Repository navigation
feat(ios): move the app into Split View on an iPhone Duo simulator #5083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ee4160d
feat(ios): move the app into Split View on an iPhone Duo simulator
thymikee 8664c7a
docs(reasons): regenerate the error reasons page
thymikee 4d81534
fix(ios): own the Split View refusal in contracts and keep request ca…
thymikee d7fb66f
fix(ios): name an unread panel table in the Split View refusal
thymikee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { expect, test } from 'vitest'; | ||
| import { buildGesturePlan } from './gesture-plan.ts'; | ||
|
|
||
| const viewport = { x: 0, y: 0, width: 951, height: 669 }; | ||
|
|
||
| test.each([ | ||
| ['split-view-left', (x: number) => x < viewport.width / 2], | ||
| ['split-view-right', (x: number) => x > viewport.width / 2], | ||
| ] as const)('%s drags up from the bottom edge, holds, then moves to its half', (preset, inHalf) => { | ||
| const plan = buildGesturePlan({ intent: 'fling', preset }, viewport, 'ios'); | ||
| expect(plan.topology === 'single' && plan.contactOrigin).toBe('split-view-edge'); | ||
| const samples = plan.pointers[0].samples; | ||
| const start = samples[0]!.point; | ||
| const end = samples.at(-1)!.point; | ||
| expect(start.y).toBeGreaterThan(viewport.height - 2); | ||
| expect(inHalf(end.x)).toBe(true); | ||
| // The runner derives the edge touch's swipe direction from start to end; it must stay upward. | ||
| expect(Math.abs(end.x - start.x)).toBeLessThan(Math.abs(end.y - start.y)); | ||
| // The pause at the middle is what lifts the app window before the sideways move. | ||
| const middle = { x: viewport.width / 2, y: viewport.height / 2 }; | ||
| expect(samples.map((sample) => sample.offsetMs)).toEqual([0, 600, 1400, 1900, 2100]); | ||
| 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' }), | ||
| }), | ||
| ); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import fs from 'node:fs'; | ||
| import { beforeEach, expect, test, vi } from 'vitest'; | ||
| import { bindTestCommandHost, createLiveTestHostEnvironment } from '@agent-device/test-kit'; | ||
|
|
||
| vi.mock('../core/runner-client.ts', () => ({ | ||
| runAppleRunnerCommand: vi.fn(async () => ({})), | ||
| })); | ||
|
|
||
| import type { DeviceInfo } from '@agent-device/kernel/device'; | ||
| import { buildGesturePlan } from '@agent-device/gestures/gesture-plan'; | ||
| import { runAppleRunnerCommand } from '../core/runner-client.ts'; | ||
| import { createLocalAppleToolProvider, withAppleToolProvider } from '../core/tool-provider.ts'; | ||
| import { createAppleInteractor } from '../interactor.ts'; | ||
| import { IOS_DEVICE, IOS_SIMULATOR } from '../__tests__/device-fixtures.ts'; | ||
| import { | ||
| IPHONE_17_SINGLE_PANEL, | ||
| IPHONE_DUO_CLOSED, | ||
| IPHONE_DUO_OPEN, | ||
| } from '../__tests__/display-fixtures.ts'; | ||
|
|
||
| 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(); | ||
| }); | ||
|
|
||
| /** A fresh simulator id per test: the daemon keeps each simulator's resolved panel count. */ | ||
| let simulatorCount = 0; | ||
| function simulator(): DeviceInfo { | ||
| simulatorCount += 1; | ||
| return { ...IOS_SIMULATOR, id: `${IOS_SIMULATOR.id}-split-${simulatorCount}` }; | ||
| } | ||
|
|
||
| async function performSplit(device: DeviceInfo, panels: object) { | ||
| const provider = createLocalAppleToolProvider({ | ||
| runCommand: async (_command, args) => { | ||
| if (args.slice(0, 4).join(' ') === 'devicectl device info displays') { | ||
| fs.writeFileSync(args.at(-1)!, JSON.stringify(panels)); | ||
| } | ||
| return { stdout: '', stderr: '', exitCode: 0 }; | ||
| }, | ||
| }); | ||
| await withAppleToolProvider(provider, () => | ||
| createAppleInteractor(device, {}, createLiveTestHostEnvironment()).performGesture!(splitPlan), | ||
| ); | ||
| } | ||
|
|
||
| test('an open foldable simulator sends the Split View drag as a screen-edge touch', async () => { | ||
| await performSplit(simulator(), IPHONE_DUO_OPEN); | ||
| expect(mockRunner).toHaveBeenCalledWith( | ||
| expect.anything(), | ||
| expect.objectContaining({ | ||
| command: 'gesture', | ||
| gesturePlan: expect.objectContaining({ contactOrigin: 'screen-edge' }), | ||
| }), | ||
| expect.anything(), | ||
| ); | ||
| }); | ||
|
|
||
| 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({ | ||
| code: 'UNSUPPORTED_OPERATION', | ||
| details: { reason: 'split_view_unavailable', dispatched: 'no' }, | ||
| }); | ||
| expect(mockRunner).not.toHaveBeenCalled(); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import type { GesturePlan } from '@agent-device/contracts/gesture-plan-types'; | ||
| 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. | ||
| */ | ||
| export async function appleSplitViewRunnerPlan( | ||
| device: DeviceInfo, | ||
| plan: GesturePlan, | ||
| signal: AbortSignal | undefined, | ||
| ): Promise<GesturePlan> { | ||
| if (plan.topology !== 'single' || plan.contactOrigin !== 'split-view-edge') return plan; | ||
| const table = | ||
| device.kind === 'simulator' | ||
| ? await readFoldablePanelTable(device, { | ||
| signal, | ||
| timeoutMs: IOS_APPLE_DISPLAY_PROBE_TIMEOUT_MS, | ||
| }) | ||
| : ({ kind: 'single-panel' } as const); | ||
| signal?.throwIfAborted(); | ||
| const lit = table.kind === 'multi-panel' ? table.inventory : undefined; | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
|
||
| if (!lit?.activeDisplay || lit.ambiguous || lit.activeDisplay.primary) { | ||
| throw splitViewUnavailableError( | ||
| table.kind === 'unreadable' | ||
| ? 'The panel table did not answer, so the lit panel is unknown and nothing was sent' | ||
| : 'Split View needs an iOS simulator with more than one panel and its inner panel lit', | ||
| { deviceId: device.id, panelTable: table.kind }, | ||
| ); | ||
| } | ||
|
thymikee marked this conversation as resolved.
Resolved
|
||
| return { ...plan, contactOrigin: 'screen-edge' }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.