Repository navigation
chore(args): introduce a more generic solution for restoring double dashes in args - #1823
Conversation
|
Tested at
One behavioral note worth flagging in case it's intentional: with the old Happy to close #1679 once this lands. Want me to do it now or wait until merge? |
|
Thanks a lot for the detailled test and report, very much appreciated!
The problem would have happen without rtk and should be handled by the LLM IMHO
As we have a release branch, merging doesn't mean available in a release, we will close it once released. Thanks again! |
…ashes in args Fixes rtk-ai#1669
4153ebb to
a5b4653
Compare
pszymkowiak
left a comment
There was a problem hiding this comment.
LGTM — solid refactor.
Reviewed in depth:
- The unified
args_utils::restore_double_dashremoves two divergent
implementations (normalize_diff_argsin git.rs,restore_double_dash
in cargo_cmd.rs) and replaces them with a single orthogonal one. - The behavior change (no more filesystem-existence heuristic to inject
--inrtk git diff) is a deliberate design call — predictable
passthrough over filesystem guessing, properly defended in the thread. - 15 new tests in
args_utilscover single/multiple swallowed dashes,
preserved dashes, no-dash-in-original, compound commands, duplicate
args, and git-diff specific cases. - @truffle-dev's manual repro suite for #1669 passed end-to-end.
- All 10 CI checks green (Windows / macOS / Linux / clippy / semgrep /
CodeQL).
A couple of minor follow-ups (non-blocking) if you ever revisit:
- Add a test for duplicate args traversing
--
(e.g.raw = [..., "x", "--", "x"],parsed = ["x", "x"]) to lock
in the behavior —contains()matches by value, edge worth pinning. - A short note in the docstring that args present in
rawbut absent
fromparsed_argsare silently skipped (e.g. the subcommand name).
Approving — none of these block merge.
aeppling
left a comment
There was a problem hiding this comment.
Requesting changes. The consolidation is the right direction, and dropping the filesystem heuristic genuinely fixes #1431 plus the bare-word miss. But the new reconstruction regresses a common git diff case. Verified end to end against a release build of a5b4653, not just the function in isolation.
Blocker: positionals equal to a command/subcommand token get duplicated
restore_double_dash_with_raw rebuilds the list by scanning the whole raw command line and re-emitting any token where parsed_args.contains(&token). That is a value test, and only argv[0] is skipped, so the command words (git, diff, cargo, test, ...) stay live candidates. When a user positional has the same value as one of them, the command word leaks back in.
All subcommands use trailing_var_arg = true (src/main.rs:83 plus ~75 others), so clap swallows the leading -- and user args arrive as the contiguous tail. That is exactly the shape this gets wrong.
Reproduced with this PR's binary in a real repo:
$ git diff -- diff # native: shows the diff, RC 0
$ rtk git diff -- diff # PR #1823 reconstructs `git diff diff -- diff`
fatal: bad revision 'diff' (exit 128)
This is a regression. Installed rtk 0.40.0 handles the same input correctly. It breaks Correctness over Token Savings for ordinary filenames (diff, git, log, test, build, status, ...) and violates "never block the user", since RTK makes a working command fail.
Root cause: value membership mapping with no positional anchor. trailing_var_arg guarantees the user args are the tail of raw_args, so restoration must align positionally from the right and stop at the first non-matching token (the command prefix). It must never scan back into the command words. The output should be byte for byte what the user typed, with only the -- reinserted.
test_compound_command_with_dashes asserts wrong behavior
let raw = vec!["rtk","cmd1","--","arg1","&&","cmd2","--","file"]; // asserts ["--","--","file"]The shell splits on &&, so each rtk process gets its own argv and this input cannot reach the function. The test locks in the buggy behavior. Remove or replace it.
Missing the test that would catch the blocker
No case uses a positional whose value equals a command token. Add -- diff, -- git, -- test, and cargo test cargo -- --nocapture.
Doc comment overclaims
The header lists "duplicate args on both sides of --" as handled, but that only holds for the one tested shape. Make it match the chosen algorithm.
Asks before merge
- Replace value membership with positional tail alignment.
- Add the collision tests above.
- Fix or remove test_compound_command_with_dashes.
- Re-confirm #1215, #1431, #1669 after the rewrite.
The fix is scoped to this one function. The rest of the refactor is good.
|
:c |
Summary
Fixes #1669
Test plan
cargo fmt --all && cargo clippy --all-targets && cargo testrtk git diff -- "src/core/args_utils.rs"output inspected