fix(runner): isolate worker fixture instances across extend() overrides (ENG-1400)

Merged
KR
21h ago
+179-20

What

A worker fixture that depends on another worker fixture now gets a separate instance for each test.extend() chain that overrides one of its dependencies, directly or through another fixture. Chains that share every worker fixture it names still share one instance.

Why

WorkerFixturePool.acquire cached each worker fixture solely by its own identity. When client depended on account and another file defined adminTest = test.extend({ account }), both chains resolved client to the same cached instance. Whichever file ran first set client for the rest of the worker, so the second file got the wrong account's client.

How it works

  1. WorkerFixturePool.instances maps each fixture key (definition.identity ?? definition) to a list of WorkerInstance entries holding { inputs, instance }, where inputs are the instance promises returned by acquire for the chain worker fixtures it depends on (packages/e2e/src/run/fixture-pool.ts:140, packages/e2e/src/run/fixture-pool.ts:199). On lookup, acquire reuses an entry only when all inputs match by reference; on setup failure, only that entry is evicted.
  2. bindFixtures tracks the acquire promise for each worker fixture in workerInstances (packages/e2e/src/run/fixture-pool.ts:321) and passes the resolved dependency promises in declaration order to pool.acquire, leaving built-in fixtures out of the key (packages/e2e/src/run/fixture-pool.ts:354-359). Keying by instance promise rather than by definition handles transitive overrides (client -> link -> account), and keying by promise rather than resolved value handles overrides that pass the extended object through.
  3. Updated the fixture doc comment (packages/e2e/src/collect/registry.ts:66), documented the instance rule under worker fixtures (docs/reference/test.mdx:1185), and added a patch changeset for e2e.
  4. Added unit tests covering both chain orders, transitive overrides with a shared dependency, and pass-through overrides (packages/e2e/tests/unit/fixture-pool.test.ts), plus a runner integration test for the two-file repro in both orders (packages/e2e/tests/integration/worker-fixtures.test.ts).

Issue

ENG-1400

Verified

Ran it locally: yes

  • Built CLI (node node_modules/e2e/dist/cli/bin.js run) on a two-file repro project (workers: 1, retries: 0) where tests/support.ts defines worker fixtures account and client, tests/user.e2e.ts uses test, and tests/admin.e2e.ts overrides account with base.extend:
mainthis PR
tests/user.e2e.ts fails: ERROR: expected client:user, got client:admin (1 failed | 1 passed (2))Both files pass (2 passed (2))
=== main ===
   ✓ |web| tests/admin.e2e.ts > admin gets admin client 461ms
 ✓ |web| tests/admin.e2e.ts (1 test) 461ms
   × |web| tests/user.e2e.ts > user gets user client 13ms
     → expected client:user, got client:admin
 ❯ |web| tests/user.e2e.ts (1 test | 1 failed) 13ms

 Test Files  1 failed | 1 passed (2)
      Tests  1 failed | 1 passed (2)

=== this PR ===
   ✓ |web| tests/admin.e2e.ts > admin gets admin client 459ms
 ✓ |web| tests/admin.e2e.ts (1 test) 459ms
   ✓ |web| tests/user.e2e.ts > user gets user client 9ms
 ✓ |web| tests/user.e2e.ts (1 test) 9ms

 Test Files  2 passed (2)
      Tests  2 passed (2)
  • apps/testbed: tests/hooks.e2e.ts passes (7 passed (7) in 2.50s).
  • Skipped pnpm bench:ab: this change adds a reference equality check over a fixture's dependency list on worker-fixture acquisition and does not alter attempt scheduling or execution loops.
  • Not verified locally: mobile (isolation: 'worker'), serial groups, and box (all go through the same bindFixtures -> acquire path).

Summary by CodeRabbit

  • Bug Fixes

    • Fixed worker-scoped fixtures so tests that override a dependency receive the correct separate fixture instance, while tests with matching fixture chains can share instances.
    • Improved handling of failed fixture setup so other fixture instances remain available and later requests can retry.
    • Verified that dependent fixtures are set up separately for overridden values, including when overrides are indirect or applied in a different order.
  • Documentation

    • Clarified how worker-fixture instances are shared across tests and how direct and indirect overrides affect dependent fixtures.