test: extract shared _install_fake_browser_manager helper in test_cli.py - #308
Conversation
test_run_login_opens_headed_persistent_browser_and_saves_profile and test_run_login_exits_cleanly_when_browser_window_closes_first each hand-rolled an identical closure that patches cli.BrowserManager to build a fake manager and record it, differing only in which FakeBrowserManager subclass they instantiate. Extracted a generic _install_fake_browser_manager(monkeypatch, manager_cls) helper, matching this file's established convention of factoring out duplicated test scaffolding (e.g. _capture_emitted_json, _verify_args). Test-only, no behavior change.
|
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 (1)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe CLI test module adds a typed helper for patching ChangesCLI login test fixture refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change consolidates duplicated setup in two CLI tests without changing production behavior; no actionable merge-blocking risk remains after normal checks and review. 🚥 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 |
Summary
test_run_login_opens_headed_persistent_browser_and_saves_profileandtest_run_login_exits_cleanly_when_browser_window_closes_firstintests/test_cli.pyeach hand-rolled an identical closure that patchescli.BrowserManagerto build a fake manager and record it into a list, differing only in whichFakeBrowserManagersubclass (FakeBrowserManagervsClosingFakeBrowserManager) they instantiate:Extracted a generic
_install_fake_browser_manager(monkeypatch, manager_cls)helper (parametrized over the manager class via a boundTypeVarso each call site keeps its preciselist[FakeBrowserManager]/list[ClosingFakeBrowserManager]typing) and had both tests delegate to it.This matches this file's own established convention of factoring out duplicated test-arrange scaffolding — it already has
_capture_emitted_jsonfor exactly this reason ("Shared by every_handle_*test that asserts on the JSON payload...").Why safe
git stashA/B).tests/test_cli.pyalone: 23/23 passed.ruff check src/ tests/: clean.ruff format --check tests/test_cli.pyflags the file, but this is pre-existing drift unrelated to this diff — reproduced identically onmainviagit stash, andruff format --diffshows every hunk sits on lines this PR didn't touch (long import/signature lines the installed ruff version now wants to wrap). Per this repo'sAGENTS.md, existing files are not reformatted unless explicitly asked.🤖 Generated with Claude Code
Generated by Claude Code
Note
Low Risk
Test-only refactor with no production code changes; behavior of the login CLI tests is unchanged.
Overview
Refactors
tests/test_cli.pyso the two async_run_logintests no longer duplicate the samemonkeypatch.setattr(cli, "BrowserManager", ...)closure.Adds
_install_fake_browser_manager(monkeypatch, manager_cls), parameterized with a boundTypeVarso callers still get a correctly typed list of created fakes (FakeBrowserManagervsClosingFakeBrowserManager). Both tests now call that helper instead of inlining list + factory + patch setup, matching the file’s existing pattern (e.g._capture_emitted_json).Reviewed by Cursor Bugbot for commit c109a3b. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by CodeRabbit