2026-11-11 23:39:17 +00:00
from __future__ import annotations
import json
import os
import shutil
import sys
import time
import unittest
2026-11-13 10:48:13 +00:00
from collections.abc import Callable
2026-11-11 23:39:17 +00:00
from pathlib import Path
from unittest import mock
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 iso
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"
2026-11-13 09:32:39 +00:00
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"
)
2026-11-12 14:10:04 +00:00
READING = max ( 1.5 , len ( FIRST . split ()) * 60 / 180 )
EARLY = 0.1
LATE = 2.0
2026-11-11 23:39:17 +00:00
VIEWS = { 1920 : "agents/orbit" , 1366 : "stream/radio" , 390 : "agents/hierarchy" }
2026-11-12 07:53:59 +00:00
SECOND_FROM = { 1920 : "Skills" , 1366 : "Skills" , 390 : "Docs" }
SECOND_ANCHORED = { 1920 : True , 1366 : False , 390 : False }
2026-11-11 23:39:17 +00:00
CALM = [{ "name" : "prefers-reduced-motion" , "value" : "reduce" }]
2026-11-13 09:32:39 +00:00
FADE_MS = 400
FADE_SLACK = 50
2026-11-11 23:39:17 +00:00
GUARD = """() => {
window.e2eViolations = [];
document.addEventListener("securitypolicyviolation", (event) => window.e2eViolations.push(`$ {event.violatedDirective} $ {event.blockedURI} `));
2026-11-13 10:48:13 +00:00
try {
localStorage.setItem("kvb-orchestrator.radio", JSON.stringify({mode: "silence", classes: ["broadcast"]}));
} catch (error) {
return;
}
2026-11-11 23:39:17 +00:00
}"""
2026-11-12 14:10:04 +00:00
HOOKED = f "() => {{\n ( { GUARD } )(); \n ( { base . GRAPH_HOOK } )(); \n}} "
2026-11-11 23:39:17 +00:00
READ = """
const toggle = document.getElementById("bubbles-toggle");
const layer = document.getElementById("bubbles");
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;
2026-11-13 09:32:39 +00:00
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;
2026-11-11 23:39:17 +00:00
const read = (node) => {
if (!node) {
return null;
}
const style = getComputedStyle(node);
const box = node.getBoundingClientRect();
2026-11-13 09:32:39 +00:00
const scale = new DOMMatrix(style.transform).a;
const anchor = face(node.dataset.who);
2026-11-11 23:39:17 +00:00
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")),
2026-11-13 09:32:39 +00:00
anchored: node.parentElement === layer, rendered: Math.round(scale * 100) / 100, transition: style.transitionProperty, font: style.fontFamily,
2026-11-11 23:39:17 +00:00
box: {left: box.left, top: box.top, right: box.right, bottom: box.bottom},
2026-11-13 09:32:39 +00:00
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"),
2026-11-11 23:39:17 +00:00
};
};
2026-11-13 09:32:39 +00:00
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)};
};
2026-11-11 23:39:17 +00:00
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@
const before = [toggle.getAttribute("aria-pressed"), layer.hidden];
2026-11-12 14:10:04 +00:00
window.e2eBubbleLog = [];
const note = (node) => window.e2eBubbleLog.push({
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,
});
2026-11-13 09:32:39 +00:00
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);
};
2026-11-12 14:10:04 +00:00
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);
2026-11-13 09:32:39 +00:00
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);
});
2026-11-12 14:10:04 +00:00
}
}).observe(layer, {subtree: true, childList: true, attributes: true, attributeFilter: ["class", "data-state", "data-words", "data-read"]});
2026-11-11 23:39:17 +00:00
toggle.click();
const on = Boolean(await until(() => toggle.getAttribute("aria-pressed") === "true" && !layer.hidden, 8000));
await cue("@CUE@");
if (!(await until(() => speaking() && waiting(), 25000))) {
return {before, on, error: "no pair of bubbles", bubbles: live().map(read), toasts: all("#toasts .toast").map(text)};
}
await sleep(400);
2026-11-13 09:32:39 +00:00
return {before, on, first: read(speaking()), second: read(waiting()), layer: frame()};
2026-11-11 23:39:17 +00:00
})()"""
BUBBLES_GROW = """(async () => {@HELPERS@@READ@
2026-11-12 14:10:04 +00:00
const log = window.e2eBubbleLog || [];
const who = (log.find((entry) => entry.state === "speaking") || {} ).who || null;
const mine = () => log.filter((entry) => entry.who === who);
const left = await until(() => mine().find((entry) => entry.leaving), 15000);
let grown = null;
if (left) {
await Promise.all((speaking() ? speaking().getAnimations() : []).map((animation) => animation.finished.catch(() => null)));
grown = read(speaking());
await until(() => mine().some((entry) => entry.removed), 4000);
2026-11-13 09:32:39 +00:00
await until(() => (window.e2eFades || []).some((entry) => entry.who === who && entry.removed !== null && entry.reference !== null), 2000);
2026-11-11 23:39:17 +00:00
}
2026-11-13 09:32:39 +00:00
const fading = (window.e2eFades || []).find((entry) => entry.who === who) || null;
2026-11-12 14:10:04 +00:00
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);
const start = entries.find((entry) => entry.state === "speaking");
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,
2026-11-13 09:32:39 +00:00
faded: fade > 0 && entries.slice(fade).every((entry) => entry.leaving), gone: entries.some((entry) => entry.removed), grown, fading,
2026-11-12 14:10:04 +00:00
};
2026-11-11 23:39:17 +00:00
})()"""
BUBBLES_DONE = """(async () => {@HELPERS@@READ@
const cleared = Boolean(await until(() => !layer.querySelector(".speech-bubble"), 10000));
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};
})()"""
2026-11-13 09:32:39 +00:00
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,
};
})()"""
2026-11-11 23:39:17 +00:00
BUBBLES_3D = """(async () => {@HELPERS@@READ@
const canvas = Boolean(await until(() => document.querySelector("#main .graph3d canvas"), 15000));
2026-11-12 14:10:04 +00:00
await until(() => {
const graph = (window.e2eGraphs || []).at(-1);
const nodes = graph ? graph.graphData().nodes : [];
const frame = document.querySelector("#main .graph3d").getBoundingClientRect();
return nodes.length && nodes.every((node) => {
const at = Number.isFinite(node.x) ? graph.graph2ScreenCoords(node.x, node.y, node.z) : {x: -1, y: -1};
return at.x >= 0 && at.y >= 0 && at.x <= frame.width && at.y <= frame.height;
});
}, 15000);
2026-11-11 23:39:17 +00:00
await cue("@CUE@");
if (!(await until(speaking, 25000))) {
return {canvas, error: "no bubble in 3D", bubbles: live().map(read)};
}
2026-11-13 09:32:39 +00:00
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();
2026-11-11 23:39:17 +00:00
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"))};
})()"""
2026-11-13 18:49:32 +00:00
BUBBLES_KEPT = """(async () => {@HELPERS@@READ@@UNLABELLED@
2026-11-11 23:39:17 +00:00
await sleep(300);
const kept = [toggle.getAttribute("aria-pressed"), layer.hidden, toggle.title, toggle.getAttribute("aria-label")];
2026-11-13 18:49:32 +00:00
const control = [Boolean(toggle.querySelector('svg.bi use[href="#bi-chat-quote"]')), text(toggle)];
const head = document.querySelector("header.top");
const labels = {header: head ? unlabelled(head) : null, layer: unlabelled(layer)};
2026-11-11 23:39:17 +00:00
toggle.click();
const off = Boolean(await until(() => toggle.getAttribute("aria-pressed") === "false" && layer.hidden, 8000));
2026-11-13 18:49:32 +00:00
return {kept, control, labels, off, display: getComputedStyle(layer).display, bubbles: layer.querySelectorAll(".speech-bubble").length, violations: window.e2eViolations || null};
2026-11-11 23:39:17 +00:00
})()"""
2026-11-13 18:49:32 +00:00
SWITCHED = { "kept" : [ "true" , False , "Speech bubbles" , "Speech bubbles" ], "control" : [ True , "" ], "labels" : { "header" : [], "layer" : []}, "off" : True , "display" : "none" , "bubbles" : 0 , "violations" : []}
2026-11-11 23:39:17 +00:00
def probe ( template : str , cue : str = CUE ) -> str :
2026-11-13 18:49:32 +00:00
return template . replace ( "@HELPERS@" , base . HELPERS ) . replace ( "@READ@" , READ ) . replace ( "@UNLABELLED@" , base . UNLABELLED ) . replace ( "@CUE@" , cue ) . replace ( "@FADE@" , str ( FADE_MS ))
2026-11-11 23:39:17 +00:00
2026-11-12 07:53:59 +00:00
def quiet ( found : dict ) -> dict :
violations = found [ "violations" ]
return { ** found , "violations" : None if violations is None else [ seen for seen in violations if not seen . endswith ( "/favicon.ico" )]}
2026-11-11 23:39:17 +00:00
@unittest.skipUnless ( shutil . which ( os . environ . get ( "CHROMIUM" , "chromium" )), "no Chromium" )
class TestWorkbenchBubbles ( HubCase ):
drive = base . TestOrchestratorE2E . drive
def setUp ( self ):
super () . setUp ()
OUT . mkdir ( parents = True , exist_ok = True )
now = time . time ()
self . write_council ({
"work/s2/claim.json" : { "office" : "work/s2" , "session" : "s2" , "runtime" : "claude" , "name" : "Stage" , "since" : iso ( now - 7200 ), "beat" : now - 60 , "work" : "x" },
"chair/claim.json" : { "office" : "chair" , "session" : "s1" , "runtime" : "claude" , "name" : "Skills session" , "since" : iso ( now - 7200 ), "beat" : now , "work" : "allocate" },
"news.jsonl" : self . jsonl ([
{ "ts" : now - 600 , "from" : "Skills session" , "to" : [ "Stage" ], "text" : "rebase please" , "class" : "post" , "v" : 2 },
{ "ts" : now - 500 , "from" : "Stage" , "to" : [ "Skills session" ], "text" : "gate red" , "class" : "call" , "v" : 2 },
{ "ts" : now - 400 , "from" : "Docs" , "to" : [], "text" : "docs are green" , "class" : "newsletter" , "v" : 2 },
]),
})
self . keys = { row [ "from" ]: row [ "source" ] for row in self . snapshot ()[ "radio" ]}
hub = self . httpd . hub
spoken = base . tone ( 1 , 8000 )
2026-11-13 10:48:13 +00:00
def synthesize ( body : bytes , admit : Callable [[ str ], None ]) -> bytes :
2026-11-11 23:39:17 +00:00
word = json . loads ( body )[ "text" ]
2026-11-13 09:32:39 +00:00
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 ):
2026-11-11 23:39:17 +00:00
now = time . time ()
rows = [
2026-11-13 10:48:13 +00:00
{ "ts" : now - 0.01 , "from" : "Stage" , "to" : [], "text" : FIRST , "class" : "broadcast" , "v" : 2 },
{ "ts" : now , "from" : "Docs" if word . endswith ( "-docs" ) else "Skills session" , "to" : [], "text" : SECOND , "class" : "broadcast" , "v" : 2 },
2026-11-11 23:39:17 +00:00
]
with ( self . council / "news.jsonl" ) . open ( "a" , encoding = "utf-8" ) as handle :
handle . write ( self . jsonl ( rows ))
return spoken
patch = mock . patch . object ( hub . speech , "synthesize" , synthesize )
patch . start ()
self . addCleanup ( patch . stop )
self . base = f "http:// { self . host } /"
def steps ( self , browser : str , calm : bool , three : bool ) -> list [ dict ]:
steps = []
for width , height in base . WIDTHS :
view = VIEWS [ width ]
media = CALM if calm and width == 390 else []
cue = f " { CUE } -docs" if SECOND_FROM [ width ] == "Docs" else CUE
shot = str ( OUT / f " { browser } - { width } -bubbles" )
steps += [
{ "width" : width , "height" : height , "url" : f " { self . base } ? { width } # { view } " , "wait" : 1200 , "probe" : probe ( BUBBLES_ON , cue ), "shot" : f " { shot } -pair.png" , "media" : media },
{ "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 },
]
2026-11-13 09:32:39 +00:00
if width == 1366 :
steps . append ({ "width" : width , "height" : height , "url" : None , "wait" : 0 , "probe" : probe ( BUBBLES_LONG ), "shot" : None , "media" : media })
2026-11-11 23:39:17 +00:00
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 })
2026-11-13 09:32:39 +00:00
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 },
]
2026-11-11 23:39:17 +00:00
return steps
2026-11-13 09:32:39 +00:00
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 )
2026-11-11 23:39:17 +00:00
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 )
2026-11-13 09:32:39 +00:00
long = next ( results ) if width == 1366 else None
2026-11-11 23:39:17 +00:00
solid = next ( results ) if three and width == 1366 else None
kept = next ( results )
2026-11-13 09:32:39 +00:00
stream = [ next ( results ), next ( results ), next ( results )] if width == 1366 else None
2026-11-11 23:39:17 +00:00
first_key , second_key = self . keys [ "Stage" ], self . keys [ SECOND_FROM [ width ]]
2026-11-13 18:49:32 +00:00
with self . subTest ( browser = browser , width = width , part = "unlabelled controls" ):
self . assertNotIn ( "error" , kept , kept )
self . assertEqual (( kept [ "control" ], kept [ "labels" ]), ( SWITCHED [ "control" ], SWITCHED [ "labels" ]), kept )
2026-11-13 09:32:39 +00:00
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 )
2026-11-13 18:49:32 +00:00
self . assertEqual ( quiet ( switched ), SWITCHED )
2026-11-11 23:39:17 +00:00
with self . subTest ( browser = browser , width = width ):
self . assertNotIn ( "error" , on , on )
self . assertEqual (( on [ "before" ], on [ "on" ]), ([ "false" , True ], True ))
first , second = on [ "first" ], on [ "second" ]
self . assertEqual (( first [ "who" ], first [ "scale" ], first [ "rendered" ], first [ "state" ], first [ "anchored" ]), ( first_key , 1 , 1 , "speaking" , True ), first )
self . assertTrue ( 0 < first [ "words" ] < len ( FIRST . split ()), first )
self . assertEqual ( first [ "text" ], " " . join ( FIRST . split ()[: first [ "words" ]]))
2026-11-12 07:53:59 +00:00
self . assertEqual ( first [ "font" ] . replace ( '"' , "" ) . split ( "," )[ 0 ], "Comic Neue" , first [ "font" ])
2026-11-11 23:39:17 +00:00
self . assertEqual (( second [ "who" ], second [ "scale" ], second [ "rendered" ], second [ "state" ], second [ "text" ], second [ "words" ]), ( second_key , 0.8 , 0.8 , "waiting" , "…" , 0 ), second )
2026-11-12 07:53:59 +00:00
self . assertEqual ( second [ "anchored" ], SECOND_ANCHORED [ width ], second )
2026-11-11 23:39:17 +00:00
motion = "opacity" if calm and width == 390 else "transform, opacity"
self . assertEqual (( first [ "transition" ], second [ "transition" ]), ( motion , motion ))
self . assertEqual ( grow [ "who" ], first_key )
2026-11-12 14:10:04 +00:00
self . assertGreaterEqual ( len ( grow [ "words" ]), 2 , grow )
self . assertEqual ( grow [ "words" ], sorted ( grow [ "words" ]), grow )
self . assertEqual ( grow [ "read" ], len ( FIRST . split ()), grow )
2026-11-11 23:39:17 +00:00
self . assertEqual (( grow [ "faded" ], grow [ "gone" ]), ( True , True ), grow )
2026-11-12 14:10:04 +00:00
self . assertTrue ( READING - EARLY <= grow [ "seconds" ] <= READING + LATE , grow )
2026-11-11 23:39:17 +00:00
grown = grow [ "grown" ]
self . assertEqual (( grown [ "who" ], grown [ "scale" ], grown [ "rendered" ], grown [ "state" ]), ( second_key , 1 , 1 , "speaking" ), grown )
self . assertEqual ( grown [ "text" ], " " . join ( SECOND . split ()[: grown [ "words" ]]))
2026-11-12 07:53:59 +00:00
self . assertEqual ( quiet ( done ), { "cleared" : True , "faces" : [ "loaded" ], "hidden" : False , "violations" : []})
2026-11-13 18:49:32 +00:00
self . assertEqual ( quiet ( kept ), SWITCHED )
2026-11-13 09:32:39 +00:00
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 )
2026-11-11 23:39:17 +00:00
if solid is not None :
with self . subTest ( browser = browser , view = "3d" ):
self . assertNotIn ( "error" , solid , solid )
graph = solid [ "graph" ]
for read in ( solid [ "first" ], solid [ "later" ]):
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 )
2026-11-13 09:32:39 +00:00
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 )
2026-11-11 23:39:17 +00:00
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 ):
2026-11-12 14:10:04 +00:00
data = self . drive ( self . steps ( "chromium" , True , True ), None , init = HOOKED )
2026-11-11 23:39:17 +00:00
( OUT / "chromium-bubbles.json" ) . write_text ( json . dumps ( data , indent = 1 ), encoding = "utf-8" )
self . assertEqual ( data [ "errors" ], [])
self . check ( data , "chromium" , True , True )
@unittest.skipUnless ( shutil . which ( os . environ . get ( "FIREFOX" , "firefox" )), "no Firefox" )
def test_firefox_reads_two_rows_without_tts_as_growing_bubbles_keeps_the_switch_and_hides_the_layer_at_three_widths ( self ):
data = self . drive ( self . steps ( "firefox" , False , False ), None , "bidi.mjs" , os . environ . get ( "FIREFOX" , "firefox" ), init = GUARD )
( OUT / "firefox-bubbles.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" , False , False )
if __name__ == "__main__" :
unittest . main ()