feat(core): broaden .understandignore starter — Rust test/bench patterns#582
Merged
Lum1104 merged 5 commits intoJul 19, 2026
Merged
Conversation
Rust's official Cargo convention is `benches/` (plural, trailing `s`), matching the target type documented at https://doc.rust-lang.org/cargo/reference/cargo-targets.html — every `.rs` file under that directory compiles as a separate benchmark binary. The existing list picked up the C++-style `bench` / `benchmark` / `benchmarks` variants but missed the Rust one, so Cargo workspaces were silently getting their criterion / test::Bencher sources indexed. Add the plural form as a case-insensitive exact-name match. Also useful to any language that adopts the naming (some Go and Zig projects use `benches/` too).
Rust's dominant unit-test convention is inline `#[cfg(test)] mod tests
{ ... }` blocks that cannot be excluded by filename — anyone wanting to
strip those has to post-process the source. The one file-pattern the
Rust Book (chapter 11.3) does describe is extracting that block into a
sibling `tests.rs` file next to `mod.rs` or `lib.rs`; that extracted
form is what a `**/tests.rs` rule can catch.
Integration tests already live under `tests/` (existing dir rule) and
benchmarks under `benches/` (added in the previous commit), so the
new file-pattern group is deliberately minimal — just the one glob
the community has actually converged on.
Tests: assert the Rust sub-header + pattern emission, and extend the
stable-order invariant to place Rust after Python.
Measurement across 10 large public Rust repos showed the tests.rs-only group carries almost no weight — the majority of file-glob hits come from workspaces that colocate a `foo_test.rs` next to `foo.rs` rather than using extracted `tests.rs` modules. In paritytech/polkadot-sdk this shape accounts for 232 files and a 15% reduction on the analysed budget; in rust-lang/rust it accounts for 253 files (3% reduction on the truncated tree, i.e. a lower bound). Add: **/test_*.rs — pytest / unittest style (less common in Rust) **/*_test.rs — dominant convention in Rust workspace monorepos Kept as separate globs from `**/tests.rs` so users on projects that follow the Rust Book pattern (single sibling tests.rs per module) aren't forced to also strip a naming shape they never use.
Most Rust benchmarks live under `benches/` (already covered by the directory rule added earlier in this branch), so these file-name patterns are mostly a defensive belt-and-braces for the small set of Cargo workspaces that keep bench targets alongside library code rather than under the canonical `benches/` tree. Kept commented-out; contributes negligibly to the token savings for mainstream layouts but preserves symmetry with the C++ group, which already ships `*_benchmark.cc` and `*Benchmark.cpp`.
The initial comment implied `tests.rs` was the load-bearing pattern.
Measurement across 10 major public Rust repos (rust-lang/rust, tokio,
cargo, ripgrep, alacritty, helix, deno, solana, foundry, polkadot-sdk)
showed the actual distribution is bimodal:
- Library-scale crates keep tests inline via `#[cfg(test)] mod`,
which no file-pattern rule can touch → group is a near-noop.
- Workspace monorepos colocate `foo_test.rs` beside `foo.rs` at
scale → `*_test.rs` alone accounts for the vast majority of hits
(232 in polkadot-sdk, 253 in rust-lang/rust even with truncated
tree).
Rewrite the block comment so a future reader lands on the right mental
model — the extracted `tests.rs` form is legitimate but rare; the win
comes from the colocated shape in workspace-heavy repos.
Contributor
Author
|
@Lum1104 Please take a look. |
Collaborator
|
Great, thanks for the PR! |
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
EXACT_DIR_NAMES+=benches— Cargo's canonical plural benchmark directory (currently only the singular / C++-stylebench/benchmark/benchmarksvariants are recognised).TEST_PATTERN_GROUPSentryRustwith 5 patterns (Rust Booktests.rs, colocated*_test.rs/test_*.rs, criterionbench_*.rs/*_bench.rs).ignore-generator.test.ts; ordering invariant extended to place Rust after Python.scala-extractor.test.ts/swift-extractor.test.tsreproduce unmodified onorigin/main).SKILL.mdunchanged — Phase 0.5 delegates togenerate-ignore.mjssince a0155c5, so no inline duplicate to keep in sync.Why these patterns (and not others)
Rust testing is bimodal:
#[cfg(test)] mod tests { … }— no file-pattern rule can touch them, group is a near-noop.foo_test.rsnext tofoo.rsat scale — dir rules miss them entirely; file patterns are load-bearing.Rejected as too project-specific or ambiguous:
**/*Test.rs(PascalCase Rust filenames are rare — snake_case dominates),**/it_*.rs/**/*_it.rs(no Rust ecosystem uses "IT" as an integration-test marker — integration tests live undertests/),**/*Bench.rs(PascalCase, effectively unused).Kept
**/tests.rsand**/*_test.rsas separate globs so users on Rust Book–style projects (single siblingtests.rsper module) aren't forced to also strip a colocated-file shape they never use.Token impact (measured across ~60 public Rust repos)
Methodology:
gh api .../git/trees?recursive=1, Rust source =.rs, 1 MiB ≈ 262K tokens. Two hero projects reported below — the highest percentage win and the highest absolute win — because Rust's ecosystem produces genuinely bimodal savings.paritytech/parity-commonparitytech/polkadot-sdkparity-common— small utility-crate monorepo, best % result in the survey. Colocated*_test.rsfiles dominate the source tree.polkadot-sdk— largest absolute saving. 232 files match the new file globs; 28 more sit underbenches/subdirs the current rule misses. All reside outside the current directory-ignore surface (substrate/frame/**/*_test.rssits directly next to the pallet source).Unlike C++ (PR #480, up to 62% on nlohmann/json) and Python (PR #579, 47% on tensorflow), Rust never approaches those percentages in the wild because the dominant unit-test convention is inline
#[cfg(test)] mod tests { … }— invisible to any file-pattern rule. That's the ecosystem, not a gap in these patterns. The opt-in model means library-scale projects incur zero behaviour change unless they uncomment the group; monorepo workspaces see the parity-common / polkadot-sdk-scale savings the moment they do.Test plan
pnpm --filter @understand-anything/core build— cleanpnpm --filter @understand-anything/core exec vitest run src/__tests__/ignore-generator.test.ts— 45/45 pass (4 new Rust tests + thebenches/dir test)pnpm --filter @understand-anything/core test— 866 pass, 2 pre-existing wasm-module failures also present onorigin/main(unrelated: scala-extractor, swift-extractor)pnpm lint— clean.understandignoreon a fixture withbenches/,tests/, plus a colocatedfoo.rs+foo_test.rs— Rust group emitted after Python, all five patterns present,# benches/in the detected-dirs section, all commentedCloses #581