Studio UI font-scale test: normalise paths so the allowlists work on Windows (#7434)

test_inline_font_size_styles_reference_the_scale compares source-relative paths
against FONTSIZE_PROP_ALLOWED_DIRS and FONTSIZE_STYLE_ALLOWLIST, both written
with forward slashes. It built those paths with str(path.relative_to(SRC)),
which is backslash-separated on Windows, so startswith() never matched and the
allowlists silently did nothing.

The suite is green on Linux CI and fails locally on Windows with 22 phantom
offenders, all of them the chart cards the allowlist already covers.

Route the paths through a _rel() helper that returns .as_posix(), and use it for
the other two offender messages too so failures read the same on every OS.
This commit is contained in:
Leo Borcherding 2026-07-27 12:39:35 -05:00 committed by GitHub
commit f4d2cc5ca3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -39,6 +39,17 @@ def _frontend_sources():
yield path
def _rel(path):
"""Source-relative path with forward slashes on every OS.
The allowlists above are written with "/", so a plain str(relative_to(SRC))
silently stops matching on Windows and every allowlisted file reports as an
offender. Keeping the separator normalised here also keeps failure messages
identical across platforms.
"""
return path.relative_to(SRC).as_posix()
def test_preference_writes_a_scale_not_the_root_font_size():
assert 'setVar("--ui-font-scale"' in STORE
assert 'el.setAttribute("data-ui-font-size"' in STORE
@ -136,7 +147,7 @@ def test_no_raw_pixel_text_utilities():
for path in _frontend_sources():
text = path.read_text(encoding = "utf-8")
for m in re.finditer(r"(?<![\w-])(?:text|leading)-\[[0-9.]+px\]", text):
offenders.append(f"{path.relative_to(SRC)}: {m.group(0)}")
offenders.append(f"{_rel(path)}: {m.group(0)}")
assert offenders == [], (
"Raw px text utilities ignore the UI font size preference; use the "
f"text-ui-* / leading-ui-* tokens in index.css instead: {offenders[:10]}"
@ -157,7 +168,7 @@ def test_css_font_sizes_reference_the_scale():
continue
if "1px" in decl:
continue # library layout tricks (KaTeX-style), not text
offenders.append(f"{path.relative_to(SRC)}: {decl.strip()[:80]}")
offenders.append(f"{_rel(path)}: {decl.strip()[:80]}")
assert offenders == [], (
"CSS typography must multiply by var(--ui-font-scale, 1) or be "
f"allowlisted here with a reason: {offenders[:10]}"
@ -167,7 +178,7 @@ def test_css_font_sizes_reference_the_scale():
def test_inline_font_size_styles_reference_the_scale():
offenders = []
for path in _frontend_sources():
rel = str(path.relative_to(SRC))
rel = _rel(path)
if rel in FONTSIZE_STYLE_ALLOWLIST:
continue
text = path.read_text(encoding = "utf-8")