Phase 47 (owner permission 2026-08-27, TODO.md L10–11, roadmap R1): the
full Podman quadlet family (.container, .network, .volume, .image,
.pod, .kube, .swap, .os, .endpoint) and .j2 Jinja templates join the
allowed + default A9 import formats, chunked as plain text (owner
decision — no TOML/Jinja-aware splitter). No env configuration needed:
a default import now indexes them.
- app/config.py: _ALLOWED_IMPORT_EXTENSIONS + the default
import_extensions CSV gain the ten names (the original seven first);
the never-widen BOR_IMPORT_EXTENSIONS validator is untouched and
still rejects truly unknown extensions.
- app/rag/chunker.py: ten _FORMAT_CHUNKERS entries -> chunk_text
(HARD_MAX_CHARS 1200 honored, unknown-suffix fallback unchanged);
docstring/comments cite the A9 revision 2026-08-27.
- tests/fixtures/docs/homelab/: quadlet/compose.container (realistic
quadlet TOML, >1500 chars, [Unit]/[Service]/[Container] sections,
RESE-QUADLET-SENTINEL-77aa), quadlet/lan.network,
quadlet/cache.volume, templates/deploy.j2 (for/set/if Jinja
constructs + RESE-JINJA-SENTINEL-33dd). Every suite that seeds the
fixture tree updates its 9 -> 13 document-count constants.
- tests/unit/test_config.py: allowed set carries all seventeen formats,
default CSV + dotted import_extension_set include the ten, the
validator accepts the new names and still rejects unknowns.
- tests/unit/test_chunker.py: dispatch parity with chunk_text for every
new suffix (parametrized), the .container fixture chunks >=2 under
the cap with the sentinel surviving, the .j2 fixture keeps {{ }}
verbatim, the unknown-suffix fallback is unchanged.
- tests/unit/test_importer.py: a default-extensions walk over a temp
tree indexes exactly the ten new files (unknown/hidden/excluded
filtered), the original seven still walk, stem-title fallback holds.
- tests/integration/test_import_quadlet_jinja.py (new): import_sources
over a temp tree with .container/.volume/.j2 -> documents + chunks
rows with stem titles; delta re-import updates only the changed .j2
doc; prune drops the deleted .volume doc with cascade.
- tests/e2e/test_quadlet_jinja_import.py (new, story suite, mock-only,
isolation): GET /api/docs (admin session) lists the four new-format
docs with non-zero chunk counts and stem titles; the Sources table
renders a row + .doc-link per file; the phase-26 modal shows the
.container TOML ([Container] section + sentinel) with stem title and
the container format badge; a RESE-JINJA-SENTINEL-33dd question
FTS-matches the .j2 chunk -> honest-positive (A8: LOW requires zero
FTS hits) — the bubble is not .is-deflected and a source chip names
templates/deploy.j2.
- README.md + .env.example: the extended default format set (A9
revised 2026-08-27, plain-text chunking, narrow-only rule intact).
- .agent/PLAN.md: the A9 revision (owner-locked R1) — A9 row status,
the revision note under the anchors table, and the §5 chunking-policy
+ §11 workflow lines. The only PLAN edit this phase.
Gates: uv run pytest 795 passed; app/ coverage TOTAL 99% (>90%);
ruff check + pyright clean; story E2E 4/4 in isolation (DB up);
regression E2E suites test_import_documents (3) / test_sync_button
(3) / test_git_sources_admin (6) green in isolation.
Also records the 47_quadlet_jinja_import task-file moves (01–03)
todo/ -> complete/.
233 lines
8.8 KiB
Python
233 lines
8.8 KiB
Python
"""Phase 05 E2E (Playwright): onboarding suggestion chips, one-tap submit.
|
|
|
|
Story: ``.agent/user_stories/suggestion-chips.md``
|
|
Run in isolation (DB must be up: ``podman compose up -d db``):
|
|
|
|
uv run pytest tests/e2e/test_suggestion_chips.py -v --no-cov
|
|
|
|
The onboarding row in the empty state renders real ``<button>`` chips from
|
|
``GET /api/suggestions`` (settings defaults). Clicking — or Tab + Enter —
|
|
fills the composer AND submits: one tap produces a user bubble with the
|
|
chip's exact text and a streamed Brain reply. On mobile (375px) the row
|
|
becomes a single horizontally scrollable line.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from pathlib import Path
|
|
from threading import Thread
|
|
from typing import Any
|
|
|
|
import httpx
|
|
import pytest
|
|
from playwright.sync_api import Browser, Page, expect
|
|
from sqlalchemy import text
|
|
|
|
from app.config import Settings
|
|
from app.db import SessionLocal
|
|
from app.rag.importer import ImportSummary, import_sources
|
|
from app.rag.llm import LLMClient
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
FIXTURES = REPO / "tests" / "fixtures" / "docs"
|
|
MOCK_ANSWER_MARKER = "Deterministic mock answer for E2E"
|
|
|
|
|
|
async def _import_fixtures(mock_port: int) -> ImportSummary:
|
|
kwargs: dict[str, Any] = {"_env_file": None, "llm_base_url": f"http://127.0.0.1:{mock_port}/v1"}
|
|
settings = Settings(**kwargs) # pyright: ignore[reportCallIssue]
|
|
return await import_sources([FIXTURES], LLMClient(settings))
|
|
|
|
|
|
def _run_in_thread(coro: Any) -> Any:
|
|
"""Run a coroutine on a worker thread (Playwright owns the test loop)."""
|
|
box: dict[str, Any] = {}
|
|
|
|
def runner() -> None:
|
|
try:
|
|
box["value"] = asyncio.run(coro)
|
|
except BaseException as e: # noqa: BLE001 — re-raised on the test thread
|
|
box["error"] = e
|
|
|
|
t = Thread(target=runner)
|
|
t.start()
|
|
t.join()
|
|
if "error" in box:
|
|
raise box["error"]
|
|
return box["value"]
|
|
|
|
|
|
def _seed_kb(mock_port: int) -> ImportSummary:
|
|
"""Deterministic KB: truncate everything, import the fixture docs."""
|
|
with SessionLocal() as db:
|
|
db.execute(text("TRUNCATE chunks, documents, query_log"))
|
|
db.commit()
|
|
summary = _run_in_thread(_import_fixtures(mock_port))
|
|
assert summary is not None and summary.added == 13 # A9 formats (phase 47 added quadlet+j2)
|
|
return summary
|
|
|
|
|
|
def _api_suggestions(app_url: str) -> list[str]:
|
|
body = httpx.get(f"{app_url}/api/suggestions", timeout=10).json()
|
|
return body["suggestions"]
|
|
|
|
|
|
def _chip_locator(page: Page) -> Any:
|
|
return page.locator("#suggestions .suggestion-chip")
|
|
|
|
|
|
def test_onboarding_chips_render(
|
|
page: Page, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_seed_kb(mock_llm)
|
|
page.set_default_timeout(30_000)
|
|
page.goto(app_url)
|
|
|
|
# Accessible group: role=list + a name screen readers can announce.
|
|
group = page.locator("#suggestions")
|
|
expect(group).to_have_attribute("role", "list")
|
|
expect(group).to_have_attribute("aria-label", "Suggested questions")
|
|
|
|
# 3+ visible chips, real buttons, each with non-empty text — and the
|
|
# texts match what the API returned (chips are drawn from the endpoint).
|
|
chips = _chip_locator(page)
|
|
expect(chips.first).to_be_visible(timeout=30_000)
|
|
assert chips.count() >= 3
|
|
api_texts = _api_suggestions(app_url)
|
|
for i in range(chips.count()):
|
|
chip = chips.nth(i)
|
|
expect(chip).to_be_visible()
|
|
expect(chip).to_have_attribute("type", "button")
|
|
expect(chip).to_have_attribute("role", "listitem")
|
|
text = chip.inner_text().strip()
|
|
assert text, "every chip needs non-empty label text"
|
|
assert text in api_texts
|
|
assert len(set(api_texts)) >= 3
|
|
|
|
# Chips live in the empty state, which is visible before any message.
|
|
expect(page.locator("#empty-state")).to_be_visible()
|
|
# Chip component contract: brand pill, >=44px touch target.
|
|
style = chips.first.evaluate("el => getComputedStyle(el)")
|
|
assert style["backgroundColor"] == "rgb(35, 43, 82)" # --brand-soft #232b52 (dark theme)
|
|
assert style["color"] == "rgb(165, 180, 252)" # --brand-ink #a5b4fc
|
|
assert style["borderRadius"] == "999px"
|
|
box = chips.first.bounding_box()
|
|
assert box is not None and box["height"] >= 44
|
|
|
|
|
|
def test_chip_click_submits(
|
|
page: Page, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_seed_kb(mock_llm)
|
|
page.set_default_timeout(30_000)
|
|
page.goto(app_url)
|
|
|
|
first = _chip_locator(page).first
|
|
expect(first).to_be_visible(timeout=30_000)
|
|
chip_text = first.inner_text().strip()
|
|
assert chip_text
|
|
|
|
# One tap = one question: the click fills AND submits.
|
|
first.click()
|
|
expect(page.locator("#empty-state")).to_be_hidden()
|
|
expect(page.locator("#message-input")).to_have_value("") # submitted, not queued
|
|
expect(page.locator(".msg.user .bubble")).to_have_count(1, timeout=30_000)
|
|
expect(page.locator(".msg.user .bubble")).to_have_text(chip_text)
|
|
|
|
# A grounded mock reply follows (the seeded KB answers this topic).
|
|
brain = page.locator(".msg.brain .bubble").first
|
|
expect(brain).to_contain_text(MOCK_ANSWER_MARKER, timeout=30_000)
|
|
expect(brain).to_contain_text(chip_text)
|
|
expect(page.locator(".msg.brain.is-deflected")).to_have_count(0)
|
|
|
|
# Never stale: the send button recovers after the turn.
|
|
expect(page.locator("#send-btn")).to_be_enabled()
|
|
expect(page.locator("#send-label")).to_have_text("Send")
|
|
|
|
|
|
def test_chips_keyboard_accessible(
|
|
page: Page, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_seed_kb(mock_llm)
|
|
page.set_default_timeout(30_000)
|
|
page.goto(app_url)
|
|
first = _chip_locator(page).first
|
|
expect(first).to_be_visible(timeout=30_000)
|
|
chip_text = first.inner_text().strip()
|
|
assert chip_text
|
|
|
|
# Tab from the page start: the first chip must be reachable on the
|
|
# keyboard, and before the composer input (skip-link + 2 nav links come
|
|
# first). Track tab stops until we land on a chip.
|
|
reached_chip_at: int | None = None
|
|
for step in range(1, 11):
|
|
page.keyboard.press("Tab")
|
|
state = page.evaluate(
|
|
"""() => {
|
|
const el = document.activeElement;
|
|
return {
|
|
id: el ? el.id : "",
|
|
isChip: !!(el && el.classList && el.classList.contains("suggestion-chip")
|
|
&& el.closest("#suggestions")),
|
|
};
|
|
}"""
|
|
)
|
|
if state["id"] == "message-input":
|
|
pytest.fail("the composer input was reached before the suggestion chips")
|
|
if state["isChip"]:
|
|
reached_chip_at = step
|
|
break
|
|
assert reached_chip_at is not None, "no suggestion chip is keyboard-reachable"
|
|
expect(first).to_be_focused()
|
|
|
|
# Enter activates the focused chip button → it submits.
|
|
page.keyboard.press("Enter")
|
|
expect(page.locator("#empty-state")).to_be_hidden()
|
|
expect(page.locator("#message-input")).to_have_value("")
|
|
expect(page.locator(".msg.user .bubble")).to_have_count(1, timeout=30_000)
|
|
expect(page.locator(".msg.user .bubble")).to_have_text(chip_text)
|
|
expect(page.locator(".msg.brain .bubble").first).to_contain_text(
|
|
MOCK_ANSWER_MARKER, timeout=30_000
|
|
)
|
|
expect(page.locator("#send-btn")).to_be_enabled()
|
|
|
|
|
|
def test_chips_mobile_row(
|
|
browser: Browser, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_seed_kb(mock_llm)
|
|
page = browser.new_page(viewport={"width": 375, "height": 720})
|
|
try:
|
|
page.set_default_timeout(30_000)
|
|
page.goto(app_url)
|
|
row = page.locator("#suggestions")
|
|
expect(row).to_be_visible(timeout=30_000)
|
|
|
|
# The row is a single line that scrolls horizontally: content is
|
|
# wider than the viewport, the container scrolls, nothing wraps.
|
|
wrap = row.evaluate("el => getComputedStyle(el)")
|
|
assert wrap["flexWrap"] == "nowrap"
|
|
assert wrap["overflowX"] in {"auto", "scroll"}
|
|
dims = row.evaluate(
|
|
"el => ({ sw: el.scrollWidth, cw: el.clientWidth, h: el.clientHeight })"
|
|
)
|
|
assert dims["sw"] > dims["cw"], "chips must overflow into a scroll row"
|
|
assert row.evaluate("el => { el.scrollLeft = 24; return el.scrollLeft; }") > 0
|
|
|
|
# Exactly one line: every chip shares the same top edge, and the
|
|
# line height fits a single 44px-tall chip (no vertical clipping).
|
|
chips = _chip_locator(page)
|
|
assert chips.count() >= 3
|
|
tops: list[float] = []
|
|
for i in range(chips.count()):
|
|
box = chips.nth(i).bounding_box()
|
|
assert box is not None
|
|
assert box["height"] >= 44, "chips stay >=44px tall on mobile"
|
|
tops.append(box["y"])
|
|
assert max(tops) - min(tops) < 0.5, "all chips sit on one horizontal line"
|
|
row_box = row.bounding_box()
|
|
assert row_box is not None
|
|
assert row_box["height"] < 2 * 44, "the mobile row is a single line tall"
|
|
finally:
|
|
page.close()
|