Skip to content

Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.

fix(commands): give the admin client the package store its room lists read

Subramanyarao1154cc925576f9
diff --git a/core/switch_core/clients/command_consumer.py b/core/switch_core/clients/command_consumer.py
index e97b6a93d..2e83bbb96 100644
--- a/core/switch_core/clients/command_consumer.py
+++ b/core/switch_core/clients/command_consumer.py
@@ -26,6 +26,7 @@ from switch_core.db.stores.agent_session_store import AgentSessionStore
from switch_core.db.stores.agent_store import AgentStore
from switch_core.db.stores.document_store import DocumentStore
from switch_core.db.stores.external_user_store import ExternalUserStore
+from switch_core.db.stores.package_store import PackageStore
from switch_core.db.stores.reference_store import ReferenceStore
from switch_core.db.stores.room_role_store import RoomRoleStore
from switch_core.db.stores.room_store import RoomStore
@@ -68,6 +69,7 @@ class CommandConsumer(Consumer[SystemActor]):
connections: AgentConnectionRegistry,
document_store: DocumentStore,
reference_store: ReferenceStore,
+ package_store: PackageStore,
agent_session_store: AgentSessionStore,
room_service: RoomService,
user_store: UserStore,
@@ -84,6 +86,7 @@ class CommandConsumer(Consumer[SystemActor]):
self._connections = connections
self._document_store = document_store
self._reference_store = reference_store
+ self._package_store = package_store
self._agent_session_store = agent_session_store
self._room_service = room_service
self._user_store = user_store
diff --git a/core/switch_core/main.py b/core/switch_core/main.py
index 038d868ad..ea394eb45 100644
--- a/core/switch_core/main.py
+++ b/core/switch_core/main.py
@@ -1001,6 +1001,7 @@ async def run(config: SwitchConfig, process_id: str) -> None:
external_user_store=external_user_store,
document_store=document_store,
reference_store=reference_store,
+ package_store=package_store,
agent_session_store=agent_session_store,
room_service=room_service,
user_store=user_store,
diff --git a/core/tests/integration/test_switch_trust_agent_e2e.py b/core/tests/integration/test_switch_trust_agent_e2e.py
index 3237d9c93..319773c08 100644
--- a/core/tests/integration/test_switch_trust_agent_e2e.py
+++ b/core/tests/integration/test_switch_trust_agent_e2e.py
@@ -85,6 +85,7 @@ async def _wire_admin_client(harness: Harness, session_env: SessionEnv) -> None:
external_user_store=session_env.external_user_store,
document_store=session_env.document_store,
reference_store=session_env.reference_store,
+ package_store=session_env.package_store,
agent_session_store=session_env.agent_session_store,
room_service=harness.room_service,
connections=AgentConnectionRegistry(),
diff --git a/core/tests/switch_core/clients/test_command_consumer_ownership.py b/core/tests/switch_core/clients/test_command_consumer_ownership.py
index e54d7289d..e03650c3e 100644
--- a/core/tests/switch_core/clients/test_command_consumer_ownership.py
+++ b/core/tests/switch_core/clients/test_command_consumer_ownership.py
@@ -40,6 +40,7 @@ from switch_core.db.stores.external_user_store import ExternalUserStore
from switch_core.db.stores.media_store import MediaStore
from switch_core.db.stores.message_store import MessageStore
from switch_core.db.stores.ownership_lease_store import OwnershipLeaseStore
+from switch_core.db.stores.package_store import PackageStore
from switch_core.db.stores.reference_store import ReferenceStore
from switch_core.db.stores.room_role_store import RoomRoleStore
from switch_core.db.stores.room_store import RoomStore
@@ -129,6 +130,7 @@ async def _process(
external_user_store=ExternalUserStore(),
document_store=DocumentStore(),
reference_store=ReferenceStore(),
+ package_store=PackageStore(),
agent_session_store=AgentSessionStore(),
room_service=MagicMock(),
user_store=UserStore(),
diff --git a/core/tests/switch_core/clients/test_command_consumer_room_lists.py b/core/tests/switch_core/clients/test_command_consumer_room_lists.py
new file mode 100644
index 000000000..74eb59c28
--- /dev/null
+++ b/core/tests/switch_core/clients/test_command_consumer_room_lists.py
@@ -0,0 +1,92 @@
+"""`!list-documents` and `!list-references` are admin-owned, so the admin
+client's `CommandConsumer` runs them, and they read what the room's packages
+bring through its package store."""
+
+from __future__ import annotations
+
+from contextlib import asynccontextmanager
+from types import SimpleNamespace
+from unittest.mock import AsyncMock, MagicMock
+
+import pytest
+
+from switch_core.bridges.agent.commands import dispatch_admin_command
+from switch_core.clients.command_consumer import CommandConsumer
+
+_ROOM = SimpleNamespace(room_id="!room:test")
+
+
+def _consumer() -> CommandConsumer:
+ package = SimpleNamespace(id="pkg-1", name="Payments context")
+ document = SimpleNamespace(
+ id="doc-1",
+ name="runbook",
+ description="",
+ room_id=None,
+ created_by_agent_id=None,
+ )
+ reference = SimpleNamespace(
+ id="ref-1", name="payments-repo", type="github", description=""
+ )
+ consumer = CommandConsumer(
+ actor=MagicMock(),
+ agent_store=MagicMock(),
+ room_store=MagicMock(),
+ room_role_store=MagicMock(),
+ external_user_store=MagicMock(),
+ connections=MagicMock(),
+ document_store=SimpleNamespace(
+ list_for_room=AsyncMock(return_value=[]),
+ get_many=AsyncMock(return_value=[document]),
+ ),
+ reference_store=SimpleNamespace(
+ list_for_room=AsyncMock(return_value=[]),
+ get=AsyncMock(return_value=reference),
+ ),
+ package_store=SimpleNamespace(
+ list_for_room=AsyncMock(return_value=[package]),
+ list_document_ids_for_package=AsyncMock(return_value=["doc-1"]),
+ list_reference_ids_for_package=AsyncMock(return_value=["ref-1"]),
+ ),
+ agent_session_store=MagicMock(),
+ room_service=MagicMock(),
+ user_store=MagicMock(),
+ agent_admin=MagicMock(),
+ deletion_requests=MagicMock(),
+ frontend_base_url=None,
+ follow_the_conversation_enabled=False,
+ )
+
+ @asynccontextmanager
+ async def _session(): # type: ignore[no-untyped-def]
+ yield SimpleNamespace()
+
+ consumer.actor.session_factory = _session
+ consumer._resolve_room_meta = AsyncMock( # type: ignore[method-assign]
+ return_value=SimpleNamespace(room_id="room-1")
+ )
+ consumer._is_direct_room = AsyncMock(return_value=False) # type: ignore[method-assign]
+ consumer.reply_command = AsyncMock() # type: ignore[method-assign]
+ return consumer
+
+
+ ("command", "listed"),
+ [
+ ("list-documents", "- **runbook** _(via Payments context)_"),
+ ("list-references", "- **payments-repo** _(github, via Payments context)_"),
+ ],
+)
+async def test_the_admin_client_lists_what_the_rooms_packages_bring(
+ command: str, listed: str
+) -> None:
+ consumer = _consumer()
+
+ await dispatch_admin_command(
+ consumer,
+ _ROOM,
+ SimpleNamespace(command=command, args="", thread_id=None, user_id="@a:test"), # type: ignore[arg-type]
+ )
+
+ [reply] = consumer.reply_command.await_args_list
+ assert listed in reply.args[1].splitlines()