Files
brain-of-reese/tests/unit/test_main.py
T
ducoterra 1200437bf8
Build and Push Containers / build-and-push-app (push) Successful in 4m4s
Build and Push Containers / build-and-push-db (push) Successful in 15s
phase: 168_admin_settings_panel
**Phase 168 — Admin Settings panel — final verification: PASS**

1. **Implemented/verified:** `/settings.html` (admin-only) with the 75-field catalogue (`app/core/settings_catalog.py`), DB-over-env overrides in Postgres (`app_settings`, migration 0028 at head, `settings_overlay.py` resolver, `app/api/admin_settings.py` — 4 admin-only routes), live-apply on save with no restart + restart-required badges, Reset/Clear all, write-only secrets, `.env`-never-written, `BOR_SETTINGS_DB=0` kill switch.
2. **Phase E2E: 12/12** — run with `E2E_APP_PORT=8200` (ports 8123/8124 are held by an unrelated "undercooked" project; no process killed, no code change — the documented env override).
3. **Regression set: all 7 suites green in isolation** (theme tab, API tokens, configurable brand, global tuning, admin auth, cache busting, wide desktop column — 38 tests).
4. **Full suite: unit+integration exit 0 (4066 passed), app/ coverage 99%** (gate >90%); **ruff clean, pyright 0 errors / 0 warnings.**
5. **Log contract (rule 10) verified live:** per-turn + per-response byte-budget lines present; settings write lines carry key + action, **never the value**.
6. **Byte-budget audit: all endpoints under the 262,144 B budget**; settings catalogue 23,513 B (gzip 3,326).
7. **Defect fixed (one):** criterion 5 had no integration pin — added `test_bad_row_inserted_directly_never_bricks_boot` to `tests/integration/test_admin_settings_api.py` (malformed row inserted directly → fresh `create_app()` boots, row skipped with logged reason, rest of table applies, `/api/health` 200) — 12/12 green.
8. **Docs pass:** `README.md` and `AGENTS.md` reviewed in full — both consistent with the as-built feature (Settings page table, Settings section, Configuration-reference note, `.env.example` block); **no changes required**.
9. **Cleanup:** audit app killed (by PID); `app_settings` left empty (0 rows); all changes left in the working tree (no commit, per protocol).
10. **Completion criteria:** all 7 checkboxes verified green (criterion 7's commit is the harness's).
11. **Next pending phase:** `170_edit_bubble_sizing`.
2026-10-10 01:05:14 -04:00

54 lines
2.2 KiB
Python

"""Unit tests: app factory edge cases (no live DB needed)."""
from __future__ import annotations
from fastapi.testclient import TestClient
import app.main as main_mod
from app.config import get_settings
from app.core import settings_overlay
def test_create_app_warns_and_serves_api_only_without_static_dir(
monkeypatch, tmp_path
) -> None:
"""If the frontend directory is missing, the API still boots (PLAN §7)."""
monkeypatch.setattr(
main_mod.settings, "static_dir", str(tmp_path / "definitely-missing")
)
app2 = main_mod.create_app()
client = TestClient(app2)
# /api still works…
assert client.get("/api/health").status_code == 200
# …but the static mount is absent (no index page).
assert client.get("/").status_code == 404
def test_create_app_wires_caching_middleware() -> None:
"""Phase 33: the app factory always attaches the cache-busting
middleware (by name) — even when the static dir is missing, so the
/api/* no-touch guarantee holds in every environment."""
app2 = main_mod.create_app()
# ``mw.cls`` is starlette's opaque ``_MiddlewareFactory`` protocol —
# reach for ``__name__`` the same way starlette's own __repr__ does.
middleware_names = [getattr(mw.cls, "__name__", "") for mw in app2.user_middleware]
assert "CachingMiddleware" in middleware_names
def test_create_app_boots_with_the_switch_on(monkeypatch) -> None:
"""Phase 168 (task 02/03): the boot prime with the kill switch ON
— the ``settings overrides loaded count=…`` branch (the OFF branch
is exercised by every other suite's app import; the overlay's
engine is fail-soft, so a DB-down unit environment still boots).
``create_app`` also wires the chat runtime reset hook here (task
03) — the ``register_invalidator`` pin lives in
``test_settings_live_apply.py``."""
settings_overlay.reset_state_for_tests()
monkeypatch.setenv("BOR_SETTINGS_DB", "1")
app2 = main_mod.create_app()
assert app2 is not None
# restore: the switch reverts via monkeypatch; the cache clear
# ensures a boot-time row set never leaks into later suites'
# settings, and the hook slate is fresh for them too.
settings_overlay.reset_state_for_tests()
get_settings.cache_clear()