#!/usr/bin/env python3 """S3 RED test: Verify cron.html job cards link to /cron/.""" import subprocess, sys, os os.chdir(os.path.expanduser("~/wechat-viewer")) BASE = "http://127.0.0.1:5000" FAIL = 0 r = subprocess.run(["curl", "-s", f"{BASE}/cron"], capture_output=True, text=True, timeout=10) html = r.stdout 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}") # 1. Cron page loads check("GET /cron returns 200", lambda: r.returncode == 0 and len(html) > 100) # 2. Job card onclick redirects to /cron/ check("onclick uses window.location=/cron/", lambda: "/cron/" in html and "location" in html) # 3. NOT using old viewLogs in onclick check("NOT using viewLogs in onclick", lambda: 'onclick="viewLogs' not in html and "onclick='viewLogs" not in html) # 4. Has href-like navigation check("Contains /cron/ path in script", lambda: "/cron/" in html) # 5. Jinja2 escape check check("No Jinja2 script escapes", lambda: 'onclick=\\"' not in html) print(f"\nResult: {FAIL} failures") sys.exit(min(FAIL, 1))