fix(api): 標示全零週報資料鏈異常
All checks were successful
Code Review / ai-code-review (push) Successful in 22s
CD Pipeline / tests (push) Successful in 1m40s
CD Pipeline / build-and-deploy (push) Successful in 4m10s
CD Pipeline / post-deploy-checks (push) Successful in 1m44s

This commit is contained in:
Your Name
2026-06-18 13:27:43 +08:00
parent 650b227a73
commit e0a32b3bd2
3 changed files with 100 additions and 5 deletions

View File

@@ -18,6 +18,7 @@ from src.services.telegram_gateway import (
SentryErrorMessage,
TelegramGateway,
TelegramMessage,
WeeklyReportMessage,
)
@@ -53,6 +54,51 @@ def test_auto_repair_status_line_distinguishes_auto_resolved() -> None:
assert "CPU 92%->30%" in result
def test_weekly_report_marks_all_zero_as_low_trust_anomaly() -> None:
report = WeeklyReportMessage(
week_range="2026-W24",
report_date="2026-06-12 10:00",
stats_source_ok=False,
k3s_source_ok=True,
git_source_ok=False,
cost_source_ok=False,
all_zero_actionable_anomaly=True,
)
body = report.format()
assert "報表資料信任度" in body
assert "判定: <b>低可信</b>" in body
assert "Stats=fail" in body
assert "Git=fail" in body
assert "Cost=missing" in body
assert "全 0: <code>actionable_anomaly</code>" in body
assert "告警統計" in body
def test_weekly_report_keeps_nonzero_source_status_visible() -> None:
report = WeeklyReportMessage(
week_range="2026-W24",
report_date="2026-06-12 10:00",
alert_total=3,
ai_proposal_count=2,
commits_count=5,
deploy_count=1,
ai_tokens_week=1200,
stats_source_ok=True,
k3s_source_ok=True,
git_source_ok=True,
cost_source_ok=True,
)
body = report.format()
assert "判定: <b>可參考</b>" in body
assert "全 0: <code>no</code>" in body
assert "Commits: <code>5</code>" in body
assert "Tokens: <code>1,200</code>" in body
def test_telegram_html_chunks_preserve_complete_lines() -> None:
"""歷史/詳情長訊息不得用 text[:500] 切壞 HTML tag。"""
lines = [