Skip to content

refactor(config):将原先边界过宽或是职责细碎的部分重构#254

Merged
phantom5099 merged 2 commits into
1024XEngineer:mainfrom
phantom5099:main
Apr 13, 2026
Merged

refactor(config):将原先边界过宽或是职责细碎的部分重构#254
phantom5099 merged 2 commits into
1024XEngineer:mainfrom
phantom5099:main

Conversation

@phantom5099

Copy link
Copy Markdown
Collaborator

变更说明

本次 PR 针对 internal/config 包进行了深度的结构梳理与重构。主要目标是解决配置模块内部存在的“过度臃肿”与“过度细碎”并存的问题。通过解耦大杂烩结构、聚合零散逻辑、清理不再使用的兼容函数,我们将 Config 包还原为一个高内聚、边界清晰、无历史债务的核心管理层。

主要改动

  1. 拆解大杂烩模型 (model.go)
    • 移除原来的大而全的 model.go
    • 将配置参数精准归位至对应的领域模型文件:新增 config.go(核心骨架)、context.go(上下文相关)、tools.go(内建工具)、mcp.go(MCP协议支持)和 memo.go(记忆相关)。
  2. 消除过度设计碎片,聚合 Provider
    • 移除 provider_runtime.gobuiltin_providers.go
    • 将 Provider 的运行时格式转换与默认值生成统一收拢至 provider.go,消灭为了分层而分层的过度设计。
  3. 清理冗余与过渡残留
    • 彻底删除为了兼容旧版本而残留的 config.Default() 方法,统一规范使用 StaticDefaults() 获取静态骨架。
    • 清理重构期间遗留的临时测试文件(如 config_model_split_test.go)。
  4. 测试体系重整
    • 将原本细碎的 builtin_providers_test.goprovider_runtime_test.go 聚合到 provider_test.go,确保测试代码结构与生产代码结构严格对齐,全量测试秒过。

预期收益

  1. 极大幅度降低心智负担:开发者如今查阅和修改特定领域(如 MCP、Tools)的配置时能“见名知意”,再也不需要在上千行的单一文件或几个来回跳转的碎片文件中苦苦搜寻。
  2. 架构更健壮、内聚度更高:在同一包内做到逻辑的完美闭环。将静态配置与动态状态(state/)区分开的同时,避免了拆解过细引入循环依赖的潜在风险。
  3. 消除隐患:移除了语义不明的历史函数,防止未来的外层调用方(app, tui)因为误用旧的静态 Default 方法而获得错误的未就绪配置。

@codecov

codecov Bot commented Apr 13, 2026

Copy link
Copy Markdown

@phantom5099

Copy link
Copy Markdown
Collaborator Author

/review -codex

@fennoai fennoai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the config refactor end-to-end (including parallel quality/perf/security/docs passes). I did not find runtime regressions, but I found two low-severity test clarity issues worth fixing to reduce future confusion.

Comment thread internal/config/tools_test.go Outdated
}
}

func TestNormalizeContentTypesFallsBackToDefaultsWhenEmpty(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestNormalizeContentTypesFallsBackToDefaultsWhenEmpty and its assertion currently describe different expectations.

  • Test name implies empty input should fallback to defaults
  • Assertion expects zero results for []string{"", " "}

Please align either the test name or the assertion with the intended behavior, so this test documents the contract unambiguously.

Comment thread internal/config/mcp_test.go Outdated
}
cloned := original.Clone()
if len(cloned.Env) != 0 {
t.Fatal("expected cloned env to be empty slice, not nil")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The failure message says empty slice, not nil, but this assertion only checks len(cloned.Env) != 0, which cannot distinguish nil from empty slice.

Either update the assertion to check nil-vs-empty explicitly, or relax the message to match the current length-only check.

@phantom5099

Copy link
Copy Markdown
Collaborator Author

/simplify

@fennoai

fennoai Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

完成情况

已按请求先检查评论日志中的未解决 review comment,并完成值得修复的项:

  1. 修复 internal/config/tools_test.go 中测试命名与断言语义不一致问题。
  2. 修复 internal/config/mcp_test.go 中“empty slice vs nil”断言问题,并同步调整 internal/config/mcp.goClone(),在原始 Env 为非 nil 空切片时保持该语义。
  3. 按要求调用了 code-simplifier 子代理,对测试做了小幅简化(合并为更清晰的表驱动用例),并保留原行为。

验证

  • gofmt -w internal/config/mcp.go internal/config/mcp_test.go internal/config/tools_test.go
  • go build ./...
  • go test ./...

提交与推送

  • Commit: e02681c
  • 已推送到 PR 头分支:phantom5099/main

未执行项

  • 未新增额外功能性改动;仅处理未解决评论与可确认收益的简化。

View job run

Generated with [codeagent](https://github.com/qbox/codeagent)
Co-authored-by: phantom5099 <245659304+phantom5099@users.noreply.github.com>
@phantom5099 phantom5099 merged commit 2ddf10e into 1024XEngineer:main Apr 13, 2026
2 checks passed
@fennoai fennoai Bot mentioned this pull request Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants