Files
orca/tests/e2e/structured-chat-tab-lifetime.test-fixture.ts
Neil 19043a3d76 refactor(mobile): organize pairing, session, RPC and host owners (#39846)
* refactor(mobile): give relay and encryption concrete owners

* refactor(mobile): organize session and review feature owners

* refactor(mobile): organize RPC and host ownership

* test(mobile): point render fixtures at concrete owners

* refactor(mobile): use explicit type-only owner imports
2026-11-08 07:19:05 -08:00

95 lines
3.3 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Frozen phone policy from 47713a90d85; only imports and exported function names differ.
type SessionTabLike = {
id: string
isActive: boolean
}
export type ActiveSessionTabSelectionSource =
| 'snapshot'
| 'pending-tab'
| 'selected-tab'
| 'navigation-intent'
export type ResolveActiveSessionTabResult<T extends SessionTabLike> = {
activeTab: T | null
selectionSource: ActiveSessionTabSelectionSource
clearPendingActiveSessionTabId: boolean
retainSelectedSessionTabId: boolean
}
export function resolveActiveSessionTab47713<T extends SessionTabLike>(
tabs: readonly T[],
opts: {
pendingActiveSessionTabId: string | null
selectedSessionTabId: string | null
navigationIntent?: 'follow'
}
): ResolveActiveSessionTabResult<T> {
const snapshotActive = tabs.find((tab) => tab.isActive) ?? tabs[0] ?? null
const pendingActiveSessionTabId = opts.pendingActiveSessionTabId
// Why: targeted follow is the only host action allowed to supersede phone-local intent.
if (opts.navigationIntent === 'follow') {
return {
activeTab: snapshotActive,
selectionSource: 'navigation-intent',
clearPendingActiveSessionTabId: pendingActiveSessionTabId !== null,
retainSelectedSessionTabId: false
}
}
if (pendingActiveSessionTabId) {
if (snapshotActive?.id === pendingActiveSessionTabId) {
return {
activeTab: snapshotActive,
selectionSource: 'snapshot',
clearPendingActiveSessionTabId: true,
retainSelectedSessionTabId: false
}
}
const pendingTab = tabs.find((tab) => tab.id === pendingActiveSessionTabId) ?? null
if (pendingTab) {
return {
activeTab: pendingTab,
selectionSource: 'pending-tab',
clearPendingActiveSessionTabId: false,
retainSelectedSessionTabId: false
}
}
}
const clearPendingActiveSessionTabId = pendingActiveSessionTabId !== null
const selectedTab = opts.selectedSessionTabId
? (tabs.find((tab) => tab.id === opts.selectedSessionTabId) ?? null)
: null
return {
activeTab: selectedTab ?? snapshotActive,
selectionSource: selectedTab ? 'selected-tab' : 'snapshot',
clearPendingActiveSessionTabId,
// Why: transient browser guest swaps must not erase the device's explicit pick.
retainSelectedSessionTabId: Boolean(opts.selectedSessionTabId) && !selectedTab
}
}
import { parsePaneKey } from '../../src/shared/workspace-layout/stable-pane-id'
import {
structuredAgentSessionPaneKey,
structuredAgentSessionTabId
} from '../../src/shared/agent-session/view/structured-agent-session-projection'
import type { MobileSessionTab } from '../../mobile/src/session/tabs/mobile-session-tabs'
// Keep native/web navigation’s pane lookup separate: importing the native sibling by name on web resolves back to the web file itself.
export function notificationPaneTab47713(tabs: readonly MobileSessionTab[], paneKey: string) {
const pane = parsePaneKey(paneKey)
if (!pane) {
return undefined
}
return tabs.find((tab) =>
tab.type === 'terminal'
? (tab.parentTabId ?? tab.id) === pane.tabId && tab.leafId === pane.leafId
: tab.type === 'agent-session' &&
(tab.id === pane.tabId ||
structuredAgentSessionPaneKey(
structuredAgentSessionTabId(tab.sessionId),
tab.sessionId
) === paneKey)
)
}