fix(indexer): correct inverted gitignore polarity in ShouldIndexFile - #113
Merged
Conversation
…via a shared exclude-filter helper
ShouldIndexFile paired GitIgnoreFilter (a keep-filter: Match==true means "not
ignored, keep") with NewSimpleFilter's exclude-consumption (if Match { return
false }), so for UseGitIgnore=true workspaces the incremental single-file update
path was inverted: not-ignored source files were skipped and gitignored files
were indexed. The full-scan path (processWorkspace) was already correct.
Introduce buildExcludeFilter as the single source of truth for the exclude
keep-filter and route both ShouldIndexFile and processWorkspace through it;
ShouldIndexFile now skips when the keep-filter returns false. Rewrite the
previously assertion-free gitignore test into an assertive one covering the
kept/ignored/ignored-dir cases.
Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
codetrek
approved these changes
Jul 10, 2026
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 & why
ShouldIndexFile(the incremental single-file update path, reached fromPOST /api/v1/document/update→handleUpdateDocument) inverted the gitignore filter forworkspaces configured with
Exclude.UseGitIgnore=true.The three path filters have different polarity:
Match(p)==truemeansGitIgnoreFilter(= !ignore.IsIgnored)utils.NewSimpleFilter(patterns)utils.NewSimpleFilterExclude(patterns)ShouldIndexFilebuilt the gitignore branch with a keep-filter but consumed it withNewSimpleFilter's exclude-convention (if exclude.Match(relPath,false) { return false }).Result for
UseGitIgnore=trueworkspaces on the incremental path:Match=true) →return false→ skipped (never re-indexed)Match=false) → falls through → indexed (junk likebuild/,vendor/)The full-scan path (
processWorkspace) already usedNewSimpleFilterExclude(keep-filter) +ListFiles(keep where
Match==true) and was correct — so only the incremental path was inverted. Default isuse_git_ignore: false, so only opt-in workspaces were affected.Fix
Introduce one helper,
buildExcludeFilter, as the single source of truth for the excludekeep-filter, and route both call sites through it so the two can never drift to opposite polarity
again:
ShouldIndexFilenow skips when the keep-filter returns false:if !exclude.Match(relPath, false) { return false }.processWorkspacerouted through the same helper — behavior unchanged (its two arms are thefilter it already constructed inline).
No on-disk format / API / reindex impact.
Tests
Rewrote the previously assertion-free
TestShouldIndexFile_WithGitIgnoreFilter(
_ = ShouldIndexFile(...)— which is why the inversion slipped through) into an assertive test:main.go(not ignored) → indexedapp.log(ignored by*.log) → skippedbuild/out.go(under ignoredbuild/) → skippedAll three fail on the pre-fix code (verified red) and pass after. The customized-exclude branch stays
covered by the existing
TestShouldIndexFile_WithCustomExcludeFilters, so bothbuildExcludeFilterbranches reach 100% coverage.
Verification
Gates:
gofmt/go build/go vet/go test/go test -raceall green;buildExcludeFilter100%,ShouldIndexFile100% coverage.End-to-end with the real server binary (
use_git_ignore: true, incremental/document/update):keep2.go(not ignored)File Ignored❌ / unsearchableOk✓ / searchableignored2.go(gitignored)Ok❌ / searchableFile Ignored✓ / absent🤖 Generated with Claude Code
via Happy