Skip to content

fix(doctor): stop removing other dtvem installs' shims from PATH #297

Closed

Description

@CalvinAllen

Description

The stale-shims-path doctor check treats as stale every PATH entry that looks like a dtvem shims directory (…/dtvem/shims or …/.dtvem/shims, via IsDtvemShimsPath) but isn't the current one (path.ShimsDir(), from DTVEM_ROOT or XDG). It never checks whether that directory is actually stale. So with a non-default DTVEM_ROOT (a second install, a test root, a CI cache), the default install's real shims directory counts as stale:

  • Report: the finding is SeverityError, so dtvem doctor exits non-zero.
  • --fix, and --fix --yes without prompting, removes it:
    • on Windows, from the User PATH in the registry (RemoveStaleShimsFromUserPath);
    • on Unix, by deleting the # Added by dtvem block from the shell config (RemoveStaleShimsFromShellConfig).
  • dtvem init on Windows removes it silently whenever it writes PATH: prependShimsDir drops every other dtvem shims entry from the User or System PATH and reports "Removed stale dtvem shims entry". On Unix, init only warns (warnAboutStaleShimsEntries).

The check was written for genuinely dead entries, left over from a pre-XDG install or from switching between system and user installs on Windows. Another dtvem root that is still in use isn't one of those.

Found while testing #294 and #295. Running dtvem doctor --fix --yes with DTVEM_ROOT pointing at a temp root removed C:\Users\<user>\.dtvem\shims from the real User PATH.

Steps to Reproduce

  1. Install dtvem normally, so %USERPROFILE%\.dtvem\shims (or ~/.dtvem/shims) is on PATH.
  2. Point dtvem at a second root: $env:DTVEM_ROOT = 'C:\temp\dtvem2' (or export DTVEM_ROOT=/tmp/dtvem2).
  3. Run dtvem doctor.
  4. Run dtvem doctor --fix --yes.

Expected Behavior

The default install's shims directory, which exists and holds its shims, isn't reported as stale and isn't removed. Only entries that no longer belong to any install are.

Actual Behavior

Step 3 reports ✗ Stale dtvem shims entry in PATH for the default install's shims directory, with Expected: <DTVEM_ROOT>\shims, and doctor exits non-zero. Step 4 removes the entry from the User PATH (Windows) or deletes its block from the shell config (Unix). New terminals then lose the default install's shims.

OS: All (Windows and Unix fixes both affected; init removal is Windows-only) · dtvem: 0.6.5 and main · Runtime: Not runtime-specific

Additional Context: proposed fix

Separate dead entries from other live roots:

  1. Directory doesn't exist: stale, as today. Error severity and auto-fixable.
  2. Directory exists but isn't the current root's: another dtvem root's shims. Report it as a warning with manual instructions: name the directory, and say to remove the entry if that install is no longer used. It is never removed by --fix, --fix --yes or dtvem init. A pre-XDG leftover whose directory still exists lands here too. The user can delete it once they confirm it's unused, which is safer than guessing.
  3. dtvem init on Windows follows the same rule. It keeps existing directories (and warns, as Unix init already does), and only drops entries whose directory is gone.

The split belongs in path (e.g. PartitionStaleShimsEntries returning missing and other-root entries separately), so doctor, RemoveStaleShimsFromUserPath, RemoveStaleShimsFromShellConfig and prependShimsDir all agree.

Acceptance criteria

  • With a non-default DTVEM_ROOT, dtvem doctor reports the default install's existing shims directory as a warning without a fix, and doesn't exit non-zero for it.
  • dtvem doctor --fix --yes never removes a PATH entry, or a shell-config block, whose shims directory exists.
  • dtvem init on Windows keeps other roots' existing shims entries and warns about them.
  • Entries whose directory no longer exists are still reported as errors and removed by --fix and init, as today.
  • Tests cover missing, existing other-root and current entries for the doctor check and for the Windows and Unix removal helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions