This commit is contained in:
@@ -58,3 +58,38 @@ def test_collect_ai_automation_smoke_persists_recent_history(tmp_path, monkeypat
|
||||
assert second["history"]["counts"]["ok"] == 2
|
||||
assert third["history"]["counts"]["ok"] == 2
|
||||
assert len(history_path.read_text(encoding="utf-8").strip().splitlines()) == 2
|
||||
|
||||
|
||||
def test_smoke_history_export_and_clear(tmp_path, monkeypatch):
|
||||
from services import ai_automation_smoke_service as smoke
|
||||
|
||||
history_path = tmp_path / "smoke_history.jsonl"
|
||||
history_path.write_text(
|
||||
'{"generated_at":"2026-04-29T01:00:00","status":"ok"}\n'
|
||||
'{"generated_at":"2026-04-29T02:00:00","status":"warning"}\n',
|
||||
encoding="utf-8",
|
||||
)
|
||||
monkeypatch.setattr(smoke, "_HISTORY_PATH", str(history_path))
|
||||
|
||||
export = smoke.export_smoke_history_jsonl()
|
||||
cleared = smoke.clear_smoke_history()
|
||||
|
||||
assert export["count"] == 2
|
||||
assert '"status":"warning"' in export["content"]
|
||||
assert cleared["cleared"] == 2
|
||||
assert not history_path.exists()
|
||||
|
||||
|
||||
def test_smoke_history_daily_summary():
|
||||
from services import ai_automation_smoke_service as smoke
|
||||
|
||||
summary = smoke._history_summary([
|
||||
{"generated_at": "2026-04-28T23:00:00", "status": "ok"},
|
||||
{"generated_at": "2026-04-29T01:00:00", "status": "warning"},
|
||||
{"generated_at": "2026-04-29T02:00:00", "status": "critical"},
|
||||
])
|
||||
|
||||
assert summary["daily"] == [
|
||||
{"date": "2026-04-28", "ok": 1, "warning": 0, "critical": 0, "total": 1},
|
||||
{"date": "2026-04-29", "ok": 0, "warning": 1, "critical": 1, "total": 2},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user