Skip to content

Commit d2f1dcc

Browse files
committed
test(composed): show the child's output when a start never publishes its port
Six of the WP13 acceptance tests fail on the Windows shards with "timed out waiting for runtime-port record". That message is the symptom and never the cause: the child process writes runtime-port.json only after a successful start, so the interesting information — a throw, a bind refusal, a missing artifact — is in its stderr, which the fixture piped and then discarded. Two CI rounds read as "Windows is flaky" for exactly this reason. This makes the next round say what actually happened. The streams are captured once at spawn and carried on StartedServer, because a Bun subprocess stream cannot be read twice — the Grok E2E case already reads stdout after start() and would otherwise fail with "ReadableStream has already been used". Caught locally before pushing. Diagnostic only: no production code, and the failure message is the only behavior that changes. Refs #2108
1 parent 4dfc2d6 commit d2f1dcc

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ const roots: Fixture[] = [];
4141

4242
type CliResult = { exitCode: number; stdout: string; stderr: string };
4343
type RuntimeRecord = { pid: number; port: number; hostname?: string };
44-
type StartedServer = { process: ReturnType<typeof Bun.spawn>; runtime: RuntimeRecord };
44+
type StartedServer = {
45+
process: ReturnType<typeof Bun.spawn>;
46+
runtime: RuntimeRecord;
47+
/** Captured during start(): the child's streams can only be read once. */
48+
stdout: Promise<string>;
49+
stderr: Promise<string>;
50+
};
4551

4652
/** A byte manifest: paths plus bytes, not mtimes or parsed JSON. */
4753
function manifest(root: string): Record<string, string> {
@@ -176,6 +182,23 @@ class Fixture {
176182
async start(): Promise<StartedServer> {
177183
const child = this.spawnCli(["start"]);
178184
const runtimePath = join(this.ocx, "runtime-port.json");
185+
// Capture the child's streams while we wait. Without this, a start that dies for a
186+
// concrete reason — a throw, a port bind refusal, a missing artifact — surfaces only as
187+
// "timed out waiting for runtime-port record", which is the symptom and never the cause.
188+
// That is exactly how the Windows failures read for two CI rounds.
189+
const stderr = new Response(child.stderr).text();
190+
const stdout = new Response(child.stdout).text();
191+
const diagnose = async (label: string): Promise<never> => {
192+
const exited = child.exitCode ?? (await Promise.race([
193+
child.exited,
194+
new Promise<null>(resolve => setTimeout(() => resolve(null), 500)),
195+
]));
196+
const [err, out] = await Promise.all([
197+
Promise.race([stderr, new Promise<string>(resolve => setTimeout(() => resolve("<stderr still open>"), 500))]),
198+
Promise.race([stdout, new Promise<string>(resolve => setTimeout(() => resolve("<stdout still open>"), 500))]),
199+
]);
200+
throw new Error(`${label}; child exit=${String(exited)}\n--- stderr ---\n${err.slice(-4000)}\n--- stdout ---\n${out.slice(-2000)}`);
201+
};
179202
const runtime = await waitFor(() => {
180203
if (!existsSync(runtimePath)) return null;
181204
try {
@@ -186,7 +209,7 @@ class Fixture {
186209
} catch {
187210
return null;
188211
}
189-
}, "runtime-port record");
212+
}, "runtime-port record").catch(() => diagnose("timed out waiting for runtime-port record"));
190213
const health = await waitFor(async () => {
191214
try {
192215
const response = await fetch(`http://127.0.0.1:${runtime.port}/healthz`, { signal: AbortSignal.timeout(500) });
@@ -197,7 +220,7 @@ class Fixture {
197220
}
198221
}, "child /healthz");
199222
expect(health).toMatchObject({ pid: child.pid, port: runtime.port });
200-
return { process: child, runtime };
223+
return { process: child, runtime, stdout, stderr };
201224
}
202225

203226
async stop(server: StartedServer): Promise<void> {
@@ -570,7 +593,7 @@ describe("WP13 composed toggle acceptance", () => {
570593
await fx.stop(first);
571594
}
572595
const second = await fx.start();
573-
const secondOutput = new Response(second.process.stdout).text();
596+
const secondOutput = second.stdout;
574597
try {
575598
expect(readFileSync(join(grokHome, "config.toml"), "utf8")).not.toContain("opencodex managed block");
576599
} finally {

0 commit comments

Comments
 (0)