Files
weval-consulting/tests/run-capabilities.py

91 lines
4.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""WEVIA Capabilities + Chat NonReg — Python runner v2 (localhost)"""
import json, subprocess, sys, os, time, re
CHAT = "http://localhost/api/weval-ia"
RESULTS_FILE = "/var/www/html/test-report/full-nonreg-results.json"
def chat(msg, timeout=60):
try:
r = subprocess.run(["curl","-s","-m",str(timeout),"-X","POST",CHAT,
"-H","Content-Type: application/json",
"-d",json.dumps({"message":msg,"language":"fr","widget":True})],
capture_output=True, text=True, timeout=timeout+10)
return json.loads(r.stdout) if r.stdout.strip() else {}
except Exception as e:
print(f" ⚠ Error: {e}")
return {}
def check(name, cat, condition, detail=""):
status = "pass" if condition else "fail"
d = detail[:200].replace('"',"'").replace('\n',' ')
print(f" {'' if condition else ''} {name}" + (f"{d[:80]}" if not condition and d else ""))
return {"name":name,"status":status,"detail":d,"category":cat}
# Load existing auth+manager+oss results
results = []
try:
with open(RESULTS_FILE) as f:
existing = json.load(f)
results = [t for t in existing.get("tests",[]) if t.get("category") not in ("chatbot","capability")]
except: pass
print("\n💬 Chatbot Tests (localhost)")
d = chat("Life Sciences pharma consulting")
resp = d.get("response","")
has_cn = any(0x4e00 <= ord(c) <= 0x9fff for c in resp)
results.append(check("CHAT-04 No Chinese", "chatbot", not has_cn, "CHINESE" if has_cn else resp[:80]))
d = chat("Quels sont vos services ?")
resp = (d.get("response","") or "").lower()
leaks = [w for w in ["groq","cerebras","ollama","hetzner","ovh","pmta","postgresql"] if w in resp]
results.append(check("CHAT-05 No provider leak", "chatbot", len(leaks)==0, "LEAK:"+",".join(leaks) if leaks else "Clean"))
print("\n🎯 Capabilities (localhost)")
d = chat("Ecris une fonction Python hello world")
resp = d.get("response","")
results.append(check("CAP-01 Code Python","capability",bool(re.search(r"def |print|python|hello",resp,re.I)),resp[:100]))
d = chat("Cree composant React bouton compteur useState")
resp = d.get("response","")
results.append(check("CAP-02 Code React","capability",bool(re.search(r"useState|React|component|import|function",resp,re.I)),resp[:100]))
d = chat("Compare SAP vs Oracle ERP en 3 points")
resp = d.get("response","")
results.append(check("CAP-03 Consulting","capability",len(resp)>100,f"{len(resp)} chars"))
d = chat("Genere image artistique coucher soleil ocean",timeout=30)
resp = d.get("response","")
results.append(check("CAP-04 Image","capability",bool(re.search(r"!\[|image.*succes|pollinations|\.png",resp,re.I)),resp[:120]))
d = chat("Genere un logo pour TechVision startup IA",timeout=60)
resp = d.get("response","")
results.append(check("CAP-05 Logo SVG","capability",bool(re.search(r"svg|logo|IMAGE|viewBox|circle|path|generation",resp,re.I)),resp[:120]))
d = chat("Genere PDF audit cybersecurite PME marocaine",timeout=90)
resp = d.get("response","")
results.append(check("CAP-06 PDF","capability",bool(re.search(r"PDF|pdf|telecharger|\.pdf|pages|precisez|genere",resp,re.I)),resp[:120]))
d = chat("Schema mermaid processus achats 5 etapes",timeout=60)
resp = d.get("response","")
results.append(check("CAP-07 Mermaid","capability",bool(re.search(r"mermaid|graph|flowchart|```|\.png|diagramme|merm_",resp,re.I)),resp[:120]))
d = chat("Quelles sont tes competences ?",timeout=30)
resp = d.get("response","")
results.append(check("CAP-08 Skills","capability",bool(re.search(r"frontend|pdf|skill|competence|algorithmic|canvas",resp,re.I)),resp[:120]))
d = chat("Analyse SWOT transformation digitale PME",timeout=60)
resp = d.get("response","")
results.append(check("CAP-09 SWOT","capability",bool(re.search(r"force|faiblesse|opportunit|menace|SWOT|strength|weakness",resp,re.I)),resp[:120]))
cat_order = {"auth":0,"chatbot":1,"capability":2,"manager":3,"oss":4}
results.sort(key=lambda t: (cat_order.get(t["category"],99), t["name"]))
p = sum(1 for t in results if t["status"]=="pass")
f = sum(1 for t in results if t["status"]=="fail")
output = {"timestamp":time.strftime("%Y-%m-%dT%H:%M:%SZ",time.gmtime()),"pass":p,"fail":f,"total":len(results),"tests":results}
with open(RESULTS_FILE,"w") as fh:
json.dump(output, fh, ensure_ascii=False)
print(f"\n{'' if f==0 else ''} {p}/{len(results)} PASSED — {f} FAILED")