File size: 3,921 Bytes
a39d8ef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/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