fix(alertmanager): keep auto repair moving on ai fallback
All checks were successful
Code Review / ai-code-review (push) Successful in 11s
CD Pipeline / tests (push) Successful in 1m10s
CD Pipeline / build-and-deploy (push) Successful in 3m25s
CD Pipeline / post-deploy-checks (push) Successful in 1m30s

This commit is contained in:
Your Name
2026-05-14 00:06:34 +08:00
parent 39581ab824
commit d835b666cf
2 changed files with 125 additions and 3 deletions

View File

@@ -1,6 +1,10 @@
import asyncio
from datetime import datetime
import pytest
from src.api.v1.webhooks import (
_analyze_alertmanager_with_timeout,
_should_bypass_alertmanager_llm,
_should_use_alertmanager_rule_first,
)
@@ -111,6 +115,43 @@ def test_alertmanager_llm_inflight_lock_key_is_fingerprint_scoped():
assert ALERTMANAGER_LLM_INFLIGHT_LOCK_TTL_SECONDS == 600
@pytest.mark.asyncio
async def test_alertmanager_analysis_timeout_returns_fallback(monkeypatch):
from src.api.v1 import webhooks as webhooks_module
class SlowOpenClaw:
async def analyze_alert(self, alert_context):
await asyncio.sleep(1)
return "unexpected"
monkeypatch.setattr(webhooks_module, "ALERTMANAGER_BACKGROUND_AI_TIMEOUT_SECONDS", 0.01)
result = await _analyze_alertmanager_with_timeout(
SlowOpenClaw(),
{"alertname": "AwoooPTimeoutCanary"},
alert_id="alert-timeout",
alertname="AwoooPTimeoutCanary",
)
assert result == (None, "fallback_timeout", "", None, "", 0, 0.0)
@pytest.mark.asyncio
async def test_alertmanager_analysis_error_returns_fallback():
class BrokenOpenClaw:
async def analyze_alert(self, alert_context):
raise RuntimeError("provider chain failed")
result = await _analyze_alertmanager_with_timeout(
BrokenOpenClaw(),
{"alertname": "AwoooPErrorCanary"},
alert_id="alert-error",
alertname="AwoooPErrorCanary",
)
assert result == (None, "fallback_error", "", None, "", 0, 0.0)
def test_resolved_guard_stamp_without_timestamp_is_clean():
assert _format_resolved_guard_stamp(None) == "✅ 此事件已解決"