Skip to content

Match wildcard .thvignore directory patterns - #7195

Closed
jstar0 wants to merge 2 commits into
stacklok:mainfrom
jstar0:fix/thvignore-wildcard-dir-patterns
Closed

jstar0 wants to merge 2 commits into
stacklok:mainfrom
jstar0:fix/thvignore-wildcard-dir-patterns

Conversation

@jstar0

@jstar0 jstar0 commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • .thvignore directory patterns (a pattern ending in /) that contain wildcards never matched: getMatchingPaths only os.Stated the literal pattern path and returned early, so filepath.Glob was never reached for directory patterns. Entries such as secrets-*/ or *.egg-info/ therefore produced no overlay and the directories stayed visible inside the container.
  • Fall back to glob matching for directory patterns when the literal path does not resolve, and keep only directory matches — a file that happens to share the pattern still must not be overlaid by a directory rule.
  • Add TestWildcardDirectoryPattern covering a multi-directory wildcard match, exclusion of a same-named file, and the overlays produced.

Fixes #7182

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests — go test ./pkg/ignore/ (full package, repeated runs) passes, including the new TestWildcardDirectoryPattern
  • E2E tests (task test-e2e)
  • Linting — gofmt -l clean and go vet ./pkg/ignore/ clean (task/golangci-lint unavailable in my environment)
  • Manual testing (describe below)

API Compatibility

No operator API surface changes.

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.56%. Comparing base (8efeeb3) to head (b2ee15c).
⚠️ Report is 784 commits behind head on main.

Files with missing lines Patch % Lines
pkg/ignore/processor.go 80.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7195       +/-   ##
===========================================
+ Coverage   71.48%   81.56%   +10.08%     
===========================================
  Files         694      896      +202     
  Lines       70971    91449    +20478     
===========================================
+ Hits        50735    74594    +23859     
- Misses      16577    16850      +273     
+ Partials     3659        5     -3654     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, the fix itself looks right to me. I merged it locally on top of current main and the wildcard matches go through the confinement checks added in #7196 as expected: patterns that escape the mount and symlinks pointing out of it are still skipped.

I'd like to see the test side changed before we merge, though.

This branch predates #6854, which gave every Processor its own artifact directory. So the processor.artifactDir = t.TempDir() override isn't needed anymore, and the comment about overlay artifacts being shared per process is no longer accurate.

Rather than a new standalone test, I'd prefer this covered as cases in TestGetOverlayMountsConfinedToMount, which came in with #7196. It already has the layout we need (ws/sub, alias -> sub, link pointing outside the mount), it's table-driven with require like the rest of the package, and it would also pin down how wildcard directory patterns interact with the confinement, which the current test can't do. After rebasing on main, something along these lines:

// next to the existing setup, a regular file whose name also matches s*
require.NoError(t, os.WriteFile(filepath.Join(ws, "subfile"), nil, 0o600))

{name: "wildcard directory pattern skips files", pattern: "s*/", expected: []string{"/app/sub"}},
{name: "wildcard directory pattern through a symlink inside the mount", pattern: "ali*/", expected: []string{"/app/sub"}},
{name: "wildcard directory pattern through a symlink leaving the mount", pattern: "lin*/", expected: nil},
{name: "wildcard directory pattern beyond the mount", pattern: "../out*/", expected: nil},

I ran those four against the merged code and they give the results above. With them in place TestWildcardDirectoryPattern can be dropped.

getMatchingPaths only stat()ed a literal path for patterns ending in '/', so a wildcard directory pattern like 'secrets-*/' never matched and the directories it was meant to hide stayed visible in the container. Fall back to glob matching for directory patterns and keep only directory matches.
Address review feedback: rebase on main so the per-processor artifact
directory from stacklok#6854 is used, extend TestGetOverlayMountsConfinedToMount
with wildcard directory cases (file skip, symlink inside and outside the
mount, pattern beyond the mount), and drop the standalone test.
@devin-ai-integration
devin-ai-integration Bot force-pushed the fix/thvignore-wildcard-dir-patterns branch from b2ee15c to 98e9b99 Compare November 23, 2026 23:15
@jstar0

jstar0 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Restructured per your suggestion — rebased on current main, dropped the artifactDir override (now per-processor from #6854) and the standalone test, and added the four wildcard cases to TestGetOverlayMountsConfinedToMount plus the subfile fixture. go test -race ./pkg/ignore/... passes locally.

@ChrisJBurns

Copy link
Copy Markdown
Collaborator

Closing in favour of #7258

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.thvignore directory patterns with wildcards never match

3 participants