wip: 2026-08-11 工作树快照(docs/memory/h5.py/scripts 等 447 项未评审改动,安全提交到 feat 分支)

This commit is contained in:
Simon
2026-08-11 09:59:44 +08:00
parent 6be361fb63
commit f2fd4fa012
447 changed files with 273482 additions and 1386 deletions
+233
View File
@@ -0,0 +1,233 @@
#!/bin/bash
# =============================================================================
# 企微IT智能服务台 — 快速规则 API 联调测试脚本
# =============================================================================
# 用途:独立测试所有 12 个快速规则 API
# 日期:2026-07-27
# =============================================================================
# 默认配置
BASE_URL="${API_BASE_URL:-http://localhost:8000}"
TOKEN="${API_TOKEN:-}"
# 颜色
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
# 计数器
PASS=0
FAIL=0
# --------------------------------------------------------------------------
# 工具函数
# --------------------------------------------------------------------------
check_response() {
local response="$1"
local expected_code="$2"
local test_name="$3"
if echo "$response" | grep -q "\"code\":$expected_code"; then
echo -e "${GREEN}✓ PASS${NC}: $test_name"
((PASS++))
else
echo -e "${RED}✗ FAIL${NC}: $test_name"
echo "Response: $response"
((FAIL++))
fi
}
# --------------------------------------------------------------------------
# 0. 健康检查
# --------------------------------------------------------------------------
echo -e "${YELLOW}=== 0. 健康检查 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/health")
echo "Health: $RESPONSE"
# --------------------------------------------------------------------------
# 1. 测试登录(获取 token
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 1. 登录 ===${NC}"
echo "请先用浏览器登录获取 token,或使用下面的方式:"
# 直接测试(需要 token
if [ -z "$TOKEN" ]; then
echo -e "${RED}错误:请先设置 API_TOKEN 环境变量${NC}"
echo "使用方式:API_TOKEN=your_token bash $0"
exit 1
fi
# --------------------------------------------------------------------------
# 2. 规则列表
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 2. 规则列表 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/api/admin/quick-rules?page=1&size=10" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "GET /quick-rules"
# --------------------------------------------------------------------------
# 3. 创建规则
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 3. 创建规则 ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rule_type": "greeting",
"keyword": "test_你好",
"priority": 10,
"is_active": true
}')
check_response "$RESPONSE" "0" "POST /quick-rules"
RULE_ID=$(echo "$RESPONSE" | grep -oP '"id":\K\d+' | head -1)
echo "Created rule ID: $RULE_ID"
# --------------------------------------------------------------------------
# 4. 更新规则
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 4. 更新规则 ===${NC}"
RESPONSE=$(curl -s -X PUT "$BASE_URL/api/admin/quick-rules/$RULE_ID" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"priority": 20,
"is_active": false
}')
check_response "$RESPONSE" "0" "PUT /quick-rules/$RULE_ID"
# --------------------------------------------------------------------------
# 5. 批量导入
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 5. 批量导入 ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/import" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rules": [
{"rule_type": "greeting", "keyword": "test_hey", "priority": 5},
{"rule_type": "greeting", "keyword": "test_hello", "priority": 5}
],
"mode": "skip_duplicates"
}')
check_response "$RESPONSE" "0" "POST /quick-rules/import"
# --------------------------------------------------------------------------
# 6. 批量导出
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 6. 批量导出 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/api/admin/quick-rules/export?format=json" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "GET /quick-rules/export"
# --------------------------------------------------------------------------
# 7. 智能体更新(高置信度)
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 7. 智能体更新(高置信度) ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/agent-update" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rule_type": "routing_prefilter",
"category": "IT服务",
"keyword": "test_投影仪",
"priority": 5,
"confidence": 0.92,
"reason": "测试用例",
"agent_id": "test_agent"
}')
check_response "$RESPONSE" "0" "POST /quick-rules/agent-update (confidence=0.92)"
# --------------------------------------------------------------------------
# 8. 智能体更新(中等置信度)
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 8. 智能体更新(中等置信度) ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/agent-update" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rule_type": "routing_prefilter",
"category": "IT服务",
"keyword": "test_音响",
"priority": 5,
"confidence": 0.7,
"reason": "测试用例",
"agent_id": "test_agent"
}')
check_response "$RESPONSE" "0" "POST /quick-rules/agent-update (confidence=0.7)"
# --------------------------------------------------------------------------
# 9. 智能体更新(低置信度)
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 9. 智能体更新(低置信度) ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/agent-update" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"rule_type": "routing_prefilter",
"category": "IT服务",
"keyword": "test_键盘",
"priority": 5,
"confidence": 0.3,
"reason": "测试用例",
"agent_id": "test_agent"
}')
check_response "$RESPONSE" "0" "POST /quick-rules/agent-update (confidence=0.3)"
# --------------------------------------------------------------------------
# 10. 审计日志
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 10. 审计日志 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/api/admin/quick-rules/audit-log?page=1&size=10" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "GET /quick-rules/audit-log"
# --------------------------------------------------------------------------
# 11. 统计详情
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 11. 统计详情 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/api/admin/quick-rules/stats/detail" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "GET /quick-rules/stats/detail"
# --------------------------------------------------------------------------
# 12. 刷新缓存
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 12. 刷新缓存 ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/refresh" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "POST /quick-rules/refresh"
# --------------------------------------------------------------------------
# 13. 批量删除
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 13. 批量删除 ===${NC}"
RESPONSE=$(curl -s -X POST "$BASE_URL/api/admin/quick-rules/batch-delete" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "{\"ids\": [$RULE_ID]}")
check_response "$RESPONSE" "0" "POST /quick-rules/batch-delete"
# --------------------------------------------------------------------------
# 14. 简单统计
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 14. 简单统计 ===${NC}"
RESPONSE=$(curl -s -X GET "$BASE_URL/api/admin/quick-rules/stats" \
-H "Authorization: Bearer $TOKEN")
check_response "$RESPONSE" "0" "GET /quick-rules/stats"
# --------------------------------------------------------------------------
# 汇总
# --------------------------------------------------------------------------
echo -e "\n${YELLOW}=== 测试汇总 ===${NC}"
echo -e "${GREEN}通过: $PASS${NC}"
echo -e "${RED}失败: $FAIL${NC}"
if [ $FAIL -eq 0 ]; then
echo -e "${GREEN}✓ 所有测试通过!${NC}"
exit 0
else
echo -e "${RED}✗ 有 $FAIL 个测试失败${NC}"
exit 1
fi