Skip to content

Fix pnpm trustLockfile env override ignored (#1514) - #1533

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pnpm-trust-lockfile-env
Oct 14, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-pnpm-trust-lockfile-env

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-opus-5-5

Fixes #1514

Summary

On pnpm 11 and 12, a pnpm_config_trust_lockfile (or PNPM_CONFIG_TRUST_LOCKFILE) environment variable takes precedence over the trustLockfile: true that hosted mode writes into pnpm-workspace.yaml. If that variable was false, scan --mode hosted still wrote the key and reported "installs need no extra flags", and then every install in that environment failed with ERR_PNPM_TARBALL_URL_MISMATCH.

The scan now treats a non-true value of that variable as an explicit user setting, the same way it treats trustLockfile: false in the file and the way the npm arm treats npm_config_allow_remote. It writes nothing. The redirect_pnpm_trust_lockfile warning names the variable and gives the remedies: unset it, set it to true wherever the project installs, or re-run with --mode vendored.

Root cause

The trust plan in pnpm_trust (crates/socket-patch-core/src/hosted/engine.rs) chose between write, AlreadyTrue and UserSet by looking only at the text of pnpm-workspace.yaml. It never read the environment that pnpm 11+ reads ahead of that file.

Changes

Test evidence

Issue Regression test Red without fix Green with fix
#1514 hosted::engine::tests::issue_1514_a_trust_lockfile_env_override_is_respected (lowercase and uppercase variable, existing trustLockfile: true, member lock; controls: true, npm spelling, pnpm 10 pin) failed: ["pnpm-lock.yaml", "pnpm-workspace.yaml"] written ok
#1514 utils::pnpm_workspace::tests::the_environment_sets_trust_lockfile_only_for_pnpm_11_and_newer n/a (new API) ok
#1514 e2e e2e_redirect_pnpm_build::pnpm11_trust_lockfile_env_override_is_respected (real pnpm 11.28.5, SOCKET_PATCH_PNPM_E2E_REQUIRED=1) failed: rewrittenFiles: ["pnpm-workspace.yaml"], "installs need no extra flags" ok; control re-run without the variable heals the key

Run locally:

  • cargo fmt --all -- --check: ok
  • cargo clippy --workspace --all-features -- -D warnings: ok
  • cargo test -p socket-patch-core --all-features --lib: 6484 passed. 4 failed, all of them read-only-permission tests (copy_tree::relax_loop_must_not_traverse_symlinked_root, vlt_heal::an_unremovable_hidden_lock_keeps_every_store_entry, pypi_poetry::wire_write_failure_maps_error_and_leaves_lock_untouched, pypi_requirements::wire_failure_rolls_back_already_written_files). They can't fail as root, which is how the sandbox runs, and they are unrelated to this diff.
  • cargo test -p socket-patch-cli --all-features --lib --bins: 920 passed
  • e2e_redirect_pnpm_build -- --ignored pnpm11_: 4 passed
  • The full cargo test --workspace build ran out of sandbox disk while linking the CLI integration binaries. CI covers those.
  • No wrapper (npm/, pypi/, gem/) changes are needed: this is engine-only.

Review findings not fixed (/code-review high)

  • pnpm_config_trust_lockfile=0 coercion. The value is read with the repo's existing env convention (PnpmSetting::as_bool, the npm-config reader: only ''/false/null/undefined are false), the same as every other pnpm env setting here. Changing that convention for one key would make them disagree.
  • Uppercase spelling. Hosted pnpm 11/12 scan ignores a pnpm_config_trust_lockfile=false env override and says "installs need no extra flags", but the next frozen install fails with ERR_PNPM_TARBALL_URL_MISMATCH #1514 verified that PNPM_CONFIG_TRUST_LOCKFILE=false makes pnpm 12.11.2 fail on Linux, so it is honoured.
  • A developer's shell env decides a committed file. This matches the npm npm_config_allow_remote precedent (CLI_CONTRACT), and the warning says plainly that nothing was written and why.
  • Injected env vs std::env in view_setting. The injection keeps the engine testable and lets the in-memory engine opt out. Moving lockfile/gitBranchLockfile onto it is a separate refactor.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Vu8yCCshtPxwd4jscWRAU


Generated by Claude Code

Assisted-by: Claude Code:claude-opus-5-5
pnpm 11 and 12 read pnpm_config_trust_lockfile (or its uppercase
spelling) ahead of pnpm-workspace.yaml. With it set to false, a hosted
scan still wrote trustLockfile: true there and said installs need no
extra flags, so every install in that environment failed with
ERR_PNPM_TARBALL_URL_MISMATCH.

The scan now treats a non-true value of that variable as an explicit
user setting, like trustLockfile: false in the file: on a project whose
pnpm is 11 or newer (or unknown) it writes nothing and the trust warning
names the variable and the remedies (unset it or set it to true for
installs, or use --mode vendored). The in-memory engine sees no
environment and is unchanged.

Fixes #1514

Assisted-by: Claude Code:claude-opus-5-5
Assisted-by: Claude Code:claude-opus-5-5
Review follow-ups for the trustLockfile env override:

- The trust check now reads the project's pnpm major through the same
  helper as the lockfile setting (#1460) instead of a second copy, and
  the env reader reuses the existing variable lookup.
- A project pinned to pnpm 9.0-10.4, or with a keyless workspace file
  that lists members, keeps its more specific guidance; the override
  only replaces the generic write.
- A workspace member scanned with the override set is no longer
  refused with advice to add trustLockfile: true to the root file,
  which the variable would override anyway; the scan pins the member
  lock and its warning names the variable.

Assisted-by: Claude Code:claude-opus-5-5
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review October 14, 2026 13:21
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

BugBot review


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2dc1100. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

Final reviewer: sent to the merge queue (squash). Approved by Tanmay Singla (@Tanmay182003) on the current head 2dc1100, ci-ok and clippy green, no unresolved review threads, no blocking labels.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants