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
Test the non-GGUF status contract by behaviour, not by source spelling (#10185)
Daniel Hanecbe3dda5a1e
diff --git a/studio/backend/tests/test_native_context_length.py b/studio/backend/tests/test_native_context_length.pyindex 28279c91e1b..e24cfc68a5c 100644--- a/studio/backend/tests/test_native_context_length.py+++ b/studio/backend/tests/test_native_context_length.py@@ -601,16 +601,11 @@ def test_the_status_route_reports_what_a_self_sizing_load_asked_for():encoding = "utf-8")assert "requested_context_length = llama_backend.requested_n_ctx" in route_src- # 0 is "size it yourself"; None is "records no request", and the UI tells them apart.- # Either spelling of the recorded request, since the route stamps one and the MLX- # mirror carries the other, but always through the non-negative reader.- assert (- "requested_context_length = _nonnegative_int_or_none(\n"- ' model_info.get("requested_context_length")\n'- ' if model_info.get("requested_context_length") is not None\n'- ' else model_info.get("max_seq_length_requested")\n'- " )," in route_src- )+ # The non-GGUF branch is covered by behaviour instead, in+ # test_non_gguf_reload_settings.py::TestNonGgufStatusReportsWhatTheLoadAskedFor: 0 is+ # "size it yourself", None is "records no request", and the MLX mirror wins over the+ # stamped spelling. Pinning that call's exact layout here only duplicated it, and the+ # duplicate is what went stale when the reader gained the mirror.# The parent cannot recompute the group once the worker holds the model: it mirrors all.src = (Path(__file__).resolve().parents[1] / "core/inference/worker.py").read_text("utf-8")assert '"native_context_length",\n "max_context_length",' in srcdiff --git a/studio/backend/tests/test_non_gguf_reload_settings.py b/studio/backend/tests/test_non_gguf_reload_settings.pyindex 67b22b182d3..6fc1de14871 100644--- a/studio/backend/tests/test_non_gguf_reload_settings.py+++ b/studio/backend/tests/test_non_gguf_reload_settings.py@@ -37,6 +37,13 @@ class _Backend:def __init__(self, entry):self.active_model_name = RESIDENTself.models = {RESIDENT: entry}+ self.loading_models: set = set()+++class _NoLlama:+ """No llama-server resident, so status takes the non-GGUF branch."""++ is_loaded = Falseclass _Request:@@ -134,18 +141,80 @@ class TestNonGgufStatusReportsWhatTheLoadAskedFor:def test_the_route_stamps_it_after_a_successful_load(self, field):assert field in self._stamp_block(), f"{field} is never recorded on the resident"- def test_the_non_gguf_status_branch_publishes_them(self):- import inspect- import routes.inference as ri+ def _status_for(self, monkeypatch, entry):+ """The non-GGUF status payload for a resident stamped with `entry`.++ Driven through the route rather than read out of its source: the spelling of the+ read is not the contract, the published field is. An earlier version asserted the+ literal `model_info.get(...)` line and broke on #8125, which kept publishing the+ same field from the same stamped key through a coercion helper.+ """+ import asyncio++ backend = _Backend(entry)+ monkeypatch.setattr(inference_route, "get_llama_cpp_backend", lambda: _NoLlama())+ monkeypatch.setattr(inference_route, "get_inference_backend", lambda: backend)+ monkeypatch.setattr(inference_route, "_peek_inference_backend", lambda: backend)+ monkeypatch.setattr(+ inference_route, "_probe_llama_cpp_status", lambda _backend: (False, {})+ )+ monkeypatch.setattr(+ inference_route,+ "_detect_safetensors_features",+ lambda *_a: {+ "supports_reasoning": False,+ "reasoning_style": "enable_thinking",+ "reasoning_effort_levels": [],+ "reasoning_always_on": False,+ "supports_preserve_thinking": False,+ "supports_tools": False,+ },+ )+ monkeypatch.setattr(inference_route, "load_inference_config", lambda _model: None)+ # Unrelated to the stamped settings, and it re-derives from the model card, which+ # would put a Hub request in the middle of a status unit test.+ monkeypatch.setattr(+ inference_route, "_resolve_loaded_trust_remote_code", lambda *_a, **_k: False+ )+ monkeypatch.setattr(inference_route, "_running_load_attempt", None)+ monkeypatch.setattr(inference_route, "_pending_load_attempts", {})+ return asyncio.run(inference_route.get_status(current_subject = "test"))++ def test_the_non_gguf_status_branch_publishes_them(self, monkeypatch):+ response = self._status_for(+ monkeypatch,+ {+ "max_seq_length_requested": 8192,+ "load_in_4bit_requested": False,+ "gpu_ids_requested": [0, 1],+ },+ )++ assert response.requested_context_length == 8192+ assert response.load_in_4bit is False+ assert response.requested_gpu_ids == [0, 1]++ def test_the_mlx_mirror_wins_over_the_stamped_spelling(self, monkeypatch):+ """#8125: the MLX worker mirrors the real context back as requested_context_length."""+ response = self._status_for(+ monkeypatch,+ {"requested_context_length": 4096, "max_seq_length_requested": 8192},+ )++ assert response.requested_context_length == 4096++ @pytest.mark.parametrize(+ "requested, published",+ [(0, 0), (8192, 8192), ("8192", 8192), (-1, None), (True, None), ("", None), (None, None)],+ )+ def test_a_requested_context_length_is_published_only_when_it_is_a_count(+ self, monkeypatch, requested, published+ ):+ """0 is an answer -- size it yourself -- so it must survive; junk must not.++ A bool is not a count even though `int(True)` is 1, and a negative is not one+ either; a numeric string still is, since the stamp is read back off JSON.+ """+ response = self._status_for(monkeypatch, {"max_seq_length_requested": requested})- src = inspect.getsource(ri.get_status)- # The GGUF branch returns first, so the last occurrence is the non-GGUF return.- non_gguf = src[src.rindex("Non-GGUF: classify from the loaded template") :]- for wire, stamped in (- ("requested_context_length", "max_seq_length_requested"),- ("load_in_4bit", "load_in_4bit_requested"),- ("requested_gpu_ids", "gpu_ids_requested"),- ):- assert (- f'{wire} = model_info.get("{stamped}")' in non_gguf- ), f"non-GGUF status does not publish {wire}"+ assert response.requested_context_length == publisheddiff --git a/tests/studio/test_model_picker_contracts.py b/tests/studio/test_model_picker_contracts.pyindex 6b700735c86..d56c8d26104 100644--- a/tests/studio/test_model_picker_contracts.py+++ b/tests/studio/test_model_picker_contracts.py@@ -681,11 +681,20 @@ def test_a_pinned_cached_row_loads_from_the_id_the_backend_pinned():# loosely, so a new row that forgets it is a failure here rather than a load# that silently follows the default ref. #7736 added the third: the collapsed# single-quant GGUF row. #7880 added the fourth: the per-quant VRAM bar, which- # has to price the pinned snapshot rather than the default ref.- assert picker.count("loadId: c.load_id") == 4, (+ # has to price the pinned snapshot rather than the default ref. #10128 put three of+ # them behind a torn-snapshot guard, so the guard is matched rather than one spelling.+ pins = re.findall(r"loadId:\s*(?:(\w+)\s*\?\s*undefined\s*:\s*)?c\.load_id", picker)+ assert len(pins) == 4, ("a row or gear that can start a load is missing the pin, or a new one was ""added and this count needs to follow it")+ # #10128: the three that can START a load withhold the pin for a part-downloaded+ # snapshot, since audio-page.tsx reads a forwarded loadId as proof the weights are+ # on disk. The VRAM bar only prices what is there, so it pins unconditionally.+ assert sorted(pins) == ["", "isPartial", "isPartial", "isPartial"], (+ "a row that can start a load lost its partial-snapshot guard, or the VRAM bar "+ f"gained one: {sorted(pins)}"+ )block = re.search(r"onConfigure\(repoId, \{.*?\n\s*\}", picker, re.S)assert block and "loadId," in block.group(0), "the GGUF gear drops the pin"# The variant click withholds it: a quant outside the pinned snapshot lands in a different one.