Skip to content

fix(cli): replay snapshot from latest-installed version, not new version#77

Merged
dipto0321 merged 1 commit into
mainfrom
fix/packages/snapshot-restore-version-key-mismatch
Jul 3, 2026
Merged

fix(cli): replay snapshot from latest-installed version, not new version#77
dipto0321 merged 1 commit into
mainfrom
fix/packages/snapshot-restore-version-key-mismatch

Conversation

@dipto0321

Copy link
Copy Markdown
Owner

Summary

The upgrade loop's restore step was looking up its snapshot by the new installed Node version, but snapshots are written for the previously installed versions. The lookup missed every time, the wrapped read snapshot: open …: no such file or directory error was swallowed behind cmd.Printf("Warning: …"), and the package migration silently no-op'd for every new install. The fix resolves the snapshot path the same way the sentinel block already does (latest-installed-version key) and replays via packages.RestoreFromSnapshot(ctx, restoreSnapshotPath) — globals now carry forward to the new default exactly once.

Closes #42.

Linked issues

Type of change

  • fix — bug fix (PATCH bump)

Checklist

  • Title follows Conventional Commits (fix(scope): subject)
  • I ran make ci locally and it passes (fmt, vet, test pass locally; make lint fails on the v2→v1 schema mismatch tracked in build(lint): .golangci.yml v1 schema incompatible with golangci-lint v2 (brew installs v2, make lint fails to even parse config) #62 — pre-existing on main, independent of this fix; CI runs golangci-lint v1.64.8 per .github/workflows/ci.yml and will parse the config fine)
  • I added or updated tests for the change
  • I updated relevant docs (README, docs/, inline godoc)
  • No new linter warnings
  • If breaking: I documented the migration path in the PR body and updated CHANGELOG.md (N/A — no breaking change)

Scope notes

Out of scope (separate issues, deliberately not touched here):

  • lts JSON union bug in internal/node/dist.go — already fixed in PR feat(cli): implement end-to-end upgrade command #20 (merged).
  • Current() failure leaving active Node unprotected from cleanup — separate issue.
  • --yes vs --no-cleanup precedence — separate issue.
  • Sentinel lifecycle bug — separate issue.

Screenshots / output

The user-visible change is: previously, after a nodeup upgrade, the user got an empty new Node with no globals. Now, the upgrade prints no migration output (matches old behaviour on success) but actually installs the carried-forward globals against the freshly-set-default Node. Verification path: npm ls -g --depth=0 after upgrade will now show the same package list as before upgrade, instead of being empty.

`runUpgrade` snapshots each *previously installed* Node version's
global npm packages, then called `packages.Restore(ctx, mgr, *v)`
for each **newly installed** version. Since snapshots are keyed by
`<mgr>-<oldVersion>.json` (e.g., `fnm-20.10.0.json`) and `Restore`
looks up by the exact same key, the restore step read a file that
didn't yet exist (`fnm-20.11.0.json`) — its wrapped "read snapshot:
open …: no such file or directory" was swallowed by the loop's
`cmd.Printf("Warning: …")`, silently no-op'ing the package
migration on every upgrade.

Resolve the snapshot path the same way the sentinel block does
(latest-installed-version key, kept in a single local variable
shared between the sentinel arm and the restore step) and replay
via `packages.RestoreFromSnapshot(ctx, restoreSnapshotPath)`.
The user's global packages now carry forward to the new default
exactly once.

Refs #42

Co-Authored-By: puku-ai-2.8 <noreply@puku.sh>
@cocogitto-bot

cocogitto-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

✔️ cf9c75d - Conventional commits check succeeded.

@dipto0321 dipto0321 merged commit 095946f into main Jul 3, 2026
10 checks passed
@dipto0321 dipto0321 deleted the fix/packages/snapshot-restore-version-key-mismatch branch July 3, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(packages): upgrade snapshot/restore version-key mismatch silently no-ops package migration

1 participant