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.

Windows installer: stop an unresolvable 8.3 alias aborting the rollback (#11319)

UmranProse27337cd892e
diff --git a/install.ps1 b/install.ps1
index 07ea7613f3f..4f3281767da 100644
--- a/install.ps1
+++ b/install.ps1
@@ -14,6 +14,28 @@
#
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+# Remove-Item's -ErrorAction does not cover every failure. For a path the FileSystem provider
+# cannot resolve it raises a terminating PSArgumentException ("An object at the specified path
+# ... does not exist"), which -ErrorAction SilentlyContinue cannot suppress, so an unguarded
+# removal during a rollback aborts the rest of the cleanup it belongs to (#11290). Guard on
+# existence and catch everything, so a missing or unresolvable temp path is never fatal. Used
+# for the temp files whose names can come from an 8.3 alias.
+#
+# Top level, NOT inside Install-UnslothStudio: a nested function lives in its parent's local
+# scope and is gone once the parent returns, and the outer finally below runs after exactly
+# that. Defined there, the finally's two calls raise CommandNotFoundException and leave the
+# overrides file -- which carries the caller's UV_OVERRIDE lines -- on disk.
+# tests/studio/test_unsloth_torch_override.ps1 pins the placement.
+function Remove-UnslothTempFileQuietly {
+ param([string]$Path)
+ if (-not $Path) { return }
+ try {
+ if (-not (Test-Path -LiteralPath $Path -ErrorAction SilentlyContinue)) { return }
+ Remove-Item -LiteralPath $Path -Force -ErrorAction Stop
+ } catch { }
+}
+
function Install-UnslothStudio {
$ErrorActionPreference = "Stop"
@@ -395,7 +417,9 @@ function Install-UnslothStudio {
} else {
$fso.GetFile($Path).ShortPath
}
- if ($short -and -not $short.Contains(" ")) { return $short }
+ # A space-free alias is not necessarily a name that resolves (#11290). This value
+ # reaches UV_OVERRIDE and --find-links, so a bogus one breaks every later uv call.
+ if ($short -and -not $short.Contains(" ") -and (Test-Path -LiteralPath $short -ErrorAction SilentlyContinue)) { return $short }
} catch {}
return $Path
}
@@ -9431,7 +9455,11 @@ exit 0
if (-not $Path.Contains(" ")) { return @{ Path = $Path; Temporary = $false } }
$short = $null
try { $short = (New-Object -ComObject Scripting.FileSystemObject).GetFile($Path).ShortPath } catch { }
- if ($short -and -not $short.Contains(" ")) { return @{ Path = $short; Temporary = $false } }
+ # Space-free is not sufficient: a volume can hand back an 8.3 name that does not resolve,
+ # and uv then fails to open the file it was pointed at (#11290).
+ if ($short -and -not $short.Contains(" ") -and (Test-Path -LiteralPath $short -PathType Leaf -ErrorAction SilentlyContinue)) {
+ return @{ Path = $short; Temporary = $false }
+ }
# No 8.3 name: copy to a space-free directory instead. Several candidates, because %TEMP%
# can carry the space itself (the #11012 case) and 8.3 creation is commonly disabled on
@@ -9457,7 +9485,9 @@ exit 0
if ($dir.Contains(" ")) {
$dirShort = $null
try { $dirShort = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($dir).ShortPath } catch { }
- if (-not $dirShort -or $dirShort.Contains(" ")) { continue }
+ # Space-free is not sufficient: an 8.3 name that does not resolve would be copied
+ # into and then handed to uv, which cannot open it (#11290).
+ if (-not $dirShort -or $dirShort.Contains(" ") -or -not (Test-Path -LiteralPath $dirShort -PathType Container -ErrorAction SilentlyContinue)) { continue }
$dir = $dirShort
}
# Declared before the try so the catch can clean up a Copy-Item that failed partway
@@ -9535,7 +9565,7 @@ exit 0
try {
[System.IO.File]::WriteAllText($f, (($lines -join "`n") + "`n"), (New-Object System.Text.UTF8Encoding($false)))
} catch {
- Remove-Item -LiteralPath $f -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $f
$script:TorchOverridesFile = $null
throw
}
@@ -9543,11 +9573,23 @@ exit 0
if ($f.Contains(" ")) {
$short = $null
try { $short = (New-Object -ComObject Scripting.FileSystemObject).GetFile($f).ShortPath } catch { }
- if (-not $short -or $short.Contains(" ")) {
- # No short name: skip the freeze rather than fail.
- substep "[WARN] the torch overrides path has a space and no 8.3 short name;" "Yellow"
+ # Space-free is not sufficient. A volume can hand back an 8.3 name that does not resolve,
+ # and this path is then both uv's --overrides argument and the file the caller deletes:
+ # uv fails to open it, and Remove-Item raises a terminating PSArgumentException that
+ # -ErrorAction SilentlyContinue on every one of these probes is the idiom at line 3277
+ # and is load-bearing: under this script's "Stop", Test-Path inside an ACL-denied
+ # directory THROWS UnauthorizedAccessException instead of returning false, and none of
+ # these guards sits inside a try. Bare, the check aborts the install on a path whose
+ # only crime is being unreadable, in functions whose contract is to fall through.
+ # -ErrorAction SilentlyContinue cannot suppress (#11290). Require a real file.
+ if (-not $short -or $short.Contains(" ") -or -not (Test-Path -LiteralPath $short -PathType Leaf -ErrorAction SilentlyContinue)) {
+ # No usable short name: skip the freeze rather than fail.
+ substep "[WARN] the torch overrides path has a space and no usable 8.3 short name;" "Yellow"
substep "installing unsloth without freezing the installed PyTorch." "Yellow"
- Remove-Item -LiteralPath $f -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $f
+ # Tracked above: clear it so the outer sweep is not handed a path this branch
+ # has already deleted.
+ $script:TorchOverridesFile = $null
return $null
}
$f = $short
@@ -9860,7 +9902,7 @@ exit 0
$script:TorchOverridesFile = New-UnslothTorchOverridesFile -PythonExe $VenvPython
if ($script:TorchOverridesFile) {
$baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (local)" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth --overrides $script:TorchOverridesFile "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.9.6" }
- Remove-Item -LiteralPath $script:TorchOverridesFile -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $script:TorchOverridesFile
$script:TorchOverridesFile = $null
} else {
$baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (local)" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.9.6" }
@@ -9870,7 +9912,7 @@ exit 0
$script:TorchOverridesFile = New-UnslothTorchOverridesFile -PythonExe $VenvPython
if ($script:TorchOverridesFile) {
$baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth --overrides $script:TorchOverridesFile -- "$_unslothPkg" }
- Remove-Item -LiteralPath $script:TorchOverridesFile -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $script:TorchOverridesFile
$script:TorchOverridesFile = $null
} else {
$baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth -- "$_unslothPkg" }
@@ -10769,11 +10811,11 @@ try {
Remove-Item Env:UNSLOTH_KEPT_TORCH -ErrorAction SilentlyContinue
# The generated overrides file copies the caller's UV_OVERRIDE contents; never leave it.
if ($script:TorchOverridesFile) {
- Remove-Item -LiteralPath $script:TorchOverridesFile -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $script:TorchOverridesFile
$script:TorchOverridesFile = $null
}
if ($script:WoaSessionOverrides) {
- Remove-Item -LiteralPath $script:WoaSessionOverrides -Force -ErrorAction SilentlyContinue
+ Remove-UnslothTempFileQuietly -Path $script:WoaSessionOverrides
$script:WoaSessionOverrides = $null
}
}
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index 73cde3c11ce..4c61203d4e8 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -5854,7 +5854,9 @@ function Get-UvSafePath {
} else {
$fso.GetFile($Path).ShortPath
}
- if ($short -and -not $short.Contains(" ")) { return $short }
+ # A space-free alias is not necessarily a name that resolves (#11290). This value
+ # reaches UV_OVERRIDE and --find-links, so a bogus one breaks every later uv call.
+ if ($short -and -not $short.Contains(" ") -and (Test-Path -LiteralPath $short -ErrorAction SilentlyContinue)) { return $short }
} catch {}
return $Path
}
diff --git a/tests/python/test_uv_requirements_path_space.py b/tests/python/test_uv_requirements_path_space.py
index 2d1b05b912e..7fec264061d 100644
--- a/tests/python/test_uv_requirements_path_space.py
+++ b/tests/python/test_uv_requirements_path_space.py
@@ -133,3 +133,49 @@ def test_the_helper_behaviour_suite_runs():
)
assert proc.returncode == 0, proc.stdout + proc.stderr
assert _VERDICT in proc.stdout, proc.stdout
+
+
+def test_an_8dot3_alias_is_only_used_once_it_resolves():
+ """A space-free 8.3 name is not necessarily a name that resolves (issue #11290).
+
+ `GetShortPathName` / the FSO `ShortPath` property can hand back a short form that the
+ volume never actually created, so "contains no space" is not sufficient validation:
+ uv is then pointed at a file it cannot open, and the same alias is what the installer
+ later hands to Remove-Item. Require the alias to exist before it is used.
+ """
+ text = INSTALL_PS1.read_text(encoding = "utf-8")
+ body = text[text.index(f"function {HELPER}") :]
+ body = body[: body.index("\n function ")]
+ # [^)]* so the assertion pins the CHECK, not the argument list: the guard also has to carry
+ # -ErrorAction SilentlyContinue, because under the installer's "Stop" a bare Test-Path in an
+ # ACL-denied directory throws instead of returning false (install.ps1:3277).
+ assert re.search(r"-and \(Test-Path -LiteralPath \$short -PathType Leaf\b[^)]*\)", body), (
+ f"{HELPER} accepts an 8.3 short path on 'contains no space' alone, so an alias that "
+ "does not resolve is handed to uv and later to Remove-Item"
+ )
+ assert re.search(r"Test-Path -LiteralPath \$short[^)]*-ErrorAction SilentlyContinue\)", body), (
+ f"{HELPER} queries the filesystem without -ErrorAction SilentlyContinue, so an unreadable "
+ "directory aborts the install instead of rejecting the alias"
+ )
+
+
+def test_get_uv_safe_path_queries_the_filesystem_safely():
+ """The alias check must not turn an unreadable directory into a failed install (#11290).
+
+ That the alias has to resolve is already pinned by
+ tests/studio/install/test_woa_torch_index_persistence.py. What is asserted here is the other
+ half: under the installer's ``$ErrorActionPreference = "Stop"`` a bare ``Test-Path`` inside an
+ ACL-denied directory raises UnauthorizedAccessException rather than returning false, and none
+ of these guards sits inside a ``try``. Without -ErrorAction SilentlyContinue the guard aborts
+ the install on a path it was only supposed to reject. install.ps1 line 3277 uses the same
+ idiom for the same reason.
+ """
+ guard = r"Test-Path -LiteralPath \$short\b[^)]*-ErrorAction SilentlyContinue\)"
+ for path in (INSTALL_PS1, REPO_ROOT / "studio" / "setup.ps1"):
+ text = path.read_text(encoding = "utf-8")
+ start = text.index("function Get-UvSafePath")
+ body = text[start : text.index("\n}", start)]
+ assert re.search(guard, body), (
+ f"{path.name}: Get-UvSafePath probes the filesystem without -ErrorAction "
+ "SilentlyContinue, so an unreadable directory aborts the install"
+ )
diff --git a/tests/studio/install/test_woa_torch_index_persistence.py b/tests/studio/install/test_woa_torch_index_persistence.py
index dbbaa73ecb9..1bb49c580ed 100644
--- a/tests/studio/install/test_woa_torch_index_persistence.py
+++ b/tests/studio/install/test_woa_torch_index_persistence.py
@@ -342,6 +342,17 @@ class TestResolverEnvironmentRestore:
install, setup = _ps_copies("Get-UvSafePath")
assert install == setup
+ def test_the_alias_is_only_used_once_it_resolves(self):
+ """A space-free 8.3 name is not necessarily a name that exists (#11290).
+
+ This helper's result reaches UV_OVERRIDE and --find-links, which every later uv call reads,
+ so an alias that does not resolve breaks the whole resolve rather than one file.
+ """
+ for source, body in zip(("install.ps1", "studio/setup.ps1"), _ps_copies("Get-UvSafePath")):
+ assert (
+ "Test-Path -LiteralPath $short" in body
+ ), f"{source}: Get-UvSafePath accepts an 8.3 alias on 'contains no space' alone"
+
def test_the_dependency_that_makes_this_necessary_is_still_there(self):
"""If studio.txt ever drops ddgs, this restore stops being load-bearing for brotli."""
studio_txt = PACKAGE_ROOT / "studio" / "backend" / "requirements" / "studio.txt"
@@ -6088,10 +6099,11 @@ class TestFoldedCallerOverridesDoNotOutliveTheRun:
def test_the_exit_path_removes_it(self):
"""Beside the torch overrides file, which is deleted on exit for the same reason."""
tail = INSTALL_SRC[INSTALL_SRC.index("try {\n Install-UnslothStudio @args") :]
- assert (
- "Remove-Item -LiteralPath $script:WoaSessionOverrides -Force -ErrorAction SilentlyContinue"
- in tail
- )
+ # Through the guarded helper: Remove-Item's -ErrorAction does not cover the terminating
+ # error the FileSystem provider raises for a path it cannot resolve (#11290), so an
+ # unguarded removal here would abort the rest of the sweep.
+ assert "Remove-UnslothTempFileQuietly -Path $script:WoaSessionOverrides" in tail
+ assert "Remove-UnslothTempFileQuietly -Path $script:TorchOverridesFile" in tail
head = INSTALL_SRC[: INSTALL_SRC.index("try {\n Install-UnslothStudio @args")]
assert head.rstrip().endswith(
"$script:WoaSessionOverrides = $null\n$script:TorchOverridesFile = $null"
diff --git a/tests/studio/test_torch_overrides_merge.ps1 b/tests/studio/test_torch_overrides_merge.ps1
index ea28eaedee1..7a5e777768b 100644
--- a/tests/studio/test_torch_overrides_merge.ps1
+++ b/tests/studio/test_torch_overrides_merge.ps1
@@ -159,7 +159,14 @@ try {
$iTrack = $src.IndexOf('$script:TorchOverridesFile = $f')
$iWrite = $src.IndexOf('[System.IO.File]::WriteAllText(')
Check "the path is tracked BEFORE the write that can throw" (($iTrack -ge 0) -and ($iTrack -lt $iWrite))
- Check "a failed write removes the file it created" ($src -match 'catch \{\s*\r?\n\s*Remove-Item -LiteralPath \$f')
+ Check "a failed write removes the file it created" ($src -match 'catch \{\s*\r?\n\s*Remove-UnslothTempFileQuietly -Path \$f')
+ # Space-free is not sufficient for an 8.3 alias: a volume can hand back a name that does not
+ # resolve, and this alias is both uv's --overrides argument and the caller's delete target, so
+ # an unresolvable one fails the install and then throws on the way out (#11290).
+ Check "the 8.3 alias is accepted only once it resolves" (
+ $src -match 'Test-Path -LiteralPath \$short -PathType Leaf')
+ Check "the give-up branch clears the path it just deleted" (
+ ([regex]::Matches($src, '\$script:TorchOverridesFile = \$null')).Count -eq 2)
# Get-Content decodes a BOM-less file with the ANSI code page on PS 5.1, which is where the
# mojibake came from. pwsh on Linux defaults to UTF-8, so the round trip cannot fail here
diff --git a/tests/studio/test_unsloth_torch_override.ps1 b/tests/studio/test_unsloth_torch_override.ps1
index 16415b54bd6..a236b8def0f 100644
--- a/tests/studio/test_unsloth_torch_override.ps1
+++ b/tests/studio/test_unsloth_torch_override.ps1
@@ -5,6 +5,9 @@
# guard (New-UnslothTorchOverridesFile) on the Step-2 unsloth installs. The generated file folds in
# the caller's UV_OVERRIDE lines, which can carry authenticated URLs, so it must never outlive the
# run: install.sh removes its twin from the traps, install.ps1 from the outer finally.
+# Every one of those removals goes through Remove-UnslothTempFileQuietly, because Remove-Item's
+# -ErrorAction cannot suppress the terminating error the FileSystem provider raises for a path it
+# cannot resolve, and an unguarded removal therefore aborts the rest of the cleanup (#11290).
# Run: pwsh -NoProfile -File tests/studio/test_unsloth_torch_override.ps1
$ErrorActionPreference = "Stop"
@@ -43,6 +46,16 @@ Check "helper defined exactly once" ($fnAst.Count -eq 1)
$fnText = $fnAst[0].Extent.Text
Check "helper returns null under --no-torch" ($fnText -match 'if \(\$SkipTorch\) \{ return \$null \}')
Check "helper folds in caller UV_OVERRIDE files" ($fnText -match '\$env:UV_OVERRIDE')
+# Space-free is not sufficient for an 8.3 alias. A volume can hand back a name that does not
+# resolve, and this alias is both uv's --overrides argument and the caller's delete target, so an
+# unresolvable one fails the install and then throws on the way out (#11290).
+Check "the 8.3 alias is accepted only once it resolves" (
+ $fnText -match 'Test-Path -LiteralPath \$short -PathType Leaf')
+# Both places the helper gives up on the file it created (a failed write, and no usable short name)
+# must also drop the tracked path, or the outer sweep is handed a file that is already gone.
+Check "every removal of the created file clears the tracked path" (
+ ([regex]::Matches($fnText, 'Remove-UnslothTempFileQuietly -Path \$f')).Count -eq 2 -and
+ ([regex]::Matches($fnText, '\$script:TorchOverridesFile = \$null')).Count -eq 2)
Write-Host "with-deps unsloth installs pass --overrides"
foreach ($label in @("install unsloth (local)", "install unsloth")) {
@@ -59,22 +72,62 @@ foreach ($label in @("install unsloth (no-torch)", "install unsloth (migrated no
}
Write-Host "the generated temp file never outlives the run"
-$removals = [regex]::Matches($installText, 'Remove-Item -LiteralPath \$script:TorchOverridesFile -Force')
+$removals = [regex]::Matches($installText, 'Remove-UnslothTempFileQuietly -Path \$script:TorchOverridesFile')
# One in-flow removal per with-deps install, plus the outer-finally sweep.
Check "in-flow removal after each with-deps install, plus a final sweep" ($removals.Count -eq 3)
+Check "no unguarded Remove-Item on the tracked overrides path survives" (
+ $installText -notmatch 'Remove-Item -LiteralPath \$script:TorchOverridesFile')
$outer = @($ast.FindAll({ param($n)
$n -is [System.Management.Automation.Language.TryStatementAst] -and
$n.Body.Extent.Text -match 'Install-UnslothStudio @args'
}, $true))
Check "outer try/finally around Install-UnslothStudio found" ($outer.Count -eq 1)
$finallyText = $outer[0].Finally.Extent.Text
-Check "outer finally removes the overrides temp file" ($finallyText -match 'Remove-Item -LiteralPath \$script:TorchOverridesFile -Force')
+Check "outer finally removes the overrides temp file" (
+ $finallyText -match 'Remove-UnslothTempFileQuietly -Path \$script:TorchOverridesFile')
+Check "outer finally removes the WOA session overrides the same way" (
+ $finallyText -match 'Remove-UnslothTempFileQuietly -Path \$script:WoaSessionOverrides')
Check "outer finally still clears UNSLOTH_KEPT_TORCH" ($finallyText -match 'Remove-Item Env:UNSLOTH_KEPT_TORCH')
# install.sh empties _UNSLOTH_TORCH_OVERRIDES before arming its traps so an inherited value is
# never rm'd; under `irm | iex` the same reset must precede the outer try.
Check "overrides path reset to null before the outer try" (
$installText -match '(?m)^\$script:TorchOverridesFile = \$null\r?\ntry \{\r?\n\s*Install-UnslothStudio @args')
+$guardAst = $ast.FindAll({ param($n)
+ $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
+ $n.Name -eq "Remove-UnslothTempFileQuietly"
+}, $true)
+Check "Remove-UnslothTempFileQuietly defined exactly once" ($guardAst.Count -eq 1)
+# WHERE it is defined is the whole point. A function nested inside Install-UnslothStudio lives in
+# that call's local scope and is gone the moment it returns, so the outer finally -- which runs
+# after exactly that -- would hit CommandNotFoundException and leave the credential-bearing
+# overrides file on disk. Defined at top level it is in scope both inside the installer and after
+# it returns, so assert the definition is not a descendant of any function (#11290).
+$guardEnclosing = $null
+$_guardParent = $guardAst[0].Parent
+while ($_guardParent) {
+ if ($_guardParent -is [System.Management.Automation.Language.FunctionDefinitionAst]) {
+ $guardEnclosing = $_guardParent.Name
+ break
+ }
+ $_guardParent = $_guardParent.Parent
+}
+Check "the guard is defined at top level, not nested inside a function" ($null -eq $guardEnclosing)
+if ($guardEnclosing) { Write-Host " enclosed by $guardEnclosing, so the outer finally cannot see it" -ForegroundColor Red }
+# Define it the way install.ps1 does, from its own source, rather than assuming this scope has it.
+Invoke-Expression $guardAst[0].Extent.Text
+
+Write-Host "Remove-UnslothTempFileQuietly is a no-op for anything that is not there"
+$liveFile = [System.IO.Path]::GetTempFileName()
+Remove-UnslothTempFileQuietly -Path $liveFile
+Check "a live temp file is removed" (-not (Test-Path -LiteralPath $liveFile))
+$helperThrew = $false
+$absent = Join-Path ([System.IO.Path]::GetTempPath()) ("unsloth-absent-" + [guid]::NewGuid().ToString("N") + ".txt")
+foreach ($candidate in @($absent, $null, "")) {
+ try { Remove-UnslothTempFileQuietly -Path $candidate } catch { $helperThrew = $true }
+}
+Check "a missing, null or empty path never throws" (-not $helperThrew)
+
Write-Host "outer finally actually deletes the file after a terminating error"
# Behavioural: run the real finally body with a live temp file holding a credential line.
$leakFile = [System.IO.Path]::GetTempFileName()
@@ -94,6 +147,123 @@ Check "kept-torch handoff still cleared" ($null -eq $env:UNSLOTH_KEPT_TORCH)
Check "tracked path reset so a rerun cannot re-remove it" ($null -eq $script:TorchOverridesFile)
Remove-Item -LiteralPath $leakFile -Force -ErrorAction SilentlyContinue
+Write-Host "and it deletes it in a scope built only from install.ps1's own top-level definitions"
+# The replay above runs in THIS scope, which was handed the guard by the Invoke-Expression higher
+# up -- a scope production does not have. A fresh runspace inherits nothing, so seeding it with
+# only install.ps1's top-level function definitions is what the script itself has when the outer
+# finally runs. Without the guard at top level, this leaves the file behind (#11290).
+$topLevelDefs = @($ast.FindAll({ param($n)
+ $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
+ -not ($n.Parent.Parent -is [System.Management.Automation.Language.FunctionDefinitionAst])
+}, $false) | Where-Object { $_.Name -ne "Install-UnslothStudio" } | ForEach-Object { $_.Extent.Text })
+$isolatedLeak = [System.IO.Path]::GetTempFileName()
+Set-Content -LiteralPath $isolatedLeak -Encoding ascii -Value "torch==2.11.0+cu128"
+$ps = [powershell]::Create()
+try {
+ $null = $ps.AddScript(@"
+`$ErrorActionPreference = 'Continue'
+$($topLevelDefs -join "`n")
+`$script:WoaResolverEnvSaved = `$null
+`$script:WoaSessionOverrides = `$null
+`$script:TorchOverridesFile = '$isolatedLeak'
+$finallyBody
+"@)
+ $null = $ps.Invoke()
+} finally { $ps.Dispose() }
+Check "the file is gone when the finally runs with install.ps1's own scope" (-not (Test-Path -LiteralPath $isolatedLeak))
+Remove-Item -LiteralPath $isolatedLeak -Force -ErrorAction SilentlyContinue
+
+Write-Host "an unresolvable tracked path cannot abort the cleanup (#11290)"
+# Shadow Remove-Item for the rest of the file. The reported failure is a *terminating* error the
+# FileSystem provider raises for a path it cannot resolve, which -ErrorAction cannot suppress, so a
+# mock that throws is the only way to reproduce that class on a host whose 8.3 names all resolve.
+$script:RemoveItemCalls = @()
+function Remove-Item {
+ param([Parameter(ValueFromRemainingArguments = $true)]$Rest)
+ $script:RemoveItemCalls += ($Rest -join ' ')
+ # The same finally also clears an Env: variable; only the file-system removal is under test.
+ if ($Rest -contains "Env:UNSLOTH_KEPT_TORCH") {
+ Microsoft.PowerShell.Management\Remove-Item -Path "Env:UNSLOTH_KEPT_TORCH" -ErrorAction SilentlyContinue
+ return
+ }
+ throw "simulated terminating PSArgumentException from FileSystemProvider"
+}
+$script:TorchOverridesFile = $absent
+$script:WoaSessionOverrides = $null
+$env:UNSLOTH_KEPT_TORCH = "2.11.0"
+$threw = $false
+try {
+ # The inner catch swallows only the simulation, so the outer one reports the finally body.
+ try { throw "simulated terminating error mid-install" }
+ catch { }
+ finally { Invoke-Expression $finallyBody }
+} catch { $threw = $true }
+Check "the outer finally does not throw on an unresolvable path" (-not $threw)
+Check "Remove-Item is never reached for a path that is not there" (
+ -not @($script:RemoveItemCalls | Where-Object { $_ -like "*unsloth-absent-*" }))
+Check "the tracked path is still cleared" ($null -eq $script:TorchOverridesFile)
+
+# The catch is what keeps the helper non-fatal, so force the throw with a path that does exist.
+$presentFile = [System.IO.Path]::GetTempFileName()
+$escaped = $false
+try { Remove-UnslothTempFileQuietly -Path $presentFile } catch { $escaped = $true }
+Check "a terminating Remove-Item error cannot escape the helper" (-not $escaped)
+Check "and the existing path really was attempted" (
+ @($script:RemoveItemCalls | Where-Object { $_ -like "*$([System.IO.Path]::GetFileName($presentFile))*" }).Count -ge 1)
+[System.IO.File]::Delete($presentFile)
+
+Write-Host "an unreadable alias path cannot abort the install (#11290)"
+# install.ps1:3277 documents it: under the installer's "Stop", Test-Path inside an ACL-denied
+# directory THROWS UnauthorizedAccessException rather than returning false. None of the 8.3
+# guards is inside a try, so a bare Test-Path there turns "reject this alias" into "abort the
+# whole install". Every guard added for #11290 must therefore carry -ErrorAction SilentlyContinue.
+$guardedPaths = [regex]::Matches($installText, 'Test-Path -LiteralPath \$(short|dirShort)\b[^\)]*\)')
+# Three is what #11290 added; the count is not the assertion, the absence of a bare one is.
+Check "the 8.3 guards were found" ($guardedPaths.Count -ge 3)
+$bareGuards = @($guardedPaths | Where-Object { $_.Value -notmatch '-ErrorAction SilentlyContinue' })
+Check "no 8.3 guard asks the filesystem without -ErrorAction SilentlyContinue" ($bareGuards.Count -eq 0)
+foreach ($b in $bareGuards) { Write-Host " bare: $($b.Value)" -ForegroundColor Red }
+
+# Behavioural, on this host: chmod 000 reproduces the same throw class PowerShell raises for a
+# Windows deny ACE. Skipped under a uid that bypasses permission bits, which would pass vacuously.
+# The probe is POSIX-only: `id` and `chmod` are not Windows commands, and this file runs under
+# "Stop", so calling them there is a terminating CommandNotFoundException that would abort the
+# suite on the very platform it is about. $IsWindows does not exist on 5.1, where the answer is
+# Windows by construction, so $env:OS answers for it. The text assertions above are the Windows
+# coverage; a real deny ACE is not reproduced anywhere here.
+if ($IsWindows -or $env:OS -eq "Windows_NT") {
+ Write-Host " SKIP Windows: chmod cannot build a denied directory here (the guards are pinned by text above)"
+} elseif ((& id -u) -eq "0") {
+ Write-Host " SKIP running as root: a denied directory is still readable, so this cannot fail"
+} else {
+ $deniedRoot = Join-Path ([System.IO.Path]::GetTempPath()) "denied_$([guid]::NewGuid().ToString('N'))"
+ [System.IO.Directory]::CreateDirectory($deniedRoot) | Out-Null
+ $deniedLeaf = Join-Path $deniedRoot "ov.tmp"
+ Set-Content -LiteralPath $deniedLeaf -Value "torch==2.10.0"
+ & chmod 000 $deniedRoot
+ try {
+ $prevEap = $ErrorActionPreference
+ $ErrorActionPreference = "Stop" # what install.ps1 line 18 sets
+ $bareThrew = $false
+ try { $null = Test-Path -LiteralPath $deniedLeaf -PathType Leaf } catch { $bareThrew = $true }
+ $guardedThrew = $false
+ try { $null = Test-Path -LiteralPath $deniedLeaf -PathType Leaf -ErrorAction SilentlyContinue } catch { $guardedThrew = $true }
+ $ErrorActionPreference = $prevEap
+ # A negative control that can fail: if the bare form stopped throwing on this host, the
+ # assertion above is no longer testing anything and must say so rather than pass quietly.
+ Check "a bare Test-Path really does throw here (negative control)" $bareThrew
+ Check "the guarded form does not throw" (-not $guardedThrew)
+ } finally {
+ & chmod 755 $deniedRoot
+ # Fully qualified: the mock above shadows Remove-Item for the rest of the file, and it is
+ # an advanced function, so -ErrorAction SilentlyContinue silences the throw it was written
+ # to raise. The cleanup then reported success and left the directory behind every run.
+ Microsoft.PowerShell.Management\Remove-Item -LiteralPath $deniedRoot -Recurse -Force -ErrorAction SilentlyContinue
+ }
+ Check "the denied directory is cleaned up rather than left behind" (
+ -not (Test-Path -LiteralPath $deniedRoot))
+}
+
Write-Host "the inherited-override filter drops the torch trio in any casing"
# PowerShell's -notmatch is case-insensitive, so a caller override `Torch<2.11` is dropped.
$filterPattern = $null