Skip to content
Open
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
6 changes: 3 additions & 3 deletions src/browser_harness/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions tests/unit/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"