Files
hermes-agent/tests/tools/test_bot_mode_dm_peer_collision.py
alt-glitch aa8481d437 refactor(bot-mode): the message_agent tool gets its own file
The message_agent model tool (its name and fan-out bound, the schema, the
Bot Chat gate, the injector, the envelope and reply helpers, the handler and
the two agent-context helpers) moves word for word from tools/bot_mode_dm.py
to the new tools/message_agent_tool.py. tools/bot_mode_dm.py keeps the
delivery lane: target resolution, transports, DM files and the background
runner it starts by path.

The tool imports the message cap, the Sender record, the error helper and the
default-home helper from tools/bot_mode_dm.py; the delivery lane names nothing
from the tool. The inline executor row, the turn-time injector and the MCP
refresh re-injection name the new module. The tool's name, schema and replies
are unchanged. Tests change only their imports, the calls that went through
the old module and one docstring line.
2026-11-30 20:41:09 +05:30

45 lines
1.9 KiB
Python

"""A bare ``message_agent`` target naming both a local bot and a registered peer (#145241).
The refusal must point at routes that actually work, and the collision check must not
re-read every profile's friendly names for an ordinary bare-peer send.
"""
import json
from tests.tools.test_bot_mode_dm import _FakeAgent, _capture_spawn, _managed_home, _rename
from tools import bot_mode_probe, bot_relay
from tools.message_agent_tool import message_agent_tool
def test_refusal_never_offers_a_handle_another_peer_owns(tmp_path, monkeypatch):
"""With peers 'ops' and 'aaa', local 'aaa' answers to a peer name too: only @bbb is a
route that reaches a local bot."""
calls = _capture_spawn(monkeypatch)
monkeypatch.setattr(bot_relay, "_hermes_cli", lambda: "hermes")
home = _managed_home(tmp_path, teammates=("aaa", "bbb"), peers=("ops", "aaa"))
_rename(home, "aaa", title="Ops")
_rename(home, "bbb", title="Ops")
result = json.loads(message_agent_tool(target="ops", message="ping", agent=_FakeAgent(home)))
assert "ambiguous" in result["error"]
assert "or @bbb to reach it" in result["error"]
assert "@aaa" not in result["error"]
assert calls == []
def test_bare_peer_send_reads_local_aliases_once(tmp_path, monkeypatch):
"""A peer with no local twin is the common case; its collision check reads the alias map once."""
_capture_spawn(monkeypatch)
monkeypatch.setattr(bot_relay, "_hermes_cli", lambda: "hermes")
monkeypatch.setattr("socket.gethostname", lambda: "eri-mac.local")
home = _managed_home(tmp_path, teammates=("researcher",), peers=("ops",))
reads = []
real = bot_mode_probe.local_alias_map
monkeypatch.setattr(bot_mode_probe, "local_alias_map", lambda root: reads.append(root) or real(root))
result = json.loads(message_agent_tool(target="ops", message="ping", agent=_FakeAgent(home)))
assert result["status"] == "queued"
assert len(reads) == 1