Skip to content

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

Merged
msyyc merged 5 commits into
mainfrom
copilot/add-test-case-python-sdk-spector
Jun 10, 2026
Merged

[python] Add mock_api coverage for single-discriminator no-subtypes and body-root nested scenarios#10896
msyyc merged 5 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
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
@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/http-client-python@10896

commit: 395b2bb

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • @typespec/http-client-python
Show changes

@typespec/http-client-python - internal ✏️

Add sync and async mock_api tests for the single-discriminator no-subtypes and body-root nested Spector scenarios from http-specs.

@msyyc msyyc enabled auto-merge June 10, 2026 05:13
@msyyc msyyc added this pull request to the merge queue Jun 10, 2026
Merged via the queue into main with commit 5f94e61 Jun 10, 2026
36 checks passed
@msyyc msyyc deleted the copilot/add-test-case-python-sdk-spector branch June 10, 2026 06:31
JennyPng pushed a commit to JennyPng/typespec that referenced this pull request Jun 10, 2026
…nd body-root nested scenarios (microsoft#10896)

This adds python mock API coverage for new Spector scenarios introduced
by the cross-language spec updates (PR microsoft#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`.

```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 microsoft#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: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: msyyc <70930885+msyyc@users.noreply.github.com>
Co-authored-by: Yuchao Yan <yuchaoyan@microsoft.com>
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

3 participants