Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions src-tauri/src/runtime_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ use std::path::{Path, PathBuf};

const PRIMARY_IDE_SERVER_PORT: u16 = 13_847;
const PRIMARY_CLI_PROXY_PORT: u16 = 17_888;
const INSTANCE_IDENTIFIER_PREFIXES: &[&str] = &["yorg.orgii.instance", "yorg.orgii.e2e.instance"];
const PRODUCTION_INSTANCE_IDENTIFIER_PREFIX: &str = "yorg.orgii.instance";
const E2E_INSTANCE_IDENTIFIER_PREFIX: &str = "yorg.orgii.e2e.instance";

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct RuntimeInstanceProfile {
Expand Down Expand Up @@ -49,9 +50,24 @@ impl RuntimeInstanceProfile {
}

fn parse_instance_id(identifier: &str) -> Option<u16> {
INSTANCE_IDENTIFIER_PREFIXES
.iter()
.find_map(|prefix| identifier.strip_prefix(prefix))?
let raw_id =
if let Some(raw_id) = identifier.strip_prefix(PRODUCTION_INSTANCE_IDENTIFIER_PREFIX) {
raw_id
} else {
let profiled = identifier.strip_prefix(E2E_INSTANCE_IDENTIFIER_PREFIX)?;
let mut segments = profiled.split('.');
let raw_id = segments.next()?;
if segments.any(|segment| {
segment.is_empty()
|| !segment
.bytes()
.all(|byte| byte.is_ascii_alphanumeric() || byte == b'-')
}) {
return None;
}
raw_id
};
raw_id
.parse::<u16>()
.ok()
.filter(|id| (2..=99).contains(id))
Expand Down Expand Up @@ -98,7 +114,9 @@ mod tests {

#[test]
fn webdriver_secondary_identifier_keeps_the_same_isolation_profile() {
let profile = RuntimeInstanceProfile::from_identifier("yorg.orgii.e2e.instance2");
let profile = RuntimeInstanceProfile::from_identifier(
"yorg.orgii.e2e.instance2.f2-server-ready-20260825",
);
assert_eq!(profile.instance_id, 2);
assert_eq!(profile.ide_server_port, 13_848);
assert_eq!(profile.cli_proxy_port, 17_889);
Expand All @@ -121,6 +139,7 @@ mod tests {
"yorg.orgii.instance0",
"yorg.orgii.instance100",
"yorg.orgii.instance2.extra",
"yorg.orgii.e2e.instance2.bad_profile",
"other.orgii.instance2",
] {
assert_eq!(
Expand Down
6 changes: 6 additions & 0 deletions src/app/root/e2e/helpers/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type KeyInfo,
type ModelType,
} from "@src/api/tauri/rpc/schemas/validation";
import { loadSharedLocalKeys } from "@src/hooks/keyVault/sharedLocalKeyStore";
import { createLogger } from "@src/hooks/logger";

import { asError } from "../result";
Expand Down Expand Up @@ -49,6 +50,7 @@ export async function addAccount(
enabled_models: [opts.model],
},
});
await loadSharedLocalKeys(true);
logger.info(`addAccount ok: ${account.id}`);
return { ok: true, account };
} catch (err) {
Expand Down Expand Up @@ -85,6 +87,7 @@ export async function addCursorNativeAccount(
enabled_models: opts.enabledModels ?? [],
},
});
await loadSharedLocalKeys(true);
return { ok: true, account };
} catch (err) {
return asError(err);
Expand Down Expand Up @@ -124,6 +127,7 @@ export async function addClaudeCodeAccount(
: undefined,
},
});
await loadSharedLocalKeys(true);
return { ok: true, account };
} catch (err) {
return asError(err);
Expand Down Expand Up @@ -163,6 +167,7 @@ export async function addCodexAccount(
env_vars: Object.keys(envVars).length > 0 ? envVars : undefined,
},
});
await loadSharedLocalKeys(true);
return { ok: true, account };
} catch (err) {
return asError(err);
Expand Down Expand Up @@ -213,6 +218,7 @@ export async function cloneCursorNativeAccountWithoutApiKey(
enabled_models: source.enabled_models,
},
});
await loadSharedLocalKeys(true);
return { ok: true, account };
} catch (err) {
return asError(err);
Expand Down
14 changes: 14 additions & 0 deletions src/config/runtimeInstance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@ describe("runtimeInstanceProfileForIdentifier", () => {
);
});

it("keeps a uniquely profiled WebDriver instance on its isolated ports", () => {
expect(
runtimeInstanceProfileForIdentifier(
"yorg.orgii.e2e.instance2.f2-server-ready-20260825"
)
).toEqual({
instanceId: 2,
ideServerPort: 13_848,
cliProxyPort: 17_889,
authDeepLinkScheme: "orgii-instance2",
});
});

it("falls back for malformed and unbounded identifiers", () => {
for (const identifier of [
"yorg.orgii.instance1",
"yorg.orgii.instance100",
"yorg.orgii.instance2.extra",
"yorg.orgii.e2e.instance2.bad_profile",
"other.orgii.instance2",
]) {
expect(runtimeInstanceProfileForIdentifier(identifier).instanceId).toBe(
Expand Down
5 changes: 4 additions & 1 deletion src/config/runtimeInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ const PRIMARY_CLI_PROXY_PORT = 17_888;
export function runtimeInstanceProfileForIdentifier(
identifier: string
): RuntimeInstanceProfile {
const match = /^yorg\.orgii\.instance(\d+)$/.exec(identifier.trim());
const normalized = identifier.trim();
const match =
/^yorg\.orgii\.instance(\d+)$/.exec(normalized) ??
/^yorg\.orgii\.e2e\.instance(\d+)(?:\.[a-zA-Z0-9-]+)*$/.exec(normalized);
const parsedId = match ? Number(match[1]) : 1;
const instanceId =
Number.isInteger(parsedId) && parsedId >= 2 && parsedId <= 99
Expand Down
Loading
Loading