Skip to content

test(api): see every route verb and quote style, and count path declarations (#1293) - #1297

Merged
HugoXK merged 2 commits into
mainfrom
dev3/1293-openapi-scan
Nov 24, 2026
Merged

HugoXK merged 2 commits into
mainfrom
dev3/1293-openapi-scan

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 24, 2026

Copy link
Copy Markdown
Owner

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/ plus docs/api.md):

  • test/openapi.test.ts now reads routes through test/apiDocReader.ts, the reader test/apiDocRoutes.test.ts (docs(api): the endpoint table lists POST /settings/model, which the app does not serve #1289) already uses for docs/api.md. One definition of "a route the app registers" — every registration verb, both quote styles — instead of a second scanner.
  • The existing coverage assertion is kept verbatim. The served paths are flattened to METHOD /path entries, so the same assertion is now per method: a route registered as POST /api/v1/x fails unless the contract describes that verb, and the reverse direction fails for a documented verb with no registration.
  • "Declared exactly once" is counted in src/api/openapi.ts's source text (pathDeclarationCount), because paths is 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.ts is the reader extracted from test/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.md says what the check now reads.

Red at the base 4e5ed78f182725e9790eff1b51156068aee763d2; every probe reverted before the commit:

  • app.post('/api/v1/shadow-post', …) added to src/app.ts: base suite 6/6 green. At the tip it fails with POST /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 to src/app.ts: base suite 6/6 green. At the tip it fails with GET /api/v1/shadow-quoted is registered in src/app.ts but is not declared exactly once in the contract.
  • A second '/api/v1/openapi.json': { … } block in the paths literal: 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:

  • A second scanner inside 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.
  • Building paths from an array in src/api/openapi.ts so duplicates cannot collapse at all: rejected for this card, because it moves the change into src/ and makes it T2 with no gain for the contract's user-visible shape; the card allows the source-text mechanism.
  • Rewriting the coverage test from scratch instead of keeping its assertions: rejected; the assertions are kept and made method-aware so the suite loses nothing.

Uncertainty and residual risk:

  • pathDeclarationCount assumes a /api/v1/* string appears in src/api/openapi.ts only as a paths key. 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.
  • The reader refuses 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 tip
  • node scripts/risk-gate.mjs --base 4e5ed78f182725e9790eff1b51156068aee763d2 — prints the tier below
    Not run: the GitHub CI jobs on this branch, the coverage job, any deploy.

risk-tier: T1; basis: test/apiDocReader.ts

Docs: docs/api.md updated in this PR. The served API is unchanged, so no changelog fragment.

@HugoXK
HugoXK merged commit 6ebb090 into main Nov 24, 2026
52 of 54 checks passed
@HugoXK
HugoXK deleted the dev3/1293-openapi-scan branch November 24, 2026 10:44
Fledge Platform Dev-3 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(api): make the OpenAPI route scan see every method and both quote styles, and stop a duplicate path from collapsing

1 participant