The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(kanban): pin scope binding and transport fail-open at both goal gates
teknium140e2aa69e796
diff --git a/tests/hermes_cli/test_kanban_goal_judge_affinity.py b/tests/hermes_cli/test_kanban_goal_judge_affinity.pyindex 2a2e65f30d7..c2d3e7d0c96 100644--- a/tests/hermes_cli/test_kanban_goal_judge_affinity.py+++ b/tests/hermes_cli/test_kanban_goal_judge_affinity.py@@ -1,11 +1,10 @@-"""Goal-judge handoff gates bind the per-task relay-affinity scope.--Both terminal-handoff gates (``hermes_cli.kanban`` for the CLI dispatcher,-``tools.kanban_tools`` for worker tool calls) run outside any agent turn, so-without a bound scope the relay rejects the judge call (400 MissingSessionID)-(#113669). Fail-open on transport failure belongs to the shared gate fix-(#73119); these tests pin only the scope binding plus unchanged genuine-verdicts.+"""Goal-judge handoff gates: per-task relay-affinity scope + fail-open on transport failure.++Both terminal-handoff gates (``hermes_cli.kanban`` for the CLI, ``tools.kanban_tools`` for+worker tool calls) run outside any agent turn, so without a bound scope the relay rejects the+judge call (400 MissingSessionID, #113669). ``judge_goal`` then fails open to ``continue`` with+``transport_failed=True``; a gate that reads that as a human "not done" rejects the handoff+(#83610). These tests pin the scope binding and that only a genuine verdict rejects."""from __future__ import annotations@@ -19,10 +18,13 @@ import pytestsys.path.insert(0, str(Path(__file__).parent.parent.parent))-from agent.portal_tags import get_affinity_scope, set_affinity_scope+from agent.portal_tags import get_affinity_scope, reset_affinity_scope, set_affinity_scopefrom hermes_cli import kanban as kanban_clifrom tools import kanban_tools+_TRANSPORT_FAILED = ("continue", "judge error: BadRequestError", False, None, True)+_GENUINE_CONTINUE = ("continue", "goal not met yet", False, None, False)+def _task(tid="task-1"):return SimpleNamespace(id=tid, title="goal title", body="goal body", goal_mode=True)@@ -35,44 +37,51 @@ def _aux_client():)-def test_cli_gate_genuine_continue_still_rejects():- """A real not-done verdict keeps rejecting; only transport failure fails open."""- with _aux_client(), patch(- "hermes_cli.goals.judge_goal",- return_value=("continue", "goal not met yet", False, None, False),- ):+def _recording_judge(seen):+ def fake_judge(**kwargs):+ seen.append(get_affinity_scope())+ return ("done", "ok", False, None, False)+ return fake_judge+++def test_cli_gate_transport_failure_fails_open_but_genuine_verdict_rejects():+ with _aux_client(), patch("hermes_cli.goals.judge_goal", return_value=_TRANSPORT_FAILED):+ assert kanban_cli._goal_mode_handoff_rejection(_task(), "evidence") == ("done", None)+ with _aux_client(), patch("hermes_cli.goals.judge_goal", return_value=_GENUINE_CONTINUE):assert kanban_cli._goal_mode_handoff_rejection(_task(), "evidence") == ("continue", "goal not met yet")+def test_tool_gate_transport_failure_fails_open_but_genuine_verdict_rejects():+ with patch.object(kanban_tools, "_goal_judge_available", return_value=True):+ with patch.object(kanban_tools, "judge_goal", return_value=_TRANSPORT_FAILED):+ kanban_tools._goal_gate("kanban_complete", _task(), "task-1", "ev") # no raise+ with patch.object(kanban_tools, "judge_goal", return_value=_GENUINE_CONTINUE):+ with pytest.raises(kanban_tools._Reject):+ kanban_tools._goal_gate("kanban_complete", _task(), "task-1", "ev")++def test_cli_gate_binds_per_task_affinity_scope():"""Headless judge call runs under kanban:<task_id>; a bound scope is kept."""seen = []-- def fake_judge(**kwargs):- seen.append(get_affinity_scope())- return ("done", "ok", False, None, False)-- with _aux_client(), patch("hermes_cli.goals.judge_goal", side_effect=fake_judge):+ with _aux_client(), patch("hermes_cli.goals.judge_goal", side_effect=_recording_judge(seen)):assert kanban_cli._goal_mode_handoff_rejection(_task("task-9"), "ev") == ("done", None)assert seen == ["kanban:task-9"]assert get_affinity_scope() is Nonetoken = set_affinity_scope("outer-conversation")try:- with _aux_client(), patch("hermes_cli.goals.judge_goal", side_effect=fake_judge):+ with _aux_client(), patch("hermes_cli.goals.judge_goal", side_effect=_recording_judge(seen)):kanban_cli._goal_mode_handoff_rejection(_task("task-9"), "ev")finally:- from agent.portal_tags import reset_affinity_scopereset_affinity_scope(token)assert seen[-1] == "outer-conversation"-def test_tool_gate_genuine_blocked_still_rejects():- """A real unachievable verdict still raises; only transport failure fails open."""+def test_tool_gate_binds_per_task_affinity_scope():+ seen = []with patch.object(kanban_tools, "_goal_judge_available", return_value=True), patch.object(- kanban_tools, "judge_goal",- return_value=("blocked", "unachievable", False, None, False),- ):- with pytest.raises(kanban_tools._Reject):- kanban_tools._goal_gate("kanban_complete", _task(), "task-1", "ev")+ kanban_tools, "judge_goal", side_effect=_recording_judge(seen)):+ kanban_tools._goal_gate("kanban_complete", _task("task-9"), "task-9", "ev")+ assert seen == ["kanban:task-9"]+ assert get_affinity_scope() is None