Skip to content

fix(package-manager): don't write the PnP loader for a virtual-store-only install - #13636

Merged
zkochan merged 4 commits into
mainfrom
fix-pnp-virtual-store-only
Aug 4, 2026
Merged

zkochan merged 4 commits into
mainfrom
fix-pnp-virtual-store-only

Conversation

@zkochan

@zkochan zkochan commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Summary

virtualStoreOnly populates the virtual store and creates no importer links — it is how pnpm fetch warms a store in a Docker layer without touching the project. The importer symlinks and node_modules/.package-map.json were already skipped on that path, but .pnp.cjs was not.

.pnp.cjs is how a PnP project resolves, which makes it a project-level artifact of exactly the same kind. Writing it leaves the project claiming to resolve out of a store it was never linked into. This gates it on virtualStoreOnly like the other two.

All four implementations carried the gap, so all four are fixed:

Stack Path Site
TypeScript fresh deps-installer/src/install/index.ts
TypeScript headless deps-restorer/src/index.ts (reuses the skipPostImportLinking flag it already derives)
Rust fresh install_with_fresh_lockfile/linking.rs
Rust frozen install_frozen_lockfile.rs

Why fix rather than forbid

Rejecting virtualStoreOnly + nodeLinker: pnp as a config conflict was considered — there is precedent next door (CONFIG_CONFLICT_VIRTUAL_STORE_ONLY_WITH_NO_MODULES_DIR). It was rejected because pnpm fetch sets virtualStoreOnly itself, so erroring would stop PnP users warming a store at all, which is a legitimate thing to want.

Tests

Two regression tests, each verified to fail when its own guard is removed:

  • fetch_under_pnp_does_not_write_the_loader — the frozen path. fetch pins frozenLockfile, so it always goes headless.
  • virtual_store_only_install_under_pnp_does_not_write_the_loader — the fresh path, reachable because virtualStoreOnly is a pnpm-workspace.yaml setting a plain install can carry.

The second exists because the first does not exercise the fresh path at all; without it that guard would ship unexercised.

Both tests set the linker by appending to the harness's pnpm-workspace.yaml. Overwriting it drops the storeDir / cacheDir / registry the harness put there, and node-linker in .npmrc does not enable PnP at all (pnpm 11 reads it from the workspace manifest) — either mistake yields a test that passes whatever the code does.

Verification

  • cargo nextest run -p pacquet-package-manager — 857 passed.
  • cargo nextest run -p pacquet-cli --test fetch --test install — 57 passed.
  • clippy -D warnings, and cargo doc with RUSTDOCFLAGS=-D warnings --document-private-items.

The TypeScript half is not verified locally — the worktree has no node_modules, so deps-installer / deps-restorer were neither typechecked nor tested. The edits are one-line conditionals, but CI is their first check. Flagging it rather than implying otherwise. The same missing bootstrap means the pre-push hook was inactive, so nothing was gated on push either.

Squash Commit Body

`virtualStoreOnly` populates the virtual store and creates no importer
links — it is how `pnpm fetch` warms a store in a Docker layer without
touching the project. The importer symlinks and
`node_modules/.package-map.json` were already skipped on that path, but
`.pnp.cjs` was not.

`.pnp.cjs` is how a PnP project resolves, which makes it a project-level
artifact of exactly the same kind: writing it leaves the project
claiming to resolve out of a store it was never linked into. Gate it on
`virtualStoreOnly` like the other two.

Fixed in all four implementations, since every one carried the gap:
`deps-installer` and `deps-restorer` on the TypeScript side, and the
fresh and frozen paths in pacquet. The headless path reuses the
`skipPostImportLinking` flag it already derives.

Forbidding the combination instead was considered and rejected: `pnpm
fetch` sets `virtualStoreOnly`, so erroring would stop PnP users warming
a store at all, which is a legitimate thing to want.

Two regression tests, each verified to fail when its own guard is
removed:

- `fetch_under_pnp_does_not_write_the_loader` covers the frozen path
  (`fetch` pins `frozenLockfile`, so it always goes headless).
- `virtual_store_only_install_under_pnp_does_not_write_the_loader`
  covers the fresh path, reachable because `virtualStoreOnly` is a
  `pnpm-workspace.yaml` setting a plain install can carry.

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • The change is implemented in both the TypeScript CLI and the Rust
    pnpm/ 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.

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


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

Summary by CodeRabbit

  • Bug Fixes

    • pnpm fetch and virtual store-only installations with PnP enabled no longer generate .pnp.cjs loader files.
    • Lifecycle scripts in virtual store-only PnP installations no longer receive unnecessary PnP loader settings.
    • Standard PnP installations continue to generate and use the loader as expected.
  • Tests

    • Added coverage confirming successful installation, virtual store population, and absence of project-level PnP loaders in affected scenarios.

…only install

`virtualStoreOnly` populates the virtual store and creates no importer
links — it is how `pnpm fetch` warms a store in a Docker layer without
touching the project. The importer symlinks and
`node_modules/.package-map.json` were already skipped on that path, but
`.pnp.cjs` was not.

`.pnp.cjs` is how a PnP project resolves, which makes it a project-level
artifact of exactly the same kind: writing it leaves the project
claiming to resolve out of a store it was never linked into. Gate it on
`virtualStoreOnly` like the other two.

Fixed in all four implementations, since every one carried the gap:
`deps-installer` and `deps-restorer` on the TypeScript side, and the
fresh and frozen paths in pacquet. The headless path reuses the
`skipPostImportLinking` flag it already derives.

Forbidding the combination instead was considered and rejected: `pnpm
fetch` sets `virtualStoreOnly`, so erroring would stop PnP users warming
a store at all, which is a legitimate thing to want.

Two regression tests, each verified to fail when its own guard is
removed:

- `fetch_under_pnp_does_not_write_the_loader` covers the frozen path
  (`fetch` pins `frozenLockfile`, so it always goes headless).
- `virtual_store_only_install_under_pnp_does_not_write_the_loader`
  covers the fresh path, reachable because `virtualStoreOnly` is a
  `pnpm-workspace.yaml` setting a plain install can carry.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings August 4, 2026 10:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Skip writing .pnp.cjs when virtualStoreOnly warms the store

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 40+ Minutes

Grey Divider

AI Description

• Prevent writing .pnp.cjs during virtualStoreOnly installs under nodeLinker: pnp.
• Apply the same guard across TypeScript (fresh/headless) and Rust (fresh/frozen) paths.
• Add regression tests for fetch (frozen/headless) and plain install (fresh) behavior.
Diagram

graph TD
  A["CLI: fetch/install"] --> B["Workspace config"] --> C["TS deps-installer"] -->|"enablePnp && !virtualStoreOnly"| F[".pnp.cjs file"]
  A["CLI: fetch/install"] --> B["Workspace config"] --> D["TS deps-restorer"] -->|"enablePnp && !skipPostImportLinking"| F[".pnp.cjs file"]
  A["CLI: fetch/install"] --> B["Workspace config"] --> E["Rust package-manager"] -->|"pnp && !virtualStoreOnly"| F[".pnp.cjs file"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Treat `virtualStoreOnly` + `nodeLinker: pnp` as a config conflict
  • ➕ Makes the behavior explicit and prevents ambiguous partial-project artifacts by construction
  • ➕ Avoids having to maintain guards in multiple code paths/implementations
  • ➖ Breaks pnpm fetch for PnP users because fetch sets virtualStoreOnly internally
  • ➖ Prevents legitimate “warm the store in Docker without touching the project” workflows
2. Always write `.pnp.cjs`, but make it inert or self-detect missing importer links
  • ➕ Keeps file presence stable for tooling that expects it in PnP projects
  • ➖ Adds complexity to the PnP loader contract and increases risk of subtle resolution issues
  • ➖ Still creates a project-level artifact in a mode explicitly intended to avoid touching the project

Recommendation: Current approach is best: align .pnp.cjs with the existing virtualStoreOnly contract (no project linking, no project-level sidecars). Keeping pnpm fetch usable for PnP users outweighs the simplicity of forbidding the configuration combination.

Files changed (7) +95 / -4

Bug fix (4) +17 / -4
install_frozen_lockfile.rsGate '.pnp.cjs' generation in frozen installs on '!virtual_store_only' +3/-1

Gate '.pnp.cjs' generation in frozen installs on '!virtual_store_only'

• Updates the frozen-lockfile (headless) path to avoid writing '.pnp.cjs' when 'virtual_store_only' is enabled. Adds a comment pointing to the fresh-lockfile rationale.

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

linking.rsGate '.pnp.cjs' generation in fresh installs on '!virtual_store_only' +6/-1

Gate '.pnp.cjs' generation in fresh installs on '!virtual_store_only'

• Changes the fresh-lockfile sidecar writing logic so '.pnp.cjs' is only written for PnP when not in 'virtual_store_only' mode. Keeps existing package-map behavior consistent with the same mode.

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

index.tsSkip writing '.pnp.cjs' when 'virtualStoreOnly' is enabled (TS fresh path) +5/-1

Skip writing '.pnp.cjs' when 'virtualStoreOnly' is enabled (TS fresh path)

• Updates the TypeScript installer to only run PnP loader generation when PnP is enabled and the install is not 'virtualStoreOnly'. Adds inline rationale matching other skipped project-linking artifacts.

pnpm11/installing/deps-installer/src/install/index.ts

index.tsSkip writing '.pnp.cjs' when post-import linking is skipped (TS headless path) +3/-1

Skip writing '.pnp.cjs' when post-import linking is skipped (TS headless path)

• Updates headlessInstall to gate PnP loader generation on '!skipPostImportLinking', which already represents the ‘do not touch project links’ path. Aligns loader behavior with importer link/package-map suppression.

pnpm11/installing/deps-restorer/src/index.ts

Tests (2) +70 / -0
fetch.rsAdd regression test: 'fetch' under PnP must not create '.pnp.cjs' +33/-0

Add regression test: 'fetch' under PnP must not create '.pnp.cjs'

• Introduces 'fetch_under_pnp_does_not_write_the_loader' to ensure 'fetch' still populates the store while not emitting '.pnp.cjs'. The test sets 'nodeLinker: pnp' by appending to 'pnpm-workspace.yaml' to preserve harness configuration.

pnpm/crates/cli/tests/fetch.rs

install.rsAdd regression test: virtualStoreOnly install under PnP must not create '.pnp.cjs' +37/-0

Add regression test: virtualStoreOnly install under PnP must not create '.pnp.cjs'

• Adds 'virtual_store_only_install_under_pnp_does_not_write_the_loader' to cover the fresh install path (not exercised by 'fetch'). Verifies '.pnp.cjs' is absent when 'virtualStoreOnly: true' and 'nodeLinker: pnp' are set in the workspace manifest.

pnpm/crates/cli/tests/install.rs

Documentation (1) +8 / -0
pnp-loader-virtual-store-only.mdAdd changeset documenting '.pnp.cjs' suppression under virtualStoreOnly +8/-0

Add changeset documenting '.pnp.cjs' suppression under virtualStoreOnly

• Adds a patch changeset for pnpm/pacquet and the TS installer/restorer packages. Documents that 'pnpm fetch' and other 'virtualStoreOnly' installs no longer write '.pnp.cjs' under PnP.

.changeset/pnp-loader-virtual-store-only.md

@coderabbitai

coderabbitai Bot commented Aug 4, 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: e72514aa-2719-4652-b8b4-4af64432176e

📥 Commits

Reviewing files that changed from the base of the PR and between 8125a01 and 8368c4f.

📒 Files selected for processing (2)
  • pnpm/crates/cli/tests/fetch.rs
  • pnpm11/installing/deps-installer/test/install/misc.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • pnpm/crates/cli/tests/fetch.rs
  • pnpm11/installing/deps-installer/test/install/misc.ts

📝 Walkthrough

Walkthrough

PnP loader generation now skips .pnp.cjs during pnpm fetch and virtualStoreOnly installs. Normal PnP installs still generate the loader. Lifecycle scripts receive loader options only when the loader exists. Rust and TypeScript tests cover these paths.

Changes

PnP loader suppression

Layer / File(s) Summary
Loader generation gating
pnpm/crates/package-manager/src/install_frozen_lockfile.rs, pnpm/crates/package-manager/src/install_with_fresh_lockfile/linking.rs, pnpm11/installing/deps-installer/src/install/index.ts, pnpm11/installing/deps-restorer/src/index.ts
Installation paths skip .pnp.cjs generation when virtual_store_only is enabled or post-import linking is suppressed. Normal PnP installs retain loader generation.
Loader injection in lifecycle scripts
pnpm11/installing/deps-installer/src/install/index.ts, pnpm11/installing/deps-restorer/src/index.ts
Lifecycle scripts receive --require .pnp.cjs only when the loader was generated.
Loader suppression validation
pnpm/crates/cli/tests/fetch.rs, pnpm/crates/cli/tests/install.rs, pnpm11/installing/deps-installer/test/install/misc.ts, pnpm11/installing/deps-restorer/test/index.ts, .changeset/pnp-loader-virtual-store-only.md
Tests verify store population, skipped linking, absent .pnp.cjs, and absent PnP NODE_OPTIONS. The changeset records patch releases.

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

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant PackageManager
  participant LifecycleScripts
  CLI->>PackageManager: Run fetch or virtualStoreOnly install
  PackageManager->>PackageManager: Check virtual_store_only and linking state
  alt Loader generation enabled
    PackageManager->>PackageManager: Generate .pnp.cjs
    PackageManager->>LifecycleScripts: Inject --require .pnp.cjs
  else Loader generation skipped
    PackageManager->>LifecycleScripts: Omit PnP loader options
  end
  LifecycleScripts-->>CLI: Complete operation
Loading

Possibly related PRs

Suggested labels: product: pacquet, product: pnpm@11

Suggested reviewers: copilot

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@greptile-apps

greptile-apps Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously requested TypeScript coverage now exercises both fresh and headless virtual-store-only PnP paths.

Reviews (4): Last reviewed commit: "test(package-manager): use STORE_VERSION..." | Re-trigger Greptile

@qodo-code-review

qodo-code-review Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

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

Context used
✅ Compliance rules (platform): 24 rules

Grey Divider


Remediation recommended

1. Duplicate NODE_OPTIONS assertion helper ✓ Resolved 📘 Rule violation ⚙ Maintainability ⭐ New
Description
makeAssertNoPnpNodeOptionsScript duplicates the existing makeAssertNoPackageMapNodeOptionsScript
pattern, differing only by the checked NODE_OPTIONS substring and error text. This increases
maintenance cost and risks future divergence between near-identical helpers.
Code

pnpm11/installing/deps-installer/test/install/misc.ts[R1583-1594]

+function makeAssertNoPnpNodeOptionsScript (marker: string): string {
+  const scriptPath = path.resolve('assert-no-pnp-node-options.cjs')
+  fs.writeFileSync(scriptPath, `
+const fs = require('node:fs')
+
+if ((process.env.NODE_OPTIONS || '').includes('.pnp.cjs')) {
+  throw new Error('unexpected PnP NODE_OPTIONS')
+}
+fs.writeFileSync(process.argv[2], 'ok')
+`, 'utf8')
+  return `node ${JSON.stringify(scriptPath)} ${JSON.stringify(marker)}`
+}
Relevance

●● Moderate

They’ve rejected some “deduplicate to avoid drift” refactors; uncertain they’ll refactor this small
test helper.

PR-#13427

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 713439 requires avoiding duplicated implementations when similar logic already
exists and should be extracted/reused. In misc.ts, the newly added
makeAssertNoPnpNodeOptionsScript is effectively a copy of the existing
makeAssertNoPackageMapNodeOptionsScript, with only the searched substring and message changed.

Rule 713439: Avoid reimplementing existing functionality; extract and reuse shared modules
pnpm11/installing/deps-installer/test/install/misc.ts[1583-1607]

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

## Issue description
A new helper (`makeAssertNoPnpNodeOptionsScript`) was added that is structurally identical to the existing `makeAssertNoPackageMapNodeOptionsScript`, which is a small but direct duplication.

## Issue Context
This violates the repo’s compliance guidance to avoid reimplementing existing functionality and instead extract a shared helper when logic is near-identical.

## Fix Focus Areas
- pnpm11/installing/deps-installer/test/install/misc.ts[1583-1607]

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


2. No TypeScript test for PnP 📘 Rule violation ▣ Testability
Description
This PR changes PnP loader writing behavior in both Rust (pacquet) and TypeScript (pnpm), but only
adds regression coverage on the Rust side. The TypeScript stack lacks a mirrored test asserting that
virtualStoreOnly/fetch under nodeLinker: pnp does not write .pnp.cjs, violating the
cross-stack mirrored-tests requirement.
Code

pnpm11/installing/deps-installer/src/install/index.ts[1888]

+    if (opts.enablePnp && !opts.virtualStoreOnly) {
Relevance

●●● Strong

Repo has accepted requests to add mirrored TypeScript tests to match Rust behavior changes and
prevent divergence.

PR-#13597

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255044 requires mirrored tests in Rust and TypeScript for cross-stack behavior
changes. The TypeScript implementation was changed to suppress .pnp.cjs when virtualStoreOnly is
enabled, while new Rust tests were added to assert the behavior; no corresponding TypeScript
regression test was added in this PR.

Rule 2255044: Cross-stack behavior changes must have mirrored tests in Rust and TypeScript
pnpm11/installing/deps-installer/src/install/index.ts[1884-1889]
pnpm/crates/cli/tests/fetch.rs[179-207]
pnpm/crates/cli/tests/install.rs[1920-1952]

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 PR adds Rust regression tests for the new behavior (PnP + `virtualStoreOnly` must not write `.pnp.cjs`), but does not add equivalent TypeScript tests. This violates the requirement that cross-stack behavior changes have mirrored tests in both Rust and TypeScript.

## Issue Context
The TypeScript implementation now gates PnP loader generation on `!opts.virtualStoreOnly`, matching the Rust change. We should add TS coverage that fails if that guard is removed.

## Fix Focus Areas
- pnpm11/installing/commands/test/fetch.ts[230-294]
- pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[606-774]
- pnpm11/installing/deps-restorer/test/index.ts[819-835]

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


3. Hardcoded store version ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new fetch_under_pnp_does_not_write_the_loader test asserts store_dir.join("v11"), which will
fail or become misleading if the store layout version changes. Use
pacquet_store_dir::STORE_VERSION (already used elsewhere in the same test file) to keep the
assertion aligned with the store contract.
Code

pnpm/crates/cli/tests/fetch.rs[203]

+    assert!(store_dir.join("v11").exists(), "fetch must still populate the store");
Relevance

●●● Strong

Team previously accepted replacing hardcoded "v11" paths in tests with canonical constants to avoid
drift.

PR-#12831

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The failing assertion hardcodes "v11" while the repository defines the canonical store layout
version via STORE_VERSION and already uses it in the same test module, indicating the literal is
an avoidable maintenance hazard.

pnpm/crates/cli/tests/fetch.rs[168-173]
pnpm/crates/cli/tests/fetch.rs[192-207]
pnpm/crates/store-dir/src/store_dir.rs[12-21]

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

### Issue description
A newly added regression test hardcodes the store version directory name (`"v11"`). This makes the test fragile when `pacquet_store_dir::STORE_VERSION` is bumped, even if behavior remains correct.

### Issue Context
The repo exposes `pacquet_store_dir::STORE_VERSION` as the canonical store layout version and documents it as part of the store contract.

### Fix Focus Areas
- pnpm/crates/cli/tests/fetch.rs[200-205]

### Proposed fix
Replace `store_dir.join("v11")` with `store_dir.join(pacquet_store_dir::STORE_VERSION)` (and add/import the constant if needed).

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


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit 8368c4f

Results up to commit 6ef433d ⚖️ Balanced


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


Remediation recommended
1. Hardcoded store version ✓ Resolved 🐞 Bug ⚙ Maintainability
Description
The new fetch_under_pnp_does_not_write_the_loader test asserts store_dir.join("v11"), which will
fail or become misleading if the store layout version changes. Use
pacquet_store_dir::STORE_VERSION (already used elsewhere in the same test file) to keep the
assertion aligned with the store contract.
Code

pnpm/crates/cli/tests/fetch.rs[203]

+    assert!(store_dir.join("v11").exists(), "fetch must still populate the store");
Relevance

●●● Strong

Team previously accepted replacing hardcoded "v11" paths in tests with canonical constants to avoid
drift.

PR-#12831

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The failing assertion hardcodes "v11" while the repository defines the canonical store layout
version via STORE_VERSION and already uses it in the same test module, indicating the literal is
an avoidable maintenance hazard.

pnpm/crates/cli/tests/fetch.rs[168-173]
pnpm/crates/cli/tests/fetch.rs[192-207]
pnpm/crates/store-dir/src/store_dir.rs[12-21]

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

### Issue description
A newly added regression test hardcodes the store version directory name (`"v11"`). This makes the test fragile when `pacquet_store_dir::STORE_VERSION` is bumped, even if behavior remains correct.

### Issue Context
The repo exposes `pacquet_store_dir::STORE_VERSION` as the canonical store layout version and documents it as part of the store contract.

### Fix Focus Areas
- pnpm/crates/cli/tests/fetch.rs[200-205]

### Proposed fix
Replace `store_dir.join("v11")` with `store_dir.join(pacquet_store_dir::STORE_VERSION)` (and add/import the constant if needed).

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


2. No TypeScript test for PnP 📘 Rule violation ▣ Testability
Description
This PR changes PnP loader writing behavior in both Rust (pacquet) and TypeScript (pnpm), but only
adds regression coverage on the Rust side. The TypeScript stack lacks a mirrored test asserting that
virtualStoreOnly/fetch under nodeLinker: pnp does not write .pnp.cjs, violating the
cross-stack mirrored-tests requirement.
Code

pnpm11/installing/deps-installer/src/install/index.ts[1888]

+    if (opts.enablePnp && !opts.virtualStoreOnly) {
Relevance

●●● Strong

Repo has accepted requests to add mirrored TypeScript tests to match Rust behavior changes and
prevent divergence.

PR-#13597

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
PR Compliance ID 2255044 requires mirrored tests in Rust and TypeScript for cross-stack behavior
changes. The TypeScript implementation was changed to suppress .pnp.cjs when virtualStoreOnly is
enabled, while new Rust tests were added to assert the behavior; no corresponding TypeScript
regression test was added in this PR.

Rule 2255044: Cross-stack behavior changes must have mirrored tests in Rust and TypeScript
pnpm11/installing/deps-installer/src/install/index.ts[1884-1889]
pnpm/crates/cli/tests/fetch.rs[179-207]
pnpm/crates/cli/tests/install.rs[1920-1952]

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 PR adds Rust regression tests for the new behavior (PnP + `virtualStoreOnly` must not write `.pnp.cjs`), but does not add equivalent TypeScript tests. This violates the requirement that cross-stack behavior changes have mirrored tests in both Rust and TypeScript.

## Issue Context
The TypeScript implementation now gates PnP loader generation on `!opts.virtualStoreOnly`, matching the Rust change. We should add TS coverage that fails if that guard is removed.

## Fix Focus Areas
- pnpm11/installing/commands/test/fetch.ts[230-294]
- pnpm11/installing/deps-installer/test/install/globalVirtualStore.ts[606-774]
- pnpm11/installing/deps-restorer/test/index.ts[819-835]

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

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     12.3±0.21ms    30.3 MB/sec    1.14     14.1±2.00ms    26.6 MB/sec
packument/parse                                  1.00     43.3±3.47µs  1530.7 MB/sec    1.00     43.1±1.24µs  1537.5 MB/sec
tarball/download_dependency                      1.00      4.0±0.64ms  1083.5 KB/sec    1.29      5.2±0.47ms   837.9 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.00    211.9±6.39ms 75.5 KElem/sec    1.22   258.5±10.42ms 61.9 KElem/sec
workspace_resolution/hoist_heavy                 1.00    273.0±5.32ms        ? ?/sec    1.14    312.0±9.17ms        ? ?/sec

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 `@pnpm/crates/cli/tests/install.rs`:
- Around line 1949-1952: Update the install test around the existing .pnp.cjs
assertion to also verify that store_dir.join("v11") exists after install,
ensuring the fresh path materializes the store while still asserting the PnP
loader is absent.

In `@pnpm11/installing/deps-installer/src/install/index.ts`:
- Around line 1884-1888: Prevent dependency builds from receiving a suppressed
PnP loader: in pnpm11/installing/deps-installer/src/install/index.ts, gate the
dependency-build makeNodeRequireOption() call near lines 1918-1922 with
!opts.virtualStoreOnly; in pnpm11/installing/deps-restorer/src/index.ts, gate
the corresponding call near lines 621-625 with !skipPostImportLinking. Keep the
existing PnP artifact suppression behavior unchanged.
🪄 Autofix

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: 98b8cb66-6ed6-4f98-a9fc-fdccd22f6bda

📥 Commits

Reviewing files that changed from the base of the PR and between 3fb4ea7 and 6ef433d.

📒 Files selected for processing (7)
  • .changeset/pnp-loader-virtual-store-only.md
  • pnpm/crates/cli/tests/fetch.rs
  • pnpm/crates/cli/tests/install.rs
  • pnpm/crates/package-manager/src/install_frozen_lockfile.rs
  • pnpm/crates/package-manager/src/install_with_fresh_lockfile/linking.rs
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-restorer/src/index.ts

Comment thread pnpm/crates/cli/tests/install.rs Resolved
@codecov-commenter

codecov-commenter commented Aug 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.05%. Comparing base (3fb4ea7) to head (8368c4f).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13636   +/-   ##
=======================================
  Coverage   88.05%   88.05%           
=======================================
  Files         573      573           
  Lines       98389    98390    +1     
=======================================
+ Hits        86636    86639    +3     
+ Misses      11753    11751    -2     

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

Withholding `.pnp.cjs` under `virtualStoreOnly` left both TypeScript
paths still passing that path to Node with `--require`, so a dependency
lifecycle script would fail before it could run. The package-map option
directly below was already gated on whether its file was written; the
loader option now follows the same rule.

Adds the TypeScript coverage the guards were missing, mirroring the
existing package-map tests:

- `deps-installer`: asserts the loader is absent *and* that a dependency
  install script still runs, which is what proves the env is clean.
- `deps-restorer`: asserts the virtual store is populated and the loader
  is not written.

Each was verified to fail with its own guard removed. The Rust
fresh-path test now also asserts store population, so loader-absence
cannot pass by the install stopping early.

pacquet needs no equivalent change: it does not wire a PnP `--require`
into the build environment.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings August 4, 2026 10:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 88b72ea

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

@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

🤖 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 `@pnpm11/installing/deps-installer/test/install/misc.ts`:
- Around line 206-217: Update the regression assertions so both tests prove
virtual-store population, not merely filesystem setup: in
pnpm11/installing/deps-installer/test/install/misc.ts lines 206-217, assert a
concrete populated package entry or store metadata after
addDependenciesToPackage while retaining the .pnp.cjs absence and marker checks;
in pnpm11/installing/deps-restorer/test/index.ts lines 830-831, replace the
virtual-store directory-existence assertion with an assertion for the known
fixture package or expected store contents, while preserving the required
.pnp.cjs/NODE_OPTIONS checks.
🪄 Autofix

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: 8810f06a-be81-43da-ac90-31a195a9a9ad

📥 Commits

Reviewing files that changed from the base of the PR and between 6ef433d and 88b72ea.

📒 Files selected for processing (5)
  • pnpm/crates/cli/tests/install.rs
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/install/misc.ts
  • pnpm11/installing/deps-restorer/src/index.ts
  • pnpm11/installing/deps-restorer/test/index.ts
🚧 Files skipped from review as they are similar to previous changes (3)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-restorer/src/index.ts
  • pnpm/crates/cli/tests/install.rs

…e-only tests

Both new TypeScript tests asserted the loader's absence without proving
the install had populated anything, so each could have passed on an
install that bailed early.

The headless test now asserts an extracted file
(`rimraf/package.json`) rather than the virtual-store directory, and the
fresh test asserts the dependency reached a virtual-store slot. Checking
an extracted file rather than a directory listing also survives the
intra-store dependency links, which `virtualStoreOnly` still creates —
those belong to the store, not the project.

Reported by CodeRabbit.
Copilot AI review requested due to automatic review settings August 4, 2026 10:34

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.

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

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8125a01

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

…ssertion helper

Two review findings, neither affecting behaviour:

- `fetch.rs` asserted `store_dir.join("v11")`, which silently goes stale
  when the store layout version moves. It now uses
  `pacquet_store_dir::STORE_VERSION`, which the global-virtual-store test
  in the same file already relied on. The pre-existing hardcoded literal
  a few tests up is changed too, so the file does not carry two
  conventions for the same path.
- `makeAssertNoPnpNodeOptionsScript` was a copy of
  `makeAssertNoPackageMapNodeOptionsScript` differing only in the
  forbidden `NODE_OPTIONS` substring. Both are now
  `makeAssertNoNodeOptionsScript(name, forbidden, marker)`.

Reported by Qodo.
Copilot AI review requested due to automatic review settings August 4, 2026 10:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

@zkochan

zkochan commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

Thanks — worked through the three findings in 8368c4f. Two applied, one declined as stale.

Applied

Hardcoded store version (Bug) — correct. fetch.rs asserted store_dir.join("v11") while the global-virtual-store test a few lines up already used pacquet_store_dir::STORE_VERSION. Now uses the constant. I also changed the pre-existing literal in fetch_populates_every_group_by_default, so the file does not end up carrying two conventions for the same path — flagging that as a deliberate step slightly outside the diff.

Duplicate NODE_OPTIONS assertion helper (Rule violation) — correct. makeAssertNoPnpNodeOptionsScript was a copy of makeAssertNoPackageMapNodeOptionsScript differing only in the forbidden substring. Both are now makeAssertNoNodeOptionsScript(name, forbidden, marker); all three call sites pass.

Declined: "No TypeScript test for PnP" (Rule 2255044)

This one is stale — the mirrored TypeScript tests are already there, and were added two commits before the one the finding cites.

$ git grep -n 'virtualStoreOnly skips linking' 8125a0191e -- pnpm11
pnpm11/installing/deps-installer/test/install/misc.ts:194: test('does not write or inject the PnP loader when virtualStoreOnly skips linking', ...)
pnpm11/installing/deps-restorer/test/index.ts:819:      test('does not write the PnP loader when virtualStoreOnly skips linking', ...)

8125a0191e is the exact commit the finding's own evidence links to. They cover both TypeScript paths — fresh (deps-installer) and headless (deps-restorer) — and each was verified to fail with its own guard removed. The deps-installer one also asserts a dependency install script still runs, which is what covers the --require injection.

The underlying rule is a good one and I agree with it; it just does not apply here.


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

@qodo-code-review

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 8368c4f

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@zkochan

zkochan commented Aug 4, 2026

Copy link
Copy Markdown
Member Author

Follow-up on the "No TypeScript test for PnP" finding, which Qodo still lists after re-reviewing 8368c4f.

I tried to close it the way it asked — a mirror of the Rust CLI-level test in installing/commands/test/fetch.ts, driving the real fetch command. I've reverted that attempt, and the reasoning is worth recording.

Why it was abandoned. nodeLinker: 'pnp' is inert at that layer: enablePnp is derived in the config reader, and neither command handler declares it. Writing the test needs enablePnp added to three separate option types — FetchCommandOptions, InstallDepsOptions, and InstallCommandOptions. Widening three public command signatures to add coverage that the library-level tests already provide is the wrong trade for a PR about the loader.

Notably my first version of that test passed with the guard removed — inert, because nodeLinker never reached enablePnp. That is the third vacuous test this change has produced; each was caught only by deleting the guard and re-running.

What the coverage actually is, and why I think it is sufficient:

  • deps-installer — fresh path, asserts loader absence and that a dependency install script still runs (which is what covers the --require injection).
  • deps-restorer — headless path, which is what fetch uses, since fetch pins frozenLockfile.

Both fail with their own guard removed. The layer differs from the Rust tests, but the scenario is the same one.

A real latent bug found on the way, worth its own change. fetch.handler and install.handler both forward enablePnp into the install through their ...opts spread, so both honour it at runtime — but no Pick<Config, …> lists it, so no typed caller can set it. Happy to file that separately if useful.


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

@zkochan
zkochan merged commit d4a9248 into main Aug 4, 2026
36 checks passed
@zkochan
zkochan deleted the fix-pnp-virtual-store-only branch August 4, 2026 11:12
KSXGitHub pushed a commit that referenced this pull request Aug 4, 2026
Picks up the install-module decomposition (#13640 and
#13624), the headless-install extraction (#13637), the
PnP-loader fix for virtual-store-only installs (#13636), and a
dependency bump (#13631).

`build_workspace_state` moved out of `install.rs` into the new
`install/workspace_state.rs`, and its two call sites moved into
`install/apply_materialization.rs` and `install/prepare_modules_state.rs`.
This branch's `Sys: Clock` seam and the `::<Host>` turbofish are
re-applied at those new homes.

# Conflicts:
#	pnpm/crates/package-manager/src/install.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product: pacquet product: pnpm@11 reviewed: coderabbit CodeRabbit submitted an approving review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants