Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

Duration encoding tests had type mismatches between input values and expected values. In the mock framework, query parameters maintain their original type rather than being serialized to strings, causing validation failures when comparing numbers to strings.

Changes

  • Updated query test expectations in mockapi.ts: Changed expected values from strings to numbers to match the input format
    • Query parameter floatSecondsLargerUnit: changed input from 150.0 to 150 and expected from "150" (string) to 150 (number)
    • Query parameter floatMillisecondsLargerUnit: changed input from 210000.0 to 210000 and expected from "210000" (string) to 210000 (number)
    • Header tests unchanged: headers remain as strings since HTTP headers are always strings

How It Works

In the mock framework, when you set query: { input: 150 }, the query object contains the number 150, not the string "150". The validation compares request.query.input with the expected value using strict equality (!==).

// Before: type mismatch
createQueryServerTests("/path", { input: 150.0 }, "150");  
// Compares: 150 !== "150" → true (fails)

// After: types match
createQueryServerTests("/path", { input: 150 }, 150);  
// Compares: 150 !== 150 → false (passes)

Affects duration encoding tests where languages use TimeSpan.FromMinutes(2.5)150 seconds.

The fix updates the test expectations in packages/http-specs/specs/encode/duration/mockapi.ts to ensure type consistency between mock inputs and expected validation values.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: EncodeDuration with larger unit durations is too strict</issue_title>
<issue_description>### Describe the bug

Some tests expect header/query params to have a trailing ".0" as they're performing string comparisons. It would be better if the test parsed the value into a number.

Reproduction

Introduced in #8729

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.

Copilot AI changed the title [WIP] Fix strictness of EncodeDuration for larger units Fix numeric string comparison in header/query parameter validation Nov 19, 2025
Copilot AI requested a review from JoshLove-msft November 19, 2025 20:31
Copilot finished work on behalf of JoshLove-msft November 19, 2025 20:31
@JoshLove-msft JoshLove-msft marked this pull request as ready for review November 19, 2025 20:37
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix numeric string comparison in header/query parameter validation Fix EncodeDuration test expectations by removing trailing .0 from numeric strings Nov 19, 2025
Copilot finished work on behalf of JoshLove-msft November 19, 2025 20:58
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • telemetry.astro.build
    • Triggering command: node /home/REDACTED/work/typespec/typespec/website/node_modules/.bin/../astro/astro.js build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Fix EncodeDuration test expectations by removing trailing .0 from numeric strings Fix EncodeDuration test expectations by matching input types Nov 19, 2025
Copilot AI requested a review from JoshLove-msft November 19, 2025 21:57
Copilot finished work on behalf of JoshLove-msft November 19, 2025 21:57
@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 19, 2025

Open in StackBlitz

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

commit: e5b6768

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: EncodeDuration with larger unit durations is too strict

3 participants