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
8 changes: 8 additions & 0 deletions server/drivers/codex.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,14 @@ describe("CodexDriver turns (fake app-server)", () => {
});
});

it("also accepts login status from older Codex versions that used stdout", async () => {
await create({ mode: "logged-in-stdout" });
await expect(instance.snapshot()).resolves.toMatchObject({
state: "available",
authenticated: true,
});
});

it("marks a Codex 401 as setup so the UI offers sign-in instead of Retry", async () => {
await create({ mode: "unauthorized" });
await instance.adapter.sendTurn({ threadId: "t-unauthorized", text: "hi" });
Expand Down
4 changes: 2 additions & 2 deletions server/drivers/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {
});
if (!version) return { state: "unavailable", reason: `\`${config.cli}\` CLI not found` };
const authenticated = await new Promise<boolean>((resolve) => {
execCli(config.cli, ["login", "status"], { timeout: 8000, env }, (err, stdout) =>
resolve(!err && /logged in/i.test(stdout)),
execCli(config.cli, ["login", "status"], { timeout: 8000, env }, (err, stdout, stderr) =>
resolve(!err && /^logged in\b/im.test(`${stdout}\n${stderr ?? ""}`)),
);
});
// childEnv drops OPENAI_API_KEY on purpose — turns run on the ChatGPT login
Expand Down
6 changes: 3 additions & 3 deletions server/procs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ export function execCli(
cli: string,
args: string[],
opts: ExecFileOptions,
cb: (err: Error | null, stdout: string) => void,
cb: (err: Error | null, stdout: string, stderr?: string) => void,
): void {
const resolved = resolveCli(cli, args);
execFile(resolved.command, resolved.args, { ...opts, windowsHide: true }, (err, stdout) =>
cb(err, typeof stdout === "string" ? stdout : String(stdout)),
execFile(resolved.command, resolved.args, { ...opts, windowsHide: true, encoding: "utf8" }, (err, stdout, stderr) =>
cb(err, stdout, stderr),
);
}

Expand Down
9 changes: 6 additions & 3 deletions server/testing/fake-codex-app-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// real app-server, it never exits on its own — the driver kills it.
//
// FAKE_CODEX_MODE happy (default) | approval | resume | stream |
// logged-out | unauthorized
// logged-in-stdout | logged-out | unauthorized
// FAKE_CODEX_DUMP path to write {argv, env, calls, decision} as JSON
//
// Keep this file dependency-free — it runs as a bare `node` subprocess.
Expand All @@ -14,15 +14,18 @@ import { writeFileSync } from "node:fs";
const mode = process.env.FAKE_CODEX_MODE ?? "happy";

if (process.argv[2] === "--version") {
process.stdout.write("codex-cli 0.146.0\n");
process.stdout.write("codex-cli 0.147.0\n");
process.exit(0);
}
if (process.argv[2] === "login" && process.argv[3] === "status") {
if (mode === "logged-out") {
process.stderr.write("Not logged in\n");
process.exit(1);
}
process.stdout.write("Logged in using ChatGPT\n");
// Codex 0.147.0 reports a successful login on stderr; retain a mode for
// older versions that wrote the same status on stdout.
const statusStream = mode === "logged-in-stdout" ? process.stdout : process.stderr;
statusStream.write("Logged in using ChatGPT\n");
process.exit(0);
}
const calls: Array<{ method: string; params: unknown }> = [];
Expand Down
Loading