feat(detector): implement Volta detection with mocked tests#3
Merged
Conversation
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.
e263562 to
e971b68
Compare
|
✔️ e971b68 - Conventional commits check succeeded. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 1 manager 3/8: Volta detection. Volta is a real binary at
$VOLTA_HOME/bin/volta(or onPATH) that stores fully-resolved Nodeinstalls on disk under
$VOLTA_HOME/tools/image/node/vX.Y.Z/.What this PR does
Implements the Phase 1 detection surface for the
voltamanager:Detect()PATHlookup viaplatform.LookupManagerBinaryOR<voltaHome>/bin/voltaexists on diskVersion()volta --versionviarunShell, parsed to drop the leadingvoltaif presentListInstalled()<voltaHome>/tools/image/node/*directory entries, skip non-dirs and unparseable namesMutation methods (
Install,Uninstall,Use,SetDefault,GlobalNpmPrefix) return a newErrVoltaNotImplementedsentinel.Reuses the package-level seams already declared elsewhere:
runShell(declared infnm.go) — Volta'svolta --versionis abinary invocation, same shape as FNM.
listDir(declared innvm.go) — Volta's installed list comes fromreading a fixed directory structure, same shape as NVM.
Why this design
Volta installer it lives at
$VOLTA_HOME/bin/volta; installed viaHomebrew it lives somewhere on
$PATH. Either signal is enough.ListInstalledis faster and moredeterministic than shelling out — and is what Volta itself does
internally.
systemsentinel like NVM has. Volta only contains realinstalls.
Notes
README recommends migrating to mise). nodeup still supports it
because many users haven't migrated yet.
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:parseVoltaVersioncases (standard, bare, whitespace, empty, ws-only)parseVoltaInstalledEntriescases (happy, no-v-prefix, non-dirs,unparseable, empty)
Versioncases (success, bare-version, runShell-error, parse-error,sub-cases)
Detectcases (no PATH no home, finds-binary, honorsVOLTA_HOME)ListInstalledcases (success, no-image-dir, list-dir-error, readsthe expected path, no-mutation)
voltaHomeenv-override + whitespace,voltaBinaryPath)Full package: 79 tests (21 FNM + 23 NVM + 29 Volta + 5 registry + 1
Volta-home override). All PASS with
-race.Checklist
go test -race ./...greengolangci-lint run ./internal/detector/...cleanfeat/detector/implement-voltaCloses nothing by itself; advances Phase 1 (detector engine) in
nodeup.md.