open-code-review icon indicating copy to clipboard operation
open-code-review copied to clipboard

test(diff): cover gitignore-drop interleaved with provider-exclude in ForEachInOrder

Open lizhengfeng101 opened this issue 2 months ago • 2 comments

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 / partitionDiffs in internal/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 that ForEachInOrder visits only the included and provider-excluded files, in the original changeset order, with correct providerExcluded flags, and never visits the gitignore-dropped file.

Acceptance Criteria

  • [ ] A new test in internal/diff/git_test.go covers the gitignore-drop + provider-exclude interleaving described above
  • [ ] The test fails if excludedAt accounting 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.

lizhengfeng101 avatar Sep 16 '26 00:09 lizhengfeng101

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.

jimpablo avatar Sep 16 '26 01:09 jimpablo

I'd like to work on this if u need.

iluv7 avatar Sep 16 '26 01:09 iluv7