From 453483f3edb8071356de57431538bcb2a53cc798 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Fri, 9 Oct 2026 22:53:13 +0000 Subject: [PATCH] test(codex): bound Windows shell shim spawns inside the spawn budget A loaded windows-latest runner starts pwsh.exe past the 15s internal deadline, so the caller-token restore sees a null status. The shell is the assertion, so the wait uses the shared spawn budget minus that deadline on win32, including the aged-lock ready file. Co-authored-by: JUN --- tests/ci-workflows/cold-spawn-warmup.test.ts | 9 --------- tests/codex-integration/codex-shim.test.ts | 18 +++++++++++++----- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/ci-workflows/cold-spawn-warmup.test.ts b/tests/ci-workflows/cold-spawn-warmup.test.ts index 9df9c516fc4..367b14edacc 100644 --- a/tests/ci-workflows/cold-spawn-warmup.test.ts +++ b/tests/ci-workflows/cold-spawn-warmup.test.ts @@ -108,15 +108,6 @@ const DISPOSITIONS: Readonly> = { + "graph, and an import scan has nothing to warm. The generated shim never loads a repository " + "module in the child: the point of the file is what the shell does with an exit status.", }, - "tests/codex-integration/codex-shim.test.ts": { - warmed: false, - why: - "Its Windows children are a cmd.exe or PowerShell driver tree, so the cold cost is shell and " - + "process startup rather than a repository module graph, and an import scan has nothing to warm. " - + "The file also sits exactly on its file-size ratchet cap of 2388 lines in " - + "tests/fixtures/file-size-baseline.json, and that cap only moves downward, so a warm-up cannot " - + "be added here without unrelated deletions. Left for a separate change.", - }, }; /** diff --git a/tests/codex-integration/codex-shim.test.ts b/tests/codex-integration/codex-shim.test.ts index b9836cbe317..7bfb275abf8 100644 --- a/tests/codex-integration/codex-shim.test.ts +++ b/tests/codex-integration/codex-shim.test.ts @@ -42,6 +42,13 @@ const python3Path = process.platform === "win32" setCodexShimProbeObservationMsForTests(20); afterAll(() => setCodexShimProbeObservationMsForTests(null)); const psPath = process.platform !== "win32" && existsSync("/bin/ps") ? "/bin/ps" : ""; +// A loaded windows-latest runner starts cmd.exe and pwsh.exe past INTERNAL_DEADLINE_MS +// (a caller-token restore returned status null at 17.2s; the aged-lock holder has taken +// 8–19s to write its ready file). The shell is the assertion, so the bound stays inside +// SPAWN_BUDGET_MS and uses the same derivation as the other Windows spawn waits. +const SHELL_SPAWN_TIMEOUT_MS = process.platform === "win32" + ? SPAWN_BUDGET_MS - INTERNAL_DEADLINE_MS + : INTERNAL_DEADLINE_MS; function successfulLauncher(label: string): string { return process.platform === "win32" ? `${label}\r\n` : `#!/bin/sh\n# ${label}\nexit 0\n`; @@ -1177,8 +1184,8 @@ printf '%s\\n' child-codex }); if (callerToken === undefined) delete env.OPENCODEX_API_AUTH_TOKEN; const result = shell === "cmd" - ? spawnSync(process.env.ComSpec ?? "cmd.exe", ["/d", "/c", "driver.cmd"], { cwd: dir, env, encoding: "utf8", timeout: INTERNAL_DEADLINE_MS, windowsHide: true }) - : spawnSync(`${shell}.exe`, ["-NoProfile", "-NonInteractive", "-File", driverPath], { env, encoding: "utf8", timeout: INTERNAL_DEADLINE_MS, windowsHide: true }); + ? spawnSync(process.env.ComSpec ?? "cmd.exe", ["/d", "/c", "driver.cmd"], { cwd: dir, env, encoding: "utf8", timeout: SHELL_SPAWN_TIMEOUT_MS, windowsHide: true }) + : spawnSync(`${shell}.exe`, ["-NoProfile", "-NonInteractive", "-File", driverPath], { env, encoding: "utf8", timeout: SHELL_SPAWN_TIMEOUT_MS, windowsHide: true }); expect(result.status, result.stderr).toBe(0); expect(result.stdout.trim().split(/\r?\n/)).toEqual([ `child:${callerToken || "file-token"}`, @@ -1220,7 +1227,7 @@ printf '%s\\n' child-codex const env = shimChildEnv({ OPENCODEX_HOME: dir, OPENCODEX_API_AUTH_TOKEN: callerToken ?? "", OCX_SHIM_BYPASS: "" }); if (callerToken === undefined) delete env.OPENCODEX_API_AUTH_TOKEN; const result = spawnSync(executable, ["-NoProfile", "-NonInteractive", "-File", driverPath], { - env, encoding: "utf8", timeout: INTERNAL_DEADLINE_MS, windowsHide: true, + env, encoding: "utf8", timeout: SHELL_SPAWN_TIMEOUT_MS, windowsHide: true, }); expect(result.error).toBeUndefined(); expect(result.status, result.stderr).toBe(0); @@ -1236,7 +1243,7 @@ printf '%s\\n' child-codex // A failed process must complete, rather than satisfy the check through a timeout. writeFileSync(driverPath, `\uFEFF$ErrorActionPreference = 'Stop'\n& '${wrapperPath.replace(/'/g, "''")}' exec\n`); const uncaught = spawnSync(executable, ["-NoProfile", "-NonInteractive", "-File", driverPath], { - env, encoding: "utf8", timeout: INTERNAL_DEADLINE_MS, windowsHide: true, + env, encoding: "utf8", timeout: SHELL_SPAWN_TIMEOUT_MS, windowsHide: true, }); expect(uncaught.error).toBeUndefined(); expect(uncaught.signal).toBeNull(); @@ -1755,7 +1762,7 @@ exit 127 stderr: "pipe", }); // Spawned holder child writing its ready marker: 8-19 s on windows-latest. - const deadline = Date.now() + INTERNAL_DEADLINE_MS; + const deadline = Date.now() + SHELL_SPAWN_TIMEOUT_MS; while (!existsSync(readyPath) && Date.now() < deadline) await Bun.sleep(5); expect(existsSync(readyPath)).toBe(true); @@ -1763,6 +1770,7 @@ exit 127 cwd: repoRoot(), env: childEnv, encoding: "utf8", + timeout: SHELL_SPAWN_TIMEOUT_MS, }); expect(second.status).toBe(0); expect(JSON.parse(second.stdout.trim())).toEqual({ status: "deferred" });