Merge branch 'feature/hub-bookmarks-everywhere' into unify/skills-20261114

# Conflicts:
#	orchestrator/templates/page-inbox.js
This commit is contained in:
Kevin Veen-Birkenbach committed 2026-11-14 21:56:35 +00:00
commit ccde693567
16 files changed
+1382 -104

No files matched your search

+485
View File
@@ -0,0 +1,485 @@
from __future__ import annotations
import json
import os
import shutil
import sys
import time
import unittest
from collections.abc import Callable
from pathlib import Path
from unittest import mock
HERE = Path(__file__).resolve().parent
sys.path[:0] = [str(HERE.parent), str(HERE)]
import test_home_dashboard_e2e as dash
import test_orchestrator_e2e as base
import test_resources_view_e2e as res
import test_workbench_w4_e2e as w4
from hub_case import HubCase
from hub_support import (
CORE_WORKTREE,
LONG_REPO,
LONG_TASK,
LONG_VOLUME,
LONG_WORKTREE,
iso,
long_repos,
long_task,
)
OUT = Path(os.environ.get("E2E_OUT", "/tmp/bookmarks-shots"))
CUE = "e2e-bookmarks-vanish"
GHOST = "Ghost"
KEPT = "feature/kept"
HARDWARE = ["disk:/", "disk:/boot/efi", res.CPU, "host:RAM", "host:Swap", res.UTIL, "vram:0000_3a_01_3a_00.0"]
WALKED = ["resources", "artifacts/tree", "agents/hierarchy", "tasks/operator"]
LONG_NAME = "/".join(Path(LONG_REPO).parts[-3:])
LONG_ROWS = ("repo", "worktree", "core", "leaf")
READ = res.READ.replace("const stored = async", "const storedResources = async").replace("await stored()", "await storedResources()")
KIT = """
const stars = (selector) => all(selector).map((owner) => Boolean(ownStar(owner)));
const panel = (kind) => `#main [data-panel="resources-${kind}"]`;
const lineIds = (root) => [...new Set(all("path.res-line", root).map((path) => path.dataset.id))];
const tileOf = (kind) => all("#main .home-tile").find((node) => node.dataset.pin.startsWith(`metric:${kind}/`)) || null;
const pinOf = (kind) => (ViewStore.get("home.pins") || []).find((pin) => pin.kind === "metric" && pin.id.startsWith(`${kind}/`)) || null;
const kept = () => all("#main .branch-row[data-item]").find((row) => row.dataset.item.endsWith("\\u0000@KEPT@")) || null;
const settled = () => until(() => !all("#main .home-tile .empty h2").some((title) => text(title).endsWith("…")), 8000);
const longRows = {
repo: () => all("#main details.repo[data-item]").find((node) => text(node.querySelector("summary")).includes("@LONG_NAME@")) || null,
worktree: () => all("#main .wt[data-item]").find((node) => text(node.querySelector(".wt-head > code")) === "@LONG_WORKTREE@") || null,
core: () => all("#main .wt[data-item]").find((node) => text(node.querySelector(".wt-head > code")) === "@CORE_WORKTREE@") || null,
leaf: () => all("#main li.leaf[data-item]").find((node) => text(node.querySelector("code")) === "@LONG_VOLUME@") || null,
};
const pinKey = (node) => `artifact:${Panels.token(node.dataset.item.slice(node.dataset.item.indexOf(":") + 1))}`;
const timeOverlaps = (root) => {
const boxes = all("text.axis", root).filter((node) => !["left", "right"].includes(node.dataset.axis)).map((node) => node.getBoundingClientRect());
return boxes.filter((box, index) => boxes.slice(index + 1).some((other) => Math.min(box.right, other.right) - Math.max(box.left, other.left) > 0.5 && Math.min(box.bottom, other.bottom) - Math.max(box.top, other.top) > 0.5)).length;
};
"""
CLEAR = """(async () => {
sessionStorage.clear();
await Promise.all([ViewStore.update("home.pins", () => []), ViewStore.update("resources.hidden", () => []), ViewStore.update("resources.combinedHidden", () => []),
ViewStore.set("resources.combined", false), ViewStore.set("resources.tokens", "interval")]);
return true;
})()"""
LOADED = """(async () => {@HELPERS@@READ@
await screenShown(8000);
const drawn = Boolean(await until(() => charts().length === 2 && chip("@CPU@"), 15000));
return {drawn, charts: charts()};
})()"""
FOUND = """(async () => {@HELPERS@@HOME@@KIT@
const found = {};
await go("resources");
found.charts = stars('#main section.res-panel[data-panel^="resources-"]');
found.chips = all("#main .legend-chip .star").length;
found.inHead = all("#main .res-panel .star").every((star) => star.parentElement.classList.contains("res-head"));
await go("artifacts/tree");
await until(() => kept(), 8000);
found.tree = stars('#main [data-panel="artifacts/tree"]');
found.rows = Object.fromEntries(["repo", "branch", "wt"].map((kind) => [kind, stars(`#main [data-item^="artifact:${kind}:"]`)]));
await until(() => Object.values(longRows).every((find) => find()), 8000);
found.long = Object.fromEntries(Object.entries(longRows).map(([key, find]) => [key, find() ? find().dataset.item.length : null]));
found.disabled = all('#main [data-item^="artifact:"]').filter((node) => !ownStar(node) || ownStar(node).disabled).map((node) => node.dataset.item.slice(0, 80));
found.deletes = all('#main button[aria-label="Delete"]').length;
await go("agents/hierarchy");
found.order = stars('#main [data-panel="agents/order"]');
await go("tasks/operator");
found.operator = stars('#main [data-panel="tasks/operator"]');
return found;
})()"""
METRIC = """(async () => {@HELPERS@@HOME@@READ@@KIT@
await go("resources");
if (!(await until(() => charts().length === 2 && chip("@CPU@") && lines().length === @COUNT@, 15000))) {
return {error: text(document.getElementById("main")), charts: charts()};
}
const axisOverlaps = timeOverlaps(document.querySelector("#main .res-panels"));
const others = @HARDWARE@.filter((id) => id !== "@CPU@");
for (const id of others) {
chip(id).click();
await sleep(120);
}
const cpuOnly = Boolean(await until(() => lineIds(document.querySelector(panel("hardware"))).join() === "@CPU@", 5000));
const hardware = await press(panel("hardware"));
const cpuTitle = starOf(panel("hardware")).getAttribute("title");
const tokens = await press(panel("tokens"));
for (const id of others) {
chip(id).click();
await sleep(120);
}
const back = Boolean(await until(() => lineIds(document.querySelector(panel("hardware"))).length === @COUNT@, 5000));
await sleep(200);
const allState = [starOf(panel("hardware")).getAttribute("aria-pressed"), starOf(panel("hardware")).getAttribute("title")];
switched("combined").click();
const combinedOn = Boolean(await until(() => charts().join() === "combined" && burn().length === 2, 5000));
const combined = await press(panel("combined"));
return {cpuOnly, hardware, cpuTitle, tokens, back, allState, combinedOn, combined, axisOverlaps, stored: (ViewStore.get("home.pins") || []).map((pin) => [pin.kind, pin.id, pin.view || null])};
})()"""
COMBINED_OFF = """(async () => {@HELPERS@@HOME@@READ@@KIT@
await go("resources");
await until(() => charts().join() === "combined", 8000);
switched("combined").click();
const off = Boolean(await until(() => charts().length === 2 && lines().length === @COUNT@, 8000));
await sleep(300);
return {off, hardware: [starOf(panel("hardware")).getAttribute("aria-pressed"), starOf(panel("hardware")).getAttribute("title")]};
})()"""
HOME_METRICS = """(async () => {@HELPERS@@HOME@@KIT@
await go("home");
await until(() => ["hardware", "tokens", "combined"].every((kind) => tileOf(kind) && tileOf(kind).querySelector("svg.res-chart")), 15000);
await sleep(300);
const read = (kind) => {
const found = tileOf(kind);
return found ? {
title: text(found.querySelector(".home-title")), lines: lineIds(found), legend: all(".legend-chip", found).map((node) => node.dataset.series),
chart: (found.querySelector("svg.res-chart") || {dataset: {}}).dataset.chart || null, right: all('text[data-axis="right"]', found).length,
burn: all("path.res-burn", found).length, bars: [...new Set(all("rect.res-bar", found).map((rect) => rect.dataset.agent))].sort(),
gone: found.classList.contains("gone"),
} : null;
};
const overlaps = Object.fromEntries(["hardware", "tokens", "combined"].map((kind) => [kind, tileOf(kind) ? timeOverlaps(tileOf(kind)) : null]));
const sized = (kind, step) => ViewStore.update("home.pins", (pins) => pins.map((pin) => (pin.kind === "metric" && pin.id.startsWith(`${kind}/`) ? {...pin, h: pin.h + step} : pin)));
await sized("combined", -1);
await sleep(600);
const body = tileOf("combined").querySelector(".home-body");
const scroll = {scrollable: body.scrollHeight > body.clientHeight + 10};
if (scroll.scrollable) {
body.scrollTop = body.scrollHeight;
scroll.before = body.scrollTop;
await sized("hardware", 1);
await sleep(400);
await sized("hardware", -1);
await sleep(400);
scroll.after = body.scrollTop;
}
await sized("combined", 1);
await sleep(300);
return {tiles: tiles(), hardware: read("hardware"), tokens: read("tokens"), combined: read("combined"), errors: all("#main .home-error").map(text), stored: pinOf("hardware"), overlaps, scroll};
})()"""
PM = """(async () => {@HELPERS@@HOME@@KIT@
await go("artifacts/tree");
const row = await until(() => kept(), 8000);
row.closest("details").open = true;
const tree = await press('#main [data-panel="artifacts/tree"]');
const rowStar = row ? ownStar(row) : null;
if (rowStar) {
rowStar.click();
await sleep(200);
}
const branch = rowStar ? (ownStar(kept()) || rowStar).getAttribute("aria-pressed") : null;
await go("agents/hierarchy");
const order = await press('#main [data-panel="agents/order"]');
await go("tasks/operator");
const operator = await press('#main [data-panel="tasks/operator"]');
await go("agents/orbit");
const node = await until(() => all("#main svg .node[data-pick]").find((found) => (found.getAttribute("aria-label") || "").startsWith("@GHOST@,")), 8000);
let agent = null;
if (node) {
node.dispatchEvent(new MouseEvent("click", {bubbles: true}));
await until(() => document.querySelector('#popup[open] [data-item^="agent:"]'), 5000);
agent = await press('#popup[open] [data-item^="agent:"]');
document.getElementById("popup").close();
}
await go("home");
await settled();
await sleep(500);
const keys = stored();
const pick = (kind) => keys.find((key) => key.startsWith(`${kind}:`)) || null;
const shown = (key) => {
const found = key ? tile(key) : null;
return found ? {gone: found.classList.contains("gone"), title: text(found.querySelector(".home-title"))} : null;
};
return {
pressed: {tree, branch, order, operator, agent}, keys,
tree: [shown("panel:artifacts/tree"), all('#main .home-tile[data-pin="panel:artifacts/tree"] details.repo').length],
order: [shown("panel:agents/order"), all('#main .home-tile[data-pin="panel:agents/order"] .home-order li').map((item) => item.dataset.name)],
operator: [shown("panel:tasks/operator"), all('#main .home-tile[data-pin="panel:tasks/operator"] .home-inbox > li').length],
artifact: [shown(pick("artifact")), text(tile(pick("artifact")) && tile(pick("artifact")).querySelector(".home-body h2.panel-title"))],
agent: [shown(pick("agent")), Boolean(tile(pick("agent")) && tile(pick("agent")).querySelector(".home-agent"))],
errors: all("#main .home-error").map(text),
};
})()"""
LONG = """(async () => {@HELPERS@@HOME@@KIT@
await go("artifacts/tree");
await until(() => Object.values(longRows).every((find) => find()), 8000);
const pressed = {};
const keys = {};
for (const [key, find] of Object.entries(longRows)) {
const star = ownStar(find());
keys[key] = pinKey(find());
pressed[key] = star ? [star.disabled, star.title.startsWith("Pin to Home: Artifact ")] : null;
if (star && !star.disabled) {
star.click();
await sleep(200);
}
pressed[key].push(ownStar(longRows[key]()).getAttribute("aria-pressed"));
}
await go("home");
await settled();
await until(() => Object.values(keys).every((key) => tile(key) && tile(key).querySelector(".home-popup")), 8000);
await sleep(300);
const shown = Object.fromEntries(Object.entries(keys).map(([key, pin]) => {
const found = tile(pin);
return [key, found ? {gone: found.classList.contains("gone"), title: text(found.querySelector(".home-title")), label: text(found.querySelector(".home-body h2.panel-title")), body: text(found.querySelector(".home-body"))} : null];
}));
const treeTile = tile("panel:artifacts/tree");
const body = treeTile ? treeTile.querySelector(".home-body") : null;
const scroll = {deletes: treeTile ? all('button[aria-label="Delete"]', treeTile).length : null, scrollable: body ? body.scrollHeight > body.clientHeight + 40 : null};
if (scroll.scrollable) {
body.scrollTop = 40;
scroll.before = body.scrollTop;
const order = (step) => ViewStore.update("home.pins", (pins) => pins.map((pin) => (pin.kind === "panel" && pin.id === "agents/order" ? {...pin, h: pin.h + step} : pin)));
await order(1);
await sleep(400);
await order(-1);
await sleep(400);
scroll.after = body.isConnected ? body.scrollTop : null;
}
return {pressed, keys, stored: stored(), shown, scroll, errors: all("#main .home-error").map(text)};
})()"""
RELOADED = """(async () => {@HELPERS@@HOME@@KIT@
await screenShown(8000);
await until(() => tileOf("hardware") && tileOf("hardware").querySelector("svg.res-chart"), 15000);
await sleep(300);
return {hash: location.hash, lines: lineIds(tileOf("hardware")), title: text(tileOf("hardware").querySelector(".home-title")), stored: pinOf("hardware")};
})()"""
GONE = """(async () => {@HELPERS@@HOME@@KIT@
await go("home");
const keys = stored();
const agentKey = keys.find((key) => key.startsWith("agent:"));
const artifactKeys = keys.filter((key) => key.startsWith("artifact:"));
const before = [agentKey, ...artifactKeys].map((key) => tile(key).classList.contains("gone"));
await fetch("/api/tts", {method: "POST", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": "application/json"}, body: JSON.stringify({text: "@CUE@", voice: ""}), cache: "no-store"});
const started = Date.now();
const vanished = await until(() => [agentKey, ...artifactKeys].every((key) => tile(key).classList.contains("gone")), 50000);
const seconds = Math.round((Date.now() - started) / 1000);
const words = (key) => (tile(key) ? [text(tile(key).querySelector(".home-gone-word")), name(tile(key).querySelector(".home-gone-unpin"))] : null);
tile(artifactKeys[0]).scrollIntoView({block: "start"});
await sleep(300);
return {before, vanished: Boolean(vanished), seconds, agent: words(agentKey), artifacts: artifactKeys.map(words), agentKey, artifactKeys};
})()"""
UNPIN = """(async () => {@HELPERS@@HOME@@KIT@
await go("home");
const keys = stored();
const metric = keys.find((key) => key.startsWith("metric:hardware/"));
const artifacts = keys.filter((key) => key.startsWith("artifact:"));
tile(metric).querySelector(".home-unpin").click();
await sleep(300);
for (const key of artifacts) {
const gone = tile(key) ? tile(key).querySelector(".home-gone-unpin") : null;
if (gone) {
gone.click();
await sleep(300);
}
}
return {metric, artifacts, tiles: tiles(), stored: stored()};
})()"""
UNPIN_PLAIN = """(async () => {@HELPERS@@HOME@@KIT@
await go("home");
const metric = stored().find((key) => key.startsWith("metric:hardware/"));
tile(metric).querySelector(".home-unpin").click();
await sleep(300);
return {metric, artifacts: [], tiles: tiles(), stored: stored()};
})()"""
def probe(template: str, screens: list[str] | None = None) -> str:
names = {
"@HELPERS@": base.HELPERS, "@HOME@": dash.HOME, "@READ@": READ, "@KIT@": KIT, "@KEPT@": KEPT, "@GHOST@": GHOST, "@CUE@": CUE, "@CPU@": res.CPU,
"@HARDWARE@": json.dumps(HARDWARE), "@COUNT@": str(len(HARDWARE)), "@SCREENS@": json.dumps(screens or WALKED),
"@LONG_NAME@": LONG_NAME, "@LONG_WORKTREE@": LONG_WORKTREE, "@CORE_WORKTREE@": CORE_WORKTREE, "@LONG_VOLUME@": LONG_VOLUME,
}
for key, value in names.items():
template = template.replace(key, value)
return template
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
class TestHomeBookmarks(HubCase):
seed = base.TestOrchestratorE2E.seed
subagents = base.TestOrchestratorE2E.subagents
drive = base.TestOrchestratorE2E.drive
sample = w4.TestWorkbenchResources.sample
def setUp(self):
super().setUp()
OUT.mkdir(parents=True, exist_ok=True)
self.seed()
now = int(time.time())
self.start = now - now % 60 - w4.ROWS * 60
hour = self.start - self.start % 3600
tokens = [{"t": hour + step * 3600, "agent": "Skills", "model": "claude-opus-5-5", "input": 1000 * (step + 1), "output": 500, "cache_read": 20000, "cache_write": 1000} for step in range(7)]
tokens += [{"t": hour + step * 3600, "agent": "Stage", "model": "claude-haiku-4-5", "input": 200, "output": 100, "cache_read": 3000, "cache_write": 0} for step in range(0, 7, 2)]
folder = self.kept / "resources"
folder.mkdir()
(folder / "samples.jsonl").write_text(self.jsonl([self.sample(index) for index in range(w4.ROWS)]), encoding="utf-8")
(folder / "tokens.jsonl").write_text(self.jsonl([row for row in tokens if row["t"] <= now]), encoding="utf-8")
register = self.council / "rasci.json"
rows = json.loads(register.read_text(encoding="utf-8"))
rows["work/ghost"] = {"title": "Ghost line", "status": "running", "worker": GHOST, "start": iso(now - 1800), "roles": {GHOST: "RA"}}
rows[LONG_TASK] = long_task(now)
register.write_text(json.dumps(rows), encoding="utf-8")
scan = json.loads(self.tree_file.read_text(encoding="utf-8"))
scan["repos"] += long_repos()
self.tree_file.write_text(json.dumps(scan), encoding="utf-8")
def vanish(self) -> None:
register = self.council / "rasci.json"
rows = json.loads(register.read_text(encoding="utf-8"))
rows.pop("work/ghost", None)
rows.pop(LONG_TASK, None)
register.write_text(json.dumps(rows), encoding="utf-8")
scan = json.loads(self.tree_file.read_text(encoding="utf-8"))
long = {repo["path"] for repo in long_repos()}
scan["repos"] = [repo for repo in scan["repos"] if repo["path"] not in long]
for repo in scan["repos"]:
repo["items"] = [item for item in repo["items"] if item.get("branch") != KEPT]
self.tree_file.write_text(json.dumps(scan), encoding="utf-8")
def cue(self) -> None:
spoken = base.tone(1, 8000)
def synthesize(body: bytes, admit: Callable[[str], None]) -> bytes:
if json.loads(body)["text"] == CUE:
self.vanish()
return spoken
patch = mock.patch.object(self.httpd.hub.speech, "synthesize", synthesize)
patch.start()
self.addCleanup(patch.stop)
def steps(self, browser: str) -> list[dict]:
self.cue()
steps = []
for index, (width, height) in enumerate(base.WIDTHS):
shot = str(OUT / f"{browser}-{width}")
page = f"{self.base}?{width}"
last = index == len(base.WIDTHS) - 1
steps += [
{"width": width, "height": height, "url": f"{page}-clear#stream", "wait": 600, "probe": CLEAR, "shot": None},
{"width": width, "height": height, "url": f"{page}-loaded#resources", "wait": 1200, "probe": probe(LOADED), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(FOUND), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(dash.STARS), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(METRIC), "shot": f"{shot}-combined-star.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(dash.STARS, ["resources"]), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(COMBINED_OFF), "shot": f"{shot}-metric-star.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(HOME_METRICS), "shot": f"{shot}-home-metrics.png"},
{"width": width, "height": height, "url": f"{page}-reloaded#home", "wait": 1500, "probe": probe(RELOADED), "shot": None},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(PM), "shot": f"{shot}-home-bookmarks.png"},
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(LONG), "shot": f"{shot}-home-long-paths.png"},
]
if last:
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": probe(GONE), "shot": f"{shot}-gone.png"})
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": probe(UNPIN if last else UNPIN_PLAIN), "shot": None})
return steps
def check(self, data: dict, browser: str) -> None:
results = iter(data["results"])
for index, (width, _) in enumerate(base.WIDTHS):
last = index == len(base.WIDTHS) - 1
with self.subTest(browser=browser, width=width):
next(results)
loaded = next(results)
self.assertTrue(loaded["drawn"], loaded)
found = next(results)
self.assertEqual((found["charts"], found["chips"], found["inHead"]), ([True, True, True], 0, True), found)
self.assertEqual(found["tree"], [True], found)
self.assertTrue(found["rows"]["repo"] and all(found["rows"]["repo"]), found)
self.assertTrue(found["rows"]["branch"] and all(found["rows"]["branch"]), found)
self.assertTrue(found["rows"]["wt"] and all(found["rows"]["wt"]), found)
self.assertEqual((found["order"], found["operator"]), ([True], [True]), found)
self.assertTrue(all(found["long"].values()), found)
self.assertGreater(found["long"]["leaf"], 0, found)
self.assertEqual(found["disabled"], [], found)
self.assertGreaterEqual(found["deletes"], 1, found)
walked = next(results)
self.assertEqual((walked["missing"], walked["covered"]), ([], []), walked)
metric = next(results)
self.assertNotIn("error", metric, metric)
self.assertEqual((metric["cpuOnly"], metric["hardware"], metric["tokens"], metric["back"], metric["combinedOn"], metric["combined"]), (True, "true", "true", True, True, "true"), metric)
self.assertEqual(metric["cpuTitle"], "Unpin from Home: Hardware: CPU")
self.assertEqual(metric["axisOverlaps"], 0, metric)
self.assertEqual(metric["allState"], ["false", "Pin to Home: Hardware: all series"])
kinds = [[kind, key.split("/")[0], view] for kind, key, view in metric["stored"]]
self.assertEqual(kinds, [
["metric", "hardware", {"chart": "hardware", "tokens": "interval", "shown": [res.CPU]}],
["metric", "tokens", {"chart": "tokens", "tokens": "interval", "shown": None}],
["metric", "combined", {"chart": "combined", "tokens": "interval", "shown": None}],
])
self.assertRegex(metric["stored"][0][1], r"^hardware/[0-9a-f]{16}$")
self.assertEqual([key for _, key, _ in metric["stored"][1:]], ["tokens/interval/all", "combined/interval/all"])
combined_walk = next(results)
self.assertEqual((combined_walk["missing"], combined_walk["covered"]), ([], []), combined_walk)
self.assertEqual(next(results), {"off": True, "hardware": ["false", "Pin to Home: Hardware: all series"]})
home = next(results)
self.assertEqual(home["errors"], [], home)
self.assertEqual((home["hardware"]["title"], home["hardware"]["lines"], home["hardware"]["legend"], home["hardware"]["chart"]), ("Hardware: CPU", [res.CPU], [res.CPU], "hardware"), home)
self.assertEqual((home["tokens"]["title"], home["tokens"]["bars"]), ("Tokens: all series", ["Skills", "Stage"]), home)
self.assertEqual((home["combined"]["title"], home["combined"]["chart"], home["combined"]["lines"]), ("Combined: all series", "combined", HARDWARE), home)
self.assertGreater(home["combined"]["right"], 0, home)
self.assertEqual(home["combined"]["burn"], 2, home)
self.assertEqual(home["overlaps"], {"hardware": 0, "tokens": 0, "combined": 0}, home)
if home["scroll"]["scrollable"]:
self.assertEqual(home["scroll"]["after"], home["scroll"]["before"], home)
reloaded = next(results)
self.assertEqual((reloaded["hash"], reloaded["lines"], reloaded["title"]), ("#home", [res.CPU], "Hardware: CPU"), reloaded)
self.assertEqual(reloaded["stored"]["view"], {"chart": "hardware", "tokens": "interval", "shown": [res.CPU]})
pm = next(results)
self.assertEqual(pm["pressed"], {"tree": "true", "branch": "true", "order": "true", "operator": "true", "agent": "true"}, pm)
self.assertEqual(pm["errors"], [], pm)
self.assertEqual((pm["tree"][0], pm["order"][0]["gone"], pm["operator"]), ({"gone": False, "title": "Artifacts: tree"}, False, [{"gone": False, "title": "Tasks: Waits on Operator"}, 2]), pm)
self.assertGreaterEqual(pm["tree"][1], 2, pm)
self.assertGreaterEqual(len(pm["order"][1]), 2, pm)
self.assertEqual((pm["artifact"][0]["gone"], pm["artifact"][1]), (False, KEPT), pm)
self.assertEqual((pm["agent"][0], pm["agent"][1]), ({"gone": False, "title": f"Agent {GHOST}"}, True), pm)
self.check_long(next(results))
if last:
gone = next(results)
self.assertEqual(gone["before"], [False] * 6, gone)
self.assertTrue(gone["vanished"], gone)
self.assertEqual((gone["agent"], gone["artifacts"]), (["gone", "Unpin"], [["gone", "Unpin"]] * 5), gone)
unpinned = next(results)
self.assertNotIn(unpinned["metric"], unpinned["tiles"])
self.assertNotIn(unpinned["metric"], unpinned["stored"])
if last:
self.assertEqual(len(unpinned["artifacts"]), 5, unpinned)
self.assertFalse(set(unpinned["artifacts"]) & set(unpinned["tiles"] + unpinned["stored"]), unpinned)
def check_long(self, long: dict) -> None:
self.assertEqual(long["errors"], [], long)
self.assertEqual(long["pressed"], {key: [False, True, "true"] for key in LONG_ROWS}, long)
self.assertEqual([key for key in long["stored"] if key in long["keys"].values()], list(long["keys"].values()), long)
for key in ("core", "leaf"):
self.assertRegex(long["keys"][key], r"^artifact:(wt|artefact)_23_[0-9a-f]{16}$", long)
labels = {"repo": LONG_REPO, "worktree": LONG_WORKTREE, "core": CORE_WORKTREE, "leaf": LONG_VOLUME}
names = {"repo": LONG_NAME, "worktree": "/".join(Path(LONG_WORKTREE).parts[-2:]), "core": "/".join(Path(CORE_WORKTREE).parts[-2:]), "leaf": LONG_VOLUME.split(":", 1)[1]}
for key in LONG_ROWS:
shown = long["shown"][key]
self.assertIsNotNone(shown, (key, long))
self.assertFalse(shown["gone"], (key, shown))
self.assertEqual(shown["label"], names[key], (key, shown))
self.assertIn(labels[key], shown["body"], (key, shown))
self.assertTrue(shown["title"].startswith("Artifact "), (key, shown))
self.assertIn(LONG_WORKTREE, long["shown"]["worktree"]["title"])
self.assertIn(CORE_WORKTREE, long["shown"]["core"]["title"])
self.assertIn(LONG_VOLUME, long["shown"]["leaf"]["title"])
self.assertEqual(long["scroll"]["deletes"], 0, long)
if long["scroll"]["scrollable"]:
self.assertEqual(long["scroll"]["after"], long["scroll"]["before"], long)
def test_chromium_pins_metrics_with_their_selection_views_and_single_elements_at_three_widths(self):
data = self.drive(self.steps("chromium"), None, init=w4.GUARD)
(OUT / "chromium-bookmarks.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
self.assertEqual(data["errors"], [])
self.check(data, "chromium")
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
def test_firefox_pins_metrics_with_their_selection_views_and_single_elements_at_three_widths(self):
data = self.drive(self.steps("firefox"), None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"), init=w4.GUARD)
(OUT / "firefox-bookmarks.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, "firefox")
if __name__ == "__main__":
unittest.main()
+55 -1
View File
@@ -43,7 +43,16 @@ GIT_ENV = {
"GIT_CONFIG_GLOBAL": os.devnull, "GIT_CONFIG_NOSYSTEM": "1",
}
TREE = "0123456789abcdef0123456789abcdef01234567"
PAGE = "<!doctype html><title>diff</title><script>document.title = 'page script'</script>"
LONG_REPO = "/home/operator-example-01/Repositories/github.com/operator-example-01/skills"
LONG_WORKTREE = f"{LONG_REPO}/.worktrees/feature/hub-bookmarks-everywhere"
LONG_BRANCH = "feature/hub-bookmarks-everywhere"
LONG_TASK = "work/bookmarks"
LONG_VOLUME = "volume:infinito_nexus_core_mariadb_data"
CORE_REPO = "/home/operator-example-01/Repositories/github.com/infinito-nexus/core"
CORE_BRANCH = "feature/store-workspace-proxmox-cosmos-requirements-statically-into-iam-before-the-final-compose-and-swarm-roundtrip"
CORE_WORKTREE = f"/home/operator-example-01/.local/share/worktrees/github.com/infinito-nexus/core/{CORE_BRANCH}"
MERGED_BRANCH = "feature/merged-away"
PAGE ="<!doctype html><title>diff</title><script>document.title = 'page script'</script>"
HOST_STATE = Path("/home/op/.local/state/kvb-orchestrator")
ASK = {"tool": "Bash", "command": "make deploy", "cwd": "/repo", "session": "s1", "agent": "", "timeout": 60}
HOOK = {
@@ -98,6 +107,51 @@ def iso(ts: float) -> str:
return datetime.datetime.fromtimestamp(ts, datetime.UTC).isoformat().replace("+00:00", "Z")
def scan_item(branch: str, worktree: str | None, state: str, sha: str) -> dict:
"""Args:
branch: the branch name.
worktree: its worktree path, None for a branch without one.
state: the gc state, such as unmerged or merged-clean.
sha: the local tip.
Returns:
One pkgmgr branch tree item; a merged-clean one without a worktree
is a branch the tree offers to delete.
"""
merged = state == "merged-clean"
counts = 0 if worktree else None
return dict({
"branch": branch, "worktree": worktree, "head": sha, "detached": False, "locked": None, "worktree_state": "clean" if worktree else "none",
"staged": counts, "unstaged": counts, "untracked": counts, "upstream": None, "ahead": None, "behind": None, "gone": False, "local_sha": sha, "remotes": {},
"compose_projects": [], "images": [], "state": state, "merged_by": "#7" if merged else None, "merged_into": "main" if merged else None, "size_bytes": None,
"skip": None, "reason": state, "result": None, "flow": None,
}, actions=["local-branch"])
def long_repos() -> list[dict]:
"""Returns:
pkgmgr scan repositories on paths of real length: the skills
repository with the worktree of LONG_BRANCH and the merged
MERGED_BRANCH, and infinito-nexus/core with a worktree path of 196
characters.
"""
def entry(path: str, items: list[dict]) -> dict:
return {"path": path, "remote": f"{path}.git", "default": "main", "missing": False, "known": True, "forge": "none", "scanned_at": "2026-11-14T12:00:00+00:00", "warnings": [], "items": items}
return [
entry(LONG_REPO, [scan_item(LONG_BRANCH, LONG_WORKTREE, "unmerged", "1" * 40), scan_item(MERGED_BRANCH, None, "merged-clean", "2" * 40)]),
entry(CORE_REPO, [scan_item(CORE_BRANCH, CORE_WORKTREE, "unmerged", "3" * 40)]),
]
def long_task(now: float) -> dict:
"""Returns:
The register row of LONG_TASK, working in LONG_WORKTREE and holding
the volume LONG_VOLUME.
"""
return {"title": "Bookmarks everywhere", "status": "running", "worker": "Skills session", "workdir": LONG_WORKTREE, "roles": {"Skills session": "RA"}, "artifacts": [{"ref": LONG_VOLUME, "added": iso(now - 600)}]}
KEYS = tempfile.TemporaryDirectory()
ORIGIN = "http://localhost:8737"
PRESENT = 0x05
+329 -12
View File
@@ -3,10 +3,27 @@ from __future__ import annotations
import json
import re
import subprocess
import time
import unittest
from typing import ClassVar
from hub_case import HubCase
from hub_support import HUB, NAV
from hub_support import (
CORE_BRANCH,
CORE_REPO,
CORE_WORKTREE,
HUB,
LONG_BRANCH,
LONG_REPO,
LONG_TASK,
LONG_VOLUME,
LONG_WORKTREE,
MERGED_BRANCH,
NAV,
long_repos,
long_task,
)
from kvb_orchestrator.viewstore import SERIES_ID, SHOWN_LIMIT
TEMPLATES = HUB / "templates"
PANELS = TEMPLATES / "panels.js"
@@ -185,7 +202,7 @@ function viewStore(server) {
function page(server) {
const store = viewStore(server);
const toasts = [];
const context = vm.createContext({ViewStore: store, labelOf: (key) => key, toast: (title, lines, good) => toasts.push([title, lines.join(" "), good]), console});
const context = vm.createContext({ViewStore: store, labelOf: (key) => key, toast: (title, lines, good) => toasts.push([title, lines.join(" "), good]), tree: {data: null, model: null}, console});
vm.runInContext(fs.readFileSync(panelsFile, "utf8"), context);
vm.runInContext(`${fs.readFileSync(homeFile, "utf8")}
globalThis.probe = {homePress, homeUnpin, homeView, Panels};`, context);
@@ -198,9 +215,9 @@ PAGE_PROBE = TAB_KIT + """
const server = hub([]);
const tab = page(server);
const {homePress, homeUnpin, homeView, Panels} = tab;
const ids = Object.fromEntries(["panel", "task", "message", "artifact", "agent", "ancestry", "nope"].map((kind) => [kind, Boolean(Panels.lookup(kind, kind === "panel" ? "stream" : "x"))]));
const panels = ["stream", "radio-log", "agents/orbit", "agents/chord", "agents/swimlane", "agents/3d", "agents/tree", "agents/hierarchy", "artifacts/orbit", "artifacts/chord", "artifacts/swimlane", "artifacts/3d",
"tasks/list", "tasks/board", "tasks/rasci", "tasks/gantt", "tasks/burn", "tasks/3d"].filter((id) => !Panels.lookup("panel", id));
const ids = Object.fromEntries(["panel", "task", "message", "artifact", "agent", "ancestry", "metric", "nope"].map((kind) => [kind, Boolean(Panels.lookup(kind, kind === "panel" ? "stream" : "x"))]));
const panels = ["stream", "radio-log", "agents/orbit", "agents/chord", "agents/swimlane", "agents/3d", "agents/tree", "agents/hierarchy", "agents/order", "artifacts/orbit", "artifacts/chord", "artifacts/swimlane", "artifacts/tree", "artifacts/3d",
"tasks/list", "tasks/board", "tasks/rasci", "tasks/gantt", "tasks/burn", "tasks/3d", "tasks/operator"].filter((id) => !Panels.lookup("panel", id));
(async () => {
homePress("panel", "tasks/gantt", "Gantt");
await settle();
@@ -261,7 +278,7 @@ RACE_PROBE = TAB_KIT + """
"""
STAR_PROBE = """
DOM_KIT = """
const fs = require("fs");
const vm = require("vm");
const XHTML = "http://www.w3.org/1999/xhtml";
@@ -275,8 +292,16 @@ class El {
setAttribute(name, value) { this.attrs.set(name, String(value)); }
getAttribute(name) { return this.attrs.has(name) ? this.attrs.get(name) : null; }
hasAttribute(name) { return this.attrs.has(name); }
removeAttribute(name) { this.attrs.delete(name); }
get classList() { const list = (this.getAttribute("class") || "").split(/\\s+/); return {contains: (name) => list.includes(name)}; }
detach() { if (this.parentNode) { this.parentNode.children = this.parentNode.children.filter((child) => child !== this); this.parentNode = null; } }
get isConnected() { let at = this; while (at.parentNode) { at = at.parentNode; } return at === document.body; }
focus() { document.activeElement = this; }
detach() {
if (this.parentNode) {
if (this.contains(document.activeElement)) { document.activeElement = document.body; }
this.parentNode.children = this.parentNode.children.filter((child) => child !== this); this.parentNode = null;
}
}
append(...nodes) { nodes.forEach((child) => { child.detach(); child.parentNode = this; this.children.push(child); }); }
prepend(...nodes) { nodes.reverse().forEach((child) => { child.detach(); child.parentNode = this; this.children.unshift(child); }); }
replaceChildren(...nodes) { [...this.children].forEach((child) => child.detach()); this.append(...nodes); }
@@ -292,10 +317,26 @@ const el = (tag, attrs, ...children) => {
made.append(...children);
return made;
};
const document = {createElement: (tag) => new El(tag), createElementNS: (ns, tag) => new El(tag, ns)};
const document = {createElement: (tag) => new El(tag), createElementNS: (ns, tag) => new El(tag, ns), body: null, activeElement: null};
document.body = new El("body");
document.activeElement = document.body;
const text = (value) => {
const made = new El("#text");
made.textContent = String(value);
return made;
};
const h = (tag, attrs, ...children) => {
const made = new El(tag);
Object.entries(attrs || {}).filter(([name, value]) => name !== "on" && value !== null && value !== undefined && value !== false).forEach(([name, value]) => made.setAttribute(name, value));
made.append(...children.flat(Infinity).filter((child) => child !== null && child !== undefined && child !== false && child !== "").map((child) => (child instanceof El ? child : text(child))));
return made;
};
const textOf = (node) => (node.tagName === "#TEXT" ? node.textContent : node.children.map(textOf).join(""));
const context = vm.createContext({document, MutationObserver: class { observe() {} }, console});
vm.runInContext(fs.readFileSync(process.argv[1], "utf8"), context);
const P = vm.runInContext("Panels", context);
"""
STAR_PROBE = DOM_KIT + """
P.panel("tasks/list", "Tasks: list", () => null);
P.panel("radio-log", "Radio log", () => null);
P.item("task", (id) => `Task ${id}`, () => null);
@@ -366,11 +407,181 @@ const settle = () => new Promise((resolve) => setTimeout(resolve, 0));
"""
VIEW_PROBE = """
const P = require(process.argv[1]);
const view = {chart: "hardware", tokens: "interval", shown: ["host:CPU"]};
const pin = {kind: "metric", id: "hardware/x", w: 4, h: 3, view};
P.item("metric", (id, seen) => `Metric ${id} ${seen ? seen.shown.join() : "none"}`, (size, id, seen) => (seen ? `${id} ${size.w} ${seen.chart}` : null));
const added = P.add([], "metric", "hardware/x", view);
const looked = P.lookup("metric", "hardware/x", view);
const bare = P.lookup("metric", "hardware/x");
console.log(JSON.stringify({
valid: [P.validLayout([pin]), P.validLayout([{...pin, view: []}]), P.validLayout([{...pin, view: "x"}]), P.validLayout([{...pin, view: null}]), P.validLayout([{...pin, extra: 1}])],
cleaned: P.clean([pin, {...pin, id: "hardware/y", view: [1]}]),
added: [added.pins, P.add([], "task", "work/a").pins, P.add([], "task", "work/a", "x").pins],
resized: P.resizeKey(added.pins, "metric:hardware/x", 6, 5),
lookup: [looked.title, looked.render({w: 4, h: 3}), bare.title, bare.render({w: 1, h: 1})],
digest: [P.digest("host:CPU") === P.digest("host:CPU"), P.digest("host:CPU") === P.digest("host:RAM"), /^[0-9a-f]{16}$/.test(P.digest("")), P.ID.test(`hardware/${P.digest("x")}`)],
}));
"""
CAPTURE_PROBE = DOM_KIT + """
P.item("metric", (id, view) => `Metric ${view.shown === null ? "all" : view.shown.join()}`, () => null);
let selection = null;
P.capture("resources-hardware", () => ({kind: "metric", id: selection === null ? "hardware/all" : "hardware/cpu", view: {chart: "hardware", tokens: "interval", shown: selection}}));
const head = el("div", {class: "res-head", "data-star-slot": ""}, el("span", {class: "res-title"}));
const chart = el("section", {"data-panel": "resources-hardware"}, head, el("div", {class: "res-plot"}));
const loose = el("section", {"data-panel": "resources-unknown"});
const root = el("main", {}, chart, loose);
const clicked = [];
const mark = P.decorate(root, {pinned: (kind, id) => `${kind}:${id}` === "metric:hardware/cpu", press: (...args) => clicked.push(args)});
const star = () => head.children.find((child) => child.classList.contains("star"));
const before = [star().getAttribute("aria-pressed"), star().getAttribute("title"), loose.children.length, chart.children[0] === head];
selection = ["host:CPU"];
mark();
const after = [star().getAttribute("aria-pressed"), star().getAttribute("title"), head.children.filter((child) => child.classList.contains("star")).length];
star().listeners.click[0]({preventDefault: () => null, stopPropagation: () => null});
console.log(JSON.stringify({before, after, clicked, target: P.targetOf(chart)}));
"""
METRIC_PROBE = """
const fs = require("fs");
const vm = require("vm");
const [panelsFile, resourcesFile, homeFile] = process.argv.slice(1);
const context = vm.createContext({ViewStore: {get: () => ({tokens: "accumulated"}), update: () => Promise.resolve(true), on: () => null}, labelOf: (key) => key, toast: () => null, console});
vm.runInContext(fs.readFileSync(panelsFile, "utf8"), context);
vm.runInContext(`${fs.readFileSync(resourcesFile, "utf8")}\\n${fs.readFileSync(homeFile, "utf8")}\\nglobalThis.probe = {resourcePin, resourceView, Panels};`, context);
const {resourcePin, resourceView, Panels} = context.probe;
const empty = resourcePin("tokens");
resourceView.series.hardware = {ids: ["host:RAM", "host:CPU", "disk:/"], shown: ["host:CPU"], tokens: "accumulated"};
resourceView.series.tokens = {ids: ["agent:Skills", "agent:Stage"], shown: ["agent:Stage", "agent:Skills"], tokens: "accumulated"};
resourceView.series.combined = {ids: ["host:CPU", "agent:Skills", "burn:done"], shown: ["host:CPU", "burn:done"], tokens: "interval"};
const pins = ["hardware", "tokens", "combined"].map(resourcePin);
resourceView.series.hardware = {ids: ["host:RAM", "host:CPU", "disk:/"], shown: ["host:RAM", "host:CPU", "disk:/"], tokens: "interval"};
const all = resourcePin("hardware");
const titles = [...pins, all, empty].map((pin) => Panels.lookup(pin.kind, pin.id, pin.view).title);
const four = Panels.lookup("metric", "x", {chart: "tokens", tokens: "interval", shown: ["agent:a", "agent:b", "agent:c", "agent:d"]}).title;
const broken = [Panels.lookup("metric", "x").title, Panels.lookup("metric", "x", {chart: "disks", shown: null}).render({w: 1, h: 1})];
const limit = Number(process.argv[4]);
const agents = (count) => Array.from({length: count}, (_, index) => `agent:a${String(index).padStart(3, "0")}`);
const selected = (count, off) => {
resourceView.series.tokens = {ids: agents(count), shown: agents(count).slice(off), tokens: "interval"};
const pin = resourcePin("tokens");
return [pin.view.shown === null ? null : pin.view.shown.length, pin.refused || null, pin.id.split("/").length];
};
const limits = [selected(limit + 1, 1), selected(limit + 2, 1), selected(limit + 2, 0), selected(limit + 2, limit + 2)];
console.log(JSON.stringify({empty, pins, all, titles, four, broken, limits, digests: [Panels.digest("host:CPU"), Panels.digest("burn:done\\nhost:CPU")]}));
"""
PRESS_PROBE = TAB_KIT + """
const server = hub([]);
const tab = page(server);
const view = {chart: "hardware", tokens: "interval", shown: ["host:CPU"]};
(async () => {
tab.homePress("metric", "hardware/abc", "Hardware: CPU", view);
await settle();
const stored = clone(server.value);
tab.homePress("metric", "hardware/abc", "Hardware: CPU", view);
await settle();
console.log(JSON.stringify({stored, after: server.value, pins: tab.homeView.pins}));
})();
"""
REFUSED_PROBE = DOM_KIT + """
P.item("metric", (id) => `Metric ${id}`, () => null);
P.item("artifact", (id) => `Artifact ${id}`, () => null);
let over = true;
P.capture("resources-tokens", () => (over ? {kind: "metric", id: "tokens/interval/x", view: {chart: "tokens"}, refused: "too many series"} : {kind: "metric", id: "tokens/interval/y", view: {chart: "tokens"}}));
const chart = el("section", {"data-panel": "resources-tokens"}, el("div", {"data-star-slot": ""}));
const long = el("li", {"data-item": `artifact:wt:/${"p".repeat(300)}`});
const root = el("main", {}, chart, long);
const clicked = [];
const mark = P.decorate(root, {pinned: () => false, press: (...args) => clicked.push(args)});
const star = (host) => host.all().find((node) => node.classList.contains("star"));
const read = (host) => [star(host).hasAttribute("disabled"), star(host).getAttribute("title"), star(host).getAttribute("aria-pressed")];
const fire = (host) => (star(host).listeners.click || []).forEach((listen) => listen({preventDefault: () => null, stopPropagation: () => null}));
const refused = read(chart);
const first = star(chart);
fire(chart);
over = false;
mark();
const freed = [...read(chart), star(chart) === first];
fire(chart);
over = true;
mark();
const again = read(chart);
fire(chart);
fire(long);
console.log(JSON.stringify({refused, freed, again, long: read(long), clicked}));
"""
ORDER_PROBE = DOM_KIT + """
Object.assign(context, {h, state: {agent_order: ["Skills", "Stage"]}, ui: {order: null}, counter: (value) => text(value), face: () => text("face"), person: (name) => text(name),
icon: () => text("icon"), officeBtn: (name, label) => h("button", {"aria-label": label}), focusKey: () => null, refocus: () => null, act: async () => true, go: () => null});
vm.runInContext(`${fs.readFileSync(process.argv[2], "utf8")}\\nglobalThis.probe = {orderDom, drawAgentOrder};`, context);
const {orderDom, drawAgentOrder} = context.probe;
P.panel("agents/order", "Agents: priority", () => null);
orderDom.box = el("section", {"data-panel": "agents/order"});
orderDom.slot = el("span", {"data-star-slot": ""});
document.body.append(orderDom.box);
const mark = P.decorate(document.body, {pinned: () => false, press: () => null});
const stars = () => orderDom.box.all().filter((node) => node.classList.contains("star"));
drawAgentOrder();
mark();
const first = stars()[0];
first.focus();
drawAgentOrder();
mark();
context.state.agent_order = ["Stage", "Skills", "Docs"];
drawAgentOrder();
mark();
console.log(JSON.stringify({count: stars().length, same: stars()[0] === first, focused: document.activeElement === first, head: first.parentNode.parentNode === orderDom.box.children[0],
ranks: orderDom.box.all().filter((node) => node.tagName === "LI").map((node) => node.getAttribute("data-name"))}));
"""
TREE_PROBE = DOM_KIT + """
const [, artifactsFile, treeFile, homeFile, dataFile] = process.argv.slice(1);
Object.assign(context, {
h, icon: () => text(""), named: (label, hint) => ({title: hint || label, "aria-label": label}), iconBtn: (name, label, cls, run, hint) => h("button", {"aria-label": label, title: hint}),
counter: (value) => text(value), emptyState: (title, words) => h("div", {class: "empty", "data-title": title}, words), branchAncestry: () => null, gateIcons: () => h("span", {class: "gates"}),
flowLine: () => null, flowDetails: () => null, flowEdges: () => [], copyButton: () => null, face: () => null, person: (name) => text(name), status: (value) => text(value), pill: (words) => text(words),
workChips: () => null, popupHead: (glyph, label) => h("h2", {class: "panel-title"}, label), meta: (rows) => h("dl", {}, rows.map(([key, value]) => h("div", {"data-key": key}, value === null || value === undefined ? "" : value))),
WORK_CHIPS: {}, clock: {format: () => "c"}, stampOf: (t) => t, nowSeconds: () => 1763000000, labelOf: (key) => key, toast: () => null,
tree: {data: JSON.parse(fs.readFileSync(dataFile, "utf8")), model: null, busy: false, q: "", open: new Set(), dom: null},
});
vm.runInContext(`${[artifactsFile, treeFile, homeFile].map((file) => fs.readFileSync(file, "utf8")).join("\\n")}
tree.model = artifactModel(tree.data);
homeView.fetched.tree = Date.now();
globalThis.probe = {treeCards};`, context);
const {treeCards} = context.probe;
const tree = context.tree;
const flat = (nodes) => nodes.filter((node) => node instanceof El).flatMap((node) => [node, ...node.all()]);
const deletes = (nodes) => flat(nodes).filter((node) => node.getAttribute("aria-label") === "Delete").length;
const rows = flat(treeCards("", false).nodes).filter((node) => node.hasAttribute("data-item"));
const pinned = rows.map((row) => {
const target = P.targetOf(row);
const entry = target.id ? P.lookup(target.kind, target.id) : null;
const shown = entry ? entry.render({w: 4, h: 3}) : null;
const head = shown ? shown.all().find((node) => node.classList.contains("panel-title")) : null;
const path = shown ? shown.all().find((node) => node.getAttribute("data-key") === "Path" || node.getAttribute("data-key") === "Ref") : null;
return {id: target.id, refused: target.refused || null, title: entry ? entry.title : null, label: head ? textOf(head) : null, path: path ? textOf(path) : null, deletes: shown ? deletes([shown]) : null};
});
const home = P.lookup("panel", "artifacts/tree").render({w: 6, h: 4});
const glance = [deletes(treeCards("", false).nodes), deletes(treeCards("", true).nodes), deletes([home])];
const digested = pinned.map((entry) => entry.id).filter((id) => /_23_/.test(id || ""));
const kept = tree.data;
tree.data = {...kept, repos: [], tasks: [], cleanups: []};
const empty = [treeCards("", true).nodes[0].getAttribute("data-title"), treeCards("zz", false).nodes[0].getAttribute("data-title"), textOf(P.lookup("panel", "artifacts/tree").render({w: 6, h: 4}).children[0])];
tree.data = kept;
tree.model = context.artifactModel({...kept, repos: [], tasks: []});
const gone = digested.map((id) => [P.lookup("artifact", id).render({w: 4, h: 3}), P.lookup("artifact", id).title]);
console.log(JSON.stringify({pinned, glance, empty, gone}));
"""
def node(probe: str, *args: str) -> dict:
done = subprocess.run(["node", "-e", probe, *args], capture_output=True, text=True, timeout=60, check=True)
return json.loads(done.stdout)
def escaped(raw: str) -> str:
return re.sub(r"[^A-Za-z0-9./-]", lambda found: f"_{ord(found.group()):x}_", raw)
class TestHomeLayout(unittest.TestCase):
def test_the_layout_validation_takes_at_most_64_pins_of_kind_id_w_and_h_in_their_ranges(self):
data = node(LAYOUT_PROBE, str(PANELS))
@@ -447,7 +658,7 @@ class TestHomeStart(unittest.TestCase):
class TestHomePage(unittest.TestCase):
def test_the_page_registers_every_panel_and_item_kind_and_refuses_the_65th_pin_before_any_update(self):
data = node(PAGE_PROBE, str(PANELS), str(HOME))
self.assertEqual(data["ids"], {"panel": True, "task": True, "message": True, "artifact": True, "agent": True, "ancestry": True, "nope": False})
self.assertEqual(data["ids"], {"panel": True, "task": True, "message": True, "artifact": True, "agent": True, "ancestry": True, "metric": True, "nope": False})
self.assertEqual(data["panels"], [])
self.assertEqual((data["one"], data["none"], data["solid"], data["full"], data["after"]), (["panel:tasks/gantt"], 0, ["panel:agents/3d"], [64, 0], 63))
self.assertEqual(data["paths"], ["home.pins"])
@@ -479,11 +690,16 @@ class TestHomePage(unittest.TestCase):
dynamic = {f"{tab}/{view}" for tab in re.findall(r'"data-panel": `(\w+)/\$\{view\}`', sources) for view in views[tab]}
used = set(re.findall(r'(?:"data-item"|item): `(\w+):', sources))
marked = set(re.findall(r"\['[^']+', \"([^\"]+)\"\]", home))
self.assertEqual((len(literal), marked), (4, {"radio-log"}))
captured = set(re.findall(r'Panels\.capture\("([^"]+)"', home))
made = set(re.findall(r'\{kind: "(\w+)", id, view[,}]', sources))
self.assertEqual((len(literal), marked), (7, {"radio-log"}))
literal |= marked
self.assertEqual(len(dynamic), 13)
self.assertEqual(sorted(literal | dynamic), sorted(registered))
self.assertEqual(sorted(used), sorted(kinds))
self.assertIn('"data-panel": `resources-${kind}`', sources)
self.assertEqual(captured, {"resources-hardware", "resources-tokens", "resources-combined"})
self.assertFalse(captured & registered)
self.assertEqual((made, sorted(used | made)), ({"metric"}, sorted(kinds)))
class TestHomeStars(unittest.TestCase):
@@ -493,7 +709,7 @@ class TestHomeStars(unittest.TestCase):
self.assertEqual(data["task"], {"inSlot": True, "slotLast": True, "rows": 0, "pressed": "true", "label": "Unpin from Home"})
self.assertEqual(data["bare"], {"first": "star-row", "stars": 1})
self.assertEqual((data["svg"], data["radio"], data["again"], data["redrawn"]), (0, ["radio-log", "star-row"], [4, 4], [True, 4]))
self.assertEqual(data["clicked"], [["task", "work/a", "Task work/a"]])
self.assertEqual(data["clicked"], [["task", "work/a", "Task work/a", None]])
def test_the_star_css_positions_nothing_and_leaves_the_starred_elements_alone(self):
css = (TEMPLATES / "style-home.css").read_text(encoding="utf-8")
@@ -504,6 +720,107 @@ class TestHomeStars(unittest.TestCase):
self.assertNotIn("[data-item]", css)
class TestHomeBookmarks(unittest.TestCase):
VIEW: ClassVar[dict] = {"chart": "hardware", "tokens": "interval", "shown": ["host:CPU"]}
def test_a_pin_may_carry_a_plain_view_that_cleaning_adding_resizing_and_the_registry_keep(self):
data = node(VIEW_PROBE, str(PANELS))
pin = {"kind": "metric", "id": "hardware/x", "w": 4, "h": 3, "view": self.VIEW}
self.assertEqual(data["valid"], [True, False, False, False, False])
self.assertEqual(data["cleaned"], [pin])
self.assertEqual(data["added"], [[pin], [{"kind": "task", "id": "work/a", "w": 4, "h": 3}], [{"kind": "task", "id": "work/a", "w": 4, "h": 3}]])
self.assertEqual(data["resized"], [{**pin, "w": 6, "h": 5}])
self.assertEqual(data["lookup"], ["Metric hardware/x host:CPU", "hardware/x 4 hardware", "Metric hardware/x none", None])
self.assertEqual(data["digest"], [True, False, True, True])
def test_a_captured_panel_stars_the_pin_its_capture_makes_now_and_presses_it_with_its_view(self):
data = node(CAPTURE_PROBE, str(PANELS))
self.assertEqual(data["before"], ["false", "Pin to Home: Metric all", 0, True])
self.assertEqual(data["after"], ["true", "Unpin from Home: Metric host:CPU", 1])
self.assertEqual(data["clicked"], [["metric", "hardware/cpu", "Metric host:CPU", self.VIEW]])
self.assertEqual(data["target"], {"kind": "metric", "id": "hardware/cpu", "view": self.VIEW})
def test_a_chart_star_pins_the_series_switched_on_now_so_another_selection_is_another_pin(self):
data = node(METRIC_PROBE, str(PANELS), str(TEMPLATES / "page-resources.js"), str(HOME))
cpu, mixed = data["digests"]
self.assertEqual(data["empty"], {"kind": "metric", "id": "tokens/accumulated/all", "view": {"chart": "tokens", "tokens": "accumulated", "shown": None}})
self.assertEqual(data["pins"], [
{"kind": "metric", "id": f"hardware/{cpu}", "view": self.VIEW},
{"kind": "metric", "id": "tokens/accumulated/all", "view": {"chart": "tokens", "tokens": "accumulated", "shown": None}},
{"kind": "metric", "id": f"combined/interval/{mixed}", "view": {"chart": "combined", "tokens": "interval", "shown": ["burn:done", "host:CPU"]}},
])
self.assertEqual(data["all"], {"kind": "metric", "id": "hardware/all", "view": {"chart": "hardware", "tokens": "interval", "shown": None}})
self.assertEqual(data["titles"], ["Hardware: CPU", "Tokens (accumulated): all series", "Combined: done, CPU", "Hardware: all series", "Tokens (accumulated): all series"])
self.assertEqual((data["four"], data["broken"]), ("Tokens: 4 series", ["Metric", None]))
def test_pressing_a_metric_star_stores_its_view_with_the_pin_and_pressing_again_unpins_it(self):
data = node(PRESS_PROBE, str(PANELS), str(HOME))
pin = {"kind": "metric", "id": "hardware/abc", "w": 4, "h": 3, "view": self.VIEW}
self.assertEqual((data["stored"], data["after"], data["pins"]), ([pin], [], []))
def test_a_chart_star_refuses_a_selection_past_the_view_stores_series_limit_and_names_why(self):
data = node(METRIC_PROBE, str(PANELS), str(TEMPLATES / "page-resources.js"), str(HOME), str(SHOWN_LIMIT))
why = f"more than {SHOWN_LIMIT} series are switched on: switch some off, or all of them on"
self.assertEqual(data["limits"], [[SHOWN_LIMIT, None, 3], [SHOWN_LIMIT + 1, why, 3], [None, None, 3], [0, None, 3]])
def test_a_refused_capture_or_an_overlong_id_disables_the_star_with_its_reason_and_a_press_pins_nothing(self):
data = node(REFUSED_PROBE, str(PANELS))
refused = [True, "Pin to Home: not possible, too many series", "false"]
self.assertEqual((data["refused"], data["again"]), (refused, refused))
self.assertEqual(data["freed"], [False, "Pin to Home: Metric tokens/interval/y", "false", True])
self.assertEqual(data["long"], [True, "Pin to Home: not possible, the id runs past 200 characters", "false"])
self.assertEqual(data["clicked"], [["metric", "tokens/interval/y", "Metric tokens/interval/y", {"chart": "tokens"}]])
def test_the_agent_priority_star_stays_the_same_button_and_keeps_its_focus_through_a_redraw(self):
data = node(ORDER_PROBE, str(PANELS), str(TEMPLATES / "page-agent-order.js"))
self.assertEqual(data, {"count": 1, "same": True, "focused": True, "head": True, "ranks": ["Stage", "Skills", "Docs"]})
def test_the_client_pin_id_grammar_is_the_hubs(self):
done = subprocess.run(["node", "-e", "console.log(JSON.stringify(require(process.argv[1]).ID.source))", str(PANELS)], capture_output=True, text=True, timeout=60, check=True)
self.assertEqual(json.loads(done.stdout), f"^{SERIES_ID.pattern}$")
class TestHomeTree(HubCase):
def served_tree(self) -> str:
self.tree_file.write_text(json.dumps({"generated_at": "2026-11-14T12:00:00+00:00", "delete_ready": False, "delete_reason": "Secret Service locked", "repos": long_repos()}), encoding="utf-8")
self.write_council({"rasci.json": {LONG_TASK: long_task(time.time())}})
status, _, body = self.get("/api/tree")
self.assertEqual(status, 200, body[:300])
served = self.outside / "served-tree.json"
served.write_bytes(body)
return str(served)
def test_every_tree_row_on_paths_of_real_length_pins_shows_that_one_element_on_home_and_turns_gone(self):
data = node(TREE_PROBE, str(PANELS), str(TEMPLATES / "page-artifacts.js"), str(TEMPLATES / "page-tree.js"), str(HOME), self.served_tree())
rows = [
(f"repo:{CORE_REPO}", "github.com/infinito-nexus/core", CORE_REPO),
(f"branch:{CORE_REPO}\0{CORE_BRANCH}", CORE_BRANCH, None),
(f"wt:{CORE_WORKTREE}", CORE_BRANCH, CORE_WORKTREE),
(f"repo:{LONG_REPO}", "github.com/operator-example-01/skills", LONG_REPO),
(f"branch:{LONG_REPO}\0{LONG_BRANCH}", LONG_BRANCH, None),
(f"wt:{LONG_WORKTREE}", LONG_BRANCH, LONG_WORKTREE),
(f"artefact:wt:{LONG_WORKTREE}\0{LONG_TASK}\0{LONG_VOLUME}", LONG_VOLUME.split(":", 1)[1], LONG_VOLUME),
(f"branch:{LONG_REPO}\0{MERGED_BRANCH}", MERGED_BRANCH, None),
]
self.assertEqual(len(data["pinned"]), len(rows), data["pinned"])
digested = []
for found, (raw, label, path) in zip(data["pinned"], rows, strict=True):
with self.subTest(row=raw):
self.assertEqual((found["refused"], found["title"], found["label"], found["path"], found["deletes"]), (None, f"Artifact {raw.replace(chr(0), ' ')}", label, path, 0), found)
self.assertTrue(SERIES_ID.fullmatch(found["id"]), found)
if len(escaped(raw)) <= 200:
self.assertEqual(found["id"], escaped(raw))
else:
self.assertRegex(found["id"], rf"^{raw.split(':', 1)[0]}_23_[0-9a-f]{{16}}$")
digested.append(found["id"].split("_23_")[0])
self.assertEqual(digested, ["wt", "artefact"])
self.assertEqual(data["glance"], [1, 0, 0])
self.assertEqual(data["empty"], ["No repository", "Nothing found", "pkgmgr names no repository."])
self.assertEqual([gone[0] for gone in data["gone"]], [None, None])
for gone, kind in zip(data["gone"], digested, strict=True):
self.assertRegex(gone[1], rf"^Artifact {kind}#[0-9a-f]{{16}}$")
class TestHomeMessage(unittest.TestCase):
def test_a_pinned_message_resolves_by_its_own_id_and_time_whatever_the_stream_shows(self):
data = node(MESSAGE_PROBE, str(PANELS), str(HOME))
+26
View File
@@ -1,5 +1,6 @@
from __future__ import annotations
import itertools
import json
import subprocess
import time
@@ -328,6 +329,31 @@ class TestResourcesPage(unittest.TestCase):
self.assertEqual(self.found["fetched"], ["/api/resources?from=1", ["PATCH", "/api/view", changes]])
AXIS_PROBE = """
const fs = require("fs");
const vm = require("vm");
const s = (tag, attrs, ...children) => ({tag, attrs, children: children.flat(), append(...more) { this.children.push(...more); }});
const context = {s, h: s, DAY: 86400, fixed: (value) => value.toFixed(1), stampOf: (t) => t, absolute: {format: () => "14 Nov 2026, 10:00"}, clock: {format: () => "10:00"}};
vm.runInNewContext(`${fs.readFileSync(process.argv[1], "utf8")}\\nglobalThis.frame = resourceFrame;`, context);
const labels = (width, days) => context.frame({kind: "tokens", label: "Tokens"}, {from: 0, to: days * 86400}, {width, height: 120}, false).svg.children
.filter((node) => node.tag === "text").map((node) => [Number(node.attrs.x), node.attrs["text-anchor"], node.children.join("")]);
console.log(JSON.stringify([[1600, 2], [390, 2], [340, 2], [150, 2], [340, 0.5]].map(([width, days]) => labels(width, days))));
"""
GLYPH = 6.2
class TestResourcesAxis(unittest.TestCase):
def test_time_labels_never_overlap_and_a_plot_too_narrow_for_two_keeps_the_last(self):
done = subprocess.run(["node", "-e", AXIS_PROBE, str(PAGE)], capture_output=True, text=True, timeout=60, check=True)
found = json.loads(done.stdout)
self.assertEqual([len(labels) for labels in found], [5, 2, 2, 1, 5])
self.assertEqual(found[3][0][1:], ["end", "14 Nov 2026, 10:00"])
for labels in found:
spans = sorted((x - {"start": 0, "middle": 0.5, "end": 1}[anchor] * len(words) * GLYPH, x + {"start": 1, "middle": 0.5, "end": 0}[anchor] * len(words) * GLYPH) for x, anchor, words in labels)
with self.subTest(labels=labels):
self.assertTrue(all(left[1] <= right[0] for left, right in itertools.pairwise(spans)), spans)
class TestHubResources(HubCase):
def write(self, name: str, rows: list[dict], tail: str = "") -> None:
folder = self.kept / "resources"
+75 -1
View File
@@ -11,7 +11,7 @@ from unittest import mock
from hub_case import HubCase
from hub_support import HOST_STATE, HUB, server
from kvb_orchestrator import records
from kvb_orchestrator import records, viewstore
from kvb_orchestrator.errors import Conflict, ToolError
from kvb_orchestrator.handler import BODY_LIMIT
from kvb_orchestrator.viewstore import (
@@ -24,6 +24,8 @@ from kvb_orchestrator.viewstore import (
)
STORE = HUB / "templates" / "view-store.js"
PANELS = HUB / "templates" / "panels.js"
DIGESTS = "const P = require(process.argv[1]); console.log(JSON.stringify(process.argv.slice(2).map(P.digest)));"
CHIPS = HUB / "templates" / "legend-chips.js"
CHIPS_STYLE = HUB / "templates" / "style-legend-chips.css"
FULL = {
@@ -277,6 +279,11 @@ def change(values: dict, expected: dict) -> bytes:
return json.dumps({"set": values, "expect": expected}).encode()
def client_digests(*texts: str) -> list[str]:
done = subprocess.run(["node", "-e", DIGESTS, str(PANELS), *texts], capture_output=True, text=True, timeout=60, check=True)
return json.loads(done.stdout)
class TestViewDocument(unittest.TestCase):
def test_the_defaults_and_a_full_document_pass_unchanged(self):
self.assertEqual(valid_view(copy.deepcopy(VIEW)), VIEW)
@@ -328,6 +335,73 @@ class TestViewDocument(unittest.TestCase):
with self.subTest(case=name), self.assertRaises(ToolError):
valid_view(doc)
def test_the_hub_digests_a_selection_exactly_as_panels_js_does(self):
texts = ["", "host:CPU", "burn:done\nhost:CPU", "agent:Ä€\U0001f600", "x" * 5000]
self.assertEqual([viewstore.digest(text) for text in texts], client_digests(*texts))
def test_a_metric_pin_id_must_be_the_one_its_view_gives_so_no_view_hides_under_another_charts_id(self):
cpu = {"chart": "hardware", "tokens": "interval", "shown": ["host:CPU"]}
tokens = {"chart": "tokens", "tokens": "accumulated", "shown": None}
mixed = {"chart": "combined", "tokens": "interval", "shown": ["burn:done", "host:CPU"]}
hundred = {"chart": "tokens", "tokens": "interval", "shown": sorted(f"agent:a{index:03d}" for index in range(100))}
cpu_digest, ram_digest, mixed_digest, hundred_digest = client_digests("host:CPU", "host:RAM", "burn:done\nhost:CPU", "\n".join(hundred["shown"]))
def doc(*pins: dict) -> dict:
made = copy.deepcopy(VIEW)
made["home"]["pins"] = [{"kind": "metric", "w": 4, "h": 3, **pin} for pin in pins]
return made
accepted = doc({"id": f"hardware/{cpu_digest}", "view": cpu}, {"id": "tokens/accumulated/all", "view": tokens}, {"id": f"combined/interval/{mixed_digest}", "view": mixed},
{"id": f"tokens/interval/{hundred_digest}", "view": hundred})
self.assertEqual(valid_view(copy.deepcopy(accepted)), accepted)
cases = {
"hardware all id with a tokens view": doc({"id": "hardware/all", "view": tokens}),
"tokens id with a hardware view": doc({"id": "tokens/accumulated/all", "view": {**cpu, "shown": None}}),
"all id with a selection": doc({"id": "hardware/all", "view": cpu}),
"digest of another selection": doc({"id": f"hardware/{ram_digest}", "view": cpu}),
"other token mode": doc({"id": "tokens/interval/all", "view": tokens}),
"hardware id with a mode": doc({"id": f"hardware/interval/{cpu_digest}", "view": cpu}),
"combined id without a mode": doc({"id": f"combined/{mixed_digest}", "view": mixed}),
}
for name, broken in cases.items():
with self.subTest(case=name), self.assertRaises(ToolError):
valid_view(broken)
def test_a_metric_pin_keeps_its_chart_selection_and_a_malformed_one_is_refused(self):
metric = {"kind": "metric", "id": f"hardware/{client_digests('host:CPU')[0]}", "w": 4, "h": 3, "view": {"chart": "hardware", "tokens": "interval", "shown": ["host:CPU"]}}
everything = {"kind": "metric", "id": "combined/accumulated/all", "w": 4, "h": 3, "view": {"chart": "combined", "tokens": "accumulated", "shown": None}}
doc = copy.deepcopy(VIEW)
doc["home"]["pins"] = [metric, everything, PIN]
self.assertEqual(valid_view(copy.deepcopy(doc)), doc)
def view(**changes: object) -> dict:
broken = copy.deepcopy(VIEW)
broken["home"]["pins"] = [{**metric, "view": {**metric["view"], **changes}}]
return broken
bare = copy.deepcopy(VIEW)
bare["home"]["pins"] = [{key: value for key, value in metric.items() if key != "view"}]
task = copy.deepcopy(VIEW)
task["home"]["pins"] = [{**PIN, "view": metric["view"]}]
extra = copy.deepcopy(VIEW)
extra["home"]["pins"] = [{**metric, "view": {**metric["view"], "hidden": []}}]
cases = {
"metric without view": bare,
"view on a panel pin": task,
"unknown view key": extra,
"unknown chart": view(chart="disks"),
"hardware accumulated": view(tokens="accumulated"),
"unknown token mode": view(chart="tokens", tokens="sum"),
"unsorted series": view(shown=["host:RAM", "host:CPU"]),
"series with a space": view(shown=["host CPU"]),
"repeated series": view(shown=["host:CPU", "host:CPU"]),
"101 series": view(shown=sorted(f"s{index:03d}" for index in range(101))),
"series not a list": view(shown="host:CPU"),
}
for name, broken in cases.items():
with self.subTest(case=name), self.assertRaises(ToolError):
valid_view(broken)
def test_sixty_four_pins_of_one_by_one_to_twelve_by_twelve_pass(self):
doc = copy.deepcopy(VIEW)
doc["home"]["pins"] = [{"kind": "panel", "id": f"p{index}", "w": 1 + index % 12, "h": 12 - index % 12} for index in range(64)]