feat(orchestrator): Match cards show the score line as metric chips
scores.metric_chips() reads each metric's value from an agent's free score line by emoji, label or former label from labels.json, and Match cards render them as chips under the name instead of the raw score pill. New e2e: real mouse swipes send later, reject, refuse a stale card and accept at three widths; the release e2e gains its negative control. Fix stays below 90: the swipe e2e ended in ERROR in the aborted final run of 2026-11-17 without a traceback; the master gate reruns it. 🎯 Fix: 88 % 💥 Break: 3 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 85 🚦 Gate: ⛔ fix 88 % < 90 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b711c3b83b
commit
78d4e4a6aa
8 files changed
+302
-16
No files matched your search
@@ -10,6 +10,7 @@ from .fields import decode, expect, field
|
|||||||
from .payloads import denied_roots, payload_files, payload_hash
|
from .payloads import denied_roots, payload_files, payload_hash
|
||||||
from .records import digest, iso_epoch
|
from .records import digest, iso_epoch
|
||||||
from .register import REGISTER, adder, operator_rows, read_register
|
from .register import REGISTER, adder, operator_rows, read_register
|
||||||
|
from .scores import metric_chips, score_labels
|
||||||
from .signed import signing
|
from .signed import signing
|
||||||
from .tree import inside
|
from .tree import inside
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@ class Matching:
|
|||||||
claims = read_claims(self.council)
|
claims = read_claims(self.council)
|
||||||
names = self.names.listed()
|
names = self.names.listed()
|
||||||
reviews = self.reviews.pending()
|
reviews = self.reviews.pending()
|
||||||
cards = [{**self.commit_card(review, reviews, born_of(review.get("agent", ""), names, claims)), "to": requester_of(claims, review.get("agent", ""))[0]} for review in reviews]
|
labels = score_labels(self.scripts.skills)
|
||||||
|
cards = [{**self.commit_card(review, reviews, born_of(review.get("agent", ""), names, claims), labels), "to": requester_of(claims, review.get("agent", ""))[0]} for review in reviews]
|
||||||
tasks = read_register(self.council / REGISTER)
|
tasks = read_register(self.council / REGISTER)
|
||||||
held = self.open_jobs()
|
held = self.open_jobs()
|
||||||
rows = [row for row in operator_rows(tasks) if row["check"] != "decision" and row["task"] not in held]
|
rows = [row for row in operator_rows(tasks) if row["check"] != "decision" and row["task"] not in held]
|
||||||
@@ -61,7 +63,7 @@ class Matching:
|
|||||||
self.match_snapshots.remove(snapshot["id"])
|
self.match_snapshots.remove(snapshot["id"])
|
||||||
return {"now": now, "cards": cards}
|
return {"now": now, "cards": cards}
|
||||||
|
|
||||||
def commit_card(self, review: dict, reviews: list[dict], born: float | None) -> dict:
|
def commit_card(self, review: dict, reviews: list[dict], born: float | None, labels: dict | None) -> dict:
|
||||||
newer = [other["id"] for other in reviews if other["created"] > review["created"] and (other["worktree"], other["branch"]) == (review["worktree"], review["branch"])]
|
newer = [other["id"] for other in reviews if other["created"] > review["created"] and (other["worktree"], other["branch"]) == (review["worktree"], review["branch"])]
|
||||||
live = review.get("live_tree")
|
live = review.get("live_tree")
|
||||||
reason = f"added again as review:{newer[-1]}" if newer else "the staged tree changed since it was added" if live not in (None, review["tree"]) else ""
|
reason = f"added again as review:{newer[-1]}" if newer else "the staged tree changed since it was added" if live not in (None, review["tree"]) else ""
|
||||||
@@ -72,7 +74,8 @@ class Matching:
|
|||||||
place = {"repo": repository_of(review.get("repo", "")), "branch": review["branch"], "worktree": review["worktree"]}
|
place = {"repo": repository_of(review.get("repo", "")), "branch": review["branch"], "worktree": review["worktree"]}
|
||||||
return {
|
return {
|
||||||
"id": f"review:{review['id']}", "kind": "commit", "ref": review["id"], "agent": review.get("agent", ""), "born": born, "created_ts": iso_epoch(review["created"]),
|
"id": f"review:{review['id']}", "kind": "commit", "ref": review["id"], "agent": review.get("agent", ""), "born": born, "created_ts": iso_epoch(review["created"]),
|
||||||
**place, "title": review["title"], "score": review.get("score", ""), "gate": review.get("gate", ""), "hash": review["tree"], "live_hash": live or review["tree"],
|
**place, "title": review["title"], "score": review.get("score", ""), "metrics": metric_chips(review.get("score", ""), labels), "gate": review.get("gate", ""),
|
||||||
|
"hash": review["tree"], "live_hash": live or review["tree"],
|
||||||
"stale": bool(reason), "stale_reason": reason, "files": files, "command": "", "directory": review["worktree"], "reason": "",
|
"stale": bool(reason), "stale_reason": reason, "files": files, "command": "", "directory": review["worktree"], "reason": "",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +91,7 @@ class Matching:
|
|||||||
repo, branch, worktree = place_of(row["directory"], scan)
|
repo, branch, worktree = place_of(row["directory"], scan)
|
||||||
return {
|
return {
|
||||||
"id": card_id, "kind": "command", "ref": row["task"], "agent": agent, "born": born, "created_ts": snapshot["taken"], "repo": repo, "branch": branch, "worktree": worktree,
|
"id": card_id, "kind": "command", "ref": row["task"], "agent": agent, "born": born, "created_ts": snapshot["taken"], "repo": repo, "branch": branch, "worktree": worktree,
|
||||||
"title": row["command"], "score": "", "gate": "", "hash": snapshot["hash"], "live_hash": live, "stale": stale,
|
"title": row["command"], "score": "", "metrics": [], "gate": "", "hash": snapshot["hash"], "live_hash": live, "stale": stale,
|
||||||
"stale_reason": "a payload file changed since it was added" if stale else "", "files": snapshot["files"], "command": row["command"], "directory": row["directory"],
|
"stale_reason": "a payload file changed since it was added" if stale else "", "files": snapshot["files"], "command": row["command"], "directory": row["directory"],
|
||||||
"reason": row["why"], "sha256": digest(row["command"]),
|
"reason": row["why"], "sha256": digest(row["command"]),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .records import epoch, parse_line, read_json, read_regular
|
from .records import epoch, parse_line, read_json, read_regular
|
||||||
@@ -7,6 +8,8 @@ from .records import epoch, parse_line, read_json, read_regular
|
|||||||
SCORES = "scores.jsonl"
|
SCORES = "scores.jsonl"
|
||||||
LABELS = "kvb-check-score/labels.json"
|
LABELS = "kvb-check-score/labels.json"
|
||||||
FILE_LIMIT = 64 << 20
|
FILE_LIMIT = 64 << 20
|
||||||
|
VARIATION = "️"
|
||||||
|
VALUE = r"([0-9]+(?:\.[0-9]+)?(?:\s*%)?|–|-|new)(?![0-9.])"
|
||||||
|
|
||||||
|
|
||||||
def checked(labels: object) -> dict | None:
|
def checked(labels: object) -> dict | None:
|
||||||
@@ -51,4 +54,30 @@ def scored(council: Path, skills: Path, span: tuple[float, float]) -> dict:
|
|||||||
"""
|
"""
|
||||||
begin, end = span
|
begin, end = span
|
||||||
inside = [row for row in journal(council) if (moment := epoch(row.get("time"))) is not None and begin <= moment <= end]
|
inside = [row for row in journal(council) if (moment := epoch(row.get("time"))) is not None and begin <= moment <= end]
|
||||||
return {"since": begin, "until": end, "labels": checked(read_json(skills / LABELS)), "rows": sorted(inside, key=lambda row: row["time"])}
|
return {"since": begin, "until": end, "labels": score_labels(skills), "rows": sorted(inside, key=lambda row: row["time"])}
|
||||||
|
|
||||||
|
|
||||||
|
def score_labels(skills: Path) -> dict | None:
|
||||||
|
return checked(read_json(skills / LABELS))
|
||||||
|
|
||||||
|
|
||||||
|
def metric_chips(score: str, labels: dict | None) -> list[dict]:
|
||||||
|
"""Args:
|
||||||
|
score: an agent's free score line, such as line 1 or the message
|
||||||
|
block of score.py.
|
||||||
|
labels: the label file as checked() returns it, or None.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
In label order, per metric whose emoji (with or without its
|
||||||
|
variation selector) or label or former label stands right before a
|
||||||
|
value in score, the first such value: {"id", "emoji", "label",
|
||||||
|
"value"}; none without labels.
|
||||||
|
"""
|
||||||
|
found = []
|
||||||
|
for key, metric in (labels or {}).get("metrics", {}).items():
|
||||||
|
emoji = re.escape(metric["emoji"].removesuffix(VARIATION)) + f"{VARIATION}?"
|
||||||
|
names = "|".join(re.escape(name) for name in (metric["label"], *metric.get("former", [])))
|
||||||
|
match = re.search(rf"(?:{emoji}\s*(?:(?:{names})\s*:?\s*)?|\b(?:{names})\s*:?\s*){VALUE}", score, re.IGNORECASE)
|
||||||
|
if match:
|
||||||
|
found.append({"id": key, "emoji": metric["emoji"], "label": metric["label"], "value": " ".join(match.group(1).split())})
|
||||||
|
return found
|
||||||
@@ -202,10 +202,13 @@
|
|||||||
|
|
||||||
function matchHead(card) {
|
function matchHead(card) {
|
||||||
const [kindName, kindTone, kindIcon] = MATCH_KINDS[card.kind] || [card.kind, "neutral", "bi-collection"];
|
const [kindName, kindTone, kindIcon] = MATCH_KINDS[card.kind] || [card.kind, "neutral", "bi-collection"];
|
||||||
|
const metrics = card.metrics || [];
|
||||||
return h("header", {class: "match-head"},
|
return h("header", {class: "match-head"},
|
||||||
h("div", {class: "match-who"}, face(card.agent || "-", true), h("strong", {class: "match-name"}, revealed(card.agent || "unknown agent")), h("span", {class: "match-age"}, ageWords(card.born))),
|
h("div", {class: "match-who"}, face(card.agent || "-", true), h("strong", {class: "match-name"}, revealed(card.agent || "unknown agent")), h("span", {class: "match-age"}, ageWords(card.born))),
|
||||||
|
metrics.length ? h("ul", {class: "match-metrics", "aria-label": "Scores"}, metrics.map((metric) => h("li", {class: "match-metric", "data-metric": metric.id, title: revealed(`${metric.label}: ${metric.value}`)},
|
||||||
|
h("span", {"aria-hidden": "true"}, metric.emoji), h("span", {class: "match-metric-label"}, metric.label), h("strong", {}, revealed(metric.value))))) : null,
|
||||||
h("div", {class: "states"}, h("span", {class: "pill", "data-tone": kindTone}, icon(kindIcon), kindName), card.gate ? pill(`gate ${card.gate}`, card.gate === "pass" ? "ok" : "bad") : null,
|
h("div", {class: "states"}, h("span", {class: "pill", "data-tone": kindTone}, icon(kindIcon), kindName), card.gate ? pill(`gate ${card.gate}`, card.gate === "pass" ? "ok" : "bad") : null,
|
||||||
card.score ? h("span", {class: "pill", "data-tone": "neutral"}, revealed(card.score)) : null, card.stale ? h("span", {class: "pill match-stale-pill", "data-tone": "bad"}, icon("bi-hourglass-split"), "stale") : null),
|
card.score && !metrics.length ? h("span", {class: "pill", "data-tone": "neutral"}, revealed(card.score)) : null, card.stale ? h("span", {class: "pill match-stale-pill", "data-tone": "bad"}, icon("bi-hourglass-split"), "stale") : null),
|
||||||
h("dl", {class: "meta match-place"}, [["Repository", card.repo], ["Branch", card.branch], ["Worktree", card.worktree]].map(([label, value]) => h("div", {}, h("dt", {}, label), h("dd", {}, h("code", {title: value ? revealed(value) : null}, revealed(dash(value))))))),
|
h("dl", {class: "meta match-place"}, [["Repository", card.repo], ["Branch", card.branch], ["Worktree", card.worktree]].map(([label, value]) => h("div", {}, h("dt", {}, label), h("dd", {}, h("code", {title: value ? revealed(value) : null}, revealed(dash(value))))))),
|
||||||
h("h2", {class: "match-title"}, revealed(card.title)),
|
h("h2", {class: "match-title"}, revealed(card.title)),
|
||||||
card.stale ? h("p", {class: "match-stale"}, icon("bi-exclamation-triangle"), revealed(card.stale_reason)) : null);
|
card.stale ? h("p", {class: "match-stale"}, icon("bi-exclamation-triangle"), revealed(card.stale_reason)) : null);
|
||||||
|
|||||||
@@ -13,6 +13,9 @@
|
|||||||
.match-who .avatar.big { width: 72px; height: 72px; }
|
.match-who .avatar.big { width: 72px; height: 72px; }
|
||||||
.match-name { font-size: var(--fs-lg); }
|
.match-name { font-size: var(--fs-lg); }
|
||||||
.match-age { color: var(--muted); font-size: var(--fs-sm); }
|
.match-age { color: var(--muted); font-size: var(--fs-sm); }
|
||||||
|
.match-metrics { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
|
||||||
|
.match-metric { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--sunken); font-size: var(--fs-sm); white-space: nowrap; }
|
||||||
|
.match-metric-label { color: var(--muted); }
|
||||||
.match-place { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); width: 100%; margin: 0; text-align: left; }
|
.match-place { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); width: 100%; margin: 0; text-align: left; }
|
||||||
.match-place code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
.match-place code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
.match-title { margin: 0; font-size: var(--fs-md); overflow-wrap: anywhere; }
|
.match-title { margin: 0; font-size: var(--fs-md); overflow-wrap: anywhere; }
|
||||||
|
|||||||
@@ -26,12 +26,22 @@ FLOW = """(async () => {@HELPERS@
|
|||||||
navigator.credentials.get = () => Promise.reject(new DOMException("The operator canceled.", "NotAllowedError"));
|
navigator.credentials.get = () => Promise.reject(new DOMException("The operator canceled.", "NotAllowedError"));
|
||||||
}
|
}
|
||||||
const posted = [];
|
const posted = [];
|
||||||
|
const statuses = [];
|
||||||
|
let tamper = @SIGNS@ && @RELEASE@;
|
||||||
const send = window.fetch.bind(window);
|
const send = window.fetch.bind(window);
|
||||||
window.fetch = (path, init) => {
|
window.fetch = async (path, init) => {
|
||||||
if (["/api/sign", "/api/inbox/approve"].includes(String(path))) {
|
if (!["/api/sign", "/api/inbox/approve"].includes(String(path))) {
|
||||||
posted.push([String(path), JSON.parse(init.body).items.map((item) => [item.kind, item.id, item.verb, item.channel || null, item.reason || null, item.to || null])]);
|
return send(path, init);
|
||||||
}
|
}
|
||||||
return send(path, init);
|
let body = JSON.parse(init.body);
|
||||||
|
if (String(path) === "/api/inbox/approve" && tamper) {
|
||||||
|
tamper = false;
|
||||||
|
body = {...body, items: body.items.map((item) => (item.verb === "reject" ? {kind: item.kind, id: item.id, verb: "approve", label: item.label, sha256: item.sha256} : item))};
|
||||||
|
}
|
||||||
|
posted.push([String(path), body.items.map((item) => [item.kind, item.id, item.verb, item.channel || null, item.reason || null, item.to || null])]);
|
||||||
|
const response = await send(path, {...init, body: JSON.stringify(body)});
|
||||||
|
statuses.push(response.status);
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
const card = () => document.querySelector("#main .match-card.front");
|
const card = () => document.querySelector("#main .match-card.front");
|
||||||
const front = () => (card() ? card().dataset.card : null);
|
const front = () => (card() ? card().dataset.card : null);
|
||||||
@@ -82,11 +92,19 @@ FLOW = """(async () => {@HELPERS@
|
|||||||
const release = document.querySelector("#main .match-release");
|
const release = document.querySelector("#main .match-release");
|
||||||
const found = {order, prefill, leaned, short, stayed, rows, label: text(release), disabled: release.disabled, wide: document.documentElement.scrollWidth > window.innerWidth + 1};
|
const found = {order, prefill, leaned, short, stayed, rows, label: text(release), disabled: release.disabled, wide: document.documentElement.scrollWidth > window.innerWidth + 1};
|
||||||
if (@RELEASE@) {
|
if (@RELEASE@) {
|
||||||
const shown = new Set(all("#toasts .toast"));
|
const toastAfter = async (click) => {
|
||||||
release.click();
|
const shown = new Set(all("#toasts .toast"));
|
||||||
found.toast = await until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith("Release")), 15000);
|
click();
|
||||||
|
return until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith("Release")), 15000);
|
||||||
|
};
|
||||||
|
if (@SIGNS@) {
|
||||||
|
found.tampered = await toastAfter(() => release.click());
|
||||||
|
found.kept = all("#main .match-decision").length;
|
||||||
|
}
|
||||||
|
found.toast = await toastAfter(() => document.querySelector("#main .match-release").click());
|
||||||
found.emptied = @SIGNS@ ? Boolean(await until(() => document.querySelector("#main .match-stack .empty"), 15000)) : false;
|
found.emptied = @SIGNS@ ? Boolean(await until(() => document.querySelector("#main .match-stack .empty"), 15000)) : false;
|
||||||
found.posted = posted;
|
found.posted = posted;
|
||||||
|
found.statuses = statuses;
|
||||||
}
|
}
|
||||||
return found;
|
return found;
|
||||||
})()"""
|
})()"""
|
||||||
@@ -173,11 +191,17 @@ class TestMatchRelease(HubCase):
|
|||||||
|
|
||||||
def test_chromium_swipes_three_cards_rejects_with_feedback_and_releases_with_one_signature(self):
|
def test_chromium_swipes_three_cards_rejects_with_feedback_and_releases_with_one_signature(self):
|
||||||
released = self.run_flow("chromium", "cdp.mjs", os.environ.get("CHROMIUM", "chromium"), signs=True)
|
released = self.run_flow("chromium", "cdp.mjs", os.environ.get("CHROMIUM", "chromium"), signs=True)
|
||||||
|
self.assertTrue(released["tampered"].startswith("Release: 3 decisions: not possible"), released)
|
||||||
|
self.assertIn("list every approved item", released["tampered"], released)
|
||||||
|
self.assertEqual(released["kept"], 3, released)
|
||||||
self.assertTrue(released["toast"].startswith("Release: 3 decisions"), released)
|
self.assertTrue(released["toast"].startswith("Release: 3 decisions"), released)
|
||||||
|
self.assertNotIn("not possible", released["toast"], released)
|
||||||
self.assertTrue(released["emptied"], released)
|
self.assertTrue(released["emptied"], released)
|
||||||
posted = [path for path, _ in released["posted"]]
|
posted = [path for path, _ in released["posted"]]
|
||||||
self.assertEqual(posted, ["/api/sign", "/api/inbox/approve"])
|
self.assertEqual(posted, ["/api/sign", "/api/inbox/approve"] * 2)
|
||||||
items = sorted(released["posted"][1][1])
|
self.assertEqual(released["statuses"], [200, 400, 200, 202], released)
|
||||||
|
self.assertIn(["review", self.rejected, "approve", None, None, None], released["posted"][1][1])
|
||||||
|
items = sorted(released["posted"][3][1])
|
||||||
told = f"{FIRST}:3: rename it\nalso add a test"
|
told = f"{FIRST}:3: rename it\nalso add a test"
|
||||||
self.assertEqual(items, sorted([["review", self.rejected, "reject", "call", told, "Skills"], ["review", self.accepted, "approve", None, None, None], ["operator", "operator/ship", "approve", None, None, None]]))
|
self.assertEqual(items, sorted([["review", self.rejected, "reject", "call", told, "Skills"], ["review", self.accepted, "approve", None, None, None], ["operator", "operator/ship", "approve", None, None, None]]))
|
||||||
stored = self.httpd.hub.reviews.get(self.rejected)
|
stored = self.httpd.hub.reviews.get(self.rejected)
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ CARD = """
|
|||||||
const head = () => ({
|
const head = () => ({
|
||||||
card: card().dataset.card, kind: card().dataset.kind, stale: card().dataset.stale, face: Boolean(card().querySelector(".match-who .avatar svg")),
|
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")),
|
name: text(card().querySelector(".match-name")), age: text(card().querySelector(".match-age")),
|
||||||
|
metrics: all(".match-metric", card()).map((chip) => [chip.dataset.metric, text(chip.querySelector("strong"))]),
|
||||||
|
under: Boolean(card().querySelector(".match-metrics")) && card().querySelector(".match-metrics").getBoundingClientRect().top >= card().querySelector(".match-name").getBoundingClientRect().bottom - 1,
|
||||||
place: all(".match-place dt", card()).map(text).map((label, index) => [label, text(all(".match-place dd", card())[index])]),
|
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,
|
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),
|
reason: text(card().querySelector(".match-stale")), peeks: all("#main .match-peek").map((tab) => tab.dataset.card),
|
||||||
@@ -115,6 +117,9 @@ class TestMatchReview(HubCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
self.cards()
|
||||||
|
|
||||||
|
def cards(self) -> None:
|
||||||
work = tempfile.TemporaryDirectory()
|
work = tempfile.TemporaryDirectory()
|
||||||
self.addCleanup(work.cleanup)
|
self.addCleanup(work.cleanup)
|
||||||
self.work = Path(work.name)
|
self.work = Path(work.name)
|
||||||
@@ -171,6 +176,7 @@ class TestMatchReview(HubCase):
|
|||||||
stack = next(results)
|
stack = next(results)
|
||||||
self.assertEqual((stack["card"], stack["kind"], stack["stale"], stack["face"]), (f"review:{self.commit}", "commit", "false", True), stack)
|
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["name"], stack["age"]), ("Skills", "3 days"), stack)
|
||||||
|
self.assertEqual((stack["metrics"], stack["under"]), ([["fix", "95"], ["break", "3"]], True), stack)
|
||||||
self.assertEqual(stack["place"], [["Repository", "/repo"], ["Branch", "feature/match"], ["Worktree", "/repo/.worktrees/feature/match"]], stack)
|
self.assertEqual(stack["place"], [["Repository", "/repo"], ["Branch", "feature/match"], ["Worktree", "/repo/.worktrees/feature/match"]], stack)
|
||||||
self.assertEqual(stack["files"], order)
|
self.assertEqual(stack["files"], order)
|
||||||
self.assertEqual(stack["peeks"], ["operator:operator/issue", f"review:{self.stale}"], stack)
|
self.assertEqual(stack["peeks"], ["operator:operator/issue", f"review:{self.stale}"], stack)
|
||||||
|
|||||||
@@ -0,0 +1,196 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
HERE = Path(__file__).resolve().parent
|
||||||
|
sys.path[:0] = [str(HERE.parent), str(HERE)]
|
||||||
|
|
||||||
|
import hub_e2e_kit as base
|
||||||
|
import test_match_review_e2e as matched
|
||||||
|
from hub_case import HubCase
|
||||||
|
|
||||||
|
OUT = Path(os.environ.get("E2E_OUT", "/tmp/match-swipe-shots"))
|
||||||
|
REACH = 0.4
|
||||||
|
LIFT = 120
|
||||||
|
SIDE = """
|
||||||
|
const key = (value) => document.body.dispatchEvent(new KeyboardEvent("keydown", {key: value, bubbles: true}));
|
||||||
|
const front = () => (card() ? card().dataset.card : null);
|
||||||
|
const tally = () => text(document.querySelector("#main .match-tally"));
|
||||||
|
const point = () => {
|
||||||
|
const name = card().querySelector(".match-name").getBoundingClientRect();
|
||||||
|
return {front: front(), x: Math.round(name.left + name.width / 2), y: Math.round(name.top + name.height / 2), width: card().getBoundingClientRect().width};
|
||||||
|
};
|
||||||
|
const aim = (x, y) => {
|
||||||
|
const at = document.elementFromPoint(x, y);
|
||||||
|
return Boolean(at && at.closest(".match-card.front .match-head") && !at.closest("button, a, input, textarea, select"));
|
||||||
|
};
|
||||||
|
const turned = (id) => until(() => front() === id && card(), 6000);
|
||||||
|
const fresh = () => new Set(all("#toasts .toast"));
|
||||||
|
const toastSince = (shown, start) => until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith(start)), 4000);
|
||||||
|
"""
|
||||||
|
MEASURE = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
await screenShown(8000);
|
||||||
|
if (!(await turned("@COMMIT@"))) {
|
||||||
|
return {error: text(document.getElementById("main"))};
|
||||||
|
}
|
||||||
|
await sleep(500);
|
||||||
|
const points = [point()];
|
||||||
|
key("ArrowUp");
|
||||||
|
await turned("@COMMAND@");
|
||||||
|
await sleep(400);
|
||||||
|
points.push(point());
|
||||||
|
key("ArrowLeft");
|
||||||
|
const confirm = await until(() => document.querySelector(".match-feedback-reject"), 4000);
|
||||||
|
confirm.click();
|
||||||
|
await turned("@STALE@");
|
||||||
|
await sleep(400);
|
||||||
|
points.push(point());
|
||||||
|
key("ArrowRight");
|
||||||
|
await sleep(400);
|
||||||
|
key("ArrowUp");
|
||||||
|
await turned("@COMMIT@");
|
||||||
|
await sleep(400);
|
||||||
|
points.push(point());
|
||||||
|
return {points, tally: tally()};
|
||||||
|
})()"""
|
||||||
|
START = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
await screenShown(8000);
|
||||||
|
if (!(await turned("@COMMIT@"))) {
|
||||||
|
return {error: text(document.getElementById("main"))};
|
||||||
|
}
|
||||||
|
await sleep(500);
|
||||||
|
return {front: front(), aim: aim(@X@, @Y@), tally: tally()};
|
||||||
|
})()"""
|
||||||
|
LATER = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
await turned("@COMMAND@");
|
||||||
|
await sleep(400);
|
||||||
|
return {front: front(), tally: tally(), aim: aim(@X@, @Y@)};
|
||||||
|
})()"""
|
||||||
|
REJECT = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
const confirm = await until(() => document.querySelector(".match-feedback-reject"), 4000);
|
||||||
|
const title = text(document.querySelector("#sheet .sheet-head h2"));
|
||||||
|
const field = Boolean(document.querySelector("#sheet textarea.match-feedback"));
|
||||||
|
if (confirm) {
|
||||||
|
confirm.click();
|
||||||
|
}
|
||||||
|
await turned("@STALE@");
|
||||||
|
await sleep(400);
|
||||||
|
return {title, field, front: front(), tally: tally(), aim: aim(@X@, @Y@)};
|
||||||
|
})()"""
|
||||||
|
REFUSED = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
const toast = await toastSince(new Set(), "Accept: refused");
|
||||||
|
const stayed = front();
|
||||||
|
key("ArrowUp");
|
||||||
|
await turned("@COMMIT@");
|
||||||
|
await sleep(400);
|
||||||
|
return {toast: Boolean(toast), stayed, front: front(), tally: tally(), aim: aim(@X@, @Y@)};
|
||||||
|
})()"""
|
||||||
|
ACCEPT = """(async () => {@HELPERS@@CARD@@SIDE@
|
||||||
|
await until(() => tally() === "2", 4000);
|
||||||
|
const counted = tally();
|
||||||
|
document.querySelector("#main .match-open-overview").click();
|
||||||
|
await until(() => document.querySelector("#main .match-overview"), 4000);
|
||||||
|
await sleep(300);
|
||||||
|
const decisions = all("#main .match-decision").map((row) => [row.dataset.card, row.dataset.verdict]).sort();
|
||||||
|
return {tally: counted, decisions, wide: document.documentElement.scrollWidth > innerWidth + 1};
|
||||||
|
})()"""
|
||||||
|
|
||||||
|
|
||||||
|
def probe(template: str, **values: object) -> str:
|
||||||
|
found = template.replace("@HELPERS@", base.HELPERS).replace("@CARD@", matched.CARD).replace("@SIDE@", SIDE)
|
||||||
|
for name, value in values.items():
|
||||||
|
found = found.replace(f"@{name}@", str(value))
|
||||||
|
return found
|
||||||
|
|
||||||
|
|
||||||
|
def sideways(point: dict, width: int, sign: int) -> list[list[int]]:
|
||||||
|
"""Args:
|
||||||
|
point: a measured {x, y, width} of a front card's name.
|
||||||
|
width: the viewport width the drag stays inside.
|
||||||
|
sign: 1 drags to the right, -1 to the left.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
The drag from the name REACH card widths sideways, kept 2 px inside the viewport.
|
||||||
|
"""
|
||||||
|
end = min(max(point["x"] + sign * round(REACH * point["width"]), 2), width - 2)
|
||||||
|
return [[point["x"], point["y"]], [end, point["y"]]]
|
||||||
|
|
||||||
|
|
||||||
|
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
|
||||||
|
class TestMatchSwipe(HubCase):
|
||||||
|
drive = base.OrchestratorE2ECase.drive
|
||||||
|
cards = matched.TestMatchReview.cards
|
||||||
|
review = matched.TestMatchReview.review
|
||||||
|
payload = matched.TestMatchReview.payload
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.cards()
|
||||||
|
|
||||||
|
def ids(self) -> dict[str, str]:
|
||||||
|
return {"COMMIT": f"review:{self.commit}", "COMMAND": "operator:operator/issue", "STALE": f"review:{self.stale}"}
|
||||||
|
|
||||||
|
def measured(self, driver: str, binary: str) -> dict[int, list[dict]]:
|
||||||
|
steps = [{"width": width, "height": height, "url": f"{self.base}?{width}-measure#tasks/match", "wait": 1500, "probe": probe(MEASURE, **self.ids()), "shot": None} for width, height in base.WIDTHS]
|
||||||
|
data = self.drive(steps, None, driver, binary)
|
||||||
|
found = {}
|
||||||
|
for result, (width, _) in zip(data["results"], base.WIDTHS, strict=True):
|
||||||
|
self.assertNotIn("error", result, result)
|
||||||
|
self.assertEqual([point["front"] for point in result["points"]], [self.ids()[name] for name in ("COMMIT", "COMMAND", "STALE", "COMMIT")], result)
|
||||||
|
self.assertEqual(result["tally"], "1", result)
|
||||||
|
found[width] = result["points"]
|
||||||
|
return found
|
||||||
|
|
||||||
|
def steps(self, browser: str, points: dict[int, list[dict]]) -> list[dict]:
|
||||||
|
OUT.mkdir(parents=True, exist_ok=True)
|
||||||
|
steps = []
|
||||||
|
for width, height in base.WIDTHS:
|
||||||
|
commit, command, stale, again = points[width]
|
||||||
|
self.assertGreaterEqual(commit["y"] - max(commit["y"] - LIFT, 2), 90, commit)
|
||||||
|
shot = str(OUT / f"{browser}-{width}")
|
||||||
|
at = {"width": width, "height": height}
|
||||||
|
steps += [
|
||||||
|
{**at, "url": f"{self.base}?{width}-swipe#tasks/match", "wait": 1500, "probe": probe(START, X=commit["x"], Y=commit["y"], **self.ids()), "shot": None},
|
||||||
|
{**at, "url": None, "wait": 0, "drag": [[commit["x"], commit["y"]], [commit["x"], max(commit["y"] - LIFT, 2)]], "probe": probe(LATER, X=command["x"], Y=command["y"], **self.ids()), "shot": None},
|
||||||
|
{**at, "url": None, "wait": 0, "drag": sideways(command, width, -1), "probe": probe(REJECT, X=stale["x"], Y=stale["y"], **self.ids()), "shot": None},
|
||||||
|
{**at, "url": None, "wait": 0, "drag": sideways(stale, width, 1), "probe": probe(REFUSED, X=again["x"], Y=again["y"], **self.ids()), "shot": None},
|
||||||
|
{**at, "url": None, "wait": 0, "drag": sideways(again, width, 1), "probe": probe(ACCEPT), "shot": f"{shot}-swiped-decisions.png"},
|
||||||
|
]
|
||||||
|
return steps
|
||||||
|
|
||||||
|
def check(self, data: dict) -> None:
|
||||||
|
self.assertEqual([error for error in data["errors"] if "/favicon.ico" not in error], [])
|
||||||
|
ids = self.ids()
|
||||||
|
results = iter(data["results"])
|
||||||
|
for width, _ in base.WIDTHS:
|
||||||
|
start, later, reject, refused, accept = (next(results) for _ in range(5))
|
||||||
|
with self.subTest(width=width):
|
||||||
|
self.assertNotIn("error", start, start)
|
||||||
|
self.assertEqual(start, {"front": ids["COMMIT"], "aim": True, "tally": "0"})
|
||||||
|
self.assertEqual(later, {"front": ids["COMMAND"], "tally": "0", "aim": True})
|
||||||
|
self.assertTrue(reject["title"] and reject["title"].startswith("Reject: "), reject)
|
||||||
|
self.assertEqual({key: reject[key] for key in ("field", "front", "tally", "aim")}, {"field": True, "front": ids["STALE"], "tally": "1", "aim": True}, reject)
|
||||||
|
self.assertEqual(refused, {"toast": True, "stayed": ids["STALE"], "front": ids["COMMIT"], "tally": "1", "aim": True})
|
||||||
|
self.assertEqual(accept, {"tally": "2", "decisions": sorted([[ids["COMMIT"], "accept"], [ids["COMMAND"], "reject"]]), "wide": False})
|
||||||
|
|
||||||
|
def test_chromium_real_mouse_swipes_send_later_reject_refuse_stale_and_accept_at_three_widths(self):
|
||||||
|
binary = os.environ.get("CHROMIUM", "chromium")
|
||||||
|
data = self.drive(self.steps("chromium", self.measured("cdp.mjs", binary)), None)
|
||||||
|
(OUT / "chromium-match-swipe.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||||
|
self.check(data)
|
||||||
|
|
||||||
|
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
|
||||||
|
def test_firefox_real_mouse_swipes_send_later_reject_refuse_stale_and_accept_at_three_widths(self):
|
||||||
|
binary = os.environ.get("FIREFOX", "firefox")
|
||||||
|
data = self.drive(self.steps("firefox", self.measured("bidi.mjs", binary)), None, "bidi.mjs", binary)
|
||||||
|
(OUT / "firefox-match-swipe.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||||
|
self.check(data)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
+23
-1
@@ -13,7 +13,7 @@ from unittest import mock
|
|||||||
|
|
||||||
from hub_case import HubCase
|
from hub_case import HubCase
|
||||||
from hub_support import APPROVAL, GIT_ENV, HUB, REPO_ROOT, key, signing
|
from hub_support import APPROVAL, GIT_ENV, HUB, REPO_ROOT, key, signing
|
||||||
from kvb_orchestrator import batches, payloads, skill_scripts
|
from kvb_orchestrator import batches, payloads, scores, skill_scripts
|
||||||
|
|
||||||
MATCH = REPO_ROOT / "skills" / "kvb-match" / "scripts" / "match.py"
|
MATCH = REPO_ROOT / "skills" / "kvb-match" / "scripts" / "match.py"
|
||||||
CLIENT = HUB / "client"
|
CLIENT = HUB / "client"
|
||||||
@@ -167,6 +167,11 @@ class TestMatchRelease(MatchCase):
|
|||||||
argv = ["verify", "--port", str(self.port), "--approvers", str(self.approvers), "--replay", str(self.replay / "commit.json"), "--review", review, "--gate", "pass"]
|
argv = ["verify", "--port", str(self.port), "--approvers", str(self.approvers), "--replay", str(self.replay / "commit.json"), "--review", review, "--gate", "pass"]
|
||||||
return subprocess.run([sys.executable, str(APPROVAL), *argv], cwd=repo, env={**os.environ, **GIT_ENV}, capture_output=True, text=True, timeout=60, check=False)
|
return subprocess.run([sys.executable, str(APPROVAL), *argv], cwd=repo, env={**os.environ, **GIT_ENV}, capture_output=True, text=True, timeout=60, check=False)
|
||||||
|
|
||||||
|
def test_a_commit_card_lists_its_score_line_as_metric_chips_and_a_command_card_none(self):
|
||||||
|
_, review = self.stack()
|
||||||
|
chips = {card["ref"]: [(metric["id"], metric["value"]) for metric in card["metrics"]] for card in self.cards()}
|
||||||
|
self.assertEqual(chips, {review: [("fix", "95"), ("break", "3")], "operator/ship": []})
|
||||||
|
|
||||||
def test_every_card_names_the_addressee_its_inbox_entry_shows(self):
|
def test_every_card_names_the_addressee_its_inbox_entry_shows(self):
|
||||||
_, review = self.stack()
|
_, review = self.stack()
|
||||||
shown = {item["id"]: item["to"] for item in self.snapshot()["inbox"]}
|
shown = {item["id"]: item["to"] for item in self.snapshot()["inbox"]}
|
||||||
@@ -345,5 +350,22 @@ class TestPayloadHash(unittest.TestCase):
|
|||||||
self.assertEqual(named, ["/tmp/x/body.md", "/repo/list.txt", "/repo/scripts/run.sh", "/repo/quoted file.md"])
|
self.assertEqual(named, ["/tmp/x/body.md", "/repo/list.txt", "/repo/scripts/run.sh", "/repo/quoted file.md"])
|
||||||
|
|
||||||
|
|
||||||
|
class TestMetricChips(unittest.TestCase):
|
||||||
|
def test_score_lines_of_every_shape_give_one_chip_per_metric_in_label_order(self):
|
||||||
|
labels = scores.score_labels(REPO_ROOT / "skills")
|
||||||
|
line = scores.metric_chips("🎯 fix 94 % · 💥 break 4 % · 💸 tokens 100 % · ⏱️ velocity 100 % · 🛡️ security 100 % · 🏆 score 90", labels)
|
||||||
|
self.assertEqual([(chip["id"], chip["emoji"], chip["label"], chip["value"]) for chip in line], [
|
||||||
|
("fix", "🎯", "Fix", "94 %"), ("break", "💥", "Break", "4 %"), ("tokens", "💸", "Tokens", "100 %"),
|
||||||
|
("velocity", "⏱️", "Velocity", "100 %"), ("security", "🛡️", "Security", "100 %"), ("score", "🏆", "Score", "90"),
|
||||||
|
])
|
||||||
|
block = scores.metric_chips("🎯 Fix: 85 %\n💥 Break: 5 %\n⏱ Speed: new\n🏆 Score: 81\n🚦 Gate: ⛔ fix 85 % < 90", labels)
|
||||||
|
self.assertEqual([(chip["id"], chip["value"]) for chip in block], [("fix", "85 %"), ("break", "5 %"), ("velocity", "new"), ("score", "81")])
|
||||||
|
self.assertEqual([(chip["id"], chip["value"]) for chip in scores.metric_chips("Fix 92% Break 2.5%", labels)], [("fix", "92%"), ("break", "2.5%")])
|
||||||
|
for text in ("", "looks good", "🎯 high", "prefix 90 %"):
|
||||||
|
with self.subTest(text=text):
|
||||||
|
self.assertEqual(scores.metric_chips(text, labels), [])
|
||||||
|
self.assertEqual(scores.metric_chips("🎯 95 💥 3", None), [])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
Reference in new issue
Block a user