From ce0a7d9490c7fff3dbae41a2f89705f79f88c353 Mon Sep 17 00:00:00 2001 From: Tejas Chopra Date: Thu, 30 Jul 2026 17:16:42 -0700 Subject: [PATCH] fix(tests): guard the ledger-isolation fixture when headroom is not importable The macos/windows-native-wrapper CI jobs install only pytest and drive the installer shell scripts via subprocess, so `import headroom` fails there on a missing third-party dep (opentelemetry). The new autouse ledger fixture imported headroom at setup, erroring every test in those jobs: ERROR at setup of test_bash_native_installer_supports_persistent_docker_lifecycle tests/conftest.py:45: in _isolate_mcp_ledger monkeypatch.setattr("headroom.mcp_registry.ledger.ledger_path", ...) ModuleNotFoundError: No module named 'opentelemetry' Mirror the guard the sibling _reset_copilot_routing_flag fixture already uses for exactly this case: import inside a try and skip when headroom is absent, since there is no ledger to redirect in those jobs anyway. This only reproduces where bash >= 4.3 is on PATH (CI installs it via brew); with macOS system bash 3.2 the tests skip before the fixture ever runs. --- tests/conftest.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3d627417e..38de51499 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -41,8 +41,17 @@ def _scrub_developer_headroom_env(monkeypatch): # assert the default workspace layout. @pytest.fixture(autouse=True) def _isolate_mcp_ledger(monkeypatch, tmp_path_factory): - ledger = tmp_path_factory.mktemp("mcp-ledger") / "mcp_installs.json" - monkeypatch.setattr("headroom.mcp_registry.ledger.ledger_path", lambda: ledger) + # Same guard as _reset_copilot_routing_flag below: the macos/windows-native- + # wrapper CI jobs install only pytest and drive the installer shell scripts + # via subprocess, so headroom isn't importable and there is no ledger to + # redirect. Skip there instead of erroring at setup. + try: + from headroom.mcp_registry import ledger + except ModuleNotFoundError: + return + + ledger_file = tmp_path_factory.mktemp("mcp-ledger") / "mcp_installs.json" + monkeypatch.setattr(ledger, "ledger_path", lambda: ledger_file) # The Copilot "routed to Copilot" flag is a module-global ContextVar that