"""Unit tests for the dual-read env helper (core/env.py, D-108, REQ-159). Covers the four cases: - both NOVA_* and ACDL_* set (NOVA wins) - only NOVA_* set - only ACDL_* set (fallback) - neither set (default returned) The ACDL_* fallback is the intentional dual-read source and is removed in P5 (REQ-164). These fixtures deliberately keep the ACDL_* names as the fallback source — they are the one allowed ACDL_* reference. """ from __future__ import annotations import pytest from core import env @pytest.fixture(autouse=True) def _isolate_env(monkeypatch): """Ensure no ACDL_*/NOVA_* leakage between tests.""" for key in list(__import__("os").environ): if key.startswith(("ACDL_", "NOVA_")): monkeypatch.delenv(key, raising=False) yield def test_both_set_nova_wins(monkeypatch): monkeypatch.setenv("NOVA_AWS_ACCOUNT_ID", "nova-value") monkeypatch.setenv("ACDL_AWS_ACCOUNT_ID", "acdl-value") assert env.get_env("AWS_ACCOUNT_ID") == "nova-value" def test_only_nova_set(monkeypatch): monkeypatch.setenv("NOVA_AWS_ACCOUNT_ID", "nova-value") assert env.get_env("AWS_ACCOUNT_ID") == "nova-value" def test_only_acdl_set_fallback(monkeypatch): # ACDL_* is the intentional dual-read fallback source (removed in P5). monkeypatch.setenv("ACDL_AWS_ACCOUNT_ID", "acdl-value") assert env.get_env("AWS_ACCOUNT_ID") == "acdl-value" def test_neither_set_returns_default(): assert env.get_env("AWS_ACCOUNT_ID") is None assert env.get_env("AWS_ACCOUNT_ID", default="581513795199") == "581513795199" def test_blank_nova_falls_back_to_acdl(monkeypatch): # An explicitly-empty NOVA key must not shadow the ACDL fallback. monkeypatch.setenv("NOVA_AWS_ACCOUNT_ID", "") monkeypatch.setenv("ACDL_AWS_ACCOUNT_ID", "acdl-value") assert env.get_env("AWS_ACCOUNT_ID") == "acdl-value"