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
Update idempotency: let the offline test survive a version bump that is not on PyPI yet (#17428)
Daniel Han03c030d1d9c4
diff --git a/tests/studio/install/test_update_idempotency.py b/tests/studio/install/test_update_idempotency.pyindex b4c9af07f43..87a439a06d5 100644--- a/tests/studio/install/test_update_idempotency.py+++ b/tests/studio/install/test_update_idempotency.py@@ -643,6 +643,14 @@ def test_the_desktop_update_path_keeps_a_verified_install_offline(install, settlor UPGRADE_MARKER in run.log), run.log[-8000:]assert run.connections == run.refused, run.report()+ if UPGRADE_MARKER in run.log:+ # Windows reached PyPI and moved to its release (the checkout's version is not PyPI's, as between+ # a version bump and its publish), so the disk moved by design. Restore the checkout first: the+ # fault tests after this one expect the code under test.+ restore = run_update(directory, "run6-restore", local = True)+ assert restore.rc == 0, restore.log[-8000:]+ _assert_install_working(install, before, same_distributions = False)+ pytest.skip("installed version is not PyPI's latest; the offline keep path was not taken")assert diff(before, snapshot(install)) == []diff --git a/tests/studio/install/test_update_idempotency_release_window.py b/tests/studio/install/test_update_idempotency_release_window.pynew file mode 100644index 00000000000..ae35134b947--- /dev/null+++ b/tests/studio/install/test_update_idempotency_release_window.py@@ -0,0 +1,126 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Every PyPI-path update test in test_update_idempotency.py must survive the release window.++Between a version bump on main and its publish, the checkout's unsloth is not PyPI's, so an update+that reaches PyPI (Windows: Invoke-RestMethod ignores HTTPS_PROXY) logs UPGRADE_MARKER and moves the+install to PyPI's release. A test that then asserts nothing on disk moved fails every Windows run+until the publish, and, without restoring the checkout, leaves the later tests running PyPI's code.+"""++from __future__ import annotations++import ast+import pathlib++SOURCE = pathlib.Path(__file__).with_name("test_update_idempotency.py")+++def _kw(call: ast.Call, name: str):+ for kw in call.keywords:+ if kw.arg == name and isinstance(kw.value, ast.Constant):+ return kw.value.value+ return None+++def _run_updates(fn: ast.FunctionDef) -> list[ast.Call]:+ return [+ n+ for n in ast.walk(fn)+ if isinstance(n, ast.Call) and isinstance(n.func, ast.Name) and n.func.id == "run_update"+ ]+++def _disk_unchanged_asserts(fn: ast.FunctionDef) -> list[ast.Assert]:+ """`assert diff(before, snapshot(...)) == []`."""+ out = []+ for n in ast.walk(fn):+ if not isinstance(n, ast.Assert) or not isinstance(n.test, ast.Compare):+ continue+ left = n.test.left+ if (+ isinstance(left, ast.Call)+ and isinstance(left.func, ast.Name)+ and left.func.id == "diff"+ ):+ out.append(n)+ return out+++def _guards_upgrade_before(fn: ast.FunctionDef, line: int) -> bool:+ """An `if` before `line` that reads UPGRADE_MARKER (in its test or body), restores the checkout+ (run_update local=True) and leaves the test (skip, fail or return)."""+ for n in ast.walk(fn):+ if not isinstance(n, ast.If) or n.lineno >= line:+ continue+ body = ast.Module(body = n.body, type_ignores = [])+ names = {x.id for x in ast.walk(n) if isinstance(x, ast.Name)}+ if "UPGRADE_MARKER" not in names:+ continue+ restores = any(+ isinstance(x, ast.Call)+ and isinstance(x.func, ast.Name)+ and x.func.id == "run_update"+ and _kw(x, "local") is True+ for x in ast.walk(body)+ )+ leaves = any(+ isinstance(x, ast.Call)+ and isinstance(x.func, ast.Attribute)+ and x.func.attr in ("skip", "fail")+ for x in ast.walk(body)+ ) or any(isinstance(x, ast.Return) for x in ast.walk(body))+ if restores and leaves:+ return True+ return False+++def offenders(source: str) -> list[str]:+ bad = []+ for fn in ast.parse(source).body:+ if not isinstance(fn, ast.FunctionDef) or not fn.name.startswith("test_"):+ continue+ if not any(_kw(c, "local") is False for c in _run_updates(fn)):+ continue+ for a in _disk_unchanged_asserts(fn):+ if not _guards_upgrade_before(fn, a.lineno):+ bad.append(f"{fn.name}:{a.lineno}")+ return bad+++def test_pypi_path_update_tests_handle_the_release_window():+ assert SOURCE.is_file(), SOURCE+ assert offenders(SOURCE.read_text(encoding = "utf-8")) == []+++def test_the_checker_flags_an_unguarded_disk_assert():+ unguarded = (+ "def test_x(install, settled):\n"+ " run = run_update(d, 'r', local = False)\n"+ " assert diff(before, snapshot(install)) == []\n"+ )+ assert offenders(unguarded) == ["test_x:3"]+ no_restore = (+ "def test_x(install, settled):\n"+ " run = run_update(d, 'r', local = False)\n"+ " if UPGRADE_MARKER in run.log:\n"+ " pytest.skip('x')\n"+ " assert diff(before, snapshot(install)) == []\n"+ )+ assert offenders(no_restore) == ["test_x:5"]+ guarded = (+ "def test_x(install, settled):\n"+ " run = run_update(d, 'r', local = False)\n"+ " if UPGRADE_MARKER in run.log:\n"+ " run_update(d, 'restore', local = True)\n"+ " pytest.skip('x')\n"+ " assert diff(before, snapshot(install)) == []\n"+ )+ assert offenders(guarded) == []+ local_only = (+ "def test_x(install, settled):\n"+ " run = run_update(d, 'r', local = True)\n"+ " assert diff(before, snapshot(install)) == []\n"+ )+ assert offenders(local_only) == []