Files
orca/mobile/src/mobile-web-shell/MobileWebShellScreen.test.tsx
T
OrcaWinandOrcaWin 7d6603aa17 [comment audit] Complete repository-wide comment cleanup (#33249)
* [comment audit] Align legacy failure-read counts with cached display

* [comment audit] Condense shared provider lifecycle and browser recovery comments [skip ci]

* [comment audit] Condense shared generation, path and preview comments [skip ci]

* [comment audit] Condense host, file and Git contract rationale [skip ci]

* [comment audit] Tighten Git lifecycle and provider contract comments [skip ci]

* [comment audit] Clarify shared host authority and launch isolation [skip ci]

* [comment audit] simplify local access mobile and native chat contracts [skip ci]

* [comment audit] simplify native chat presentation and state contracts [skip ci]

* [comment audit] simplify native runtime and provider contracts [skip ci]

* [comment audit] simplify migration and orchestration contracts [skip ci]

* [comment audit] simplify plugin trust and process capture rationale [skip ci]

* [comment audit] simplify terminal delivery and remote compatibility rationale [skip ci]

* [comment audit] clarify remote recovery and launch wire rationale [skip ci]

* [comment audit] shorten shared RPC compatibility and runtime evidence comments [skip ci]

* [comment audit] simplify secure storage shell startup and sidebar rationale [skip ci]

* [comment audit] clarify sidebar, skill and SSH invariants [skip ci]

* [comment audit] condense structured chat delivery and timing rationale [skip ci]

* [comment audit] condense terminal replay and telemetry invariants [skip ci]

* [comment audit] clarify launch permission and terminal delivery rationale [skip ci]

* [comment audit] clarify workspace ownership and layout contracts [skip ci]

* [comment audit] wait for fitted and painted SSH terminal links

* [comment audit] clarify layout persistence and session ownership [skip ci]

* [comment audit] clarify host routing and workspace lifecycle contracts [skip ci]

* [comment audit] clarify startup persistence and app lifetime comments [skip ci]

* [comment audit] clarify recovery and activity boundaries [skip ci]

* [comment audit] condense activity and artifact invariants [skip ci]

* [comment audit] condense automation authority contracts [skip ci]

* [comment audit] simplify automation scheduling and history contracts [skip ci]

* [comment audit] clarify browser chrome and annotation lifecycles [skip ci]

* [comment audit] clarify browser routing and retained guest ownership [skip ci]

* [comment audit] clarify browser recovery and document ownership comments [skip ci]

* [comment audit] restore hosted runners required by native IME fixtures

* [comment audit] shorten preview, palette and dashboard invariants [skip ci]

* [comment audit] clarify terminal preview, dashboard and retention comments [skip ci]

* [comment audit] clarify diff-note recovery and editor lifecycle comments [skip ci]

* [comment audit] shorten rich-text and combined-diff ownership comments [skip ci]

* [comment audit] shorten autosave, draft recovery and model ownership comments [skip ci]

* [comment audit] shorten save-queue, notebook and Markdown constraints [skip ci]

* [comment audit] shorten Monaco, PDF and rich Markdown safeguards [skip ci]

* [comment audit] clarify rich Markdown source and selection safeguards [skip ci]

* [comment audit] clarify editor loading and emulator stream lifetimes [skip ci]

* [comment audit] trim emulator and feature tour narration [skip ci]

* [comment audit] clarify floating workspace and GitHub cache ownership [skip ci]

* [comment audit] trim provider controls and Linear filter explanations [skip ci]

* [comment audit] clarify pairing and chat resume lifetimes [skip ci]

* [comment audit] clarify chat delivery and transcript lifetimes [skip ci]

* [comment audit] clarify session options and host-owned status [skip ci]

* [comment audit] clarify draft durability and live-status precedence [skip ci]

* [comment audit] Trim chat send and model ownership explanations [skip ci]

* [comment audit] Shorten transcript ownership and send recovery comments [skip ci]

* [comment audit] Simplify native chat composer and transcript hook comments [skip ci]

* [comment audit] Shorten native chat scroll and structured session explanations [skip ci]

* [comment audit] Trim workspace picker and onboarding commentary [skip ci]

* [comment audit] Simplify pet rendering, review cache and quick open comments [skip ci]

* [comment audit] Trim sidebar and session history explanations [skip ci]

* [comment audit] Condense session resume and review checks comments [skip ci]

* [comment audit] Shorten checks state and file explorer refresh comments [skip ci]

* [comment audit] Trim plugin bridge and source-control action rationale [skip ci]

* [comment audit] Trim source-control listing and review rationale [skip ci]

* [comment audit] Shorten sidebar lifecycle and explorer safeguards [skip ci]

* [comment audit] Condense Settings account and appearance rationale [skip ci]

* [comment audit] Trim pairing and repository Settings explanations [skip ci]

* [comment audit] Condense Settings search SSH and terminal safeguards [skip ci]

* [comment audit] Shorten Settings voice and provider ownership comments [skip ci]

* [comment audit] Condense Settings draft persistence and host-state rationale [skip ci]

* [comment audit] Trim Settings hooks and sidebar setup rationale [skip ci]

* [comment audit] Condense sidebar deletion and board-filter safeguards [skip ci]

* [comment audit] Condense worktree cards, host ownership and Markdown contracts [skip ci]

* [comment audit] Condense sidebar drag, folder and filtering contracts [skip ci]

* [comment audit] Condense sidebar parity, sleep and host ownership contracts [skip ci]

* [comment audit] Prune focus-read baseline after comment cleanup

* [comment audit] Clarify sidebar visibility, board drops and agent evidence [skip ci]

* [comment audit] Tighten sidebar listing, drag and reveal contracts [skip ci]

* [comment audit] Clarify viewport geometry and skill update safeguards [skip ci]

* [comment audit] Tighten skill inventory, usage and host status comments [skip ci]

* [comment audit] Clarify usage ownership and resource kill safeguards [skip ci]

* [comment audit] Tighten tab selection, rename and search contracts [skip ci]

* [comment audit] Tighten tab-strip geometry and drag ownership comments [skip ci]

* [comment audit] Tighten Tasks recovery, pagination and mutation comments [skip ci]

* [comment audit] Tighten provider loading and terminal recovery comments [skip ci]

* [comment audit] Tighten completion, cadence and PTY ownership comments [skip ci]

* [comment audit] Clarify terminal restore and parked-pane boundaries [skip ci]

* [comment audit] Tighten PTY startup and replay explanations [skip ci]

* [comment audit] Clarify PTY identity and delivery ownership [skip ci]

* [comment audit] Shorten remote reconnect and input replay rationale [skip ci]

* [comment audit] Condense terminal parking clipboard and file link comments [skip ci]

* [comment audit] Clarify IME ownership and trim trace history [skip ci]

* [comment audit] Shorten pane recovery and parked watcher explanations [skip ci]

* [comment audit] Condense snapshot replay and visibility recovery rationale [skip ci]

* [comment audit] Shorten terminal parking and keyboard ownership rationale [skip ci]

* [comment audit] Trim renderer lifecycle and menu rationale [skip ci]

* [comment audit] Condense workspace cleanup ownership and settlement notes [skip ci]

* [comment audit] Clarify renderer hook evidence and source ownership [skip ci]

* [comment audit] Tighten IPC ownership and reconnect explanations [skip ci]

* [comment audit] Trim renderer focus, paste and attention comments [skip ci]

* [comment audit] Shorten scroll, locale and agent lifecycle comments [skip ci]

* [comment audit] Trim agent launch, resume and ownership commentary [skip ci]

* [comment audit] Shorten account, browser and editor comments [skip ci]

* [comment audit] Clarify host-mirror waits, previews and input ownership [skip ci]

* [comment audit] Condense launch recovery and editor tokenization comments [skip ci]

* [comment audit] Condense workspace selection and terminal pane rationale [skip ci]

* [comment audit] Condense terminal fitting and rendering recovery comments [skip ci]

* [comment audit] Condense terminal input and host routing explanations [skip ci]

* [comment audit] Condense ownership and sleeping-session recovery rationale [skip ci]

* [comment audit] Condense structured launch and terminal link explanations [skip ci]

* [comment audit] Condense terminal ownership and workspace file routing rationale [skip ci]

* [comment audit] Condense session persistence and workspace activation rationale [skip ci]

* [comment audit] Condense workspace routing and browser ownership rationale [skip ci]

* [comment audit] Condense mirror recovery and layout authority rationale [skip ci]

* [comment audit] Condense runtime transport and file safety rationale [skip ci]

* [comment audit] Condense runtime graph and structured session rationale [skip ci]

* [comment audit] Condense browser creation and remote tab recovery rationale [skip ci]

* [comment audit] Condense snapshot authority and publisher recovery rationale [skip ci]

* [comment audit] Condense frame, startup and provider cache rationale [skip ci]

* [comment audit] Condense host twin and agent lifecycle rationale [skip ci]

* [comment audit] Condense browser authority and editor cleanup rationale [skip ci]

* [comment audit] Condense editor buffer identity and review cache rationale [skip ci]

* [comment audit] Condense provider lifetime and repository ownership rationale [skip ci]

* [comment audit] Condense reconnect, hydration and terminal retirement rationale [skip ci]

* [comment audit] Condense recovery, reconciliation and persistence rationale [skip ci]

* [comment audit] Condense cleanup ownership and listing admission rationale [skip ci]

* [comment audit] Condense teardown ordering and terminal ownership rationale [skip ci]

* [comment audit] Condense recovery ledger and web host-boundary rationale [skip ci]

* [comment audit] Condense web reconnect and credential lifecycle rationale [skip ci]

* [comment audit] Condense cloud rollout and assignment safety rationale [skip ci]

* [comment audit] Condense relay session and database recovery rationale [skip ci]

* [comment audit] Condense relay placement and protocol compatibility rationale [skip ci]

* [comment audit] Condense build and packaging constraints [skip ci]

* [comment audit] Condense CI gates and validation isolation rationale [skip ci]

* [comment audit] Condense catalog identity and browser validation rationale [skip ci]

* [comment audit] Condense mobile browser and frame-budget rationale [skip ci]

* [comment audit] Shorten mobile route and browser test explanations [skip ci]

* [comment audit] Condense editor and session seam test rationale [skip ci]

* [comment audit] Trim session and terminal closure history [skip ci]

* [comment audit] Shorten terminal browser and census explanations [skip ci]

* [comment audit] Preserve root-only E2E diagnostic baseline

* [comment audit] Condense mobile seam and HTML preview test rationale [skip ci]

* [comment audit] Condense preview instrumentation and render harness rationale [skip ci]

* [comment audit] Condense bundle contracts and native-build constraints [skip ci]

* [comment audit] Shorten native packaging and CI routing rationale [skip ci]

* [comment audit] Condense release tooling and benchmark constraints [skip ci]

* [comment audit] Condense packaging and platform gate rationale [skip ci]

* [comment audit] Shorten mobile route and history rationale [skip ci]

* [comment audit] Condense mobile browser and component rationale [skip ci]

* [comment audit] Shorten drawer and workspace-form rationale [skip ci]

* [comment audit] Trim mobile review and editor-document explanations [skip ci]

* [comment audit] Condense editor lifecycle and Markdown explanations [skip ci]

* [comment audit] Trim mobile file, diagnostics and dictation commentary [skip ci]

* [comment audit] Simplify mobile host-list and workspace-view explanations [skip ci]

* [comment audit] Clarify mobile shell lifetime and bridge delivery constraints [skip ci]

* [comment audit] Condense bridge stream, native request and audio rationale [skip ci]

* [comment audit] Reduce bridge schema and page-client commentary [skip ci]

* [comment audit] Tighten mobile page bridge contracts [skip ci]

* [comment audit] Clarify mobile cache and session constraints [skip ci]

* [comment audit] Condense mobile route and lifecycle rationale [skip ci]

* [comment audit] Tighten mobile shell hook timing rationale [skip ci]

* [comment audit] Clarify route handoff and notification compatibility [skip ci]

* [comment audit] Clarify push registration and dictation cleanup constraints [skip ci]

* [comment audit] Condense keyboard geometry and native media ownership rationale [skip ci]

* [comment audit] Tighten mobile chat scroll and composer concurrency rationale [skip ci]

* [comment audit] Condense mobile reply compatibility and upload ownership rationale [skip ci]

* [comment audit] Condense optimistic echo and scroll ownership rationale [skip ci]

* [comment audit] Tighten stream replay and queued session ownership rationale [skip ci]

* [comment audit] Condense mobile composer and reply-schema constraints [skip ci]

* [comment audit] Clarify mobile transcript recovery and session ownership [skip ci]

* [comment audit] Clarify mobile queue and source-control compatibility [skip ci]

* [comment audit] Condense storage and task launch constraints [skip ci]

* [comment audit] Clarify task schemas and terminal document ownership [skip ci]

* [comment audit] Tighten terminal input and viewport rationale [skip ci]

* [comment audit] Shorten terminal and RPC recorder contracts [skip ci]

* [comment audit] Condense recorder engine and connection contracts [skip ci]

* [comment audit] Shorten host credential and relay recovery comments [skip ci]

* [comment audit] Tighten pairing recovery and bundle transport rationale [skip ci]

* [comment audit] Clarify RPC delivery and workspace catalog boundaries [skip ci]

* [comment audit] Condense catalog and relay entry contracts [skip ci]

* [comment audit] Shorten shutdown and SSH relay delivery contracts [skip ci]

* [comment audit] Condense WSL relay and E2E regression rationale [skip ci]

* [comment audit] Shorten cross-version harness and renderer fixture explanations [skip ci]

* [comment audit] Condense paired-host and E2E lifecycle rationale [skip ci]

* [comment audit] Shorten layout oracle and regression explanations [skip ci]

* [comment audit] Condense paired recovery and ownership regression contracts [skip ci]

* [comment audit] Shorten restart, sidebar and SSH lifecycle contracts [skip ci]

* [comment audit] Condense terminal rendering and IME regression rationale [skip ci]

* [comment audit] Shorten terminal recovery and benchmark contracts [skip ci]

* [comment audit] Condense tooling and Windows lifecycle proof rationale [skip ci]

* [comment audit] Condense workflow routing and release rationale [skip ci]

* [comment audit] Condense mobile security and installer contracts [skip ci]

* [comment audit] Shorten native rationale and stylesheet workarounds [skip ci]

* [comment audit] Shorten Windows visibility probe rationale [skip ci]

* [comment audit] Condense embedded release and signing rationale [skip ci]

* [comment audit] Retain current main test behavior in final reconciliation [skip ci]

* [comment audit] Complete final comment review across current source inventory

* [comment audit] Handle consolidated audit reports before final CI

* [comment audit] Preserve credential storage census detail [skip ci]

* [comment audit] Scale broad changed E2E selections with verified timing shards

* [comment audit] Align E2E assertions with browser close and settled session metadata

* [comment audit] Match existing E2Es to current resource and windowing contracts

* [comment audit] Observe the shared server outage notice in reconnect coverage

* [comment audit] Make existing renderer probes measure settled tab and PTY work

* [comment audit] Align palette E2E selector with task search

* [comment audit] Refresh remaining palette search selectors

* [comment audit] Keep selector correction within selected audit specs

* [comment audit] Await emoji fixture settings inside renderer evaluation

* [comment audit] Cancel fixture fit retries between terminal tests

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-25 04:05:46 -07:00

771 lines
31 KiB
TypeScript
Raw 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.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
const harness = await vi.hoisted(async () => await import('./mobile-web-shell-screen-test-harness'))
const dependencies = vi.hoisted(() => harness.createScreenDependencies())
const { screenModuleMocks } = await vi.hoisted(
async () => await import('./mobile-web-shell-screen-test-mocks')
)
const mocks = vi.hoisted(() => screenModuleMocks(dependencies))
vi.mock('react-native', mocks['react-native'])
vi.mock('expo-clipboard', mocks['expo-clipboard'])
vi.mock('expo-haptics', mocks['expo-haptics'])
vi.mock('expo-document-picker', mocks['expo-document-picker'])
vi.mock('@orca/expo-two-way-audio', mocks['@orca/expo-two-way-audio'])
vi.mock('expo-keep-awake', mocks['expo-keep-awake'])
vi.mock('expo-image-picker', mocks['expo-image-picker'])
vi.mock('expo-file-system', mocks['expo-file-system'])
vi.mock('lucide-react-native', mocks['lucide-react-native'])
vi.mock('react-native-safe-area-context', mocks['react-native-safe-area-context'])
vi.mock('expo-router', mocks['expo-router'])
vi.mock('../../modules/orca-mobile-web-shell/src', mocks['../../modules/orca-mobile-web-shell/src'])
vi.mock('../app-update/use-wall-app-update', mocks['../app-update/use-wall-app-update'])
vi.mock('../transport/host-client-hooks', mocks['../transport/host-client-hooks'])
vi.mock('./use-page-host-snapshot', mocks['./use-page-host-snapshot'])
vi.mock('./use-mobile-web-shell-session', mocks['./use-mobile-web-shell-session'])
import { createElement } from 'react'
import { act, create } from 'react-test-renderer'
import { bridgeId, clientFrame, createFakeRpcClient } from './bridge-host-test-fakes'
import {
byName,
trackRenderedScreen,
SCREEN_BUILD_ID as BUILD_ID,
SCREEN_DIRECTORY as DIRECTORY,
hostParentOf,
readyState,
renderScreen as mountScreen,
textOf,
updateScreen as reRenderScreen
} from './mobile-web-shell-screen-test-harness'
import { BRIDGE_BACK_CLAIM_NOTIFY } from './bridge/bridge-page-back'
import { BRIDGE_PAGE_PAINTED } from './bridge/bridge-page-painted'
import {
BRIDGE_FAULT_GRANT,
BRIDGE_NAVIGATE_BACK_NOTIFY,
readBridgeHostMessage
} from './bridge/bridge-envelope'
import { MobileWebShellScreen } from './MobileWebShellScreen'
import { connectionLogStore } from '../transport/persisted-connection-log-store'
import type { MobileWebShellSessionState } from './mobile-web-shell-session-contract'
import type { ReactTestInstance, ReactTestRenderer } from 'react-test-renderer'
const fetching = (receivedBytes: number, totalBytes: number): MobileWebShellSessionState => ({
kind: 'fetching',
completedAssets: 0,
totalAssets: 128,
receivedBytes,
totalBytes
})
function fillScaleOf(tree: ReactTestRenderer): unknown {
return fillOf(tree).value
}
function fillOf(tree: ReactTestRenderer): { readonly value: unknown } {
const bar = tree.root.find(
(node) => node.props.testID === 'mobile-web-shell-progress-bar' && String(node.type) === 'View'
)
const [fill] = bar.findAll((node) => String(node.type) === 'Animated.View')
return fill.props.style[1].transform[0].scaleX
}
const renderScreen = (state: MobileWebShellSessionState): Promise<ReactTestRenderer> =>
mountScreen(MobileWebShellScreen, dependencies, state)
const updateScreen = (tree: ReactTestRenderer, state: MobileWebShellSessionState): Promise<void> =>
reRenderScreen(MobileWebShellScreen, dependencies, tree, state)
afterEach(harness.unmountRenderedScreens)
beforeEach(() => {
harness.resetScreenDependencies(dependencies)
})
describe('the hybrid shell screen', () => {
it('renders the update wall for a bundle verdict, with no shell view', async () => {
const tree = await renderScreen({
kind: 'wall',
verdict: { kind: 'blocked', reason: 'bundle-unavailable' }
})
expect(textOf(tree)).toContain('Update Orca on your computer')
expect(byName(tree, 'ShellViewProbe')).toEqual([])
})
it('renders the refetch wall a cached generation older than the host earns', async () => {
const tree = await renderScreen({
kind: 'wall',
verdict: {
kind: 'blocked',
reason: 'bundle-incompatible',
side: 'mobile',
bundleRuntimeProtocolVersion: 3,
requiredBundleRuntimeProtocolVersion: 9
}
})
expect(textOf(tree)).toContain('Refresh the mobile workspace')
})
it('offers Try again on a failure a retry can clear', async () => {
const tree = await renderScreen({
kind: 'failed',
reason: 'document-load-failed',
retriedOnce: true
})
expect(textOf(tree)).toContain('The downloaded app could not be opened.')
const retry = tree.root.findAll((node) => node.props.testID === 'mobile-web-shell-retry')
expect(retry).toHaveLength(1)
await act(async () => {
retry[0].props.onPress()
})
expect(dependencies.retry).toHaveBeenCalledTimes(1)
})
it('offers no retry when the device cannot isolate a WebView', async () => {
const tree = await renderScreen({
kind: 'failed',
reason: 'isolation-unavailable',
retriedOnce: false
})
expect(textOf(tree)).toContain("This device's WebView is too old")
expect(tree.root.findAll((node) => node.props.testID === 'mobile-web-shell-retry')).toEqual([])
})
it('offers no retry for a status that could not be read, since the gate is settled', async () => {
const tree = await renderScreen({
kind: 'failed',
reason: 'status-unreadable',
retriedOnce: false
})
expect(textOf(tree)).toContain("Could not read this host's status")
expect(tree.root.findAll((node) => node.props.testID === 'mobile-web-shell-retry')).toEqual([])
})
it('names what is missing when the host is unreachable and nothing is cached', async () => {
expect(textOf(await renderScreen({ kind: 'offline' }))).toContain(
'Connect to this host to download the latest app'
)
})
it('shows the download as a progress bar with megabytes from the paired host', async () => {
const tree = await renderScreen({
kind: 'fetching',
completedAssets: 0,
totalAssets: 128,
receivedBytes: 2_020_592,
totalBytes: 8_082_368
})
expect(textOf(tree)).toContain('Downloading the latest app')
expect(textOf(tree)).toContain('from Host One · 2.0 of 8.1 MB')
const bar = tree.root.findAll(
(node) =>
node.props.testID === 'mobile-web-shell-progress-bar' && String(node.type) === 'View'
)
expect(bar).toHaveLength(1)
expect(bar[0].props.accessibilityRole).toBe('progressbar')
expect(bar[0].props.accessibilityValue).toEqual({ min: 0, max: 100, now: 25 })
expect(fillScaleOf(tree)).toBe(0.25)
expect(byName(tree, 'ActivityIndicator')).toEqual([])
})
it('moves the fill with the download feed, without a render to carry it', async () => {
const tree = await renderScreen(fetching(2_020_592, 8_082_368))
expect(fillScaleOf(tree)).toBe(0.25)
dependencies.downloadProgress.publish(0.5)
expect(fillScaleOf(tree)).toBe(0.5)
expect(textOf(tree)).toContain('2.0 of 8.1 MB')
})
it('starts one ease per window toward the latest value, and lands full at once', async () => {
const tree = await renderScreen(fetching(0, 8_082_368))
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
try {
dependencies.downloadProgress.publish(0.1)
dependencies.downloadProgress.publish(0.2)
dependencies.downloadProgress.publish(0.3)
expect(fillScaleOf(tree)).toBe(0.1)
vi.advanceTimersByTime(50)
expect(fillScaleOf(tree)).toBe(0.3)
dependencies.downloadProgress.publish(0.4)
dependencies.downloadProgress.publish(1)
expect(fillScaleOf(tree)).toBe(1)
} finally {
vi.useRealTimers()
}
})
it('starts nothing after unmount for a value still waiting on its window', async () => {
const tree = await renderScreen(fetching(0, 8_082_368))
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout', 'Date'] })
try {
dependencies.downloadProgress.publish(0.1)
dependencies.downloadProgress.publish(0.5)
const fill = fillOf(tree)
act(() => tree.unmount())
vi.advanceTimersByTime(50)
expect(fill.value).toBe(0.1)
} finally {
vi.useRealTimers()
}
})
it('caps the bar at full when more bytes arrive than the total named', async () => {
const tree = await renderScreen(fetching(9_000_000, 8_082_368))
expect(fillScaleOf(tree)).toBe(1)
})
it('reads an empty download as no progress rather than dividing by zero', async () => {
const tree = await renderScreen({
kind: 'fetching',
completedAssets: 0,
totalAssets: 0,
receivedBytes: 0,
totalBytes: 0
})
const bar = tree.root.findAll(
(node) =>
node.props.testID === 'mobile-web-shell-progress-bar' && String(node.type) === 'View'
)
expect(bar[0].props.accessibilityValue).toEqual({ min: 0, max: 100, now: 0 })
expect(fillScaleOf(tree)).toBe(0)
expect(textOf(tree)).toContain('0.0 of 0.0 MB')
})
it('hands the shell view the generation path and the session id', async () => {
const tree = await renderScreen(readyState('session-one'))
const view = byName(tree, 'ShellViewProbe')[0]
expect(view.props.generationDirectory).toBe(DIRECTORY)
expect(view.props.sessionId).toBe('session-one')
})
it('delivers an init through the ready view bridge', async () => {
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-one'))
const view = byName(tree, 'ShellViewProbe')[0]
expect(view.props.bridgeEnabled).toBe(true)
await act(async () =>
view.props.onBridgeMessage({ nativeEvent: { json: clientFrame({ type: 'ready' }) } })
)
expect(dependencies.posted.map((raw) => readBridgeHostMessage(raw))).toContainEqual({
ok: true,
message: expect.objectContaining({
type: 'init',
sessionId: 'session-one',
host: expect.objectContaining({ id: 'host-1' })
})
})
})
it('rebuilds the view rather than updating it when the session id changes', async () => {
const tree = await renderScreen(readyState('session-one'))
await updateScreen(tree, readyState('session-two'))
expect(dependencies.lifecycle).toEqual([
'mount:session-one',
'unmount:session-one',
'mount:session-two'
])
})
it('forwards a failure the native view reports and drops a payload it cannot read', async () => {
const tree = await renderScreen(readyState('session-one'))
const view = byName(tree, 'ShellViewProbe')[0]
await act(async () => {
view.props.onLoadState({ nativeEvent: { state: 'ready' } })
view.props.onLoadState({ nativeEvent: { state: 'failed', reason: 'invented' } })
view.props.onLoadState({ nativeEvent: { state: 'failed', reason: 'render-process-gone' } })
})
expect(dependencies.reportShellFailure.mock.calls).toEqual([['render-process-gone']])
})
it('starts the wait for the page when the native view says the document finished', async () => {
const tree = await renderScreen(readyState('session-one'))
const view = byName(tree, 'ShellViewProbe')[0]
await act(async () => {
view.props.onLoadState({ nativeEvent: { state: 'loading' } })
view.props.onLoadState({ nativeEvent: { state: 'ready' } })
view.props.onLoadState({ nativeEvent: { state: 'failed', reason: 'document-load-failed' } })
})
// Start the paint deadline only for completed documents; failed loads cannot produce a frame.
expect(dependencies.reportDocumentLoaded).toHaveBeenCalledTimes(1)
expect(dependencies.reportDocumentStarted).toHaveBeenCalledTimes(1)
})
it('fails the session when this host could not be read from the app store', async () => {
// Profile failure must exit ready; otherwise the page keeps asking for init with no host behind it.
dependencies.snapshotUnreadable = true
const warned = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const logged = () => connectionLogStore.get('host-1').map((entry) => entry.message)
const before = logged().length
await renderScreen(readyState('session-one'))
expect(dependencies.reportShellFailure.mock.calls).toEqual([['document-load-failed']])
expect(logged().slice(before)).toEqual(['Web shell: host profile unreadable'])
warned.mockRestore()
})
it('requests an app-store refresh on every ready ask', async () => {
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-one'))
const view = byName(tree, 'ShellViewProbe')[0]
await act(async () => {
view.props.onBridgeMessage({ nativeEvent: { json: clientFrame({ type: 'ready' }) } })
view.props.onBridgeMessage({ nativeEvent: { json: clientFrame({ type: 'ready' }) } })
})
// A reload within this mount must refresh storage again so intervening app writes reach init.
expect(dependencies.storageRefreshes).toBe(2)
})
// Observe wire frames only; ruling 34 leaves delivery untracked and one-shot consumption to the page.
async function renderForRoute(params: Record<string, string>): Promise<{
tree: ReactTestRenderer
initRoutes: () => (Record<string, string> | undefined)[]
move: (next: Record<string, string>) => Promise<void>
ready: () => Promise<void>
}> {
const element = (next: Record<string, string>) =>
createElement(MobileWebShellScreen, {
hostId: 'host-1',
route: { pathname: '/h/host-1', params: next }
})
dependencies.state = readyState('session-one')
const rendered: { tree: ReactTestRenderer | null } = { tree: null }
await act(async () => {
rendered.tree = create(element(params))
})
const tree = rendered.tree
if (tree === null) {
throw new Error('screen did not render')
}
trackRenderedScreen(tree)
return {
tree,
// Parse with the page’s reader so rejected frames cannot inflate init counts.
initRoutes: () =>
dependencies.posted
.map((json) => readBridgeHostMessage(json))
.flatMap((read) => (read.ok && read.message.type === 'init' ? [read.message] : []))
.map((frame) => frame.route?.params),
move: async (next) => {
await act(async () => {
tree.update(element(next))
})
},
ready: async () => {
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
})
}
}
}
// Send once per route change; the next ready repairs missed delivery using the current route, without tracking acknowledgements (rulings 33.1/34).
it('posts one init for a route that moved, and none for a render that moved nothing', async () => {
dependencies.client = createFakeRpcClient()
const page = await renderForRoute({ paneKey: '' })
await page.ready()
expect(page.initRoutes()).toEqual([{ paneKey: '' }])
await page.move({ paneKey: 'pane-1' })
expect(page.initRoutes()).toEqual([{ paneKey: '' }, { paneKey: 'pane-1' }])
await page.move({ paneKey: 'pane-1' })
expect(page.initRoutes()).toHaveLength(2)
})
it('answers every ask with the route it holds then, which is how a lost frame is repaired', async () => {
dependencies.client = createFakeRpcClient()
dependencies.postFails = true
const warned = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const page = await renderForRoute({ paneKey: '' })
await page.ready()
await page.move({ paneKey: 'pane-1' })
expect(dependencies.posted).toHaveLength(2)
dependencies.postFails = false
await page.ready()
expect(page.initRoutes().at(-1)).toEqual({ paneKey: 'pane-1' })
warned.mockRestore()
})
it('ends that wait on the page asking for a session', async () => {
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
})
expect(dependencies.reportPageReady).toHaveBeenCalled()
})
// Client replacement rebuilds the host without changing the page session; seed it from reducer state because the page does not handshake again.
it('serves a page whose session handshook before this host was built', async () => {
const client = createFakeRpcClient()
dependencies.client = client
dependencies.pageReady = true
const tree = await renderScreen(readyState('session-one'))
// No new ready arrives from a page that was never told its host changed.
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: {
json: clientFrame({ type: 'request', id: bridgeId(1), method: 'status.get' })
}
})
})
expect(client.requests.map((request) => request.method)).toEqual(['status.get'])
})
it('reports a ready page fault as a document-load failure', async () => {
dependencies.client = createFakeRpcClient()
const warned = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
// Only an established session receives the fault grant.
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: {
json: clientFrame({
type: 'notify',
name: BRIDGE_FAULT_GRANT,
error: { category: 'Error', message: 'the route threw', isRpcDeliveryUnknown: false }
})
}
})
})
expect(dependencies.reportShellFailure.mock.calls).toEqual([['document-load-failed']])
warned.mockRestore()
})
it('reports a URL nothing on this phone could open, which is the dead tap that survives', async () => {
dependencies.client = createFakeRpcClient()
const failure = new Error('no activity found')
// Create rejection per call; constructing it before the frame arrives would leave it temporarily unhandled.
dependencies.openUrl.mockImplementation(() => Promise.reject(failure))
const warned = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: {
json: clientFrame({
type: 'notify',
name: 'externalLink',
url: 'mailto:someone@example.com'
})
}
})
})
// Notify has no reply, so only diagnostics reveal that the device failed to open the link.
expect(warned.mock.calls).toContainEqual([
'[web-shell] could not open a URL for the page',
{ url: 'mailto:someone@example.com', error: failure }
])
warned.mockRestore()
})
it('pops its own stack when the page hands its back button over', async () => {
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'notify', name: BRIDGE_NAVIGATE_BACK_NOTIFY }) }
})
})
expect(dependencies.back).toHaveBeenCalledTimes(1)
expect(dependencies.push).not.toHaveBeenCalled()
})
// This file pins iOS swipe interception; use-shell-page-back.test.tsx covers platform key selection.
it('carries the page taking the device Back key up to the session', async () => {
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: {
json: clientFrame({ type: 'notify', name: BRIDGE_BACK_CLAIM_NOTIFY, claimed: true })
}
})
})
expect(dependencies.reportPageBackClaim).toHaveBeenCalledWith(true)
})
it('takes the stack swipe away while the session says the page is holding the key', async () => {
dependencies.backClaimed = true
await renderScreen(readyState('session-one'))
expect(dependencies.setScreenOptions).toHaveBeenCalledWith({ gestureEnabled: false })
})
it('leaves the swipe alone while the page is holding nothing', async () => {
await renderScreen(readyState('session-one'))
expect(dependencies.setScreenOptions).toHaveBeenCalledWith({ gestureEnabled: true })
})
it('pops nothing when this page is the first screen on the stack, rather than dismissing it', async () => {
dependencies.client = createFakeRpcClient()
dependencies.canGoBack = false
const warned = vi.spyOn(console, 'warn').mockImplementation(() => undefined)
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
byName(tree, 'ShellViewProbe')[0].props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'notify', name: BRIDGE_NAVIGATE_BACK_NOTIFY }) }
})
})
expect(dependencies.back).not.toHaveBeenCalled()
// Back notify has no reply; its log is the only evidence of failure.
expect(warned.mock.calls).toContainEqual([
'[web-shell-bridge] did not pop the stack for a page going back',
{ why: 'nothing-to-pop' }
])
warned.mockRestore()
})
it('shows a build id prefix and never the whole one, the cache path, or the host id', async () => {
const tree = await renderScreen(readyState('session-one'))
const text = textOf(tree)
expect(text).toContain(BUILD_ID.slice(0, 12))
expect(text).toContain('4096 B')
expect(text).toContain('811 ms')
expect(text).not.toContain(BUILD_ID)
expect(text).not.toContain(DIRECTORY)
expect(text).not.toContain('host-1')
})
})
describe('a route the page does not serve and no side can be blamed for', () => {
it('paints the unavailable screen itself, with no view and no spinner', async () => {
const tree = await renderScreen({ kind: 'route-unavailable' })
expect(textOf(tree)).toContain('This workspace screen is not available on this host.')
expect(byName(tree, 'ShellViewProbe')).toEqual([])
expect(byName(tree, 'ActivityIndicator')).toEqual([])
})
})
describe('the dropped-frame count on the dev facts line', () => {
// 500,000 raw bytes exceed the frame cap once encoded.
const oversized = {
opcode: 1 as const,
seq: 1,
format: 'jpeg' as const,
metadata: {},
image: new Uint8Array(500_000)
}
async function openBinaryStream(tree: ReactTestRenderer): Promise<void> {
await act(async () => {
byName(tree, 'ShellViewProbe')[0]?.props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
})
await act(async () => {
byName(tree, 'ShellViewProbe')[0]?.props.onBridgeMessage({
nativeEvent: {
json: clientFrame({
type: 'subscribe',
id: 'a'.repeat(22),
method: 'browser.screencast',
params: {},
wantsBinary: true
})
}
})
})
}
async function drop(times: number): Promise<void> {
const emit = dependencies.client?.streams[0]?.emitBinary
if (emit === undefined || emit === null) {
throw new Error('binary subscription was never opened')
}
for (let index = 0; index < times; index += 1) {
await act(async () => {
emit({ ...oversized, seq: index + 1 })
})
}
}
function devFactsText(tree: ReactTestRenderer): string | null {
const line = byName(tree, 'Text').find(
(node) => node.props.testID === 'mobile-web-shell-dev-facts'
)
return line === undefined ? null : String(line.props.children)
}
it('shows the running total and resets it when the host is rebuilt', async () => {
dependencies.client = createFakeRpcClient()
dependencies.routeGrants = ['navigate', 'screencastBinary']
const tree = await renderScreen(readyState('session-one'))
await openBinaryStream(tree)
await drop(2)
expect(devFactsText(tree)).toContain('2 frames dropped')
await updateScreen(tree, readyState('session-two'))
expect(devFactsText(tree)).not.toContain('dropped')
})
// Dev facts render null in release; their updates must not rerender the screen at screencast frequency.
it('renders the screen not once more per dropped frame in a production build', async () => {
Object.assign(globalThis, { __DEV__: false })
try {
dependencies.client = createFakeRpcClient()
dependencies.routeGrants = ['navigate', 'screencastBinary']
const tree = await renderScreen(readyState('session-one'))
await openBinaryStream(tree)
expect(devFactsText(tree)).toBeNull()
const before = dependencies.viewRenders
await drop(5)
expect({ extraRenders: dependencies.viewRenders - before }).toEqual({ extraRenders: 0 })
expect(devFactsText(tree)).toBeNull()
} finally {
Object.assign(globalThis, { __DEV__: true })
}
})
})
// Keep update refusal separate from the working fallback document; dismissing its notice must not reload that document.
describe('a refused update is said beside the page, not in front of it', () => {
function dismissControl(tree: ReactTestRenderer): ReactTestInstance | undefined {
return byName(tree, 'Pressable').find(
(node) => node.props.accessibilityLabel === 'Dismiss notice'
)
}
it('serves the page and says the update did not happen, promising no retry', async () => {
dependencies.updateNotice = 'update-failed'
const tree = await renderScreen(readyState('session-one'))
expect(byName(tree, 'ShellViewProbe')).toHaveLength(1)
const text = textOf(tree)
expect(text).toContain("Couldn't download the latest app from this host")
expect(text).toContain('Showing the last version that worked')
expect(text).not.toContain('Try again')
})
it('carries the notice to a reader who never arrives at the top of the page', async () => {
// Use assertive failure announcement for an update refused after the screen was already visible.
dependencies.updateNotice = 'update-failed'
const tree = await renderScreen(readyState('session-one'))
const alert = byName(tree, 'View').find((node) => node.props.accessibilityRole === 'alert')
expect(alert).toBeDefined()
expect(alert?.props.accessibilityLiveRegion).toBe('assertive')
})
it('says nothing when the generation on screen is the one the host serves', async () => {
const tree = await renderScreen(readyState('session-one'))
expect(dismissControl(tree)).toBeUndefined()
expect(textOf(tree)).not.toContain("Couldn't update")
})
it('keeps the same document mounted when the notice is dismissed', async () => {
dependencies.updateNotice = 'update-failed'
const tree = await renderScreen(readyState('session-one'))
dependencies.lifecycle.length = 0
await act(async () => {
tree.root
.find(
(node) =>
String(node.type) === 'Pressable' && node.props.accessibilityLabel === 'Dismiss notice'
)
.props.onPress()
})
expect(dismissControl(tree)).toBeUndefined()
expect(textOf(tree)).not.toContain("Couldn't update")
expect(byName(tree, 'ShellViewProbe')).toHaveLength(1)
expect(dependencies.lifecycle).toEqual([])
})
it('shows a later refusal rather than staying dismissed for the rest of the host', async () => {
dependencies.updateNotice = 'update-failed'
const tree = await renderScreen(readyState('session-one'))
await act(async () => {
tree.root
.find(
(node) =>
String(node.type) === 'Pressable' && node.props.accessibilityLabel === 'Dismiss notice'
)
.props.onPress()
})
// A new document’s refusal must not inherit the previous document’s dismissal.
await updateScreen(tree, readyState('session-two'))
expect(dismissControl(tree)).toBeDefined()
})
})
// Keep a cover until first paint; uncovering at ready exposed bare surface during measured 1.42-second cached-page startup.
describe('the frame under a page that has not painted', () => {
it('keeps the shell frame over a mounted view, with the view underneath it', async () => {
dependencies.pageFrame = 'unpainted'
const tree = await renderScreen(readyState('session-a'))
expect(
tree.root.findAll((node) => node.props.testID === 'mobile-web-shell-cover')
).toHaveLength(1)
// Keep the document mounted and loading under the cover.
expect(byName(tree, 'ShellViewProbe')).toHaveLength(1)
expect(textOf(tree)).toContain('Opening workspace')
})
it('carries the same label the screen was already painting while it opened the generation', async () => {
const opening = await renderScreen({ kind: 'activating', source: 'cache' })
expect(textOf(opening)).toContain('Opening workspace')
dependencies.pageFrame = 'unpainted'
await updateScreen(opening, readyState('session-a'))
expect(textOf(opening)).toContain('Opening workspace')
})
it('takes the frame down once the page reports one of its own', async () => {
dependencies.pageFrame = 'unpainted'
const tree = await renderScreen(readyState('session-a'))
dependencies.pageFrame = 'painted'
await updateScreen(tree, readyState('session-a'))
expect(tree.root.findAll((node) => node.props.testID === 'mobile-web-shell-cover')).toEqual([])
})
it('covers the same box the view gets, which the keyboard does not shorten', async () => {
// View and absolute cover share the padded content box; keyboard overlays it rather than resizing it, so neither can expose an inset gap.
dependencies.pageFrame = 'unpainted'
const tree = await renderScreen(readyState('session-keyboard-cover'))
const root = tree.root.find((node) => node.props.testID === 'mobile-web-shell-ready')
await act(async () => {
dependencies.keyboardListeners.get('keyboardWillShow')?.({ endCoordinates: { height: 336 } })
})
expect(root.props.style[1]).toEqual({ paddingTop: 0 })
const cover = tree.root.find((node) => node.props.testID === 'mobile-web-shell-cover')
expect(cover.props.style[0]).toMatchObject({
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0
})
expect(hostParentOf(cover)).toBe('mobile-web-shell-ready')
expect(hostParentOf(byName(tree, 'ShellViewProbe')[0])).toBe('mobile-web-shell-ready')
})
it('hands the page report to the session', async () => {
dependencies.pageFrame = 'unpainted'
dependencies.client = createFakeRpcClient()
const tree = await renderScreen(readyState('session-a'))
const probe = byName(tree, 'ShellViewProbe')[0]
await act(async () => {
probe.props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'ready' }) }
})
})
expect(dependencies.reportPageReady).toHaveBeenCalledTimes(1)
await act(async () => {
probe.props.onBridgeMessage({
nativeEvent: { json: clientFrame({ type: 'notify', name: BRIDGE_PAGE_PAINTED }) }
})
})
expect(dependencies.reportPagePainted).toHaveBeenCalledTimes(1)
})
})