Skip to content

perf: let projects with a pnpmfile use the fast lockfile updates - #13770

Merged
zkochan merged 7 commits into
mainfrom
pnpmfile-gate
Aug 10, 2026
Merged

zkochan merged 7 commits into
mainfrom
pnpmfile-gate

Conversation

@zkochan

@zkochan zkochan commented Aug 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Item 7 of #13696 — the one the issue flags as highest value: the blanket !opts.hooks.readPackage?.length gate disabled every fast lockfile update for any project with a pnpmfile, exactly the population (large monorepos) where re-resolution hurts most.

The premise was proven with failing tests first, then the gate turned out to be unnecessary rather than merely liftable:

  • getContext already applies the composed readPackage hook to every project manifest, so drift detection and the handlers compare hooked manifests against the hooked state the lockfile records. The adversarial case — a hook that rewrites one of the project's own specifiers (raw ^1.0.0 hooked to a 1.0.0 pin) — is absorbed correctly: the fast update keeps the hooked specifier and never writes the raw one (pinned by a test that fails if detection ran on raw manifests).
  • A changed pnpmfile surfaces as pnpmfileChecksum drift, which is not a composable field, so it falls back to the resolver. Hooks the checksum cannot vouch for keep forcing the resolver: a programmatic readPackage hook (no calculatePnpmfileChecksum behind it) and a hook from the checksum-excluded global pnpmfile (reported by the new hasUntrackedReadPackageHook flag on requireHooks) both stay on the full-resolution path, each pinned by a test.
  • The freshness gates that validate every fast-update candidate are the same allProjectsAreUpToDate machinery that already admits frozen-like installs for pnpmfile projects on every repeat install, so the fast path's eligibility now matches the frozen path's.

pacquet has no such gate and already behaved this way; it gains the regression e2e pair (dead registry: unchanged-pnpmfile remove skips resolution and keeps the hook's transitive pin; a project-rewriting hook's recorded specifier survives a fast update untouched). Writing those tests surfaced a pre-existing recording divergence between the stacks — the TypeScript CLI records the hooked specifier for the importer entry while pacquet records the raw one — filed separately as #13769; both fast-update paths preserve whatever their resolver recorded, so neither is affected by it.

The CLI e2e that used a pnpmfile to force the resolution fallback still forces it (a newly added pnpmfile changes pnpmfileChecksum); its comment now states the actual reason.

Squash Commit Body

The blanket readPackage gate on canTryFastUpdateLockfile predates the
machinery that makes it unnecessary: getContext applies the composed
readPackage hook to every project manifest, so drift detection and the
handlers compare hooked manifests against the hooked state the
lockfile records, and a changed pnpmfile surfaces as pnpmfileChecksum
drift, which is not composable and falls back to the resolver. The
freshness gates that validate every candidate are the same ones that
already admit frozen-like installs for pnpmfile projects.

pacquet has no such gate and already behaved this way; it gains the
regression e2e tests, including one pinning that a fast update never
rewrites a specifier a project-rewriting hook recorded. Writing that
test surfaced a pre-existing recording divergence between the stacks,
filed as pnpm/pnpm#13769.

Item 7 of pnpm/pnpm#13696.

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.

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

  • Performance

    • Faster lockfile updates when project configuration remains unchanged, avoiding unnecessary package resolution.
    • Supported configuration hooks can now run during fast updates when their integrity can be verified.
  • Bug Fixes

    • Dependency removals preserve pins and rewritten version specifications supplied by configuration hooks.
    • Configuration changes, or hooks without verifiable integrity information, continue to trigger full dependency resolution when needed.
    • Untracked configuration hooks correctly prevent fast updates when their changes cannot be verified.

The blanket readPackage gate on canTryFastUpdateLockfile predates the
machinery that makes it unnecessary: getContext applies the composed
readPackage hook to every project manifest, so drift detection and the
handlers compare hooked manifests against the hooked state the
lockfile records, and a changed pnpmfile surfaces as pnpmfileChecksum
drift, which is not composable and falls back to the resolver. The
freshness gates that validate every candidate are the same ones that
already admit frozen-like installs for pnpmfile projects.

pacquet has no such gate and already behaved this way; it gains the
regression e2e tests, including one pinning that a fast update never
rewrites a specifier a project-rewriting hook recorded. Writing that
test surfaced a pre-existing recording divergence between the stacks,
filed as #13769.

Item 7 of #13696.
Copilot AI lite review requested due to automatic review settings August 10, 2026 15: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.

@coderabbitai

coderabbitai Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Fast lockfile updates now permit unchanged, checksum-covered pnpmfiles with readPackage hooks. Untracked hooks still force resolution. Tests cover dependency removal, skipped resolution, preserved hook changes, rewritten specifiers, and fallback resolution.

Changes

pnpmfile Fast Update

Layer / File(s) Summary
Hook metadata and fast-update eligibility
pnpm11/hooks/pnpmfile/src/requireHooks.ts, pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts, pnpm11/installing/deps-installer/src/install/index.ts, pnpm11/installing/deps-installer/package.json, pnpm11/installing/deps-installer/tsconfig.json
Hook metadata identifies checksum-excluded readPackage hooks. Fast updates allow hooks covered by calculatePnpmfileChecksum and reject untracked hooks.
Fast removal regression coverage
pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts, pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs, pnpm11/pnpm/test/install/lifecycleScripts.ts
Tests verify skipped resolution, preserved hook-generated lockfile data, rewritten specifiers, and fallback resolution for unsupported or changed pnpmfiles.
Release documentation
.changeset/pnpmfile-fast-update-gate.md
The changeset records patch releases and documents checksum-based fast lockfile updates.

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

Sequence Diagram(s)

sequenceDiagram
  participant requireHooks
  participant depsInstaller
  participant pnpmfileChecksum
  participant lockfile
  participant storeController
  requireHooks->>depsInstaller: Provide hook tracking metadata
  depsInstaller->>pnpmfileChecksum: Validate pnpmfile checksum coverage
  pnpmfileChecksum-->>depsInstaller: Allow or reject fast update
  depsInstaller->>lockfile: Remove dependency and preserve hook data
  depsInstaller->>storeController: Avoid requests for eligible fast updates
Loading

Possibly related issues

Possibly related PRs

  • pnpm/pnpm#13698: Extends fast lockfile updates for dependency removal.
  • pnpm/pnpm#13712: Updates dependency removal behavior and related integration tests.
  • pnpm/pnpm#13690: Adds pnpmfile hook metadata used in install decisions.

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

✨ 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 pnpmfile-gate

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.

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

Enable fast lockfile updates for projects using pnpmfile readPackage

✨ Enhancement 🧪 Tests 🕐 40+ Minutes

Grey Divider

AI Description

• Remove the readPackage-hook gate so pnpmfile projects can use fast lockfile rewrites.
• Rely on pnpmfileChecksum drift and existing freshness checks to safely fall back to resolution.
• Add regression tests ensuring pnpmfile-driven pins/specifiers survive fast updates without
 registry access.
Diagram

graph TD
  A["deps-installer mutateModules"] --> B["getContext readPackage"] --> C{"Fast update eligible?"}
  C --> D["Fast lockfile update"] --> E[("wanted lockfile")]
  C -- "pnpmfileChecksum drift or other gates" --> F["Full resolution"] --> E

  subgraph Legend
    direction LR
    _proc["Process/step"] ~~~ _dec{"Decision"} ~~~ _db[("Lockfile")]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep a narrower readPackage gate
  • ➕ Minimizes behavioral change surface area if any hook edge-cases exist
  • ➖ Still blocks the primary value case (large monorepos with pnpmfile)
  • ➖ Duplicates safety already provided by hooked-manifest drift detection and pnpmfileChecksum drift
2. Persist both raw and hooked specifiers in lockfile
  • ➕ Makes lockfile semantics explicit and could simplify certain comparisons
  • ➖ Format change with migration burden and ecosystem impact
  • ➖ Not necessary to safely enable fast updates given current checksum/drift checks

Recommendation: Proceed with the current approach: removing the blanket readPackage gate aligns fast-update eligibility with the existing frozen-like freshness logic, while pnpmfileChecksum drift continues to force full resolution when the pnpmfile changes. The added regression tests meaningfully de-risk the change, especially around hook-modified specifiers and dead-registry scenarios.

Files changed (5) +240 / -3

Enhancement (1) +5 / -1
index.tsRemove readPackage-hook gate from fast lockfile update eligibility +5/-1

Remove readPackage-hook gate from fast lockfile update eligibility

• Drops the blanket '!opts.hooks.readPackage?.length' condition from the fast-update candidate gate. Adds rationale comments: manifests are already processed through getContext hooks and pnpmfile changes are caught via pnpmfileChecksum drift.

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

Tests (3) +229 / -2
lockfile_resolution_reuse.rsAdd pacquet E2E regressions for pnpmfile fast-update removals +130/-0

Add pacquet E2E regressions for pnpmfile fast-update removals

• Introduces two new Rust E2E tests verifying removals skip resolution even with an unchanged pnpmfile. Also asserts that pnpmfile-driven dependency pins and recorded specifiers survive fast lockfile updates under a dead-registry setup.

pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs

pnpmfileFastUpdate.tsAdd Jest tests ensuring pnpmfile fast updates skip resolution safely +96/-0

Add Jest tests ensuring pnpmfile fast updates skip resolution safely

• Adds tests proving uninstall/removal operations do not call the store controller (no resolution) when pnpmfileChecksum is unchanged. Covers both transitive pinning via readPackage and project-specifier rewriting, ensuring fast updates keep the hooked/recorded specifiers.

pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts

lifecycleScripts.tsClarify why pnpmfile-based remove falls back to resolution in lifecycle test +3/-2

Clarify why pnpmfile-based remove falls back to resolution in lifecycle test

• Updates the test comment to reflect the real fallback reason: a pnpmfile added after install changes pnpmfileChecksum. Keeps the existing assertion that the removal uses the resolve-then-materialize path (and thus lifecycle behavior).

pnpm11/pnpm/test/install/lifecycleScripts.ts

Other (1) +6 / -0
pnpmfile-fast-update-gate.mdChangeset: allow fast lockfile updates for pnpmfile projects +6/-0

Changeset: allow fast lockfile updates for pnpmfile projects

• Adds a patch changeset for both @pnpm/installing.deps-installer and pnpm. Documents that an unchanged pnpmfile (via pnpmfileChecksum) no longer forces re-resolution for fast lockfile rewrite operations.

.changeset/pnpmfile-fast-update-gate.md

@greptile-apps

greptile-apps Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The PR is not yet safe to merge because a pnpmfile composed with a programmatic readPackage hook can still take the fast path and retain a stale dependency graph.

The fix tracks checksum-excluded pnpmfile hooks, but recursive hook composition appends programmatic hooks without setting the untracked flag, so the pnpmfile checksum can incorrectly vouch for the combined hook array.

Files Needing Attention: pnpm11/installing/commands/src/recursive.ts, pnpm11/hooks/pnpmfile/src/requireHooks.ts, pnpm11/installing/deps-installer/src/install/index.ts

Reviews (4): Last reviewed commit: "chore: sync tsconfig references via meta..." | Re-trigger Greptile

@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 @.changeset/pnpmfile-fast-update-gate.md:
- Around line 2-3: Add a "pacquet": patch entry to the changeset alongside the
existing package entries, ensuring both affected published packages receive
release bumps and release notes.
🪄 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: cae909f3-c540-49fd-9b52-a04b82d4dde1

📥 Commits

Reviewing files that changed from the base of the PR and between 25e3fe9 and 977ffac.

📒 Files selected for processing (5)
  • .changeset/pnpmfile-fast-update-gate.md
  • pnpm/crates/cli/tests/suite/lockfile_resolution_reuse.rs
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts
  • pnpm11/pnpm/test/install/lifecycleScripts.ts

Comment thread .changeset/pnpmfile-fast-update-gate.md Resolved
@github-actions

github-actions Bot commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Micro-Benchmark Results

Linux

group                                            main                                   pr
-----                                            ----                                   --
lockfile/parse_pnpm_lock                         1.00     13.4±1.16ms    28.0 MB/sec    1.37     18.3±3.27ms    20.4 MB/sec
packument/parse                                  1.00     38.0±1.44µs  1743.6 MB/sec    1.03     39.3±1.46µs  1688.7 MB/sec
tarball/download_dependency                      1.00      2.7±0.54ms  1606.9 KB/sec    1.08      2.9±0.26ms  1485.5 KB/sec
tarball_batch/cold_store_many_medium_tarballs    1.19   229.8±45.67ms 69.6 KElem/sec    1.00    192.3±5.45ms 83.2 KElem/sec
workspace_resolution/hoist_heavy                 1.00   318.1±13.93ms        ? ?/sec    1.01   321.9±21.76ms        ? ?/sec

@qodo-code-review

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

Copy link
Copy Markdown

Code Review by Qodo

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

Grey Divider


Remediation recommended

1. Untracked hook fast-path 🐞 Bug ⛨ Security ⭐ New
Description
canTryFastUpdateLockfile now allows fast lockfile updates with readPackage hooks when
calculatePnpmfileChecksum exists and hasUntrackedReadPackageHook is falsy, but
hasUntrackedReadPackageHook is only derived from pnpmfile entries and can miss additional
programmatic readPackage hooks merged into opts.hooks. This can skip resolution even when
effective manifests change (hook drift not covered by pnpmfileChecksum), producing an
incorrect/stale lockfile update.
Code

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

+      (!opts.hooks.readPackage?.length ||
+        (opts.hooks.calculatePnpmfileChecksum != null && !opts.hooks.hasUntrackedReadPackageHook)) &&
Relevance

●●● Strong

Team often accepts fast-path safety hardening to avoid bypassing checks/policies.

PR-#13464
PR-#13482

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fast-path gate now depends on hasUntrackedReadPackageHook, but that flag is computed only from
pnpmfile entries, while other code paths can merge opts.hooks.readPackage into the effective hook
list without recomputing the flag, allowing a checksum-uncovered hook to be present while the
fast-path still sees hasUntrackedReadPackageHook as false.

pnpm11/installing/deps-installer/src/install/index.ts[754-781]
pnpm11/hooks/pnpmfile/src/requireHooks.ts[128-141]
pnpm11/installing/commands/src/recursive.ts[382-393]

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

### Issue description
`canTryFastUpdateLockfile` treats a `readPackage` hook as safe for fast lockfile updates when a pnpmfile checksum function exists and `hasUntrackedReadPackageHook` is falsey. However, `hasUntrackedReadPackageHook` is computed in `requireHooks()` only from pnpmfile entries, and other code can merge additional `readPackage` hooks into `opts.hooks.readPackage` without updating/recomputing the flag. This can incorrectly enable fast updates even though some effective `readPackage` hooks are not covered by the checksum.

### Issue Context
This PR introduced the new `hasUntrackedReadPackageHook` signal and made the fast-path gate depend on it. Any mismatch between the final `opts.hooks.readPackage` array and the `hasUntrackedReadPackageHook` boolean defeats the safety contract.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[772-781]
- pnpm11/hooks/pnpmfile/src/requireHooks.ts[128-141]
- pnpm11/installing/commands/src/recursive.ts[384-393]

### What to change
1. Ensure `hasUntrackedReadPackageHook` reflects the *effective* hooks after merges:
  - When combining hook sets (e.g. `recursive.ts`), set:
    - `hasUntrackedReadPackageHook = (pnpmfileHooks.hasUntrackedReadPackageHook ?? false) || (opts.hooks?.hasUntrackedReadPackageHook ?? false) || (addedReadPackageHooksNotFromChecksum ? true : false)`.
  - If you can’t reliably prove a merged-in `readPackage` hook is checksum-covered, conservatively treat it as untracked.
2. Add a regression test covering the mixed case: pnpmfile-provided checksum + additional programmatic `readPackage` hook => fast update must be rejected (resolver path is used).

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


2. Missing checksum still fast-updates 🐞 Bug ⛨ Security
Description
canTryFastUpdateLockfile now allows the fast path whenever a readPackage hook exists and
hooks.calculatePnpmfileChecksum is defined, but it does not require the *computed*
pnpmfileChecksum value to be present. If a caller supplies a checksum function that returns
undefined, pnpm can run fast updates with no pnpmfile drift marker, so changes to readPackage
behavior (especially transitive manifest rewrites) may not force a re-resolution.
Code

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

+      // A pnpmfile's `readPackage` hook is safe here — `getContext` applies
+      // it to every project manifest and a changed pnpmfile surfaces as
+      // `pnpmfileChecksum` drift. A programmatic hook has no checksum
+      // proving it unchanged, so it keeps forcing the resolver.
+      (!opts.hooks.readPackage?.length || opts.hooks.calculatePnpmfileChecksum != null) &&
Relevance

●●● Strong

Team often accepts adding safety guards to fast-update paths to avoid incorrect reuse/drift.

PR-#13482
PR-#13464

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fast-update gate only checks for a checksum function, but the checksum value is allowed to be
undefined; without a persisted checksum, pnpm loses the drift signal for
pnpmfile-driven/transitive rewrites, and allProjectsAreUpToDate can’t catch those changes because
it only validates importer vs project manifest.

pnpm11/installing/deps-installer/src/install/index.ts[772-776]
pnpm11/installing/deps-installer/src/install/index.ts[664-716]
pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts[106-113]
pnpm11/lockfile/verification/src/allProjectsAreUpToDate.ts[17-71]

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

### Issue description
`canTryFastUpdateLockfile` currently treats the *presence* of `hooks.calculatePnpmfileChecksum` as sufficient to allow the fast lockfile update path with `readPackage` hooks. However, the hook type allows returning `Promise<string | undefined>`, and the gate does not require that a non-`undefined` checksum was actually computed/recorded.

When the checksum resolves to `undefined`, there is no lockfile-level drift marker for `readPackage` effects that aren’t reflected in the (already-hooked) project manifests (notably: transitive manifest rewrites). In that scenario, fast updates can incorrectly skip full resolution.

### Issue Context
- The code already computes `pnpmfileChecksum` (`await opts.hooks.calculatePnpmfileChecksum?.()`) and stores it in lockfile settings when doing a full resolution.
- The freshness gate `allProjectsAreUpToDate` only checks project manifests/importers + related settings and does not encode pnpmfile/transitive `readPackage` effects unless they are represented via `pnpmfileChecksum`.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[772-776]

### Suggested fix
- Change the fast-update eligibility check to require a *defined* checksum value when `readPackage` hooks are present (e.g., `(!opts.hooks.readPackage?.length || pnpmfileChecksum != null)`), rather than only checking `opts.hooks.calculatePnpmfileChecksum != null`.
- (Optional but recommended) Add/extend a regression test that sets `calculatePnpmfileChecksum: async () => undefined` with a non-empty `readPackage` hook, and asserts the uninstall/remove path performs resolution (i.e., does not take the fast-update path).

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



Informational

3. Untracked hook detection untested ✓ Resolved 🐞 Bug ⚙ Maintainability ⭐ New
Description
The new hasUntrackedReadPackageHook safety signal is computed in requireHooks(), but the
deps-installer regression test bypasses that by setting the flag manually. This leaves a gap where
regressions in requireHooks detection or in plumbing/propagation could re-enable the fast path for
a checksum-excluded global pnpmfile hook without tests catching it.
Code

pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts[R123-125]

+  const readPackage = (pkg: PackageManifest) => pkg
+  const hooks = { readPackage: [readPackage], calculatePnpmfileChecksum, hasUntrackedReadPackageHook: true }
+  await mutateModulesInSingleProject({
Relevance

● Weak

Similar “strengthen test to cover real failure mode” suggestions were previously rejected.

PR-#13680

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
requireHooks now computes hasUntrackedReadPackageHook, but the new deps-installer test
hard-codes the flag instead of exercising hook loading, so it won’t fail if detection/plumbing
breaks; the new global fixture supports adding such a test.

pnpm11/hooks/pnpmfile/src/requireHooks.ts[128-141]
pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts[115-141]
pnpm11/hooks/pnpmfile/test/fixtures/globalReadPackage.js[1-5]
pnpm11/hooks/pnpmfile/test/index.ts[61-79]

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 `hasUntrackedReadPackageHook` flag was added to `requireHooks()` to represent checksum-excluded global pnpmfile `readPackage` hooks. The deps-installer test exercises downstream behavior by manually setting this flag, but does not validate that `requireHooks()` actually sets it (or that it survives the production wiring into deps-installer).

### Issue Context
This flag is safety-critical for deciding whether fast lockfile updates may run. If `requireHooks()` stops setting it correctly or a call site drops it, fast updates could silently run under a global pnpmfile hook.

### Fix Focus Areas
- pnpm11/hooks/pnpmfile/src/requireHooks.ts[128-141]
- pnpm11/hooks/pnpmfile/test/__fixtures__/globalReadPackage.js[1-5]
- pnpm11/hooks/pnpmfile/test/index.ts[61-79]
- pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts[115-141]

### What to change
1. Add/extend a `requireHooks` unit test that:
  - passes `globalPnpmfile` pointing at `test/__fixtures__/globalReadPackage.js` (or another fixture that defines `hooks.readPackage`),
  - asserts `hooks.hasUntrackedReadPackageHook === true`, and
  - asserts `hooks.calculatePnpmfileChecksum` exists (and optionally that the checksum excludes the global pnpmfile if that’s the intended behavior).
2. Optionally add an integration-style test that runs through the real hook-loading path (instead of manually setting the flag) and asserts fast update is disabled when the global pnpmfile provides a `readPackage` hook.

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


Grey Divider

Context used
✅ Compliance rules (platform): 26 rules

Grey Divider

Tip of the day
💡 Did you know, you can reply 'qodo' on any finding to push back, ask questions, or dig deeper

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Previous review results

Review updated until commit a3441d2

Results up to commit 2e374b0 ⚖️ Balanced


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


Remediation recommended
1. Missing checksum still fast-updates 🐞 Bug ⛨ Security
Description
canTryFastUpdateLockfile now allows the fast path whenever a readPackage hook exists and
hooks.calculatePnpmfileChecksum is defined, but it does not require the *computed*
pnpmfileChecksum value to be present. If a caller supplies a checksum function that returns
undefined, pnpm can run fast updates with no pnpmfile drift marker, so changes to readPackage
behavior (especially transitive manifest rewrites) may not force a re-resolution.
Code

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

+      // A pnpmfile's `readPackage` hook is safe here — `getContext` applies
+      // it to every project manifest and a changed pnpmfile surfaces as
+      // `pnpmfileChecksum` drift. A programmatic hook has no checksum
+      // proving it unchanged, so it keeps forcing the resolver.
+      (!opts.hooks.readPackage?.length || opts.hooks.calculatePnpmfileChecksum != null) &&
Relevance

●●● Strong

Team often accepts adding safety guards to fast-update paths to avoid incorrect reuse/drift.

PR-#13482
PR-#13464

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The fast-update gate only checks for a checksum function, but the checksum value is allowed to be
undefined; without a persisted checksum, pnpm loses the drift signal for
pnpmfile-driven/transitive rewrites, and allProjectsAreUpToDate can’t catch those changes because
it only validates importer vs project manifest.

pnpm11/installing/deps-installer/src/install/index.ts[772-776]
pnpm11/installing/deps-installer/src/install/index.ts[664-716]
pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts[106-113]
pnpm11/lockfile/verification/src/allProjectsAreUpToDate.ts[17-71]

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

### Issue description
`canTryFastUpdateLockfile` currently treats the *presence* of `hooks.calculatePnpmfileChecksum` as sufficient to allow the fast lockfile update path with `readPackage` hooks. However, the hook type allows returning `Promise<string | undefined>`, and the gate does not require that a non-`undefined` checksum was actually computed/recorded.

When the checksum resolves to `undefined`, there is no lockfile-level drift marker for `readPackage` effects that aren’t reflected in the (already-hooked) project manifests (notably: transitive manifest rewrites). In that scenario, fast updates can incorrectly skip full resolution.

### Issue Context
- The code already computes `pnpmfileChecksum` (`await opts.hooks.calculatePnpmfileChecksum?.()`) and stores it in lockfile settings when doing a full resolution.
- The freshness gate `allProjectsAreUpToDate` only checks project manifests/importers + related settings and does not encode pnpmfile/transitive `readPackage` effects unless they are represented via `pnpmfileChecksum`.

### Fix Focus Areas
- pnpm11/installing/deps-installer/src/install/index.ts[772-776]

### Suggested fix
- Change the fast-update eligibility check to require a *defined* checksum value when `readPackage` hooks are present (e.g., `(!opts.hooks.readPackage?.length || pnpmfileChecksum != null)`), rather than only checking `opts.hooks.calculatePnpmfileChecksum != null`.
- (Optional but recommended) Add/extend a regression test that sets `calculatePnpmfileChecksum: async () => undefined` with a non-empty `readPackage` hook, and asserts the uninstall/remove path performs resolution (i.e., does not take the fast-update path).

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


Qodo Logo

@qodo-code-review

Copy link
Copy Markdown

PR Code Suggestions ✨

Warning

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

No code suggestions found for the PR.

@codecov-commenter

codecov-commenter commented Aug 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.14%. Comparing base (25e3fe9) to head (a3441d2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #13770   +/-   ##
=======================================
  Coverage   88.13%   88.14%           
=======================================
  Files         623      623           
  Lines      101380   101380           
=======================================
+ Hits        89353    89361    +8     
+ Misses      12027    12019    -8     

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

The lifted gate relied on pnpmfileChecksum drift to catch a changed
hook, but a hook passed programmatically (no pnpmfile behind it) has
no checksum proving it unchanged between installs, so its output
drift would go unnoticed by every freshness gate. The fast paths now
admit readPackage hooks only when hooks.calculatePnpmfileChecksum is
present, which requireHooks sets whenever the hooks come from real
pnpmfiles. API consumers passing bare hooks keep today's
full-resolution behavior, pinned by a test.
Copilot AI review requested due to automatic review settings August 10, 2026 15:16

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)
pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts (1)

115-121: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Add checksum-drift coverage if no existing test covers it.

calculatePnpmfileChecksum always returns test-pnpmfile-checksum in these cases. The added tests verify unchanged pnpmfiles and hooks without checksum support, but they do not verify that a changed checksum triggers package resolution. Confirm that an existing test changes the checksum between installs. Add one if it does not.

As per path instructions, tests must meaningfully verify checksum drift fallback.

🤖 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 `@pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts` around
lines 115 - 121, Review the tests using calculatePnpmfileChecksum and confirm
they perform installs with different checksum values between runs. If no test
covers this drift, add coverage that changes the returned checksum and verifies
package resolution is triggered, while preserving the existing
unchanged-checksum and no-checksum-hook cases.

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts`:
- Around line 115-121: Review the tests using calculatePnpmfileChecksum and
confirm they perform installs with different checksum values between runs. If no
test covers this drift, add coverage that changes the returned checksum and
verifies package resolution is triggered, while preserving the existing
unchanged-checksum and no-checksum-hook cases.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f45bb88a-0822-4f0b-ad75-df904c47486d

📥 Commits

Reviewing files that changed from the base of the PR and between 977ffac and 2e374b0.

📒 Files selected for processing (2)
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm11/installing/deps-installer/src/install/index.ts

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

Copy link
Copy Markdown

Code review by qodo was updated up to the latest commit 2e374b0

@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 pnpmfile checksum deliberately excludes the global pnpmfile, so a
readPackage hook it contributes can drift without pnpmfileChecksum
moving. requireHooks now reports hasUntrackedReadPackageHook when a
checksum-excluded pnpmfile exports readPackage, and the fast-update
gate requires the flag to be off in addition to the checksum
calculator being present. The flag also gives API consumers composing
their own hooks with pnpmfile hooks an explicit way to keep the
resolver in the loop.
Copilot AI review requested due to automatic review settings August 10, 2026 15:32

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.

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/pnpmfileFastUpdate.ts`:
- Around line 123-124: Update the test around requireHooks to create a temporary
checksum-excluded global pnpmfile and load it through the normal hook-loading
path instead of injecting a prebuilt hooks object with
hasUntrackedReadPackageHook set manually. Verify the resulting fast-update
behavior and fallback-resolution path depend on the flag produced by
requireHooks; rename the test if it remains only a downstream gate test.
🪄 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: ee9b159f-e5a1-4584-b0d3-6d64e89057ed

📥 Commits

Reviewing files that changed from the base of the PR and between 2e374b0 and f5ca8a6.

⛔ Files ignored due to path filters (1)
  • pnpm11/hooks/pnpmfile/test/__fixtures__/globalReadPackage.js is excluded by !**/__fixtures__/**
📒 Files selected for processing (4)
  • pnpm11/hooks/pnpmfile/src/requireHooks.ts
  • pnpm11/installing/deps-installer/src/install/extendInstallOptions.ts
  • pnpm11/installing/deps-installer/src/install/index.ts
  • pnpm11/installing/deps-installer/test/install/pnpmfileFastUpdate.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • pnpm11/installing/deps-installer/src/install/index.ts

The install-level test injected the untracked-hook flag by hand, so
it kept passing even if requireHooks stopped producing the flag. It
now writes a real global pnpmfile and loads it through requireHooks,
covering the producer-to-consumer seam; verified to fail with the
flag assignment removed.
@zkochan
zkochan merged commit 69328ff into main Aug 10, 2026
37 of 38 checks passed
@zkochan
zkochan deleted the pnpmfile-gate branch August 10, 2026 16:24
@qodo-code-review qodo-code-review Bot mentioned this pull request Nov 19, 2026
5 tasks done
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