#!/usr/bin/env python3 """S2 RED test: Verify cron_job.html dark terminal template.""" import subprocess, json, sys, os os.chdir(os.path.expanduser("~/wechat-viewer")) BASE = "http://127.0.0.1:5000" FAIL = 0 def check(desc, test_fn): global FAIL ok = test_fn() status = "PASS" if ok else "FAIL" if not ok: FAIL += 1 print(f"[{status}] {desc}") # Get a job ID r = subprocess.run(["curl", "-s", f"{BASE}/api/cron/list"], capture_output=True, text=True, timeout=10) jobs = json.loads(r.stdout).get("data", []) if not jobs: print("SKIP: No cron jobs") sys.exit(0) job = jobs[0] job_id = job["id"] print(f"Testing with: {job['name']} (id={job_id})") # Fetch page r = subprocess.run(["curl", "-s", f"{BASE}/cron/{job_id}"], capture_output=True, text=True, timeout=10) html = r.stdout # 1. Job name present check(f"Page contains job name", lambda: job["name"] in html) # 2. Dark background check("Dark background (#1e1e1e)", lambda: "#1e1e1e" in html or "1e1e1e" in html) # 3. Green terminal text check("Green text (#27ae60)", lambda: "#27ae60" in html or "27ae60" in html) # 4. Return link to /cron check("Return link to /cron", lambda: 'href="/cron"' in html) # 5. JS loads logs via /api/cron/logs check("JS fetches /api/cron/logs/", lambda: "/api/cron/logs/" in html) # 6. CSS class for log entries check("Log entry CSS", lambda: "log-entry" in html or "timeline" in html.lower()) # 7. Jinja2 escape check check("No Jinja2 backslash escape in onclick", lambda: 'onclick=\\"' not in html) check("No triple-escaped quotes", lambda: '\\\\\\\\\\\\\\"' not in html) check("No style backslash bug", lambda: "style=\\\\\\'" not in html) # 8. Monospace font for logs check("Monospace font-family", lambda: "monospace" in html) sys.exit(min(FAIL, 1))