fix(runner): distinguish worker fixtures by import URL (ENG-1553)
What
On Node.js, worker fixtures distinguish user-written ES module queries and
fragments. When the runner reloads the same import for a retry or hook
registration, the worker reuses that fixture value. Reuse holds when another
resolver appends a fragment or query parameter, rewrites or percent-encodes the
query, appends a literal ? query onto the URL's query, or short-circuits a
test entry started by importFreshModule. Fresh config graphs (0.18.0
through 0.25.0) and registrar collections (0.25.0) started by an older copy
of e2e in the same process stay fresh when that entry reaches this loader's
resolve hook with the accepted parameter shape.
Why
Worker fixture identity previously keyed on file path alone, which merged
imports such as ./db.ts?a and ./db.ts?b into one instance. Keying on raw
import.meta.url instead would break retries, because each fresh runner load
appends a new ?e2e=<key> query parameter and a second setup of an exclusive
port or file lock fails. Reading any e2e or e2e-graph query parameter from
the URL as loader metadata also mistook user-written parameters under those
names for the runner's own.
How it works
flowchart LR
A[importFreshModule] --> S[keys + graphs sets]
B[legacyEntry in resolve] --> S
B --> C[legacyCollectorLoads WeakMap]
U[module URL] --> W[writtenIn]
S --> W
W -->|key + graph| R[resolve + load hooks]
C -->|active 0.25.0 collection| R
W -->|original URL| F[fixtureIdentities]
- Shared parameter sets.
FreshnessStateonfreshnessSlot
(packages/e2e/src/config/esm-hooks.ts:87,:111) sharesatWork, the
load sequence, and decodedkeysandgraphssets across copies ofe2e
in one process.importFresh(packages/e2e/src/config/load.ts:137)
prefixes new keys asfresh-<cacheKey>-<n>, andimportFreshModule
(packages/e2e/src/config/esm-hooks.ts:205) recordskeyandgraph
before importing the entry. - One URL reader.
loaderParameterandwrittenIn
(packages/e2e/src/config/esm-hooks.ts:434,:452) inspect the query
before#, preserve any leading?inside a parameter name, match decoded
e2eande2e-graphvalues againstkeysandgraphs(including
percent-encoded names or values and a naive resolver appending?x=1
directly onto a loader parameter), and rebuildoriginalfrom the remaining
raw parameters, their literal?or&separators, and the fragment.
resolve(packages/e2e/src/config/esm-hooks.ts:483),load
(packages/e2e/src/config/esm-hooks.ts:501), andoriginalModuleURLSlot
(packages/e2e/src/config/esm-hooks.ts:568) all readwrittenIn.
appendQuery(packages/e2e/src/config/esm-hooks.ts:177) appends loader
parameters without re-encoding user query text or fragments. - Older copies in the same process. Published versions
0.18.0through
0.25.0write?e2e=<key>and optional&e2e-graph=<name>on the entry
imported fromdist/config/load.js, and hold any active collector on
e2e.activeCollector.v1.isConfigLoaderandlegacyEntry
(packages/e2e/src/config/esm-hooks.ts:367,:402) resolve the importer
path withfileURLToPath(ignoring any query or fragment added to
config/load) and read the writtenspecifierquery even if an earlier
resolver modifiesresolution.url. While collection is active,
legacyEntrybinds the key to the collector inlegacyCollectorLoads
(WeakMap,packages/e2e/src/config/esm-hooks.ts:121,:123,:171). On
0.25.0, which reports registrar modules viae2e.registrar-module.v1,
transitive plain helpers re-evaluate registrars during active collection and
stop inheriting that load once collection ends. - Fixture identity and older-first fallback.
fixtureIdentities
(packages/e2e/src/collect/fixture-identity.ts:25) keys worker fixtures by
originalModuleURL(location) ?? locationwhen the slot is present, and
falls back tomoduleFile(location)
(packages/e2e/src/collect/fixture-identity.ts:32) when an older copy
registered the module loader first and installed no lookup. - Documentation and release note.
docs/fixtures.mdx,
docs/reference/test.mdx,skills/e2e/references/writing-tests.md,
plugins/e2e/skills/e2e/references/writing-tests.md, and
.changeset/silent-fixture-urls.mddescribe synchronous registration on
Node.js, ES module URL query and fragment identity, the file-path fallback
when an older version owns the loader, and Bun test-file reload behavior.
Tradeoffs and limits
- If user code writes an import query whose decoded
e2eore2e-graph
parameter equals a livekeyinkeysorgraphingraphs(or starts
with one followed by a literal?, such as?e2e-graph=<live>?x=1),
writtenInreads that prefix as the loader's, matching howmaintreats
everye2eande2e-graphparameter. The same user-written URL therefore
reads differently in one process once that load key or graph name becomes
live. inGraph(packages/e2e/src/config/esm-hooks.ts:315) skips the fresh-graph
tag when a resolved URL already has anye2e-graphparameter, and
inFreshLoad(packages/e2e/src/config/esm-hooks.ts:162) skips the load key
when it already has anye2eparameter. A config dependency imported with a
user-written?e2e-graph=appstays cached across fresh graphs, as onmain.- A resolver that mutates a URL's fragment text differently after the loader
adds?e2e=<key>(for example appending?x=1versus&x=1after#frag),
or that concatenates an unescaped?x=1onto the query and then re-encodes
it into%3Fx%3D1viasearchParams.sort(), produces distinct module
identities across reloads. keysandgraphsretain one short string per fresh load key and graph name
created in the process, andlegacyConfigParentscaches one boolean per
distinctconfig/loadfile path;legacyCollectorLoadsis aWeakMapand
retains nothing after a collection finishes. Failed or symlinked imports add
no per-module entry.- Recognizing an older copy's entry requires its import from
dist/config/load.js
orsrc/config/load.tsin a package namede2eto reach this loader's
resolvehook with the accepted parameter shape (?e2e=<key>and optional
&e2e-graph=<name>, nothing else). A bundled or relocated older copy, or a
resolver registered after this loader that short-circuits the entry or adds
extra query parameters tospecifierbeforeresolveruns, is not matched. - When an older copy registered the module loader first, its
resolvehook
owns the process: worker fixtures use file-path identity, and two-install
runner.list()calls reaching a shared registrar through plain helpers keep
0.25.0's own two-install behavior (a, thenb, thenaandb) because
0.25.0storesatWorkin module-privateAsyncLocalStorage. Releases
0.18.0through0.24.0predatee2e.registrar-module.v1and do not mark
imported helpers as registrars.
Issue
ENG-1553
Verified
Ran it locally: yes
Head d14129e7d adds one test-only commit on top of c77e61689 (passing
'junction' to symlinkSync in open-host-loader.test.ts); that file passed
11 of 11 tests on Node.js v22.23.5 and v26.13.1, and pnpm check passed.
The probes, mutation run, and bench-ab table below were recorded on
c77e61689.
Ran the built CLI and two-install runner.js / config/load.js probes on
Node.js v22.23.5 and v26.13.1, pairing this head against a physical
e2e@0.25.0 / main (8bad3fc5b) install:
| Case | main (8bad3fc5b / 0.25.0) | This PR (c77e61689) |
|---|---|---|
Distinct user queries and fragments (./support.ts?a=1#one vs #two, ?a=a%20b vs ?a=a+b, ??e2e-graph=...) | Shared one worker fixture by file path | Separate worker fixtures |
Forwarded import (./forward.mjs?e2e=blue -> ./support.mjs?variant=base) beside ./support.mjs?variant=base&e2e=blue | Forwarded query treated as loader key | Separate worker fixtures matching Node.js module identity |
Retry on entry or queried helper (./support.mjs?variant=blue) when a later resolver appends &x=1, appends literal ?x=1 before #, percent-encodes %652e, or short-circuits retry.e2e.ts | One setup, retry passed | One setup, retry passed on Node.js 22 and 26 |
Newer loader first, 0.25.0 runner.list() called 3 times on direct registrars, plus helper-wrapped registrars | Direct: a,b each call; helper-wrapped: a, then b, then a,b | Direct and helper-wrapped: a,b on all 3 calls |
Newer loader first, dynamic import() of a registrar from a plain helper after 0.25.0 runner.list() returns | Returned cached module | Returned cached module (no COLLECTION_ERROR) |
Newer loader first, older openHost() / loadConfigModule({ graph }) across edits, including #instrumented on config/load.js, &x=1 from an earlier resolver, and + rewritten to %20 | Reloaded edited target each time | Reloaded edited target each time |
Older loader registered first (originalModuleURLSlot absent) with a fixed-port worker fixture on retry | One setup and one teardown | One setup and one teardown |
$ node outside.mjs <head> <0.25.0-build> newer-first
{"listed":["test A","test B"],"result":""}
$ node p2-retry.mjs <head> cand literal '?variant=blue' out.json
{"node":"v26.13.1","exit":0,"status":"flaky","setups":1,"events":["setup ?variant=blue?x=1","teardown ?variant=blue?x=1"]}
$ node graph.mjs <head> <0.25.0-build> before append host
["first","second","third","fourth"]
Mutation testing in an isolated detached worktree (mutant.sh --vitest across
tests/unit/esm-hooks.test.ts, tests/integration/open-host-loader.test.ts,
and tests/integration/worker-fixtures.test.ts): 25 mutants, 25 killed,
0 survived, 0 unconfirmed, 0 did not build, with all 30 added tests killed by
at least one mutant (new-test-kills.mjs exit 0).
No rendered docs screenshot is attached: the docs edits in docs/fixtures.mdx
and docs/reference/test.mdx are prose bullets covering synchronous Node.js
registration (no top-level await), ES module URL query and fragment identity,
the older-loader file-path fallback, and Bun test-file reloads, validated with
pnpm docs:check, and no local Mintlify preview server is configured in this
CLI session. Not measured locally: long-session heap retention and Bun runtime
execution.
bench-ab: 8bad3fc5 (merge base with 8bad3fc5b56e9a9d6e8f273ad2205eb5b5b8db0b) vs c77e6168
apps/testbed: e2e run --workers 1 tests/forms.e2e.ts. 6 pairs in random order, resolved after 6 pairs. Threshold ±3% and 10 ms. darwin arm64, Apple M5 Pro x18, Node 26.13.1, load 6.2.
Behavior
Every test ran the same steps with the same outcome on every run of both builds.
Timings
| Metric | base median (IQR) | head median (IQR) | change (95% CI) | verdict |
|---|---|---|---|---|
| wall (process) | 1.73 s (1.71 s-1.74 s) | 1.71 s (1.71 s-1.72 s) | -1.2% (-1.5% to +0.2%) | same |
| suite (sum of attempts) | 831 ms (824 ms-837 ms) | 829 ms (826 ms-835 ms) | -0.7% (-1.5% to +0.8%) | same, under the floor |
| action (events) | 363 ms (362 ms-363 ms) | 364 ms (362 ms-364 ms) | +0.3% (-0.4% to +1.0%) | same, under the floor |
| step app.open | 188 ms (186 ms-191 ms) | 187 ms (186 ms-188 ms) | -0.8% (-3.6% to +1.9%) | same, under the floor |
| step locator.fill | 157 ms (156 ms-157 ms) | 157 ms (156 ms-158 ms) | +0.3% (-0.6% to +1.6%) | same, under the floor |
| step locator.tap | 90 ms (88 ms-90 ms) | 90 ms (90 ms-91 ms) | +0.6% (0.0% to +4.4%) | same, under the floor |
| step locator.check | 44 ms (42 ms-45 ms) | 43 ms (42 ms-44 ms) | -1.1% (-4.3% to +5.0%) | same, under the floor |
| step locator.pressSequentially | 41 ms (41 ms-42 ms) | 42 ms (42 ms-42 ms) | +2.4% (0.0% to +2.4%) | same, under the floor |
| step locator.uncheck | 32 ms (32 ms-33 ms) | 32 ms (32 ms-33 ms) | 0.0% (-3.0% to +3.1%) | same |
| step expect.toBeVisible | 18 ms (18 ms-18 ms) | 17 ms (17 ms-18 ms) | -5.6% (-5.6% to -2.7%) | same, under the floor |
| step locator.selectOption | 17 ms (17 ms-18 ms) | 16 ms (16 ms-17 ms) | -5.9% (-13.1% to 0.0%) | same, under the floor |
| step locator.clear | 17 ms (16 ms-17 ms) | 17 ms (17 ms-17 ms) | +2.9% (-2.8% to +9.7%) | same, under the floor |
| step expect.toHaveValue | 7 ms (6 ms-9 ms) | 7 ms (6 ms-7 ms) | -5.7% (-18.4% to +18.3%) | same, under the floor |
| step expect.toHaveCount | 5 ms (5 ms-6 ms) | 6 ms (5 ms-6 ms) | +9.5% (-8.7% to +34.2%) | same, under the floor |
| step expect.toHaveText | 4 ms (3 ms-4 ms) | 4 ms (4 ms-5 ms) | +29.1% (-13.4% to +41.4%) | same, under the floor |
| step expect.toBeChecked | 2 ms (2 ms-2 ms) | 2 ms (2 ms-2 ms) | 0.0% (-18.4% to 0.0%) | same |
| step expect.not.toBeChecked | 2 ms (1 ms-2 ms) | 2 ms (2 ms-2 ms) | 0.0% (-29.3% to +100.0%) | same |
Counters
Every counter matched on every run of both builds.
Tests outside the threshold: 0 of 640
With 640 tests compared at 95%, about 32.0 could land outside by chance.
Summary by CodeRabbit
-
Bug Fixes
- Improved worker-fixture identity across module reloads and imports with different URL queries or fragments, so fixtures are separated or reused consistently during retries.
- Improved fresh module graph and configuration reload behavior across supported loader scenarios.
-
Documentation
- Clarified worker-fixture behavior in Node.js and Bun, including how top-level
awaitand test-file reloads affect fixture setup. - Added guidance on declaring shared worker fixtures, handling asynchronous setup, and how URL differences can affect fixture instances.
- Clarified worker-fixture behavior in Node.js and Bun, including how top-level