From 730b6e51724227ec44da8747233a6704229bb1ea Mon Sep 17 00:00:00 2001 From: ogt Date: Tue, 14 Jul 2026 22:06:40 +0800 Subject: [PATCH] test(telegram): require verified delivery receipts --- .../tests/test_ansible_verified_closure.py | 13 ++++++++- .../test_channel_hub_grouped_alert_events.py | 27 +++++++++++++++++-- .../TELEGRAM-CANONICAL-ROUTING-INVENTORY.md | 2 +- 3 files changed, 38 insertions(+), 4 deletions(-) diff --git a/apps/api/tests/test_ansible_verified_closure.py b/apps/api/tests/test_ansible_verified_closure.py index f43b2eff5..966887f36 100644 --- a/apps/api/tests/test_ansible_verified_closure.py +++ b/apps/api/tests/test_ansible_verified_closure.py @@ -744,7 +744,13 @@ async def test_controlled_result_pending_reservation_never_resends_provider( return None def json(self) -> dict: - return {"ok": True, "result": {"message_id": 456}} + return { + "ok": True, + "result": { + "message_id": 456, + "chat": {"id": "sre-chat"}, + }, + } class _Client: def __init__(self) -> None: @@ -849,6 +855,11 @@ async def test_no_write_result_reuses_durable_suppression_without_provider_send( monkeypatch: pytest.MonkeyPatch, ) -> None: gateway = TelegramGateway() + monkeypatch.setattr( + telegram_gateway_module.settings, + "SRE_GROUP_CHAT_ID", + "sre-chat", + ) gateway._initialized = True client = AsyncMock() gateway._http_client = client diff --git a/apps/api/tests/test_channel_hub_grouped_alert_events.py b/apps/api/tests/test_channel_hub_grouped_alert_events.py index 17d10478e..d7f628ede 100644 --- a/apps/api/tests/test_channel_hub_grouped_alert_events.py +++ b/apps/api/tests/test_channel_hub_grouped_alert_events.py @@ -1,7 +1,7 @@ from __future__ import annotations -import json import inspect +import json from uuid import uuid4 from src.services.channel_hub import ( @@ -20,6 +20,7 @@ from src.services.channel_hub import ( mirror_inbound_event, record_outbound_message, ) +from src.services.telegram_gateway import _telegram_destination_binding _FAKE_SECRET_SHAPED_VALUE = "1234567890:" + "abcdefghijklmnopqrstuvwxyzABCDEFGH" @@ -54,11 +55,33 @@ async def test_send_telegram_interim_uses_gateway_mirror_path(monkeypatch) -> No "inbound_message_id": inbound_message_id, } ) + destination_binding = _telegram_destination_binding(chat_id) + destination_alias = "verified_inbound_chat" return { "ok": True, - "result": {"message_id": 42}, + "result": { + "message_id": 42, + "chat": {"id": chat_id}, + }, "_awooop_delivery_status": "sent", "_awooop_provider_send_performed": True, + "_awoooi_canonical_route_receipt": { + "schema_version": "telegram_canonical_egress_receipt_v1", + "decision": "allowed", + "provider_send_performed": True, + "sender_bot_alias": "tsenyang_bot", + "destination_alias": destination_alias, + "destination_binding": destination_binding, + }, + "_awoooi_delivery_context": { + "schema_version": "telegram_delivery_context_v1", + "sender_bot_alias": "tsenyang_bot", + "destination_alias": destination_alias, + "destination_binding": destination_binding, + "payload_destination_binding": destination_binding, + "provider_destination_binding": destination_binding, + "destination_binding_verified": True, + }, } monkeypatch.setattr( diff --git a/docs/security/TELEGRAM-CANONICAL-ROUTING-INVENTORY.md b/docs/security/TELEGRAM-CANONICAL-ROUTING-INVENTORY.md index 2e30d028a..53b3a781b 100644 --- a/docs/security/TELEGRAM-CANONICAL-ROUTING-INVENTORY.md +++ b/docs/security/TELEGRAM-CANONICAL-ROUTING-INVENTORY.md @@ -1,6 +1,6 @@ # Telegram 監控告警路由總帳 -> 狀態:`source_policy_ready_runtime_not_applied` +> 狀態:`source_policy_ready_runtime_not_applied` > 真相邊界:本表把「已證明現況」、「建議目的地」、「目前阻擋」、「source risk」與「receipt 強度」分開。建議不等於 live route;alias 不是 numeric chat ID;本變更沒有送 Telegram、讀 token/chat ID、改 runtime route 或部署。 ## 判讀規則