概述
verification-loop 是一个六阶段质量门禁技能,用于按顺序验证代码变更。每个阶段必须通过后才会进入下一阶段。它会自动检测项目类型并适配相应命令。
适用场景
- 提交变更之前
- 合并前校验
- CI/CD 流水线集成
- 代码评审准备
阶段定义
阶段 1:构建
| 项目 |
命令 |
跳过条件 |
| Node.js |
npm run build |
package.json 中无 build 脚本 |
| Python |
uv build / python -m build |
无 pyproject.toml 或 setup.py |
| Rust |
cargo build --release |
无 Cargo.toml |
阶段 2:类型检查
| 项目 |
命令 |
跳过条件 |
| TypeScript |
tsc --noEmit |
无 tsconfig.json |
| Python |
pyright / mypy . |
未安装类型检查器 |
| Rust |
(包含在构建中) |
始终(cargo 处理类型) |
阶段 3:代码检查
| 项目 |
命令 |
跳过条件 |
| JS/TS |
eslint . --ext .js,.jsx,.ts,.tsx |
无 eslint 配置 |
| Python |
ruff check . / flake8 . |
无 linter 配置 |
| Rust |
cargo clippy -- -D warnings |
无 Cargo.toml |
阶段 4:测试
| 项目 |
命令 |
跳过条件 |
| JS/TS |
npm test / npm run test:coverage |
无 test 脚本 |
| Python |
pytest --cov |
无 tests 目录 |
| Rust |
cargo test |
无测试 |
阶段 5:安全
| 项目 |
命令 |
跳过条件 |
| JS/TS |
npm audit |
无 package-lock.json |
| Python |
safety check / pip-audit / bandit -r . |
未安装扫描器 |
| Rust |
cargo audit |
未安装 cargo-audit |
阶段 6:差异审查
命令:git diff HEAD~1 --stat
提供变更摘要以供评审参考。始终为信息性,永不失败。
检测逻辑
# 项目类型检测
detect_project() {
[ -f "package.json" ] && echo "node"
[ -f "pyproject.toml" ] || [ -f "setup.py" ] && echo "python"
[ -f "Cargo.toml" ] && echo "rust"
}
# 各阶段的跳过条件
should_skip_typecheck() {
[ ! -f "tsconfig.json" ] && [ ! -f "pyproject.toml" ]
}
should_skip_lint() {
[ ! -f ".eslintrc.js" ] && [ ! -f ".eslintrc.json" ] && \
[ ! -f "ruff.toml" ] && [ ! -f "Cargo.toml" ]
}
should_skip_test() {
[ ! -d "tests" ] && [ ! -d "test" ] && \
! find . -name "*_test.py" -o -name "test_*.py" | grep -q .
}
执行流程
START -> BUILD -> TYPECHECK -> LINT -> TEST -> SECURITY -> DIFF-REVIEW -> SUCCESS
\ \ \ \ \
-> SKIP -> SKIP -> SKIP -> SKIP -> SKIP (if conditions met)
Any phase FAIL -> STOP with error report
配置
环境变量
VERIFICATION_SKIP_PHASES="security,diff-review" # 跳过指定阶段
VERIFICATION_COVERAGE_MIN=80 # 覆盖率阈值
VERIFICATION_STRICT=true # 警告即失败
配置文件(.verification-loop.yml)
phases:
build:
enabled: true
timeout: 300
typecheck:
enabled: true
timeout: 120
lint:
enabled: true
allow_warnings: false
test:
enabled: true
coverage_threshold: 80
security:
enabled: true
severity_threshold: moderate
diff-review:
enabled: true
compare_ref: HEAD~1
skip_conditions:
- pattern: "*.md"
skip_phases: [build, typecheck, lint, test]
错误处理
| 阶段 |
失败时 |
| 构建 |
停止,报告编译错误 |
| 类型检查 |
停止,报告类型错误 |
| 代码检查 |
停止,报告 lint 违规 |
| 测试 |
停止,报告失败的测试 |
| 安全 |
报告漏洞,若低于阈值则继续 |
| 差异审查 |
始终成功(信息性) |
集成
- CI(GitHub Actions):为差异审查使用 fetch-depth: 2,按顺序运行各阶段。
- Pre-Commit 钩子:
#!/bin/bash
./verification-loop.sh --skip=security,diff-review
[ $? -ne 0 ] && exit 1
指标
| 指标 |
目标 |
| 通过率 |
>95% |
| 时长 |
<60s |
| 测试覆盖率 |
>80% |
版本
1.0.0(2026-01-24):初始发布。