fix(test): mock get_auth_header instead of get_api_key in anthropic file content test#24258
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a test regression in Key changes:
Remaining concern:
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/llms/anthropic/test_anthropic_files_and_batches.py | Fixes test_afile_content_missing_api_key to mock get_auth_header (what the handler now calls) instead of get_api_key. The targeted fix is correct, but a sibling test (test_afile_content_mixed_results) still carries a now-dead get_api_key mock at line 306 that should also be updated. |
Sequence Diagram
sequenceDiagram
participant Test
participant Handler as afile_content
participant ModelInfo as AnthropicModelInfo
participant HTTP as httpx client
Note over Test,HTTP: After fix — mock intercepts correctly
Test->>Handler: afile_content(file_id, no credentials)
Handler->>ModelInfo: get_auth_header() [mocked to return None]
ModelInfo-->>Handler: None
Handler-->>Test: raises ValueError ✅
Note over Test,HTTP: Before fix — mock was bypassed
Test->>Handler: afile_content(file_id, no credentials)
Handler->>ModelInfo: get_auth_header() [NOT mocked, get_api_key was]
ModelInfo-->>Handler: reads env vars
Handler-->>HTTP: real outbound request to Anthropic — returns 400 ❌
Comments Outside Diff (1)
-
tests/test_litellm/llms/anthropic/test_anthropic_files_and_batches.py, line 306 (link)Dead mock left over from the same refactor
This test still patches
get_api_keyon theanthropic_model_infoinstance, but after commitf415b72bthe handler callsget_auth_header(...)instead, so this patch has no effect. The test still passes because the caller passes the credential explicitly as an argument, which flows through the realget_auth_headerimplementation and produces a valid header without any mocking.The dead mock is misleading: a future reader would reasonably believe it is what authorizes the HTTP call. To match the fix applied in
test_afile_content_missing_api_key, this mock should be updated to patchget_auth_headerwith a non-Nonereturn value instead.
Last reviewed commit: "fix(test): mock get_..."
Summary
Fixes a regression introduced by f415b72 which added
get_auth_headerto the handler. The test was mockingget_api_keybut the handler now callsget_auth_headerdirectly, causing the mock to be bypassed — resulting in a real HTTP request to Anthropic and a 400 instead of the expectedValueError.Root Cause
get_api_keyf415b72bchanged handler to callget_auth_headerinsteadapi.anthropic.com, got 400Fix
Mock
get_auth_headerdirectly since that's what the handler calls to gate on missing credentials.