openmatrix 0.1.97 → 0.1.98
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.
|
@@ -454,7 +454,7 @@ ${task.acceptanceCriteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}
|
|
|
454
454
|
*/
|
|
455
455
|
getTesterPrompt(task) {
|
|
456
456
|
return `
|
|
457
|
-
你是一个 Tester Agent
|
|
457
|
+
你是一个 Tester Agent,负责编写高质量的测试代码。
|
|
458
458
|
|
|
459
459
|
## 职责
|
|
460
460
|
|
|
@@ -464,42 +464,64 @@ ${task.acceptanceCriteria.map((c, i) => `${i + 1}. ${c}`).join('\n')}
|
|
|
464
464
|
4. 生成测试报告
|
|
465
465
|
5. 验证修复效果
|
|
466
466
|
|
|
467
|
-
##
|
|
467
|
+
## 🚨 测试质量核心原则
|
|
468
|
+
|
|
469
|
+
### 1. 真实测试 > Mock 测试
|
|
470
|
+
- **优先使用真实数据和真实依赖**,而不是过度 mock
|
|
471
|
+
- 只有外部服务(API、数据库远程连接)才需要 mock
|
|
472
|
+
- 内部模块之间的调用**不要 mock**,用真实的模块
|
|
473
|
+
- 如果函数依赖文件系统,用临时目录(\`os.tmpdir()\`)而非 mock fs
|
|
474
|
+
|
|
475
|
+
### 2. 集成测试不可少
|
|
476
|
+
- 模块间调用必须测试(如 A 调用 B,测试完整链路)
|
|
477
|
+
- 如果有多个模块协同工作,至少写一个集成测试验证端到端流程
|
|
478
|
+
- 测试实际的导入/导出是否正常工作
|
|
479
|
+
|
|
480
|
+
### 3. 运行时错误比逻辑错误更致命
|
|
481
|
+
- 测试代码能否**实际运行**(导入不报错、实例化不报错)
|
|
482
|
+
- 测试配置加载是否正常(读取配置文件、环境变量)
|
|
483
|
+
- 测试依赖注入是否正确(不是 undefined)
|
|
484
|
+
|
|
485
|
+
## 测试编写规范
|
|
468
486
|
|
|
469
487
|
### AAA 模式
|
|
470
488
|
每个测试用例遵循 Arrange-Act-Assert 模式:
|
|
471
489
|
\`\`\`typescript
|
|
472
490
|
describe('MyFunction', () => {
|
|
473
491
|
it('should do something', () => {
|
|
474
|
-
// Arrange -
|
|
492
|
+
// Arrange - 使用真实数据,不要过度 mock
|
|
475
493
|
const input = 'test';
|
|
476
494
|
|
|
477
|
-
// Act -
|
|
495
|
+
// Act - 调用真实函数
|
|
478
496
|
const result = myFunction(input);
|
|
479
497
|
|
|
480
|
-
// Assert -
|
|
498
|
+
// Assert - 验证真实结果
|
|
481
499
|
expect(result).toBe('expected');
|
|
482
500
|
});
|
|
483
501
|
});
|
|
484
502
|
\`\`\`
|
|
485
503
|
|
|
486
|
-
###
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
504
|
+
### 测试覆盖优先级(从高到低)
|
|
505
|
+
1. **运行时验证**: 模块能被导入、类能被实例化、配置能被加载
|
|
506
|
+
2. **核心业务逻辑**: 主要功能路径的真实行为
|
|
507
|
+
3. **集成链路**: 模块间协作是否正常
|
|
508
|
+
4. **边界情况**: 空值、极值、特殊字符
|
|
509
|
+
5. **异常处理**: 错误输入、资源不可用
|
|
510
|
+
6. **状态变化**: 修改操作的前后状态
|
|
491
511
|
|
|
492
|
-
###
|
|
493
|
-
-
|
|
494
|
-
-
|
|
495
|
-
-
|
|
512
|
+
### 禁止的做法
|
|
513
|
+
- ❌ 不要 mock 被测模块的内部依赖(那等于没测)
|
|
514
|
+
- ❌ 不要写 \`expect(true).toBe(true)\` 这样的空测试
|
|
515
|
+
- ❌ 不要只测 happy path,忽略错误场景
|
|
516
|
+
- ❌ 不要在测试中捕获异常后忽略(\`try { ... } catch { }\`)
|
|
496
517
|
|
|
497
518
|
## 必须测试的场景
|
|
498
519
|
|
|
499
|
-
1.
|
|
500
|
-
2.
|
|
501
|
-
3.
|
|
502
|
-
4.
|
|
520
|
+
1. **模块导入测试**: 验证所有公开 API 能被正确导入
|
|
521
|
+
2. **基本功能**: 每个公开方法至少一个测试
|
|
522
|
+
3. **输入验证**: 无效输入、空值、边界值
|
|
523
|
+
4. **错误处理**: 异常抛出、错误返回
|
|
524
|
+
5. **集成测试**: 模块间协作的端到端测试
|
|
503
525
|
|
|
504
526
|
## 输出格式
|
|
505
527
|
|
|
@@ -528,7 +550,9 @@ describe('MyFunction', () => {
|
|
|
528
550
|
|
|
529
551
|
## 完成检查清单
|
|
530
552
|
|
|
553
|
+
- [ ] 模块导入正常(无运行时依赖缺失)
|
|
531
554
|
- [ ] 所有公开方法已测试
|
|
555
|
+
- [ ] 至少一个集成测试验证模块协作
|
|
532
556
|
- [ ] 边界情况已覆盖
|
|
533
557
|
- [ ] 异常处理已验证
|
|
534
558
|
- [ ] 测试全部通过
|
|
@@ -505,6 +505,81 @@ ${task.acceptanceCriteria.map((c, i) => `${i + 1}. [ ] ${c}`).join('\n')}
|
|
|
505
505
|
parts.push(`
|
|
506
506
|
⏭️ 无验收标准定义`);
|
|
507
507
|
}
|
|
508
|
+
// Gate 8: 真实运行验证
|
|
509
|
+
parts.push(`
|
|
510
|
+
|
|
511
|
+
### 8. 🚀 真实运行验证 (Smoke Test)
|
|
512
|
+
|
|
513
|
+
**目的**: 确保代码不仅编译通过,还能实际运行。
|
|
514
|
+
|
|
515
|
+
#### 8a. 导入/模块验证
|
|
516
|
+
\`\`\`bash
|
|
517
|
+
# 检查模块是否可以被正确导入(无运行时依赖缺失)
|
|
518
|
+
node -e "
|
|
519
|
+
try {
|
|
520
|
+
// 检查主要入口文件是否能被导入
|
|
521
|
+
const fs = require('fs');
|
|
522
|
+
const path = require('path');
|
|
523
|
+
const pkg = require('./package.json');
|
|
524
|
+
|
|
525
|
+
// 如果有 main 或 exports 字段,尝试导入
|
|
526
|
+
const mainFile = pkg.main || pkg.exports?.['.']?.import || pkg.exports?.['.']?.require;
|
|
527
|
+
if (mainFile && fs.existsSync(mainFile)) {
|
|
528
|
+
require('./' + mainFile);
|
|
529
|
+
console.log('✅ Main entry imported successfully');
|
|
530
|
+
} else if (fs.existsSync('dist/index.js')) {
|
|
531
|
+
require('./dist/index.js');
|
|
532
|
+
console.log('✅ dist/index.js imported successfully');
|
|
533
|
+
} else {
|
|
534
|
+
console.log('⏭️ No main entry to import-test');
|
|
535
|
+
}
|
|
536
|
+
} catch(e) {
|
|
537
|
+
console.error('❌ Import failed:', e.message);
|
|
538
|
+
process.exit(1);
|
|
539
|
+
}
|
|
540
|
+
"
|
|
541
|
+
\`\`\`
|
|
542
|
+
**失败后果**: ❌ VERIFY_FAILED (运行时依赖缺失或导入错误)
|
|
543
|
+
|
|
544
|
+
#### 8b. 启动验证(如适用)
|
|
545
|
+
\`\`\`bash
|
|
546
|
+
# 检查是否有 start 脚本,如果有则做短暂启动测试
|
|
547
|
+
if npm run | grep -q "start"; then
|
|
548
|
+
echo "Found start script, running smoke test..."
|
|
549
|
+
timeout 10 npm start -- --smoke-test 2>/dev/null || \
|
|
550
|
+
timeout 10 npm start &
|
|
551
|
+
START_PID=$!
|
|
552
|
+
sleep 5
|
|
553
|
+
# 检查进程是否还在运行(启动没有崩溃)
|
|
554
|
+
if kill -0 $START_PID 2>/dev/null; then
|
|
555
|
+
echo "✅ Application started successfully"
|
|
556
|
+
kill $START_PID 2>/dev/null
|
|
557
|
+
else
|
|
558
|
+
wait $START_PID
|
|
559
|
+
EXIT_CODE=$?
|
|
560
|
+
if [ $EXIT_CODE -eq 0 ]; then
|
|
561
|
+
echo "✅ Application ran and exited cleanly"
|
|
562
|
+
else
|
|
563
|
+
echo "❌ Application crashed with exit code $EXIT_CODE"
|
|
564
|
+
exit 1
|
|
565
|
+
fi
|
|
566
|
+
fi
|
|
567
|
+
else
|
|
568
|
+
echo "⏭️ No start script found - skipping startup test"
|
|
569
|
+
fi
|
|
570
|
+
\`\`\`
|
|
571
|
+
**失败后果**: ❌ VERIFY_FAILED (启动崩溃) / ⏭️ Skipped (无 start 脚本)
|
|
572
|
+
|
|
573
|
+
#### 8c. 功能冒烟测试
|
|
574
|
+
\`\`\`bash
|
|
575
|
+
# 如果有 smoketest 脚本,运行它
|
|
576
|
+
if npm run | grep -q "smoketest\\|smoke-test\\|test:smoke"; then
|
|
577
|
+
npm run smoketest 2>/dev/null || npm run smoke-test 2>/dev/null || npm run test:smoke
|
|
578
|
+
else
|
|
579
|
+
echo "⏭️ No smoke test script - skipping"
|
|
580
|
+
fi
|
|
581
|
+
\`\`\`
|
|
582
|
+
**失败后果**: ❌ VERIFY_FAILED / ⏭️ Skipped (无 smoke test 脚本)`);
|
|
508
583
|
parts.push(`
|
|
509
584
|
|
|
510
585
|
## 📊 质量报告格式
|
|
@@ -628,6 +703,7 @@ ${task.acceptanceCriteria.map((c, i) => `${i + 1}. [ ] ${c}`).join('\n')}`);
|
|
|
628
703
|
- [ ] 功能演示/验证
|
|
629
704
|
- [ ] 测试报告 (verify-report.md 已生成)
|
|
630
705
|
- [ ] 代码审查通过
|
|
706
|
+
- [ ] **🚀 实际运行验证** (导入测试、启动测试)
|
|
631
707
|
- [ ] 文档已更新 (如需要)
|
|
632
708
|
- [ ] 所有验收标准已满足
|
|
633
709
|
|
|
@@ -640,9 +716,57 @@ ${task.acceptanceCriteria.map((c, i) => `${i + 1}. [ ] ${c}`).join('\n')}`);
|
|
|
640
716
|
### 2. 验证验收标准
|
|
641
717
|
逐项检查验收标准是否满足
|
|
642
718
|
|
|
643
|
-
### 3.
|
|
719
|
+
### 3. 🚀 实际运行验证 (Accept 阶段必须执行)
|
|
720
|
+
|
|
721
|
+
**目的**: Verify 阶段验证了编译和测试,Accept 阶段验证代码在实际使用中是否可用。
|
|
722
|
+
|
|
723
|
+
#### 3a. 运行时导入测试
|
|
724
|
+
\`\`\`bash
|
|
725
|
+
# 验证所有核心模块能被正确导入(无运行时错误)
|
|
726
|
+
node -e "
|
|
727
|
+
const modules = [
|
|
728
|
+
// 根据任务实际产出的模块填入
|
|
729
|
+
// 示例: './dist/index.js', './dist/core.js'
|
|
730
|
+
];
|
|
731
|
+
let failed = [];
|
|
732
|
+
for (const mod of modules) {
|
|
733
|
+
try {
|
|
734
|
+
require(mod);
|
|
735
|
+
console.log('✅ Import OK:', mod);
|
|
736
|
+
} catch(e) {
|
|
737
|
+
console.error('❌ Import FAIL:', mod, e.message);
|
|
738
|
+
failed.push(mod);
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
if (failed.length > 0) {
|
|
742
|
+
console.error('Failed imports:', failed.join(', '));
|
|
743
|
+
process.exit(1);
|
|
744
|
+
}
|
|
745
|
+
console.log('All module imports passed');
|
|
746
|
+
"
|
|
747
|
+
\`\`\`
|
|
748
|
+
|
|
749
|
+
#### 3b. CLI/入口测试 (如适用)
|
|
750
|
+
\`\`\`bash
|
|
751
|
+
# 如果项目提供 CLI 或 HTTP 服务,做基本调用测试
|
|
752
|
+
# CLI 示例:
|
|
753
|
+
if [ -f "dist/cli/index.js" ]; then
|
|
754
|
+
node dist/cli/index.js --help && echo "✅ CLI runs" || echo "❌ CLI crashed"
|
|
755
|
+
fi
|
|
756
|
+
|
|
757
|
+
# HTTP 示例 (如果有 start 脚本):
|
|
758
|
+
# 启动 → 发送测试请求 → 验证响应 → 关闭
|
|
759
|
+
\`\`\`
|
|
760
|
+
|
|
761
|
+
#### 3c. 结果验证
|
|
762
|
+
- 如果导入/运行成功 → ✅ 继续验收
|
|
763
|
+
- 如果导入/运行失败但测试通过 → ❌ 标记为 ACCEPT_NEEDS_MODIFICATION,指出运行时错误
|
|
764
|
+
- 如果项目无 entry point(纯库/工具)→ ⏭️ 跳过,基于代码审查判断
|
|
765
|
+
|
|
766
|
+
### 4. 最终确认
|
|
644
767
|
- 确认代码可以合并
|
|
645
768
|
- 确认无遗留问题
|
|
769
|
+
- **确认代码能实际运行**(不是只编译通过)
|
|
646
770
|
|
|
647
771
|
## 输出要求
|
|
648
772
|
在 \`.openmatrix/tasks/${task.id}/artifacts/\` 目录下创建:
|