test(router): freeze radix-router parity corpus and baseline (CARD-08, #109) #123

Merged
chrnx merged 11 commits from feature/fprd-001b-router-corpus into develop 2026-10-11 17:23:56 +00:00
Owner

Freezes the radix-router compatibility baseline (FPRD-001 CARD-08) before any router code changes. Test and bench files only: src/ is byte-identical to ed47836. Refs #109.

Pinned revision

ed47836c9820c47bf4ed5e902d91e019abdb110a (develop after #117 and #122), not ROUTER-CORPUS's 42376c6. src/http/router.ts is unchanged between the two. #117 changed the WS upgrade paths, so everything was captured from ed47836. The revision is recorded in manifest.json, frozen.ts and every frozen file, and each file's revision is asserted.

What is frozen, and where

All under test/router-parity/ unless noted. The rule is in its README.md: the baseline stays immutable through CARD-07 review, and a deliberate compatibility change needs its own approval, not an edited golden.

Set Size
Retained existing tests (manifest.json, checked by manifest.test.ts) 8 files/groups + runtime smoke
Oracle (oracle.ts, verbatim copy at ed47836, never imported by src/) matchRoute, resolveRoute, allowedMethods, normalizeRequestPath, compilePattern, matchWsRoute
Hand-picked matcher scenarios 24 scenarios, 129 requests
Owner-requested matcher scenarios: backtracking, cross-pattern Allow, encoded slash, zero-segment catch-all 9 scenarios, 45 requests
Generated v1, seed 10908 40 scenarios, 211 declarations, 480 requests
Generated v2, seed 10908, forced shared-prefix siblings 40 scenarios, 238 declarations, 480 requests; 71.9% reach sibling branches and 67.3% backtrack (v1: 36.5% / 26.7%)
WS matcher 3 scenarios, 24 lookups
App level via app.fetch and a Node socket (status, headers, Allow, HEAD body) 45 requests per adapter, plus 10 owner cross-pattern Allow requests per adapter
WS upgrades via app.upgrade and the Node listener 12 paths, plus 5 HTTP requests at WS paths
Boot errors 26 patterns, 18 createApp cases (14 rejections, 4 accepted controls), 5 mesh splice cases
Mesh route table across a peer's lifetime 16 probes over 4 phases
Mesh local + remote on one path (CARD-07's two-tree design): Allow union, cross-tree precedence, remote implicit HEAD 18 requests per adapter (app.fetch and Node)
Introspection goldens graph(); explain() for 7 patterns (4 declared, 3 no route:); openapi({ title: 'Parity', version: '1' }); mesh teacup before and after ready()

Re-capturing cannot happen by accident. vitest -u is refused with an explicit message. ROUTER_PARITY_CAPTURE=1 only writes a frozen file that is missing and never overwrites one.

How the oracle comparison works

Every matcher scenario runs through both the oracle and the live src/http/router exports, and both must equal the frozen capture. Each run gets fresh RouteDef objects. Answers are compared by declaration ID (never by pattern text), plus decoded params, implicitHead, ordered Allow, or the normalization error, with key and array order held. When CARD-07 swaps the internals behind the same exports, the same tests compare oracle against radix with no edit.

Mutation check (npm run parity:mutants, not part of npm test)

12 targeted mutants are applied to a temporary copy of src/, one at a time, and the parity suite runs against each. The real src/ is never written; the run ends with git diff --exit-code src.

Mutant (models) Result Failing tests
no backtracking to a param branch killed 35
static/param precedence swapped killed 18
equal-rank tie broken by last-registered killed 15
constraint ignored killed 71
decode before splitting (%2F) killed 8
catch-all needs a segment killed 38
implicit HEAD from a streaming GET killed 21
Allow from one pattern only killed 52
Allow in discovery order killed 49
trailing slash not normalized killed 74
WS ranked like HTTP killed 4
case-insensitive static match killed 5

12 of 12 were killed on the first pass, so no case had to be added; the "before" and "after" tables are identical. Re-run after the mesh local/remote cases: still 12 of 12.

Differential on every runtime

The matcher comparison and the app.fetch fixtures live in runtime-neutral modules (differential.ts, app-fixture.ts).

Runtime Matcher (oracle and live, 1158 cases) app.fetch (55 cases) Where
Node 22 (vitest) pass pass macOS arm64 and jarvis Linux x86_64
Deno 2.9.7 pass pass test/deno/router-parity.test.ts; macOS and denoland/deno:2.9.7 on jarvis
Bun 1.3.14 pass pass test/bun/router-parity.test.ts; macOS and oven/bun:1.3.14 on jarvis
workerd (Miniflare) pass pass test/edge/parity-worker.ts via test/edge/run.ts; macOS and node:22 on jarvis

The Node-socket, WS-upgrade, boot, mesh and introspection captures stay Node-only: they need http.request, the ws client, or a mesh peer on a port.

Baseline: jarvis, interleaved harness

bench:lookup now loads both routers into one process. In each cell it warms each router, then takes 21 rounds of one sample per router, alternating AB / BA. This repeats over 4 fresh processes with alternating module import order, giving 84 paired rounds per cell. It reports the median B/A ratio with a percentile-bootstrap 95% CI.

The baseline is the A/A run: the live matcher as A and the byte-identical oracle as B. Setup:

  • jarvis, Ryzen 7 3700X, --cpuset-cpus 6,7,14,15 (two idle physical cores and their SMT siblings);
  • node:22 container, Node 22.23.1, kernel 6.8.0-138, Docker 29.1.3;
  • load average 0.27 → 0.79, no CI job running, power N/A.

Full environment record in bench/baseline/router-ed47836/README.md; the laptop battery run is kept in battery-run/.

Live linear matcher

Routes Workload live median ns run medians (ns) run spread
10 static hit 185.3 156.1 / 187.7 / 174.1 / 194.2 20.5%
10 late param hit 328.4 311.9 / 336.2 / 323.0 / 342.4 9.3%
10 method miss 800.4 762.6 / 801.2 / 798.6 / 804.4 5.2%
10 path miss 625.5 594.6 / 631.3 / 620.3 / 628.1 5.9%
100 static hit 201.2 202.2 / 200.8 / 197.6 / 207.2 4.8%
100 late param hit 878.0 861.1 / 857.0 / 907.3 / 880.5 5.7%
100 method miss 2,525 2,424 / 2,514 / 2,580 / 2,531 6.2%
100 path miss 3,054 2,965 / 3,024 / 3,114 / 3,071 4.9%
500 static hit 202.2 201.8 / 202.3 / 195.1 / 210.3 7.5%
500 late param hit 2,931 2,830 / 2,804 / 2,980 / 3,016 7.2%
500 method miss 11,904 11,635 / 11,518 / 11,946 / 12,031 4.3%
500 path miss 15,514 15,103 / 14,972 / 15,665 / 16,034 6.8%

A/A noise floor (identical code)

Routes Workload oracle / live median 95% CI
10 static hit 0.9507 (-4.9%) -13.7% … +11.9%
10 late param hit 1.0415 (+4.1%) -1.6% … +9.8%
10 method miss 0.9809 (-1.9%) -4.4% … +0.8%
10 path miss 0.9919 (-0.8%) -3.2% … +1.4%
100 static hit 1.0082 (+0.8%) -1.9% … +4.5%
100 late param hit 1.0247 (+2.5%) +1.9% … +2.9%
100 method miss 1.0055 (+0.6%) +0.3% … +0.7%
100 path miss 1.0165 (+1.7%) +1.2% … +1.9%
500 static hit 1.0107 (+1.1%) -2.2% … +4.5%
500 late param hit 0.9838 (-1.6%) -2.2% … +0.8%
500 method miss 1.0197 (+2.0%) +1.6% … +2.3%
500 path miss 1.0161 (+1.6%) +0.5% … +2.6%

Awaiting owner decision

  • D4. In-process, the module imported first runs about 20% faster on the cheapest cell. At 10-route static hit the per-run medians swap from 156 vs 200 ns to 188 vs 162 ns when the import order swaps. Alternating the order removes that from the median but leaves the cell's 95% CI at −13.7 … +11.9%, so a ≤5% regression limit cannot be resolved there with this method and sample size. The other 10-route cells' CIs are within about ±10% (the misses within ±4.4%). At 100 and 500 routes, identical code shows small systematic offsets of up to +2.9%. The ≥20% improvement target at 500 routes is far outside the noise. The options are to apply the 10-route limit to the miss and late-parameter cells only, to require more rounds for the static cell, or to restate the limit against this measured floor.
  • D5. Accountable corpus owner and approval of this corpus, including the deviations below and the three supplementary manifest entries.

Deviations from ROUTER-CORPUS

  • The pinned revision is ed47836, not 42376c6.
  • Three tests are proposed as supplementary manifest entries, pending D5: ws-upgrade-reject.test.ts, mesh/control-upgrade.test.ts, and the mesh control over app.upgrade group.
  • WS paths do go through HTTP normalization since #117; CARD-08's note saying otherwise is out of date.
  • The adapters disagree in one place, frozen as observed: a user @Ws('/__mesh__/control') on an app without mesh is refused by app.upgrade (1008) but served by the Node listener.
  • The mesh HTTP route table is built once at boot. A departed peer keeps its routes (hit → 503, Allow unchanged); a late peer is never spliced in (404). Route removal is not supported, and this is captured as such.
  • A constraint cannot contain / (:id([a-z/]+) is rejected as malformed constraint); the encoded-slash case uses \S+.
  • Finding (mesh proxy, not the matcher): a remote GET with no local route advertises HEAD in Allow/OPTIONS, but HEAD answers 404. The teacup resolves HEAD to the remote GET implicitly, forwards the request as HEAD, and the teapot looks up (pattern, HEAD) and finds no plan. This is frozen as observed; fixing it is a separate decision.
  • TRACE cannot be built with new Request, so app-level tests use PURGE.
  • The bench:compare end-to-end run (A/A, all cases within ±1.9%) is from the laptop on battery and lives in battery-run/. It was not repeated on jarvis.

Gates

On macOS arm64: lint, format:check, typecheck, typecheck:bench, complexity:check, build, npm test (87 files, 801 tests), test:deno (36), test:bun (26) and test:edge (including the parity phase) all pass. git diff ed47836 -- src is empty. npm audit --audit-level=moderate: 0 vulnerabilities. The open Dependabot alerts on the GitHub mirror are for main before #122, and every package involved is already patched in this lockfile.

Freezes the radix-router compatibility baseline (FPRD-001 CARD-08) before any router code changes. **Test and bench files only: `src/` is byte-identical to `ed47836`.** Refs #109. ## Pinned revision `ed47836c9820c47bf4ed5e902d91e019abdb110a` (develop after #117 and #122), not ROUTER-CORPUS's `42376c6`. `src/http/router.ts` is unchanged between the two. #117 changed the WS upgrade paths, so everything was captured from `ed47836`. The revision is recorded in `manifest.json`, `frozen.ts` and every frozen file, and each file's revision is asserted. ## What is frozen, and where All under `test/router-parity/` unless noted. The rule is in its `README.md`: the baseline stays immutable through CARD-07 review, and a deliberate compatibility change needs its own approval, not an edited golden. | Set | Size | |---|---| | Retained existing tests (`manifest.json`, checked by `manifest.test.ts`) | 8 files/groups + runtime smoke | | Oracle (`oracle.ts`, verbatim copy at `ed47836`, never imported by `src/`) | `matchRoute`, `resolveRoute`, `allowedMethods`, `normalizeRequestPath`, `compilePattern`, `matchWsRoute` | | Hand-picked matcher scenarios | 24 scenarios, 129 requests | | Owner-requested matcher scenarios: backtracking, cross-pattern `Allow`, encoded slash, zero-segment catch-all | 9 scenarios, 45 requests | | Generated v1, seed 10908 | 40 scenarios, 211 declarations, 480 requests | | Generated v2, seed 10908, forced shared-prefix siblings | 40 scenarios, 238 declarations, 480 requests; 71.9% reach sibling branches and 67.3% backtrack (v1: 36.5% / 26.7%) | | WS matcher | 3 scenarios, 24 lookups | | App level via `app.fetch` and a Node socket (status, headers, `Allow`, HEAD body) | 45 requests per adapter, plus 10 owner cross-pattern `Allow` requests per adapter | | WS upgrades via `app.upgrade` and the Node listener | 12 paths, plus 5 HTTP requests at WS paths | | Boot errors | 26 patterns, 18 `createApp` cases (14 rejections, 4 accepted controls), 5 mesh splice cases | | Mesh route table across a peer's lifetime | 16 probes over 4 phases | | Mesh local + remote on one path (CARD-07's two-tree design): `Allow` union, cross-tree precedence, remote implicit HEAD | 18 requests per adapter (`app.fetch` and Node) | | Introspection goldens | `graph()`; `explain()` for 7 patterns (4 declared, 3 `no route:`); `openapi({ title: 'Parity', version: '1' })`; mesh teacup before and after `ready()` | Re-capturing cannot happen by accident. `vitest -u` is refused with an explicit message. `ROUTER_PARITY_CAPTURE=1` only writes a frozen file that is missing and never overwrites one. ## How the oracle comparison works Every matcher scenario runs through both the oracle and the live `src/http/router` exports, and both must equal the frozen capture. Each run gets fresh `RouteDef` objects. Answers are compared by declaration ID (never by pattern text), plus decoded params, `implicitHead`, ordered `Allow`, or the normalization error, with key and array order held. When CARD-07 swaps the internals behind the same exports, the same tests compare oracle against radix with no edit. ## Mutation check (`npm run parity:mutants`, not part of `npm test`) 12 targeted mutants are applied to a temporary copy of `src/`, one at a time, and the parity suite runs against each. The real `src/` is never written; the run ends with `git diff --exit-code src`. | Mutant (models) | Result | Failing tests | |---|---|---:| | no backtracking to a param branch | killed | 35 | | static/param precedence swapped | killed | 18 | | equal-rank tie broken by last-registered | killed | 15 | | constraint ignored | killed | 71 | | decode before splitting (`%2F`) | killed | 8 | | catch-all needs a segment | killed | 38 | | implicit HEAD from a streaming GET | killed | 21 | | `Allow` from one pattern only | killed | 52 | | `Allow` in discovery order | killed | 49 | | trailing slash not normalized | killed | 74 | | WS ranked like HTTP | killed | 4 | | case-insensitive static match | killed | 5 | 12 of 12 were killed on the first pass, so no case had to be added; the "before" and "after" tables are identical. Re-run after the mesh local/remote cases: still 12 of 12. ## Differential on every runtime The matcher comparison and the `app.fetch` fixtures live in runtime-neutral modules (`differential.ts`, `app-fixture.ts`). | Runtime | Matcher (oracle and live, 1158 cases) | `app.fetch` (55 cases) | Where | |---|---|---|---| | Node 22 (vitest) | pass | pass | macOS arm64 and jarvis Linux x86_64 | | Deno 2.9.7 | pass | pass | `test/deno/router-parity.test.ts`; macOS and `denoland/deno:2.9.7` on jarvis | | Bun 1.3.14 | pass | pass | `test/bun/router-parity.test.ts`; macOS and `oven/bun:1.3.14` on jarvis | | workerd (Miniflare) | pass | pass | `test/edge/parity-worker.ts` via `test/edge/run.ts`; macOS and `node:22` on jarvis | The Node-socket, WS-upgrade, boot, mesh and introspection captures stay Node-only: they need `http.request`, the `ws` client, or a mesh peer on a port. ## Baseline: jarvis, interleaved harness `bench:lookup` now loads both routers into one process. In each cell it warms each router, then takes 21 rounds of one sample per router, alternating AB / BA. This repeats over 4 fresh processes with alternating module import order, giving 84 paired rounds per cell. It reports the median B/A ratio with a percentile-bootstrap 95% CI. The baseline is the A/A run: the live matcher as A and the byte-identical oracle as B. Setup: - jarvis, Ryzen 7 3700X, `--cpuset-cpus 6,7,14,15` (two idle physical cores and their SMT siblings); - `node:22` container, Node 22.23.1, kernel 6.8.0-138, Docker 29.1.3; - load average 0.27 → 0.79, no CI job running, power N/A. Full environment record in `bench/baseline/router-ed47836/README.md`; the laptop battery run is kept in `battery-run/`. ### Live linear matcher | Routes | Workload | live median ns | run medians (ns) | run spread | |---:|---|---:|---|---:| | 10 | static hit | 185.3 | 156.1 / 187.7 / 174.1 / 194.2 | 20.5% | | 10 | late param hit | 328.4 | 311.9 / 336.2 / 323.0 / 342.4 | 9.3% | | 10 | method miss | 800.4 | 762.6 / 801.2 / 798.6 / 804.4 | 5.2% | | 10 | path miss | 625.5 | 594.6 / 631.3 / 620.3 / 628.1 | 5.9% | | 100 | static hit | 201.2 | 202.2 / 200.8 / 197.6 / 207.2 | 4.8% | | 100 | late param hit | 878.0 | 861.1 / 857.0 / 907.3 / 880.5 | 5.7% | | 100 | method miss | 2,525 | 2,424 / 2,514 / 2,580 / 2,531 | 6.2% | | 100 | path miss | 3,054 | 2,965 / 3,024 / 3,114 / 3,071 | 4.9% | | 500 | static hit | 202.2 | 201.8 / 202.3 / 195.1 / 210.3 | 7.5% | | 500 | late param hit | 2,931 | 2,830 / 2,804 / 2,980 / 3,016 | 7.2% | | 500 | method miss | 11,904 | 11,635 / 11,518 / 11,946 / 12,031 | 4.3% | | 500 | path miss | 15,514 | 15,103 / 14,972 / 15,665 / 16,034 | 6.8% | ### A/A noise floor (identical code) | Routes | Workload | oracle / live median | 95% CI | |---:|---|---:|---| | 10 | static hit | 0.9507 (-4.9%) | -13.7% … +11.9% | | 10 | late param hit | 1.0415 (+4.1%) | -1.6% … +9.8% | | 10 | method miss | 0.9809 (-1.9%) | -4.4% … +0.8% | | 10 | path miss | 0.9919 (-0.8%) | -3.2% … +1.4% | | 100 | static hit | 1.0082 (+0.8%) | -1.9% … +4.5% | | 100 | late param hit | 1.0247 (+2.5%) | +1.9% … +2.9% | | 100 | method miss | 1.0055 (+0.6%) | +0.3% … +0.7% | | 100 | path miss | 1.0165 (+1.7%) | +1.2% … +1.9% | | 500 | static hit | 1.0107 (+1.1%) | -2.2% … +4.5% | | 500 | late param hit | 0.9838 (-1.6%) | -2.2% … +0.8% | | 500 | method miss | 1.0197 (+2.0%) | +1.6% … +2.3% | | 500 | path miss | 1.0161 (+1.6%) | +0.5% … +2.6% | ## Awaiting owner decision - **D4.** In-process, the module imported first runs about 20% faster on the cheapest cell. At 10-route static hit the per-run medians swap from 156 vs 200 ns to 188 vs 162 ns when the import order swaps. Alternating the order removes that from the median but leaves the cell's 95% CI at −13.7 … +11.9%, so a ≤5% regression limit **cannot be resolved there** with this method and sample size. The other 10-route cells' CIs are within about ±10% (the misses within ±4.4%). At 100 and 500 routes, identical code shows small systematic offsets of up to +2.9%. The ≥20% improvement target at 500 routes is far outside the noise. The options are to apply the 10-route limit to the miss and late-parameter cells only, to require more rounds for the static cell, or to restate the limit against this measured floor. - **D5.** Accountable corpus owner and approval of this corpus, including the deviations below and the three supplementary manifest entries. ## Deviations from ROUTER-CORPUS - The pinned revision is `ed47836`, not `42376c6`. - Three tests are proposed as supplementary manifest entries, pending D5: `ws-upgrade-reject.test.ts`, `mesh/control-upgrade.test.ts`, and the `mesh control over app.upgrade` group. - WS paths do go through HTTP normalization since #117; CARD-08's note saying otherwise is out of date. - The adapters disagree in one place, frozen as observed: a user `@Ws('/__mesh__/control')` on an app without mesh is refused by `app.upgrade` (1008) but served by the Node listener. - The mesh HTTP route table is built once at boot. A departed peer keeps its routes (hit → 503, `Allow` unchanged); a late peer is never spliced in (404). Route removal is not supported, and this is captured as such. - A constraint cannot contain `/` (`:id([a-z/]+)` is rejected as `malformed constraint`); the encoded-slash case uses `\S+`. - **Finding (mesh proxy, not the matcher):** a remote `GET` with no local route advertises `HEAD` in `Allow`/`OPTIONS`, but `HEAD` answers 404. The teacup resolves `HEAD` to the remote `GET` implicitly, forwards the request as `HEAD`, and the teapot looks up `(pattern, HEAD)` and finds no plan. This is frozen as observed; fixing it is a separate decision. - `TRACE` cannot be built with `new Request`, so app-level tests use `PURGE`. - The `bench:compare` end-to-end run (A/A, all cases within ±1.9%) is from the laptop on battery and lives in `battery-run/`. It was not repeated on jarvis. ## Gates On macOS arm64: `lint`, `format:check`, `typecheck`, `typecheck:bench`, `complexity:check`, `build`, `npm test` (87 files, 801 tests), `test:deno` (36), `test:bun` (26) and `test:edge` (including the parity phase) all pass. `git diff ed47836 -- src` is empty. `npm audit --audit-level=moderate`: 0 vulnerabilities. The open Dependabot alerts on the GitHub mirror are for `main` before #122, and every package involved is already patched in this lockfile.
chrnx added 6 commits 2026-10-10 22:28:39 +00:00
CARD-07 replaces the linear HTTP matcher with a radix index. Before any of
that code changes, the behaviour it must preserve has to exist somewhere the
new code cannot quietly move it.

manifest.json names the existing tests retained unchanged (ROUTER-CORPUS §1),
pinned to ed47836 instead of 42376c6: #117 and #122 landed after the corpus
was written. Every named file and test was verified to exist and pass there;
none was renamed. Three upgrade-path tests from #117 are listed separately as
proposed additions, pending D5. manifest.test.ts fails if a named test
disappears.

oracle.ts is a verbatim copy of the matcher at ed47836 (matchRoute,
resolveRoute, allowedMethods, normalizeRequestPath, compilePattern,
matchWsRoute), with local route types and its own caches. Its header says it
must not be edited to fit a new implementation, and the manifest test fails if
anything under src/ imports it.

frozen.ts reads the captured baseline. It refuses `vitest -u`, and the capture
switch only fills a missing file, never overwrites one.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The parity corpus from ROUTER-CORPUS §2, with every expected output captured
from ed47836 rather than written by hand.

Matcher: 24 hand-picked scenarios (precedence, constraint ties, exact versus
catch-all, equal-rank and same-pattern ties with reversed twins, implicit and
explicit HEAD, streaming GETs, canonical Allow, encoding, case, Unicode and
normalization) plus 40 scenarios from a fixed-seed generator
(router-parity-gen-v1, seed 10908). The generated file stores the seed, the
rules and every generated input; the test regenerates and requires a match,
so changing the generator cannot move the baseline. Each scenario runs through
the oracle and the live router and both must equal the capture, compared by
declaration ID, decoded params, implicitHead, ordered Allow, or the
normalization error.

Application level: status, Allow, headers and body through app.fetch and a
Node socket, including HEAD body suppression, 400/404/405 and OPTIONS.

WebSocket, separate from HTTP: first-registered selection, an HTTP route at the
same path not taking the upgrade, and the reserved mesh control path, through
app.upgrade and the Node listener. This freezes one adapter disagreement as
observed: a user @Ws('/__mesh__/control') on an app without mesh is refused by
app.upgrade (1008) and served by the Node listener.

Boot-time rejections: pattern compilation, local ambiguity and mesh splicing
(duplicate exports, same-shape exports, local-over-remote precedence with its
warning, and a remote static outranking a local parameter route).

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
graph(), explain() and openapi() read routePlans in declaration order. A
radix index must stay a lookup structure and never become their source, so
their output is frozen from ed47836 for CARD-09 to compare against.

One app fixture covers multiple methods and transports, constraints, explicit
HEAD and OPTIONS, providers and steps, and WS, declared out of specificity
order. The goldens hold graph(), explain() for declared patterns and the
`no route: <pattern>` error (including a concrete request path, which is not a
declaration), and openapi({ title: 'Parity', version: '1' }). A separate mesh
teacup records the pre-ready errors, then post-ready introspection in which
the remote HTTP route is reachable but absent from routePlans.

The comparison holds array order and object key order, and `vitest -u` is
refused rather than allowed to rewrite a golden.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
bench:compare reports end-to-end req/s with 50 and 200 filler routes. Lookup
is a few percent of a request there, so it cannot judge D4's thresholds
(at most 5% median regression at 10 routes, at least 20% improvement at 500),
which are stated in median lookup time.

bench:lookup measures exactly what dispatch does with a normalized path:
resolveRoute, and on a miss allowedMethods. It covers 10, 100 and 500 total
HTTP routes from a recorded generator, with static hit, late parameter hit,
method miss and path miss workloads. Each answer is checked before timing, so
an implementation that answers wrongly cannot post a number. Warm-up is
time-boxed and calibrates the iterations per sample; every sample is kept.

The router under test is a module path. LOOKUP_ROUTERS takes several, and each
run measures them in separate child processes, alternating which goes first,
so CARD-07/10 can run this same harness on base and head.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
Additions requested in CARD-08 review, captured from ed47836 like the rest of
the corpus and frozen in their own files, so the first capture is untouched.

- Backtracking: a static branch failing one level down, at depth 5 (and a
  param branch at depth 3), and with a constrained param on the fallback.
- Cross-pattern Allow: GET :id plus POST b, with and without DELETE :rest*,
  at matcher level and through app.fetch and Node.
- Encoded slashes in plain and constrained params. A constraint cannot itself
  contain a slash: the pattern splits there and is rejected as malformed.
- Zero-segment catch-alls without an exact sibling, and a root catch-all.
- The mesh HTTP table across a peer's lifetime. It is built once at boot and
  never changes: a peer that leaves keeps its routes (503 on hit, 405 Allow
  unchanged) and a peer that arrives after boot is never spliced in (404).
  CARD-10 can reuse this for its no-rebuild-per-request check.
- router-parity-gen-v2, same seed 10908, forces static, param, constrained
  and catch-all siblings under shared prefixes at depths 1-4. branches.ts
  measures the effect and the result is frozen with the fixture: 71.9% of v2
  requests reach sibling branches and 67.3% backtrack, against 36.5% and
  26.7% for v1. v1 and its fixture are unchanged.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
perf(bench): record the pre-radix lookup baseline at ed47836
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 25s
CI / runtimes (deno) (pull_request) Successful in 21s
CI / runtimes (edge) (pull_request) Successful in 14s
a4562b2b23
The baseline CARD-10 compares the radix index against, captured before any
router change. Kept with its environment record and every raw sample.

bench:lookup on the linear matcher, five runs of 105 samples per cell. Median
ns per lookup:

  routes  static hit  late param  method miss  path miss
  10            61.3       123.3        313.1      247.1
  100           67.6       343.4       1263.7     1463.3
  500           67.8      1326.8       6732.2     8973.4

Run-to-run spread of the per-run medians is 2.0-17.5%. An A/A run (live
router against the byte-identical oracle, same protocol) differs by +5.2% on
the 10-route static hit and by at most 2.7% elsewhere, so D4's 5% limit at 10
routes sits at the noise floor for that cell. That is recorded for the D4
decision, not resolved here.

bench:compare, run once A/A, is stored separately as end-to-end req/s only:
every case within 1.9%.

Measured on an Apple M4 Max on battery power, load average 2.4-3.4 on 16
cores; the comparison run should use the same power source.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx added 4 commits 2026-10-10 22:45:46 +00:00
The matcher comparison does not depend on the runtime, so it should run on every
runtime core supports. Only the Node suite ran it before.

The comparison and the app.fetch fixtures move into differential.ts and
app-fixture.ts, which use neither vitest nor a file API. Each runtime passes in
a loader for the frozen JSON. The vitest files use the same modules, plus a
Node check that the neutral runners report no mismatch, so the two paths cannot
drift.

- Deno and Bun: test/{deno,bun}/router-parity.test.ts run all 1158 frozen
  matcher cases (hand-picked, owner, generated v1 and v2, WS) through the oracle
  and the live router, plus the 55 app.fetch cases.
- workerd: test/edge/parity-worker.ts bundles the frozen JSON and runs the
  same checks; test/edge/run.ts adds the phase after its existing assertions.

The Node-socket, WS-upgrade, boot and mesh captures stay Node-only: they need
http.request, the ws client, or a mesh peer on a port.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
A frozen corpus is only worth what it catches. npm run parity:mutants applies 12
targeted mutants to a temporary copy of src/, one at a time, and runs the parity
suite against each. Every mutant models a bug a radix rewrite could plausibly
introduce:

  no backtracking to a param branch     static/param precedence swapped
  equal-rank tie to last-registered     constraint ignored
  decode before splitting (%2F)         catch-all needs a segment
  implicit HEAD from a streaming GET    Allow from one pattern only
  Allow in discovery order              trailing slash not normalized
  WS ranked like HTTP                   case-insensitive static match

All 12 are killed (4 to 74 failing tests each), so no corpus case had to be
added. A mutant whose search text is not found exactly once fails the run rather
than silently testing an unmutated copy. The real src/ is never written, and
the run ends with git diff --exit-code src. It is not part of npm test because
it runs the suite once per mutant.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
The first baseline ran each router in its own process, one after another, so
drift and background load landed on whichever side ran later. Comparing two
medians taken minutes apart cannot resolve a 5% threshold.

bench:lookup now loads every router into one process. In each cell it warms
every router, then takes one sample from each per round, alternating the
order: AB, BA, AB. There are at least 15 rounds per cell per run (default 21)
over 4 fresh processes, and module import order also alternates per run.
Every router after the first is reported against the first as the median of
the per-round paired B/A ratios, with a percentile-bootstrap 95% CI (4000
resamples, fixed seed, so the same samples always give the same interval).
With a single router it reports absolute medians as before.

The record now includes hostname, the effective cpuset when run in a Linux
container, and any LOOKUP_* note variables. The harness still runs on any
machine with Node 22.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
perf(bench): re-baseline lookup on jarvis with the interleaved harness
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 35s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 15s
71fc027134
The first baseline came from a laptop on battery, with one router per process,
run one after the other. It moves to battery-run/ for reference. The new
baseline is the interleaved A/A run (live matcher as A, byte-identical oracle
as B) on jarvis.

Setup: Ryzen 7 3700X, cpuset 6,7,14,15 (two idle physical cores and their SMT
siblings), node:22 container, Node 22.23.1, load average 0.27-0.79, no CI job
running. 4 processes x 21 rounds give 84 paired rounds per cell.

Live medians in ns per lookup (static hit, late param, method miss, path miss):
  10 routes:   185, 328, 800, 626
  100 routes:  201, 878, 2525, 3054
  500 routes:  202, 2931, 11904, 15514

A/A noise floor (oracle/live median ratio, 95% CI): at 10 routes, static hit
-13.7..+11.9% and late param -1.6..+9.8%; misses within +-4.4%. At 100 and 500
routes, offsets are systematic but within about 3%.

In-process, the module imported first runs about 20% faster on the 10-route
static hit. Alternating import order per process removes the bias from the
median but not from that cell's CI. A 5% limit there cannot be resolved with
this method and sample size, so this is recorded for the D4 decision. The 20%
improvement target at 500 routes is far outside the noise.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx added 1 commit 2026-10-10 23:16:14 +00:00
test(router): freeze local/remote Allow and remote implicit HEAD for mesh
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 26s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 14s
fdd762b081
CARD-07 will index local and remote mesh routes as two radix trees and keep
today's unified precedence: the most specific route wins across both trees, a
tie goes to the local route, and Allow is the union. This freezes that behaviour
from ed47836, through app.fetch and a Node socket, in a new file
(owner-mesh-allow.json); existing captures are untouched.

- Local GET and remote POST on one path: PUT is 405 and OPTIONS is 204, both
  with Allow GET, HEAD, POST, OPTIONS. HEAD uses the local GET.
- Local static GET /api/v/b with remote POST /api/v/🆔 the same union on
  /api/v/b, and only POST, OPTIONS on /api/v/c.
- A remote GET with no local route: OPTIONS advertises GET, HEAD, OPTIONS, but
  HEAD answers 404. The teacup resolves HEAD to the remote GET implicitly,
  forwards it as HEAD, and the teapot finds no plan for (pattern, HEAD). That
  is the mesh proxy, not the matcher, and is captured as observed.

The mutation check still kills 12 of 12.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
chrnx merged commit 7ee7ab7ec5 into develop 2026-10-11 17:23:56 +00:00
Sign in to join this conversation.