feat(core): open a path in a freshly launched app with app.open(path, { relaunch: true }) (ENG-1490)

Draft
SA
1h ago
+599-48

What

app.open(path, { relaunch: true }) starts the app fresh at a path in one call on both web and device targets.

await app.open('/orders/42', { relaunch: true });
  • On a web target: closes open tabs, opens a new tab that keeps storage (as app.restart() does), and opens the URL there without loading the base URL first.
  • On a device target with app.linkBase: sets the target's app.permissions first (as on any fresh launch), stops the pinned app if it is running, and launches the app from the link. On Android and a physical iOS device, it passes the target's app.launchArguments with the launch.
  • Throws UNSUPPORTED_CAPABILITY when it cannot launch the app from the link: the engine does not declare linkRelaunch, the device comes from a device provider, the target has no pinned app, an iOS simulator receives an http(s) link or launch arguments, or the device is an older iPhone that xcrun devicectl list devices does not list. On that iPhone, the app stops before the refusal and stays closed.
  • Throws INVALID_ARGUMENT for an unknown option or a non-boolean relaunch value.

Why

Tests shared across web and device targets had no single call to start the app fresh at a path. On a device, app.open(path) opens the link in the running app and app.restart() starts the app without the link, so shared tests had to check for device and call device.closeApp() before opening the link. Web had no single call for this either.

How it works

flowchart LR
  A["app.open(path, { relaunch: true })"] --> B{target}
  B -- URL --> C[session.restart] --> D["session.open(url)"]
  B -- device + linkBase --> E{engine declares linkRelaunch?}
  E -- yes --> F["session.openLink(link, ctx, { relaunch: true })"]
  E -- no --> G[UNSUPPORTED_CAPABILITY]
  1. app.open rejects unknown option keys and non-boolean relaunch values with INVALID_ARGUMENT, then branches by target (packages/core/src/run/fixtures.ts:751).
  2. On a URL target, navigate resolves the URL first so a forbidden scheme fails with POLICY_DENIED before anything restarts. When relaunch is set, it calls session.restart and then session.open with the resolved URL, sharing one Deadline across both calls (packages/core/src/run/fixtures.ts:674).
  3. On a device target with app.linkBase, launchPinnedApp rejects engines that do not declare linkRelaunch (fixtures.ts:721), then calls session.openLink(link, context, { relaunch: true }) (fixtures.ts:728).
  4. The engine contract adds OpenLinkOptions as a third argument to openLink (packages/core/src/engine/index.ts:381, :412) and adds the linkRelaunch capability (index.ts:846). defineEngine (packages/core/src/engine/manifest.ts:311), the protocol manifest (packages/core/src/engine/protocol/manifest.ts:57), and the engine-manifest-1 schema (packages/e2e/schema/engine-manifest-v1.schema.json:124, :427) all reject linkRelaunch: true when session.openLink is absent, and both schema fixtures cover this rule. session/openLink now accepts an optional options param. When connectEngine({ session: { openLink } }) handles openLink locally, the client drops the server's linkRelaunch capability (packages/core/src/engine/protocol/client.ts:246).
  5. The mobile engine declares linkRelaunch (packages/mobile/src/engine.ts:43) and routes relaunch calls to surface.relaunchLink (engine.ts:76). Plain link opens without relaunch behave as before.
  6. Before sending any device command, relaunchLink (packages/mobile/src/surface.ts:1021) rejects devices from a provider, targets without a pinned app, and iOS simulator calls with an http(s) link or launch arguments. Revyl's driver starts the app first and then sends open_url, so the link reaches a running app. No other provider ran on a live device, so relaunchLink rejects every provider. On an iOS simulator, agent-device 0.21.44 launches the app first when given an http(s) link or launch arguments and then runs simctl openurl in the running app.
  7. After those checks pass, relaunchLink sets the target's permissions (surface.ts:1047) and calls agent-device apps.open({ app, url, relaunch: true, launchArgs }) once (surface.ts:1054). On Android, this runs as one am start with the link, package, and arguments. On a physical iOS device, the CoreDevice backend launches the app with the URL and arguments.
  8. agent-device's XCTest backend stops the app and then throws UNSUPPORTED_OPERATION with backend: 'xctest'. The engine cannot tell XCTest from CoreDevice before calling it because agent-device's client drops iosPhysicalDeviceBackend when mapping a device, and boot, devices.list, and devices.capabilities return no backend. Instead, relaunchLink rethrows the XCTest error as UNSUPPORTED_CAPABILITY with the next step and keeps the original error as cause (surface.ts:1068, packages/mobile/src/errors.ts:372).
  9. The mobile benchmark sets linkBase: 'e2e-benchmark://' on both targets (apps/mobile-benchmark/e2e.config.ts:62, :67). A device test launches the app from the link while it is running and again after device.closeApp() (apps/mobile-benchmark/tests/device-fixture.e2e.ts:135). The replay cache keys on app.identity, which both targets set, so the recordings do not change.

Putting relaunch on openLink behind a capability avoids a separate stop hook and rejects older engines instead of opening the link in the running app.

Issue

Part of ENG-1434.

Verified

Ran it locally: yes

The mobile benchmark Release build (built as in mobile.yml) ran on an iOS 27.2 simulator (iPhone 18 Pro). The test opens Control Inventory and launches the app from the /login-form link. Back then lands on the home list, showing a cold start. It then calls device.closeApp() and launches the app from the /login-form link again.

$ e2e run tests/device-fixture.e2e.ts --target ios-simulator --grep relaunch --video on
   ✓ |ios-simulator| tests/device-fixture.e2e.ts > device fixture > closeApp then openApp relaunches on the home list 10.69s
   ✓ |ios-simulator| tests/device-fixture.e2e.ts > device fixture > app.open with relaunch launches the app from the link whether running or stopped 17.40s
      Tests  2 passed (2)
  • The video shows the iOS simulator's "Open in "e2e Benchmark"?" prompt over the home screen after the app stops. The test accepts it with device.alert('accept').
  • CI's mobile job passed the test on both the Android emulator and the iOS simulator at 87e0ee6. Compared with that commit, this head changes only messages, comments, test titles, and code layout.
  • packages/e2e/tests/integration/web-platform.test.ts covers the web side in Chromium: after a relaunch, sessionStorage is empty, localStorage persists, and the page shows the path.
  • Unit tests cover the iOS simulator rejections, launch arguments on Android and a physical iOS device, setting permissions before the launch, and the XCTest rejection. Because no physical iOS device was available, the CoreDevice and XCTest paths ran only in unit tests.

pnpm bench:ab on the web benchmark (smoke, login-form, filter-deep-link, control-inventory), merge base against this branch:

Every test ran the same steps with the same outcome on every run of both builds, and every counter matched.

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)5.75 s (5.64 s-5.84 s)5.66 s (5.59 s-5.80 s)-1.3% (-2.5% to +0.8%)same
suite (sum of attempts)4.77 s (4.67 s-4.81 s)4.68 s (4.58 s-4.77 s)-1.3% (-3.5% to -0.5%)same
action (events)3.06 s (3.01 s-3.08 s)3.01 s (2.97 s-3.04 s)-0.5% (-3.6% to +0.1%)same
step locator.longPress1.52 s (1.51 s-1.52 s)1.51 s (1.51 s-1.52 s)-0.3% (-1.0% to +0.6%)same, under the floor
step app.open1.15 s (1.13 s-1.17 s)1.13 s (1.08 s-1.14 s)-2.0% (-3.6% to -0.6%)same
step locator.tap588 ms (573 ms-629 ms)591 ms (585 ms-596 ms)-0.0% (-11.8% to +5.2%)same, under the floor
step locator.check342 ms (325 ms-359 ms)343 ms (320 ms-356 ms)-2.9% (-9.3% to +6.9%)same, under the floor
step locator.fill260 ms (255 ms-261 ms)237 ms (230 ms-250 ms)-6.5% (-14.6% to +0.4%)unresolved
step expect.toHaveText120 ms (111 ms-124 ms)119 ms (113 ms-121 ms)-2.8% (-21.4% to +3.5%)same, under the floor
step locator.secondaryTap78 ms (67 ms-78 ms)79 ms (76 ms-79 ms)+0.6% (-2.7% to +17.4%)same, under the floor
step locator.doubleTap70 ms (60 ms-78 ms)70 ms (61 ms-79 ms)+1.1% (-3.7% to +8.7%)same, under the floor
step locator.scrollIntoView66 ms (65 ms-67 ms)67 ms (65 ms-69 ms)+1.5% (-2.4% to +3.7%)same, under the floor
step locator.setInputFiles65 ms (63 ms-68 ms)68 ms (64 ms-69 ms)+1.5% (-1.5% to +6.2%)same, under the floor
step locator.uncheck46 ms (45 ms-47 ms)46 ms (45 ms-47 ms)+1.1% (-3.2% to +2.2%)same, under the floor
step expect.toHaveURL41 ms (41 ms-42 ms)43 ms (43 ms-44 ms)+3.6% (0.0% to +8.5%)same, under the floor
step expect.toBeVisible33 ms (32 ms-35 ms)29 ms (27 ms-32 ms)-3.5% (-25.6% to -1.5%)same, under the floor
step expect.toHaveValue19 ms (18 ms-19 ms)18 ms (17 ms-18 ms)-5.3% (-7.8% to +5.4%)same, under the floor
step app.back17 ms (16 ms-18 ms)17 ms (17 ms-17 ms)0.0% (-7.8% to +6.5%)same
step expect.toBeChecked3 ms (3 ms-5 ms)3 ms (3 ms-5 ms)0.0% (-29.3% to +41.4%)same
step expect.toHaveTitle2 ms (2 ms-3 ms)2 ms (2 ms-2 ms)0.0% (-48.4% to +22.5%)same
Evidence
Video of the device testiOS recording from e2e run --video on, attached below
Docs screenshotsNot captured. The pages render on e2e.com from another repository. pnpm docs:check passes

Checklist

  • Changeset added (pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only.
  • Breaking change: title carries !, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md).
  • Docs updated in the same PR: the docs/**/*.mdx page for the behavior, and skills/e2e/ if the skill describes it.
  • Contract change: emitted .d.ts reviewed, tests/types/sdk-types.ts updated; wire change edits the schema and both fixtures.
  • Engine contract change (e2e/engine): changesets for e2e, @e2e-dev/web, and @e2e-dev/mobile.