meta description -> locked (A3) auto-save string (history.html L6). page-sub -> locked (A3) string, the <strong>Save</strong> emphasis retired with the button (L106-109). empty row -> locked (A3) string; colspan=6, hidden, and row id untouched (L163). h1, the anonymous gate section, and history.js are byte-identical — state language verified accurate.
115 lines
4.4 KiB
Python
115 lines
4.4 KiB
Python
"""Phase 66 E2E (Playwright): the History tab's auto-save copy.
|
|
|
|
TODO.md L4 (owner 2026-09-01): "Update the history tab — the text
|
|
still reads like there's a save button. There isn't anymore, every
|
|
chat is saved."
|
|
|
|
Run in isolation (DB must be up: ``podman compose up -d db``):
|
|
|
|
uv run pytest tests/e2e/test_history_copy.py -v --no-cov
|
|
|
|
One phase, one file (AGENTS.md rule 4). What is asserted: the SIGNED-IN
|
|
ADMIN sees the actual page (the anonymous gate hidden, the table
|
|
rendered) reading the locked (A3) auto-save copy — and the rendered
|
|
page text nowhere reads like a Save button exists (none has since the
|
|
phase-55 owner-lock A2: every conversation auto-saves via ``app.js``
|
|
``persistConversation``).
|
|
|
|
Determinism: every assertion is settled-state (static HTML + the one
|
|
0-row ``/api/chats`` fetch); Playwright ``expect`` retries ride out the
|
|
table load.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
from playwright.sync_api import Page, expect
|
|
from sqlalchemy import text
|
|
|
|
from app.db import SessionLocal
|
|
from e2e.auth_helpers import login
|
|
|
|
REPO = Path(__file__).resolve().parents[2] # noqa: F841 — house pattern
|
|
|
|
# --- the locked auto-save copy (owner-locked A3, phase 66 task 01) -----
|
|
|
|
META = "Saved chats — every conversation is saved automatically, one click back."
|
|
PAGE_SUB = (
|
|
"Every conversation is saved automatically — newest activity first. "
|
|
"Click a title to return to that chat."
|
|
)
|
|
EMPTY_ROW = "No saved chats yet — start a conversation and it will be saved automatically."
|
|
|
|
#: Rendered copy that would still read like a Save button exists
|
|
#: (retired, phase 55 A2). The scan runs alongside a pinned <h1> so it
|
|
#: cannot pass by deleting the heading.
|
|
SAVE_BUTTON_PATTERNS = (
|
|
re.compile(r"press(ed)?\s+save", re.IGNORECASE),
|
|
re.compile(r"save\s+button", re.IGNORECASE),
|
|
)
|
|
|
|
|
|
def _reset_db() -> None:
|
|
"""The house reset (TRUNCATE chunks, documents, query_log,
|
|
steering_notes) EXTENDED with ``saved_chats`` — so the History tab
|
|
renders a genuinely empty table and the empty-row copy is pinned in
|
|
the real 0-row state, not only in the template. No KB re-import:
|
|
this suite reads static copy and never asks the brain a question."""
|
|
with SessionLocal() as db:
|
|
db.execute(
|
|
text("TRUNCATE chunks, documents, query_log, steering_notes, saved_chats")
|
|
)
|
|
db.commit()
|
|
|
|
|
|
def test_history_tab_shows_auto_save_copy(
|
|
page: Page, app_url: str, db_ready: None
|
|
) -> None:
|
|
_reset_db()
|
|
page.set_default_timeout(30_000)
|
|
|
|
login(page, app_url, next="/history.html")
|
|
expect(page).to_have_url(app_url + "/history.html", timeout=30_000)
|
|
|
|
# The anonymous gate is hidden (the login worked — history.js hides
|
|
# it for the admin) and the table region is rendered.
|
|
expect(page.locator("#history-gate")).to_be_hidden(timeout=15_000)
|
|
expect(page.locator("#history-table-wrap")).to_be_visible()
|
|
|
|
# The 0-row fetch reveals #history-empty-row (history.js) and its
|
|
# text is exactly the locked (A3) empty-row string.
|
|
empty_row = page.locator("#history-empty-row")
|
|
expect(empty_row).to_be_visible(timeout=15_000)
|
|
raw = empty_row.text_content()
|
|
assert raw is not None and raw.strip() == EMPTY_ROW
|
|
|
|
# The .page-sub reads the locked (A3) page-sub string
|
|
# (whitespace-normalized — the template wraps the line).
|
|
page_sub = page.locator(".page-sub")
|
|
expect(page_sub).to_have_count(1)
|
|
assert re.sub(r"\s+", " ", page_sub.inner_text()).strip() == PAGE_SUB
|
|
|
|
# The meta description is the locked (A3) meta string.
|
|
meta = page.locator('meta[name="description"]')
|
|
expect(meta).to_have_count(1)
|
|
assert meta.get_attribute("content") == META
|
|
|
|
# The no-button contract: the WHOLE rendered page reads neither
|
|
# "press(ed) Save" nor "Save button" — while the <h1> still reads
|
|
# "Saved chats" (asserted present, so the scan cannot pass by
|
|
# deleting the heading).
|
|
h1 = page.locator("h1")
|
|
expect(h1).to_have_count(1)
|
|
expect(h1).to_have_text("Saved chats")
|
|
body_text = page.locator("body").inner_text()
|
|
for pattern in SAVE_BUTTON_PATTERNS:
|
|
assert not pattern.search(body_text), (
|
|
f"History tab copy still reads like a Save button exists: "
|
|
f"{pattern.pattern!r} in {body_text!r}"
|
|
)
|
|
|
|
# The control itself is gone from the app (phase 55 A2) — not just
|
|
# the copy: no #save-chat-btn anywhere on the page.
|
|
expect(page.locator("#save-chat-btn")).to_have_count(0)
|