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 composer icon check: re-measure a case when the dev page reloads mid-case (#14647)
Daniel Hanb20f180ed46a
diff --git a/tests/studio/playwright_composer_icons.py b/tests/studio/playwright_composer_icons.pyindex 40b2a70e316..c6142baece0 100644--- a/tests/studio/playwright_composer_icons.py+++ b/tests/studio/playwright_composer_icons.py@@ -53,6 +53,52 @@ MEASURE = """() => [...document.querySelectorAll('button[data-case]')].map(butto};})"""+# Applies one display case and measures it in the same evaluate, so a reload cannot reset the case+# between the two and have the default layout recorded under the case's name.+APPLY_AND_MEASURE = (+ """async ({font, zoom, dark, direction}) => {+ const root = document.documentElement;+ root.style.setProperty('--ui-font-scale', String(font));+ root.style.zoom = String(zoom);+ root.classList.toggle('dark', dark);+ root.dir = direction;+ await new Promise(requestAnimationFrame);+ return ("""+ + MEASURE+ + """)();+}"""+)++CASE_ATTEMPTS = 3+++def measure_case(+ page,+ case: dict,+ server = None,+) -> list:+ """Measures a case, re-running it on a fresh render when the page navigates away mid-case.++ The vite dev page sometimes reloads itself on Windows runners after its buttons have rendered+ (main job 119495424607, PR 14592 job 119703801606); the evaluate then loses its context."""+ for attempt in range(1, CASE_ATTEMPTS + 1):+ try:+ return page.evaluate(APPLY_AND_MEASURE, case)+ except Exception as exc:+ if (+ attempt == CASE_ATTEMPTS+ or "execution context was destroyed" not in str(exc).lower()+ ):+ raise+ tail = "\n".join(getattr(server, "vite_tail", []))+ print(+ f"page navigated during {case} (attempt {attempt}); re-measuring on the new render\n"+ f"vite output:\n{tail}",+ flush = True,+ )+ page.wait_for_load_state("domcontentloaded")+ page.locator("button[data-case]").last.wait_for()+def main() -> None:parser = argparse.ArgumentParser(description = __doc__)@@ -96,18 +142,7 @@ def main() -> None:dark = dark,direction = direction,)- page.evaluate(- """async ({font, zoom, dark, direction}) => {- const root = document.documentElement;- root.style.setProperty('--ui-font-scale', String(font));- root.style.zoom = String(zoom);- root.classList.toggle('dark', dark);- root.dir = direction;- await new Promise(requestAnimationFrame);- }""",- case,- )- measures = page.evaluate(MEASURE)+ measures = measure_case(page, case, server)assert len(measures) == 6, measuresresults.append(dict(case = case, measures = measures))for measure in measures:diff --git a/tests/studio/test_composer_icons_navigation.py b/tests/studio/test_composer_icons_navigation.pynew file mode 100644index 00000000000..2b086759e8d--- /dev/null+++ b/tests/studio/test_composer_icons_navigation.py@@ -0,0 +1,109 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""The composer icon check survives the dev page reloading itself mid-case.++On Windows runners the vite page sometimes navigated after its buttons rendered, and the next+evaluate died with "Execution context was destroyed" (main job 119495424607, PR 14592 job+119703801606). A reload also resets the display case, so re-running only the measurement would+record the default layout under the case's name: the case must be applied again with it.+"""++import importlib.util+import sys+import types+from pathlib import Path++import pytest++SCRIPT = Path(__file__).resolve().parent / "playwright_composer_icons.py"+DEFAULT = dict(font = 1, zoom = 1, dark = False, direction = "ltr")+CASE = dict(engine = "chromium", dpr = 2, font = 1.25, zoom = 0.8, dark = True, direction = "rtl")+LOST = "Page.evaluate: Execution context was destroyed, most likely because of a navigation"+++def mod(monkeypatch):+ if "playwright.sync_api" not in sys.modules:+ pkg = types.ModuleType("playwright")+ api = types.ModuleType("playwright.sync_api")+ api.sync_playwright = lambda: None+ pkg.sync_api = api+ monkeypatch.setitem(sys.modules, "playwright", pkg)+ monkeypatch.setitem(sys.modules, "playwright.sync_api", api)+ monkeypatch.syspath_prepend(str(SCRIPT.parent))+ spec = importlib.util.spec_from_file_location("composer_icons_under_test", SCRIPT)+ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+++class FakePage:+ """Holds the applied display case; a reload resets it and kills the evaluate in flight."""++ def __init__(+ self,+ reloads_on_calls = (),+ error = LOST,+ ):+ self.state = dict(DEFAULT)+ self.calls = 0+ self.reloads_on_calls = set(reloads_on_calls)+ self.error = error+ self.waits = 0++ def evaluate(+ self,+ expression,+ arg = None,+ ):+ self.calls += 1+ if self.calls in self.reloads_on_calls:+ self.state = dict(DEFAULT)+ raise RuntimeError(self.error)+ if "root.dir = direction" in expression:+ self.state = {k: arg[k] for k in DEFAULT}+ if "getBBox" in expression:+ return [dict(self.state, name = f"icon{i}") for i in range(6)]+ return None++ def wait_for_load_state(self, *args, **kwargs):+ self.waits += 1++ def locator(self, selector):+ return types.SimpleNamespace(last = types.SimpleNamespace(wait_for = lambda: None))+++def _case_state(measures):+ return [{k: m[k] for k in DEFAULT} for m in measures]+++def test_a_case_is_applied_and_measured_in_one_evaluate(mod):+ page = FakePage()+ measures = mod.measure_case(page, CASE)+ assert page.calls == 1+ assert _case_state(measures) == [{k: CASE[k] for k in DEFAULT}] * 6++[email protected]("reload_on", [1, 2])+def test_a_reload_mid_case_re_measures_the_same_case(mod, reload_on):+ page = FakePage(reloads_on_calls = range(1, reload_on + 1))+ measures = mod.measure_case(page, CASE)+ assert (+ _case_state(measures) == [{k: CASE[k] for k in DEFAULT}] * 6+ ), "a reload reset the display case and the default layout was recorded under its name"+ assert page.waits == reload_on+++def test_a_page_that_keeps_navigating_still_fails(mod):+ page = FakePage(reloads_on_calls = range(1, 99))+ with pytest.raises(RuntimeError, match = "Execution context was destroyed"):+ mod.measure_case(page, CASE)+ assert page.calls == mod.CASE_ATTEMPTS+++def test_any_other_evaluate_error_fails_at_once(mod):+ page = FakePage(reloads_on_calls = {1}, error = "ReferenceError: getBBox is not defined")+ with pytest.raises(RuntimeError, match = "ReferenceError"):+ mod.measure_case(page, CASE)+ assert page.calls == 1