Skip to content

feat(detector): implement Volta detection with mocked tests#3

Merged
dipto0321 merged 1 commit into
mainfrom
feat/detector/implement-volta
Jun 29, 2026
Merged

feat(detector): implement Volta detection with mocked tests#3
dipto0321 merged 1 commit into
mainfrom
feat/detector/implement-volta

Conversation

@dipto0321

Copy link
Copy Markdown
Owner

Summary

Phase 1 manager 3/8: Volta detection. Volta is a real binary at
$VOLTA_HOME/bin/volta (or on PATH) that stores fully-resolved Node
installs on disk under $VOLTA_HOME/tools/image/node/vX.Y.Z/.

What this PR does

Implements the Phase 1 detection surface for the volta manager:

Method Strategy Subprocess?
Detect() PATH lookup via platform.LookupManagerBinary OR <voltaHome>/bin/volta exists on disk No
Version() volta --version via runShell, parsed to drop the leading volta if present Yes
ListInstalled() Read <voltaHome>/tools/image/node/* directory entries, skip non-dirs and unparseable names No

Mutation methods (Install, Uninstall, Use, SetDefault,
GlobalNpmPrefix) return a new ErrVoltaNotImplemented sentinel.

Reuses the package-level seams already declared elsewhere:

  • runShell (declared in fnm.go) — Volta's volta --version is a
    binary invocation, same shape as FNM.
  • listDir (declared in nvm.go) — Volta's installed list comes from
    reading a fixed directory structure, same shape as NVM.

Why this design

  • Hybrid Detect mirrors how Volta actually ships: installed via the
    Volta installer it lives at $VOLTA_HOME/bin/volta; installed via
    Homebrew it lives somewhere on $PATH. Either signal is enough.
  • Direct disk read for ListInstalled is faster and more
    deterministic than shelling out — and is what Volta itself does
    internally.
  • No system sentinel like NVM has. Volta only contains real
    installs.

Notes

  • Volta is in maintenance mode (last release v2.0.2 on 2024-12-05,
    README recommends migrating to mise). nodeup still supports it
    because many users haven't migrated yet.
  • Skipped the live probe — the user doesn't have Volta installed and
    didn't want test managers installed (see feat(detector): implement NVM detection with mocked tests #2's PR body for the
    precedent). Coverage rests on the 29 mocked tests.

Tests

29 new tests in internal/detector/volta_test.go, all PASS:

  • 5 parseVoltaVersion cases (standard, bare, whitespace, empty, ws-only)
  • 5 parseVoltaInstalledEntries cases (happy, no-v-prefix, non-dirs,
    unparseable, empty)
  • 5 Version cases (success, bare-version, runShell-error, parse-error,
    sub-cases)
  • 3 Detect cases (no PATH no home, finds-binary, honors VOLTA_HOME)
  • 5 ListInstalled cases (success, no-image-dir, list-dir-error, reads
    the expected path, no-mutation)
  • 2 helper tests (voltaHome env-override + whitespace, voltaBinaryPath)
  • 1 mutation-stub check
  • 1 Detect-doesn't-invoke-runShell guard

Full package: 79 tests (21 FNM + 23 NVM + 29 Volta + 5 registry + 1
Volta-home override). All PASS with -race.

Checklist

Closes nothing by itself; advances Phase 1 (detector engine) in
nodeup.md.

Phase 1 manager 3/8. Volta is a true binary at /bin/volta (or on
PATH) that stores Node installs under $VOLTA_HOME/tools/image/node/.
Detect uses two OR'd checks (PATH + on-disk existence); Version
wraps volta --version; ListInstalled reads the image directory
entries, skipping non-dirs and unparseable names.

The homeDir seam isolates Volta path resolution from the developer's
real $HOME/%USERPROFILE%, which is critical on Windows where
os.UserHomeDir reads %USERPROFILE% and ignores $HOME. Without the
seam, t.Setenv("HOME", ...) can't redirect Detect on Windows.

Mutation methods return ErrVoltaNotImplemented.
@dipto0321 dipto0321 force-pushed the feat/detector/implement-volta branch from e263562 to e971b68 Compare June 29, 2026 10:09
@cocogitto-bot

cocogitto-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

✔️ e971b68 - Conventional commits check succeeded.

@dipto0321 dipto0321 merged commit bd87abe into main Jun 29, 2026
10 checks passed
@dipto0321 dipto0321 deleted the feat/detector/implement-volta branch June 29, 2026 10:18
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.

1 participant