diff --git a/orchestrator/kvb_orchestrator/mcp.py b/orchestrator/kvb_orchestrator/mcp.py index 7f6161b..b12ccfc 100644 --- a/orchestrator/kvb_orchestrator/mcp.py +++ b/orchestrator/kvb_orchestrator/mcp.py @@ -59,7 +59,7 @@ class Mcp: "agent": text_property("Your agent name as the radio knows it; the operator's denial and its reason go to it."), }, ), - tool("review_status", "Status of a review (pending, approved, rejected, superseded: a newer review of the same worktree and branch replaced it, named by superseded_by), its tree, decision time and the passkey proof that approval.py verify --record checks.", {"id": review_id}), + tool("review_status", "Status of a review (pending, approved, rejected, superseded: a newer review of the same worktree and branch replaced it, named by superseded_by), its tree, decision time, for a denial with a note its channel, reason and to, and the passkey proof that approval.py verify --record checks.", {"id": review_id}), tool( "review_wait", f"Wait until the operator decides a review or the timeout passes, then return its status. " diff --git a/orchestrator/kvb_orchestrator/reviewing.py b/orchestrator/kvb_orchestrator/reviewing.py index 6faec61..f9f3b18 100644 --- a/orchestrator/kvb_orchestrator/reviewing.py +++ b/orchestrator/kvb_orchestrator/reviewing.py @@ -28,6 +28,7 @@ REQUEST = ("repo", "worktree", "branch", "tree", "title", "page", "notes", "gate OPTIONAL = ("agent", "diff", "sealed") LISTED = ("id", "created", "worktree", "branch", "tree", "title") STATE = ("id", "status", "tree", "decided") +DENIAL = ("channel", "reason", "to") def found(review: dict | None, review_id: str) -> dict: @@ -38,11 +39,12 @@ def found(review: dict | None, review_id: str) -> dict: def state_of(review: dict) -> dict: """Returns: - The review's id, status, tree and decision time, and superseded_by - once a newer review of its worktree and branch replaced it. + The review's id, status, tree and decision time, superseded_by + once a newer review of its worktree and branch replaced it, and + channel, reason and to of a denial with a note. """ replaced = {"superseded_by": review["superseded_by"]} if "superseded_by" in review else {} - return {**{key: review[key] for key in STATE}, **replaced} + return {**{key: review[key] for key in STATE}, **replaced, **{key: review[key] for key in DENIAL if key in review}} def proven(review: dict) -> dict: diff --git a/tests/test_hub_deny.py b/tests/test_hub_deny.py index 911f872..3344bff 100644 --- a/tests/test_hub_deny.py +++ b/tests/test_hub_deny.py @@ -234,6 +234,26 @@ class TestHubDeny(HubCase): self.settle(lambda: any("no recipient" in row["text"] for row in self.events("kinds=approval")["events"])) self.assertEqual((self.ask_status(ask_id, "0"), self.radio()), ("denied", [])) + def test_a_review_denied_without_recipient_still_returns_its_reason(self): + review_id = self.tool("review_request", self.arguments("feat: nameless", "", self.page("bundle.html", PAGE)))["structuredContent"]["id"] + entry = self.denial("review", review_id, "", "call", " drop the\n comments ") + self.assertEqual(entry["to"], "") + with mock.patch.object(batches, "UNDO", 0.05): + self.assertEqual(self.approve([entry], self.signed([entry], self.pin()))[0], 202) + self.settle(lambda: any("no recipient" in row["text"] for row in self.events("kinds=approval")["events"])) + self.assertEqual(self.radio(), []) + for name, arguments in (("review_status", {"id": review_id}), ("review_wait", {"id": review_id, "timeout_seconds": 0})): + with self.subTest(tool=name): + state = self.tool(name, arguments)["structuredContent"] + self.assertEqual((state["status"], state["channel"], state["reason"], state["to"]), ("rejected", "call", "drop the comments", "")) + + def test_a_review_rejected_without_a_note_carries_no_reason(self): + review_id = self.tool("review_request", self.arguments("feat: plain", "", self.page("bundle.html", PAGE)))["structuredContent"]["id"] + with mock.patch.object(batches, "UNDO", 0.05): + self.assertEqual(self.approve([{**self.entry("review", review_id, "", ""), "verb": "reject"}], None)[0], 202) + self.settle(lambda: self.tool("review_status", {"id": review_id})["structuredContent"]["status"] == "rejected") + self.assertFalse({"channel", "reason", "to"} & set(self.tool("review_status", {"id": review_id})["structuredContent"])) + def answer(self, signer: Key, item: dict, channel: str, reason: str) -> dict: payload = signing.approval_payload([signing.item_hash(signing.denial_item(item, channel, reason, "Skills"))], secrets.token_hex(16), int(time.time()) + 60) return {"status": "denied", "channel": channel, "reason": reason, "to": "Skills", "proof": signer.proof(payload, self.origin)}