The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(cron): pin the #115656 chain end to end, drop the duplicate direct-lane pins
teknium16ee6c05b2f4c
diff --git a/tests/cron/test_cron_send_authorized_transport.py b/tests/cron/test_cron_send_authorized_transport.pydeleted file mode 100644index df745ebb929..00000000000--- a/tests/cron/test_cron_send_authorized_transport.py+++ /dev/null@@ -1,125 +0,0 @@-"""Live-lane text send uses the already-authorized transport (#115656).--``_resolve_target_transport`` authorizes a credentialless satellite's exact-profile_routes target through the PRIMARY adapter (the SharedRouteAdapters-grant, #101113), building a transport with the satellite's own-``platforms.<p>`` block force-enabled. ``_live_send_text`` then rebuilt a-``DeliveryRouter`` over the plain ``target_adapters`` dict and re-resolved:-the satellite's real (disabled) block vetoed the grant, the second-resolution yielded None, and delivery fell through to the credentialless-standalone lane and failed.--The live send must go through the already-authorized ``t.transport`` — no-second resolution. These tests pin it with a REAL DeliveryRouter and a-satellite config whose own ``platforms.discord`` block is disabled: the only-way the send succeeds is via the authorized transport.-"""-import asyncio-from concurrent.futures import Future-from unittest.mock import MagicMock, patch--import yaml--from cron.scheduler import _deliver_result-from cron.scheduler_preflight import SharedRouteAdapters, _primary_profile_routes_for_current_home-from gateway.config import Platform, PlatformConfig-from hermes_constants import reset_hermes_home_override, set_hermes_home_override--PRIMARY_YAML = {- "gateway": {- "multiplex_profiles": True,- "profile_routes": [- {"name": "fit", "platform": "discord", "chat_id": "1543065293755256852", "profile": "fitness"},- ],- }-}--CHAT_ID = "1543065293755256852"---def _job(chat_id: str) -> dict:- return {"id": "a7ae1520356c", "name": "brief", "deliver": f"discord:{chat_id}"}---def _run(job, adapters):- """Drive ``_deliver_result`` with a live loop and a real DeliveryRouter.-- The satellite's own ``platforms.discord`` block is DISABLED (a connector- the credentialless satellite never runs) — the shape under which a second- router-side resolution yields None.- """- loop = MagicMock()- loop.is_running.return_value = True-- def fake_run_coro(coro, _loop):- future = Future()- future.set_result(asyncio.run(coro))- return future-- standalone = []-- async def _fake_send_to_platform(platform, pconfig, chat_id, text, **kwargs):- standalone.append(chat_id)- return {"success": False, "error": "DISCORD_BOT_TOKEN is not set"}-- config = MagicMock()- config.platforms = {Platform.DISCORD: PlatformConfig(enabled=False)}- config.get_home_channel = lambda p: None- with patch("gateway.config.load_gateway_config", return_value=config), \- patch("cron.scheduler.load_config", return_value={"cron": {"wrap_response": False}}), \- patch("tools.send_message_tool._send_to_platform", _fake_send_to_platform), \- patch("asyncio.run_coroutine_threadsafe", side_effect=fake_run_coro):- error = _deliver_result(job, "hello", adapters=adapters, loop=loop)- return error, standalone---def _primary_adapter():- adapter = MagicMock()- adapter.sent = []-- async def send(chat_id, content, metadata=None):- adapter.sent.append(chat_id)- return {"success": True, "message_id": "m1"}-- adapter.send = send- return adapter---def _shared_view(tmp_path, monkeypatch, primary):- root = tmp_path / "root"- fitness_home = root / "profiles" / "fitness"- fitness_home.mkdir(parents=True)- (root / "config.yaml").write_text(yaml.safe_dump(PRIMARY_YAML), encoding="utf-8")- monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)- token = set_hermes_home_override(str(fitness_home))- try:- yield SharedRouteAdapters(- {Platform.DISCORD: primary}, _primary_profile_routes_for_current_home()- )- finally:- reset_hermes_home_override(token)---def test_satellite_disabled_block_sends_through_authorized_transport(tmp_path, monkeypatch):- """Exact route + disabled satellite block: live lane delivers, no standalone."""- primary = _primary_adapter()- for shared in _shared_view(tmp_path, monkeypatch, primary):- error, standalone = _run(_job(CHAT_ID), shared)- assert error is None, error- assert primary.sent == [CHAT_ID]- assert standalone == []---def test_satellite_disabled_block_still_fails_closed_off_route(tmp_path, monkeypatch):- """Unmatched chat: the primary bot is NEVER used (#101113 fail-closed).-- With the satellite's own block disabled, an off-route chat fails closed- at transport resolution (never reaching any sender) — the pin is that the- primary adapter stays silent and the run reports an error.- """- primary = _primary_adapter()- for shared in _shared_view(tmp_path, monkeypatch, primary):- error, standalone = _run(_job("424242"), shared)- assert error is not None- assert primary.sent == []- assert standalone == []diff --git a/tests/gateway/test_cron_delivery_housekeeping.py b/tests/gateway/test_cron_delivery_housekeeping.pyindex c1c21c49667..5bea1f10120 100644--- a/tests/gateway/test_cron_delivery_housekeeping.py+++ b/tests/gateway/test_cron_delivery_housekeeping.py@@ -156,3 +156,73 @@ def test_multiplex_housekeeping_uses_primary_routes_for_credentialless_satellite("routed", root_adapters, ["route-to-secondary"]),("drain", routed),]+++def test_primary_drain_delivers_credentialless_satellite_queue_row_through_primary_adapter(+ tmp_path, monkeypatch,+):+ """Regression for #115656 (the chain #101113's tests skipped): an external restart-safe worker+ durably queues a routed satellite's result; the PRIMARY gateway PID claims the row under the+ satellite's scope and must send it through its live adapter, never the satellite's+ credentialless standalone lane. Before, ``_live_send_text`` re-resolved the transport from the+ plain adapter dict and reported ``No adapter configured for discord``.+ """+ import asyncio+ import threading+ from unittest.mock import patch++ import yaml++ from cron import delivery_queue+ from gateway.config import Platform+ from hermes_constants import reset_hermes_home_override, set_hermes_home_override++ root = tmp_path / "root"+ satellite_home = root / "profiles" / "satellite"+ (satellite_home / "cron").mkdir(parents=True)+ (root / "config.yaml").write_text(yaml.safe_dump({+ "gateway": {"multiplex_profiles": True, "profile_routes": [+ {"platform": "discord", "guild_id": "G1", "chat_id": "C1", "profile": "satellite"}]},+ }), encoding="utf-8")+ # The satellite names its home channel but holds no token: block present, ``enabled`` False.+ (satellite_home / "config.yaml").write_text(+ yaml.safe_dump({"platforms": {"discord": {"home_channel": "C1"}}}), encoding="utf-8")+ monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)+ monkeypatch.delenv("DISCORD_BOT_TOKEN", raising=False)++ sent, standalone = [], []++ class PrimaryDiscord:+ async def send(self, chat_id, content, metadata=None):+ sent.append(chat_id)+ return {"success": True, "message_id": "m1"}++ async def _standalone(platform, pconfig, chat_id, text, **kwargs):+ standalone.append(chat_id)+ return {"success": False, "error": "DISCORD_BOT_TOKEN is not set"}++ # The external worker: no adapters, queues under the OWNING (satellite) home.+ token = set_hermes_home_override(str(satellite_home))+ try:+ delivery_queue.enqueue("exec-1", {"id": "job1", "name": "probe", "deliver": "discord:C1"}, "hello")+ finally:+ reset_hermes_home_override(token)++ loop = asyncio.new_event_loop()+ threading.Thread(target=loop.run_forever, daemon=True).start()+ runner = SimpleNamespace(config=SimpleNamespace(multiplex_profiles=True), _profile_adapters={"satellite": {}})+ monkeypatch.setattr(gateway_run, "_handoff_watch_scopes", lambda _r: [("satellite", satellite_home)])+ try:+ with patch("tools.send_message_tool._send_to_platform", _standalone), \+ patch("cron.scheduler.load_config", return_value={"cron": {"wrap_response": False}}):+ gateway_run._drain_restart_safe_cron_deliveries({Platform.DISCORD: PrimaryDiscord()}, loop, runner)+ finally:+ loop.call_soon_threadsafe(loop.stop)++ token = set_hermes_home_override(str(satellite_home))+ try:+ row = delivery_queue.get_status("exec-1")+ finally:+ reset_hermes_home_override(token)+ assert row["status"] == "delivered", row+ assert sent == ["C1"] and standalone == []