Fix remote browser/editor tab props persistence (#5847)
Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
@@ -9,6 +9,7 @@ import { ipcMain } from 'electron'
|
||||
import type {
|
||||
FolderWorkspace,
|
||||
ProjectGroup,
|
||||
Tab,
|
||||
TerminalLayoutSnapshot,
|
||||
WorktreeLineage,
|
||||
WorktreeMeta,
|
||||
@@ -10860,8 +10861,18 @@ describe('OrcaRuntimeService', () => {
|
||||
},
|
||||
tabGroups: {
|
||||
[TEST_WORKTREE_ID]: [
|
||||
{ id: 'group-left', worktreeId: TEST_WORKTREE_ID, activeTabId: 'host-tab', tabOrder: ['host-tab'] },
|
||||
{ id: 'group-right', worktreeId: TEST_WORKTREE_ID, activeTabId: 'host-tab-2', tabOrder: ['host-tab-2'] }
|
||||
{
|
||||
id: 'group-left',
|
||||
worktreeId: TEST_WORKTREE_ID,
|
||||
activeTabId: 'host-tab',
|
||||
tabOrder: ['host-tab']
|
||||
},
|
||||
{
|
||||
id: 'group-right',
|
||||
worktreeId: TEST_WORKTREE_ID,
|
||||
activeTabId: 'host-tab-2',
|
||||
tabOrder: ['host-tab-2']
|
||||
}
|
||||
]
|
||||
},
|
||||
tabGroupLayouts: {
|
||||
@@ -10987,6 +10998,95 @@ describe('OrcaRuntimeService', () => {
|
||||
expect(surface?.type === 'terminal' && surface.isPinned).toBe(true)
|
||||
})
|
||||
|
||||
it('persists headless browser tab color + pin and surfaces them through a cold rehydrate', async () => {
|
||||
const browserTab: Tab = {
|
||||
id: 'browser-page-1',
|
||||
entityId: 'browser-page-1',
|
||||
groupId: 'group-1',
|
||||
worktreeId: TEST_WORKTREE_ID,
|
||||
contentType: 'browser',
|
||||
label: 'Live Browser',
|
||||
customLabel: null,
|
||||
color: null,
|
||||
sortOrder: 1,
|
||||
createdAt: 2,
|
||||
isPreview: false,
|
||||
isPinned: false
|
||||
}
|
||||
const session = makeWorkspaceSessionWithHeadlessTerminal({
|
||||
unifiedTabs: { [TEST_WORKTREE_ID]: [browserTab] },
|
||||
tabGroups: {
|
||||
[TEST_WORKTREE_ID]: [
|
||||
{
|
||||
id: 'group-1',
|
||||
worktreeId: TEST_WORKTREE_ID,
|
||||
activeTabId: 'browser-page-1',
|
||||
tabOrder: ['browser-page-1']
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
const { runtimeStore, getSession } = makeRuntimeStoreWithWorkspaceSession(session)
|
||||
const runtime = new OrcaRuntimeService(runtimeStore as never)
|
||||
runtime.setOffscreenBrowserBackend({ createTab: vi.fn(), closeTab: vi.fn() })
|
||||
runtime.setAgentBrowserBridge({
|
||||
tabList: vi.fn(() => ({
|
||||
tabs: [
|
||||
{
|
||||
browserPageId: 'browser-page-1',
|
||||
index: 0,
|
||||
url: 'https://example.com/',
|
||||
title: 'Live Browser',
|
||||
active: true
|
||||
}
|
||||
]
|
||||
}))
|
||||
} as never)
|
||||
|
||||
await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`)
|
||||
await runtime.setMobileSessionTabProps(`id:${TEST_WORKTREE_ID}`, {
|
||||
tabId: 'browser-page-1',
|
||||
color: '#3b82f6',
|
||||
isPinned: true
|
||||
})
|
||||
|
||||
const persisted = getSession().unifiedTabs?.[TEST_WORKTREE_ID]?.find(
|
||||
(tab) => tab.id === 'browser-page-1'
|
||||
)
|
||||
expect(persisted?.color).toBe('#3b82f6')
|
||||
expect(persisted?.isPinned).toBe(true)
|
||||
|
||||
runtime['mobileSessionTabsByWorktree'].delete(TEST_WORKTREE_ID)
|
||||
runtime['hydrateHeadlessMobileSessionTabsFromWorkspaceSession'](TEST_WORKTREE_ID)
|
||||
const rehydrated = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`)
|
||||
const surface = rehydrated.tabs.find(
|
||||
(tab) => tab.type === 'browser' && tab.id === 'browser-page-1'
|
||||
)
|
||||
expect(surface?.type === 'browser' && surface.color).toBe('#3b82f6')
|
||||
expect(surface?.type === 'browser' && surface.isPinned).toBe(true)
|
||||
|
||||
await runtime.setMobileSessionTabProps(`id:${TEST_WORKTREE_ID}`, {
|
||||
tabId: 'browser-page-1',
|
||||
color: null,
|
||||
isPinned: false
|
||||
})
|
||||
|
||||
const cleared = getSession().unifiedTabs?.[TEST_WORKTREE_ID]?.find(
|
||||
(tab) => tab.id === 'browser-page-1'
|
||||
)
|
||||
expect(cleared?.color).toBeNull()
|
||||
expect(cleared?.isPinned).toBe(false)
|
||||
|
||||
runtime['mobileSessionTabsByWorktree'].delete(TEST_WORKTREE_ID)
|
||||
runtime['hydrateHeadlessMobileSessionTabsFromWorkspaceSession'](TEST_WORKTREE_ID)
|
||||
const rehydratedCleared = await runtime.listMobileSessionTabs(`id:${TEST_WORKTREE_ID}`)
|
||||
const clearedSurface = rehydratedCleared.tabs.find(
|
||||
(tab) => tab.type === 'browser' && tab.id === 'browser-page-1'
|
||||
)
|
||||
expect(clearedSurface?.type === 'browser' && clearedSurface.color).toBeNull()
|
||||
expect(clearedSurface?.type === 'browser' && clearedSurface.isPinned).toBe(false)
|
||||
})
|
||||
|
||||
it('still persists tab props in serve mode after syncWindowGraph(0) (gate does not fire)', async () => {
|
||||
// Why: the renderer-authoritative gate uses getAvailableAuthoritativeWindow,
|
||||
// and serve startup calls syncWindowGraph(0,...) which sets authoritativeWindowId=0.
|
||||
|
||||
@@ -95,12 +95,14 @@ import type {
|
||||
ProjectGroupImportMode,
|
||||
ProjectGroupImportResult,
|
||||
MemorySnapshot,
|
||||
Tab,
|
||||
TabGroupLayoutNode,
|
||||
TerminalLayoutSnapshot,
|
||||
TerminalPaneLayoutNode,
|
||||
TerminalTab,
|
||||
TuiAgent,
|
||||
WorkspaceCreateTelemetrySource,
|
||||
WorkspaceSessionState,
|
||||
DirEntry
|
||||
} from '../../shared/types'
|
||||
import type { RuntimeClientEvent } from '../../shared/runtime-client-events'
|
||||
@@ -3174,20 +3176,38 @@ export class OrcaRuntimeService {
|
||||
if (!this.offscreenBrowserBackend || !this.agentBrowserBridge?.tabList) {
|
||||
return []
|
||||
}
|
||||
return this.agentBrowserBridge.tabList(worktreeId).tabs.map((tab) => ({
|
||||
type: 'browser' as const,
|
||||
// Why: an offscreen page has no separate workspace identity, so the page id
|
||||
// is its own workspace id (matches the server's browserWorkspaceId fallback).
|
||||
id: tab.browserPageId,
|
||||
title: tab.title || tab.url || 'Browser',
|
||||
browserWorkspaceId: tab.browserPageId,
|
||||
browserPageId: tab.browserPageId,
|
||||
url: tab.url || 'about:blank',
|
||||
loading: false,
|
||||
canGoBack: false,
|
||||
canGoForward: false,
|
||||
isActive: tab.active === true
|
||||
}))
|
||||
return this.agentBrowserBridge.tabList(worktreeId).tabs.map((tab) => {
|
||||
const persistedProps = this.getPersistedUnifiedSessionTabProps(worktreeId, tab.browserPageId)
|
||||
return {
|
||||
type: 'browser' as const,
|
||||
// Why: an offscreen page has no separate workspace identity, so the page id
|
||||
// is its own workspace id (matches the server's browserWorkspaceId fallback).
|
||||
id: tab.browserPageId,
|
||||
title: tab.title || tab.url || 'Browser',
|
||||
browserWorkspaceId: tab.browserPageId,
|
||||
browserPageId: tab.browserPageId,
|
||||
url: tab.url || 'about:blank',
|
||||
loading: false,
|
||||
canGoBack: false,
|
||||
canGoForward: false,
|
||||
...(persistedProps ? { color: persistedProps.color } : {}),
|
||||
...(persistedProps ? { isPinned: persistedProps.isPinned === true } : {}),
|
||||
isActive: tab.active === true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private getPersistedUnifiedSessionTabProps(
|
||||
worktreeId: string,
|
||||
tabId: string
|
||||
): Pick<Tab, 'color' | 'isPinned'> | null {
|
||||
const tab =
|
||||
this.store
|
||||
?.getWorkspaceSession?.()
|
||||
?.unifiedTabs?.[worktreeId]?.find(
|
||||
(candidate) => candidate.id === tabId || candidate.entityId === tabId
|
||||
) ?? null
|
||||
return tab ? { color: tab.color, isPinned: tab.isPinned } : null
|
||||
}
|
||||
|
||||
private collectPersistedTerminalLeafIds(layout: TerminalLayoutSnapshot | undefined): string[] {
|
||||
@@ -3997,12 +4017,12 @@ export class OrcaRuntimeService {
|
||||
const hostTabId = snapshot
|
||||
? (this.resolveMobileSessionHostTabId(snapshot, args.tabId) ?? args.tabId)
|
||||
: args.tabId
|
||||
this.persistHeadlessTerminalTabProps(worktreeId, hostTabId, args)
|
||||
this.applyHeadlessTerminalTabPropsToSnapshot(worktreeId, hostTabId, args)
|
||||
this.persistHeadlessSessionTabProps(worktreeId, hostTabId, args)
|
||||
this.applyHeadlessSessionTabPropsToSnapshot(worktreeId, hostTabId, args)
|
||||
return { updated: true }
|
||||
}
|
||||
|
||||
private persistHeadlessTerminalTabProps(
|
||||
private persistHeadlessSessionTabProps(
|
||||
worktreeId: string,
|
||||
tabId: string,
|
||||
props: { color?: string | null; isPinned?: boolean }
|
||||
@@ -4012,12 +4032,11 @@ export class OrcaRuntimeService {
|
||||
return
|
||||
}
|
||||
const tabs = session.tabsByWorktree[worktreeId]
|
||||
if (!tabs?.some((tab) => tab.id === tabId)) {
|
||||
return
|
||||
}
|
||||
this.store.setWorkspaceSession({
|
||||
...session,
|
||||
tabsByWorktree: {
|
||||
const nextSession: WorkspaceSessionState = { ...session }
|
||||
let changed = false
|
||||
if (tabs?.some((tab) => tab.id === tabId)) {
|
||||
changed = true
|
||||
nextSession.tabsByWorktree = {
|
||||
...session.tabsByWorktree,
|
||||
[worktreeId]: tabs.map((tab) =>
|
||||
tab.id === tabId
|
||||
@@ -4029,10 +4048,32 @@ export class OrcaRuntimeService {
|
||||
: tab
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const unifiedTabs = session.unifiedTabs?.[worktreeId]
|
||||
if (unifiedTabs?.some((tab) => tab.id === tabId || tab.entityId === tabId)) {
|
||||
changed = true
|
||||
nextSession.unifiedTabs = {
|
||||
...session.unifiedTabs,
|
||||
[worktreeId]: unifiedTabs.map((tab) =>
|
||||
tab.id === tabId || tab.entityId === tabId
|
||||
? {
|
||||
...tab,
|
||||
...(props.color !== undefined ? { color: props.color } : {}),
|
||||
...(props.isPinned !== undefined ? { isPinned: props.isPinned } : {})
|
||||
}
|
||||
: tab
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!changed) {
|
||||
return
|
||||
}
|
||||
this.store.setWorkspaceSession(nextSession)
|
||||
}
|
||||
|
||||
private applyHeadlessTerminalTabPropsToSnapshot(
|
||||
private applyHeadlessSessionTabPropsToSnapshot(
|
||||
worktreeId: string,
|
||||
tabId: string,
|
||||
props: { color?: string | null; isPinned?: boolean }
|
||||
@@ -4041,12 +4082,9 @@ export class OrcaRuntimeService {
|
||||
if (!snapshot) {
|
||||
return
|
||||
}
|
||||
// Why: only terminal tabs persist color/pin today (browser/editor are
|
||||
// tracked in #5729). Applying to a browser surface here would show a
|
||||
// transient that reverts on the next rebuild — apply only what we persist.
|
||||
let changed = false
|
||||
const tabs = snapshot.tabs.map((tab) => {
|
||||
if (tab.type !== 'terminal' || tab.parentTabId !== tabId) {
|
||||
if (this.getMobileSessionTopLevelTabId(tab) !== tabId) {
|
||||
return tab
|
||||
}
|
||||
changed = true
|
||||
@@ -4069,6 +4107,10 @@ export class OrcaRuntimeService {
|
||||
this.emitMobileSessionTabsSnapshot(nextSnapshot)
|
||||
}
|
||||
|
||||
private getMobileSessionTopLevelTabId(tab: RuntimeMobileSessionSnapshotTab): string {
|
||||
return tab.type === 'terminal' ? tab.parentTabId : tab.id
|
||||
}
|
||||
|
||||
// Merge the client's pane structure into the persisted tab layout. PTY
|
||||
// bindings and active leaf stay host-owned; only ratios/expand/titles change.
|
||||
// terminalLayoutsByTabId is keyed by tab id (worktree-independent).
|
||||
|
||||
Reference in New Issue
Block a user