From 341307dea0a50de108d2e26e69e12f23840cdd12 Mon Sep 17 00:00:00 2001 From: Jinwoo-H Date: Thu, 20 Aug 2026 02:32:30 -0400 Subject: [PATCH] test(automations): reproduce hidden completed run session (STA-4870) --- .../lib/automation-terminal-ownership.test.ts | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/renderer/src/lib/automation-terminal-ownership.test.ts b/src/renderer/src/lib/automation-terminal-ownership.test.ts index 9528bbdf384..f9c501e105c 100644 --- a/src/renderer/src/lib/automation-terminal-ownership.test.ts +++ b/src/renderer/src/lib/automation-terminal-ownership.test.ts @@ -23,10 +23,12 @@ type OwnershipState = Pick< | 'terminalLayoutsByTabId' | 'lastTerminalInputAtByPaneKey' | 'closeTab' + | 'shutdownCompletedAgentPaneForHibernation' > function createStore() { const closeTab = vi.fn() + const shutdownCompletedAgentPaneForHibernation = vi.fn().mockResolvedValue(undefined) let state: OwnershipState = { activeWorktreeId: 'other-worktree', activeTabId: 'other-tab', @@ -50,7 +52,8 @@ function createStore() { [TAB_ID]: singlePaneLayoutSnapshot(LEAF_ID, PTY_ID) }, lastTerminalInputAtByPaneKey: {}, - closeTab + closeTab, + shutdownCompletedAgentPaneForHibernation } const listeners = new Set<(state: AppState, previousState: AppState) => void>() const store: AutomationTerminalOwnershipStore = { @@ -67,7 +70,13 @@ function createStore() { listener(state as unknown as AppState, previousState as unknown as AppState) } } - return { closeTab, getState: () => state, store, update } + return { + closeTab, + getState: () => state, + shutdownCompletedAgentPaneForHibernation, + store, + update + } } function own( @@ -89,23 +98,20 @@ function own( describe('automation terminal ownership', () => { beforeEach(() => vi.clearAllMocks()) - it('closes the exact fresh desktop tab once after the PTY exit binding is cleared', () => { - const { closeTab, store, update } = createStore() + it('hibernates the exact fresh desktop session once after automation completion', async () => { + const { closeTab, shutdownCompletedAgentPaneForHibernation, store } = createStore() const ownership = own(store) - update({ - ptyIdsByTabId: { [TAB_ID]: [] }, - tabsByWorktree: { - [WORKTREE_ID]: [{ ...store.getState().tabsByWorktree[WORKTREE_ID]![0]!, ptyId: null }] - } - }) - expect(ownership.finalize()).toBe(true) - expect(ownership.finalize()).toBe(false) - expect(closeTab).toHaveBeenCalledTimes(1) - expect(closeTab).toHaveBeenCalledWith(TAB_ID, { - recordInteraction: false, - reason: 'cleanup' + expect(await ownership.finalize()).toBe(true) + expect(await ownership.finalize()).toBe(false) + expect(shutdownCompletedAgentPaneForHibernation).toHaveBeenCalledOnce() + expect(shutdownCompletedAgentPaneForHibernation).toHaveBeenCalledWith(WORKTREE_ID, { + paneKey: PANE_KEY, + tabId: TAB_ID, + leafId: LEAF_ID, + ptyId: PTY_ID }) + expect(closeTab).not.toHaveBeenCalled() }) it('preserves a tab activated after launch even when focus later moves away', () => {