Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ extension RunnerTests {
code: RunnerPassThroughErrorCode.textEntryMismatch,
message: "text entry read-back did not match the requested text",
hint: textEntryMode == .replacement
? "The app may have formatted, filtered, or consumed the entry. Inspect the field or resulting screen before retrying. If it needs correction, retry fill with the full text and --delay-ms \(TextEntryTiming.recoveryDelayMilliseconds)."
? Self.replacementMismatchHint(observedText: textResult.observedText)
: nil
)
)
Expand Down Expand Up @@ -203,6 +203,16 @@ extension RunnerTests {
return Response(ok: true, data: data)
}

/// A field that reads back empty after the text was typed never received it. The usual cause is
/// an overlay, such as a sheet or a development menu, that took the focus tap and the typing.
static func replacementMismatchHint(observedText: String?) -> String {
let retry = "If it needs correction, retry fill with the full text and --delay-ms \(TextEntryTiming.recoveryDelayMilliseconds)."
if observedText?.isEmpty == true {
return "The field read back empty, so the tap may have landed on an overlay above it, such as a sheet or a development menu. Run snapshot -i and close the overlay before retrying. \(retry)"
}
return "The app may have formatted, filtered, or consumed the entry. Inspect the field or resulting screen before retrying. \(retry)"
}

/// The refusal of a coordinate `fill` whose point identified no text input, answered before the
/// focus tap is dispatched so nothing runs. Without an input at the point the synthesized
/// replacement has no element to bind to, so its clear and its typed text would reach the app-level
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ extension RunnerTests {
}
}

func testReplacementMismatchHintNamesAnOverlayOnlyForAnEmptyReadBack() {
XCTAssertTrue(Self.replacementMismatchHint(observedText: "").contains("overlay"))
XCTAssertFalse(Self.replacementMismatchHint(observedText: "ada").contains("overlay"))
XCTAssertFalse(Self.replacementMismatchHint(observedText: nil).contains("overlay"))
XCTAssertTrue(Self.replacementMismatchHint(observedText: "").contains("--delay-ms"))
}

func testReplacementDisclosesNonLiteralValuesWithoutInferringCorrectness() {
let cases: [(String, String, String)] = [
("", "000629177", "00 062 91 77"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { describe, expect, test } from 'vitest';
import type { SnapshotNode } from '@agent-device/kernel/snapshot';
import { formatReactNativeOverlayWarning } from './react-native-overlay.ts';

function nodes(specs: Array<Partial<SnapshotNode>>): SnapshotNode[] {
return specs.map((spec, index) => ({ index, ...spec }) as SnapshotNode);
}

/** iPhone 17 Pro simulator, `snapshot -i`: the test app's form under the Expo dev menu, trimmed. */
const IOS_MENU = nodes([
{ type: 'Application', label: 'Agent Device Tester' },
{ type: 'TextField', label: 'Email' },
{ type: 'StaticText', label: 'Agent Device Tester' },
{ type: 'Button', label: 'Close' },
{ type: 'StaticText', label: 'Runtime version: exposdk:58.0.0' },
{ type: 'Button', label: 'Reload' },
{ type: 'Button', label: 'Go home' },
]);

/** Pixel 9 emulator, full `snapshot` of an Expo dev-client app under the dev menu, trimmed. */
const ANDROID_MENU = nodes([
{ type: 'android.widget.TextView', label: 'Lab (Dev)' },
{ type: 'android.widget.TextView', label: 'Runtime version: 3.5.0' },
{ type: 'android.view.View', label: 'Close' },
{ type: 'android.view.View', label: 'Reload' },
{ type: 'android.widget.TextView', label: 'Reload' },
{ type: 'android.view.View', label: 'Home' },
{ type: 'android.widget.TextView', label: 'Go home' },
]);

/** The same Android menu in `snapshot -i`, which drops the header text. */
const ANDROID_INTERACTIVE_MENU = ANDROID_MENU.filter(
(node) => !node.label?.startsWith('Runtime version') && node.label !== 'Lab (Dev)',
);

const DEV_MENU_HINT = /Expo dev menu looks open[\s\S]*Close[\s\S]*disableAutoLaunch=1/;

describe('the Expo dev menu hint', () => {
test.each([
['the iOS simulator capture', IOS_MENU],
['the Android full capture', ANDROID_MENU],
[
'an SDK version line beside Go home only',
nodes([{ label: 'SDK version: 58.0.0' }, { label: 'Go home' }]),
],
[
'the version line carried as a value',
nodes([{ value: 'Runtime version: 1.0.0' }, { label: 'Reload' }]),
],
])('names the menu and its Close for %s', (_name, captured) => {
expect(formatReactNativeOverlayWarning(captured)).toMatch(DEV_MENU_HINT);
});

test.each([
["Android's interactive capture, which drops the version line", ANDROID_INTERACTIVE_MENU],
[
'a version line with no Reload or Go home',
nodes([{ label: 'Runtime version: 1.0.0' }, { label: 'Close' }]),
],
['an app Reload with no version line', nodes([{ label: 'Reload' }, { label: 'Close' }])],
[
'a version line that only mentions the words',
nodes([{ label: 'See the runtime version: below' }, { label: 'Reload' }]),
],
['a version line with no value', nodes([{ label: 'Runtime version:' }, { label: 'Reload' }])],
])('stays quiet for %s', (_name, captured) => {
expect(formatReactNativeOverlayWarning(captured)).toBeUndefined();
});
});
25 changes: 25 additions & 0 deletions packages/capture-kit/src/react-native-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,19 @@ const FOOTER_LANDSCAPE_SIDE_INSET_MAX_DP = 80;
*/
const FOOTER_MIN_COLUMNS_WITHOUT_SURFACE = 3;

const EXPO_DEV_MENU_VERSION_PATTERN = /^(?:runtime|sdk) version: \S/;
const EXPO_DEV_MENU_ACTION_LABELS = new Set(['reload', 'go home']);

export function formatReactNativeOverlayWarning(
nodes: SnapshotNode[],
surface?: ReactNativeOverlaySurface,
): string | undefined {
if (showsExpoDevMenuText(nodes)) {
return [
'Hint: The Expo dev menu looks open. It takes every tap until it closes, so press its Close button first.',
"When you launch the app with your own expo-development-client URL, add disableAutoLaunch=1 to it, or turn off the menu's show-at-launch setting.",
].join('\n');
}
const overlay = analyzeReactNativeOverlay(nodes, surface);
if (!overlay.detected) return undefined;
return [
Expand Down Expand Up @@ -270,6 +279,22 @@ function isSafeCollapsedWarningCoordinateFallback(
}

/** Reads every text a node carries, lowercased, against a label classifier. */
/**
* The Expo dev menu's header line and one of its first actions, read as text only: the menu's
* layout differs by platform, capture and Expo release. Android's interactive capture drops the
* header line, so only its full snapshot carries both.
*/
function showsExpoDevMenuText(nodes: readonly SnapshotNode[]): boolean {
return (
nodes.some((node) =>
nodeHasMatchingLabel(node, (label) => EXPO_DEV_MENU_VERSION_PATTERN.test(label)),
) &&
nodes.some((node) =>
nodeHasMatchingLabel(node, (label) => EXPO_DEV_MENU_ACTION_LABELS.has(label)),
)
);
}

function nodeHasMatchingLabel(
node: ReactNativeOverlayNode,
matches: (label: string) => boolean,
Expand Down
2 changes: 1 addition & 1 deletion packages/command-surface/src/management/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const openCommandFacet = defineCommandFacet({
summary: 'Open an app, deep link or URL, save replays',
searchHint: 'relaunch',
cliDetail:
'Use --platform to bind URL/deep-link opens to the target platform. For local or Limrun iOS simulator initial stdout/stderr, put --launch-console <path> on this open command, for example agent-device open "Agent Device Tester" --platform ios --launch-console artifacts/launch-console.log. Expo Go/dev-client shells accept host + URL, for example agent-device open "Expo Go" exp://127.0.0.1:8081 --platform ios. macOS also supports --surface app|frontmost-app|desktop|menubar. --metro-host/--metro-port/--bundle-url choose the app\'s Metro server and save that address for later metro reload calls in the same session. A fresh open without Metro hints clears an older same-name binding; close also clears it. --launch-url supplies the app\'s launch URL; it does not select the reload server. A later open without these flags applies the hints and launch URL again only when it opens the same app; it opens another app without them. An open that passes hints for another app also removes the earlier hints from the app an earlier open applied them to. On an iOS simulator without --launch-url, open connects a detected Expo development client through its expo-development-client URL. The app must declare a single exp+<slug> scheme that no other installed app owns. If detection is inconclusive, the app opens normally. Bare React Native apps receive their server settings before launch. On an iOS simulator, when --launch-url raises an "Open in <App>?" prompt that keeps open from seeing the app, open accepts it if the URL scheme belongs to the session app (data.launchConfirmation: "accepted"); if the scheme belongs to another installed app, the prompt stays on screen and open fails with details.reason launch_confirmation_foreign_app; if the scheme owner cannot be resolved because no single installed app owns it or the lookup failed, the prompt stays on screen and open returns with data.launchConfirmation: "unanswered", launchConfirmationReason url-owner-unresolved, and a warning; a prompt that is seen but not recognized is reported the same way with launchConfirmationReason alert-unrecognized and its own warning; for url-owner-unresolved, answer the prompt with alert accept; for alert-unrecognized, read the alert with alert get first, because it can be the app\'s own alert (such as a permission prompt) rather than the launch confirmation, and answer with alert accept only when it is the launch confirmation; when agent-device cannot read whether a prompt is up at all (the alert read, the accept, or the runner itself failed, including after a re-hand of the URL), open stays green, reports no launchConfirmation plus data.launchConfirmationProbeFailure naming the failed step (alert-read, alert-accept, or runner), and appends a warning that says to check with alert get. The prompt is read whenever open cannot see the app afterwards, including on a slow host where the app\'s target discovery fails on its own deadline. When an accept leaves the app provably not running, open hands the same URL over once more and reads again; still not running, it fails with details.reason launch_confirmation_unanswered. When the runner reports its main-thread timeout for the accept and the prompt is still up, open presses Open again, but only when the time the open request has left covers a whole press and the read that checks it. A recognized prompt still visible after a failed accept, or once that time is gone, also fails with this reason, even if the app is running behind it; answer it with alert accept or alert dismiss. A simulator openurl that CoreSimulator never answers fails within 20s with details.reason ios-simulator-openurl-timeout. The prompt is recognized by the OS\'s own wording of its title and buttons in the Simulator\'s preferred languages; when the runner cannot read that wording, the prompt stays on screen as alert-unrecognized. A prompt that appears after open has already seen the app is not answered; use alert accept. A device another session is holding refuses at once; add --wait <ms> to block up to that budget for it and only then fail with DEVICE_IN_USE naming the owning session. On HarmonyOS, open reads the foreground app for up to 5s after dispatch. When the launched app never holds it, open succeeds with a warning that names open-not-foreground with the app that held the foreground, or that no mission is foreground; unlock and run the open again. A budget whose every read fails names open-foreground-probe-unreadable instead and claims nothing; check the connection. With --foreground, it fails with details.reason open-not-foreground or open-foreground-probe-unreadable.',
'Use --platform to bind URL/deep-link opens to the target platform. For local or Limrun iOS simulator initial stdout/stderr, put --launch-console <path> on this open command, for example agent-device open "Agent Device Tester" --platform ios --launch-console artifacts/launch-console.log. Expo Go/dev-client shells accept host + URL, for example agent-device open "Expo Go" exp://127.0.0.1:8081 --platform ios. macOS also supports --surface app|frontmost-app|desktop|menubar. --metro-host/--metro-port/--bundle-url choose the app\'s Metro server and save that address for later metro reload calls in the same session. A fresh open without Metro hints clears an older same-name binding; close also clears it. --launch-url supplies the app\'s launch URL; it does not select the reload server. A later open without these flags applies the hints and launch URL again only when it opens the same app; it opens another app without them. An open that passes hints for another app also removes the earlier hints from the app an earlier open applied them to. On an iOS simulator without --launch-url, open connects a detected Expo development client through its expo-development-client URL, with disableAutoLaunch=1 so the dev menu stays closed at launch; Expo also saves that as the app\'s show-at-launch setting. The app must declare a single exp+<slug> scheme that no other installed app owns. If detection is inconclusive, the app opens normally. Bare React Native apps receive their server settings before launch. On an iOS simulator, when --launch-url raises an "Open in <App>?" prompt that keeps open from seeing the app, open accepts it if the URL scheme belongs to the session app (data.launchConfirmation: "accepted"); if the scheme belongs to another installed app, the prompt stays on screen and open fails with details.reason launch_confirmation_foreign_app; if the scheme owner cannot be resolved because no single installed app owns it or the lookup failed, the prompt stays on screen and open returns with data.launchConfirmation: "unanswered", launchConfirmationReason url-owner-unresolved, and a warning; a prompt that is seen but not recognized is reported the same way with launchConfirmationReason alert-unrecognized and its own warning; for url-owner-unresolved, answer the prompt with alert accept; for alert-unrecognized, read the alert with alert get first, because it can be the app\'s own alert (such as a permission prompt) rather than the launch confirmation, and answer with alert accept only when it is the launch confirmation; when agent-device cannot read whether a prompt is up at all (the alert read, the accept, or the runner itself failed, including after a re-hand of the URL), open stays green, reports no launchConfirmation plus data.launchConfirmationProbeFailure naming the failed step (alert-read, alert-accept, or runner), and appends a warning that says to check with alert get. The prompt is read whenever open cannot see the app afterwards, including on a slow host where the app\'s target discovery fails on its own deadline. When an accept leaves the app provably not running, open hands the same URL over once more and reads again; still not running, it fails with details.reason launch_confirmation_unanswered. When the runner reports its main-thread timeout for the accept and the prompt is still up, open presses Open again, but only when the time the open request has left covers a whole press and the read that checks it. A recognized prompt still visible after a failed accept, or once that time is gone, also fails with this reason, even if the app is running behind it; answer it with alert accept or alert dismiss. A simulator openurl that CoreSimulator never answers fails within 20s with details.reason ios-simulator-openurl-timeout. The prompt is recognized by the OS\'s own wording of its title and buttons in the Simulator\'s preferred languages; when the runner cannot read that wording, the prompt stays on screen as alert-unrecognized. A prompt that appears after open has already seen the app is not answered; use alert accept. A device another session is holding refuses at once; add --wait <ms> to block up to that budget for it and only then fail with DEVICE_IN_USE naming the owning session. On HarmonyOS, open reads the foreground app for up to 5s after dispatch. When the launched app never holds it, open succeeds with a warning that names open-not-foreground with the app that held the foreground, or that no mission is foreground; unlock and run the open again. A budget whose every read fails names open-foreground-probe-unreadable instead and claims nothing; check the connection. With --foreground, it fails with details.reason open-not-foreground or open-foreground-probe-unreadable.',
mcpDetail:
"metroHost, metroPort, and bundleUrl choose the app's Metro server and save its address for later reloads. launchUrl selects the app's launch URL and does not select the reload server. A later open without hints applies them again only when it opens the same app; it opens another app without them. An open that passes hints for another app also removes the earlier hints from the app an earlier open applied them to. A fresh open without Metro hints clears an older same-name binding; close also clears it.",
},
Expand Down
17 changes: 13 additions & 4 deletions packages/platform-apple/src/expo-dev-client-launch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ test.each([
[
'an http server',
undefined,
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F127.0.0.1%3A8085',
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F127.0.0.1%3A8085&disableAutoLaunch=1',
],
[
'an https server',
'https://metro.example.test',
'exp+dev-slug://expo-development-client/?url=https%3A%2F%2Fmetro.example.test',
'exp+dev-slug://expo-development-client/?url=https%3A%2F%2Fmetro.example.test&disableAutoLaunch=1',
],
])('points an expo-dev-client at %s', async (_name, bundleUrl, expected) => {
resolveScheme.mockResolvedValue('exp+dev-slug');
Expand All @@ -59,7 +59,7 @@ test('points at the server origin of a bundle URL, not at the bundle itself', as
});

await expect(resolveExpoDevClientLaunchUrl(SIMULATOR, input)).resolves.toBe(
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F10.0.0.5%3A8090',
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F10.0.0.5%3A8090&disableAutoLaunch=1',
);
});

Expand All @@ -70,7 +70,7 @@ test('keeps a single pair of brackets around an IPv6 bundle URL host', async ()
});

await expect(resolveExpoDevClientLaunchUrl(SIMULATOR, input)).resolves.toBe(
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F%5B%3A%3A1%5D%3A8090',
'exp+dev-slug://expo-development-client/?url=http%3A%2F%2F%5B%3A%3A1%5D%3A8090&disableAutoLaunch=1',
);
});

Expand All @@ -87,6 +87,15 @@ test('keeps the server mount when opening a path-prefixed Expo bundle', async ()
expect(new URL(launchUrl!).searchParams.get('url')).toBe('https://metro.example.test/tenant-42');
});

test('asks the dev client to keep its menu closed, beside the server URL rather than inside it', async () => {
resolveScheme.mockResolvedValue('exp+dev-slug');

const launchUrl = new URL((await resolveExpoDevClientLaunchUrl(SIMULATOR, openInput()))!);

expect(launchUrl.searchParams.get('disableAutoLaunch')).toBe('1');
expect(launchUrl.searchParams.get('url')).toBe('http://127.0.0.1:8085');
});

test.each([
['a bare React Native app', openInput(), undefined],
[
Expand Down
9 changes: 6 additions & 3 deletions packages/platform-apple/src/expo-dev-client-launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export async function resolveExpoDevClientLaunchUrl(
if (isRequestCanceledError(error)) throw error;
return undefined;
}
return scheme
? `${scheme}://expo-development-client/?url=${encodeURIComponent(serverUrl.toString().replace(/\/+$/, ''))}`
: undefined;
if (!scheme) return undefined;
const url = encodeURIComponent(serverUrl.toString().replace(/\/+$/, ''));
// `disableAutoLaunch=1` keeps the dev menu from opening over the app at launch. Expo documents it
// next to `url` for every SDK, and it also turns off the app's saved show-at-launch setting:
// https://docs.expo.dev/develop/development-builds/development-workflows/
return `${scheme}://expo-development-client/?url=${url}&disableAutoLaunch=1`;
}
Loading
Loading