From e60189c470e4d4b031399ae0e2e5bd1b3f042770 Mon Sep 17 00:00:00 2001 From: yiling Date: Sun, 6 Dec 2026 16:58:48 +0800 Subject: [PATCH] test(cli): wait for killed child processes to exit in runner shell tests --- apps/cli/src/runner/shell.test.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/cli/src/runner/shell.test.ts b/apps/cli/src/runner/shell.test.ts index 9af4b71d..6fa70233 100644 --- a/apps/cli/src/runner/shell.test.ts +++ b/apps/cli/src/runner/shell.test.ts @@ -137,13 +137,14 @@ describe('runner bash execution', () => { it('times out and terminates background children', async () => { const result = await shell.run( - { ...request('sleep 30 & echo $!; wait'), timeoutSec: 0.1 }, + { ...request('sleep 30 & echo $!; wait'), timeoutSec: 0.5 }, new AbortController().signal, () => {}, ) expect(result).toMatchObject({ timedOut: true, signal: 'SIGKILL' }) const pid = Number((await readFile(path.join(cwd, '.pi/logs/bash-test.log'), 'utf8')).trim()) - expect(() => process.kill(pid, 0)).toThrow() + expect(pid).toBeGreaterThan(0) + await vi.waitFor(() => expect(() => process.kill(pid, 0)).toThrow(), { timeout: 2000 }) }) it('cancels a running command and never starts an already cancelled one', async () => { @@ -205,7 +206,7 @@ describe('runner bash execution', () => { ) expect(result.error).toBe('Output consumer failed') expect(pid).toBeGreaterThan(0) - expect(() => process.kill(pid, 0)).toThrow() + await vi.waitFor(() => expect(() => process.kill(pid, 0)).toThrow(), { timeout: 2000 }) }) it('rejects invalid timeouts and caps runaway output', async () => {