The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: drain durable cron failure deliveries before asserting sends
Teknium9b753d3b3fe7
diff --git a/tests/cron/test_cron_failure_deliver.py b/tests/cron/test_cron_failure_deliver.pyindex 3bbb9226c9c..9409f9bc46a 100644--- a/tests/cron/test_cron_failure_deliver.py+++ b/tests/cron/test_cron_failure_deliver.py@@ -43,10 +43,9 @@ def cron_env(tmp_path, monkeypatch):def run_env(monkeypatch, tmp_path):"""Drive run_one_job with the REAL delivery path down to a fake sender.- Bookkeeping primitives are stubbed (recorded), but _deliver_result and- _resolve_delivery_targets are the genuine articles — the send that would- leave the process is captured at the platform-registry sender seam,- exactly where a real slack delivery exits.+ Bookkeeping primitives are recorded; durable enqueue, gateway drain and+ target resolution are real. Only the outbound platform sender is replaced.+ Tests drain explicitly so queue admission cannot masquerade as delivery."""home = tmp_path / "hermes-home"home.mkdir()@@ -56,11 +55,13 @@ def run_env(monkeypatch, tmp_path):monkeypatch.setenv("HERMES_HOME", str(home))send_calls = []+ transport = {"success": True}async def fake_sender(pconfig, chat_id, message, *, thread_id=None,media_files=None, force_document=False, caption=None):send_calls.append({"chat_id": chat_id, "message": message})- return {"success": True, "chat_id": chat_id, "message_id": "1.2"}+ return {"success": transport["success"], "chat_id": chat_id,+ "message_id": "1.2", "error": None if transport["success"] else "transport refused"}import gateway.platform_registry as regimport hermes_cli.plugins as hp@@ -74,7 +75,23 @@ def run_env(monkeypatch, tmp_path):monkeypatch.setattr(entry, "standalone_sender_fn", fake_sender)monkeypatch.setattr(hp, "discover_plugins", lambda *a, **k: None)- state = {"send": send_calls, "marked": [], "saved": [], "finished": []}+ state: dict = {"send": send_calls, "marked": [], "saved": [], "finished": []}+ from cron import delivery_queue+ monkeypatch.setattr(delivery_queue, "DELIVERY_DB", home / "cron" / "deliveries.db")++ def drain(*, for_failure):+ assert send_calls == [], "delivery must wait for the gateway drain"+ pending = delivery_queue.get_status("exec-t")+ assert pending is not None and pending["status"] == "pending"+ assert bool(pending["for_failure"]) is for_failure+ assert s.drain_delivery_queue(adapters={}, loop=None) == 1+ result = delivery_queue.get_status("exec-t")+ assert result is not None+ assert result["status"] == ("delivered" if transport["success"] else "failed")+ assert s.drain_delivery_queue(adapters={}, loop=None) == 0++ state["drain"] = drain+ state["transport"] = transportmonkeypatch.setattr(s, "create_execution", lambda *_a, **_kw: {"id": "exec-t"})monkeypatch.setattr(s, "claim_dispatch", lambda _job_id: True)@@ -121,6 +138,7 @@ class TestFailureDeliverRouting:s.run_one_job({"id": "j1", "name": "scout", "deliver": "slack:D0MAIN"})+ run_env["drain"](for_failure=True)assert [c["chat_id"] for c in run_env["send"]] == ["D0MAIN"]assert "failed" in run_env["send"][0]["message"].lower()@@ -156,6 +174,7 @@ class TestFailureDeliverRouting:"deliver": "slack:D0MAIN", "failure_deliver": "slack:D0ALERTS",})+ run_env["drain"](for_failure=True)assert [c["chat_id"] for c in run_env["send"]] == ["D0ALERTS"]assert "failed" in run_env["send"][0]["message"].lower()@@ -170,6 +189,7 @@ class TestFailureDeliverRouting:})assert ok is True+ run_env["drain"](for_failure=False)assert [c["chat_id"] for c in run_env["send"]] == ["D0MAIN"]assert "all good, here is the brief" in run_env["send"][0]["message"]@@ -363,6 +383,9 @@ class TestOutcomeBookkeeping:):alerted = []monkeypatch.setattr(s, "_mark_incident_alerted", alerted.append)+ monkeypatch.setattr(+ s, "_upsert_incident_for_failure", lambda *_a, **_kw: (False, "inc-local")+ )monkeypatch.setattr(s, "run_job", _failing_run_job())s.run_one_job({@@ -372,13 +395,15 @@ class TestOutcomeBookkeeping:assert run_env["send"] == []assert self._outcome(run_env) == "suppressed"+ assert s.drain_delivery_queue(adapters={}, loop=None) == 0assert alerted == [], "silenced failure must NOT mark incident alerted"+ @pytest.mark.parametrize("transport_success", [True, False])def test_fd_explicit_target_failure_records_delivered(- self, run_env, monkeypatch+ self, run_env, monkeypatch, transport_success):"""deliver=origin (unresolvable) + failure_deliver=explicit target:- the notice IS delivered — outcome must say so, not 'not_configured'."""+ the notice is queued then delivered, never 'not_configured'."""alerted = []monkeypatch.setattr(s, "_mark_incident_alerted", alerted.append)monkeypatch.setattr(@@ -391,13 +416,19 @@ class TestOutcomeBookkeeping:"deliver": "origin", "failure_deliver": "slack:D0OPS",})+ run_env["transport"]["success"] = transport_success+ assert self._outcome(run_env) == "queued"+ assert alerted == [], "admission alone must NOT mark incident alerted"+ run_env["drain"](for_failure=True)assert [c["chat_id"] for c in run_env["send"]] == ["D0OPS"]- assert self._outcome(run_env) == "delivered"- assert alerted == ["inc-b1"], "delivered failure ping must mark incident alerted"+ assert "failed" in run_env["send"][0]["message"].lower()+ assert alerted == (["inc-b1"] if transport_success else []), (+ "only a delivered failure ping may mark the incident alerted"+ )def test_success_outcome_still_reads_deliver_lane(self, run_env, monkeypatch):"""Success bookkeeping is untouched: fd set, success delivers to- deliver and records 'delivered'."""+ deliver and records queue admission before the actual send."""monkeypatch.setattr(s, "run_job", _succeeding_run_job())s.run_one_job({@@ -405,8 +436,9 @@ class TestOutcomeBookkeeping:"deliver": "slack:D0MAIN", "failure_deliver": "local",})+ assert self._outcome(run_env) == "queued"+ run_env["drain"](for_failure=False)assert [c["chat_id"] for c in run_env["send"]] == ["D0MAIN"]- assert self._outcome(run_env) == "delivered"class TestPreflightAndDashboardLanes: