phase: 130_chat_answer_clusters
**Phase 130 — final verification pass: 100% green, complete.** - **Verified:** chips-only row (no chip for image docs) → images-only row (`.msg-images`) → related row → `.msg-actions` last; `getActionsRow` used by all 3 buttons + stopped/failed notes; `markLastRetryable` save-re-append hack gone; in-place chip fallback on image-load failure; CSS right-align with per-button auto margins removed — implementation matches the design in every detail. - **Completion criteria:** (1) mixed citation renders chips→images→actions-last, DOM-asserted ✅ (2) all 3 buttons in one right-aligned `.msg-actions`; non-admin sees Retry-only; restore path identical ✅ (3) 404-bytes figure → plain chip, unit-pinned ✅ (4) E2E isolated ✅ (5) no behavior change (modal affordances, related tier, ARIA names) ✅ - **Tests/lint/coverage:** `uv run pytest tests/e2e/test_chat_answer_clusters.py -v --no-cov` → 4 passed; `uv run pytest --cov=app --cov-report=term-missing` → 3061 passed, **99%** app coverage; the 4 E2E files this phase modified (test_answer_images, test_image_documents, test_pdf_support, test_responsive_polish) → 22 passed in isolation; `uv run ruff check .` clean, `uv run pyright` → 0 errors. - **Docs:** README.md — verified consistent in full (page table vs routes, env-var coverage vs `.env.example`, phase-130 cluster wording already in tree); no changes needed. AGENTS.md — fixed one pre-existing inconsistency: rule 5 still cited the retired "centered 46rem chat column"; now states the 72rem container contract (phase 100). - **Decisions:** PLAN.md §7.1 still says 46rem, but it's owner-managed (phase 100 records the supersession pending owner sign-off) and out of my editable scope — AGENTS.md now cross-references the supersession. - **Next pending phase:** `131_read_line_ranges` (todo/).
This commit is contained in:
@@ -0,0 +1,421 @@
|
||||
"""Unit: the phase-130 (task 02, TODO L6) chat actions cluster.
|
||||
|
||||
The three answer actions (Tune / Retry / Save-as-doc) and the
|
||||
answer-status notes (Stopped / Failed) stop joining whatever the first
|
||||
``.msg-meta`` row happens to be (usually the source chips row). They
|
||||
get-or-create a dedicated ``.msg-meta.msg-actions`` row — the bubble's
|
||||
LAST row, right-aligned by CSS (task 03) — so chips and images can
|
||||
never push the buttons around.
|
||||
|
||||
Pins (the house source-pin pattern — no browser):
|
||||
|
||||
* ``getActionsRow(wrap)`` — the shared get-or-create helper: scoped to
|
||||
the ``msg-actions`` class so it NEVER grabs the chips row (or any
|
||||
other meta row), ``role=list`` + ``aria-label="Answer actions"``,
|
||||
null without a ``.msg-body``;
|
||||
* all FIVE appenders/notes route through ``getActionsRow(wrap)`` —
|
||||
none of them reuses the first ``.msg-meta`` row anymore;
|
||||
* ``markLastRetryable`` re-appends the Retry button into the actions
|
||||
row and the phase-59 save-button re-append hack is GONE (the row's
|
||||
row-level right-align replaces the per-button auto margins);
|
||||
* the call-order audit (task 02 item 5): at every completed-bubble
|
||||
render site the order is answer figure → sources → related → the
|
||||
action appenders, so ``.msg-actions`` is the bubble's LAST row, and
|
||||
the done branch's insertion order inside the row is Tune → Retry →
|
||||
Save-as-doc.
|
||||
|
||||
The browser-level assertions (the right-aligned cluster, the row
|
||||
order in the rendered DOM, the restore parity) are E2E-gated by
|
||||
tests/e2e/test_chat_answer_clusters.py (task 04).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
FRONTEND = Path(__file__).resolve().parents[2] / "frontend"
|
||||
APP_JS = FRONTEND / "assets" / "app.js"
|
||||
|
||||
|
||||
def _js() -> str:
|
||||
return APP_JS.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _fn_body(js: str, header: str) -> str:
|
||||
"""The full source of the function whose header is *header* —
|
||||
brace-matched from the first ``{`` OUTSIDE the parameter list
|
||||
(paren depth 0, the house convention), so destructured parameters
|
||||
are skipped (the pinned functions carry no string literal with a
|
||||
stray brace)."""
|
||||
start = js.index(header)
|
||||
i = start
|
||||
paren = 0
|
||||
while i < len(js):
|
||||
c = js[i]
|
||||
if c == "(":
|
||||
paren += 1
|
||||
elif c == ")":
|
||||
paren -= 1
|
||||
elif c == "{" and paren == 0:
|
||||
break
|
||||
i += 1
|
||||
depth = 0
|
||||
for j in range(i, len(js)):
|
||||
c = js[j]
|
||||
if c == "{":
|
||||
depth += 1
|
||||
elif c == "}":
|
||||
depth -= 1
|
||||
if depth == 0:
|
||||
return js[start : j + 1]
|
||||
raise AssertionError(f"unbalanced braces in {header!r}")
|
||||
|
||||
|
||||
def _done_branch(js: str) -> str:
|
||||
"""The SSE ``done`` branch — from the branch test to the next
|
||||
``else if`` (flat block, the slice is exact)."""
|
||||
start = js.index('ev.type === "done"')
|
||||
return js[start : js.index('ev.type === "tool_result"', start)]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# getActionsRow — the shared get-or-create helper
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_get_actions_row_gets_or_creates_the_dedicated_row() -> None:
|
||||
"""``getActionsRow(wrap)`` find-or-creates the bubble's
|
||||
``.msg-meta.msg-actions`` row: the query is scoped to the
|
||||
``msg-actions`` class (NEVER the bare first ``.msg-meta`` — that
|
||||
would grab the chips row), the created row is ``role=list`` +
|
||||
``aria-label="Answer actions"`` (the ARIA convention of the other
|
||||
meta rows), and it lands in ``.msg-body``. A missing ``.msg-body``
|
||||
(the defensive pre-phase convention) returns null — the appenders
|
||||
no-op."""
|
||||
js = _js()
|
||||
body = _fn_body(js, "function getActionsRow(wrap) {")
|
||||
assert 'body.querySelector(".msg-meta.msg-actions")' in body, (
|
||||
"the reuse query is scoped to the msg-actions class — the "
|
||||
"helper must NEVER grab the chips row (or any other meta row)"
|
||||
)
|
||||
assert "document.querySelector" not in body and "body.querySelector(\".msg-meta\")" not in body
|
||||
assert 'row.className = "msg-meta msg-actions";' in body
|
||||
assert 'row.setAttribute("role", "list");' in body, (
|
||||
"the row is an accessible list (the house meta-row convention)"
|
||||
)
|
||||
assert 'row.setAttribute("aria-label", "Answer actions");' in body, (
|
||||
"the row's accessible name (WCAG — the row is never unnamed)"
|
||||
)
|
||||
assert "body.appendChild(row)" in body, "a new row lands in .msg-body"
|
||||
assert 'wrap?.querySelector?.(".msg-body")' in body, (
|
||||
"defensive .msg-body lookup (the stopped-note convention)"
|
||||
)
|
||||
assert "if (!body) return null" in body, "no .msg-body → null (appenders no-op)"
|
||||
assert "return row" in body
|
||||
|
||||
|
||||
def test_get_actions_row_is_the_shared_helper() -> None:
|
||||
"""EXACTLY ONE getActionsRow (no per-appender copies of the
|
||||
get-or-create logic), and the created row's class string appears
|
||||
nowhere else in the file (the appenders only ever LOOK it up —
|
||||
they never build a second actions row)."""
|
||||
js = _js()
|
||||
assert js.count("function getActionsRow(wrap) {") == 1, (
|
||||
"exactly ONE getActionsRow — the shared helper"
|
||||
)
|
||||
assert js.count('row.className = "msg-meta msg-actions";') == 1, (
|
||||
"the row is created in exactly ONE place — the helper; the "
|
||||
"appenders never build a row themselves"
|
||||
)
|
||||
assert js.count('body.querySelector(".msg-meta.msg-actions")') == 1, (
|
||||
"the reuse query lives in exactly ONE place — the helper"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the five appenders/notes — all through getActionsRow
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
#: (function header, the one-per-bubble guard's class, the child class)
|
||||
APPENDERS = [
|
||||
("function appendTuneButton(wrap) {", ".tune-btn", "tune-btn"),
|
||||
("function appendRetryButton(wrap) {", ".retry-btn", "retry-btn"),
|
||||
(
|
||||
"function appendSaveAsDocButton(wrap, markdown) {",
|
||||
".save-as-doc-btn",
|
||||
"save-as-doc-btn",
|
||||
),
|
||||
("function appendStoppedNote(wrap) {", ".stopped-note", "stopped-note"),
|
||||
("function appendFailedNote(wrap, detail) {", ".failed-note", "failed-note"),
|
||||
]
|
||||
|
||||
|
||||
def test_all_action_appenders_join_the_actions_row() -> None:
|
||||
"""All FIVE appenders/notes (Tune, Retry, Save-as-doc, Stopped,
|
||||
Failed) route through ``getActionsRow(wrap)`` and no-op on its
|
||||
null (no ``.msg-body``) — none of them reuses the FIRST
|
||||
``.msg-meta`` row anymore (the pre-phase-130 soup-div behavior is
|
||||
gone from every appender)."""
|
||||
js = _js()
|
||||
for header, guard, child in APPENDERS:
|
||||
body = _fn_body(js, header)
|
||||
assert "getActionsRow(wrap)" in body, f"{header} must use getActionsRow"
|
||||
assert 'querySelector(".msg-meta")' not in body, (
|
||||
f"{header} must not query the bare first .msg-meta row"
|
||||
)
|
||||
assert "if (!meta) return" in body, (
|
||||
f"{header} must no-op when getActionsRow returns null"
|
||||
)
|
||||
assert f'querySelector("{guard}")' in body, (
|
||||
f"{header} keeps its one-per-bubble guard"
|
||||
)
|
||||
assert f'"{child}"' in body, f"{header} keeps its child class"
|
||||
|
||||
|
||||
def test_action_appenders_keep_the_listitem_aria() -> None:
|
||||
"""ARIA is kept (the existing convention): the role=list check
|
||||
stays on every appender and the child joins the row as a
|
||||
listitem (the row is ALWAYS role=list — getActionsRow sets it —
|
||||
so the check always applies)."""
|
||||
js = _js()
|
||||
for header, _, _ in APPENDERS:
|
||||
body = _fn_body(js, header)
|
||||
assert 'meta.getAttribute("role") === "list"' in body, (
|
||||
f"{header} keeps the role=list check"
|
||||
)
|
||||
assert 'setAttribute("role", "listitem")' in body, (
|
||||
f"{header} keeps the listitem join"
|
||||
)
|
||||
|
||||
|
||||
def test_tune_and_save_gates_are_unchanged() -> None:
|
||||
"""The gates are untouched (no behavior change in completed work):
|
||||
Tune is admin-gated (phase 16) and Save-as-doc is admin-gated AND
|
||||
docs-repo-gated (phase 59) — both BEFORE any row work. Retry is
|
||||
NOT admin-gated (owner-locked: every visitor)."""
|
||||
js = _js()
|
||||
tune = _fn_body(js, "function appendTuneButton(wrap) {")
|
||||
assert 'if (!isAdmin) return' in tune
|
||||
save = _fn_body(js, "function appendSaveAsDocButton(wrap, markdown) {")
|
||||
assert "if (!isAdmin || !docsRepoConfigured) return" in save
|
||||
retry = _fn_body(js, "function appendRetryButton(wrap) {")
|
||||
assert "isAdmin" not in retry, "Retry stays NOT admin-gated"
|
||||
|
||||
|
||||
def test_failed_note_detail_is_textcontent_only() -> None:
|
||||
"""The ``failed-detail`` contract survives (task 02 item 3): the
|
||||
error detail goes through ``textContent`` — no HTML from error
|
||||
strings, ever."""
|
||||
js = _js()
|
||||
body = _fn_body(js, "function appendFailedNote(wrap, detail) {")
|
||||
assert 'd.className = "failed-detail"' in body
|
||||
assert "d.textContent = detail" in body, (
|
||||
"the error string is NEVER innerHTML"
|
||||
)
|
||||
# The icon constant is the ONLY innerHTML (the static aria-hidden
|
||||
# SVG) — the detail path never builds HTML (comments stripped —
|
||||
# the "NEVER innerHTML" remark is not code).
|
||||
code = "\n".join(
|
||||
line for line in body.splitlines() if "//" not in line
|
||||
)
|
||||
assert code.count("innerHTML") == 1, (
|
||||
"only the static FAILED_ICON innerHTML remains in the note"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# markLastRetryable — the rework (task 02 item 4)
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_mark_last_retryable_moves_retry_into_the_actions_row() -> None:
|
||||
"""``markLastRetryable`` keeps the phase-49 remove-then-append
|
||||
shape (remove every rendered .retry-btn FIRST, then re-append on
|
||||
the last brain bubble — only when its preceding user record
|
||||
exists), but the re-append now lands in the bubble's .msg-actions
|
||||
row (via appendRetryButton → getActionsRow). The phase-59
|
||||
save-button re-append hack (the ``saveDocBtn`` block) is DELETED:
|
||||
the row's row-level right-align (task 03) right-aligns the whole
|
||||
cluster, and the DOM order inside the row is the insertion order.
|
||||
The 'auto margins split the free space' rationale is gone with it."""
|
||||
js = _js()
|
||||
body = _fn_body(js, "function markLastRetryable() {")
|
||||
assert 'querySelectorAll(".retry-btn")' in body
|
||||
assert ".remove()" in body
|
||||
assert body.index(".remove()") < body.index("appendRetryButton(lastBrainWrap)"), (
|
||||
"the existing buttons are removed before the new one is appended"
|
||||
)
|
||||
assert "appendRetryButton(lastBrainWrap)" in body, (
|
||||
"the re-append targets the last brain wrap (via getActionsRow)"
|
||||
)
|
||||
assert 'who !== "user"' in body, "the preceding-user-record guard stays"
|
||||
assert "saveDocBtn" not in body, (
|
||||
"the phase-59 save-button re-append hack is deleted"
|
||||
)
|
||||
assert "parentElement" not in body, (
|
||||
"no DOM re-parenting of the save button anymore"
|
||||
)
|
||||
assert "auto margins" not in body, (
|
||||
"the 'auto margins split the free space' rationale is gone"
|
||||
)
|
||||
# The hack had no other home in the file.
|
||||
assert "saveDocBtn" not in js
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the call-order audit (task 02 item 5) — .msg-actions is the LAST row
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_done_branch_appends_actions_last_in_insertion_order() -> None:
|
||||
"""The live ``done`` branch (a completed brain bubble): the row
|
||||
order is the DOM order — the answer figure, then the source
|
||||
clusters (appendSources), then the related row, then the action
|
||||
appenders — so the .msg-actions row is the bubble's LAST row.
|
||||
Inside the row the insertion order is Tune → Retry (the
|
||||
markLastRetryable re-append) → Save-as-doc."""
|
||||
js = _js()
|
||||
branch = _done_branch(js)
|
||||
for marker in (
|
||||
"appendSources(wrap, ev.sources);",
|
||||
"appendRelated(wrap, ev.related);",
|
||||
"appendTuneButton(wrap);",
|
||||
"markLastRetryable();",
|
||||
'appendSaveAsDocButton(wrap, finalText || acc || "…");',
|
||||
):
|
||||
assert marker in branch, f"the done branch must keep {marker!r}"
|
||||
order = [
|
||||
branch.index("appendSources(wrap, ev.sources);"),
|
||||
branch.index("appendRelated(wrap, ev.related);"),
|
||||
branch.index("appendTuneButton(wrap);"),
|
||||
branch.index("markLastRetryable();"),
|
||||
branch.index('appendSaveAsDocButton(wrap, finalText || acc || "…");'),
|
||||
]
|
||||
assert order == sorted(order), (
|
||||
"done branch: sources → related → Tune → Retry → Save-as-doc "
|
||||
"(the .msg-actions row is the bubble's LAST row — phase 130 "
|
||||
"task 02; the row's inner order is the insertion order)"
|
||||
)
|
||||
# lastBrainWrap is set before the Retry re-append reads it.
|
||||
assert branch.index("lastBrainWrap = wrap") < branch.index(
|
||||
"markLastRetryable();"
|
||||
)
|
||||
|
||||
|
||||
def test_zero_frame_fallback_appends_actions_last() -> None:
|
||||
"""The zero-frame-but-completed fallback bubble (the stream
|
||||
settled with no events): a failed turn — Tune + the Failed note +
|
||||
Retry (markLastRetryable) + Save-as-doc, all in the bubble's
|
||||
.msg-actions row (the only row it has), the note BEFORE the Retry
|
||||
re-append (the 'note + Retry' reading), the save button LAST in
|
||||
the row (the phase-59 parity with the done path)."""
|
||||
js = _js()
|
||||
zero = js.index("if (!aborted && !wrap) {")
|
||||
block = js[zero : js.index("} catch (err) {", zero)]
|
||||
for marker in (
|
||||
"appendTuneButton(fwrap);",
|
||||
"appendFailedNote(fwrap, nothing);",
|
||||
"markLastRetryable();",
|
||||
"appendSaveAsDocButton(fwrap, fallback);",
|
||||
):
|
||||
assert marker in block, f"the fallback block must keep {marker!r}"
|
||||
order = [
|
||||
block.index("appendTuneButton(fwrap);"),
|
||||
block.index("appendFailedNote(fwrap, nothing);"),
|
||||
block.index("markLastRetryable();"),
|
||||
block.index("appendSaveAsDocButton(fwrap, fallback);"),
|
||||
]
|
||||
assert order == sorted(order), (
|
||||
"fallback: Tune → Failed note → Retry → Save-as-doc — the "
|
||||
"actions row holds the whole cluster (phase 130 task 02)"
|
||||
)
|
||||
|
||||
|
||||
def test_stop_finalize_appends_actions_last() -> None:
|
||||
"""The stop finalize (a stopped partial — the prime retry
|
||||
candidate): Tune + the Stopped note + Retry (markLastRetryable),
|
||||
all in the actions row — the stop path renders no sources or
|
||||
related rows, so the actions row IS the bubble's only (and last)
|
||||
row. The order is Tune → note → Retry (the 'note + Retry'
|
||||
reading), unchanged from pre-phase (no save button — a stopped
|
||||
partial is a note, not an answer)."""
|
||||
js = _js()
|
||||
catch = js.index("} catch (err) {")
|
||||
stop = js.index('stoppedByUser || err?.name === "AbortError"', catch)
|
||||
branch = js[stop : js.index("} else {", stop)]
|
||||
for marker in (
|
||||
"appendTuneButton(wrap);",
|
||||
"appendStoppedNote(wrap);",
|
||||
"markLastRetryable();",
|
||||
):
|
||||
assert marker in branch, f"the stop branch must keep {marker!r}"
|
||||
order = [
|
||||
branch.index("appendTuneButton(wrap);"),
|
||||
branch.index("appendStoppedNote(wrap);"),
|
||||
branch.index("markLastRetryable();"),
|
||||
]
|
||||
assert order == sorted(order), (
|
||||
"stop: Tune → Stopped note → Retry (phase 130 task 02 — the "
|
||||
"note + Retry in the actions row)"
|
||||
)
|
||||
assert "appendSaveAsDocButton" not in branch, (
|
||||
"the stopped partial (note, not answer) still gets no save button"
|
||||
)
|
||||
|
||||
|
||||
def test_failed_funnel_note_and_retry_join_the_actions_row() -> None:
|
||||
"""The phase-120 failure funnel (finalizeFailedTurn): the Failed
|
||||
note is appended and the funnel ENDS with markLastRetryable — the
|
||||
note + Retry in the failed bubble's actions row (the partial
|
||||
keeps its streamed text; the zero-frame shape gets a plain
|
||||
FAILED_TURN_TEXT bubble). Both shapes end retryable."""
|
||||
js = _js()
|
||||
header = (
|
||||
"function finalizeFailedTurn(detail, "
|
||||
"{ acc, thinking, tools, wrap, leavePartialIndex }) {"
|
||||
)
|
||||
body = _fn_body(js, header)
|
||||
assert body.count("appendFailedNote(") == 2, (
|
||||
"both funnel shapes add the in-bubble error note"
|
||||
)
|
||||
lines = [line for line in body.splitlines() if line.strip()]
|
||||
assert lines[-1].strip() == "}" and lines[-2].strip().startswith(
|
||||
"markLastRetryable();"
|
||||
), (
|
||||
"the funnel still ends with the markLastRetryable() call — the "
|
||||
"Retry button lands on the failed bubble's actions row"
|
||||
)
|
||||
|
||||
|
||||
def test_restore_path_appends_actions_last() -> None:
|
||||
"""The phase-14 restore path (renderStoredMessage): the answer
|
||||
figure → sources → related → the action appenders (Tune /
|
||||
Save-as-doc / the Stopped + Failed notes) — so the .msg-actions
|
||||
row a restored bubble gets is its LAST row too, identical to the
|
||||
live done path. The restore loop's after-the-loop
|
||||
markLastRetryable() then lands the Retry button in that same row
|
||||
(on the LAST restored brain bubble)."""
|
||||
js = _js()
|
||||
body = _fn_body(js, "function renderStoredMessage(m) {")
|
||||
for marker in (
|
||||
"appendSources(wrap, m.sources);",
|
||||
"appendRelated(wrap, m.related);",
|
||||
"appendTuneButton(wrap)",
|
||||
"appendSaveAsDocButton(wrap, m.text);",
|
||||
"appendStoppedNote(wrap);",
|
||||
"appendFailedNote(wrap, m.error);",
|
||||
"lastBrainWrap = wrap",
|
||||
):
|
||||
assert marker in body, f"the restore path must keep {marker!r}"
|
||||
order = [
|
||||
body.index("appendSources(wrap, m.sources);"),
|
||||
body.index("appendRelated(wrap, m.related);"),
|
||||
body.index("appendTuneButton(wrap)"),
|
||||
body.index("appendSaveAsDocButton(wrap, m.text);"),
|
||||
body.index("lastBrainWrap = wrap"),
|
||||
]
|
||||
assert order == sorted(order), (
|
||||
"restore: sources → related → the action appenders → "
|
||||
"lastBrainWrap (the after-the-loop markLastRetryable lands the "
|
||||
"Retry in the same actions row — phase 130 task 02)"
|
||||
)
|
||||
@@ -0,0 +1,245 @@
|
||||
"""Unit: the phase-130 (task 03, TODO L6) chat cluster rows — CSS.
|
||||
|
||||
The bubble's metadata reads as organized rows, top to bottom: the
|
||||
answer text → the answer figure (phase 124, unchanged) → the source
|
||||
chips row (text refs only) → the source images row (`.msg-images`,
|
||||
phase 130 task 01) → the "Nearby docs" row (phase 113, unchanged) →
|
||||
the actions row (`.msg-actions`, phase 130 task 02) — never one soup
|
||||
div. The DOM is built by app.js (pinned by test_frontend_actions_cluster
|
||||
and test_source_chip_quality); THIS module pins the row-level layout
|
||||
that makes the clusters read as clusters:
|
||||
|
||||
* the actions row right-aligns its buttons as a cluster — the "bottom
|
||||
right" is the row's ``justify-content: flex-end``, and the
|
||||
per-button auto margins (the phase-49/59 ``.tune-btn`` /
|
||||
``.retry-btn`` / ``.save-as-doc-btn`` margin mechanisms) are GONE;
|
||||
* the images row wraps its figures with the chips row's rhythm (the
|
||||
base ``.msg-meta`` wrap + 0.35rem gap + center align — pinned
|
||||
explicitly so the two clusters cannot drift apart);
|
||||
* the audit (task 03 item 3): the chips row and the related row are
|
||||
untouched, the ``.source-image`` figure styles are untouched, and
|
||||
the mobile squeeze pins nothing about the actions row left — the
|
||||
cluster stays right-aligned at every width.
|
||||
|
||||
House source-pin pattern (no browser); the browser-level bounding-box
|
||||
assertions are E2E-gated by tests/e2e/test_chat_answer_clusters.py
|
||||
(task 04).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
STYLES_CSS = Path(__file__).resolve().parents[2] / "frontend" / "assets" / "styles.css"
|
||||
|
||||
|
||||
def _css() -> str:
|
||||
return STYLES_CSS.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _block(css: str, selector: str) -> str:
|
||||
"""The first ``<selector> { … }`` rule body — the house pin
|
||||
pattern (the cluster selectors are unique in the sheet)."""
|
||||
m = re.search(re.escape(selector) + r" \{([^}]*)\}", css)
|
||||
assert m, f"styles.css must style {selector}"
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def _media_block(css: str, query: str) -> str:
|
||||
"""The body of the ``@media (<query>)`` block — the house non-
|
||||
greedy pattern (the sheet indents the block's nested closing
|
||||
braces, so the FIRST column-0 ``}`` is the block's own end)."""
|
||||
pattern = "@media \\(" + re.escape(query) + r"\) \{([\s\S]*?)\n\}"
|
||||
m = re.search(pattern, css)
|
||||
assert m, f"{query} media query missing"
|
||||
return m.group(1)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the actions cluster — right-aligned by the ROW, no per-button margins
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_actions_row_rule_right_aligns_the_cluster() -> None:
|
||||
"""``.msg-meta.msg-actions`` right-aligns its contents — the TODO's
|
||||
"bottom right" is the bubble's LAST row (the DOM order, phase 130
|
||||
task 02) + this row-level justify. No positioning tricks: the row
|
||||
keeps the base .msg-meta flex/wrap/rhythm, only the justify moves."""
|
||||
css = _css()
|
||||
assert re.search(r"\.msg-meta\.msg-actions \{", css), (
|
||||
"the .msg-meta.msg-actions row rule is missing"
|
||||
)
|
||||
body = _block(css, ".msg-meta.msg-actions")
|
||||
assert "justify-content: flex-end" in body, (
|
||||
"the row's justify does the 'bottom right' (right edge)"
|
||||
)
|
||||
# Row-level only — no absolute/float/transform tricks.
|
||||
for prop in ("position", "float", "transform", "margin", "padding"):
|
||||
assert prop not in body, (
|
||||
f"the actions row is a plain flex row ({prop} is a "
|
||||
"positioning trick — the row order is DOM order)"
|
||||
)
|
||||
|
||||
|
||||
def test_no_per_button_auto_margins_remain() -> None:
|
||||
"""The per-button auto margins (the pre-phase-130 mechanism the
|
||||
markLastRetryable comment named) are gone from ALL THREE action
|
||||
buttons — grep-confirmed: the buttons are plain flex items of the
|
||||
actions row, and the row's justify does the alignment. (Completion
|
||||
criterion: 'right-aligned by .msg-actions alone'.)"""
|
||||
css = _css()
|
||||
for selector in (".tune-btn", ".retry-btn", ".save-as-doc-btn"):
|
||||
body = _block(css, selector)
|
||||
assert "margin-left: auto" not in body, (
|
||||
f"{selector}: the per-button auto margin must be gone — "
|
||||
"the .msg-actions row's justify right-aligns the cluster"
|
||||
)
|
||||
assert "margin-inline-start: auto" not in body, (
|
||||
f"{selector}: the per-button auto margin must be gone"
|
||||
)
|
||||
assert "margin-right: auto" not in body and "margin-inline-end: auto" not in body
|
||||
|
||||
|
||||
def test_button_family_is_untouched() -> None:
|
||||
"""Removing the auto margins is the ONLY change to the button
|
||||
rules — the phase-49/59 visual family (pill, ≥44px, line border,
|
||||
ink-soft palette, brand/neutral hovers, 14px glyph) is intact."""
|
||||
css = _css()
|
||||
for selector in (".tune-btn", ".retry-btn", ".save-as-doc-btn"):
|
||||
body = _block(css, selector)
|
||||
for prop in (
|
||||
"display: inline-flex",
|
||||
"min-height: 44px",
|
||||
"padding: 0.35rem 0.8rem",
|
||||
"border-radius: 999px",
|
||||
"border: 1px solid var(--line)",
|
||||
"color: var(--ink-soft)",
|
||||
"font-size: 0.82rem",
|
||||
"cursor: pointer",
|
||||
):
|
||||
assert prop in body, f"{selector} must keep the family ({prop})"
|
||||
assert f"{selector} svg {{ width: 14px; height: 14px" in css
|
||||
assert f"{selector}:hover" in css
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the images cluster — wraps like the chips row
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_images_row_rule_wraps_like_the_chips_row() -> None:
|
||||
"""``.msg-meta.msg-images`` pins the chips row's rhythm EXPLICITLY
|
||||
(wrap + the base .msg-meta 0.35rem gap + center align) — no new
|
||||
spacing values (task 03: 'match the EXISTING .msg-meta gap/align
|
||||
values'). A future base-rule change cannot drift the two clusters
|
||||
apart."""
|
||||
css = _css()
|
||||
assert re.search(r"\.msg-meta\.msg-images \{", css), (
|
||||
"the .msg-meta.msg-images row rule is missing"
|
||||
)
|
||||
body = _block(css, ".msg-meta.msg-images")
|
||||
assert "flex-wrap: wrap" in body, "the figures wrap (many image refs)"
|
||||
assert "gap: 0.35rem" in body, (
|
||||
"the images row's gap MUST equal the chips row's gap "
|
||||
"(the base .msg-meta 0.35rem — no invented spacing)"
|
||||
)
|
||||
assert "align-items: center" in body, "the row aligns like the chips row"
|
||||
|
||||
|
||||
def test_base_msg_meta_rhythm_is_unchanged() -> None:
|
||||
"""The base ``.msg-meta`` rule (the chips row, the related row, and
|
||||
every meta row's rhythm) is untouched: flex + wrap + 0.35rem gap +
|
||||
center align + the soft-ink 0.75rem text."""
|
||||
css = _css()
|
||||
body = _block(css, ".msg-meta")
|
||||
for prop in (
|
||||
"font-size: 0.75rem",
|
||||
"color: var(--ink-soft)",
|
||||
"display: flex",
|
||||
"flex-wrap: wrap",
|
||||
"gap: 0.35rem",
|
||||
"align-items: center",
|
||||
):
|
||||
assert prop in body, f"the base .msg-meta rhythm must keep {prop}"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# the audit (task 03 item 3) — neighbors untouched
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
def test_chips_row_is_untouched() -> None:
|
||||
"""The chips row's look is the completed phase-26/113 surface —
|
||||
mono pill, brand-soft fill, line border, nowrap ellipsis (the
|
||||
min-width: 0 escape). Phase 130 only removed the buttons from this
|
||||
row's neighbors, never the chip's styling."""
|
||||
css = _css()
|
||||
body = _block(css, ".source-chip")
|
||||
for prop in (
|
||||
"font-family: var(--mono)",
|
||||
"background: var(--brand-soft)",
|
||||
"border: 1px solid var(--line)",
|
||||
"border-radius: 999px",
|
||||
"white-space: nowrap",
|
||||
"min-width: 0",
|
||||
"text-overflow: ellipsis",
|
||||
):
|
||||
assert prop in body, f".source-chip must keep {prop}"
|
||||
assert ".source-chip:hover" in css
|
||||
|
||||
|
||||
def test_related_row_is_untouched() -> None:
|
||||
"""The phase-113 "Nearby docs" row keeps its de-emphasized look
|
||||
(dashed border, transparent fill, muted mono links — never a
|
||||
citation) and still joins the .msg-meta family."""
|
||||
css = _css()
|
||||
body = _block(css, ".related-doc")
|
||||
for prop in (
|
||||
"border: 1px dashed var(--line)",
|
||||
"background: transparent",
|
||||
"font-family: var(--mono)",
|
||||
"white-space: nowrap",
|
||||
):
|
||||
assert prop in body, f".related-doc must keep {prop}"
|
||||
assert ".related-docs-label" in css
|
||||
assert "Nearby docs" not in css # the label text lives in app.js, not CSS
|
||||
|
||||
|
||||
def test_source_image_figure_is_untouched() -> None:
|
||||
"""The ``.source-image`` figure (phase 122) was already sized for a
|
||||
row context — the 96px contain img on the theme's surface, the
|
||||
clamped muted caption. Phase 130 moves it to its OWN row, not to a
|
||||
new scale."""
|
||||
css = _css()
|
||||
assert "max-height: 96px" in _block(css, ".source-image-img"), (
|
||||
"the compact source figure keeps its 96px row-scale cap"
|
||||
)
|
||||
assert "object-fit: contain" in _block(css, ".source-image-img")
|
||||
assert "-webkit-line-clamp: 2" in _block(css, ".source-image-caption")
|
||||
# The answer figure (phase 124) is a DIFFERENT scale — untouched.
|
||||
assert "max-height: 320px" in _block(css, ".answer-image-img")
|
||||
|
||||
|
||||
def test_mobile_pins_the_actions_row_left_nowhere() -> None:
|
||||
"""The mobile squeeze (≤640px) may keep the ≥44px touch floor but
|
||||
must NOT pin the actions row left or restyle it: the cluster stays
|
||||
right-aligned at every width (the row's justify is width-agnostic,
|
||||
the .msg-body flex gap stacks the rows)."""
|
||||
css = _css()
|
||||
mobile = _media_block(css, "max-width: 640px")
|
||||
for selector in (".tune-btn", ".retry-btn", ".msg-actions", ".msg-images"):
|
||||
for m in re.finditer(re.escape(selector) + r" \{([^}]*)\}", mobile):
|
||||
body = m.group(1)
|
||||
assert "justify-content" not in body, (
|
||||
f"{selector}: the mobile block must not re-justify the "
|
||||
"cluster (the actions row stays right-aligned)"
|
||||
)
|
||||
assert "margin-left" not in body and "margin-inline" not in body, (
|
||||
f"{selector}: the mobile block must not re-margin the "
|
||||
"cluster (no left pin, no margin reset)"
|
||||
)
|
||||
assert "position" not in body
|
||||
# The mobile squeeze's only tune/retry rules are the 44px floors
|
||||
# (pre-existing, untouched by this phase).
|
||||
assert ".tune-btn { min-height: 44px; }" in mobile
|
||||
assert ".retry-btn { min-height: 44px; }" in mobile
|
||||
@@ -84,12 +84,16 @@ def _fn_body(js: str, name: str) -> str:
|
||||
|
||||
def test_append_failed_note_exists_and_guards_dedup() -> None:
|
||||
"""``appendFailedNote(wrap, detail)`` exists and mirrors
|
||||
``appendStoppedNote``: it reuses the ``.msg-meta`` row and adds at
|
||||
``appendStoppedNote``: it joins the bubble's ``.msg-actions`` row
|
||||
(getActionsRow — phase 130 task 02, ASSUMPTION A7: the notes are
|
||||
answer-status markers, the actions row is their home) and adds at
|
||||
most ONE ``.failed-note`` per bubble (the duplicate guard)."""
|
||||
js = _js()
|
||||
body = _fn_body(js, "appendFailedNote")
|
||||
assert '.msg-body' in body, "the note must land in the bubble's .msg-body"
|
||||
assert ".msg-meta" in body, "the note rides the existing .msg-meta row"
|
||||
assert "getActionsRow(wrap)" in body, (
|
||||
"the note joins the dedicated .msg-actions row (getActionsRow — "
|
||||
"phase 130 task 02), never the first .msg-meta row"
|
||||
)
|
||||
assert '.failed-note' in body
|
||||
assert (
|
||||
'if (meta.querySelector(".failed-note")) return;' in body
|
||||
|
||||
@@ -313,18 +313,22 @@ def test_stop_branch_keeps_partial_and_persists_stopped() -> None:
|
||||
|
||||
|
||||
def test_stopped_note_helper_and_restore_path() -> None:
|
||||
"""appendStoppedNote: reuses/creates the .msg-meta row exactly like
|
||||
appendTuneButton (role=list → the span joins as a listitem), one
|
||||
.stopped-note per bubble — the aria-hidden stop-glyph SVG + the
|
||||
"Stopped" text (the accessible meaning). The restore path renders it
|
||||
for records with `m.stopped` (phase-14 optional-field convention —
|
||||
no version bump)."""
|
||||
"""appendStoppedNote: joins the bubble's ACTIONS row (getActionsRow
|
||||
— phase 130 task 02, ASSUMPTION A7: the notes are answer-status
|
||||
markers, the actions row is their home; the role=list row joins the
|
||||
span as a listitem so ARIA stays valid), one .stopped-note per
|
||||
bubble — the aria-hidden stop-glyph SVG + the "Stopped" text (the
|
||||
accessible meaning). The restore path renders it for records with
|
||||
`m.stopped` (phase-14 optional-field convention — no version
|
||||
bump)."""
|
||||
js = _js()
|
||||
fn = js.find("function appendStoppedNote")
|
||||
assert fn != -1, "appendStoppedNote must exist"
|
||||
body = js[fn : js.find("\n}\n", fn)]
|
||||
assert 'querySelector(".msg-meta")' in body, "reuses the meta row when it exists"
|
||||
assert 'className = "msg-meta"' in body, "creates it otherwise"
|
||||
assert "getActionsRow(wrap)" in body, (
|
||||
"the note joins the dedicated .msg-actions row (getActionsRow — "
|
||||
"phase 130 task 02), never the first .msg-meta row"
|
||||
)
|
||||
assert 'className = "stopped-note"' in body
|
||||
assert 'querySelector(".stopped-note")' in body, "one note per bubble"
|
||||
assert 'note.setAttribute("role", "listitem")' in body
|
||||
@@ -443,19 +447,22 @@ def test_run_turn_is_the_extracted_turn_handler() -> None:
|
||||
|
||||
|
||||
def test_retry_button_is_not_admin_gated_and_one_per_bubble() -> None:
|
||||
"""appendRetryButton: the house appendTuneButton pattern — reuses the
|
||||
.msg-meta row when it exists (role=list → the button joins as a
|
||||
listitem so ARIA stays valid), creates it otherwise, one .retry-btn
|
||||
per bubble, the aria-hidden redo glyph + the "Retry" text (the
|
||||
accessible name). NOT admin-gated — unlike appendTuneButton, chat is
|
||||
public and every visitor gets the redo (owner-locked)."""
|
||||
"""appendRetryButton: the house pattern through getActionsRow
|
||||
(phase 130 task 02 — the button joins the bubble's dedicated
|
||||
.msg-actions row; the role=list row joins it as a listitem so ARIA
|
||||
stays valid), one .retry-btn per bubble, the aria-hidden redo glyph
|
||||
+ the "Retry" text (the accessible name). NOT admin-gated — unlike
|
||||
appendTuneButton, chat is public and every visitor gets the redo
|
||||
(owner-locked)."""
|
||||
js = _js()
|
||||
fn = js.find("function appendRetryButton")
|
||||
assert fn != -1, "appendRetryButton must exist"
|
||||
body = js[fn: js.find("\n}\n", fn)]
|
||||
assert "isAdmin" not in body, "Retry is NOT admin-gated (owner-locked: all visitors)"
|
||||
assert 'querySelector(".msg-meta")' in body, "reuses the meta row when it exists"
|
||||
assert 'className = "msg-meta"' in body, "creates it otherwise"
|
||||
assert "getActionsRow(wrap)" in body, (
|
||||
"the button joins the dedicated .msg-actions row (getActionsRow — "
|
||||
"phase 130 task 02), never the first .msg-meta row"
|
||||
)
|
||||
assert 'className = "retry-btn"' in body
|
||||
assert 'querySelector(".retry-btn")' in body, "one Retry button per bubble"
|
||||
assert 'btn.setAttribute("role", "listitem")' in body, ("role=list → listitem")
|
||||
@@ -584,12 +591,14 @@ def test_last_brain_wrap_tracking_and_restore() -> None:
|
||||
|
||||
def test_retry_btn_css_is_the_tune_family() -> None:
|
||||
"""Phase 49 styling: the .retry-btn pill is the exact .tune-btn
|
||||
visual family (same size/spacing/min-height, right-aligned after
|
||||
the source chips, 14px glyph) so the two meta actions read as a
|
||||
pair — with the neutral ink-soft → ink hover (Tune keeps the brand
|
||||
pair). Contrast: ink-soft on --bg ~8.6:1, ink ~15:1, hover ink on
|
||||
--brand-soft ~15.7:1 — all AA. The mobile squeeze keeps the >=44px
|
||||
floor."""
|
||||
visual family (same size/spacing/min-height, 14px glyph) so the
|
||||
meta actions read as a pair — with the neutral ink-soft → ink
|
||||
hover (Tune keeps the brand pair). The right-align moved to the
|
||||
ROW in phase 130 (the .msg-meta.msg-actions justify — the button
|
||||
is a plain flex item with NO per-button auto margin; the
|
||||
cluster-level pin lives in test_frontend_cluster_css). Contrast:
|
||||
ink-soft on --bg ~8.6:1, ink ~15:1, hover ink on --brand-soft
|
||||
~15.7:1 — all AA. The mobile squeeze keeps the >=44px floor."""
|
||||
css = _css()
|
||||
block = re.search(r"\.retry-btn \{([\s\S]*?)\n\}", css)
|
||||
assert block, "styles.css must style .retry-btn"
|
||||
@@ -597,7 +606,6 @@ def test_retry_btn_css_is_the_tune_family() -> None:
|
||||
for prop in (
|
||||
"display: inline-flex",
|
||||
"min-height: 44px",
|
||||
"margin-left: auto",
|
||||
"padding: 0.35rem 0.8rem",
|
||||
"border-radius: 999px",
|
||||
"border: 1px solid var(--line)",
|
||||
@@ -606,6 +614,10 @@ def test_retry_btn_css_is_the_tune_family() -> None:
|
||||
"cursor: pointer",
|
||||
):
|
||||
assert prop in body, f".retry-btn must keep the .tune-btn family ({prop})"
|
||||
assert "margin-left: auto" not in body and "margin-inline-start: auto" not in body, (
|
||||
"phase 130: the per-button auto margin is gone — the row's "
|
||||
".msg-actions justify right-aligns the cluster"
|
||||
)
|
||||
assert re.search(r"\.retry-btn svg \{ width: 14px; height: 14px", css), (
|
||||
"the redo glyph rides the 14px meta-row size"
|
||||
)
|
||||
|
||||
@@ -51,12 +51,19 @@ image doc prefacing the description with the pinned
|
||||
``IMAGE_DOC_MARKER`` line (header + date line byte-identical, the
|
||||
cap-truncation case marker-before-cut, a text doc's result
|
||||
byte-identical); and the house-style frontend source contracts — the
|
||||
chat sources block's inline image figure (both the citation chips and
|
||||
the related row, gated on ``s.image_url``) reads ``image_url``, sets
|
||||
chat sources block's inline image figure reads ``image_url``, sets
|
||||
``alt`` + the visible caption to the document's summary (fetched from
|
||||
the content endpoint the chip's modal already uses — the frame
|
||||
carries no summary), and collapses to the plain chip on an image
|
||||
load error (never a broken-image icon). The SSE-level byte pin sits in
|
||||
carries no summary), and becomes the IN-PLACE CHIP FALLBACK on an
|
||||
image load error (phase 130 task 01: the figure is replaced, in
|
||||
place, with a plain chip for the same document — never a broken-image
|
||||
icon; the pre-phase-130 rule collapsed by removing the figure, the
|
||||
chip staying). Phase 130 (task 01) also re-partitions the citation
|
||||
block: the chips row holds the NON-image refs only (no chip for an
|
||||
image doc — its figure IS the citation) and a second
|
||||
``.msg-meta.msg-images`` row holds the figures in ref order (the
|
||||
related row keeps its own interleave, unchanged — ASSUMPTION A4).
|
||||
The SSE-level byte pin sits in
|
||||
``tests/integration/test_chat_api.py``; the E2E rendering scenario is
|
||||
task 06's isolated story suite.
|
||||
"""
|
||||
@@ -1342,16 +1349,23 @@ def test_read_of_image_doc_over_the_cap_truncates_after_the_marker(db) -> None:
|
||||
# --- the chat sources block: the inline image (house-style frontend)
|
||||
|
||||
|
||||
def test_chat_sources_figure_reads_image_url_sets_alt_and_collapses_on_error() -> None:
|
||||
def test_chat_sources_figure_reads_image_url_sets_alt_and_falls_back_in_place() -> None:
|
||||
"""House-style source contract (app.js appendSourceImageFigure —
|
||||
task 05's "shown in the chat nicely" renderer): the figure's
|
||||
``<img>`` comes from the ref's ``image_url``; ``alt`` is set
|
||||
(title first, then the SUMMARY once the content fetch settles —
|
||||
the frame carries no summary, image_url is its only new field)
|
||||
and so is the VISIBLE caption; a FAILED image load removes the
|
||||
whole figure — it collapses to the plain chip, never a
|
||||
broken-image icon. Properties only (src/alt/textContent) — the
|
||||
figure builds no innerHTML from document-derived data."""
|
||||
and so is the VISIBLE caption. Phase 130 (task 01, ASSUMPTION A3)
|
||||
REPLACES the old collapse-to-chip rule (``fig.remove()`` — the
|
||||
chip stayed) with the IN-PLACE CHIP FALLBACK: a FAILED image load
|
||||
replaces the figure, in place (``fig.replaceWith(chip)``), with a
|
||||
plain ``.source-chip`` anchor for the same document (the same
|
||||
``documentUrl`` href, the same left-click → modal, the label as
|
||||
text) — there is no chip for image docs anymore, so the figure
|
||||
itself becomes the citation; never a broken-image icon. The fetch
|
||||
summary swap is untouched (its ``!fig.isConnected`` guard makes it
|
||||
a no-op after the swap). Properties only (src/alt/textContent) —
|
||||
the figure builds no innerHTML from document-derived data."""
|
||||
js = APP_JS.read_text(encoding="utf-8")
|
||||
body = _function_body(js, "function appendSourceImageFigure(meta, s) {")
|
||||
assert "img.src = s.image_url" in body, "the <img> must come from s.image_url"
|
||||
@@ -1360,10 +1374,34 @@ def test_chat_sources_figure_reads_image_url_sets_alt_and_collapses_on_error() -
|
||||
assert "caption.textContent = s.title || label" in body # visible caption: title
|
||||
assert "caption.textContent = summary" in body # …then the summary
|
||||
assert 'img.addEventListener("error"' in body, "the error handler must exist"
|
||||
assert "fig.remove();" in body, "a failed load collapses to the plain chip"
|
||||
assert "fig.remove()" not in body, (
|
||||
"the phase-122 collapse rule is RETIRED — the figure is never "
|
||||
"simply removed (there is no chip left behind to stay)"
|
||||
)
|
||||
# Phase 130 (task 01): the in-place chip fallback — the figure is
|
||||
# replaced with a plain .source-chip anchor for the same document.
|
||||
assert "fig.replaceWith(chip);" in body, (
|
||||
"a failed load replaces the figure IN PLACE with its chip"
|
||||
)
|
||||
assert 'chip.className = "source-chip";' in body, (
|
||||
"the fallback is a PLAIN citation chip"
|
||||
)
|
||||
assert 'chip.setAttribute("role", "listitem");' in body # ARIA stays valid
|
||||
assert 'chip.href = documentUrl(s.source, s.path, "/");' in body, (
|
||||
"the fallback chip keeps the chip's /document.html href"
|
||||
)
|
||||
assert "openDocumentModal(s.source, s.path, chip);" in body, (
|
||||
"the fallback chip keeps the left-click → same-page modal"
|
||||
)
|
||||
assert "e.preventDefault();" in body # no new tab (phase 26)
|
||||
assert "chip.textContent = label;" in body, ("the label is the chip's text")
|
||||
assert "chip.title = label;" in body # full path as the native tooltip
|
||||
assert "fetchContentSummary(s.source, s.path)" in body, (
|
||||
"the frame carries no summary — the figure fetches it"
|
||||
)
|
||||
assert "if (!fig.isConnected) return;" in body, (
|
||||
"the summary swap is a no-op once the figure was replaced"
|
||||
)
|
||||
code = re.sub(r"//.*", "", re.sub(r"/\*.*?\*/", "", body, flags=re.S))
|
||||
assert "innerHTML" not in code, "no innerHTML from document-derived data"
|
||||
# The figure reuses the chip's navigation (phase 26 contract):
|
||||
@@ -1371,20 +1409,55 @@ def test_chat_sources_figure_reads_image_url_sets_alt_and_collapses_on_error() -
|
||||
assert "openDocumentModal(s.source, s.path, fig);" in body
|
||||
|
||||
|
||||
def test_chat_sources_and_related_rows_gate_the_figure_on_image_url() -> None:
|
||||
"""Both chat source surfaces (the citation chips AND the related
|
||||
row — the frame's two ref tiers, built by the same server helper)
|
||||
render the figure ONLY when the ref carries ``image_url``: text
|
||||
refs (and every pre-phase saved ref) add zero new DOM — the
|
||||
renderer stays byte-identical for them. The chip's text +
|
||||
affordance stay (the figure is additive, not a replacement), and
|
||||
the summary fetch targets the SAME content endpoint the chip's
|
||||
modal already uses (failing soft to null — the title stands)."""
|
||||
def test_chat_sources_splits_the_chips_row_from_the_images_row() -> None:
|
||||
"""Phase 130 (task 01, TODO L6): ``appendSources`` stops
|
||||
interleaving figures after chips — it PARTITIONS the refs on the
|
||||
existing image-doc signal (the ``image_url`` presence, phase 122)
|
||||
and builds two clusters: the chips row from the NON-image refs
|
||||
ONLY (no chip for an image doc — the figure IS the citation) and
|
||||
a second ``.msg-meta.msg-images`` row (``role=list`` +
|
||||
``aria-label="Source images"``) holding one figure per image ref
|
||||
in ref order. Each row is built only when its refs are non-empty
|
||||
(image-only citations get no chips row; text-only turns render
|
||||
the pre-phase-130 single row). The clipped-chip ``aria-label``
|
||||
pass stays, over the chips row only. The related row is a
|
||||
separate tier and is NOT reorganized (ASSUMPTION A4 — its own
|
||||
chip/figure interleave is untouched), and the summary fetch
|
||||
targets the SAME content endpoint the chip's modal already uses
|
||||
(failing soft to null — the title stands)."""
|
||||
js = APP_JS.read_text(encoding="utf-8")
|
||||
src = _function_body(js, "function appendSources(wrap, sources) {")
|
||||
assert 'if (s.image_url) appendSourceImageFigure(meta, s);' in src
|
||||
assert 'chip.className = "source-chip";' in src, "the chip stays (additive)"
|
||||
# The partition (the `image_url` presence is the image-doc signal):
|
||||
assert "const imageRefs = sources.filter((s) => s.image_url);" in src
|
||||
assert "const textRefs = sources.filter((s) => !s.image_url);" in src
|
||||
# Cluster 1 — the chips row, text refs only, skipped when empty:
|
||||
assert "if (textRefs.length) {" in src, (
|
||||
"the chips row is skipped when there are no text refs "
|
||||
"(an image-only citation still gets its images row)"
|
||||
)
|
||||
assert "for (const s of textRefs) {" in src, (
|
||||
"one chip per NON-image ref — an image ref contributes NO chip"
|
||||
)
|
||||
assert 'meta.className = "msg-meta";' in src
|
||||
assert 'meta.setAttribute("aria-label", "Sources");' in src # ARIA name kept
|
||||
assert 'chip.className = "source-chip";' in src
|
||||
assert "chip.textContent = label" in src
|
||||
# The clipped-chip aria-label pass stays, over the chips row only:
|
||||
assert "chip.scrollWidth > chip.clientWidth" in src
|
||||
# Cluster 2 — the images row, image refs only, absent when empty:
|
||||
assert "if (imageRefs.length) {" in src, (
|
||||
"the images row is built only when image refs exist"
|
||||
)
|
||||
assert 'images.className = "msg-meta msg-images";' in src
|
||||
assert 'images.setAttribute("role", "list");' in src
|
||||
assert 'images.setAttribute("aria-label", "Source images");' in src
|
||||
assert "for (const s of imageRefs) appendSourceImageFigure(images, s);" in src, (
|
||||
"one figure per image ref, in ref order, no chips in the row"
|
||||
)
|
||||
# The phase-122 interleave is gone from appendSources (the figure
|
||||
# no longer rides right after a chip in the chips row):
|
||||
assert "if (s.image_url) appendSourceImageFigure(meta, s);" not in src
|
||||
# The related tier is NOT reorganized (ASSUMPTION A4):
|
||||
rel = _function_body(js, "function appendRelated(wrap, related) {")
|
||||
assert 'if (s.image_url) appendSourceImageFigure(row, s);' in rel
|
||||
fetch = _function_body(js, "function fetchContentSummary(source, path) {")
|
||||
|
||||
@@ -139,8 +139,9 @@ def test_app_js_button_gates_on_admin_and_configured() -> None:
|
||||
"""The single guard: admin (the whoami gate Tune uses) AND
|
||||
docs_repo_configured — otherwise the function injects NOTHING
|
||||
(anonymous, or unconfigured admin, or deflected scope — same as
|
||||
Tune). One button per bubble; the .msg-meta row is reused (or
|
||||
created plain) and a role=list row gets a listitem button (ARIA)."""
|
||||
Tune). One button per bubble; the button joins the bubble's
|
||||
.msg-actions row (getActionsRow — phase 130 task 02; the role=list
|
||||
row gets a listitem button, ARIA)."""
|
||||
js = _text(APP_JS)
|
||||
fn_idx = js.find("function appendSaveAsDocButton(wrap, markdown) {")
|
||||
assert fn_idx != -1, "appendSaveAsDocButton missing"
|
||||
@@ -354,23 +355,36 @@ def test_app_js_post_payload_and_navigation() -> None:
|
||||
assert "Couldn't save the answer as a doc" in fn_body
|
||||
|
||||
|
||||
def test_app_js_retry_landing_keeps_save_rightmost() -> None:
|
||||
"""markLastRetryable re-appends the save button AFTER the Retry
|
||||
button lands on the same (last) bubble — the auto-margined buttons
|
||||
split the row's free space between them, so DOM order decides the
|
||||
right edge: "Save as doc" stays the bottom-right action even on the
|
||||
last bubble (which also carries Retry)."""
|
||||
def test_app_js_retry_landing_has_no_save_reappend_hack() -> None:
|
||||
"""Phase 130 (task 02): markLastRetryable re-appends the Retry
|
||||
button into the last bubble's .msg-actions row (appendRetryButton →
|
||||
getActionsRow) and NO LONGER re-appends the save button after it —
|
||||
the row's row-level right-align (phase 130 task 03) right-aligns
|
||||
the WHOLE cluster, and the DOM order inside the row is the
|
||||
insertion order (the live call sites append Tune → Retry →
|
||||
Save-as-doc per their gates). The phase-59 "auto margins split the
|
||||
free space" hack is gone with the per-button auto margins it worked
|
||||
around."""
|
||||
js = _text(APP_JS)
|
||||
fn_idx = js.find("function markLastRetryable() {")
|
||||
assert fn_idx != -1
|
||||
fn_end = js.find("/* Phase 59 (owner-locked 2026-08-31, TODO.md L3): the bottom-right", fn_idx)
|
||||
fn_body = js[fn_idx:fn_end]
|
||||
assert "appendRetryButton(lastBrainWrap);" in fn_body
|
||||
assert 'lastBrainWrap.querySelector(".save-as-doc-btn")' in fn_body
|
||||
# "saveDocBtn" — NOT "saveBtn": phase 55 pins the Save pill's
|
||||
# identifier gone from app.js (substring), so the local stays distinct.
|
||||
assert "saveDocBtn.parentElement.appendChild(saveDocBtn)" in fn_body
|
||||
assert "saveBtn" not in _text(APP_JS), (
|
||||
assert "appendRetryButton(lastBrainWrap);" in fn_body, (
|
||||
"the Retry button is re-appended to the last brain bubble"
|
||||
)
|
||||
assert "saveDocBtn" not in fn_body, (
|
||||
"the phase-59 save-button re-append hack is gone — the actions "
|
||||
"row's right-align (phase 130 task 03) replaces it"
|
||||
)
|
||||
assert "parentElement" not in fn_body, (
|
||||
"no DOM re-parenting of the save button anymore"
|
||||
)
|
||||
# "saveDocBtn" is gone from the WHOLE file (the hack had no other
|
||||
# home); "saveBtn" (the phase-55 retired Save pill's identifier)
|
||||
# stays absent too.
|
||||
assert "saveDocBtn" not in js
|
||||
assert "saveBtn" not in js, (
|
||||
"the phase-55 pin: no saveBtn identifier in app.js"
|
||||
)
|
||||
|
||||
@@ -381,16 +395,24 @@ def test_app_js_retry_landing_keeps_save_rightmost() -> None:
|
||||
|
||||
|
||||
def test_styles_css_save_as_doc_btn_is_right_aligned() -> None:
|
||||
""".save-as-doc-btn exists, carries the bottom-right declaration
|
||||
(margin-inline-start: auto) and the .tune-btn visual family (pill,
|
||||
>=44px target, line border, ink-soft palette); :focus-visible is
|
||||
the global rule, the hover rule is per-class."""
|
||||
""".save-as-doc-btn exists in the .tune-btn visual family (pill,
|
||||
>=44px target, line border, ink-soft palette) with NO per-button
|
||||
auto margin — phase 130 moved the bottom-right requirement to the
|
||||
ROW (the .msg-meta.msg-actions justify right-aligns the whole
|
||||
actions cluster; the cluster-level pin lives in
|
||||
test_frontend_cluster_css). :focus-visible is the global rule, the
|
||||
hover rule is per-class."""
|
||||
css = _text(STYLES_CSS)
|
||||
m = re.search(r"\.save-as-doc-btn \{[^}]*\}", css)
|
||||
assert m, "the .save-as-doc-btn rule is missing"
|
||||
block = m.group(0)
|
||||
assert "margin-inline-start: auto;" in block, (
|
||||
"the bottom-right requirement lives on the button's class"
|
||||
assert "margin-inline-start: auto" not in block and "margin-left: auto" not in block, (
|
||||
"phase 130: the per-button auto margin is gone — the row's "
|
||||
".msg-actions justify does the bottom right"
|
||||
)
|
||||
row = re.search(r"\.msg-meta\.msg-actions \{[^}]*\}", css)
|
||||
assert row and "justify-content: flex-end" in row.group(0), (
|
||||
"the bottom-right requirement now lives on the .msg-actions row"
|
||||
)
|
||||
assert "min-height: 44px;" in block # WCAG touch target (the family)
|
||||
assert "border-radius: 999px;" in block
|
||||
|
||||
@@ -223,26 +223,35 @@ def test_append_related_row_contract() -> None:
|
||||
# ---------- task 02: wiring — the done frame and the restore path ----------
|
||||
|
||||
|
||||
def test_done_handler_calls_append_related_last() -> None:
|
||||
def test_done_handler_appends_related_above_the_actions_row() -> None:
|
||||
"""The done-frame handler calls ``appendRelated(wrap, ev.related)``
|
||||
— and appends the row LAST among the bubble's meta rows: AFTER
|
||||
``markLastRetryable()`` (the appendTuneButton / appendSaveAsDoc /
|
||||
appendRetryButton claimers all take the FIRST ``.msg-meta`` row,
|
||||
so a deflected turn with related docs — no citation row — gets its
|
||||
OWN meta row for the buttons instead of actions joining the
|
||||
related row). The call sits after the Retry claim in the branch."""
|
||||
— and appends the row BELOW the citation clusters and ABOVE the
|
||||
actions row (phase 130 task 02): the action appenders (appendTune
|
||||
Button → markLastRetryable's Retry → appendSaveAsDocButton) FOLLOW
|
||||
it in the branch, so the get-or-created ``.msg-actions`` row is the
|
||||
bubble's LAST row (the bottom-right cluster — DOM order is visual
|
||||
order). The getActionsRow scoping keeps the buttons out of the
|
||||
related row either way: a deflected turn with related docs gets its
|
||||
OWN actions row, never a button in the related row."""
|
||||
branch = _done_branch(_app_js())
|
||||
assert "appendRelated(wrap, ev.related);" in branch, (
|
||||
"the done handler must render the related tier (it arrives in "
|
||||
"ev.related — on a deflected turn ev.sources is empty and the "
|
||||
"weak hits live here, row only, zero chips)"
|
||||
)
|
||||
assert branch.index("appendRelated(wrap, ev.related);") > branch.index(
|
||||
"markLastRetryable();"
|
||||
assert branch.index("appendRelated(wrap, ev.related);") < branch.index(
|
||||
"appendTuneButton(wrap);"
|
||||
), (
|
||||
"appendRelated must run AFTER the meta-action claimers (last "
|
||||
"meta row) — a deflected turn's tune/retry buttons must land in "
|
||||
"their own row, never in the related row"
|
||||
"appendRelated must run BEFORE the action appenders — the "
|
||||
".msg-actions row is the bubble's LAST row (phase 130 task 02)"
|
||||
)
|
||||
# The insertion order inside the row: Tune → Retry → Save-as-doc
|
||||
# (markLastRetryable re-appends the Retry button between them).
|
||||
assert branch.index("appendTuneButton(wrap);") < branch.index(
|
||||
"markLastRetryable();"
|
||||
) < branch.index('appendSaveAsDocButton(wrap, finalText || acc || "…");'), (
|
||||
"the actions row's DOM order is the insertion order: Tune, "
|
||||
"Retry, Save-as-doc (phase 130 task 02)"
|
||||
)
|
||||
|
||||
|
||||
@@ -266,25 +275,30 @@ def test_done_handler_persists_related_with_the_turn() -> None:
|
||||
)
|
||||
|
||||
|
||||
def test_restore_path_calls_append_related() -> None:
|
||||
def test_restore_path_appends_related_above_the_actions_row() -> None:
|
||||
"""The phase-14 restore path (``renderStoredMessage`` — used by
|
||||
BOTH the localStorage restore and the /?chat=<id> saved-chat boot
|
||||
load) re-renders the related row from the stored payload when it
|
||||
carries ``related``; a pre-phase record without the field
|
||||
restores exactly as today (appendRelated no-ops — no row). The
|
||||
call sits after the meta-row claimers, exactly like the live
|
||||
done path, so restored buttons never join the related row."""
|
||||
call sits BEFORE the action appenders (Tune / Save-as-doc / notes —
|
||||
plus the restore loop's after-the-loop markLastRetryable Retry),
|
||||
so the .msg-actions row is the restored bubble's LAST row too —
|
||||
identical order to the live done path (phase 130 task 02); the
|
||||
getActionsRow scoping keeps restored buttons out of the related
|
||||
row."""
|
||||
body = _function_body(_app_js(), "function renderStoredMessage(m) {")
|
||||
assert "appendRelated(wrap, m.related);" in body, (
|
||||
"the restore path must render the related tier from the stored "
|
||||
"payload (pre-phase records carry no `related` → no row, "
|
||||
"graceful)"
|
||||
)
|
||||
assert body.index("appendRelated(wrap, m.related);") > body.index(
|
||||
"appendStoppedNote(wrap);"
|
||||
assert body.index("appendRelated(wrap, m.related);") < body.index(
|
||||
"appendTuneButton(wrap)"
|
||||
), (
|
||||
"the related row appends LAST (after the claimers) on the "
|
||||
"restore path too — identical order to the live done path"
|
||||
"the related row appends BEFORE the action appenders on the "
|
||||
"restore path too (the actions row is the bubble's LAST row) — "
|
||||
"identical order to the live done path (phase 130 task 02)"
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user