Repository navigation
fix(cli): hand -h, --help and help to the tool each subcommand wraps - #4348
Conversation
Clap adds -h/--help and a help subcommand to every subcommand it builds. On a subcommand that exists only to compress another tool's output those tokens are not RTK's to answer: grep -h is --no-filename, ls -h and tree -h are --human-readable, and git help log is a real subcommand. RTK replied with its own usage on stdout at exit 0, so an agent that only ever typed grep -h (the hook adds the prefix) read RTK's help as grep's matches. Only psql and ctest had opted out, one bug report at a time. release_meta_flags now walks the clap tree and releases those flags on every subcommand that forwards to a native tool, detected structurally rather than from a list. RTK's own commands keep their help, and rtk help <cmd> still reaches RTK's usage for a wrapper. Forwarding the flag exposed a second half: filters that summarise found no diagnostics in a help page and printed their empty summary instead, so cargo test --help returned nothing at all. args_utils::asks_tool_for_help guards those entry points and defers to runner::run_passthrough. Fixes #4198
|
Adrien EPPLING seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
📊 Automated PR Analysis
SummaryFixes RTK's clap-based CLI so that -h, --help, -V, --version, and the help subcommand are forwarded to the native tool a wrapper subcommand wraps, instead of being intercepted and answered by RTK's own help text (which previously produced misleading output and a 0 exit code, e.g. for Review Checklist
Linked issues: #4198 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
Drops the docs and awareness-text changes: rewording the "always safe" claim in the agent instructions is a separate concern from the flag collision, and the README and TECHNICAL edits were not needed to ship the fix. release_meta_flags no longer recurses. disable_help_flag, disable_version_flag and disable_help_subcommand are all global settings in clap, so one call already covers the whole subtree. asks_tool_for_help now reads -h as a help request. It only read the long spellings before, so cargo build -h still reached the build filter and came back as "cargo build (0 crates compiled)". ls and tree use the long-only form, since their -h is --human-readable.
The guard was repeated at 41 filter entry points. 38 of those modules already run their child through runner::run, which holds the built Command and so can answer the question itself: requests_help reads the program name and the argv before the boundary, and swaps the mode to Passthrough. That leaves explicit guards only where the filter runs the child itself rather than through the runner: git, find, pip, uv and dotnet. requests_help_args is the same rule for those callers, so there is one definition of what a help request is. -h is a request everywhere except psql, ls, tree and grep, which spell something else with it. RTK's own package-runner prefix (pnpm exec --, npx --) is skipped so the -- it ends with is not read as the caller's boundary.
Two layers, mirroring the two halves of the bug. Over the clap tree: every wrapper path crossed with -h, --help, -V, --version and help, dropped at every position of nine argv shapes, asserting RTK never answers with its own usage and that the token still reaches the leaf. Roughly 14k parses, read off the built tree so a new subcommand joins on its own. The inverse is pinned too, or releasing everything would satisfy it. Over real binaries: rtk <tool> --help spawned against the tool itself for 24 pairs, comparing exit code and asserting the page was not collapsed to a summary. Tools that are not installed are skipped, and commands are spawned directly so a grep shell function cannot stand in for the binary. Both were mutation-checked. Removing release_meta_flags fails the first with "RTK answered `rtk ls -h` itself"; removing the runner guard fails the second with "rtk cargo build -h returned 32 bytes of the tool's 3241"; dropping tree from DASH_H_IS_NOT_HELP fails the filtering check.
Three fixes to the tests added in the previous commit, all found by CI. semgrep's dynamic-command-execution rule forbids Command::new(<variable>) anywhere under src/, test modules included. The runner tests built a Command only to feed requests_help, so they now exercise requests_help_args, which takes the tool name as a string, and one adapter test keeps a literal program. Windows names the binary rtk.exe, so the "Usage: rtk " marker never matched. That failed the positive assertion and, worse, made the negative one pass for the wrong reason. The marker now stops at the stem. on_path joined PATH entries with a bare name, which on Windows finds the extensionless npm script rather than npm.cmd and fails the spawn with error 193. It now walks PATHEXT there. The cases whose Windows namesake is an unrelated program (find, tree) or needs a Unix toolchain (grep, ls, wc) are skipped, and the two tests asserting GNU/BSD flag semantics are unix-only.
KuSh
left a comment
There was a problem hiding this comment.
Round 1 of 3 — CHANGES REQUESTED
Claim: wrapper subcommands hand -h/--help/-V/--version/help to the tool they wrap, and the help page the tool prints comes back unfiltered.
Scope: accept. This PR is the one to keep: #3944, #3905 and #3888 are closed as superseded by it. (round 1, frozen)
Ran: native × develop merge-base × this head, every command through rtk rewrite first:
- 114 rows: every installed wrapper path from the clap tree ×
--help/-h. - 60 targeted rows: the issue repro and
-ho/-hnclusters,-V/--version, thehelpsubcommand,git -C,stash list, Go-help. - 20 boundary and non-help rows:
cargo test -- --help,git log --grep --help,git show --stat HEAD~20on a 30-commit repo,log --oneline -25. - dotnet 10.0.400, golangci-lint and ast-grep in Docker.
Invariants: non-default targets, under the hook, every decision. Streams were not split: help goes to stdout. Savings: non-help rows are byte-identical to develop (git log -5 71%, ls -la 82%, pip list 62%). Help rows are 0% by design (CONTRIBUTING.md floor is 20%).
Pins: 35 decisions, 35 mutated, 11 survived (forwards_to_native_tool guard; git help argv: globals, stash subcommand, two git_name arms; kubectl/oc extra ×2; uv guard; dotnet format guard, binlog guard, forwarded subcommand), 1 equivalent (disable_version_flag)
Matrix: executed this round; pin check: executed this round
CI @fb18174f8: all green on the branch. Merged onto develop 6f5503d it is red: core::test_isolation::tests_that_spawn_rtk_isolate_their_data fails (blocker 3).
What works, and works well: 112 of 114 wrapper rows now return the tool's own page byte for byte with its exit code, where develop printed RTK's usage at exit 0. Two examples:
grep -h alpha a.txt b.txtgoes from 644 B of RTK usage to grep's 12 B of matches.gh pr comment --helpgoes from 13 B (ok commented) to gh's full 936 B page, which also fixes #1474.
Blocks merge (3, frozen at round 1)
-
src/core/runner.rs:319— a help request the wrapped tool honours still reaches a filter, and several of those filters print a plausible result in place of the page. This happens in three shapes.(a) Handlers that run the child through
exec_capture, with no guard. The body lists git, find, pip, uv and dotnet as the only handlers outsiderunner::run. pnpm and wget are two more, and both now invent a result:rtk pnpm outdated --help, in a directory with nopackage.json, prints48 outdated packages (of 48)followed by help lines parsed as package rows (296 B, where pnpm prints 6259 B).rtk wget https://example.invalid/f --helpprintsexample.invalid/f ok | index.html | ?at exit 0, where wget prints 13331 B of help.
Develop printed RTK's usage for both; releasing the clap flags is what routes help into these filters. The same shape appears by reading at the sites below. None of these tools is installed here, so either guard them or show them covered with the tool installed:
gtsubmit/sync/restack/create/log (gt_cmd.rs:47, e.g.ok synced)lint(lint_cmd.rs:194)playwright(playwright_cmd.rs:283)prismagenerate/migrate/db-push (prisma_cmd.rs:57/113/155, e.g.Schema pushed to database)vitest/jest(vitest_cmd.rs:241)aws s3 ls/sync/cp(aws_cmd.rs:391/440)
On jest, your table shows 26881 B, but my reading of
vitest_cmd.rssays tier 3 caps it at 2000 chars. Can you confirm with jest installed?(b) The tool's own help spellings.
rtk dotnet test -?printsok dotnet test: completed (binlog-only mode, counts unavailable, 0 warnings), where dotnet prints 8833 B of help.rtk dotnet build -?and/?printfail dotnet build: 1 projects, 0 errors, 0 warnings, where dotnet prints 2852/2754 B.rtk go vet -helpprintsGo vet: No issues foundat exit 2, where go prints 202 B of usage.
(c) Help addressed past the tool's own
--.rtk cargo test -- --helpprints 0 B, where cargo prints libtest's 11078 B.- By reading, a runner
--the user types (rtk uv run -- pytest --help) stops the scan the same way.
A correct fix has to satisfy these rows:
rtk pnpm list|outdated|install --helpand-hreturn pnpm's page byte for byte. Here that is 6042/5434, 6259/5621 and 10968/10340 B; this head gives 2126, 286–296 and 1394–1609 B.rtk wget <url> --helpreturns wget's page.rtk dotnet test -?,rtk dotnet build -?|/?andrtk go vet -helpreturn the tool's page and exit code.rtk cargo test -- --helpreturns libtest's usage.
For (a), three shapes would close it; which do you prefer?
- A guard per handler, as you did for git and pip.
- A single check in
run_cliafter the parse. - The check inside
stream::capture, as #3944 had it, which covers everyexec_capturecaller at once.
Whichever you choose, add these rows to
a_wrapped_tools_own_help_survives_rtk, with a content check rather than a length check (see 2). -
Unpinned behaviour. These mutations pass the whole suite:
- RTK's own help on non-wrapper commands (
src/main.rs:1591). Removing theforwards_to_native_toolearly return passes everything, yet it breaksrtk read --helpandrtk log --help(they fall back to resolving aread/logbinary) andrtk diff --help/rtk env --help(they print GNU diff/env usage). Test must:rtk read|diff|log|env --helpprint RTK's usage.fuzz_rtk_own_commands_still_answer_their_own_helponly classifiesRTK_META_COMMANDSas own, so these four are never checked. - What the git help path forwards (
src/cmds/git/git_cmd.rs:141-152). Each of these survives: droppingglobal_args, dropping the stash subcommand push, andGitCommand::Status => "diff"orWorktree => "branch".a_wrapped_tools_own_help_survives_rtkcompares length and exit code only, so a longer page from the wrong subcommand passes. Test must assert the forwarded argv, e.g.-C <dir> stash list -hforrtk git -C <dir> stash list -h, and thatrtk git status --helpreturns status's page. - kubectl/oc
extra(src/main.rs:1837). Both droppingextraand droppingrestore_double_dashon it pass. Test must assert thatbuild_k8s_namespace_argsappendsextrawith the boundary restored. Question: wasextrameant to accept anything beyond help? By reading,-w, a pod name or-o widenow go tokubectl get pods -o json …underrun_filtered. Before, they were a parse error that reached kubectl visibly. kubectl isn't installed here, so I didn't run it. - uv and dotnet guards (
uv_cmd.rs:64,dotnet_cmd.rs:40/128/82). Turning off the uv guard, either dotnet guard, or dropping the subcommand fromforwarded_dotnet_argspasses on a host without uv/dotnet, because the integration test skips absent tools. There is nodotnet format --helpcase at all. Test must: pinforwarded_dotnet_args("format", ["--help"])as["format","--help"]in a unit test. Add thedotnet format --helpcase and confirm a CI runner has uv and dotnet, so the skips don't hide the rest.
- RTK's own help on non-wrapper commands (
-
Red after merge on develop (
tests/help_passthrough_fuzz_test.rs:74). The PR conflicts with develop in thesrc/main.rstest imports: keepuse crate::core::test_isolation;and dropuse clap::Parser;. Once that is resolved,tests_that_spawn_rtk_isolate_their_datafails, because the new test spawnsCARGO_BIN_EXE_rtkdirectly; since #3758 it has to be built withcommon::rtk_command(). With the conflict resolved, 30 suites pass and that test is the only failure (--no-fail-fast).
Optional — will not hold merge
asks_for_usagescans raw strings (*arg == "--help").search.rs:688already does this witharg_tokenizer: scoped before--, value-taking flags skipped,-hper engine..claude/rules/rust-patterns.mdrule 6 asks for that, and reusing it would stop value forms such ascargo install <crate> --version 1.2.3from running unfiltered. It may also be the natural place for the per-tool spellings in 1(b).src/main.rs:1645: withtestinRTK_META_COMMANDS, theargs[0] == "test" && --shellbranch is unreachable, and its comment ("cannot join that list") now contradictsconstants.rs.disable_version_flag(true)is a no-op: wrapper subcommands never had a-V(grep -V,ls --versionalready reached the tool on develop).Fixes #4198points at an issue closed as a duplicate of #3663. #3663 is the live one, and-his the part of it still open. This head also fixes #1474 (verified above).
Checked and correct — no need to re-verify
- The issue repro and
-hforms:grep -h/-rh/-h -n/-ho/-hnmatch grep byte for byte;ls -handtree -hare still filtered. --helpand-hon every installed wrapper path: cargo (7 subcommands), git (16, incl.-C,stash list, exit 129), go, gh, pip, pytest, ruff, npm, rg, find, wc, ctest, docker/compose, curl, golangci-lint, ast-grep, dotnet build.- The
helpsubcommand:go help test,cargo help build,pnpm help,docker help,gh help pr. git log --grep --helpnow matches git, which treats it as usage itself (exit 129), so the "known limit" in the body is correct output.- RTK's own help:
rtk --help/-h/-V,gain,proxy,init,rewrite,test,format,err,summary, andrtk help <wrapper>, which only loses the-h, --helpandhelplines that are no longer RTK's. - The 126-wrapper count matches the clap tree. Non-help output is byte-identical to develop.
- Mutations killed: runner guard,
--help,--version, the-htable and each of its 4 entries, the--boundary, all 3 runner-prefix arms, the stem read, the 3 clap settings,has_subcommands, the meta exemption,test/formatmembership, and the git, find and pip guards.
Your questions
- On "Happy to close this in favour of a rebased #3944": no need, this one carries on. #3944, #3905 and #3888 are closed as superseded, crediting #3944's
stream::captureapproach above.
Next
Close 1(a)–(c) against the rows above, add tests that kill the mutations in 2, and rebase onto develop with common::rtk_command() (3). The CLA check is also pending: the commit email for Adrien EPPLING isn't linked to a GitHub account.
Rounds: 1/3. Threads: 3 open (waiting on the author), 0 resolved this round.
Resolves the test-import conflict in src/main.rs by keeping develop's test_isolation import and dropping clap::Parser, which this branch no longer needs. The help fuzz now spawns through common::rtk_command() rather than naming CARGO_BIN_EXE_rtk, so the child writes to the test's scratch data directory instead of the contributor's own. core::test_isolation fails the suite on a spawn that skips it (#3758), which is what turned the merged branch red.
…n capture too Review round 1 on #4348. Blocker 1(a): a help request still reached filters that run the child through exec_capture rather than runner::run, and several answered with a plausible result: jest returned 2161 bytes of its 26881, pnpm outdated reported "48 outdated packages" parsed out of a help page, wget reported a download. The guard now also sits in stream::capture, which every exec_capture caller passes through. exec_capture_probe is the way out for a command RTK issues itself: a version probe asks --version to read the answer, not to show it, and golangci runs one. Blocker 1(b) and 1(c): asks_for_usage goes through arg_tokenizer instead of comparing raw strings, per rule 6 in rust-patterns.md. A per-tool spelling picks the dialect, so dotnet's -? and /? and Go's -help are read as the atomic names they are; a flag carrying a value no longer counts, so `cargo install x --version 1.2.3` stays filtered; and a tool that forwards past -- gets that region scanned as the argv it is, so `cargo test -- --help` is libtest's usage while `grep -- --help` is still a pattern. git and dotnet keep their own guards rather than relying on capture: by then RTK has injected its globals, and git's --no-pager turns the man page into a one-screen usage. pip's guard goes, covered by capture. kubectl/oc `extra` now carries only a usage request. Anything else runs as the caller typed it, matching kubectl's own "unknown command" rather than silently reaching a `get` pinned to -o json. Blocker 2: pins for what the mutations survived. The forwarded git argv including globals and the stash subcommand, every git_name arm, forwarded_dotnet_args, the dotnet spellings, the k8s alias split, RTK's own help on the commands that wrap nothing (read, diff, log, env), the forwarded boundary and the value forms. The integration check compares the tool's own first line rather than a length, so a page from the wrong subcommand fails.
Moving the scan onto the tokenizer brought short-flag clustering with it, and that read the h inside another flag as a request: `find -maxdepth 2` came back as raw find output instead of the compressed listing, and `mvn -Dhttp.proxyHost=…` and `gradlew -Dhttp.x=1` carry one the same way. A clustered h is almost never the flag, so it counts only when the argument is exactly `-h`. The cost is `cargo -qh`, which no longer registers; the tools that spell help with a single-dash long name (`go -help`, `dotnet -?`) are unaffected, since they are read in the MSBuild dialect where the name is atomic.
On Windows this harness reaches pip.EXE where rtk reaches pip, so the usage line the two print differs by that spelling while the page is the same. The anchor is compared with it removed. The check still fails on a page from the wrong subcommand, which is what it is for.
KuSh
left a comment
There was a problem hiding this comment.
Round 2 — CHANGES REQUESTED
Claim: wrapper subcommands hand -h/--help/-V/--version/help to the tool they wrap, and the help page the tool prints comes back unfiltered.
Scope: accept (round 1, frozen)
Ran: native × develop c356374 × round-1 head fb18174 × this head, every command through rtk rewrite first:
- Round 1's finding rows: pnpm ×6, wget ×2, go
-help×3,cargo test -- --help|-h, dotnet-?//?/--help/-h×7 (dotnet 10.0.400 in Docker). - The 114-row sweep of every installed wrapper path ×
--help/-h. - New-code rows: grep/rg patterns that spell a help token ×6; go
-run/-o/-args×19 on a real module;find -maxdepth/-ipath;summary/errwithdf -h; golangci-lintrunin Docker.
Invariants: under the hook, non-default targets, every decision. Non-help rows are byte-identical to develop (git log -5 71%, pip list 62%); help rows are 0% by design (CONTRIBUTING.md floor is 20%).
Pins: 42 decisions, 42 mutated, 6 survived (uv guard; dotnet format and binlog guards; k8s restore_double_dash; deno forward arm; capture guard exit code; go tool golangci-lint probe), 2 equivalent
Matrix: executed this round; pin check: executed this round
CI @51b551700: all green (16/16); the CLA check is still pending.
Round 1's help rows now all pass byte for byte against the tool:
- pnpm
list/outdated/install×--help/-h, andwget <url> --help. dotnet test -?//?(8833 B),dotnet build -?//?.go vet -help,go test -help,go build -help.cargo test -- --helpand-h.
All 114 wrapper paths match the tool's size and exit code. Round 1's unpinned git argv, git_name arms, RTK's own help on read/diff/log/env, forwarded_dotnet_args and the k8s split are now killed by the new tests.
Blocks merge (2 open of 3 frozen at round 1; +1 new regression in 6c56121)
-
Help reaching a filter— fixed (rows above). Thread resolved. -
src/cmds/python/uv_cmd.rs:64— unpinned behaviour, 6 decisions. Each of these mutations passes the whole suite:- uv guard (
|| requests_help_args("uv", …)→|| false) and the dotnet format and binlog guards (dotnet_cmd.rs:41/133→if false && …). Only the integration test reaches them, and it skips absent tools. CI'stestjob installs neither uv nor dotnet. The detection is pinned (dotnet_help_is_recognised_in_every_spelling), but the call site isn't. Test must: makertk uv run --helpandrtk dotnet build --helpreach the tool's page on a runner that has the tool, or pin the routing without it. - The capture guard's exit code (
stream.rs:746→std::process::exit(0)).rtk wget --zzz --helpandrtk pnpm outdated --zzz --helpexit 2 through this path, as the tool does, but no case asserts a non-zero help exit. Test must: run a capture-path help whose native exit is non-zero and assert the code. - The
go tool golangci-lintversion probe (go_cmd.rs:177back toexec_capture). The same edit ongolangci_cmd.rs:183is caught bylint_issues_are_summarised_and_exit_zero; with it,rtk golangci-lint run ./...prints onlygolangci-lint has version 2.13.1 …and never lints (run in Docker). Thego toolsibling has no such test. Test must: runrtk go tool golangci-lint runthe way those tests do and assert the lint result, not the version. - The deno forward arm (
runner.rs:302("deno", "run" | "test")→ never). No test asserts it. Question: isdeno test -- --helpa help request at all? Deno hands args after--to the test scripts asDeno.args, so the arm may only makertk deno test -- … --helprun unfiltered. Either pin it or droptestfrom it. restore_double_dashon k8sextra(main.rs:1854→extra.clone()). Test must:build_k8s_namespace_args("pods", None, false, ["--", "--help"])decide as it does now.
- uv guard (
-
Red after merge— fixed: rebased on develop,common::rtk_command(), CI green. Thread resolved. -
src/core/stream.rs:719— a value the caller passes is read as a usage request, and the replay runs the argv RTK built (new in 6c56121). The capture guard checks the argv RTK assembled, not the one the caller typed, so a pattern or value that spells a help token sets it off. It then reruns that argv raw, with RTK's own flags:- grep/rg:
rtk grep -e --help flags.txtprintsflags.txt\0+2:use --help for usage, which is search.rs's internal-H -n --nullformat with a NUL byte, at exit 0. Develop prints grep's line. The same happens forgrep -- --version flags.txt,grep -F -- --help flags.txt,rg -e --help flags.txtandrg -- -h flags.txt, all reached under the hook. search.rs has already answered the help question on the caller's argv before it callsexec_capture_stdin. Removing the guard fromexec_capture_stdinpasses the whole suite and fixes all five rows. - go: the MSBuild dialect reads
-run /version(a valid subtest pattern) as a switch.rtk go test -run /version ./...prints 1452 B of raw-jsonevents, where develop printsGo test: 2 passed in 1 packages.
Same mechanism, unfiltered rather than wrong:
rtk err df -handrtk summary df -hprint df's full output instead of the summary.rtk go test ./... -args -helpreturns the test binary's help as-jsonevents (10211 B for 2693 B).
A correct fix keeps every round-1 row and the 114-row sweep, and brings the five grep/rg rows and
go test -run /versionback to develop's output byte for byte. How would you rather do it?- (a) Decide on, and replay, the caller's argv at the handler, as you already do for git and dotnet.
- (b) Make the capture guard opt-in for handlers that pass the caller's argv unchanged.
- (c) Give search.rs and go a value grammar, so
-e/-run/-ovalues are not read as flags.
- grep/rg:
Optional — will not hold merge
runner.rs:1512: the new tests went in betweenfuzz_odd_argv_never_panicsand its doc comment. "Shapes that have made argument scanners panic…" now headsa_forwarded_boundary_is_another_programs_argv, and the fuzz test has none.a_wrapped_tools_own_help_survives_rtkruns the native tool from the test's working directory, and rtk from the scratch projectcommon::rtk_command()sets. A version manager that picks the tool per directory then compares two different tools. Here, proto resolved pnpm 12.9.1 for one side and 11.0.4 for the other, and the suite failed until the version was pinned. Running the native side fromcommon::rtk_command().get_current_dir()would keep both sides on the same tool.
Filed as follow-ups
- #4453
rtk cargo test -- --listprints nothing: the filter reads libtest's listing as an empty run. Same on develop, and outside this claim because--listis not a help request; filed.
Checked and correct — no need to re-verify
- Round-1 rows and sweep: all of round 1's help rows above, and the 114-row sweep; no head output contains RTK's usage.
- Fixed false positives:
find deep -maxdepth 2,find -ipathand-Dproperties stay filtered (dd6532e). - Round-1 boundaries unchanged:
grep -h/-ho,git log --grep --help,git -C <repo> stash list -handgh pr comment --helpstill match the tool. - Probes: golangci-lint
runis still filtered throughexec_capture_probe. The only other internal captures,user_dirs(git rev-parse) and ccusage, carry no help token. - Value rule:
cargo install <crate> --version 1.2.3stays filtered. - Mutations killed (32): the 4
short_hexclusions; both dialects; the npx, cargo, go, uv and npm-family forward arms; the forwarded-region scan;attached/linked/?; the whole-argument-h; the capture guard inexec_capture; the k8s Raw/Filtered split and alias; the find, git and runner guards; and round 1's git,git_name,forwarded_dotnet_args, k8sextraandrelease_meta_flagssurvivors.
Your questions
- None asked since round 1.
Next
Fix 4 (the grep/rg rows and go test -run /version back to develop's output), and add tests that kill the 6 mutations in 2.
Threads: 2 open (new this round, waiting on the author), 3 resolved this round (all round-1 threads, fixed).
Review round 2 follow-up, found by differential fuzzing against develop. git's cap-notice probe appends the caller's args to an argv RTK built, so a clustered -h reached it and the guard answered for the probe: `git log -hp` printed git's usage twice and `-ph` returned 129 where git returns 128. The probe and the cat-file blob probe now capture unguarded. `--help=x` is a request again. Only a separate value disqualifies one, so `cargo install x --version 1.2.3` still filters while `jest --help=x` returns jest's own 1936 bytes instead of 95. git's -m, --message, -F and --file carry values, so `git commit -m "--help"` is a message and stays filtered. Co-Authored-By: Claude Opus 5 <[email protected]>
Three conflicts, all additive on both sides: src/main.rs keeps develop's proxy_label alongside this branch's K8sAlias version of build_k8s_namespace_args. go_cmd.rs and golangci_cmd.rs keep develop's shell imports alongside exec_capture_unguarded. The help fuzz now builds its native side with develop's common::native_command, so both sides of every comparison run in the same environment. Co-Authored-By: Claude Opus 5 <[email protected]>
|
@KuSh round 2 addressed at 5f95337, merged on develop, CI pending. Blocker 4. Three causes, not one.
Blocker 2. All 6 killed, each verified to fail when reverted. dotnet and the k8s boundary are pinned with fake tools on PATH, so no runner needs the tool. Your Differential fuzz against develop then found 3 regressions of my own, all fixed:
Also fixed both optional items. Measured: 41/41 help rows byte-exact, 34/34 non-help byte-identical to the merge-base on separate streams. 4415 tests, 37 suites, 0 failures. Startup 3.6 ms, same as develop. Three for you, not fixed:
Two pre-existing, same in all builds, worth their own issues: non-UTF8 argv panics at 134 via |
The check compared RTK's output against half the size of `df -h`, which is 1627 bytes here and 436 on the CI container, where a 438 byte summary then read as unfiltered. It now asserts the property instead: the output differs from df's own and starts with RTK's marker. Co-Authored-By: Claude Opus 5 <[email protected]>
The err/summary pin used `df -h`, which is 436 bytes on a CI runner and 1.6 KB on a laptop. RTK rightly returns output raw when summarising it would be larger, so on ubuntu the assertion read RTK's correct fallback as a guard failure. Generate a 60 directory tree and probe `du -h` on it instead: the summary is 258 bytes against 1450 raw with short /tmp paths, so the marker means the guard held rather than that the input was long. Mutation checked: making the guard ignore `unguarded_help` fails it. Co-Authored-By: Claude Opus 5 <[email protected]>
…p guard decisions `cargo install x --version=1.2.3` was read as a usage request and ran unfiltered, while `--version 1.2.3` stayed filtered; cargo reads both as the version to install. An attached value on a flag the value rule names is now a value too. Pins three decisions no test reached: git's message and file flags carry a value, `rtk test` reads the command it was given without the usage guard, and `rtk git log`'s cap-notice probe leaves a clustered `-h` to git. The help fuzz tests now create their directories under the scratch directory instead of fixed names in the system temp dir, which concurrent runs shared. Co-Authored-By: Claude Opus 5.5 <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Round 3 — APPROVED, follow-ups filed
Claim: wrapper subcommands hand -h/--help/-V/--version/help to the tool they wrap, and the help page the tool prints comes back unfiltered.
Scope: accept (round 1, frozen)
Ran: native × develop 311ebcb × round-2 head 51b5517 × this head, every command through rtk rewrite first:
- 48 rows: round 1's and round 2's finding rows, git's clustered
-hand value forms, absent tools, non-help controls. - 14 go rows on a real module.
- dotnet 10.0.400 and golangci-lint in Docker.
- The 114-row sweep of every installed wrapper path ×
--help/-h. - 19 rows on the fixup: cargo install's
--versionforms, and git's-m/-F/--grep/-Svalue forms against native and develop.
Invariants: under the hook, non-default targets, every decision. Non-help rows are byte-identical to develop (git log -5 72%, pip list 62%); help rows are 0% by design (CONTRIBUTING.md floor is 20%).
Pins: 54 decisions, 54 mutated, 5 survived on 4ef06a6 (git -m/-F and --message/--file value spec, rtk test's unguarded flag ×2, git's cap-notice probe), all 5 killed by fixup 4f51c44; 4 equivalent (search's help branch, go build/vet guards, the blob probe). The fixup's one new decision is mutated both ways and killed.
Matrix: executed this round; pin check: executed this round
CI @4f51c4405: 17 pass (tests on ubuntu, macOS and Windows, clippy, semgrep, benchmark); license/cla pending. Gate on the merge with develop ffa5651: fmt, clippy, test green.
Round 2's blockers are closed:
- grep/rg:
rtk grep -e --help,grep -- --version,grep -F -- --help,rg -e --helpandrg -- -hmatch grep and rg byte for byte; the NUL format is gone. - go:
rtk go test -run /version ./...is back toGo test: 2 passed, andgo test ./... -args -helpreturns the test binary's 2693 B of text. - err/summary:
rtk err df -handrtk summary df -hmatch develop. - Pins: the uv guard, both dotnet guards, the capture guard's exit code, the
go tool golangci-lintprobe and the k8s boundary are each killed by a test now.
Round 1's rows all still pass, and so do the three regressions your fuzz found: git log -hp|-ph|-hu|-uh match git, --help=x reaches the tool, and git commit -m|-am|--message=|-F --help stays a message.
Blocks merge
None open.
Fixup 4f51c44 — what it changed
cargo install x --version=1.2.3was read as a usage request and ran unfiltered (raw 112 B where develop prints its 106 B summary), while--version 1.2.3stayed filtered; cargo reads both as the version.names_usagenow gets the value rule, and an attached value on a flag it names is a value. The=form is byte-identical to develop again;cargo install --versionalone,cargo build --help=neverandprettier --help=xstill ask. Pinned ina_flags_value_names_something_a_value_on_help_still_asks(renamed froma_separate_value_names_something_an_attached_one_still_asks).a_git_message_is_not_a_requestpins the git-m/-F/--message/--filevalue spec, with the argv the git handler passes (the arguments after the subcommand), and-m x --helpstill asks.an_arbitrary_commands_flags_are_not_rtks_to_readcoversrtk test du -htoo, asserting RTK's ownOUTPUT (last 5 lines):report rather than du's output.a_clustered_h_is_answered_by_git_oncecomparesrtk git log -hpwith git byte for byte on every platform, so the cap-notice probe staying unguarded is pinned.- The help fuzz tests take a per-test
common::tempdir()instead of fixedrtk_4198_*names in the system temp dir, which concurrent runs shared and deleted under each other. exec_capture_unguardedandexec_capture_stdinget doc comments saying when each skips the guard.
Filed as follow-ups
- #4547 rtk git log / git show print nothing when git exits non-zero with output on stdout — pre-existing (
rtk git log -m -his blank on develop too); reached here bygit log -hh/-h5andgit show -hp, and bylog/show/fetch/branch -m --help, where the help guard reads-mas commit's message flag (same bytes on develop). - #4548 rtk err / test / summary --help filter the command's own help page — pre-existing, outside the claim (meta commands, not wrappers).
Checked and correct — no need to re-verify
- Help rows:
- grep/rg value forms, pnpm ×6, wget ×2,
cargo test -- --help|-h,cargo build --help|--help=x,gh pr comment --help,pip list --help; git log --grep --help,-S --help,stash list -h;- dotnet
-?//?/--help/-hon build, test and format; - golangci-lint
run --help, go-help/-hon test, build and vet.
- grep/rg value forms, pnpm ×6, wget ×2,
- Filtered paths:
golangci-lint runstays filtered through the unguarded probe, andfind -maxdepthstays compressed. - Absent tools:
aws --helpanddotnet --helpwithout the tool give ENOENT at 127, as native. - Merge: 5f95337's conflict resolutions drop nothing from develop in any of the 9 files.
- Mutations killed (45): the 4
short_hexclusions, the dotnet dialect, every forward arm, go's whole-argument-help, thecargo installvalue rule,linked/?/version, whole-argument-h, the forwarded scan, the runner guard and its opt-out forerr, the capture guard and its exit code, the stdin and summary opt-outs, both version probes, go's clean forward ontest, uv, dotnet, git's guard and argv, find,release_meta_flags, the k8s split and boundary, andtest/formatmembership.
Your questions
- "Tool absent: … Fall back to RTK's usage on ENOENT?" → No. RTK's usage would answer a question meant for the tool, which is the bug this PR removes. The native command fails the same way at 127, and
rtk help <cmd>still reaches RTK's usage. The npx download is the existing fallback of everyrtk playwrightcall, tracked in #739. - "
git log -hh: … Neither right." → Deferred to #4547.run_logprints only stderr when git exits non-zero, and git puts its usage on stdout;rtk git log -m -his blank on develop for the same reason. Printing stdout on that path fixes every form at once. - "
bun test --version: head matches native but loses compression" → Fine as it is. The output is bun's own and nothing is lost; a bun exception would cost a spelling-table entry for a rare form. - The non-UTF-8 argv panic is #3025, open. For
grep -hHagainst BSD grep I found no issue; I can't produce a BSD transcript here, so it is not filed.
Next
Nothing — approved on 4f51c44, CI green.
Threads: 0 open, 2 resolved this round (round 2's two, fixed).
develop moved the whole CLI out of `src/main.rs` into `src/lib.rs` behind `rtk::entry()`, so the help guard work had to be ported onto the library: `rtk_command`, `release_meta_flags`, `forwards_to_native_tool`, `try_parse_cli_from` and the k8s alias helpers now live there, and `run_cli` parses through `try_parse_cli_from` as before. Two resolutions worth naming: `RTK_META_COMMANDS` takes develop's five new entries (llm-proxy, pipeline, methods, tasks, plugins) alongside `test` and `format`. Both of the latter use trailing_var_arg, so the bad-flag loop skips them. `proxy` is now a clap alias on `Bypass` rather than a subcommand of its own, so the help test looks a node up by name or alias instead of by name alone. Verified: 4296 tests pass, clippy clean, and 24 behaviour checks hold on the merged tree. Wrapped tools answer their own `-h` (cargo, git, npm, go, docker, kubectl, pytest, vitest), RTK's own commands keep RTK's help (develop's five new ones included), and filtering is unchanged. Co-Authored-By: Claude Opus 5 <[email protected]>
Fixes #3663 (the
-hhalf; #4198 is its duplicate). Also fixes #1474.Before
grep -hmeans "do not prefix lines with the filename". Clap claims-hon every subcommand it builds, so RTK answered a question meant for grep, on stdout, at exit 0. The hook rewritesgrep ...intortk grep ...by itself, so nobody opted into this.Same for
ls -handtree -h(human-readable sizes), and forgit help logandcargo help, which are real subcommands. Onlypsqlandctesthad opted out, one bug report at a time.It is two bugs, not one
Stopping RTK from claiming the flag lets it reach the tool. The tool then prints its help, and the filter eats it:
The cargo filter reads build logs. Handed a help page it counts zero crates and zero errors, so its "clean build" line is all that comes back.
guard::never_worsedoes not catch this, because it compares token counts and the summary is the smaller of the two.Fixing only the first half would turn
cargo test --helpfrom the wrong text into no text at all, so both ship together.Direction: one rule per half
Do not claim the flag.
release_meta_flagswalks the clap tree once and gives-h,--help,-V,--versionand thehelpsubcommand back to every subcommand that forwards to a native tool. Detection is structural, not a list, so a new filter is covered without anyone annotating it. RTK's own commands keep their help, andrtk help <cmd>still reaches RTK's usage for a wrapper.Do not filter the answer.
runner::requests_helpanswers once, and two choke points ask it:runner::runandstream::capture. Between them they cover every filter.gitanddotnetkeep their own guard because by then RTK has injected its globals, and git's--no-pagerturns the man page into a one-screen usage;findkeeps one because it reads a lone--helpas a name pattern before any command is built;uvkeeps one because it callsrun_streamingdirectly.exec_capture_probeis the way out for a command RTK issues itself, since a version probe asks--versionto read the answer rather than show it.Detection goes through
arg_tokenizer, per rule 6 inrust-patterns.md, with a per-tool spelling picking the dialect:-his a request except forpsql,ls,treeandgrep, which spell something else with it.-?and/?and Go's-helpare read as the atomic names they are.cargo install x --version 1.2.3stays filtered.--gets that region scanned as the argv it is, socargo test -- --helpis libtest's usage whilertk grep -- --helpis still a pattern to search for.Results
126 command nodes now hand these flags to the tool, up from 2.
cargo test --helpgit log --helpgh pr diff --helptsc --helpcargo build --helppip list --helpjest --helppnpm outdated --helpwget <url> --helpgo vet -helpcargo test -- --helpTwo more things this fixes.
rtk kubectl pods|services --helpand theocequivalents: these are RTK-only aliases, so the raw-exec fallback ran the literalkubectl pods --help. A usage request now forwards toget pods, and anything else runs as the caller typed it, matching kubectl's own "unknown command" rather than reaching agetalready pinned to-o json. Andtest/formatjoinerr/summaryinRTK_META_COMMANDS, since they run a command RTK picks and a fallback ontestwould find/bin/test.Tests
Two fuzz layers, both mutation-checked so they are known to fail when the fix is removed.
Over the clap tree, in
src/main.rs: every wrapper path crossed with each meta flag, dropped at every position of nine argv shapes. Around 14k parses, read off the built tree so a new subcommand joins on its own.Over real binaries, in
tests/help_passthrough_fuzz_test.rs: 24 pairs spawningrtk <tool> --helpagainst the tool itself, plus the issue's repro byte for byte. Uninstalled tools are skipped.release_meta_flagsRTK answered `rtk ls -h` itselfrunner::runguardrtk cargo build -h returned 32 bytes of the tool's 3241treefromDASH_H_IS_NOT_HELPrtk tree -h was passed through unfilteredGate passes:
cargo fmt --all --check && cargo clippy --all-targets && cargo test, 30 suites, 0 failures. Startup unchanged at 3.6 ms.Known limits:
-his matched whole, so a cluster like-lhis not read as a request, and a value that happens to be--help(git log --grep --help) runs unfiltered rather than searching for the string. Both fail toward running the command unfiltered, never toward eating output.Prior art
Same ground as #3944 (kylehgc), #3905 (AngelVRodC), #3888 (dmazhukov) and #4094 (Cornul11), none currently mergeable against
develop. #3944 reached this architecture independently; both therunner::runguard and the-htable here follow it, and itsRTK_OWN_RUNNERSexemption is what led me to catch theerr/test/summary/formatcase. Happy to close this in favour of a rebased #3944 if the maintainers prefer.