Skip to content

Assert chat tracking in em, not in pixels at a 16px base - #7826

Merged
danielhanchen merged 1 commit into
mainfrom
fix/chat-typography-follows-font-scale
Aug 4, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/chat-typography-follows-font-scale

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Chat UI Tests has been red on main since aa4e6af, on both macOS and Linux runners:

macOS  [ui] FAIL: chat letter spacing theme-cycle-1/assistant: expected 0.31px,   got 0.290625px
Linux  [ui] FAIL: chat letter spacing theme-cycle-1/assistant: expected 0.3565px, got 0.334219px

Both are exactly 15/16 of what the test wanted, and the reason is in the product source:

/* The authored typography tokens use a 16px CSS base; the product default
   is 15px. An explicit user preference overrides this inline. */
--ui-font-scale: 0.9375;

The chat message roots carry text-ui-15p5 (0.96875rem) and tracking-[0.01em] dark:tracking-[0.02em], with 0.023em for the lighter dark-mode instance on Linux. Tracking authored in em resolves against the element's own size, so when the default base moved from 16px to 15px every computed value scaled with it: 0.02em of 15.5px is 0.31px, and 0.02em of 14.53125px is 0.290625px. The product is correct; the test was pinning the product of a tracking value and a base it did not measure.

So this reads the size off the element and asserts the em:

expected_spacing = expected_em * font_size

Checked against every real observation, including the ones from before the default changed:

case em size expected reported
macOS dark, 15px default 0.02 14.53125px 0.290625px 0.290625px
Linux dark, 15px default 0.023 14.53125px 0.334219px 0.334219px
macOS dark, 16px base 0.02 15.5px 0.31px 0.31px
Linux dark, 16px base 0.023 15.5px 0.3565px 0.3565px
light mode, either base 0.01 15.5 / 14.53125px 0.155 / 0.145313px matches

It also passes under a user font-size preference (20px, scale 1.25) rather than only at the default, which the pinned values never could. The tolerance is 0.005px, sub-pixel on purpose: substituting a genuinely wrong tracking (0.01em or 0.023em where 0.02em is required) still fails, so the check keeps its teeth.

Test-only change, no product code touched.

The chat typography check pinned letter-spacing as px, computed against a 16px
CSS base. aa4e6af set the product default to 15px (--ui-font-scale: 0.9375), so
every computed value became 15/16 of the pinned one and Chat UI Tests has failed
on main since, on both macOS and Linux:

  macOS  expected 0.31px,   got 0.290625px
  Linux  expected 0.3565px, got 0.334219px

The tracking is authored in em, so read the size off the element and assert the
em. That holds at either base and under a user font-size preference, and still
catches a tracking value that is actually wrong.
@danielhanchen
danielhanchen merged commit d303cd7 into main Aug 4, 2026
19 of 21 checks passed
@danielhanchen
danielhanchen deleted the fix/chat-typography-follows-font-scale branch August 4, 2026 08:49
danielhanchen added a commit that referenced this pull request Aug 4, 2026
…7828)

* test(studio): bound the chat font size and accept a normal tracking

Two follow-ups to #7826, which is otherwise the right fix.

Asserting the em means the font size itself is no longer checked. The px literal
it replaced caught that implicitly, since 0.3565px only matched at 15.5px, so the
check quietly lost the ability to notice chat text rendering at the wrong size.
Bounding the size to 12-18px restores a coarse version of that: a deliberate
scale change or a user font-size preference passes, chat text at a caption or
heading size does not.

float("normal") also raises, and "normal" is how a browser reports a zero
tracking, so that path would surface as a test error rather than as this check
failing with its own message.

Exercised against the values that occur: the three current theme branches, the
pre-#7359 15.5px body, a raised user preference, a zero tracking spelled
"normal", a wrong tracking, and chat text at caption and heading sizes. Only the
last three fail, each with the message that names the cause.

* Assert the chat size token rather than a range

Both review points, and they are the same finding from two sides: a range is
wrong at the edges and useless in the middle.

UI_FONT_SIZE_RANGE is 12 to 20 and the store sets --ui-font-scale to
preference / 16, so text-ui-15p5 spans 11.625px to 19.375px. The 12-18px bound
rejected both endpoints, failing a UI that is rendering its configured size
correctly. At the default scale it also admitted text-ui-13 at 12.1875px and
text-ui-18 at 16.875px, so the token swap it was meant to catch passed, and the
tracking assertion passed with it because the expectation derives from the same
measured size.

So read --ui-font-scale off the root and assert the size is text-ui-15p5 at that
scale. That holds at every supported preference and pins the token, which is what
the check was for.

Exercised at preferences 12, 15 and 20, at the pre-#7359 base, with a zero
tracking spelled "normal", against swaps to text-ui-13 and text-ui-18, and
against a wrong tracking. The three intended failures fail, each naming its
cause.

* Tighten the size-assertion comment

Post-convergence comment pass. The embedded JavaScript comment is left alone: it
sits inside a Python string literal, so editing it is a code change and the
comment-only gate correctly rejects it.

* test(studio): match the UI font size default the store actually uses

The font-scale test drove the size input to 16 and then asserted that
data-ui-font-size had been dropped, but the store only removes the
attribute at UI_FONT_SIZE_RANGE.default, which is 15. The static
--ui-font-scale of 0.9375 in index.css is the same 15/16.

* Tighten typography test comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant