From fc85866bed2fafde5dc00685abefd72142db5d2e Mon Sep 17 00:00:00 2001 From: Brennan Benson <79079362+brennanb2025@users.noreply.github.com> Date: Tue, 10 Nov 2026 03:39:53 -0800 Subject: [PATCH] fix(browser): scope inventory ownership work to browser workspaces --- config/tsconfig.node.json | 1 + config/tsconfig.test.pane-launch.json | 1 + .../browser-page-inventory.test.ts | 26 ++++++++++++++++--- .../mobile-session-inputs.ts | 5 +++- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/config/tsconfig.node.json b/config/tsconfig.node.json index 563748d8a33..12ae30f3da8 100644 --- a/config/tsconfig.node.json +++ b/config/tsconfig.node.json @@ -39,6 +39,7 @@ "../src/types/**/*" ], "exclude": [ + "../src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts", "../src/main/runtime/orchestration/terminal-authority/structured-sessions/structured-chat-coordinator-mail.test.ts", "../src/main/runtime/rpc/methods/orchestration/orchestration-check-ambiguous-caller.test.ts" ], diff --git a/config/tsconfig.test.pane-launch.json b/config/tsconfig.test.pane-launch.json index 63896e6d839..64a0453fe2b 100644 --- a/config/tsconfig.test.pane-launch.json +++ b/config/tsconfig.test.pane-launch.json @@ -1,6 +1,7 @@ { "extends": "./tsconfig.web.json", "include": [ + "../src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts", "../src/renderer/src/lib/agent-session/launch/new-tab/launch-agent-in-new-tab-main-surface.test.ts", "../src/main/runtime/orchestration/terminal-authority/structured-sessions/structured-chat-coordinator-mail.test.ts", "../src/main/runtime/rpc/methods/orchestration/orchestration-check-ambiguous-caller.test.ts", diff --git a/src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts b/src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts index f5c26df2c75..9a1301a31fc 100644 --- a/src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts +++ b/src/main/runtime/orca-runtime-tests/browser-page-inventory.test.ts @@ -87,6 +87,7 @@ function fixture(runtime = createRuntime()) { }), tabSwitch: vi.fn(async (_index, _worktree, id) => ({ browserPageId: id, switched: 0 })) } + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: this bridge implements the list, registration and switch methods reached by the runtime. runtime.setAgentBrowserBridge(bridge as never) electronMocks.webContents.fromId.mockReturnValue({ isDestroyed: () => false }) const sync = (snapshots = publication(), extra: Partial = {}) => @@ -136,6 +137,7 @@ describe('accepted saved browser page inventory', () => { }) const window = { isDestroyed: () => false, webContents: contents } electronMocks.BrowserWindow.fromId.mockReturnValue(window) + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: readiness only needs this window's IPC emitter and send transport. watchBrowserMainWindowReadiness(window as never) ipc.emit('browser:tabRequestsReady') expect(await runtime.browserTabSwitch({ page: 'A' })).toMatchObject({ @@ -206,6 +208,7 @@ describe('accepted saved browser page inventory', () => { }) const { runtimeStore } = makeRuntimeStoreWithWorkspaceSession(session) const remoteRepo = { ...store.getRepo(TEST_REPO_ID)!, connectionId: 'ssh-1' } + // oxlint-disable-next-line typescript/consistent-type-assertions -- SAFETY: the existing runtime store fixture supplies the methods used by hydration and catalog reads. const runtime = new OrcaRuntimeService({ ...runtimeStore, getRepos: () => [remoteRepo], @@ -219,9 +222,13 @@ describe('accepted saved browser page inventory', () => { listProcesses: async () => [] }) const { sync, list } = fixture(runtime) + electronMocks.BrowserWindow.fromId.mockReturnValue({ isDestroyed: () => false }) sync() await vi.advanceTimersByTimeAsync(100) const before = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`) + expect(before.tabs).toEqual( + expect.arrayContaining([expect.objectContaining({ browserPageId: 'C' })]) + ) const events: RuntimeMobileSessionTabsResult[] = [] const unsubscribe = runtime.onMobileSessionTabsChanged((snapshot) => events.push(snapshot)) sync([], { unchangedMobileSessionWorktrees: [TEST_WORKTREE_ID] }) @@ -275,7 +282,7 @@ describe('accepted saved browser page inventory', () => { await vi.advanceTimersByTimeAsync(100) const initial = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`) expect(initial.tabs).toEqual( - expect.arrayContaining([expect.objectContaining({ title: 'Before' })]) + expect.arrayContaining([expect.objectContaining({ browserPageId: 'C', title: 'C' })]) ) const events: RuntimeMobileSessionTabsResult[] = [] const unsubscribe = runtime.onMobileSessionTabsChanged((snapshot) => events.push(snapshot)) @@ -313,9 +320,20 @@ describe('accepted saved browser page inventory', () => { paneTitle: null } ] - const terminalState = { + const terminalState: Partial = { tabsByWorktree: { - [TEST_WORKTREE_ID]: [{ id: 'terminal', title: 'Before', customTitle: null, ptyId: null }] + [TEST_WORKTREE_ID]: [ + { + id: 'terminal', + worktreeId: TEST_WORKTREE_ID, + title: 'Before', + customTitle: null, + ptyId: null, + color: null, + createdAt: 1, + sortOrder: 0 + } + ] }, terminalLayoutsByTabId: { terminal: { @@ -324,7 +342,7 @@ describe('accepted saved browser page inventory', () => { expandedLeafId: null } } - } as Partial + } sync(publication(undefined, undefined, terminalState), { tabs, leaves }) await vi.advanceTimersByTimeAsync(100) const initial = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`) diff --git a/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts b/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts index 824544857cd..bd54e58224a 100644 --- a/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts +++ b/src/renderer/src/runtime/sync-runtime-graph/mobile-session-inputs.ts @@ -198,7 +198,10 @@ export function buildMobileSessionWorktreeInputs( worktreeInstanceId: resolveWorktreeInstanceId(state, worktreeId), terminalTabs, browserWorkspaces, - browserRuntimeEnvironmentId: runtimeEnvironmentIdOrLocalUnlessTwin(state, worktreeId), + browserRuntimeEnvironmentId: + browserWorkspaces.length > 0 + ? runtimeEnvironmentIdOrLocalUnlessTwin(state, worktreeId) + : null, unifiedTabs: state.unifiedTabsByWorktree[worktreeId] ?? EMPTY_WORKTREE_UNIFIED_TABS, groups: state.groupsByWorktree[worktreeId] ?? EMPTY_WORKTREE_TAB_GROUPS, tabBarOrder: state.tabBarOrderByWorktree[worktreeId],