Skip to content

test: make release HTTP mocks independent of agent proxy routing - #636

Closed
Mehak Bindra (MehakBindra) wants to merge 1 commit into
release/v2.1from
mehakbindra-patch-release
Closed

Mehak Bindra (MehakBindra) wants to merge 1 commit into
release/v2.1from
mehakbindra-patch-release

Conversation

@MehakBindra

Copy link
Copy Markdown
Member

Summary

  • Fix mocked API/common HTTP clients to inject httpx.AsyncClient(transport=MockTransport(...)) at construction, rather than replacing _transport after HTTPX has configured proxy mounts.
  • Preserve mock transports, client settings, event hooks, and shared-client behavior when cloning test clients.
  • Add proxy-environment regression tests and document the mocking pattern.
  • No production code, proxy policy, TLS behavior, dependency versions, or release version changes. Keep 2.1.1 for the unpublished release.

Why this is needed

ADO publish run 20467 failed with real network requests escaping unit-test mocks (httpx.ProxyError: 403 Forbidden, connection errors, and real HTTP responses). The same failure mechanism was reproduced locally with a process-scoped proxy pointing at an unreachable loopback port.

The last successful run 17012 used agent image 29.0.0 and network-isolation task 1.0.175; the failed run used image 41.0.0 and task 1.0.185. HTTPX 0.28.1, HTTP Core 1.0.9, the affected test setup, and the publish YAML are unchanged. AnyIO changed from 4.11.0 to 4.14.2, and Python from 3.13.15 to 3.13.16. The exact infrastructure/dependency trigger has not been established; the proxy/mock routing failure itself is confirmed.

Validation

  • 387 affected API/common unit tests passed with HTTP_PROXY, HTTPS_PROXY and ALL_PROXY set to an unreachable loopback proxy and NO_PROXY empty.
  • All lint and formatting checks passed, as did commit hooks.
  • The separate wheel-build test needs dependency downloads and could not pass in the locally restricted environment; it is not skipped or changed in CI.
  • Full local Pyright remains blocked by the incomplete local dependency environment; GitHub CI must validate before merge.

Release

Merge with a merge commit into release/v2.1, then rerun the publish pipeline for 2.1.1. This PR does not publish anything.

Construct mocked HTTPX clients with explicit transports and preserve settings and event hooks for clones. Add proxy-environment regressions without changing production proxy behavior.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 75921e14-a409-4a9a-bb03-08659dc023de
@MehakBindra

Copy link
Copy Markdown
Member Author

Superseded by #637 targeting main, per the main-first release workflow. After that PR merges, its merged commit will be cherry-picked into release/v2.1 for the 2.1.1 release.

Mehak Bindra (MehakBindra) added a commit that referenced this pull request Oct 16, 2026
## 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
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.

1 participant