from __future__ import annotations import os import runpy from pathlib import Path ROOT = Path(__file__).resolve().parents[1] SCRIPT = ROOT / "deploy" / "scripts" / "rein-aharness-claim" def _launcher_namespace() -> dict: return runpy.run_path(str(SCRIPT), run_name="rein_aharness_claim_test") def test_runtime_defaults_expose_bao_and_approle(tmp_path: Path) -> None: apply_defaults = _launcher_namespace()["_apply_runtime_defaults"] env = apply_defaults({"PATH": "/usr/bin:/bin"}, tmp_path) assert env["BAO_ADDR"] == "https://bao.coulomb.social" assert env["VAULT_ADDR"] == env["BAO_ADDR"] assert env["EXECUTOR_APPROLE_DIR"] == str( tmp_path / ".local/rein-aharness/approle-binky-mail" ) assert env["PATH"].split(os.pathsep)[0] == str(tmp_path / ".local/bin") def test_runtime_defaults_preserve_explicit_configuration(tmp_path: Path) -> None: apply_defaults = _launcher_namespace()["_apply_runtime_defaults"] configured_bin = str(tmp_path / ".local/bin") env = { "BAO_ADDR": "https://bao.example.test", "VAULT_ADDR": "https://vault.example.test", "EXECUTOR_APPROLE_DIR": "/run/approle", "PATH": f"{configured_bin}:/usr/bin", } resolved = apply_defaults(env, tmp_path) assert resolved["BAO_ADDR"] == "https://bao.example.test" assert resolved["VAULT_ADDR"] == "https://vault.example.test" assert resolved["EXECUTOR_APPROLE_DIR"] == "/run/approle" assert resolved["PATH"] == f"{configured_bin}:/usr/bin"