test(matrix): cover streamed replies and cross-room isolation
This commit is contained in:
1 parent
c1067e2926
commit
df5e6a00e3
1 file changed
+47
@@ -2555,6 +2555,53 @@ async def test_send_delta_threaded_edit_keeps_replace_and_thread_relation(monkey
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_delta_room_reply_edits_the_bot_event(monkeypatch) -> None:
|
||||
channel = MatrixChannel(_make_config(), MessageBus())
|
||||
client = _FakeAsyncClient("", "", "", None)
|
||||
channel.client = client
|
||||
client.room_send_response.event_id = "$bot"
|
||||
times = iter([100.0, 102.0])
|
||||
monkeypatch.setattr(channel, "monotonic_time", lambda: next(times))
|
||||
metadata = {"message_id": "$user", "event_id": "$user"}
|
||||
|
||||
await channel.send_delta("!source:example.org", "Hello", metadata)
|
||||
await channel.send_delta("!source:example.org", " world", metadata)
|
||||
await channel.send_delta("!source:example.org", "", metadata, stream_end=True)
|
||||
|
||||
assert len(client.room_send_calls) == 3
|
||||
assert client.room_send_calls[0]["content"]["m.relates_to"] == {
|
||||
"m.in_reply_to": {"event_id": "$user"},
|
||||
}
|
||||
for call in client.room_send_calls[1:]:
|
||||
assert call["content"]["m.relates_to"] == {
|
||||
"rel_type": "m.replace", "event_id": "$bot",
|
||||
}
|
||||
assert call["content"]["m.new_content"]["body"] == "Hello world"
|
||||
assert call["content"]["m.new_content"]["m.relates_to"] == {
|
||||
"m.in_reply_to": {"event_id": "$user"},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_message_tool_does_not_carry_reply_to_another_room(tmp_path) -> None:
|
||||
from nanobot.agent.tools.message import MessageTool
|
||||
|
||||
channel = MatrixChannel(_make_config(), MessageBus())
|
||||
client = _FakeAsyncClient("", "", "", None)
|
||||
channel.client = client
|
||||
tool = MessageTool(
|
||||
channel.send, default_channel="matrix", default_chat_id="!source:example.org",
|
||||
default_message_id="$user", workspace=tmp_path,
|
||||
)
|
||||
tool._fallback_metadata = {"message_id": "$user", "event_id": "$user"}
|
||||
|
||||
await tool.execute("proactive", channel="matrix", chat_id="!other:example.org")
|
||||
|
||||
assert client.room_send_calls[-1]["room_id"] == "!other:example.org"
|
||||
assert "m.relates_to" not in client.room_send_calls[-1]["content"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_send_delta_stream_end_noop_when_buffer_missing() -> None:
|
||||
channel = MatrixChannel(_make_config(), MessageBus())
|
||||
|
||||
Reference in new issue
Block a user