Skip to content

Commit 99a329d

Browse files
authored
Intercept httpx2 in the Microsoft Bot's Anthropic endpoint test (#761)
anthropic 1.x sends through httpx2 rather than httpx. The test patched httpx.AsyncHTTPTransport, so with the newest SDK its request reached the real Anthropic API and failed with 401, breaking main's CI. It now patches httpx2.AsyncHTTPTransport, as the AG2 Bot's tests already do.
1 parent aff4981 commit 99a329d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎agent-microsoft/tests/test_main.py‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,13 @@ async def respond(transport, request):
191191
seen.append(
192192
(request.url.scheme, request.url.host, request.url.path, request.headers.get("x-api-key"))
193193
)
194-
async with httpx.ASGITransport(app=provider_app) as local_provider:
194+
async with httpx2.ASGITransport(app=provider_app) as local_provider:
195195
return await local_provider.handle_async_request(request)
196196

197-
# Keep the real framework and Anthropic clients; replace only the network transport.
198-
monkeypatch.setattr(httpx.AsyncHTTPTransport, "handle_async_request", respond)
197+
# Keep the real framework and Anthropic clients; replace only the network transport. The
198+
# Anthropic SDK sends through httpx2 (pydantic's fork) since 1.x, not httpx, so that is the
199+
# transport to intercept; patching httpx here lets the request reach the real API.
200+
monkeypatch.setattr(httpx2.AsyncHTTPTransport, "handle_async_request", respond)
199201
monkeypatch.setenv("MANAGED_AGENT_TOKEN", TOKEN)
200202
monkeypatch.setenv("BOT_PROVIDER", "anthropic")
201203
monkeypatch.setenv("BOT_MODEL", "claude-sonnet-4-5")

0 commit comments

Comments
 (0)