Skip to content

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.

Repin six UI contracts on what they guard, not how it was spelled (#8197)

Daniel Han37f43eb7420e
diff --git a/tests/studio/test_model_picker_contracts.py b/tests/studio/test_model_picker_contracts.py
index 612da9fb243..a66ea392b4f 100644
--- a/tests/studio/test_model_picker_contracts.py
+++ b/tests/studio/test_model_picker_contracts.py
@@ -26,6 +26,23 @@ def _read(rel: str) -> str:
return path.read_text(encoding = "utf-8")
+def _split_args(captured: str) -> list[str]:
+ """Split on top-level commas only, so `loadSpecFor(wanted, CATALOG)` survives."""
+ args, depth, current = [], 0, ""
+ for char in captured:
+ if char in "([{":
+ depth += 1
+ elif char in ")]}":
+ depth -= 1
+ if char == "," and depth == 0:
+ args.append(current)
+ current = ""
+ else:
+ current += char
+ args.append(current)
+ return args
+
+
def _read_backend(rel: str) -> str:
path = WORKDIR / "studio" / "backend" / rel
assert path.exists(), f"missing backend source file: {path}"
@@ -1071,11 +1088,19 @@ def test_a_routed_curated_pick_uses_the_same_load_spec_as_a_direct_one():
("features/video/video-page.tsx", "VIDEO_CATALOG"),
):
src = _read(rel)
- call = re.search(
- r"diffusionRoutePick\(\s*wanted,\s*routeSearch\.quant,\s*(.*?),?\s*\);", src, re.S
- )
- assert call, f"{rel}: the routed pick passes no spec"
- assert f"loadSpecFor(wanted, {catalog})" in call.group(1), rel
+ # The middle argument, the routed filename, has been respelled more than once;
+ # only the third is load-bearing, so do not pin the second.
+ call = re.search(r"diffusionRoutePick\(\s*wanted,\s*(.*?),?\s*\);", src, re.S)
+ assert call, f"{rel}: the routed pick does not go through diffusionRoutePick"
+ # By position, not by presence: `diffusionRoutePick(wanted, routedFilename ??
+ # loadSpecFor(wanted, IMAGE_CATALOG)?.filename)` type-checks, passes the spec's
+ # filename as the quant, drops the spec, and would pass a substring check while
+ # curated single-file artifacts load as GGUF.
+ args = _split_args(call.group(1))
+ assert len(args) >= 2, f"{rel}: the routed pick passes no spec argument"
+ assert (
+ f"loadSpecFor(wanted, {catalog})" in args[1]
+ ), f"{rel}: the routed pick passes no catalog spec"
def test_a_quantized_load_drops_a_lora_selection_it_cannot_bake():
@@ -1097,15 +1122,19 @@ def test_a_quantized_load_drops_a_lora_selection_it_cannot_bake():
def test_diffusion_pages_never_drop_a_gguf_pick_silently():
- """The fallback branch splits a local path; a repo pick reaching it has no
- filename. It must say so instead of returning with no request and no toast."""
+ """The fallback branch splits a local path, so a repo pick reaching it has no
+ filename. It used to error; it now resolves the repo's own .gguf. Either way the
+ branch must act: returning with no request and no toast drops the pick."""
for rel in ("features/images/images-page.tsx", "features/video/video-page.tsx"):
src = _read(rel)
branch = re.search(
- r'if \(!filename\.toLowerCase\(\)\.endsWith\("\.gguf"\)\) \{.*?\}', src, re.S
+ r'if \(!filename\.toLowerCase\(\)\.endsWith\("\.gguf"\)\) \{.*?\n \}', src, re.S
)
assert branch, f"{rel}: gguf extension guard not found"
- assert "toast.error(" in branch.group(0), f"{rel}: guard returns silently"
+ body = branch.group(0)
+ assert (
+ "toast.error(" in body or "loadGgufRepoPick(" in body
+ ), f"{rel}: guard returns silently"
def test_diffusion_pages_stage_downloads_through_the_manager():
@@ -1137,13 +1166,31 @@ def test_a_hidden_diffusion_page_does_not_load_when_its_download_lands():
assert "if (!active)" in ready.group(0), f"{rel}: a hidden page still takes the GPU"
# Deferred, not dropped: something has to fire the held pick when the page returns.
assert "stagedLoadDeferred" in ready.group(0), f"{rel}: the pick is discarded"
+ # The deps array grew when the load body moved into runStagedLoad, so match the
+ # effect by its guard and check the deps separately. Keying the boundary on
+ # `[active` instead lets a reordered array run the match on into the next hook,
+ # where loadOrStage's own handleLoadRef call satisfies the loader assertion below
+ # for a flush that loads nothing.
flush = re.search(
- r"if \(!active \|\| !stagedLoadDeferred\.current\) return;.*?\n \}, \[active\]\);",
+ r"if \(!active \|\| !stagedLoadDeferred\.current\) return;(.*?)\n \}, \[([^\]]*)\]\);",
src,
re.S,
)
assert flush, f"{rel}: nothing flushes the deferred load when the page is shown"
- assert "handleLoadRef.current(" in flush.group(0), f"{rel}: deferred load never runs"
+ deps = [dep.strip() for dep in flush.group(2).split(",")]
+ assert "active" in deps, f"{rel}: the flush does not re-run when the page is shown"
+ body = flush.group(1)
+ # Loading directly or through the visible path's helper is fine; clearing the
+ # flag and stopping is not.
+ assert (
+ "runStagedLoad()" in body or "handleLoadRef.current(" in body
+ ), f"{rel}: deferred load never runs"
+ if "runStagedLoad()" in body:
+ runner = re.search(r"const runStagedLoad = useCallback\(.*?\n \}, \[", src, re.S)
+ assert runner, f"{rel}: runStagedLoad not found"
+ assert "handleLoadRef.current(" in runner.group(
+ 0
+ ), f"{rel}: runStagedLoad loads nothing"
def test_staged_downloads_always_scope_their_files():
diff --git a/tests/studio/test_update_release_notes.py b/tests/studio/test_update_release_notes.py
index 765ad553215..4adf2264ba6 100644
--- a/tests/studio/test_update_release_notes.py
+++ b/tests/studio/test_update_release_notes.py
@@ -1113,10 +1113,16 @@ def test_code_span_closers_ignore_backslashes():
def test_the_overlay_stack_fits_the_viewport():
- """The update card's own cap does not account for a long download list
- stacked beneath it."""
+ """The update card's own cap does not account for a long download list stacked
+ beneath it. The cap is no longer the literal class `max-h-[calc(100dvh_-_2rem)]`
+ but `stackGeometry`, whose arithmetic is checked numerically in
+ studio/frontend/tests/monitor-stack-inset.test.ts; what has to hold here is that
+ the stack reads it rather than growing unbounded."""
provider = (FRONTEND / "app/provider.tsx").read_text(encoding = "utf-8")
- assert "max-h-[calc(100dvh_-_2rem)]" in provider
+ stacks = provider.count("z-[9998] flex flex-col items-end gap-2")
+ assert stacks, "the bottom-right overlay stack is gone"
+ # Counted, not merely present: capping only one of the stacks is the bug here.
+ assert provider.count("maxHeight: stack.maxHeight") == stacks, "every stack is capped"
panel = (FRONTEND / "features/hub/download-manager/download-manager-panel.tsx").read_text(
encoding = "utf-8"
)
@@ -1126,13 +1132,24 @@ def test_the_overlay_stack_fits_the_viewport():
def test_the_desktop_stack_is_capped_like_the_browser_one():
- """The download panel shares the desktop stack, so the update card's own
- cap is not enough there either."""
+ """The download panel shares the desktop stack, so the update card's own cap is
+ not enough there either, and the desktop branch has been left uncapped before."""
provider = (FRONTEND / "app/provider.tsx").read_text(encoding = "utf-8")
- assert provider.count("max-h-[calc(100dvh_-_2rem)]") == 2, "both stacks are capped"
+ assert provider.count("useStackGeometry()") == 2, "both stacks measure themselves"
+ assert provider.count("maxHeight: stack.maxHeight") == 2, "both stacks are capped"
assert "flex min-h-0" in TAURI_BANNER.read_text(encoding = "utf-8")
+def test_the_stack_geometry_is_checked_numerically():
+ """The cap is arithmetic now, not a class name, so the node test owns it. Named
+ here so deleting it does not quietly leave the cap unchecked."""
+ geometry = REPO / "studio/frontend/tests/monitor-stack-inset.test.ts"
+ src = geometry.read_text(encoding = "utf-8")
+ assert (
+ "stackGeometry(null, W, H).maxHeight, H - 32" in src
+ ), "nothing pins the no-obstacle cap to the 2rem the class used to spell"
+
+
def test_desktop_notes_are_looked_up_by_the_backend_version():
"""latest.json's `version` is the app SemVer while CHANGELOG.md is keyed by
the backend release, so the desktop popup used to find no section at all
@@ -1360,7 +1377,8 @@ def test_the_download_panel_can_shrink_inside_the_capped_stack():
)
assert 'positioned ? "fixed bottom-4 right-4 z-50" : "flex min-h-0 justify-end"' in panel
provider = (FRONTEND / "app/provider.tsx").read_text(encoding="utf-8")
- assert "max-h-[calc(100dvh_-_2rem)]" in provider, "the cap this has to absorb"
+ stacks = provider.count("z-[9998] flex flex-col items-end gap-2")
+ assert provider.count("maxHeight: stack.maxHeight") == stacks, "the cap this has to absorb"
@pytest.fixture(scope="module")