test: extract shared assert_pending_close_task_runs_to_completion helper - #309
Conversation
test_mcp_server.py's close_runners_sync regression test and test_navigator_client.py's _schedule_close regression test each ended with an identical 9-line block asserting the same "task retained until it finishes, then released" invariant against their own module. Hoisted it to a single assert_pending_close_task_runs_to_completion helper in tests/fakes.py that both now call, matching this file's established convention of factoring out duplicated test scaffolding shared across files (assert_claim_result_payload_shape, noop_sleep, etc). Co-authored-by: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe change adds a shared async helper for pending close task assertions. The MCP server and navigator client tests use the helper instead of duplicating task lifecycle checks. ChangesPending close task assertions
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This test-only refactor centralizes an existing regression assertion without changing production behavior; no actionable merge-blocking risk remains after normal checks and review. Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Issue
test_mcp_server.py::test_close_runners_sync_holds_strong_reference_until_task_completesandtest_navigator_client.py::test_schedule_close_holds_strong_reference_until_task_completeseach end with a byte-identical 9-line block asserting the same "the task must be retained in_pending_close_tasksuntil it finishes, then released" regression-guard invariant — differing only in which module (mcp_servervsnavigator_client) they check.Found via a fresh AST sliding-window duplicate scan across all
tests/*.py(same technique that found PRs #307 and #308 earlier today), which flagged this as the only cross-file duplicate — most other matches were same-file or too small/coincidental to be worth extracting.Fix
Hoisted the block to a single
assert_pending_close_task_runs_to_completion(module, release, closed)async helper intests/fakes.py(the file both test modules already treat as shared scaffolding), and had both tests call it. This matches the file's established convention of factoring out duplicated test scaffolding (assert_claim_result_payload_shape,noop_sleep,import_or_skip, etc.) that PRs #307/#308 also followed today.Why it's safe
uv run pytest tests/before and after: 326 passed, same 21 pre-existing environment-only Chromium-sandbox failures (verified unchanged by diffing full test output pre/post-change).uv run ruff check src/ tests/clean;uv run ruff format --checkon the 3 changed files reports "already formatted" (the 7 files flagged by a full-tree format-check are pre-existing and unrelated — reproduced identically on agit stashof this change).Co-authored-by: Claude noreply@anthropic.com
Generated by Claude Code
Note
Low Risk
Test-only refactor with verbatim logic moved to a shared helper; no production code changes.
Overview
Deduplicates identical regression-guard tails in the MCP server and navigator client tests by moving them into
assert_pending_close_task_runs_to_completionintests/fakes.py.That helper still drives the same async close scenario: yield so the background task blocks on an event, assert the module keeps exactly one entry in
_pending_close_tasks, release the event, await the retained task, then assert cleanup ran and the pending set is empty.test_close_runners_sync_holds_strong_reference_until_task_completesandtest_schedule_close_holds_strong_reference_until_task_completesnow call it instead of inlining the block;fakes.pyadds theasyncioimport the helper needs.Reviewed by Cursor Bugbot for commit 14513ef. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit