Files
stonks-oracle/scripts/test_saved_queries.py
T
Celes Renata 1842b2039c ops: add SQL query test script and macro reclassify/reaggregate runner
- scripts/test_saved_queries.py: tests all 24 saved SQL explorer queries
  against the live Trino API (all 24 pass)
- scripts/run_reclassify_and_reaggregate.sh: self-contained script to
  re-classify macro events with updated prompts and re-aggregate all
  tickers. Scales aggregation to 16 pods, monitors queues, scales back.
2026-04-17 08:03:14 +00:00

51 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""Test all saved SQL explorer queries against the live API."""
import json
import subprocess
API = "https://stonks-api.celestium.life"
result = subprocess.run(
["curl", "-sk", f"{API}/api/analytics/saved-queries"],
capture_output=True, text=True, timeout=15,
)
queries = json.loads(result.stdout)
print(f"Found {len(queries)} saved queries\n")
passed, failed, errors = 0, 0, []
for i, q in enumerate(queries, 1):
name = q["name"]
sql = q["sql_text"]
payload = json.dumps({"sql": sql, "limit": 5})
r = subprocess.run(
["curl", "-sk", "-X", "POST", f"{API}/api/analytics/query",
"-H", "Content-Type: application/json", "-d", payload],
capture_output=True, text=True, timeout=30,
)
try:
resp = json.loads(r.stdout)
if "error" in resp or "detail" in resp:
err = str(resp.get("detail", resp.get("error", "?")))[:120]
print(f" [{i:2d}/24] FAIL {name}")
print(f" {err}")
failed += 1
errors.append((name, err))
else:
rows = len(resp.get("rows", []))
cols = len(resp.get("columns", []))
ms = resp.get("elapsed_ms", "?")
print(f" [{i:2d}/24] OK {name} ({rows} rows, {cols} cols, {ms}ms)")
passed += 1
except json.JSONDecodeError:
print(f" [{i:2d}/24] FAIL {name} (not JSON)")
failed += 1
errors.append((name, r.stdout[:100]))
print(f"\n{'='*60}")
print(f"Results: {passed} passed, {failed} failed out of {len(queries)}")
if errors:
print("\nFailed:")
for n, e in errors:
print(f" - {n}: {e}")