test(codex): reuse unproven close fixture sequence

This commit is contained in:
Neil
2026-10-06 17:46:39 -07:00
committed by Neil
parent 983098dd00
commit 0c32e80cc8
@@ -126,6 +126,26 @@ async function flushStreams(): Promise<void> {
await new Promise((resolve) => setImmediate(resolve))
}
async function closeWithoutObservedExit(
connection: CodexAppServerConnection,
child: StubChild
): Promise<boolean> {
const forcedKill = new Promise<void>((resolve) => {
child.kill.mockImplementation((signal) => {
if (signal === 'SIGKILL') {
resolve()
}
})
})
const closing = connection.close()
await flushStreams()
await vi.advanceTimersByTimeAsync(GRACEFUL_EXIT_MS)
await forcedKill
await vi.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(1_000)
return closing
}
function rejection(promise: Promise<unknown>): Promise<Error> {
return promise.then(
() => {
@@ -511,21 +531,7 @@ describe('openCodexAppServerConnection', () => {
spawnImpl
)
const forcedKill = new Promise<void>((resolve) => {
child.kill.mockImplementation((signal) => {
if (signal === 'SIGKILL') {
resolve()
}
})
})
const closing = connection.close()
await flushStreams()
await vi.advanceTimersByTimeAsync(GRACEFUL_EXIT_MS)
await forcedKill
await vi.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(1_000)
await expect(closing).resolves.toBe(false)
await expect(closeWithoutObservedExit(connection, child)).resolves.toBe(false)
expect(vi.getTimerCount()).toBe(0)
}, 10_000)
@@ -561,20 +567,7 @@ describe('openCodexAppServerConnection', () => {
spawnImpl
)
const forcedKill = new Promise<void>((resolve) => {
child.kill.mockImplementation((signal) => {
if (signal === 'SIGKILL') {
resolve()
}
})
})
const first = connection.close()
await flushStreams()
await vi.advanceTimersByTimeAsync(GRACEFUL_EXIT_MS)
await forcedKill
await vi.advanceTimersByTimeAsync(0)
await vi.advanceTimersByTimeAsync(1_000)
await expect(first).resolves.toBe(false)
await expect(closeWithoutObservedExit(connection, child)).resolves.toBe(false)
child.emit('exit', 0, null)
await expect(connection.close()).resolves.toBe(true)