fix(mobile): never pin an install's file path as the app app.open() launches

Merged
OK
2mo ago
+99-17

A target with only app.appPath on Android: device.installApp() succeeds, then app.open() fails with Android runtime hints require an installed package name, not "/.../benchmark.apk". CI never saw it because the benchmark always sets bundleId.

Root cause (upstream, agent-device 0.21.18)

  • install --json returns app: <apk path> and no package when it cannot identify the APK (src/daemon/handlers/session-app-deployment.ts, buildNonIosDeployResult: app || packageName || launchTarget || appPath).
  • Its binary AndroidManifest.xml parser never matches aapt2 output: it requires a 36-byte start-element header and counts attributeStart from the chunk, but ResXMLTree_node's header is 16 bytes and attributeStart is relative to ResXMLTree_attrExt (packages/platform-android/src/manifest.ts, parseStartElementPackageName). Its tests only use text manifests.
  • The fallback is the SDK's aapt, searched under ANDROID_SDK_ROOT, ANDROID_HOME, ~/Android/Sdk, so not the macOS default ~/Library/Android/sdk.
  • The last fallback diffs pm list packages before and after install, which finds nothing when the package is already on the device.
  • Proof on this Mac: resolveAndroidArchivePackageName(apk) from agent-device/artifacts returns undefined, and with ANDROID_HOME set it returns dev.e2e.benchmark.
  • An upstream fix for the parser (a 10-line offset fix plus a test with a real aapt2-compiled manifest) is ready locally and not opened yet. With it, agent-device install --json reports "package": "dev.e2e.benchmark" with no SDK env. The bump comes in a follow-up PR once it is released.

This PR

  • installApp opens by the id agent-device reported, else the app passed in, and never by result.app (packages/mobile/src/surface.ts). With neither, it fails at the install with ENGINE_FAILURE naming app.bundleId or the app option, instead of pinning a file path that fails later in app.open().
  • app.open() on a device now keeps the engine's own UNSUPPORTED_CAPABILITY reason. Before, core rewrote every one into "pin one with the target's app.bundleId or app.appPath", even with appPath set (packages/e2e/src/run/fixtures.ts). Core's message now covers only an engine with no relaunch hook.
  • The mobile restart message now reads correctly under both app.open() and app.restart(): "launching the app needs...".
  • Docs: installApp return rules (reference, README) and a Troubleshooting entry for the Android case (ANDROID_HOME, daemon restart, or bundleId).
  • Decision: a non-engine build installed with no identity and no app also fails, because InstalledApp.app has no honest value to return. Before, it returned the path.

Verified

Ran it locally: yes

  • Pixel_7_API_36 emulator, scratch project with app: { appPath: '.build/android/benchmark.apk' } and a test that runs await device.installApp(); await app.open(); and then expects the home list. dev.e2e.benchmark was already installed and ANDROID_HOME was unset, the stress-test setup.
mainthis branch
Android, no ANDROID_HOMEinstallApp resolves {"app":"/.../benchmark.apk"}, then app.open(): ENGINE_FAILURE: open /.../benchmark.apk failed: Android runtime hints require an installed package nameinstallApp: ENGINE_FAILURE: installed /.../benchmark.apk, but agent-device reported no bundle id or package for it, so nothing can open it: name the app with the target's app.bundleId or installApp's app option
Android, ANDROID_HOME set (daemon restarted)not runinstallApp resolved to {"app":"dev.e2e.benchmark","bundleId":"dev.e2e.benchmark"}, app.open() launches, test passes
iOS, appPath only, no installApp()UNSUPPORTED_CAPABILITY: app.open() has no app to launch on target "ios": pin one with the target's app.bundleId or app.appPath, or bring one up with device.openAppUNSUPPORTED_CAPABILITY: launching the app needs the target's app.bundleId, or the build the target's app.appPath names installed first with device.installApp()
iOS, appPath only, installApp() then app.open()not runpasses, resolves dev.e2e.benchmark
  • Mobile benchmark locator suite on the Android emulator, branch build, E2E_MOBILE_BENCHMARK_ANDROID_APP set: 54 passed | 1 skipped.
  • No video: --video fails on this host with start video recording failed: 4 devices match this request equally, because iOS simulators were booted next to the emulator and the video start passes no device selection. That bug is on main too and out of scope here.

Devin Review