Skip to content
Merged
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
15 changes: 0 additions & 15 deletions linux-features/account-switcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,6 @@ mkdir -p "$test_tmp"
TMPDIR="$test_tmp" node --test linux-features/account-switcher/test.js
```

Set `CODEX_ACCOUNT_SWITCHER_NATIVE_APP` to an extracted official application
root and `CODEX_ACCOUNT_SWITCHER_ASAR_CLI` to `@electron/asar/bin/asar.mjs` to also
run the native Owl regression test. This requires a graphical session and an
unlocked Secret Service provider. It generates a disposable probe, uses synthetic
credentials, verifies key persistence and vault decryption in fresh switcher
instances, and exercises **Add account** with the official connection class's
request/subscription methods. An initially disconnected hosted connection must
remain untouched, and the probe rejects any attempts to query global cloud work.
The probe uses a synthetic transport and intercepts the browser launch, then
cancels OAuth; it does not log in to real accounts. It exits only its own process
and clears only its own test key.
Do not set a long build `TMPDIR` when launching a desktop app: Chromium's socket
path must fit the Unix-domain socket limit. Use `TMPDIR="$XDG_RUNTIME_DIR"` for
interactive launches instead.

Set `CODEX_ACCOUNT_SWITCHER_CLI` to the extracted official `resources/codex` to
also check credential-file decoding and the idle-check protocol in a disposable,
unauthenticated app server. This does not test OAuth with real accounts.
Expand Down
86 changes: 0 additions & 86 deletions linux-features/account-switcher/native-probe.js

This file was deleted.

7 changes: 3 additions & 4 deletions linux-features/account-switcher/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ function createAccountSwitcher({ electron, clients, home, runSecretTool }) {
async function assertIdle() {
stage = "checking backend connections";
for (const client of clients()) {
if (client.getPendingRequestCount() !== 0) throw new SwitcherError("Wait for pending requests and active tasks to finish before switching accounts.");
if (client.hostConfig.id === "durable" && client.getConnectionState() === "disconnected") continue;
if (await client.getPendingRequestCount() !== 0) throw new SwitcherError("Wait for pending requests and active tasks to finish before switching accounts.");
// Durable tasks run independently of this desktop connection. An
// account-wide catalog includes work in other apps/profiles, which a
// local credential change neither restarts nor cancels. Only in-flight
Expand Down Expand Up @@ -261,7 +262,6 @@ function createAccountSwitcher({ electron, clients, home, runSecretTool }) {
stage = "reconnecting the account";
const info = identity(text);
writePrivate(authPath, text);
client.clearAuthTokenCache();
await client.restart({ intent: "reconnect" });
await rpc(client, "account/read", { refreshToken: false });
if (!await principalMatches(client, info, PRINCIPAL_SETTLE_ATTEMPTS)) {
Expand Down Expand Up @@ -295,7 +295,7 @@ function createAccountSwitcher({ electron, clients, home, runSecretTool }) {
if (message.method !== "account/login/completed") return;
if (loginId == null) { early = message.params; return; }
if (message.params?.loginId === loginId) resolveLogin(message.params);
});
}, { methods: ["account/login/completed"] });
const controller = new AbortController();
try {
const login = await rpc(client, "account/login/start", { type: "chatgpt", appBrand: "chatgpt", useHostedLoginSuccessPage: true });
Expand All @@ -311,7 +311,6 @@ function createAccountSwitcher({ electron, clients, home, runSecretTool }) {
dialog.showMessageBox({ type: "info", title: "ChatGPT Community", message: "Sign in to another ChatGPT account in your browser.", detail: "Your current login is remembered. Cancel returns to it.", buttons: ["Cancel"], cancelId: 0, signal: controller.signal }).then(() => null),
]);
if (!result?.success) return;
client.clearAuthTokenCache();
remember(accounts, await readCurrent(client, PRINCIPAL_SETTLE_ATTEMPTS));
completed = true;
} catch (error) {
Expand Down
62 changes: 22 additions & 40 deletions linux-features/account-switcher/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ function fixture(t, options = {}) {
const client = {
hostConfig: { id: "local", kind: "local" },
ensureReady: async () => { ready = true; calls.push("ensureReady"); },
getPendingRequestCount: () => options.pending ?? 0,
getConnectionState: () => ready ? "connected" : "disconnected",
getPendingRequestCount: async () => options.pending ?? 0,
getAuthenticatedPrincipal: async () => ({ accountId: `account-${active}`, userId: `user-${active}` }),
clearAuthTokenCache: () => calls.push("clearCache"),
restart: async () => {
calls.push("restart");
const name = JSON.parse(fs.readFileSync(authPath)).tokens.account_id.slice(8);
Expand Down Expand Up @@ -322,7 +322,9 @@ for (const action of ["add", "switch"]) {
const f = fixture(t);
const reads = [];
f.clients.push({
hostConfig: { id: "durable", kind: "local" }, getPendingRequestCount: () => pending,
hostConfig: { id: "durable", kind: "local" },
getConnectionState: () => "connected",
getPendingRequestCount: async () => pending,
sendAppServerRequest: async method => {
reads.push(method);
// A catalog would contain a permanently active task from another
Expand All @@ -348,6 +350,23 @@ for (const action of ["add", "switch"]) {
}
}

test("disconnected durable host is not opened during idle checks", async t => {
for (const action of ["switch", "add"]) {
const f = fixture(t, action === "add" ? { login: "second" } : {});
let durableOpened = false;
f.clients.push({
hostConfig: { id: "durable", kind: "local" },
getConnectionState: () => "disconnected",
getPendingRequestCount: async () => { durableOpened = true; return 0; },
});
if (action === "switch") { await f.open(3); f.seedSecond(); }
await f.open(1);
assert.equal(durableOpened, false, `disconnected durable host must not be opened during ${action}`);
assert.equal(f.dialogs.filter(dialog => dialog.type === "error").length, 0);
assert.equal(fs.readFileSync(f.authPath, "utf8"), credentials("second"));
}
});

test("login setup errors name the phase without exposing upstream error details", async t => {
const f = fixture(t);
f.client.registerInternalNotificationHandler = () => { throw new Error("private-error-token"); };
Expand Down Expand Up @@ -648,40 +667,3 @@ test("official main and profile dropdown chunks patch uniquely and remain valid
}
}
});

test("official Owl reaches OAuth and reopens an encrypted vault without querying independent cloud work", {
skip: !process.env.CODEX_ACCOUNT_SWITCHER_NATIVE_APP || !process.env.CODEX_ACCOUNT_SWITCHER_ASAR_CLI,
timeout: 30_000,
}, t => {
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "account-native-"));
const app = process.env.CODEX_ACCOUNT_SWITCHER_NATIVE_APP;
const home = path.join(dir, "home"), profile = path.join(dir, "profile");
const probe = path.join(dir, "app"), source = path.join(dir, "source");
fs.mkdirSync(path.join(probe, "resources"), { recursive: true });
fs.mkdirSync(source);
t.after(() => {
if (fs.existsSync(home)) {
const id = crypto.createHash("sha256").update(fs.realpathSync(home)).digest("hex");
try { execFileSync("secret-tool", ["clear", "application", "codex-desktop", "feature", "account-switcher", "profile", id], { stdio: "ignore", timeout: 5_000 }); } catch {}
}
fs.rmSync(dir, { recursive: true, force: true });
});
fs.copyFileSync(path.join(app, "ChatGPT"), path.join(probe, "ChatGPT"));
fs.chmodSync(path.join(probe, "ChatGPT"), 0o755);
for (const name of fs.readdirSync(app)) {
if (["ChatGPT", "resources", "start.sh", ".codex-linux"].includes(name)) continue;
fs.symlinkSync(path.join(app, name), path.join(probe, name));
}
for (const name of ["owl-app.ini", "owl-electron-app.json"]) fs.copyFileSync(path.join(app, "resources", name), path.join(probe, "resources", name));
fs.copyFileSync(path.join(__dirname, "native-probe.js"), path.join(source, "probe.js"));
fs.writeFileSync(path.join(source, "package.json"), JSON.stringify({ name: "account-native-probe", version: "1.0.0", main: "probe.js" }));
execFileSync(process.execPath, [process.env.CODEX_ACCOUNT_SWITCHER_ASAR_CLI, "pack", source, path.join(probe, "resources/app.asar")], { stdio: "pipe", timeout: 5_000 });
const result = path.join(dir, "result.json");
execFileSync(path.join(probe, "ChatGPT"), [`--user-data-dir=${profile}`], {
env: { ...process.env, TMPDIR: process.env.XDG_RUNTIME_DIR || "/tmp", CODEX_HOME: home, CODEX_ELECTRON_USER_DATA_PATH: profile,
ACCOUNT_SWITCHER_PROBE_RUNTIME: process.env.CODEX_ACCOUNT_SWITCHER_PROBE_RUNTIME || path.join(__dirname, "runtime.js"), ACCOUNT_SWITCHER_PROBE_RESULT: result,
ACCOUNT_SWITCHER_PROBE_NATIVE_APP: app },
stdio: "pipe", timeout: 20_000,
});
assert.deepEqual(JSON.parse(fs.readFileSync(result)), { menus: 3, encryptedVault: true, errors: [], openedLogin: 1, readyChecks: 4, cloudUntouched: true });
});