test_s5_rename.py
3.45 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
#!/usr/bin/env python3
"""RED test for S5: Session 管理增强
Tests:
TC1: renderConversations has no duplicate function declaration
TC2: Inline rename (startRename) exists and PUTs to API
TC3: Delete conversation (deleteConversation) exists with confirmation
TC4: Session info persistence (what's the actual bug?)
"""
import sys, os, json, subprocess
HTML_PATH = "/data/data/com.termux/files/home/wechat-viewer/templates/aichat.html"
BASE = "http://127.0.0.1:5001"
def read_html():
r = subprocess.run(["su", "-c", "cat " + HTML_PATH], capture_output=True, text=True, timeout=10)
return r.stdout
def curl_get(path):
r = subprocess.run(["curl", "-s", BASE + path], capture_output=True, text=True, timeout=15)
return json.loads(r.stdout) if r.stdout else {}
def curl_post(path, data):
body = json.dumps(data)
r = subprocess.run(["curl", "-s", "-X", "POST", BASE + path,
"-H", "Content-Type: application/json", "-d", body], capture_output=True, text=True, timeout=15)
return json.loads(r.stdout) if r.stdout else {}
def main():
html = read_html()
errors = []
# TC1: No duplicate function renderConversations
# Count occurrences of "function renderConversations"
func_count = html.count("function renderConversations")
if func_count > 1:
errors.append("TC1: Duplicate renderConversations function (count=" + str(func_count) + ") - JS error")
# TC2: startRename with PUT API
if "function startRename" not in html:
errors.append("TC2: startRename function missing")
if "method: 'PUT'" not in html:
errors.append("TC2: startRename missing PUT API call for rename")
if "/api/conversations/" not in html:
errors.append("TC2: startRename missing API path")
# TC3: deleteConversation with confirm
if "function deleteConversation" not in html:
errors.append("TC3: deleteConversation function missing")
if "confirm" not in html:
errors.append("TC3: deleteConversation missing confirmation dialog")
if "DELETE" not in html:
errors.append("TC3: deleteConversation missing DELETE method")
# TC4: rename conversation via API
conv = curl_post("/api/conversations", {"title": "test s5 rename old"})
if not conv.get("ok"):
errors.append("TC4: Cannot create test conversation")
else:
conv_id = conv["data"]["id"]
# Test PUT rename
r2 = subprocess.run(["curl", "-s", "-X", "PUT", BASE + "/api/conversations/" + str(conv_id),
"-H", "Content-Type: application/json",
"-d", '{"title": "test s5 renamed"!r}'], # wrong, let me fix
capture_output=True, text=True, timeout=15)
# Actually, let me just verify the endpoint accepts PUT
rename = subprocess.run(["curl", "-s", "-X", "PUT",
BASE + "/api/conversations/" + str(conv_id),
"-H", "Content-Type: application/json",
"-d", '{"title":"test s5 renamed"}'],
capture_output=True, text=True, timeout=15)
rename_data = json.loads(rename.stdout) if rename.stdout else {}
if rename_data.get("ok"):
print(" TC4: PUT rename succeeded ✓")
else:
errors.append("TC4: PUT /api/conversations/<id> rename failed: " + str(rename_data))
if errors:
print("\nRED: " + str(len(errors)) + " failures")
for e in errors:
print(" FAIL: " + e)
sys.exit(1)
else:
print("\nGREEN: All checks passed")
sys.exit(0)
if __name__ == '__main__':
main()