flow-comet 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/skills/flow-comet/GUIDANCE.md +4 -2
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +31 -1
- package/.flow-comet/skills/flow-comet/reference/workflow-protocol.json +1 -1
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +129 -3
- package/.flow-comet/skills/flow-comet/scripts/context-scan.mjs +396 -0
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +778 -0
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +2697 -12
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +664 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +602 -1
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +145 -1
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +5 -3
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +153 -27
- package/.flow-comet/skills/flow-comet-change/SKILL.md +11 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +4 -2
- package/.flow-comet/skills/flow-comet-evolve/SKILL.md +46 -11
- package/.flow-comet/skills/flow-comet-health/SKILL.md +57 -16
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +28 -3
- package/README.md +2 -2
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// C1 · flow-comet 引擎自测套件(场景数以 SCENARIOS.length 为准:节点门禁 entry/exit 校验正反例与 WARN 渐进、自定义协议加载路由与防线、TASK 签名与 next 推进、handoff Return Contract 与时间序、init 状态机与 hook 写白名单、CONTEXT 自动初始化检测、completedChecks 真实性声明机制(skill-load/record/exit 校验 + 交叉自洽 + 旧兼容)、init 参数误用防护、执行遗漏防护、严格模式、验证失败计数按变更隔离、多趟路由依赖图校验(环/缺失依赖 BLOCK 与混排合法锚)、契约解析失败检测、计数一致性自检(场景数 + 系统测试集项数)、prepare-env 平台选择链、零提交边界与入口首部强制、多趟出口硬化(可运行串行放行与拦截双向锚、单行分号 write_files 容错、收尾态路由静默、死结提示与技能文本锁)、installer 新链路(flow-kit 获取五态 / 桥接健康六态 / 他方保持 / 强制回退)、并行文件依赖检测(写写重叠强判前移 plan 出口 + read 读写弱判渐进 + 触发面排除 + 委托前保持锚 + 扩展名闭合)、directOverride 授权约束(协调者授权留痕正例 / 执行者自切无授权 BLOCK / 越界改 state hook 拦截 / 恢复双路径)、hook state 大小写变体拦截(win32/darwin 闭合 / 其他平台放行)、路由完成判定 fail-closed(缺/未知 status 畸形块不提前放行)、并行文件依赖路径归一化(`.` 段变体重叠检出)、运行时文件位置迁移(白名单搬移 / 迁移前备份与回退 / 新旧并存·符号链接·内容损坏三边界 / 失败保护 / gitignore 三形态保守纳管与幂等)、Comet 感知层剥离(classic 资产有无判定一致 / overlay 协议不再进入叠加分支 + 源码符号检索)、自检清单条目缺失显式报告、受控计划重校重签(replan 授权 fail-closed / 轮次上限与显式续轮 / 幂等空操作 / 重签后 execute 出口放行 / 校验不豁免与任务图分析单源锚)与强制推进留痕(advance-forced 事件 / status.forcedNodes
|
|
2
|
+
// C1 · flow-comet 引擎自测套件(场景数以 SCENARIOS.length 为准:节点门禁 entry/exit 校验正反例与 WARN 渐进、自定义协议加载路由与防线、TASK 签名与 next 推进、handoff Return Contract 与时间序、init 状态机与 hook 写白名单、CONTEXT 自动初始化检测、completedChecks 真实性声明机制(skill-load/record/exit 校验 + 交叉自洽 + 旧兼容)、init 参数误用防护、执行遗漏防护、严格模式、验证失败计数按变更隔离、多趟路由依赖图校验(环/缺失依赖 BLOCK 与混排合法锚)、契约解析失败检测、计数一致性自检(场景数 + 系统测试集项数)、prepare-env 平台选择链、零提交边界与入口首部强制、多趟出口硬化(可运行串行放行与拦截双向锚、单行分号 write_files 容错、收尾态路由静默、死结提示与技能文本锁)、installer 新链路(flow-kit 获取五态 / 桥接健康六态 / 他方保持 / 强制回退)、并行文件依赖检测(写写重叠强判前移 plan 出口 + read 读写弱判渐进 + 触发面排除 + 委托前保持锚 + 扩展名闭合)、directOverride 授权约束(协调者授权留痕正例 / 执行者自切无授权 BLOCK / 越界改 state hook 拦截 / 恢复双路径)、hook state 大小写变体拦截(win32/darwin 闭合 / 其他平台放行)、路由完成判定 fail-closed(缺/未知 status 畸形块不提前放行)、并行文件依赖路径归一化(`.` 段变体重叠检出)、运行时文件位置迁移(白名单搬移 / 迁移前备份与回退 / 新旧并存·符号链接·内容损坏三边界 / 失败保护 / gitignore 三形态保守纳管与幂等)、Comet 感知层剥离(classic 资产有无判定一致 / overlay 协议不再进入叠加分支 + 源码符号检索)、自检清单条目缺失显式报告、受控计划重校重签(replan 授权 fail-closed / 轮次上限与显式续轮 / 幂等空操作 / 重签后 execute 出口放行 / 校验不豁免与任务图分析单源锚)与强制推进留痕(advance-forced 事件 / status.forcedNodes 派生视图)、扫描时刻双落点一致(init 侧的形态单一来源 + 漂移可见提示 + 段名/字段名跨文件一致))
|
|
3
3
|
//
|
|
4
4
|
// 每个场景 = 独立临时目录(fs.mkdtemp)+ 伪造 .flow-comet/flow-comet-state.json
|
|
5
5
|
// (currentNode + evidence + executionMode:'subagent',满足前置校验)+
|
|
@@ -143,6 +143,10 @@ const SCENARIO_COUNT_FILES_MAINTAINER = [
|
|
|
143
143
|
'CLAUDE.md',
|
|
144
144
|
];
|
|
145
145
|
const MAINTAINER_DOC_DIR = 'docs/internal';
|
|
146
|
+
// 本仓 CONTEXT 工件(**流程工件面**:.specs/ 被 gitignore)。存在性即「维护者形态」判据——
|
|
147
|
+
// CI 全新检出 / worktree 下结构性缺席,依赖它的场景须输出**可见 SKIP**(未验证 ≠ 通过),
|
|
148
|
+
// 不得把「文件不在场」当成「校验通过」。与 docs/internal/(MAINTAINER_DOC_DIR)同源缺席。
|
|
149
|
+
const REPO_CONTEXT_FILE = path.join(REPO_ROOT, '.specs', 'CONTEXT.md');
|
|
146
150
|
// 三册显式清单(维护文档机检扫描面;与 docs/internal/*.md、.specs/adr/*.md 并列):
|
|
147
151
|
// 知识权威累积面,更新频率高——写入即需校验。显式清单(不用 .specs/*.md 通配)可预测、
|
|
148
152
|
// 可按册 allowlist,未来新增册需手工登记(与计数受检清单同纪律)。
|
|
@@ -2249,7 +2253,624 @@ function vocabularyMirrorProblems(root = REPO_ROOT) {
|
|
|
2249
2253
|
return problems;
|
|
2250
2254
|
}
|
|
2251
2255
|
|
|
2252
|
-
// ----------
|
|
2256
|
+
// ---------- 侧命令锚点材料(evolve / health / context-scan + 到期提示 + ui-design 强制等级) ----------
|
|
2257
|
+
// 三条侧命令与 ui-design 门是横向机制:判据一律走**真实 CLI**(spawn)或**模块导出**(动态导入
|
|
2258
|
+
// 同一实现),套件内不复制第二份判据。零写入判据用**树指纹**(相对路径清单 + 文件 sha256)表达——
|
|
2259
|
+
// 「跑完没变」与「跑前跑后一致」是同一判据的两种说法,此处只实现一次。
|
|
2260
|
+
|
|
2261
|
+
const timeUtilsModule = await import(pathToFileURL(path.join(__dirname, 'time-utils.mjs')).href);
|
|
2262
|
+
const contextInitModule = await import(pathToFileURL(path.join(__dirname, 'context-init.mjs')).href);
|
|
2263
|
+
const stateSchemaModule = await import(pathToFileURL(path.join(__dirname, 'state-schema.mjs')).href);
|
|
2264
|
+
|
|
2265
|
+
const SIDE_EVOLVE = path.join(__dirname, 'evolve.mjs');
|
|
2266
|
+
const SIDE_HEALTH = path.join(__dirname, 'health.mjs');
|
|
2267
|
+
const SIDE_CONTEXT_SCAN = path.join(__dirname, 'context-scan.mjs');
|
|
2268
|
+
const SKILL_PROTOCOL_FILE = path.join(__dirname, '..', 'reference', 'workflow-protocol.json');
|
|
2269
|
+
|
|
2270
|
+
function requireModuleExport(moduleObject, name, where) {
|
|
2271
|
+
const value = moduleObject[name];
|
|
2272
|
+
if (value === undefined) {
|
|
2273
|
+
throw new Error(where + ' 缺导出 ' + name + '(套件锚点前提失效:单一实现被改名 / 移除)');
|
|
2274
|
+
}
|
|
2275
|
+
return value;
|
|
2276
|
+
}
|
|
2277
|
+
|
|
2278
|
+
function assertTrue(condition, message) {
|
|
2279
|
+
if (!condition) throw new Error(message);
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
function assertEqual(actual, expected, label) {
|
|
2283
|
+
if (actual !== expected) {
|
|
2284
|
+
throw new Error(label + ':期望 ' + JSON.stringify(expected) + ',实际 ' + JSON.stringify(actual));
|
|
2285
|
+
}
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
// 侧命令真实调用(cwd = 项目根;--root 由调用方显式传入——侧命令不进 8 节点流程)。
|
|
2289
|
+
// FLOW_COMET_PROTOCOL 注入场景内协议副本,与 runGuard / runStateWithProtocol 同一表达:协议路径的
|
|
2290
|
+
// 唯一权威是 state-schema 的选择器(state.protocolPath > 环境变量 > 内置默认),侧命令的子进程
|
|
2291
|
+
// (workflow-state 通道)因此要看到与门禁同一份协议来源——平台侧注入环境变量正是真实项目形态。
|
|
2292
|
+
// 需要构造「无环境变量」的场景用 `{ FLOW_COMET_PROTOCOL: '' }` 覆盖(空串按未设置处理)。
|
|
2293
|
+
function runSideScript(script, args, root, envOverrides = {}) {
|
|
2294
|
+
const res = spawnSync(process.execPath, [script, ...args], {
|
|
2295
|
+
cwd: root,
|
|
2296
|
+
env: {
|
|
2297
|
+
...process.env,
|
|
2298
|
+
FLOW_COMET_PROTOCOL: path.join(root, 'reference', 'workflow-protocol.json'),
|
|
2299
|
+
...envOverrides,
|
|
2300
|
+
},
|
|
2301
|
+
encoding: 'utf8',
|
|
2302
|
+
timeout: 120000,
|
|
2303
|
+
});
|
|
2304
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
// 树指纹:目录(含空目录)与文件内容的 sha256,按相对路径排序
|
|
2308
|
+
function treeFingerprint(root) {
|
|
2309
|
+
const rows = [];
|
|
2310
|
+
const walk = (dir) => {
|
|
2311
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
2312
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
2313
|
+
for (const entry of entries) {
|
|
2314
|
+
const full = path.join(dir, entry.name);
|
|
2315
|
+
const rel = path.relative(root, full).split(path.sep).join('/');
|
|
2316
|
+
if (entry.isDirectory()) { rows.push(rel + '/'); walk(full); continue; }
|
|
2317
|
+
rows.push(rel + ' ' + createHash('sha256').update(fs.readFileSync(full)).digest('hex'));
|
|
2318
|
+
}
|
|
2319
|
+
};
|
|
2320
|
+
walk(root);
|
|
2321
|
+
return rows.join('\n');
|
|
2322
|
+
}
|
|
2323
|
+
|
|
2324
|
+
function fingerprintChanges(before, after) {
|
|
2325
|
+
const beforeRows = before === '' ? [] : before.split('\n');
|
|
2326
|
+
const afterRows = after === '' ? [] : after.split('\n');
|
|
2327
|
+
const beforeSet = new Set(beforeRows);
|
|
2328
|
+
const afterSet = new Set(afterRows);
|
|
2329
|
+
return [
|
|
2330
|
+
...beforeRows.filter((row) => !afterSet.has(row)).map((row) => '消失: ' + row),
|
|
2331
|
+
...afterRows.filter((row) => !beforeSet.has(row)).map((row) => '新增: ' + row),
|
|
2332
|
+
];
|
|
2333
|
+
}
|
|
2334
|
+
|
|
2335
|
+
// 定义处计数:某名字在本脚本同级目录(引擎脚本目录)内的定义次数——单源结构锚用
|
|
2336
|
+
// 定义面扫描(默认引擎脚本目录)。root 是可测性接缝:使「同名第二份定义 → 检出 2 处」能在合成
|
|
2337
|
+
// 目录上被场景驱动(场景 277 的反向构造),否则该判据只能靠人工实验证明判别力。
|
|
2338
|
+
function engineDefinitionHits(name, root = __dirname) {
|
|
2339
|
+
const pattern = new RegExp('(?:export\\s+)?(?:async\\s+)?function\\s+' + name + '\\b'
|
|
2340
|
+
+ '|(?:export\\s+)?const\\s+' + name + '\\s*=', 'g');
|
|
2341
|
+
const hits = [];
|
|
2342
|
+
for (const file of fs.readdirSync(root).sort()) {
|
|
2343
|
+
if (!file.endsWith('.mjs')) continue;
|
|
2344
|
+
const text = fs.readFileSync(path.join(root, file), 'utf8');
|
|
2345
|
+
const count = (text.match(pattern) ?? []).length;
|
|
2346
|
+
if (count > 0) hits.push({ file, count });
|
|
2347
|
+
}
|
|
2348
|
+
return hits;
|
|
2349
|
+
}
|
|
2350
|
+
|
|
2351
|
+
// 时间单源**消费面**判据(场景 277 使用;纯函数 + 合成输入可驱动):每个符号必须同时满足
|
|
2352
|
+
// 「具名 import 自 time-utils.mjs」与「真实调用」才算真实消费。旧判据只看 `name + '('` 的子串——
|
|
2353
|
+
// 消费脚本里内联一份同名实现即可满足(判据被本地影子实现骗过),故必须查 import 来源。
|
|
2354
|
+
function timeSingleSourceConsumerProblems(text, symbols, file = '') {
|
|
2355
|
+
const problems = [];
|
|
2356
|
+
const prefix = file === '' ? '' : file + ' ';
|
|
2357
|
+
for (const symbol of symbols) {
|
|
2358
|
+
if (!hasNamedImport(text, './time-utils.mjs', symbol)) {
|
|
2359
|
+
problems.push(prefix + '未从 time-utils.mjs 具名 import ' + symbol
|
|
2360
|
+
+ '(单源纪律:不得在消费脚本内联同名第二份实现)');
|
|
2361
|
+
}
|
|
2362
|
+
if (!text.includes(symbol + '(')) {
|
|
2363
|
+
problems.push(prefix + '未真实消费 ' + symbol + '(单一权威应被调用)');
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
return problems;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
// 前端判据**散文口径**判据(场景 286 使用;纯函数 + 合成输入可驱动):引擎侧判据已升为结构形态
|
|
2370
|
+
// (独立行 / 行首 / 适用性标签的字段值位 + 词形边界 + 命中片段回显),五份分发文本是它的散文副本——
|
|
2371
|
+
// 副本必须陈述**结构形态**,不得残留旧口径(「段内不含 / 未标注字面『不适用』」这类把判据说成
|
|
2372
|
+
// 段内任意位置子串的表述,正是「一处措辞即关闸」fail-open 的文字版)。返回问题描述数组。
|
|
2373
|
+
const FRONTEND_CRITERION_STRUCTURE_GROUPS = [
|
|
2374
|
+
['独立行', '独占一行'],
|
|
2375
|
+
['行首'],
|
|
2376
|
+
['字段值位'],
|
|
2377
|
+
['词形边界'],
|
|
2378
|
+
['命中片段', '回显'],
|
|
2379
|
+
];
|
|
2380
|
+
// 旧口径的**显式措辞**(逐条对应改前的真实句子,收窄到这些形态以免误伤新口径的正常行文)。
|
|
2381
|
+
const FRONTEND_CRITERION_STALE_PROSE_RES = [
|
|
2382
|
+
/段内\s*\*{0,2}(?:不含|不包含|未含|不得含|不得出现)\*{0,2}\s*(?:字面\s*)?「?不适用」?/,
|
|
2383
|
+
/段内\s*\*{0,2}(?:标注|标记)\*{0,2}\s*「?不适用」?\s*(?:两个)?字面/,
|
|
2384
|
+
/未标注\s*「不适用」/,
|
|
2385
|
+
/不含\s*字面\s*「不适用」/,
|
|
2386
|
+
];
|
|
2387
|
+
function frontendCriterionProseProblems(label, text) {
|
|
2388
|
+
const problems = [];
|
|
2389
|
+
for (const group of FRONTEND_CRITERION_STRUCTURE_GROUPS) {
|
|
2390
|
+
if (!group.some((token) => text.includes(token))) {
|
|
2391
|
+
problems.push(label + ' 未陈述结构形态「' + group[0] + '」(散文副本须与引擎的结构判据同口径)');
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
for (const re of FRONTEND_CRITERION_STALE_PROSE_RES) {
|
|
2395
|
+
const hit = re.exec(text);
|
|
2396
|
+
if (hit !== null) problems.push(label + ' 残留旧口径表述: ' + JSON.stringify(hit[0]));
|
|
2397
|
+
}
|
|
2398
|
+
return problems;
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
// 时间纪律四条硬规则的**文本判据**(场景 302 使用;纯函数 + 合成输入可驱动):入参是承载该纪律的
|
|
2402
|
+
// 文本(入口技能 / 验证阶梯),按规则逐条检查关键词组合;返回问题描述数组(空数组 = 四条齐备)。
|
|
2403
|
+
// 判别力由场景内的逐条移除构造常驻证明(移掉任一条的关键词 → 必报),不依赖人工实验。
|
|
2404
|
+
const TIME_DISCIPLINE_RULES = [
|
|
2405
|
+
['规则① 时间戳一律本地时间 + 显式偏移', ['本地时间 + 显式偏移']],
|
|
2406
|
+
['规则② 比较一律 Date.parse 差值', ['Date.parse']],
|
|
2407
|
+
['规则③ 判活 / 判时以 mtime 或 git 时间为准、date 不作基准', ['mtime', 'git 时间', '不作基准']],
|
|
2408
|
+
['规则④ 纪律已写入验证阶梯', ['验证阶梯']],
|
|
2409
|
+
];
|
|
2410
|
+
function timeDisciplineTextProblems(label, text) {
|
|
2411
|
+
const problems = [];
|
|
2412
|
+
for (const [rule, tokens] of TIME_DISCIPLINE_RULES) {
|
|
2413
|
+
const missing = tokens.filter((token) => !text.includes(token));
|
|
2414
|
+
if (missing.length > 0) problems.push(label + ' 缺 ' + rule + '(缺 ' + missing.join(' / ') + ')');
|
|
2415
|
+
}
|
|
2416
|
+
return problems;
|
|
2417
|
+
}
|
|
2418
|
+
|
|
2419
|
+
// CRLF 行尾判据(场景 303 使用;纯函数 + 合成输入可驱动):CRLF 文档的**每一条行**都必须以 CRLF
|
|
2420
|
+
// 终结——`split('\n')` 之后除末尾哨兵外每个元素都须以 `\r` 收尾,且文档得以换行收尾。返回违例
|
|
2421
|
+
// 行号(空数组 = 整篇行尾一致)。旧实现在「以换行收尾的文档」上直接于哨兵之后追加,拼出一条
|
|
2422
|
+
// **无 `\r` 的空行**:同一文件两种行尾,渲染层看不见、diff 层刺眼(REVIEW 实测形态)。
|
|
2423
|
+
function crlfLineViolations(text) {
|
|
2424
|
+
const value = String(text);
|
|
2425
|
+
const lines = value.split('\n');
|
|
2426
|
+
const offenders = [];
|
|
2427
|
+
if (!value.endsWith('\n')) offenders.push(lines.length);
|
|
2428
|
+
for (let i = 0; i < lines.length - 1; i += 1) {
|
|
2429
|
+
if (!lines[i].endsWith('\r')) offenders.push(i + 1);
|
|
2430
|
+
}
|
|
2431
|
+
return offenders;
|
|
2432
|
+
}
|
|
2433
|
+
|
|
2434
|
+
// EVOLVE 报告列表符号判据(场景 304 使用;纯函数 + 合成输入可驱动):报告行不得出现 `- -`
|
|
2435
|
+
// 双层列表符号——` - ` 前缀与条目自带的 `- ` 叠加后渲染成「空壳父项 + 子项」,读者看到两条。
|
|
2436
|
+
function evolveReportBulletProblems(reportText) {
|
|
2437
|
+
const problems = [];
|
|
2438
|
+
const lines = String(reportText).split('\n');
|
|
2439
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
2440
|
+
if (/^\s*-\s+-\s/.test(lines[i])) {
|
|
2441
|
+
problems.push('第 ' + (i + 1) + ' 行出现双列表符号: ' + JSON.stringify(lines[i]));
|
|
2442
|
+
}
|
|
2443
|
+
}
|
|
2444
|
+
return problems;
|
|
2445
|
+
}
|
|
2446
|
+
|
|
2447
|
+
// 确定性层「每项都带可复现命令」判据(场景 306 使用,对应验收条款的该子句;纯函数 + 合成输入
|
|
2448
|
+
// 可驱动):确定性层以 `### k · 名称` 分项,每个项内必须随附 `- 复现命令:` 行——项是「机器可判」
|
|
2449
|
+
// 的承诺,复现命令是它的兑现方式:缺一项,该层就有一格不可复核(读数与命令两边只在校验报告里
|
|
2450
|
+
// 出现过一次,读者无法自己重算)。返回问题描述数组(空 = 每项都有)。
|
|
2451
|
+
function deterministicReproProblems(reportText) {
|
|
2452
|
+
const layer = /## 确定性层(机器可判)\n([\s\S]*?)(?=\n## |$)/.exec(String(reportText));
|
|
2453
|
+
if (layer === null) return ['缺「## 确定性层(机器可判)」段'];
|
|
2454
|
+
const chunks = layer[1].split(/\n(?=### )/).filter((chunk) => chunk.startsWith('### '));
|
|
2455
|
+
if (chunks.length === 0) return ['确定性层零个分项(判据无从校验)'];
|
|
2456
|
+
const problems = [];
|
|
2457
|
+
for (const chunk of chunks) {
|
|
2458
|
+
const title = chunk.split('\n')[0].replace(/^###\s*/, '').trim();
|
|
2459
|
+
if (!/^- 复现命令:/m.test(chunk)) problems.push('确定性项缺复现命令: ' + title);
|
|
2460
|
+
}
|
|
2461
|
+
return problems;
|
|
2462
|
+
}
|
|
2463
|
+
|
|
2464
|
+
// 上游覆盖声明四要素判据(场景 307 使用;纯函数 + 合成输入可驱动)。上游语义被本仓有意覆盖,
|
|
2465
|
+
// 声明此前是纯文本、无机检——读者无从判断「说没说清不采用什么」。四要素:
|
|
2466
|
+
// ① 上游文件标记为**只读基准**;② **「不采用」栏** ≥1 条(逐条点名,不是笼统「有意偏离」);
|
|
2467
|
+
// ③ **「沿用上游」栏** ≥1 条(**指针式入口豁免**——细则在各自技能册,入口只留指针);
|
|
2468
|
+
// ④ **「以…为准」兜底语**(冲突时以本节为准)。
|
|
2469
|
+
// 「栏内条目」计数容忍两种行文形态:序号标记(①②③…)与顿号 / 分号列举——技能册一用序号、
|
|
2470
|
+
// 一用顿号,形态差异不是「有没有条目」的差异;判据只锚「栏在场且至少一条」。
|
|
2471
|
+
const OVERRIDE_CLAUSE_ITEM_MARKS = /[①②③④⑤⑥⑦⑧⑨⑩]/g;
|
|
2472
|
+
// 兜底语 = **冲突优先**声明(「以本节为准」式):判据不认任何 `以…为准`——`以安装平台为准`
|
|
2473
|
+
// 一类是无关行文,`冲突以 state 为准` 一类是局部字段优先级,都会被它冒充满足。
|
|
2474
|
+
const OVERRIDE_FALLBACK_RE = /以(?:本节|本册|本文)[^\n。]{0,20}为准|冲突[^\n。]{1,60}为准/;
|
|
2475
|
+
// 声明块 = 「只读基准」所在行起,向后吞掉「空行 / 粗体栏名开头的段落 / 兜底语所在行」,直到首个
|
|
2476
|
+
// 既非空行、也不以 `**` 开头、也不含兜底语的行为止——四要素都必须落在**块内**。没有块边界,
|
|
2477
|
+
// 判据会被文件里别处的 `以…为准` / 局部优先级条款冒充满足(「锚偏弱」的另一种形态)。
|
|
2478
|
+
function overrideDeclarationBlock(text) {
|
|
2479
|
+
const lines = String(text).split('\n');
|
|
2480
|
+
const start = lines.findIndex((line) => line.includes('只读基准'));
|
|
2481
|
+
if (start < 0) return null;
|
|
2482
|
+
let end = start + 1;
|
|
2483
|
+
for (let i = start; i < lines.length; i += 1) {
|
|
2484
|
+
const line = lines[i];
|
|
2485
|
+
if (i > start && line.trim() !== '' && !line.startsWith('**') && !OVERRIDE_FALLBACK_RE.test(line)) break;
|
|
2486
|
+
end = i + 1;
|
|
2487
|
+
}
|
|
2488
|
+
return lines.slice(start, end).join('\n');
|
|
2489
|
+
}
|
|
2490
|
+
function labeledClauseItemCount(text, label) {
|
|
2491
|
+
const value = String(text);
|
|
2492
|
+
const at = value.indexOf(label);
|
|
2493
|
+
if (at < 0) return null;
|
|
2494
|
+
const nextLine = value.indexOf('\n', at);
|
|
2495
|
+
const line = value.slice(at, nextLine < 0 ? value.length : nextLine);
|
|
2496
|
+
// 栏名之后先剥掉自身的粗体闭合与冒号,再截到**下一个栏名**(粗体 + 冒号形态)为止:
|
|
2497
|
+
// 栏内联的粗体强调(`**确定性子集**(…)`)不是栏名,不能当成栏边界。
|
|
2498
|
+
const rest = line.slice(label.length).replace(/^[*::\s]+/, '');
|
|
2499
|
+
const nextLabel = rest.search(/\*\*[^*]{1,20}\*\*\s*[::]/);
|
|
2500
|
+
const body = nextLabel < 0 ? rest : rest.slice(0, nextLabel);
|
|
2501
|
+
const marked = (body.match(OVERRIDE_CLAUSE_ITEM_MARKS) ?? []).length;
|
|
2502
|
+
const listed = body.split(/[、;]/).map((piece) => piece.trim()).filter((piece) => piece.length > 0).length;
|
|
2503
|
+
return Math.max(marked, listed);
|
|
2504
|
+
}
|
|
2505
|
+
function overrideDeclarationProblems(label, text, { pointer = false } = {}) {
|
|
2506
|
+
const problems = [];
|
|
2507
|
+
const block = overrideDeclarationBlock(text);
|
|
2508
|
+
if (block === null) return [label + ' 找不到覆盖声明块(缺「只读基准」标记)'];
|
|
2509
|
+
if (!block.includes('只读基准')) problems.push(label + ' 未把上游文件标记为「只读基准」');
|
|
2510
|
+
const notAdopted = labeledClauseItemCount(block, '不采用');
|
|
2511
|
+
if (notAdopted === null) problems.push(label + ' 缺「不采用」栏');
|
|
2512
|
+
else if (notAdopted === 0) problems.push(label + ' 的「不采用」栏零条目(须逐条点名上游语义)');
|
|
2513
|
+
if (!pointer) {
|
|
2514
|
+
const kept = labeledClauseItemCount(block, '沿用上游');
|
|
2515
|
+
if (kept === null) problems.push(label + ' 缺「沿用上游」栏');
|
|
2516
|
+
else if (kept === 0) problems.push(label + ' 的「沿用上游」栏零条目');
|
|
2517
|
+
}
|
|
2518
|
+
if (!OVERRIDE_FALLBACK_RE.test(block)) {
|
|
2519
|
+
problems.push(label + ' 缺「以…为准」兜底语(冲突时以本节 / 本册为准)');
|
|
2520
|
+
}
|
|
2521
|
+
return problems;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
// 覆盖声明里点名的上游工件路径(`flow-kit/prompts/...` 形态,含 `{a,b,c}.md` 花括号合写):
|
|
2525
|
+
// 逐条展开为可 stat 的真实路径——声明的锚必须指向在场实体,不能指向幽灵路径。尖括号占位形态
|
|
2526
|
+
// (`flow-kit/prompts/<阶段>.md` 一类说明性写法)不是实体,直接排除。
|
|
2527
|
+
function upstreamArtifactPaths(text) {
|
|
2528
|
+
const found = String(text).match(/flow-kit\/prompts\/[^\s`)()、,。]+\.md/g) ?? [];
|
|
2529
|
+
const out = [];
|
|
2530
|
+
for (const raw of found) {
|
|
2531
|
+
if (raw.includes('<') || raw.includes('>')) continue;
|
|
2532
|
+
const brace = /\{([^}]*)\}/.exec(raw);
|
|
2533
|
+
if (brace === null) { out.push(raw); continue; }
|
|
2534
|
+
for (const name of brace[1].split(',')) out.push(raw.replace(brace[0], name.trim()));
|
|
2535
|
+
}
|
|
2536
|
+
return out;
|
|
2537
|
+
}
|
|
2538
|
+
|
|
2539
|
+
// 具名 import 断言(容忍多行 / 符号重排 / 其它符号共存):source 为模块说明符(`./state-schema.mjs`)。
|
|
2540
|
+
// 与场景 154 的内联写法同判据,本处提为复用工具(原子写与元数据常量两处消费面都要断言)。
|
|
2541
|
+
function hasNamedImport(text, source, name) {
|
|
2542
|
+
const pattern = /import\s*\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
2543
|
+
let match;
|
|
2544
|
+
while ((match = pattern.exec(String(text))) !== null) {
|
|
2545
|
+
if (match[2] !== source) continue;
|
|
2546
|
+
const names = match[1].split(',').map((piece) => piece.trim().split(/\s+as\s+/).pop());
|
|
2547
|
+
if (names.includes(name)) return true;
|
|
2548
|
+
}
|
|
2549
|
+
return false;
|
|
2550
|
+
}
|
|
2551
|
+
|
|
2552
|
+
// 原子写惯用法指纹(两条件同现于一个文件):`+ '.tmp'` 拼接 + `fs.rename(` 落位——即「同目录固定
|
|
2553
|
+
// 临时名 + rename」的写法。**收敛面 = 任务写边界内的写盘脚本**(状态/侧命令的state 与文档落盘),
|
|
2554
|
+
// 由调用方显式传入清单:`workflow-guard.mjs` 的受保护写入是**独立的安全硬化通道**(临时名含 pid +
|
|
2555
|
+
// 随机段、写后 fsync 与快照复核、保护目录校验),不属于本惯用法,且不在本任务写边界内——它的
|
|
2556
|
+
// 排除在场景里另有**边界锚**看守(形态一旦退回本惯用法即变红),不是静默跳过。
|
|
2557
|
+
// root 是可测性接缝(默认引擎脚本目录):使「第二份实现 → 检出 2 处」能在合成目录上被场景驱动,
|
|
2558
|
+
// 否则该判据只能靠人工实验证明判别力、回归时可能被改成恒真空过(场景 291 反向构造)。
|
|
2559
|
+
// 套件自身不是引擎写盘面(夹具文本会携带惯用法样例),排除在扫描外。
|
|
2560
|
+
const ATOMIC_TEMP_SUFFIX_RE = /\+\s*'\.tmp'/g;
|
|
2561
|
+
const ENGINE_IDIOM_SCAN_EXCLUDE = new Set(['guard-self-test.mjs', 'system-test.mjs']);
|
|
2562
|
+
function atomicWriteIdiomHits(root = __dirname, files = null) {
|
|
2563
|
+
const candidates = files ?? fs.readdirSync(root).sort()
|
|
2564
|
+
.filter((file) => file.endsWith('.mjs') && !ENGINE_IDIOM_SCAN_EXCLUDE.has(file));
|
|
2565
|
+
const hits = [];
|
|
2566
|
+
for (const file of candidates) {
|
|
2567
|
+
const text = fs.readFileSync(path.join(root, file), 'utf8');
|
|
2568
|
+
const count = (text.match(ATOMIC_TEMP_SUFFIX_RE) ?? []).length;
|
|
2569
|
+
if (count > 0 && text.includes('fs.rename(')) hits.push({ file, count });
|
|
2570
|
+
}
|
|
2571
|
+
return hits;
|
|
2572
|
+
}
|
|
2573
|
+
// 原子写收敛面(本任务写边界内的写盘脚本 + 单源模块):全引擎只应有 state-schema.mjs 一处实现。
|
|
2574
|
+
const ATOMIC_WRITE_CONVERGENCE_FACE = [
|
|
2575
|
+
'state-schema.mjs', 'workflow-state.mjs', 'workflow-handoff.mjs', 'evolve.mjs', 'context-scan.mjs',
|
|
2576
|
+
];
|
|
2577
|
+
|
|
2578
|
+
// 日期前缀判据的**表达式形态**扫描(与原子写惯用法同型):报告 / 工件名的「日期前缀」判定只许由
|
|
2579
|
+
// time-utils.mjs 表达一处——本判据认的形态是「日期三分量以**字面连字符**相接」的前缀写法
|
|
2580
|
+
// (`/^(\d{4}-\d{2}-\d{2})/` 一类),在其它脚本内联第二份即为单源违规(注释互指同源不作数,
|
|
2581
|
+
// 判据只认形态)。时刻形态 `\d{4})-(\d{2})-(\d{2})T…`(`TIMESTAMP_SHAPE`)是另一个判据面,同样
|
|
2582
|
+
// 落在 time-utils 一处,不在本形态内。**收敛面 = 本任务写边界内的日期前缀消费方 + 单源模块**:
|
|
2583
|
+
// `workflow-guard.mjs` 的两处日期匹配是**文档内容**里的日期条目匹配(行锚 + `matchAll(.../gm)`),
|
|
2584
|
+
// 不是文件名前缀判定,且不在本任务写边界内——该排除在场景里另有**边界锚**看守(形态一旦不再是
|
|
2585
|
+
// 内容条目匹配即变红),不是静默跳过。root 是可测性接缝(默认引擎脚本目录):使「第二份实现 →
|
|
2586
|
+
// 检出 2 处」能在合成目录上被场景驱动,否则该判据只能靠人工实验证明判别力、回归时可能被改成
|
|
2587
|
+
// 恒真空过(场景 295 反向构造)。
|
|
2588
|
+
const DATE_PREFIX_LITERAL_RE = /\\d\{4\}-\\d\{2\}-\\d\{2\}/g;
|
|
2589
|
+
const DATE_PREFIX_CONVERGENCE_FACE = ['time-utils.mjs', 'health.mjs', 'context-scan.mjs'];
|
|
2590
|
+
function datePrefixRegexpHits(root = __dirname, files = null) {
|
|
2591
|
+
const candidates = files ?? fs.readdirSync(root).sort().filter((file) => file.endsWith('.mjs'));
|
|
2592
|
+
const hits = [];
|
|
2593
|
+
for (const file of candidates) {
|
|
2594
|
+
const text = fs.readFileSync(path.join(root, file), 'utf8');
|
|
2595
|
+
const count = (text.match(DATE_PREFIX_LITERAL_RE) ?? []).length;
|
|
2596
|
+
if (count > 0) hits.push({ file, count });
|
|
2597
|
+
}
|
|
2598
|
+
return hits;
|
|
2599
|
+
}
|
|
2600
|
+
|
|
2601
|
+
// 备份实现形态(改写前版本落盘):`命名族字面量 + fs.copyFile(` 同现于一个文件即「一份备份实现」。
|
|
2602
|
+
// 收敛面 = 单源模块 state-schema.mjs + 两个消费方:实现只许落在单源模块一处,消费方只许具名
|
|
2603
|
+
// import 后消费导出(此前 evolve 与 context-scan 各写一份——命名族或失败处置再演进时只改到一侧)。
|
|
2604
|
+
// root / files 是可测性接缝(默认引擎脚本目录):使「第二份实现 → 检出 2 处」能在合成目录上被场景
|
|
2605
|
+
// 驱动,否则该判据只能靠人工实验证明判别力、回归时可能被改成恒真空过(场景 301)。
|
|
2606
|
+
const BACKUP_NAME_LITERAL = "'.bak-'";
|
|
2607
|
+
const BACKUP_IMPL_FACE = ['state-schema.mjs', 'evolve.mjs', 'context-scan.mjs'];
|
|
2608
|
+
function inlineBackupHits(root = __dirname, files = null) {
|
|
2609
|
+
const candidates = files ?? fs.readdirSync(root).sort().filter((file) => file.endsWith('.mjs'));
|
|
2610
|
+
const hits = [];
|
|
2611
|
+
for (const file of candidates) {
|
|
2612
|
+
const text = fs.readFileSync(path.join(root, file), 'utf8');
|
|
2613
|
+
if (!text.includes(BACKUP_NAME_LITERAL)) continue;
|
|
2614
|
+
const count = (text.match(/await fs\.copyFile\(/g) ?? []).length;
|
|
2615
|
+
if (count > 0) hits.push({ file, count });
|
|
2616
|
+
}
|
|
2617
|
+
return hits;
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
// 裸时间拼接静态锚(DESIGN R4「禁裸拼接」):时间形态 / 格式化的唯一权威是 time-utils.mjs。
|
|
2621
|
+
// 两面判据——① 三条侧命令**零容忍**(它们的产物是人可见报告、CLI 摘要行与备份名);
|
|
2622
|
+
// ② 其余引擎脚本走**显式白名单 + 逐条理由**:既有落点都是已持久化的机器字段(state 时刻 /
|
|
2623
|
+
// handoff 工件字段 / 审计事件),迁移须连同一批历史值的解析与比较面,留专门窗口并登记债务;
|
|
2624
|
+
// 白名单**精确匹配**(新增与消失都必须显式改这里,不许静默漂移)。判据只看代码不看散文:
|
|
2625
|
+
// 行注释剥掉后计数——注释里的反例引用不是「实现」(time-utils 的头部注释就引用了该形态)。
|
|
2626
|
+
// root / files 是可测性接缝:合成目录可驱动「新增即红」(场景 298)。
|
|
2627
|
+
const BARE_ISO_TIMESTAMP_RE = /new Date\(\)\.toISOString\(\)/g;
|
|
2628
|
+
const BARE_ISO_SIDE_COMMANDS = ['health.mjs', 'evolve.mjs', 'context-scan.mjs'];
|
|
2629
|
+
const BARE_ISO_ENGINE_WHITELIST = [
|
|
2630
|
+
{
|
|
2631
|
+
file: 'workflow-state.mjs',
|
|
2632
|
+
count: 7,
|
|
2633
|
+
reason: 'state 的机器字段时间戳(createdAt / 事件 at / 授权与覆盖时刻):Z 形已随既有 state 与事件流持久化,迁移须同批处理历史值的解析与比较,留专门窗口(登记 KNOWN-ISSUES);扫描时刻(last_intel_scan)已迁出本条——写入走 time-utils 的 nowTimestamp(场景 308 的形态锚 + 277 的单源消费面看守)',
|
|
2634
|
+
},
|
|
2635
|
+
{
|
|
2636
|
+
file: 'workflow-handoff.mjs',
|
|
2637
|
+
count: 4,
|
|
2638
|
+
reason: 'handoff 请求 / 结果的机器字段(requestedAt / revokedAt / completedAt):Z 形是既有 handoff 工件契约,须与 workflow-state 同批迁移',
|
|
2639
|
+
},
|
|
2640
|
+
{
|
|
2641
|
+
file: 'workflow-guard.mjs',
|
|
2642
|
+
count: 1,
|
|
2643
|
+
reason: 'exit-applied 审计事件的机器时刻:非人可见报告面,随事件流时间形态一并迁移',
|
|
2644
|
+
},
|
|
2645
|
+
{
|
|
2646
|
+
file: 'system-test.mjs',
|
|
2647
|
+
count: 1,
|
|
2648
|
+
reason: 'L2 套件夹具构造的 round 覆盖时刻(测试载体,非人可见面):随 state 时间形态迁移批次一并改',
|
|
2649
|
+
},
|
|
2650
|
+
];
|
|
2651
|
+
// intel-scan 元数据「段名 / 字段名」字面量的跨文件一致判据(纯函数 + 合成输入可驱动):双落点判据在
|
|
2652
|
+
// init 侧按「段名 + 字段名」定位段内取值,段行的写通道在 context-scan 侧——同一条命名决定落在两处
|
|
2653
|
+
// 声明里(单一来源收口须改到测试面之外的脚本,见场景 309 的登记)。字面量若各自漂移,init 侧会
|
|
2654
|
+
// **静默**退化成「段不在场」(零提示)——静默面正是该机制要消灭的形态,故此处让「两处声明逐字相等」
|
|
2655
|
+
// 可机检。返回问题描述数组(空数组 = 一致)。
|
|
2656
|
+
const INTEL_NAME_DECL_RE = /const\s+(INTEL_SECTION(?:_NAME)?|INTEL_FIELD(?:_NAME)?)\s*=\s*'([^']+)'/g;
|
|
2657
|
+
function intelMetadataNameDeclarations(text) {
|
|
2658
|
+
const out = {};
|
|
2659
|
+
for (const match of String(text).matchAll(INTEL_NAME_DECL_RE)) {
|
|
2660
|
+
out[match[1].startsWith('INTEL_SECTION') ? 'section' : 'field'] = match[2];
|
|
2661
|
+
}
|
|
2662
|
+
return out;
|
|
2663
|
+
}
|
|
2664
|
+
function intelMetadataNameProblems(consumerText, producerText) {
|
|
2665
|
+
const problems = [];
|
|
2666
|
+
const consumer = intelMetadataNameDeclarations(consumerText);
|
|
2667
|
+
const producer = intelMetadataNameDeclarations(producerText);
|
|
2668
|
+
for (const role of ['section', 'field']) {
|
|
2669
|
+
const label = role === 'section' ? '段名' : '字段名';
|
|
2670
|
+
if (consumer[role] === undefined) { problems.push('init 侧未声明 intel-scan ' + label + '字面量'); continue; }
|
|
2671
|
+
if (producer[role] === undefined) { problems.push('重扫命令侧未声明 intel-scan ' + label + '字面量'); continue; }
|
|
2672
|
+
if (consumer[role] !== producer[role]) {
|
|
2673
|
+
problems.push('intel-scan ' + label + '字面量两处声明不一致: init 侧 ' + JSON.stringify(consumer[role])
|
|
2674
|
+
+ ' / 重扫命令侧 ' + JSON.stringify(producer[role]) + '(段侧定位会静默退化为「段不在场」)');
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
return problems;
|
|
2678
|
+
}
|
|
2679
|
+
|
|
2680
|
+
// 行注释剥离(`//` 之后非代码):判据的语义是「代码里有没有裸拼接」,散文引用不算实现。
|
|
2681
|
+
// 字符串里的 `//`(URL 一类)会把其后内容当注释剥掉——只可能**少计**(判据变松),而白名单面
|
|
2682
|
+
// 另有精确条数锚(13 处)兜底;不为注释识别引入字符串感知的复杂度。
|
|
2683
|
+
function stripLineComments(text) {
|
|
2684
|
+
return text.split('\n').map((line) => {
|
|
2685
|
+
const at = line.indexOf('//');
|
|
2686
|
+
return at === -1 ? line : line.slice(0, at);
|
|
2687
|
+
}).join('\n');
|
|
2688
|
+
}
|
|
2689
|
+
function bareIsoTimestampHits(root = __dirname, files = null) {
|
|
2690
|
+
const candidates = files ?? fs.readdirSync(root).sort().filter((file) => file.endsWith('.mjs'));
|
|
2691
|
+
const hits = [];
|
|
2692
|
+
for (const file of candidates) {
|
|
2693
|
+
const text = stripLineComments(fs.readFileSync(path.join(root, file), 'utf8'));
|
|
2694
|
+
const count = (text.match(BARE_ISO_TIMESTAMP_RE) ?? []).length;
|
|
2695
|
+
if (count > 0) hits.push({ file, count });
|
|
2696
|
+
}
|
|
2697
|
+
return hits;
|
|
2698
|
+
}
|
|
2699
|
+
// 白名单判定(纯函数,合成输入可驱动):条数漂移(增 / 减)与未登记文件各自必报。
|
|
2700
|
+
function bareIsoWhitelistProblems(hits, whitelist) {
|
|
2701
|
+
const problems = [];
|
|
2702
|
+
const actual = new Map(hits.map((hit) => [hit.file, hit.count]));
|
|
2703
|
+
for (const entry of whitelist) {
|
|
2704
|
+
const count = actual.get(entry.file) ?? 0;
|
|
2705
|
+
if (count === entry.count) continue;
|
|
2706
|
+
problems.push(entry.file + ' 白名单 ' + entry.count + ' 处 / 实际 ' + count
|
|
2707
|
+
+ ' 处(须显式改白名单:新增落点先迁移到 time-utils,已迁移的落点同步收窄;理由:' + entry.reason + ')');
|
|
2708
|
+
}
|
|
2709
|
+
for (const hit of hits) {
|
|
2710
|
+
if (whitelist.some((entry) => entry.file === hit.file)) continue;
|
|
2711
|
+
problems.push(hit.file + ' 未登记白名单(' + hit.count
|
|
2712
|
+
+ ' 处)——人可见面禁新增裸时间拼接,改用 time-utils.mjs 的 nowTimestamp / formatLocalTimestamp');
|
|
2713
|
+
}
|
|
2714
|
+
return problems;
|
|
2715
|
+
}
|
|
2716
|
+
|
|
2717
|
+
// health 报告夹具:报告名的日期前缀与读数快照都是**构造出来的输入面**——快照哨兵值只在被采作
|
|
2718
|
+
// 基线时才出现在新报告里(哨兵 → `999999 → …`),据此可判「当前基线到底是哪一份」,不必解析
|
|
2719
|
+
// 报告结构。哨兵键取全小写键(快照行的键形态判据只认小写字母与 `.` / `_`),与既有 `context.exists`
|
|
2720
|
+
// 一类保持一致。
|
|
2721
|
+
function healthReportFixture(date, sentinelEntries) {
|
|
2722
|
+
return [
|
|
2723
|
+
'# 健康巡检 · ' + date,
|
|
2724
|
+
'',
|
|
2725
|
+
'## 读数快照(机器可读 · 供下次报告对比)',
|
|
2726
|
+
'',
|
|
2727
|
+
'```text',
|
|
2728
|
+
'lessons.exists=true',
|
|
2729
|
+
'lessons.entries=' + sentinelEntries,
|
|
2730
|
+
'```',
|
|
2731
|
+
'',
|
|
2732
|
+
'## 与上次对比',
|
|
2733
|
+
'',
|
|
2734
|
+
'- 基线:无(夹具报告)',
|
|
2735
|
+
'',
|
|
2736
|
+
].join('\n');
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
// 读数快照的**往返夹具**:把生产者自己产出的快照段整段(不解析、不重排、不改键名)当作历史
|
|
2740
|
+
// 基线喂回去——写方与读方的键形态是否同源,由「每个产出的键都能被读回」这一往返判定,而不是
|
|
2741
|
+
// 由套件再持一份键形态(第三份表达只会掩盖同一类缺陷)。此前写方发 6 个含大写字母的键、读方的
|
|
2742
|
+
// 键形态正则只认全小写,这 6 个键在对比段恒判「(基线无此读数)」:逐键趋势静默失效且不报错。
|
|
2743
|
+
function healthReportWithSnapshot(date, snapshotSectionText) {
|
|
2744
|
+
return [
|
|
2745
|
+
'# 健康巡检 · ' + date,
|
|
2746
|
+
'',
|
|
2747
|
+
snapshotSectionText.trimEnd(),
|
|
2748
|
+
'',
|
|
2749
|
+
'## 与上次对比',
|
|
2750
|
+
'',
|
|
2751
|
+
'- 基线:无(夹具报告)',
|
|
2752
|
+
'',
|
|
2753
|
+
].join('\n');
|
|
2754
|
+
}
|
|
2755
|
+
// 报告里「## 读数快照」段的原文切片(往返夹具的输入 = 生产面的真实字节)
|
|
2756
|
+
function snapshotSectionOf(reportText) {
|
|
2757
|
+
const start = reportText.indexOf('## 读数快照');
|
|
2758
|
+
if (start === -1) return null;
|
|
2759
|
+
const rest = reportText.slice(start);
|
|
2760
|
+
const end = rest.indexOf('\n## ', 1);
|
|
2761
|
+
return end === -1 ? rest : rest.slice(0, end);
|
|
2762
|
+
}
|
|
2763
|
+
// 快照段内的读数条数(`key=value` 行,排除围栏与空行)——往返判据的「应读到条数」由生产面原文派生
|
|
2764
|
+
function snapshotEntryCount(sectionText) {
|
|
2765
|
+
return sectionText.split('\n').filter((line) => /^[^`\s][^=]*=/.test(line)).length;
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
// CONTEXT.md 夹具(七段骨架 + 可选 evolve 段)——夹具不装 flow-kit 模板时 validateContext
|
|
2769
|
+
// 取内置基准段名;`intel-scan 元数据` / `evolve 元数据` 字段行与模板同形。
|
|
2770
|
+
// 与 system-test.mjs 的同名夹具**同形镜像**(两份载体刻意独立、不互相 import:夹具若从被测模块
|
|
2771
|
+
// 派生,锚点会退化成同义反复)——改段名 / 字段名时必须两份同改(与词表镜像同纪律)。
|
|
2772
|
+
const CONTEXT_BASE_SECTION_NAMES = ['项目概要', '技术栈', '域语言', '已锁决策', '默认偏好', '既有抽象索引'];
|
|
2773
|
+
// 段侧扫描时刻的取值与行尾说明:**真实生成件形态**(`--init-context` 的 CONTEXT 生成物 = 取值词元 +
|
|
2774
|
+
// 行尾说明;写侧 `context-scan` 只替换首个取值词元、说明原样保留)。夹具取这一形态——裸取值词元
|
|
2775
|
+
// 夹具下「读侧取整行剩余文本」的口径缺陷在两级基线下都不可见(见场景 308 的单变量对照)。
|
|
2776
|
+
const INTEL_FIELD_VALUE = '2026-09-01T10:00:00+08:00';
|
|
2777
|
+
const INTEL_FIELD_SUFFIX = ' (首次接入生成时留占位;由 `init --init-context` 或 `context-scan` 记录扫描时间)';
|
|
2778
|
+
const INTEL_METADATA_FIELD_LINES = [
|
|
2779
|
+
'- **last_intel_scan**: ' + INTEL_FIELD_VALUE + INTEL_FIELD_SUFFIX,
|
|
2780
|
+
'- **scanner**: `flow-comet`',
|
|
2781
|
+
'- **下次重扫建议**: 3 个月后',
|
|
2782
|
+
];
|
|
2783
|
+
const EVOLVE_METADATA_FIELD_LINES = [
|
|
2784
|
+
'- **last_evolve_at**: `2026-09-01T10:00:00+08:00`',
|
|
2785
|
+
'- **scanner**: `flow-comet-evolve`',
|
|
2786
|
+
'- **下次建议**: 约 60 天后,或新增 ≥ 5 个带 §9 内容的 change 之后',
|
|
2787
|
+
];
|
|
2788
|
+
|
|
2789
|
+
function contextFixtureText({ evolveSection = null, intelSection = true, tail = '' } = {}) {
|
|
2790
|
+
const lines = ['# 项目上下文', ''];
|
|
2791
|
+
for (const name of CONTEXT_BASE_SECTION_NAMES) {
|
|
2792
|
+
lines.push('## ' + name, '');
|
|
2793
|
+
if (name === '已锁决策') {
|
|
2794
|
+
lines.push('- [2026-09-01] 夹具决策 — 来自 @.specs/CONTEXT.md', '');
|
|
2795
|
+
continue;
|
|
2796
|
+
}
|
|
2797
|
+
if (name === '域语言') {
|
|
2798
|
+
// 域语言段须带模板表格表头(格式判据:`| 术语 | 定义 |`)
|
|
2799
|
+
lines.push('| 术语 | 定义 |', '|---|---|', '| 夹具 | 测试用上下文 |', '');
|
|
2800
|
+
continue;
|
|
2801
|
+
}
|
|
2802
|
+
lines.push('- 夹具条目(' + name + ')', '');
|
|
2803
|
+
}
|
|
2804
|
+
if (intelSection) lines.push('## intel-scan 元数据', '', ...INTEL_METADATA_FIELD_LINES, '');
|
|
2805
|
+
if (evolveSection !== null) lines.push('## evolve 元数据', '', ...evolveSection, '');
|
|
2806
|
+
if (tail !== '') lines.push(tail, '');
|
|
2807
|
+
return lines.join('\n');
|
|
2808
|
+
}
|
|
2809
|
+
|
|
2810
|
+
// 段侧取值的读取口径:结构提取返回的是**整行剩余文本**(取值词元 + markdown 引号 + 行尾说明),
|
|
2811
|
+
// 而写侧(`context-scan` 的 `INTEL_FIELD_LINE`)只替换首个 `(\S+)` 取值词元、说明原样保留——
|
|
2812
|
+
// 断言必须与写侧同口径取词元,否则「带说明行」会被判成不一致(本缺陷的成因即读侧取整行)。
|
|
2813
|
+
function intelFieldToken(value) {
|
|
2814
|
+
return String(value).trim().split(/\s+/)[0].replace(/^`+/, '').replace(/`+$/, '');
|
|
2815
|
+
}
|
|
2816
|
+
|
|
2817
|
+
// design 出口 ui-design 门夹具:CHANGE.md 的「视觉调性」段是结构级前端判据的输入面
|
|
2818
|
+
const VISUAL_TONE_APPLICABLE = '## 视觉调性(Visual Tone)\n\n现代、克制的工具型界面。\n';
|
|
2819
|
+
const VISUAL_TONE_NOT_APPLICABLE = '## 视觉调性(Visual Tone)\n\n不适用(非前端项目)。\n';
|
|
2820
|
+
// 负向标记的另外几种形态(判据不接受裸子串,只接受结构形态):
|
|
2821
|
+
// 行首形态(标记 + 破折号理由,非独立行)
|
|
2822
|
+
const VISUAL_TONE_LINE_HEAD_MARKER = '## 视觉调性(Visual Tone)\n\n不适用 —— CLI 工具,无用户可见界面。\n';
|
|
2823
|
+
// 字段值位(`- 适用性:不适用`)
|
|
2824
|
+
const VISUAL_TONE_FIELD_MARKER = '## 视觉调性(Visual Tone)\n\n- 适用性:不适用(CLI 工具,无用户可见界面)\n';
|
|
2825
|
+
// 子维度字段(标签不是适用性标签)——结构形态在场,但主体是暗色主题,不得关掉整道门
|
|
2826
|
+
const VISUAL_TONE_SUBDIMENSION_FIELD = '## 视觉调性(Visual Tone)\n\n- 选定:克制工具型\n- 暗色主题:不适用\n';
|
|
2827
|
+
// 自然句子(标记词出现在行首与句内,但都不成结构形态)——不得据它把前端 change 改判非前端
|
|
2828
|
+
const VISUAL_TONE_NATURAL_SENTENCE = '## 视觉调性(Visual Tone)\n\n不适用于暗色主题,本 change 仅覆盖浅色分支。\n';
|
|
2829
|
+
|
|
2830
|
+
// ui-design 门键控夹具:以内置协议副本(runGuardWithProtocol 指向的同一路径)为基准改写 design
|
|
2831
|
+
// 节点的 flow-comet-ui-design 绑定——'guarded'(默认形态,写回)/ 'advisory'(等级降级)/
|
|
2832
|
+
// 'absent'(删掉绑定)。协议副本是「门是否在场」的唯一输入面。
|
|
2833
|
+
function writeUiDesignBindingVariant(dir, variant) {
|
|
2834
|
+
const file = scenarioProtocolPath(dir);
|
|
2835
|
+
const protocol = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
2836
|
+
const design = (protocol.nodes ?? []).find((node) => node.id === 'design');
|
|
2837
|
+
if (!design) throw new Error('内置协议缺 design 节点(夹具前提不成立)');
|
|
2838
|
+
const kept = (design.requiredSkillCalls ?? []).filter((call) => call.skill !== 'flow-comet-ui-design');
|
|
2839
|
+
if (variant !== 'absent') {
|
|
2840
|
+
kept.push({
|
|
2841
|
+
skill: 'flow-comet-ui-design', operation: 'require', scope: 'main', enforcement: variant, reason: 'UI-DESIGN(仅前端)',
|
|
2842
|
+
});
|
|
2843
|
+
}
|
|
2844
|
+
design.requiredSkillCalls = kept;
|
|
2845
|
+
fs.writeFileSync(file, JSON.stringify(protocol, null, 2) + '\n');
|
|
2846
|
+
}
|
|
2847
|
+
|
|
2848
|
+
function writeDesignExitFixture(dir, {
|
|
2849
|
+
newChange, visualTone, uiDesign, declareUiDesign, changeName = CHANGE_ID, changeTail = '', declareDesign = true,
|
|
2850
|
+
}) {
|
|
2851
|
+
writeFile(dir, 'flow-kit/templates/DESIGN.md', '# DESIGN 模板\n\n## 0. 技术栈选型\n## 1. 技术决策清单\n');
|
|
2852
|
+
const state = baseState('design');
|
|
2853
|
+
state.newChange = newChange === true;
|
|
2854
|
+
state.enteredNodes = ['design'];
|
|
2855
|
+
const checks = [];
|
|
2856
|
+
if (declareDesign) checks.push('required-skill:design.flow-comet-design');
|
|
2857
|
+
if (declareUiDesign) checks.push('required-skill:design.flow-comet-ui-design');
|
|
2858
|
+
state.evidence.design = { summary: 'design done', completedChecks: checks };
|
|
2859
|
+
writeState(dir, state);
|
|
2860
|
+
writeFile(dir, '.specs/' + changeName + '/CHANGE.md',
|
|
2861
|
+
'# CHANGE\n\n- **Change ID**: ' + changeName + '\n\n## Why(为什么做)\n\n夹具。\n\n' + visualTone + changeTail);
|
|
2862
|
+
writeFile(dir, '.specs/' + changeName + '/DESIGN.md',
|
|
2863
|
+
'# DESIGN\n\n- **Change ID**: ' + changeName + '\n\n## 0. 技术栈选型\n\nNode(纯脚本)\n\n## 1. 技术决策清单\n\n- [ ] 决策 1\n');
|
|
2864
|
+
if (uiDesign) {
|
|
2865
|
+
writeFile(dir, '.specs/' + changeName + '/UI-DESIGN.md',
|
|
2866
|
+
'# UI-DESIGN\n\n## 1. 设计 token\n\n- 主色 `oklch(0.6 0.1 250)`\n');
|
|
2867
|
+
} else {
|
|
2868
|
+
// 同一目录里连续构造四个子用例:缺席必须真实缺席(残留上一用例的工件会让缺件门形同虚设)
|
|
2869
|
+
fs.rmSync(path.join(dir, '.specs', changeName, 'UI-DESIGN.md'), { force: true });
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
|
|
2873
|
+
// ---------- 场景表 ----------
|
|
2253
2874
|
|
|
2254
2875
|
const SCENARIOS = [
|
|
2255
2876
|
// 1: open exit 通过(模板段名 CHANGE "## Why(为什么做)" + REQUIREMENT "## 用户故事(User Story)" + 验收段)——带模板验证 C2 派生
|
|
@@ -5752,16 +6373,8 @@ const SCENARIOS = [
|
|
|
5752
6373
|
assertOut(res, 'SINGLE SOURCE OK');
|
|
5753
6374
|
|
|
5754
6375
|
// ===== F-3(AC-5):三消费脚本 execute 家族成员单一来源静态锁 ====
|
|
5755
|
-
// ① import
|
|
5756
|
-
|
|
5757
|
-
const hasNamedImport = (text, source, name) => {
|
|
5758
|
-
importRe.lastIndex = 0;
|
|
5759
|
-
let m;
|
|
5760
|
-
while ((m = importRe.exec(text)) !== null) {
|
|
5761
|
-
if (m[2] === source && m[1].split(',').some((s) => s.trim() === name)) return true;
|
|
5762
|
-
}
|
|
5763
|
-
return false;
|
|
5764
|
-
};
|
|
6376
|
+
// ① import 断言走模块级 hasNamedImport(同一判据只实现一次——本场景原先内联了同形闭包,
|
|
6377
|
+
// 两处实现会在容忍面上漂移)。
|
|
5765
6378
|
// ② 内联 pair 检测器:`=== 'execute'` 与 `=== 'subagent-execute'` 经 `||` 直连(正反顺序)。
|
|
5766
6379
|
// 只命中双侧 === || === 组合;单节点分支(&& / 单 compare)、协议判定、证据键不命中
|
|
5767
6380
|
//(下方合成正/负例自锚,防检测器退化为永不生效或误伤允许形态)。
|
|
@@ -13646,6 +14259,2078 @@ const SCENARIOS = [
|
|
|
13646
14259
|
}
|
|
13647
14260
|
},
|
|
13648
14261
|
},
|
|
14262
|
+
|
|
14263
|
+
// 276: 时间形态三态——本地 `+HH:mm` 与历史 `Z`(含毫秒)合法且解析等值;纯日期 / 缺时区 /
|
|
14264
|
+
// 偏移缺冒号 / 日历不自洽(2026-02-30,Date.parse 会静默滚动)一律非法。判据走 time-utils
|
|
14265
|
+
// 的导出(与消费脚本同一实现,不在套件里复制第二份)。
|
|
14266
|
+
{
|
|
14267
|
+
name: '276 时间形态三态:本地 +HH:mm / 历史 Z(含毫秒)合法等值,形态不符与日历不自洽非法',
|
|
14268
|
+
run: () => {
|
|
14269
|
+
const parse = requireModuleExport(timeUtilsModule, 'parseTimestamp', 'time-utils.mjs');
|
|
14270
|
+
const format = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
14271
|
+
const isValid = requireModuleExport(timeUtilsModule, 'isValidTimestamp', 'time-utils.mjs');
|
|
14272
|
+
|
|
14273
|
+
const localWithOffset = '2026-10-02T18:30:00+08:00';
|
|
14274
|
+
const zulu = '2026-10-02T10:30:00Z';
|
|
14275
|
+
const zuluMillis = '2026-10-02T10:30:00.500Z';
|
|
14276
|
+
assertEqual(parse(localWithOffset), Date.parse(localWithOffset), '本地 +HH:mm 形态解析');
|
|
14277
|
+
assertEqual(parse(zulu), Date.parse(zulu), '历史 Z 形态解析');
|
|
14278
|
+
assertEqual(parse(zuluMillis), Date.parse(zuluMillis), '历史 Z + 毫秒解析');
|
|
14279
|
+
assertEqual(parse(localWithOffset), parse(zulu), '同一时刻的两种形态解析等值');
|
|
14280
|
+
assertEqual(parse(zuluMillis) - parse(zulu), 500, '毫秒分量参与解析');
|
|
14281
|
+
|
|
14282
|
+
const illegal = [
|
|
14283
|
+
['2026-10-02', '纯日期(无法表达时刻)'],
|
|
14284
|
+
['2026-10-02T10:30:00', '缺时区'],
|
|
14285
|
+
['2026-10-02T10:30:00+0800', '偏移缺冒号'],
|
|
14286
|
+
['2026-10-02T10:30:00+24:00', '偏移越界'],
|
|
14287
|
+
['2026-10-02T10:30:00-08:60', '偏移分钟越界'],
|
|
14288
|
+
['2026-02-30T00:00:00Z', '日历不自洽'],
|
|
14289
|
+
['2026-13-01T00:00:00Z', '月份越界'],
|
|
14290
|
+
['不是时间', '垃圾值'],
|
|
14291
|
+
['', '空串'],
|
|
14292
|
+
[null, '非字符串'],
|
|
14293
|
+
];
|
|
14294
|
+
for (const [value, label] of illegal) {
|
|
14295
|
+
assertTrue(Number.isNaN(parse(value)),
|
|
14296
|
+
'非法形态未被拒绝: ' + label + ' = ' + JSON.stringify(value));
|
|
14297
|
+
assertTrue(!isValid(value), 'isValidTimestamp 未拒绝非法形态: ' + label);
|
|
14298
|
+
}
|
|
14299
|
+
|
|
14300
|
+
// 生成侧:本地时间 + 显式偏移;生成 → 解析回环等值(秒级精度)
|
|
14301
|
+
const instant = Date.parse('2026-10-02T10:30:15Z');
|
|
14302
|
+
const formatted = format(new Date(instant));
|
|
14303
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(formatted),
|
|
14304
|
+
'生成形态非「本地时间 + 显式偏移」: ' + formatted);
|
|
14305
|
+
assertEqual(parse(formatted), instant, '生成 → 解析回环');
|
|
14306
|
+
},
|
|
14307
|
+
},
|
|
14308
|
+
|
|
14309
|
+
// 277: 单源结构锚——时间与窗口判据(formatLocalTimestamp / nowTimestamp / parseTimestamp /
|
|
14310
|
+
// hasSection9 / isArchivedAfterTimestamp)在全引擎**各只有一处定义**,且四个消费脚本一律从
|
|
14311
|
+
// time-utils 取值(含 init 写扫描时刻的 nowTimestamp:形态单一来源是双落点一致的形态前提)。
|
|
14312
|
+
// 判别力边界(修正旧注释的夸大——「第二份内联实现必然让本场景变红」只在**同名**时成立):
|
|
14313
|
+
// ① 定义面按**同名定义**计数:同名第二份实现(函数声明 / const 箭头)即变红;
|
|
14314
|
+
// ② 消费面按**具名 import 自 time-utils.mjs + 真实调用**判定(不是纯文本存在性):消费脚本
|
|
14315
|
+
// 内联同名实现顶替导出会变红——旧判据 `text.includes(name + '(')` 会被内联同名实现满足,
|
|
14316
|
+
// 属假绿形态(本锚升级的正是这半边);
|
|
14317
|
+
// ③ **不在本锚覆盖内**:与单源导出**不同名**、且消费方仍保留一次真实调用的等价内联实现——
|
|
14318
|
+
// 那类形态由各判据族的形态锚分族承担(如 295 日期前缀 / 298 裸拼接),本锚不冒充覆盖它。
|
|
14319
|
+
// 判别力由两条合成反向构造常驻证明(同名第二份定义 / 未具名 import 的内联实现)。
|
|
14320
|
+
{
|
|
14321
|
+
name: '277 单源结构锚:时间与窗口判据全引擎各一处定义,四个消费脚本零内联',
|
|
14322
|
+
run: () => {
|
|
14323
|
+
const singleSource = ['formatLocalTimestamp', 'nowTimestamp', 'parseTimestamp', 'hasSection9', 'isArchivedAfterTimestamp'];
|
|
14324
|
+
for (const name of singleSource) {
|
|
14325
|
+
const hits = engineDefinitionHits(name);
|
|
14326
|
+
assertEqual(hits.length, 1, name + ' 的定义面数量(全引擎应恰 1 处)实际 ' + JSON.stringify(hits));
|
|
14327
|
+
assertEqual(hits[0].file, 'time-utils.mjs', name + ' 的定义文件');
|
|
14328
|
+
assertEqual(hits[0].count, 1, name + ' 在 ' + hits[0].file + ' 内的定义处数');
|
|
14329
|
+
}
|
|
14330
|
+
const consumers = {
|
|
14331
|
+
'workflow-state.mjs': ['isValidTimestamp', 'daysSince', 'hasSection9', 'isArchivedAfterTimestamp', 'nowTimestamp', 'parseTimestamp'],
|
|
14332
|
+
'evolve.mjs': ['parseTimestamp', 'hasSection9', 'isArchivedAfterTimestamp', 'nowTimestamp'],
|
|
14333
|
+
'context-scan.mjs': ['nowTimestamp', 'formatLocalDate', 'archiveDateFromName'],
|
|
14334
|
+
'health.mjs': ['formatLocalTimestamp', 'formatLocalDate'],
|
|
14335
|
+
};
|
|
14336
|
+
for (const [file, symbols] of Object.entries(consumers)) {
|
|
14337
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
14338
|
+
const problems = timeSingleSourceConsumerProblems(text, symbols, file);
|
|
14339
|
+
assertEqual(problems.length, 0, '消费面单源违规: ' + problems.join(' | '));
|
|
14340
|
+
}
|
|
14341
|
+
|
|
14342
|
+
// 反向构造 ①(合成目录 · 纯函数):同名第二份定义 → 定义面检出 2(判据不恒真空过)。
|
|
14343
|
+
// 样例经拼接构造,避免套件自身源码携带定义形态字面量而污染真实面计数(本套件同样在扫描面内)。
|
|
14344
|
+
const definitionSample = (name) => 'function ' + name + '(date) { return String(date); }\n';
|
|
14345
|
+
const synthetic = makeTmp();
|
|
14346
|
+
try {
|
|
14347
|
+
writeFile(synthetic, 'single.mjs', definitionSample('formatLocalTimestamp'));
|
|
14348
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', synthetic).length, 1, '合成目录单份定义检出数');
|
|
14349
|
+
writeFile(synthetic, 'second.mjs', definitionSample('formatLocalTimestamp'));
|
|
14350
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', synthetic).length, 2,
|
|
14351
|
+
'合成目录同名第二份定义检出数(判据须变红)');
|
|
14352
|
+
} finally {
|
|
14353
|
+
cleanupTmpDir(synthetic);
|
|
14354
|
+
}
|
|
14355
|
+
|
|
14356
|
+
// 反向构造 ②(合成文本 · 纯函数):内联同名实现顶替导出——旧子串判据会放过、本锚必须拒绝;
|
|
14357
|
+
// 另两态证明判据不恒真(具名 import 但零调用 → 必报;具名 import + 真实调用 → 零问题)。
|
|
14358
|
+
// 同一拼接纪律:调用形态的 `name + '('` 可以字面出现(它不是定义形态),定义形态不可。
|
|
14359
|
+
const inlined = 'function ' + 'parseTimestamp(text) {\n return Date.parse(text);\n}\n'
|
|
14360
|
+
+ "parseTimestamp('2026-10-02T10:00:00+08:00');\n";
|
|
14361
|
+
assertTrue(inlined.includes('parseTimestamp('), '反向构造前提不成立:旧子串判据本应命中内联实现');
|
|
14362
|
+
const inlinedProblems = timeSingleSourceConsumerProblems(inlined, ['parseTimestamp'], 'synthetic.mjs');
|
|
14363
|
+
assertTrue(inlinedProblems.some((problem) => problem.includes('未从 time-utils.mjs 具名 import')),
|
|
14364
|
+
'内联同名实现未被判违规(旧判据的假绿形态): ' + JSON.stringify(inlinedProblems));
|
|
14365
|
+
const importedOnly = "import { parseTimestamp } from './time-utils.mjs';\nconst unused = 1;\n";
|
|
14366
|
+
assertTrue(timeSingleSourceConsumerProblems(importedOnly, ['parseTimestamp'], 'synthetic.mjs')
|
|
14367
|
+
.some((problem) => problem.includes('未真实消费')), '具名 import 但零调用未被判违规');
|
|
14368
|
+
const genuine = "import { parseTimestamp } from './time-utils.mjs';\n"
|
|
14369
|
+
+ 'export const instant = (value) => parseTimestamp(value);\n';
|
|
14370
|
+
assertEqual(timeSingleSourceConsumerProblems(genuine, ['parseTimestamp'], 'synthetic.mjs').length, 0,
|
|
14371
|
+
'具名 import + 真实调用不应被判违规');
|
|
14372
|
+
},
|
|
14373
|
+
},
|
|
14374
|
+
|
|
14375
|
+
// 278: evolve 增量窗口与历史 `Z` 兼容——窗口内入选 / 窗口外排除 / 无基线全量;扫描严格限定在
|
|
14376
|
+
// 设计文档的沉淀段(其它段的标记串不得出现在输出);`scan` 零写入用树指纹对照。
|
|
14377
|
+
{
|
|
14378
|
+
name: '278 evolve 窗口:窗口内入选·窗口外排除·无基线全量 + 历史 Z 兼容 + 只读沉淀段 + 零写入',
|
|
14379
|
+
run: (dir) => {
|
|
14380
|
+
writeFile(dir, '.specs/archive/2026-08-20-old/DESIGN.md',
|
|
14381
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
|
|
14382
|
+
writeFile(dir, '.specs/archive/2026-09-10-new/DESIGN.md',
|
|
14383
|
+
'# DESIGN\n\n## 5. 其它段\n\nOTHER-SECTION-MARKER\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
|
|
14384
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14385
|
+
const state = baseState('open');
|
|
14386
|
+
state.last_evolve_at = '2026-09-01T00:00:00Z'; // 历史 Z 形态基线
|
|
14387
|
+
writeState(dir, state);
|
|
14388
|
+
|
|
14389
|
+
const before = treeFingerprint(dir);
|
|
14390
|
+
const res = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
14391
|
+
assertExit(res, 0);
|
|
14392
|
+
assertOut(res, 'EVOLVE: 扫描');
|
|
14393
|
+
assertOut(res, '窗口 起始 = 2026-09-01T00:00:00Z');
|
|
14394
|
+
assertOut(res, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
|
|
14395
|
+
assertOut(res, '2026-09-10-new#1');
|
|
14396
|
+
assertNotOut(res, '2026-08-20-old#');
|
|
14397
|
+
assertNotOut(res, 'OTHER-SECTION-MARKER'); // 只读沉淀段:其它段的标记串不进候选
|
|
14398
|
+
const written = fingerprintChanges(before, treeFingerprint(dir));
|
|
14399
|
+
assertEqual(written.length, 0, 'scan 必须零写入,实际树变化: ' + JSON.stringify(written));
|
|
14400
|
+
|
|
14401
|
+
// 等值的 `+00:00` 形态给出同一窗口(兼容历史 Z 与本地偏移两种写法,不是两套语义)
|
|
14402
|
+
const offsetState = { ...state, last_evolve_at: '2026-09-01T00:00:00+00:00' };
|
|
14403
|
+
writeState(dir, offsetState);
|
|
14404
|
+
const offsetRes = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
14405
|
+
assertExit(offsetRes, 0);
|
|
14406
|
+
assertOut(offsetRes, '窗口 起始 = 2026-09-01T00:00:00+00:00');
|
|
14407
|
+
assertOut(offsetRes, '窗口内 1 个');
|
|
14408
|
+
assertNotOut(offsetRes, '上次沉淀时间不可解析');
|
|
14409
|
+
|
|
14410
|
+
// 不可解析的基线 → 显式按全量扫描(不静默当成「无新增」)
|
|
14411
|
+
writeState(dir, { ...state, last_evolve_at: '不是时间' });
|
|
14412
|
+
const broken = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
14413
|
+
assertExit(broken, 0);
|
|
14414
|
+
assertOut(broken, '上次沉淀时间不可解析(按全量扫描)');
|
|
14415
|
+
assertOut(broken, '窗口内 2 个');
|
|
14416
|
+
|
|
14417
|
+
// 无基线(字段缺席)→ 全量扫描
|
|
14418
|
+
writeState(dir, baseState('open'));
|
|
14419
|
+
const noBaseline = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
14420
|
+
assertExit(noBaseline, 0);
|
|
14421
|
+
assertOut(noBaseline, '无基线(首次运行,全量扫描)');
|
|
14422
|
+
assertOut(noBaseline, '窗口内 2 个');
|
|
14423
|
+
assertOut(noBaseline, '2026-08-20-old#1');
|
|
14424
|
+
},
|
|
14425
|
+
},
|
|
14426
|
+
|
|
14427
|
+
// 279: 到期提示两因与静默——「距今 > 60 天」或「该时刻之后新增 ≥ 5 个带 §9 的归档 change」
|
|
14428
|
+
// 达阈值即输出 `EVOLVE-DUE`(提示行不含花括号,status 的 JSON 块仍可被既有消费方解析);
|
|
14429
|
+
// 未达阈值 / 字段缺席(从未跑过 evolve)一律零输出;非法值经 `config set` 写入 → BLOCKED 零改写。
|
|
14430
|
+
{
|
|
14431
|
+
name: '279 到期提示:按天数·按新增数达阈值提示,未达阈值与字段缺席静默,JSON 块可解析',
|
|
14432
|
+
run: (dir) => {
|
|
14433
|
+
const formatStamp = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
14434
|
+
const formatDate = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs');
|
|
14435
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
14436
|
+
const stampDaysAgo = (days) => formatStamp(new Date(Date.now() - days * dayMs));
|
|
14437
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/CHANGE.md', '# CHANGE\n\n## Why(为什么做)\n\n夹具。\n');
|
|
14438
|
+
|
|
14439
|
+
// ① 按天数:距今 100 天 → 提示行 + JSON 块仍可解析
|
|
14440
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: stampDaysAgo(100) });
|
|
14441
|
+
const aged = runStateWithProtocol(dir, ['status']);
|
|
14442
|
+
assertExit(aged, 0);
|
|
14443
|
+
assertOut(aged, 'EVOLVE-DUE: 上次架构沉淀');
|
|
14444
|
+
assertOut(aged, '超阈值 60 天');
|
|
14445
|
+
assertEqual(parseStatusJson(aged).status, 'running', '提示行在场时 status 的 JSON 块解析');
|
|
14446
|
+
|
|
14447
|
+
// ② 未达阈值(新鲜)→ 静默;③ 字段缺席(从未跑过 evolve)→ 同样静默
|
|
14448
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: stampDaysAgo(1) });
|
|
14449
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
14450
|
+
writeState(dir, baseState('open'));
|
|
14451
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
14452
|
+
|
|
14453
|
+
// ④ 按新增数:基线之后 5 个带 §9 的归档 change → 提示;取走一个(4 个)→ 静默
|
|
14454
|
+
const baselineMs = Date.now() - 30 * dayMs;
|
|
14455
|
+
const baselineStamp = formatStamp(new Date(baselineMs));
|
|
14456
|
+
const archiveDirName = (offsetDays) => formatDate(new Date(baselineMs + offsetDays * dayMs)) + '-new-' + offsetDays;
|
|
14457
|
+
for (let offset = 1; offset <= 5; offset += 1) {
|
|
14458
|
+
writeFile(dir, '.specs/archive/' + archiveDirName(offset) + '/DESIGN.md',
|
|
14459
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 条目 ' + offset + '\n');
|
|
14460
|
+
}
|
|
14461
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: baselineStamp });
|
|
14462
|
+
const byCount = runStateWithProtocol(dir, ['status']);
|
|
14463
|
+
assertExit(byCount, 0);
|
|
14464
|
+
assertOut(byCount, 'EVOLVE-DUE: 上次架构沉淀');
|
|
14465
|
+
assertOut(byCount, '其后新增 5 个带 §9 的归档 change,达阈值 5 个');
|
|
14466
|
+
parseStatusJson(byCount);
|
|
14467
|
+
fs.rmSync(path.join(dir, '.specs', 'archive', archiveDirName(5)), { recursive: true, force: true });
|
|
14468
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
14469
|
+
|
|
14470
|
+
// ⑤ 非法值经唯一写通道写入 → BLOCKED 且 state 字节零改写
|
|
14471
|
+
const beforeBytes = readStateBytes(dir);
|
|
14472
|
+
const illegal = runStateWithProtocol(dir, ['config', 'set', 'last_evolve_at', '2026-02-30T00:00:00Z']);
|
|
14473
|
+
assertExit(illegal, 1);
|
|
14474
|
+
assertOut(illegal, 'BLOCKED');
|
|
14475
|
+
assertOut(illegal, 'last_evolve_at');
|
|
14476
|
+
assertStateBytesUnchanged(dir, beforeBytes, 'last_evolve_at 非法值');
|
|
14477
|
+
},
|
|
14478
|
+
},
|
|
14479
|
+
|
|
14480
|
+
// 280: health 复现性——同一冻结树两次运行,差异必须落在报告的「易变行声明」集合内(声明的
|
|
14481
|
+
// 差异集合之外逐字节一致);`--stdout` 与落盘逐字节相同;state 零改写(报告是唯一写入面)。
|
|
14482
|
+
{
|
|
14483
|
+
name: '280 health 两次运行:易变行声明之外逐字节一致 + --stdout 与落盘相同 + state 零改写',
|
|
14484
|
+
run: (dir) => {
|
|
14485
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14486
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
|
|
14487
|
+
writeState(dir, baseState('open'));
|
|
14488
|
+
const stateBytes = readStateBytes(dir);
|
|
14489
|
+
|
|
14490
|
+
const first = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
14491
|
+
assertExit(first, 0);
|
|
14492
|
+
assertOut(first, '## 确定性层(机器可判)');
|
|
14493
|
+
assertOut(first, '### 1 · 项目上下文一致性');
|
|
14494
|
+
assertOut(first, '### 2 · 经验条目编号连续性');
|
|
14495
|
+
assertOut(first, '- 缺失编号(0):无');
|
|
14496
|
+
assertOut(first, '## 增补层(代码体检工具的 4 维结果 · 可选)');
|
|
14497
|
+
assertOut(first, '## 降级声明');
|
|
14498
|
+
assertOut(first, '## 易变行声明(两次运行的允许差异集合)');
|
|
14499
|
+
|
|
14500
|
+
const second = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
14501
|
+
assertExit(second, 0);
|
|
14502
|
+
const volatilePrefixes = ['- **生成时间**:', '- 最近 30 天提交数:'];
|
|
14503
|
+
const firstLines = first.output.split('\n');
|
|
14504
|
+
const secondLines = second.output.split('\n');
|
|
14505
|
+
const differing = [];
|
|
14506
|
+
for (let i = 0; i < Math.max(firstLines.length, secondLines.length); i += 1) {
|
|
14507
|
+
if (firstLines[i] === secondLines[i]) continue;
|
|
14508
|
+
const line = firstLines[i] ?? secondLines[i] ?? '';
|
|
14509
|
+
if (volatilePrefixes.some((prefix) => line.startsWith(prefix))) continue;
|
|
14510
|
+
differing.push('第 ' + (i + 1) + ' 行 ' + JSON.stringify(firstLines[i]) + ' → ' + JSON.stringify(secondLines[i]));
|
|
14511
|
+
}
|
|
14512
|
+
assertEqual(differing.length, 0, '两次运行的差异落在易变行声明之外: ' + differing.join(' | '));
|
|
14513
|
+
|
|
14514
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
14515
|
+
const reportFile = path.join(dir, '.specs', 'health', today + '-HEALTH.md');
|
|
14516
|
+
assertTrue(fs.existsSync(reportFile), '报告未按 <日期>-HEALTH.md 形态落盘: ' + reportFile);
|
|
14517
|
+
// `--stdout` = 落盘报告正文原样在前 + `HEALTH:` 审计行追加在后:审计行是 CLI 摘要而非报告
|
|
14518
|
+
// 内容,不进报告字节(报告仍是唯一写入面);正文部分与落盘逐字节一致。
|
|
14519
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
14520
|
+
assertTrue(second.output.startsWith(reportText),
|
|
14521
|
+
'--stdout 的报告正文应与落盘逐字节一致(审计行追加在后): ' + JSON.stringify(second.output.slice(0, 120)));
|
|
14522
|
+
assertOut(second, 'HEALTH: 报告 `.specs/health/' + today + '-HEALTH.md`');
|
|
14523
|
+
assertOut(second, 'HEALTH-DONE');
|
|
14524
|
+
assertOut(second, '- **写入边界**:只写本报告文件;不改代码、不写运行状态文件(本命令不新增任何状态字段)');
|
|
14525
|
+
assertStateBytesUnchanged(dir, stateBytes, 'health 运行后');
|
|
14526
|
+
// 同日重跑不与自己对比(否则报告自我污染、复现性判据失效)
|
|
14527
|
+
assertOut(second, '基线:无(`.specs/health` 下无日期不同的历史报告)');
|
|
14528
|
+
},
|
|
14529
|
+
},
|
|
14530
|
+
|
|
14531
|
+
// 281: health 缺可选工具的两态之一——隔离 HOME/USERPROFILE(用户级插件缓存与用户技能目录
|
|
14532
|
+
// 都落主目录)→ 增补层逐项不在场、降级声明可见,确定性层照常完整、退出码 0(可选工具缺席
|
|
14533
|
+
// 不构成失败;本机实际装有 brooks,故须隔离而不是假设)。
|
|
14534
|
+
{
|
|
14535
|
+
name: '281 health 隔离 HOME:增补层逐项不在场 + 降级声明可见 + 确定性层完整 + exit 0',
|
|
14536
|
+
run: (dir) => {
|
|
14537
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14538
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
14539
|
+
const isolatedHome = path.join(dir, 'isolated-home');
|
|
14540
|
+
fs.mkdirSync(isolatedHome, { recursive: true });
|
|
14541
|
+
|
|
14542
|
+
const isolated = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir,
|
|
14543
|
+
{ HOME: isolatedHome, USERPROFILE: isolatedHome });
|
|
14544
|
+
assertExit(isolated, 0);
|
|
14545
|
+
assertOut(isolated, '- **在场判定**:不在场——下列探测面逐项未命中(未安装 / 未加载)');
|
|
14546
|
+
assertOut(isolated, 'Claude Code 插件缓存(用户级)');
|
|
14547
|
+
assertOut(isolated, '- **降级**:4 维结果缺省;报告只由确定性层构成(判据不因缺可选工具而失败)');
|
|
14548
|
+
assertOut(isolated, '- **brooks-lint**:不可用——探测面逐项未命中');
|
|
14549
|
+
assertOut(isolated, '## 确定性层(机器可判)');
|
|
14550
|
+
assertOut(isolated, '### 5 · 版本历史统计(git)');
|
|
14551
|
+
assertOut(isolated, '缺席不影响本命令成功(退出码 0)');
|
|
14552
|
+
|
|
14553
|
+
// 对照:未隔离运行同样以完整报告 + 退出码 0 收尾(在场与否随环境,报告形态不变)
|
|
14554
|
+
const openEnv = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
14555
|
+
assertExit(openEnv, 0);
|
|
14556
|
+
assertOut(openEnv, '- **探测面(固定清单 · 逐项判定)**:');
|
|
14557
|
+
assertOut(openEnv, '## 确定性层(机器可判)');
|
|
14558
|
+
},
|
|
14559
|
+
},
|
|
14560
|
+
|
|
14561
|
+
// 282: context-scan 首次无基线与二次差异——首次显式声明「本次为基线,无差异可比」;第二次
|
|
14562
|
+
// 逐项比对出新增;同一秒连续重扫不得误 BLOCK;双落点(state 的 last_intel_scan 与 CONTEXT
|
|
14563
|
+
// 的 `## intel-scan 元数据` 字段)取值一致;工件含机器快照标记。
|
|
14564
|
+
{
|
|
14565
|
+
name: '282 context-scan 首次无基线 → 二次差异:新增可比 + 同秒重扫 exit 0 + 双落点一致',
|
|
14566
|
+
run: (dir) => {
|
|
14567
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14568
|
+
writeState(dir, baseState('open'));
|
|
14569
|
+
|
|
14570
|
+
const first = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
14571
|
+
assertExit(first, 0);
|
|
14572
|
+
assertOut(first, 'CONTEXT-SCAN: 基线 无(本次为基线,无差异可比)');
|
|
14573
|
+
assertOut(first, 'CONTEXT-SCAN: 差异 无(本次为基线,无差异可比)');
|
|
14574
|
+
assertOut(first, 'CONTEXT-SCAN-DONE');
|
|
14575
|
+
|
|
14576
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
14577
|
+
const reportFile = path.join(dir, '.specs', 'context-scan', today + '-SCAN.md');
|
|
14578
|
+
assertTrue(fs.existsSync(reportFile), '扫描工件未落盘: ' + reportFile);
|
|
14579
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
14580
|
+
assertTrue(reportText.includes('<!-- context-scan-snapshot -->'), '工件缺机器快照标记');
|
|
14581
|
+
assertTrue(/```json\r?\n/.test(reportText.slice(reportText.indexOf('<!-- context-scan-snapshot -->'))),
|
|
14582
|
+
'机器快照标记之后缺 json 块');
|
|
14583
|
+
|
|
14584
|
+
// 同一秒连续重扫(取值未变)不得被误判成字段行形态不符
|
|
14585
|
+
const immediate = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
14586
|
+
assertExit(immediate, 0);
|
|
14587
|
+
assertOut(immediate, 'CONTEXT-SCAN-DONE');
|
|
14588
|
+
|
|
14589
|
+
// 双落点:state 的 last_intel_scan 与 CONTEXT 段内字段**取值词元**一致(夹具段行带行尾说明)
|
|
14590
|
+
const structure = requireModuleExport(contextInitModule, 'extractContextStructure', 'context-init.mjs')(
|
|
14591
|
+
fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8'));
|
|
14592
|
+
const landed = intelFieldToken(structure.metadata['intel-scan 元数据'].last_intel_scan.value);
|
|
14593
|
+
const stateFile = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
14594
|
+
assertEqual(stateFile.last_intel_scan, landed, '双落点取值(state 与 CONTEXT 段)');
|
|
14595
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(landed),
|
|
14596
|
+
'落盘扫描时刻形态非「本地时间 + 显式偏移」: ' + landed);
|
|
14597
|
+
|
|
14598
|
+
// 二次差异:新增一份 AI 上下文文档 → 差异段「新增」列出该条目(条目在工件内,摘要行只给计数)
|
|
14599
|
+
writeFile(dir, 'AGENTS.md', '# AGENTS\n\n夹具。\n');
|
|
14600
|
+
const second = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
14601
|
+
assertExit(second, 0);
|
|
14602
|
+
assertOut(second, 'CONTEXT-SCAN: 基线');
|
|
14603
|
+
assertOut(second, '差异 新增 1 ');
|
|
14604
|
+
assertOut(second, 'CONTEXT-SCAN-DONE');
|
|
14605
|
+
const diffReport = fs.readFileSync(reportFile, 'utf8');
|
|
14606
|
+
assertTrue(diffReport.includes('### 新增(1)'), '工件缺「新增(1)」段');
|
|
14607
|
+
assertTrue(diffReport.includes('- AI 上下文文档 · AGENTS.md'),
|
|
14608
|
+
'工件的新增段未列出新增的 AI 上下文文档');
|
|
14609
|
+
},
|
|
14610
|
+
},
|
|
14611
|
+
|
|
14612
|
+
// 283: context-scan 四类边界——① 既有基线不含机器快照 → 显式「无法比对」(不静默省略差异段);
|
|
14613
|
+
// ② 结构校验不通过的一轮零写入且基线不前进(工件与 state 逐字节不变);③ 未初始化项目 →
|
|
14614
|
+
// INIT-GENERATE 指引 + 零写入 + exit 1;④ state 在场但字段非法 → CONTEXT 段零改写
|
|
14615
|
+
// (校验先于两次写入,双落点不被拆成两半)。
|
|
14616
|
+
{
|
|
14617
|
+
name: '283 context-scan 边界:旧基线无快照显式无法比对 / BLOCK 轮不推进基线 / 未初始化零写入 / state 字段非法零改写',
|
|
14618
|
+
run: (dir) => {
|
|
14619
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14620
|
+
writeState(dir, baseState('open'));
|
|
14621
|
+
|
|
14622
|
+
// ① 旧基线不含机器快照(人读工件的历史形态)
|
|
14623
|
+
const legacyBaseline = path.join(dir, '.specs', 'context-scan', '2020-01-01-SCAN.md');
|
|
14624
|
+
fs.mkdirSync(path.dirname(legacyBaseline), { recursive: true });
|
|
14625
|
+
fs.writeFileSync(legacyBaseline, '# 项目上下文重扫报告 · 2020-01-01\n\n(历史工件,无机器快照块)\n', 'utf8');
|
|
14626
|
+
const legacyRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
14627
|
+
assertExit(legacyRes, 0);
|
|
14628
|
+
assertOut(legacyRes, 'CONTEXT-SCAN: 差异 无(既有基线不含机器快照,无法比对)');
|
|
14629
|
+
assertOut(legacyRes, 'CONTEXT-SCAN-DONE');
|
|
14630
|
+
|
|
14631
|
+
// ② 结构校验不通过的一轮:零写入,基线不前进
|
|
14632
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
14633
|
+
const baselineFile = path.join(dir, '.specs', 'context-scan', today + '-SCAN.md');
|
|
14634
|
+
assertTrue(fs.existsSync(baselineFile), '本轮基线工件应在场: ' + baselineFile);
|
|
14635
|
+
const baselineBytes = fs.readFileSync(baselineFile);
|
|
14636
|
+
const stateBytes = readStateBytes(dir);
|
|
14637
|
+
fs.writeFileSync(path.join(dir, '.specs', 'CONTEXT.md'),
|
|
14638
|
+
contextFixtureText().replace('## 默认偏好\n', ''), 'utf8');
|
|
14639
|
+
const blocked = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
14640
|
+
assertExit(blocked, 1);
|
|
14641
|
+
assertOut(blocked, 'BLOCKED: CONTEXT.md 未通过结构校验');
|
|
14642
|
+
assertTrue(fs.readFileSync(baselineFile).equals(baselineBytes), 'BLOCK 的一轮改写了基线工件');
|
|
14643
|
+
assertStateBytesUnchanged(dir, stateBytes, 'context-scan BLOCK 轮');
|
|
14644
|
+
|
|
14645
|
+
// ③ 未初始化项目:INIT-GENERATE 指引 + 零写入 + exit 1
|
|
14646
|
+
const fresh = path.join(dir, 'fresh-project');
|
|
14647
|
+
fs.mkdirSync(fresh, { recursive: true });
|
|
14648
|
+
const freshBefore = treeFingerprint(fresh);
|
|
14649
|
+
const freshRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', fresh], fresh);
|
|
14650
|
+
assertExit(freshRes, 1);
|
|
14651
|
+
assertOut(freshRes, 'INIT-GENERATE');
|
|
14652
|
+
assertOut(freshRes, 'BLOCKED');
|
|
14653
|
+
const freshChanges = fingerprintChanges(freshBefore, treeFingerprint(fresh));
|
|
14654
|
+
assertEqual(freshChanges.length, 0, '未初始化项目必须零写入,实际树变化: ' + JSON.stringify(freshChanges));
|
|
14655
|
+
|
|
14656
|
+
// ④ state 在场但字段非法(写闸门会拒):CONTEXT 段必须零改写。校验此前排在 CONTEXT 改写之后
|
|
14657
|
+
// ⇒ 段侧先落新扫描时刻、state 侧被拒,双落点被拆成两半(且段侧指向引擎根本不认的时刻)。
|
|
14658
|
+
// 与同一命令的损坏态判定(preflight ②:状态不可信 → 零元数据写入)是同一姿态。
|
|
14659
|
+
const badStateRoot = path.join(dir, 'bad-state-field');
|
|
14660
|
+
writeFile(badStateRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
14661
|
+
writeState(badStateRoot, { ...baseState('open'), executionMode: 'not-a-mode' });
|
|
14662
|
+
const badContextBefore = fs.readFileSync(path.join(badStateRoot, '.specs', 'CONTEXT.md'));
|
|
14663
|
+
const badStateBytes = readStateBytes(badStateRoot);
|
|
14664
|
+
const badStateRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', badStateRoot], badStateRoot);
|
|
14665
|
+
assertExit(badStateRes, 1);
|
|
14666
|
+
assertOut(badStateRes, 'BLOCKED');
|
|
14667
|
+
assertTrue(fs.readFileSync(path.join(badStateRoot, '.specs', 'CONTEXT.md')).equals(badContextBefore),
|
|
14668
|
+
'state 字段非法的一轮改写了 CONTEXT 段(双落点被拆成两半)');
|
|
14669
|
+
assertStateBytesUnchanged(badStateRoot, badStateBytes, 'context-scan state 字段非法轮');
|
|
14670
|
+
},
|
|
14671
|
+
},
|
|
14672
|
+
|
|
14673
|
+
// 284: 本仓 CONTEXT 的七段校验 + 可选的 `## evolve 元数据` 段语义——缺席不报(没跑过架构
|
|
14674
|
+
// 沉淀的项目不补段);在场则三字段必须齐(跑过一次却写残的半成品正是要拦的形态);判据
|
|
14675
|
+
// **限定在段内**(别处的同名字段不得让残缺的 evolve 段蒙混过关)。
|
|
14676
|
+
// ① 是本仓真实文件的**维护者形态**断言(.specs/ 被 gitignore):文件结构性缺席(CI 全新检出 /
|
|
14677
|
+
// worktree)时输出可见 SKIP 行(未验证 ≠ 通过),**在场时判据逐字不变**;②~⑤ 恒检(夹具驱动)。
|
|
14678
|
+
{
|
|
14679
|
+
name: '284 CONTEXT 七段校验 + evolve 元数据可选段:缺席不报·在场缺一即报·判据限段内',
|
|
14680
|
+
run: async () => {
|
|
14681
|
+
const validate = requireModuleExport(contextInitModule, 'validateContext', 'context-init.mjs');
|
|
14682
|
+
|
|
14683
|
+
// ① 本仓 CONTEXT.md 通过七段校验(真实文件,非夹具)——文件缺席即非维护者形态,可见跳过
|
|
14684
|
+
if (fs.existsSync(REPO_CONTEXT_FILE)) {
|
|
14685
|
+
const repo = await validate(REPO_ROOT);
|
|
14686
|
+
assertEqual(repo.missingSections.length, 0, '本仓 CONTEXT.md 缺段: ' + JSON.stringify(repo.missingSections));
|
|
14687
|
+
assertEqual(repo.formatIssues.length, 0, '本仓 CONTEXT.md 格式问题: ' + JSON.stringify(repo.formatIssues));
|
|
14688
|
+
} else {
|
|
14689
|
+
console.log('SKIP: 284 的本仓 CONTEXT 面(.specs/CONTEXT.md 为流程工件面,可能结构性缺席)'
|
|
14690
|
+
+ '——本仓 CONTEXT 缺席 = 非维护者形态;本次检出未校验本仓 CONTEXT.md 的七段与 evolve 元数据段语义,'
|
|
14691
|
+
+ '请在维护者主树重跑本套件');
|
|
14692
|
+
}
|
|
14693
|
+
|
|
14694
|
+
// ② 夹具:七段齐备、evolve 段缺席 → 通过(可选段的缺席不报)
|
|
14695
|
+
const project = makeTmp();
|
|
14696
|
+
try {
|
|
14697
|
+
writeFile(project, '.specs/CONTEXT.md', contextFixtureText());
|
|
14698
|
+
const absent = await validate(project);
|
|
14699
|
+
assertEqual(absent.missingSections.length, 0, '七段骨架缺段: ' + JSON.stringify(absent.missingSections));
|
|
14700
|
+
assertEqual(absent.formatIssues.length, 0, 'evolve 段缺席不应报格式问题: ' + JSON.stringify(absent.formatIssues));
|
|
14701
|
+
|
|
14702
|
+
// ③ evolve 段在场且三字段齐 → 通过
|
|
14703
|
+
writeFile(project, '.specs/CONTEXT.md',
|
|
14704
|
+
contextFixtureText({ evolveSection: EVOLVE_METADATA_FIELD_LINES }));
|
|
14705
|
+
const complete = await validate(project);
|
|
14706
|
+
assertEqual(complete.formatIssues.length, 0, 'evolve 段齐备仍报格式问题: ' + JSON.stringify(complete.formatIssues));
|
|
14707
|
+
|
|
14708
|
+
// ④ 段内缺一个字段 → 报「evolve 元数据三字段」
|
|
14709
|
+
writeFile(project, '.specs/CONTEXT.md',
|
|
14710
|
+
contextFixtureText({ evolveSection: EVOLVE_METADATA_FIELD_LINES.slice(0, 2) }));
|
|
14711
|
+
const incomplete = await validate(project);
|
|
14712
|
+
assertTrue(incomplete.formatIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
14713
|
+
'evolve 段缺字段未报出: ' + JSON.stringify(incomplete.formatIssues));
|
|
14714
|
+
|
|
14715
|
+
// ⑤ 判据限段内:缺的那个字段出现在**其它段**里,不得让残缺的 evolve 段蒙混过关
|
|
14716
|
+
writeFile(project, '.specs/CONTEXT.md', contextFixtureText({
|
|
14717
|
+
evolveSection: EVOLVE_METADATA_FIELD_LINES.slice(0, 2),
|
|
14718
|
+
tail: '## 其它段\n\n- **下次建议**: 别处的同名字段',
|
|
14719
|
+
}));
|
|
14720
|
+
const outside = await validate(project);
|
|
14721
|
+
assertTrue(outside.formatIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
14722
|
+
'判据未限定段内(别处的同名字段放行了残缺段): ' + JSON.stringify(outside.formatIssues));
|
|
14723
|
+
} finally {
|
|
14724
|
+
cleanupTmpDir(project);
|
|
14725
|
+
}
|
|
14726
|
+
},
|
|
14727
|
+
},
|
|
14728
|
+
|
|
14729
|
+
// 285: design 出口 ui-design 门四类——正例(前端齐备 + 真实声明 → 放行)/ 负例(缺工件
|
|
14730
|
+
// BLOCKED、缺声明 BLOCKED 且不再自动补写)/ 越界(非前端 → 可见跳过,不要求工件与声明)/
|
|
14731
|
+
// 恢复(旧 change 前端缺件 → WARN 渐进不卡死)。前端判据是结构级:CHANGE.md「视觉调性」段。
|
|
14732
|
+
{
|
|
14733
|
+
name: '285 ui-design 门四类:前端齐备放行 / 前端缺件 BLOCK / 非前端可见跳过 / 旧 change WARN',
|
|
14734
|
+
run: (dir) => {
|
|
14735
|
+
// 正例:前端(「视觉调性」段在场且未标注不适用)+ 工件齐备 + 真实声明
|
|
14736
|
+
writeDesignExitFixture(dir, {
|
|
14737
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
14738
|
+
});
|
|
14739
|
+
const positive = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14740
|
+
assertExit(positive, 0);
|
|
14741
|
+
assertOut(positive, 'ALL CHECKS PASSED');
|
|
14742
|
+
assertNotOut(positive, 'UI-DESIGN: skipped');
|
|
14743
|
+
|
|
14744
|
+
// 负例 A:前端缺 UI-DESIGN.md → BLOCKED + 两条恢复路径
|
|
14745
|
+
writeDesignExitFixture(dir, {
|
|
14746
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
14747
|
+
});
|
|
14748
|
+
const missingArtifact = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14749
|
+
assertExit(missingArtifact, 1);
|
|
14750
|
+
assertOut(missingArtifact, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
14751
|
+
assertOut(missingArtifact, '恢复: 补 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
|
|
14752
|
+
|
|
14753
|
+
// 负例 B:工件齐备但缺 `required-skill:design.flow-comet-ui-design` → BLOCKED(出口不再自动补写)
|
|
14754
|
+
writeDesignExitFixture(dir, {
|
|
14755
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: false,
|
|
14756
|
+
});
|
|
14757
|
+
const missingDeclaration = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14758
|
+
assertExit(missingDeclaration, 1);
|
|
14759
|
+
assertOut(missingDeclaration, 'BLOCKED: missing required Skill evidence: required-skill:design.flow-comet-ui-design');
|
|
14760
|
+
assertOut(missingDeclaration, '不再由出口自动补写');
|
|
14761
|
+
|
|
14762
|
+
// 越界:非前端(「视觉调性」段标注不适用)→ 可见跳过,不要求工件、也不要求该声明
|
|
14763
|
+
writeDesignExitFixture(dir, {
|
|
14764
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
14765
|
+
});
|
|
14766
|
+
const nonFrontend = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14767
|
+
assertExit(nonFrontend, 0);
|
|
14768
|
+
assertOut(nonFrontend, 'UI-DESIGN: skipped(非前端)');
|
|
14769
|
+
assertOut(nonFrontend, 'ALL CHECKS PASSED');
|
|
14770
|
+
|
|
14771
|
+
// 恢复:旧 change 前端缺件 → WARN 渐进(不阻断,也不静默放行)
|
|
14772
|
+
writeDesignExitFixture(dir, {
|
|
14773
|
+
newChange: false, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
14774
|
+
});
|
|
14775
|
+
const legacy = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14776
|
+
assertExit(legacy, 0);
|
|
14777
|
+
assertOut(legacy, 'UI-DESIGN WARN: 缺 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
|
|
14778
|
+
assertOut(legacy, '旧 change 渐进不阻断');
|
|
14779
|
+
},
|
|
14780
|
+
},
|
|
14781
|
+
|
|
14782
|
+
// 286: ui-design 强制等级的文本一致性锚——协议 `design.requiredSkillCalls[flow-comet-ui-design]`
|
|
14783
|
+
// 为 `guarded`,**五份**技能文本(ui-design 技能 / 入口 SKILL / design 节点 SKILL / 入口展开册
|
|
14784
|
+
// GUIDANCE / change 阶段 SKILL)不得残留 `advisory` 表述且须同时点名该绑定与 `guarded`。等级只在
|
|
14785
|
+
// 协议里表达一次,文本是它的散文副本:副本漂移即红(旧表述「advisory,不要求声明」正是被本锚拦下
|
|
14786
|
+
// 的形态)。另锚**判据散文口径**:五份文本必须陈述引擎收紧后的**结构形态**(独立行 / 行首 /
|
|
14787
|
+
// 适用性标签的字段值位 + 词形边界 + 命中片段回显),不得残留旧口径(「段内不含 / 未标注字面
|
|
14788
|
+
// 『不适用』」——把判据说成段内任意位置子串,是「一处措辞即关闸」fail-open 的文字版)。
|
|
14789
|
+
{
|
|
14790
|
+
name: '286 ui-design 强制等级一致性锚:协议 guarded + 五处技能文本零 advisory 残留 + 结构判据散文口径',
|
|
14791
|
+
run: () => {
|
|
14792
|
+
const protocol = JSON.parse(fs.readFileSync(SKILL_PROTOCOL_FILE, 'utf8'));
|
|
14793
|
+
const designNode = (protocol.nodes ?? []).find((node) => node.id === 'design');
|
|
14794
|
+
assertTrue(designNode !== undefined, '协议缺 design 节点');
|
|
14795
|
+
const binding = (designNode.requiredSkillCalls ?? []).find((call) => call.skill === 'flow-comet-ui-design');
|
|
14796
|
+
assertTrue(binding !== undefined, '协议 design 节点缺 flow-comet-ui-design 绑定');
|
|
14797
|
+
assertEqual(binding.enforcement, 'guarded', '协议 flow-comet-ui-design 绑定的强制等级');
|
|
14798
|
+
|
|
14799
|
+
const skillsRoot = skillsRootForScriptsDir(__dirname);
|
|
14800
|
+
const texts = {
|
|
14801
|
+
'flow-comet-ui-design/SKILL.md': path.join(skillsRoot, 'flow-comet-ui-design', 'SKILL.md'),
|
|
14802
|
+
'flow-comet/SKILL.md': path.join(skillsRoot, 'flow-comet', 'SKILL.md'),
|
|
14803
|
+
'flow-comet-design/SKILL.md': path.join(skillsRoot, 'flow-comet-design', 'SKILL.md'),
|
|
14804
|
+
'flow-comet/GUIDANCE.md': path.join(skillsRoot, 'flow-comet', 'GUIDANCE.md'),
|
|
14805
|
+
'flow-comet-change/SKILL.md': path.join(skillsRoot, 'flow-comet-change', 'SKILL.md'),
|
|
14806
|
+
};
|
|
14807
|
+
for (const [label, file] of Object.entries(texts)) {
|
|
14808
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
14809
|
+
assertTrue(!/advisory/i.test(text), label + ' 残留 advisory 等级表述(协议为 guarded)');
|
|
14810
|
+
assertTrue(text.includes('guarded'), label + ' 未点名 guarded 等级');
|
|
14811
|
+
assertTrue(text.includes('flow-comet-ui-design'), label + ' 未点名 flow-comet-ui-design 绑定');
|
|
14812
|
+
const proseProblems = frontendCriterionProseProblems(label, text);
|
|
14813
|
+
assertEqual(proseProblems.length, 0, '判据散文口径未对齐: ' + proseProblems.join(' | '));
|
|
14814
|
+
}
|
|
14815
|
+
// 反向构造(合成输入驱动同一判据,证明判据不恒真空过):① 旧口径句逐条注入任一文本 → 必报;
|
|
14816
|
+
// ② 结构词缺一 → 必报;③ 原地加回旧口径的真实文本副本 → 必报(「把旧口径加回任一文本即红」)。
|
|
14817
|
+
const structuralSample = '前端判据是结构级的:独立行 / 行首 / 适用性标签的字段值位三种形态,'
|
|
14818
|
+
+ '标记后须成词形边界,命中片段回显。\n';
|
|
14819
|
+
assertEqual(frontendCriterionProseProblems('sample', structuralSample).length, 0,
|
|
14820
|
+
'结构口径样本不应被判违规(判据不恒真)');
|
|
14821
|
+
const staleSamples = [
|
|
14822
|
+
'前端判据是结构级的:`CHANGE.md` 的「视觉调性」段在场且段内未标注「不适用」。',
|
|
14823
|
+
'段在场,段内**不含**字面「不适用」',
|
|
14824
|
+
'非前端项目:在段内标注「不适用」两个字面。',
|
|
14825
|
+
];
|
|
14826
|
+
for (const stale of staleSamples) {
|
|
14827
|
+
const problems = frontendCriterionProseProblems('sample', structuralSample + stale + '\n');
|
|
14828
|
+
assertTrue(problems.some((problem) => problem.includes('残留旧口径')),
|
|
14829
|
+
'旧口径样本未被判违规: ' + JSON.stringify(stale) + ' → ' + JSON.stringify(problems));
|
|
14830
|
+
}
|
|
14831
|
+
for (const text of Object.values(texts)) {
|
|
14832
|
+
const original = fs.readFileSync(text, 'utf8');
|
|
14833
|
+
const regressed = original.replace('词形边界', '段内未标注「不适用」');
|
|
14834
|
+
assertTrue(regressed !== original, '反向构造前提不成立:' + text + ' 缺「词形边界」字样');
|
|
14835
|
+
assertTrue(frontendCriterionProseProblems('regressed', regressed)
|
|
14836
|
+
.some((problem) => problem.includes('残留旧口径') || problem.includes('未陈述结构形态')),
|
|
14837
|
+
'把旧口径加回真实文本未被判违规: ' + text);
|
|
14838
|
+
}
|
|
14839
|
+
// 行为口径的散文锚:非前端可见跳过 + 旧 change 渐进(与 285 的行为断言同源)
|
|
14840
|
+
const uiDesignSkill = fs.readFileSync(texts['flow-comet-ui-design/SKILL.md'], 'utf8');
|
|
14841
|
+
assertTrue(uiDesignSkill.includes('UI-DESIGN: skipped(非前端)'), 'ui-design 技能缺非前端跳过口径');
|
|
14842
|
+
assertTrue(uiDesignSkill.includes('旧 change') && uiDesignSkill.includes('WARN'),
|
|
14843
|
+
'ui-design 技能缺旧 change 渐进口径');
|
|
14844
|
+
},
|
|
14845
|
+
},
|
|
14846
|
+
|
|
14847
|
+
// 287: 真实 `init` 跨 change 的 evolve 基线保留——`last_evolve_at` 与 `last_intel_scan` 同形
|
|
14848
|
+
// (两者都是**项目级**字段:换 change 不该丢)。场景 278/279 的窗口与到期锚全用 `writeState` 直注
|
|
14849
|
+
// (覆盖缺口:那条旁路绕开了 init 的保留清单,本缺陷因此完整逃过 286+90);
|
|
14850
|
+
// 本场景**全程只走真实 `init` 子命令**,证明的是「跨 change 持久性」这条正常路径:
|
|
14851
|
+
// 设基线 → init 新 change → 基线仍在 + `status` 的 EVOLVE-DUE 仍生效 + `evolve scan` 窗口仍按基线过滤。
|
|
14852
|
+
// 断言面刻意覆盖 C1 的全部三条后果(字段丢失 / 到期提示消失 / 窗口静默退化为全量)。
|
|
14853
|
+
{
|
|
14854
|
+
name: '287 真实 init 跨 change:last_evolve_at 保留(基线在场·到期提示仍生效·扫描窗口仍过滤)',
|
|
14855
|
+
run: (dir) => {
|
|
14856
|
+
const formatStamp = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
14857
|
+
const formatDate = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs');
|
|
14858
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
14859
|
+
const dateDaysAgo = (days) => formatDate(new Date(Date.now() - days * dayMs));
|
|
14860
|
+
// 窗口两侧各一条带 §9 的归档 change(窗口过滤按目录名日期前缀判定,基线落在两者之间)
|
|
14861
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(101) + '-before-baseline/DESIGN.md',
|
|
14862
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
|
|
14863
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(99) + '-after-baseline/DESIGN.md',
|
|
14864
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
|
|
14865
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
14866
|
+
|
|
14867
|
+
// ① 真实 init 建首个 change → 经**唯一写通道**落基线(100 天前:到期判据按天数必然触发)
|
|
14868
|
+
assertExit(runStateWithProtocol(dir, ['init', CHANGE_ID, '--init-skip']), 0);
|
|
14869
|
+
const baseline = formatStamp(new Date(Date.now() - 100 * dayMs));
|
|
14870
|
+
const setRes = runStateWithProtocol(dir, ['config', 'set', 'last_evolve_at', baseline]);
|
|
14871
|
+
assertExit(setRes, 0);
|
|
14872
|
+
assertOut(setRes, 'CONFIG: last_evolve_at = ' + baseline);
|
|
14873
|
+
|
|
14874
|
+
// ② 真实 init 换 change——跨 change 的全部动作就是这一步(不碰 writeState)
|
|
14875
|
+
const secondInit = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-skip']);
|
|
14876
|
+
assertExit(secondInit, 0);
|
|
14877
|
+
const state = JSON.parse(readStateBytes(dir));
|
|
14878
|
+
assertEqual(state.activeChange, CHANGE_ID + '-2', 'init 后 activeChange');
|
|
14879
|
+
assertEqual(state.last_evolve_at, baseline, 'init 跨 change 保留 last_evolve_at');
|
|
14880
|
+
|
|
14881
|
+
// ③ 到期提示仍生效(AC-18 的跨 change 形态)+ 提示行在场时 status 的 JSON 块仍可解析
|
|
14882
|
+
const status = runStateWithProtocol(dir, ['status']);
|
|
14883
|
+
assertExit(status, 0);
|
|
14884
|
+
assertOut(status, 'EVOLVE-DUE: 上次架构沉淀 ' + baseline);
|
|
14885
|
+
assertOut(status, '超阈值 60 天');
|
|
14886
|
+
assertEqual(parseStatusJson(status).status, 'running', '提示行在场时 status 的 JSON 块解析');
|
|
14887
|
+
|
|
14888
|
+
// ④ 增量窗口仍按基线过滤(AC-4 的跨 change 形态):窗口内入选、窗口外排除,
|
|
14889
|
+
// 且**不**退回「无基线(首次运行,全量扫描)」——后者正是窗口静默退化为全量的形态
|
|
14890
|
+
const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
14891
|
+
assertExit(scan, 0);
|
|
14892
|
+
assertOut(scan, '窗口 起始 = ' + baseline);
|
|
14893
|
+
assertOut(scan, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
|
|
14894
|
+
assertOut(scan, 'after-baseline#1');
|
|
14895
|
+
assertNotOut(scan, 'before-baseline#');
|
|
14896
|
+
assertNotOut(scan, '无基线(首次运行,全量扫描)');
|
|
14897
|
+
},
|
|
14898
|
+
},
|
|
14899
|
+
|
|
14900
|
+
// 288: ui-design 工件门按协议绑定键控(负例面:协议删掉绑定)——闸门开关由协议里的 binding
|
|
14901
|
+
// 表达(在场 ∧ 等级 = guarded),门禁侧只复用同一登记表 / requiredSkillCalls 查询,不存在第二份
|
|
14902
|
+
// 键表。四类:负例(删绑定 → 门随绑定退场,且留可见「门未启用」行,不静默消失)/ 正例(绑定在
|
|
14903
|
+
// 场且 guarded → 前端缺件仍 BLOCKED,键控未误伤既有语义)/ 越界(绑定缺席时 design 的另一
|
|
14904
|
+
// guarded 绑定仍由出口自动补写——其它绑定路径逐字不变)/ 恢复(协议写回 guarded 绑定 → 门重新
|
|
14905
|
+
// 拦住,键控是活判据不是一次性快照)。
|
|
14906
|
+
{
|
|
14907
|
+
name: '288 ui-design 门按协议绑定键控:删绑定门退场(可见行)/ 在场仍拦 / 其它绑定零改动 / 写回即恢复',
|
|
14908
|
+
run: (dir) => {
|
|
14909
|
+
// 负例:协议删掉该绑定 → 前端判据成立且缺件也不再拦(门随绑定退场)
|
|
14910
|
+
writeUiDesignBindingVariant(dir, 'absent');
|
|
14911
|
+
writeDesignExitFixture(dir, {
|
|
14912
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
14913
|
+
});
|
|
14914
|
+
const absent = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14915
|
+
assertExit(absent, 0);
|
|
14916
|
+
assertOut(absent, 'ALL CHECKS PASSED');
|
|
14917
|
+
assertOut(absent, 'UI-DESIGN: 门未启用(协议 design 节点未登记 flow-comet-ui-design 绑定)');
|
|
14918
|
+
assertNotOut(absent, 'BLOCKED');
|
|
14919
|
+
assertNotOut(absent, 'UI-DESIGN: skipped');
|
|
14920
|
+
|
|
14921
|
+
// 越界:绑定缺席时 design 的另一 guarded 绑定(flow-comet-design)仍由出口自动补写——
|
|
14922
|
+
// 零真实声明也放行,证明自动补语义只在登记表命中的绑定上改道
|
|
14923
|
+
writeDesignExitFixture(dir, {
|
|
14924
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: false, declareDesign: false,
|
|
14925
|
+
});
|
|
14926
|
+
const otherBindings = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14927
|
+
assertExit(otherBindings, 0);
|
|
14928
|
+
assertOut(otherBindings, 'ALL CHECKS PASSED');
|
|
14929
|
+
|
|
14930
|
+
// 正例:协议写回 guarded 绑定 → 同一夹具、同一 change 立刻恢复拦截(与既有语义逐字一致)
|
|
14931
|
+
writeUiDesignBindingVariant(dir, 'guarded');
|
|
14932
|
+
writeDesignExitFixture(dir, {
|
|
14933
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
14934
|
+
});
|
|
14935
|
+
const guardedInPlace = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14936
|
+
assertExit(guardedInPlace, 1);
|
|
14937
|
+
assertOut(guardedInPlace, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
14938
|
+
assertNotOut(guardedInPlace, 'UI-DESIGN: 门未启用');
|
|
14939
|
+
|
|
14940
|
+
// 恢复:补齐工件 + 真实声明 → 出口放行(恢复路径未被键控改动波及)
|
|
14941
|
+
writeDesignExitFixture(dir, {
|
|
14942
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
14943
|
+
});
|
|
14944
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14945
|
+
assertExit(recovered, 0);
|
|
14946
|
+
assertOut(recovered, 'ALL CHECKS PASSED');
|
|
14947
|
+
},
|
|
14948
|
+
},
|
|
14949
|
+
|
|
14950
|
+
// 289: ui-design 工件门按协议绑定键控(负例面:等级降回 advisory)——`enforcement` 是该门的单一
|
|
14951
|
+
// 表达处:等级非 guarded ⇒ 门不适用,且该绑定的出口自动补写回到未登记路径的原语义(声明照旧
|
|
14952
|
+
// 由出口代记)。四类:负例(advisory → 不再拦)/ 正例(写回 guarded → 仍拦)/ 越界(同一节点
|
|
14953
|
+
// 的另一绑定不受影响)/ 恢复(等级回到 guarded 即恢复拦截)。
|
|
14954
|
+
{
|
|
14955
|
+
name: '289 ui-design 门按协议等级键控:调回 advisory 不再拦且自动补写原语义 / 写回 guarded 即恢复',
|
|
14956
|
+
run: (dir) => {
|
|
14957
|
+
// 负例:等级调回 advisory → 缺工件 + 零真实声明也放行(自动补写保持原语义)
|
|
14958
|
+
writeUiDesignBindingVariant(dir, 'advisory');
|
|
14959
|
+
writeDesignExitFixture(dir, {
|
|
14960
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
14961
|
+
});
|
|
14962
|
+
const advisory = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14963
|
+
assertExit(advisory, 0);
|
|
14964
|
+
assertOut(advisory, 'ALL CHECKS PASSED');
|
|
14965
|
+
assertOut(advisory, 'UI-DESIGN: 门未启用(协议 design 绑定等级 = advisory,非 guarded)');
|
|
14966
|
+
assertNotOut(advisory, 'BLOCKED');
|
|
14967
|
+
assertNotOut(advisory, 'UI-DESIGN: skipped');
|
|
14968
|
+
|
|
14969
|
+
// 越界:同一节点的另一 guarded 绑定零真实声明仍放行(自动补语义未被本次键控改道)
|
|
14970
|
+
writeDesignExitFixture(dir, {
|
|
14971
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: false, declareDesign: false,
|
|
14972
|
+
});
|
|
14973
|
+
const otherBindings = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14974
|
+
assertExit(otherBindings, 0);
|
|
14975
|
+
assertOut(otherBindings, 'ALL CHECKS PASSED');
|
|
14976
|
+
|
|
14977
|
+
// 正例:等级写回 guarded → 缺件与缺声明双拦截同时回来
|
|
14978
|
+
writeUiDesignBindingVariant(dir, 'guarded');
|
|
14979
|
+
writeDesignExitFixture(dir, {
|
|
14980
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
14981
|
+
});
|
|
14982
|
+
const guardedInPlace = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14983
|
+
assertExit(guardedInPlace, 1);
|
|
14984
|
+
assertOut(guardedInPlace, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
14985
|
+
assertNotOut(guardedInPlace, 'UI-DESIGN: 门未启用');
|
|
14986
|
+
|
|
14987
|
+
// 恢复:补齐工件 + 真实声明 → 放行
|
|
14988
|
+
writeDesignExitFixture(dir, {
|
|
14989
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
14990
|
+
});
|
|
14991
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
14992
|
+
assertExit(recovered, 0);
|
|
14993
|
+
assertOut(recovered, 'ALL CHECKS PASSED');
|
|
14994
|
+
},
|
|
14995
|
+
},
|
|
14996
|
+
|
|
14997
|
+
// 290: 前端判据的负向标记是结构约束(不是裸子串)——三种结构形态(独立行 / 行首 / 字段值位)
|
|
14998
|
+
// 任一命中即判非前端并**回显命中片段**;自然句子与子维度字段里的标记词一律不关掉整道门。
|
|
14999
|
+
// 四类:负例(行首的「不适用于暗色主题」与结构形态的 `- 暗色主题:不适用` → 仍判前端,前端
|
|
15000
|
+
// 缺件照样 BLOCKED)/ 正例(独立行带括注、行首带理由、字段值位三种形态可见跳过并回显片段)/
|
|
15001
|
+
// 越界(段外独立行不参与判据,判据限段内)/ 恢复(改段即放行)。
|
|
15002
|
+
{
|
|
15003
|
+
name: '290 负向标记结构约束:独立行·行首·字段值位跳过并回显片段 / 自然句子·子维度字段·段外标记不关闸',
|
|
15004
|
+
run: (dir) => {
|
|
15005
|
+
// 负例:自然句子(标记词在行首且后接「于」,句内再出现一次)→ 判据仍是前端 ⇒ 缺件 BLOCKED
|
|
15006
|
+
writeDesignExitFixture(dir, {
|
|
15007
|
+
newChange: true, visualTone: VISUAL_TONE_NATURAL_SENTENCE, uiDesign: false, declareUiDesign: true,
|
|
15008
|
+
});
|
|
15009
|
+
const naturalSentence = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15010
|
+
assertExit(naturalSentence, 1);
|
|
15011
|
+
assertOut(naturalSentence, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
15012
|
+
assertNotOut(naturalSentence, 'UI-DESIGN: skipped');
|
|
15013
|
+
assertNotOut(naturalSentence, '命中片段');
|
|
15014
|
+
|
|
15015
|
+
// 负例(结构形态的越界面):子维度字段 `- 暗色主题:不适用` 是结构形态但主体不是本 change
|
|
15016
|
+
// 的适用性 ⇒ 仍判前端(标签表把可误伤的字段形态挡在外面)
|
|
15017
|
+
writeDesignExitFixture(dir, {
|
|
15018
|
+
newChange: true, visualTone: VISUAL_TONE_SUBDIMENSION_FIELD, uiDesign: false, declareUiDesign: true,
|
|
15019
|
+
});
|
|
15020
|
+
const subDimensionField = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15021
|
+
assertExit(subDimensionField, 1);
|
|
15022
|
+
assertOut(subDimensionField, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
15023
|
+
assertNotOut(subDimensionField, 'UI-DESIGN: skipped');
|
|
15024
|
+
|
|
15025
|
+
// 越界:标记出现在「视觉调性」段之外的独立行 → 不参与判据(判据限段内)
|
|
15026
|
+
writeDesignExitFixture(dir, {
|
|
15027
|
+
newChange: true,
|
|
15028
|
+
visualTone: VISUAL_TONE_APPLICABLE,
|
|
15029
|
+
changeTail: '\n## 范围排除(Out of Scope)\n\n不适用。\n',
|
|
15030
|
+
uiDesign: false,
|
|
15031
|
+
declareUiDesign: true,
|
|
15032
|
+
});
|
|
15033
|
+
const outsideSection = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15034
|
+
assertExit(outsideSection, 1);
|
|
15035
|
+
assertOut(outsideSection, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
15036
|
+
assertNotOut(outsideSection, 'UI-DESIGN: skipped');
|
|
15037
|
+
|
|
15038
|
+
// 正例 A:独立行(带括注理由)→ 可见跳过 + 回显命中片段
|
|
15039
|
+
writeDesignExitFixture(dir, {
|
|
15040
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
15041
|
+
});
|
|
15042
|
+
const standalone = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15043
|
+
assertExit(standalone, 0);
|
|
15044
|
+
assertOut(standalone, 'UI-DESIGN: skipped(非前端)');
|
|
15045
|
+
assertOut(standalone, '命中片段: 不适用(非前端项目)。');
|
|
15046
|
+
assertNotOut(standalone, 'BLOCKED');
|
|
15047
|
+
|
|
15048
|
+
// 正例 B:字段值位(`- 适用性:不适用(…)`)→ 同样判非前端(结构形态之二,非行首)
|
|
15049
|
+
writeDesignExitFixture(dir, {
|
|
15050
|
+
newChange: true, visualTone: VISUAL_TONE_FIELD_MARKER, uiDesign: false, declareUiDesign: false,
|
|
15051
|
+
});
|
|
15052
|
+
const fieldValue = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15053
|
+
assertExit(fieldValue, 0);
|
|
15054
|
+
assertOut(fieldValue, 'UI-DESIGN: skipped(非前端)');
|
|
15055
|
+
assertOut(fieldValue, '命中片段: - 适用性:不适用(CLI 工具,无用户可见界面)');
|
|
15056
|
+
assertNotOut(fieldValue, 'BLOCKED');
|
|
15057
|
+
|
|
15058
|
+
// 正例 C:行首形态(标记 + 破折号理由,非独立行)→ 同样判非前端
|
|
15059
|
+
writeDesignExitFixture(dir, {
|
|
15060
|
+
newChange: true, visualTone: VISUAL_TONE_LINE_HEAD_MARKER, uiDesign: false, declareUiDesign: false,
|
|
15061
|
+
});
|
|
15062
|
+
const lineHead = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15063
|
+
assertExit(lineHead, 0);
|
|
15064
|
+
assertOut(lineHead, 'UI-DESIGN: skipped(非前端)');
|
|
15065
|
+
assertOut(lineHead, '命中片段: 不适用 —— CLI 工具,无用户可见界面。');
|
|
15066
|
+
assertNotOut(lineHead, 'BLOCKED');
|
|
15067
|
+
|
|
15068
|
+
// 恢复:把调性段改成结构形态(标注路径)→ 同一 change 放行,命中片段一并回显
|
|
15069
|
+
writeDesignExitFixture(dir, {
|
|
15070
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
15071
|
+
});
|
|
15072
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
15073
|
+
assertExit(recovered, 0);
|
|
15074
|
+
assertOut(recovered, 'UI-DESIGN: skipped(非前端)');
|
|
15075
|
+
assertOut(recovered, '命中片段: 不适用(非前端项目)。');
|
|
15076
|
+
},
|
|
15077
|
+
},
|
|
15078
|
+
|
|
15079
|
+
// 291: 原子写单一来源——「同目录固定 `.tmp` + rename + 失败清理」惯用法在收敛面(状态 / 侧命令 /
|
|
15080
|
+
// handoff 的写盘脚本 + 单源模块)内恰一处实现(落点 = 既有单源模块 state-schema.mjs),三个侧命令
|
|
15081
|
+
// 与 handoff 的 state 直写一律消费同一导出、零内联。判别力两条:① 具名导出被真实消费(import +
|
|
15082
|
+
// 调用,不是纯文本存在性);② **合成目录反向构造**——把第二份实现丢进合成引擎目录,检出数必须
|
|
15083
|
+
// 从 1 变 2(证明检出不恒真空过)。guard 的受保护写入按边界锚显式排除,不静默跳过。
|
|
15084
|
+
{
|
|
15085
|
+
name: '291 原子写单一来源:收敛面内一处实现 + 四消费方零内联 + 合成反向构造判别力',
|
|
15086
|
+
run: async () => {
|
|
15087
|
+
// ① 惯用法唯一实现(收敛面 = 本任务写边界内的写盘脚本 + 单源模块)
|
|
15088
|
+
const idiom = atomicWriteIdiomHits(__dirname, ATOMIC_WRITE_CONVERGENCE_FACE);
|
|
15089
|
+
assertEqual(idiom.length, 1, '原子写惯用法实现面(收敛面内应恰 1 处)实际 ' + JSON.stringify(idiom));
|
|
15090
|
+
assertEqual(idiom[0].file, 'state-schema.mjs', '原子写惯用法落点文件');
|
|
15091
|
+
assertEqual(idiom[0].count, 1, 'state-schema.mjs 内惯用法处数');
|
|
15092
|
+
|
|
15093
|
+
// ①b 边界锚(可见,不静默排除):guard 的受保护写入是独立安全硬化通道——唯一临时名 + 快照
|
|
15094
|
+
// 复核;形态一旦退回「固定 `<目标>.tmp`」惯用法即变红,强制重新评估它是否落回收敛面。
|
|
15095
|
+
const guardText = fs.readFileSync(path.join(__dirname, 'workflow-guard.mjs'), 'utf8');
|
|
15096
|
+
assertTrue(guardText.includes('String(process.pid)') && /Math\.random\(\)\.toString\(16\)/.test(guardText),
|
|
15097
|
+
'workflow-guard 的受保护写入不再是「唯一临时名」硬化通道——须重新评估原子写收敛面');
|
|
15098
|
+
assertTrue(hasNamedImport(guardText, './state-schema.mjs', 'RUNTIME_STATE_PATH'),
|
|
15099
|
+
'workflow-guard 未从 state-schema.mjs import 运行时路径常量(单源关系被破坏,收敛面须重评)');
|
|
15100
|
+
|
|
15101
|
+
// ② 具名导出唯一定义 + 行为可用(落盘、无临时残留、失败路径 fail-closed)
|
|
15102
|
+
const writeAtomic = requireModuleExport(stateSchemaModule, 'writeFileAtomic', 'state-schema.mjs');
|
|
15103
|
+
const definition = engineDefinitionHits('writeFileAtomic');
|
|
15104
|
+
assertEqual(definition.length, 1, 'writeFileAtomic 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(definition));
|
|
15105
|
+
assertEqual(definition[0].file, 'state-schema.mjs', 'writeFileAtomic 定义文件');
|
|
15106
|
+
const probe = makeTmp();
|
|
15107
|
+
try {
|
|
15108
|
+
const target = path.join(probe, 'nested', 'out.json');
|
|
15109
|
+
await writeAtomic(target, '{"ok":true}\n');
|
|
15110
|
+
assertEqual(fs.readFileSync(target, 'utf8'), '{"ok":true}\n', '原子写落盘内容');
|
|
15111
|
+
assertTrue(!fs.existsSync(target + '.tmp'), '原子写成功路径不得残留临时文件');
|
|
15112
|
+
const blocked = path.join(probe, 'blocked.txt');
|
|
15113
|
+
fs.mkdirSync(blocked + '.tmp');
|
|
15114
|
+
let thrown = null;
|
|
15115
|
+
try { await writeAtomic(blocked, '半写'); } catch (e) { thrown = e; }
|
|
15116
|
+
assertTrue(thrown !== null, '临时路径被占用时原子写必须抛错(fail-closed)');
|
|
15117
|
+
assertTrue(!fs.existsSync(blocked), '失败路径不得留下半写目标文件');
|
|
15118
|
+
} finally {
|
|
15119
|
+
cleanupTmpDir(probe);
|
|
15120
|
+
}
|
|
15121
|
+
|
|
15122
|
+
// ③ 四个消费方:具名 import 自 state-schema.mjs + 真实调用 + 零内联第二份实现
|
|
15123
|
+
const consumers = {
|
|
15124
|
+
'workflow-state.mjs': 'writeJsonAtomic',
|
|
15125
|
+
'workflow-handoff.mjs': 'writeJsonAtomic',
|
|
15126
|
+
'evolve.mjs': 'writeFileAtomic',
|
|
15127
|
+
'context-scan.mjs': 'writeJsonAtomic',
|
|
15128
|
+
};
|
|
15129
|
+
for (const [file, symbol] of Object.entries(consumers)) {
|
|
15130
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
15131
|
+
assertTrue(hasNamedImport(text, './state-schema.mjs', symbol),
|
|
15132
|
+
file + ' 未从 state-schema.mjs import ' + symbol + '(单源纪律:写盘不得在本脚本内联第二份)');
|
|
15133
|
+
assertTrue(text.includes(symbol + '('), file + ' 未真实消费 ' + symbol + '(单一权威应被调用)');
|
|
15134
|
+
const inline = (text.match(ATOMIC_TEMP_SUFFIX_RE) ?? []).length;
|
|
15135
|
+
assertEqual(inline, 0, file + ' 仍内联原子写惯用法(第二份实现)处数');
|
|
15136
|
+
}
|
|
15137
|
+
|
|
15138
|
+
// ④ 反向构造:合成引擎目录(单文件 1 处 → 检出 1;再放第二份实现 → 检出 2)——
|
|
15139
|
+
// 证明③的判据确实会因第二份实现变红,而非恒真空过。
|
|
15140
|
+
const synthetic = makeTmp();
|
|
15141
|
+
try {
|
|
15142
|
+
writeFile(synthetic, 'single.mjs',
|
|
15143
|
+
"export async function duplicateWriter(file, text) {\n"
|
|
15144
|
+
+ " const temporary = file + '.tmp';\n"
|
|
15145
|
+
+ ' await fs.writeFile(temporary, text);\n'
|
|
15146
|
+
+ ' await fs.rename(temporary, file);\n'
|
|
15147
|
+
+ '}\n');
|
|
15148
|
+
assertEqual(atomicWriteIdiomHits(synthetic).length, 1, '合成目录单实现检出数');
|
|
15149
|
+
writeFile(synthetic, 'second.mjs',
|
|
15150
|
+
"async function anotherWriter(file, text) {\n"
|
|
15151
|
+
+ " const temporary = file + '.tmp';\n"
|
|
15152
|
+
+ ' await fs.writeFile(temporary, text);\n'
|
|
15153
|
+
+ ' await fs.rename(temporary, file);\n'
|
|
15154
|
+
+ '}\n');
|
|
15155
|
+
assertEqual(atomicWriteIdiomHits(synthetic).length, 2, '合成目录第二份实现检出数(判据须变红)');
|
|
15156
|
+
} finally {
|
|
15157
|
+
cleanupTmpDir(synthetic);
|
|
15158
|
+
}
|
|
15159
|
+
},
|
|
15160
|
+
},
|
|
15161
|
+
|
|
15162
|
+
// 292: evolve 元数据字段面单一来源——`## evolve 元数据` 的段名与三字段名在 state-schema.mjs
|
|
15163
|
+
// 唯一导出,写方(evolve)与校验方(context-init)同源消费、零内联字面量;容差收窄到单形:
|
|
15164
|
+
// 无生产者的旧别名「下次同步建议」不再被静默接受,而是**可见**的格式提示(点名旧别名 + 应改
|
|
15165
|
+
// 写的字段名)。写→校一致性用真实链路:evolve apply 生成的段必须零格式问题通过校验。
|
|
15166
|
+
{
|
|
15167
|
+
name: '292 evolve 元数据单一来源:常量集唯一导出·写校同源·旧别名收窄为可见提示',
|
|
15168
|
+
run: async (dir) => {
|
|
15169
|
+
// ① 常量集唯一导出 + 取值单形(去掉无生产者的旧别名是**取值**层面的收窄)
|
|
15170
|
+
for (const name of ['EVOLVE_METADATA_SECTION', 'EVOLVE_METADATA_FIELDS']) {
|
|
15171
|
+
const hits = engineDefinitionHits(name);
|
|
15172
|
+
assertEqual(hits.length, 1, name + ' 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(hits));
|
|
15173
|
+
assertEqual(hits[0].file, 'state-schema.mjs', name + ' 定义文件');
|
|
15174
|
+
}
|
|
15175
|
+
const section = requireModuleExport(stateSchemaModule, 'EVOLVE_METADATA_SECTION', 'state-schema.mjs');
|
|
15176
|
+
const fields = requireModuleExport(stateSchemaModule, 'EVOLVE_METADATA_FIELDS', 'state-schema.mjs');
|
|
15177
|
+
assertEqual(section, 'evolve 元数据', '段名常量取值');
|
|
15178
|
+
assertEqual(fields.join(','), ['last_evolve_at', 'scanner', '下次建议'].join(','), '三字段常量取值');
|
|
15179
|
+
|
|
15180
|
+
// ② 写方与校验方同源消费 + 零内联字面量(第二份表达即变红)
|
|
15181
|
+
for (const file of ['evolve.mjs', 'context-init.mjs']) {
|
|
15182
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
15183
|
+
assertTrue(hasNamedImport(text, './state-schema.mjs', 'EVOLVE_METADATA_SECTION'),
|
|
15184
|
+
file + ' 未从 state-schema.mjs import 段名常量');
|
|
15185
|
+
assertTrue(text.includes('EVOLVE_METADATA_FIELDS'), file + ' 未消费字段常量集');
|
|
15186
|
+
assertTrue(!/'evolve 元数据'/.test(text), file + ' 仍内联段名字面量(第二份表达)');
|
|
15187
|
+
assertTrue(!/'下次建议'/.test(text), file + ' 仍内联第三字段字面量(第二份表达)');
|
|
15188
|
+
}
|
|
15189
|
+
|
|
15190
|
+
// ③ 写→校一致性(真实链路):evolve apply 产出的段必须被校验方无问题接收
|
|
15191
|
+
writeFile(dir, '.specs/archive/2026-10-02-fixture/DESIGN.md',
|
|
15192
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 夹具抽象条目(元数据单一来源)\n');
|
|
15193
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15194
|
+
writeState(dir, baseState('open'));
|
|
15195
|
+
const apply = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-fixture#1', '--root', dir], dir);
|
|
15196
|
+
assertExit(apply, 0);
|
|
15197
|
+
assertOut(apply, 'EVOLVE-OK');
|
|
15198
|
+
const written = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
15199
|
+
for (const field of fields) {
|
|
15200
|
+
assertTrue(written.includes('**' + field + '**'), '写方产出的段缺字段 ' + field);
|
|
15201
|
+
}
|
|
15202
|
+
const validate = requireModuleExport(contextInitModule, 'validateContext', 'context-init.mjs');
|
|
15203
|
+
const consistent = await validate(dir);
|
|
15204
|
+
assertEqual(consistent.missingSections.length, 0,
|
|
15205
|
+
'夹具七段骨架缺段: ' + JSON.stringify(consistent.missingSections));
|
|
15206
|
+
assertEqual(consistent.formatIssues.length, 0,
|
|
15207
|
+
'写方产物未通过校验方(同源失配): ' + JSON.stringify(consistent.formatIssues));
|
|
15208
|
+
|
|
15209
|
+
// ④ 容差收窄判别力:旧别名顶替第三字段 → 必报,且提示点名旧别名与应写字段(可见,不静默)
|
|
15210
|
+
const aliased = contextFixtureText({ evolveSection: [
|
|
15211
|
+
'- **' + fields[0] + '**: `2026-10-02T10:00:00+08:00`',
|
|
15212
|
+
'- **' + fields[1] + '**: `flow-comet-evolve`',
|
|
15213
|
+
'- **下次同步建议**: 约 60 天后',
|
|
15214
|
+
] });
|
|
15215
|
+
writeFile(dir, '.specs/CONTEXT.md', aliased);
|
|
15216
|
+
const aliasedIssues = (await validate(dir)).formatIssues;
|
|
15217
|
+
assertTrue(aliasedIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
15218
|
+
'旧别名未被收窄(仍静默通过): ' + JSON.stringify(aliasedIssues));
|
|
15219
|
+
assertTrue(aliasedIssues.some((issue) => issue.includes('下次同步建议') && issue.includes('不再接受')),
|
|
15220
|
+
'旧别名未给出可见格式提示: ' + JSON.stringify(aliasedIssues));
|
|
15221
|
+
},
|
|
15222
|
+
},
|
|
15223
|
+
|
|
15224
|
+
// 293: 侧命令 CLI 契约——三条横向命令的 `--root` 两种形态 / `--stdout` / `--help` /
|
|
15225
|
+
// 未知参数走**同一份**共享助手:等号形三命令一致(修复前 evolve 报「未知参数: --root=.」exit 1)、
|
|
15226
|
+
// `--help`/`-h` 三命令一致(修复前只有 health 有)、空格形与未知参数的退出码语义保持不变;
|
|
15227
|
+
// 位置参数语义由各命令自持(evolve 的 scan/apply 子命令与候选 id)。结构锚:带引号的 `--root`
|
|
15228
|
+
// 解析形态与「未知参数」构造在三条命令里**只允许出现在共享助手一处**,第二份自写脚手架即红。
|
|
15229
|
+
{
|
|
15230
|
+
name: '293 侧命令 CLI 契约:--root 两形态·--stdout·--help 三命令同形 + 未知参数语义不变 + 解析面单源',
|
|
15231
|
+
run: (dir) => {
|
|
15232
|
+
writeFile(dir, '.specs/archive/2026-10-02-cli/DESIGN.md',
|
|
15233
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- CLI 契约夹具条目\n');
|
|
15234
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15235
|
+
writeState(dir, baseState('open'));
|
|
15236
|
+
|
|
15237
|
+
// ① 等号形 `--root=<目录>`:三命令等价(修复前 evolve 是唯一不支持的一条)
|
|
15238
|
+
const evolveEq = runSideScript(SIDE_EVOLVE, ['scan', '--root=' + dir], dir);
|
|
15239
|
+
assertExit(evolveEq, 0);
|
|
15240
|
+
assertOut(evolveEq, 'EVOLVE: 窗口');
|
|
15241
|
+
assertOut(evolveEq, '2026-10-02-cli#1');
|
|
15242
|
+
const healthEq = runSideScript(SIDE_HEALTH, ['--root=' + dir, '--stdout'], dir);
|
|
15243
|
+
assertExit(healthEq, 0);
|
|
15244
|
+
assertOut(healthEq, '## 确定性层(机器可判)');
|
|
15245
|
+
const scanEq = runSideScript(SIDE_CONTEXT_SCAN, ['--root=' + dir], dir);
|
|
15246
|
+
assertExit(scanEq, 0);
|
|
15247
|
+
assertOut(scanEq, 'CONTEXT-SCAN-DONE');
|
|
15248
|
+
|
|
15249
|
+
// ② 空格形 `--root <目录>`:向后兼容(三命令语义不变)
|
|
15250
|
+
const evolveSpace = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
15251
|
+
assertExit(evolveSpace, 0);
|
|
15252
|
+
assertOut(evolveSpace, 'EVOLVE: 窗口');
|
|
15253
|
+
const healthSpace = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15254
|
+
assertExit(healthSpace, 0);
|
|
15255
|
+
assertOut(healthSpace, '## 确定性层(机器可判)');
|
|
15256
|
+
const scanSpace = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
15257
|
+
assertExit(scanSpace, 0);
|
|
15258
|
+
assertOut(scanSpace, 'CONTEXT-SCAN-DONE');
|
|
15259
|
+
|
|
15260
|
+
// ③ `--help` / `-h`:三命令一律打印**自己的**用法后 exit 0(用法里各自列出自身命令形态)
|
|
15261
|
+
const helpCases = [
|
|
15262
|
+
{ args: ['--help'], keywords: ['evolve.mjs scan', 'evolve.mjs apply', '--stdout'] },
|
|
15263
|
+
{ args: ['-h'], keywords: ['health.mjs', '--root', '--stdout'] },
|
|
15264
|
+
{ args: ['--help'], keywords: ['context-scan.mjs', '--root', '--stdout'] },
|
|
15265
|
+
];
|
|
15266
|
+
const helpScripts = [SIDE_EVOLVE, SIDE_HEALTH, SIDE_CONTEXT_SCAN];
|
|
15267
|
+
for (let i = 0; i < helpScripts.length; i += 1) {
|
|
15268
|
+
const res = runSideScript(helpScripts[i], helpCases[i].args, dir);
|
|
15269
|
+
assertExit(res, 0);
|
|
15270
|
+
for (const keyword of helpCases[i].keywords) assertOut(res, keyword);
|
|
15271
|
+
}
|
|
15272
|
+
// 子命令之后的 `--help` 同样短路(不因缺候选 id 报用法错误)
|
|
15273
|
+
const applyHelp = runSideScript(SIDE_EVOLVE, ['apply', '--help'], dir);
|
|
15274
|
+
assertExit(applyHelp, 0);
|
|
15275
|
+
assertOut(applyHelp, 'evolve.mjs apply');
|
|
15276
|
+
// `--stdout` 三命令均被接受(evolve 的 scan 本就全量输出到标准输出)
|
|
15277
|
+
assertExit(runSideScript(SIDE_EVOLVE, ['scan', '--stdout', '--root', dir], dir), 0);
|
|
15278
|
+
// evolve 的 `--stdout` 语义 = 本次追加进报告的内容原样输出(与落盘块逐字节相同);
|
|
15279
|
+
// 命令自有取值开关的等号形同样走共享助手(`--scanner=<文本>`)
|
|
15280
|
+
const applyOut = runSideScript(SIDE_EVOLVE,
|
|
15281
|
+
['apply', '2026-10-02-cli#1', '--root', dir, '--stdout', '--scanner=契约夹具扫描器'], dir);
|
|
15282
|
+
assertExit(applyOut, 0);
|
|
15283
|
+
assertOut(applyOut, 'EVOLVE-OK');
|
|
15284
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
15285
|
+
const evolveReport = fs.readFileSync(path.join(dir, '.specs', 'evolve', today + '-EVOLVE.md'), 'utf8');
|
|
15286
|
+
assertTrue(applyOut.output.includes(evolveReport),
|
|
15287
|
+
'--stdout 输出应与落盘报告块逐字节一致(stdout 与文件各自渲染即漂移)');
|
|
15288
|
+
assertTrue(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8').includes('契约夹具扫描器'),
|
|
15289
|
+
'命令自有取值开关(--scanner=<文本>)未生效');
|
|
15290
|
+
|
|
15291
|
+
// ④ 未知参数:三命令一律 exit 1 且点名该词元(既有退出码语义不变)
|
|
15292
|
+
for (const script of helpScripts) {
|
|
15293
|
+
const unknown = runSideScript(script, ['--bogus'], dir);
|
|
15294
|
+
assertExit(unknown, 1);
|
|
15295
|
+
assertOut(unknown, '未知参数: --bogus');
|
|
15296
|
+
}
|
|
15297
|
+
// 位置参数语义按命令自持:evolve 的 scan 拒位置参数、apply 缺候选 id 仍报用法错误
|
|
15298
|
+
const scanExtra = runSideScript(SIDE_EVOLVE, ['scan', 'extra'], dir);
|
|
15299
|
+
assertExit(scanExtra, 1);
|
|
15300
|
+
assertOut(scanExtra, 'scan 不接受位置参数: extra');
|
|
15301
|
+
const applyEmpty = runSideScript(SIDE_EVOLVE, ['apply', '--root', dir], dir);
|
|
15302
|
+
assertExit(applyEmpty, 1);
|
|
15303
|
+
assertOut(applyEmpty, 'apply 需要至少一个候选 id');
|
|
15304
|
+
// 取值开关悬空 → 用法错误(三命令同一文案、同一退出码)
|
|
15305
|
+
for (const script of helpScripts) {
|
|
15306
|
+
const dangling = runSideScript(script, ['--root'], dir);
|
|
15307
|
+
assertExit(dangling, 1);
|
|
15308
|
+
assertOut(dangling, '--root 需要一个目录参数');
|
|
15309
|
+
}
|
|
15310
|
+
|
|
15311
|
+
// ⑤ 结构锚:解析形态只此一处(共享助手);两个消费方具名 import + 真实调用
|
|
15312
|
+
const parseFace = new Map(helpScripts.map((script) => [path.basename(script), fs.readFileSync(script, 'utf8')]));
|
|
15313
|
+
const rootTokenFiles = [...parseFace].filter(([, text]) => text.includes("'--root'")).map(([file]) => file);
|
|
15314
|
+
assertEqual(rootTokenFiles.join(','), 'evolve.mjs',
|
|
15315
|
+
'带引号的 `--root` 解析形态应只出现在共享助手一处(实际: ' + (rootTokenFiles.join(',') || '无') + ')');
|
|
15316
|
+
const unknownTokenFiles = [...parseFace].filter(([, text]) => text.includes('未知参数: ')).map(([file]) => file);
|
|
15317
|
+
assertEqual(unknownTokenFiles.join(','), 'evolve.mjs',
|
|
15318
|
+
'「未知参数」构造应只出现在共享助手一处(实际: ' + (unknownTokenFiles.join(',') || '无') + ')');
|
|
15319
|
+
for (const file of ['health.mjs', 'context-scan.mjs']) {
|
|
15320
|
+
const text = parseFace.get(file);
|
|
15321
|
+
assertTrue(hasNamedImport(text, './evolve.mjs', 'parseSideCommandArgs'),
|
|
15322
|
+
file + ' 未从共享助手模块具名 import parseSideCommandArgs(第二份脚手架或未接线)');
|
|
15323
|
+
assertTrue(text.includes('parseSideCommandArgs('), file + ' 未真实调用共享助手');
|
|
15324
|
+
}
|
|
15325
|
+
},
|
|
15326
|
+
},
|
|
15327
|
+
|
|
15328
|
+
// 294: 损坏 state 的 fail-closed 与「首次运行」口径收窄 + 协议路径单源——
|
|
15329
|
+
// ① state 文件在场但不可解析(含顶层非对象)→ `evolve scan` BLOCKED 且零写入,不再谎称
|
|
15330
|
+
// 「无基线(首次运行,全量扫描)」把增量窗口静默退化为全量;② 「首次运行」只限
|
|
15331
|
+
// 「state 可读且字段缺席」,state 不在场另有措辞(不冒充首次运行);③ 协议路径走
|
|
15332
|
+
// state-schema 的唯一选择器:state.protocolPath 绑定**独占**(项目内约定副本坏掉也必须成功、
|
|
15333
|
+
// 绑定本身坏掉也不回退候选布局),本模块零候选布局表。
|
|
15334
|
+
{
|
|
15335
|
+
name: '294 损坏 state fail-closed:scan/apply BLOCKED 零写入·首次运行口径收窄 + 协议路径走单源选择器',
|
|
15336
|
+
run: (dir) => {
|
|
15337
|
+
writeFile(dir, '.specs/archive/2026-10-02-state/DESIGN.md',
|
|
15338
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 状态口径夹具条目\n');
|
|
15339
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15340
|
+
const stateFile = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
15341
|
+
writeState(dir, baseState('open'));
|
|
15342
|
+
|
|
15343
|
+
// ① state 不在场:显式点名「state 不在场」,不冒充「首次运行」(全量扫描仍可用)
|
|
15344
|
+
fs.rmSync(stateFile);
|
|
15345
|
+
const noState = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
15346
|
+
assertExit(noState, 0);
|
|
15347
|
+
assertOut(noState, 'state 不在场');
|
|
15348
|
+
assertNotOut(noState, '无基线(首次运行,全量扫描)');
|
|
15349
|
+
|
|
15350
|
+
// ② state 可读且字段缺席 = 唯一的「首次运行」口径(全量扫描)
|
|
15351
|
+
writeState(dir, baseState('open'));
|
|
15352
|
+
const firstRun = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
15353
|
+
assertExit(firstRun, 0);
|
|
15354
|
+
assertOut(firstRun, '无基线(首次运行,全量扫描)');
|
|
15355
|
+
assertOut(firstRun, '窗口内 1 个');
|
|
15356
|
+
|
|
15357
|
+
// ③ 损坏 state(JSON 截断):fail-closed —— BLOCKED + 零写入,不再退化成全量扫描
|
|
15358
|
+
const stateText = fs.readFileSync(stateFile, 'utf8');
|
|
15359
|
+
const truncated = stateText.slice(0, Math.max(1, Math.floor(stateText.length / 2)));
|
|
15360
|
+
fs.writeFileSync(stateFile, truncated, 'utf8');
|
|
15361
|
+
const damagedBytes = readStateBytes(dir);
|
|
15362
|
+
const before = treeFingerprint(dir);
|
|
15363
|
+
const blocked = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
15364
|
+
assertExit(blocked, 1);
|
|
15365
|
+
assertOut(blocked, 'BLOCKED');
|
|
15366
|
+
assertOut(blocked, '无法解析');
|
|
15367
|
+
assertNotOut(blocked, '首次运行');
|
|
15368
|
+
assertNotOut(blocked, '候选清单');
|
|
15369
|
+
assertEqual(readStateBytes(dir), damagedBytes, '损坏 state 的 scan 轮改写了 state');
|
|
15370
|
+
assertEqual(fingerprintChanges(before, treeFingerprint(dir)).join(' | '), '',
|
|
15371
|
+
'损坏 state 的 scan 轮有写入');
|
|
15372
|
+
|
|
15373
|
+
// ④ 顶层非对象(数组)同样判「不可信」——不得冒充「字段缺席」
|
|
15374
|
+
fs.writeFileSync(stateFile, '[]\n', 'utf8');
|
|
15375
|
+
const arrayState = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
15376
|
+
assertExit(arrayState, 1);
|
|
15377
|
+
assertOut(arrayState, 'BLOCKED');
|
|
15378
|
+
assertOut(arrayState, '无法解析');
|
|
15379
|
+
|
|
15380
|
+
// ⑤ 损坏态下 apply 同样 fail-closed:目标文档 / 报告 / state 三处零改动
|
|
15381
|
+
fs.writeFileSync(stateFile, truncated, 'utf8');
|
|
15382
|
+
const contextBefore = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
15383
|
+
const applyBlocked = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-state#1', '--root', dir], dir);
|
|
15384
|
+
assertExit(applyBlocked, 1);
|
|
15385
|
+
assertOut(applyBlocked, 'BLOCKED');
|
|
15386
|
+
assertEqual(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8'), contextBefore,
|
|
15387
|
+
'损坏 state 的 apply 轮改写了目标文档');
|
|
15388
|
+
assertTrue(!fs.existsSync(path.join(dir, '.specs', 'evolve')), '损坏 state 的 apply 轮落了报告');
|
|
15389
|
+
|
|
15390
|
+
// ⑥ 协议路径单源:state.protocolPath 绑定独占——项目内约定副本坏掉,绑定好 → 必须成功
|
|
15391
|
+
// (修复前的候选布局表先命中 <根>/reference/workflow-protocol.json → 子进程按坏协议 BLOCK)
|
|
15392
|
+
writeFile(dir, '.specs/archive/2026-10-02-proto/DESIGN.md',
|
|
15393
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 协议绑定夹具条目\n');
|
|
15394
|
+
fs.writeFileSync(path.join(dir, 'reference', 'workflow-protocol.json'),
|
|
15395
|
+
'{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
15396
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(dir, 'bound-protocol.json'));
|
|
15397
|
+
writeState(dir, { ...baseState('open'), protocolPath: 'bound-protocol.json' });
|
|
15398
|
+
const bound = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-proto#1', '--root', dir], dir,
|
|
15399
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
15400
|
+
assertExit(bound, 0);
|
|
15401
|
+
assertOut(bound, 'EVOLVE-OK');
|
|
15402
|
+
assertTrue(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8').includes('协议绑定夹具条目'),
|
|
15403
|
+
'状态绑定协议下的 apply 未落盘条目');
|
|
15404
|
+
|
|
15405
|
+
// ⑦ 绑定本身坏掉 → fail-closed 可见(不回退项目内约定副本),指引指向绑定修正
|
|
15406
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(dir, 'reference', 'workflow-protocol.json'));
|
|
15407
|
+
fs.writeFileSync(path.join(dir, 'broken-protocol.json'), '{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
15408
|
+
writeState(dir, { ...baseState('open'), protocolPath: 'broken-protocol.json' });
|
|
15409
|
+
const brokenBytes = readStateBytes(dir);
|
|
15410
|
+
const broken = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-proto#1', '--root', dir], dir,
|
|
15411
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
15412
|
+
assertExit(broken, 1);
|
|
15413
|
+
assertOut(broken, 'state 写入通道失败');
|
|
15414
|
+
assertOut(broken, 'state.protocolPath');
|
|
15415
|
+
assertEqual(readStateBytes(dir), brokenBytes, '绑定损坏的 apply 轮改写了 state');
|
|
15416
|
+
|
|
15417
|
+
// ⑧ 写入前先验 state 通道(协议闸门):通道排在文档之后,不预验就有半成品——候选**未应用过**
|
|
15418
|
+
// (目标文档必然会被改写),绑定指向 schema 非法的根内副本 ⇒ 必须零文档改动、零报告、零 state。
|
|
15419
|
+
const halfRoot = path.join(dir, 'half-write');
|
|
15420
|
+
writeFile(halfRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
15421
|
+
writeFile(halfRoot, '.specs/archive/2026-10-02-half/DESIGN.md',
|
|
15422
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 半成品夹具条目\n');
|
|
15423
|
+
fs.writeFileSync(path.join(halfRoot, 'broken-protocol.json'), '{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
15424
|
+
writeState(halfRoot, { ...baseState('open'), protocolPath: 'broken-protocol.json' });
|
|
15425
|
+
const halfContextBefore = fs.readFileSync(path.join(halfRoot, '.specs', 'CONTEXT.md'));
|
|
15426
|
+
const halfStateBefore = readStateBytes(halfRoot);
|
|
15427
|
+
const half = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-half#1', '--root', halfRoot], halfRoot,
|
|
15428
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
15429
|
+
assertExit(half, 1);
|
|
15430
|
+
assertOut(half, 'state 写入通道失败');
|
|
15431
|
+
assertOut(half, 'state.protocolPath');
|
|
15432
|
+
assertTrue(fs.readFileSync(path.join(halfRoot, '.specs', 'CONTEXT.md')).equals(halfContextBefore),
|
|
15433
|
+
'state 通道不可用的 apply 轮改写了目标文档(写入前未验通道 ⇒ 半成品)');
|
|
15434
|
+
assertStateBytesUnchanged(halfRoot, halfStateBefore, 'state 通道不可用的 apply 轮');
|
|
15435
|
+
assertTrue(!fs.existsSync(path.join(halfRoot, '.specs', 'evolve')),
|
|
15436
|
+
'state 通道不可用的 apply 轮落了报告');
|
|
15437
|
+
|
|
15438
|
+
// ⑨ 第二条确定性闸门(state 字段非法)同样必须在文档写入之前拦下——通道预验不能只验协议。
|
|
15439
|
+
// 协议经 state.protocolPath 绑到根内合法副本(这一格只考字段闸门,不考协议闸门)。
|
|
15440
|
+
const fieldRoot = path.join(dir, 'half-write-field');
|
|
15441
|
+
writeFile(fieldRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
15442
|
+
writeFile(fieldRoot, '.specs/archive/2026-10-02-field/DESIGN.md',
|
|
15443
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 字段闸门夹具条目\n');
|
|
15444
|
+
fs.mkdirSync(path.join(fieldRoot, 'reference'), { recursive: true });
|
|
15445
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(fieldRoot, 'reference', 'workflow-protocol.json'));
|
|
15446
|
+
writeState(fieldRoot, {
|
|
15447
|
+
...baseState('open'), executionMode: 'not-a-mode', protocolPath: 'reference/workflow-protocol.json',
|
|
15448
|
+
});
|
|
15449
|
+
const fieldContextBefore = fs.readFileSync(path.join(fieldRoot, '.specs', 'CONTEXT.md'));
|
|
15450
|
+
const fieldStateBefore = readStateBytes(fieldRoot);
|
|
15451
|
+
const fieldGate = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-field#1', '--root', fieldRoot], fieldRoot,
|
|
15452
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
15453
|
+
assertExit(fieldGate, 1);
|
|
15454
|
+
assertOut(fieldGate, 'state 写入通道失败');
|
|
15455
|
+
assertOut(fieldGate, 'executionMode');
|
|
15456
|
+
assertTrue(fs.readFileSync(path.join(fieldRoot, '.specs', 'CONTEXT.md')).equals(fieldContextBefore),
|
|
15457
|
+
'state 字段非法的一轮改写了目标文档(写入前未验字段闸门 ⇒ 半成品)');
|
|
15458
|
+
assertStateBytesUnchanged(fieldRoot, fieldStateBefore, 'state 字段非法的 apply 轮');
|
|
15459
|
+
|
|
15460
|
+
// ⑩ 结构锚:本模块不再自持候选布局表;协议路径只经 state-schema 的唯一导出选择;
|
|
15461
|
+
// state 三态读入口两条侧命令共用一个实现(第二份内联即红)
|
|
15462
|
+
const evolveText = fs.readFileSync(SIDE_EVOLVE, 'utf8');
|
|
15463
|
+
assertTrue(hasNamedImport(evolveText, './state-schema.mjs', 'resolveProtocolPathWithState'),
|
|
15464
|
+
'evolve.mjs 未从 state-schema.mjs 具名 import 协议路径选择器');
|
|
15465
|
+
assertTrue(evolveText.includes('resolveProtocolPathWithState('), 'evolve.mjs 未真实调用协议路径选择器');
|
|
15466
|
+
assertTrue(!evolveText.includes("'reference', 'workflow-protocol.json'"),
|
|
15467
|
+
'evolve.mjs 仍自持项目内约定副本候选(第二套「协议在哪」表达)');
|
|
15468
|
+
assertTrue(!evolveText.includes("'.flow-comet', 'skills'"),
|
|
15469
|
+
'evolve.mjs 仍自持权威源布局候选(第二套「协议在哪」表达)');
|
|
15470
|
+
const scanText = fs.readFileSync(SIDE_CONTEXT_SCAN, 'utf8');
|
|
15471
|
+
assertTrue(hasNamedImport(scanText, './evolve.mjs', 'readStateInfo'),
|
|
15472
|
+
'context-scan.mjs 未共用 state 三态读入口(第二份读盘实现)');
|
|
15473
|
+
assertTrue(scanText.includes('readStateInfo('), 'context-scan.mjs 未真实调用共用的 state 读入口');
|
|
15474
|
+
assertTrue(!/function\s+readStateFile\b/.test(scanText),
|
|
15475
|
+
'context-scan.mjs 仍保留本地 state 读实现(三态判定第二份表达)');
|
|
15476
|
+
},
|
|
15477
|
+
},
|
|
15478
|
+
|
|
15479
|
+
// 295: health 基线日期判据单源——报告名的「日期前缀 + 日历自洽」判定收敛到 time-utils
|
|
15480
|
+
//(真实消费 `archiveDateFromName`),本模块不再自写前缀正则:日历不自洽的
|
|
15481
|
+
// `2026-02-30-HEALTH.md` 不再被采作基线(旧实现单独在场时直接采作基线、并输出看似有据的
|
|
15482
|
+
// ↑/↓ 趋势;与合法旧报告并存时又因「取排序最后一份」必然取到它)。判据面配**合成目录
|
|
15483
|
+
// 反向构造**:第二份前缀正则丢进合成引擎目录必须被检出(证明形态判据不恒真空过)。
|
|
15484
|
+
{
|
|
15485
|
+
name: '295 health 基线日期判据单源:日历不自洽前缀不入选·合法旧报告入选 + 零自写前缀正则',
|
|
15486
|
+
run: (dir) => {
|
|
15487
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15488
|
+
writeState(dir, baseState('open'));
|
|
15489
|
+
|
|
15490
|
+
// ① 负例:前缀形态合法、日历不自洽(2026-02-30 不存在)——不得被采作基线。快照哨兵
|
|
15491
|
+
// `lessons.entries=123456` 一旦出现在输出里,即证明这份报告被当成了基线。
|
|
15492
|
+
writeFile(dir, '.specs/health/2026-02-30-HEALTH.md', healthReportFixture('2026-02-30', 123456));
|
|
15493
|
+
const invalidOnly = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15494
|
+
assertExit(invalidOnly, 0);
|
|
15495
|
+
assertOut(invalidOnly, '基线:无(`.specs/health` 下无日期不同的历史报告)');
|
|
15496
|
+
assertNotOut(invalidOnly, '2026-02-30-HEALTH.md');
|
|
15497
|
+
assertNotOut(invalidOnly, '123456');
|
|
15498
|
+
|
|
15499
|
+
// ② 正例 + 越界:合法旧报告与日历不自洽者并存 → 取合法那份(日历不自洽的名字排序在后,
|
|
15500
|
+
// 旧实现「取最后一份」必然取到它 → 哨兵串成 123456 而非 999999)
|
|
15501
|
+
writeFile(dir, '.specs/health/2026-01-05-HEALTH.md', healthReportFixture('2026-01-05', 999999));
|
|
15502
|
+
const picked = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15503
|
+
assertExit(picked, 0);
|
|
15504
|
+
assertOut(picked, '基线:`.specs/health/2026-01-05-HEALTH.md`');
|
|
15505
|
+
assertOut(picked, '`lessons.entries`:999999 → ');
|
|
15506
|
+
assertNotOut(picked, '2026-02-30-HEALTH.md');
|
|
15507
|
+
assertNotOut(picked, '123456');
|
|
15508
|
+
|
|
15509
|
+
// ③ 结构锚:health 真实消费 time-utils 的日期判定;收敛面内只许 time-utils 表达该形态
|
|
15510
|
+
const healthText = fs.readFileSync(SIDE_HEALTH, 'utf8');
|
|
15511
|
+
assertTrue(hasNamedImport(healthText, './time-utils.mjs', 'archiveDateFromName'),
|
|
15512
|
+
'health.mjs 未从 time-utils.mjs 具名 import archiveDateFromName(日期判据第二份表达)');
|
|
15513
|
+
assertTrue(healthText.includes('archiveDateFromName('),
|
|
15514
|
+
'health.mjs 未真实消费 archiveDateFromName(单一权威应被调用)');
|
|
15515
|
+
const faceHits = datePrefixRegexpHits(__dirname, DATE_PREFIX_CONVERGENCE_FACE);
|
|
15516
|
+
assertEqual(faceHits.length, 1, '日期前缀形态实现面(收敛面内应恰 1 处)实际 ' + JSON.stringify(faceHits));
|
|
15517
|
+
assertEqual(faceHits[0].file, 'time-utils.mjs', '日期前缀形态落点文件');
|
|
15518
|
+
|
|
15519
|
+
// ③b 边界锚(可见,不静默排除):guard 的两处日期匹配是文档**内容**里的日期条目匹配
|
|
15520
|
+
//(行锚 + `matchAll(.../gm)`),不是文件名前缀判定,且不在本任务写边界内——形态一旦
|
|
15521
|
+
// 改变即变红,强制重评收敛面。
|
|
15522
|
+
const guardText = fs.readFileSync(path.join(__dirname, 'workflow-guard.mjs'), 'utf8');
|
|
15523
|
+
assertEqual((guardText.match(/matchAll\(\/\^[^\n]*\\d\{4\}-\\d\{2\}-\\d\{2\}[^\n]*\/gm\)/g) ?? []).length, 2,
|
|
15524
|
+
'workflow-guard 的日期匹配不再是「行锚 + 内容条目」两处形态——须重评日期前缀判据的收敛面');
|
|
15525
|
+
|
|
15526
|
+
// ④ 反向构造:合成引擎目录(单份前缀正则 → 检出 1;再放第二份 → 检出 2)
|
|
15527
|
+
const synthetic = makeTmp();
|
|
15528
|
+
try {
|
|
15529
|
+
writeFile(synthetic, 'single.mjs', "const REPORT_DATE_PREFIX = /^(\\d{4}-\\d{2}-\\d{2})/;\n");
|
|
15530
|
+
assertEqual(datePrefixRegexpHits(synthetic).length, 1, '合成目录单实现检出数');
|
|
15531
|
+
writeFile(synthetic, 'second.mjs',
|
|
15532
|
+
"function reportDateOf(name) {\n return /^(\\d{4}-\\d{2}-\\d{2})/.exec(name);\n}\n");
|
|
15533
|
+
assertEqual(datePrefixRegexpHits(synthetic).length, 2, '合成目录第二份实现检出数(判据须变红)');
|
|
15534
|
+
} finally {
|
|
15535
|
+
cleanupTmpDir(synthetic);
|
|
15536
|
+
}
|
|
15537
|
+
},
|
|
15538
|
+
},
|
|
15539
|
+
|
|
15540
|
+
// 296: context-scan 改写 CONTEXT.md 前落备份——命名族(目标文档同目录 + `.bak-<本地日期>`)与
|
|
15541
|
+
// 失败处置由 state-schema.mjs 的共享助手单源提供(消费关系与零内联见场景 301):备份内容 =
|
|
15542
|
+
// 改写前版本;同日重复改写只保留一份当日备份(同名覆盖,不堆积);复制不成功时目标与 state
|
|
15543
|
+
// 逐字节不变(备份**先于**写入,不是事后补)。
|
|
15544
|
+
{
|
|
15545
|
+
name: '296 context-scan 改写前落备份:同形命名·内容为改写前版本·复制失败 fail-closed 零写入',
|
|
15546
|
+
run: (dir) => {
|
|
15547
|
+
const contextFile = path.join(dir, '.specs', 'CONTEXT.md');
|
|
15548
|
+
const original = contextFixtureText();
|
|
15549
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
15550
|
+
writeFile(dir, '.specs/CONTEXT.md', original);
|
|
15551
|
+
writeState(dir, baseState('open'));
|
|
15552
|
+
|
|
15553
|
+
// ① 改写落备份:同目录、命名族 `.bak-<日期>`、内容 = 改写前版本;双落点写入照常
|
|
15554
|
+
const first = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
15555
|
+
assertExit(first, 0);
|
|
15556
|
+
const backups = fs.readdirSync(path.join(dir, '.specs'))
|
|
15557
|
+
.filter((name) => /^CONTEXT\.md\.bak-\d{4}-\d{2}-\d{2}$/.test(name));
|
|
15558
|
+
assertEqual(backups.length, 1, '改写前的备份份数(应恰 1 份同目录 `.bak-<日期>`)实际 ' + JSON.stringify(backups));
|
|
15559
|
+
assertEqual(backups[0], 'CONTEXT.md.bak-' + today, '备份命名(应为改写当日的本地日期)');
|
|
15560
|
+
assertEqual(fs.readFileSync(path.join(dir, '.specs', backups[0]), 'utf8'), original, '备份内容应为改写前版本');
|
|
15561
|
+
assertTrue(fs.readFileSync(contextFile, 'utf8') !== original, 'CONTEXT.md 未被改写(夹具前提不成立)');
|
|
15562
|
+
|
|
15563
|
+
// ② 同日再改写:同名覆盖——只保留一份当日备份,内容为该轮改写前版本(不堆积、链路不丢)
|
|
15564
|
+
const intermediate = contextFixtureText().replace('2026-09-01T10:00:00+08:00', '2026-09-02T10:00:00+08:00');
|
|
15565
|
+
writeFile(dir, '.specs/CONTEXT.md', intermediate);
|
|
15566
|
+
const second = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
15567
|
+
assertExit(second, 0);
|
|
15568
|
+
assertEqual(fs.readdirSync(path.join(dir, '.specs'))
|
|
15569
|
+
.filter((name) => name.startsWith('CONTEXT.md.bak-')).length, 1, '同日重复改写的当日备份份数');
|
|
15570
|
+
assertEqual(fs.readFileSync(path.join(dir, '.specs', backups[0]), 'utf8'), intermediate,
|
|
15571
|
+
'第二轮的备份内容应为该轮改写前版本');
|
|
15572
|
+
|
|
15573
|
+
// ③ 复制不成功 → fail-closed:目标文档与 state 逐字节不变(备份先于写入,写入面不留半态)
|
|
15574
|
+
writeFile(dir, '.specs/CONTEXT.md', original);
|
|
15575
|
+
const stateBytes = readStateBytes(dir);
|
|
15576
|
+
fs.rmSync(path.join(dir, '.specs', backups[0]), { force: true });
|
|
15577
|
+
fs.mkdirSync(path.join(dir, '.specs', backups[0]));
|
|
15578
|
+
const blocked = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
15579
|
+
assertExit(blocked, 1);
|
|
15580
|
+
assertOut(blocked, 'BLOCKED');
|
|
15581
|
+
assertEqual(fs.readFileSync(contextFile, 'utf8'), original, '备份失败的一轮改写了 CONTEXT.md');
|
|
15582
|
+
assertStateBytesUnchanged(dir, stateBytes, '备份失败的一轮');
|
|
15583
|
+
|
|
15584
|
+
// ④ 命名族与失败处置的**同源**判据已随备份助手抽取移到场景 301(唯一定义 + 两消费方零内联
|
|
15585
|
+
// + 合成反向构造):此处不重复表达同一判据,只保留上面的真实行为锚。
|
|
15586
|
+
},
|
|
15587
|
+
},
|
|
15588
|
+
|
|
15589
|
+
// 297: health 的审计行与报告落盘路径**恒输出**——报告是唯一写入面,调用方至少要能从标准输出
|
|
15590
|
+
// 确认「跑没跑、落在哪、基线是谁」:不带 `--stdout` 时此前 stdout 为空(审计行 0 命中),
|
|
15591
|
+
// 报告路径无处可见;`--stdout` 时报告正文在前、审计行追加在后(正文仍是落盘字节,审计行不进
|
|
15592
|
+
// 报告)。审计行内容当日确定(日期 / 在场判定 / 基线),不引入新的易变行。另锚:审计行用的
|
|
15593
|
+
// CLI 路径标签是三条侧命令的**共享助手**(evolve.mjs 唯一定义),不给同一显示决定留下第二份。
|
|
15594
|
+
{
|
|
15595
|
+
name: '297 health 审计行恒输出:HEALTH: 行与报告落盘路径(不带 --stdout 亦然)+ 正文不回流 + --help 不产报告',
|
|
15596
|
+
run: (dir) => {
|
|
15597
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15598
|
+
writeState(dir, baseState('open'));
|
|
15599
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
15600
|
+
const reportFile = path.join(dir, '.specs', 'health', today + '-HEALTH.md');
|
|
15601
|
+
const reportLine = 'HEALTH: 报告 `.specs/health/' + today + '-HEALTH.md`';
|
|
15602
|
+
|
|
15603
|
+
// ① 不带 `--stdout`:审计行与报告路径仍必须输出,且**不**把报告正文回流
|
|
15604
|
+
const quiet = runSideScript(SIDE_HEALTH, ['--root', dir], dir);
|
|
15605
|
+
assertExit(quiet, 0);
|
|
15606
|
+
assertOut(quiet, reportLine);
|
|
15607
|
+
assertOut(quiet, 'HEALTH-DONE');
|
|
15608
|
+
assertNotOut(quiet, '## 确定性层(机器可判)');
|
|
15609
|
+
// 审计行点名的路径必须是真实落盘的工件(文案与产物同源)
|
|
15610
|
+
assertTrue(fs.existsSync(reportFile), '审计行点名的报告未落盘: ' + reportFile);
|
|
15611
|
+
|
|
15612
|
+
// ② 带 `--stdout`:报告正文在前(与落盘逐字节一致)、审计行在后
|
|
15613
|
+
const loud = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15614
|
+
assertExit(loud, 0);
|
|
15615
|
+
assertOut(loud, reportLine);
|
|
15616
|
+
assertOut(loud, 'HEALTH-DONE');
|
|
15617
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
15618
|
+
assertTrue(loud.output.startsWith(reportText), '--stdout 的报告正文应与落盘逐字节一致(审计行追加在后)');
|
|
15619
|
+
assertTrue(loud.output.indexOf('HEALTH-DONE') > loud.output.indexOf(reportText),
|
|
15620
|
+
'审计行应在报告正文之后(顺序反了会让消费方把摘要当正文)');
|
|
15621
|
+
|
|
15622
|
+
// ③ 审计行回显本次采用的基线:合法旧报告在场时点名它(同日重跑不与自己对比)
|
|
15623
|
+
writeFile(dir, '.specs/health/2026-01-05-HEALTH.md', healthReportFixture('2026-01-05', 999999));
|
|
15624
|
+
const withBaseline = runSideScript(SIDE_HEALTH, ['--root', dir], dir);
|
|
15625
|
+
assertExit(withBaseline, 0);
|
|
15626
|
+
assertOut(withBaseline, 'HEALTH: 日期 ' + today);
|
|
15627
|
+
assertOut(withBaseline, '基线 `.specs/health/2026-01-05-HEALTH.md`');
|
|
15628
|
+
|
|
15629
|
+
// ④ `--help` 短路:打用法、不产报告、不输出审计行(用法面语义不变)
|
|
15630
|
+
const help = runSideScript(SIDE_HEALTH, ['--help'], dir);
|
|
15631
|
+
assertExit(help, 0);
|
|
15632
|
+
assertOut(help, 'health.mjs');
|
|
15633
|
+
assertNotOut(help, 'HEALTH: 报告');
|
|
15634
|
+
|
|
15635
|
+
// ⑤ 结构锚:CLI 路径标签**单一来源**(三条命令的摘要行同形)——定义只在共享助手模块
|
|
15636
|
+
// evolve.mjs(侧命令共享助手的既有落点),另两条具名 import 后真实调用;第二份同名
|
|
15637
|
+
// 助手(或改回各处内联)即红。
|
|
15638
|
+
const labelDefinition = engineDefinitionHits('relativeLabel');
|
|
15639
|
+
assertEqual(labelDefinition.length, 1, 'relativeLabel 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(labelDefinition));
|
|
15640
|
+
assertEqual(labelDefinition[0].file, 'evolve.mjs', 'relativeLabel 定义文件');
|
|
15641
|
+
for (const file of ['health.mjs', 'context-scan.mjs']) {
|
|
15642
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
15643
|
+
assertTrue(hasNamedImport(text, './evolve.mjs', 'relativeLabel'),
|
|
15644
|
+
file + ' 未从共享助手模块 import 路径标签(第二份同名助手或未接线)');
|
|
15645
|
+
assertTrue(text.includes('relativeLabel('), file + ' 未真实调用共享路径标签');
|
|
15646
|
+
}
|
|
15647
|
+
},
|
|
15648
|
+
},
|
|
15649
|
+
|
|
15650
|
+
// 298: 禁裸拼接静态锚(DESIGN R4 的落地)——时间形态 / 格式化的唯一权威是 time-utils.mjs:
|
|
15651
|
+
// 三条侧命令零容忍(人可见报告 / CLI 摘要行 / 备份名);其余引擎脚本走**显式白名单 + 逐条理由**
|
|
15652
|
+
// (既有 13 处都是已持久化的机器字段,迁移留专门窗口)。判别力两条:① 白名单判定是纯函数,
|
|
15653
|
+
// 合成输入可驱动「条数漂移(增 / 减)」与「未登记文件」三态必报;② 合成引擎目录注入第二处
|
|
15654
|
+
// 裸拼接 → 检出必增(证明真实面判据不恒真空过)。
|
|
15655
|
+
{
|
|
15656
|
+
name: '298 禁裸拼接静态锚:三侧命令零容忍 + 引擎 13 处显式白名单(逐条理由)+ 合成反向构造',
|
|
15657
|
+
run: () => {
|
|
15658
|
+
// ① 三条侧命令零容忍(人可见面的时间形态只许走 time-utils)
|
|
15659
|
+
const sideHits = bareIsoTimestampHits(__dirname, BARE_ISO_SIDE_COMMANDS);
|
|
15660
|
+
assertEqual(sideHits.length, 0,
|
|
15661
|
+
'侧命令出现裸时间拼接(人可见面须走 time-utils 的 nowTimestamp / formatLocalTimestamp): ' + JSON.stringify(sideHits));
|
|
15662
|
+
|
|
15663
|
+
// ② 其余引擎脚本 = 精确白名单:条数逐文件相等 + 每条例外带非空理由
|
|
15664
|
+
const engineHits = bareIsoTimestampHits(__dirname).filter((hit) => !BARE_ISO_SIDE_COMMANDS.includes(hit.file));
|
|
15665
|
+
assertEqual(engineHits.reduce((sum, hit) => sum + hit.count, 0), 13, '引擎既有裸拼接落点总数(白名单代数)');
|
|
15666
|
+
const problems = bareIsoWhitelistProblems(engineHits, BARE_ISO_ENGINE_WHITELIST);
|
|
15667
|
+
assertEqual(problems.length, 0, '白名单漂移: ' + problems.join(' | '));
|
|
15668
|
+
for (const entry of BARE_ISO_ENGINE_WHITELIST) {
|
|
15669
|
+
assertTrue(typeof entry.reason === 'string' && entry.reason.length >= 20,
|
|
15670
|
+
entry.file + ' 的白名单条目缺理由(豁免必须是显式且有据的,不是静默名单)');
|
|
15671
|
+
}
|
|
15672
|
+
|
|
15673
|
+
// ③ 白名单判定的判别力(纯函数 · 合成输入):等价集合不报;三类漂移各自必报
|
|
15674
|
+
// (合成等价集合的条数取真实白名单首条的当前值——它必须与常量同值,否则第 1 条断言即红)
|
|
15675
|
+
const equivalent = [{ file: 'a.mjs', count: 7 }, { file: 'b.mjs', count: 4 }, { file: 'c.mjs', count: 1 }, { file: 'd.mjs', count: 1 }];
|
|
15676
|
+
const whitelist = BARE_ISO_ENGINE_WHITELIST.map((entry, index) => ({ ...entry, file: equivalent[index].file }));
|
|
15677
|
+
assertEqual(bareIsoWhitelistProblems(equivalent, whitelist).length, 0, '等价集合不应报白名单漂移');
|
|
15678
|
+
const newcomer = bareIsoWhitelistProblems([...equivalent, { file: 'newcomer.mjs', count: 1 }], whitelist);
|
|
15679
|
+
assertTrue(newcomer.some((problem) => problem.includes('newcomer.mjs') && problem.includes('未登记白名单')),
|
|
15680
|
+
'未登记文件的裸拼接未被判定: ' + JSON.stringify(newcomer));
|
|
15681
|
+
const grown = bareIsoWhitelistProblems(
|
|
15682
|
+
equivalent.map((hit, index) => (index === 0 ? { ...hit, count: hit.count + 1 } : hit)), whitelist);
|
|
15683
|
+
assertTrue(grown.some((problem) => problem.includes('白名单 7 处 / 实际 8 处')),
|
|
15684
|
+
'白名单条数增长未被判定: ' + JSON.stringify(grown));
|
|
15685
|
+
const shrunk = bareIsoWhitelistProblems(equivalent.slice(1), whitelist);
|
|
15686
|
+
assertTrue(shrunk.some((problem) => problem.includes('白名单 7 处 / 实际 0 处')),
|
|
15687
|
+
'已迁移落点未同步收窄白名单未被判定: ' + JSON.stringify(shrunk));
|
|
15688
|
+
|
|
15689
|
+
// ④ 合成引擎目录反向构造:单处 → 检出 1;再注入一处 → 检出 2(判据不恒真空过)。
|
|
15690
|
+
// 样例经拼接构造,避免套件自身源码携带该字面量而污染真实面计数(本套件同样在扫描面内)。
|
|
15691
|
+
const bareIsoSample = 'new Date().' + 'toISOString()';
|
|
15692
|
+
const synthetic = makeTmp();
|
|
15693
|
+
try {
|
|
15694
|
+
writeFile(synthetic, 'one.mjs', 'export const a = () => ' + bareIsoSample + ';\n');
|
|
15695
|
+
assertEqual(bareIsoTimestampHits(synthetic).length, 1, '合成目录单处检出数');
|
|
15696
|
+
writeFile(synthetic, 'two.mjs', 'export const b = () => ' + bareIsoSample + ';\n');
|
|
15697
|
+
assertEqual(bareIsoTimestampHits(synthetic).length, 2, '合成目录第二处检出数(判据须变红)');
|
|
15698
|
+
// 注释里的引用不算实现(判据只看代码)
|
|
15699
|
+
writeFile(synthetic, 'three.mjs', '// 反例引用: ' + bareIsoSample + '\nexport const c = 1;\n');
|
|
15700
|
+
assertEqual(bareIsoTimestampHits(synthetic).length, 2, '行注释中的引用不应计入实现面');
|
|
15701
|
+
} finally {
|
|
15702
|
+
cleanupTmpDir(synthetic);
|
|
15703
|
+
}
|
|
15704
|
+
},
|
|
15705
|
+
},
|
|
15706
|
+
|
|
15707
|
+
// 299: 可选工具超时预算(60s 内)+ 超时不静默——常量与调用点同源,且「工具在场但运行未完成」
|
|
15708
|
+
// 必须把降级原因(含本次超时预算)写进报告、快照读数按 `present` 而非 `ok` 落盘,退出码仍 0
|
|
15709
|
+
// (可选工具不可用不是失败)。判别力:常量越预算即红;夹具工具(在场但跑不起来)触发同一
|
|
15710
|
+
// 失败分支,报告里必须看到降级原因——不静默、不冒充成功读数。
|
|
15711
|
+
{
|
|
15712
|
+
name: '299 工具超时收口:常量 ≤ 60s 且与调用点同源 + 在场但运行失败必记降级原因(含预算)',
|
|
15713
|
+
run: (dir) => {
|
|
15714
|
+
const healthText = fs.readFileSync(SIDE_HEALTH, 'utf8');
|
|
15715
|
+
const match = /const TOOL_TIMEOUT_MS = (\d+);/.exec(healthText);
|
|
15716
|
+
assertTrue(match !== null, 'health.mjs 缺工具超时常量 TOOL_TIMEOUT_MS');
|
|
15717
|
+
const budget = Number(match[1]);
|
|
15718
|
+
assertTrue(budget > 0 && budget <= 60000, '工具超时常量超出 60s 预算: ' + budget + ' ms');
|
|
15719
|
+
assertTrue(/timeout: TOOL_TIMEOUT_MS/.test(healthText), '工具调用未消费超时常量(常量会变成装饰)');
|
|
15720
|
+
assertTrue(healthText.includes('超时预算'), '降级原因未回显本次超时预算(超时须可自证,不静默)');
|
|
15721
|
+
|
|
15722
|
+
// 真实链路:夹具工具「在场」(探面命中 <根>/node_modules/.bin/)但跑不起来 → 同一失败分支
|
|
15723
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15724
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
|
|
15725
|
+
fs.mkdirSync(path.join(dir, 'src'), { recursive: true });
|
|
15726
|
+
fs.mkdirSync(path.join(dir, 'node_modules', '.bin'), { recursive: true });
|
|
15727
|
+
const toolPath = path.join(dir, 'node_modules', '.bin', 'jscpd');
|
|
15728
|
+
fs.writeFileSync(toolPath, '#!/usr/bin/env node\nprocess.exit(3);\n', 'utf8');
|
|
15729
|
+
fs.chmodSync(toolPath, 0o755);
|
|
15730
|
+
const res = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15731
|
+
assertExit(res, 0);
|
|
15732
|
+
assertOut(res, '未采集——工具在场但运行未完成(超时预算 ' + budget + ' ms;');
|
|
15733
|
+
assertOut(res, 'redundancy.jscpd=present');
|
|
15734
|
+
assertNotOut(res, 'redundancy.jscpd=ok');
|
|
15735
|
+
assertOut(res, '- **jscpd**:在场——字面重复块读数见「冗余扫描」段');
|
|
15736
|
+
},
|
|
15737
|
+
},
|
|
15738
|
+
|
|
15739
|
+
// 300: 读数快照的键形态**单一来源**——往返判据:把生产者自己产出的快照段整段当作历史基线
|
|
15740
|
+
// 喂回去,每个产出的键都必须被读回(零「基线无此读数」、条数与产出条数相等);反例:给写方
|
|
15741
|
+
// 真实产出的键写异常值 → 必出趋势行;近形状键(大小写不符)不得被读走。此前写方发 6 个含
|
|
15742
|
+
// 大写字母的键、读方的键形态正则只认全小写:6/18 个键恒判「(基线无此读数)」,逐键趋势
|
|
15743
|
+
// 静默失效且不报错(假绿形态)。
|
|
15744
|
+
{
|
|
15745
|
+
name: '300 快照键形态单一来源:产出快照往返零「基线无此读数」+ 真实键异常值必出趋势行 + 近形状键不误读',
|
|
15746
|
+
run: (dir) => {
|
|
15747
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15748
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
|
|
15749
|
+
writeState(dir, baseState('open'));
|
|
15750
|
+
|
|
15751
|
+
// ① 生产面自证:先跑一次拿到真实报告,取其快照段原文(不解析、不重排)
|
|
15752
|
+
const firstRun = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15753
|
+
assertExit(firstRun, 0);
|
|
15754
|
+
const firstReport = fs.readFileSync(path.join(dir, '.specs', 'health',
|
|
15755
|
+
requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date()) + '-HEALTH.md'), 'utf8');
|
|
15756
|
+
const section = snapshotSectionOf(firstReport);
|
|
15757
|
+
assertTrue(section !== null, '报告缺「## 读数快照」段(往返夹具前提不成立)');
|
|
15758
|
+
const producedEntries = snapshotEntryCount(section);
|
|
15759
|
+
assertTrue(producedEntries >= 10, '快照条数异常(往返判据的样本太小): ' + producedEntries);
|
|
15760
|
+
|
|
15761
|
+
// ② 往返:产出快照整段当作 2026-01-05 的历史基线 → 每个键都必须被读回
|
|
15762
|
+
writeFile(dir, '.specs/health/2026-01-05-HEALTH.md', healthReportWithSnapshot('2026-01-05', section));
|
|
15763
|
+
const roundTrip = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15764
|
+
assertExit(roundTrip, 0);
|
|
15765
|
+
assertOut(roundTrip, '基线:`.specs/health/2026-01-05-HEALTH.md`');
|
|
15766
|
+
assertNotOut(roundTrip, '(基线无此读数)');
|
|
15767
|
+
const unchanged = (roundTrip.output.match(/(无变化)/g) ?? []).length;
|
|
15768
|
+
assertEqual(unchanged, producedEntries, '往返后逐键「无变化」条数应等于产出条数(有键没被读回)');
|
|
15769
|
+
|
|
15770
|
+
// ③ 真实产出的键(含此前恒被判「基线无此读数」的驼峰键)写异常值 → 必出趋势行
|
|
15771
|
+
const anomalous = section
|
|
15772
|
+
.replace(/(^|\n)context\.lineCount=[^\n]*/, '$1context.lineCount=999999')
|
|
15773
|
+
.replace(/(^|\n)git\.head=[^\n]*/, '$1git.head=ffffffff');
|
|
15774
|
+
writeFile(dir, '.specs/health/2026-01-06-HEALTH.md', healthReportWithSnapshot('2026-01-06', anomalous));
|
|
15775
|
+
const trend = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15776
|
+
assertExit(trend, 0);
|
|
15777
|
+
assertOut(trend, '基线:`.specs/health/2026-01-06-HEALTH.md`');
|
|
15778
|
+
assertOut(trend, '`context.lineCount`:999999 → ');
|
|
15779
|
+
assertOut(trend, '`git.head`:ffffffff → ');
|
|
15780
|
+
assertNotOut(trend, '999999(基线无此读数)');
|
|
15781
|
+
assertNotOut(trend, 'ffffffff(基线无此读数)');
|
|
15782
|
+
|
|
15783
|
+
// ④ 近形状键(大小写不符)不是本版本的读数面:不得被读走(报「基线无此读数」而非伪造趋势)
|
|
15784
|
+
const nearMiss = section.replace(/(^|\n)context\.lineCount=[^\n]*/, '$1context.linecount=888888');
|
|
15785
|
+
writeFile(dir, '.specs/health/2026-01-07-HEALTH.md', healthReportWithSnapshot('2026-01-07', nearMiss));
|
|
15786
|
+
const miss = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
15787
|
+
assertExit(miss, 0);
|
|
15788
|
+
assertOut(miss, '基线:`.specs/health/2026-01-07-HEALTH.md`');
|
|
15789
|
+
assertNotOut(miss, '888888');
|
|
15790
|
+
assertOut(miss, '`context.lineCount`:');
|
|
15791
|
+
assertOut(miss, '(基线无此读数)');
|
|
15792
|
+
},
|
|
15793
|
+
},
|
|
15794
|
+
|
|
15795
|
+
// 301: 备份改写前版本**单一来源**——命名族(目标文档同目录 + `.bak-<本地日期>`)与失败处置
|
|
15796
|
+
// 收敛为 state-schema.mjs 的单一导出(与原子写同址),evolve 与 context-scan 只消费导出:
|
|
15797
|
+
// 命名族或失败处置再演进时不会只改到一侧。判别力:① 定义面唯一 + 两消费方零内联(第二份
|
|
15798
|
+
// 实现 → 收敛面内检出 2 处);② evolve 真实链路(备份 = 改写前版本、命名族命中当日日期、
|
|
15799
|
+
// 复制失败整轮 fail-closed:目标文档 / state / 报告三处零改动,与 context-scan 同处置);
|
|
15800
|
+
// ③ 合成目录反向构造证明①的判据不恒真空过。
|
|
15801
|
+
{
|
|
15802
|
+
name: '301 备份助手单一来源:state-schema 唯一导出·两消费方零内联 + evolve 真实链路 fail-closed',
|
|
15803
|
+
run: async (dir) => {
|
|
15804
|
+
// ① 收敛面内恰一处实现(命名族字面量 + 复制调用同现者)——修复前 evolve 与 context-scan
|
|
15805
|
+
// 各一份(同形但两份),此断言即「第二份实现必红」的落点
|
|
15806
|
+
const impl = inlineBackupHits(__dirname, BACKUP_IMPL_FACE);
|
|
15807
|
+
assertEqual(impl.length, 1, '备份实现面(收敛面内应恰 1 处)实际 ' + JSON.stringify(impl));
|
|
15808
|
+
assertEqual(impl[0].file, 'state-schema.mjs', '备份实现落点文件');
|
|
15809
|
+
|
|
15810
|
+
// ② 定义面唯一 + 两消费方具名 import 与真实调用
|
|
15811
|
+
const definition = engineDefinitionHits('backupBeforeWrite');
|
|
15812
|
+
assertEqual(definition.length, 1, 'backupBeforeWrite 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(definition));
|
|
15813
|
+
assertEqual(definition[0].file, 'state-schema.mjs', 'backupBeforeWrite 定义文件');
|
|
15814
|
+
const backupHelper = requireModuleExport(stateSchemaModule, 'backupBeforeWrite', 'state-schema.mjs');
|
|
15815
|
+
for (const file of ['evolve.mjs', 'context-scan.mjs']) {
|
|
15816
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
15817
|
+
assertTrue(hasNamedImport(text, './state-schema.mjs', 'backupBeforeWrite'),
|
|
15818
|
+
file + ' 未从 state-schema.mjs 具名 import 备份助手(第二份实现或未接线)');
|
|
15819
|
+
assertTrue(text.includes('backupBeforeWrite('), file + ' 未真实调用共享备份助手');
|
|
15820
|
+
}
|
|
15821
|
+
|
|
15822
|
+
// ③ 单一导出的行为(命名族由共享实现派生:`.bak-<本地日期>`,内容 = 改写前版本)
|
|
15823
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
15824
|
+
const stamp = requireModuleExport(timeUtilsModule, 'nowTimestamp', 'time-utils.mjs')();
|
|
15825
|
+
const probe = makeTmp();
|
|
15826
|
+
try {
|
|
15827
|
+
const target = path.join(probe, 'doc.md');
|
|
15828
|
+
writeFile(probe, 'doc.md', '改写前内容\n');
|
|
15829
|
+
await backupHelper(target, stamp);
|
|
15830
|
+
const produced = target + '.bak-' + today;
|
|
15831
|
+
assertTrue(fs.existsSync(produced), '备份未按「同目录 + 当日本地日期」落点: ' + produced);
|
|
15832
|
+
assertEqual(fs.readFileSync(produced, 'utf8'), '改写前内容\n', '备份内容应为改写前版本');
|
|
15833
|
+
} finally {
|
|
15834
|
+
cleanupTmpDir(probe);
|
|
15835
|
+
}
|
|
15836
|
+
|
|
15837
|
+
// ④ evolve 真实链路:apply 落备份(内容 = 改写前版本)
|
|
15838
|
+
writeFile(dir, '.specs/archive/2026-10-02-backup/DESIGN.md',
|
|
15839
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 备份单一来源夹具条目\n');
|
|
15840
|
+
const original = contextFixtureText();
|
|
15841
|
+
const contextFile = path.join(dir, '.specs', 'CONTEXT.md');
|
|
15842
|
+
const backupFile = contextFile + '.bak-' + today;
|
|
15843
|
+
writeFile(dir, '.specs/CONTEXT.md', original);
|
|
15844
|
+
writeState(dir, baseState('open'));
|
|
15845
|
+
const apply = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-backup#1', '--root', dir], dir);
|
|
15846
|
+
assertExit(apply, 0);
|
|
15847
|
+
assertTrue(fs.existsSync(backupFile), 'evolve apply 未落改写前备份: ' + backupFile);
|
|
15848
|
+
assertEqual(fs.readFileSync(backupFile, 'utf8'), original, '备份内容应为改写前版本');
|
|
15849
|
+
assertTrue(fs.readFileSync(contextFile, 'utf8') !== original, 'CONTEXT.md 未被改写(夹具前提不成立)');
|
|
15850
|
+
|
|
15851
|
+
// ⑤ 复制不成功 → fail-closed:目标文档 / state / 报告三处零改动(与 context-scan 同处置)
|
|
15852
|
+
writeFile(dir, '.specs/CONTEXT.md', original);
|
|
15853
|
+
const stateBytes = readStateBytes(dir);
|
|
15854
|
+
const reportFile = path.join(dir, '.specs', 'evolve', today + '-EVOLVE.md');
|
|
15855
|
+
const reportBefore = fs.readFileSync(reportFile);
|
|
15856
|
+
fs.rmSync(backupFile, { force: true });
|
|
15857
|
+
fs.mkdirSync(backupFile);
|
|
15858
|
+
const blocked = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-backup#1', '--root', dir], dir);
|
|
15859
|
+
assertExit(blocked, 1);
|
|
15860
|
+
assertOut(blocked, 'BLOCKED');
|
|
15861
|
+
assertEqual(fs.readFileSync(contextFile, 'utf8'), original, '备份失败的 apply 轮改写了 CONTEXT.md');
|
|
15862
|
+
assertStateBytesUnchanged(dir, stateBytes, '备份失败的 apply 轮');
|
|
15863
|
+
assertTrue(fs.readFileSync(reportFile).equals(reportBefore), '备份失败的 apply 轮改写了报告');
|
|
15864
|
+
|
|
15865
|
+
// ⑥ 合成目录反向构造:单实现 → 1;再放第二份 → 2
|
|
15866
|
+
const synthetic = makeTmp();
|
|
15867
|
+
try {
|
|
15868
|
+
writeFile(synthetic, 'single.mjs',
|
|
15869
|
+
"export async function duplicateBackup(file, ts) {\n"
|
|
15870
|
+
+ " const backup = file + '.bak-' + ts;\n"
|
|
15871
|
+
+ ' await fs.copyFile(file, backup);\n'
|
|
15872
|
+
+ '}\n');
|
|
15873
|
+
assertEqual(inlineBackupHits(synthetic).length, 1, '合成目录单实现检出数');
|
|
15874
|
+
writeFile(synthetic, 'second.mjs',
|
|
15875
|
+
"async function anotherBackup(file, ts) {\n"
|
|
15876
|
+
+ " const backup = file + '.bak-' + ts;\n"
|
|
15877
|
+
+ ' await fs.copyFile(file, backup);\n'
|
|
15878
|
+
+ '}\n');
|
|
15879
|
+
assertEqual(inlineBackupHits(synthetic).length, 2, '合成目录第二份实现检出数(判据须变红)');
|
|
15880
|
+
} finally {
|
|
15881
|
+
cleanupTmpDir(synthetic);
|
|
15882
|
+
}
|
|
15883
|
+
},
|
|
15884
|
+
},
|
|
15885
|
+
|
|
15886
|
+
// 302: AC-11 的四条时间硬规则文本锚(存在级,但**指真实实体**):① 分发面技能文本(入口 SKILL
|
|
15887
|
+
// 的侧命令「共同边界」)陈述规则 ①②③;② 验证阶梯(docs/internal/WORKING-METHOD.md 一·五 的
|
|
15888
|
+
// 「环境 / 过程纪律·时间」条)承载规则 ①~③ 并落实 ④(纪律已写入阶梯本身);③ 文本点名的实体
|
|
15889
|
+
// 在树内真实存在——`time-utils.mjs` 在场且真实定义被点名的判据符号(防锚指向幽灵:散文提到的
|
|
15890
|
+
// 东西必须在树里找得到)。维护者面结构性缺席(CI 全新检出 / worktree)时验证阶梯半边输出可见
|
|
15891
|
+
// SKIP 行(未验证 ≠ 通过),分发面半边恒检。
|
|
15892
|
+
{
|
|
15893
|
+
name: '302 时间纪律四条硬规则文本锚:入口技能陈述 ①②③ + 验证阶梯承载四条 + 点名实体真实在场',
|
|
15894
|
+
run: () => {
|
|
15895
|
+
const skillsRoot = skillsRootForScriptsDir(__dirname);
|
|
15896
|
+
const entrySkill = path.join(skillsRoot, 'flow-comet', 'SKILL.md');
|
|
15897
|
+
const skillText = fs.readFileSync(entrySkill, 'utf8');
|
|
15898
|
+
const skillProblems = timeDisciplineTextProblems('入口 SKILL', skillText);
|
|
15899
|
+
assertEqual(skillProblems.length, 0, '时间纪律文本锚: ' + skillProblems.join(' | '));
|
|
15900
|
+
|
|
15901
|
+
// 反向构造(真实文本逐条移除 · 合成输入驱动同一判据):任一条规则的关键词被移走 → 该条必报。
|
|
15902
|
+
for (const [rule, tokens] of TIME_DISCIPLINE_RULES) {
|
|
15903
|
+
const stripped = tokens.reduce((text, token) => text.replace(token, '(反向构造:移除)'), skillText);
|
|
15904
|
+
assertTrue(stripped !== skillText, '反向构造前提不成立(入口 SKILL 缺该条关键词): ' + rule);
|
|
15905
|
+
assertTrue(timeDisciplineTextProblems('入口 SKILL', stripped).some((problem) => problem.includes(rule)),
|
|
15906
|
+
'逐条移除未被判违规(判别力缺失): ' + rule);
|
|
15907
|
+
}
|
|
15908
|
+
|
|
15909
|
+
if (maintainerFacePresent()) {
|
|
15910
|
+
const ladder = fs.readFileSync(path.join(REPO_ROOT, 'docs/internal/WORKING-METHOD.md'), 'utf8');
|
|
15911
|
+
const ladderProblems = timeDisciplineTextProblems('验证阶梯', ladder);
|
|
15912
|
+
assertEqual(ladderProblems.length, 0, '验证阶梯文本锚: ' + ladderProblems.join(' | '));
|
|
15913
|
+
assertTrue(ladder.includes('环境 / 过程纪律'), '验证阶梯缺「环境 / 过程纪律」条(规则④的落点)');
|
|
15914
|
+
assertTrue(ladder.includes('L-096'), '验证阶梯的时间纪律条未点名 L-096 实证(规则③的依据)');
|
|
15915
|
+
} else {
|
|
15916
|
+
console.log('SKIP: 302 的验证阶梯面(docs/internal/WORKING-METHOD.md 一·五「环境 / 过程纪律」条)'
|
|
15917
|
+
+ '——维护者面结构性缺席;本次检出未校验规则 ①~④ 已写入验证阶梯,请在维护者主树重跑本套件');
|
|
15918
|
+
}
|
|
15919
|
+
|
|
15920
|
+
// 点名实体真实在场:time-utils.mjs(规则①②的单一权威)在场,且真实定义被点名的判据符号。
|
|
15921
|
+
const timeUtilsFile = path.join(__dirname, 'time-utils.mjs');
|
|
15922
|
+
assertTrue(fs.existsSync(timeUtilsFile), '入口 SKILL 的时间纪律点名 time-utils.mjs,但树内无此文件(锚指向幽灵实体)');
|
|
15923
|
+
for (const symbol of ['formatLocalTimestamp', 'parseTimestamp']) {
|
|
15924
|
+
assertTrue(engineDefinitionHits(symbol).some((hit) => hit.file === 'time-utils.mjs'),
|
|
15925
|
+
'time-utils.mjs 未定义被点名的判据符号 ' + symbol + '(散文与实现脱节)');
|
|
15926
|
+
}
|
|
15927
|
+
},
|
|
15928
|
+
},
|
|
15929
|
+
|
|
15930
|
+
// 303: 收尾打磨之首——`evolve` 在 **CRLF 文档**上追加「## evolve 元数据」段前不得留裸 LF 行。
|
|
15931
|
+
// 复现形态(评审实测 `-->\r\n\n\r\n---`):`split('\n')` 对「以换行收尾的文档」留有一个零长度
|
|
15932
|
+
// 哨兵元素,旧实现直接在哨兵之后 push,于是拼出一条**无 `\r` 的空行**(同一文件两种行尾)。
|
|
15933
|
+
// 断言面:整篇每条行都以 CRLF 终结(逐行行号可读)+ 追加块前后形态逐字 + LF 文档对照
|
|
15934
|
+
// (证明修复不是「CRLF 专属补丁」——两种行尾约定下追加块都退化为**单空行**)。
|
|
15935
|
+
{
|
|
15936
|
+
name: '303 侧命令 CRLF 追加块:evolve 追加元数据段零裸 LF 行 · 两种行尾约定形态一致',
|
|
15937
|
+
run: (dir) => {
|
|
15938
|
+
writeFile(dir, '.specs/archive/2026-10-02-crlf/DESIGN.md',
|
|
15939
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- CRLF 夹具条目\n');
|
|
15940
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15941
|
+
writeState(dir, baseState('open'));
|
|
15942
|
+
|
|
15943
|
+
// ① CRLF 文档:夹具本身必须整篇 CRLF(否则「裸 LF」判据的前提不成立)
|
|
15944
|
+
const crlfFixture = contextFixtureText({ tail: '<!-- crlf-tail -->' }).replace(/\n/g, '\r\n');
|
|
15945
|
+
assertEqual(crlfLineViolations(crlfFixture).length, 0, '夹具前提不成立:CRLF 夹具本身含非 CRLF 行');
|
|
15946
|
+
writeFile(dir, '.specs/CONTEXT.md', crlfFixture);
|
|
15947
|
+
|
|
15948
|
+
const applied = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-crlf#1', '--root', dir], dir);
|
|
15949
|
+
assertExit(applied, 0);
|
|
15950
|
+
assertOut(applied, 'EVOLVE-OK');
|
|
15951
|
+
const crlfText = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
15952
|
+
const violations = crlfLineViolations(crlfText);
|
|
15953
|
+
assertEqual(violations.join(','), '',
|
|
15954
|
+
'CRLF 文档追加后出现非 CRLF 行(行号): ' + violations.join(','));
|
|
15955
|
+
assertTrue(crlfText.includes('<!-- crlf-tail -->\r\n\r\n---\r\n\r\n## evolve 元数据\r\n\r\n'),
|
|
15956
|
+
'追加块前后形态不符(期望单空行 + 全 CRLF): '
|
|
15957
|
+
+ JSON.stringify(crlfText.slice(crlfText.indexOf('<!-- crlf-tail -->'))));
|
|
15958
|
+
// 判别力(合成变异驱动同一判据):把评审实测的修复前形态灌回真实文本 → 必报
|
|
15959
|
+
const regressed = crlfText.replace('\r\n\r\n---\r\n', '\r\n\n\r\n---\r\n');
|
|
15960
|
+
assertTrue(regressed !== crlfText, '反向构造前提不成立(追加块形态已变)');
|
|
15961
|
+
assertTrue(crlfLineViolations(regressed).length > 0, '裸 LF 行未被判违规(判别力缺失)');
|
|
15962
|
+
|
|
15963
|
+
// ② LF 文档对照:行尾约定不变(单空行 + 全 LF),且不得被写入 CR
|
|
15964
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText({ tail: '<!-- lf-tail -->' }));
|
|
15965
|
+
writeState(dir, baseState('open'));
|
|
15966
|
+
const appliedLf = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-crlf#1', '--root', dir], dir);
|
|
15967
|
+
assertExit(appliedLf, 0);
|
|
15968
|
+
const lfText = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
15969
|
+
assertTrue(lfText.includes('<!-- lf-tail -->\n\n---\n\n## evolve 元数据\n\n'),
|
|
15970
|
+
'LF 文档追加块形态回归: ' + JSON.stringify(lfText.slice(lfText.indexOf('<!-- lf-tail -->'))));
|
|
15971
|
+
assertTrue(!lfText.includes('\r'), 'LF 文档被写入 CR(行尾约定不得被改写)');
|
|
15972
|
+
},
|
|
15973
|
+
},
|
|
15974
|
+
|
|
15975
|
+
// 304: 收尾打磨之二——EVOLVE 报告的「## 应用 patch」条目此前是 ` - ` 前缀与条目自带的 `- `
|
|
15976
|
+
// 叠加(` - - <条目>`):Markdown 渲染成「空壳父项 + 子项」两条,报告读者数不清应用了几条。
|
|
15977
|
+
// 断言面:报告零 `- -` 双符号行 + 条目行逐字(单符号)+ 父项在场(子项挂在正确的父项下)。
|
|
15978
|
+
{
|
|
15979
|
+
name: '304 EVOLVE 报告条目单一列表符号:零 `- -` 双符号行 · 条目行逐字',
|
|
15980
|
+
run: (dir) => {
|
|
15981
|
+
writeFile(dir, '.specs/archive/2026-10-02-report/DESIGN.md',
|
|
15982
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 报告条目夹具\n');
|
|
15983
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
15984
|
+
writeState(dir, baseState('open'));
|
|
15985
|
+
const applied = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-report#1', '--root', dir], dir);
|
|
15986
|
+
assertExit(applied, 0);
|
|
15987
|
+
assertOut(applied, 'EVOLVE-OK');
|
|
15988
|
+
|
|
15989
|
+
const date = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
15990
|
+
const reportFile = path.join(dir, '.specs', 'evolve', date + '-EVOLVE.md');
|
|
15991
|
+
assertTrue(fs.existsSync(reportFile), 'EVOLVE 报告未落盘: ' + reportFile);
|
|
15992
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
15993
|
+
const bulletProblems = evolveReportBulletProblems(reportText);
|
|
15994
|
+
assertEqual(bulletProblems.length, 0, 'EVOLVE 报告列表符号: ' + bulletProblems.join(' | '));
|
|
15995
|
+
assertTrue(reportText.includes('- [2026-10-02-report#1] → `.specs/CONTEXT.md`「既有抽象索引」'),
|
|
15996
|
+
'报告缺应用项的父条目行: ' + JSON.stringify(reportText.slice(reportText.indexOf('## 应用 patch'))));
|
|
15997
|
+
assertTrue(reportText.includes(' - 报告条目夹具 · 来源 @.specs/archive/2026-10-02-report/DESIGN.md'),
|
|
15998
|
+
'报告条目行不是单一列表符号: ' + JSON.stringify(reportText.slice(reportText.indexOf('## 应用 patch'))));
|
|
15999
|
+
// 判别力(合成变异驱动同一判据):把双符号灌回真实报告 → 必报
|
|
16000
|
+
const regressed = reportText.replace(' - 报告条目夹具', ' - - 报告条目夹具');
|
|
16001
|
+
assertTrue(regressed !== reportText, '反向构造前提不成立(报告缺条目行)');
|
|
16002
|
+
assertTrue(evolveReportBulletProblems(regressed).length > 0, '双列表符号未被判违规(判别力缺失)');
|
|
16003
|
+
},
|
|
16004
|
+
},
|
|
16005
|
+
|
|
16006
|
+
// 305: 收尾打磨之三——`health` 的「技术债表项数」复现命令此前硬编码 H3(`/^### 技术债/`),
|
|
16007
|
+
// 而同一项的判据把段标题层级放宽到二~四级:`## 技术债` 的项目照抄命令复现不出报告读数
|
|
16008
|
+
// (读数说 0,其实段在场有表项)——命令与判据各说一套。
|
|
16009
|
+
// 同一条判据的残留边界(同批收口):段边界此前按「任意 H1~H4 标题」截断,段内**子标题**之后的
|
|
16010
|
+
// 表格整段丢失(`## 技术债` + `### 明细` 与 `### 技术债` + `#### 明细` 都读成 0 表项)——层级
|
|
16011
|
+
// 必须与段标题自身比较。断言面 = 标题层级 × 有无子标题的**六格矩阵**(H4 + 更深子标题是控制格:
|
|
16012
|
+
// 更深子标题本就不该截断),复现命令的段终点同步改为「同级或更高级标题,或分隔线」而与判据同源。
|
|
16013
|
+
{
|
|
16014
|
+
name: '305 health 技术债段级与段边界按判据动态取:H2/H3/H4 × 子标题六格矩阵 · 段缺席退回区间',
|
|
16015
|
+
run: (dir) => {
|
|
16016
|
+
const withDebt = (heading, sub) => contextFixtureText()
|
|
16017
|
+
+ '\n' + heading + '(夹具技术债)\n\n' + (sub === '' ? '' : sub + '\n\n')
|
|
16018
|
+
+ '| 项 | 说明 |\n|---|---|\n| 债 A | 说明 A |\n| 债 B | 说明 B |\n';
|
|
16019
|
+
// 复现命令的段级与段终点都取自判据本身(段级 = 文档里真实命中的标题层级;终点 = 同级或更
|
|
16020
|
+
// 高级标题,或分隔线)——命令与读数才是同一件事的两种说法。
|
|
16021
|
+
const reproLine = (bound) => "- 复现命令:`awk 'f&&(/^#{1," + bound
|
|
16022
|
+
+ "}[[:space:]]/||/^-{3,}[[:space:]]*$/){exit} /^#{2,4}[[:space:]]*技术债/{f=1} f' .specs/CONTEXT.md"
|
|
16023
|
+
+ " | grep -c '^|'`(含表头与分隔行,减去 2 即表项数)";
|
|
16024
|
+
|
|
16025
|
+
for (const [label, heading, sub, bound] of [
|
|
16026
|
+
['H2', '## 技术债', '', '2'],
|
|
16027
|
+
['H2-sub', '## 技术债', '### 明细', '2'],
|
|
16028
|
+
['H3', '### 技术债', '', '3'],
|
|
16029
|
+
['H3-sub', '### 技术债', '#### 明细', '3'],
|
|
16030
|
+
['H4', '#### 技术债', '', '4'],
|
|
16031
|
+
['H4-sub', '#### 技术债', '##### 明细', '4'],
|
|
16032
|
+
]) {
|
|
16033
|
+
const root = path.join(dir, label.toLowerCase());
|
|
16034
|
+
writeFile(root, '.specs/CONTEXT.md', withDebt(heading, sub));
|
|
16035
|
+
writeFile(root, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
16036
|
+
const res = runSideScript(SIDE_HEALTH, ['--root', root, '--stdout'], dir);
|
|
16037
|
+
assertExit(res, 0);
|
|
16038
|
+
assertOut(res, '- 表项数:2');
|
|
16039
|
+
assertOut(res, reproLine(bound));
|
|
16040
|
+
if (bound !== '3') assertNotOut(res, reproLine('3'));
|
|
16041
|
+
}
|
|
16042
|
+
// 命令形态已换(段终点须能表达「同级或更高级」)——旧的 `/^---/` 单终点形态不得再出现
|
|
16043
|
+
const h2 = runSideScript(SIDE_HEALTH, ['--root', path.join(dir, 'h2'), '--stdout'], dir);
|
|
16044
|
+
assertNotOut(h2, "- 复现命令:`sed -n ");
|
|
16045
|
+
|
|
16046
|
+
// 段缺席:没有可取的层级 → 退回判据的层级区间(二~四级)形态;读数仍为 0(复现命令成立)
|
|
16047
|
+
const absentRoot = path.join(dir, 'absent');
|
|
16048
|
+
writeFile(absentRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
16049
|
+
writeFile(absentRoot, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
16050
|
+
const absent = runSideScript(SIDE_HEALTH, ['--root', absentRoot, '--stdout'], dir);
|
|
16051
|
+
assertExit(absent, 0);
|
|
16052
|
+
assertOut(absent, '- 表项数:0');
|
|
16053
|
+
assertOut(absent, reproLine('4'));
|
|
16054
|
+
},
|
|
16055
|
+
},
|
|
16056
|
+
|
|
16057
|
+
// 306: 验收条款子句的机检锚——「确定性层**每项**都带可复现命令」。此前该子句只由「state 字节
|
|
16058
|
+
// 零改写」间接代表(评审记为锚偏弱):报告里说「逐项带计数与判据」,但「每项都有复现命令」
|
|
16059
|
+
// 无人核。断言面:确定性层逐项都有 `- 复现命令:` 行(非仓库态与真实 git 仓库态两态)+ 逐项
|
|
16060
|
+
// 抽掉该项的复现命令 → 每抽一次必报(判据不是只看第一项)。
|
|
16061
|
+
{
|
|
16062
|
+
name: '306 health 确定性层每项带复现命令:逐项机检 + 逐项抽掉必报 + git 两态覆盖',
|
|
16063
|
+
run: (dir) => {
|
|
16064
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
16065
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
16066
|
+
const plain = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
16067
|
+
assertExit(plain, 0);
|
|
16068
|
+
assertOut(plain, '### 5 · 版本历史统计(git)');
|
|
16069
|
+
const plainProblems = deterministicReproProblems(plain.output);
|
|
16070
|
+
assertEqual(plainProblems.length, 0, '确定性层缺复现命令: ' + plainProblems.join(' | '));
|
|
16071
|
+
|
|
16072
|
+
// 逐项判别力(合成变异驱动同一判据):确定性子集逐项各抽掉一次复现命令 → 每次都必报
|
|
16073
|
+
const rows = plain.output.split('\n');
|
|
16074
|
+
const starts = rows.map((line, i) => (line.startsWith('### ') ? i : -1)).filter((i) => i >= 0);
|
|
16075
|
+
assertTrue(starts.length >= 5, '确定性层分项数不足(判据无从覆盖): ' + starts.length);
|
|
16076
|
+
for (const start of starts) {
|
|
16077
|
+
const nextStart = rows.findIndex((line, i) => i > start && line.startsWith('### '));
|
|
16078
|
+
const stop = nextStart < 0 ? rows.length : nextStart;
|
|
16079
|
+
const at = rows.findIndex((line, i) => i > start && i < stop && line.startsWith('- 复现命令:'));
|
|
16080
|
+
assertTrue(at >= 0, '确定性项缺复现命令: ' + rows[start]);
|
|
16081
|
+
const mutated = [...rows.slice(0, at), ...rows.slice(at + 1)].join('\n');
|
|
16082
|
+
assertTrue(deterministicReproProblems(mutated).length > 0,
|
|
16083
|
+
'抽掉该项复现命令未被判违规(判别力缺失): ' + rows[start]);
|
|
16084
|
+
}
|
|
16085
|
+
|
|
16086
|
+
// git 在场态:另起一个真实仓库根(`git init`)→ 第 5 项走「是」分支,同样带复现命令
|
|
16087
|
+
const repoRoot = path.join(dir, 'repo-root');
|
|
16088
|
+
writeFile(repoRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
16089
|
+
writeFile(repoRoot, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
16090
|
+
execFileSync('git', ['init', '-q'], { cwd: repoRoot, stdio: 'ignore' });
|
|
16091
|
+
const inRepo = runSideScript(SIDE_HEALTH, ['--root', repoRoot, '--stdout'], dir);
|
|
16092
|
+
assertExit(inRepo, 0);
|
|
16093
|
+
assertOut(inRepo, '- git 仓库:是');
|
|
16094
|
+
const repoProblems = deterministicReproProblems(inRepo.output);
|
|
16095
|
+
assertEqual(repoProblems.length, 0, 'git 在场态确定性层缺复现命令: ' + repoProblems.join(' | '));
|
|
16096
|
+
},
|
|
16097
|
+
},
|
|
16098
|
+
|
|
16099
|
+
// 307: 覆盖声明四要素机检锚(评审登记的移交项)——三处「上游 vendored 只读」覆盖声明此前是
|
|
16100
|
+
// **纯文本、无机检**。四要素:① 上游文件标记为只读基准(且点名的上游文件真实在场);
|
|
16101
|
+
// ② 「不采用」栏 ≥1 条;③ 「沿用上游」栏 ≥1 条(入口为**指针式** → 该栏豁免,细则在各自技能册);
|
|
16102
|
+
// ④ 「以…为准」兜底语。负向控制:把任一要素从**真实文本**里抽掉 → 必红。
|
|
16103
|
+
{
|
|
16104
|
+
name: '307 上游覆盖声明四要素:三处声明齐备 + 点名上游实体在场 + 逐要素抽掉必红',
|
|
16105
|
+
run: () => {
|
|
16106
|
+
const skillsRoot = skillsRootForScriptsDir(__dirname);
|
|
16107
|
+
const declarations = [
|
|
16108
|
+
{ label: 'flow-comet-health/SKILL.md', file: path.join(skillsRoot, 'flow-comet-health', 'SKILL.md'), pointer: false },
|
|
16109
|
+
{ label: 'flow-comet-evolve/SKILL.md', file: path.join(skillsRoot, 'flow-comet-evolve', 'SKILL.md'), pointer: false },
|
|
16110
|
+
{ label: 'flow-comet/SKILL.md', file: path.join(skillsRoot, 'flow-comet', 'SKILL.md'), pointer: true },
|
|
16111
|
+
];
|
|
16112
|
+
for (const declaration of declarations) {
|
|
16113
|
+
const text = fs.readFileSync(declaration.file, 'utf8');
|
|
16114
|
+
const problems = overrideDeclarationProblems(declaration.label, text, { pointer: declaration.pointer });
|
|
16115
|
+
assertEqual(problems.length, 0, '覆盖声明四要素: ' + problems.join(' | '));
|
|
16116
|
+
|
|
16117
|
+
// 逐要素抽掉(真实文本驱动同一判据):该要素必报——判据不恒真空过。
|
|
16118
|
+
// 兜底语取**声明块内**的匹配(文件里别处的 `冲突…以文件为准` 一类行文不是该要素,
|
|
16119
|
+
// 抽错目标会让判别力断言变成假绿)。
|
|
16120
|
+
const probes = [
|
|
16121
|
+
{ element: '只读基准', strip: (value) => value.replaceAll('只读基准', '(反向构造:抽掉)') },
|
|
16122
|
+
{ element: '不采用栏', strip: (value) => value.replaceAll('不采用', '(反向构造:抽掉)') },
|
|
16123
|
+
{
|
|
16124
|
+
element: '兜底语',
|
|
16125
|
+
strip: (value) => {
|
|
16126
|
+
const blockFallback = OVERRIDE_FALLBACK_RE.exec(overrideDeclarationBlock(value));
|
|
16127
|
+
return value.replace(blockFallback[0], '(反向构造:抽掉)');
|
|
16128
|
+
},
|
|
16129
|
+
},
|
|
16130
|
+
];
|
|
16131
|
+
if (!declaration.pointer) {
|
|
16132
|
+
probes.push({ element: '沿用上游栏', strip: (value) => value.replaceAll('沿用上游', '(反向构造:抽掉)') });
|
|
16133
|
+
}
|
|
16134
|
+
for (const probe of probes) {
|
|
16135
|
+
const stripped = probe.strip(text);
|
|
16136
|
+
assertTrue(stripped !== text, '反向构造前提不成立(文本缺该要素): ' + declaration.label + ' / ' + probe.element);
|
|
16137
|
+
assertTrue(overrideDeclarationProblems(declaration.label, stripped, { pointer: declaration.pointer })
|
|
16138
|
+
.some((problem) => problem.includes(probe.element.replace(/栏$/, '')) || problem.includes('兜底语')),
|
|
16139
|
+
'抽掉要素未被判违规(判别力缺失): ' + declaration.label + ' / ' + probe.element);
|
|
16140
|
+
}
|
|
16141
|
+
}
|
|
16142
|
+
|
|
16143
|
+
// 点名的上游实体真实在场:vendored 上游面结构性缺席时输出可见 SKIP(未验证 ≠ 通过)。
|
|
16144
|
+
// 取「声明块内」点名的路径——文件别处的说明性写法(`flow-kit/prompts/<阶段>.md` 占位)
|
|
16145
|
+
// 不是本声明的落点。
|
|
16146
|
+
const promptsRoot = path.join(REPO_ROOT, 'flow-kit', 'prompts');
|
|
16147
|
+
if (fs.existsSync(promptsRoot)) {
|
|
16148
|
+
for (const declaration of declarations) {
|
|
16149
|
+
const block = overrideDeclarationBlock(fs.readFileSync(declaration.file, 'utf8'));
|
|
16150
|
+
const paths = upstreamArtifactPaths(block);
|
|
16151
|
+
assertTrue(paths.length > 0, declaration.label + ' 未点名任何上游工件(声明的锚缺落点)');
|
|
16152
|
+
for (const rel of paths) {
|
|
16153
|
+
assertTrue(fs.existsSync(path.join(REPO_ROOT, rel)),
|
|
16154
|
+
declaration.label + ' 点名的上游文件不存在(锚指向幽灵实体): ' + rel);
|
|
16155
|
+
}
|
|
16156
|
+
}
|
|
16157
|
+
} else {
|
|
16158
|
+
console.log('SKIP: 307 的上游实体面(flow-kit/prompts 为 vendored 上游面,可能结构性缺席)'
|
|
16159
|
+
+ '——本次检出未校验「覆盖声明点名的上游文件真实在场」,请在 vendored 上游在场处重跑本套件');
|
|
16160
|
+
}
|
|
16161
|
+
},
|
|
16162
|
+
},
|
|
16163
|
+
|
|
16164
|
+
// 308: `last_intel_scan` 双落点一致(原症状顺序 · 真实链路)——先 `context-scan` 建双落点,真实时间
|
|
16165
|
+
// 流逝后再跑 `init --init-context`:state 侧取值必须以**统一形态**(本地时间 + 显式偏移,经
|
|
16166
|
+
// time-utils)写入;段侧不由 init 改写(段行的唯一写通道是 context-scan,其改写与备份实现只有
|
|
16167
|
+
// 一份);两者取值不一致时**必须有可见提示**并点名收敛命令——修复前是「写 `Z` 形态 + 段未更新 +
|
|
16168
|
+
// 零提示」的静默漂移。反向控制:两处取值一致时零提示(不误报),且未刷新路径不改写既有取值。
|
|
16169
|
+
// 段行夹具 = **真实生成件形态**(取值词元 + 行尾说明,见 INTEL_FIELD_SUFFIX):读侧若按整行剩余
|
|
16170
|
+
// 文本比对,则同刻同形态(②)与收敛后(⑥)都会恒亮、漂移类别退化成「段内取值不是合法时间戳」
|
|
16171
|
+
// (④)——三条都是本场景的判据;⑦ 单变量对照(只剥掉说明)证明判别条件是词元口径而非说明本身。
|
|
16172
|
+
{
|
|
16173
|
+
name: '308 双落点一致:带行尾说明的段行同刻静默 + 漂移类别正确 + 重扫收敛后零提示 + 单变量对照',
|
|
16174
|
+
run: (dir) => {
|
|
16175
|
+
const parse = requireModuleExport(timeUtilsModule, 'parseTimestamp', 'time-utils.mjs');
|
|
16176
|
+
const extract = requireModuleExport(contextInitModule, 'extractContextStructure', 'context-init.mjs');
|
|
16177
|
+
const readContext = () => fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
16178
|
+
const readLandedState = () => JSON.parse(
|
|
16179
|
+
fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8')).last_intel_scan;
|
|
16180
|
+
// 段侧取值的读取口径与生产侧同源:结构提取定位字段 → 取**取值词元**(写侧只换词元,说明原样保留)
|
|
16181
|
+
const readLandedSection = () => {
|
|
16182
|
+
const field = extract(readContext()).metadata['intel-scan 元数据'];
|
|
16183
|
+
return field === undefined ? undefined : intelFieldToken(field.last_intel_scan.value);
|
|
16184
|
+
};
|
|
16185
|
+
|
|
16186
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
16187
|
+
writeState(dir, baseState('open'));
|
|
16188
|
+
|
|
16189
|
+
// ① 首扫:双落点建立且同刻同形态;段行的行尾说明原样保留(写侧只替换取值词元)
|
|
16190
|
+
const scan = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
16191
|
+
assertExit(scan, 0);
|
|
16192
|
+
assertOut(scan, 'CONTEXT-SCAN-DONE');
|
|
16193
|
+
const scanned = readLandedState();
|
|
16194
|
+
assertEqual(readLandedSection(), scanned, '首扫后双落点应同刻同形态');
|
|
16195
|
+
assertTrue(readContext().includes(INTEL_FIELD_SUFFIX), '重扫改写了段行的行尾说明(写侧只应替换取值词元)');
|
|
16196
|
+
|
|
16197
|
+
// ② 带行尾说明的同刻同形态 ⇒ **静默**(未刷新路径的 init 不改写既有取值)——整行口径的读侧在此恒亮
|
|
16198
|
+
const quietLanded = runStateWithProtocol(dir, ['init', CHANGE_ID]);
|
|
16199
|
+
assertExit(quietLanded, 0);
|
|
16200
|
+
assertEqual(readLandedState(), scanned, '未刷新路径应原样保留既有扫描时刻');
|
|
16201
|
+
assertNotOut(quietLanded, 'INIT-NOTICE');
|
|
16202
|
+
|
|
16203
|
+
// ③ 真实时间流逝——时间戳是秒级精度,同一秒内的两次写入取值可能相同(漂移不可判)
|
|
16204
|
+
sleepSync(1100);
|
|
16205
|
+
|
|
16206
|
+
// ④ 原症状顺序:`init --init-context`(CONTEXT 校验通过路径 → 记录扫描时刻)
|
|
16207
|
+
const reinit = runStateWithProtocol(dir, ['init', CHANGE_ID, '--init-context']);
|
|
16208
|
+
assertExit(reinit, 0);
|
|
16209
|
+
assertOut(reinit, 'INIT-DONE');
|
|
16210
|
+
const stateAfter = readLandedState();
|
|
16211
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(stateAfter),
|
|
16212
|
+
'init 写入的扫描时刻形态非「本地时间 + 显式偏移」: ' + stateAfter);
|
|
16213
|
+
assertTrue(parse(stateAfter) > parse(scanned),
|
|
16214
|
+
'init 写入的扫描时刻应晚于首扫(不得回退): ' + stateAfter + ' vs ' + scanned);
|
|
16215
|
+
assertEqual(readLandedSection(), scanned, 'init 不应改写 CONTEXT 段(该段行的写通道是 context-scan)');
|
|
16216
|
+
// 漂移不得静默:提示在场 + 两侧取值回显 + 点名收敛命令 + **类别正确**(两侧同为「本地时间 +
|
|
16217
|
+
// 显式偏移」形态、仅时刻不同 ⇒ 「刻与形态均不一致」;行尾说明不得把类别打成取值非法)
|
|
16218
|
+
assertOut(reinit, 'INIT-NOTICE');
|
|
16219
|
+
assertOut(reinit, stateAfter);
|
|
16220
|
+
assertOut(reinit, scanned);
|
|
16221
|
+
assertOut(reinit, '刻与形态均不一致');
|
|
16222
|
+
assertNotOut(reinit, '段内取值不是合法时间戳');
|
|
16223
|
+
assertOut(reinit, 'context-scan');
|
|
16224
|
+
|
|
16225
|
+
// ⑤ 收敛:重扫一次 → 双落点同刻同形态(行尾说明原样保留)
|
|
16226
|
+
const converge = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
16227
|
+
assertExit(converge, 0);
|
|
16228
|
+
assertOut(converge, 'CONTEXT-SCAN-DONE');
|
|
16229
|
+
const converged = readLandedState();
|
|
16230
|
+
assertEqual(readLandedSection(), converged, '重扫后双落点应收敛为同刻同形态');
|
|
16231
|
+
assertTrue(readContext().includes(INTEL_FIELD_SUFFIX), '收敛轮改写了段行的行尾说明');
|
|
16232
|
+
|
|
16233
|
+
// ⑥ 收敛后:取值一致时的 init(未授权刷新 → 原样保留既有扫描时刻)零提示——提示承诺的收敛可达
|
|
16234
|
+
const quiet = runStateWithProtocol(dir, ['init', CHANGE_ID]);
|
|
16235
|
+
assertExit(quiet, 0);
|
|
16236
|
+
assertEqual(readLandedState(), converged, '未刷新路径应原样保留既有扫描时刻');
|
|
16237
|
+
assertNotOut(quiet, 'INIT-NOTICE');
|
|
16238
|
+
|
|
16239
|
+
// ⑦ 单变量对照:**只**剥掉段行的行尾说明(取值词元不变、state 不变)→ 仍然静默——判别条件是
|
|
16240
|
+
// 「取值词元」口径而非「有没有说明」;裸取值行(无说明)是写侧支持的既有形态,须继续正确
|
|
16241
|
+
const bareLine = readContext().replace(INTEL_FIELD_SUFFIX, '');
|
|
16242
|
+
assertTrue(bareLine !== readContext(), '单变量对照前提不成立:段行不含夹具行尾说明');
|
|
16243
|
+
writeFile(dir, '.specs/CONTEXT.md', bareLine);
|
|
16244
|
+
const quietBare = runStateWithProtocol(dir, ['init', CHANGE_ID]);
|
|
16245
|
+
assertExit(quietBare, 0);
|
|
16246
|
+
assertNotOut(quietBare, 'INIT-NOTICE');
|
|
16247
|
+
|
|
16248
|
+
// ⑧ 向后兼容:取值词元带 markdown 引号(`` `…` ``;模板/旧夹具形态)时按词元归一后比对 → 静默
|
|
16249
|
+
writeFile(dir, '.specs/CONTEXT.md',
|
|
16250
|
+
contextFixtureText().replace(INTEL_FIELD_VALUE + INTEL_FIELD_SUFFIX,
|
|
16251
|
+
'`' + converged + '`' + INTEL_FIELD_SUFFIX));
|
|
16252
|
+
const quietQuoted = runStateWithProtocol(dir, ['init', CHANGE_ID]);
|
|
16253
|
+
assertExit(quietQuoted, 0);
|
|
16254
|
+
assertNotOut(quietQuoted, 'INIT-NOTICE');
|
|
16255
|
+
},
|
|
16256
|
+
},
|
|
16257
|
+
|
|
16258
|
+
// 309: 漂移判据的形态边界与反向控制(判别力 + 零误报)——① **同一时刻的两种形态**(state 为历史
|
|
16259
|
+
// `Z` 值、段侧为本地偏移)也判漂移:提示在场且点名形态差异(修复前该形态零提示、state 被原样保留);
|
|
16260
|
+
// ② 段缺席 = 无可比对面 → 零提示(不无中生有);③ 段内取值不可解析(占位)→ 仍判漂移(不静默);
|
|
16261
|
+
// 提示一律不阻断 init(exit 0);④ 判据输入端的两条命名声明(段名 / 字段名)跨文件逐字一致——
|
|
16262
|
+
// 段行夹具一律**带行尾说明**(真实生成件形态):整行口径的读侧会让 ① 退化成「取值非法」、③ 的
|
|
16263
|
+
// 类别也由说明决定——故 ① 显式断言「同刻不同形态」且不得落到取值非法类别。
|
|
16264
|
+
// 两处各写一份字面量是本机制的既有形态(单一来源收口须改到写边界外的脚本,见 SUMMARY 的已知接受),
|
|
16265
|
+
// 故此处把「不得静默漂移」机检化:任一侧改名即红,而漂移的后果正是 ② 的静默路径。
|
|
16266
|
+
{
|
|
16267
|
+
name: '309 漂移判据边界:同刻不同形态必报 + 段缺席零误报 + 段内占位取值不静默 + 命名声明跨文件一致',
|
|
16268
|
+
run: (dir) => {
|
|
16269
|
+
const readContext = () => fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
16270
|
+
const readLandedState = () => JSON.parse(
|
|
16271
|
+
fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8')).last_intel_scan;
|
|
16272
|
+
|
|
16273
|
+
// ① state = `Z` 形态(历史写入的真实形态);段 = 同一时刻的「本地时间 + 显式偏移」,**带行尾说明**
|
|
16274
|
+
// (真实生成件形态)——两侧同刻 ⇒ 类别必须是「同刻不同形态」,不得退化成取值非法
|
|
16275
|
+
const zForm = '2026-09-24T18:14:23Z';
|
|
16276
|
+
const localForm = '2026-09-25T02:14:23+08:00';
|
|
16277
|
+
writeState(dir, { ...baseState('open'), last_intel_scan: zForm });
|
|
16278
|
+
writeFile(dir, '.specs/CONTEXT.md',
|
|
16279
|
+
contextFixtureText().replace(INTEL_FIELD_VALUE, localForm));
|
|
16280
|
+
const sameMoment = runStateWithProtocol(dir, ['init', CHANGE_ID]);
|
|
16281
|
+
assertExit(sameMoment, 0);
|
|
16282
|
+
assertOut(sameMoment, 'INIT-NOTICE');
|
|
16283
|
+
assertOut(sameMoment, '同刻不同形态');
|
|
16284
|
+
assertNotOut(sameMoment, '段内取值不是合法时间戳');
|
|
16285
|
+
assertOut(sameMoment, zForm);
|
|
16286
|
+
assertOut(sameMoment, localForm);
|
|
16287
|
+
assertEqual(readLandedState(), zForm, '未刷新路径不得改写既有扫描时刻');
|
|
16288
|
+
|
|
16289
|
+
// ② 段缺席(CONTEXT 不含 intel-scan 段)→ 无可比对面 → 零提示
|
|
16290
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText({ intelSection: false }));
|
|
16291
|
+
const noSection = runStateWithProtocol(dir, ['init', CHANGE_ID + '-no-section']);
|
|
16292
|
+
assertExit(noSection, 0);
|
|
16293
|
+
assertNotOut(noSection, 'INIT-NOTICE');
|
|
16294
|
+
|
|
16295
|
+
// ③ 段内取值词元不可解析(占位形态)→ 仍判漂移且点明该类别(静默放过会让「段侧从未被正确
|
|
16296
|
+
// 写入」长期不可见);占位词元之后的说明不参与判定(类别由词元决定)
|
|
16297
|
+
writeFile(dir, '.specs/CONTEXT.md',
|
|
16298
|
+
contextFixtureText().replace(INTEL_FIELD_VALUE, '(待扫描)'));
|
|
16299
|
+
const placeholder = runStateWithProtocol(dir, ['init', CHANGE_ID + '-placeholder']);
|
|
16300
|
+
assertExit(placeholder, 0);
|
|
16301
|
+
assertOut(placeholder, 'INIT-NOTICE');
|
|
16302
|
+
assertOut(placeholder, '段内取值不是合法时间戳');
|
|
16303
|
+
assertOut(placeholder, '(待扫描)');
|
|
16304
|
+
|
|
16305
|
+
// ④ 取值词元口径的夹具前提(合成输入 · 纯函数口径):段行带行尾说明时,结构提取返回的是
|
|
16306
|
+
// 「词元 + 说明」整串——按整行比对会落「取值非法」(缺陷形态),按词元比对才落正确类别
|
|
16307
|
+
// (类别本身已在 ① 的真实命令面断言)。此处把夹具形态与词元提取钉住:夹具若退回裸词元,
|
|
16308
|
+
// 本锚立即红(防「缺陷形态重新变得不可见」的假绿)。
|
|
16309
|
+
const fieldsWithSuffix = requireModuleExport(contextInitModule, 'extractContextStructure', 'context-init.mjs')(
|
|
16310
|
+
contextFixtureText()).metadata['intel-scan 元数据'].last_intel_scan.value;
|
|
16311
|
+
assertTrue(fieldsWithSuffix.includes(INTEL_FIELD_SUFFIX),
|
|
16312
|
+
'夹具段行未带行尾说明(真实生成件形态前提不成立): ' + JSON.stringify(fieldsWithSuffix));
|
|
16313
|
+
assertTrue(intelFieldToken(fieldsWithSuffix) === INTEL_FIELD_VALUE,
|
|
16314
|
+
'取值词元口径提取错误: ' + JSON.stringify(intelFieldToken(fieldsWithSuffix)));
|
|
16315
|
+
|
|
16316
|
+
// ⑤ 命名声明跨文件一致(结构锚 + 反向构造):init 侧按段名 / 字段名定位段内取值,两处声明
|
|
16317
|
+
// 漂移会让判据静默退化成 ② 的「无可比对面」——故两处字面量必须逐字相等,合成改写即红。
|
|
16318
|
+
const consumerText = fs.readFileSync(path.join(__dirname, 'workflow-state.mjs'), 'utf8');
|
|
16319
|
+
const producerText = fs.readFileSync(SIDE_CONTEXT_SCAN, 'utf8');
|
|
16320
|
+
const namingProblems = intelMetadataNameProblems(consumerText, producerText);
|
|
16321
|
+
assertEqual(namingProblems.length, 0, 'intel-scan 命名声明漂移: ' + namingProblems.join(' | '));
|
|
16322
|
+
const tamperedSection = producerText.replace("'intel-scan 元数据'", "'intel-scan 元数据(漂移)'");
|
|
16323
|
+
assertTrue(tamperedSection !== producerText, '反向构造前提不成立:重扫命令侧缺段名字面量声明');
|
|
16324
|
+
assertTrue(intelMetadataNameProblems(consumerText, tamperedSection)
|
|
16325
|
+
.some((problem) => problem.includes('段名字面量两处声明不一致')),
|
|
16326
|
+
'段名漂移未被判定(判别力缺失)');
|
|
16327
|
+
const tamperedField = producerText.replace("'last_intel_scan'", "'last_intel_scan_v2'");
|
|
16328
|
+
assertTrue(tamperedField !== producerText, '反向构造前提不成立:重扫命令侧缺字段名字面量声明');
|
|
16329
|
+
assertTrue(intelMetadataNameProblems(consumerText, tamperedField)
|
|
16330
|
+
.some((problem) => problem.includes('字段名字面量两处声明不一致')),
|
|
16331
|
+
'字段名漂移未被判定(判别力缺失)');
|
|
16332
|
+
},
|
|
16333
|
+
},
|
|
13649
16334
|
];
|
|
13650
16335
|
// ---------- 运行 ----------
|
|
13651
16336
|
|