openmatrix 0.2.24 → 0.2.25

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.
@@ -143,10 +143,25 @@ function generateTestContent(source, config) {
143
143
  // 导入语句
144
144
  const importPath = source.path.replace(/\.(ts|tsx)$/, '').replace(/\.(js|jsx)$/, '');
145
145
  const imports = generateImports(source.exports, importPath, usesTypeScript);
146
+ // 需要生命周期钩子的文件类型
147
+ const needsLifecycle = ['service', 'util', 'api', 'module'].includes(source.fileType);
148
+ // 需要 vi 导入的测试类型(使用 Mock 验证副作用)
149
+ const needsViImport = ['service', 'util', 'api', 'component', 'module'].includes(source.fileType);
146
150
  // 测试块
147
151
  const testBlocks = source.exports.map(exp => generateTestBlock(exp, framework, usesDescribeIt, source.fileType));
148
152
  // 组装内容
149
- const content = `${imports}\n\n${testBlocks.join('\n\n')}\n`;
153
+ const content = `${needsViImport ? `import { vi } from 'vitest';\n` : ''}${imports}
154
+ ${needsLifecycle ? `
155
+ beforeEach(() => {
156
+ vi.clearAllMocks();
157
+ });
158
+
159
+ afterEach(() => {
160
+ vi.restoreAllMocks();
161
+ });
162
+ ` : ''}
163
+ ${testBlocks.join('\n\n')}
164
+ `;
150
165
  return content;
151
166
  }
152
167
  /**
@@ -193,13 +208,15 @@ function generateBusinessTestCases(exportName, fileType) {
193
208
  name: 'should return valid result on successful execution',
194
209
  arrange: `// Arrange - 准备有效的输入参数
195
210
  const params = { id: 'test-id', data: {} };
196
- const mockDependencies = {};`,
211
+ const spy = vi.spyOn({ ${exportName} }, '${exportName}');`,
197
212
  act: `// Act - 执行服务方法
198
213
  const result = await ${exportName}(params);`,
199
214
  assert: [
200
215
  'expect(result).toBeDefined();',
201
216
  'expect(result).toHaveProperty(\'data\');',
202
- 'expect(result.error).toBeUndefined();'
217
+ 'expect(result.error).toBeUndefined();',
218
+ `expect(spy).toHaveBeenCalledWith(params);`,
219
+ 'expect(spy).toHaveBeenCalledTimes(1);'
203
220
  ]
204
221
  },
205
222
  {
@@ -239,12 +256,15 @@ function generateBusinessTestCases(exportName, fileType) {
239
256
  name: 'should process valid input correctly',
240
257
  arrange: `// Arrange - 准备有效输入
241
258
  const input = 'test-value';
242
- const expected = 'expected-result';`,
259
+ const expected = 'expected-result';
260
+ const spy = vi.spyOn({ ${exportName} }, '${exportName}');`,
243
261
  act: `// Act
244
262
  const result = ${exportName}(input);`,
245
263
  assert: [
246
264
  'expect(result).toBeDefined();',
247
- 'expect(typeof result).toBe(\'string\');'
265
+ 'expect(typeof result).toBe(\'string\');',
266
+ `expect(spy).toHaveBeenCalledWith(input);`,
267
+ 'expect(spy).toHaveBeenCalledTimes(1);'
248
268
  ]
249
269
  },
250
270
  {
@@ -333,19 +353,25 @@ function generateBusinessTestCases(exportName, fileType) {
333
353
  {
334
354
  name: 'should return success response for valid request',
335
355
  arrange: `// Arrange - 准备有效的 API 请求参数
336
- const request = { method: \'GET\', path: \'/api/test\' };`,
356
+ const request = { method: \'GET\', path: \'/api/test\' };
357
+ const mockResponse = { status: 200, data: { id: 1 } };
358
+ const spy = vi.spyOn({ ${exportName} }, '${exportName}').mockResolvedValue(mockResponse);`,
337
359
  act: `// Act - 执行 API 调用
338
360
  const response = await ${exportName}(request);`,
339
361
  assert: [
340
362
  'expect(response).toBeDefined();',
341
363
  'expect(response.status).toBe(200);',
342
- 'expect(response.data).toBeDefined();'
364
+ 'expect(response.data).toBeDefined();',
365
+ `expect(spy).toHaveBeenCalledWith(request);`,
366
+ 'expect(spy).toHaveBeenCalledTimes(1);'
343
367
  ]
344
368
  },
345
369
  {
346
370
  name: 'should handle 404 not found',
347
371
  arrange: `// Arrange - 准备不存在的资源请求
348
- const request = { method: \'GET\', path: \'/api/nonexistent\' };`,
372
+ const request = { method: \'GET\', path: \'/api/nonexistent\' };
373
+ const mockResponse = { status: 404, error: \'Not Found\' };
374
+ vi.spyOn({ ${exportName} }, '${exportName}').mockResolvedValue(mockResponse);`,
349
375
  act: `// Act - 请求不存在的资源
350
376
  const response = await ${exportName}(request);`,
351
377
  assert: [
@@ -356,7 +382,9 @@ function generateBusinessTestCases(exportName, fileType) {
356
382
  {
357
383
  name: 'should handle invalid request body',
358
384
  arrange: `// Arrange - 准备无效的请求体
359
- const request = { method: \'POST\', path: \'/api/test\', body: null };`,
385
+ const request = { method: \'POST\', path: \'/api/test\', body: null };
386
+ const mockResponse = { status: 400, error: \'invalid request\' };
387
+ vi.spyOn({ ${exportName} }, '${exportName}').mockResolvedValue(mockResponse);`,
360
388
  act: `// Act - 发送无效请求
361
389
  const response = await ${exportName}(request);`,
362
390
  assert: [
@@ -368,10 +396,10 @@ function generateBusinessTestCases(exportName, fileType) {
368
396
  name: 'should handle network errors gracefully',
369
397
  arrange: `// Arrange - 模拟网络错误
370
398
  const request = { method: \'GET\', path: \'/api/error\' };
371
- // Mock network failure`,
399
+ vi.spyOn({ ${exportName} }, '${exportName}').mockRejectedValue(new Error('Network Error'));`,
372
400
  act: `// Act - 处理错误响应`,
373
401
  assert: [
374
- `await expect(${exportName}(request)).resolves.toBeDefined();`,
402
+ `await expect(${exportName}(request)).rejects.toThrow('Network Error');`,
375
403
  '// 应该返回错误对象而非抛出异常'
376
404
  ]
377
405
  }
@@ -228,8 +228,10 @@ export interface ParsedTask {
228
228
  title: string;
229
229
  description: string;
230
230
  goals: string[];
231
- /** 每个 goal 的类型标注 (AI 在提取时标注),与 goals 数组一一对应 */
231
+ /** 每个 goal 的类型标注 (AI 必填),与 goals 数组一一对应 */
232
232
  goalTypes?: GoalType[];
233
+ /** 每个 goal 的复杂度标注 (AI 必填),与 goals 数组一一对应 */
234
+ goalComplexity?: ('low' | 'medium' | 'high')[];
233
235
  constraints: string[];
234
236
  deliverables: string[];
235
237
  rawContent: string;
package/package.json CHANGED
@@ -1,61 +1,61 @@
1
- {
2
- "name": "openmatrix",
3
- "version": "0.2.24",
4
- "description": "AI Agent task orchestration system with Claude Code Skills integration",
5
- "main": "dist/index.js",
6
- "types": "dist/index.d.ts",
7
- "bin": {
8
- "openmatrix": "dist/cli/index.js"
9
- },
10
- "files": [
11
- "dist",
12
- "skills",
13
- "scripts",
14
- "README.md"
15
- ],
16
- "scripts": {
17
- "build": "tsc",
18
- "dev": "tsx src/cli/index.ts",
19
- "test": "vitest",
20
- "lint": "eslint src --ext .ts",
21
- "typecheck": "tsc --noEmit",
22
- "postinstall": "node scripts/install-skills.js"
23
- },
24
- "keywords": [
25
- "claude",
26
- "claude-code",
27
- "ai-agent",
28
- "task-orchestration",
29
- "automation",
30
- "multi-agent"
31
- ],
32
- "author": "",
33
- "license": "MIT",
34
- "type": "commonjs",
35
- "repository": {
36
- "type": "git",
37
- "url": "git+https://github.com/bigfish1913/openmatrix.git"
38
- },
39
- "homepage": "https://github.com/bigfish1913/openmatrix#readme",
40
- "bugs": {
41
- "url": "https://github.com/bigfish1913/openmatrix/issues"
42
- },
43
- "dependencies": {
44
- "chalk": "^5.6.2",
45
- "chokidar": "^5.0.0",
46
- "commander": "^14.0.3",
47
- "winston": "^3.19.0"
48
- },
49
- "devDependencies": {
50
- "@types/node": "^22.0.0",
51
- "@typescript-eslint/eslint-plugin": "^8.58.1",
52
- "@typescript-eslint/parser": "^8.58.1",
53
- "@vitest/coverage-v8": "^1.6.1",
54
- "eslint": "^10.2.0",
55
- "typescript": "^5.3.3",
56
- "vitest": "^1.6.0"
57
- },
58
- "engines": {
59
- "node": ">=18.0.0"
60
- }
61
- }
1
+ {
2
+ "name": "openmatrix",
3
+ "version": "0.2.25",
4
+ "description": "AI Agent task orchestration system with Claude Code Skills integration",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "bin": {
8
+ "openmatrix": "dist/cli/index.js"
9
+ },
10
+ "files": [
11
+ "dist",
12
+ "skills",
13
+ "scripts",
14
+ "README.md"
15
+ ],
16
+ "scripts": {
17
+ "build": "tsc",
18
+ "dev": "tsx src/cli/index.ts",
19
+ "test": "vitest",
20
+ "lint": "eslint src --ext .ts",
21
+ "typecheck": "tsc --noEmit",
22
+ "postinstall": "node scripts/install-skills.js"
23
+ },
24
+ "keywords": [
25
+ "claude",
26
+ "claude-code",
27
+ "ai-agent",
28
+ "task-orchestration",
29
+ "automation",
30
+ "multi-agent"
31
+ ],
32
+ "author": "",
33
+ "license": "MIT",
34
+ "type": "commonjs",
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "git+https://github.com/bigfish1913/openmatrix.git"
38
+ },
39
+ "homepage": "https://github.com/bigfish1913/openmatrix#readme",
40
+ "bugs": {
41
+ "url": "https://github.com/bigfish1913/openmatrix/issues"
42
+ },
43
+ "dependencies": {
44
+ "chalk": "^5.6.2",
45
+ "chokidar": "^5.0.0",
46
+ "commander": "^14.0.3",
47
+ "winston": "^3.19.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^22.0.0",
51
+ "@typescript-eslint/eslint-plugin": "^8.58.1",
52
+ "@typescript-eslint/parser": "^8.58.1",
53
+ "@vitest/coverage-v8": "^1.6.1",
54
+ "eslint": "^10.2.0",
55
+ "typescript": "^5.3.3",
56
+ "vitest": "^1.6.0"
57
+ },
58
+ "engines": {
59
+ "node": ">=18.0.0"
60
+ }
61
+ }