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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Windows: guard the source-build and whisper.cpp probes on an unreadable install tree (#7757)
Daniel Hancc0185fbb170
diff --git a/studio/backend/core/inference/stt_ggml_sidecar.py b/studio/backend/core/inference/stt_ggml_sidecar.pyindex 02b376dea51..89e8cf1d05d 100644--- a/studio/backend/core/inference/stt_ggml_sidecar.py+++ b/studio/backend/core/inference/stt_ggml_sidecar.py@@ -172,7 +172,12 @@ def _is_runnable(p: Path) -> bool:"""A real whisper-server is an executable file. On Windows os.access(X_OK) iseffectively an existence check; on Unix it rejects a non-executable stub so ahalf-written or wrong-mode file isn't mistaken for the server."""- return p.is_file() and (sys.platform == "win32" or os.access(p, os.X_OK))+ try:+ return p.is_file() and (sys.platform == "win32" or os.access(p, os.X_OK))+ except OSError:+ # is_file() propagates EACCES: an unreadable install dir must read as+ # engine-unavailable, like a missing one, never a 500 out of stt/status.+ return Falsedef _whisper_install_marker(binary: str) -> Optional[dict]:diff --git a/studio/setup.ps1 b/studio/setup.ps1index 37d67677ad6..86cae6274c6 100644--- a/studio/setup.ps1+++ b/studio/setup.ps1@@ -2940,6 +2940,14 @@ function Get-StudioAdoptableState {}}if ($denied) { return "Denied" }+ # Windows reports a MISSING child of an unreadable directory as absent, so the+ # probes above cannot tell "no markers here" from "cannot look"; listing the+ # directory itself can. Without this a denied tree reads as unowned.+ try { $null = @(Get-ChildItem -LiteralPath $Path -Force -ErrorAction Stop | Select-Object -First 1) }+ catch {+ if (Test-AccessDeniedError $_) { return "Denied" }+ # Anything else was not adoptable before either; this must not throw.+ }return "No"}# Boolean view for callers that only gate a cosmetic cleanup on adoption.@@ -2950,7 +2958,10 @@ function Test-StudioOwnedAdoptable {function Assert-StudioOwnedOrAbsent {param([Parameter(Mandatory = $true)][string]$Path,- [Parameter(Mandatory = $true)][string]$Label+ [Parameter(Mandatory = $true)][string]$Label,+ # whisper.cpp is non-fatal by contract, so it needs the denial handed back+ # rather than exited on. Only this mode returns a value.+ [switch]$NonFatal)# Denied is not Absent: a root we cannot read cannot be proven ours, and# returning here would let the caller replace it. Both stops stay gated on@@ -2959,17 +2970,20 @@ function Assert-StudioOwnedOrAbsent {$pathState = Get-PathState -Path $Path -PathType Containerif ($pathState -ne "Present") {if ($StudioHomeIsCustom -and $pathState -eq "Denied") {+ if ($NonFatal) { return "Denied" }Exit-PathAccessDenied -Path $Path -Label $Label -OwnershipUnverified}return}$markerState = Get-PathState -Path (Join-Path $Path $StudioOwnedMarker) -PathType Leafif ($StudioHomeIsCustom -and $markerState -eq "Denied") {+ if ($NonFatal) { return "Denied" }Exit-PathAccessDenied -Path $Path -Label $Label -OwnershipUnverified}if ($StudioHomeIsCustom -and $markerState -ne "Present") {$adoptState = Get-StudioAdoptableState -Path $Pathif ($adoptState -eq "Denied") {+ if ($NonFatal) { return "Denied" }Exit-PathAccessDenied -Path $Path -Label $Label -OwnershipUnverified}if ($adoptState -eq "Yes") {@@ -4333,6 +4347,12 @@ if ($env:WHISPER_SERVER_PATH -or $env:UNSLOTH_WHISPER_CPP_PATH) {substep "whisper.cpp: using a user-configured binary/dir; skipping managed install"} elseif ($env:UNSLOTH_SKIP_WHISPER_INSTALL -eq "1") {substep "whisper.cpp: install skipped (UNSLOTH_SKIP_WHISPER_INSTALL=1)"+} elseif ($StudioHomeIsCustom -and (Test-Path -LiteralPath $WhisperInstaller) -and+ (Assert-StudioOwnedOrAbsent -Path $WhisperCppDir -Label "whisper.cpp install" -NonFatal) -eq "Denied") {+ # Never fatal, per the phase header: the guard below would exit the whole run+ # on an unreadable tree, taking llama.cpp down with it. Only the denial is+ # caught here; an unowned tree still stops.+ step "whisper.cpp" "install directory cannot be read: access is denied; curated whisper.cpp dictation is unavailable; restore access to $WhisperCppDir or move it aside, then re-run setup; browser and Transformers dictation remain available" "Yellow"} elseif (Test-Path -LiteralPath $WhisperInstaller) {# The installer's atomic activation replaces the whole directory, so the# custom-home ownership guard must run first (mirrors the llama block).@@ -4372,7 +4392,7 @@ if ($env:WHISPER_SERVER_PATH -or $env:UNSLOTH_WHISPER_CPP_PATH) {} else {step "whisper.cpp" "prebuilt installed"}- if ($StudioHomeIsCustom -and (Test-Path -LiteralPath $WhisperCppDir -PathType Container)) {+ if ($StudioHomeIsCustom -and (Test-PathQuiet $WhisperCppDir "Container")) {Mark-StudioOwned -Path $WhisperCppDir}} elseif ($whisperExit -eq 3) {@@ -4466,10 +4486,25 @@ $HasGitForBuild = $null -ne (Get-Command git -ErrorAction SilentlyContinue)# Check if existing llama-server matches current GPU mode. A CUDA-built binary# on a now-CPU-only machine (or vice versa) needs to be rebuilt.$NeedRebuild = $false-if (Test-Path -LiteralPath $LlamaServerBin) {+# A forced compile, a pinned PR or a custom source skips the prebuilt path and its+# phase 3.4 denial guard, so this can be the first probe to read inside the tree.+# A linked local dir is skipped: it reads through the junction into the user's own+# checkout, and nothing here is consumed on that path anyway.+$llamaBinState = if ($LocalLlamaCppLinked) { "Absent" } else { Get-PathState -Path $LlamaServerBin -PathType Leaf }+if ($llamaBinState -eq "Denied") {+ # Nothing proved this tree is ours here, so do not advise deleting it.+ Exit-PathAccessDenied -Path $LlamaCppDir -Label "llama.cpp install" -OwnershipUnverified:$StudioHomeIsCustom+}+if ($llamaBinState -eq "Present") {$CmakeCacheFile = Join-Path $BuildDir "CMakeCache.txt"- if (Test-Path -LiteralPath $CmakeCacheFile) {- $cachedCuda = Select-String -LiteralPath $CmakeCacheFile -Pattern 'GGML_CUDA:BOOL=ON' -Quiet+ if (Test-PathQuiet $CmakeCacheFile "Leaf") {+ # A listed file can still deny the read, which Test-PathQuiet cannot see.+ try {+ $cachedCuda = Select-String -LiteralPath $CmakeCacheFile -Pattern 'GGML_CUDA:BOOL=ON' -Quiet+ } catch {+ if (-not (Test-AccessDeniedError $_)) { throw }+ Exit-PathAccessDenied -Path $LlamaCppDir -Label "llama.cpp install" -OwnershipUnverified:$StudioHomeIsCustom+ }if ($HasNvidiaSmi -and -not $cachedCuda) {Write-Host " Existing llama-server is CPU-only but GPU is available -- rebuilding" -ForegroundColor Yellow$NeedRebuild = $true@@ -4485,7 +4520,7 @@ if (Test-Path -LiteralPath $LlamaServerBin) {# build runs only when needed and no usable binary is already present. A linked# local dir sets $NeedLlamaSourceBuild = $false, so this no-ops for that path.$WillBuildLlamaFromSource = $NeedLlamaSourceBuild -and `- -not ((Test-Path -LiteralPath $LlamaServerBin) -and -not $NeedRebuild -and $RequestedLlamaTag -ne "master")+ -not ((Test-PathQuiet $LlamaServerBin "Leaf") -and -not $NeedRebuild -and $RequestedLlamaTag -ne "master")if ($WillBuildLlamaFromSource) {if (-not $HasGitForBuild) {# Phase 1 keeps git optional, so only the automatic fallback after a failed prebuilt@@ -4519,7 +4554,7 @@ if ($LocalLlamaCppLinked) {} elseif (-not $NeedLlamaSourceBuild) {Write-Host ""step "llama.cpp" "prebuilt (validated)"-} elseif ((Test-Path -LiteralPath $LlamaServerBin) -and -not $NeedRebuild -and $RequestedLlamaTag -ne "master") {+} elseif ((Test-PathQuiet $LlamaServerBin "Leaf") -and -not $NeedRebuild -and $RequestedLlamaTag -ne "master") {# Skip rebuild only for pinned tags (e.g. b8635). When the requested# tag is "master" (a moving target), always rebuild so the binary picks# up new model architecture support (e.g. Gemma 4).@@ -5063,16 +5098,16 @@ if ($LocalLlamaCppLinked) {$totalSec = [math]::Round($totalSw.Elapsed.TotalSeconds % 60, 1)# -- Summary --- if ($BuildOk -and (Test-Path -LiteralPath $LlamaServerBin)) {+ if ($BuildOk -and (Test-PathQuiet $LlamaServerBin "Leaf")) {step "llama.cpp" "built"$QuantizeBin = Join-Path $BuildDir "bin\Release\llama-quantize.exe"- if (Test-Path -LiteralPath $QuantizeBin) {+ if (Test-PathQuiet $QuantizeBin "Leaf") {step "llama-quantize" "built"}step "build time" "${totalMin}m ${totalSec}s" "DarkGray"} else {$altBin = Join-Path $BuildDir "bin\llama-server.exe"- if ($BuildOk -and (Test-Path -LiteralPath $altBin)) {+ if ($BuildOk -and (Test-PathQuiet $altBin "Leaf")) {step "llama.cpp" "built"step "build time" "${totalMin}m ${totalSec}s" "DarkGray"} else {diff --git a/tests/studio/install/test_setup_denied_install_tree.py b/tests/studio/install/test_setup_denied_install_tree.pyindex 648b2218243..a131f116ff3 100644--- a/tests/studio/install/test_setup_denied_install_tree.py+++ b/tests/studio/install/test_setup_denied_install_tree.py@@ -102,19 +102,23 @@ def test_ownership_guard_distinguishes_denied_from_unowned():# unreadable; it must stay for the genuinely-unowned case only.assert "is not marked as an Unsloth-owned $Label" in guard# Both stops stay gated, so default-home installs behave exactly as before.- assert guard.count("$StudioHomeIsCustom -and") == 3+ assert guard.count("$StudioHomeIsCustom -and") >= 3def test_no_bare_test_path_probes_inside_the_llama_install_tree():"""Probes that read *inside* a tree whose permissions we do not control arethe ones that throw; they must all go through the guarded helpers."""inside_tree = re.compile(- r"Test-Path\b[^\n]*(\$existingMetaPath|\$llamaMarker|\$_cand|Join-Path \$LlamaCppDir)"+ r"Test-Path\b[^\n]*("+ r"\$existingMetaPath|\$llamaMarker|\$_cand|Join-Path \$LlamaCppDir"+ r"|\$LlamaServerBin|\$CmakeCacheFile|\$QuantizeBin|\$altBin"+ r"|Join-Path \$BuildDir)")+ # A comment naming a probe is not a probe.offenders = [f"{index}: {line.strip()}"for index, line in enumerate(SETUP_PS1.splitlines(), start = 1)- if inside_tree.search(line)+ if inside_tree.search(line.split("#", 1)[0])]assert not offenders, offenders@@ -232,7 +236,7 @@ def test_the_ownership_guard_never_advises_deleting_an_unverified_tree():the tree is ours. It already says "move it aside" when it can prove it."""guard = SETUP_PS1.split("function Assert-StudioOwnedOrAbsent", 1)[1].split("\nfunction ", 1)[0]calls = [line.strip() for line in guard.splitlines() if "Exit-PathAccessDenied" in line]- assert len(calls) == 3, calls+ assert len(calls) >= 3, callsfor line in calls:assert "-OwnershipUnverified" in line, linebody = SETUP_PS1.split("function Exit-PathAccessDenied", 1)[1].split("\nfunction ", 1)[0]@@ -265,3 +269,108 @@ def test_the_temp_dir_swap_checks_both_of_its_destructive_steps():# And catch a move that silently did not happen.assert '(Get-PathState -Path $LlamaCppDir) -ne "Absent"' in swap.split(move, 1)[1], swapassert "Test-Path -LiteralPath $OriginalLlamaCppDir" not in swap, swap+++def test_the_source_build_phase_probes_the_tree_three_state():+ """A forced compile, a pinned PR or a custom source skips the prebuilt phase+ and its denial guard, so the rebuild check is the first read inside the tree."""+ build = _slice("$llamaBinState = ", "# -- Summary --")+ assert "Get-PathState -Path $LlamaServerBin -PathType Leaf" in build, build+ assert '$llamaBinState -eq "Denied"' in build, build+ assert '$llamaBinState -eq "Present"' in build, build+ assert "Test-Path -LiteralPath $LlamaServerBin" not in build, build+++def test_the_source_build_probe_skips_a_linked_local_dir():+ """$LlamaCppDir is a junction onto the user's checkout there, so probing it+ reads their tree, and nothing this block computes is consumed on that path."""+ flat = " ".join(SETUP_PS1.split())+ assert '$llamaBinState = if ($LocalLlamaCppLinked) { "Absent" }' in flat+++def test_the_source_build_denial_never_advises_deleting_an_unproven_tree():+ """Nothing on this route ran the ownership guard, so under a custom home the+ tree cannot be proven ours and the delete advice must stay suppressed."""+ block = _slice("$llamaBinState = ", "$WillBuildLlamaFromSource")+ denials = [ln.strip() for ln in block.splitlines() if "Exit-PathAccessDenied" in ln]+ assert len(denials) >= 2, denials+ assert all(d.endswith("-OwnershipUnverified:$StudioHomeIsCustom") for d in denials), denials+ assert all(d.startswith("Exit-PathAccessDenied -Path $LlamaCppDir ") for d in denials), denials+++def test_the_cmake_cache_read_is_guarded_not_just_its_probe():+ """Test-PathQuiet only proves the entry is listed; a deny ACE on the file+ itself leaves the probe true and throws on the read below it."""+ block = _slice("$CmakeCacheFile = Join-Path", "$WillBuildLlamaFromSource")+ read = "Select-String -LiteralPath $CmakeCacheFile"+ assert read in block, block+ before, after = block.split(read, 1)+ assert "try {" in before, before+ assert "Test-AccessDeniedError" in after, after+ assert "Exit-PathAccessDenied" in after, after+++def _slice(start: str, end: str) -> str:+ """Both bounds asserted: an unasserted terminator does not fail, it silently+ widens the window to end-of-file and makes everything inside it near-vacuous."""+ assert start in SETUP_PS1, start+ assert end in SETUP_PS1, end+ return SETUP_PS1.split(start, 1)[1].split(end, 1)[0]+++def _whisper_phase() -> str:+ """The whisper phase body. Both anchors are asserted so a phase renumbering+ fails as an assertion instead of an IndexError, and cannot silently widen+ the window to end-of-file."""+ return _slice("Install the whisper.cpp prebuilt", "PHASE 3.5")+++def test_the_whisper_phase_survives_an_unreadable_whisper_tree():+ """The phase header promises failure is never fatal, but the ownership guard+ exits the whole run, which would take llama.cpp inference down with it."""+ guard = SETUP_PS1.split("function Assert-StudioOwnedOrAbsent", 1)[1].split("\nfunction ", 1)[0]+ assert "[switch]$NonFatal" in guard+ # Ordering, not just presence: below its exit the return is dead code.+ paired = re.findall(+ r'if \(\$NonFatal\) \{ return "Denied" \}\n\s*Exit-PathAccessDenied -Path \$Path', guard+ )+ assert len(paired) == guard.count("Exit-PathAccessDenied -Path $Path"), guard+ # No unpaired return: one above the custom-home gate would call a fresh+ # install unreadable.+ assert len(paired) == guard.count('if ($NonFatal) { return "Denied" }'), guard+ assert len(paired) >= 3, guard+ # Only the denial is handed back; an unowned tree must still stop.+ assert 'Exit-SetupFailure "$Label path is not an Unsloth-owned install' in guard+ whisper = _whisper_phase()+ assert '-Label "whisper.cpp install" -NonFatal) -eq "Denied"' in whisper, whisper+ # Scoped to the new branch: both phrases occur elsewhere in the phase, so a+ # phase-wide match proves nothing about this branch.+ marker = '-NonFatal) -eq "Denied") {'+ assert marker in whisper, whisper+ denial = whisper.split(marker, 1)[1].split("\n} elseif", 1)[0]+ assert re.search(r'^\s*step "whisper\.cpp" ', denial, re.M), denial+ assert "install directory cannot be read: access is denied" in denial, denial+ assert "browser and Transformers dictation remain available" in denial, denial+ # The whole point is that this stays non-fatal.+ assert "Exit-SetupFailure" not in denial, denial+ assert not re.search(r"\bexit \d", denial), denial+ # The skip must precede the branch whose guard would exit. Anchored on that+ # branch's body, which survives a hardening of its own probe.+ body = "$whisperArgs = @("+ assert body in whisper, whisper+ assert whisper.index("-NonFatal") < whisper.index(body)+++def test_the_whisper_skip_stays_behind_the_installer_gate():+ """The guard used to live inside the installer branch, so a tree without the+ installer was a no-op. Hoisting it must not make that case fatal."""+ marker = "-NonFatal) -eq"+ whisper = _whisper_phase()+ assert marker in whisper, whisper+ head = whisper.split(marker, 1)[0]+ assert "} elseif" in head, head+ branch = head.rsplit("} elseif", 1)[1]+ # A conjunct, not merely present: -or or a negation reopens this case.+ assert re.search(r"-and\s*\([^\n]*\$WhisperInstaller[^\n]*\)\s*-and", branch), branch+ assert "-not (Test-Path" not in branch, branch+ assert " -or " not in branch, branchdiff --git a/tests/studio/test_path_probe_access_denied.ps1 b/tests/studio/test_path_probe_access_denied.ps1index 96aa1d64a40..58151e446c2 100644--- a/tests/studio/test_path_probe_access_denied.ps1+++ b/tests/studio/test_path_probe_access_denied.ps1@@ -236,6 +236,110 @@ Check "a wrapped UnauthorizedAccessException classifies as access denied" (Check "an unrelated exception does not classify as access denied" (-not (Test-AccessDeniedError ([System.IO.FileNotFoundException]::new("missing"))))+# -- Assert-StudioOwnedOrAbsent -NonFatal, run for real --+# whisper.cpp promises "failure is never fatal", so a denied tree there is handed+# back instead of exiting the run. Everything else about the guard stays fatal.+$assertSrc = Get-FunctionSource -Path $setupPath -Name Assert-StudioOwnedOrAbsent+$markSrc = Get-FunctionSource -Path $setupPath -Name Mark-StudioOwned+Check "setup.ps1 defines Assert-StudioOwnedOrAbsent" ($null -ne $assertSrc)+if ($assertSrc -and $markSrc) {+ . ([scriptblock]::Create($assertSrc))+ . ([scriptblock]::Create($markSrc))+ # Reaching either of these is the failure the -NonFatal mode exists to avoid.+ function Exit-PathAccessDenied { param($Path, $Label, [switch]$UserSupplied, [switch]$OwnershipUnverified) throw "EXIT-DENIED" }+ function Exit-SetupFailure { param($Message, $Code) throw "EXIT-SETUP" }+ function step { param($a, $b, $c) }+ function substep { param($a, $b) }+ $StudioOwnedMarker = ".unsloth-studio-owned"+ $StudioHomeIsCustom = $true++ $nfRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("uns_nf_" + [guid]::NewGuid().ToString("N"))+ $nfDenied = Join-Path $nfRoot "whisper.cpp"+ $nfUnowned = Join-Path $nfRoot "unowned"+ $nfInner = Join-Path $nfDenied "inner"+ $nfMarker = Join-Path $nfDenied $StudioOwnedMarker+ # Populate before locking: Windows returns $false for a MISSING child of a+ # denied directory instead of throwing, so a probe target that does not exist+ # makes the negative control read as "this host cannot deny".+ New-Item -ItemType Directory -Force -Path $nfInner | Out-Null+ Set-Content -LiteralPath $nfMarker -Value ""+ New-Item -ItemType Directory -Force -Path $nfUnowned | Out-Null+ Set-Content -LiteralPath (Join-Path $nfUnowned "someone-elses.txt") -Value "x"+ function Set-NfDenied([bool]$on) {+ if ($onWindows) {+ $who = "$env:USERDOMAIN\$env:USERNAME"+ if ($on) { icacls $nfDenied /deny "${who}:(OI)(CI)(RX)" *>$null }+ else { icacls $nfDenied /remove:d "$who" *>$null }+ } else {+ if ($on) { chmod 000 $nfDenied } else { chmod 755 $nfDenied }+ }+ }+ try {+ Set-NfDenied $true+ # Same environment gate as above: no real denial means no real test.+ $nfReal = $false+ try { $null = Test-Path $nfMarker } catch { $nfReal = $true }+ Check "the host can actually deny a read (negative control)" $nfReal+ if ($nfReal) {+ $threw = $false+ $out = $null+ try { $out = @(Assert-StudioOwnedOrAbsent -Path $nfDenied -Label "whisper.cpp install" -NonFatal) }+ catch { $threw = $true }+ Check "-NonFatal hands a denied tree back instead of exiting" (-not $threw)+ # One bare string, not an array: a stray emit would break the caller's -eq.+ Check "-NonFatal returns exactly one value" ($out.Count -eq 1)+ Check "-NonFatal returns Denied" ($out.Count -eq 1 -and $out[0] -eq "Denied")++ $threw = $false+ try { $null = Assert-StudioOwnedOrAbsent -Path $nfDenied -Label "whisper.cpp install" } catch { $threw = $true }+ Check "without -NonFatal a denied tree still stops setup" $threw++ # A locked directory still probes Present from its readable parent, so+ # the case above only covers the marker read; lock the parent instead.+ $out = $null+ $threw = $false+ try { $out = @(Assert-StudioOwnedOrAbsent -Path $nfInner -Label "whisper.cpp install" -NonFatal) }+ catch { $threw = $true }+ Check "-NonFatal hands back a tree whose parent is unreadable" (+ -not $threw -and $out.Count -eq 1 -and $out[0] -eq "Denied")++ # The fresh-custom-home case: no marker was ever written. Windows+ # reports a MISSING child of a denied directory as Absent, so there the+ # adoptable-state read catches this, not the marker probe. Either route+ # is fine; anything other than Denied is not.+ # chmod 000 blocks the child probes outright; chmod 111 allows stat of a+ # named child but forbids listing, matching Windows, and is the only+ # shape reaching the directory listing in Get-StudioAdoptableState.+ $bareWho = "$env:USERDOMAIN\$env:USERNAME"+ $bareModes = if ($onWindows) { @("acl") } else { @("000", "111") }+ foreach ($mode in $bareModes) {+ $nfBare = Join-Path $nfRoot "bare_$mode"+ New-Item -ItemType Directory -Force -Path (Join-Path $nfBare "sub") | Out-Null+ if ($mode -eq "acl") { icacls $nfBare /deny "${bareWho}:(OI)(CI)(RX)" *>$null }+ else { chmod $mode $nfBare }+ try {+ $out = $null+ $threw = $false+ try { $out = @(Assert-StudioOwnedOrAbsent -Path $nfBare -Label "whisper.cpp install" -NonFatal) }+ catch { $threw = $true }+ Check "-NonFatal hands back a denied tree that has no marker ($mode)" (+ -not $threw -and $out.Count -eq 1 -and $out[0] -eq "Denied")+ } finally {+ if ($mode -eq "acl") { icacls $nfBare /remove:d "$bareWho" *>$null }+ else { chmod 755 $nfBare }+ }+ }+ }+ # -NonFatal rescues the denial only: someone else's folder must still stop.+ $threw = $false+ try { $null = Assert-StudioOwnedOrAbsent -Path $nfUnowned -Label "whisper.cpp install" -NonFatal } catch { $threw = $true }+ Check "-NonFatal does not excuse an unowned tree" $threw+ } finally {+ Set-NfDenied $false+ Remove-Item -Recurse -Force -LiteralPath $nfRoot -ErrorAction SilentlyContinue+ }+}+if ($script:failures -gt 0) {Write-Host "$($script:failures) check(s) failed" -ForegroundColor Redexit 1diff --git a/tests/studio/test_whisper_binary_probe_denied.py b/tests/studio/test_whisper_binary_probe_denied.pynew file mode 100644index 00000000000..5c19a0108ba--- /dev/null+++ b/tests/studio/test_whisper_binary_probe_denied.py@@ -0,0 +1,87 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.++"""An unreadable whisper.cpp install must read as engine-unavailable, not raise.++setup.ps1 now leaves a denied `<STUDIO_HOME>/whisper.cpp` in place instead of+aborting the run, so the backend is the first thing to probe it. `Path.is_file()`+propagates EACCES, and `stt_status` does not catch it, so an unguarded probe turns+into a 500 on the one endpoint that reports *both* dictation engines.+"""++from __future__ import annotations++import ast+import os+import sys+from pathlib import Path++import pytest+++REPO_ROOT = Path(__file__).resolve().parents[2]+SIDECAR = REPO_ROOT / "studio" / "backend" / "core" / "inference" / "stt_ggml_sidecar.py"+++def _is_runnable():+ """Exec the real function alone: importing the module pulls in the whole+ backend (structlog, fastapi), which this check does not need."""+ tree = ast.parse(SIDECAR.read_text(encoding = "utf-8"))+ for node in tree.body:+ if isinstance(node, ast.FunctionDef) and node.name == "_is_runnable":+ namespace: dict = {"os": os, "sys": sys, "Path": Path}+ exec(compile(ast.Module([node], []), str(SIDECAR), "exec"), namespace)+ return namespace["_is_runnable"]+ raise AssertionError("_is_runnable not found in stt_ggml_sidecar.py")+++def _can_deny() -> bool:+ """Probe rather than infer. Guessing from euid silently drops the only+ behavioural test in any root container, which is most CI images."""+ import tempfile+ with tempfile.TemporaryDirectory() as tmp:+ locked = Path(tmp) / "locked"+ locked.mkdir()+ (locked / "probe").write_text("", encoding = "utf-8")+ locked.chmod(0o000)+ try:+ (locked / "probe").is_file()+ return False+ except OSError:+ return True+ finally:+ locked.chmod(0o755)+++denial_capable = pytest.mark.skipif(+ sys.platform == "win32" or not _can_deny(),+ reason = "this host cannot produce a read denial, so the check would pass vacuously",+)+++def test_a_readable_executable_is_still_runnable(tmp_path):+ binary = tmp_path / "whisper-server"+ binary.write_text("", encoding = "utf-8")+ binary.chmod(0o755)+ assert _is_runnable()(binary) is True+++def test_a_missing_binary_is_not_runnable(tmp_path):+ assert _is_runnable()(tmp_path / "whisper-server") is False+++@denial_capable+def test_an_unreadable_install_dir_reads_as_unavailable_not_an_exception(tmp_path):+ install = tmp_path / "whisper.cpp"+ install.mkdir()+ binary = install / "whisper-server"+ binary.write_text("", encoding = "utf-8")+ binary.chmod(0o755)+ install.chmod(0o000)+ try:+ # Negative control: the denial is real on this filesystem.+ with pytest.raises(OSError):+ binary.is_file()+ assert _is_runnable()(binary) is False+ finally:+ install.chmod(0o755)diff --git a/tests/test_studio_install_workspace_guard.py b/tests/test_studio_install_workspace_guard.pyindex aeb22cac455..7b035ed596b 100644--- a/tests/test_studio_install_workspace_guard.py+++ b/tests/test_studio_install_workspace_guard.py@@ -369,7 +369,9 @@ def test_setup_helpers_gate_on_canonical_custom_root():ps_src = SETUP_PS1.read_text(encoding = "utf-8")ps_idx = ps_src.index("function Assert-StudioOwnedOrAbsent")- ps_func = ps_src[ps_idx : ps_idx + 800]+ # To the end of the function, not a fixed width, which a new parameter or+ # comment would push the assertions below out of.+ ps_func = ps_src[ps_idx:].split("\nfunction ", 1)[0]assert ("$StudioHomeIsCustom -and" in ps_func), "setup.ps1 Assert-StudioOwnedOrAbsent must gate on $StudioHomeIsCustom"