Repository navigation
Expand file tree
/
Copy pathtest-full-flow.js
More file actions
124 lines (102 loc) · 4.42 KB
/
Copy pathtest-full-flow.js
File metadata and controls
124 lines (102 loc) · 4.42 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
/**
* Test Full Flow: Create Project + AI Task Decomposition
*/
const initSqlJs = require('sql.js');
const path = require('path');
const fs = require('fs');
// Get user data directory
const getUserDataPath = () => {
const appData = process.env.APPDATA || path.join(process.env.HOME || '', '.local', 'share');
return path.join(appData, 'project-delivery-tool');
};
const dbPath = path.join(getUserDataPath(), 'delivery.db');
async function testFullFlow() {
try {
const SQL = await initSqlJs();
const fileBuffer = fs.readFileSync(dbPath);
const db = new SQL.Database(fileBuffer);
console.log('=== Testing Full Flow ===\n');
// Step 1: Create a test project
console.log('Step 1: Creating test project...');
db.run(`
INSERT INTO projects (name, client, start_date, end_date, status, budget_hours)
VALUES (?, ?, ?, ?, ?, ?)
`, ['测试项目 - 用户登录系统', '某企业客户', '2026-03-17', '2026-04-15', 'planning', 200]);
const projectIdResult = db.exec('SELECT last_insert_rowid() as id');
const projectId = projectIdResult[0].values[0][0];
console.log(`✓ Project created with ID: ${projectId}\n`);
// Step 2: Call AI service to decompose task
console.log('Step 2: Calling AI to decompose task...');
const { AIService } = require('./electron/ai-service');
const aiService = new AIService();
const subtasks = await aiService.decomposeTask({
projectName: '测试项目 - 用户登录系统',
taskDescription: '实现用户登录功能,包括前端页面、后端 API、数据库设计',
startDate: '2026-03-17',
endDate: '2026-03-25',
});
console.log(`✓ AI returned ${subtasks.length} subtasks\n`);
// Step 3: Create parent task
console.log('Step 3: Creating parent task in database...');
db.run(`
INSERT INTO tasks (project_id, parent_id, name, description, start_date, end_date, duration, progress)
VALUES (?, NULL, ?, ?, ?, ?, ?, 0)
`, [projectId, '用户登录功能', '实现用户登录功能,包括前端页面、后端 API、数据库设计', '2026-03-17', '2026-03-25', 9]);
const parentTaskResult = db.exec('SELECT last_insert_rowid() as id');
const parentTaskId = parentTaskResult[0].values[0][0];
console.log(`✓ Parent task created with ID: ${parentTaskId}\n`);
// Step 4: Create subtasks
console.log('Step 4: Creating subtasks in database...');
const taskIdMap = new Map();
taskIdMap.set(null, parentTaskId);
for (const subtask of subtasks) {
const parentId = subtask.parent ? taskIdMap.get(subtask.parent) : parentTaskId;
const startDate = new Date('2026-03-17');
startDate.setDate(startDate.getDate() + subtask.id);
const endDate = new Date(startDate);
endDate.setDate(endDate.getDate() + (subtask.duration || 1));
db.run(`
INSERT INTO tasks (project_id, parent_id, name, description, start_date, end_date, duration, progress, predecessor_ids)
VALUES (?, ?, ?, ?, ?, ?, ?, 0, ?)
`, [
projectId,
parentId,
subtask.name,
subtask.name,
startDate.toISOString().split('T')[0],
endDate.toISOString().split('T')[0],
subtask.duration || 1,
subtask.predecessor ? String(taskIdMap.get(subtask.predecessor)) : null
]);
const taskResult = db.exec('SELECT last_insert_rowid() as id');
taskIdMap.set(subtask.id, taskResult[0].values[0][0]);
}
console.log(`✓ All ${subtasks.length} subtasks created\n`);
// Step 5: Verify data
console.log('Step 5: Verifying data...');
const tasks = db.exec(`
SELECT t.id, t.name, t.duration, t.parent_id, p.name as project_name
FROM tasks t
JOIN projects p ON t.project_id = p.id
WHERE t.project_id = ${projectId}
ORDER BY t.id
`);
console.log('\nTasks in database:');
console.log('---');
tasks[0].values.forEach(row => {
console.log(` [${row[0]}] ${row[1]} (${row[2]} days) - Parent: ${row[3] || 'null'}`);
});
// Save and close
const data = db.export();
const buffer = Buffer.from(data);
fs.writeFileSync(dbPath, buffer);
db.close();
console.log('\n=== Test Completed Successfully! ===');
console.log(`\nDatabase saved to: ${dbPath}`);
console.log('\nYou can now run the Electron app to see the tasks in the Gantt chart.');
} catch (error) {
console.error('Test failed:', error);
process.exit(1);
}
}
testFullFlow();