关于 qe-iterative-loop
qe-iterative-loop 是面向 AI Agent 的质量工程技能,以可衡量目标驱动反复测试与质量改进。它涵盖测试、覆盖率、质量门禁、不稳定测试和契约验证,并提供 AQE v3 Fleet 工作模式。
主要功能
- 01迭代式测试修复
- 02提升覆盖率目标
- 03满足质量门禁
- 04稳定不稳定测试
- 05验证 API 契约
适用场景
- 01反复修复测试直至全部通过
- 02将覆盖率提升至指定目标
- 03解决部署前的质量门禁失败
- 04识别并稳定结果不一致的测试
MCP 相关
该技能介绍了通过 AQE MCP 存储和搜索质量工程迭代模式,以及检查覆盖率状态。
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ proffesor-for-testing/ agentic-qe --skill qe-iterative-loop安装后在 Claude Code 中输入/qe-iterative-loop确认已加载。
附带文件schemas/output.jsonscripts/validate-config.json
详细介绍
QE 迭代循环
概述
QE 迭代循环是 Ralph Wiggum 技术针对质量工程工作流的专门改编。它支持自主、自我修正的质量循环,让 AI Agent 持续迭代,直到达到质量目标——测试通过、满足覆盖率目标、通过质量门禁,或稳定易波动的测试。
迭代为何有益于 QE
质量工程具有客观、可衡量的成功标准:
- 测试要么通过,要么失败(退出代码为 0 或非零)
- 覆盖率可量化(78.5% 与 80% 目标)
- 质量门禁的结果是二元的(通过/失败)
- 契约验证具有明确的架构
因此,QE 非常适合采用迭代循环——我们确切知道何时完成。
先决条件
- 已初始化 AQE v3 代理群组
- 已配置测试框架(Jest、Vitest、Pytest 等)
- 覆盖率工具(c8、istanbul、coverage.py)
- 质量门禁定义
快速入门
模式 1:测试修复迭代
# Task: Fix all failing tests
/qe-loop "Run npm test and fix all failing tests.
Success: npm test exits with code 0
Output <promise>TESTS_GREEN</promise> when all tests pass."
模式 2:覆盖率目标迭代
# Task: Achieve 80% coverage
/qe-loop "Increase test coverage to 80%.
Success: Coverage report shows >= 80%
Output <promise>COVERAGE_MET</promise> when target achieved."
模式 3:质量门禁迭代
# Task: Pass all quality gates
/qe-loop "Pass all quality gates for deployment.
Gates:
- Unit tests: pass
- Integration tests: pass
- Coverage: >= 80%
- No critical vulnerabilities
- Performance < 200ms P95
Output <promise>QUALITY_GATES_PASSED</promise> when all pass."
QE 迭代模式
模式 1:测试修复迭代循环
目标:所有测试通过
## QE Test-Fix Loop
### Success Criteria
- `npm test` (or test command) returns exit code 0
- No skipped tests (unless explicitly allowed)
- No pending tests
### Iteration Steps
1. Run full test suite
2. Parse output for failures
3. Analyze first failure:
- Identify failing test file
- Understand assertion that failed
- Check if production code or test is wrong
4. Fix the issue
5. Re-run failed test file only (faster feedback)
6. If file passes, run full suite
7. If all pass -> output <promise>TESTS_GREEN</promise>
8. If failures remain -> continue to next failure
### Safety
- Max iterations: 30
- After 10 iterations: report remaining failures
- Stop if same test fails 5 times (possible design issue)
模式 2:覆盖率提升循环
目标:达到覆盖率目标
## QE Coverage Loop
### Success Criteria
- Line coverage >= {target}%
- Branch coverage >= {target - 5}% (typically lower target)
- No critical paths uncovered
### Iteration Steps
1. Run tests with coverage: `npm test -- --coverage`
2. Parse coverage report
3. If target met -> output <promise>COVERAGE_MET</promise>
4. Identify uncovered files, sorted by:
- Critical business logic (highest priority)
- Lines uncovered (most impact)
- Complexity (McCabe score)
5. Generate test for highest-impact uncovered code
6. Run tests to verify new test passes
7. Check coverage improvement
8. Continue until target met
### Intelligence Integration
- Store successful test patterns in memory
- Learn from coverage achievements
- Predict best coverage strategies
### Commands
```bash
# Check coverage status (via AQE MCP)
aqe memory get --key "coverage-status" --namespace "coverage"
# Store coverage achievement pattern (via AQE MCP)
aqe memory store \
--key "coverage-pattern-auth" \
--value '{"approach": "mock external deps", "improvement": "12%"}' \
--namespace "coverage-patterns"
### Pattern 3: Quality Gate Compliance Loop
**Goal**: Pass all quality gates
```markdown
## QE Quality Gate Loop
### Gate Definitions
| Gate | Criteria | Priority |
|------|----------|----------|
| unit-tests | All pass | P0 |
| integration-tests | All pass | P0 |
| coverage | >= 80% | P1 |
| lint | No errors | P1 |
| typecheck | No errors | P1 |
| security | No critical/high CVEs | P0 |
| performance | P95 < 200ms | P2 |
### Iteration Strategy
1. Run all gate checks
2. Identify failing gates (sorted by priority)
3. Fix highest-priority failing gate
4. Re-run that gate to verify
5. When gate passes, move to next failing gate
6. When all pass -> output <promise>QUALITY_GATES_PASSED</promise>
### Gate Check Commands
```bash
# Check all gates
npm test && npm run lint && npm run typecheck && npm run coverage && npm audit
# Individual gate checks
npm test # unit-tests
npm run test:integration # integration-tests
npm run coverage # coverage
npm run lint # lint
npx tsc --noEmit # typecheck
npm audit --audit-level=high # security
npm run benchmark # performance
与 AQE v3 集成
# Submit quality gate assessment task
aqe quality --runGate true
# Task orchestration for gate compliance
aqe task submit --task "Pass all quality gates" --strategy adaptive
### Pattern 4: Flaky Test Stabilization Loop
**Goal**: Eliminate test flakiness
```markdown
## QE Flaky Test Loop
### Flakiness Detection
1. Run test suite N times (e.g., 5 runs)
2. Identify tests that pass/fail inconsistently
3. Calculate flakiness score: (inconsistent runs / total runs)
### Iteration Steps
1. Run: `for i in {1..5}; do npm test; done`
2. Aggregate results per test
3. Identify flaky tests (passed some, failed some)
4. For each flaky test:
- Analyze failure modes
- Common causes:
- Timing issues (add retries/waits)
- Shared state (isolate test data)
- Network calls (mock external services)
- Random data (use deterministic seeds)
- Apply appropriate fix
- Re-run 5 times to verify stability
5. When all tests stable -> output <promise>TESTS_STABLE</promise>
### AQE v3 Flaky Detection
```bash
# Use qe-flaky-hunter agent
Task("Hunt flaky tests", "Detect and stabilize flaky tests", "qe-flaky-hunter")
# Or submit flaky detection task
aqe task submit --type "flaky-detection" --priority "p1"
### Pattern 5: Contract Validation Loop
**Goal**: API contracts aligned
```markdown
## QE Contract Loop
### Success Criteria
- Provider implements all consumer contracts
- No breaking changes detected
- Schema validation passes
### Iteration Steps
1. Run contract tests: `npm run test:contracts`
2. Parse contract violations
3. For each violation:
- Determine if provider or consumer needs update
- Update appropriate side
- Re-run contract tests
4. When all contracts valid -> output <promise>CONTRACTS_VALID</promise>
### AQE v3 Integration
```bash
# Validate contracts
aqe test contract --contractPath "./contracts"
# Or use specialized agent
Task("Validate API contracts", "Check consumer-provider alignment", "qe-contract-validator")
---
## AQE v3 Fleet Integration
### Spawning QE Iteration Agents
```bash
# Initialize AQE fleet for QE iteration
aqe fleet init --topology "hierarchical" --maxAgents 8
# Spawn specialized QE iterators using Task tool
Task("Fix failing tests", "Iterate until all tests pass", "qe-tdd-green", {run_in_background: true})
Task("Improve coverage", "Iterate until 80% coverage", "qe-coverage-analyzer", {run_in_background: true})
Task("Fix security issues", "Iterate until security scan passes", "qe-security-scanner", {run_in_background: true})
Task("Stabilize flaky tests", "Iterate until tests stable", "qe-flaky-hunter", {run_in_background: true})
由记忆增强的 QE 迭代
# Store iteration patterns for learning (via AQE MCP)
aqe memory store \
--key "qe-iteration-test-fix" \
--value '{"approach": "mock external deps", "success_rate": 0.85}' \
--namespace "qe-patterns"
# Search for relevant QE patterns (via AQE MCP)
aqe memory search \
--pattern "test-fix-*" \
--namespace "qe-patterns"
# Record successful iteration completion (via AQE task tracking)
aqe task status --taskId "test-fix-iteration"
QE 专用 Agent 路由
| QE 任务 | 推荐 Agent | 迭代目标 |
|---|---|---|
| 测试修复 | qe-tdd-green | 所有测试通过 |
| 覆盖率缺口 | qe-coverage-analyzer | 达到覆盖率目标 |
| 质量门禁 | qe-quality-gate | 所有门禁通过 |
| 易波动的测试 | qe-flaky-hunter | 测试稳定 |
| 契约验证 | qe-contract-validator | 契约一致 |
| 安全修复 | qe-security-scanner | 无漏洞 |
| 性能 | qe-performance-validator | 基准测试通过 |
QE 完成承诺
标准 QE 承诺
# Test-related
<promise>TESTS_GREEN</promise> # All tests pass
<promise>TESTS_STABLE</promise> # Flaky tests fixed
<promise>TDD_COMPLETE</promise> # TDD cycle done
# Coverage-related
<promise>COVERAGE_MET</promise> # Target coverage achieved
<promise>GAPS_FILLED</promise> # Coverage gaps addressed
# Quality gates
<promise>QUALITY_GATES_PASSED</promise> # All gates pass
<promise>DEPLOYMENT_READY</promise> # Ready for deploy
# Contract/API
<promise>CONTRACTS_VALID</promise> # Contracts aligned
<promise>API_COMPLIANT</promise> # API matches spec
# Security
<promise>SECURITY_CLEARED</promise> # No vulnerabilities
<promise>COMPLIANCE_MET</promise> # Compliance requirements met
# Performance
<promise>PERF_TARGET_MET</promise> # Benchmarks satisfied
示例:完整 QE 迭代工作流
## Complete QE Iteration Task
### Objective
Achieve deployment readiness through iterative quality improvement
### Phase 1: Test Health (Priority)
1. Run `npm test`
2. Fix failing tests iteratively
3. Success: <promise>TESTS_GREEN</promise>
### Phase 2: Coverage (After Phase 1)
1. Run `npm test -- --coverage`
2. Write tests for uncovered critical paths
3. Success: Coverage >= 80% -> <promise>COVERAGE_MET</promise>
### Phase 3: Quality Gates (After Phase 2)
1. Run lint: `npm run lint`
2. Run typecheck: `npx tsc --noEmit`
3. Fix any violations
4. Success: <promise>LINT_PASS</promise> + <promise>TYPES_PASS</promise>
### Phase 4: Security (Parallel with Phase 3)
1. Run `npm audit`
2. Fix critical/high vulnerabilities
3. Success: <promise>SECURITY_CLEARED</promise>
### Phase 5: Integration
1. Run `npm run test:integration`
2. Fix any integration failures
3. Success: <promise>INTEGRATION_PASS</promise>
### Final Gate
When ALL phases complete -> <promise>DEPLOYMENT_READY</promise>
### Safety Limits
- Max iterations per phase: 15
- Total max iterations: 50
- Stuck detection: 5 iterations without progress triggers escalation
故障排除
问题:测试总是在同一断言处失败
原因:可能是设计问题,而非实现错误
解决方案:
- 同一测试尝试 5 次后停止迭代
- 分析测试预期是否正确
- 检查生产环境行为是否符合设计
- 如不明确,则升级至人工审查
问题:覆盖率停滞不前
原因:剩余未覆盖代码较复杂/包含条件逻辑
解决方案:
- 找出未覆盖的分支(而不仅是代码行)
- 生成边界情况测试
- 考虑未覆盖代码是否为死代码
- 对确实无法测试的代码,接受较低的目标
问题:易波动的测试始终无法稳定
原因:深层的时序或状态问题
解决方案:
- 添加明确的等待/重试
- 模拟依赖时间的行为
- 隔离测试环境
- 考虑将其标记为跳过,并附上说明
相关技能
- 迭代循环 - 通用迭代技术
- qe-test-generation - AI 驱动的测试创建
- qe-coverage-analysis - 覆盖率缺口检测
- qe-quality-assessment - 质量门禁管理
- qe-chaos-resilience - 韧性迭代测试
资源
- AQE v3 文档 - 完整的 v3 参考资料
- Ralph Wiggum 技术 - 原始方法
- Agentic QE MCP 工具 - MCP 工具参考
来源:改编自 Ralph Wiggum 插件(anthropics/claude-code) 专为以下对象定制:包含 60 个 QE Agent 的 Agentic QE v3 代理群组 领域:test-generation、test-execution、coverage-analysis、quality-assessment
评论
支持 Markdown