openmatrix 0.1.49 → 0.1.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -8
- package/dist/cli/commands/analyze.js +3 -4
- package/dist/cli/commands/brainstorm.js +52 -74
- package/dist/cli/commands/start.js +31 -163
- package/dist/cli/index.js +0 -4
- package/dist/orchestrator/smart-question-analyzer.d.ts +0 -38
- package/dist/orchestrator/smart-question-analyzer.js +7 -257
- package/dist/orchestrator/task-parser.d.ts +0 -8
- package/dist/orchestrator/task-parser.js +9 -22
- package/dist/orchestrator/task-planner.d.ts +45 -10
- package/dist/orchestrator/task-planner.js +282 -188
- package/dist/storage/state-manager.d.ts +0 -1
- package/dist/storage/state-manager.js +1 -1
- package/package.json +55 -56
- package/skills/brainstorm.md +238 -105
- package/skills/check.md +199 -199
- package/skills/openmatrix.md +190 -175
- package/skills/start.md +626 -171
|
@@ -4,45 +4,49 @@ exports.TaskPlanner = void 0;
|
|
|
4
4
|
/**
|
|
5
5
|
* TaskPlanner - 任务拆解器
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* 增强版特性:
|
|
8
|
+
* 1. 更细粒度的任务拆分 (每个目标拆分为设计+实现+测试)
|
|
9
|
+
* 2. 测试任务配对 (每个开发任务自动生成对应测试任务)
|
|
10
|
+
* 3. 验收标准注入 (从用户回答中提取)
|
|
11
|
+
* 4. 用户上下文注入 (将用户回答注入任务描述)
|
|
12
|
+
* 5. 依赖关系分析 (自动分析任务间依赖)
|
|
10
13
|
*/
|
|
11
14
|
class TaskPlanner {
|
|
15
|
+
userAnswers;
|
|
16
|
+
constructor(userAnswers) {
|
|
17
|
+
this.userAnswers = userAnswers || {};
|
|
18
|
+
}
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
20
|
+
* 设置用户回答
|
|
14
21
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// 有 goals → 按 goals 拆分多任务
|
|
18
|
-
if (parsedTask.goals.length > 0) {
|
|
19
|
-
return this.breakdownByGoals(parsedTask, userContext, answers);
|
|
20
|
-
}
|
|
21
|
-
// 无 goals → 退化为 planner → coder → tester 三任务
|
|
22
|
-
return this.breakdownFallback(parsedTask, userContext, answers);
|
|
22
|
+
setUserAnswers(answers) {
|
|
23
|
+
this.userAnswers = answers;
|
|
23
24
|
}
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
+
* Break down a parsed task into sub-tasks
|
|
27
|
+
*
|
|
28
|
+
* 增强版: 生成更细粒度的任务,包含设计、开发、测试配对
|
|
26
29
|
*/
|
|
27
|
-
|
|
30
|
+
breakdown(parsedTask, answers) {
|
|
28
31
|
const breakdowns = [];
|
|
29
32
|
const seenTitles = new Set();
|
|
30
|
-
|
|
33
|
+
const userContext = this.extractUserContext(answers);
|
|
34
|
+
// 0. 设计阶段任务
|
|
31
35
|
if (parsedTask.goals.length > 1) {
|
|
32
36
|
breakdowns.push({
|
|
33
37
|
taskId: this.generateTaskId(),
|
|
34
38
|
title: '架构设计和任务规划',
|
|
35
|
-
description: `分析需求,设计整体架构,规划实现方案
|
|
36
|
-
|
|
37
|
-
## 用户需求
|
|
38
|
-
${userContext.objective ||
|
|
39
|
-
|
|
40
|
-
## 技术栈
|
|
41
|
-
${userContext.techStack?.join(', ') || '未指定'}
|
|
42
|
-
|
|
43
|
-
## 输出
|
|
44
|
-
- 架构设计文档
|
|
45
|
-
- 接口定义
|
|
39
|
+
description: `分析需求,设计整体架构,规划实现方案
|
|
40
|
+
|
|
41
|
+
## 用户需求
|
|
42
|
+
${userContext.objective || '未指定'}
|
|
43
|
+
|
|
44
|
+
## 技术栈
|
|
45
|
+
${userContext.techStack?.join(', ') || '未指定'}
|
|
46
|
+
|
|
47
|
+
## 输出
|
|
48
|
+
- 架构设计文档
|
|
49
|
+
- 接口定义
|
|
46
50
|
- 任务依赖图`,
|
|
47
51
|
priority: 'P0',
|
|
48
52
|
dependencies: [],
|
|
@@ -57,37 +61,41 @@ ${userContext.techStack?.join(', ') || '未指定'}
|
|
|
57
61
|
]
|
|
58
62
|
});
|
|
59
63
|
}
|
|
60
|
-
// 1.
|
|
64
|
+
// 1. 为每个目标创建细粒度任务
|
|
61
65
|
const devTaskIds = [];
|
|
62
66
|
for (let i = 0; i < parsedTask.goals.length; i++) {
|
|
63
67
|
const goal = parsedTask.goals[i];
|
|
64
|
-
|
|
68
|
+
// 跳过重复项
|
|
69
|
+
if (seenTitles.has(goal)) {
|
|
65
70
|
continue;
|
|
71
|
+
}
|
|
66
72
|
seenTitles.add(goal);
|
|
73
|
+
// 创建开发任务
|
|
67
74
|
const devTaskId = this.generateTaskId();
|
|
68
75
|
devTaskIds.push(devTaskId);
|
|
69
|
-
|
|
76
|
+
const acceptanceCriteria = this.generateAcceptanceCriteria(goal, userContext);
|
|
70
77
|
breakdowns.push({
|
|
71
78
|
taskId: devTaskId,
|
|
72
79
|
title: `实现: ${goal}`,
|
|
73
80
|
description: this.buildTaskDescription(goal, userContext, answers),
|
|
74
81
|
priority: this.determinePriority(i),
|
|
75
82
|
dependencies: i === 0 && parsedTask.goals.length > 1
|
|
76
|
-
? [breakdowns[0].taskId]
|
|
77
|
-
: (i > 0 ? [devTaskIds[i - 1]] : []),
|
|
83
|
+
? [breakdowns[0].taskId] // 依赖设计任务
|
|
84
|
+
: (i > 0 ? [devTaskIds[i - 1]] : []), // 依赖前一个开发任务
|
|
78
85
|
estimatedComplexity: this.estimateComplexity(goal),
|
|
79
86
|
assignedAgent: 'coder',
|
|
80
87
|
phase: 'develop',
|
|
81
|
-
acceptanceCriteria
|
|
88
|
+
acceptanceCriteria,
|
|
89
|
+
testTaskId: undefined // 稍后关联
|
|
82
90
|
});
|
|
83
|
-
//
|
|
91
|
+
// 为每个开发任务创建配对的测试任务
|
|
84
92
|
const testTaskId = this.generateTaskId();
|
|
85
93
|
breakdowns.push({
|
|
86
94
|
taskId: testTaskId,
|
|
87
95
|
title: `测试: ${goal}`,
|
|
88
96
|
description: this.buildTestDescription(goal, devTaskId, userContext),
|
|
89
97
|
priority: this.determinePriority(i),
|
|
90
|
-
dependencies: [devTaskId],
|
|
98
|
+
dependencies: [devTaskId], // 测试依赖开发任务
|
|
91
99
|
estimatedComplexity: 'medium',
|
|
92
100
|
assignedAgent: 'tester',
|
|
93
101
|
phase: 'verify',
|
|
@@ -98,23 +106,23 @@ ${userContext.techStack?.join(', ') || '未指定'}
|
|
|
98
106
|
'所有测试通过'
|
|
99
107
|
]
|
|
100
108
|
});
|
|
101
|
-
// 关联测试任务
|
|
109
|
+
// 关联测试任务 ID
|
|
102
110
|
breakdowns[breakdowns.length - 2].testTaskId = testTaskId;
|
|
103
111
|
}
|
|
104
|
-
// 2.
|
|
105
|
-
if (devTaskIds.length >
|
|
112
|
+
// 2. 代码审查任务 (仅在有开发任务时创建)
|
|
113
|
+
if (devTaskIds.length > 0) {
|
|
106
114
|
breakdowns.push({
|
|
107
115
|
taskId: this.generateTaskId(),
|
|
108
116
|
title: '代码审查',
|
|
109
|
-
description: `对所有开发任务进行代码审查
|
|
110
|
-
|
|
111
|
-
## 审查范围
|
|
112
|
-
${devTaskIds.map(id => `- ${id}`).join('\n')}
|
|
113
|
-
|
|
114
|
-
## 审查要点
|
|
115
|
-
- 代码质量
|
|
116
|
-
- 安全性
|
|
117
|
-
- 性能
|
|
117
|
+
description: `对所有开发任务进行代码审查
|
|
118
|
+
|
|
119
|
+
## 审查范围
|
|
120
|
+
${devTaskIds.map(id => `- ${id}`).join('\n')}
|
|
121
|
+
|
|
122
|
+
## 审查要点
|
|
123
|
+
- 代码质量
|
|
124
|
+
- 安全性
|
|
125
|
+
- 性能
|
|
118
126
|
- 最佳实践`,
|
|
119
127
|
priority: 'P1',
|
|
120
128
|
dependencies: devTaskIds,
|
|
@@ -129,188 +137,270 @@ ${devTaskIds.map(id => `- ${id}`).join('\n')}
|
|
|
129
137
|
]
|
|
130
138
|
});
|
|
131
139
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
if (userContext.objective)
|
|
147
|
-
contextParts.push(`## 核心目标\n${userContext.objective}`);
|
|
148
|
-
if (userContext.techStack?.length)
|
|
149
|
-
contextParts.push(`## 技术栈\n${userContext.techStack.join(', ')}`);
|
|
150
|
-
if (parsedTask.constraints.length)
|
|
151
|
-
contextParts.push(`## 约束\n${parsedTask.constraints.map(c => `- ${c}`).join('\n')}`);
|
|
152
|
-
const brainstormKeys = ['brainstormAnswers', 'insights', 'designNotes'];
|
|
153
|
-
for (const key of brainstormKeys) {
|
|
154
|
-
if (answers[key])
|
|
155
|
-
contextParts.push(`## ${key}\n${answers[key]}`);
|
|
156
|
-
}
|
|
157
|
-
const fullContext = contextParts.join('\n\n');
|
|
158
|
-
return [
|
|
159
|
-
{
|
|
160
|
-
taskId: planTaskId,
|
|
161
|
-
title: `${parsedTask.title} - 需求分析与规划`,
|
|
162
|
-
description: `分析需求并制定实现计划。
|
|
163
|
-
|
|
164
|
-
${fullContext}
|
|
165
|
-
|
|
166
|
-
## 你的任务
|
|
167
|
-
1. 深入理解需求
|
|
168
|
-
2. 设计实现方案
|
|
169
|
-
3. 将需求拆解为具体步骤
|
|
170
|
-
|
|
171
|
-
## 输出: PLAN.md
|
|
172
|
-
在 .openmatrix/plan/ 目录创建 PLAN.md,格式:
|
|
173
|
-
|
|
174
|
-
# 实现计划
|
|
175
|
-
|
|
176
|
-
## 架构设计
|
|
177
|
-
(整体方案)
|
|
178
|
-
|
|
179
|
-
## 实现步骤
|
|
180
|
-
### 步骤 1: (标题)
|
|
181
|
-
- 描述: (具体做什么)
|
|
182
|
-
- 文件: (涉及哪些文件)
|
|
183
|
-
- 验收: (怎么判断完成)
|
|
184
|
-
|
|
185
|
-
### 步骤 2: (标题)
|
|
186
|
-
...
|
|
187
|
-
|
|
188
|
-
## 注意事项
|
|
189
|
-
- (风险、约束等)`,
|
|
190
|
-
priority: 'P0',
|
|
191
|
-
dependencies: [],
|
|
192
|
-
estimatedComplexity: 'high',
|
|
193
|
-
assignedAgent: 'planner',
|
|
194
|
-
phase: 'design',
|
|
195
|
-
acceptanceCriteria: [
|
|
196
|
-
'PLAN.md 已创建在 .openmatrix/plan/',
|
|
197
|
-
'实现步骤清晰可执行',
|
|
198
|
-
'每步有明确的文件和验收标准'
|
|
199
|
-
]
|
|
200
|
-
},
|
|
201
|
-
{
|
|
202
|
-
taskId: devTaskId,
|
|
203
|
-
title: `${parsedTask.title} - 开发实现`,
|
|
204
|
-
description: `根据 PLAN.md 实现功能。
|
|
205
|
-
|
|
206
|
-
${fullContext}
|
|
207
|
-
|
|
208
|
-
## 执行方式
|
|
209
|
-
1. 先读取 .openmatrix/plan/PLAN.md
|
|
210
|
-
2. 按照步骤逐一实现
|
|
211
|
-
3. 每完成一个步骤,验证对应的验收标准
|
|
212
|
-
|
|
213
|
-
## 输出
|
|
214
|
-
- 完整的功能代码
|
|
215
|
-
- 必要的配置文件`,
|
|
140
|
+
// 3. 集成测试任务 (如果有多个交付物)
|
|
141
|
+
if (parsedTask.deliverables.length > 1) {
|
|
142
|
+
breakdowns.push({
|
|
143
|
+
taskId: this.generateTaskId(),
|
|
144
|
+
title: '集成测试',
|
|
145
|
+
description: `验证所有交付物正确集成
|
|
146
|
+
|
|
147
|
+
## 交付物
|
|
148
|
+
${parsedTask.deliverables.map(d => `- ${d}`).join('\n')}
|
|
149
|
+
|
|
150
|
+
## 测试范围
|
|
151
|
+
- 模块间接口
|
|
152
|
+
- 端到端流程
|
|
153
|
+
- 数据流验证`,
|
|
216
154
|
priority: 'P1',
|
|
217
|
-
dependencies:
|
|
218
|
-
estimatedComplexity: '
|
|
219
|
-
assignedAgent: '
|
|
220
|
-
phase: '
|
|
155
|
+
dependencies: devTaskIds,
|
|
156
|
+
estimatedComplexity: 'medium',
|
|
157
|
+
assignedAgent: 'tester',
|
|
158
|
+
phase: 'verify',
|
|
221
159
|
acceptanceCriteria: [
|
|
222
|
-
'
|
|
223
|
-
'
|
|
224
|
-
'
|
|
160
|
+
'所有模块正确集成',
|
|
161
|
+
'端到端流程通过',
|
|
162
|
+
'接口兼容性验证',
|
|
163
|
+
'集成测试报告完整'
|
|
225
164
|
]
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
// 4. E2E 测试任务 (如果启用,作为 verify 阶段的一部分)
|
|
168
|
+
if (userContext.e2eTests) {
|
|
169
|
+
const e2eTaskId = this.generateTaskId();
|
|
170
|
+
const e2eType = userContext.e2eType || 'web';
|
|
171
|
+
// E2E 测试依赖所有开发任务和单元测试任务
|
|
172
|
+
const allTestDependencies = [...devTaskIds];
|
|
173
|
+
breakdowns.forEach(b => {
|
|
174
|
+
if (b.phase === 'verify' && b.title.startsWith('测试:')) {
|
|
175
|
+
allTestDependencies.push(b.taskId);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
breakdowns.push({
|
|
179
|
+
taskId: e2eTaskId,
|
|
180
|
+
title: '端到端(E2E)测试',
|
|
181
|
+
description: this.buildE2ETestDescription(e2eType, parsedTask, userContext),
|
|
182
|
+
priority: 'P0', // E2E 测试是关键任务
|
|
183
|
+
dependencies: allTestDependencies, // 依赖所有开发任务和单元测试
|
|
184
|
+
estimatedComplexity: 'high',
|
|
243
185
|
assignedAgent: 'tester',
|
|
244
186
|
phase: 'verify',
|
|
245
187
|
acceptanceCriteria: [
|
|
246
|
-
'
|
|
247
|
-
'
|
|
248
|
-
'
|
|
188
|
+
'所有 E2E 测试用例通过',
|
|
189
|
+
'关键用户流程验证完成',
|
|
190
|
+
'跨浏览器/设备兼容性验证',
|
|
191
|
+
'E2E 测试报告已生成',
|
|
192
|
+
'无阻塞级别的缺陷'
|
|
249
193
|
]
|
|
250
|
-
}
|
|
251
|
-
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
// 5. 文档任务 (如果需要)
|
|
197
|
+
if (userContext.documentationLevel && userContext.documentationLevel !== '无需文档') {
|
|
198
|
+
breakdowns.push({
|
|
199
|
+
taskId: this.generateTaskId(),
|
|
200
|
+
title: '文档编写',
|
|
201
|
+
description: `编写项目文档
|
|
202
|
+
|
|
203
|
+
## 文档级别
|
|
204
|
+
${userContext.documentationLevel}
|
|
205
|
+
|
|
206
|
+
## 文档内容
|
|
207
|
+
- README 更新
|
|
208
|
+
- API 文档
|
|
209
|
+
- 使用说明`,
|
|
210
|
+
priority: 'P2',
|
|
211
|
+
dependencies: devTaskIds,
|
|
212
|
+
estimatedComplexity: 'low',
|
|
213
|
+
assignedAgent: 'executor',
|
|
214
|
+
phase: 'accept',
|
|
215
|
+
acceptanceCriteria: [
|
|
216
|
+
'README 已更新',
|
|
217
|
+
'API 文档完整',
|
|
218
|
+
'使用说明清晰'
|
|
219
|
+
]
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
return breakdowns;
|
|
252
223
|
}
|
|
253
|
-
|
|
224
|
+
/**
|
|
225
|
+
* 提取用户上下文
|
|
226
|
+
*/
|
|
254
227
|
extractUserContext(answers) {
|
|
228
|
+
const e2eAnswer = answers['E2E测试'] || answers['e2eTests'] || answers['e2e'];
|
|
229
|
+
const e2eTypeAnswer = answers['E2E类型'] || answers['e2eType'];
|
|
255
230
|
return {
|
|
256
231
|
objective: answers['目标'] || answers['objective'],
|
|
257
232
|
techStack: this.parseArrayAnswer(answers['技术栈'] || answers['techStack']),
|
|
258
233
|
testCoverage: answers['测试'] || answers['testCoverage'],
|
|
259
234
|
documentationLevel: answers['文档'] || answers['documentationLevel'],
|
|
235
|
+
e2eTests: e2eAnswer === 'true' || e2eAnswer === '✅ 启用 E2E 测试' || e2eAnswer === '是',
|
|
236
|
+
e2eType: e2eTypeAnswer || 'web',
|
|
260
237
|
additionalContext: answers
|
|
261
238
|
};
|
|
262
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* 解析数组类型的回答
|
|
242
|
+
*/
|
|
263
243
|
parseArrayAnswer(answer) {
|
|
264
244
|
if (!answer)
|
|
265
245
|
return [];
|
|
246
|
+
// 处理逗号分隔或换行分隔的答案
|
|
266
247
|
return answer.split(/[,,\n]/).map(s => s.trim()).filter(Boolean);
|
|
267
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* 构建任务描述 (注入用户上下文)
|
|
251
|
+
*/
|
|
268
252
|
buildTaskDescription(goal, userContext, answers) {
|
|
269
253
|
const parts = [];
|
|
270
254
|
parts.push(`## 任务目标\n${goal}\n`);
|
|
271
|
-
if (userContext.objective)
|
|
255
|
+
if (userContext.objective) {
|
|
272
256
|
parts.push(`## 整体目标\n${userContext.objective}\n`);
|
|
273
|
-
|
|
257
|
+
}
|
|
258
|
+
if (userContext.techStack && userContext.techStack.length > 0) {
|
|
274
259
|
parts.push(`## 技术栈要求\n${userContext.techStack.map(t => `- ${t}`).join('\n')}\n`);
|
|
275
260
|
}
|
|
261
|
+
// 注入所有用户回答
|
|
276
262
|
const relevantAnswers = Object.entries(answers).filter(([key]) => !['目标', '技术栈', '测试', '文档', 'objective', 'techStack', 'testCoverage', 'documentationLevel'].includes(key));
|
|
277
263
|
if (relevantAnswers.length > 0) {
|
|
278
264
|
parts.push(`## 其他要求\n${relevantAnswers.map(([k, v]) => `- ${k}: ${v}`).join('\n')}\n`);
|
|
279
265
|
}
|
|
280
|
-
parts.push(`## 输出要求
|
|
281
|
-
- 完成功能实现
|
|
282
|
-
- 代码可编译
|
|
283
|
-
- 遵循项目规范
|
|
266
|
+
parts.push(`## 输出要求
|
|
267
|
+
- 完成功能实现
|
|
268
|
+
- 代码可编译
|
|
269
|
+
- 遵循项目规范
|
|
284
270
|
- 添加必要注释`);
|
|
285
271
|
return parts.join('\n');
|
|
286
272
|
}
|
|
273
|
+
/**
|
|
274
|
+
* 构建测试任务描述
|
|
275
|
+
*/
|
|
287
276
|
buildTestDescription(goal, devTaskId, userContext) {
|
|
288
277
|
const coverage = this.parseCoverage(userContext.testCoverage || '60%');
|
|
289
|
-
return `## 测试目标
|
|
290
|
-
为 "${goal}" 编写测试用例
|
|
291
|
-
|
|
292
|
-
## 关联开发任务
|
|
293
|
-
${devTaskId}
|
|
294
|
-
|
|
295
|
-
## 测试要求
|
|
296
|
-
- 单元测试覆盖率 >= ${coverage}%
|
|
297
|
-
- 测试正常流程
|
|
298
|
-
- 测试边界情况
|
|
299
|
-
- 测试异常处理
|
|
300
|
-
|
|
301
|
-
## 测试文件
|
|
302
|
-
- 创建 \`.test.ts\` 或 \`.spec.ts\` 文件
|
|
303
|
-
- 放置在与源文件相同目录或 \`tests/\` 目录
|
|
304
|
-
|
|
305
|
-
## 输出
|
|
306
|
-
- 测试文件
|
|
307
|
-
- 测试报告
|
|
278
|
+
return `## 测试目标
|
|
279
|
+
为 "${goal}" 编写测试用例
|
|
280
|
+
|
|
281
|
+
## 关联开发任务
|
|
282
|
+
${devTaskId}
|
|
283
|
+
|
|
284
|
+
## 测试要求
|
|
285
|
+
- 单元测试覆盖率 >= ${coverage}%
|
|
286
|
+
- 测试正常流程
|
|
287
|
+
- 测试边界情况
|
|
288
|
+
- 测试异常处理
|
|
289
|
+
|
|
290
|
+
## 测试文件
|
|
291
|
+
- 创建 \`.test.ts\` 或 \`.spec.ts\` 文件
|
|
292
|
+
- 放置在与源文件相同目录或 \`tests/\` 目录
|
|
293
|
+
|
|
294
|
+
## 输出
|
|
295
|
+
- 测试文件
|
|
296
|
+
- 测试报告
|
|
308
297
|
- 覆盖率报告`;
|
|
309
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* 构建 E2E 测试任务描述
|
|
301
|
+
*/
|
|
302
|
+
buildE2ETestDescription(e2eType, parsedTask, userContext) {
|
|
303
|
+
const typeConfig = this.getE2ETypeConfig(e2eType);
|
|
304
|
+
return `## E2E 测试目标
|
|
305
|
+
执行完整的端到端测试,验证关键用户流程
|
|
306
|
+
|
|
307
|
+
## 应用类型
|
|
308
|
+
${typeConfig.description}
|
|
309
|
+
|
|
310
|
+
## 测试框架
|
|
311
|
+
${typeConfig.frameworks.map(f => `- ${f}`).join('\n')}
|
|
312
|
+
|
|
313
|
+
## 测试范围
|
|
314
|
+
${parsedTask.goals.map((g, i) => `${i + 1}. ${g}`).join('\n')}
|
|
315
|
+
|
|
316
|
+
## 关键用户流程
|
|
317
|
+
根据应用功能,测试以下流程:
|
|
318
|
+
${this.generateUserFlows(parsedTask, e2eType)}
|
|
319
|
+
|
|
320
|
+
## 测试环境
|
|
321
|
+
${typeConfig.environments.map(e => `- ${e}`).join('\n')}
|
|
322
|
+
|
|
323
|
+
## 测试要求
|
|
324
|
+
1. **关键路径覆盖**: 所有核心用户流程必须有 E2E 测试
|
|
325
|
+
2. **断言完整**: 每个测试步骤必须有明确的断言
|
|
326
|
+
3. **等待策略**: 使用合理的等待机制,避免硬编码延迟
|
|
327
|
+
4. **数据隔离**: 测试数据独立,不影响其他测试
|
|
328
|
+
5. **清理机制**: 测试后清理创建的数据
|
|
329
|
+
|
|
330
|
+
## 输出要求
|
|
331
|
+
- E2E 测试文件 (tests/e2e/*.spec.ts)
|
|
332
|
+
- 测试执行报告
|
|
333
|
+
- 截图/录像 (失败时)
|
|
334
|
+
- 测试覆盖率报告 (如有)
|
|
335
|
+
|
|
336
|
+
## 运行命令
|
|
337
|
+
\`\`\`bash
|
|
338
|
+
${typeConfig.runCommand}
|
|
339
|
+
\`\`\`
|
|
340
|
+
|
|
341
|
+
## 验收标准
|
|
342
|
+
- [ ] 所有 E2E 测试用例通过
|
|
343
|
+
- [ ] 关键用户流程验证完成
|
|
344
|
+
- [ ] 跨浏览器/设备兼容性验证
|
|
345
|
+
- [ ] E2E 测试报告已生成
|
|
346
|
+
- [ ] 无阻塞级别的缺陷`;
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 获取 E2E 测试类型配置
|
|
350
|
+
*/
|
|
351
|
+
getE2ETypeConfig(type) {
|
|
352
|
+
const configs = {
|
|
353
|
+
web: {
|
|
354
|
+
description: 'Web 应用 (浏览器)',
|
|
355
|
+
frameworks: ['Playwright (推荐)', 'Cypress', 'Selenium WebDriver', 'Puppeteer'],
|
|
356
|
+
environments: ['Chrome', 'Firefox', 'Safari', 'Edge', 'Mobile Viewports'],
|
|
357
|
+
runCommand: 'npx playwright test --reporter=html'
|
|
358
|
+
},
|
|
359
|
+
mobile: {
|
|
360
|
+
description: '移动应用 (iOS/Android)',
|
|
361
|
+
frameworks: ['Appium', 'Detox (React Native)', 'XCUITest (iOS)', 'Espresso (Android)'],
|
|
362
|
+
environments: ['iOS Simulator', 'Android Emulator', 'Real Devices'],
|
|
363
|
+
runCommand: 'npx appium --base-path /wd/hub && npm run test:e2e'
|
|
364
|
+
},
|
|
365
|
+
gui: {
|
|
366
|
+
description: 'GUI 桌面应用 (Electron/Native)',
|
|
367
|
+
frameworks: ['Playwright for Electron', 'Spectron (Electron)', 'Robot Framework', 'PyAutoGUI'],
|
|
368
|
+
environments: ['Windows', 'macOS', 'Linux'],
|
|
369
|
+
runCommand: 'npm run test:e2e'
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
return configs[type];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* 生成用户流程测试用例
|
|
376
|
+
*/
|
|
377
|
+
generateUserFlows(parsedTask, type) {
|
|
378
|
+
const flows = [];
|
|
379
|
+
const goals = parsedTask.goals;
|
|
380
|
+
// 根据目标生成用户流程
|
|
381
|
+
goals.forEach((goal, i) => {
|
|
382
|
+
flows.push(`\n### 流程 ${i + 1}: ${goal}`);
|
|
383
|
+
flows.push('```gherkin');
|
|
384
|
+
flows.push(`Feature: ${goal}`);
|
|
385
|
+
flows.push('');
|
|
386
|
+
flows.push(' Scenario: 正常流程');
|
|
387
|
+
flows.push(` Given 用户已启动应用`);
|
|
388
|
+
flows.push(` When 用户执行 "${goal}" 操作`);
|
|
389
|
+
flows.push(` Then 操作成功完成`);
|
|
390
|
+
flows.push('```');
|
|
391
|
+
});
|
|
392
|
+
return flows.join('\n');
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* 解析覆盖率数值
|
|
396
|
+
*/
|
|
310
397
|
parseCoverage(coverageStr) {
|
|
311
398
|
const match = coverageStr.match(/(\d+)/);
|
|
312
399
|
return match ? parseInt(match[1], 10) : 60;
|
|
313
400
|
}
|
|
401
|
+
/**
|
|
402
|
+
* 生成验收标准
|
|
403
|
+
*/
|
|
314
404
|
generateAcceptanceCriteria(goal, userContext) {
|
|
315
405
|
const criteria = [
|
|
316
406
|
`功能 "${goal}" 已实现`,
|
|
@@ -318,11 +408,14 @@ ${devTaskId}
|
|
|
318
408
|
'代码符合项目规范',
|
|
319
409
|
'必要的注释已添加'
|
|
320
410
|
];
|
|
321
|
-
if (userContext.testCoverage)
|
|
411
|
+
if (userContext.testCoverage) {
|
|
322
412
|
criteria.push(`测试覆盖率 >= ${userContext.testCoverage}`);
|
|
323
|
-
|
|
413
|
+
}
|
|
414
|
+
if (userContext.techStack?.length) {
|
|
324
415
|
criteria.push(`使用指定技术栈: ${userContext.techStack.join(', ')}`);
|
|
325
|
-
|
|
416
|
+
}
|
|
417
|
+
criteria.push('无安全隐患');
|
|
418
|
+
criteria.push('边界情况已处理');
|
|
326
419
|
return criteria;
|
|
327
420
|
}
|
|
328
421
|
generateTaskId() {
|
|
@@ -331,6 +424,7 @@ ${devTaskId}
|
|
|
331
424
|
return `TASK-${timestamp}${rand}`;
|
|
332
425
|
}
|
|
333
426
|
determinePriority(goalIndex) {
|
|
427
|
+
// First goal is highest priority
|
|
334
428
|
if (goalIndex === 0)
|
|
335
429
|
return 'P1';
|
|
336
430
|
return 'P2';
|
|
@@ -13,7 +13,6 @@ export declare class StateManager {
|
|
|
13
13
|
timeout: number;
|
|
14
14
|
dependencies: string[];
|
|
15
15
|
assignedAgent: string;
|
|
16
|
-
id?: string;
|
|
17
16
|
}): Promise<Task>;
|
|
18
17
|
getTask(taskId: string): Promise<Task | null>;
|
|
19
18
|
updateTask(taskId: string, updates: Partial<Task>): Promise<void>;
|