已关闭
refactor: pkg/cmdutil 导入 internal/config — 分层倒置 #351
aflyingto创建于  6月26日关闭于  6月27日
aflyingto成员
6月26日 创建

发现来源

Agent 6 - 架构审查 (Low)

位置

pkg/cmdutil/factory.go, pkg/cmdutil/auth.go (导入 internal/config)

证据

pkg/cmdutil 在 pkg/ 树中(语义上暗示可共享的工具层),但它导入 internal/config(语义上暗示私有实现细节)。Go 编译器允许(同一模块),但架构上违反分层:internal/ 应由应用层代码消费,而非共享工具包。

影响评估

如果项目拆分为多个模块或暴露 pkg/ 为库,此导入将因 Go internal/ 跨模块限制而中断。

建议修复方向

方案 A: 将 config 从 internal/ 迁移到 pkg/config/
方案 B: 在 pkg/cmdutil 中定义 consumer-side 接口,由 internal/config 满足


🤖 Generated by multi-agent code review workflow

likedislike
Aaflyingto成员
6月26日 添加了label:risk/lowscope/layering, status/triage,type/refactor
aflyingto成员
6月27日 评论:

Triage 记录

  • 类型: type/refactor
  • 范围: scope/layering
  • 风险: risk/low
  • 判定: 问题描述清晰,导入方向确实违反分层约定。pkg/cmdutil 在 pkg/ 层却导入 internal/config。建议采用方案 A(将 config 从 internal/ 迁移到 pkg/config/),因为 config 包被 16 个文件使用,本质上是共享配置层,放在 pkg/ 下更合理。

当前标签

  • type/refactor ✅
  • status/triage ✅
  • risk/low ✅
  • scope/layering ✅

→ 进入验证阶段

likedislike
aflyingto成员
6月27日 评论:

验证记录

  • 当前版本或分支: main (e21f05d)
  • 复现命令: grep -n "internal/config" pkg/cmdutil/factory.go pkg/cmdutil/auth.go
  • 实际结果:
    • pkg/cmdutil/factory.go:11: 导入 gitcode.com/gitcode-cli/cli/internal/config
    • pkg/cmdutil/auth.go:9: 导入 gitcode.com/gitcode-cli/cli/internal/config
    • internal/config/ 位于 internal/ 目录
  • 结论: 分层倒置确实存在。pkg/cmdutil(pkg/ 共享层)不应依赖 internal/config(internal/ 私有层)。继续修复。采用方案 A:将 config 从 internal/ 迁移到 pkg/config/
likedislike
Aaflyingto成员
6月27日 添加了label:status/verified
Aaflyingto成员
6月27日 添加了label:status/in-progress
Aaflyingto成员
6月27日 关联了pull request:refactor: move config from internal/ to pkg/ to fix layering
Aaflyingto成员
6月27日 关闭了 issue
Aaflyingto成员
6月27日 添加了label:status/merged
aflyingto成员
6月27日 评论:

开发完成 & 合入记录

门禁证据

# 门禁 状态 证据
1 开发实现 ✅ 将 internal/config 迁移到 pkg/config,更新 17 个 import
2 测试 ✅ 1259 passed, 96 packages
3 本地构建 ✅ go build -o ./gc ./cmd/gc 成功
4 单元测试 ✅ go test ./... 全部通过
5 Pre-commit ✅ 全部 hooks 通过
6 实际命令验证 ✅ gc auth status, gc issue list 等正常
7 远端 CI ✅ https://github.com/gitcode-cli/cli/actions/runs/28278917165
8 风险分级 risk/low 自动合并

作者自检 9 项

  1. 根因/实现理由: pkg/cmdutil 在 pkg/ 共享层却导入 internal/config 私有层,违反分层约定。采用方案 A:将 config 移到 pkg/config/
  2. 修改范围: 20 个文件,仅 import 路径变更 (+17 -17),3 个 config 文件零内容变更
  3. 测试结果: go test ./... 1259 passed
  4. 实际命令验证: gc auth status, gc issue list 等通过
  5. 安全审查结果: PASS,无硬编码凭证,封装良好
  6. 文档同步结果: 已修复 spec/foundations/coding-standards.md 中的过时引用
  7. 风险点: 无 — 纯机械重构
  8. 未覆盖项: 无
  9. 文档审查发现: coding-standards.md 过时引用已修复

多角色评审

维度 结论
代码审查 ✅ PASS
安全审查 ✅ PASS
测试审查 ✅ PASS
文档审查 ✅ PASS (coding-standards.md 已修复)

关联 PR

#301 — merged

CI Run URL

https://github.com/gitcode-cli/cli/actions/runs/28278917165

likedislike
Aaflyingto成员
7月7日 添加了label:status/ready-for-review