Files
gochat/test-captain-llm-provider.sh
T
Rogee 1c6b8c661c fix: 文件上传Metadata jsonb BUG + search config + fake:ai provider + QA报告
修复:
- message_service.go: 附件Metadata零值字符串''→'{}'(PG jsonb列报错)
- config.dev.yaml/config.development.yaml: search.engine改为db
  (避免依赖未运行的MeiliSearch导致搜索500)

新增:
- fake_provider.go: Captain/AI fake LLM Provider
- test-captain-llm-provider.sh: 测试脚本
- QA测试报告: 93项CDP功能点覆盖验证

文档:
- CDP_TESTING_HANDOFF.md: 进度更新(89%->92%->95%)
- 报告: 11.846~11.897 完整测试日志
2026-07-27 22:01:28 +08:00

134 lines
5.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# fake:ai LLM provider test
# Tests all Captain/Copilot API endpoints with canned data
# since there's no real AI provider configured (model is gpt-4o).
#
# CRITERIA: The API must respond without crash (no 500) for every endpoint.
# Endpoints that require an actual LLM provider return 4xx with
# "Copilot provider is not configured" — this is EXPECTED behavior.
BASE="http://127.0.0.1:3000/api/v1/accounts/1"
AUTH="-H X-User-ID:1 -H X-Account-ID:1"
CT="-H Content-Type:application/json"
PASS=0
FAIL=0
EXPECTED=0
green() { echo -e "\033[32m✓ $1\033[0m"; PASS=$((PASS+1)); }
red() { echo -e "\033[31m✗ $1\033[0m"; FAIL=$((FAIL+1)); }
blue() { echo -e "\033[34m∼ $1 (expected — no LLM provider)\033[0m"; EXPECTED=$((EXPECTED+1)); }
check() { local label="$1" code="$2" body="$3"
if [ "$code" = "200" ] || [ "$code" = "201" ] || [ "$code" = "204" ]; then
green "$label (HTTP $code)"
elif echo "$body" | grep -q "Copilot provider is not configured"; then
blue "$label (HTTP $code)"
else
red "$label (HTTP $code) — $(echo "$body" | head -c 200)"
fi
}
echo "========================================"
echo " fake:ai LLM Provider — Captain Tests"
echo "========================================"
echo ""
# --- 1. GET captain/assistants ---
echo "--- 1. GET captain/assistants ---"
resp=$(curl -s -w "\n%{http_code}" $AUTH "$BASE/captain/assistants")
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "List assistants" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 2. POST captain/assistants (create an assistant) ---
echo "--- 2. POST captain/assistants (create assistant) ---"
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/assistants" \
-d '{"assistant":{"name":"faketest-ai","description":"test from fake:ai","config":{"model":"gpt-4o","temperature":0.7,"feature_faq":true,"feature_memory":false,"feature_contact_attributes":false,"product_name":"GoChat"}}}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Create assistant" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -15
echo ""
# --- 3. GET captain/assistants/tools ---
echo "--- 3. GET captain/assistants/tools ---"
resp=$(curl -s -w "\n%{http_code}" $AUTH "$BASE/captain/assistants/tools")
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "List tools" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 4. POST assistant playground (simulate LLM call) ---
echo "--- 4. POST captain/assistants/1/playground (simulate LLM call) ---"
# Uses message_content (flat) as documented in the handler
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/assistants/1/playground" \
-d '{"message_content":"Hello from fake:ai test"}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Playground (simulated)" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 5. POST captain/copilot_threads (create thread) ---
echo "--- 5. POST captain/copilot_threads (create thread) ---"
# Uses flat message + assistant_id as documented in the handler test
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/copilot_threads" \
-d '{"message":"Hello Copilot, please help with a customer query","assistant_id":1}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Create copilot thread" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 6. POST captain/tasks/reply_suggestion (suggest reply) ---
echo "--- 6. POST captain/tasks/reply_suggestion ---"
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/tasks/reply_suggestion" \
-d '{"conversation_id":1,"assistant_id":1}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Reply suggestion" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 7. POST captain/tasks/summarize ---
echo "--- 7. POST captain/tasks/summarize ---"
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/tasks/summarize" \
-d '{"conversation_id":1,"assistant_id":1}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Summarize" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 8. POST captain/tasks/rewrite ---
echo "--- 8. POST captain/tasks/rewrite ---"
resp=$(curl -s -w "\n%{http_code}" -X POST $AUTH $CT \
"$BASE/captain/tasks/rewrite" \
-d '{"content":"This is a test message to be rewritten for clarity","assistant_id":1}')
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Rewrite" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
# --- 9. GET captain/preferences ---
echo "--- 9. GET captain/preferences ---"
resp=$(curl -s -w "\n%{http_code}" $AUTH "$BASE/captain/preferences")
code=$(echo "$resp" | tail -1)
body=$(echo "$resp" | sed '$d')
check "Get preferences" "$code" "$body"
echo "$body" | python3 -m json.tool 2>/dev/null | head -20
echo ""
echo "========================================"
echo " RESULTS: $PASS passed, $FAIL failed, $EXPECTED expected (no LLM provider)"
echo "========================================"
exit $FAIL