fix(electron): fail a test on its last step's dialog, and keep app.restart() within its time (ENG-892)
What
- A
confirmoralertdialog 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, andapp.clearState()fail withunhandled confirm dialog: ...when the app being quit left a dialog unanswered. Before, the first step on the new app failed with it.app.restart()andapp.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 ofCANCELLED. A call out of time when its turn comes starts no app and deletes no app data. Anapp.clearState()that runs out of time or is cancelled names itself in the error, notapp.open.electron.launch()(from #2406) follows the same rules asapp.restart(): its quit counts against the operation's time, and it fails with the dialog the quitting app left unanswered.prepare,init, anddoctorfind the Electron binary withELECTRON_OVERRIDE_DIST_PATHfrom 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:
endAttemptthrew the last dialog. Core records anendAttemptfailure as cleanup after the verdict, so the test passed. The engine contract hassettleAttemptfor 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 aclearState()cancelled while it waited for its turn still emptied the app's data.executable.tsreadprocess.env, thoughprepare,init, anddoctorreceive the run's environment, which a host can give a worker separately from its own.
How it works
ElectronSurface.settleAttempt(packages/electron/src/surface.ts:143) waits for open dialogs to settle, then throws the unhandled one throughfailOnDialog. The engine exposes it (packages/electron/src/engine.ts:52), and core awaits it before the verdict.endAttemptonly resets the dialog router.restartandreset(surface.ts:155,surface.ts:169) callfailOnDialog()first, then start oneBudgetfor the operation before they queue behind other launches and quits;reset's is labelledapp.clearState. In the queue,budget.check()runs before the quit and, inreset, before the app data is deleted.AppProcess.launchtakes that budget (packages/electron/src/app-process.ts:149), checks it before it spawns anything, and gives the launch what remains.electronPackage,locateExecutable,resolveExecutable,describeExecutable,ensureElectronBinary, anddownloadtake the run's environment (RunEnv,packages/electron/src/executable.ts:29).downloadspawnsinstall.jswith it (executable.ts:212). Since #2408 onmainthey also take the platform; the environment comes before it. The surface passesinfo.env(surface.ts:95).- Text: the
envoption's JSDoc (packages/electron/src/options.ts) says the app gets only the few variables a process needs to start and draw, plusenv.docs/electron.mdxsays a last-step dialog fails the test. Theelectron-typed-main-modulechangeset calls theelectronpeer 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 testandtest:integrationon this head (f205a848d, withmainmerged in), and the electron testbed on 66e22065, before the actions fix below came up through the stack (CI'selectronjob 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):
| Test | PR below | this PR |
|---|---|---|
settle.test.ts: fails the attempt from settleAttempt, once, as a step would | failed | passed |
settle.test.ts: fails app.restart() and app.clearState() when the app being quit left it, not the next app's first step | failed | passed |
settle.test.ts: is reported through the engine's settleAttempt, which core awaits before the verdict | failed | passed |
launch.test.ts: says why a launch failed when the operation spent part of its time before it, as a restart's quit does | failed | passed |
launch.test.ts: starts no app when the operation spent all its time before the launch | failed | passed |
executable.test.ts: starts the binary ELECTRON_OVERRIDE_DIST_PATH names (from the run's environment) | failed | passed |
executable.test.ts: names the variable, and downloads nothing, when ELECTRON_OVERRIDE_DIST_PATH points where no binary is | failed | passed |
-
The
executable.test.tscheck that the worker's ownELECTRON_OVERRIDE_DIST_PATHis 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 ofclearState'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.failcounts the closed app'sAPP_NOT_OPENas infrastructure. -
pnpm bench:ab --suite electron-testbedagainstmain, 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.
| Metric | base 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.open | 22.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.selectOption | 4.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.tap | 4.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.fill | 3.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.dragTo | 1.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.pressSequentially | 1.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.restart | 1.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.title | 1.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.window | 956 ms (955 ms-957 ms) | 1.00 s (967 ms-1.00 s) | +5.0% (-2.7% to +5.3%) | unresolved |
| step electron.waitForWindow | 954 ms (949 ms-957 ms) | 957 ms (950 ms-961 ms) | -0.2% (-1.1% to +4.3%) | same, under the floor |
| step locator.scrollIntoView | 924 ms (923 ms-926 ms) | 927 ms (925 ms-929 ms) | +0.3% (+0.1% to +0.4%) | same, under the floor |
| step locator.waitFor | 901 ms (901 ms-901 ms) | 902 ms (901 ms-902 ms) | +0.1% (-0.1% to +0.1%) | same, under the floor |
| step locator.setInputFiles | 584 ms (581 ms-588 ms) | 589 ms (583 ms-593 ms) | +0.7% (-1.6% to +1.7%) | same, under the floor |
| step electron.waitForDownload | 517 ms (516 ms-518 ms) | 517 ms (516 ms-518 ms) | +0.2% (-1.0% to +0.8%) | same, under the floor |
| step expect.toBeVisible | 345 ms (334 ms-353 ms) | 343 ms (328 ms-366 ms) | -1.1% (-5.3% to +6.8%) | same, under the floor |
| step electron.evaluate | 342 ms (329 ms-347 ms) | 341 ms (327 ms-355 ms) | +2.2% (-6.3% to +2.9%) | same, under the floor |
| step app.clearState | 338 ms (332 ms-416 ms) | 335 ms (331 ms-344 ms) | -1.2% (-25.1% to +17.7%) | same, under the floor |
| step expect.toHaveText | 318 ms (303 ms-322 ms) | 320 ms (313 ms-328 ms) | +1.8% (-6.3% to +7.0%) | same, under the floor |
| step locator.check | 306 ms (303 ms-313 ms) | 307 ms (303 ms-308 ms) | +0.7% (-2.7% to +3.8%) | same, under the floor |
| step expect.toHaveValue | 198 ms (185 ms-206 ms) | 199 ms (190 ms-205 ms) | +1.6% (-4.3% to +8.4%) | same, under the floor |
| step app.screenshot | 120 ms (117 ms-122 ms) | 122 ms (115 ms-124 ms) | +0.8% (-5.0% to +4.7%) | same, under the floor |
| step app.stopRecording | 93 ms (82 ms-96 ms) | 81 ms (78 ms-81 ms) | -13.0% (-18.9% to -1.9%) | unresolved |
| step expect.toHaveCount | 72 ms (70 ms-74 ms) | 64 ms (61 ms-67 ms) | -8.1% (-19.7% to -2.2%) | same, under the floor |
| step locator.press | 59 ms (56 ms-63 ms) | 58 ms (56 ms-59 ms) | -5.9% (-11.4% to +8.5%) | same, under the floor |
| step locator.clear | 56 ms (52 ms-57 ms) | 59 ms (53 ms-62 ms) | +10.8% (-10.4% to +23.4%) | same, under the floor |
| step locator.swipe | 35 ms (33 ms-37 ms) | 36 ms (33 ms-36 ms) | -1.2% (-27.5% to +35.8%) | same, under the floor |
| step expect.toBeChecked | 25 ms (23 ms-27 ms) | 25 ms (25 ms-27 ms) | +6.4% (-12.0% to +10.1%) | same, under the floor |
| step app.startRecording | 25 ms (23 ms-27 ms) | 25 ms (23 ms-25 ms) | +2.4% (-13.1% to +10.5%) | same, under the floor |
| step locator.uncheck | 19 ms (17 ms-19 ms) | 19 ms (17 ms-20 ms) | +8.7% (-7.2% to +22.1%) | same, under the floor |
| step expect.toBeEditable | 19 ms (18 ms-21 ms) | 21 ms (19 ms-22 ms) | +5.6% (-9.2% to +25.0%) | same, under the floor |
| step expect.toBeDisabled | 16 ms (15 ms-17 ms) | 17 ms (16 ms-17 ms) | +6.7% (0.0% to +9.2%) | same, under the floor |
| step expect.toBeHidden | 15 ms (14 ms-18 ms) | 15 ms (15 ms-16 ms) | +6.3% (-11.6% to +14.8%) | same, under the floor |
| step locator.hover | 15 ms (13 ms-16 ms) | 17 ms (15 ms-18 ms) | +6.7% (-3.0% to +57.9%) | same, under the floor |
| step locator.dblclick | 14 ms (14 ms-15 ms) | 15 ms (13 ms-15 ms) | -3.2% (-13.8% to +7.1%) | same, under the floor |
| step app.back | 12 ms (11 ms-12 ms) | 14 ms (13 ms-14 ms) | +16.7% (-18.1% to +115.3%) | same, under the floor |
| step expect.toBeInViewport | 11 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.toBeEmpty | 11 ms (11 ms-12 ms) | 12 ms (11 ms-13 ms) | -0.0% (-12.3% to +18.2%) | same, under the floor |
| step expect.toBeEmpty | 11 ms (10 ms-13 ms) | 12 ms (12 ms-13 ms) | +0.6% (-8.4% to +29.6%) | same, under the floor |
| step expect.toHaveAttribute | 11 ms (10 ms-12 ms) | 10 ms (10 ms-12 ms) | 0.0% (-4.7% to +4.1%) | same |
| step expect.not.toBeChecked | 11 ms (9 ms-12 ms) | 12 ms (11 ms-14 ms) | +18.9% (-15.1% to +42.2%) | same, under the floor |
| step locator.focus | 9 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.toBeEditable | 9 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.toBeInViewport | 9 ms (8 ms-11 ms) | 11 ms (10 ms-12 ms) | +25.0% (-4.3% to +41.4%) | same, under the floor |
| step expect.toContainText | 8 ms (7 ms-8 ms) | 8 ms (7 ms-8 ms) | 0.0% (-6.5% to +6.1%) | same |
| step expect.not.toHaveAttribute | 8 ms (7 ms-9 ms) | 7 ms (7 ms-7 ms) | 0.0% (-26.2% to +6.1%) | same |
| step expect.not.toBeHidden | 7 ms (6 ms-7 ms) | 6 ms (5 ms-6 ms) | -15.5% (-25.5% to -7.4%) | same, under the floor |
| step screen.tree | 5 ms (4 ms-5 ms) | 5 ms (4 ms-5 ms) | 0.0% (-10.6% to +36.9%) | same |
| step expect.not.toHaveValue | 4 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.toHaveRole | 4 ms (3 ms-5 ms) | 4 ms (4 ms-4 ms) | +11.8% (-27.0% to +33.3%) | same, under the floor |
| step expect.toBeSelected | 4 ms (4 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (-10.6% to +22.5%) | same |
| step expect.not.toBeEnabled | 4 ms (3 ms-4 ms) | 4 ms (4 ms-4 ms) | 0.0% (-18.4% to +29.1%) | same |
| step expect.toHaveScreenshot | 2 ms (2 ms-2 ms) | 1 ms (1 ms-2 ms) | -29.3% (-50.0% to 0.0%) | same, under the floor |
| step window.close | 1 ms (1 ms-2 ms) | 1 ms (1 ms-1 ms) | 0.0% (-50.0% to +73.2%) | same |
Counters
| Counter | base | head |
|---|---|---|
| attempts | 75-76 | 75-76 |
| events engine | 112 | 115 |
| events navigation | 95-102 | 92-112 |
| events poll | 197 | 206 |
| steps | 481-482 | 495-496 |
| tests flaky | 0-1 | 0-1 |
| tests passed | 74-75 | 74-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/electronis not released yet (0.0.0, not on npm). Theelectron-enginechangeset onmaincovers 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 YESadded 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 initnow 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.