From 78d4e4a6aa590a400bfd9cbaaf4486ed61741c15 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 17 Nov 2026 19:02:17 +0000 Subject: [PATCH] feat(orchestrator): Match cards show the score line as metric chips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- orchestrator/kvb_orchestrator/matching.py | 11 +- orchestrator/kvb_orchestrator/scores.py | 31 +++- orchestrator/templates/page-match.js | 5 +- orchestrator/templates/style-match.css | 3 + tests/e2e/test_match_release_e2e.py | 42 ++++- tests/e2e/test_match_review_e2e.py | 6 + tests/e2e/test_match_swipe_e2e.py | 196 ++++++++++++++++++++++ tests/test_hub_match.py | 24 ++- 8 files changed, 302 insertions(+), 16 deletions(-) create mode 100644 tests/e2e/test_match_swipe_e2e.py diff --git a/orchestrator/kvb_orchestrator/matching.py b/orchestrator/kvb_orchestrator/matching.py index e22c61b..e619eca 100644 --- a/orchestrator/kvb_orchestrator/matching.py +++ b/orchestrator/kvb_orchestrator/matching.py @@ -10,6 +10,7 @@ from .fields import decode, expect, field from .payloads import denied_roots, payload_files, payload_hash from .records import digest, iso_epoch from .register import REGISTER, adder, operator_rows, read_register +from .scores import metric_chips, score_labels from .signed import signing from .tree import inside @@ -46,7 +47,8 @@ class Matching: claims = read_claims(self.council) names = self.names.listed() 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) held = self.open_jobs() 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"]) 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"])] 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 "" @@ -72,7 +74,8 @@ class Matching: place = {"repo": repository_of(review.get("repo", "")), "branch": review["branch"], "worktree": review["worktree"]} return { "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": "", } @@ -88,7 +91,7 @@ class Matching: repo, branch, worktree = place_of(row["directory"], scan) return { "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"], "reason": row["why"], "sha256": digest(row["command"]), } diff --git a/orchestrator/kvb_orchestrator/scores.py b/orchestrator/kvb_orchestrator/scores.py index 5e3b768..25b7457 100644 --- a/orchestrator/kvb_orchestrator/scores.py +++ b/orchestrator/kvb_orchestrator/scores.py @@ -1,5 +1,6 @@ from __future__ import annotations +import re from pathlib import Path 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" LABELS = "kvb-check-score/labels.json" FILE_LIMIT = 64 << 20 +VARIATION = "๏ธ" +VALUE = r"([0-9]+(?:\.[0-9]+)?(?:\s*%)?|โ€“|-|new)(?![0-9.])" def checked(labels: object) -> dict | None: @@ -51,4 +54,30 @@ def scored(council: Path, skills: Path, span: tuple[float, float]) -> dict: """ begin, end = span 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 diff --git a/orchestrator/templates/page-match.js b/orchestrator/templates/page-match.js index 4e1ec7a..3914ec0 100644 --- a/orchestrator/templates/page-match.js +++ b/orchestrator/templates/page-match.js @@ -202,10 +202,13 @@ function matchHead(card) { const [kindName, kindTone, kindIcon] = MATCH_KINDS[card.kind] || [card.kind, "neutral", "bi-collection"]; + const metrics = card.metrics || []; 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))), + 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, - 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("h2", {class: "match-title"}, revealed(card.title)), card.stale ? h("p", {class: "match-stale"}, icon("bi-exclamation-triangle"), revealed(card.stale_reason)) : null); diff --git a/orchestrator/templates/style-match.css b/orchestrator/templates/style-match.css index 6f434e1..9f4bcfb 100644 --- a/orchestrator/templates/style-match.css +++ b/orchestrator/templates/style-match.css @@ -13,6 +13,9 @@ .match-who .avatar.big { width: 72px; height: 72px; } .match-name { font-size: var(--fs-lg); } .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 code { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .match-title { margin: 0; font-size: var(--fs-md); overflow-wrap: anywhere; } diff --git a/tests/e2e/test_match_release_e2e.py b/tests/e2e/test_match_release_e2e.py index 280de58..d829626 100644 --- a/tests/e2e/test_match_release_e2e.py +++ b/tests/e2e/test_match_release_e2e.py @@ -26,12 +26,22 @@ FLOW = """(async () => {@HELPERS@ navigator.credentials.get = () => Promise.reject(new DOMException("The operator canceled.", "NotAllowedError")); } const posted = []; + const statuses = []; + let tamper = @SIGNS@ && @RELEASE@; const send = window.fetch.bind(window); - window.fetch = (path, init) => { - 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])]); + window.fetch = async (path, init) => { + if (!["/api/sign", "/api/inbox/approve"].includes(String(path))) { + 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 front = () => (card() ? card().dataset.card : null); @@ -82,11 +92,19 @@ FLOW = """(async () => {@HELPERS@ 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}; if (@RELEASE@) { - const shown = new Set(all("#toasts .toast")); - release.click(); - found.toast = await until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((entry) => entry.startsWith("Release")), 15000); + const toastAfter = async (click) => { + const shown = new Set(all("#toasts .toast")); + 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.posted = posted; + found.statuses = statuses; } return found; })()""" @@ -173,11 +191,17 @@ class TestMatchRelease(HubCase): 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) + 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.assertNotIn("not possible", released["toast"], released) self.assertTrue(released["emptied"], released) posted = [path for path, _ in released["posted"]] - self.assertEqual(posted, ["/api/sign", "/api/inbox/approve"]) - items = sorted(released["posted"][1][1]) + self.assertEqual(posted, ["/api/sign", "/api/inbox/approve"] * 2) + 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" 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) diff --git a/tests/e2e/test_match_review_e2e.py b/tests/e2e/test_match_review_e2e.py index e4457f9..558567a 100644 --- a/tests/e2e/test_match_review_e2e.py +++ b/tests/e2e/test_match_review_e2e.py @@ -32,6 +32,8 @@ CARD = """ 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")), + 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])]), 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), @@ -115,6 +117,9 @@ class TestMatchReview(HubCase): def setUp(self): super().setUp() + self.cards() + + def cards(self) -> None: work = tempfile.TemporaryDirectory() self.addCleanup(work.cleanup) self.work = Path(work.name) @@ -171,6 +176,7 @@ class TestMatchReview(HubCase): 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["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["files"], order) self.assertEqual(stack["peeks"], ["operator:operator/issue", f"review:{self.stale}"], stack) diff --git a/tests/e2e/test_match_swipe_e2e.py b/tests/e2e/test_match_swipe_e2e.py new file mode 100644 index 0000000..c499388 --- /dev/null +++ b/tests/e2e/test_match_swipe_e2e.py @@ -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() diff --git a/tests/test_hub_match.py b/tests/test_hub_match.py index 53b0bda..8a59c8e 100644 --- a/tests/test_hub_match.py +++ b/tests/test_hub_match.py @@ -13,7 +13,7 @@ from unittest import mock from hub_case import HubCase 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" 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"] 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): _, review = self.stack() 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"]) +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__": unittest.main()