fix(hub): commit rows run only after their reviews, which now hold two hours
Stage 2.0's commit row failed because its approvals lived 15 minutes and the row ran before them (operator picks 2026-11-20). A review approval now holds two hours (signing.REVIEW_LIFETIME 7200 for all-review batches, signing.lifetime and checked_approval shared by the verifier and the hub). operator.py run reads the approval.py verify steps of a row's command (VERIFY_STEP, the same pattern signing uses), asks the hub through the client's hub_api for each review and skips the row with 'waits <name>: <why>; the row stays open' until every one is approved; a hub that does not answer, a missing client or a port above 65535 also skips it. The inbox lists each commit row's reviews (inbox.linked) with a reviews k/n approved pill; its Run button becomes 'Approve n and run', which brings the row's pending reviews into the selection, signs each rule and red-gate review alone first and then the rest once; approving.apply settles operator rows after the reviews they verify. kvb-git-diff and requirement 020 describe it.
Stacked on grantall (14bb4f3). Conflicts in page-inbox.js (grantNote and DENY_NOTE next to the ux reason chips) and kvb-git-diff/SKILL.md (the superseded line next to the two-hour paragraph) keep both sides. ruff and node --check pass.
Tests: tests/test_operator.py ran once before the commit (operator exception): 51 passed, 61 subtests. test_hub_approval, test_hub_console, test_hub_grant_mode and the fixture updates are written, not run: the full suite runs once on master after all bundles (operator order).
Security: MEDUSA over the staged tree on master: 100, no findings, all 16 files covered. WEB-SSRF at skills/kvb-org-operator/scripts/operator.py:996 (urllib.request to the local hub at base_url(port)) stays accepted as by design after kvb-think-criticize with 1 skeptic over 2 rounds and the operator's accept on 2026-11-21: the port is checked against 65535, the opener has no proxy and no redirects.
🎯 Fix: 92 %
💥 Break: 5 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 87
🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 %
Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
14bb4f38df
commit
0fa05c54d5
16 files changed
+288
-33
No files matched your search
@@ -150,6 +150,23 @@ class TestApproval(unittest.TestCase):
|
||||
self.approvers.write_text('{"credentials": []}', encoding="utf-8")
|
||||
self.refused(signer.proof(self.payload([self.item], int(self.now) + 60), ORIGIN), self.item, "", "no key is pinned")
|
||||
|
||||
def test_a_review_approval_lives_two_hours_and_every_other_kind_fifteen_minutes(self):
|
||||
signer = key(-7, "main")
|
||||
signer.pin(self.approvers, ORIGIN)
|
||||
tree = signing.review_item("0123456789abcdef", "/repo/.git", "/repo", "main", "a" * 40)
|
||||
later = int(self.now) + signing.LIFETIME + 60
|
||||
verifier.check(signer.proof(self.payload([tree], later), ORIGIN), tree, "pass", self.trust, self.now)
|
||||
self.refused(signer.proof(self.payload([tree], int(self.now) + signing.REVIEW_LIFETIME + 60), ORIGIN), tree, "pass", "too far")
|
||||
self.refused(signer.proof(self.payload([self.item, tree], later), ORIGIN), self.item, "", "too far")
|
||||
self.assertEqual((signing.lifetime([tree]), signing.lifetime([tree, self.item]), signing.lifetime([])), (signing.REVIEW_LIFETIME, signing.LIFETIME, signing.LIFETIME))
|
||||
|
||||
def test_the_operator_runner_reads_the_verify_steps_of_a_commit_row_as_the_hub_does(self):
|
||||
runner = (HUB.parent / "skills" / "kvb-org-operator" / "scripts" / "operator.py").read_text(encoding="utf-8")
|
||||
self.assertIn(f'VERIFY_STEP = re.compile(r"{signing.VERIFY_STEP.pattern}")', runner)
|
||||
first, second = "a" * 16, "b" * 16
|
||||
command = f"approval.py verify --port 1 --review {first} && approval.py verify --review {second} --gate pass --port 2; approval.py verify --port 1 --review {first}; approval.py verify --review {'c' * 16}; echo --port 3"
|
||||
self.assertEqual(signing.verified_reviews(command), [first, second])
|
||||
|
||||
def test_one_bulk_signature_serves_each_listed_item_once(self):
|
||||
signer = key(-8, "main")
|
||||
signer.pin(self.approvers, ORIGIN)
|
||||
|
||||
@@ -8,7 +8,7 @@ from unittest import mock
|
||||
|
||||
from hub_case import HubCase
|
||||
from hub_support import HUB
|
||||
from kvb_orchestrator import batches, skill_scripts
|
||||
from kvb_orchestrator import batches, jobs, skill_scripts
|
||||
|
||||
COMMAND = "echo hi"
|
||||
DIGEST = hashlib.sha256(COMMAND.encode()).hexdigest()
|
||||
@@ -29,6 +29,29 @@ class TestHubConsole(HubCase):
|
||||
def dismiss(self, payload: object, headers: dict[str, str]) -> int:
|
||||
return self.post_json("/api/inbox/dismiss", payload, headers)[0]
|
||||
|
||||
def test_a_commit_row_lists_the_reviews_it_verifies_and_queues_its_job_only_after_them(self):
|
||||
self.claim("s1", "Skills session")
|
||||
review = self.request("feat: x", "notes")
|
||||
command = f"python3 approval.py verify --port 8737 --review {review} --gate pass && python3 approval.py verify --port 8737 --review {'f' * 16} --gate pass && git commit -m x"
|
||||
row = {"title": command, "workdir": str(self.outside), "description": "commit", "check": "manual", "status": "queued", "roles": {"Operator": "R", "Skills session": "A"}}
|
||||
self.write_council({"rasci.json": {"operator/commit": row}})
|
||||
self.assertEqual(self.item("operator/commit")["reviews"], [{"id": review, "status": "pending", "gate": "pass"}, {"id": "f" * 16, "status": "unknown", "gate": ""}])
|
||||
self.assertEqual(self.item(review)["reviews"], [])
|
||||
seen = []
|
||||
queue = jobs.Jobs.queue_job
|
||||
|
||||
def spy(hub, item, proof):
|
||||
seen.append(hub.reviews.get(review)["status"])
|
||||
return queue(hub, item, proof)
|
||||
|
||||
signer = self.pin()
|
||||
entries = [self.entry("operator", "operator/commit", "", hashlib.sha256(command.encode()).hexdigest()), self.entry("review", review, "", "")]
|
||||
with mock.patch.object(batches, "UNDO", 0.05), mock.patch.object(jobs.Jobs, "queue_job", spy):
|
||||
self.assertEqual(self.approve(entries, self.signed(entries, signer))[0], 202)
|
||||
self.settle(lambda: self.item("operator/commit")["job"] is not None)
|
||||
self.assertEqual(seen, ["approved"])
|
||||
self.assertEqual(self.item("operator/commit")["reviews"][0]["status"], "approved")
|
||||
|
||||
def test_the_job_console_stays_under_the_command_until_the_row_is_dismissed(self):
|
||||
self.claim("s1", "Skills session")
|
||||
self.register("queued")
|
||||
|
||||
@@ -34,7 +34,7 @@ const document = {
|
||||
createElement: (tag) => new El(tag), createElementNS: (ns, tag) => new El(tag),
|
||||
};
|
||||
const now = 1_800_000_000;
|
||||
const base = {agent: "Stage 2.0", to: "Stage 2.0", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", check: "", command: "", directory: "/repo", sha256: "s", runnable: false, deniable: true, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now};
|
||||
const base = {agent: "Stage 2.0", to: "Stage 2.0", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", check: "", command: "", directory: "/repo", sha256: "s", runnable: false, deniable: true, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now, reviews: []};
|
||||
const question = "decide: keep or remove the donation section";
|
||||
const options = [{label: "Keep", description: "the section ships with the IAM PR"}, {label: "Remove", description: "drop it before the PR"}];
|
||||
const items = {
|
||||
|
||||
@@ -37,7 +37,7 @@ const document = {
|
||||
createElement: (tag) => new El(tag), createElementNS: (ns, tag) => new El(tag),
|
||||
};
|
||||
const now = 1_800_000_000;
|
||||
const base = {agent: "Store", to: "Store", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "/repo", sha256: "s", runnable: false, deniable: false, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now};
|
||||
const base = {agent: "Store", to: "Store", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "/repo", sha256: "s", runnable: false, deniable: false, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now, reviews: []};
|
||||
const items = {
|
||||
green: {...base, kind: "review", id: "r-green", title: "feat: green", gate: "pass", green: true},
|
||||
red: {...base, kind: "review", id: "r-red", title: "feat: red", gate: "fail"},
|
||||
@@ -156,6 +156,21 @@ const byName = (node, label) => buttons(node).find((button) => button.getAttribu
|
||||
signing = true;
|
||||
await buttons(sheet[2]).find((button) => text(button).startsWith("Grant ")).click();
|
||||
results.all_granted = take();
|
||||
const commit = {...base, kind: "operator", id: "operator/commit", title: "git commit", command: "git commit", runnable: true, deniable: true, reviews: [{id: "r-green", status: "pending", gate: "pass"}, {id: "r-red", status: "pending", gate: "fail"}, {id: "r-old", status: "approved", gate: "pass"}]};
|
||||
state.inbox = [...Object.values(items).map((item) => ({...item})), commit];
|
||||
const runOf = (row) => actionsFor(row)[0];
|
||||
results.run_label = runOf(commit).getAttribute("aria-label");
|
||||
await runOf(commit).click();
|
||||
results.run_collected = {...take(), sheets: sheets.splice(0).length};
|
||||
ui.selected.clear();
|
||||
mode.value = "direct";
|
||||
await runOf(commit).click();
|
||||
const runSheet = sheets.splice(0)[0];
|
||||
results.run_note = text(runSheet[0]);
|
||||
await buttons(runSheet[2]).find((button) => text(button).startsWith("Grant ")).click();
|
||||
results.run_granted = take();
|
||||
results.run_stuck = runOf({...commit, reviews: [{id: "r-gone", status: "rejected", gate: "pass"}]}).getAttribute("disabled");
|
||||
results.run_plain = runOf({...commit, reviews: [{id: "r-old", status: "approved", gate: "pass"}]}).getAttribute("aria-label");
|
||||
console.log(JSON.stringify(results));
|
||||
})().catch((error) => { console.error(error && error.stack || error); process.exit(1); });
|
||||
`;
|
||||
@@ -214,16 +229,24 @@ class TestGrantMode(unittest.TestCase):
|
||||
self.assertEqual((self.data["option_removed"]["selected"], self.data["option_removed"]["pressed"]), ([], []))
|
||||
self.assertEqual(self.data["option_row"], {"pressed": ["Yes"], "batchable": True})
|
||||
|
||||
def test_grant_n_signs_the_batch_once_then_each_rule_and_red_gate_alone(self):
|
||||
def test_grant_n_signs_each_rule_and_red_gate_alone_first_then_the_batch_once(self):
|
||||
self.assertEqual(self.data["all"]["selected"], ["decision:d-1", "decision:d-2", "operator:operator/ask", "review:r-green", "review:r-red", "rule:1123456789abcdef"])
|
||||
self.assertEqual((self.data["all"]["proofs"], self.data["all"]["accepts"]), ([], []))
|
||||
self.assertEqual(self.data["all_grant"], "Grant selection (6)")
|
||||
self.assertTrue(self.data["all_note"].endswith("Each rule and each red-gate review then asks its own signature, one after the other (2)."), self.data["all_note"])
|
||||
self.assertIn("Each rule and each red-gate review first asks its own signature, one after the other (2). Then the passkey signs the rest once", self.data["all_note"])
|
||||
granted = self.data["all_granted"]
|
||||
self.assertEqual(granted["proofs"], [["review:r-green", "decision:d-1", "decision:d-2", "operator:operator/ask"], ["review:r-red"]])
|
||||
self.assertEqual(granted["labels"], [["", "B", "B", "Yes"], [""]])
|
||||
self.assertEqual(granted["proofs"], [["review:r-red"], ["review:r-green", "decision:d-1", "decision:d-2", "operator:operator/ask"]])
|
||||
self.assertEqual(granted["labels"], [[""], ["", "B", "B", "Yes"]])
|
||||
self.assertEqual((granted["accepts"], granted["selected"]), (["1123456789abcdef"], []))
|
||||
|
||||
def test_a_commit_row_approves_the_reviews_it_verifies_before_it_runs(self):
|
||||
self.assertEqual(self.data["run_label"], "Approve 2 and run")
|
||||
self.assertEqual(self.data["run_collected"]["selected"], ["operator:operator/commit"])
|
||||
self.assertEqual((self.data["run_collected"]["proofs"], self.data["run_collected"]["sheets"]), ([], 0))
|
||||
self.assertIn("first asks its own signature, one after the other (1). Then the passkey signs the rest once, commit rows settling after the reviews they verify.", self.data["run_note"])
|
||||
self.assertEqual(self.data["run_granted"]["proofs"], [["review:r-red"], ["review:r-green", "operator:operator/commit"]])
|
||||
self.assertEqual((self.data["run_stuck"], self.data["run_plain"]), ("", "Run"))
|
||||
|
||||
def test_one_split_grants_the_selection_and_its_menu_holds_the_rest(self):
|
||||
tray = self.data["tray"]
|
||||
self.assertEqual(tray["main"], "Grant selection (4)")
|
||||
|
||||
@@ -27,7 +27,7 @@ const document = {
|
||||
createElement: () => new El(), createElementNS: () => new El(),
|
||||
};
|
||||
const now = 1_800_000_000;
|
||||
const base = {agent: "Store", to: "Store", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "/repo", sha256: "s", runnable: true, deniable: true, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now};
|
||||
const base = {agent: "Store", to: "Store", detail: "", green: false, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "/repo", sha256: "s", runnable: true, deniable: true, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now, reviews: []};
|
||||
const row = (id, command, extra) => ({...base, kind: "operator", id, title: command, command, ...extra});
|
||||
const items = {
|
||||
gone: row(GONE, "git merge --no-ff --no-verify -F msg"),
|
||||
|
||||
@@ -106,7 +106,7 @@ const classes = (node) => String(node.className || node.attrs.class || "").split
|
||||
const labels = (node) => all(node).filter((el) => el.tag === "button").map((el) => el.getAttribute("aria-label") || el.textContent);
|
||||
const calls = {proofs: [], posts: [], sheets: [], radio: [], signs: []};
|
||||
const now = 1_800_000_000;
|
||||
const base = {agent: "Skills", to: "Skills", detail: "", green: true, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "", sha256: "", runnable: false, deniable: false, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now - 60};
|
||||
const base = {agent: "Skills", to: "Skills", detail: "", green: true, gate: "", score: "", warnings: [], options: [], recommended: "", command: "", directory: "", sha256: "", runnable: false, deniable: false, job: null, rule: null, dry_run: null, diff: null, pinned: false, until: 0, held: false, ts: now - 60, reviews: []};
|
||||
const operator = {...base, kind: "operator", id: "operator/ship", title: "make ship", command: "make ship", directory: "/repo", detail: "release the build", runnable: true, deniable: true, green: false, sha256: "abc"};
|
||||
const review = {...base, kind: "review", id: "0123456789abcdef", title: "feat: x", detail: "feature/x", gate: "pass", score: "🎯 95", directory: "/repo", diff: 4};
|
||||
const ask = {...base, kind: "ask", id: "1123456789abcdef", title: "Bash: git commit -m x", command: "git commit -m x", directory: "/repo", deniable: true};
|
||||
|
||||
@@ -2,16 +2,19 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
import pty
|
||||
import select
|
||||
import shutil
|
||||
import signal
|
||||
import socket
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import termios
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
@@ -381,6 +384,55 @@ class TestOperator(unittest.TestCase):
|
||||
self.assertNotIn("\x1b", out)
|
||||
self.assertEqual(self._open(), ["operator/second"])
|
||||
|
||||
def test_run_skips_a_commit_row_while_a_review_it_verifies_is_unapproved_or_the_hub_is_silent(self):
|
||||
statuses = {"a" * 16: "pending", "b" * 16: "approved"}
|
||||
|
||||
class Hub(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
review = self.path.rsplit("/", 1)[-1]
|
||||
if review == "c" * 16:
|
||||
self.send_response(302)
|
||||
self.send_header("Location", f"/api/reviews/{'b' * 16}")
|
||||
self.end_headers()
|
||||
return
|
||||
guarded = self.headers.get("X-Kvb-Orchestrator") == "1"
|
||||
body = json.dumps({"status": statuses.get(review) if guarded else "approved"}).encode()
|
||||
self.send_response(200)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.end_headers()
|
||||
self.wfile.write(body)
|
||||
|
||||
def log_message(self, *_):
|
||||
return
|
||||
|
||||
hub = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Hub)
|
||||
self.addCleanup(hub.server_close)
|
||||
threading.Thread(target=hub.serve_forever, daemon=True).start()
|
||||
self.addCleanup(hub.shutdown)
|
||||
silent = socket.socket()
|
||||
silent.bind(("127.0.0.1", 0))
|
||||
dead = silent.getsockname()[1]
|
||||
silent.close()
|
||||
port = hub.server_address[1]
|
||||
work = self.base / "work"
|
||||
work.mkdir()
|
||||
rows = {"pending": (port, "a"), "huge": (65536 + port, "b"), "approved": (port, "b"), "offline": (dead, "b"), "redirect": (port, "c")}
|
||||
for slug, (target, letter) in rows.items():
|
||||
self._add(slug, work, f"true approval.py verify --port {target} --review {letter * 16} && touch ran-{slug}", "commit", "manual")
|
||||
missing = self._feed("")
|
||||
self.assertIn("waits operator/approved: the hub does not answer about the reviews its commit verifies, or", missing.stdout)
|
||||
client = self.home / ".local" / "share" / "kvb-orchestrator" / "client"
|
||||
client.mkdir(parents=True)
|
||||
shutil.copy(REPO_ROOT / "orchestrator" / "client" / "hub_api.py", client / "hub_api.py")
|
||||
result = self._feed("y\n")
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(sorted(path.name for path in work.iterdir()), ["ran-approved"])
|
||||
self.assertIn(f"waits operator/pending: 1 reviews its commit verifies are not approved yet ({'a' * 16})", result.stdout)
|
||||
self.assertIn("waits operator/offline: the hub does not answer", result.stdout)
|
||||
self.assertIn("waits operator/redirect: the hub does not answer", result.stdout)
|
||||
self.assertIn("waits operator/huge: the hub does not answer", result.stdout)
|
||||
self.assertEqual(sorted(self._open()), ["operator/huge", "operator/offline", "operator/pending", "operator/redirect"])
|
||||
|
||||
def test_run_colors_only_on_a_terminal_without_no_color(self):
|
||||
self._add("go", self.base, "true", "runnable", "manual")
|
||||
piped = self._feed("q\n").stdout
|
||||
|
||||
@@ -85,7 +85,7 @@ def shown(templates: Path, calls: list[list[object]], globals_: dict | None = No
|
||||
|
||||
|
||||
def item(kind: str, **fields: object) -> dict:
|
||||
base = {"kind": kind, "id": "0123456789abcdef", "title": "Bash: make test", "command": "", "directory": "", "agent": "Skills", "to": "Skills", "ts": 1_800_000_000, "warnings": [], "options": [], "recommended": "", "held": False, "until": 0, "pinned": False, "diff": None, "job": None, "rule": None, "detail": "", "green": False, "gate": "", "score": "", "runnable": True, "deniable": True, "sha256": ""}
|
||||
base = {"kind": kind, "id": "0123456789abcdef", "title": "Bash: make test", "command": "", "directory": "", "agent": "Skills", "to": "Skills", "ts": 1_800_000_000, "warnings": [], "options": [], "recommended": "", "held": False, "until": 0, "pinned": False, "diff": None, "job": None, "rule": None, "detail": "", "green": False, "gate": "", "score": "", "runnable": True, "deniable": True, "sha256": "", "reviews": []}
|
||||
return {**base, **fields}
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user