Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

test(codex): cover Windows update notices and restored status

Afloat73d7881d53f5
diff --git a/server/drivers/codex-update.test.ts b/server/drivers/codex-update.test.ts
index 56d653f8d2..6b1ae80d00 100644
--- a/server/drivers/codex-update.test.ts
+++ b/server/drivers/codex-update.test.ts
@@ -25,7 +25,7 @@ it("keeps the app updater when the advertised release is the pinned version", as
it("keeps the configured executable's update command when a terminal update is needed", async () => {
const update = await codexReleaseUpdate("codex-cli 0.167.0", "'/Applications/My Codex/codex'", false);
- expect(update?.command).toBe("'/Applications/My Codex/codex' update");
+ expect(update?.command).toBe(`${process.platform === "win32" ? "& " : ""}'/Applications/My Codex/codex' update`);
});
it("does not show an update on My Cloud or for an already current copy", async () => {
diff --git a/server/engine-status-seed.e2e.test.ts b/server/engine-status-seed.e2e.test.ts
new file mode 100644
index 0000000000..39ceb38366
--- /dev/null
+++ b/server/engine-status-seed.e2e.test.ts
@@ -0,0 +1,69 @@
+import { spawn, type ChildProcess } from "node:child_process";
+import { existsSync, openSync, closeSync, readFileSync, writeFileSync } from "node:fs";
+import { join } from "node:path";
+import { fileURLToPath } from "node:url";
+import { expect, it } from "vitest";
+import { launchVerificationServer, verificationServerArgs, verificationServerEnvironment } from "../scripts/control-omb.ts";
+import { engineStatusFile, flushEngineStatusFiles } from "./harness/engine-status-file.ts";
+import { waitForExit } from "./testing/cleanup.ts";
+import { freePortBlock } from "./testing/ports.ts";
+
+const ROOT = fileURLToPath(new URL("..", import.meta.url));
+
+it("restores a terminal-only update through the real engine API before the startup probe finishes", async () => {
+ const fixture = await launchVerificationServer();
+ const release = join(fixture.info.dataDir, "release-codex-probe");
+ let child: ChildProcess | undefined;
+ try {
+ await waitForExit(fixture.child, { signal: "SIGTERM" });
+ const { dataDir, logPath } = fixture.info;
+ const probed = join(dataDir, "codex-probe-started");
+ const cli = join(dataDir, "codex-seed-fixture.mjs");
+ writeFileSync(cli, `#!/usr/bin/env node
+import { existsSync, writeFileSync } from "node:fs";
+if (process.argv[2] === "--version") {
+ writeFileSync(${JSON.stringify(probed)}, "started");
+ while (!existsSync(${JSON.stringify(release)})) await new Promise(resolve => setTimeout(resolve, 25));
+ process.stdout.write("codex-cli 0.147.0\\n");
+} else {
+ await import(${JSON.stringify(new URL("./testing/fake-codex-app-server.ts", import.meta.url).href)});
+}
+`, { mode: 0o700 });
+ const configFile = join(dataDir, "config.json");
+ const config = JSON.parse(readFileSync(configFile, "utf8"));
+ config.instances.codex = { driver: "codex", config: { cli } };
+ writeFileSync(configFile, JSON.stringify(config));
+ const update = { title: "Update Codex to 0.169.0", message: "Use the terminal for the newer release.", command: "codex update", serverInstall: false as const };
+ engineStatusFile(join(dataDir, "providers", "engine-status.json")).save([
+ { instanceId: "codex", driverKind: "codex", cli, snapshot: { state: "available", version: "codex-cli 0.167.0", authenticated: true, update } },
+ ]);
+ flushEngineStatusFiles();
+
+ const port = await freePortBlock([0, 1]);
+ const url = `http://127.0.0.1:${port}`;
+ const env = verificationServerEnvironment(process.env, dataDir, port);
+ const log = openSync(logPath, "a");
+ child = spawn(process.execPath, verificationServerArgs(env), { cwd: ROOT, env, stdio: ["ignore", log, log] });
+ closeSync(log);
+ await expect.poll(async () => {
+ if (child!.exitCode !== null) throw new Error(`fixture exited; see ${logPath}`);
+ try { return (await fetch(`${url}/api/health`)).ok; } catch { return false; }
+ }, { timeout: 30_000, interval: 50 }).toBe(true);
+ const status = async () => {
+ const response = await fetch(`${url}/api/instances`, { headers: { origin: url } });
+ expect(response.status).toBe(200);
+ const body = await response.json() as { instances: Array<{ instanceId: string; snapshot: { version?: string; update?: unknown } }> };
+ return body.instances.find((instance) => instance.instanceId === "codex")!.snapshot;
+ };
+ await expect.poll(() => existsSync(probed), { timeout: 10_000 }).toBe(true);
+ expect(existsSync(release)).toBe(false);
+ expect(await status()).toMatchObject({ version: "codex-cli 0.167.0", update });
+ writeFileSync(release, "continue");
+ await expect.poll(async () => (await status()).version, { timeout: 15_000 }).toBe("codex-cli 0.147.0");
+ console.info(`Codex status recovery fixture: ${url}; server log: ${logPath}`);
+ } finally {
+ writeFileSync(release, "cleanup");
+ if (child) await waitForExit(child, { signal: "SIGTERM" });
+ await fixture.close();
+ }
+}, 90_000);