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 uv splitting a requirements path, and keep the error position in diagnostics (#11064)

Daniel Han040403021399
diff --git a/install.ps1 b/install.ps1
index 9a4a880bf2f..1e90654a03c 100644
--- a/install.ps1
+++ b/install.ps1
@@ -6885,6 +6885,74 @@ exit 0
# unsloth==2024.8, so install torch from the explicit index first. --upgrade-package (not
# --upgrade) so upgrading unsloth cannot re-resolve torch from PyPI and strip the +cuXXX.
# ── Helper: find no-torch-runtime.txt ──
+ # uv splits -r/-c/--overrides on whitespace with no way to quote, so the path must be
+ # space-free (#6503, #10722, #11012). Requirements only: relocating is safe because
+ # no-torch-runtime.txt has no relative includes, while uv resolves an override's relative
+ # references against its own directory, so New-UnslothTorchOverridesFile keeps its own
+ # handling. Mirrors uv_safe_path in studio/backend/utils/uv_path_safety.py. Returns whether
+ # it made a copy, so the caller never deletes the user's own file.
+ function Get-UvSafeRequirementsPath {
+ param([Parameter(Mandatory = $true)][string]$Path)
+ 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 } }
+
+ # 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
+ # non-system volumes. Each is used only once confirmed space-free and writable.
+ # Produced one at a time and guarded. Under this script's ErrorActionPreference = "Stop" a
+ # single throwing element in an array literal is evaluated before the loop starts and
+ # aborts the install outright, and these calls do throw on a relative or malformed TMP:
+ # GetPathRoot returns "" and Join-Path then rejects the empty path.
+ $candidates = @()
+ foreach ($produce in @(
+ { [System.IO.Path]::GetTempPath() },
+ { $env:TEMP },
+ { $env:TMP },
+ { $root = [System.IO.Path]::GetPathRoot([System.IO.Path]::GetTempPath())
+ if ($root) { Join-Path $root "Windows\Temp" } },
+ { [System.IO.Path]::GetDirectoryName($Path) }
+ )) {
+ try { $candidates += & $produce } catch { }
+ }
+ foreach ($candidate in $candidates) {
+ if (-not $candidate) { continue }
+ $dir = $candidate
+ if ($dir.Contains(" ")) {
+ $dirShort = $null
+ try { $dirShort = (New-Object -ComObject Scripting.FileSystemObject).GetFolder($dir).ShortPath } catch { }
+ if (-not $dirShort -or $dirShort.Contains(" ")) { continue }
+ $dir = $dirShort
+ }
+ # Declared before the try so the catch can clean up a Copy-Item that failed partway
+ # and left a partial destination, but built inside it: a candidate naming an unmapped
+ # drive makes Join-Path throw DriveNotFoundException, which under Stop would abort the
+ # install rather than move on to the next candidate.
+ $tmp = $null
+ try {
+ $tmp = Join-Path $dir ("unsloth-reqs-" + [guid]::NewGuid().ToString("N") + ".txt")
+ Copy-Item -LiteralPath $Path -Destination $tmp -Force -ErrorAction Stop
+ if ($tmp.Contains(" ")) {
+ Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue
+ continue
+ }
+ return @{ Path = $tmp; Temporary = $true }
+ } catch {
+ if ($tmp) { Remove-Item -LiteralPath $tmp -Force -ErrorAction SilentlyContinue }
+ continue
+ }
+ }
+
+ # Nowhere usable. Say so, because uv's message for a split path names a fragment of the
+ # install root and reads as a missing requirements file (#11012). The original is still
+ # returned, so the install behaves as it does today rather than failing somewhere new.
+ substep "[WARN] the requirements path contains a space and no space-free location was" "Yellow"
+ substep "available; uv splits such a path, so this install may fail. Set TMP and TEMP" "Yellow"
+ substep "to a path without spaces and run the installer again." "Yellow"
+ return @{ Path = $Path; Temporary = $false }
+ }
+
function Find-NoTorchRuntimeFile {
if ($StudioLocalInstall -and (Test-Path (Join-Path $RepoRoot "studio\backend\requirements\no-torch-runtime.txt"))) {
return Join-Path $RepoRoot "studio\backend\requirements\no-torch-runtime.txt"
@@ -6987,7 +7055,12 @@ exit 0
if ($baseInstallExit -eq 0) {
$NoTorchReq = Find-NoTorchRuntimeFile
if ($NoTorchReq) {
- $baseInstallExit = Invoke-InstallCommandRetry -Label "install no-torch runtime deps" { & $script:UvExe pip install --python $VenvPython --no-deps -r $NoTorchReq }
+ $NoTorchReqSafe = Get-UvSafeRequirementsPath -Path $NoTorchReq
+ $NoTorchReqArg = $NoTorchReqSafe.Path
+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install no-torch runtime deps" { & $script:UvExe pip install --python $VenvPython --no-deps -r $NoTorchReqArg }
+ if ($NoTorchReqSafe.Temporary) {
+ Remove-Item -LiteralPath $NoTorchReqArg -Force -ErrorAction SilentlyContinue
+ }
}
}
} else {
@@ -7179,7 +7252,12 @@ exit 0
if ($baseInstallExit -eq 0) {
$NoTorchReq = Find-NoTorchRuntimeFile
if ($NoTorchReq) {
- $baseInstallExit = Invoke-InstallCommandRetry -Label "install no-torch runtime deps" { & $script:UvExe pip install --python $VenvPython --no-deps -r $NoTorchReq }
+ $NoTorchReqSafe = Get-UvSafeRequirementsPath -Path $NoTorchReq
+ $NoTorchReqArg = $NoTorchReqSafe.Path
+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install no-torch runtime deps" { & $script:UvExe pip install --python $VenvPython --no-deps -r $NoTorchReqArg }
+ if ($NoTorchReqSafe.Temporary) {
+ Remove-Item -LiteralPath $NoTorchReqArg -Force -ErrorAction SilentlyContinue
+ }
}
}
} elseif ($StudioLocalInstall) {
diff --git a/studio/frontend/src/lib/tauri-diagnostics.ts b/studio/frontend/src/lib/tauri-diagnostics.ts
index 7e460e399bc..2e3b6b2ba25 100644
--- a/studio/frontend/src/lib/tauri-diagnostics.ts
+++ b/studio/frontend/src/lib/tauri-diagnostics.ts
@@ -60,11 +60,11 @@ export function redactDiagnosticsText(text: string): string {
"<studio_home>",
);
redacted = redacted.replace(
- /[A-Z]:\\Users\\[^\s\\]+\\\.unsloth\\studio/gi,
+ /[A-Z]:\\Users\\[^\s\\:]+\\\.unsloth\\studio/gi,
"<studio_home>",
);
redacted = redacted.replace(/(?:\/Users|\/home)\/[^\s/]+/gi, "$HOME");
- redacted = redacted.replace(/[A-Z]:\\Users\\[^\s\\]+/gi, "%USERPROFILE%");
+ redacted = redacted.replace(/[A-Z]:\\Users\\[^\s\\:]+/gi, "%USERPROFILE%");
redacted = redacted.replace(
/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi,
"<redacted-email>",
diff --git a/studio/src-tauri/src/diagnostics/redaction.rs b/studio/src-tauri/src/diagnostics/redaction.rs
index bd36f9254e7..0e3b1bca61b 100644
--- a/studio/src-tauri/src/diagnostics/redaction.rs
+++ b/studio/src-tauri/src/diagnostics/redaction.rs
@@ -157,13 +157,13 @@ fn native_path_lease_re() -> &'static Regex {
fn windows_studio_re() -> &'static Regex {
static RE: OnceLock<Regex> = OnceLock::new();
RE.get_or_init(|| {
- Regex::new(r"(?i)\b[A-Z]:[\\/]Users[\\/][^\\/\r\n\s]+[\\/]\.unsloth[\\/]studio").unwrap()
+ Regex::new(r"(?i)\b[A-Z]:[\\/]Users[\\/][^\\/:\r\n\s]+[\\/]\.unsloth[\\/]studio").unwrap()
})
}
fn windows_home_re() -> &'static Regex {
static RE: OnceLock<Regex> = OnceLock::new();
- RE.get_or_init(|| Regex::new(r"(?i)\b[A-Z]:[\\/]Users[\\/][^\\/\r\n\s]+").unwrap())
+ RE.get_or_init(|| Regex::new(r"(?i)\b[A-Z]:[\\/]Users[\\/][^\\/:\r\n\s]+").unwrap())
}
fn unix_studio_re() -> &'static Regex {
@@ -219,6 +219,40 @@ mod tests {
assert!(!redacted.contains("PRIVATE KEY-----\nabc"));
}
+ #[test]
+ fn windows_home_redaction_keeps_the_line_and_column_suffix() {
+ // A colon cannot appear inside a Windows path segment, but the Windows classes used to
+ // allow one, so a single-segment path swallowed whatever followed it. uv reports a bad
+ // requirements path as `<path>:<line>:<col>`, and issue #11012 arrived with the position
+ // and the file name already eaten, which is most of what made it expensive to diagnose.
+ // The Unix rules never had this because their class is [A-Za-z0-9._-].
+ let mut report = RedactionReport::default();
+ let redacted = redact_text(
+ "error: Unexpected '[' at C:\\Users\\Alex:1:1\n",
+ &mut report,
+ );
+ assert!(
+ !redacted.contains("Alex"),
+ "user name still present: {redacted}"
+ );
+ assert!(
+ redacted.contains("%USERPROFILE%:1:1"),
+ "line and column were redacted away: {redacted}"
+ );
+
+ // A deeper path was never affected, and must stay that way.
+ let mut report = RedactionReport::default();
+ let deep = redact_text(
+ "at C:\\Users\\Alex\\AppData\\Local\\Temp\\tmp1.tmp:1:1\n",
+ &mut report,
+ );
+ assert!(!deep.contains("Alex"), "user name still present: {deep}");
+ assert!(
+ deep.contains("\\AppData\\Local\\Temp\\tmp1.tmp:1:1"),
+ "{deep}"
+ );
+ }
+
#[test]
fn redaction_avoids_keyboard_monkey_false_positives() {
let input = "keyboard=present monkey=banana MONKEY=banana KEYBOARD=present API_KEY=secret";
diff --git a/tests/python/test_uv_requirements_path_space.py b/tests/python/test_uv_requirements_path_space.py
new file mode 100644
index 00000000000..dc9f6098ace
--- /dev/null
+++ b/tests/python/test_uv_requirements_path_space.py
@@ -0,0 +1,130 @@
+# Unsloth Zoo - Utilities for Unsloth
+# Copyright 2023-present Daniel Han-Chen, Michael Han-Chen & the Unsloth team. All rights reserved.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published
+# by the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+"""Every uv `-r` in install.ps1 goes through the space-safety helper (issue #11012).
+
+uv splits `-r`, `-c` and `--overrides` on whitespace and offers no quoting escape, so a path with a
+space arrives as two bogus requirement files. `--overrides` was fixed in #10765 by making the file
+install.ps1 writes space-free, but `-r $NoTorchReq` resolves under `$RepoRoot` or `$VenvDir`, both
+chosen by the user, and was still passed through verbatim.
+
+A static check rather than a behavioural one: the failure only reproduces on Windows with a spaced
+install root, and that lane is not where a future edit would be caught. Asserting on the call shape
+means the regression is caught wherever the test suite runs.
+"""
+
+from __future__ import annotations
+
+import re
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+INSTALL_PS1 = REPO_ROOT / "install.ps1"
+
+HELPER = "Get-UvSafeRequirementsPath"
+
+
+def _code_lines(text: str) -> list[str]:
+ """Drop whole-line comments so a commented example never satisfies an assertion."""
+ return [line for line in text.splitlines() if not line.lstrip().startswith("#")]
+
+
+def test_the_helper_is_defined():
+ lines = _code_lines(INSTALL_PS1.read_text(encoding = "utf-8"))
+ assert any(
+ re.match(rf"\s*function\s+{HELPER}\b", line) for line in lines
+ ), f"{HELPER} is missing from install.ps1"
+
+
+def test_every_uv_requirements_flag_uses_a_sanitised_path():
+ lines = _code_lines(INSTALL_PS1.read_text(encoding = "utf-8"))
+
+ # Variables the helper's result reaches, rather than a naming convention: first those assigned
+ # from the helper itself, then those assigned from the .Path of one of those. Keying on a name
+ # like "*Safe" would pass for a variable that merely looked sanitised.
+ from_helper = set()
+ for line in lines:
+ hit = re.search(rf"(\$[A-Za-z_][A-Za-z0-9_]*)\s*=\s*{HELPER}\b", line)
+ if hit:
+ from_helper.add(hit.group(1))
+ sanitised = set()
+ for line in lines:
+ hit = re.search(
+ r"(\$[A-Za-z_][A-Za-z0-9_]*)\s*=\s*(\$[A-Za-z_][A-Za-z0-9_]*)\.Path\b", line
+ )
+ if hit and hit.group(2) in from_helper:
+ sanitised.add(hit.group(1))
+ sanitised |= {f"{name}.Path" for name in from_helper}
+
+ # `-r <arg>` where the argument is a PowerShell variable. A literal path in the repo cannot
+ # carry a user-chosen space, so only variables are of interest here.
+ uses = [(n, line) for n, line in enumerate(lines, 1) if re.search(r"\s-r\s+\$", line)]
+ assert uses, "no uv -r call sites found; this test is no longer measuring anything"
+
+ unsafe = []
+ for number, line in uses:
+ arg = re.search(r"\s-r\s+(\$[A-Za-z_][A-Za-z0-9_:]*(?:\.Path)?)", line)
+ if arg and arg.group(1) not in sanitised:
+ unsafe.append(f"line {number}: {line.strip()}")
+ assert not unsafe, (
+ "uv -r is handed a path that never passed through "
+ f"{HELPER}, so an install root containing a space truncates it:\n" + "\n".join(unsafe)
+ )
+
+
+def test_a_copy_is_removed_but_the_users_own_file_is_not():
+ """The helper may return a copy; only a copy may be deleted."""
+ text = INSTALL_PS1.read_text(encoding = "utf-8")
+ body = text[text.index(f"function {HELPER}") :]
+ body = body[: body.index("\n function ")]
+ assert "Temporary = $true" in body, "the helper never reports that it made a copy"
+ assert "Temporary = $false" in body, "the helper never reports a pass-through path"
+
+ for line in _code_lines(text):
+ if "Remove-Item" in line and "NoTorchReqArg" in line:
+ break
+ else:
+ raise AssertionError("a temporary copy is created but never removed")
+
+ guarded = re.search(r"if \(\$NoTorchReqSafe\.Temporary\) \{\s*\n\s*Remove-Item", text)
+ assert guarded, (
+ "the Remove-Item is not guarded on .Temporary, so a pass-through path "
+ "would delete the user's own requirements file"
+ )
+
+
+def test_the_helper_behaviour_suite_runs():
+ """Run the PowerShell unit test under pytest so the CPU test job executes it.
+
+ The static checks above assert the call shape; this one exercises the helper itself,
+ including the fallback chain and the give-up warning.
+ """
+ import shutil
+ import subprocess
+
+ import pytest
+
+ if shutil.which("pwsh") is None:
+ pytest.skip("pwsh not available")
+ script = REPO_ROOT / "tests" / "studio" / "test_uv_safe_requirements_path.ps1"
+ assert script.is_file(), f"missing: {script}"
+ proc = subprocess.run(
+ ["pwsh", "-NoProfile", "-File", str(script)],
+ capture_output = True,
+ text = True,
+ )
+ assert proc.returncode == 0, proc.stdout + proc.stderr
+ assert "All Get-UvSafeRequirementsPath checks passed" in proc.stdout, proc.stdout
diff --git a/tests/studio/test_uv_safe_requirements_path.ps1 b/tests/studio/test_uv_safe_requirements_path.ps1
new file mode 100644
index 00000000000..1e0afcda76c
--- /dev/null
+++ b/tests/studio/test_uv_safe_requirements_path.ps1
@@ -0,0 +1,168 @@
+#!/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
+# Unit test for install.ps1's Get-UvSafeRequirementsPath (issue #11012). uv splits -r on
+# whitespace with no way to quote around it, so a requirements path under a user-chosen
+# $RepoRoot or $VenvDir has to be made space-free before it is handed over.
+#
+# The contract under test: a space-free path is returned untouched and never marked temporary,
+# a spaced path never comes back spaced while any space-free writable directory exists, a copy
+# is reported as temporary so only a copy is ever deleted, and when nothing space-free can be
+# found the original comes back with a warning rather than silently.
+# Run: pwsh -NoProfile -File tests/studio/test_uv_safe_requirements_path.ps1
+
+$ErrorActionPreference = "Stop"
+$installPath = [System.IO.Path]::Combine($PSScriptRoot, "..", "..", "install.ps1")
+$installPath = (Resolve-Path $installPath).Path
+
+# Parse install.ps1 (also a syntax gate) and extract the helper.
+$tokens = $null; $errors = $null
+$ast = [System.Management.Automation.Language.Parser]::ParseFile($installPath, [ref]$tokens, [ref]$errors)
+if ($errors) { $errors | ForEach-Object { $_.ToString() }; throw "install.ps1 has parse errors" }
+
+$fn = $ast.FindAll({ param($n)
+ $n -is [System.Management.Automation.Language.FunctionDefinitionAst] -and
+ $n.Name -eq "Get-UvSafeRequirementsPath"
+}, $true)
+if ($fn.Count -ne 1) { throw "expected exactly one Get-UvSafeRequirementsPath in install.ps1, found $($fn.Count)" }
+Invoke-Expression $fn[0].Extent.Text
+
+# The helper reports the give-up case through the installer's own output helper. Capture it here
+# rather than stubbing it away, so the warning is part of the contract and not an implementation
+# detail a later edit can drop unnoticed.
+$script:Warnings = @()
+function substep { param([string]$Text, [string]$Colour) $script:Warnings += $Text }
+
+$failures = 0
+function Check($name, $cond) {
+ if ($cond) { Write-Host " PASS $name" }
+ else { Write-Host " FAIL $name" -ForegroundColor Red; $script:failures++ }
+}
+
+$root = Join-Path ([System.IO.Path]::GetTempPath()) ("uvsafe-" + [guid]::NewGuid().ToString("N"))
+New-Item -ItemType Directory -Force -Path $root | Out-Null
+try {
+ # 1. A path with no space is the common case and must be handed through untouched.
+ $plainDir = Join-Path $root "plain"
+ New-Item -ItemType Directory -Force -Path $plainDir | Out-Null
+ $plain = Join-Path $plainDir "no-torch-runtime.txt"
+ "typer" | Set-Content -LiteralPath $plain
+ $r = Get-UvSafeRequirementsPath -Path $plain
+ Check "a space-free path is returned unchanged" ($r.Path -eq $plain)
+ Check "a space-free path is never marked temporary" (-not $r.Temporary)
+ Check "the untouched path emits no warning" ($script:Warnings.Count -eq 0)
+
+ # 2. A spaced path must not come back spaced while somewhere space-free is writable.
+ $spacedDir = Join-Path $root "has space"
+ New-Item -ItemType Directory -Force -Path $spacedDir | Out-Null
+ $spaced = Join-Path $spacedDir "no-torch-runtime.txt"
+ "typer" | Set-Content -LiteralPath $spaced
+ $r2 = Get-UvSafeRequirementsPath -Path $spaced
+ Check "a spaced path never comes back containing a space" (-not $r2.Path.Contains(" "))
+ Check "the relocated copy carries the same content" ((Get-Content -Raw -LiteralPath $r2.Path).Trim() -eq "typer")
+
+ # 3. Only a copy may be deleted. Deleting what the helper reported must leave the user's file.
+ if ($r2.Temporary) {
+ Remove-Item -LiteralPath $r2.Path -Force
+ Check "deleting the copy leaves the original in place" (Test-Path -LiteralPath $spaced)
+ } else {
+ Check "a relocated path is reported as temporary" $false
+ }
+
+ # 4. Every candidate unusable: the original comes back, and the user is told why. Without the
+ # warning this case is indistinguishable from success until uv fails with a message that
+ # names a fragment of the install root, which is what made #11012 hard to read.
+ $script:Warnings = @()
+ # TMPDIR as well as TEMP/TMP: .NET reads TMPDIR for GetTempPath off Windows, so without it
+ # this case quietly takes the success branch on Linux and never exercises the warning.
+ $savedTemp = $env:TEMP; $savedTmp = $env:TMP; $savedTmpDir = $env:TMPDIR
+ try {
+ $env:TEMP = $spacedDir
+ $env:TMP = $spacedDir
+ $env:TMPDIR = $spacedDir
+ $r3 = Get-UvSafeRequirementsPath -Path $spaced
+ if ($r3.Path.Contains(" ")) {
+ Check "the original is returned when nowhere space-free is usable" ($r3.Path -eq $spaced)
+ Check "the give-up path is not marked temporary" (-not $r3.Temporary)
+ Check "the give-up path warns the user" (($script:Warnings -join " ") -match "space")
+ Check "the warning names the variables to change" (($script:Warnings -join " ") -match "TMP")
+ } else {
+ # A host that still found somewhere space-free (an 8.3 name, or a space-free drive
+ # root) is a pass for the contract that matters: the path handed to uv has no space.
+ Check "a space-free path was still found, which satisfies the contract" $true
+ }
+ } finally {
+ $env:TEMP = $savedTemp; $env:TMP = $savedTmp; $env:TMPDIR = $savedTmpDir
+ }
+ # 5. A failed copy must return the original, report it as not temporary, and leave nothing
+ # behind. Every candidate points at a path that exists as a FILE, so Copy-Item throws.
+ #
+ # Honest limit: in this scenario Copy-Item fails before creating anything, so these two
+ # checks pass with or without the cleanup in the catch and do not prove it. They pin the
+ # reachable contract. The cleanup exists for a copy that fails PARTWAY, a full disk or an
+ # interrupted write, which leaves a partial destination; that cannot be forced portably
+ # here, so it is defensive rather than covered.
+ $script:Warnings = @()
+ $blocker = Join-Path $root "blocker"
+ "not a directory" | Set-Content -LiteralPath $blocker
+ $savedTemp = $env:TEMP; $savedTmp = $env:TMP; $savedTmpDir = $env:TMPDIR
+ try {
+ $env:TEMP = $blocker
+ $env:TMP = $blocker
+ $env:TMPDIR = $blocker
+ $before = @(Get-ChildItem -LiteralPath $root -Recurse -File -Filter "unsloth-reqs-*").Count
+ $r4 = Get-UvSafeRequirementsPath -Path $spaced
+ $after = @(Get-ChildItem -LiteralPath $root -Recurse -File -Filter "unsloth-reqs-*").Count
+ Check "a failed copy leaves no stray unsloth-reqs file" ($after -eq $before)
+ Check "a failed copy is never reported as temporary" (-not $r4.Temporary)
+ } finally {
+ $env:TEMP = $savedTemp; $env:TMP = $savedTmp; $env:TMPDIR = $savedTmpDir
+ }
+ # 6. A relative or malformed temp path must not abort the install. install.ps1 runs under
+ # ErrorActionPreference = "Stop", so a throwing expression in the candidate list would be
+ # evaluated before the loop and terminate the whole run, which is worse than the split
+ # path this helper exists to prevent. GetPathRoot returns "" for a relative path and
+ # Join-Path then rejects it, so this is reachable from a machine with an odd TMP.
+ $script:Warnings = @()
+ $savedTemp = $env:TEMP; $savedTmp = $env:TMP; $savedTmpDir = $env:TMPDIR
+ try {
+ $ErrorActionPreference = "Stop"
+ $env:TEMP = "relative-temp-dir"
+ $env:TMP = "relative-temp-dir"
+ $env:TMPDIR = "relative-temp-dir"
+ $threw = $false
+ try { $r5 = Get-UvSafeRequirementsPath -Path $spaced } catch { $threw = $true }
+ Check "a relative temp path does not abort the helper" (-not $threw)
+ if (-not $threw) {
+ Check "a relative temp path still yields a usable result" ($null -ne $r5.Path)
+ }
+ } finally {
+ $env:TEMP = $savedTemp; $env:TMP = $savedTmp; $env:TMPDIR = $savedTmpDir
+ }
+ # 7. A temp path on an unmapped drive must not abort the install either. Join-Path resolves
+ # the drive qualifier, so it throws DriveNotFoundException for a stale or disconnected
+ # drive, and under ErrorActionPreference = "Stop" that would terminate the run before the
+ # loop could reach a candidate that works.
+ $script:Warnings = @()
+ $savedTemp = $env:TEMP; $savedTmp = $env:TMP; $savedTmpDir = $env:TMPDIR
+ try {
+ $ErrorActionPreference = "Stop"
+ $env:TEMP = "Z:\stale"
+ $env:TMP = "Z:\stale"
+ $env:TMPDIR = "Z:\stale"
+ $threw = $false
+ try { $r6 = Get-UvSafeRequirementsPath -Path $spaced } catch { $threw = $true }
+ Check "an unmapped temp drive does not abort the helper" (-not $threw)
+ if (-not $threw) {
+ Check "an unmapped temp drive still yields a result" ($null -ne $r6.Path)
+ }
+ } finally {
+ $env:TEMP = $savedTemp; $env:TMP = $savedTmp; $env:TMPDIR = $savedTmpDir
+ }
+} finally {
+ Remove-Item -LiteralPath $root -Recurse -Force -ErrorAction SilentlyContinue
+}
+
+if ($failures -gt 0) { Write-Host "$failures check(s) failed" -ForegroundColor Red; exit 1 }
+Write-Host "All Get-UvSafeRequirementsPath checks passed"
+exit 0