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 审计每次调用先校验间距绑定
Kirozengf0bbebfb1981
diff --git a/docs/design-evidence/2026-09-13/ds10-desktop-guards.md b/docs/design-evidence/2026-09-13/ds10-desktop-guards.mdindex 557237d040..7b4c76b25f 100644--- a/docs/design-evidence/2026-09-13/ds10-desktop-guards.md+++ b/docs/design-evidence/2026-09-13/ds10-desktop-guards.md@@ -75,3 +75,10 @@ G2 的真实独立贡献者待安排,不能以 Agent 模拟替代;公开图在该主干上运行 `pnpm install --frozen-lockfile` 后,`VITE_CINDY_AUTH_REGION=global pnpm test:unit:related` 通过:runner 540 pass / 1 存量 skip,Desktop related 18.3s。Desktop、Mobile、design-tokens typecheck,生成/50 surface 台账新鲜度、endpoint/i18n/brand/glossary、migration、scheduler、Mobile scope、9 项文档合同检查均通过;Device Link 类型与 9 项真实 loopback 集成也通过。已有未跟踪 ui-showcase 被 related 自动选入,仍不提交。23 组固定历史回放的脚本/绑定 hash 与本候选一致,沿用原结果;原运行矩阵和截图仍绑定 07eac89584,不冒充新主干全量实机复验。新增主干的 open-path 生命周期/模型适配与 iOS 动画不属于本批;本批相对提交基线没有产品 UI、Token 源/生成物、依赖或 CI 配置改动。最终证据及单人自查回执在原附件目录的 submit-2026-09-14 中。提交走当前维护者 fork 与 DCO,不伪造双审共识或自动跟踪注册;最终远端检查以实际 PR 为准。+++## 2026-09-14 审查修复:绑定校验提前到每次审计++PR 审查指出上节契约有缺口:diff 无间距候选(docs-only 或纯颜色)时 `classifySpacing` 的惰性读取不执行,损坏的 `desktop-bindings.json` 只进入 scriptHashes、`--report` 退出 0。已用 `{bad json` + docs-only 候选在隔离 fixture 以真实 CLI 复现 exit 0。++修复:`getSpacingVariables` 导出并增加 `foundations.css` 结构校验,`audit()` 对每次调用先行解析校验;阻断与 `--report` 两种模式对损坏、结构缺失绑定均退出 2,健康输入报告不变。回归测试在无间距候选的既有 fixture 上补损坏绑定断言,带候选的损坏/缺失断言保留。`ds10-replay.json` 仍绑定提交候选的脚本 hash,本轮不覆写也不重跑冒充;改动只前置校验,不改变有效绑定下的分类输出。本节只改 `hardcoded-color-audit.mjs`、`design-layer-report.mjs`、对应测试与本文,无产品 UI、Token 源、依赖或 CI 接线变更;`pnpm test:unit:related` 通过(runner 540 pass / 1 存量 skip),scripts 不在带 typecheck 的 package 内。diff --git a/scripts/__tests__/hardcoded-color-audit.test.mjs b/scripts/__tests__/hardcoded-color-audit.test.mjsindex 9f3a9b99d0..7a628d2a61 100644--- a/scripts/__tests__/hardcoded-color-audit.test.mjs+++ b/scripts/__tests__/hardcoded-color-audit.test.mjs@@ -228,6 +228,12 @@ test('worktree includes staged, unstaged and untracked source; commit mode excluassert.throws(()=>audit({root:temp,baseRef:commit,worktree:true}));assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);fs.writeFileSync(path.join(temp,'scripts/hardcoded-color-exemptions.json'),'[]');+ // Corrupt bindings must fail closed even with no spacing candidate in the+ // diff: classifySpacing's lazy read never runs for colour-/docs-only+ // candidates, so the audit itself has to validate the contract it hashes.+ fs.writeFileSync(path.join(temp,bindings),'{bad json');+ assert.equal(cli('--base-ref',commit,'--worktree','--report').status,2);+ fs.copyFileSync(path.join(root, bindings), path.join(temp, bindings));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);diff --git a/scripts/hardcoded-color-audit.mjs b/scripts/hardcoded-color-audit.mjsindex 10fe04adcd..1f03ee6109 100644--- a/scripts/hardcoded-color-audit.mjs+++ b/scripts/hardcoded-color-audit.mjs@@ -8,7 +8,7 @@ import fs from 'node:fs';import path from 'node:path';import { fileURLToPath } from 'node:url';import { findBareColors, maskColorComments } from './shared/hardcoded-color-match.mjs';-import { reportDesignLayers } from './shared/design-layer-report.mjs';+import { reportDesignLayers, getSpacingVariables } from './shared/design-layer-report.mjs';const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');const hash = (text) => createHash('sha256').update(text).digest('hex');@@ -154,6 +154,10 @@ export function audit({ root = ROOT, baseRef = 'origin/main', headRef = 'HEAD',const resolve = ref => git(root, ['rev-parse', '--verify', '--end-of-options', `${ref}^{commit}`]).trim();const base = resolve(baseRef), head = resolve(headRef);const exemptions = readExemptions(root);+ // Validate the spacing binding on every run: a docs- or colour-only diff+ // never reaches the lazy read inside classifySpacing, and hashing alone+ // would accept a corrupt contract as a clean exit.+ getSpacingVariables();const range = worktree ? [base] : [base, head];const diffArgs = ['diff', '--no-ext-diff', '--no-textconv', '--no-renames'];const tracked = git(root, [...diffArgs, '--name-only', '-z', ...range, '--']).split('\0').filter(Boolean);diff --git a/scripts/shared/design-layer-report.mjs b/scripts/shared/design-layer-report.mjsindex f5d118eeef..27feb67ef9 100644--- a/scripts/shared/design-layer-report.mjs+++ b/scripts/shared/design-layer-report.mjs@@ -1,10 +1,15 @@import { readFileSync } from 'node:fs';// Read the generation contract, not a second hand-maintained token allowlist.+// Exported so the audit can validate the binding on every invocation, not+// only when a spacing candidate reaches the lazy read below.let spacingVariables;-function getSpacingVariables() {+export function getSpacingVariables() {if (!spacingVariables) {const { foundations } = JSON.parse(readFileSync(new URL('../../packages/design-tokens/src/desktop-bindings.json', import.meta.url), 'utf8'));+ if (!foundations?.css || typeof foundations.css !== 'object') {+ throw new Error('Invalid desktop-bindings.json; expected foundations.css spacing bindings');+ }spacingVariables = new Set(Object.entries(foundations.css)// Includes component spacing (space-input-lg), not only Tailwind's scale..filter(([, id]) => id.startsWith('semantic.foundations.space-'))