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
+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);
|
||||
Reference in new issue
Block a user