fix(browser): avoid eager agent-browser probe - #54366
Conversation
|
Ran the test suite for this PR with a real However, running the existing browser tests against this branch surfaced a regression. Switching Affected tests:
The fix is to make those stubs tolerate the new keyword arg ( diff --git a/tests/tools/test_browser_chromium_check.py b/tests/tools/test_browser_chromium_check.py
@@ class TestCheckBrowserRequirementsChromium:
def test_local_mode_with_chromium_returns_true(self, monkeypatch, tmp_path):
monkeypatch.setattr(bt, "_is_camofox_mode", lambda: False)
- monkeypatch.setattr(bt, "_find_agent_browser", lambda: "/usr/local/bin/agent-browser")
+ monkeypatch.setattr(bt, "_find_agent_browser", lambda *a, **k: "/usr/local/bin/agent-browser")
@@ class TestCheckBrowserRequirementsChromium:
monkeypatch.setattr(bt, "_is_camofox_mode", lambda: False)
- monkeypatch.setattr(bt, "_find_agent_browser", lambda: "/usr/local/bin/agent-browser")
+ monkeypatch.setattr(bt, "_find_agent_browser", lambda *a, **k: "/usr/local/bin/agent-browser")
diff --git a/tests/tools/test_browser_homebrew_paths.py b/tests/tools/test_browser_homebrew_paths.py
@@ class TestBrowserRequirements:
def test_cdp_override_does_not_require_agent_browser_cli(self, monkeypatch):
monkeypatch.setenv("BROWSER_CDP_URL", "ws://127.0.0.1:9222/devtools/browser/test")
monkeypatch.setattr("tools.browser_tool._is_camofox_mode", lambda: False)
- monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda: (_ for _ in ()).throw(FileNotFoundError("not found")))
+ monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda *a, **k: (_ for _ in ()).throw(FileNotFoundError("not found")))
@@ class TestBrowserRequirements:
monkeypatch.setattr("tools.browser_tool._get_cloud_provider", lambda: None)
- monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda: "npx agent-browser")
+ monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda *a, **k: "npx agent-browser")
@@ class TestRunBrowserCommandTermuxFallback:
def test_termux_local_mode_rejects_bare_npx_fallback(self, monkeypatch):
monkeypatch.setenv("PREFIX", "/data/data/com.termux/files/usr")
- monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda: "npx agent-browser")
+ monkeypatch.setattr("tools.browser_tool._find_agent_browser", lambda *a, **k: "npx agent-browser")
monkeypatch.setattr("tools.browser_tool._get_cloud_provider", lambda: None)(The CDP-override and |
check_browser_requirements() now calls _find_agent_browser(validate=False), but three existing tests monkeypatch _find_agent_browser with a zero-arg lambda, so they fail with TypeError: <lambda>() got an unexpected keyword argument 'validate'. Widen the stubs to lambda *a, **k: so they tolerate the new signature. Brings the browser suite from 7 failed to 4 failed (the remaining 4 are pre-existing env-only failures unrelated to this PR).
|
Pushed this stub fix directly to the branch as |
|
Closing as superseded by #54417. The browser eager-probe fix from this PR has landed on main as part of #54417: Thanks for narrowing this down — this PR/report directly matched one of the follow-up legs. |
Summary
agent-browser --versionduring browser tool availability checks.Root cause
Desktop startup builds the agent tool list, which evaluates tool
check_fns. The browsercheck_fncalled_find_agent_browser(), and that path validated candidates by executingagent-browser --version. On Windows, resolving the local npm.CMDshim runs throughcmd.exe, causing a visible console flash during desktop startup even though the user did not invoke a browser tool.Changes
validateparameter to_find_agent_browser().validate=Falsefromcheck_browser_requirements()so tool-list assembly remains side-effect-free.validate=Trueas the default for real browser execution paths, including revalidating a candidate cached by a lightweight probe.Closes #54364.
Testing
python -m py_compile tools/browser_tool.py tests/tools/test_browser_agent_browser_probe.pygit diff --checkcheck_browser_requirements()does not callagent_browser_runnable().validate=Falseis still validated when_find_agent_browser(validate=True)is called.Note:
pytestis not installed in the available local Python environments on this Windows machine, so the new pytest file was syntax-checked and the equivalent assertions were run manually without installing packages.Risk
Low. The behavior change only affects availability probing. Real browser command execution still validates the executable before use, so stale/broken npm shims are not silently accepted.