Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(design-system): DS-10 间距绑定目标须存在于 DTCG 源
Kirozeng373d435a5bd5
diff --git a/scripts/__tests__/hardcoded-color-audit.test.mjs b/scripts/__tests__/hardcoded-color-audit.test.mjsindex f6c97aae2f..cae3dcce61 100644--- a/scripts/__tests__/hardcoded-color-audit.test.mjs+++ b/scripts/__tests__/hardcoded-color-audit.test.mjs@@ -205,8 +205,11 @@ test('worktree includes staged, unstaged and untracked source; commit mode exclufs.copyFileSync(path.join(root, 'scripts', rel), target);}const bindings = 'packages/design-tokens/src/desktop-bindings.json';+ const dtcg = 'packages/design-tokens/src/semantic/foundations.json';fs.mkdirSync(path.dirname(path.join(temp, bindings)), {recursive:true});fs.copyFileSync(path.join(root, bindings), path.join(temp, bindings));+ fs.mkdirSync(path.dirname(path.join(temp, dtcg)), {recursive:true});+ fs.copyFileSync(path.join(root, dtcg), path.join(temp, dtcg));const cli = (...args) => spawnSync(process.execPath, ['scripts/hardcoded-color-audit.mjs', ...args], {cwd:temp,encoding:'utf8'});const failed = cli('--base-ref',commit,'--worktree','--json');assert.equal(failed.status,1,failed.stderr);@@ -239,13 +242,23 @@ test('worktree includes staged, unstaged and untracked source; commit mode excluassert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);fs.writeFileSync(path.join(temp,bindings),'{"foundations":{"css":{"text":"semantic.foundations.text-14"}}}');assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);+ // A prefix-correct but non-existent target must not invent a real source:+ // the binding has to resolve against the DTCG generation source.+ const poisoned = JSON.parse(fs.readFileSync(path.join(root, bindings), 'utf8'));+ poisoned.foundations.css['space-typo'] = 'semantic.foundations.space-typo';+ fs.writeFileSync(path.join(temp,bindings), JSON.stringify(poisoned));+ assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);fs.copyFileSync(path.join(root, bindings), path.join(temp, bindings));+ fs.rmSync(path.join(temp,dtcg));+ assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);+ fs.copyFileSync(path.join(root, dtcg), path.join(temp, dtcg));fs.appendFileSync(path.join(temp,file), '\nconst spacing = "gap-x-[var(--space-4)]";\n');const reported = cli('--base-ref',commit,'--worktree','--report','--json');assert.equal(reported.status,0,reported.stderr);const report = JSON.parse(reported.stdout);assert.equal(report.findings.find(f=>f.rule==='role-spacing')?.classification,'spacing-source-reference');assert.match(report.scriptHashes[bindings],/^[a-f0-9]{64}$/);+ assert.match(report.scriptHashes[dtcg],/^[a-f0-9]{64}$/);fs.writeFileSync(path.join(temp,bindings),'{bad json');assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);fs.rmSync(path.join(temp,bindings));diff --git a/scripts/hardcoded-color-audit.mjs b/scripts/hardcoded-color-audit.mjsindex 1f03ee6109..8d5e08d509 100644--- a/scripts/hardcoded-color-audit.mjs+++ b/scripts/hardcoded-color-audit.mjs@@ -185,7 +185,8 @@ export function audit({ root = ROOT, baseRef = 'origin/main', headRef = 'HEAD',}const scripts = ['scripts/hardcoded-color-audit.mjs', 'scripts/shared/hardcoded-color-match.mjs','scripts/shared/design-layer-report.mjs', 'scripts/hardcoded-color-exemptions.json',- 'packages/design-tokens/src/desktop-bindings.json'];+ 'packages/design-tokens/src/desktop-bindings.json',+ 'packages/design-tokens/src/semantic/foundations.json'];const scriptHashes = Object.fromEntries(scripts.map(f => [f, hash(fs.readFileSync(path.join(f === 'scripts/hardcoded-color-exemptions.json' ? root : ROOT, f)))]));const colors = findings.filter(f => f.rule === 'bare-color');return { schemaVersion: 1, base, head, candidate: worktree ? 'worktree (staged + unstaged + untracked)' : 'commit',diff --git a/scripts/shared/design-layer-report.mjs b/scripts/shared/design-layer-report.mjsindex ff773390c6..ebe4c118a2 100644--- a/scripts/shared/design-layer-report.mjs+++ b/scripts/shared/design-layer-report.mjs@@ -10,13 +10,23 @@ export function getSpacingVariables() {if (!foundations?.css || typeof foundations.css !== 'object' || Array.isArray(foundations.css)) {throw new Error('Invalid desktop-bindings.json; expected foundations.css as a non-array mapping');}- spacingVariables = new Set(Object.entries(foundations.css)+ const bindings = Object.entries(foundations.css)// Includes component spacing (space-input-lg), not only Tailwind's scale.- .filter(([, id]) => id.startsWith('semantic.foundations.space-'))- .map(([name]) => `--${name}`));- if (!spacingVariables.size) {+ .filter(([, id]) => id.startsWith('semantic.foundations.space-'));+ if (!bindings.length) {throw new Error('Invalid desktop-bindings.json; foundations.css has no semantic.foundations.space-* entries');}+ // The prefix alone must not invent sources: every binding target has to+ // exist as a token in the DTCG generation source the binding is built from.+ const dtcg = JSON.parse(readFileSync(new URL('../../packages/design-tokens/src/semantic/foundations.json', import.meta.url), 'utf8'))?.semantic?.foundations;+ if (!dtcg || typeof dtcg !== 'object' || Array.isArray(dtcg)) {+ throw new Error('Invalid semantic/foundations.json; expected semantic.foundations DTCG tokens');+ }+ const unbound = bindings.filter(([, id]) => !dtcg[id.slice('semantic.foundations.'.length)]);+ if (unbound.length) {+ throw new Error(`Invalid desktop-bindings.json; spacing bindings without a DTCG token: ${unbound.map(([name]) => `--${name}`).join(', ')}`);+ }+ spacingVariables = new Set(bindings.map(([name]) => `--${name}`));}return spacingVariables;}