Repository navigation
feat(pacquet-cli): port the self-update command - #12693
Conversation
|
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:
📝 WalkthroughWalkthroughAdds a ChangesSelf-update command
Sequence Diagram(s)sequenceDiagram
participant CliArgsRun
participant SelfUpdateRun
participant ResolvePnpmVersion
participant Handler
participant VerifyEngine
participant InstallPnpm
participant GlobalBin
CliArgsRun->>ResolvePnpmVersion: resolve pnpm target version
CliArgsRun->>SelfUpdateRun: CliCommand::SelfUpdate
SelfUpdateRun->>Handler: run with config and dir
alt project pin exists
Handler->>Handler: update_project_pin
else global update
Handler->>VerifyEngine: verify engine identity
Handler->>InstallPnpm: install pnpm
Handler->>GlobalBin: link binaries and hash-link
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~75 minutes Possibly related issues
Possibly related PRs
Suggested labels
✨ 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 Qodofeat(pacquet-cli): port pnpm-style self-update with policy checks and engine verification Description
Diagram
High-Level Assessment
Files changed (7)
|
Code Review by Qodo
1. Overrides taint self-update
|
There was a problem hiding this comment.
Actionable comments posted: 8
🤖 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 `@pacquet/crates/cli/src/cli_args.rs`:
- Around line 1058-1060: The SelfUpdate dispatch path in CliCommand::SelfUpdate
currently calls config() before checking Corepack, which can surface config
errors instead of the intended Corepack refusal. Reorder the logic in this arm
so the Corepack guard is evaluated first, before loading project config, and
ensure it returns the same ERR_PNPM_CANT_SELF_UPDATE_IN_COREPACK behavior as
handler and the self-update contract require.
In `@pacquet/crates/cli/src/cli_args/self_update.rs`:
- Around line 145-149: Use the resolved project pin when computing
`previous_version` in `self_update.rs` so major-upgrade detection works for
range pins like `^10.0.0`. Update the `match &wanted` logic to reuse
`read_project_pinned_pnpm_version` (instead of relying only on
`pm.version`/`coerce_major`) so the exact env-lockfile version is available, and
then compare that resolved version against `target_version` in the same
`previous_version` flow.
- Around line 441-445: The range_satisfies helper currently rejects prerelease
versions like 1.2.3-beta.1 even when the stripped base version 1.2.3 would
satisfy the range. Update range_satisfies in self_update.rs to detect prerelease
targets, retry the check with the base version, and use that fallback when
node_semver::Range::satisfies fails on the prerelease form.
In `@pacquet/crates/cli/src/cli_args/self_update/install_pnpm.rs`:
- Around line 77-78: The self-update flow is reporting success even when the
native wrapper link step fails, so `install_pnpm()` should surface any failure
from `link_exe_platform_binary()` instead of continuing. Update the
`install_pnpm` path and the related wrapper-linking logic in
`link_exe_platform_binary` so missing platform packages, hardlink failures, or
other early returns become errors that abort the install. Make sure the same
failure handling is applied to the other wrapper-linking call sites referenced
by this flow so `InstallPnpmResult` is only returned after a runnable native
`pnpm` binary is actually installed.
In `@pacquet/crates/cli/src/cli_args/self_update/install_pnpm/tests.rs`:
- Around line 3-21: The existing tests only validate the platform directory name
helpers, but they do not cover the filesystem behavior introduced by
link_exe_platform_binary() and rewrite_windows_bin_field(). Add TempDir-based
regression tests that exercise hardlinking the wrapper binary, alias creation,
and the Windows bin-field rewrite, and assert the installed layout/metadata
matches the expected cross-platform contract. Prefer real fixture-style coverage
in the test module so the behavior is proven end-to-end rather than only by
helper function outputs.
In `@pacquet/crates/cli/src/cli_args/self_update/verify_engine.rs`:
- Around line 77-514: Add regression coverage for the trust-decision flow in
verify_pnpm_engine_identity and its helpers. Create tests that prove signature
acceptance, expired-key rejection, malformed signatures metadata, and
unreachable-vs-mismatch classification, exercising find_signature_failure,
signature_validates, and fetch_packument behavior. Keep the tests aligned with
pnpm-parity expectations and fail-closed behavior so the self-update gate is
covered end to end.
- Around line 82-86: Remove the runtime environment-variable bypass from
verify_engine::verify_engine so engine signature verification cannot be disabled
in non-test builds. Move the PACQUET_SELF_UPDATE_SKIP_ENGINE_VERIFY_FOR_TESTS
seam behind cfg(test) or route it through the test harness only, and keep the
normal trust check path in place for all production calls. Use the existing
verify_engine function and its early-return branch as the fix location.
In `@pacquet/crates/cli/src/config_deps.rs`:
- Around line 99-102: The maturity cutoff computation in `config_deps.rs`
currently falls back to `None` via `resolved_minimum_release_age`/`published_by`
when conversion or date arithmetic fails, which disables the gate. Update the
logic around `resolved_minimum_release_age`, `try_minutes`, and
`Utc::now().checked_sub_signed` so failures return an error instead of silently
producing `None`, ensuring `minimumReleaseAge`-based self-update checks fail
closed.
🪄 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: c563dc0e-dab2-4879-bb0a-ea8a1a94ef96
📒 Files selected for processing (7)
pacquet/crates/cli/src/cli_args.rspacquet/crates/cli/src/cli_args/self_update.rspacquet/crates/cli/src/cli_args/self_update/install_pnpm.rspacquet/crates/cli/src/cli_args/self_update/install_pnpm/tests.rspacquet/crates/cli/src/cli_args/self_update/tests.rspacquet/crates/cli/src/cli_args/self_update/verify_engine.rspacquet/crates/cli/src/config_deps.rs
|
Code review by qodo was updated up to the latest commit 90f686a |
90f686a to
2344563
Compare
There was a problem hiding this comment.
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 `@pacquet/crates/cli/src/cli_args/self_update/tests.rs`:
- Line 25: The self-update test comment contains a misspelled word; update the
comment in the self_update tests so it uses “Unparsable” instead of
“Unparseable” to satisfy the spell-check rule. Locate the affected comment near
the self_update test case in tests.rs and make only the wording correction.
In `@pacquet/crates/cli/src/cli_args/self_update/verify_engine.rs`:
- Around line 152-183: The self-update verification flow in verify_components is
failing open when the host platform binary for `@pnpm/exe` cannot be resolved from
the snapshot or optional_dependencies, allowing verification to succeed after
only checking pnpm and `@pnpm/exe`. Update the logic around engine_component,
plain_version, and the candidate_names loop so that missing/unparseable snapshot
data, absent optional deps, or no matching host package cause verification to
fail closed instead of returning Ok(to_verify); treat the host package as
required whenever `@pnpm/exe` is present.
🪄 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: 7ba4d676-ac50-4b5b-9ec9-777ee6ba0b09
📒 Files selected for processing (7)
pacquet/crates/cli/src/cli_args.rspacquet/crates/cli/src/cli_args/self_update.rspacquet/crates/cli/src/cli_args/self_update/install_pnpm.rspacquet/crates/cli/src/cli_args/self_update/install_pnpm/tests.rspacquet/crates/cli/src/cli_args/self_update/tests.rspacquet/crates/cli/src/cli_args/self_update/verify_engine.rspacquet/crates/cli/src/config_deps.rs
🚧 Files skipped from review as they are similar to previous changes (5)
- pacquet/crates/cli/src/cli_args.rs
- pacquet/crates/cli/src/config_deps.rs
- pacquet/crates/cli/src/cli_args/self_update/install_pnpm/tests.rs
- pacquet/crates/cli/src/cli_args/self_update.rs
- pacquet/crates/cli/src/cli_args/self_update/install_pnpm.rs
Micro-Benchmark ResultsLinux |
|
Code review by qodo was updated up to the latest commit 2344563 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 2344563 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #12693 +/- ##
==========================================
- Coverage 86.96% 85.88% -1.08%
==========================================
Files 382 385 +3
Lines 58161 59044 +883
==========================================
+ Hits 50577 50708 +131
- Misses 7584 8336 +752 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code review by qodo was updated up to the latest commit 640b0db |
|
Code review by qodo was updated up to the latest commit eb790e7 |
|
Code review by qodo was updated up to the latest commit 8be8ae7 |
1 similar comment
|
Code review by qodo was updated up to the latest commit 8be8ae7 |
Ports pnpm's `self-update` command to the Rust pacquet CLI, matching the TypeScript implementation in pnpm11/engine/pm/commands/src/self-updater. The pnpm side already has this command, so this is the pacquet port — no TypeScript change is needed. `pacquet self-update [VERSION]` resolves the target version from the trusted package-manager bootstrap registry (never the repo-controlled project registries), honoring minimumReleaseAge / trustPolicy with strict resolution failing closed. It guards against corepack (before loading project config), refuses to downgrade on an implicit `latest`, prints the already-up-to-date / downgrade no-op messages, and emits the major-upgrade migration hint (using the resolved env-lockfile version so range pins still trigger it). When the project pins pnpm via packageManager / devEngines.packageManager, the pin is updated in place (range-style preserved, integrities persisted). Otherwise the engine is installed into the global packages directory through the bootstrap config: integrities are resolved into the env lockfile, the engine's npm registry signature is verified against npm's embedded public keys (failing closed, including when the host platform binary can't be collected), the host's native platform binary is hard-linked into the wrapper (the preinstall is skipped because the engine installs with scripts disabled; link failures are propagated), and the bins are linked into the global bin directory with a bootstrap-registry cache-keyed hash symlink. New modules under cli_args/self_update: install_pnpm (installPnpm + linkExePlatformBinary) and verify_engine (verifyPnpmEngineIdentity). config_deps gains resolve_pnpm_version, the policy-aware version probe, which fails closed if the specifier resolves to a package other than pnpm. The shared packageManager helpers move to pub(crate) so the new module can reuse them. Unit tests cover platform dir-name parity, version-constraint preservation, semver comparison, signature accept/expiry/unknown-key rejection, and platform-binary linking.
8be8ae7 to
7b28a19
Compare
|
Code review by qodo was updated up to the latest commit 7b28a19 |
|
Code review by qodo was updated up to the latest commit 7b28a19 |
…ile from the workspace root Address the latest review findings: - run_install now clears repo-controlled resolution-rewrite settings (overrides, packageExtensions, catalogs, patchedDependencies) before installing the engine, so a project's pnpm-workspace.yaml can't change the installed engine's dependency closure even though the top-level engine components are signature-verified. - read_project_pinned_pnpm_version now reads the env lockfile from the workspace root (config.workspace_dir, falling back to --dir) instead of the command's working directory, so a workspace self-update invoked from a package subdirectory still sees the pinned pnpm version (preserving the implicit-latest downgrade refusal and the major-upgrade hint).
|
Code review by qodo was updated up to the latest commit 1967227 |
|
Code review by qodo was updated up to the latest commit 1967227 |
Summary
Ports pnpm's
self-updatecommand to the RustpacquetCLI, matching the TypeScript implementation inpnpm11/engine/pm/commands/src/self-updater. The pnpm side already has this command, so this is the pacquet side catching up — no TypeScript change is needed.pacquet self-update [VERSION]:minimumReleaseAge/trustPolicy; strict resolution fails closed on a policy violation (mirrorsmakeResolutionStrict).latest(explicitself-update latestforces it), prints the already-up-to-date / downgrade no-op messages, and emits the major-upgrade migration hint.packageManager/devEngines.packageManager, updates the pin in place — preserving the range-operator style and persisting integrities — instead of touching the global install.@pnpm/exe.<target>binary into the wrapper, and links the bins into the global bin dir with a cache-keyed hash symlink.New modules under
crates/cli/src/cli_args/self_update:install_pnpm— portsinstallPnpm+linkExePlatformBinary(legacy<os>-<arch>andexe.<platform>-<arch>[-musl]schemes; Windows alias hardlinks +bin-field rewrite).verify_engine— portsverifyPnpmEngineIdentity(embedded npm keys, ECDSA-P256 overname@version:integrity, fail-closed on tamper / unreachable registry).config_depsgainsresolve_pnpm_version, the policy-aware version probe reusing the existing bootstrap-registry resolver.Error codes mirror pnpm's
PnpmErrorcodes (ERR_PNPM_CANT_SELF_UPDATE_IN_COREPACK,ERR_PNPM_CANNOT_RESOLVE_PNPM,ERR_PNPM_PNPM_ENGINE_IDENTITY_UNVERIFIABLE/_MISMATCH,ERR_PNPM_NO_GLOBAL_BIN_DIR).Squash Commit Body
Checklist
pacquet/port, or the description notes what still needs porting.(TypeScript side already exists; this is the pacquet port.)
pnpm changeset) if this PR changes any publishedpackage. (Not applicable — Rust-only change; changesets version the
TypeScript workspace.)
version-constraint preservation, and semver comparison. An end-to-end
install+verify integration test still needs the mock registry to serve
pnpm/@pnpm/exe.<target>with valid signatures — flagged as afollow-up.)
self-updatedocs already cover the command.)Written by an agent (Claude Code, claude-opus-4-8).
Summary by CodeRabbit
pnpmself-update CLI command to upgrade a project-pinned pnpm (updating the pin when present) or install/link a verified global pnpm when not pinned, including major-upgrade migration hints.