Hub: send in the field (032), coherent speak box (033), stream head band (034), Match at full width with its pile (035, 036), Home without the outer box (037), badge to Match (038), rejects that survive a changed or withdrawn card (039), the release card (040), code marks in the review diff (041), why Deny is off (042), the undo window clock (043), widgets without inner boxes (044), the Artifacts head on one line (045), accepting a red gate's risk (046), one code box (047), done rows greyed and folded (048), one control height (049), menus that stay open (050), radio settings in the Device card (051), bubbles beside the modes (052), agent settings on every face and name (053), pin only by menu (054), WASD in Match (055), the flowing card edge (056), Schedules in Controls (057) and the hub poll cost (059). Skills: the coach leaves for its own repository kevinveenbirkenbach/coach (058; test_install pins its four skills in skills-lock.json and stays red until that repository is published and pinned), hooks and timers start fewer processes (060), council files on hot paths stay bounded and mirror by marker instead of mtime (061), scripts and hooks hand agents less output (062), and block.py builds the commit table and message block in one run (063). Requirement documents 032 to 063 with their implementation amendments. MEDUSA false positives accepted after kvb-think-criticize (36 lines): MM-SCAN-058 (pla inside replace or plan), JB-SCAN-616/641 (the local clip helper), CODEGEN-SCAN-001 (drop-in paths), CGS-SCAN-029 (systemctl argv from constants), CGS-SCAN-040 (runner poll loop), FLA-SCAN-055 (feedback), WM-SCAN-354, AI-BACKDOOR-006, GENAI-SCAN-1270, B604 (runner shell path for passkey-verified commands), TC004, EXA002, EXA006, EXA010 and WEB-SSRF. 🎯 Fix: 92 % 💥 Break: 8 % 💸 Tokens: 89 % ⏱️ Velocity: – 🛡️ Security: ~100 % 🏆 Score: 95 🚦 Gate: ⛔ break 8 % > 5 Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
5.3 KiB
Python
103 lines
5.3 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parents[1]
|
|
DISPATCHER = REPO_ROOT / "skills" / "kvb-org-organize" / "scripts" / "hooks.py"
|
|
SCRIPTS = {
|
|
"radio": "kvb-org-radio/scripts/radio.py",
|
|
"watch": "kvb-org-organize/scripts/watch.py",
|
|
"queue": "kvb-org-queue/scripts/queue.py",
|
|
"graph": "kvb-agent-optimize/scripts/graph.py",
|
|
"log": "kvb-org-perform/scripts/log.py",
|
|
}
|
|
FAKE = """import json, os, sys
|
|
NAME = {name!r}
|
|
|
|
|
|
def main():
|
|
event = json.load(sys.stdin)
|
|
with open(os.environ["HOOK_LOG"], "a", encoding="utf-8") as log:
|
|
log.write(json.dumps([NAME, sys.argv[1:], event["tool_input"]["command"]]) + "\\n")
|
|
plan = json.loads(os.environ.get("HOOK_PLAN", "{{}}")).get(NAME, {{}})
|
|
if plan.get("crash"):
|
|
raise RuntimeError(NAME + " broke")
|
|
if plan.get("out"):
|
|
print(plan["out"])
|
|
if plan.get("err"):
|
|
print(plan["err"], file=sys.stderr)
|
|
if "exit" in plan:
|
|
sys.exit(plan["exit"])
|
|
return plan.get("code", 0)
|
|
"""
|
|
ASK = {"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "ask", "permissionDecisionReason": "held command meets an ask rule"}}
|
|
|
|
|
|
class TestHooks(unittest.TestCase):
|
|
def setUp(self):
|
|
self.tmp = tempfile.TemporaryDirectory()
|
|
self.addCleanup(self.tmp.cleanup)
|
|
self.root = Path(self.tmp.name)
|
|
target = self.root / "kvb-org-organize" / "scripts" / "hooks.py"
|
|
target.parent.mkdir(parents=True)
|
|
shutil.copy(DISPATCHER, target)
|
|
for name, script in SCRIPTS.items():
|
|
path = self.root / script
|
|
path.parent.mkdir(parents=True, exist_ok=True)
|
|
path.write_text(FAKE.format(name=name), encoding="utf-8")
|
|
self.log = self.root / "log.jsonl"
|
|
|
|
def dispatch(self, sub: str, plan: dict) -> subprocess.CompletedProcess:
|
|
self.log.unlink(missing_ok=True)
|
|
event = json.dumps({"session_id": "s", "hook_event_name": "PreToolUse", "tool_name": "Bash", "tool_input": {"command": "make test"}})
|
|
env = {**os.environ, "HOOK_LOG": str(self.log), "HOOK_PLAN": json.dumps(plan)}
|
|
return subprocess.run(["/usr/bin/python3", "-I", str(self.root / "kvb-org-organize" / "scripts" / "hooks.py"), sub], input=event, env=env, capture_output=True, text=True, timeout=60, check=False)
|
|
|
|
def ran(self) -> list[list]:
|
|
return [json.loads(line) for line in self.log.read_text(encoding="utf-8").splitlines()]
|
|
|
|
def test_each_event_runs_its_handlers_in_order_with_the_same_event_and_their_own_subcommand(self):
|
|
self.assertEqual(self.dispatch("pre-bash", {}).returncode, 0)
|
|
self.assertEqual(self.ran(), [["radio", ["block"], "make test"], ["watch", ["block"], "make test"], ["queue", ["block"], "make test"], ["graph", ["hook"], "make test"]])
|
|
self.assertEqual(self.dispatch("post-bash", {}).returncode, 0)
|
|
self.assertEqual(self.ran(), [["watch", ["watch"], "make test"], ["log", ["persist"], "make test"]])
|
|
|
|
def test_exit_two_blocks_with_the_text_of_every_blocking_handler_after_all_ran(self):
|
|
done = self.dispatch("pre-bash", {"watch": {"code": 2, "err": "watch: disk full"}, "queue": {"exit": 2, "err": "queue: through the queue"}, "graph": {"out": json.dumps({"systemMessage": "graph"})}})
|
|
self.assertEqual((done.returncode, done.stdout, done.stderr), (2, "", "watch: disk full\nqueue: through the queue\n"))
|
|
self.assertEqual([name for name, _, _ in self.ran()], ["radio", "watch", "queue", "graph"])
|
|
|
|
def test_a_crash_leaves_the_other_handlers_running_and_their_answers_merged(self):
|
|
context = {"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": "watch: alert"}}
|
|
done = self.dispatch("pre-bash", {"radio": {"crash": True}, "watch": {"out": json.dumps(context)}, "queue": {"out": json.dumps(ASK)}, "graph": {"out": json.dumps({"systemMessage": "graph: notice"})}})
|
|
self.assertEqual(done.returncode, 0, done.stderr)
|
|
self.assertIn("RuntimeError: radio broke", done.stderr)
|
|
self.assertEqual([name for name, _, _ in self.ran()], ["radio", "watch", "queue", "graph"])
|
|
self.assertEqual(json.loads(done.stdout), {
|
|
"hookSpecificOutput": {"hookEventName": "PreToolUse", "additionalContext": "watch: alert", "permissionDecision": "ask", "permissionDecisionReason": "held command meets an ask rule"},
|
|
"systemMessage": "graph: notice",
|
|
})
|
|
|
|
def test_a_single_answer_passes_through_unchanged_and_plain_text_goes_to_stderr(self):
|
|
done = self.dispatch("pre-bash", {"queue": {"out": json.dumps(ASK)}, "graph": {"out": "plain words"}})
|
|
self.assertEqual((done.returncode, json.loads(done.stdout)), (0, ASK))
|
|
self.assertEqual(done.stderr, "plain words\n")
|
|
|
|
def test_a_missing_handler_is_skipped_and_an_unknown_event_is_refused(self):
|
|
(self.root / SCRIPTS["queue"]).unlink()
|
|
self.assertEqual(self.dispatch("pre-bash", {}).returncode, 0)
|
|
self.assertEqual([name for name, _, _ in self.ran()], ["radio", "watch", "graph"])
|
|
refused = self.dispatch("stop", {})
|
|
self.assertEqual(refused.returncode, 1)
|
|
self.assertIn("usage: hooks.py pre-bash|post-bash", refused.stderr)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|