fix: dedupe daily report Telegram in dual mode and show host in summary fallback

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-03 09:15:21 +10:00
parent 3053058cdf
commit 0d4a50cd35
4 changed files with 93 additions and 3 deletions
+58
View File
@@ -226,3 +226,61 @@ def test_notify_lifecycle_skips_telegram_when_via_agent():
notify_dispatch.notify_lifecycle(event)
mock_tg.notify_event.assert_not_called()
mock_wh.notify_event.assert_called_once()
def test_notify_daily_report_skips_telegram_when_via_agent():
event = Event(
event_id="00000000-0000-4000-8000-000000000604",
host_id=1,
occurred_at=datetime(2026, 6, 3, 9, 0, tzinfo=timezone.utc),
category="report",
type="report.daily.rdp",
severity="info",
title="Ежедневный отчёт Windows",
summary="RDP 24ч: успех 0, неудач 0, банов 0",
details={"telegram_via": "agent", "report_body": "📊 body"},
payload={},
)
policy = NotificationPolicyConfig(
min_severity="warning",
use_telegram=True,
use_webhook=True,
use_email=False,
source="db",
)
with patch.object(notify_dispatch, "get_effective_notification_policy", return_value=policy):
with patch.object(notify_dispatch, "should_notify_event", return_value=True):
with patch.object(notify_dispatch, "telegram_notify") as mock_tg:
with patch.object(notify_dispatch, "webhook_notify") as mock_wh:
notify_dispatch.notify_daily_report(event)
mock_tg.notify_event.assert_not_called()
mock_wh.notify_event.assert_called_once()
def test_notify_daily_report_skips_telegram_when_via_agent():
event = Event(
event_id="00000000-0000-4000-8000-000000000604",
host_id=1,
occurred_at=datetime(2026, 6, 3, 9, 0, tzinfo=timezone.utc),
category="report",
type="report.daily.rdp",
severity="info",
title="Ежедневный отчёт Windows",
summary="RDP 24ч: успех 0, неудач 0, банов 0",
details={"telegram_via": "agent", "report_body": "📊 body"},
payload={},
)
policy = NotificationPolicyConfig(
min_severity="warning",
use_telegram=True,
use_webhook=True,
use_email=False,
source="db",
)
with patch.object(notify_dispatch, "get_effective_notification_policy", return_value=policy):
with patch.object(notify_dispatch, "should_notify_event", return_value=True):
with patch.object(notify_dispatch, "telegram_notify") as mock_tg:
with patch.object(notify_dispatch, "webhook_notify") as mock_wh:
notify_dispatch.notify_daily_report(event)
mock_tg.notify_event.assert_not_called()
mock_wh.notify_event.assert_called_once()