verify_skills.py 2.56 KB
#!/usr/bin/env python3
"""VERIFY phase: Skills page smoketest + frontend checks."""
import subprocess, sys

BASE = "http://127.0.0.1:5001"
errors = []

def curl(path):
    cmd = ["curl", "-s", f"{BASE}{path}"]
    r = subprocess.run(cmd, capture_output=True, text=True, timeout=15)
    return r.stdout, r.returncode

def http_code(path):
    cmd = ["curl", "-s", "-o", "/dev/null", "-w", "%{http_code}", f"{BASE}{path}"]
    r = subprocess.run(cmd, capture_output=True, text=True, timeout=10)
    return r.stdout.strip()

# 1. Skills menu entry check
print("=== 1. Skills menu entry ===")
html, _ = curl("/")
if '/skills' in html and 'Skills' in html:
    print("  PASS: Skills link in menu")
else:
    print("  FAIL: Skills link missing")
    errors.append("menu")

# 2. JS/Jinja2 escape checks (simple grep)
print("=== 2. Frontend JS checks ===")
html, _ = curl("/")
# Check for common escape bugs
escaped_quote = chr(92) + chr(92) + chr(92) + '"'
if escaped_quote in html:
    print(f"  FAIL: triple-escaped quotes found")
    errors.append("js-escape")
else:
    print("  PASS: JS CLEAN")
    
# Check for jinja2 literal escaping
jinja_esc = 'data-action=' + chr(92) + '"'
if jinja_esc in html:
    print(f"  FAIL: jinja2 escaped quotes in template literal")
    errors.append("jinja2-escape")
else:
    print("  PASS: JINJA2 CLEAN")

# 3. Smoketest - all key pages
print("=== 3. Smoketest ===")
pages = ["/", "/skills", "/skill/feishu-todo-sync", "/articles", "/learn", "/reports", "/chat", "/cron", "/jobs", "/dashboard"]
for p in pages:
    code = http_code(p)
    if code == "200":
        print(f"  {code} {p}")
    else:
        print(f"  FAIL {code} {p}")
        errors.append(p)

# 4. Skills page content
print("=== 4. Skills page content ===")
html, _ = curl("/skills")
checks = ['skill-name', 'use-count', 'skill-item', 'skill-list', 'SKILL']
found_any = any(c.lower() in html.lower() for c in checks)
if found_any:
    # Count skills
    count = html.count('skill-name') or html.count('skill-item') or 'N/A'
    print(f"  PASS: skills list content found (skill-name x{count})")
else:
    print("  FAIL: no skill list content")
    errors.append("skills-content")

# 5. Skill detail page
print("=== 5. Skill detail page ===")
html, _ = curl("/skill/feishu-todo-sync")
if 'feishu-todo-sync' in html.lower():
    print("  PASS: skill detail page shows skill name")
else:
    print("  FAIL: skill detail page")
    errors.append("skill-detail")

# Summary
if not errors:
    print("\n=== ALL VERIFY CHECKS PASSED ===")
    sys.exit(0)
else:
    print(f"\n=== FAILURES: {', '.join(errors)} ===")
    sys.exit(1)