A: PoseAdapter.set_confidence_threshold is applied on start, so the
settings model-confidence field actually affects inference.
B: config source.mode ('stream'|'replay') is explicit; app no longer
guesses the source type from the URL prefix.
C: FallStateMachine takes a session_id and from_config generates a
unique one per run, so event ids never collide across restarts
(no screenshot overwrite or duplicate JSONL identity in a day).
51 tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
106 lines
3.4 KiB
Python
106 lines
3.4 KiB
Python
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_source_mode_defaults_to_stream(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")
|
|
|
|
assert load_config(config_file).source_mode == "stream"
|
|
|
|
|
|
def test_source_mode_replay_is_parsed(tmp_path, monkeypatch):
|
|
config_file = tmp_path / "config.json"
|
|
_write_config(
|
|
config_file,
|
|
{"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL", "mode": "replay"},
|
|
)
|
|
monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://demo.invalid/live")
|
|
|
|
assert load_config(config_file).source_mode == "replay"
|
|
|
|
|
|
def test_invalid_source_mode_is_rejected(tmp_path, monkeypatch):
|
|
config_file = tmp_path / "config.json"
|
|
_write_config(
|
|
config_file,
|
|
{"id": "lobby-camera-01", "rtsp_url_env": "SILVER_POSE_RTSP_URL", "mode": "loop"},
|
|
)
|
|
monkeypatch.setenv("SILVER_POSE_RTSP_URL", "rtsp://demo.invalid/live")
|
|
|
|
with pytest.raises(ConfigError, match="mode"):
|
|
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-")
|