fix(telegram): clarify auto repair handoff cards
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 1m17s
CD Pipeline / build-and-deploy (push) Successful in 3m47s
CD Pipeline / post-deploy-checks (push) Successful in 1m57s

This commit is contained in:
Your Name
2026-05-07 02:07:43 +08:00
parent 57df3582dd
commit 3f69e03fcb
2 changed files with 96 additions and 18 deletions

View File

@@ -8,6 +8,7 @@ test_telegram_message_templates.py - Telegram 訊息模板測試
import pytest
import src.services.telegram_gateway as telegram_gateway_module
from src.services.decision_manager import _format_auto_repair_status_line
from src.services.telegram_gateway import (
DailySummaryMessage,
DeploySuccessMessage,
@@ -20,6 +21,38 @@ from src.services.telegram_gateway import (
)
def test_auto_repair_status_line_distinguishes_handoff_required() -> None:
"""自動化失敗 reply 必須明確標示轉人工,且不把 raw error 當純文字噴出。"""
result = _format_auto_repair_status_line(
incident_id="INC-20260507-AAAAAA",
target="node-exporter-110",
action='ssh 192.168.0.110 "ps aux --sort=-%cpu | head -15"',
success=False,
error="Unsupported <scheme> & %d format: a real number is required, not str",
)
assert "HANDOFF REQUIREDAI 自動修復失敗,已轉人工" in result
assert "自動化已停止,不再重試" in result
assert "請 SRE 依 AwoooP Run / 原告警卡處理" in result
assert "&lt;scheme&gt; &amp; %d format" in result
assert "<scheme>" not in result
def test_auto_repair_status_line_distinguishes_auto_resolved() -> None:
"""自動化成功 reply 必須明確標示已自動解決。"""
result = _format_auto_repair_status_line(
incident_id="INC-20260507-BBBBBB",
target="awoooi-api",
action="kubectl rollout restart deployment/awoooi-api",
success=True,
metrics_delta_text="CPU 92%->30%",
)
assert "AUTO RESOLVEDAI 自動修復完成" in result
assert "自動化已完成,等待後驗證觀察" in result
assert "CPU 92%-&gt;30%" in result
class TestTelegramMessageFormat:
"""測試現有 TelegramMessage 格式化"""