test(pty): account for asynchronous immediate descendant cleanup

This commit is contained in:
Neil
2026-09-14 08:31:15 -07:00
parent 68b9cab9d5
commit ea5fa7dc61
2 changed files with 20 additions and 2 deletions
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from 'vitest'
import {
existsSyncMock,
loginPreflightExecFileMock,
spawnMock,
openCodeClearPtyMock,
piClearPtyMock
@@ -162,9 +163,25 @@ describe('registerPtyHandlers', () => {
rows: 24
})) as { id: string }
let finishSnapshot: (() => void) | undefined
loginPreflightExecFileMock.mockImplementationOnce(
(
_file: string,
_args: string[],
_options: unknown,
callback: (error: Error | null, stdout: string) => void
) => {
finishSnapshot = () => callback(null, '')
}
)
const killPromise = handlers.get('pty:kill')!(null, { id: spawnResult.id }) as Promise<void>
expect(killSpy).toHaveBeenCalledTimes(1)
expect(killSpy).not.toHaveBeenCalled()
expect(onDataDisposable.dispose).not.toHaveBeenCalled()
expect(onExitDisposable.dispose).not.toHaveBeenCalled()
await vi.waitFor(() => expect(finishSnapshot).toBeTypeOf('function'))
finishSnapshot?.()
await vi.waitFor(() => expect(killSpy).toHaveBeenCalledTimes(1))
expect(onDataDisposable.dispose).not.toHaveBeenCalled()
expect(onExitDisposable.dispose).not.toHaveBeenCalled()
@@ -16,7 +16,8 @@ import { describe, expect, it } from 'vitest'
*/
const SRC_DIR = join(__dirname, '..')
const CALL = 'killWithDescendantSweep('
const EXPECTED_MINIMUM_SITES = 5
// Local immediate and recognized-agent shutdown share one guarded call site.
const EXPECTED_MINIMUM_SITES = 4
function collectTypeScriptFiles(dir: string): string[] {
const found: string[] = []