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 installing Git and the VS toolchain without asking (#12971)

Leo Borcherdingc1302eec32dc
diff --git a/studio/setup.ps1 b/studio/setup.ps1
index 63680bcb118..ad0c2647ff6 100644
--- a/studio/setup.ps1
+++ b/studio/setup.ps1
@@ -2760,6 +2760,69 @@ function Find-VsBuildTools {
return $null
}
+# Same ceiling Resolve-CudaToolkit reads: nvidia-smi, else the driver library.
+function Get-LlamaDriverMaxCuda {
+ $smi = ""
+ if ($NvidiaSmiExe -and (Get-Command Invoke-NvidiaSmiBounded -ErrorAction SilentlyContinue)) {
+ try { $smi = Invoke-NvidiaSmiBounded $NvidiaSmiExe } catch { }
+ }
+ if ($smi -match "CUDA(?: UMD)? Version:\s+(\d+)\.(\d+)") { return "$($Matches[1]).$($Matches[2])" }
+ if (Get-Command Get-NvidiaLibraryInventory -ErrorAction SilentlyContinue) {
+ $inv = Get-NvidiaLibraryInventory
+ if ($inv) { return "$($inv.CudaMajor).$($inv.CudaMinor)" }
+ }
+ return $null
+}
+
+function Get-NvccMajor {
+ param([string]$Nvcc)
+ try { if ((& $Nvcc --version 2>&1 | Out-String) -match 'release\s+(\d+)\.') { return [int]$Matches[1] } } catch { }
+ return $null
+}
+
+function Test-LlamaBuildToolsMissing {
+ if ($null -eq (Get-Command git -ErrorAction SilentlyContinue)) { return $true }
+ if ($null -eq (Get-Command cmake -ErrorAction SilentlyContinue)) { return $true }
+ # A CUDA source build installs the Toolkit (several GB) when no nvcc is found.
+ $nvccExe = $null
+ if ($HasNvidiaDriverEvidence) {
+ # A toolkit newer than the driver is rejected by Resolve-CudaToolkit, which then installs one.
+ $max = Get-LlamaDriverMaxCuda
+ $nvccExe = if ($max) { Find-Nvcc -MaxVersion $max } else { $null }
+ if (-not $nvccExe) {
+ $nvccExe = Find-Nvcc
+ $major = if ($nvccExe -and $max) { Get-NvccMajor $nvccExe } else { $null }
+ if ($max -and ($null -eq $major -or $major -gt [int]$max.Split('.')[0])) { $nvccExe = $null }
+ }
+ }
+ if ($HasNvidiaDriverEvidence -and -not $nvccExe) { return $true }
+ # Phase 4 upgrades a CMake too old for VS 2026 via winget.
+ if ($CmakeGenerator -match 'Visual Studio 18\b' -and -not (Test-CmakeCanDriveGenerator -Generator $CmakeGenerator)) { return $true }
+ # Resolve-CudaToolkit copies missing CUDA .targets into VS, elevating when denied.
+ $cudaRoot = if ($nvccExe) { Split-Path (Split-Path $nvccExe -Parent) -Parent } else { $null }
+ if ($cudaRoot -and $script:VsInstallPath) {
+ $extras = Join-Path $cudaRoot "extras\visual_studio_integration\MSBuildExtensions"
+ $custom = Get-VcBuildCustomizationsDir -VsInstallPath $script:VsInstallPath -Generator $CmakeGenerator
+ if ((Test-Path $extras) -and (Test-Path $custom) -and
+ -not (Get-ChildItem $custom -Filter "CUDA *.targets" -ErrorAction SilentlyContinue)) { return $true }
+ }
+ return (-not $script:VsInstallPath) -and (-not (Find-VsBuildTools))
+}
+
+function Test-SetupConsoleHeadless {
+ return (-not [Environment]::UserInteractive) -or [Console]::IsInputRedirected -or [Console]::IsOutputRedirected
+}
+
+# A failed prebuilt is not consent to a multi-GB toolchain. No prompt (#8040): headless runs
+# outside Desktop keep installing; a terminal or Desktop opts in via UNSLOTH_INSTALL_BUILD_TOOLS.
+function Test-LlamaBuildToolsInstallAllowed {
+ $opt = "$env:UNSLOTH_INSTALL_BUILD_TOOLS".Trim().ToLowerInvariant()
+ if ($opt -in @("1", "true", "yes")) { return $true }
+ if ($opt -in @("0", "false", "no")) { return $false }
+ if ((@("1", "true") -contains $env:UNSLOTH_TAURI_MODE) -or (@("1", "true") -contains $env:UNSLOTH_TAURI_UPDATE)) { return $false }
+ return (Test-SetupConsoleHeadless)
+}
+
# Deferred from Phase 1 so the prebuilt path never pays for the multi-GB install.
function Ensure-BuildToolsForLlamaSourceBuild {
# CMake
@@ -4987,6 +5050,7 @@ if ($LongPathsEnabled) {
step "long paths" "disabled; already asked earlier in this update" "Yellow"
} else {
Write-StudioLine "Windows Long Paths not enabled (required for Triton compilation and deep dependency paths)." -ForegroundColor Yellow
+ Write-StudioLine " This turns on LongPathsEnabled under HKLM, a machine-wide setting, so Windows asks for admin approval." -ForegroundColor Yellow
Write-StudioLine " Requesting admin access to fix..." -ForegroundColor Yellow
try {
$proc = Start-Process -FilePath "reg.exe" `
@@ -5050,10 +5114,8 @@ if (-not $HasGit) {
if ($gitNeeded -and $StageRoot) {
Exit-SetupFailure "Background staging cannot install Git; retry with the foreground updater."
}
- # Optional here; the first pass already tried and the installer prompts for UAC.
- if ($env:UNSLOTH_SETUP_RERUN -eq '1' -and -not $gitNeeded) {
- step "git" "not found; already tried earlier in this update" "Yellow"
- } elseif ($gitNeeded -or -not $StageRoot) {
+ # Only when something here clones: a machine-wide Git install is not ours to add otherwise.
+ if ($gitNeeded) {
Write-StudioLine "Git not found -- attempting install via winget..." -ForegroundColor Yellow
$HasWinget = $null -ne (Get-Command winget -ErrorAction SilentlyContinue)
if ($HasWinget) {
@@ -9676,6 +9738,7 @@ $ErrorActionPreference = $script:PrevEAP_T5
# Reuse the managed path resolved and preflighted before phase 1.
if (-not (Test-Path -LiteralPath $UnslothHome)) { [System.IO.Directory]::CreateDirectory($UnslothHome) | Out-Null }
$NeedLlamaSourceBuild = $false
+$script:LlamaSourceBuildIsFallback = $false
$SkipPrebuiltInstall = $false
$RequestedLlamaTag = if ($env:UNSLOTH_LLAMA_TAG) { $env:UNSLOTH_LLAMA_TAG } else { $DefaultLlamaTag }
# Every host installs the fork's app-* prebuilts; ggml-org artifacts are no longer the default.
@@ -10114,6 +10177,7 @@ if ($LocalLlamaCppLinked) {
# which this script cannot see -- exits 5 above instead.
substep "Prebuilt llama.cpp path unavailable or failed validation -- falling back to source build" "Yellow"
$NeedLlamaSourceBuild = $true
+ $script:LlamaSourceBuildIsFallback = $true
}
} else {
step "llama.cpp" "prebuilt helper failed unexpectedly" "Red"
@@ -10279,12 +10343,16 @@ if ($StageRoot -and $NeedLlamaSourceBuild) {
Exit-SetupFailure "Background staging cannot install system build tools for llama.cpp; retry with the foreground updater."
}
+# Asked before Phase 3.5: OpenSSL is a system install too.
+$script:LlamaBuildToolsDeclined = $NeedLlamaSourceBuild -and $script:LlamaSourceBuildIsFallback -and (Test-LlamaBuildToolsMissing) -and
+ -not (Test-LlamaBuildToolsInstallAllowed)
+
# ==========================================================================
# PHASE 3.5: Install OpenSSL dev (for HTTPS support in llama-server)
# ==========================================================================
$OpenSslAvailable = $false
-if ($NeedLlamaSourceBuild) {
+if ($NeedLlamaSourceBuild -and -not $script:LlamaBuildToolsDeclined) {
$OpenSslRoots = @(
'C:\Program Files\OpenSSL-Win64',
'C:\Program Files\OpenSSL',
@@ -10301,6 +10369,9 @@ if ($NeedLlamaSourceBuild) {
if ($OpenSslRoot) {
$OpenSslAvailable = $true
substep "OpenSSL dev found at $OpenSslRoot"
+ } elseif ($script:LlamaSourceBuildIsFallback -and -not (Test-LlamaBuildToolsInstallAllowed)) {
+ # Optional for the build, so it is skipped rather than declining the whole build.
+ substep "OpenSSL dev not found; building without HTTPS (UNSLOTH_INSTALL_BUILD_TOOLS=1 installs it)" "Yellow"
} else {
Write-StudioLine ""
substep "installing OpenSSL dev (for HTTPS in llama-server)..."
@@ -10379,6 +10450,7 @@ if ($CanReuseLlamaBuild -and $NeedLlamaSourceBuild -and -not $LocalLlamaCppLinke
$CanReuseLlamaBuild = Test-LlamaTreeStillHealthy $LlamaCppDir
}
$WillBuildLlamaFromSource = $NeedLlamaSourceBuild -and -not $CanReuseLlamaBuild
+if ($script:LlamaBuildToolsDeclined -and -not $CanReuseLlamaBuild) { $WillBuildLlamaFromSource = $false }
if ($WillBuildLlamaFromSource) {
if (-not $HasGitForBuild) {
# Phase 1 keeps git optional, so only the automatic fallback after a failed prebuilt
@@ -10419,6 +10491,13 @@ if ($LocalLlamaCppLinked) {
# $CanReuseLlamaBuild above, so refusing here also planned the toolchain.
Write-StudioLine ""
step "llama.cpp" "already built"
+} elseif ($script:LlamaBuildToolsDeclined) {
+ Write-StudioLine ""
+ step "llama.cpp" "build skipped (build tools not installed)" "Yellow"
+ substep "The prebuilt download failed, and a source build needs Git, CMake and Visual Studio Build Tools." "Yellow"
+ substep "GGUF inference and export will not be available." "Yellow"
+ substep "To install them and build from source, set UNSLOTH_INSTALL_BUILD_TOOLS=1 and re-run setup." "Yellow"
+ $script:LlamaCppDegraded = $true
} elseif (-not $HasGitForBuild) {
# Before cmake: the toolchain install is skipped without git, so cmake may be missing
# purely as a consequence. Degrade rather than abort; the opt-in source triggers already
@@ -11014,6 +11093,8 @@ if ($script:LlamaCppDegraded -and $env:SKIP_STUDIO_BASE -eq "1") {
[Console]::Out.WriteLine("[TAURI:PROGRESS] llama.cpp unavailable; GGUF inference is disabled until 'unsloth studio update' succeeds")
[Console]::Out.WriteLine("[TAURI:DIAG] llama_cpp=unavailable")
[Console]::Out.Flush()
+ } elseif ($script:LlamaBuildToolsDeclined) {
+ step "llama.cpp" "unavailable; GGUF inference is disabled until the build tools are installed" "Yellow"
} else {
Exit-SetupFailure "llama.cpp setup did not produce a usable server"
}
diff --git a/tests/sh/test_setup_staged_root.sh b/tests/sh/test_setup_staged_root.sh
index 8f7e475a191..2d9a1b89d99 100755
--- a/tests/sh/test_setup_staged_root.sh
+++ b/tests/sh/test_setup_staged_root.sh
@@ -103,8 +103,8 @@ check "setup.ps1 leaves long-path policy unchanged while staging" \
"$(has "$SETUP_PS1" 'step "long paths" "disabled; unchanged during staging"')"
check "setup.ps1 does not install Git while staging" \
"$(has "$SETUP_PS1" 'Background staging cannot install Git; retry with the foreground updater.')"
-check "setup.ps1 preserves foreground Git bootstrap" \
- "$(has "$SETUP_PS1" 'if ($gitNeeded -or -not $StageRoot) {')"
+check "setup.ps1 installs Git in the foreground only when a clone needs it" \
+ "$(grep -qF 'if ($gitNeeded -or -not $StageRoot) {' "$SETUP_PS1" && echo 1 || echo 0)"
# The branch that decides TORCHINDUCTOR_CACHE_DIR, by what it does rather than by its old
# spelling: a staged run must take the stage root and must be asked FIRST, ahead of the Studio
# cache and the short drive-root fallback that a normal install chooses between.
diff --git a/tests/studio_setup_ps1/Studio.Setup.BuildToolsConsent.Tests.ps1 b/tests/studio_setup_ps1/Studio.Setup.BuildToolsConsent.Tests.ps1
new file mode 100644
index 00000000000..c43af7622f4
--- /dev/null
+++ b/tests/studio_setup_ps1/Studio.Setup.BuildToolsConsent.Tests.ps1
@@ -0,0 +1,172 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+#Requires -Modules @{ ModuleName = 'Pester'; ModuleVersion = '5.0' }
+# A failed llama.cpp prebuilt must not install a machine-wide toolchain without consent.
+
+BeforeAll {
+ . (Join-Path $PSScriptRoot 'Get-FunctionSource.ps1')
+ $script:SetupPs1 = Join-Path $PSScriptRoot '..\..\studio\setup.ps1'
+ . ([scriptblock]::Create((Get-FunctionSource -Path $script:SetupPs1 -Name 'Test-LlamaBuildToolsInstallAllowed')))
+ . ([scriptblock]::Create((Get-FunctionSource -Path $script:SetupPs1 -Name 'Test-LlamaBuildToolsMissing')))
+ . ([scriptblock]::Create((Get-FunctionSource -Path $script:SetupPs1 -Name 'Test-SetupConsoleHeadless')))
+ . ([scriptblock]::Create((Get-FunctionSource -Path $script:SetupPs1 -Name 'Get-VcBuildCustomizationsDir')))
+ function Get-LlamaDriverMaxCuda { $null }
+ function Write-StudioLine { param([string]$Text, [string]$ForegroundColor) }
+ $script:SetupText = Get-Content -LiteralPath $script:SetupPs1 -Raw
+}
+
+Describe 'Test-LlamaBuildToolsInstallAllowed' {
+ BeforeEach {
+ foreach ($k in 'UNSLOTH_INSTALL_BUILD_TOOLS', 'UNSLOTH_TAURI_MODE', 'UNSLOTH_TAURI_UPDATE') {
+ Remove-Item "Env:$k" -ErrorAction SilentlyContinue
+ }
+ }
+ AfterAll {
+ foreach ($k in 'UNSLOTH_INSTALL_BUILD_TOOLS', 'UNSLOTH_TAURI_MODE', 'UNSLOTH_TAURI_UPDATE') {
+ Remove-Item "Env:$k" -ErrorAction SilentlyContinue
+ }
+ }
+
+ It 'UNSLOTH_INSTALL_BUILD_TOOLS=<Value> answers without a prompt' -ForEach @(
+ @{ Value = '1'; Expected = $true }, @{ Value = 'yes'; Expected = $true },
+ @{ Value = '0'; Expected = $false }, @{ Value = 'no'; Expected = $false }
+ ) {
+ Mock Read-Host { throw 'prompted' }
+ $env:UNSLOTH_INSTALL_BUILD_TOOLS = $Value
+ Test-LlamaBuildToolsInstallAllowed | Should -Be $Expected
+ Should -Invoke Read-Host -Times 0 -Exactly
+ }
+
+ It 'declines in Unsloth Desktop (<Var>) instead of prompting' -ForEach @(
+ @{ Var = 'UNSLOTH_TAURI_MODE' }, @{ Var = 'UNSLOTH_TAURI_UPDATE' }
+ ) {
+ Mock Read-Host { throw 'prompted' }
+ Set-Item "Env:$Var" '1'
+ Test-LlamaBuildToolsInstallAllowed | Should -BeFalse
+ Should -Invoke Read-Host -Times 0 -Exactly
+ }
+
+ It 'a <Kind> run outside Unsloth Desktop answers <Expected> without a prompt' -ForEach @(
+ @{ Kind = 'headless'; Headless = $true; Expected = $true },
+ @{ Kind = 'terminal'; Headless = $false; Expected = $false }
+ ) {
+ Mock Read-Host { throw 'prompted' }
+ Mock Test-SetupConsoleHeadless { $Headless }
+ Test-LlamaBuildToolsInstallAllowed | Should -Be $Expected
+ Should -Invoke Read-Host -Times 0 -Exactly
+ }
+
+ It 'setup.ps1 never asks about the build tools' {
+ $body = Get-FunctionSource -Path $script:SetupPs1 -Name 'Test-LlamaBuildToolsInstallAllowed'
+ $body | Should -Not -Match 'Read-Host'
+ }
+
+ It 'the opt-in still wins inside Unsloth Desktop' {
+ $env:UNSLOTH_TAURI_MODE = '1'
+ $env:UNSLOTH_INSTALL_BUILD_TOOLS = '1'
+ Test-LlamaBuildToolsInstallAllowed | Should -BeTrue
+ }
+}
+
+Describe 'Test-LlamaBuildToolsMissing' {
+ It 'reports missing when <Case>' -ForEach @(
+ @{ Case = 'git is absent'; Git = $false; Cmake = $true; Vs = 'C:\VS'; Expected = $true },
+ @{ Case = 'cmake is absent'; Git = $true; Cmake = $false; Vs = 'C:\VS'; Expected = $true },
+ @{ Case = 'Build Tools are absent'; Git = $true; Cmake = $true; Vs = $null; Expected = $true },
+ @{ Case = 'the CUDA Toolkit is absent on NVIDIA'; Git = $true; Cmake = $true; Vs = 'C:\VS'; Nvidia = $true; Nvcc = $null; Expected = $true },
+ @{ Case = 'nothing is absent on NVIDIA'; Git = $true; Cmake = $true; Vs = 'C:\VS'; Nvidia = $true; Nvcc = 'C:\nvcc.exe'; Expected = $false },
+ @{ Case = 'nothing is absent'; Git = $true; Cmake = $true; Vs = 'C:\VS'; Expected = $false }
+ ) {
+ Mock Get-Command { if ($Git) { [pscustomobject]@{ Name = 'git' } } } -ParameterFilter { $Name -eq 'git' }
+ Mock Get-Command { if ($Cmake) { [pscustomobject]@{ Name = 'cmake' } } } -ParameterFilter { $Name -eq 'cmake' }
+ function Find-VsBuildTools { $null }
+ function Find-Nvcc { $Nvcc }
+ $HasNvidiaDriverEvidence = [bool]$Nvidia
+ $script:VsInstallPath = $Vs
+ Test-LlamaBuildToolsMissing | Should -Be $Expected
+ }
+
+ It 'a CUDA toolkit newer than the driver counts as missing (toolkit <Major>, driver 12.8)' -ForEach @(
+ @{ Major = 13; Expected = $true }, @{ Major = 12; Expected = $false }
+ ) {
+ Mock Get-Command { [pscustomobject]@{ Name = $Name } } -ParameterFilter { $Name -in 'git', 'cmake' }
+ function Find-VsBuildTools { $null }
+ function Find-Nvcc { param([string]$MaxVersion) if ($MaxVersion) { $null } else { 'C:\CUDA\v13.0\bin\nvcc.exe' } }
+ function Get-LlamaDriverMaxCuda { '12.8' }
+ function Get-NvccMajor { param($Nvcc) $Major }
+ $HasNvidiaDriverEvidence = $true
+ $CmakeGenerator = $null
+ $script:VsInstallPath = $TestDrive
+ Test-LlamaBuildToolsMissing | Should -Be $Expected
+ }
+
+ It 'reports missing when CMake cannot drive the VS 2026 generator (<CanDrive>)' -ForEach @(
+ @{ CanDrive = $false; Expected = $true }, @{ CanDrive = $true; Expected = $false }
+ ) {
+ Mock Get-Command { [pscustomobject]@{ Name = $Name } } -ParameterFilter { $Name -in 'git', 'cmake' }
+ function Find-VsBuildTools { $null }
+ function Find-Nvcc { $null }
+ function Test-CmakeCanDriveGenerator { param($Generator) $CanDrive }
+ $HasNvidiaDriverEvidence = $false
+ $CmakeGenerator = 'Visual Studio 18 2026'
+ $script:VsInstallPath = 'C:\VS'
+ Test-LlamaBuildToolsMissing | Should -Be $Expected
+ }
+
+ It 'reports missing when VS lacks the CUDA integration Resolve-CudaToolkit would copy (<Targets>)' -ForEach @(
+ @{ Targets = $false; Expected = $true }, @{ Targets = $true; Expected = $false }
+ ) {
+ Mock Get-Command { [pscustomobject]@{ Name = $Name } } -ParameterFilter { $Name -in 'git', 'cmake' }
+ $cuda = Join-Path $TestDrive 'CUDA\v12.8'
+ $vs = Join-Path $TestDrive 'VS'
+ $null = New-Item -ItemType Directory -Force (Join-Path $cuda 'bin'), (Join-Path $cuda 'extras\visual_studio_integration\MSBuildExtensions')
+ $custom = Get-VcBuildCustomizationsDir -VsInstallPath $vs -Generator 'Visual Studio 17 2022'
+ Remove-Item -Recurse -Force $custom -ErrorAction SilentlyContinue
+ $null = New-Item -ItemType Directory -Force $custom
+ if ($Targets) { $null = New-Item -ItemType File (Join-Path $custom 'CUDA 12.8.targets') }
+ $nvccPath = Join-Path $cuda 'bin\nvcc.exe'
+ function Find-VsBuildTools { $null }
+ function Find-Nvcc { $nvccPath }
+ $HasNvidiaDriverEvidence = $true
+ $CmakeGenerator = 'Visual Studio 17 2022'
+ $script:VsInstallPath = $vs
+ Test-LlamaBuildToolsMissing | Should -Be $Expected
+ }
+}
+
+Describe 'only the automatic fallback is gated' {
+ It 'marks the fallback right where the failed prebuilt hands over to a source build' {
+ $at = $script:SetupText.IndexOf('failed validation -- falling back to source build')
+ $at | Should -BeGreaterThan 0
+ $next = $script:SetupText.IndexOf('$script:LlamaSourceBuildIsFallback = $true')
+ $next | Should -BeGreaterThan $at
+ $script:SetupText.Substring($at, $next - $at).Split("`n").Count | Should -BeLessOrEqual 3
+ }
+
+ It 'a declined toolchain finishes the install instead of failing it' {
+ $declined = $script:SetupText.IndexOf('} elseif ($script:LlamaBuildToolsDeclined) {', $script:SetupText.IndexOf('[TAURI:DIAG] llama_cpp=unavailable'))
+ $fatal = $script:SetupText.IndexOf('Exit-SetupFailure "llama.cpp setup did not produce a usable server"')
+ $declined | Should -BeGreaterThan 0
+ $declined | Should -BeLessThan $fatal
+ }
+
+ It 'decides consent before Phase 3.5 installs OpenSSL, and OpenSSL honours it' {
+ $decide = $script:SetupText.IndexOf('$script:LlamaBuildToolsDeclined = $NeedLlamaSourceBuild')
+ $openssl = $script:SetupText.IndexOf('ShiningLight.OpenSSL.Dev')
+ $decide | Should -BeGreaterThan 0
+ $decide | Should -BeLessThan $openssl
+ $script:SetupText | Should -Match ([regex]::Escape('if ($NeedLlamaSourceBuild -and -not $script:LlamaBuildToolsDeclined) {'))
+ }
+
+ It 'a fallback without consent skips the OpenSSL install even when every other tool is present' {
+ $skip = $script:SetupText.IndexOf('} elseif ($script:LlamaSourceBuildIsFallback -and -not (Test-LlamaBuildToolsInstallAllowed)) {')
+ $install = $script:SetupText.IndexOf('winget install -e --id ShiningLight.OpenSSL.Dev')
+ $skip | Should -BeGreaterThan 0
+ $skip | Should -BeLessThan $install
+ $script:SetupText.Substring($skip, $install - $skip) | Should -Match 'building without HTTPS'
+ }
+
+ It 'the gate checks the fallback flag before asking' {
+ $script:SetupText | Should -Match ([regex]::Escape('$script:LlamaSourceBuildIsFallback -and (Test-LlamaBuildToolsMissing) -and'))
+ }
+}
diff --git a/tests/studio_setup_ps1/Studio.Setup.SelfRerun.Tests.ps1 b/tests/studio_setup_ps1/Studio.Setup.SelfRerun.Tests.ps1
index c3f67c6f80f..3a431fa3b10 100644
--- a/tests/studio_setup_ps1/Studio.Setup.SelfRerun.Tests.ps1
+++ b/tests/studio_setup_ps1/Studio.Setup.SelfRerun.Tests.ps1
@@ -345,8 +345,9 @@ Describe 'elevation prompts across the rerun' {
$script:SetupText.IndexOf('winget install Git.Git') | Should -BeLessThan $script:HandoffAt
}
- It 'Git: tries the optional install on a first run and not on the rerun (<Guard>)' -ForEach @(
- @{ Guard = ''; Expected = 1 }, @{ Guard = '1'; Expected = 0 }
+ It 'Git: installs only when a clone needs it (rerun=<Guard>, needed=<Needed>)' -ForEach @(
+ @{ Guard = ''; Needed = $false; Expected = 0 }, @{ Guard = '1'; Needed = $false; Expected = 0 },
+ @{ Guard = ''; Needed = $true; Expected = 1 }, @{ Guard = '1'; Needed = $true; Expected = 1 }
) {
function Invoke-SetupCommand { param([scriptblock]$Block) }
function Refresh-Environment { }
@@ -360,8 +361,11 @@ Describe 'elevation prompts across the rerun' {
}
$DefaultLlamaPrForce = ''; $DefaultLlamaSource = 'https://github.com/ggml-org/llama.cpp'; $DefaultLlamaTag = 'b1'
if ($Guard) { $env:UNSLOTH_SETUP_RERUN = $Guard }
+ if ($Needed) { $env:UNSLOTH_LLAMA_FORCE_COMPILE = '1' }
$StageRoot = $null
- . ([scriptblock]::Create($script:GitBlock))
+ # Git stays missing under the mock, so a needed install ends in Exit-SetupFailure.
+ try { . ([scriptblock]::Create($script:GitBlock)) } catch { if (-not $Needed) { throw } }
+ Remove-Item Env:UNSLOTH_LLAMA_FORCE_COMPILE -ErrorAction SilentlyContinue
Should -Invoke Invoke-SetupCommand -Times $Expected -Exactly
}