Repository navigation
test(api): see every route verb and quote style, and count path declarations (#1293) - #1297
Merged
Merged
Conversation
added 2 commits
November 24, 2026 10:58
…rations (#1293) The contract check promised that an undocumented route fails, but its scan read single-quoted app.get only and counted path occurrences in an object literal, where a duplicate key has already collapsed. The reader is now the one the docs/api.md checker uses, both quote styles and every verb are read, coverage is per method, and declarations are counted in the contract's source text.
The suite keeps every assertion it had; flattening the served paths to METHOD /path makes those same assertions method-aware, so no assertion is removed to close the coverage gap.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Written-by: Fledge Platform Dev-3
Fixes #1293
The contract check promised "an undocumented route fails", but its scanner could not keep that promise. It read
app.get('…')with single quotes only, and it counted path occurrences in an object literal where a duplicate key has already collapsed. Both holes are closed here, and every existing assertion is kept.What changed (test-only,
test/plusdocs/api.md):test/openapi.test.tsnow reads routes throughtest/apiDocReader.ts, the readertest/apiDocRoutes.test.ts(docs(api): the endpoint table lists POST /settings/model, which the app does not serve #1289) already uses fordocs/api.md. One definition of "a route the app registers" — every registration verb, both quote styles — instead of a second scanner.pathsare flattened toMETHOD /pathentries, so the same assertion is now per method: a route registered asPOST /api/v1/xfails unless the contract describes that verb, and the reverse direction fails for a documented verb with no registration.src/api/openapi.ts's source text (pathDeclarationCount), becausepathsis an object literal: a duplicate key is gone before the served document could be counted. The counter has its own fixture test, so the assertion can actually fail.test/apiDocReader.tsis the reader extracted fromtest/apiDocRoutes.test.ts. The reader now reads both quote styles (it previously threw on a double-quoted registration), and a fixture test pins that.docs/api.mdsays what the check now reads.Red at the base
4e5ed78f182725e9790eff1b51156068aee763d2; every probe reverted before the commit:app.post('/api/v1/shadow-post', …)added tosrc/app.ts: base suite 6/6 green. At the tip it fails withPOST /api/v1/shadow-post is registered in src/app.ts but is not declared exactly once in the contract.app.get("/api/v1/shadow-quoted", …)(double quotes) added tosrc/app.ts: base suite 6/6 green. At the tip it fails withGET /api/v1/shadow-quoted is registered in src/app.ts but is not declared exactly once in the contract.'/api/v1/openapi.json': { … }block in thepathsliteral: base suite 6/6 green. At the tip it fails with/api/v1/openapi.json is declared 2 time(s) in src/api/openapi.ts; a duplicate key collapses before the served document can show it.Green at the tip:
npx tsx --test test/openapi.test.ts test/apiDocRoutes.test.ts— 12 tests, 12 pass, 0 fail.Alternatives considered:
test/openapi.test.ts: rejected, the reviewer asked for one reader and docs(api): name the route that saves a model, not the phantom /settings/model row (#1289) #1295 already built one.pathsfrom an array insrc/api/openapi.tsso duplicates cannot collapse at all: rejected for this card, because it moves the change intosrc/and makes it T2 with no gain for the contract's user-visible shape; the card allows the source-text mechanism.Uncertainty and residual risk:
pathDeclarationCountassumes a/api/v1/*string appears insrc/api/openapi.tsonly as apathskey. That is true today and the test runs over every served path, but a future description that quotes a path followed by a colon would over-count and fail loudly rather than pass silently.app.route({...})registrations by design (it cannot read the verb there); that behavior comes from docs(api): the endpoint table lists POST /settings/model, which the app does not serve #1289 and is unchanged.Ran:
npm run check— pass (lint, typecheck, full test suite, build)npx tsx --test test/openapi.test.ts test/apiDocRoutes.test.ts— pass, 12/12 at the tipnode scripts/risk-gate.mjs --base 4e5ed78f182725e9790eff1b51156068aee763d2— prints the tier belowNot run: the GitHub CI jobs on this branch, the coverage job, any deploy.
risk-tier: T1; basis: test/apiDocReader.ts
Docs:
docs/api.mdupdated in this PR. The served API is unchanged, so no changelog fragment.