fix(git_ops): clean up path-keyed .gitmodules after a failed add + idempotency tests (#62 P2)#75
Merged
Merged
Conversation
#62 P2) The #62 audit (P2) asked for idempotency / partial-failure coverage. Writing the tests surfaced a real masked bug: when a submodule already exists (so .gitmodules is present) and a subsequent `add` fails against an unreachable URL, a stale `[submodule "<path>"]` entry was left behind in .gitmodules. Root cause: the add fallback cleanup (git_ops/mod.rs) removed the .gitmodules section by `opts.name`, but git2 writes the section keyed by *path* (it uses the path as the section key when name != path). The name-keyed match missed git2's path-keyed entry, so it lingered after the failed add. Fix: match both the name- and path-keyed section headers during cleanup. TDD: - test_failed_add_leaves_no_partial_state — baseline add, then a failed add; asserts no stale .gitmodules/git-config entry, no orphan worktree dir, no dangling .git/modules, AND that the pre-existing submodule survives (non-vacuous). RED before the fix, GREEN after. - test_add_same_submodule_twice_is_idempotent — re-adding the same name+path succeeds with exactly one entry in .gitmodules, git config, and submod.toml (characterization; behavior was already correct). - test_delete_nonexistent_submodule_fails — deleting a missing submodule exits non-zero with a specific "ghost ... not found" error (characterization). Full suite 558 pass; fmt + clippy clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T8D5ZK1473YCiZkbueAY2X
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.
What
Addresses the #62 audit's P2 bullet "Idempotency / partial-failure untested." Writing the tests surfaced a real masked bug.
Bug: failed add leaves a stale
.gitmodulesentryWhen a submodule already exists (so
.gitmodulesis present) and a lateraddfails against an unreachable URL, a stale[submodule "<path>"]entry was left behind.Root cause: the add fallback cleanup (
src/git_ops/mod.rs) removed the.gitmodulessection byopts.name, but git2 writes the section keyed by path (it uses the path as the section key whenname != path). The name-keyed match missed git2's path-keyed entry. Fix: match both the name- and path-keyed section headers during cleanup (4 lines).Tests (TDD)
test_failed_add_leaves_no_partial_state.gitmodules/git-config entry, no orphan worktree dir, no dangling.git/modules, and that the pre-existing submodule survives (non-vacuous)test_add_same_submodule_twice_is_idempotent.gitmodules, git config, andsubmod.tomltest_delete_nonexistent_submodule_failsghost ... not founderrorAll assertions were probed against the real binary first (e.g.
.git/configstores.urlnot.path;.gitmodulessections are path-keyed) so the counts are accurate and non-vacuous.Verification
Full suite 558 pass, 0 fail;
cargo fmt+clippy --all-features --testsclean. Fix confirmed load-bearing (the partial-state test is RED without it).🤖 Generated with Claude Code