From bd7205684a9713820c0cd8a22169a837c0f1435e Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Fri, 17 Jul 2026 19:17:33 -0700 Subject: [PATCH] test(pty-connection): drain async confirm reads between tests (#9260) The connectPanePty suite intermittently fails in CI on `clearAgentLaunchConfig` call-count assertions (e.g. expected exactly once, received 5 with pane keys belonging to other tests). Root cause is cross-test async leakage: pane foreground-agent trackers kick off `confirmForegroundProcess` reads whose continuations settle on the microtask queue, not on fake timers. A test that ends with one still in flight leaks it into the next test, where it resolves against that test's fresh store mock and calls clearAgentLaunchConfig with the prior test's pane key. Drain pending microtasks in afterEach (before tearing down fake timers, while the test still owns its store mock) so each test absorbs its own async fallout. No behavior change; full suite stays green (446/446). Note: this is a CI-timing flake not reproducible locally in isolation (ordered runs pass repeatedly, incl. under GC pressure); the fix targets the confirmed leak mechanism and removes the timing dependence. --- .../components/terminal-pane/pty-connection.test.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/components/terminal-pane/pty-connection.test.ts b/src/renderer/src/components/terminal-pane/pty-connection.test.ts index e8aeb34ef..025233221 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection.test.ts @@ -906,7 +906,16 @@ describe('connectPanePty', () => { globalThis.cancelAnimationFrame = vi.fn() }) - afterEach(() => { + afterEach(async () => { + // Why: pane foreground-agent trackers run async foreground-confirm reads + // (`confirmForegroundProcess`) whose continuations settle on the microtask + // queue, not on fake timers. A test that ends with one still in flight + // leaks it into the NEXT test, where it resolves against that test's fresh + // store mock and calls e.g. clearAgentLaunchConfig with THIS test's pane + // key — a flaky cross-test call-count failure (seen in CI). Drain pending + // microtasks while this test still owns the store mock, before fake timers + // are torn down, so each test absorbs its own async fallout. + await flushAsyncTicks() vi.useRealTimers() if (originalRequestAnimationFrame) { globalThis.requestAnimationFrame = originalRequestAnimationFrame