Skip to content

fix(spector): handle matchers in query param validation#10259

Open
Copilot wants to merge 4 commits intomainfrom
copilot/fix-date-time-query-matching
Open

fix(spector): handle matchers in query param validation#10259
Copilot wants to merge 4 commits intomainfrom
copilot/fix-date-time-query-matching

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 3, 2026

  • Fix query param matcher handling (resolveMatchers: false + isMatcher branch)
  • Add regression tests for query param matcher preservation
  • Apply the same fix to header validation: pass resolveMatchers: false and add isMatcher(value) branch
  • Add regression test for header matcher preservation

Copilot AI and others added 2 commits April 3, 2026 02:14
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/97f0d4fc-38c9-455c-b99d-f9dd980c6658

Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/97f0d4fc-38c9-455c-b99d-f9dd980c6658

Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>

if (apiDefinition.request?.query) {
const query = expandDyns(apiDefinition.request.query, config);
const query = expandDyns(apiDefinition.request.query, config, { resolveMatchers: false });
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.

Agent says the expandDyns with resolveMatchers: true converts the smart matcher into a dumb string too early, discarding its comparison logic. resolveMatchers: false keeps the matcher alive long enough for deepEqual → matchValues → matcher.check() to perform the semantic comparison.

…gh expandDyns

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/3d8e85a8-9e45-4d55-9f8c-7882641b3c27

Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>
@weidongxu-microsoft
Copy link
Copy Markdown
Contributor

weidongxu-microsoft commented Apr 3, 2026

For PR #10011

agent session https://github.com/microsoft/typespec/tasks/467970f4-8e4b-4bab-b0fb-6d9774b72753?author=weidongxu-microsoft (analyze is on my local Copilot CLI)

tested locally by directly modify the js file in test project node_modules

Comment on lines +247 to +260
it("should demonstrate why resolveMatchers:true (default) breaks semantic query param matching", () => {
// With the default resolveMatchers:true, the matcher is eagerly converted to a plain string.
// A strict string comparison then fails for semantically equivalent but format-different values.
const queryDef = { input: match.dateTime.utcRfc3339("2022-08-26T18:38:00.000Z") };
const expandedWithResolve = expandDyns(queryDef, config); // resolveMatchers: true (default)

// The matcher is gone — replaced by its serialized string
expect(isMatcher(expandedWithResolve.input)).toBe(false);
expect(expandedWithResolve.input).toBe("2022-08-26T18:38:00.000Z");

// Strict string comparison fails for an equivalent datetime without milliseconds
expect(expandedWithResolve.input === "2022-08-26T18:38:00Z").toBe(false);
});
});
Copy link
Copy Markdown
Contributor

@weidongxu-microsoft weidongxu-microsoft Apr 3, 2026

Choose a reason for hiding this comment

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

I asked copilot to add test, but these may not be very meaningful. I can revert them if unhelpful.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah that make sense, wondering if we ever need the resolveMatchers: true on. i'll investigate in a folllow up pr

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 3, 2026

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/spec-api@10259
npm i https://pkg.pr.new/@typespec/spector@10259

commit: 006ef06

…gression test

Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/05805cb9-1d23-42fd-8b80-fd06410b09dc

Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>
@azure-sdk
Copy link
Copy Markdown
Collaborator

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

spector Issues related to spector and the spec sets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants