Skip to content

[python] Add mock_api coverage for single-discriminator no-subtypes and body-root nested scenarios#10896

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/add-test-case-python-sdk-spector
Open

[python] Add mock_api coverage for single-discriminator no-subtypes and body-root nested scenarios#10896
Copilot wants to merge 4 commits into
mainfrom
copilot/add-test-case-python-sdk-spector

Conversation

Copilot AI commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This adds python mock API coverage for new Spector scenarios introduced by the cross-language spec updates (PR #10841): a discriminated model with no declared subtypes, and a @bodyRoot parameter nested inside a wrapper model. The PR extends existing single-discriminator tests in both sync and async suites, adds new shared body-root tests, and aligns local spec inputs to a version that contains the scenarios.

  • Test coverage: single-discriminator no-subtypes (shared sync/async)

    • Extended existing shared tests to cover:
      • get_no_subtypes_model()
      • put_no_subtypes_model(...)
    • Added Fish model assertions to validate the expected wire payload shape (kind, size).
  • Test coverage: body-root nested (shared sync/async)

    • Added new shared tests (test_parameters_body_root.py and asynctests/test_parameters_body_root_async.py) covering the nested(...) operation with a BodyRootModel (category, link_type, was_successful).
    • Validated locally against the Spector mock server.
  • Spec dependency update for scenario availability

    • Updated @typespec/http-specs in packages/http-client-python/package.json (and lockfile) to a version containing the new scenario definitions used by regeneration.
  • Change tracking

    • Added a Chronus internal entry for @typespec/http-client-python.
def test_get_no_subtypes_model(client):
    assert client.get_no_subtypes_model() == Fish(kind="salmon", size=10)

def test_put_no_subtypes_model(client):
    client.put_no_subtypes_model(Fish(kind="salmon", size=10))

def test_nested(client):
    client.nested(BodyRootModel(category="widget", link_type="hard", was_successful=True))

Note: The third scenario from PR #10841, Parameters_Query_SpecialChar_dollarSign, is intentionally not covered. There is an upstream spec inconsistency where main.tsp declares @route("/dollarSign") (camelCase) while mockapi.ts registers the endpoint at /dollar-sign (kebab-case). The mock server only serves /dollar-sign, while the generated SDK correctly calls /dollarSign, so the test would 404. This requires a fix in @typespec/http-specs before SDK coverage can pass.

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the emitter:client:python Issue for the Python client emitter: @typespec/http-client-python label Jun 4, 2026
Copilot AI changed the title [WIP] Add test case for Python SDK Spector mock API [python] Add mock_api coverage for single-discriminator no-subtypes scenario Jun 4, 2026
Copilot finished work on behalf of msyyc June 4, 2026 23:30
Copilot AI requested a review from msyyc June 4, 2026 23:30
@msyyc

msyyc commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

…-python-sdk-spector

# Conflicts:
#	packages/http-client-python/package-lock.json

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflict in packages/http-client-python/package-lock.json (version conflict — kept 0.31.0 from main to match package.json) and completed the merge of origin/main in 6f0cf3d.

Copilot finished work on behalf of msyyc June 9, 2026 08:19
- "@typespec/http-client-python"
---

Add sync and async mock_api tests for the single-discriminator no-subtypes Spector scenario from http-specs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow https://github.com/microsoft/typespec/blob/main/.github/skills/python-sdk-spector-mock-api-tests/SKILL.md to add test case for #10841.

NOTE: there is already some test added but you miss some. @copilot

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the missing coverage. PR #10841 introduced three scenarios:

  • Type_Model_Inheritance_SingleDiscriminator_get/putNoSubtypesModel — already covered.
  • Parameters_BodyRoot_nested — now covered (sync + async, shared) in test_parameters_body_root.py / asynctests/test_parameters_body_root_async.py. Validated locally against the Spector mock server (both pass).
  • Parameters_Query_SpecialChar_dollarSign — not added because of an upstream spec inconsistency: main.tsp declares @route("/dollarSign") (and spec-summary.md documents /dollarSign), but mockapi.ts registers the endpoint at /parameters/query/special-char/dollar-sign. The mock server only serves /dollar-sign, while the generated SDK correctly calls /dollarSign, so the test 404s. This needs a fix in http-specs (align the mockapi.ts uri with the route) before SDK coverage can pass. Let me know if you'd like me to proceed once that's corrected.

Done in 19224f7.

Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Copilot AI changed the title [python] Add mock_api coverage for single-discriminator no-subtypes scenario [python] Add mock_api coverage for single-discriminator no-subtypes and body-root nested scenarios Jun 9, 2026
Copilot finished work on behalf of msyyc June 9, 2026 09:35
Copilot AI requested a review from msyyc June 9, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

emitter:client:python Issue for the Python client emitter: @typespec/http-client-python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[python] add test case for https://github.com/microsoft/typespec/pull/10841

2 participants