Files
skills/tests/test_hub_match_release_last.py
T
Kevin Veen-BirkenbachandClaude Opus 5.5 b15dd5e414 fix(match): release card repairs, hotfix 092
An Ask accepted while pending expired before the release, and the hub
refused all 11 decisions with a raw 409. The release card now checks
every row first: an unreleasable row turns red with its reason, Release
names the rows on click, and a red Cancel drops them and their cards.
A hub refusal names the card's title and marks its row. The verdict pill
opens a menu (options, Accept, Reject, Back to the stack, impossible
entries greyed with their reason). Back to the stack puts the card
behind the release card, last in the deck. W no longer puts a skipped
card in front of the release card. An expired decision no longer claims
its tool call went back to the terminal.

🎯 Fix: 85 %
💥 Break: 8 %
💸 Tokens: -
⏱️ Velocity: -
🛡️ Security: 100 %
🏆 Score: 78
🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 (E2E rerun after 085 to 094, operator word 2026-11-27)

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 20:53:57 +00:00

102 lines
3.9 KiB
Python

from __future__ import annotations
import json
import re
import subprocess
import unittest
from hub_support import HUB
MATCH = HUB / "templates" / "page-match.js"
NAMES = ("toBack", "releaseLast", "matchOrder", "decisionOf")
PROBE = r"""
const vm = require("vm");
const sandbox = {RELEASE: "release", matchView: {order: [], decisions: new Map()}, out: {}};
vm.runInNewContext(process.argv[1], sandbox);
vm.runInNewContext(`
const card = (id, ts) => ({id, hash: id, created_ts: ts, stale: false, blocked: ""});
const ids = () => matchView.order.join(",");
matchView.order = ["a", "b", "release"];
matchView.decisions.set("a", {verdict: "accept", hash: "a"});
matchOrder([card("a", 1), card("b", 2), card("c", 3)]);
out.fresh = ids();
toBack("b");
out.later = ids();
matchView.order = ["release", "b", "c"];
matchOrder([card("a", 1), card("b", 2), card("c", 3), card("d", 4)]);
out.shown = ids();
toBack("release");
out.back = ids();
`, sandbox);
console.log(JSON.stringify(sandbox.out));
"""
def extracted() -> str:
source = MATCH.read_text(encoding="utf-8")
parts = []
for name in NAMES:
found = re.search(rf"^ (?:function {name}\(|const {name} = ).*?^ }};?$", source, re.MULTILINE | re.DOTALL)
if found is None:
raise AssertionError(f"{name} not found in {MATCH}")
parts.append(found.group(0).replace(f"const {name} = ", f"var {name} = "))
return "\n".join(parts)
STAMP_PROBE = r"""
const vm = require("vm");
const sandbox = {};
vm.runInNewContext(process.argv[1], sandbox);
console.log(JSON.stringify(vm.runInNewContext(`[
greyStamp({stale: false, blocked: ""}),
greyStamp({stale: false, blocked: "runs", blocked_kind: "running"}),
greyStamp({stale: false, blocked: "waits", blocked_kind: "queued"}),
greyStamp({stale: false, blocked: "no dir", blocked_kind: "unrunnable"}),
greyStamp({stale: true, blocked: "runs", blocked_kind: "running"}),
greyStamp({stale: false, blocked: "ask held"}),
greyStamp({stale: false, blocked: "too late", blocked_kind: "expired"}),
].map((key) => [key, key ? MATCH_STAMPS[key] : ""])`, sandbox)));
"""
def stamp_source() -> str:
source = MATCH.read_text(encoding="utf-8")
table = re.search(r"^ const MATCH_STAMPS = .*;$", source, re.MULTILINE)
function = re.search(r"^ function greyStamp\(.*?^ }$", source, re.MULTILINE | re.DOTALL)
if table is None or function is None:
raise AssertionError(f"MATCH_STAMPS or greyStamp not found in {MATCH}")
return table.group(0).replace("const ", "var ", 1) + "\n" + function.group(0)
class TestGreyedCardStamp(unittest.TestCase):
def test_every_greyed_card_names_its_reason_and_an_active_card_has_none(self):
done = subprocess.run(["node", "-e", STAMP_PROBE, stamp_source()], capture_output=True, text=True, timeout=60, check=True)
self.assertEqual(json.loads(done.stdout), [
["", ""], ["running", "RUNNING"], ["queued", "QUEUED"], ["blocked", "BLOCKED"], ["stale", "STALE"], ["blocked", "BLOCKED"], ["expired", "EXPIRED"],
])
class TestReleaseCardLast(unittest.TestCase):
@classmethod
def setUpClass(cls):
done = subprocess.run(["node", "-e", PROBE, extracted()], capture_output=True, text=True, timeout=60, check=False)
if done.returncode != 0:
raise AssertionError(done.stderr[-4000:])
cls.data = json.loads(done.stdout)
def test_a_new_card_queues_before_the_release_card(self):
self.assertEqual(self.data["fresh"], "a,b,c,release")
def test_later_puts_a_card_behind_the_release_card(self):
self.assertEqual(self.data["later"], "a,c,release,b")
def test_a_shown_release_card_stays_in_front_and_new_cards_queue_behind_it(self):
self.assertEqual(self.data["shown"], "release,b,c,a,d")
def test_sending_the_release_card_back_puts_it_last(self):
self.assertEqual(self.data["back"], "b,c,a,d,release")
if __name__ == "__main__":
unittest.main()