Skip to content

[WIP] Detect mock api uri / spec route mismatches in http-specs validation#10978

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-ci-detection-issue
Open

[WIP] Detect mock api uri / spec route mismatches in http-specs validation#10978
Copilot wants to merge 8 commits into
mainfrom
copilot/fix-ci-detection-issue

Conversation

Copilot AI commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

tsp-spector validate-mock-apis only checked that each scenario had a mock API; it never compared the mock API uri against the route declared in main.tsp. When they diverge, generated clients call one path while the mock server serves another (404 at runtime) — and CI stayed green. The knock/server tests can't catch it either, since they derive both the served and called path from the same uri.

Changes

  • @typespec/spector — new utils/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/spectorvalidate-mock-apis.ts: each mock api uri must be consistent with one of the scenario's spec routes; otherwise a diagnostic is reported and the action exits non-zero.
  • @typespec/http-specsroutes/mockapi.ts: fixes a genuine mismatch surfaced by the new check — the Routes_fixed and Routes_InInterface mock uris were swapped.
  • Unit tests for the matching logic + changesets.

Example diagnostic

✘ Scenario Parameters_Query_SpecialChar_dollarSign has a mock api uri
  "/parameters/query/special-char/dollar-sign" that does not match
  (segment-by-segment, treating route template params as wildcards)
  any of the routes defined in the spec:
  "/parameters/query/special-char/dollarSign".

Note

The Parameters_Query_SpecialChar_dollarSign mismatch 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
image

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added lib:http-specs For issues/prs related to the @typespec/http-specs package spector Issues related to spector and the spec sets labels Jun 12, 2026
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CI detection for mismatch in http-specs Detect mock api uri / spec route mismatches in http-specs validation Jun 12, 2026
Copilot finished work on behalf of msyyc June 12, 2026 07:01
Copilot AI requested a review from msyyc June 12, 2026 07:01
@msyyc msyyc requested a review from Copilot June 12, 2026 07:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.uri against the scenario’s spec routes and fail with a diagnostic on mismatch.
  • Fix swapped mock URIs in http-specs routes 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.

Comment thread packages/spector/src/utils/route-utils.ts Outdated
Comment thread packages/spector/src/utils/route-utils.test.ts
Comment thread packages/spector/src/actions/validate-mock-apis.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-specs@10978
npm i https://pkg.pr.new/@typespec/spector@10978

commit: b152f41

@msyyc msyyc marked this pull request as ready for review June 12, 2026 07:30
@github-actions

github-actions Bot commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-specs
  • @typespec/spector
Show changes

@typespec/http-specs - fix ✏️

Fix the swapped mock api uris for the Routes_fixed and Routes_InInterface scenarios so they match the routes defined in the spec.

@typespec/spector - fix ✏️

validate-mock-apis now verifies that every route defined in a scenario's main.tsp is served by at least one of the scenario's mock API uris, so a mismatch between the spec route and the mock api uri (which would make a generated client get a 404 from the mock server) is detected by CI.

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot finished work on behalf of msyyc June 12, 2026 07:36
@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

msyyc and others added 2 commits June 15, 2026 10:05
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>
@msyyc msyyc changed the title Detect mock api uri / spec route mismatches in http-specs validation [WIP] Detect mock api uri / spec route mismatches in http-specs validation Jun 15, 2026
@msyyc msyyc requested a review from Copilot June 15, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread packages/spector/src/actions/validate-mock-apis.ts
Comment thread packages/spector/src/utils/route-utils.test.ts
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lib:http-specs For issues/prs related to the @typespec/http-specs package spector Issues related to spector and the spec sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants