From 7ef547b795e7fa310d52e20329c2245838acf694 Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Fri, 28 Aug 2026 08:25:17 -0700 Subject: [PATCH] test(terminal): pin the consumed tab in the resume-record clear The callback returned a pre-consumed startup and ignored its tabId, so the helper could spend any tab's startup and still pass. --- .../lib/worktree-reactivation-tab-forkbomb.test.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/renderer/src/lib/worktree-reactivation-tab-forkbomb.test.ts b/src/renderer/src/lib/worktree-reactivation-tab-forkbomb.test.ts index d6fab33faee..e9b34b93f16 100644 --- a/src/renderer/src/lib/worktree-reactivation-tab-forkbomb.test.ts +++ b/src/renderer/src/lib/worktree-reactivation-tab-forkbomb.test.ts @@ -95,16 +95,21 @@ describe('STA-1111 worktree reopen does not fork-bomb tabs', () => { // its first PTY spawn consumes that startup command. if (reopen === 0) { expect(state.sleepingAgentSessionsByPaneKey[paneKey]).toBeDefined() - const consumed = state.consumeTabStartupCommand(tabs[0]!.id) - expect(consumed?.resumeProviderSession).toEqual(providerSession) - // The real pane lifecycle invokes this on the fresh PTY boundary. + // The real pane lifecycle invokes this on the fresh PTY boundary. Consume inside the + // callback so the tab the helper asks for is what actually gets spent. + let consumed: ReturnType = null consumeQueuedStartupAndClearSleepingRecord( tabs[0]!.id, - () => consumed, + (consumeTabId) => { + consumed = useAppStore.getState().consumeTabStartupCommand(consumeTabId) + return consumed + }, (identityPaneKey) => useAppStore.getState().sleepingAgentSessionsByPaneKey[identityPaneKey], useAppStore.getState().clearSleepingAgentSession ) + expect(consumed).not.toBeNull() + expect(consumed!.resumeProviderSession).toEqual(providerSession) expect(useAppStore.getState().sleepingAgentSessionsByPaneKey[paneKey]).toBeUndefined() } else { // Later captures are stale replays of the already claimed session and