Skip to content

feat(core): broaden .understandignore starter — Rust test/bench patterns#582

Merged
Lum1104 merged 5 commits into
Egonex-AI:mainfrom
thejesh23:feat/understandignore-rust-test-patterns
Jul 19, 2026
Merged

feat(core): broaden .understandignore starter — Rust test/bench patterns#582
Lum1104 merged 5 commits into
Egonex-AI:mainfrom
thejesh23:feat/understandignore-rust-test-patterns

Conversation

@thejesh23

@thejesh23 thejesh23 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • EXACT_DIR_NAMES += benches — Cargo's canonical plural benchmark directory (currently only the singular / C++-style bench / benchmark / benchmarks variants are recognised).
  • New TEST_PATTERN_GROUPS entry Rust with 5 patterns (Rust Book tests.rs, colocated *_test.rs / test_*.rs, criterion bench_*.rs / *_bench.rs).
  • +4 tests in ignore-generator.test.ts; ordering invariant extended to place Rust after Python.
  • build + lint clean; ignore-generator suite 45/45 pass, core suite 866 pass (2 pre-existing wasm module resolution failures on scala-extractor.test.ts / swift-extractor.test.ts reproduce unmodified on origin/main).

SKILL.md unchanged — Phase 0.5 delegates to generate-ignore.mjs since a0155c5, so no inline duplicate to keep in sync.

Why these patterns (and not others)

Rust testing is bimodal:

  • Library-scale crates (ripgrep, alacritty, helix, cargo) keep unit tests inline in #[cfg(test)] mod tests { … } — no file-pattern rule can touch them, group is a near-noop.
  • Workspace monorepos (polkadot-sdk, solana, rust-lang/rust) colocate foo_test.rs next to foo.rs at 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 under tests/), **/*Bench.rs (PascalCase, effectively unused).

Kept **/tests.rs and **/*_test.rs as separate globs so users on Rust Book–style projects (single sibling tests.rs per 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.

Project Before (analyzed) After (analyzed) Reduction
paritytech/parity-common 0.52 MB / ~0.13M tok 0.37 MB / ~0.09M tok −0.04M (28%)
paritytech/polkadot-sdk 51.84 MB / ~12.95M tok 44.14 MB / ~11.03M tok −1.92M (15%)
  • parity-common — small utility-crate monorepo, best % result in the survey. Colocated *_test.rs files dominate the source tree.
  • polkadot-sdk — largest absolute saving. 232 files match the new file globs; 28 more sit under benches/ subdirs the current rule misses. All reside outside the current directory-ignore surface (substrate/frame/**/*_test.rs sits 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 — clean
  • pnpm --filter @understand-anything/core exec vitest run src/__tests__/ignore-generator.test.ts — 45/45 pass (4 new Rust tests + the benches/ dir test)
  • pnpm --filter @understand-anything/core test — 866 pass, 2 pre-existing wasm-module failures also present on origin/main (unrelated: scala-extractor, swift-extractor)
  • pnpm lint — clean
  • Manual preview of generated .understandignore on a fixture with benches/, tests/, plus a colocated foo.rs + foo_test.rs — Rust group emitted after Python, all five patterns present, # benches/ in the detected-dirs section, all commented

Closes #581

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.
@thejesh23

Copy link
Copy Markdown
Contributor Author

@Lum1104 Please take a look.
Will do it language by language over next 2 weeks as it's easier for review , test and small investigation usually required per language due to unique test convention of each language.

@Lum1104

Lum1104 commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Great, thanks for the PR!

@Lum1104
Lum1104 merged commit 5c3bc1b into Egonex-AI:main Jul 19, 2026
2 checks passed
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.

feat(core): broaden .understandignore starter — Rust test/bench patterns

2 participants