49 lines
2.5 KiB
Bash
Executable File
49 lines
2.5 KiB
Bash
Executable File
#!/bin/bash
|
|
# RAG Server smoke test — run after any change
|
|
# Usage: bash test_rag.sh [host]
|
|
HOST="${1:-http://localhost:9181}"
|
|
ADMIN="${2:-admin}"
|
|
PASS="${3:-admin123}"
|
|
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; NC='\033[0m'
|
|
errors=0
|
|
|
|
check() { local desc="$1" code="$2" expect="$3"
|
|
if [ "$code" = "$expect" ]; then echo -e " ${GREEN}OK${NC} $desc"; else echo -e " ${RED}FAIL${NC} $desc (got $code, want $expect)"; errors=$((errors+1)); fi
|
|
}
|
|
|
|
echo "=== RAG Server Smoke Test ==="
|
|
|
|
# 1. Public endpoints (no login)
|
|
echo "-- Public --"
|
|
check "health" "$(curl -s -o /dev/null -w '%{http_code}' "$HOST/api/status")" 200
|
|
check "no login kb" "$(curl -s -o /dev/null -w '%{http_code}' "$HOST/rag/knowledge_bases_list/index.ui")" 401
|
|
|
|
# 2. Login
|
|
S=$(curl -s -D - -X POST "$HOST/rbac/user/up_login.dspy" -d "username=$ADMIN&password=$PASS" | grep -oP 'AIOHTTP_SESSION=\K[^;]+' | head -1)
|
|
if [ -z "$S" ]; then echo -e " ${RED}FAIL${NC} login"; exit 1; fi
|
|
echo -e " ${GREEN}OK${NC} login"
|
|
|
|
# 3. Logged-in endpoints
|
|
echo "-- Logined --"
|
|
|
|
check "index.ui" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/index.ui")" 200
|
|
check "detail.ui" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/detail.ui?kb_id=41c9f1cd45e0")" 200
|
|
check "get_tree_data" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/get_tree_data.dspy?kb_id=41c9f1cd45e0")" 200
|
|
check "file_list" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/file_list.dspy?kb_id=41c9f1cd45e0&id=__root__")" 200
|
|
check "storage_card" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/storage_card.dspy?_webbricks_=1")" 200
|
|
check "new_kb_form" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/new_kb_form.ui")" 200
|
|
check "kb_list" "$(curl -s -o /dev/null -w '%{http_code}' -b "AIOHTTP_SESSION=$S" "$HOST/api/kb/list")" 200
|
|
|
|
# 4. Verify storage shows real data
|
|
used=$(curl -s -b "AIOHTTP_SESSION=$S" "$HOST/rag/knowledge_bases_list/storage_card.dspy?_webbricks_=1" | grep -oP '已用 \K[\d.]+')
|
|
if [ "$used" != "0.0" ] && [ -n "$used" ]; then
|
|
echo -e " ${GREEN}OK${NC} storage shows ${used}MB"
|
|
else
|
|
echo -e " ${RED}FAIL${NC} storage shows $used (want >0)"
|
|
errors=$((errors+1))
|
|
fi
|
|
|
|
echo "=== $errors errors ==="
|
|
exit $errors
|