diff --git a/tests/tools/test_send_message_tool.py b/tests/tools/test_send_message_tool.py index 17c95d797..a174cf24f 100644 --- a/tests/tools/test_send_message_tool.py +++ b/tests/tools/test_send_message_tool.py @@ -622,6 +622,25 @@ class TestSendToPlatformChunking: finally: doc_path.unlink(missing_ok=True) + def test_matrix_text_only_uses_lightweight_path(self): + """Text-only Matrix sends should NOT go through the heavy adapter path.""" + helper = AsyncMock() + lightweight = AsyncMock(return_value={"success": True, "platform": "matrix", "chat_id": "!room:ex.com", "message_id": "$txt"}) + with patch("tools.send_message_tool._send_matrix_via_adapter", helper), \ + patch("tools.send_message_tool._send_matrix", lightweight): + result = asyncio.run( + _send_to_platform( + Platform.MATRIX, + SimpleNamespace(enabled=True, token="tok", extra={"homeserver": "https://matrix.example.com"}), + "!room:ex.com", + "just text, no files", + ) + ) + + assert result["success"] is True + helper.assert_not_awaited() + lightweight.assert_awaited_once() + def test_send_matrix_via_adapter_sends_document(self, tmp_path): file_path = tmp_path / "report.pdf" file_path.write_bytes(b"%PDF-1.4 test") diff --git a/tools/send_message_tool.py b/tools/send_message_tool.py index cc681adc7..8c673c170 100644 --- a/tools/send_message_tool.py +++ b/tools/send_message_tool.py @@ -404,8 +404,8 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None, last_result = result return last_result - # --- Matrix: use the native adapter helper for text + media --- - if platform == Platform.MATRIX: + # --- Matrix: use the native adapter helper when media is present --- + if platform == Platform.MATRIX and media_files: last_result = None for i, chunk in enumerate(chunks): is_last = (i == len(chunks) - 1)