[Fix] Update Outdated test_responses_background_cost Assertions - #23589
Conversation
…ation and stale cleanup Tests were outdated after #23472 added pagination (take/order) to find_many and stale-row cleanup via update_many. Updated assertions to match new call signatures. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR updates 4 pre-existing unit tests in Changes made:
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| tests/test_litellm/integrations/test_responses_background_cost.py | Updated 4 tests in TestCheckResponsesCost to account for pagination params on find_many and the extra update_many call from _cleanup_stale_managed_objects; filter logic correctly distinguishes stale-cleanup calls (no "id" key in where) from completion calls (has "id" key in where). |
Sequence Diagram
sequenceDiagram
participant Test
participant CheckResponsesCost
participant DB as litellm_managedobjecttable
participant LiteLLM
Test->>CheckResponsesCost: check_responses_cost()
Note over CheckResponsesCost,DB: Stale cleanup (always runs)
CheckResponsesCost->>DB: update_many(where={file_purpose, status, created_at}, data={status: stale_expired})
DB-->>CheckResponsesCost: count
Note over CheckResponsesCost,DB: Paginated fetch
CheckResponsesCost->>DB: find_many(where={status: [queued, in_progress], file_purpose: response}, take=MAX_OBJECTS_PER_POLL_CYCLE, order={created_at: asc})
DB-->>CheckResponsesCost: jobs[]
loop For each job
CheckResponsesCost->>LiteLLM: aget_responses(response_id)
LiteLLM-->>CheckResponsesCost: response (status: completed/failed/in_progress/...)
end
alt Terminal jobs exist (completed/failed/cancelled)
Note over CheckResponsesCost,DB: Completion update (id-keyed)
CheckResponsesCost->>DB: update_many(where={id: {in: [job_ids]}}, data={status: completed})
end
Last reviewed commit: 3aeca22
| # Verify job was marked as completed even though it failed | ||
| mock_prisma_client.db.litellm_managedobjecttable.update_many.assert_called_once() | ||
| # (stale cleanup also calls update_many, so check the specific completion call) | ||
| update_many_calls = mock_prisma_client.db.litellm_managedobjecttable.update_many.call_args_list | ||
| completion_calls = [ | ||
| c for c in update_many_calls | ||
| if c.kwargs.get("where", {}).get("id") is not None | ||
| ] | ||
| assert len(completion_calls) == 1 |
There was a problem hiding this comment.
Missing argument assertions for failed-job completion call
test_check_responses_cost_with_failed_job now only verifies that exactly one completion update_many call occurred (len(completion_calls) == 1), but does not assert what the call was made with. The parallel test for a completed job (test_check_responses_cost_with_completed_job) was updated to check both where.id.in and data.status. For consistency and to guard against regressions, consider adding the same argument checks here:
| # Verify job was marked as completed even though it failed | |
| mock_prisma_client.db.litellm_managedobjecttable.update_many.assert_called_once() | |
| # (stale cleanup also calls update_many, so check the specific completion call) | |
| update_many_calls = mock_prisma_client.db.litellm_managedobjecttable.update_many.call_args_list | |
| completion_calls = [ | |
| c for c in update_many_calls | |
| if c.kwargs.get("where", {}).get("id") is not None | |
| ] | |
| assert len(completion_calls) == 1 | |
| assert len(completion_calls) == 1 | |
| assert completion_calls[0].kwargs["where"]["id"]["in"] == ["job-456"] | |
| assert completion_calls[0].kwargs["data"]["status"] == "completed" |
85e5ef4
into
litellm_internal_dev_03_12_2026
…ackground_cost_tests [Fix] Update Outdated test_responses_background_cost Assertions
Relevant issues
Related to #23472
Summary
Problem
PR #23472 added pagination (
take/orderparams) tofind_manyand stale-row cleanup (update_manyforstale_expired) inCheckResponsesCost, but did not update 4 pre-existing tests that assert the old call signatures.Fix
Updated test assertions to account for the new pagination params on
find_manyand the additionalupdate_manycall from stale cleanup. Tests now filterupdate_manycalls to distinguish stale cleanup from completion updates.Testing
All 4 previously failing tests now pass with the updated assertions.
Type
✅ Test