feat(desktop)!: drive macOS through the native driver instead of agent-desktop (ENG-1533)

Merged
KD
2d ago
+8199-4008

What

@e2e-dev/desktop drives macOS apps through the native driver from #2322, loaded into the worker's process, instead of the agent-desktop CLI.

  • npm installs the driver with the engine, as @e2e-dev/desktop-darwin-arm64 or @e2e-dev/desktop-darwin-x64. Nothing is downloaded on the first run.
  • Breaking: the desktop({ binary }) option is gone. A config that still sets it fails to load with INVALID_CONFIG.
  • press and the keyboard capability (keyboard.type, keyboard.press) no longer need headed: true. Keys go into the app's own event queue while it stays in the background. A ControlOrMeta shortcut then reaches only the app's menu bar, so Copy, Paste, and Select All still need headed.
  • desktop.press(key) presses a key into the app's window, for an app with no control that takes keyboard focus (Calculator). getAttribute reads a node's label and identifier. getByRole('heading', { level }) finds a native heading by the level macOS 26 reports.
  • screen reads the focused window, else the app's main window, else the first visible one. The Siri dialog macOS 27 puts over an app after a press in a SwiftUI sheet is read only when desktop.useWindow() picks it. A window whose sheet has focus counts as focused, so keys reach a sheet.
  • An open context menu, a pop-up menu, and a popover are read as part of their window. A row scrolled out of its list reads as hidden.
  • On Windows and Linux, a run that includes a desktop target stops with UNSUPPORTED_CAPABILITY before any test starts, not INVALID_CONFIG. The config is valid; the engine does not support the OS.

Second of four PRs for ENG-1533 (#2322, #2323, #2324, #2325). The driver crate in #2322 is merged, so this PR is based on main. The other two merge after it.

Why

agent-desktop starts one process per action, so each step pays for a process start and a JSON round trip. Its key and typing input reached only the active window, so press and typing needed headed: true, which takes the user's keyboard and pointer. A fix there also had to wait for an upstream release. On the testbed's sign-in suite this branch runs in about an eighth of the time (## Verified).

How it works

  1. src/driver.ts (loadNativeDriver) loads native/desktop.<platform>-<arch>.node when a checkout built one, else the platform package for this machine: a platform package a canary build placed in a checkout must not hide the build just made there. It reads the driver's version from the platform package's package.json, or reports checkout build; reports and doctor show it as desktop-driver. A platform with no driver gets UNSUPPORTED_CAPABILITY. A missing package gets ENGINE_FAILURE naming the package to install.
  2. call (src/driver.ts) bounds each driver call by the operation's budget and signal. An input gets at least 500 ms once started, so a click that lands is not reported as cut off. A read gets 200 ms less than the call's cut-off (driverCall, src/surface.ts), so a read the driver stops at its deadline still answers, marked incomplete. If the budget or the signal cuts a call off, call drops the answer and runs onCutOff: for every act, press, pointer, and launch call that is cancelInput(id), so the driver sends nothing more and starts no app. The id comes from the driver's inputId, unique across the worker threads that share the addon. translate maps the driver's failure codes onto the engine error contract; the driver's disposition.delivery decides between "refused" and ACTION_MAY_HAVE_COMMITTED.
  3. src/surface.ts goes through the driver where it used to run agent-desktop commands. What a worker owns outside its process is in src/launch-ownership.ts: each worker's state directory (e2e-desktop-worker-) records its launches. The sweep that quits apps left by a killed worker also clears the old e2e-agent-desktop- directories, which hold field text. A launch the engine stopped waiting for keeps the driver's promise: the next quit kills the pid that launch reports later, and any process that carries its token. processesCarrying is awaited, since it reads every process. A quit that is cancelled, or whose scans fail, while it looks for an app the launch started late keeps the launch pending and its record (lateCarriers), so the next quit or sweep looks again. A quit cancelled or out of time before its kill sends none and keeps the app to quit again (killed).
  4. app.open() waits until a window of the app can be read: a read the driver marks root_unread (the app did not answer for the window itself) is read again, never taken as ready. Window choice: byPreference orders the focused window, the main one, the visible ones, then the rest, and leaves out a system window (the Siri dialog), which would otherwise be read in place of an app window it cannot read. A screen with only such a dialog reads again with a retryable NODE_STALE. A locked screen that lists the app's windows as unreadable says it is locked (unlessLocked).
  5. Input that has no ref to check against:
    • pointAtNode hovers and double-clicks a node with no ref (static text, a plain view) at the center of where a fresh read of its window finds it now (sameNode), and is a retryable NODE_STALE when that read no longer holds it, so the pointer never lands on what replaced or moved past it. A double-click is refused when another control is at the node's center (inside it, reaching past its box, laid over it, or an ancestor that takes a press of its own; not a hidden one), since it would press that control, and when the read stopped at the depth limit, since it may have left that control out. The driver is told the point takes no control, so it refuses one that coming forward reveals.
    • A replace in typeText selects the field's text through the driver's selectAll first. Cmd+A sent to an app in the background goes to its menu bar and selects nothing, so it is sent only with headed. Without headed, a field whose selection cannot be set is refused before anything is deleted.
    • performAt refuses a tap at a point when the sheet on its window changed since the point was taken: one opened, the one there closed, or another took its place. The observation records which sheet held the window's focus (pointIn, sheetKey), and a tap with no observation first takes its baseline as it starts. A tap on the same sheet goes. It brings the window forward under an input id, so a call given up on raises nothing later, and passes the driver the window and its sheet, so the driver checks them again after the move.
    • A key a locator presses is checked against the keyboard layout (checkCombo) before focus moves; with headed, the control's window comes forward before the control is focused, so a window useWindow() picked while another held the keyboard takes the key, so a digit shortcut on AZERTY is refused with nothing changed. It carries its control's ref (sendKey), and the driver sends it only while that control holds the app's focus.
    • A swipe on the window goes to the first node that scrolls along the swipe's axis (scrollTargets), so a carousel does not take a swipe down.
    • A tap on a node the read found hidden (shown) goes only when a scroll area holds it, or a row it is in, out of view (scrolledOut; the projection carries what hides an ancestor down as scrolled or other) and the driver offers ScrollTo: the driver scrolls it and answers once it shows, so a look-alike that moved is not looked for again by its place, and a failure after that scroll is ACTION_MAY_HAVE_COMMITTED, never retried. A node hidden by a minimized window, a hidden ancestor, or no size is refused at once. A secondary tap, check, and uncheck leave the rule to the driver, which reads the context menu or the box live first, so a box already right is left alone wherever it is.
    • locate answers a window read the deadline stopped (timed_out) as OPERATION_TIMEOUT, so a wait that matched nothing fails as "locator matched no nodes" and a failing toBeVisible as such, never as "node became stale"; core takes no cut read for an answer, so a negative assertion cannot pass on one.
  6. src/engine.ts adds press to the actions without headed, and offers the keyboard capability always. doubleTap, hover, and point taps stay headed-only, since they need the real pointer. desktop.press(key) (src/desktop.ts) sends a key through the same pressKey. nodes.ts adds the label and identifier attributes, and no longer guesses a window's title-bar buttons by their place (the driver leaves them out by subrole); a text node, or a name over 1,000 characters (MAX_LABEL_CHARS), gets no label, since observations do not cut attributes. A heading's level comes from the driver, else from its description (headingLevel). scrollIntoView (src/surface.ts) takes a node not read as hidden as in view unless the driver offers ScrollTo for it, so an element screenshot of a button that does not take the scroll action still captures. requireMacOS (src/options.ts) raises UNSUPPORTED_CAPABILITY in prepare and init, and doctor reports the same message.
  7. src/png.ts crops a screenshot whose capture carries an outline around the window (insideOutline), which screencapture adds on some windows, and widens the password mask by the outline's slack.
  8. packages/desktop-darwin-arm64 and packages/desktop-darwin-x64 are new packages that hold only the addon (main) and its NOTICE. Each sets os and cpu, and prepublishOnly (scripts/check-native.ts) refuses an addon not built for the version being published. They are optionalDependencies of the engine, in a changesets fixed group with it (.changeset/config.json). scripts/build-native.ts builds the addon (pnpm --filter @e2e-dev/desktop build:native [--target <triple>] [--out <dir>], macOS 13 deployment target) with the toolchain rust-toolchain.toml pins, as rustup run <channel> cargo with that toolchain's bin first on PATH, ahead of any other cargo (scripts/cargo.ts), so the release build is stripped. It installs that toolchain by name, ignoring a RUSTUP_TOOLCHAIN override, and adds the build's target to it, so an x64 build on an arm64 Mac finds its standard library, and removes the old file before writing the new one, since macOS kills a process that loads a binary overwritten in place. scripts/native-licenses.ts (pnpm --filter @e2e-dev/desktop licenses:native) writes each platform package's THIRD_PARTY_LICENSES.md, the notices of the crates the addon links, from Cargo.lock resolved for the two Mac targets, taking a crate's notice from native/licenses/ when the crate publishes none, and refusing a crate with neither or an empty text; it is packed, and prepublishOnly refuses a package without it. scripts/install-smoke.ts packs both and serves them through overrides. On a machine they do not match, the override drops them (-), as a registry install skips them by os and cpu.
  9. The unit tests drive DesktopSurface with a scripted driver (tests/helpers/fake-driver.ts) and run on any OS. The tests of the agent-desktop binary and CLI are gone with that code.
  10. Docs: docs/desktop.mdx (setup and the macOS 13 minimum, the environment the app gets and which apps get the launch token as arguments, the desktop fixture, the limits table: a tap, check, fill, or select on a disabled control waits for it and then fails, a hidden node is scrolled into view or refused, a table row's label is all its text and a label two rows show is refused, background Cmd shortcuts reach only the menu bar, a shortcut's letter follows the keyboard layout and a digit shortcut needs one that types it without Shift, when a physical click is refused and that a double-click is one gesture, a combo box that takes no typed value, the size and depth a read takes, the APIs refused), docs/reference/screen.mdx (a desktop node's attributes, and a description left out when it is the name), docs/reference/errors.mdx (AGENT_DESKTOP_INSTALL_FAILED removed; UNSUPPORTED_CAPABILITY names the OS case), the package README (a fill's text goes to the app under test through Accessibility, to no helper process), the root README, and AGENTS.md. The changeset is a minor for the three packages and opens with **Breaking:**.

Not in this stack, and listed as limits: video recording, app.clearState(), test.setup sessions, and app.back(). Each needs a scope decision first (a recording of the screen shows unmasked fields; clearing state deletes a defaults domain that an installed copy of the app may share; an app.back() key that an app ignores would report success).

Before the first release, a maintainer publishes both platform packages once by hand and adds a trusted publisher for each on npmjs, as for any new package.

Issue

Refs ENG-1533

Verified

Ran it locally: yes, the unit tests, the install smoke, and, with this Mac's screen unlocked, the desktop testbed with the driver of this stack: pnpm test 23 of 23 and pnpm test:headed 5 of 5. The headed press into a window another holds the keyboard from fails without its fix. A wait on a missing button, 8 runs each: tap({ timeout: 1500 }) fails as "locator matched no nodes" 8 of 8 and toBeVisible as "expect.toBeVisible failed" 8 of 8, where a reviewer measured "node became stale" in 6 of 8 before. michal-e2e ran it live at 63a08edf6 and fcb32fcd9 too. The release build is stripped again: run through rustup run, the arm64 addon is 1.09 MB with no local symbols, against 1.46 MB with the toolchain's bin only on PATH, where rust-objcopy aborts; with only rustup on PATH the build still finds rustc.

  • The desktop unit tests pass (248), with typecheck, lint, dead code, the error-code check, and docs:check. New since the last live run: the cut-off tests for press, pointer input, and the launch, a tap refused over a sheet that just opened, or that opened, closed, or was replaced after the observation, a ref-less double-click refused over a control at its center (a child, one reaching past its box, an overlay, a button it is in, but not a hidden one or a selectable row) and on a depth-cut read, a swipe that takes the node for its axis, a window swipe left or right that scrolls the node that scrolls sideways (it fails with the axis fixed to vertical), a keyless sheet refused, a shortcut the layout cannot type refused before focus, the window passed to the driver with a tap, a cancelled closeApp that kills nothing and quits on the next try, a native heading level, the stale ref-less double-click, the background replace refusal, the Siri, main-window, and locked-screen window picks, the read margin, desktop.press, the label and identifier attributes and the bound on label, a visible control with no scroll action taken as in view, a hidden control scrolled into view or refused (a look-alike that the scroll moved, a minimized window, a control with no size, a check left to the driver), a double-click at a moved node's new place, a cancelled quit that keeps the launch pending, and every driver function present in the built addon (the loader test, which CI runs on the built addon).
  • node scripts/install-smoke.ts 11 and 12 pass on an arm64 Mac, which gets the arm64 package as a tarball and drops the x64 one. With pnpm resolving for Linux (supportedArchitectures), pnpm 11's frozen reinstall failed with ENOTDIR on the skipped file: override, as it did in CI, and passes once the override drops the packages.
  • The desktop testbed on the built packages, with the suites from #2324: the locator suite (9 tests), the headed suite (3), and the agentic suite (1, live model, --no-cache) all pass. The agent's act made 6 tool calls (type, type_secret, check, select, tap, complete_step) with no failures, and the password is in no file under .e2e/. These runs predate review rounds 2 to 5 in #2322 and here; nothing has run live since. okwasniewski's runs on macOS 27 of 075ad9d9cb, with his prototype that this head takes in (the main window, the sheet focus rule, the scroll bar rule, desktop.press), passed his SwiftUI app 12/12 in both modes and Calculator 3/3.
  • pnpm bench:ab --suite desktop-testbed -- tests/sign-in.e2e.ts, main (agent-desktop) against the stack's head before the review fixes. The 4 sign-in tests behave the same on both and run about 8 times faster. The 5 controls tests from #2324 exist only on the head, so the harness leaves them out of the timings.

bench-ab: c801a12f (merge base with origin/main) vs f806eb0a

apps/desktop-testbed: e2e run --workers 1 tests/sign-in.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 5.0.

The suite's tests or config differ between base and head, so each side ran its own. A timing change can be the test change.

Behavior

These tests are left out of the timing rows below.

  • added tests/controls.e2e.ts › controls window › opens a context menu and chooses one of its items (macos)
  • added tests/controls.e2e.ts › controls window › presses keys into a field of an app in the background (macos)
  • added tests/controls.e2e.ts › controls window › scrolls a list until an item shows, and selects it (macos)
  • added tests/controls.e2e.ts › controls window › sets a slider and reads a disabled button (macos)
  • added tests/controls.e2e.ts › controls window › types text whose characters take two UTF-16 units each, whole (macos)
Timings

Every row but the process wall clock covers the 4 tests whose behavior matched.

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)30.34 s (30.17 s-30.48 s)3.92 s (3.89 s-3.96 s)-87.1% (-87.2% to -86.6%)faster
suite (sum of attempts)30.03 s (29.81 s-30.15 s)3.58 s (3.56 s-3.61 s)-88.1% (-88.2% to -87.6%)faster
action (events)7.68 s (7.59 s-7.69 s)790 ms (783 ms-843 ms)-89.7% (-90.0% to -88.1%)faster
step app.open11.69 s (11.62 s-11.71 s)1.04 s (1.02 s-1.05 s)-91.1% (-91.3% to -90.8%)faster
step locator.fill3.43 s (3.30 s-3.51 s)88 ms (85 ms-96 ms)-97.3% (-97.6% to -97.1%)faster
step expect.toHaveValue3.03 s (2.94 s-3.06 s)61 ms (58 ms-64 ms)-98.0% (-98.2% to -97.7%)faster
step app.screenshot1.67 s (1.66 s-1.69 s)133 ms (130 ms-140 ms)-92.1% (-92.4% to -91.6%)faster
step locator.tap1.64 s (1.61 s-1.68 s)139 ms (137 ms-207 ms)-91.6% (-91.9% to -85.9%)faster
step expect.not.toBeChecked1.30 s (1.20 s-1.33 s)1.01 s (1.01 s-1.01 s)-22.1% (-24.5% to -12.5%)faster
step expect.toHaveText1.19 s (1.16 s-1.21 s)30 ms (28 ms-31 ms)-97.5% (-98.1% to -96.7%)faster
step locator.selectOption1.12 s (1.09 s-1.15 s)427 ms (425 ms-430 ms)-61.8% (-63.1% to -58.9%)faster
step locator.check777 ms (757 ms-811 ms)114 ms (113 ms-115 ms)-85.6% (-86.2% to -84.1%)faster
step locator.clear676 ms (644 ms-710 ms)14 ms (9 ms-15 ms)-97.9% (-99.0% to -97.8%)faster
step expect.toBeVisible653 ms (644 ms-659 ms)10 ms (9 ms-13 ms)-98.5% (-98.9% to -97.7%)faster
step expect.toBeChecked602 ms (576 ms-642 ms)16 ms (14 ms-18 ms)-97.4% (-97.7% to -96.7%)faster
step desktop.windows197 ms (187 ms-203 ms)3 ms (2 ms-3 ms)-98.6% (-99.0% to -98.5%)faster
Counters
Counterbasehead
tests skipped05
Tests outside the threshold: 4 of 4
Testbase median (IQR)head median (IQR)change (95% CI)verdict
tests/sign-in.e2e.ts › sign-in form › reads controls by test id and refuses an empty password (macos)7.18 s (7.13 s-7.25 s)457 ms (441 ms-522 ms)-93.7% (-94.0% to -92.2%)faster
tests/sign-in.e2e.ts › sign-in form › signs in with every control set (macos)9.82 s (9.80 s-9.85 s)1.17 s (1.17 s-1.18 s)-88.1% (-88.2% to -87.2%)faster
tests/sign-in.e2e.ts › sign-in form › starts every test from a fresh launch (macos)5.84 s (5.74 s-5.85 s)1.39 s (1.38 s-1.39 s)-76.2% (-76.6% to -75.0%)faster
tests/sign-in.e2e.ts › sign-in form › takes a screenshot of the window with the password field painted over (macos)7.33 s (7.15 s-7.47 s)551 ms (544 ms-556 ms)-92.5% (-92.7% to -92.3%)faster

With 4 tests compared at 95%, about 0.2 could land outside by chance.

🤖 Generated with Claude Code