fix(web,kernel): Kernel downloads, crashed-worker leaks, icon-font names, and clearer attempt-scope limits
Merged
OK
2mo ago+1159+1159+0123456789012345678901234567890123456789-119-119-012345678901234567890123456789
Six web engine and Kernel bugs from the Oct 1 bug bash, one commit each.
web.waitForDownloadon Kernel. It always failed withdownload.saveAs: canceled, because a remote Chromium saves the file on its own disk.BrowserProvidergets an optionaldownloads: { dir, read }. Before the download, the engine tells the browser to save the page's context downloads intodiron its machine (Browser.setDownloadBehavior), then reads the finished file back throughread(packages/web/src/downloads.ts).kernel()(@e2e-dev/kernel) implementsreadwithclient.browsers.fs.readFile. A provider without the hook fails with anENGINE_FAILUREthat names the provider and the missingdownloads.downloads.dirmust be an absolute path in the POSIX or Windows form, elseINVALID_CONFIGwhen the config loads.- Icon fonts.
<button><i class="fa fa-sign-in"> Login</i></button>showed asbutton "Login"on screen, butgetByRole('button', { name: 'Login' })found nothing, because Playwright's name includes the::beforeglyph. The reader now includes::before/::aftertext 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, asgetByLabeldoes. - Leaked browsers after a worker crash. A worker killed in
kernel({ scope: 'attempt' })left its browser running until Kernel'stimeout_seconds.BrowserProvidergets an optionalsweep(context), whichfinishcalls once per target after releasing the leases it holds (packages/web/src/provider.ts:396).kernel()deletes every browser still active with the run'se2e_runande2e_targettags. 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
initlog, sowatch 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 sayingengine web does not implement it. A session consumed on a target whose engine has no state capability now fails selection withCOLLECTION_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 listuserAgentamong 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 itstitle, as it did on main, so the agent can tell a toolbar's buttons apart. But the browser names that control by the glyph, sogetByRoleby the title still finds nothing. That is a known limit, listed with its reason intests/crosscheck/expected.txt. I tried matching it by title too (getByRole(...).or(... .and(getByTitle(...)))), but that dropped matches inside closed shadow roots. ARegExpname is matched against the browser's name, glyph included. Documented indocs/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 underallowAndName. That is a Playwright internal.tests/integration/provider-downloads.test.tscatches 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_secondsstill ends the browser.kernel()tries every delete and names both the deleted and the failed ones. The sweep is skipped whenpreparefailed 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
statecapability, so it applies to mobile and third-party engines too. It cannot name attempt scope in its message (it saysengine web, as configured, has no state capability). Naming the cause would need a new engine contract field. The mobile engine declares nostatewith any device provider, EAS included, so a session consumer there already failed at runtime (restore andsession.save()both raiseUNSUPPORTED_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 backsapp.clearState()), and in attempt scope and withconnect.reconnectEndpointit rejects withUNSUPPORTED_CAPABILITYnaming 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'shandleSIGINT/handleSIGTERM: falsestill covers every local browser (the Kernel path isconnectOverCDP, 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 newgenerated contentcross-check fixture page, and new cases intests/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, andpackages/e2e/tests/integration/engine-contract.test.ts. - The cross-check
expected.txtis 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:
| Scenario | main | this branch |
|---|---|---|
web.waitForDownload, worker scope | ENGINE_FAILURE: download failed: download.saveAs: canceled | ✓ download a file, downloads/001-test.txt holds Test file |
web.waitForDownload, attempt scope | same failure | ✓ download a file |
getByRole('button', { name: 'Login' }) on /login | LOCATOR_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 check | LEAK 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 view | no watch at line | ℹ kernel worker 0: kernel: browser <id>, watch at <url> |
app.clearState() in attempt scope | UNSUPPORTED_CAPABILITY: target "kernel" has no engine capability for app state reset: engine web does not implement it | UNSUPPORTED_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 scope | the 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/::aftercosts two moregetComputedStylecalls per element on the name walk, cached once per element per read.pnpm bench:abon the web benchmark (4 pairs) reports no change: every test ran the same steps with the same outcome, and every counter matched.
| Metric | main | this PR | change (95% CI) |
|---|---|---|---|
| suite (sum of attempts) | 109.11 s | 109.40 s | +0.5% (-1.8% to +1.2%), same |
| wall | 110.45 s | 111.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.