mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-16 14:32:34 +00:00
Session-based channel discovery resurrected historical origins for platforms with no connected adapter, exposing stale send_message targets that can no longer deliver. Gate both the enum loop and the plugin-registry loop on the live adapter set. Surgical reapply of the channel-directory portion of PR #25959 (branch was 6.5k commits stale; the text-batching delay changes bundled there were dropped - separate concern, defaults have since been retuned on main). Co-authored-by: Marco-Olivier Lavoie <marcolivier@gmail.com>
46 lines
1.8 KiB
Python
46 lines
1.8 KiB
Python
"""Session-based channel discovery must not resurrect disconnected platforms.
|
|
|
|
Surgical reapply of the directory portion of PR #25959: historical session
|
|
origins for platforms with no connected adapter must not become active
|
|
send_message targets."""
|
|
|
|
import asyncio
|
|
from unittest.mock import patch
|
|
|
|
from gateway.channel_directory import build_channel_directory
|
|
from gateway.platforms.base import Platform
|
|
|
|
|
|
def test_does_not_resurrect_disconnected_platforms_from_session_history(tmp_path, monkeypatch):
|
|
cache_file = tmp_path / "channel_directory.json"
|
|
|
|
calls = []
|
|
|
|
def fake_build_from_sessions(plat_name):
|
|
calls.append(plat_name)
|
|
return {"channels": [{"id": "1", "name": "old"}]}
|
|
|
|
with patch("gateway.channel_directory._build_from_sessions", side_effect=fake_build_from_sessions), \
|
|
patch("gateway.channel_directory.DIRECTORY_PATH", cache_file):
|
|
# Only telegram is connected; no discord/slack/whatsapp adapters.
|
|
directory = asyncio.run(build_channel_directory({Platform.TELEGRAM: object()}))
|
|
|
|
plats = directory["platforms"]
|
|
assert "telegram" in plats
|
|
# Disconnected platforms must not appear via session discovery.
|
|
for stale in ("whatsapp", "signal", "matrix"):
|
|
assert stale not in plats, f"{stale} resurrected from session history"
|
|
assert set(calls) <= {"telegram"}
|
|
|
|
|
|
def test_connected_platform_still_uses_session_discovery(tmp_path):
|
|
cache_file = tmp_path / "channel_directory.json"
|
|
|
|
with patch(
|
|
"gateway.channel_directory._build_from_sessions",
|
|
return_value={"channels": []},
|
|
) as mock_sessions, patch("gateway.channel_directory.DIRECTORY_PATH", cache_file):
|
|
directory = asyncio.run(build_channel_directory({Platform.TELEGRAM: object()}))
|
|
|
|
assert "telegram" in directory["platforms"]
|
|
mock_sessions.assert_any_call("telegram")
|