feat(gates): DEC-N1 把 accent 第二条通道钉成判据 B,并抓到一条绕开色值真源的真漂移
裁定:7 个产品线色相**保留**为受控例外(实测 hero 徽章占视口 0.538%、色相仅以 6.3% alpha
底纹存在、1600×846 hero 视口冷色像素普查 = 0),但**不再**让 check:accents 的口径停在「仅类名通道」——
那等于第二条通道无人看守。判据 B 扫三处:真源 hero-themes 的 accentColor/accentBg、
可达营销代码里 style={{…}} 的色彩属性(含 --badge-accent 与内联引用 accent 令牌的更隐蔽形态)、
营销页就地组装 accentColor。豁免按 文件+色值 登记且归一化成 #rrggbb(否则换个 rgba() 写法就绕过);
登记了却命中 0 ⇒ 判红;棘轮 MAX_NON_BRAND_HUES=7,存量恰在上限 ⇒ 第 8 个色相即判红。
战果:落盘即抓到 erp-upgrade-v3/page.tsx 的 deriveTheme() 在营销页里抄了一整份 theme
(含 accentColor '#1e3a5f' 与两段渐变)绕开真源。改走 getHeroTheme(heroThemeId || 'erp') 只覆盖动态字段 badge;
与真源逐字段对拍全等,并用库内实值确认 erp 行 heroThemeId='erp' ⇒ 渲染不变(查过,不是推定)。
自证与改正(原稿从未跑成过):selftest 11 情景 EXIT=0,每情景只喂一维。
修掉两处不自洽 —— 把「另一维的豁免腐化」当串维证据会让自证永远红(腐化只是该维没喂料的必然产物,
违规数才是证据),以及 4 情景棘轮期望与 分母0 情景 stale(写 9、实取 7)按实测改正。
连带新增 scripts/check-package-keys.mjs:按父路径+键名分组查 JSON 重复键,退出码 0/1/2 三档,
--selftest 三条各测一维;活体负对照注入重复 "lint" 键 ⇒ EXIT=1 点名 scripts.lint,还原 ⇒ EXIT=0。
背景见 qa-tracker §12.8:我先前用来去重的那条 node 回读只扫顶层缩进,对目标那一维根本不敏感。
读数:check:accents 0、check:visual 0、tsc 0、jest --testPathPatterns products 48 例 0、selftest 0。
ADR-0008 补决策五并 supersede 决策一的「本批不收」,同时把被证伪的 DEC-N2 默认值 0.15 就地标注更正。
This commit is contained in:
1 parent
0e17327ef0
commit
ffd709ae06
5 files changed
+675
-117
No files matched your search
@@ -751,3 +751,79 @@ ADR-0008 §87-1 的同一句话需要一并更正(该文件本轮由 accent
|
||||
又被路由的 catch 吞成 500 之外的路径**,所以测试毫无症状。已把 `body` 改可选并留下注释。
|
||||
⇒ 口径补充:**改 `src/**` 下的测试后必须让 `npm run build` 过一遍 tsc**,
|
||||
`npm run type-check` 与 build 的 tsc 覆盖同一份 tsconfig,但只有 build 会被 CI 跑到。
|
||||
|
||||
### 12.5 DEC-N4 · 授权与 basis 门槛下沉成共用闸(`2e009942`)
|
||||
|
||||
判据原先只有新成果槽有:`CaseStudiesSection` 与 `detail-trust-section` 里的案例主张不过闸,
|
||||
于是「同一类证据走两套标准」。这轮把判据(授权 + ≥1 个 `basis === 'verified'` + 禁词扫描)
|
||||
下沉成 `src/lib/constants/case-publish-gate.ts`,`results-slot` 的 `casePublishBlockers` 改为委托它
|
||||
⇒ **三处消费同一实现,禁词/口径真源仍只有 `metrics-basis.ts` 一份**(不造第二套真源)。
|
||||
|
||||
| 项 | 读数 |
|
||||
|---|---|
|
||||
| 门槛下会被隐藏的既有条目 | **0 条** —— seeds(products×6 / services×4 / standalone×1)的 `caseStudies` 全是空数组,solutions seed 无该字段,CMS `dev.db` 11 条内容的 `caseStudies` 长度全为 0 ⇒ 线上转化页无可见变化,本条是**前瞻性 fail-closed 加固**而非内容清洗 |
|
||||
| 转红的既有断言 | 2 处旧测试写的是「未授权案例照常渲染」,按测试夹具补 `authorized + basis:'verified'` 处理并新增负例(线上传言与测试数据不混用) |
|
||||
| 仪器自证 | 把闸改恒真(`return []`)⇒ **EXIT=1、20 例转红**(gate 本体、results-slot 原有用例、两区块负例、solution-detail 消费页都在红因里);还原后 EXIT=0 ⇒ 证明确实共用一道闸 |
|
||||
| `dataProofs` 为何不套硬闸 | 它已在 `weakestBasis` + `MetricsBasisNote` 契约下且自述目标口径,硬清会误伤全站已标注数字(理由写进代码注释) |
|
||||
|
||||
⚠ **残留(登记而非隐瞒)**:CMS `content-types` 的 `caseStudies` schema 还没有 `authorized/basis` 两个字段。
|
||||
后台现在无法为案例授权,闸只挡住「无字段 ⇒ 不可发布」这一侧;业务要真出案例须先扩 schema。
|
||||
|
||||
### 12.6 本轮的合并验证读数(提交前)
|
||||
|
||||
`tsc --noEmit` EXIT=0;全量 jest **145 套件 / 1795 例 EXIT=0**(较 §11 的 141/1747 增加 4 套件 48 例);
|
||||
`check:visual`(grammar + accents 各自 selftest 先跑)EXIT=0;`check:dead` EXIT=0(dead 0);
|
||||
`check:motion` EXIT=0;`npm run build` EXIT=0(`postbuild` 已装配 `dist/static` + `public`)。
|
||||
|
||||
### 12.7 DEC-N1 · accent 第二条通道钉成判据 B,并当场抓到一条真漂移
|
||||
|
||||
裁定:**保留** 7 个产品线色相(承担产品线视觉身份,实测 hero 徽章占视口 **0.538%**、色相仅以 **6.3% alpha** 底纹存在、
|
||||
1600×846 hero 视口**冷色像素普查 = 0**),但把这条通道收进 `check:accents` 的判据 B:
|
||||
①真源 `hero-themes.ts` 的 `accentColor/accentBg`、②可达营销代码里 `style={{…}}` 的色彩属性
|
||||
(含 `--badge-accent` 与内联引用 `--color-accent-*` 令牌的更隐蔽形态)、③营销页就地组装 `accentColor`(绕开真源的第二份色值)。
|
||||
豁免按 **文件 + 色值** 登记且色值归一化成 `#rrggbb`(否则换个 `rgba()` 写法就绕过);
|
||||
登记了却命中 0 ⇒ 判红(与判据 A 同一条防腐化纪律);棘轮 `MAX_NON_BRAND_HUES = 7`,存量恰在上限 ⇒ 第 8 个色相即判红。
|
||||
|
||||
| 证据 | 读数 |
|
||||
|---|---|
|
||||
| 仪器自证 | `check:accents:selftest` **11 情景 EXIT=0**,每情景只喂一维并断言另一维违规数为 0 |
|
||||
| 自证里的两处不自洽(原稿从未跑成) | ①把「另一维的豁免腐化」当串维证据 ⇒ B 夹具天然不带 A 的 3 个豁免文件 ⇒ A 必报 stale 3 ⇒ 自证永远红。腐化不是串维证据(它只是"该维没喂料"的必然产物),**违规数才是**;②4 情景的棘轮期望与 `分母 0` 情景的 stale(写 9、实取 7)按实测改正 |
|
||||
| 当场战果(真漂移) | `erp-upgrade-v3/page.tsx` 的 `deriveTheme()` 在营销页里抄了一整份 theme(含 `accentColor: '#1e3a5f'` 与两段渐变)绕开真源 ⇒ 判据 B 判红。改为 `getHeroTheme(heroThemeId ‖ 'erp')` 只覆盖动态字段 `badge` |
|
||||
| 改后渲染是否变的对拍 | 与真源逐字段对拍 `gradientFrom/gradientTo/gradientAngle/accentColor/accentBg/texture/layout` **全等**;并用库内实值确认 `erp` 行的 `heroThemeId` 就是 `'erp'` ⇒ 解析到同一份 theme,渲染不变(不是"应该一样",是查过) |
|
||||
| 复跑 | `check:accents` EXIT=0、`check:visual` EXIT=0、`tsc` EXIT=0、`jest --testPathPatterns products` 4 套件 48 例 EXIT=0 |
|
||||
|
||||
⚠ 口径边界(写在闸的成功输出行里):本闸只覆盖**代码面两条入路**;CMS 内容里 authored 的色值(富文本/图表数据)不在其内。
|
||||
|
||||
### 12.8 DEC-N6 · e2e 进类型口径 + 两处工程卫生,以及我自己造成的两次破坏
|
||||
|
||||
`e2e/tsconfig.json` + `npm run type-check:e2e` 并入 `test:all`;负对照读数:注入重复 `const revalidateSecret` 时
|
||||
`type-check` EXIT=0(0 条 e2e 诊断)而 `type-check:e2e` **EXIT=2(TS2451×2)**,还原 EXIT=0 ⇒ 补口真的敏感。
|
||||
既有 e2e 类型错误 **25 条**:19 条按行为等价修掉(`viewportSize` 可空、`.at(-1)`、`?? 0`、可选链、正则捕获组落局部变量、
|
||||
touch-targets 数组参数改对象参数、删掉既非法又等于默认值的 `locator.screenshot({fullPage:false})` 等);
|
||||
**6 条登记为残留并用 `@ts-expect-error` 标注**:5 处 `use.reducedMotion`(fixture 白名单证明运行时被忽略,
|
||||
而正确写法 `contextOptions` 会真的改截图 ⇒ 与本轮基线重采相撞)、1 处 `expect.toHaveScreenshot.timeout`(类型没这个键但运行时确实读它)。
|
||||
|
||||
`.husky/pre-commit` 索引模式 100644→**100755**(`git ls-files -s` 为准)。⚠ 但 `core.hooksPath` 是**指向主检出的绝对路径**,
|
||||
本机主检出那份工作树文件仍是 644 ⇒ 本仓每次提交照旧打 `hook was ignored`;克隆/检出该提交后才是 755。
|
||||
axe 证据默认落 `docs/acceptance/<运行日>-axe/axe-evidence.json`,旧路径保留为 latest 副本(Jenkinsfile:399 与文档引用不断),
|
||||
判定与三档退出码未动,新增 `check:axe:selftest`(临时目录真写一遍,9 项全 ✓)与 `--print-paths`。
|
||||
|
||||
**我自报两次破坏(管理归零,写在这里而不是只写在提交信息里)**:
|
||||
|
||||
1. **在别人还在写它的文件时就 `git add`** ⇒ 提交冻结的是中间态:`1c0ce5f4` 的信息声称「重复键已由 node 回读校验」,
|
||||
而 `git show HEAD:package.json` 实取重复键 **2 处**、且 `test:all` 整条不见 —— 由后续 `0e17327e` 补正。
|
||||
更狠的一环是我用来去重的那条命令:`grep -n 'type-check:e2e' package.json | tail -1` 取到的行号
|
||||
命中的是**含该子串的 `test:all` 整行**,`sed -i "<行号>d"` 于是把全仓门禁入口删了。
|
||||
⇒ 纪律:**按子串取行号再删行**属于危险动作(子串会出现在别的行里);改 JSON 要走解析器而不是行号。
|
||||
2. **校验仪器本身是坏的**:那条 node 回读用正则 `^ "key":`(两空格缩进)数重复键,
|
||||
而重复键在 `scripts` 对象里(四空格)⇒ 报 `dups=[]`,对目标那一维根本不敏感。
|
||||
现已换成 `scripts/check-package-keys.mjs`:按**父路径 + 键名**分组计数,退出码 0/1/2 三档,
|
||||
自带 `--selftest`(正对照 + 「同层重复必抓」+「异父同名不误报」三条各测一维),
|
||||
并在真 `package.json` 上做了活体负对照:注入重复的 `"lint"` 键 ⇒ **NEGATIVE=1(`scripts` 里的 "lint")**,还原 ⇒ REAL=0。
|
||||
|
||||
另记一次同类自伤:`npx jest "src/app/(marketing)/products"` 里 `(` 与 `[` 是**正则元字符**,
|
||||
jest 把它当 testPathPattern 解析 ⇒ "No tests found" 被我读成"测试失败"(EXIT=1 同码)。
|
||||
改用 `--testPathPatterns products` 后 4 套件 48 例 EXIT=0。这与 §5.42「命中 0 必须配页面健康的正对照」是同一族:
|
||||
**空结果与失败共用一个退出码时,仪器必须先自证能取到非空样本**。
|
||||
|
||||
|
||||
@@ -70,6 +70,34 @@
|
||||
|
||||
首页 8 段 + 一条承载详情页(`/solutions/[id]`)端到端做完,交付决策人看过再套其余模板。目的是避免在语法未验收前把全站 20+ 页面重写一遍。
|
||||
|
||||
### 决策五:产品线色相保留为**受控例外**,但第二条通道钉成机器判据(2026-10-17 轮,决策人「均采用推荐方案」)
|
||||
|
||||
本节 supersede 决策一里那句「本批不收它」与其两个理由,以及「若裁定保留,`check:accents` 的口径就永久是类名通道」——
|
||||
**永久类名通道 = 第二条通道无人看守**,不是裁定而是放弃。现行裁定如下:
|
||||
|
||||
- **保留** 7 个产品线色相(erp `#1e3a5f`、crm `#1e40af`、bi `#0c4a6e`、cms `#14532d`、sds `#78350f`、oa `#4c1d95`、novavis `#0f3d3e`)。
|
||||
依据是它们承担产品线视觉身份,且实测可见占比极低:hero 徽章占视口 **0.538%**,色相只以 **6.3% alpha** 底纹存在,
|
||||
1600×846 的 hero 视口**冷色像素普查 = 0**(离品牌红族 `#C41E3A` 色相 349.9° 最近的一条也远于 20° 判定带)。
|
||||
- **但**把它收进 `check:accents` 的**判据 B**:扫①色值真源 `src/lib/constants/hero-themes.ts` 的 `accentColor/accentBg`,
|
||||
②可达营销代码里的 `style={{…}}` 色彩属性(含 `--badge-accent` 这类自定义属性、以及内联引用 `--color-accent-*` 令牌的更隐蔽形态),
|
||||
③营销页里就地组装 `accentColor`(绕过真源的第二份色值)。豁免**按 文件 + 色值**登记,
|
||||
色值一律归一化成 `#rrggbb`(否则换个 `rgba()` 写法就绕过);纪律沿用判据 A:**登记了却命中 0 ⇒ 判红**(防腐化成永久豁免)。
|
||||
- **棘轮**:`MAX_NON_BRAND_HUES = 7`,存量恰在上限 ⇒ 第 8 个产品线色相出现即判红(加色相是设计决定,须显式改上限)。
|
||||
- **口径边界写死在输出行里**:本闸覆盖「代码面的两条入路」;**未覆盖 CMS 内容里 authored 的色值**(富文本/图表数据),属数据面。
|
||||
|
||||
自证与当场战果(这台仪器不是装饰):
|
||||
|
||||
- `npm run check:accents:selftest` **11 情景、EXIT=0**,每个情景**只喂一维**并额外断言未被测的那一维在该夹具上违规数为 0。
|
||||
这里修掉一处自伤:原稿把「另一维的豁免腐化数」也当成串维证据,而 B 的夹具天然不带 A 的三个豁免文件 ⇒
|
||||
A 必报 stale 3 ⇒ 自证永远红。腐化不是串维证据(它是"该维自己没喂料"的必然产物),**违规数才是**。
|
||||
另两处期望不自洽(4 情景的棘轮、`分母 0` 情景的 stale 9 vs 实取 7)已按实测改正——原稿从未跑成过。
|
||||
- 落盘实跑**当场抓到一条真漂移**:`src/app/(marketing)/products/erp-upgrade-v3/page.tsx` 的 `deriveTheme()`
|
||||
在营销页里就地抄了一整份 theme(含 `accentColor: '#1e3a5f'` 与两段渐变),绕过色值真源。
|
||||
已改为 `getHeroTheme(productData.heroThemeId || 'erp')` + 只覆盖动态字段 `badge`;
|
||||
与真源逐字段对拍 `gradientFrom/gradientTo/gradientAngle/accentColor/accentBg/texture/layout` **全等** ⇒ 渲染不变,
|
||||
读数 `check:accents` EXIT=0、`check:visual` EXIT=0、`tsc --noEmit` EXIT=0、`jest --testPathPatterns products` 4 套件 48 例 EXIT=0。
|
||||
|
||||
|
||||
## 理由
|
||||
|
||||
- 对标的价值在于**它已被验证的形状**,而形状可以脱离色相继承;色相是品牌资产,不该在对标时被换掉
|
||||
@@ -84,7 +112,12 @@
|
||||
|
||||
**已知偏差,本轮不修(各自登记为独立动作)**:
|
||||
|
||||
1. `StaggerReveal` 默认 `staggerDelay = 0.15` 与 ADR-0004 决策三「子元素 stagger 30–60ms」不符;改库默认值是全站动效重排 + 基线重采,需单独授权。本批只在首页与账本处显式传 0.04–0.06。
|
||||
1. ~~`StaggerReveal` 默认 `staggerDelay = 0.15` 与 ADR-0004 决策三「子元素 stagger 30–60ms」不符;改库默认值是全站动效重排 + 基线重采,需单独授权。本批只在首页与账本处显式传 0.04–0.06。~~
|
||||
**本条于 2026-10-17 轮被证伪,无需执行**(见 `docs/acceptance/qa-tracker.md` §12.2):
|
||||
`src/components/ui/scroll-reveal.tsx:113` 的默认值一直是 **`0.05`(50ms,本就在 30–60ms 内)**,
|
||||
`git log -S'staggerDelay = 0.15' -- src/components/ui/scroll-reveal.tsx` **无任何提交**,
|
||||
且全站 18 个显式传参只有 `0.05`(16 处)与 `0.06`(2 处)。
|
||||
⇒ 教训与前一轮「axe 哨兵抄字面量」同族:**台账里的数必须是当场仪器读数,不能是上一轮叙述的抄本**。
|
||||
2. `check:motion` 现存 8 条违反(6 条写死贝塞尔不在令牌层、`--transition-gentle = 1000ms` 超 700ms 入场上限、1 条 CSS 裸时长字面量),**全部为本分支基线 da9a5cb6 就有的红**,非本轮引入。
|
||||
3. `CaseStudiesSection` 与 `detail-trust-section` 仍**没有**授权/basis 门槛(只有新的成果槽有);应在彼处与 CMS 发布时同样设闸。
|
||||
4. `ui/` 组件库里 53 个不可达原语是产品决定,本批不删。
|
||||
@@ -106,6 +139,9 @@
|
||||
## 取证与验证
|
||||
|
||||
- 语法闸自证:`npm run check:grammar:selftest` 喂已知违规样本,R1–R9 必须全部判红,R10 棘轮必须「上限处不判红 / 上限+1 判红」;任一不成立即宣布"上面所有绿灯不作数"并 EXIT=1
|
||||
- accent 闸自证:`npm run check:accents:selftest` 三个情景分别只测一维(违规 / 豁免腐化 / 全绿),因为把互斥前提写进同一份夹具会让其中一维永远测不到
|
||||
- accent 闸自证:`npm run check:accents:selftest` **11 情景、按 dimension 各只喂一维**(A 类名:违规 / 豁免腐化 / 全绿;
|
||||
B 内联色彩通道与色值真源:新增未登记色相、内联写死色相、新增透传点、绕开真源、豁免腐化、分母 0 = 未能度量、全绿、
|
||||
色值写法归一化、棘轮超限)。纪律来自踩过的坑:把互斥前提写进同一份夹具会让其中一维永远测不到。
|
||||
2026-10-17 轮起判据 B 已上线(见决策五),故不再是「三情景只测类名通道」。
|
||||
- 注释渲染回归:`solution-detail-content-v3.test.tsx` 断言渲染文字里不含 `/*`,且先断言被污染的两段 DOM 确实渲染了(否则"找不到注释"可能只是"那段没出现");该断言已用变异验证过敏感性——把注释改回裸文本节点后仅这一条转红、其余三条仍绿
|
||||
- 负对照(待授权执行):把 `--radius-cta` 设成 12px,确认 ≥1 张视觉基线转红;若 N=0,说明基线什么都没拍,只读复跑的绿灯作废
|
||||
+452
-100
@@ -1,33 +1,32 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* accent 消费面闸:彩色编码只能出现在「工具 UI」与「图表/序列」里,不得出现在营销面。
|
||||
* accent 消费面闸:**两条通道**各一条判据。
|
||||
*
|
||||
* 依据是实测:Bain 全站字色只有 4 个值(#000 #FFF #CC0000 #767676)、面色 3 个;
|
||||
* Porsche 字色 3 个、面色 4 个,红只出现在按钮上。两家都**没有**用颜色给内容分类。
|
||||
* 本仓 2026-06 的 ADR-0004 决策一选了「编号为主 + 4px 色条为辅」,7 个 coding accent
|
||||
* 因此进了令牌层;实测下来真正在跑的营销代码只用了**一个蓝**(accent-blue)做装饰性
|
||||
* 图标砖与状态徽章 —— 也就是这些令牌的存在成本一直是「全站语法」,收益是「一处蓝」。
|
||||
* ══════════════════════════════════════════════════════════════════════════
|
||||
* 判据 A —— 类名通道(2026-10-17 首批)
|
||||
* 营销面不得出现 `accent-*` 类名。口径按文件名登记豁免。
|
||||
*
|
||||
* 本轮的处置不是删令牌(后台工具 UI 的分类色标确实用得上,图表也要),而是
|
||||
* **把消费面收窄**:营销面(app/(marketing)/、components/{sections,detail,content}/ 中
|
||||
* 可达的部分)一律不得出现 accent-*。
|
||||
* 判据 B —— 内联 style 色彩通道 + 色值真源(DEC-N1 的落地,本轮新增)
|
||||
* 判据 A 只看得见 Tailwind 类名。但色值还有第二条入路:
|
||||
* · `src/lib/constants/hero-themes.ts` 的 `accentColor` 是**色值真源**,
|
||||
* 它以内联样式进 DetailHero 徽章(`detail-hero.tsx` 的 backgroundColor /
|
||||
* borderColor / `--badge-accent`),字符串里根本没有 `accent-` 这个词,
|
||||
* 判据 A 对它**完全无感**。
|
||||
* · 可达营销组件里直接写死的内联色值字面量(`#1e3a5f`、`rgba(30,58,95,.06)`)
|
||||
* 同样是这条通道,而且它会**绕过真源**造出第二份色值。
|
||||
* 判据 B 扫这两处,要求每个命中都在**按 文件 + 色值 登记**的豁免表里;
|
||||
* 再加一道**数量棘轮**:真源里的非品牌色相数不得超上限。
|
||||
* 豁免纪律沿用判据 A:登记了却零命中 ⇒ 判红(防腐化成永久豁免)。
|
||||
*
|
||||
* 两条防赖设计:
|
||||
* 1) 豁免**按文件名登记**,不写目录通配 —— 通配会让新文件自动继承豁免。
|
||||
* 2) 名单里的文件若命中数变 0,同样判红。豁免名单只会随时间腐化成"没人记得为什么在这"
|
||||
* 的永久豁免;让它主动报红,才有人去删。
|
||||
* 依据仍是实测(Bain 全站字色只有 `#000 #FFF #CC0000 #767676`、面色 3 个;
|
||||
* Porsche 字色 3 个、面色 4 个,红只出现在按钮上——两家都没有用颜色给内容分类)。
|
||||
*
|
||||
* ⚠ 本闸**只覆盖 Tailwind 类名通道**(`accent-*`),不要把它读成"营销面没有任何彩色编码"。
|
||||
* 实测还有**第二条通道**:`src/lib/constants/hero-themes.ts` 的 `accentColor` 以内联样式
|
||||
* 进到 DetailHero 的徽章(`detail-hero.tsx:81-86` 的 backgroundColor/color/borderColor 与
|
||||
* `--badge-accent`)。11 个主题里有 7 个用非品牌色相(erp #1e3a5f / crm #1e40af /
|
||||
* bi #0c4a6e / cms #14532d / sds #78350f / oa #4c1d95 / novavis #0f3d3e),
|
||||
* 落在产品·方案·服务详情页的 hero 上。
|
||||
* 为什么本批不一起收:它属于「把首页那一条详情页的做法套到其余模板」,而决策四明确把模板批
|
||||
* 推到交付决策人验收之后;且去掉逐产品色相等于取消产品线视觉身份,是设计裁定不是语法收口。
|
||||
* 登记于 docs/acceptance/qa-tracker.md,判据口径也要在那里写清"类名通道为零"。
|
||||
* 判据 B 的**裁定口径**(ADR-0008「决策五」):产品线色相**保留为受控例外**,
|
||||
* 理由是实测它的可见占比近 0(详见 ADR 的量),而"新增一个未登记色相"才是真成本。
|
||||
* 所以这里不判红存量,只判红**未登记**与**超数量**。
|
||||
*
|
||||
* 退出码:0 成立 / 1 判红(含违规与豁免腐化)/ 2 未能度量(扫描文件数为 0)。
|
||||
* 退出码:0 成立 / 1 判红(违规、豁免腐化、棘轮超限)/ 2 未能度量(分母 0)。
|
||||
* ⚠ 分母 0 一律走 2 不走 0——"没量到"永远不等于"通过"。
|
||||
*/
|
||||
import { readFileSync, existsSync, readdirSync } from 'node:fs';
|
||||
import path from 'node:path';
|
||||
@@ -37,8 +36,10 @@ const ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const SRC = path.join(ROOT, 'src');
|
||||
const ACCENT_RE = /\baccent-(blue|teal|amber|purple|cyan|rose|indigo)\b/g;
|
||||
|
||||
/* ───────────────────────── 判据 A:类名通道 ───────────────────────── */
|
||||
|
||||
/** 按名登记的豁免:每条都必须仍有命中,否则判红 */
|
||||
const ALLOWLIST = [
|
||||
const ALLOWLIST_CLASSNAME = [
|
||||
// 后台工具 UI:内容模型的类型色标是**分类编码**(16 个模型要靠颜色快速区分),
|
||||
// 属"数据可视化"族而非编辑面。
|
||||
{ file: 'src/app/admin/page.tsx', reason: 'CMS 模型类型的分类色标(工具 UI)' },
|
||||
@@ -47,6 +48,94 @@ const ALLOWLIST = [
|
||||
{ file: 'src/components/ui/brand-visuals.tsx', reason: '组件库库存(品牌图形调色板本身)' },
|
||||
];
|
||||
|
||||
/* ─────────────── 判据 B:内联 style 色彩通道 + 色值真源 ─────────────── */
|
||||
|
||||
/** 色值真源:HERO_THEMES 所在文件(相对 ROOT 的路径) */
|
||||
const THEME_SOURCE = 'src/lib/constants/hero-themes.ts';
|
||||
|
||||
/**
|
||||
* 品牌色相族。判据是**实测色相距离**,不是肉眼归类:
|
||||
* #C41E3A 的 HSV 色相 = 349.9°。11 个主题的 accentColor 里,
|
||||
* security 的 #991b1b 色相 0.0°、距品牌红 10.1°,与 `--color-brand-section` #8B1530(346.3°)
|
||||
* 同族——所以它**不是**第二条彩色编码,它就是品牌红本身;
|
||||
* 而 sds 的 #78350f 色相 21.7°、距品牌红 31.8°,已是橙褐,落在族外。
|
||||
* 20° 这条线取在 10.1 与 31.8 之间,两侧各有 ≥10° 余量,不是凑数的阈值。
|
||||
*/
|
||||
const BRAND = { hex: '#c41e3a', hue: 349.9 };
|
||||
const BRAND_HUE_MAX_DISTANCE = 20;
|
||||
/** HSV 饱和度门限:低于此视为中性(纸白 #f8f6f3 实测 s=0.02、墨黑 #141210 s=0.20 但色带仅 4 阶)*/
|
||||
const CHROMATIC_MIN_SATURATION = 0.25;
|
||||
const CHROMATIC_MIN_CHANNEL_SPAN = 30;
|
||||
|
||||
/**
|
||||
* 数量棘轮:真源里**非品牌族色相**的上限。
|
||||
* 2026-10-17 实测存量 = 7(erp/crm/bi/cms/sds/oa/novavis)。
|
||||
* 新增一个产品线色相是**设计决定**,必须显式上调这里,不接受"顺手加了个字段"。
|
||||
* 递减不判红,但把下调提示写进 note(和判据 A 的 R10 同一套纪律)。
|
||||
*/
|
||||
const MAX_NON_BRAND_HUES = 7;
|
||||
|
||||
/**
|
||||
* 按 文件 + 色值 登记的豁免。色值一律**归一化成 #rrggbb**(rgba(30,58,95,.06) 与
|
||||
* #1e3a5f 是同一个色相,必须撞进同一条豁免,否则换个写法就绕过了)。
|
||||
* 'theme.accentColor' 是保留身份,含义是"色值来自真源、本文件只做透传"。
|
||||
*/
|
||||
const ALLOWLIST_INLINE_COLOR = [
|
||||
// —— 色值真源:产品线视觉身份。保留的裁定与实测见 ADR-0008 决策五。
|
||||
// 实测可见占比:徽章 162.7×44.8px = 视口的 0.538%,其中色相只以 6.3% alpha 底纹存在,
|
||||
// 1600×846 hero 视口的**彩色像素普查里冷色 = 0**(22407 个彩色像素全是品牌红族暖色)。
|
||||
{ file: THEME_SOURCE, color: '#1e3a5f', reason: '产品线视觉身份 erp(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#1e40af', reason: '产品线视觉身份 crm(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#0c4a6e', reason: '产品线视觉身份 bi(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#14532d', reason: '产品线视觉身份 cms(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#78350f', reason: '产品线视觉身份 sds(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#4c1d95', reason: '产品线视觉身份 oa(受控例外,ADR-0008 决策五)' },
|
||||
{ file: THEME_SOURCE, color: '#0f3d3e', reason: '产品线视觉身份 novavis(受控例外,ADR-0008 决策五)' },
|
||||
// —— 透传点:把真源色值写进内联 style 的两处。登记后,**新增透传点即判红**
|
||||
// (比如哪天有人把产品线色相从徽章扩散到卡片描边)。
|
||||
{ file: 'src/components/detail/detail-hero.tsx', color: 'theme.accentColor', reason: '唯一持有该身份的内联透传点(hero 徽章)' },
|
||||
{ file: 'src/components/content/sections.tsx', color: 'theme.accentColor', reason: 'dataviz 构件的 accent 透传(默认值是品牌红,未被产品线覆盖)' },
|
||||
];
|
||||
|
||||
/* ───────────────────────────── 颜色数学 ───────────────────────────── */
|
||||
|
||||
function normalizeHex(v) {
|
||||
const h = v.match(/#[0-9a-fA-F]{6}\b|#[0-9a-fA-F]{3}\b/);
|
||||
if (h) {
|
||||
let s = h[0].toLowerCase();
|
||||
if (s.length === 4) s = '#' + s.slice(1).split('').map((c) => c + c).join('');
|
||||
return s;
|
||||
}
|
||||
const r = v.match(/rgba?\(\s*([\d.]+)[,\s]+([\d.]+)[,\s]+([\d.]+)/);
|
||||
if (r) return '#' + [r[1], r[2], r[3]].map((x) => parseInt(x, 10).toString(16).padStart(2, '0')).join('');
|
||||
return null;
|
||||
}
|
||||
|
||||
/** HSV 色相/饱和;返回 null 表示无彩色信息 */
|
||||
function hsv(hex) {
|
||||
if (!hex || !/^#[0-9a-f]{6}$/.test(hex)) return null;
|
||||
const [r, g, b] = [1, 3, 5].map((i) => parseInt(hex.slice(i, i + 2), 16) / 255);
|
||||
const mx = Math.max(r, g, b), mn = Math.min(r, g, b), d = mx - mn;
|
||||
if (!mx || !d) return { hue: null, sat: 0, span: Math.round((mx - mn) * 255) };
|
||||
let h;
|
||||
if (mx === r) h = ((g - b) / d) % 6;
|
||||
else if (mx === g) h = (b - r) / d + 2;
|
||||
else h = (r - g) / d + 4;
|
||||
h *= 60;
|
||||
if (h < 0) h += 360;
|
||||
return { hue: +h.toFixed(1), sat: +(d / mx).toFixed(3), span: Math.round(d * 255) };
|
||||
}
|
||||
|
||||
/** 是否为「彩色编码」:够饱和、够色带跨度,且色相离品牌红族足够远 */
|
||||
function codingHue(hex) {
|
||||
const c = hsv(hex);
|
||||
if (!c || c.sat < CHROMATIC_MIN_SATURATION || c.span < CHROMATIC_MIN_CHANNEL_SPAN) return null;
|
||||
const dh = Math.min(Math.abs(c.hue - BRAND.hue), 360 - Math.abs(c.hue - BRAND.hue));
|
||||
return dh <= BRAND_HUE_MAX_DISTANCE ? null : { ...c, distanceToBrandHue: +dh.toFixed(1) };
|
||||
}
|
||||
|
||||
const relOf = (f) => path.relative(ROOT, f).split(path.sep).join('/');
|
||||
|
||||
function walk(dir, acc = []) {
|
||||
if (!existsSync(dir)) return acc;
|
||||
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
||||
@@ -58,104 +147,367 @@ function walk(dir, acc = []) {
|
||||
return acc;
|
||||
}
|
||||
|
||||
/**
|
||||
* —— 自证:三个互相独立的情景,每个只测一维 ——
|
||||
*
|
||||
* 第一版只喂了一个情景:营销面违规 + 三条豁免**全部有命中**,于是断言
|
||||
* `stale.length === 3` 永远不可能成立(豁免有命中正是"不腐化"的定义)。
|
||||
* 那不是豁免维度漏测,是**夹具把两个维度的前提写在了同一份数据里、
|
||||
* 而这两个前提互斥** —— 属于"仪器坏时仍要失败"的反面:仪器压根没被喂到那一维。
|
||||
* 现拆成三份,并补一份全绿情景,防的是另一头:判据写错成恒红,
|
||||
* 那它也会"抓到"所有负例,自证照样过。
|
||||
*/
|
||||
const ALLOWED_LINES = [
|
||||
['src/app/admin/page.tsx', 'const tone = bg-accent-blue'],
|
||||
['src/components/ui/product-card.tsx', 'const x = bg-accent-purple'],
|
||||
['src/components/ui/brand-visuals.tsx', 'const y = text-accent-cyan'],
|
||||
];
|
||||
const MARKETING_HIT = ['src/app/(marketing)/x.tsx', '<div className="bg-accent-blue-soft text-accent-blue" />'];
|
||||
/* ─────────────────────── 判据 A 的求值 ─────────────────────── */
|
||||
|
||||
const SCENARIOS = [
|
||||
{
|
||||
name: '营销面违规(豁免仍各有命中)',
|
||||
files: new Map([MARKETING_HIT, ...ALLOWED_LINES]),
|
||||
expect: { violations: 1, stale: 0 },
|
||||
},
|
||||
{
|
||||
name: '豁免腐化(登记在案但命中 0)',
|
||||
files: new Map([['src/app/(marketing)/y.tsx', '<div className="text-ink" />']]),
|
||||
expect: { violations: 0, stale: 3 },
|
||||
},
|
||||
{
|
||||
name: '全绿(既无违规也无腐化)',
|
||||
files: new Map(ALLOWED_LINES),
|
||||
expect: { violations: 0, stale: 0 },
|
||||
},
|
||||
];
|
||||
|
||||
function selftest() {
|
||||
console.log('accent 闸自证(负例必须被抓红,正例必须不判红)');
|
||||
let ok = true;
|
||||
for (const s of SCENARIOS) {
|
||||
const { violations, stale } = evaluate(s.files);
|
||||
const pass = violations.length === s.expect.violations && stale.length === s.expect.stale;
|
||||
if (!pass) ok = false;
|
||||
console.log(
|
||||
` ${pass ? '✓' : '✗'} ${s.name}:违规 ${violations.length}(应 ${s.expect.violations})` +
|
||||
` · 腐化 ${stale.length}(应 ${s.expect.stale})`,
|
||||
);
|
||||
}
|
||||
if (!ok) {
|
||||
console.log(' ⇒ 上面所有绿灯不作数');
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function evaluate(fileTexts) {
|
||||
function evaluateClassname(fileTexts) {
|
||||
const violations = [];
|
||||
const hitsByFile = new Map();
|
||||
|
||||
for (const [rel, text] of fileTexts) {
|
||||
const hits = [...text.matchAll(ACCENT_RE)];
|
||||
if (hits.length === 0) continue;
|
||||
hitsByFile.set(rel, hits.length);
|
||||
const allowed = ALLOWLIST.some((a) => a.file === rel);
|
||||
if (!allowed) {
|
||||
if (!ALLOWLIST_CLASSNAME.some((a) => a.file === rel)) {
|
||||
const line = text.slice(0, hits[0].index).split('\n').length;
|
||||
violations.push({ file: rel, count: hits.length, at: line, sample: hits[0][0] });
|
||||
}
|
||||
}
|
||||
|
||||
// 豁免腐化:登记了却没命中的文件
|
||||
const stale = ALLOWLIST.filter((a) => !hitsByFile.has(a.file)).map((a) => a.file);
|
||||
return { violations, stale, hitsByFile };
|
||||
const stale = ALLOWLIST_CLASSNAME.filter((a) => !hitsByFile.has(a.file)).map((a) => a.file);
|
||||
return { violations, stale, hitsByFile, measured: fileTexts.size > 0 };
|
||||
}
|
||||
|
||||
/* ─────────────────────── 判据 B 的求值 ─────────────────────── */
|
||||
|
||||
/** style={{ ... }} 块:逐字符配平花括号,块内才是内联样式通道 */
|
||||
function styleBodies(text) {
|
||||
const out = [];
|
||||
const re = /style\s*=\s*\{\{/g;
|
||||
let m;
|
||||
while ((m = re.exec(text))) {
|
||||
let i = m.index + m[0].length, depth = 1;
|
||||
const start = i;
|
||||
while (i < text.length && depth > 0) {
|
||||
if (text[i] === '{') depth++;
|
||||
else if (text[i] === '}') depth--;
|
||||
i++;
|
||||
}
|
||||
out.push({ body: text.slice(start, i - 1), line: text.slice(0, start).split('\n').length });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
// 色彩属性 + CSS 自定义属性。'--badge-accent' 这种带引号的键也接。
|
||||
const COLOR_PROP_RE =
|
||||
/(?:'(--[\w-]+)'|"(--[\w-]+)"|(--[\w-]+)|(backgroundColor|backgroundImage|background|borderColor|border|outlineColor|color|fill|stroke|boxShadow|textShadow))\s*:\s*([^,}\n]+)/g;
|
||||
|
||||
/** 真源里每个主题的 accent 色值:字段名限定,避免把 gradientFrom 那种纸色也算进来 */
|
||||
function themeSourceValues(text) {
|
||||
const out = [];
|
||||
const re = /(accentColor|accentBg)\s*:\s*['"`]([^'"`]*)['"`]/g;
|
||||
let m;
|
||||
while ((m = re.exec(text))) {
|
||||
const line = text.slice(0, m.index).split('\n').length;
|
||||
out.push({ field: m[1], raw: m[2], hex: normalizeHex(m[2]), at: line });
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
function evaluateInlineColor(fileTexts) {
|
||||
const violations = [];
|
||||
const hits = new Map(); // `${file}::${colorIdentity}` -> count
|
||||
const addHit = (file, color) => {
|
||||
const k = `${file}::${color}`;
|
||||
hits.set(k, (hits.get(k) || 0) + 1);
|
||||
};
|
||||
const registered = new Set(ALLOWLIST_INLINE_COLOR.map((a) => `${a.file}::${a.color}`));
|
||||
const bump = (arr, x) => { if (!arr.some((y) => y.file === x.file && y.color === x.color)) arr.push(x); };
|
||||
const violationsUnregistered = [];
|
||||
const violationsDuplicateSource = [];
|
||||
const registeredBrand = [];
|
||||
// 内联 style 里被当作色彩载体使用的属性名集合(诊断用,不参与判红)。
|
||||
// 原稿把它声明在 for 循环内、却在 return 里引用 ⇒ 截断后 ReferenceError;
|
||||
// 提到函数作用域,语义取「所有文件的并集」,判据不受影响(runDimension 只断言四维)。
|
||||
const accentProps = new Set();
|
||||
|
||||
const themeText = fileTexts.get(THEME_SOURCE);
|
||||
// 分母:真源解析出的 accent 字段数。0 ⇒ 未能度量,不许报通过。
|
||||
const denominator = themeText ? themeSourceValues(themeText).length : 0;
|
||||
|
||||
/* —— B-1 色值真源 —— */
|
||||
const nonBrandHues = new Set();
|
||||
if (themeText) {
|
||||
for (const v of themeSourceValues(themeText)) {
|
||||
if (!v.hex) continue;
|
||||
addHit(THEME_SOURCE, v.hex);
|
||||
const coding = codingHue(v.hex);
|
||||
if (!coding) {
|
||||
if (v.hex === BRAND.hex) registeredBrand.push(v.hex);
|
||||
continue; // 品牌族 / 中性 → 不是彩色编码,无需登记
|
||||
}
|
||||
nonBrandHues.add(v.hex);
|
||||
if (!registered.has(`${THEME_SOURCE}::${v.hex}`)) {
|
||||
bump(violationsUnregistered, {
|
||||
file: THEME_SOURCE, color: v.hex, at: v.at, why: `真源新增未登记的产品线色相(色相 ${coding.hue}°,距品牌红 ${coding.distanceToBrandHue}°)`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* —— B-2 可达营销代码里的内联 style 色彩通道 —— */
|
||||
for (const [rel, text] of fileTexts) {
|
||||
if (rel === THEME_SOURCE) continue;
|
||||
for (const sb of styleBodies(text)) {
|
||||
COLOR_PROP_RE.lastIndex = 0;
|
||||
let m;
|
||||
while ((m = COLOR_PROP_RE.exec(sb.body))) {
|
||||
const prop = (m[1] || m[2] || m[3] || m[4] || '').trim();
|
||||
const value = m[5] || '';
|
||||
if (/--color-accent-[\w-]+/.test(value)) {
|
||||
// 真身:把 accent 令牌塞进内联 style,比类名通道更隐蔽。
|
||||
bump(violationsUnregistered, { file: rel, color: '--color-accent-*', at: sb.line, why: `内联 style 直接引用 accent 令牌(${prop})` });
|
||||
continue;
|
||||
}
|
||||
if (/accentColor/.test(value)) {
|
||||
addHit(rel, 'theme.accentColor');
|
||||
accentProps.add(prop);
|
||||
if (!registered.has(`${rel}::theme.accentColor`)) {
|
||||
bump(violationsUnregistered, { file: rel, color: 'theme.accentColor', at: sb.line, why: `新增内联透传点(${prop} 取真源 accentColor)` });
|
||||
}
|
||||
continue;
|
||||
}
|
||||
const hex = normalizeHex(value);
|
||||
if (!hex) continue; // var(--color-brand) / currentColor / transparent 等:走令牌真源,不是硬编码
|
||||
addHit(rel, hex);
|
||||
const coding = codingHue(hex);
|
||||
if (!coding) continue; // 中性纸墨 / 品牌红族:不算彩色编码
|
||||
if (!registered.has(`${rel}::${hex}`)) {
|
||||
bump(violationsUnregistered, {
|
||||
file: rel, color: hex, at: sb.line, why: `营销面内联 style 写死色相 ${coding.hue}°(距品牌红 ${coding.distanceToBrandHue}°)`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 绕开真源的第二份色值:在营销代码里就地组装 HeroTheme 对象
|
||||
const dupRe = /accentColor\s*(?::|=)\s*['"`]([^'"`]*)['"`]/g;
|
||||
let d;
|
||||
while ((d = dupRe.exec(text))) {
|
||||
const hex = normalizeHex(d[1]);
|
||||
if (!hex || !codingHue(hex)) continue;
|
||||
const at = text.slice(0, d.index).split('\n').length;
|
||||
bump(violationsDuplicateSource, { file: rel, color: hex, at, why: '在营销页面里就地写死 accentColor,绕过色值真源' });
|
||||
}
|
||||
}
|
||||
|
||||
// 豁免腐化:登记了但命中 0 ⇒ 判红(与判据 A 同纪律)
|
||||
const stale = ALLOWLIST_INLINE_COLOR
|
||||
.filter((a) => !hits.has(`${a.file}::${a.color}`))
|
||||
.map((a) => ({ file: a.file, color: a.color, reason: a.reason }));
|
||||
|
||||
const ratchetRed = nonBrandHues.size > MAX_NON_BRAND_HUES;
|
||||
violations.push(...violationsUnregistered, ...violationsDuplicateSource);
|
||||
|
||||
return {
|
||||
violations,
|
||||
violationsUnregistered,
|
||||
violationsDuplicateSource,
|
||||
stale,
|
||||
ratchetRed,
|
||||
nonBrandHueCount: nonBrandHues.size,
|
||||
nonBrandHues: [...nonBrandHues],
|
||||
hits,
|
||||
denominator,
|
||||
measured: denominator > 0,
|
||||
accentProps,
|
||||
};
|
||||
}
|
||||
|
||||
/* ─────────────────────────── 自证 ─────────────────────────── */
|
||||
|
||||
/**
|
||||
* 每个情景**只测一维**。这条纪律是踩过坑换来的:
|
||||
* 上一版把「违规」和「豁免腐化」两个互斥前提塞进同一份夹具——豁免有命中正是
|
||||
* "不腐化"的定义,于是腐化那一维永远测不到,自照出来全线绿灯。
|
||||
* 现在按 dimension 只跑对应求值器,并额外断言**另一维在该夹具上为 0**,
|
||||
* 用来自证夹具确实只喂了一个维度(否则"单维"只是自称)。
|
||||
*/
|
||||
const A_ALLOWED_LINES = [
|
||||
['src/app/admin/page.tsx', 'const tone = bg-accent-blue'],
|
||||
['src/components/ui/product-card.tsx', 'const x = bg-accent-purple'],
|
||||
['src/components/ui/brand-visuals.tsx', 'const y = text-accent-cyan'],
|
||||
];
|
||||
const A_MARKETING_HIT = ['src/app/(marketing)/x.tsx', '<div className="bg-accent-blue-soft text-accent-blue" />'];
|
||||
|
||||
// 判据 B 用的真源夹具:7 个已登记产品线色相 + 品牌红 + 品牌族的 #991b1b(后者必须不被判红)
|
||||
const B_THEME = [THEME_SOURCE, [
|
||||
"erp: { accentColor: '#1e3a5f', accentBg: 'rgba(30, 58, 95, 0.06)' },",
|
||||
"crm: { accentColor: '#1e40af' },",
|
||||
"bi: { accentColor: '#0c4a6e' },",
|
||||
"cms: { accentColor: '#14532d' },",
|
||||
"sds: { accentColor: '#78350f' },",
|
||||
"oa: { accentColor: '#4c1d95' },",
|
||||
"novavis: { accentColor: '#0f3d3e' },",
|
||||
"security: { accentColor: '#991b1b' },",
|
||||
"solution: { accentColor: '#C41E3A' },",
|
||||
].join('\n')];
|
||||
const B_PROPAGATION = [
|
||||
['src/components/detail/detail-hero.tsx', 'style={{ backgroundColor: `${theme.accentColor}10` }}'],
|
||||
['src/components/content/sections.tsx', 'style={{ color: accentColor }}'],
|
||||
];
|
||||
|
||||
const SCENARIOS = [
|
||||
// ── 判据 A 的三维 ──
|
||||
{
|
||||
name: '[A] 营销面类名违规(A 豁免仍各有命中)',
|
||||
dimension: 'classname',
|
||||
files: new Map([A_MARKETING_HIT, ...A_ALLOWED_LINES, B_THEME, ...B_PROPAGATION]),
|
||||
expect: { violations: 1, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[A] 类名豁免腐化(登记在案但命中 0)',
|
||||
dimension: 'classname',
|
||||
files: new Map([['src/app/(marketing)/y.tsx', '<div className="text-ink" />'], B_THEME, ...B_PROPAGATION]),
|
||||
expect: { violations: 0, stale: 3, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[A] 类名全绿(无违规也无腐化)',
|
||||
dimension: 'classname',
|
||||
files: new Map([...A_ALLOWED_LINES, B_THEME, ...B_PROPAGATION]),
|
||||
expect: { violations: 0, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
// ── 判据 B 的四维:未登记色相 / 透传点新增 / 绕开真源 / 豁免腐化 / 棘轮 ──
|
||||
{
|
||||
name: '[B] 真源新增未登记色相',
|
||||
dimension: 'inline',
|
||||
files: new Map([[THEME_SOURCE, B_THEME[1] + "\nfinance: { accentColor: '#0e7490' },"], ...B_PROPAGATION]),
|
||||
expect: { violations: 1, stale: 0, ratchet: true, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 营销面内联 style 写死色相',
|
||||
dimension: 'inline',
|
||||
files: new Map([B_THEME, ...B_PROPAGATION, ['src/app/(marketing)/z.tsx', '<div style={{ backgroundColor: "#7c3aed" }} />']]),
|
||||
expect: { violations: 1, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 新增内联透传点',
|
||||
dimension: 'inline',
|
||||
files: new Map([B_THEME, ...B_PROPAGATION, ['src/components/sections/new-card.tsx', 'style={{ borderColor: accentColor }}']]),
|
||||
expect: { violations: 1, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 绕开真源、页面里就地组装 accentColor',
|
||||
dimension: 'inline',
|
||||
files: new Map([B_THEME, ...B_PROPAGATION, ['src/app/(marketing)/products/v3/page.tsx', "const t = { accentColor: '#1e3a5f' };"]]),
|
||||
expect: { violations: 1, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 内联豁免腐化(登记在案但命中 0)',
|
||||
dimension: 'inline',
|
||||
files: new Map([[THEME_SOURCE, "solution: { accentColor: '#C41E3A' },"], ['src/components/detail/detail-hero.tsx', 'style={{ color: "var(--ink)" }}']]),
|
||||
expect: { violations: 0, stale: 9, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 分母 0 = 未能度量(真源解析不出任何 accent 字段)',
|
||||
dimension: 'inline',
|
||||
files: new Map([[THEME_SOURCE, 'export const HERO_THEMES = {};'], ...B_PROPAGATION]),
|
||||
expect: { violations: 0, stale: 7, ratchet: false, measured: false },
|
||||
},
|
||||
{
|
||||
name: '[B] 内联全绿(产品线色相均已登记、棘轮未越界)',
|
||||
dimension: 'inline',
|
||||
files: new Map([B_THEME, ...B_PROPAGATION]),
|
||||
expect: { violations: 0, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
{
|
||||
name: '[B] 色值写法归一化:rgba 与十六进制撞进同一条豁免',
|
||||
dimension: 'inline',
|
||||
files: new Map([[THEME_SOURCE, B_THEME[1].replace(
|
||||
"erp: { accentColor: '#1e3a5f', accentBg: 'rgba(30, 58, 95, 0.06)' },",
|
||||
"erp: { accentColor: 'rgba(30, 58, 95, 1)', accentBg: '#1E3A5F' },",
|
||||
)], ...B_PROPAGATION]),
|
||||
expect: { violations: 0, stale: 0, ratchet: false, measured: true },
|
||||
},
|
||||
];
|
||||
|
||||
function runDimension(dimension, files) {
|
||||
const a = evaluateClassname(files);
|
||||
const b = evaluateInlineColor(files);
|
||||
const src = dimension === 'classname' ? a : b;
|
||||
const other = dimension === 'classname' ? b : a;
|
||||
return {
|
||||
violations: src.violations.length,
|
||||
stale: src.stale.length,
|
||||
ratchet: dimension === 'classname' ? false : b.ratchetRed,
|
||||
measured: dimension === 'classname' ? a.measured : b.measured,
|
||||
otherViolations: other.violations.length,
|
||||
otherStale: other.stale.length,
|
||||
};
|
||||
}
|
||||
|
||||
function selftest() {
|
||||
console.log('accent 闸自证(判据 A 类名通道 / 判据 B 内联色彩通道 + 色值真源)');
|
||||
console.log('纪律:每个情景只喂一维;情景同时断言另一维在该夹具上为 0,自证"单维"不是自称。');
|
||||
let ok = true;
|
||||
for (const s of SCENARIOS) {
|
||||
const got = runDimension(s.dimension, s.files);
|
||||
const errs = [];
|
||||
if (got.violations !== s.expect.violations) errs.push(`违规 ${got.violations}≠应 ${s.expect.violations}`);
|
||||
if (got.stale !== s.expect.stale) errs.push(`腐化 ${got.stale}≠应 ${s.expect.stale}`);
|
||||
if (got.ratchet !== s.expect.ratchet) errs.push(`棘轮 ${got.ratchet}≠应 ${s.expect.ratchet}`);
|
||||
if (got.measured !== s.expect.measured) errs.push(`可度量 ${got.measured}≠应 ${s.expect.measured}`);
|
||||
// 夹具纯度断言:未被测的那一维必须干净(棘轮情景例外——它本来就靠真源色相数超限成立)
|
||||
// 串维证据只取「另一维的违规数」:豁免腐化(stale)在单维夹具里是必然产物 ——
|
||||
// B 的夹具不带 A 的三个豁免文件,A 一定报 stale 3;把 stale 当串维证据会让
|
||||
// 自证永远红,而把它删掉又等于放弃单维断言。违规数才是「这维真的被抓了」的证据。
|
||||
if (got.otherViolations > 0) {
|
||||
errs.push(`夹具串维:未被测的那一维在该夹具上命中 条违规`);
|
||||
}
|
||||
if (errs.length) { ok = false; console.log(` ✗ ${s.name}:${errs.join(';')}`); }
|
||||
else console.log(` ✓ ${s.name}:违规 ${got.violations} · 腐化 ${got.stale} · 棘轮超限 ${got.ratchet} · 可度量 ${got.measured}`);
|
||||
}
|
||||
if (!ok) { console.log(' ⇒ 上面所有绿灯不作数'); return 1; }
|
||||
console.log(' ⇒ 两维各自独立可失败,夹具未串维');
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ─────────────────────────── 主流程 ─────────────────────────── */
|
||||
|
||||
function main() {
|
||||
if (process.argv.includes('--selftest')) process.exit(selftest());
|
||||
|
||||
const files = walk(SRC);
|
||||
if (files.length === 0) { console.log('未能度量:src 下没扫到任何文件'); process.exit(2); }
|
||||
const fileTexts = new Map(files.map((f) => [path.relative(ROOT, f).split(path.sep).join('/'), readFileSync(f, 'utf8')]));
|
||||
const { violations, stale, hitsByFile } = evaluate(fileTexts);
|
||||
const totalHits = [...hitsByFile.values()].reduce((a, b) => a + b, 0);
|
||||
const allowedHits = [...hitsByFile].filter(([f]) => ALLOWLIST.some((a) => a.file === f));
|
||||
const fileTexts = new Map(files.map((f) => [relOf(f), readFileSync(f, 'utf8')]));
|
||||
|
||||
console.log(`accent 消费面对账:扫描 ${files.length} 个源文件 · 命中 ${totalHits} 处 / ${hitsByFile.size} 文件`);
|
||||
for (const [f, n] of allowedHits) {
|
||||
const a = ALLOWLIST.find((x) => x.file === f);
|
||||
console.log(` · 豁免 ${f} (${n} 处) — ${a.reason}`);
|
||||
const a = evaluateClassname(fileTexts);
|
||||
const b = evaluateInlineColor(fileTexts);
|
||||
|
||||
console.log(`══ 判据 A 类名通道:扫描 ${files.length} 个源文件 · 命中 ${[...a.hitsByFile.values()].reduce((x, y) => x + y, 0)} 处 / ${a.hitsByFile.size} 文件`);
|
||||
for (const [f, n] of a.hitsByFile) {
|
||||
const x = ALLOWLIST_CLASSNAME.find((y) => y.file === f);
|
||||
if (x) console.log(` · 豁免 ${f} (${n} 处) — ${x.reason}`);
|
||||
}
|
||||
|
||||
let bad = false;
|
||||
for (const v of violations) { bad = true; console.log(` ✗ 营销面使用彩色编码 ${v.file}:${v.at} (${v.count} 处,如 ${v.sample})`); }
|
||||
for (const f of stale) { bad = true; console.log(` ✗ 豁免已腐化:${f} 登记在案但命中 0 处 —— 请把这条豁免删掉`); }
|
||||
for (const v of a.violations) { bad = true; console.log(` ✗ 营销面使用彩色编码 ${v.file}:${v.at} (${v.count} 处,如 ${v.sample})`); }
|
||||
for (const f of a.stale) { bad = true; console.log(` ✗ A 豁免已腐化:${f} 登记在案但命中 0 处 —— 请把这条豁免删掉`); }
|
||||
|
||||
// 判据 B
|
||||
console.log(`\n══ 判据 B 内联 style 色彩通道 + 色值真源`);
|
||||
console.log(` 真源 ${THEME_SOURCE}:解析出 accent 字段 ${b.denominator} 个(分母)`);
|
||||
if (!b.measured) {
|
||||
console.log(' ⇒ 分母为 0:未能度量(不是通过)');
|
||||
process.exit(2);
|
||||
}
|
||||
const brandSide = b.nonBrandHues.length;
|
||||
console.log(` 非品牌族色相 ${brandSide} 个 / 棘轮上限 ${MAX_NON_BRAND_HUES}:${b.nonBrandHues.join(' ')}`);
|
||||
for (const e of ALLOWLIST_INLINE_COLOR) {
|
||||
const n = b.hits.get(`${e.file}::${e.color}`) || 0;
|
||||
console.log(` · 豁免 ${e.file} @ ${e.color} (${n} 处) — ${e.reason}`);
|
||||
}
|
||||
for (const v of b.violationsUnregistered) { bad = true; console.log(` ✗ 未登记的彩色编码 ${v.file}:${v.at} — ${v.why}`); }
|
||||
for (const v of b.violationsDuplicateSource) { bad = true; console.log(` ✗ 绕过色值真源 ${v.file}:${v.at} @ ${v.color} — ${v.why}`); }
|
||||
for (const s of b.stale) { bad = true; console.log(` ✗ B 豁免已腐化:${s.file} @ ${s.color} 登记在案但命中 0 处(${s.reason})—— 请把这条豁免删掉`); }
|
||||
if (b.ratchetRed) { bad = true; console.log(` ✗ 棘轮超限:产品线非品牌色相 ${brandSide} > 上限 ${MAX_NON_BRAND_HUES} —— 加色相是设计决定,须显式上调上限`); }
|
||||
if (b.nonBrandHueCount < MAX_NON_BRAND_HUES && !bad) {
|
||||
console.log(` note:存量已降到 ${brandSide},可把 MAX_NON_BRAND_HUES 从 ${MAX_NON_BRAND_HUES} 下调(棘轮自锁)`);
|
||||
}
|
||||
|
||||
if (bad) { console.log('\n不成立'); process.exit(1); }
|
||||
// 口径写死在这一行:本闸只证明**类名通道**为零。
|
||||
// 第二通道(hero-themes 的 accentColor 内联样式)不在它的敏感范围内,
|
||||
// 说"营销面零彩色编码"会是假陈述 —— 措辞必须与被验的那一维一致。
|
||||
console.log('\n成立:营销面零 accent-* 类彩色编码(仅类名通道),且每条豁免都仍有命中');
|
||||
console.log(' 口径提示:hero-themes 的 accentColor 走内联样式,本闸不覆盖;实测 7 个非品牌色相仍在,见本文件头部注释与 qa-tracker');
|
||||
console.log('\n成立:判据 A 营销面零 accent-* 类彩色编码;判据 B 内联色彩通道与色值真源的每个命中都已按 文件+色值 登记,且两维的每条豁免都仍有命中');
|
||||
console.log(` 口径:彩色编码的两条入路都在这道闸的敏感范围内(类名 / 内联 style+真源色值)。`);
|
||||
console.log(` 产品线色相 ${brandSide} 个是**已裁定的受控例外**(ADR-0008 决策五),不是漏网;新增未登记色相或超棘轮上限即判红。`);
|
||||
console.log(` 实测可见占比(同 ADR):hero 徽章 = 视口 0.538%,色相仅以 6.3% alpha 底纹存在,1600×846 hero 视口冷色像素普查 = 0。`);
|
||||
console.log(' ⚠ 未被本闸覆盖:CMS 内容里 authored 的色值(富文本/图表数据),属数据面而非代码面。');
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -0,0 +1,102 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* package.json 重复键守卫(DEC-N6 连带)。
|
||||
*
|
||||
* 为什么要有这个文件:JSON 的重复键**不报错**,`JSON.parse` 让后者静默覆盖前者,
|
||||
* 于是 "npm run type-check:e2e" 被写了两遍时,脚本数、退出码、CI 读数全都看不出异常。
|
||||
* 本仓在并行分工下真就这么踩了一次(1c0ce5f4 冻结的就是中间态)。
|
||||
*
|
||||
* 我上一版用它做校验时把仪器写废了:正则 `^ "key":` 只匹配**顶层**(两空格缩进),
|
||||
* 而重复键在 `scripts` 对象里(四空格)⇒ 报 `dups=[]` 却对目标那一维根本不敏感。
|
||||
* 所以这里按「父路径 + 键名」分组计数,并且**自带负对照**:
|
||||
* 喂一份明知重复的样本,不判红就宣布上面的 ok 都不作数。
|
||||
*
|
||||
* 退出码三档:0 无重复 / 1 有重复 / 2 未能度量(文件读不到或解析失败)。
|
||||
*/
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
// 注意层级:base 是 scripts/check-package-keys.mjs 本身,'..' 只退一级就到仓库根。
|
||||
// 写成 '../../package.json' 会退两级落到 .qoder/worktrees/ ⇒ 读不到文件、报 EXIT=2,
|
||||
// 而 EXIT=2 是「未能度量」不是「无重复」——负对照两次都撞在这个错上(本仓 §5.42 的同族)。
|
||||
const TARGET = new URL('../package.json', import.meta.url);
|
||||
|
||||
function findDuplicateKeys(raw) {
|
||||
const lines = raw.split('\n');
|
||||
const stack = []; // 每层的容器名;数组用 '#'
|
||||
const seen = new Map(); // path -> Set(keys)
|
||||
|
||||
for (const line of lines) {
|
||||
const stripped = line.trim();
|
||||
if (!stripped) continue;
|
||||
// 先出栈:本行以 } 或 ] 开头表示上一层结束
|
||||
while (stack.length && /^[}\]]/.test(stripped)) stack.pop();
|
||||
|
||||
const m = stripped.match(/^"([^"]+)"\s*:/);
|
||||
if (!m) {
|
||||
// 数组元素等非键行;`,` 结尾的容器关闭由下一轮处理
|
||||
continue;
|
||||
}
|
||||
const key = m[1];
|
||||
const path = stack.join('.');
|
||||
if (!seen.has(path)) seen.set(path, new Set());
|
||||
if (seen.get(path).has(key)) {
|
||||
return [{ path: path || '<root>', key }];
|
||||
}
|
||||
seen.get(path).add(key);
|
||||
|
||||
// 若本行的值以 { 或 [ 开头,则该键成为下一层的容器(单行对象不展开)
|
||||
const after = stripped.slice(m[0].length);
|
||||
if (/^\{/.test(after.trim()) && !/\}/.test(after)) stack.push(key);
|
||||
else if (/^\[/.test(after.trim()) && !/\]/.test(after)) stack.push(key + '.#');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
function selftest() {
|
||||
// 正对照:同一份真文件若确实无重复,判绿
|
||||
const dup = findDuplicateKeys('{"a":{"x":1},"b":{"y":2}}\n'.replace(/\n$/, ''));
|
||||
// 负对照 1:同层重复键必须抓到(这是本仪器存在的意义)
|
||||
const neg1 = findDuplicateKeys('{\n "scripts": {\n "a": "1",\n "a": "2"\n }\n}');
|
||||
// 负对照 2:不同父路径下的同名键不得误报(否则守卫会把所有嵌套键全判红)
|
||||
const neg2 = findDuplicateKeys('{\n "scripts": {\n "a": "1"\n },\n "lint-staged": {\n "a": "2"\n }\n}');
|
||||
const ok = dup.length === 0 && neg1.length === 1 && neg2.length === 0;
|
||||
console.log(
|
||||
`[selftest] 正对照=${dup.length === 0 ? 'ok' : 'FAIL'} ` +
|
||||
`负对照-重复必抓=${neg1.length === 1 ? 'ok' : 'FAIL'} ` +
|
||||
`负对照-异父不误报=${neg2.length === 0 ? 'ok' : 'FAIL'}`
|
||||
);
|
||||
if (!ok) {
|
||||
console.error('[selftest] 仪器自证失败 ⇒ 任何 ok 读数都不作数');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
if (args.includes('--selftest')) {
|
||||
selftest();
|
||||
console.log('SELFTEST_EXIT=0');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
let raw;
|
||||
try {
|
||||
raw = readFileSync(TARGET, 'utf8');
|
||||
} catch (e) {
|
||||
console.error(`未能度量:读不到 ${fileURLToPath(TARGET)} —— ${e.message}`);
|
||||
process.exit(2);
|
||||
}
|
||||
try {
|
||||
JSON.parse(raw);
|
||||
} catch (e) {
|
||||
console.error(`未能度量:package.json 解析失败 —— ${e.message}`);
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const dups = findDuplicateKeys(raw);
|
||||
if (dups.length === 0) {
|
||||
console.log('package.json 重复键:0(按父路径分组计数;自证见 --selftest)');
|
||||
process.exit(0);
|
||||
}
|
||||
for (const d of dups) console.error(`重复键判红:${d.path || '<root>'} 里的 "${d.key}"`);
|
||||
process.exit(1);
|
||||
@@ -8,7 +8,7 @@ import { ProductValueSection } from '@/components/detail/detail-product-value';
|
||||
import { DetailTrustSection } from '@/components/detail/detail-trust-section';
|
||||
import { DetailCTASection } from '@/components/detail/detail-cta-section';
|
||||
import { L3EmptyFallback } from '@/components/detail';
|
||||
import type { HeroTheme } from '@/lib/constants/hero-themes';
|
||||
import { getHeroTheme, type HeroTheme } from '@/lib/constants/hero-themes';
|
||||
import type { Product, CaseStudy, DataProof, Certification } from '@/lib/constants/products';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
@@ -17,20 +17,12 @@ export const metadata: Metadata = {
|
||||
};
|
||||
|
||||
function deriveTheme(productData: Record<string, unknown>): HeroTheme {
|
||||
const heroThemeId = productData.heroThemeId as string;
|
||||
// Build a theme from product data fields, with sensible defaults
|
||||
return {
|
||||
id: heroThemeId || 'default',
|
||||
name: 'ERP主题',
|
||||
gradientFrom: '#f8f6f3',
|
||||
gradientTo: '#f0ebe4',
|
||||
gradientAngle: 135,
|
||||
accentColor: '#1e3a5f',
|
||||
accentBg: 'rgba(30, 58, 95, 0.06)',
|
||||
texture: { type: 'grid' as const, opacity: 0.03 },
|
||||
layout: 'left' as const,
|
||||
badge: productData.category as string,
|
||||
};
|
||||
// 色值与渐变一律取自真源 src/lib/constants/hero-themes.ts。
|
||||
// 这一版原先在营销页里就地抄了一整份 theme(含 erp 的 accentColor '#1e3a5f' 与两段渐变),
|
||||
// 被 check:accents 判据 B 的「绕过色值真源」当场抓红 —— 抄本会随真源漂移而静默过期,
|
||||
// 而且它在营销面制造了一个未登记的硬编码色相。本页只补动态字段 badge。
|
||||
const base = getHeroTheme((productData.heroThemeId as string) || 'erp');
|
||||
return { ...base, badge: productData.category as string };
|
||||
}
|
||||
|
||||
export default async function ERPUpgradeV3Page() {
|
||||
|
||||
Reference in new issue
Block a user