Repository navigation
fix(diff): report a one-operand call as a usage error with exit 2 (fixes #4320) - #4383
Conversation
Real `diff <file>` with one operand reports `diff: missing operand after '<file>'` and exits 2 before opening the file. rtk treated the single operand as the stdin form, ignored the file, echoed stdin back as a diff to condense, and exited 0 — so a `diff <file> && next` step ran where `diff` would stop, and a missing operand was never reported. The `-` operand still reads a piped diff from stdin; only a real file operand alone takes the usage-error path. The hook rewrites a bare `diff <file>` to `rtk diff <file>`, so the command an agent wrote now fails where the tool it stands in for fails. Fixes rtk-ai#4320.
- one_file_operand_is_a_usage_error_not_a_stdin_condense: `rtk diff <file>` exits 2 with diff's `missing operand after` message, and stdin is not echoed back as a diff. - explicit_stdin_dash_still_condenses: `rtk diff -` keeps reading a piped diff from stdin and exits 0.
📊 Automated PR Analysis
SummaryFixes a bug where Review Checklist
Linked issues: #4320 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
The one-operand test ran with stdin closed and an existing file, so a branch that still condensed stdin, or opened the operand first, passed it. Pipe a diff in, name a missing file, and assert empty stdout, the usage error and no read error. Also state the comment positively, give FILE2's help the real rule, and replace the FEATURES.md line that documented the removed form. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — APPROVED
Claim: rtk diff <file> with a single file operand reports diff's usage error and exits 2 instead of condensing stdin; rtk diff - keeps condensing a piped unified diff.
Scope: accept (round 1, frozen). #3781 edits the same Diff doc comment and FEATURES.md line; this one lands first, #3781 rebases onto it.
Ran: base 3a12dfe37 vs head × 17 operand forms vs GNU diff 3.12, LC_ALL=C: one operand (existing file, missing file, spaced name, ./-, /dev/stdin, -- o.txt) with stdin from a file and from /dev/null; - with a piped diff and with /dev/null; two operands identical / different / missing; - o.txt, o.txt -; the forms clap hands to diff ('', -u o.txt, three operands). Invariants: under the hook (rtk rewrite "diff o.txt" → rtk diff o.txt; rtk diff o.txt && echo next now stops, rc 2), every decision, exact conditions (stdin /dev/null and a piped file). Savings: n/a — the new path prints only the usage error; the - and two-file paths are byte-identical before/after.
Pins: 3 decisions (- guard, exit 2, usage error before any read), 7 mutated, 2 survived the PR's own tests (echo stdin before the error; open the operand before the error) — both killed by the fixup's test.
Matrix: executed this round; pin check: executed this round
CI @b17a355b2: all green (11/11)
Blocks merge (0)
Checked and correct — no need to re-verify
- Every one-operand file form now matches GNU diff: rc 2,
diff: missing operand after '<f>', nothing on stdout, the operand never opened (a missing file gets the usage error, not a read error). - Only a byte-exact
-reaches the stdin mode;./-and/dev/stdinget the usage error, as with diff. - Two-operand results and exit codes (0/1/2) are unchanged, as are the clap-fallback forms that already ran the real
diff. - fmt, clippy and
cargo test --allpass on the head and on the head merged onto currentdevelop.
Your questions
- "@KuSh could you please review?" → done, this is the review.
Next
Fixup b17a355 pushed, code-reviewed: it adds one_missing_operand_is_a_usage_error_before_any_read (piped diff on stdin, missing operand → rc 2, usage error, no read error, empty stdout), which fails if the branch condenses stdin or opens the file before erroring; it also states the branch comment without history, gives file2's help the real rule (omit only when the first operand is -), and replaces the FEATURES.md line that still documented rtk diff <fichier1> as "stdin as second file". Approving.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
Summary
Fixes #4320:
rtk diff <file>with a single file operand treated it as the stdin form — it ignored the file, echoed stdin back as a diff to condense, and exited 0. Realdiffreports a usage error and exits 2.Changes
Commands::Diffdispatch: with no second file, only the-operand reads a piped diff from stdin; a real file operand alone now prints diff's own message (diff: missing operand after '<file>') and exits 2, before opening the file — the same order realdiffuses, so a missing operand is reported too.Diffvariant doc now states the full contract: 0 identical, 1 different, 2 read error or usage error;-is the stdin form.Testing
one_file_operand_is_a_usage_error_not_a_stdin_condense: exits 2 with themissing operand aftermessage, stdin not echoed backexplicit_stdin_dash_still_condenses:rtk diff -keeps reading a piped diff and exits 0cargo fmt --all -- --check,cargo clippy --all-targets, andcargo test --allpass@KuSh could you please review?