fix(tests): use class-level AsyncHTTPHandler mock in vertex GPT-OSS tests#21428
fix(tests): use class-level AsyncHTTPHandler mock in vertex GPT-OSS tests#21428
Conversation
…ests Replace instance-level patch.object(client, "post", side_effect=...) with class-level patch of AsyncHTTPHandler and AsyncMock to reliably intercept HTTP calls in CI where real Google credentials are available. The old approach patched a specific instance's post method and passed client=client to acompletion(). In CI, the mock wasn't intercepting actual HTTP calls, causing 401 ACCESS_TOKEN_TYPE_UNSUPPORTED errors. The new approach patches AsyncHTTPHandler at the class level so any instance created internally by get_async_httpx_client() is also mocked. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes flaky CI failures in the Vertex AI GPT-OSS tests by switching from instance-level
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/gpt_oss/test_vertex_ai_gpt_oss_transformation.py | Switches to class-level AsyncHTTPHandler mock (matching reference pattern), but is missing the _reset_litellm_http_client_cache fixture that the reference test uses, which could cause test failures when cached HTTP clients bypass the mock. |
Flowchart
flowchart TD
A["test calls litellm.acompletion()"] --> B["VertexAIPartnerModels.completion()"]
B --> C["BaseLLMHTTPHandler.completion()"]
C --> D{client is None?}
D -->|Yes| E["get_async_httpx_client()"]
E --> F{Cached client exists?}
F -->|Yes - cache hit| G["Returns cached real client ⚠️"]
F -->|No - cache miss| H["AsyncHTTPHandler()"]
H --> I["Class-level mock intercepts ✅"]
I --> J["Mock returns fake response"]
G --> K["Real HTTP call - test may fail ❌"]
D -->|No - old approach| L["Uses passed client instance"]
Last reviewed commit: f0fc44c
Additional Comments (1)
The reference test file ( Here's why: the GPT-OSS code path calls Consider adding the same fixture used in |
Add _reset_litellm_http_client_cache autouse fixture (matching test_vertex_gemma_transformation.py) to flush in_memory_llm_clients_cache before each test. Without this, a cached real AsyncHTTPHandler from an earlier test could bypass the class-level mock and cause real HTTP calls. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@greptile-apps re-review this PR |
Greptile SummaryThis PR fixes flaky CI failures (
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/gpt_oss/test_vertex_ai_gpt_oss_transformation.py | Replaces fragile instance-level HTTP mock with class-level AsyncHTTPHandler patch, adds cache flush fixture, and removes client passthrough — matching the established pattern in test_vertex_gemma_transformation.py. No issues found. |
Flowchart
flowchart TD
A["Test calls litellm.acompletion()"] --> B["Class-level patch intercepts\nAsyncHTTPHandler construction"]
B --> C["_reset_litellm_http_client_cache\nflushes cached clients"]
C --> D["New AsyncHTTPHandler instance\ncreated internally"]
D --> E["mock_http_handler.return_value.post\nreturns AsyncMock response"]
E --> F["Test verifies URL, request body,\nand response structure"]
style B fill:#d4edda,stroke:#155724
style C fill:#d4edda,stroke:#155724
style E fill:#d4edda,stroke:#155724
Last reviewed commit: ea0cfac
Summary
test_vertex_ai_gpt_oss_simple_requestandtest_vertex_ai_gpt_oss_reasoning_effortCI failures with401 ACCESS_TOKEN_TYPE_UNSUPPORTEDpatch.object(client, "post", side_effect=...)with class-levelpatch("litellm.llms.custom_httpx.http_handler.AsyncHTTPHandler")andAsyncMockclient=clientargument fromlitellm.acompletion()calls so the internally-created handler is intercepted by the class-level mockRoot Cause
The original tests patched the
postmethod on a specificAsyncHTTPHandlerinstance and passedclient=clientthrough toacompletion(). In CI (where real Google credentials exist), the mock wasn't reliably intercepting HTTP calls, resulting in real requests toaiplatform.googleapis.comand401 ACCESS_TOKEN_TYPE_UNSUPPORTEDerrors.Fix
Follow the same pattern used in
test_vertex_gemma_transformation.py:AsyncHTTPHandlerat the class levelmock_http_handler.return_value.post = AsyncMock(return_value=mock_response)client=clienttoacompletion()— let the code create its own instance, which is intercepted by the class-level mockTest plan
test_vertex_ai_gpt_oss_transformation.pypass locally🤖 Generated with Claude Code