Files
weval-l99/l99-functional-test.py

34 lines
2.5 KiB
Python
Executable File

#!/usr/bin/env python3
import subprocess,json,datetime
R={"ts":datetime.datetime.now().isoformat(),"tests":[],"pass":0,"fail":0}
def t(name,cmd,check):
try:
out=subprocess.run(cmd,shell=True,capture_output=True,text=True,timeout=15).stdout.strip()
ok=check(out)
except Exception as e:
out=str(e)[:60];ok=False
R["tests"].append({"name":name,"s":"PASS" if ok else "FAIL","o":out[:60]})
if ok: R["pass"]+=1
else: R["fail"]+=1;print(f" FAIL: {name} -> {out[:50]}")
t("Sovereign responds","curl -s -X POST https://weval-consulting.com/api/wevia-json-api.php -H Content-Type:application/json -d {\"message\":\"hi\"} --max-time 10",lambda o:'"response"' in o and len(o)>20)
t("Director health","curl -sf https://weval-consulting.com/api/wevia-director.php?health --max-time 5",lambda o:"alive" in o)
t("NonReg >150","bash /var/www/html/api/nonreg-check.sh",lambda o:int(o.split("/")[0])>=150)
t("Auth login","curl -so /dev/null -w %{http_code} https://weval-consulting.com/auth/login.html --max-time 3",lambda o:o=="200")
t("Protected 302","curl -so /dev/null -w %{http_code} https://weval-consulting.com/ops-center.html --max-time 3",lambda o:o=="302")
t("Docker >=8","docker ps -q | wc -l",lambda o:int(o)>=8)
t("Qdrant cols","curl -sf http://127.0.0.1:6333/collections --max-time 3 | python3 -c \"import json,sys;print(len(json.load(sys.stdin).get('result',{}).get('collections',[])))\"",lambda o:int(o)>=4)
t("OSS 700+","curl -sf 'https://weval-consulting.com/api/oss-discovery.php?k=WEVADS2026&action=health' --max-time 5 | python3 -c \"import json,sys;print(json.load(sys.stdin).get('total',0))\"",lambda o:int(o)>=700)
t("Master API","curl -sf https://weval-consulting.com/api/wevia-master-api.php?health --max-time 5",lambda o:"version" in o)
t("Disk <90","df -h / | tail -1 | awk '{print $5}' | tr -d '%'",lambda o:int(o)<90)
t("Crons >30","(crontab -l 2>/dev/null; sudo crontab -l 2>/dev/null; cat /etc/cron.d/* 2>/dev/null) | grep -v '^#' | grep -v '^$' | wc -l",lambda o:int(o)>=30)
t("Git brain clean","cd /opt/wevia-brain && git status --short | grep -v GOLD | grep -v resolver | wc -l",lambda o:int(o)==0)
t("Guardian OK","bash /var/www/html/api/sso-guardian.sh",lambda o:"OK" in o)
t("Auto-fix runs","bash /var/www/html/api/auto-fix.sh 2>&1 | tail -1",lambda o:"NonReg" in o or "FIXES" in o)
total=R["pass"]+R["fail"]
pct=int(100*R["pass"]/total) if total else 0
print(f"\nFUNCTIONAL: {R['pass']}/{total} ({pct}%)")
json.dump(R,open("/opt/weval-l99/functional-test-results.json","w"),indent=2)