#!/usr/bin/env bash # nl2sql-bench/scripts/smoke_test.sh # ───────────────────────────────────────────────────────────────────────────── # Smoke tests against a running server (local or HF Space). # Verifies all endpoints return expected HTTP codes and JSON shapes. # # Usage: # ./scripts/smoke_test.sh # default localhost:8000 # ./scripts/smoke_test.sh https://your.hf.space # HF Space URL # ───────────────────────────────────────────────────────────────────────────── set -euo pipefail BASE_URL="${1:-http://localhost:8000}" BASE_URL="${BASE_URL%/}" PASS=0; FAIL=0 GREEN='\033[0;32m'; RED='\033[0;31m'; NC='\033[0m'; BOLD='\033[1m' pass() { echo -e "${GREEN}✓${NC} $1"; PASS=$((PASS+1)); } fail() { echo -e "${RED}✗${NC} $1"; FAIL=$((FAIL+1)); } echo "" echo -e "${BOLD}NL2SQL-Bench Smoke Tests${NC}" echo "Target: $BASE_URL" echo "────────────────────────────────────────" # ── /health ────────────────────────────────────────────────────────────────── CODE=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL/health") [ "$CODE" = "200" ] && pass "/health → 200" || fail "/health → $CODE (expected 200)" # ── /reset ─────────────────────────────────────────────────────────────────── RESET_BODY=$(curl -s -X POST "$BASE_URL/reset" \ -H "Content-Type: application/json" -d '{}') echo "$RESET_BODY" | grep -q "question" && pass "/reset → has 'question' field" \ || fail "/reset → missing 'question' field. Body: $RESET_BODY" # ── /step (valid SQL) ───────────────────────────────────────────────────────── STEP_BODY=$(curl -s -X POST "$BASE_URL/step" \ -H "Content-Type: application/json" \ -d '{"query": "SELECT id, name FROM customers LIMIT 3"}') echo "$STEP_BODY" | grep -q "reward" && pass "/step valid SQL → has 'reward'" \ || fail "/step valid SQL → missing 'reward'. Body: $STEP_BODY" echo "$STEP_BODY" | grep -q '"done"' && pass "/step valid SQL → has 'done'" \ || fail "/step valid SQL → missing 'done'. Body: $STEP_BODY" # ── /step (syntax error SQL) ────────────────────────────────────────────────── STEP_ERR=$(curl -s -X POST "$BASE_URL/step" \ -H "Content-Type: application/json" \ -d '{"query": "SELCT * FORM broken_tbl"}') echo "$STEP_ERR" | grep -q "last_error" && pass "/step bad SQL → has 'last_error'" \ || fail "/step bad SQL → missing 'last_error'. Body: $STEP_ERR" # ── /state ──────────────────────────────────────────────────────────────────── STATE_BODY=$(curl -s "$BASE_URL/state") echo "$STATE_BODY" | grep -q "step_count" && pass "/state → has 'step_count'" \ || fail "/state → missing 'step_count'. Body: $STATE_BODY" echo "────────────────────────────────────────" echo -e "${BOLD}Results: ${GREEN}${PASS} passed${NC}, ${RED}${FAIL} failed${NC}" echo "" [ "$FAIL" -eq 0 ] && exit 0 || exit 1