Three intertwined bodies of work developed and tested together this session. Full test suite green: python (edge) + phpunit (cloud). ## Edge/Pi install path - setup_online.sh: apt-lock retry (apt-daily contention), Type=exec unit + StartLimitIntervalSec in [Unit], journalctl-on-failure, crash-loop detection. - onnxruntime is now best-effort (no sdist / no 32-bit-ARM wheel); [6/8] probes the real backend and hard-fails if none works. - Hailo HEF auto-fetch: edge/tools/fetch_hailo_hef.py (pinned sha256, refuses to guess 8 vs 8L, HAILO_ARCH override for serial-less boards); hailo_pose.py run() timeout fix. - install_offline.sh: mirrors the backend gate; onnxruntime optional. ## Cafe24 cloud package (cloud/deploy/) - build_cafe24_package.sh emits move_detect_app/ (private, one folder) + www/move_detect/ (docroot subdir); no-dev classmap autoloader; preflight.php; hardened .htaccess. - Subdirectory mount support: Request::baseFrom/pathFor strip the mount prefix; index.php walks up to find the app root; views/JS prefix every URL with APP_BASE; session cookie scoped to the mount. ## Delivery audit — silent-failure & correctness (docs/delivery-audit.md) All 4 blockers + all Phase-1 silent-failure + Phase-2 HIGH correctness: - Edge cloud clients send a custom User-Agent (cafe24 WAF blocks python-requests) and allow_redirects=False. - Daemon fails loud on blank CAFE24_URL/DEVICE_SECRET; run_loop logs swallowed exceptions; heartbeat carries real fps + per-camera health; UvcSource reopens a dead camera; offline queue is size-capped and drops poison rows; TARGET_FPS/QUEUE_DB validated. - Zone coordinates normalized 0..1 on both sides (were canvas-px vs camera-px — every zone misplaced); pinch zones emit PINCH/HIGH (were downgraded to WARNING). - Fall detection uses bbox cues when keypoints are low-confidence (occluded fallen person); ghost incident not cancelled by a bystander; displacement normalized per-second (FPS-invariant). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019Xmn8KZWqiQUguEMRtn6rW
72 lines
3.1 KiB
Python
72 lines
3.1 KiB
Python
import pytest
|
|
|
|
from edge.config import (frame_interval_from_env, load_config, queue_db_path,
|
|
require_upload_config)
|
|
|
|
def test_defaults_when_env_empty():
|
|
cfg = load_config({})
|
|
assert cfg.device_id == "pi-unknown"
|
|
assert cfg.fall.prone_confirm_s == 3.0
|
|
assert cfg.fall.no_motion_s == 10.0
|
|
assert cfg.camera_id == "cam-01"
|
|
assert cfg.cafe24_url == ""
|
|
assert cfg.secret == ""
|
|
assert cfg.ghost.reappear_s == 10.0
|
|
assert cfg.zone.debounce_s == 0.75
|
|
assert cfg.engine.cooldown_s == 30.0
|
|
|
|
def test_env_overrides():
|
|
env = {
|
|
"DEVICE_ID": "pi-w1", "CAMERA_ID": "cam-9",
|
|
"CAFE24_URL": "https://x/api/events", "DEVICE_SECRET": "s",
|
|
"FALL_PRONE_S": "2.0", "FALL_NO_MOTION_S": "8",
|
|
"IMMOBILE_S": "90", "COOLDOWN_S": "45",
|
|
"GHOST_REAPPEAR_S": "7", "ZONE_DEBOUNCE_S": "1.5",
|
|
}
|
|
cfg = load_config(env)
|
|
assert cfg.device_id == "pi-w1"
|
|
assert cfg.camera_id == "cam-9"
|
|
assert cfg.fall.prone_confirm_s == 2.0
|
|
assert cfg.fall.no_motion_s == 8.0
|
|
assert cfg.immobility.immobile_s == 90.0
|
|
assert cfg.engine.cooldown_s == 45.0
|
|
assert cfg.engine.camera_id == "cam-9"
|
|
assert cfg.ghost.reappear_s == 7.0
|
|
assert cfg.zone.debounce_s == 1.5
|
|
|
|
|
|
def test_require_upload_config_rejects_blank_url_and_secret():
|
|
# A blank CAFE24_URL or DEVICE_SECRET must fail LOUD at startup. Left silent, the daemon
|
|
# runs green while every upload fails (bad URL -> requests error, caught) and the offline
|
|
# queue grows until the SD card is full.
|
|
with pytest.raises(ValueError, match="CAFE24_URL"):
|
|
require_upload_config(load_config({"DEVICE_SECRET": "s"}))
|
|
with pytest.raises(ValueError, match="DEVICE_SECRET"):
|
|
require_upload_config(load_config({"CAFE24_URL": "https://x/move_detect"}))
|
|
# Whitespace-only is still blank.
|
|
with pytest.raises(ValueError):
|
|
require_upload_config(load_config({"CAFE24_URL": " ", "DEVICE_SECRET": " "}))
|
|
|
|
|
|
def test_require_upload_config_passes_when_both_present():
|
|
cfg = load_config({"CAFE24_URL": "https://x/move_detect", "DEVICE_SECRET": "s"})
|
|
require_upload_config(cfg) # must not raise
|
|
|
|
|
|
def test_frame_interval_defaults_and_validates():
|
|
assert frame_interval_from_env({}) == pytest.approx(1 / 12)
|
|
assert frame_interval_from_env({"TARGET_FPS": "24"}) == pytest.approx(1 / 24)
|
|
# TARGET_FPS=0 -> ZeroDivisionError today -> infinite systemd crash loop; must be rejected.
|
|
with pytest.raises(ValueError):
|
|
frame_interval_from_env({"TARGET_FPS": "0"})
|
|
with pytest.raises(ValueError):
|
|
frame_interval_from_env({"TARGET_FPS": "12fps"})
|
|
with pytest.raises(ValueError):
|
|
frame_interval_from_env({"TARGET_FPS": "-5"})
|
|
|
|
|
|
def test_queue_db_path_defaults_absolute_under_state_dir():
|
|
# A relative 'queue.db' is unwritable under the hardened unit (ProtectSystem=strict,
|
|
# WorkingDirectory read-only) -> crash loop. Default to the writable StateDirectory.
|
|
assert queue_db_path({}) == "/var/lib/move-detect/queue.db"
|
|
assert queue_db_path({"QUEUE_DB": "/custom/q.db"}) == "/custom/q.db"
|