Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/scripts/build-mobile-web-app-bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,8 @@ export function resolveMobileWebPageRoutes(routeKeys, declared = MOBILE_WEB_PAGE
...(route.optionalGrants === undefined || route.optionalGrants.length === 0
? {}
: { optionalGrants: [...route.optionalGrants] }),
...(route.canOwnHostArea === true ? { canOwnHostArea: true } : {})
...(route.canOwnHostArea === true ? { canOwnHostArea: true } : {}),
...(route.canOwnHostAreaAcrossLayouts === true ? { canOwnHostAreaAcrossLayouts: true } : {})
}))
}

Expand Down
4 changes: 3 additions & 1 deletion config/scripts/mobile-web-page-routes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ export const MOBILE_WEB_PAGE_ROUTES = [
// every `/h` route in `HostProtocolGate`, so without the grant the wall's Update Orca tap posts a
// notify the shell refuses, with nothing on screen to say why.
// `canOwnHostArea`: on wide layouts it draws the sidebar itself, given `ownsHostArea` in `init`.
// `canOwnHostAreaAcrossLayouts`: it also renders the narrow host area, so ownership survives rotation.
{
pathname: '/h/[hostId]',
grants: ['navigate', 'storage', 'externalLink', 'haptics'],
canOwnHostArea: true
canOwnHostArea: true,
canOwnHostAreaAcrossLayouts: true
},
// Agent session history. `navigate` because a resumed session opens the session screen, which is
// native, and because the list above now reaches this one without leaving the page. `storage`
Expand Down
32 changes: 32 additions & 0 deletions config/scripts/mobile-web-page-routes.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,38 @@ describe('the page routes the manifest declares', () => {
])
})

it('serializes cross-layout ownership only for opted-in routes and declares it only on the host root', () => {
const routes = resolveMobileWebPageRoutes(
['./h/[hostId]/index.tsx', './h/[hostId]/tasks.tsx'],
[
{
pathname: '/h/[hostId]',
grants: ['navigate'],
canOwnHostArea: true,
canOwnHostAreaAcrossLayouts: true
},
{ pathname: '/h/[hostId]/tasks', grants: ['navigate'], canOwnHostArea: true }
]
)
expect(JSON.parse(JSON.stringify(routes))).toEqual([
{
pathname: '/h/[hostId]',
grants: ['navigate'],
canOwnHostArea: true,
canOwnHostAreaAcrossLayouts: true
},
{ pathname: '/h/[hostId]/tasks', grants: ['navigate'], canOwnHostArea: true }
])
expect(
MOBILE_WEB_PAGE_ROUTES.filter((route) => route.canOwnHostAreaAcrossLayouts).map(
(route) => route.pathname
)
).toEqual(['/h/[hostId]'])
for (const route of routes) {
expect(MobileWebBundleRouteSchema.safeParse(route).success).toBe(true)
}
})

/**
* The wide iPad's host-area session is granted every served route's list, so its in-page hops
* stay in the page. Bounded by the per-route ceiling too, so that grant never outgrows one route's.
Expand Down
5 changes: 4 additions & 1 deletion mobile/app/h/[hostId]/index.web.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { WorkspaceDetailPlaceholder } from '../../../src/components/WorkspaceDetailPlaceholder'
import { HostScreen } from '../../../src/host-screen/HostScreen'
import { useResponsiveLayout } from '../../../src/layout/responsive-layout'
import { usePageOwnsHostArea } from '../../../src/mobile-web-shell/page-owns-host-area'

/**
Expand All @@ -8,5 +9,7 @@ import { usePageOwnsHostArea } from '../../../src/mobile-web-shell/page-owns-hos
*/
export default function HostWorktreeRoute() {
// The placeholder only beside the page's own sidebar: without the host area this is the list.
return usePageOwnsHostArea() ? <WorkspaceDetailPlaceholder /> : <HostScreen />
const ownsHostArea = usePageOwnsHostArea()
const { isWideLayout } = useResponsiveLayout()
return ownsHostArea && isWideLayout ? <WorkspaceDetailPlaceholder /> : <HostScreen />
}
8 changes: 4 additions & 4 deletions mobile/src/mobile-web-shell/MobileWebShellScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ export function MobileWebShellScreen({
})
return
}
// Wide, this host's route is the area-owning session even when it is not on the stack as
// asked: `dismissTo` pops to it by name with the href's params, or replaces this one after a
// cold deep link, so it is never a second on top.
if (isWideLayout && isHostRouteOf(href, hostId)) {
// This host's route is the area-owning session at either width, even when it is not on the
// stack as asked: `dismissTo` pops to it by name with the href's params, or replaces this one
// after a cold deep link, so it is never a second on top.
if (isHostRouteOf(href, hostId)) {
router.dismissTo(href)
return
}
Expand Down
2 changes: 2 additions & 0 deletions mobile/src/mobile-web-shell/bridge-host-back.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { BRIDGE_BACK_FRAME } from './bridge/bridge-page-back'
*/
export type BridgeSessionBack = {
readonly claimed: boolean
/** The negotiated storage keys the page's `ready` named; absent for a page that named none. */
readonly storageKeys?: readonly string[]
}

/**
Expand Down
12 changes: 10 additions & 2 deletions mobile/src/mobile-web-shell/bridge-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { createBridgeHostFrames } from './bridge-host-frames'
import { createBridgeHostBack, type BridgeSessionBack } from './bridge-host-back'
import { createBridgeNotifyForwarder } from './bridge-host-notify'
import { createBridgeHostRoute } from './bridge-host-route'
import { pageStorageForReader } from './page-storage-keys'
import type { BridgeSafeAreaInsets } from './bridge/bridge-safe-area-insets'
import type { BridgeHostOptions } from './bridge-host-contract'

Expand Down Expand Up @@ -108,6 +109,9 @@ export function createBridgeHost(options: BridgeHostOptions): BridgeHost {
// Seeded from the session rather than started false: this host may be a rebuild taking over a
// session that handshook with the one before it.
let initSent = options.sessionEstablished
// What the page's init reader accepts, carried across a rebuild because the page does not
// re-handshake. Null is a page older than `storageKeys`, which gets the legacy keys only.
let pageStorageKeys: readonly string[] | null = options.sessionBack?.storageKeys ?? null

const frames = createBridgeHostFrames({
post: options.post,
Expand Down Expand Up @@ -178,7 +182,7 @@ export function createBridgeHost(options: BridgeHostOptions): BridgeHost {
granted,
host,
ownsHostArea: options.ownsHostArea === true,
...options.readStorage()
...pageStorageForReader(options.readStorage(), pageStorageKeys)
})
)
)
Expand Down Expand Up @@ -257,6 +261,7 @@ export function createBridgeHost(options: BridgeHostOptions): BridgeHost {
// re-asked `ready` from the document already being served is answered the same way.
if (message.type === 'ready') {
serving = true
pageStorageKeys = message.storageKeys ?? null
back.readReady()
// Every time it is asked, not once: the page re-asks on a backoff, and each ask is answered
// with the route the shell holds now. That is the whole repair path for a frame that never
Expand Down Expand Up @@ -345,7 +350,10 @@ export function createBridgeHost(options: BridgeHostOptions): BridgeHost {
routes.publishKeyboardInset(next, deliverable())
},
sendBack: back.send,
readSessionBack: back.read,
readSessionBack: () => ({
...back.read(),
...(pageStorageKeys === null ? {} : { storageKeys: pageStorageKeys })
}),
dispose
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('a Back press crossing from the shell to the page', () => {
expect(pair.host.sendBack()).toBe(true)
await pair.flush()
expect(took).toHaveBeenCalledTimes(1)
expect(pair.readToShell().find((frame) => frame.type === 'ready')).toEqual({
expect(pair.readToShell().find((frame) => frame.type === 'ready')).toMatchObject({
v: 1,
type: 'ready'
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BRIDGE_PROTOCOL_VERSION, type BridgeClientMessage } from './bridge-envelope'
import { NEGOTIATED_PAGE_STORAGE_KEYS } from '../page-storage-keys'

/** The page asks again until the shell answers; a session has no other way to start. */
export const BRIDGE_READY_RETRY_MIN_MS = 50
Expand Down Expand Up @@ -49,8 +50,12 @@ export function createBridgeInitHandshake(ask: () => void): BridgeInitHandshake
}
}

/** What the page says on every ask. It declares nothing: the shell serves no page older than its
* floor, so every page it talks to takes everything the shell sends. */
/** What the page says on every ask. Pages and shells update independently, so it names the
* negotiated storage keys its `init` reader accepts; an older shell ignores the member. */
export function createPageReadyFrame(): Extract<BridgeClientMessage, { type: 'ready' }> {
return { v: BRIDGE_PROTOCOL_VERSION, type: 'ready' }
return {
v: BRIDGE_PROTOCOL_VERSION,
type: 'ready',
storageKeys: [...NEGOTIATED_PAGE_STORAGE_KEYS]
}
}
9 changes: 8 additions & 1 deletion mobile/src/mobile-web-shell/bridge/bridge-envelope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,14 @@ const replyPartSchema = z.object({
const BridgeClientMessageSchema = z.discriminatedUnion('type', [
z.object({
v: versionSchema,
type: z.literal('ready')
type: z.literal('ready'),
// Negotiated keys this page's `init` reader accepts. A malformed list reads as none, so the
// page gets the legacy keys rather than no session.
storageKeys: z
.array(z.string().min(1).max(PAGE_STORAGE_MAX_KEY_CHARS))
.max(PAGE_STORAGE_MAX_ENTRIES)
.optional()
.catch(undefined)
}),
z.object({
v: versionSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ afterEach(() => {
})

describe('bridge client handshake', () => {
it('asks for a session as soon as it exists, declaring nothing', () => {
it('asks for a session immediately and declares the storage keys it can read', () => {
const page = createPageClient()
expect(page.frames()).toEqual([{ v: BRIDGE_PROTOCOL_VERSION, type: 'ready' }])
expect(page.frames()).toEqual([
{ v: BRIDGE_PROTOCOL_VERSION, type: 'ready', storageKeys: ['orca:terminalSplitLayout'] }
])
})

it('keeps asking on a widening backoff until init answers', () => {
Expand Down
30 changes: 19 additions & 11 deletions mobile/src/mobile-web-shell/host-area-layout-class-change.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
*
* Off a wide layout a detail route is served as before; on one it is served only by a page that
* declares `canOwnHostArea`, because an older page would draw its own sidebar beside the native
* one, so an older one is walled. The session rebuilds on the change, so the page's in-page stack
* does not survive it.
* one, so an older one is walled. A declaring page keeps its session and in-page stack across the change.
*/
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -95,12 +94,13 @@ const store: GenerationStore = {
forgetHostUpdateFailures: async () => undefined
}

function routes(declares: boolean): MobileWebBundleManifestRead['routes'] {
function routes(declares: boolean, acrossLayouts = true): MobileWebBundleManifestRead['routes'] {
return [
{
pathname: '/h/[hostId]',
grants: ['navigate'],
...(declares ? { canOwnHostArea: true } : {})
...(declares ? { canOwnHostArea: true } : {}),
...(declares && acrossLayouts ? { canOwnHostAreaAcrossLayouts: true } : {})
},
{ pathname: '/h/[hostId]/session/[worktreeId]', grants: ['navigate'] }
]
Expand All @@ -109,9 +109,10 @@ function routes(declares: boolean): MobileWebBundleManifestRead['routes'] {
async function settledKinds(
declares: boolean,
widths: readonly boolean[],
routePathname = '/h/host-1/session/wt-1'
routePathname = '/h/host-1/session/wt-1',
acrossLayouts = true
) {
doubles.routes = routes(declares)
doubles.routes = routes(declares, acrossLayouts)
doubles.manifestReads = 0
doubles.gates.hostCapabilities = [MOBILE_WEB_BUNDLE_CAPABILITY]
const seen: MobileWebShellSessionState[] = []
Expand Down Expand Up @@ -150,9 +151,16 @@ async function settledKinds(
}

describe('a detail session across a layout-class change', () => {
// Once per flip: the wide session may not keep the host-route hop the narrow one could.
it('restarts an open page once per flip under a declaring bundle', async () => {
// Ownership and route grants belong to the document, not its changing viewport.
it('preserves the open page across rotation under a declaring bundle', async () => {
expect(await settledKinds(true, [false, true, false])).toEqual({
kinds: ['ready session-1', 'ready session-1', 'ready session-1'],
manifestReads: 1
})
})

it('keeps legacy declaring pages usable under their original layout-specific sessions', async () => {
expect(await settledKinds(true, [false, true, false], '/h/host-1', false)).toEqual({
kinds: ['ready session-1', 'ready session-2', 'ready session-3'],
manifestReads: 3
})
Expand All @@ -165,9 +173,9 @@ describe('a detail session across a layout-class change', () => {
})
})

it('rebuilds the host route, whose wide session owns the area under other grants', async () => {
const { kinds } = await settledKinds(true, [false, true], '/h/host-1')
expect(kinds).toEqual(['ready session-1', 'ready session-2'])
it('preserves the host-area document and its in-page workspace across rotation', async () => {
const { kinds } = await settledKinds(true, [false, true, false], '/h/host-1')
expect(kinds).toEqual(['ready session-1', 'ready session-1', 'ready session-1'])
})
})

Expand Down
11 changes: 11 additions & 0 deletions mobile/src/mobile-web-shell/host-area-leave-session.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ describe('leaving a wide detail session for its host route', () => {
})

describe('the same hop on a phone', () => {
it.each([HOST, BOUNCE])('replaces a cold detail session with %s', async (href) => {
await hopFromSession(PHONE, [DETAIL], href)
expect(applied([DETAIL])).toEqual([href])
expect(dependencies.push).not.toHaveBeenCalled()
})

it('updates the existing host notice without retaining the exited detail session', async () => {
await hopFromSession(PHONE, [HOST, DETAIL], BOUNCE)
expect(applied([HOST, DETAIL])).toEqual([BOUNCE])
})

it('returns to the host route below rather than stacking a second one', async () => {
await hopFromSession(PHONE, [HOST, DETAIL], HOST)
expect(device.dismissTo).not.toHaveBeenCalled()
Expand Down
15 changes: 15 additions & 0 deletions mobile/src/mobile-web-shell/host-area-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ describe('the page declaring it can own the host area', () => {
const unserved = [{ ...desktopRoutes(true)[0]!, grants: ['native.teleport.start'] }]
expect(routeViewOf(unserved, HOST_ROUTE, true).ownsHostArea).toBe(false)
})

it('keeps the area at either width only for a page that declares it across layouts', () => {
const [host, ...rest] = desktopRoutes(true)
const routes = [{ ...host!, canOwnHostAreaAcrossLayouts: true }, ...rest]
expect(routeViewOf(routes, HOST_ROUTE, true).ownsHostArea).toBe(true)
expect(routeViewOf(routes, HOST_ROUTE, false).ownsHostArea).toBe(true)
// A narrow detail session hands a hop to the host route back to the shell, like a wide one.
expect(
routeViewOf(routes, '/h/host-1/session/wt-1', false).pageRouteGrants.map((p) => p.pathname)
).not.toContain('/h/[hostId]')
// Without `canOwnHostArea` the across-layouts flag claims nothing.
const flagOnly = [{ ...desktopRoutes(false)[0]!, canOwnHostAreaAcrossLayouts: true }]
expect(routeViewOf(flagOnly, HOST_ROUTE, false).ownsHostArea).toBe(false)
expect(routeViewOf(flagOnly, HOST_ROUTE, true).ownsHostArea).toBe(false)
})
})

describe('the wide host-area session', () => {
Expand Down
6 changes: 3 additions & 3 deletions mobile/src/mobile-web-shell/host-area-sidebar-matrix.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function pageRoutes(page: Page): MobileWebPageRoute[] | null {
{
pathname: '/h/[hostId]',
grants: ['navigate'],
...(page === 'declared' ? { canOwnHostArea: true } : {})
...(page === 'declared' ? { canOwnHostArea: true, canOwnHostAreaAcrossLayouts: true } : {})
},
{ pathname: '/h/[hostId]/session/[worktreeId]', grants: ['navigate'] }
]
Expand Down Expand Up @@ -368,11 +368,11 @@ describe('the page sidebar rule', () => {
})

describe('a phone', () => {
it('reports nothing to the layout from a served host route', async () => {
it('reports host ownership without drawing a sidebar on a narrow viewport', async () => {
const hostSession = sessionFor('declared', HOST, false)
expect(hostSession.state.kind).toBe('activating')
env.reports.length = 0
expect(await sidebarsIn('native', PHONE, { hostSession })).toBe(0)
expect(env.reports).toEqual([])
expect(env.reports).toEqual([true, false])
})
})
43 changes: 43 additions & 0 deletions mobile/src/mobile-web-shell/host-root-responsive-content.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { createElement } from 'react'
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
import { describe, expect, it, vi } from 'vitest'

const viewport = vi.hoisted(() => ({ width: 669, height: 951, ownsHostArea: true }))
vi.mock('react-native', () => ({ useWindowDimensions: () => viewport }))
vi.mock('./page-owns-host-area', () => ({ usePageOwnsHostArea: () => viewport.ownsHostArea }))
vi.mock('../host-screen/HostScreen', () => ({ HostScreen: () => createElement('WorkspacePicker') }))
vi.mock('../components/WorkspaceDetailPlaceholder', () => ({
WorkspaceDetailPlaceholder: () => createElement('WorkspacePlaceholder')
}))

import HostWorktreeRoute from '../../app/h/[hostId]/index.web'

describe('host root content across layouts', () => {
it.each([
{ width: 390, height: 844, ownsHostArea: true, expected: 'WorkspacePicker' },
{ width: 669, height: 951, ownsHostArea: true, expected: 'WorkspacePicker' },
{ width: 951, height: 669, ownsHostArea: true, expected: 'WorkspacePlaceholder' },
{ width: 951, height: 669, ownsHostArea: false, expected: 'WorkspacePicker' }
])('renders $expected at $width with ownership $ownsHostArea', (state) => {
Object.assign(viewport, state)
let tree: ReactTestRenderer | undefined
act(() => {
tree = create(createElement(HostWorktreeRoute))
})
expect(tree?.toJSON()).toMatchObject({ type: state.expected })
act(() => tree?.unmount())
})

it('returns the picker after rotating a host root from landscape to portrait', () => {
Object.assign(viewport, { width: 951, height: 669, ownsHostArea: true })
let tree: ReactTestRenderer | undefined
act(() => {
tree = create(createElement(HostWorktreeRoute))
})
expect(tree?.toJSON()).toMatchObject({ type: 'WorkspacePlaceholder' })
Object.assign(viewport, { width: 669, height: 951 })
act(() => tree?.update(createElement(HostWorktreeRoute)))
expect(tree?.toJSON()).toMatchObject({ type: 'WorkspacePicker' })
act(() => tree?.unmount())
})
})
Loading