From b731272037e5e42d7920e91234afdce0b5dc9066 Mon Sep 17 00:00:00 2001 From: Dylan Pulver Date: Sat, 18 Jul 2026 01:09:42 -0400 Subject: [PATCH] feat(admin): BU_NO_OPEN suppresses liveUrl auto-open For unattended/audit runs, auto-opening the cloud browser's liveUrl in the local default browser is an unwanted popup that steals focus. BU_NO_OPEN skips the auto-open (URL is still printed). Enables fully off-machine, no-local-window browser automation. Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01SY7iBojYKGTdNTS78GKZSZ --- src/browser_harness/admin.py | 6 +++--- tests/unit/test_admin.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/browser_harness/admin.py b/src/browser_harness/admin.py index bdcf5d28..18ca964d 100644 --- a/src/browser_harness/admin.py +++ b/src/browser_harness/admin.py @@ -391,12 +391,12 @@ def _has_local_gui(): def _show_live_url(url): - """Print liveUrl and auto-open it locally if there's a GUI.""" + """Print liveUrl and auto-open it locally if there's a GUI (unless BU_NO_OPEN).""" import sys, webbrowser if not url: return print(url) - if not _has_local_gui(): - print("(no local GUI — share the liveUrl with the user)", file=sys.stderr) + if os.environ.get("BU_NO_OPEN") or not _has_local_gui(): + print("(liveUrl not auto-opened — share it with the user)", file=sys.stderr) return try: webbrowser.open(url, new=2) diff --git a/tests/unit/test_admin.py b/tests/unit/test_admin.py index 06ec751c..27414774 100644 --- a/tests/unit/test_admin.py +++ b/tests/unit/test_admin.py @@ -527,3 +527,20 @@ def test_process_start_time_returns_none_for_invalid_pid(): ) # 2**31 - 1 is the largest pid_t; in practice no live process at that PID. assert admin._process_start_time((1 << 31) - 1) is None + + +def test_show_live_url_bu_no_open_suppresses_auto_open(monkeypatch): + """BU_NO_OPEN keeps _show_live_url from popping a local tab (still prints the URL).""" + import webbrowser + + monkeypatch.setattr(admin, "_has_local_gui", lambda: True) + calls = [] + monkeypatch.setattr(webbrowser, "open", lambda *a, **k: calls.append(a)) + + monkeypatch.setenv("BU_NO_OPEN", "1") + admin._show_live_url("https://example.com/live") + assert calls == [], "BU_NO_OPEN should suppress the auto-open" + + monkeypatch.delenv("BU_NO_OPEN") + admin._show_live_url("https://example.com/live") + assert calls, "without BU_NO_OPEN it should auto-open when a GUI is present"