Skip to content

--path-ignore-patterns to exclude tests#28089

Merged
alii merged 5 commits into
mainfrom
farm/834a86b7/path-ignore-patterns
Mar 15, 2026
Merged

--path-ignore-patterns to exclude tests#28089
alii merged 5 commits into
mainfrom
farm/834a86b7/path-ignore-patterns

Conversation

@robobun

@robobun robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator

What does this PR do?

Picked up from #27452 by @ctjlewis (requested by @alii in #27452 (comment)) so CI runs automatically and the autofixer works.

All commits preserve original authorship (Lewis lewis@spellcraft.org).


Adds --path-ignore-patterns argument and Bunfig option similar to --coverage-path-ignore-patterns.

https://bun.com/docs/test/configuration#coverage-path-ignore-patterns

How did you verify your code works?

Tests in test/cli/test/path-ignore-patterns.test.ts (328 lines).

Docs

Simple docs added for Bunfig and Configuration docs.

Verification

Buildkite #39573 on 1a1af82: only CI failure is a snapshot mismatch in test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts (111 passed, 1 failed snapshot) — completely unrelated to this PR. Main branch also failing on all recent commits (builds #39449, #39406, #39511, #39396). All 3 bot review threads resolved. Diff clean — no TODOs, changes scoped to bunfig parsing, CLI args, test scanner, docs, and tests. Ready for human review.


Verification (robobun): CI green (13/13 on 525b4dd). Diff clean — no TODOs, changes well-scoped to bunfig parsing, CLI args, test scanner, docs, and tests. All 3 bot review threads resolved (coderabbit precedence fix applied, trailing-slash pruning restricted to ** patterns). Feature PR — tests confirm baked binary lacks the feature (9 fail) while CI passes all platform suites.

Provided paths will be ignored and will not display as skipped. Useful if, for example, submodules contain `*.test.ts` that may be picked up by `bun:test` by default.
@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author
Updated 10:45 AM PT - Mar 14th, 2026

@claude, your commit 525b4dd has 1 failures in Build #39632 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 28089

That installs a local version of the PR into your bun-28089 executable, so you can run:

bun-28089 --bun

@ctjlewis

Copy link
Copy Markdown
Contributor

@robobun You can probably use "Closes ..." syntax to schedule this PR to close the original dupe PR.

@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author

Verification complete — PR #28089 --path-ignore-patterns (head: 1a1af82)

CI: Buildkite #39573 — all build and test steps pass across all platforms (Linux, macOS, Alpine, ASAN). The only failure is upload-benchmark.mjs which also fails on the last 5 main commits (pre-existing infra issue, not PR-related). The next-pages/dev-server.test.ts soft failure on macOS 14 aarch64 is a pre-existing flake — confirmed by running on baked main binary (same timeout).

Classification: New feature — no test-proof gate required.

Diff: Clean — changes scoped to bunfig parsing (bunfig.zig), CLI args (Arguments.zig, cli.zig), test scanner (Scanner.zig, test_command.zig), docs, and tests. No TODOs/FIXMEs.

Review threads: 0 unresolved.

Hygiene: Branch farm/834a86b7/path-ignore-patterns follows naming convention. PR body is complete with issue refs (#27388, #21395, #13963).

Ready for human review and merge. (Re-verified Mar 14, last re-check: all gates still hold, CI completed, no new pushes or threads.)

@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author

Good call — GitHub's "Closes" keyword only auto-closes issues on merge, not other PRs. I'll close #27452 manually once this lands.

@coderabbitai

coderabbitai Bot commented Mar 14, 2026

Copy link
Copy Markdown
Contributor

Walkthrough

Adds test path exclusion via a new pathIgnorePatterns option (string or string array) in bunfig.toml, exposes --path-ignore-patterns CLI flag, parses and validates values, wires patterns into the test Scanner to prune directories and skip files, adds docs and tests covering behavior and errors.

Changes

Cohort / File(s) Summary
Documentation
docs/runtime/bunfig.mdx, docs/test/configuration.mdx
Add docs and examples for pathIgnorePatterns under [test], document CLI flag --path-ignore-patterns, and note directory pruning during scanning.
Config parsing & CLI options
src/bunfig.zig, src/cli.zig, src/cli/Arguments.zig
Parse pathIgnorePatterns (accept string or array of strings) from bunfig, add path_ignore_patterns and path_ignore_patterns_from_cli to TestOptions, and add --path-ignore-patterns CLI parameter (CLI values override config).
Test discovery / Scanner
src/cli/test/Scanner.zig, src/cli/test_command.zig
Add path_ignore_patterns field and public matchesPathIgnorePattern(); use it to prune directory traversal and skip ignored files; set scanner patterns from test options.
Tests
test/cli/test/path-ignore-patterns.test.ts
Add comprehensive tests for TOML and CLI parsing, glob semantics (including **), directory pruning, CLI override behavior, invalid types/values, and expected inclusion/exclusion of test files.
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main feature being added: a CLI argument to exclude tests using path patterns.
Linked Issues check ✅ Passed The PR fully addresses all linked issue requirements: #27388 (skip test patterns like coverage feature), #21395 (pathIgnorePatterns with bunfig and CLI support), and #13963 (exclude tests via bunfig).
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing pathIgnorePatterns: bunfig parsing, CLI argument parsing, test scanner filtering, documentation, and comprehensive tests. No unrelated changes detected.
Description check ✅ Passed The PR description adequately covers both required template sections with clear explanations of functionality and comprehensive test verification.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/bunfig.zig`:
- Around line 487-490: The precedence check in the block handling
test_.get("pathIgnorePatterns") uses
this.ctx.test_options.path_ignore_patterns.len > 0 to infer a CLI override,
which prevents local bunfig values from overriding a previously loaded global
bunfig; change the logic to check an explicit flag (e.g.,
this.ctx.test_options.path_ignore_patterns_from_cli) instead of length so only
an actual CLI-provided value blocks overrides, update all similar checks in the
surrounding block (the same pattern around lines handling pathIgnorePatterns
between the if and the following cases), and modify the CLI parsing code that
processes --path-ignore-patterns to set that boolean when the option is
provided.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3acbdf22-6d6d-4132-ae65-ea3708f62f00

📥 Commits

Reviewing files that changed from the base of the PR and between 1f134a1 and 4b3db3c.

📒 Files selected for processing (8)
  • docs/runtime/bunfig.mdx
  • docs/test/configuration.mdx
  • src/bunfig.zig
  • src/cli.zig
  • src/cli/Arguments.zig
  • src/cli/test/Scanner.zig
  • src/cli/test_command.zig
  • test/cli/test/path-ignore-patterns.test.ts

Comment thread src/bunfig.zig
@github-actions

Copy link
Copy Markdown
Contributor

Found 4 issues this PR may fix:

  1. Allow custom patterns for bun test #3440 - Directly requests custom patterns for bun test, which --path-ignore-patterns provides
  2. bun test with globs not detecting all tests #10353 - Reports glob pattern issues with test detection, addressed by improved pattern matching
  3. Support ignores in Bun.Glob options #8182 - Requests ignore functionality in Bun.Glob options, conceptually similar to test path exclusion
  4. exclude file pattern from entrypoints on bun build : --exclude=*.test.ts #15577 - Requests excluding test files from build using patterns, similar pattern-based exclusion concept

If this is helpful, consider adding Fixes #<number> to the PR description to auto-close the issue on merge.

🤖 Generated with Claude Code

Comment thread src/cli/test/Scanner.zig
Add explicit `path_ignore_patterns_from_cli` flag so local bunfig can
override global bunfig (previously the `.len > 0` check blocked it).

Also try matching directory paths with a trailing `/` so patterns like
`vendor/**` correctly prune directory subtrees during scanning.

https://claude.ai/code/session_01XUic2GpN4rRZw8bh19ALRT
Comment thread src/cli/test/Scanner.zig Outdated
@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author

⏳ Push 525b4dd: restricts trailing-slash pruning to ** patterns (addresses claude[bot] finding). Gates 2/4/5/6 pass. Waiting on CI build #39632...

Single-star patterns like "vendor/*" must not prune entire directory
trees during scanning. Only patterns containing "**" get the
trailing-slash retry, preventing over-pruning.

https://claude.ai/code/session_01XUic2GpN4rRZw8bh19ALRT
@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author

✅ All gates pass on 525b4dd. CI green (Buildkite #39632, Lint, Format). All 3 bot review threads resolved. PR description updated with verification summary. Awaiting human reviewer (Jarred-Sumner, alii, dylan-conway requested).

@claude claude Bot 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.

No bugs found and all previously raised issues are resolved. Deferring because this is a new feature touching core test discovery infrastructure (Scanner, bunfig, CLI args) where a maintainer should sign off on design choices.

Extended reasoning...

Overview

This PR adds --path-ignore-patterns as a CLI flag and pathIgnorePatterns as a bunfig.toml option for excluding test files/directories during bun test discovery. It touches 8 files: bunfig parsing (bunfig.zig), CLI option struct and argument parsing (cli.zig, Arguments.zig), the test scanner (Scanner.zig), wiring in test_command.zig, documentation (bunfig.mdx, configuration.mdx), and comprehensive tests (path-ignore-patterns.test.ts).

Security risks

No security concerns. The feature operates on local file paths using existing glob matching infrastructure. No user input reaches network calls, shell execution, or sensitive operations.

Level of scrutiny

This is a new user-facing feature that modifies the test scanner — a core code path for test discovery. While the implementation closely follows the existing coveragePathIgnorePatterns pattern (same bunfig parsing structure, same CLI arg style), the design decisions around naming (pathIgnorePatterns vs alternatives), glob semantics (directory pruning behavior, CLI-overrides-bunfig), and the trailing-slash heuristic for ** patterns deserve human review. A maintainer should confirm these choices align with Bun's overall design direction.

Other factors

  • All three issues raised during the review cycle (bunfig precedence bug, /** pruning failure, single-star over-pruning) have been addressed in the current diff.
  • CI passes (only pre-existing failures on main).
  • Tests cover single/array patterns, glob behavior, directory pruning, CLI override semantics, invalid config errors, and empty arrays.
  • The PR was AI-authored (claude label) and should receive human sign-off before merging.

@alii

alii commented Mar 14, 2026

Copy link
Copy Markdown
Member

@robobun Why do we have path_ignore_patterns_from_cli?

@robobun

robobun commented Mar 14, 2026

Copy link
Copy Markdown
Collaborator Author

It tracks whether --path-ignore-patterns was explicitly passed on the CLI, so that bunfig loading knows to skip overwriting it. Without it, the bunfig parser checked path_ignore_patterns.len > 0 to decide "CLI already set this, don't override" — but that breaks local-over-global bunfig layering (a global bunfig setting the field would prevent a local bunfig from overriding it). CodeRabbit caught this in the first review round and the fix was to use an explicit boolean instead of inferring from length.

In short: CLI --path-ignore-patterns should always win over bunfig, and local bunfig should win over global bunfig. The boolean makes the first rule work without breaking the second.

@robobun robobun requested a review from alii March 15, 2026 00:39
@alii alii merged commit 7a2ce3a into main Mar 15, 2026
63 of 65 checks passed
@alii alii deleted the farm/834a86b7/path-ignore-patterns branch March 15, 2026 04:33
alii added a commit that referenced this pull request Mar 15, 2026
Follow-up to #28089.

`matchesPathIgnorePattern` in `src/cli/test/Scanner.zig` allocates `var
buf: [bun.MAX_PATH_BYTES]u8` on the stack. On Windows that's `32767 * 3
+ 1` ≈ 96KB to hold a relative path from the project root plus a
trailing slash — realistically under 200 bytes.

Changes:
- Shrink the buffer to `[4096]u8` (POSIX PATH_MAX — covers any realistic
test directory depth)
- Hoist the `rel_path + '/'` construction outside the `for (patterns)`
loop since `rel_path` is loop-invariant (was re-memcpy'ing the same path
once per pattern)

Behavior is unchanged. If a relative path somehow exceeds 4095 bytes,
the trailing-slash fallback is skipped (same silent-degrade as before,
just at a lower threshold) — early directory pruning is lost for that
one path but files inside still get filtered by the direct glob match.
@robobun robobun mentioned this pull request Mar 16, 2026
@graffhyrum

Copy link
Copy Markdown

This is already in the docs despite not being available in 1.3.10. Is that intentional?
https://bun.sh/docs/test/configuration#path-ignore-patterns

structwafel pushed a commit to structwafel/bun that referenced this pull request Apr 25, 2026
### What does this PR do?

Picked up from oven-sh#27452 by @ctjlewis (requested by @alii in
oven-sh#27452 (comment)) so CI
runs automatically and the autofixer works.

All commits preserve original authorship (Lewis <lewis@spellcraft.org>).

---

Adds `--path-ignore-patterns` argument and Bunfig option similar to
`--coverage-path-ignore-patterns`.

https://bun.com/docs/test/configuration#coverage-path-ignore-patterns

- Closes oven-sh#27388
- Closes oven-sh#21395
- Closes oven-sh#13963

### How did you verify your code works?

Tests in `test/cli/test/path-ignore-patterns.test.ts` (328 lines).

### Docs

Simple docs added for Bunfig and Configuration docs.

### Verification

Buildkite #39573 on `1a1af82`: only CI failure is a snapshot mismatch in
`test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts` (111
passed, 1 failed snapshot) — completely unrelated to this PR. Main
branch also failing on all recent commits (builds #39449, #39406,
#39511, #39396). All 3 bot review threads resolved. Diff clean — no
TODOs, changes scoped to bunfig parsing, CLI args, test scanner, docs,
and tests. Ready for human review.

---
**Verification (robobun):** CI green (13/13 on `525b4dd`). Diff clean —
no TODOs, changes well-scoped to bunfig parsing, CLI args, test scanner,
docs, and tests. All 3 bot review threads resolved (coderabbit
precedence fix applied, trailing-slash pruning restricted to `**`
patterns). Feature PR — tests confirm baked binary lacks the feature (9
fail) while CI passes all platform suites.

---------

Co-authored-by: Lewis <lewis@spellcraft.org>
Co-authored-by: Alistair Smith <alistair@anthropic.com>
structwafel pushed a commit to structwafel/bun that referenced this pull request Apr 25, 2026
…ven-sh#28128)

Follow-up to oven-sh#28089.

`matchesPathIgnorePattern` in `src/cli/test/Scanner.zig` allocates `var
buf: [bun.MAX_PATH_BYTES]u8` on the stack. On Windows that's `32767 * 3
+ 1` ≈ 96KB to hold a relative path from the project root plus a
trailing slash — realistically under 200 bytes.

Changes:
- Shrink the buffer to `[4096]u8` (POSIX PATH_MAX — covers any realistic
test directory depth)
- Hoist the `rel_path + '/'` construction outside the `for (patterns)`
loop since `rel_path` is loop-invariant (was re-memcpy'ing the same path
once per pattern)

Behavior is unchanged. If a relative path somehow exceeds 4095 bytes,
the trailing-slash fallback is skipped (same silent-degrade as before,
just at a lower threshold) — early directory pruning is lost for that
one path but files inside still get filtered by the direct glob match.
brettimus added a commit to fiberplane/switchyard that referenced this pull request May 5, 2026
Verified after upgrading from Bun 1.3.10 to 1.3.13: the bunfig key now prunes
references/ during scan (oven-sh/bun#28089). Tightens the comments and AGENTS.md
callout to reflect the version requirement instead of a 'no-op' workaround.
xhjkl pushed a commit to xhjkl/bun that referenced this pull request May 14, 2026
### What does this PR do?

Picked up from oven-sh#27452 by @ctjlewis (requested by @alii in
oven-sh#27452 (comment)) so CI
runs automatically and the autofixer works.

All commits preserve original authorship (Lewis <lewis@spellcraft.org>).

---

Adds `--path-ignore-patterns` argument and Bunfig option similar to
`--coverage-path-ignore-patterns`.

https://bun.com/docs/test/configuration#coverage-path-ignore-patterns

- Closes oven-sh#27388
- Closes oven-sh#21395
- Closes oven-sh#13963

### How did you verify your code works?

Tests in `test/cli/test/path-ignore-patterns.test.ts` (328 lines).

### Docs

Simple docs added for Bunfig and Configuration docs.

### Verification

Buildkite #39573 on `1a1af82`: only CI failure is a snapshot mismatch in
`test/js/bun/test/snapshot-tests/snapshots/snapshot.test.ts` (111
passed, 1 failed snapshot) — completely unrelated to this PR. Main
branch also failing on all recent commits (builds #39449, #39406,
#39511, #39396). All 3 bot review threads resolved. Diff clean — no
TODOs, changes scoped to bunfig parsing, CLI args, test scanner, docs,
and tests. Ready for human review.

---
**Verification (robobun):** CI green (13/13 on `525b4dd`). Diff clean —
no TODOs, changes well-scoped to bunfig parsing, CLI args, test scanner,
docs, and tests. All 3 bot review threads resolved (coderabbit
precedence fix applied, trailing-slash pruning restricted to `**`
patterns). Feature PR — tests confirm baked binary lacks the feature (9
fail) while CI passes all platform suites.

---------

Co-authored-by: Lewis <lewis@spellcraft.org>
Co-authored-by: Alistair Smith <alistair@anthropic.com>
xhjkl pushed a commit to xhjkl/bun that referenced this pull request May 14, 2026
…ven-sh#28128)

Follow-up to oven-sh#28089.

`matchesPathIgnorePattern` in `src/cli/test/Scanner.zig` allocates `var
buf: [bun.MAX_PATH_BYTES]u8` on the stack. On Windows that's `32767 * 3
+ 1` ≈ 96KB to hold a relative path from the project root plus a
trailing slash — realistically under 200 bytes.

Changes:
- Shrink the buffer to `[4096]u8` (POSIX PATH_MAX — covers any realistic
test directory depth)
- Hoist the `rel_path + '/'` construction outside the `for (patterns)`
loop since `rel_path` is loop-invariant (was re-memcpy'ing the same path
once per pattern)

Behavior is unchanged. If a relative path somehow exceeds 4095 bytes,
the trailing-slash fallback is skipped (same silent-degrade as before,
just at a lower threshold) — early directory pruning is lost for that
one path but files inside still get filtered by the direct glob match.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

5 participants