Merge branch 'feature/hub-match-review' into unify/skills-20261114

# Conflicts:
#	docs/requirements/README.md
This commit is contained in:
Kevin Veen-Birkenbach committed 2026-11-14 22:02:51 +00:00
commit 7241e53a98
23 files changed
+1407 -15

No files matched your search

+215
View File
@@ -0,0 +1,215 @@
from __future__ import annotations
import json
import os
import shutil
import sys
import tempfile
import time
import unittest
from pathlib import Path
HERE = Path(__file__).resolve().parent
sys.path[:0] = [str(HERE.parent), str(HERE)]
import test_orchestrator_e2e as base
from hub_case import HubCase
from hub_support import iso
OUT = Path(os.environ.get("E2E_OUT", "/tmp/hub-012-shots"))
FILES = (("src/app.py", 60), ("src/view.js", 30), ("docs/notes.md", 12))
CARD = """
const card = () => document.querySelector("#main .match-card.front");
const body = () => card() && card().querySelector(".match-body");
const opened = () => all(".match-file", card()).filter((file) => file.open).map((file) => file.dataset.path);
const pick = async (id) => {
const tab = await until(() => document.querySelector(`#main .match-peek[data-card="${id}"]`), 8000);
if (tab) {
tab.click();
}
return until(() => card() && card().dataset.card === id && card(), 8000);
};
const head = () => ({
card: card().dataset.card, kind: card().dataset.kind, stale: card().dataset.stale, face: Boolean(card().querySelector(".match-who .avatar svg")),
name: text(card().querySelector(".match-name")), age: text(card().querySelector(".match-age")),
place: all(".match-place dt", card()).map(text).map((label, index) => [label, text(all(".match-place dd", card())[index])]),
files: all(".match-file", card()).map((file) => file.dataset.path), accept: card().closest(".match-stack").querySelector(".match-accept").disabled,
reason: text(card().querySelector(".match-stale")), peeks: all("#main .match-peek").map((tab) => tab.dataset.card),
wide: document.documentElement.scrollWidth > window.innerWidth + 1,
});
"""
STACK = """(async () => {@HELPERS@@CARD@
await screenShown(8000);
await until(card, 8000);
await sleep(400);
return head();
})()"""
SCROLL = """(async () => {@HELPERS@@CARD@
await until(card, 8000);
const steps = [opened()];
for (let step = 0; step < 6; step += 1) {
body().scrollTop = body().scrollHeight;
body().dispatchEvent(new Event("scroll"));
await sleep(350);
steps.push(opened());
}
const numbered = all(".match-file[open]", card()).map((file) => [file.dataset.path, all("tr[data-line] td.num", file).filter((cell) => text(cell)).length > 0]);
body().scrollTop = 0;
return {steps, numbered};
})()"""
MARK = """(async () => {@HELPERS@@CARD@
await until(card, 8000);
const row = (path, line) => card().querySelector(`.match-file[data-path="${path}"] tr[data-line="${line}"]`);
const save = async (words) => {
const field = await until(() => card().querySelector(".match-comment textarea"), 3000);
if (!field) {
return false;
}
field.value = words;
card().querySelector(".match-comment .match-save").click();
await sleep(200);
return true;
};
const first = row("@FIRST@", 3);
first.scrollIntoView({block: "center"});
const box = first.getBoundingClientRect();
first.dispatchEvent(new MouseEvent("contextmenu", {bubbles: true, cancelable: true, clientX: box.left + 40, clientY: box.top + 4, button: 2}));
const clicked = await save("use the helper here");
const second = row("@FIRST@", 6);
second.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true, cancelable: true, pointerId: 7, pointerType: "touch", isPrimary: true, clientX: box.left + 40, clientY: box.top + 4}));
await sleep(800);
second.dispatchEvent(new PointerEvent("pointerup", {bubbles: true, cancelable: true, pointerId: 7, pointerType: "touch", isPrimary: true}));
const pressed = await save("long press note");
const marks = all("tr.match-mark", card()).map((mark) => [mark.dataset.line, text(mark.querySelector(".match-mark-text"))]);
const marked = all("tr.marked", card()).map((mark) => mark.dataset.line);
return {clicked, pressed, marks, marked, count: text(card().querySelector('.match-file[data-path="@FIRST@"] .match-marks'))};
})()"""
PICK = """(async () => {@HELPERS@@CARD@
const found = await pick("@ID@");
if (!found) {
return {missing: "@ID@"};
}
await sleep(400);
const command = card().querySelector(".match-command");
const payload = all(".match-file", card()).map((file) => [file.dataset.path.split("/").pop(), file.dataset.state || "", all("tr[data-line]", file).length]);
return {...head(), command: command ? text(command.querySelector("code")) : null, where: text(card().querySelector(".match-directory")), why: text(card().querySelector(".match-reason")), payload};
})()"""
def probe(template: str, **values: str) -> str:
found = template.replace("@HELPERS@", base.HELPERS).replace("@CARD@", CARD)
for name, value in values.items():
found = found.replace(f"@{name}@", value)
return found
def patch(lines: int) -> str:
rows = [f"@@ -1,{lines} +1,{lines + 1} @@"] + [f" line {number}" for number in range(1, lines + 1)]
rows.insert(4, "+added line")
return "\n".join(rows)
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
class TestMatchReview(HubCase):
drive = base.TestOrchestratorE2E.drive
def setUp(self):
super().setUp()
work = tempfile.TemporaryDirectory()
self.addCleanup(work.cleanup)
self.work = Path(work.name)
now = time.time()
self.write_council({
"work/s1/claim.json": {"office": "work/s1", "session": "s1", "runtime": "claude", "name": "Skills", "since": iso(now - 3 * 86400 - 60), "beat": now, "work": "match"},
"work/s2/claim.json": {"office": "work/s2", "session": "s2", "runtime": "claude", "name": "Stage", "since": iso(now - 9 * 86400 - 60), "beat": now, "work": "i18n"},
})
diff = [{"path": path, "status": "M", "mode": "100644", "additions": 1, "deletions": 0, "patch": patch(lines), "note": ""} for path, lines in FILES]
self.commit = self.review("feat: match review", "/repo/.worktrees/feature/match", "feature/match", "Skills", diff)
stale_diff = [{"path": "README.md", "status": "M", "mode": "100644", "additions": 1, "deletions": 0, "patch": patch(8), "note": ""}]
self.stale = self.review("docs: stale stage", "/repo/.worktrees/feature/old", "feature/old", "Stage", stale_diff)
status, _, body = self.post_json("/api/match/stale", {"id": self.stale, "tree": "f" * 40}, self.local())
self.assertEqual(status, 200, body)
self.payload()
self.base = f"http://{self.host}/"
def review(self, title: str, worktree: str, branch: str, agent: str, diff: list[dict]) -> str:
arguments = {**self.arguments(title, "", self.page(f"{branch.replace('/', '-')}.html", "<!doctype html><title>p</title>")), "worktree": worktree, "branch": branch, "agent": agent, "diff": diff}
result = self.tool("review_request", arguments)
self.assertFalse(result["isError"], result)
return result["structuredContent"]["id"]
def payload(self) -> None:
body = self.work / "body.md"
body.write_text("".join(f"Release note line {number}\n" for number in range(1, 15)), encoding="utf-8")
(self.work / "link.md").symlink_to(body)
folder = self.state / "firewall"
folder.mkdir(parents=True, exist_ok=True)
files = [{"path": "/home/op/.claude/settings.json", "exists": True, "sha256": "", "settings": {"sandbox": {"filesystem": {"denyRead": []}}}}]
(folder / "view.json").write_text(json.dumps({"written": "2026-11-14T12:00:00+00:00", "files": files}), encoding="utf-8")
self.command = f"gh issue create --body-file {body} --list link.md"
self.write_council({"rasci.json": {"operator/issue": {"title": self.command, "workdir": str(self.work), "description": "file the release issue", "check": "done", "roles": {"Skills": "A", "Operator": "R"}}}})
def steps(self, browser: str, widths: tuple[tuple[int, int], ...]) -> list[dict]:
OUT.mkdir(parents=True, exist_ok=True)
steps = []
for width, height in widths:
shot = str(OUT / f"{browser}-{width}")
steps += [
{"width": width, "height": height, "url": f"{self.base}?{width}#tasks/match", "wait": 1500, "probe": probe(STACK), "shot": f"{shot}-stack.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(SCROLL), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(MARK, FIRST=FILES[0][0]), "shot": f"{shot}-marked.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(PICK, ID="operator:operator/issue"), "shot": f"{shot}-command.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(PICK, ID=f"review:{self.stale}"), "shot": f"{shot}-stale.png"},
]
return steps
def check(self, data: dict, widths: tuple[tuple[int, int], ...]) -> None:
results = iter(data["results"])
order = [path for path, _ in FILES]
for width, _ in widths:
with self.subTest(width=width):
stack = next(results)
self.assertEqual((stack["card"], stack["kind"], stack["stale"], stack["face"]), (f"review:{self.commit}", "commit", "false", True), stack)
self.assertEqual((stack["name"], stack["age"]), ("Skills", "3 days"), stack)
self.assertEqual(stack["place"], [["Repository", "/repo"], ["Branch", "feature/match"], ["Worktree", "/repo/.worktrees/feature/match"]], stack)
self.assertEqual(stack["files"], order)
self.assertEqual(stack["peeks"], ["operator:operator/issue", f"review:{self.stale}"], stack)
self.assertFalse(stack["accept"], stack)
self.assertFalse(stack["wide"], stack)
scroll = next(results)
self.assertEqual(scroll["steps"][0], order[:1], scroll)
self.assertEqual(scroll["steps"][-1], order, scroll)
for step in scroll["steps"]:
self.assertEqual(step, order[: len(step)], scroll)
self.assertGreater(len({len(step) for step in scroll["steps"]}), 2, scroll)
self.assertEqual(scroll["numbered"], [[path, True] for path in order], scroll)
mark = next(results)
self.assertEqual((mark["clicked"], mark["pressed"]), (True, True), mark)
self.assertEqual(mark["marks"], [["3", "use the helper here"], ["6", "long press note"]], mark)
self.assertEqual(mark["marked"], ["3", "6"], mark)
self.assertEqual(mark["count"], "2", mark)
command = next(results)
self.assertEqual((command["kind"], command["stale"], command["command"], command["why"]), ("command", "false", self.command, "file the release issue"), command)
self.assertEqual(command["where"], str(self.work), command)
self.assertEqual(command["payload"], [["body.md", "read", 14], ["link.md", "refused", 0]], command)
self.assertEqual((command["name"], command["age"]), ("Skills", "3 days"), command)
stale = next(results)
self.assertEqual((stale["kind"], stale["stale"], stale["accept"], stale["name"], stale["age"]), ("commit", "true", True, "Stage", "9 days"), stale)
self.assertIn("changed", stale["reason"])
def test_chromium_shows_face_place_files_on_scroll_and_marks_at_three_widths(self):
data = self.drive(self.steps("chromium", base.WIDTHS), None)
(OUT / "chromium-match.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
self.assertEqual(data["errors"], [])
self.check(data, base.WIDTHS)
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
def test_firefox_shows_face_place_files_on_scroll_and_marks_at_three_widths(self):
data = self.drive(self.steps("firefox", base.WIDTHS), None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"))
(OUT / "firefox-match.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
self.assertEqual([error for error in data["errors"] if "/favicon.ico" not in error], [])
self.check(data, base.WIDTHS)
if __name__ == "__main__":
unittest.main()
+208
View File
@@ -0,0 +1,208 @@
from __future__ import annotations
import json
import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path
from hub_case import HubCase
from hub_support import GIT_ENV, HUB, REPO_ROOT
from kvb_orchestrator import payloads
MATCH = REPO_ROOT / "skills" / "kvb-match" / "scripts" / "match.py"
CLIENT = HUB / "client"
def git(cwd: Path, *args: str) -> str:
done = subprocess.run(["git", *args], cwd=cwd, env={**os.environ, **GIT_ENV}, check=True, capture_output=True, text=True)
return done.stdout
def staged_repo(root: Path) -> Path:
repo = root / "demo"
repo.mkdir()
git(repo, "init", "-q", "-b", "feature/match")
(repo / "app.py").write_text("keep = 1\nold = 2\n", encoding="utf-8")
git(repo, "add", "-A")
git(repo, "commit", "-q", "-m", "base")
(repo / "app.py").write_text("keep = 1\nnew = 3\nmore = 4\n", encoding="utf-8")
(repo / "notes.md").write_text("# Notes\n\nfresh\n", encoding="utf-8")
git(repo, "add", "-A")
return repo
class MatchCase(HubCase):
def setUp(self):
super().setUp()
work = tempfile.TemporaryDirectory()
self.addCleanup(work.cleanup)
self.work = Path(work.name)
self.sandbox_view([])
def sandbox_view(self, denied: list[str]) -> None:
folder = self.state / "firewall"
folder.mkdir(parents=True, exist_ok=True)
settings = {"sandbox": {"filesystem": {"denyRead": denied}}}
files = [{"path": "/home/op/.claude/settings.json", "exists": True, "sha256": "", "settings": settings}]
(folder / "view.json").write_text(json.dumps({"written": "2026-11-14T12:00:00+00:00", "files": files}), encoding="utf-8")
def match(self, cwd: Path, *args: str) -> subprocess.CompletedProcess:
command = [sys.executable, str(MATCH), *args, "--port", str(self.port), "--client", str(CLIENT)]
return subprocess.run(command, cwd=cwd, env={**os.environ, **GIT_ENV}, capture_output=True, text=True, timeout=60, check=False)
def add(self, repo: Path) -> str:
done = self.match(repo, "add", "--repo", str(repo), "--title", "feat: match", "--score", "🎯 95 💥 3", "--gate", "pass", "--agent", "Skills", "--pages", str(self.pages))
self.assertEqual(done.returncode, 0, done.stderr)
return json.loads(done.stdout)["id"]
def cards(self) -> list[dict]:
status, _, body = self.get("/api/match")
self.assertEqual(status, 200, body)
return json.loads(body)["cards"]
def card(self, card_id: str) -> dict:
return next(card for card in self.cards() if card["id"] == card_id)
def operator_row(self, task: str, command: str, directory: str) -> None:
register = {task: {"title": command, "workdir": directory, "description": "ship the release notes", "check": "done", "roles": {"Skills": "A", "Operator": "R"}}}
self.write_council({"rasci.json": register})
class TestMatchSkill(MatchCase):
def test_add_takes_the_staged_patch_and_tree_and_list_and_show_print_them(self):
repo = staged_repo(self.work)
review = self.add(repo)
card = self.card(f"review:{review}")
self.assertEqual((card["kind"], card["hash"], card["stale"]), ("commit", git(repo, "write-tree").strip(), False))
self.assertEqual((card["branch"], card["worktree"], card["agent"], card["title"]), ("feature/match", str(repo), "Skills", "feat: match"))
self.assertEqual([entry["path"] for entry in card["files"]], ["app.py", "notes.md"])
shown = self.match(repo, "show", f"review:{review}")
self.assertEqual(shown.returncode, 0, shown.stderr)
self.assertEqual(shown.stdout, git(repo, "diff", "--cached"))
listed = self.match(repo, "list")
self.assertEqual(listed.returncode, 0, listed.stderr)
self.assertIn(f"review:{review}", listed.stdout)
self.assertIn("feat: match", listed.stdout)
def test_add_refuses_an_empty_stage(self):
repo = staged_repo(self.work)
git(repo, "commit", "-q", "-m", "all")
done = self.match(repo, "add", "--repo", str(repo), "--title", "feat: none", "--score", "🎯 1", "--gate", "pass", "--agent", "Skills", "--pages", str(self.pages))
self.assertEqual(done.returncode, 1)
self.assertIn("nothing staged", done.stderr)
self.assertEqual(self.cards(), [])
def test_a_changed_stage_turns_the_card_stale_and_adding_it_again_gives_a_fresh_card(self):
repo = staged_repo(self.work)
first = self.add(repo)
(repo / "notes.md").write_text("# Notes\n\nchanged\n", encoding="utf-8")
git(repo, "add", "-A")
listed = self.match(repo, "list")
self.assertEqual(listed.returncode, 0, listed.stderr)
self.assertIn("stale", listed.stdout)
old = self.card(f"review:{first}")
self.assertTrue(old["stale"], old)
self.assertIn("changed", old["stale_reason"])
second = self.add(repo)
fresh = self.card(f"review:{second}")
self.assertEqual((fresh["stale"], fresh["hash"]), (False, git(repo, "write-tree").strip()))
self.assertTrue(self.card(f"review:{first}")["stale"])
def test_a_stale_report_needs_the_local_guard_and_a_tree(self):
repo = staged_repo(self.work)
review = self.add(repo)
status, _, _ = self.post_json("/api/match/stale", {"id": review, "tree": "f" * 40}, {"Host": self.host})
self.assertEqual(status, 403)
status, _, _ = self.post_json("/api/match/stale", {"id": review, "tree": "nope"}, self.local())
self.assertEqual(status, 400)
self.assertFalse(self.card(f"review:{review}")["stale"])
def test_a_gone_review_or_operator_row_leaves_the_cards(self):
repo = staged_repo(self.work)
review = self.add(repo)
self.operator_row("operator/ship", "make ship", str(self.work))
self.assertEqual(sorted(card["id"] for card in self.cards()), sorted([f"review:{review}", "operator:operator/ship"]))
status, _, body = self.post_json(f"/reviews/{review}/reject", {}, self.guard(self.host))
self.assertEqual(status, 200, body)
self.write_council({"rasci.json": {}})
self.assertEqual(self.cards(), [])
class TestCommandCards(MatchCase):
def payload_command(self) -> str:
body = self.work / "body.md"
body.write_text("# Release\n\nline two\n", encoding="utf-8")
(self.work / "link.md").symlink_to(body)
(self.work / "big.txt").write_text("x" * (payloads.PAYLOAD_LIMIT + 1), encoding="utf-8")
(self.work / "secret.txt").write_text("hidden\n", encoding="utf-8")
return f"gh issue create --body-file {body} --list link.md --big=big.txt --key {self.work / 'secret.txt'} --base origin/main"
def test_an_operator_row_is_a_card_with_command_directory_reason_and_payload_files(self):
self.sandbox_view([str(self.work / "secret.txt")])
command = self.payload_command()
self.operator_row("operator/ship", command, str(self.work))
card = self.card("operator:operator/ship")
self.assertEqual((card["kind"], card["command"], card["directory"], card["reason"], card["agent"], card["stale"]), ("command", command, str(self.work), "ship the release notes", "Skills", False))
files = {Path(entry["path"]).name: entry for entry in card["files"]}
self.assertEqual(sorted(files), ["big.txt", "body.md", "link.md", "secret.txt"])
self.assertEqual((files["body.md"]["state"], files["body.md"]["content"]), ("read", "# Release\n\nline two\n"))
for name, words in (("link.md", "symlink"), ("big.txt", "bytes"), ("secret.txt", "sandbox")):
with self.subTest(name=name):
self.assertEqual((files[name]["state"], files[name]["content"]), ("refused", ""))
self.assertIn(words, files[name]["reason"])
def test_without_a_sandbox_view_every_payload_file_is_refused(self):
(self.state / "firewall" / "view.json").unlink()
command = self.payload_command()
self.operator_row("operator/ship", command, str(self.work))
states = {entry["state"] for entry in self.card("operator:operator/ship")["files"]}
self.assertEqual(states, {"refused"})
def test_a_changed_payload_file_turns_the_card_stale_until_it_is_added_again(self):
command = self.payload_command()
self.operator_row("operator/ship", command, str(self.work))
before = self.card("operator:operator/ship")
(self.work / "body.md").write_text("# Release\n\nswapped\n", encoding="utf-8")
after = self.card("operator:operator/ship")
self.assertTrue(after["stale"], after)
self.assertEqual(after["files"], before["files"])
self.assertNotEqual(after["live_hash"], after["hash"])
done = self.match(self.work, "add", "--task", "operator/ship")
self.assertEqual(done.returncode, 0, done.stderr)
fresh = self.card("operator:operator/ship")
self.assertFalse(fresh["stale"], fresh)
self.assertIn("swapped", next(entry["content"] for entry in fresh["files"] if entry["path"].endswith("body.md")))
def test_decision_rows_and_rows_at_the_runner_are_no_cards(self):
self.write_council({"rasci.json": {"operator/pick": {"title": "-", "workdir": str(self.work), "check": "decision", "roles": {"Operator": "R"}}}})
self.assertEqual(self.cards(), [])
def test_show_prints_the_command_and_its_payload(self):
command = self.payload_command()
self.operator_row("operator/ship", command, str(self.work))
shown = self.match(self.work, "show", "operator:operator/ship")
self.assertEqual(shown.returncode, 0, shown.stderr)
for words in (command, f"in {self.work}", "line two", "refused"):
with self.subTest(words=words):
self.assertIn(words, shown.stdout)
class TestPayloadHash(unittest.TestCase):
def test_the_hash_binds_command_directory_and_every_file_state(self):
files = [{"path": "/tmp/a", "state": "read", "reason": "", "sha256": "1" * 64, "size": 3, "content": "abc"}]
base = payloads.payload_hash("make ship", "/repo", files)
self.assertEqual(base, payloads.payload_hash("make ship", "/repo", [dict(files[0])]))
self.assertRegex(base, "^[0-9a-f]{64}$")
for changed in (payloads.payload_hash("make ship ", "/repo", files), payloads.payload_hash("make ship", "/other", files), payloads.payload_hash("make ship", "/repo", [{**files[0], "sha256": "2" * 64}]), payloads.payload_hash("make ship", "/repo", [{**files[0], "state": "refused"}])):
self.assertNotEqual(changed, base)
def test_named_paths_come_from_words_and_option_values_resolved_in_the_directory(self):
named = payloads.named_paths("gh issue create --body-file /tmp/x/body.md --list=list.txt scripts/run.sh 'quoted file.md' https://example.org/a.md", "/repo")
self.assertEqual(named, ["/tmp/x/body.md", "/repo/list.txt", "/repo/scripts/run.sh", "/repo/quoted file.md"])
if __name__ == "__main__":
unittest.main()
+1
View File
@@ -16,6 +16,7 @@ UNCATEGORIZED = frozenset(
"kvb-coach",
"kvb-dream",
"kvb-help",
"kvb-match",
"kvb-optimize",
"kvb-release",
"kvb-transcend",