已关闭
test: ExitCode 映射测试覆盖不完整 — 缺少 409/403/400/网络错误等关键路径 #352
aflyingto创建于 6月26日关闭于 6月27日
aflyingto
6月27日 评论:
6月27日 评论:
aflyingto
6月27日 评论:
6月27日 评论:
验证记录
- 当前分支: origin/main (878741b)
- 复现命令:
go test ./pkg/cmdutil/ -v -run TestExitCode -count=1 go test ./pkg/cmdutil/ -coverprofile=/tmp/cover.out -count=1 go tool cover -func=/tmp/cover.out | grep -E 'ExitCode|WrapNotFound|errors.go' - 实际结果:
ExitCode: 75.0% 覆盖 — 缺少 APIError StatusCode 409/403/400/404、5xx fallback 等路径WrapNotFound: 0.0% 覆盖 — 完全未测试CLIError.Unwrap: 0.0% 覆盖isCobraUsageError: 90.0% 覆盖- 当前 16 个 ExitCode 测试均通过,但所列缺失场景确未覆盖
- 结论: 继续修复 — 补充 ExitCode 映射、WrapNotFound、Unwrap 的缺失测试用例


aflyingto
6月27日 评论:
6月27日 评论:
开发进度
- 根因: ExitCode/WrapNotFound/CLIError 的多个 APIError 状态码路径、包装错误路径和 nil 边界未测试
- 主要修改:
errors.go: 修复 nil*CLIErrordereference panic (添加&& cliErr != nil守卫)errors_test.go: +222 行,新增 25 个测试用例 (14 ExitCode + 5 WrapNotFound + 6 CLIError)
- 测试:
go test ./...1244 passed - 实际命令验证:
./gc issue list -R infra-test/gctest1exit 0 - 安全影响: 无 — 纯测试补充 + nil 守卫修复
- 风险或未覆盖项: isCobraUsageError 仍有 10% 未覆盖 (非标准 Cobra 错误消息)
- 关联 PR: https://github.com/gitcode-cli/cli/pull/8
- CI: https://github.com/gitcode-cli/cli/actions/runs/28275334484 (ubuntu ✅, windows ✅, macos ❌ pre-existing dyld env issue)


发现来源
Agent 4 - Agent 友好性 (Low)
位置
pkg/cmdutil/errors_test.go
证据
errors_test.go 测试了 16 个场景但缺少: APIError 409 (ExitConflict), 403 (ExitAuth), 400 (ExitUsage), 404 (ExitNotFound), 5xx fallback, 包装后的 %w 错误, API error 回退路径, releaseError 类型, net.OpError, nil CLIError 边界, WrapNotFound 场景。
影响评估
对 ExitCode 映射函数的修改可能破坏未测试的退出码路径,Agent 依赖的退出码稳定性可能被无意破坏。
建议修复方向
补充上述缺失的测试用例。
🤖 Generated by multi-agent code review workflow