Skip to content

feat(cli): port set-script command to pacquet - #12618

Merged
zkochan merged 2 commits into
pnpm:mainfrom
Safort:feat/pacquet-set-script
Jun 24, 2026
Merged

zkochan merged 2 commits into
pnpm:mainfrom
Safort:feat/pacquet-set-script

Conversation

@Safort

@Safort Safort commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Ports the set-script / ss command from the TypeScript pnpm CLI to the Rust pacquet port. It writes a scripts entry into the project's package.json, mirroring pnpm11/pkg-manifest/commands/src/setScript.ts.

Part of the Rust Roadmap — related to #11633.

Squash Commit Body

Add the `set-script` command (and its `ss` alias) to pacquet, porting it from
the TypeScript CLI at pnpm11/pkg-manifest/commands/src/setScript.ts.

The command sets a script entry in the project's package.json. It takes a
script name followed by the command, and stores the command as the remaining
arguments joined by a single space, so `set-script lint eslint --fix src`
writes `"eslint --fix src"`. Both a name and a command are required; if either
is missing, the command fails with `ERR_PNPM_SET_SCRIPT_MISSING_ARGS`.


Related to pnpm/pnpm#11633.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pacquet/ port, or the description notes what still needs porting.
  • Added a changeset (pnpm changeset) if this PR changes any published
    package. Keep it short and written for pnpm users — it becomes a release note.
  • Added or updated tests.
  • Updated the documentation if needed.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added set-script (alias ss) to create or update scripts entries in package.json
    • Concatenates remaining command arguments into a single script command
    • Automatically creates scripts when missing and replaces it when it’s not an object
    • Supports advanced script names (including dots, hyphens, quotes, and =)
  • Bug Fixes

    • Returns clear, dedicated errors when required arguments are missing
  • Security/Validation

    • Rejects unsafe script names like __proto__, constructor, and prototype
  • Tests

    • Added unit and CLI integration coverage for the new command and validation behavior

@Safort
Safort requested a review from zkochan as a code owner June 23, 2026 18:14
@coderabbitai

coderabbitai Bot commented Jun 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: b5be1935-386b-4d03-ac8d-905d6fbd62f5

📥 Commits

Reviewing files that changed from the base of the PR and between 9763b07 and f7c6ad9.

📒 Files selected for processing (4)
  • pacquet/crates/cli/src/cli_args.rs
  • pacquet/crates/cli/src/cli_args/set_script.rs
  • pacquet/crates/cli/src/cli_args/set_script/tests.rs
  • pacquet/crates/cli/tests/set_script.rs
✅ Files skipped from review due to trivial changes (1)
  • pacquet/crates/cli/src/cli_args/set_script/tests.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • pacquet/crates/cli/src/cli_args/set_script.rs
  • pacquet/crates/cli/src/cli_args.rs
  • pacquet/crates/cli/tests/set_script.rs

📝 Walkthrough

Walkthrough

Adds a set-script (ss) subcommand to the pacquet CLI. The command accepts a script name and command string, validates the name against an unsafe-key list, then loads and updates the scripts field in package.json, creating or replacing it as needed. Includes unit and integration tests.

Changes

pacquet set-script command

Layer / File(s) Summary
CLI module export and command dispatch
pacquet/crates/cli/src/cli_args.rs
Exports pub mod set_script, imports SetScriptArgs, adds CliCommand::SetScript(SetScriptArgs) with visible alias ss, and adds a synchronous CliArgs::run dispatch arm calling args.run(&manifest_path()).
SetScriptArgs, SetScriptError, and manifest update logic
pacquet/crates/cli/src/cli_args/set_script.rs, pacquet/crates/cli/src/cli_args/set_script/tests.rs
Defines UNSAFE_KEYS, SetScriptError with MissingArgs and UnsafeKey variants, SetScriptArgs parsing and run() control flow, reject_unsafe_key(), and set_script() JSON upsert logic. Unit tests cover create, replace, dotted-key, and unsafe-key rejection behaviors.
CLI integration tests
pacquet/crates/cli/tests/set_script.rs
Integration tests cover ss alias forwarding, script creation and overwrite, multi-token command joining, dotted/hyphenated/special-character and equals-sign script names, and missing-args plus unsafe-key failure diagnostics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

  • pnpm/pnpm#11504: Both PRs add a set-script/ss CLI command that writes scripts[name] = command into the package manifest while rejecting unsafe prototype-pollution keys and joining remaining CLI params into the stored script command.

Suggested reviewers

  • zkochan
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Add pacquet set-script/ss command to write package.json scripts safely
✨ Enhancement 🧪 Tests 🕐 20-40 Minutes

Grey Divider

Description

• Add set-script command (alias ss) to write package.json#scripts[name].
• Validate required args and reject prototype-pollution keys with pnpm-compatible errors.
• Add unit and CLI integration tests covering script creation, overwrite, and failures.
Diagram

graph TD
  A(["pacquet CLI"]) --> B["clap command parser"] --> C["SetScriptArgs::run"] --> D[["PackageManifest"]] --> E[("package.json")]
  F["Unit tests"] --> C
  G["CLI integration tests"] --> A

  subgraph Legend
    direction LR
    _cli(["CLI/entrypoint"]) ~~~ _proc["Processing step"] ~~~ _lib[["Library/helper"]] ~~~ _file[("File")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use a shared/single manifest mutation helper (property-path style)
  • ➕ Centralizes JSON mutation behavior across commands (consistent handling of non-object intermediates).
  • ➕ Potentially reduces duplicated logic as more pkg-manifest commands are ported.
  • ➖ Introduces additional abstraction early; may slow down straightforward ports.
  • ➖ Still requires explicit prototype-pollution key blocking for safety.
2. Leverage an existing safe property-path crate instead of custom setter
  • ➕ Less bespoke code; benefits from upstream hardening and edge-case handling.
  • ➕ Could support future commands needing nested updates.
  • ➖ Adds dependency surface area; may not match pnpm semantics (literal key vs dotted path).
  • ➖ Would still need pnpm-compatible unsafe-key policy and error codes.

Recommendation: Current approach is appropriate for a faithful pnpm port: it intentionally treats the script name as a literal key (no dotted-path semantics), enforces pnpm-compatible error codes, and keeps scope limited to rewriting package.json without touching lockfile/install flows. Consider extracting the safe-key guard + "replace non-object with object" behavior into a shared helper once additional manifest-writing commands are added.

Files changed (4) +278 / -0

Enhancement (2) +109 / -0
cli_args.rsRegister and dispatch new 'set-script'/'ss' CLI subcommand +12/-0

Register and dispatch new 'set-script'/'ss' CLI subcommand

• Adds the 'set_script' module and introduces a 'CliCommand::SetScript' variant with the 'ss' alias. Wires command execution into the CLI dispatcher as a synchronous manifest-only operation (no reporter fan-out, lockfile, or install pipeline).

pacquet/crates/cli/src/cli_args.rs

set_script.rsImplement 'set-script' argument parsing, errors, and manifest rewrite +97/-0

Implement 'set-script' argument parsing, errors, and manifest rewrite

• Implements 'SetScriptArgs' to accept a script name plus trailing command args, joining remaining params with spaces for the stored script value. Adds pnpm-compatible diagnostics for missing args and unsafe prototype-pollution keys, then reads/saves 'package.json' via 'PackageManifest' while ensuring 'scripts' is an object and updating 'scripts[name]'.

pacquet/crates/cli/src/cli_args/set_script.rs

Tests (2) +169 / -0
tests.rsAdd unit tests for scripts object creation and unsafe-key rejection +32/-0

Add unit tests for scripts object creation and unsafe-key rejection

• Validates that 'scripts' is created when absent and replaced when not an object. Confirms dotted script names are treated as literal keys and prototype-pollution keys are rejected.

pacquet/crates/cli/src/cli_args/set_script/tests.rs

set_script.rsAdd end-to-end CLI tests for 'set-script'/'ss' behavior and error codes +137/-0

Add end-to-end CLI tests for 'set-script'/'ss' behavior and error codes

• Introduces integration tests that run the 'pacquet' binary to ensure scripts are added/overwritten and command args are joined correctly. Verifies alias support, acceptance of diverse script names, and failure modes emitting the expected pnpm-style diagnostic codes.

pacquet/crates/cli/tests/set_script.rs

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Jun 23, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Tickets: 🎫 Rust Roadmap

Grey Divider


Action required

1. Symlink clobber write 🐞 Bug ⛨ Security
Description
set-script persists changes by calling PackageManifest::save(), whose implementation uses
fs::File::create(path) and will follow an existing package.json symlink, truncating/overwriting
the symlink target. In a malicious repo where package.json is a symlink, running `pacquet
set-script` can overwrite an arbitrary user-writable file outside the repo.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save() after mutating JSON.
PackageManifest::save_and_get_written_value() uses fs::File::create(&self.path) and write_all,
which follows symlinks and truncates the target, enabling arbitrary file overwrite when
package.json is a symlink in an attacker-controlled repo.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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 set-script` writes back to `package.json` via `PackageManifest::save()`. The current save implementation uses `fs::File::create(&self.path)` which follows symlinks; a repo-controlled `package.json -> /some/other/file` can cause an arbitrary file overwrite when the victim runs `pacquet set-script` in that repo.
### Issue Context
- The CLI dispatch calls `SetScriptArgs::run(&manifest_path())`, which loads `PackageManifest` and calls `manifest.save()`.
- `PackageManifest::save_and_get_written_value()` currently does a direct `File::create` + `write_all`, which both truncates in-place and follows symlinks.
- The repo already has robust “write temp + rename” patterns (e.g. `pacquet_fs::ensure_file` / lockfile atomic writers) that avoid symlink-following at the temp path and prevent torn writes.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
### What to change
1. Update `PackageManifest::save_and_get_written_value()` (preferred, since it centralizes all manifest writes) to write via a temp file in the same directory and then rename over `package.json` (overwrite-safe on Windows too).
- Reuse/extract an existing atomic writer (e.g. the `write_atomic`/`rename_with_retry` approach in `pacquet_fs::ensure_file`, or introduce a small shared helper in `pacquet_fs`).
- Ensure the temp file is created with `create_new(true)` to avoid following a pre-seeded symlink at the temp path.
2. (Optional, stricter) Decide policy for an existing `package.json` that is itself a symlink:
- Either reject with a clear diagnostic (safest), or
- Ensure the rename replaces the symlink itself (never writes to its target).
3. Add/extend a test that constructs a symlinked `package.json` in a temp dir and verifies `set-script` does **not** overwrite the symlink target.

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



Remediation recommended

2. Scripts edit blocked by deps 🐞 Bug ☼ Reliability
Description
SetScriptArgs::run saves via PackageManifest::save(), which performs
dependencies/devDependencies runtime-folding and rejects non-object dependency fields, so
pacquet set-script can fail (or rewrite non-scripts fields) even though it’s intended to only
update package.json#scripts. Example: a manifest with "dependencies": "oops" will error during
save with "the dependencies field must be an object" and prevent setting the script.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-65]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
Evidence
The new command always persists via PackageManifest::save(). That save path clones the whole JSON,
applies dependency/engines conversions, and errors when dependency fields are present but not JSON
objects—so a scripts-only edit can unexpectedly fail or modify additional fields.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-168]
pacquet/crates/package-manifest/src/lib.rs[404-413]
pacquet/crates/cli/src/cli_args.rs[374-380]

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 set-script` is intended to only update `package.json#scripts`, but it writes via `PackageManifest::save()`, which runs dependency/engines runtime folding and validates dependency map shapes. This can cause `set-script` to fail (or touch unrelated fields) due to unrelated manifest data.
### Issue Context
`PackageManifest::save_and_get_written_value()` calls `convert_dependencies_to_engines_runtime()` for `devDependencies` and `dependencies`, and that conversion returns `InvalidAttribute` when those fields exist but are not objects.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
- pacquet/crates/package-manifest/src/lib.rs[404-413]
### Suggested approach
- Add a `PackageManifest` API (or a local save path in `set-script`) that writes the manifest without performing dependency/engines runtime conversions/validations, since `set-script` only needs to update `scripts`.
- Alternatively, make the runtime-folding conversion conditional so it does not error for unrelated invalid `dependencies`/`devDependencies` shapes in commands that don’t touch those fields.

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


3. set-script silent no-op 🐞 Bug ≡ Correctness
Description
If package.json parses to a non-object JSON value, set_script() returns early without mutating,
but run() still saves and returns success, so the CLI reports success while not setting the
script. This can confuse users/automation and hides that the manifest is in an invalid shape for
mutation.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R84-86]

+fn set_script(manifest: &mut Value, name: String, command: String) {
+    let Some(manifest) = manifest.as_object_mut() else { return };
+    let scripts = manifest.entry("scripts").or_insert_with(|| Value::Object(Map::new()));
Evidence
set_script() currently bails out silently when the manifest root is not an object, and run()
does not check whether mutation occurred before saving and returning success. Since
PackageManifest::read_from_file() parses arbitrary JSON into Value without enforcing an object
root, this condition is reachable with malformed manifests.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/cli/src/cli_args/set_script.rs[84-86]
pacquet/crates/package-manifest/src/lib.rs[99-105]

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 set-script` can exit successfully without writing the requested script when the parsed `package.json` root is not a JSON object.
### Issue Context
`PackageManifest::from_path()` deserializes `package.json` into an unconstrained `serde_json::Value`, so the root may be a non-object (string/array/etc.). The current `set_script()` helper silently returns in that case, and the caller still invokes `save()` and returns `Ok(())`.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-67]
- pacquet/crates/cli/src/cli_args/set_script.rs[84-94]
### Proposed fix
- Make `set_script` return `Result<(), SetScriptError>` (or a new error type) instead of silently returning.
- If `manifest.as_object_mut()` is `None`, return a diagnostic error (and ensure `run()` propagates it) so the command fails instead of silently succeeding.
- Add a unit/integration test that writes a non-object `package.json` (e.g. `"oops"`) and asserts the command fails with a stable diagnostic code/message.

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


4. Non-atomic manifest save 🐞 Bug ☼ Reliability
Description
set-script persists changes by calling PackageManifest::save(), which truncates package.json
and writes new contents directly; a crash or mid-write I/O failure can leave an empty/partial
manifest. This is a reliability hazard for a command whose sole purpose is editing package.json.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save(), and the underlying save path uses fs::File::create
(truncate) followed by write_all, with no temp-file + rename step, so an interrupted write can
corrupt package.json.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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

## Issue description
`PackageManifest::save_and_get_written_value()` writes by truncating the target file and streaming the new JSON, which is not crash-safe.
### Issue Context
`pacquet set-script` now exposes a dedicated manifest-editing command path that can corrupt `package.json` if the process is interrupted (panic, SIGKILL, power loss) during write.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[156-163]
- pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
### Proposed fix
- Implement atomic write in `PackageManifest::save_and_get_written_value()`:
- write to a temp file in the same directory (to keep rename atomic on the same filesystem),
- `flush`/`sync_all` the temp file as appropriate,
- `rename` over the destination,
- optionally `sync_all` the parent directory for durability.
- Keep the API the same so all callers (including add/update/remove and this new set-script command) benefit automatically.
- Add a focused unit test if the repo has a pattern for simulating mid-write failures; otherwise, document the atomicity guarantee in code comments.

ⓘ 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 f7c6ad9

Results up to commit f7c6ad9


🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Tickets: 🎫 Rust Roadmap

Action required
1. Symlink clobber write 🐞 Bug ⛨ Security
Description
set-script persists changes by calling PackageManifest::save(), whose implementation uses
fs::File::create(path) and will follow an existing package.json symlink, truncating/overwriting
the symlink target. In a malicious repo where package.json is a symlink, running `pacquet
set-script` can overwrite an arbitrary user-writable file outside the repo.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save() after mutating JSON.
PackageManifest::save_and_get_written_value() uses fs::File::create(&self.path) and write_all,
which follows symlinks and truncates the target, enabling arbitrary file overwrite when
package.json is a symlink in an attacker-controlled repo.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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 set-script` writes back to `package.json` via `PackageManifest::save()`. The current save implementation uses `fs::File::create(&self.path)` which follows symlinks; a repo-controlled `package.json -> /some/other/file` can cause an arbitrary file overwrite when the victim runs `pacquet set-script` in that repo.
### Issue Context
- The CLI dispatch calls `SetScriptArgs::run(&manifest_path())`, which loads `PackageManifest` and calls `manifest.save()`.
- `PackageManifest::save_and_get_written_value()` currently does a direct `File::create` + `write_all`, which both truncates in-place and follows symlinks.
- The repo already has robust “write temp + rename” patterns (e.g. `pacquet_fs::ensure_file` / lockfile atomic writers) that avoid symlink-following at the temp path and prevent torn writes.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
### What to change
1. Update `PackageManifest::save_and_get_written_value()` (preferred, since it centralizes all manifest writes) to write via a temp file in the same directory and then rename over `package.json` (overwrite-safe on Windows too).
- Reuse/extract an existing atomic writer (e.g. the `write_atomic`/`rename_with_retry` approach in `pacquet_fs::ensure_file`, or introduce a small shared helper in `pacquet_fs`).
- Ensure the temp file is created with `create_new(true)` to avoid following a pre-seeded symlink at the temp path.
2. (Optional, stricter) Decide policy for an existing `package.json` that is itself a symlink:
- Either reject with a clear diagnostic (safest), or
- Ensure the rename replaces the symlink itself (never writes to its target).
3. Add/extend a test that constructs a symlinked `package.json` in a temp dir and verifies `set-script` does **not** overwrite the symlink target.

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



Remediation recommended
2. Scripts edit blocked by deps 🐞 Bug ☼ Reliability
Description
SetScriptArgs::run saves via PackageManifest::save(), which performs
dependencies/devDependencies runtime-folding and rejects non-object dependency fields, so
pacquet set-script can fail (or rewrite non-scripts fields) even though it’s intended to only
update package.json#scripts. Example: a manifest with "dependencies": "oops" will error during
save with "the dependencies field must be an object" and prevent setting the script.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-65]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
Evidence
The new command always persists via PackageManifest::save(). That save path clones the whole JSON,
applies dependency/engines conversions, and errors when dependency fields are present but not JSON
objects—so a scripts-only edit can unexpectedly fail or modify additional fields.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-168]
pacquet/crates/package-manifest/src/lib.rs[404-413]
pacquet/crates/cli/src/cli_args.rs[374-380]

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 set-script` is intended to only update `package.json#scripts`, but it writes via `PackageManifest::save()`, which runs dependency/engines runtime folding and validates dependency map shapes. This can cause `set-script` to fail (or touch unrelated fields) due to unrelated manifest data.
### Issue Context
`PackageManifest::save_and_get_written_value()` calls `convert_dependencies_to_engines_runtime()` for `devDependencies` and `dependencies`, and that conversion returns `InvalidAttribute` when those fields exist but are not objects.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
- pacquet/crates/package-manifest/src/lib.rs[404-413]
### Suggested approach
- Add a `PackageManifest` API (or a local save path in `set-script`) that writes the manifest without performing dependency/engines runtime conversions/validations, since `set-script` only needs to update `scripts`.
- Alternatively, make the runtime-folding conversion conditional so it does not error for unrelated invalid `dependencies`/`devDependencies` shapes in commands that don’t touch those fields.

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


3. set-script silent no-op 🐞 Bug ≡ Correctness
Description
If package.json parses to a non-object JSON value, set_script() returns early without mutating,
but run() still saves and returns success, so the CLI reports success while not setting the
script. This can confuse users/automation and hides that the manifest is in an invalid shape for
mutation.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R84-86]

+fn set_script(manifest: &mut Value, name: String, command: String) {
+    let Some(manifest) = manifest.as_object_mut() else { return };
+    let scripts = manifest.entry("scripts").or_insert_with(|| Value::Object(Map::new()));
Evidence
set_script() currently bails out silently when the manifest root is not an object, and run()
does not check whether mutation occurred before saving and returning success. Since
PackageManifest::read_from_file() parses arbitrary JSON into Value without enforcing an object
root, this condition is reachable with malformed manifests.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/cli/src/cli_args/set_script.rs[84-86]
pacquet/crates/package-manifest/src/lib.rs[99-105]

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 set-script` can exit successfully without writing the requested script when the parsed `package.json` root is not a JSON object.
### Issue Context
`PackageManifest::from_path()` deserializes `package.json` into an unconstrained `serde_json::Value`, so the root may be a non-object (string/array/etc.). The current `set_script()` helper silently returns in that case, and the caller still invokes `save()` and returns `Ok(())`.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-67]
- pacquet/crates/cli/src/cli_args/set_script.rs[84-94]
### Proposed fix
- Make `set_script` return `Result<(), SetScriptError>` (or a new error type) instead of silently returning.
- If `manifest.as_object_mut()` is `None`, return a diagnostic error (and ensure `run()` propagates it) so the command fails instead of silently succeeding.
- Add a unit/integration test that writes a non-object `package.json` (e.g. `"oops"`) and asserts the command fails with a stable diagnostic code/message.

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


4. Non-atomic manifest save 🐞 Bug ☼ Reliability
Description
set-script persists changes by calling PackageManifest::save(), which truncates package.json
and writes new contents directly; a crash or mid-write I/O failure can leave an empty/partial
manifest. This is a reliability hazard for a command whose sole purpose is editing package.json.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save(), and the underlying save path uses fs::File::create
(truncate) followed by write_all, with no temp-file + rename step, so an interrupted write can
corrupt package.json.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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

## Issue description
`PackageManifest::save_and_get_written_value()` writes by truncating the target file and streaming the new JSON, which is not crash-safe.
### Issue Context
`pacquet set-script` now exposes a dedicated manifest-editing command path that can corrupt `package.json` if the process is interrupted (panic, SIGKILL, power loss) during write.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[156-163]
- pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
### Proposed fix
- Implement atomic write in `PackageManifest::save_and_get_written_value()`:
- write to a temp file in the same directory (to keep rename atomic on the same filesystem),
- `flush`/`sync_all` the temp file as appropriate,
- `rename` over the destination,
- optionally `sync_all` the parent directory for durability.
- Keep the API the same so all callers (including add/update/remove and this new set-script command) benefit automatically.
- Add a focused unit test if the repo has a pattern for simulating mid-write failures; otherwise, document the atomicity guarantee in code comments.

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


Results up to commit 9763b07


🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Tickets: 🎫 Rust Roadmap

Action required
1. Symlink clobber write 🐞 Bug ⛨ Security
Description
set-script persists changes by calling PackageManifest::save(), whose implementation uses
fs::File::create(path) and will follow an existing package.json symlink, truncating/overwriting
the symlink target. In a malicious repo where package.json is a symlink, running `pacquet
set-script` can overwrite an arbitrary user-writable file outside the repo.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save() after mutating JSON.
PackageManifest::save_and_get_written_value() uses fs::File::create(&self.path) and write_all,
which follows symlinks and truncates the target, enabling arbitrary file overwrite when
package.json is a symlink in an attacker-controlled repo.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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 set-script` writes back to `package.json` via `PackageManifest::save()`. The current save implementation uses `fs::File::create(&self.path)` which follows symlinks; a repo-controlled `package.json -> /some/other/file` can cause an arbitrary file overwrite when the victim runs `pacquet set-script` in that repo.
### Issue Context
- The CLI dispatch calls `SetScriptArgs::run(&manifest_path())`, which loads `PackageManifest` and calls `manifest.save()`.
- `PackageManifest::save_and_get_written_value()` currently does a direct `File::create` + `write_all`, which both truncates in-place and follows symlinks.
- The repo already has robust “write temp + rename” patterns (e.g. `pacquet_fs::ensure_file` / lockfile atomic writers) that avoid symlink-following at the temp path and prevent torn writes.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
### What to change
1. Update `PackageManifest::save_and_get_written_value()` (preferred, since it centralizes all manifest writes) to write via a temp file in the same directory and then rename over `package.json` (overwrite-safe on Windows too).
- Reuse/extract an existing atomic writer (e.g. the `write_atomic`/`rename_with_retry` approach in `pacquet_fs::ensure_file`, or introduce a small shared helper in `pacquet_fs`).
- Ensure the temp file is created with `create_new(true)` to avoid following a pre-seeded symlink at the temp path.
2. (Optional, stricter) Decide policy for an existing `package.json` that is itself a symlink:
- Either reject with a clear diagnostic (safest), or
- Ensure the rename replaces the symlink itself (never writes to its target).
3. Add/extend a test that constructs a symlinked `package.json` in a temp dir and verifies `set-script` does **not** overwrite the symlink target.

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



Remediation recommended
2. Scripts edit blocked by deps 🐞 Bug ☼ Reliability
Description
SetScriptArgs::run saves via PackageManifest::save(), which performs
dependencies/devDependencies runtime-folding and rejects non-object dependency fields, so
pacquet set-script can fail (or rewrite non-scripts fields) even though it’s intended to only
update package.json#scripts. Example: a manifest with "dependencies": "oops" will error during
save with "the dependencies field must be an object" and prevent setting the script.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-65]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
Evidence
The new command always persists via PackageManifest::save(). That save path clones the whole JSON,
applies dependency/engines conversions, and errors when dependency fields are present but not JSON
objects—so a scripts-only edit can unexpectedly fail or modify additional fields.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-168]
pacquet/crates/package-manifest/src/lib.rs[404-413]
pacquet/crates/cli/src/cli_args.rs[374-380]

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 set-script` is intended to only update `package.json#scripts`, but it writes via `PackageManifest::save()`, which runs dependency/engines runtime folding and validates dependency map shapes. This can cause `set-script` to fail (or touch unrelated fields) due to unrelated manifest data.
### Issue Context
`PackageManifest::save_and_get_written_value()` calls `convert_dependencies_to_engines_runtime()` for `devDependencies` and `dependencies`, and that conversion returns `InvalidAttribute` when those fields exist but are not objects.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
- pacquet/crates/package-manifest/src/lib.rs[404-413]
### Suggested approach
- Add a `PackageManifest` API (or a local save path in `set-script`) that writes the manifest without performing dependency/engines runtime conversions/validations, since `set-script` only needs to update `scripts`.
- Alternatively, make the runtime-folding conversion conditional so it does not error for unrelated invalid `dependencies`/`devDependencies` shapes in commands that don’t touch those fields.

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


3. set-script silent no-op 🐞 Bug ≡ Correctness
Description
If package.json parses to a non-object JSON value, set_script() returns early without mutating,
but run() still saves and returns success, so the CLI reports success while not setting the
script. This can confuse users/automation and hides that the manifest is in an invalid shape for
mutation.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R84-86]

+fn set_script(manifest: &mut Value, name: String, command: String) {
+    let Some(manifest) = manifest.as_object_mut() else { return };
+    let scripts = manifest.entry("scripts").or_insert_with(|| Value::Object(Map::new()));
Evidence
set_script() currently bails out silently when the manifest root is not an object, and run()
does not check whether mutation occurred before saving and returning success. Since
PackageManifest::read_from_file() parses arbitrary JSON into Value without enforcing an object
root, this condition is reachable with malformed manifests.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/cli/src/cli_args/set_script.rs[84-86]
pacquet/crates/package-manifest/src/lib.rs[99-105]

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 set-script` can exit successfully without writing the requested script when the parsed `package.json` root is not a JSON object.
### Issue Context
`PackageManifest::from_path()` deserializes `package.json` into an unconstrained `serde_json::Value`, so the root may be a non-object (string/array/etc.). The current `set_script()` helper silently returns in that case, and the caller still invokes `save()` and returns `Ok(())`.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-67]
- pacquet/crates/cli/src/cli_args/set_script.rs[84-94]
### Proposed fix
- Make `set_script` return `Result<(), SetScriptError>` (or a new error type) instead of silently returning.
- If `manifest.as_object_mut()` is `None`, return a diagnostic error (and ensure `run()` propagates it) so the command fails instead of silently succeeding.
- Add a unit/integration test that writes a non-object `package.json` (e.g. `"oops"`) and asserts the command fails with a stable diagnostic code/message.

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


4. Non-atomic manifest save 🐞 Bug ☼ Reliability
Description
set-script persists changes by calling PackageManifest::save(), which truncates package.json
and writes new contents directly; a crash or mid-write I/O failure can leave an empty/partial
manifest. This is a reliability hazard for a command whose sole purpose is editing package.json.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save(), and the underlying save path uses fs::File::create
(truncate) followed by write_all, with no temp-file + rename step, so an interrupted write can
corrupt package.json.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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

## Issue description
`PackageManifest::save_and_get_written_value()` writes by truncating the target file and streaming the new JSON, which is not crash-safe.
### Issue Context
`pacquet set-script` now exposes a dedicated manifest-editing command path that can corrupt `package.json` if the process is interrupted (panic, SIGKILL, power loss) during write.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[156-163]
- pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
### Proposed fix
- Implement atomic write in `PackageManifest::save_and_get_written_value()`:
- write to a temp file in the same directory (to keep rename atomic on the same filesystem),
- `flush`/`sync_all` the temp file as appropriate,
- `rename` over the destination,
- optionally `sync_all` the parent directory for durability.
- Keep the API the same so all callers (including add/update/remove and this new set-script command) benefit automatically.
- Add a focused unit test if the repo has a pattern for simulating mid-write failures; otherwise, document the atomicity guarantee in code comments.

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


Results up to commit 9763b07


🐞 Bugs (4) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Tickets: 🎫 Rust Roadmap

Action required
1. Symlink clobber write 🐞 Bug ⛨ Security
Description
set-script persists changes by calling PackageManifest::save(), whose implementation uses
fs::File::create(path) and will follow an existing package.json symlink, truncating/overwriting
the symlink target. In a malicious repo where package.json is a symlink, running `pacquet
set-script` can overwrite an arbitrary user-writable file outside the repo.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save() after mutating JSON.
PackageManifest::save_and_get_written_value() uses fs::File::create(&self.path) and write_all,
which follows symlinks and truncates the target, enabling arbitrary file overwrite when
package.json is a symlink in an attacker-controlled repo.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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 set-script` writes back to `package.json` via `PackageManifest::save()`. The current save implementation uses `fs::File::create(&self.path)` which follows symlinks; a repo-controlled `package.json -> /some/other/file` can cause an arbitrary file overwrite when the victim runs `pacquet set-script` in that repo.
### Issue Context
- The CLI dispatch calls `SetScriptArgs::run(&manifest_path())`, which loads `PackageManifest` and calls `manifest.save()`.
- `PackageManifest::save_and_get_written_value()` currently does a direct `File::create` + `write_all`, which both truncates in-place and follows symlinks.
- The repo already has robust “write temp + rename” patterns (e.g. `pacquet_fs::ensure_file` / lockfile atomic writers) that avoid symlink-following at the temp path and prevent torn writes.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
### What to change
1. Update `PackageManifest::save_and_get_written_value()` (preferred, since it centralizes all manifest writes) to write via a temp file in the same directory and then rename over `package.json` (overwrite-safe on Windows too).
 - Reuse/extract an existing atomic writer (e.g. the `write_atomic`/`rename_with_retry` approach in `pacquet_fs::ensure_file`, or introduce a small shared helper in `pacquet_fs`).
 - Ensure the temp file is created with `create_new(true)` to avoid following a pre-seeded symlink at the temp path.
2. (Optional, stricter) Decide policy for an existing `package.json` that is itself a symlink:
 - Either reject with a clear diagnostic (safest), or
 - Ensure the rename replaces the symlink itself (never writes to its target).
3. Add/extend a test that constructs a symlinked `package.json` in a temp dir and verifies `set-script` does **not** overwrite the symlink target.

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



Remediation recommended
2. Scripts edit blocked by deps 🐞 Bug ☼ Reliability ⭐ New
Description
SetScriptArgs::run saves via PackageManifest::save(), which performs
dependencies/devDependencies runtime-folding and rejects non-object dependency fields, so
pacquet set-script can fail (or rewrite non-scripts fields) even though it’s intended to only
update package.json#scripts. Example: a manifest with "dependencies": "oops" will error during
save with "the dependencies field must be an object" and prevent setting the script.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-65]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
Evidence
The new command always persists via PackageManifest::save(). That save path clones the whole JSON,
applies dependency/engines conversions, and errors when dependency fields are present but not JSON
objects—so a scripts-only edit can unexpectedly fail or modify additional fields.

pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
pacquet/crates/package-manifest/src/lib.rs[156-168]
pacquet/crates/package-manifest/src/lib.rs[404-413]
pacquet/crates/cli/src/cli_args.rs[374-380]

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 set-script` is intended to only update `package.json#scripts`, but it writes via `PackageManifest::save()`, which runs dependency/engines runtime folding and validates dependency map shapes. This can cause `set-script` to fail (or touch unrelated fields) due to unrelated manifest data.

### Issue Context
`PackageManifest::save_and_get_written_value()` calls `convert_dependencies_to_engines_runtime()` for `devDependencies` and `dependencies`, and that conversion returns `InvalidAttribute` when those fields exist but are not objects.

### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-66]
- pacquet/crates/package-manifest/src/lib.rs[156-169]
- pacquet/crates/package-manifest/src/lib.rs[404-413]

### Suggested approach
- Add a `PackageManifest` API (or a local save path in `set-script`) that writes the manifest without performing dependency/engines runtime conversions/validations, since `set-script` only needs to update `scripts`.
- Alternatively, make the runtime-folding conversion conditional so it does not error for unrelated invalid `dependencies`/`devDependencies` shapes in commands that don’t touch those fields.

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


3. set-script silent no-op 🐞 Bug ≡ Correctness
Description
If package.json parses to a non-object JSON value, set_script() returns early without mutating,
but run() still saves and returns success, so the CLI reports success while not setting the
script. This can confuse users/automation and hides that the manifest is in an invalid shape for
mutation.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R84-86]

+fn set_script(manifest: &mut Value, name: String, command: String) {
+    let Some(manifest) = manifest.as_object_mut() else { return };
+    let scripts = manifest.entry("scripts").or_insert_with(|| Value::Object(Map::new()));
Evidence
set_script() currently bails out silently when the manifest root is not an object, and run()
does not check whether mutation occurred before saving and returning success. Since
PackageManifest::read_from_file() parses arbitrary JSON into Value without enforcing an object
root, this condition is reachable with malformed manifests.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/cli/src/cli_args/set_script.rs[84-86]
pacquet/crates/package-manifest/src/lib.rs[99-105]

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 set-script` can exit successfully without writing the requested script when the parsed `package.json` root is not a JSON object.
### Issue Context
`PackageManifest::from_path()` deserializes `package.json` into an unconstrained `serde_json::Value`, so the root may be a non-object (string/array/etc.). The current `set_script()` helper silently returns in that case, and the caller still invokes `save()` and returns `Ok(())`.
### Fix Focus Areas
- pacquet/crates/cli/src/cli_args/set_script.rs[50-67]
- pacquet/crates/cli/src/cli_args/set_script.rs[84-94]
### Proposed fix
- Make `set_script` return `Result<(), SetScriptError>` (or a new error type) instead of silently returning.
- If `manifest.as_object_mut()` is `None`, return a diagnostic error (and ensure `run()` propagates it) so the command fails instead of silently succeeding.
- Add a unit/integration test that writes a non-object `package.json` (e.g. `"oops"`) and asserts the command fails with a stable diagnostic code/message.

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


4. Non-atomic manifest save 🐞 Bug ☼ Reliability
Description
set-script persists changes by calling PackageManifest::save(), which truncates package.json
and writes new contents directly; a crash or mid-write I/O failure can leave an empty/partial
manifest. This is a reliability hazard for a command whose sole purpose is editing package.json.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence
The new command calls manifest.save(), and the underlying save path uses fs::File::create
(truncate) followed by write_all, with no temp-file + rename step, so an interrupted write can
corrupt package.json.

pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
pacquet/crates/package-manifest/src/lib.rs[156-163]

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

## Issue description
`PackageManifest::save_and_get_written_value()` writes by truncating the target file and streaming the new JSON, which is not crash-safe.
### Issue Context
`pacquet set-script` now exposes a dedicated manifest-editing command path that can corrupt `package.json` if the process is interrupted (panic, SIGKILL, power loss) during write.
### Fix Focus Areas
- pacquet/crates/package-manifest/src/lib.rs[156-163]
- pacquet/crates/cli/src/cli_args/set_script.rs[62-66]
### Proposed fix
- Implement atomic write in `PackageManifest::save_and_get_written_value()`:
- write to a temp file in the same directory (to keep rename atomic on the same filesystem),
- `flush`/`sync_all` the temp file as appropriate,
- `rename` over the destination,
- optionally `sync_all` the parent directory for durability.
- Keep the API the same so all callers (including add/update/remove and this new set-script command) benefit automatically.
- Add a focused unit test if the repo has a pattern for simulating mid-write failures; otherwise, document the atomicity guarantee in code comments.

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


Results up to commit e549efd


🐞 Bugs (3) 📘 Rule violations (0) 📎 Requirement gaps (0) 📜 Skill insights (0)

Context used
✅ Tickets: 🎫 Rust Roadmap

Action required
1. Symlink clobber write 🐞 Bug ⛨ Security ⭐ New
Description
set-script persists changes by calling PackageManifest::save(), whose implementation uses
fs::File::create(path) and will follow an existing package.json symlink, truncating/overwriting
the symlink target. In a malicious repo where package.json is a symlink, running `pacquet
set-script` can overwrite an arbitrary user-writable file outside the repo.
Code

pacquet/crates/cli/src/cli_args/set_script.rs[R62-66]

+        let mut manifest = PackageManifest::from_path(manifest_path.to_path_buf())
+            .wrap_err("reading package.json")?;
+        set_script(manifest.value_mut(), name, command);
+        manifest.save().wrap_err("saving package.json")?;
+        Ok(())
Evidence

@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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@pacquet/crates/cli/src/cli_args/set_script.rs`:
- Around line 62-66: The save() method in PackageManifest uses
fs::File::create() which truncates the file immediately and can leave
package.json corrupted if the write or serialization fails mid-way. Replace the
file writing logic with an atomic write pattern by writing to a temporary file
first, then atomically renaming it to the target manifest path. Additionally,
the read_from_file() method does not validate that the parsed JSON root is an
object before it is used, though set_script() currently guards against
non-object roots via as_object_mut() check. Either add explicit validation in
read_from_file() to assert the root is a Value::Object, or clearly document this
invariant in the code comments to explain why set_script() relies on the
as_object_mut() guard for safety.

In `@pacquet/crates/cli/tests/set_script.rs`:
- Around line 99-117: Add a new test function to cover the case where pacquet
set-script is invoked with zero extra arguments (no name and no command), which
exercises a different code path in SetScriptArgs::run than the existing
fails_when_arguments_are_missing test. The new test should follow the same
pattern: initialize a CommandTempCwd, call pacquet.with_args with only
["set-script"], verify the command fails, and assert that the stderr contains
the appropriate error code for missing arguments.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b0608ff5-c807-4f86-aa79-91ea448a585c

📥 Commits

Reviewing files that changed from the base of the PR and between 9671d9a and e549efd.

📒 Files selected for processing (4)
  • pacquet/crates/cli/src/cli_args.rs
  • pacquet/crates/cli/src/cli_args/set_script.rs
  • pacquet/crates/cli/src/cli_args/set_script/tests.rs
  • pacquet/crates/cli/tests/set_script.rs

Comment thread pacquet/crates/cli/tests/set_script.rs Resolved
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

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

@codecov-commenter

codecov-commenter commented Jun 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.50%. Comparing base (ebd38f8) to head (f7c6ad9).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #12618   +/-   ##
=======================================
  Coverage   88.49%   88.50%           
=======================================
  Files         335      336    +1     
  Lines       48823    48859   +36     
=======================================
+ Hits        43207    43243   +36     
  Misses       5616     5616           

☔ 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.

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: f7c6ad9a9de2

Each scenario reports direct installs and pnpr installs. Bencher consumes pacquet@HEAD and pnpr@HEAD.

Scenario: Isolated linker: fresh restore, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.562 ± 0.142 4.363 4.731 1.55 ± 0.08
pacquet@main 4.531 ± 0.139 4.357 4.784 1.54 ± 0.08
pnpr@HEAD 2.949 ± 0.121 2.802 3.105 1.00
pnpr@main 3.037 ± 0.122 2.873 3.235 1.03 ± 0.06
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.56229831844,
      "stddev": 0.1418653813219754,
      "median": 4.548023110339999,
      "user": 3.652848060000001,
      "system": 3.43228832,
      "min": 4.363077522339999,
      "max": 4.73078692134,
      "times": [
        4.72389569234,
        4.5686775613399995,
        4.73078692134,
        4.5273686593399995,
        4.7259568203399995,
        4.46634627734,
        4.436390193339999,
        4.66842819034,
        4.41205534634,
        4.363077522339999
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.530635929440001,
      "stddev": 0.1385488359690996,
      "median": 4.4941869608400005,
      "user": 3.7326891599999996,
      "system": 3.41959582,
      "min": 4.35700035334,
      "max": 4.78368675634,
      "times": [
        4.65834128434,
        4.59673199634,
        4.49269776334,
        4.49567615834,
        4.48817156234,
        4.42586961934,
        4.78368675634,
        4.35700035334,
        4.36082506134,
        4.6473587393399995
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 2.94882781844,
      "stddev": 0.12135075863783834,
      "median": 2.9079885018400002,
      "user": 2.69003006,
      "system": 3.01913052,
      "min": 2.8021174063400003,
      "max": 3.1049728193400004,
      "times": [
        2.89684611934,
        2.8224838983400002,
        3.0666954463400002,
        2.82648994434,
        3.1049728193400004,
        3.1013223553400002,
        3.05684357434,
        2.9191308843400003,
        2.89137573634,
        2.8021174063400003
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.0373678705400002,
      "stddev": 0.12171600460890923,
      "median": 3.0960110733400006,
      "user": 2.73284036,
      "system": 3.0274566199999997,
      "min": 2.8729445093400003,
      "max": 3.2354442973400004,
      "times": [
        3.2354442973400004,
        2.9323595353400003,
        3.0875595873400004,
        3.11414542934,
        2.8729445093400003,
        2.9085831693400004,
        3.10594487034,
        3.1044625593400004,
        3.1058164673400004,
        2.90641828034
      ]
    }
  ]
}

Scenario: Isolated linker: fresh restore, hot cache + hot store

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 638.3 ± 10.7 618.6 650.8 1.00 ± 0.02
pacquet@main 636.3 ± 8.9 622.7 653.8 1.00
pnpr@HEAD 699.0 ± 14.7 677.1 723.0 1.10 ± 0.03
pnpr@main 714.2 ± 42.4 672.3 826.2 1.12 ± 0.07
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.6383084500400001,
      "stddev": 0.01066836219394596,
      "median": 0.6395206740400001,
      "user": 0.39721641999999996,
      "system": 1.3165922799999996,
      "min": 0.6185793115400001,
      "max": 0.6507856715400001,
      "times": [
        0.64978569754,
        0.6337534085400001,
        0.64759504554,
        0.62404554154,
        0.6376824655400001,
        0.6507856715400001,
        0.6431704835400001,
        0.6413588825400001,
        0.63632799254,
        0.6185793115400001
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.6362741104400002,
      "stddev": 0.008936069582235456,
      "median": 0.6335017805400001,
      "user": 0.40047151999999997,
      "system": 1.3039994799999997,
      "min": 0.62273901854,
      "max": 0.6537815035400001,
      "times": [
        0.6431593655400001,
        0.6320996765400001,
        0.6283777705400001,
        0.6537815035400001,
        0.62273901854,
        0.6346164775400001,
        0.6419755665400001,
        0.63175918854,
        0.6323870835400001,
        0.6418454535400001
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.6989595713400001,
      "stddev": 0.014725117051366948,
      "median": 0.7009563855400001,
      "user": 0.41305421999999997,
      "system": 1.3419978799999999,
      "min": 0.6770729015400001,
      "max": 0.7229933295400001,
      "times": [
        0.6770729015400001,
        0.7044333325400001,
        0.71100317154,
        0.6783363135400001,
        0.6910747115400001,
        0.6915706435400001,
        0.6977980195400001,
        0.71119853854,
        0.7229933295400001,
        0.70411475154
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.71417503464,
      "stddev": 0.04238857688283934,
      "median": 0.7038201220400001,
      "user": 0.40175642,
      "system": 1.3553849799999997,
      "min": 0.6722658825400001,
      "max": 0.82624156654,
      "times": [
        0.69154700554,
        0.6883099545400001,
        0.72307837354,
        0.6722658825400001,
        0.6997113085400001,
        0.7063626865400001,
        0.7012775575400001,
        0.82624156654,
        0.7250906275400001,
        0.7078653835400001
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + cold store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.750 ± 0.065 4.631 4.836 1.50 ± 0.05
pacquet@main 4.783 ± 0.050 4.712 4.851 1.51 ± 0.04
pnpr@HEAD 3.165 ± 0.086 3.005 3.283 1.00
pnpr@main 3.221 ± 0.118 3.083 3.464 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.74972036158,
      "stddev": 0.0649042183870086,
      "median": 4.75624598658,
      "user": 3.7941646799999993,
      "system": 3.4066744399999997,
      "min": 4.63116063958,
      "max": 4.83599318058,
      "times": [
        4.73336017658,
        4.80891165558,
        4.77913179658,
        4.83599318058,
        4.8134788005799996,
        4.78380469858,
        4.71473781158,
        4.70284580558,
        4.63116063958,
        4.69377905058
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.78311660268,
      "stddev": 0.050075098369475844,
      "median": 4.79606100008,
      "user": 3.86907198,
      "system": 3.42119004,
      "min": 4.71152904958,
      "max": 4.85076656958,
      "times": [
        4.84822162258,
        4.71152904958,
        4.71918836458,
        4.81257777058,
        4.760499386579999,
        4.796479370579999,
        4.85076656958,
        4.79564262958,
        4.733657904579999,
        4.80260335858
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.16520853938,
      "stddev": 0.08628574603871386,
      "median": 3.1759201360800002,
      "user": 2.81040768,
      "system": 3.1502794399999994,
      "min": 3.00537714858,
      "max": 3.28348807858,
      "times": [
        3.23313391158,
        3.1088684955800003,
        3.10141718658,
        3.09672214758,
        3.00537714858,
        3.28348807858,
        3.2211548205800002,
        3.18933606058,
        3.25008333258,
        3.16250421158
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.22138819388,
      "stddev": 0.11802312907796873,
      "median": 3.18114433458,
      "user": 2.8721147799999995,
      "system": 3.1548648399999997,
      "min": 3.0831477835800003,
      "max": 3.46363059258,
      "times": [
        3.13007864358,
        3.27275579358,
        3.14995720758,
        3.46363059258,
        3.32523059158,
        3.14925210058,
        3.2123314615800003,
        3.12625805958,
        3.0831477835800003,
        3.30123970458
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, hot cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.336 ± 0.014 1.305 1.352 1.00
pacquet@main 1.376 ± 0.084 1.325 1.613 1.03 ± 0.06
pnpr@HEAD 1.417 ± 0.037 1.382 1.516 1.06 ± 0.03
pnpr@main 1.420 ± 0.060 1.385 1.586 1.06 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.33571000702,
      "stddev": 0.013526309843482732,
      "median": 1.3420100215200002,
      "user": 1.3259854999999998,
      "system": 1.6951599199999996,
      "min": 1.30463683052,
      "max": 1.3518849745200001,
      "times": [
        1.3418235765200002,
        1.3421964665200001,
        1.3423696205200002,
        1.33051517852,
        1.34426609152,
        1.3518849745200001,
        1.30463683052,
        1.3277075815200001,
        1.32774411952,
        1.34395563052
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.37577342442,
      "stddev": 0.0844377433389386,
      "median": 1.3502418980200002,
      "user": 1.3365293999999999,
      "system": 1.7054184199999998,
      "min": 1.32513275552,
      "max": 1.61254877752,
      "times": [
        1.35161489052,
        1.37406487652,
        1.61254877752,
        1.35109998552,
        1.34371345552,
        1.37066684152,
        1.3394826205200001,
        1.3400262305200001,
        1.34938381052,
        1.32513275552
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4165983158200002,
      "stddev": 0.037146910091908986,
      "median": 1.40784836852,
      "user": 0.6129396,
      "system": 1.5533675199999997,
      "min": 1.38168650552,
      "max": 1.5164282205200001,
      "times": [
        1.4087357015200002,
        1.41002142552,
        1.4031427735200002,
        1.5164282205200001,
        1.3929745345200002,
        1.41979316852,
        1.40696103552,
        1.40165913552,
        1.4245806575200002,
        1.38168650552
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.4197626678200002,
      "stddev": 0.060114094369272876,
      "median": 1.3992717890200002,
      "user": 0.5991617999999999,
      "system": 1.56382032,
      "min": 1.38495026252,
      "max": 1.58644925552,
      "times": [
        1.4286391975200001,
        1.58644925552,
        1.41613810452,
        1.38795936352,
        1.39530259652,
        1.38495026252,
        1.4088644355200002,
        1.3913777255200002,
        1.40324098152,
        1.39470475552
      ]
    }
  ]
}

Scenario: Isolated linker: fresh install, cold cache + hot store

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 3.020 ± 0.038 2.987 3.116 2.15 ± 0.04
pacquet@main 3.067 ± 0.053 3.001 3.206 2.18 ± 0.05
pnpr@HEAD 1.406 ± 0.020 1.375 1.446 1.00
pnpr@main 1.431 ± 0.064 1.393 1.609 1.02 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 3.0203994687,
      "stddev": 0.03804623749724153,
      "median": 3.0119880483999997,
      "user": 1.7904553800000003,
      "system": 1.9380703999999997,
      "min": 2.9866931438999997,
      "max": 3.1162486099,
      "times": [
        2.9903051149,
        3.0144596138999997,
        2.9993487629,
        2.9866931438999997,
        3.0257294739,
        3.0206660369,
        3.0447360458999997,
        2.9962914018999998,
        3.1162486099,
        3.0095164828999996
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 3.0674776962,
      "stddev": 0.05312754192078872,
      "median": 3.0549300098999996,
      "user": 1.80630618,
      "system": 2.0125701,
      "min": 3.0014314099,
      "max": 3.2060981759,
      "times": [
        3.0625396139,
        3.0401662258999997,
        3.0849055589,
        3.0550963179,
        3.0539538219,
        3.0519882098999997,
        3.0014314099,
        3.0547637019,
        3.2060981759,
        3.0638339259
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.4060841628,
      "stddev": 0.019780308701746917,
      "median": 1.4040937359,
      "user": 0.60602108,
      "system": 1.5660829999999997,
      "min": 1.3754063509,
      "max": 1.4460607779,
      "times": [
        1.4460607779,
        1.4187432759,
        1.4065989489000001,
        1.4244484139000002,
        1.3926380179000002,
        1.4058986929000001,
        1.3916339529000001,
        1.4022887789,
        1.3754063509,
        1.3971244179
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.4305174268000003,
      "stddev": 0.0639146563099218,
      "median": 1.4098523324,
      "user": 0.60670778,
      "system": 1.5686136999999998,
      "min": 1.3930790339,
      "max": 1.6091655999,
      "times": [
        1.4310638839,
        1.4109470129000001,
        1.6091655999,
        1.3950599489,
        1.4220758269,
        1.4087576519,
        1.3930790339,
        1.4051194639,
        1.4067644659,
        1.4231413799000001
      ]
    }
  ]
}

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12618
Testbedpacquet
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
milliseconds (ms)
(Result Δ%)
Upper Boundary
milliseconds (ms)
(Limit %)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
🚷 view threshold
4,749.72 ms
(+2.18%)Baseline: 4,648.39 ms
5,578.07 ms
(85.15%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
3,020.40 ms
(-0.83%)Baseline: 3,045.68 ms
3,654.81 ms
(82.64%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
1,335.71 ms
(-1.15%)Baseline: 1,351.28 ms
1,621.53 ms
(82.37%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
4,562.30 ms
(+1.37%)Baseline: 4,500.85 ms
5,401.02 ms
(84.47%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
638.31 ms
(+1.60%)Baseline: 628.27 ms
753.93 ms
(84.66%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

github-actions Bot commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/12618
Testbedpnpr

⚠️ WARNING: No Threshold found!

Without a Threshold, no Alerts will ever be generated.

Click here to create a new Threshold
For more information, see the Threshold documentation.
To only post results if a Threshold exists, set the --ci-only-thresholds flag.

Click to view all benchmark results
BenchmarkLatencymilliseconds (ms)
isolated-linker.fresh-install.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
3,165.21 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,406.08 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
1,416.60 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
2,948.83 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
698.96 ms
🐰 View full continuous benchmarking report in Bencher

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9763b07

1 similar comment
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 9763b07

@Safort
Safort force-pushed the feat/pacquet-set-script branch from 9763b07 to f7c6ad9 Compare June 24, 2026 17:31
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

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

1 similar comment
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

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

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jun 24, 2026
@zkochan
zkochan added this pull request to the merge queue Jun 24, 2026
Merged via the queue into pnpm:main with commit 8fec992 Jun 24, 2026
34 checks passed
@welcome

welcome Bot commented Jun 24, 2026

Copy link
Copy Markdown

Congrats on merging your first pull request! 🎉🎉🎉

@coderabbitai coderabbitai Bot mentioned this pull request Jun 25, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Jul 15, 2026
2 of 4 tasks
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 state: automerge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants