test(diff): cover gitignore-drop interleaved with provider-exclude in ForEachInOrder
Description
DiffSet.ForEachInOrder (internal/diff/git.go) walks Included and Excluded
in the original changeset order using the arithmetic upTo := excludedAt[i] - i,
where excludedAt[i] is the exclusion's index in the mixed stream of included
and provider-excluded files.
That mixed-stream index deliberately does not count files dropped by
.gitignore, because partitionDiffs adds a gitignore-dropped file to neither
Included nor Excluded. The ordering is therefore correct only as long as a
gitignore-dropped file contributes to neither counter — an invariant the code
relies on but that no test exercises directly.
The existing test TestGetDiffSetWalksChangesetOrder covers an
included → provider-excluded → included interleaving (a.go, target/mid.go,
z.go), but never mixes in a gitignore-ignored file. If a future change to
partitionDiffs ever miscounted dropped files, the ordering would silently skew
and no test would catch it.
This is a test-completeness gap, not a known defect: the current logic is correct. We want a regression test that pins the invariant.
Scope
- File(s):
internal/diff/git_test.go - Function/area:
DiffSet.ForEachInOrder/partitionDiffsininternal/diff/git.go - Add a test case where the changeset interleaves all three kinds of file:
included, provider-excluded (e.g. under
target/), and gitignore-ignored, arranged so the gitignore-dropped file sits between an included and an excluded file. Assert thatForEachInOrdervisits only the included and provider-excluded files, in the original changeset order, with correctproviderExcludedflags, and never visits the gitignore-dropped file.
Acceptance Criteria
- [ ] A new test in
internal/diff/git_test.gocovers the gitignore-drop + provider-exclude interleaving described above - [ ] The test fails if
excludedAtaccounting is perturbed to count dropped files (verify by temporarily breaking it locally) - [ ] Tests pass (
make test) - [ ] Code check passes (
make check)
Context
Surfaced while reviewing the ordering logic introduced in #1242. The arithmetic was verified correct by hand across the empty / all-excluded / interleaved / gitignore-mixed cases; this issue only fills the missing regression coverage for the last case.
Hi @lizhengfeng101 — I'd like to take this. I remember walking through the gitignore-mixed case by hand in #1242; happy to add the regression test that pins it.
I'd like to work on this if u need.