Skip to content

Commit 3a88e1f

Browse files
committed
test(apple): keep one source of truth for the confirmation shape
The review found three P3s on the same split: - The openurl-timeout test compared `hint` against itself, so nothing pinned the operator-facing text. Export `IOS_SIMULATOR_OPENURL_TIMEOUT_HINT` and assert it. - `CONFIRMATION` and `alertNotFound()` existed twice, one copy per test file, so prompt-text changes could diverge. Both now come from `launch-confirmation.fixtures.ts`, which `lifecycle.fixtures.ts` no longer duplicates. - The docs claimed every later command would have failed; `open` and `activate` can relaunch a stopped app, so the claim is limited to commands that require a running app.
1 parent fb8c473 commit 3a88e1f

7 files changed

Lines changed: 29 additions & 25 deletions

File tree

‎packages/platform-apple/src/core/__tests__/app-launch-url.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ vi.mock('../simulator.ts', async (importOriginal) => {
1515
import { AppError } from '@agent-device/kernel/errors';
1616
import { runCmd } from '@agent-device/host-kit/command';
1717
import { ensureBootedSimulator } from '../simulator.ts';
18-
import { IOS_SIMULATOR_OPENURL_TIMEOUT_REASON, openIosApp } from '../app-launch.ts';
18+
import {
19+
IOS_SIMULATOR_OPENURL_TIMEOUT_HINT,
20+
IOS_SIMULATOR_OPENURL_TIMEOUT_REASON,
21+
openIosApp,
22+
} from '../app-launch.ts';
1923

2024
const mockRunCmd = vi.mocked(runCmd);
2125
const mockEnsureBootedSimulator = vi.mocked(ensureBootedSimulator);
@@ -65,7 +69,7 @@ test('a Simulator that never answers openurl fails the open at its own bound', a
6569
timeoutMs: IOS_SIMULATOR_OPENURL_TIMEOUT_MS,
6670
reason: IOS_SIMULATOR_OPENURL_TIMEOUT_REASON,
6771
deviceId: IOS_TEST_SIMULATOR.id,
68-
hint: failure.details?.hint,
72+
hint: IOS_SIMULATOR_OPENURL_TIMEOUT_HINT,
6973
});
7074
});
7175

‎packages/platform-apple/src/core/app-launch.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ const IOS_SIMULATOR_LAUNCH_ARGS_WITH_URL_MESSAGE =
4343
/** Why an open failed because CoreSimulator never answered its `simctl openurl` within the bound. */
4444
export const IOS_SIMULATOR_OPENURL_TIMEOUT_REASON = 'ios-simulator-openurl-timeout';
4545

46+
/**
47+
* A killed child answers nothing, so the bound cannot report whether the hand-off landed; the hint is
48+
* the operator's only notice that a retry can duplicate the deep link.
49+
*/
50+
export const IOS_SIMULATOR_OPENURL_TIMEOUT_HINT =
51+
'The Simulator may still have received the URL; CoreSimulator is slow to answer. Retry the open, or answer any "Open in" prompt with alert accept.';
52+
4653
// fallow-ignore-next-line complexity
4754
export async function openIosApp(
4855
device: DeviceInfo,
@@ -178,7 +185,7 @@ async function openIosSimulatorUrl(
178185
reason: IOS_SIMULATOR_OPENURL_TIMEOUT_REASON,
179186
timeoutMs: IOS_SIMULATOR_OPENURL_TIMEOUT_MS,
180187
deviceId: device.id,
181-
hint: 'The Simulator may still have received the URL; CoreSimulator is slow to answer. Retry the open, or answer any "Open in" prompt with alert accept.',
188+
hint: IOS_SIMULATOR_OPENURL_TIMEOUT_HINT,
182189
},
183190
);
184191
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ALERT_NOT_FOUND_RUNNER_CODE } from '@agent-device/contracts/alert-contract';
2+
import { AppError } from '@agent-device/kernel/errors';
3+
4+
/** The prompt a session app's own launch URL raises. */
5+
export const CONFIRMATION = { message: 'Open in “Example App”?', items: ['Cancel', 'Open'] };
6+
7+
/** The runner's typed absence: `alert get` looked once and found no alert. */
8+
export function alertNotFound(): AppError {
9+
return new AppError('COMMAND_FAILED', 'alert not found', {
10+
runnerErrorCode: ALERT_NOT_FOUND_RUNNER_CODE,
11+
});
12+
}

‎packages/platform-apple/src/launch-confirmation.test.ts‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { expect, test, vi } from 'vitest';
2-
import { ALERT_NOT_FOUND_RUNNER_CODE } from '@agent-device/contracts/alert-contract';
32
import type { Interactor } from '@agent-device/contracts/interactor-types';
43
import type { DeviceInfo } from '@agent-device/kernel/device';
54
import { emitDiagnostic } from '@agent-device/host-kit/diagnostics';
@@ -16,6 +15,7 @@ import {
1615
type LaunchConfirmationPort,
1716
URL_OWNER_LOOKUP_TIMEOUT_MS,
1817
} from './launch-confirmation.ts';
18+
import { alertNotFound, CONFIRMATION } from './launch-confirmation.fixtures.ts';
1919

2020
vi.mock('@agent-device/host-kit/diagnostics', async (importOriginal) => {
2121
const actual = await importOriginal<typeof import('@agent-device/host-kit/diagnostics')>();
@@ -40,20 +40,11 @@ const simulator: DeviceInfo = {
4040
booted: true,
4141
};
4242

43-
/** The runner's typed absence: `alert get` looked once and found no alert. */
44-
function alertNotFound(): AppError {
45-
return new AppError('COMMAND_FAILED', 'alert not found', {
46-
runnerErrorCode: ALERT_NOT_FOUND_RUNNER_CODE,
47-
});
48-
}
49-
5043
/** How `exec.ts` rejects a spawn that outlives its timeout; `allowFailure` does not absorb it. */
5144
function spawnTimeout(): AppError {
5245
return new AppError('COMMAND_FAILED', 'xcrun timed out', { timeoutMs: 10_000 });
5346
}
5447

55-
const CONFIRMATION = { message: 'Open in “Example App”?', items: ['Cancel', 'Open'] };
56-
5748
function port(
5849
readAlert: () => Promise<Record<string, unknown> | undefined>,
5950
legs: Readonly<{

‎packages/platform-apple/src/lifecycle.fixtures.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { vi } from 'vitest';
2-
import { ALERT_NOT_FOUND_RUNNER_CODE } from '@agent-device/contracts/alert-contract';
32
import type { OpenApplicationInput } from '@agent-device/contracts/application-lifecycle-runtime';
43
import type { Interactor } from '@agent-device/contracts/interactor-types';
54
import type { PlatformRuntimeHost } from '@agent-device/contracts/platform-runtime-operations';
@@ -117,7 +116,6 @@ export const COMING_UP: LaunchObservation = {
117116
proof: 'launch-transition',
118117
};
119118
export const OBSERVABLE: LaunchObservation = { observation: 'observable' };
120-
export const CONFIRMATION = { message: 'Open in “Example App”?', items: ['Cancel', 'Open'] };
121119
export const SPAWN_TIMEOUT = new AppError('COMMAND_FAILED', 'xcrun timed out', {
122120
timeoutMs: 10_000,
123121
});
@@ -130,13 +128,6 @@ export function launchUrlInput(): OpenApplicationInput {
130128
};
131129
}
132130

133-
/** The runner's typed absence: `alert get` looked once and found no alert. */
134-
export function alertNotFound(): AppError {
135-
return new AppError('COMMAND_FAILED', 'alert not found', {
136-
runnerErrorCode: ALERT_NOT_FOUND_RUNNER_CODE,
137-
});
138-
}
139-
140131
/**
141132
* A Simulator whose host AX bridge reports `observations` in turn after each settle, and whose
142133
* runner answers the alert read with `readAlert`.

‎packages/platform-apple/src/lifecycle.test.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import { AppError } from '@agent-device/kernel/errors';
77
import { bindAppleApplicationLifecycle } from './lifecycle.ts';
88
import { platformRuntimeHostFixture } from './runtime.fixtures.ts';
99
import type { LaunchObservation } from './snapshot-observability.ts';
10+
import { alertNotFound, CONFIRMATION } from './launch-confirmation.fixtures.ts';
1011
import {
1112
COMING_UP,
12-
CONFIRMATION,
1313
LAUNCH_URL,
1414
OBSERVABLE,
1515
SPAWN_TIMEOUT,
1616
UNOBSERVABLE,
17-
alertNotFound,
1817
device,
1918
launchUrlInput,
2019
launchUrlSimulator,

‎website/docs/docs/commands.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ agent-device fold open
8282
- On an iOS Simulator, iOS can ask `Open in "<App>"?` before your app receives the URL from `open <app> --launch-url <url>`. If the URL's scheme belongs to your session app, `open` taps **Open** for you and its JSON data includes `launchConfirmation: "accepted"`. If no prompt appears, the response has no `launchConfirmation` field.
8383
- `open` recognizes the prompt by its English title. On a Simulator set to another language, it leaves the prompt on screen and returns as if no prompt appeared; answer it with `alert accept` or `alert dismiss`. Run with `--debug` to see the title `open` did not recognize.
8484
- `open` reads the prompt whenever it cannot see your app after the launch, including on a slow host where the app's target discovery fails on its own deadline. A prompt that appears after `open` has already seen your app stays on screen; answer it with `alert accept` or `alert dismiss`.
85-
- When `open` taps **Open** and your app still provably never starts, it hands the same URL to the Simulator once more and reads the prompt again. If the app is still not running after that, `open` fails with `details.reason: launch_confirmation_unanswered` instead of reporting success for a launch that never happened; every later command in that session would have failed with `app is not running`.
85+
- When `open` taps **Open** and your app still provably never starts, it hands the same URL to the Simulator once more and reads the prompt again. If the app is still not running after that, `open` fails with `details.reason: launch_confirmation_unanswered` instead of reporting success for a launch that never happened; later commands that require a running app would have failed with `app is not running`.
8686
- If the URL's scheme belongs to a different installed app, `open` does not answer the prompt. The command fails with `details.reason: launch_confirmation_foreign_app`; `details.foreignAppBundleId` names that app. The prompt stays on screen: close it with `alert dismiss`, then pass a launch URL whose scheme your app handles.
8787
- If `open` cannot identify a single installed app that owns the scheme, it does not know which app would receive the URL, so it leaves the prompt on screen and returns as if no prompt appeared; answer it with `alert accept` or `alert dismiss`. This happens when no installed app declares the scheme, when more than one does (for example a debug and a release build), and when the app list or an app's `Info.plist` could not be read.
8888
- `open <app> --launch-console <path>` captures launch-time stdout/stderr for direct iOS simulator app launches. It is not valid for URL opens or

0 commit comments

Comments
 (0)