test(gateway): shutdown notices carry the interim marker (#98432)

Ported from 12845c7b1a (#98445): home-channel + active-chat sends assert
_interim_send, and the cached-thread-source assertion expects the marker.
This commit is contained in:
liuhao1024
2026-09-24 17:09:48 +05:30
committed by kshitij
parent fee92ee748
commit 08a7042299

View File

@@ -337,7 +337,33 @@ async def test_shutdown_notifications_use_cached_live_thread_source_when_origin_
chat_id, message = adapter.send.await_args.args
assert chat_id == "parent-42"
assert message
assert adapter.send.await_args.kwargs == {"metadata": {"thread_id": "topic-7"}}
assert adapter.send.await_args.kwargs == {"metadata": {"thread_id": "topic-7", "_interim_send": True}}
@pytest.mark.asyncio
async def test_shutdown_home_channel_broadcast_carries_interim_marker():
"""Active-chat and home-channel shutdown sends are interim sends (#98432): a
stream-is-the-message adapter must not seal an in-flight answer with the advisory,
including when the home channel has no thread routing metadata."""
runner, adapter = make_restart_runner()
source = make_restart_source(chat_id="active-42", chat_type="dm")
session_key = build_session_key(source)
runner.config.platforms[Platform.TELEGRAM].home_channel = HomeChannel(
platform=Platform.TELEGRAM,
chat_id="home-42",
name="Ops Home",
)
runner._running_agents[session_key] = object()
runner.session_store._entries[session_key] = MagicMock(origin=source)
adapter.send = AsyncMock(return_value=SendResult(success=True, message_id="m"))
await runner._notify_active_sessions_of_shutdown()
targets = [c.args[0] for c in adapter.send.await_args_list]
assert targets == ["active-42", "home-42"]
for call in adapter.send.await_args_list:
assert call.kwargs["metadata"]["_interim_send"] is True
@pytest.mark.asyncio