Closed
test: pkg/cmdutil 核心模块覆盖率不达标 (52.0%) #313
aflyingtoAdd on  Jun 26Closed at  28 days ago
aflyingtoCollaborators
Jun 26 Create

发现来源

Agent 3 - 测试审查 (Critical)

位置

pkg/cmdutil/ 目录 — factory.go, format.go, output.go, flag_annotations.go 无测试

证据

go test -coverprofile=/tmp/cov.out -coverpkg=./pkg/cmdutil/... ./pkg/cmdutil/...
go tool cover -func=/tmp/cov.out | grep total
# 输出: total: (statements) 52.0%

errors_test.go (137行) 测试了 ExitCode() 和 FormatAPIID()。
但 factory.go (87行, 核心 Factory 模式), format.go, output.go, flag_annotations.go 的测试覆盖不足或缺失。

影响评估

Factory 模式是项目中所有命令的依赖注入核心。NewFactory() 和 TestFactory() 未经测试意味着它们的默认行为(如默认 HTTP 客户端创建、Git 仓库检测)可能在不同环境下产生不同结果。spec/foundations/testing-guide.md 要求核心模块覆盖率 ≥ 80%。

建议修复方向

  1. 为 factory.go 创建 factory_test.go,验证 TestFactory() 返回各字段的正确性
  2. 检查 confirm_test.go 是否充分覆盖确认流程
  3. 为 format.go 和 output.go 中的格式化函数补充测试

🤖 Generated by multi-agent code review workflow

likedislike
AaflyingtoCollaborators
Jun 26 Added label: risk/criticalscope/cmdutil, status/triage,type/test
AaflyingtoCollaborators
Jul 1 Associated milestone: M5: Test Coverage Foundation
AaflyingtoCollaborators
Aug 9 Removed label: status/triage
AaflyingtoCollaborators
Aug 9 Added label: status/verified
aflyingtoCollaborators
Aug 9 Comments:

Triage 复核(2026-08-09,origin/main 581262e)

重新测量确认问题仍有效(覆盖率/无测试文件状态仍低于 80% 要求)。推进 status/verified,可进入开发补测试。

  • 原报告覆盖率 vs 当前重新测量见 triage 汇总
  • 代码已演进(如 #462 DRY queryBuilder 等),但本 issue 涉及的覆盖缺口仍存在
  • 下一步:进入 status/in-progress 时补对应测试
likedislike
langjitianya008Collaborators
29 days ago Comments:

验证记录

  • 当前版本或分支: origin/main (64d1027)
  • 验证时间: 2026-10-09
  • 复现命令: go test -count=1 -coverprofile=cover.out ./pkg/cmdutil/ && go tool cover -func=cover.out
  • 实际结果: 覆盖率 73.6%(较 issue 创建时 52.0% 已有提升,但仍低于 80% 门槛)。函数级缺口:NewFactory 0%、TestFactory 0%、SetTopicAnnotation 0%、AddFormatFlag 0%、AddTimeFormatFlag 0%、AddTemplateFlag 0%、AddJSONFlag 0%、DefaultToken 0%、AuthenticatedClientFromFactory 0%、FormatAPIID 41.7%、ConfirmTokenDisclosure 61.5%
  • 预期结果: 核心模块覆盖率 ≥ 80%(spec/foundations/testing-guide.md)
  • 时间线检查: 2026-08-09 triage 复核确认缺口仍存在;当前无关联 PR、无 assignee、无认领评论,不存在重复交付风险
  • 结论: 继续修复——补充上述缺口函数单元测试,目标覆盖率 ≥ 80%
likedislike
langjitianya008Collaborators
29 days ago Comments:

开发进度

  • 当前状态: in-progress
  • 根因: pkg/cmdutil 多个导出函数(factory.go、format.go、output.go、flag_annotations.go、auth.go 部分函数)长期无单元测试,FormatAPIID/ConfirmTokenDisclosure 分支覆盖不全,整体覆盖率 73.6% 低于核心模块 80% 要求
  • 主要修改: 新增 factory_test.go、format_test.go、token_confirm_test.go,扩展 errors_test.go、auth_test.go、output_test.go、flag_annotations_test.go
  • 影响范围: 仅测试文件,无生产代码改动
  • 单元测试: 开发中
  • 构建: 待验证
  • 实际命令验证: 不适用(纯测试补充,无命令行为变更)
  • 安全影响: 无(不涉及凭证、网络调用逻辑变更)
  • 文档同步: 无需更新 docs/COMMANDS.md(无命令行为变更)
  • 风险或未覆盖项: 低风险,仅新增测试
  • 关联 PR: 待提交
likedislike
Llangjitianya008Collaborators
29 days ago Associated pull request
wangsikewangsikeCollaborators
28 days ago Close issue