fix: refresh stale Telegram DM topic threads

(cherry picked from commit 26b87057ad)
This commit is contained in:
stepanov1975 2026-05-16 20:01:40 +00:00 committed by Teknium
parent dcd504cea4
commit c394e7919d
5 changed files with 202 additions and 14 deletions

View file

@ -624,6 +624,33 @@ async def test_send_created_private_topic_uses_message_thread_without_anchor():
assert "direct_messages_topic_id" not in call_log[0]
@pytest.mark.asyncio
async def test_created_private_topic_thread_not_found_fails_without_root_fallback():
"""Created private-topic sends must not retry into All Messages on stale thread IDs."""
adapter = _make_adapter()
call_log = []
async def mock_send_message(**kwargs):
call_log.append(dict(kwargs))
raise FakeBadRequest("Message thread not found")
adapter._bot = SimpleNamespace(send_message=mock_send_message)
result = await adapter.send(
chat_id="123",
content="created topic message",
metadata={
"thread_id": "32343",
"telegram_dm_topic_created_for_send": True,
},
)
assert result.success is False
assert "thread not found" in str(result.error).lower()
assert len(call_log) == 1
assert call_log[0]["message_thread_id"] == 32343
@pytest.mark.asyncio
async def test_send_uses_metadata_reply_fallback_for_streaming_dm_topics():
"""Metadata-only sends still stay in Hermes-created Telegram DM topics."""