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
Studio: propagate required backend version to repair pipeline (#8610) (#8670)
karan yadavdc26127a4294
diff --git a/install.ps1 b/install.ps1index f7916b6b81d..a51c7589741 100644--- a/install.ps1+++ b/install.ps1@@ -5473,6 +5473,10 @@ exit 0return $installed}+ $_desktopMinVer = if ($env:UNSLOTH_DESKTOP_BACKEND_VERSION) { $env:UNSLOTH_DESKTOP_BACKEND_VERSION.Trim() } else { "" }+ $_unslothDesktopInstallSpec = if ($_desktopMinVer) { "unsloth>=$_desktopMinVer" } else { $null }+ $_unslothReleaseInstallSpec = if ($_unslothDesktopInstallSpec) { $_unslothDesktopInstallSpec } else { "unsloth>=2026.8.18" }+if ($_Migrated) {# Migrated env: force-reinstall unsloth+unsloth-zoo for a clean state, preserving# existing torch/CUDA unless the flavor repair below re-lands it.@@ -5481,7 +5485,7 @@ exit 0if ($SkipTorch) {# No-torch: install unsloth + unsloth-zoo with --no-deps, then# runtime deps (typer, safetensors, transformers, etc.) with --no-deps.- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (migrated no-torch)" { & $script:UvExe pip install --python $VenvPython --no-deps --reinstall-package unsloth --reinstall-package unsloth-zoo "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12" }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (migrated no-torch)" { & $script:UvExe pip install --python $VenvPython --no-deps --reinstall-package unsloth --reinstall-package unsloth-zoo "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.8.12" }if ($baseInstallExit -eq 0) {# Resolve pydantic WITH deps so pip pins pydantic-core# to the matching version (no-torch-runtime.txt below@@ -5495,7 +5499,7 @@ exit 0}}} else {- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (migrated)" { & $script:UvExe pip install --python $VenvPython --reinstall-package unsloth --reinstall-package unsloth-zoo "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12" }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (migrated)" { & $script:UvExe pip install --python $VenvPython --reinstall-package unsloth --reinstall-package unsloth-zoo "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.8.12" }}if ($baseInstallExit -ne 0) {Write-StudioLine "[ERROR] Failed to install unsloth (exit code $baseInstallExit)" -ForegroundColor Red@@ -5622,7 +5626,7 @@ exit 0if ($SkipTorch) {# No-torch: install unsloth + unsloth-zoo with --no-deps, then# runtime deps (typer, safetensors, transformers, etc.) with --no-deps.- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (no-torch)" { & $script:UvExe pip install --python $VenvPython --no-deps --upgrade-package unsloth --upgrade-package unsloth-zoo "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12" }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (no-torch)" { & $script:UvExe pip install --python $VenvPython --no-deps --upgrade-package unsloth --upgrade-package unsloth-zoo "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.8.12" }if ($baseInstallExit -eq 0) {# Same pydantic-with-deps trick as the migrated branch.$baseInstallExit = Invoke-InstallCommandRetry -Label "install pydantic" { & $script:UvExe pip install --python $VenvPython pydantic }@@ -5634,9 +5638,10 @@ exit 0}}} elseif ($StudioLocalInstall) {- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (local)" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12" }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (local)" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth "$_unslothReleaseInstallSpec" "unsloth-zoo>=2026.8.12" }} else {- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth -- "$PackageName" }+ $_unslothPkg = if ($PackageName -eq "unsloth" -and $_unslothDesktopInstallSpec) { $_unslothDesktopInstallSpec } else { $PackageName }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth" { & $script:UvExe pip install --python $VenvPython --upgrade-package unsloth -- "$_unslothPkg" }}if ($baseInstallExit -ne 0) {Write-StudioLine "[ERROR] Failed to install unsloth (exit code $baseInstallExit)" -ForegroundColor Red@@ -5662,7 +5667,7 @@ exit 0Write-TauriLog "STEP" "Installing unsloth"substep "installing unsloth (this may take a few minutes)..."if ($StudioLocalInstall) {- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (auto torch backend)" { & $script:UvExe pip install --python $VenvPython "unsloth-zoo>=2026.8.12" "unsloth>=2026.8.18" --torch-backend=auto }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (auto torch backend)" { & $script:UvExe pip install --python $VenvPython "unsloth-zoo>=2026.8.12" "$_unslothReleaseInstallSpec" --torch-backend=auto }if ($baseInstallExit -ne 0) {Write-StudioLine "[ERROR] Failed to install unsloth (exit code $baseInstallExit)" -ForegroundColor Redreturn (Exit-InstallFailure "Failed to install unsloth (exit code $baseInstallExit)" $baseInstallExit)@@ -5680,7 +5685,8 @@ exit 0return (Exit-InstallFailure "Failed to overlay unsloth-zoo (exit code $zooOverlayExit)" $zooOverlayExit)}} else {- $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (auto torch backend)" { & $script:UvExe pip install --python $VenvPython --torch-backend=auto -- "$PackageName" }+ $_unslothPkg = if ($PackageName -eq "unsloth" -and $_unslothDesktopInstallSpec) { $_unslothDesktopInstallSpec } else { $PackageName }+ $baseInstallExit = Invoke-InstallCommandRetry -Label "install unsloth (auto torch backend)" { & $script:UvExe pip install --python $VenvPython --torch-backend=auto -- "$_unslothPkg" }if ($baseInstallExit -ne 0) {Write-StudioLine "[ERROR] Failed to install unsloth (exit code $baseInstallExit)" -ForegroundColor Redreturn (Exit-InstallFailure "Failed to install unsloth (exit code $baseInstallExit)" $baseInstallExit)diff --git a/install.sh b/install.shindex e35b07e92bd..907e2fc08b3 100755--- a/install.sh+++ b/install.sh@@ -4940,6 +4940,12 @@ for _p in ('torch', 'torchvision', 'torchaudio'):esac}+_unsloth_desktop_install_spec=""+if [ -n "${UNSLOTH_DESKTOP_BACKEND_VERSION:-}" ]; then+ _unsloth_desktop_install_spec="unsloth>=${UNSLOTH_DESKTOP_BACKEND_VERSION}"+fi+_unsloth_release_install_spec="${_unsloth_desktop_install_spec:-unsloth>=2026.8.18}"+if [ "$_MIGRATED" = true ]; then# Migrated env: force-reinstall unsloth+unsloth-zoo for a clean state, preserving# existing torch/CUDA unless the ROCm repair below fires.@@ -4952,7 +4958,7 @@ if [ "$_MIGRATED" = true ]; then# to prevent transitive torch resolution.run_install_cmd_retry "install unsloth (migrated no-torch)" uv pip install --python "$_VENV_PY" --no-deps \--reinstall-package unsloth --reinstall-package unsloth-zoo \- "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12"+ "$_unsloth_release_install_spec" "unsloth-zoo>=2026.8.12"# Resolve pydantic WITH deps so pip pins pydantic-core to the# matching version (no-torch-runtime.txt below is --no-deps).# All transitive deps are torch-free.@@ -4967,7 +4973,7 @@ if [ "$_MIGRATED" = true ]; thenrun_install_cmd_retry "install unsloth (migrated)" uv pip install --python "$_VENV_PY" \${_UNSLOTH_TORCH_OVERRIDES:+--overrides "$_UNSLOTH_TORCH_OVERRIDES"} \--reinstall-package unsloth --reinstall-package unsloth-zoo \- "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12"+ "$_unsloth_release_install_spec" "unsloth-zoo>=2026.8.12"[ -n "$_UNSLOTH_TORCH_OVERRIDES" ] && rm -f "$_UNSLOTH_TORCH_OVERRIDES"_UNSLOTH_TORCH_OVERRIDES=""fi@@ -5201,7 +5207,7 @@ elif [ -n "$TORCH_INDEX_URL" ]; then# runtime deps (typer, safetensors, transformers, etc.) with --no-deps.run_install_cmd_retry "install unsloth (no-torch)" uv pip install --python "$_VENV_PY" --no-deps \--upgrade-package unsloth --upgrade-package unsloth-zoo \- "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12"+ "$_unsloth_release_install_spec" "unsloth-zoo>=2026.8.12"# Same pydantic-with-deps trick as the migrated branch.run_install_cmd_retry "install pydantic (with deps for compatible core)" \uv pip install --python "$_VENV_PY" pydantic@@ -5220,7 +5226,7 @@ elif [ -n "$TORCH_INDEX_URL" ]; thenelif [ "$STUDIO_LOCAL_INSTALL" = true ]; thenrun_install_cmd_retry "install unsloth (local)" uv pip install --python "$_VENV_PY" \${_UNSLOTH_TORCH_OVERRIDES:+--overrides "$_UNSLOTH_TORCH_OVERRIDES"} \- --upgrade-package unsloth "unsloth>=2026.8.18" "unsloth-zoo>=2026.8.12"+ --upgrade-package unsloth "$_unsloth_release_install_spec" "unsloth-zoo>=2026.8.12"substep "overlaying local repo (editable)..."run_install_cmd "overlay local repo" uv pip install --python "$_VENV_PY" -e "$_REPO_ROOT" --no-depssubstep "overlaying unsloth-zoo from git main..."@@ -5228,9 +5234,13 @@ elif [ -n "$TORCH_INDEX_URL" ]; then--no-deps --reinstall-package unsloth-zoo \"unsloth-zoo @ git+https://github.com/unslothai/unsloth-zoo"else+ _unsloth_install_pkg="$PACKAGE_NAME"+ if [ "$PACKAGE_NAME" = "unsloth" ] && [ -n "$_unsloth_desktop_install_spec" ]; then+ _unsloth_install_pkg="$_unsloth_desktop_install_spec"+ firun_install_cmd_retry "install unsloth" uv pip install --python "$_VENV_PY" \${_UNSLOTH_TORCH_OVERRIDES:+--overrides "$_UNSLOTH_TORCH_OVERRIDES"} \- --upgrade-package unsloth -- "$PACKAGE_NAME"+ --upgrade-package unsloth -- "$_unsloth_install_pkg"fi[ -n "$_UNSLOTH_TORCH_OVERRIDES" ] && rm -f "$_UNSLOTH_TORCH_OVERRIDES"_UNSLOTH_TORCH_OVERRIDES=""@@ -5249,7 +5259,7 @@ elsetauri_log "STEP" "Installing Unsloth"substep "installing unsloth (this may take a few minutes)..."if [ "$STUDIO_LOCAL_INSTALL" = true ]; then- run_install_cmd_retry "install unsloth (auto torch backend)" uv pip install --python "$_VENV_PY" "unsloth-zoo>=2026.8.12" "unsloth>=2026.8.18" --torch-backend=auto+ run_install_cmd_retry "install unsloth (auto torch backend)" uv pip install --python "$_VENV_PY" "unsloth-zoo>=2026.8.12" "$_unsloth_release_install_spec" --torch-backend=autosubstep "overlaying local repo (editable)..."run_install_cmd "overlay local repo" uv pip install --python "$_VENV_PY" -e "$_REPO_ROOT" --no-depssubstep "overlaying unsloth-zoo from git main..."@@ -5257,7 +5267,17 @@ else--no-deps --reinstall-package unsloth-zoo \"unsloth-zoo @ git+https://github.com/unslothai/unsloth-zoo"else- run_install_cmd_retry "install unsloth (auto torch backend)" uv pip install --python "$_VENV_PY" --torch-backend=auto -- "$PACKAGE_NAME"+ case "$PACKAGE_NAME" in+ unsloth)+ if [ -n "$_unsloth_desktop_install_spec" ]; then+ _unsloth_install_pkg="$_unsloth_desktop_install_spec"+ else+ _unsloth_install_pkg="$PACKAGE_NAME"+ fi+ ;;+ *) _unsloth_install_pkg="$PACKAGE_NAME" ;;+ esac+ run_install_cmd_retry "install unsloth (auto torch backend)" uv pip install --python "$_VENV_PY" --torch-backend=auto -- "$_unsloth_install_pkg"fifidiff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex 4aff0312257..e2f24f1466f 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -4383,6 +4383,12 @@ def install_python_stack() -> int:# No-torch update path: install unsloth + unsloth-zoo, then runtime deps,# both with --no-deps (PyPI metadata declares torch a hard dep; avoid it)._progress("base packages (no torch)")+ desktop_min_ver = os.environ.get("UNSLOTH_DESKTOP_BACKEND_VERSION", "").strip()+ unsloth_spec = (+ f"{package_name}>={desktop_min_ver}"+ if (desktop_min_ver and package_name == "unsloth")+ else package_name+ )pip_install(f"Updating {package_name} + unsloth-zoo (no-torch mode)","--no-cache-dir",@@ -4391,7 +4397,7 @@ def install_python_stack() -> int:package_name,"--upgrade-package","unsloth-zoo",- package_name,+ unsloth_spec,"unsloth-zoo",)# Resolve pydantic WITH deps so pip pins pydantic-core to the exact version@@ -4472,6 +4478,12 @@ def install_python_stack() -> int:# torch/CUDA installs. Torch is pre-installed by install.sh/setup.ps1;# --upgrade-package targets only base pkgs._progress("base packages")+ desktop_min_ver = os.environ.get("UNSLOTH_DESKTOP_BACKEND_VERSION", "").strip()+ unsloth_spec = (+ f"{package_name}>={desktop_min_ver}"+ if (desktop_min_ver and package_name == "unsloth")+ else package_name+ )pip_install("Updating core packages","--no-cache-dir",@@ -4479,7 +4491,7 @@ def install_python_stack() -> int:"unsloth","--upgrade-package","unsloth-zoo",- "unsloth",+ unsloth_spec,"unsloth-zoo",)diff --git a/studio/setup.ps1 b/studio/setup.ps1index 9d5787b6078..c0db19431bd 100644--- a/studio/setup.ps1+++ b/studio/setup.ps1@@ -4782,6 +4782,30 @@ sys.exit(0 if install_manifest.verify_install()['ok'] else 1)substep "studio install incomplete -- forcing dependency pass to repair..." "Cyan"$SkipPythonDeps = $false}+ # If the desktop app specifies a minimum required backend version and the installed+ # package is older than that requirement, force the dependency pass to upgrade it.+ if ($env:UNSLOTH_DESKTOP_BACKEND_VERSION) {+ $_desktopVerBad = $false+ try {+ & python -c "+import re, sys+try:+ from packaging.version import parse as parse_v+except ImportError:+ def parse_v(v):+ match = re.fullmatch(r'(\d+)\.(\d+)\.(\d+)', (v or '').strip())+ return (int(match.group(1)), int(match.group(2)), int(match.group(3))) if match else None+installed = parse_v(sys.argv[1])+required = parse_v(sys.argv[2])+sys.exit(0 if installed is not None and required is not None and installed >= required else 1)+" "$InstalledVer" "$env:UNSLOTH_DESKTOP_BACKEND_VERSION" 2>$null+ if ($LASTEXITCODE -ne 0) { $_desktopVerBad = $true }+ } catch {}+ if ($_desktopVerBad) {+ substep "$_PkgName $InstalledVer < $env:UNSLOTH_DESKTOP_BACKEND_VERSION (required by desktop app) -- forcing dependency pass to update..." "Cyan"+ $SkipPythonDeps = $false+ }+ }# ...but not if an AMD GPU is present and installed PyTorch is CPU-only# (host predates ROCm-wheel support, or GPU added later): the fast "up to# date" path would leave the user on CPU torch with Train/Export disabled.diff --git a/studio/setup.sh b/studio/setup.shindex 734e0dd04f7..209ac39d2a6 100755--- a/studio/setup.sh+++ b/studio/setup.sh@@ -1839,6 +1839,25 @@ sys.exit(0 if install_manifest.verify_install()['ok'] else 1)substep "studio install incomplete -- forcing dependency pass to repair..."_SKIP_PYTHON_DEPS=falsefi+ # If the desktop app specifies a minimum required backend version and the installed+ # package is older than that requirement, force the dependency pass to upgrade it.+ if [ -n "${UNSLOTH_DESKTOP_BACKEND_VERSION:-}" ]; then+ if ! "$VENV_DIR/bin/python" -c "+import re, sys+try:+ from packaging.version import parse as parse_v+except ImportError:+ def parse_v(v):+ match = re.fullmatch(r'(\d+)\.(\d+)\.(\d+)', (v or '').strip())+ return (int(match.group(1)), int(match.group(2)), int(match.group(3))) if match else None+installed = parse_v(sys.argv[1])+required = parse_v(sys.argv[2])+sys.exit(0 if installed is not None and required is not None and installed >= required else 1)+" "$INSTALLED_VER" "$UNSLOTH_DESKTOP_BACKEND_VERSION" 2>/dev/null; then+ substep "$_PKG_NAME $INSTALLED_VER < $UNSLOTH_DESKTOP_BACKEND_VERSION (required by desktop app) -- forcing dependency pass to update..."+ _SKIP_PYTHON_DEPS=false+ fi+ fi# An XPU pin the venv does not satisfy. Only the dependency pass acts on it# (install_python_stack's _ensure_xpu_torch), so without this escape a CPU install# switched to UNSLOTH_TORCH_INDEX_FAMILY=xpu keeps its CPU wheel forever: the packagediff --git a/studio/src-tauri/src/install.rs b/studio/src-tauri/src/install.rsindex 1c77a2b9901..e90b3d639b9 100644--- a/studio/src-tauri/src/install.rs+++ b/studio/src-tauri/src/install.rs@@ -582,6 +582,10 @@ fn spawn_script(// these under --tauri. Scrub so an inherited value can't trip the guard.cmd.env_remove("UNSLOTH_STUDIO_HOME");cmd.env_remove("STUDIO_HOME");+ cmd.env(+ "UNSLOTH_DESKTOP_BACKEND_VERSION",+ crate::preflight::expected_backend_version(),+ );// We decode this child as UTF-8 below, so its Python descendants must emit// UTF-8 or the log fills with U+FFFD. The .ps1 entry points set these too;diff --git a/studio/src-tauri/src/preflight.rs b/studio/src-tauri/src/preflight.rsindex 062ec6279fa..7c475a96d8c 100644--- a/studio/src-tauri/src/preflight.rs+++ b/studio/src-tauri/src/preflight.rs@@ -17,7 +17,8 @@ pub use types::{DesktopPreflightDisposition, DesktopPreflightResult, ExternalBac#[cfg(test)]pub(crate) use version::DESKTOP_MANAGEABILITY_VERSION;pub(crate) use version::{- backend_version_stale_reason, DESKTOP_BACKEND_MANAGEABILITY_VERSION, DESKTOP_PROTOCOL_VERSION,+ backend_version_stale_reason, expected_backend_version, DESKTOP_BACKEND_MANAGEABILITY_VERSION,+ DESKTOP_PROTOCOL_VERSION,};#[cfg(test)]@@ -26,7 +27,7 @@ use backend::{backend_desktop_auth_status, backend_health};use managed::probe_managed_bin;#[cfg(test)]use version::{- backend_version_compatible, backend_version_outdated_reason, expected_backend_version,+ backend_version_compatible, backend_version_outdated_reason,managed_backend_version_stale_reason, MIN_DESKTOP_BACKEND_VERSION,};diff --git a/studio/src-tauri/src/preflight/version.rs b/studio/src-tauri/src/preflight/version.rsindex add4dac191a..715ec74fb71 100644--- a/studio/src-tauri/src/preflight/version.rs+++ b/studio/src-tauri/src/preflight/version.rs@@ -173,7 +173,7 @@ pub(crate) fn backend_version_stale_reason(version: Option<&str>) -> Option<Stri// The backend package this build shipped with, stamped by the release workflow// from the same pypi_version as the updater manifest. Local and CI builds leave// it unset, so the floor above stays their only gate.-pub(super) fn expected_backend_version() -> &'static str {+pub(crate) fn expected_backend_version() -> &'static str {option_env!("UNSLOTH_DESKTOP_BACKEND_VERSION").unwrap_or(MIN_DESKTOP_BACKEND_VERSION)}diff --git a/studio/src-tauri/src/update.rs b/studio/src-tauri/src/update.rsindex 586ca20cf16..ae4b4425411 100644--- a/studio/src-tauri/src/update.rs+++ b/studio/src-tauri/src/update.rs@@ -55,6 +55,10 @@ fn configure_tauri_update_environment(cmd: &mut Command) {cmd.env_remove("STUDIO_HOME");cmd.env("UNSLOTH_TAURI_UPDATE", "1");cmd.env("SKIP_STUDIO_FRONTEND", "1");+ cmd.env(+ "UNSLOTH_DESKTOP_BACKEND_VERSION",+ crate::preflight::expected_backend_version(),+ );}fn spawn_update(diff --git a/tests/python/test_install_python_stack.py b/tests/python/test_install_python_stack.pyindex b255be8435a..93cecee6f56 100644--- a/tests/python/test_install_python_stack.py+++ b/tests/python/test_install_python_stack.py@@ -767,3 +767,29 @@ class TestBuildPipCmdUpgradeIntent:def test_commands_without_the_flag_are_untouched(self):cmd = ips._build_pip_cmd(("--no-cache-dir", "somepackage"))assert cmd == [sys.executable, "-m", "pip", "install", "--no-cache-dir", "somepackage"]+++class TestDesktopBackendVersionConstraint:+ """Verify that UNSLOTH_DESKTOP_BACKEND_VERSION adds the floor pin when upgrading unsloth."""++ def test_spec_includes_floor_when_env_set(self):+ with mock.patch.dict(os.environ, {"UNSLOTH_DESKTOP_BACKEND_VERSION": "2026.8.15"}):+ desktop_min_ver = os.environ.get("UNSLOTH_DESKTOP_BACKEND_VERSION", "").strip()+ package_name = "unsloth"+ unsloth_spec = (+ f"{package_name}>={desktop_min_ver}"+ if (desktop_min_ver and package_name == "unsloth")+ else package_name+ )+ assert unsloth_spec == "unsloth>=2026.8.15"++ def test_spec_bare_when_env_unset(self):+ with mock.patch.dict(os.environ, {}, clear = True):+ desktop_min_ver = os.environ.get("UNSLOTH_DESKTOP_BACKEND_VERSION", "").strip()+ package_name = "unsloth"+ unsloth_spec = (+ f"{package_name}>={desktop_min_ver}"+ if (desktop_min_ver and package_name == "unsloth")+ else package_name+ )+ assert unsloth_spec == "unsloth"diff --git a/tests/sh/test_setup_desktop_backend_version_fastpath.sh b/tests/sh/test_setup_desktop_backend_version_fastpath.shnew file mode 100644index 00000000000..be73fa42ab4--- /dev/null+++ b/tests/sh/test_setup_desktop_backend_version_fastpath.sh@@ -0,0 +1,96 @@+#!/bin/bash+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+# Tests that setup.sh's fastpath escapes when UNSLOTH_DESKTOP_BACKEND_VERSION+# requires a backend upgrade even if INSTALLED_VER == LATEST_VER.++set -euo pipefail++SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"+SETUP_SH="$SCRIPT_DIR/../../studio/setup.sh"+WORK=$(mktemp -d)+trap 'rm -rf "$WORK"' EXIT++# Extract the fast-path check block from setup.sh+awk '/if \[ -n "\$INSTALLED_VER" \] && \[ -n "\$LATEST_VER" \] && \[ "\$INSTALLED_VER" = "\$LATEST_VER" \]/ {on=1}+ on && /^ _setup_pin=/ {exit}+ on {print}' "$SETUP_SH" > "$WORK/fastpath_blk.sh"+echo "fi" >> "$WORK/fastpath_blk.sh"++[ -s "$WORK/fastpath_blk.sh" ] || { echo "FATAL: fastpath block not found in $SETUP_SH" >&2; exit 1; }++PASS=0+FAIL=0++check() {+ local label="$1"+ local got="$2"+ local want="$3"+ if [ "$got" = "$want" ]; then+ echo " PASS: $label (got=$got)"+ PASS=$((PASS + 1))+ else+ echo " FAIL: $label (got=$got, want=$want)"+ FAIL=$((FAIL + 1))+ fi+}++# Create a mock venv that runs Python without site-packages, exercising setup's fallback parser.+VENV_DIR="$WORK/mock_venv"+mkdir -p "$VENV_DIR/bin"+cat << 'EOF' > "$VENV_DIR/bin/python"+#!/bin/sh+exec python3 -S "$@"+EOF+chmod +x "$VENV_DIR/bin/python"++# Mock install_manifest to return ok: True so manifest check passes+printf 'def verify_install():\n return {"ok": True}\n' > "$WORK/install_manifest.py"++eval_fastpath() {+ local installed_ver="$1"+ local latest_ver="$2"+ local desktop_ver="${3:-}"+ (+ INSTALLED_VER="$installed_ver"+ LATEST_VER="$latest_ver"+ UNSLOTH_DESKTOP_BACKEND_VERSION="$desktop_ver"+ _PKG_NAME="unsloth"+ SCRIPT_DIR="$WORK"+ _SKIP_PYTHON_DEPS=false+ step() { :; }+ substep() { :; }++ # Execute extracted block+ # shellcheck disable=SC1090+ . "$WORK/fastpath_blk.sh"+ echo "$_SKIP_PYTHON_DEPS"+ )+}++echo "Testing UNSLOTH_DESKTOP_BACKEND_VERSION fastpath escape in setup.sh:"++# 1. When versions match and no desktop version required -> skips python deps+check "matching versions, no desktop requirement" \+ "$(eval_fastpath '2026.8.15' '2026.8.15' '')" "true"++# 2. When installed version satisfies desktop requirement -> skips python deps+check "installed satisfies desktop requirement" \+ "$(eval_fastpath '2026.8.15' '2026.8.15' '2026.8.15')" "true"++check "installed exceeds desktop requirement" \+ "$(eval_fastpath '2026.8.16' '2026.8.16' '2026.8.15')" "true"++# 3. When installed version is older than desktop requirement -> escapes fastpath (_SKIP_PYTHON_DEPS=false)+check "installed older than desktop requirement (2026.8.4 < 2026.8.15)" \+ "$(eval_fastpath '2026.8.4' '2026.8.4' '2026.8.15')" "false"++check "installed older than desktop requirement (2026.8.14 < 2026.8.15)" \+ "$(eval_fastpath '2026.8.14' '2026.8.14' '2026.8.15')" "false"++# 4. Without packaging, a suffix cannot be ordered safely, so force the dependency pass.+check "post-release requirement forces dependency pass without packaging" \+ "$(eval_fastpath '2026.8.15' '2026.8.15' '2026.8.15.post1')" "false"++echo "Results: $PASS passed, $FAIL failed"+[ "$FAIL" -eq 0 ]