Skip to content

fix(gradle): remove the unreachable gradle.toml filter - #2709

Merged
KuSh merged 2 commits into
rtk-ai:developfrom
guyoron1:fix/gradle-filter-regex-match
Sep 25, 2026
Merged

KuSh merged 2 commits into
rtk-ai:developfrom
guyoron1:fix/gradle-filter-regex-match

Conversation

@guyoron1

@guyoron1 guyoron1 commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Deletes src/filters/gradle.toml and updates the two hard-coded built-in filter counts (63 -> 62 in test_builtin_filter_count, 64 -> 63 in test_new_filter_discoverable_after_concat).

Why: the original premise was wrong

This PR first proposed widening match_command to ^(\./)?(gradlew?)\b. KuSh's review showed that fixes nothing and breaks two things, and I reproduced his findings independently:

  • src/discover/rules.rs already routes the whole family: gradle build, gradle bootRun, gradlew build, ./gradlew build and gradlew.bat clean all rewrite to rtk gradlew and reach the Rust gradlew_cmd, which even falls back to the system gradle binary. Nothing was falling through unfiltered.
  • Both TOML lookup call sites reduce argv[0] to its basename first (run_fallback in main.rs, strip_absolute_path on the hook path), so the ./ branch, the regex's only real match, is unreachable at every call site. gradle.toml has filtered nothing since it landed: basename logic adda2537 (2026-03-10), file added 8fae5b06 (2026-03-18). Verified with a stand-in gradle: rtk gradle build returns byte-identical raw output today, not what the filter's own inline test expects.
  • Widening it would shadow spring-boot.toml (BTreeMap ordered by filter name, first match wins, gradle < spring-boot), turning a diagnosed bootRun failure into head-truncated INFO noise, and would pull gradle-profiler / gradle.bat into a max_lines = 50 head cut that discards the result line.

Proof it changes nothing

Built both binaries and compared rtk rewrite for nine gradle spellings (gradle build, gradle bootRun, gradlew build, ./gradlew build, gradlew.bat clean, gradle test, gradle clean assemble, and the two that must not rewrite, gradle-profiler benchmark and gradle.bat build), plus real execution of rtk gradle build|bootRun|test and rtk gradlew build through stand-in tools: identical on every one. rtk gradle bootRun keeps its spring-boot.toml filtering. cargo test --all matches the baseline (3734 passed), clippy 0 warnings, fmt clean.

Making TOML filters reachable from the default passthrough is the separate design question in #3904 and is deliberately not attempted here.

Refs #2708

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at head 0801879b, built and tested merged into today's develop (5e10aa64), not on the branch alone. Merges cleanly; CLA signed; all 12 checks green. Real binaries, real producer shims, LC_ALL=C.

The regex reading in #2708 is correct — ^(gradle|gradlew|\./)gradlew?\b really does require an impossible gradlegradle. But the stated impact is not, and that changes what the fix should be.

The premise doesn't hold

src/discover/rules.rs:785 already rewrites the whole gradle family. Confirmed against both binaries:

rtk rewrite "gradle build"     → rtk gradlew build      (identical on develop and this PR)
rtk rewrite "gradle bootRun"   → rtk gradlew bootRun
rtk rewrite "gradlew build"    → rtk gradlew build
rtk rewrite "./gradlew build"  → rtk gradlew build

So gradle build was never "falling through to unfiltered output" — it goes to the Rust gradlew_cmd, which even falls back to the system gradle binary when no wrapper exists (gradlew_cmd.rs:72-78).

The ./ rows of the table are also wrong: run_fallback matches against the basename of args[0] (main.rs:1483-1487), so ./gradlew arrives as gradlew. The old regex matched nothing at all, and the new (\./)? group is unreachable at the only call site.

gradle.toml has in fact never filtered a single invocation: the basename logic landed adda2537 (2026-03-10), the file was added 8fae5b06 (2026-03-18). It was born unreachable.

Two regressions from widening it

Details in the inline comments. In short: the widened pattern feeds the hook's rewrite decision, so gradle-profiler and gradle.bat are now actively routed into a lossy filter (201 lines → 52, result line discarded); and it shadows spring-boot.toml, turning a diagnosed startup failure into 50 lines of INFO noise.

The regex is the wrong lever

gradle.toml is dead from unreachability, not redundancy — gradlew_cmd classifies build/test/lint/dependencies/connected and drops everything else into GradlewTask::Other → run_passthrough, fully unfiltered:

rtk gradlew bootRun   164 lines in → 164 out
rtk gradlew publish   164 lines in → 164 out
rtk gradlew build     164 lines in →   2 out

So the noise this filter targets is exactly the noise gradlew_cmd declines to touch, and routing guarantees they never meet. Widening the match_command can't fix that; it only makes the filter capture neighbouring tools instead.

Two coherent ways forward:

  1. Delete src/filters/gradle.toml. Costs nothing — it has never filtered anything. Update test_builtin_filter_count 63→62 and drop "gradle" from the expected-names list. Leaves spring-boot.toml working.
  2. Make it reachable properly — let default passthrough consult TOML filters. Filed as #3904 with the design; FilterMode::Buffered already exists unused for exactly this. That is core-architecture work and explicitly not something to ask of this PR.

Also worth noting: nothing anywhere tests which filter a command line selects — run_filter_tests only runs the [[tests.*]] pipeline cases and never evaluates match_command. A table-driven selection test would have caught both regressions at author time.

Thanks for the careful regex analysis in #2708 — the reading is right, it's the routing underneath that makes the conclusion come out differently.

Comment thread src/filters/gradle.toml Resolved
Comment thread src/filters/gradle.toml Resolved
Its match_command, `^(gradle|gradlew|\./)gradlew?\b`, needs a doubled
token (`gradlegradle`) or a literal `./gradle…`. Both call sites reduce
argv[0] to its basename before the lookup — `run_fallback` in main.rs and
`strip_absolute_path` on the hook rewrite path — so the `./` branch is
unreachable too. The filter has matched nothing since it landed: the
basename logic arrived in adda253 (2026-03-10), the file in 8fae5b0
(2026-03-18).

Deleting it changes no output. `src/discover/rules.rs` already routes the
whole gradle family (`gradle`, `gradlew`, `./gradlew`, `gradlew.bat`) to
`rtk gradlew` and the Rust gradlew_cmd, and `gradle … bootRun` is filtered
by spring-boot.toml. Widening the regex instead would have shadowed
spring-boot.toml — first match wins, ordered by filter name — and pulled
gradle-profiler and gradle.bat into a head-truncating filter.

Making TOML filters reachable from the default passthrough is a separate
design question, tracked in rtk-ai#3904.

Refs rtk-ai#2708
@guyoron1 guyoron1 changed the title fix(gradle): correct match_command regex to match bare gradle/gradlew fix(gradle): remove the unreachable gradle.toml filter Sep 21, 2026
@guyoron1
guyoron1 force-pushed the fix/gradle-filter-regex-match branch from 0801879 to 757188f Compare September 21, 2026 12:03
@guyoron1

Copy link
Copy Markdown
Contributor Author

@KuSh you're right on all counts. I checked each claim against binaries before deleting anything: the rewrite rule already covers the whole gradle family, both TOML lookup call sites reduce argv[0] to its basename (so the ./ branch is unreachable at run_fallback and at the hook path's strip_absolute_path), and with gradle.toml in place rtk gradle build returns byte-identical raw output today, so it never ran.

So I went with your option 1. The regex commit is replaced by a single commit that deletes src/filters/gradle.toml. Two count pins needed updating rather than one: test_builtin_filter_count (63 -> 62) and test_new_filter_discoverable_after_concat (64 -> 63). test_builtin_all_expected_filters_present doesn't list "gradle" on current develop, so nothing changed there, and no doc mentions the filter.

Proof it changes nothing: rtk rewrite across nine gradle spellings and real execution of rtk gradle build|bootRun|test and rtk gradlew build are identical before and after, and rtk gradle bootRun keeps its spring-boot.toml filtering. I've left #3904 alone. The title and description are updated, since the old ones described the regex fix.

The module map in the search-strategy rule still counted 63 TOML filter
configs; src/filters/ now holds 62.

@KuSh KuSh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Round 2 of 3 — APPROVED

Claim: delete src/filters/gradle.toml, a built-in filter that has never been reachable, and correct the two hard-coded built-in counts.
Scope: accept. (Round 1 predates the current review template; verdict stated here and frozen.)
Ran: stand-in gradle/gradlew/gradle-profiler/gradle.bat replaying this repo's own captured fixtures (tests/fixtures/gradlew_{build,build_failed,test,test_failed,lint}_raw.txt) plus spring-boot.toml's committed bootRun input — 9 rewrite spellings + 18 execution rows (green, failing, empty, noise-only, missing-tool) + split streams + 5 exit codes + rtk verify, develop vs head-merged-on-develop, binaries md5-distinct; invariants: under the hook, split streams, every decision branch, over-cap accounting; savings 74% on the bootRun row against the 20% floor (CONTRIBUTING.md).
CI @3729bc41: 11/11 pass, including macOS, Ubuntu and Windows.

Blocks merge (0)

Both round-1 blockers are dissolved rather than waived: they were anchored on the widened match_command line, and that line no longer exists.

Every gradle-family spelling is byte-identical before and after, exit codes included:

row develop this PR
rtk rewrite × 9 spellings — identical
gradle build / test / lint / publish / tasks raw passthrough byte-identical
gradlew build / test / lint / bootRun — byte-identical
gradle bootRun 88 B (spring-boot keep-list) 88 B, identical
gradle-profiler / gradle.bat raw raw
split streams (large stderr) 1385 + 8530 B identical
exit codes 0/1/2/42/127 propagated identical
rtk verify 154/154 151/151

Two of those carry the weight. gradle build's output is byte-identical to the raw fixture on develop, which is the direct proof the filter never fired rather than an inference from the pattern. And rtk verify drops exactly 3, matching the file's three inline [[tests.gradle]] blocks, so the accounting closes with nothing unexplained. gradle bootRun keeps spring-boot.toml's filtering on both sides, verified by mechanism — the output is exactly that filter's keep-list — not by the byte count alone.

Both new pins are live gates at their new values, not merely self-consistent: adding a filter file fails test_builtin_filter_count with "got 63" against 62, and test_new_filter_discoverable_after_concat with "Expected 63". develop carries 63 filter files, this branch 62.

Re-checked before approving: src/filters/, src/core/toml_filter.rs and build.rs are unchanged on develop since the matrix run, so the count of 62 is still right at merge time. Gate on the pushed commit merged onto current develop: fmt clean, clippy --all-targets 0 warnings, cargo test --all 3937 passed / 0 failed.

Fixup pushed

3729bc41 — .claude/rules/search-strategy.md:65 still described src/filters/ as holding 63 TOML filter configs. One line, docs only; it touches no code path and no matrix row, and CI's doc review job is green on it.

Filed as follow-ups

Both pre-existing and untouched by this diff, so evidence went to #3402 (which already owns this class) rather than into new issues:

  • test_builtin_all_expected_filters_present calls itself "the safeguard against accidentally deleting a filter file" but lists only 41 of the 62 names. Verified by mutation: delete turbo.toml, bump the two counts, and all four enumerating tests stay green. This PR is exactly the case that comment claims to cover, and the only thing that actually noticed was the hand-maintained count pin — which you updated correctly, including the second one.
  • build.rs:54's duplicate-filter-name detection is unreachable: the combined document's own parse rejects a duplicate key first. Duplicates are still caught loudly, so it is a dead diagnostic rather than a hole.

Checked and correct — no need to re-verify

  • "gradle" is absent from test_builtin_all_expected_filters_present's list, so nothing there needed changing; you were right.
  • Nothing else enumerates, counts, hashes or name-looks-up the built-in blob: active_filter_summaries and count_custom_toml_filters read only on-disk project and global filters, the pinned SHA-256s in init.rs cover the awareness payloads rather than the filter blob, and the anchoring and inline-test sweeps iterate whatever is present.
  • Removing the key cannot reorder the rest (BTreeMap keyed by filter name), and the old pattern matched only ./gradle… forms, so it never shadowed another filter.
  • No doc other than the one in the fixup carried a filter count.

Hypotheses built and dropped

  • "spring-boot becomes newly reachable for gradle bootRun" — dropped: it already matched on develop, because the old gradle pattern never matched that string. The 88-byte output is identical on both sides.
  • "./gradle <task> loses its only handler" — dropped: no rule rewrites it in either tree, and the wrapper is always named gradlew.

Your questions

  • "Two count pins needed updating rather than one" → correct, and both values are individually right; mutation-confirmed.
  • "test_builtin_all_expected_filters_present doesn't list gradle, so nothing changed there" → confirmed. It also cannot see 21 of the 62, but that gap is #3402's, not this PR's.
  • "I've left #3904 alone" → the right call. #3904 turned out to overlap #3402, which predates it; I've commented on both to sort that out.

Next

Nothing — approving. Thank you for re-deriving the findings against binaries yourself before deleting anything, and for writing up why the original premise was wrong; that made this round short.

Rounds: 2/3. Threads: 0 open, 2 resolved this round.

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.

2 participants