mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
fix: gate Matrix adapter path on media_files presence
Text-only Matrix sends should continue using the lightweight _send_matrix() HTTP helper (~100ms). Only route through the heavy MatrixAdapter (full sync + E2EE setup) when media files are present. Adds test verifying text-only messages don't take the adapter path.
This commit is contained in:
parent
276ed5c399
commit
c850a40e4e
2 changed files with 21 additions and 2 deletions
|
|
@ -622,6 +622,25 @@ class TestSendToPlatformChunking:
|
||||||
finally:
|
finally:
|
||||||
doc_path.unlink(missing_ok=True)
|
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):
|
def test_send_matrix_via_adapter_sends_document(self, tmp_path):
|
||||||
file_path = tmp_path / "report.pdf"
|
file_path = tmp_path / "report.pdf"
|
||||||
file_path.write_bytes(b"%PDF-1.4 test")
|
file_path.write_bytes(b"%PDF-1.4 test")
|
||||||
|
|
|
||||||
|
|
@ -404,8 +404,8 @@ async def _send_to_platform(platform, pconfig, chat_id, message, thread_id=None,
|
||||||
last_result = result
|
last_result = result
|
||||||
return last_result
|
return last_result
|
||||||
|
|
||||||
# --- Matrix: use the native adapter helper for text + media ---
|
# --- Matrix: use the native adapter helper when media is present ---
|
||||||
if platform == Platform.MATRIX:
|
if platform == Platform.MATRIX and media_files:
|
||||||
last_result = None
|
last_result = None
|
||||||
for i, chunk in enumerate(chunks):
|
for i, chunk in enumerate(chunks):
|
||||||
is_last = (i == len(chunks) - 1)
|
is_last = (i == len(chunks) - 1)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue