[WIP] Detect mock api uri / spec route mismatches in http-specs validation#10978
[WIP] Detect mock api uri / spec route mismatches in http-specs validation#10978Copilot wants to merge 8 commits into
Conversation
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR strengthens tsp-spector validate-mock-apis by validating that each mock API uri is consistent with the corresponding TypeSpec route, preventing “green CI but 404 at runtime” mismatches between generated clients and the mock server.
Changes:
- Add route-vs-uri segment comparison utilities (with normalization and URI-template wildcard handling).
- Validate each
MockApiDefinition.uriagainst the scenario’s spec routes and fail with a diagnostic on mismatch. - Fix swapped mock URIs in
http-specsroutes scenarios and add Chronus entries.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/spector/src/utils/route-utils.ts | New URI normalization + route/URI segment matching utility used by validation. |
| packages/spector/src/utils/route-utils.test.ts | Unit tests for normalization and route/URI matching behavior. |
| packages/spector/src/utils/index.ts | Exports new route-utils helpers. |
| packages/spector/src/actions/validate-mock-apis.ts | Adds route/URI consistency validation and new diagnostic. |
| packages/http-specs/specs/routes/mockapi.ts | Fixes swapped Routes_fixed vs Routes_InInterface mock URIs. |
| .chronus/changes/spector-validate-mockapi-route-2026-6-12-6-58-0.md | Changelog entry for @typespec/spector validation enhancement. |
| .chronus/changes/http-specs-fix-swapped-routes-2026-6-12-6-58-0.md | Changelog entry for @typespec/http-specs swapped-URI fix. |
commit: |
|
All changed packages have been documented.
Show changes
|
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
|
You can try these changes here
|
Resolve operation routes from getAllHttpServices (real HTTP routes) instead of the lossy scenario-endpoint route summary, and check per-spec-route that each route is served by at least one mock api uri (rather than per-mock-uri). This skips the server path prefix, supports ARM resource-uri scope spanning, and ignores extra supporting mock handlers (LRO status polling, pagination continuation pages) while still catching genuine route/mock mismatches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…st comment - Match a mock uri against every distinct @server path-prefix length (instead of only the shortest), so services declaring multiple servers with different prefix lengths cannot produce false mismatches. - Reword the literal-segment mismatch test comment so it stays accurate after the dollar-sign spec fix merged. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
tsp-spector validate-mock-apisonly checked that each scenario had a mock API; it never compared the mock APIuriagainst the route declared inmain.tsp. When they diverge, generated clients call one path while the mock server serves another (404 at runtime) — and CI stayed green. Theknock/server tests can't catch it either, since they derive both the served and called path from the sameuri.Changes
@typespec/spector— newutils/route-utils.ts:isMockApiUriConsistentWithRoute(template, uri)compares a spec route against a mock uri segment-by-segment. URI template expressions ({param},{+param},{param*},{/param}) are treated as wildcards; literal segments must match exactly; the uri may carry extra trailing segments (for@path-annotated params, server-templated api-versions, reserved expansions). Also normalizes express\:escaping and strips query strings.@typespec/spector—validate-mock-apis.ts: each mock apiurimust be consistent with one of the scenario's spec routes; otherwise a diagnostic is reported and the action exits non-zero.@typespec/http-specs—routes/mockapi.ts: fixes a genuine mismatch surfaced by the new check — theRoutes_fixedandRoutes_InInterfacemock uris were swapped.Example diagnostic
Note
The
Parameters_Query_SpecialChar_dollarSignmismatch is intentionally left in place (its data fix is handled by #10962) and serves as the live confirmation that the check now fails CI on a real mismatch. Validated against all specs: the check produces no false positives and flags only genuine divergences.Test
After fix, CI could catch the mismatch now
