Merge branch 'chore/requirement-test-gaps' into unify/skills-20261112-night
This commit is contained in:
commit
b4a38f02d5
11 files changed
+687
-26
No files matched your search
@@ -0,0 +1,354 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
HERE = Path(__file__).resolve().parent
|
||||
sys.path[:0] = [str(HERE.parent), str(HERE)]
|
||||
|
||||
import test_orchestrator_e2e as base
|
||||
from hub_case import HubCase
|
||||
from hub_support import ASK, iso
|
||||
from kvb_orchestrator import skill_scripts
|
||||
|
||||
OUT = Path(os.environ.get("E2E_OUT", "/tmp/orchestrator-001-gaps-shots"))
|
||||
BANNER = "MAYDAY · Docs: disk full"
|
||||
LOCKED = "kept for the audit"
|
||||
INIT = """() => {
|
||||
window.consoleErrors = [];
|
||||
const original = console.error.bind(console);
|
||||
console.error = (...args) => {
|
||||
window.consoleErrors.push(args.map(String).join(" "));
|
||||
original(...args);
|
||||
};
|
||||
window.addEventListener("error", (event) => window.consoleErrors.push(String(event.message || event.type)));
|
||||
window.addEventListener("unhandledrejection", (event) => window.consoleErrors.push(String(event.reason)));
|
||||
}"""
|
||||
SWEEP = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
await until(() => !(text(document.querySelector("#main .space-note")) || "").startsWith("Loading") && !all("#main .empty h2").some((title) => text(title).endsWith("…")), 8000);
|
||||
await sleep(300);
|
||||
const main = document.getElementById("main");
|
||||
const page = document.scrollingElement;
|
||||
const styles = new Map();
|
||||
const css = (node) => styles.get(node) || styles.set(node, getComputedStyle(node)).get(node);
|
||||
const scrolls = (node) => /(auto|scroll)/.test(css(node).overflowX + css(node).overflowY);
|
||||
const clips = (node) => css(node).overflowX !== "visible" || css(node).overflowY !== "visible";
|
||||
const shown = (node) => {
|
||||
const box = node.getBoundingClientRect();
|
||||
return node.getClientRects().length > 0 && css(node).visibility !== "hidden" && box.width > 1 && box.height > 1 && !node.closest("details:not([open]) > :not(summary)");
|
||||
};
|
||||
const path = (node) => {
|
||||
const parts = [];
|
||||
for (let cur = node; cur && cur !== main && parts.length < 4; cur = cur.parentElement) {
|
||||
parts.unshift(cur.tagName.toLowerCase() + (cur.id ? `#${cur.id}` : "") + [...cur.classList].slice(0, 2).map((cls) => `.${cls}`).join(""));
|
||||
}
|
||||
return parts.join(" > ");
|
||||
};
|
||||
const clipped = (node) => {
|
||||
let {top, bottom, left, right} = node.getBoundingClientRect();
|
||||
let [cur, statics] = [node, false];
|
||||
for (let up = node.parentElement; up && cur !== main; cur = up, up = up.parentElement) {
|
||||
if (css(cur).position === "fixed") {
|
||||
break;
|
||||
}
|
||||
statics = css(cur).position === "absolute" || (statics && css(cur).position === "static");
|
||||
if (statics && css(up).position === "static" && up !== main) {
|
||||
continue;
|
||||
}
|
||||
if (!clips(up)) {
|
||||
continue;
|
||||
}
|
||||
const own = up.getBoundingClientRect();
|
||||
if (scrolls(up)) {
|
||||
if (top - own.top + up.scrollTop < -1 || left - own.left + up.scrollLeft < -1) {
|
||||
return `before the scroll start of ${path(up)}`;
|
||||
}
|
||||
({top, bottom, left, right} = own);
|
||||
continue;
|
||||
}
|
||||
if (css(up).textOverflow === "ellipsis" || css(up).webkitLineClamp !== "none") {
|
||||
return null;
|
||||
}
|
||||
if (top < own.top - 1 || bottom > own.bottom + 1 || left < own.left - 1 || right > own.right + 1) {
|
||||
return `cut by ${path(up)}`;
|
||||
}
|
||||
}
|
||||
return top < -1 || bottom > innerHeight + 1 || left < -1 || right > innerWidth + 1 ? "outside the window" : null;
|
||||
};
|
||||
const nodes = all("#main *").filter((node) => !node.ownerSVGElement && !node.closest("canvas") && shown(node));
|
||||
const cut = nodes.map((node) => [path(node), clipped(node)]).filter(([, why]) => why);
|
||||
const owner = (node) => {
|
||||
for (let up = node.parentElement; up && up !== main; up = up.parentElement) {
|
||||
if (scrolls(up)) {
|
||||
return up;
|
||||
}
|
||||
}
|
||||
return main;
|
||||
};
|
||||
const lasts = new Map();
|
||||
for (const node of nodes) {
|
||||
const box = owner(node);
|
||||
const at = node.getBoundingClientRect().bottom - box.getBoundingClientRect().top + box.scrollTop;
|
||||
if (!lasts.has(box) || at > lasts.get(box)[1]) {
|
||||
lasts.set(box, [node, at]);
|
||||
}
|
||||
}
|
||||
const seen = (node) => {
|
||||
const {bottom} = node.getBoundingClientRect();
|
||||
for (let up = node.parentElement; up && up !== document.body; up = up.parentElement) {
|
||||
if (clips(up) && bottom > up.getBoundingClientRect().bottom + 1) {
|
||||
return `below the end of ${path(up)}`;
|
||||
}
|
||||
}
|
||||
return bottom <= innerHeight + 1 ? null : "below the window";
|
||||
};
|
||||
const kept = [main, ...nodes].filter(scrolls).map((node) => [node, node.scrollTop, node.scrollLeft]);
|
||||
const unreached = [];
|
||||
for (const [box, [node]] of lasts) {
|
||||
node.scrollIntoView({block: "end", inline: "nearest"});
|
||||
await sleep(100);
|
||||
const why = seen(node);
|
||||
if (why) {
|
||||
unreached.push(`${path(box) || "main"} last ${path(node)}: ${why}`);
|
||||
}
|
||||
}
|
||||
const moved = page.scrollTop !== 0 || page.scrollLeft !== 0;
|
||||
kept.forEach(([node, top, left]) => node.scrollTo(left, top));
|
||||
page.scrollTo(0, 0);
|
||||
const banner = document.getElementById("mayday");
|
||||
const expected = [
|
||||
...Nav.TABS.filter(([id]) => !["agents", "artifacts", "tasks"].includes(id)).map(([id]) => Nav.hashOf(id, null)),
|
||||
...Object.values(Nav.SUBS).flat().map(([sub]) => Nav.hashOf(sub, null)),
|
||||
...Object.keys(Nav.PANES).map((pane) => Nav.hashOf(pane, null)),
|
||||
...["agents", "artifacts", "tasks"].flatMap((screen) => Nav.viewsOf(screen).map(([id]) => Nav.hashOf(screen, id))),
|
||||
];
|
||||
return {
|
||||
hash: location.hash, banner: banner.hidden ? null : text(banner),
|
||||
layout: ["pane", "fit"].filter((cls) => document.body.classList.contains(cls)),
|
||||
tall: page.scrollHeight > innerHeight, wide: page.scrollWidth > innerWidth + 1,
|
||||
scrollers: lasts.size, unreached, moved,
|
||||
cut: [...new Set(cut.map(([where, why]) => `${where}: ${why}`))].slice(0, 12), count: cut.length,
|
||||
errors: window.consoleErrors || ["no console recorder"],
|
||||
expected, nav: all("#tabs button[id^='tab-']").map((button) => Nav.hashOf(button.id.slice(4), null)),
|
||||
views: all('#main [aria-label="View"] button').map(name),
|
||||
viewNames: [...new Set(["agents", "artifacts", "tasks"].flatMap((screen) => Nav.viewsOf(screen).map(([, label]) => label)))],
|
||||
};
|
||||
})()"""
|
||||
FILTER = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
const menu = await until(() => all("#main details.menu").find((details) => name(details.querySelector("summary")) === "Filter"), 8000);
|
||||
if (!menu) {
|
||||
return {error: text(document.getElementById("main"))};
|
||||
}
|
||||
const box = menu.querySelector(".menu-box");
|
||||
const groups = () => Object.fromEntries(all(".chips[aria-label]", box).map((group) => [group.getAttribute("aria-label"), all("button, .chip, .muted", group).filter((node) => node.parentElement === group).map(name)]));
|
||||
const outside = ["Kinds", "Transcript parts", "Saved views"].filter((label) => all(`#main [aria-label="${label}"]`).some((node) => !menu.contains(node)));
|
||||
menu.querySelector("summary").click();
|
||||
await sleep(200);
|
||||
const opened = menu.open;
|
||||
const before = groups();
|
||||
document.querySelector('#main [aria-label="Categories"] button[aria-label="Transcripts"]').click();
|
||||
await until(() => all('.chips[aria-label="Transcript parts"] button', box).length, 4000);
|
||||
return {
|
||||
opened, headings: all("h3", box).map(text), before, after: groups(), outside,
|
||||
range: all('input[type="datetime-local"]', box).map((input) => input.getAttribute("aria-label")),
|
||||
tall: document.documentElement.scrollHeight > window.innerHeight, wide: document.documentElement.scrollWidth > window.innerWidth + 1,
|
||||
};
|
||||
})()"""
|
||||
TREE_ICONS = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
const card = await until(() => all("#main details.repo").find((details) => details.textContent.includes("elsewhere")), 8000);
|
||||
if (!card) {
|
||||
return {error: text(document.getElementById("main"))};
|
||||
}
|
||||
const chips = Object.fromEntries(all("#main span.state").map((chip) => [name(chip), [(chip.querySelector("use") || {getAttribute: () => null}).getAttribute("href"), chip.title === chip.getAttribute("aria-label"), chip.getAttribute("role"), text(chip)]]));
|
||||
const row = all("#main .branch-row", card).find((entry) => text(entry.querySelector(".branch-name strong")) === "old/stale");
|
||||
return {chips, stale: row ? all(".branch-name span.state", row).map(name) : null, worktree: row ? all(".wt-head span.state", row).map(name) : null};
|
||||
})()"""
|
||||
MAYDAY = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
window.confirm = () => true;
|
||||
if (!@SIGNS@) {
|
||||
navigator.credentials.get = () => Promise.reject(new DOMException("The operator canceled.", "NotAllowedError"));
|
||||
}
|
||||
const banner = document.getElementById("mayday");
|
||||
const cancel = await until(() => !banner.hidden && banner.querySelector("button"), 8000);
|
||||
if (!cancel) {
|
||||
return {error: "no mayday banner", hidden: banner.hidden};
|
||||
}
|
||||
const tint = document.createElement("i");
|
||||
tint.style.color = "var(--alarm)";
|
||||
document.body.append(tint);
|
||||
const red = getComputedStyle(tint).color;
|
||||
tint.remove();
|
||||
const seen = {text: text(banner.querySelector(".text")), role: banner.getAttribute("role"), red: getComputedStyle(banner).backgroundColor === red,
|
||||
cancel: [cancel.getAttribute("aria-label"), cancel.title, text(cancel), Boolean(cancel.querySelector('use[href="#bi-x-octagon"]'))]};
|
||||
const shown = new Set(all("#toasts .toast"));
|
||||
cancel.click();
|
||||
const done = @SIGNS@ ? await until(() => all("#toasts .toast").filter((node) => !shown.has(node)).map(text).find((line) => line.startsWith("Cancel mayday")), 15000) : (await sleep(1500), null);
|
||||
const hidden = @SIGNS@ ? Boolean(await until(() => banner.hidden, 15000)) : banner.hidden;
|
||||
return {seen, done, hidden, children: banner.children.length};
|
||||
})()"""
|
||||
GONE = """(async () => {@HELPERS@
|
||||
await screenShown(8000);
|
||||
await sleep(600);
|
||||
const banner = document.getElementById("mayday");
|
||||
return {hidden: banner.hidden, display: getComputedStyle(banner).display, children: banner.children.length, alerts: all('[role="alert"]').filter((node) => node.getClientRects().length).length};
|
||||
})()"""
|
||||
|
||||
|
||||
def probe(template: str, signs: bool = False) -> str:
|
||||
return template.replace("@HELPERS@", base.HELPERS).replace("@SIGNS@", "true" if signs else "false")
|
||||
|
||||
|
||||
@unittest.skipUnless(shutil.which(os.environ.get("CHROMIUM", "chromium")), "no Chromium")
|
||||
class TestOrchestratorGaps(HubCase):
|
||||
drive = base.TestOrchestratorE2E.drive
|
||||
authenticator = base.TestOrchestratorE2E.authenticator
|
||||
subagents = base.TestOrchestratorE2E.subagents
|
||||
beside = base.TestOrchestratorE2E.beside
|
||||
|
||||
def setUp(self):
|
||||
super().setUp()
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
now = time.time()
|
||||
root = self.write_tree()
|
||||
data = json.loads(self.tree_file.read_text(encoding="utf-8"))
|
||||
elsewhere = data["repos"][1]
|
||||
lone = next(item for item in elsewhere["items"] if item["branch"] == "lone")
|
||||
stale = {**lone, "branch": "old/stale", "worktree": f"{root}/worktrees/x/y/stale", "locked": LOCKED, "state": "stale", "reason": "stale: no commit for 90 days"}
|
||||
elsewhere["items"].append(stale)
|
||||
self.tree_file.write_text(json.dumps(data), encoding="utf-8")
|
||||
feature = f"{root}/worktrees/github.com/me/demo/feature"
|
||||
self.claim("s1", "Skills session")
|
||||
self.write_council({
|
||||
"work/s2/claim.json": {"office": "work/s2", "session": "s2", "runtime": "claude", "name": "Stage", "since": iso(now - 7200), "beat": now - 2000, "work": "x"},
|
||||
"chair/claim.json": {"office": "chair", "session": "s1", "runtime": "claude", "name": "Skills session", "since": iso(now - 7200), "beat": now, "work": "allocate"},
|
||||
"rasci.json": {
|
||||
"work/feature": {"title": "Show the merge flow in the hub", "status": "running", "worker": "Skills session", "workdir": feature, "prio": 1, "roles": {"Skills session": "RA", "Operator": "C"}},
|
||||
"work/docs": {"title": "Update the README", "status": "blocked", "worker": "Docs", "branch": "main", "roles": {"Docs": "R", "Maintainer": "A"}},
|
||||
"operator/push": {"title": "git push", "workdir": "/repo", "status": "done", "roles": {"Operator": "R"}},
|
||||
},
|
||||
"queue.json": {"seq": 3, "entries": [{"id": "gate-3", "kind": "gate", "task": "work/feature", "workdir": feature, "session": "s1", "name": "Skills", "status": "waiting", "enqueued": now - 120, "cmd": "make test"}]},
|
||||
"radio-silence.json": {"since": now - 60, "until": now + 3600, "by": "Docs", "text": "disk full"},
|
||||
"news.jsonl": self.jsonl([
|
||||
{"ts": now - 600, "from": "Skills", "to": ["Stage"], "text": "rebase please", "class": "post", "v": 2},
|
||||
{"ts": now - 500, "from": "Stage", "to": ["Skills"], "text": "gate red", "class": "call", "v": 2},
|
||||
{"ts": now - 400, "from": "Maintainer", "to": [], "text": "main is green", "class": "newsletter", "v": 2},
|
||||
{"ts": now - 60, "from": "Docs", "to": [], "text": "MAYDAY disk full", "class": "mayday", "v": 2},
|
||||
]),
|
||||
})
|
||||
self.subagents(now)
|
||||
self.request("feat: orchestrator", "")
|
||||
self.create_ask({**ASK, "timeout": 3600})
|
||||
self.base = f"http://localhost:{self.port}/"
|
||||
|
||||
def steps(self, browser: str, signs: bool) -> list[dict]:
|
||||
steps = [
|
||||
{"width": width, "height": height, "url": f"{self.base}?sweep-{width}-{screen.replace('/', '-')}#{screen}", "wait": 900, "probe": probe(SWEEP), "shot": str(OUT / f"{browser}-{width}-sweep-{screen.replace('/', '-')}.png")}
|
||||
for width, height in base.WIDTHS
|
||||
for screen in base.SCREENS
|
||||
]
|
||||
for width, height in base.WIDTHS:
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?{width}-filter#stream", "wait": 900, "probe": probe(FILTER), "shot": str(OUT / f"{browser}-{width}-filter.png")})
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?{width}-icons#artifacts/tree", "wait": 900, "probe": probe(TREE_ICONS), "shot": str(OUT / f"{browser}-{width}-tree-icons.png")})
|
||||
(width, height), *rest = base.WIDTHS
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?{width}-mayday#stream", "wait": 900, "probe": probe(MAYDAY, signs), "shot": str(OUT / f"{browser}-{width}-mayday.png")})
|
||||
if signs:
|
||||
steps += [{"width": width, "height": height, "url": f"{self.base}?{width}-gone#{screen}", "wait": 900, "probe": probe(GONE), "shot": str(OUT / f"{browser}-{width}-no-mayday.png")} for (width, height), screen in zip(rest, ("agents/orbit", "artifacts/tree"), strict=True)]
|
||||
return steps
|
||||
|
||||
def check(self, data: dict, signs: bool) -> None:
|
||||
walked = len(base.WIDTHS) * len(base.SCREENS)
|
||||
screens = [screen for _ in base.WIDTHS for screen in base.SCREENS]
|
||||
widths = [width for width, _ in base.WIDTHS for _ in base.SCREENS]
|
||||
sweep = data["results"][:walked]
|
||||
with self.subTest(part="every screen and view"):
|
||||
self.assertNotIn("error", sweep[0], sweep[0])
|
||||
self.assertEqual(sorted(sweep[0]["expected"]), sorted(f"#{screen}" for screen in base.SCREENS))
|
||||
self.assertEqual([target for target in sweep[0]["nav"] if not any(f"#{screen}" == target or f"#{screen}".startswith(f"{target}/") for screen in base.SCREENS)], [])
|
||||
self.assertEqual(sorted({view for found in sweep for view in found["views"]}), sorted(sweep[0]["viewNames"]))
|
||||
for found, screen, width in zip(sweep, screens, widths, strict=True):
|
||||
with self.subTest(screen=screen, width=width):
|
||||
self.assertNotIn("error", found, found)
|
||||
self.assertEqual((found["hash"], found["banner"]), (f"#{screen}", BANNER))
|
||||
self.assertEqual(len(found["layout"]), 1, found["layout"])
|
||||
self.assertEqual((found["tall"], found["wide"], found["moved"]), (False, False, False), "the page scrolls")
|
||||
self.assertEqual(found["unreached"], [], "a scroller cannot show its last child")
|
||||
self.assertEqual((found["count"], found["cut"]), (0, []), "an element sits outside every scroller")
|
||||
self.assertEqual(found["errors"], [], "console error")
|
||||
extra = iter(data["results"][walked:])
|
||||
for width, _ in base.WIDTHS:
|
||||
menu, icons = next(extra), next(extra)
|
||||
with self.subTest(width=width, part="filter"):
|
||||
self.assertNotIn("error", menu, menu)
|
||||
self.assertEqual((menu["opened"], menu["headings"], menu["outside"], menu["range"]), (True, ["Kinds", "Transcript parts", "Saved views", "Custom time range"], [], ["From", "To"]))
|
||||
kinds = ["only waiting", *self.snapshot()["kinds"].values()]
|
||||
self.assertEqual(menu["before"], {"Kinds": kinds, "Transcript parts": ["Only with the kind Transcripts."], "Saved views": ["Save view"]})
|
||||
self.assertEqual(menu["after"]["Transcript parts"], ["User", "Assistant", "Tool call", "Tool result", "System"])
|
||||
self.assertEqual((menu["tall"], menu["wide"]), (False, False))
|
||||
with self.subTest(width=width, part="tree icons"):
|
||||
self.assertNotIn("error", icons, icons)
|
||||
chips = icons["chips"]
|
||||
expected = {
|
||||
"merged by #12 into main": "#bi-sign-merge-left", "clean": "#bi-check-circle", "not committed: 0 staged, 0 changed, 1 new": "#bi-pencil-square", "1 commits unpushed": "#bi-cloud-upload",
|
||||
"upstream gone": "#bi-cloud-slash", f"locked: {LOCKED}": "#bi-lock-fill", "stale": "#bi-hourglass-bottom", "protected": "#bi-shield-lock",
|
||||
}
|
||||
for label, href in expected.items():
|
||||
with self.subTest(label=label):
|
||||
self.assertIn(label, chips, sorted(chips))
|
||||
self.assertEqual(chips[label][:3], [href, True, "img"])
|
||||
self.assertEqual((chips["1 commits unpushed"][3], chips["not committed: 0 staged, 0 changed, 1 new"][3]), ("1", "1"))
|
||||
self.assertIn("stale", icons["stale"])
|
||||
self.assertEqual(icons["worktree"], ["clean", f"locked: {LOCKED}"])
|
||||
mayday, gone = next(extra), list(extra)
|
||||
clear = (skill_scripts.RADIO, ["clear", "--force", "--session", "Operator"])
|
||||
with self.subTest(part="mayday"):
|
||||
self.assertNotIn("error", mayday, mayday)
|
||||
self.assertEqual(mayday["seen"], {"text": BANNER, "role": "alert", "red": True, "cancel": ["cancel", "cancel: end the mayday (radio.py clear)", "", True]})
|
||||
if signs:
|
||||
self.assertTrue((mayday["done"] or "").startswith("Cancel mayday: done"), mayday)
|
||||
self.assertEqual((mayday["hidden"], mayday["children"]), (True, 0))
|
||||
self.assertEqual(self.scripts.calls.count(clear), 1)
|
||||
else:
|
||||
self.assertEqual((mayday["hidden"], mayday["children"]), (False, 2))
|
||||
self.assertNotIn(clear, self.scripts.calls)
|
||||
with self.subTest(part="no mayday"):
|
||||
self.assertEqual(gone, [{"hidden": True, "display": "none", "children": 0, "alerts": 0}] * (len(base.WIDTHS) - 1 if signs else 0))
|
||||
|
||||
def lift(self) -> None:
|
||||
handled = []
|
||||
|
||||
def answer() -> None:
|
||||
for script, args in self.scripts.calls[len(handled) :]:
|
||||
handled.append(script)
|
||||
if script == skill_scripts.RADIO and args[:1] == ["clear"]:
|
||||
(self.council / "radio-silence.json").unlink(missing_ok=True)
|
||||
|
||||
self.beside(answer)
|
||||
|
||||
def test_chromium_fits_every_screen_fills_the_filter_menu_marks_locked_and_stale_and_shows_the_mayday_banner_only_until_its_cancel_clears_it(self):
|
||||
self.lift()
|
||||
data = self.drive(self.steps("chromium", True), self.authenticator(), init=INIT)
|
||||
(OUT / "chromium-gaps.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
self.assertEqual(data["errors"], [])
|
||||
self.check(data, True)
|
||||
|
||||
@unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox")
|
||||
def test_firefox_fits_every_screen_fills_the_filter_menu_marks_locked_and_stale_and_keeps_the_mayday_without_a_signature(self):
|
||||
data = self.drive(self.steps("firefox", False), None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"), INIT)
|
||||
(OUT / "firefox-gaps.json").write_text(json.dumps(data, indent=1), encoding="utf-8")
|
||||
blocked = [error for error in data["errors"] if error.startswith("Content-Security-Policy")]
|
||||
self.assertEqual([error for error in data["errors"] if error not in blocked and "/favicon.ico" not in error], [])
|
||||
self.assertEqual([error for error in blocked if "(style-src-elem)" not in error and "/favicon.ico" not in error], [])
|
||||
self.check(data, False)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -20,6 +20,10 @@ OUT = Path(os.environ.get("E2E_OUT", "/tmp/workbench-w6-shots"))
|
||||
CUE = "e2e-bubbles"
|
||||
FIRST = "Disk almost full on the build host, the gate waits for space now"
|
||||
SECOND = "Gate green for the merge"
|
||||
LONG = (
|
||||
"Reconfiguration of the infrastructure monitoring dashboards requires acknowledgement from administrators before synchronization across distributed environments, "
|
||||
"otherwise notifications accumulate indefinitely throughout overnight maintenance windows affecting availability measurements considerably and delaying deployments"
|
||||
)
|
||||
READING = max(1.5, len(FIRST.split()) * 60 / 180)
|
||||
EARLY = 0.1
|
||||
LATE = 2.0
|
||||
@@ -27,6 +31,8 @@ VIEWS = {1920: "agents/orbit", 1366: "stream/radio", 390: "agents/hierarchy"}
|
||||
SECOND_FROM = {1920: "Skills", 1366: "Skills", 390: "Docs"}
|
||||
SECOND_ANCHORED = {1920: True, 1366: False, 390: False}
|
||||
CALM = [{"name": "prefers-reduced-motion", "value": "reduce"}]
|
||||
FADE_MS = 400
|
||||
FADE_SLACK = 50
|
||||
GUARD = """() => {
|
||||
window.e2eViolations = [];
|
||||
document.addEventListener("securitypolicyviolation", (event) => window.e2eViolations.push(`${event.violatedDirective} ${event.blockedURI}`));
|
||||
@@ -38,18 +44,30 @@ READ = """
|
||||
const live = () => all(".speech-bubble:not(.leaving)", layer);
|
||||
const speaking = () => live().find((node) => node.dataset.state === "speaking") || null;
|
||||
const waiting = () => live().find((node) => node.dataset.state === "waiting") || null;
|
||||
const visible = (box) => box.width > 0 && box.height > 0 && box.right > 0 && box.bottom > 0 && box.left < innerWidth && box.top < innerHeight;
|
||||
const face = (who) => [...document.querySelectorAll(`[data-face="${CSS.escape(who)}"]`)].map((node) => node.getBoundingClientRect()).find(visible) || null;
|
||||
const read = (node) => {
|
||||
if (!node) {
|
||||
return null;
|
||||
}
|
||||
const style = getComputedStyle(node);
|
||||
const box = node.getBoundingClientRect();
|
||||
const scale = new DOMMatrix(style.transform).a;
|
||||
const anchor = face(node.dataset.who);
|
||||
return {
|
||||
who: node.dataset.who, scale: Number(node.dataset.scale), state: node.dataset.state, words: Number(node.dataset.words), text: text(node.querySelector(".bubble-words")),
|
||||
anchored: node.parentElement === layer, rendered: Math.round(new DOMMatrix(style.transform).a * 100) / 100, transition: style.transitionProperty, font: style.fontFamily,
|
||||
anchored: node.parentElement === layer, rendered: Math.round(scale * 100) / 100, transition: style.transitionProperty, font: style.fontFamily,
|
||||
box: {left: box.left, top: box.top, right: box.right, bottom: box.bottom},
|
||||
aim: {tip: (box.left + box.right) / 2 + (parseFloat(node.style.getPropertyValue("--tail")) || 0) * scale, bottom: box.bottom, height: box.bottom - box.top,
|
||||
mid: anchor ? anchor.left + anchor.width / 2 : null, top: anchor ? anchor.top : null},
|
||||
bar: node.parentElement.classList.contains("bubble-bar"),
|
||||
};
|
||||
};
|
||||
const frame = () => {
|
||||
const css = getComputedStyle(layer);
|
||||
const bar = layer.querySelector(".bubble-bar").getBoundingClientRect();
|
||||
return {position: css.position, events: css.pointerEvents, bar: Math.round(innerHeight - bar.bottom)};
|
||||
};
|
||||
const cue = (word) => fetch("/api/tts", {method: "POST", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": "application/json"}, body: JSON.stringify({text: word, voice: ""}), cache: "no-store"});
|
||||
"""
|
||||
BUBBLES_ON = """(async () => {@HELPERS@@READ@
|
||||
@@ -59,10 +77,29 @@ BUBBLES_ON = """(async () => {@HELPERS@@READ@
|
||||
t: performance.now(), who: node.dataset.who, state: node.dataset.state || null, words: Number(node.dataset.words || 0),
|
||||
leaving: node.classList.contains("leaving"), read: node.dataset.read === undefined ? null : Number(node.dataset.read), removed: !node.isConnected,
|
||||
});
|
||||
window.e2eFades = [];
|
||||
const watched = new Map();
|
||||
const fading = (node) => {
|
||||
const css = getComputedStyle(node);
|
||||
const times = css.transitionDuration.split(", ");
|
||||
const fade = {who: node.dataset.who, removed: null, reference: null, seconds: parseFloat(times[css.transitionProperty.split(", ").indexOf("opacity")] ?? "NaN"), start: performance.now()};
|
||||
watched.set(node, fade);
|
||||
window.setTimeout(() => {
|
||||
fade.reference = Math.round(performance.now() - fade.start);
|
||||
}, @FADE@);
|
||||
window.e2eFades.push(fade);
|
||||
};
|
||||
new MutationObserver((records) => {
|
||||
for (const record of records) {
|
||||
const gone = [...record.removedNodes].filter((node) => node instanceof Element && node.matches(".speech-bubble") && !node.isConnected);
|
||||
[...(record.type === "attributes" && record.target.matches(".speech-bubble") ? [record.target] : []), ...gone].forEach(note);
|
||||
if (record.type === "attributes" && record.target.matches(".speech-bubble.leaving") && !watched.has(record.target)) {
|
||||
fading(record.target);
|
||||
}
|
||||
gone.filter((node) => watched.has(node)).forEach((node) => {
|
||||
const fade = watched.get(node);
|
||||
fade.removed = Math.round(performance.now() - fade.start);
|
||||
});
|
||||
}
|
||||
}).observe(layer, {subtree: true, childList: true, attributes: true, attributeFilter: ["class", "data-state", "data-words", "data-read"]});
|
||||
toggle.click();
|
||||
@@ -72,7 +109,7 @@ BUBBLES_ON = """(async () => {@HELPERS@@READ@
|
||||
return {before, on, error: "no pair of bubbles", bubbles: live().map(read), toasts: all("#toasts .toast").map(text)};
|
||||
}
|
||||
await sleep(400);
|
||||
return {before, on, first: read(speaking()), second: read(waiting())};
|
||||
return {before, on, first: read(speaking()), second: read(waiting()), layer: frame()};
|
||||
})()"""
|
||||
BUBBLES_GROW = """(async () => {@HELPERS@@READ@
|
||||
const log = window.e2eBubbleLog || [];
|
||||
@@ -84,7 +121,9 @@ BUBBLES_GROW = """(async () => {@HELPERS@@READ@
|
||||
await Promise.all((speaking() ? speaking().getAnimations() : []).map((animation) => animation.finished.catch(() => null)));
|
||||
grown = read(speaking());
|
||||
await until(() => mine().some((entry) => entry.removed), 4000);
|
||||
await until(() => (window.e2eFades || []).some((entry) => entry.who === who && entry.removed !== null && entry.reference !== null), 2000);
|
||||
}
|
||||
const fading = (window.e2eFades || []).find((entry) => entry.who === who) || null;
|
||||
const entries = mine();
|
||||
const fade = entries.findIndex((entry) => entry.leaving);
|
||||
const reading = entries.slice(0, fade < 0 ? entries.length : fade).filter((entry) => entry.state === "speaking").map((entry) => entry.words);
|
||||
@@ -92,7 +131,7 @@ BUBBLES_GROW = """(async () => {@HELPERS@@READ@
|
||||
return {
|
||||
who, words: reading.filter((value, index) => value !== reading[index - 1]), read: left ? left.read : null,
|
||||
seconds: start && left ? Math.round(left.t - start.t) / 1000 : null,
|
||||
faded: fade > 0 && entries.slice(fade).every((entry) => entry.leaving), gone: entries.some((entry) => entry.removed), grown,
|
||||
faded: fade > 0 && entries.slice(fade).every((entry) => entry.leaving), gone: entries.some((entry) => entry.removed), grown, fading,
|
||||
};
|
||||
})()"""
|
||||
BUBBLES_DONE = """(async () => {@HELPERS@@READ@
|
||||
@@ -100,6 +139,28 @@ BUBBLES_DONE = """(async () => {@HELPERS@@READ@
|
||||
const faces = [...document.fonts].filter((face) => face.family.replace(/["']/g, "") === "Comic Neue").map((face) => face.status);
|
||||
return {cleared, faces, hidden: layer.hidden, violations: window.e2eViolations || null};
|
||||
})()"""
|
||||
BUBBLES_LONG = """(async () => {@HELPERS@@READ@
|
||||
await cue("@CUE@-long");
|
||||
const node = await until(() => live().find((entry) => entry.dataset.state === "speaking" && text(entry.querySelector(".bubble-words")).startsWith("Reconfiguration")), 25000);
|
||||
if (!node) {
|
||||
return {error: "no long bubble", bubbles: live().map(read)};
|
||||
}
|
||||
const words = node.querySelector(".bubble-words");
|
||||
const line = parseFloat(getComputedStyle(words).lineHeight);
|
||||
const samples = [];
|
||||
const end = Date.now() + 30000;
|
||||
while (node.isConnected && Date.now() < end) {
|
||||
samples.push({top: words.scrollTop, client: words.clientHeight, full: words.scrollHeight, count: Number(node.dataset.words), text: text(words)});
|
||||
await sleep(40);
|
||||
}
|
||||
const total = Math.max(...samples.map((sample) => sample.count));
|
||||
const final = samples.filter((sample) => sample.count === total);
|
||||
return {
|
||||
text: final.length ? final.at(-1).text : null, lines: Math.max(...samples.map((sample) => sample.client)) / line,
|
||||
overflow: samples.some((sample) => sample.full > sample.client + line / 2), scrolled: samples.some((sample) => sample.top > 0),
|
||||
gap: final.length ? Math.min(...final.map((sample) => sample.full - sample.client - sample.top)) : null, gone: !node.isConnected,
|
||||
};
|
||||
})()"""
|
||||
BUBBLES_3D = """(async () => {@HELPERS@@READ@
|
||||
const canvas = Boolean(await until(() => document.querySelector("#main .graph3d canvas"), 15000));
|
||||
await until(() => {
|
||||
@@ -115,9 +176,21 @@ BUBBLES_3D = """(async () => {@HELPERS@@READ@
|
||||
if (!(await until(speaking, 25000))) {
|
||||
return {canvas, error: "no bubble in 3D", bubbles: live().map(read)};
|
||||
}
|
||||
const first = read(speaking());
|
||||
await sleep(500);
|
||||
const later = read(speaking());
|
||||
const scene = (window.e2eGraphs || []).at(-1);
|
||||
const track = async () => {
|
||||
await new Promise((done) => requestAnimationFrame(() => requestAnimationFrame(done)));
|
||||
const node = speaking();
|
||||
const found = read(node);
|
||||
const entry = scene.graphData().nodes.find((item) => item.id === node.dataset.who);
|
||||
const box = document.querySelector("#main .graph3d").getBoundingClientRect();
|
||||
const at = entry ? scene.graph2ScreenCoords(entry.x, entry.y, entry.z) : null;
|
||||
return {...found, projected: at ? {x: box.left + at.x, y: box.top + at.y} : null};
|
||||
};
|
||||
const first = await track();
|
||||
const camera = scene.cameraPosition();
|
||||
scene.cameraPosition({x: camera.z, y: camera.y, z: -camera.x});
|
||||
await sleep(300);
|
||||
const later = await track();
|
||||
const graph = document.querySelector("#main .graph3d").getBoundingClientRect();
|
||||
return {canvas, first, later, graph: {left: graph.left, top: graph.top, right: graph.right, bottom: graph.bottom}, mode: text(document.querySelector("#main .space-note"))};
|
||||
})()"""
|
||||
@@ -131,7 +204,7 @@ BUBBLES_KEPT = """(async () => {@HELPERS@@READ@
|
||||
|
||||
|
||||
def probe(template: str, cue: str = CUE) -> str:
|
||||
return template.replace("@HELPERS@", base.HELPERS).replace("@READ@", READ).replace("@CUE@", cue)
|
||||
return template.replace("@HELPERS@", base.HELPERS).replace("@READ@", READ).replace("@CUE@", cue).replace("@FADE@", str(FADE_MS))
|
||||
|
||||
|
||||
def quiet(found: dict) -> dict:
|
||||
@@ -162,7 +235,10 @@ class TestWorkbenchBubbles(HubCase):
|
||||
|
||||
def synthesize(body: bytes) -> bytes:
|
||||
word = json.loads(body)["text"]
|
||||
if word.startswith(CUE):
|
||||
if word == f"{CUE}-long":
|
||||
with (self.council / "news.jsonl").open("a", encoding="utf-8") as handle:
|
||||
handle.write(self.jsonl([{"ts": time.time(), "from": "Stage", "to": [], "text": LONG, "class": "security", "v": 2}]))
|
||||
elif word.startswith(CUE):
|
||||
now = time.time()
|
||||
rows = [
|
||||
{"ts": now - 0.01, "from": "Stage", "to": [], "text": FIRST, "class": "security", "v": 2},
|
||||
@@ -189,18 +265,66 @@ class TestWorkbenchBubbles(HubCase):
|
||||
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(BUBBLES_GROW), "shot": f"{shot}-grown.png", "media": media},
|
||||
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(BUBBLES_DONE), "shot": None, "media": media},
|
||||
]
|
||||
if width == 1366:
|
||||
steps.append({"width": width, "height": height, "url": None, "wait": 0, "probe": probe(BUBBLES_LONG), "shot": None, "media": media})
|
||||
if three and width == 1366:
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?3d#agents/3d", "wait": 1500, "probe": probe(BUBBLES_3D), "shot": f"{shot}-3d.png"})
|
||||
steps.append({"width": width, "height": height, "url": f"{self.base}?{width}-reloaded#{view}", "wait": 1200, "probe": probe(BUBBLES_KEPT), "shot": f"{shot}-off.png", "media": media})
|
||||
if width == 1366:
|
||||
steps += [
|
||||
{"width": width, "height": height, "url": f"{self.base}?{width}-stream#stream", "wait": 1200, "probe": probe(BUBBLES_ON), "shot": f"{shot}-stream.png", "media": media},
|
||||
{"width": width, "height": height, "url": None, "wait": 0, "probe": probe(BUBBLES_DONE), "shot": None, "media": media},
|
||||
{"width": width, "height": height, "url": f"{self.base}?{width}-stream-reloaded#stream", "wait": 1200, "probe": probe(BUBBLES_KEPT), "shot": None, "media": media},
|
||||
]
|
||||
return steps
|
||||
|
||||
def aimed(self, found: dict, anchor: tuple[float, float] | None = None) -> None:
|
||||
aim = found["aim"]
|
||||
mid, top = anchor or (aim["mid"], aim["top"])
|
||||
self.assertIsNotNone(mid, found)
|
||||
self.assertAlmostEqual(aim["tip"], mid, delta=4, msg=found)
|
||||
self.assertAlmostEqual(aim["bottom"], max(top - 4, 8 + aim["height"]), delta=4, msg=found)
|
||||
|
||||
def check(self, data: dict, browser: str, calm: bool, three: bool) -> None:
|
||||
results = iter(data["results"])
|
||||
for width, _ in base.WIDTHS:
|
||||
on, grow, done = next(results), next(results), next(results)
|
||||
long = next(results) if width == 1366 else None
|
||||
solid = next(results) if three and width == 1366 else None
|
||||
kept = next(results)
|
||||
stream = [next(results), next(results), next(results)] if width == 1366 else None
|
||||
first_key, second_key = self.keys["Stage"], self.keys[SECOND_FROM[width]]
|
||||
with self.subTest(browser=browser, width=width, part="anchor"):
|
||||
self.assertNotIn("error", on, on)
|
||||
self.assertEqual(on["layer"]["position"], "fixed")
|
||||
self.assertEqual(on["layer"]["events"], "none")
|
||||
self.assertTrue(0 <= on["layer"]["bar"] <= 48, on["layer"])
|
||||
self.aimed(on["first"])
|
||||
if SECOND_ANCHORED[width]:
|
||||
self.aimed(on["second"])
|
||||
else:
|
||||
self.assertEqual((on["second"]["bar"], on["second"]["aim"]["mid"]), (True, None), on["second"])
|
||||
with self.subTest(browser=browser, width=width, part="fade"):
|
||||
fading = grow["fading"]
|
||||
self.assertIsNotNone(fading, grow)
|
||||
self.assertIsNotNone(fading["reference"], fading)
|
||||
self.assertIsNotNone(fading["removed"], fading)
|
||||
self.assertTrue(0 <= fading["seconds"] <= FADE_MS / 1000 and (fading["seconds"] > 0 or (calm and width == 390)), fading)
|
||||
self.assertLessEqual(fading["removed"], fading["reference"] + FADE_SLACK, fading)
|
||||
if stream is not None:
|
||||
with self.subTest(browser=browser, width=width, view="stream"):
|
||||
shown, cleared, switched = stream
|
||||
self.assertNotIn("error", shown, shown)
|
||||
self.assertEqual((shown["before"], shown["on"]), (["false", True], True))
|
||||
self.assertEqual((shown["first"]["who"], shown["first"]["scale"], shown["first"]["state"]), (first_key, 1, "speaking"), shown)
|
||||
self.assertEqual((shown["second"]["scale"], shown["second"]["state"]), (0.8, "waiting"), shown)
|
||||
for found in (shown["first"], shown["second"]):
|
||||
if found["aim"]["mid"] is None:
|
||||
self.assertEqual((found["anchored"], found["bar"]), (False, True), found)
|
||||
else:
|
||||
self.aimed(found)
|
||||
self.assertTrue(quiet(cleared)["cleared"], cleared)
|
||||
self.assertEqual(quiet(switched), {"kept": ["true", False, "Speech bubbles", "Speech bubbles"], "off": True, "display": "none", "bubbles": 0, "violations": []})
|
||||
with self.subTest(browser=browser, width=width):
|
||||
self.assertNotIn("error", on, on)
|
||||
self.assertEqual((on["before"], on["on"]), (["false", True], True))
|
||||
@@ -224,6 +348,12 @@ class TestWorkbenchBubbles(HubCase):
|
||||
self.assertEqual(grown["text"], " ".join(SECOND.split()[: grown["words"]]))
|
||||
self.assertEqual(quiet(done), {"cleared": True, "faces": ["loaded"], "hidden": False, "violations": []})
|
||||
self.assertEqual(quiet(kept), {"kept": ["true", False, "Speech bubbles", "Speech bubbles"], "off": True, "display": "none", "bubbles": 0, "violations": []})
|
||||
if long is not None:
|
||||
with self.subTest(browser=browser, width=width, bubble="long"):
|
||||
self.assertNotIn("error", long, long)
|
||||
self.assertEqual((long["text"], long["overflow"], long["scrolled"], long["gone"]), (LONG, True, True, True), long)
|
||||
self.assertTrue(5.5 < long["lines"] <= 6.05, long)
|
||||
self.assertLessEqual(long["gap"], 2, long)
|
||||
if solid is not None:
|
||||
with self.subTest(browser=browser, view="3d"):
|
||||
self.assertNotIn("error", solid, solid)
|
||||
@@ -232,6 +362,10 @@ class TestWorkbenchBubbles(HubCase):
|
||||
self.assertEqual((read["who"], read["anchored"]), (first_key, True), solid)
|
||||
middle = (read["box"]["left"] + read["box"]["right"]) / 2
|
||||
self.assertTrue(graph["left"] <= middle <= graph["right"] and graph["top"] - 16 <= read["box"]["bottom"] <= graph["bottom"], solid)
|
||||
self.assertIsNotNone(read["projected"], solid)
|
||||
self.aimed(read, (read["projected"]["x"], read["projected"]["y"] - 8))
|
||||
moved = solid["later"]["projected"], solid["first"]["projected"]
|
||||
self.assertGreater(abs(moved[0]["x"] - moved[1]["x"]) + abs(moved[0]["y"] - moved[1]["y"]), 20, solid)
|
||||
self.assertFalse(self.httpd.hub.settings.get()["bubbles"])
|
||||
|
||||
def test_chromium_reads_two_rows_without_tts_as_growing_bubbles_keeps_the_switch_and_hides_the_layer_at_three_widths(self):
|
||||
|
||||
Reference in new issue
Block a user