Files
odysseus/tests/test_agent_thread_dot_alignment_css.py
T
Léo 1323fab0bd refactor(tests): read the whole cascade instead of style.css alone
static/style.css no longer holds every rule. 79 rules for the document,
gallery and editor panels now live in static/css/, yet 27 browser tests still
built their synthetic page with a single <link> to style.css, and 51 more read
that one file as though it were the whole cascade. Those tests kept passing
while covering less: a rule that moved became invisible to the assertion that
was meant to pin it.

Python readers now call tests.helpers.stylesheets.app_css(), and synthetic
pages are built from stylesheet_link_tags() so they load exactly what
index.html loads, in the same order. The helper already existed; this moves
the remaining callers onto it.

test_portal_dropdown_z_js parametrised over a file list including style.css to
assert an absence. Checking a negative against one file of a split stylesheet
is how a moved rule escapes, so the CSS case now checks the concatenation.

Two guards keep it from coming back: one fails on any test reading
static/style.css directly, the other on any synthetic page linking it alone.
Both name the helper to use.

No production code changes. Suite is unchanged at 6 pre-existing failures.
2026-09-29 17:05:29 +02:00

105 lines
3.7 KiB
Python

"""Agent-thread timeline dots must stay centred on the vertical rail.
Source-text assertions here are the narrow exception allowed by
TESTING_STANDARD.md: the invariant is pure CSS geometry, and driving it at
runtime would need a real layout engine, which the suite has no runner for.
The test parses the declared pixel values and recomputes the centres rather
than pinning literals, so retuning the spacing keeps it green — but moving a
breakpoint's padding without moving both dot offsets turns it red.
The thread's padding is restated once per breakpoint, and each breakpoint's
overrides follow its own `.agent-thread` rule, so a rule's position in the
file identifies the breakpoint it belongs to.
"""
import re
from pathlib import Path
from tests.helpers.stylesheets import app_css
CSS = app_css()
THREAD = r"^[ \t]*\.agent-thread[ \t]*\{"
RAIL = r"^[ \t]*\.agent-thread::before[ \t]*\{"
STEP_DOT = r"^[ \t]*\.agent-thread-dot[ \t]*\{"
END_DOT = (
r"^[ \t]*\.agent-thread:not\(\.has-bottom\) "
r"\.agent-thread-node\.open:last-child::after[ \t]*\{"
)
def _blocks(selector: str) -> list[tuple[int, str]]:
"""(position, declaration block) for each rule using this exact selector."""
return [
(m.start(), CSS[m.end() : CSS.index("}", m.end())])
for m in re.finditer(selector, CSS, re.MULTILINE)
]
def _px(block: str, prop: str) -> float | None:
m = re.search(rf"(?:^|;|/)\s*{prop}\s*:\s*(-?[\d.]+)px", block)
return float(m.group(1)) if m else None
def _padding_left(block: str) -> float | None:
explicit = _px(block, "padding-left")
if explicit is not None:
return explicit
shorthand = re.search(r"(?:^|;)\s*padding\s*:([^;]+);", block)
sides = shorthand.group(1).split() if shorthand else []
return float(sides[3].removesuffix("px")) if len(sides) == 4 else None
def _breakpoints() -> list[tuple[float, int, int]]:
"""(padding-left, window start, window end) for each declared breakpoint."""
threads = _blocks(THREAD)
assert threads, "no .agent-thread rule found"
bounds = [pos for pos, _ in threads] + [len(CSS)]
return [
(_padding_left(block), bounds[i], bounds[i + 1])
for i, (_, block) in enumerate(threads)
]
def _in_force(selector: str, prop: str, start: int, end: int, fallback):
"""Value a breakpoint's window declares, else the one it inherits."""
declared = [_px(b, prop) for pos, b in _blocks(selector) if start <= pos < end]
values = [v for v in declared if v is not None]
return values[-1] if values else fallback
def _centres() -> list[tuple[float, float, float]]:
rail = _blocks(RAIL)[0][1]
rail_centre = _px(rail, "left") + _px(rail, "width") / 2
base_step, base_end = _blocks(STEP_DOT)[0][1], _blocks(END_DOT)[0][1]
step_width, end_width = _px(base_step, "width"), _px(base_end, "width")
rows = []
for padding, start, end in _breakpoints():
step_left = _in_force(STEP_DOT, "left", start, end, _px(base_step, "left"))
end_left = _in_force(END_DOT, "left", start, end, _px(base_end, "left"))
rows.append(
(
rail_centre,
padding + step_left + step_width / 2,
padding + end_left + end_width / 2,
)
)
return rows
def test_step_dots_are_centred_on_the_rail_at_every_breakpoint():
for index, (rail, step, _) in enumerate(_centres()):
assert step == rail, (
f"step dot at breakpoint {index} sits {step - rail}px off the rail"
)
def test_terminating_dot_is_centred_on_the_rail_at_every_breakpoint():
for index, (rail, _, end) in enumerate(_centres()):
assert end == rail, (
f"terminating dot at breakpoint {index} sits {end - rail}px "
"off the rail"
)