fix(alerts): 收斂 Telegram 告警到 SRE 戰情室
This commit is contained in:
@@ -126,7 +126,7 @@ async def test_converged_recurrence_falls_back_to_milestones(monkeypatch):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_converged_recurrence_mirrors_to_private_chat(monkeypatch):
|
||||
async def test_converged_recurrence_does_not_mirror_to_private_chat(monkeypatch):
|
||||
gateway = _FakeGateway()
|
||||
|
||||
async def _always_notify(*, fingerprint, hit_count):
|
||||
@@ -134,7 +134,6 @@ async def test_converged_recurrence_mirrors_to_private_chat(monkeypatch):
|
||||
|
||||
monkeypatch.setattr(notifier, "should_notify_converged_alert_recurrence", _always_notify)
|
||||
monkeypatch.setattr(notifier, "get_telegram_gateway", lambda: gateway)
|
||||
monkeypatch.setattr(notifier.settings, "OPENCLAW_TG_CHAT_ID", "private-chat")
|
||||
|
||||
await notifier.notify_converged_alert_recurrence(
|
||||
source="alertmanager",
|
||||
@@ -151,9 +150,4 @@ async def test_converged_recurrence_mirrors_to_private_chat(monkeypatch):
|
||||
)
|
||||
|
||||
assert len(gateway.primary_messages) == 1
|
||||
assert gateway.private_messages == [
|
||||
{
|
||||
"text": gateway.primary_messages[0],
|
||||
"chat_id": "private-chat",
|
||||
}
|
||||
]
|
||||
assert gateway.private_messages == []
|
||||
|
||||
@@ -22,10 +22,10 @@ def test_all_alert_types_resolve_to_sre_group_first() -> None:
|
||||
) == ["-1003711974679"]
|
||||
|
||||
|
||||
def test_dm_is_only_fail_soft_fallback_when_group_missing() -> None:
|
||||
def test_dm_is_not_used_when_group_missing() -> None:
|
||||
assert resolve_chat_ids(
|
||||
"TYPE-3",
|
||||
dm_chat_id="5619078117",
|
||||
group_chat_id="",
|
||||
tg_group_cutover=True,
|
||||
) == ["5619078117"]
|
||||
) == []
|
||||
|
||||
@@ -195,6 +195,30 @@ class TestSREGroupCutover:
|
||||
assert "_send_approval_card_to_group(" not in fn_body
|
||||
assert "asyncio.create_task" not in fn_body
|
||||
|
||||
def test_alert_chat_id_is_sre_only(self):
|
||||
source = _read_gateway()
|
||||
match = re.search(
|
||||
r"def alert_chat_id\(self\).*?(?=\n def _summarize_callback_data_for_audit)",
|
||||
source,
|
||||
re.DOTALL,
|
||||
)
|
||||
assert match, "找不到 alert_chat_id property"
|
||||
fn_body = match.group(0)
|
||||
assert "return settings.SRE_GROUP_CHAT_ID" in fn_body
|
||||
assert "or settings.OPENCLAW_TG_CHAT_ID" not in fn_body
|
||||
|
||||
def test_default_chat_id_is_sre_only(self):
|
||||
source = _read_gateway()
|
||||
match = re.search(
|
||||
r"def chat_id\(self\).*?(?=\n @property\n def alert_chat_id)",
|
||||
source,
|
||||
re.DOTALL,
|
||||
)
|
||||
assert match, "找不到 chat_id property"
|
||||
fn_body = match.group(0)
|
||||
assert "return settings.SRE_GROUP_CHAT_ID" in fn_body
|
||||
assert "return settings.OPENCLAW_TG_CHAT_ID" not in fn_body
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Test: callback handler 完整性(鬼魂按鈕鐵律)
|
||||
|
||||
Reference in New Issue
Block a user