fix(desktop): pass the launch token as one argument

Merged
OK
2d ago
+54-44

What

An app whose environment macOS hides gets its launch token as one argument, -E2EDesktopLaunch=<token>. It used to get two, -E2EDesktopLaunch <token>.

Why

Launching Google Chrome through @e2e-dev/desktop opened an extra tab titled with the token uuid: Chromium reads a bare argument as a URL, and other apps can read one as a file to open. Chrome is signed with restrict, so it is one of the apps that get the token in argv.

The second extra tab from the same report (yes, from -ApplePersistenceIgnoreState YES) is not fixed here. NSUserDefaults reads only the two-entry form, so that one needs a decision of its own.

How it works

  1. launch::token_argument spells the entry, -E2EDesktopLaunch=<token> (crates/e2e-desktop-napi/src/launch.rs:22). launch appends it when the bundle's signature hides its environment (launch.rs:172).
  2. process::holds_argument replaces argument_pair and matches one whole entry (crates/e2e-desktop-napi/src/process.rs:87). The claim after open and carrying (the sweep and the quit, behind processesCarrying) both compare against token_argument, so writer and readers share one spelling.
  3. processesCarrying takes the token alone. It took E2E_DESKTOP_LAUNCH=<token>, built at four TypeScript call sites, and the driver stripped the name back off to match the argument form. Now launch::token_marker and launch::token_argument spell both forms in the driver, and the TypeScript copy of the variable name is gone.
  4. The two-entry form is no longer read. Only 0.1.0-nightly-20261127110549 shipped it (npm latest is 0.0.1, before the native driver). An app that nightly left running is still swept by the pid and start time in its launch record. Only a worker killed mid-launch, before the record got a pid, would leave an app this version cannot find, and reading the old form for that one nightly was not worth a permanent second path.
  5. Docs and README name the new spelling. The pending desktop-native-driver changeset, which introduces the argument, is corrected in place, so the release notes never describe the two-entry form.

AppKit ignores the single entry: a probe app got no application(_:openFiles:) call for it and no argument-domain default, and a -key before it does not take it as its value.

Verified

Ran it locally: yes

  • Scratch project on the built CLI, background mode. Chrome launched with a fresh --user-data-dir, --no-first-run, and a debugging port. The test prints the app's argv (ps) and its tabs (/json/list).
  • Calculator (environment hidden): the launch is claimed, the test passes, and no copy is left running after the run.
  • Sweep lookup, on the built driver: a Calculator copy started by hand with the one-entry token, and a sleep with the token in its environment. processesCarrying(token) finds each, and nothing for an unknown token.
  • cargo fmt, cargo clippy -D warnings, cargo test (58 passed), pnpm check, desktop unit tests (248 passed), and the desktop testbed suite (25 passed) pass. The Calculator run, the lookup, and all of these were run again after the processesCarrying change (third commit); the Chrome runs are from the first commit.
mainthis PR
Chrome argv tail-E2EDesktopLaunch 8ff2bdfb-...-E2EDesktopLaunch=7924bb7c-...
Chrome tabshttp://8ff2bdfb-.../, http://yes/http://yes/
Calculatorclaimed, quitclaimed, quit
# main
ARGV /Applications/Google Chrome.app/Contents/MacOS/Google Chrome -ApplePersistenceIgnoreState YES --user-data-dir=/tmp/kdy1-f57-profile --no-first-run --no-default-browser-check --remote-debugging-port=9377 -E2EDesktopLaunch 8ff2bdfb-142f-4e99-8d4a-9632636bbbc3
TAB title="8ff2bdfb-142f-4e99-8d4a-9632636bbbc3" url=http://8ff2bdfb-142f-4e99-8d4a-9632636bbbc3/
TAB title="yes" url=http://yes/

# this PR
ARGV /Applications/Google Chrome.app/Contents/MacOS/Google Chrome -ApplePersistenceIgnoreState YES --user-data-dir=/tmp/kdy1-f57-profile --no-first-run --no-default-browser-check --remote-debugging-port=9377 -E2EDesktopLaunch=7924bb7c-97a1-4821-a4a5-b9b563bc3a5c
TAB title="yes" url=http://yes/
ARGV /System/Applications/Calculator.app/Contents/MacOS/Calculator -ApplePersistenceIgnoreState YES -E2EDesktopLaunch=338b41c7-1edf-4e57-80ac-1416b1af8abf
 ✓ |macos| tests/probe.e2e.ts > launch probe 4.59s

# processesCarrying, this PR
kdy1-arg-tok [ 96731 ]   Calculator -E2EDesktopLaunch=kdy1-arg-tok
kdy1-env-tok [ 97353 ]   E2E_DESKTOP_LAUNCH=kdy1-env-tok sleep 30
kdy1-absent  []

No video: the change is in argv, and the runs were in the background.