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. The inputs where reuse does not hold,
such as an import with only a fragment under a resolver that appends text after
it, are under "Tradeoffs and limits". Fresh config graphs (0.18.0 or later)
and registrar collections (0.25.0 or later) 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 older-copy 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)
writes new keys as<cacheKey>-<n>-fresh, andimportFreshModule
(packages/e2e/src/config/esm-hooks.ts:205) recordskeyandgraph
before importing the entry. An older copy keys its loads<cacheKey>-<n>,
and its cache keys can start with a target's name, so it can write any key
that ends in a number; the-freshsuffix keeps this copy's keys out of
that set, where afresh-prefix did not. - One URL reader.
loaderParameterandwrittenIn
(packages/e2e/src/config/esm-hooks.ts:435,:453) 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:484),load
(packages/e2e/src/config/esm-hooks.ts:502), andoriginalModuleURLSlot
(packages/e2e/src/config/esm-hooks.ts:569) 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.26.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,:403) 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.0and0.26.0, which report 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 ortest.extendfrom an older
version,0.25.0or later, declares the fixture, anotherresolvehook
that changes a module's URL between loads, when a test file reloads (after a failed test and for each
serial group and setup test), and Bun test-file reload behavior. The
fixture guide links to the test reference for the mixed-version cases and
for theresolvehook case. All four pages also say that a reload keeps the
fixture's value, not the module's variables: a fixture that returns an
object from module scope hands later test files the first file's object.
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.0and0.26.0's own two-install behavior (a, thenb, thenaand
b) because those releases storeatWorkin module-privateAsyncLocalStorage. Releases
0.18.0through0.24.0predatee2e.registrar-module.v1and do not mark
imported helpers as registrars. - A fixture declared with
test.extendfrom0.25.0or0.26.0keeps
file-path identity when this loader registered first too: the copy that runs
test.extendnames the fixture (packages/e2e/src/collect/registry.ts:776),
and those releases name it by file (0.26.0shipped without this change, and
itsconfig/esm-hooksandcollect/fixture-identityfiles match
0.25.0's).0.24.0and earlier give a definition no identity; a fixture
declared through one of them was not run. - An import with only a fragment (
./support.ts#variant) under a resolver
registered after the loader that appends?x=1or&x=1to the end of the
URL text loads as#variant?x=1first and#variant&x=1on reload, so its
worker fixture is set up twice, and so is each worker fixture that names it.
mainkeyed by file path and set it up once.
tsx 4.22.0 does this when a tsx namespace is in use; tsx 4.23.15 and
import-in-the-middle 3.7.1 insert before the fragment. The docs give the
workaround (set the parameter throughURL.searchParams), a
worker-fixtures.test.tsrow covers it, and a follow-up ticket tracks the
loader fix.
Issue
ENG-1553, answered as by design. This PR does not change the case ENG-1553
reports: one import URL, a helper that registers beforeEach, and two test
files that compare the fixture's value with the Map they imported. That case
stays as #2148 made it. Each test file reloads the helper and gets a new Map,
while the worker keeps the fixture's value from the first file. The docs now
say so (step 5). Making that case pass would mean evaluating the helper once
and replaying its registrations for each file, which is a separate change.
Verified
Ran it locally: yes
Head 374d6b7f2 adds two commits to a6a14453e. 439edd3e8 corrects the
JSDoc of the keys set in esm-hooks.ts (comment only). 374d6b7f2 adds the
sentence from step 5 to docs/fixtures.mdx, docs/reference/test.mdx, and
both copies of writing-tests.md. On 374d6b7f2, pnpm run build and
pnpm check passed.
ENG-1553's own script on the built CLI, 1 worker, twice each:
| Build | ENG-1553 script | The same helper without beforeEach |
|---|---|---|
main (4fec2de67) | Second file failed: fixture and hook module point at different state | Both tests passed |
a6a14453e | Second file failed with the same error | Both tests passed |
Head a6a14453e adds two commits to 300d292a8, which adds six commits on top
of c77e61689. a30df9ca1 merges main (4fec2de67). The merge had one
conflict, the worker fixture list in docs/reference/test.mdx. The list keeps
this PR's bullets and the bullet #2554 added, word for word. Git merged
worker-fixtures.test.ts and both copies of writing-tests.md without a
conflict, and no file under src/ is changed by both. a6a14453e adds one docs
sentence, for the resolver case in the three-build table below.
300d292a8 is
docs-only: it rewraps one paragraph of docs/reference/test.mdx, same words
(pnpm docs:check passed). d14129e7d is
test-only (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. 80a5a47c7, 249ac03d8, and 5ffcda05a are docs-only
(docs/fixtures.mdx, docs/reference/test.mdx, and both copies of
writing-tests.md). The probes, mutation run, and bench-ab table below were
recorded on c77e61689.
112b5e15e changes the fresh-load key from fresh-<cacheKey>-<n> to
<cacheKey>-<n>-fresh, words the older-version notes as 0.25.0 or later, and
adds two tests. Ran on Node.js v26.13.1:
| Check | 5ffcda05a | 112b5e15e |
|---|---|---|
New open-host-loader test: an older copy imports the config as ?e2e=fresh-module-<n>&e2e-graph=fresh-module-<n> for n 1 to 20, the config is edited, then openHost() | Failed: target one (stale module from Node's cache) | Passed: target two |
New worker-fixtures row: #variant and ?variant=two under a resolver after the loader that sets its parameter through URL.searchParams | Not run | Passed, one setup per import; the same row with an appending resolver fails, as the documented limit says |
tests/unit/esm-hooks.test.ts, tests/integration/open-host-loader.test.ts, tests/integration/worker-fixtures.test.ts | Not rerun | 105 of 105 passed |
pnpm check | Passed | Passed |
#2554 on main gives a worker fixture a separate instance for each chain
that overrides a fixture it names. This PR names the fixture by the URL its
module was imported by. Both ran together on a6a14453e, on Node.js v26.13.1:
| Check | a6a14453e |
|---|---|
pnpm --filter e2e run test, the whole runner suite | 6792 tests passed and 15 skipped, in 406 files passed and 1 skipped |
pnpm check | Passed |
Built CLI, 1 worker, twice from fresh state. A fixture module where client names account and adminTest overrides account, imported as ?tenant=a and ?tenant=b, then as #a and #b | Four client setups, one per import and chain. Each test got the client of its own tenant and account |
| The same module imported by one URL from two test files, and a test that fails once and is retried | Two client setups, one per chain. The second file and the retry got the instances of the first |
With #2554 the resolver limit under "Tradeoffs and limits" reaches the fixtures
that name the affected one. db.mjs declares worker fixture db and a hook.
client.mjs imports it as ./db.mjs#variant and declares client, which names
db and holds a lock file. Two test files import client.mjs, and a resolver
registered after the loader appends apm=1 to the end of the URL of db.mjs.
Each test checks that its client was built from the db it got. Built CLI,
1 worker, twice each from fresh state:
| Build | Setups | Second test |
|---|---|---|
main (4fec2de67) | db, client | Passed |
300d292a8 | db, client, db | Failed its own check: it got the second db with the client built from the first |
a6a14453e | db, client, db, client | Failed with EEXIST on the lock the first client holds |
Each of the three, with the resolver using URL.searchParams | db, client | Passed |
Two inputs the newest docs sentences describe ran on 80a5a47c7 with the
built CLI on Node.js v26.13.1, 1 worker, twice each from fresh state:
| Case | main (8bad3fc5b) | This PR (80a5a47c7) |
|---|---|---|
Two test files import a fixture module that registers a hook as ./support.mjs#variant; a resolver registered after the loader appends ?apm=1 to a URL without a query and &apm=1 to one with a query | One setup, both tests passed | Two setups (#variant?apm=1, then #variant&apm=1), second test failed with EEXIST |
The same, with the resolver adding apm=1 through URL.searchParams | One setup, both tests passed | One setup, both tests passed |
This build runs; the fixture module calls test.extend from the 8bad3fc5b build; imports ?v=one and ?v=two | Not run | One setup, second test received one |
The same, with this build's test.extend | One setup | Two setups, both tests passed |
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 and older test.extend (0.25.0 or later) file-path fallback, another
resolve hook that changes a module's URL between loads, 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 separation and reuse across module reloads and imports with different URL queries or fragments, including during retries.
- Improved configuration reload behavior so updates are recognized consistently across loader scenarios.
-
Documentation
- Clarified how worker fixtures behave in Node.js and Bun, including how test-file reloads and top-level
awaitcan affect fixture setup. - Added guidance on sharing worker fixtures, handling asynchronous setup, and how import URL differences and loader versions affect fixture instances.
- Clarified how worker fixtures behave in Node.js and Bun, including how test-file reloads and top-level