Files
silver_pose/v1/tests/test_report.py
T
ilaandClaude Opus 4.8 2688f2d449 feat(v1): add event-log summary tool for acceptance evidence
v1/report.py reads events.jsonl and lists each confirmed event with its
latency (flags the 1-3s target) and screenshot, or reports a clean pass
when empty. Supports T-204 latency records and false-alarm counting.
78 tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-21 23:52:59 +08:00

61 lines
1.6 KiB
Python

import json
from v1.report import collect_jsonl, format_report, load_events, summarize
def _write_events(path, events):
path.write_text(
"\n".join(json.dumps(e, ensure_ascii=False) for e in events) + "\n",
encoding="utf-8",
)
def _event(event_id, latency):
return {
"event_id": event_id,
"track_id": "P-0001",
"confirmed_at_utc": "2026-07-21T08:30:00+00:00",
"latency_seconds": latency,
"screenshot": "20260721/{0}.png".format(event_id),
}
def test_load_events_reads_each_jsonl_line(tmp_path):
jsonl = tmp_path / "events.jsonl"
_write_events(jsonl, [_event("FALL-A-000001", 1.8), _event("FALL-A-000002", 2.1)])
events = load_events(jsonl)
assert len(events) == 2
assert events[0]["event_id"] == "FALL-A-000001"
def test_summarize_counts_latency_in_target_window(tmp_path):
events = [_event("a", 1.8), _event("b", 0.9), _event("c", 3.0)]
summary = summarize(events)
assert summary["count"] == 3
assert summary["latency_in_target"] == 2 # 1.8 and 3.0 are within 1-3s, 0.9 is not
def test_empty_log_reads_as_clean_pass(tmp_path):
jsonl = tmp_path / "events.jsonl"
jsonl.write_text("", encoding="utf-8")
events = load_events(jsonl)
report = format_report(jsonl, events)
assert events == []
assert "no confirmed events" in report
def test_collect_jsonl_finds_day_directories(tmp_path):
day = tmp_path / "20260721"
day.mkdir()
_write_events(day / "events.jsonl", [_event("FALL-A-000001", 1.8)])
found = collect_jsonl(tmp_path)
assert found == [day / "events.jsonl"]