From 0546590feba8eba19ac8e2f164922dc8cc2e50ea Mon Sep 17 00:00:00 2001 From: Adekunes <107763438+Adekunes@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:44:39 -0400 Subject: [PATCH 1/2] test(run): isolate cloud-bootstrap tests from ambient BU_* env test_cloud_bootstrap_on_headless_server failed on any box that exports BU_CDP_URL (a running local Chrome debug endpoint): run.main()'s bootstrap guard reads process env directly, so the ambient value made _explicit_cdp_configured() true and suppressed the start_remote_daemon call the test asserts on. Add an autouse fixture that clears BROWSER_USE_API_KEY, BU_AUTOSPAWN, BU_CDP_URL and BU_CDP_WS before each test, so every test starts from a clean slate and sets only the vars it needs. Also hardens the non-cloud tests, which would otherwise fire the real start_remote_daemon on a box exporting BU_AUTOSPAWN + key. Source logic was correct; only the test's env assumption was stale. Co-Authored-By: Claude Opus 4.8 --- tests/unit/test_run.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit/test_run.py b/tests/unit/test_run.py index ec3ef95e..dadccbce 100644 --- a/tests/unit/test_run.py +++ b/tests/unit/test_run.py @@ -7,6 +7,20 @@ from browser_harness import run +@pytest.fixture(autouse=True) +def _isolate_browser_env(monkeypatch): + """run.main()'s cloud-bootstrap guard reads process env directly + (BROWSER_USE_API_KEY, BU_AUTOSPAWN, BU_CDP_URL, BU_CDP_WS). A dev box or CI + runner that exports any of these leaks it into every test — e.g. an ambient + BU_CDP_URL (a running local Chrome debug endpoint) makes + _explicit_cdp_configured() true and silently blocks the bootstrap these + tests assert on, and an ambient BU_AUTOSPAWN + key would fire the real + start_remote_daemon in tests that don't mock it. Start every test from a + clean slate; tests that need a var set it themselves.""" + for var in ("BROWSER_USE_API_KEY", "BU_AUTOSPAWN", "BU_CDP_URL", "BU_CDP_WS"): + monkeypatch.delenv(var, raising=False) + + def test_stdin_executes_code(): stdout = StringIO() fake_stdin = StringIO("print('hello from stdin')") From aa4e15a4a4f73001703f07c525ec1339953e2007 Mon Sep 17 00:00:00 2001 From: Adekunes <107763438+Adekunes@users.noreply.github.com> Date: Mon, 20 Jul 2026 16:47:00 -0400 Subject: [PATCH 2/2] build: add pytest to a dev dependency-group for faster test runs Tests were being run via `uv run --with pytest pytest`, which layers pytest into a fresh ephemeral overlay venv on every cold uv cache (~2.8s) instead of the persistent project env (~0.5s). Declaring pytest in the default `dev` group lets `uv run pytest ...` resolve it from the synced project env, so repeat runs stay sub-second. uv.lock is gitignored, so only pyproject changes. Co-Authored-By: Claude Opus 4.8 --- pyproject.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 6a33d071..72b1a383 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,14 @@ Homepage = "https://github.com/browser-use/browser-harness" Repository = "https://github.com/browser-use/browser-harness" Issues = "https://github.com/browser-use/browser-harness/issues" +# Dev tooling lives in the default `dev` group so `uv run pytest` resolves it +# from the persistent project env. Running `uv run --with pytest pytest` instead +# builds a fresh ephemeral overlay venv on every cold cache (~2.8s vs ~0.5s). +[dependency-groups] +dev = [ + "pytest>=8", +] + [tool.setuptools] package-dir = {"" = "src"}