Skip to content

Commit 619405d

Browse files
committed
test(codex): await startup teardown in lifecycle fixtures
Startup validation observes the catalog home through real filesystem I/O. Advancing the fake clock cannot establish that stdin teardown has started, so the shared and isolated cleanup checks could race that lookup. Subscribe to the existing stdin close event before acquisition and await it while retaining the separate assertion that acquisition stays pending until the synthetic process exits. Preserve all eight lifecycle variants. The original 23-file shard reproduced the premature assertion on main. Validation: 20 standalone runs (132 tests each), three original-shard runs (864 tests each), scoped lint/format, and independent review passed. Fixes the fixture introduced in #157229.
1 parent 749b11e commit 619405d

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎extensions/codex/src/app-server/shared-client-lifetime.test-support.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { once } from "node:events";
12
import type {
23
AgentHarnessTaskRecord,
34
AgentHarnessTaskRuntime,
@@ -35,6 +36,7 @@ export function registerSharedClientLifetimeTests(
3536
async (kind) => {
3637
vi.useFakeTimers();
3738
const harness = createClientHarness({ autoEmitExit: false });
39+
const stdinClosed = once(harness.process.stdin, "close");
3840
let finishStart!: (client: CodexAppServerClient) => void;
3941
const starting = new Promise<CodexAppServerClient>((resolve) => {
4042
finishStart = resolve;
@@ -56,7 +58,7 @@ export function registerSharedClientLifetimeTests(
5658
try {
5759
expect(settled).toBe(false);
5860
finishStart(harness.client);
59-
await vi.advanceTimersByTimeAsync(0);
61+
await stdinClosed;
6062
expect(harness.stdinDestroyed).toBe(true);
6163
expect(settled).toBe(false);
6264
} finally {
@@ -90,6 +92,7 @@ export function registerSharedClientLifetimeTests(
9092

9193
for (let attempt = 0; attempt < 3; attempt++) {
9294
const harness = createClientHarness({ autoEmitExit: false });
95+
const stdinClosed = once(harness.process.stdin, "close");
9396
startSpy.mockImplementationOnce(async () => {
9497
live.add(harness);
9598
harness.process.once("exit", () => live.delete(harness));
@@ -118,6 +121,8 @@ export function registerSharedClientLifetimeTests(
118121
}
119122
await vi.advanceTimersByTimeAsync(mode === "timeout" ? 50 : 0);
120123
try {
124+
// Catalog identity can await real filesystem I/O outside the fake clock.
125+
await stdinClosed;
121126
expect(harness.stdinDestroyed).toBe(true);
122127
expect(settled).toBe(false);
123128
} finally {

0 commit comments

Comments
 (0)