import json import pytest from v1.config import ConfigError, load_config def _write_config(path, source): path.write_text( json.dumps( { "source": source, "model": { "path": "models/best.pt", "sha256": "a" * 64, "confidence_threshold": 0.25, }, "event": { "keypoint_confidence_threshold": 0.4, "suspect_window_seconds": 0.5, "confirm_window_seconds": 1.8, "recovery_window_seconds": 2.0, "cooldown_seconds": 10.0, }, "artifacts": {"event_dir": "artifacts/events"}, }, ensure_ascii=False, ), encoding="utf-8", ) def test_load_config_resolves_source_from_environment_variable(tmp_path, monkeypatch): config_file = tmp_path / "config.json" _write_config( config_file, {"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL"}, ) monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://demo.invalid/live") config = load_config(config_file) assert config.source_id == "lobby-camera-01" assert config.source_url == "rtsp://demo.invalid/live" assert config.event.confirm_window_seconds == 1.8 def test_load_config_rejects_embedded_source_address(tmp_path): config_file = tmp_path / "config.json" _write_config( config_file, {"id": "lobby-camera-01", "url": "rtsp://demo.invalid/live"}, ) with pytest.raises(ConfigError, match="rtsp_url_env"): load_config(config_file) def test_runtime_config_version_is_stable_and_excludes_rtsp_address(tmp_path, monkeypatch): config_file = tmp_path / "config.json" _write_config( config_file, {"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL"}, ) monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://operator:secret@camera-a/live") first = load_config(config_file) monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://operator:other-secret@camera-b/live") second = load_config(config_file) assert first.runtime_config_version == second.runtime_config_version assert first.runtime_config_version.startswith("cfg-")