Repository navigation
fix(self-update): discard an installed pnpm that cannot run - #13076
Conversation
A self-update that installs a working pnpm and one that installs a broken one were indistinguishable. Installing `@pnpm/[email protected]` printed "Successfully updated pnpm to v11.13.0", exited 0, and left the user with no working pnpm at all: its platform package shipped without a native, so setup.js kept the tarball's placeholder bin, and nothing between the download and the relink of PNPM_HOME ever executed the result. Run the installed CLI before the caller makes it active. The install already happens in a throwaway directory and the relink is downstream, so failing here keeps the version that was working and removes the directory rather than needing to restore anything. This is what deno's check_exe and rustup's self-update do — they run the downloaded binary and refuse to replace the current one if it does not start. Only that it runs is asserted, not what it prints: matching --version output exactly would fail on anything else a release writes to stdout, and the test fixtures show why — one tarball stands in for several mocked versions. pacquet gets the same check for native engines, which is the whole set that can install yet fail to execute: the legacy JS engine has no binary of its own to be missing, and running it would mean locating a Node.js first. A release that installs but cannot run still reaches users; this only stops it from taking their working pnpm with it. Rejecting it before publication is #13072.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthrough
ChangesSelf-update verification
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant SelfUpdate as pnpm self-update
participant InstallDir as New install directory
participant Pnpm as Installed pnpm
participant Active as Active pnpm
SelfUpdate->>InstallDir: install and link target version
SelfUpdate->>Pnpm: run pnpm --version
Pnpm-->>SelfUpdate: success or execution failure
alt executable succeeds
SelfUpdate->>Active: activate installed version
else executable fails
SelfUpdate->>InstallDir: discard failed installation
SelfUpdate-->>Active: keep current active version
end
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
PR Summary by QodoSelf-update: verify installed pnpm executable before activation
AI Description
Diagram
High-Level Assessment
Files changed (7)
|
There was a problem hiding this comment.
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/engine/pm/commands/src/self-updater/installPnpm.ts`:
- Around line 274-276: Update the failure-reason construction in the installPnpm
process handling so a null status, indicating signal termination, produces “a
signal” instead of “it exited with code null”; preserve the existing
error-message and non-null exit-code behavior, and mirror the same user-visible
handling in the corresponding Rust pacquet implementation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: aa2819b6-7c3c-4ad8-954e-595032ede405
📒 Files selected for processing (7)
.changeset/self-update-verify-installed-pnpm.mdpnpm/crates/cli/src/cli_args/self_update.rspnpm/crates/cli/src/cli_args/self_update/install_pnpm.rspnpm/crates/cli/src/cli_args/self_update/tests.rspnpm11/engine/pm/commands/src/index.tspnpm11/engine/pm/commands/src/self-updater/installPnpm.tspnpm11/engine/pm/commands/test/self-updater/selfUpdate.test.ts
Micro-Benchmark ResultsLinux |
Confidence Score: 5/5Safe to merge — the new guards only run before the global bin is relinked, so a failure leaves the previously-working pnpm untouched. Cleanup on error was already in place; this PR only adds a check before the commit point. Both stacks receive the same two guards, error codes match, and the verify-before-commit placement means a check failure is strictly non-destructive. One structural difference exists between the TypeScript and Rust implementations (TS runs the spawn check for all package types; Rust gates it on native binaries), but it produces no false failures in practice. Test coverage is thorough on both sides. pnpm11/engine/pm/commands/src/self-updater/installPnpm.ts — the unconditional Reviews (7): Last reviewed commit: "docs(self-update): cut the prose down to..." | Re-trigger Greptile |
Code Review by Qodo
1.
|
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #13076 +/- ##
==========================================
- Coverage 85.54% 85.54% -0.01%
==========================================
Files 499 499
Lines 79844 79884 +40
==========================================
+ Hits 68304 68336 +32
- Misses 11540 11548 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The TypeScript check read the exit code straight into its message, so an engine killed by a signal — where there is no code — was reported as "it exited with code null". pacquet already says "a signal" for the same case, so the two stacks disagreed on a message. This is not a hypothetical branch: macOS kills a binary whose signature check rejects it, which is exactly the shape a mis-signed release arrives in, and one of the shapes this check exists to catch. Say "a signal", matching pacquet's wording rather than naming it. Node reports the name (SIGKILL) but Rust only has the number, and reaching parity on a named signal would need a unix-only cfg plus a number-to-name table. The new test fails with "it exited with code null" against the previous code. It is POSIX-only: Windows has no real signals, so a killed process still reports an exit code there and the branch is unreachable.
|
Code review by qodo was updated up to the latest commit 6c5eb71 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
The runtime check only guards a fresh install. A slot cached by an earlier pnpm was handed straight back and relinked into the global bin without ever running, so the one case the check exists for — an engine already on disk that cannot execute — could still take out a working installation. Reject the two releases known to be broken by version instead of spawning the cached engine to find out. `@pnpm/exe` 11.12.0 and 11.13.0 published their platform packages with no binary; both are immutable on npm and deprecated there, and neither ships a working binary on any platform, so the version alone settles it. The cache-hit path keeps its current cost: a self-update that is already up to date does not spawn anything. This is not a second safety net. The runtime check still catches a broken release whether or not it is listed; the list only spares the ones already known from having to be discovered at runtime. The resolver already skips deprecated versions when a range or dist-tag leaves it a choice, so only an explicit request for one of these reaches here.
|
Code review by qodo was updated up to the latest commit 98f92a5 |
PR Code Suggestions ✨Warning
No code suggestions found for the PR. |
Summary
pnpm self-updatecould not tell a working install from a broken one. Upgrading onto@pnpm/[email protected]printed "Successfully updated pnpm to v11.13.0", exited 0, and left the user with no working pnpm at all — measured against the real registry, before this change:pnpm→ 11.12.0)@pnpm/exe→ 11.13.0)This: command not foundThe crash case already fails safe: the install happens in a throwaway directory and
installPnpmToGlobalDirremoves it on throw, all beforeselfUpdate.tsrelinksPNPM_HOME/bin. The second case is the gap —@pnpm/[email protected]'s platform package shipped without a native,setup.jsexits 0 when the binary is missing, so the tarball's placeholder bin survived and nothing ever executed the result.This runs the installed CLI before the caller makes it active. Because the relink is downstream and the existing
catchalready removes the install dir, a failure keeps the version that was working and needs no restore — verify-then-commit rather than commit-then-revert, so there is no window in which pnpm is broken.Prior art. This is what the other self-updating toolchains do, and neither goes further:
check_exe()runs the downloaded binary with-Vandbail!s ("Failed to validate Deno executable...") before replacing the current one.get_new_rustup_version()doesCommand::new(path).arg("--version")on the downloaded binary.Only that it runs is asserted, not what it prints. Matching
--versionoutput exactly would fail on anything else a release writes to stdout — and this repo's own fixtures show why:selfUpdate.test.tsserves onepnpm-9.1.0.tgzfor several mocked versions, so a strict check failed two legitimate downgrade tests.A deeper "install a dependency and check it landed" test was considered and deliberately placed in the tag gate (#13072) instead: it would have caught no bug we have actually had (11.12.0's own binary runs fine — the fault is in the driver resolving its manifest), while adding a network dependency inside self-update where a registry blip would fail a good upgrade.
Parity
pacquet gets the same check, for native engines — which is the whole set that can install yet fail to execute. The legacy JS engine has no binary of its own to be missing, and running it would mean locating a Node.js first. Same
ERR_PNPM_BROKEN_PNPM_INSTALLcode and message on both stacks.Verification
installPnpm— real tarball fetch, real headless install, real bin linking, real spawn — and asserts both the rejection and that the half-installed directory is removed. Confirmed it catches a regression: withassertPnpmRunscommented out it fails with "Received promise resolved instead of rejected".This file intentionally left blank) that@pnpm/exeships when its platform package carries no native.This does not stop a broken release from reaching users — it stops one from taking their working pnpm with it. Rejecting it before publication is #13072.
Squash Commit Body
Checklist
pnpm/port, or the description notes what still needs porting.pnpm changeset) if this PR changes any publishedpackage. Keep it short and written for pnpm users — it becomes a release note.
Written by an agent (Claude Code, claude-opus-4-8).
Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Summary by CodeRabbit
Bug Fixes
pnpm self-updatenow verifies the downloaded pnpm executable starts successfully before switching the active version.Tests