Repository navigation
test(grep): pin -l/-L parity with grep, including numeric patterns - #3258
Conversation
34e1fb9 to
f7179f4
Compare
KuSh
left a comment
There was a problem hiding this comment.
The core change is right, and I verified the mechanism against a built binary: with no short on --max-len, a leading -l flows into extra_args, has_format_flag sees l/L, and the raw-grep passthrough reproduces GNU semantics. src/hooks/init.rs:203 already documents -l/-L as raw format flags, so this aligns the parser with the shipped agent instructions.
Two things to fix before merge — see the inline comments. The benchmark line is the blocker: the new form is not parsed as --max-len at all and now makes that bench report ❌ FAIL.
One thing worth adding to the PR description: this change is silent for existing users of the old spelling. rtk grep -l 40 <pat> <path> used to (wrongly) hit the passthrough; it now searches for the literal pattern 40 in <pat> and <path> with no error.
|
Both inline points fixed in
Also folded your note about the silent behavior change into the PR description.
|
|
Thanks for the quick turnaround — both review points are fixed and I've verified each in a clean worktree at
Unfortunately
That is why the PR now shows conflicts in three files: One hunk is genuinely new and worth keeping: Could you rebase onto
Sorry for the churn; the duplication is on our side, not yours — you and the |
|
Friendly nudge: both review threads were verified and resolved on 2026-09-02 — the benchmark line now parses |
What about my comment from 2 dans ago and the fact that it conflicts on most of the files you touched? |
`-l` was bound to RTK's `--max-len`, colliding with GNU grep where `-l` means `--files-with-matches`. Running `grep -l <pattern>` made clap read the pattern as a usize and error (`invalid value '<pattern>' for '--max-len'`), dropping the command to a raw-grep fallback at 0% savings. Drop the short binding. `-l`/`-L` now flow to `extra_args`, where the existing `has_format_flag` already routes them to the grep passthrough (GNU semantics, minimal output). `--max-len` keeps its long form and its default of 80; nothing internal used the short. - src/main.rs: remove `short = 'l'` from `Grep::max_len` + clap-parse regression test. - tests/grep_faithful_format_test.rs: end-to-end test asserting `rtk grep -l/-L` is byte-identical to `grep -l/-L`, covering `-l` leading and trailing. - scripts/benchmark.sh: the max-len bench used the old `-l 40` alias -> `--max-len 40`. - docs/usage/FEATURES.md: drop the `-l` short from the grep options table.
…_grep Address review: - benchmark.sh: with trailing_var_arg on extra_args, --max-len after the positionals was swallowed and forwarded raw to grep (unknown option -> bench FAIL). Move it before -rn/pattern so rtk parses it; verified 320KB -> 14.8KB (~95%) and that --max-len 40 vs 200 changes output size. - grep_faithful_format_test: the inline cmp closure duplicated the existing assert_eq_grep helper (rtk_grep + grep_plain, same stdout/exit asserts); drop it in.
ea60b8f to
74ec070
Compare
|
Rebased onto the current |
A non-numeric pattern stops at clap's parse error and falls back to raw grep, so rtk and grep agree byte-for-byte whether or not `-l` is bound to --max-len: the three existing cases still pass with the bug reintroduced. Only a numeric pattern reaches the wrong answer -- rtk printed nothing and exited 1 where grep listed the file. Drop the clap-level test and the comment sentence with it. Develop's test_grep_parse_files_with_matches_l already fails under the same mutation, and -L never had a short binding on --max-len, so src/main.rs is untouched. Co-Authored-By: Claude Opus 5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 3 of 3 — APPROVED
Claim: after the rebase this is a tests-only PR adding the end-to-end -l/-L coverage develop lacks.
Scope: accept (round 1, frozen). The substance changed underneath it — 16228b74 landed the same fix on develop — but the remaining test is worth having.
Ran: head in a dedicated worktree against latest develop; fmt --check clean, clippy --all-targets -D warnings 0 warnings, test --all green (3329 passed, 0 failed); differential sweep vs /usr/bin/grep (LC_ALL=C) 17/17 identical.
Blocks merge (0)
Both round-1 items were fixed in ea60b8f and verified; those threads are resolved. Nothing in the pushed code is a silent loss or a regression against develop.
What I found, and a correction I owe you
The integration test did not detect the regression it claimed to pin. With #[arg(short = 'l', ...)] restored on max_len, dash_l_and_dash_cap_l_match_grep still reported ok. A non-numeric pattern like tenant_id stops at clap's parse error and falls back to raw grep, so stdout and exit code are byte-identical either way. Only a numeric pattern diverges:
rtk grep -l 8080 port.txt miss.txt -> (no output) exit 1
grep -l 8080 port.txt miss.txt -> port.txt exit 0
And the correction: last round I called the integration test "the only salvageable hunk" and said the clap test was superseded and could be skipped. That was backwards — the clap test was the one actually catching the regression. You were right to keep it.
Fixup pushed (d554bef2)
- Adds the numeric-pattern cases for
-land-L. Verified both ways: fails with the bug reintroduced, passes clean. - Drops the clap-level test and the
-Lcomment sentence with it. Develop'stest_grep_parse_files_with_matches_lalready fails under the same mutation, so the coverage is not lost, and-Lnever had a short binding on--max-len.src/main.rsis now untouched by this PR.
Net effect: coverage went up, not down — the regression is now pinned at both the parse level (develop's test) and the behavioural level (this one), where before the rebase only the parse level held it.
I also trimmed the PR description, which still described the benchmark.sh, docs and main.rs changes that are no longer in the diff.
Your questions
- "Could you re-review when you have a moment?" / "Ready for re-review" -> Done. The stale CHANGES_REQUESTED was the only thing holding this; this approval lifts it.
Next
Nothing — approving. Sorry for the long round trip on what ended up a 26-line test.
Rounds: 3/3. Threads: 0 open, 2 resolved.
Summary
rtk grep's-lshort was bound to--max-len, colliding with GNU grep where-l=--files-with-matches. That fix has since landed ondevelopin16228b74, along with the-m/--max-countand-t/--file-typecollisions and thescripts/benchmark.shand docs edits this PR originally carried.After the rebase this PR is tests only — it adds the end-to-end coverage
developstill lacks:dash_l_and_dash_cap_l_match_grepassertsrtk grep -l/-Lis byte-identical togrep -l/-L(stdout and exit code), covering-lleading,-ltrailing, and-L.-lbound to ausize, a non-numeric pattern only ever reached clap's parse error and the raw-grep fallback — byte-identical to grep, and therefore invisible to a parity test. Only a numeric pattern diverged:developpins the parse level withtest_grep_parse_files_with_matches_l; this adds the behavioural level. No production code is touched.Test plan
cargo fmt --all -- --checkclean;cargo clippy --all-targets -- -D warnings0 warnings;cargo test --allgreen (3329 passed, 0 failed).#[arg(short = 'l', ...)]onmax_lenmakes bothdash_l_and_dash_cap_l_match_grepand develop'stest_grep_parse_files_with_matches_lfail; reverting makes them pass./usr/bin/grep(LC_ALL=C), 17/17 identical:-l/-Lleading and trailing, numeric patterns,-rl/-rLclusters,-il,-lv,-lZ,-c,-o, and no-match exit codes.