"""Unit tests for ``_live_e2e_common``'s binary-discovery env-var override. ``CONTROLLER_CANDIDATES``/``XCEADMIN_CANDIDATES`` previously only ever resolved to the three default profile-dir names (``xce.build``, ``build.release``, ``build.dbg``) -- no way to point the live E2E suite at a binary built to a custom/explicit build dir (``xce-build.sh``'s "legacy explicit build_dir" override) without editing this module directly. This adds ``XCE_CONTROLLER_BIN``/``XCEADMIN_BIN`` env-var overrides, consistent with the ``${XCE_CONTROLLER_BIN:-default}``-style pattern already used by ``clean_failover_preservation.sh``/``run-ha-soak.sh``. Tests the pure resolution helper directly (not the frozen module-level ``CONTROLLER_CANDIDATES``/``XCEADMIN_CANDIDATES`` constants, which are computed once at import time from whatever the environment happened to be -- re-importing the module under a patched environment is fragile/awkward under pytest's module caching, so the override LOGIC is factored into a directly-testable function instead). """ from __future__ import annotations from pathlib import Path from _live_e2e_common import resolve_binary_candidates def test_no_env_override_returns_default_candidates_unchanged(monkeypatch): monkeypatch.delenv("XCE_SOME_TEST_BIN", raising=False) defaults = [Path("/a/xce.build/x"), Path("/a/build.release/x")] result = resolve_binary_candidates("XCE_SOME_TEST_BIN", defaults) assert result == defaults def test_empty_env_override_falls_back_to_default_candidates(monkeypatch): monkeypatch.setenv("XCE_SOME_TEST_BIN", "") defaults = [Path("/a/xce.build/x")] result = resolve_binary_candidates("XCE_SOME_TEST_BIN", defaults) assert result == defaults def test_env_override_becomes_sole_candidate(monkeypatch, tmp_path): custom_bin = tmp_path / "my-custom-build" / "controller" / "xce_controller" monkeypatch.setenv("XCE_SOME_TEST_BIN", str(custom_bin)) defaults = [Path("/a/xce.build/x"), Path("/a/build.dbg/x")] result = resolve_binary_candidates("XCE_SOME_TEST_BIN", defaults) assert result == [custom_bin] def test_controller_and_xceadmin_candidates_respect_their_own_env_vars(monkeypatch, tmp_path): """End-to-end through the real module constants' construction: reload the module with each override env var set and confirm the exported candidate lists reduce to the single overridden path, proving the actual production wiring (not just the helper in isolation) is correct. """ import importlib import _live_e2e_common as mod custom_controller = tmp_path / "custom" / "xce_controller" custom_xceadmin = tmp_path / "custom" / "xceadmin" monkeypatch.setenv("XCE_CONTROLLER_BIN", str(custom_controller)) monkeypatch.setenv("XCEADMIN_BIN", str(custom_xceadmin)) try: importlib.reload(mod) assert mod.CONTROLLER_CANDIDATES == [custom_controller] assert mod.XCEADMIN_CANDIDATES == [custom_xceadmin] finally: monkeypatch.delenv("XCE_CONTROLLER_BIN", raising=False) monkeypatch.delenv("XCEADMIN_BIN", raising=False) importlib.reload(mod) # restore default candidates for any test after this one