Skip to content

test: backport proxy-independent HTTP mocks to release/v2.1 - #638

Merged
Mehak Bindra (MehakBindra) merged 1 commit into
release/v2.1from
mehakbindra-http-mock-release-backport
Oct 16, 2026
Merged

Mehak Bindra (MehakBindra) merged 1 commit into
release/v2.1from
mehakbindra-http-mock-release-backport

Conversation

@MehakBindra

Copy link
Copy Markdown
Member

Summary

Backport merged main PR #637 by cherry-picking 45694bdf374a10be5e023ede684d8a6cda0c9e63 with -x. Backport commit: 4f80b16649e0657b94dc35481bfafb6f6a96aeea. Applied cleanly on release/v2.1 after #635.

Only five HTTP mock test files change. Construct mocked httpx.AsyncClient instances with explicit MockTransport before injecting them into SDK Client(_http=...), preserving clone configuration, event hooks, and share_http behavior. Add regression coverage with unreachable proxy settings.

No production code, TLS/proxy policy, dependencies, release version, or documentation changes. version.json remains 2.1.1. This new backport follows the user-approved main-first sequence; superseded release PR #636 remains closed.

Why

HTTPX 0.28.1 discovers proxies using Python urllib.request.getproxies(), including Windows registry fallback, and creates proxy mounts during client initialization. Request routing checks those mounts before the default transport, so replacing _transport afterward can bypass a mock. Passing the mock transport at construction avoids creating environment proxy mounts.

Sources: HTTPX proxy discovery, HTTPX client routing.

Failed ADO publish run 20467 followed successful run 17012 with agent image/network-task changes (29.0.0 / 1.0.175 to 41.0.0 / 1.0.185). HTTPX/HTTP Core were unchanged; the exact environmental trigger is unproven.

Validation

  • 445 API/common tests passed on Python 3.13 with HTTP_PROXY, HTTPS_PROXY, and ALL_PROXY set to http://127.0.0.1:1, and empty NO_PROXY. Imports confirmed to resolve to this worktree.
  • The wheel typing-marker test was excluded only from the local forced-proxy experiment, then run separately without proxy overrides. Its build dependency downloads failed with PyPI TLS HandshakeFailure; it is unchanged and remains enabled in CI.
  • Repository-wide Ruff lint and formatting checks passed (513 files formatted correctly); diff whitespace check passed.
  • Full local Pyright is blocked by the missing workspace virtual environment/unresolved dependencies. GitHub CI must provide complete build/type validation. Main PR test: make HTTP mocks independent of environment proxy routing #637 already passed CI on Python 3.11–3.14 and CodeQL.
  • nbgv get-version --public-release=true -v SemVer2 returned 2.1.1.

Merge and publishing

Merge with a merge commit, not squash, as required by RELEASE.md. This PR does not merge or publish anything. No successful 2.1.1 publication has occurred; publishing remains a separate authorized step after CI and merge.

## Summary

Cherry-pick 24ccd41 onto main with `-x`
provenance, with the CONTRIBUTING.md addition subsequently removed. This
PR contains only the test fix in five files; it does not include
release-only ancestry, the 2.1.1 version bump, dependency changes, or
production proxy/TLS changes.

Construct mocked `httpx.AsyncClient` instances with explicit
`MockTransport` before injecting them into SDK `Client` via `_http`,
rather than replacing `_transport` after HTTPX has configured proxy
mounts. Preserve clone settings, event hooks, and `share_http` behavior.
Add proxy-environment regression coverage.

## Context

ADO publish run 20467 failed 117 tests because real HTTP requests
bypassed mocks. HTTPX 0.28.1/HTTP Core 1.0.9 and the affected test
setup/YAML were unchanged from successful run 17012. The image and
1ESNetworkIsolation task changed (29.0.0 / 1.0.175 to 41.0.0 / 1.0.185),
alongside Python and AnyIO versions; the exact trigger of proxy routing
remains unproven.

**HTTPX confirms the failure mechanism.** Its [proxy-discovery
code](https://github.com/encode/httpx/blob/0.28.1/httpx/_utils.py) reads
proxy settings through Python’s `getproxies()`, including the **Windows
registry**, not just environment variables. Its [client
code](https://github.com/encode/httpx/blob/0.28.1/httpx/_client.py)
checks proxy mounts before the default transport—so replacing
`_transport` afterward can leave proxies active.

User-directed sequence: main first, then backport the merged commit to
release/v2.1. This supersedes the proposed release-first fix in #636;
closing that PR and handling the later backport are left to the
coordinating session. Nothing is being merged or published here.

## Validation

- 447 API/common tests passed with `HTTP_PROXY`, `HTTPS_PROXY`, and
`ALL_PROXY` set to `http://127.0.0.1:1` and `NO_PROXY` empty. Imports
were confirmed to resolve to this worktree. The wheel-build test was
excluded only from this local forced-proxy run, not changed or skipped
in CI.
- Repository-wide Ruff lint and format checks passed; commit hooks
passed (Pyright hook had no production files to check).
- The wheel typing-marker test was run separately without forced proxy
overrides and was blocked downloading build dependencies from PyPI by
TLS `HandshakeFailure`.
- Full Pyright could not be validated with the incomplete local
environment. Dependency restoration failed with the same PyPI TLS
handshake errors, including with native certificate trust. CI is
required for complete build/type validation; no TLS verification or
corporate proxy settings were disabled.

---------

Copilot-Session: 75921e14-a409-4a9a-bb03-08659dc023de
Copilot-Session: 70488242-a4f5-4f62-86f7-91d9335545c2
(cherry picked from commit 45694bd)
@MehakBindra
Mehak Bindra (MehakBindra) merged commit 669023e into release/v2.1 Oct 16, 2026
5 checks passed
@MehakBindra
Mehak Bindra (MehakBindra) deleted the mehakbindra-http-mock-release-backport branch October 16, 2026 22:24
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.

2 participants