Skip to content

The agent that grows with you

test(gateway): refuse wakes from another user on a per-user route

unsupportedpastelsd8ac8a589119
diff --git a/tests/gateway/test_automation_notification_category.py b/tests/gateway/test_automation_notification_category.py
index 7b083657c88..d6e2fe91df2 100644
--- a/tests/gateway/test_automation_notification_category.py
+++ b/tests/gateway/test_automation_notification_category.py
@@ -157,18 +157,19 @@ async def test_native_automation_category_roundtrip(tmp_path, monkeypatch, categ
_SOURCE = dict(chat_id='42', chat_type='dm', user_id='42', user_name='human')
-async def _native_owner(tmp_path, monkeypatch, human_message_id):
+async def _native_owner(tmp_path, monkeypatch, human_message_id, fields=_SOURCE, **config):
from gateway.session_ingress_context import native_callback, register_transport_home
from plugins.platforms.discord.adapter import DiscordAdapter
runner, authority = await _authority(tmp_path, monkeypatch)
+ vars(runner.session_store.config).update(config)
adapter = DiscordAdapter(PlatformConfig(enabled=True, token='***', typing_indicator=False))
runner.adapters = {Platform.DISCORD: adapter}
runner._wire_adapter_handlers(adapter)
register_transport_home(runner, None, tmp_path)
monkeypatch.setenv('DISCORD_ALLOWED_USERS', '42')
- source = adapter.build_source(**_SOURCE)
+ source = adapter.build_source(**fields)
# The committed human turn keeps its platform reply anchor on the source.
- human = MessageEvent(text='human', source=adapter.build_source(**_SOURCE, message_id=human_message_id),
+ human = MessageEvent(text='human', source=adapter.build_source(**fields, message_id=human_message_id),
message_id=human_message_id)
with native_callback(runner, human, tmp_path):
await authority.admit_native(human)
diff --git a/tests/gateway/test_automation_wake_route.py b/tests/gateway/test_automation_wake_route.py
index 9fbab1a748b..2c81bc03f50 100644
--- a/tests/gateway/test_automation_wake_route.py
+++ b/tests/gateway/test_automation_wake_route.py
@@ -8,9 +8,9 @@ from gateway.config import Platform, PlatformConfig
from gateway.platforms.event import MessageEvent
from gateway.session import SessionSource
from gateway.session_identity import replace_source
-from hermes_state_runtime import get_session_admission, list_session_admissions
+from hermes_state_runtime import RuntimeStoreError, get_session_admission, list_session_admissions
from tests.gateway.test_automation_compression_media import _admit_human, _discord_owner
-from tests.gateway.test_automation_notification_category import _authority, _native_owner
+from tests.gateway.test_automation_notification_category import _SOURCE, _authority, _native_owner
@pytest.mark.asyncio
@@ -33,6 +33,21 @@ async def test_wake_admits_as_the_committed_turn_when_the_origin_drifted(tmp_pat
authority.db.close()
[email protected]('thread_id', [None, '9'])
+async def test_wake_refuses_another_user_on_a_per_user_route(tmp_path, monkeypatch, thread_id):
+ fields = {**_SOURCE, 'chat_type': 'group', 'thread_id': thread_id}
+ _runner, authority, adapter, _source, metadata = await _native_owner(
+ tmp_path, monkeypatch, 'human-1', fields, group_sessions_per_user=True, thread_sessions_per_user=True)
+ try:
+ other = adapter.build_source(**{**fields, 'user_id': '7'})
+ event = MessageEvent(text='notice', source=other, internal=True, metadata=dict(metadata))
+ with pytest.raises(RuntimeStoreError, match='admission_conflict'):
+ await authority.admit_automation(adapter, event, 'notice')
+ finally:
+ authority.db.close()
+
+
@pytest.mark.asyncio
async def test_subagent_process_notice_enters_its_parent_route_but_not_after_reset(tmp_path, monkeypatch):
runner, _, authority, source = await _discord_owner(tmp_path, monkeypatch)