Skip to content

test: extract shared _install_fake_browser_manager helper in test_cli.py - #308

Merged
dhruvbatra merged 1 commit into
mainfrom
claude/admiring-hawking-hps195
Aug 29, 2026
Merged

test: extract shared _install_fake_browser_manager helper in test_cli.py#308
dhruvbatra merged 1 commit into
mainfrom
claude/admiring-hawking-hps195

Conversation

@dhruvbatra

@dhruvbatra dhruvbatra commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

test_run_login_opens_headed_persistent_browser_and_saves_profile and test_run_login_exits_cleanly_when_browser_window_closes_first in tests/test_cli.py each hand-rolled an identical closure that patches cli.BrowserManager to build a fake manager and record it into a list, differing only in which FakeBrowserManager subclass (FakeBrowserManager vs ClosingFakeBrowserManager) they instantiate:

created_managers: list[FakeBrowserManager] = []

def _fake_browser_manager(*, config: BrowserConfig) -> FakeBrowserManager:
    manager = FakeBrowserManager(config=config)
    created_managers.append(manager)
    return manager

monkeypatch.setattr(cli, "BrowserManager", _fake_browser_manager)

Extracted a generic _install_fake_browser_manager(monkeypatch, manager_cls) helper (parametrized over the manager class via a bound TypeVar so each call site keeps its precise list[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_json for exactly this reason ("Shared by every _handle_* test that asserts on the JSON payload...").

Why safe

  • Test-only change, single file, no production code touched.
  • Pure mechanical extraction: same manager class per call site, same monkeypatch target, same returned list — behavior is unchanged.
  • Full suite: 326 passed / 21 pre-existing environment-only Chromium-sandbox failures (missing Chromium binary in this sandbox), identical before and after (verified via git stash A/B).
  • tests/test_cli.py alone: 23/23 passed.
  • ruff check src/ tests/: clean.
  • ruff format --check tests/test_cli.py flags the file, but this is pre-existing drift unrelated to this diff — reproduced identically on main via git stash, and ruff format --diff shows 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's AGENTS.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.py so the two async _run_login tests no longer duplicate the same monkeypatch.setattr(cli, "BrowserManager", ...) closure.

Adds _install_fake_browser_manager(monkeypatch, manager_cls), parameterized with a bound TypeVar so callers still get a correctly typed list of created fakes (FakeBrowserManager vs ClosingFakeBrowserManager). 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

  • Tests
    • Improved CLI login test coverage with reusable fake browser manager setup.
    • Simplified test configuration and verified browser manager instance creation consistently.

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.
@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 47e07f33-e744-445f-ba2f-cd6415947e2a

📥 Commits

Reviewing files that changed from the base of the PR and between eaea8f5 and c109a3b.

📒 Files selected for processing (1)
  • tests/test_cli.py

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The CLI test module adds a typed helper for patching cli.BrowserManager. Both login tests now use the helper with their respective fake manager classes.

Changes

CLI login test fixture refactor

Layer / File(s) Summary
Shared fake browser manager setup
tests/test_cli.py
Adds a typed helper that patches cli.BrowserManager, creates the requested fake manager class, and records instances. The two _run_login tests use the shared helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c109a

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: extracting the shared _install_fake_browser_manager helper in tests/test_cli.py.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/admiring-hawking-hps195

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@dhruvbatra
dhruvbatra merged commit 8dc7373 into main Aug 29, 2026
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants