From 75bb1899fc6a67abbf3e4c833925ad2e33ad1a26 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Tue, 29 Sep 2026 18:18:49 +0200 Subject: [PATCH] test: Count Derived Scrim Tokens as Theme-Owned (#16512) The stylesheet-ownership check added in #16480 required every declared color token to be a theme key of its own, so the scrim tokens from #16492, which compose the surface-overlay role with a scrim opacity role, failed it once both landed on canary. A token is now owned when a variable its value reads is one a theme can set. --- packages/client/src/theme/tokens.spec.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/client/src/theme/tokens.spec.ts b/packages/client/src/theme/tokens.spec.ts index 3a6c4890b2..5741d8a39c 100644 --- a/packages/client/src/theme/tokens.spec.ts +++ b/packages/client/src/theme/tokens.spec.ts @@ -11,11 +11,15 @@ globalThis.structuredClone ??= (value: T): T => deserialize(serialize(value)) const tokensPath = path.resolve(__dirname, 'tokens.css'); const tokens = fs.readFileSync(tokensPath, 'utf8'); -const declared = new Set( - Array.from(tokens.matchAll(/--color-([\w-]+):/g), (match) => match[1]).filter( - (name) => !name.endsWith('*'), - ), +/** Each declared color token, mapped to the custom properties its value reads. */ +const declarations = new Map( + Array.from( + tokens.matchAll(/--color-([\w-]+):([^;]+);/g), + ([, name, value]) => + [name, Array.from(value.matchAll(/var\(--([\w-]+)/g), (match) => match[1])] as const, + ).filter(([name]) => !name.endsWith('*')), ); +const declared = new Set(declarations.keys()); /** * Theme properties consumed by stylesheets rather than by utilities: the shimmer animation and @@ -70,7 +74,9 @@ describe('theme color tokens', () => { it('lets a theme set every color token the stylesheet declares', () => { const registered = new Set(Object.keys(defaultTheme).map((key) => key.replace(/^rgb-/, ''))); - const unowned = [...declared].filter((token) => !registered.has(token)); + const unowned = [...declarations] + .filter(([, reads]) => !reads.some((property) => registered.has(property))) + .map(([token]) => token); expect(unowned).toEqual([]); });