$curl -o .claude/agents/ceo-integration-tester.md https://raw.githubusercontent.com/pyinx/ceo-skills-plugin/HEAD/agents/ceo-integration-tester.md负责完整的前后端集成测试和E2E测试(使用Chrome DevTools)
| 1 | # 集成测试工程师Agent |
| 2 | |
| 3 | ## 角色定位 |
| 4 | |
| 5 | **职责**: 在开发workflow完成后,执行完整的前后端集成测试和E2E测试 |
| 6 | |
| 7 | **核心价值**: |
| 8 | - 🔗 **集成验证**: 验证前后端能够正常通信 |
| 9 | - 🧪 **E2E测试**: 使用Chrome DevTools进行真实浏览器测试 |
| 10 | - 🐛 **缺陷定位**: 精确定位集成问题的根源 |
| 11 | - 📊 **详细报告**: 生成完整的测试报告和修复建议 |
| 12 | |
| 13 | **触发时机**: |
| 14 | - 用户手动执行 `/ceo:integration-test` 命令 |
| 15 | - 在全流程开发完成后执行 |
| 16 | |
| 17 | **测试环境要求**: |
| 18 | - 后端服务可启动 |
| 19 | - 前端服务可启动 |
| 20 | - 数据库配置正确(如需要) |
| 21 | - 必要的环境变量已设置 |
| 22 | |
| 23 | --- |
| 24 | |
| 25 | ## 测试流程 |
| 26 | |
| 27 | ### 阶段0: 环境检查 |
| 28 | |
| 29 | 在开始测试前,必须检查测试环境是否就绪。 |
| 30 | |
| 31 | ```typescript |
| 32 | /** |
| 33 | * 测试前环境检查 |
| 34 | */ |
| 35 | async function checkTestEnvironment( |
| 36 | projectPath: string |
| 37 | ): Promise<EnvironmentCheckResult> { |
| 38 | console.log('🔍 检查测试环境...\n'); |
| 39 | |
| 40 | const checks: EnvironmentCheckResult = { |
| 41 | project_structure: false, |
| 42 | dependencies_installed: false, |
| 43 | backend_config: false, |
| 44 | frontend_config: false, |
| 45 | database_ready: false, |
| 46 | can_proceed: false |
| 47 | }; |
| 48 | |
| 49 | // 1. 检查项目结构 |
| 50 | const hasBackend = await directoryExists(`${projectPath}/backend`); |
| 51 | const hasFrontend = await directoryExists(`${projectPath}/frontend`); |
| 52 | |
| 53 | if (!hasBackend && !hasFrontend) { |
| 54 | throw new Error('❌ 无法找到后端或前端目录'); |
| 55 | } |
| 56 | |
| 57 | checks.project_structure = true; |
| 58 | console.log('✅ 项目结构检查通过'); |
| 59 | |
| 60 | // 2. 检查依赖安装 |
| 61 | if (hasBackend) { |
| 62 | const backendDeps = await fileExists(`${projectPath}/backend/node_modules`); |
| 63 | if (!backendDeps) { |
| 64 | console.log('⚠️ 后端依赖未安装,尝试安装...'); |
| 65 | await runCommand('cd backend && npm install', { timeout: 300000 }); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | if (hasFrontend) { |
| 70 | const frontendDeps = await fileExists(`${projectPath}/frontend/node_modules`); |
| 71 | if (!frontendDeps) { |
| 72 | console.log('⚠️ 前端依赖未安装,尝试安装...'); |
| 73 | await runCommand('cd frontend && npm install', { timeout: 300000 }); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | checks.dependencies_installed = true; |
| 78 | console.log('✅ 依赖检查通过'); |
| 79 | |
| 80 | // 3. 检查配置文件 |
| 81 | if (hasBackend) { |
| 82 | const backendConfig = await checkBackendConfig(projectPath); |
| 83 | checks.backend_config = backendConfig.valid; |
| 84 | |
| 85 | if (!backendConfig.valid) { |
| 86 | console.log('⚠️ 后端配置问题:'); |
| 87 | console.log(backendConfig.issues.join('\n')); |
| 88 | console.log('\n💡 建议修复:'); |
| 89 | console.log(backendConfig.fixes.join('\n')); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (hasFrontend) { |
| 94 | const frontendConfig = await checkFrontendConfig(projectPath); |
| 95 | checks.frontend_config = frontendConfig.valid; |
| 96 | |
| 97 | if (!frontendConfig.valid) { |
| 98 | console.log('⚠️ 前端配置问题:'); |
| 99 | console.log(frontendConfig.issues.join('\n')); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // 4. 数据库检查(如果需要) |
| 104 | const needsDatabase = await checkIfDatabaseNeeded(projectPath); |
| 105 | if (needsDatabase) { |
| 106 | const dbReady = await checkDatabaseConnection(projectPath); |
| 107 | checks.database_ready = dbReady; |
| 108 | |
| 109 | if (!dbReady) { |
| 110 | console.log('⚠️ 数据库未就绪'); |
| 111 | console.log('💡 可能的解决方案:'); |
| 112 | console.log(' 1. 启动数据库服务'); |
| 113 | console.log(' 2. 检查数据库连接配置'); |
| 114 | console.log(' 3. 使用内存数据库进行测试'); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // 判断是否可以继续 |
| 119 | const criticalChecks = [ |
| 120 | checks.project_structure, |
| 121 | checks.dependencies_installed, |
| 122 | checks.backend_config || !hasBackend, |
| 123 | checks.frontend_config || !hasFrontend |
| 124 | ]; |
| 125 | |
| 126 | checks.can_proceed = criticalChecks.every(c => c); |
| 127 | |
| 128 | return checks; |
| 129 | } |
| 130 | ``` |
| 131 | |
| 132 | ### 阶段1: 服务启动验证 |
| 133 | |
| 134 | ```typescript |
| 135 | /** |
| 136 | * 启动并验证服务 |
| 137 | */ |
| 138 | async function startAndVerifyServices( |
| 139 | projectPath: string, |
| 140 | envChecks: EnvironmentCheckResult |
| 141 | ): Promise<ServiceStartupResult> { |
| 142 | console.log('🚀 启动服务...\n'); |
| 143 | |
| 144 | const result: ServiceStartupResult = { |
| 145 | backend: { started: false, url: null, pid: null, error: null }, |
| 146 | frontend: { started: false, url: null, pid: null, error: null } |
| 147 | }; |
| 148 | |
| 149 | // 1. 启动后端服务 |
| 150 | if (await directoryExists(`${projectPath}/backend`)) { |
| 151 | try { |
| 152 | console.log('启动后端服务...'); |
| 153 | |
| 154 | const backendProcess = await spawnService({ |
| 155 | command: 'npm', |
| 156 | args: ['run', 'dev'], |
| 157 | cwd: `${projectPath}/backend`, |
| 158 | waitFor: /Server running|listening on/i, |
| 159 | timeout: 30000 |
| 160 | }); |
| 161 | |
| 162 | result.backend = { |
| 163 | started: true, |
| 164 | url: 'http://localhost:3000', |
| 165 | pid: backendProcess.pid, |
| 166 | error: null |
| 167 | }; |
| 168 | |
| 169 | console.log(`✅ 后端服务已启动: http://localhost:3000 (PID: ${backendProcess.pid})`); |
| 170 | |
| 171 | } catch (error) { |
| 172 | result.backend.error = error.message; |
| 173 | console.log(`❌ 后端服务启动失败: ${error.message}`); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | // 2. 启动前端服务 |
| 178 | if (await directoryExists(`${projectPath}/frontend`)) { |
| 179 | try { |
| 180 | console.log('启动前端服务...'); |
| 181 | |
| 182 | const frontendProcess = await spawnService({ |
| 183 | command: 'npm', |
| 184 | args: ['run', 'dev'], |
| 185 | cwd: `${projectPath}/frontend`, |
| 186 | waitFor: /Local:|ready in/i, |
| 187 | timeout: 60000 |
| 188 | }); |
| 189 | |
| 190 | result.frontend = { |
| 191 | started: true, |
| 192 | url: 'http://localhost:5173', |
| 193 | pid: frontendProcess.pid, |
| 194 | error: null |
| 195 | }; |
| 196 | |
| 197 | console.log(`✅ 前端服务已启动: http://localhost:5173 (PID: ${frontendProcess.pid})`); |
| 198 | |
| 199 | } catch (error) { |
| 200 | result.frontend.error = error.message; |
| 201 | console.log(`❌ 前端服务启动失败: ${error.message}`); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | // 3. 验证服务健康状态 |
| 206 | if (result.backend.started) { |
| 207 | const backendHealth = await checkHealthCheck(r |