test_stale_anomaly_verify.py
4.62 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
#!/usr/bin/env python3
"""RED phase: Verify that the 4 stale anomaly records' functionality is actually complete.
Records:
recvpl61g9tjzW - Main task: Chat page bug fix + ChatGPT feature parity
recvpl64pgw0zz - S6: Message edit + regenerate
recvpl64SQejSh - S7: Code highlighting + dark mode
recvpl65oVM7QD - S8: Mobile adaptation + e2e verification
"""
import os, sys, subprocess
PROJECT = os.path.expanduser("~/wechat-viewer")
AICHAT = os.path.join(PROJECT, "templates", "aichat.html")
APP_PY = os.path.join(PROJECT, "app.py")
results = []
def check(name, condition, detail=""):
status = "PASS" if condition else "FAIL"
results.append((name, status, detail))
print(f" [{status}] {name}: {detail}")
print("=== TC1: S6 - Message Edit + Regenerate ===")
s6_test = os.path.join(PROJECT, "test_s6_edit_regenerate.py")
check("S6 test file exists", os.path.exists(s6_test), f"{os.path.getsize(s6_test) if os.path.exists(s6_test) else 0} bytes")
if os.path.exists(AICHAT):
with open(AICHAT) as f:
html = f.read()
check("S6 edit button in HTML", "edit" in html.lower() and ("regenerate" in html.lower() or "重新生成" in html), "edit/regenerate found in aichat.html")
else:
check("S6 aichat.html exists", False, "NOT FOUND")
if os.path.exists(APP_PY):
with open(APP_PY) as f:
appcode = f.read()
check("S6 edit API route", "/api/conversations" in appcode and ("api_messages_edit" in appcode or "regenerate" in appcode.lower()), "edit/regenerate API in app.py")
else:
check("S6 app.py exists", False, "NOT FOUND")
print()
print("=== TC2: S7 - Code Highlight + Dark Mode ===")
s7_test = os.path.join(PROJECT, "test_s7_highlight.py")
check("S7 test file exists", os.path.exists(s7_test), f"{os.path.getsize(s7_test) if os.path.exists(s7_test) else 0} bytes")
if os.path.exists(AICHAT):
with open(AICHAT) as f:
html = f.read()
check("S7 highlight.js in HTML", "highlight" in html.lower() or "hljs" in html.lower(), "highlight.js reference found")
check("S7 dark mode in HTML", "dark" in html.lower() or "#343541" in html or "theme" in html.lower(), "dark mode found")
else:
check("S7 aichat.html exists", False, "NOT FOUND")
print()
print("=== TC3: S8 - Mobile Adaptation ===")
s8_test = os.path.join(PROJECT, "test_chat_mobile.py")
check("S8 test file exists", os.path.exists(s8_test), f"{os.path.getsize(s8_test) if os.path.exists(s8_test) else 0} bytes")
if os.path.exists(AICHAT):
with open(AICHAT) as f:
html = f.read()
check("S8 mobile media query", "@media" in html and ("768" in html or "mobile" in html.lower() or "responsive" in html.lower()), "mobile media query found")
check("S8 sidebar/toggle", "sidebar" in html.lower() or "drawer" in html.lower() or "toggle" in html.lower(), "sidebar/toggle found")
else:
check("S8 aichat.html exists", False, "NOT FOUND")
print()
print("=== TC4: Main Task - Core Functionality ===")
if os.path.exists(AICHAT):
with open(AICHAT) as f:
html = f.read()
check("MT stream/SSE support", "EventSource" in html or "stream" in html.lower() or "sse" in html.lower(), "streaming support found")
check("MT session management", "session" in html.lower() or "conversation" in html.lower(), "session management found")
check("MT send button", "sendBtn" in html or "send-btn" in html or "send" in html.lower(), "send button found")
check("MT typewriter effect", "typewriter" in html.lower() or "typing" in html.lower() or "setInterval" in html, "typewriter/typing effect found")
print()
print("=== TC5: Smoke Test ===")
smoke_test = os.path.join(PROJECT, "test_smoke.py")
check("Smoke test file exists", os.path.exists(smoke_test), f"{os.path.getsize(smoke_test) if os.path.exists(smoke_test) else 0} bytes")
if os.path.exists(smoke_test):
try:
r = subprocess.run([sys.executable, smoke_test], capture_output=True, text=True, timeout=30, cwd=PROJECT)
check("Smoke test runs", r.returncode == 0, f"exit={r.returncode}, {r.stdout[-200:] if r.stdout else ''} {r.stderr[-200:] if r.stderr else ''}")
except Exception as e:
check("Smoke test runs", False, f"Exception: {e}")
else:
check("Smoke test runs", False, "smoke test file not found")
print()
print("=== Summary ===")
passed = sum(1 for _, s, _ in results if s == "PASS")
failed = sum(1 for _, s, _ in results if s == "FAIL")
print(f"Passed: {passed}, Failed: {failed}, Total: {len(results)}")
if failed > 0:
print("\nFAILED CHECKS:")
for name, status, detail in results:
if status == "FAIL":
print(f" - {name}: {detail}")
sys.exit(1)
else:
print("\nAll checks passed - all functionality verified as complete")
sys.exit(0)