Kalletlamadhav/sql_optimized_env_new
0
1import requests, time2 3BASE = "https://kalletlamadhav-sql-optimized-env-new.hf.space"4T = 905fails = []6 7def check(label, status, condition, detail=""):8 result = "PASS" if condition else "FAIL"9 print(f"{result} | {label} | {detail}")10 if not condition: fails.append(label)11 12print("Waiting a bit for Space to rebuild...")13time.sleep(120)14 15# Health16try:17 r = requests.get(f"{BASE}/health", timeout=T)18 check("GET /health", r.status_code, r.status_code==200, r.text[:100])19except Exception as e:20 check("GET /health", 0, False, str(e))21 22# Tasks23try:24 r = requests.get(f"{BASE}/tasks", timeout=T)25 tasks = r.json()26 check("GET /tasks", r.status_code, len(tasks)>=3, f"{len(tasks)} tasks found")27 task_ids = [t['task_id'] for t in tasks[:3]]28except Exception as e:29 check("GET /tasks", 0, False, str(e))30 task_ids = ['gst_missing_index','pds_select_star','railway_missing_index'] # fallback31 32# POST /reset for each task33for tid in task_ids:34 try:35 r = requests.post(f"{BASE}/reset?task_id={tid}", timeout=T)36 check(f"POST /reset {tid}", r.status_code, r.status_code==200, r.text[:150])37 if r.status_code == 200:38 obs = r.json()39 query = obs.get('current_query', 'SELECT 1')40 action = {"optimized_query": query, "identified_pattern": "NONE",41 "explanation": "live test", "index_statements": [], "schema_analysis": "test"}42 r2 = requests.post(f"{BASE}/step", json=action, timeout=T)43 if r2.status_code == 200:44 reward = r2.json().get('reward', -1)45 check(f"POST /step {tid} reward in (0,1)", r2.status_code,46 0.0 < reward < 1.0, f"reward={reward}")47 else:48 check(f"POST /step {tid}", r2.status_code, False, r2.text[:150])49 except Exception as e:50 check(f"POST /reset {tid}", 0, False, str(e))51 52# State53try:54 r = requests.get(f"{BASE}/state", timeout=T)55 check("GET /state", r.status_code, r.status_code==200, r.text[:100])56except Exception as e:57 check("GET /state", 0, False, str(e))58 59print(f"\n{'=== ALL LIVE TESTS PASSED ===' if not fails else 'FAILED: '+str(fails)}")60 