""" WEVIA Master full Playwright test · Yacine non-tech user simulation - Open /wevia-master.html - Send 'wevia truth' → verify 906 agents response - Send 'agis en multiagent' → verify SSE exec not simulate - Send 'combien d'agents' → verify NL query works - Video + screenshots + timing proofs """ import time, json from pathlib import Path from playwright.sync_api import sync_playwright TS = time.strftime("%Y%m%d-%H%M%S") OUT = Path(f"/var/www/html/test-report/wevia-full-test-{TS}") OUT.mkdir(parents=True, exist_ok=True) results = {"ts": TS, "steps": [], "api_tests": []} # First: direct API tests (proof SSE works) import urllib.request, urllib.error def api_post(path, data, timeout=40): req = urllib.request.Request( f"https://weval-consulting.com{path}", data=json.dumps(data).encode(), headers={'Content-Type': 'application/json'}, method='POST' ) try: r = urllib.request.urlopen(req, timeout=timeout) return r.read().decode(errors='replace') except Exception as e: return f"ERR: {e}" # Test 1: wevia truth via API print("[API] Testing 'wevia truth'...") r1 = api_post("/api/wevia-master-api.php?fast=1", {"message":"wevia truth"}, timeout=15) try: d1 = json.loads(r1) results["api_tests"].append({"q":"wevia truth", "intent":d1.get("intent"), "size":len(r1)}) print(f" ✓ intent={d1.get('intent')} size={len(r1)}") except: results["api_tests"].append({"q":"wevia truth", "raw":r1[:200]}) # Test 2: NL count r2 = api_post("/api/wevia-master-api.php?fast=1", {"message":"combien d'agents"}, timeout=15) try: d2 = json.loads(r2) results["api_tests"].append({"q":"combien d'agents", "intent":d2.get("intent"), "size":len(r2)}) print(f" ✓ intent={d2.get('intent')} size={len(r2)}") except: pass # Test 3: SSE multiagent (streaming) print("[API] Testing SSE multiagent (30s)...") import http.client, ssl conn = http.client.HTTPSConnection("weval-consulting.com", timeout=35, context=ssl._create_unverified_context()) conn.request("POST", "/api/wevia-master-api.php", json.dumps({"message":"agis en multiagent 10 agents parallèles"}).encode(), {"Content-Type": "application/json"}) resp = conn.getresponse() sse_data = resp.read().decode(errors='replace') conn.close() events = [] for line in sse_data.split('\n'): if line.startswith('data: '): try: events.append(json.loads(line[6:])) except: pass sse_summary = { "total_events": len(events), "types": list(set(e.get("type","?") for e in events)), "agents_count": len([e for e in events if e.get("type")=="agent"]), "exec_results": len([e for e in events if e.get("type")=="exec_result"]), "has_done": any(e.get("type")=="done" for e in events), "has_llm_synthesis": any(e.get("type")=="llm_synthesis" for e in events), } results["sse_multiagent"] = sse_summary print(f" ✓ SSE: {sse_summary['agents_count']} agents parallel, exec_results={sse_summary['exec_results']}") # Now Playwright video recording print("[PW] Opening chat UI with video...") try: with sync_playwright() as p: browser = p.chromium.launch(headless=True, args=["--no-sandbox"]) ctx = browser.new_context( viewport={"width":1400,"height":1000}, ignore_https_errors=True, record_video_dir=str(OUT), record_video_size={"width":1400,"height":1000} ) page = ctx.new_page() page.goto("https://weval-consulting.com/wevia-master.html", wait_until="networkidle", timeout=25000) time.sleep(3) page.screenshot(path=str(OUT/"01-chat-opened.png"), full_page=True) results["steps"].append({"step":"chat_opened", "ok":True}) # Find input input_sel = None for sel in ['#chat-input', '#message', 'textarea[placeholder*="essage"]', 'textarea[placeholder*="uestion"]', 'textarea', 'input[type="text"][placeholder]']: try: el = page.locator(sel).first if el.count() > 0 and el.is_visible(): input_sel = sel print(f" Input found: {sel}") break except: continue if input_sel: # Test 1 in UI: wevia truth page.fill(input_sel, "wevia truth") page.keyboard.press("Enter") time.sleep(8) page.screenshot(path=str(OUT/"02-truth-sent.png"), full_page=True) results["steps"].append({"step":"truth_sent", "ok":True}) # Test 2 in UI: combien d'agents time.sleep(2) page.fill(input_sel, "combien d'agents") page.keyboard.press("Enter") time.sleep(6) page.screenshot(path=str(OUT/"03-combien-agents.png"), full_page=True) results["steps"].append({"step":"combien_agents", "ok":True}) # Test 3 in UI: multiagent time.sleep(2) page.fill(input_sel, "agis en multiagent 5 agents") page.keyboard.press("Enter") time.sleep(20) # SSE takes time page.screenshot(path=str(OUT/"04-multiagent.png"), full_page=True) results["steps"].append({"step":"multiagent", "ok":True}) else: results["steps"].append({"step":"input_find", "ok":False, "err":"no input visible"}) ctx.close() browser.close() videos = list(OUT.glob("*.webm")) results["video"] = videos[0].name if videos else None pngs = list(OUT.glob("*.png")) results["screenshots"] = [p.name for p in pngs] results["total_png_size"] = sum(p.stat().st_size for p in pngs) print(f" ✓ video={results['video']} screenshots={len(pngs)} total_size={results['total_png_size']}") except Exception as e: results["pw_error"] = str(e) print(f"[PW err] {e}") with open(OUT/"results.json","w") as f: json.dump(results, f, indent=2) print("\n=== SUMMARY ===") print(json.dumps(results, indent=2, default=str)[:1500])