Commit Graph
467 Commits
Author SHA1 Message Date
chrnx 88cbe41f72 feat(edge)!: trust cf-connecting-ip only under trustProxy, for HTTP and WebSocket (CARD-23, #119)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 25s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 15s
edgeHandler copied cf-connecting-ip into ctx.ip on every WebSocket
upgrade, so any client that sent the header chose its own address, and
it never read the header for HTTP, so IP-keyed plugins saw '' there.
D21 settles both: the header counts only under trustProxy, on both
paths, with no new option.

The adapter cannot make that call, because trustProxy is an app option.
So edgeHandler records the header against the object it hands the app
(the Request for HTTP, the WsRequest for an upgrade) in an internal
registry next to the Deno/Bun peer one, and app.fetch and app.upgrade
both consult it through one helper, trustedProxyClient(), which returns
'' unless trustProxy is on. Under trustProxy it takes precedence over
x-forwarded-for, since Cloudflare sets it itself and XFF can carry
client-supplied hops.

Nothing else records into the registry, so the Node, Deno and Bun
adapters, and a bare app.fetch or app.upgrade, ignore the header as
before.

BREAKING CHANGE: an edge WebSocket upgrade no longer takes ctx.ip from
  cf-connecting-ip unless the app sets trustProxy: true; without it,
  ctx.ip is ''.
Refs: #119

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-23 00:47:58 -05:00
chrnx 89ac955072 Merge pull request 'fix(http): keep every ? after the first in the query string (CARD-25, GitHub #48)' (#136) from feature/fprd-001c-query-string-question-marks into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 27s
CI / runtimes (edge) (push) Successful in 13s
CI / runtimes (deno) (push) Successful in 20s
Promote → GitHub / push-github (push) Successful in 7s
2026-10-23 05:47:53 +00:00
chrnx 8bf54ec168 fix(http): keep every ? after the first in the query string (CARD-25, GitHub #48)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 27s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 14s
parseQuery took `url.split('?')[1]`, so a second `?` ended the query
string and `/search?q=what?now` gave `q: 'what'`. RFC 3986 §3.4 allows
`?` inside a query. The query string is now everything after the first
`?` and before `#`, if one is present. The early return for URLs without
a query is kept, and so is its measurement note. The comment that
deferred this behaviour question is removed because the question is now
decided (D23).

Path extraction already split on the first `?` and is unchanged.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-23 00:02:42 -05:00
chrnx e565b1d4c9 Merge pull request 'chore(deps): patch vite, vitest and fastify dev-dependency advisories' (#134) from chore/audit-fix-2026-10-22 into develop
CI / dco (push) Has been skipped
CI / build (push) Successful in 27s
CI / runtimes (bun) (push) Successful in 15s
CI / runtimes (deno) (push) Successful in 20s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-23 04:55:05 +00:00
chrnxandClaude Opus 5.5 e112819f64 chore(deps): patch vite, vitest and fastify dev-dependency advisories
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 26s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 14s
`npm audit --audit-level=moderate` failed on develop: vite <=6.4.3 (high:
cross-origin script execution in custom middleware, fs.allow bypass,
launch-editor), vitest/@vitest/mocker <=4.1.11 (moderate: code injection via
manual mock registration) and fastify 5.12.2-5.12.5 (low, benchmark only).

All are devDependencies; the published package is unaffected. Lockfile-only:
vite 6.4.5, vitest 4.1.12, fastify 5.12.7, all inside the existing ranges.
Generated with npm 11 because npm 10.9.7's arborist crashes on this tree
(`Cannot read properties of null (reading 'edgesOut')`).

Verified: npm ci, audit (0), lint, format, typecheck, test (915),
build, complexity, test:deno, test:bun, test:edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-22 23:53:16 -05:00
chrnx f4d29d8ee8 Merge pull request 'test(bun): expect 1009 for oversized WebSocket frames on Bun 1.4+' (#135) from fix/bun-ws-oversize-close into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 16s
CI / build (push) Successful in 27s
CI / runtimes (deno) (push) Successful in 20s
Promote → GitHub / push-github (push) Successful in 6s
CI / runtimes (edge) (push) Successful in 14s
2026-10-23 04:53:08 +00:00
chrnxandClaude Opus 5.5 69bdc8adec test(bun): expect 1009 for oversized WebSocket frames on Bun 1.4+
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 14s
CI / build (pull_request) Successful in 27s
CI picked up Bun 1.4.4 (`oven-sh/setup-bun@v2`, latest), which now sends a
real `1009` close frame when `maxPayloadLength` refuses a frame. Bun 1.3
dropped the connection instead, so the peer saw `1006` — the difference D1
documented and these two assertions pinned on purpose so a Bun upgrade would
be noticed. It was: `runtimes (bun)` fails on develop.

The assertion now follows `Bun.version` (1006 before 1.4, 1009 from 1.4), so a
further change in either direction still fails. JSDoc, README and the #107
CHANGELOG entry say which Bun versions do what.

Verified with Bun 1.3.14 and 1.4.4 (26/26 each); lint, format, typecheck,
npm test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-22 23:50:30 -05:00
chrnx 169ffe6b88 Merge pull request 'ci: move workflow actions off the deprecated Node 20 runtime' (#133) from chore/ci-node24-actions into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 27s
CI / runtimes (deno) (push) Successful in 20s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 5s
2026-10-18 04:42:07 +00:00
chrnx 7bc402a1fb ci: move workflow actions off the deprecated Node 20 runtime
CI / dco (pull_request) Successful in 13s
CI / runtimes (bun) (pull_request) Successful in 37s
CI / build (pull_request) Successful in 53s
CI / runtimes (edge) (pull_request) Successful in 14s
CI / runtimes (deno) (pull_request) Successful in 20s
actions/checkout and actions/setup-node v4 -> v5, softprops/action-gh-release
v2 -> v3; all three run on Node 24. setup-deno@v2, setup-bun@v2 and
crates-io-auth-action@v1 already resolve to Node 24 releases. Jobs keep
node-version 22.

Refs #103

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-17 22:55:41 -05:00
chrnx 539f287a67 Merge pull request 'feat(router)!: fail boot on unreachable or ambiguous constrained params (CARD-13, #127)' (#132) from feature/fprd-001b-constraint-ambiguity into develop
CI / runtimes (deno) (push) Successful in 20s
Promote → GitHub / push-github (push) Successful in 6s
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 17s
CI / build (push) Successful in 26s
CI / runtimes (edge) (push) Successful in 14s
2026-10-14 02:22:28 +00:00
chrnx 84e6f0752e docs(readme): describe radix route lookup
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 26s
CI / runtimes (deno) (pull_request) Successful in 20s
CI / runtimes (edge) (pull_request) Successful in 15s
The README still said matching was a linear scan with a radix tree as
post-beta work; CARD-07 (#128) shipped the radix index.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-13 21:21:25 -05:00
chrnx 63f60134ea feat(router)!: fail boot on unreachable or ambiguous constrained params
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 27s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 14s
Before, when two sibling routes could match the same request, the router
picked one by registration order or precedence, and nothing reported it.
Boot now refuses two cases between routes of the same method that branch at
the same segment under the same prefix:

- ambiguous: both params are constrained, the constraints accept a common
  segment, and the rest of both patterns can match one request. The error
  names both declarations and a witness segment with an example path.
- unreachable: a plain param sits next to a constraint that accepts every
  segment, and the constraint wins every request the plain param could take.

A plain param next to a constraint that leaves some segments over is the
documented fallback pattern and still boots.

The check is exact. assertSafeConstraint admits only a linear, group-free
subset, so every constraint reads back as a sequence of (character set, min,
max) blocks. Atom sets follow u-flag semantics. \p{...} is the one construct
that is not modelled, and for it the engine is asked once per code point. A
product walk over two block sequences finds a common segment, or proves none
exists, in O(|A|*|B|*(|A|+|B|)*K) with K <= 2048. "Accepts every segment" is
a closed-form test on the blocks. Both are measured against what the router
hands a param: a decoded, non-empty segment that is never "." or "..".

The check runs per table under that table's own precedence. HTTP ranks by
specificity. WebSocket takes the first declared match. @Stream routes sit in
both tables. Routes exported by different teapots are checked against each
other. Local against remote keeps the local override and its warning.

The lookup path is unchanged. router.ts only exports the two token regexes,
so the boot check and assertSafeConstraint read atoms the same way.

BREAKING CHANGE: an app that declares two overlapping constrained siblings
  (e.g. /u/:id(\d+) and /u/:n(\d{1,3})), or a plain param beside a constraint
  that accepts every segment, now fails createApp. So do a plain WebSocket param
  declared before a constrained sibling, and such pairs across mesh teapots.
Refs: #127
Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 16:07:58 -05:00
chrnx e41d9560ba test(router-parity): make the app fixture's hex route disjoint for CARD-13 (owner approval required)
The frozen app fixture declares GET /n/:num(\d+) and GET /n/:code([0-9a-f]+).
Both constraints accept digits, so CARD-13 (#127) makes this pair a boot error,
and the fixture app could no longer start. That would fail app-fetch.json and
app-node.json, and the Deno, Bun and workerd parity runs that boot the same app.

Narrow nCode to [a-f]+. The two frozen requests on this pair still get the
captured answers: /n/42 goes to nNum and /n/ff goes to nCode, with the same
params. No frozen JSON file changes.

What is lost at app level is the equal-rank registration tie between two
overlapping constraints. CARD-13 now forbids that tie at boot. The tie stays
covered by matcher-hand.json, which calls the matcher without booting an app.

Owner approval required (CARD-08 rule): this edits a file under
test/router-parity/.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 16:07:15 -05:00
chrnx c2db4f69c6 Merge pull request 'test(router): record D4 lookup evidence and no miss-time recompilation (CARD-10, #109)' (#130) from feature/fprd-001b-lookup-evidence into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 26s
CI / runtimes (deno) (push) Successful in 20s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 5s
2026-10-12 20:43:32 +00:00
chrnx 2e2c68de07 test(bench): record D4 lookup evidence at ed19f16 (CARD-10, #109)
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 20s
CI / runtimes (edge) (pull_request) Successful in 19s
Formal D4 run after the walk-stack fix (#131) and the router-order fix in
the harness, 16 x 21 rounds on jarvis. Every cell passes; the 10-route
late param hit passes with its CI lower bound at +4.9%. Marks the
b128139 evidence as superseded.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 15:27:20 -05:00
chrnx ed19f16c70 test(bench): alternate the whole router order per lookup run
Only the import order alternated between processes; warm-up order and
the shared lookup call site always saw the first-listed router first.
CARD-10's A/A run (oracle vs a byte-identical copy) showed a steady bias
of up to +8.3% against the second-listed router at 10 routes. Reversing
the whole order per process brings the same A/A to -0.1% (8 x 21
rounds on jarvis). Owner-approved D4 method change (2026-10-12).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 15:16:13 -05:00
chrnx a64f514db2 test(bench): record D4 lookup evidence for the radix router (CARD-10, #109)
Formal D4 run on jarvis with the baseline's harness, image, and cpuset:
oracle (pre-radix linear matcher) against the radix router at b128139,
16 processes x 21 rounds = 336 paired rounds per cell, plus an A/A
run (oracle against a byte-identical copy) at the same settings.

D4 fails at 10 routes: late param hit +52.5%, method miss +31.8% and path
miss +101.9%, with every CI lower bound far above +5%. 100 routes improve
in every cell, and all 500-route targets are met (-82.5% to -92.1%). A
diagnostic run with three router revisions traces the 10-route regression
to a2b71e2 (try/finally stack reset in the walk). The seam counters
added for the no-recompilation test change nothing.

No threshold was relaxed and no src/ change was made. The raw samples
are committed for an owner decision.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 15:12:40 -05:00
chrnx 7a9932f095 test(router): prove misses after index build recompile nothing (CARD-10, #109)
The linear matcher answered every 404, 405 and automatic OPTIONS by compiling
the whole route table. The radix index compiles each pattern once, when the
index for an array is built. Nothing asserted that, so a regression to
per-request compilation or per-request index builds would only show up as a
slower benchmark.

compilePattern is called inside router.ts, where a spy on the module export
cannot see it, so the router gains two internal counters (compilePattern calls,
index builds), exposed as @internal routerSeamCounts() next to walkStackSize.
router.ts is not a package entry. The new test warms the index, then repeats
404, 405 and OPTIONS misses through resolveRoute/allowedMethods, buildFetch and
app.fetch, and asserts both counts stay constant while status and Allow stay
correct.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 15:12:40 -05:00
chrnx 72f591dd21 Merge pull request 'test(router): prove introspection parity after the radix index (CARD-09, #109)' (#129) from feature/fprd-001b-introspection-parity into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 25s
CI / runtimes (deno) (push) Successful in 19s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-12 20:12:25 +00:00
chrnx d07d6add04 Merge pull request 'perf(router): reset the walk stack only when a lookup throws (#109)' (#131) from fix/router-walk-stack-reset into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 25s
CI / runtimes (deno) (push) Successful in 19s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 7s
2026-10-12 20:10:44 +00:00
chrnx 1b30f15c02 perf(router): reset the walk stack only when a lookup throws
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 26s
CI / runtimes (edge) (pull_request) Successful in 14s
CI / runtimes (deno) (pull_request) Successful in 19s
The finally block added in a2b71e2 wrote both stacks' length on every
lookup, which drops their backing storage and made every walked lookup
pay for reallocation: +50% late param hit, +33% method miss and +104%
path miss at 10 routes on jarvis (CARD-10). A normal walk already ends
at base, so reset only in a catch and rethrow.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 14:27:24 -05:00
chrnx fcee6892bf 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
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>
2026-10-12 13:59:56 -05:00
chrnx cb123e3774 Merge pull request 'perf(router): radix index for HTTP route lookup (CARD-07, #109)' (#128) from feature/fprd-001b-radix-index into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 25s
CI / runtimes (deno) (push) Successful in 20s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 7s
2026-10-12 18:54:45 +00:00
chrnx a2b71e2472 fix(router): drop pending walk frames when a segment fails to decode
CI / dco (pull_request) Successful in 5s
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 14s
The walk stack is shared across lookups. A malformed % escape threw out
of decodeSegment with frames still pushed, so repeated direct matcher
calls on such paths retained them. Truncate both arrays back to the
entry length in a finally block, and check it with a test.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-12 13:47:53 -05:00
chrnx 4de9f32e31 test(router-parity): retarget walk mutants to the iterative walk
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 27s
CI / runtimes (deno) (pull_request) Successful in 21s
CI / runtimes (edge) (pull_request) Successful in 15s
Same four mutants (no-backtrack, catch-all-needs-segment,
prune-bound-off-by-one, zero-catch-all-after-static-dead-end), patched
at their new sites in the stack-based walk. 21/21 still killed.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 22:07:17 -05:00
chrnx 5e0ae94ba2 fix(router): walk the radix index without recursion
The lookup walk recursed once per path segment, so a valid deep route
such as 4,999 static segments followed by /:x threw RangeError where the
linear matcher matched. Walk on an explicit stack instead, visiting
frames in the same order, and cover the case through buildFetch.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 22:06:49 -05:00
chrnx 996fb3f7a5 test(router-parity): retarget mutants to the radix index (owner-approved)
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 25s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 14s
The owner approved editing this one file under test/router-parity/ so
the PR ends with a single mutant check. The original search texts
targeted lines of the linear scan that CARD-07 removed, so the script
refused to run against the new router. The parity tests, oracle,
frozen JSON and manifest are untouched.

The twelve original mutants keep their names and the bug each models;
six apply their original edit, six are rewritten against the index.
Nine new mutants cover risks the index introduced: the static-route
map ignoring the method or shadowing an earlier route, an off-by-one
pruning bound, the empty-collection skip pruning a real match, a
local/remote tie going remote, Allow and implicit HEAD from the local
tree only, the stale-index guard removed, and a zero-segment
catch-all skipped where the path ends on a static continuation.

The suite now also runs test/router-index.test.ts, which covers the
local/remote split and index lifetime the corpus cannot reach. Each
edit must match exactly once and must change the file; a failed edit
restores the copy before the run aborts. The script still ends with
git diff --exit-code src.

Removes test/router-index-mutants.ts and parity:mutants:index, which
this replaces.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 21:00:35 -05:00
chrnx 55a4e282ad test(router): cover pruning across a static branch and a param sibling
The walk takes the static branch first, so for `GET /a/:rest*` and
`GET /:x/b` it reaches the catch-all on `/a/b` before the exact param
route that outranks it. The corpus has no such pair, and a pruning
bound off by one went unnoticed there. Checked against the oracle in
both declaration orders.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 21:00:27 -05:00
chrnx d76afd7f25 docs(changelog): note the radix route index
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 15s
CI / build (pull_request) Successful in 25s
CI / runtimes (edge) (pull_request) Successful in 14s
CI / runtimes (deno) (pull_request) Successful in 25s
An internal change with no behaviour difference, recorded under
Changed with the lookup numbers from the jarvis run.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 12:58:26 -05:00
chrnx 815f76116f perf(router): index HTTP routes in a radix tree
Replace the linear, specificity-sorted scan behind matchRoute,
resolveRoute and allowedMethods with a segment trie per HTTP method,
built once per route array from the compiled segments compilePattern
already produces.

Ranking stays global: every terminal carries its position in the old
sorted bucket (moreSpecific, declaration order on ties), and the walk
keeps the lowest rank it can reach, pruning subtrees that cannot beat
it. The tree decides which routes can match; the rank alone decides
which one does. A static branch that dead-ends deeper backtracks into
its param, constrained and catch-all siblings.

All-static routes are also kept by exact path per method. A hit there
is provably the tree's best match, so a static request is answered
without splitting the path; a miss falls through to the walk.

Mesh-spliced remote routes go in a second tree, per the owner's
design decision. Both trees answer, the more specific match wins and
an equal one goes to the earlier declaration, so local still beats
remote on a tie. Allow, 405 and implicit HEAD run over the union. An
app without remote routes does one lookup.

allowedMethods walks the index instead of recompiling every route on
a miss, and an implicit HEAD no longer builds a fresh index from a
filtered array on every request.

The frozen parity corpus passes unchanged. The frozen mutant script
cannot run against the new layout by design, so
test/router-index-mutants.ts re-targets its twelve bug classes at
the new code and runs the same untouched suite.

Refs #109

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-11 12:56:37 -05:00
chrnx 7ee7ab7ec5 Merge pull request 'test(router): freeze radix-router parity corpus and baseline (CARD-08, #109)' (#123) from feature/fprd-001b-router-corpus into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 25s
CI / runtimes (deno) (push) Successful in 20s
CI / runtimes (edge) (push) Successful in 14s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-11 17:23:53 +00:00
chrnx fdd762b081 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
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>
2026-10-10 18:16:09 -05:00
chrnx 71fc027134 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
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>
2026-10-10 17:44:53 -05:00
chrnx ee7fdec541 perf(bench): interleave lookup comparisons and report B/A with a bootstrap CI
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>
2026-10-10 17:41:15 -05:00
chrnx 32caa21308 test(router): add a mutation check for the parity corpus
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>
2026-10-10 17:39:38 -05:00
chrnx 684795a2de test(router): run the parity differential on Deno, Bun and workerd
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>
2026-10-10 17:38:36 -05:00
chrnx a4562b2b23 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
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>
2026-10-10 17:27:26 -05:00
chrnx a47c6564ab test(router): add owner-requested parity cases and a shared-prefix generator
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>
2026-10-10 17:27:11 -05:00
chrnx 98ea948ffa perf(bench): add a focused route-lookup benchmark for D4
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>
2026-10-10 17:01:25 -05:00
chrnx 5d0e544878 test(router): capture graph, explain and OpenAPI goldens before indexing
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>
2026-10-10 16:59:46 -05:00
chrnx c30cf7e457 test(router): freeze the differential, application, WS and boot-error corpus
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>
2026-10-10 16:59:45 -05:00
chrnx adce82beaa test(router): pin the retained-test manifest and a frozen pre-radix oracle
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>
2026-10-10 16:59:31 -05:00
chrnx ed47836c98 Merge pull request 'chore!: require Node 22 and clear dev audit advisories' (#122) from chore/audit-dev-deps into develop
CI / dco (push) Has been skipped
CI / build (push) Successful in 26s
CI / runtimes (deno) (push) Successful in 30s
CI / runtimes (bun) (push) Successful in 14s
CI / runtimes (edge) (push) Successful in 13s
Promote → GitHub / push-github (push) Successful in 6s
2026-10-10 21:41:42 +00:00
chrnx 77a99e83ce chore(deps): vitest 4
CI / runtimes (bun) (pull_request) Successful in 15s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / dco (pull_request) Successful in 4s
CI / build (pull_request) Successful in 26s
CI / runtimes (edge) (pull_request) Successful in 13s
vitest 3.2.7 carried the last three dev audit advisories: tinypool
(critical, prototype pollution to RCE in worker options), vitest itself
(critical, through tinypool and @vitest/mocker) and @vitest/mocker
(moderate, path traversal through a redirected mock). 4.1.11 is the
first stable release outside every affected range; vitest 4 no longer
depends on tinypool at all. It needs Node 20 or newer, which the Node 22
floor now guarantees. vitest 5 would need Node 22.12, and 4.1.11 is
enough to clear the advisories.

vite stays on ^6.4.3, which vitest 4 accepts.

The one change the bump requires: vitest 4 types `vi.fn()` with no
arguments as a mock of a function *or* a constructor, so
`ReturnType<typeof vi.fn>` is no longer callable as a plain function.
listener-boundary.test.ts now types its spies as
`Mock<(...args: unknown[]) => void>`.

npm 10.9 crashes in arborist's #loadPeerSet resolving this tree, so the
lockfile was produced with npm 11.6.2; `npm ci` on Node 22's bundled
npm 10 installs it cleanly.

npm audit: 3 -> 0. npm audit --omit=dev stays at 0.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 15:03:19 -05:00
chrnx bd478ce09c build!: require Node 22
Node 18 and Node 20 are end-of-life and receive no security patches, so
supporting them before RC.1 would mean promising a runtime nobody can
patch. Node 22 is the oldest line still maintained.

engines.node moves to >=22, @types/node to ^22, the tsup target to
node22, and CI's build job from Node 18 to 22, so every workflow now
runs Node 22 only. The docs, the bug report example and the comments
that stated 18 as the floor follow.

The node:crypto fallback in the HTTP core existed only for Node 18,
which lacked the global crypto; it goes with its regression test, which
said as much. The ws fallback for the WebSocket client stays: Node 22
has the global, but it can still be switched off with a flag.

Moving off Node 18 and 20 also unblocks vitest 4, which the remaining
dev audit advisories need.

BREAKING CHANGE: Node 18 and Node 20 are no longer supported. The
minimum is Node 22.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 12:10:52 -05:00
chrnx 4c3b4d29c4 chore(deps): move the benchmark's fastify to 5.12.5
CI / dco (pull_request) Successful in 5s
CI / runtimes (bun) (pull_request) Successful in 14s
CI / build (pull_request) Successful in 29s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 13s
fastify <= 5.12.4 carries seven advisories (high), and it reaches us
twice, both benchmark-only: as a direct devDependency and through
@nestjs/platform-fastify 11.2.7, which pins fastify 5.11.3 exactly.
`npm audit fix --force` would move to @nestjs/platform-fastify 12,
which is ESM-only and needs @nestjs/core and @nestjs/common 12 as
well: a migration of the Nest benchmark servers, not a dependency fix.

Raise the direct range to ^5.12.5, a patch inside the major we already
use, and point nest's copy at it with `"fastify": "$fastify"` so the
tree holds a single, patched fastify.

Checked with `BENCH_SMOKE=1 npm run bench`: fastify, nestjs-fastify
and nestjs-express all boot and serve every scenario with 0% errors.

npm audit: 5 (2 critical, 1 high, 2 moderate) -> 3 (2 critical,
1 moderate), all of them vitest. `npm audit --omit=dev` stays at 0.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 12:00:06 -05:00
chrnx 445738e830 chore(deps): override miniflare's undici and sharp to patched releases
miniflare 4.20260730.0 is still the newest stable release, and it pins
undici 7.28.0 and sharp 0.35.2. The existing undici 7.29.0 override is
now inside a new advisory range (7.0.0 - 7.29.0, high), and sharp is
under two libheif/librsvg advisories (<= 0.35.5-rc.1, high).
`npm audit fix --force` would install miniflare 5.20261006.1-alpha:
a major and a prerelease, for a test-only dependency.

Move the undici override to 7.29.1 and add sharp 0.35.5, both patch
releases and the exact versions the next miniflare ships with. Same
approach already used for find-my-way, hyperid's uuid and undici.

`test:edge` is the suite that drives workerd through miniflare and it
passes unchanged.

npm audit: 8 (2 critical, 4 high, 2 moderate) -> 5 (2 critical,
1 high, 2 moderate). `npm audit --omit=dev` stays at 0.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 11:59:59 -05:00
chrnx 352ba477b4 chore(deps): apply non-breaking dev-dependency audit fixes
`npm audit fix` without --force: every bump stays inside the ranges
package.json already declares, so only the lockfile changes.

Clears proxy-addr (critical), multer and @nestjs/platform-express,
qs, brace-expansion, fast-uri, js-yaml and source-map-js. All of them
are dev or benchmark dependencies; `npm audit --omit=dev` was and
stays at 0.

npm audit: 16 (3 critical, 11 high, 2 moderate) -> 8 (2 critical,
4 high, 2 moderate).

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 11:57:23 -05:00
chrnx 4d1639f7c5 Merge pull request 'FPRD-001a: core safety and adapter correctness (#104 #105 #106 #107 #108 #116)' (#117) from feature/fprd-001a into develop
CI / dco (push) Has been skipped
CI / runtimes (bun) (push) Successful in 15s
CI / build (push) Successful in 30s
CI / runtimes (deno) (push) Successful in 21s
Promote → GitHub / push-github (push) Successful in 6s
CI / runtimes (edge) (push) Successful in 14s
2026-10-10 16:49:33 +00:00
chrnx 26bacdb304 fix(ws): bound inbound frames synchronously and all-or-nothing
CI / dco (pull_request) Successful in 4s
CI / runtimes (bun) (pull_request) Successful in 16s
CI / build (pull_request) Successful in 30s
CI / runtimes (deno) (pull_request) Successful in 19s
CI / runtimes (edge) (pull_request) Successful in 14s
Two gaps in boundInbound, both from review of #117.

The bound ran in an async pump reading the adapter's channel. `ws` emits a
whole TCP read's worth of frames synchronously, so the unbounded channel
took the burst before the pump saw the first frame: with maxWsQueue 2, a
2,000-frame burst reached the channel in full before close(1013). boundInbound now taps
the channel through an internal, non-exported hook that runs inside push(),
so each frame is bounded before it is queued. Measured on the Node
listen() path, the same burst now closes on the 3rd frame.

accept() also offered a frame to consumers in order and closed 1013 when a
later queue was full, so the rejected frame had already reached earlier
consumers. Capacity is now checked for every consumer before any delivery.

Refs #107

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-10-10 11:42:38 -05:00