fix(web,kernel): Kernel downloads, crashed-worker leaks, icon-font names, and clearer attempt-scope limits

Merged
OK
2mo ago
+1159-119

Six web engine and Kernel bugs from the Oct 1 bug bash, one commit each.

  • web.waitForDownload on Kernel. It always failed with download.saveAs: canceled, because a remote Chromium saves the file on its own disk. BrowserProvider gets an optional downloads: { dir, read }. Before the download, the engine tells the browser to save the page's context downloads into dir on its machine (Browser.setDownloadBehavior), then reads the finished file back through read (packages/web/src/downloads.ts). kernel() (@e2e-dev/kernel) implements read with client.browsers.fs.readFile. A provider without the hook fails with an ENGINE_FAILURE that names the provider and the missing downloads. downloads.dir must be an absolute path in the POSIX or Windows form, else INVALID_CONFIG when the config loads.
  • Icon fonts. <button><i class="fa fa-sign-in"> Login</i></button> showed as button "Login" on screen, but getByRole('button', { name: 'Login' }) found nothing, because Playwright's name includes the ::before glyph. The reader now includes ::before/::after text in names, as accname, Chrome, and Playwright do, and turns each private-use-area glyph into a space in the name it reports. A role query with a string name matches the browser's name with those glyphs allowed where the name has a space or begins or ends (packages/web/src/locators.ts:84). Label text still leaves out generated content, as getByLabel does.
  • Leaked browsers after a worker crash. A worker killed in kernel({ scope: 'attempt' }) left its browser running until Kernel's timeout_seconds. BrowserProvider gets an optional sweep(context), which finish calls once per target after releasing the leases it holds (packages/web/src/provider.ts:396). kernel() deletes every browser still active with the run's e2e_run and e2e_target tags. Core still knows nothing about browsers.
  • Kernel live-view line. Leases acquired in a worker (attempt scope, and replacements) used a log that threw lines away. They now log through the worker's init log, so watch at <url> reaches the reporter.
  • Clear errors for persistent-context limits. In attempt scope, app.clearState() now names the mode it is running in instead of saying engine web does not implement it. A session consumed on a target whose engine has no state capability now fails selection with COLLECTION_ERROR, before the setup test logs in (packages/e2e/src/collect/select.ts).
  • Kernel error text. The trailing newline on SDK error messages (401 Invalid or disabled API key\n) is trimmed. The docs now list userAgent among what attempt scope rules out.
flowchart LR
  P[prepare: lease worker-scope browsers] --> W[workers: attempt leases, replacements]
  W -- worker exits normally --> R[worker releases its own leases]
  W -- worker is killed --> X[its leases stay open]
  R --> F[finish: release the prepare leases]
  X --> F
  F --> S[provider.sweep: release what is still open for this run and target]
export interface BrowserProvider {
  // ...name, scope, acquire, release, record as before
  readonly downloads?: { readonly dir: string; read(lease, file, context): Promise<Uint8Array> };
  sweep?(context: BrowserReleaseContext): Promise<readonly string[]>;
}

Decisions to review

  • Glyph names. Glyphs count as content while a name is computed, as they do for the browser. They become spaces only in the name the tree reports. A control whose only content is a glyph (<button title="Delete"><i class="fa fa-trash"></i></button>) still reads as its title, as it did on main, so the agent can tell a toolbar's buttons apart. But the browser names that control by the glyph, so getByRole by the title still finds nothing. That is a known limit, listed with its reason in tests/crosscheck/expected.txt. I tried matching it by title too (getByRole(...).or(... .and(getByTitle(...)))), but that dropped matches inside closed shadow roots. A RegExp name is matched against the browser's name, glyph included. Documented in docs/browser.mdx, "Icon fonts and generated content".
  • Reliance on a Playwright internal. The engine finds the file on the remote disk by the basename of download.path(). That relies on Playwright naming its local file after the CDP download GUID, which is also the name the browser gives the file under allowAndName. That is a Playwright internal. tests/integration/provider-downloads.test.ts catches it against a real Chrome if it changes.
  • Sweep behaviour. The sweep is a backstop: when it fails, the reporter gets one line and the run does not fail, since Kernel's timeout_seconds still ends the browser. kernel() tries every delete and names both the deleted and the failed ones. The sweep is skipped when prepare failed and no worker started. It costs one Kernel list call per target per run.
  • The plan-time session check applies to every engine. It lives in core selection and uses only the generic state capability, so it applies to mobile and third-party engines too. It cannot name attempt scope in its message (it says engine web, as configured, has no state capability). Naming the cause would need a new engine contract field. The mobile engine declares no state with any device provider, EAS included, so a session consumer there already failed at runtime (restore and session.save() both raise UNSUPPORTED_CAPABILITY); it now fails at plan time instead.
  • The reset hook is always present in attempt scope. The web engine now always declares session.reset (what backs app.clearState()), and in attempt scope and with connect.reconnectEndpoint it rejects with UNSUPPORTED_CAPABILITY naming the mode. Before, the member was left out, and core produced the generic message.

Verified

Ran it locally: yes

  • Rebased onto main at 77940082 (after #663, #664, #666, #671) with no conflicts. Main changed none of the kernel, provider, or selection files, so the live Kernel rows below stand as run. Re-ran after the rebase: pnpm check, the web and kernel suites (cross-check and conformance with them), select.test.ts, engine-contract.test.ts, interrupt-signals.test.ts, parallel-workers.test.ts, the testbed default suite, the web benchmark suite, and the cross-check against every web-benchmark scenario. This PR adds no launch path, so #664's handleSIGINT/handleSIGTERM: false still covers every local browser (the Kernel path is connectOverCDP, which starts no process).
  • Every pinning test fails on main and passes here: tests/integration/provider-downloads.test.ts, tests/integration/icon-glyph-names.test.ts, the new generated content cross-check fixture page, and new cases in tests/unit/browser-provider.test.ts, tests/unit/cdp-connect.test.ts, packages/kernel/tests/unit/kernel.test.ts, packages/e2e/tests/unit/select.test.ts, and packages/e2e/tests/integration/engine-contract.test.ts.
  • The cross-check expected.txt is unchanged from main: the new fixture page agrees with Chrome and Playwright on every node. The conformance expectations are unchanged too.
  • Live Kernel runs (hosted Chromium against the-internet.herokuapp.com), with main's and this branch's packages packed into scratch projects:
Scenariomainthis branch
web.waitForDownload, worker scopeENGINE_FAILURE: download failed: download.saveAs: canceled✓ download a file, downloads/001-test.txt holds Test file
web.waitForDownload, attempt scopesame failure✓ download a file
getByRole('button', { name: 'Login' }) on /loginLOCATOR_NOT_FOUND: locator matched no nodes within getByRole("button", name: "Login") (the screen reads button "Login")✓ font awesome login button by its name
worker SIGKILLed in attempt scope, then a leak checkLEAK CHECK: active=1 (the attempt's browser, until timeout)ℹ kernel: released 1 browser(s) a worker left open: <id>, LEAK CHECK: active=0
attempt-scope live viewno watch at lineℹ kernel worker 0: kernel: browser <id>, watch at <url>
app.clearState() in attempt scopeUNSUPPORTED_CAPABILITY: target "kernel" has no engine capability for app state reset: engine web does not implement itUNSUPPORTED_CAPABILITY: app.clearState() is unavailable with browser provider "kernel" with scope "attempt": it replaces the browser context, and the attempt rides one persistent context; every attempt already starts on a fresh browser, and scope "worker" can clear one mid-test
test.setup + session.save() in attempt scopethe login runs for 20s, then UNSUPPORTED_CAPABILITY: ... no engine state capability for session.save()COLLECTION_ERROR: setup test ... saves session "tom" for a selected test, but target "kernel" cannot save or restore a session: engine web, as configured, has no state capability, no browser leased
bad KERNEL_API_KEY... could not lease a browser: 401 Invalid or disabled API key then, on its own line, while preparing engine web ...one line: ... 401 Invalid or disabled API key while preparing engine web for target "kernel"
  • Worker scope with a SIGKILLed worker still releases its browser (ℹ kernel: released 1 browser(s)). Every browser these runs created is deleted (LEAK CHECK: active=0).
  • The testbed default suite and the web benchmark suite pass on this branch, and so does the cross-check against every web-benchmark scenario (CROSSCHECK_BENCHMARK_URL).
  • Reading ::before/::after costs two more getComputedStyle calls per element on the name walk, cached once per element per read. pnpm bench:ab on the web benchmark (4 pairs) reports no change: every test ran the same steps with the same outcome, and every counter matched.
Metricmainthis PRchange (95% CI)
suite (sum of attempts)109.11 s109.40 s+0.5% (-1.8% to +1.2%), same
wall110.45 s111.03 s+0.7% (-1.9% to +1.9%), same

A direct reader measurement (an 800-row table plus a 300-item list, median of 10 reads, three alternating runs, machine under load) gave 916 to 1081 ms on this branch against 862 to 1110 ms on main.