verify_chat.py
2.8 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
#!/usr/bin/env python3
"""Frontend verification: Jinja2 safety, JS function presence, DOM elements."""
import subprocess, sys
def curl(url):
r = subprocess.run(["curl", "-s", url, "--connect-timeout", "5", "--max-time", "10"],
capture_output=True, text=True, timeout=15)
return r.stdout
FAILURES = []
def check(name, condition):
if condition:
print(f" [PASS] {name}")
else:
print(f" [FAIL] {name}")
FAILURES.append(name)
html = curl("http://127.0.0.1:5000/chat")
print("=== Jinja2 safety ===")
check("No Jinja2 escaped quotes in template literal", 'data-action=\\"' not in html)
check("No inline onclick with escaped quotes", 'onclick=\\"event' not in html)
check("No style backslash bug", "style=\\\\\\'" not in html)
print("\n=== JS function presence ===")
check("toggleChatSidebar exists", 'function toggleChatSidebar' in html)
check("loadMessages exists", 'function loadMessages' in html)
check("selectConversation exists", 'function selectConversation' in html)
check("sendMessage exists", 'function sendMessage' in html)
check("newConversation exists", 'function newConversation' in html)
check("deleteConversation exists", 'function deleteConversation' in html)
check("renderMsg exists", 'function renderMsg' in html)
check("loadConversations exists", 'function loadConversations' in html)
print("\n=== DOM elements ===")
check("chatSidebar div", 'id="chatSidebar"' in html)
check("currentConvTitle span", 'id="currentConvTitle"' in html)
check("convList div", 'id="convList"' in html)
check("msgList div", 'id="msgList"' in html)
check("msgInput textarea", 'id="msgInput"' in html)
check("sendBtn button", 'id="sendBtn"' in html)
check("emptyState div", 'id="emptyState"' in html)
check("Base.html drawer present", 'id="drawer"' in html)
check("Base.html overlay present", 'id="overlay"' in html)
check("Base.html topbar present", 'class="topbar"' in html)
print("\n=== Responsive CSS ===")
check("Media query for mobile", '@media (max-width: 768px)' in html)
check("Chat sidebar transform transition", 'transform: translateX(-100%)' in html)
print(f"\n=== {len(FAILURES)} failure(s) ===")
if FAILURES:
for f in FAILURES:
print(f" FAIL: {f}")
sys.exit(1)
else:
print("ALL CHECKS PASSED")
# Full smoketest
print("\n=== Full smoketest ===")
for page in ["/", "/chat", "/articles", "/learn", "/reports", "/dashboard"]:
r = subprocess.run(["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}",
f"http://127.0.0.1:5000{page}"],
capture_output=True, text=True, timeout=10)
status = r.stdout.strip()
ok = "OK" if status == "200" else "FAIL"
print(f" {page} → {status} {ok}")
if status != "200":
FAILURES.append(f"Smoketest {page} returned {status}")
if FAILURES:
sys.exit(1)
print("\nVERIFY COMPLETE — ALL GREEN")