Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(design-tokens): 拒绝运行期像素绑定的符号别名并修复 Windows 路径断言
Kirozeng4f2964bc2595
diff --git a/packages/design-tokens/src/__tests__/classification.test.ts b/packages/design-tokens/src/__tests__/classification.test.tsindex 20fbb3bd55..11ed62253a 100644--- a/packages/design-tokens/src/__tests__/classification.test.ts+++ b/packages/design-tokens/src/__tests__/classification.test.ts@@ -1,6 +1,6 @@import { execFileSync } from 'node:child_process';import { readFileSync } from 'node:fs';-import { relative } from 'node:path';+import { join, relative } from 'node:path';import { describe, expect, it } from 'vitest';import {@@ -47,7 +47,10 @@ describe('DS-3 · 分类登记', () => {it('生产生成结果与磁盘字节一致;fixture 仅用于独立分类预期', async () => {const files = await buildProductionFiles(repoRoot);- expect(files.some(file => file.path.endsWith('themes/colors.ts'))).toBe(true);+ // Windows 上 buildProductionFiles 返回的分隔符是 `\`,期望路径必须用+ // join 构造(跨平台路径宪法),不能写死 `/` 后缀。+ const colorsPath = join(repoRoot, 'apps/desktop/src/renderer/themes/colors.ts');+ expect(files.some(file => file.path === colorsPath)).toBe(true);for (const file of files) expect(readFileSync(file.path, 'utf8')).toBe(file.body);}, 30_000); // Real Terrazzo build; allow CPU contention with the workspace suite.diff --git a/packages/design-tokens/src/__tests__/production.test.ts b/packages/design-tokens/src/__tests__/production.test.tsindex eab0ef6add..2527994bc0 100644--- a/packages/design-tokens/src/__tests__/production.test.ts+++ b/packages/design-tokens/src/__tests__/production.test.ts@@ -88,8 +88,8 @@ describe("DS-8 production source", () => {];writeFileSync(sourcePath, JSON.stringify(source));const changed = await buildProductionFiles(dir);- const colors = changed.find((f) =>- f.path.endsWith("themes/colors.ts"),+ const colors = changed.find(+ (f) => f.path === join(dir, "apps/desktop/src/renderer/themes/colors.ts"),)!.body;expect(colors).toContain('"light": "#1a334d"');expect(colors).toContain('"light": "var(--surface)"');@@ -188,7 +188,7 @@ describe("DS-8 production source", () => {).toBe(false);});- it("rejects illegal types, missing modes, reversed aliases, missing references, color overflow and disconnected CSS aliases", () => {+ it("rejects illegal types, missing modes, reversed aliases, missing references, color overflow, disconnected CSS aliases and CSS aliases on runtime pixel bindings", () => {const source = loadSource();expect(() => validateProduction(source, bindings)).not.toThrow();const mutate = (@@ -240,6 +240,20 @@ describe("DS-8 production source", () => {mutate((t) => {t["reference.foundations.text-13"].$value = { value: 1, unit: "rem" };}, /Runtime pixel binding/);+ // A legal-looking CSS alias on a runtime pixel binding would make+ // formatToken() emit `var(--…)`, whose parseFloat silently becomes NaN in+ // token-mappings.ts (numeric/text/lineHeight) and appearance-tokens.ts+ // (defaults). The generator must reject it instead.+ mutate((t) => {+ t["semantic.foundations.text-13"].$extensions = {+ "com.cindy.desktop": { cssAlias: "font-size-13", wrapper: "var" },+ };+ }, /Runtime pixel binding cannot use a CSS alias/);+ mutate((t) => {+ t["semantic.foundations.app-ui-font-size"].$extensions = {+ "com.cindy.desktop": { cssAlias: "app-ui-font-size", wrapper: "var" },+ };+ }, /Runtime pixel binding cannot use a CSS alias/);const badTheme = structuredClone(bindings);(badTheme.themes["default-dark.ts"] as { type: string }).type = "night";expect(() => validateProduction(source, badTheme)).toThrow(diff --git a/packages/design-tokens/src/production.ts b/packages/design-tokens/src/production.tsindex df8c28d6a7..742f74365d 100644--- a/packages/design-tokens/src/production.ts+++ b/packages/design-tokens/src/production.ts@@ -223,9 +223,13 @@ export function validateProduction(}// These mappings enter the existing runtime scale calculation as numbers.// Other CSS dimensions may use rem, but dropping that unit here would turn- // (for example) 1rem into 1px after applyFontSettings runs.+ // (for example) 1rem into 1px after applyFontSettings runs. Symbolic aliases+ // must be rejected as well: formatToken() would emit `var(--…)`, and the+ // parseFloat in generate.ts would silently bake NaN into the mappings.for (const family of ["numeric", "text", "lineHeight", "defaults"] as const) {for (const id of Object.values(bindings.foundations[family])) {+ if (tokens[id].$extensions?.[EXTENSION]?.cssAlias)+ throw new Error(`Runtime pixel binding cannot use a CSS alias: ${id}`);const value = referenceToken(id, tokens);if (value.$type !== "dimension" ||