feat(detector): implement FNM detection with mocked tests#1
Merged
Conversation
Replace the FNM stub with a real implementation of the detection
surface of the Manager interface:
- Detect() — cheap PATH probe via platform.LookupManagerBinary
- Version() — wraps `fnm --version`, parses leading "fnm " token
- ListInstalled()— wraps `fnm list`, skips the "system" line and the
"*" default marker, returns a non-nil sorted-asc
[]semver.Version
Mutation methods (Install, Uninstall, Use, SetDefault,
GlobalNpmPrefix) now return the new ErrFNMNotImplemented sentinel
instead of a silent zero value, so callers can use errors.Is to
distinguish "not yet implemented" from "succeeded".
Tests use a package-level runShell var (signature-compatible with
platform.RunShell) that is swapped per-test via withStubShell. The
test-stub pattern intentionally matches what was already established
in detector_test.go for future manager files (nvm, volta, asdf,
mise, n, nodenv, nvm-windows) to follow.
Verified against the local /opt/homebrew/bin/fnm 1.39.0: detected,
version "1.39.0" parsed, installed versions [24.15.0 25.9.0]
returned sorted asc with the "system" line correctly excluded.
badb145 to
077baae
Compare
|
✔️ 077baae - Conventional commits check succeeded. |
This was referenced Jun 29, 2026
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
Replaces the FNM stub in
internal/detector/fnm.gowith a real implementation of the detection surface of theManagerinterface. Mutation methods (Install,Uninstall,Use,SetDefault,GlobalNpmPrefix) now return a newErrFNMNotImplementedsentinel rather than a silent zero value.What's implemented
Detect()platform.LookupManagerBinary("fnm") != ""— zero subprocessesVersion()fnm --version, parses leading"fnm "tokenListInstalled()fnm list, strips"* "default marker, drops"system"line, returns sorted-asc[]semver.VersionErrFNMNotImplementedsentinelWhat's tested
internal/detector/fnm_test.go— 21 tests covering:parseFNMVersion: standard output, bare version, trailing whitespace, emptyparseFNMInstalled: happy path, unparseable lines skipped, empty input, system-onlyFNM.Version(): success, RunShell error wrapping, parse error on blankFNM.ListInstalled(): success, RunShell error wrappingFNM.MutationMethods: each returnsErrFNMNotImplemented(errors.Is-verified)FNM.Detect()does not invokerunShell(cheap-probe contract)withStubShellhelperLive verification
Against the local
/opt/homebrew/bin/fnm 1.39.0:The
"* system"line infnm listoutput is correctly excluded.Test-stub pattern (for future managers)
fnm.godeclares a package-levelrunShell = platform.RunShellvar. Tests usewithStubShell(t, ...)to swap it for the duration of the test (auto-restored viat.Cleanup). Future manager implementations (nvm, volta, asdf, mise, n, nodenv, nvm-windows) should follow the same pattern for consistency.Out of scope (tracked separately)
Install,Uninstall,Use,SetDefault,GlobalNpmPrefix) — will land in their own commit when the upgrade command (Phase 4) needs to call themTest plan
go build ./...go vet ./...go test -race ./internal/detector/...(21/21 pass)