加入 AI Smoke 每日摘要推播
All checks were successful
CD Pipeline / deploy (push) Successful in 1m15s

This commit is contained in:
OoO
2026-04-29 23:57:36 +08:00
parent 10bbd55f5b
commit d5f4fd7198
15 changed files with 172 additions and 11 deletions

View File

@@ -93,3 +93,43 @@ def test_smoke_history_daily_summary():
{"date": "2026-04-28", "ok": 1, "warning": 0, "critical": 0, "total": 1},
{"date": "2026-04-29", "ok": 0, "warning": 1, "critical": 1, "total": 2},
]
def test_build_smoke_daily_summary_message_escapes_history(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":"warning",'
'"summary":{"ok":0,"warning":1,"critical":0,"total":1},'
'"checks":[{"name":"<script>","status":"warning","summary":"bad"}]}\n',
encoding="utf-8",
)
monkeypatch.setattr(smoke, "_HISTORY_PATH", str(history_path))
message = smoke.build_smoke_daily_summary_message()
assert "AI 自動化 Smoke 每日摘要" in message
assert "WARNING" in message
assert "<script>" not in message
def test_send_smoke_daily_summary_uses_telegram_result(monkeypatch):
from services import ai_automation_smoke_service as smoke
monkeypatch.setattr(smoke, "build_smoke_daily_summary_message", lambda: "hello")
monkeypatch.setattr(
"services.telegram_templates.send_telegram_with_result",
lambda message, chat_ids=None: {
"ok": True,
"sent": 1,
"failed": 0,
"chat_ids": chat_ids or [123],
"errors": [],
},
)
result = smoke.send_smoke_daily_summary(chat_ids=[999])
assert result["status"] == "sent"
assert result["telegram"]["chat_ids"] == [999]