Files
gps-denied-onboard/tests/unit/test_runtime_root_env_gate.py
T
Oleksandr Bezdieniezhnykh 3acc7f33dd [AZ-270] [AZ-272] [AZ-279] [AZ-281] [AZ-283] Compose root + FDR schema + 3 Layer-1 helpers
AZ-270: composition root with strategy registry, tier-gated lookup,
topo-order construction, all-or-nothing teardown, StrategyNotLinkedError
payload.
AZ-272: orjson-backed FdrRecord serialise/parse with forward-compat for
unknown payload + top-level fields and canonical overrun-record shape.
AZ-279: pyproj-backed WGS84/ECEF/ENU + OSM slippy-map tile math with
WgsConversionError for shape/range/zoom guards.
AZ-281: strict EngineFilenameSchema build/parse/matches_host with
anchored regex + enum validation; round-trip identity by construction.
AZ-283: dtype-preserving (fp16/fp32) single + batch L2 normaliser with
zero-norm safety and descriptor_metric() source-of-truth.
pyproject.toml pins pyproj>=3.6 and orjson>=3.9 (named-backend deps per
the AZ-272 / AZ-279 contracts). New DTOs LatLonAlt + BoundingBox and
EngineCacheKey + HostCapabilities land in _types/ to back the helper
contracts.
203 unit tests pass (64 new). Review verdict: PASS_WITH_WARNINGS;
findings are perf-NFR deferrals + dep amendment + minor docstring polish.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-11 02:03:36 +03:00

59 lines
1.6 KiB
Python

"""Runtime-root env-var fail-fast — AZ-263 AC-8 (updated by AZ-270 to pass a Config).
AZ-270 swapped ``compose_root()`` to ``compose_root(config: Config)``; the
env-var fail-fast still happens inside ``compose_root`` before any factory
construction, so this AC-8 contract is intact.
"""
import pytest
from gps_denied_onboard.config import Config
from gps_denied_onboard.runtime_root import ConfigurationError, compose_root
def test_compose_root_fails_fast_on_missing_required(monkeypatch: pytest.MonkeyPatch) -> None:
# Arrange
for var in (
"GPS_DENIED_FC_PROFILE",
"GPS_DENIED_TIER",
"DB_URL",
"CAMERA_CALIBRATION_PATH",
"LOG_LEVEL",
"LOG_SINK",
"INFERENCE_BACKEND",
"FDR_PATH",
"TILE_CACHE_PATH",
"MAVLINK_SIGNING_KEY",
):
monkeypatch.delenv(var, raising=False)
# Act / Assert
with pytest.raises(ConfigurationError) as excinfo:
compose_root(Config())
assert "Missing required environment variable" in str(excinfo.value)
def test_compose_root_names_the_first_missing_var(monkeypatch: pytest.MonkeyPatch) -> None:
# Arrange
for var in (
"GPS_DENIED_FC_PROFILE",
"GPS_DENIED_TIER",
"DB_URL",
"CAMERA_CALIBRATION_PATH",
"LOG_LEVEL",
"LOG_SINK",
"INFERENCE_BACKEND",
"FDR_PATH",
"TILE_CACHE_PATH",
"MAVLINK_SIGNING_KEY",
):
monkeypatch.delenv(var, raising=False)
# Act
with pytest.raises(ConfigurationError) as excinfo:
compose_root(Config())
# Assert
msg = str(excinfo.value)
assert "GPS_DENIED_FC_PROFILE" in msg