fix(alertmanager): keep auto repair moving on ai fallback
This commit is contained in:
@@ -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) == "✅ 此事件已解決"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user