fix(cli): reject extra positional arguments passed to add - #3891
Open
miga-heygen wants to merge 1 commit into
Open
fix(cli): reject extra positional arguments passed to add#3891miga-heygen wants to merge 1 commit into
miga-heygen wants to merge 1 commit into
Conversation
`add <a> <b> <c>` silently installed only `<a>` and exited 0, discarding `<b>` and `<c>` with no warning. citty binds only the first positional token to `name`; every token after it still lands in `args._`, but nothing read it. `add` now rejects the extra arguments up front, before touching the registry, naming exactly what was dropped. Co-Authored-By: Miguel Angel <miguel.sierra@heygen.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add <a> <b> <c>installed only<a>and exited 0, with<b>and<c>silently dropped — no warning, no error. citty's positional-arg binding only assigns the first token to the declarednamearg; every token after it still lands inargs._, but nothing inadd'srun()read that array.addinstalls exactly one item or tag per invocation today — a tag (e.g.add html-in-canvas) is the existing bulk-install path, expanding to every item with that tag. Passing several explicit item names has never been a supported way to bulk-install, so rather than inventing that as a new feature, this makes the existing single-item contract honest: extra positional arguments are now rejected up front, before any project-config write or registry request, naming exactly what was dropped.Changes
packages/cli/src/commands/add.ts:run()now checksargs._.slice(1)for leftover positional tokens and fails with a usage error via the existingfailUsage()helper (same one other commands in this package already use for invalid invocations) instead of silently proceeding with just the first name. Added a small exportedformatExtraPositionalsError()helper for the message, matching the existingremapTarget/buildSnippetpattern of pulling pure logic out for direct testing.packages/cli/src/commands/add.test.ts: unit tests for the message formatter, plus end-to-end tests that invoke the command'srun()wrapper directly (following the same pattern already used inauth/login.test.ts) — including one that runs the arguments through citty's ownparseArgswith a flag interleaved between positionals (add a --dir <dir> b) to confirm the fix holds against real parsing, not just a hand-built args object.Test plan
bunx vitest run packages/cli/src/commands/add.test.ts— 29/29 passadd.tschange and reran — the 4 new assertions failed exactly as expected against the old behaviorbunx tsc --noEmit -p packages/clicleanbunx oxlint/bunx oxfmt --writecleanbunx fallow audit --base origin/main --fail-on-issuesclean (0 issues, 2 changed files)namewhile_retains every token, including when flags are interleaved with positionals (e.g.add a --dir <dir> b)