mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-06-02 07:11:49 +00:00
fix(send_message): preserve Slack and Matrix thread targets resolved from channel directory
This commit is contained in:
parent
d5a0815c3d
commit
2f28b60a47
2 changed files with 103 additions and 3 deletions
|
|
@ -182,6 +182,81 @@ class TestSendMessageTool:
|
|||
force_document=False,
|
||||
)
|
||||
|
||||
def test_resolved_slack_thread_name_preserves_thread_id(self):
|
||||
slack_cfg = SimpleNamespace(enabled=True, token="xoxb-test", extra={})
|
||||
config = SimpleNamespace(
|
||||
platforms={Platform.SLACK: slack_cfg},
|
||||
get_home_channel=lambda _platform: None,
|
||||
)
|
||||
|
||||
with patch("gateway.config.load_gateway_config", return_value=config), \
|
||||
patch("tools.interrupt.is_interrupted", return_value=False), \
|
||||
patch("gateway.channel_directory.resolve_channel_name", return_value="C123ABCDEF:171.000001"), \
|
||||
patch("model_tools._run_async", side_effect=_run_async_immediately), \
|
||||
patch("tools.send_message_tool._send_to_platform", new=AsyncMock(return_value={"success": True})) as send_mock, \
|
||||
patch("gateway.mirror.mirror_to_session", return_value=True):
|
||||
result = json.loads(
|
||||
send_message_tool(
|
||||
{
|
||||
"action": "send",
|
||||
"target": "slack:ops / topic 171.000001",
|
||||
"message": "hello",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
assert result["success"] is True
|
||||
send_mock.assert_awaited_once_with(
|
||||
Platform.SLACK,
|
||||
slack_cfg,
|
||||
"C123ABCDEF",
|
||||
"hello",
|
||||
thread_id="171.000001",
|
||||
media_files=[],
|
||||
force_document=False,
|
||||
)
|
||||
|
||||
def test_resolved_matrix_thread_name_preserves_thread_id(self):
|
||||
matrix_cfg = SimpleNamespace(
|
||||
enabled=True,
|
||||
token="tok",
|
||||
extra={"homeserver": "https://matrix.example.com"},
|
||||
)
|
||||
config = SimpleNamespace(
|
||||
platforms={Platform.MATRIX: matrix_cfg},
|
||||
get_home_channel=lambda _platform: None,
|
||||
)
|
||||
|
||||
with patch("gateway.config.load_gateway_config", return_value=config), \
|
||||
patch("tools.interrupt.is_interrupted", return_value=False), \
|
||||
patch(
|
||||
"gateway.channel_directory.resolve_channel_name",
|
||||
return_value="!roomid:matrix.example.org:$thread123:matrix.example.org",
|
||||
), \
|
||||
patch("model_tools._run_async", side_effect=_run_async_immediately), \
|
||||
patch("tools.send_message_tool._send_to_platform", new=AsyncMock(return_value={"success": True})) as send_mock, \
|
||||
patch("gateway.mirror.mirror_to_session", return_value=True):
|
||||
result = json.loads(
|
||||
send_message_tool(
|
||||
{
|
||||
"action": "send",
|
||||
"target": "matrix:Ops / topic $thread123",
|
||||
"message": "hello",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
assert result["success"] is True
|
||||
send_mock.assert_awaited_once_with(
|
||||
Platform.MATRIX,
|
||||
matrix_cfg,
|
||||
"!roomid:matrix.example.org",
|
||||
"hello",
|
||||
thread_id="$thread123:matrix.example.org",
|
||||
media_files=[],
|
||||
force_document=False,
|
||||
)
|
||||
|
||||
def test_mirror_receives_current_session_user_id(self):
|
||||
config, _telegram_cfg = _make_config()
|
||||
|
||||
|
|
@ -503,9 +578,8 @@ class TestSendToPlatformChunking:
|
|||
assert all(call == [] for call in sent_calls[:-1])
|
||||
assert sent_calls[-1] == media
|
||||
|
||||
def test_matrix_media_uses_native_adapter_helper(self):
|
||||
|
||||
doc_path = Path("/tmp/test-send-message-matrix.pdf")
|
||||
def test_matrix_media_uses_native_adapter_helper(self, tmp_path):
|
||||
doc_path = tmp_path / "test-send-message-matrix.pdf"
|
||||
doc_path.write_bytes(b"%PDF-1.4 test")
|
||||
|
||||
try:
|
||||
|
|
@ -847,6 +921,16 @@ class TestParseTargetRefDiscord:
|
|||
class TestParseTargetRefMatrix:
|
||||
"""_parse_target_ref correctly handles Matrix room IDs and user MXIDs."""
|
||||
|
||||
def test_matrix_thread_target_is_explicit(self):
|
||||
"""Session-derived Matrix thread targets round-trip as room + event id."""
|
||||
chat_id, thread_id, is_explicit = _parse_target_ref(
|
||||
"matrix",
|
||||
"!HLOQwxYGgFPMPJUSNR:matrix.org:$thread123:matrix.org",
|
||||
)
|
||||
assert chat_id == "!HLOQwxYGgFPMPJUSNR:matrix.org"
|
||||
assert thread_id == "$thread123:matrix.org"
|
||||
assert is_explicit is True
|
||||
|
||||
def test_matrix_room_id_is_explicit(self):
|
||||
"""Matrix room IDs (!) are recognized as explicit targets."""
|
||||
chat_id, thread_id, is_explicit = _parse_target_ref("matrix", "!HLOQwxYGgFPMPJUSNR:matrix.org")
|
||||
|
|
@ -919,6 +1003,12 @@ class TestParseTargetRefE164:
|
|||
class TestParseTargetRefSlack:
|
||||
"""_parse_target_ref recognizes Slack channel/user IDs as explicit."""
|
||||
|
||||
def test_thread_target_is_explicit(self):
|
||||
chat_id, thread_id, is_explicit = _parse_target_ref("slack", "C0B0QV5434G:171.000001")
|
||||
assert chat_id == "C0B0QV5434G"
|
||||
assert thread_id == "171.000001"
|
||||
assert is_explicit is True
|
||||
|
||||
def test_public_channel_id_is_explicit(self):
|
||||
chat_id, thread_id, is_explicit = _parse_target_ref("slack", "C0B0QV5434G")
|
||||
assert chat_id == "C0B0QV5434G"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue