Skip to content

Fix float comparison in duration encode mockapi for query and header params#9945

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-float-comparison-in-mockapi
Open

Fix float comparison in duration encode mockapi for query and header params#9945
Copilot wants to merge 3 commits intomainfrom
copilot/fix-float-comparison-in-mockapi

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

Float-typed duration values transmitted as query/header params were compared as strings, causing valid representations like "35625.0" to fail against expected "35625" even though they're numerically equal.

Changes

  • New createQueryFloatServerTests helper: Uses parseFloat() for numeric comparison instead of string equality for float query param scenarios
  • New createHeaderFloatServerTests helper: Same numeric comparison approach for float header scenarios
  • Updated 8 scenarios to use the new float helpers — the ones where whole-number float values create representation ambiguity:
    • floatMilliseconds / float64Milliseconds (35625)
    • floatSecondsLargerUnit (150)
    • floatMillisecondsLargerUnit (210000)

Non-float scenarios (int32, iso8601) and non-ambiguous floats like 35.625 are unchanged — their string comparison remains appropriate.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: mockapi in e2e test, logic to compare float is not correct</issue_title>
<issue_description>### Describe the bug

mockapi in test https://github.com/microsoft/typespec/blob/main/packages/http-specs/specs/encode/duration/mockapi.ts

On test of duration as float, in query param and header param, it compares with e.g. 35625, which fails other same float value of 35625.0 etc.

Please fix these mockapi, to make it compare the float number (not its string representation).

Reproduction

run test with e.g. 35625.0 as input

Checklist

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…eader params

Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service bot added the lib:http-specs For issues/prs related to the @typespec/http-specs package label Mar 6, 2026
Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix float comparison logic in mockapi for e2e tests Fix float comparison in duration encode mockapi for query and header params Mar 6, 2026
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 6, 2026

Open in StackBlitz

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

commit: 1b5d62c

@azure-sdk
Copy link
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

lib:http-specs For issues/prs related to the @typespec/http-specs package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: mockapi in e2e test, logic to compare float is not correct

5 participants