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

+58 -2
View File
@@ -13,8 +13,17 @@ import { matchWsRoute as liveMatchWsRoute } from '../../src/http/ws-core';
import type { WsRouteDef } from '../../src/http/types';
import * as oracle from './oracle';
import { runScenario, type MatcherImpl, type Outcome, type Scenario } from './matcher';
import { HAND_SCENARIOS } from './cases';
import { generateScenarios, GENERATOR_RULES, GENERATOR_SEED, GENERATOR_VERSION } from './generator';
import { HAND_SCENARIOS, OWNER_SCENARIOS } from './cases';
import { branchStats, type BranchStats } from './branches';
import {
generateScenarios,
generateScenariosV2,
GENERATOR_RULES,
GENERATOR_SEED,
GENERATOR_VERSION,
GENERATOR_V2_RULES,
GENERATOR_V2_VERSION,
} from './generator';
import { frozen, expectFrozenEqual } from './frozen';
const LIVE: MatcherImpl = live;
@@ -81,6 +90,53 @@ describe(`router parity: generated matcher cases (${GENERATOR_VERSION}, seed ${G
}
});
describe('router parity: owner-requested matcher cases', () => {
let expected: Map<string, CapturedScenario>;
beforeAll(async () => {
const data = await frozen('matcher-owner', () => capture(OWNER_SCENARIOS));
expect(data.map((scenario) => scenario.id)).toEqual(OWNER_SCENARIOS.map((scenario) => scenario.id));
expected = new Map(data.map((scenario) => [scenario.id, scenario]));
});
for (const scenario of OWNER_SCENARIOS) {
it(`${scenario.id}: ${scenario.note}`, () => checkScenario(scenario, expected.get(scenario.id)));
}
});
interface GeneratedV2File extends GeneratedFile {
/** Share of generated requests that walk into sibling branches; v1's share is kept for contrast. */
branchStats: { v1: BranchStats; v2: BranchStats };
}
describe(`router parity: generated shared-prefix cases (${GENERATOR_V2_VERSION}, seed ${GENERATOR_SEED})`, () => {
const generated = generateScenariosV2(GENERATOR_SEED);
const stats = () => ({ v1: branchStats(generateScenarios(GENERATOR_SEED)), v2: branchStats(generated) });
let expected: Map<string, CapturedScenario>;
beforeAll(async () => {
const data = await frozen<GeneratedV2File>('matcher-generated-v2', () => ({
generator: GENERATOR_V2_VERSION,
seed: GENERATOR_SEED,
rules: GENERATOR_V2_RULES,
branchStats: stats(),
scenarios: capture(generated),
}));
expect({ generator: data.generator, seed: data.seed, rules: data.rules }).toEqual({
generator: GENERATOR_V2_VERSION,
seed: GENERATOR_SEED,
rules: GENERATOR_V2_RULES,
});
expect(stats()).toEqual(data.branchStats);
expect(data.scenarios.map((scenario) => scenario.id)).toEqual(generated.map((scenario) => scenario.id));
expected = new Map(data.scenarios.map((scenario) => [scenario.id, scenario]));
});
for (const scenario of generated) {
it(`${scenario.id}`, () => checkScenario(scenario, expected.get(scenario.id)));
}
});
describe('router parity: WebSocket matcher (first registered wins)', () => {
// WS selection is a separate contract from HTTP: no specificity ranking, registration order only.
// Paths are fed already normalized, as both upgrade adapters do since #117.