Skip to content

fix(cli): close three CLI parity gaps found moving the Tag workflow to v12 - #13246

Merged
zkochan merged 3 commits into
mainfrom
fix-13242
Jul 23, 2026
Merged

zkochan merged 3 commits into
mainfrom
fix-13242

Conversation

@zkochan

@zkochan zkochan commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #13242.

Moving the Tag workflow's operator pnpm to 12.0.0-alpha.19 surfaced three CLI surfaces the TypeScript CLI has that pacquet did not. The operator runs a single command:

pnpm add "<pkg>" --dir "<d>" --allow-build=@pnpm/exe --registry="<url>"

and against pacquet each option aborted the parse with error: unexpected argument '...' found. This brings pacquet's surface in line with the TypeScript CLI:

  1. --registry <url> is now universal. It is a global clap arg accepted on every command, layered onto the config exactly like --config.registry=<url> (default registry + default named-registry + the package-manager bootstrap copies). The registry-scoped commands that already spelled --registry out locally keep working — clap lets the global and the command-local arg coexist and both receive the value.
  2. pnpm add / pnpm add -g accept --allow-build=<pkg>. The named packages are appended to allowBuilds: any the root project explicitly disallows (allowBuilds: false) are rejected with ERR_PNPM_OVERRIDING_IGNORED_BUILT_DEPENDENCIES, the rest are persisted to pnpm-workspace.yaml and enabled for the install. This mirrors the TS add handler.
  3. --dir / -C is now global = true, so it parses on either side of the subcommand instead of only before it.

Notes / decisions

  • install deliberately does not accept --allow-build. The issue text says "install / add", but the TS install command does not register allow-build in its option types, so pnpm install --allow-build=foo errors there with Unknown option: 'allow-build' (exit 1). pacquet's install already rejects the unknown flag the same way, so honoring it would be a divergence. Only add (and the pre-existing dlx / create) accept it. The concrete operator command is add, so this covers the reported use case.
  • Audit of the other non-global top-level args (issue asked for this): --if-present stays non-global — the script subcommands (run, stop, restart, …) declare their own --if-present, and a global would collide; the existing tests document that install --if-present fails at parse time by design. --version stays a top-level-only Version action. Only --dir was wrongly position-bound.

Squash Commit Body

The Tag release operator runs `pnpm add <pkg> --dir <d>
--allow-build=<pkg> --registry=<url>`; against pacquet each option
aborted the parse with "unexpected argument". Bring pacquet's surface
in line with the TypeScript CLI:

- `--registry <url>` is now a universal rc-option accepted on every
  command (a global clap arg layered onto the config the same way
  `--config.registry=<url>` is), not only the registry-scoped commands
  that spelled it out locally.
- `pnpm add` / `pnpm add -g` accept `--allow-build=<pkg>`, appending the
  named packages to `allowBuilds` — rejecting any the root explicitly
  disallows, persisting the rest to `pnpm-workspace.yaml`, and enabling
  them for the install. `pnpm install` still rejects it, matching the TS
  CLI (which errors on the unknown option there).
- `--dir` / `-C` is now `global = true`, so it parses on either side of
  the subcommand instead of only before it.

Refs pnpm/pnpm#13242.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust pnpm/ port, or the description notes what still needs porting. — pacquet-only: these are gaps in pacquet; the TypeScript CLI already has all three surfaces.
  • Added a changeset (pnpm changeset) if this PR changes any published package. — pacquet patch.
  • Added or updated tests. — parse-level unit tests, apply_allow_build / apply_registry_override unit tests, and an end-to-end add test in the operator's exact flag shape.
  • Updated the documentation if needed. — n/a (parity with existing documented flags).

Written by an agent (Claude Code, claude-opus-4-8).


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Summary by CodeRabbit

  • New Features

    • Added universal --registry <url> support across commands.
    • --dir / -C is now position-independent and can appear anywhere on the command line.
    • Added --allow-build=<package> to add and add -g, enabling selected build scripts during installation and persisting the setting for future installs.
  • Bug Fixes

    • Prevented --allow-build from overriding explicitly disabled build dependencies, returning a clear error instead.
    • Workspace manifest updates now reject invalid control characters in persisted allowBuilds entries.

…o v12

The Tag release operator runs `pnpm add <pkg> --dir <d>
--allow-build=<pkg> --registry=<url>`; against pacquet each option
aborted the parse with "unexpected argument". Bring pacquet's surface
in line with the TypeScript CLI:

- `--registry <url>` is now a universal rc-option accepted on every
  command (a global clap arg layered onto the config the same way
  `--config.registry=<url>` is), not only the registry-scoped commands
  that spelled it out locally.
- `pnpm add` / `pnpm add -g` accept `--allow-build=<pkg>`, appending the
  named packages to `allowBuilds` — rejecting any the root explicitly
  disallows, persisting the rest to `pnpm-workspace.yaml`, and enabling
  them for the install. `pnpm install` still rejects it, matching the TS
  CLI (which errors on the unknown option there).
- `--dir` / `-C` is now `global = true`, so it parses on either side of
  the subcommand instead of only before it.

Audit of the remaining non-global top-level args: `--if-present` stays
non-global (the script subcommands declare their own) and `--version`
stays a top-level-only action; only `--dir` was wrongly position-bound.

Refs #13242.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 23, 2026 16:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: d069e0ad-cdc6-40c7-b52d-a8b1e851c9c3

📥 Commits

Reviewing files that changed from the base of the PR and between 84f8213 and 5975383.

📒 Files selected for processing (5)
  • pnpm/crates/cli/src/cli_args/add/tests.rs
  • pnpm/crates/cli/src/cli_args/tests.rs
  • pnpm/crates/cli/tests/add.rs
  • pnpm/crates/workspace-manifest-writer/src/lib.rs
  • pnpm/crates/workspace-manifest-writer/src/tests.rs
💤 Files with no reviewable changes (1)
  • pnpm/crates/cli/src/cli_args/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/cli/tests/add.rs
  • pnpm/crates/cli/src/cli_args/add/tests.rs

📝 Walkthrough

Walkthrough

Pacquet now accepts universal --registry and position-independent --dir options. pnpm add supports --allow-build for local and global installs, persists approved packages, rejects ignored dependencies, and validates manifest keys before writing.

Changes

CLI parity options

Layer / File(s) Summary
Universal registry and directory options
pnpm/crates/cli/src/cli_args/cli_command.rs, pnpm/crates/cli/src/cli_args/dispatch.rs, pnpm/crates/cli/src/config_overrides.rs, pnpm/crates/cli/src/cli_args/tests.rs, pnpm/crates/cli/src/config_overrides/tests.rs
--dir/-C is accepted around subcommands, while --registry is parsed globally and applied consistently across registry configuration fields.
Allow-build install handling
pnpm/crates/cli/src/cli_args/add.rs, pnpm/crates/cli/src/cli_args/dispatch_install.rs, pnpm/crates/cli/src/cli_args/global.rs, pnpm/crates/cli/src/cli_args/runtime.rs, pnpm/crates/cli/src/cli_args/add/tests.rs, pnpm/crates/cli/tests/add.rs, .changeset/pacquet-registry-allow-build-dir-parity.md
pnpm add and pnpm add -g parse and apply --allow-build, persist approved packages, reject explicitly ignored dependencies, and validate lifecycle-script execution and configuration persistence.
Allow-build manifest validation
pnpm/crates/workspace-manifest-writer/src/lib.rs, pnpm/crates/workspace-manifest-writer/src/tests.rs
set_allow_builds rejects control characters in package names and avoids writing an invalid workspace manifest.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Assessment against linked issues

Objective Addressed Explanation
Universal --registry support [#13242] ✅
--allow-build support for install/add flows [#13242] ✅
Position-independent --dir/-C [#13242] ✅

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CliArgs
  participant Config
  participant AddPipeline
  participant WorkspaceManifest
  User->>CliArgs: Run add with --registry, --dir, and --allow-build
  CliArgs->>Config: Apply registry and allowBuilds overrides
  Config->>WorkspaceManifest: Persist allowed build packages
  CliArgs->>AddPipeline: Start add using effective configuration
  AddPipeline->>User: Complete install and lifecycle scripts
Loading

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#12436: Directly overlaps --allow-build support and persistence in pnpm add and pnpm add -g.
  • pnpm/pnpm#13176: Overlaps lifecycle-script behavior and allowBuilds validation.
  • pnpm/pnpm#13218: Directly overlaps universal --registry handling and registry override plumbing.

Suggested labels: product: pacquet

Suggested reviewers: copilot, yeshyungseok

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-13242

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

fix(cli): align pacquet with pnpm v12 for --registry, --allow-build, and --dir

🐞 Bug fix ✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Make --registry  a universal global rc-option applied to the runtime config.
• Add pnpm add / pnpm add -g support for --allow-build= with persistence.
• Make --dir/-C position-independent and add regression tests for all three flags.
Diagram

graph TD
A["CLI argv"] --> B["clap: CliArgs"] --> C["cli_args/dispatch"] --> D["Config overrides"] --> E["add/global handlers"] --> F["pnpm-workspace.yaml"]
E --> G["package install"]
Loading
High-Level Assessment

The approach is appropriate for parity and maintainability: use clap global = true for --dir/--registry, centralize registry layering in apply_registry_override, and implement --allow-build only where pnpm supports it (add/add -g) while explicitly not diverging on install. Alternatives like manual argv preprocessing or accepting --allow-build on install were effectively ruled out by the goal of matching the TypeScript CLI surface.

Files changed (12) +264 / -16

Enhancement (3) +72 / -4
add.rsAdd '--allow-build' to 'add' and persist allowBuilds +56/-1

Add '--allow-build' to 'add' and persist allowBuilds

• Introduces '--allow-build' (repeatable) to 'AddArgs' and threads it through 'add -g' handling. Adds 'apply_allow_build' to validate against explicit root disallows, persist allowed names to 'pnpm-workspace.yaml', and enable them in the in-memory config for the current install, with a diagnostic error code matching pnpm.

pnpm/crates/cli/src/cli_args/add.rs

dispatch_install.rsHonor '--allow-build' in the workspace add pipeline +2/-1

Honor '--allow-build' in the workspace add pipeline

• Applies 'apply_allow_build' after deriving the settings/config root for 'add', ensuring allowBuilds are persisted at the correct settings directory and enabled for the operation.

pnpm/crates/cli/src/cli_args/dispatch_install.rs

global.rsSupport 'pnpm add -g --allow-build' in global installs +14/-2

Support 'pnpm add -g --allow-build' in global installs

• Threads 'allow_build' through the global add path and applies it after loading global settings so selected packages can run lifecycle scripts and be persisted into the global allowBuilds settings. Explicitly keeps 'update -g' without '--allow-build'.

pnpm/crates/cli/src/cli_args/global.rs

Bug fix (2) +18 / -3
cli_command.rsMake '--dir' global and add universal '--registry' option +10/-2

Make '--dir' global and add universal '--registry' option

• Marks '--dir/-C' as a global clap option so it parses before or after the subcommand. Adds a global '--registry' argument intended to behave like '--config.registry=<url>' across all commands, even when a command also defines its own '--registry'.

pnpm/crates/cli/src/cli_args/cli_command.rs

dispatch.rsApply global '--registry' to loaded config during dispatch +8/-1

Apply global '--registry' to loaded config during dispatch

• Plumbs the new 'CliArgs.registry' value through dispatch and applies it to the effective config via a shared override helper, ensuring all subcommands see the override.

pnpm/crates/cli/src/cli_args/dispatch.rs

Refactor (2) +19 / -7
runtime.rsKeep runtime installs unaffected by allow-build (pass empty list) +3/-0

Keep runtime installs unaffected by allow-build (pass empty list)

• Updates the shared add call site for 'pnpm runtime' to pass an empty allow-build list, documenting that runtime installs are not user package installs and do not accept '--allow-build'.

pnpm/crates/cli/src/cli_args/runtime.rs

config_overrides.rsFactor and reuse registry override application logic +16/-7

Factor and reuse registry override application logic

• Extracts 'apply_registry_override' to consistently normalize registry URLs (trailing slash) and set all registry slots (resolved registry, default named registry, and bootstrap copies). Registers 'registry' in global option width accounting.

pnpm/crates/cli/src/config_overrides.rs

Tests (4) +146 / -2
tests.rsUnit tests for allow-build persistence and rejection +43/-1

Unit tests for allow-build persistence and rejection

• Adds tests covering successful persistence into 'pnpm-workspace.yaml', rejection when the root config explicitly disallows a package, and no-op behavior for an empty allow-build list.

pnpm/crates/cli/src/cli_args/add/tests.rs

tests.rsCLI parsing regression tests for global dir/registry and allow-build collection +42/-0

CLI parsing regression tests for global dir/registry and allow-build collection

• Adds clap parsing tests verifying '--dir' works on either side of the subcommand, '--registry' is accepted universally, and repeated '--allow-build' values collect into a vector.

pnpm/crates/cli/src/cli_args/tests.rs

tests.rsTest registry override normalization and propagation +15/-1

Test registry override normalization and propagation

• Adds a unit test ensuring a CLI registry override is normalized and applied to every registry location in the config, including bootstrap copies.

pnpm/crates/cli/src/config_overrides/tests.rs

add.rsEnd-to-end test reproducing Tag operator flag ordering +46/-0

End-to-end test reproducing Tag operator flag ordering

• Adds an integration test matching the Tag workflow’s exact flag shape (options after positional) to ensure 'add' accepts '--dir', '--allow-build', and '--registry' together. Verifies lifecycle scripts run due to allow-build and that allowBuilds is persisted to 'pnpm-workspace.yaml'.

pnpm/crates/cli/tests/add.rs

Documentation (1) +9 / -0
pacquet-registry-allow-build-dir-parity.mdAdd changeset documenting CLI parity fixes +9/-0

Add changeset documenting CLI parity fixes

• Adds a patch changeset describing the three CLI parity gaps closed ('--registry', '--allow-build' on add, and position-independent '--dir'). Includes example commands to demonstrate expected behavior.

.changeset/pacquet-registry-allow-build-dir-parity.md

@greptile-apps

greptile-apps Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge because no eligible blocking failure remains in this follow-up review.

No blocking failure remains.

Reviews (3): Last reviewed commit: "test(cli): drop redundant narration from..." | Re-trigger Greptile

@github-actions

github-actions Bot commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     13.0±0.70ms    28.8 MB/sec    1.06     13.8±1.30ms    27.1 MB/sec
packument/parse                1.00     40.0±1.57µs  1659.5 MB/sec    1.05     42.0±3.02µs  1580.2 MB/sec
tarball/download_dependency    1.00      2.8±0.39ms  1528.1 KB/sec    1.00      2.8±0.32ms  1523.0 KB/sec

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
pnpm/crates/cli/src/cli_args/add/tests.rs (1)

13-19: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove test narration and obsolete implementation history.

  • pnpm/crates/cli/src/cli_args/add/tests.rs#L13-L19: remove comments that repeat the following assertions.
  • pnpm/crates/cli/src/cli_args/add/tests.rs#L34-L35: let the assertion express the no-write behavior.
  • pnpm/crates/cli/tests/add.rs#L36-L37: remove the pre-fix parser-failure history.
  • pnpm/crates/cli/tests/add.rs#L57-L58: remove the postinstall assertion narration.
  • pnpm/crates/cli/tests/add.rs#L68-L68: remove the persistence assertion narration.

As per coding guidelines, Rust comments should explain non-obvious invariants or contracts and must not duplicate test behavior or describe removed implementation history.

🤖 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/add/tests.rs` around lines 13 - 19, Remove
redundant narration comments from pnpm/crates/cli/src/cli_args/add/tests.rs
lines 13-19 and 34-35, and from pnpm/crates/cli/tests/add.rs lines 36-37, 57-58,
and 68; leave the assertions unchanged so they express the tested behavior
directly.

Sources: Coding guidelines, 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/add/tests.rs`:
- Around line 13-19: Remove redundant narration comments from
pnpm/crates/cli/src/cli_args/add/tests.rs lines 13-19 and 34-35, and from
pnpm/crates/cli/tests/add.rs lines 36-37, 57-58, and 68; leave the assertions
unchanged so they express the tested behavior directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c5b348d-9454-4b3c-bab3-da62435099ca

📥 Commits

Reviewing files that changed from the base of the PR and between 6fb1095 and 84f8213.

📒 Files selected for processing (12)
  • .changeset/pacquet-registry-allow-build-dir-parity.md
  • pnpm/crates/cli/src/cli_args/add.rs
  • pnpm/crates/cli/src/cli_args/add/tests.rs
  • pnpm/crates/cli/src/cli_args/cli_command.rs
  • pnpm/crates/cli/src/cli_args/dispatch.rs
  • pnpm/crates/cli/src/cli_args/dispatch_install.rs
  • pnpm/crates/cli/src/cli_args/global.rs
  • pnpm/crates/cli/src/cli_args/runtime.rs
  • pnpm/crates/cli/src/cli_args/tests.rs
  • pnpm/crates/cli/src/config_overrides.rs
  • pnpm/crates/cli/src/config_overrides/tests.rs
  • pnpm/crates/cli/tests/add.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 23, 2026
@qodo-code-review

qodo-code-review Bot commented Jul 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (1) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. set_allow_builds rejects control chars 📘 Rule violation ≡ Correctness ⭐ New
Description
Pacquet now errors when an allowBuilds key contains control characters, which is a user-visible
behavior difference vs pnpm TypeScript that persists allowBuilds keys without this validation.
This violates the requirement that Pacquet not introduce new user-visible behavior beyond pnpm
unless mirrored or explicitly called out.
Code

pnpm/crates/workspace-manifest-writer/src/lib.rs[R255-263]

+        // The block-style splice writes `- name: true` on one line, so a
+        // control character in `name` (e.g. a newline from a crafted
+        // `--allow-build`) would corrupt the document — refuse instead.
+        if has_control_char(name) {
+            return Err(UpdateWorkspaceManifestError::InvalidControlCharacter {
+                path,
+                value: name.to_string(),
+            });
+        }
Evidence
Pacquet now returns an error for allowBuilds entries with control characters (added guard in
set_allow_builds). In pnpm TypeScript, the add command builds an allowBuilds object from
opts.allowBuild and writes it via writeSettings/updateWorkspaceManifest with no comparable
validation, so the same input would not be rejected there.

Rule 713429: Pacquet must not introduce new user-visible behavior beyond pnpm
pnpm/crates/workspace-manifest-writer/src/lib.rs[255-263]
pnpm11/installing/commands/src/add.ts[281-309]
pnpm11/config/writer/src/index.ts[13-18]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Pacquet rejects `allowBuilds` keys containing control characters (e.g. a newline) when persisting to `pnpm-workspace.yaml`, but pnpm TypeScript currently persists the `--allow-build` values into `allowBuilds` without equivalent validation. This creates a parity gap where the same CLI input is accepted by pnpm but rejected by pacquet.

## Issue Context
The new Rust-side guard is added in `set_allow_builds()` to avoid corrupting the YAML splice format, but it introduces a user-visible restriction not present in pnpm TypeScript.

## Fix Focus Areas
- pnpm/crates/workspace-manifest-writer/src/lib.rs[255-263]
- pnpm11/installing/commands/src/add.ts[281-309]
- pnpm11/config/writer/src/index.ts[13-18]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Historical comment in add test ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added Rust test comment describes prior behavior using historical phrasing (`Before the fix
...`). This violates the requirement that comments document current behavior, increasing the chance
of stale or misleading documentation over time.
Code

pnpm/crates/cli/tests/add.rs[R33-37]

+/// The three CLI parity gaps from pnpm/pnpm#13242, reproduced together in
+/// the exact flag shape the Tag release operator uses: `pnpm add <pkg>
+/// --dir <d> --allow-build=<pkg> --registry=<url>`, with every option
+/// written *after* the subcommand and its positional. Before the fix each
+/// option aborted the parse with "unexpected argument".
Evidence
PR Compliance ID 772199 prohibits comments that refer to past behavior (e.g., "Before the fix"). The
added comment in pnpm/crates/cli/tests/add.rs explicitly describes what happened before this
change, rather than documenting the current contract being tested.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cli/tests/add.rs[33-37]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new inline comment uses historical phrasing (e.g., `Before the fix ...`), which can become stale and is disallowed by the comments policy.

## Issue Context
Comments must describe the current behavior and intent. Historical notes should live in PR/commit messages or design docs.

## Fix Focus Areas
- pnpm/crates/cli/tests/add.rs[33-37]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. allow-build control-char persistence ✓ Resolved 🐞 Bug ⛨ Security
Description
apply_allow_build() persists raw --allow-build values into pnpm-workspace.yaml via
set_allow_builds() without rejecting control characters, even though the workspace manifest writer
documents that control characters corrupt its single-line splicing format. A crafted value
containing e.g. a newline can permanently break workspace YAML parsing for subsequent commands (or
alter the allowBuilds structure), turning a single invocation into persistent config integrity
damage.
Code

pnpm/crates/cli/src/cli_args/add.rs[R337-360]

+pub(crate) fn apply_allow_build(
+    config: &mut Config,
+    allow_build: &[String],
+    settings_dir: &Path,
+) -> miette::Result<()> {
+    if allow_build.is_empty() {
+        return Ok(());
+    }
+    let overlap: Vec<&str> = allow_build
+        .iter()
+        .filter(|pkg| config.allow_builds.get(pkg.as_str()) == Some(&false))
+        .map(String::as_str)
+        .collect();
+    if !overlap.is_empty() {
+        return Err(AllowBuildError::OverridingIgnoredBuiltDependencies {
+            dependencies: overlap.join(", "),
+        }
+        .into());
+    }
+    set_allow_builds(settings_dir, allow_build.iter().map(|pkg| (pkg.as_str(), true)))
+        .into_diagnostic()?;
+    for pkg in allow_build {
+        config.allow_builds.insert(pkg.clone(), true);
+    }
Evidence
apply_allow_build() forwards raw CLI-provided strings into set_allow_builds(). The workspace
manifest writer itself documents that control characters corrupt its single-line splicing approach,
but set_allow_builds() does not perform that check; the edit path constructs a single YAML line
containing the rendered key, so an embedded newline/control character can break the document
structure and persist a bad config file.

pnpm/crates/cli/src/cli_args/add.rs[331-361]
pnpm/crates/workspace-manifest-writer/src/lib.rs[101-108]
pnpm/crates/workspace-manifest-writer/src/lib.rs[227-262]
pnpm/crates/workspace-manifest-writer/src/edit.rs[868-892]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`--allow-build` values are treated as attacker-controlled input (CLI arg) and are persisted to `pnpm-workspace.yaml`. The workspace manifest writer’s block-style splicing assumes values can be embedded into a single `key: value` line; it explicitly documents that control characters (newline, CR, etc.) would corrupt the YAML. However, `set_allow_builds()` currently does not enforce this invariant, and the new `apply_allow_build()` path makes it trivial to feed arbitrary strings into it.

## Issue Context
This PR adds `--allow-build` to `pnpm add` and persists the names to `pnpm-workspace.yaml`.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/add.rs[331-361]
- pnpm/crates/workspace-manifest-writer/src/lib.rs[227-262]
- pnpm/crates/workspace-manifest-writer/src/lib.rs[101-108]

## Suggested fix
1. Add control-character validation for `set_allow_builds()` entries (preferred: fix at the writer boundary so *all* callers are protected):
  - For each `(name, _)` in `entries`, if `name.chars().any(char::is_control)` then return `UpdateWorkspaceManifestError::InvalidControlCharacter { path, value: name.to_string() }` (reuse existing error).
2. Add a regression test:
  - Call `apply_allow_build(..., &["bad\nkey".to_string()], ...)` and assert it returns an error and does not create/modify `pnpm-workspace.yaml`.
3. (Optional) Also validate in `apply_allow_build()` to fail early before composing error strings or touching disk; but the writer-level guard is the important one.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Informational

4. Misleading YAML format comment 🐞 Bug ⚙ Maintainability ⭐ New
Description
set_allow_builds() says it splices entries as - name: true, but the allowBuilds writer actually
renders a mapping entry like   <rendered_name>: true via render_value(). This mismatch can confuse
future changes around YAML integrity/injection protections for allowBuilds.
Code

pnpm/crates/workspace-manifest-writer/src/lib.rs[R255-257]

+        // The block-style splice writes `- name: true` on one line, so a
+        // control character in `name` (e.g. a newline from a crafted
+        // `--allow-build`) would corrupt the document — refuse instead.
Evidence
The new comment documents a list-item form (- name: true), but the actual allowBuilds edit path
formats allowBuilds:\n  {render_value(name)}: {bool} (a mapping entry), and render_value() is
the mechanism that makes quoting single-line-safe (hence the control-char guard).

pnpm/crates/workspace-manifest-writer/src/lib.rs[253-265]
pnpm/crates/workspace-manifest-writer/src/edit.rs[550-573]
pnpm/crates/workspace-manifest-writer/src/render.rs[77-84]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
A newly-added comment in `set_allow_builds()` claims the writer splices YAML as a sequence item (`- name: true`), but the implementation splices a mapping entry under `allowBuilds:` (`  <name>: true`) using `render::render_value(name)`.

### Issue Context
Keeping this comment accurate matters because it documents the exact YAML surface the control-character guard is protecting (single-line splicing).

### Fix Focus Areas
- pnpm/crates/workspace-manifest-writer/src/lib.rs[255-257]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Previous review results

Review updated until commit 5975383

Results up to commit 84f8213 ⚖️ Balanced


🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Remediation recommended
1. Historical comment in add test ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
A newly added Rust test comment describes prior behavior using historical phrasing (`Before the fix
...`). This violates the requirement that comments document current behavior, increasing the chance
of stale or misleading documentation over time.
Code

pnpm/crates/cli/tests/add.rs[R33-37]

+/// The three CLI parity gaps from pnpm/pnpm#13242, reproduced together in
+/// the exact flag shape the Tag release operator uses: `pnpm add <pkg>
+/// --dir <d> --allow-build=<pkg> --registry=<url>`, with every option
+/// written *after* the subcommand and its positional. Before the fix each
+/// option aborted the parse with "unexpected argument".
Evidence
PR Compliance ID 772199 prohibits comments that refer to past behavior (e.g., "Before the fix"). The
added comment in pnpm/crates/cli/tests/add.rs explicitly describes what happened before this
change, rather than documenting the current contract being tested.

Rule 772199: Comments must describe current behavior, not historical implementations
pnpm/crates/cli/tests/add.rs[33-37]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
A new inline comment uses historical phrasing (e.g., `Before the fix ...`), which can become stale and is disallowed by the comments policy.

## Issue Context
Comments must describe the current behavior and intent. Historical notes should live in PR/commit messages or design docs.

## Fix Focus Areas
- pnpm/crates/cli/tests/add.rs[33-37]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. allow-build control-char persistence ✓ Resolved 🐞 Bug ⛨ Security
Description
apply_allow_build() persists raw --allow-build values into pnpm-workspace.yaml via
set_allow_builds() without rejecting control characters, even though the workspace manifest writer
documents that control characters corrupt its single-line splicing format. A crafted value
containing e.g. a newline can permanently break workspace YAML parsing for subsequent commands (or
alter the allowBuilds structure), turning a single invocation into persistent config integrity
damage.
Code

pnpm/crates/cli/src/cli_args/add.rs[R337-360]

+pub(crate) fn apply_allow_build(
+    config: &mut Config,
+    allow_build: &[String],
+    settings_dir: &Path,
+) -> miette::Result<()> {
+    if allow_build.is_empty() {
+        return Ok(());
+    }
+    let overlap: Vec<&str> = allow_build
+        .iter()
+        .filter(|pkg| config.allow_builds.get(pkg.as_str()) == Some(&false))
+        .map(String::as_str)
+        .collect();
+    if !overlap.is_empty() {
+        return Err(AllowBuildError::OverridingIgnoredBuiltDependencies {
+            dependencies: overlap.join(", "),
+        }
+        .into());
+    }
+    set_allow_builds(settings_dir, allow_build.iter().map(|pkg| (pkg.as_str(), true)))
+        .into_diagnostic()?;
+    for pkg in allow_build {
+        config.allow_builds.insert(pkg.clone(), true);
+    }
Evidence
apply_allow_build() forwards raw CLI-provided strings into set_allow_builds(). The workspace
manifest writer itself documents that control characters corrupt its single-line splicing approach,
but set_allow_builds() does not perform that check; the edit path constructs a single YAML line
containing the rendered key, so an embedded newline/control character can break the document
structure and persist a bad config file.

pnpm/crates/cli/src/cli_args/add.rs[331-361]
pnpm/crates/workspace-manifest-writer/src/lib.rs[101-108]
pnpm/crates/workspace-manifest-writer/src/lib.rs[227-262]
pnpm/crates/workspace-manifest-writer/src/edit.rs[868-892]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`--allow-build` values are treated as attacker-controlled input (CLI arg) and are persisted to `pnpm-workspace.yaml`. The workspace manifest writer’s block-style splicing assumes values can be embedded into a single `key: value` line; it explicitly documents that control characters (newline, CR, etc.) would corrupt the YAML. However, `set_allow_builds()` currently does not enforce this invariant, and the new `apply_allow_build()` path makes it trivial to feed arbitrary strings into it.

## Issue Context
This PR adds `--allow-build` to `pnpm add` and persists the names to `pnpm-workspace.yaml`.

## Fix Focus Areas
- pnpm/crates/cli/src/cli_args/add.rs[331-361]
- pnpm/crates/workspace-manifest-writer/src/lib.rs[227-262]
- pnpm/crates/workspace-manifest-writer/src/lib.rs[101-108]

## Suggested fix
1. Add control-character validation for `set_allow_builds()` entries (preferred: fix at the writer boundary so *all* callers are protected):
  - For each `(name, _)` in `entries`, if `name.chars().any(char::is_control)` then return `UpdateWorkspaceManifestError::InvalidControlCharacter { path, value: name.to_string() }` (reuse existing error).
2. Add a regression test:
  - Call `apply_allow_build(..., &["bad\nkey".to_string()], ...)` and assert it returns an error and does not create/modify `pnpm-workspace.yaml`.
3. (Optional) Also validate in `apply_allow_build()` to fail early before composing error strings or touching disk; but the writer-level guard is the important one.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Jul 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.33333% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.92%. Comparing base (454e7d6) to head (5975383).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/cli/src/cli_args/global.rs 57.14% 3 Missing ⚠️
pnpm/crates/cli/src/cli_args/runtime.rs 0.00% 3 Missing ⚠️
pnpm/crates/cli/src/cli_args/dispatch.rs 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13246      +/-   ##
==========================================
- Coverage   86.94%   86.92%   -0.02%     
==========================================
  Files         528      528              
  Lines       90472    90524      +52     
==========================================
+ Hits        78661    78690      +29     
- Misses      11811    11834      +23     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…ames

`set_allow_builds` spliced each package name into a single `- name: true`
line without the control-character guard the other block-style setters
(`set_overrides`, `set_audit_ignore_ghsas`, …) already apply. `pnpm add
--allow-build=<pkg>` is the first user-controlled path into it, so a
crafted value containing a newline could persist malformed YAML into
`pnpm-workspace.yaml` and break later commands. Guard it the same way,
erroring with ERR_PNPM_WORKSPACE_MANIFEST_WRITER_INVALID_CONTROL_CHARACTER.

Also drop test comments that narrated assertions or described pre-fix
behavior, per the repo comment policy.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 23, 2026 17:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@zkochan

zkochan commented Jul 23, 2026

Copy link
Copy Markdown
Member Author

Thanks for the reviews. Addressed the two actionable findings in 00243ac:

  • Qodo 🐞 (control-char persistence in allowBuilds): valid. set_allow_builds was the one block-style writer missing the control-character guard the others (set_overrides, set_audit_ignore_ghsas, …) already apply, and pnpm add --allow-build is the first user-controlled path into it. Hardened set_allow_builds itself to reject control characters up front with ERR_PNPM_WORKSPACE_MANIFEST_WRITER_INVALID_CONTROL_CHARACTER (so a crafted --allow-build can no longer corrupt pnpm-workspace.yaml), and added set_allow_builds_rejects_control_characters covering it. The add path fails cleanly before mutating config.
  • Qodo 📘 / CodeRabbit nitpick (comment policy): removed the "before the fix" historical phrasing and the assertion-narrating comments in the new tests, folding the intent into the assertion messages instead.

Greptile (5/5) and CodeRabbit approved; all Rust CI checks were green on the prior commit.


Written by an agent (Claude Code, claude-opus-4-8).

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 00243ac

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

The assertions and test names already document the behavior; remove the
inline comments and trimmed the e2e doc comment to just the non-obvious
why (the release operator's invocation), per the repo comment policy.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings July 23, 2026 17:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 5975383

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

/improve is deprecated. Use /agentic_review instead (removal date not yet scheduled).

No code suggestions found for the PR.

@zkochan
zkochan merged commit 842f6d5 into main Jul 23, 2026
41 of 43 checks passed
@zkochan
zkochan deleted the fix-13242 branch July 23, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pacquet: CLI parity gaps with the TypeScript CLI found while moving the Tag workflow to pnpm v12

3 participants