fix(web): history tab copy — every chat saves automatically, there is no Save button
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.
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
"""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)
|
||||
@@ -0,0 +1,79 @@
|
||||
"""Unit: phase-66 text pins — the History tab describes the auto-save
|
||||
model, not the retired Save button.
|
||||
|
||||
House pattern (``test_stale_ui_copy.py``): read ``frontend/history.html``
|
||||
as text and assert substrings — no browser. The browser-visible layer is
|
||||
gated by the dedicated story suite (``tests/e2e/test_history_copy.py``);
|
||||
these pins catch a silent regression in the template without it.
|
||||
|
||||
Locked decision (owner-locked A3, 2026-09-01): every conversation saves
|
||||
itself automatically — there is NO Save button (retired phase 55, owner-
|
||||
locked A2, pinned by ``test_save_share_ux.py::test_anonymous_auto_save``),
|
||||
so no user-visible History-tab string may name one.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
FRONTEND = Path(__file__).resolve().parents[2] / "frontend"
|
||||
|
||||
# --- the locked auto-save copy (owner-locked A3) -----------------------
|
||||
|
||||
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."
|
||||
|
||||
# --- the retired manual-save copy (must be nowhere) --------------------
|
||||
|
||||
OLD_META = "every conversation you saved"
|
||||
OLD_PAGE_SUB = "you pressed <strong>Save</strong>"
|
||||
OLD_EMPTY_ROW = "press <strong>Save</strong> in the chat"
|
||||
|
||||
# --- state-language survivors (must STAY — "saved" is a state, not a
|
||||
# button; their absence would prove over-deletion) ------------------
|
||||
|
||||
STATE_STRINGS = (
|
||||
"<h1>Saved chats</h1>",
|
||||
"Sign in to view your saved chats",
|
||||
"Saved conversations are admin-only",
|
||||
)
|
||||
|
||||
|
||||
def _text() -> str:
|
||||
return (FRONTEND / "history.html").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def _norm(text: str) -> str:
|
||||
"""Collapse whitespace runs — the templates wrap long lines, so the
|
||||
locked copy is pinned against the normalized text."""
|
||||
return re.sub(r"\s+", " ", text).strip()
|
||||
|
||||
|
||||
def test_manual_save_copy_is_gone() -> None:
|
||||
"""history.html: the three retired manual-save strings are GONE —
|
||||
the copy no longer tells the visitor to press a Save button."""
|
||||
html = _text()
|
||||
for frag in (OLD_META, OLD_PAGE_SUB, OLD_EMPTY_ROW):
|
||||
assert frag not in html, f"retired manual-save copy still present: {frag!r}"
|
||||
|
||||
|
||||
def test_locked_auto_save_copy_present_exactly_once() -> None:
|
||||
"""The three locked (A3) auto-save strings, each exactly once in
|
||||
history.html (a second copy could drift out of sync)."""
|
||||
html = _norm(_text())
|
||||
assert html.count(META) == 1, "the locked meta description"
|
||||
assert html.count(PAGE_SUB) == 1, "the locked page-sub"
|
||||
assert html.count(EMPTY_ROW) == 1, "the locked empty-row string"
|
||||
|
||||
|
||||
def test_state_language_survivors_are_untouched() -> None:
|
||||
"""Proof of NO over-deletion: the strings where "saved" is a state —
|
||||
the <h1>, the anonymous gate title, and the gate sub — stay exactly
|
||||
as phase 50 wrote them."""
|
||||
html = _text()
|
||||
for frag in STATE_STRINGS:
|
||||
assert frag in html, f"state-language survivor deleted: {frag!r}"
|
||||
@@ -216,9 +216,11 @@ def test_history_table_skeleton() -> None:
|
||||
assert "hidden" in row.group(0)
|
||||
assert 'id="history-empty-row"' in row.group(0)
|
||||
assert "<td colspan=\"6\">" in html
|
||||
# Phase 66 (owner-locked A3, 2026-09-01): the auto-save copy —
|
||||
# the Save button is retired (phase 55), every conversation
|
||||
# saves itself; the old "press Save" line is gone.
|
||||
assert (
|
||||
"No saved chats yet — finish a conversation and press"
|
||||
" <strong>Save</strong> in the chat."
|
||||
"No saved chats yet — start a conversation and it will be saved automatically."
|
||||
) in html
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user