Files
orca/mobile/src/session/opened-mobile-session-tab.ts
T
Neil 6194a7a1b6 test: drop private-internal and boundary-census tests with behavioral owners (#23941)
Fourth audit wave, cut short by a session restart, so this lands the verified
subset rather than the full batch.

Removes private-predicate cases whose behavior is already covered through the
module's real entry point, and de-exports the seams they reached for. Also drops
three whole files whose every case was a duplicate or a call-shape grep.

The source-grep vein is close to exhausted. One auditor reviewed 15 remaining
flagged files and deleted nothing: what is left is mostly legitimate
architectural ratchets that no type checker and no behavioral test can reach —
AST fences banning `as`/`any` in an RPC operation region, discovered-vs-listed
set equality over subscription sites, count ceilings on unchecked reply readers,
and assertions on generated WebView bundles (no CDN URL, no `</script`
tokenizer escape, parses at the Chrome 74 floor). Those stay.
2026-09-29 16:35:49 -07:00

105 lines
3.6 KiB
TypeScript

export type OpenedMobileSessionTabCandidate = {
id: string
type: string
mode?: unknown
relativePath?: unknown
}
export type OpenedMobileSessionTabActivationState = {
activated: boolean
activationSeq: number
latestActivationSeq: number
sourceTerminalHandle: string | null
activeTerminalHandle: string | null
sourceSessionTabId?: string | null
activeSessionTabId?: string | null
activeTabType: string | null
}
export function findOpenedMobileSessionTab<T extends OpenedMobileSessionTabCandidate>(
tabs: readonly T[],
relativePath: string,
options: { preferMode?: 'diff' | 'edit' } = {}
): T | null {
const matches = tabs.filter(
(tab) => tab.type !== 'browser' && tab.type !== 'terminal' && tab.relativePath === relativePath
)
if (matches.length === 0) {
return null
}
if (options.preferMode === 'diff') {
return matches.find((tab) => tab.mode === 'diff') ?? matches[0] ?? null
}
return matches.find((tab) => tab.mode !== 'diff') ?? matches[0] ?? null
}
export type OpenedSourceControlDiffActivationState = {
activated: boolean
activationSeq: number
latestActivationSeq: number
}
export type ActivateOpenedSourceControlDiffTabOptions<T extends OpenedMobileSessionTabCandidate> = {
relativePath: string
activeTabIdAtTap: string | null
fetchSessionTabs: () => Promise<void>
getTabs: () => readonly T[]
getActiveTabId: () => string | null
getActivationState: () => OpenedSourceControlDiffActivationState
switchSessionTab: (tab: T) => void
}
// Activation for a diff tab opened by tapping a changed file in the docked
// source-control panel. Unlike the terminal path there is no "source terminal"
// to guard against; instead we cancel if the user moved to a different tab
// after the tap (no focus steal) and treat the diff already being active as
// success. Returns true once activation is settled so retries can stop.
export async function activateOpenedSourceControlDiffTab<T extends OpenedMobileSessionTabCandidate>(
options: ActivateOpenedSourceControlDiffTabOptions<T>
): Promise<boolean> {
const isSuperseded = (): boolean => {
const state = options.getActivationState()
return state.activated || state.activationSeq !== state.latestActivationSeq
}
if (isSuperseded()) {
return false
}
await options.fetchSessionTabs()
if (isSuperseded()) {
return false
}
const opened = findOpenedMobileSessionTab(options.getTabs(), options.relativePath, {
preferMode: 'diff'
})
if (!opened) {
return false
}
const activeTabId = options.getActiveTabId()
// The post-open snapshot may already show the opened diff as active; that is
// success, not a focus steal, so settle without re-activating.
if (activeTabId === opened.id) {
return true
}
// No focus steal: if the user moved to a different tab after the tap, leave
// them there instead of yanking focus back to the diff.
if (activeTabId !== options.activeTabIdAtTap) {
return false
}
options.switchSessionTab(opened)
return true
}
export function shouldActivateOpenedMobileSessionTab(
state: OpenedMobileSessionTabActivationState
): boolean {
const sourceStillActive =
state.activeTabType === 'agent-session'
? state.sourceSessionTabId !== null &&
state.sourceSessionTabId !== undefined &&
state.activeSessionTabId === state.sourceSessionTabId
: state.activeTabType === 'terminal' &&
state.sourceTerminalHandle !== null &&
state.activeTerminalHandle === state.sourceTerminalHandle
return !state.activated && state.activationSeq === state.latestActivationSeq && sourceStillActive
}