phase: 93_theme_semantic_completion
Build and Push Containers / build-and-push-app (push) Successful in 1m56s
Build and Push Containers / build-and-push-db (push) Successful in 11s

All verification is complete. Final report:

**Phase 93 — Theme semantic completion: FINAL VERIFICATION PASS — ALL GREEN**

- Verified full implementation in tree: migration `0016` (8 nullable semantic columns, applied at head), 17-var `BUILTIN_COLORS`/`COLOR_FIELDS`/`effective_settings`, API validation, `#view-theme` State-colors fieldset (17 pickers), `theme.js` FIELDS/PAIRS (5→8), `.page-head` surface panel (6 shell views + doc-edit + shared.html; login card / document sticky header audited as already-surfaced), mock_llm `content: None` fix
- Fixed 2 pre-existing defects (both fail identically on baseline `d4f38ad`, proven via worktree A/B): `test_nav_rename_sources` — expected nav tail missing the phase-91 "Theme" link; `test_stale_ui_copy` — now truncates `saved_chats` before/after (house `test_suggestion_chips` pattern) so the seed-chip contract is deterministic on the shared dev DB (owner's 22 saved chats triggered phase-80 last-3-questions)
- Tests: `uv run pytest --cov=app --cov-report=term-missing` → **1868 passed, app/ 99%** (>90% ✓); `uv run ruff check .` → clean; `uv run pyright` → **0 errors**
- E2E: dedicated `uv run pytest tests/e2e/test_theme_semantic_completion.py -v --no-cov` → **8/8 in isolation** (all-gray 17-color theme: zero residual color on saved-result/Stale/Revoked/Local/tool-call elements, text labels intact, gray heads non-transparent, pre-paint tag, Reset → byte-identical no-tag); 15 theme/header/nav/responsive suites green in isolation; full 85-file combined run: only the 2 fixed pre-existing failures + 1 combined-run artifact (`test_sync_upload_progress`, green in isolation)
- Completion criteria: (1) monochrome E2E ✓ (2) default byte-identical, no `#bor-theme` tag ✓ (3) all page heads on solid surface ✓ (4) suite/coverage/lint/E2E green ✓ (5) phases 01–92 no behavior change ✓ (6) commit left to harness per protocol
- Notable: cleaned stray uvicorn leftovers from prior implementation pass (owner's `--reload` dev server untouched); no deviations from the phase design
- Next pending phase: `94_ls_tree_drilldown`
This commit is contained in:
2026-09-10 16:43:08 -04:00
parent d4f38ad3ce
commit 9188be259b
44 changed files with 3019 additions and 196 deletions
+48 -34
View File
@@ -17,24 +17,25 @@ Test → contract mapping (one story, one phase, one isolated file):
1. ``test_save_applies_live_without_reload`` — defect 1 (Save): the
§7.4 save lifecycle lands, and — with NO navigation — the OPEN
document mirrors the saved state: the computed ``:root`` palette is
the saved 9 hexes, the ``#bor-theme`` tag's DOM text is the exact
9-var ``:root{…}`` the next load would serve, and ``<html>``'s
inline style holds EXACTLY the 9 saved custom properties (no stale
pick). The server agrees (the raw ``/`` carries the 9-var tag), and
an SPA nav to Chat (same document) keeps the saved palette on the
computed ``--brand`` and the ``.send-btn`` fill.
the saved 17 hexes, the ``#bor-theme`` tag's DOM text is the exact
17-var ``:root{…}`` the next load would serve, and ``<html>``'s
inline style holds EXACTLY the 17 saved custom properties (no
stale pick). The server agrees (the raw ``/`` carries the 17-var
tag), and an SPA nav to Chat (same document) keeps the saved
palette on the computed ``--brand`` and the ``.send-btn`` fill.
2. ``test_reset_applies_live_without_reload`` — defect 1 (Reset): on a
THEMED load (the served tag is present), the §7.4 reset lifecycle
lands, and — with NO navigation — the ``#bor-theme`` tag is REMOVED
from the live document, the computed ``:root`` palette is the 9
from the live document, the computed ``:root`` palette is the 17
built-ins (parsed from ``styles.css`` in-test), ``<html>`` carries
no overrides, the served HTML has no tag, and the with-row bytes
equal a row-less deployment byte for byte (the no-op contract end
to end, now 9-wide).
to end, now 17-wide).
3. ``test_theme_controls_drive_the_whole_site`` — defect 2: with the
palette seeded, a fresh load's first paint is the themed paint
(the raw HTML carries the 9-var tag immediately before ``</head>``
+ the phase-91 CSP ``style-src 'self' 'sha256-…'``), and the
(the raw HTML carries the 17-var tag immediately before
``</head>`` + the phase-91 CSP ``style-src 'self'
'sha256-…'``), and the
browser-COMPUTED values prove every themed surface follows the tab:
the background grid texture (``body::before`` — the owner's named
defect) at 60% ``--grid-line``, ``::selection`` at 45% ``--brand``,
@@ -121,9 +122,10 @@ APP_URL = f"http://127.0.0.1:{APP_PORT}"
# The distinct E2E palette: the phase-91 8-value indigo set PLUS the
# 9th identity var (phase 92, task 01) — grid_line #2b3550, distinct
# from its built-in #4a2626 and from line #232a4a. Every value differs
# from its built-in, so the tag is non-empty and every saved color is
# stored as-is (no built-in→NULL collapse).
# from its built-in #4a2626 and from line #232a4a — PLUS the 8
# semantic state colors (phase 93), each distinct from its built-in.
# Every value differs from its built-in, so the tag is non-empty and
# every saved color is stored as-is (no built-in→NULL collapse).
PALETTE: dict[str, str] = {
"bg": "#0b1020",
"surface": "#111730",
@@ -134,6 +136,14 @@ PALETTE: dict[str, str] = {
"brand": "#4f46e5",
"brand_soft": "#1e2447",
"brand_ink": "#c7d2fe",
"ok_bg": "#101c24",
"ok_ink": "#86d9c0",
"err_bg": "#20101c",
"err_ink": "#e896b4",
"err_line": "#d1608c",
"accent_bg": "#1e1a10",
"accent_ink": "#d9c37a",
"accent_line": "#b8963e",
}
APP_NAME = "Theme E2E"
PLACEHOLDER = "Ask the themed brain…"
@@ -157,7 +167,8 @@ COLOR_INPUT_IDS: dict[str, str] = {
def _builtin_colors() -> dict[str, str]:
"""The 9 built-in identity hexes parsed OUT of
"""The 17 built-in palette hexes (the 9 identity + the 8
semantic state, phase 93) parsed OUT of
``frontend/assets/styles.css``'s ``:root`` in-test — the single
source of truth, so the suite can't drift from the stylesheet it
asserts on."""
@@ -176,7 +187,7 @@ def _builtin_colors() -> dict[str, str]:
def _expected_tag(colors: dict[str, str]) -> str:
"""The EXACT inline tag ``theme_style_tag`` renders for
``colors``: one ``:root`` override, all 9 vars in COLOR_FIELDS
``colors``: one ``:root`` override, all 17 vars in COLOR_FIELDS
order, no whitespace (the byte the middleware injects)."""
declarations = "".join(f"--{k.replace('_', '-')}:{colors[k]};" for k in COLOR_FIELDS)
return f'<style id="bor-theme">:root{{{declarations}}}</style>'
@@ -185,14 +196,14 @@ def _expected_tag(colors: dict[str, str]) -> str:
def _expected_tag_content(colors: dict[str, str]) -> str:
"""The tag's INNER ``:root{…}`` string — the ``#bor-theme``
element's ``textContent`` after a settled save (task 04's mirror
half is byte-identical to it: same 9 fields, same order, the
half is byte-identical to it: same 17 fields, same order, the
resolver's lowercased hexes)."""
declarations = "".join(f"--{k.replace('_', '-')}:{colors[k]};" for k in COLOR_FIELDS)
return f":root{{{declarations}}}"
def _wait_theme_computed(page: Page, colors: dict[str, str], timeout: int = 15_000) -> None:
"""All 9 computed ``:root`` custom properties equal the given
"""All 17 computed ``:root`` custom properties equal the given
hexes. The inline tag precedes every stylesheet application, so a
themed deployment resolves them from the first style pass — no red
flash, no pop-in (custom properties return the specified token, so
@@ -500,8 +511,9 @@ def _fill_theme_form(
palette: dict[str, str],
strings: dict[str, str] | None = None,
) -> None:
"""Fill the 12 inputs: the 3 text fields (``strings``, default
the E2E set) + the 9 color pickers (``palette``)."""
"""Fill the 20 inputs: the 3 text fields (``strings``, default
the E2E set) + the 17 color pickers (``palette`` — all 17 vars,
phase 93)."""
text_values = strings if strings is not None else SAVED_STRINGS
page.fill("#theme-app-name", text_values["app_name"])
page.fill("#theme-placeholder", text_values["input_placeholder"])
@@ -512,7 +524,7 @@ def _fill_theme_form(
def _assert_raw_tag(raw: str, colors: dict[str, str]) -> None:
"""The RAW served HTML carries exactly one inline theme tag, with
all 9 vars = the given hexes, placed IMMEDIATELY before
all 17 vars = the given hexes, placed IMMEDIATELY before
``</head>`` (``inject_theme``'s exact placement: the tag ends
exactly where ``</head>`` begins and carries the injector's
single leading newline)."""
@@ -541,7 +553,7 @@ def test_save_applies_live_without_reload(page: Page, app_url: str, db_ready: No
# in-flight load can race the save's own refetch.
_wait_mount_settled(page)
# Fill the 12 inputs (the 3 strings + the 9-color palette) and Save
# Fill the 20 inputs (the 3 strings + the 17-color palette) and Save
# through the real form — the PUT held so the §7.4 in-flight state
# is observable deterministically (the same lifecycle assertions
# as the phase-91 suite — the save's contract is unchanged).
@@ -564,21 +576,21 @@ def test_save_applies_live_without_reload(page: Page, app_url: str, db_ready: No
# NO navigation (the URL never leaves the Theme view): the OPEN
# document mirrors the settled save — the tag's DOM text is the
# exact 9-var :root{…} the next load would serve (task 04's mirror
# half) and <html>'s inline style holds EXACTLY the 9 saved
# custom properties (the paint half — no stale pick; the pre-fix
# code cleared the preview onto the STALE served tag and fails
# this wait).
# exact 17-var :root{…} the next load would serve (task 04's
# mirror half) and <html>'s inline style holds EXACTLY the 17
# saved custom properties (the paint half — no stale pick; the
# pre-fix code cleared the preview onto the STALE served tag and
# fails this wait).
expect(page).to_have_url(APP_URL + "/theme.html")
_wait_settled_open_document(
page, _expected_tag_content(PALETTE), _expected_overrides(PALETTE, builtin)
)
# …and all 9 computed :root custom properties ARE the saved hexes
# …and all 17 computed :root custom properties ARE the saved hexes
# (the open page painted the saved palette — defect 1 gone).
_wait_theme_computed(page, PALETTE)
# The server agrees: the RAW served HTML (a fresh request) carries
# the 9-var tag immediately before </head>.
# the 17-var tag immediately before </head>.
r = httpx.get(app_url + "/", timeout=10)
assert r.status_code == 200
_assert_raw_tag(r.text, PALETTE)
@@ -616,7 +628,7 @@ def test_reset_applies_live_without_reload(page: Page, app_url: str, db_ready: N
expect(page.locator("#theme-content")).to_be_visible(timeout=15_000)
# Seed the theme via the API, THEN load the shell: the served
# document carries the 9-var tag (a THEMED load — the reset must
# document carries the 17-var tag (a THEMED load — the reset must
# remove it from the live document, not just stop serving it).
_seed_theme_via_api(app_url, _cookies(page))
page.goto(app_url + "/theme.html")
@@ -648,7 +660,7 @@ def test_reset_applies_live_without_reload(page: Page, app_url: str, db_ready: N
# NO navigation: the #bor-theme tag is REMOVED from the live
# document (effective = the built-ins → content null → the tag
# goes) and the page paints the 9 built-ins (parsed from
# goes) and the page paints the 17 built-ins (parsed from
# styles.css in-test) with <html> carrying no overrides at all —
# the reset is the one case where the cleared-preview shape and
# the overrides shape agree: the style attribute is empty.
@@ -665,7 +677,7 @@ def test_reset_applies_live_without_reload(page: Page, app_url: str, db_ready: N
r = httpx.get(app_url + "/", timeout=10)
assert "bor-theme" not in r.text
# …and the byte-identical contract end to end: the with-row bytes
# equal a ROW-LESS deployment byte for byte (now 9-wide — a
# equal a ROW-LESS deployment byte for byte (now 17-wide — a
# defaults-saved row never adds a byte).
with_row = r.content
with SessionLocal() as db:
@@ -688,9 +700,11 @@ def test_theme_controls_drive_the_whole_site(page: Page, app_url: str, db_ready:
login(page, app_url, next="/")
_seed_theme_via_api(app_url, _cookies(page))
# Pre-paint with the 9th var: the raw served HTML carries the
# 9-var tag immediately before </head>, permitted in a real
# browser only via the phase-91 CSP hash (now 9-wide).
# Pre-paint with the full 17-var palette (phase 93 — the 8
# semantic state colors join the 9 identity vars): the raw served
# HTML carries the 17-var tag immediately before </head>,
# permitted in a real browser only via the phase-91 CSP hash
# (now 17-wide).
r = httpx.get(app_url + "/", timeout=10)
assert r.status_code == 200
_assert_raw_tag(r.text, PALETTE)