fix(mobile): fail a missing installApp path and out-of-range setLocation coordinates as INVALID_ARGUMENT

Merged
KA
3d ago
+107-10

What

  • device.installApp(path) with nothing at the path now fails with INVALID_ARGUMENT (exit 1) before any device command. The message names the path the test passed and the absolute path it resolved to.
  • device.setLocation() with a latitude outside -90 to 90, a longitude outside -180 to 180, or a coordinate that isn't a finite number fails the same way, naming the bad value.

Why

  • Both are mistakes in the test, like a typo'd build path or a swapped coordinate. agent-device refuses them with INVALID_ARGS, translateError maps that to ENGINE_FAILURE, and the run exits 3 as if the simulator broke.
  • This is the mobile side of #2039 (setInputFiles on a missing path), and it works the same way as the existing setPermission and pressRemote guards.
  • I didn't map agent-device's INVALID_ARGS to INVALID_ARGUMENT in general. agent-device uses that code in many places, including for requests the engine builds itself, and those shouldn't be blamed on the test.

How it works

  1. packages/mobile/src/surface.ts:1055: installApp checks existsSync on the resolved path, but only for a path the test passed. With no argument it still installs the target's app.appPath without a check. A file (.apk, .ipa) and a directory (.app) both pass.
  2. packages/mobile/src/device.ts:267: requireCoordinates checks both coordinates before the Android "location services on" command, so a refused call changes nothing on the device.
  3. docs/reference/mobile.mdx: a Throws row for each method, and the setLocation JSDoc copy. The installApp table also said APP_NOT_OPEN for a missing build or a reinstall with no app, but invalidState throws INVALID_STATE there, which is what the unit test expects. I fixed that row since the new one sits under it.

Issue

Fixes #2291

Verified

Ran it locally: yes. iPhone 17 simulator, iOS 26.5, agent-device 0.21.42, Node 24.22.3. Target app: { bundleId: 'com.apple.Preferences' }.

testmain (1642ef238)this PR
device.installApp('./build/Missing.app')ENGINE_FAILURE: install /…/build/Missing.app failed: App binary not found: /…/build/Missing.appINVALID_ARGUMENT: device.installApp("./build/Missing.app"): no build at /…/build/Missing.app; the path resolves against the project root
device.setLocation({ latitude: 152.5, longitude: 21.01 })ENGINE_FAILURE: device.setLocation failed: latitude must be a number from -90 to 90INVALID_ARGUMENT: device.setLocation: latitude must be a finite number from -90 to 90, got 152.5
device.setLocation({ latitude: NaN, … })same ENGINE_FAILUREINVALID_ARGUMENT: … got NaN
e2e run exit code31
  • On the branch, setLocation({ latitude: 52.2297, longitude: 21.0122 }) followed by clearLocation() passed. installApp() of a real e2eBenchmark.app simulator build installed dev.e2e.benchmark.
  • Two new unit tests in packages/mobile/tests/unit/engine.test.ts fail on main (ENGINE_FAILURE) and pass here. They check that a refused call sends nothing to the device and that the range edges (-90, 180) still go through. The harness's project root /project isn't on disk, so the file mocks existsSync to treat paths under it as present. Two existing tests now pass /project/b/App.app instead of /b/App.app.
  • pnpm --filter @e2e-dev/mobile test (653 passed) and pnpm check pass.
  • Not run: Android on an emulator (none on this Mac). The Android setLocation path is covered by the unit test only.

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.