fix: require anchors for Telegram DM topic deliveries

This commit is contained in:
Hermes Agent 2026-05-16 18:55:33 +00:00
parent 3d585f8db5
commit 6daafb3fd4
2 changed files with 60 additions and 8 deletions

View file

@ -135,25 +135,60 @@ class RecordingAdapter:
@pytest.mark.asyncio
async def test_explicit_telegram_private_thread_uses_direct_messages_topic_id(tmp_path, monkeypatch):
async def test_explicit_telegram_private_thread_requires_reply_anchor(tmp_path, monkeypatch):
monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
adapter = RecordingAdapter()
router = DeliveryRouter(GatewayConfig(), adapters={Platform.TELEGRAM: adapter})
target = DeliveryTarget.parse("telegram:722341991:32344")
await router._deliver_to_platform(target, "hello", metadata=None)
with pytest.raises(RuntimeError, match="requires telegram_reply_to_message_id"):
await router._deliver_to_platform(target, "hello", metadata=None)
assert adapter.calls == []
@pytest.mark.asyncio
async def test_explicit_telegram_private_thread_uses_reply_fallback_with_anchor(tmp_path, monkeypatch):
monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
adapter = RecordingAdapter()
router = DeliveryRouter(GatewayConfig(), adapters={Platform.TELEGRAM: adapter})
target = DeliveryTarget.parse("telegram:722341991:32344")
await router._deliver_to_platform(
target,
"hello",
metadata={"telegram_reply_to_message_id": "9001"},
)
assert adapter.calls == [
{
"chat_id": "722341991",
"content": "hello",
"metadata": {
"telegram_direct_messages_topic_id": "32344",
"telegram_reply_to_message_id": "9001",
"thread_id": "32344",
"telegram_dm_topic_reply_fallback": True,
},
}
]
@pytest.mark.asyncio
async def test_explicit_telegram_direct_messages_topic_metadata_is_respected(tmp_path, monkeypatch):
monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
adapter = RecordingAdapter()
router = DeliveryRouter(GatewayConfig(), adapters={Platform.TELEGRAM: adapter})
target = DeliveryTarget.parse("telegram:722341991:32344")
await router._deliver_to_platform(
target,
"hello",
metadata={"telegram_direct_messages_topic_id": "32344"},
)
assert adapter.calls[0]["metadata"] == {"telegram_direct_messages_topic_id": "32344"}
@pytest.mark.asyncio
async def test_explicit_telegram_group_thread_does_not_mark_dm_fallback(tmp_path, monkeypatch):
monkeypatch.setattr("gateway.delivery.get_hermes_home", lambda: tmp_path)
@ -178,4 +213,4 @@ async def test_platform_send_failure_raises_for_delivery_result(tmp_path, monkey
target = DeliveryTarget.parse("telegram:722341991:32344")
with pytest.raises(RuntimeError, match="route failed"):
await router._deliver_to_platform(target, "hello", metadata=None)
await router._deliver_to_platform(target, "hello", metadata={"telegram_reply_to_message_id": "9001"})