qat

Debug: explain, snapshot, replay, test, explore

A bug in a Qat app goes through four steps, each with its own tool, and every step names things by the same program graph id (src/stores/cart.js#cart.items, src/pages/checkout.qx#Checkout.on:submit<form>):

  1. Explain the element that is wrong, in the devtools panel: which binding, which effect, which signals, who wrote them last.
  2. Snapshot the page: snapshot() is its whole reactive state as JSON, report() adds the errors and the action log.
  3. Replay it: qatjs replay bug.json starts qatjs dev in that state and plays the steps back.
  4. Test it: qatjs replay --to-test writes a Playwright test, qatjs repro a happy-dom test.

The bug you have not seen yet goes the other way round: explore finds it, writes its test, and the replay shows it in the browser (5).

This page walks through all four on examples/shop, with a bug recorded from the shop that is committed to the repository: examples/shop/bugs/cart-checkout.json. The details of each tool are in dev.md.

Setup

shell2 lines
pnpm add -D @qatjs/devtools     # the snapshot, the action log, replay (dev only, never in a build)
qatjs dev --devtools            # the panel, in a drawer at the bottom of every page (Alt+Shift+D)

@qatjs/devtools as a devDependency is enough for qatjs dev to load it before the app. --devtools adds the panel; without it, snapshot(), report() and the action log still work.

1. Explain: start from the element

Open the panel's Explain tab and pick the element that shows the wrong thing (Pick an element, then click it on the page, or type a CSS selector). The panel reads it element-first:

  • the component that rendered it, and the source line;
  • each of its bindings (prop:value, text, class:hot, …) and the effect that wrote it;
  • the signals that effect reads, with their values, subscriber counts and declarations;
  • the derived chain down to the state it comes from;
  • the last writer of each signal, from the action log: the event, its target, and the handler's graph id and source span.

The Explain tab on the shop's product page: the quantity field, its prop:value binding written by an effect of Detail, the Detail.qty state it reads, and its last writer, the input event on input.qty

A disabled button that is bound to a form ends at the failing field: its constraint and the browser's validationMessage. The Stores tab shows the same writes as a log, by handler, with time travel over them and edits that go through a snapshot patch:

The Stores tab after "Add to cart": the cart store's items, count and total, and the action log with the click on button.add and the input on input.qty, each with its handler's graph id

2. Snapshot: the page's state as one JSON file

JavaScript4 lines
import { report, snapshot } from '@qatjs/devtools'

const s = snapshot() // component state, stores, form values, loads, route loads, the router, <Head>
const bug = report() // the snapshot + the last 50 errors + the user agent + the action log (a sequence)

report() is what a bug report should carry. It is redacted, and the redacted ids are listed in redacted. What is left out everywhere (the snapshot, the log, the start state):

  • a store's redact: ['token'] fields and report({ redact }) ids;
  • what is typed into a password field, or a field whose autocomplete is a password, a card (cc-*) or a one-time code, and from then on the state it was written to (a bind:value state too);
  • in the URL and in error messages, the value of a token=, key=, secret=, password=, auth…=, code=, session= or sig…= pair, and a bearer token.

Anything else your app keeps in state goes in as it is: add it to redact.

The shop has a Download report() button at the foot of every page in qatjs dev (you can see it above the drawer in the screenshots). It is a few lines of plain DOM in examples/shop/src/dev/report-button.js, loaded from main.js under import.meta.env.DEV:

JavaScript8 lines
if (import.meta.env.DEV) import('./dev/report-button.js').then((m) => m.mountReportButton())

// src/dev/report-button.js, on click:
const { report } = await import('@qatjs/devtools')
const a = document.createElement('a')
a.href = URL.createObjectURL(new Blob([JSON.stringify(report(), null, 2)], { type: 'application/json' }))
a.download = 'qat-report.json'
a.click()

qatjs compress replaces import.meta.env.DEV with false and drops the branch, the module and @qatjs/devtools with it: a build has no trace of the button (a test greps dist/ for it). In production, report() needs a recording build: qatjs compress --report.

The recorded bug

examples/shop/bugs/cart-checkout.json was recorded by examples/shop/bugs/record.mjs: a Playwright session against qatjs dev that clicks the shop's own button. It is a real report():

step event target handler writes
1 input 2 input.qty Detail.bind:value<input> Detail.qty = 2
2 click button.add Detail.on:click<button> cart.items = [Kettle × 2]
3 click a.cart-link (the router) router = /cart
4 click a.btn (Checkout) (the router) router = /checkout
5–7 input the email, name and ZIP fields (the form's fields) Checkout.f.email, .name, .zip
8 submit form.checkout Checkout.on:submit<form> after await api.order(…): cart.items = [], router = /done (async: true)

Its start state (sequence.start) was taken before the first event, on /products/1: it holds the two route loads (src/routes.js#/products/:id and src/routes.js#layout:/products) and two keyed loads (the reviews, ["reviews","1"], and the live stock, ["stock","1"]), so a replay renders the page without a request. Step 8's writes happen after an await; each await carries its event, so they are logged under the submit.

It holds nothing sensitive: example data only (ada@example.com is an RFC 2606 address), no password field, no order id (the order lives in sessionStorage, not in a signal), and the browser's version is stripped by the recording script. A test checks each of these.

3. Replay: back into a running app

shell1 line
qatjs replay examples/shop/bugs/cart-checkout.json examples/shop

starts qatjs dev with the page in the bug's start state and plays the eight steps with their recorded timing, pausing on the first error that reaches onError. The restore makes no API call: every load whose value the snapshot holds (route loads, keyed and keyless loads) is answered from it while the restore runs; after it, loads request as usual. A snapshot() file (no action log) just starts every page in that state.

4. Test: keep the bug fixed

shell4 lines
qatjs replay examples/shop/bugs/cart-checkout.json examples/shop --to-test
#   tests/replay/cart-checkout.spec.ts: a Playwright test of the same steps
qatjs repro examples/shop/bugs/cart-checkout.json examples/shop
#   tests/repro/1.test.ts: the replay in happy-dom (Vitest), no browser
  • --to-test replays headless, then writes the steps as Playwright actions and asserts only the nodes the handlers' write sets reach in the graph. For this bug, that is the header's cart link, its text and its href (qatjs replay … --to-test, 2026-11-07: 8 steps, 2 assertions): await expect(page.locator("a.cart-link")).toHaveText("Cart (0)") and toHaveAttribute("href", "/cart"). Run it against qatjs dev (the page needs @qatjs/devtools to start in the recorded state).
  • qatjs repro bundles the app as a recording build, replays the report in happy-dom and compares the signals' final values with sequence.expect, by graph id. A signal whose component is gone by the end (the checkout form, after the navigation to /done) is compared by the last value the replay wrote to it.

Both files start with a REVIEW: line: they are a starting point, to be read before being trusted. The repository runs both on the committed bug (packages/toolchain/test/devtools-shop.test.ts and devtools-build.test.ts), and checks that its restore makes no request.

5. Explore: the bug before anyone records it

The four steps start from a bug someone saw. qatjs check --explore starts from a rule (invariant(), see testing) and searches the event orders that break it. The loop has three steps:

shell6 lines
qatjs check --explore examples/shop
#   src/pages/checkout.qx:36:1 error QX-INVARIANT-VIOLATED 'one order at a time' breaks after … → submit form.checkout → submit form.checkout
#   test: tests/explore/checkout-1.test.ts
qatjs test examples/shop
#   × Checkout: one order at a time          (red until the fix)
qatjs replay examples/shop/tests/explore/checkout-1.json examples/shop
  1. Explore: the finding is the shortest sequence that breaks the rule, with the step it broke at, the signals that changed and since which step, what was waiting, and the fix of a known pattern. It names its signals by the same graph ids as the four steps above (Checkout.placing).
  2. Test: tests/explore/checkout-1.test.ts replays the exact sequence in happy-dom, with each answer in the order the explorer found: red while the bug is there, green once it is fixed. A step the fixed page no longer offers (the second submit, now ignored) is skipped, not an error.
  3. Replay: checkout-1.json is the sequence (v1). qatjs replay plays its user steps in the running app, where the answers come from the app's own backend, in the order they arrive. The exact order of the answers is the test's to reproduce.

For the shop, this is how the checkout's double order was found and fixed: Enter in a field submitted the form while the order was out, with the button disabled.

The devtools' cost in dev

What @qatjs/devtools (the action log and the per-await attribution) and qatjs dev --devtools (the agent, and the drawer closed or open) add to qatjs dev, against qatjs dev without either. Two pages: the shop's /products/1 (88 elements) and a heavy page, a route of the generated scale app that renders all 300 of its components (7,432 elements). Medians of 7 interleaved runs, each in a fresh browser context, Apple M3 Pro, Chrome 157, by node benchmarks/devtools/run.mjs --runs 7 --label phase-14 (benchmarks/devtools/results/phase-14.json, 2026-11-07). The machine was busy: load average 2.9 at the start, 2.3 at the end.

page configuration content rendered blocking (> 50 ms) per event (sync) heap after load heap after 200 rounds
shop none 208.2 ms 0 ms 0.072 ms 1.88 MB 2.08 MB
shop @qatjs/devtools 204.4 ms 0 ms 0.105 ms 1.96 MB 2.34 MB
shop --devtools, closed 210.5 ms 0 ms 0.111 ms 2.07 MB 2.53 MB
shop --devtools, open 212.1 ms 0 ms 0.144 ms 2.96 MB 3.45 MB
heavy none 213.0 ms 40 ms 0.080 ms 11.12 MB 11.91 MB
heavy @qatjs/devtools 244.3 ms (+15 %) 49 ms 0.116 ms 13.48 MB 14.77 MB
heavy --devtools, closed 231.0 ms (+8 %) 49 ms 0.130 ms 14.78 MB 16.12 MB
heavy --devtools, open 246.9 ms (+16 %) 48 ms 0.140 ms 18.47 MB 19.72 MB

"Content rendered" is navigation start to the page's content in the DOM (the shop's includes its fake API's 150 ms latency). "Per event" is the mean synchronous time of dispatching one event of a real interaction loop (the shop: type a quantity, add to cart; the heavy page: its counter, opening or closing a component, typing in its filter): the capture listeners, the handler, the writes, the DOM updates and the logging. The --devtools rows include @qatjs/devtools (the shop has it).

Per call (µs, the shop page; the agent wraps these only with --devtools, closed–open):

none @qatjs/devtools --devtools
addEventListener + removeEventListener 0.15 0.17 0.34–0.45
… inside an owner (mount, effect) 0.15 0.16 0.73–0.84
setTimeout + clearTimeout 0.62 0.67 0.62–0.66
… inside an owner 0.57 0.61 1.08–1.09
await in an event handler, as compiled in dev (hot.w(hot.k(), await x)) 0.06 0.40 0.30–0.32
a plain await, for comparison 0.02 0.04 0.02

snapshot() takes 0.2–0.3 ms and report() 0.9–1.2 ms on the shop.

What this says:

  • Load: nothing measurable on the shop; on the heavy page, 8 % (the agent, drawer closed) to 16 % (the drawer open, whose panel and graph load after the page's content). With 7 runs on a busy machine, the closed agent measuring faster than @qatjs/devtools alone is noise.
  • The per-await attribution costs about 0.3 µs per await (hot.w/hot.k): nothing a handler notices. The wrapped listeners and timers cost 0.2–0.7 µs per call.
  • Interaction latency: @qatjs/devtools adds about 0.035 ms per event, on the shop and on the heavy page alike (+45 %); the agent and the open drawer add up to 0.04 ms more. It used to be 0.18 ms on the heavy page: each user event's target got a unique CSS selector when the event began, one document.querySelectorAll per ancestor (benchmarks/devtools/results/phase-8-profile.txt). Now only the target's own part is taken then, and the full selector when the log is first read.
  • Memory: @qatjs/devtools adds 2.4 MB on the heavy page (its registry of every state, handler and bound node), the agent 1.3 MB more, the open panel 3.7 MB more. On the shop, under 1.4 MB in all.
  • Without @qatjs/devtools, the dev client queues its registrations only until the page has loaded (at most 10,000), then drops the queue and stops: nothing is left queued after the heavy page's 200 rounds.
shell2 lines
node benchmarks/devtools/run.mjs --runs 7 --label phase-14  # → benchmarks/devtools/results/phase-14.json
node benchmarks/devtools/profile.mjs package                # where the per-event time goes

On Windows

Windows has jobs in CI (.github/workflows/ci.yml): a check job (build, typecheck, lint, test, size), a smoke job (qatjs dev, one transform, HMR, qatjs compress of the shop, the language server suite) and the VS Code extension build. In the last full run (2026-11-01, run 41326219255) the extension build and the deterministic-build job passed on Windows; the unit tests failed there as on Linux, and the smoke job failed at the language server suite. Paths are handled for it everywhere: every text file is LF, inside-root checks use path.relative, scripts use fileURLToPath, and the path helpers are tested with path.win32.

Not yet verified on a Windows runner (open until a run passes): the full unit suite, the fs.watch timing that HMR depends on, VS Code's language-server URIs, long pnpm paths and imports that differ only in case. The devtools, qatjs replay and qatjs repro are among what the full suite covers, so on Windows they are expected, not proven, to work.

qatjs check --json for tools

The bug-to-test tools above are for people; agents and CI read diagnostics as JSON:

shell2 lines
qatjs check --json     # { "$schema": "https://qat.dev/schema/check/v1.json", "version": 1, "diagnostics": [...] }
qatjs check --json=0   # the bare diagnostics array of 0.9.0-rc.1 and before, with a deprecation notice

The envelope is how Qat's JSON outputs carry their schema and version: $schema plus version: 1 (check, explain, unused, policy and the files of compress). Two outputs are older and still say { "schema": 1, … } instead: qatjs check --explore --json and qatjs check --impact --json (testing.md). Each diagnostic is { file, line, col, code, severity, message, fix? }. --json=0 is deprecated: it prints the v0 array through 0.9.x and is removed in 0.10.0, the first entry of the upgrade ledger (@qatjs/toolchain/upgrade-ledger.json). readManifest(json, 'check') from @qatjs/schemas reads both shapes.