Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | /** * Test Suite - 完整测试套件 */ const assert = require('assert'); const path = require('path'); // 测试配置 const config = { dbPath: path.join(__dirname, 'test.db'), timeout: 5000 }; // 测试计数器 let testsPassed = 0; let testsFailed = 0; /** * 运行单个测试 */ function runTest(name, testFn) { try { testFn(); console.log(`✅ ${name}`); testsPassed++; } catch (error) { console.log(`❌ ${name}`); console.log(` ${error.message}`); testsFailed++; } } /** * 测试工具函数 */ function testUtils() { console.log('\n📦 测试工具函数...'); const { formatStatus, formatPriority, createProgressBar, truncate } = require('./utils'); runTest('formatStatus', () => { assert.strictEqual(formatStatus('completed'), '✅ 已完成'); assert.strictEqual(formatStatus('pending'), '⏳ 待处理'); }); runTest('formatPriority', () => { assert.strictEqual(formatPriority(1), '🔴 高'); assert.strictEqual(formatPriority(3), '🟡 中'); assert.strictEqual(formatPriority(5), '🟢 低'); }); runTest('createProgressBar', () => { const bar = createProgressBar(50, 20); assert(bar.includes('█')); assert(bar.includes('░')); assert(bar.includes('50%')); }); runTest('truncate', () => { assert.strictEqual(truncate('Hello World', 5), 'Hello'); assert.strictEqual(truncate('Hello', 10), 'Hello'); }); } /** * 测试数据库操作 */ function testDatabase() { console.log('\n🗄️ 测试数据库操作...'); const { initDatabase, createTask, getAllTasks, getTaskById } = require('./db/task-manager'); runTest('initDatabase', () => { initDatabase(); }); runTest('createTask', () => { const task = { project_id: 'test-project', title: 'Test Task', description: 'Test Description', status: 'pending', priority: 3 }; const result = createTask(task); assert(result.id > 0); assert.strictEqual(result.title, task.title); }); runTest('getAllTasks', () => { const tasks = getAllTasks(); assert(Array.isArray(tasks)); }); runTest('getTaskById', () => { const task = getTaskById(1); assert(task !== undefined); }); } /** * 测试 Agent 操作 */ function testAgents() { console.log('\n🤖 测试 Agent 操作...'); const { initDatabase, upsertAgent, getAllAgents, getAgentByName } = require('./db/agent-manager'); runTest('initDatabase', () => { initDatabase(); }); runTest('upsertAgent', () => { const agent = { name: 'Test Agent', role: 'test', target: 'qqbot:c2c:test', description: 'Test Description', capabilities: 'test' }; const result = upsertAgent(agent); assert(result.changes > 0); }); runTest('getAllAgents', () => { const agents = getAllAgents(); assert(Array.isArray(agents)); }); runTest('getAgentByName', () => { const agent = getAgentByName('Test Agent'); assert(agent !== undefined); }); } /** * 测试任务依赖 */ function testDependencies() { console.log('\n🔗 测试任务依赖...'); const { initDependencies, addDependency, getTaskDependencies, canExecuteTask } = require('./db/task-dependency-manager'); runTest('initDependencies', () => { initDependencies(); }); runTest('addDependency', () => { const result = addDependency(1, 2, 'BLOCKING'); assert(result > 0); }); runTest('getTaskDependencies', () => { const deps = getTaskDependencies(1); assert(Array.isArray(deps)); }); runTest('canExecuteTask', () => { const canExecute = canExecuteTask(1); assert(typeof canExecute === 'boolean'); }); } /** * 测试项目操作 */ function testProjects() { console.log('\n📁 测试项目操作...'); const { initDatabase, createProject, getAllProjects, getProjectById } = require('./db/project-manager'); runTest('initDatabase', () => { initDatabase(); }); runTest('createProject', () => { const project = { name: 'Test Project', description: 'Test Description', status: 'active' }; const result = createProject(project); assert(result.id > 0); assert.strictEqual(result.name, project.name); }); runTest('getAllProjects', () => { const projects = getAllProjects(); assert(Array.isArray(projects)); }); runTest('getProjectById', () => { const project = getProjectById(1); assert(project !== undefined); }); } /** * 运行所有测试 */ function runAllTests() { console.log('🚀 开始运行测试...\n'); testUtils(); testDatabase(); testAgents(); testDependencies(); testProjects(); console.log('\n📊 测试结果:'); console.log(` 通过:${testsPassed}`); console.log(` 失败:${testsFailed}`); console.log(` 总计:${testsPassed + testsFailed}`); if (testsFailed === 0) { console.log('\n🎉 所有测试通过!'); } else { console.log('\n⚠️ 部分测试失败,请检查错误信息'); } } // 运行测试 runAllTests(); |