Repository navigation
fix(ruff): preserve non-check subcommands - #3083
Conversation
46e8f30 to
bf2748b
Compare
known_ruff_subcommands_do_not_route_through_check iterates RUFF_SUBCOMMANDS, so dropping an entry from the constant leaves it green. Pin the list literally so a missing subcommand fails the suite. Co-Authored-By: Claude Opus 5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — APPROVED, follow-ups filed
Claim: ruff's non-check subcommands (rule, config, linter, clean, server, analyze, help, generate-shell-completion) must stop having check --output-format=json injected into them.
Scope: accept. (round 1, frozen)
Ran: real ruff 0.16.6, LC_ALL=C, ~35 invocations × {develop 665b272, this PR merged into it, native ruff}: all 11 subcommands, their error paths, implicit-path check, explicit check, format --check/--diff, top-level flags, and server under both a closed and an open stdin. Merge into current develop is clean (ort, no conflict); cargo fmt --all --check, cargo clippy --all-targets and cargo test --all (3260 passed, 0 failed) are all green on the merge result, which matters here because the branch predates develop's 44982e07/fa82e18d ruff changes. Savings on the check path unchanged at 99.5%, well above the 20% floor (CONTRIBUTING.md).
Blocks merge (0)
None. The allowlist is exactly ruff --help for 0.16.6 — check, rule, config, linter, clean, format, server, analyze, version, help — plus the hidden generate-shell-completion, which I confirmed still exists (ruff generate-shell-completion bash → exit 0). ruff does not infer abbreviated subcommands (ruff ver → unrecognized subcommand), so there is no partial-match gap.
The before/after is as bad as #2669 said, and worth recording since the hook rewrites every ruff … to rtk ruff …:
$ rtk ruff rule E501 # develop
Ruff: 2 issues in 2 files
Top rules:
E902 (2x)
Violations:
E501:1:1 E902 No such file or directory (os error 2) [exit 1]
$ rtk ruff rule E501 # this PR
# line-too-long (E501)
Derived from the **pycodestyle** linter.
... [exit 0]
That is a fabricated lint report, not an error — the worst failure shape rtk has. Same on config, linter, clean, help, analyze graph, generate-shell-completion.
Exit-code fidelity is right too, which is the part I most expected to break. On every error path the PR now returns ruff's own code where develop returned a confident 1:
| develop | this PR | native ruff | |
|---|---|---|---|
ruff analyze |
1 + fake E902 | 2 | 2 |
ruff rule |
1 + fake E902 | 2 | 2 |
ruff config nonexistent.option |
1 + fake E902 | 2 | 2 |
ruff generate-shell-completion |
1 + fake E902 | 2 | 2 |
And the paths the PR must not disturb are undisturbed: rtk ruff check src, rtk ruff ., rtk ruff src, rtk ruff check --statistics src, rtk ruff format --check/--diff src are byte-identical between develop and this PR (modulo the pre-existing HashMap ordering in filter_ruff_check_json's "Top files" block, which varies run-to-run on the same binary — sorted output is identical).
ruff server does not hang, which was my main worry given the hook rewrite: stdout_only() gives the child a null stdin, so it exits 2 immediately even when the parent's stdin stays open. Verified both ways.
Optional — will not hold merge
known_ruff_subcommands_do_not_route_through_checkiteratesRUFF_SUBCOMMANDS, so it cannot catch an entry going missing from the constant. Mutation-verified: deleting"rule"and"linter"leaves all 16 ruff tests green. It does bite on the routing logic — replacing the body with the old blocklist fails it. This mirrors the existingNPM_SUBCOMMANDStest, so it is precedent-consistent, not a defect; I have covered it with the fixup below rather than sending it back.rtk ruff linterloses the leading space on its first line (stdout.trim()), breaking the right-aligned prefix column. Cosmetic, and theelsebranch has always done this.
Filed as follow-ups
All five are on lines this PR does not touch, and all five reproduce identically on develop — none is a regression here.
- #3927 —
rtk ruff --select F401 srcexits 2 with no output:is_check_invocationbails on any leading-, so a flag-first implicit check is never routed tocheck. Pre-existing. - #3928 —
is_formatusesany(|a| a == "format")whileis_checkusesfirst(), sortk ruff help formatcomes back uncapped at 4889 bytes whilertk ruff help checkis capped at 2001. Correct output, accidental routing. Pre-existing; became observable here. - #3929 —
rtk ruff analyze graphis truncated atpassthrough_max_charsand emits unparseable JSON (12408 → 2001 bytes, cut mid-string). The cap is develop's (fa82e18d); this PR is what makes the path reachable, and it is still a large improvement on the fabricated E902 report it replaces. - #3930 —
filter_ruff_formatstill matches pre-0.12 wording (Would reformat:/left unchanged). ruff 0.16.6 saysunformatted:/already formatted, sortk ruff format --check .compresses 886 → 886 bytes: 0% savings against the 20% floor. Its two unit-test fixtures use the old strings, which is why the drift went unnoticed. Pre-existing. - #3931 —
ruff servershould not be proxied at all (null stdin + buffered stdout can never run an LSP). Not a regression — develop proxied it too, just more destructively.
Separately: rtk ruff rule NOSUCHRULE shows nothing at all because RunOptions::stdout_only() drops stderr. That is module-wide and pre-existing (identical on develop for rtk ruff format --nonexistent-flag), and #3772 already fixes it. Nothing owed here.
Checked and correct — no need to re-verify
- Allowlist completeness against ruff 0.16.6, including the hidden
generate-shell-completion; no subcommand inference to worry about. arg == "check"short-circuit ahead of thecontainscheck — needed, since"check"is in the list, and correct.filter_ruff_formatis a safe identity on non-format text:rtk ruff help formatandrtk ruff config formatare byte-identical to native ruff despiteis_formatbeing true for both.- Exit-code propagation on all four subcommand error paths (table above).
- No hang on
ruff server, under closed and open stdin. - Merge with current
develop— clean, and semantically right:is_check_invocationcomposes with develop's neweruser_set_output_format/use_json_filterlogic without either clobbering the other. git_checkout_dirty_tree_error_keeps_file_listfails on the PR head in isolation. It is stale-branch fallout, not yours — it passes on the merge with develop.- Overlap with #3912, #3782 and #3577, which all touch
ruff_cmd.rs: they hit therun_filteredcall and the filter-fn names, never the routing line. Any merge order works.
Hypotheses built and dropped
ruff serverbecomes a hang under the hook rewrite. Dropped: null stdin makes it exit 2 immediately, matching native ruff under a closed stdin, with the parent's stdin open or closed.- The PR newly loses stderr diagnostics on the subcommands it reroutes. Dropped:
stdout_only()drops stderr on the check branch too, so develop loses it identically. Filed under #3772, not here. - The 2000-char passthrough cap is introduced by this PR. Dropped: it is develop's
fa82e18d; the PR head alone hasstdout.trim().to_string(). - A first argument that is a real directory named
server/analyze/cleanis now misrouted. Dropped: native ruff resolves those the same way, so rtk matching it is the correct behaviour, not a bug. is_formatbeing true forhelp format/config formatcorrupts their output. Dropped:filter_ruff_formatfalls through to identity; both are byte-identical to native ruff. Only the cap inconsistency survives, as B.
Your questions
None open — no comments on the PR since it was filed.
Next
fixup afa9cae pushed: adds ruff_subcommands_cover_the_ruff_cli, pinning RUFF_SUBCOMMANDS against a literal list so deleting an entry fails the suite (mutation-verified: dropping "rule" fails it, where the existing test stays green). Test-only, fmt/clippy/test --all green. Nothing else owed — approving.
Rounds: 1/3. Threads: 0 open, 0 resolved this round.
Summary
format/versionblocklist with an explicit official-subcommand listrule,config,linter,clean,server,analyze, and completion commands from receivingcheck --output-format=jsonruff checkinvocationsTesting
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo test --all-features(2,498 passed, 8 ignored)Closes #2669