feat(orchestrator): hub requirements 066 to 082 and 084

Radio footer, rules page, schedules editor (System timers and Claude
tasks through signed runner jobs), account usage bar, usage explorer
with a streamed usage.jsonl, queue Controls tab and override, running
tasks on the board, stale task prune with the generic dial, greyed card
stamps, commit-tree diffs from the runner preview, VS Code path links,
expired asks and decisions that stay as EXPIRED cards (asks keyed by a
call digest; an async PostToolUse hook closes those answered in the
terminal), the Match refresh hourglass, attachments by paste, drop and
paperclip in every text field (page CSP gains img-src blob: for the
thumbnails) and the limits board with profiles and a passkey to loosen.
Fixes: one red accept on a red-gate commit and no release while a risk
is open, the send bar footer segments share one height, the mic button
survives a redraw, new Match cards queue before the release card.

E2E specs were still running at commit time (operator order); their
failures follow as separate fixes.

🎯 Fix: 88 %
💥 Break: 8 %
💸 Tokens: –
⏱️ Velocity: –
🛡️ Security: 100 %
🏆 Score: 81
🚦 Gate: ⛔ fix 88 % < 90, break 8 % > 5 (committed on the operator's word)

Created-with: https://s.veen.world/skills
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kevin Veen-BirkenbachandClaude Opus 5.5 committed 2026-11-27 19:05:38 +00:00
1 parent dc0d578eca
commit f356083a24
149 files changed
+10646 -963

No files matched your search

+172 -1
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import copy
import datetime
import importlib.util
import json
import os
@@ -11,10 +12,11 @@ import tempfile
import time
import unittest
from pathlib import Path
from unittest import mock
import hub_support
from hub_case import HubCase
from kvb_orchestrator import accounts
from kvb_orchestrator import accounts, calibration, settings
from kvb_orchestrator.errors import ToolError
from kvb_orchestrator.viewstore import VIEW, upgraded, valid_view
@@ -23,6 +25,7 @@ REPO = hub_support.REPO_ROOT
HOOK = REPO / "skills" / "kvb-org-organize" / "scripts" / "account.py"
SAMPLER = HUB / "client" / "resources.py"
MODULE = HUB / "templates" / "resources.js"
BAR = HUB / "templates" / "usagebar.js"
ACCOUNT = {
"provider": "Anthropic", "email": "one@example.org", "renewal": {"day": 1, "time": "09:00"}, "reset": {"day": 4, "time": "18:30"},
"resubscribe": "2026-12-01", "autorenew": True, "limit": 1000, "note": "team seat",
@@ -43,6 +46,46 @@ console.log(JSON.stringify({
}));
"""
COLOURS = r"""
const U = require(process.argv[1]);
const HOUR = 3600;
const LAST = Date.UTC(2026, 10, 23, 8, 0) / 1000;
const AT = LAST + 2 * HOUR;
const NOW = Date.UTC(2026, 10, 25, 12, 0);
const DAY = 86400000;
const entry = {total: 150, hours: [[LAST + HOUR, 100], [AT + HOUR, 50]]};
const recent = {total: 240, hours: [[NOW / 1000 - HOUR, 240]]};
console.log(JSON.stringify({
stops: [0, 50, 75, 100].map(U.fillColor),
named: ["green", "yellow", "orange", "red"].map((name) => U.css(U.COLORS[name])),
colors: U.COLORS,
sixty: U.fillStop(60),
hues: Array.from({length: 1001}, (_, tenth) => U.fillStop(tenth / 10)[2]),
ends: [U.fillColor(-5), U.fillColor(140)],
calibrated: U.usage(1000, entry, {share: 40, at: AT}, LAST * 1000),
stale: U.usage(1000, entry, {share: 40, at: LAST - 60}, LAST * 1000),
plain: U.usage(1000, entry, undefined, LAST * 1000),
empty: U.usage(0, {total: 0, hours: []}, undefined, LAST * 1000),
full: U.forecast(1000, recent, 40, NOW, NOW + 5 * DAY),
late: U.forecast(1000, recent, 40, NOW, NOW + 2 * DAY),
idle: U.forecast(1000, {total: 0, hours: []}, 40, NOW, NOW + 2 * DAY),
over: U.forecast(1000, {total: 0, hours: []}, 100, NOW, NOW + 2 * DAY),
now: NOW, day: DAY,
}));
"""
def epoch(text: str) -> float:
return datetime.datetime.fromisoformat(text).timestamp()
def in_berlin(case: unittest.TestCase) -> None:
zone = mock.patch.dict(os.environ, {"TZ": "Europe/Berlin"})
zone.start()
case.addCleanup(time.tzset)
case.addCleanup(zone.stop)
time.tzset()
def load(path: Path, name: str):
spec = importlib.util.spec_from_file_location(name, path)
@@ -94,6 +137,88 @@ class TestResetMath(unittest.TestCase):
self.assertEqual(found["unassigned"], {"since": None, "today": 300, "total": 900})
class TestUsageBar(unittest.TestCase):
@classmethod
def setUpClass(cls):
done = subprocess.run(["node", "-e", COLOURS, str(BAR)], capture_output=True, text=True, timeout=60, check=False)
if done.returncode != 0:
raise AssertionError(done.stderr[-2000:])
cls.found = json.loads(done.stdout)
def test_the_fill_is_green_yellow_orange_and_red_at_the_stops_and_flows_between_them_without_steps(self):
found = self.found
self.assertEqual(found["stops"], found["named"])
hues = {name: found["colors"][name][2] for name in ("green", "yellow", "orange", "red")}
for name, (low, high) in {"green": (120, 160), "yellow": (85, 105), "orange": (45, 70), "red": (15, 35)}.items():
with self.subTest(colour=name):
self.assertTrue(low <= hues[name] <= high, hues[name])
self.assertTrue(hues["orange"] < found["sixty"][2] < hues["yellow"], found["sixty"])
steps = [before - after for before, after in zip(found["hues"], found["hues"][1:], strict=False)]
self.assertTrue(all(0 <= step < 0.5 for step in steps), max(steps))
self.assertEqual(found["ends"], [found["named"][0], found["named"][3]])
def test_the_share_is_the_calibration_plus_the_tokens_since_it_and_a_calibration_older_than_the_reset_counts_nothing(self):
found = self.found
self.assertEqual(found["calibrated"], {"share": 45, "used": 450, "calibrated": True})
self.assertEqual(found["stale"], {"share": 15, "used": 150, "calibrated": False})
self.assertEqual(found["plain"], found["stale"])
self.assertEqual(found["empty"], {"share": 0, "used": 0, "calibrated": False})
def test_the_forecast_extends_the_rate_of_the_last_24_hours_to_the_reset_and_names_when_it_reaches_100(self):
found = self.found
now, day = found["now"], found["day"]
self.assertAlmostEqual(found["full"]["share"], 160)
self.assertAlmostEqual(found["full"]["full"], now + 2.5 * day, delta=1)
self.assertAlmostEqual(found["late"]["share"], 88)
self.assertIsNone(found["late"]["full"])
self.assertEqual(found["idle"], {"share": 40, "full": None})
self.assertEqual(found["over"], {"share": 100, "full": now})
class TestCalibration(unittest.TestCase):
def setUp(self):
folder = tempfile.TemporaryDirectory()
self.addCleanup(folder.cleanup)
self.file = Path(folder.name) / calibration.CALIBRATION
def test_a_share_from_0_to_100_passes_and_anything_else_is_refused(self):
for share in (0, 40.5, 100):
with self.subTest(share=share):
self.assertEqual(calibration.valid_share(json.dumps({"share": share}).encode()), float(share))
for body in ({"share": -0.1}, {"share": 100.1}, {"share": True}, {"share": "40"}, {"share": None}, {}, {"share": 40, "at": 1}, [40]):
with self.subTest(body=body), self.assertRaises(ToolError):
calibration.valid_share(json.dumps(body).encode())
with self.assertRaises(ToolError):
calibration.valid_share(b"not json")
def test_the_last_reset_keeps_its_wall_clock_across_the_october_dst_change_as_the_page_counts_it(self):
in_berlin(self)
reset = {"day": 0, "time": "03:30"}
self.assertEqual(calibration.last_reset(reset, epoch("2026-10-25T01:00:00+00:00")), epoch("2026-10-18T01:30:00+00:00"))
self.assertEqual(calibration.last_reset(reset, epoch("2026-10-25T04:00:00+00:00")), epoch("2026-10-25T02:30:00+00:00"))
self.assertEqual(calibration.last_reset(reset, epoch("2026-10-25T02:30:00+00:00")), epoch("2026-10-25T02:30:00+00:00"))
def test_a_calibration_holds_until_the_account_resets_or_goes_and_the_file_stays_0600(self):
in_berlin(self)
now = epoch("2026-11-25T10:00:00+00:00")
soon = datetime.datetime.fromtimestamp(now + 3600)
listed = [{"id": "a" * 16, "reset": {"day": soon.isoweekday() % 7, "time": soon.strftime("%H:%M")}}]
store = calibration.Calibrations(self.file)
self.assertEqual(store.put("a" * 16, 40.0, now + 0.7), {"share": 40.0, "at": int(now)})
store.put("b" * 16, 10.0, now)
self.assertEqual(stat.S_IMODE(self.file.stat().st_mode), 0o600)
self.assertEqual(store.current(listed, now + 60), {"a" * 16: {"share": 40.0, "at": int(now)}})
self.assertEqual(json.loads(self.file.read_text(encoding="utf-8")), {"a" * 16: {"share": 40.0, "at": int(now)}})
self.assertEqual(calibration.Calibrations(self.file).current(listed, now + 60), {"a" * 16: {"share": 40.0, "at": int(now)}})
self.assertEqual(store.current(listed, now + 7200), {})
self.assertEqual(json.loads(self.file.read_text(encoding="utf-8")), {})
self.assertEqual(stat.S_IMODE(self.file.stat().st_mode), 0o600)
def test_malformed_stored_entries_are_ignored_on_load(self):
self.file.write_text(json.dumps({"a" * 16: {"share": 140, "at": 1}, "b" * 16: {"share": 5, "at": "x"}, "c" * 16: {"share": 5, "at": 1, "x": 1}, "d" * 16: {"share": 5, "at": 9}}), encoding="utf-8")
self.assertEqual(calibration.Calibrations(self.file).items, {"d" * 16: {"share": 5, "at": 9}})
class TestHook(unittest.TestCase):
def setUp(self):
folder = tempfile.TemporaryDirectory()
@@ -209,6 +334,52 @@ class TestAccountsApi(HubCase):
self.assertEqual(view["active"], "one@example.org")
self.assertEqual(view["usage"], {"one@example.org": {"total": 42, "hours": [[hour, 42]]}, "": {"total": 3, "hours": [[hour, 3]]}})
def test_the_calibrate_route_stores_share_and_time_0600_refuses_bad_input_and_guards_like_the_other_account_routes(self):
added = json.loads(self.post("/api/accounts", {"id": "", "account": ACCOUNT})[1])
route = f"/api/accounts/{added['id']}/calibrate"
before = int(time.time())
status, body = self.post(route, {"share": 40})
self.assertEqual(status, 200, body)
stored = json.loads(body)
self.assertEqual(stored["share"], 40.0)
self.assertTrue(before <= stored["at"] <= time.time())
file = self.state / calibration.CALIBRATION
self.assertEqual(stat.S_IMODE(file.stat().st_mode), 0o600)
self.assertEqual(json.loads(self.get("/api/accounts")[2])["calibrations"], {added["id"]: stored})
for payload in ({"share": 100.5}, {"share": -1}, {"share": "40"}, {}, {"share": 40, "extra": 1}):
with self.subTest(payload=payload):
self.assertEqual(self.post(route, payload)[0], 400)
self.assertEqual(self.post(f"/api/accounts/{'0' * 16}/calibrate", {"share": 40})[0], 404)
self.assertEqual(self.post("/api/accounts/zz/calibrate", {"share": 40})[0], 404)
self.assertEqual(self.post_json(route, {"share": 50}, {"Host": self.host, "X-Kvb-Orchestrator": "1"})[0], 403)
self.assertEqual(self.post_json(route, {"share": 50}, {**self.guard(self.host), "Origin": "http://evil.example"})[0], 403)
self.assertEqual(self.get(route)[0], 405)
self.assertEqual(json.loads(self.get("/api/accounts")[2])["calibrations"], {added["id"]: stored})
def test_the_payload_drops_a_calibration_older_than_the_last_reset_and_one_of_a_removed_account(self):
added = json.loads(self.post("/api/accounts", {"id": "", "account": ACCOUNT})[1])
other = json.loads(self.post("/api/accounts", {"id": "", "account": {**ACCOUNT, "email": "two@example.org"}})[1])
hub = self.httpd.hub.accounts
hub.calibrations.put(added["id"], 30.0, time.time() - 8 * 86400)
self.assertEqual(self.post(f"/api/accounts/{other['id']}/calibrate", {"share": 12.5})[0], 200)
calibrations = json.loads(self.get("/api/accounts")[2])["calibrations"]
self.assertEqual(list(calibrations), [other["id"]])
self.assertEqual(list(json.loads((self.state / calibration.CALIBRATION).read_text(encoding="utf-8"))), [other["id"]])
self.assertEqual(self.post(f"/api/accounts/{other['id']}/delete", {})[0], 200)
self.assertEqual(json.loads(self.get("/api/accounts")[2])["calibrations"], {})
def test_the_forecast_toggle_is_a_hub_setting_that_needs_no_passkey_and_survives_a_page_that_omits_it(self):
guard = self.guard(self.host)
status, _, body = self.post_json("/api/settings", {**settings.SETTINGS, "forecast": True}, guard)
self.assertEqual(status, 200, body)
self.assertTrue(json.loads(body)["settings"]["forecast"])
older = {key: value for key, value in settings.SETTINGS.items() if key != "forecast"}
status, _, body = self.post_json("/api/settings", older, guard)
self.assertEqual(status, 200, body)
self.assertTrue(json.loads(body)["settings"]["forecast"])
self.assertEqual(self.post_json("/api/settings", {**settings.SETTINGS, "forecast": "yes"}, guard)[0], 400)
self.assertTrue(json.loads((self.state / "settings.json").read_text(encoding="utf-8"))["forecast"])
if __name__ == "__main__":
unittest.main()