From ea5fa7dc61cabc08e57ba298de157c434ef96c01 Mon Sep 17 00:00:00 2001 From: Neil Date: Mon, 14 Sep 2026 08:31:15 -0700 Subject: [PATCH] test(pty): account for asynchronous immediate descendant cleanup --- .../pty-listener-teardown-and-orphans.test.ts | 19 ++++++++++++++++++- ...escendant-termination-job-coverage.test.ts | 3 ++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/main/ipc/pty-listener-teardown-and-orphans.test.ts b/src/main/ipc/pty-listener-teardown-and-orphans.test.ts index ae749f8dbe0..accc0347217 100644 --- a/src/main/ipc/pty-listener-teardown-and-orphans.test.ts +++ b/src/main/ipc/pty-listener-teardown-and-orphans.test.ts @@ -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 - 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() diff --git a/src/main/pty-descendant-termination-job-coverage.test.ts b/src/main/pty-descendant-termination-job-coverage.test.ts index 21e14012caa..738d16ab16f 100644 --- a/src/main/pty-descendant-termination-job-coverage.test.ts +++ b/src/main/pty-descendant-termination-job-coverage.test.ts @@ -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[] = []