Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions tests/tools/test_browser_cdp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,33 +379,35 @@ def test_dispatch_through_registry(cdp_server):


def test_check_fn_false_when_no_cdp_url(monkeypatch):
"""Gate closes when no CDP URL is set — even if the browser toolset is
otherwise configured."""
"""Gate closes when no CDP URL is configured."""
import tools.browser_tool as bt

monkeypatch.setattr(bt, "check_browser_requirements", lambda: True)
monkeypatch.setattr(bt, "_get_cdp_override", lambda: "")
assert browser_cdp_tool._browser_cdp_check() is False


def test_check_fn_true_when_cdp_url_set(monkeypatch):
"""Gate opens as soon as a CDP URL is resolvable."""
"""Gate opens as soon as a CDP URL is resolvable, regardless of agent-browser."""
import tools.browser_tool as bt

monkeypatch.setattr(bt, "check_browser_requirements", lambda: True)
monkeypatch.setattr(
bt, "_get_cdp_override", lambda: "ws://localhost:9222/devtools/browser/x"
)
assert browser_cdp_tool._browser_cdp_check() is True


def test_check_fn_false_when_browser_requirements_fail(monkeypatch):
"""Even with a CDP URL, gate closes if the overall browser toolset is
unavailable (e.g. agent-browser not installed)."""
def test_check_fn_true_when_cdp_url_set_but_agent_browser_missing(monkeypatch):
"""CDP URL alone is sufficient — agent-browser CLI is not required."""
import tools.browser_tool as bt

monkeypatch.setattr(bt, "check_browser_requirements", lambda: False)
monkeypatch.setattr(
bt, "_get_cdp_override", lambda: "ws://localhost:9222/devtools/browser/x"
)

Copilot AI Apr 26, 2026

Copy link

Choose a reason for hiding this comment

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

The new test test_check_fn_true_when_cdp_url_set_but_agent_browser_missing doesn’t actually simulate agent-browser being missing (it only patches _get_cdp_override, same as the previous test). To make this a real regression guard, patch bt.check_browser_requirements (or _find_agent_browser) to raise/return False and assert _browser_cdp_check() still returns True, or remove/merge this test to avoid redundant coverage.

Suggested change
)
)
def _unexpected_browser_check():
raise AssertionError(
"check_browser_requirements should not be needed when CDP URL is set"
)
monkeypatch.setattr(bt, "check_browser_requirements", _unexpected_browser_check)

Copilot uses AI. Check for mistakes.
assert browser_cdp_tool._browser_cdp_check() is False

def _unexpected_browser_check():
raise AssertionError(
"check_browser_requirements should not be needed when CDP URL is set"
)

monkeypatch.setattr(bt, "check_browser_requirements", _unexpected_browser_check)
assert browser_cdp_tool._browser_cdp_check() is True
7 changes: 1 addition & 6 deletions tools/browser_cdp_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,10 @@ def _browser_cdp_check() -> bool:
``registry.register(...)`` calls).
"""
try:
from tools.browser_tool import ( # type: ignore[import-not-found]
_get_cdp_override,
check_browser_requirements,
)
from tools.browser_tool import _get_cdp_override # type: ignore[import-not-found]
except ImportError as exc: # pragma: no cover — defensive
logger.debug("browser_cdp check: browser_tool import failed: %s", exc)
return False
if not check_browser_requirements():
return False
return bool(_get_cdp_override())


Expand Down
Loading