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
Collapse repeated fixture construction in the studio install tests (#10501)
Daniel Han8a056b3372be
diff --git a/tests/studio/install/test_install_llama_prebuilt_logic.py b/tests/studio/install/test_install_llama_prebuilt_logic.pyindex 31bcb85647a..221acd9fd2d 100644--- a/tests/studio/install/test_install_llama_prebuilt_logic.py+++ b/tests/studio/install/test_install_llama_prebuilt_logic.py@@ -53,8 +53,111 @@ ensure_diffusion_visual_server = INSTALL_LLAMA_PREBUILT.ensure_diffusion_visual_runtime_payload_health_groups = INSTALL_LLAMA_PREBUILT.runtime_payload_health_groups-def linux_host() -> HostInfo:- return HostInfo(+def write_metadata(+ install_dir,+ choice,+ approved_checksums,+ *,+ requested_tag = "latest",+ llama_tag = "b9001",+ release_tag = "release-1",+ prebuilt_fallback_used = False,+):+ write_prebuilt_metadata(+ install_dir,+ requested_tag = requested_tag,+ llama_tag = llama_tag,+ release_tag = release_tag,+ choice = choice,+ approved_checksums = approved_checksums,+ prebuilt_fallback_used = prebuilt_fallback_used,+ )+++def release_plan(+ attempts,+ approved_checksums,+ *,+ requested_tag = "latest",+ llama_tag = "b9001",+ release_tag = "release-1",+):+ return INSTALL_LLAMA_PREBUILT.InstallReleasePlan(+ requested_tag = requested_tag,+ llama_tag = llama_tag,+ release_tag = release_tag,+ attempts = attempts,+ approved_checksums = approved_checksums,+ )+++def asset_choice(**overrides) -> AssetChoice:+ """The b9001 linux-cpu upstream asset; `overrides` swaps any field. A `name`+ override re-derives `url` as https://example.com/<name>, so pass `url` explicitly+ only when it must differ."""+ name = overrides.pop("name", "llama-b9001-bin-ubuntu-x64.tar.gz")+ defaults = dict(+ repo = "unslothai/llama.cpp",+ tag = "release-1",+ name = name,+ url = f"https://example.com/{name}",+ source_label = "upstream",+ install_kind = "linux-cpu",+ expected_sha256 = "a" * 64,+ )+ defaults.update(overrides)+ return AssetChoice(**defaults)+++UPSTREAM = ("ggml-org/llama.cpp", "upstream-prebuilt")+PREBUILT = ("unslothai/llama.cpp", "prebuilt")+_SOURCE = ("ggml-org/llama.cpp", "upstream-source")+++def _artifact_hash(asset_name: str, sha256: str, origin: tuple[str, str]) -> ApprovedArtifactHash:+ repo, kind = origin+ return ApprovedArtifactHash(asset_name = asset_name, sha256 = sha256, repo = repo, kind = kind)+++def release_checksums(+ *assets: tuple[str, str, tuple[str, str]],+ release_tag: str = "release-1",+ upstream_tag: str = "b9001",+ source_commit: str | None = "deadbeef",+ source_sha256: str = "b" * 64,+) -> ApprovedReleaseChecksums:+ """Approved checksums for one unslothai/llama.cpp release: the upstream source+ archive plus one entry per (asset_name, sha256, origin). source_commit = None+ means "no source archive approved" and drops that entry."""+ artifacts = {}+ if source_commit is not None:+ logical = source_archive_logical_name(upstream_tag)+ artifacts[logical] = _artifact_hash(logical, source_sha256, _SOURCE)+ for asset_name, sha256, origin in assets:+ artifacts[asset_name] = _artifact_hash(asset_name, sha256, origin)+ return ApprovedReleaseChecksums(+ repo = "unslothai/llama.cpp",+ release_tag = release_tag,+ upstream_tag = upstream_tag,+ source_commit = source_commit,+ artifacts = artifacts,+ )+++def _host(platform: dict, **overrides) -> HostInfo:+ base = dict(+ nvidia_smi = None,+ driver_cuda_version = None,+ compute_caps = [],+ visible_cuda_devices = None,+ has_physical_nvidia = False,+ has_usable_nvidia = False,+ )+ return HostInfo(**{**platform, **base, **overrides})+++def linux_host(**overrides) -> HostInfo:+ platform = dict(system = "Linux",machine = "x86_64",is_windows = False,@@ -62,13 +165,34 @@ def linux_host() -> HostInfo:is_macos = False,is_x86_64 = True,is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,)+ return _host(platform, **overrides)+++def windows_host(**overrides) -> HostInfo:+ platform = dict(+ system = "Windows",+ machine = "AMD64",+ is_windows = True,+ is_linux = False,+ is_macos = False,+ is_x86_64 = True,+ is_arm64 = False,+ )+ return _host(platform, **overrides)+++def macos_host(**overrides) -> HostInfo:+ platform = dict(+ system = "Darwin",+ machine = "arm64",+ is_windows = False,+ is_linux = False,+ is_macos = True,+ is_x86_64 = False,+ is_arm64 = True,+ )+ return _host(platform, **overrides)def approved_release_checksums_for_asset(asset_name: str, sha256: str) -> ApprovedReleaseChecksums:@@ -112,10 +236,9 @@ def approved_checksums_for()-# The extract_archive guard tests (safe symlink chain / hardlink, absolute or-# escaping or unresolved symlink targets, zip symlink entries) moved verbatim-# to tests/studio/install/test_prebuilt_core.py: extract_archive is the shared-# prebuilt_core implementation, re-exported by this installer.+# The extract_archive guard tests (safe symlink chain / hardlink, absolute, escaping+# or unresolved symlink targets, zip symlink entries) moved verbatim to+# test_prebuilt_core.py: extract_archive is the shared implementation re-exported here.def test_remove_agent_instruction_files_does_not_follow_links(tmp_path: Path):@@ -532,26 +655,12 @@ def test_validate_prebuilt_choice_creates_repo_shaped_linux_install(monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "validate_quantize", lambda *args, **kwargs: None)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "validate_server", lambda *args, **kwargs: None)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "local",- tag = upstream_tag,+ host = linux_host()+ choice = asset_choice(name = bundle_name,url = "file://bundle",+ repo = "local",+ tag = upstream_tag,source_label = "local",is_ready_bundle = True,install_kind = "linux-cuda",@@ -649,26 +758,12 @@ def test_validate_prebuilt_choice_creates_repo_shaped_windows_install(monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "validate_quantize", lambda *args, **kwargs: None)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "validate_server", lambda *args, **kwargs: None)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "local",- tag = upstream_tag,+ host = windows_host()+ choice = asset_choice(name = bundle_name,url = "file://bundle.zip",+ repo = "local",+ tag = upstream_tag,source_label = "local",is_ready_bundle = True,install_kind = "windows-cpu",@@ -719,21 +814,7 @@ def test_activate_install_tree_restores_existing_install_after_activation_failurstaging_dir = create_install_staging_dir(install_dir)(staging_dir / "new.txt").write_text("new install\n")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,@@ -791,21 +872,7 @@ def test_activate_install_tree_keeps_rollback_when_restore_fails(staging_dir = create_install_staging_dir(install_dir)(staging_dir / "new.txt").write_text("new install\n")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,@@ -903,10 +970,9 @@ def _fail_activation_then_restore_rename(def test_activate_install_tree_reports_a_recovery_disk_full_as_out_of_space(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, make_copy_error):- """The copy back is the first step of this path that needs free space -- every- step before it renames or deletes -- so a full disk can show up there and- nowhere else. Dropping it would leave the caller starting a source build that- needs far more room than the copy that just failed."""+ """The copy back is the first step here that needs free space -- everything before+ it renames or deletes -- so a full disk shows up there and nowhere else. Dropping+ it would start a source build needing far more room than the copy that failed."""install_dir, staging_dir = _fail_activation_then_restore_rename(tmp_path, monkeypatch, make_copy_error())@@ -1254,10 +1320,9 @@ def test_retention_keeps_a_known_good_install_over_an_unvalidated_one():"""Two failed updates in a row must not trade the last good install for a stub.- Attempt 1 leaves a tree at install_dir that is not a usable install and that- cleanup cannot remove, so attempt 2 moves exactly that tree into the new- rollback path. Capping retention on the newer path alone would then delete- the only llama.cpp the user still has.+ Attempt 1 leaves an unusable tree at install_dir that cleanup cannot remove, so+ attempt 2 moves exactly that tree into the new rollback path. Capping retention on+ the newer path alone would delete the only llama.cpp the user still has."""good = b"GOOD-LLAMA-CPP\n"install_dir = tmp_path / "llama.cpp"@@ -1403,12 +1468,11 @@ def test_prune_stale_install_side_paths_ignores_another_installs_side_paths(tmp_def test_prune_stale_install_side_paths_ignores_a_sibling_named_like_a_side_path(tmp_path: Path):- # Two installs in one parent share a .staging root but hold *different*- # locks, since install_lock_path keys on the directory name. glob.escape- # only neutralises * ? and [, so "<name>.rollback-*" can still run past the- # end of <name> into a sibling called "<name>.rollback-special": updating- # the first install would delete that sibling's retained rollback tree,- # possibly its last copy, along with its live staging dir.+ # Two installs in one parent share a .staging root but hold *different* locks,+ # since install_lock_path keys on the directory name. glob.escape neutralises+ # only * ? and [, so "<name>.rollback-*" can run past <name> into a sibling+ # "<name>.rollback-special", deleting its retained rollback tree (possibly its+ # last copy) and its live staging dir.install_dir = tmp_path / "llama.cpp"install_dir.mkdir()sibling = tmp_path / "llama.cpp.rollback-special"@@ -1501,10 +1565,9 @@ def test_remove_tree_logged_leaves_posix_directory_modes_alone(tmp_path: Path):try:with pytest.raises(OSError):remove_tree_logged(tree, "unreadable tree")- # S_IWRITE is an assignment, not a bit clear, so a handler here would- # leave the directory at 0o200 and harder to delete by hand. On POSIX- # the unlink permission lives on the parent anyway, so a chmod of this- # entry could not have fixed anything.+ # S_IWRITE assigns rather than clears a bit, so a handler here would leave the+ # directory at 0o200 and harder to delete by hand. On POSIX the unlink permission+ # lives on the parent anyway, so a chmod of this entry could not have helped.assert stat.S_IMODE(os.stat(unreadable).st_mode) == 0o500finally:if unreadable.exists():@@ -1895,21 +1958,7 @@ def test_binary_env_linux_includes_binary_parent_in_ld_library_path(binary_path = bin_dir / "llama-server"binary_path.write_bytes(b"fake")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "linux_runtime_dirs", lambda _bp: [])@@ -1948,21 +1997,7 @@ def test_binary_env_windows_skips_inaccessible_inherited_path_entry(def resolve(self):return Path(self.raw).resolve()- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = windows_host()# Exercise Windows PATH parsing even when this test runs on a POSIX host.monkeypatch.setattr(INSTALL_LLAMA_PREBUILT.os, "pathsep", ";")@@ -2100,21 +2135,7 @@ def test_binary_env_strips_secrets_from_downloaded_binary_environment(binary_path = bin_dir / "llama-server"binary_path.write_bytes(b"fake")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "linux_runtime_dirs", lambda _bp: [])monkeypatch.setenv("HF_TOKEN", "hf_secret_from_ci")@@ -2143,21 +2164,7 @@ def test_binary_env_redirects_home_away_from_real_credential_stores(binary_path = bin_dir / "llama-server"binary_path.write_bytes(b"fake")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "linux_runtime_dirs", lambda _bp: [])real_home = str(tmp_path / "real_home")@@ -2189,21 +2196,7 @@ def test_scrub_env_drops_token_only_url_userinfo():def test_binary_env_drops_explicit_credential_file_pointers(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "linux_runtime_dirs", lambda _bp: [])dropped = ("NETRC",@@ -2248,64 +2241,25 @@ def test_install_prebuilt_falls_back_to_older_release_plan(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):install_dir = tmp_path / "llama.cpp"- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()- first_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "old-release",+ first_choice = asset_choice(name = "app-b9002-linux-x64.tar.gz",- url = "https://example.com/app-b9002-linux-x64.tar.gz",+ tag = "old-release",source_label = "published",- install_kind = "linux-cpu",)- second_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "older-release",+ second_choice = asset_choice(name = "app-b9001-linux-x64.tar.gz",- url = "https://example.com/app-b9001-linux-x64.tar.gz",+ tag = "older-release",source_label = "published",- install_kind = "linux-cpu",)- first_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",+ first_plan = release_plan(+ [first_choice],+ release_checksums(release_tag = "release-2", upstream_tag = "b9002", source_commit = None),llama_tag = "b9002",release_tag = "release-2",- attempts = [first_choice],- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-2",- upstream_tag = "b9002",- source_commit = None,- artifacts = {},- ),- )- second_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [second_choice],- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = None,- artifacts = {},- ),)+ second_plan = release_plan([second_choice], release_checksums(source_commit = None))monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "detect_host", lambda: host)monkeypatch.setattr(@@ -2459,67 +2413,12 @@ def test_existing_install_matches_plan_with_fingerprint_linux(tmp_path: Path):install_dir.mkdir()write_linux_install_shape(install_dir)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ host = linux_host()+ choice = asset_choice()+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ plan = release_plan([choice], checksums)- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ write_metadata(install_dir, choice, checksums)assert existing_install_matches_plan(install_dir, host, plan) is True@@ -2533,57 +2432,10 @@ def test_existing_install_matches_plan_false_without_fingerprint(tmp_path: Path)encoding = "utf-8",)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/x.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ host = linux_host()+ choice = asset_choice(url = "https://example.com/x.tar.gz")+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ plan = release_plan([choice], checksums)assert existing_install_matches_plan(install_dir, host, plan) is False@@ -2594,57 +2446,10 @@ def test_existing_install_matches_plan_false_with_malformed_metadata(tmp_path: Pwrite_linux_install_shape(install_dir)(install_dir / "UNSLOTH_PREBUILT_INFO.json").write_text("{not-json\n", encoding = "utf-8")- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/x.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ host = linux_host()+ choice = asset_choice(url = "https://example.com/x.tar.gz")+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ plan = release_plan([choice], checksums)assert existing_install_matches_plan(install_dir, host, plan) is False@@ -2654,66 +2459,16 @@ def test_existing_install_matches_plan_windows_cpu_requires_llama_dll(tmp_path:install_dir.mkdir()write_windows_install_shape(install_dir, include_llama_dll = True)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = windows_host()+ choice = asset_choice(name = "llama-b9001-bin-win-cpu-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,)+ checksums = release_checksums((choice.name, choice.expected_sha256, PREBUILT))+ plan = release_plan([choice], checksums)+ write_metadata(install_dir, choice, checksums)assert existing_install_matches_plan(install_dir, host, plan) is True(install_dir / "build" / "bin" / "Release" / "llama.dll").unlink()@@ -2725,67 +2480,17 @@ def test_existing_install_matches_plan_windows_cuda_requires_cuda_dll(tmp_path:install_dir.mkdir()write_windows_install_shape(install_dir, include_llama_dll = True, include_cuda_dll = True)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (12, 4),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = True,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = windows_host(driver_cuda_version = (12, 4), has_usable_nvidia = True)+ choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,)+ checksums = release_checksums((choice.name, choice.expected_sha256, PREBUILT))+ plan = release_plan([choice], checksums)+ write_metadata(install_dir, choice, checksums)assert existing_install_matches_plan(install_dir, host, plan) is True(install_dir / "build" / "bin" / "Release" / "ggml-cuda.dll").unlink()@@ -2803,76 +2508,23 @@ def test_existing_install_matches_plan_windows_cuda_paired_requires_cudart(tmp_pinclude_cudart_dlls = True,)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (12, 4),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = True,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = windows_host(driver_cuda_version = (12, 4), has_usable_nvidia = True)+ choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,runtime_name = "cudart-llama-bin-win-cuda-12.4-x64.zip",runtime_url = "https://example.com/cudart.zip",runtime_sha256 = "c" * 64,)- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- choice.runtime_name: ApprovedArtifactHash(- asset_name = choice.runtime_name,- sha256 = choice.runtime_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,+ checksums = release_checksums(+ (choice.name, choice.expected_sha256, PREBUILT),+ (choice.runtime_name, choice.runtime_sha256, PREBUILT),)+ plan = release_plan([choice], checksums)+ write_metadata(install_dir, choice, checksums)# Fully populated install (main archive + cudart DLLs) matches.assert existing_install_matches_plan(install_dir, host, plan) is True@@ -2913,67 +2565,17 @@ def test_existing_install_matches_plan_windows_cuda_unpaired_skips_cudart_check(include_cudart_dlls = False,)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (12, 4),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = True,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = windows_host(driver_cuda_version = (12, 4), has_usable_nvidia = True)+ choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,)+ checksums = release_checksums((choice.name, choice.expected_sha256, PREBUILT))+ plan = release_plan([choice], checksums)+ write_metadata(install_dir, choice, checksums)assert existing_install_matches_plan(install_dir, host, plan) is True@@ -2996,25 +2598,12 @@ def test_arch_fields_do_not_change_the_install_fingerprint(tmp_path: Path):# The pre-PR marker shape: no arch fields at all.old_choice = AssetChoice(**choice_kwargs)# Verbatim from the published manifest for this asset.- new_choice = AssetChoice(- **choice_kwargs,- gfx_target = "gfx110X",- mapped_targets = ["gfx1100", "gfx1101", "gfx1102", "gfx1103"],- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- },+ new_choice = AssetChoice(+ **choice_kwargs,+ gfx_target = "gfx110X",+ mapped_targets = ["gfx1100", "gfx1101", "gfx1102", "gfx1103"],)+ checksums = release_checksums()fingerprint_kwargs = dict(llama_tag = "b9001", release_tag = "release-1", approved_checksums = checksums)@@ -3034,15 +2623,7 @@ def test_arch_fields_do_not_change_the_install_fingerprint(tmp_path: Path):# upgraded client does not decide the install on disk is stale.install_dir = tmp_path / "llama.cpp"install_dir.mkdir()- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = new_choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ write_metadata(install_dir, new_choice, checksums)marker = json.loads((install_dir / "UNSLOTH_PREBUILT_INFO.json").read_text())assert marker["mapped_targets"] == ["gfx1100", "gfx1101", "gfx1102", "gfx1103"]assert marker["gfx_target"] == "gfx110X"@@ -3053,20 +2634,7 @@ def test_non_rocm_bundles_record_no_mapped_targets(tmp_path: Path):"""CPU/CUDA/Vulkan/macOS choices never populate the arch fields (#7624): onlypublished_rocm_choice_for_host sets them, so the marker records [] and the runtimegate fails open on a non-ROCm bundle."""- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- },- )+ checksums = release_checksums()for kind, asset in (("linux-cpu", "app-b9001-linux-x64-cpu.tar.gz"),("linux-cuda12", "app-b9001-linux-x64-cuda12-portable.tar.gz"),@@ -3076,22 +2644,15 @@ def test_non_rocm_bundles_record_no_mapped_targets(tmp_path: Path):):install_dir = tmp_path / kindinstall_dir.mkdir()- write_prebuilt_metadata(+ write_metadata(install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ asset_choice(name = asset,url = "https://example.com/x",source_label = "published",install_kind = kind,- expected_sha256 = "a" * 64,),- approved_checksums = checksums,- prebuilt_fallback_used = False,+ checksums,)marker = json.loads((install_dir / "UNSLOTH_PREBUILT_INFO.json").read_text())assert marker["mapped_targets"] == [], kind@@ -3099,8 +2660,7 @@ def test_non_rocm_bundles_record_no_mapped_targets(tmp_path: Path):def _rocm_choice(**overrides):- """A published ROCm bundle choice, the shape published_rocm_choice_for_host- returns."""+ """A published ROCm bundle choice, as published_rocm_choice_for_host returns."""fields = dict(repo = "unslothai/llama.cpp",tag = "b10360",@@ -3269,11 +2829,10 @@ def test_a_reused_install_backfills_the_paired_runtime_asset(tmp_path: Path):json.dumps({"release_tag": "release-1", "llama_backend": "auto", "force_cpu": False}),encoding = "utf-8",)- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "b9002",+ choice = asset_choice(name = "app-b9002-windows-cuda-x64.zip",url = "https://example/x",+ tag = "b9002",source_label = "published",install_kind = "windows-cuda",runtime_name = "cudart-llama-bin-win-cuda-13.0-x64.zip",@@ -3294,11 +2853,10 @@ def test_a_pair_less_reuse_does_not_invent_a_runtime_asset(tmp_path: Path):json.dumps({"release_tag": "release-1", "llama_backend": "auto", "force_cpu": False}),encoding = "utf-8",)- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "b9002",+ choice = asset_choice(name = "app-b9002-windows-cpu-x64.zip",url = "https://example/x",+ tag = "b9002",source_label = "published",install_kind = "windows-cpu",)@@ -3310,9 +2868,8 @@ def test_a_pair_less_reuse_does_not_invent_a_runtime_asset(tmp_path: Path):def test_marker_rewrite_preserves_arch_fields(tmp_path: Path):"""A sync that touches other fields must not drop the arch ones (#7624).- sync_marker_selection reads the marker, applies a patch and writes the whole dict- back; a rebuild-from-known-keys implementation would strip mapped_targets on any- reused install, turning the gate off unnoticed."""+ sync_marker_selection reads the marker, patches it and writes the whole dict back; a+ rebuild-from-known-keys version would strip mapped_targets and silently kill the gate."""install_dir = tmp_path / "llama.cpp"install_dir.mkdir()marker_path = install_dir / "UNSLOTH_PREBUILT_INFO.json"@@ -3371,14 +2928,12 @@ def test_write_prebuilt_metadata_records_supported_sms(tmp_path: Path):install_dir = tmp_path / "llama.cpp"install_dir.mkdir()choice = _cuda_choice()- write_prebuilt_metadata(+ write_metadata(install_dir,- requested_tag = "latest",+ choice,+ approved_release_checksums_for_asset(choice.name, "a" * 64),llama_tag = "b10360",release_tag = "b10360",- choice = choice,- approved_checksums = approved_release_checksums_for_asset(choice.name, "a" * 64),- prebuilt_fallback_used = False,)marker = json.loads((install_dir / "UNSLOTH_PREBUILT_INFO.json").read_text())assert marker["supported_sms"] == ["75", "80", "86", "89"]@@ -3425,81 +2980,31 @@ def test_existing_install_fingerprint_changes_when_cudart_pair_added(tmp_path: Pinclude_cudart_dlls = False,)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (12, 4),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = True,- )- legacy_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = windows_host(driver_cuda_version = (12, 4), has_usable_nvidia = True)+ legacy_choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,)- paired_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ paired_choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "https://example.com/x.zip",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,runtime_name = "cudart-llama-bin-win-cuda-12.4-x64.zip",runtime_url = "https://example.com/cudart.zip",runtime_sha256 = "c" * 64,)- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- legacy_choice.name: ApprovedArtifactHash(- asset_name = legacy_choice.name,- sha256 = legacy_choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- paired_choice.runtime_name: ApprovedArtifactHash(- asset_name = paired_choice.runtime_name,- sha256 = paired_choice.runtime_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },+ checksums = release_checksums(+ (legacy_choice.name, legacy_choice.expected_sha256, PREBUILT),+ (paired_choice.runtime_name, paired_choice.runtime_sha256, PREBUILT),)# Metadata written for the legacy (no-pair) choice.- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = legacy_choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ write_metadata(install_dir, legacy_choice, checksums)# The paired choice's fingerprint must differ from the legacy one so the install refreshes.legacy_fingerprint = INSTALL_LLAMA_PREBUILT.expected_install_fingerprint(@@ -3519,13 +3024,7 @@ def test_existing_install_fingerprint_changes_when_cudart_pair_added(tmp_path: P"so pre-#5322 installs are not falsely considered up-to-date")- paired_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [paired_choice],- approved_checksums = checksums,- )+ paired_plan = release_plan([paired_choice], checksums)assert existing_install_matches_plan(install_dir, host, paired_plan) is False@@ -3534,66 +3033,16 @@ def test_existing_install_matches_plan_macos_requires_dylibs(tmp_path: Path):install_dir.mkdir()write_macos_install_shape(install_dir)- host = HostInfo(- system = "Darwin",- machine = "arm64",- is_windows = False,- is_linux = False,- is_macos = True,- is_x86_64 = False,- is_arm64 = True,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = macos_host()+ choice = asset_choice(name = "llama-b9001-bin-macos-arm64.tar.gz",url = "https://example.com/x.tar.gz",source_label = "published",install_kind = "macos-arm64",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,)+ checksums = release_checksums((choice.name, choice.expected_sha256, PREBUILT))+ plan = release_plan([choice], checksums)+ write_metadata(install_dir, choice, checksums)assert existing_install_matches_plan(install_dir, host, plan) is True(install_dir / "build" / "bin" / "libggml.0.dylib").unlink()@@ -3607,67 +3056,12 @@ def test_install_prebuilt_skips_download_when_existing_install_matches(install_dir.mkdir()write_linux_install_shape(install_dir)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ host = linux_host()+ choice = asset_choice()+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ plan = release_plan([choice], checksums)- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ write_metadata(install_dir, choice, checksums)(install_dir / "AGENTS.md").write_text("old root instructions", encoding = "utf-8")nested_agents = install_dir / "examples" / "AGENTS.md"nested_agents.parent.mkdir()@@ -3741,99 +3135,44 @@ def test_setup_sh_cleanup_unlinks_instruction_symlink_only(tmp_path: Path):if shutil.which("bash") is None:pytest.skip("bash is not available")- setup_sh = (PACKAGE_ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")- start = setup_sh.index("_remove_agent_instruction_files() {")- end = setup_sh.index("\n}\n", start) + 2- function = setup_sh[start:end]- managed = tmp_path / "managed"- external = tmp_path / "external.md"- managed.mkdir()- external.write_text("external", encoding = "utf-8")- instruction = managed / "AGENTS.md"- try:- instruction.symlink_to(external)- except OSError as exc:- pytest.skip(f"symlinks unavailable: {exc}")-- subprocess.run(- ["bash", "-c", function + '\n_remove_agent_instruction_files "$1"', "bash", str(managed)],- check = True,- )-- assert not os.path.lexists(instruction)- assert external.read_text(encoding = "utf-8") == "external"---def test_install_prebuilt_does_not_skip_unhealthy_existing_install(- tmp_path: Path, monkeypatch: pytest.MonkeyPatch-):- install_dir = tmp_path / "llama.cpp"- install_dir.mkdir()- write_linux_install_shape(install_dir)- (install_dir / "llama-quantize").unlink()-- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ setup_sh = (PACKAGE_ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")+ start = setup_sh.index("_remove_agent_instruction_files() {")+ end = setup_sh.index("\n}\n", start) + 2+ function = setup_sh[start:end]+ managed = tmp_path / "managed"+ external = tmp_path / "external.md"+ managed.mkdir()+ external.write_text("external", encoding = "utf-8")+ instruction = managed / "AGENTS.md"+ try:+ instruction.symlink_to(external)+ except OSError as exc:+ pytest.skip(f"symlinks unavailable: {exc}")- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,+ subprocess.run(+ ["bash", "-c", function + '\n_remove_agent_instruction_files "$1"', "bash", str(managed)],+ check = True,)+ assert not os.path.lexists(instruction)+ assert external.read_text(encoding = "utf-8") == "external"+++def test_install_prebuilt_does_not_skip_unhealthy_existing_install(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+):+ install_dir = tmp_path / "llama.cpp"+ install_dir.mkdir()+ write_linux_install_shape(install_dir)+ (install_dir / "llama-quantize").unlink()++ host = linux_host()+ choice = asset_choice()+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ plan = release_plan([choice], checksums)++ write_metadata(install_dir, choice, checksums)+monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "detect_host", lambda: host)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,@@ -3867,103 +3206,32 @@ def test_install_prebuilt_skips_when_older_release_fallback_matches_existing_insinstall_dir.mkdir()write_linux_install_shape(install_dir)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- latest_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-2",+ host = linux_host()+ latest_choice = asset_choice(name = "llama-b9002-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9002-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",+ tag = "release-2",expected_sha256 = "c" * 64,)- fallback_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- latest_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",+ fallback_choice = asset_choice()+ latest_checksums = release_checksums(+ (latest_choice.name, latest_choice.expected_sha256, UPSTREAM),release_tag = "release-2",upstream_tag = "b9002",source_commit = "beadfeed",- artifacts = {- source_archive_logical_name("b9002"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9002"),- sha256 = "d" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- latest_choice.name: ApprovedArtifactHash(- asset_name = latest_choice.name,- sha256 = latest_choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },+ source_sha256 = "d" * 64,)- fallback_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- fallback_choice.name: ApprovedArtifactHash(- asset_name = fallback_choice.name,- sha256 = fallback_choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },+ fallback_checksums = release_checksums(+ (fallback_choice.name, fallback_choice.expected_sha256, UPSTREAM))- latest_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",+ latest_plan = release_plan(+ [latest_choice],+ latest_checksums,llama_tag = "b9002",release_tag = "release-2",- attempts = [latest_choice],- approved_checksums = latest_checksums,- )- fallback_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [fallback_choice],- approved_checksums = fallback_checksums,)+ fallback_plan = release_plan([fallback_choice], fallback_checksums)- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = fallback_choice,- approved_checksums = fallback_checksums,- prebuilt_fallback_used = True,- )+ write_metadata(install_dir, fallback_choice, fallback_checksums, prebuilt_fallback_used = True)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "detect_host", lambda: host)monkeypatch.setattr(@@ -4028,82 +3296,20 @@ def test_install_prebuilt_skips_same_release_fallback_attempt_when_installed(install_dir.mkdir()write_linux_install_shape(install_dir)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- first_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ host = linux_host()+ first_choice = asset_choice(name = "llama-b9001-bin-ubuntu-x64-bad.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64-bad.tar.gz",source_label = "published",- install_kind = "linux-cpu",expected_sha256 = "c" * 64,)- fallback_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64-good.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64-good.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- first_choice.name: ApprovedArtifactHash(- asset_name = first_choice.name,- sha256 = first_choice.expected_sha256,- repo = "unslothai/llama.cpp",- kind = "prebuilt",- ),- fallback_choice.name: ApprovedArtifactHash(- asset_name = fallback_choice.name,- sha256 = fallback_choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [first_choice, fallback_choice],- approved_checksums = checksums,+ fallback_choice = asset_choice(name = "llama-b9001-bin-ubuntu-x64-good.tar.gz")+ checksums = release_checksums(+ (first_choice.name, first_choice.expected_sha256, PREBUILT),+ (fallback_choice.name, fallback_choice.expected_sha256, UPSTREAM),)+ plan = release_plan([first_choice, fallback_choice], checksums)- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = fallback_choice,- approved_checksums = checksums,- prebuilt_fallback_used = True,- )+ write_metadata(install_dir, fallback_choice, checksums, prebuilt_fallback_used = True)assert (existing_install_matches_choice(install_dir,@@ -4178,66 +3384,21 @@ def test_install_prebuilt_same_tag_upstream_failure_uses_older_unsloth_release_ptmp_path: Path, monkeypatch: pytest.MonkeyPatch):install_dir = tmp_path / "llama.cpp"- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ host = linux_host()- same_tag_upstream_choice = AssetChoice(+ same_tag_upstream_choice = asset_choice(+ name = "llama-b9002-bin-ubuntu-x64.tar.gz",repo = "ggml-org/llama.cpp",tag = "b9002",- name = "llama-b9002-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9002-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- older_release_choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "b" * 64,)- latest_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",+ older_release_choice = asset_choice(expected_sha256 = "b" * 64)+ latest_plan = release_plan(+ [same_tag_upstream_choice],+ release_checksums(release_tag = "release-2", upstream_tag = "b9002", source_commit = None),llama_tag = "b9002",release_tag = "release-2",- attempts = [same_tag_upstream_choice],- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-2",- upstream_tag = "b9002",- source_commit = None,- artifacts = {},- ),- )- older_plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [older_release_choice],- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = None,- artifacts = {},- ),)+ older_plan = release_plan([older_release_choice], release_checksums(source_commit = None))monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "detect_host", lambda: host)monkeypatch.setattr(@@ -4311,88 +3472,39 @@ def test_install_prebuilt_same_tag_upstream_failure_uses_older_unsloth_release_pdef io_bytes(data: bytes):- return io.BytesIO(data)---def add_bytes_to_tar(- archive: tarfile.TarFile,- name: str,- data: bytes,- *,- mode: int = 0o644,-) -> None:- info = tarfile.TarInfo(name)- info.size = len(data)- info.mode = mode- archive.addfile(info, io_bytes(data))---def add_symlink_to_tar(archive: tarfile.TarFile, name: str, target: str) -> None:- info = tarfile.TarInfo(name)- info.type = tarfile.SYMTYPE- info.linkname = target- archive.addfile(info)---def test_existing_install_matches_choice_fails_when_install_tree_incomplete(tmp_path: Path):- """confirm_install_tree guard rejects installs missing critical files."""- install_dir = tmp_path / "llama.cpp"- install_dir.mkdir()- write_linux_install_shape(install_dir)-- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ return io.BytesIO(data)+++def add_bytes_to_tar(+ archive: tarfile.TarFile,+ name: str,+ data: bytes,+ *,+ mode: int = 0o644,+) -> None:+ info = tarfile.TarInfo(name)+ info.size = len(data)+ info.mode = mode+ archive.addfile(info, io_bytes(data))+++def add_symlink_to_tar(archive: tarfile.TarFile, name: str, target: str) -> None:+ info = tarfile.TarInfo(name)+ info.type = tarfile.SYMTYPE+ info.linkname = target+ archive.addfile(info)+++def test_existing_install_matches_choice_fails_when_install_tree_incomplete(tmp_path: Path):+ """confirm_install_tree guard rejects installs missing critical files."""+ install_dir = tmp_path / "llama.cpp"+ install_dir.mkdir()+ write_linux_install_shape(install_dir)++ host = linux_host()+ choice = asset_choice()+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ write_metadata(install_dir, choice, checksums)# Full install should matchassert (@@ -4428,59 +3540,10 @@ def test_existing_install_matches_choice_fails_when_install_tree_incomplete_macoinstall_dir.mkdir()write_macos_install_shape(install_dir)- host = HostInfo(- system = "Darwin",- machine = "arm64",- is_windows = False,- is_linux = False,- is_macos = True,- is_x86_64 = False,- is_arm64 = True,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-macos-arm64.tar.gz",- url = "https://example.com/llama-b9001-bin-macos-arm64.tar.gz",- source_label = "upstream",- install_kind = "macos-arm64",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ host = macos_host()+ choice = asset_choice(name = "llama-b9001-bin-macos-arm64.tar.gz", install_kind = "macos-arm64")+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ write_metadata(install_dir, choice, checksums)# Full install should matchassert (@@ -4511,73 +3574,21 @@ def test_existing_install_matches_choice_fails_when_install_tree_incomplete_macodef test_existing_macos_install_that_cannot_load_is_not_reused(tmp_path: Path, monkeypatch):- """A bundle that dyld refuses must not be accepted just because its- fingerprint matches.-- This is the path that reaches the users who matter: a bundle that cannot- load is usually ALREADY installed by the time the installer learns to reject- it, and the reuse check ran the Linux preflight only. Re-running the- installer then saw a matching fingerprint, kept the broken tree and failed at- first launch again.+ """A bundle that dyld refuses must not be accepted just because its fingerprint matches.++ A bundle that cannot load is usually ALREADY installed by the time the installer+ learns to reject it, and the reuse check ran the Linux preflight only, so re-running+ the installer saw a matching fingerprint, kept the broken tree and failed at first+ launch again."""install_dir = tmp_path / "llama.cpp"install_dir.mkdir()write_macos_install_shape(install_dir)- host = HostInfo(- system = "Darwin",- machine = "arm64",- is_windows = False,- is_linux = False,- is_macos = True,- is_x86_64 = False,- is_arm64 = True,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- macos_version = (15, 5),- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-macos-arm64.tar.gz",- url = "https://example.com/llama-b9001-bin-macos-arm64.tar.gz",- source_label = "upstream",- install_kind = "macos-arm64",- expected_sha256 = "a" * 64,- )- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- choice.name: ApprovedArtifactHash(- asset_name = choice.name,- sha256 = choice.expected_sha256,- repo = "ggml-org/llama.cpp",- kind = "upstream-prebuilt",- ),- },- )- write_prebuilt_metadata(- install_dir,- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- choice = choice,- approved_checksums = checksums,- prebuilt_fallback_used = False,- )+ host = macos_host(macos_version = (15, 5))+ choice = asset_choice(name = "llama-b9001-bin-macos-arm64.tar.gz", install_kind = "macos-arm64")+ checksums = release_checksums((choice.name, choice.expected_sha256, UPSTREAM))+ write_metadata(install_dir, choice, checksums)def matches() -> bool:return existing_install_matches_choice(@@ -4605,15 +3616,14 @@ def test_existing_macos_install_that_cannot_load_is_not_reused(tmp_path: Path, mdef test_paired_runtime_dll_patterns_excludes_executables() -> None:"""The paired runtime archive must contribute only CUDA DLLs (no *.exe/*.dll) so it can't overwrite binaries."""paired_runtime_dll_patterns = INSTALL_LLAMA_PREBUILT.paired_runtime_dll_patterns- paired_choice = AssetChoice(- repo = "x",- tag = "t",+ paired_choice = asset_choice(name = "llama-b9001-bin-win-cuda-12.4-x64.zip",url = "u",+ repo = "x",+ tag = "t",source_label = "published",install_kind = "windows-cuda",runtime_line = "cuda12",- expected_sha256 = "a" * 64,runtime_name = "cudart-llama-bin-win-cuda-12.4-x64.zip",runtime_url = "https://example.com/cudart.zip",runtime_sha256 = "c" * 64,@@ -4634,14 +3644,13 @@ def test_paired_runtime_dll_patterns_excludes_executables() -> None:"windows-cpu","windows-hip",):- non_windows = AssetChoice(- repo = "x",- tag = "t",+ non_windows = asset_choice(name = "x",url = "u",+ repo = "x",+ tag = "t",source_label = "published",install_kind = kind,- expected_sha256 = "a" * 64,)assert paired_runtime_dll_patterns(non_windows) == []@@ -4674,9 +3683,7 @@ def test_runtime_overlay_cannot_overwrite_main_archive_payload(tmp_path: Path) -zf.writestr("llama-server.exe", b"RUNTIME-OVERWRITE")runtime_sha = hashlib.sha256(runtime_zip.read_bytes()).hexdigest()- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",+ choice = asset_choice(name = main_zip.name,url = f"https://example.com/{main_zip.name}",source_label = "published",@@ -4687,21 +3694,7 @@ def test_runtime_overlay_cannot_overwrite_main_archive_payload(tmp_path: Path) -runtime_url = f"https://example.com/{runtime_zip.name}",runtime_sha256 = runtime_sha,)- host = HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (12, 4),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = True,- )+ host = windows_host(driver_cuda_version = (12, 4), has_usable_nvidia = True)import shutil as _shutil@@ -4774,31 +3767,16 @@ def test_linux_runtime_overlay_copies_llama_tool_impl_libraries(tmp_path: Path)import shutil as _shutilbundle_sha = hashlib.sha256(bundle.read_bytes()).hexdigest()- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "b9334",+ choice = asset_choice(name = bundle.name,url = f"https://example.com/{bundle.name}",+ tag = "b9334",source_label = "published",install_kind = "linux-cuda",runtime_line = "cuda13",expected_sha256 = bundle_sha,)- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = (13, 0),- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = True,- has_usable_nvidia = True,- )+ host = linux_host(driver_cuda_version = (13, 0), has_physical_nvidia = True, has_usable_nvidia = True)orig_download = INSTALL_LLAMA_PREBUILT.download_file_verified@@ -4864,21 +3842,7 @@ def test_python_runtime_dirs_covers_cu13_and_library_bin(monkeypatch, tmp_path:def _nvidia_linux_host():- return HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = ["10.0"],- visible_cuda_devices = None,- has_physical_nvidia = True,- has_usable_nvidia = True,- )+ return linux_host(compute_caps = ["10.0"], has_physical_nvidia = True, has_usable_nvidia = True)def _run_validate_prebuilt_choice(@@ -4918,11 +3882,11 @@ def _run_validate_prebuilt_choice(source_archive.write_bytes(b"source")bundle_archive.write_bytes(b"bundle")- choice = AssetChoice(- repo = "local",- tag = "b9998",+ choice = asset_choice(name = bundle_name,url = "file://bundle",+ repo = "local",+ tag = "b9998",source_label = "local",is_ready_bundle = True,install_kind = "linux-cuda",@@ -5020,30 +3984,8 @@ def test_probe_rate_limit_no_longer_forces_a_source_build(tmp_path, monkeypatch)install_dir = tmp_path / "llama.cpp"install_dir.mkdir()- host = HostInfo(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )- choice = AssetChoice(- repo = "unslothai/llama.cpp",- tag = "release-1",- name = "llama-b9001-bin-ubuntu-x64.tar.gz",- url = "https://example.com/llama-b9001-bin-ubuntu-x64.tar.gz",- source_label = "upstream",- install_kind = "linux-cpu",- expected_sha256 = "a" * 64,- )+ host = linux_host()+ choice = asset_choice()checksums = ApprovedReleaseChecksums(repo = "unslothai/llama.cpp",release_tag = "release-1",@@ -5058,13 +4000,7 @@ def test_probe_rate_limit_no_longer_forces_a_source_build(tmp_path, monkeypatch)),},)- plan = INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",- llama_tag = "b9001",- release_tag = "release-1",- attempts = [choice],- approved_checksums = checksums,- )+ plan = release_plan([choice], checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "detect_host", lambda: host)monkeypatch.setattr(@@ -5095,10 +4031,9 @@ def test_probe_rate_limit_no_longer_forces_a_source_build(tmp_path, monkeypatch)def test_probe_failure_does_not_demote_to_a_lower_priority_candidate(tmp_path, monkeypatch):# validate_prebuilt_attempts catches Exception per candidate, so a probe download- # failing inside that try would read as a bad bundle and quietly install the CPU- # asset over the healthy GPU one -- re-downloading each time, since the thunk- # memoises success but not failure. Hashless attempts always validate, so the- # probe has to be resolved before the loop.+ # failing inside that try would read as a bad bundle and install the CPU asset over+ # the healthy GPU one, re-downloading each time (the thunk memoises success, not+ # failure). Hashless attempts always validate, so resolve the probe before the loop.fetches = []def refuse() -> Path:@@ -5138,13 +4073,7 @@ def test_probe_failure_does_not_demote_to_a_lower_priority_candidate(tmp_path, mrequested_tag = "b9001",llama_tag = "b9001",release_tag = "release-1",- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = None,- artifacts = {},- ),+ approved_checksums = release_checksums(source_commit = None),)assert attempted == [] # the CPU asset was never reached@@ -5168,18 +4097,11 @@ def test_probe_failure_does_not_demote_to_an_older_release(tmp_path, monkeypatchinstall_kind = "linux-cpu",expected_sha256 = None, # hashless plans always smoke-test)- return INSTALL_LLAMA_PREBUILT.InstallReleasePlan(- requested_tag = "latest",+ return release_plan(+ [choice],+ release_checksums(release_tag = release_tag, upstream_tag = llama_tag, source_commit = None),llama_tag = llama_tag,release_tag = release_tag,- attempts = [choice],- approved_checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = release_tag,- upstream_tag = llama_tag,- source_commit = None,- artifacts = {},- ),)plans = [hashless_plan("release-2", "b9002"), hashless_plan("release-1", "b9001")]@@ -5513,13 +4435,11 @@ def test_setup_sh_starts_source_build_only_for_expected_prebuilt_exit():"""Behavioural cover for the exit-code routing: runs the real block under bash.- The previous version of this test compared ``str.index`` offsets, which is a- tautology -- ``index(needle, start)`` never returns less than ``start`` -- so- it asserted only that three literals existed in textual order.-- The PowerShell side of the same routing is covered textually by- test_setup_scripts_unexpected_exit_branch_never_sets_source_build, which is- platform independent.+ The previous version compared ``str.index`` offsets, a tautology --+ ``index(needle, start)`` never returns less than ``start`` -- so it asserted only+ that three literals appeared in order. The PowerShell side is covered textually by+ test_setup_scripts_unexpected_exit_branch_never_sets_source_build, which is platform+ independent."""if shutil.which("bash") is None: # pragma: no cover - CI always has bashpytest.skip("bash is required to exercise the setup.sh routing block")@@ -5594,10 +4514,9 @@ def _run_setup_ps1_routing()script_path = tmp_path / "routing.ps1"script_path.write_text(script, encoding = "utf-8")- # run_pwsh, not subprocess.run: this helper feeds every routing case below, and a pwsh- # killed at startup returns rc -6 with empty stdout, which the callers would compare- # against the bash mirror and report as setup.ps1 routing the exit code wrongly.- # See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh (see tests/_shared/unsloth_pwsh_runner.py), not subprocess.run: a pwsh killed+ # at startup returns rc -6 with empty stdout, which callers would compare against the+ # bash mirror and report as setup.ps1 routing the exit code wrongly.completed = run_pwsh([shutil.which("pwsh") or "pwsh",@@ -5624,15 +4543,14 @@ def _run_setup_ps1_routing(def test_setup_ps1_routing_matches_setup_sh(status, explicit_backend, install_exists, tmp_path):"""Windows must route an installer exit exactly as Linux does.- The two scripts are maintained side by side and the assertions above compare their- SOURCE TEXT, which cannot catch a branch that reads the same and behaves differently- (a PowerShell `$false` string, an `exit` that does not propagate, a guard whose- variable was never set). Running both and comparing the decision is what makes- "the mirrored setup.ps1 does the same" a measurement rather than a claim.+ The assertions above compare SOURCE TEXT, which cannot catch a branch that reads the+ same and behaves differently (a PowerShell `$false` string, an `exit` that does not+ propagate, a guard whose variable was never set). Running both and comparing the+ decision makes "the mirrored setup.ps1 does the same" a measurement, not a claim.- The decision is two values: the process exit code, and whether a source build was- queued. Exit 5 must fail closed everywhere -- that is the point of the exit code --- while exit 2 stays the one automatic path allowed to fall back to a compile.+ The decision is two values: the exit code, and whether a source build was queued.+ Exit 5 must fail closed everywhere, while exit 2 stays the one automatic path+ allowed to fall back to a compile."""if shutil.which("bash") is None: # pragma: no cover - CI always has bashpytest.skip("bash is required to compare against the setup.sh routing block")@@ -5721,10 +4639,9 @@ def test_setup_scripts_unexpected_exit_branch_never_sets_source_build():def test_release_listing_failure_exits_fallback_not_error(tmp_path, monkeypatch, error):"""A network problem while listing releases must ask for a source build.- The setup scripts only source build on EXIT_FALLBACK, so anything that- escapes as EXIT_ERROR here hard-fails the whole install for what is a- transient condition -- a source build clones over git, not api.github.com,- and succeeds while the API is rate limited.+ The setup scripts only source build on EXIT_FALLBACK, so anything escaping as+ EXIT_ERROR hard-fails the whole install for a transient condition. A source build+ clones over git, not api.github.com, and succeeds while the API is rate limited."""def boom(*args, **kwargs):@@ -5934,21 +4851,7 @@ def test_release_listing_failure_does_not_keep_a_non_executable_install(tmp_pathdef _windows_host() -> HostInfo:- return HostInfo(- system = "Windows",- machine = "AMD64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- )+ return windows_host()@pytest.mark.parametrize(@@ -6408,14 +5311,13 @@ def test_recorded_ggml_tree_only_for_binaries_from_that_release():"""def choice(repo):- return AssetChoice(- repo = repo,- tag = "b10173",+ return asset_choice(name = "bundle.tar.gz",url = "https://x/bundle",+ repo = repo,+ tag = "b10173",source_label = "fork" if repo == "unslothai/llama.cpp" else "upstream",is_ready_bundle = True,- install_kind = "linux-cpu",bundle_profile = "cpu",runtime_line = "cpu",expected_sha256 = "0" * 64,@@ -6431,9 +5333,8 @@ def test_recorded_ggml_tree_only_for_binaries_from_that_release():def test_reused_install_backfills_the_ggml_tree(tmp_path):"""An install made before ggml_tree existed must gain it on reuse.- write_prebuilt_metadata only runs on a real install, so without this the- marker stays tree-less forever and slim whisper pairing silently falls back- to the "-mix-" suffix.+ write_prebuilt_metadata only runs on a real install, so without this the marker stays+ tree-less forever and slim whisper pairing falls back to the "-mix-" suffix."""install_dir = tmp_path / "llama.cpp"(install_dir / "build" / "bin").mkdir(parents = True)@@ -6469,10 +5370,9 @@ def test_reused_install_keeps_the_ggml_tree_when_the_release_declares_none(tmp_pdef test_marker_sync_preserves_the_marker_mode(tmp_path, mode):"""A shared install's marker must stay readable by everyone who could read it.- os.replace keeps the SOURCE file's mode and NamedTemporaryFile is 0600, so a- naive atomic refresh would leave UNSLOTH_PREBUILT_INFO.json readable only by- whoever ran setup -- and other users could no longer recognise or update the- shared installation.+ os.replace keeps the SOURCE file's mode and NamedTemporaryFile is 0600, so a naive+ atomic refresh would leave UNSLOTH_PREBUILT_INFO.json readable only by whoever ran+ setup, and other users could no longer recognise or update the shared install."""install_dir = tmp_path / "llama.cpp"install_dir.mkdir()@@ -6515,9 +5415,8 @@ def test_marker_sync_leaves_a_valid_marker_intact_when_the_write_fails(tmp_path,def test_python_runtime_dirs_skips_an_inaccessible_glob_result(monkeypatch, tmp_path):"""A readable site-packages root with a denied child must not abort discovery.- That is the shape of the bug this PR is about: the parent lists fine and the- entry underneath is denied. Guarding only the root would leave the strict- dedupe on the return to raise anyway.+ The parent lists fine and the entry underneath is denied; guarding only the root+ would leave the strict dedupe on the return to raise anyway."""root = tmp_path / "site-packages"good = root / "torch" / "lib"@@ -6628,11 +5527,10 @@ def test_binary_env_linux_skips_inaccessible_inherited_ld_library_path(monkeypatdef _reused_choice(install_kind = "linux-cpu"):"""The bundle a reuse path re-records the run's selection against."""- return AssetChoice(- repo = "unslothai/llama.cpp",- tag = "b10173",+ return asset_choice(name = "bundle.tar.gz",url = "file://bundle",+ tag = "b10173",source_label = "published",install_kind = install_kind,)@@ -6674,11 +5572,10 @@ def _sync_ggml_tree(install_dir, tree):def test_marker_sync_survives_a_read_only_marker(tmp_path, kwargs, install_kind, field, expected):"""A shared or admin-owned install must not fail setup on a marker rewrite.- Re-recording the run's selection (force_cpu, the legacy backend field, the- recorded choice) happens on the existing-install reuse path. The read is- guarded but the write was not, so a read-only marker raised PermissionError- out of the helper as EXIT_ERROR -- which no longer falls back to a source- build, so it would abort the whole install.+ Re-recording the run's selection (force_cpu, the legacy backend field, the recorded+ choice) happens on the existing-install reuse path. The read was guarded, the write+ was not, so a read-only marker raised PermissionError as EXIT_ERROR, which no longer+ falls back to a source build and would abort the whole install."""install_dir = tmp_path / "llama.cpp"install_dir.mkdir()@@ -6731,10 +5628,9 @@ def test_marker_sync_never_fails_setup_when_the_write_cannot_land(tmp_path, monkassert any("WARNING" in line and "force_cpu" in line for line in logged), logged-# The stubs above stand in for these two, so a keyword added to either reaches-# them as a TypeError raised inside whatever assertion happened to be running.-# `rocm_gfx` did exactly that to four tests at once. Named here so the next one-# fails once, in this test, saying which parameter moved.+# The stubs above stand in for these two, so a keyword added to either arrives as a+# TypeError inside whatever assertion was running; `rocm_gfx` did that to four tests+# at once. Named here so the next one fails once, here, saying which parameter moved._VALIDATOR_KEYWORD_ONLY = {"validate_prebuilt_attempts": ("requested_tag",@@ -6796,20 +5692,7 @@ def test_supported_sms_stays_out_of_the_install_fingerprint():coverage_class = "older",expected_sha256 = "a" * 64,)- checksums = ApprovedReleaseChecksums(- repo = "unslothai/llama.cpp",- release_tag = "release-1",- upstream_tag = "b9001",- source_commit = "deadbeef",- artifacts = {- source_archive_logical_name("b9001"): ApprovedArtifactHash(- asset_name = source_archive_logical_name("b9001"),- sha256 = "b" * 64,- repo = "ggml-org/llama.cpp",- kind = "upstream-source",- ),- },- )+ checksums = release_checksums()kwargs = dict(llama_tag = "b9001", release_tag = "release-1", approved_checksums = checksums)without = INSTALL_LLAMA_PREBUILT.expected_install_fingerprint(choice = AssetChoice(**base), **kwargs@@ -6834,14 +5717,12 @@ def test_a_non_cuda_bundle_declares_no_supported_sms(tmp_path: Path, install_kininstall_dir = tmp_path / "llama.cpp"install_dir.mkdir()choice = _cuda_choice(install_kind = install_kind, runtime_line = runtime_line, supported_sms = None)- write_prebuilt_metadata(+ write_metadata(install_dir,- requested_tag = "latest",+ choice,+ approved_release_checksums_for_asset(choice.name, "a" * 64),llama_tag = "b10360",release_tag = "b10360",- choice = choice,- approved_checksums = approved_release_checksums_for_asset(choice.name, "a" * 64),- prebuilt_fallback_used = False,)marker = json.loads((install_dir / "UNSLOTH_PREBUILT_INFO.json").read_text())assert marker["supported_sms"] == []@@ -6967,11 +5848,9 @@ _POST_SPLIT_WINDOWS_PAYLOAD = _PRE_SPLIT_WINDOWS_PAYLOAD + ("llama-server-impl.ddef test_pre_split_upstream_windows_pin_is_not_forced_to_a_source_build(tmp_path: Path, tag: str, payload: tuple[str, ...], healthy: bool):- """A pinned upstream tag older than b9283 ships no llama-server-impl.dll.-- Requiring it unconditionally made validate_prebuilt_choice reject a valid- downloaded prebuilt and fall back to a costly Windows source build.- """+ """A pinned upstream tag older than b9283 ships no llama-server-impl.dll; requiring+ it made validate_prebuilt_choice reject a valid downloaded prebuilt and fall back to+ a costly Windows source build."""install_dir = tmp_path / "llama.cpp"runtime_dir = install_dir / "build" / "bin" / "Release"runtime_dir.mkdir(parents = True)diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.pyindex b492a8d21e1..1787611ca3a 100644--- a/tests/studio/install/test_rocm_support.py+++ b/tests/studio/install/test_rocm_support.py@@ -187,136 +187,83 @@ def _write_dpkg_query_stub(# ── Helper: build HostInfo for different scenarios ──────────────────────────+_LINUX_X64 = dict(+ system = "Linux",+ machine = "x86_64",+ is_windows = False,+ is_linux = True,+ is_macos = False,+ is_x86_64 = True,+ is_arm64 = False,+)+_WINDOWS_X64 = dict(+ system = "Windows",+ machine = "amd64",+ is_windows = True,+ is_linux = False,+ is_macos = False,+ is_x86_64 = True,+ is_arm64 = False,+)+_MACOS_ARM64 = dict(+ system = "Darwin",+ machine = "arm64",+ is_windows = False,+ is_linux = False,+ is_macos = True,+ is_x86_64 = False,+ is_arm64 = True,+)+_NO_GPU = dict(+ nvidia_smi = None,+ driver_cuda_version = None,+ compute_caps = [],+ visible_cuda_devices = None,+ has_physical_nvidia = False,+ has_usable_nvidia = False,+ has_rocm = False,+)+++def _host(platform: dict, gpu: dict, **overrides) -> HostInfo:+ return HostInfo(**{**platform, **_NO_GPU, **gpu, **overrides})++def nvidia_host(**overrides) -> HostInfo:"""NVIDIA Linux x86_64 host."""- defaults = dict(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,+ gpu = dict(nvidia_smi = "/usr/bin/nvidia-smi",driver_cuda_version = (12, 6),compute_caps = ["89"],- visible_cuda_devices = None,has_physical_nvidia = True,has_usable_nvidia = True,- has_rocm = False,)- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_LINUX_X64, gpu, **overrides)def rocm_host(**overrides) -> HostInfo:"""AMD ROCm Linux x86_64 host (no NVIDIA)."""- defaults = dict(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- has_rocm = True,- )- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_LINUX_X64, dict(has_rocm = True), **overrides)def cpu_host(**overrides) -> HostInfo:"""CPU-only Linux x86_64 host."""- defaults = dict(- system = "Linux",- machine = "x86_64",- is_windows = False,- is_linux = True,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- has_rocm = False,- )- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_LINUX_X64, {}, **overrides)def macos_host(**overrides) -> HostInfo:"""macOS arm64 host."""- defaults = dict(- system = "Darwin",- machine = "arm64",- is_windows = False,- is_linux = False,- is_macos = True,- is_x86_64 = False,- is_arm64 = True,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- has_rocm = False,- )- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_MACOS_ARM64, {}, **overrides)def windows_host(**overrides) -> HostInfo:"""Windows x86_64 host."""- defaults = dict(- system = "Windows",- machine = "amd64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- has_rocm = False,- )- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_WINDOWS_X64, {}, **overrides)def windows_rocm_host(**overrides) -> HostInfo:"""Windows x86_64 host with ROCm."""- defaults = dict(- system = "Windows",- machine = "amd64",- is_windows = True,- is_linux = False,- is_macos = False,- is_x86_64 = True,- is_arm64 = False,- nvidia_smi = None,- driver_cuda_version = None,- compute_caps = [],- visible_cuda_devices = None,- has_physical_nvidia = False,- has_usable_nvidia = False,- has_rocm = True,- )- defaults.update(overrides)- return HostInfo(**defaults)+ return _host(_WINDOWS_X64, dict(has_rocm = True), **overrides)# ── Upstream asset fixture ───────────────────────────────────────────────────@@ -829,14 +776,52 @@ class TestDetectRocmVersion:def _named_arch_only():- """_infer_linux_amd_gfx_arch with the product-name half removed.-- The function answers UNSLOTH_ROCM_GFX_ARCH first and infers from the board only after,- and a real AMD host decides that second half. Cases naming an arch still get it; the- rest get None instead of whatever board the runner happens to have."""+ """_infer_linux_amd_gfx_arch with the product-name half removed. It answers+ UNSLOTH_ROCM_GFX_ARCH first and infers from the board only after, which a real AMD+ host would decide. Cases naming an arch still get it; the rest get None instead of+ whatever board the runner happens to have."""return (os.environ.get("UNSLOTH_ROCM_GFX_ARCH") or "").strip().lower() or None+def run_ensure_rocm_torch(+ probe: str = "",+ *,+ env = None,+ isdir = True,+ timeout = False,+ attrs = None,+ **stubs,+):+ """Run _ensure_rocm_torch() against a fully mocked host.++ `stubs` maps a stack_mod probe function to its return value, `attrs` replaces plain+ module attributes (IS_WINDOWS and friends), `probe` is the torch-probe stdout after+ the marker ("" means no marker at all, i.e. CPU torch), and `timeout` makes the probe+ subprocess time out. Returns the (pip_install, pip_install_try) mocks.+ """+ pip = MagicMock()+ pip_try = MagicMock(return_value = True)+ result = MagicMock(returncode = 0, stdout = (_MARK + probe + "\n") if probe else "\n")+ with contextlib.ExitStack() as stack:+ for name, value in {"IS_WINDOWS": False, **(attrs or {})}.items():+ stack.enter_context(patch.object(stack_mod, name, value))+ stack.enter_context(patch.object(stack_mod, "pip_install", pip))+ stack.enter_context(patch.object(stack_mod, "pip_install_try", pip_try))+ for name, value in {"_has_usable_nvidia_gpu": False, **stubs}.items():+ stack.enter_context(patch.object(stack_mod, name, return_value = value))+ if env is not None:+ stack.enter_context(patch.dict(os.environ, env, clear = False))+ stack.enter_context(patch("os.path.isdir", return_value = isdir))+ if timeout:+ stack.enter_context(+ patch("subprocess.run", side_effect = subprocess.TimeoutExpired("python", 30))+ )+ else:+ stack.enter_context(patch("subprocess.run", return_value = result))+ _ensure_rocm_torch()+ return pip, pip_try++class TestEnsureRocmTorch:"""Verify ROCm torch reinstall logic."""@@ -845,13 +830,12 @@ class TestEnsureRocmTorch:"""Describe the host by mocks alone: hide KFD topology and any ambient GPU mask.Both are read by _runtime_gfx_target and neither is covered by the per-case mocks.- KFD sysfs is filtered by nothing, so on a real AMD machine it supplies a GPU no case- asked for; an inherited empty HIP/ROCR/CUDA mask means "no GPU" and suppresses the- very reroute a case asserts. A masked CI job hits both at once. The product-name- inference is the third: on a Strix box /proc/cpuinfo names gfx1151 and the Strix- route then answers before the tag these cases assert, which is what the gfx1151- runner sees. Cases that mean to exercise any of the three set it themselves and win,- since that happens inside this fixture."""+ Unfiltered KFD sysfs supplies a GPU no case asked for on a real AMD machine; an+ inherited empty HIP/ROCR/CUDA mask means "no GPU" and suppresses the very reroute a+ case asserts; and on a Strix box /proc/cpuinfo names gfx1151, so the Strix route+ answers before the tag these cases assert, which is what the gfx1151 runner sees.+ A masked CI job hits several at once. Cases meaning to exercise any of the three set+ it themselves and win, since that happens inside this fixture."""for _mask in ("HIP_VISIBLE_DEVICES", "ROCR_VISIBLE_DEVICES", "CUDA_VISIBLE_DEVICES"):monkeypatch.delenv(_mask, raising = False)with (@@ -860,9 +844,8 @@ class TestEnsureRocmTorch:):yield- # _infer_linux_amd_gfx_arch mocked to None: on a real Strix host the live- # /proc/cpuinfo would otherwise take the inferred-install path and break- # these "must not install" hosts (environment leak, not the code under test).+ # _infer_linux_amd_gfx_arch mocked to None: on a real Strix host live /proc/cpuinfo+ # would take the inferred-install path and break these "must not install" hosts.@patch.object(stack_mod, "pip_install")@patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)@patch.object(stack_mod, "_infer_linux_amd_gfx_arch", return_value = None)@@ -876,133 +859,84 @@ class TestEnsureRocmTorch:_ensure_rocm_torch()mock_pip.assert_not_called()- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = False)- @patch.object(stack_mod, "_infer_linux_amd_gfx_arch", return_value = "gfx1151")- @patch.object(stack_mod, "_detect_rocm_version", return_value = None)- def test_inferred_gfx_without_rocm_runtime_installs_amd_index(- self, mock_ver, mock_infer, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_inferred_gfx_without_rocm_runtime_installs_amd_index(self):"""Strix Halo without /dev/kfd must still get AMD gfx1151 wheels (unslothai#7301)."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+cpu||\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+cpu||",+ _has_rocm_gpu = False,+ _infer_linux_amd_gfx_arch = "gfx1151",+ _detect_rocm_version = None,+ )torch_call = str(mock_pip.call_args_list[0])assert "gfx1151" in torch_callassert "torch>=2.11.0,<2.12.0" in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = False)- @patch.object(stack_mod, "_infer_linux_amd_gfx_arch", return_value = "gfx1151")- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = [])- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_inferred_gfx_not_overwritten_when_rocm_userland_readable(- self, mock_ver, mock_gfx, mock_infer, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_inferred_gfx_not_overwritten_when_rocm_userland_readable(self):"""Codex P1 #7305: after an inferred per-arch install, do not fall through to thegeneric pytorch.org/rocmX.Y reinstall just because has_hip_torch is still False.Readable ROCm userland without /dev/kfd is exactly the case that used to overwritethe AMD gfx wheels."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+cpu||\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+cpu||",+ _has_rocm_gpu = False,+ _infer_linux_amd_gfx_arch = "gfx1151",+ _detect_amd_gfx_codes = [],+ _detect_rocm_version = (7, 1),+ )assert mock_pip.call_count == 1, mock_pip.call_args_listtorch_call = str(mock_pip.call_args_list[0])assert "gfx1151" in torch_callassert "rocm7.1" not in torch_callassert "download.pytorch.org" not in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_infer_linux_amd_gfx_arch", return_value = "gfx1151")- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx1100"])- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_inference_yields_to_runtime_visible_gpu(- self, mock_ver, mock_gfx, mock_infer, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_inference_yields_to_runtime_visible_gpu(self):"""When the runtime CAN enumerate a GPU, the cpuinfo inference must notinstall wheels: a mixed Strix APU + dGPU box with the dGPU selected wouldotherwise get gfx1151 wheels for a gfx1100 GPU. The runtime-visible arch(Strix override / generic branch) decides instead."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+cpu||\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = run_ensure_rocm_torch(+ "2.10.0+cpu||",+ _has_rocm_gpu = True,+ _infer_linux_amd_gfx_arch = "gfx1151",+ _detect_amd_gfx_codes = ["gfx1100"],+ _detect_rocm_version = (7, 1),+ )all_calls = str(mock_pip.call_args_list) + str(mock_pip_try.call_args_list)assert "gfx1151" not in all_calls, all_callsassert "rocm7.1" in all_calls, all_calls- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = [])- @patch.object(stack_mod, "_detect_rocm_version", return_value = None)- def test_gfx_override_installs_despite_visible_rocm(- self, mock_ver, mock_gfx, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_gfx_override_installs_despite_visible_rocm(self):"""#7305 review: an explicit UNSLOTH_ROCM_GFX_ARCH is exempt from thenot-_has_rocm_gpu() gate (mirrors install.sh). A visible GPU with anunreadable ROCm version must not silently discard the user's named archand leave CPU torch in place -- the per-arch install runs."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+cpu||\n"- with patch.dict(os.environ, {"UNSLOTH_ROCM_GFX_ARCH": "gfx1151"}):- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+cpu||",+ env = {"UNSLOTH_ROCM_GFX_ARCH": "gfx1151"},+ _has_rocm_gpu = True,+ _detect_amd_gfx_codes = [],+ _detect_rocm_version = None,+ )assert mock_pip.call_count == 1, mock_pip.call_args_listtorch_call = str(mock_pip.call_args_list[0])assert "gfx1151" in torch_callassert "download.pytorch.org" not in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_cuda_torch_on_amd_host_reinstalls(- self, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_cuda_torch_on_amd_host_reinstalls(self):"""A CUDA-only torch build is unusable on an AMD-only host, so it must bereinstalled to ROCm (has_hip_torch is driven by the empty HIP marker, notby treating the CUDA version string as a HIP marker)."""- mock_probe = MagicMock()- mock_probe.returncode = 0# Single-line probe: empty HIP marker before "|" for a CUDA build.- mock_probe.stdout = _MARK + "2.10.0+cu126||\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+cu126||", _has_rocm_gpu = True, _detect_rocm_version = (7, 1)+ )assert mock_pip.call_count == 1assert "rocm7.1" in str(mock_pip.call_args_list[0])@staticmethoddef _windows_repair(installed_family, gfx = "gfx1200"):- """Run the Windows ROCm repair with an already-ROCm torch on disk.-- Returns the pip_install_try mock so callers can assert on the reinstall.- """+ """Run the Windows ROCm repair with an already-ROCm torch on disk. Returns the+ pip_install_try mock so callers can assert on the reinstall."""probe = MagicMock(returncode = 0, stdout = _MARK + "2.10.0+rocm7.1|7.1|\n")pip_try = MagicMock(return_value = True)with patch.dict(os.environ, {}, clear = False):@@ -1064,9 +998,8 @@ class TestEnsureRocmTorch:assert stack_mod._installed_rocm_wheel_family() == "gfx120x-all"def test_orphaned_runtime_does_not_masquerade_as_the_active_family(self):- # pip never uninstalls the old rocm-sdk-libraries-<family> on a switch (different- # distribution name), so reading the first one found would report the orphan and- # redownload the stack on every update.+ # pip never uninstalls the old rocm-sdk-libraries-<family> on a switch (different dist+ # name), so reading the first one found reports the orphan and redownloads every update.reqs = ['rocm-sdk-libraries-gfx120X-all==7.13.0; extra == "libraries"']dists = self._dists("rocm_sdk_libraries_gfx103X-all", "rocm_sdk_libraries_gfx120X-all")with patch("importlib.metadata.requires", return_value = reqs):@@ -1099,89 +1032,45 @@ class TestEnsureRocmTorch:family = stack_mod._installed_rocm_wheel_family()assert self._windows_repair(family).call_count == 0- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_torch_already_has_hip_skips(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):+ def test_torch_already_has_hip_skips(self):"""If torch already has HIP, should skip ROCm reinstall."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+rocm7.1|7.1.12345|\n" # HIP marker + version- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+rocm7.1|7.1.12345|", # HIP marker + version+ _has_rocm_gpu = True,+ _detect_rocm_version = (7, 1),+ )mock_pip.assert_not_called()- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_cpu_torch_probe_line_not_read_as_hip(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):+ def test_cpu_torch_probe_line_not_read_as_hip(self):"""A CPU build's probe line ("|2.10.0+cpu") must not read as HIP: the versionafter the "|" separator is data, not a HIP marker, so has_hip_torch stays Falseand the reinstall fires."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.10.0+cpu||\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- with patch.object(stack_mod, "pip_install_try", return_value = True):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.10.0+cpu||", _has_rocm_gpu = True, _detect_rocm_version = (7, 1)+ )assert mock_pip.call_count == 1assert "rocm7.1" in str(mock_pip.call_args_list[0])- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_cpu_torch_gets_rocm_reinstall(- self, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_cpu_torch_gets_rocm_reinstall(self):"""CPU-only torch on ROCm host should trigger reinstall."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # empty = no GPU backend- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = run_ensure_rocm_torch(+ _has_rocm_gpu = True, _detect_rocm_version = (7, 1)+ )assert mock_pip.call_count == 1assert "rocm7.1" in str(mock_pip.call_args_list[0])assert mock_pip_try.call_count >= 1assert "bitsandbytes" in str(mock_pip_try.call_args_list[0])assert mock_pip_try.call_args.kwargs["force_pip"] is True- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (6, 3))- def test_rocm_63_selects_correct_tag(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):+ def test_rocm_63_selects_correct_tag(self):"""ROCm 6.3 should select rocm6.3 tag."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(_has_rocm_gpu = True, _detect_rocm_version = (6, 3))torch_call = mock_pip.call_args_list[0]assert "rocm6.3" in str(torch_call)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (5, 0))- def test_old_rocm_skips(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):+ def test_old_rocm_skips(self):"""ROCm version too old (below 6.0) should skip."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(_has_rocm_gpu = True, _detect_rocm_version = (5, 0))mock_pip.assert_not_called()@patch.object(stack_mod, "IS_WINDOWS", False)@@ -1210,39 +1099,20 @@ class TestEnsureRocmTorch:captured = capsys.readouterr()assert "unreadable" in captured.out- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- def test_rocm_72_selects_72_tag(self, mock_ver, mock_gpu, mock_nvidia, mock_pip):+ def test_rocm_72_selects_72_tag(self):"""ROCm 7.2 should select rocm7.2 tag (now in mapping with torch 2.11.0)."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(_has_rocm_gpu = True, _detect_rocm_version = (7, 2))torch_call = mock_pip.call_args_list[0]assert "rocm7.2" in str(torch_call)- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 14))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx1150"])- def test_rocm_714_strix_routes_to_amd_arch_index(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_rocm_714_strix_routes_to_amd_arch_index(self):"""ROCm 7.14 caps to rocm7.2 on pytorch.org; Strix must use AMD gfx index."""- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.11.0+rocm7.2|7.14.60850|\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = run_ensure_rocm_torch(+ "2.11.0+rocm7.2|7.14.60850|",+ _has_rocm_gpu = True,+ _detect_rocm_version = (7, 14),+ _detect_amd_gfx_codes = ["gfx1150"],+ )torch_call = str(mock_pip.call_args_list[0])assert "gfx1150" in torch_callassert "torch>=2.11.0,<2.12.0" in torch_call@@ -1548,9 +1418,8 @@ Agent 4any(str(a).startswith("torch") for a in _c.args) for _c in mock_pip.call_args_list)- # Same reason as test_rocm_pin_family_mismatch_helper: the pin's staleness is judged- # against the installed family first, so an unpinned read makes this assert something- # about the machine running the suite.+ # Same reason as test_rocm_pin_family_mismatch_helper: staleness is judged against the+ # installed family first, so an unpinned read asserts about the machine running the suite.@patch.object(stack_mod, "_installed_rocm_wheel_family", lambda: None)@patch.object(stack_mod, "_torch_requires_rocm_sdk", lambda: False)@patch.object(stack_mod, "IS_WINDOWS", False)@@ -1625,9 +1494,8 @@ Agent 4assert leaf_f("current") is Falseassert leaf_f("cpu") is Falseassert leaf_f("cu128") is False- # A rocm<digit>-SUFFIX private mirror shares the family prefix but is a custom pin- # the verbatim path owns: a ^rocm\d PREFIX match would wrongly treat it as a- # --index-url family. Match EXACTLY.+ # A rocm<digit>-SUFFIX private mirror shares the family prefix but is a custom pin the+ # verbatim path owns: a ^rocm\d PREFIX match would treat it as a family. Match EXACTLY.assert leaf_f("rocm7.2-private") is Falseassert leaf_f("rocm7-current") is Falseassert leaf_f("rocm7.2.1") is False # two-part local suffix -> custom, not rocm7.2@@ -1677,19 +1545,11 @@ Agent 4assert mock_pip.call_count == 1assert "https://mirror.local/cpu" in str(mock_pip.call_args)- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 1))- def test_probe_timeout_triggers_reinstall(- self, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try- ):+ def test_probe_timeout_triggers_reinstall(self):"""Probe subprocess timeout should not crash; should proceed to reinstall."""- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", side_effect = subprocess.TimeoutExpired("python", 30)):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = run_ensure_rocm_torch(+ timeout = True, _has_rocm_gpu = True, _detect_rocm_version = (7, 1)+ )# Probe timeout: treat torch as unusable and reinstall torch + bitsandbytes.assert mock_pip.call_count == 1assert "rocm7.1" in str(mock_pip.call_args_list[0])@@ -1766,6 +1626,16 @@ class TestGfx906LegacyReroute:assert end >= 0, "end of gfx906 case arm not found"return source[start:end]+ @staticmethod+ def _reroute(gfx_codes, *, probe = ""):+ """A ROCm 7.2 AMD host whose runtime reports `gfx_codes`, with CPU torch by default."""+ return run_ensure_rocm_torch(+ probe,+ _has_rocm_gpu = True,+ _detect_rocm_version = (7, 2),+ _detect_amd_gfx_codes = gfx_codes,+ )+def test_gfx906_needs_legacy_index_floor(self):f = stack_mod._gfx906_needs_legacy_index# rocm6.0-6.3 tags still ship gfx906 kernels: no reroute.@@ -1803,26 +1673,10 @@ class TestGfx906LegacyReroute:with patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = []):assert stack_mod._runtime_target_is_gfx906() is True- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx906"])- def test_gfx906_on_rocm72_routes_to_rocm63(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_on_rocm72_routes_to_rocm63(self, monkeypatch):"""CPU torch on a ROCm 7.2 MI50 host installs from rocm6.3, not rocm7.2."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx906"])torch_call = str(mock_pip.call_args_list[0])assert "rocm6.3" in torch_callassert "rocm7.2" not in torch_call@@ -1832,186 +1686,74 @@ class TestGfx906LegacyReroute:# gfx906 has no prebuilt bnb -- the generic wheel must not be installed.assert not any("bitsandbytes" in str(c).lower() for c in mock_pip_try.call_args_list)- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx906"])- def test_gfx906_repairs_existing_rocm72_torch(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_repairs_existing_rocm72_torch(self, monkeypatch):"""An installed +rocm7.2 torch IS the broken combo: reinstall from rocm6.3even though has_hip_torch is True."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.11.0+rocm7.2|7.2.12345|\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx906"], probe = "2.11.0+rocm7.2|7.2.12345|")torch_call = str(mock_pip.call_args_list[0])assert "rocm6.3" in torch_callassert "torch>=2.4,<2.11.0" in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx906"])- def test_gfx906_already_on_rocm63_left_alone(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_already_on_rocm63_left_alone(self, monkeypatch):"""torch already on rocm6.3 wheels must not be reinstalled (no update loop),and the generic bnb wheel must not clobber a source build."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = _MARK + "2.7.0+rocm6.3|6.3.42131|\n"- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx906"], probe = "2.7.0+rocm6.3|6.3.42131|")mock_pip.assert_not_called()# gfx906: prebuilt bnb is skipped entirely (no torch reinstall, no bnb).mock_pip_try.assert_not_called()- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx1100", "gfx906"])- def test_mixed_host_gfx906_not_sole_arch_skips_reroute(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_mixed_host_gfx906_not_sole_arch_skips_reroute(self, monkeypatch):"""Mixed host (gfx906 + dGPU) with no explicit override: gfx906 is not thesole arch, so the generic index is kept (Codex #3: never downgrade ade-dup-ambiguous mixed host)."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = self._reroute(["gfx1100", "gfx906"])torch_call = str(mock_pip.call_args_list[0])assert "rocm7.2" in torch_callassert "rocm6.3" not in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = [])- def test_gfx906_env_override_forces_reroute(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_env_override_forces_reroute(self, monkeypatch):"""UNSLOTH_ROCM_GFX_ARCH=gfx906 reroutes even when probes emit no gfx token(Codex #2: runtime-only ROCm hosts where rocminfo/amd-smi are absent)."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx906")- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, _ = self._reroute([])torch_call = str(mock_pip.call_args_list[0])assert "rocm6.3" in torch_callassert "rocm7.2" not in torch_call- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx906"])- def test_gfx906_bnb_skipped_even_when_index_pinned(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_bnb_skipped_even_when_index_pinned(self, monkeypatch):"""A gfx906 user who pins the ROCm index AND sets the arch override stillskips the generic bnb wheel: the pin suppresses the torch reroute, not thegfx906 runtime flag used for the bnb skip."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx906")monkeypatch.setenv("UNSLOTH_TORCH_INDEX_URL", "https://download.pytorch.org/whl/rocm6.3")- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall from the pinned index- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx906"])# torch is (re)installed from the pinned rocm6.3 index...assert any("rocm6.3" in str(c) for c in mock_pip.call_args_list)# ...but the prebuilt bnb wheel is never installed.assert not any("bitsandbytes" in str(c).lower() for c in mock_pip_try.call_args_list)- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx1151", "gfx906"])- def test_gfx906_override_wins_over_strix_probe(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_override_wins_over_strix_probe(self, monkeypatch):"""Mixed Strix + MI50 host: UNSLOTH_ROCM_GFX_ARCH=gfx906 suppresses the Strixoverride (which probe order would otherwise pick) and routes to rocm6.3."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx906")- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx1151", "gfx906"])torch_call = str(mock_pip.call_args_list[0])assert "rocm6.3" in torch_callassert "gfx1151" not in torch_call# gfx906 target -> generic bnb wheel skipped.assert not any("bitsandbytes" in str(c).lower() for c in mock_pip_try.call_args_list)- @patch.object(stack_mod, "IS_WINDOWS", False)- @patch.object(stack_mod, "pip_install_try", return_value = True)- @patch.object(stack_mod, "pip_install")- @patch.object(stack_mod, "_has_usable_nvidia_gpu", return_value = False)- @patch.object(stack_mod, "_has_rocm_gpu", return_value = True)- @patch.object(stack_mod, "_detect_rocm_version", return_value = (7, 2))- @patch.object(stack_mod, "_detect_amd_gfx_codes", return_value = ["gfx906"])- def test_gfx906_bnb_skipped_on_pinned_index_without_env_override(- self, mock_gfx, mock_ver, mock_gpu, mock_nvidia, mock_pip, mock_pip_try, monkeypatch- ):+ def test_gfx906_bnb_skipped_on_pinned_index_without_env_override(self, monkeypatch):"""Codex #2: a real gfx906 host that pins the ROCm index but does NOT setUNSLOTH_ROCM_GFX_ARCH must still skip the prebuilt bnb wheel -- the pinsuppresses only the torch reroute, not the probe-driven gfx906 detectionused for the bnb skip (otherwise `studio update` clobbers source-built bnb)."""- monkeypatch.delenv("HIP_VISIBLE_DEVICES", raising = False)- monkeypatch.delenv("ROCR_VISIBLE_DEVICES", raising = False)monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)monkeypatch.setenv("UNSLOTH_TORCH_INDEX_URL", "https://download.pytorch.org/whl/rocm6.3")- mock_probe = MagicMock()- mock_probe.returncode = 0- mock_probe.stdout = "\n" # cpu torch -> reinstall from the pinned index- with patch("os.path.isdir", return_value = True):- with patch("subprocess.run", return_value = mock_probe):- _ensure_rocm_torch()+ mock_pip, mock_pip_try = self._reroute(["gfx906"])# torch is (re)installed from the pinned rocm6.3 index...assert any("rocm6.3" in str(c) for c in mock_pip.call_args_list)# ...but the prebuilt bnb wheel is never installed (probe saw sole gfx906).@@ -2361,19 +2103,17 @@ class TestInstallShStructure:assert "amd-smi" in sourcedef test_cpu_index_note_respects_explicit_pin(self):- """An explicit UNSLOTH_TORCH_INDEX_URL/_FAMILY CPU pin is a request, not- a detection failure: the */cpu wheel note must report the pin instead of- claiming ROCm/HIP is unusable, the WSL setup guidance must be skipped,- and the gpu summary must not label a pinned AMD host "no usable ROCm".-- The property is ORDER: the pin arm opens the chain the message sits in, so- a pinned host never reaches the message. This used to be approximated by a- character window before the message, which is a different claim -- it is a- budget on how much source may sit between the two, and every arm added to- the chain eats into it. #8529 added an unsupported-arch arm and pushed the- real distance to ~1121, so the window had to grow 400 -> 1400 for reasons- that had nothing to do with what the test is for. Walk the enclosing- if/elif chains instead: no distance, nothing to re-tune.+ """An explicit UNSLOTH_TORCH_INDEX_URL/_FAMILY CPU pin is a request, not a detection+ failure: the */cpu wheel note must report the pin instead of claiming ROCm/HIP is+ unusable, the WSL setup guidance must be skipped, and the gpu summary must not label+ a pinned AMD host "no usable ROCm".++ The property is ORDER: the pin arm opens the chain the message sits in, so a pinned+ host never reaches it. This used to be approximated by a character window before the+ message, a budget on how much source may sit between the two that every new arm eats+ into. #8529 added an unsupported-arch arm and pushed the real distance to ~1121, so+ the window had to grow 400 -> 1400 for reasons unrelated to what the test is for.+ Walk the enclosing if/elif chains instead: no distance, nothing to re-tune."""sh_path = PACKAGE_ROOT / "install.sh"source = sh_path.read_text(encoding = "utf-8")@@ -2414,25 +2154,22 @@ class TestInstallShStructure:@classmethoddef _assert_guarded_by_pin_arm(cls, source, needle, pinned_note, arm, message):- """Assert ``needle`` sits in the ``arm`` arm of a still-open chain whose- first arm is the pin check and whose pin arm says ``pinned_note``.-- Deliberately local rather than a whole-file walk of if/elif/fi. install.sh- embeds awk programs and PowerShell in quoted blocks, all of which contain- their own `if (...)`, and it closes some chains with a trailing `; fi`; a- global keyword walk mis-nests on both and can end up satisfying this guard- from an unrelated chain. Indentation is the structure install.sh is written- in and needs no parse: find the pin arm above the message, then require the- chain it opens to still be open (nothing closes it before the message) and- to have moved on to another arm (an `elif`/`else` at its indent).-- The pin arm has to be the exact whole line and the arm the message sits in- has to be the exact expected one, or "a chain opened by something that- mentions the pin" is enough to pass: a never-firing `&& [ ... ]` extension- of the condition, or a decoy chain left open across the message with the- real guard deleted, both read as guards otherwise. And a guard that routes- pinned hosts to an empty arm still suppresses the message, so the pin arm- must be checked to carry its own note.+ """Assert ``needle`` sits in the ``arm`` arm of a still-open chain whose first arm+ is the pin check and whose pin arm says ``pinned_note``.++ Deliberately local rather than a whole-file walk of if/elif/fi: install.sh embeds+ awk and PowerShell in quoted blocks that contain their own `if (...)`, and closes+ some chains with a trailing `; fi`, so a global keyword walk mis-nests on both and+ can satisfy this guard from an unrelated chain. Indentation needs no parse: find the+ pin arm above the message, then require the chain it opens to still be open (nothing+ closes it first) and to have moved on to another arm (an `elif`/`else` at its indent).++ The pin arm must be the exact whole line and the arm the message sits in the exact+ expected one, or "a chain opened by something that mentions the pin" is enough to+ pass: a never-firing `&& [ ... ]` extension of the condition, or a decoy chain left+ open across the message with the real guard deleted, both read as guards otherwise.+ And a guard routing pinned hosts to an empty arm still suppresses the message, so+ the pin arm must be checked to carry its own note."""lines = source.splitlines()# Skip comments: a commented-out `substep` is not a message users ever see.@@ -2494,16 +2231,15 @@ class TestInstallShStructure:)def _rocm_version_detection_script(self, source: str, rocm_prefix: str) -> str:- """The version-source helpers plus the resolver and the guarded- assignment that get_torch_index_url makes, as a runnable script.+ """The version-source helpers plus the resolver and the guarded assignment that+ get_torch_index_url makes, as a runnable script.- /opt/rocm is redirected to `rocm_prefix` so the version file is a source- the test controls: a real ROCm host would otherwise answer one of the- probes and make the assertions machine-dependent."""+ /opt/rocm is redirected to `rocm_prefix` so the version file is a source the test+ controls: a real ROCm host would otherwise answer one of the probes and make the+ assertions machine-dependent."""parts = []- # _run_bounded first: _rocm_tag_from_rpm routes its query through it, so- # omitting it makes that source answer nothing and the per-position- # assertions below pass for the wrong reason.+ # _run_bounded first: _rocm_tag_from_rpm routes its query through it, so omitting+ # it makes that source answer nothing and the assertions below pass for a wrong reason.for name in ("_run_bounded",*self._ROCM_VERSION_SOURCES,@@ -2552,11 +2288,10 @@ class TestInstallShStructure:assert "rocm" in source.lower()def test_rocm_version_detection_takes_the_highest_source(self):- """Issue #8402: Debian 13 ships hipconfig 5.7 next to a 6.1 runtime, so- stopping at the first source that answered gated a working gfx1100 out to- CPU wheels. Every source is read and the highest wins. Executed, not- text, and asserted per source position so no single ordering passes by- accident."""+ """Issue #8402: Debian 13 ships hipconfig 5.7 next to a 6.1 runtime, so stopping+ at the first source that answered gated a working gfx1100 out to CPU wheels. Every+ source is read and the highest wins. Executed, not text, and asserted per source+ position so no single ordering passes by accident."""shell = shutil.which("bash")if not shell:pytest.skip("bash needed to execute the version chain")@@ -2643,14 +2378,13 @@ class TestInstallShStructure:assert r.stdout.strip() == "TAG:rocm6.1", r.stdoutdef test_removed_dpkg_rocm_core_cannot_pick_the_wheels(self):- """Highest-wins fixed the undershoot in #8402 and opened the symmetric- hole: a source reading HIGHER than the runtime now wins outright.- Undershoot lands on CPU wheels, which work; overshoot installs wheels the- runtime cannot load. `dpkg-query -W` reports packages left in "deinstall- ok config-files" by `apt remove` without `apt purge`, still carrying the- version they had, so a host that ran ROCm 7.0 and went back to 6.1 hands- dpkg a 7.0 that beats every live source. Only "installed" counts.- Executed, not text, and paired with the installed case so the assertion+ """Highest-wins fixed the undershoot in #8402 and opened the symmetric hole: a+ source reading HIGHER than the runtime now wins outright. Undershoot lands on CPU+ wheels, which work; overshoot installs wheels the runtime cannot load. `dpkg-query+ -W` reports packages left in "deinstall ok config-files" by `apt remove` without+ `apt purge`, still carrying the version they had, so a host that ran ROCm 7.0 and+ went back to 6.1 hands dpkg a 7.0 that beats every live source. Only "installed"+ counts. Executed, not text, and paired with the installed case so the assertioncannot pass on the version alone."""shell = shutil.which("bash")if not shell:@@ -2816,12 +2550,12 @@ class TestInstallShStructure:"""KFD sysfs awk must decide on a single vendor_id line, with no cross-node state.The old awk paired two per-node flags (gpu_id + vendor_id) and needed an FNR==1- reset so flags from different KFD nodes could not combine into a Ryzen+NVIDIA- false positive. gpu_id is a sibling sysfs file and never appears inside- properties, so that pairing also never matched at all (every ROCm-less AMD host- was reported as no-GPU). The replacement keys on one atomic line: only an AMD- GPU node reports `vendor_id 4098` (KFD CPU nodes report 0, NVIDIA's open kernel- module registers 4318), so there is no cross-file state left to reset.+ reset so flags from different KFD nodes could not combine into a Ryzen+NVIDIA false+ positive. gpu_id is a sibling sysfs file and never appears inside properties, so+ that pairing also never matched at all (every ROCm-less AMD host was reported as+ no-GPU). The replacement keys on one atomic line: only an AMD GPU node reports+ `vendor_id 4098` (KFD CPU nodes report 0, NVIDIA's open kernel module registers+ 4318), so no cross-file state is left to reset."""sh_path = PACKAGE_ROOT / "install.sh"source = sh_path.read_text(encoding = "utf-8")@@ -2840,9 +2574,9 @@ class TestInstallShStructure:def test_setup_sh_kfd_awk_matches_install_sh(self):"""setup.sh's KFD fallback must use the same per-line vendor_id check as install.sh.- setup.sh re-probes AMD detection independently of install.sh; if its copy keeps- the dead gpu_id-inside-properties pairing, a host that install.sh routes to ROCm- still gets a CPU llama.cpp from the setup step (_setup_amd_detected stays false).+ setup.sh re-probes AMD detection independently; if its copy keeps the dead+ gpu_id-inside-properties pairing, a host install.sh routes to ROCm still gets a CPU+ llama.cpp from the setup step (_setup_amd_detected stays false)."""source = (PACKAGE_ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")assert (@@ -3101,12 +2835,11 @@ class TestInstallShStructure:), f"an inferred arch with no wheel family must keep the CPU warning: {r3.stderr!r}"def test_no_version_cpu_warning_respects_gfx_override(self):- """With UNSLOTH_ROCM_GFX_ARCH set on a KFD-only host that has no ROCm- version sources, the gfx probe is seeded by the override, so the- no-version endpoint used to print 'falling back to CPU-only PyTorch'- even though the reroute then installs the per-arch wheels (Codex P3).- A supported override must defer; an unsupported override, or a- readable-gfx host without an override, keeps the CPU warning."""+ """With UNSLOTH_ROCM_GFX_ARCH set on a KFD-only host that has no ROCm version+ sources, the gfx probe is seeded by the override, so the no-version endpoint used+ to print 'falling back to CPU-only PyTorch' even though the reroute then installs+ the per-arch wheels (Codex P3). A supported override must defer; an unsupported+ override, or a readable-gfx host without one, keeps the CPU warning."""shell = shutil.which("bash")if not shell:pytest.skip("bash needed to execute get_torch_index_url")@@ -3152,9 +2885,8 @@ class TestInstallShStructure:]with open(os.path.join(d, "uname"), "w", encoding = "utf-8", newline = "\n") as f:f.write('#!/bin/sh\ncase "${1:-}" in -m) echo x86_64 ;; *) echo Linux ;; esac\n')- # Silence every ROCm version source, not just amd-smi: a dev box with- # a real hipconfig/dpkg would otherwise resolve a version and skip- # the no-version endpoint this test exercises.+ # Silence every ROCm version source, not just amd-smi: a dev box with a real+ # hipconfig/dpkg would resolve a version and skip the no-version endpoint under test.with open(os.path.join(d, "amd-smi"), "w", encoding = "utf-8", newline = "\n") as f:f.write("#!/bin/sh\nexit 0\n")for name in ("hipconfig", "dpkg-query", "rpm"):@@ -4493,9 +4225,8 @@ class TestGfxArchNameFallback:assert "setx HIP_VISIBLE_DEVICES 1" in outdef test_wmi_masked_unmappable_adapter_warns_instead_of_substituting(self):- # Under a mask the selected adapter is the user's choice, so another card's arch- # must not stand in (same rule as setup.ps1). That leaves no arch and torch goes- # CPU-only, which has to be said out loud.+ # Under a mask the selected adapter is the user's choice, so another card's arch must+ # not stand in (same rule as setup.ps1). That leaves no arch, so say the CPU outcome.arch, out = self._wmi_arch(["AMD Radeon Graphics", "AMD Radeon RX 9060 XT"], {"HIP_VISIBLE_DEVICES": "0"})@@ -4551,9 +4282,8 @@ class TestGfxArchNameFallback:@pytest.mark.skipif(shutil.which("pwsh") is None, reason = "pwsh not installed")def test_wmi_adapter_filter_is_valid_powershell(self):- # The filter lives in a Python string, so nothing else checks it. Run the real- # expression over stand-ins: a null error code (absent on some drivers) and 0- # stay, anything else goes.+ # The filter lives in a Python string, so nothing else checks it. Run the real expression+ # over stand-ins: a null error code (absent on some drivers) and 0 stay, the rest go.source = _STACK_PATH.read_text(encoding = "utf-8")assert "ConfigManagerErrorCode" in sourcescript = """@@ -4566,10 +4296,9 @@ $adapters = @(($adapters | Where-Object { ($null -eq $_.ConfigManagerErrorCode) -or ($_.ConfigManagerErrorCode -eq 0) }).Name"""- # run_pwsh, not subprocess.run: this asserts the WMI adapter filter is valid- # PowerShell, so an interpreter that died before parsing it would be recorded as- # the filter expression itself being malformed.- # See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh (see tests/_shared/unsloth_pwsh_runner.py), not subprocess.run: this+ # asserts the WMI adapter filter is valid PowerShell, so an interpreter that died+ # before parsing it would be recorded as the filter expression itself being malformed.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", script],check = True,@@ -4716,10 +4445,9 @@ foreach ($v in @('$script:ShadowingIntegratedGfx', '$archFamilyMap')) {merged = {k: v for k, v in os.environ.items() if not k.endswith("_VISIBLE_DEVICES")}merged["SETUP_PS1"] = str(PACKAGE_ROOT / "studio" / "setup.ps1")merged.update(env or {})- # run_pwsh, not subprocess.run: every Resolve-ShadowingGfxPick case goes through- # here, and a crashed interpreter returns no stdout at all, which the callers would- # read as the shadowing pick returning the wrong gfx arch.- # See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh (see tests/_shared/unsloth_pwsh_runner.py), not subprocess.run: every+ # Resolve-ShadowingGfxPick case goes through here, and a crashed interpreter returns+ # no stdout, which callers would read as the pick returning the wrong gfx arch.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", self._HARNESS + body],check = True,@@ -4797,9 +4525,8 @@ foreach ($v in @('$script:ShadowingIntegratedGfx', '$archFamilyMap')) {)merged = {k: v for k, v in os.environ.items() if not k.endswith("_VISIBLE_DEVICES")}merged["SETUP_PS1"] = str(PACKAGE_ROOT / "studio" / "setup.ps1")- # run_pwsh, not subprocess.run: the advisory text is collected from this run's- # stdout, so a pwsh that aborted at startup would look like substep never naming- # the real HIP_VISIBLE_DEVICES index. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh (see tests/_shared/unsloth_pwsh_runner.py), not subprocess.run: the advisory+ # text comes from this run's stdout, so a pwsh killed at startup looks like a lost index.out = run_pwsh(["pwsh", "-NoProfile", "-NonInteractive", "-Command", harness + body],check = True,@@ -5402,11 +5129,9 @@ class TestProgressStepCountMatchesTotal:def test_progress_reaches_total_on_both_core_paths(self, tmp_path, is_windows, is_macos, is_mac_arm, skip_base):- """Both the installer handoff and `studio update`, on every platform.-- The update path on Apple Silicon runs the MLX step, which the earlier- SKIP_STUDIO_BASE=1-only cases never reached, so its slot went uncounted.- """+ """Both the installer handoff and `studio update`, on every platform. The update+ path on Apple Silicon runs the MLX step, which the earlier SKIP_STUDIO_BASE=1-only+ cases never reached, so its slot went uncounted."""step, total = self._run_stack(tmp_path,is_windows = is_windows,@@ -5571,9 +5296,9 @@ class TestRocmTorchPkgSpecs:"""rocm7.1 serves a paired 2.11 trio, so the repair path must not cap at <2.11.install.sh leaves a rocm7.1 leaf on its default trio (torch>=2.4,<2.12.0 /- torchvision>=0.19,<0.27.0 / torchaudio>=2.4,<2.12.0), which resolves- torch 2.11.0+rocm7.1 on that index. Falling back to _default here would- force-reinstall 2.10.0+rocm7.1 over it on the next `studio update`.+ torchvision>=0.19,<0.27.0 / torchaudio>=2.4,<2.12.0), which resolves torch+ 2.11.0+rocm7.1 on that index. Falling back to _default here would force-reinstall+ 2.10.0+rocm7.1 over it on the next `studio update`."""specs = stack_mod._ROCM_TORCH_PKG_SPECS.get("rocm7.1")assert specs is not None, "rocm7.1 must have its own repair spec"@@ -6342,9 +6067,8 @@ class TestStrixRocm71Override:)assert block, "could not extract the gfx-detection block"with tempfile.TemporaryDirectory() as d:- # rocminfo honours ROCR_VISIBLE_DEVICES like the real tool: -1 and- # set-but-empty hide both agents, 1 renumbers to the dGPU only,- # unset shows both.+ # rocminfo honours ROCR_VISIBLE_DEVICES like the real tool: -1 and set-but-empty hide+ # both agents, 1 renumbers to the dGPU only, unset shows both.rocminfo = ("#!/bin/sh\n"'case "${ROCR_VISIBLE_DEVICES-__unset__}" in\n'@@ -6405,10 +6129,9 @@ class TestStrixRocm71Override:def test_torch_constraint_211_matches_leaf_not_whole_url(self):"""The 2.11 constraint case must match the index LEAF, not the whole URL.- A custom UNSLOTH_PYTORCH_MIRROR whose base path contains a gfx/rocm7.2- segment (e.g. https://mirror.local/gfx-cache) with a cu*/cpu family must- not be pushed to the torch 2.11 line -- same leaf-only reasoning the- UNSLOTH_TORCH_BACKEND classification uses.+ A custom UNSLOTH_PYTORCH_MIRROR whose base path contains a gfx/rocm7.2 segment+ (e.g. https://mirror.local/gfx-cache) with a cu*/cpu family must not be pushed to+ the torch 2.11 line -- same leaf-only reasoning UNSLOTH_TORCH_BACKEND uses."""source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")# The 2.11 constraint block must switch on $_torch_index_leaf, not the full@@ -6760,17 +6483,15 @@ class TestApplyHostOverrides:assert out.has_rocm is Truedef test_forwarded_family_label_still_fills_an_unprobed_arch(self, monkeypatch):- # Negative control: with no probed arch the forward is the only source, so it- # applies.+ # Negative control: with no probed arch the forward is the only source, so it applies.monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)out = _apply_host_overrides(cpu_host(), override_rocm_gfx = "gfx110X")assert out.rocm_gfx_target == "gfx110x"assert out.has_rocm is Truedef test_forwarded_gfx_matching_active_keeps_physical_gfx_list(self, monkeypatch):- # When the forward agrees with the probe the per-GPU list must survive: collapsing- # it would hide the host's other AMD cards from the Windows auto-Vulkan floor- # check.+ # When the forward agrees with the probe the per-GPU list must survive: collapsing it+ # would hide the host's other AMD cards from the Windows auto-Vulkan floor check.monkeypatch.delenv("UNSLOTH_ROCM_GFX_ARCH", raising = False)host = rocm_host(rocm_gfx_target = "gfx1010", rocm_gfx_targets = ["gfx1100", "gfx1010"])out = _apply_host_overrides(host, override_rocm_gfx = "gfx1010")@@ -6950,9 +6671,8 @@ class TestRocmGfxForwarding:)assert line is not None, "$HelperReleaseRepo selection not found in setup.ps1"harness = f"{line}\nWrite-Output $HelperReleaseRepo"- # run_pwsh, not subprocess.run: the returncode assertion just below treats a- # non-zero exit as $HelperReleaseRepo failing to resolve, and a signal-killed pwsh- # would be blamed the same way. See tests/_shared/unsloth_pwsh_runner.py.+ # run_pwsh (see tests/_shared/unsloth_pwsh_runner.py), not subprocess.run: the returncode+ # assertion reads a non-zero exit as $HelperReleaseRepo failing, as would a killed pwsh.result = run_pwsh([pwsh, "-NoProfile", "-Command", harness],capture_output = True,@@ -6968,9 +6688,8 @@ class TestRocmGfxForwarding:assert self._resolve_setup_ps1_repo() == "unslothai/llama.cpp"-# TEST: _pick_rocm_gfx_target -- visible-device selection from rocminfo output.-# Honours CUDA/HIP_VISIBLE_DEVICES so a mixed-arch host installs the prebuilt for the-# selected GPU, not GPU 0.+# TEST: _pick_rocm_gfx_target -- visible-device selection from rocminfo output. Honours+# CUDA/HIP_VISIBLE_DEVICES so a mixed-arch host gets the prebuilt for the selected GPU._pick_rocm_gfx_target = prebuilt_mod._pick_rocm_gfx_target@@ -7239,9 +6958,8 @@ class TestRocmWslSupplyChainPins:assert idx_check != -1 and idx_check < idx_cmake < idx_installdef test_install_sh_forwards_the_same_librocdxg_pin_as_the_helper(self):- # install.sh forwards the pin so it also applies to a helper fetched from an older- # commit. The two copies must never disagree, or a bumped helper would be handed a- # stale pin by install.sh and build the wrong revision.+ # install.sh forwards the pin so it also applies to a helper from an older commit. The+ # copies must never disagree, or a bumped helper gets a stale pin and builds a wrong rev.install_sh = _INSTALL_SH_PATH.read_text(encoding = "utf-8")helper = _STRIXHALO_WSL_PATH.read_text(encoding = "utf-8")fwd_ref = re.search(r'_rw_dxg_ref="([0-9a-f]{40})"', install_sh)@@ -7261,9 +6979,8 @@ class TestRocmWslSupplyChainPins:)def test_helper_contract_matches_what_install_sh_requires(self):- # install.sh runs only a helper declaring this contract, so the level it requires and- # the level the helper declares must move together, and the helper must actually- # implement both guarantees the level stands for.+ # install.sh runs only a helper declaring this contract, so the required and declared+ # levels must move together, and the helper must implement both guarantees they mean.install_sh = _INSTALL_SH_PATH.read_text(encoding = "utf-8")helper = _STRIXHALO_WSL_PATH.read_text(encoding = "utf-8")required = re.search(r'grep -q "\^UNSLOTH_ROCM_WSL_HELPER_CONTRACT=(\d+)\$"', install_sh)@@ -7387,10 +7104,10 @@ class TestRocmMiscomputingArchDemotion:def test_a_declared_arch_does_not_outrank_the_silicon(self, monkeypatch):"""UNSLOTH_ROCM_GFX_ARCH is a routing hint, not an answer about the hardware.- A stale gfx1030 on a real Van Gogh, which HSA_OVERRIDE_GFX_VERSION=10.3.0 also spoofs- to, used to be taken first and skip the demotion outright, so a standalone- `studio update` left the miscomputing wheels in place. The probes are asked first now,- and the declared arch only answers when none of them can.+ A stale gfx1030 on a real Van Gogh, which HSA_OVERRIDE_GFX_VERSION=10.3.0 also+ spoofs to, used to be taken first and skip the demotion outright, so a standalone+ `studio update` left the miscomputing wheels in place. The probes are asked first+ now, and the declared arch only answers when none of them can."""calls = self._demotion_calls(monkeypatch,@@ -7498,8 +7215,7 @@ class TestRocmMiscomputingArchDemotion:from _infer_linux_amd_gfx_arch() and so believed the override, force-installed themulti-GB gfx103X-all stack, and set _inferred_arch_installed, which skips theruntime-target check below it. _ensure_cpu_torch() then saw the real gfx1033 and- force-reinstalled CPU torch, so every `studio update` paid for both installs instead- of settling.+ force-reinstalled CPU torch, so every `studio update` paid for both installs."""calls = []monkeypatch.setattr(stack_mod, "IS_WINDOWS", False)diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex 78108b32095..099ef2f19ee 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -63,16 +63,13 @@ 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.+ # Module-level dedupe: without this reset a test's verdict depends on which earlier test logged the reason.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.- # test_download_host_resolve.py covers the fast path itself.+ # Mocked releases only, so keep the real-CDN download-host fast path out; test_download_host_resolve.py covers it.monkeypatch.setenv("UNSLOTH_LLAMA_DISABLE_DOWNLOAD_HOST_RESOLVE", "1")@@ -84,9 +81,8 @@ def load_studio_run_module(monkeypatch):)loggers = types.ModuleType("loggers")loggers.get_logger = lambda name: logger- # run.py imports this at module scope, so the stub has to carry it or the import- # of run fails before any test body runs. A no-op is right here: the filter only- # de-duplicates uvicorn's copy of a traceback, and this module never starts a server.+ # run.py imports this at module scope, so the stub must carry it or importing run fails before any test runs.+ # A no-op is right: the filter only de-duplicates uvicorn's copy of a traceback, and no server starts here.loggers.install_uvicorn_duplicate_exception_filter = lambda: Nonemonkeypatch.setitem(sys.modules, "loggers", loggers)@@ -114,6 +110,19 @@ def load_studio_run_module(monkeypatch):return module+def mock_resolved_releases(monkeypatch, releases):+ monkeypatch.setattr(+ INSTALL_LLAMA_PREBUILT,+ "iter_resolved_published_releases",+ lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(releases),+ )+++def mock_published_releases(monkeypatch, release, checksums):+ resolved = INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(bundle = release, checksums = checksums)+ mock_resolved_releases(monkeypatch, [resolved])++def make_host(**overrides):system = overrides.pop("system", "Linux")machine = overrides.pop("machine", "x86_64")@@ -152,6 +161,19 @@ def make_artifact(asset_name, **overrides):return PublishedLlamaArtifact(**defaults)+def make_cpu_artifact(asset_name, **overrides):+ """An artifact with no CUDA runtime: no runtime line, no SM coverage, no profile."""+ nulls = dict(+ runtime_line = None,+ coverage_class = None,+ supported_sms = [],+ min_sm = None,+ max_sm = None,+ bundle_profile = None,+ )+ return make_artifact(asset_name, **{**nulls, **overrides})++def make_release(artifacts, **overrides):defaults = dict(repo = "unslothai/llama.cpp",@@ -440,8 +462,7 @@ class TestStudioLocalhostIpv6Warning:run_module._emit_startup_output("127.0.0.1", 8888, "127.0.0.1")- # The stop hint no longer rides inside the banner: it is printed once at the- # end so it stays the final line after the tool-policy notice.+ # Printed once at the end, not inside the banner, so it stays the final line after the tool-policy notice.assert calls["banner"][0]["include_stop_hint"] is Falseassert calls["warning"] == []assert calls["stop_hint"] == 1@@ -462,10 +483,8 @@ class TestStudioLocalhostIpv6Warning:# ===========================================================================-# A-F, H. Component-independent GPU/token helpers: the behavior tables live in-# tests/studio/install/test_prebuilt_core.py (they are pure prebuilt_core-# functions). This pin proves the installer still re-exports them from core, so-# the master tables keep covering the names this module and its callers use.+# A-F, H. Component-independent GPU/token helpers. Their behaviour tables live in test_prebuilt_core.py (pure+# prebuilt_core functions); this pin proves the installer still re-exports them, so those tables stay in force.# ===========================================================================@@ -1077,8 +1096,7 @@ 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.bundle = make_release([], release_tag = "r1", upstream_tag = "b8508")checksums = make_checksums_with_source([], release_tag = "r1", upstream_tag = "b8508", source_commit = "a" * 40@@ -1093,8 +1111,7 @@ 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, so validation must accept it.bundle = make_release([],release_tag = "r1",@@ -1267,7 +1284,6 @@ class TestLinuxCudaChoiceFromRelease:assert result.primary.runtime_line == "cuda12"def test_non_blackwell_keeps_torch_preference(self, monkeypatch):- # Non-Blackwell: torch preference untouched, no override.mock_linux_runtime(monkeypatch, ["cuda13", "cuda12"])host = make_host(driver_cuda_version = (13, 0), compute_caps = ["86"])art12 = make_artifact(@@ -1314,9 +1330,8 @@ 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 cu130) gets no+ # bundle and GGUF inference silently moves to CPU. The selection log only prints when an attempt survives.mock_linux_runtime(monkeypatch, ["cuda13"])host = make_host(driver_cuda_version = (13, 0), compute_caps = ["70"])art12 = make_artifact(@@ -1332,8 +1347,7 @@ 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.+ # A pin, not a promise about a re-run: these caps are the masked view; 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.@@ -1343,8 +1357,7 @@ 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 exactly what cu126 exists for, and the cuda12 portable bundle covers both.mock_linux_runtime(monkeypatch, ["cuda13"])host = make_host(driver_cuda_version = (13, 0), compute_caps = ["70", "86"])release = make_release(@@ -1451,7 +1464,6 @@ class TestLinuxCudaChoiceFromRelease:assert result.primary.runtime_line == "cuda14"def test_arm64_host_selects_linux_arm64_cuda_kind(self, monkeypatch):- # arm64 CUDA host selects the linux-arm64-cuda bundle, not the x64 one.mock_linux_runtime(monkeypatch, ["cuda13"])host = make_host(machine = "aarch64",@@ -1705,18 +1717,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -1750,18 +1751,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -1799,9 +1789,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- # reaching for an upstream asset.+ # CPU-only Linux routes to the fork. If a release manifest ships no CPU bundle the resolver raises rather+ # than quietly reaching for the ggml-org upstream asset.host = make_host(has_usable_nvidia = False,has_physical_nvidia = False,@@ -1814,18 +1803,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -1846,18 +1824,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)mock_linux_runtime(monkeypatch, ["cuda12"])with pytest.raises(PrebuiltFallback, match = "no compatible Linux prebuilt asset was found"):@@ -1873,18 +1840,7 @@ class TestResolveInstallAttempts:)asset_name = "llama-b9000-bin-win-cpu-x64.zip"release = make_release(- [- make_artifact(- asset_name,- install_kind = "windows-cpu",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,- bundle_profile = None,- )- ],+ [make_cpu_artifact(asset_name, install_kind = "windows-cpu", bundle_profile = None)],release_tag = "llama-prebuilt-latest",upstream_tag = "b9000",assets = {asset_name: f"https://published.example/{asset_name}"},@@ -1895,18 +1851,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -1963,14 +1908,9 @@ class TestResolveInstallAttempts:)release = make_release([- make_artifact(+ make_cpu_artifact(asset_name,install_kind = install_kind,- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = bundle_profile,rank = 1000,)@@ -1985,18 +1925,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9625",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -2018,10 +1947,8 @@ class TestResolveInstallAttempts:assert attempts[0].source_label == "published"def test_cpu_only_unsupported_arch_source_builds(self, monkeypatch):- # A CPU-only Linux host that is neither x86_64 nor arm64 (ppc64le,- # riscv64, s390x) has no compatible CPU bundle. It must source-build, not- # receive the x86_64 linux-cpu binary (the Linux preflight checks libs,- # not ELF arch, so a wrong-arch binary would slip through).+ # A CPU-only Linux host that is neither x86_64 nor arm64 (ppc64le, riscv64, s390x) has no compatible bundle+ # and must source-build: the Linux preflight checks libs, not ELF arch, so an x86_64 binary would slip through.host = make_host(machine = "ppc64le",has_usable_nvidia = False,@@ -2032,14 +1959,9 @@ class TestResolveInstallAttempts:x64_asset = "app-b9625-linux-x64-cpu.tar.gz"release = make_release([- make_artifact(+ make_cpu_artifact(x64_asset,install_kind = "linux-cpu",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = "linux-cpu-x64",rank = 1000,)@@ -2054,18 +1976,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9625",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)with pytest.raises(PrebuiltFallback, match = "no compatible Linux prebuilt asset was found"):resolve_install_attempts("latest", host, "unslothai/llama.cpp", "")@@ -2082,18 +1993,7 @@ class TestResolveInstallAttempts:)asset_name = "llama-b9000-bin-macos-arm64.tar.gz"release = make_release(- [- make_artifact(- asset_name,- install_kind = "macos-arm64",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,- bundle_profile = None,- )- ],+ [make_cpu_artifact(asset_name, install_kind = "macos-arm64", bundle_profile = None)],release_tag = "llama-prebuilt-latest",upstream_tag = "b9000",assets = {asset_name: f"https://published.example/{asset_name}"},@@ -2104,18 +2004,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -2146,14 +2035,9 @@ class TestResolveInstallAttempts:published_name = "llama-b9000-bin-win-cpu-x64.zip"release = make_release([- make_artifact(+ make_cpu_artifact(published_name,install_kind = "windows-cpu",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = None,)],@@ -2167,18 +2051,7 @@ class TestResolveInstallAttempts:upstream_tag = "b9000",)- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- [- INSTALL_LLAMA_PREBUILT.ResolvedPublishedRelease(- bundle = release,- checksums = checksums,- )- ]- ),- )+ mock_published_releases(monkeypatch, release, checksums)monkeypatch.setattr(INSTALL_LLAMA_PREBUILT,"github_release_assets",@@ -2201,8 +2074,7 @@ 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.art = make_artifact(asset_name,install_kind = "linux-cuda",@@ -2230,13 +2102,7 @@ class TestResolveInstallReleasePlans:self._cuda_bundle("app-b9001-linux-x64-cuda12.tar.gz", "r1", "b9001"),]- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- releases- ),- )+ mock_resolved_releases(monkeypatch, releases)requested_tag, plans = _fork_manifest_release_plans("latest",@@ -2266,13 +2132,7 @@ class TestResolveInstallReleasePlans:self._cuda_bundle("app-b9001-linux-x64-cuda12.tar.gz", "r1", "b9001"),]- monkeypatch.setattr(- INSTALL_LLAMA_PREBUILT,- "iter_resolved_published_releases",- lambda requested_tag, published_repo, published_release_tag = "", **_kwargs: iter(- releases- ),- )+ mock_resolved_releases(monkeypatch, releases)_requested_tag, plans = _fork_manifest_release_plans("latest",@@ -2344,8 +2204,7 @@ 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 cannot run a 13.1 build (forward minor): gated to cuda12 even if only cuda13 libs are seen.mock_windows_runtime(monkeypatch, ["cuda13"])host = make_host(system = "Windows", machine = "AMD64", driver_cuda_version = (13, 0))assets = self._upstream("13.1", "12.4")@@ -2638,8 +2497,7 @@ 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 on Blackwell and the b9360 pin is gone, so this falls to windows-cpu.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).@@ -2696,8 +2554,7 @@ 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 with sm_120, so manifest SM metadata keeps them on Blackwell.bundle = AssetChoice(repo = "unslothai/llama.cpp",tag = "b9585",@@ -2766,14 +2623,9 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:def _cpu_only_bundle(self):return make_release([- make_artifact(+ make_cpu_artifact("app-b8508-linux-x64-cpu.tar.gz",install_kind = "linux-cpu",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = None,rank = 1000,),@@ -2807,29 +2659,18 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:assert [a.install_kind for a in attempts] == ["linux-cpu"]def _vulkan_and_cpu_bundle(self):- """What unslothai/llama.cpp actually publishes: both an x64 Vulkan bundle and- an x64 CPU one (app-<tag>-linux-x64-vulkan.tar.gz / -cpu.tar.gz)."""+ """What unslothai/llama.cpp publishes: app-<tag>-linux-x64-vulkan.tar.gz and -cpu.tar.gz."""return make_release([- make_artifact(+ make_cpu_artifact("app-b8508-linux-x64-vulkan.tar.gz",install_kind = "linux-vulkan",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = "linux-vulkan-x64",rank = 500,),- make_artifact(+ make_cpu_artifact("app-b8508-linux-x64-cpu.tar.gz",install_kind = "linux-cpu",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = None,rank = 1000,),@@ -2849,20 +2690,17 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:return make_host(**base)def test_amd_without_rocm_gets_the_published_vulkan_bundle(self):- """The regression this guards: an AMD host with no usable ROCm silently took the- CPU bundle.+ """Regression: an AMD host with no usable ROCm silently took the CPU bundle.- The Vulkan preference was stated in direct_upstream_release_plan and in- resolve_upstream_asset_choice, but NOT here, and this is the branch that runs whenever a- published bundle exists. So a Steam Deck installed the CPU llama.cpp while both upstream- paths said Vulkan, reachable only by setting UNSLOTH_LLAMA_CPP_BACKEND by hand.+ The Vulkan preference was stated in direct_upstream_release_plan and resolve_upstream_asset_choice but NOT+ here, the branch that runs whenever a published bundle exists, so a Steam Deck installed the CPU llama.cpp+ and only setting UNSLOTH_LLAMA_CPP_BACKEND by hand could fix it."""host = self._gpu_host(has_amd_gpu_without_rocm = True)attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(host, self._vulkan_and_cpu_bundle())- # Vulkan first, CPU kept behind it: if the Vulkan bundle fails validation the- # host still gets a working engine rather than nothing.+ # Vulkan first, CPU behind it: if the Vulkan bundle fails validation the host still gets a working engine.assert [a.install_kind for a in attempts] == ["linux-vulkan", "linux-cpu"]def test_intel_routing_is_unchanged(self):@@ -2880,9 +2718,8 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:assert [a.install_kind for a in attempts] == ["linux-cpu"]def test_amd_next_to_a_physical_nvidia_does_not_reach_vulkan(self):- """Vulkan ignores CUDA_VISIBLE_DEVICES, so a hidden NVIDIA card must not be- enumerated through it -- the same reason the other two paths test physical- rather than usable NVIDIA."""+ """Vulkan ignores CUDA_VISIBLE_DEVICES, so a hidden NVIDIA card must not be enumerated through it --+ the same reason the other two paths test physical rather than usable NVIDIA."""host = self._gpu_host(has_amd_gpu_without_rocm = True, has_physical_nvidia = True)attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(host, self._vulkan_and_cpu_bundle()@@ -2920,8 +2757,7 @@ class TestPublishedWindowsCudaAttemptsDynamicMajor:return make_release(artifacts, upstream_tag = self.TAG)def test_future_cuda14_published_is_selected(self, monkeypatch):- # The dynamic seed lets a 14.x driver reach a published cuda14 build; the old- # hardcoded cuda12/cuda13 seed would never order it.+ # The dynamic seed lets a 14.x driver reach a published cuda14 build; the old cuda12/cuda13 seed could not.mock_windows_runtime(monkeypatch, ["cuda14", "cuda13", "cuda12"])release = self._release([("14.0", "cuda14"), ("13.3", "cuda13"), ("12.4", "cuda12")])host = make_host(@@ -3010,9 +2846,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- # walk-back deterministically finds no usable CUDA build -> PrebuiltFallback.+ # Once the Blackwell filter drops every published attempt the resolver walks back upstream; stub that fetch+ # to stay offline (the scanner blocks live GitHub) so it deterministically finds no CUDA build -> fallback.monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "github_release_assets", lambda repo, tag: {})release = self._release([("13.3", "cuda13"), ("12.4", "cuda12")])checksums = self._checksums(["12.4"]) # 13.3 gated off for a 13.1 driver@@ -3022,9 +2857,8 @@ 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 the b9360 pin is gone, so no+ # 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)@@ -3109,8 +2943,7 @@ 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 cuda13 line on a 13.0 driver; gating is at major now.mock_windows_runtime(monkeypatch, ["cuda13", "cuda12"])release = make_release([self._line("cuda12", "newer", 20), self._line("cuda13", "newer", 50)],@@ -3128,9 +2961,8 @@ 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 falls back to the driver-derived order instead of the upstream build.mock_windows_runtime(monkeypatch, [])release = make_release([self._line("cuda12", "newer", 20), self._line("cuda13", "newer", 50)],@@ -3161,14 +2993,9 @@ class TestPublishedRocmGfxSelection:def _release(self, install_kind, prefix):artifacts = [- make_artifact(+ make_cpu_artifact(f"{prefix}-{gfx}.{'zip' if 'windows' in install_kind else 'tar.gz'}",install_kind = install_kind,- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = None,rank = 1000,gfx_target = gfx,@@ -3224,8 +3051,7 @@ 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 is in no bundle's mapped_targets, so it falls back to source.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")for unbuilt in ("gfx1033", "gfx1035", "gfx1104", "gfx1202"):assert (@@ -3247,9 +3073,8 @@ 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), so selection matches on gfx_target rather than the+ # mapped list. It must still record concrete archs: this is the one path where the matched token is not one.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")for token in ("gfx110X", "gfx110x"):choice = INSTALL_LLAMA_PREBUILT.published_rocm_choice_for_host(@@ -3260,8 +3085,7 @@ class TestPublishedRocmGfxSelection:assert token.lower() not in [t.lower() for t in choice.mapped_targets], tokendef test_family_token_matches_family_bundle(self):- # The update path forwards a family token (gfx110X, lowercased to gfx110x), not- # a concrete arch; it must still select the family bundle, not source-build.+ # The update path forwards a family token (gfx110X, lowercased gfx110x); it must still hit the family bundle.release = self._release("linux-rocm", "app-b9457-linux-x64-rocm")for token in ("gfx110X", "gfx110x"):choice = INSTALL_LLAMA_PREBUILT.published_rocm_choice_for_host(@@ -3271,8 +3095,7 @@ 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 match covers windows-rocm.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"@@ -3282,10 +3105,8 @@ class TestPublishedRocmGfxSelection:class TestPublishedRocmBundleCoverage:- """Every arch the installer routes torch for should also have a llama.cpp- bundle, or be recorded here as a known gap. Routing an arch for torch while- no bundle covers it is silent: the GPU works for training and drops to a HIP- source build for inference, which is correct but much slower to install."""+ """Every arch the installer routes torch for needs a llama.cpp bundle or a KNOWN_GAPS entry. The gap is silent:+ the GPU trains fine and inference drops to a HIP source build, which is correct but much slower to install."""# mapped_targets of each published ROCm bundle, mirroring unslothai/llama.cpp's llama-prebuilt-manifest.json.PUBLISHED = {@@ -3300,24 +3121,17 @@ class TestPublishedRocmBundleCoverage:# Arches _GFX_TO_AMD_INDEX_ARCH routes torch for that no bundle covers.# gfx1033/1035/1036: RDNA 2 variants, never built.- # gfx1152: Krackan Point (Radeon 860M/840M). Torch goes to its own- # repo.amd.com/rocm/whl/gfx1152 leaf, but no llama.cpp bundle exists, so- # these hosts source-build. Publish a -gfx1152 bundle, or add gfx1152 to- # the gfx1150 bundle's mapped_targets if that build genuinely covers it,- # then drop it from this set.+ # gfx1152: Krackan Point (Radeon 860M/840M). Torch has its own repo.amd.com/rocm/whl/gfx1152 leaf but no+ # llama.cpp bundle, so these hosts source-build. To close it: publish a -gfx1152 bundle, or add gfx1152+ # to the gfx1150 bundle's mapped_targets if that build covers it, then drop it here.KNOWN_GAPS = {"gfx1033", "gfx1035", "gfx1036", "gfx1152"}def _release(self):return make_release([- make_artifact(+ make_cpu_artifact(f"app-b9457-linux-x64-rocm-{fam}.tar.gz",install_kind = "linux-rocm",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = None,rank = 1000,gfx_target = fam,@@ -3341,9 +3155,8 @@ class TestPublishedRocmBundleCoverage:)def test_known_gaps_fall_back_to_source_build(self):- """A gap arch must return None rather than be served a sibling bundle:- a wrong-ISA binary fails at the first BLAS call instead of installing- slowly, which is the worse of the two outcomes."""+ """A gap arch must return None rather than a sibling bundle: a wrong-ISA binary fails at the first BLAS+ call instead of merely installing slowly, which is the worse outcome."""release = self._release()for gfx in sorted(self.KNOWN_GAPS):assert (@@ -3354,13 +3167,11 @@ class TestPublishedRocmBundleCoverage:), f"{gfx} is in KNOWN_GAPS but a bundle now matches it; drop it from the set"def test_every_torch_routed_arch_is_covered_or_a_known_gap(self):- """The guard that would have caught gfx1152: adding an arch to- _GFX_TO_AMD_INDEX_ARCH without a bundle must be a deliberate entry in- KNOWN_GAPS, not an unnoticed drop to source builds."""+ """The guard that would have caught gfx1152: an arch in _GFX_TO_AMD_INDEX_ARCH with no bundle must be a+ deliberate KNOWN_GAPS entry, 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; importing the installer pulls 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"@@ -3379,25 +3190,15 @@ class TestPublishedMacosForkSelection:def _release(self):arts = [- make_artifact(+ make_cpu_artifact("llama-b9457-bin-macos-arm64.tar.gz",install_kind = "macos-arm64",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = "macos-metal-arm64",rank = 50,),- make_artifact(+ make_cpu_artifact("llama-b9457-bin-macos-x64.tar.gz",install_kind = "macos-x64",- runtime_line = None,- coverage_class = None,- supported_sms = [],- min_sm = None,- max_sm = None,bundle_profile = "macos-cpu-x64",rank = 50,),@@ -3796,8 +3597,7 @@ 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 use the manifest resolver, not filename parsing.called = {}def _full(llama_tag, host, repo, tag, **_kw):@@ -3960,6 +3760,33 @@ class TestCudaDriverToolkitMismatchMessage:)return proc.stdout + proc.stderr+ def _run_cuda_script(+ self,+ body,+ path_dir = None,+ *,+ only_path_dir = False,+ ):+ """Run `body` under setup.sh's CUDA driver/toolkit helpers, with the usual preamble.++ `only_path_dir` drops the inherited PATH, which is the only way a case that means+ "no nvidia-smi anywhere" stays honest on a machine that has one in /usr/bin.+ """+ script = textwrap.dedent(+ f"""\+ set -euo pipefail+ C_WARN=+ substep() {{ printf '%s\\n' "$1"; }}+ {self._setup_sh_cuda_helper_fragment()}+ {textwrap.dedent(body)}+ """+ )+ env = None+ if path_dir is not None:+ inherited = "" if only_path_dir else f":{os.environ.get('PATH', '')}"+ env = {"PATH": f"{path_dir}{inherited}"}+ return self._run_bash(script, env = env)+def _fake_nvidia_smi(self, tmp_path, output):mock_bin = tmp_path / "bin"mock_bin.mkdir()@@ -3983,12 +3810,7 @@ class TestCudaDriverToolkitMismatchMessage:tmp_path,"| NVIDIA-SMI 580.95 Driver Version: 580.95 CUDA Version: 13.1 |",)- script = textwrap.dedent(- f"""\- set -euo pipefail- C_WARN=- substep() {{ printf '%s\\n' "$1"; }}- {self._setup_sh_cuda_helper_fragment()}+ body = """\_driver="$(_cuda_driver_max_version)"if _cuda_toolkit_major_gt_driver "13.3" "$_driver"; then_print_cuda_driver_toolkit_mismatch "13.3" "$_driver"@@ -3996,11 +3818,7 @@ class TestCudaDriverToolkitMismatchMessage:printf 'compatible:%s\\n' "$_driver"fi"""- )- output = self._run_bash(- script,- env = {"PATH": f"{mock_bin}:{os.environ.get('PATH', '')}"},- )+ output = self._run_cuda_script(body, mock_bin)assert "compatible:13.1" in outputassert "major-version mismatch" not in output@@ -4009,22 +3827,13 @@ class TestCudaDriverToolkitMismatchMessage:tmp_path,"| NVIDIA-SMI 570.95 Driver Version: 570.95 CUDA Version: 12.9 |",)- script = textwrap.dedent(- f"""\- set -euo pipefail- C_WARN=- substep() {{ printf '%s\\n' "$1"; }}- {self._setup_sh_cuda_helper_fragment()}+ body = """\_driver="$(_cuda_driver_max_version)"if _cuda_toolkit_major_gt_driver "13.3" "$_driver"; then_print_cuda_driver_toolkit_mismatch "13.3" "$_driver"fi"""- )- output = self._run_bash(- script,- env = {"PATH": f"{mock_bin}:{os.environ.get('PATH', '')}"},- )+ output = self._run_cuda_script(body, mock_bin)assert ("CUDA Toolkit 13.3 is a major-version mismatch: toolkit major 13 ""exceeds driver CUDA major 12 (12.9)."@@ -4040,12 +3849,7 @@ class TestCudaDriverToolkitMismatchMessage:tmp_path,"| NVIDIA-SMI 580.95 Driver Version: 580.95 CUDA Version: 13.3 |",)- script = textwrap.dedent(- f"""\- set -euo pipefail- C_WARN=- substep() {{ printf '%s\\n' "$1"; }}- {self._setup_sh_cuda_helper_fragment()}+ body = """\_driver="$(_cuda_driver_max_version)"if _cuda_toolkit_major_gt_driver "13.3" "$_driver"; then_print_cuda_driver_toolkit_mismatch "13.3" "$_driver"@@ -4053,23 +3857,14 @@ class TestCudaDriverToolkitMismatchMessage:printf 'compatible:%s\\n' "$_driver"fi"""- )- output = self._run_bash(- script,- env = {"PATH": f"{mock_bin}:{os.environ.get('PATH', '')}"},- )+ output = self._run_cuda_script(body, mock_bin)assert "compatible:13.3" in outputassert "Unsloth supports CUDA Toolkit" not in outputdef test_setup_sh_skips_check_without_nvidia_smi(self, tmp_path):empty_bin = tmp_path / "empty-bin"empty_bin.mkdir()- script = textwrap.dedent(- f"""\- set -euo pipefail- C_WARN=- substep() {{ printf '%s\\n' "$1"; }}- {self._setup_sh_cuda_helper_fragment()}+ body = """\_driver="$(_cuda_driver_max_version)"if [ -n "$_driver" ] && _cuda_toolkit_major_gt_driver "13.3" "$_driver"; then_print_cuda_driver_toolkit_mismatch "13.3" "$_driver"@@ -4077,8 +3872,7 @@ class TestCudaDriverToolkitMismatchMessage:printf 'skipped\\n'fi"""- )- output = self._run_bash(script, env = {"PATH": str(empty_bin)})+ output = self._run_cuda_script(body, empty_bin, only_path_dir = True)assert "skipped" in outputassert "Unsloth supports CUDA Toolkit" not in output@@ -4237,12 +4031,7 @@ class TestCudaDriverToolkitMismatchMessage:tmp_path,"| NVIDIA-SMI 580.95 Driver Version: 580.95 CUDA Version: 13.0 |",)- script = textwrap.dedent(- f"""\- set -euo pipefail- C_WARN=- substep() {{ printf '%s\\n' "$1"; }}- {self._setup_sh_cuda_helper_fragment()}+ body = """\_nvcc=""_driver="$(_cuda_driver_max_version)"if [ -n "$_nvcc" ] && [ -n "$_driver" ] && _cuda_toolkit_major_gt_driver "$_nvcc" "$_driver"; then@@ -4251,11 +4040,7 @@ class TestCudaDriverToolkitMismatchMessage:printf 'skipped\\n'fi"""- )- output = self._run_bash(- script,- env = {"PATH": f"{mock_bin}:{os.environ.get('PATH', '')}"},- )+ output = self._run_cuda_script(body, mock_bin)assert "skipped" in outputassert "Unsloth supports CUDA Toolkit" not in output@@ -4369,13 +4154,12 @@ class TestCudaDriverToolkitMismatchMessage:class TestExactSourceAssetUrl:- """exact_source_asset_url resolves the published source-commit release asset- for mix builds even when the manifest omits the top-level repo/release_tag.+ """exact_source_asset_url resolves the published source-commit asset for mix builds even when the manifest+ omits the top-level repo/release_tag.- A mix build's merge commit is never pushed, so its codeload/archive URLs- 404; the ``llama.cpp-source-commit-<sha>.tar.gz`` asset is the only durable- copy. If the asset URL resolves empty, hydration falls through to the 404-ing- commit archive and the whole prebuilt install fails to a source build.+ A mix build's merge commit is never pushed, so its codeload/archive URLs 404 and+ ``llama.cpp-source-commit-<sha>.tar.gz`` is the only durable copy. An empty asset URL sends hydration to the+ 404-ing commit archive and the whole prebuilt install falls to a source build."""COMMIT = "c4fca6de" + "a" * 32 # 40-char sha@@ -4414,8 +4198,7 @@ class TestExactSourceAssetUrl:assert url == self._expected("unslothai/llama.cpp", self.INSTALL_TAG)def test_falls_back_to_install_tag_when_manifest_tag_missing(self):- # Regression: an empty manifest release_tag must not drop the asset URL.- # Before the fix this returned None and hydration 404'd on the merge commit.+ # Regression: an empty manifest release_tag returned None, and hydration then 404'd on the merge commit.checksums = self._checksums(repo = "unslothai/llama.cpp", release_tag = "")url = INSTALL_LLAMA_PREBUILT.exact_source_asset_url(checksums, "unslothai/llama.cpp", self._artifact(repo = None), True, self.INSTALL_TAG@@ -4459,9 +4242,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- # parser/selection wiring can't pass while only the helper unit tests stay green.+ # The cases above hand-build ApprovedReleaseChecksums; this walks the production path they bypass+ # (parse_approved_release_checksums -> preferred_source_archive -> exact_source_asset_url).payload = {"schema_version": 1,"component": "llama.cpp",