Script loading

The golden, dispatch, loop-contract, acceptance, and runtime nets, and how to refresh the goldens

Complementary test nets pin the script-loading subsystem (design, implementation). The fixture-site nets run in npm run test:repo; the browser nets run in npm run test:visual.

Golden net

scripts-golden.test.mjs pins, across fixture configurations:

  • the rendered script region of selected pages, and
  • every locally built script, byte-exact.

Fixture builds, region extraction, and the comparison form live in lib/scripts-goldens.mjs. The net was committed and verified green against untouched main before the scripts.html decomposition, so the refactor’s no-output-change claim is machine-checked, not asserted.

The goldens are committed. After a reviewed, intended output change, refresh them with:

npm run update:scripts-goldens

Dispatch net

scripts-dispatch.test.mjs pins the dispatcher’s page-flag wiring: the .Page.Store-gated partials (Mermaid, KaTeX) are dispatched on flagged pages only. The real partials fetch remote assets at build time, so fixture marker overrides stand in for them; what’s pinned is exactly the gate-to-partial wiring, offline.

Loop-contract tests

plugins.test.mjs pins the plugin loop’s registry contract: emission with @params, enable/defer/pageGate handling, both companions, shape-guard warnings, name coercion and allowlisting, theme-default inheritance, and fingerprint distinctness (distinct builds of one source publish distinct paths, in development too). Companion nets:

Acceptance test

plugins-acceptance.test.mjs proves adoption end to end: a project site drops assets/js/plugins/hello.js plus one registry entry and gets its script loaded, with zero layout overrides asserted structurally (the fixture contains no layouts/ directory).

Runtime nets

Two browser nets under tests/visual/:

  • js-runtime.test.mjs loads representative fixture pages in a real browser and asserts that no uncaught exception or in-scope console error fires, alongside behavior probes (search, diagrams, navbar). Markup and visual goldens can’t see JS runtime breakage (a missing global, a botched conversion); this net can (#1436).
    • Two fixture variants cover both search bundles: the main bundle (scripts/main-bundle.html) concatenates offline-search.js or search.js into main.js, never both.
    • Pages load their real CDN script dependencies, so the net needs network access. The console tally filters off-origin and non-code resource noise but keeps same-origin script and stylesheet load failures (a broken first-party bundle is a defect). Filtered breakage that throws (a dependent script’s missing global) still surfaces as a page error; silent feature degradation is what the behavior probes catch.
  • plugins-runtime.test.mjs proves an emitted plugin actually executes: its options reach the runtime and its DOM effects land. A static-markup check can bless output whose runtime is broken (a botched build); this net can’t.

Red-proof rationale

A net that passes for the wrong reason (building nothing, matching an empty region) is worse than a red one: it hides breakage behind green. The nets were built red-first, and where a no-op could masquerade as success, a persistent safeguard proves the signal:

  • Zero-output cases are asserted against: a golden’s script region must be non-empty.
  • The plugin runtime net’s red-proof doubles as an assertion: a deliberately broken plugin must be the error tally’s only entry, so an empty tally from the healthy plugin is meaningful.
  • The site runtime net carries a collector self-test: a page that deliberately throws and drops a same-origin script must have both reported, so a silent collector (wrong event names, races, a broken filter) can’t masquerade as all-green.