Skip to content

Commit 512d1c7

Browse files
committed
test(composed): scale the WP13 start watchdogs to the CI floor
Six WP13 acceptance cases fail on the Windows shards with "timed out waiting for runtime-port record". The diagnostic added in the previous commit answered what that meant: child exit=null with both streams still open. The child was alive and still working — a slow start, not a crash. These waits sit on a real `ocx start`: spawn a Bun runtime, load the CLI, read config, bind a port, publish runtime-port.json. 10s is generous locally and is not on a Windows shard running a quarter of the suite. The repository already has the answer to exactly this class of flake — watchdogMs() with a 30s CI floor, added when the macOS lane's 10s-floor watchdog fired at 10.16s — and this suite never adopted it. All three watchdogs move together, because they bound one lifecycle: the runtime-port wait, the CLI watchdog, and the shutdown watchdog. The per-case budget moves with them. A case can start a server twice and stop it, so 45s would kill the case before a 30s watchdog inside it could report anything — the budget has to exceed the sum of what it contains. 150s on CI, unchanged locally. Worth stating why the number matters here and not on the macOS lane: that lane passes --timeout 60000, which would pre-empt any larger per-case value. The Windows shards pass no --timeout at all, so Bun's 5s default applies and the explicit per-case budget is the only ceiling that exists. Refs #2108 Verification: 8 pass / 0 fail locally, ci-workflows 132 pass / 0 fail (it pins the lane's timeout contract), tsc --noEmit exit 0. The Windows shard is the only check that can prove the change, since the failure exists nowhere else.
1 parent d2f1dcc commit 512d1c7

1 file changed

Lines changed: 33 additions & 10 deletions

File tree

‎tests/codex-composed-acceptance.test.ts‎

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ import { join, relative, resolve } from "node:path";
2424
import { createHash } from "node:crypto";
2525
import { Database } from "bun:sqlite";
2626

27+
import { watchdogMs } from "./helpers/ci-watchdog";
28+
29+
/**
30+
* Per-case budget. A case can start a server twice and stop it, so it must exceed the sum of
31+
* the watchdogs inside it or the case dies before the watchdog it was meant to bound can
32+
* report anything useful. On CI those watchdogs take the 30s floor, so this scales with them.
33+
*/
34+
const CASE_TIMEOUT_MS = process.env.CI === "true" ? 150_000 : 45_000;
35+
2736
import {
2837
canonicalizeCodexHome,
2938
} from "../src/codex/codex-write-lock";
@@ -73,7 +82,16 @@ function manifestWithoutCatalogArtifacts(entries: Record<string, string>): Recor
7382
);
7483
}
7584

76-
async function waitFor<T>(read: () => T | null | Promise<T | null>, label: string, timeoutMs = 10_000): Promise<T> {
85+
async function waitFor<T>(
86+
read: () => T | null | Promise<T | null>,
87+
label: string,
88+
// These wait on a REAL `ocx start` child: spawn a Bun runtime, load the CLI, read config,
89+
// bind a port, then publish runtime-port.json. On the Windows shards that exceeded 10s
90+
// while the child was still alive and still working — `child exit=null` with both streams
91+
// open, which is a slow start, not a crash. The watchdog exists to bound a hung test, not
92+
// to assert startup latency, so it takes the repository's CI floor.
93+
timeoutMs = watchdogMs(10_000),
94+
): Promise<T> {
7795
const deadline = Date.now() + timeoutMs;
7896
while (Date.now() < deadline) {
7997
const value = await read();
@@ -169,7 +187,12 @@ class Fixture {
169187
return child;
170188
}
171189

172-
async runCli(argv: string[], home = this.homeA, userprofile = this.userprofileA, timeoutMs = 15_000): Promise<CliResult> {
190+
async runCli(
191+
argv: string[],
192+
home = this.homeA,
193+
userprofile = this.userprofileA,
194+
timeoutMs = watchdogMs(15_000),
195+
): Promise<CliResult> {
173196
const child = this.spawnCli(argv, home, userprofile);
174197
const completed = await Promise.race([
175198
Promise.all([new Response(child.stdout).text(), new Response(child.stderr).text(), child.exited]),
@@ -227,7 +250,7 @@ class Fixture {
227250
if (server.process.exitCode === null) server.process.kill("SIGTERM");
228251
const exitCode = await Promise.race([
229252
server.process.exited,
230-
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("server shutdown watchdog")), 10_000)),
253+
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("server shutdown watchdog")), watchdogMs(10_000))),
231254
]);
232255
// Bun reports a forced SIGTERM as 128 + 15 on Windows; POSIX children may
233256
// run the CLI shutdown handler and exit cleanly instead.
@@ -317,7 +340,7 @@ describe("WP13 composed toggle acceptance", () => {
317340
} finally {
318341
await fx.stop(server);
319342
}
320-
}, 45_000);
343+
}, CASE_TIMEOUT_MS);
321344

322345
/**
323346
* RED: remove shouldSyncCodexOnStart or the under-lock desired-state read; an
@@ -372,7 +395,7 @@ describe("WP13 composed toggle acceptance", () => {
372395
} finally {
373396
await fx.stop(server);
374397
}
375-
}, 45_000);
398+
}, CASE_TIMEOUT_MS);
376399

377400
/** RED: bypass the persisted OFF mutation or the under-lock re-read; stale P19 writes its candidate after gather. */
378401
test("B-reduced: a held local provider cannot commit after the HTTP route persists OFF", async () => {
@@ -434,7 +457,7 @@ describe("WP13 composed toggle acceptance", () => {
434457
} finally {
435458
provider.stop(true);
436459
}
437-
}, 45_000);
460+
}, CASE_TIMEOUT_MS);
438461

439462
/** RED: omit `admitCodexWrite` ownership refusal; start/ensure/P19 create a coordinator or native artifact. */
440463
test("D-reduced: foreign service-home evidence refuses real CLI and HTTP writers before artifacts", async () => {
@@ -492,7 +515,7 @@ describe("WP13 composed toggle acceptance", () => {
492515
} finally {
493516
await fx.stop(server);
494517
}
495-
}, 45_000);
518+
}, CASE_TIMEOUT_MS);
496519

497520
test("D-unknown: unprovable service-home ownership refuses native reads and cache writes", async () => {
498521
const fx = fixture();
@@ -537,7 +560,7 @@ describe("WP13 composed toggle acceptance", () => {
537560
} finally {
538561
await fx.stop(server);
539562
}
540-
}, 45_000);
563+
}, CASE_TIMEOUT_MS);
541564

542565
/** RED: key N by HOME/USERPROFILE instead of effective uid plus canonical CODEX_HOME; both children acquire. */
543566
test("E: separate fake homes share the effective-user Codex lock", async () => {
@@ -600,7 +623,7 @@ describe("WP13 composed toggle acceptance", () => {
600623
await fx.stop(second);
601624
}
602625
expect(await secondOutput).not.toContain("Grok Build config updated");
603-
}, 45_000);
626+
}, CASE_TIMEOUT_MS);
604627

605628
/** RED: report restore success after a blocked history worker; config recovery must not hide history contention. */
606629
test("Restore truth: JSON distinguishes a busy history restore from native artifact recovery", async () => {
@@ -662,5 +685,5 @@ describe("WP13 composed toggle acceptance", () => {
662685
const after = new Database(stateDb, { readonly: true });
663686
expect(after.query<{ model_provider: string }, []>("SELECT model_provider FROM threads WHERE id = 'restore-1'").get()?.model_provider).toBe("openai");
664687
after.close();
665-
}, 45_000);
688+
}, CASE_TIMEOUT_MS);
666689
});

0 commit comments

Comments
 (0)