Repository navigation
fix(cli): forward every argument of test, start, and stop to the script - #13344
Conversation
pnpm has no commands by these names: they reach `run` through the
`pnpm <script>` fallback, so parsing stops at the command name and every
later token is the script's. pacquet registered them as commands, so clap
parsed their arguments — `test` and `start` declared none at all and
rejected everything, and `stop` claimed the tokens it recognized:
pnpm test --watch usage error -> forwarded
pnpm test -- --flag usage error -> ["--", "--flag"]
pnpm stop --if-present taken as the flag -> forwarded
pnpm stop -s taken as the flag -> forwarded
pnpm stop -- --other=1 ["--other=1"] -> ["--", "--other=1"]
Give all three the single trailing_var_arg shape `run` got in
#13300, through a shared ScriptShortcutArgs, and teach the
parse boundary that their arguments start right after the command name.
`restart` is a real command upstream, with its own --if-present, and is
left as it is.
A leading `--` needs one extra step: clap consumes it as its own escape
until the positional has taken a value, and a shortcut's arguments can
open on it because no script name precedes them. `leading_separator`
writes a second one there, keyed off the boundary scan reporting that the
command is a shortcut — the boundary alone is not enough, since for `run`
it points past the script name, where clap already keeps the separator.
Two consequences worth naming, both of them the parity behavior:
`pnpm test -s` no longer silences pnpm's own reporter, and
`pnpm stop --if-present` no longer skips a missing script — for either,
the flag must precede the command name, as it must under pnpm.
Closes #13301
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
📝 WalkthroughWalkthroughChangesScript shortcut argument forwarding
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI as pacquet CLI
participant Parser as clap parser
participant Dispatch as dispatch_script
participant Script as package script
CLI->>CLI: Preserve leading separator
CLI->>Parser: Parse test/start/stop arguments
Parser->>Dispatch: Pass ScriptShortcutArgs
Dispatch->>Script: Forward all trailing tokens
Assessment against linked issues
Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Summary by QodoFix script shortcuts (test/start/stop) to forward argv verbatim
AI Description
Diagram
High-Level Assessment
Files changed (15)
|
Confidence Score: 5/5The PR appears safe to merge with no actionable correctness or security issues identified. The shortcut boundary, separator preservation, clap argument shape, and direct and recursive dispatch paths consistently preserve script arguments while retaining the intended missing-script semantics. Reviews (1): Last reviewed commit: "fix(cli): forward every argument of test..." | Re-trigger Greptile |
Micro-Benchmark ResultsLinux |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs (1)
61-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winUse regular comments for private-test rationale. These
///blocks attach documentation to private test functions/helpers while narrating test behavior rather than documenting a public API contract.
pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs#L61-L61: change the test-driver rationale to//.pnpm/crates/cli/tests/restart.rs#L182-L184: retain only the ordering invariant as a regular comment.pnpm/crates/cli/tests/restart.rs#L201-L203: retain only the trailing-argument invariant as a regular comment.pnpm/crates/cli/tests/run.rs#L741-L744: retain the fallback-parity rationale as a regular comment.As per coding guidelines, “Use rustdoc comments for public API contracts and regular comments for implementation rationale.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs` at line 61, The test rationale comments in pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs:61-61, pnpm/crates/cli/tests/restart.rs:182-184, pnpm/crates/cli/tests/restart.rs:201-203, and pnpm/crates/cli/tests/run.rs:741-744 should use regular comments instead of rustdoc comments. Replace the `///` markers at each site with `//`, retaining only the ordering invariant, trailing-argument invariant, fallback-parity rationale, and ScriptShortcutArgs::run test-driver rationale respectively.Sources: Coding guidelines, Path instructions
pnpm/crates/cli/tests/run.rs (1)
745-774: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy liftMake the forwarding assertion lossless and cross-platform.
#[cfg(unix)]leaves this CLI behavior untested on Windows, while"$*"joins arguments and cannot prove token boundaries were preserved. Use a platform-neutral recorder and compare an encoded argument sequence, including empty and whitespace-containing arguments.Per
REVIEW_GUIDE.md, CLI wiring regressions need e2e coverage and must be cross-platform where relevant.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pnpm/crates/cli/tests/run.rs` around lines 745 - 774, Update script_shortcuts_forward_every_argument_to_the_script to remove the Unix-only restriction and use a cross-platform argument recorder. Encode each received argument with an unambiguous delimiter or structured format so empty and whitespace-containing values retain their boundaries, then extend the cases and assertions to compare the complete encoded argument sequence, including the existing flag and “--” scenarios.Source: Path instructions
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs`:
- Line 61: The test rationale comments in
pnpm/crates/cli/src/cli_args/script_shortcut/tests.rs:61-61,
pnpm/crates/cli/tests/restart.rs:182-184,
pnpm/crates/cli/tests/restart.rs:201-203, and
pnpm/crates/cli/tests/run.rs:741-744 should use regular comments instead of
rustdoc comments. Replace the `///` markers at each site with `//`, retaining
only the ordering invariant, trailing-argument invariant, fallback-parity
rationale, and ScriptShortcutArgs::run test-driver rationale respectively.
In `@pnpm/crates/cli/tests/run.rs`:
- Around line 745-774: Update
script_shortcuts_forward_every_argument_to_the_script to remove the Unix-only
restriction and use a cross-platform argument recorder. Encode each received
argument with an unambiguous delimiter or structured format so empty and
whitespace-containing values retain their boundaries, then extend the cases and
assertions to compare the complete encoded argument sequence, including the
existing flag and “--” scenarios.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 463b9f98-ce06-4e98-8151-9b864b31ebc0
📒 Files selected for processing (16)
.changeset/pacquet-script-shortcut-args.mdpnpm/crates/cli/src/cli_args.rspnpm/crates/cli/src/cli_args/cli_command.rspnpm/crates/cli/src/cli_args/dispatch.rspnpm/crates/cli/src/cli_args/dispatch_script.rspnpm/crates/cli/src/cli_args/pre_command.rspnpm/crates/cli/src/cli_args/script_shortcut.rspnpm/crates/cli/src/cli_args/script_shortcut/tests.rspnpm/crates/cli/src/cli_args/stop.rspnpm/crates/cli/src/leading_separator.rspnpm/crates/cli/src/leading_separator/tests.rspnpm/crates/cli/src/lib.rspnpm/crates/cli/src/parse_boundary.rspnpm/crates/cli/src/shorthands/tests.rspnpm/crates/cli/tests/restart.rspnpm/crates/cli/tests/run.rs
💤 Files with no reviewable changes (1)
- pnpm/crates/cli/src/cli_args/stop.rs
Code Review by Qodo
Context used✅ Compliance rules (platform):
24 rules 1. leading_separator comment uses past tense
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #13344 +/- ##
=======================================
Coverage 87.04% 87.04%
=======================================
Files 534 535 +1
Lines 91806 91824 +18
=======================================
+ Hits 79911 79932 +21
+ Misses 11895 11892 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…pt (pnpm#13344) pnpm has no commands by these names: they reach `run` through the `pnpm <script>` fallback, so parsing stops at the command name and every later token is the script's. pacquet registered them as commands, so clap parsed their arguments — `test` and `start` declared none at all and rejected everything, and `stop` claimed the tokens it recognized: pnpm test --watch usage error -> forwarded pnpm test -- --flag usage error -> ["--", "--flag"] pnpm stop --if-present taken as the flag -> forwarded pnpm stop -s taken as the flag -> forwarded pnpm stop -- --other=1 ["--other=1"] -> ["--", "--other=1"] Give all three the single trailing_var_arg shape `run` got in pnpm#13300, through a shared ScriptShortcutArgs, and teach the parse boundary that their arguments start right after the command name. `restart` is a real command upstream, with its own --if-present, and is left as it is. A leading `--` needs one extra step: clap consumes it as its own escape until the positional has taken a value, and a shortcut's arguments can open on it because no script name precedes them. `leading_separator` writes a second one there, keyed off the boundary scan reporting that the command is a shortcut — the boundary alone is not enough, since for `run` it points past the script name, where clap already keeps the separator. Two consequences worth naming, both of them the parity behavior: `pnpm test -s` no longer silences pnpm's own reporter, and `pnpm stop --if-present` no longer skips a missing script — for either, the flag must precede the command name, as it must under pnpm. Closes pnpm#13301 Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Summary
pnpm test --watchfails with a usage error, andpnpm stop --if-presentruns pnpm's flag instead of the script's. pnpm has no commands by these names at all —test,start, andstopreachrunthrough thepnpm <script>fallback (run.ts'sopts.fallbackCommandUsedbranch), so parsing stops at the command name and every later token is the script's.pacquet registered them as commands, so clap parsed their arguments:
testandstartdeclared none and rejected everything, whilestopclaimed the tokens it recognized.test --watchtest -- --flag["--","--flag"]start --port 3000stop --if-presentstop -sstop -- --other=1["--","--other=1"]["--other=1"]All three now take the single
trailing_var_argpositionalrungot in #13300, through a sharedScriptShortcutArgs, andparse_boundaryknows their arguments begin right after the command name.restartis a real command upstream, with its own--if-present, and is left alone.The leading separator
One case needs more than the shape change. clap consumes the first
--as its own escape until the positional has taken a value — and a shortcut's arguments can open on the separator, because no script name precedes them.leading_separatorwrites a second--there for clap to eat.It keys off the boundary scan reporting that the command is a shortcut, not off the boundary index alone: for
runthe boundary points past the script name, where clap already keeps the separator, so an index-only rule double-writespnpm run build -- --flag. The unit tests caught that on the first attempt.Behavior changes worth calling out
Both follow from these being script shortcuts rather than commands, and both match pnpm — but neither is strictly "the bug", so they should not land unnoticed:
pnpm test -sno longer silences pnpm's reporter.-sis now the script's argument. Verified against pnpm, which passes-sthrough.pnpm -s teststill silences.pnpm stop --if-presentno longer skips a missing script. pnpm reportsCommand "stop" not foundfor exactly that invocation;pnpm --if-present stopis the spelling that skips, and still does.Each has a test pinning both spellings.
Verification
Every form checked by running both binaries against a script that prints its own argv — 22 invocations across
test/start/stop/restart/run/ thepnpm <script>fallback, including-- -- x. All match.Two existing tests encoded the old behavior (
shorthands::short_s_expands_for_commands_that_do_not_own_it,restart::stop_without_script_succeeds_with_if_present); both now assert the upstream rule, the latter alongside a new mirror test for the post-command spelling. I confirmedscript_shortcuts_forward_every_argument_to_the_scriptfails when the shortcut list is emptied.Full gate green: 7071 tests, clippy, dylint, taplo.
Closes #13301
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-5).
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by CodeRabbit
test,start, andstopnow forward all trailing arguments to the requested script.--if-presentand-s, are passed through correctly.--separators are preserved when invoking shortcut scripts.