fix: preserve handled display cabinet cases
This commit is contained in:
@@ -6,7 +6,7 @@ import unittest
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
|
||||
from cold_display_guard.cases import CaseStore
|
||||
from cold_display_guard.cases import CaseStore, append_case_snapshots, load_case_snapshots
|
||||
from cold_display_guard.main import (
|
||||
case_sink_path,
|
||||
capture_runtime_alarm_snapshot,
|
||||
@@ -67,6 +67,61 @@ class RuntimeRestoreTests(unittest.TestCase):
|
||||
self.assertEqual(written[0]["case_type"], "time_alarm")
|
||||
self.assertEqual(written[0]["case_status"], "open")
|
||||
|
||||
def test_persist_case_updates_preserves_api_handled_snapshot(self) -> None:
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
path = Path(tmpdir) / "cases.jsonl"
|
||||
runtime_store = CaseStore()
|
||||
created = persist_case_updates(
|
||||
runtime_store,
|
||||
path,
|
||||
[
|
||||
{
|
||||
"event": "time_alarm",
|
||||
"ts": datetime(2026, 6, 9, 9, 0, tzinfo=UTC).isoformat(),
|
||||
"batch_id": "batch_000001",
|
||||
"camera_id": "cam_01",
|
||||
"zone_id": "1",
|
||||
"zone_label": "区域 1",
|
||||
"severity": "alarm",
|
||||
"state": "alerted",
|
||||
}
|
||||
],
|
||||
)[0]
|
||||
api_store = CaseStore(load_case_snapshots(path))
|
||||
append_case_snapshots(
|
||||
path,
|
||||
[
|
||||
api_store.mark_handled(
|
||||
str(created["case_id"]),
|
||||
handled_at=datetime(2026, 6, 9, 9, 5, tzinfo=UTC),
|
||||
handled_by="alice",
|
||||
handled_source="manual",
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
snapshots = persist_case_updates(
|
||||
runtime_store,
|
||||
path,
|
||||
[
|
||||
{
|
||||
"event": "batch_pending_disposal",
|
||||
"ts": datetime(2026, 6, 9, 9, 6, tzinfo=UTC).isoformat(),
|
||||
"batch_id": "batch_000001",
|
||||
"camera_id": "cam_01",
|
||||
"zone_id": "1",
|
||||
"zone_label": "区域 1",
|
||||
"severity": "warning",
|
||||
"state": "pending_disposal",
|
||||
}
|
||||
],
|
||||
)
|
||||
latest = CaseStore(load_case_snapshots(path)).latest_cases()[0]
|
||||
|
||||
self.assertEqual(snapshots, [])
|
||||
self.assertEqual(latest["case_status"], "handled")
|
||||
self.assertEqual(latest["handled_source"], "manual")
|
||||
|
||||
def test_deliver_runtime_webhooks_sends_event_and_case_payloads(self) -> None:
|
||||
deliveries: list[tuple[str, dict[str, object]]] = []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user