From c41562cf0ef2ef3b9a2c23eedd74b09294d2f888 Mon Sep 17 00:00:00 2001 From: Jan-Stefan Janetzky Date: Wed, 26 Aug 2026 14:49:08 +0200 Subject: [PATCH] fix(browser): pass encoding to detector subprocesses and accept local_browser in test spies The two default-browser detectors call subprocess.run(text=True) without an explicit encoding, which the Windows-footgun linter (and its full-repo test, tests/scripts/test_footgun_subprocess_encoding.py) rejects. Pass encoding='utf-8', errors='replace' like the rest of the tree. Two existing tests replace browser_navigate / _navigation_session_key with positional-only lambdas; both callables now receive local_browser= from the registry handler and browser_navigate, so the spies raised TypeError. Accept the keyword with its default. Fixes the three CI failures on the PR head (Windows footguns lint, test_browser_extension_router_wiring x2, test_browser_open_timeout). --- hermes_cli/browser_connect.py | 15 +++++++++++++-- .../tools/test_browser_extension_router_wiring.py | 6 +++++- tests/tools/test_browser_open_timeout.py | 4 +++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/hermes_cli/browser_connect.py b/hermes_cli/browser_connect.py index c3f2657d2b..25e4a5d91b 100644 --- a/hermes_cli/browser_connect.py +++ b/hermes_cli/browser_connect.py @@ -250,7 +250,14 @@ def _detect_default_darwin() -> str | None: ["defaults", "read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"], ): try: - out = subprocess.run(reader, capture_output=True, text=True, timeout=5).stdout.lower() + out = subprocess.run( + reader, + capture_output=True, + text=True, + encoding="utf-8", + errors="replace", + timeout=5, + ).stdout.lower() except Exception: out = "" for frag, browser in _DARWIN_BUNDLE_MAP: @@ -267,7 +274,11 @@ def _detect_default_linux() -> str | None: try: out = subprocess.run( ["xdg-settings", "get", "default-web-browser"], - capture_output=True, text=True, timeout=5, + capture_output=True, + text=True, + encoding="utf-8", + errors="replace", + timeout=5, ).stdout.strip().lower() except Exception: out = "" diff --git a/tests/tools/test_browser_extension_router_wiring.py b/tests/tools/test_browser_extension_router_wiring.py index bbdd4bf1be..8fb7e62869 100644 --- a/tests/tools/test_browser_extension_router_wiring.py +++ b/tests/tools/test_browser_extension_router_wiring.py @@ -36,7 +36,11 @@ def _route_spy(monkeypatch): monkeypatch.setattr(browser_tool, "routed_browser_handler", spy) monkeypatch.setattr(browser_cdp_tool, "routed_browser_handler", spy) - monkeypatch.setattr(browser_tool, "browser_navigate", lambda url="", task_id=None: "legacy-nav") + monkeypatch.setattr( + browser_tool, + "browser_navigate", + lambda url="", task_id=None, local_browser=False: "legacy-nav", + ) monkeypatch.setattr(browser_cdp_tool, "browser_cdp", lambda *a, **k: "legacy-cdp") return calls diff --git a/tests/tools/test_browser_open_timeout.py b/tests/tools/test_browser_open_timeout.py index 6d791ee282..570f8f9b6a 100644 --- a/tests/tools/test_browser_open_timeout.py +++ b/tests/tools/test_browser_open_timeout.py @@ -96,7 +96,9 @@ class TestBrowserNavigateOpenTimeout: monkeypatch.setattr(bt, "_is_camofox_mode", lambda: False) monkeypatch.setattr(bt, "_is_local_backend", lambda: True) monkeypatch.setattr(bt, "_is_local_sidecar_key", lambda key: False) - monkeypatch.setattr(bt, "_navigation_session_key", lambda task_id, url: task_id) + monkeypatch.setattr( + bt, "_navigation_session_key", lambda task_id, url, local_browser=False: task_id + ) monkeypatch.setattr(bt, "_maybe_start_recording", lambda *a, **kw: None) monkeypatch.setattr(bt, "check_website_access", lambda url: None)