fix(cdb): preserve tests/ entries across mcpp build (v0.0.63)#166
Merged
Conversation
…rage) `compile_commands.json` mirrors the current build plan. `mcpp build`'s plan excludes tests/**/*.cpp and dev-deps, yet it writes the SAME cdb as `mcpp test` — so in the edit→build loop the test entries get overwritten and clangd loses all completion in tests/ (gtest, import std, import mcpplibs.*). Fix: `write_compile_commands` now MERGES instead of overwriting — it preserves still-valid prior entries the current plan doesn't cover (the tests/ entries a previous `mcpp test` wrote) and prunes entries whose file no longer exists. `mcpp build` itself is unchanged: it resolves/downloads NO dev-deps, leaving build-only users and the build graph untouched (offline-first). Run `mcpp test` once and test completion persists across every subsequent `mcpp build`. - new pure helper merge_compile_commands(fresh, existing, fileExists) - unit: tests/unit/test_compile_commands.cpp (merge/prune/dedup/bad-json) - e2e: tests/e2e/77_cdb_preserves_test_entries.sh (build keeps test entries) - design: .agents/docs/2026-06-25-cdb-test-coverage-design.md - bump 0.0.62 -> 0.0.63
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
clangd 在
tests/目录下对gtest::InitGoogleTest()、import std、import mcpplibs.*全无代码提示。根因:
compile_commands.json是当次构建 plan 的镜像。mcpp build的 plan 不含tests/**/*.cpp与 dev-deps,而它与mcpp test写同一个 cdb——后写覆盖前写。日常「编辑→mcpp build」循环里,测试条目几乎总被擦掉(P0 fast-path 全缓存时不重写,故偶尔残留;一旦真实重建即回退)。完整分析见
.agents/docs/2026-06-25-cdb-test-coverage-design.md。方案:offline-first 的 cdb「合并保留」
mcpp test本就能写出完整正确的 cdb(测试条目 flag 有效、其 BMI 因 build/test 共用输出目录而真实存在)。bug 本质是mcpp build摧毁它。修复 = 让 build 停止摧毁:write_compile_commands由「全量覆盖」改为「合并」:mcpp test写的测试条目)→ 保留;mcpp build自身零改动:不解析、不下载任何 dev-deps,build-only 用户与构建图均不受影响(严守 offline-first)。跑一次mcpp test后,测试补全在后续所有mcpp build中持久生效。改动
src/build/compile_commands.cppm:新增纯函数merge_compile_commands(fresh, existing, fileExists)+write_compile_commands走合并。其余构建相关文件(plan/prepare/ninja_backend/execute)均无改动。tests/unit/test_compile_commands.cpp:合并保留 / 剪除已删 / fresh 胜出去重 / 坏 JSON 回退(TDD,先 RED 后 GREEN)。tests/e2e/77_cdb_preserves_test_entries.sh:mcpp test后真实重建mcpp build仍保留测试条目 + 删测试文件后剪除(三平台)。0.0.62 → 0.0.63。验证(本机)
test_compile_commands4/4)。🤖 Generated with Claude Code