Skip to content

test: verify Chromium interception before browser mocks (backport vitest#11083) - #1675

Merged
trueadm merged 1 commit into
mainfrom
test/browser-playwright-route-race
Oct 3, 2026
Merged

trueadm merged 1 commit into
mainfrom
test/browser-playwright-route-race

Conversation

@trueadm

@trueadm trueadm commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Backport fix(browser): close the mock route interception race (fix #8339) vitest-dev/vitest#11083 (d6620fae6fdb401a510af4e071f7451b7c638021) into @vitest/[email protected] as patches/@[email protected]. It is registered in pnpm-workspace.yaml beside the existing @vitest/browser and @vitest/mocker patches. No 4.x release contains the fix: 4.1.11 shipped 2026-08-18, and the fix merged 2026-10-01.
  • The patched provider proves Chromium request interception is live before it adds a mock route, and keeps interception on across files. This covers every config that uses playwright(), including the adapted and pristine Base UI browser lanes.

Why

  • @vitest/browser-playwright applies vi.mock through context.route(). The tester's invalidate() → clearMocks → unroute drops the route count to zero between files. Playwright 1.61.1 sends Fetch.enable only when the count goes from 0 to 1, and Chromium applies it asynchronously after its ack. A module request issued about 1 ms after route() resolves can therefore bypass the mock and load the real module ([Browser] Inexplicable flakiness with spies and mocks in CI vitest-dev/vitest#8339). This is the react-parity-browser-tooling flake "The first file must see its own mock". Base UI's browser lanes run 20 adapted upstream files that call vi.mock and have the same exposure.

Changes

  • patches/@[email protected] changes only dist/index.js:
    • register now awaits armInterception(page).
    • On a Chromium context's first mock, probeInterception installs a route for /__vitest_interception_probe__ and fetches it from the page until the x-vitest-probe header proves interception is live. That is up to 5 s, with the same error message as upstream.
    • The probe route stays installed, so Fetch is never disabled between files.
    • The code is upstream's TypeScript, transpiled to match the dist.
  • test-utils/vitest-browser-collection.test.ts: the mocked collection file now fetches the probe after its mocked import. The race itself only fires on loaded Linux runners, so this check is the deterministic signal that the backport is active, as in upstream's own interception-probe.test.ts. It fails if an upgrade or lockfile change drops the patch.
  • packages/base-ui/scripts/build-react-parity-manifest.mjs: the Base UI browser lanes list the new patch as support evidence, next to the other two Vitest patches.
  • docs/browser-diagnostics.md: new "Browser mock interception race" section covering the mechanism, the fix and the evidence.
  • Generated by pnpm sync: the lockfileSha256 refresh in every packages/*/audit/react-parity.json and the evals manifest.jsonl, both caused by the lockfile change.

Evidence (DEBUG=pw:protocol, macOS)

  • Collection fixture, unpatched. Fetch.enable is sent when registerMock arrives (21.101). Its ack and the Fetch.requestPaused for dependency.mjs both land at 21.102. Fetch.disable follows at clearMocks. Nothing orders the import after interception is live. On macOS the request happened to be paused; on loaded Linux it can slip past.
  • Collection fixture, patched. Fetch.enable (56.497), then the probe is paused and fulfilled with x-vitest-probe: 1 (56.501–56.503). Only after that is dependency.mjs paused and mocked (56.504). No Fetch.disable appears anywhere. The unmocked file's dependency.mjs is paused, continued, and loads the original module.
  • Base UI adapted browser lane, its 20 vi.mock files (18 ran, 2 skipped; 196 tests passed both ways):
    • Unpatched: 20 × Fetch.enable and 20 × Fetch.disable. Each file's first paused request arrived 0–2 ms after Fetch.enable was sent and 0–1 ms after its ack.
    • Patched: 1 × Fetch.enable, 0 × Fetch.disable. The probe was interception-job-1.0 and was fulfilled before any mock.
  • Probe guard. Against the unpatched provider, the probe gets Vite's 404 with no header, so the new check throws. Patched, it gets 204 with x-vitest-probe: 1.

Fixture-local anchor

A fixture-only workaround was drafted on test/browser-collection-mock-race but never committed. It installed a never-matching route in a wrapped createContext. It is not needed with this patch, so it should not land:

  • The provider's probe route already holds the route count at or above one from the first registration onward.
  • The probe also proves interception is live before the mock route is added, which a passive anchor cannot.
  • The fixture on main passes with the patch and uses a plain playwright() provider, as every real lane does.

Validation

  • pnpm format:check: not run repo-wide. pnpm format:files:check passes on the changed files.
  • pnpm typecheck: not run. The test edit is inside a fixture template string, and neither changed source file belongs to a TS project.
  • pnpm test: not run locally; left to CI.
  • targeted tests:
    • vitest run --project react-parity-browser-tooling test-utils/vitest-browser-collection.test.ts: 2/2 passed.
    • Base UI adapted browser config on its 20 vi.mock files: 18 passed, 2 skipped, 196 tests passed.
    • node packages/base-ui/scripts/build-react-parity-manifest.mjs --check passes.
    • pnpm sync is clean.

Risk / follow-ups

  • After a context's first mock, every request from that context goes through Playwright's route handler, including requests in later files that mock nothing. Upstream accepted this cost.
  • Firefox and WebKit are not probed, as upstream.
  • Drop the patch when Vitest is upgraded to a release that contains fix(browser): close the mock route interception race (fix #8339) vitest-dev/vitest#11083. A version bump without removing the entry fails install as an unused patch.

Provenance

  • An agent produced this diff (agent-authored)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Note

Medium Risk
Changes vendored Vitest Playwright behavior for all playwright() browser lanes (extra routing overhead per context); low production impact but broad test-infrastructure touch—remove the patch when upgrading to a Vitest release that includes #11083.

Overview
Adds a pnpm patch for @vitest/[email protected] that backports vitest-dev/vitest#11083 (not in any 4.x release). Before registering a mock route, the provider now proves Chromium request interception is active via /__vitest_interception_probe__ and keeps a probe route installed so Fetch is not toggled off between test files—addressing flaky cases where vi.mock could load the real module right after registration on loaded Linux runners.

Wiring and guards: the patch is registered in pnpm-workspace.yaml and pnpm-lock.yaml; Base UI react-parity manifest evidence lists it alongside the existing Vitest browser/mocker patches; docs/browser-diagnostics.md documents the race and fix.

Regression: test-utils/vitest-browser-collection.test.ts fetches the probe after the mocked import so CI fails if the patch is missing. Sync refreshed lockfileSha256 (and related manifest hashes) across packages/*/audit/react-parity.json.

Reviewed by Cursor Bugbot for commit 93c9feb. Bugbot is set up for automated code reviews on this repo. Configure here.

Backport vitest-dev/vitest#11083 into @vitest/[email protected] as
a pnpm patch. The provider mocks through context.route(); clearing mocks
between files removes every route, and Playwright 1.61.1 re-sends
Fetch.enable on the next route, which Chromium applies after its ack. A
module request issued right after vi.mock could load the real module
(vitest-dev/vitest#8339).

On a context's first mock registration the patched provider installs a
probe route, fetches it until interception is proven live, and keeps it
installed so interception stays on across files. The collection
regression now checks the probe after its mocked import, and the Base UI
browser lanes record the patch as evidence. Parity manifests and the evals
corpus pick up the new lockfile digest.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@trueadm
trueadm marked this pull request as ready for review October 3, 2026 16:38
@github-actions github-actions Bot added agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only labels Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

🟢 No budget breaches, no added work, and no timing changes beyond ±3%.

Compares 8fddced09, the merge commit's first parent with 9286652bf on the same runner. A byte value over its committed budget or any increase in a js-framework work counter fails this check. Wall time is a report: base and head samples alternate in one browser, and an operation is called slower or faster only when the 95% confidence interval of its ratio excludes ±3%. Workflow run

js-framework: 1k/10k row operations

All 20 timed operations (20 without a verdict)
target operation base ms head ms head/base 95% CI
octane-tsrx run 3.033 3.058 ±0.0% −1.6% … ±0.0% ⚪ within noise
octane-tsrx replace 5.975 5.850 −0.8% −1.7% … ±0.0% ⚪ within noise
octane-tsrx add 2.775 2.775 ±0.0% −3.6% … ±0.0% ⚪ within noise
octane-tsrx update 0.121 0.121 −0.4% −6.0% … +2.2% ⚪ within noise
octane-tsrx select 0.006 0.006 +2.8% +0.5% … +4.3% ⚪ within noise
octane-tsrx swap 0.040 0.042 +0.4% −1.3% … +4.7% ⚪ within noise
octane-tsrx remove 0.017 0.018 +1.5% +0.0% … +4.8% ⚪ within noise
octane-tsrx runlots 26.892 26.275 −0.5% −4.2% … +2.3% ⚪ within noise
octane-tsrx select_lots 0.006 0.006 −1.2% −3.0% … ±0.0% ⚪ within noise
octane-tsrx clear 36.075 36.642 +0.7% −2.1% … +4.6% ⚪ within noise
octane-jsx run 3.525 3.517 ±0.0% ±0.0% … +1.2% ⚪ within noise
octane-jsx replace 6.400 6.667 ±0.0% −1.6% … +1.5% ⚪ within noise
octane-jsx add 3.475 3.258 −0.0% −3.0% … ±0.0% ⚪ within noise
octane-jsx update 0.255 0.253 +0.4% −1.5% … +2.3% ⚪ within noise
octane-jsx select 0.137 0.134 −2.5% −5.3% … −1.5% ⚪ within noise
octane-jsx swap 0.229 0.226 −0.3% −1.4% … +0.0% ⚪ within noise
octane-jsx remove 0.173 0.170 −1.4% −2.5% … +0.0% ⚪ within noise
octane-jsx runlots 31.242 30.650 −0.7% −2.5% … +2.4% ⚪ within noise
octane-jsx select_lots 1.716 1.712 +0.0% −1.8% … +1.2% ⚪ within noise
octane-jsx clear 39.867 40.267 +0.7% −0.6% … +3.2% ⚪ within noise

All 64 work counters are unchanged.

Application bundle size (bytes)

No changes across 45 measured values.

Public-import reachability bundles (bytes)

No changes across 105 measured values.

@trueadm
trueadm merged commit 521dfbf into main Oct 3, 2026
50 of 52 checks passed
@trueadm
trueadm deleted the test/browser-playwright-route-race branch October 3, 2026 17:15
KevinVandy pushed a commit to KevinVandy/octane that referenced this pull request Oct 9, 2026
* feat: add @octanejs/tanstack-db binding

Port the Octane live-query bindings for @tanstack/db (TanStack/db PR octanejs#1699,
`packages/octane-db`, still open) into the monorepo as `@octanejs/tanstack-db`.

- Re-exports @tanstack/[email protected] unchanged; adapts the live-query surface
  (useLiveQuery, useLiveInfiniteQuery, useLiveSuspenseQuery, useLiveQueryEffect,
  usePacedMutations) onto Octane hooks. Source imports only public @tanstack/db.
- Package shape matches sibling bindings: exports point at src/ (no dist build),
  self-contained tsconfig (jsxImportSource octane), status.json.
- Tests decoupled from the db monorepo: internal src imports rewritten to
  @tanstack/db; test helpers, the conformance suite, and db's expression
  evaluator vendored under tests/db-fixtures/ (pinned to 0.6.17, test-only) so
  the infinite-query tests can interpret the where/cursor IR db generates.
- Wired into vitest.config.js and the root typecheck script; registered in
  website/src/content/bindings.json; changeset added.

Generated inventories (docs/packages.md, docs/bindings-status.md, CLI data,
react-parity lockfile hashes) are intentionally omitted from this diff and
should be regenerated with `pnpm sync` at merge time.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(tanstack-db): move @octanejs/tanstack-db to TanStack DB 0.7.0 and fix live-query blockers

Rebinds the binding to the TanStack DB 0.7.0 adapter architecture and fixes the
PR review's P1 blockers at the source:

- Suspense suspends via Octane `use(thenable)` instead of `throw promise`
  (Octane Suspense only recognizes the use() sentinel). Proven by an async
  fallback regression test.
- useLiveQuery/useLiveSuspenseQuery rebuilt on db's shared createLiveQueryObserver
  (db octanejs#1642) so status-only transitions (error/cleaned-up) update isError/
  isCleanedUp.
- useLiveInfiniteQuery rebuilt on the coordinated createLiveQueryWindowController
  (db octanejs#1675): window leases stop two hooks on one collection truncating each
  other (regression test), and a failed page load rolls back and surfaces
  snapshot.error with a clean retry.
- useLiveQueryEffect parses deps + the compiler slot together from ...rest, so
  no-deps usage keeps its call-site slot.
- Conformance suite: drop order-only-move from universal expected-fail (db octanejs#1669
  fixed the contract); un-skip the missing-orderBy test (surfaced synchronously
  during render via getWindow()); record StrictMode double-invoke as
  not-applicable. Committed-test-marker gate passes.
- Bump @tanstack/db ^0.6.17 -> ^0.7.0; re-pin vendored db-internal fixtures;
  vendor the @tanstack/[email protected] adapter source under upstream/ with
  SHA256SUMS; add UPSTREAM.md pin + crosswalk; refresh status.json/README.

Octane-adaptation: the subscribe wrappers defer an initial onStoreChange to a
microtask because Octane's useSyncExternalStore re-checks the snapshot before
(not after) subscribe; pinned by the eager-onstorechange test.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(tanstack-db): call use() unconditionally in useLiveSuspenseQuery; document startSync divergence

Addresses two Cursor Bugbot findings on the 0.7.0 remediation commit.

- [High] useLiveSuspenseQuery called use() only on the loading/idle path and
  skipped it once ready. Octane keys use(thenable) by dynamic call-order index
  (runtime __thenableIdx), not by compiler slot, so a ready hook that skips its
  use() shifts the thenable index of a sibling use()/second useLiveSuspenseQuery
  in the same component. On the replay after the first query resolves, the
  second hook read the first's fulfilled thenable (resume-replay leniency path)
  and stopped suspending, surfacing its still-loading collection as ready. Fix:
  call use() unconditionally — exactly once per render — handing it an
  already-resolved sentinel on the ready/stale paths so the call-order index
  stays stable and no suspend occurs. New regression test drives two
  independently gated collections and asserts the later sibling stays suspended
  while the earlier one is ready (fails pre-fix with `a:3|b:0`).

- [Medium] Documented the useLiveInfiniteQuery `startSync: true` divergence in
  status.json. The query-function collection is created with the first-page
  window already applied (.limit(pageSize + 1).offset(0)), so eager sync fetches
  exactly the first page — never a wider subset — before the window controller
  grows it; only the fetch-start timing differs from upstream's post-commit
  start. (Bugbot's third finding, "stale pages after deps change", was against
  the pre-remediation commit and no longer applies: the controller rewrite
  computes page count synchronously during render.)

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(tanstack-db): pre-tag the useLiveSuspenseQuery ready-path sentinel as fulfilled

Follow-up to the unconditional-use() change. The shared `SETTLED` thenable handed
to `use()` on the non-loading paths was a bare `Promise.resolve()`. Octane's
`use()` tags an untagged thenable `'pending'` synchronously (its fulfillment
callback runs a microtask later), so the first `use(SETTLED)` on the ready path
suspended and flashed the Suspense fallback even though data was already ready.

Give `SETTLED` the React 19 `cache()` settled shape (`status: 'fulfilled'`) so
`trackThenable` leaves it untouched and `use()` returns synchronously without
suspending. New regression test preloads a collection to `ready` before mount so
the first render takes the ready path, and asserts the fallback never renders
(fails pre-fix: first commit shows `Loading...` instead of `ready:3`).

Reported by Cursor Bugbot on the previous commit.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(tanstack-db): defer infinite query sync until commit

* fix: repair tanstack db CI integration

* fix: complete tanstack db CI integration

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: Dominic Gannaway <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-authored Diff or issue body substantially produced by an AI agent test PR: tests only

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant