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: read the scaled lengths and colours the UI contracts were written against (#11505)
Daniel Han655a195808a1
diff --git a/tests/studio/test_desktop_reliability_frontend_contract.py b/tests/studio/test_desktop_reliability_frontend_contract.pyindex fa3f3ee060d..ceb8bb62dda 100644--- a/tests/studio/test_desktop_reliability_frontend_contract.py+++ b/tests/studio/test_desktop_reliability_frontend_contract.py@@ -82,7 +82,13 @@ def _scale_constants() -> dict[str, str]:and provider.tsx uses the same constant as the CSS fallback, which is what keeps asingle 34 in the codebase, so read it from there rather than repeating it here."""- source = INTERFACE_SCALE_RUNTIME.read_text(encoding = "utf-8")+ # Raw. These are native chrome: the mac titlebar is 34px because the OS window+ # decoration is, and the runtime divides it by the webview zoom rather than scaling it+ # with the interface font. Read through `_ui_source`, a constant respelled as+ # `calc(34px * var(--ui-space-scale, 1))` would collapse back to 34px here and every+ # chrome contract downstream would agree with itself while the CSS moved off the+ # native chrome it is supposed to sit against.+ source = _window_chrome_source(INTERFACE_SCALE_RUNTIME)numbers = dict(re.findall(r"export const (\w+_PX) = (\d+);", source))return {name: re.sub(r"\$\{(\w+)\}", lambda m: numbers.get(m.group(1), m.group(0)), body)@@ -148,10 +154,10 @@ def _px(value: str | None) -> int | None:def test_desktop_update_offer_remains_actionable_from_settings():- provider = APP_PROVIDER.read_text(encoding = "utf-8")- context = TAURI_UPDATE_CONTEXT.read_text(encoding = "utf-8")- hook = TAURI_UPDATE_HOOK.read_text(encoding = "utf-8")- settings = DESKTOP_UPDATE_CONTROL.read_text(encoding = "utf-8")+ provider = _ui_source(APP_PROVIDER)+ context = _ui_source(TAURI_UPDATE_CONTEXT)+ hook = _ui_source(TAURI_UPDATE_HOOK)+ settings = _ui_source(DESKTOP_UPDATE_CONTROL)assert "<TauriUpdateContext.Provider value={update}>" in providercontext_start = provider.index("<TauriUpdateContext.Provider value={update}>")@@ -172,7 +178,7 @@ def test_desktop_update_offer_remains_actionable_from_settings():def test_desktop_update_search_has_a_stable_general_tab_destination():- general = GENERAL_SETTINGS.read_text(encoding = "utf-8")+ general = _ui_source(GENERAL_SETTINGS)assert 'data-settings-label={t("settings.about.updates")}' in generalassert "<DesktopUpdateControl />" in general@@ -185,8 +191,8 @@ def test_desktop_update_keeps_the_in_app_path_on_a_guessed_policy():command, which returns Ok(None) off Linux, so Settings would claim the appwas up to date while an update was waiting."""- hook = TAURI_UPDATE_HOOK.read_text(encoding = "utf-8")- policy = DESKTOP_UPDATE_POLICY.read_text(encoding = "utf-8")+ hook = _ui_source(TAURI_UPDATE_HOOK)+ policy = _ui_source(DESKTOP_UPDATE_POLICY)assert "resolved: boolean" in hookassert "resolved: false" in hook@@ -206,7 +212,7 @@ def test_desktop_update_keeps_the_in_app_path_on_a_guessed_policy():def test_settings_update_button_is_inert_while_an_install_runs():- settings = DESKTOP_UPDATE_CONTROL.read_text(encoding = "utf-8")+ settings = _ui_source(DESKTOP_UPDATE_CONTROL)assert 'update.status === "updating-backend"' in settingsassert 'update.status === "downloading"' in settings@@ -216,9 +222,9 @@ def test_settings_update_button_is_inert_while_an_install_runs():def test_desktop_update_check_failures_are_retryable():- hook = TAURI_UPDATE_HOOK.read_text(encoding = "utf-8")- settings = DESKTOP_UPDATE_CONTROL.read_text(encoding = "utf-8")- policy = DESKTOP_UPDATE_POLICY.read_text(encoding = "utf-8")+ hook = _ui_source(TAURI_UPDATE_HOOK)+ settings = _ui_source(DESKTOP_UPDATE_CONTROL)+ policy = _ui_source(DESKTOP_UPDATE_POLICY)assert "setCheckError(String(e));" in hookassert "update.checkError !== null" in settings@@ -233,12 +239,12 @@ def test_desktop_update_check_failures_are_retryable():def test_file_actions_route_through_native_commands_only_in_tauri():- helper = NATIVE_FILES.read_text(encoding = "utf-8")- history = CHAT_EXPORT.read_text(encoding = "utf-8")- data_tab = DATA_TAB.read_text(encoding = "utf-8")- prompt_storage = PROMPT_STORAGE.read_text(encoding = "utf-8")+ helper = _ui_source(NATIVE_FILES)+ history = _ui_source(CHAT_EXPORT)+ data_tab = _ui_source(DATA_TAB)+ prompt_storage = _ui_source(PROMPT_STORAGE)- projects = (FRONTEND / "features/chat/projects-page.tsx").read_text(encoding = "utf-8")+ projects = _ui_source(FRONTEND / "features/chat/projects-page.tsx")assert 'invoke<string | null>("save_native_file", bytes, {' in helperassert '"x-unsloth-default-name"' in helper@@ -263,7 +269,7 @@ def test_file_actions_route_through_native_commands_only_in_tauri():# Open WebUI exports are .json arrays, so the picker takes that too.assert 'accept=".json,.jsonl,.ndjson,.csv"' in data_tab- native_dialogs = NATIVE_DIALOGS.read_text(encoding = "utf-8")+ native_dialogs = _ui_source(NATIVE_DIALOGS)assert 'CHAT_IMPORT_EXTENSIONS: &[&str] = &["json", "jsonl", "ndjson", "csv"]' in native_dialogsassert "InvokeBody::Raw" in native_dialogs@@ -273,8 +279,8 @@ def test_file_actions_route_through_native_commands_only_in_tauri():def test_media_galleries_save_natively_with_feedback():- images_page = IMAGES_PAGE.read_text(encoding = "utf-8")- video_page = VIDEO_PAGE.read_text(encoding = "utf-8")+ images_page = _ui_source(IMAGES_PAGE)+ video_page = _ui_source(VIDEO_PAGE)reencode = images_page.split("async function reencodeImage(", 1)[1].split("\n}\n\nasync function downloadImage", 1)[0]@@ -302,14 +308,14 @@ def test_media_galleries_save_natively_with_feedback():def test_chat_exports_await_native_saves_and_markdown_uses_shared_helper():- app_sidebar = APP_SIDEBAR.read_text(encoding = "utf-8")- prompt_storage = PROMPT_STORAGE.read_text(encoding = "utf-8")- thread = THREAD.read_text(encoding = "utf-8")- thread_sidebar = THREAD_SIDEBAR.read_text(encoding = "utf-8")- shared_composer = SHARED_COMPOSER.read_text(encoding = "utf-8")-- data_tab = DATA_TAB.read_text(encoding = "utf-8")- projects = (FRONTEND / "features/chat/projects-page.tsx").read_text(encoding = "utf-8")+ app_sidebar = _ui_source(APP_SIDEBAR)+ prompt_storage = _ui_source(PROMPT_STORAGE)+ thread = _ui_source(THREAD)+ thread_sidebar = _ui_source(THREAD_SIDEBAR)+ shared_composer = _ui_source(SHARED_COMPOSER)++ data_tab = _ui_source(DATA_TAB)+ projects = _ui_source(FRONTEND / "features/chat/projects-page.tsx")assert "async function downloadBlob(" in prompt_storagedownload_blob = prompt_storage.split("async function downloadBlob(", 1)[1].split("\n}\n", 1)[0]assert "return downloadFile(" in download_blob@@ -336,11 +342,11 @@ def test_chat_exports_await_native_saves_and_markdown_uses_shared_helper():def test_generated_download_buttons_use_the_native_save_boundary():- helper = NATIVE_FILES.read_text(encoding = "utf-8")- training = TRAINING_CONFIG_ACTIONS.read_text(encoding = "utf-8")- markdown = MARKDOWN_TEXT.read_text(encoding = "utf-8")- image = IMAGE.read_text(encoding = "utf-8")- audio = AUDIO_PLAYER.read_text(encoding = "utf-8")+ helper = _ui_source(NATIVE_FILES)+ training = _ui_source(TRAINING_CONFIG_ACTIONS)+ markdown = _ui_source(MARKDOWN_TEXT)+ image = _ui_source(IMAGE)+ audio = _ui_source(AUDIO_PLAYER)assert "downloadFile(bytes, filename" in helperassert "browserUrlDownload(url, filename)" in helper@@ -363,9 +369,9 @@ def test_generated_download_buttons_use_the_native_save_boundary():def test_gallery_video_links_are_absolute_and_saved_natively():- video_api = VIDEO_API.read_text(encoding = "utf-8")- video_page = VIDEO_PAGE.read_text(encoding = "utf-8")- rag_api = RAG_API.read_text(encoding = "utf-8")+ video_api = _ui_source(VIDEO_API)+ video_page = _ui_source(VIDEO_PAGE)+ rag_api = _ui_source(RAG_API)# The backend mints this link relative so a proxy can serve it. Its consumers are# <video src> and the download, none of which go through authFetch, so a relative@@ -378,7 +384,7 @@ def test_gallery_video_links_are_absolute_and_saved_natively():# An absolute link is cross-origin, where the download attribute stops saving, so the# MP4 goes native. Streaming, not downloadUrl: a clip is capped at 2048x2048 x 1024# frames, too big to buffer for IPC, and the chooser must not wait on the body.- helper = NATIVE_FILES.read_text(encoding = "utf-8")+ helper = _ui_source(NATIVE_FILES)assert "downloadUrlStreaming(src, exportFilename(video, format))" in video_pageassert '"save_native_file_from_url"' in helperassert "isDownloadCancelled(err)" in video_page@@ -394,7 +400,7 @@ def test_gallery_video_links_are_absolute_and_saved_natively():# The save dialog now offers these to video, not just to the audio player, and the# streaming command is registered and pinned to the local backend.- dialogs = NATIVE_DIALOGS.read_text(encoding = "utf-8")+ dialogs = _ui_source(NATIVE_DIALOGS)assert '("MPEG-4 video or audio", filter_extensions(["m4a", "mp4"]))' in dialogsassert '("WebM video or audio", filter_extensions(["webm"]))' in dialogsassert "async fn stream_url_to_path" in dialogs@@ -420,12 +426,10 @@ def test_gallery_video_links_are_absolute_and_saved_natively():def test_clipboard_file_paste_is_bounded_and_wired_to_both_composers():- helper = CLIPBOARD_FILES.read_text(encoding = "utf-8") + CLIPBOARD_PAYLOAD.read_text(- encoding = "utf-8"- )- thread = THREAD.read_text(encoding = "utf-8")- shared_composer = SHARED_COMPOSER.read_text(encoding = "utf-8")- capabilities = TAURI_CAPABILITIES.read_text(encoding = "utf-8")+ helper = _ui_source(CLIPBOARD_FILES) + _ui_source(CLIPBOARD_PAYLOAD)+ thread = _ui_source(THREAD)+ shared_composer = _ui_source(SHARED_COMPOSER)+ capabilities = _ui_source(TAURI_CAPABILITIES)for contract in ("clipboardData.files",@@ -460,8 +464,8 @@ def test_clipboard_file_paste_is_bounded_and_wired_to_both_composers():def test_native_clipboard_bridge_is_bounded_and_registered():- native_clipboard = NATIVE_CLIPBOARD.read_text(encoding = "utf-8")- tauri_main = TAURI_MAIN.read_text(encoding = "utf-8")+ native_clipboard = _ui_source(NATIVE_CLIPBOARD)+ tauri_main = _ui_source(TAURI_MAIN)for contract in ("MAX_CLIPBOARD_FILES",@@ -489,7 +493,7 @@ def test_native_clipboard_bridge_is_bounded_and_registered():def test_mac_dock_reopens_hidden_main_window():- source = TAURI_MAIN.read_text(encoding = "utf-8")+ source = _ui_source(TAURI_MAIN)show_helper = source.split("fn show_main_window", 1)[1].split("\n}\n", 1)[0]run_handler = source.split(".run(|app, event|", 1)[1]@@ -504,7 +508,7 @@ def test_mac_dock_reopens_hidden_main_window():def test_windows_browser_guard_runs_only_in_release_builds():# WebView2 is not reachable from Python, so pin the release-only call that# keeps refresh controls available during development.- source = TAURI_MAIN.read_text(encoding = "utf-8")+ source = _ui_source(TAURI_MAIN)assert "fn setup_windows_browser_guards" in sourcebefore_call = source.split("setup_windows_browser_guards(app)?;", 1)[0]@@ -512,8 +516,8 @@ def test_windows_browser_guard_runs_only_in_release_builds():def test_desktop_manages_the_remote_password_through_the_account_dialog():- section = REMOTE_ACCESS_SECTION.read_text(encoding = "utf-8")- dialog = PASSWORD_DIALOG.read_text(encoding = "utf-8")+ section = _ui_source(REMOTE_ACCESS_SECTION)+ dialog = _ui_source(PASSWORD_DIALOG)row = section.split("function RemotePasswordRow", 1)[1].split("export function RemoteAccessSection", 1@@ -521,7 +525,7 @@ def test_desktop_manages_the_remote_password_through_the_account_dialog():assert "if (!(isTauri && status)) {" in rowassert "initial={status.passwordPending}" in rowassert "<RemotePasswordRow status={status} onDone={refreshStatus} />" in section- assert "{isTauri && isOwner ? null : (" in GENERAL_TAB.read_text(encoding = "utf-8")+ assert "{isTauri && isOwner ? null : (" in _ui_source(GENERAL_TAB)# A password change rotates credentials outside the polling requests.refresh = section.split("const refreshStatus = useCallback(", 1)[1].split("}, []);", 1)[0]assert "mutationEpoch.current += 1;" in refresh@@ -543,7 +547,7 @@ def test_desktop_manages_the_remote_password_through_the_account_dialog():def test_desktop_startup_waits_for_auth_without_intermediate_handoff():- source = APP_PROVIDER.read_text(encoding = "utf-8")+ source = _ui_source(APP_PROVIDER)# The gate has been renamed once already (showApp -> canMountApp) and gained a second# clause, so pin the CONDITION that makes the app wait for auth, not the name in front@@ -562,7 +566,7 @@ def test_desktop_startup_waits_for_auth_without_intermediate_handoff():def test_full_app_layout_uses_its_own_initialized_marker():- source = APP_PROVIDER.read_text(encoding = "utf-8")+ source = _ui_source(APP_PROVIDER)assert 'invoke<boolean>("has_initialized_app_window_layout")' in sourcesetup_layout = source.split("async function showSetupWindow", 1)[1].split(@@ -576,7 +580,7 @@ def test_full_app_layout_uses_its_own_initialized_marker():def test_first_app_layout_survives_a_stale_setup_window_size():- source = APP_PROVIDER.read_text(encoding = "utf-8")+ source = _ui_source(APP_PROVIDER)bounds_helper = source.split("async function enforceWindowSizeBounds", 1)[1].split("async function applyAppWindowLayout", 1)[0]@@ -603,9 +607,20 @@ def test_first_app_layout_survives_a_stale_setup_window_size():def test_expanded_titlebar_button_and_corner_match_sidebar_edge():- source = TITLEBAR.read_text(encoding = "utf-8")-- assert 'showSidebarSurface && !pinned ? "7rem" : sidebarWidth' in source+ source = _ui_source(TITLEBAR)++ # Read raw, and matched across whitespace because prettier wrapped the ternary over three+ # lines. #11458 made the slot `max(7rem, calc(7rem * var(--ui-space-scale, 1)))` so it+ # grows with the UI font and never drops under the three 30px buttons. A bare `7rem` is+ # not the same guarantee: the buttons' own padding and gaps still scale, so at a larger+ # setting a fixed slot is overrun and the drag region starts inside the navigation. Both+ # terms are pinned, since either one drifting is a slot that no longer says 7rem.+ assert re.search(+ r"showSidebarSurface && !pinned\s*\?\s*"+ r'"max\(\s*7rem\s*,\s*calc\(\s*7rem\s*\*\s*var\(\s*--ui-space-scale\s*,\s*1\s*\)\s*\)\s*\)"'+ r"\s*:\s*sidebarWidth",+ TITLEBAR.read_text(encoding = "utf-8"),+ ), "the unpinned sidebar surface no longer sizes the titlebar navigation slot from 7rem"assert "style={{ width: titlebarNavigationWidth }}" in sourceassert "left: titlebarNavigationWidth" in sourceassert "<DesktopTitlebarNavigation" in source@@ -631,8 +646,8 @@ def test_expanded_titlebar_button_and_corner_match_sidebar_edge():def test_desktop_titlebar_separates_navigation_from_sidebar_brand():- titlebar = TITLEBAR.read_text(encoding = "utf-8")- sidebar = APP_SIDEBAR.read_text(encoding = "utf-8")+ titlebar = _ui_source(TITLEBAR)+ sidebar = _ui_source(APP_SIDEBAR)header = sidebar.split("<SidebarHeader", 1)[1].split("</SidebarHeader>", 1)[0]# The names, not the whole import list: #8025 added Minus/Square/X to the@@ -650,8 +665,8 @@ def test_desktop_titlebar_separates_navigation_from_sidebar_brand():def test_collapsed_tauri_keeps_history_arrows_and_adds_new_chat_by_model_picker():- titlebar = TITLEBAR.read_text(encoding = "utf-8")- chat_page = CHAT_PAGE.read_text(encoding = "utf-8")+ titlebar = _ui_source(TITLEBAR)+ chat_page = _ui_source(CHAT_PAGE)navigation = titlebar.split("export function DesktopTitlebarNavigation", 1)[1].split("export function WindowTitlebar", 1)[0]@@ -686,7 +701,7 @@ def test_collapsed_tauri_keeps_history_arrows_and_adds_new_chat_by_model_picker(# titlebar sets the same var to its own much smaller inset, hence the mac-only filter.insets = {name: _px(values["--studio-collapsed-chat-controls-inset"])- for name, values in _chrome_style_blocks(APP_PROVIDER.read_text(encoding = "utf-8")).items()+ for name, values in _chrome_style_blocks(_ui_source(APP_PROVIDER)).items()if "--studio-mac-traffic-light-inset" in values}assert insets, "no style block sets both the traffic-light and collapsed-controls insets"@@ -698,10 +713,10 @@ def test_collapsed_tauri_keeps_history_arrows_and_adds_new_chat_by_model_picker(def test_tauri_collapse_removes_the_icon_rail_but_web_keeps_it():- titlebar = TITLEBAR.read_text(encoding = "utf-8")- app_sidebar = APP_SIDEBAR.read_text(encoding = "utf-8")- primitive = SIDEBAR_PRIMITIVE.read_text(encoding = "utf-8")- navbar = NAVBAR.read_text(encoding = "utf-8")+ titlebar = _ui_source(TITLEBAR)+ app_sidebar = _ui_source(APP_SIDEBAR)+ primitive = _ui_source(SIDEBAR_PRIMITIVE)+ navbar = _ui_source(NAVBAR)assert "collapseToZero={isTauri}" in app_sidebarassert "collapseToZero = false" in primitive@@ -727,7 +742,7 @@ def test_tauri_collapse_removes_the_icon_rail_but_web_keeps_it():assert "mt-[var(--studio-titlebar-navigation-margin-top,0px)]" in navigationbutton = _titlebar_nav_button_px(titlebar)assert button is not None, "navigation button size no longer readable from buttonClass"- blocks = _chrome_style_blocks(APP_PROVIDER.read_text(encoding = "utf-8"))+ blocks = _chrome_style_blocks(_ui_source(APP_PROVIDER))nudged = {name: valuesfor name, values in blocks.items()@@ -765,8 +780,8 @@ def test_tauri_collapse_removes_the_icon_rail_but_web_keeps_it():def test_fixed_sheets_start_below_the_custom_titlebar():- provider = APP_PROVIDER.read_text(encoding = "utf-8")- sheet = SHEET.read_text(encoding = "utf-8")+ provider = _window_chrome_source(APP_PROVIDER)+ sheet = _ui_source(SHEET)# Portalled sheets read the height off <html>, so the mirror has to stay.assert 'set("--studio-custom-titlebar-height", usesCustomTitlebar ? "34px" : null)' in provider@@ -791,11 +806,11 @@ def test_fixed_sheets_start_below_the_custom_titlebar():RESPONSE_DETAILS_SHEET,DOCUMENT_PREVIEW_SHEET,):- assert "studio-custom-titlebar-height" not in portalled.read_text(encoding = "utf-8")+ assert "studio-custom-titlebar-height" not in _ui_source(portalled)def test_visible_mac_sidebar_header_is_a_drag_region():- source = APP_SIDEBAR.read_text(encoding = "utf-8")+ source = _ui_source(APP_SIDEBAR)header = source.split("<SidebarHeader", 1)[1].split("</SidebarHeader>", 1)[0]drag_region = "data-tauri-drag-region={usesNativeMacTitlebar || undefined}"@@ -804,8 +819,8 @@ def test_visible_mac_sidebar_header_is_a_drag_region():def test_mac_chat_header_controls_share_the_titlebar_row():- source = CHAT_PAGE.read_text(encoding = "utf-8")- provider = APP_PROVIDER.read_text(encoding = "utf-8")+ source = _ui_source(CHAT_PAGE)+ provider = _ui_source(APP_PROVIDER)assert "shouldUseNativeMacWindowTitlebar" not in sourceassert "[--studio-content-top-inset:var(--studio-mac-titlebar-height" not in source@@ -831,14 +846,14 @@ def test_mac_chat_header_controls_share_the_titlebar_row():def test_collapsed_mac_sidebar_hides_divider():- source = APP_SIDEBAR.read_text(encoding = "utf-8")+ source = _ui_source(APP_SIDEBAR)assert "group-data-[collapsible=icon]:[&_[data-sidebar=sidebar]]:border-r-0" in sourceassert "top-[var(--studio-mac-titlebar-height,34px)]" not in sourcedef test_chat_sidebar_rows_are_compact_without_vertical_padding():- sidebar_source = APP_SIDEBAR.read_text(encoding = "utf-8")+ sidebar_source = _ui_source(APP_SIDEBAR)block = sidebar_source.split("function renderChatSidebarItem", 1)[1]assert (@@ -950,6 +965,119 @@ def _button_classes(source: str, tag: str, variant: str) -> str | None:return _resolve_classes(source, value[1:-1], variant)+# #11458 made spacing follow the UI font size: every fixed length in the stylesheet and in+# the page markup became `calc(<length> * var(--ui-space-scale, 1))`, and #11459 did the same+# for the dark wash with `--contrast-wash-gain`. Both scales default to 1, so the rendered+# value is unchanged; only the spelling moved. These contracts are written against the+# lengths, so resolve the wrapper back to the length it scales. A real change to the length+# still fails, which is the whole point of reading the value rather than the spelling.+#+# Only `--ui-space-scale` reads back as the length it wraps, and only it. `index.css:316`+# declares `--ui-font-scale: 0.9375` and derives `--ui-space-scale` as the ratio of the two,+# so the spacing scale is 1 by default while the font scale is not: a length respelled onto+# `calc(48px * var(--ui-font-scale, 1))` renders at 45px. Reading the font scale, or+# `var(--anything, 1)` at large, would hand a contract back the literal it asks about while+# the pane had quietly stopped following the interface font size, or moved to a typo such as+# `--ui-spcae-scale` that resolves to nothing and takes the fallback.+_SCALED_LENGTH = re.compile(+ r"calc\(\s*(-?[\d.]+(?:px|rem|em))\s*\*\s*var\(\s*--ui-space-scale\s*,\s*1\s*\)\s*\)"+)++# The gains are not declared at all: `appearance-custom-store.ts` sets them only away from+# the default, so both take the `1` fallback here and a colour reads back as its own amount.+# Which gain, though, is load-bearing. The store gives the edge and the wash different spans,+# so a border scaled by the wash renders a colour its contract does not name as soon as the+# contrast setting moves off default. Surfaces take the wash; borders, rings and outlines+# take the edge; each is resolved only under the gain its own role is entitled to.+_SCALED_AMOUNT = re.compile(+ r"calc\(\s*([\d.]+%?)\s*\*\s*var\(\s*--contrast-(edge|wash)-gain\s*,\s*1\s*\)\s*\)"+)+_COLOUR_ROLE = re.compile(+ r"bg-|background(?:-color)?\s*:|border(?:-color)?\s*:"+ r"|border-|ring-|outline-|--tw-ring-color\s*:"+)+++def _gain_owed_to(preceding: str) -> str | None:+ """The gain the colour written after *preceding* is entitled to, if that role is readable."""+ roles = _COLOUR_ROLE.findall(preceding[-200:])+ if not roles:+ return None+ return "wash" if roles[-1].startswith(("bg-", "background")) else "edge"+++def _resolve_amount(source: str, match: "re.Match[str]") -> str:+ """A gain-scaled colour amount, read back only where the gain matches the colour's role."""+ if _gain_owed_to(source[: match.start()]) != match.group(2):+ return match.group(0)+ return match.group(1)+++# The same move in colour. #11459 respelled the opacity shorthands as a colour function+# whose amount scales with a gain, again defaulting to 1: `foreground/10` became a+# `color-mix` of `--foreground` at 10% with transparent, and `white/[0.06]` an `rgb()` at+# 0.06. Those are the shorthands, written out. Reading them back keeps a contract about the+# colour asking about the colour.+#+# The gain has to be there. A colour that keeps the amount but drops the gain renders the+# same thing at the default setting and nothing like it anywhere else, so the two are not+# interchangeable and only the gain-bearing spelling is read back as the shorthand.+_MIXED_TOKEN = re.compile(+ r"\[color-mix\(in_oklab,\s*var\(--([\w-]+)\)_"+ r"calc\(([\d.]+)%\*var\(--contrast-(edge|wash)-gain,\s*1\)\)\s*,\s*transparent\)\]"+)+_WHITE_ALPHA = re.compile(+ r"\[rgb\(255_255_255_/_calc\(([\d.]+)\*var\(--contrast-(edge|wash)-gain,\s*1\)\)\)\]"+)+++def _resolve_mix(source: str, match: "re.Match[str]") -> str:+ """A gain-scaled `color-mix`, read back as its shorthand under its own gain."""+ if _gain_owed_to(source[: match.start()]) != match.group(3):+ return match.group(0)+ amount = match.group(2)+ return f"{match.group(1)}/{amount[:-2] if amount.endswith('.0') else amount}"+++def _resolve_white_alpha(source: str, match: "re.Match[str]") -> str:+ """A gain-scaled white lift, read back as its shorthand under its own gain."""+ if _gain_owed_to(source[: match.start()]) != match.group(2):+ return match.group(0)+ return f"white/[{match.group(1)}]"+++def _at_default_scale(source: str) -> str:+ """*source* with every scale-wrapped length and gain-wrapped colour read back as itself."""+ resolved = _SCALED_LENGTH.sub(r"\1", source)+ resolved = _MIXED_TOKEN.sub(lambda m: _resolve_mix(resolved, m), resolved)+ resolved = _WHITE_ALPHA.sub(lambda m: _resolve_white_alpha(resolved, m), resolved)+ return _SCALED_AMOUNT.sub(lambda m: _resolve_amount(resolved, m), resolved)+++def _ui_source(path) -> str:+ """A checked-in source, read at the default UI scale.++ Every contract in this file is written against fixed lengths. #11458 wrapped those+ lengths in `calc(... * var(--ui-space-scale, 1))` so they follow the UI font size, which+ renders identically at the default scale of 1. Reading through `_at_default_scale` keeps+ each contract asking about the length it was written for instead of the spelling.+ """+ return _at_default_scale(path.read_text(encoding = "utf-8"))+++def _window_chrome_source(path) -> str:+ """A checked-in source, read exactly as written.++ Window chrome does not scale with the interface font size. The custom titlebar is 34px+ because the Tauri window decoration is 34px, and `DesktopChromeVarsEffect` only mirrors+ that number onto `<html>` for the portalled sheets to sit below. Reading that mirror+ through `_ui_source` would accept `calc(34px * var(--ui-space-scale, 1))` as 34px while+ the real titlebar stayed put and every fixed sheet slid off it at a non-default UI size,+ so the chrome is read raw and a scale wrapper fails the contract.+ """+ return path.read_text(encoding = "utf-8")++def _spacing_rem(live_css: str) -> float | None:"""The rem one Tailwind spacing unit is worth, read from the theme's `--spacing`.@@ -1709,8 +1837,8 @@ def _cn_arguments(body: str) -> list[str]:def test_chat_sidebar_row_actions_visible_on_coarse_pointers():"""unslothai/unsloth#7276: Recents chat kebab must be tappable on iPad."""- sidebar_source = APP_SIDEBAR.read_text(encoding = "utf-8")- css_source = INDEX_CSS.read_text(encoding = "utf-8")+ sidebar_source = _ui_source(APP_SIDEBAR)+ css_source = _ui_source(INDEX_CSS)assert "renderChatSidebarItem" in sidebar_sourceblock = sidebar_source.split("function renderChatSidebarItem", 1)[1].split("\n function ", 1)[0@@ -1843,7 +1971,7 @@ def test_chat_sidebar_row_actions_visible_on_coarse_pointers():# in the builder says nothing about the rows that do not take it: moving the verified# pair into `showWorkSpinner ? "...pair..." : undefined` leaves every ordinary row with# no gutter at all while a scan over literals still finds it.- live_css = re.sub(r"/\*.*?\*/", " ", css_source, flags = re.S)+ live_css = _at_default_scale(re.sub(r"/\*.*?\*/", " ", css_source, flags = re.S))spacing = _spacing_rem(live_css)assert spacing is not None, ("index.css does not state one readable --spacing, so this guard cannot convert the "@@ -2213,19 +2341,19 @@ def test_chat_sidebar_row_actions_visible_on_coarse_pointers():def test_media_pages_clear_the_custom_titlebar():"""The chat-style layout gives the media pages no outer inset, so each applies its own."""- root = ROOT_ROUTE.read_text(encoding = "utf-8")+ root = _ui_source(ROOT_ROUTE)assert re.search(r"const isChatLike =\s*isChatRoute \|\| isImagesRoute \|\| isVideoRoute \|\| isAudioRoute;",root,)for page in (IMAGES_PAGE, VIDEO_PAGE):- shell = page.read_text(encoding = "utf-8").split('"diffusion-surface', 1)[1].split(">", 1)[0]+ shell = _ui_source(page).split('"diffusion-surface', 1)[1].split(">", 1)[0]assert "pt-[var(--studio-content-top-inset,0px)]" in shell, page.namedef test_image_page_structural_panes_share_the_container_breakpoint():- source = IMAGES_PAGE.read_text(encoding = "utf-8")+ source = _ui_source(IMAGES_PAGE)shell = source.split('className="diffusion-surface', 1)[1].split(">", 1)[0]section = source.split("Settings column + preview canvas", 1)[1]@@ -2244,7 +2372,7 @@ def test_image_page_structural_panes_share_the_container_breakpoint():def test_audio_page_matches_the_image_rail_header_and_action_footer():- source = AUDIO_PAGE.read_text(encoding = "utf-8")+ source = _ui_source(AUDIO_PAGE)before, marker, after = source.partition("h-[48px] shrink-0")assert markerheader_opening = before.rsplit('<div className="', 1)[1] + marker + after.split(">", 1)[0]@@ -2281,7 +2409,7 @@ def test_audio_page_matches_the_image_rail_header_and_action_footer():def test_image_train_rail_matches_create_and_header():- source = DIFFUSION_TRAIN_PANEL.read_text(encoding = "utf-8")+ source = _ui_source(DIFFUSION_TRAIN_PANEL)layout = source.split("overflow-x-hidden: an unset overflow-x", 1)[1]assert "@[50rem]:flex-row @[50rem]:overflow-hidden" in layout@@ -2293,7 +2421,7 @@ def test_image_train_rail_matches_create_and_header():def test_compact_media_link_keeps_accessible_name_and_truncation():- source = MEDIA_PAGE_LINK.read_text(encoding = "utf-8")+ source = _ui_source(MEDIA_PAGE_LINK)button = source.split("<button", 1)[1].split("</button>", 1)[0]assert "aria-label={label}" in button@@ -2304,7 +2432,7 @@ def test_compact_media_link_keeps_accessible_name_and_truncation():def test_media_page_link_tooltip_drops_below_titlebar_controls():"""unslothai/unsloth#10226: Images/Video park this link in the top-right header besideWindows controls; a top tooltip blocks minimize/maximize/close."""- source = MEDIA_PAGE_LINK.read_text(encoding = "utf-8")+ source = _ui_source(MEDIA_PAGE_LINK)tooltip = source.split("<TooltipContent", 1)[1].split("</TooltipContent>", 1)[0]assert 'side="bottom"' in tooltip@@ -2314,7 +2442,7 @@ def test_media_page_link_tooltip_drops_below_titlebar_controls():def test_media_page_headers_out_stack_the_mac_drag_region():"""macOS insets the media pages 0px, so their 48px header overlaps the navbar's 34px dragstrip: the band must out-stack it yet stay click-through (controls click, gaps drag)."""- navbar = NAVBAR.read_text(encoding = "utf-8")+ navbar = _ui_source(NAVBAR)# The strip to beat: same z-40, but earlier in DOM order.assert "pointer-events-none absolute inset-x-0 top-0 z-40 h-[48px]" in navbar@@ -2326,7 +2454,7 @@ def test_media_page_headers_out_stack_the_mac_drag_region():(VIDEO_PAGE, "MediaPageLink", 2),(AUDIO_PAGE, "PillTabs", 2),):- source = page.read_text(encoding = "utf-8")+ source = _ui_source(page)# matched on the band's size alone: Images lays its header out as a grid and Video as a# flex row, so the stacking contract below is what this pins, not one layout's utilities.before, marker, band = source.partition("h-[48px] shrink-0")@@ -2344,7 +2472,7 @@ def test_media_page_headers_out_stack_the_mac_drag_region():def test_images_header_tracks_preview_and_preserves_titlebar_controls():- source = IMAGES_PAGE.read_text(encoding = "utf-8")+ source = _ui_source(IMAGES_PAGE)before, marker, after = source.partition("h-[48px] shrink-0")assert markeropening = before.rsplit("<div", 1)[1] + marker + after.split(">", 1)[0]@@ -2375,7 +2503,7 @@ def test_images_header_tracks_preview_and_preserves_titlebar_controls():def test_a_stopped_repair_update_is_recorded_as_canceled_not_failed():"""unslothai/unsloth#7793: the support report prints final_status verbatim, so auser quitting mid-update must not read as a failed repair."""- source = TAURI_COMMANDS.read_text(encoding = "utf-8")+ source = _ui_source(TAURI_COMMANDS)stopped_arm = source.split("if msg == update::UPDATE_STOPPED", 1)[1].split("return Err(msg);", 1)[0]@@ -2383,3 +2511,164 @@ def test_a_stopped_repair_update_is_recorded_as_canceled_not_failed():call = stopped_arm.split("finish_repair_group(", 1)[1].split(");", 1)[0]assert '"canceled"' in callassert '"failed"' not in call+++# Every geometry contract above reads its lengths through `_ui_source`, which answers with+# the length at the default scale. That is the same 48px whether the source still scales the+# band or has gone back to a bare `h-[48px]`, so no contract that measures the band can tell+# those apart, and none of them should have to: the scaling is a separate claim and it is+# stated here. Each row is a length one of those contracts measures, with how many times the+# file states it. Unwrap one and this fails, rather than every contract downstream of it+# passing while the layout has stopped following the interface font size.+#+# The variant is part of the claim, so each row carries its own. `h-[...]` and+# `hover:h-[...]` are different guarantees, and the second one is not a fixed band at all.+_LENGTHS_THAT_MUST_KEEP_THE_SCALE = (+ (NAVBAR, "", "h", "48px", 2),+ (IMAGES_PAGE, "", "h", "48px", 1),+ (AUDIO_PAGE, "", "h", "48px", 1),+ (VIDEO_PAGE, "", "h", "48px", 1),+ (CHAT_PAGE, "", "h", "48px", 1),+ (IMAGES_PAGE, "@[50rem]:", "pt", "60px", 1),+ (AUDIO_PAGE, "@[50rem]:", "pt", "60px", 2),+ (DIFFUSION_TRAIN_PANEL, "@[50rem]:", "pt", "42px", 1),+ (DIFFUSION_TRAIN_PANEL, "", "pt", "42px", 1),+ # The sidebar row: its height, the gap it sets when pinned, and the indent a project row+ # takes. These are hand-set one-off lengths, which is exactly the spacing that used to+ # stay put while the labels grew, so the row clips its own text at a larger setting.+ (APP_SIDEBAR, "", "h", "30px", 5),+ (APP_SIDEBAR, "", "gap", "8.5px", 6),+ (APP_SIDEBAR, "", "pl", "39px", 2),+ # The 34px pill controls in the media headers, in all three spellings the pages use. The+ # band around them scales and so does their own text, so a control left fixed is the one+ # thing in that row that does not move, and it crowds out its label.+ (IMAGES_PAGE, "!", "h", "34px", 2),+ (IMAGES_PAGE, "", "h", "34px", 1),+ (IMAGES_PAGE, "[&>button]:", "h", "34px", 1),+ (AUDIO_PAGE, "!", "h", "34px", 1),+ (AUDIO_PAGE, "", "h", "34px", 1),+ (AUDIO_PAGE, "[&>button]:", "h", "34px", 1),+ (VIDEO_PAGE, "!", "h", "34px", 2),+ # The chat page's 30px round controls, including the collapsed New Chat button. The+ # header they sit in grows with the setting, so one left fixed shrinks against its own row.+ (CHAT_PAGE, "!", "size", "30px", 1),+ (CHAT_PAGE, "", "size", "30px", 3),+)++# Where a class may begin: the start of the string it is written in, or the space after the+# one before it. Anchoring on "not a word character" is not enough, because `:` is not one:+# it lets `hover:h-[...]` answer for `h-[...]`, and a height that only applies under the+# pointer is not the fixed band any of these contracts measure.+_CLASS_STARTS = r"(?:(?<=[\s\"'`])|^)"+# And where it may end. A trailing `:broken` is not a suffix on the utility, it is a+# different candidate entirely: Tailwind emits nothing for it, while the normalised source+# still shows the length this file asks about.+_CLASS_ENDS = r"(?=[\s\"'`]|$)"+++# The same blind spot in colour, and it needs the same answer. `_MIXED_TOKEN` reads a+# gain-scaled `color-mix` back as its shorthand, so a contract asking for+# `border-foreground/10` is satisfied by either the scaled spelling or a literal+# `border-foreground/10` that has lost the gain and stopped responding to the contrast+# setting. The reader cannot tell them apart by design, so the gain is stated here.+_COLOURS_THAT_MUST_KEEP_THEIR_GAIN = ((IMAGES_PAGE, "border", "--foreground", "10", "edge", 1),)+++# The stylesheet needs the same statement. `_spacing_rem` and the pin arithmetic read+# `index.css` through `_ui_source`, which answers with the length at the default scale, so a+# scale wrapper and a bare rem are the same number to every one of those contracts. These two+# declarations are the pin's own geometry: the Tailwind gutter they are compared against+# follows `--spacing`, so a fixed `right` or `padding-right` drifts away from it at any+# setting other than the default, and the reach arithmetic that decides whether the pin can+# overlap the title is done against a number the UI no longer renders.+_CSS_DECLARATIONS_THAT_MUST_KEEP_THE_SCALE = (+ ("right", "1.875rem", 1),+ ("padding-right", "0.125rem", 1),+)+++# The chat header geometry is stated once per platform chrome, and the contracts that do+# arithmetic on it read the provider through `_ui_source`. So a header height that has gone+# back to a bare `44px` reads as 44px, exactly what the arithmetic wants, while the padding+# and the control height beside it still scale. Above the default they grow and it does not,+# their sum passes the header, and the shared titlebar row is clipped. Every declaration of+# these three is checked, not the first one found: they are written out once per chrome, and+# a guard that stops at the first reads one platform and answers for all of them.+_CHAT_GEOMETRY_THAT_MUST_KEEP_THE_SCALE = (+ "--studio-chat-header-height",+ "--studio-chat-header-padding-top",+ "--studio-chat-control-height",+)+++def test_every_platform_chat_header_geometry_still_follows_the_ui_scale():+ source = APP_PROVIDER.read_text(encoding = "utf-8")+ blocks = dict(re.findall(r"const (\w+_CHROME_STYLE) = \{(.*?)\n\}", source, re.S))+ assert len(blocks) >= 2, f"the provider states {sorted(blocks)}, so a chrome has gone missing"+ # Per block, not across the file: the chromes are alternatives, and one of them holding a+ # declaration says nothing about the other. Dropping all three from the custom chrome+ # leaves its users on the root geometry rather than the padding and control height this+ # row is laid out against, while the mac block's copies answer for it in a global search.+ for chrome, body in blocks.items():+ for name in _CHAT_GEOMETRY_THAT_MUST_KEEP_THE_SCALE:+ stated = re.findall(rf'"{re.escape(name)}":\s*"([^"]+)"', body)+ assert stated, f"{chrome} no longer states {name}"+ for value in stated:+ assert re.fullmatch(+ r"calc\(\s*[\d.]+px\s*\*\s*var\(\s*--ui-space-scale\s*,\s*1\s*\)\s*\)",+ value,+ ), f"{chrome} states {name} as {value!r}, which stays put while the row grows"+++def test_the_sidebar_action_geometry_still_follows_the_ui_scale():+ source = INDEX_CSS.read_text(encoding = "utf-8")+ for prop, length, expected in _CSS_DECLARATIONS_THAT_MUST_KEEP_THE_SCALE:+ scaled = len(+ re.findall(+ rf"(?<![\w-]){re.escape(prop)}:\s*"+ rf"calc\(\s*{re.escape(length)}\s*\*\s*var\(\s*--ui-space-scale\s*,\s*1\s*\)\s*\);",+ source,+ )+ )+ assert (+ scaled == expected+ ), f"index.css states {scaled} scaled `{prop}: {length}`, not {expected}"+ assert not re.search(+ rf"(?<![\w-]){re.escape(prop)}:\s*{re.escape(length)}\s*;", source+ ), f"index.css has a bare `{prop}: {length}`, which stays put while the gutter scales"+++def test_the_colours_these_contracts_read_still_carry_their_gain():+ for path, utility, colour, amount, gain, expected in _COLOURS_THAT_MUST_KEEP_THEIR_GAIN:+ source = path.read_text(encoding = "utf-8")+ scaled = (+ f"{utility}-[color-mix(in_oklab,var({colour})_"+ f"calc({amount}%*var(--contrast-{gain}-gain,1)),transparent)]"+ )+ found = len(re.findall(_CLASS_STARTS + re.escape(scaled) + _CLASS_ENDS, source))+ assert found == expected, (+ f"{path.name} states {found} gain-scaled {utility} {colour} at {amount}%, "+ f"not {expected}"+ )+ bare = f"{utility}-{colour.removeprefix('--')}/{amount}"+ assert not re.search(+ _CLASS_STARTS + re.escape(bare) + _CLASS_ENDS, source+ ), f"{path.name} has a bare {bare}, which stops following the contrast setting"+++def test_the_lengths_these_contracts_measure_still_follow_the_ui_scale():+ for path, variant, utility, length, expected in _LENGTHS_THAT_MUST_KEEP_THE_SCALE:+ source = path.read_text(encoding = "utf-8")+ named = f"{variant}{utility}-{length}"+ scaled = len(+ re.findall(+ _CLASS_STARTS+ + re.escape(f"{variant}{utility}-[calc({length}*var(--ui-space-scale,1))]")+ + _CLASS_ENDS,+ source,+ )+ )+ assert scaled == expected, f"{path.name} states {scaled} scaled {named}, not {expected}"+ assert not re.search(+ _CLASS_STARTS + re.escape(f"{variant}{utility}-[{length}]") + _CLASS_ENDS, source+ ), f"{path.name} has a bare {named}, which stays put while its text grows"diff --git a/tests/studio/test_update_release_notes.py b/tests/studio/test_update_release_notes.pyindex 0e1a603d554..10aa3438c94 100644--- a/tests/studio/test_update_release_notes.py+++ b/tests/studio/test_update_release_notes.py@@ -945,8 +945,21 @@ def test_notes_surface_is_borderless_and_lifts_in_dark_mode():src = PANEL.read_text(encoding = "utf-8")layout = NOTES_LAYOUT.read_text(encoding = "utf-8")assert "border border-border" not in src, "the notes box is a fill, not a bordered box"- # Lighter than the card behind it, rather than a darker inset.- assert "dark:bg-white/[0.06]" in layout+ # Lighter than the card behind it, rather than a darker inset. #11459 respelled the+ # shorthand as an rgb() whose alpha scales with --contrast-wash-gain, which is the same+ # 0.06 white at the default gain of 1, so read the white and the amount rather than one+ # spelling. A darker inset, or a different amount, still fails. The class also has to end+ # where the match does, and start where it starts. Anything else and Tailwind reads a+ # different candidate than the one named here: `-broken` names no utility at all, `/50`+ # is a different lift, `:broken` is a variant on nothing, and a `hover:` in front paints+ # the lift only under the pointer instead of on the dark surface.+ assert re.search(+ r"(?:(?<=[\s\"'`])|^)"+ r"dark:bg-(?:white/\[0\.06\]"+ r"|\[rgb\(255_255_255_/_calc\(0\.06\*var\(--contrast-wash-gain,\s*1\)\)\)\])"+ r"(?=[\s\"'`]|$)",+ layout,+ ), "the dark notes surface is no longer a 0.06 white lift"# Streamdown's mt-6 clips the first heading against the scroller edge.assert "[&>*>*:first-child]:mt-0" in src# Shared utility: thumb hidden until the notes are hovered.