Skip to content

test(pacquet): port the upstream optionalDependencies install suite - #13141

Merged
zkochan merged 3 commits into
mainfrom
port-optional-deps-tests
Jul 19, 2026
Merged

zkochan merged 3 commits into
mainfrom
port-optional-deps-tests

Conversation

@zkochan

@zkochan zkochan commented Jul 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #13138: port the TypeScript test coverage whose absence let that bug ship. This lands the "Proper Support Of optionalDependencies" block of pnpm/plans/TEST_PORTING.md — sixteen tests from installing/deps-installer/test/install/optionalDependencies.ts, hoist.ts:540, and the three deps-restorer headless include-filter tests — plus updatingPkgJson.ts:112, whose installSome suite was missing from the plan entirely (a new plan section now enumerates it).

Most ports live in the new crates/cli/tests/optional_dependencies.rs suite. hoist.ts:540 replaces its former known_failures stub (the @pnpm.e2e/not-compatible-with-any-os fixture it was waiting on exists now). The --force-dependent cases (optionalDependencies.ts:199 and the forced-headless tail of :283) are gated as known_failures because install --force is not wired on pacquet's CLI — a parity gap in its own right.

Porting surfaced four behavioral gaps, fixed here so the ports assert pnpm's behavior instead of enshrining divergence (each has a changeset):

  1. Skip-set closure. .modules.yaml's skipped now records the dependencies reachable only through a skipped optional package, and every downstream pass (materialization, hoist, symlinks, bins, prune) observes the closure.
  2. Architecture changes un-skip. Seeded installability skips are re-evaluated on every install, so changing --os / --cpu / supportedArchitectures installs the newly compatible platform packages instead of leaving them skipped.
  3. add moves a dependency between groups. Saving an existing dependency with --save-dev / --save-optional / --save-prod removes it from its old group, and the re-add specifier lookup follows pnpm's findSpec field order (verified against pnpm 11.13.1; the previous pacquet-only test asserting the old behavior is updated).
  4. Hoisted differ tolerates skipped optionals. A missing snapshot behind an optional edge no longer fails the hoisted linker with ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY.

Every ported test was verified to fail with its subject behavior broken (the skip-family via a temporarily neutered compute_skipped_snapshots; the rest failed naturally against the pre-fix code during development). Full runs: pacquet-cli integration suite 1735/1735, pacquet-package-manager + pacquet-real-hoist + pacquet-package-manifest 845/845, clippy and fmt clean.

Known divergences left for follow-up (recorded in the plan / noted here):

  • pacquet drops installability-skipped snapshots from the current lock.yaml where pnpm keeps them (with optional: true markers).
  • A warm dependent's virtual-store slot does not gain in-parent alias symlinks for newly un-skipped optionals; Node resolution works through the .pnpm/node_modules fallback, which is also what upstream's deepRequireCwd assertions exercise.
  • install --force is missing from pacquet's CLI surface (TypeScript pnpm accepts it), as are --global-dir / --global-bin-dir on global commands.
  • The npm-resolver / package-requester unit-level items in the plan section remain open; they test TS-internal API shapes and need a pacquet-native design.

Also hardens the workflow itself: plans/TEST_PORTING.md's "test the tests" instructions (and the AGENTS.md Tests section) now prescribe git restore for reverting the temporary breakage — an mtime-preserving restore leaves cargo serving the binary compiled from the broken source, which surfaced during this work as an hour of impossible-looking flaky failures.

Squash Commit Body

Port the "Proper Support Of optionalDependencies" block of
plans/TEST_PORTING.md — sixteen tests from optionalDependencies.ts,
hoist.ts:540, and the three deps-restorer headless include-filter
tests — plus updatingPkgJson.ts:112, whose installSome suite was
missing from the plan entirely. The force-dependent cases stay gated
as known_failures because `install --force` is not wired on pacquet's
CLI yet.

Porting surfaced four behavioral gaps, fixed here so the ports assert
pnpm's behavior rather than enshrining divergence:

- The recorded skip set is now the reachability closure of the direct
  skips (extend_skipped_with_dependency_closure, applied in both
  install paths before their consumers).
- compute_skipped_snapshots re-evaluates seeded installability skips,
  so changing --os/--cpu/supportedArchitectures between installs
  un-skips the now-compatible platform packages.
- PackageManifest::add_dependency moves an already-declared dependency
  to the target group, and the re-add specifier lookup scans the
  manifest in pnpm's findSpec field order (Peer saves stay additive).
- real-hoist tolerates a missing snapshot behind an optional edge
  instead of failing with ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY.

The TypeScript CLI already behaves this way in all four cases, so no
TS-side changes are needed. Known divergences left for follow-up are
recorded in plans/TEST_PORTING.md and the PR description.

Checklist

  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ port, or the description notes what still needs porting. (Rust-only:
    every behavioral fix brings pacquet to already-verified TypeScript behavior;
    the ported tests are the TS suite's own coverage.)
  • 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.
    (Four changesets, one per behavioral fix; test-only changes need none.)
  • Added or updated tests.
  • Updated the documentation if needed. (plans/TEST_PORTING.md checkboxes
    and a new "Manifest Group Mutations" section.)

Written by an agent (Claude Code, claude-fable-5).


View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.

Summary by CodeRabbit

  • Bug Fixes
    • add now moves name@version between dependency groups (non-peer) instead of leaving duplicates in prior groups.
    • Platform-incompatible optionalDependencies no longer break installs/hoisting; their skipped dependency closure is tracked and respected across fresh, frozen, and headless installs.
    • Seeded installability skips are recomputed on each install and removed when they become compatible after platform/host changes.
  • Tests
    • Expanded/added end-to-end Rust CLI coverage for optional dependencies, hoisting, skipped-link prevention, and dependency-group mutations.
  • Documentation
    • Updated contributor testing/porting guidance for optional-dependency behavior and test-revert practices.

Port the "Proper Support Of optionalDependencies" block of
plans/TEST_PORTING.md — sixteen tests from
`installing/deps-installer/test/install/optionalDependencies.ts`,
`hoist.ts:540`, and the three `deps-restorer` headless include-filter
tests — plus `updatingPkgJson.ts:112`, whose `installSome` suite was
missing from the plan entirely. The new `optional_dependencies.rs` CLI
suite holds most ports; `hoist.ts:540` replaces its former
`known_failures` stub (the fixture it was waiting on exists now), and
the `--force`-dependent cases stay gated because `install --force`
is not wired on pacquet's CLI yet.

Porting surfaced four behavioral gaps, fixed here so the ports assert
pnpm's behavior rather than enshrining divergence:

- The recorded skip set is now the reachability closure of the direct
  skips: dependencies reachable only through a skipped optional package
  land in `.modules.yaml`'s `skipped` too, and every downstream pass
  (materialization, hoist, symlinks, bins, prune) observes them
  (`extend_skipped_with_dependency_closure`, applied in both install
  paths before their consumers).
- `compute_skipped_snapshots` re-evaluates seeded installability skips
  instead of short-circuiting them, so changing `--os` / `--cpu` /
  `supportedArchitectures` between installs un-skips the now-compatible
  platform packages. pnpm recomputes installability fresh on every
  install.
- `PackageManifest::add_dependency` moves an already-declared
  dependency to the target group (and the re-add specifier lookup scans
  the manifest in pnpm's `findSpec` field order), matching
  `updateProjectManifestObject`: a dependency has one home among the
  three install groups. `Peer` saves stay additive.
- `real-hoist` tolerates a missing snapshot behind an *optional* edge
  instead of failing with `ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY` —
  a skipped optional's snapshot is legitimately absent from the current
  lockfile the hoisted-linker differ walks.

The TypeScript CLI already behaves this way in all four cases (the
ported tests are its own coverage; the group-move semantics were
verified against pnpm 11.13.1 directly), so no TS-side changes are
needed. Known divergences left for follow-up, recorded in the plan:
pacquet drops installability-skipped snapshots from the current
lockfile where pnpm keeps them, and a warm dependent's slot does not
gain in-parent alias symlinks for newly un-skipped optionals (Node
resolution works through the `.pnpm/node_modules` fallback, which is
also what upstream's `deepRequireCwd` assertions exercise).
Copilot AI review requested due to automatic review settings July 19, 2026 10:07

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 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR moves dependencies between manifest groups, re-evaluates skipped optional packages, records skipped dependency closures, tolerates missing optional snapshots during hoisting, and adds Rust integration coverage.

Changes

Dependency group moves

Layer / File(s) Summary
Manifest group movement
pnpm/crates/package-manifest/src/lib.rs, pnpm/crates/package-manager/src/add.rs, pnpm/crates/cli/tests/add.rs, pnpm/crates/cli/tests/_utils.rs, .changeset/add-moves-dependency-between-groups.md
Non-peer dependencies are removed from previous install groups, existing specifiers are preserved, and sequential pnpm add operations are tested.

Optional dependency installation

Layer / File(s) Summary
Re-evaluate persisted optional skips
pnpm/crates/package-manager/src/installability.rs, pnpm/crates/package-manager/src/installability/tests.rs, .changeset/reevaluate-skipped-optionals-on-arch-change.md
Persisted installability skips are rechecked against current platform constraints and removed when compatible.
Propagate skipped dependency closures
pnpm/crates/package-manager/src/current_lockfile.rs, pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs, pnpm/crates/package-manager/src/install_frozen_lockfile.rs, pnpm/crates/package-manager/src/install/tests.rs, .changeset/skipped-optional-dependency-closure.md
Fresh and frozen installs expand skipped snapshots to include reachable skipped dependency subtrees.
Hoist missing optional snapshots
pnpm/crates/real-hoist/src/lib.rs, pnpm/crates/cli/tests/hoist.rs, .changeset/hoist-tolerates-skipped-optional-snapshots.md
Hoisting omits missing optional snapshots instead of reporting lockfile-missing-dependency errors, with fresh and frozen install coverage.
Optional dependency integration coverage
pnpm/crates/cli/tests/optional_dependencies.rs, pnpm/plans/TEST_PORTING.md, pnpm/AGENTS.md
Rust tests cover compatibility skips, platform selection, headless installs, fetch failures, lockfile state, hardlinks, frozen reinstalls, and test-porting guidance.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Install
  participant Installability
  participant SkipClosure
  participant Hoister
  Install->>Installability: evaluate optional dependency constraints
  Installability->>SkipClosure: provide directly skipped snapshots
  SkipClosure->>Hoister: provide closure-complete skipped set
  Hoister->>Install: omit missing optional snapshots
Loading

Possibly related PRs

  • pnpm/pnpm#12809 — Modifies skipped-snapshot propagation through the fresh-install and materialization pipeline.
  • pnpm/pnpm#12994 — Also changes installability skip computation in the fresh-install flow.
  • pnpm/pnpm#12995 — Modifies the resolve_added_dependency flow used for preserving existing dependency specs.

Suggested labels: product: pacquet

Suggested reviewers: copilot, yeshyungseok, qodo-code-review

✨ 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 port-optional-deps-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-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Port upstream optionalDependencies install tests; fix skip closure, arch recheck, add-group moves

🧪 Tests 🐞 Bug fix 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Port upstream optionalDependencies install/hoist/headless test coverage into pacquet CLI tests.
• Fix skipped-optional semantics: record full dependency closure and re-evaluate skips on arch
 changes.
• Align pnpm add + hoist behavior: move deps between groups and tolerate missing optional snapshots.
Diagram

graph TD
T["CLI test suites"] --> PM["Install / add flows"] --> CL["Skipped closure"] --> MY[(".modules.yaml")]
PM --> IL["Installability recheck"]
PM --> MF["Manifest group move"]
PM --> RH["Hoist tolerates missing"]
PM --> LF[("Lockfiles")]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Compute skipped-closure only during materialization/hoist
  • ➕ Limits skip-closure computation to consumers that need it (materializer/hoister).
  • ➕ Avoids expanding persisted .modules.yaml.skipped beyond direct installability decisions.
  • ➖ Would diverge from pnpm’s persisted semantics and make state harder to reason about across passes.
  • ➖ Other downstream passes (bins/prune/symlinks/current-lockfile) still need a consistent view, pushing complexity outward.
2. Persist installability skips with host fingerprint (os/cpu/libc/supportedArchitectures)
  • ➕ Makes re-check behavior explicit and could avoid unnecessary recomputation when host inputs are unchanged.
  • ➕ Could support multi-host workspaces more predictably if .modules.yaml is shared/copied.
  • ➖ Requires a schema change to .modules.yaml and migration logic.
  • ➖ Still needs correctness for the “host changed” case; this PR’s approach achieves parity without new schema.
3. Keep stricter hoist behavior (error on missing snapshot)
  • ➕ Surfaces lockfile corruption early for non-optional dependency graph gaps.
  • ➖ Incorrect for optional edges when the current lockfile intentionally filters skipped optionals; breaks valid installs and pnpm parity.
  • ➖ Forces users into lockfile regeneration for benign optional-skip scenarios.

Recommendation: Keep the PR’s approach: centralize skip-closure computation (once per install path) and re-evaluate seeded installability skips every run, matching pnpm’s observable behavior and ensuring all downstream phases consume the same skip set. The optional-edge tolerance in real-hoist is also the right compatibility fix given current-lockfile filtering semantics. Follow-ups can focus on adding install --force CLI parity and (optionally) richer persisted skip metadata if multi-host scenarios become a requirement.

Files changed (18) +1037 / -87

Bug fix (7) +164 / -40
add.rsMatch pnpm specifier lookup order when re-adding dependencies +14/-9

Match pnpm specifier lookup order when re-adding dependencies

• Changes versionless re-add behavior to scan existing specifiers in pnpm’s 'findSpec' order across all dependency fields, rather than only the targeted groups, so the first-found specifier is preserved consistently when moving groups.

pnpm/crates/package-manager/src/add.rs

current_lockfile.rsCompute transitive closure of skipped snapshots +28/-0

Compute transitive closure of skipped snapshots

• Adds 'extend_skipped_with_dependency_closure()' to expand the persisted skip set with snapshots only reachable through already-skipped packages, aligning '.modules.yaml.skipped' and downstream consumers with pnpm semantics.

pnpm/crates/package-manager/src/current_lockfile.rs

install_frozen_lockfile.rsApply skipped-closure expansion in frozen install path +21/-0

Apply skipped-closure expansion in frozen install path

• Extends the computed skipped set with dependency closure before virtual-store creation, hoisting, and symlink/bin passes in the frozen-lockfile install flow.

pnpm/crates/package-manager/src/install_frozen_lockfile.rs

install_with_fresh_lockfile.rsApply skipped-closure expansion in fresh-lockfile install path +17/-0

Apply skipped-closure expansion in fresh-lockfile install path

• Extends the computed skipped set with dependency closure before materialization, hoisting, symlink, and bin passes in the fresh-lockfile install flow.

pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs

installability.rsRe-evaluate seeded installability skips and allow un-skipping on arch change +27/-5

Re-evaluate seeded installability skips and allow un-skipping on arch change

• Adds helpers to distinguish seeded installability skips from transient skip categories and updates 'compute_skipped_snapshots' to re-check seeded keys each run, removing them when they become installable under new host/architecture inputs.

pnpm/crates/package-manager/src/installability.rs

lib.rsMove dependencies between install groups on add/save targets +17/-0

Move dependencies between install groups on add/save targets

• Updates 'PackageManifest::add_dependency' so saving into prod/dev/optional removes the dependency from the other install groups (peer saves remain additive), matching pnpm’s manifest mutation behavior.

pnpm/crates/package-manifest/src/lib.rs

lib.rsHoist builder skips missing optional snapshots instead of erroring +40/-26

Hoist builder skips missing optional snapshots instead of erroring

• Threads optionality through importer and snapshot dependency collection so that a missing snapshot behind an optional edge returns 'None' (skipped) rather than raising a lockfile-missing-dependency error; non-optional missing snapshots still error.

pnpm/crates/real-hoist/src/lib.rs

Tests (6) +824 / -30
_utils.rsAdd helper to read the current lockfile from node_modules/.pnpm/lock.yaml +9/-0

Add helper to read the current lockfile from node_modules/.pnpm/lock.yaml

• Introduces 'read_current_lockfile()' for integration tests to validate the materialized (current) lockfile produced by installs.

pnpm/crates/cli/tests/_utils.rs

add.rsAlign add tests with pnpm group-move semantics and add installSome port +84/-8

Align add tests with pnpm group-move semantics and add installSome port

• Updates an existing test to assert that re-adding a dep with an explicit save target moves it to the new group and follows pnpm’s specifier selection order. Adds a new ported test ensuring sequential adds move dependencies between groups and that the current lockfile reflects the final grouping.

pnpm/crates/cli/tests/add.rs

hoist.rsPort hoist regression test: avoid broken symlinks for skipped optionals +55/-18

Port hoist regression test: avoid broken symlinks for skipped optionals

• Adds an end-to-end hoist test ensuring public hoisting does not create (dangling or real) symlinks for a skipped platform-incompatible optional package or its dependency, including a frozen reinstall. Removes the prior known-failure stub now that the fixture exists.

pnpm/crates/cli/tests/hoist.rs

optional_dependencies.rsNew optionalDependencies integration suite ported from pnpm TypeScript tests +638/-0

New optionalDependencies integration suite ported from pnpm TypeScript tests

• Adds a large Rust test suite covering optional dependency installation, skipping behavior (missing, failing, engine/platform constrained), skip-set persistence across frozen installs, headless include filtering, and hardlink behavior. Includes known-failure stubs for 'install --force' cases not yet exposed by pacquet’s CLI.

pnpm/crates/cli/tests/optional_dependencies.rs

tests.rsUpdate install unit test to expect skipped closure in .modules.yaml +6/-1

Update install unit test to expect skipped closure in .modules.yaml

• Adjusts an install test assertion to include the skipped optional’s dependency in the recorded '.modules.yaml.skipped' list, reflecting the new closure behavior.

pnpm/crates/package-manager/src/install/tests.rs

tests.rsAdjust installability tests for seeded-skip recheck + add unskip coverage +32/-3

Adjust installability tests for seeded-skip recheck + add unskip coverage

• Updates the seeded-skip test to assert re-reporting of the skip on each install, and adds a new test verifying that a seeded skip is dropped when the host becomes compatible.

pnpm/crates/package-manager/src/installability/tests.rs

Documentation (5) +49 / -17
add-moves-dependency-between-groups.mdChangeset: pnpm add moves existing dependency to targeted group +5/-0

Changeset: pnpm add moves existing dependency to targeted group

• Adds a patch changeset documenting that saving an already-declared dependency with explicit save flags moves it between dependency groups instead of duplicating it.

.changeset/add-moves-dependency-between-groups.md

hoist-tolerates-skipped-optional-snapshots.mdChangeset: hoist tolerates missing optional snapshots +5/-0

Changeset: hoist tolerates missing optional snapshots

• Adds a patch changeset documenting that hoisted installs no longer fail when an optional dependency snapshot is absent due to prior skipping.

.changeset/hoist-tolerates-skipped-optional-snapshots.md

reevaluate-skipped-optionals-on-arch-change.mdChangeset: re-evaluate skipped optionals when architecture inputs change +5/-0

Changeset: re-evaluate skipped optionals when architecture inputs change

• Adds a patch changeset documenting that changing os/cpu/libc/supportedArchitectures between installs re-checks previously skipped optionals and installs newly compatible platform packages.

.changeset/reevaluate-skipped-optionals-on-arch-change.md

skipped-optional-dependency-closure.mdChangeset: persist transitive skipped-optional dependency closure +5/-0

Changeset: persist transitive skipped-optional dependency closure

• Adds a patch changeset documenting that '.modules.yaml' now records not just the skipped optional package but also its dependency subtree, matching pnpm behavior.

.changeset/skipped-optional-dependency-closure.md

TEST_PORTING.mdMark optionalDependencies test block as ported and add manifest-mutation section +29/-17

Mark optionalDependencies test block as ported and add manifest-mutation section

• Checks off the newly ported optionalDependencies/hoist/headless tests, documents known divergences ('install --force'), and adds a new section enumerating manifest group-mutation (installSome) suites and their port status.

pnpm/plans/TEST_PORTING.md

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                          main                                   pr
-----                          ----                                   --
lockfile/parse_pnpm_lock       1.00     11.5±0.07ms    32.5 MB/sec    1.00     11.6±0.05ms    32.3 MB/sec
packument/parse                1.08     39.5±0.07µs  1677.2 MB/sec    1.00     36.5±0.13µs  1816.3 MB/sec
tarball/download_dependency    1.00      2.2±0.05ms  1934.9 KB/sec    1.02      2.3±0.06ms  1897.8 KB/sec

@greptile-apps

greptile-apps Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe to merge. All four behavioral fixes are isolated to their respective code paths, the logic matches pnpm's documented behavior, and every new code path has unit and integration test coverage.

The changes are well-scoped: each behavioral fix is surgically applied to one function or module, backed by explicit tests that were verified to fail before the fix, and the resulting behavior matches the TypeScript pnpm reference. The skip-set closure, arch-change un-skip, group-move, and hoist-tolerates-optional-missing changes all have clear correctness invariants documented in code and verified by tests. No pre-existing contracts are broken.

No files require special attention. The install-path changes in install_frozen_lockfile.rs and install_with_fresh_lockfile.rs are the most load-bearing additions, but both are exercised by the new integration tests in optional_dependencies.rs.

Reviews (3): Last reviewed commit: "fix(pacquet): seed the skip closure from..." | Re-trigger Greptile

Comment thread pnpm/crates/real-hoist/src/lib.rs Resolved
@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Action required

1. Known-failure tests lack issue ✓ Resolved 📘 Rule violation ▣ Testability
Description
Two new tests are quarantined via allow_known_failure! without a linked tracking issue reference.
This makes it harder to audit and ensure the missing install --force coverage is re-enabled
promptly.
Code

pnpm/crates/cli/tests/optional_dependencies.rs[R206-242]

+mod known_failures {
+    //! Optional-dependency cases blocked on CLI surface pacquet hasn't
+    //! built yet. Each entry stubs the not-yet-built subject under test
+    //! through [`pacquet_testing_utils::allow_known_failure`] so the
+    //! test exits early rather than masking a real bug.
+
+    use pacquet_testing_utils::{
+        allow_known_failure,
+        known_failure::{KnownFailure, KnownResult},
+    };
+
+    fn install_force_flag() -> KnownResult<()> {
+        Err(KnownFailure::new(
+            "`pnpm install --force` is not wired on pacquet's install \
+             command yet. `Config::force` exists and the installability \
+             check honors it (`pnpm deploy --force` uses that path), but \
+             the install/add CLI does not expose the flag, so the \
+             force-installs-incompatible-optionals behavior is \
+             unreachable end to end.",
+        ))
+    }
+
+    /// TS: `don't skip optional dependency that does not support the
+    /// current OS when forcing` (`optionalDependencies.ts:199`).
+    #[test]
+    fn do_not_skip_unsupported_os_optional_dependency_when_forcing() {
+        allow_known_failure!(install_force_flag());
+    }
+
+    /// The forced-headless tail of TS `optional subdependency is skipped`
+    /// (`optionalDependencies.ts:283`): `force: true, frozenLockfile: true`
+    /// must materialize the incompatible optional and clear
+    /// `.modules.yaml.skipped`.
+    #[test]
+    fn forced_frozen_install_materializes_incompatible_optionals() {
+        allow_known_failure!(install_force_flag());
+    }
Evidence
PR Compliance ID 713440 requires quarantined/skipped tests to include an explicit issue reference.
The new known_failures module stubs out two tests with explanatory text but no linked issue
ID/reference.

Rule 713440: Investigate and resolve all failing tests before merge
pnpm/crates/cli/tests/optional_dependencies.rs[206-242]

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

## Issue description
New `known_failures` test stubs quarantine coverage without an explicit linked tracking issue/reference.

## Issue Context
Compliance requires any newly skipped/xfail/quarantined tests to have an explicit issue reference and justification.

## Fix Focus Areas
- pnpm/crates/cli/tests/optional_dependencies.rs[206-242]

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


2. Transient closure becomes sticky ✓ Resolved 🐞 Bug ≡ Correctness
Description
extend_skipped_with_dependency_closure computes the closure using skipped.contains() (all skip
categories) but inserts discovered closure keys into the persisted installability subset, so
transient skips (e.g. optional_excluded used by skip_runtimes) can leak into
.modules.yaml.skipped. On the frozen-lockfile constraint-free fast path, that seed is reused
verbatim (no re-evaluation), so those leaked entries can keep packages skipped even when the
transient flag is no longer set.
Code

pnpm/crates/package-manager/src/current_lockfile.rs[R272-279]

+    let full = collect_reachable(lockfile, workspace_root, importer_ids, included, |_| false);
+    let kept = collect_reachable(lockfile, workspace_root, importer_ids, included, |key| {
+        skipped.contains(key)
+    });
+    for key in full.snapshot_keys {
+        if !kept.snapshot_keys.contains(&key) && !skipped.contains(&key) {
+            skipped.insert_installability(key);
+        }
Evidence
The closure function prunes reachability using the union skip set but persists newly discovered keys
into the installability subset; .modules.yaml persists only that subset, and frozen installs can
reuse it verbatim when constraints are absent. Additionally, skip_runtimes populates
optional_excluded before the new closure-extension call, so transient skips can influence the
closure computation and become persisted.

pnpm/crates/package-manager/src/current_lockfile.rs[255-281]
pnpm/crates/package-manager/src/install_frozen_lockfile.rs[791-841]
pnpm/crates/package-manager/src/install_frozen_lockfile.rs[640-747]
pnpm/crates/package-manager/src/install.rs[2604-2607]

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

## Issue description
`extend_skipped_with_dependency_closure` currently treats *all* skipped keys as “removal roots” (`skipped.contains(key)`), but then persists the resulting closure by inserting it into the `installability` subset. Because `.modules.yaml.skipped` only persists the `installability` subset, this can accidentally persist closure entries that were only skipped due to a transient reason (notably `optional_excluded` from `skip_runtimes`).

This is especially dangerous on the frozen-lockfile “no constraints” fast path where the code deliberately reuses the previous `.modules.yaml.skipped` seed verbatim (no recomputation), so any leaked closure entries can remain skipped across later installs.

## Issue Context
- `.modules.yaml.skipped` persists `skipped.iter_installability()` only.
- `install_frozen_lockfile` reuses `seed` verbatim when `needs_installability_check == false`.
- `skip_runtimes` uses `SkippedSnapshots::add_optional_excluded(...)` (transient by design) before the newly-added closure extension call.

## Fix Focus Areas
- pnpm/crates/package-manager/src/current_lockfile.rs[255-281]
- pnpm/crates/package-manager/src/install_frozen_lockfile.rs[822-841]
- pnpm/crates/package-manager/src/install_frozen_lockfile.rs[640-747]
- pnpm/crates/package-manager/src/install.rs[2561-2612]

## Proposed fix
1. Change `extend_skipped_with_dependency_closure` to compute the closure **only from the persisted installability roots**, not from the union:
  - Use `skipped.contains_installability(key)` (or iterate `iter_installability`) in the `should_skip` predicate.
  - Optionally, early-return if `skipped.iter_installability().next().is_none()` (instead of `skipped.is_empty()`) to avoid work when only transient skips exist.
2. Keep inserting closure keys into `installability` (that’s correct for installability-skipped optionals), but only for nodes that are unreachable *because of installability skips*.
3. Add a regression test around the frozen “constraint-free” path to prove transient skips don’t cause persisted closure:
  - Seed `.modules.yaml.skipped` with a closure derived from an `optional_excluded`-only skip,
  - run a constraint-free frozen install,
  - verify the packages aren’t skipped solely due to the prior transient exclusion.

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


3. Changesets omit pnpm bump ✗ Dismissed 📘 Rule violation § Compliance
Description
New changeset files declare only pacquet and omit a pnpm entry, which violates the requirement
to explicitly include pnpm with a valid bump type. This can cause the pnpm release/versioning
automation to miss the intended bump.
Code

.changeset/add-moves-dependency-between-groups.md[R1-3]

+---
+"pacquet": patch
+---
Evidence
PR Compliance ID 713436 requires changesets to include an explicit pnpm entry with a valid bump
type. The newly added changesets’ front-matter contains only "pacquet": patch and no pnpm entry.

Rule 713436: Explicitly declare pnpm package and correct bump type in changesets
.changeset/add-moves-dependency-between-groups.md[1-3]
.changeset/hoist-tolerates-skipped-optional-snapshots.md[1-3]
.changeset/reevaluate-skipped-optionals-on-arch-change.md[1-3]
.changeset/skipped-optional-dependency-closure.md[1-3]

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

## Issue description
New changeset files include only `"pacquet": patch` and omit the required `"pnpm": <patch|minor|major>` entry.

## Issue Context
Compliance requires every added/modified changeset to explicitly declare the `pnpm` package with a valid bump type.

## Fix Focus Areas
- .changeset/add-moves-dependency-between-groups.md[1-3]
- .changeset/hoist-tolerates-skipped-optional-snapshots.md[1-3]
- .changeset/reevaluate-skipped-optionals-on-arch-change.md[1-3]
- .changeset/skipped-optional-dependency-closure.md[1-3]

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



Remediation recommended

4. Extra reachability traversals 🐞 Bug ➹ Performance
Description
extend_skipped_with_dependency_closure adds two full collect_reachable walks (full vs pruned) on
installs with a non-empty skip set. Both install paths also later run additional collect_reachable
traversals via materialization_closure, so skipped installs now pay for multiple full
lockfile-graph walks on the hot path.
Code

pnpm/crates/package-manager/src/current_lockfile.rs[R272-275]

+    let full = collect_reachable(lockfile, workspace_root, importer_ids, included, |_| false);
+    let kept = collect_reachable(lockfile, workspace_root, importer_ids, included, |key| {
+        skipped.contains(key)
+    });
Evidence
The new helper performs two collect_reachable traversals, and materialization_closure already
performs two more traversals; the install paths now call the helper before later materialization,
making the traversals additive on skipped installs.

pnpm/crates/package-manager/src/current_lockfile.rs[45-65]
pnpm/crates/package-manager/src/current_lockfile.rs[255-281]
pnpm/crates/package-manager/src/install_frozen_lockfile.rs[822-841]
pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs[1862-1877]

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

## Issue description
When `skipped` is non-empty, `extend_skipped_with_dependency_closure` performs *two* whole-graph reachability traversals (`collect_reachable` with and without skipping), and later phases (e.g. `materialization_closure`) perform additional reachability traversals. On large lockfiles (thousands of snapshots), these extra O(V+E) passes can add measurable CPU and allocation overhead.

## Issue Context
- `extend_skipped_with_dependency_closure` does two traversals.
- `materialization_closure` does two traversals (reachable + metadata_reachable).
- The new closure-extension call is invoked in both frozen and fresh install paths before later consumers run.

## Fix Focus Areas
- pnpm/crates/package-manager/src/current_lockfile.rs[45-104]
- pnpm/crates/package-manager/src/current_lockfile.rs[255-281]
- pnpm/crates/package-manager/src/install_frozen_lockfile.rs[822-841]
- pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs[1862-1877]

## Suggested optimization direction
Choose one of:
1. **Single-pass closure derivation:** compute the pruned reachable set once (kept graph), then walk *only from skipped roots* through the snapshot graph to find candidate closure nodes, and insert those not in the kept set. This removes the need for the “full” traversal.
2. **Reuse materialization results:** if a reachability set is computed anyway for materialization, thread it into closure computation (or combine the steps) to avoid re-walking the graph.

Keep behavior identical; the goal is to reduce redundant traversals and allocations, especially in large workspaces.

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


Grey Divider

Qodo Logo

@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: 1

🧹 Nitpick comments (1)
pnpm/crates/real-hoist/src/lib.rs (1)

373-374: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low value

Avoid string allocations when sorting dependencies.

Sorting the merged dependencies by calling .to_string() on the alias allocates a new String for every entry just to compare them. PkgName already implements Ord, so the string allocation is unnecessary. Switching the underlying map from HashMap to std::collections::BTreeMap eliminates the need to collect into a Vec and sort entirely, while preserving the deterministic alias-sorted output.

  • pnpm/crates/real-hoist/src/lib.rs#L373-L374: Change the merged map (lines 362-363) to std::collections::BTreeMap and replace these collection/sorting lines by iterating directly over merged.
  • pnpm/crates/real-hoist/src/lib.rs#L491-L492: Change the merged map (line 483) to std::collections::BTreeMap and replace these collection/sorting lines by iterating directly over merged here as well.
🤖 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/real-hoist/src/lib.rs` around lines 373 - 374, Replace the merged
maps in pnpm/crates/real-hoist/src/lib.rs at lines 362-363 and 483 with
std::collections::BTreeMap, then update both output paths at lines 373-374 and
491-492 to iterate directly over merged instead of collecting and sorting by
alias.to_string(). Preserve the deterministic alias ordering while avoiding
per-entry string allocations.
🤖 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 `@pnpm/crates/real-hoist/src/lib.rs`:
- Around line 364-368: Update both dependency merge arrays in
pnpm/crates/real-hoist/src/lib.rs: at lines 364-368, move optional_dependencies
before dependencies and dev_dependencies; at lines 484-486, move
snapshot.optional_dependencies before the non-optional groups. Preserve the
existing merge logic so later non-optional entries overwrite optional flags with
false.

---

Nitpick comments:
In `@pnpm/crates/real-hoist/src/lib.rs`:
- Around line 373-374: Replace the merged maps in
pnpm/crates/real-hoist/src/lib.rs at lines 362-363 and 483 with
std::collections::BTreeMap, then update both output paths at lines 373-374 and
491-492 to iterate directly over merged instead of collecting and sorting by
alias.to_string(). Preserve the deterministic alias ordering while avoiding
per-entry string allocations.
🪄 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: 630ff107-36a5-43c1-9a39-17300cf32724

📥 Commits

Reviewing files that changed from the base of the PR and between 1166108 and 2e5e940.

📒 Files selected for processing (18)
  • .changeset/add-moves-dependency-between-groups.md
  • .changeset/hoist-tolerates-skipped-optional-snapshots.md
  • .changeset/reevaluate-skipped-optionals-on-arch-change.md
  • .changeset/skipped-optional-dependency-closure.md
  • pnpm/crates/cli/tests/_utils.rs
  • pnpm/crates/cli/tests/add.rs
  • pnpm/crates/cli/tests/hoist.rs
  • pnpm/crates/cli/tests/optional_dependencies.rs
  • pnpm/crates/package-manager/src/add.rs
  • pnpm/crates/package-manager/src/current_lockfile.rs
  • pnpm/crates/package-manager/src/install/tests.rs
  • pnpm/crates/package-manager/src/install_frozen_lockfile.rs
  • pnpm/crates/package-manager/src/install_with_fresh_lockfile.rs
  • pnpm/crates/package-manager/src/installability.rs
  • pnpm/crates/package-manager/src/installability/tests.rs
  • pnpm/crates/package-manifest/src/lib.rs
  • pnpm/crates/real-hoist/src/lib.rs
  • pnpm/plans/TEST_PORTING.md

Comment thread pnpm/crates/real-hoist/src/lib.rs Resolved
@qodo-code-review

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

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Reuse constant for group order

Extract the inline dependency group array into a shared constant.

pnpm/crates/package-manager/src/add.rs [586-594]

+// Use a shared ordering constant instead of an inline array
 let prev_specifier = manifest
-    .dependencies([
-        DependencyGroup::Optional,
-        DependencyGroup::Prod,
-        DependencyGroup::Dev,
-        DependencyGroup::Peer,
-    ])
+    .dependencies(DEPENDENCIES_OR_PEER_FIELDS)
     .find(|(name, _)| *name == package_name)
     .map(|(_, spec)| spec.to_string());
  • Apply / Chat
Suggestion importance[1-10]: 3

__

Why: Extracting the dependency group order into a named constant slightly improves code readability, although the current inline array is only used once and is already well-documented.

Low
  • Update

@github-actions

Copy link
Copy Markdown
Contributor

Integrated-Benchmark Report (Linux)

Commit: 2e5e940bb9c8

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

The tables below show mean ± σ; Bencher thresholds on the minimum latency, which is far less perturbed by shared-runner contention (noise only adds time).

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.494 ± 0.155 2.345 2.763 1.61 ± 0.17
pacquet@main 2.505 ± 0.171 2.337 2.779 1.61 ± 0.18
pnpr@HEAD 1.553 ± 0.138 1.355 1.738 1.00
pnpr@main 1.567 ± 0.170 1.339 1.795 1.01 ± 0.14
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.49439687586,
      "stddev": 0.15485795292170249,
      "median": 2.4650060509600005,
      "user": 1.476087,
      "system": 1.3148597,
      "min": 2.34541224546,
      "max": 2.76279965646,
      "times": [
        2.3460255184600003,
        2.57692356446,
        2.3518400384600002,
        2.51767274146,
        2.76279965646,
        2.6022316354600004,
        2.35196667546,
        2.67675732246,
        2.34541224546,
        2.4123393604600003
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.50544130836,
      "stddev": 0.17056236309921594,
      "median": 2.44453574846,
      "user": 1.5128137,
      "system": 1.2638897000000002,
      "min": 2.33669476146,
      "max": 2.77874474146,
      "times": [
        2.74052240946,
        2.40931905846,
        2.70898610746,
        2.4761718734600002,
        2.44469184646,
        2.44437965046,
        2.33669476146,
        2.37537643446,
        2.77874474146,
        2.33952620046
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.5527072510600004,
      "stddev": 0.1379841632212979,
      "median": 1.57157230946,
      "user": 1.0518921999999997,
      "system": 1.1208788,
      "min": 1.3554078714600002,
      "max": 1.7381902994600003,
      "times": [
        1.63661955746,
        1.73247164146,
        1.3554078714600002,
        1.47768312546,
        1.37545770946,
        1.7381902994600003,
        1.52817703846,
        1.4433604364600001,
        1.61496758046,
        1.6247372504600002
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.56721073686,
      "stddev": 0.16979274118043491,
      "median": 1.5748054019600002,
      "user": 1.0387667999999999,
      "system": 1.1587721000000002,
      "min": 1.33880756246,
      "max": 1.7951386614600002,
      "times": [
        1.6640938104600003,
        1.7951386614600002,
        1.7000023134600002,
        1.7178343874600002,
        1.7262790574600002,
        1.4508942254600001,
        1.42865678846,
        1.48551699346,
        1.36488356846,
        1.33880756246
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 253.3 ± 4.9 245.5 260.4 1.03 ± 0.03
pacquet@main 246.8 ± 6.9 233.6 256.4 1.00
pnpr@HEAD 272.6 ± 9.2 257.6 284.8 1.10 ± 0.05
pnpr@main 264.6 ± 7.3 254.4 278.3 1.07 ± 0.04
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.25331004312000005,
      "stddev": 0.004908240326868456,
      "median": 0.25306350452000004,
      "user": 0.20166028000000003,
      "system": 0.53913008,
      "min": 0.24550017352000003,
      "max": 0.26043186852,
      "times": [
        0.24550017352000003,
        0.25874697352000003,
        0.26043186852,
        0.25106866252000004,
        0.24833002852000002,
        0.25505834652000003,
        0.25719692152,
        0.25627399952,
        0.25027106452000003,
        0.25022239252
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.24675530122000003,
      "stddev": 0.006897031164269239,
      "median": 0.24777309702000003,
      "user": 0.19382768,
      "system": 0.50670228,
      "min": 0.23361823652000002,
      "max": 0.25643721452,
      "times": [
        0.24082041352000003,
        0.25533044552,
        0.24918973252,
        0.24682299752000003,
        0.24872319652000002,
        0.24367717852,
        0.25056548652000005,
        0.25643721452,
        0.23361823652000002,
        0.24236811052
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.27258543492,
      "stddev": 0.009196448070704036,
      "median": 0.27456247352,
      "user": 0.19513788,
      "system": 0.55624758,
      "min": 0.25757049352,
      "max": 0.28483811752000004,
      "times": [
        0.27501373552,
        0.27711291852000003,
        0.26560652752,
        0.26193418952,
        0.28097883952,
        0.27411121152,
        0.28202799952,
        0.26666031652,
        0.25757049352,
        0.28483811752000004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.26459130972,
      "stddev": 0.007315062992073662,
      "median": 0.26300469602000004,
      "user": 0.20615548,
      "system": 0.53548058,
      "min": 0.25441691152,
      "max": 0.27831713052,
      "times": [
        0.26281203952000004,
        0.26092849952,
        0.26802498952000003,
        0.27157945652000004,
        0.26319735252000004,
        0.25887648752000003,
        0.27831713052,
        0.25768114152000005,
        0.25441691152,
        0.27007908852
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 2.690 ± 0.020 2.652 2.711 1.81 ± 0.16
pacquet@main 2.689 ± 0.022 2.659 2.735 1.81 ± 0.16
pnpr@HEAD 1.483 ± 0.127 1.379 1.705 1.00
pnpr@main 1.605 ± 0.130 1.391 1.755 1.08 ± 0.13
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 2.69041893088,
      "stddev": 0.02015228789260131,
      "median": 2.69427676758,
      "user": 1.5955610000000002,
      "system": 1.26333882,
      "min": 2.6523897940800003,
      "max": 2.71092044808,
      "times": [
        2.69300684308,
        2.68464939508,
        2.68890602008,
        2.71023450008,
        2.70968484708,
        2.66052579708,
        2.71092044808,
        2.69832497208,
        2.6523897940800003,
        2.69554669208
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 2.6891518877799996,
      "stddev": 0.022248891961497798,
      "median": 2.68466063158,
      "user": 1.5992824999999997,
      "system": 1.23783882,
      "min": 2.65900123308,
      "max": 2.73508169408,
      "times": [
        2.69049121808,
        2.6788300450799998,
        2.67542711308,
        2.70236759508,
        2.73508169408,
        2.7010488610800003,
        2.67340241308,
        2.70485478908,
        2.65900123308,
        2.67101391608
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 1.48324289488,
      "stddev": 0.12725001965591878,
      "median": 1.4192111990799998,
      "user": 0.9775922999999999,
      "system": 1.12037832,
      "min": 1.37929272008,
      "max": 1.70459244708,
      "times": [
        1.5662311950799999,
        1.39436411808,
        1.70459244708,
        1.40028744508,
        1.43793557908,
        1.70061963508,
        1.40048681908,
        1.40019017208,
        1.44842881808,
        1.37929272008
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 1.6045252694800003,
      "stddev": 0.12958633834349176,
      "median": 1.6020718115800001,
      "user": 0.9797625999999999,
      "system": 1.09635112,
      "min": 1.39142212208,
      "max": 1.75509039708,
      "times": [
        1.6150253540800001,
        1.74247764608,
        1.73461779408,
        1.75509039708,
        1.39142212208,
        1.65273195808,
        1.58885691208,
        1.58015725208,
        1.58911826908,
        1.39575499008
      ]
    }
  ]
}

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

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 536.0 ± 12.3 516.4 557.2 1.87 ± 0.06
pacquet@main 536.4 ± 13.0 516.1 550.3 1.87 ± 0.06
pnpr@HEAD 294.4 ± 4.8 287.2 300.6 1.02 ± 0.03
pnpr@main 287.3 ± 6.3 280.0 300.5 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.5359876723799999,
      "stddev": 0.012254334193295725,
      "median": 0.53399089978,
      "user": 0.6556847800000001,
      "system": 0.6564261,
      "min": 0.51641331828,
      "max": 0.55721676028,
      "times": [
        0.53026080928,
        0.54537869428,
        0.54933934428,
        0.53658394528,
        0.53139785428,
        0.54013049728,
        0.55721676028,
        0.5277514652799999,
        0.52540403528,
        0.51641331828
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.53636765518,
      "stddev": 0.013048952584831746,
      "median": 0.54024735578,
      "user": 0.6713897799999999,
      "system": 0.6251854,
      "min": 0.51610290528,
      "max": 0.55033340228,
      "times": [
        0.51909037728,
        0.51610290528,
        0.54166345628,
        0.55033340228,
        0.53883125528,
        0.54773276628,
        0.53335735528,
        0.54800550928,
        0.52179438628,
        0.54676513828
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.2943963796800001,
      "stddev": 0.00478274343116407,
      "median": 0.29464662878000003,
      "user": 0.18910458,
      "system": 0.5172286,
      "min": 0.28715715128,
      "max": 0.30055878428000005,
      "times": [
        0.29739583228000005,
        0.29911756728000005,
        0.28715715128,
        0.29921278528000006,
        0.29075676228,
        0.29234670928000006,
        0.28913259128,
        0.29694654828000006,
        0.29133906528000003,
        0.30055878428000005
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.28730973748000005,
      "stddev": 0.006319174511210878,
      "median": 0.28685229278,
      "user": 0.16717948,
      "system": 0.5243922999999999,
      "min": 0.27995673628000006,
      "max": 0.30046681128,
      "times": [
        0.28296656028000006,
        0.28042028728,
        0.28277798528000003,
        0.29227835028000004,
        0.28576317228000003,
        0.27995673628000006,
        0.30046681128,
        0.29072462128000004,
        0.28794141328000006,
        0.28980143728
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 1.836 ± 0.010 1.823 1.859 6.45 ± 0.14
pacquet@main 1.828 ± 0.009 1.811 1.841 6.42 ± 0.14
pnpr@HEAD 0.293 ± 0.006 0.282 0.301 1.03 ± 0.03
pnpr@main 0.285 ± 0.006 0.273 0.291 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 1.8357112146600003,
      "stddev": 0.009616703981098833,
      "median": 1.83476924386,
      "user": 0.8745055,
      "system": 0.72970052,
      "min": 1.82311373036,
      "max": 1.85898637036,
      "times": [
        1.85898637036,
        1.82733607136,
        1.8391840053600002,
        1.83220782236,
        1.8315904433599999,
        1.83747451436,
        1.83768070136,
        1.82311373036,
        1.83718574336,
        1.83235274436
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 1.8276014540599999,
      "stddev": 0.00893627473134073,
      "median": 1.82854799836,
      "user": 0.8386682999999999,
      "system": 0.7321434200000001,
      "min": 1.81086822936,
      "max": 1.84061354036,
      "times": [
        1.83500508636,
        1.82980496936,
        1.84061354036,
        1.83616996436,
        1.82210446536,
        1.83207055436,
        1.82109683236,
        1.81086822936,
        1.82729102736,
        1.82098987136
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.29272731216,
      "stddev": 0.006286246898830491,
      "median": 0.29330356686000003,
      "user": 0.18100650000000001,
      "system": 0.53356702,
      "min": 0.28224150336,
      "max": 0.30105130436,
      "times": [
        0.29442012936,
        0.29714573836,
        0.28440350436,
        0.28224150336,
        0.29579102336,
        0.30105130436,
        0.28974736136,
        0.28992215036,
        0.29218700436,
        0.30036340236
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.28466508156000003,
      "stddev": 0.005925067140014827,
      "median": 0.28646278786,
      "user": 0.17392039999999998,
      "system": 0.50214542,
      "min": 0.27269453036,
      "max": 0.29107966436,
      "times": [
        0.28180739836,
        0.29107966436,
        0.27269453036,
        0.28735949736,
        0.28556607836,
        0.28824539036,
        0.28993821036,
        0.29007720036,
        0.28054861336,
        0.27933423236
      ]
    }
  ]
}

Scenario: Isolated linker: fresh resolve, hot cache, offline

Command Mean [ms] Min [ms] Max [ms] Relative
pacquet@HEAD 322.2 ± 7.5 311.2 331.7 3.76 ± 0.13
pacquet@main 326.8 ± 8.6 316.3 346.9 3.82 ± 0.14
pnpr@HEAD 85.7 ± 2.2 81.1 88.6 1.00 ± 0.04
pnpr@main 85.7 ± 2.3 81.0 89.0 1.00
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 0.32216742629999995,
      "stddev": 0.007451470724970854,
      "median": 0.3224188759,
      "user": 0.31760617999999996,
      "system": 0.05210687999999999,
      "min": 0.3111658949,
      "max": 0.33167039890000005,
      "times": [
        0.3258866959,
        0.31460914390000005,
        0.33167039890000005,
        0.3305448549,
        0.32853281590000005,
        0.3271298609,
        0.3187795559,
        0.3111658949,
        0.3189510559,
        0.3144039859
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 0.32677688200000005,
      "stddev": 0.008635843270643654,
      "median": 0.32418448590000004,
      "user": 0.31487208,
      "system": 0.05564097999999999,
      "min": 0.31632787990000005,
      "max": 0.3468590429,
      "times": [
        0.3468590429,
        0.32247513590000004,
        0.32539634190000005,
        0.31954986090000004,
        0.32253814290000005,
        0.32297262990000003,
        0.31632787990000005,
        0.32892111290000003,
        0.3294991179,
        0.3332295549
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 0.08567822893030305,
      "stddev": 0.002153818932385733,
      "median": 0.0863550219,
      "user": 0.018634610303030305,
      "system": 0.009594586666666668,
      "min": 0.0810957849,
      "max": 0.0886246159,
      "times": [
        0.0865097529,
        0.0876740899,
        0.0869231999,
        0.0863680859,
        0.0810957849,
        0.0843298489,
        0.0874330569,
        0.0868981519,
        0.0868584479,
        0.0880212519,
        0.0881079949,
        0.0873846759,
        0.0856400889,
        0.0825115239,
        0.0865983499,
        0.0854113499,
        0.0863550219,
        0.0875713169,
        0.0862864529,
        0.0886246159,
        0.0854190739,
        0.0862270819,
        0.0816108509,
        0.0829154219,
        0.0825073749,
        0.0873994139,
        0.0873309449,
        0.0862267019,
        0.0829756849,
        0.0873187719,
        0.0863544009,
        0.0821454459,
        0.0823473249
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 0.08565579690000001,
      "stddev": 0.002291605213145073,
      "median": 0.0864385149,
      "user": 0.020201517499999995,
      "system": 0.00826016875,
      "min": 0.0809839749,
      "max": 0.0889577909,
      "times": [
        0.0874101939,
        0.0863121229,
        0.0835003509,
        0.0872922429,
        0.0877991849,
        0.0866021669,
        0.0874234289,
        0.0873119599,
        0.0889577909,
        0.0857059429,
        0.0870776399,
        0.0832320469,
        0.0865649069,
        0.0823414039,
        0.0872046379,
        0.0868725949,
        0.0809839749,
        0.0853137759,
        0.0877061299,
        0.0857848009,
        0.0821988259,
        0.0815511599,
        0.0817333819,
        0.0848472099,
        0.0873030629,
        0.0884543059,
        0.0867181339,
        0.0857827979,
        0.0814778719,
        0.0860327869,
        0.0854301349,
        0.0880585319
      ]
    }
  ]
}

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

Command Mean [s] Min [s] Max [s] Relative
pacquet@HEAD 4.506 ± 0.172 4.397 4.855 1.28 ± 0.06
pacquet@main 4.476 ± 0.095 4.404 4.741 1.28 ± 0.05
pnpr@HEAD 3.509 ± 0.107 3.442 3.801 1.00
pnpr@main 3.548 ± 0.132 3.430 3.856 1.01 ± 0.05
BENCHMARK_REPORT.json
{
  "results": [
    {
      "command": "pacquet@HEAD",
      "mean": 4.50580828918,
      "stddev": 0.17150914892101643,
      "median": 4.42624406498,
      "user": 1.66392192,
      "system": 1.3760408400000002,
      "min": 4.39712295998,
      "max": 4.8548617489799994,
      "times": [
        4.39712295998,
        4.42328531798,
        4.41472477898,
        4.4130008709799995,
        4.43185491298,
        4.42920281198,
        4.47260027098,
        4.41977317098,
        4.8548617489799994,
        4.80165604798
      ]
    },
    {
      "command": "pacquet@main",
      "mean": 4.475607641080001,
      "stddev": 0.09500382434288997,
      "median": 4.45360434348,
      "user": 1.6801975199999997,
      "system": 1.3354908399999996,
      "min": 4.40357532898,
      "max": 4.74128751298,
      "times": [
        4.45350754198,
        4.40357532898,
        4.4660494569799996,
        4.454497078979999,
        4.74128751298,
        4.45370114498,
        4.43787965898,
        4.43618797198,
        4.44763102398,
        4.46175969098
      ]
    },
    {
      "command": "pnpr@HEAD",
      "mean": 3.50921812618,
      "stddev": 0.10713204428660811,
      "median": 3.47250751998,
      "user": 1.1771159199999999,
      "system": 1.2118324399999998,
      "min": 3.4424214459800004,
      "max": 3.8012894089800002,
      "times": [
        3.8012894089800002,
        3.4424214459800004,
        3.4568918649800002,
        3.46629501698,
        3.44867533298,
        3.47872002298,
        3.4520788069800004,
        3.49111815998,
        3.52019272698,
        3.5344984749800004
      ]
    },
    {
      "command": "pnpr@main",
      "mean": 3.54803266018,
      "stddev": 0.13205155477036565,
      "median": 3.5042186294800004,
      "user": 1.1743629199999999,
      "system": 1.23807964,
      "min": 3.43045159598,
      "max": 3.8562422019800002,
      "times": [
        3.47211089998,
        3.8562422019800002,
        3.4492265479800004,
        3.5363263589800003,
        3.5950906589800002,
        3.6346462819800003,
        3.60523409998,
        3.43562831898,
        3.43045159598,
        3.4653696369800002
      ]
    }
  ]
}

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/13141
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
2,652.39 ms
(-4.39%)Baseline: 2,774.16 ms
3,328.99 ms
(79.68%)
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
🚷 view threshold
1,823.11 ms
(-6.13%)Baseline: 1,942.13 ms
2,330.56 ms
(78.23%)
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
🚷 view threshold
516.41 ms
(-13.40%)Baseline: 596.29 ms
715.55 ms
(72.17%)
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
🚷 view threshold
311.17 ms
(-15.02%)Baseline: 366.18 ms
439.41 ms
(70.81%)
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
🚷 view threshold
2,345.41 ms
(-5.34%)Baseline: 2,477.77 ms
2,973.33 ms
(78.88%)
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
🚷 view threshold
4,397.12 ms
(-3.10%)Baseline: 4,537.74 ms
5,445.29 ms
(80.75%)
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
🚷 view threshold
245.50 ms
(-9.24%)Baseline: 270.50 ms
324.60 ms
(75.63%)
🐰 View full continuous benchmarking report in Bencher

@github-actions

Copy link
Copy Markdown
Contributor

🐰 Bencher Report

Branchpr/13141
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
1,379.29 ms
isolated-linker.fresh-install.cold-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
282.24 ms
isolated-linker.fresh-install.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
287.16 ms
isolated-linker.fresh-resolve.hot-cache.offline📈 view plot
⚠️ NO THRESHOLD
81.10 ms
isolated-linker.fresh-restore.cold-cache.cold-store📈 view plot
⚠️ NO THRESHOLD
1,355.41 ms
isolated-linker.fresh-restore.cold-cache.cold-store.cold-pnpr📈 view plot
⚠️ NO THRESHOLD
3,442.42 ms
isolated-linker.fresh-restore.hot-cache.hot-store📈 view plot
⚠️ NO THRESHOLD
257.57 ms
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter

codecov-commenter commented Jul 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.95833% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.84%. Comparing base (bff4ec1) to head (9f5107b).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
pnpm/crates/real-hoist/src/lib.rs 96.42% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13141      +/-   ##
==========================================
+ Coverage   85.64%   85.84%   +0.20%     
==========================================
  Files         505      505              
  Lines       83660    83943     +283     
==========================================
+ Hits        71653    72065     +412     
+ Misses      12007    11878     -129     

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

… breakage

Cargo's freshness check is mtime-based, so reverting a deliberately
broken implementation by moving a backup copy into place leaves the
broken artifact looking fresh, and later test runs fail in
impossible-looking ways. Prescribe git restore (or a follow-up touch)
in the test-the-tests workflow that plans/TEST_PORTING.md mandates,
and cross-reference it from the AGENTS.md Tests section.
Copilot AI review requested due to automatic review settings July 19, 2026 12:10

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

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Unsafe store/cache cleanup 🐞 Bug ☼ Reliability ⭐ New
Description
The same test unconditionally remove_dir_alls the mocked store/cache paths, but the test harness
only computes those paths and does not guarantee the directories exist; on runs where either
directory was never created, the test can fail with NotFound before executing the frozen install
assertion.
Code

pnpm/crates/cli/tests/optional_dependencies.rs[R574-575]

+    fs::remove_dir_all(&npmrc_info.store_dir).expect("clear the store");
+    fs::remove_dir_all(&npmrc_info.cache_dir).expect("clear the cache");
Evidence
The test assumes the directories exist and panics otherwise, while the mocked-registry setup only
defines the paths and does not create them, so existence is not a safe invariant for the test to
rely on.

pnpm/crates/cli/tests/optional_dependencies.rs[574-575]
pnpm/crates/testing-utils/src/bin.rs[57-60]

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

### Issue description
The test unconditionally calls `fs::remove_dir_all` on `store_dir` and `cache_dir`. If either directory does not exist (which is not guaranteed by the mocked-registry setup), the test can abort with `NotFound`.

### Issue Context
`CommandTempCwd::add_mocked_registry` sets `store_dir`/`cache_dir` paths but does not create those directories.

### Fix Focus Areas
- pnpm/crates/cli/tests/optional_dependencies.rs[574-575]
- pnpm/crates/testing-utils/src/bin.rs[57-60]

### Suggested fix
Replace the `expect(...)` removals with one of:
- `if path.exists() { fs::remove_dir_all(path)? }`
- or `match fs::remove_dir_all(path) { Ok(()) => (), Err(e) if e.kind()==NotFound => (), Err(e) => return Err(e.into()) }`
This preserves the intent (cold store/cache) without making the test depend on incidental directory creation.

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


2. pacquet_in() duplicated in tests 📘 Rule violation ⚙ Maintainability ⭐ New
Description
pnpm/crates/cli/tests/optional_dependencies.rs adds local helpers like
pacquet_in()/write_manifest() that duplicate existing test helpers, increasing drift risk when
CLI invocation or manifest-writing patterns change. This violates the repo guidance to reuse
existing utilities instead of copy-pasting similar logic.
Code

pnpm/crates/cli/tests/optional_dependencies.rs[R14-35]

+fn pacquet_in(workspace: &Path) -> Command {
+    Command::cargo_bin("pnpm").expect("find the pnpm binary").with_current_dir(workspace)
+}
+
+fn read_wanted_lockfile(workspace: &Path) -> Lockfile {
+    let text =
+        fs::read_to_string(workspace.join(Lockfile::FILE_NAME)).expect("read pnpm-lock.yaml");
+    serde_saphyr::from_str(&text).expect("parse pnpm-lock.yaml")
+}
+
+fn read_skipped(workspace: &Path) -> Vec<String> {
+    pacquet_modules_yaml::read_modules_layout::<pacquet_modules_yaml::Host>(
+        &workspace.join("node_modules"),
+    )
+    .expect("read .modules.yaml")
+    .expect(".modules.yaml exists")
+    .skipped
+}
+
+fn write_manifest(workspace: &Path, manifest: &serde_json::Value) {
+    fs::write(workspace.join("package.json"), manifest.to_string()).expect("write package.json");
+}
Evidence
PR Compliance ID 3 requires reusing existing utilities instead of introducing new duplicate
implementations. The PR adds a new pacquet_in() helper in optional_dependencies.rs while an
identical pacquet_in() already exists in verify_deps_before_run.rs, and it also adds another
per-file manifest writer while similar helpers exist elsewhere, indicating copy-pasted patterns
rather than shared utilities.

CLAUDE.md, AGENTS.md: Avoid Code Duplication by Reusing Existing Utilities and Extracting Shared Logic
pnpm/crates/cli/tests/optional_dependencies.rs[14-16]
pnpm/crates/cli/tests/verify_deps_before_run.rs[12-14]
pnpm/crates/cli/tests/optional_dependencies.rs[33-35]
pnpm/crates/cli/tests/hoist.rs[63-66]

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

## Issue description
`optional_dependencies.rs` defines local helpers (notably `pacquet_in()` and `write_manifest()`) that duplicate helpers already present in other CLI integration tests. This increases maintenance cost and makes future changes to command construction/manifest setup easy to miss.

## Issue Context
There is already an identical `pacquet_in()` helper in `verify_deps_before_run.rs`, and similar manifest-writing helpers exist in other test files. The new suite already imports `tests/_utils.rs`, so it’s a natural home for shared test helpers.

## Fix Focus Areas
- pnpm/crates/cli/tests/optional_dependencies.rs[14-35]
- pnpm/crates/cli/tests/verify_deps_before_run.rs[12-26]
- pnpm/crates/cli/tests/_utils.rs[1-101]

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


3. Brittle lockfile corruption 🐞 Bug ☼ Reliability ⭐ New
Description
headless_install_skips_unfetchable_optional_dependency corrupts pnpm-lock.yaml using substring
searches that assume a specific YAML quoting/layout (single-quoted key and a } delimiter), so
innocuous lockfile formatting changes can make the test fail before it exercises the intended
integrity-verification path.
Code

pnpm/crates/cli/tests/optional_dependencies.rs[R562-573]

+    let lockfile_path = workspace.join(Lockfile::FILE_NAME);
+    let lockfile_text = fs::read_to_string(&lockfile_path).expect("read pnpm-lock.yaml");
+    let foo_header = "'@pnpm.e2e/[email protected]':";
+    let foo_at = lockfile_text.find(foo_header).expect("lockfile records the optional");
+    let integrity_at =
+        foo_at + lockfile_text[foo_at..].find("sha512-").expect("optional has an integrity");
+    let integrity_end =
+        integrity_at + lockfile_text[integrity_at..].find('}').expect("integrity value ends");
+    let mut corrupted = lockfile_text.clone();
+    corrupted.replace_range(integrity_at..integrity_end, &format!("sha512-{}==", "A".repeat(86)));
+    assert_ne!(corrupted, lockfile_text);
+    fs::write(&lockfile_path, corrupted).expect("write the corrupted lockfile");
Evidence
The test currently relies on hard-coded YAML substrings/structure to find and replace the integrity,
even though the codebase already has a structured lockfile model with an integrity field that can be
mutated directly.

pnpm/crates/cli/tests/optional_dependencies.rs[559-575]
pnpm/crates/lockfile/src/package_metadata.rs[9-15]
pnpm/crates/lockfile/src/resolution.rs[292-311]

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

### Issue description
The test edits `pnpm-lock.yaml` via raw string offsets, which is fragile against changes in YAML quoting/formatting (and can fail before reaching the fetch/integrity verification behavior).

### Issue Context
The repository already parses lockfiles into structured types (`pacquet_lockfile::Lockfile`) and the lockfile model exposes integrity via `PackageMetadata.resolution`.

### Fix Focus Areas
- pnpm/crates/cli/tests/optional_dependencies.rs[562-573]
- pnpm/crates/lockfile/src/package_metadata.rs[9-15]
- pnpm/crates/lockfile/src/resolution.rs[292-311]

### Suggested fix
1. Parse `pnpm-lock.yaml` into `pacquet_lockfile::Lockfile` (or a serde value).
2. Locate the `packages` entry for `@pnpm.e2e/[email protected]` and replace its `resolution.integrity` with a clearly invalid value.
3. Serialize the lockfile back to YAML and write it to disk.
This keeps the test resilient to lockfile formatting changes while still reliably forcing an integrity verification failure.

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


View more (2)
4. Optional merge overrides required 📘 Rule violation ≡ Correctness
Description
In real-hoist, dependencies are merged by alias with a last-write-wins optional flag, so if the
same alias appears in both required maps and optionalDependencies, the optional entry can
overwrite the required one and make the dependency incorrectly treated as optional. This can cause
pacquet to silently ignore missing required snapshots during hoist (instead of raising
HoistError::LockfileMissingDependency), masking lockfile corruption/inconsistency and risking
pnpm/pacquet parity.
Code

pnpm/crates/real-hoist/src/lib.rs[R362-371]

+    let mut merged: HashMap<&PkgName, (&pacquet_lockfile::ResolvedDependencySpec, bool)> =
+        HashMap::new();
+    for (deps, optional) in [
+        (&importer.dependencies, false),
+        (&importer.dev_dependencies, false),
+        (&importer.optional_dependencies, true),
+    ] {
+        for (alias, spec) in deps.iter().flatten() {
+            merged.insert(alias, (spec, optional));
        }
Evidence
The compliance requirement calls for user-visible behavior parity between pnpm and pacquet, but the
current implementation determines an edge’s optional status via merge order:
collect_importer_deps and collect_snapshot_deps insert optional dependencies after required ones
into a HashMap keyed only by alias, so any alias collision can replace a required edge with an
optional one. That propagated optional boolean is then used by build_dep_node, which explicitly
suppresses HoistError::LockfileMissingDependency for optional edges by returning Ok(None) when a
snapshot is missing; therefore, if an alias exists in both required and optional groups, the code
can incorrectly treat a required dependency as optional and silently skip what should be a
user-visible lockfile integrity error.

AGENTS.md: User-visible CLI changes must be kept in sync between TypeScript pnpm and Rust pacquet
pnpm/crates/real-hoist/src/lib.rs[362-372]
pnpm/crates/real-hoist/src/lib.rs[398-427]
pnpm/crates/real-hoist/src/lib.rs[483-509]
pnpm/crates/real-hoist/src/lib.rs[349-395]
pnpm/crates/real-hoist/src/lib.rs[476-513]

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

## Issue description
`collect_importer_deps()` / `collect_snapshot_deps()` collapse multiple dependency sources into a single alias-keyed entry while recording a single `optional` boolean using last-write-wins merge behavior. Because `optionalDependencies` are inserted/merged last, an alias that appears in both required maps and optional maps can incorrectly become `optional=true`, which then causes `build_dep_node()` to treat a missing snapshot as ignorable (`Ok(None)`) instead of raising `HoistError::LockfileMissingDependency`.

## Issue Context
This PR intentionally tolerates missing snapshots only for *truly optional* edges (e.g., optionals filtered from the current lockfile). The optionality signal must be conservative to preserve pnpm/pacquet parity and avoid masking lockfile corruption/inconsistency (legacy lockfiles, hand-edited lockfiles, or other inconsistent states): if an alias is present in any non-optional dependency map, it must not be treated as optional for missing-snapshot handling.

## Fix Focus Areas
- pnpm/crates/real-hoist/src/lib.rs[349-396]
- pnpm/crates/real-hoist/src/lib.rs[398-474]
- pnpm/crates/real-hoist/src/lib.rs[476-513]
- pnpm/crates/real-hoist/src/lib.rs[362-372]
- pnpm/crates/real-hoist/src/lib.rs[421-427]
- pnpm/crates/real-hoist/src/lib.rs[483-490]

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


5. Duplicate mtime restore guidance 📘 Rule violation ⚙ Maintainability
Description
The same long guidance about avoiding mtime-preserving restores is duplicated in both
pnpm/AGENTS.md and pnpm/plans/TEST_PORTING.md. This increases maintenance burden and creates
drift risk if the guidance needs updates later.
Code

pnpm/AGENTS.md[R211-220]

+- When temporarily breaking an implementation (to prove a test catches the
+  regression, or for any other experiment), revert with `git restore <file>`,
+  never by moving a saved backup copy into place. Cargo's freshness check is
+  mtime-based, and an mtime-preserving restore leaves the binary compiled
+  from the broken source looking fresh — later test runs then fail in
+  impossible-looking, "flaky" ways with nothing pointing at the stale
+  artifact. Details in the "Test the tests" section of
+  [`plans/TEST_PORTING.md`](./plans/TEST_PORTING.md). If test outcomes ever
+  flip with no code change, `touch` the implementation file and rerun before
+  debugging anything else.
Evidence
PR Compliance ID 4 requires comments/docs to capture non-obvious rationale without duplicating the
same rationale across peers; the added text repeats essentially the same guidance in two separate
documents rather than centralizing it once and linking.

AGENTS.md: Comments must not restate code and must document contracts or non-obvious rationale only
pnpm/AGENTS.md[211-220]
pnpm/plans/TEST_PORTING.md[16-19]

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

## Issue description
The repo now contains duplicated, detailed guidance on reverting experimental breakages with `git restore` to avoid Cargo mtime freshness issues.

## Issue Context
Compliance guidance discourages duplicating rationale across multiple locations; it should live in a single canonical place and other docs should link to it.

## Fix Focus Areas
- pnpm/AGENTS.md[211-220]
- pnpm/plans/TEST_PORTING.md[16-19]

ⓘ 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 9f5107b

Results up to commit c1f2906


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


Remediation recommended
1. Duplicate mtime restore guidance 📘 Rule violation ⚙ Maintainability
Description
The same long guidance about avoiding mtime-preserving restores is duplicated in both
pnpm/AGENTS.md and pnpm/plans/TEST_PORTING.md. This increases maintenance burden and creates
drift risk if the guidance needs updates later.
Code

pnpm/AGENTS.md[R211-220]

+- When temporarily breaking an implementation (to prove a test catches the
+  regression, or for any other experiment), revert with `git restore <file>`,
+  never by moving a saved backup copy into place. Cargo's freshness check is
+  mtime-based, and an mtime-preserving restore leaves the binary compiled
+  from the broken source looking fresh — later test runs then fail in
+  impossible-looking, "flaky" ways with nothing pointing at the stale
+  artifact. Details in the "Test the tests" section of
+  [`plans/TEST_PORTING.md`](./plans/TEST_PORTING.md). If test outcomes ever
+  flip with no code change, `touch` the implementation file and rerun before
+  debugging anything else.
Evidence
PR Compliance ID 4 requires comments/docs to capture non-obvious rationale without duplicating the
same rationale across peers; the added text repeats essentially the same guidance in two separate
documents rather than centralizing it once and linking.

AGENTS.md: Comments must not restate code and must document contracts or non-obvious rationale only
pnpm/AGENTS.md[211-220]
pnpm/plans/TEST_PORTING.md[16-19]

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

## Issue description
The repo now contains duplicated, detailed guidance on reverting experimental breakages with `git restore` to avoid Cargo mtime freshness issues.

## Issue Context
Compliance guidance discourages duplicating rationale across multiple locations; it should live in a single canonical place and other docs should link to it.

## Fix Focus Areas
- pnpm/AGENTS.md[211-220]
- pnpm/plans/TEST_PORTING.md[16-19]

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


2. Optional merge overrides required 📘 Rule violation ≡ Correctness
Description
In real-hoist, dependencies are merged by alias with a last-write-wins optional flag, so if the
same alias appears in both required maps and optionalDependencies, the optional entry can
overwrite the required one and make the dependency incorrectly treated as optional. This can cause
pacquet to silently ignore missing required snapshots during hoist (instead of raising
HoistError::LockfileMissingDependency), masking lockfile corruption/inconsistency and risking
pnpm/pacquet parity.
Code

pnpm/crates/real-hoist/src/lib.rs[R362-371]

+    let mut merged: HashMap<&PkgName, (&pacquet_lockfile::ResolvedDependencySpec, bool)> =
+        HashMap::new();
+    for (deps, optional) in [
+        (&importer.dependencies, false),
+        (&importer.dev_dependencies, false),
+        (&importer.optional_dependencies, true),
+    ] {
+        for (alias, spec) in deps.iter().flatten() {
+            merged.insert(alias, (spec, optional));
        }
Evidence
The compliance requirement calls for user-visible behavior parity between pnpm and pacquet, but the
current implementation determines an edge’s optional status via merge order:
collect_importer_deps and collect_snapshot_deps insert optional dependencies after required ones
into a HashMap keyed only by alias, so any alias collision can replace a required edge with an
optional one. That propagated optional boolean is then used by build_dep_node, which explicitly
suppresses HoistError::LockfileMissingDependency for optional edges by returning Ok(None) when a
snapshot is missing; therefore, if an alias exists in both required and optional groups, the code
can incorrectly treat a required dependency as optional and silently skip what should be a
user-visible lockfile integrity error.

AGENTS.md: User-visible CLI changes must be kept in sync between TypeScript pnpm and Rust pacquet
pnpm/crates/real-hoist/src/lib.rs[362-372]
pnpm/crates/real-hoist/src/lib.rs[398-427]
pnpm/crates/real-hoist/src/lib.rs[483-509]
pnpm/crates/real-hoist/src/lib.rs[349-395]
pnpm/crates/real-hoist/src/lib.rs[476-513]

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

## Issue description
`collect_importer_deps()` / `collect_snapshot_deps()` collapse multiple dependency sources into a single alias-keyed entry while recording a single `optional` boolean using last-write-wins merge behavior. Because `optionalDependencies` are inserted/merged last, an alias that appears in both required maps and optional maps can incorrectly become `optional=true`, which then causes `build_dep_node()` to treat a missing snapshot as ignorable (`Ok(None)`) instead of raising `HoistError::LockfileMissingDependency`.

## Issue Context
This PR intentionally tolerates missing snapshots only for *truly optional* edges (e.g., optionals filtered from the current lockfile). The optionality signal must be conservative to preserve pnpm/pacquet parity and avoid masking lockfile corruption/inconsistency (legacy lockfiles, hand-edited lockfiles, or other inconsistent states): if an alias is present in any non-optional dependency map, it must not be treated as optional for missing-snapshot handling.

## Fix Focus Areas
- pnpm/crates/real-hoist/src/lib.rs[349-396]
- pnpm/crates/real-hoist/src/lib.rs[398-474]
- pnpm/crates/real-hoist/src/lib.rs[476-513]
- pnpm/crates/real-hoist/src/lib.rs[362-372]
- pnpm/crates/real-hoist/src/lib.rs[421-427]
- pnpm/crates/real-hoist/src/lib.rs[483-490]

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

The closure extension computed its roots from the whole skip-set union
but persisted its additions into the installability subset, so a
transient exclusion (`--no-optional`, `--no-runtime`, a failed optional
fetch) could leak its dependency subtree into `.modules.yaml`'s
`skipped` — and the frozen path's constraint-free fast path reuses that
seed verbatim, keeping the subtree skipped after the transient
condition is gone. Seed and extend the closure from the persisted
installability subset only; transient subtrees are already cut from
materialization by the reachability walks that consume the full union.

Also narrow `extend_skipped_with_dependency_closure` to `pub(crate)`
(it has no callers outside the crate, matching its peers), and
reference the new tracking issue #13142 from the
`install --force` known-failure stubs and the porting plan.
Copilot AI review requested due to automatic review settings July 19, 2026 12:20

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 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/package-manager/src/current_lockfile/tests.rs (1)

1268-1271: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Prefer contains_installability over stringifying the iterator.

You can avoid string allocations and simplify this assertion by using the available contains_installability method, making it consistent with how contains is used in the second test.

♻️ Proposed fix
-    assert!(
-        skipped.iter_installability().any(|key| key.to_string() == "[email protected]"),
-        "a snapshot only reachable through an installability skip joins the persisted set",
-    );
+    assert!(
+        skipped.contains_installability(&key("child", "1.0.0")),
+        "a snapshot only reachable through an installability skip joins the persisted set",
+    );
🤖 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/package-manager/src/current_lockfile/tests.rs` around lines 1268
- 1271, Update the assertion for skipped installability snapshots to use the
available contains_installability method with the [email protected] key instead of
iterating, converting keys to strings, and comparing them. Keep the existing
assertion message and expected membership unchanged.
🤖 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/package-manager/src/current_lockfile/tests.rs`:
- Around line 1268-1271: Update the assertion for skipped installability
snapshots to use the available contains_installability method with the
[email protected] key instead of iterating, converting keys to strings, and comparing
them. Keep the existing assertion message and expected membership unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2a77b16b-0c3b-475a-92c3-0fcca6957827

📥 Commits

Reviewing files that changed from the base of the PR and between c1f2906 and 9f5107b.

📒 Files selected for processing (4)
  • pnpm/crates/cli/tests/optional_dependencies.rs
  • pnpm/crates/package-manager/src/current_lockfile.rs
  • pnpm/crates/package-manager/src/current_lockfile/tests.rs
  • pnpm/plans/TEST_PORTING.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • pnpm/crates/package-manager/src/current_lockfile.rs
  • pnpm/plans/TEST_PORTING.md
  • pnpm/crates/cli/tests/optional_dependencies.rs

@github-actions github-actions Bot added the reviewed: coderabbit CodeRabbit submitted an approving review label Jul 19, 2026
@zkochan
zkochan merged commit e8dd37a into main Jul 19, 2026
39 checks passed
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.

3 participants