Skip to content

fix: skip latest/SHASUMS256.txt check for full semver installs and warn on stale mirror#1337

Open
abaschen wants to merge 1 commit intocoreybutler:masterfrom
abaschen:fix/mirror-shasum-stale
Open

fix: skip latest/SHASUMS256.txt check for full semver installs and warn on stale mirror#1337
abaschen wants to merge 1 commit intocoreybutler:masterfrom
abaschen:fix/mirror-shasum-stale

Conversation

@abaschen
Copy link
Copy Markdown

Fixes #1336

Problem

When using nvm install behind a mirror (nvm node_mirror <url>), the latest/SHASUMS256.txt file may be stale (cached behind the real Node.js distribution), causing two issues:

  1. Full semver installs blocked: nvm install 22.16.0 unnecessarily fetches latest/SHASUMS256.txt and blocks with "not yet released" when the mirror is stale, even though the version exists in index.json.
  2. Silent stale latest: nvm install latest silently installs the stale version with no warning.

Changes

  • src/semver/semver.go: Add IsFullSemver() to detect full major.minor.patch version strings
  • src/nvm.go:
    • Add isUsingMirror() helper to centralize mirror detection
    • Skip checkVersionExceedsLatest() for full semver installs — validate against index.json directly
    • When checkVersionExceedsLatest() would block and a mirror is configured, cross-validate against index.json: if the version exists, warn about the stale mirror and allow installation
    • When getLatest() resolves from a stale mirror, warn that the mirror's latest differs from index.json

Correctness Properties Validated

Property Description Status
P1: Bug Condition Full semver installs skip checkVersionExceedsLatest() PASS
P2: Bug Condition Stale mirror warns instead of blocking when version exists in index PASS
P3: Bug Condition getLatest() warns when mirror is stale PASS
P4: Preservation Official distribution behavior unchanged (no mirror) PASS
P5: Preservation Non-existent versions still rejected PASS
P6: Preservation Already-installed versions still detected PASS

Tests

Added src/nvm_test/ standalone test module (the main package has Windows-only deps) with property-based tests (testing/quick) and table-driven tests covering all properties above.

…rn on stale mirror

When using nvm install behind a mirror, the latest/SHASUMS256.txt file may be
stale (cached behind the real Node.js distribution), causing valid installs to
be incorrectly blocked with a misleading 'not yet released' error.

Changes:
- Add semver.IsFullSemver() to detect full major.minor.patch version strings
- Skip checkVersionExceedsLatest() for full semver installs; validate against
  index.json directly via node.IsVersionAvailable()
- Add isUsingMirror() helper to centralize mirror detection logic
- When checkVersionExceedsLatest() would block and a mirror is configured,
  cross-validate against index.json: if the version exists, warn about the
  stale mirror and allow installation instead of blocking
- When getLatest() resolves a version from a stale mirror, warn that the
  mirror's latest/ differs from index.json

Includes property-based tests (testing/quick) and table-driven tests covering:
- Bug condition exploration (stale mirror blocking, full semver bypass)
- Preservation properties (official dist unchanged, non-existent version
  rejection, already-installed detection)

Fixes coreybutler#1336
@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 45 days with no activity.

@github-actions github-actions Bot added the Stale Stale label Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stale Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nvm install behind mirror: stale SHASUMS256.txt blocks valid installs and no warning for stale latest/

1 participant