phase: 190_app_name_settings_fix
All gates re-verified green. Report: - **Verified (all 4 tasks already complete; this was the final pass):** `effective_settings` resolves the 3 brand strings panel-row → tab-row → env (`applied_override_keys`, presence-not-value); `PUT /api/ui-settings` ignores string body fields; Theme-tab form is colors-only (17 pickers, no `#theme-app-name`/`#theme-placeholder`/`#theme-footer`); the ONE shared `applyBrandFromConfig` re-applies title/`.brand-text`/footer/placeholder after a panel save-reset and a tab save-reset; boot path byte-identical (single `/api/config`). - **Completion criteria:** - strings order panel→tab→env, both branches — ✅ `tests/unit/test_theming.py::test_effective_app_name_prefers_settings_panel_row_over_ui_settings_row`, `..._fall_back_to_ui_settings_row_without_panel_row`, `..._per_field_panel_then_tab_then_env`, `..._ignore_panel_rows_when_the_overlay_is_off` - PUT ignores string fields + no 3 inputs in the tab — ✅ `tests/integration/test_ui_settings_api.py::test_put_ignores_string_fields_in_body` (+2) and the E2E `test_theme_tab_dom_is_colors_only` - live apply without reload + incident regression — ✅ `tests/e2e/test_app_name_settings_fix.py` tests 1–4 - byte-identical boot, no double-apply — ✅ `tests/unit/test_brand_live.py` markers + E2E "exactly one /api/config" - suite green, coverage >90%, ruff+pyright clean — ✅ - no behavior change in prior phases — ✅ (palette, phase-168 panel, env fallback suites all green) - atomic commit — **left to the harness** (pipeline rule overrides per-phase committing; no git write run) - **Gates:** `uv run pytest --cov=app --cov-report=term-missing` → **4630 passed, TOTAL 6941 16 99%**, exit 0 · `uv run pytest tests/e2e/test_app_name_settings_fix.py -v --no-cov` → **6 passed** in isolation · regression E2E (isolated, one process each, all exit 0): `test_smoke` `test_configurable_brand` `test_admin_theme_tab` `test_theme_save_and_coverage` `test_theme_semantic_completion` `test_themed_favicon` `test_dark_tech_theme` `test_admin_settings_panel` `test_admin_settings_layout` `test_settings_mobile_value_width` · `uv run ruff check .` → All checks passed · `uv run pyright` → 0 errors. - **Documentation:** README — fixed "saving one repaints *every* open page" (only the open document repaints; other pages on next load) and a broken paragraph wrap in *Customizing the look*; AGENTS.md rule 16 — `test_chunks_hnsw_recall.py` now described accurately (index paths forced with `enable_seqscan`/`indexonlyscan`/`bitmapscan` off, unforced plan asserted only on a pristine relation); `tests/unit/test_theme_frontend.py` — two stale section headers ("20 form fields"/"20 inputs" → 17 color). No AGENTS.md settings-overlay/resolution-order clause exists, so per the phase none was added. Full env-var cross-check (`BOR_*` in `app/config.py` vs README) → 0 gaps; 0 missing file references. - **Notable:** the working tree also carries this phase's flake hardening of the phase-188 `tests/integration/test_chunks_hnsw_recall.py` (verified legit and green). Live infra untouched; shared DB left clean (0 `app_settings`, 0 `ui_settings`). **Flagged, not changed:** `settings_overlay.applied_override_keys` lets a `ProgrammingError` (missing `app_settings`) propagate from public `GET /api/config`, where `load_overrides` deliberately fails soft — only reachable on an un-migrated (0027) DB, outside this phase's pinned A1 semantics, so left for the owner to rule on rather than silently deviating. - **Next pending phase:** `191_source_name_labels_tags`.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""Unit: the admin UI-settings API (phase 91, task 01).
|
||||
"""Unit: the admin UI-settings API (phase 91, task 01; colors-only since
|
||||
phase 190, task 02).
|
||||
|
||||
Covers ``app/api/ui_settings.py`` — the PUT validation + normalization
|
||||
contract and the GET/PUT persistence on the single ``ui_settings`` row
|
||||
@@ -6,13 +7,18 @@ contract and the GET/PUT persistence on the single ``ui_settings`` row
|
||||
the 8 semantic state):
|
||||
|
||||
* PUT validation — the 422s NAME the offending field (fixed details):
|
||||
a >300-char string after the trim, a non-``#rrggbb`` color (wrong
|
||||
prefix, 3-digit shorthand, 8 hex chars, missing ``#``) — identity AND
|
||||
semantic fields alike (the loops are ``COLOR_FIELDS``-driven);
|
||||
a non-``#rrggbb`` color (wrong prefix, 3-digit shorthand, 8 hex
|
||||
chars, missing ``#``) — identity AND semantic fields alike (the loops
|
||||
are ``COLOR_FIELDS``-driven);
|
||||
* the STRINGS are accepted and IGNORED (phase 190, A1 — the admin
|
||||
Settings panel is the single writable owner of ``app_name`` /
|
||||
``input_placeholder`` / ``footer_text``): no body string is written,
|
||||
whatever its length or whitespace, and the stored columns are left
|
||||
exactly as they were (never cleared) — so an old cached client's Save
|
||||
cannot re-bake a name and shadow the panel;
|
||||
* normalization — colors are lowercased on store; a color EQUAL to its
|
||||
built-in is stored as NULL (the owner-locked rule: "save the defaults"
|
||||
must leave the row empty — the no-op injection contract); an empty /
|
||||
whitespace-only string is the clear operation (NULL);
|
||||
must leave the row empty — the no-op injection contract);
|
||||
* GET — the effective merge (a partial row reports the DB values over
|
||||
the env/built-in defaults);
|
||||
* upsert — the first PUT CREATES the id-1 row, the second UPDATES that
|
||||
@@ -65,25 +71,33 @@ def _row(db: Session) -> UiSettings | None:
|
||||
return db.execute(select(UiSettings).where(UiSettings.id == 1)).scalars().first()
|
||||
|
||||
|
||||
def test_put_too_long_string_422_names_the_field(
|
||||
def test_put_string_fields_are_ignored_not_validated(
|
||||
admin_client: TestClient, db: Session
|
||||
) -> None:
|
||||
"""Each of the 3 strings: >300 chars AFTER the trim is a 422 naming
|
||||
that field; a rejected PUT half-writes nothing; exactly 300 still
|
||||
passes (the column is VARCHAR(300))."""
|
||||
"""Phase 190 (A1): the 3 string fields of the body are DROPPED before
|
||||
the handler reads them — no trim, no length check, no 422. A
|
||||
400-char name (the old 422 case) is a plain 200 that writes nothing,
|
||||
and the response reports the effective (env) value; the palette in
|
||||
the same body still saves. An old cached client can therefore never
|
||||
re-bake a brand string from this surface — and can never be blocked
|
||||
by a validation error on a field this API no longer owns."""
|
||||
for field in theming.STRING_FIELDS:
|
||||
r = admin_client.put("/api/ui-settings", json={field: "x" * 301})
|
||||
assert r.status_code == 422, (field, r.text)
|
||||
assert r.json()["detail"] == f"{field} is too long (max 300)"
|
||||
# A whitespace-padded 301 is still 301 after the trim…
|
||||
r = admin_client.put("/api/ui-settings", json={field: " x" * 151})
|
||||
assert r.status_code == 422, (field, r.text)
|
||||
# No rejected PUT created the row — the upsert runs after validation.
|
||||
assert _row(db) is None
|
||||
# Exactly 300 passes — stored, trimmed.
|
||||
r = admin_client.put("/api/ui-settings", json={"app_name": "y" * 300})
|
||||
assert r.status_code == 200, r.text
|
||||
assert r.json()["app_name"] == "y" * 300
|
||||
r = admin_client.put(
|
||||
"/api/ui-settings", json={field: "x" * 301, "brand": "#818cf8"}
|
||||
)
|
||||
assert r.status_code == 200, (field, r.text)
|
||||
assert r.json()[field] == getattr(get_settings(), field)
|
||||
db.expire_all()
|
||||
row = _row(db)
|
||||
assert row is not None
|
||||
assert getattr(row, field) is None, f"{field} must never be stored"
|
||||
assert row.brand == "#818cf8" # the colors half still saves beside it
|
||||
# And the row the PUT created holds no string at all.
|
||||
db.expire_all()
|
||||
row = _row(db)
|
||||
assert row is not None
|
||||
for field in theming.STRING_FIELDS:
|
||||
assert getattr(row, field) is None
|
||||
|
||||
|
||||
def test_put_bad_hex_422_names_the_field(admin_client: TestClient) -> None:
|
||||
@@ -210,27 +224,35 @@ def test_put_semantic_built_in_is_stored_as_null(
|
||||
assert r.json()["ok_ink"] == theming.BUILTIN_COLORS["ok_ink"]
|
||||
|
||||
|
||||
def test_put_empty_string_is_the_clear_operation(
|
||||
def test_put_cannot_clear_a_stored_string(
|
||||
admin_client: TestClient, db: Session
|
||||
) -> None:
|
||||
"""A whitespace-only (or empty) string trims to empty → NULL — the
|
||||
clear operation, not a 422 and not a stored blank: the effective
|
||||
value falls back to the env default."""
|
||||
r = admin_client.put("/api/ui-settings", json={"app_name": " ", "footer_text": ""})
|
||||
assert r.status_code == 200, r.text
|
||||
row = _row(db)
|
||||
assert row is not None
|
||||
assert row.app_name is None
|
||||
assert row.footer_text is None
|
||||
# The response reports the effective (env) fallback, not "".
|
||||
assert r.json()["app_name"] == get_settings().app_name
|
||||
assert r.json()["footer_text"] == get_settings().footer_text
|
||||
"""The A1 fallback survives the write strip: a legacy row that holds
|
||||
a baked-in string keeps it through an empty / whitespace / explicit
|
||||
``null`` PUT — the Theme tab neither writes nor CLEARS the strings
|
||||
(clearing one is the panel's ``DELETE /api/admin/settings/{key}``).
|
||||
The response keeps reporting the effective value, so the old client
|
||||
still shows what the deployment shows."""
|
||||
db.add(UiSettings(id=1, app_name="Legacy bake", footer_text="Legacy footer"))
|
||||
db.commit()
|
||||
|
||||
for body in ({"app_name": " ", "footer_text": ""}, {"app_name": None}):
|
||||
r = admin_client.put("/api/ui-settings", json=body)
|
||||
assert r.status_code == 200, (body, r.text)
|
||||
db.expire_all()
|
||||
row = _row(db)
|
||||
assert row is not None
|
||||
assert row.app_name == "Legacy bake" # never written, never cleared
|
||||
assert row.footer_text == "Legacy footer"
|
||||
# The response reports the EFFECTIVE value (the stored fallback).
|
||||
assert r.json()["app_name"] == "Legacy bake"
|
||||
assert r.json()["footer_text"] == "Legacy footer"
|
||||
|
||||
|
||||
def test_get_effective_merge_partial_row(admin_client: TestClient, db: Session) -> None:
|
||||
"""GET reports the DB values over the defaults, column by column: a
|
||||
row with ONLY ``bg`` set (hand-inserted) reports that color plus the
|
||||
built-ins and the env strings — all 12 keys, no nulls."""
|
||||
built-ins and the env strings — all 20 keys, no nulls."""
|
||||
db.add(UiSettings(id=1, bg="#123456"))
|
||||
db.commit()
|
||||
r = admin_client.get("/api/ui-settings")
|
||||
@@ -258,19 +280,19 @@ def test_upsert_creates_then_updates_the_id_1_row(
|
||||
row = _row(db)
|
||||
assert row is not None and row.id == 1
|
||||
assert row.brand == "#123abc"
|
||||
assert row.app_name == "First"
|
||||
assert row.app_name is None # phase 190 A1: the body's string is dropped
|
||||
|
||||
r2 = admin_client.put(
|
||||
"/api/ui-settings", json={"brand": "#abcdef", "input_placeholder": "Second"}
|
||||
)
|
||||
assert r2.status_code == 200, r2.text
|
||||
assert r2.json()["brand"] == "#abcdef"
|
||||
assert r2.json()["input_placeholder"] == "Second"
|
||||
assert r2.json()["input_placeholder"] == get_settings().input_placeholder
|
||||
|
||||
db.expire_all() # drop the test session's pre-second-PUT view (house pattern)
|
||||
rows = db.execute(select(UiSettings)).scalars().all()
|
||||
assert len(rows) == 1, "the upsert must never create a second row"
|
||||
assert rows[0].id == 1
|
||||
assert rows[0].brand == "#abcdef" # updated, not appended
|
||||
assert rows[0].input_placeholder == "Second" # the new string landed
|
||||
assert rows[0].app_name is None # absent in the second body → NULL
|
||||
assert rows[0].input_placeholder is None # the strings are never written
|
||||
assert rows[0].app_name is None
|
||||
|
||||
Reference in New Issue
Block a user