Skip to content

feat(cmd): add doctor command for diagnosing configuration issues#261

Merged
CalvinAllen merged 1 commit into
mainfrom
feat/cmd/doctor-command
May 13, 2026
Merged

feat(cmd): add doctor command for diagnosing configuration issues#261
CalvinAllen merged 1 commit into
mainfrom
feat/cmd/doctor-command

Conversation

@CalvinAllen
Copy link
Copy Markdown
Contributor

Summary

Adds dtvem doctor, a diagnostic command that runs nine checks against a dtvem installation and reports findings as [fixable] (doctor can remediate) or [manual] (step-by-step instructions). Default mode is read-only; --fix enables interactive remediation, and --yes skips per-finding prompts. Exits non-zero when any error-severity finding is present so CI scripts can react.

Checks

Check Severity Remediation
stale-shims-path error fixable (Windows User PATH registry / Unix shell-config marker blocks)
shims-in-path error manual (dtvem init)
shim-binary-present error manual (reinstall)
empty-shims-directory error fixable (Rehash)
shim-map-cache warning fixable (Rehash, with post-fix drift check that flags orphan shim files Rehash can't resolve)
system-runtime-precedence warning manual (uninstall / reorder PATH / accept)
xdg-split-state warning manual (consolidate install)
configured-runtimes-installed error manual (dtvem install <r> <v>)
runtime-executable-present error manual (uninstall+install for first problem)

Framework

src/internal/doctor/ contains the framework — Check interface, Finding/Detail/Severity types, a Registry with init()-time registration (same pattern as runtime/migration providers), and a Run aggregator with HasErrors() and Fixable() helpers. Adding a new check is one Go file plus a Register(...) call in init().

Path helpers

Two new helpers in internal/path back the stale-shims fix:

  • RemoveStaleShimsFromUserPath (Windows-only): rewrites the User PATH registry value to drop stale dtvem-shims entries while preserving every other entry's order. No admin required. Stale entries in System PATH still need an elevated terminal and aren't auto-touched.
  • RemoveStaleShimsFromShellConfig (cross-platform, called only from Unix branch): only deletes pairs of lines where the first is exactly the # Added by dtvem marker, so user-edited PATH exports are never touched even if they happen to reference an old dtvem path.

Both share a new pure helper PartitionStaleShimsEntries, which complements the existing FindStaleShimsEntries.

Test plan

  • ./rnr check passes (format, lint, all tests)
  • All 9 checks have unit tests covering pass/fail/edge cases
  • dtvem doctor runs all checks read-only and prints a report
  • Findings render with [fixable] / [manual] tags
  • dtvem doctor --fix --yes applies fixable findings non-interactively
  • dtvem doctor --fix --no-fix errors with exit code 2
  • Smoke-tested locally on Windows: detected a real shim-map drift case (python3.exe shim with no installed-version executable to back it); the post-fix drift check correctly surfaced the orphan filename rather than falsely claiming Fixed
  • Smoke-test on macOS / Linux

Resolves #248

Add `dtvem doctor` and supporting framework. Diagnoses nine classes
of dtvem misconfiguration, splitting findings into [fixable] (doctor
knows how to remediate) and [manual] (step-by-step instructions).
Default mode is read-only; `--fix` opts into interactive remediation
and `--yes` skips per-finding prompts. Exits non-zero when any
error-severity finding is present so CI scripts can react.

Checks: stale-shims-path (fixable: User PATH registry on Windows,
shell-config marker-block removal on Unix), shims-in-path,
shim-binary-present, empty-shims-directory (fixable: reshim),
shim-map-cache (fixable: reshim, with post-fix drift check that
surfaces orphan shim files reshim can't resolve),
system-runtime-precedence, xdg-split-state,
configured-runtimes-installed, runtime-executable-present.

Adds internal/path helpers RemoveStaleShimsFromUserPath (Windows,
no admin) and RemoveStaleShimsFromShellConfig (Unix, only touches
lines preceded by the `# Added by dtvem` marker) so the
stale-shims-path fix can run targeted writes without re-using the
init-time PATH helpers, which bundle removal with re-ordering.
@CalvinAllen CalvinAllen merged commit 3cc1064 into main May 13, 2026
14 checks passed
@CalvinAllen CalvinAllen deleted the feat/cmd/doctor-command branch May 13, 2026 15:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

feat(cmd): add doctor command for diagnosing configuration issues

1 participant