Open-source AI teammates in Slack, Teams, Discord, Telegram and Mattermost. Self-host it, with any agent harness and any model.
Python agent-orchestrationaiai-agentschatopsdiscordlangchainmcpmicrosoft-teamsmulti-agentopen-sourceopenaiself-hostedslack
test(agents): list_all_rooms paging stays inside the tenant
raullopez-sandbox7ed841e967e4
diff --git a/core/tests/switch_core/bridges/agent/test_list_all_rooms_paging.py b/core/tests/switch_core/bridges/agent/test_list_all_rooms_paging.pyindex 64019d844..5a6349d61 100644--- a/core/tests/switch_core/bridges/agent/test_list_all_rooms_paging.py+++ b/core/tests/switch_core/bridges/agent/test_list_all_rooms_paging.py@@ -4,6 +4,7 @@ match a name in any case. Real Postgres."""from __future__ import annotationsimport base64+import uuidfrom datetime import UTC, datetime, timedeltafrom types import SimpleNamespace@@ -11,8 +12,10 @@ import pytestfrom sqlalchemy.ext.asyncio import AsyncSession, async_sessionmakerfrom switch_core.bridges.agent.protocol.agent_core import AgentCore-from switch_core.db.models import Room+from switch_core.db.models import Room, Tenantfrom switch_core.db.stores.room_store import RoomStore+from switch_core.tenant_context import tenant_scope+from tests.conftest import RLSHarness_START = datetime(2026, 1, 1, tzinfo=UTC)@@ -95,3 +98,48 @@ async def test_a_bad_cursor_or_limit_is_refused(for limit in (0, 501):with pytest.raises(ValueError, match="limit"):await _list(session_factory, limit=limit)+++async def _tenant_with_rooms(+ owner: async_sessionmaker[AsyncSession], count: int+) -> str:+ tenant_id = f"tenant-{uuid.uuid4().hex[:8]}"+ async with owner() as session:+ session.add(Tenant(id=tenant_id, slug=tenant_id, name=tenant_id))+ await session.flush()+ session.add_all(+ Room(+ tenant_id=tenant_id,+ transport_room_id=f"!{tenant_id}-{index}:test",+ name=f"{tenant_id} room {index}",+ description="",+ created_at=_START + timedelta(minutes=index),+ )+ for index in range(count)+ )+ await session.commit()+ return tenant_id+++async def test_paging_never_crosses_tenants(rls_harness: RLSHarness) -> None:+ """Through the role the policies apply to: a tenant pages only its own+ rooms, and a cursor from another tenant only positions a page in them."""+ tenant_a = await _tenant_with_rooms(rls_harness.owner, 3)+ tenant_b = await _tenant_with_rooms(rls_harness.owner, 3)++ with tenant_scope(tenant_b):+ _, b_cursor = await _list(rls_harness.restricted, limit=1)+ assert b_cursor is not None++ with tenant_scope(tenant_a):+ seen: list[Room] = []+ cursor = None+ while True:+ rooms, cursor = await _list(rls_harness.restricted, limit=2, cursor=cursor)+ seen.extend(rooms)+ if cursor is None:+ break+ foreign, _ = await _list(rls_harness.restricted, cursor=b_cursor)+ assert {room.tenant_id for room in seen} == {tenant_a}+ assert len(seen) == 3+ assert {room.tenant_id for room in foreign} <= {tenant_a}