fix(send-message): treat ntfy topic targets as explicit
This commit is contained in:
@@ -4,7 +4,7 @@ import asyncio
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from types import SimpleNamespace
|
||||
from types import ModuleType, SimpleNamespace
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
@@ -163,6 +163,48 @@ def _ensure_slack_mock(monkeypatch):
|
||||
|
||||
|
||||
class TestSendMessageTool:
|
||||
def test_ntfy_topic_target_is_explicit(self):
|
||||
chat_id, thread_id, is_explicit = _parse_target_ref("ntfy", "alerts-channel")
|
||||
|
||||
assert chat_id == "alerts-channel"
|
||||
assert thread_id is None
|
||||
assert is_explicit is True
|
||||
|
||||
def test_ntfy_topic_target_bypasses_channel_directory(self):
|
||||
ntfy_platform = Platform("ntfy")
|
||||
ntfy_cfg = SimpleNamespace(enabled=True, token=None, extra={"topic": "hermes-in"})
|
||||
config = SimpleNamespace(
|
||||
platforms={ntfy_platform: ntfy_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", side_effect=AssertionError("should not resolve ntfy topics")), \
|
||||
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": "ntfy:alerts-channel",
|
||||
"message": "done",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
assert result["success"] is True
|
||||
send_mock.assert_awaited_once_with(
|
||||
ntfy_platform,
|
||||
ntfy_cfg,
|
||||
"alerts-channel",
|
||||
"done",
|
||||
thread_id=None,
|
||||
media_files=[],
|
||||
force_document=False,
|
||||
)
|
||||
|
||||
def test_cron_duplicate_target_is_skipped_and_explained(self):
|
||||
home = SimpleNamespace(chat_id="-1001")
|
||||
config, _telegram_cfg = _make_config()
|
||||
@@ -2433,6 +2475,37 @@ class TestSendViaAdapterStandaloneFallback:
|
||||
standalone_sender_fn=send_fn,
|
||||
)
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_ntfy_adapter_receives_explicit_publish_topic(self, monkeypatch):
|
||||
from tools.send_message_tool import _send_via_adapter
|
||||
|
||||
platform = Platform("ntfy")
|
||||
recorded = {}
|
||||
|
||||
class Adapter:
|
||||
async def send(self, *, chat_id, content, metadata=None):
|
||||
recorded["chat_id"] = chat_id
|
||||
recorded["content"] = content
|
||||
recorded["metadata"] = metadata
|
||||
return SimpleNamespace(success=True, message_id="ntfy-id")
|
||||
|
||||
runner = SimpleNamespace(adapters={platform: Adapter()})
|
||||
fake_gateway_run = ModuleType("gateway.run")
|
||||
fake_gateway_run._gateway_runner_ref = lambda: runner
|
||||
monkeypatch.setitem(sys.modules, "gateway.run", fake_gateway_run)
|
||||
|
||||
result = await _send_via_adapter(
|
||||
platform,
|
||||
SimpleNamespace(extra={"publish_topic": "configured-topic"}),
|
||||
"alerts-channel",
|
||||
"done",
|
||||
)
|
||||
|
||||
assert result == {"success": True, "message_id": "ntfy-id"}
|
||||
assert recorded["chat_id"] == "alerts-channel"
|
||||
assert recorded["content"] == "done"
|
||||
assert recorded["metadata"] == {"publish_topic": "alerts-channel"}
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_standalone_sender_fn_called_when_no_adapter(self, monkeypatch):
|
||||
"""Registry has hook, runner ref returns None: the hook is awaited."""
|
||||
|
||||
Reference in New Issue
Block a user