From 55a4e282ad9b8d69f84225dbc2203578a3ac0141 Mon Sep 17 00:00:00 2001 From: Diego Resendez Date: Sun, 11 Oct 2026 21:00:27 -0500 Subject: [PATCH] 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 --- test/router-index.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/test/router-index.test.ts b/test/router-index.test.ts index e67d2b5..7338a5b 100644 --- a/test/router-index.test.ts +++ b/test/router-index.test.ts @@ -92,6 +92,22 @@ describe('radix index: local and remote trees', () => { }); }); +describe('radix index: ranking across branches', () => { + it('lets an exact param route beat a catch-all the walk reached first through a static branch', () => { + // The static branch is walked first and yields the catch-all (rank 1); the param sibling still + // holds the rank-0 exact route, so pruning must not cut it, even by one. + for (const order of [ + ['/a/:rest*', '/:x/b'], + ['/:x/b', '/a/:rest*'], + ]) { + const routes = order.map((pattern) => route('GET', pattern)); + const expected = oracle.matchRoute(routes, 'GET', '/a/b'); + expect(expected?.def.pattern).toBe('/:x/b'); + expect(live.matchRoute(routes, 'GET', '/a/b')).toEqual(expected); + } + }); +}); + describe('radix index: lifetime', () => { it('rebuilds when the array it was built from changes length', () => { const routes = [route('GET', '/a')];