fix(spector): handle matchers in query param validation#10259
fix(spector): handle matchers in query param validation#10259
Conversation
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 }); |
There was a problem hiding this comment.
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>
|
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 |
| 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); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
I asked copilot to add test, but these may not be very meaningful. I can revert them if unhelpful.
There was a problem hiding this comment.
yeah that make sense, wondering if we ever need the resolveMatchers: true on. i'll investigate in a folllow up pr
commit: |
…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>
|
You can try these changes here
|
resolveMatchers: false+isMatcherbranch)resolveMatchers: falseand addisMatcher(value)branch