Skip to content

feat(detector): implement ASDF detection#4

Merged
dipto0321 merged 2 commits into
mainfrom
feat/detector/implement-asdf
Jun 29, 2026
Merged

feat(detector): implement ASDF detection#4
dipto0321 merged 2 commits into
mainfrom
feat/detector/implement-asdf

Conversation

@dipto0321

Copy link
Copy Markdown
Owner

Summary

Adds ASDF (4/8) to the node-version-updater detector registry. ASDF is a true binary (unlike NVM), so detection follows the same pattern as FNM/Volta: a no-subprocess Detect() probe plus a runShell-backed Version() and ListInstalled().

Detection strategy

Detect() returns true when any of:

  1. asdf is on PATH (via platform.LookupManagerBinary)
  2. $ASDF_DATA_DIR env var is set
  3. ~/.asdf directory exists on disk

All three branches are pure-PATH/on-disk checks — no subprocesses. TestASDF_DoesNotInvokeRunShellOnDetect enforces this with a t.Fatalf if any branch reaches runShell.

Implementation

  • Version() — runs asdf version (urfave/cli style, not --version) and strips an optional v prefix defensively.
  • ListInstalled() — runs asdf list nodejs and parses the two-space-indented lines, where the current version is marked with *. Skips the No compatible versions installed message rather than aborting the parse.
  • asdfDataDir() — respects $ASDF_DATA_DIR (the data dir override) before falling back to $HOME/.asdf, using the homeDir seam already added by Volta for cross-platform test isolation.
  • Mutation methods (Install, Uninstall, Use, SetDefault, GlobalNpmPrefix) return ErrASDFNotImplemented — same sentinel pattern as the other Phase-1 managers.

Tests

19 mocked tests across:

Group Count Coverage
parseASDFVersion 5 standard, bare, whitespace, empty, whitespace-only
parseASDFInstalled 6 real output, unsorted, "no versions" message, unparseable lines, empty, blank lines
Detect branches 4 neither path nor dir, finds dir on disk, honors $ASDF_DATA_DIR, empty env falls through
Method-level 7 Name, Version × 4, ListInstalled × 3
Stubs 1 All five mutation methods return ErrASDFNotImplemented
Helpers 5 asdfDataDir env-wins, home-fallback, empty-home, whitespace-trim, no-shell-on-PATH

go test ./... passes; gofmt and go vet clean.

Out of scope (Phase 1)

Mutation commands — Install / Uninstall / Use / SetDefault / GlobalNpmPrefix — are stubbed with ErrASDFNotImplemented per the project plan. They will be implemented when the upgrade command lands in Phase 4.

Part of the Phase 1 detector rollout (FNM #1, NVM #2, Volta #3, this one #4).

dipto0321 added 2 commits June 29, 2026 17:13
Adds the asdf-vm manager (4/8) to the detector registry. ASDF is a
true binary (unlike NVM), so detection follows the same pattern as
FNM/Volta: a no-subprocess Detect() probe plus a runShell-backed
Version() and ListInstalled().

Detection strategy (any of):
  1. `asdf` on PATH (via platform.LookupManagerBinary)
  2. $ASDF_DATA_DIR env var is set
  3. ~/.asdf directory exists on disk

Implementation notes:
  - Version() runs `asdf version` (urfave/cli style, not --version)
    and strips an optional 'v' prefix defensively.
  - ListInstalled() runs `asdf list nodejs` and parses the
    two-space-indented lines, where the current version is marked
    with ' *'. Skips the 'No compatible versions installed' message
    rather than aborting the parse.
  - asdfDataDir() respects $ASDF_DATA_DIR (the data dir override)
    before falling back to $HOME/.asdf, using the homeDir seam
    already added by Volta for cross-platform test isolation.
  - Mutation methods (Install, Uninstall, Use, SetDefault,
    GlobalNpmPrefix) return ErrASDFNotImplemented — the same
    sentinel pattern used by other Phase-1 managers.

Tests: 19 mocked tests covering parseASDFVersion (5), parseASDFInstalled
(6), the four Detect() branches (4), method-level coverage for
Name/Version/ListInstalled (7), and the not-implemented stubs (1).
TestASDF_DoesNotInvokeRunShellOnDetect explicitly verifies that
Detect() never spawns a subprocess on any of its happy paths.
- Replace 'Defence' with 'Defense' to satisfy the misspell linter rule.
- Use platform-correct binary name (asdf.exe on Windows, asdf elsewhere)
  so the stub binary is found by exec.LookPath on Windows.
- Replace PATH with a single entry pointing at the stub dir, rather than
  prepending — prevents a pre-existing asdf on the CI runner's PATH
  (notably the GitHub Actions Windows image) from shadowing the stub.
@cocogitto-bot

cocogitto-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

✔️ f684001...40ca167 - Conventional commits check succeeded.

@dipto0321 dipto0321 merged commit 55b42cc into main Jun 29, 2026
10 checks passed
@dipto0321 dipto0321 deleted the feat/detector/implement-asdf branch June 29, 2026 11:49
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