feat(task-7): verify matrix per-room context routing
This commit is contained in:
parent
c11c8ecfbf
commit
07c5078934
2 changed files with 56 additions and 3 deletions
|
|
@ -253,6 +253,56 @@ async def test_bot_assigns_platform_chat_id_for_existing_managed_room():
|
|||
runtime.dispatcher.dispatch.assert_awaited_once()
|
||||
|
||||
|
||||
async def test_bot_routes_plain_messages_via_platform_chat_id():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
await set_room_meta(
|
||||
runtime.store,
|
||||
"!chat1:example.org",
|
||||
{
|
||||
"chat_id": "C1",
|
||||
"matrix_user_id": "@alice:example.org",
|
||||
"platform_chat_id": "matrix:ctx-1",
|
||||
},
|
||||
)
|
||||
client = SimpleNamespace(user_id="@bot:example.org")
|
||||
bot = MatrixBot(client, runtime)
|
||||
bot._send_all = AsyncMock()
|
||||
runtime.dispatcher.dispatch = AsyncMock(return_value=[])
|
||||
room = SimpleNamespace(room_id="!chat1:example.org")
|
||||
event = SimpleNamespace(sender="@alice:example.org", body="hello")
|
||||
|
||||
await bot.on_room_message(room, event)
|
||||
|
||||
dispatched = runtime.dispatcher.dispatch.await_args.args[0]
|
||||
assert dispatched.chat_id == "matrix:ctx-1"
|
||||
assert dispatched.text == "hello"
|
||||
|
||||
|
||||
async def test_bot_keeps_commands_on_local_chat_id():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
await set_room_meta(
|
||||
runtime.store,
|
||||
"!chat1:example.org",
|
||||
{
|
||||
"chat_id": "C1",
|
||||
"matrix_user_id": "@alice:example.org",
|
||||
"platform_chat_id": "matrix:ctx-1",
|
||||
},
|
||||
)
|
||||
client = SimpleNamespace(user_id="@bot:example.org")
|
||||
bot = MatrixBot(client, runtime)
|
||||
bot._send_all = AsyncMock()
|
||||
runtime.dispatcher.dispatch = AsyncMock(return_value=[])
|
||||
room = SimpleNamespace(room_id="!chat1:example.org")
|
||||
event = SimpleNamespace(sender="@alice:example.org", body="!rename New")
|
||||
|
||||
await bot.on_room_message(room, event)
|
||||
|
||||
dispatched = runtime.dispatcher.dispatch.await_args.args[0]
|
||||
assert dispatched.chat_id == "C1"
|
||||
assert dispatched.command == "rename"
|
||||
|
||||
|
||||
async def test_bot_leaves_existing_platform_chat_id_unchanged():
|
||||
runtime = build_runtime(platform=MockPlatformClient())
|
||||
await set_room_meta(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue