fix(electron): fail a test on its last step's dialog, and keep app.restart() within its time (ENG-892)

Merged
KD
19h ago
+378-98

What

  • A confirm or alert dialog that the test's last step opened, and that nothing answered, fails the test. Before, the test passed and the dialog was reported as a cleanup failure after the verdict, with no retry.
  • app.restart(), app.open() on a running app, and app.clearState() fail with unhandled confirm dialog: ... when the app being quit left a dialog unanswered. Before, the first step on the new app failed with it.
  • app.restart() and app.clearState() count the quit against the operation's time. A relaunch that opens no window says why it failed (1 window has loaded nothing yet) instead of CANCELLED. A call out of time when its turn comes starts no app and deletes no app data. An app.clearState() that runs out of time or is cancelled names itself in the error, not app.open.
  • electron.launch() (from #2406) follows the same rules as app.restart(): its quit counts against the operation's time, and it fails with the dialog the quitting app left unanswered.
  • prepare, init, and doctor find the Electron binary with ELECTRON_OVERRIDE_DIST_PATH from the run's environment, and the binary download runs in that environment, not in the worker process's own.

Why

The fifth PR of the stack for the review of #2237 (ENG-892), which added @e2e-dev/electron. These are defects in the app's lifecycle:

  • endAttempt threw the last dialog. Core records an endAttempt failure as cleanup after the verdict, so the test passed. The engine contract has settleAttempt for a failure that no step awaited.
  • A dialog nothing answered stayed latched through a restart and failed the next app's first step, which opened no dialog.
  • launch() started its budget from the full operation timeout after the quit. A quit of a few seconds moved the launch's end past the operation's, so the operation was cancelled before the launch could report why it failed. A restart whose quit used all the time still spawned the app, and a clearState() cancelled while it waited for its turn still emptied the app's data.
  • executable.ts read process.env, though prepare, init, and doctor receive the run's environment, which a host can give a worker separately from its own.

How it works

  1. ElectronSurface.settleAttempt (packages/electron/src/surface.ts:143) waits for open dialogs to settle, then throws the unhandled one through failOnDialog. The engine exposes it (packages/electron/src/engine.ts:52), and core awaits it before the verdict. endAttempt only resets the dialog router.
  2. restart and reset (surface.ts:155, surface.ts:169) call failOnDialog() first, then start one Budget for the operation before they queue behind other launches and quits; reset's is labelled app.clearState. In the queue, budget.check() runs before the quit and, in reset, before the app data is deleted.
  3. AppProcess.launch takes that budget (packages/electron/src/app-process.ts:149), checks it before it spawns anything, and gives the launch what remains.
  4. electronPackage, locateExecutable, resolveExecutable, describeExecutable, ensureElectronBinary, and download take the run's environment (RunEnv, packages/electron/src/executable.ts:29). download spawns install.js with it (executable.ts:212). Since #2408 on main they also take the platform; the environment comes before it. The surface passes info.env (surface.ts:95).
  5. Text: the env option's JSDoc (packages/electron/src/options.ts) says the app gets only the few variables a process needs to start and draw, plus env. docs/electron.mdx says a last-step dialog fails the test. The electron-typed-main-module changeset calls the electron peer required, as the manifest has it.

Issue

Part of ENG-892. Stack: #2419 → #2420 → #2421 → #2422 → this PR.

Verified

Ran it locally: yes

  • pnpm --filter @e2e-dev/electron test and test:integration on this head (f205a848d, with main merged in), and the electron testbed on 66e22065, before the actions fix below came up through the stack (CI's electron job runs the testbed on this head):
@e2e-dev/electron unit + integration: Tests  168 passed (168)
apps/electron-testbed:                Tests  75 passed (75)
  • The new tests of this PR on the code of the PR below it (the bug) and on this PR (the fix):
TestPR belowthis PR
settle.test.ts: fails the attempt from settleAttempt, once, as a step wouldfailedpassed
settle.test.ts: fails app.restart() and app.clearState() when the app being quit left it, not the next app's first stepfailedpassed
settle.test.ts: is reported through the engine's settleAttempt, which core awaits before the verdictfailedpassed
launch.test.ts: says why a launch failed when the operation spent part of its time before it, as a restart's quit doesfailedpassed
launch.test.ts: starts no app when the operation spent all its time before the launchfailedpassed
executable.test.ts: starts the binary ELECTRON_OVERRIDE_DIST_PATH names (from the run's environment)failedpassed
executable.test.ts: names the variable, and downloads nothing, when ELECTRON_OVERRIDE_DIST_PATH points where no binary isfailedpassed
  • The executable.test.ts check that the worker's own ELECTRON_OVERRIDE_DIST_PATH is unchanged compares it with its value before the test, so it also passes for a developer who has the variable set.

  • The surface's own budget wiring has unit tests in settle.test.ts, with a stubbed quit and launch: a cancelled call quits nothing and deletes no app data, a quit that takes the rest of clearState's time deletes no app data, and the launch after a restart's quit gets what the quit left. Handing the launch a new budget, or taking out the check before the data is deleted, fails them.

  • The last-step dialog is a unit test (packages/electron/tests/unit/settle.test.ts). A testbed test cannot show it: test.fail counts the closed app's APP_NOT_OPEN as infrastructure.

  • pnpm bench:ab --suite electron-testbed against main, all five PRs of the stack together. Measured at 66e22065, before 0d7cadc77 in #2419 replaced the page-side modal hit test with the accessibility-tree check alone. That change removes work from each poll of a non-pointer action. The table was not measured again:

bench-ab output

bench-ab: aaf92318 (merge base with origin/main) vs 66e22065

apps/electron-testbed: e2e run --workers 1. 6 pairs in random order, stopped at the 20-minute timeout, unresolved. Threshold ±5% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 5.6.

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.

  • changed tests/controls.e2e.ts › controls page › checks a checkbox its label draws, and finds text by text alone, as web() does (electron)

    - assertion expect.toHaveCount "getByText(\"Tracked\")" passed
    + assertion expect.toBeHidden "getByTestId(\"ghost-box\")" passed
    - assertion expect.toHaveCount "getByTestId(\"toast\") >> getByText(\"Saved draft\")" passed
    + assertion expect.toBeHidden "getByTestId(\"wrapped-ghost\")" passed
    + assertion expect.toHaveCount "getByText(\"Tracked\")" passed
    + assertion expect.toHaveCount "getByTestId(\"toast\") >> getByText(\"Saved draft\")" passed
    
  • added tests/controls.e2e.ts › controls page › finds text that inline markup splits, and text under aria-hidden or inert, as web() does (electron)

  • removed tests/controls.e2e.ts › controls page › finds text that inline markup splits, and text under aria-hidden, as web() does (electron)

  • changed tests/controls.e2e.ts › controls page › reads a heading tag's level over its aria-level, and a progress element's value (electron)

    + assertion expect.toHaveValue "getByRole(\"progressbar\", name: \"Overfull\")" passed
    + assertion expect.toHaveValue "getByRole(\"progressbar\", name: \"Waiting\")" failed ASSERTION_FAILED
    + assertion expect.not.toHaveValue "getByRole(\"progressbar\", name: \"Waiting\")" failed ASSERTION_FAILED
    
  • unstable on base (2 different step sequences) tests/controls.e2e.ts › controls page › releases a long press its timeout cuts short before the step fails (electron)

  • changed tests/controls.e2e.ts › controls page › saves a download in the attempt's own directory, never the user's (electron)

    + locator locator.tap "getByRole(\"link\", name: \"Download note\")" passed
    + locator locator.tap "getByRole(\"link\", name: \"Download shouting note\")" passed
    + app app.restart "" passed
    + resource electron.evaluate "" passed
    + locator locator.tap "getByRole(\"link\", name: \"Download note\")" passed
    
  • unstable on base (2 different step sequences) tests/controls.e2e.ts › controls page › taps a button a sticky header covers (electron)

  • unstable on base (2 different step sequences) tests/sign-in.e2e.ts › an app that quits on its own › relaunches with app.restart() and ends the test cleanly (electron)

  • unstable on head (2 different step sequences) tests/sign-in.e2e.ts › an app that quits on its own › relaunches with app.restart() and ends the test cleanly (electron)

Timings

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

Metricbase median (IQR)head median (IQR)change (95% CI)verdict
wall (process)125.48 s (65.48 s-181.13 s)62.87 s (60.91 s-65.17 s)-43.3% (-66.2% to +72.7%)unresolved
suite (sum of attempts)56.35 s (54.75 s-58.15 s)55.88 s (54.96 s-57.17 s)-0.5% (-9.4% to +3.2%)unresolved
action (events)15.90 s (15.88 s-15.95 s)15.90 s (15.88 s-15.92 s)+0.0% (-0.4% to +0.4%)same, under the floor
step app.open22.75 s (21.49 s-24.16 s)22.10 s (21.42 s-23.33 s)-2.1% (-18.0% to +6.1%)unresolved
step locator.selectOption4.72 s (4.71 s-4.73 s)4.72 s (4.65 s-4.72 s)+0.0% (-1.1% to +0.2%)same, under the floor
step locator.tap4.33 s (4.30 s-4.35 s)4.33 s (4.30 s-4.35 s)-0.2% (-0.9% to +0.9%)same, under the floor
step locator.fill3.37 s (3.36 s-3.38 s)3.37 s (3.36 s-3.38 s)+0.3% (-0.5% to +0.6%)same
step locator.dragTo1.43 s (1.43 s-1.43 s)1.43 s (1.43 s-1.43 s)+0.4% (+0.1% to +0.7%)same, under the floor
step locator.pressSequentially1.09 s (1.08 s-1.09 s)1.08 s (1.07 s-1.09 s)-0.2% (-1.7% to +0.9%)same, under the floor
step app.restart1.06 s (1.01 s-1.20 s)1.10 s (1.04 s-1.11 s)-4.1% (-21.1% to +9.8%)unresolved
step window.title1.00 s (1.00 s-1.00 s)1.00 s (1.00 s-1.00 s)0.0% (-0.1% to +0.0%)same
step electron.window956 ms (955 ms-957 ms)1.00 s (967 ms-1.00 s)+5.0% (-2.7% to +5.3%)unresolved
step electron.waitForWindow954 ms (949 ms-957 ms)957 ms (950 ms-961 ms)-0.2% (-1.1% to +4.3%)same, under the floor
step locator.scrollIntoView924 ms (923 ms-926 ms)927 ms (925 ms-929 ms)+0.3% (+0.1% to +0.4%)same, under the floor
step locator.waitFor901 ms (901 ms-901 ms)902 ms (901 ms-902 ms)+0.1% (-0.1% to +0.1%)same, under the floor
step locator.setInputFiles584 ms (581 ms-588 ms)589 ms (583 ms-593 ms)+0.7% (-1.6% to +1.7%)same, under the floor
step electron.waitForDownload517 ms (516 ms-518 ms)517 ms (516 ms-518 ms)+0.2% (-1.0% to +0.8%)same, under the floor
step expect.toBeVisible345 ms (334 ms-353 ms)343 ms (328 ms-366 ms)-1.1% (-5.3% to +6.8%)same, under the floor
step electron.evaluate342 ms (329 ms-347 ms)341 ms (327 ms-355 ms)+2.2% (-6.3% to +2.9%)same, under the floor
step app.clearState338 ms (332 ms-416 ms)335 ms (331 ms-344 ms)-1.2% (-25.1% to +17.7%)same, under the floor
step expect.toHaveText318 ms (303 ms-322 ms)320 ms (313 ms-328 ms)+1.8% (-6.3% to +7.0%)same, under the floor
step locator.check306 ms (303 ms-313 ms)307 ms (303 ms-308 ms)+0.7% (-2.7% to +3.8%)same, under the floor
step expect.toHaveValue198 ms (185 ms-206 ms)199 ms (190 ms-205 ms)+1.6% (-4.3% to +8.4%)same, under the floor
step app.screenshot120 ms (117 ms-122 ms)122 ms (115 ms-124 ms)+0.8% (-5.0% to +4.7%)same, under the floor
step app.stopRecording93 ms (82 ms-96 ms)81 ms (78 ms-81 ms)-13.0% (-18.9% to -1.9%)unresolved
step expect.toHaveCount72 ms (70 ms-74 ms)64 ms (61 ms-67 ms)-8.1% (-19.7% to -2.2%)same, under the floor
step locator.press59 ms (56 ms-63 ms)58 ms (56 ms-59 ms)-5.9% (-11.4% to +8.5%)same, under the floor
step locator.clear56 ms (52 ms-57 ms)59 ms (53 ms-62 ms)+10.8% (-10.4% to +23.4%)same, under the floor
step locator.swipe35 ms (33 ms-37 ms)36 ms (33 ms-36 ms)-1.2% (-27.5% to +35.8%)same, under the floor
step expect.toBeChecked25 ms (23 ms-27 ms)25 ms (25 ms-27 ms)+6.4% (-12.0% to +10.1%)same, under the floor
step app.startRecording25 ms (23 ms-27 ms)25 ms (23 ms-25 ms)+2.4% (-13.1% to +10.5%)same, under the floor
step locator.uncheck19 ms (17 ms-19 ms)19 ms (17 ms-20 ms)+8.7% (-7.2% to +22.1%)same, under the floor
step expect.toBeEditable19 ms (18 ms-21 ms)21 ms (19 ms-22 ms)+5.6% (-9.2% to +25.0%)same, under the floor
step expect.toBeDisabled16 ms (15 ms-17 ms)17 ms (16 ms-17 ms)+6.7% (0.0% to +9.2%)same, under the floor
step expect.toBeHidden15 ms (14 ms-18 ms)15 ms (15 ms-16 ms)+6.3% (-11.6% to +14.8%)same, under the floor
step locator.hover15 ms (13 ms-16 ms)17 ms (15 ms-18 ms)+6.7% (-3.0% to +57.9%)same, under the floor
step locator.dblclick14 ms (14 ms-15 ms)15 ms (13 ms-15 ms)-3.2% (-13.8% to +7.1%)same, under the floor
step app.back12 ms (11 ms-12 ms)14 ms (13 ms-14 ms)+16.7% (-18.1% to +115.3%)same, under the floor
step expect.toBeInViewport11 ms (11 ms-12 ms)12 ms (11 ms-14 ms)+10.1% (0.0% to +16.7%)same, under the floor
step expect.not.toBeEmpty11 ms (11 ms-12 ms)12 ms (11 ms-13 ms)-0.0% (-12.3% to +18.2%)same, under the floor
step expect.toBeEmpty11 ms (10 ms-13 ms)12 ms (12 ms-13 ms)+0.6% (-8.4% to +29.6%)same, under the floor
step expect.toHaveAttribute11 ms (10 ms-12 ms)10 ms (10 ms-12 ms)0.0% (-4.7% to +4.1%)same
step expect.not.toBeChecked11 ms (9 ms-12 ms)12 ms (11 ms-14 ms)+18.9% (-15.1% to +42.2%)same, under the floor
step locator.focus9 ms (8 ms-10 ms)10 ms (9 ms-11 ms)+11.8% (-17.8% to +35.4%)same, under the floor
step expect.not.toBeEditable9 ms (7 ms-9 ms)9 ms (8 ms-9 ms)+10.6% (-18.4% to +28.6%)same, under the floor
step expect.not.toBeInViewport9 ms (8 ms-11 ms)11 ms (10 ms-12 ms)+25.0% (-4.3% to +41.4%)same, under the floor
step expect.toContainText8 ms (7 ms-8 ms)8 ms (7 ms-8 ms)0.0% (-6.5% to +6.1%)same
step expect.not.toHaveAttribute8 ms (7 ms-9 ms)7 ms (7 ms-7 ms)0.0% (-26.2% to +6.1%)same
step expect.not.toBeHidden7 ms (6 ms-7 ms)6 ms (5 ms-6 ms)-15.5% (-25.5% to -7.4%)same, under the floor
step screen.tree5 ms (4 ms-5 ms)5 ms (4 ms-5 ms)0.0% (-10.6% to +36.9%)same
step expect.not.toHaveValue4 ms (3 ms-4 ms)5 ms (5 ms-6 ms)+36.9% (+9.5% to +66.7%)same, under the floor
step expect.not.toHaveRole4 ms (3 ms-5 ms)4 ms (4 ms-4 ms)+11.8% (-27.0% to +33.3%)same, under the floor
step expect.toBeSelected4 ms (4 ms-4 ms)4 ms (4 ms-4 ms)0.0% (-10.6% to +22.5%)same
step expect.not.toBeEnabled4 ms (3 ms-4 ms)4 ms (4 ms-4 ms)0.0% (-18.4% to +29.1%)same
step expect.toHaveScreenshot2 ms (2 ms-2 ms)1 ms (1 ms-2 ms)-29.3% (-50.0% to 0.0%)same, under the floor
step window.close1 ms (1 ms-2 ms)1 ms (1 ms-1 ms)0.0% (-50.0% to +73.2%)same

Counters

Counterbasehead
attempts75-7675-76
events engine112115
events navigation95-10292-112
events poll197206
steps481-482495-496
tests flaky0-10-1
tests passed74-7574-75
Tests outside the threshold: 0 of 68

With 68 tests compared at 95%, about 3.4 could land outside by chance.

Action time and the steps that now run the accessibility-tree check (locator.fill, locator.selectOption) are same. The suite and wall-clock rows are unresolved: half the base runs took about 180 s instead of 62 s, which matches macOS's reopen-windows prompt holding a launch (the base has no fix for it; the iteration branch does). The behavior changes are the new and changed testbed tests of this stack, and the Waiting rows show ASSERTION_FAILED because the test expects both assertions on an indeterminate progress bar to fail.

  • No changeset: @e2e-dev/electron is not released yet (0.0.0, not on npm). The electron-engine changeset on main covers its first release.
  • Not clean: the five PRs come from three rounds of review with four models, then a fresh review with gpt-6.2-sol. Later rounds over the whole engine found more defects; those go in a follow-up PR on top of this stack.
  • On macOS the electron testbed can time out at 120 s in many tests at once: after an app was killed, macOS asks whether to reopen its windows in a modal alert, and no window loads. The same happens on main. On this head the testbed passed 75 of 75 with -ApplePersistenceIgnoreState YES added to its launch arguments for that run only; the follow-up PR makes the engine pass it.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • e2e init now supports Electron, generating an Electron configuration and example test.
    • Setup guidance explains that Electron targets need an app path and aren’t included in generated CI jobs.
  • Bug Fixes

    • Electron launches honor the run’s configured environment when locating and preparing the executable.
    • Launch, restart, and reset operations respect the remaining time available; timed-out or cancelled operations won’t start the app or delete its data.
    • Unhandled dialogs are dismissed and reported as failures, including during restart and reset.
    • Screenshots are denied if the window leaves the app or loads a different document during capture. Paused animations remain paused when masks are applied and removed.
  • Documentation

    • Clarified which environment variables are passed to the app, how unhandled dialogs affect test results, and how the app directory is determined.