ritvik360/nl2sql-bench
0
1#!/usr/bin/env bash2# nl2sql-bench/scripts/smoke_test.sh3# ─────────────────────────────────────────────────────────────────────────────4# Smoke tests against a running server (local or HF Space).5# Verifies all endpoints return expected HTTP codes and JSON shapes.6#7# Usage:8# ./scripts/smoke_test.sh # default localhost:80009# ./scripts/smoke_test.sh https://your.hf.space # HF Space URL10# ─────────────────────────────────────────────────────────────────────────────11set -euo pipefail12 13BASE_URL="${1:-http://localhost:8000}"14BASE_URL="${BASE_URL%/}"15PASS=0; FAIL=016 17GREEN='\033[0;32m'; RED='\033[0;31m'; NC='\033[0m'; BOLD='\033[1m'18 19pass() { echo -e "${GREEN}✓${NC} $1"; PASS=$((PASS+1)); }20fail() { echo -e "${RED}✗${NC} $1"; FAIL=$((FAIL+1)); }21 22echo ""23echo -e "${BOLD}NL2SQL-Bench Smoke Tests${NC}"24echo "Target: $BASE_URL"25echo "────────────────────────────────────────"26 27# ── /health ──────────────────────────────────────────────────────────────────28CODE=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/health")29[ "$CODE" = "200" ] && pass "/health → 200" || fail "/health → $CODE (expected 200)"30 31# ── /reset ───────────────────────────────────────────────────────────────────32RESET_BODY=$(curl -s -X POST "$BASE_URL/reset" \33 -H "Content-Type: application/json" -d '{}')34echo "$RESET_BODY" | grep -q "question" && pass "/reset → has 'question' field" \35 || fail "/reset → missing 'question' field. Body: $RESET_BODY"36 37# ── /step (valid SQL) ─────────────────────────────────────────────────────────38STEP_BODY=$(curl -s -X POST "$BASE_URL/step" \39 -H "Content-Type: application/json" \40 -d '{"query": "SELECT id, name FROM customers LIMIT 3"}')41echo "$STEP_BODY" | grep -q "reward" && pass "/step valid SQL → has 'reward'" \42 || fail "/step valid SQL → missing 'reward'. Body: $STEP_BODY"43echo "$STEP_BODY" | grep -q '"done"' && pass "/step valid SQL → has 'done'" \44 || fail "/step valid SQL → missing 'done'. Body: $STEP_BODY"45 46# ── /step (syntax error SQL) ──────────────────────────────────────────────────47STEP_ERR=$(curl -s -X POST "$BASE_URL/step" \48 -H "Content-Type: application/json" \49 -d '{"query": "SELCT * FORM broken_tbl"}')50echo "$STEP_ERR" | grep -q "last_error" && pass "/step bad SQL → has 'last_error'" \51 || fail "/step bad SQL → missing 'last_error'. Body: $STEP_ERR"52 53# ── /state ────────────────────────────────────────────────────────────────────54STATE_BODY=$(curl -s "$BASE_URL/state")55echo "$STATE_BODY" | grep -q "step_count" && pass "/state → has 'step_count'" \56 || fail "/state → missing 'step_count'. Body: $STATE_BODY"57 58echo "────────────────────────────────────────"59echo -e "${BOLD}Results: ${GREEN}${PASS} passed${NC}, ${RED}${FAIL} failed${NC}"60echo ""61 62[ "$FAIL" -eq 0 ] && exit 0 || exit 163 