Skip to content

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

Windows-safe tests: cloud computer real-shell cases only where a POSIX sh is the target, and codex-update expects the platform's own command (#6047)

Milind Sonie020c1ac790b
diff --git a/server/boat-command.test.ts b/server/boat-command.test.ts
index c885e4657b..63880e9adb 100644
--- a/server/boat-command.test.ts
+++ b/server/boat-command.test.ts
@@ -100,8 +100,7 @@ describe("the provider's limits on a synchronous command", () => {
expect(await boat.runCommand(cfg, BOX, "ls ms:5", { timeoutMs: command.COMMAND_WALL.syncSafeMs })).toMatchObject({ ok: false, exitCode: null, unanswered: true });
}
tooSlow = false;
- await sleep(150);
- expect(processes.some((process) => process.command === "true")).toBe(true);
+ await vi.waitFor(() => expect(processes.some((process) => process.command === "true")).toBe(true), { timeout: 30_000 });
expect(silent).toEqual([]);
expect(health.boatHealth.notRespondingSince(BOX)).toBeNull();
});
@@ -151,7 +150,9 @@ describe("a command that may run long", () => {
expect(command.trackedProcesses(BOX).size).toBe(0);
});
- it("keeps a quick command quick: about a tenth of a second and a few status reads on top of its own time", async () => {
+ // A slow runner (a Windows one takes three to five times as long per request) still has to stay well under "seconds":
+ // the count of status reads, which no machine's speed changes, is the tight half of this.
+ it("keeps a quick command quick: a few status reads and well under two seconds on top of its own time", async () => {
const took: number[] = [];
for (let run = 0; run < 5; run++) {
const before = Date.now();
@@ -159,8 +160,9 @@ describe("a command that may run long", () => {
took.push(Date.now() - before - 200);
}
const typical = [...took].sort((a, b) => a - b)[2]!;
- expect(typical).toBeLessThan(400);
+ expect(typical).toBeLessThan(1_500);
expect(requests.filter((request) => request.method === "GET").length).toBeLessThanOrEqual(5 * 4);
+ expect(command.COMMAND_WALL.pollMs.slice(0, 3).reduce((sum, ms) => sum + ms, 0)).toBeLessThan(300);
});
it("hands back a command still running when the caller's time is up: timed out, with its process id, not stopped", async () => {
@@ -174,7 +176,7 @@ describe("a command that may run long", () => {
}, 45_000);
it("reads a small tail while the command runs and the whole tail once, when it has ended", async () => {
- await boat.runCommand(cfg, BOX, "build ms:700");
+ await boat.runCommand(cfg, BOX, "build ms:1500");
const tails = requests.filter((request) => request.method === "GET").map((request) => request.tail);
expect(tails.length).toBeGreaterThanOrEqual(3);
expect(tails.at(-1)).toBe(command.COMMAND_WALL.tailBytes);
@@ -209,8 +211,8 @@ describe("a command that may run long", () => {
});
it("takes a process the provider says it does not know as lost", async () => {
- const pending = boat.runCommand(cfg, BOX, "build ms:2000");
- await sleep(100);
+ const pending = boat.runCommand(cfg, BOX, "build ms:20000");
+ await vi.waitFor(() => expect(command.trackedProcesses(BOX).size).toBe(1), { timeout: 30_000 });
unknownProcess = true;
await expect(pending).resolves.toMatchObject({ ok: false, lost: true });
});
@@ -219,8 +221,7 @@ describe("a command that may run long", () => {
const abort = new AbortController();
const pending = boat.runCommand(cfg, BOX, "build ms:5000", { signal: abort.signal });
const rejected = expect(pending).rejects.toThrow();
- await sleep(100);
- expect(command.trackedProcesses(BOX).size).toBe(1);
+ await vi.waitFor(() => expect(command.trackedProcesses(BOX).size).toBe(1), { timeout: 30_000 });
abort.abort();
await rejected;
// Nobody follows it any more, so it no longer keeps the computer awake.
diff --git a/server/cloud-computer-once.test.ts b/server/cloud-computer-once.test.ts
index d15b9331c3..087134d1e6 100644
--- a/server/cloud-computer-once.test.ts
+++ b/server/cloud-computer-once.test.ts
@@ -1,9 +1,12 @@
-// The claim script is run for real, by this machine's own sh in a throwaway folder, standing in for the computer's shell.
+// The claim and stop scripts only ever run on the cloud computer, which is Linux. Where this machine has a POSIX sh they
+// are run for real, in a throwaway folder; everywhere, Windows included, the app's side (the script it writes, what it
+// does with each answer, when it sends again) is tested against a model of the computer that the real shell is checked
+// against.
import { execFileSync, spawn } from "node:child_process";
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
-import { afterEach, describe, expect, it } from "vitest";
+import { afterEach, describe, expect, it, vi } from "vitest";
import { onceCommand, RESEND, retryRead, runOnce, stopCommand, type OnceDeps } from "./cloud-computer-once.ts";
import { createCloudComputerCounters } from "./cloud-computer-counters.ts";
@@ -12,6 +15,9 @@ import type { AppConfig } from "./config.ts";
const cfg = {} as AppConfig;
const BOX = "bx_23456789";
const KEY = "0123456789abcdef";
+/** Git Bash on a Windows runner is not the shell these scripts are written for: paths, `mkdir`, signals and process ids differ. */
+const POSIX_SH = process.platform !== "win32";
+const ONLY_POSIX = "(POSIX sh only: the script runs on the cloud computer, which is Linux)";
const dirs: string[] = [];
afterEach(() => { for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true }); });
@@ -36,7 +42,106 @@ function computer() {
};
}
-describe("a call's claim on the computer", () => {
+type Answer = { exitCode: number; stdout: string };
+const TAKEN = (key: string): Answer => ({ exitCode: 75, stdout: `omb-once:${key}:taken\n` });
+const UNCLAIMED = (key: string): Answer => ({ exitCode: 76, stdout: `omb-once:${key}:unclaimed\n` });
+
+/** What the claim script does on the computer, in memory: who may run, by key, by whether a claim can be made, and by
+ * whether this copy is a first send or a resend. `claimable: false` is a disk and a /dev/shm that both refuse. */
+function modelComputer(options: { claimable?: boolean; exitCode?: number } = {}) {
+ const claimed = new Set<string>();
+ let runs = 0;
+ return {
+ runs: () => runs,
+ sh(script: string): Answer {
+ const key = /^k=([0-9a-f]{16});/.exec(script)?.[1];
+ if (!key) throw new Error("not a claim script");
+ const resend = script.includes(`echo omb-once:${key}:unclaimed; exit 76`);
+ if (claimed.has(key)) return TAKEN(key);
+ if (options.claimable === false) { if (resend) return UNCLAIMED(key); } else claimed.add(key);
+ runs += 1;
+ return { exitCode: options.exitCode ?? 0, stdout: "done\n" };
+ },
+ };
+}
+
+describe("the script a call is sent as", () => {
+ const lines = (script: string) => script.split("\n");
+
+ it("claims the call's key on the disk, then in memory, before the command, which comes last and unchanged", () => {
+ const script = lines(onceCommand(KEY, 1, "exec make all"));
+ expect(script[0]).toBe(`k=${KEY}; a="\${HOME:-/tmp}/.cache/omb-once"; b="/dev/shm/omb-once"`);
+ expect(script.at(-1)).toBe("exec make all");
+ const claimDisk = script.indexOf('if ! mkdir "$a/$k" 2>/dev/null; then'), claimMemory = script.indexOf(' if ! mkdir "$b/$k" 2>/dev/null; then');
+ expect(claimDisk).toBeGreaterThan(0);
+ expect(claimMemory).toBeGreaterThan(claimDisk);
+ expect(claimMemory).toBeLessThan(script.length - 1);
+ });
+
+ it("stops with its own mark and exit code 75 wherever it finds the key already claimed", () => {
+ const script = onceCommand(KEY, 1, "true");
+ expect(script).toContain(`taken() { echo omb-once:${KEY}:taken; exit 75; }`);
+ expect(script).toContain('if [ -d "$a/$k" ] || [ -d "$b/$k" ]; then taken; fi');
+ expect(script).toContain(' if [ -d "$a/$k" ]; then taken; fi');
+ expect(script).toContain(' if [ -d "$b/$k" ]; then taken; fi');
+ });
+
+ it("lets a first send run with no claim, and makes a resend that cannot claim stop with exit code 76", () => {
+ expect(onceCommand(KEY, 1, "true")).not.toContain("exit 76");
+ for (const attempt of [2, 3, 4]) expect(onceCommand(KEY, attempt, "true")).toContain(` echo omb-once:${KEY}:unclaimed; exit 76`);
+ });
+
+ it("records the shell's process id beside the claim, and the stop script signals only that process and what it started", () => {
+ expect(onceCommand(KEY, 1, "true")).toContain('echo $$ > "$a/$k/pid" 2>/dev/null || echo $$ > "$b/$k/pid" 2>/dev/null');
+ const stop = stopCommand(KEY);
+ expect(stop).toContain(`k=${KEY}; p=; for d in "\${HOME:-/tmp}/.cache/omb-once" "/dev/shm/omb-once"; do if [ -f "$d/$k/pid" ]`);
+ expect(stop).toContain('stop() { for c in $(pgrep -P "$1" 2>/dev/null); do stop "$c"; done; kill -TERM "$1" 2>/dev/null; }');
+ expect(stop).not.toMatch(/kill[^\n]* -- -|kill -9|pkill/);
+ });
+
+ it("clears claims older than a day now and then, never on every call", () => {
+ expect(onceCommand("0123456789abcde0", 1, "true")).toContain("-mmin +1440 -exec rmdir {} +");
+ expect(onceCommand(KEY, 1, "true")).not.toContain("rmdir");
+ });
+
+ it("refuses a key that is not its own kind, since the key is written into the shell", () => {
+ expect(() => onceCommand("$(reboot)", 1, "true")).toThrow(RangeError);
+ expect(() => stopCommand("$(reboot)")).toThrow(RangeError);
+ });
+});
+
+describe("who may run, by the claim", () => {
+ it.each<[string, { claimable?: boolean }, number[], number[], number]>([
+ ["a first send, then a late copy and a resend", {}, [1, 1, 2], [0, 75, 75], 1],
+ ["a resend that arrives first, then the hung first send", {}, [2, 1], [0, 75], 1],
+ ["nowhere to claim: a first send runs as it always did", { claimable: false }, [1], [0], 1],
+ ["nowhere to claim: a resend never runs", { claimable: false }, [2, 3], [76, 76], 0],
+ ])("%s", (_name, options, attempts, exitCodes, runs) => {
+ const pc = modelComputer(options);
+ expect(attempts.map((attempt) => pc.sh(onceCommand(KEY, attempt, "true")).exitCode)).toEqual(exitCodes);
+ expect(pc.runs()).toBe(runs);
+ });
+
+ it("gives each call its own claim", () => {
+ const pc = modelComputer();
+ pc.sh(onceCommand(KEY, 1, "true"));
+ expect(pc.sh(onceCommand("fedcba9876543210", 1, "true")).exitCode).toBe(0);
+ expect(pc.runs()).toBe(2);
+ });
+});
+
+describe.skipIf(!POSIX_SH)(`a call's claim on the computer ${ONLY_POSIX}`, () => {
+ it("decides who may run exactly as the model the other tests use", () => {
+ const table: Array<[{ claimable?: boolean }, number[]]> = [[{}, [1, 1, 2]], [{}, [2, 1]], [{ claimable: false }, [1]], [{ claimable: false }, [2, 3]]];
+ for (const [options, attempts] of table) {
+ const pc = computer(), model = modelComputer(options);
+ if (options.claimable === false) { writeFileSync(join(pc.root, "disk"), ""); writeFileSync(join(pc.root, "shm"), ""); }
+ const real = attempts.map((attempt) => pc.sh(onceCommand(KEY, attempt, pc.command, pc.claims)));
+ expect(real).toEqual(attempts.map((attempt) => model.sh(onceCommand(KEY, attempt, "true"))));
+ expect(pc.runs()).toBe(model.runs());
+ }
+ });
+
it("lets the first copy of a call run and stops every later copy before the command", () => {
const pc = computer();
const first = pc.sh(onceCommand(KEY, 1, pc.command, pc.claims));
@@ -78,14 +183,11 @@ describe("a call's claim on the computer", () => {
expect(pc.sh(onceCommand(KEY, 1, "echo out; exit 3", pc.claims))).toEqual({ exitCode: 3, stdout: "out\n" });
});
- it("refuses a key that is not its own kind, since the key is written into the shell", () => {
- expect(() => onceCommand("$(reboot)", 1, "true")).toThrow(RangeError);
- });
});
-describe("stopping the command a call started", () => {
+describe.skipIf(!POSIX_SH)(`stopping the command a call started ${ONLY_POSIX}`, () => {
const alive = (pid: number) => { try { process.kill(pid, 0); return true; } catch { return false; } };
- const until = async (check: () => boolean, ms = 10_000) => {
+ const until = async (check: () => boolean, ms = 30_000) => {
for (const end = Date.now() + ms; Date.now() < end; await new Promise((resolve) => setTimeout(resolve, 25))) if (check()) return true;
return false;
};
@@ -109,7 +211,6 @@ describe("stopping the command a call started", () => {
it("does nothing, quietly, for a call that recorded no process", () => {
const pc = computer();
expect(pc.sh(stopCommand(KEY, pc.claims))).toEqual({ exitCode: 0, stdout: "" });
- expect(() => stopCommand("$(reboot)")).toThrow(RangeError);
});
});
@@ -117,8 +218,7 @@ type Sent = { ok: boolean; exitCode: number | null; stdout: string; stderr: stri
const UNANSWERED: Sent = { ok: false, exitCode: null, stdout: "", stderr: "", unanswered: true };
/** `gateway(send)` decides, per send, whether the command reaches the computer and whether its answer comes back. */
-function relay(gateway: (send: number) => { delivered: boolean; answered: boolean; status?: 503 }, answersProbe: () => boolean = () => true) {
- const pc = computer();
+function relay(gateway: (send: number) => { delivered: boolean; answered: boolean; status?: 503 }, answersProbe: () => boolean = () => true, pc: { sh(script: string): Answer; runs(): number } = modelComputer()) {
const counters = createCloudComputerCounters();
let at = 0, sends = 0, probes = 0;
const waits: number[] = [];
@@ -127,8 +227,7 @@ function relay(gateway: (send: number) => { delivered: boolean; answered: boolea
sleep: async (ms) => { waits.push(ms); at += ms; },
run: async (_cfg, _box, script) => {
const { delivered, answered, status } = gateway(sends++);
- // What reaches the computer is the script with the test's own claim folders in place of the real ones.
- const out = delivered ? pc.sh(script.replace('a="${HOME:-/tmp}/.cache/omb-once"; b="/dev/shm/omb-once"', `a="${pc.claims.disk}"; b="${pc.claims.memory}"`)) : null;
+ const out = delivered ? pc.sh(script) : null;
if (status === 503) return { ok: false, exitCode: null, stdout: "", stderr: "", busy: true as const };
if (!answered || !out) return UNANSWERED;
return { ok: out.exitCode === 0, exitCode: out.exitCode, stdout: out.stdout, stderr: "" };
@@ -139,7 +238,7 @@ function relay(gateway: (send: number) => { delivered: boolean; answered: boolea
return answersProbe() ? { ok: true, waitedMs: 4_000 } : { ok: false, phase: "restoring", waitedMs: 90_000 };
},
};
- const call = () => runOnce(cfg, BOX, pc.command, { signal: new AbortController().signal, deadline: 120_000 }, deps);
+ const call = () => runOnce(cfg, BOX, "make", { signal: new AbortController().signal, deadline: 120_000 }, deps);
return { pc, call, counters, sends: () => sends, probes: () => probes, waits };
}
@@ -164,7 +263,7 @@ describe("a call the computer did not answer", () => {
const r = relay((send) => ({ delivered: send > 0, answered: send > 0 }));
await r.call();
// The hung first send finally reaches the machine.
- const late = r.pc.sh(onceCommand(KEY, 1, r.pc.command, r.pc.claims));
+ const late = r.pc.sh(onceCommand(KEY, 1, "make"));
expect(late.exitCode).toBe(75);
expect(r.pc.runs()).toBe(1);
});
@@ -197,16 +296,22 @@ describe("a call the computer did not answer", () => {
});
it("returns a command that ran and failed as it is, with no resend", async () => {
- const pc = computer();
+ const pc = modelComputer({ exitCode: 2 });
let sends = 0;
- const outcome = await runOnce(cfg, BOX, "exit 2", { signal: new AbortController().signal, deadline: Date.now() + 60_000 }, {
- key: () => KEY,
- run: async (_cfg, _box, script) => { sends++; const out = pc.sh(script.replace(/a="[^"]*"; b="[^"]*"/, `a="${pc.claims.disk}"; b="${pc.claims.memory}"`)); return { ok: false, exitCode: out.exitCode, stdout: out.stdout, stderr: "" }; },
+ const outcome = await runOnce(cfg, BOX, "exit 2", { signal: new AbortController().signal, deadline: 120_000 }, {
+ key: () => KEY, now: () => 0,
+ run: async (_cfg, _box, script) => { sends++; const out = pc.sh(script); return { ok: false, exitCode: out.exitCode, stdout: out.stdout, stderr: "" }; },
});
expect(outcome).toMatchObject({ kind: "ran", resent: 0, result: { exitCode: 2 } });
expect(sends).toBe(1);
});
+ it("does not run a resend that can claim nowhere, and says the computer did not answer", async () => {
+ const r = relay((send) => ({ delivered: send > 0, answered: send > 0 }), () => true, modelComputer({ claimable: false }));
+ await expect(r.call()).resolves.toEqual({ kind: "unanswered", phase: "waking" });
+ expect(r.pc.runs()).toBe(0);
+ });
+
it("answers that the call ran out of time, not a raw error, when a send hangs with no reply until the call's time is up", async () => {
let at = 0;
const outcome = await runOnce(cfg, BOX, "make", { signal: new AbortController().signal, deadline: 120_000 }, {
@@ -230,10 +335,11 @@ describe("a call the computer did not answer", () => {
},
});
const rejected = expect(pending).rejects.toBeDefined();
- await new Promise((resolve) => setTimeout(resolve, 10));
+ await vi.waitFor(() => expect(sent).toHaveLength(1), { timeout: 30_000 });
(stoppedByPerson ? turn : call).abort();
await rejected;
- await new Promise((resolve) => setTimeout(resolve, 10));
+ // The stop is sent in the same turn of the event loop as the rejection; one more turn shows whether it was.
+ await new Promise((resolve) => setImmediate(resolve));
return sent.includes(stopCommand(KEY));
};
expect(await sentFor(true)).toBe(true);
@@ -242,7 +348,8 @@ describe("a call the computer did not answer", () => {
it("does not treat a refusal thrown before the send as the computer's silence", async () => {
const refusal = Object.assign(new Error("this cloud computer is being deleted"), { status: 409 });
- await expect(runOnce(cfg, BOX, "true", { signal: new AbortController().signal, deadline: Date.now() + 60_000 }, {
+ await expect(runOnce(cfg, BOX, "true", { signal: new AbortController().signal, deadline: 120_000 }, {
+ now: () => 0,
run: async () => { throw refusal; },
})).rejects.toBe(refusal);
});
@@ -266,3 +373,28 @@ describe("a read the computer did not answer", () => {
await expect(retryRead(cfg, BOX, async () => { throw other; }, () => false, options, quick)).rejects.toBe(other);
});
});
+
+describe.skipIf(!POSIX_SH)(`a call sent again, against the real shell ${ONLY_POSIX}`, () => {
+ /** The script as it reaches the computer, with the test's own claim folders in place of the real ones. */
+ const onDisk = (pc: ReturnType<typeof computer>) => ({
+ runs: pc.runs,
+ sh: (script: string) => pc.sh(script.replace('a="${HOME:-/tmp}/.cache/omb-once"; b="/dev/shm/omb-once"', `a="${pc.claims.disk}"; b="${pc.claims.memory}"`).replace(/\nmake$/, `\n${pc.command}`)),
+ });
+
+ it("runs the command once when the first copy never arrived", async () => {
+ const pc = computer();
+ const r = relay((send) => ({ delivered: send > 0, answered: send > 0 }), () => true, onDisk(pc));
+ await expect(r.call()).resolves.toMatchObject({ kind: "ran", resent: 1, result: { ok: true, stdout: "done\n" } });
+ expect(pc.runs()).toBe(1);
+ });
+
+ it("does not run it a second time when only the first copy's answer was lost, or when that copy arrives late", async () => {
+ const lost = computer();
+ await expect(relay((send) => ({ delivered: true, answered: send > 0 }), () => true, onDisk(lost)).call()).resolves.toEqual({ kind: "lost" });
+ expect(lost.runs()).toBe(1);
+ const late = computer();
+ await relay((send) => ({ delivered: send > 0, answered: send > 0 }), () => true, onDisk(late)).call();
+ expect(late.sh(onceCommand(KEY, 1, late.command, late.claims)).exitCode).toBe(75);
+ expect(late.runs()).toBe(1);
+ });
+});
diff --git a/server/cloud-computer-tools.test.ts b/server/cloud-computer-tools.test.ts
index 75fadaa7f1..bbc5d9a6c0 100644
--- a/server/cloud-computer-tools.test.ts
+++ b/server/cloud-computer-tools.test.ts
@@ -225,14 +225,17 @@ describe("cloud computer tools", () => {
it("answers within its call budget, the gate's wait included, when the Boat holds a command", async () => {
holdCommand = true;
+ const BUDGET_MS = 3_000;
const started = Date.now();
const result = await tools.cloudComputerRpc({ method: "tools/call", params: { name: "exec", arguments: { command: "sleep 600" } } }, {
- cfg, boxId: () => "bx_23456789", signal: new AbortController().signal, budgetMs: 600, assertActive: () => {},
+ // Room for a slow runner to get the request out after the gate's wait. The answer may come before the budget ends
+ // (the command's own limit ends first), never after it by more than a slow machine's slack.
+ cfg, boxId: () => "bx_23456789", signal: new AbortController().signal, budgetMs: BUDGET_MS, assertActive: () => {},
gate: async () => { await new Promise(resolve => setTimeout(resolve, 300)); return { held: false }; },
});
expect(result).toEqual({ isError: true, content: [{ type: "text", text: (await import("./cloud-computer-background.ts")).EXEC_LATE }] });
- expect(Date.now() - started).toBeGreaterThanOrEqual(550);
- expect(Date.now() - started).toBeLessThan(1_500);
+ expect(Date.now() - started).toBeGreaterThanOrEqual(250);
+ expect(Date.now() - started).toBeLessThan(BUDGET_MS + 10_000);
expect(calls.filter(entry => entry.path.endsWith("/commands") && String(entry.body.command).includes("sleep 600"))).toHaveLength(1);
expect(calls.some(entry => String(entry.body?.command).includes("kill -TERM"))).toBe(false);
server.closeAllConnections();
@@ -260,14 +263,13 @@ describe("cloud computer tools", () => {
expect(calls.filter(entry => entry.path.endsWith("/commands")).map(entry => entry.body.detached === true)).toEqual([false, false, true]);
});
- it("answers that the command ran out of time, as a result and before the call's own limit, when its start gets no reply", async () => {
+ it("answers that the command ran out of time, as a result, when its start gets no reply", async () => {
holdCommand = true;
- const before = Date.now();
const result = await tools.cloudComputerRpc({ method: "tools/call", params: { name: "exec", arguments: { command: "make" } } }, {
cfg, boxId: () => "bx_23456789", signal: new AbortController().signal, budgetMs: 8_000, assertActive: () => {}, gate: async () => ({ held: false }),
});
expect(result).toEqual({ isError: true, content: [{ type: "text", text: (await import("./cloud-computer-background.ts")).EXEC_LATE }] });
- expect(Date.now() - before).toBeLessThan(7_000);
+ expect(calls.filter(entry => entry.path.endsWith("/commands") && String(entry.body.command).includes("make"))).toHaveLength(1);
server.closeAllConnections();
}, 20_000);
diff --git a/server/drivers/codex-update.test.ts b/server/drivers/codex-update.test.ts
index 56d653f8d2..2a9cab90de 100644
--- a/server/drivers/codex-update.test.ts
+++ b/server/drivers/codex-update.test.ts
@@ -1,5 +1,5 @@
import { afterEach, expect, it, vi } from "vitest";
-import { codexReleaseUpdate } from "./codex-update.ts";
+import { codexReleaseUpdate, codexUpdateCommand } from "./codex-update.ts";
const releases = vi.hoisted(() => ({ latest: "0.169.0" as string | null, pinned: "0.167.0" as string | undefined }));
vi.mock("./codex-release.ts", async (original) => ({
@@ -24,8 +24,12 @@ 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");
+ const cli = "'/Applications/My Codex/codex'";
+ const update = await codexReleaseUpdate("codex-cli 0.167.0", cli, false);
+ // PowerShell runs a quoted path only behind its call operator, so the command differs by the host's platform.
+ expect(codexUpdateCommand(cli, "darwin")).toBe("'/Applications/My Codex/codex' update");
+ expect(codexUpdateCommand(cli, "win32")).toBe("& '/Applications/My Codex/codex' update");
+ expect(update?.command).toBe(codexUpdateCommand(cli, process.platform));
});
it("does not show an update on My Cloud or for an already current copy", async () => {