All verification complete. Final report: **Phase 119 final verification pass — all criteria verified, one stale pin fixed.** - Verified implementation of all 6 tasks: D1 component name-hit rule (`name_hit` flag, titles never matched, retired length tie-break), D2 `BOR_NAME_HIT_BONUS` (0.005 default, 0 = byte-identical kill switch, negative fails startup, selection-layer only, `eval_retrieval` `suggested:` line), D3 suggested-folder lines (after `SUGGEST_INTRO`, before first block), D4 cite-discipline `SUGGEST_INTRO` sentence (PERSONA/LOW/`TOOLS_SECTION` byte-pins intact), D5 `done.sources` = read docs only (frontend no-op on empty confirmed), D6 mock `repeat your folder map` echo + new suite + telemetry. - Battery (replica restored per skill, fingerprint docs=1000/chunks=8866 verified, `eval_retrieval --from-file tests/fixtures/retrieval_battery.txt` re-run): **GATE PASS** — gitea README #4 in suggested top-5, forgejo 5/5 (README #1), gateway README in top-5 (#4), qwen3.8-27b quadlets top-5, Mongolia HIGH/fts=5 unchanged. - New E2E in isolation: `4 passed` ×2 (deterministic). All 27 modified E2E suites in isolation: 26 green; **1 stale pin fixed** — `test_source_chip_quality.py` durable-record order pin pre-dated the D1 re-rank (`aliases` stem sub-component name-hits `ssh_aliases.txt`, deterministically lifting `backups.md` over `kubernetes.md`; probe-verified 0.016277 vs 0.016036, 4/4 stable) — re-pinned with the phase-119 rationale; suite green ×2. - Gates: `uv run pytest --cov=app --cov-report=term-missing` → **2547 passed, app coverage 99%** (>90%); `uv run ruff check .` → All checks passed; `uv run pyright` → 0 errors. - Completion criteria: 1 ✅ (battery, recorded), 2 ✅ (folder lines; block/LOW byte-identical pins green), 3 ✅ (read-only chips, zero-read chips nothing, related row + durable record untouched — unit+E2E agree), 4 ✅ (all green), 5 → commit/phase-move left to the harness per pass rules (nothing committed). - Deviations: battery output + real-model telemetry recorded in `.agents/reports/119_name_signal_read_chips/task06_battery_and_e2e.md` and `TOOL_CALLING_TESTING.md` §11 (task files in `complete/` are immutable to this pass); gateway canonical doc at #4 vs overview's #3 was already documented at task 06 (containment gate met). - Next pending phase: **none** — `todo/` holds only phase 119.
239 lines
10 KiB
Python
239 lines
10 KiB
Python
"""Phase 47 E2E (Playwright): quadlet unit files + Jinja templates ride the
|
|
A9 import path end to end (A9 revised 2026-08-27, owner permission).
|
|
|
|
Story: ``.agents/user_stories/quadlet-jinja-import.md``
|
|
Run in isolation (DB must be up: ``podman compose up -d db``):
|
|
|
|
uv run pytest tests/e2e/test_quadlet_jinja_import.py -v --no-cov
|
|
|
|
Seeding reuses the real import function against ``tests/fixtures/docs/``
|
|
with the deterministic mock embeddings — the ``test_import_documents.py``
|
|
pattern (truncate the KB, ``import_sources`` in a worker thread). This
|
|
suite's re-import changes the KB for the session; it is run in isolation
|
|
(A16), so there is no cross-suite interference.
|
|
|
|
Test → story mapping (Playwright Mapping Rule):
|
|
1. ``test_quadlet_and_jinja_indexed`` — ``GET /api/docs`` (admin session)
|
|
lists the four new-format fixtures with non-zero chunk counts and the
|
|
file stem as title — no env configuration needed (default set).
|
|
2. ``test_sources_table_shows_them`` (admin) — the Sources table renders
|
|
a row per new file, each with its ``.doc-link`` path link.
|
|
3. ``test_container_content_viewable`` — the phase-26 modal shows the
|
|
``.container`` file's TOML content (``[Container]`` section + sentinel)
|
|
with the stem as title.
|
|
4. ``test_jinja_retrievable_not_deflected`` — a question carrying the
|
|
``.j2`` sentinel FTS-matches the chunk (A8: LOW requires best cosine
|
|
below threshold **and** zero FTS hits) → honest-positive: the answer
|
|
bubble is not ``.is-deflected`` — and (phase 119, LOCKED A1) the
|
|
zero-read turn chips NOTHING (the ``templates/deploy.j2`` retrieval
|
|
doc is suggested context, not a chip; the retired phase-118 A4
|
|
union is gone).
|
|
|
|
Phase 97 adaptation: the Sources table is the DRILL-DOWN TREE — the
|
|
rows live at their folder levels (``docs`` → ``homelab`` → ``quadlet``
|
|
/ ``templates``); the drill is the only change, the asserted
|
|
rows/links are unchanged.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
from pathlib import Path
|
|
from threading import Thread
|
|
from typing import Any
|
|
|
|
from playwright.sync_api import 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
|
|
from e2e.auth_helpers import login
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
FIXTURES = REPO / "tests" / "fixtures" / "docs"
|
|
|
|
#: The four new-format fixtures (A9 revised 2026-08-27): path → stem title
|
|
#: (no H1 → ``extract_title`` falls back to the file stem).
|
|
NEW_FORMAT_DOCS = {
|
|
"homelab/quadlet/compose.container": "compose",
|
|
"homelab/quadlet/lan.network": "lan",
|
|
"homelab/quadlet/cache.volume": "cache",
|
|
"homelab/templates/deploy.j2": "deploy",
|
|
}
|
|
|
|
#: Carries the ``.j2`` fixture's sentinel — the hyphens split into the
|
|
#: ``rese | jinja | sentinel | 33dd`` tsquery tokens that FTS-match the
|
|
#: chunk holding ``{% set sentinel = "RESE-JINJA-SENTINEL-33dd" %}``.
|
|
JINJA_QUESTION = "What is RESE-JINJA-SENTINEL-33dd?"
|
|
|
|
|
|
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's sync API keeps an asyncio loop running on the test thread,
|
|
so ``asyncio.run`` cannot be called directly from a test body.
|
|
"""
|
|
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 _reset_db(mock_port: int, seed: bool) -> ImportSummary | None:
|
|
"""Truncate the KB (and query log), then optionally re-import fixtures."""
|
|
with SessionLocal() as db:
|
|
db.execute(text("TRUNCATE chunks, documents, query_log"))
|
|
db.commit()
|
|
if not seed:
|
|
return None
|
|
return _run_in_thread(_import_fixtures(mock_port))
|
|
|
|
|
|
def _drill(page: Page, *names: str) -> None:
|
|
"""Drill one level at a time (phase 97 — client-side, no fetch,
|
|
no URL change): each name is the EXACT text of the source/folder
|
|
link at the current level."""
|
|
for name in names:
|
|
page.click(f'#folders-tbody a.folder-link:text-is("{name}")')
|
|
|
|
|
|
def _go_top(page: Page) -> None:
|
|
"""Back to the top level: the breadcrumb's top-level link (call
|
|
between drills only — the breadcrumb is hidden at the top)."""
|
|
page.locator("#kb-crumb a.kb-crumb-link").first.click()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 1. Default-extensions import indexes the new formats (API view)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_quadlet_and_jinja_indexed(page: Page, app_url: str, mock_llm: int, db_ready: None) -> None:
|
|
summary = _reset_db(mock_llm, seed=True)
|
|
assert summary is not None
|
|
# The four fixtures joined the default set (A9 revised 2026-08-27) —
|
|
# the import needed no BOR_IMPORT_EXTENSIONS configuration at all.
|
|
assert summary.added == 13, f"expected all 13 fixture docs, added {summary.added}"
|
|
|
|
login(page, app_url) # phase 16: the catalog is admin-only
|
|
r = page.request.get(f"{app_url}/api/docs")
|
|
assert r.status == 200
|
|
by_path = {d["path"]: d for d in r.json()["documents"]}
|
|
for path, stem in NEW_FORMAT_DOCS.items():
|
|
doc = by_path.get(path)
|
|
assert doc is not None, f"{path} missing from GET /api/docs"
|
|
assert doc["chunks"] > 0, f"{path} indexed zero chunks"
|
|
# No H1 → the stem is the title, exactly like the other
|
|
# non-markdown formats.
|
|
assert doc["title"] == stem, f"{path} title {doc['title']!r}, want stem {stem!r}"
|
|
assert doc["source"] == "docs"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 2. The Sources table renders a row (with path link) per new file
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_sources_table_shows_them(page: Page, app_url: str, mock_llm: int, db_ready: None) -> None:
|
|
_reset_db(mock_llm, seed=True)
|
|
login(page, app_url) # phase 16: the Sources catalog is admin-only
|
|
for i, path in enumerate(NEW_FORMAT_DOCS):
|
|
# Phase 97: the rows live at their folder levels — drill
|
|
# source → folder(s) per path (the drill is the only change).
|
|
if i > 0:
|
|
_go_top(page)
|
|
_drill(page, "docs", *path.rsplit("/", 1)[0].split("/"))
|
|
row = page.locator("#docs-tbody tr", has_text=path)
|
|
expect(row).to_have_count(1)
|
|
link = row.locator("td:nth-child(2) a.doc-link")
|
|
expect(link).to_have_count(1)
|
|
# The full path is the link's accessible context (ellipsis is
|
|
# visual only) — the same contract the other rows carry.
|
|
expect(link).to_have_attribute("title", path)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 3. The .container file's TOML is viewable in the modal (stem title)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_container_content_viewable(
|
|
page: Page, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_reset_db(mock_llm, seed=True)
|
|
login(page, app_url) # phase 16: the Sources catalog is admin-only
|
|
|
|
# Phase 97: the row lives at its folder level — drill first.
|
|
_drill(page, "docs", "homelab", "quadlet")
|
|
row = page.locator("#docs-tbody tr", has_text="homelab/quadlet/compose.container")
|
|
expect(row).to_have_count(1)
|
|
link = row.locator("td:nth-child(2) a.doc-link")
|
|
expect(link).to_have_attribute(
|
|
"href", "/document.html?source=docs&path=homelab%2Fquadlet%2Fcompose.container"
|
|
)
|
|
expect(link).not_to_have_attribute("target")
|
|
|
|
link.click()
|
|
expect(page.locator(".doc-modal")).to_be_visible()
|
|
# Stem title (no H1 in a quadlet unit file) + the extension badge.
|
|
expect(page.locator("#doc-modal-title")).to_have_text("compose")
|
|
expect(page.locator("#doc-modal-meta .format-badge")).to_have_text("container")
|
|
# Non-markdown content renders as escaped monospace text in a pre —
|
|
# the whole TOML, [Container] section and sentinel included.
|
|
pre = page.locator("#doc-modal-content pre.doc-raw")
|
|
expect(pre).to_have_count(1)
|
|
expect(pre).to_contain_text("[Container]")
|
|
expect(pre).to_contain_text("Image=docker.io/reese/compose-gateway:1.4.2")
|
|
expect(pre).to_contain_text("RESE-QUADLET-SENTINEL-77aa")
|
|
# Still on the Sources page: the modal is same-page (phase 26).
|
|
assert page.url == app_url + "/sources.html"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# 4. A .j2 sentinel question is retrievable and honest-positive (A8)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
def test_jinja_retrievable_not_deflected(
|
|
page: Page, app_url: str, mock_llm: int, db_ready: None
|
|
) -> None:
|
|
_reset_db(mock_llm, seed=True)
|
|
page.set_default_timeout(30_000)
|
|
login(page, app_url, next="/") # phase 79: chat is require_user-gated
|
|
page.fill("#message-input", JINJA_QUESTION)
|
|
page.click("#send-btn")
|
|
|
|
# Phase 119 (LOCKED A1): the turn read nothing, so ZERO citation
|
|
# chips — the .j2 retrieval doc is suggested context, not a chip
|
|
# (the retired phase-118 A4 union is gone). The turn is finished
|
|
# (and the grounded, non-deflected state is reached) when the
|
|
# answer settles with the send button recovered.
|
|
expect(page.locator(".msg.brain .bubble").last).to_contain_text(
|
|
"Deterministic mock answer for E2E", timeout=30_000
|
|
)
|
|
expect(page.locator("#send-label")).to_have_text("Send")
|
|
expect(page.locator(".msg.brain .source-chip")).to_have_count(0)
|
|
|
|
# A8: LOW requires best cosine < threshold AND zero FTS hits — the
|
|
# question's sentinel tokens FTS-match the .j2 chunk, so the gate is
|
|
# honest-positive whatever the mock's cosine says.
|
|
expect(page.locator(".msg.brain")).to_have_count(1)
|
|
expect(page.locator(".msg.brain.is-deflected")).to_have_count(0)
|