feat: always notify agent.lifecycle via SAC with telegram_via routing

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-05-31 12:25:48 +10:00
parent 3d4d1f3c76
commit 366a9c83f7
6 changed files with 160 additions and 2 deletions
+56
View File
@@ -87,3 +87,59 @@ def test_notify_event_skipped_by_cooldown():
with patch.object(notify_dispatch, "telegram_notify") as mock_tg:
notify_dispatch.notify_event(event)
mock_tg.notify_event.assert_not_called()
def test_notify_lifecycle_bypasses_min_severity():
event = Event(
event_id="00000000-0000-4000-8000-000000000501",
host_id=1,
occurred_at=datetime(2026, 5, 29, 15, 0, tzinfo=timezone.utc),
category="agent",
type="agent.lifecycle",
severity="info",
title="started",
summary="agent started",
details={"lifecycle": "started", "telegram_via": "sac"},
payload={},
)
policy = NotificationPolicyConfig(
min_severity="warning",
use_telegram=True,
use_webhook=False,
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:
notify_dispatch.notify_lifecycle(event)
mock_tg.notify_event.assert_called_once()
def test_notify_lifecycle_skips_telegram_when_via_agent():
event = Event(
event_id="00000000-0000-4000-8000-000000000502",
host_id=1,
occurred_at=datetime(2026, 5, 29, 15, 0, tzinfo=timezone.utc),
category="agent",
type="agent.lifecycle",
severity="info",
title="started",
summary="agent started",
details={"lifecycle": "started", "telegram_via": "agent"},
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_lifecycle(event)
mock_tg.notify_event.assert_not_called()
mock_wh.notify_event.assert_called_once()