From 60f3763c23fdf8fb560e1cf1cebdcf9477735c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=A1=82=E9=9B=84?= Date: Mon, 14 Sep 2026 17:10:55 +0800 Subject: [PATCH] test(gateway): keep the runner's system proxy out of the media-retry connect guard test_blocks_private_dns_answer_at_connect_time clears the six proxy env vars, but httpx resolves environment proxies through urllib.request.getproxies(), which on macOS falls back to the System Configuration (scutil --proxy) when no proxy env var is set. On a runner with a system-wide proxy the request dials the proxy rather than the rebinding host, and the test fails with: AssertionError: TCP connect attempted for 127.0.0.1:7890 httpx binds that name at import time (httpx/_utils.py does ``from urllib.request import getproxies``), so patching urllib.request.getproxies has no effect; patch the httpx-side binding. Test-only change: production proxy semantics are untouched, and the mutation check still holds (removing the connect-time guard in tools/url_safety.py turns this test red again). One of the test-isolation gaps reported in #110728 (the system-proxy one). --- tests/gateway/test_media_download_retry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/gateway/test_media_download_retry.py b/tests/gateway/test_media_download_retry.py index a6bac1684b..a53e57101a 100644 --- a/tests/gateway/test_media_download_retry.py +++ b/tests/gateway/test_media_download_retry.py @@ -170,6 +170,11 @@ class TestCacheImageFromUrlConnectGuard: "all_proxy", ): monkeypatch.delenv(proxy_var, raising=False) + # Clearing the variables above is not enough: httpx resolves environment proxies + # through ``urllib.request.getproxies``, which on macOS falls back to the System + # Configuration (``scutil --proxy``) when no proxy env var is set — so on a runner + # with a system-wide proxy the request would dial the proxy, not the rebinding host. + monkeypatch.setattr("httpx._utils.getproxies", lambda: {}) answers = [ [(socket.AF_INET, socket.SOCK_STREAM, 6, "", ("93.184.216.34", 80))],