mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-21 10:22:18 +00:00
Salvage of PR #41284 onto current main. Relocates the last 9 inline messaging adapters (+ satellites: telegram_network, feishu_comment/_rules/meeting_invite, wecom_crypto, wecom_callback) from gateway/platforms/ into self-contained bundled plugins under plugins/platforms/<x>/, discovered via the platform registry. Strips the per-platform core touchpoints from gateway/run.py, gateway/config.py, hermes_cli/gateway.py, hermes_cli/setup.py, and tools/send_message_tool.py. Carries forward the migration fixes (explicit enabled:false honored, get_connected_platforms forces discovery, plugin is_connected via gateway.get_env_value, logs --component gateway matches plugins.platforms.*, matrix hidden on Windows). Additionally ports config keys main added since the PR base: the matrix plugin's _apply_yaml_config now also covers allowed_users, ignore_user_patterns, process_notices, and session_scope (the inline gateway/config.py matrix block gained these in the 1340 commits the PR sat open; they would otherwise have been silently dropped on deletion).
60 lines
2.7 KiB
Python
60 lines
2.7 KiB
Python
import types
|
|
|
|
import pytest
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
from gateway.config import PlatformConfig
|
|
|
|
|
|
class TestMatrixExecApprovalReactions:
|
|
@pytest.mark.asyncio
|
|
async def test_send_exec_approval_registers_prompt_and_seeds_reactions(self, monkeypatch):
|
|
monkeypatch.setenv("MATRIX_ALLOWED_USERS", "@liizfq:liizfq.top")
|
|
from plugins.platforms.matrix.adapter import MatrixAdapter
|
|
|
|
adapter = MatrixAdapter(PlatformConfig(enabled=True, token="tok", extra={"homeserver": "https://matrix.example.org"}))
|
|
adapter._client = types.SimpleNamespace()
|
|
adapter.send = AsyncMock(return_value=types.SimpleNamespace(success=True, message_id="$evt1"))
|
|
adapter._send_reaction = AsyncMock(return_value="$r")
|
|
|
|
result = await adapter.send_exec_approval(
|
|
chat_id="!room:example.org",
|
|
command="rm -rf /tmp/test",
|
|
session_key="sess-1",
|
|
description="dangerous",
|
|
)
|
|
|
|
assert result.success is True
|
|
assert adapter._approval_prompt_by_session["sess-1"] == "$evt1"
|
|
assert adapter._approval_prompts_by_event["$evt1"].session_key == "sess-1"
|
|
assert adapter._send_reaction.await_count == 3
|
|
emojis = [call.args[2] for call in adapter._send_reaction.await_args_list]
|
|
assert emojis == ["✅", "♾️", "❌"]
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_reaction_resolves_pending_approval(self, monkeypatch):
|
|
monkeypatch.setenv("MATRIX_ALLOWED_USERS", "@liizfq:liizfq.top")
|
|
from plugins.platforms.matrix.adapter import MatrixAdapter, _MatrixApprovalPrompt
|
|
|
|
adapter = MatrixAdapter(PlatformConfig(enabled=True, token="tok", extra={"homeserver": "https://matrix.example.org"}))
|
|
# Resolve user_id so _is_self_sender doesn't defensively drop all traffic (#15763).
|
|
adapter._user_id = "@bot:example.org"
|
|
adapter._approval_prompts_by_event["$target"] = _MatrixApprovalPrompt(
|
|
session_key="sess-1", chat_id="!room:example.org", message_id="$target"
|
|
)
|
|
adapter._approval_prompt_by_session["sess-1"] = "$target"
|
|
|
|
content = {"m.relates_to": {"event_id": "$target", "key": "✅"}}
|
|
event = types.SimpleNamespace(
|
|
sender="@liizfq:liizfq.top",
|
|
event_id="$react1",
|
|
room_id="!room:example.org",
|
|
content=content,
|
|
)
|
|
|
|
with patch("tools.approval.resolve_gateway_approval", return_value=1) as mock_resolve:
|
|
await adapter._on_reaction(event)
|
|
|
|
mock_resolve.assert_called_once_with("sess-1", "once")
|
|
assert "$target" not in adapter._approval_prompts_by_event
|
|
assert "sess-1" not in adapter._approval_prompt_by_session
|