"""Antigravity Battle Test — Stress Testing the AI Queue and Email Dispatcher.""" import asyncio import httpx import time import uuid import sys from loguru import logger # --- Configuration --- API_BASE_URL = "http://localhost:8000" CONCURRENT_USERS = 10 # Test with 10 users hitting the AI simultaneously TEST_EMAIL = "test@briga.id" async def simulate_user_request(user_id: int): """Simulates a talent requesting a CV analysis.""" payload = { "agent_name": "RecruiterStrategicAdvisor", "task_name": "cv_analysis", "payload": { "cv_text": f"User {user_id} experience: 5 years in Solar Panel Installation.", "context": "Seeking for Mid-Level Green Engineer position." }, "priority": 0, "user_email": TEST_EMAIL } trace_id = str(uuid.uuid4()) logger.info(f"[User {user_id}] Sending request (Trace: {trace_id[:8]})") try: async with httpx.AsyncClient(timeout=30.0) as client: start_time = time.time() response = await client.post(f"{API_BASE_URL}/agents/execute", json=payload) latency = (time.time() - start_time) * 1000 if response.status_code == 200: data = response.json() logger.success(f"[User {user_id}] Success ({latency:.2f}ms) | Status: {data.get('status')} | Trace: {data.get('trace_id')[:8]}") else: logger.error(f"[User {user_id}] Failed ({response.status_code}): {response.text}") except Exception as e: logger.critical(f"[User {user_id}] Connection Error: {e}") async def run_battle_test(): """Launches multiple concurrent requests to test Antigravity's RPM throttle.""" logger.info(f"=== Antigravity Battle Test Started: {CONCURRENT_USERS} Users ===") tasks = [simulate_user_request(i) for i in range(1, CONCURRENT_USERS + 1)] start_all = time.time() await asyncio.gather(*tasks) end_all = time.time() logger.info(f"=== Battle Test Complete. Total Duration: {end_all - start_all:.2f}s ===") logger.info("Check the Health Dashboard or Supabase 'agent_state_logs' for detailed results.") if __name__ == "__main__": # Check if backend is alive first try: httpx.get(f"{API_BASE_URL}/health") except Exception: logger.error(f"Backend is not running at {API_BASE_URL}. Please start the server first!") sys.exit(1) asyncio.run(run_battle_test())