Skip to content

fix: run playwright preflight via current python#281

Open
voidborne-d wants to merge 1 commit intoteng-lin:mainfrom
voidborne-d:fix/playwright-preflight-current-python
Open

fix: run playwright preflight via current python#281
voidborne-d wants to merge 1 commit intoteng-lin:mainfrom
voidborne-d:fix/playwright-preflight-current-python

Conversation

@voidborne-d
Copy link
Copy Markdown
Contributor

@voidborne-d voidborne-d commented Apr 14, 2026

Summary

  • run Chromium pre-flight checks via instead of a bare binary
  • keep the auto-install path on the same interpreter and update the manual fallback hint
  • add regression coverage for both dry-run and install commands

Testing

  • .................................................................... [100%]
    68 passed in 0.38s

Closes #278.

Summary by CodeRabbit

  • Bug Fixes

    • Improved Chromium installation process to use the current Python interpreter for better compatibility and reliability.
    • Enhanced error messages to provide clearer guidance when installation issues occur.
  • Tests

    • Added comprehensive test coverage for the Chromium installation preflight checks.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 14, 2026

📝 Walkthrough

Walkthrough

Updated Playwright invocation to use sys.executable -m playwright instead of the bare playwright CLI command, ensuring the tool works in virtual environments where the entry point isn't on PATH. New tests verify both the dry-run preflight and actual installation use the correct Python interpreter.

Changes

Cohort / File(s) Summary
Chromium installation check
src/notebooklm/cli/session.py
Modified _ensure_chromium_installed() to invoke Playwright via the current Python interpreter using [sys.executable, "-m", "playwright"] instead of bare ["playwright"]. Updated error message to include the full command. Simplified exception handling comments to reflect general pre-flight failure.
Installation pre-flight tests
tests/unit/cli/test_session.py
Added TestChromiumPreflight test class with coverage for _ensure_chromium_installed(), mocking subprocess.run to verify both the dry-run preflight and actual install invocations use sys.executable with the correct command arguments.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 With whiskers twitched and paws all set,
No more PATH shall cause us fret!
Python's own interpreter we call,
Now Playwright works in virtualenvs all!
Hopping through environments, joyful and free, 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and concisely describes the main fix: changing Playwright invocation to use the current Python interpreter.
Linked Issues check ✅ Passed The PR fully implements the proposed fix from issue #278 by replacing bare 'playwright' with [sys.executable, '-m', 'playwright'] in both dry-run and install commands, and adds regression test coverage.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the Playwright preflight invocation issue and adding corresponding test coverage with no extraneous modifications.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the Playwright browser installation logic to use the current Python interpreter via sys.executable -m playwright, ensuring compatibility with virtual environments and pipx. It also includes new unit tests to verify the command execution. The review feedback suggests improving the user experience by allowing installation progress to be visible in the console and ensuring the Python executable path is quoted in error messages to handle paths containing spaces.

Comment on lines 323 to 327
install_result = subprocess.run(
["playwright", "install", "chromium"],
[*playwright_cmd, "install", "chromium"],
capture_output=True,
text=True,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Capturing output for the actual installation command prevents the user from seeing the progress bar and any detailed error messages from Playwright. Since this command can take a significant amount of time to download the browser binaries, it's better to let the output flow to the console so the user can monitor the progress.

        install_result = subprocess.run(
            [*playwright_cmd, "install", "chromium"],
        )

console.print(
"[red]Failed to install Chromium browser.[/red]\n"
"Run manually: playwright install chromium"
f"Run manually: {sys.executable} -m playwright install chromium"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If the path to the Python executable contains spaces (which is common on Windows, e.g., in C:\Program Files\...), the suggested manual command will fail when copy-pasted. Wrapping the executable path in quotes ensures it remains a single argument.

Suggested change
f"Run manually: {sys.executable} -m playwright install chromium"
f"Run manually: \"{sys.executable}\" -m playwright install chromium"

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/unit/cli/test_session.py (1)

85-99: Consider asserting the full call sequence in the install-path test.

Right now the second test checks only positional argv content. Asserting the exact two calls (including kwargs) would catch regressions in invocation flags too.

Proposed tightening for this test
-from unittest.mock import AsyncMock, MagicMock, patch
+from unittest.mock import AsyncMock, MagicMock, call, patch
@@
-        assert mock_run.call_args_list[0].args[0] == [
-            sys.executable,
-            "-m",
-            "playwright",
-            "install",
-            "--dry-run",
-            "chromium",
-        ]
-        assert mock_run.call_args_list[1].args[0] == [
-            sys.executable,
-            "-m",
-            "playwright",
-            "install",
-            "chromium",
-        ]
+        assert mock_run.call_args_list == [
+            call(
+                [sys.executable, "-m", "playwright", "install", "--dry-run", "chromium"],
+                capture_output=True,
+                text=True,
+            ),
+            call(
+                [sys.executable, "-m", "playwright", "install", "chromium"],
+                capture_output=True,
+                text=True,
+            ),
+        ]
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/cli/test_session.py` around lines 85 - 99, Update the install-path
test to assert the complete sequence of mock_run calls (including kwargs)
instead of only positional argv for the second call: inspect
mock_run.call_args_list and compare both entries to the exact expected call
tuples/dicts so you verify both args and kwargs; use the existing mock_run
reference and assert mock_run.call_args_list == [call([...], **{...}),
call([...], **{...})] (or equivalent explicit comparisons) to lock down
invocation flags and prevent regressions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/unit/cli/test_session.py`:
- Around line 85-99: Update the install-path test to assert the complete
sequence of mock_run calls (including kwargs) instead of only positional argv
for the second call: inspect mock_run.call_args_list and compare both entries to
the exact expected call tuples/dicts so you verify both args and kwargs; use the
existing mock_run reference and assert mock_run.call_args_list == [call([...],
**{...}), call([...], **{...})] (or equivalent explicit comparisons) to lock
down invocation flags and prevent regressions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d95fd19d-5c2a-4b79-bbe1-075da50eade0

📥 Commits

Reviewing files that changed from the base of the PR and between a997718 and 310b4b5.

📒 Files selected for processing (2)
  • src/notebooklm/cli/session.py
  • tests/unit/cli/test_session.py

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.

login: Playwright pre-flight check fails when CLI is not on PATH (virtualenv/pipx)

1 participant