48 lines
1.3 KiB
Python
48 lines
1.3 KiB
Python
from datetime import datetime
|
|
|
|
from src.api.v1.webhooks import _should_bypass_alertmanager_llm
|
|
from src.services.telegram_gateway import _format_resolved_guard_stamp
|
|
|
|
|
|
def test_host_resource_yaml_no_action_bypasses_llm():
|
|
rule_response = {
|
|
"rule_id": "host_resource_alert",
|
|
"suggested_action": "NO_ACTION",
|
|
"kubectl_command": "",
|
|
}
|
|
|
|
assert _should_bypass_alertmanager_llm(rule_response, "host_resource") is True
|
|
|
|
|
|
def test_generic_fallback_does_not_bypass_llm():
|
|
rule_response = {
|
|
"rule_id": "generic_fallback",
|
|
"suggested_action": "NO_ACTION",
|
|
"kubectl_command": "",
|
|
}
|
|
|
|
assert _should_bypass_alertmanager_llm(rule_response, "host_resource") is False
|
|
|
|
|
|
def test_non_host_category_does_not_bypass_llm():
|
|
rule_response = {
|
|
"rule_id": "host_resource_alert",
|
|
"suggested_action": "NO_ACTION",
|
|
"kubectl_command": "",
|
|
}
|
|
|
|
assert _should_bypass_alertmanager_llm(rule_response, "kubernetes") is False
|
|
|
|
|
|
def test_resolved_guard_stamp_without_timestamp_is_clean():
|
|
assert _format_resolved_guard_stamp(None) == "✅ 此事件已解決"
|
|
|
|
|
|
def test_resolved_guard_stamp_with_timestamp_formats_time():
|
|
resolved_at = datetime(2026, 4, 25, 0, 2)
|
|
|
|
assert (
|
|
_format_resolved_guard_stamp(resolved_at)
|
|
== "✅ 此事件已於 2026-04-25 00:02 解決"
|
|
)
|