Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio tests: use a portable fake llama-server in the load cancel tests (#15826)
Daniel Han8821c405ab3f
diff --git a/studio/backend/tests/_fake_llama_server.py b/studio/backend/tests/_fake_llama_server.pynew file mode 100644index 00000000000..9cfba3c8e6e--- /dev/null+++ b/studio/backend/tests/_fake_llama_server.py@@ -0,0 +1,21 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""A stand-in llama-server that exits 0 at once on every OS (Windows has no /usr/bin/true)."""++from __future__ import annotations++import sys+from pathlib import Path+++def fake_llama_server(directory: Path) -> str:+ directory.mkdir(parents = True, exist_ok = True)+ if sys.platform == "win32":+ fake = directory / "llama-server.cmd"+ fake.write_text("@exit /b 0\r\n", encoding = "utf-8")+ else:+ fake = directory / "llama-server"+ fake.write_text("#!/bin/sh\nexit 0\n", encoding = "utf-8")+ fake.chmod(0o755)+ return str(fake)diff --git a/studio/backend/tests/test_gguf_load_cache_reuse.py b/studio/backend/tests/test_gguf_load_cache_reuse.pyindex 7edac5b0d11..b3e576121ff 100644--- a/studio/backend/tests/test_gguf_load_cache_reuse.py+++ b/studio/backend/tests/test_gguf_load_cache_reuse.py@@ -84,6 +84,8 @@ from core.inference.llama_cpp import ()from core.inference.openai_auto_download import _DISK_RESERVE_BYTES+from ._fake_llama_server import fake_llama_server+REPO = "unsloth/gemma-test-GGUF"VARIANT = "UD-Q4_K_XL"@@ -670,16 +672,23 @@ class TestLoadReusesCachedCopy:backend._begin_load_warnings()assert backend.last_load_warning == "Q4_K_M was loaded instead."- def test_low_disk_fallback_load_records_the_served_variant(self, hf_cache, tmp_path):+ def test_low_disk_fallback_load_records_the_served_variant(+ self, hf_cache, tmp_path, monkeypatch+ ):backend = LlamaCppBackend()served = tmp_path / "gemma-test-Q4_K_M.gguf"served.write_bytes(b"GGUF" + b"\0" * 4096)- backend._find_llama_server_binary = lambda *_a, **_k: "/usr/bin/true"+ fake_server = fake_llama_server(tmp_path / "bin")+ backend._find_llama_server_binary = lambda *_a, **_k: fake_serverbackend._remote_non_chat_gguf_refusal = lambda **_k: Nonebackend._non_chat_gguf_refusal_for_path = lambda *_a, **_k: Nonebackend._non_chat_gguf_refusal = lambda *_a, **_k: Nonebackend._kill_process = lambda *_a, **_k: Nonebackend._wait_for_health = lambda timeout = 600.0, interval = 0.5, cancelled = None: True+ # Apple's unified-memory planner adds a notice for this header-only GGUF.+ monkeypatch.setattr(+ LlamaCppBackend, "_apple_metal_memory_budget_bytes", staticmethod(lambda: 0)+ )def _start(cmd, env, **_kwargs):backend._process = Mock(pid = 424242, returncode = None)diff --git a/studio/backend/tests/test_llama_cpp_placement.py b/studio/backend/tests/test_llama_cpp_placement.pyindex 267c073c438..e8721c45c12 100644--- a/studio/backend/tests/test_llama_cpp_placement.py+++ b/studio/backend/tests/test_llama_cpp_placement.py@@ -3427,6 +3427,10 @@ def _vulkan_cpu_replay_backend(tmp_path, monkeypatch, *, gguf_gb, free_mib, avaimonkeypatch.setattr(LlamaCppBackend, "_available_system_memory_mib", staticmethod(lambda: avail_mib))+ # A Vulkan host is never Apple Silicon; on a Mac runner the Metal budget would size the context instead.+ monkeypatch.setattr(+ LlamaCppBackend, "_apple_metal_memory_budget_bytes", staticmethod(lambda: 0)+ )monkeypatch.delenv("UNSLOTH_ALLOW_HOST_OFFLOAD", raising = False)return backend, ggufdiff --git a/studio/backend/tests/test_llama_cpp_wait_for_health.py b/studio/backend/tests/test_llama_cpp_wait_for_health.pyindex 57d59353a46..5f6a9f4b795 100644--- a/studio/backend/tests/test_llama_cpp_wait_for_health.py+++ b/studio/backend/tests/test_llama_cpp_wait_for_health.py@@ -30,6 +30,8 @@ import httpx # noqa: E402from core.inference.llama_cpp import LlamaCppBackend # noqa: E402from core.inference.llama_cpp import GgufLoadIntent+from ._fake_llama_server import fake_llama_server+# Sibling tests may install an httpx stub lacking get; fill gaps so order does not matter.if not hasattr(httpx, "get"):httpx.get = None@@ -668,7 +670,8 @@ class TestCancelledWaitEndsTheLoad:gguf.write_bytes(b"GGUF" + b"\0" * 4096)b = LlamaCppBackend()- b._find_llama_server_binary = lambda *a, **kw: "/usr/bin/true"+ fake_server = fake_llama_server(tmp_path / "bin")+ b._find_llama_server_binary = lambda *a, **kw: fake_serverb._non_chat_gguf_refusal_for_path = lambda *a, **kw: Noneb._non_chat_gguf_refusal = lambda *a, **kw: Noneb._kill_process = lambda *a, **kw: None@@ -714,7 +717,8 @@ class TestCancelledWaitEndsTheLoad:gguf.write_bytes(b"GGUF" + b"\0" * 4096)b = LlamaCppBackend()- b._find_llama_server_binary = lambda *a, **kw: "/usr/bin/true"+ fake_server = fake_llama_server(tmp_path / "bin")+ b._find_llama_server_binary = lambda *a, **kw: fake_serverb._non_chat_gguf_refusal_for_path = lambda *a, **kw: Noneb._non_chat_gguf_refusal = lambda *a, **kw: None# The drain thread would iterate a Mock's stdout forever.@@ -840,7 +844,8 @@ def test_a_diffusion_cancel_after_health_reaps_the_runner():def _cancel_scaffold(tmp_path, kills):"""A backend wired far enough to run load_model without weights or a server."""b = LlamaCppBackend()- b._find_llama_server_binary = lambda *a, **kw: "/usr/bin/true"+ fake_server = fake_llama_server(tmp_path / "bin")+ b._find_llama_server_binary = lambda *a, **kw: fake_serverb._non_chat_gguf_refusal_for_path = lambda *a, **kw: Noneb._non_chat_gguf_refusal = lambda *a, **kw: Noneb._kill_process = lambda *a, **kw: kills.append(1)