fix: resolve listed messaging targets consistently
This commit is contained in:
@@ -90,8 +90,9 @@ class TestResolveDeliveryTarget:
|
||||
with patch(
|
||||
"gateway.channel_directory.resolve_channel_name",
|
||||
return_value="12345678901234@lid",
|
||||
):
|
||||
) as resolve_mock:
|
||||
result = _resolve_delivery_target(job)
|
||||
resolve_mock.assert_called_once_with("whatsapp", "Alice (dm)")
|
||||
assert result == {
|
||||
"platform": "whatsapp",
|
||||
"chat_id": "12345678901234@lid",
|
||||
@@ -112,6 +113,20 @@ class TestResolveDeliveryTarget:
|
||||
"thread_id": None,
|
||||
}
|
||||
|
||||
def test_human_friendly_topic_label_preserves_thread_id(self):
|
||||
"""Resolved Telegram topic labels should split chat_id and thread_id."""
|
||||
job = {"deliver": "telegram:Coaching Chat / topic 17585 (group)"}
|
||||
with patch(
|
||||
"gateway.channel_directory.resolve_channel_name",
|
||||
return_value="-1009999:17585",
|
||||
):
|
||||
result = _resolve_delivery_target(job)
|
||||
assert result == {
|
||||
"platform": "telegram",
|
||||
"chat_id": "-1009999",
|
||||
"thread_id": "17585",
|
||||
}
|
||||
|
||||
def test_raw_id_not_mangled_when_directory_returns_none(self):
|
||||
"""deliver: 'whatsapp:12345@lid' passes through when directory has no match."""
|
||||
job = {"deliver": "whatsapp:12345@lid"}
|
||||
|
||||
@@ -119,6 +119,19 @@ class TestResolveChannelName:
|
||||
with self._setup(tmp_path, platforms):
|
||||
assert resolve_channel_name("telegram", "Coaching Chat / topic 17585") == "-1001:17585"
|
||||
|
||||
def test_display_label_with_type_suffix_resolves(self, tmp_path):
|
||||
platforms = {
|
||||
"telegram": [
|
||||
{"id": "123", "name": "Alice", "type": "dm"},
|
||||
{"id": "456", "name": "Dev Group", "type": "group"},
|
||||
{"id": "-1001:17585", "name": "Coaching Chat / topic 17585", "type": "group"},
|
||||
]
|
||||
}
|
||||
with self._setup(tmp_path, platforms):
|
||||
assert resolve_channel_name("telegram", "Alice (dm)") == "123"
|
||||
assert resolve_channel_name("telegram", "Dev Group (group)") == "456"
|
||||
assert resolve_channel_name("telegram", "Coaching Chat / topic 17585 (group)") == "-1001:17585"
|
||||
|
||||
|
||||
class TestBuildFromSessions:
|
||||
def _write_sessions(self, tmp_path, sessions_data):
|
||||
|
||||
@@ -203,6 +203,44 @@ class TestSendMessageTool:
|
||||
media_files=[],
|
||||
)
|
||||
|
||||
def test_display_label_target_resolves_via_channel_directory(self, tmp_path):
|
||||
config, telegram_cfg = _make_config()
|
||||
cache_file = tmp_path / "channel_directory.json"
|
||||
cache_file.write_text(json.dumps({
|
||||
"updated_at": "2026-01-01T00:00:00",
|
||||
"platforms": {
|
||||
"telegram": [
|
||||
{"id": "-1001:17585", "name": "Coaching Chat / topic 17585", "type": "group"}
|
||||
]
|
||||
},
|
||||
}))
|
||||
|
||||
with patch("gateway.channel_directory.DIRECTORY_PATH", cache_file), \
|
||||
patch("gateway.config.load_gateway_config", return_value=config), \
|
||||
patch("tools.interrupt.is_interrupted", return_value=False), \
|
||||
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": "telegram:Coaching Chat / topic 17585 (group)",
|
||||
"message": "hello",
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
assert result["success"] is True
|
||||
send_mock.assert_awaited_once_with(
|
||||
Platform.TELEGRAM,
|
||||
telegram_cfg,
|
||||
"-1001",
|
||||
"hello",
|
||||
thread_id="17585",
|
||||
media_files=[],
|
||||
)
|
||||
|
||||
def test_media_only_message_uses_placeholder_for_mirroring(self):
|
||||
config, telegram_cfg = _make_config()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user