This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user