跳到正文
agore-skill
参考

测试与覆盖率

测试布局、注入式 fake,以及覆盖率门槛。

测试布局

每个包的测试都紧挨代码放置:

包测试文件
cmd/agore-skillmain_test.go
internal/clicli_test.go
internal/configconfig_test.go
internal/workspacediscover_test.go
internal/skillparser_test.go, templates_test.go
internal/filefilterfilefilter_test.go
internal/inspectanalyzer_test.go
internal/lintrules_test.go
internal/releaserelease_test.go, bundle_more_test.go, github_test.go, github_more_test.go
internal/uirender_test.go

风格:表驱动测试、精确消息匹配,以及在 CLI 场景下针对 fake App 的端到端命令运行。

三层测试

  1. 单元测试(mise run test)——包内局部、快速、确定性。
  2. 命令测试——internal/cli 经 cobra 驱动每条命令,并注入 fake App:捕获的写入器、fake git 辅助 (ChangedFiles、DescribeTag、WorkingTreeClean、RemoteURL)、 fake LookPath/Getenv/RunCommand、prompt fake,以及 PublishGitHub stub。没有真实 TTY,也没有真实网络。
  3. 端到端(scripts/e2e.sh、mise run e2e)——在临时目录中运行真实 二进制,走完整个生命周期,校验归档内容、 校验和、SKILL.md 不可变性,以及不泄漏仓库内容。

一个跨包的不变量:lint 包断言三个内嵌脚手架模板 lint 后均为 0 错误 0 警告——这是用户教程所依赖的契约。

命令

mise run test        # go test ./...
mise run test:race   # go test -race ./...
mise run vet         # go vet ./...

覆盖率门槛

mise run cover

scripts/coverage.sh 以 -covermode=atomic -coverprofile 运行测试,并解析 go tool cover -func 获取总计。低于 90.0% 时会失败(可通过 COVERAGE_MIN 环境变量修改), profile 路径为 COVERAGE_PROFILE(默认 coverage.out,已被 gitignore)。

当前语句覆盖率总计:运行该脚本即可——它会打印总数并执行门槛检查;作为契约的是门槛本身。

在 CI 中,quality job 运行同样的门槛,并将 coverage.out 作为 artifact 上传(保留 14 天);在本地 act 运行中,上传步骤会被跳过 (if: ${{ !env.ACT }}),因为 act 的 artifact 服务器不支持 upload-artifact@v7 协议。

相关页面

本页目录