001project_wildgrowth/backend/scripts/test-optimization.sh

149 lines
4.5 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
# AI 内容生成优化测试脚本
# 测试队列系统、预生成、批量生成等功能
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo -e "${GREEN}🧪 开始测试 AI 内容生成优化功能...${NC}\n"
# 1. 检查 Redis 连接
echo -e "${YELLOW}1. 检查 Redis 连接...${NC}"
if command -v redis-cli &> /dev/null; then
if redis-cli ping &> /dev/null; then
echo -e "${GREEN}✅ Redis 连接正常${NC}"
else
echo -e "${RED}❌ Redis 未运行,请启动 Redis${NC}"
exit 1
fi
else
echo -e "${YELLOW}⚠️ redis-cli 未安装,跳过 Redis 检查${NC}"
fi
# 2. 检查依赖
echo -e "\n${YELLOW}2. 检查依赖...${NC}"
if [ -d "node_modules/bullmq" ]; then
echo -e "${GREEN}✅ bullmq 已安装${NC}"
else
echo -e "${RED}❌ bullmq 未安装,运行: npm install bullmq${NC}"
exit 1
fi
# 3. 检查 Prisma Client
echo -e "\n${YELLOW}3. 检查 Prisma Client...${NC}"
if [ -d "node_modules/@prisma/client" ]; then
echo -e "${GREEN}✅ Prisma Client 已生成${NC}"
else
echo -e "${YELLOW}⚠️ Prisma Client 未生成,运行: npm run prisma:generate${NC}"
npm run prisma:generate
fi
# 4. 编译 TypeScript
echo -e "\n${YELLOW}4. 编译 TypeScript...${NC}"
if npm run build 2>&1 | grep -q "error TS"; then
echo -e "${RED}❌ TypeScript 编译失败${NC}"
npm run build 2>&1 | grep "error TS" | head -10
exit 1
else
echo -e "${GREEN}✅ TypeScript 编译成功${NC}"
fi
# 5. 检查新增文件
echo -e "\n${YELLOW}5. 检查新增文件...${NC}"
files=(
"src/services/queueService.ts"
"src/services/templateService.ts"
"src/workers/aiContentWorker.ts"
)
all_exist=true
for file in "${files[@]}"; do
if [ -f "$file" ]; then
echo -e "${GREEN}$file${NC}"
else
echo -e "${RED}$file 不存在${NC}"
all_exist=false
fi
done
if [ "$all_exist" = false ]; then
exit 1
fi
# 6. 检查数据库 Schema
echo -e "\n${YELLOW}6. 检查数据库 Schema...${NC}"
if grep -q "wordCount" prisma/schema.prisma && \
grep -q "outlineEssence" prisma/schema.prisma && \
grep -q "outlineFull" prisma/schema.prisma; then
echo -e "${GREEN}✅ Schema 已更新(包含新字段)${NC}"
else
echo -e "${RED}❌ Schema 未更新,缺少新字段${NC}"
exit 1
fi
# 7. 检查代码关键功能
echo -e "\n${YELLOW}7. 检查代码关键功能...${NC}"
# 检查队列服务
if grep -q "addOutlineTask" src/services/queueService.ts; then
echo -e "${GREEN}✅ 队列服务:大纲任务添加功能${NC}"
else
echo -e "${RED}❌ 队列服务缺少 addOutlineTask${NC}"
exit 1
fi
# 检查降级策略
if grep -q "templateService" src/services/aiService.ts; then
echo -e "${GREEN}✅ AI 服务:多级降级策略${NC}"
else
echo -e "${RED}❌ AI 服务缺少降级策略${NC}"
exit 1
fi
# 检查预生成逻辑
if grep -q "outlineEssence\|outlineFull" src/controllers/aiContentController.ts; then
echo -e "${GREEN}✅ 控制器:预生成逻辑${NC}"
else
echo -e "${RED}❌ 控制器缺少预生成逻辑${NC}"
exit 1
fi
# 检查批量生成
if grep -q "Promise.allSettled" src/controllers/aiContentController.ts | grep -q "nodeResults"; then
echo -e "${GREEN}✅ 控制器:批量节点生成${NC}"
else
echo -e "${YELLOW}⚠️ 批量生成逻辑需要验证${NC}"
fi
# 8. 检查前端逻辑层
echo -e "\n${YELLOW}8. 检查前端逻辑层...${NC}"
if [ -f "../ios/WildGrowth/WildGrowth/CourseServiceExtension.swift" ]; then
if grep -q "selectGenerationMode" ../ios/WildGrowth/WildGrowth/CourseServiceExtension.swift && \
grep -q "getTaskStatus" ../ios/WildGrowth/WildGrowth/CourseServiceExtension.swift; then
echo -e "${GREEN}✅ 前端逻辑层:新增接口方法${NC}"
else
echo -e "${RED}❌ 前端逻辑层缺少新方法${NC}"
exit 1
fi
if grep -q "GenerationMode" ../ios/WildGrowth/WildGrowth/CourseModels.swift; then
echo -e "${GREEN}✅ 前端模型GenerationMode 枚举${NC}"
else
echo -e "${RED}❌ 前端模型缺少 GenerationMode${NC}"
exit 1
fi
else
echo -e "${YELLOW}⚠️ 前端文件路径可能不同,跳过检查${NC}"
fi
echo -e "\n${GREEN}✅ 所有检查通过!${NC}"
echo -e "\n${YELLOW}📝 下一步:${NC}"
echo -e "1. 运行数据库迁移: ${GREEN}npm run prisma:migrate${NC}"
echo -e "2. 启动服务器测试: ${GREEN}npm run dev${NC}"
echo -e "3. 实施 UI 层改造(见 FRONTEND_UI_REQUIREMENTS.md"