Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: mention the leftover uv cache in uninstall (#10442)

Chaitanya Laxmanf4bf6c521f29
diff --git a/.github/workflows/cross-platform-parity-ci.yml b/.github/workflows/cross-platform-parity-ci.yml
index a440e1e1869..0bed5bbec8d 100644
--- a/.github/workflows/cross-platform-parity-ci.yml
+++ b/.github/workflows/cross-platform-parity-ci.yml
@@ -62,6 +62,7 @@ on:
- 'tests/studio/test_uninstall_prebuilt_parity.ps1'
- 'tests/studio/test_uninstall_reparse_stop_roots.ps1'
- 'tests/studio/test_uninstall_legacy_layout_gate.ps1'
+ - 'tests/studio/test_uninstall_uv_cache_note.ps1'
- 'tests/sh/test_uninstall_legacy_layout_gate.sh'
- 'scripts/build_whisper_cpp.sh'
- 'studio/setup*.bat'
@@ -186,6 +187,7 @@ on:
- 'tests/studio/test_uninstall_prebuilt_parity.ps1'
- 'tests/studio/test_uninstall_reparse_stop_roots.ps1'
- 'tests/studio/test_uninstall_legacy_layout_gate.ps1'
+ - 'tests/studio/test_uninstall_uv_cache_note.ps1'
- 'tests/sh/test_uninstall_legacy_layout_gate.sh'
- 'scripts/build_whisper_cpp.sh'
- 'studio/setup*.bat'
@@ -488,6 +490,10 @@ jobs:
- name: Uninstaller ownership gate tests
shell: pwsh
run: pwsh -NoProfile -File tests/studio/test_uninstall_legacy_layout_gate.ps1
+ - name: Uninstaller uv cache note tests
+ if: runner.os == 'Windows'
+ shell: pwsh
+ run: pwsh -NoProfile -File tests/studio/test_uninstall_uv_cache_note.ps1
- name: Path resolver degradation tests
if: runner.os == 'Linux'
run: pwsh -NoProfile -File tests/studio/test_path_resolver_degrades.ps1
diff --git a/scripts/uninstall.ps1 b/scripts/uninstall.ps1
index 3ad7592dbd8..36296561ea1 100644
--- a/scripts/uninstall.ps1
+++ b/scripts/uninstall.ps1
@@ -43,6 +43,7 @@ prebuilts that sit beside the install dir:
%USERPROFILE%\.unsloth\{llama.cpp,node,whisper.cpp,audio.cpp,.cache}. The Hugging
Face cache is left in place (only audio.cpp's unsloth-audiocpp-links beside it
goes), as is anything else you keep under %USERPROFILE%\.unsloth.
+A shared uv package cache (`uv cache dir`) is also left when install reused one.
Options:
-Help, -h, --help, -?, /? Print this message and exit without removing anything.
@@ -540,6 +541,51 @@ Environment:
return $false
}
+ # install.ps1 records its uv cache in <root>\cache\uv-cache-dir.
+ function _RecordedUvCache {
+ param([string]$Root)
+ $marker = Join-Path $Root "cache\uv-cache-dir"
+ if (-not (Test-Path -LiteralPath $marker -PathType Leaf)) { return $null }
+ try {
+ $raw = [System.IO.File]::ReadAllText($marker)
+ } catch {
+ return $null
+ }
+ $raw = $raw.TrimEnd("`r", "`n")
+ if ([string]::IsNullOrWhiteSpace($raw)) { return $null }
+ return $raw
+ }
+
+ function _UvCacheUnderRoot {
+ param([string]$Cache, [string]$Root)
+ if ([string]::IsNullOrWhiteSpace($Cache) -or [string]::IsNullOrWhiteSpace($Root)) { return $false }
+ $normCache = $Cache.Replace('/', '\').TrimEnd('\')
+ $normRoot = $Root.Replace('/', '\').TrimEnd('\')
+ if ($normCache -eq $normRoot) { return $true }
+ return $normCache.StartsWith($normRoot + '\', [StringComparison]::OrdinalIgnoreCase)
+ }
+
+ # Saw: any root recorded a cache. Leftovers: recorded caches outside every root this run deletes.
+ function _UvLeftoverCaches {
+ param([string[]]$Roots)
+ $saw = $false
+ $leftovers = @()
+ foreach ($r in $Roots) {
+ $rec = _RecordedUvCache $r
+ if ($null -eq $rec) { continue }
+ $saw = $true
+ $under = $false
+ foreach ($root in $Roots) {
+ # A junctioned/symlinked root is only unlinked, so its target (and any cache in it) stays.
+ $item = Get-Item -LiteralPath $root -Force -ErrorAction SilentlyContinue
+ if ($item -and $item.LinkType) { continue }
+ if (_UvCacheUnderRoot $rec $root) { $under = $true; break }
+ }
+ if (-not $under -and $leftovers -notcontains $rec) { $leftovers += $rec }
+ }
+ return @{ Saw = $saw; Leftovers = $leftovers }
+ }
+
# Hard deny list: never recursively delete a drive root, USERPROFILE, its parent or a system dir.
function _IsUnsafeRoot {
param([string]$Path)
@@ -995,6 +1041,8 @@ Environment:
if ((_IsStudioRoot $r) -and -not (_IsUnsafeRoot $r)) { $ownedRoots += $r }
}
+ $uvCaches = _UvLeftoverCaches $ownedRoots
+
# ── Stop running servers ──
_Step "Stopping any running Unsloth Studio servers..."
if ($defaultDataDir) {
@@ -1423,6 +1471,17 @@ Environment:
Write-Host " http://localhost:<port> origin you used to remove them."
Write-Host "Note: Hugging Face model cache at %USERPROFILE%\.cache\huggingface was left in place."
Write-Host "Remove it manually with 'Remove-Item -Recurse -Force `"$env:USERPROFILE\.cache\huggingface\hub`"' if desired."
+ if ($uvCaches.Leftovers.Count -gt 0) {
+ foreach ($p in $uvCaches.Leftovers) {
+ Write-Host "Note: the uv package cache at $p was left in place (it may be shared with other tools)."
+ # --cache-dir: a bare `uv cache clean` cleans whichever cache uv resolves now.
+ $q = "'" + $p.Replace("'", "''") + "'"
+ Write-Host " Free it with: uv cache clean --cache-dir $q"
+ }
+ } elseif (-not $uvCaches.Saw) {
+ Write-Host 'Note: if install reused a shared uv cache (`uv cache dir`), it was left in place.'
+ Write-Host " Free it with 'uv cache clean'."
+ }
if (-not $env:UNSLOTH_STUDIO_HOME -and -not $env:STUDIO_HOME) {
Write-Host ""
Write-Host "If you installed Unsloth Studio with UNSLOTH_STUDIO_HOME or STUDIO_HOME"
diff --git a/scripts/uninstall.sh b/scripts/uninstall.sh
index 9afd2781d7b..4ab6a78d461 100755
--- a/scripts/uninstall.sh
+++ b/scripts/uninstall.sh
@@ -30,7 +30,8 @@ entry. In a default-mode install it also removes the shared prebuilts that sit
beside the install dir: ~/.unsloth/{llama.cpp,node,whisper.cpp,audio.cpp,.cache}.
The Hugging Face cache at ~/.cache/huggingface is left in place (only audio.cpp's
unsloth-audiocpp-links beside it goes), as is anything else you keep under
-~/.unsloth.
+~/.unsloth. A shared uv package cache (`uv cache dir`) is also left when install
+reused one.
On WSL it also removes this distro's Windows-side shortcuts under /mnt/*/Users,
strips the Unsloth block from ~/.bashrc, and uses sudo to delete
@@ -245,10 +246,16 @@ _MARKER_DIR=$(mktemp -d 2>/dev/null || true)
_REMOVE_FAILED_FLAG=""
_DB_REMOVED_FLAG=""
_DB_KEPT_FLAG=""
+_UV_ROOTS_FILE=""
+_UV_LEFTOVER_FILE=""
+_UV_SAW_MARKER_FLAG=""
if [ -n "$_MARKER_DIR" ] && [ -d "$_MARKER_DIR" ]; then
_REMOVE_FAILED_FLAG="$_MARKER_DIR/remove-failed"
_DB_REMOVED_FLAG="$_MARKER_DIR/db-removed"
_DB_KEPT_FLAG="$_MARKER_DIR/db-kept"
+ _UV_ROOTS_FILE="$_MARKER_DIR/uv-roots"
+ _UV_LEFTOVER_FILE="$_MARKER_DIR/uv-leftovers"
+ _UV_SAW_MARKER_FLAG="$_MARKER_DIR/uv-saw-marker"
fi
# `printf`, never `: > "$f"`: `:` is a POSIX special builtin, so a redirection error on it kills a
@@ -269,6 +276,52 @@ _markers_unavailable() {
return 1
}
+# install.sh records its uv cache in <root>/cache/uv-cache-dir. One under a removed root goes with
+# it; any other is shared and stays. Read before any root is deleted.
+_uv_cache_under_any_root() {
+ while IFS= read -r _uv_r; do
+ # A symlinked root is only unlinked, so its target (and any cache in it) stays.
+ [ -L "$_uv_r" ] && continue
+ case "$1" in "$_uv_r"|"$_uv_r"/*) return 0 ;; esac
+ done < "$_UV_ROOTS_FILE"
+ return 1
+}
+
+_uv_collect_from_install_roots() {
+ [ -n "$_UV_ROOTS_FILE" ] || return 0
+ {
+ printf '%s\n' "$HOME/.unsloth/studio"
+ _custom_studio_roots | while IFS= read -r _uv_root; do
+ [ -n "$_uv_root" ] || continue
+ if ! _is_unsafe_root "$_uv_root" && _is_studio_root "$_uv_root"; then
+ printf '%s\n' "$_uv_root"
+ fi
+ done
+ } > "$_UV_ROOTS_FILE" 2>/dev/null || return 0
+ while IFS= read -r _uv_root; do
+ [ -f "$_uv_root/cache/uv-cache-dir" ] || continue
+ _set_marker "$_UV_SAW_MARKER_FLAG"
+ _uv_rec=$(sed -n '1p' "$_uv_root/cache/uv-cache-dir" 2>/dev/null | tr -d '\r') || _uv_rec=""
+ [ -n "$_uv_rec" ] || continue
+ _uv_cache_under_any_root "$_uv_rec" || printf '%s\n' "$_uv_rec" >> "$_UV_LEFTOVER_FILE" 2>/dev/null || true
+ done < "$_UV_ROOTS_FILE"
+}
+
+_uv_print_leftover_notes() {
+ if [ -s "$_UV_LEFTOVER_FILE" ]; then
+ awk '!seen[$0]++' "$_UV_LEFTOVER_FILE" 2>/dev/null | while IFS= read -r _uv_path; do
+ [ -n "$_uv_path" ] || continue
+ # --cache-dir: a bare `uv cache clean` cleans whichever cache uv resolves now.
+ _uv_q=$(printf '%s' "$_uv_path" | sed "s/'/'\\\\''/g")
+ echo "Note: the uv package cache at $_uv_path was left in place (it may be shared with other tools)."
+ echo " Free it with: uv cache clean --cache-dir '$_uv_q'"
+ done
+ elif ! _marker_set "$_UV_SAW_MARKER_FLAG"; then
+ echo "Note: if install reused a shared uv cache (\`uv cache dir\`), it was left in place."
+ echo " Free it with 'uv cache clean'."
+ fi
+}
+
# EXIT, not a line at the end of main: --help, a bad argument and `set -e` all skip that.
_cleanup_markers() {
if [ -n "$_MARKER_DIR" ]; then
@@ -754,6 +807,7 @@ _unsloth_uninstall_main() {
_pkill_studio
echo "Removing data and install directories..."
+ _uv_collect_from_install_roots
# Resolved ONCE, before anything is deleted: _master_root can read its answer from a note
# inside a Studio tree the loop below removes, after which the runtime siblings are stranded.
_MASTER_ROOT_SAVED="$(_master_root)"
@@ -1207,6 +1261,7 @@ _unsloth_uninstall_main() {
echo " http://localhost:<port> origin you used to remove them."
echo "Note: Hugging Face model cache at ~/.cache/huggingface was left in place."
echo "Remove it manually with 'rm -rf ~/.cache/huggingface/hub' if desired."
+ _uv_print_leftover_notes
# Env-mode installs leave no breadcrumb in $HOME, so a custom root is only found when the
# user re-exports the variable. Hint when neither is set, so `curl | sh` does not silently miss.
if [ -z "${UNSLOTH_STUDIO_HOME:-}" ] && [ -z "${STUDIO_HOME:-}" ]; then
diff --git a/tests/sh/test_uninstall_leaves_uv_cache.sh b/tests/sh/test_uninstall_leaves_uv_cache.sh
new file mode 100755
index 00000000000..2058d6d8e5a
--- /dev/null
+++ b/tests/sh/test_uninstall_leaves_uv_cache.sh
@@ -0,0 +1,143 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# A shared uv cache stays and is named; a Studio-owned one goes silently with the root (#9651).
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+UNINSTALL_SH="$SCRIPT_DIR/../../scripts/uninstall.sh"
+PASS=0
+FAIL=0
+
+if grep -qi microsoft /proc/version 2>/dev/null; then
+ echo " SKIP: WSL -- the uninstall body reaches Windows-side state outside the fixture"
+ exit 0
+fi
+
+_TMP_ROOT=$(mktemp -d)
+trap 'rm -rf "$_TMP_ROOT"' EXIT
+
+unset UNSLOTH_STUDIO_HOME STUDIO_HOME UNSLOTH_UNINSTALL_ROCM
+XDG_RUNTIME_DIR="$_TMP_ROOT/run"
+export XDG_RUNTIME_DIR
+mkdir -p "$XDG_RUNTIME_DIR"
+
+ok() { echo " PASS: $1"; PASS=$((PASS + 1)); }
+nope() { echo " FAIL: $1"; FAIL=$((FAIL + 1)); }
+
+make_studio() {
+ FIXTURE_HOME=$(mktemp -d "$_TMP_ROOT/home.XXXXXX")
+ mkdir -p "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/bin"
+ : > "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/bin/unsloth"
+ : > "$FIXTURE_HOME/.unsloth/studio/unsloth_studio/.unsloth-studio-owned"
+}
+
+run_uninstall() {
+ HOME="$FIXTURE_HOME" sh "$UNINSTALL_SH" > "$_TMP_ROOT/out.log" 2>&1 || {
+ echo " FAIL: uninstall exited $?"; cat "$_TMP_ROOT/out.log"; exit 1
+ }
+ OUT=$(cat "$_TMP_ROOT/out.log")
+}
+
+echo "=== shared uv cache recorded outside the install root ==="
+
+make_studio
+mkdir -p "$FIXTURE_HOME/.cache/uv/wheels-v0" \
+ "$FIXTURE_HOME/.unsloth/studio/cache"
+: > "$FIXTURE_HOME/.cache/uv/wheels-v0/keep-me.whl"
+printf '%s\n' "$FIXTURE_HOME/.cache/uv" > "$FIXTURE_HOME/.unsloth/studio/cache/uv-cache-dir"
+run_uninstall
+
+if [ -f "$FIXTURE_HOME/.cache/uv/wheels-v0/keep-me.whl" ]; then
+ ok "shared uv cache survives uninstall"
+else
+ nope "shared uv cache was deleted"
+fi
+case "$OUT" in
+ *"the uv package cache at $FIXTURE_HOME/.cache/uv was left in place"*)
+ ok "output names the recorded shared cache"
+ ;;
+ *) nope "output missing the recorded shared cache path" ;;
+esac
+case "$OUT" in
+ *"uv cache clean"*) ok "shared-cache note names uv cache clean" ;;
+ *) nope "shared-cache note missing uv cache clean" ;;
+esac
+case "$OUT" in
+ *"uv cache prune"*) nope "shared-cache note still leads with prune" ;;
+ *) ok "shared-cache note does not lead with prune" ;;
+esac
+
+case "$OUT" in
+ *"uv cache clean --cache-dir '$FIXTURE_HOME/.cache/uv'"*) ok "shared-cache note names the cache to clean" ;;
+ *) nope "shared-cache note does not pass --cache-dir" ;;
+esac
+
+echo "=== shared uv cache path with a quote is pasteable ==="
+
+make_studio
+_q_cache="$FIXTURE_HOME/it's uv"
+mkdir -p "$_q_cache" "$FIXTURE_HOME/.unsloth/studio/cache"
+printf '%s\n' "$_q_cache" > "$FIXTURE_HOME/.unsloth/studio/cache/uv-cache-dir"
+run_uninstall
+_q_cmd=$(printf '%s\n' "$OUT" | sed -n 's/^ *Free it with: //p' | head -n 1)
+_q_arg=$(eval "set -- ${_q_cmd#uv cache clean --cache-dir }"; printf '%s' "$1")
+if [ "$_q_arg" = "$_q_cache" ]; then
+ ok "quoted --cache-dir argument round-trips"
+else
+ nope "quoted --cache-dir argument is '$_q_arg'"
+fi
+
+echo "=== symlinked install root keeps the cache in its target ==="
+
+make_studio
+_real="$FIXTURE_HOME/real-studio"
+mv "$FIXTURE_HOME/.unsloth/studio" "$_real"
+ln -s "$_real" "$FIXTURE_HOME/.unsloth/studio"
+mkdir -p "$_real/cache/uv"
+printf '%s\n' "$FIXTURE_HOME/.unsloth/studio/cache/uv" > "$_real/cache/uv-cache-dir"
+run_uninstall
+if [ -d "$_real/cache/uv" ]; then
+ case "$OUT" in
+ *"uv package cache at $FIXTURE_HOME/.unsloth/studio/cache/uv was left"*) ok "kept cache under a symlinked root is named" ;;
+ *) nope "kept cache under a symlinked root is not named" ;;
+ esac
+else
+ ok "symlinked root target removed with its cache (nothing to name)"
+fi
+
+echo "=== Studio-owned uv cache under the install root ==="
+
+make_studio
+mkdir -p "$FIXTURE_HOME/.unsloth/studio/cache/uv/wheels-v0"
+: > "$FIXTURE_HOME/.unsloth/studio/cache/uv/wheels-v0/x.whl"
+printf '%s\n' "$FIXTURE_HOME/.unsloth/studio/cache/uv" \
+ > "$FIXTURE_HOME/.unsloth/studio/cache/uv-cache-dir"
+run_uninstall
+
+if [ -e "$FIXTURE_HOME/.unsloth/studio" ]; then
+ nope "studio install dir still present"
+else
+ ok "studio install dir (and its uv cache) is gone"
+fi
+case "$OUT" in
+ *"uv package cache"*) nope "studio-mode still claims a uv cache was left" ;;
+ *) ok "studio-mode is silent about a leftover uv cache" ;;
+esac
+case "$OUT" in
+ *"uv cache clean"*) nope "studio-mode still points at uv cache clean" ;;
+ *) ok "studio-mode does not point at uv cache clean" ;;
+esac
+
+echo "=== no uv-cache-dir marker (pre-#10204 install) ==="
+
+make_studio
+run_uninstall
+case "$OUT" in
+ *"if install reused a shared uv cache"*) ok "missing marker hedges instead of claiming a leftover" ;;
+ *) nope "missing marker did not hedge" ;;
+esac
+
+echo ""
+echo "Results: $PASS passed, $FAIL failed"
+[ "$FAIL" = 0 ]
diff --git a/tests/studio/test_uninstall_prebuilt_parity.ps1 b/tests/studio/test_uninstall_prebuilt_parity.ps1
index aef57e7ddbd..52a7d9f9543 100644
--- a/tests/studio/test_uninstall_prebuilt_parity.ps1
+++ b/tests/studio/test_uninstall_prebuilt_parity.ps1
@@ -74,5 +74,10 @@ Check "uninstall.ps1 sweeps stale install locks" ($ps1Text -match '\.install\.lo
Check "uninstall.ps1 prunes ~/.unsloth only when empty" `
($ps1Text -match 'Get-ChildItem -LiteralPath \$defaultUnslothHome')
+Check "uninstall.sh reads uv-cache-dir" ($shText -match 'uv-cache-dir')
+Check "uninstall.ps1 reads uv-cache-dir" ($ps1Text -match 'uv-cache-dir')
+Check "uninstall.sh names uv cache clean" ($shText -match 'uv cache clean')
+Check "uninstall.ps1 names uv cache clean" ($ps1Text -match 'uv cache clean')
+
if ($failures -gt 0) { Write-Host ""; Write-Host "FAILED ($failures)" -ForegroundColor Red; exit 1 }
Write-Host ""; Write-Host "All tests passed."; exit 0
diff --git a/tests/studio/test_uninstall_uv_cache_note.ps1 b/tests/studio/test_uninstall_uv_cache_note.ps1
new file mode 100644
index 00000000000..95bbce36020
--- /dev/null
+++ b/tests/studio/test_uninstall_uv_cache_note.ps1
@@ -0,0 +1,86 @@
+#!/usr/bin/env pwsh
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# #9651: a recorded uv cache outside every removed root is named, one inside is not. The
+# uninstaller body writes to the registry, so the helpers are lifted out by AST.
+# Run: pwsh -NoProfile -File tests/studio/test_uninstall_uv_cache_note.ps1
+
+$ErrorActionPreference = "Stop"
+$repoRoot = (Resolve-Path ([System.IO.Path]::Combine($PSScriptRoot, "..", ".."))).Path
+$ps1Path = [System.IO.Path]::Combine($repoRoot, "scripts", "uninstall.ps1")
+
+$failures = 0
+function Check($name, $cond) {
+ if ($cond) { Write-Host " PASS $name" }
+ else { Write-Host " FAIL $name" -ForegroundColor Red; $script:failures++ }
+}
+
+$tokens = $null; $errors = $null
+$ast = [System.Management.Automation.Language.Parser]::ParseFile($ps1Path, [ref]$tokens, [ref]$errors)
+Check "uninstall.ps1 parses" ($null -eq $errors -or $errors.Count -eq 0)
+$allFns = $ast.FindAll({
+ param($n) $n -is [System.Management.Automation.Language.FunctionDefinitionAst]
+ }, $true)
+foreach ($name in @("_RecordedUvCache", "_UvCacheUnderRoot", "_UvLeftoverCaches")) {
+ $fn = $allFns | Where-Object { $_.Name -eq $name } | Select-Object -First 1
+ if (-not $fn) {
+ Write-Host " FAIL $name not found in uninstall.ps1" -ForegroundColor Red
+ exit 1
+ }
+ . ([scriptblock]::Create($fn.Extent.Text))
+}
+
+if ([System.IO.Path]::DirectorySeparatorChar -ne '\') {
+ Write-Host " SKIP uninstall.ps1 joins Windows paths; run on Windows"
+ exit 0
+}
+
+$tmp = Join-Path ([System.IO.Path]::GetTempPath()) ("unsloth-uv-note-" + [System.Guid]::NewGuid().ToString("N"))
+New-Item -ItemType Directory -Path $tmp -Force | Out-Null
+try {
+ function Root([string]$Name, $Recorded) {
+ $root = Join-Path $tmp $Name
+ New-Item -ItemType Directory -Path (Join-Path $root "cache") -Force | Out-Null
+ if ($null -ne $Recorded) {
+ [System.IO.File]::WriteAllText((Join-Path $root "cache\uv-cache-dir"), $Recorded + "`r`n")
+ }
+ return $root
+ }
+
+ $shared = Join-Path $tmp "shared-uv"
+ $a = Root "a" $shared
+ $r = _UvLeftoverCaches @($a)
+ Check "shared cache is a leftover" ($r.Saw -and $r.Leftovers.Count -eq 1 -and $r.Leftovers[0] -eq $shared)
+
+ $own = Join-Path (Join-Path $tmp "b") "cache\uv"
+ $b = Root "b" $own
+ $r = _UvLeftoverCaches @($b)
+ Check "Studio-owned cache is silent" ($r.Saw -and $r.Leftovers.Count -eq 0)
+
+ $r = _UvLeftoverCaches @((Root "c" ((Join-Path $tmp "c").Replace('\', '/') + "/cache/uv")))
+ Check "forward-slash cache under the root is silent" ($r.Saw -and $r.Leftovers.Count -eq 0)
+
+ $d = Root "d" (Join-Path (Join-Path $tmp "b") "cache\uv")
+ $r = _UvLeftoverCaches @($b, $d)
+ Check "cache under another removed root is silent" ($r.Leftovers.Count -eq 0)
+
+ $r = _UvLeftoverCaches @((Root "e" $null))
+ Check "no marker: nothing seen, nothing named" (-not $r.Saw -and $r.Leftovers.Count -eq 0)
+
+ $r = _UvLeftoverCaches @()
+ Check "no roots" (-not $r.Saw -and $r.Leftovers.Count -eq 0)
+
+ $target = Join-Path $tmp "real"
+ $link = Join-Path $tmp "linked"
+ New-Item -ItemType Directory -Path (Join-Path $target "cache") -Force | Out-Null
+ New-Item -ItemType Junction -Path $link -Target $target | Out-Null
+ $linkedCache = Join-Path $link "cache\uv"
+ [System.IO.File]::WriteAllText((Join-Path $target "cache\uv-cache-dir"), $linkedCache + "`n")
+ $r = _UvLeftoverCaches @($link)
+ Check "junctioned root: its cache is named" ($r.Leftovers.Count -eq 1 -and $r.Leftovers[0] -eq $linkedCache)
+} finally {
+ Remove-Item -LiteralPath $tmp -Recurse -Force -ErrorAction SilentlyContinue
+}
+
+if ($failures -gt 0) { Write-Host ""; Write-Host "FAILED ($failures)" -ForegroundColor Red; exit 1 }
+Write-Host ""; Write-Host "All tests passed."; exit 0
diff --git a/tests/test_setup_master_root.py b/tests/test_setup_master_root.py
index 45408132d71..ba359df4bf1 100644
--- a/tests/test_setup_master_root.py
+++ b/tests/test_setup_master_root.py
@@ -1229,7 +1229,7 @@ def test_neither_uninstaller_re_resolves_the_master_root_after_deleting_it():
sh_code = "\n".join(l for l in sh.splitlines() if not l.lstrip().startswith("#"))
saved = sh_code.index('_MASTER_ROOT_SAVED="$(_master_root)"')
- removal = sh_code.index("_custom_studio_roots | while")
+ removal = sh_code.index("_custom_studio_roots | while IFS= read -r _custom_root")
# Resolved before the first deletion, and nothing asks again after it. Calls BEFORE the loop
# are fine: those enumerate while every tree is still on disk.
assert saved < removal