Skip to content

[http-client-python] Honor void response replacements - #12651

Draft
Libba Lawrence (l0lawrence) wants to merge 1 commit into
microsoft:mainfrom
l0lawrence:l0lawrence-python-core-spector-gap
Draft

Libba Lawrence (l0lawrence) wants to merge 1 commit into
microsoft:mainfrom
l0lawrence:l0lawrence-python-core-spector-gap

Conversation

@l0lawrence

Copy link
Copy Markdown
Member

Summary

Fix one verified Core-tier Spector gap in @typespec/http-client-python: basic methods with an intentional void response replacement now return None, rather than deserializing the original service response into a model. Keep the service status, headers, and JSON response on the wire unchanged. Ordinary basic responses and the separately unsupported bytes replacement are not changed.

Exact Spector coverage

Scenario ID Dashboard evidence Python tests and assertions
Azure_ClientGenerator_Core_ResponseReplacement_voidResponse Azure HTTP dashboard: not-implemented; Core by the current default tier, with no matching Backlog exact/wildcard rule. The standard dashboard does not include this Azure suite/scenario. packages/http-client-python/tests/mock_api/azure/test_response_replacement.py and packages/http-client-python/tests/mock_api/azure/asynctests/test_response_replacement_async.py: normal sync/async calls return None; a cls callback receives a None deserialized value while the raw response still has status 200 and JSON {"name":"widget"}.

This is the only scenario for which this PR adds Python Spector coverage. It does not claim support for Azure_ClientGenerator_Core_ResponseReplacement_bytesResponse.

Verified cross-language comparison

  • C#: read packages/http-client-csharp/generator/TestProjects/Spector.Tests/Http/Azure/ClientGeneratorCore/ResponseReplacement/ResponseReplacementTests.cs, introduced by #12340. Its VoidResponse and VoidResponseAsync assert the untyped ClientResult runtime type, HTTP 200, and the exact raw JSON text. Python provides equivalent sync/async discard-body behavior and raw-response access, but returns None instead of an untyped result wrapper; its cls callback verifies the parsed raw JSON rather than comparing its textual formatting.
  • Java: read packages/http-client-java/generator/http-client-generator-test/src/test/java/azure/clientgenerator/core/responsereplacement/ResponseReplacementTests.java, added with regenerated coverage in #12540. testVoidResponse is a sync Spector client invocation with no explicit return-value or raw-response assertions. The Python tests additionally assert None, status/body preservation, and async behavior. Java's separate bytes test is not parity evidence for the void scenario and is not included in this PR's coverage claim.

Fresh dashboard evidence and version comparison

Both deployed dashboards were inspected, including their hydrated configuration and deployed JavaScript, rather than assuming report paths. They read https://typespec.blob.core.windows.net/coverages/, resolve <generator>/index.json, try legacy reports/<version>.json first, then the mode-specific report. The legacy reports were absent and both selected reports were obtained. Report suites were matched to manifests by scenariosMetadata.packageName; missing scenario entries were treated as leads, not proof of unsupported behavior.

  • Standard report: @typespec/http-client-python/reports/0.28.3/standard.json, generator commit 07e6c7fb6a6f6c32583bdbabd7be8b8a17f58398; HTTP suite 0.1.0-alpha.36, same commit.
  • Azure report: @azure-tools/typespec-python/reports/0.63.12/azure.json, generator commit a5cc5a36512716e89d7578e4cda3b721580164b4; Azure suite 0.1.0-alpha.47, same commit; HTTP suite 0.1.0-alpha.46, commit 123e997958ced3b632caa0a4486e306d1487ca82.
  • Current HTTP manifest: 0.1.0-alpha.46, commit e06f6b34fdad9d7f49bfc084a598b03c60684e9a (verified ancestor of this checkout).
  • Current Azure manifest: 0.1.0-alpha.47, commit 9f3187901c0ef5015eb0d8eb4b0151166cd79135.
  • Reproduction checkout: 1549a46bdb9b4f8dbaa45199807d927f66f1a423; Python emitter 0.40.1, pinned HTTP specs 0.1.0-alpha.46 and Azure specs 0.1.0-alpha.47. No dependency versions were changed. The report commits differ from the current manifests; the standard report's HTTP version also predates the pinned suite.

The Azure dashboard's live tier rules were applied to scenarios from both dashboards: exact rules take precedence over anchored * wildcard rules, then the configured default (Core). Core candidate leads were merged by scenario ID. Open Microsoft TypeSpec PRs and identifiable pending Python automation sessions were checked; named-model query scenarios already tracked by #12624 and policy-skipped specs were excluded from selection.

Reproduction and root cause

Read the manifest-located, pinned Azure spec and its client.tsp override and mockapi.ts under packages/http-client-python/node_modules/@azure-tools/azure-http-specs/specs/azure/client-generator-core/response-replacement/.

Before the fix, both new pytest tests failed because void_response() returned Widget(name="widget") instead of None. A separate sync reproduction against an isolated Spector server serving these pinned dependencies on port 3107 failed identically. The emitter always chose the underlying HTTP body type for basic methods, ignoring the overridden method's absent response type.

The fix honors an absent response type on overridden basic methods, retaining the original wire response metadata. The emitter unit regression verifies omitted response type with HTTP 200 and application/json preserved.

Checks

Passed:

  • npm run build in packages/http-client-python.
  • npm run test:emitter: complete emitter suite, 76 tests.
  • npx tsc --noEmit -p .\emitter\tsconfig.json.
  • Single-spec compilation with the locally built emitter, using tests/generated/azure/response to avoid Windows long-path failures in the usual fixture directory.
  • python -m pytest on the two new sync/async Spector files: 2 passed (--asyncio-mode=auto).
  • Independent sync and async calls against the isolated pinned-spec Spector server on port 3107, including the None and raw status/body assertions.
  • npm run format, npm run format:check, npm run lint -- --emitter, and Black checks for both added Python tests.
  • Root pnpm format and git diff --check.

Only targeted Spector clients were generated; the full generated-client flavor matrix was not run. Generated clients and coverage output are not committed, and no coverage metadata or existing assertions were weakened.

@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 Nov 24, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 421b2a3

@github-actions

Copy link
Copy Markdown
Contributor

All changed packages have been documented.

  • ✅ @typespec/http-client-python
Show changes

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

Honor replaceResponseWithVoid for basic client methods, returning None while preserving the service response on the wire.

@github-actions

Copy link
Copy Markdown
Contributor

Python emitter diff

Baseline gh:1549a46bdb9b4f8dbaa45199807d927f66f1a423 vs this PR.

Diff summary: 2 file(s), +12 / -38

Rendered diff: inline on the run summary, or the emitter-diff-html artifact.

Informational check (eng/emitter-diff); does not block the PR.

@azure-sdk-automation

Copy link
Copy Markdown

You can try these changes here

🛝 Playground 🌐 Website 🛝 VSCode Extension

This branch has not been deployed

No deployments
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.

1 participant