Files
awoooi/apps/api/tests/test_telegram_ai_automation_block.py
Your Name 8c40621d42
Some checks failed
CD Pipeline / tests (push) Successful in 1m22s
Code Review / ai-code-review (push) Successful in 12s
CD Pipeline / build-and-deploy (push) Successful in 4m14s
CD Pipeline / post-deploy-checks (push) Has been cancelled
fix(alerts): distinguish diagnostic ops from repair
2026-05-31 14:31:07 +08:00

127 lines
4.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from src.services.telegram_gateway import TelegramMessage
def test_action_required_card_exposes_ai_automation_on_fallback() -> None:
message = TelegramMessage(
status_emoji="🚨",
risk_level="CRITICAL",
resource_name="node-exporter-110",
root_cause="AI 分析超時90s降級至人工審核",
suggested_action="待分析",
estimated_downtime="5-15 min",
approval_id="test-approval-id",
incident_id="INC-20260429-TEST01",
primary_responsibility="INFRA",
confidence=0.0,
)
body = message.format()
assert "AI 自動化鏈路" in body
assert "rule_fallback" in body
assert "llm_timeout_manual_gate" in body
assert "OpenClaw" in body
assert "NemoTron" in body
assert "Hermes" in body
assert "ElephantAlpha" in body
assert "流程進度" in body
assert "執行:<code>no_action_or_observe</code>" in body
def test_nemotron_card_exposes_same_ai_automation_chain() -> None:
message = TelegramMessage(
status_emoji="🚨",
risk_level="CRITICAL",
resource_name="awoooi-api",
root_cause="Pod restart loop",
suggested_action="restart deployment/awoooi-api",
estimated_downtime="30s",
approval_id="test-approval-id",
incident_id="INC-20260429-TEST02",
primary_responsibility="INFRA",
confidence=0.86,
ai_provider="openclaw_nemo",
ai_model="llama-3.1-nemotron",
nemotron_enabled=True,
playbook_name="restart_deployment",
)
body = message.format_with_nemotron()
assert "AI 自動化鏈路" in body
assert "OpenClaw Nemo" in body
assert "tool_ready" in body
assert "restart_deployment" in body
assert "流程進度" in body
def test_action_required_card_exposes_truth_chain_progress() -> None:
message = TelegramMessage(
status_emoji="⚠️",
risk_level="LOW",
resource_name="awoooi-api",
root_cause="restart spike",
suggested_action="kubectl rollout restart deployment/awoooi-api",
estimated_downtime="30s",
approval_id="approval-id",
incident_id="INC-20260513-TEST03",
primary_responsibility="INFRA",
confidence=0.91,
playbook_name="restart_deployment",
automation_quality={
"verdict": "auto_repaired_verified",
"facts": {
"auto_repair_execution_records": 1,
"automation_operation_records": 1,
"verification_result": "success",
"mcp_gateway_total": 5,
"knowledge_entries": 2,
},
},
)
body = message.format()
assert "流程進度" in body
assert "執行:<code>auto_repair_recorded:1</code>" in body
assert "驗證:<code>success</code>" in body
assert "KM<code>2</code>" in body
assert "MCP<code>5</code>" in body
assert "已驗證自動修復" in body
assert "已驗證自動修復完成" in body
assert "等待人工批准" not in body
def test_action_required_card_does_not_call_diagnostic_ops_auto_repair() -> None:
message = TelegramMessage(
status_emoji="🚨",
risk_level="CRITICAL",
resource_name="dirty-reboot-evidence",
root_cause="Expert System: 偵測到高錯誤率",
suggested_action="ssh 192.168.0.110 'df -h /data/minio'",
estimated_downtime="0 min",
approval_id="approval-id",
incident_id="INC-20260530-88D960",
primary_responsibility="INFRA",
confidence=0.0,
playbook_name="rule_catalog",
automation_quality={
"verdict": "auto_repaired_verification_degraded",
"facts": {
"auto_repair_execution_records": 0,
"automation_operation_records": 1,
"effective_execution_records": 0,
"verification_result": "degraded",
"mcp_gateway_total": 22,
"knowledge_entries": 2,
},
},
)
body = message.format()
assert "已記錄診斷/觀察驗證結果degraded" in body
assert "執行:<code>diagnostic_recorded:1</code>" in body
assert "已記錄診斷/觀察,尚未證明修復" in body
assert "已自動執行" not in body