fix(browser): scope inventory ownership work to browser workspaces

This commit is contained in:
Brennan Benson
2026-11-10 03:39:53 -08:00
parent 445415c340
commit fc85866bed
4 changed files with 28 additions and 5 deletions
+1
View File
@@ -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"
],
+1
View File
@@ -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",
@@ -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<RuntimeSyncWindowGraph> = {}) =>
@@ -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<AppState> = {
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<AppState>
}
sync(publication(undefined, undefined, terminalState), { tabs, leaves })
await vi.advanceTimersByTimeAsync(100)
const initial = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`)
@@ -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],