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
Unbreak main: catch the install.ps1 handoff harness up with the block it drives (#10538)
Daniel Han4d96157631dd
diff --git a/tests/test_windows_amd_gpu_scan_fallback.py b/tests/test_windows_amd_gpu_scan_fallback.pyindex 4709a8a1d3f..0d6ab365921 100644--- a/tests/test_windows_amd_gpu_scan_fallback.py+++ b/tests/test_windows_amd_gpu_scan_fallback.py@@ -251,10 +251,13 @@ def test_installer_restores_the_private_handoff_after_setup():assert f"$previousRocmGfxHandoff = $env:{HANDOFF}" in srcassert f"$env:{HANDOFF} = $previousRocmGfxHandoff" in srcassert f"Remove-Item Env:{HANDOFF} -ErrorAction SilentlyContinue" in src- # Saved after the last early return, so no path skips the restore.- assert src.index("$previousRocmGfxHandoff") > src.index(- "--with-llama-cpp-dir path does not exist"- )+ # Cheap companion to test_the_bail_restores_the_caller_environment, which drives the+ # bail: no path out of the setup call may skip the restore, and the bail now lives+ # inside the restoring try, so assert the arrangement save < bail < restore.+ saved = src.index("$previousRocmGfxHandoff = $env:")+ bail = src.index("--with-llama-cpp-dir path does not exist")+ restored = src.index(f"$env:{HANDOFF} = $previousRocmGfxHandoff")+ assert saved < bail < restored, (saved, bail, restored)def test_setup_consumes_the_handoff_only_after_its_own_inference():@@ -530,10 +533,20 @@ def _handoff_lifecycle_block() -> str:def _run_handoff_lifecycle(- tmp_path: Path, *, arch: str | None, inherited: str | None, fails: bool+ tmp_path: Path,+ *,+ arch: str | None,+ inherited: str | None,+ fails: bool,+ bails: bool = False,) -> dict:- body = _handoff_lifecycle_block().replace(- "Invoke-ManagedUnslothCli -Python $VenvPython -Arguments $studioArgs",+ call = "Invoke-ManagedUnslothCli -Python $VenvPython -Arguments $studioArgs"+ block = _handoff_lifecycle_block()+ # Loudly: a silent miss leaves the probe unrun and every assertion reading+ # "<never ran>" with nothing saying why.+ assert call in block, "install.ps1 no longer makes the setup call this harness replaces"+ body = block.replace(+ call,"throw 'setup exploded'"if failselse "$script:SeenByChild = $env:_UNSLOTH_ROCM_GFX_ARCH_HANDOFF",@@ -550,16 +563,49 @@ def _run_handoff_lifecycle("$previousProxyHandoff = $null; $hadPreviousProxyHandoff = $false","$UnslothProxyHandoffJson = $null","$UnslothExe = 'stub'; $studioArgs = @(); $setupExit = 0",+ # Installer inputs the block reads. Undefined, they throw under+ # ErrorActionPreference Stop, the catch swallows it, and the probe never runs.+ "$PackageName = 'unsloth'; $SkipTorch = $false; $TauriMode = $false",+ "$StudioLocalInstall = $false; $RepoRoot = $null",+ "$StudioRedirectMode = 'none'; $StudioHome = $null",+ (+ f"$WithLlamaCppDir = '{tmp_path / 'no-such-llama.cpp'}'"+ if bails+ else "$WithLlamaCppDir = $null"+ )+ + "; $VenvPython = 'stub-python'; $VenvDir = 'stub-venv'",+ "$TorchIndexUrl = $null; $ROCmIndexUrl = $null",+ # Every installer function the block reaches, stubbed.+ "function Get-ExpectedTorchFlavorTag { param($TorchIndexUrl, $ROCmIndexUrl) 'cu128' }",+ "function Get-InstalledTorchVersionRaw { param($Python) '' }",+ "function ConvertTo-TorchNumericRelease { param($Raw) $null }",+ "function Write-StudioLine { param($Message, $ForegroundColor) }",+ "function Write-ApplicationControlBlocked { param($Message, $Detail) }",+ "function Exit-InstallFailure { param($Message) 1 }","$script:SeenByChild = '<never ran>'",+ "$script:BlockError = $null",+ # Read right after the setup call; null makes the block return early.+ "$script:ManagedUnslothCliExit = 0",+ "$script:PrevTorchPin = $null","$ROCmGfxArch = " + ("$null" if arch is None else f"'{arch}'"),+ # In a function so the block's own return -- the --with-llama-cpp-dir bail --+ # leaves the block, not the script, letting us read the environment after it.+ "function Invoke-HandoffBlock {","try {",body,- "} catch { }",+ "} catch { $script:BlockError = $_.ToString() }",+ "}",+ "Invoke-HandoffBlock | Out-Null","@{"," seen_by_child = $script:SeenByChild",+ " block_error = $script:BlockError"," after = $(if (Test-Path Env:_UNSLOTH_ROCM_GFX_ARCH_HANDOFF) { $env:_UNSLOTH_ROCM_GFX_ARCH_HANDOFF } else { $null })"," after_set = [bool](Test-Path Env:_UNSLOTH_ROCM_GFX_ARCH_HANDOFF)"," public = $(if (Test-Path Env:UNSLOTH_ROCM_GFX_ARCH) { $env:UNSLOTH_ROCM_GFX_ARCH } else { $null })",+ # Set at the top of the block's try, above the bail: gone afterwards+ # is what says the finally ran.+ " package_name = $(if (Test-Path Env:STUDIO_PACKAGE_NAME) { $env:STUDIO_PACKAGE_NAME } else { $null })",+ " skip_base = $(if (Test-Path Env:SKIP_STUDIO_BASE) { $env:SKIP_STUDIO_BASE } else { $null })","} | ConvertTo-Json -Compress",]),@@ -576,7 +622,20 @@ def _run_handoff_lifecycle(env = env,)assert proc.returncode == 0, f"handoff block failed:\n{proc.stdout}\n{proc.stderr}"- return json.loads(proc.stdout)+ # Last JSON object only: a stub may emit its return value into the pipeline first.+ reports = [line for line in proc.stdout.splitlines() if line.startswith("{")]+ assert reports, f"the handoff block printed no report:\n{proc.stdout}\n{proc.stderr}"+ out = json.loads(reports[-1])+ # The block may throw only where the test asked; anything else is a missing stub.+ if fails:+ # The injected throw specifically: an earlier helper failure would still restore+ # the environment and pass every assertion without the failure path running.+ assert "setup exploded" in (+ out.get("block_error") or ""+ ), f"the block failed before the injected throw: {out.get('block_error')}"+ else:+ assert not out.get("block_error"), f"the handoff block threw: {out['block_error']}"+ return out@requires_pwsh@@ -595,6 +654,26 @@ def test_the_caller_environment_survives_the_setup_call(tmp_path, arch, inheriteassert out["public"] == "gfx90a", "a user's own override must come back untouched"+@requires_pwsh+def test_the_bail_restores_the_caller_environment(tmp_path):+ """The --with-llama-cpp-dir bail returns from inside the try, so the finally still runs.++ Textual ordering cannot show that: move the try below the bail and `saved < bail <+ restored` still holds while the return walks out past the restore. So this takes the+ bail, with a directory that does not exist, and reads the environment afterwards.+ """+ out = _run_handoff_lifecycle(+ tmp_path, arch = "gfx1151", inherited = "gfx1030", fails = False, bails = True+ )+ assert out["seen_by_child"] == "<never ran>", "the bail did not happen before the setup call"+ assert out["after"] == "gfx1030", "the caller's inherited handoff was not restored by the bail"+ assert out["after_set"] is True+ # Set above the bail and removed only by the finally, so still set in the caller+ # would mean the bail escaped the try.+ assert out["package_name"] is None, "STUDIO_PACKAGE_NAME leaked past the bail"+ assert out["skip_base"] is None, "SKIP_STUDIO_BASE leaked past the bail"++@requires_pwsh@pytest.mark.parametrize("arch, inherited, expected",