forked from ChelseaKR/fare-policy-assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_public_ux.py
More file actions
115 lines (80 loc) · 3.88 KB
/
Copy pathtest_public_ux.py
File metadata and controls
115 lines (80 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
"""Regression checks for the public rider surfaces.
These checks deliberately stay outside ``test_web.py``: they exercise the
static/generator contracts owned by the public UX slice without coupling them
to Lambda routing.
"""
from __future__ import annotations
from pathlib import Path
import pytest
from bs4 import BeautifulSoup
from assistant.ingest import load_chunks
from web.embed import EMBED_HTML
from web.guide import render_guide
from web.offline import render_offline_reference
INDEX = Path(__file__).parents[1] / "web" / "index.html"
@pytest.mark.parametrize("renderer", [render_guide, render_offline_reference])
def test_static_modes_disclose_the_complete_snapshot_window(renderer):
chunks = load_chunks()
dates = sorted({chunk.fetch_date for chunk in chunks})
html = renderer(chunks)
assert f"from {dates[0]} through {dates[-1]}" in html
assert "not live agency pages" in html
assert "Corpus version (full)" in html
assert "active page-view version" in html
def test_main_ui_has_distinct_progress_and_conversation_live_regions():
soup = BeautifulSoup(INDEX.read_text(encoding="utf-8"), "html.parser")
status = soup.find(id="status")
assert status is not None
assert status.get("role") == "status"
assert status.get("aria-live") == "polite"
assert status.get("aria-atomic") == "true"
transcript = soup.find(id="transcript")
assert transcript is not None
assert transcript.get("role") == "log"
assert transcript.get("aria-live") == "polite"
assert transcript.get("aria-relevant") == "additions"
assert transcript.get("aria-label")
def test_embed_answer_region_is_named_and_announced():
soup = BeautifulSoup(EMBED_HTML, "html.parser")
status = soup.find(id="status")
assert status is not None
assert status.get("role") == "status"
assert status.get("aria-atomic") == "true"
answer = soup.find(id="answer")
assert answer is not None
assert answer.get("role") == "region"
assert answer.get("aria-label") == "Assistant answer"
assert answer.get("aria-live") == "polite"
assert answer.get("aria-busy") == "false"
def test_main_and_embed_use_strong_visible_focus_treatment():
main = INDEX.read_text(encoding="utf-8")
for html in (main, EMBED_HTML):
assert ":focus-visible" in html
assert "outline: 4px solid #1d4ed8" in html
assert "outline-offset: 3px" in html
def test_public_beta_renders_prose_and_ignores_additive_structured_payload():
html = INDEX.read_text(encoding="utf-8")
assert "renderStructured" not in html
assert "ans.innerHTML = render(data.answer);" in html
assert "The API may expose an additive `structured` field" in html
def test_main_and_embed_strip_combined_citation_tags_from_rider_prose():
main = INDEX.read_text(encoding="utf-8")
assert r"(?:,\s*doc:[a-z0-9-]+)*" in main
assert r"(?:,\s*doc:[a-z0-9-]+)*" in EMBED_HTML
def test_public_evaluation_status_separates_baseline_from_latest_red_run():
main = INDEX.read_text(encoding="utf-8")
evidence = (INDEX.parents[1] / "docs" / "pages" / "index.html").read_text(encoding="utf-8")
for html in (main, evidence):
assert "Committed promoted baseline" in html
assert "192" in html and "201" in html
assert "Latest observed" in html
assert "190" in html and "175" in html and "186" in html
assert "cross-agency" in html
assert "red" in html
def test_only_supported_answers_are_added_to_client_follow_up_history():
html = INDEX.read_text(encoding="utf-8")
assert 'if (r.data.kind === "answered")' in html
assert 'r.data.kind === "refused_input" ? "Question withheld for privacy."' in html
assert html.index('input.value = "";') < html.index('fetch("/api/ask"')
def test_embed_clears_transient_question_before_request():
assert EMBED_HTML.index('input.value = "";') < EMBED_HTML.index('fetch("/api/ask"')