fix(config): 根治 TestDefaultConfigValues 非 hermetic 红测(#90/#107)#148
Conversation
NewGlobalConfig 会先填默认再被 config.json 覆盖,旧测试却把它当纯默认值断言, 导致默认与 json 不一致的字段(MaxMemTableSize 1024 vs 10000)恒红,且依赖文件存在。 抽出 defaultGlobalConfig()(纯默认,不读文件/不解析命令行),NewGlobalConfig 在其上 叠加 Init+ParseFlags;测试改测 defaultGlobalConfig(),名副其实且不再依赖外部文件。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthrough
ChangesConfig default construction refactor
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Possibly related issues
Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🐯 BanGD 数据库内核评审整体风险:🟢 低 变更总结:本 PR 在
未发现需要从架构层面改进的问题。 本次评审消耗 token:共 15131 tokens(输入 14815,输出 316,缓存命中 0,缓存写入 0)|维度 [memory, storage, performance, resource, error]|对抗式复核 3 票/条,过滤疑似误报 0 条 |
问题
TestDefaultConfigValues调NewGlobalConfig()断言「纯默认值」,但NewGlobalConfig会先填默认、再用 config.json 覆盖。默认与 json 不一致的字段(MaxMemTableSize:默认 1024 vs json 10000)恒红;且测试结果依赖 config.json 是否被找到——非 hermetic。修法(已与用户确认:抽纯默认构造 + 测试 hermetic)
defaultGlobalConfig():返回纯代码默认值,不读文件、不解析命令行NewGlobalConfig()=defaultGlobalConfig()+Init()(文件覆盖) +ParseFlags()(命令行覆盖)TestDefaultConfigValues改测defaultGlobalConfig()——名副其实,且不再依赖外部文件测试
go build ./...通过;config包全绿(此前唯一红点MaxMemTableSize消除),其余 config 测试无回归。🤖 Generated with Claude Code
Summary by CodeRabbit
Refactor
Tests