From 232ba441d73a1f90104202a9100792c87c93c017 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Sun, 15 Mar 2026 02:38:48 -0700 Subject: [PATCH] test: cover DM session key isolation Update interrupt-key expectations for namespaced DM session keys and add a regression test that different DM chat IDs produce distinct gateway sessions. --- tests/gateway/test_interrupt_key_match.py | 4 ++-- tests/gateway/test_session.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/gateway/test_interrupt_key_match.py b/tests/gateway/test_interrupt_key_match.py index f129977d..ece3878d 100644 --- a/tests/gateway/test_interrupt_key_match.py +++ b/tests/gateway/test_interrupt_key_match.py @@ -50,11 +50,11 @@ class TestInterruptKeyConsistency: """Ensure adapter interrupt methods are queried with session_key, not chat_id.""" def test_session_key_differs_from_chat_id_for_dm(self): - """Session key for a DM is NOT the same as chat_id.""" + """Session key for a DM is namespaced and includes the DM chat_id.""" source = _source("123456", "dm") session_key = build_session_key(source) assert session_key != source.chat_id - assert session_key == "agent:main:telegram:dm" + assert session_key == "agent:main:telegram:dm:123456" def test_session_key_differs_from_chat_id_for_group(self): """Session key for a group chat includes prefix, unlike raw chat_id.""" diff --git a/tests/gateway/test_session.py b/tests/gateway/test_session.py index 0f39ca6a..cd0104ac 100644 --- a/tests/gateway/test_session.py +++ b/tests/gateway/test_session.py @@ -379,6 +379,15 @@ class TestWhatsAppDMSessionKeyConsistency: key = build_session_key(source) assert key == "agent:main:telegram:dm:99" + def test_distinct_dm_chat_ids_get_distinct_session_keys(self): + """Different DM chats must not collapse into one shared session.""" + first = SessionSource(platform=Platform.TELEGRAM, chat_id="99", chat_type="dm") + second = SessionSource(platform=Platform.TELEGRAM, chat_id="100", chat_type="dm") + + assert build_session_key(first) == "agent:main:telegram:dm:99" + assert build_session_key(second) == "agent:main:telegram:dm:100" + assert build_session_key(first) != build_session_key(second) + def test_discord_group_includes_chat_id(self): """Group/channel keys include chat_type and chat_id.""" source = SessionSource(