Skip to content

Run oracles in a real browser (Vitest browser mode) #49

Open

Description

@KyleAMathews

Problem

An oracle for DOM code must run in jsdom today, so its driver supplies the
browser facts that jsdom lacks: layout, scroll positions, the targets where
scroll events fire, ResizeObserver notifications, and computed styles. When
the driver's stand-in and production rest on the same wrong belief about the
browser, the oracle passes, and only a human or a real browser finds the bug.

We hit this three times in one pull request (react-headroom):

  • The stand-in notified a ResizeObserver on any size change. Chrome notifies
    a content-box observer only when the content box changes, so a header that
    changes only its padding kept a stale height.
  • The stand-in decided that a body with overflow-y: auto scrolls itself.
    With html { overflow-y: scroll } body { overflow-x: hidden }, Chrome
    computes the body's overflow-y as auto, but the body grows with its
    content and the page scrolls.
  • The stand-in gave a body the viewport's height. In Chrome, a body that does
    not scroll itself grows with the page.

We checked each fact by hand in headless Chrome. An oracle that runs in
Chrome would have checked them on every run.

What stops it at 4749f61

  1. oracleProperty imports node:async_hooks (AsyncLocalStorage for probe
    windows), node:fs (appendFileSync) and node:util (inspect,
    isDeepStrictEqual, types). In Vitest browser mode the test file fails
    to import: AsyncLocalStorage is not a constructor.
  2. The gap check's setup file (oracle-gaps/capture-setup.mjs) reads its run
    state from process.env.ORACLE_GAPS_STATE with readFileSync. In browser
    mode, setup files run in the page.

Request

  • Let oracleProperty and useOracleClock run in Vitest browser mode, for
    example with a browser-safe entry that replaces AsyncLocalStorage, fs
    and util with browser equivalents or leaves those features out.
  • Let oracle-gaps run an oracle in browser mode, or document that it cannot,
    and recommend a pattern: for example, an oracle that runs in Chrome for its
    laws, and the same oracle in jsdom for the gap check.

Workaround we considered

Keep the oracle in Node and drive a Chrome page through Playwright: the
driver sends each history to the page, which runs it against a bundle of
production and returns the observations. This needs a page bundle, a
page-side clock in place of useOracleClock, and two copies of the driver
environment. The gap check still cannot mutate the code in the page.

Activity

  1. KyleAMathews commented on Nov 12, 2026

    @KyleAMathews
    ContributorAuthor

    Triage: this is a valid gap. A stand-in for a browser fact and the production code can rest on the same wrong belief, and only a real browser can check that fact. We will add browser support in two phases.

    What blocks browser mode at cc7bf09

    All the Node-only code is in src/oracle-property.ts, plus one appendFileSync in src/oracle-replay-witness.ts.

    Node API Use Browser replacement
    AsyncLocalStorage probe windows A current-window global. Histories run one at a time, so this is sound except for concurrent async work inside one history. That case becomes a stated limit.
    isDeepStrictEqual comparison outside the data domain A portable deep equality, in the browser build only. Node comparisons do not change.
    types.isProxy the value-domain check None. A browser cannot detect a proxy, so this becomes a stated limit.
    types.isMap, isSet, isNativeError the value-domain check instanceof and Object.prototype.toString checks
    inspect failure messages A small formatter
    appendFileSync, process.env.ORACLE_MANIFEST, process.stdout.write manifests, replay witnesses, reach lines Vitest browser commands (commands from @vitest/browser/context), which run on the Node side

    Plan

    Phase 1: oracleProperty and useOracleClock run in Vitest browser mode.

    • The replacements above ship under a browser export condition, so Node behavior does not change.
    • The framework self-oracle gets a headless-Chromium job.
    • A differential law requires the same verdicts in Node and in the browser for the same histories, except for the stated limits.

    Phase 2: oracle-gaps mutates code that runs in the page. Vitest browser mode serves the test file and the production code through Vite, and the gap CLI already instruments code through Vite. So mutants can reach the page. The run state and the captured observations then go through browser commands instead of fs and process.env. Phase 2 needs a design of its own, which comes first.

    Until then

    • For the laws: keep the oracle in Node and drive a page with Playwright, as the workaround describes. Playwright's page.clock can take the place of useOracleClock in the page. Send the whole history to a runner in the page, rather than making one round trip per step.
    • For the gap check: run the same oracle in jsdom. That check cannot see a defect in a stand-in for a browser fact, which is the defect class of this issue. Phase 2 closes that gap.

    This comment was written by Isaac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions