diff --git a/src/renderer/src/runtime/web-session-tabs-sync.test.ts b/src/renderer/src/runtime/web-session-tabs-sync.test.ts index 146bb5ab6bc..89e0b6fda2b 100644 --- a/src/renderer/src/runtime/web-session-tabs-sync.test.ts +++ b/src/renderer/src/runtime/web-session-tabs-sync.test.ts @@ -3102,28 +3102,30 @@ describe('applyWebSessionTabsSnapshot', () => { } } + const state = makeState({ + activeTabId: mirroredTabId, + activeTabIdByWorktree: { [WT]: mirroredTabId }, + activeTabType: 'terminal', + activeTabTypeByWorktree: { [WT]: 'terminal' }, + tabsByWorktree: { + [WT]: [ + { + id: mirroredTabId, + ptyId: 'remote:web-env-1@@terminal-2', + worktreeId: WT, + title: 'right pane', + customTitle: null, + color: null, + sortOrder: 0, + createdAt: NOW + } + ] + }, + terminalLayoutsByTabId: { [mirroredTabId]: currentLayout } + }) + const patch = applyWebSessionTabsSnapshot( - makeState({ - activeTabId: mirroredTabId, - activeTabIdByWorktree: { [WT]: mirroredTabId }, - activeTabType: 'terminal', - activeTabTypeByWorktree: { [WT]: 'terminal' }, - tabsByWorktree: { - [WT]: [ - { - id: mirroredTabId, - ptyId: 'remote:web-env-1@@terminal-2', - worktreeId: WT, - title: 'right pane', - customTitle: null, - color: null, - sortOrder: 0, - createdAt: NOW - } - ] - }, - terminalLayoutsByTabId: { [mirroredTabId]: currentLayout } - }), + state, makeSnapshot([ { type: 'terminal', @@ -3163,7 +3165,11 @@ describe('applyWebSessionTabsSnapshot', () => { ptyId: 'remote:web-env-1@@terminal-2', title: 'right pane' }) + // No layout patch at all, and the effective layout keeps the local active leaf. expect(patch.terminalLayoutsByTabId).toBeUndefined() + expect({ ...state, ...patch }.terminalLayoutsByTabId[mirroredTabId]?.activeLeafId).toBe( + SECOND_LEAF_ID + ) }) it('removes a null-pty pending activation tab when the host publishes the initial terminal', () => { @@ -3540,6 +3546,7 @@ describe('applyWebSessionTabsSnapshot', () => { title: 'Example Domain' } ]) + // Absent key, not a missing handle: the seeded { ENV, 'host-browser-page' } handle matched. expect(patch.remoteBrowserPageHandlesByPageId).toBeUndefined() expect(patch.unifiedTabsByWorktree?.[WT]?.map((tab) => tab.id)).toEqual([ 'local-browser-unified' diff --git a/src/renderer/src/runtime/web-session-tabs-sync.ts b/src/renderer/src/runtime/web-session-tabs-sync.ts index d9281076255..aa102eb11a5 100644 --- a/src/renderer/src/runtime/web-session-tabs-sync.ts +++ b/src/renderer/src/runtime/web-session-tabs-sync.ts @@ -1215,6 +1215,8 @@ function buildMirroredBrowserTabs( browserRuntimeEnvironmentId: environmentId, viewportPresetId: existing?.page.viewportPresetId ?? null } + // Why: reuse hinges on browserPageEqual comparing workspaceId — the removed-workspace + // page-list cleanup gates on page.workspaceId matching this entry's workspace.id. const page = existing && browserPageEqual(existing.page, nextPage) ? existing.page : nextPage const workspace: BrowserWorkspace = { id: workspaceId,