From f36c36f0681fcb264192592964878bd100556739 Mon Sep 17 00:00:00 2001 From: bbingz Date: Mon, 13 Jul 2026 19:09:07 +0800 Subject: [PATCH] test(terminal): dispose foreground trackers between cases --- .../terminal-pane/pty-connection.test.ts | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) 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 6c72e259c72..ae1576f04df 100644 --- a/src/renderer/src/components/terminal-pane/pty-connection.test.ts +++ b/src/renderer/src/components/terminal-pane/pty-connection.test.ts @@ -26,6 +26,7 @@ import { resetAgentStartupDelayedDeliveryForTests } from '@/lib/agent-startup-delayed-delivery' import type { PaneForegroundAgentEntry } from '@/store/slices/pane-foreground-agent' +import type { createPaneForegroundAgentTracker } from './pane-foreground-agent-tracker' // Repro command: // pnpm exec vitest run --config config/vitest.config.ts src/renderer/src/components/terminal-pane/pty-connection.test.ts -t "OpenTUI-style small ANSI redraw" @@ -257,6 +258,12 @@ let mockStoreState: StoreState let transportFactoryQueue: MockTransport[] = [] let createdTransportOptions: Record[] = [] let storeSubscribers: ((state: StoreState) => void)[] = [] +type PaneForegroundAgentTrackerFactory = typeof createPaneForegroundAgentTracker +type PaneForegroundAgentTracker = ReturnType +type PaneForegroundAgentTrackerModule = { + createPaneForegroundAgentTracker: PaneForegroundAgentTrackerFactory +} +const paneForegroundAgentTrackers = new Set() vi.mock('@/runtime/sync-runtime-graph', () => ({ scheduleRuntimeGraphSync @@ -278,6 +285,20 @@ vi.mock('./terminal-webgl-atlas-recovery', () => ({ scheduleTerminalWebglAtlasRecovery })) +vi.mock('./pane-foreground-agent-tracker', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + createPaneForegroundAgentTracker: ( + ...args: Parameters + ) => { + const tracker = actual.createPaneForegroundAgentTracker(...args) + paneForegroundAgentTrackers.add(tracker) + return tracker + } + } +}) + function notifyStoreSubscribers(): void { for (const listener of storeSubscribers.slice()) { listener(mockStoreState) @@ -894,6 +915,12 @@ describe('connectPanePty', () => { }) afterEach(() => { + // Why: most cases do not retain their pane binding; cancel its delayed reads + // before they can publish into the next case's freshly reset store mock. + for (const tracker of paneForegroundAgentTrackers) { + tracker.dispose() + } + paneForegroundAgentTrackers.clear() vi.useRealTimers() if (originalRequestAnimationFrame) { globalThis.requestAnimationFrame = originalRequestAnimationFrame