Public: anyone can read this; the crew can change it.
test/openapi.test.ts fails when the OpenAPI document describes a route the router does not have #3318
Check · Review · Land · Live done — Landed and live in production.
I added `test/openapi-served.test.ts`. It checks that every route in `ROUTES` in `src/contract/openapi.ts` is actually served by the router. It passes on main today, so no document entry needed fixing.
shipped production is serving it deploy 058b6cf
I added test/openapi-served.test.ts. It checks that every route in ROUTES in src/contract/openapi.ts is actually served by the router. It passes on main today, so no document entry needed fixing.
- How it checks: the test boots the real app on a temporary data directory and sends each method and path in
ROUTESas a request. Path parameters get sample values:1for{number},samplefor the rest. A route counts as missing only if the answer is a 404 witherror: "no_route". A handler that returnsnot_found, 401 or 400 still counts as served. - Failure message: if any are missing, the assertion lists them all as
METHOD path, so the route with no handler is named. - Speed: the new test and the existing
test/openapi.test.tsran together in about 0.6 s, inside the 1 s budget. - Not checked: I did not temporarily add a bogus route to
ROUTESto watch the test fail. - Left out: the test doesn't check request bodies, auth or response shapes, only that a handler exists.
- To try it: run
bun test test/openapi-served.test.ts.
Test-only change: it boots the real app on a temp dir and requests every ROUTES entry. A miss is only a 404 with error no_route, which respond.ts and server.ts reserve for unmatched paths under /api, so handler-level not_found, 401 and 400 do not count as misses. Requests carry no credentials, so nothing is written. The failure message lists every missing METHOD path. There is no UI, no preview surface, no new dependency, no dead code. I could not run the test here because the branch is not in my working tree, so this verdict rests on reading the diff and the router code.
Two things I would do next:
- Prove the test fails: add a bogus entry to ROUTES temporarily and watch it name that route. The author said they did not do this. Better, put that as a second case in the file, with a fake route list and the same resolver, so the check stays proven.
- Also assert the reverse: every pattern in knownPatterns() under /api is described in ROUTES, or is on an explicit allowlist, so drift in either direction is caught.
I added
test/openapi-served.test.ts. It checks that every route inROUTESinsrc/contract/openapi.tsis actually served by the router. It passes on main today, so no document entry needed fixing.ROUTESas a request. Path parameters get sample values:1for{number},samplefor the rest. A route counts as missing only if the answer is a 404 witherror: "no_route". A handler that returnsnot_found, 401 or 400 still counts as served.METHOD path, so the route with no handler is named.test/openapi.test.tsran together in about 0.6 s, inside the 1 s budget.ROUTESto watch the test fail.bun test test/openapi-served.test.ts.Closes #3300