#!/usr/bin/env python3 """Script de test complet pour JARVIS v3 Pipecat.""" import subprocess, os, json, time, sys, asyncio # 1. Récupérer la clé API Hermes depuis Infisical print("🔑 Récupération clé API Hermes...") try: creds = json.load(open("/opt/infisical/admin-credentials.json")) r = subprocess.run( ["/home/openclaw/.local/bin/infisical", "secrets", "get", "API_SERVER_KEY", "--domain", "https://secret.dracodev.net", "--projectId", "192c1eed-6666-41ee-80df-a4636a2da0ad", "--env", "prod", "--path", "/hermes-claw", "--plain", "--token", creds["token"]], capture_output=True, text=True, timeout=20, env={"PATH": "/usr/local/bin:/usr/bin:/bin"} ) hermes_key = r.stdout.strip() if not hermes_key: print(f"❌ Erreur Infisical: {r.stderr}") sys.exit(1) print(f"✅ Clé: {hermes_key[:15]}...") except Exception as e: print(f"❌ Erreur: {e}") sys.exit(1) # 2. Lancer le bot print("\n🚀 Lancement du bot Pipecat...") os.environ["HERMES_API_KEY"] = hermes_key proc = subprocess.Popen( ["./venv/bin/python", "bot.py"], cwd="/home/openclaw/workspace/jarvis-pipecat", env={**os.environ, "HERMES_API_KEY": hermes_key}, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, bufsize=1 ) # 3. Attendre que le serveur démarre print("⏳ Attente démarrage serveur...") import select start = time.time() while time.time() - start < 15: ready, _, _ = select.select([proc.stdout], [], [], 0.5) if ready: line = proc.stdout.readline() if line: print(f" {line.rstrip()}") if "Uvicorn running" in line or "Application startup complete" in line: break # Vérifier si le port écoute try: import socket s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.settimeout(1) s.connect(("localhost", 7081)) s.close() print("✅ Port 7081 ouvert!") break except: pass time.sleep(0.5) if proc.poll() is not None: print("❌ Le bot a crashé au démarrage!") sys.exit(1) print("✅ Bot démarré!") # 4. Test HTTP print("\n🌐 Test HTTP GET /") import urllib.request resp = urllib.request.urlopen("http://localhost:7081/", timeout=5) content = resp.read().decode() if "JARVIS" in content: print("✅ Page HTML OK") else: print(f"⚠️ Page: {content[:100]}") # 5. Test WebSocket print("\n🔌 Test WebSocket...") try: import websockets except ImportError: subprocess.run(["./venv/bin/pip", "install", "websockets"], check=True) import websockets async def ws_test(): async with websockets.connect("ws://localhost:7081/ws") as ws: # Recevoir message de bienvenue msg = await asyncio.wait_for(ws.recv(), timeout=5) print(f"👋 Welcome: {msg[:150]}") # Envoyer une question await ws.send("Quelle heure est-il actuellement?") print("📤 Question envoyée") # Attendre la réponse try: msg = await asyncio.wait_for(ws.recv(), timeout=15) print(f"🤖 Réponse: {msg[:300]}") print("\n✅✅✅ TEST RÉUSSI! JARVIS v3 répond via Pipecat! ✅✅✅") except asyncio.TimeoutError: print("⚠️ Timeout: pas de réponse du LLM en 15s") print(" (le LLM peut prendre plus de temps)") asyncio.run(ws_test()) print("\n📊 Serveur toujours en cours d'exécution...") print(f" 🌐 http://openclaw1.dev.home:7081/") print(f" 🔌 ws://openclaw1.dev.home:7081/ws") print(f" PID: {proc.pid}")