Repository navigation
Conversation
42995bd to
0c1c960
Compare
|
Re-ran the repro today as a straight A/B against current Control — Same command, this commit applied: So the redirect is still being reinterpreted on mainline today, and the argument reaches the child verbatim with the change. Windows 11, |
0c1c960 to
8957c8e
Compare
|
Rebased onto current Since the last push, Verification on Windows 11 (
Note for anyone testing on the |
|
Some upstream context that landed after this PR was opened, which narrows what it is asking for. #3728 merged on 18 Sep and fixes the sibling half of this problem — arguments containing a
That is this PR. #2389 is still open, and the four subcommands named there ( Two things I re-verified today against
Happy to rebase, split it further, or add cases if any of that would help. |
Four subcommands took clap `trailing_var_arg` vectors, rejoined them with spaces, and handed the resulting string to a second shell (`cmd /C` on Windows, `sh -c` elsewhere): main.rs Err (1850) Test (1855) Summary (1978) Run (2496) Those varargs have already been split by the shell that invoked rtk, so any operator it recognized was consumed before rtk ran. Re-joining and re-parsing makes the second shell reinterpret metacharacters that were plain data, which is the mechanism behind rtk-ai#3185: an argument containing `>` becomes a redirection and silently creates a stray empty file. Reproduced on 0.43.0 and 0.45.0, all four creating a stray empty file: rtk run echo "a > b" -> file 'b' rtk summary echo "a > stray_summary" -> file 'stray_summary' rtk err echo "a > stray_err" -> file 'stray_err' rtk test echo "a > stray_test" -> file 'stray_test' The discriminator is arity, matching the convention `Commands::Proxy` already uses (main.rs:2528, "If a single quoted arg contains spaces, split it respecting quotes (rtk-ai#388)"): - one part -> the user quoted a whole command line, so shell syntax inside it is intentional; keep running it through a shell (`rtk err 'cargo build && cargo test'` is unchanged). - many parts -> the invoking shell already parsed it; spawn argv directly via `resolved_command` so every argument reaches the child verbatim, and no second shell ever sees it. `rtk run -c` is documented as the shell-like invocation, so it stays a shell string by contract. Adds `utils::user_command` and `utils::shell_command`, the latter collapsing the three copies of the platform-shell split that had accumulated in runner.rs and summary.rs. Joining is now used only to build display and tracking labels, never to build a process. Ref rtk-ai#3185
user_command spawned the multi-part route with plain Command::args, which predates rtk-ai#3728. An argument holding a `"` therefore reached an MSYS/Cygwin child re-encoded by std's rules instead of libuv's, e.g. `rtk err grep -c '"type"' f` under Git Bash. Route it through child_args like every other caller-supplied argument.
8957c8e to
3f285de
Compare
|
Closing in favour of #4125, which fixes the same four subcommands with an explicit |
Rescoped 2026-09-01. This PR previously carried nine commits across seven subsystems. Eight of those were cherry-picks of other contributors' still-open PRs that I had been carrying in a local fork build (#3239, #3333, #3344, #3462) — re-proposing them here was duplicative and made the PR unreviewable. They are dropped. What remains is one commit touching only the exec path.
The bug
Four subcommands take clap
trailing_var_argvectors, rejoin them with spaces, and hand the resulting string to a second shell (cmd /Con Windows,sh -celsewhere):Those varargs have already been split by the shell that invoked rtk, so any operator it recognized was consumed before rtk ran. Re-joining and re-parsing makes the second shell reinterpret metacharacters that were plain data — the mechanism behind #3185, where an argument containing
>becomes a redirection and silently creates a stray empty file.Reproduced on 0.43.0 and 0.45.0, all four creating a stray empty file:
The fix
The discriminator is arity, matching the convention
Commands::Proxyalready uses (main.rs:2528, "If a single quoted arg contains spaces, split it respecting quotes (#388)"):rtk err 'cargo build && cargo test'is unchanged.resolved_commandso every argument reaches the child verbatim and no second shell ever sees it.rtk run -cis documented as the shell-like invocation, so it stays a shell string by contract.Adds
utils::user_commandandutils::shell_command, the latter collapsing the three copies of the platform-shell split that had accumulated inrunner.rsandsummary.rs. Joining is now used only to build display and tracking labels, never to build a process.Testing
Updated 2026-09-24: rebased onto
develop@ f5e104e (applies cleanly), plus a second commit routing the argv path throughChildArgExtfrom #3728, so an argument holding a"reaches an MSYS/Cygwin child intact.user_command_multi_part_encodes_quotes_for_the_childfails against plain.argsand passes withchild_args. On the rebased head,cargo test --allon Windows (x86_64-pc-windows-gnu) gives 3712 passed / 3 failed, the same three that fail on pristinedevelopon that machine. Live under Git Bash:rtk summary grep -c '"type"' q.jsonl→ 2 (system grep: 2);rtk err sh -c 'exit 7'→[FAIL], exit 7;rtk err echo "a > stray"creates no file.Original test notes (base aa40853):
cargo teston the rebased branch: 2894 passed, 2 failed. The two failures arecore::stream::tests::test_read_lines_lossy_preserves_lines_after_invalid_utf8hooks::hook_cmd::tests::test_claude_pipeline_rewrites_only_safe_final_stageand both fail identically on pristine
developwithout this commit (verified: 0 passed, 2 failed on a baseline branch), so they are pre-existing and unrelated to this change. Neither touches a file this PR modifies.One local-build note, not a request: on
x86_64-pc-windows-gnucurrentdevelopdoes not link at all, becausebuild.rsemits the MSVC-only/STACK:8388608under#[cfg(windows)]. I applied #3239 locally to run the suite and deliberately kept it out of this PR. CI only coverswindows-latest(msvc), so the gnu target is silently unbuildable ondeveloptoday.Closes #2389. Ref #3185. #3727 (quote handling when spawning MSYS/Cygwin children) was fixed separately by #3728; this PR reuses its
child_argson the new argv route rather than adding its own encoding.