unsloth/tests/studio/test_studio_text_descender_clipping.py
Michael Han 8aaf2f78eb
Studio: drive UI font size through a typography scale instead of the root font size (#7359)
* Studio: drive UI font size through a typography scale, not the root font size

Follow up to #7355. The preference now writes --ui-font-scale
(selected / 16) and a data-ui-font-size attribute on the root instead
of mutating the root font size, and the applier clears any stale inline
root font-size left by older builds. Because the rem base never moves,
every layout-only rem-to-px conversion from #7355 is reverted to its
original form: the spacing, radius and container tokens, sidebar and
thread widths, grid tracks, calc margins and hub.css dimensions match
pre-#7355 main again, which also restores rem-based accessibility
scaling for users with a larger browser default font size.

Typography scales through tokens in index.css, all exact at 16px:

- The named Tailwind sizes (--text-xs through --text-4xl) multiply
  their defaults by the scale, so standard utilities scale
- One token per design px size (--text-ui-8 ... --text-ui-34) replaces
  every arbitrary text-[Npx] class; leading-ui-* mirrors the exact
  line heights and the numeric --leading-3..10 scale as well
- CSS font-size and line-height declarations multiply by the scale
- Chart labels scale through a .recharts-text rule; streamdown and
  react-flow px text is re-based via scaled overrides; KaTeX's 1px
  layout trick stays fixed by design
- The logo lockups keep their half-rate behavior via the scale var
- The explicit Code font size remains unmultiplied

Keeps the #7355 behavior fixes: color chip min width, voice select
min/max widths, and the select and dropdown menus scrolling an inner
viewport so their corners stay rounded. The whitespace-password and
IME rename guards that merged alongside are preserved.

* Studio: contract and Playwright coverage for the UI font size scale

test_ui_font_scale_contract.py pins the mechanism (scale var written,
root font size never mutated, tokens scaled, code font size not
multiplied, the Radix select viewport owning scroll state) and guards
against new raw pixel typography, with a documented allowlist for the
recharts fontSize props covered by the stylesheet override and the
offscreen clipboard textarea.

playwright_ui_font_scale.py drives the real appearance controls: root
font size fixed at 12/16/20, text and line height scale by size/16,
sidebar width invariant, explicit code font size stays fixed, an
overflowing dictation select scrolls its Radix viewport by keyboard
and wheel, and the default restores exactly. Wired into the UI smoke
workflow against the second studio boot.

The thinking-compact and descender contracts move back to the rem and
token forms now that layout values no longer need px pinning.
2026-07-23 01:26:56 -07:00

69 lines
2.4 KiB
Python

"""Regression guard: Unsloth text spans must not pair `leading-none` with
`truncate`, which clips glyph descenders (g, p, q, y, j) in visible labels.
"""
from __future__ import annotations
import re
from pathlib import Path
WORKDIR = Path(__file__).resolve().parents[2]
MODEL_SELECTOR = (
WORKDIR
/ "studio"
/ "frontend"
/ "src"
/ "features"
/ "model-picker"
/ "components"
/ "model-selector.tsx"
)
APP_SIDEBAR = WORKDIR / "studio" / "frontend" / "src" / "components" / "app-sidebar.tsx"
def _read(path: Path) -> str:
assert path.exists(), f"missing source file: {path}"
return path.read_text()
def test_model_selector_trigger_label_uses_leading_tight():
src = _read(MODEL_SELECTOR)
pattern = re.compile(
r'<span\s+className="[^"]*\bmin-w-0\b[^"]*\bflex-1\b[^"]*\btruncate\b[^"]*\bfont-heading\b[^"]*\btext-ui-16[^"]*"',
)
matches = pattern.findall(src)
assert matches, "could not find ModelSelectorTrigger model-name span"
for cls in matches:
assert "leading-tight" in cls, f"expected leading-tight, got: {cls}"
assert "leading-none" not in cls, f"leading-none must not coexist with truncate here: {cls}"
def test_sidebar_account_block_uses_leading_tight():
src = _read(APP_SIDEBAR)
class_names = re.findall(r'<div\s+className="([^"]+)"', src)
required = {
"flex",
"flex-1",
"flex-col",
"group-data-[collapsible=icon]:hidden",
}
matches = [classes for classes in class_names if required <= set(classes.split())]
assert matches, "could not find sidebar account-block parent div"
for classes in matches:
leading_classes = [cls for cls in classes.split() if cls.startswith("leading-")]
assert leading_classes, f"no leading-* class on sidebar account-block parent: {classes}"
for cls in leading_classes:
assert (
cls == "leading-tight"
), f"sidebar account-block must use leading-tight, got: {cls}"
def test_no_truncate_plus_leading_none_in_changed_files():
for path in (MODEL_SELECTOR, APP_SIDEBAR):
src = _read(path)
for line in src.splitlines():
if "truncate" in line and "leading-none" in line:
raise AssertionError(
f"{path.name}: same line uses truncate + leading-none, descenders will clip: {line.strip()}"
)