From 53a69daeaf171b31ac71712e75e20b2d1d0887f4 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 17 Nov 2026 09:57:26 +0000 Subject: [PATCH] test(e2e): close the radio, bubbles and score overlay gaps MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The station popover check asserts the side it opens to against the room above and below the fold and its 12 rem cap; the radio log tile is 8 x 4 as 004 requires, with 88 px Home rows at 640 px so it shows its rows; the live bubbles probe turns bubbles on only when they are off, since the setting is kept on the server; a new score overlay e2e draws the token, CPU and RAM overlays from fixture tasks on the master branch. 🎯 Fix: 93 % 💥 Break: 3 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % (style-home.css not covered by MEDUSA, reviewed by hand) 🏆 Score: 90 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 --- orchestrator/templates/style-home.css | 1 + tests/e2e/radio_layout_focus_probes.py | 11 +- tests/e2e/radio_layout_kit.py | 2 +- tests/e2e/test_hub_bubbles_live_e2e.py | 22 +++- tests/e2e/test_radio_focus_e2e.py | 11 ++ tests/e2e/test_score_overlays_e2e.py | 174 +++++++++++++++++++++++++ 6 files changed, 212 insertions(+), 9 deletions(-) create mode 100644 tests/e2e/test_score_overlays_e2e.py diff --git a/orchestrator/templates/style-home.css b/orchestrator/templates/style-home.css index d434180..9178aca 100644 --- a/orchestrator/templates/style-home.css +++ b/orchestrator/templates/style-home.css @@ -30,6 +30,7 @@ .home-inbox .msg-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); } .leaf > .star-row { order: 1; margin-inline-start: auto; } @media (max-width: 640px) { + .home-grid { grid-auto-rows: 88px; } .home-tile { grid-column: 1 / -1; } .legend[data-star-slot] > .star { order: 1; } .legend[data-star-slot] > .muted { order: 2; } diff --git a/tests/e2e/radio_layout_focus_probes.py b/tests/e2e/radio_layout_focus_probes.py index e6aadb1..75e89e9 100644 --- a/tests/e2e/radio_layout_focus_probes.py +++ b/tests/e2e/radio_layout_focus_probes.py @@ -39,7 +39,16 @@ POP = """(async () => {@HELPERS@@PROBES@ summary.click(); await sleep(300); const whole = all(".station", layer).filter((row) => box(row).top >= box(layer).top - 1 && box(row).bottom <= box(layer).bottom + 1).length; - const opened = {open: fold.open, side: fold.dataset.side, height: Math.round(box(layer).height), outside: outside(layer), whole}; + const cap = Math.min(12 * parseFloat(getComputedStyle(document.documentElement).fontSize), 0.28 * innerHeight); + let [top, bottom] = [0, innerHeight]; + for (let node = fold.parentElement; node && node !== document.documentElement; node = node.parentElement) { + const look = getComputedStyle(node); + if (look.overflowX !== "visible" || look.overflowY !== "visible") { + [top, bottom] = [Math.max(top, box(node).top), Math.min(bottom, box(node).bottom)]; + } + } + const room = {above: Math.floor(box(fold).top - top), below: Math.floor(bottom - box(fold).bottom), need: Math.floor(Math.min(layer.scrollHeight + layer.offsetHeight - layer.clientHeight, cap))}; + const opened = {open: fold.open, side: fold.dataset.side, height: Math.round(box(layer).height), cap: Math.ceil(cap), ...room, outside: outside(layer), whole}; layer.querySelector(".station button").focus(); document.activeElement.dispatchEvent(new KeyboardEvent("keydown", {key: "Escape", bubbles: true})); await sleep(200); diff --git a/tests/e2e/radio_layout_kit.py b/tests/e2e/radio_layout_kit.py index a0f9774..03afb3a 100644 --- a/tests/e2e/radio_layout_kit.py +++ b/tests/e2e/radio_layout_kit.py @@ -44,7 +44,7 @@ HOME_RADIO = [{"kind": "panel", "id": "radio-device", "w": 6, "h": 6}, {"kind": STREAMS = [{"name": f"Station {index}", "url": f"https://radio.example/{index}.mp3", "from": "00:00", "to": "24:00", "days": list(range(7)), "on": False, "via": []} for index in (1, 2, 3)] PARTS = ["radio", "radio-device", "radio-speak", "radio-log"] DEFAULTS = {"radio": [12, 7], "radio-device": [6, 6], "radio-speak": [6, 5], "radio-log": [6, 5]} -SIZES = {"radio": [12, 9], "radio-device": [5, 7], "radio-speak": [7, 6], "radio-log": [8, 6]} +SIZES = {"radio": [12, 9], "radio-device": [5, 7], "radio-speak": [7, 6], "radio-log": [8, 4]} LISTED = {"radio-log"} SCROLLER = {"radio": "radio-log", "radio-device": None, "radio-speak": None, "radio-log": "radio-log"} PROBES = """ diff --git a/tests/e2e/test_hub_bubbles_live_e2e.py b/tests/e2e/test_hub_bubbles_live_e2e.py index 9f377af..25d9c48 100644 --- a/tests/e2e/test_hub_bubbles_live_e2e.py +++ b/tests/e2e/test_hub_bubbles_live_e2e.py @@ -52,8 +52,10 @@ PROBE = """(async () => {@HELPERS@ const poll = () => window.dispatchEvent(new Event("focus")); const cleared = () => until(() => !layer.querySelector(".speech-bubble"), 30000); document.dispatchEvent(new PointerEvent("pointerdown", {bubbles: true})); - toggle.click(); - const on = Boolean(await until(() => toggle.getAttribute("aria-pressed") === "true" && !layer.hidden, 8000)); + if (toggle.getAttribute("aria-pressed") !== "true") { + toggle.click(); + } + const on =Boolean(await until(() => toggle.getAttribute("aria-pressed") === "true" && !layer.hidden, 8000)); await sleep(1500); poll(); await sleep(3000); @@ -204,18 +206,24 @@ class TestLiveBubbles(HubCase): ) return [ { - "width": 1366, - "height": 768, - "url": f"{self.base}#stream", + "width": width, + "height": height, + "url": f"{self.base}?{width}#stream", "wait": 1200, "probe": probe, - "shot": str(OUT / f"{browser}-1366-live-bubbles.png"), + "shot": str(OUT / f"{browser}-{width}-live-bubbles.png"), "gesture": True, } + for width, height in base.WIDTHS ] def check(self, data: dict) -> None: - found = data["results"][0] + self.assertEqual(len(data["results"]), len(base.WIDTHS), data) + for (width, _), found in zip(base.WIDTHS, data["results"], strict=True): + with self.subTest(width=width): + self.check_width(found) + + def check_width(self, found: dict) -> None: self.assertNotIn("error", found, found) self.assertTrue(found["on"], found) self.assertEqual( diff --git a/tests/e2e/test_radio_focus_e2e.py b/tests/e2e/test_radio_focus_e2e.py index 1fb73d1..a5d835a 100644 --- a/tests/e2e/test_radio_focus_e2e.py +++ b/tests/e2e/test_radio_focus_e2e.py @@ -44,6 +44,16 @@ class TestRadioFocus(kit.RadioLayoutCase): "probe": probe(POP.replace("@VIEW@", view).replace("@PINS@", pins).replace("@ROOTS@", roots).replace("@SPOT@", spot)), "shot": str(OUT / f"{browser}-{width}-pop-{name}.png")} for width, height in POPOVER_SIZES for name, view, pins, roots, spot in places] + def check_side(self, opened: dict) -> None: + self.assertLessEqual(opened["height"], opened["cap"], opened) + above, below, need = opened["above"], opened["below"], opened["need"] + if above >= need: + self.assertEqual(opened["side"], "up", opened) + elif below >= need: + self.assertEqual(opened["side"], "down", opened) + else: + self.assertEqual(opened["side"], "up" if above >= below else "down", opened) + def check_popover(self, data: dict, browser: str) -> None: results = iter(data["results"]) for width, _ in POPOVER_SIZES: @@ -55,6 +65,7 @@ class TestRadioFocus(kit.RadioLayoutCase): self.assertNotIn("error", fold, fold) self.assertEqual((fold["opened"]["open"], fold["opened"]["outside"]), (True, []), fold) self.assertGreaterEqual(fold["opened"]["whole"], 1, fold) + self.check_side(fold["opened"]) self.assertEqual(fold["escape"], [False, True], fold) self.assertEqual(fold["again"], {"open": True, "outside": []}, fold) self.assertEqual(fold["click"], [False, False, True], fold) diff --git a/tests/e2e/test_score_overlays_e2e.py b/tests/e2e/test_score_overlays_e2e.py new file mode 100644 index 0000000..4409704 --- /dev/null +++ b/tests/e2e/test_score_overlays_e2e.py @@ -0,0 +1,174 @@ +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 hub_e2e_kit as base +import test_workbench_w4_e2e as w4 +from hub_case import HubCase +from hub_support import iso +from kvb_orchestrator.viewstore import OVERLAYS, VIEW + +OUT = Path(os.environ.get("E2E_OUT", "/tmp/hub-006-shots")) +PICKED = ["fix", "score"] +READ = """ + const chip = (key) => document.querySelector(`#main .legend-chip[data-path="burn.overlays"][data-chip="${key}"]`); + const chips = () => Object.fromEntries(all('#main .legend-chip[data-path="burn.overlays"]').map((node) => [node.dataset.chip, node.getAttribute("aria-pressed")])); + const drawn = () => Object.fromEntries(all("#main g.burn-overlay").map((group) => [group.dataset.overlay, Number(group.dataset.points)])); + const axis = () => all("#main text.overlay-axis").length; + const ready = () => Object.keys(chips()).length === @COUNT@ && document.querySelector("#main svg.burn"); + const stored = async () => (await (await fetch("/api/view", {cache: "no-store"})).json()).burn.overlays; + const storedUntil = async (test, ms) => { + const end = Date.now() + ms; + while (Date.now() < end) { + const kept = await stored(); + if (test(kept)) { + return kept; + } + await sleep(200); + } + return null; + }; + const look = () => ({chips: chips(), drawn: drawn(), axis: axis(), wide: document.documentElement.scrollWidth > innerWidth + 1}); +""" +SWITCH = """(async () => {@HELPERS@@READ@ + if (!(await until(ready, 15000))) { + return {error: text(document.getElementById("main"))}; + } + const before = look(); + for (const key of @PICKED@) { + chip(key).click(); + } + const on = Boolean(await until(() => Object.keys(drawn()).length === @PICKED@.length, 6000)); + const saved = await storedUntil((kept) => kept.length === @PICKED@.length, 6000); + return {before, on, after: look(), saved, violations: window.e2eViolations || null}; +})()""" +KEPT = """(async () => {@HELPERS@@READ@ + if (!(await until(() => ready() && Object.keys(drawn()).length === @PICKED@.length, 15000))) { + return {error: text(document.getElementById("main")), seen: look()}; + } + const kept = look(); + if (@CLEAR@) { + for (const key of @PICKED@) { + chip(key).click(); + } + } + const off = @CLEAR@ ? Boolean(await until(() => !Object.keys(drawn()).length, 6000)) : null; + const saved = @CLEAR@ ? await storedUntil((list) => !list.length, 6000) : await stored(); + return {kept, off, after: look(), saved, violations: window.e2eViolations || null}; +})()""" +RESET = """(async () => { + const current = await (await fetch("/api/view", {cache: "no-store"})).json(); + const reset = await fetch("/api/view", {method: "PATCH", headers: {"X-Kvb-Orchestrator": "1", "Content-Type": "application/json"}, body: JSON.stringify({set: @DEFAULTS@, expect: current}), cache: "no-store"}); + return {reset: reset.status}; +})()""" + + +def probe(template: str, clear: bool = True) -> str: + names = { + "@HELPERS@": base.HELPERS, "@READ@": READ, "@COUNT@": str(len(OVERLAYS)), "@PICKED@": json.dumps(PICKED), + "@CLEAR@": json.dumps(clear), "@DEFAULTS@": json.dumps(VIEW), + } + 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 TestScoreOverlays(HubCase): + drive = base.OrchestratorE2ECase.drive + + def setUp(self): + super().setUp() + OUT.mkdir(parents=True, exist_ok=True) + now = int(time.time()) + journal = [ + {"time": now - age, "branch": "master", "values": {"fix": fix, "break": 100 - fix, "tokens": 80, "velocity": 90, "security": 100, "score": fix - 5}} + for age, fix in ((15000, 70), (8000, 85), (2000, 95)) + ] + self.write_council({ + "scores.jsonl": self.jsonl(journal), + "rasci.json": { + "work/first": {"title": "First", "branch": "master", "status": "done", "worker": "Skills", "start": iso(now - 20000), "end": iso(now - 9000), "updated": iso(now - 9000), "roles": {"Skills": "RA"}}, + "work/second": {"title": "Second", "branch": "master", "status": "running", "worker": "Stage", "start": iso(now - 15000), "updated": iso(now - 600), "roles": {"Stage": "RA"}}, + }, + }) + self.base = f"http://{self.host}/" + + def steps(self, browser: str) -> list[dict]: + steps = [] + for width, height in base.WIDTHS: + shot = OUT / f"{browser}-{width}" + steps += [ + {"width": width, "height": height, "url": f"{self.base}?{width}#tasks/burn", "wait": 1200, "probe": probe(SWITCH), "shot": f"{shot}-on.png"}, + {"width": width, "height": height, "url": f"{self.base}?{width}-reloaded#tasks/burn", "wait": 1200, "probe": probe(KEPT), "shot": f"{shot}-kept.png"}, + ] + return steps + + def check_switch(self, found: dict, label: str) -> None: + with self.subTest(step=label, part="switch"): + self.assertNotIn("error", found, found) + self.assertEqual(found["before"], {"chips": dict.fromkeys(OVERLAYS, "false"), "drawn": {}, "axis": 0, "wide": False}) + self.assertTrue(found["on"], found) + after = found["after"] + self.assertEqual(after["chips"], {key: str(key in PICKED).lower() for key in OVERLAYS}) + self.assertEqual(after["drawn"], dict.fromkeys(PICKED, 3)) + self.assertEqual((after["axis"], after["wide"]), (3, False)) + self.assertEqual(sorted(found["saved"]), PICKED) + self.assertEqual(w4.quiet(found["violations"]), []) + + def check_kept(self, found: dict, label: str, cleared: bool) -> None: + with self.subTest(step=label, part="kept"): + self.assertNotIn("error", found, found) + self.assertEqual(found["kept"]["chips"], {key: str(key in PICKED).lower() for key in OVERLAYS}) + self.assertEqual(found["kept"]["drawn"], dict.fromkeys(PICKED, 3)) + if cleared: + self.assertTrue(found["off"], found) + self.assertEqual((found["after"]["drawn"], found["after"]["axis"], found["saved"]), ({}, 0, [])) + else: + self.assertEqual(sorted(found["saved"]), PICKED) + self.assertEqual(w4.quiet(found["violations"]), []) + + def run_browser(self, browser: str, *driver: str) -> None: + data = self.drive(self.steps(browser), None, *driver, init=w4.GUARD) + (OUT / f"{browser}-score-overlays.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], []) + results = iter(data["results"]) + for width, _ in base.WIDTHS: + self.check_switch(next(results), f"{browser}-{width}") + self.check_kept(next(results), f"{browser}-{width}", cleared=True) + self.assertEqual(self.httpd.hub.view_store.get(), VIEW) + + def test_chromium_switches_score_overlays_that_persist_across_a_reload_at_three_widths(self): + self.run_browser("chromium") + + @unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox") + def test_firefox_switches_score_overlays_that_persist_across_a_reload_at_three_widths(self): + self.run_browser("firefox", "bidi.mjs", os.environ.get("FIREFOX", "firefox")) + + @unittest.skipUnless(shutil.which(os.environ.get("FIREFOX", "firefox")), "no Firefox") + def test_overlays_switched_in_chromium_show_in_firefox(self): + width, height = 1366, 768 + url = f"{self.base}?{width}-second#tasks/burn" + first = self.drive([{"width": width, "height": height, "url": f"{self.base}?{width}#tasks/burn", "wait": 1200, "probe": probe(SWITCH), "shot": str(OUT / "chromium-second-on.png")}], None, init=w4.GUARD) + self.check_switch(first["results"][0], "chromium-first") + second = self.drive( + [{"width": width, "height": height, "url": url, "wait": 1200, "probe": probe(KEPT, clear=False), "shot": str(OUT / "firefox-second-seen.png")}, + {"width": width, "height": height, "url": None, "wait": 0, "probe": probe(RESET), "shot": None}], + None, "bidi.mjs", os.environ.get("FIREFOX", "firefox"), init=w4.GUARD, + ) + self.check_kept(second["results"][0], "firefox-second", cleared=False) + self.assertEqual(second["results"][1], {"reset": 200}) + self.assertEqual(self.httpd.hub.view_store.get(), VIEW) + + +if __name__ == "__main__": + unittest.main()