Kalletlamadhav/sql_optimized_env_new
0
1"""2Exact simulation of the hackathon Phase 2 validator.3Runs reset → step for ALL tasks, captures reward exactly as validator does.4Flags any score == 0.0 or == 1.0 as a boundary violation.5"""6import requests, json, sys, time7 8BASE = "https://kalletlamadhav-sql-optimized-env-new.hf.space"9T = 12010 11TASKS = [12 "gst_missing_index",13 "gst_n_plus_one",14 "gst_multi_join",15 "pds_select_star",16 "railway_simple_filter",17 "pds_cartesian",18 "mgnrega_wildcard",19 "railway_tatkal_workload",20 "mgnrega_schema_e",21 "mgnrega_count",22 "railway_missing_index",23 "gst_unbounded_aggregation",24 "pds_n_plus_one",25 "mgnrega_implicit_cast",26]27 28ACTIONS = [29 {"optimized_query": "SELECT 1", "identified_pattern": "NONE", "explanation": "test", "index_statements": [], "schema_analysis": ""},30 {"optimized_query": "SELECT id FROM gst_invoice_records WHERE state_code = 'MH'", "identified_pattern": "MISSING_INDEX", "explanation": "use index", "index_statements": ["CREATE INDEX idx_state ON gst_invoice_records(state_code)"], "schema_analysis": ""},31 {"optimized_query": "SELECT card_id, district_code FROM ration_card_beneficiaries WHERE card_type = 'BPL'", "identified_pattern": "SELECT_STAR", "explanation": "remove star", "index_statements": [], "schema_analysis": ""},32]33 34failures = []35results = {}36 37print("=" * 60)38print("EXACT VALIDATOR SIMULATION — Phase 2")39print(f"Target: {BASE}")40print("=" * 60)41 42for tid in TASKS:43 print(f"\n[TASK] {tid}")44 task_results = []45 46 for action_idx, action in enumerate(ACTIONS):47 try:48 # Step 1: Reset49 r = requests.post(f"{BASE}/reset", 50 params={"task_id": tid},51 timeout=T)52 if r.status_code != 200:53 print(f" ACTION {action_idx}: RESET FAILED {r.status_code}: {r.text[:100]}")54 task_results.append(f"RESET_FAIL_{r.status_code}")55 continue56 57 obs = r.json()58 actual_query = obs.get("current_query", "SELECT 1")59 60 # Use the actual query for one of our test actions61 if action_idx == 0:62 test_action = {63 "optimized_query": actual_query, # same query = no improvement baseline64 "identified_pattern": "NONE",65 "explanation": "baseline passthrough",66 "index_statements": [],67 "schema_analysis": ""68 }69 else:70 test_action = action71 72 # Step 2: Step73 s = requests.post(f"{BASE}/step", json=test_action, timeout=T)74 if s.status_code != 200:75 print(f" ACTION {action_idx}: STEP FAILED {s.status_code}: {s.text[:100]}")76 task_results.append(f"STEP_FAIL_{s.status_code}")77 continue78 79 step_data = s.json()80 reward = step_data.get("reward", -999)81 reward_detail = step_data.get("reward_detail", {})82 83 try:84 reward = float(reward)85 except:86 reward = -999.087 88 in_range = (0.0 < reward < 1.0)89 strict_exact = (reward == 0.0 or reward == 1.0)90 91 status = "✅ PASS" if in_range else f"❌ FAIL reward={reward}"92 print(f" ACTION {action_idx}: reward={reward:.4f} → {status}")93 94 if not in_range:95 failures.append({96 "task": tid,97 "action": action_idx,98 "reward": reward,99 "detail": reward_detail,100 "obs_task_id": obs.get("task_id"),101 })102 103 task_results.append(reward)104 105 except Exception as e:106 print(f" ACTION {action_idx}: EXCEPTION {e}")107 task_results.append(f"ERROR_{e}")108 109 time.sleep(0.5)110 111 results[tid] = task_results112 113print("\n" + "=" * 60)114print("SUMMARY")115print("=" * 60)116 117all_pass = len(failures) == 0118 119for tid, tr in results.items():120 nums = [r for r in tr if isinstance(r, float)]121 bads = [r for r in nums if not (0.0 < r < 1.0)]122 symbol = "✅" if not bads else "❌"123 print(f" {symbol} {tid}: {tr}")124 125if failures:126 print(f"\n❌ {len(failures)} BOUNDARY VIOLATIONS FOUND:")127 for f in failures:128 print(f" Task={f['task']} action={f['action']} reward={f['reward']}")129 print(f" detail={json.dumps(f['detail'], indent=6)}")130else:131 print("\n✅ ALL SCORES STRICTLY IN (0.0, 1.0) — READY TO SUBMIT")132 133print(f"\nPHASE 2: {'ALL PASSED' if all_pass else 'FAILED — FIX NEEDED'}")134 