fix(cli): diff-aware mode must not fall back to full scan on empty diff#712
Merged
Conversation
Two paired bugs caused a delete-only PR to dump every full-repo finding instead of the expected zero. Surfaced as 207 findings on PR #693, which only deletes one YAML workflow file. The wire: pathfinder ci computes changedFiles via git diff, then filters scan results to that set when diff-aware is on. Both halves were broken: 1. diff/git_provider.go ran `git diff --diff-filter=ACMR`, excluding deletions. A delete-only PR therefore produced changedFiles=[]. 2. cmd/ci.go guarded the filter with `diffEnabled && len(changedFiles) > 0`. When the list was empty, the filter was skipped entirely and ALL full-scan findings were returned. The same guard was on the filesScanned count, so the report also claimed "scanned full repo." Fix: - ACMR -> ACMRD so deletions show up in changedFiles. A delete-only PR now returns the deleted path, distinguishing it from an empty PR. - Drop the `len(changedFiles) > 0` guard at both call sites. If diff-aware is on, honour it: an empty intersection returns zero findings, not "full repo." The two states (diff-aware on, nothing matched vs diff-aware off, scan everything) must stay separable. Updated the existing TestGitDiffProvider_DeletedFileExcluded test (now TestGitDiffProvider_DeletedFileIncluded) and added a deletion-only regression covering exactly the PR #693 shape. CLAUDE.md gains a "Diff-Aware Scanning" section documenting the new contract so future maintainers don't reintroduce the fallback.
SafeDep Report SummaryNo dependency changes detected. Nothing to scan. This report is generated by SafeDep Github App |
Code Pathfinder Security ScanNo security issues detected.
Powered by Code Pathfinder |
Pathfinder Report✅ No security findings on the changed files. This pull request is clean. Powered by Code Pathfinder. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #712 +/- ##
==========================================
+ Coverage 85.52% 85.54% +0.02%
==========================================
Files 190 191 +1
Lines 27467 27467
==========================================
+ Hits 23492 23498 +6
+ Misses 3083 3079 -4
+ Partials 892 890 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…tput.DiffFilter Codecov caught that the two diff-filter call-site changes in PR #712 weren't directly unit-tested (33% patch coverage). Pulling the gate logic into a named helper makes both branches testable as pure functions and exposes a deeper instance of the same bug. Changes: - cmd/diff_filter.go: new applyDiffFilter + countScannedFiles helpers. applyDiffFilter is the single source of truth for "if diff-aware is on, run the filter; an empty changedFiles list is a valid input that yields zero detections, NOT a pass-through." - cmd/ci.go, cmd/scan.go: both call sites switched to applyDiffFilter. cmd/scan.go previously had the same `diffAware && len(changedFiles) > 0` guard as cmd/ci.go — same regression risk, fixed here too. - output/filter.go: removed the `if len(f.changedFiles) == 0 { return detections }` short-circuit in both Filter and FilteredCount. That was the deeper instance of the bug: even after fixing the cmd-layer guard, output.NewDiffFilter([]).Filter(d) would still pass d through, defeating the cmd-layer fix for genuinely empty diffs. Callers that want "no filtering" must skip Filter entirely (which applyDiffFilter now enforces via the diffEnabled gate). - output/filter_test.go: flipped two test cases that hard-coded the buggy pass-through behaviour to assert the new contract. - cmd/diff_filter_test.go: 10 tests covering every branch of both helpers (100% function coverage). go vet, golangci-lint: 0 issues.
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.



Summary
A delete-only PR was dumping every full-repo finding instead of the expected zero. Surfaced as 207 findings on #693, which only deletes one YAML workflow file. Compare with #692 — same shape (single YAML change) but an addition — which correctly returned 0 findings.
Two paired bugs:
diff/git_provider.gorangit diff --name-only --diff-filter=ACMR, excluding deletions. A delete-only PR therefore producedchangedFiles=[].cmd/ci.goguarded the filter withdiffEnabled && len(changedFiles) > 0. When the list was empty, the filter was skipped entirely and ALL full-scan findings were returned. The same guard was on thefilesScannedcount, so the JSON also claimed the whole repo was scanned.Fix
ACMR→ACMRD. Deletions show up inchangedFiles. A delete-only PR now returns the deleted path, distinguishing it from a genuinely empty PR.len(changedFiles) > 0guard at both call sites incmd/ci.go. If diff-aware is requested, honour it: an empty intersection returns zero findings, not "full repo." The two states (diff-aware on, nothing matchedvsdiff-aware off, scan everything) must stay separable.Test plan
TestGitDiffProvider_DeletedFileExcluded→TestGitDiffProvider_DeletedFileIncluded. The contract change is named in the test.TestGitDiffProvider_DeletionOnlyPRcovering the exact PR chore(ci): remove self-scan workflow, superseded by hosted scanner #693 shape (one workflow file deleted, nothing else).go test ./diff/... ./cmd/...passes.go vet,golangci-lint: clean.diffpackage: 91.5% (GetChangedFiles100%,diffFiles72.7% — unchanged baseline; error-path branches are timeout-only).Docs
CLAUDE.mdgains a Diff-Aware Scanning section documenting the new contract — including the explicit "do not reintroduce the full-scan fallback" rule — so this regression can't sneak back in.