diff --git a/src/main/native-chat/transcript-watch-liveness.test.ts b/src/main/native-chat/transcript-watch-liveness.test.ts index 84be20dde58..8667f58af08 100644 --- a/src/main/native-chat/transcript-watch-liveness.test.ts +++ b/src/main/native-chat/transcript-watch-liveness.test.ts @@ -60,7 +60,8 @@ function claudeLine(uuid: string, role: 'user' | 'assistant', text: string): str })}\n` } -async function waitFor(predicate: () => boolean, timeoutMs = 2_000): Promise { +// fs.watch and filesystem mutations use the platform clock; poll observable callbacks to a deadline. +async function waitFor(predicate: () => boolean, timeoutMs = 5_000): Promise { const start = Date.now() while (!predicate()) { if (Date.now() - start > timeoutMs) { @@ -166,13 +167,14 @@ describe('native chat transcript watcher liveness', () => { onReplace: replacements, onAppend: () => {}, debounceMs: 0, - reconciliationIntervalMs: 20 + reconciliationIntervalMs: 10_000 }) await waitFor(() => snapshots.mock.calls.length === 1) await writeFile(filePath, prefixAfter + stableTail) const future = new Date(Date.now() + 10_000) await utimes(filePath, future, future) + watchCallbacks[0]!('change', 'transcript.jsonl') await waitFor(() => replacements.mock.calls.flat(2).some((message) => message.id === 'prefix-new') ) diff --git a/src/main/windows/windows-host-job.win32.test.ts b/src/main/windows/windows-host-job.win32.test.ts index ceba9ab6f14..94e9c323860 100644 --- a/src/main/windows/windows-host-job.win32.test.ts +++ b/src/main/windows/windows-host-job.win32.test.ts @@ -30,6 +30,18 @@ function isAlive(pid: number): boolean { } } +// Job-object teardown is external to fake timers; poll the real process table to a deadline. +async function waitForProcessExit(pid: number, timeoutMs: number): Promise { + const deadline = Date.now() + timeoutMs + while (Date.now() < deadline) { + if (!isAlive(pid)) { + return true + } + await sleep(50) + } + return !isAlive(pid) +} + describeOnWindows('host job reaps the tree when the host dies', () => { let dir: string @@ -83,11 +95,13 @@ describeOnWindows('host job reaps the tree when the host dies', () => { // Force-kill only the host: no tree kill, nothing given a chance to unwind. // This is the daemon-crash shape. process.kill(host.pid!, 'SIGKILL') - await sleep(3_000) - try { - expect(isAlive(shellPid)).toBe(false) - expect(isAlive(grandchildPid)).toBe(false) + const [shellExited, grandchildExited] = await Promise.all([ + waitForProcessExit(shellPid, 15_000), + waitForProcessExit(grandchildPid, 15_000) + ]) + expect(shellExited).toBe(true) + expect(grandchildExited).toBe(true) } finally { for (const pid of [shellPid, grandchildPid]) { try {