[Fix] Update check_responses_cost tests for _expire_stale_rows - #25299
Conversation
PR #25258 changed _cleanup_stale_managed_objects from update_many to execute_raw via _expire_stale_rows, but the tests were not updated. The tests now mock _expire_stale_rows on the instance and assert update_many calls only for job completion, not stale cleanup.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes 8 broken unit tests in
Confidence Score: 5/5Safe to merge — test-only fix that correctly aligns assertions with the actual implementation, with a single minor validation gap. All changes are test-only and directly fix broken CI caused by a prior implementation change. Coverage is maintained or improved: stale-cleanup behavior is now tested via _expire_stale_rows assertions rather than indirectly through update_many counts. The only finding is a P2 style suggestion to also validate the cutoff datetime type, which does not block merge. tests/proxy_unit_tests/test_check_responses_cost.py — minor: consider asserting isinstance(cutoff, datetime) and cutoff.tzinfo is not None in test_cleanup_stale_managed_objects
|
| Filename | Overview |
|---|---|
| tests/proxy_unit_tests/test_check_responses_cost.py | Test suite correctly updated to reflect _expire_stale_rows replacing update_many for stale cleanup; call counts and assertions aligned with the new raw-SQL implementation. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[check_responses_cost called] --> B[_cleanup_stale_managed_objects]
B --> C[_expire_stale_rows\nraw SQL UPDATE via execute_raw]
C -->|rows marked stale_expired| D[find_many: queued / in_progress jobs]
D --> E{Any jobs?}
E -->|No| Z[Done]
E -->|Yes| F[Loop: aget_responses per job]
F --> G{Terminal status?}
G -->|completed / failed / cancelled| H[Add to completed_jobs]
G -->|in_progress / queued| I[Skip job]
H --> J{completed_jobs > 0?}
J -->|Yes| K[update_many: status = completed]
J -->|No| Z
K --> Z
Reviews (1): Last reviewed commit: "fix(test): update check_responses_cost t..." | Re-trigger Greptile
| # _expire_stale_rows should have been called with a cutoff datetime and batch size | ||
| check_responses_cost_instance._expire_stale_rows.assert_called_once() | ||
| call_args = check_responses_cost_instance._expire_stale_rows.call_args | ||
| assert call_args[0][1] == STALE_OBJECT_CLEANUP_BATCH_SIZE |
There was a problem hiding this comment.
Cutoff datetime argument not validated
The test verifies that _expire_stale_rows is called with the correct batch_size (second positional arg), but never asserts anything about the cutoff argument (first positional arg). A regression where a non-datetime value (e.g. a plain string or None) is passed instead of a timezone-aware datetime would go completely undetected.
Consider also asserting the type and timezone-awareness of the cutoff:
| # _expire_stale_rows should have been called with a cutoff datetime and batch size | |
| check_responses_cost_instance._expire_stale_rows.assert_called_once() | |
| call_args = check_responses_cost_instance._expire_stale_rows.call_args | |
| assert call_args[0][1] == STALE_OBJECT_CLEANUP_BATCH_SIZE | |
| # _expire_stale_rows should have been called with a cutoff datetime and batch size | |
| check_responses_cost_instance._expire_stale_rows.assert_called_once() | |
| call_args = check_responses_cost_instance._expire_stale_rows.call_args | |
| assert isinstance(call_args[0][0], datetime) | |
| assert call_args[0][0].tzinfo is not None # must be timezone-aware | |
| assert call_args[0][1] == STALE_OBJECT_CLEANUP_BATCH_SIZE |
Rule Used: What: Flag any modifications to existing tests and... (source)
…nses_cost_tests [Fix] Update check_responses_cost tests for _expire_stale_rows
Summary
Problem
PR #25258 changed
_cleanup_stale_managed_objectsfrom using Prisma'supdate_manyto raw SQL via a new_expire_stale_rowsmethod, but the tests were not updated. This caused all 8 tests intest_check_responses_cost.pyto fail in theauth-and-jwtCI job because:execute_rawwas auto-generated as aMagicMock(notAsyncMock), causingawaitto failupdate_manycall counts didn't match expectationsFix
_expire_stale_rowsasAsyncMockon the fixture instance so_cleanup_stale_managed_objectssucceeds without a real DBtest_cleanup_stale_managed_objectsto verify_expire_stale_rowsis called with the correct batch sizeupdate_manycall count assertions: stale cleanup no longer goes throughupdate_many, so terminal-state tests expect 1 call (not 2) and non-terminal tests expect 0 calls (not 1)Testing
All 10 tests in
test_check_responses_cost.pyshould now pass with the current_expire_stale_rowsimplementation on main.Type
🐛 Bug Fix
✅ Test