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.
This commit is contained in:
Tejas Chopra 2026-07-30 17:16:42 -07:00
parent 9fd20f2593
commit ce0a7d9490

View file

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