test(router): prove introspection parity after the radix index (CARD-09, #109) #129

Merged
chrnx merged 1 commits from feature/fprd-001b-introspection-parity into develop 2026-10-12 20:12:27 +00:00
Owner

Closes the CARD-09 acceptance check (FPRD-001b, #109): route introspection is unchanged after the radix index from #128. Tests only; src/ is untouched and no file under test/router-parity/ was edited.

What the frozen CARD-08 corpus already covers

All in test/router-parity/introspection.test.ts, against goldens captured at ed47836:

Criterion / test case Evidence
graph().routes content and order (method, transport, pattern, chain), declaration order not specificity order golden-graph.json, test "graph() equals the golden"
explain() success for declared patterns (incl. WS and catch-all) golden-explain.json
explain() no route: <pattern> error golden-explain.json (/api/missing, /api/items)
Concrete request path is not a declaration lookup golden-explain.json (/api/items/42 throws)
Duplicate pattern under several methods: first declaration wins golden-explain.json (/api/items/:id(\d+) under GET/HEAD/OPTIONS/DELETE gives GET)
openapi() paths, operations, parameters, schema, key order, WS excluded golden-openapi.json (/api/live/:room absent)
Mesh: pre-ready graph()/explain() error, openapi() before ready golden-mesh.json before
Mesh: post-ready introspection, remote routes absent from routePlans but served golden-mesh.json after, explainRemote, lookup

What this PR adds

test/router-introspection-parity.test.ts and test/fixtures/router-introspection-ed47836.json:

Gap Test
Duplicate pattern where a non-GET is declared first (DELETE before GET at /v1/docs/:id), for explain() and inspect() captured fixture + "explain() and inspect() take the first declaration..."
Dev endpoints /__graph__ (HTML and text/plain Mermaid) and /__openapi__ when enabled, on app.fetch and on a Node listener captured fixture (local.fetchDev, local.nodeDev)
Dev endpoints agree with the direct API (openapi(), toMermaid(graph()), graphHtml(graph())) "dev endpoints agree with the direct API on app.fetch"
Mesh teacup: dev endpoints after ready() agree with the direct API; inspect() pre-ready error; remote route served but absent from graph/OpenAPI captured fixture (mesh.*) + "...on a mesh teacup after ready()"
Introspection does not depend on the radix index "introspection never consults the lookup index...": the router lookup entry points (matchRoute, resolveRoute, allowedMethods) are wrapped with a call counter via vi.mock; graph/explain/inspect/toMermaid/openapi make zero lookup calls, give identical output before and after requests build the index, and list routes in declaration order (remove, rest, get, latest, events, live) while the index answers GET /v1/docs/latest with the later-declared static route and GET /v1/docs/7 with get over the earlier catch-all

How expectations were captured

The new test file was copied into a temporary detached git worktree of ed47836c9820c47bf4ed5e902d91e019abdb110a (the CARD-08 pinned revision, pre-radix router) and run there with INTROSPECTION_PARITY_CAPTURE=<out.json>. The output was committed as test/fixtures/router-introspection-ed47836.json, which records that revision and is checked by the test. The temporary worktree was removed. Nothing was generated from the radix implementation. A capture from cb123e3 was byte-identical to the ed47836 one.

A sanity check (swapping two routes in the fixture locally) made the test fail as expected; the fixture was restored from the ed47836 capture.

Compatibility differences

None found.

Gates

  • npm run lint: 0 errors (50 pre-existing no-explicit-any warnings in src/); the new test file is also eslint-clean
  • npm run format:check: pass; prettier --check on the new files: pass
  • npm run build, then npm run typecheck: pass
  • npm test: 89 files, 818 tests pass
  • npm run test:deno: 36 passed; npm run test:bun: 26 pass; npm run test:edge: PASS (incl. 1158 matcher + 55 app.fetch parity cases)
  • npm run parity:mutants: 21/21 killed
  • npm run complexity:check: pass
  • npm audit --audit-level=moderate: 0 vulnerabilities

Deviations

  • The new tests also cover inspect() and toMermaid(), which read routePlans too, though the card names only graph/explain/OpenAPI.
  • Graph HTML from /__graph__ is compared by SHA-256 rather than stored in full, since it embeds a large inline SVG.
  • No Matcha-facing comparison: Matcha does not consume these outputs in core, so none was invented (as the card allows).
Closes the CARD-09 acceptance check (FPRD-001b, #109): route introspection is unchanged after the radix index from #128. Tests only; `src/` is untouched and no file under `test/router-parity/` was edited. ## What the frozen CARD-08 corpus already covers All in `test/router-parity/introspection.test.ts`, against goldens captured at `ed47836`: | Criterion / test case | Evidence | |---|---| | `graph().routes` content and order (method, transport, pattern, chain), declaration order not specificity order | `golden-graph.json`, test "graph() equals the golden" | | `explain()` success for declared patterns (incl. WS and catch-all) | `golden-explain.json` | | `explain()` `no route: <pattern>` error | `golden-explain.json` (`/api/missing`, `/api/items`) | | Concrete request path is not a declaration lookup | `golden-explain.json` (`/api/items/42` throws) | | Duplicate pattern under several methods: first declaration wins | `golden-explain.json` (`/api/items/:id(\d+)` under GET/HEAD/OPTIONS/DELETE gives GET) | | `openapi()` paths, operations, parameters, schema, key order, WS excluded | `golden-openapi.json` (`/api/live/:room` absent) | | Mesh: pre-ready `graph()`/`explain()` error, `openapi()` before ready | `golden-mesh.json` `before` | | Mesh: post-ready introspection, remote routes absent from routePlans but served | `golden-mesh.json` `after`, `explainRemote`, `lookup` | ## What this PR adds `test/router-introspection-parity.test.ts` and `test/fixtures/router-introspection-ed47836.json`: | Gap | Test | |---|---| | Duplicate pattern where a **non-GET** is declared first (`DELETE` before `GET` at `/v1/docs/:id`), for `explain()` and `inspect()` | captured fixture + "explain() and inspect() take the first declaration..." | | Dev endpoints `/__graph__` (HTML and `text/plain` Mermaid) and `/__openapi__` when enabled, on `app.fetch` and on a Node listener | captured fixture (`local.fetchDev`, `local.nodeDev`) | | Dev endpoints agree with the direct API (`openapi()`, `toMermaid(graph())`, `graphHtml(graph())`) | "dev endpoints agree with the direct API on app.fetch" | | Mesh teacup: dev endpoints after `ready()` agree with the direct API; `inspect()` pre-ready error; remote route served but absent from graph/OpenAPI | captured fixture (`mesh.*`) + "...on a mesh teacup after ready()" | | Introspection does not depend on the radix index | "introspection never consults the lookup index...": the router lookup entry points (`matchRoute`, `resolveRoute`, `allowedMethods`) are wrapped with a call counter via `vi.mock`; `graph`/`explain`/`inspect`/`toMermaid`/`openapi` make zero lookup calls, give identical output before and after requests build the index, and list routes in declaration order (`remove, rest, get, latest, events, live`) while the index answers `GET /v1/docs/latest` with the later-declared static route and `GET /v1/docs/7` with `get` over the earlier catch-all | ### How expectations were captured The new test file was copied into a temporary detached `git worktree` of `ed47836c9820c47bf4ed5e902d91e019abdb110a` (the CARD-08 pinned revision, pre-radix router) and run there with `INTROSPECTION_PARITY_CAPTURE=<out.json>`. The output was committed as `test/fixtures/router-introspection-ed47836.json`, which records that revision and is checked by the test. The temporary worktree was removed. Nothing was generated from the radix implementation. A capture from `cb123e3` was byte-identical to the `ed47836` one. A sanity check (swapping two routes in the fixture locally) made the test fail as expected; the fixture was restored from the `ed47836` capture. ## Compatibility differences None found. ## Gates - `npm run lint`: 0 errors (50 pre-existing `no-explicit-any` warnings in `src/`); the new test file is also eslint-clean - `npm run format:check`: pass; prettier `--check` on the new files: pass - `npm run build`, then `npm run typecheck`: pass - `npm test`: 89 files, 818 tests pass - `npm run test:deno`: 36 passed; `npm run test:bun`: 26 pass; `npm run test:edge`: PASS (incl. 1158 matcher + 55 app.fetch parity cases) - `npm run parity:mutants`: 21/21 killed - `npm run complexity:check`: pass - `npm audit --audit-level=moderate`: 0 vulnerabilities ## Deviations - The new tests also cover `inspect()` and `toMermaid()`, which read `routePlans` too, though the card names only graph/explain/OpenAPI. - Graph HTML from `/__graph__` is compared by SHA-256 rather than stored in full, since it embeds a large inline SVG. - No Matcha-facing comparison: Matcha does not consume these outputs in core, so none was invented (as the card allows).
chrnx added 1 commit 2026-10-12 19:00:22 +00:00
test(router): prove introspection parity after the radix index (CARD-09, #109)
CI / dco (pull_request) Successful in 3s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 26s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 15s
fcee6892bf
The frozen CARD-08 goldens already hold graph(), explain(), openapi() and
the mesh teacup. This adds what they do not cover, with expectations
captured from the pre-radix code at ed47836 in a detached checkout:

- explain()/inspect() on a pattern shared by several methods with a
  non-GET declared first, and a concrete path that is not a declaration;
- /__graph__ and /__openapi__ on app.fetch, a Node listener and a mesh
  teacup, and their agreement with the direct API;
- a structural check that graph/explain/inspect/openapi never call the
  router lookup, return the same output before and after the index is
  built, and keep declaration order where the index ranks differently.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx closed this pull request 2026-10-12 20:10:53 +00:00
chrnx deleted branch feature/fprd-001b-introspection-parity 2026-10-12 20:10:54 +00:00
chrnx reopened this pull request 2026-10-12 20:11:00 +00:00
chrnx merged commit 72f591dd21 into develop 2026-10-12 20:12:27 +00:00
Sign in to join this conversation.