fix(profiles): a Codex switch reaches running and new sessions
Codex >= 0.164 sends every request through a shared app-server daemon that outlives its TUIs and keeps the login it started with, so writing a new auth.json changed nothing: open sessions and even new ones stayed on the old (out-of-quota) account. After a switch, restart that CODEX_HOME's daemon when one runs; open TUIs reconnect to it on their own (verified on 0.164.0 with two keys). The response says so (following), and the toast tells the user running sessions follow.
This commit is contained in:
@@ -97,6 +97,33 @@ describe("tool-profiles: codex", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("restarts a running Codex daemon so open sessions follow; none running, nothing to restart", async () => {
|
||||
login("acct-a", "alice@example.com");
|
||||
profiles.saveProfile("codex");
|
||||
login("acct-b", "bob@example.com");
|
||||
profiles.saveProfile("codex");
|
||||
assert.equal(profiles.activateProfile("codex", "alice").following, false);
|
||||
|
||||
const log = path.join(ROOT, "codex-argv.log");
|
||||
const bin = path.join(ROOT, "fake-codex.sh");
|
||||
fs.writeFileSync(bin, `#!/bin/sh\necho "$CODEX_HOME $*" >> '${log}'\n`, { mode: 0o755 });
|
||||
const sock = path.join(process.env.CODEX_HOME, "app-server-control", "app-server-control.sock");
|
||||
fs.mkdirSync(path.dirname(sock), { recursive: true });
|
||||
fs.writeFileSync(sock, "");
|
||||
process.env.AGENTHUB_CODEX_BIN = bin;
|
||||
try {
|
||||
assert.equal(profiles.activateProfile("codex", "bob").following, true);
|
||||
for (let i = 0; i < 50 && !fs.existsSync(log); i++)
|
||||
await new Promise((r) => setTimeout(r, 20));
|
||||
assert.equal(
|
||||
fs.readFileSync(log, "utf8").trim(),
|
||||
`${process.env.CODEX_HOME} app-server daemon restart`
|
||||
);
|
||||
} finally {
|
||||
delete process.env.AGENTHUB_CODEX_BIN;
|
||||
}
|
||||
});
|
||||
|
||||
it("refuses to switch away from an unsaved login", () => {
|
||||
login("acct-a", "alice@example.com");
|
||||
profiles.saveProfile("codex");
|
||||
|
||||
Reference in New Issue
Block a user