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).
This commit is contained in:
Jan-Stefan Janetzky
2026-08-26 14:49:08 +02:00
committed by Teknium
parent 830e4a29be
commit c41562cf0e
3 changed files with 21 additions and 4 deletions

View File

@@ -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 = ""

View File

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

View File

@@ -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)