Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 14, 2025

Fixes the issue by adding new Spector test scenarios for duration encoding where the duration value is several minutes, demonstrating that language implementations should use the largest possible unit when constructing duration primitives.

Changes

New Test Scenarios Added

Added 12 new test scenarios across Header, Property, and Query namespaces:

  • int32SecondsLargerUnit - 120 seconds (2 minutes)
  • floatSecondsLargerUnit - 150.0 seconds (2.5 minutes)
  • int32MillisecondsLargerUnit - 180000 milliseconds (3 minutes)
  • floatMillisecondsLargerUnit - 210000.0 milliseconds (3.5 minutes)

Documentation

All new scenarios include explicit documentation stating:

Languages that support duration primitives should use the largest possible unit, e.g. TimeSpan.FromMinutes(2) in C#.

This guidance ensures language implementations construct duration values idiomatically (e.g., TimeSpan.FromMinutes(2) in C# or Duration.ofMinutes(2) in Java) rather than always using the encoded unit (e.g., TimeSpan.FromSeconds(120)).

Files Modified

  • packages/http-specs/specs/encode/duration/main.tsp - Added 12 operations and 4 models
  • packages/http-specs/specs/encode/duration/mockapi.ts - Added 12 mock API scenarios
  • packages/http-specs/spec-summary.md - Auto-generated documentation for new scenarios

Wire Format

The wire format remains unchanged - durations are still encoded as integers or floats in seconds or milliseconds as specified. The new scenarios document how language SDKs should construct the duration values in memory before encoding.

Validation

All validation steps from the testserver generation guidelines have been completed successfully:

  • pnpm build
  • pnpm validate-mock-apis
  • pnpm cspell
  • pnpm format
  • pnpm lint
  • pnpm regen-docs

Fixes #8728

Original prompt

This section details on the original issue you should resolve

<issue_title>Add Spector scenario for EncodeDuration where the duration could be satisfied by a larger unit</issue_title>
<issue_description>for encode seconds, have a test case where the duration is several minutes and document that languages that support duration primitives should use the largest possible unit, e.g. in C# TimeSpan.FromMinutes(2)

Similar test case needed for encode milliseconds.

We should add the new test cases for:

  • seconds, int32
  • seconds, float
  • milliseconds, int32,
  • milliseconds, float

across each of Header, Property, and Query.
</issue_description>

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

Fixes #8728


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
@JoshLove-msft
Copy link
Contributor

@copilot please follow the instructions here - https://github.com/microsoft/typespec/blob/main/.github/prompts/testserver-generation.md#required-steps-all-must-be-completed-in-order. Specifically, the validation instructions.

Copilot AI changed the title [WIP] Add Spector scenario for EncodeDuration with larger units Add Spector scenarios for EncodeDuration with larger unit durations Oct 14, 2025
Copilot AI requested a review from JoshLove-msft October 14, 2025 19:03
Copilot finished work on behalf of JoshLove-msft October 14, 2025 19:03
Copilot AI and others added 2 commits October 14, 2025 19:10
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 14, 2025

@copilot please follow the instructions here - https://github.com/microsoft/typespec/blob/main/.github/prompts/testserver-generation.md#required-steps-all-must-be-completed-in-order. Specifically, the...

Followed validation instructions in 18f42c9. All validation steps passed:

  • ✓ pnpm build
  • ✓ pnpm validate-mock-apis
  • ✓ pnpm cspell
  • ✓ pnpm format
  • ✓ pnpm lint
  • ✓ pnpm regen-docs

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 finished work on behalf of JoshLove-msft October 14, 2025 19:29
@JoshLove-msft JoshLove-msft marked this pull request as ready for review October 14, 2025 19:33
@github-actions
Copy link
Contributor

All changed packages have been documented.

  • @typespec/http-specs
Show changes

@typespec/http-specs - feature ✏️

Add scenario for encode duration with larger units

@JoshLove-msft JoshLove-msft added this pull request to the merge queue Oct 14, 2025
Merged via the queue into main with commit bb74d7b Oct 14, 2025
22 checks passed
@JoshLove-msft JoshLove-msft deleted the copilot/add-spector-scenario-encode-duration branch October 14, 2025 22:22
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.

Add Spector scenario for EncodeDuration where the duration could be satisfied by a larger unit

4 participants