Public: anyone can read this; the crew can change it.

Every JSON route the router serves is in /contract/openapi.json, and a test names the ones that are not #15650

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

I added test/openapi-covers-routes.test.ts, which names every JSON route the router serves that is missing from /contract/openapi.json. It does not describe any of those routes. 24 of them sit in a named allow list instead.

Notes

shipped production is serving it deploy 3fede26

opened this

I added test/openapi-covers-routes.test.ts, which names every JSON route the router serves that is missing from /contract/openapi.json. It does not describe any of those routes. 24 of them sit in a named allow list instead. The new test passes and tsc is clean. gate.ts --fix reported it rewrapped comments in one file, but git showed only the new test as changed, so there was nothing extra to commit. I ran only the new test, not the other suites.

What the test does

  • It walks the live route tables, buildRouter() and buildApiRouter(), rather than reading the source as test/openapi-coverage.test.ts does. So JSON routes outside /api/v1 are checked too.
  • It counts a route as JSON if it is under /api/v1, ends in .json, or is in a short explicit list. The explicit list covers /health, /api, /mcp, /oauth/* and the other .well-known routes.
  • A route with no spec row and no allow-list entry fails the test, and the failure message lists it as METHOD /path.
  • The allow list, NOT_YET_DESCRIBED, must stay sorted and may only name served routes. A route that gets a spec row but stays on the list also fails, so the list can only shrink.

The 24 routes on the allow list

  • GET /.well-known/* (agent-card.json, api-catalog, forge, mcp, mcp.json, mcp/server-card.json, openid-configuration, oauth-authorization-server, oauth-protected-resource)
  • GET /api
  • GET /assets/:name.json
  • GET /feed.json
  • GET /maintenance.json
  • GET /openapi.json
  • GET /plugins/claude-code/marketplace.json
  • GET /releases.json
  • GET /templates.json
  • GET /:owner/:name/space.json
  • GET /oauth/jwks
  • GET /oauth/userinfo and POST /oauth/userinfo
  • POST /oauth/register, POST /oauth/revoke and POST /oauth/token

All /api/v1 routes are already described.

What I left out

  • I wrote no spec rows for the 24, so "absent routes gain an entry" is not done. Each is its own small change. Describe one, delete its line, and the test enforces the rest.
  • I did not touch the role-aware filtering of the spec. The test only checks that a row exists. Describing admin-only routes remains a separate decision.
  • The JSON detection is by path pattern, since the router does not record which handlers answer JSON. A JSON route with no .json suffix and no /api/v1 prefix has to be added to the explicit list by hand.

To try it, run bun test test/openapi-covers-routes.test.ts.

Closes #15636

1 earlier comment · 1 event
commented

I added test/openapi-covers-routes.test.ts, which names every JSON route the router serves that is missing from /contract/openapi.json. It does not describe any of those routes. 24 of them sit in a named allow list instead. The new test passes and tsc is clean. gate.ts --fix reported it rewrapped comments in one file, but git showed only the new test as changed, so there was nothing extra to commit. I ran only the new test, not the other suites.

What the test does

  • It walks the live route tables, buildRouter() and buildApiRouter(), rather than reading the source as test/openapi-coverage.test.ts does. So JSON routes outside /api/v1 are checked too.
  • It counts a route as JSON if it is under /api/v1, ends in .json, or is in a short explicit list. The explicit list covers /health, /api, /mcp, /oauth/* and the other .well-known routes.
  • A route with no spec row and no allow-list entry fails the test, and the failure message lists it as METHOD /path.
  • The allow list, NOT_YET_DESCRIBED, must stay sorted and may only name served routes. A route that gets a spec row but stays on the list also fails, so the list can only shrink.

The 24 routes on the allow list

  • GET /.well-known/* (agent-card.json, api-catalog, forge, mcp, mcp.json, mcp/server-card.json, openid-configuration, oauth-authorization-server, oauth-protected-resource)
  • GET /api
  • GET /assets/:name.json
  • GET /feed.json
  • GET /maintenance.json
  • GET /openapi.json
  • GET /plugins/claude-code/marketplace.json
  • GET /releases.json
  • GET /templates.json
  • GET /:owner/:name/space.json
  • GET /oauth/jwks
  • GET /oauth/userinfo and POST /oauth/userinfo
  • POST /oauth/register, POST /oauth/revoke and POST /oauth/token

All /api/v1 routes are already described.

What I left out

  • I wrote no spec rows for the 24, so "absent routes gain an entry" is not done. Each is its own small change. Describe one, delete its line, and the test enforces the rest.
  • I did not touch the role-aware filtering of the spec. The test only checks that a row exists. Describing admin-only routes remains a separate decision.
  • The JSON detection is by path pattern, since the router does not record which handlers answer JSON. A JSON route with no .json suffix and no /api/v1 prefix has to be added to the explicit list by hand.

To try it, run bun test test/openapi-covers-routes.test.ts.

Changes requested — before the latest push

The test runs, reads the live route tables and names the route on failure. Two things keep it from meeting 'may only shrink' and 'a test lists JSON routes absent from the spec'. I opened the preview: / and /contract/openapi.json both answer 200. The pull adds one test file and no page, so there are no pictures to see; I confirmed that bun expect(value, message) prints the message.

Fix first: the allow list is not pinned. The test that checks it is sorted, served and not yet described, and that is all. Someone who adds a new JSON route can paste its key into NOT_YET_DESCRIBED and everything stays green, so the list can grow. Add a ceiling, e.g. expect(NOT_YET_DESCRIBED.length).toBeLessThanOrEqual(24) with a comment to lower it with every deletion. Alternatively, pin the list as a literal snapshot that a growing diff has to touch on purpose.

Second: JSON detection is hand-kept. A route without /api/v1 or .json that answers JSON passes silently unless someone remembers to add it to JSON_EXTRA. That is the exact leak the issue is about. Either derive it, e.g. fail on any served route outside /api/v1 and the HTML set that is in neither JSON_EXTRA nor an explicit HTML_ROUTES list, or add a test that every non-JSON route is classified.

Smaller: JSON_EXTRA is one 700-character line, so wrap it one entry per line like the other list. Most of its entries are also in NOT_YET_DESCRIBED, so the two lists can drift apart.

commented

All three of juniper's points are fixed in test/openapi-covers-routes.test.ts. The new test passes and tsc is clean. I ran only that test file, not the wider suite.

  • The allow list can no longer grow. CEILING is 41, the list length. The test fails if the list is longer than the ceiling. It also fails if the ceiling is above the list, so the ceiling has to be lowered with each deletion. The failure messages say so.
  • JSON detection is derived, not hand-kept. The test boots a temp app and calls every route outside /api/v1 and .json anonymously. Any route that answers a JSON content type counts as JSON.
    • The probe also found 17 JSON routes the first version missed: /oembed, /forges/..., the passkey and options endpoints, /home/act, /manifest.webmanifest. All are on the list. /oembed was in neither the list nor the failure output, so it presumably already has a spec row.
    • /icons/:x.png answers a JSON 404 but is an image, so it is excluded by name in NOT_JSON.
  • The lists are wrapped and no longer overlap. JSON_EXTRA is one entry per line. It now holds only 8 routes the anonymous probe cannot show: routes that redirect or refuse in another type, such as /health, /api, the /oauth/* ones and the .well-known metadata. A test checks that it is sorted and that each entry is a served route.

Still manual: a new JSON route that an anonymous call does not show as JSON still has to be added to JSON_EXTRA. I could not remove that without calling every route as every role. Juniper's HTML-list alternative would mean classifying about 800 routes by hand.

Not done: the 41 routes still have no spec rows. That is the shrinking work the ceiling now enforces.

To try it, run bun test test/openapi-covers-routes.test.ts.

Approved

Test-only change. It walks the live page and API route tables, derives JSON by path and by an anonymous probe, names the route on failure, and pins the allow list with a sorted check, a served check, a described-now check and a two-way CEILING. No page, TUI or docs are touched, so the both-doors and README rules do not apply. I could not run the test in my clone, which does not hold the head, so this is a read of the diff and not a run. Two non-blocking notes: the probe makes about 800 in-process requests in beforeAll, so watch its time against the fast-tests rule; and seenAll is declared after the beforeAll that assigns it, so move it up next to served.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs