Compare commits
6
Commits
ed47836c98
...
a4562b2b23
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4562b2b23 | ||
|
|
a47c6564ab | ||
|
|
98ea948ffa | ||
|
|
5d0e544878 | ||
|
|
c30cf7e457 | ||
|
|
adce82beaa |
No files matched your search
@@ -0,0 +1,90 @@
|
||||
# Pre-radix router baseline — `ed47836`
|
||||
|
||||
The performance half of the CARD-08 parity corpus (FPRD-001, #109). Captured before any CARD-07
|
||||
router change; immutable through CARD-07 review, like `test/router-parity/`. CARD-10 measures the
|
||||
radix index with the **same harness, same defaults, same machine class**, and compares against
|
||||
these files. Do not re-run into this directory: a new capture goes in a new directory.
|
||||
|
||||
## Files
|
||||
|
||||
| File | What it is |
|
||||
|---|---|
|
||||
| `lookup-raw.json` | **The D4 baseline.** `bench:lookup` on the live linear matcher: environment, method, every sample of every run, and the summary. |
|
||||
| `lookup-summary.txt` | The table `bench:lookup` printed for that run. |
|
||||
| `lookup-aa-raw.json`, `lookup-aa-summary.txt` | A/A noise check: the live router against the byte-identical frozen oracle (`test/router-parity/oracle.ts`), same alternating protocol. Any difference here is noise. |
|
||||
| `compare-e2e-raw.json`, `compare-e2e-summary.txt`, `compare-e2e-stderr.txt` | `npm run bench:compare`, run once with this tree as both base and head. **End-to-end req/s signal only**: 50/200 *filler* routes plus base routes, not 10/100/500 total, and not lookup time. It cannot decide D4. |
|
||||
| `load.txt` | `uptime` before and after each run. |
|
||||
|
||||
## Environment
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| Hardware | Apple M4 Max (`Mac16,5`), 16 cores (12 performance + 4 efficiency), 64 GiB |
|
||||
| Power | **On battery** (84%, discharging) for every run. macOS may manage clocks differently on AC; run the CARD-10 comparison on the same power source, or re-capture both on AC. |
|
||||
| OS | macOS 27.0.1 (build 26A434), Darwin 27.0.0 arm64 |
|
||||
| Node | v22.22.2 (V8 12.4.254.21-node.39) |
|
||||
| Packages | `@green-tea/core@26.9.0-beta.2`; tsx 4.23.5, typescript 5.9.3, vitest 4.1.11, autocannon 8.0.0 (from `package-lock.json`) |
|
||||
| Core revision | Router source at `ed47836c9820c47bf4ed5e902d91e019abdb110a`. The harness ran from `98ea948` (this branch), whose `src/` is byte-identical to `ed47836` — the branch adds only tests and bench files. |
|
||||
| Env vars | `LOOKUP_OUT` only (and `LOOKUP_ROUTERS` for the A/A run); no `NODE_OPTIONS`. Recorded in each raw file under `meta.env`. |
|
||||
| Load | 1-minute load average 2.4–3.4 on 16 cores throughout (see `load.txt` and `meta.loadavgAtStart/End`). Foreground apps were a browser and the window server; nothing else CPU-bound. |
|
||||
|
||||
## Method (`bench/lookup.ts`, defaults)
|
||||
|
||||
- **Operation:** `resolveRoute(routes, method, path)`, and on `undefined`, `allowedMethods(routes, path)` — what `dispatch` does after `normalizeRequestPath`. Normalization is excluded.
|
||||
- **Route counts:** 10, 100 and 500 **total registered HTTP routes**.
|
||||
- **Generator:** N−2 fillers cycling `GET /res{k}/items`, `POST /res{k}/items`, `GET /res{k}/items/:id`, `PUT /res{k}/items/:id(\d+)`, `GET /res{k}/files/:path*` (k = ⌊i/5⌋), then `GET /static/target/leaf`, then `GET /late/:group/:id` declared last.
|
||||
- **Workloads:** static hit `GET /static/target/leaf`; late parameter hit `GET /late/g1/42`; method miss `DELETE /static/target/leaf` (Allow `GET, HEAD, OPTIONS`); path miss `GET /nowhere/at/all`. Each answer is asserted before timing.
|
||||
- **Order:** for each run, for each router (order alternates per run), for count 10 → 100 → 500, for the four workloads in the order above.
|
||||
- **Warm-up:** 250 ms per cell, time-boxed; it also calibrates iterations so one sample lasts ≈25 ms (iteration counts are stored per cell).
|
||||
- **Repetitions:** 5 runs, each a fresh child process; 21 samples per cell per run → 105 samples per cell. Every sample is kept.
|
||||
- **Statistic:** median ns per lookup over all 105 samples. Run spread = (max − min of the five per-run medians) / median.
|
||||
|
||||
## Baseline (median ns per lookup, `lookup-raw.json`)
|
||||
|
||||
| Routes | Static hit | Late param hit | Method miss | Path miss |
|
||||
|---:|---:|---:|---:|---:|
|
||||
| 10 | 61.3 (spread 17.5%) | 123.3 (6.2%) | 313.1 (4.6%) | 247.1 (6.8%) |
|
||||
| 100 | 67.6 (8.0%) | 343.4 (2.1%) | 1 263.7 (3.5%) | 1 463.3 (3.2%) |
|
||||
| 500 | 67.8 (7.5%) | 1 326.8 (16.5%) | 6 732.2 (6.5%) | 8 973.4 (2.0%) |
|
||||
|
||||
## Noise floor (A/A, `lookup-aa-raw.json`)
|
||||
|
||||
Identical matcher code under two labels, alternating order per run. Median difference
|
||||
(oracle − live) / live:
|
||||
|
||||
| Routes | Static hit | Late param hit | Method miss | Path miss |
|
||||
|---:|---:|---:|---:|---:|
|
||||
| 10 | +5.2% | 0.0% | +1.2% | +0.2% |
|
||||
| 100 | −0.1% | −0.8% | −0.1% | +0.1% |
|
||||
| 500 | −2.7% | +0.3% | −0.4% | +0.1% |
|
||||
|
||||
**For D4:** with no code difference at all, the 10-route static hit already moves 5.2% — the
|
||||
size of the proposed ≤5% regression limit — and per-run medians at 10 routes spread 4.5–17.5%.
|
||||
That cell is ~60 ns, where a few nanoseconds of timer and scheduling noise are a large fraction.
|
||||
The ≥20% improvement at 500 routes is well clear of the noise (≤2.7% A/A, ≤16.5% spread on a
|
||||
1.3–9 µs operation). Whether D4's 10-route limit applies per workload, to a mean across workloads,
|
||||
or needs more runs is an owner decision; this baseline does not make it.
|
||||
|
||||
## End-to-end signal (`bench:compare`, req/s — not lookup time)
|
||||
|
||||
Run once, A/A: `AB_BASE` pointed at this same tree, so base and head are identical code. Defaults:
|
||||
3 rounds × 10 s per case after a 10 s warm-up, 100 connections, alternating side order. Load
|
||||
average 2.8–3.3 throughout. A few short parity-test runs (seconds each) happened during this
|
||||
~22-minute run; the lookup runs above had nothing else running.
|
||||
|
||||
| Scenario | base req/s | head req/s | Δ |
|
||||
|---|---:|---:|---:|
|
||||
| hello | 88,212 | 88,236 | +0.0% |
|
||||
| param | 86,508 | 85,885 | −0.7% |
|
||||
| pipeline (3 steps) | 80,189 | 80,934 | +0.9% |
|
||||
| steps5 | 74,359 | 73,975 | −0.5% |
|
||||
| validate (POST) | 70,607 | 69,903 | −1.0% |
|
||||
| hello + security | 83,913 | 83,802 | −0.1% |
|
||||
| hello + cors predicate | 82,028 | 80,445 | −1.9% |
|
||||
| preflight + cors predicate | 114,377 | 114,010 | −0.3% |
|
||||
| param, 50 routes | 82,476 | 82,045 | −0.5% |
|
||||
| param, 200 routes | 72,957 | 73,306 | +0.5% |
|
||||
|
||||
Every row's sample ranges overlap. So with no code change, end-to-end throughput moves up to
|
||||
±1.9%; the route-width rows show that 200 filler routes already cost ~12% req/s against
|
||||
`param` with none.
|
||||
@@ -0,0 +1,207 @@
|
||||
{
|
||||
"rounds": 3,
|
||||
"duration": 10,
|
||||
"conns": 100,
|
||||
"rows": [
|
||||
{
|
||||
"name": "hello",
|
||||
"base": 88212.37,
|
||||
"head": 88235.64,
|
||||
"delta": 0.0263795202418936,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
82493.1,
|
||||
88503.28,
|
||||
88212.37
|
||||
],
|
||||
"head": [
|
||||
88177.46,
|
||||
88235.64,
|
||||
92826.19
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "param",
|
||||
"base": 86507.64,
|
||||
"head": 85885.1,
|
||||
"delta": -0.7196358610638246,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
81230.55,
|
||||
86757.82,
|
||||
86507.64
|
||||
],
|
||||
"head": [
|
||||
83412.37,
|
||||
86705.46,
|
||||
85885.1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "pipeline (3 steps)",
|
||||
"base": 80189.1,
|
||||
"head": 80933.82,
|
||||
"delta": 0.9287047740902455,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
76116.37,
|
||||
80189.1,
|
||||
80276.37
|
||||
],
|
||||
"head": [
|
||||
77035.64,
|
||||
80992,
|
||||
80933.82
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "steps5",
|
||||
"base": 74359.28,
|
||||
"head": 73975.28,
|
||||
"delta": -0.5164116704734096,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
75272.73,
|
||||
74359.28,
|
||||
73928.73
|
||||
],
|
||||
"head": [
|
||||
72235.64,
|
||||
74813.1,
|
||||
73975.28
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "validate (POST)",
|
||||
"base": 70606.55,
|
||||
"head": 69902.55,
|
||||
"delta": -0.997074634010584,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
70775.28,
|
||||
70606.55,
|
||||
69762.91
|
||||
],
|
||||
"head": [
|
||||
67138.91,
|
||||
74353.46,
|
||||
69902.55
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "hello + security",
|
||||
"base": 83912.73,
|
||||
"head": 83802.19,
|
||||
"delta": -0.13173209833596597,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
81928.73,
|
||||
84709.82,
|
||||
83912.73
|
||||
],
|
||||
"head": [
|
||||
81742.55,
|
||||
83802.19,
|
||||
84512
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "hello + cors predicate",
|
||||
"base": 82027.64,
|
||||
"head": 80445.1,
|
||||
"delta": -1.9292765219138253,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
82481.46,
|
||||
82027.64,
|
||||
81381.82
|
||||
],
|
||||
"head": [
|
||||
79368.73,
|
||||
82213.82,
|
||||
80445.1
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "preflight + cors predicate",
|
||||
"base": 114376.73,
|
||||
"head": 114010.19,
|
||||
"delta": -0.3204672838609686,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
114580.37,
|
||||
114376.73,
|
||||
112322.91
|
||||
],
|
||||
"head": [
|
||||
109669.82,
|
||||
114813.1,
|
||||
114010.19
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "param, 50 routes",
|
||||
"base": 82475.64,
|
||||
"head": 82045.1,
|
||||
"delta": -0.5220208051734956,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
82562.91,
|
||||
82475.64,
|
||||
82178.91
|
||||
],
|
||||
"head": [
|
||||
78891.64,
|
||||
82045.1,
|
||||
82388.37
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "param, 200 routes",
|
||||
"base": 72957.1,
|
||||
"head": 73306.19,
|
||||
"delta": 0.47848667230467834,
|
||||
"separated": false,
|
||||
"samples": {
|
||||
"base": [
|
||||
72986.19,
|
||||
72957.1,
|
||||
72194.91
|
||||
],
|
||||
"head": [
|
||||
72055.28,
|
||||
73306.19,
|
||||
73381.82
|
||||
]
|
||||
}
|
||||
}
|
||||
],
|
||||
"cors": {
|
||||
"base": {
|
||||
"get": 1,
|
||||
"preflight": 1
|
||||
},
|
||||
"head": {
|
||||
"get": 1,
|
||||
"preflight": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
[compare] round 1 base hello 82,493 req/s
|
||||
[compare] round 1 base param 81,231 req/s
|
||||
[compare] round 1 base pipeline (3 steps) 76,116 req/s
|
||||
[compare] round 1 base steps5 75,273 req/s
|
||||
[compare] round 1 base validate (POST) 70,775 req/s
|
||||
[compare] round 1 base hello + security 81,929 req/s
|
||||
[compare] round 1 base hello + cors predicate 82,481 req/s
|
||||
[compare] round 1 base preflight + cors predicate 114,580 req/s
|
||||
[compare] round 1 base param, 50 routes 82,563 req/s
|
||||
[compare] round 1 base param, 200 routes 72,986 req/s
|
||||
[compare] round 1 head hello 88,177 req/s
|
||||
[compare] round 1 head param 83,412 req/s
|
||||
[compare] round 1 head pipeline (3 steps) 77,036 req/s
|
||||
[compare] round 1 head steps5 72,236 req/s
|
||||
[compare] round 1 head validate (POST) 67,139 req/s
|
||||
[compare] round 1 head hello + security 81,743 req/s
|
||||
[compare] round 1 head hello + cors predicate 79,369 req/s
|
||||
[compare] round 1 head preflight + cors predicate 109,670 req/s
|
||||
[compare] round 1 head param, 50 routes 78,892 req/s
|
||||
[compare] round 1 head param, 200 routes 72,055 req/s
|
||||
[compare] round 2 head hello 88,236 req/s
|
||||
[compare] round 2 head param 86,705 req/s
|
||||
[compare] round 2 head pipeline (3 steps) 80,992 req/s
|
||||
[compare] round 2 head steps5 74,813 req/s
|
||||
[compare] round 2 head validate (POST) 74,353 req/s
|
||||
[compare] round 2 head hello + security 83,802 req/s
|
||||
[compare] round 2 head hello + cors predicate 82,214 req/s
|
||||
[compare] round 2 head preflight + cors predicate 114,813 req/s
|
||||
[compare] round 2 head param, 50 routes 82,045 req/s
|
||||
[compare] round 2 head param, 200 routes 73,306 req/s
|
||||
[compare] round 2 base hello 88,503 req/s
|
||||
[compare] round 2 base param 86,758 req/s
|
||||
[compare] round 2 base pipeline (3 steps) 80,189 req/s
|
||||
[compare] round 2 base steps5 74,359 req/s
|
||||
[compare] round 2 base validate (POST) 70,607 req/s
|
||||
[compare] round 2 base hello + security 84,710 req/s
|
||||
[compare] round 2 base hello + cors predicate 82,028 req/s
|
||||
[compare] round 2 base preflight + cors predicate 114,377 req/s
|
||||
[compare] round 2 base param, 50 routes 82,476 req/s
|
||||
[compare] round 2 base param, 200 routes 72,957 req/s
|
||||
[compare] round 3 base hello 88,212 req/s
|
||||
[compare] round 3 base param 86,508 req/s
|
||||
[compare] round 3 base pipeline (3 steps) 80,276 req/s
|
||||
[compare] round 3 base steps5 73,929 req/s
|
||||
[compare] round 3 base validate (POST) 69,763 req/s
|
||||
[compare] round 3 base hello + security 83,913 req/s
|
||||
[compare] round 3 base hello + cors predicate 81,382 req/s
|
||||
[compare] round 3 base preflight + cors predicate 112,323 req/s
|
||||
[compare] round 3 base param, 50 routes 82,179 req/s
|
||||
[compare] round 3 base param, 200 routes 72,195 req/s
|
||||
[compare] round 3 head hello 92,826 req/s
|
||||
[compare] round 3 head param 85,885 req/s
|
||||
[compare] round 3 head pipeline (3 steps) 80,934 req/s
|
||||
[compare] round 3 head steps5 73,975 req/s
|
||||
[compare] round 3 head validate (POST) 69,903 req/s
|
||||
[compare] round 3 head hello + security 84,512 req/s
|
||||
[compare] round 3 head hello + cors predicate 80,445 req/s
|
||||
[compare] round 3 head preflight + cors predicate 114,010 req/s
|
||||
[compare] round 3 head param, 50 routes 82,388 req/s
|
||||
[compare] round 3 head param, 200 routes 73,382 req/s
|
||||
@@ -0,0 +1,21 @@
|
||||
|
||||
> @green-tea/core@26.9.0-beta.2 bench:compare
|
||||
> tsx bench/compare.ts
|
||||
|
||||
|
||||
| Scenario | base | head | Δ | |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| hello | 88,212 | 88,236 | +0.0% | overlaps |
|
||||
| param | 86,508 | 85,885 | -0.7% | overlaps |
|
||||
| pipeline (3 steps) | 80,189 | 80,934 | +0.9% | overlaps |
|
||||
| steps5 | 74,359 | 73,975 | -0.5% | overlaps |
|
||||
| validate (POST) | 70,607 | 69,903 | -1.0% | overlaps |
|
||||
| hello + security | 83,913 | 83,802 | -0.1% | overlaps |
|
||||
| hello + cors predicate | 82,028 | 80,445 | -1.9% | overlaps |
|
||||
| preflight + cors predicate | 114,377 | 114,010 | -0.3% | overlaps |
|
||||
| param, 50 routes | 82,476 | 82,045 | -0.5% | overlaps |
|
||||
| param, 200 routes | 72,957 | 73,306 | +0.5% | overlaps |
|
||||
|
||||
cors.origins calls — base: 1 per GET, 1 per preflight
|
||||
cors.origins calls — head: 1 per GET, 1 per preflight
|
||||
exit 0
|
||||
@@ -0,0 +1,6 @@
|
||||
uptime before: 17:01 up 9 days, 7:50, 1 user, load averages: 2.47 2.14 6.86
|
||||
uptime after: 17:02 up 9 days, 7:51, 1 user, load averages: 2.58 2.21 6.64
|
||||
A/A uptime before: 17:02 up 9 days, 7:51, 1 user, load averages: 3.42 2.40 6.66
|
||||
A/A uptime after: 17:03 up 9 days, 7:53, 1 user, load averages: 2.89 2.48 6.26
|
||||
bench:compare uptime before: 17:04 up 9 days, 7:53, 1 user, load averages: 2.98 2.51 6.25
|
||||
bench:compare uptime after: 17:26 up 9 days, 8:15, 1 user, load averages: 2.82 3.32 4.29
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,33 @@
|
||||
|
||||
> @green-tea/core@26.9.0-beta.2 bench:lookup
|
||||
> tsx bench/lookup.ts
|
||||
|
||||
| router | routes | workload | median ns/op | run medians (ns) | run spread |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| live | 10 | static hit | 62.0 | 57.9 / 65.8 / 60.3 / 62.7 / 61.8 | 12.7% |
|
||||
| live | 10 | late param hit | 123.8 | 124.0 / 120.4 / 122.1 / 124.3 / 128.4 | 6.4% |
|
||||
| live | 10 | method miss | 309.0 | 305.7 / 305.6 / 320.1 / 310.8 / 311.6 | 4.7% |
|
||||
| live | 10 | path miss | 248.4 | 242.7 / 242.5 / 253.7 / 251.0 / 248.7 | 4.5% |
|
||||
| live | 100 | static hit | 69.5 | 66.7 / 68.7 / 69.2 / 71.6 / 71.5 | 7.1% |
|
||||
| live | 100 | late param hit | 352.2 | 345.1 / 348.3 / 349.9 / 355.2 / 365.1 | 5.7% |
|
||||
| live | 100 | method miss | 1265.3 | 1273.8 / 1256.0 / 1254.2 / 1279.7 / 1267.1 | 2.0% |
|
||||
| live | 100 | path miss | 1464.9 | 1462.8 / 1451.3 / 1462.3 / 1485.2 / 1470.6 | 2.3% |
|
||||
| live | 500 | static hit | 67.8 | 67.2 / 66.9 / 68.1 / 69.3 / 67.7 | 3.4% |
|
||||
| live | 500 | late param hit | 1313.7 | 1362.0 / 1293.9 / 1309.7 / 1313.7 / 1316.9 | 5.2% |
|
||||
| live | 500 | method miss | 6778.2 | 7068.9 / 6783.2 / 6634.3 / 6816.4 / 6689.2 | 6.4% |
|
||||
| live | 500 | path miss | 9005.3 | 9445.9 / 9015.5 / 8965.0 / 9032.4 / 8834.1 | 6.8% |
|
||||
| oracle | 10 | static hit | 65.2 | 62.2 / 66.6 / 66.6 / 65.2 / 58.0 | 13.1% |
|
||||
| oracle | 10 | late param hit | 123.9 | 130.7 / 123.5 / 125.2 / 122.9 / 120.1 | 8.5% |
|
||||
| oracle | 10 | method miss | 312.7 | 311.4 / 314.2 / 312.2 / 316.8 / 309.1 | 2.4% |
|
||||
| oracle | 10 | path miss | 249.0 | 248.6 / 253.1 / 247.3 / 249.0 / 248.9 | 2.3% |
|
||||
| oracle | 100 | static hit | 69.4 | 69.5 / 71.1 / 69.8 / 67.5 / 66.7 | 6.4% |
|
||||
| oracle | 100 | late param hit | 349.3 | 347.5 / 352.5 / 349.6 / 347.2 / 354.0 | 1.9% |
|
||||
| oracle | 100 | method miss | 1263.6 | 1294.1 / 1243.1 / 1251.2 / 1286.5 / 1258.0 | 4.0% |
|
||||
| oracle | 100 | path miss | 1466.2 | 1511.6 / 1464.0 / 1459.5 / 1480.7 / 1449.1 | 4.3% |
|
||||
| oracle | 500 | static hit | 66.0 | 67.0 / 67.3 / 65.8 / 64.9 / 65.1 | 3.6% |
|
||||
| oracle | 500 | late param hit | 1317.6 | 1313.2 / 1310.2 / 1323.5 / 1294.5 / 1363.2 | 5.2% |
|
||||
| oracle | 500 | method miss | 6753.3 | 6717.3 / 6758.7 / 6666.4 / 6876.3 / 6750.7 | 3.1% |
|
||||
| oracle | 500 | path miss | 9015.3 | 8998.0 / 9021.6 / 8980.8 / 9100.7 / 8884.0 | 2.4% |
|
||||
|
||||
load average: start 3.42 2.40 6.66, end 2.89 2.48 6.26
|
||||
raw samples: bench/baseline/router-ed47836/lookup-aa-raw.json
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,21 @@
|
||||
|
||||
> @green-tea/core@26.9.0-beta.2 bench:lookup
|
||||
> tsx bench/lookup.ts
|
||||
|
||||
| router | routes | workload | median ns/op | run medians (ns) | run spread |
|
||||
| --- | --- | --- | --- | --- | --- |
|
||||
| live | 10 | static hit | 61.3 | 64.4 / 61.0 / 68.4 / 58.0 / 57.6 | 17.5% |
|
||||
| live | 10 | late param hit | 123.3 | 122.4 / 128.1 / 123.3 / 123.7 / 120.4 | 6.2% |
|
||||
| live | 10 | method miss | 313.1 | 303.2 / 314.0 / 317.6 / 317.2 / 304.7 | 4.6% |
|
||||
| live | 10 | path miss | 247.1 | 243.8 / 246.0 / 256.5 / 251.7 / 239.7 | 6.8% |
|
||||
| live | 100 | static hit | 67.6 | 67.6 / 70.3 / 71.7 / 66.9 / 66.3 | 8.0% |
|
||||
| live | 100 | late param hit | 343.4 | 339.7 / 345.5 / 346.8 / 343.0 / 341.0 | 2.1% |
|
||||
| live | 100 | method miss | 1263.7 | 1253.2 / 1236.5 / 1280.9 / 1261.0 / 1264.6 | 3.5% |
|
||||
| live | 100 | path miss | 1463.3 | 1444.6 / 1442.4 / 1489.2 / 1467.6 / 1467.1 | 3.2% |
|
||||
| live | 500 | static hit | 67.8 | 69.7 / 68.1 / 68.2 / 64.6 / 65.1 | 7.5% |
|
||||
| live | 500 | late param hit | 1326.8 | 1480.6 / 1262.0 / 1309.9 / 1328.9 / 1331.8 | 16.5% |
|
||||
| live | 500 | method miss | 6732.2 | 7072.0 / 6659.6 / 6796.0 / 6631.5 / 6699.6 | 6.5% |
|
||||
| live | 500 | path miss | 8973.4 | 8915.3 / 8994.7 / 9052.0 / 8876.0 / 8981.4 | 2.0% |
|
||||
|
||||
load average: start 2.47 2.14 6.86, end 2.58 2.21 6.64
|
||||
raw samples: bench/baseline/router-ed47836/lookup-raw.json
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
/**
|
||||
* Focused route-lookup benchmark — the D4 instrument for the radix router (FPRD-001 CARD-08/10, #109).
|
||||
*
|
||||
* `bench:compare` measures req/s end to end, where lookup is a few percent of a request and drowns
|
||||
* in socket and pipeline noise. This measures the lookup alone: exactly what `dispatch` in
|
||||
* `src/http/core.ts` does with an already-normalized path — `resolveRoute`, and on a miss
|
||||
* `allowedMethods` for the 404/405 decision. Normalization is excluded: CARD-07 does not touch it.
|
||||
*
|
||||
* Usage:
|
||||
*
|
||||
* npm run bench:lookup
|
||||
* LOOKUP_ROUTERS="base=/tmp/base/src/http/router.ts,head=src/http/router.ts" npm run bench:lookup
|
||||
*
|
||||
* Each implementation is a module exporting `resolveRoute` and `allowedMethods` with the
|
||||
* `src/http/router.ts` signatures. With several, every run measures all of them in separate child
|
||||
* processes, alternating which goes first, on the same generated tables. Do not edit the generator,
|
||||
* the workloads or the defaults below between a baseline and its comparison — they are the method.
|
||||
*
|
||||
* Env: `LOOKUP_ROUTERS` (label=path list, default `live=src/http/router.ts`), `LOOKUP_RUNS` (5),
|
||||
* `LOOKUP_SAMPLES` (21 per cell per run), `LOOKUP_SAMPLE_MS` (25), `LOOKUP_WARMUP_MS` (250),
|
||||
* `LOOKUP_OUT` (bench/lookup-results.json).
|
||||
*/
|
||||
import { spawn, execFileSync } from 'child_process';
|
||||
import { writeFileSync, readFileSync } from 'fs';
|
||||
import os from 'os';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { pathToFileURL } from 'url';
|
||||
|
||||
const ROUTE_COUNTS = [10, 100, 500];
|
||||
const RUNS = Number(process.env.LOOKUP_RUNS ?? 5);
|
||||
const SAMPLES = Number(process.env.LOOKUP_SAMPLES ?? 21);
|
||||
const SAMPLE_MS = Number(process.env.LOOKUP_SAMPLE_MS ?? 25);
|
||||
const WARMUP_MS = Number(process.env.LOOKUP_WARMUP_MS ?? 250);
|
||||
const OUT = process.env.LOOKUP_OUT ?? 'bench/lookup-results.json';
|
||||
|
||||
interface Route {
|
||||
method: string;
|
||||
pattern: string;
|
||||
transport: 'buffer';
|
||||
handler: () => Promise<{ status: number; headers: Record<string, string>; body: string }>;
|
||||
}
|
||||
|
||||
interface RouterModule {
|
||||
resolveRoute(routes: Route[], method: string, path: string): { def: Route } | undefined;
|
||||
allowedMethods(routes: Route[], path: string): string[];
|
||||
}
|
||||
|
||||
/** Five REST-shaped filler routes per resource, cycled, so every count has statics, params, constraints and catch-alls. */
|
||||
const FILLER: Array<(k: number) => [string, string]> = [
|
||||
(k) => ['GET', `/res${k}/items`],
|
||||
(k) => ['POST', `/res${k}/items`],
|
||||
(k) => ['GET', `/res${k}/items/:id`],
|
||||
(k) => ['PUT', `/res${k}/items/:id(\\d+)`],
|
||||
(k) => ['GET', `/res${k}/files/:path*`],
|
||||
];
|
||||
|
||||
export const ROUTE_GENERATOR =
|
||||
'N total HTTP routes: N-2 fillers (i = 0..N-3, shape FILLER[i % 5] with k = floor(i / 5): GET /res{k}/items, ' +
|
||||
'POST /res{k}/items, GET /res{k}/items/:id, PUT /res{k}/items/:id(\\d+), GET /res{k}/files/:path*), then ' +
|
||||
'GET /static/target/leaf, then GET /late/:group/:id declared last. All buffer transport.';
|
||||
|
||||
const handler = async () => ({ status: 200, headers: {}, body: '' });
|
||||
|
||||
export function buildRoutes(total: number): Route[] {
|
||||
const fillers = Array.from({ length: total - 2 }, (_, i): Route => {
|
||||
const [method, pattern] = FILLER[i % FILLER.length](Math.floor(i / FILLER.length));
|
||||
return { method, pattern, transport: 'buffer', handler };
|
||||
});
|
||||
return [
|
||||
...fillers,
|
||||
{ method: 'GET', pattern: '/static/target/leaf', transport: 'buffer', handler },
|
||||
{ method: 'GET', pattern: '/late/:group/:id', transport: 'buffer', handler },
|
||||
];
|
||||
}
|
||||
|
||||
interface Workload {
|
||||
name: string;
|
||||
method: string;
|
||||
path: string;
|
||||
/** What the lookup must answer; checked before timing, so a broken implementation cannot post a number. */
|
||||
expect: string;
|
||||
}
|
||||
|
||||
export const WORKLOADS: Workload[] = [
|
||||
{ name: 'static hit', method: 'GET', path: '/static/target/leaf', expect: 'hit /static/target/leaf' },
|
||||
{ name: 'late param hit', method: 'GET', path: '/late/g1/42', expect: 'hit /late/:group/:id' },
|
||||
{ name: 'method miss', method: 'DELETE', path: '/static/target/leaf', expect: 'allow GET,HEAD,OPTIONS' },
|
||||
{ name: 'path miss', method: 'GET', path: '/nowhere/at/all', expect: 'allow ' },
|
||||
];
|
||||
|
||||
/** One lookup, as `dispatch` performs it. Returns a value so the work cannot be optimised away. */
|
||||
function lookup(router: RouterModule, routes: Route[], w: Workload): string {
|
||||
const matched = router.resolveRoute(routes, w.method, w.path);
|
||||
if (matched) return `hit ${matched.def.pattern}`;
|
||||
return `allow ${router.allowedMethods(routes, w.path).join(',')}`;
|
||||
}
|
||||
|
||||
interface Cell {
|
||||
routes: number;
|
||||
workload: string;
|
||||
iterations: number;
|
||||
samplesNs: number[];
|
||||
}
|
||||
|
||||
function measure(router: RouterModule, routes: Route[], w: Workload): { iterations: number; samplesNs: number[] } {
|
||||
const answer = lookup(router, routes, w);
|
||||
if (answer !== w.expect) throw new Error(`${w.name} @ ${routes.length}: expected '${w.expect}', got '${answer}'`);
|
||||
|
||||
// Warm-up, time-boxed; it also calibrates how many iterations make one sample last SAMPLE_MS.
|
||||
let sink = 0;
|
||||
let ops = 0;
|
||||
const warmStart = process.hrtime.bigint();
|
||||
const warmBudget = BigInt(WARMUP_MS * 1_000_000);
|
||||
while (process.hrtime.bigint() - warmStart < warmBudget) {
|
||||
for (let i = 0; i < 100; i++) sink += lookup(router, routes, w).length;
|
||||
ops += 100;
|
||||
}
|
||||
const nsPerOp = Number(process.hrtime.bigint() - warmStart) / ops;
|
||||
const iterations = Math.max(100, Math.round((SAMPLE_MS * 1e6) / nsPerOp));
|
||||
|
||||
const samplesNs: number[] = [];
|
||||
for (let s = 0; s < SAMPLES; s++) {
|
||||
const start = process.hrtime.bigint();
|
||||
for (let i = 0; i < iterations; i++) sink += lookup(router, routes, w).length;
|
||||
samplesNs.push(Number(process.hrtime.bigint() - start) / iterations);
|
||||
}
|
||||
|
||||
if (sink === 42) process.stderr.write(''); // keeps `sink` observable
|
||||
return { iterations, samplesNs };
|
||||
}
|
||||
|
||||
async function child(label: string, path: string): Promise<void> {
|
||||
const router = (await import(pathToFileURL(resolve(path)).href)) as RouterModule;
|
||||
const cells: Cell[] = [];
|
||||
|
||||
for (const count of ROUTE_COUNTS) {
|
||||
const routes = buildRoutes(count);
|
||||
for (const w of WORKLOADS) cells.push({ routes: count, workload: w.name, ...measure(router, routes, w) });
|
||||
}
|
||||
|
||||
process.stdout.write(`${JSON.stringify({ label, cells })}\n`);
|
||||
}
|
||||
|
||||
function runChild(label: string, path: string): Promise<{ label: string; cells: Cell[] }> {
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
const proc = spawn(process.execPath, ['--import', 'tsx', 'bench/lookup.ts'], {
|
||||
env: { ...process.env, LOOKUP_CHILD: `${label}=${path}` },
|
||||
stdio: ['ignore', 'pipe', 'inherit'],
|
||||
});
|
||||
let out = '';
|
||||
proc.stdout.on('data', (d) => (out += d));
|
||||
proc.on('exit', (code) =>
|
||||
code === 0 ? resolvePromise(JSON.parse(out)) : reject(new Error(`${label} exited ${code}`)),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
const median = (xs: number[]): number => {
|
||||
const s = [...xs].sort((a, b) => a - b);
|
||||
const m = s.length >> 1;
|
||||
return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
|
||||
};
|
||||
|
||||
function git(cwd: string, ...args: string[]): string {
|
||||
try {
|
||||
return execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8' }).trim();
|
||||
} catch {
|
||||
return 'unavailable';
|
||||
}
|
||||
}
|
||||
|
||||
function environment(routers: Array<[string, string]>) {
|
||||
const pkg = JSON.parse(readFileSync('package.json', 'utf8')) as { name: string; version: string };
|
||||
return {
|
||||
startedAt: new Date().toISOString(),
|
||||
node: process.version,
|
||||
v8: process.versions.v8,
|
||||
platform: `${os.platform()} ${os.release()} ${os.arch()}`,
|
||||
cpu: os.cpus()[0]?.model,
|
||||
cpus: os.cpus().length,
|
||||
memoryBytes: os.totalmem(),
|
||||
loadavgAtStart: os.loadavg(),
|
||||
package: `${pkg.name}@${pkg.version}`,
|
||||
harnessCommit: git('.', 'rev-parse', 'HEAD'),
|
||||
routers: routers.map(([label, path]) => ({
|
||||
label,
|
||||
path,
|
||||
commit: git(dirname(resolve(path)), 'rev-parse', 'HEAD'),
|
||||
dirty: git(dirname(resolve(path)), 'status', '--porcelain', '--', resolve(path)) !== '',
|
||||
})),
|
||||
env: Object.fromEntries(
|
||||
Object.entries(process.env).filter(([k]) => k.startsWith('LOOKUP_') || k === 'NODE_OPTIONS'),
|
||||
),
|
||||
method: {
|
||||
routeCounts: ROUTE_COUNTS,
|
||||
routeCountMeaning: 'total registered HTTP routes',
|
||||
routeGenerator: ROUTE_GENERATOR,
|
||||
workloads: WORKLOADS,
|
||||
workloadOrder:
|
||||
'for each run: for each router (order alternates per run): for count in routeCounts: for workload in workloads',
|
||||
operation: 'resolveRoute(routes, method, path); on undefined, allowedMethods(routes, path)',
|
||||
runs: RUNS,
|
||||
samplesPerCellPerRun: SAMPLES,
|
||||
sampleMs: SAMPLE_MS,
|
||||
warmupMsPerCell: WARMUP_MS,
|
||||
unit: 'ns per lookup (sample time / iterations)',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
if (process.env.LOOKUP_CHILD) {
|
||||
const [label, path] = process.env.LOOKUP_CHILD.split('=');
|
||||
return child(label, path);
|
||||
}
|
||||
|
||||
const routers = (process.env.LOOKUP_ROUTERS ?? 'live=src/http/router.ts')
|
||||
.split(',')
|
||||
.map((entry) => entry.split('=') as [string, string]);
|
||||
const meta = environment(routers);
|
||||
const runs: Array<{ run: number; order: string[]; label: string; cells: Cell[] }> = [];
|
||||
|
||||
for (let run = 0; run < RUNS; run++) {
|
||||
const order = run % 2 === 0 ? routers : [...routers].reverse();
|
||||
for (const [label, path] of order) {
|
||||
const result = await runChild(label, path);
|
||||
runs.push({ run: run + 1, order: order.map(([l]) => l), ...result });
|
||||
process.stderr.write(`[lookup] run ${run + 1}/${RUNS} ${label} done\n`);
|
||||
}
|
||||
}
|
||||
|
||||
const summary = routers.flatMap(([label]) =>
|
||||
ROUTE_COUNTS.flatMap((count) =>
|
||||
WORKLOADS.map((w) => {
|
||||
const cells = runs
|
||||
.filter((r) => r.label === label)
|
||||
.map((r) => r.cells.find((c) => c.routes === count && c.workload === w.name)!);
|
||||
const runMedians = cells.map((c) => median(c.samplesNs));
|
||||
const all = cells.flatMap((c) => c.samplesNs);
|
||||
const med = median(all);
|
||||
return {
|
||||
router: label,
|
||||
routes: count,
|
||||
workload: w.name,
|
||||
medianNs: med,
|
||||
runMediansNs: runMedians,
|
||||
runSpreadPct: ((Math.max(...runMedians) - Math.min(...runMedians)) / med) * 100,
|
||||
};
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
const loadavgAtEnd = os.loadavg();
|
||||
writeFileSync(OUT, `${JSON.stringify({ meta: { ...meta, loadavgAtEnd }, summary, runs }, null, 2)}\n`);
|
||||
|
||||
console.log('| router | routes | workload | median ns/op | run medians (ns) | run spread |');
|
||||
console.log('| --- | --- | --- | --- | --- | --- |');
|
||||
for (const row of summary) {
|
||||
const runsText = row.runMediansNs.map((n) => n.toFixed(1)).join(' / ');
|
||||
console.log(
|
||||
`| ${row.router} | ${row.routes} | ${row.workload} | ${row.medianNs.toFixed(1)} | ${runsText} | ${row.runSpreadPct.toFixed(1)}% |`,
|
||||
);
|
||||
}
|
||||
console.log(
|
||||
`\nload average: start ${meta.loadavgAtStart.map((n) => n.toFixed(2)).join(' ')}, end ${loadavgAtEnd.map((n) => n.toFixed(2)).join(' ')}`,
|
||||
);
|
||||
console.log(`raw samples: ${OUT}`);
|
||||
}
|
||||
|
||||
main().catch((e) => {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
});
|
||||
@@ -103,6 +103,7 @@
|
||||
"complexity:cyclomatic": "cyclomatic-complexity \"src/**/*.ts\" -tw 15 -te 25",
|
||||
"bench": "tsx bench/run.ts",
|
||||
"bench:compare": "tsx bench/compare.ts",
|
||||
"bench:lookup": "tsx bench/lookup.ts",
|
||||
"prepublishOnly": "npm run lint && npm run complexity:check && npm run typecheck && npm test && npm run build",
|
||||
"prepare": "git config core.hooksPath .githooks || true"
|
||||
},
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
# Router parity corpus (frozen)
|
||||
|
||||
The compatibility baseline for replacing the linear HTTP matcher with a radix index
|
||||
(FPRD-001 CARD-07/08/09/10, issue #109). Everything here was captured from
|
||||
`@green-tea/core` at **`ed47836c9820c47bf4ed5e902d91e019abdb110a`** (develop after #117 and #122).
|
||||
|
||||
## The rule
|
||||
|
||||
**The baseline is immutable through CARD-07 review.** If the router change makes a test here fail,
|
||||
the router changed behaviour. That is a compatibility failure, not a stale fixture.
|
||||
|
||||
A deliberate compatibility change needs its own maintainer approval, recorded on the card, and a
|
||||
reviewed edit to the specific frozen file, in a commit that says why. Do not edit a golden to make a
|
||||
test pass, do not edit `oracle.ts` to fit a new implementation, and do not delete a frozen file to
|
||||
let a capture run recreate it.
|
||||
|
||||
Nothing can regenerate the baseline by accident:
|
||||
|
||||
- `vitest -u` is refused with an error. These are plain JSON files, not vitest snapshots.
|
||||
- `ROUTER_PARITY_CAPTURE=1` only writes a frozen file that **does not exist**. It never
|
||||
overwrites. It is how the files were first captured, and how a new fixture gets added later.
|
||||
|
||||
## What is here
|
||||
|
||||
| File | What it freezes |
|
||||
|---|---|
|
||||
| `manifest.json` | Existing tests retained unchanged (ROUTER-CORPUS §1), with the verification result at the pinned revision. `manifest.test.ts` fails if a named file or test disappears. |
|
||||
| `oracle.ts` | Verbatim copy of the pre-radix `matchRoute`, `resolveRoute`, `allowedMethods`, `normalizeRequestPath`, `compilePattern` and `matchWsRoute`. Test-only; `src/` must never import it. |
|
||||
| `cases.ts`, `generator.ts` | Matcher inputs: 24 hand-picked scenarios (§2), 9 owner-requested scenarios (backtracking, cross-pattern `Allow`, encoded slashes, zero-segment catch-alls), and a fixed-seed generator in two versions, both seed `10908`: `router-parity-gen-v1`, and `router-parity-gen-v2`, which forces static/param/constrained/catch-all siblings under shared prefixes. |
|
||||
| `branches.ts` | Measures the share of generated requests that walk into sibling branches and backtrack; frozen with the v2 fixture. |
|
||||
| `frozen/matcher-*.json` | Captured matcher outputs: declaration ID, decoded params, `implicitHead`, ordered `Allow`, or the normalization error. The generated file also stores the seed, the generator rules and every generated input. |
|
||||
| `frozen/app-*.json` | Status, headers, `Allow` and body through `app.fetch` and through a Node socket, including HEAD body suppression. |
|
||||
| `frozen/ws-*.json` | WS upgrade selection through `app.upgrade` and the Node listener, plus HTTP requests at the WS paths. |
|
||||
| `frozen/owner-*.json` | Owner additions needing a running app: cross-pattern `Allow` through both adapters, and the mesh HTTP route table across a peer's lifetime (it is built once at boot and never changes — see `owner.test.ts`). |
|
||||
| `frozen/boot-*.json` | Boot-time rejections: pattern compilation, local ambiguity, mesh splicing. |
|
||||
| `frozen/golden-*.json` | `graph()`, `explain()`, `openapi({ title: 'Parity', version: '1' })`, and a mesh teacup before and after `ready()`. |
|
||||
|
||||
## How the comparison works
|
||||
|
||||
`matcher.test.ts` runs every scenario through the oracle **and** through the live
|
||||
`src/http/router` exports, and requires both to equal the frozen capture. Today the live router is
|
||||
the linear matcher, so this proves the oracle is a faithful copy. CARD-07 replaces the internals
|
||||
behind the same exports, and the same test then compares oracle against radix with no edit here.
|
||||
|
||||
Each run builds fresh `RouteDef` objects, so the two implementations never share a cached table, and
|
||||
the answering route is identified by declaration ID, never by pattern text.
|
||||
|
||||
Application-level, WS, boot and introspection files are compared against the live code only,
|
||||
because there is no second implementation of `app.fetch` to diff against; the frozen capture plays
|
||||
the oracle's role.
|
||||
|
||||
The performance half of the baseline is in `bench/lookup.ts` and `bench/baseline/router-ed47836/`.
|
||||
@@ -0,0 +1,234 @@
|
||||
/**
|
||||
* Application-level router parity: what a client sees through `app.fetch` and through a real Node
|
||||
* socket — status, `Allow`, response headers, and HEAD body suppression. Matcher equality alone
|
||||
* cannot prove these: the 404/405/OPTIONS decisions, the 400 for a bad path and the HEAD body rule
|
||||
* live in `src/http/core.ts`, around the matcher.
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import http from 'http';
|
||||
import type { AddressInfo } from 'net';
|
||||
import { describe, it, beforeAll, afterAll } from 'vitest';
|
||||
import { createApp, Route, Get, Head, Post, Put, Patch, Delete, Options, Sse, Module, param } from '../../src/index';
|
||||
import type { App } from '../../src/app/types';
|
||||
import { frozen, expectFrozenEqual } from './frozen';
|
||||
|
||||
const reply = (id: string, params: Record<string, string>) => ({ id, params });
|
||||
|
||||
// Ordered on purpose: the overlapping declarations are registered least-specific first, so a
|
||||
// lookup that fell back to registration order would answer differently from one that ranks.
|
||||
@Route('/')
|
||||
class ParityHttp {
|
||||
@Get('/a/:rest*') aRest(@param() p: Record<string, string>) {
|
||||
return reply('aRest', p);
|
||||
}
|
||||
@Get('/a/:id') aId(@param() p: Record<string, string>) {
|
||||
return reply('aId', p);
|
||||
}
|
||||
@Get('/a/b') aB(@param() p: Record<string, string>) {
|
||||
return reply('aB', p);
|
||||
}
|
||||
@Get('/users/:value') usersValue(@param() p: Record<string, string>) {
|
||||
return reply('usersValue', p);
|
||||
}
|
||||
@Get('/users/:id(\\d+)') usersId(@param() p: Record<string, string>) {
|
||||
return reply('usersId', p);
|
||||
}
|
||||
@Get('/n/:num(\\d+)') nNum(@param() p: Record<string, string>) {
|
||||
return reply('nNum', p);
|
||||
}
|
||||
@Get('/n/:code([0-9a-f]+)') nCode(@param() p: Record<string, string>) {
|
||||
return reply('nCode', p);
|
||||
}
|
||||
@Get('/files') files(@param() p: Record<string, string>) {
|
||||
return reply('files', p);
|
||||
}
|
||||
@Get('/files/:rest*') filesRest(@param() p: Record<string, string>) {
|
||||
return reply('filesRest', p);
|
||||
}
|
||||
@Get('/m') mGet(@param() p: Record<string, string>) {
|
||||
return reply('mGet', p);
|
||||
}
|
||||
@Post('/m') mPost(@param() p: Record<string, string>) {
|
||||
return reply('mPost', p);
|
||||
}
|
||||
@Get('/h') hGet(@param() p: Record<string, string>) {
|
||||
return reply('hGet', p);
|
||||
}
|
||||
@Head('/h') hHead(@param() p: Record<string, string>) {
|
||||
return reply('hHead', p);
|
||||
}
|
||||
@Sse('/stream') stream() {
|
||||
return (async function* () {
|
||||
yield { id: 'stream' };
|
||||
})();
|
||||
}
|
||||
@Sse('/s/live') sLive() {
|
||||
return (async function* () {
|
||||
yield { id: 'sLive' };
|
||||
})();
|
||||
}
|
||||
@Get('/s/:id') sId(@param() p: Record<string, string>) {
|
||||
return reply('sId', p);
|
||||
}
|
||||
@Get('/Case') caseUpper(@param() p: Record<string, string>) {
|
||||
return reply('caseUpper', p);
|
||||
}
|
||||
@Get('/u/:name') uName(@param() p: Record<string, string>) {
|
||||
return reply('uName', p);
|
||||
}
|
||||
@Get('/admin') admin(@param() p: Record<string, string>) {
|
||||
return reply('admin', p);
|
||||
}
|
||||
@Get('/public/:file') publicFile(@param() p: Record<string, string>) {
|
||||
return reply('publicFile', p);
|
||||
}
|
||||
@Delete('/r') rDelete(@param() p: Record<string, string>) {
|
||||
return reply('rDelete', p);
|
||||
}
|
||||
@Patch('/r') rPatch(@param() p: Record<string, string>) {
|
||||
return reply('rPatch', p);
|
||||
}
|
||||
@Options('/r') rOptions(@param() p: Record<string, string>) {
|
||||
return reply('rOptions', p);
|
||||
}
|
||||
@Put('/r') rPut(@param() p: Record<string, string>) {
|
||||
return reply('rPut', p);
|
||||
}
|
||||
@Get('/') root(@param() p: Record<string, string>) {
|
||||
return reply('root', p);
|
||||
}
|
||||
}
|
||||
|
||||
@Module({ mountpoint: '/', controllers: [ParityHttp] })
|
||||
class ParityHttpModule {}
|
||||
|
||||
type Req = [method: string, raw: string];
|
||||
|
||||
const REQUESTS: Req[] = [
|
||||
['GET', '/a/b'],
|
||||
['GET', '/a/x'],
|
||||
['GET', '/a/x/y'],
|
||||
['GET', '/a'],
|
||||
['GET', '/users/42'],
|
||||
['GET', '/users/alice'],
|
||||
['GET', '/users/a%20b'],
|
||||
['GET', '/n/42'],
|
||||
['GET', '/n/ff'],
|
||||
['GET', '/files'],
|
||||
['GET', '/files/'],
|
||||
['GET', '/files/a%2Fb'],
|
||||
['GET', '/m'],
|
||||
['HEAD', '/m'],
|
||||
['OPTIONS', '/m'],
|
||||
['PUT', '/m'],
|
||||
['DELETE', '/m'],
|
||||
['POST', '/m'],
|
||||
['GET', '/h'],
|
||||
['HEAD', '/h'],
|
||||
['GET', '/stream'],
|
||||
['HEAD', '/stream'],
|
||||
['OPTIONS', '/stream'],
|
||||
['HEAD', '/s/live'],
|
||||
['HEAD', '/s/x'],
|
||||
['GET', '/absent'],
|
||||
['HEAD', '/absent'],
|
||||
['OPTIONS', '/absent'],
|
||||
['GET', '/users/%E0%A4%A'],
|
||||
['HEAD', '/users/%E0%A4%A'],
|
||||
['GET', '/a//b'],
|
||||
['GET', '/Case'],
|
||||
['GET', '/case'],
|
||||
['GET', '/caf%C3%A9'],
|
||||
['GET', '/u/caf%C3%A9'],
|
||||
['GET', '/public/../admin'],
|
||||
['GET', '/public/%2e%2e/admin'],
|
||||
['GET', '/public/..%2fadmin'],
|
||||
['GET', '/admin/'],
|
||||
['OPTIONS', '/r'],
|
||||
['HEAD', '/r'],
|
||||
['GET', '/r'],
|
||||
['PURGE', '/r'], // TRACE is a forbidden method for `new Request`
|
||||
['GET', '/'],
|
||||
['GET', '/?q=1'],
|
||||
];
|
||||
|
||||
/** Headers that vary per run or per connection rather than per route decision. */
|
||||
const VOLATILE = new Set(['date', 'connection', 'keep-alive', 'x-request-id']);
|
||||
|
||||
function stableHeaders(entries: Iterable<[string, string]>): Record<string, string> {
|
||||
const out: Record<string, string> = {};
|
||||
for (const [name, value] of [...entries].sort(([a], [b]) => a.localeCompare(b)))
|
||||
if (!VOLATILE.has(name)) out[name] = value;
|
||||
return out;
|
||||
}
|
||||
|
||||
interface Observed {
|
||||
method: string;
|
||||
raw: string;
|
||||
status: number;
|
||||
headers: Record<string, string>;
|
||||
body: string;
|
||||
}
|
||||
|
||||
async function viaFetch(app: App, [method, raw]: Req): Promise<Observed> {
|
||||
// `new Request` applies the URL parser first — exactly what Deno, Bun and workerd do.
|
||||
const res = await app.fetch(new Request(`http://parity.test${raw}`, { method }));
|
||||
return { method, raw, status: res.status, headers: stableHeaders(res.headers), body: await res.text() };
|
||||
}
|
||||
|
||||
function viaNode(port: number, [method, raw]: Req): Promise<Observed> {
|
||||
// `http.request` sends the path bytes as given, so the server sees the raw target.
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request({ host: '127.0.0.1', port, method, path: raw, agent: false }, (res) => {
|
||||
let body = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', (chunk) => (body += chunk));
|
||||
res.on('end', () => {
|
||||
const headers = Object.entries(res.headers).map(([k, v]): [string, string] => [
|
||||
k,
|
||||
Array.isArray(v) ? v.join(', ') : String(v),
|
||||
]);
|
||||
resolve({ method, raw, status: res.statusCode ?? 0, headers: stableHeaders(headers), body });
|
||||
});
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
describe('router parity: application-level HTTP outcomes', () => {
|
||||
let fetchApp: App;
|
||||
let nodeApp: App;
|
||||
let port: number;
|
||||
|
||||
beforeAll(async () => {
|
||||
fetchApp = createApp({ modules: [ParityHttpModule] });
|
||||
nodeApp = createApp({ modules: [ParityHttpModule] });
|
||||
const server = await nodeApp.listen(0);
|
||||
port = (server.address() as AddressInfo).port;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await nodeApp.close();
|
||||
});
|
||||
|
||||
it('app.fetch outcomes equal the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: Observed[] = [];
|
||||
for (const req of REQUESTS) out.push(await viaFetch(fetchApp, req));
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('app-fetch', run);
|
||||
expectFrozenEqual(await run(), expected, 'app.fetch');
|
||||
});
|
||||
|
||||
it('Node listener outcomes equal the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: Observed[] = [];
|
||||
for (const req of REQUESTS) out.push(await viaNode(port, req));
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('app-node', run);
|
||||
expectFrozenEqual(await run(), expected, 'node listener');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,315 @@
|
||||
/**
|
||||
* Boot-time rejection parity: invalid patterns, local ambiguity and mesh route splicing. These are
|
||||
* not inputs to the differential matcher — a pattern that fails here never reaches a lookup — so
|
||||
* they are frozen as their own expected-error fixture: the rejection point (pattern compile, app
|
||||
* construction, mesh `ready()`), the error class and the exact message.
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import type { AddressInfo } from 'net';
|
||||
import { describe, it } from 'vitest';
|
||||
import { createApp, Route, Get, Post, Sse, Ws, Module, param } from '../../src/index';
|
||||
import type { RouteDecorator } from '../../src/metadata';
|
||||
import type { Logger } from '../../src/logger';
|
||||
import * as live from '../../src/http/router';
|
||||
import * as oracle from './oracle';
|
||||
import { errorOutcome, type ErrorOutcome } from './matcher';
|
||||
import { frozen, expectFrozenEqual } from './frozen';
|
||||
|
||||
const PATTERNS = [
|
||||
'/',
|
||||
'/users/:id',
|
||||
'/users/:id(\\d+)',
|
||||
'/files/:rest*',
|
||||
'/:rest*',
|
||||
'/t/',
|
||||
'/café',
|
||||
'/build/:version(\\d{2}\\.\\d{1,2})',
|
||||
'/x/:id/:id',
|
||||
'/x/:id/:rest*/tail',
|
||||
'/x/:rest*/:rest*',
|
||||
'/x/:',
|
||||
'/x/:1x',
|
||||
'/x//y',
|
||||
'x',
|
||||
'',
|
||||
'/x/:id((a+)+)',
|
||||
'/x/:id((?=a)a)',
|
||||
'/x/:id(\\1)',
|
||||
'/x/:id(a|b)',
|
||||
'/x/:id(\\d+\\w+)',
|
||||
'/x/:id(\\d{5,2})',
|
||||
'/x/:id(\\d{1,4096})',
|
||||
'/x/:id(\\d+',
|
||||
'/x/:id()',
|
||||
`/x/:id(${'a'.repeat(129)})`,
|
||||
];
|
||||
|
||||
type PatternOutcome = { pattern: string; shape: string } | { pattern: string; error: ErrorOutcome };
|
||||
|
||||
function compileAll(compile: (pattern: string) => { shape: string }): PatternOutcome[] {
|
||||
return PATTERNS.map((pattern) => {
|
||||
try {
|
||||
return { pattern, shape: compile(pattern).shape };
|
||||
} catch (error) {
|
||||
return { pattern, error: errorOutcome(error) };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
type Decl = [decorator: RouteDecorator, path: string];
|
||||
|
||||
/** One controller per case, its handlers declared in the given order (decorators applied by hand). */
|
||||
function moduleWith(decls: Decl[]) {
|
||||
class ParityBoot {}
|
||||
decls.forEach(([decorator, path], index) => {
|
||||
const name = `h${index}`;
|
||||
Object.defineProperty(ParityBoot.prototype, name, {
|
||||
value: () => (async function* () {})(),
|
||||
configurable: true,
|
||||
});
|
||||
decorator(path)(ParityBoot.prototype, name, Object.getOwnPropertyDescriptor(ParityBoot.prototype, name)!);
|
||||
});
|
||||
Route('/')(ParityBoot);
|
||||
class ParityBootModule {}
|
||||
Module({ mountpoint: '/', controllers: [ParityBoot] })(ParityBootModule);
|
||||
return ParityBootModule;
|
||||
}
|
||||
|
||||
const APP_CASES: Array<{ id: string; decls: Decl[] }> = [
|
||||
{ id: 'B01-duplicate-param', decls: [[Get, '/x/:id/:id']] },
|
||||
{ id: 'B02-nonfinal-catch-all', decls: [[Get, '/x/:rest*/tail']] },
|
||||
{ id: 'B03-nested-quantifier', decls: [[Get, '/x/:id((a+)+)']] },
|
||||
{ id: 'B04-alternation', decls: [[Get, '/x/:id(a|b)']] },
|
||||
{ id: 'B05-adjacent-unbounded', decls: [[Get, '/x/:id(\\d+\\w+)']] },
|
||||
{ id: 'B06-inverted-quantifier', decls: [[Get, '/x/:id(\\d{5,2})']] },
|
||||
{ id: 'B07-invalid-param-name', decls: [[Get, '/x/:1x']] },
|
||||
{ id: 'B08-malformed-constraint', decls: [[Get, '/x/:id(\\d+']] },
|
||||
{
|
||||
id: 'B09-same-shape-plain',
|
||||
decls: [
|
||||
[Get, '/users/:id'],
|
||||
[Get, '/users/:name'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B10-same-shape-constrained',
|
||||
decls: [
|
||||
[Get, '/c/:a(\\d+)'],
|
||||
[Get, '/c/:b(\\d+)'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B11-trailing-slash-twin',
|
||||
decls: [
|
||||
[Get, '/t'],
|
||||
[Get, '/t/'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B12-get-and-ws-same-path',
|
||||
decls: [
|
||||
[Get, '/live'],
|
||||
[Ws, '/live'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B13-get-and-sse-same-path',
|
||||
decls: [
|
||||
[Get, '/feed'],
|
||||
[Sse, '/feed'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B14-ws-same-shape',
|
||||
decls: [
|
||||
[Ws, '/w/:a'],
|
||||
[Ws, '/w/:b'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B15-ok-same-shape-different-methods',
|
||||
decls: [
|
||||
[Get, '/users/:id'],
|
||||
[Post, '/users/:name'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B16-ok-different-constraints',
|
||||
decls: [
|
||||
[Get, '/c/:a(\\d+)'],
|
||||
[Get, '/c/:b([a-z]+)'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B17-ok-static-and-param',
|
||||
decls: [
|
||||
[Get, '/users/me'],
|
||||
[Get, '/users/:id'],
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 'B18-ok-exact-and-catch-all',
|
||||
decls: [
|
||||
[Get, '/f'],
|
||||
[Get, '/f/:rest*'],
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const LABELS = new Map<RouteDecorator, string>([
|
||||
[Get, '@Get'],
|
||||
[Post, '@Post'],
|
||||
[Sse, '@Sse'],
|
||||
[Ws, '@Ws'],
|
||||
]);
|
||||
|
||||
function bootAll() {
|
||||
return APP_CASES.map(({ id, decls }) => {
|
||||
const declarations = decls.map(([decorator, path]) => `${LABELS.get(decorator)}('${path}')`);
|
||||
try {
|
||||
createApp({ modules: [moduleWith(decls)] });
|
||||
return { id, declarations, ok: true };
|
||||
} catch (error) {
|
||||
return { id, declarations, error: errorOutcome(error) };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ── mesh ────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const SECRET = 'parity-secret';
|
||||
|
||||
@Route('/dup')
|
||||
class DupCtl {
|
||||
@Get('/ping', { export: true }) ping() {
|
||||
return { from: 'teapot' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [DupCtl] })
|
||||
class DupTeapotModule {}
|
||||
|
||||
@Route('/shape')
|
||||
class ShapeIdCtl {
|
||||
@Get('/:id', { export: true }) get(@param() p: Record<string, string>) {
|
||||
return { from: 'id', p };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [ShapeIdCtl] })
|
||||
class ShapeIdTeapotModule {}
|
||||
|
||||
@Route('/shape')
|
||||
class ShapeNameCtl {
|
||||
@Get('/:name', { export: true }) get(@param() p: Record<string, string>) {
|
||||
return { from: 'name', p };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [ShapeNameCtl] })
|
||||
class ShapeNameTeapotModule {}
|
||||
|
||||
// Same method and shape as the teapot's export: the local route wins, with a warning.
|
||||
@Route('/dup')
|
||||
class ShadowCtl {
|
||||
@Get('/ping') local() {
|
||||
return { from: 'local' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [ShadowCtl] })
|
||||
class ShadowTeacupModule {}
|
||||
|
||||
// A different shape that overlaps the export: no warning, and lookup ranks across local and remote.
|
||||
@Route('/dup')
|
||||
class OverlapCtl {
|
||||
@Get('/:anything') local(@param() p: Record<string, string>) {
|
||||
return { from: 'local', p };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [OverlapCtl] })
|
||||
class OverlapTeacupModule {}
|
||||
|
||||
@Route('/c')
|
||||
class PlainCtl {
|
||||
@Get('/ok') ok() {
|
||||
return { from: 'teacup' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [PlainCtl] })
|
||||
class PlainTeacupModule {}
|
||||
|
||||
type Ctor = new (...args: unknown[]) => unknown;
|
||||
|
||||
function recordingLogger(): { logger: Logger; warnings: string[] } {
|
||||
const warnings: string[] = [];
|
||||
const noop = () => {};
|
||||
return { logger: { debug: noop, info: noop, error: noop, warn: (m) => warnings.push(m) }, warnings };
|
||||
}
|
||||
|
||||
/** Starts one teapot per module and returns their control URLs plus a function that hides the ports. */
|
||||
async function teapots(modules: Ctor[]) {
|
||||
const apps = modules.map((module) => createApp({ modules: [module], experimental: true, mesh: { secret: SECRET } }));
|
||||
const servers = await Promise.all(apps.map((app) => app.listen(0)));
|
||||
const urls = servers.map((s) => `ws://127.0.0.1:${(s.address() as AddressInfo).port}/__mesh__/control`);
|
||||
const anonymize = (text: string) => urls.reduce((out, url, i) => out.split(url).join(`<teapot${i + 1}>`), text);
|
||||
const close = () => Promise.all(apps.map((app) => app.close()));
|
||||
return { urls, anonymize, close };
|
||||
}
|
||||
|
||||
async function meshCase(id: string, teacupModule: Ctor, teapotModules: Ctor[], requests: string[]) {
|
||||
const pots = await teapots(teapotModules);
|
||||
const { logger, warnings } = recordingLogger();
|
||||
const teacup = createApp({
|
||||
modules: [teacupModule],
|
||||
experimental: true,
|
||||
logger,
|
||||
mesh: { teapots: pots.urls.map((url) => ({ url, secret: SECRET })) },
|
||||
});
|
||||
|
||||
try {
|
||||
await teacup.ready();
|
||||
const responses = [];
|
||||
for (const path of requests) {
|
||||
const res = await teacup.fetch(new Request(`http://parity.test${path}`));
|
||||
responses.push({ path, status: res.status, body: await res.text() });
|
||||
}
|
||||
const routing = warnings.filter((w) => w.includes('precedence')).map(pots.anonymize);
|
||||
return { id, ok: true, warnings: routing, responses };
|
||||
} catch (error) {
|
||||
const { name, message } = errorOutcome(error);
|
||||
return { id, error: { name, message: pots.anonymize(message) } };
|
||||
} finally {
|
||||
await teacup.close();
|
||||
await pots.close();
|
||||
}
|
||||
}
|
||||
|
||||
async function meshAll() {
|
||||
return [
|
||||
await meshCase('M01-two-teapots-same-route', PlainTeacupModule, [DupTeapotModule, DupTeapotModule], []),
|
||||
await meshCase('M02-two-teapots-same-shape', PlainTeacupModule, [ShapeIdTeapotModule, ShapeNameTeapotModule], []),
|
||||
await meshCase('M03-local-same-shape-wins', ShadowTeacupModule, [DupTeapotModule], ['/api/dup/ping']),
|
||||
await meshCase('M04-unique-remote', PlainTeacupModule, [DupTeapotModule], ['/api/dup/ping', '/c/ok', '/api/nope']),
|
||||
await meshCase(
|
||||
'M05-remote-static-outranks-local-param',
|
||||
OverlapTeacupModule,
|
||||
[DupTeapotModule],
|
||||
['/api/dup/ping', '/api/dup/x'],
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
describe('router parity: boot-time rejection', () => {
|
||||
it('pattern compilation (oracle and live compilePattern) equals the frozen capture', async () => {
|
||||
const expected = await frozen('boot-patterns', () => compileAll(live.compilePattern));
|
||||
expectFrozenEqual(compileAll(oracle.compilePattern), expected, 'oracle compilePattern');
|
||||
expectFrozenEqual(compileAll(live.compilePattern), expected, 'live compilePattern');
|
||||
});
|
||||
|
||||
it('createApp route-table validation equals the frozen capture', async () => {
|
||||
const expected = await frozen('boot-app', bootAll);
|
||||
expectFrozenEqual(bootAll(), expected, 'createApp');
|
||||
});
|
||||
|
||||
it('mesh route splicing equals the frozen capture', async () => {
|
||||
const expected = await frozen('boot-mesh', meshAll);
|
||||
expectFrozenEqual(await meshAll(), expected, 'mesh splice');
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
/**
|
||||
* Measures how much of a corpus exercises sibling branches, so "the generator covers backtracking"
|
||||
* is a number rather than a hope. Method-agnostic: a tree is walked by path before a method is
|
||||
* chosen, so any declaration that shares the walk counts.
|
||||
*
|
||||
* - sibling hit: two declarations both match the request's leading segments through a segment
|
||||
* where their patterns differ — the lookup has two branches to choose between at that point.
|
||||
* - backtrack: a sibling hit where at least one of those declarations then fails to match the
|
||||
* whole path — a branch the lookup walks into and has to leave.
|
||||
*/
|
||||
import { compilePattern, normalizeRequestPath, type CompiledSegment } from './oracle';
|
||||
import type { Scenario } from './matcher';
|
||||
|
||||
function segmentMatches(segment: CompiledSegment, value: string): boolean {
|
||||
if (segment.kind === 'static') return segment.value === value;
|
||||
if (segment.kind === 'catchAll') return true;
|
||||
const decoded = value.includes('%') ? decodeURIComponent(value) : value;
|
||||
return !segment.constraint || segment.constraint.test(decoded);
|
||||
}
|
||||
|
||||
/** Leading segments matched, and whether the whole path matched. */
|
||||
function walk(pattern: string, segs: string[]): { depth: number; full: boolean } {
|
||||
const { segments } = compilePattern(pattern);
|
||||
for (let i = 0; i < segments.length; i++) {
|
||||
if (segments[i].kind === 'catchAll') return { depth: segments.length, full: true };
|
||||
if (i >= segs.length || !segmentMatches(segments[i], segs[i])) return { depth: i, full: false };
|
||||
}
|
||||
return { depth: segments.length, full: segments.length === segs.length };
|
||||
}
|
||||
|
||||
const sameSegment = (a: CompiledSegment, b: CompiledSegment): boolean =>
|
||||
JSON.stringify({ ...a, constraint: undefined }) === JSON.stringify({ ...b, constraint: undefined });
|
||||
|
||||
export interface BranchStats {
|
||||
requests: number;
|
||||
validPaths: number;
|
||||
siblingHits: number;
|
||||
backtracks: number;
|
||||
siblingShare: string;
|
||||
backtrackShare: string;
|
||||
}
|
||||
|
||||
export function branchStats(scenarios: Scenario[]): BranchStats {
|
||||
let requests = 0;
|
||||
let validPaths = 0;
|
||||
let siblingHits = 0;
|
||||
let backtracks = 0;
|
||||
|
||||
for (const scenario of scenarios) {
|
||||
const patterns = [...new Set(scenario.declarations.map((d) => d.pattern))];
|
||||
|
||||
for (const { raw } of scenario.requests) {
|
||||
requests++;
|
||||
let path: string;
|
||||
try {
|
||||
path = normalizeRequestPath(raw);
|
||||
} catch {
|
||||
continue;
|
||||
}
|
||||
validPaths++;
|
||||
|
||||
const segs = path.split('/').filter(Boolean);
|
||||
const walks = patterns.map((pattern) => ({ segments: compilePattern(pattern).segments, ...walk(pattern, segs) }));
|
||||
let sibling = false;
|
||||
let backtrack = false;
|
||||
|
||||
for (let i = 0; i < walks.length; i++) {
|
||||
for (let j = i + 1; j < walks.length; j++) {
|
||||
const [a, b] = [walks[i], walks[j]];
|
||||
const shared = Math.min(a.depth, b.depth, a.segments.length, b.segments.length);
|
||||
const diverge = Array.from({ length: shared }, (_, d) => d).find(
|
||||
(d) => !sameSegment(a.segments[d], b.segments[d]),
|
||||
);
|
||||
if (diverge === undefined) continue;
|
||||
sibling = true;
|
||||
if (!a.full || !b.full) backtrack = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sibling) siblingHits++;
|
||||
if (backtrack) backtracks++;
|
||||
}
|
||||
}
|
||||
|
||||
const pct = (n: number) => `${((n / requests) * 100).toFixed(1)}%`;
|
||||
return {
|
||||
requests,
|
||||
validPaths,
|
||||
siblingHits,
|
||||
backtracks,
|
||||
siblingShare: pct(siblingHits),
|
||||
backtrackShare: pct(backtracks),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,342 @@
|
||||
/**
|
||||
* Hand-picked matcher scenarios (ROUTER-CORPUS §2). Declaration IDs are stable across a scenario
|
||||
* and its reversed twin, so a reversed run is compared by which declaration answered, not by which
|
||||
* pattern text happens to sit first.
|
||||
*
|
||||
* Inputs only. The expected outputs live in `frozen/matcher-hand.json`, captured from the pinned
|
||||
* revision; nothing in this file states what the answer should be.
|
||||
*/
|
||||
import type { Declaration, Request, Scenario, Transport } from './matcher';
|
||||
|
||||
type Decl = [id: string, method: string, pattern: string, transport?: Transport];
|
||||
type Req = [method: string, raw: string];
|
||||
|
||||
function scenario(id: string, note: string, decls: Decl[], reqs: Req[]): Scenario {
|
||||
const declarations = decls.map(([declId, method, pattern, transport = 'buffer']): Declaration => ({
|
||||
id: declId,
|
||||
method,
|
||||
pattern,
|
||||
transport,
|
||||
}));
|
||||
const requests = reqs.map(([method, raw]): Request => ({ method, raw }));
|
||||
return { id, note, declarations, requests };
|
||||
}
|
||||
|
||||
/** The same scenario with its declarations in reverse registration order. */
|
||||
function reversed(base: Scenario, id: string): Scenario {
|
||||
return { ...base, id, note: `${base.note} (declarations reversed)`, declarations: [...base.declarations].reverse() };
|
||||
}
|
||||
|
||||
const get = (...paths: string[]): Req[] => paths.map((path): Req => ['GET', path]);
|
||||
const methods = (path: string, ...verbs: string[]): Req[] => verbs.map((verb): Req => [verb, path]);
|
||||
|
||||
const rank = scenario(
|
||||
'H01-rank',
|
||||
'static beats plain param beats catch-all',
|
||||
[
|
||||
['catchAll', 'GET', '/a/:rest*'],
|
||||
['param', 'GET', '/a/:id'],
|
||||
['static', 'GET', '/a/b'],
|
||||
],
|
||||
[...get('/a/b', '/a/x', '/a/x/y', '/a', '/a/'), ['HEAD', '/a/x'], ['OPTIONS', '/a/b'], ['POST', '/a/b']],
|
||||
);
|
||||
|
||||
const constraint = scenario(
|
||||
'H03-constraint',
|
||||
'constrained param beats plain param; constraint tested against the decoded segment',
|
||||
[
|
||||
['plain', 'GET', '/users/:value'],
|
||||
['digits', 'GET', '/users/:id(\\d+)'],
|
||||
],
|
||||
get('/users/42', '/users/alice', '/users/42x', '/users/%34%32', '/users/'),
|
||||
);
|
||||
|
||||
const constraintTie = scenario(
|
||||
'H05-constraint-tie',
|
||||
'two overlapping constraints of equal rank: registration order decides',
|
||||
[
|
||||
['digits', 'GET', '/n/:num(\\d+)'],
|
||||
['hex', 'GET', '/n/:code([0-9a-f]+)'],
|
||||
],
|
||||
get('/n/42', '/n/ff', '/n/4f', '/n/zz'),
|
||||
);
|
||||
|
||||
const equalRank = scenario(
|
||||
'H08-equal-rank',
|
||||
'equal-specificity plain params: first registered wins',
|
||||
[
|
||||
['first', 'GET', '/t/:first'],
|
||||
['second', 'GET', '/t/:second'],
|
||||
],
|
||||
[...get('/t/x', '/t/x/y'), ['HEAD', '/t/x']],
|
||||
);
|
||||
|
||||
const samePattern = scenario(
|
||||
'H10-same-pattern',
|
||||
'identical pattern text under two declaration IDs (mesh local/remote twins reach the matcher this way)',
|
||||
[
|
||||
['one', 'GET', '/same'],
|
||||
['two', 'GET', '/same'],
|
||||
],
|
||||
[...get('/same'), ['HEAD', '/same'], ['OPTIONS', '/same']],
|
||||
);
|
||||
|
||||
export const HAND_SCENARIOS: Scenario[] = [
|
||||
rank,
|
||||
reversed(rank, 'H02-rank-reversed'),
|
||||
constraint,
|
||||
reversed(constraint, 'H04-constraint-reversed'),
|
||||
constraintTie,
|
||||
reversed(constraintTie, 'H06-constraint-tie-reversed'),
|
||||
scenario(
|
||||
'H07-exact-vs-catch-all',
|
||||
'exact route at /files, catch-all below it, decoded captures',
|
||||
[
|
||||
['exact', 'GET', '/files'],
|
||||
['rest', 'GET', '/files/:rest*'],
|
||||
],
|
||||
[...get('/files', '/files/', '/files/a%2Fb', '/files/a/b/c', '/files/a%20b/c%2Fd'), ['HEAD', '/files/x']],
|
||||
),
|
||||
equalRank,
|
||||
reversed(equalRank, 'H09-equal-rank-reversed'),
|
||||
samePattern,
|
||||
reversed(samePattern, 'H11-same-pattern-reversed'),
|
||||
scenario(
|
||||
'H12-method-implicit-head',
|
||||
'buffered GET supplies HEAD; OPTIONS and 405 share one canonical Allow',
|
||||
[
|
||||
['get', 'GET', '/m'],
|
||||
['post', 'POST', '/m'],
|
||||
],
|
||||
methods('/m', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'DELETE', 'PATCH'),
|
||||
),
|
||||
scenario(
|
||||
'H13-method-explicit-head',
|
||||
'an explicit HEAD wins over the buffered-GET fallback',
|
||||
[
|
||||
['get', 'GET', '/m'],
|
||||
['post', 'POST', '/m'],
|
||||
['head', 'HEAD', '/m'],
|
||||
],
|
||||
methods('/m', 'GET', 'HEAD', 'OPTIONS', 'POST', 'PUT', 'DELETE'),
|
||||
),
|
||||
scenario(
|
||||
'H14-streaming-head',
|
||||
'a streaming GET does not supply HEAD',
|
||||
[['stream', 'GET', '/stream', 'sse']],
|
||||
methods('/stream', 'GET', 'HEAD', 'OPTIONS', 'POST'),
|
||||
),
|
||||
scenario(
|
||||
'H15-streaming-outranks-buffered',
|
||||
'HEAD skips a higher-ranked streaming GET and falls back to a lower-ranked buffered GET',
|
||||
[
|
||||
['live', 'GET', '/s/live', 'sse'],
|
||||
['byId', 'GET', '/s/:id'],
|
||||
],
|
||||
[...methods('/s/live', 'GET', 'HEAD', 'OPTIONS'), ['HEAD', '/s/x']],
|
||||
),
|
||||
scenario(
|
||||
'H16-negotiate-and-ndjson-head',
|
||||
'negotiate and ndjson GETs are streaming transports for the HEAD rule',
|
||||
[
|
||||
['negotiate', 'GET', '/neg', 'negotiate'],
|
||||
['ndjson', 'GET', '/nd', 'ndjson'],
|
||||
],
|
||||
[...methods('/neg', 'GET', 'HEAD', 'OPTIONS'), ...methods('/nd', 'HEAD', 'OPTIONS')],
|
||||
),
|
||||
scenario(
|
||||
'H17-allow-order',
|
||||
'Allow is canonical regardless of declaration order; explicit OPTIONS is a normal route',
|
||||
[
|
||||
['delete', 'DELETE', '/r'],
|
||||
['patch', 'PATCH', '/r'],
|
||||
['options', 'OPTIONS', '/r'],
|
||||
['put', 'PUT', '/r'],
|
||||
['get', 'GET', '/r', 'sse'],
|
||||
['post', 'POST', '/r'],
|
||||
],
|
||||
methods('/r', 'OPTIONS', 'HEAD', 'GET', 'TRACE', 'POST'),
|
||||
),
|
||||
scenario(
|
||||
'H18-path-miss',
|
||||
'a path no pattern matches: no route and an empty Allow',
|
||||
[['a', 'GET', '/a']],
|
||||
[...get('/absent', '/a/extra', '/'), ['OPTIONS', '/absent'], ['HEAD', '/absent']],
|
||||
),
|
||||
scenario(
|
||||
'H19-encoding-case-unicode',
|
||||
'decoded params, malformed escapes, repeated slashes, exact case and Unicode literals',
|
||||
[
|
||||
['userId', 'GET', '/users/:id'],
|
||||
['upper', 'GET', '/Case'],
|
||||
['unicode', 'GET', '/café'],
|
||||
['unicodeParam', 'GET', '/u/:name'],
|
||||
],
|
||||
get(
|
||||
'/users/a%20b',
|
||||
'/users/a+b',
|
||||
'/users/%F0%9F%8D%B5',
|
||||
'/users/%E0%A4%A',
|
||||
'/users/%zz',
|
||||
'/a//b',
|
||||
'/users//x',
|
||||
'/Case',
|
||||
'/case',
|
||||
'/CASE',
|
||||
'/café',
|
||||
'/caf%C3%A9',
|
||||
'/u/caf%C3%A9',
|
||||
'/u/café',
|
||||
),
|
||||
),
|
||||
scenario(
|
||||
'H20-normalization',
|
||||
'one trailing slash removed; plain and encoded dot segments resolved before lookup',
|
||||
[
|
||||
['a', 'GET', '/a'],
|
||||
['admin', 'GET', '/admin'],
|
||||
['file', 'GET', '/public/:file'],
|
||||
],
|
||||
get(
|
||||
'/a/',
|
||||
'/a//',
|
||||
'/public/../admin',
|
||||
'/public/%2e%2e/admin',
|
||||
'/public/%2E%2E/admin',
|
||||
'/public/./x',
|
||||
'/a/.',
|
||||
'/public/..%2fadmin',
|
||||
'/..',
|
||||
'/a/b/../../admin',
|
||||
'',
|
||||
'a',
|
||||
),
|
||||
),
|
||||
scenario(
|
||||
'H21-root',
|
||||
'the root pattern and a root catch-all',
|
||||
[
|
||||
['any', 'GET', '/:rest*'],
|
||||
['root', 'GET', '/'],
|
||||
],
|
||||
get('/', '/x', '/x/y', '/x/'),
|
||||
),
|
||||
scenario(
|
||||
'H22-first-differing-segment',
|
||||
'ranking is decided at the first segment whose kind differs',
|
||||
[
|
||||
['paramStatic', 'GET', '/a/:x/c'],
|
||||
['staticParam', 'GET', '/a/b/:y'],
|
||||
['paramConstrained', 'GET', '/a/:x/:y(\\d+)'],
|
||||
],
|
||||
get('/a/b/c', '/a/z/c', '/a/z/5', '/a/b/5', '/a/z/q'),
|
||||
),
|
||||
scenario(
|
||||
'H23-per-position-decode',
|
||||
'a decoded value is the same for every candidate the scan reaches',
|
||||
[
|
||||
['zzz', 'GET', '/a/:x/zzz'],
|
||||
['b', 'GET', '/a/:y/b'],
|
||||
],
|
||||
get('/a/a%20b/b', '/a/a%20b/zzz'),
|
||||
),
|
||||
scenario(
|
||||
'H24-constrained-catch-all',
|
||||
'two catch-alls ranked by the segments before them',
|
||||
[
|
||||
['named', 'GET', '/v/:name/:rest*'],
|
||||
['versioned', 'GET', '/v/:ver(\\d+)/:rest*'],
|
||||
],
|
||||
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/')),
|
||||
];
|
||||
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Reads the frozen router-parity baseline. Read README.md in this directory before touching it.
|
||||
*
|
||||
* Every expected output under `frozen/` was captured from the pinned revision below, by running
|
||||
* these tests with `ROUTER_PARITY_CAPTURE=1` while the file did not exist yet. Nothing here ever
|
||||
* overwrites a file: a capture only fills a gap, and `vitest -u` is refused outright, because a
|
||||
* baseline that a flag can rewrite is a baseline a new implementation can quietly move.
|
||||
*/
|
||||
import { existsSync, readFileSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { expect } from 'vitest';
|
||||
|
||||
/** The `@green-tea/core` commit every frozen output was captured from (develop after #117 and #122). */
|
||||
export const PINNED_REVISION = 'ed47836c9820c47bf4ed5e902d91e019abdb110a';
|
||||
|
||||
const FROZEN_DIR = join(__dirname, 'frozen');
|
||||
|
||||
interface FrozenFile<T> {
|
||||
revision: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
function refuseSnapshotUpdate(name: string): void {
|
||||
// `_updateSnapshot` is vitest's private record of `-u` ('all') versus a normal run ('new'/'none').
|
||||
const state = expect.getState().snapshotState as unknown as { _updateSnapshot?: string } | undefined;
|
||||
if (state?._updateSnapshot !== 'all') return;
|
||||
|
||||
throw new Error(
|
||||
`router-parity: '${name}' is a frozen baseline captured at ${PINNED_REVISION} and is never ` +
|
||||
'rewritten by `vitest -u`. A behaviour difference against it is a compatibility failure. ' +
|
||||
'If the change is deliberate, it needs its own maintainer approval and a reviewed edit of ' +
|
||||
`test/router-parity/frozen/${name}.json — see test/router-parity/README.md.`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the frozen data for `name`. When the file is missing it fails, unless
|
||||
* `ROUTER_PARITY_CAPTURE=1` is set, in which case `capture()` runs against the current code and its
|
||||
* result is written. An existing file is never replaced.
|
||||
*/
|
||||
export async function frozen<T>(name: string, capture: () => T | Promise<T>): Promise<T> {
|
||||
refuseSnapshotUpdate(name);
|
||||
const file = join(FROZEN_DIR, `${name}.json`);
|
||||
|
||||
if (!existsSync(file)) {
|
||||
if (process.env.ROUTER_PARITY_CAPTURE !== '1')
|
||||
throw new Error(
|
||||
`router-parity: frozen file ${file} is missing — the baseline cannot be regenerated by a test run`,
|
||||
);
|
||||
const data = JSON.parse(JSON.stringify(await capture())) as T;
|
||||
const record: FrozenFile<T> = { revision: PINNED_REVISION, data };
|
||||
writeFileSync(file, `${JSON.stringify(record, null, 2)}\n`);
|
||||
return data;
|
||||
}
|
||||
|
||||
const record = JSON.parse(readFileSync(file, 'utf8')) as FrozenFile<T>;
|
||||
expect(record.revision, `${name}.json was captured from a different revision`).toBe(PINNED_REVISION);
|
||||
return record.data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Structural equality that also holds array order and object key order. `toEqual` alone ignores key
|
||||
* order, which is observable in `openapi().paths` and in serialized introspection output.
|
||||
*/
|
||||
export function expectFrozenEqual(actual: unknown, expected: unknown, label: string): void {
|
||||
const plain = JSON.parse(JSON.stringify(actual));
|
||||
expect(plain, label).toEqual(expected);
|
||||
expect(JSON.stringify(plain), `${label} (key and array order)`).toBe(JSON.stringify(expected));
|
||||
}
|
||||
@@ -0,0 +1,597 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/b",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aB\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/x",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aId\",\"params\":{\"id\":\"x\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/x/y",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aRest\",\"params\":{\"rest\":\"x/y\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aRest\",\"params\":{\"rest\":\"\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/42",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersId\",\"params\":{\"id\":\"42\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/alice",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersValue\",\"params\":{\"value\":\"alice\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/a%20b",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersValue\",\"params\":{\"value\":\"a b\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/n/42",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"nNum\",\"params\":{\"num\":\"42\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/n/ff",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"nCode\",\"params\":{\"code\":\"ff\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"files\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"files\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files/a%2Fb",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"filesRest\",\"params\":{\"rest\":\"a/b\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"mGet\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/m",
|
||||
"status": 204,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "PUT",
|
||||
"raw": "/m",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "DELETE",
|
||||
"raw": "/m",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"mPost\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/h",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"hGet\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/h",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/stream",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"cache-control": "no-cache",
|
||||
"content-type": "text/event-stream",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "data: {\"id\":\"stream\"}\n\n"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/stream",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/stream",
|
||||
"status": 204,
|
||||
"headers": {
|
||||
"allow": "GET, OPTIONS",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/s/live",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/s/x",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/%E0%A4%A",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Bad Request\"}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/users/%E0%A4%A",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a//b",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Bad Request\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/Case",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"caseUpper\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/case",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/caf%C3%A9",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/u/caf%C3%A9",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"uName\",\"params\":{\"name\":\"café\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/../admin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/%2e%2e/admin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/..%2fadmin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"publicFile\",\"params\":{\"file\":\"../admin\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/admin/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/r",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"rOptions\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "PURGE",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"root\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/?q=1",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"root\",\"params\":{}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,632 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/b",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aB\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/x",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aId\",\"params\":{\"id\":\"x\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a/x/y",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aRest\",\"params\":{\"rest\":\"x/y\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"aRest\",\"params\":{\"rest\":\"\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/42",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersId\",\"params\":{\"id\":\"42\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/alice",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersValue\",\"params\":{\"value\":\"alice\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/a%20b",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"usersValue\",\"params\":{\"value\":\"a b\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/n/42",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"nNum\",\"params\":{\"num\":\"42\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/n/ff",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"nCode\",\"params\":{\"code\":\"ff\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"files\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"files\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/files/a%2Fb",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"filesRest\",\"params\":{\"rest\":\"a/b\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"mGet\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/m",
|
||||
"status": 204,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "PUT",
|
||||
"raw": "/m",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "DELETE",
|
||||
"raw": "/m",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"raw": "/m",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"mPost\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/h",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"hGet\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/h",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/stream",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"cache-control": "no-cache",
|
||||
"content-type": "text/event-stream",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "data: {\"id\":\"stream\"}\n\n"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/stream",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "GET, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/stream",
|
||||
"status": 204,
|
||||
"headers": {
|
||||
"allow": "GET, OPTIONS",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/s/live",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/s/x",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/absent",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/users/%E0%A4%A",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Bad Request\"}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/users/%E0%A4%A",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/a//b",
|
||||
"status": 400,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Bad Request\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/Case",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"caseUpper\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/case",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/caf%C3%A9",
|
||||
"status": 404,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/u/caf%C3%A9",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"uName\",\"params\":{\"name\":\"café\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/../admin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/%2e%2e/admin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/public/..%2fadmin",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"publicFile\",\"params\":{\"file\":\"../admin\"}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/admin/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"admin\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"raw": "/r",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"rOptions\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "HEAD",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "PURGE",
|
||||
"raw": "/r",
|
||||
"status": 405,
|
||||
"headers": {
|
||||
"allow": "PUT, PATCH, DELETE, OPTIONS",
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"root\",\"params\":{}}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"raw": "/?q=1",
|
||||
"status": 200,
|
||||
"headers": {
|
||||
"content-type": "application/json",
|
||||
"referrer-policy": "no-referrer",
|
||||
"transfer-encoding": "chunked",
|
||||
"x-content-type-options": "nosniff",
|
||||
"x-dns-prefetch-control": "off",
|
||||
"x-frame-options": "SAMEORIGIN"
|
||||
},
|
||||
"body": "{\"id\":\"root\",\"params\":{}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"id": "B01-duplicate-param",
|
||||
"declarations": [
|
||||
"@Get('/x/:id/:id')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:id/:id': duplicate parameter 'id'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B02-nonfinal-catch-all",
|
||||
"declarations": [
|
||||
"@Get('/x/:rest*/tail')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:rest*/tail': catch-all must be the final segment"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B03-nested-quantifier",
|
||||
"declarations": [
|
||||
"@Get('/x/:id((a+)+)')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression '(a+)+'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B04-alternation",
|
||||
"declarations": [
|
||||
"@Get('/x/:id(a|b)')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression 'a|b'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B05-adjacent-unbounded",
|
||||
"declarations": [
|
||||
"@Get('/x/:id(\\d+\\w+)')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: adjacent unbounded quantifiers in '\\d+\\w+'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B06-inverted-quantifier",
|
||||
"declarations": [
|
||||
"@Get('/x/:id(\\d{5,2})')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: invalid quantifier '{5,2}'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B07-invalid-param-name",
|
||||
"declarations": [
|
||||
"@Get('/x/:1x')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:1x': invalid parameter name '1x'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B08-malformed-constraint",
|
||||
"declarations": [
|
||||
"@Get('/x/:id(\\d+')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:id(\\d+': malformed constraint"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B09-same-shape-plain",
|
||||
"declarations": [
|
||||
"@Get('/users/:id')",
|
||||
"@Get('/users/:name')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /users/:name at ParityBoot.h1 conflicts with GET /users/:id at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B10-same-shape-constrained",
|
||||
"declarations": [
|
||||
"@Get('/c/:a(\\d+)')",
|
||||
"@Get('/c/:b(\\d+)')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /c/:b(\\d+) at ParityBoot.h1 conflicts with GET /c/:a(\\d+) at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B11-trailing-slash-twin",
|
||||
"declarations": [
|
||||
"@Get('/t')",
|
||||
"@Get('/t/')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /t/ at ParityBoot.h1 conflicts with GET /t at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B12-get-and-ws-same-path",
|
||||
"declarations": [
|
||||
"@Get('/live')",
|
||||
"@Ws('/live')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /live at ParityBoot.h1 conflicts with GET /live at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B13-get-and-sse-same-path",
|
||||
"declarations": [
|
||||
"@Get('/feed')",
|
||||
"@Sse('/feed')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /feed at ParityBoot.h1 conflicts with GET /feed at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B14-ws-same-shape",
|
||||
"declarations": [
|
||||
"@Ws('/w/:a')",
|
||||
"@Ws('/w/:b')"
|
||||
],
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "ambiguous route GET /w/:b at ParityBoot.h1 conflicts with GET /w/:a at ParityBoot.h0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "B15-ok-same-shape-different-methods",
|
||||
"declarations": [
|
||||
"@Get('/users/:id')",
|
||||
"@Post('/users/:name')"
|
||||
],
|
||||
"ok": true
|
||||
},
|
||||
{
|
||||
"id": "B16-ok-different-constraints",
|
||||
"declarations": [
|
||||
"@Get('/c/:a(\\d+)')",
|
||||
"@Get('/c/:b([a-z]+)')"
|
||||
],
|
||||
"ok": true
|
||||
},
|
||||
{
|
||||
"id": "B17-ok-static-and-param",
|
||||
"declarations": [
|
||||
"@Get('/users/me')",
|
||||
"@Get('/users/:id')"
|
||||
],
|
||||
"ok": true
|
||||
},
|
||||
{
|
||||
"id": "B18-ok-exact-and-catch-all",
|
||||
"declarations": [
|
||||
"@Get('/f')",
|
||||
"@Get('/f/:rest*')"
|
||||
],
|
||||
"ok": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"id": "M01-two-teapots-same-route",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "mesh: ambiguous remote route 'GET /api/dup/ping' from <teapot2> conflicts with 'GET /api/dup/ping' from <teapot1> — load balancing across teapots is not implemented yet, so green-tea will not choose one for you. Export it from a single teapot."
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "M02-two-teapots-same-shape",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "mesh: ambiguous remote route 'GET /api/shape/:name' from <teapot2> conflicts with 'GET /api/shape/:id' from <teapot1> — load balancing across teapots is not implemented yet, so green-tea will not choose one for you. Export it from a single teapot."
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "M03-local-same-shape-wins",
|
||||
"ok": true,
|
||||
"warnings": [
|
||||
"mesh: route 'GET /api/dup/ping' is exported by teapot <teapot1> but also declared locally — the local route takes precedence and the remote one will not be reached. Remove one if that is not what you meant."
|
||||
],
|
||||
"responses": [
|
||||
{
|
||||
"path": "/api/dup/ping",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"local\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "M04-unique-remote",
|
||||
"ok": true,
|
||||
"warnings": [],
|
||||
"responses": [
|
||||
{
|
||||
"path": "/api/dup/ping",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"teapot\"}"
|
||||
},
|
||||
{
|
||||
"path": "/c/ok",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"teacup\"}"
|
||||
},
|
||||
{
|
||||
"path": "/api/nope",
|
||||
"status": 404,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "M05-remote-static-outranks-local-param",
|
||||
"ok": true,
|
||||
"warnings": [],
|
||||
"responses": [
|
||||
{
|
||||
"path": "/api/dup/ping",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"teapot\"}"
|
||||
},
|
||||
{
|
||||
"path": "/api/dup/x",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"local\",\"p\":{\"anything\":\"x\"}}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"pattern": "/",
|
||||
"shape": ""
|
||||
},
|
||||
{
|
||||
"pattern": "/users/:id",
|
||||
"shape": "s:users/p"
|
||||
},
|
||||
{
|
||||
"pattern": "/users/:id(\\d+)",
|
||||
"shape": "s:users/r:\\d+"
|
||||
},
|
||||
{
|
||||
"pattern": "/files/:rest*",
|
||||
"shape": "s:files/c"
|
||||
},
|
||||
{
|
||||
"pattern": "/:rest*",
|
||||
"shape": "c"
|
||||
},
|
||||
{
|
||||
"pattern": "/t/",
|
||||
"shape": "s:t"
|
||||
},
|
||||
{
|
||||
"pattern": "/café",
|
||||
"shape": "s:café"
|
||||
},
|
||||
{
|
||||
"pattern": "/build/:version(\\d{2}\\.\\d{1,2})",
|
||||
"shape": "s:build/r:\\d{2}\\.\\d{1,2}"
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id/:id",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:id/:id': duplicate parameter 'id'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id/:rest*/tail",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:id/:rest*/tail': catch-all must be the final segment"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:rest*/:rest*",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:rest*/:rest*': catch-all must be the final segment"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:': invalid parameter name ''"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:1x",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:1x': invalid parameter name '1x'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x//y",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x//y': repeated slash"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "x",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern 'x': pattern must start with '/'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '': pattern must start with '/'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id((a+)+)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression '(a+)+'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id((?=a)a)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression '(?=a)a'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(\\1)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression '\\1'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(a|b)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: unsupported expression 'a|b'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(\\d+\\w+)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: adjacent unbounded quantifiers in '\\d+\\w+'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(\\d{5,2})",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: invalid quantifier '{5,2}'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(\\d{1,4096})",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: invalid quantifier '{1,4096}'"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(\\d+",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "invalid route pattern '/x/:id(\\d+': malformed constraint"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id()",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: expression must contain 1-128 characters"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/x/:id(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "unsafe route constraint: expression must contain 1-128 characters"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"explain": {
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
{
|
||||
"name": "get",
|
||||
"kind": "handler",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "no route: /api/items"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/live/:room",
|
||||
"explain": {
|
||||
"pattern": "/api/live/:room",
|
||||
"method": "GET",
|
||||
"transport": "ws",
|
||||
"chain": [
|
||||
{
|
||||
"name": "db",
|
||||
"kind": "provider",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"db"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"kind": "step",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [
|
||||
"db"
|
||||
],
|
||||
"provides": [
|
||||
"user"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "live",
|
||||
"kind": "handler",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [
|
||||
"user"
|
||||
],
|
||||
"provides": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:id/files/:path*",
|
||||
"explain": {
|
||||
"pattern": "/api/items/:id/files/:path*",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
{
|
||||
"name": "files",
|
||||
"kind": "handler",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": []
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/missing",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "no route: /api/missing"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/42",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "no route: /api/items/42"
|
||||
}
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/",
|
||||
"explain": {
|
||||
"pattern": "/api/items/",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
{
|
||||
"name": "db",
|
||||
"kind": "provider",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"db"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"kind": "step",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [
|
||||
"db"
|
||||
],
|
||||
"provides": [
|
||||
"user"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "list",
|
||||
"kind": "handler",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [
|
||||
"user"
|
||||
],
|
||||
"provides": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": {
|
||||
"nodes": [
|
||||
{
|
||||
"name": "db",
|
||||
"kind": "provider",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"db"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "logger",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"logger"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "rooms",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"rooms"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "events",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"events"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "user",
|
||||
"kind": "step",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [
|
||||
"db"
|
||||
],
|
||||
"provides": [
|
||||
"user"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "audit",
|
||||
"kind": "step",
|
||||
"origin": "module:IntrospectionModule",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"audit"
|
||||
]
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"pattern": "/api/items/:id/files/:path*",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"files"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"db",
|
||||
"user",
|
||||
"list"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/",
|
||||
"method": "POST",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"db",
|
||||
"user",
|
||||
"create"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"get"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"method": "HEAD",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"head"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"method": "OPTIONS",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"options"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:id(\\d+)",
|
||||
"method": "DELETE",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"audit",
|
||||
"remove"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/:slug([a-z0-9-]+)",
|
||||
"method": "PUT",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"upsert"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/items/search",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"search"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/events",
|
||||
"method": "GET",
|
||||
"transport": "sse",
|
||||
"chain": [
|
||||
"events"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/feed",
|
||||
"method": "GET",
|
||||
"transport": "negotiate",
|
||||
"chain": [
|
||||
"feed"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/live/:room",
|
||||
"method": "GET",
|
||||
"transport": "ws",
|
||||
"chain": [
|
||||
"db",
|
||||
"user",
|
||||
"live"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": {
|
||||
"before": {
|
||||
"graph": {
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "graph() unavailable until a mesh app has booted: a mesh graph is not knowable until its teapots are asked. Call `await app.ready()` first — it is a no-op on a non-mesh app"
|
||||
}
|
||||
},
|
||||
"explain": {
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "explain() unavailable until a mesh app has booted: a mesh graph is not knowable until its teapots are asked. Call `await app.ready()` first — it is a no-op on a non-mesh app"
|
||||
}
|
||||
},
|
||||
"openapi": {
|
||||
"value": {
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Parity",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/api/local/who": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/local/{id}": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"after": {
|
||||
"graph": {
|
||||
"nodes": [
|
||||
{
|
||||
"name": "logger",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"logger"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "rooms",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"rooms"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "events",
|
||||
"kind": "provider",
|
||||
"origin": "builtin",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"events"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "config",
|
||||
"kind": "step",
|
||||
"origin": "mesh:<teapot>",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"config"
|
||||
]
|
||||
}
|
||||
],
|
||||
"routes": [
|
||||
{
|
||||
"pattern": "/api/local/who",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"config",
|
||||
"who"
|
||||
]
|
||||
},
|
||||
{
|
||||
"pattern": "/api/local/:id",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
"byId"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"explain": [
|
||||
{
|
||||
"pattern": "/api/missing",
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "no route: /api/missing"
|
||||
}
|
||||
}
|
||||
],
|
||||
"explainLocal": {
|
||||
"pattern": "/api/local/who",
|
||||
"method": "GET",
|
||||
"transport": "buffer",
|
||||
"chain": [
|
||||
{
|
||||
"name": "config",
|
||||
"kind": "step",
|
||||
"origin": "mesh:<teapot>",
|
||||
"needs": [],
|
||||
"provides": [
|
||||
"config"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "who",
|
||||
"kind": "handler",
|
||||
"origin": "module:TeacupModule",
|
||||
"needs": [
|
||||
"config"
|
||||
],
|
||||
"provides": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"explainRemote": {
|
||||
"error": {
|
||||
"name": "Error",
|
||||
"message": "no route: /api/remote/ping"
|
||||
}
|
||||
},
|
||||
"openapi": {
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Parity",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/api/local/who": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/local/{id}": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"lookup": {
|
||||
"path": "/api/remote/ping",
|
||||
"status": 200,
|
||||
"body": "{\"from\":\"teapot\"}"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,285 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": {
|
||||
"openapi": "3.1.0",
|
||||
"info": {
|
||||
"title": "Parity",
|
||||
"version": "1"
|
||||
},
|
||||
"paths": {
|
||||
"/api/items/{id}/files/{path}": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "path",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/items": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/items/{id}": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": "\\d+"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "expand",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"head": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": "\\d+"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"options": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": "\\d+"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"delete": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": "\\d+"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/items/{slug}": {
|
||||
"put": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation failed"
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "slug",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"pattern": "[a-z0-9-]+"
|
||||
}
|
||||
}
|
||||
],
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/items/search": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/events": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Event stream",
|
||||
"content": {
|
||||
"text/event-stream": {}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/feed": {
|
||||
"get": {
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Stream",
|
||||
"content": {
|
||||
"application/x-ndjson": {}
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,214 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"id": "W01-overlap",
|
||||
"declarations": [
|
||||
{
|
||||
"id": "param",
|
||||
"pattern": "/ws/:id"
|
||||
},
|
||||
{
|
||||
"id": "static",
|
||||
"pattern": "/ws/static"
|
||||
},
|
||||
{
|
||||
"id": "rest",
|
||||
"pattern": "/ws/:rest*"
|
||||
}
|
||||
],
|
||||
"outcomes": [
|
||||
{
|
||||
"path": "/ws/static",
|
||||
"route": {
|
||||
"id": "param",
|
||||
"params": {
|
||||
"id": "static"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/x",
|
||||
"route": {
|
||||
"id": "param",
|
||||
"params": {
|
||||
"id": "x"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/a%20b",
|
||||
"route": {
|
||||
"id": "param",
|
||||
"params": {
|
||||
"id": "a b"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/x/y",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "x/y"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/w",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/w/a%2Fb/c",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/nope",
|
||||
"route": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "W02-overlap-reversed",
|
||||
"declarations": [
|
||||
{
|
||||
"id": "rest",
|
||||
"pattern": "/ws/:rest*"
|
||||
},
|
||||
{
|
||||
"id": "static",
|
||||
"pattern": "/ws/static"
|
||||
},
|
||||
{
|
||||
"id": "param",
|
||||
"pattern": "/ws/:id"
|
||||
}
|
||||
],
|
||||
"outcomes": [
|
||||
{
|
||||
"path": "/ws/static",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "static"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/x",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "x"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/a%20b",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "a b"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/ws/x/y",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "x/y"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/w",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/w/a%2Fb/c",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/nope",
|
||||
"route": null
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"id": "W03-catch-all-first",
|
||||
"declarations": [
|
||||
{
|
||||
"id": "rest",
|
||||
"pattern": "/w/:rest*"
|
||||
},
|
||||
{
|
||||
"id": "exact",
|
||||
"pattern": "/w"
|
||||
}
|
||||
],
|
||||
"outcomes": [
|
||||
{
|
||||
"path": "/ws/static",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/ws/x",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/ws/a%20b",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/ws",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/ws/x/y",
|
||||
"route": null
|
||||
},
|
||||
{
|
||||
"path": "/w",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/w/a%2Fb/c",
|
||||
"route": {
|
||||
"id": "rest",
|
||||
"params": {
|
||||
"rest": "a/b/c"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/nope",
|
||||
"route": null
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/ca/b",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "OPTIONS",
|
||||
"path": "/ca/b",
|
||||
"status": 204,
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/ca/x",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "HEAD",
|
||||
"path": "/ca/b",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/ca/x/y",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/cb/b",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, POST, DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "OPTIONS",
|
||||
"path": "/cb/b",
|
||||
"status": 204,
|
||||
"allow": "GET, HEAD, POST, DELETE, OPTIONS",
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/cb/x",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "HEAD",
|
||||
"path": "/cb/b",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "fetch",
|
||||
"method": "PUT",
|
||||
"path": "/cb/x/y",
|
||||
"status": 405,
|
||||
"allow": "DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/ca/b",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "OPTIONS",
|
||||
"path": "/ca/b",
|
||||
"status": 204,
|
||||
"allow": "GET, HEAD, POST, OPTIONS",
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/ca/x",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "HEAD",
|
||||
"path": "/ca/b",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/ca/x/y",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/cb/b",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, POST, DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "OPTIONS",
|
||||
"path": "/cb/b",
|
||||
"status": 204,
|
||||
"allow": "GET, HEAD, POST, DELETE, OPTIONS",
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/cb/x",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "HEAD",
|
||||
"path": "/cb/b",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"adapter": "node",
|
||||
"method": "PUT",
|
||||
"path": "/cb/x/y",
|
||||
"status": 405,
|
||||
"allow": "DELETE, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"phase": "A1 teapot up at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"from\":\"teapot\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A1 teapot up at boot",
|
||||
"method": "POST",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A1 teapot up at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/local/ok",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"from\":\"teacup\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A1 teapot up at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/nope",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A2 teapot gone after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 503,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"mesh link to <teapot>/__mesh__/control is down\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A2 teapot gone after boot",
|
||||
"method": "POST",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 405,
|
||||
"allow": "GET, HEAD, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A2 teapot gone after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/local/ok",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"from\":\"teacup\"}"
|
||||
},
|
||||
{
|
||||
"phase": "A2 teapot gone after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/nope",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B1 teapot absent at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B1 teapot absent at boot",
|
||||
"method": "POST",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B1 teapot absent at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/local/ok",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"from\":\"teacup\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B1 teapot absent at boot",
|
||||
"method": "GET",
|
||||
"path": "/api/nope",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B2 teapot up after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B2 teapot up after boot",
|
||||
"method": "POST",
|
||||
"path": "/api/remote/ping",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B2 teapot up after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/local/ok",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"from\":\"teacup\"}"
|
||||
},
|
||||
{
|
||||
"phase": "B2 teapot up after boot",
|
||||
"method": "GET",
|
||||
"path": "/api/nope",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"path": "/live/lobby",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/kitchen",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "kitchen"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/lobby/",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/x/../lobby",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/a%20b",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "a b"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/lobby?x=1",
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live/%E0%A4%A",
|
||||
"sent": [],
|
||||
"closes": [
|
||||
{
|
||||
"code": 1008,
|
||||
"reason": "invalid request path"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/live//lobby",
|
||||
"sent": [],
|
||||
"closes": [
|
||||
{
|
||||
"code": 1008,
|
||||
"reason": "invalid request path"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/plain",
|
||||
"sent": [],
|
||||
"closes": [
|
||||
{
|
||||
"code": 1008,
|
||||
"reason": "no matching ws route"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/nope",
|
||||
"sent": [],
|
||||
"closes": [
|
||||
{
|
||||
"code": 1008,
|
||||
"reason": "no matching ws route"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/feed",
|
||||
"sent": [
|
||||
{
|
||||
"id": "feed",
|
||||
"params": {}
|
||||
}
|
||||
],
|
||||
"closes": [
|
||||
{}
|
||||
]
|
||||
},
|
||||
{
|
||||
"path": "/__mesh__/control",
|
||||
"sent": [],
|
||||
"closes": [
|
||||
{
|
||||
"code": 1008,
|
||||
"reason": "mesh control channel not enabled: this app exports nothing, or has no mesh.secret"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/live/lobby",
|
||||
"status": 405,
|
||||
"allow": "POST, OPTIONS",
|
||||
"body": "{\"error\":\"Method Not Allowed\"}"
|
||||
},
|
||||
{
|
||||
"method": "POST",
|
||||
"path": "/live/lobby",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"id\":\"httpLobby\"}"
|
||||
},
|
||||
{
|
||||
"method": "OPTIONS",
|
||||
"path": "/live/lobby",
|
||||
"status": 204,
|
||||
"allow": "POST, OPTIONS",
|
||||
"body": ""
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/live/kitchen",
|
||||
"status": 404,
|
||||
"allow": null,
|
||||
"body": "{\"error\":\"Not Found\"}"
|
||||
},
|
||||
{
|
||||
"method": "GET",
|
||||
"path": "/feed",
|
||||
"status": 200,
|
||||
"allow": null,
|
||||
"body": "{\"id\":\"feed\",\"params\":{}}\n"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
{
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"data": [
|
||||
{
|
||||
"path": "/live/lobby",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/kitchen",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "kitchen"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/lobby/",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/x/../lobby",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/a%20b",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "a b"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/lobby?x=1",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "liveRoom",
|
||||
"params": {
|
||||
"room": "lobby"
|
||||
}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/live/%E0%A4%A",
|
||||
"status": 400,
|
||||
"sent": []
|
||||
},
|
||||
{
|
||||
"path": "/live//lobby",
|
||||
"status": 400,
|
||||
"sent": []
|
||||
},
|
||||
{
|
||||
"path": "/plain",
|
||||
"status": 404,
|
||||
"sent": []
|
||||
},
|
||||
{
|
||||
"path": "/nope",
|
||||
"status": 404,
|
||||
"sent": []
|
||||
},
|
||||
{
|
||||
"path": "/feed",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "feed",
|
||||
"params": {}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"path": "/__mesh__/control",
|
||||
"status": 101,
|
||||
"sent": [
|
||||
{
|
||||
"id": "reserved",
|
||||
"params": {}
|
||||
}
|
||||
],
|
||||
"close": {
|
||||
"code": 1005,
|
||||
"reason": ""
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,211 @@
|
||||
/**
|
||||
* Fixed-seed route/path generator for the differential corpus.
|
||||
*
|
||||
* Its output is versioned with the fixture: `frozen/matcher-generated.json` stores the seed, the
|
||||
* rules below and every generated declaration and request. The test regenerates from the seed and
|
||||
* requires the result to equal the stored inputs, so a change to this file cannot quietly move the
|
||||
* baseline — it fails until someone deliberately starts a new generator version.
|
||||
*
|
||||
* Do not edit GENERATOR_V1. A new generator is a new version with its own frozen file.
|
||||
*/
|
||||
import { compilePattern } from './oracle';
|
||||
import type { Declaration, Request, Scenario, Transport } from './matcher';
|
||||
|
||||
export const GENERATOR_SEED = 10908;
|
||||
export const GENERATOR_VERSION = 'router-parity-gen-v1';
|
||||
|
||||
export const GENERATOR_RULES = [
|
||||
'PRNG: mulberry32(seed); every choice below draws from it in program order.',
|
||||
'40 scenarios; each has 2-10 declarations and 12 requests.',
|
||||
'Declaration: 0-3 segments, each static (a|b|c|x, p=0.5), plain param (p=0.25) or constrained param (p=0.25) ' +
|
||||
'using one of \\d+ | [a-c]+ | [0-9a-f]{2}; then a final catch-all with p=0.2. Param names are p<index>.',
|
||||
'Declaration method from GET x3, POST, PUT, DELETE, PATCH, HEAD, OPTIONS. A GET is buffer with p=0.7, else ' +
|
||||
'sse | ndjson | negotiate; every other method is buffer.',
|
||||
'Request path: p=0.6 instantiate a random declaration (static -> its literal, param -> value pool, catch-all -> ' +
|
||||
'0-2 pool values), else 0-4 random pool segments. Value pool: a b c x 7 42 ff 0a a%20b caf%C3%A9 %34%32.',
|
||||
'Request decoration: trailing slash p=0.15, a dot segment (/./ or /q/../) inserted p=0.1, a repeated slash p=0.05.',
|
||||
'Request method from GET x2, HEAD, POST, PUT, DELETE, PATCH, OPTIONS.',
|
||||
'Unsupported patterns are never produced: every generated pattern must pass compilePattern.',
|
||||
];
|
||||
|
||||
const STATICS = ['a', 'b', 'c', 'x'];
|
||||
const CONSTRAINTS = ['\\d+', '[a-c]+', '[0-9a-f]{2}'];
|
||||
const VALUES = ['a', 'b', 'c', 'x', '7', '42', 'ff', '0a', 'a%20b', 'caf%C3%A9', '%34%32'];
|
||||
const DECL_METHODS = ['GET', 'GET', 'GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
||||
const STREAMING: Transport[] = ['sse', 'ndjson', 'negotiate'];
|
||||
const REQUEST_METHODS = ['GET', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'];
|
||||
|
||||
type Rng = () => number;
|
||||
|
||||
function mulberry32(seed: number): Rng {
|
||||
let state = seed >>> 0;
|
||||
return () => {
|
||||
state = (state + 0x6d2b79f5) >>> 0;
|
||||
let t = state;
|
||||
t = Math.imul(t ^ (t >>> 15), t | 1);
|
||||
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
||||
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||
};
|
||||
}
|
||||
|
||||
const pick = <T>(rng: Rng, items: readonly T[]): T => items[Math.floor(rng() * items.length)];
|
||||
const int = (rng: Rng, min: number, max: number): number => min + Math.floor(rng() * (max - min + 1));
|
||||
|
||||
function patternSegment(rng: Rng, index: number): string {
|
||||
const roll = rng();
|
||||
if (roll < 0.5) return pick(rng, STATICS);
|
||||
if (roll < 0.75) return `:p${index}`;
|
||||
return `:p${index}(${pick(rng, CONSTRAINTS)})`;
|
||||
}
|
||||
|
||||
function declaration(rng: Rng, id: string): Declaration {
|
||||
const depth = int(rng, 0, 3);
|
||||
const segments = Array.from({ length: depth }, (_, index) => patternSegment(rng, index));
|
||||
if (rng() < 0.2) segments.push(`:p${depth}*`);
|
||||
|
||||
const method = pick(rng, DECL_METHODS);
|
||||
const transport: Transport = method === 'GET' && rng() >= 0.7 ? pick(rng, STREAMING) : 'buffer';
|
||||
const pattern = `/${segments.join('/')}`;
|
||||
compilePattern(pattern); // throws if a rule above ever produced an unsupported pattern
|
||||
return { id, method, pattern, transport };
|
||||
}
|
||||
|
||||
function instantiate(rng: Rng, decl: Declaration): string[] {
|
||||
const segments: string[] = [];
|
||||
|
||||
for (const segment of decl.pattern.split('/').slice(1)) {
|
||||
if (!segment) continue;
|
||||
if (segment.endsWith('*')) {
|
||||
const count = int(rng, 0, 2);
|
||||
for (let index = 0; index < count; index++) segments.push(pick(rng, VALUES));
|
||||
} else {
|
||||
segments.push(segment.startsWith(':') ? pick(rng, VALUES) : segment);
|
||||
}
|
||||
}
|
||||
|
||||
return segments;
|
||||
}
|
||||
|
||||
function decorate(rng: Rng, segments: string[]): string {
|
||||
let path = `/${segments.join('/')}`;
|
||||
if (rng() < 0.15 && path !== '/') path += '/';
|
||||
|
||||
if (rng() < 0.1) {
|
||||
const at = int(rng, 0, segments.length);
|
||||
const dots = rng() < 0.5 ? ['.'] : ['q', '..'];
|
||||
const withDots = [...segments.slice(0, at), ...dots, ...segments.slice(at)];
|
||||
path = `/${withDots.join('/')}`;
|
||||
}
|
||||
|
||||
if (rng() < 0.05) path = path.replace('/', '//');
|
||||
return path;
|
||||
}
|
||||
|
||||
function request(rng: Rng, declarations: Declaration[]): Request {
|
||||
const segments =
|
||||
rng() < 0.6
|
||||
? instantiate(rng, pick(rng, declarations))
|
||||
: Array.from({ length: int(rng, 0, 4) }, () => pick(rng, VALUES));
|
||||
return { method: pick(rng, REQUEST_METHODS), raw: decorate(rng, segments) };
|
||||
}
|
||||
|
||||
export function generateScenarios(seed: number = GENERATOR_SEED): Scenario[] {
|
||||
const rng = mulberry32(seed);
|
||||
|
||||
return Array.from({ length: 40 }, (_, index): Scenario => {
|
||||
const id = `G${String(index + 1).padStart(2, '0')}`;
|
||||
const declarations = Array.from({ length: int(rng, 2, 10) }, (_, d) => declaration(rng, `${id}.d${d + 1}`));
|
||||
const requests = Array.from({ length: 12 }, () => request(rng, declarations));
|
||||
return { id, note: `generated by ${GENERATOR_VERSION}, seed ${seed}`, declarations, requests };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Version 2: the same seed and helpers, plus rules that force shared prefixes, so a meaningful share
|
||||
* of cases puts static, param, constrained and catch-all siblings under one prefix and makes the
|
||||
* lookup leave a branch it has already walked into. Frozen in `frozen/matcher-generated-v2.json`;
|
||||
* v1 above and its frozen file are unchanged.
|
||||
*/
|
||||
export const GENERATOR_V2_VERSION = 'router-parity-gen-v2';
|
||||
|
||||
export const GENERATOR_V2_RULES = [
|
||||
'PRNG: mulberry32(seed), fresh for v2; every choice below draws from it in program order.',
|
||||
'40 scenarios; each has a shared static prefix of 0-3 segments (a|b|c|x), so siblings sit at depth 1-4.',
|
||||
'Each scenario has 3-6 sibling declarations: prefix + one sibling segment + a tail. The first sibling segment is ' +
|
||||
'static, the second a plain or constrained param; the rest are static (p=0.35), plain (p=0.25), constrained ' +
|
||||
'(p=0.25) or a final catch-all (p=0.15). Tails are 0-2 segments, static/plain/constrained, none after a catch-all.',
|
||||
'Then 0-3 unrelated declarations made by the v1 declaration rule.',
|
||||
'Methods and transports follow the v1 declaration rule.',
|
||||
'Requests (12): p=0.5 instantiate a sibling; p=0.25 cross two siblings (prefix and sibling segment of one, tail ' +
|
||||
'of another) to force a partial match; else prefix + 0-3 pool values. v1 decoration and request methods apply.',
|
||||
'Unsupported patterns are never produced: every generated pattern must pass compilePattern.',
|
||||
];
|
||||
|
||||
function siblingSegment(rng: Rng, depth: number, index: number): string {
|
||||
if (index === 0) return pick(rng, STATICS);
|
||||
if (index === 1) return rng() < 0.5 ? `:p${depth}` : `:p${depth}(${pick(rng, CONSTRAINTS)})`;
|
||||
const roll = rng();
|
||||
if (roll < 0.35) return pick(rng, STATICS);
|
||||
if (roll < 0.6) return `:p${depth}`;
|
||||
if (roll < 0.85) return `:p${depth}(${pick(rng, CONSTRAINTS)})`;
|
||||
return `:p${depth}*`;
|
||||
}
|
||||
|
||||
function siblingDeclaration(rng: Rng, id: string, prefix: string[], index: number): Declaration {
|
||||
const sibling = siblingSegment(rng, prefix.length, index);
|
||||
const segments = [...prefix, sibling];
|
||||
if (!sibling.endsWith('*')) {
|
||||
const tail = int(rng, 0, 2);
|
||||
for (let t = 0; t < tail; t++) {
|
||||
const depth = segments.length;
|
||||
const roll = rng();
|
||||
segments.push(
|
||||
roll < 0.5 ? pick(rng, STATICS) : roll < 0.75 ? `:p${depth}` : `:p${depth}(${pick(rng, CONSTRAINTS)})`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const method = pick(rng, DECL_METHODS);
|
||||
const transport: Transport = method === 'GET' && rng() >= 0.7 ? pick(rng, STREAMING) : 'buffer';
|
||||
const pattern = `/${segments.join('/')}`;
|
||||
compilePattern(pattern);
|
||||
return { id, method, pattern, transport };
|
||||
}
|
||||
|
||||
function siblingRequest(rng: Rng, prefixLength: number, siblings: Declaration[]): Request {
|
||||
const roll = rng();
|
||||
let segments: string[];
|
||||
|
||||
if (roll < 0.5) {
|
||||
segments = instantiate(rng, pick(rng, siblings));
|
||||
} else if (roll < 0.75) {
|
||||
const head = instantiate(rng, pick(rng, siblings)).slice(0, prefixLength + 1);
|
||||
const tail = instantiate(rng, pick(rng, siblings)).slice(prefixLength + 1);
|
||||
segments = [...head, ...tail];
|
||||
} else {
|
||||
const prefix = instantiate(rng, siblings[0]).slice(0, prefixLength);
|
||||
segments = [...prefix, ...Array.from({ length: int(rng, 0, 3) }, () => pick(rng, VALUES))];
|
||||
}
|
||||
|
||||
return { method: pick(rng, REQUEST_METHODS), raw: decorate(rng, segments) };
|
||||
}
|
||||
|
||||
export function generateScenariosV2(seed: number = GENERATOR_SEED): Scenario[] {
|
||||
const rng = mulberry32(seed);
|
||||
|
||||
return Array.from({ length: 40 }, (_, index): Scenario => {
|
||||
const id = `S${String(index + 1).padStart(2, '0')}`;
|
||||
const prefix = Array.from({ length: int(rng, 0, 3) }, () => pick(rng, STATICS));
|
||||
const siblings = Array.from({ length: int(rng, 3, 6) }, (_, s) =>
|
||||
siblingDeclaration(rng, `${id}.s${s + 1}`, prefix, s),
|
||||
);
|
||||
const unrelated = Array.from({ length: int(rng, 0, 3) }, (_, u) => declaration(rng, `${id}.u${u + 1}`));
|
||||
const requests = Array.from({ length: 12 }, () => siblingRequest(rng, prefix.length, siblings));
|
||||
return {
|
||||
id,
|
||||
note: `generated by ${GENERATOR_V2_VERSION}, seed ${seed}, shared prefix /${prefix.join('/')}`,
|
||||
declarations: [...siblings, ...unrelated],
|
||||
requests,
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,227 @@
|
||||
/**
|
||||
* Introspection goldens (ROUTER-CORPUS §3, CARD-09). `graph()`, `explain()` and `openapi()` read
|
||||
* `routePlans` in declaration order and must never be derived from a lookup index. Compared as
|
||||
* parsed structures with array order and key order held — see `expectFrozenEqual`.
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import type { AddressInfo } from 'net';
|
||||
import { describe, it } from 'vitest';
|
||||
import {
|
||||
createApp,
|
||||
Provider,
|
||||
Step,
|
||||
Route,
|
||||
Get,
|
||||
Head,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Options,
|
||||
Sse,
|
||||
Stream,
|
||||
Ws,
|
||||
Module,
|
||||
needs,
|
||||
param,
|
||||
query,
|
||||
body,
|
||||
} from '../../src/index';
|
||||
import type { Logger } from '../../src/logger';
|
||||
import { errorOutcome } from './matcher';
|
||||
import { frozen, expectFrozenEqual } from './frozen';
|
||||
|
||||
const slugSchema = {
|
||||
'~standard': { version: 1 as const, vendor: 'parity', validate: (v: unknown) => ({ value: v }) },
|
||||
};
|
||||
|
||||
@Provider({ provides: 'db' })
|
||||
class Db {
|
||||
provide() {
|
||||
return { db: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@Step({ provides: 'user', needs: ['db'] })
|
||||
class Auth {
|
||||
run() {
|
||||
return { user: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@Step({ provides: 'audit', needs: [] })
|
||||
class Audit {
|
||||
run() {
|
||||
return { audit: {} };
|
||||
}
|
||||
}
|
||||
|
||||
// Declaration order is deliberately not specificity order, and paths repeat across methods, so
|
||||
// any traversal-ordered output would differ from this one.
|
||||
@Route('/items')
|
||||
class Items {
|
||||
@Get('/:id/files/:path*') files(@param('path') _p: string) {
|
||||
return {};
|
||||
}
|
||||
@Get('/') list(@needs('user') _u: unknown) {
|
||||
return [];
|
||||
}
|
||||
@Post('/') create(@body() _b: unknown, @needs('user') _u: unknown) {
|
||||
return {};
|
||||
}
|
||||
@Get('/:id(\\d+)') get(@param('id') _id: string, @query('expand') _e: string) {
|
||||
return {};
|
||||
}
|
||||
@Head('/:id(\\d+)') head() {
|
||||
return {};
|
||||
}
|
||||
@Options('/:id(\\d+)') options() {
|
||||
return {};
|
||||
}
|
||||
@Delete('/:id(\\d+)') remove(@needs('audit') _a: unknown) {
|
||||
return {};
|
||||
}
|
||||
@Put('/:slug([a-z0-9-]+)') upsert(@body(slugSchema) _b: unknown) {
|
||||
return {};
|
||||
}
|
||||
@Get('/search') search() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@Route('/')
|
||||
class Streams {
|
||||
@Sse('/events') events() {
|
||||
return (async function* () {})();
|
||||
}
|
||||
@Stream('/feed') feed() {
|
||||
return (async function* () {})();
|
||||
}
|
||||
@Ws('/live/:room') live(@needs('user') _u: unknown) {
|
||||
return (async function* () {})();
|
||||
}
|
||||
}
|
||||
|
||||
@Module({ mountpoint: '/api', providers: [Db], steps: [Auth, Audit], controllers: [Items, Streams] })
|
||||
class IntrospectionModule {}
|
||||
|
||||
const EXPLAINED = ['/api/items/:id(\\d+)', '/api/items', '/api/live/:room', '/api/items/:id/files/:path*'];
|
||||
const NOT_DECLARED = ['/api/missing', '/api/items/42', '/api/items/'];
|
||||
|
||||
function explainAll(explain: (pattern: string) => unknown) {
|
||||
return [...EXPLAINED, ...NOT_DECLARED].map((pattern) => {
|
||||
try {
|
||||
return { pattern, explain: explain(pattern) };
|
||||
} catch (error) {
|
||||
return { pattern, error: errorOutcome(error) };
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function capture() {
|
||||
const app = createApp({ modules: [IntrospectionModule] });
|
||||
return {
|
||||
graph: app.graph(),
|
||||
explain: explainAll(app.explain),
|
||||
openapi: app.openapi({ title: 'Parity', version: '1' }),
|
||||
};
|
||||
}
|
||||
|
||||
// ── mesh ────────────────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const SECRET = 'parity-secret';
|
||||
|
||||
@Step({ provides: 'config', needs: [], export: true })
|
||||
class Config {
|
||||
run() {
|
||||
return { config: {} };
|
||||
}
|
||||
}
|
||||
|
||||
@Route('/remote')
|
||||
class RemoteCtl {
|
||||
@Get('/ping', { export: true }) ping() {
|
||||
return { from: 'teapot' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', steps: [Config], controllers: [RemoteCtl] })
|
||||
class TeapotModule {}
|
||||
|
||||
@Route('/local')
|
||||
class LocalCtl {
|
||||
@Get('/who') who(@needs('config') _c: unknown) {
|
||||
return { from: 'teacup' };
|
||||
}
|
||||
@Get('/:id') byId() {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [LocalCtl] })
|
||||
class TeacupModule {}
|
||||
|
||||
const quiet: Logger = { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} };
|
||||
|
||||
function attempt<T>(fn: () => T): { value: T } | { error: ReturnType<typeof errorOutcome> } {
|
||||
try {
|
||||
return { value: fn() };
|
||||
} catch (error) {
|
||||
return { error: errorOutcome(error) };
|
||||
}
|
||||
}
|
||||
|
||||
async function captureMesh() {
|
||||
const teapot = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
|
||||
const server = await teapot.listen(0);
|
||||
const url = `ws://127.0.0.1:${(server.address() as AddressInfo).port}/__mesh__/control`;
|
||||
const anonymize = (value: unknown) => JSON.parse(JSON.stringify(value).split(url).join('<teapot>'));
|
||||
const teacup = createApp({
|
||||
modules: [TeacupModule],
|
||||
experimental: true,
|
||||
logger: quiet,
|
||||
mesh: { teapots: [{ url, secret: SECRET }] },
|
||||
});
|
||||
|
||||
try {
|
||||
const before = {
|
||||
graph: attempt(() => teacup.graph()),
|
||||
explain: attempt(() => teacup.explain('/api/local/who')),
|
||||
openapi: attempt(() => teacup.openapi({ title: 'Parity', version: '1' })),
|
||||
};
|
||||
await teacup.ready();
|
||||
const after = {
|
||||
graph: teacup.graph(),
|
||||
explain: explainAll(teacup.explain).filter(({ pattern }) => pattern === '/api/missing'),
|
||||
explainLocal: teacup.explain('/api/local/who'),
|
||||
explainRemote: attempt(() => teacup.explain('/api/remote/ping')),
|
||||
openapi: teacup.openapi({ title: 'Parity', version: '1' }),
|
||||
};
|
||||
// Remote routes are reachable for lookup even though they are absent from routePlans.
|
||||
const res = await teacup.fetch(new Request('http://parity.test/api/remote/ping'));
|
||||
const lookup = { path: '/api/remote/ping', status: res.status, body: await res.text() };
|
||||
return anonymize({ before, after, lookup });
|
||||
} finally {
|
||||
await teacup.close();
|
||||
await teapot.close();
|
||||
}
|
||||
}
|
||||
|
||||
describe('router parity: introspection goldens', () => {
|
||||
it('graph() equals the golden, routes in declaration order', async () => {
|
||||
const expected = await frozen('golden-graph', () => capture().graph);
|
||||
expectFrozenEqual(capture().graph, expected, 'graph()');
|
||||
});
|
||||
|
||||
it('explain() for declared patterns and the `no route:` error equals the golden', async () => {
|
||||
const expected = await frozen('golden-explain', () => capture().explain);
|
||||
expectFrozenEqual(capture().explain, expected, 'explain()');
|
||||
});
|
||||
|
||||
it("openapi({ title: 'Parity', version: '1' }) equals the golden", async () => {
|
||||
const expected = await frozen('golden-openapi', () => capture().openapi);
|
||||
expectFrozenEqual(capture().openapi, expected, 'openapi()');
|
||||
});
|
||||
|
||||
it('a mesh teacup before and after ready() equals the golden; remote routes stay out of routePlans', async () => {
|
||||
const expected = await frozen('golden-mesh', captureMesh);
|
||||
expectFrozenEqual(await captureMesh(), expected, 'mesh introspection');
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,155 @@
|
||||
{
|
||||
"purpose": "Existing tests retained unchanged as the radix-router compatibility baseline (FPRD-001 CARD-08, ROUTER-CORPUS §1, #109).",
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"corpusRevision": "42376c6693c7e15fadbcfb544172cc571fcacef0",
|
||||
"verification": {
|
||||
"date": "2026-10-10",
|
||||
"revision": "ed47836c9820c47bf4ed5e902d91e019abdb110a",
|
||||
"command": "npx vitest run <every vitest file below> --reporter=json; npm run test:deno; npm run test:bun; npm run test:edge",
|
||||
"result": "Every file and every named test exists at the pinned revision and passes. No test was renamed or removed between 42376c6 and ed47836; src/http/router.ts is byte-identical between the two.",
|
||||
"renamed": []
|
||||
},
|
||||
"retained": [
|
||||
{
|
||||
"surface": "Pattern grammar, normalization, matching, Allow, HEAD",
|
||||
"file": "test/router.test.ts",
|
||||
"scope": "file"
|
||||
},
|
||||
{
|
||||
"surface": "HTTP adapter",
|
||||
"file": "test/http.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"matches a static + :param route and extracts params",
|
||||
"http streaming > routes by method (non-GET no longer falls through)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"surface": "Fetch adapter",
|
||||
"file": "test/fetch.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"app.fetch > handles GET and returns JSON 200",
|
||||
"app.fetch > 404s an unknown route",
|
||||
"app.fetch on a mesh app > serves without ever calling listen()",
|
||||
"app.fetch on a mesh app > does not re-boot when listen() follows a fetch"
|
||||
]
|
||||
},
|
||||
{
|
||||
"surface": "App declarations and introspection",
|
||||
"file": "test/app.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"app.graph / explain > graph() returns nodes (with origin/needs/provides) and routes with their sliced chain",
|
||||
"app.graph / explain > explain() returns the rich chain with origin and a handler entry",
|
||||
"route table validation > rejects routes with the same method and effective pattern",
|
||||
"route table validation > allows the same effective pattern under different methods",
|
||||
"devGraph endpoint > serves /__graph__ as HTML when devGraph:true",
|
||||
"devGraph endpoint > does NOT mount /__graph__ without devGraph",
|
||||
"devGraph endpoint > serves /__graph__ and /__openapi__ over app.fetch too (runtime-agnostic dev tools)",
|
||||
"app streaming wiring > serves a @Ws route receiving @inbound and returning a channel"
|
||||
]
|
||||
},
|
||||
{
|
||||
"surface": "OpenAPI",
|
||||
"file": "test/openapi.test.ts",
|
||||
"scope": "file"
|
||||
},
|
||||
{
|
||||
"surface": "WebSocket selection",
|
||||
"file": "test/ws-core.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": ["runWsConnection (neutral core) > matchWsRoute finds a pattern and captures params"]
|
||||
},
|
||||
{
|
||||
"surface": "Node WebSocket upgrade",
|
||||
"file": "test/ws.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"ws upgrade > echoes inbound to outbound and aborts on close",
|
||||
"ws upgrade > closes with a 4000+status code when the WS open() throws an HttpError"
|
||||
]
|
||||
},
|
||||
{
|
||||
"surface": "Mesh route splicing",
|
||||
"file": "test/mesh/integration.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"mesh skeleton integration > teapot still serves its own local route (regression)",
|
||||
"mesh skeleton integration > refuses to boot when two teapots export the same route, naming both",
|
||||
"mesh skeleton integration > refuses ambiguous remote routes that differ only by parameter name",
|
||||
"mesh skeleton integration > accepts the same route from a single teapot (regression: no false positive)",
|
||||
"mesh skeleton integration > gives a local route precedence over a remote one, and says so",
|
||||
"mesh skeleton integration > does not warn when a remote route has no local twin"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runtimeSmoke": [
|
||||
{
|
||||
"file": "test/deno/ws.test.ts",
|
||||
"runner": "npm run test:deno",
|
||||
"tests": [
|
||||
"serveDeno: HTTP + WebSocket round-trip through the graph",
|
||||
"serveDeno: a malformed upgrade path closes 1008 and the server keeps serving"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "test/bun/ws.test.ts",
|
||||
"runner": "npm run test:bun",
|
||||
"tests": [
|
||||
"serveBun: HTTP + WebSocket round-trip",
|
||||
"serveBun: a malformed upgrade path closes 1008 and the server keeps serving"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "test/deno/mesh.test.ts",
|
||||
"runner": "npm run test:deno",
|
||||
"tests": [
|
||||
"mesh on Deno: teacup resolves a Deno teapot through the graph",
|
||||
"mesh on Deno: a teapot refuses a bad secret over its control channel"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "test/bun/mesh.test.ts",
|
||||
"runner": "npm run test:bun",
|
||||
"tests": [
|
||||
"mesh on Bun: teacup resolves a Bun teapot through the graph",
|
||||
"mesh on Bun: a teapot refuses a bad secret over its control channel"
|
||||
]
|
||||
},
|
||||
{
|
||||
"file": "test/edge/run.ts",
|
||||
"runner": "npm run test:edge",
|
||||
"tests": []
|
||||
}
|
||||
],
|
||||
"supplementary": {
|
||||
"note": "Not in ROUTER-CORPUS §1. Proposed because #117 (merged after the corpus was written) moved WS upgrade paths through normalizeRequestPath and added the reserved-path refusal on app.upgrade. Pending D5 approval; they run in npm test either way.",
|
||||
"retained": [
|
||||
{
|
||||
"surface": "Node upgrade path normalization and rejection (#104)",
|
||||
"file": "test/ws-upgrade-reject.test.ts",
|
||||
"scope": "file"
|
||||
},
|
||||
{
|
||||
"surface": "Reserved mesh control path ahead of WS routes (Node)",
|
||||
"file": "test/mesh/control-upgrade.test.ts",
|
||||
"scope": "file"
|
||||
},
|
||||
{
|
||||
"surface": "Reserved mesh control path over app.upgrade",
|
||||
"file": "test/mesh/fetch-boot.test.ts",
|
||||
"scope": "tests",
|
||||
"tests": [
|
||||
"mesh control over app.upgrade (no listen) > serves the handshake to a peer that never touched a Node server",
|
||||
"mesh control over app.upgrade (no listen) > refuses the reserved path explicitly on an app that exports nothing"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"frozenFixtures": {
|
||||
"dir": "test/router-parity/frozen",
|
||||
"oracle": "test/router-parity/oracle.ts",
|
||||
"readme": "test/router-parity/README.md"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Keeps the retained-test manifest honest: every file it names must exist and every test it names
|
||||
* must still be declared there. A rename or deletion during CARD-07 fails here instead of silently
|
||||
* shrinking the compatibility baseline. Whether those tests *pass* is `npm test` and the runtime
|
||||
* suites' job; this only proves they are still the tests the manifest says they are.
|
||||
*/
|
||||
import { existsSync, readFileSync, readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { PINNED_REVISION } from './frozen';
|
||||
|
||||
interface Entry {
|
||||
file: string;
|
||||
scope?: 'file' | 'tests';
|
||||
tests?: string[];
|
||||
}
|
||||
|
||||
const ROOT = join(__dirname, '..', '..');
|
||||
const manifest = JSON.parse(readFileSync(join(__dirname, 'manifest.json'), 'utf8')) as {
|
||||
revision: string;
|
||||
retained: Entry[];
|
||||
runtimeSmoke: Entry[];
|
||||
supplementary: { retained: Entry[] };
|
||||
frozenFixtures: { oracle: string; readme: string };
|
||||
};
|
||||
|
||||
const entries: Entry[] = [...manifest.retained, ...manifest.runtimeSmoke, ...manifest.supplementary.retained];
|
||||
|
||||
describe('router parity: retained-test manifest', () => {
|
||||
it('is pinned to the same revision as the frozen fixtures', () => {
|
||||
expect(manifest.revision).toBe(PINNED_REVISION);
|
||||
});
|
||||
|
||||
for (const entry of entries) {
|
||||
it(`${entry.file} exists and declares every named test`, () => {
|
||||
const path = join(ROOT, entry.file);
|
||||
expect(existsSync(path), `${entry.file} is missing`).toBe(true);
|
||||
const source = readFileSync(path, 'utf8');
|
||||
|
||||
for (const name of entry.tests ?? []) {
|
||||
for (const part of name.split(' > ')) expect(source, `${entry.file}: '${name}'`).toContain(part);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
it('names an oracle and a README that exist', () => {
|
||||
for (const file of [manifest.frozenFixtures.oracle, manifest.frozenFixtures.readme])
|
||||
expect(existsSync(join(ROOT, file)), file).toBe(true);
|
||||
});
|
||||
|
||||
it('the oracle is not imported from src/', () => {
|
||||
// A frozen oracle the product can reach is no longer frozen: someone will "fix" it.
|
||||
const files = readdirSync(join(ROOT, 'src'), { recursive: true, encoding: 'utf8' }).filter((f) =>
|
||||
f.endsWith('.ts'),
|
||||
);
|
||||
const hits = files.filter((f) => readFileSync(join(ROOT, 'src', f), 'utf8').includes('router-parity'));
|
||||
expect(hits).toEqual([]);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Differential matcher parity (CARD-08 → CARD-07, #109).
|
||||
*
|
||||
* Every scenario runs through the frozen oracle and through the live `src/http/router` exports, and
|
||||
* both must equal the outputs captured at the pinned revision. Today the live router *is* the
|
||||
* linear matcher, so this proves the oracle is a faithful copy; once CARD-07 swaps the internals
|
||||
* for a radix index behind the same exports, the same test compares oracle against radix with no
|
||||
* edit here.
|
||||
*/
|
||||
import { describe, it, expect, beforeAll } from 'vitest';
|
||||
import * as live from '../../src/http/router';
|
||||
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, 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;
|
||||
const ORACLE: MatcherImpl = oracle;
|
||||
|
||||
interface CapturedScenario extends Scenario {
|
||||
outcomes: Outcome[];
|
||||
}
|
||||
|
||||
interface GeneratedFile {
|
||||
generator: string;
|
||||
seed: number;
|
||||
rules: string[];
|
||||
scenarios: CapturedScenario[];
|
||||
}
|
||||
|
||||
const capture = (scenarios: Scenario[]): CapturedScenario[] =>
|
||||
scenarios.map((scenario) => ({ ...scenario, outcomes: runScenario(LIVE, scenario) }));
|
||||
|
||||
function checkScenario(scenario: Scenario, expected: CapturedScenario | undefined): void {
|
||||
expect(expected, `${scenario.id} is missing from the frozen fixture`).toBeDefined();
|
||||
const { outcomes, ...inputs } = expected!;
|
||||
expectFrozenEqual(scenario, inputs, `${scenario.id} inputs`);
|
||||
expectFrozenEqual(runScenario(ORACLE, scenario), outcomes, `${scenario.id} oracle`);
|
||||
expectFrozenEqual(runScenario(LIVE, scenario), outcomes, `${scenario.id} live router`);
|
||||
}
|
||||
|
||||
describe('router parity: hand-picked matcher cases', () => {
|
||||
let expected: Map<string, CapturedScenario>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const data = await frozen('matcher-hand', () => capture(HAND_SCENARIOS));
|
||||
expect(data.map((scenario) => scenario.id)).toEqual(HAND_SCENARIOS.map((scenario) => scenario.id));
|
||||
expected = new Map(data.map((scenario) => [scenario.id, scenario]));
|
||||
});
|
||||
|
||||
for (const scenario of HAND_SCENARIOS) {
|
||||
it(`${scenario.id}: ${scenario.note}`, () => checkScenario(scenario, expected.get(scenario.id)));
|
||||
}
|
||||
});
|
||||
|
||||
describe(`router parity: generated matcher cases (${GENERATOR_VERSION}, seed ${GENERATOR_SEED})`, () => {
|
||||
const generated = generateScenarios(GENERATOR_SEED);
|
||||
let expected: Map<string, CapturedScenario>;
|
||||
|
||||
beforeAll(async () => {
|
||||
const data = await frozen<GeneratedFile>('matcher-generated', () => ({
|
||||
generator: GENERATOR_VERSION,
|
||||
seed: GENERATOR_SEED,
|
||||
rules: GENERATOR_RULES,
|
||||
scenarios: capture(generated),
|
||||
}));
|
||||
expect({ generator: data.generator, seed: data.seed, rules: data.rules }).toEqual({
|
||||
generator: GENERATOR_VERSION,
|
||||
seed: GENERATOR_SEED,
|
||||
rules: GENERATOR_RULES,
|
||||
});
|
||||
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: 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.
|
||||
type WsDecl = WsRouteDef & { id: string };
|
||||
type WsMatcher = (
|
||||
routes: WsRouteDef[],
|
||||
path: string,
|
||||
) => { def: WsRouteDef; params: Record<string, string> | undefined } | undefined;
|
||||
const ws = (id: string, pattern: string): WsDecl => ({ id, pattern, open: async () => (async function* () {})() });
|
||||
const overlap = [ws('param', '/ws/:id'), ws('static', '/ws/static'), ws('rest', '/ws/:rest*')];
|
||||
const scenarios = [
|
||||
{ id: 'W01-overlap', routes: overlap },
|
||||
{ id: 'W02-overlap-reversed', routes: [...overlap].reverse() },
|
||||
{ id: 'W03-catch-all-first', routes: [ws('rest', '/w/:rest*'), ws('exact', '/w')] },
|
||||
];
|
||||
const paths = ['/ws/static', '/ws/x', '/ws/a%20b', '/ws', '/ws/x/y', '/w', '/w/a%2Fb/c', '/nope'];
|
||||
|
||||
const run = (matchWs: WsMatcher) =>
|
||||
scenarios.map(({ id, routes }) => ({
|
||||
id,
|
||||
declarations: routes.map((route) => ({ id: route.id, pattern: route.pattern })),
|
||||
outcomes: paths.map((path) => {
|
||||
const hit = matchWs(routes, path);
|
||||
return { path, route: hit ? { id: (hit.def as WsDecl).id, params: hit.params } : null };
|
||||
}),
|
||||
}));
|
||||
|
||||
it('oracle and live matchWsRoute equal the frozen capture', async () => {
|
||||
const expected = await frozen('matcher-ws', () => run(liveMatchWsRoute));
|
||||
expectFrozenEqual(run(oracle.matchWsRoute), expected, 'ws oracle');
|
||||
expectFrozenEqual(run(liveMatchWsRoute), expected, 'ws live');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,107 @@
|
||||
/**
|
||||
* The differential matcher harness: one ordered declaration array and one request list, run through
|
||||
* any implementation of the router's lookup functions, reduced to what a caller can observe —
|
||||
* which declaration answered (by stable ID, never by pattern text), its decoded params, whether HEAD
|
||||
* was implicit, the ordered `Allow` list, and the normalization error if the path never got that far.
|
||||
*/
|
||||
import type { RouteDef } from '../../src/http/types';
|
||||
|
||||
export type Transport = 'buffer' | 'sse' | 'ndjson' | 'negotiate';
|
||||
|
||||
export interface Declaration {
|
||||
id: string;
|
||||
method: string;
|
||||
pattern: string;
|
||||
transport: Transport;
|
||||
}
|
||||
|
||||
export interface Request {
|
||||
method: string;
|
||||
raw: string;
|
||||
}
|
||||
|
||||
export interface Scenario {
|
||||
id: string;
|
||||
note: string;
|
||||
declarations: Declaration[];
|
||||
requests: Request[];
|
||||
}
|
||||
|
||||
/** The lookup surface CARD-07 replaces. The live router and the frozen oracle both satisfy it. */
|
||||
export interface MatcherImpl {
|
||||
normalizeRequestPath(path: string): string;
|
||||
matchRoute(
|
||||
routes: RouteDef[],
|
||||
method: string,
|
||||
path: string,
|
||||
): { def: unknown; params: Record<string, string> } | undefined;
|
||||
resolveRoute(
|
||||
routes: RouteDef[],
|
||||
method: string,
|
||||
path: string,
|
||||
): { def: unknown; params: Record<string, string>; implicitHead: boolean } | undefined;
|
||||
allowedMethods(routes: RouteDef[], path: string): string[];
|
||||
}
|
||||
|
||||
export interface ErrorOutcome {
|
||||
name: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface Outcome {
|
||||
method: string;
|
||||
raw: string;
|
||||
normalized?: string;
|
||||
error?: ErrorOutcome;
|
||||
match?: { id: string; params: Record<string, string> } | null;
|
||||
resolve?: { id: string; params: Record<string, string>; implicitHead: boolean } | null;
|
||||
allow?: string[];
|
||||
}
|
||||
|
||||
export function errorOutcome(error: unknown): ErrorOutcome {
|
||||
const err = error as Error;
|
||||
return { name: err.name, message: err.message };
|
||||
}
|
||||
|
||||
/** Builds fresh `RouteDef` objects for one run, so no implementation can see another's cached table. */
|
||||
function buildRoutes(declarations: Declaration[]): { routes: RouteDef[]; idOf: Map<unknown, string> } {
|
||||
const idOf = new Map<unknown, string>();
|
||||
const routes = declarations.map((decl): RouteDef => {
|
||||
const def: RouteDef = {
|
||||
method: decl.method,
|
||||
pattern: decl.pattern,
|
||||
transport: decl.transport,
|
||||
handler: async () => ({ status: 200, headers: {}, body: decl.id }),
|
||||
};
|
||||
idOf.set(def, decl.id);
|
||||
return def;
|
||||
});
|
||||
return { routes, idOf };
|
||||
}
|
||||
|
||||
export function runScenario(impl: MatcherImpl, scenario: Scenario): Outcome[] {
|
||||
const { routes, idOf } = buildRoutes(scenario.declarations);
|
||||
const id = (def: unknown): string => idOf.get(def) ?? '<unknown declaration>';
|
||||
|
||||
return scenario.requests.map(({ method, raw }): Outcome => {
|
||||
let normalized: string;
|
||||
|
||||
try {
|
||||
normalized = impl.normalizeRequestPath(raw);
|
||||
} catch (error) {
|
||||
return { method, raw, error: errorOutcome(error) };
|
||||
}
|
||||
|
||||
const match = impl.matchRoute(routes, method, normalized);
|
||||
const resolved = impl.resolveRoute(routes, method, normalized);
|
||||
|
||||
return {
|
||||
method,
|
||||
raw,
|
||||
normalized,
|
||||
match: match ? { id: id(match.def), params: match.params } : null,
|
||||
resolve: resolved ? { id: id(resolved.def), params: resolved.params, implicitHead: resolved.implicitHead } : null,
|
||||
allow: impl.allowedMethods(routes, normalized),
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,472 @@
|
||||
/**
|
||||
* FROZEN ORACLE — the pre-radix HTTP and WebSocket matcher, copied verbatim from `@green-tea/core`
|
||||
* at ed47836c9820c47bf4ed5e902d91e019abdb110a (`src/http/router.ts`, minus `parseQuery`, plus
|
||||
* `matchWsRoute` from `src/http/ws-core.ts`).
|
||||
*
|
||||
* DO NOT EDIT THIS FILE TO FIT A NEW IMPLEMENTATION. It is the reference the radix index (CARD-07,
|
||||
* #109) is judged against: if the live matcher disagrees with it, the live matcher is what changed.
|
||||
* A deliberate compatibility change needs its own maintainer approval and a new pinned oracle,
|
||||
* never an edit here. Test-only: nothing under `src/` may import it.
|
||||
*
|
||||
* The only departures from the source are mechanical: the route types are declared locally (so a
|
||||
* later change to `src/http/types.ts` cannot alter what this file compiles to), and the module-level
|
||||
* caches are this file's own, so the oracle never shares compiled state with the live matcher.
|
||||
*/
|
||||
|
||||
/** The fields of `RouteDef` the matcher reads. A live `RouteDef` is assignable to it. */
|
||||
export interface OracleRoute {
|
||||
method: string;
|
||||
pattern: string;
|
||||
transport: string;
|
||||
}
|
||||
|
||||
/** The fields of `WsRouteDef` the WS matcher reads. */
|
||||
export interface OracleWsRoute {
|
||||
pattern: string;
|
||||
}
|
||||
|
||||
export interface MatchedRoute {
|
||||
params: Record<string, string>;
|
||||
def: OracleRoute;
|
||||
}
|
||||
|
||||
export type CompiledSegment =
|
||||
| { kind: 'static'; value: string }
|
||||
| { kind: 'param'; name: string; constraint?: RegExp; constraintSource?: string }
|
||||
| { kind: 'catchAll'; name: string };
|
||||
|
||||
/** Parsed route pattern reused by matching, specificity, ambiguity checks, and OpenAPI projection. */
|
||||
export interface CompiledPattern {
|
||||
source: string;
|
||||
normalized: string;
|
||||
shape: string;
|
||||
segments: CompiledSegment[];
|
||||
kinds: number[];
|
||||
catchAll: boolean;
|
||||
}
|
||||
|
||||
const compiledCache = new Map<string, CompiledPattern>();
|
||||
const PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
||||
const MAX_CONSTRAINT_LENGTH = 128;
|
||||
|
||||
/** Request-path syntax error. Adapters translate this to the standard 400 response envelope. */
|
||||
export class InvalidRequestPathError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
this.name = 'InvalidRequestPathError';
|
||||
}
|
||||
}
|
||||
|
||||
interface ConstraintToken {
|
||||
length: number;
|
||||
unbounded: boolean;
|
||||
separator: boolean;
|
||||
}
|
||||
|
||||
/** Reads one atom plus its optional quantifier from the deliberately small safe-regex subset. */
|
||||
function readConstraintToken(source: string): ConstraintToken | undefined {
|
||||
const atom = /^(?:\\[dDsSwW]|\\[.\-_/]|[A-Za-z0-9_.-]|\[(?:\\.|[^\]\\])+\])/u.exec(source)?.[0];
|
||||
if (!atom) return undefined;
|
||||
|
||||
const rest = source.slice(atom.length);
|
||||
const quantifier = /^(?:[+*?]|\{\d+(?:,\d*)?\})/u.exec(rest)?.[0] ?? '';
|
||||
if (quantifier.startsWith('{')) assertBoundedQuantifier(quantifier);
|
||||
|
||||
return {
|
||||
length: atom.length + quantifier.length,
|
||||
unbounded: quantifier === '+' || quantifier === '*' || quantifier.endsWith(',}'),
|
||||
separator: quantifier === '' && /^(?:\\[.\-_/]|[._-])$/u.test(atom),
|
||||
};
|
||||
}
|
||||
|
||||
/** Rejects nonsensical or excessively large counted quantifiers before RegExp compilation. */
|
||||
function assertBoundedQuantifier(quantifier: string): void {
|
||||
const [minText, maxText] = quantifier.slice(1, -1).split(',');
|
||||
const min = Number(minText);
|
||||
const max = maxText === undefined || maxText === '' ? min : Number(maxText);
|
||||
if (min > max || max > 2048) throw new Error(`unsafe route constraint: invalid quantifier '${quantifier}'`);
|
||||
}
|
||||
|
||||
/** Accepts only a linear, group-free regex subset to keep attacker-controlled segments ReDoS-safe. */
|
||||
function assertSafeConstraint(source: string): void {
|
||||
if (!source || source.length > MAX_CONSTRAINT_LENGTH)
|
||||
throw new Error('unsafe route constraint: expression must contain 1-128 characters');
|
||||
|
||||
let offset = 0;
|
||||
let previousUnbounded = false;
|
||||
|
||||
while (offset < source.length) {
|
||||
const token = readConstraintToken(source.slice(offset));
|
||||
if (!token) throw new Error(`unsafe route constraint: unsupported expression '${source}'`);
|
||||
if (previousUnbounded && token.unbounded)
|
||||
throw new Error(`unsafe route constraint: adjacent unbounded quantifiers in '${source}'`);
|
||||
previousUnbounded = token.separator ? false : token.unbounded;
|
||||
offset += token.length;
|
||||
}
|
||||
}
|
||||
|
||||
function assertParamName(name: string, pattern: string): void {
|
||||
if (!PARAM_NAME.test(name)) throw new Error(`invalid route pattern '${pattern}': invalid parameter name '${name}'`);
|
||||
}
|
||||
|
||||
function compileParam(segment: string, pattern: string): Extract<CompiledSegment, { kind: 'param' }> {
|
||||
const constraintStart = segment.indexOf('(');
|
||||
|
||||
if (constraintStart < 0) {
|
||||
const name = segment.slice(1);
|
||||
assertParamName(name, pattern);
|
||||
return { kind: 'param', name };
|
||||
}
|
||||
|
||||
if (!segment.endsWith(')')) throw new Error(`invalid route pattern '${pattern}': malformed constraint`);
|
||||
const name = segment.slice(1, constraintStart);
|
||||
const constraintSource = segment.slice(constraintStart + 1, -1);
|
||||
assertParamName(name, pattern);
|
||||
assertSafeConstraint(constraintSource);
|
||||
return {
|
||||
kind: 'param',
|
||||
name,
|
||||
constraintSource,
|
||||
constraint: new RegExp(`^(?:${constraintSource})$`, 'u'),
|
||||
};
|
||||
}
|
||||
|
||||
function compileSegments(pattern: string, rawSegments: string[]): CompiledSegment[] {
|
||||
const names = new Set<string>();
|
||||
const compiled: CompiledSegment[] = [];
|
||||
|
||||
for (let index = 0; index < rawSegments.length; index++) {
|
||||
const raw = rawSegments[index];
|
||||
let segment: CompiledSegment;
|
||||
|
||||
if (raw.startsWith(':') && raw.endsWith('*')) {
|
||||
const name = raw.slice(1, -1);
|
||||
assertParamName(name, pattern);
|
||||
if (index !== rawSegments.length - 1)
|
||||
throw new Error(`invalid route pattern '${pattern}': catch-all must be the final segment`);
|
||||
segment = { kind: 'catchAll', name };
|
||||
} else if (raw.startsWith(':')) {
|
||||
segment = compileParam(raw, pattern);
|
||||
} else {
|
||||
segment = { kind: 'static', value: raw };
|
||||
}
|
||||
|
||||
if (segment.kind !== 'static') {
|
||||
if (names.has(segment.name))
|
||||
throw new Error(`invalid route pattern '${pattern}': duplicate parameter '${segment.name}'`);
|
||||
names.add(segment.name);
|
||||
}
|
||||
|
||||
compiled.push(segment);
|
||||
}
|
||||
|
||||
return compiled;
|
||||
}
|
||||
|
||||
function segmentShape(segment: CompiledSegment): string {
|
||||
if (segment.kind === 'static') return `s:${segment.value}`;
|
||||
if (segment.kind === 'catchAll') return 'c';
|
||||
return segment.constraintSource ? `r:${segment.constraintSource}` : 'p';
|
||||
}
|
||||
|
||||
/** Compiles and validates one route pattern. Results are cached by source string. */
|
||||
export function compilePattern(pattern: string): CompiledPattern {
|
||||
const cached = compiledCache.get(pattern);
|
||||
if (cached) return cached;
|
||||
if (!pattern.startsWith('/')) throw new Error(`invalid route pattern '${pattern}': pattern must start with '/'`);
|
||||
if (pattern.includes('//')) throw new Error(`invalid route pattern '${pattern}': repeated slash`);
|
||||
|
||||
const normalized = pattern.length > 1 && pattern.endsWith('/') ? pattern.slice(0, -1) : pattern;
|
||||
const rawSegments = normalized === '/' ? [] : normalized.split('/').slice(1);
|
||||
const segments = compileSegments(pattern, rawSegments);
|
||||
const compiled: CompiledPattern = {
|
||||
source: pattern,
|
||||
normalized,
|
||||
shape: segments.map(segmentShape).join('/'),
|
||||
segments,
|
||||
kinds: segments
|
||||
.filter((segment) => segment.kind !== 'catchAll')
|
||||
.map((segment) => (segment.kind === 'static' ? 3 : segment.constraint ? 2 : 1)),
|
||||
catchAll: segments.at(-1)?.kind === 'catchAll',
|
||||
};
|
||||
compiledCache.set(pattern, compiled);
|
||||
return compiled;
|
||||
}
|
||||
|
||||
/** Matches a `.` or `..` segment, percent-encoded or not, sitting alone between separators. */
|
||||
const DOT_SEGMENT = /(?:^|\/)(?:\.|%2e){1,2}(?:\/|$)/i;
|
||||
|
||||
/**
|
||||
* Classifies one path segment as `.`, `..`, or neither.
|
||||
*
|
||||
* `%2e` is a dot as far as the URL spec is concerned, so `/a/%2e%2e/b` and `/a/../b` are the same
|
||||
* path. Skipping the encoded spelling would leave the encoded form as a way to reach a route the
|
||||
* plain form resolves away from.
|
||||
*/
|
||||
function dotSegment(segment: string): '.' | '..' | undefined {
|
||||
if (segment === '.' || segment === '..') return segment;
|
||||
if (segment.length > 6 || !segment.includes('%')) return undefined;
|
||||
const decoded = segment.toLowerCase().replace(/%2e/g, '.');
|
||||
return decoded === '.' || decoded === '..' ? decoded : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves `.` and `..` segments, the way RFC 3986 §5.2.4 and the WHATWG URL parser both do.
|
||||
*
|
||||
* This runs for the *Node* adapter's benefit. Every fetch-based runtime — Deno, Bun, workerd —
|
||||
* resolves dot segments inside the `Request` constructor, before green-tea is handed anything:
|
||||
* `new Request('http://x/public/../admin').url` is already `http://x/admin`. The raw target is
|
||||
* simply not recoverable there, so rejecting dot segments outright — which is what this module
|
||||
* does for `//`, and would be the stricter policy — cannot be implemented on three of the four
|
||||
* runtimes. Resolving is the only rule all four can agree on.
|
||||
*
|
||||
* Before this, the same bytes on the wire routed differently per runtime: `GET /public/../admin`
|
||||
* reached a `/admin` route under Deno/Bun/edge and 404'd under Node.
|
||||
*/
|
||||
function resolveDotSegments(path: string): string {
|
||||
const out: string[] = [];
|
||||
|
||||
for (const segment of path.split('/').slice(1)) {
|
||||
const dots = dotSegment(segment);
|
||||
if (dots === '.') continue;
|
||||
|
||||
if (dots === '..') {
|
||||
out.pop();
|
||||
continue;
|
||||
}
|
||||
|
||||
out.push(segment);
|
||||
}
|
||||
|
||||
return `/${out.join('/')}`;
|
||||
}
|
||||
|
||||
/** Applies the public trailing-slash policy and validates every segment's percent encoding. */
|
||||
export function normalizeRequestPath(path: string): string {
|
||||
if (!path.startsWith('/')) throw new InvalidRequestPathError('invalid request path: path must start with slash');
|
||||
if (path.includes('//')) throw new InvalidRequestPathError('invalid request path: repeated slash');
|
||||
|
||||
// Two `indexOf` scans gate the regex, and the regex gates the split. A path with no `.` and no
|
||||
// `%` at all — which is most of them — pays only the scans.
|
||||
const resolved =
|
||||
(path.includes('.') || path.includes('%')) && DOT_SEGMENT.test(path) ? resolveDotSegments(path) : path;
|
||||
const normalized = resolved.length > 1 && resolved.endsWith('/') ? resolved.slice(0, -1) : resolved;
|
||||
|
||||
// Validation only — the decoded value is deliberately discarded, matching is done on the raw
|
||||
// path. So the work is skipped entirely unless there is something to validate.
|
||||
//
|
||||
// This used to split the path and call `decodeURIComponent` per segment, on every request, and
|
||||
// throw all of it away. Measured on this path: 95.8 ns for `/hello`, 342.7 ns for a six-segment
|
||||
// route — around 8% of a whole request, spent proving that a string nobody decodes could be
|
||||
// decoded. The guard below is 15.7 ns and 6.7 ns for the same two paths.
|
||||
//
|
||||
// One call on the whole string rather than per segment is the same check: `decodeURIComponent`
|
||||
// throws on the first malformed `%` sequence wherever it appears, and a `%2F` inside a segment
|
||||
// decodes fine either way. Only the throw matters here, never the result.
|
||||
if (normalized.includes('%')) {
|
||||
try {
|
||||
decodeURIComponent(normalized);
|
||||
} catch {
|
||||
throw new InvalidRequestPathError('invalid request path: malformed path encoding');
|
||||
}
|
||||
}
|
||||
|
||||
return normalized;
|
||||
}
|
||||
|
||||
function decodeSegment(value: string): string {
|
||||
// Same gate `normalizeRequestPath` uses on the whole path, for the same reason: a segment with no
|
||||
// `%` decodes to itself, so the call only ever proves that. Most segments have no `%`, and this
|
||||
// runs for every param segment of every candidate route the scan reaches.
|
||||
return value.includes('%') ? decodeURIComponent(value) : value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a request path into its non-empty segments.
|
||||
*
|
||||
* Called once per request by the scanning functions below, not once per candidate route. It used to
|
||||
* live inside {@link matchCompiled}, which meant `split` + `filter` — two allocations — ran for every
|
||||
* registered route on every request, always producing the same array.
|
||||
*/
|
||||
function splitPath(path: string): string[] {
|
||||
return path.split('/').filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Matches one compiled pattern against a request's segments.
|
||||
*
|
||||
* `decoded` memoizes per request, not per candidate: a scan reaching the same parameter position on
|
||||
* several routes decoded the same string once per route. Position is all decoding depends on, so one
|
||||
* array shared across the scan is the same answer for less work.
|
||||
*/
|
||||
function matchCompiled(
|
||||
compiled: CompiledPattern,
|
||||
pathSegs: string[],
|
||||
decoded?: Array<string | undefined>,
|
||||
): Record<string, string> | undefined {
|
||||
const params: Record<string, string> = {};
|
||||
|
||||
for (let index = 0; index < compiled.segments.length; index++) {
|
||||
const segment = compiled.segments[index];
|
||||
|
||||
if (segment.kind === 'catchAll') {
|
||||
params[segment.name] = pathSegs.slice(index).map(decodeSegment).join('/');
|
||||
return params;
|
||||
}
|
||||
|
||||
if (index >= pathSegs.length) return undefined;
|
||||
|
||||
if (segment.kind === 'static') {
|
||||
if (segment.value !== pathSegs[index]) return undefined;
|
||||
continue;
|
||||
}
|
||||
|
||||
const value = decoded ? (decoded[index] ??= decodeSegment(pathSegs[index])) : decodeSegment(pathSegs[index]);
|
||||
if (segment.constraint && !segment.constraint.test(value)) return undefined;
|
||||
params[segment.name] = value;
|
||||
}
|
||||
|
||||
return compiled.segments.length === pathSegs.length ? params : undefined;
|
||||
}
|
||||
|
||||
/** Matches a compiled segment pattern and returns its decoded parameters. */
|
||||
export function matchPattern(pattern: string, path: string): Record<string, string> | undefined {
|
||||
return matchCompiled(compilePattern(pattern), splitPath(path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Orders patterns by exactness, then static/constrained/plain segment specificity.
|
||||
*
|
||||
* Takes compiled patterns rather than their source strings: it used to re-derive both through
|
||||
* `compilePattern`, which is a `Map` lookup each, on every comparison of every request.
|
||||
*/
|
||||
function moreSpecific(a: CompiledPattern, b: CompiledPattern): number {
|
||||
const scoreA = a;
|
||||
const scoreB = b;
|
||||
if (scoreA.catchAll !== scoreB.catchAll) return scoreA.catchAll ? -1 : 1;
|
||||
const length = Math.max(scoreA.kinds.length, scoreB.kinds.length);
|
||||
|
||||
for (let index = 0; index < length; index++) {
|
||||
const kindA = scoreA.kinds[index] ?? -1;
|
||||
const kindB = scoreB.kinds[index] ?? -1;
|
||||
if (kindA !== kindB) return kindA - kindB;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** One route with its pattern already compiled. Built once per table, ordered within its method. */
|
||||
interface IndexedRoute {
|
||||
def: OracleRoute;
|
||||
compiled: CompiledPattern;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compiled, method-bucketed, specificity-ordered route tables, keyed by the identity of the array
|
||||
* they were built from.
|
||||
*
|
||||
* A server hands the same array to every request, so this is built once and collected with the
|
||||
* table it describes. A table assembled fresh — mesh splicing a teapot's exports in at boot — is a
|
||||
* different array and gets its own index, so nothing has to remember to invalidate anything.
|
||||
*/
|
||||
const routeIndexCache = new WeakMap<OracleRoute[], Map<string, IndexedRoute[]>>();
|
||||
|
||||
function routeIndex(routes: OracleRoute[]): Map<string, IndexedRoute[]> {
|
||||
const cached = routeIndexCache.get(routes);
|
||||
if (cached) return cached;
|
||||
|
||||
const byMethod = new Map<string, IndexedRoute[]>();
|
||||
|
||||
for (const def of routes) {
|
||||
const entry: IndexedRoute = { def, compiled: compilePattern(def.pattern) };
|
||||
const bucket = byMethod.get(def.method);
|
||||
if (bucket) bucket.push(entry);
|
||||
else byMethod.set(def.method, [entry]);
|
||||
}
|
||||
|
||||
// Most specific first, so the first match *is* the answer. `sort` is stable, so equal patterns
|
||||
// keep registration order — which is exactly what the old scan did by refusing to replace its
|
||||
// best on a tie.
|
||||
for (const bucket of byMethod.values()) bucket.sort((a, b) => moreSpecific(b.compiled, a.compiled));
|
||||
|
||||
routeIndexCache.set(routes, byMethod);
|
||||
return byMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the most specific route matching both method and path; ties keep registration order.
|
||||
*
|
||||
* The ranking is settled when the table is built, not per request: the answer cannot change between
|
||||
* requests, and re-deriving it charged every request for a scan to the end plus a `moreSpecific`
|
||||
* call — two `compilePattern` lookups each — per candidate. Both scaled with the size of the route
|
||||
* table. What is left here is a walk that stops at the first match.
|
||||
*/
|
||||
export function matchRoute(routes: OracleRoute[], method: string, path: string): MatchedRoute | undefined {
|
||||
const candidates = routeIndex(routes).get(method);
|
||||
if (!candidates) return undefined;
|
||||
|
||||
const pathSegs = splitPath(path);
|
||||
const decoded: Array<string | undefined> = new Array(pathSegs.length);
|
||||
|
||||
for (const { def, compiled } of candidates) {
|
||||
const params = matchCompiled(compiled, pathSegs, decoded);
|
||||
if (params) return { params, def };
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Route resolution adds the one HTTP fallback the matcher supports: buffered GET serves HEAD. */
|
||||
export interface ResolvedRoute extends MatchedRoute {
|
||||
implicitHead: boolean;
|
||||
}
|
||||
|
||||
export function resolveRoute(routes: OracleRoute[], method: string, path: string): ResolvedRoute | undefined {
|
||||
const explicit = matchRoute(routes, method, path);
|
||||
if (explicit) return { ...explicit, implicitHead: false };
|
||||
if (method !== 'HEAD') return undefined;
|
||||
|
||||
const fallback = matchRoute(
|
||||
routes.filter((route) => route.transport === 'buffer'),
|
||||
'GET',
|
||||
path,
|
||||
);
|
||||
return fallback ? { ...fallback, implicitHead: true } : undefined;
|
||||
}
|
||||
|
||||
const METHOD_ORDER = ['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'];
|
||||
|
||||
/** Lists the distinct HTTP methods whose pattern matches the path — used to build a 405 `Allow` header. */
|
||||
export function allowedMethods(routes: OracleRoute[], path: string): string[] {
|
||||
const pathSegs = splitPath(path);
|
||||
const methods = new Set<string>();
|
||||
|
||||
for (const route of routes) {
|
||||
if (!matchCompiled(compilePattern(route.pattern), pathSegs)) continue;
|
||||
methods.add(route.method);
|
||||
if (route.method === 'GET' && route.transport === 'buffer') methods.add('HEAD');
|
||||
}
|
||||
|
||||
if (methods.size) methods.add('OPTIONS');
|
||||
return [...methods].sort((a, b) => {
|
||||
const indexA = METHOD_ORDER.indexOf(a);
|
||||
const indexB = METHOD_ORDER.indexOf(b);
|
||||
return (
|
||||
(indexA < 0 ? METHOD_ORDER.length : indexA) - (indexB < 0 ? METHOD_ORDER.length : indexB) || a.localeCompare(b)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects the first registered WS declaration whose pattern matches — no specificity ranking.
|
||||
* Copied from `src/http/ws-core.ts`; both adapters hand it a path already through
|
||||
* `normalizeRequestPath` (Node `routeUpgrade`, and `buildAppUpgrade` for app.upgrade).
|
||||
*/
|
||||
export function matchWsRoute<W extends OracleWsRoute>(
|
||||
wsRoutes: W[],
|
||||
path: string,
|
||||
): { def: W; params: Record<string, string> | undefined } | undefined {
|
||||
return wsRoutes
|
||||
.map((candidate) => ({ def: candidate, params: matchPattern(candidate.pattern, path) }))
|
||||
.find((entry) => entry.params);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/**
|
||||
* Owner-requested additions (CARD-08 review) that need a running app: cross-pattern `Allow` through
|
||||
* both adapters, and the HTTP route table across a mesh peer's lifetime.
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import http from 'http';
|
||||
import net from 'net';
|
||||
import type { AddressInfo } from 'net';
|
||||
import { describe, it, afterAll, beforeAll } from 'vitest';
|
||||
import { createApp, Route, Get, Post, Delete, Module, param } from '../../src/index';
|
||||
import type { App } from '../../src/app/types';
|
||||
import type { Logger } from '../../src/logger';
|
||||
import { frozen, expectFrozenEqual } from './frozen';
|
||||
|
||||
// `/ca` is GET :id + POST b; `/cb` adds DELETE :rest*. Two prefixes because one app cannot hold both
|
||||
// variants at the same path.
|
||||
@Route('/')
|
||||
class CrossAllow {
|
||||
@Get('/ca/:id') caGet(@param() p: Record<string, string>) {
|
||||
return { id: 'caGet', p };
|
||||
}
|
||||
@Post('/ca/b') caPost() {
|
||||
return { id: 'caPost' };
|
||||
}
|
||||
@Get('/cb/:id') cbGet(@param() p: Record<string, string>) {
|
||||
return { id: 'cbGet', p };
|
||||
}
|
||||
@Post('/cb/b') cbPost() {
|
||||
return { id: 'cbPost' };
|
||||
}
|
||||
@Delete('/cb/:rest*') cbDelete(@param() p: Record<string, string>) {
|
||||
return { id: 'cbDelete', p };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/', controllers: [CrossAllow] })
|
||||
class CrossAllowModule {}
|
||||
|
||||
const ALLOW_REQUESTS: Array<[string, string]> = ['/ca', '/cb'].flatMap((base): Array<[string, string]> => [
|
||||
['PUT', `${base}/b`],
|
||||
['OPTIONS', `${base}/b`],
|
||||
['PUT', `${base}/x`],
|
||||
['HEAD', `${base}/b`],
|
||||
['PUT', `${base}/x/y`],
|
||||
]);
|
||||
|
||||
interface Seen {
|
||||
method: string;
|
||||
path: string;
|
||||
status: number;
|
||||
allow: string | null;
|
||||
body: string;
|
||||
}
|
||||
|
||||
function nodeRequest(port: number, method: string, path: string): Promise<Seen> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const req = http.request({ host: '127.0.0.1', port, method, path, agent: false }, (res) => {
|
||||
let body = '';
|
||||
res.setEncoding('utf8');
|
||||
res.on('data', (chunk) => (body += chunk));
|
||||
res.on('end', () =>
|
||||
resolve({ method, path, status: res.statusCode ?? 0, allow: (res.headers.allow as string) ?? null, body }),
|
||||
);
|
||||
});
|
||||
req.on('error', reject);
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchRequest(app: App, method: string, path: string): Promise<Seen> {
|
||||
const res = await app.fetch(new Request(`http://parity.test${path}`, { method }));
|
||||
return { method, path, status: res.status, allow: res.headers.get('allow'), body: await res.text() };
|
||||
}
|
||||
|
||||
// ── mesh: the HTTP route table across a peer's lifetime ─────────────────────────────────────────
|
||||
|
||||
const SECRET = 'parity-secret';
|
||||
|
||||
@Route('/remote')
|
||||
class RemoteCtl {
|
||||
@Get('/ping', { export: true }) ping() {
|
||||
return { from: 'teapot' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [RemoteCtl] })
|
||||
class TeapotModule {}
|
||||
|
||||
@Route('/local')
|
||||
class LocalCtl {
|
||||
@Get('/ok') ok() {
|
||||
return { from: 'teacup' };
|
||||
}
|
||||
}
|
||||
@Module({ mountpoint: '/api', controllers: [LocalCtl] })
|
||||
class TeacupModule {}
|
||||
|
||||
const quiet: Logger = { debug: () => {}, info: () => {}, warn: () => {}, error: () => {} };
|
||||
|
||||
/** A port nothing is listening on, that a teapot can take later. */
|
||||
async function freePort(): Promise<number> {
|
||||
const server = net.createServer();
|
||||
await new Promise<void>((resolve) => server.listen(0, '127.0.0.1', resolve));
|
||||
const { port } = server.address() as AddressInfo;
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
return port;
|
||||
}
|
||||
|
||||
// Same probes at every phase: the remote hit, its method miss, a local hit and a path miss.
|
||||
const PROBES: Array<[string, string]> = [
|
||||
['GET', '/api/remote/ping'],
|
||||
['POST', '/api/remote/ping'],
|
||||
['GET', '/api/local/ok'],
|
||||
['GET', '/api/nope'],
|
||||
];
|
||||
|
||||
async function probe(app: App, phase: string) {
|
||||
const out = [];
|
||||
for (const [method, path] of PROBES) {
|
||||
const { status, allow, body } = await fetchRequest(app, method, path);
|
||||
// The teapot's ephemeral port appears in the 503 body; the port is not routing behaviour.
|
||||
out.push({ phase, method, path, status, allow, body: body.replace(/ws:\/\/127\.0\.0\.1:\d+/g, '<teapot>') });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
const teacupFor = (port: number) =>
|
||||
createApp({
|
||||
modules: [TeacupModule],
|
||||
experimental: true,
|
||||
logger: quiet,
|
||||
mesh: {
|
||||
teapots: [{ url: `ws://127.0.0.1:${port}/__mesh__/control`, secret: SECRET }],
|
||||
bootTimeoutMs: 300,
|
||||
timeoutMs: 500,
|
||||
reconnect: false,
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Two lifetimes. A: the teapot is up at boot, then goes away. B: the teapot is absent at boot and
|
||||
* comes up afterwards. The current code builds the HTTP table once, at boot, and never changes it:
|
||||
* routes spliced at boot stay in the table after their peer leaves, and a peer that arrives late
|
||||
* is never spliced in. CARD-10 can reuse this to assert the index is not rebuilt per request.
|
||||
*/
|
||||
async function meshLifetimes() {
|
||||
const results = [];
|
||||
|
||||
const portA = await freePort();
|
||||
const teapotA = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
|
||||
await teapotA.listen(portA);
|
||||
const teacupA = teacupFor(portA);
|
||||
try {
|
||||
results.push(...(await probe(teacupA, 'A1 teapot up at boot')));
|
||||
await teapotA.close();
|
||||
results.push(...(await probe(teacupA, 'A2 teapot gone after boot')));
|
||||
} finally {
|
||||
await teacupA.close();
|
||||
}
|
||||
|
||||
const portB = await freePort();
|
||||
const teacupB = teacupFor(portB);
|
||||
const teapotB = createApp({ modules: [TeapotModule], experimental: true, mesh: { secret: SECRET } });
|
||||
try {
|
||||
results.push(...(await probe(teacupB, 'B1 teapot absent at boot')));
|
||||
await teapotB.listen(portB);
|
||||
results.push(...(await probe(teacupB, 'B2 teapot up after boot')));
|
||||
} finally {
|
||||
await teacupB.close();
|
||||
await teapotB.close();
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
describe('router parity: owner-requested application cases', () => {
|
||||
let fetchApp: App;
|
||||
let nodeApp: App;
|
||||
let port: number;
|
||||
|
||||
beforeAll(async () => {
|
||||
fetchApp = createApp({ modules: [CrossAllowModule] });
|
||||
nodeApp = createApp({ modules: [CrossAllowModule] });
|
||||
port = ((await nodeApp.listen(0)).address() as AddressInfo).port;
|
||||
});
|
||||
|
||||
afterAll(() => nodeApp.close());
|
||||
|
||||
it('cross-pattern Allow through app.fetch and Node equals the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: Array<Seen & { adapter: string }> = [];
|
||||
for (const [method, path] of ALLOW_REQUESTS)
|
||||
out.push({ adapter: 'fetch', ...(await fetchRequest(fetchApp, method, path)) });
|
||||
for (const [method, path] of ALLOW_REQUESTS)
|
||||
out.push({ adapter: 'node', ...(await nodeRequest(port, method, path)) });
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('owner-app-allow', run);
|
||||
expectFrozenEqual(await run(), expected, 'cross-pattern Allow');
|
||||
});
|
||||
|
||||
it('the mesh HTTP route table across a peer lifetime equals the frozen capture', async () => {
|
||||
const expected = await frozen('owner-mesh-lifetime', meshLifetimes);
|
||||
expectFrozenEqual(await meshLifetimes(), expected, 'mesh lifetime');
|
||||
}, 30_000);
|
||||
});
|
||||
@@ -0,0 +1,183 @@
|
||||
/**
|
||||
* WebSocket upgrade parity, kept apart from HTTP on purpose: WS selection is first-registered-wins
|
||||
* with no specificity ranking, an HTTP route at the same path never takes the upgrade, and the mesh
|
||||
* control path is checked before WS route matching. Captured through both upgrade entry points —
|
||||
* `app.upgrade` (Deno/Bun/edge) and the Node `server.on('upgrade')` listener — because they are
|
||||
* separate code paths and do not agree on everything (see the reserved-path rows in the fixture).
|
||||
*/
|
||||
import 'reflect-metadata';
|
||||
import type { AddressInfo } from 'net';
|
||||
import WebSocket from 'ws';
|
||||
import { describe, it, beforeAll, afterAll } from 'vitest';
|
||||
import { createApp, Route, Get, Post, Ws, Stream, Module, param } from '../../src/index';
|
||||
import { channel } from '../../src/channel';
|
||||
import type { App } from '../../src/app/types';
|
||||
import type { WsRequest, WsSocket } from '../../src/http/ws-core';
|
||||
import { frozen, expectFrozenEqual } from './frozen';
|
||||
|
||||
const announce = (id: string, params: Record<string, string>) =>
|
||||
(async function* () {
|
||||
yield { id, params };
|
||||
})();
|
||||
|
||||
@Route('/')
|
||||
class ParityWs {
|
||||
// Registered before the static twin: WS does not rank, so this one answers /live/lobby.
|
||||
@Ws('/live/:room') liveRoom(@param() p: Record<string, string>) {
|
||||
return announce('liveRoom', p);
|
||||
}
|
||||
@Ws('/live/lobby') liveLobby(@param() p: Record<string, string>) {
|
||||
return announce('liveLobby', p);
|
||||
}
|
||||
// Same path as the WS routes, different method, so the boot accepts it; it must not take upgrades.
|
||||
@Post('/live/lobby') httpLobby() {
|
||||
return { id: 'httpLobby' };
|
||||
}
|
||||
@Get('/plain') plain() {
|
||||
return { id: 'plain' };
|
||||
}
|
||||
// `negotiate` routes are registered for both HTTP and WS.
|
||||
@Stream('/feed') feed() {
|
||||
return announce('feed', {});
|
||||
}
|
||||
// A user route on the reserved mesh path, on an app with no mesh: the two adapters disagree here.
|
||||
@Ws('/__mesh__/control') reserved(@param() p: Record<string, string>) {
|
||||
return announce('reserved', p);
|
||||
}
|
||||
}
|
||||
|
||||
@Module({ mountpoint: '/', controllers: [ParityWs] })
|
||||
class ParityWsModule {}
|
||||
|
||||
// The `ws` client runs its URL through the URL parser, so on the Node rows dot segments are already
|
||||
// resolved before the server sees them; `app.upgrade` receives each path exactly as written here.
|
||||
const UPGRADE_PATHS = [
|
||||
'/live/lobby',
|
||||
'/live/kitchen',
|
||||
'/live/lobby/',
|
||||
'/live/x/../lobby',
|
||||
'/live/a%20b',
|
||||
'/live/lobby?x=1',
|
||||
'/live/%E0%A4%A',
|
||||
'/live//lobby',
|
||||
'/plain',
|
||||
'/nope',
|
||||
'/feed',
|
||||
'/__mesh__/control',
|
||||
];
|
||||
|
||||
const HTTP_REQUESTS: Array<[string, string]> = [
|
||||
['GET', '/live/lobby'],
|
||||
['POST', '/live/lobby'],
|
||||
['OPTIONS', '/live/lobby'],
|
||||
['GET', '/live/kitchen'],
|
||||
['GET', '/feed'],
|
||||
];
|
||||
|
||||
interface UpgradeOutcome {
|
||||
path: string;
|
||||
sent: unknown[];
|
||||
closes: Array<{ code?: number; reason?: string }>;
|
||||
}
|
||||
|
||||
async function viaAppUpgrade(app: App, path: string): Promise<UpgradeOutcome> {
|
||||
const inbound = channel<unknown>();
|
||||
const ac = new AbortController();
|
||||
const sent: unknown[] = [];
|
||||
const closes: Array<{ code?: number; reason?: string }> = [];
|
||||
let open = true;
|
||||
const socket: WsSocket = {
|
||||
inbound,
|
||||
abort: ac.signal,
|
||||
get isOpen() {
|
||||
return open;
|
||||
},
|
||||
send: (data) => sent.push(JSON.parse(data)),
|
||||
close: (code, reason) => {
|
||||
open = false;
|
||||
closes.push({ code, reason });
|
||||
ac.abort();
|
||||
},
|
||||
terminate: () => {
|
||||
open = false;
|
||||
ac.abort();
|
||||
},
|
||||
};
|
||||
const request: WsRequest = { url: path, headers: {}, protocol: 'http', ip: '127.0.0.1' };
|
||||
await app.upgrade(request, socket);
|
||||
return { path, sent, closes };
|
||||
}
|
||||
|
||||
interface NodeUpgradeOutcome {
|
||||
path: string;
|
||||
status?: number;
|
||||
sent: unknown[];
|
||||
close?: { code: number; reason: string };
|
||||
}
|
||||
|
||||
function viaNodeUpgrade(port: number, path: string): Promise<NodeUpgradeOutcome> {
|
||||
return new Promise((resolve) => {
|
||||
const sent: unknown[] = [];
|
||||
const client = new WebSocket(`ws://127.0.0.1:${port}${path}`);
|
||||
client.on('unexpected-response', (_req, res) => {
|
||||
resolve({ path, status: res.statusCode, sent });
|
||||
res.resume();
|
||||
client.terminate();
|
||||
});
|
||||
client.on('message', (data) => sent.push(JSON.parse(String(data))));
|
||||
client.on('close', (code, reason) => resolve({ path, status: 101, sent, close: { code, reason: String(reason) } }));
|
||||
client.on('error', () => {
|
||||
/* reported through unexpected-response or close */
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe('router parity: WebSocket upgrade outcomes', () => {
|
||||
let app: App;
|
||||
let nodeApp: App;
|
||||
let port: number;
|
||||
|
||||
beforeAll(async () => {
|
||||
app = createApp({ modules: [ParityWsModule] });
|
||||
nodeApp = createApp({ modules: [ParityWsModule] });
|
||||
const server = await nodeApp.listen(0);
|
||||
port = (server.address() as AddressInfo).port;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await nodeApp.close();
|
||||
});
|
||||
|
||||
it('app.upgrade outcomes equal the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: UpgradeOutcome[] = [];
|
||||
for (const path of UPGRADE_PATHS) out.push(await viaAppUpgrade(app, path));
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('ws-app-upgrade', run);
|
||||
expectFrozenEqual(await run(), expected, 'app.upgrade');
|
||||
});
|
||||
|
||||
it('Node upgrade listener outcomes equal the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: NodeUpgradeOutcome[] = [];
|
||||
for (const path of UPGRADE_PATHS) out.push(await viaNodeUpgrade(port, path));
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('ws-node-upgrade', run);
|
||||
expectFrozenEqual(await run(), expected, 'node upgrade');
|
||||
});
|
||||
|
||||
it('plain HTTP requests at the WS paths equal the frozen capture', async () => {
|
||||
const run = async () => {
|
||||
const out: Array<{ method: string; path: string; status: number; allow: string | null; body: string }> = [];
|
||||
for (const [method, path] of HTTP_REQUESTS) {
|
||||
const res = await app.fetch(new Request(`http://parity.test${path}`, { method }));
|
||||
out.push({ method, path, status: res.status, allow: res.headers.get('allow'), body: await res.text() });
|
||||
}
|
||||
return out;
|
||||
};
|
||||
const expected = await frozen('ws-http-same-path', run);
|
||||
expectFrozenEqual(await run(), expected, 'http at ws paths');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user