Repository navigation
Expand file tree
/
Copy pathtest-bug-report.js
More file actions
294 lines (253 loc) · 10.9 KB
/
Copy pathtest-bug-report.js
File metadata and controls
294 lines (253 loc) · 10.9 KB
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
/**
* 完整功能测试和 Bug 报告脚本
* 测试所有核心功能,记录所有 bug
*/
const initSqlJs = require('sql.js');
const path = require('path');
const fs = require('fs');
const dbPath = path.join(process.env.APPDATA, 'project-delivery-tool', 'delivery.db');
const bugs = [];
function reportBug(module, description, severity = 'high') {
bugs.push({ module, description, severity, timestamp: new Date().toISOString() });
console.log(`[BUG] [${severity}] ${module}: ${description}`);
}
function reportPass(module, description) {
console.log(`[PASS] ${module}: ${description}`);
}
async function runTests() {
console.log('='.repeat(70));
console.log(' 项目交付管理工具 - 完整功能测试 & Bug 报告');
console.log('='.repeat(70));
console.log();
let SQL, db;
try {
SQL = await initSqlJs();
const fileBuffer = fs.readFileSync(dbPath);
db = new SQL.Database(fileBuffer);
console.log('[INFO] 数据库加载成功');
} catch (error) {
reportBug('数据库', `无法加载数据库:${error.message}`, 'critical');
return;
}
// ========== 测试 1: 数据库表结构 ==========
console.log('\n【测试 1】数据库表结构');
console.log('-'.repeat(40));
try {
const tables = db.exec("SELECT name FROM sqlite_master WHERE type='table'");
if (tables[0] && tables[0].values.length > 0) {
reportPass('数据库', `表结构完整,共 ${tables[0].values.length} 张表`);
} else {
reportBug('数据库', '数据库表不存在', 'critical');
}
} catch (error) {
reportBug('数据库', `表结构查询失败:${error.message}`, 'critical');
}
// ========== 测试 2: 项目管理模块 ==========
console.log('\n【测试 2】项目管理模块');
console.log('-'.repeat(40));
try {
const projects = db.exec('SELECT id, name, client, status FROM projects ORDER BY id DESC');
if (projects[0] && projects[0].values.length > 0) {
reportPass('项目管理', `现有项目 ${projects[0].values.length} 个`);
projects[0].values.forEach(p => {
console.log(` [${p[0]}] ${p[1]} - ${p[2]} (${p[3]})`);
});
} else {
console.log(' [INFO] 数据库中无项目记录');
}
} catch (error) {
reportBug('项目管理', `查询项目失败:${error.message}`, 'high');
}
// 测试新建项目数据结构
try {
const tableInfo = db.exec("PRAGMA table_info(projects)");
if (tableInfo[0]) {
const requiredColumns = ['id', 'name', 'client', 'start_date', 'end_date', 'status', 'budget_hours'];
const actualColumns = tableInfo[0].values.map(col => col[1]);
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('项目管理', `项目表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('项目管理', '项目表结构完整');
}
}
} catch (error) {
reportBug('项目管理', `检查表结构失败:${error.message}`, 'medium');
}
// ========== 测试 3: 任务管理模块 ==========
console.log('\n【测试 3】任务管理模块');
console.log('-'.repeat(40));
try {
const tasks = db.exec('SELECT COUNT(*) as count FROM tasks');
const taskCount = tasks[0]?.values[0]?.count || 0;
reportPass('任务管理', `现有任务 ${taskCount} 个`);
// 检查任务表结构
const tableInfo = db.exec("PRAGMA table_info(tasks)");
const requiredColumns = ['id', 'project_id', 'parent_id', 'name', 'description', 'start_date', 'duration', 'progress'];
const actualColumns = tableInfo[0]?.values.map(col => col[1]) || [];
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('任务管理', `任务表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('任务管理', '任务表结构完整');
}
} catch (error) {
reportBug('任务管理', `查询任务失败:${error.message}`, 'high');
}
// 测试层级关系
try {
const hierarchyCheck = db.exec(`
SELECT t.id, t.name, t.parent_id,
CASE WHEN t.parent_id IS NOT NULL AND p.id IS NULL THEN 'orphan' ELSE 'ok' END as status
FROM tasks t
LEFT JOIN tasks p ON t.parent_id = p.id
WHERE t.parent_id IS NOT NULL AND p.id IS NULL
LIMIT 5
`);
if (hierarchyCheck[0] && hierarchyCheck[0].values.length > 0) {
reportBug('任务管理', `发现孤立任务(父任务不存在): ${hierarchyCheck[0].values.length} 个`, 'medium');
} else {
reportPass('任务管理', '任务层级关系正常');
}
} catch (error) {
reportBug('任务管理', `层级关系检查失败:${error.message}`, 'medium');
}
// ========== 测试 4: 团队成员模块 ==========
console.log('\n【测试 4】团队成员模块');
console.log('-'.repeat(40));
try {
const members = db.exec('SELECT id, name, role, skills FROM members ORDER BY id');
if (members[0] && members[0].values.length > 0) {
reportPass('团队成员', `现有成员 ${members[0].values.length} 个`);
members[0].values.forEach(m => {
const skills = JSON.parse(m[3] || '[]');
console.log(` [${m[0]}] ${m[1]} - ${m[2]} (技能:${skills.join(', ')})`);
});
} else {
console.log(' [INFO] 数据库中无成员记录');
}
// 检查成员表结构
const tableInfo = db.exec("PRAGMA table_info(members)");
const requiredColumns = ['id', 'name', 'role', 'skills', 'available_hours_per_day'];
const actualColumns = tableInfo[0]?.values.map(col => col[1]) || [];
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('团队成员', `成员表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('团队成员', '成员表结构完整');
}
} catch (error) {
reportBug('团队成员', `查询成员失败:${error.message}`, 'high');
}
// ========== 测试 5: 资源日历模块 ==========
console.log('\n【测试 5】资源日历模块');
console.log('-'.repeat(40));
try {
const calendar = db.exec('SELECT COUNT(*) as count FROM resource_calendar');
const count = calendar[0]?.values[0]?.count || 0;
reportPass('资源日历', `现有日历记录 ${count} 条`);
// 检查表结构
const tableInfo = db.exec("PRAGMA table_info(resource_calendar)");
const requiredColumns = ['id', 'member_id', 'date', 'available_hours', 'assigned_hours', 'type'];
const actualColumns = tableInfo[0]?.values.map(col => col[1]) || [];
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('资源日历', `日历表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('资源日历', '日历表结构完整');
}
} catch (error) {
reportBug('资源日历', `查询日历失败:${error.message}`, 'high');
}
// ========== 测试 6: 报告生成模块 ==========
console.log('\n【测试 6】报告生成模块');
console.log('-'.repeat(40));
try {
const reports = db.exec('SELECT COUNT(*) as count FROM reports');
const count = reports[0]?.values[0]?.count || 0;
reportPass('报告生成', `现有报告 ${count} 份`);
// 检查表结构
const tableInfo = db.exec("PRAGMA table_info(reports)");
const requiredColumns = ['id', 'project_id', 'type', 'date_range', 'content'];
const actualColumns = tableInfo[0]?.values.map(col => col[1]) || [];
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('报告生成', `报告表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('报告生成', '报告表结构完整');
}
} catch (error) {
reportBug('报告生成', `查询报告失败:${error.message}`, 'high');
}
// ========== 测试 7: 风险管理模块 ==========
console.log('\n【测试 7】风险管理模块');
console.log('-'.repeat(40));
try {
const risks = db.exec('SELECT COUNT(*) as count FROM risks');
const count = risks[0]?.values[0]?.count || 0;
reportPass('风险管理', `现有风险 ${count} 个`);
// 检查表结构
const tableInfo = db.exec("PRAGMA table_info(risks)");
const requiredColumns = ['id', 'project_id', 'description', 'severity', 'probability', 'status'];
const actualColumns = tableInfo[0]?.values.map(col => col[1]) || [];
const missing = requiredColumns.filter(col => !actualColumns.includes(col));
if (missing.length > 0) {
reportBug('风险管理', `风险表缺少字段:${missing.join(', ')}`, 'high');
} else {
reportPass('风险管理', '风险表结构完整');
}
} catch (error) {
reportBug('风险管理', `查询风险失败:${error.message}`, 'high');
}
// ========== 测试 8: 数据库保存功能 ==========
console.log('\n【测试 8】数据库保存功能');
console.log('-'.repeat(40));
try {
const stats = fs.statSync(dbPath);
reportPass('数据库保存', `数据库文件大小:${(stats.size / 1024).toFixed(2)} KB`);
console.log(` 最后修改时间:${stats.mtime.toLocaleString('zh-CN')}`);
} catch (error) {
reportBug('数据库保存', `无法读取数据库文件:${error.message}`, 'critical');
}
// 尝试写入测试数据
try {
const testProjectName = `测试项目_${Date.now()}`;
db.run('INSERT INTO projects (name, client, start_date, end_date, status) VALUES (?, ?, ?, ?, ?)',
[testProjectName, '测试客户', '2026-03-20', '2026-04-20', 'planning']);
// 立即导出并保存
const data = db.export();
const buffer = Buffer.from(data);
fs.writeFileSync(dbPath + '.test', buffer);
fs.unlinkSync(dbPath + '.test');
// 删除测试数据
db.run('DELETE FROM projects WHERE name = ?', [testProjectName]);
reportPass('数据库写入', '写入测试通过');
} catch (error) {
reportBug('数据库写入', `写入测试失败:${error.message}`, 'critical');
}
db.close();
// ========== 测试总结 ==========
console.log('\n' + '='.repeat(70));
console.log(' 测试总结');
console.log('='.repeat(70));
console.log();
const criticalBugs = bugs.filter(b => b.severity === 'critical');
const highBugs = bugs.filter(b => b.severity === 'high');
const mediumBugs = bugs.filter(b => b.severity === 'medium');
console.log(`Bug 统计:`);
console.log(` Critical: ${criticalBugs.length}`);
console.log(` High: ${highBugs.length}`);
console.log(` Medium: ${mediumBugs.length}`);
console.log(` Total: ${bugs.length}`);
console.log();
if (bugs.length > 0) {
console.log('Bug 列表:');
bugs.forEach((bug, i) => {
console.log(` ${i+1}. [${bug.severity.toUpperCase()}] ${bug.module}: ${bug.description}`);
});
console.log();
}
console.log('数据库位置:', dbPath);
console.log('='.repeat(70));
}
runTests().catch(console.error);