Skip to content

Commit 817c5a2

Browse files
committed
Ignore proxy variables when probing the local service
Node's fetch in the TypeScript client ignores them too; macOS runners set one, so probes never reached the service.
1 parent 3bad357 commit 817c5a2

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

‎src/opencode/_service.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,9 @@ def _info_url(info: _Info) -> httpx.URL:
252252

253253

254254
def _probe(info: _Info, timeout: float) -> _Probe:
255+
# The service is local: ignore proxy variables, as Node's fetch in the TypeScript client does.
255256
try:
256-
with httpx.Client(timeout=timeout) as http:
257+
with httpx.Client(timeout=timeout, trust_env=False) as http:
257258
response = http.get(_info_url(info), headers=headers(_endpoint(info)))
258259
body: object = None if response.status_code == 404 else response.json()
259260
except httpx.TimeoutException:
@@ -265,7 +266,7 @@ def _probe(info: _Info, timeout: float) -> _Probe:
265266

266267
async def _async_probe(info: _Info, timeout: float) -> _Probe:
267268
try:
268-
async with httpx.AsyncClient(timeout=timeout) as http:
269+
async with httpx.AsyncClient(timeout=timeout, trust_env=False) as http:
269270
response = await http.get(_info_url(info), headers=headers(_endpoint(info)))
270271
body: object = None if response.status_code == 404 else response.json()
271272
except httpx.TimeoutException:
@@ -469,7 +470,7 @@ def _pty_prepare(file: Path, info: _Info, timeout: float) -> None:
469470
# Publish the ticket before stopping its owner so every replacement contender can adopt it.
470471
if _fresh_for(_read_sidecar(file), info):
471472
return
472-
with httpx.Client(timeout=timeout, headers=_pty_headers(info)) as http:
473+
with httpx.Client(timeout=timeout, trust_env=False, headers=_pty_headers(info)) as http:
473474
try:
474475
response = http.post(_pty_url(info, "handoff"))
475476
response.raise_for_status()
@@ -486,7 +487,7 @@ def _pty_prepare(file: Path, info: _Info, timeout: float) -> None:
486487
async def _async_pty_prepare(file: Path, info: _Info, timeout: float) -> None:
487488
if _fresh_for(_read_sidecar(file), info):
488489
return
489-
async with httpx.AsyncClient(timeout=timeout, headers=_pty_headers(info)) as http:
490+
async with httpx.AsyncClient(timeout=timeout, trust_env=False, headers=_pty_headers(info)) as http:
490491
try:
491492
response = await http.post(_pty_url(info, "handoff"))
492493
response.raise_for_status()

‎tests/test_service.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ async def test_async_lifecycle(file: Path) -> None:
246246
endpoint = await service.async_ensure(file, command=fake(file, "1.0.0"))
247247
assert await service.async_discover(file) == endpoint
248248
async with await AsyncOpencode.from_service(start=False, file=file) as client:
249-
response = await client._http.get(f"{endpoint.url}/api/info", headers=service.headers(endpoint))
249+
assert client.password == (endpoint.auth.password if endpoint.auth else None)
250+
async with httpx.AsyncClient(trust_env=False) as http: # CI runners may set proxy variables
251+
response = await http.get(f"{endpoint.url}/api/info", headers=service.headers(endpoint))
250252
assert response.json()["version"] == "1.0.0"
251253
second = await service.async_ensure(file, "2.0.0", command=fake(file, "2.0.0"))
252254
assert second != endpoint

0 commit comments

Comments
 (0)