Skip to content

fix: apply trustPolicy to the pnpm version a project pins - #17038

Merged
zkochan merged 1 commit into
mainfrom
switch-trust-policy
Oct 17, 2026
Merged

zkochan merged 1 commit into
mainfrom
switch-trust-policy

Conversation

@zkochan

@zkochan zkochan commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Step 5 of pnpm/tasks#144 settles the parity drift left over from #16319. Related to pnpm/tasks#144.

Before this PR, the two CLIs resolved the pinned pnpm differently:

  • pnpm v12 resolves the pnpm a project pins (packageManager / devEngines.packageManager) under trustPolicy, trustPolicyExclude, and trustPolicyIgnoreAfter, like any other dependency.
  • pnpm v11 resolved it with no trust policy at all.

So a pinned version whose trust evidence was downgraded failed on v12 and ran on v11. #16319 settled that the failure is intended (pnpm v10.34.6 was republished with provenance to fix that report). This PR makes v11 apply the policy too.

Change (v11 only)

  • resolveManifestDependencies and resolvePackageManagerIntegrities take the three trust settings (PackageTrustPolicy) and pass them to resolveDependencies.
  • switchCliVersion (switching to the pinned version) and syncEnvLockfile (recording a pin the running pnpm already satisfies) pass them from the config.
  • The switch's store controller is already created from the full config, so trustPolicy: no-downgrade already turns on the full metadata the check reads.
  • pnpm with and pnpm self-update are unchanged. They are separate flows, and self-update already checks its target version against the policy.
  • The trustPolicy docs of both versions now say the check covers the pinned pnpm. v12's behavior was already this, but undocumented.

Tests

  • resolveManifestDependencies.test.ts resolves @pnpm/[email protected], a trust downgrade, against the mock registry. It fails with ERR_PNPM_TRUST_DOWNGRADE under no-downgrade, and resolves under trustPolicyExclude and with the policy off. The test fails if the settings aren't passed to resolveDependencies.
  • switchCliVersion.test.ts and syncEnvLockfile.test.ts check that the config's trust settings reach resolvePackageManagerIntegrities.

Squash Commit Body

pnpm v12 resolves the pinned pnpm under the project's `trustPolicy`,
`trustPolicyExclude`, and `trustPolicyIgnoreAfter`, as it resolves any
other dependency. pnpm v11 resolved it with no trust policy at all, both
when switching to the pinned version and when recording a pin the
running pnpm already satisfies. A version whose trust evidence was
downgraded therefore failed under one CLI and ran under the other
(https://github.com/pnpm/pnpm/issues/16319). The trust failure is the
intended behavior, so v11 now matches v12.

`resolveManifestDependencies` and `resolvePackageManagerIntegrities` take
the three settings (`PackageTrustPolicy`) and pass them to
`resolveDependencies`. `switchCliVersion` and `syncEnvLockfile` pass them
from the config. The store controller for the switch is already created
from the full config, so `trustPolicy: no-downgrade` already fetches the
full metadata the check reads.

The trustPolicy docs of both versions now say the check covers the
pinned pnpm.

Part of https://github.com/pnpm/tasks/issues/144

Checklist

  • I checked the referenced issue and verified that none of the PRs
    already linked to it solves it.
  • New features are implemented only in the Rust pnpm v12 CLI. Bug fixes
    are implemented in every affected version.
  • 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-5).

🤖 Generated with Claude Code


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

Summary by CodeRabbit

  • New Features
    • Trust-policy checks now cover pnpm versions pinned in packageManager or devEngines.packageManager. If a pinned version has downgraded trust evidence, pnpm stops before switching to it or recording it in the lockfile.
  • Documentation
    • Updated the dependency-resolution settings guides to describe trust-policy checks for pinned pnpm versions.

pnpm v12 resolves the pinned pnpm under the project's `trustPolicy`,
`trustPolicyExclude`, and `trustPolicyIgnoreAfter`, as it resolves any
other dependency. pnpm v11 resolved it with no trust policy at all, both
when switching to the pinned version and when recording a pin the
running pnpm already satisfies. A version whose trust evidence was
downgraded therefore failed under one CLI and ran under the other
(#16319). The trust failure is the
intended behavior, so v11 now matches v12.

`resolveManifestDependencies` and `resolvePackageManagerIntegrities` take
the three settings (`PackageTrustPolicy`) and pass them to
`resolveDependencies`. `switchCliVersion` and `syncEnvLockfile` pass them
from the config. The store controller for the switch is already created
from the full config, so `trustPolicy: no-downgrade` already fetches the
full metadata the check reads.

The trustPolicy docs of both versions now say the check covers the
pinned pnpm.

Part of pnpm/tasks#144

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: pnpm/pnpm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a62ab83a-705b-44b1-81e0-4c43d492c3b5
📥 Commits

Reviewing files that changed from the base of the PR and between 2bdf8de and 7030cf0.

📒 Files selected for processing: 11
  • .changeset/switch-honors-trust-policy.md
  • pnpm/docs/settings/dependency-resolution.md
  • pnpm11/docs/settings/dependency-resolution.md
  • pnpm11/installing/env-installer/src/index.ts
  • pnpm11/installing/env-installer/src/resolveManifestDependencies.ts
  • pnpm11/installing/env-installer/src/resolvePackageManagerIntegrities.ts
  • pnpm11/installing/env-installer/test/resolveManifestDependencies.test.ts
  • pnpm11/pnpm/src/switchCliVersion.test.ts
  • pnpm11/pnpm/src/switchCliVersion.ts
  • pnpm11/pnpm/src/syncEnvLockfile.test.ts
  • pnpm11/pnpm/src/syncEnvLockfile.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

📝 Walkthrough

Pinned pnpm version resolution now receives configured trust-policy options. The changes add option forwarding, tests, documentation updates, and patch-release notes.

Changes: Pinned pnpm trust-policy checks

Layer / File(s) Summary
Trust-policy option plumbing
pnpm11/installing/env-installer/src/index.ts, pnpm11/installing/env-installer/src/resolveManifestDependencies.ts, pnpm11/installing/env-installer/src/resolvePackageManagerIntegrities.ts, pnpm11/installing/env-installer/test/resolveManifestDependencies.test.ts
The env-installer exposes and forwards the three trust-policy options. Tests cover resolution with no-downgrade, an exclusion, and no trust policy.
Pinned pnpm resolution
pnpm11/pnpm/src/syncEnvLockfile.ts, pnpm11/pnpm/src/switchCliVersion.ts, pnpm11/pnpm/src/syncEnvLockfile.test.ts, pnpm11/pnpm/src/switchCliVersion.test.ts, pnpm/docs/settings/dependency-resolution.md, pnpm11/docs/settings/dependency-resolution.md, .changeset/switch-honors-trust-policy.md
The pnpm configuration helper supplies trust-policy options to pinned-version resolution. Tests check option forwarding. Documentation and release notes describe checks before switching versions or recording them in the lockfile.

Priority: ➖ Normal

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

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant switchCliVersion
  participant packageManagerTrustPolicy
  participant resolvePackageManagerIntegrities
  participant resolveManifestDependencies
  participant resolveDependencies
  switchCliVersion->>packageManagerTrustPolicy: Read trust settings from config
  packageManagerTrustPolicy-->>switchCliVersion: Return trust-policy options
  switchCliVersion->>resolvePackageManagerIntegrities: Resolve pinned pnpm version with trust options
  resolvePackageManagerIntegrities->>resolveManifestDependencies: Forward trust-policy options
  resolveManifestDependencies->>resolveDependencies: Resolve dependencies with trust-policy options
Loading

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

Suggested reviewers: ksxgithub

Merge Risk: ⚪ Minimal · up to 7030c

pnpm v11 now applies trustPolicy, trustPolicyExclude, and trustPolicyIgnoreAfter when it resolves a pinned pnpm version, matching pnpm v12. Pins already recorded in the lockfile are reused without a fresh check, the same way v12 and ordinary locked dependencies behave. No outstanding merge risk was found.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@zkochan
zkochan marked this pull request as ready for review October 17, 2026 12:51
@zkochan

zkochan commented Oct 17, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

Copilot AI balanced review requested due to automatic review settings October 17, 2026 12:51

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

Your trial has ended. Reactivate Greptile to resume code reviews.

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

Apply trust policy when resolving a project-pinned pnpm version

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 20-40 Minutes

Grey Divider

AI Description

• Apply project trust settings when pnpm v11 resolves a pinned pnpm version, matching v12 behavior.
• Reject trust downgrades before switching versions or recording a pin, while honoring policy
 exclusions.
• Add resolution and config-forwarding tests, plus documentation for both versions.
Diagram

graph TD
  CFG["Project config"] --> SWITCH["Version switch"] --> INTEGRITIES["Integrity resolution"] --> MANIFEST["Manifest resolution"] --> DEPS["Dependency resolver"]
  CFG --> SYNC["Lockfile sync"] --> INTEGRITIES
Loading
High-Level Assessment

Passing the existing trust settings through the shared dependency resolver is the appropriate approach: it gives pinned pnpm the same checks as other dependencies without duplicating policy logic. No separate trust checker is warranted.

Files changed (11) +125 / -5

Enhancement (1) +1 / -0
index.tsExport the package trust policy type +1/-0

Export the package trust policy type

• Exposes the shared trust-settings type for use by v11 CLI callers.

pnpm11/installing/env-installer/src/index.ts

Bug fix (4) +35 / -5
resolveManifestDependencies.tsApply trust settings during manifest resolution +13/-1

Apply trust settings during manifest resolution

• Defines a type for the three resolver trust settings and forwards them to dependency resolution, where trust checks are enforced.

pnpm11/installing/env-installer/src/resolveManifestDependencies.ts

resolvePackageManagerIntegrities.tsCarry trust settings through package-manager resolution +5/-2

Carry trust settings through package-manager resolution

• Accepts trust settings and supplies them to manifest resolution for exact versions and range or tag resolution.

pnpm11/installing/env-installer/src/resolvePackageManagerIntegrities.ts

switchCliVersion.tsApply project trust settings to switch resolution +2/-1

Apply project trust settings to switch resolution

• Passes the project's trust policy, exclusions, and ignore-after setting when resolving integrities for a pinned pnpm version.

pnpm11/pnpm/src/switchCliVersion.ts

syncEnvLockfile.tsApply project trust settings during lockfile sync +15/-1

Apply project trust settings during lockfile sync

• Passes the configured trust settings when resolving a pin for lockfile recording. Adds a shared helper used by both sync and version switching.

pnpm11/pnpm/src/syncEnvLockfile.ts

Tests (3) +79 / -0
resolveManifestDependencies.test.tsTest trust enforcement and exclusions at the resolver +31/-0

Test trust enforcement and exclusions at the resolver

• Uses a registry package with downgraded trust evidence to verify rejection under no-downgrade and successful resolution with an exclusion or no policy.

pnpm11/installing/env-installer/test/resolveManifestDependencies.test.ts

switchCliVersion.test.tsTest trust-setting forwarding during version switching +31/-0

Test trust-setting forwarding during version switching

• Verifies that the switch path passes all three configured trust settings to package-manager integrity resolution.

pnpm11/pnpm/src/switchCliVersion.test.ts

syncEnvLockfile.test.tsTest trust-setting forwarding when recording a pin +17/-0

Test trust-setting forwarding when recording a pin

• Verifies that lockfile synchronization passes all three trust settings to package-manager integrity resolution.

pnpm11/pnpm/src/syncEnvLockfile.test.ts

Documentation (3) +10 / -0
switch-honors-trust-policy.mdRecord patch releases for pinned-pnpm trust enforcement +6/-0

Record patch releases for pinned-pnpm trust enforcement

• Adds patch changesets for pnpm and the environment installer. Explains that downgraded trust evidence blocks a pinned version before switching or lockfile recording.

.changeset/switch-honors-trust-policy.md

dependency-resolution.mdDocument trust checks for pinned pnpm in current docs +2/-0

Document trust checks for pinned pnpm in current docs

• Clarifies that the existing trust policy check also covers versions pinned through either package-manager manifest field.

pnpm/docs/settings/dependency-resolution.md

dependency-resolution.mdDocument pinned-pnpm trust checks for v11 +2/-0

Document pinned-pnpm trust checks for v11

• Explains that a trust downgrade prevents v11 from switching to or recording a pinned pnpm version.

pnpm11/docs/settings/dependency-resolution.md

@qodo-code-review

qodo-code-review Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (1) 🔗 Cross-repo conflicts (0) 📜 Skill insights (1)

Grey Divider


Action required

1. Locked pnpm versions skip trust checks ✗ Dismissed
Description
resolveIntegrities passes the trust settings to the resolver, but recordPin returns before
calling it when the env lockfile already has complete entries for the pinned version. If a project
enables trustPolicy: no-downgrade after recording a downgraded version without that policy,
switching can use the recorded version without evaluating its trust evidence.
Code

pnpm11/pnpm/src/switchCliVersion.ts[151]

+    ...packageManagerTrustPolicy(versionSwitch.config),
Relevance

●●● Strong

Accepted precedents require trust-policy inputs on fast paths and stronger trust metadata coverage.

PR-#13464
PR-#12838

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The new switch-path forwarding is reached only if resolution runs. The switch's existing-entry check
returns first, while the resolver's own cached and frozen-lockfile paths also return before the
manifest resolution that applies the newly forwarded settings.

pnpm11/pnpm/src/switchCliVersion.ts[105-120]
pnpm11/installing/env-installer/src/resolvePackageManagerIntegrities.ts[142-160]
pnpm11/installing/env-installer/src/resolveManifestDependencies.ts[92-99]

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

## Issue description
An existing package-manager lockfile entry can bypass the newly applied trust policy because the switch returns before reaching the resolver.
## Fix Focus Areas
- pnpm11/pnpm/src/switchCliVersion.ts[105-120]
- pnpm11/installing/env-installer/src/resolvePackageManagerIntegrities.ts[142-160]
## Recommended Fix
Make cached package-manager entries eligible for reuse under a trust policy only when their trust validation is current for that policy. Track the relevant validation settings or use another targeted revalidation mechanism, while retaining a fast path for entries already checked under unchanged settings.

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



Informational

2. CLI wiring lacks end-to-end coverage 📜 Skill insight ▣ Testability
Description
The new regression tests invoke switchCliVersion and syncEnvLockfile directly and assert mocked
resolvePackageManagerIntegrities calls instead of running the CLI. Because the fix propagates
project settings through CLI command wiring, a dispatch, command, or real process path could still
omit the settings while these helper-level tests pass.
Code

pnpm11/pnpm/src/switchCliVersion.test.ts[R196-216]

+  await expect(switchCliVersion({
+    registriesByScope: { default: 'https://registry.npmjs.org/' },
+    trustPolicy: 'no-downgrade',
+    trustPolicyExclude: ['[email protected]'],
+    trustPolicyIgnoreAfter: 1440,
+    virtualStoreDirMaxLength: 120,
+  } as unknown as Config, {
+    rootProjectManifestDir: '/repo',
+    wantedPackageManager: {
+      fromDevEngines: true,
+      name: 'pnpm',
+      onFail: 'download',
+      version: '9.3.0',
+    },
+  } as unknown as ConfigContext)).rejects.toThrow('exit 0')
+
+  expect(resolvePackageManagerIntegrities).toHaveBeenCalledWith('9.3.0', expect.objectContaining({
+    trustPolicy: 'no-downgrade',
+    trustPolicyExclude: ['[email protected]'],
+    trustPolicyIgnoreAfter: 1440,
+  }))
Relevance

● Weak

Similar direct-helper-to-CLI coverage request was rejected in #11306; current tests target the
forwarding contract.

PR-#11306

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The checklist requires CLI wiring changes involving configuration propagation to include a test that
invokes the real CLI path. The added tests call switchCliVersion and syncEnvLockfile directly
and verify mocked resolver arguments, while no changed test invokes the CLI dispatch or command
process.

pnpm11/pnpm/src/switchCliVersion.test.ts[190-216]
pnpm11/pnpm/src/syncEnvLockfile.test.ts[170-184]
Skill: review-code

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 trust-policy propagation fix is covered only through direct calls to internal helpers and mocked resolver assertions. This does not verify that the real pnpm CLI path forwards the project trust settings when switching to or recording a pinned pnpm version.

## Fix Focus Areas
- pnpm11/pnpm/src/switchCliVersion.test.ts[190-219]
- pnpm11/pnpm/src/syncEnvLockfile.test.ts[170-185]

## Recommended Fix
Add at least one test that invokes the real pnpm CLI with a project pin and trust-policy configuration, then assert the resulting trust-policy behavior. Keep the existing unit tests for precise propagation assertions, but use the CLI test to cover command dispatch and configuration wiring.

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

Dismiss ↗ | View ↗


3. Trust-policy tests omit trailing commas 📘 Rule violation ⚙ Maintainability
Description
The new trust-policy tests pass multi-line argument lists without a trailing comma at the final
argument in switchCliVersion.test.ts:210 and syncEnvLockfile.test.ts:185. These call sites
remain valid but violate the TypeScript formatting contract and make later diffs noisier.
Code

pnpm11/pnpm/src/switchCliVersion.test.ts[210]

+  } as unknown as ConfigContext)).rejects.toThrow('exit 0')
Relevance

● Weak

Exact trailing-comma formatting request on multiline TypeScript calls was rejected in #15547.

PR-#15547

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The changed tests contain multi-line function argument lists whose final arguments do not have
trailing commas, while the checklist requires trailing commas for multi-line TypeScript argument
lists.

Rule 713434: Require trailing commas in TypeScript collections and multi-line constructs
pnpm11/pnpm/src/switchCliVersion.test.ts[196-210]
pnpm11/pnpm/src/syncEnvLockfile.test.ts[172-185]

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 new multi-line TypeScript call in the trust-policy regression test omits the required trailing comma after its final argument, and the corresponding sync test has the same formatting issue.

## Fix Focus Areas
- pnpm11/pnpm/src/switchCliVersion.test.ts[196-210]
- pnpm11/pnpm/src/syncEnvLockfile.test.ts[172-185]

## Recommended Fix
Add trailing commas to the final arguments of both multi-line function calls, preserving the existing test behavior.

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

Dismiss ↗ | View ↗


Grey Divider

Context sources
❌ Tickets: failed to load — Ticket collection could not establish complete evidence
✅ Compliance rules (platform): 66 rules
✅ Cross-repo context — repo relationships
  Explored: repo: pnpm/update (sha: 2457663d) — View relationship
  Explored: repo: pnpm/setup (sha: a0881977) — View relationship
  Explored: repo: pnpm/pnpm.io (sha: e5b39ba5) — View relationship
Review mode: Auto: ⚖️ Balanced: Security-sensitive trust-policy behavior warrants a complete single-pass review.

Grey Divider

Tip of the day
💡 Did you know, you can see how risky a PR is at a glance with blast radius labels

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Comment thread pnpm11/pnpm/src/switchCliVersion.ts Resolved
@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 added the reviewed: coderabbit CodeRabbit submitted an approving review label Oct 17, 2026
@zkochan
zkochan merged commit 94d5ca6 into main Oct 17, 2026
43 checks passed
@zkochan
zkochan deleted the switch-trust-policy branch October 17, 2026 13:00
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Pull request is closed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

2 participants