Files
codebase-memory-mcp/tests
Andrew Hundt 76f7796fb8 fix(mcp): distinguish dirty worktree from HEAD
Previous behavior:
- index_status.git returned head_sha and base_sha without stating that HEAD identifies committed content only or whether the current filesystem differed from HEAD.
- A consumer could treat the SHA as the identity of a dirty working tree.

Changes:
- Reuse cbm_git_snapshot_read(CBM_GIT_SNAPSHOT_DIRTY) in add_git_context_json() at src/mcp/mcp.c:3106-3126.
- Emit head_scope=committed_revision_only, worktree_dirty, head_matches_worktree, worktree_state, and a dirty_hash only for dirty repositories.
- Emit null dirty/match fields plus worktree_state=unknown when snapshot capture is unavailable instead of claiming the tree is clean.
- State the HEAD/working-tree distinction in the shared index_status tool description.

Scope and lifecycle:
- Dirty status is computed only for single-project index_status responses; list_projects and search paths gain no git-status scan.
- cbm_git_snapshot_t is stack-owned and add_git_context_json() retains its existing cbm_git_context_free() cleanup.

Verification:
- Red: focused test failed at tests/test_mcp.c:3115 because worktree_dirty was absent.
- Green: clean-to-dirty focused test passed 1/1; MCP ASan/UBSan passed 223/223; tool_consolidation passed 100/100.
- make -f Makefile.cbm lint-source-safety passed both checks.

Signed-off-by: Andrew Hundt <ATHundt@gmail.com>
2026-07-16 04:25:36 -04:00
..
2026-07-08 00:05:19 +05:30