Repository navigation
fix(doctor): stop removing other dtvem installs' shims from PATH #297
Description
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, sodtvem doctorexits non-zero. --fix, and--fix --yeswithout prompting, removes it:- on Windows, from the User
PATHin the registry (RemoveStaleShimsFromUserPath); - on Unix, by deleting the
# Added by dtvemblock from the shell config (RemoveStaleShimsFromShellConfig).
- on Windows, from the User
dtvem initon Windows removes it silently whenever it writesPATH:prependShimsDirdrops every other dtvem shims entry from the User or SystemPATHand reports "Removed stale dtvem shims entry". On Unix,initonly 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
- Install dtvem normally, so
%USERPROFILE%\.dtvem\shims(or~/.dtvem/shims) is onPATH. - Point dtvem at a second root:
$env:DTVEM_ROOT = 'C:\temp\dtvem2'(orexport DTVEM_ROOT=/tmp/dtvem2). - Run
dtvem doctor. - 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:
- Directory doesn't exist: stale, as today. Error severity and auto-fixable.
- 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 --yesordtvem 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. dtvem initon Windows follows the same rule. It keeps existing directories (and warns, as Unixinitalready 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 doctorreports the default install's existing shims directory as a warning without a fix, and doesn't exit non-zero for it. -
dtvem doctor --fix --yesnever removes aPATHentry, or a shell-config block, whose shims directory exists. -
dtvem initon 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
--fixandinit, as today. - Tests cover missing, existing other-root and current entries for the doctor check and for the Windows and Unix removal helpers.
Activity