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>
This commit is contained in:
chrnx committed 2026-10-10 17:27:11 -05:00
1 parent 98ea948ffa
commit a47c6564ab
10 files changed
+11835 -3

No files matched your search

+90
View File
@@ -250,3 +250,93 @@ export const HAND_SCENARIOS: Scenario[] = [
get('/v/1/x', '/v/a/x', '/v/1', '/v'),
),
];
/**
* Owner-requested additions (CARD-08 review), frozen separately in `frozen/matcher-owner.json` so the
* first capture stays untouched. Inputs only, like everything above.
*/
export const OWNER_SCENARIOS: Scenario[] = [
scenario(
'O01-backtrack',
'a static branch that fails one level down must fall back to a sibling param branch',
[
['static', 'GET', '/a/b/c'],
['param', 'GET', '/a/:x/d'],
],
get('/a/b/d', '/a/b/c', '/a/z/d', '/a/b/x'),
),
scenario(
'O02-backtrack-deep',
'the static branch fails at depth 5 (and a param branch at depth 3), after walking four or two levels',
[
['static', 'GET', '/p/q/r/s/t'],
['paramDepth2', 'GET', '/p/:x/r/s/u'],
['paramDepth3', 'GET', '/p/q/:y/s/v'],
],
get('/p/q/r/s/u', '/p/q/r/s/t', '/p/z/r/s/u', '/p/q/r/s/v', '/p/q/z/s/v', '/p/q/r/s/w'),
),
scenario(
'O03-backtrack-constrained',
'the fallback branch is a constrained param',
[
['static', 'GET', '/k/1/c'],
['digits', 'GET', '/k/:n(\\d+)/d'],
],
get('/k/1/d', '/k/1/c', '/k/2/d', '/k/x/d'),
),
scenario(
'O04-cross-pattern-allow',
'Allow is the union of methods across different patterns matching the same path',
[
['getParam', 'GET', '/a/:id'],
['postStatic', 'POST', '/a/b'],
],
[
['PUT', '/a/b'],
['OPTIONS', '/a/b'],
['PUT', '/a/x'],
['HEAD', '/a/b'],
['GET', '/a/b'],
['POST', '/a/x'],
],
),
scenario(
'O05-cross-pattern-allow-catch-all',
'the same, with a catch-all contributing a method',
[
['getParam', 'GET', '/a/:id'],
['postStatic', 'POST', '/a/b'],
['deleteRest', 'DELETE', '/a/:rest*'],
],
[
['PUT', '/a/b'],
['OPTIONS', '/a/b'],
['PUT', '/a/x'],
['HEAD', '/a/b'],
['PUT', '/a/x/y'],
['DELETE', '/a'],
],
),
scenario(
'O06-encoded-slash-plain',
'an encoded slash inside one segment, plain param',
[['userId', 'GET', '/users/:id']],
get('/users/a%2Fb', '/users/a%2fb', '/users/%2F', '/users/a/b'),
),
scenario(
'O07-encoded-slash-constrained',
'an encoded slash against a word constraint and a non-space constraint (a / cannot appear inside a constraint: the pattern splits there)',
[
['word', 'GET', '/c/:id(\\w+)'],
['nonSpace', 'GET', '/d/:id(\\S+)'],
],
get('/c/a%2Fb', '/c/ab', '/d/a%2Fb', '/d/a%2fb', '/d/%2F', '/d/a/b'),
),
scenario(
'O08-zero-segment-catch-all',
'a catch-all with no exact sibling route',
[['rest', 'GET', '/files/:rest*']],
[...get('/files', '/files/', '/files/a', '/filesx'), ['HEAD', '/files'], ['OPTIONS', '/files']],
),
scenario('O09-root-catch-all', 'a root catch-all alone', [['rest', 'GET', '/:rest*']], get('/', '/a', '/a/b/')),
];