From 32644c8e7404137f4ea43136ee3c73c17f5bc30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 25 Nov 2026 11:38:20 +0100 Subject: [PATCH 1/3] feat(ios): leave Split View on an iPhone Duo simulator --- .../RunnerTests+CommandExecution.swift | 6 ++- .../RunnerTests+Models.swift | 1 + .../RunnerTests+SynthesizedInteraction.swift | 5 +- .../apple-runner/src/runner-command-types.ts | 1 + .../command-surface/src/interaction/index.ts | 2 +- packages/contracts/src/gesture-plan-types.ts | 8 +-- packages/contracts/src/gesture-runtime.ts | 8 +-- packages/contracts/src/interactor-types.ts | 4 +- packages/contracts/src/scroll-gesture.ts | 7 +-- packages/daemon/src/core/gesture-runtime.ts | 51 ++++++++++++------- .../interaction-gesture-viewport.test.ts | 12 +++-- .../src/gesture-plan-split-view.test.ts | 37 ++++++++++---- packages/gestures/src/gesture-plan.ts | 25 +++++++-- .../__tests__/index-runner-requests.test.ts | 2 +- .../src/foldable/split-view.test.ts | 31 ++++++++--- .../platform-apple/src/foldable/split-view.ts | 21 +++++--- .../platform-apple/src/interactions.test.ts | 2 +- packages/platform-apple/src/interactions.ts | 8 +-- .../src/webdriver-interactor.ts | 3 +- src/commands/schema/cli-help-foldable.ts | 2 +- website/docs/docs/commands.md | 2 +- 21 files changed, 165 insertions(+), 73 deletions(-) diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift index eb785cabe0..64c63c9a61 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+CommandExecution.swift @@ -709,7 +709,11 @@ extension RunnerTests { } return Self.reportingSchedule(execution.schedule, in: response) case .gestureViewport: - let frame = try gestureViewportFrame(app: activeApp, includesKeyboard: command.includesKeyboard == true) + let frame = try gestureViewportFrame( + app: activeApp, + includesKeyboard: command.includesKeyboard == true, + displayViewport: command.displayViewport == true + ) guard !frame.isNull, !frame.isInfinite, !frame.isEmpty else { return Response(ok: false, error: ErrorPayload(code: "COMMAND_FAILED", message: "Active app interaction viewport is unavailable")) } diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift index e41025bb45..7154379dd1 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift @@ -257,6 +257,7 @@ struct Command: Codable { let textEntryMode: String? let action: String? let includesKeyboard: Bool? + let displayViewport: Bool? let x: Double? let y: Double? let button: String? diff --git a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift index 6e1a38847f..f47f8e8ac0 100644 --- a/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift +++ b/apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SynthesizedInteraction.swift @@ -325,8 +325,11 @@ extension RunnerTests { /// context its record is routed through, so a tree with no window whose app provably fills its /// sole screen plans on that screen, the same route a synthesized tap or scroll takes. @MainActor - func gestureViewportFrame(app: XCUIApplication, includesKeyboard: Bool = false) throws -> CGRect { + func gestureViewportFrame(app: XCUIApplication, includesKeyboard: Bool = false, displayViewport: Bool = false) throws -> CGRect { #if os(iOS) + if displayViewport { + return try requireRequestLitPanelSurface(app: app).geometry.digitizerBasis.rect + } if let context = try synthesizedCoordinateContext(app: app) { let frame = context.geometry.windowOnScreen.rect return includesKeyboard || context.resolvedWindow == nil ? frame : frameAvoidingKeyboard(app: app, frame: frame) diff --git a/packages/apple-runner/src/runner-command-types.ts b/packages/apple-runner/src/runner-command-types.ts index 0fda811aa3..68e7ef740a 100644 --- a/packages/apple-runner/src/runner-command-types.ts +++ b/packages/apple-runner/src/runner-command-types.ts @@ -82,6 +82,7 @@ export type RunnerCommand = { textEntryMode?: 'append' | 'replace'; action?: 'get' | 'accept' | 'dismiss'; includesKeyboard?: boolean; + displayViewport?: boolean; x?: number; y?: number; button?: ClickButton; diff --git a/packages/command-surface/src/interaction/index.ts b/packages/command-surface/src/interaction/index.ts index 4d72f3455e..4aaa0387d6 100644 --- a/packages/command-surface/src/interaction/index.ts +++ b/packages/command-surface/src/interaction/index.ts @@ -667,7 +667,7 @@ const gestureCommandFacet = defineCommandFacet({ summary: 'Run pan, fling, swipe, pinch, rotate, transform, tap, or drag gestures', searchHint: 'reorder zoom multi-touch', cliDetail: - 'Argument shapes: pan [durationMs], fling [distance], swipe , pinch [x y | @ref|selector] (centered on the screen when neither is given), rotate [x] [y], transform [durationMs], tap [... ] [--hold-ms ] [--count ] [--pause-ms ], or drag [sourceHoldMs] [moveMs] [destinationHoldMs]; drag holds the source down first (800 ms by default) before moving, which is what engages a reorder handle. For command plans, output only command lines. Android transform verification should use all app-observable effects, for example wait text "pan changed yes", wait text "pinch changed yes", and wait text "rotate changed yes", not exact transform values. gesture swipe accepts --no-post-gesture-stabilization to skip the stabilization wait before the next read, for a caller whose own polling verifies the screen.', + 'Argument shapes: pan [durationMs], fling [distance], swipe , pinch [x y | @ref|selector] (centered on the screen when neither is given), rotate [x] [y], transform [durationMs], tap [... ] [--hold-ms ] [--count ] [--pause-ms ], or drag [sourceHoldMs] [moveMs] [destinationHoldMs]; drag holds the source down first (800 ms by default) before moving, which is what engages a reorder handle. For command plans, output only command lines. Android transform verification should use all app-observable effects, for example wait text "pan changed yes", wait text "pinch changed yes", and wait text "rotate changed yes", not exact transform values. gesture swipe accepts --no-post-gesture-stabilization to skip the stabilization wait before the next read, for a caller whose own polling verifies the screen.', }, metadata: metadata('gesture'), run: (client, input) => diff --git a/packages/contracts/src/gesture-plan-types.ts b/packages/contracts/src/gesture-plan-types.ts index ef537bb379..6606c17620 100644 --- a/packages/contracts/src/gesture-plan-types.ts +++ b/packages/contracts/src/gesture-plan-types.ts @@ -102,10 +102,12 @@ export type SinglePointerTrajectory = { /** * Where a contact starts. `screen-edge` asks the platform to deliver the contact as a screen-edge * touch, which edge gesture recognizers require. `split-view-edge` is a screen-edge touch that - * starts the system Split View gesture; only a foldable iOS simulator with its inner panel lit - * executes it. + * starts the system Split View gesture. `split-view-divider` starts an ordinary drag on the system + * divider. Only a foldable iOS simulator with its inner panel lit executes Split View gestures. */ -export type GestureContactOrigin = 'screen-edge' | 'split-view-edge'; +export type GestureContactOrigin = 'screen-edge' | 'split-view-edge' | 'split-view-divider'; + +export type GestureViewportScope = 'including-keyboard' | 'display'; export type SinglePointerGesturePlan = { topology: 'single'; diff --git a/packages/contracts/src/gesture-runtime.ts b/packages/contracts/src/gesture-runtime.ts index 6243272115..62aec63a88 100644 --- a/packages/contracts/src/gesture-runtime.ts +++ b/packages/contracts/src/gesture-runtime.ts @@ -1,6 +1,6 @@ import type { DeviceInfo } from '@agent-device/kernel/device'; import type { Rect } from '@agent-device/kernel/snapshot'; -import type { GesturePlan } from './gesture-plan-types.ts'; +import type { GesturePlan, GestureViewportScope } from './gesture-plan-types.ts'; import { localInteractorSource, providerInteractorSource, @@ -26,7 +26,7 @@ export type GesturePlanInput = Readonly<{ /** Reading the gesture coordinate frame needs no plan — only the owner's authority. */ export type GestureViewportInput = Readonly<{ - includesKeyboard?: true; + scope?: GestureViewportScope; options?: Readonly<{ appBundleId?: string }>; execution?: SnapshotRuntimeExecution; }>; @@ -152,8 +152,8 @@ function bindGestureOperations( 'Runtime owner advertised gestureViewport without an interactor implementation', ); } - return input.includesKeyboard - ? await interactor.gestureViewport(true) + return input.scope + ? await interactor.gestureViewport(input.scope) : await interactor.gestureViewport(); }, } diff --git a/packages/contracts/src/interactor-types.ts b/packages/contracts/src/interactor-types.ts index 87c1a69e5e..7a4eaf9e3f 100644 --- a/packages/contracts/src/interactor-types.ts +++ b/packages/contracts/src/interactor-types.ts @@ -9,7 +9,7 @@ import type { FillUnconfirmedVerification } from './fill-evidence.ts'; import type { ScrollDirection } from './scroll-gesture.ts'; import type { ScrollExecutionOptions } from './scroll-command.ts'; import type { TvRemoteButton } from './tv-remote.ts'; -import type { GesturePlan } from './gesture-plan-types.ts'; +import type { GesturePlan, GestureViewportScope } from './gesture-plan-types.ts'; import type { ReadSettingResult, SettingOptions } from './settings.ts'; import type { ReadableSetting } from './settings-catalog.ts'; import type { SessionSurface } from './session-surface.ts'; @@ -416,7 +416,7 @@ export type Interactor = { ): Promise<{ found: boolean; }>; - gestureViewport?(includesKeyboard?: true): Promise; + gestureViewport?(scope?: GestureViewportScope): Promise; back(mode?: BackMode): Promise; /** * Optional (parity with `actionButton`): opens the springboard, a control not every owner diff --git a/packages/contracts/src/scroll-gesture.ts b/packages/contracts/src/scroll-gesture.ts index 4818355fcf..aa4ff9be0f 100644 --- a/packages/contracts/src/scroll-gesture.ts +++ b/packages/contracts/src/scroll-gesture.ts @@ -28,12 +28,13 @@ export const SWIPE_PRESETS = [ 'right-edge', 'split-view-left', 'split-view-right', + 'split-view-exit', ] as const; export type SwipePreset = (typeof SWIPE_PRESETS)[number]; -/** Presets that move a full-screen app into one half of Split View on a foldable iOS simulator. */ +/** Presets that enter or leave Split View on a foldable iOS simulator. */ export type SplitViewSwipePreset = Extract; export function isSplitViewSwipePreset(preset: SwipePreset): preset is SplitViewSwipePreset { - return preset === 'split-view-left' || preset === 'split-view-right'; + return preset.startsWith('split-view-'); } /** Why a Split View swipe preset was refused before any touch went down. */ const SPLIT_VIEW_GESTURE_REASONS = { @@ -49,7 +50,7 @@ export function splitViewUnavailableError( ...details, reason: SPLIT_VIEW_GESTURE_REASONS.unavailable.reason, dispatched: 'no', - hint: 'Use an iPhone Duo simulator with its inner panel lit (not closed), open the app full screen, then swipe again.', + hint: 'Use an iPhone Duo simulator with its inner panel lit.', }); } const SCREEN_EDGE_SWIPE_PRESETS: ReadonlySet = new Set(['left-edge', 'right-edge']); diff --git a/packages/daemon/src/core/gesture-runtime.ts b/packages/daemon/src/core/gesture-runtime.ts index 6d4c41d12b..3f56ad1e33 100644 --- a/packages/daemon/src/core/gesture-runtime.ts +++ b/packages/daemon/src/core/gesture-runtime.ts @@ -1,5 +1,9 @@ import { gestureRefusalMessage } from '@agent-device/contracts/gesture-admission'; -import type { GestureCommandInput, GesturePlan } from '@agent-device/contracts/gesture-plan-types'; +import type { + GestureCommandInput, + GesturePlan, + GestureViewportScope, +} from '@agent-device/contracts/gesture-plan-types'; import type { GesturePlanInput, GestureRuntimeOperations, @@ -122,18 +126,31 @@ export async function resolveBoundGestureRuntime( }); if (admitted.type === 'response') return { ok: false, response: admitted.response }; // One bind, with the exactly-typed use the tier selected (ADR 0019 §9). - const includesKeyboard = - params.input.intent === 'pan' && - (params.input.pointerCount ?? 1) === 1 && - params.input.executionProfile !== 'endpoint-hold' - ? true - : undefined; return { ok: true, - gestures: await bindGestureTier(admitted.bind, params.device, plan, includesKeyboard), + gestures: await bindGestureTier( + admitted.bind, + params.device, + plan, + gestureViewportScope(params.input), + ), }; } +function gestureViewportScope(input: GestureCommandInput): GestureViewportScope | undefined { + if (input.intent === 'fling' && 'preset' in input && input.preset === 'split-view-exit') { + return 'display'; + } + if ( + input.intent === 'pan' && + (input.pointerCount ?? 1) === 1 && + input.executionProfile !== 'endpoint-hold' + ) { + return 'including-keyboard'; + } + return undefined; +} + /** * The ONE place each bound gesture tier executes (R52/R54, shared by `gesture` and `swipe`). * @@ -146,7 +163,7 @@ async function bindGestureTier( bind: Extract>, { type: 'admitted' }>['bind'], device: DeviceInfo, plan: GestureRuntimePlan, - includesKeyboard?: true, + scope?: GestureViewportScope, ): Promise { switch (plan.tier) { case 'plan': { @@ -154,7 +171,7 @@ async function bindGestureTier( return { performPlan: async (gesturePlan, context) => await runtime.operations.performGesturePlan(gesturePlanInput(gesturePlan, context)), - ...selectGestureFrame(runtime, includesKeyboard), + ...selectGestureFrame(runtime, scope), ...(runtime.operations.querySelector ? { querySelector: runtime.operations.querySelector } : {}), @@ -194,7 +211,7 @@ async function bindGestureTier( gesturePlanInput(gesturePlan, context), ), // A held pan reaches this tier too, and a pan's frame read includes the keyboard. - ...selectGestureFrame(runtime, includesKeyboard), + ...selectGestureFrame(runtime, scope), ...(runtime.operations.querySelector ? { querySelector: runtime.operations.querySelector } : {}), @@ -218,7 +235,7 @@ function selectGestureFrame( gestureViewport?: GestureRuntimeOperations['gestureViewport']; }>; }>, - includesKeyboard?: true, + scope?: GestureViewportScope, ): Pick; function selectGestureFrame( runtime: Readonly<{ @@ -227,7 +244,7 @@ function selectGestureFrame( gestureViewport?: GestureRuntimeOperations['gestureViewport']; }>; }>, - includesKeyboard?: true, + scope?: GestureViewportScope, ): Partial> { const { gestureViewport } = runtime.operations; const selectedCapture = runtime.operations.captureSnapshot @@ -244,9 +261,7 @@ function selectGestureFrame( ...(selected ? { gestureViewport: async (context: DaemonCommandContext) => - await selected.operations.gestureViewport( - gestureViewportInput(context, includesKeyboard), - ), + await selected.operations.gestureViewport(gestureViewportInput(context, scope)), } : {}), }); @@ -261,9 +276,9 @@ function gesturePlanInput(plan: GesturePlan, context: DaemonCommandContext): Ges }; } -function gestureViewportInput(context: DaemonCommandContext, includesKeyboard?: true) { +function gestureViewportInput(context: DaemonCommandContext, scope?: GestureViewportScope) { return { - ...(includesKeyboard ? { includesKeyboard } : {}), + ...(scope ? { scope } : {}), ...(context.appBundleId === undefined ? {} : { options: { appBundleId: context.appBundleId } }), execution: runtimeExecutionFromContext(context), }; diff --git a/packages/daemon/src/execution/interaction/internal/interaction-gesture-viewport.test.ts b/packages/daemon/src/execution/interaction/internal/interaction-gesture-viewport.test.ts index 897e600a4a..1ab06248f6 100644 --- a/packages/daemon/src/execution/interaction/internal/interaction-gesture-viewport.test.ts +++ b/packages/daemon/src/execution/interaction/internal/interaction-gesture-viewport.test.ts @@ -11,10 +11,16 @@ const to = { x: 120, y: 320 }; const pan = { kind: 'pan', origin: from, delta: { x: 0, y: 100 }, durationMs: 500 }; test.each([ - { name: 'one-finger pan', command: 'gesture', input: pan, includesKeyboard: true }, + { name: 'one-finger pan', command: 'gesture', input: pan, scope: 'including-keyboard' }, { name: 'two-finger pan', command: 'gesture', input: { ...pan, pointerCount: 2 } }, { name: 'fling', command: 'gesture', input: { kind: 'fling', direction: 'down', origin: from } }, { name: 'swipe', command: 'swipe', input: { from, to } }, + { + name: 'Split View exit', + command: 'gesture', + input: { kind: 'swipe', preset: 'split-view-exit' }, + scope: 'display', + }, { name: 'Maestro coordinate swipe', command: 'gesture', @@ -64,8 +70,8 @@ test.each([ expect(response).toMatchObject({ ok: true }); expect(gestureViewport).toHaveBeenCalledOnce(); - expect(gestureViewport.mock.calls[0]?.[0].includesKeyboard).toBe( - 'includesKeyboard' in scenario ? scenario.includesKeyboard : undefined, + expect(gestureViewport.mock.calls[0]?.[0].scope).toBe( + 'scope' in scenario ? scenario.scope : undefined, ); }); diff --git a/packages/gestures/src/gesture-plan-split-view.test.ts b/packages/gestures/src/gesture-plan-split-view.test.ts index 115ad94ed8..402b13a7f7 100644 --- a/packages/gestures/src/gesture-plan-split-view.test.ts +++ b/packages/gestures/src/gesture-plan-split-view.test.ts @@ -22,13 +22,32 @@ test.each([ expect([samples[1]!.point, samples[2]!.point]).toEqual([middle, middle]); }); -test('a Split View preset off iOS is refused before planning a touch', () => { - expect(() => - buildGesturePlan({ intent: 'fling', preset: 'split-view-left' }, viewport, 'android'), - ).toThrow( - expect.objectContaining({ - code: 'UNSUPPORTED_OPERATION', - details: expect.objectContaining({ reason: 'split_view_unavailable', dispatched: 'no' }), - }), - ); +test('split-view-exit drags the divider from the center to the left edge', () => { + const display = { ...viewport, x: 20, y: 10 }; + const plan = buildGesturePlan({ intent: 'fling', preset: 'split-view-exit' }, display, 'ios'); + expect(plan).toMatchObject({ + topology: 'single', + executionProfile: 'timed-pan', + contactOrigin: 'split-view-divider', + pointers: [ + { + samples: [ + { offsetMs: 0, point: { x: 495.5, y: 344.5 } }, + { offsetMs: 700, point: { x: 21, y: 344.5 } }, + ], + }, + ], + }); }); + +test.each(['split-view-left', 'split-view-exit'] as const)( + '%s off iOS is refused before planning a touch', + (preset) => { + expect(() => buildGesturePlan({ intent: 'fling', preset }, viewport, 'android')).toThrow( + expect.objectContaining({ + code: 'UNSUPPORTED_OPERATION', + details: expect.objectContaining({ reason: 'split_view_unavailable', dispatched: 'no' }), + }), + ); + }, +); diff --git a/packages/gestures/src/gesture-plan.ts b/packages/gestures/src/gesture-plan.ts index ee8fbb3a63..5b157b2aaa 100644 --- a/packages/gestures/src/gesture-plan.ts +++ b/packages/gestures/src/gesture-plan.ts @@ -21,6 +21,7 @@ import { GESTURE_TAP_MIN_CONTACTS, } from '@agent-device/contracts/gesture-plan-types'; import type { + GestureContactOrigin, GesturePlan, GestureExecutionProfile, GestureSemanticInput, @@ -61,6 +62,7 @@ const GESTURE_VIEWPORT_INSET_PX = 1; const DEFAULT_PAN_DURATION_MS = 500; export const GESTURE_FLING_DURATION_MS = 100; const SPLIT_VIEW_DURATION_MS = 2100; +const SPLIT_VIEW_EXIT_DURATION_MS = 700; const SPLIT_VIEW_EDGE_INSET_PX = 1; const DEFAULT_MULTI_TOUCH_DURATION_MS = 300; const MAX_ROTATION_DEGREES_PER_SAMPLE = 3; @@ -90,6 +92,12 @@ const GESTURE_PLATFORM_PROFILES = { web: DEFAULT_GESTURE_PLATFORM_PROFILE, } satisfies Record; +export function isSplitViewContactOrigin( + origin: GestureContactOrigin | undefined, +): origin is 'split-view-edge' | 'split-view-divider' { + return origin === 'split-view-edge' || origin === 'split-view-divider'; +} + /** Plans one physical gesture. Public aliases must be normalized before this boundary. */ export function buildGesturePlan( input: GestureSemanticInput, @@ -274,11 +282,6 @@ function buildFlingPlan( ); } -/** - * The system Split View drag: up from the bottom edge to the middle, a hold that lifts the app - * window, then sideways toward the requested half. The sideways end stays short of the vertical - * travel, so the edge touch keeps its upward swipe direction. - */ function buildSplitViewPlan( preset: SplitViewSwipePreset, viewport: Rect, @@ -289,6 +292,18 @@ function buildSplitViewPlan( } const centerX = viewport.x + viewport.width / 2; const middleY = viewport.y + viewport.height / 2; + if (preset === 'split-view-exit') { + const plan = buildSinglePointerPlan( + 'fling', + { x: centerX, y: middleY }, + { x: viewport.x + SPLIT_VIEW_EDGE_INSET_PX, y: middleY }, + SPLIT_VIEW_EXIT_DURATION_MS, + viewport, + 'timed-pan', + ); + return { ...plan, contactOrigin: 'split-view-divider' }; + } + // The sideways travel stays shorter than the initial lift so the edge touch stays upward. const endX = viewport.x + viewport.width * (preset === 'split-view-left' ? 0.2 : 0.8); const samples: SinglePointerTrajectory['samples'] = [ { diff --git a/packages/platform-apple/src/__tests__/index-runner-requests.test.ts b/packages/platform-apple/src/__tests__/index-runner-requests.test.ts index bbd326cd7d..5adf7820ee 100644 --- a/packages/platform-apple/src/__tests__/index-runner-requests.test.ts +++ b/packages/platform-apple/src/__tests__/index-runner-requests.test.ts @@ -101,7 +101,7 @@ const INTERACTOR_SITES: Record = { 'ios-simulator.interactions-gesture-viewport.read': [IOS_SIMULATOR, (i) => i.gestureViewport!()], 'ios-simulator.interactions-gesture-viewport.include-keyboard': [ IOS_SIMULATOR, - (i) => i.gestureViewport!(true), + (i) => i.gestureViewport!('including-keyboard'), ], 'ios-simulator.interactions-press-series.tap': [ IOS_SIMULATOR, diff --git a/packages/platform-apple/src/foldable/split-view.test.ts b/packages/platform-apple/src/foldable/split-view.test.ts index 54195f02ce..7a4ac29db1 100644 --- a/packages/platform-apple/src/foldable/split-view.test.ts +++ b/packages/platform-apple/src/foldable/split-view.test.ts @@ -7,6 +7,7 @@ vi.mock('../core/runner-client.ts', () => ({ })); import type { DeviceInfo } from '@agent-device/kernel/device'; +import type { SplitViewSwipePreset } from '@agent-device/contracts/scroll-gesture'; import { buildGesturePlan } from '@agent-device/gestures/gesture-plan'; import { runAppleRunnerCommand } from '../core/runner-client.ts'; import { createLocalAppleToolProvider, withAppleToolProvider } from '../core/tool-provider.ts'; @@ -22,7 +23,6 @@ bindTestCommandHost(); const mockRunner = vi.mocked(runAppleRunnerCommand); const viewport = { x: 0, y: 0, width: 951, height: 669 }; -const splitPlan = buildGesturePlan({ intent: 'fling', preset: 'split-view-left' }, viewport, 'ios'); beforeEach(() => { mockRunner.mockClear(); @@ -35,7 +35,11 @@ function simulator(): DeviceInfo { return { ...IOS_SIMULATOR, id: `${IOS_SIMULATOR.id}-split-${simulatorCount}` }; } -async function performSplit(device: DeviceInfo, panels: object) { +async function performSplit( + device: DeviceInfo, + panels: object, + preset: SplitViewSwipePreset = 'split-view-left', +) { const provider = createLocalAppleToolProvider({ runCommand: async (_command, args) => { if (args.slice(0, 4).join(' ') === 'devicectl device info displays') { @@ -44,8 +48,9 @@ async function performSplit(device: DeviceInfo, panels: object) { return { stdout: '', stderr: '', exitCode: 0 }; }, }); + const plan = buildGesturePlan({ intent: 'fling', preset }, viewport, 'ios'); await withAppleToolProvider(provider, () => - createAppleInteractor(device, {}, createLiveTestHostEnvironment()).performGesture!(splitPlan), + createAppleInteractor(device, {}, createLiveTestHostEnvironment()).performGesture!(plan), ); } @@ -61,12 +66,22 @@ test('an open foldable simulator sends the Split View drag as a screen-edge touc ); }); +test('an open foldable simulator sends the divider drag as an ordinary timed pan', async () => { + await performSplit(simulator(), IPHONE_DUO_OPEN, 'split-view-exit'); + const command = mockRunner.mock.calls[0]?.[1]; + expect(command).toMatchObject({ + command: 'gesture', + gesturePlan: { executionProfile: 'timed-pan' }, + }); + expect(command?.gesturePlan).not.toHaveProperty('contactOrigin'); +}); + test.each([ - ['a closed foldable simulator', simulator(), IPHONE_DUO_CLOSED], - ['a single-panel simulator', simulator(), IPHONE_17_SINGLE_PANEL], - ['a physical iPhone', IOS_DEVICE, IPHONE_DUO_OPEN], -] as const)('%s refuses Split View before any touch', async (_name, device, panels) => { - await expect(performSplit(device, panels)).rejects.toMatchObject({ + ['a closed foldable simulator', simulator(), IPHONE_DUO_CLOSED, 'split-view-exit'], + ['a single-panel simulator', simulator(), IPHONE_17_SINGLE_PANEL, 'split-view-left'], + ['a physical iPhone', IOS_DEVICE, IPHONE_DUO_OPEN, 'split-view-left'], +] as const)('%s refuses Split View before any touch', async (_name, device, panels, preset) => { + await expect(performSplit(device, panels, preset)).rejects.toMatchObject({ code: 'UNSUPPORTED_OPERATION', details: { reason: 'split_view_unavailable', dispatched: 'no' }, }); diff --git a/packages/platform-apple/src/foldable/split-view.ts b/packages/platform-apple/src/foldable/split-view.ts index 13629a87a2..ef3a618e73 100644 --- a/packages/platform-apple/src/foldable/split-view.ts +++ b/packages/platform-apple/src/foldable/split-view.ts @@ -1,20 +1,28 @@ import type { GesturePlan } from '@agent-device/contracts/gesture-plan-types'; +import { isSplitViewContactOrigin } from '@agent-device/gestures/gesture-plan'; import type { DeviceInfo } from '@agent-device/kernel/device'; import { splitViewUnavailableError } from '@agent-device/contracts/scroll-gesture'; import { IOS_APPLE_DISPLAY_PROBE_TIMEOUT_MS } from '../core/config.ts'; import { readFoldablePanelTable } from './orientation.ts'; -/** - * The runner form of a Split View plan. Only a foldable simulator with its inner panel lit has - * Split View; elsewhere the same bottom-edge touch opens Home or the app switcher, so the plan is - * refused before any touch. The runner sends the contact as an ordinary screen-edge touch. - */ +/** Converts a Split View contact to the runner's contact origin after checking the lit panel. */ export async function appleSplitViewRunnerPlan( device: DeviceInfo, plan: GesturePlan, signal: AbortSignal | undefined, ): Promise { - if (plan.topology !== 'single' || plan.contactOrigin !== 'split-view-edge') return plan; + if (plan.topology !== 'single' || !isSplitViewContactOrigin(plan.contactOrigin)) return plan; + await requireAppleSplitViewPanel(device, signal); + const { contactOrigin, ...runnerPlan } = plan; + return contactOrigin === 'split-view-edge' + ? { ...runnerPlan, contactOrigin: 'screen-edge' } + : runnerPlan; +} + +export async function requireAppleSplitViewPanel( + device: DeviceInfo, + signal: AbortSignal | undefined, +): Promise { const table = device.kind === 'simulator' ? await readFoldablePanelTable(device, { @@ -32,5 +40,4 @@ export async function appleSplitViewRunnerPlan( { deviceId: device.id, panelTable: table.kind }, ); } - return { ...plan, contactOrigin: 'screen-edge' }; } diff --git a/packages/platform-apple/src/interactions.test.ts b/packages/platform-apple/src/interactions.test.ts index 9940d24670..248181d556 100644 --- a/packages/platform-apple/src/interactions.test.ts +++ b/packages/platform-apple/src/interactions.test.ts @@ -355,7 +355,7 @@ test('iosRunnerOverrides reads and validates the fresh gesture viewport', async command: 'gestureViewport', appBundleId: 'com.example.App', }); - await overrides.gestureViewport(true); + await overrides.gestureViewport('including-keyboard'); assert.deepEqual(mockRunAppleRunnerCommand.mock.calls[1]?.[1], { command: 'gestureViewport', appBundleId: 'com.example.App', diff --git a/packages/platform-apple/src/interactions.ts b/packages/platform-apple/src/interactions.ts index ee568eda8d..093cff4727 100644 --- a/packages/platform-apple/src/interactions.ts +++ b/packages/platform-apple/src/interactions.ts @@ -22,7 +22,7 @@ import { assertScrollGestureInput, } from '@agent-device/contracts/scroll-gesture'; import { assertAppleMultiTouchSupported } from './multitouch-support.ts'; -import { appleSplitViewRunnerPlan } from './foldable/split-view.ts'; +import { appleSplitViewRunnerPlan, requireAppleSplitViewPanel } from './foldable/split-view.ts'; import { isMacOs, isTvOsDevice, @@ -184,13 +184,15 @@ export function iosRunnerOverrides( ); }, performGesture: async (plan) => await performGestureApple(device, ctx, runnerOpts, plan), - gestureViewport: async (includesKeyboard) => { + gestureViewport: async (scope) => { + if (scope === 'display') await requireAppleSplitViewPanel(device, runnerOpts.signal); const result = await runAppleRunnerCommand( device, { command: 'gestureViewport', appBundleId: ctx.appBundleId, - ...(includesKeyboard ? { includesKeyboard } : {}), + ...(scope === 'including-keyboard' ? { includesKeyboard: true } : {}), + ...(scope === 'display' ? { displayViewport: true } : {}), }, runnerOpts, ); diff --git a/packages/provider-webdriver/src/webdriver-interactor.ts b/packages/provider-webdriver/src/webdriver-interactor.ts index a449d60bd1..7cb0bb3252 100644 --- a/packages/provider-webdriver/src/webdriver-interactor.ts +++ b/packages/provider-webdriver/src/webdriver-interactor.ts @@ -10,6 +10,7 @@ import type { KeyboardStatusResult, } from '@agent-device/contracts/interactor-types'; import type { GesturePlan } from '@agent-device/contracts/gesture-plan-types'; +import { isSplitViewContactOrigin } from '@agent-device/gestures/gesture-plan'; import { type ScrollDirection, buildScrollGesturePlan, @@ -280,7 +281,7 @@ class WebDriverInteractor implements Interactor { } async performGesture(plan: GesturePlan): Promise> { - if (plan.topology === 'single' && plan.contactOrigin === 'split-view-edge') { + if (plan.topology === 'single' && isSplitViewContactOrigin(plan.contactOrigin)) { throw splitViewUnavailableError('WebDriver providers do not support Split View'); } this.requireSupport(webDriverOperationForGesture(plan)); diff --git a/src/commands/schema/cli-help-foldable.ts b/src/commands/schema/cli-help-foldable.ts index b90d3a0e92..b2cc20070c 100644 --- a/src/commands/schema/cli-help-foldable.ts +++ b/src/commands/schema/cli-help-foldable.ts @@ -21,5 +21,5 @@ Changing the pose: Home and app switcher: On a foldable iOS simulator, home and app-switcher press the Home button through the same helper's simulator HID, once for home and twice for the app switcher, because the XCUITest Home press does not reach the home screen there. Verified closed, half-open, and open. The first press on a host or Xcode builds the helper and takes longer. - Split View on an unfolded device (the inner panel lit, so open or half-open; check the exact pose with UIHinge.status): with the session app full screen, run gesture swipe split-view-left or gesture swipe split-view-right. The app moves to that half and the Home Screen fills the other; open launches a second app there and binds the session to it. Switch between the halves with open ; the split stays. Any other device, a closed Duo, or a WebDriver provider refuses with UNSUPPORTED_OPERATION and reason split_view_unavailable before any touch.`, + Split View on an unfolded iPhone Duo simulator requires the inner panel to be lit. With the session app full screen, run gesture swipe split-view-left or gesture swipe split-view-right to move it to that half. Run open to launch the second app on the other half or switch between the two apps. With both apps in Split View, run gesture swipe split-view-exit to drag the divider left and make the right-hand app fill the screen. Other devices, a closed Duo, and WebDriver providers refuse these presets with UNSUPPORTED_OPERATION and reason split_view_unavailable before any touch.`, } as const; diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 351abbfa96..f41d8fb56e 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -415,7 +415,7 @@ Exact behavior: `agent-device help fold`. - Take a new snapshot after every fold, even a failed one. Refs and coordinates from before it are stale. - On iOS, `fold` needs an Xcode with foldable HID support. The first fold on a host or Xcode builds a helper and takes longer. The response's panel size is not the next snapshot's viewport, so do not use it to place a tap. - On a foldable iOS simulator, `home` and `app-switcher` press the Home button through the same helper, because the XCUITest Home press does not reach the home screen there. The first press on a host or Xcode builds the helper and takes longer. -- On an unfolded iPhone Duo simulator, with the inner panel lit, `gesture swipe split-view-left` or `gesture swipe split-view-right` moves the full-screen app into that half of Split View. Then `open ` launches a second app into the other half, and `open` switches between them. Other devices, a closed Duo, and WebDriver providers refuse with `split_view_unavailable` before any touch. +- On an unfolded iPhone Duo simulator with the inner panel lit, run `gesture swipe split-view-left` or `gesture swipe split-view-right` to move the full-screen app to that half. Use `open ` to launch the second app or switch between the two apps. With both apps in Split View, run `gesture swipe split-view-exit` to drag the divider left and make the right-hand app fill the screen. Other devices, a closed Duo, and WebDriver providers refuse these presets with `split_view_unavailable` before any touch. - `--keyframes` plays a timed hinge trajectory on iOS only, for example `fold --keyframes '[{"atMs":0,"angle":0},{"atMs":1667,"angle":160},{"atMs":5000,"angle":180}]'`. - For failure reasons, see [error reasons](/docs/error-reasons). For panels and poses, see `agent-device help foldable`. From 7b02767b66a8272cfc4e5419fc47574f3b9ef756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 25 Nov 2026 11:47:35 +0100 Subject: [PATCH 2/3] fix(webdriver): keep Split View checks in shared contracts --- packages/contracts/src/scroll-gesture.ts | 6 ++++++ packages/gestures/src/gesture-plan.ts | 7 ------- packages/platform-apple/src/foldable/split-view.ts | 6 ++++-- packages/provider-webdriver/src/webdriver-interactor.ts | 2 +- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/contracts/src/scroll-gesture.ts b/packages/contracts/src/scroll-gesture.ts index aa4ff9be0f..b9fe111ef7 100644 --- a/packages/contracts/src/scroll-gesture.ts +++ b/packages/contracts/src/scroll-gesture.ts @@ -1,4 +1,5 @@ import { AppError, type ReasonTable } from '@agent-device/kernel/errors'; +import type { GestureContactOrigin } from './gesture-plan-types.ts'; import { SCROLL_REASONS } from './scroll-reasons.ts'; import { defineStringEnum } from './string-enum.ts'; import { isViewportRootNode } from './snapshot-visibility.ts'; @@ -36,6 +37,11 @@ export type SplitViewSwipePreset = Extract; export function isSplitViewSwipePreset(preset: SwipePreset): preset is SplitViewSwipePreset { return preset.startsWith('split-view-'); } +export function isSplitViewContactOrigin( + origin: GestureContactOrigin | undefined, +): origin is 'split-view-edge' | 'split-view-divider' { + return origin === 'split-view-edge' || origin === 'split-view-divider'; +} /** Why a Split View swipe preset was refused before any touch went down. */ const SPLIT_VIEW_GESTURE_REASONS = { // Split View presets need an iOS simulator with more than one panel and its inner panel lit. diff --git a/packages/gestures/src/gesture-plan.ts b/packages/gestures/src/gesture-plan.ts index 5b157b2aaa..f022989095 100644 --- a/packages/gestures/src/gesture-plan.ts +++ b/packages/gestures/src/gesture-plan.ts @@ -21,7 +21,6 @@ import { GESTURE_TAP_MIN_CONTACTS, } from '@agent-device/contracts/gesture-plan-types'; import type { - GestureContactOrigin, GesturePlan, GestureExecutionProfile, GestureSemanticInput, @@ -92,12 +91,6 @@ const GESTURE_PLATFORM_PROFILES = { web: DEFAULT_GESTURE_PLATFORM_PROFILE, } satisfies Record; -export function isSplitViewContactOrigin( - origin: GestureContactOrigin | undefined, -): origin is 'split-view-edge' | 'split-view-divider' { - return origin === 'split-view-edge' || origin === 'split-view-divider'; -} - /** Plans one physical gesture. Public aliases must be normalized before this boundary. */ export function buildGesturePlan( input: GestureSemanticInput, diff --git a/packages/platform-apple/src/foldable/split-view.ts b/packages/platform-apple/src/foldable/split-view.ts index ef3a618e73..a0555978f6 100644 --- a/packages/platform-apple/src/foldable/split-view.ts +++ b/packages/platform-apple/src/foldable/split-view.ts @@ -1,7 +1,9 @@ import type { GesturePlan } from '@agent-device/contracts/gesture-plan-types'; -import { isSplitViewContactOrigin } from '@agent-device/gestures/gesture-plan'; import type { DeviceInfo } from '@agent-device/kernel/device'; -import { splitViewUnavailableError } from '@agent-device/contracts/scroll-gesture'; +import { + isSplitViewContactOrigin, + splitViewUnavailableError, +} from '@agent-device/contracts/scroll-gesture'; import { IOS_APPLE_DISPLAY_PROBE_TIMEOUT_MS } from '../core/config.ts'; import { readFoldablePanelTable } from './orientation.ts'; diff --git a/packages/provider-webdriver/src/webdriver-interactor.ts b/packages/provider-webdriver/src/webdriver-interactor.ts index 7cb0bb3252..84f8ec1476 100644 --- a/packages/provider-webdriver/src/webdriver-interactor.ts +++ b/packages/provider-webdriver/src/webdriver-interactor.ts @@ -10,10 +10,10 @@ import type { KeyboardStatusResult, } from '@agent-device/contracts/interactor-types'; import type { GesturePlan } from '@agent-device/contracts/gesture-plan-types'; -import { isSplitViewContactOrigin } from '@agent-device/gestures/gesture-plan'; import { type ScrollDirection, buildScrollGesturePlan, + isSplitViewContactOrigin, splitViewUnavailableError, } from '@agent-device/contracts/scroll-gesture'; import type { TvRemoteButton } from '@agent-device/contracts/tv-remote'; From 4f72a4aed3f8f998de28f5ffb9f0f5d7e25daf44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pierzcha=C5=82a?= Date: Wed, 25 Nov 2026 11:54:49 +0100 Subject: [PATCH 3/3] test(apple): cover the display viewport runner request --- contracts/fixtures/runner-requests.json | 1 + .../src/__tests__/interactor-foldable-runner-requests.test.ts | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/contracts/fixtures/runner-requests.json b/contracts/fixtures/runner-requests.json index 703af4791f..86c1e967ca 100644 --- a/contracts/fixtures/runner-requests.json +++ b/contracts/fixtures/runner-requests.json @@ -8,6 +8,7 @@ {"name": "ios-device.recording-stop.no-app", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop"}}, {"name": "ios-device.recording-stop.session", "producer": "src/__tests__/screen-recording-runner-requests.test.ts", "request": {"command": "recordStop", "appBundleId": "com.example.app"}}, {"name": "ios-foldable.alert.get", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "alert", "action": "get", "appBundleId": "com.example.app", "timeoutMs": 10000, "commandId": ""}}, + {"name": "ios-foldable.interactions-gesture-viewport.display", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "gestureViewport", "appBundleId": "com.example.app", "displayViewport": true, "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": ""}}, {"name": "ios-foldable.interactions-tap.synthesized", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "tap", "x": 10, "y": 20, "synthesized": true, "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": ""}}, {"name": "ios-foldable.interactor-find-text.lit-panel", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "findText", "text": "Search", "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": ""}}, {"name": "ios-foldable.interactor-keyboard-dismiss.lit-panel", "producer": "packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts", "request": {"command": "keyboardDismiss", "appBundleId": "com.example.app", "litPanel": {"displayId": 3, "widthPt": 669, "heightPt": 951}, "commandId": ""}}, diff --git a/packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts b/packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts index b78e96a010..da3e2e73ab 100644 --- a/packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts +++ b/packages/platform-apple/src/__tests__/interactor-foldable-runner-requests.test.ts @@ -43,6 +43,10 @@ const DUO_SIMULATOR: DeviceInfo = { ...IOS_SIMULATOR, name: 'iPhone Duo' }; type InteractorDrive = readonly [DeviceInfo, (interactor: Interactor) => Promise]; const INTERACTOR_SITES: Record = { + 'ios-foldable.interactions-gesture-viewport.display': [ + DUO_SIMULATOR, + (i) => i.gestureViewport!('display'), + ], 'ios-foldable.interactions-tap.synthesized': [DUO_SIMULATOR, (i) => i.tap(10, 20)], 'ios-foldable.interactor-snapshot.lit-panel': [ DUO_SIMULATOR,