mcp-probe-kit 3.6.9 → 3.6.11
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 +13 -7
- package/build/index.js +16 -13
- package/build/lib/__tests__/gitnexus-bridge.unit.test.js +28 -1
- package/build/lib/__tests__/src8-guidance.unit.test.d.ts +1 -0
- package/build/lib/__tests__/src8-guidance.unit.test.js +62 -0
- package/build/lib/__tests__/task-defaults.unit.test.js +16 -2
- package/build/lib/code-review-input.d.ts +15 -0
- package/build/lib/code-review-input.js +47 -0
- package/build/lib/gitnexus-bridge.d.ts +1 -0
- package/build/lib/gitnexus-bridge.js +15 -6
- package/build/lib/src8-guidance.d.ts +178 -0
- package/build/lib/src8-guidance.js +633 -0
- package/build/lib/task-defaults.d.ts +2 -1
- package/build/lib/task-defaults.js +7 -4
- package/build/lib/tbp8-guidance.d.ts +4 -0
- package/build/lib/tbp8-guidance.js +4 -0
- package/build/schemas/code-analysis-tools.d.ts +49 -5
- package/build/schemas/code-analysis-tools.js +49 -5
- package/build/schemas/code-gen-tools.d.ts +9 -1
- package/build/schemas/code-gen-tools.js +9 -1
- package/build/schemas/index.d.ts +65 -9
- package/build/schemas/orchestration-tools.d.ts +7 -3
- package/build/schemas/orchestration-tools.js +7 -3
- package/build/schemas/output/core-tools.d.ts +238 -13
- package/build/schemas/output/core-tools.js +63 -13
- package/build/schemas/structured-output.d.ts +26 -8
- package/build/schemas/structured-output.js +17 -7
- package/build/tools/__tests__/code_review.unit.test.d.ts +1 -0
- package/build/tools/__tests__/code_review.unit.test.js +43 -0
- package/build/tools/__tests__/fix_bug.unit.test.js +54 -17
- package/build/tools/__tests__/gentest.unit.test.d.ts +1 -0
- package/build/tools/__tests__/gentest.unit.test.js +40 -0
- package/build/tools/__tests__/refactor.unit.test.d.ts +1 -0
- package/build/tools/__tests__/refactor.unit.test.js +40 -0
- package/build/tools/__tests__/start_bugfix.unit.test.js +31 -18
- package/build/tools/code_review.js +149 -164
- package/build/tools/fix_bug.d.ts +1 -9
- package/build/tools/fix_bug.js +137 -289
- package/build/tools/gentest.js +149 -186
- package/build/tools/refactor.js +132 -360
- package/build/tools/start_bugfix.js +258 -344
- package/package.json +1 -1
package/build/tools/gentest.js
CHANGED
|
@@ -1,209 +1,172 @@
|
|
|
1
1
|
import { parseArgs, getString } from "../utils/parseArgs.js";
|
|
2
|
-
import {
|
|
2
|
+
import { okStructured } from "../lib/response.js";
|
|
3
3
|
import { renderGuidanceHeader } from "../lib/guidance.js";
|
|
4
4
|
import { handleToolError } from "../utils/error-handler.js";
|
|
5
|
-
|
|
5
|
+
import { resolveGuidanceCode, trimCodeForPrompt } from "../lib/code-review-input.js";
|
|
6
|
+
import { resolveWorkspaceRoot } from "../lib/workspace-root.js";
|
|
6
7
|
export async function gentest(args) {
|
|
7
8
|
try {
|
|
8
|
-
// 智能参数解析,支持自然语言输入
|
|
9
9
|
const parsedArgs = parseArgs(args, {
|
|
10
10
|
defaultValues: {
|
|
11
11
|
code: "",
|
|
12
12
|
framework: "jest",
|
|
13
|
+
file_path: "",
|
|
14
|
+
project_root: "",
|
|
13
15
|
},
|
|
14
|
-
primaryField: "code",
|
|
16
|
+
primaryField: "code",
|
|
15
17
|
fieldAliases: {
|
|
16
18
|
code: ["source", "src", "代码", "function"],
|
|
17
19
|
framework: ["test_framework", "lib", "框架", "测试框架"],
|
|
20
|
+
file_path: ["filePath", "filepath", "path", "文件路径"],
|
|
21
|
+
project_root: ["projectRoot", "project_path", "dir", "directory", "项目路径"],
|
|
18
22
|
},
|
|
19
23
|
});
|
|
20
|
-
const
|
|
21
|
-
const
|
|
24
|
+
const framework = getString(parsedArgs.framework) || "jest";
|
|
25
|
+
const inlineCode = getString(parsedArgs.code) || getString(parsedArgs.input);
|
|
26
|
+
const filePath = getString(parsedArgs.file_path);
|
|
27
|
+
const projectRoot = getString(parsedArgs.project_root);
|
|
28
|
+
const resolved = resolveGuidanceCode({
|
|
29
|
+
code: inlineCode,
|
|
30
|
+
filePath: filePath || undefined,
|
|
31
|
+
projectRoot: projectRoot ? resolveWorkspaceRoot(projectRoot) : undefined,
|
|
32
|
+
});
|
|
33
|
+
if (resolved.error) {
|
|
34
|
+
return okStructured(`❌ gentest 无法读取输入: ${resolved.error}`, {
|
|
35
|
+
mode: "guidance",
|
|
36
|
+
gentestInput: {
|
|
37
|
+
received: false,
|
|
38
|
+
error: resolved.error,
|
|
39
|
+
file: filePath || null,
|
|
40
|
+
framework,
|
|
41
|
+
},
|
|
42
|
+
}, {
|
|
43
|
+
note: "指南型工具:请修正 file_path / project_root 或传入 code 后,由 Agent 生成完整测试代码",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const hasCode = Boolean(resolved.code.trim());
|
|
47
|
+
const promptCode = hasCode ? trimCodeForPrompt(resolved.code, 24000, "gentestInput") : "";
|
|
22
48
|
const header = renderGuidanceHeader({
|
|
23
49
|
tool: "gentest",
|
|
24
|
-
goal: "
|
|
25
|
-
tasks: [
|
|
26
|
-
|
|
50
|
+
goal: "由 Agent 根据下方代码与测试清单生成完整可运行的测试用例。",
|
|
51
|
+
tasks: [
|
|
52
|
+
"先阅读本次注入的 gentestInput.code(或 file_path 对应文件)",
|
|
53
|
+
"按测试策略覆盖正常、边界与异常场景",
|
|
54
|
+
"在回复中直接输出完整测试代码文件",
|
|
55
|
+
],
|
|
56
|
+
outputs: [`${framework} 测试代码(含边界与异常用例)— 由 Agent 生成,非 MCP 自动生成`],
|
|
57
|
+
notes: [
|
|
58
|
+
"本工具为指南型(guidance-only),不在服务端生成或运行测试",
|
|
59
|
+
hasCode ? `已注入待测代码(${resolved.code.split("\n").length} 行)` : "未收到 code/file_path,请先提供待测内容",
|
|
60
|
+
],
|
|
27
61
|
});
|
|
28
|
-
const message = `${header}请为以下代码生成完整的测试用例:
|
|
29
|
-
|
|
30
|
-
📝
|
|
31
|
-
${code
|
|
32
|
-
|
|
33
|
-
🧪 **测试框架**:${framework}
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
## 测试用例生成指南
|
|
38
|
-
|
|
39
|
-
### 1️⃣ 测试策略
|
|
40
|
-
|
|
41
|
-
**测试类型**:
|
|
42
|
-
- **单元测试**:测试单个函数/方法
|
|
43
|
-
- **集成测试**:测试模块间交互
|
|
44
|
-
- **边界测试**:测试极端情况
|
|
45
|
-
- **异常测试**:测试错误处理
|
|
46
|
-
|
|
47
|
-
**覆盖维度**:
|
|
48
|
-
- ✅ 正常情况(Happy Path)
|
|
49
|
-
- ✅ 边界条件(Boundary Conditions)
|
|
50
|
-
- ✅ 异常情况(Error Cases)
|
|
51
|
-
- ✅ 空值/特殊值(Null/Special Values)
|
|
52
|
-
|
|
53
|
-
### 2️⃣ 测试用例模板
|
|
54
|
-
|
|
55
|
-
**测试结构(AAA 模式)**:
|
|
56
|
-
\`\`\`typescript
|
|
57
|
-
describe('函数/模块名称', () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
//
|
|
64
|
-
const
|
|
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
|
-
id: 1,
|
|
134
|
-
name: 'Test User',
|
|
135
|
-
email: 'test@example.com',
|
|
136
|
-
...overrides
|
|
137
|
-
});
|
|
138
|
-
\`\`\`
|
|
139
|
-
|
|
140
|
-
---
|
|
141
|
-
|
|
142
|
-
## 测试文件命名规范
|
|
143
|
-
|
|
144
|
-
- **单元测试**:\`functionName.test.ts\` 或 \`functionName.spec.ts\`
|
|
145
|
-
- **集成测试**:\`moduleName.integration.test.ts\`
|
|
146
|
-
- **E2E 测试**:\`feature.e2e.test.ts\`
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
---
|
|
151
|
-
|
|
152
|
-
## ⚠️ 边界约束
|
|
153
|
-
|
|
154
|
-
- ❌ 仅输出测试代码,不自动运行测试
|
|
155
|
-
- ❌ 不修改被测试的源代码
|
|
156
|
-
- ✅ 默认跟随项目现有测试框架与语言
|
|
157
|
-
- ✅ 输出完整可运行的测试文件
|
|
158
|
-
|
|
159
|
-
现在请生成完整的测试代码,包括:
|
|
160
|
-
1. describe 块组织
|
|
161
|
-
2. 所有必要的测试用例
|
|
162
|
-
3. Mock/Stub 设置
|
|
163
|
-
4. 测试数据准备
|
|
164
|
-
5. 清晰的注释说明
|
|
165
|
-
|
|
166
|
-
---
|
|
167
|
-
|
|
168
|
-
## 📤 输出格式要求
|
|
169
|
-
|
|
170
|
-
请直接输出完整的测试代码文件,包含:
|
|
171
|
-
- import 语句(测试框架和被测试代码)
|
|
172
|
-
- describe 块(测试套件)
|
|
173
|
-
- 多个 test/it 块(各种测试用例)
|
|
174
|
-
- 必要的 mock 和 setup/teardown
|
|
175
|
-
|
|
176
|
-
**示例输出**:
|
|
177
|
-
\`\`\`typescript
|
|
178
|
-
import { functionUnderTest } from '../src/module';
|
|
179
|
-
|
|
180
|
-
describe('functionUnderTest', () => {
|
|
181
|
-
test('应该正常处理有效输入', () => {
|
|
182
|
-
const result = functionUnderTest('valid input');
|
|
183
|
-
expect(result).toBe('expected output');
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
test('应该处理边界情况:空字符串', () => {
|
|
187
|
-
const result = functionUnderTest('');
|
|
188
|
-
expect(result).toBe('');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
test('应该抛出错误:无效输入', () => {
|
|
192
|
-
expect(() => functionUnderTest(null)).toThrow('Invalid input');
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
\`\`\`
|
|
196
|
-
|
|
197
|
-
💡 **提示**:
|
|
198
|
-
- 确保测试代码可以直接运行
|
|
199
|
-
- 包含必要的类型声明(如果使用 TypeScript)
|
|
200
|
-
- 添加适当的注释说明测试意图`;
|
|
201
|
-
return okText(message, {
|
|
202
|
-
schema: (await import('../schemas/output/core-tools.js')).TestSuiteSchema,
|
|
203
|
-
note: "本工具返回测试生成指南,AI 应根据指南和代码生成完整的测试文件"
|
|
62
|
+
const message = `${header}请为以下代码生成完整的测试用例:
|
|
63
|
+
|
|
64
|
+
📝 **待测代码**${resolved.file ? `(来源: ${resolved.file})` : ""}:
|
|
65
|
+
${hasCode ? `\`\`\`\n${promptCode}\n\`\`\`` : "_未提供 code / file_path,请 Agent 先读取目标文件或让用户补充后再生成测试_"}
|
|
66
|
+
|
|
67
|
+
🧪 **测试框架**:${framework}
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## 测试用例生成指南
|
|
72
|
+
|
|
73
|
+
### 1️⃣ 测试策略
|
|
74
|
+
|
|
75
|
+
**测试类型**:
|
|
76
|
+
- **单元测试**:测试单个函数/方法
|
|
77
|
+
- **集成测试**:测试模块间交互
|
|
78
|
+
- **边界测试**:测试极端情况
|
|
79
|
+
- **异常测试**:测试错误处理
|
|
80
|
+
|
|
81
|
+
**覆盖维度**:
|
|
82
|
+
- ✅ 正常情况(Happy Path)
|
|
83
|
+
- ✅ 边界条件(Boundary Conditions)
|
|
84
|
+
- ✅ 异常情况(Error Cases)
|
|
85
|
+
- ✅ 空值/特殊值(Null/Special Values)
|
|
86
|
+
|
|
87
|
+
### 2️⃣ 测试用例模板
|
|
88
|
+
|
|
89
|
+
**测试结构(AAA 模式)**:
|
|
90
|
+
\`\`\`typescript
|
|
91
|
+
describe('函数/模块名称', () => {
|
|
92
|
+
test('描述测试场景', () => {
|
|
93
|
+
// Arrange
|
|
94
|
+
const input = ...;
|
|
95
|
+
const expected = ...;
|
|
96
|
+
|
|
97
|
+
// Act
|
|
98
|
+
const result = functionUnderTest(input);
|
|
99
|
+
|
|
100
|
+
// Assert
|
|
101
|
+
expect(result).toBe(expected);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
\`\`\`
|
|
105
|
+
|
|
106
|
+
### 3️⃣ 测试用例清单
|
|
107
|
+
|
|
108
|
+
**正常情况测试**:
|
|
109
|
+
- [ ] 基本功能正常工作
|
|
110
|
+
- [ ] 返回值类型正确
|
|
111
|
+
- [ ] 副作用符合预期
|
|
112
|
+
|
|
113
|
+
**边界条件测试**:
|
|
114
|
+
- [ ] 空输入(null, undefined, "", [], {})
|
|
115
|
+
- [ ] 最小值/最大值
|
|
116
|
+
- [ ] 边界临界值
|
|
117
|
+
|
|
118
|
+
**异常情况测试**:
|
|
119
|
+
- [ ] 无效输入
|
|
120
|
+
- [ ] 类型错误
|
|
121
|
+
- [ ] 超出范围
|
|
122
|
+
- [ ] 异常抛出正确
|
|
123
|
+
|
|
124
|
+
### 4️⃣ Mock 和 Stub
|
|
125
|
+
|
|
126
|
+
**需要 Mock 的场景**:API 调用、数据库、文件系统、时间、随机数、外部依赖
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 测试文件命名规范
|
|
131
|
+
|
|
132
|
+
- **单元测试**:\`functionName.test.ts\` 或 \`functionName.spec.ts\`
|
|
133
|
+
- **集成测试**:\`moduleName.integration.test.ts\`
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## ⚠️ 边界约束
|
|
138
|
+
|
|
139
|
+
- MCP 仅返回指南 + 注入的待测代码,**测试代码由 Agent 生成**
|
|
140
|
+
- ❌ 不自动运行测试,不修改被测试的源代码
|
|
141
|
+
- ✅ 默认跟随项目现有测试框架与语言
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## 📤 Agent 必须输出的内容
|
|
146
|
+
|
|
147
|
+
请直接输出完整的测试代码文件,包含:
|
|
148
|
+
- import 语句(测试框架和被测试代码)
|
|
149
|
+
- describe 块(测试套件)
|
|
150
|
+
- 多个 test/it 块(各种测试用例)
|
|
151
|
+
- 必要的 mock 和 setup/teardown
|
|
152
|
+
|
|
153
|
+
现在请生成完整的测试代码。`;
|
|
154
|
+
return okStructured(message, {
|
|
155
|
+
mode: "guidance",
|
|
156
|
+
gentestInput: {
|
|
157
|
+
received: hasCode,
|
|
158
|
+
framework,
|
|
159
|
+
file: resolved.file ?? null,
|
|
160
|
+
lineCount: hasCode ? resolved.code.split("\n").length : 0,
|
|
161
|
+
code: hasCode ? resolved.code : null,
|
|
162
|
+
truncatedInPrompt: hasCode && resolved.code.length !== promptCode.length,
|
|
163
|
+
},
|
|
164
|
+
}, {
|
|
165
|
+
schema: (await import("../schemas/output/core-tools.js")).TestSuiteSchema,
|
|
166
|
+
note: "指南型工具:测试代码须由 Agent 按清单生成;MCP 不返回自动生成的测试文件",
|
|
204
167
|
});
|
|
205
168
|
}
|
|
206
169
|
catch (error) {
|
|
207
|
-
return handleToolError(error,
|
|
170
|
+
return handleToolError(error, "gentest");
|
|
208
171
|
}
|
|
209
172
|
}
|