Skip to content

Add Spector case for serializing fractional duration encoded as integer#10835

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/add-spector-case-serialization
Draft

Add Spector case for serializing fractional duration encoded as integer#10835
Copilot wants to merge 2 commits into
mainfrom
copilot/add-spector-case-serialization

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 29, 2026

Existing encode/duration scenarios only used whole-number payloads, so they couldn't catch the bug from #10831 where a duration with a fractional sub-second component was serialized as a floating point number (e.g. 123.45) instead of an integer.

Changes (packages/http-specs/specs/encode/duration/)

  • main.tsp: New int32-seconds-fractional scenarios in the Query, Property, and Header namespaces. Each constructs a 35.625-second duration encoded as int32 seconds:

    @route("/int32-seconds-fractional")
    @scenario
    @scenarioDoc("""
      ...The duration is 35.625 seconds, e.g. TimeSpan.FromSeconds(35.625) in C#.
      Even though the underlying value is fractional, the client must serialize it
      as an integer (not a floating point number), e.g. `input=36`.
      """)
    op int32SecondsFractional(
      @query @encode(DurationKnownEncoding.seconds, int32) input: duration,
    ): NoContentResponse;
  • mockapi.ts: New handlers (createBodyIntServerTests, createQueryIntServerTests, createHeaderIntServerTests) assert the received value is an integer and reject floating point. Validation checks integer-ness rather than an exact value, since truncate-vs-round semantics across languages is still unresolved in the issue discussion — this verifies the core contract ("serializes as an int") without prescribing a rounding mode.

  • spec-summary.md: Regenerated.

Open question

The cross-language semantic for converting a fractional duration to an integer (truncate vs. round) remains undecided per the issue thread. The mock is intentionally lenient so it passes under either choice while still failing on float output; tightening to an exact value can follow once the semantic is settled.

Co-authored-by: JoshLove-msft <54595583+JoshLove-msft@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 May 29, 2026
Copilot AI changed the title [WIP] Add Spector case for serializing duration as integer Add Spector case for serializing fractional duration encoded as integer May 29, 2026
Copilot AI requested a review from JoshLove-msft May 29, 2026 02:28
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.

Add Spector Case for Serializing Duration encoded as integer

2 participants