flow-comet 1.5.0 → 1.6.0
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/rules/flow-comet-orchestration.md +1 -2
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/SKILL.md +21 -3
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +9 -8
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +9 -2
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +4233 -94
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +24 -4
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +697 -15
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +69 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +1718 -5
- package/.flow-comet/skills/flow-comet/scripts/task-parsing.mjs +13 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +429 -276
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +330 -13
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +423 -38
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +15 -0
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +19 -1
- package/.flow-comet/skills/flow-comet-review/SKILL.md +21 -3
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +12 -3
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +19 -4
- package/README.md +7 -3
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/prepare-env.mjs +102 -54
|
@@ -25,13 +25,19 @@
|
|
|
25
25
|
// 校验绑定、hook 白名单缺省)。
|
|
26
26
|
|
|
27
27
|
import { execFileSync, spawnSync } from 'child_process';
|
|
28
|
+
import { createHash } from 'crypto';
|
|
28
29
|
import fs from 'fs';
|
|
29
30
|
import os from 'os';
|
|
30
31
|
import path from 'path';
|
|
31
32
|
import { fileURLToPath, pathToFileURL } from 'url';
|
|
33
|
+
import { isDeepStrictEqual } from 'util'; // 白名单外深比(state 字节级不变量断言,标准库零依赖)
|
|
32
34
|
import vm from 'vm'; // 系统测试集项数的运行时派生:求值其 TEST_ITEMS 数组字面量(见 readSystemTestItemCount)
|
|
33
35
|
|
|
34
36
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
37
|
+
// route-node 共享 Fix 判定纯函数(直接调用锚):动态导入 + 顶层 await——缺失命名导出由
|
|
38
|
+
// requireRouteNodeExport 在场景内显式报告(RED 可定位到具体场景),避免静态命名 import 在
|
|
39
|
+
// 模块加载期失败导致其余场景一并 abort(整套件 0 场景、失败原因失焦)。
|
|
40
|
+
const routeNodeModule = await import(pathToFileURL(path.join(__dirname, 'route-node.mjs')).href);
|
|
35
41
|
const GUARD = path.join(__dirname, 'workflow-guard.mjs');
|
|
36
42
|
const STATE = path.join(__dirname, 'workflow-state.mjs');
|
|
37
43
|
const HOOK = path.join(__dirname, 'comet-hook-guard.mjs');
|
|
@@ -54,8 +60,31 @@ const PREPARE_ENV = path.join(REPO_ROOT, 'scripts', 'prepare-env.mjs');
|
|
|
54
60
|
const BUILTIN_PROTOCOL_SOURCE = path.join(__dirname, '..', 'reference', 'workflow-protocol.json');
|
|
55
61
|
const CHANGE_ID = 'ch';
|
|
56
62
|
|
|
57
|
-
//
|
|
58
|
-
//
|
|
63
|
+
// 组件技能树布局感知(单一来源):本 suite 恒位于 <skillsRoot>/flow-comet/scripts/,
|
|
64
|
+
// 组件技能(flow-comet-execute / flow-comet-review / flow-comet-verify 等)是 <skillsRoot>
|
|
65
|
+
// 下的同级目录。权威源 checkout → <root>/.flow-comet/skills/;安装副本 → <目标>/.claude|
|
|
66
|
+
// .agents|.dsh/skills/ —— 同一相对推导覆盖全部形态。禁止再假定权威源布局
|
|
67
|
+
// (REPO_ROOT/.flow-comet/skills 在安装副本形态不存在 → 技能文本锁场景 ENOENT,级 3 e2e 缺陷)。
|
|
68
|
+
function skillsRootForScriptsDir(scriptsDir) {
|
|
69
|
+
return path.resolve(scriptsDir, '..', '..');
|
|
70
|
+
}
|
|
71
|
+
// 解析组件技能 SKILL.md:缺失即显式失败并给指引(MECHANISM 三·6「未验证 ≠ 通过」——
|
|
72
|
+
// 不得静默跳过);scriptsDir 为可测接缝(技能文本锁场景的合成布局回归锚)。
|
|
73
|
+
function resolveComponentSkillFile(nodeSkill, scriptsDir = __dirname) {
|
|
74
|
+
const skillsRoot = skillsRootForScriptsDir(scriptsDir);
|
|
75
|
+
const file = path.join(skillsRoot, nodeSkill, 'SKILL.md');
|
|
76
|
+
if (!fs.existsSync(file)) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
'技能树布局定位失败:' + nodeSkill + '/SKILL.md 不存在。suite 脚本须位于 <skillsRoot>/flow-comet/scripts/' +
|
|
79
|
+
',组件技能为其同级目录;已解析 skillsRoot=' + skillsRoot + ',期望路径=' + file +
|
|
80
|
+
'。权威源 .flow-comet/skills 与安装副本 .claude|.agents|.dsh/skills 均按此相对布局解析。'
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return file;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// 场景数一致性自检清单(20 文件 = 15 分发组 + 5 维护者组,全变体:ALL n SCENARIOS PASSED / n scenarios / n 场景 / n/n)——
|
|
87
|
+
// 场景数自检与底部自检共用同一清单/同一实现(自检常量同步:SCENARIOS.length 变更 → 20 受检文件须同步)。
|
|
59
88
|
// 分两组按"分发形态"划界(AC-14:条目缺失必须显式报告,不得静默跳过——幽灵条目无处藏身):
|
|
60
89
|
// ① 分发组:随仓库分发(受版本控制),**任何**权威源检出都必须存在——维护者工作副本、
|
|
61
90
|
// CI 全新检出、worktree 检出皆然 → 条目缺失即报错(幽灵条目在此被强制暴露)。
|
|
@@ -214,6 +243,80 @@ function countSyncProblems(root = REPO_ROOT) {
|
|
|
214
243
|
return [...scenarioCountSyncProblems(SCENARIOS.length, root), ...systemTestCountSyncProblems(root)];
|
|
215
244
|
}
|
|
216
245
|
|
|
246
|
+
// 维护文档机检(docs-governance):覆盖 CI 结构上不可见的面——docs/internal/ 与 .specs/adr/ 的
|
|
247
|
+
// ① 死引用(文档中的仓库相对路径引用必须存在);② ROADMAP 最低结构(Now / Next / Later / Open decisions)。
|
|
248
|
+
// 与计数检查同构:docs/internal 整组缺席(CI 全新检出 / worktree 检出)→ 跳过(空数组,不误红)。
|
|
249
|
+
// 判别力边界(实测教训):提取必须取「完整路径 token」而非后缀子串;scripts/… 一类简写按技能树基准解析;
|
|
250
|
+
// 占位符 / 通配 / 未来路径不参与判定(见 ALLOWLIST)。
|
|
251
|
+
const INTERNAL_DOC_REF_BASES = ['.flow-comet/skills/flow-comet', '.claude/skills/flow-comet', '', 'flow-kit'];
|
|
252
|
+
const INTERNAL_DOC_REF_ALLOWLIST = new Set(['.specs/archive/CONTEXT-history.md']);
|
|
253
|
+
const INTERNAL_DOC_REF_RE = /(?<![A-Za-z0-9_.\-\/])(\.?(?:[A-Za-z0-9_][A-Za-z0-9_.\-]*\/)+[A-Za-z0-9_.\-]+\.(?:md|mjs|cjs|js|ts|json|ya?ml|sh|patch|toml))(?![A-Za-z0-9])/gm;
|
|
254
|
+
|
|
255
|
+
function internalDocRefCandidates(text) {
|
|
256
|
+
const out = [];
|
|
257
|
+
const seen = new Set();
|
|
258
|
+
const lines = String(text).split(/\r?\n/);
|
|
259
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
260
|
+
for (const m of lines[i].matchAll(INTERNAL_DOC_REF_RE)) {
|
|
261
|
+
const token = m[1];
|
|
262
|
+
if (token.includes('*') || token.includes('<')) continue; // 通配 / 占位符
|
|
263
|
+
const key = i + 1 + ' ' + token;
|
|
264
|
+
if (seen.has(key)) continue;
|
|
265
|
+
seen.add(key);
|
|
266
|
+
out.push({ ref: token, line: i + 1 });
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return out;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function internalDocsProblems(root = REPO_ROOT) {
|
|
273
|
+
const problems = [];
|
|
274
|
+
const internalDir = path.join(root, MAINTAINER_DOC_DIR);
|
|
275
|
+
const hasInternal = fs.existsSync(internalDir);
|
|
276
|
+
const targets = [];
|
|
277
|
+
if (hasInternal) {
|
|
278
|
+
for (const name of fs.readdirSync(internalDir)) {
|
|
279
|
+
if (name.endsWith('.md')) targets.push(path.posix.join(MAINTAINER_DOC_DIR, name));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
const adrDir = path.join(root, '.specs', 'adr');
|
|
283
|
+
if (fs.existsSync(adrDir)) {
|
|
284
|
+
for (const name of fs.readdirSync(adrDir)) {
|
|
285
|
+
if (name.endsWith('.md')) targets.push(path.posix.join('.specs', 'adr', name));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
if (targets.length === 0) return problems; // 两处目标面皆缺席 → 整组跳过(CI / worktree 形态)
|
|
289
|
+
for (const rel of targets) {
|
|
290
|
+
let text;
|
|
291
|
+
try {
|
|
292
|
+
text = fs.readFileSync(path.join(root, rel), 'utf8');
|
|
293
|
+
} catch {
|
|
294
|
+
continue;
|
|
295
|
+
}
|
|
296
|
+
for (const { ref, line } of internalDocRefCandidates(text)) {
|
|
297
|
+
if (INTERNAL_DOC_REF_ALLOWLIST.has(ref)) continue;
|
|
298
|
+
if (INTERNAL_DOC_REF_BASES.some((base) => fs.existsSync(path.join(root, base, ref)))) continue;
|
|
299
|
+
const firstSegment = ref.split('/')[0];
|
|
300
|
+
if (!fs.existsSync(path.join(root, firstSegment))) continue; // 顶层整体缺席 → 跳过(组缺席语义)
|
|
301
|
+
problems.push('死引用: ' + rel + ':' + line + ' → ' + ref);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
const roadmapRel = path.posix.join(MAINTAINER_DOC_DIR, 'ROADMAP.md');
|
|
305
|
+
if (!fs.existsSync(path.join(root, roadmapRel))) {
|
|
306
|
+
problems.push('ROADMAP 缺失: ' + roadmapRel);
|
|
307
|
+
} else {
|
|
308
|
+
const text = fs.readFileSync(path.join(root, roadmapRel), 'utf8');
|
|
309
|
+
for (const section of ['Now', 'Next', 'Later', 'Open decisions']) {
|
|
310
|
+
const sectionRe = new RegExp('^##\\s*' + section + '\\s*(?:[((][^))\\n]*[))])?\\s*$', 'm');
|
|
311
|
+
if (!sectionRe.test(text)) {
|
|
312
|
+
problems.push('ROADMAP 结构缺段: ' + section + '(' + roadmapRel + ')');
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return problems;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
|
|
217
320
|
function makeTmp() {
|
|
218
321
|
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'flow-comet-guard-test-'));
|
|
219
322
|
createdDirs.push(dir);
|
|
@@ -314,6 +417,35 @@ function runBridgeCheck(root, dshHome) {
|
|
|
314
417
|
});
|
|
315
418
|
}
|
|
316
419
|
|
|
420
|
+
// 桥接夹具 loader 写入(单一来源——bridge-check 夹具与安装副本形态夹具共用;两处各自
|
|
421
|
+
// 拼装锚点行会随契约格式演进分叉)。返回 loader 绝对路径。
|
|
422
|
+
function writeBridgeLoaderFixture(dshHome, loaderStamp) {
|
|
423
|
+
const loaderPath = path.join(dshHome, 'plugins', 'dsh-flow-comet-bridge.mjs');
|
|
424
|
+
writeFile(dshHome, 'plugins/dsh-flow-comet-bridge.mjs',
|
|
425
|
+
'// dsh bridge loader fixture\n// BRIDGE_VERSION: ' + loaderStamp + '\n' +
|
|
426
|
+
"export const name = 'dsh-flow-comet-bridge';\nexport const version = '" + loaderStamp + "';\n");
|
|
427
|
+
return loaderPath;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// cordis.patch.yml 托管块(insert 形态 + file:// 引用)逐字构造(单一来源,同上)。
|
|
431
|
+
function managedCordisBlockFor(loaderPath) {
|
|
432
|
+
const fileUrl = pathToFileURL(loaderPath).href;
|
|
433
|
+
return '# --- flow-comet managed ---\n- insert:\n - id: dsh-flow-comet-bridge\n name: \'' +
|
|
434
|
+
fileUrl.replace(/'/g, "''") + '\'\n# --- end flow-comet managed ---\n';
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// bridge-check 版本断言的期望值归一(测试侧镜像生产 bridge-check 契约:仅剥离 git-describe
|
|
438
|
+
// dev 态后缀 `-<N>-g<hash>`,大小写不敏感;预发布标识不匹配、不剥离)。套件自身
|
|
439
|
+
// INSTALLED_VERSION 在权威源检出差为发布标记、在安装副本内为 dev 态戳——期望必须从载体
|
|
440
|
+
// 原始戳归一出的基础版本派生,两种载体形态(权威源 / 安装副本)才都可移植。
|
|
441
|
+
const FIXTURE_BRIDGE_DEV_SUFFIX_RE = /-\d+-g[0-9a-f]+$/i;
|
|
442
|
+
function fixtureBridgeBaseVersion(version) {
|
|
443
|
+
return String(version).replace(FIXTURE_BRIDGE_DEV_SUFFIX_RE, '');
|
|
444
|
+
}
|
|
445
|
+
function fixtureIsBridgeDevVersion(version) {
|
|
446
|
+
return FIXTURE_BRIDGE_DEV_SUFFIX_RE.test(String(version));
|
|
447
|
+
}
|
|
448
|
+
|
|
317
449
|
// 组装 dsh 桥接健康夹具(bridge-check 六态场景共用):项目根挂 .dsh/skills/flow-comet
|
|
318
450
|
// 适用性门;$DSH_HOME/plugins/ 放 loader(含契约锚点 BRIDGE_VERSION 戳,值取自权威源
|
|
319
451
|
// INSTALLED_VERSION,与 bridge-check 比对源同值——健康态恒等、偏斜态可控);cordis.patch.yml
|
|
@@ -326,14 +458,9 @@ function writeBridgeFixture(dir, overrides = {}) {
|
|
|
326
458
|
writeFile(dir, '.dsh/skills/flow-comet/.fixture-anchor', 'fixture\n');
|
|
327
459
|
const loaderPath = path.join(dshHome, 'plugins', 'dsh-flow-comet-bridge.mjs');
|
|
328
460
|
if (!overrides.skipLoader) {
|
|
329
|
-
|
|
330
|
-
'// dsh bridge loader fixture\n// BRIDGE_VERSION: ' + loaderStamp + '\n' +
|
|
331
|
-
"export const name = 'dsh-flow-comet-bridge';\nexport const version = '" + loaderStamp + "';\n");
|
|
461
|
+
writeBridgeLoaderFixture(dshHome, loaderStamp);
|
|
332
462
|
}
|
|
333
|
-
const
|
|
334
|
-
const managedBlock =
|
|
335
|
-
'# --- flow-comet managed ---\n- insert:\n - id: dsh-flow-comet-bridge\n name: \'' +
|
|
336
|
-
fileUrl.replace(/'/g, "''") + '\'\n# --- end flow-comet managed ---\n';
|
|
463
|
+
const managedBlock = managedCordisBlockFor(loaderPath);
|
|
337
464
|
writeFile(dshHome, 'cordis.patch.yml',
|
|
338
465
|
overrides.patchContent !== undefined
|
|
339
466
|
? overrides.patchContent
|
|
@@ -341,6 +468,53 @@ function writeBridgeFixture(dir, overrides = {}) {
|
|
|
341
468
|
return { dshHome, loaderPath, installedVersion, managedBlock };
|
|
342
469
|
}
|
|
343
470
|
|
|
471
|
+
// 安装副本形态夹具(版本比较场景):把本 suite 自身技能树整体复制为
|
|
472
|
+
// <dir>/.dsh/skills/flow-comet —— 被检脚本与同包 INSTALLED_VERSION 因而都可控。
|
|
473
|
+
// bridge-check 读取脚本同包(`<脚本目录>/..`)的 INSTALLED_VERSION:权威源检出路径固定为
|
|
474
|
+
// 发布标记,无法表达「载体 INSTALLED_VERSION 为 dev 态(git describe 后缀)」的形态;
|
|
475
|
+
// 只有以副本自身脚本运行才能构造真实 dev 态载体(与 prepare-env 安装出的形态同构)。
|
|
476
|
+
// 返回 { dshHome, skillCopy };loader 戳由调用方指定,与 INSTALLED_VERSION 可不同。
|
|
477
|
+
// 便携递归复制:不使用 fs.cpSync——实测在 Windows 且**源路径含非 ASCII 字符**时 cpSync 会让
|
|
478
|
+
// 进程静默崩溃(同一进程内 ASCII 源正常、中文源直接退出,逐文件复制两种源都正常),使本套件在
|
|
479
|
+
// 路径含中文的项目内无法跑完。逐目录逐文件复制无此问题,且复制完整性与内容可断言。
|
|
480
|
+
function copyTreePortable(src, dst) {
|
|
481
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
482
|
+
for (const entry of fs.readdirSync(src, { withFileTypes: true })) {
|
|
483
|
+
const from = path.join(src, entry.name);
|
|
484
|
+
const to = path.join(dst, entry.name);
|
|
485
|
+
if (entry.isDirectory()) copyTreePortable(from, to);
|
|
486
|
+
else if (entry.isFile()) fs.copyFileSync(from, to);
|
|
487
|
+
else if (entry.isSymbolicLink()) fs.symlinkSync(fs.readlinkSync(from), to);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function writeInstalledCopyBridgeFixture(dir, { installedVersion, loaderStamp }) {
|
|
492
|
+
const skillCopy = path.join(dir, '.dsh', 'skills', 'flow-comet');
|
|
493
|
+
copyTreePortable(path.join(__dirname, '..'), skillCopy);
|
|
494
|
+
writeFile(skillCopy, 'INSTALLED_VERSION', installedVersion + '\n');
|
|
495
|
+
const dshHome = path.join(dir, 'dshhome');
|
|
496
|
+
const loaderPath = writeBridgeLoaderFixture(dshHome, loaderStamp);
|
|
497
|
+
writeFile(dshHome, 'cordis.patch.yml', managedCordisBlockFor(loaderPath));
|
|
498
|
+
return { dshHome, skillCopy };
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// 以安装副本自身脚本运行 bridge-check(runRoot = 载体项目根;协议副本在 skill 包内,
|
|
502
|
+
// 与真实安装形态一致——默认协议解析即为 <skillCopy>/reference/workflow-protocol.json)。
|
|
503
|
+
function runBridgeCheckFromCopy(dir, dshHome, skillCopy) {
|
|
504
|
+
const res = spawnSync(process.execPath, [path.join(skillCopy, 'scripts', 'workflow-state.mjs'), 'bridge-check'], {
|
|
505
|
+
cwd: dir,
|
|
506
|
+
env: {
|
|
507
|
+
...process.env,
|
|
508
|
+
FLOW_COMET_RUN_ROOT: dir,
|
|
509
|
+
FLOW_COMET_PROTOCOL: path.join(skillCopy, 'reference', 'workflow-protocol.json'),
|
|
510
|
+
DSH_HOME: dshHome,
|
|
511
|
+
},
|
|
512
|
+
encoding: 'utf8',
|
|
513
|
+
timeout: 60000,
|
|
514
|
+
});
|
|
515
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
516
|
+
}
|
|
517
|
+
|
|
344
518
|
function assertExit(res, expected) {
|
|
345
519
|
if (res.status !== expected) {
|
|
346
520
|
throw new Error('期望 exit ' + expected + ',实际 exit ' + res.status + '\n实际输出:\n' + res.output);
|
|
@@ -370,6 +544,332 @@ function assertNotOut(res, keyword) {
|
|
|
370
544
|
}
|
|
371
545
|
}
|
|
372
546
|
|
|
547
|
+
// result 重验撤销审计断言(共享单一来源):撤销后 request evidence 必须 noCommit=false,
|
|
548
|
+
// 且含非空、可被 Date 解析的 revokedAt 与失败类别对应的 revokeReason(缺任一即审计缺口)。
|
|
549
|
+
function assertRevocationAudit(req, expectedReason, label) {
|
|
550
|
+
if (!req || req.noCommit !== false) {
|
|
551
|
+
throw new Error(label + ':撤销后 request evidence 应为 noCommit=false,实际 ' + JSON.stringify(req));
|
|
552
|
+
}
|
|
553
|
+
if (typeof req.revokedAt !== 'string' || req.revokedAt.trim() === '' || Number.isNaN(Date.parse(req.revokedAt))) {
|
|
554
|
+
throw new Error(label + ':撤销应记录非空且可被 Date 解析的 revokedAt,实际 ' + JSON.stringify(req.revokedAt));
|
|
555
|
+
}
|
|
556
|
+
if (req.revokeReason !== expectedReason) {
|
|
557
|
+
throw new Error(label + ':撤销应记录 revokeReason=' + expectedReason + ',实际 ' + JSON.stringify(req.revokeReason));
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// state 不变量断言(m-09 / AC-4 / AC-12):白名单外深比 + history 旧前缀稳定 + 恰新增一条
|
|
562
|
+
// exit-applied 事件。白名单为点分路径(如 'currentNode' / 'evidence.execute.completedChecks')。
|
|
563
|
+
// 判别力:实现若顺手写白名单外字段、重写 history 旧条目、多推/漏推出口事件即抛错。
|
|
564
|
+
function omitStatePath(root, dottedPath) {
|
|
565
|
+
const parts = String(dottedPath).split('.');
|
|
566
|
+
let cursor = root;
|
|
567
|
+
for (let i = 0; i < parts.length - 1; i += 1) {
|
|
568
|
+
if (!cursor || typeof cursor !== 'object') return;
|
|
569
|
+
cursor = cursor[parts[i]];
|
|
570
|
+
}
|
|
571
|
+
if (cursor && typeof cursor === 'object') delete cursor[parts[parts.length - 1]];
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function assertStateOnlyChanged(before, after, options = {}) {
|
|
575
|
+
const label = options.label ? '[' + options.label + '] ' : '';
|
|
576
|
+
const allowed = Array.isArray(options.allowed) ? options.allowed : [];
|
|
577
|
+
const expectNewExitApplied = options.expectNewExitApplied === undefined ? 1 : options.expectNewExitApplied;
|
|
578
|
+
const beforeCmp = JSON.parse(JSON.stringify(before));
|
|
579
|
+
const afterCmp = JSON.parse(JSON.stringify(after));
|
|
580
|
+
for (const p of allowed) {
|
|
581
|
+
omitStatePath(beforeCmp, p);
|
|
582
|
+
omitStatePath(afterCmp, p);
|
|
583
|
+
}
|
|
584
|
+
if (!isDeepStrictEqual(beforeCmp, afterCmp)) {
|
|
585
|
+
throw new Error(label + '白名单外 state 深度不变量被破坏(allowed=' + JSON.stringify(allowed) + ')\n'
|
|
586
|
+
+ 'before=' + JSON.stringify(beforeCmp) + '\nafter=' + JSON.stringify(afterCmp));
|
|
587
|
+
}
|
|
588
|
+
const beforeHistory = Array.isArray(before?.history) ? before.history : [];
|
|
589
|
+
const afterHistory = Array.isArray(after?.history) ? after.history : [];
|
|
590
|
+
if (!isDeepStrictEqual(afterHistory.slice(0, beforeHistory.length), beforeHistory)) {
|
|
591
|
+
throw new Error(label + 'history 旧前缀被改写(旧条目必须逐字稳定)');
|
|
592
|
+
}
|
|
593
|
+
const appended = afterHistory.slice(beforeHistory.length);
|
|
594
|
+
if (appended.length !== expectNewExitApplied) {
|
|
595
|
+
throw new Error(label + 'history 应恰新增 ' + expectNewExitApplied + ' 条,实际 ' + appended.length
|
|
596
|
+
+ ':' + JSON.stringify(appended));
|
|
597
|
+
}
|
|
598
|
+
for (const event of appended) {
|
|
599
|
+
if (!event || event.event !== 'exit-applied') {
|
|
600
|
+
throw new Error(label + '新增 history 条目应为 exit-applied:' + JSON.stringify(event));
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
return appended;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
// 安装副本版本比较断言单点(场景 193 多子锚共用):构造安装副本夹具 → 以副本脚本跑真实
|
|
607
|
+
// bridge-check CLI → 断言 exit 与全部关键词(失败附子锚标签便于定位)。helper 只声明期望,
|
|
608
|
+
// bridge-check 语义仍由 CLI 真实输出承载。
|
|
609
|
+
function assertInstalledCopyBridgeVersionCase(dir, { label, installedVersion, loaderStamp, expectedExit, expectedKeywords }) {
|
|
610
|
+
const fixture = writeInstalledCopyBridgeFixture(dir, { installedVersion, loaderStamp });
|
|
611
|
+
const res = runBridgeCheckFromCopy(dir, fixture.dshHome, fixture.skillCopy);
|
|
612
|
+
try {
|
|
613
|
+
assertExit(res, expectedExit);
|
|
614
|
+
for (const keyword of expectedKeywords) assertOut(res, keyword);
|
|
615
|
+
} catch (e) {
|
|
616
|
+
throw new Error('[' + label + '] ' + e.message);
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// 子锚表构造:单字段对象工厂 + 表函数(run 回调保持线性短小;子锚增长不再推动回调膨胀)。
|
|
621
|
+
function bridgeCopyVersionCase(label, installedVersion, loaderStamp, expectedExit, ...expectedKeywords) {
|
|
622
|
+
return { label, installedVersion, loaderStamp, expectedExit, expectedKeywords };
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
// 场景 193 的安装副本版本比较子锚表——期望值全部从载体基础版本 baseVersion 派生:
|
|
626
|
+
// ② release 态严格相等;③ dev 态安装副本形态同基础健康;④ 两侧 dev 后缀同基础健康;
|
|
627
|
+
// ⑤ 基础版本失配仍 FAIL;⑥ 预发布标识不剥离仍 FAIL;⑦ release 对 release 失配仍 FAIL。
|
|
628
|
+
function bridgeCopyVersionSubAnchorCases(baseVersion, devVersion) {
|
|
629
|
+
const major = parseInt(baseVersion.split('.')[0], 10);
|
|
630
|
+
const otherBase = (major + 9) + '.0.0';
|
|
631
|
+
return [
|
|
632
|
+
// ② release 态严格相等:两原始戳逐字相同 → 沿用 `==` 报告。
|
|
633
|
+
bridgeCopyVersionCase('release 严格相等', baseVersion, baseVersion, 0,
|
|
634
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + ' == 项目 INSTALLED_VERSION=' + baseVersion,
|
|
635
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
636
|
+
// ③ dev 态安装副本形态:载体戳为本副本自身形态(安装副本为 git describe 戳;权威源以发布
|
|
637
|
+
// 标记 + 同构 dev 后缀构造)→ 归一后与同基础 loader 判健康。
|
|
638
|
+
bridgeCopyVersionCase('dev 态安装副本同基础健康', devVersion, baseVersion, 0,
|
|
639
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + ' ~= 项目 INSTALLED_VERSION=' + devVersion + '(dev 态后缀归一后基础版本 ' + baseVersion + ' 一致)',
|
|
640
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
641
|
+
// ④ 两侧 dev 后缀同基础:归一后健康(后缀位置无关性)。
|
|
642
|
+
bridgeCopyVersionCase('两侧 dev 后缀同基础健康', baseVersion + '-3-gabcdef0', baseVersion + '-2-g1234567', 0,
|
|
643
|
+
'[OK] 版本一致性: loader BRIDGE_VERSION=' + baseVersion + '-2-g1234567 ~= 项目 INSTALLED_VERSION=' + baseVersion + '-3-gabcdef0(dev 态后缀归一后基础版本 ' + baseVersion + ' 一致)',
|
|
644
|
+
'bridge-check: 健康(全部检查通过)——exit 0'),
|
|
645
|
+
// ⑤ 基础版本失配:两侧 dev 后缀归一后仍不同 → 原始戳配对 + 双方归一值 FAIL exit 1。
|
|
646
|
+
bridgeCopyVersionCase('基础版本失配', otherBase + '-3-gabcdef0', baseVersion + '-2-g1234567', 1,
|
|
647
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=' + baseVersion + '-2-g1234567 != 项目 INSTALLED_VERSION=' + otherBase + '-3-gabcdef0(归一基础版本: loader=' + baseVersion + ' / installed=' + otherBase + ')——两值如上',
|
|
648
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
649
|
+
// ⑥ 预发布标识不剥离:-rc.N 不属 dev 态后缀 → 仍报偏斜 FAIL exit 1。
|
|
650
|
+
bridgeCopyVersionCase('预发布标识不剥离', baseVersion, baseVersion + '-rc.3', 1,
|
|
651
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=' + baseVersion + '-rc.3 != 项目 INSTALLED_VERSION=' + baseVersion + '(归一基础版本: loader=' + baseVersion + '-rc.3 / installed=' + baseVersion + ')——两值如上',
|
|
652
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
653
|
+
// ⑦ release 对 release 失配:两侧均无 dev 后缀且不同 → 仍 FAIL exit 1。
|
|
654
|
+
bridgeCopyVersionCase('release 对 release 失配', baseVersion, '9.9.9-fixture-skew', 1,
|
|
655
|
+
'[FAIL] 版本偏斜: loader BRIDGE_VERSION=9.9.9-fixture-skew != 项目 INSTALLED_VERSION=' + baseVersion + '(归一基础版本: loader=9.9.9-fixture-skew / installed=' + baseVersion + ')——两值如上',
|
|
656
|
+
'bridge-check: 失配 1 项——exit 1'),
|
|
657
|
+
];
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// ---------- route-node 共享 Fix 判定纯函数锚(直接调用) ----------
|
|
661
|
+
|
|
662
|
+
// 协议副本由运行器在场景执行前复制到 <dir>/reference/(见底部运行段)。
|
|
663
|
+
function readScenarioProtocol(dir) {
|
|
664
|
+
return JSON.parse(fs.readFileSync(path.join(dir, 'reference', 'workflow-protocol.json'), 'utf8'));
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
// 245~247 场景直接调用 route-node 纯函数:缺失导出在此显式报告(RED 定位到具体场景,
|
|
668
|
+
// 而不是整套件在模块加载期因命名绑定失败 abort)。
|
|
669
|
+
function requireRouteNodeExport(name) {
|
|
670
|
+
const fn = routeNodeModule?.[name];
|
|
671
|
+
if (typeof fn !== 'function') {
|
|
672
|
+
throw new Error('route-node.mjs 未导出共享 Fix 判定纯函数 ' + name + '(待实现)');
|
|
673
|
+
}
|
|
674
|
+
return fn;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// Fix 夹具任务块(串行;字段齐全以通过 task-parsing 解析)
|
|
678
|
+
function fixTaskBlock(id, status) {
|
|
679
|
+
return '<task id="' + id + '" parallel="false" status="' + status + '">'
|
|
680
|
+
+ '<action>实现 ' + id + '</action><write_files>src/' + id.toLowerCase() + '.mjs</write_files>'
|
|
681
|
+
+ '<verify>node --check src/' + id.toLowerCase() + '.mjs</verify></task>';
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// Fix 批次(248~252)场景公共任务集:既有任务 T01 done + 修复任务(状态由参数指定)
|
|
685
|
+
function fixBatchTaskText(fixStatus) {
|
|
686
|
+
return '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T-FIX-01', fixStatus) + '\n';
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// exit execute 二次完成回源场景公共夹具(场景族拆分后由三个顶层场景共享;每个场景仍在独立
|
|
690
|
+
// 临时目录运行,状态不跨场景共享):家族证据与基础 state 的字段基线在此单一表达。
|
|
691
|
+
function fixReturnFamilyEvidence(taskIds) {
|
|
692
|
+
return {
|
|
693
|
+
execute: { summary: 'fix batch executed', completedChecks: ['required-skill:execute.flow-comet-dev'] },
|
|
694
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(taskIds) },
|
|
695
|
+
review: { summary: 'review in progress' },
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function fixReturnBaseState(overrides = {}) {
|
|
700
|
+
return {
|
|
701
|
+
activeChange: CHANGE_ID,
|
|
702
|
+
currentNode: 'execute',
|
|
703
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
704
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
705
|
+
evidence: fixReturnFamilyEvidence(['T01']),
|
|
706
|
+
verifyFailures: 0,
|
|
707
|
+
executionMode: 'subagent',
|
|
708
|
+
directOverride: false,
|
|
709
|
+
newChange: true,
|
|
710
|
+
...overrides,
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const FIX_RETURN_FAMILY_COMPLETED = 'open,design,plan,execute,subagent-execute';
|
|
715
|
+
|
|
716
|
+
// 回源夹具的 REVIEW.md 正文:内容表达「审查未完成、Fix 批次待回源出口」,文件在场即触发
|
|
717
|
+
// 路由按产物跳过 review 的行为。
|
|
718
|
+
const FIX_RETURN_REVIEW_TEXT = '# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\n审查结论已记录;Fix 批次由 execute 完成,待回源重新出口。\n';
|
|
719
|
+
|
|
720
|
+
// 逐任务写入摘要夹具(id 列表由调用场景给出,未列出的任务不会凭空出现摘要)。
|
|
721
|
+
function writeFixReturnSummaries(dir, taskIds) {
|
|
722
|
+
for (const id of taskIds) {
|
|
723
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/' + id + '-SUMMARY.md', strictSummary(id));
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// 并行 Fix 任务集(无依赖 → 可委托):既有任务 T01 done + parallel 修复任务(状态由参数指定)。
|
|
728
|
+
function fixBatchParallelTaskText(fixStatus) {
|
|
729
|
+
return '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
730
|
+
+ '<task id="P-FIX-01" parallel="true" status="' + fixStatus + '">'
|
|
731
|
+
+ '<action>实现 P-FIX-01</action><write_files>src/p-fix-01.mjs</write_files>'
|
|
732
|
+
+ '<verify>node --check src/p-fix-01.mjs</verify></task>\n';
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// 家族出口事件过时回放:最新 exit-applied 事件节点为 execute / subagent-execute,
|
|
736
|
+
// 签名仍是修复任务追加前的占位值(本批生命周期未闭合的信号;change 缺省 = 旧 state 兼容)。
|
|
737
|
+
function fixBatchHistoryWithStaleFamilyExit(node = 'execute') {
|
|
738
|
+
return [{ event: 'exit-applied', node, at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE }];
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
// done-but-unclosed 回放夹具(L-070 事故形态):history 中最新 exit-applied execute 事件记录的
|
|
742
|
+
// 签名仍是追加修复任务之前的占位值(与「既有任务 + 追加修复任务」当前任务集签名必然不等)——
|
|
743
|
+
// 机器信号 =「修复任务已标 done,但本批 execute 出口从未重新通过」。追加前的真实哈希值不影响
|
|
744
|
+
// 判据(只比较是否相等),占位常量让夹具与哈希算法实现解耦;旧 state 无该字段 → 渐进放行。
|
|
745
|
+
const STALE_FIX_BATCH_SIGNATURE = '0'.repeat(64);
|
|
746
|
+
function fixBatchHistoryWithStaleExecuteExit() {
|
|
747
|
+
return [{ event: 'exit-applied', node: 'execute', at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE }];
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
// 读取场景 state 的机器字段(Fix 批次场景的写盘断言:归位/回程真实落盘,不是只看输出)
|
|
751
|
+
function readScenarioState(dir) {
|
|
752
|
+
return JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// ---------- 受控重入(archive 源回边)场景材料(先写期望后执行) ----------
|
|
756
|
+
// archive 已 entry 且归档目录仍在原位时的受控重入契约(设计决策清单全部条目 /
|
|
757
|
+
// REQUIREMENT AC-1~AC-10):CLI 入口为
|
|
758
|
+
// `workflow-state.mjs reenter <target> --authorized-by <source> --reason <text>`。
|
|
759
|
+
// 本段只装配夹具与断言助手;判定语义的唯一权威在 route-node.mjs(测试侧不复制生产判定——
|
|
760
|
+
// L-067);前驱交集期望值由内置协议 success 边独立推导,是测试判据的独立复算。
|
|
761
|
+
|
|
762
|
+
// 内置协议(route 顺序 open→design→plan→execute→subagent-execute→review→verify→archive)
|
|
763
|
+
// 下 predecessors(target) 的期望交集:success 边反向传递闭包,按协议顺序输出。
|
|
764
|
+
const REENTRY_EXPECTED_INTERSECTION = {
|
|
765
|
+
'execute': ['open', 'design', 'plan'],
|
|
766
|
+
'subagent-execute': ['open', 'design', 'plan', 'execute'],
|
|
767
|
+
'review': ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
768
|
+
'verify': ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
769
|
+
};
|
|
770
|
+
const REENTRY_FULL_COMPLETED = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'];
|
|
771
|
+
|
|
772
|
+
// archive 已 entry 夹具(AC-1 初始状态):归档目录仍在原位、status=running、前驱全已完成;
|
|
773
|
+
// overrides 覆盖旧 change(无 newChange 字段)/ status=completed / 轮次事件等形态。
|
|
774
|
+
// branchMode / enablePrReview / branchPrefix 显式在场——避免 readState 的旧 state 默认补齐
|
|
775
|
+
// 让「白名单外字段零改写」断言混入实现细节噪音。
|
|
776
|
+
function reentryArchiveState(overrides = {}) {
|
|
777
|
+
return {
|
|
778
|
+
activeChange: CHANGE_ID,
|
|
779
|
+
currentNode: 'archive',
|
|
780
|
+
completedNodes: [...REENTRY_FULL_COMPLETED],
|
|
781
|
+
enteredNodes: [...REENTRY_FULL_COMPLETED, 'archive'],
|
|
782
|
+
evidence: {},
|
|
783
|
+
verifyFailures: 0,
|
|
784
|
+
executionMode: 'subagent',
|
|
785
|
+
directOverride: false,
|
|
786
|
+
newChange: true,
|
|
787
|
+
status: 'running',
|
|
788
|
+
branchMode: true,
|
|
789
|
+
enablePrReview: false,
|
|
790
|
+
branchPrefix: 'change/',
|
|
791
|
+
history: [{ event: 'exit-applied', node: 'verify', at: '2026-09-20T00:00:00.000Z', change: CHANGE_ID }],
|
|
792
|
+
...overrides,
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
// 归档目录仍在原位(移动边界判定的前提之一):CHANGE.md + TASK.md 在场
|
|
797
|
+
function writeReentryChangeDir(dir, changeName = CHANGE_ID) {
|
|
798
|
+
writeFile(dir, '.specs/' + changeName + '/CHANGE.md', '# CHANGE\n\n## Why\n\n受控重入夹具。\n');
|
|
799
|
+
writeFile(dir, '.specs/' + changeName + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
// 受控重入 CLI(真实命令路径):env 显式注入协议路径(门禁不得静默跳过);
|
|
803
|
+
// extra 供 --protocol 等追加参数;reenter 未落地前本路径因 unknown subcommand 必然 RED。
|
|
804
|
+
function runReenter(dir, target, options = {}) {
|
|
805
|
+
const args = ['reenter', target];
|
|
806
|
+
if (options.source !== undefined) args.push('--authorized-by', options.source);
|
|
807
|
+
if (options.reason !== undefined) args.push('--reason', options.reason);
|
|
808
|
+
if (Array.isArray(options.extra)) args.push(...options.extra);
|
|
809
|
+
return runState(args, dir, {
|
|
810
|
+
FLOW_COMET_PROTOCOL: options.protocol || path.join(dir, 'reference', 'workflow-protocol.json'),
|
|
811
|
+
});
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// state 原始字节:BLOCK / 空操作路径的「字节零改写」判据(JSON 深比会漏掉格式化、键序与
|
|
815
|
+
// 序列化表示漂移——字节比较才是契约)。
|
|
816
|
+
function readStateBytes(dir) {
|
|
817
|
+
const file = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
818
|
+
if (!fs.existsSync(file)) {
|
|
819
|
+
throw new Error('state 文件缺失(夹具错误或命令删除了 state): ' + file);
|
|
820
|
+
}
|
|
821
|
+
return fs.readFileSync(file, 'utf8');
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
function assertStateBytesUnchanged(dir, before, label) {
|
|
825
|
+
const after = readStateBytes(dir);
|
|
826
|
+
if (after !== before) {
|
|
827
|
+
throw new Error(label + ':要求 state 字节零改写,实际发生变化\nbefore:\n' + before + '\nafter:\n' + after);
|
|
828
|
+
}
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// 备份文件清单(备份路径规则 .specs/<change-id>/.reentry-backups/):BLOCK / 空操作路径必须零新增。
|
|
832
|
+
function reentryBackupFiles(dir, changeName = CHANGE_ID) {
|
|
833
|
+
const backupDir = path.join(dir, '.specs', changeName, '.reentry-backups');
|
|
834
|
+
if (!fs.existsSync(backupDir)) return [];
|
|
835
|
+
return fs.readdirSync(backupDir).sort();
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
// 轮次事件夹具:change 归属字段是跨 change 隔离的唯一依据(写侧必须带 change)——
|
|
839
|
+
// 不带 change 的旧事件按 legacy 形态参与(reentry-applied 为新事件类型,实际不会出现)。
|
|
840
|
+
function reentryHistoryEvent(roundNumber, changeName = CHANGE_ID) {
|
|
841
|
+
return {
|
|
842
|
+
event: 'reentry-applied',
|
|
843
|
+
from: 'archive',
|
|
844
|
+
to: 'verify',
|
|
845
|
+
round: roundNumber,
|
|
846
|
+
change: changeName,
|
|
847
|
+
authorization: { round: roundNumber, at: '2026-09-20T00:00:00.000Z', source: 'user-approval', target: 'verify' },
|
|
848
|
+
backup: '.specs/' + changeName + '/.reentry-backups/2026-09-20T00-00-00.000Z-pre-verify.json',
|
|
849
|
+
fingerprint: '0'.repeat(64),
|
|
850
|
+
at: '2026-09-20T00:00:00.000Z',
|
|
851
|
+
};
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
// 授权形态纯函数锚(AC-2 的 guard-self-test 验证方式):形态合法性由 route-node 的
|
|
855
|
+
// parseReentryAuthorization 单一权威判定,本助手只声明期望(malformed → ok:false)。
|
|
856
|
+
function assertReentryAuthorizationShape(authorization, target, expectedOk, label) {
|
|
857
|
+
const parse = requireRouteNodeExport('parseReentryAuthorization');
|
|
858
|
+
const result = parse({ authorization, target });
|
|
859
|
+
if (!result || result.ok !== expectedOk) {
|
|
860
|
+
throw new Error('[' + label + '] 授权形态判定应为 ok=' + expectedOk + ',实际 ' + JSON.stringify(result));
|
|
861
|
+
}
|
|
862
|
+
return result;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// 输出正则断言(BLOCK 指引类断言的共享助手;精确关键词断言用 assertOut)。
|
|
866
|
+
function assertOutMatches(res, pattern, label) {
|
|
867
|
+
const text = outputText(res);
|
|
868
|
+
if (!pattern.test(text)) {
|
|
869
|
+
throw new Error((label || '输出') + ' 应匹配 ' + pattern + ',实际输出:\n' + text);
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
|
|
373
873
|
// ---------- 伪造材料 ----------
|
|
374
874
|
|
|
375
875
|
function baseState(node) {
|
|
@@ -585,10 +1085,30 @@ function strictSummary(taskId) {
|
|
|
585
1085
|
'- 可观测: 通过',
|
|
586
1086
|
'- 可维护: 通过',
|
|
587
1087
|
'',
|
|
1088
|
+
'## 数据库迁移',
|
|
1089
|
+
'',
|
|
1090
|
+
'N/A:本任务无 schema 变更(条件段按模板占位)。',
|
|
1091
|
+
'',
|
|
588
1092
|
'## 越界检查',
|
|
589
1093
|
'',
|
|
590
1094
|
'仅修改 src/' + taskId.toLowerCase() + '.mjs,无越界。',
|
|
591
1095
|
'',
|
|
1096
|
+
'## 破坏性变更',
|
|
1097
|
+
'',
|
|
1098
|
+
'N/A:本任务不涉及破坏性变更。',
|
|
1099
|
+
'',
|
|
1100
|
+
'## 决策与偏离',
|
|
1101
|
+
'',
|
|
1102
|
+
'无偏离。',
|
|
1103
|
+
'',
|
|
1104
|
+
'## 是否触发新工作',
|
|
1105
|
+
'',
|
|
1106
|
+
'无。',
|
|
1107
|
+
'',
|
|
1108
|
+
'## 完成判定',
|
|
1109
|
+
'',
|
|
1110
|
+
'- TASK.md 中对应任务已勾选:是',
|
|
1111
|
+
'',
|
|
592
1112
|
'## 自检方法',
|
|
593
1113
|
'',
|
|
594
1114
|
'brooks-review',
|
|
@@ -1283,12 +1803,20 @@ const SCENARIOS = [
|
|
|
1283
1803
|
throw new Error('exit verify 失败计数未递增: ' + JSON.stringify(stFail2.verifyFailuresByChange));
|
|
1284
1804
|
}
|
|
1285
1805
|
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```bash\nnode -e "1"\n```\n');
|
|
1806
|
+
// AC-5 隔离:verify 成功只清 verify 计数,不得清 Fix 归位轮次(预置计数,成功出口后核对)
|
|
1807
|
+
const stBeforePass = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
1808
|
+
stBeforePass.fixRoundsByChange = { ...(stBeforePass.fixRoundsByChange || {}), [CHANGE_ID]: 2 };
|
|
1809
|
+
fs.writeFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), JSON.stringify(stBeforePass, null, 2) + '\n');
|
|
1286
1810
|
const resPass = runGuard(['exit', 'verify', '--apply'], dir);
|
|
1287
1811
|
assertExit(resPass, 0);
|
|
1288
1812
|
const stPass = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
1289
1813
|
if (!stPass.verifyFailuresByChange || stPass.verifyFailuresByChange[CHANGE_ID] !== 0) {
|
|
1290
1814
|
throw new Error('exit verify 成功未清零当前 change 计数: ' + JSON.stringify(stPass.verifyFailuresByChange));
|
|
1291
1815
|
}
|
|
1816
|
+
if (stPass.fixRoundsByChange?.[CHANGE_ID] !== 2) {
|
|
1817
|
+
throw new Error('exit verify 成功不得清 Fix 归位轮次(计数隔离): '
|
|
1818
|
+
+ JSON.stringify(stPass.fixRoundsByChange));
|
|
1819
|
+
}
|
|
1292
1820
|
},
|
|
1293
1821
|
},
|
|
1294
1822
|
|
|
@@ -1428,6 +1956,27 @@ const SCENARIOS = [
|
|
|
1428
1956
|
assertExit(res, 0);
|
|
1429
1957
|
assertOut(res, 'ALL CHECKS PASSED');
|
|
1430
1958
|
assertNotOut(res, 'Unknown workflow Node');
|
|
1959
|
+
// ③ state.protocolPath 持久化绑定优先于 FLOW_COMET_PROTOCOL env:env 指向内置协议
|
|
1960
|
+
// (无 brainstorm 节点),state 绑定自定义协议 → 仍按自定义协议通过。修复前 guard 只看
|
|
1961
|
+
// CLI/env → 走内置协议报 Unknown Node(RED)。
|
|
1962
|
+
const bound = composeState({
|
|
1963
|
+
currentNode: 'brainstorm',
|
|
1964
|
+
evidence: { brainstorm: { summary: 'brainstorm done' } },
|
|
1965
|
+
protocolPath: 'custom-protocol.json',
|
|
1966
|
+
});
|
|
1967
|
+
writeState(dir, bound);
|
|
1968
|
+
const resBound = runGuard(['exit', 'brainstorm'], dir); // runGuard 默认 env=内置协议副本
|
|
1969
|
+
assertExit(resBound, 0);
|
|
1970
|
+
assertOut(resBound, 'ALL CHECKS PASSED');
|
|
1971
|
+
assertNotOut(resBound, 'Unknown workflow Node');
|
|
1972
|
+
// ④ state.protocolPath 绑定不可读 → fail-closed 不回退 env/默认协议,错误说明来源与
|
|
1973
|
+
// 不回退语义(归属门禁可跳过校验,节点门禁没有等价降级路径)。
|
|
1974
|
+
writeState(dir, composeState({ protocolPath: 'missing-protocol.json' }));
|
|
1975
|
+
const resBoundMissing = runGuard(['exit', 'brainstorm'], dir);
|
|
1976
|
+
assertExit(resBoundMissing, 1);
|
|
1977
|
+
assertOut(resBoundMissing, 'state.protocolPath');
|
|
1978
|
+
assertOut(resBoundMissing, '不回退');
|
|
1979
|
+
assertNotOut(resBoundMissing, 'Unknown workflow Node');
|
|
1431
1980
|
},
|
|
1432
1981
|
},
|
|
1433
1982
|
|
|
@@ -3013,6 +3562,21 @@ const SCENARIOS = [
|
|
|
3013
3562
|
assertExit(res2, 0);
|
|
3014
3563
|
assertNotOut(res2, 'REVIEW WARN');
|
|
3015
3564
|
assertOut(res2, 'ALL CHECKS PASSED');
|
|
3565
|
+
// ③ 有序条目(1. **...**)与无序同口径——缺处置标记 → 旧 change 仍渐进 REVIEW WARN
|
|
3566
|
+
// (修复前 .filter((item) => !item.ordered) 使有序条目静默通过 = RED)
|
|
3567
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
3568
|
+
'# REVIEW\n\n## 发现\n\n1. **m-2 · 有序未处置**:某处问题,未给出任何处置结论,描述足够长以避免内容不足\n\n## 结论\n\n通过\n');
|
|
3569
|
+
const resOrdered = runGuard(['exit', 'review'], dir);
|
|
3570
|
+
assertExit(resOrdered, 0);
|
|
3571
|
+
assertOut(resOrdered, 'REVIEW WARN');
|
|
3572
|
+
assertNotOut(resOrdered, 'BLOCKED');
|
|
3573
|
+
// ④ 有序 Minor 带 [转待办] → 无该渐进告警(有序条目接入校验不误报已处置项)
|
|
3574
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
3575
|
+
'# REVIEW\n\n## 发现\n\n1. **m-3 · 有序小项**:某处小问题,已登记下一 change 跟踪处置 [转待办]\n\n## 结论\n\n通过\n');
|
|
3576
|
+
const resOrderedOk = runGuard(['exit', 'review'], dir);
|
|
3577
|
+
assertExit(resOrderedOk, 0);
|
|
3578
|
+
assertNotOut(resOrderedOk, 'REVIEW WARN');
|
|
3579
|
+
assertOut(resOrderedOk, 'ALL CHECKS PASSED');
|
|
3016
3580
|
},
|
|
3017
3581
|
},
|
|
3018
3582
|
|
|
@@ -3479,9 +4043,11 @@ const SCENARIOS = [
|
|
|
3479
4043
|
},
|
|
3480
4044
|
},
|
|
3481
4045
|
|
|
3482
|
-
// 125: R1——新 change(newChange:true)review 处置标记缺失 → BLOCKED(旧 change WARN 保留)
|
|
4046
|
+
// 125: R1——新 change(newChange:true)review 处置标记缺失 → BLOCKED(旧 change WARN 保留);
|
|
4047
|
+
// 并内扩 Major 延期待裁决门禁三态+一反例:无用户裁决 BLOCK / 同段或文末裁决(由 [升级]
|
|
4048
|
+
// 承接)放行 / Minor [转待办] 不受影响 / 有裁决但缺 [升级] 承接仍 BLOCK。
|
|
3483
4049
|
{
|
|
3484
|
-
name: '125 review exit BLOCKED:新 change
|
|
4050
|
+
name: '125 review exit BLOCKED:新 change 处置标记缺失 + Major 延期待裁决(R1)',
|
|
3485
4051
|
run: (dir) => {
|
|
3486
4052
|
const st = baseState('review');
|
|
3487
4053
|
st.evidence.review = { summary: 'reviewed' };
|
|
@@ -3509,6 +4075,89 @@ const SCENARIOS = [
|
|
|
3509
4075
|
const resOk2 = runGuard(['exit', 'review'], dir);
|
|
3510
4076
|
assertExit(resOk2, 0);
|
|
3511
4077
|
assertOut(resOk2, 'ALL CHECKS PASSED');
|
|
4078
|
+
// 子断言:Major [转待办] 属用户决策点——无用户裁决记录 → BLOCKED(修复前放行 = RED)
|
|
4079
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F1 · 未裁决的延期**:某处问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4080
|
+
const resMajor = runGuard(['exit', 'review'], dir);
|
|
4081
|
+
assertExit(resMajor, 1);
|
|
4082
|
+
assertOut(resMajor, 'BLOCKED');
|
|
4083
|
+
assertOut(resMajor, 'Major');
|
|
4084
|
+
assertOut(resMajor, '用户裁决');
|
|
4085
|
+
// 子断言:同段用户裁决 + [升级] 承接 → 放行
|
|
4086
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F2 · 已裁决的延期**:某处问题 [升级] [转待办](用户裁决:接受延期,下一 change 首修)\n\n## 结论\n\n通过\n');
|
|
4087
|
+
const resAdjudicated = runGuard(['exit', 'review'], dir);
|
|
4088
|
+
assertExit(resAdjudicated, 0);
|
|
4089
|
+
assertOut(resAdjudicated, 'ALL CHECKS PASSED');
|
|
4090
|
+
assertNotOut(resAdjudicated, '用户裁决');
|
|
4091
|
+
// 子断言:Minor [转待办] 不受影响 → 放行
|
|
4092
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Minor\n\n- **m-1 · 小项**:某处小问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4093
|
+
const resMinor = runGuard(['exit', 'review'], dir);
|
|
4094
|
+
assertExit(resMinor, 0);
|
|
4095
|
+
assertOut(resMinor, 'ALL CHECKS PASSED');
|
|
4096
|
+
// 子断言:文末用户裁决 + 指向该条目 + [升级] 承接 → 放行
|
|
4097
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F3 · 文末裁决的延期**:某处问题 [升级] [转待办]\n\n## 用户裁决\n\n- 用户裁决:接受延期 —— 发现 F3(文末裁决的延期):下一 change 首修。\n\n## 结论\n\n通过\n');
|
|
4098
|
+
const resTail = runGuard(['exit', 'review'], dir);
|
|
4099
|
+
assertExit(resTail, 0);
|
|
4100
|
+
assertOut(resTail, 'ALL CHECKS PASSED');
|
|
4101
|
+
// 子断言:尾部裁决段落引用条目整行(引用块)时不得被误判为条目自身段落 → 放行
|
|
4102
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F5 · 引用条目行的尾部裁决**:某处问题 [升级] [转待办]\n\n## 用户裁决\n\n> - **F5 · 引用条目行的尾部裁决**:某处问题 [升级] [转待办]\n> 用户裁决:接受延期 —— 发现 F5:下一 change 首修。\n\n## 结论\n\n通过\n');
|
|
4103
|
+
const resQuotedTail = runGuard(['exit', 'review'], dir);
|
|
4104
|
+
assertExit(resQuotedTail, 0);
|
|
4105
|
+
assertOut(resQuotedTail, 'ALL CHECKS PASSED');
|
|
4106
|
+
// 子断言:有用户裁决但缺 [升级] 承接 → 仍 BLOCKED(不因裁决在文末就跳过承接校验)
|
|
4107
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F4 · 无升级承接**:某处问题 [转待办]\n\n## 用户裁决\n\n- 用户裁决:接受延期 —— 发现 F4(无升级承接):下一 change 首修。\n\n## 结论\n\n通过\n');
|
|
4108
|
+
const resNoEscalation = runGuard(['exit', 'review'], dir);
|
|
4109
|
+
assertExit(resNoEscalation, 1);
|
|
4110
|
+
assertOut(resNoEscalation, 'BLOCKED');
|
|
4111
|
+
assertOut(resNoEscalation, 'Major');
|
|
4112
|
+
assertOut(resNoEscalation, '用户裁决');
|
|
4113
|
+
// 子断言:Minor 条目正文引用 [Major] 标签字样(自身 [转待办])→ 放行——严重度/处置
|
|
4114
|
+
// 以条目自身标题/行首为准,不做整块标签扫描(修复前误判 Major 并触发延期门禁 = RED)
|
|
4115
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n- **m-2 · 引用 Major 的小项**:本条与 [Major] F1 项不同,是独立问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4116
|
+
const resCited = runGuard(['exit', 'review'], dir);
|
|
4117
|
+
assertExit(resCited, 0);
|
|
4118
|
+
assertOut(resCited, 'ALL CHECKS PASSED');
|
|
4119
|
+
assertNotOut(resCited, 'BLOCKED');
|
|
4120
|
+
// 子断言:Major 条目自身处置为 [已修],续行正文引用他条 [转待办] → 放行——
|
|
4121
|
+
// 延期门禁只看该条目自身标题/行首的处置标记,不做整块扫描
|
|
4122
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **[Major] F9 · 已修项引用他条**:某处问题 [已修]\n (续行仅引用他条的处置去向 [转待办],非本条处置)\n\n## 结论\n\n通过\n');
|
|
4123
|
+
const resQuotedDisposition = runGuard(['exit', 'review'], dir);
|
|
4124
|
+
assertExit(resQuotedDisposition, 0);
|
|
4125
|
+
assertOut(resQuotedDisposition, 'ALL CHECKS PASSED');
|
|
4126
|
+
assertNotOut(resQuotedDisposition, 'BLOCKED');
|
|
4127
|
+
// 子断言:有序 Major 标签条目缺任何处置标记 → BLOCKED(修复前有序条目被跳过 = RED)
|
|
4128
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n1. **[Major] F6 · 有序无处置**:某处问题,未给出任何处置结论,描述足够长以避免内容不足\n\n## 结论\n\n通过\n');
|
|
4129
|
+
const resOrderedMissing = runGuard(['exit', 'review'], dir);
|
|
4130
|
+
assertExit(resOrderedMissing, 1);
|
|
4131
|
+
assertOut(resOrderedMissing, '处置状态标记');
|
|
4132
|
+
// 子断言:有序 Major [转待办] 无用户裁决 → BLOCKED(Major 延期门禁对有序条目同口径)
|
|
4133
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n1. **F7 · 有序未裁决的延期**:某处问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4134
|
+
const resOrderedDeferred = runGuard(['exit', 'review'], dir);
|
|
4135
|
+
assertExit(resOrderedDeferred, 1);
|
|
4136
|
+
assertOut(resOrderedDeferred, 'Major');
|
|
4137
|
+
assertOut(resOrderedDeferred, '用户裁决');
|
|
4138
|
+
// 子断言:有序 Major [升级] [转待办] + 同段用户裁决([升级] 承接)→ 放行
|
|
4139
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n1. **F8 · 有序已裁决的延期**:某处问题 [升级] [转待办](用户裁决:接受延期,下一 change 首修)\n\n## 结论\n\n通过\n');
|
|
4140
|
+
const resOrderedAdjudicated = runGuard(['exit', 'review'], dir);
|
|
4141
|
+
assertExit(resOrderedAdjudicated, 0);
|
|
4142
|
+
assertOut(resOrderedAdjudicated, 'ALL CHECKS PASSED');
|
|
4143
|
+
assertNotOut(resOrderedAdjudicated, '用户裁决');
|
|
4144
|
+
// 子断言:中间位置的独立裁决段落(不与条目同段、也不在文末)——指向该条目且含
|
|
4145
|
+
// [升级] 承接 → 放行。实现按独立段落匹配,位置不限;文档须写明这一合法形态。
|
|
4146
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
4147
|
+
'# REVIEW\n\n## 发现\n\n### Major\n\n'
|
|
4148
|
+
+ '- **F10 · 中段裁决的延期**:某处问题 [升级] [转待办]\n\n'
|
|
4149
|
+
+ '- 用户裁决:接受延期 —— 发现 F10(中段裁决的延期):下一 change 首修。\n\n'
|
|
4150
|
+
+ '### Minor\n\n- **m-4 · 小项**:另一个独立问题 [已修]\n\n## 结论\n\n通过\n');
|
|
4151
|
+
const resMidParagraph = runGuard(['exit', 'review'], dir);
|
|
4152
|
+
assertExit(resMidParagraph, 0);
|
|
4153
|
+
assertOut(resMidParagraph, 'ALL CHECKS PASSED');
|
|
4154
|
+
// 子断言:文档口径与实现对齐——review SKILL 须写明「单独段落(指向条目 + [升级] 承接)」
|
|
4155
|
+
// 也是合法裁决位置,避免文档只写「同段或文末」而收窄实现语义(文档未同步 = RED)。
|
|
4156
|
+
const reviewSkillText = fs.readFileSync(
|
|
4157
|
+
path.join(__dirname, '..', '..', 'flow-comet-review', 'SKILL.md'), 'utf8');
|
|
4158
|
+
if (!reviewSkillText.includes('单独段落') || !reviewSkillText.includes('指向') || !reviewSkillText.includes('[升级]')) {
|
|
4159
|
+
throw new Error('flow-comet-review/SKILL.md 未写明「单独段落(指向条目 + [升级] 承接)」合法');
|
|
4160
|
+
}
|
|
3512
4161
|
},
|
|
3513
4162
|
},
|
|
3514
4163
|
|
|
@@ -3569,6 +4218,101 @@ const SCENARIOS = [
|
|
|
3569
4218
|
const res = runGuard(['exit', 'execute'], dir);
|
|
3570
4219
|
assertExit(res, 1);
|
|
3571
4220
|
assertOut(res, '越权');
|
|
4221
|
+
|
|
4222
|
+
// ===== M-02 request 时刻归属门禁(AC-1/AC-2/AC-3 的 L1 面)=====
|
|
4223
|
+
// 夹具前提:新 change 驻留 execute + 本节点技能声明标记在场(否则先被技能声明门 BLOCK,
|
|
4224
|
+
// 测不到归属门禁本身);协议副本由运行器放入 <dir>/reference/ 并显式指向(env 优先级)。
|
|
4225
|
+
const reqEnv = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
4226
|
+
const reqStatePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
4227
|
+
fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID, '.skill-loads'), { recursive: true });
|
|
4228
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/execute-flow-comet-dev.json',
|
|
4229
|
+
JSON.stringify({ node: 'execute', skill: 'flow-comet-dev', protocol: '4-dev.md', at: '2026-08-01T00:00:00.000Z' }, null, 2) + '\n');
|
|
4230
|
+
const pendingParallelTask =
|
|
4231
|
+
'<task id="P-M02" parallel="true" status="pending"><action>实现 P-M02</action><write_files>src/p-m02.mjs</write_files><verify>node --check src/p-m02.mjs</verify></task>\n';
|
|
4232
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + pendingParallelTask);
|
|
4233
|
+
// ① 新 change 错误节点 pending 并行 request → BLOCK + state 字节零改写 + 不落请求记录 + 恢复指引
|
|
4234
|
+
const reqState = baseState('execute');
|
|
4235
|
+
reqState.newChange = true;
|
|
4236
|
+
reqState.enteredNodes = ['execute'];
|
|
4237
|
+
writeState(dir, reqState);
|
|
4238
|
+
const beforeReqBytes = fs.readFileSync(reqStatePath, 'utf8');
|
|
4239
|
+
const resWrongNode = runHandoff(['request', 'P-M02', 'parallel fix slice'], dir, reqEnv);
|
|
4240
|
+
assertExit(resWrongNode, 1);
|
|
4241
|
+
assertOut(resWrongNode, 'BLOCKED: 任务 P-M02(并行 pending)应归属节点 subagent-execute');
|
|
4242
|
+
assertOut(resWrongNode, 'workflow-state next');
|
|
4243
|
+
assertOut(resWrongNode, 'entry subagent-execute');
|
|
4244
|
+
assertOut(resWrongNode, '本次请求未写入 state');
|
|
4245
|
+
if (fs.readFileSync(reqStatePath, 'utf8') !== beforeReqBytes) {
|
|
4246
|
+
throw new Error('M-02 BLOCK 必须 state 字节零改写');
|
|
4247
|
+
}
|
|
4248
|
+
const stAfterBlock = readScenarioState(dir);
|
|
4249
|
+
const reqsAfterBlock = stAfterBlock.evidence?.['subagent-execute']?.handoffRequests ?? {};
|
|
4250
|
+
if (reqsAfterBlock['P-M02']) {
|
|
4251
|
+
throw new Error('M-02 BLOCK 不得落 handoffRequests: ' + JSON.stringify(reqsAfterBlock));
|
|
4252
|
+
}
|
|
4253
|
+
// ② 旧 change 同构造 → 可见 WARN + 照常落库(AC-3 渐进兼容)
|
|
4254
|
+
writeState(dir, { ...baseState('execute'), enteredNodes: ['execute'] });
|
|
4255
|
+
const resOldChange = runHandoff(['request', 'P-M02', 'parallel fix slice'], dir, reqEnv);
|
|
4256
|
+
assertExit(resOldChange, 0);
|
|
4257
|
+
assertOut(resOldChange, 'WARN: 任务 P-M02(并行 pending)应归属节点 subagent-execute');
|
|
4258
|
+
assertOut(resOldChange, '旧 change 渐进不阻断');
|
|
4259
|
+
assertOut(resOldChange, 'HANDOFF REQUEST: P-M02');
|
|
4260
|
+
const stOldChange = readScenarioState(dir);
|
|
4261
|
+
if (!stOldChange.evidence?.['subagent-execute']?.handoffRequests?.['P-M02']) {
|
|
4262
|
+
throw new Error('旧 change 错误节点请求应照常落库(AC-3),实际 ' + JSON.stringify(stOldChange.evidence));
|
|
4263
|
+
}
|
|
4264
|
+
// ③ pending 并行任务依赖未满足 → 当前不可委托。恢复指引必须以 next 实际输出为准:
|
|
4265
|
+
// next 对依赖未满足的并行任务按串行消化输出 execute——指引不得再固定指向
|
|
4266
|
+
// entry subagent-execute(否则按指引进入会被 currentNode 门禁拦成死路)。
|
|
4267
|
+
writeIntakeArtifacts(dir);
|
|
4268
|
+
const unmetDepsTask =
|
|
4269
|
+
'<task id="S-M01" parallel="false" status="pending"><action>实现 S-M01</action><write_files>src/s-m01.mjs</write_files><verify>node --check src/s-m01.mjs</verify></task>\n' +
|
|
4270
|
+
'<task id="P-M03" parallel="true" status="pending"><action>实现 P-M03</action><write_files>src/p-m03.mjs</write_files><verify>node --check src/p-m03.mjs</verify><depends_on>S-M01</depends_on></task>\n';
|
|
4271
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + unmetDepsTask);
|
|
4272
|
+
const unmetState = baseState('execute');
|
|
4273
|
+
unmetState.newChange = true;
|
|
4274
|
+
unmetState.enteredNodes = ['execute'];
|
|
4275
|
+
unmetState.completedNodes = ['open', 'design', 'plan'];
|
|
4276
|
+
unmetState.evidence = { plan: { summary: 'plan done' } };
|
|
4277
|
+
writeState(dir, unmetState);
|
|
4278
|
+
const unmetBytesBefore = fs.readFileSync(reqStatePath, 'utf8');
|
|
4279
|
+
const resUnmet = runHandoff(['request', 'P-M03', 'parallel slice with unmet deps'], dir, reqEnv);
|
|
4280
|
+
assertExit(resUnmet, 1);
|
|
4281
|
+
assertOut(resUnmet, 'BLOCKED: 任务 P-M03(并行 pending)当前不可委托:依赖未满足');
|
|
4282
|
+
assertOut(resUnmet, '未完成: S-M01');
|
|
4283
|
+
assertOut(resUnmet, '原始 currentNode=execute');
|
|
4284
|
+
assertOut(resUnmet, 'workflow-state next');
|
|
4285
|
+
assertOut(resUnmet, '按输出的 NODE 进入');
|
|
4286
|
+
assertOut(resUnmet, '若输出 execute 表示依赖未满足');
|
|
4287
|
+
assertOut(resUnmet, '待任务变为可委托');
|
|
4288
|
+
// 不得固定指引 next 不会输出的节点(进入即死路的反锚)
|
|
4289
|
+
assertNotOut(resUnmet, 'entry subagent-execute');
|
|
4290
|
+
assertNotOut(resUnmet, 'HANDOFF REQUEST');
|
|
4291
|
+
if (fs.readFileSync(reqStatePath, 'utf8') !== unmetBytesBefore) {
|
|
4292
|
+
throw new Error('依赖未满足 BLOCK 必须 state 字节零改写');
|
|
4293
|
+
}
|
|
4294
|
+
const stUnmet = readScenarioState(dir);
|
|
4295
|
+
if (stUnmet.evidence?.['subagent-execute']?.handoffRequests?.['P-M03']) {
|
|
4296
|
+
throw new Error('依赖未满足 BLOCK 不得落 handoffRequests: ' + JSON.stringify(stUnmet.evidence));
|
|
4297
|
+
}
|
|
4298
|
+
// 同构真实链路:next 对当前 TASK 实际输出 execute(依赖未满足/串行消化),与指引条件分支一致
|
|
4299
|
+
const resUnmetNext = runState(['next'], dir, reqEnv);
|
|
4300
|
+
assertExit(resUnmetNext, 0);
|
|
4301
|
+
if (!/^NODE: execute$/m.test(resUnmetNext.output)) {
|
|
4302
|
+
throw new Error('依赖未满足时 next 应输出 execute(指引一致性锚):\n' + resUnmetNext.output);
|
|
4303
|
+
}
|
|
4304
|
+
if (readScenarioState(dir).currentNode !== 'execute') {
|
|
4305
|
+
throw new Error('依赖未满足时 next 应把工作归属留在 execute: ' + JSON.stringify(readScenarioState(dir).currentNode));
|
|
4306
|
+
}
|
|
4307
|
+
// 旧 change 同形态 → 可见 WARN + 照常落库(渐进兼容,不因依赖未满足而卡死)
|
|
4308
|
+
const oldUnmetState = { ...unmetState };
|
|
4309
|
+
delete oldUnmetState.newChange;
|
|
4310
|
+
writeState(dir, oldUnmetState);
|
|
4311
|
+
const resUnmetOld = runHandoff(['request', 'P-M03', 'old change unmet deps'], dir, reqEnv);
|
|
4312
|
+
assertExit(resUnmetOld, 0);
|
|
4313
|
+
assertOut(resUnmetOld, 'WARN: 任务 P-M03(并行 pending)当前不可委托:依赖未满足');
|
|
4314
|
+
assertOut(resUnmetOld, '旧 change 渐进不阻断');
|
|
4315
|
+
assertOut(resUnmetOld, 'HANDOFF REQUEST: P-M03');
|
|
3572
4316
|
},
|
|
3573
4317
|
},
|
|
3574
4318
|
|
|
@@ -3602,9 +4346,10 @@ const SCENARIOS = [
|
|
|
3602
4346
|
},
|
|
3603
4347
|
},
|
|
3604
4348
|
|
|
3605
|
-
// 131: R1 旧兼容——旧 change(无 newChange)处置标记缺失仍 WARN
|
|
4349
|
+
// 131: R1 旧兼容——旧 change(无 newChange)处置标记缺失仍 WARN;并内扩 Major 延期待裁决
|
|
4350
|
+
// 门禁旧 change 渐进面:无用户裁决 → WARN 不 BLOCK(不卡死旧 REVIEW);有裁决+[升级] → 放行。
|
|
3606
4351
|
{
|
|
3607
|
-
name: '131 review exit 兼容:旧 change 处置标记缺失仍 WARN
|
|
4352
|
+
name: '131 review exit 兼容:旧 change 处置标记缺失仍 WARN + Major 延期渐进(R1 旧兼容)',
|
|
3608
4353
|
run: (dir) => {
|
|
3609
4354
|
const st = baseState('review');
|
|
3610
4355
|
st.evidence.review = { summary: 'reviewed' };
|
|
@@ -3613,6 +4358,27 @@ const SCENARIOS = [
|
|
|
3613
4358
|
const res = runGuard(['exit', 'review'], dir);
|
|
3614
4359
|
assertExit(res, 0);
|
|
3615
4360
|
assertOut(res, 'WARN');
|
|
4361
|
+
// 子断言:Major [转待办] 无用户裁决 → 旧 change 渐进 WARN 且不 BLOCK(不卡死旧 REVIEW)
|
|
4362
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F1 · 未裁决的延期**:某处问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4363
|
+
const resMajor = runGuard(['exit', 'review'], dir);
|
|
4364
|
+
assertExit(resMajor, 0);
|
|
4365
|
+
assertOut(resMajor, 'REVIEW WARN');
|
|
4366
|
+
assertOut(resMajor, 'Major');
|
|
4367
|
+
assertOut(resMajor, '用户裁决');
|
|
4368
|
+
assertNotOut(resMajor, 'BLOCKED');
|
|
4369
|
+
// 子断言:有同段用户裁决 + [升级] 承接 → 无该渐进告警
|
|
4370
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n- **F2 · 已裁决的延期**:某处问题 [升级] [转待办](用户裁决:接受延期)\n\n## 结论\n\n通过\n');
|
|
4371
|
+
const resOk = runGuard(['exit', 'review'], dir);
|
|
4372
|
+
assertExit(resOk, 0);
|
|
4373
|
+
assertNotOut(resOk, '用户裁决');
|
|
4374
|
+
assertOut(resOk, 'ALL CHECKS PASSED');
|
|
4375
|
+
// 子断言:有序 Major [转待办] 无用户裁决 → 旧 change 渐进 WARN 不 BLOCK(有序同口径)
|
|
4376
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', '# REVIEW\n\n## 发现\n\n### Major\n\n1. **F3 · 有序未裁决的延期**:某处问题 [转待办]\n\n## 结论\n\n通过\n');
|
|
4377
|
+
const resOrderedMajor = runGuard(['exit', 'review'], dir);
|
|
4378
|
+
assertExit(resOrderedMajor, 0);
|
|
4379
|
+
assertOut(resOrderedMajor, 'REVIEW WARN');
|
|
4380
|
+
assertOut(resOrderedMajor, '用户裁决');
|
|
4381
|
+
assertNotOut(resOrderedMajor, 'BLOCKED');
|
|
3616
4382
|
},
|
|
3617
4383
|
},
|
|
3618
4384
|
|
|
@@ -3748,6 +4514,29 @@ const SCENARIOS = [
|
|
|
3748
4514
|
const r9 = runState(['verify-fail'], dir, env);
|
|
3749
4515
|
assertExit(r9, 1);
|
|
3750
4516
|
assertOut(r9, '超限');
|
|
4517
|
+
// ⑥ 计数隔离扩展(AC-5):verify 失败计数与 Fix 归位轮次各自独立——verify-fail 只动
|
|
4518
|
+
// verifyFailuresByChange,绝不触碰 fixRoundsByChange(旧实现只读 verify 计数已通过;
|
|
4519
|
+
// 若未来把二者混用 / 共用容器,本条按 change 逐项断言变红)。
|
|
4520
|
+
const stIsolated = readScenarioState(dir);
|
|
4521
|
+
stIsolated.fixRoundsByChange = { ch: 2, ch2: 1 };
|
|
4522
|
+
writeState(dir, stIsolated);
|
|
4523
|
+
writeFile(dir, '.specs/ch3/CHANGE.md', '# CHANGE\n## Why\nx\n');
|
|
4524
|
+
assertExit(runState(['select', 'ch3'], dir, env), 0);
|
|
4525
|
+
const stCh3Before = readScenarioState(dir);
|
|
4526
|
+
stCh3Before.fixRoundsByChange = { ch: 2, ch2: 1, ch3: 5 };
|
|
4527
|
+
writeState(dir, stCh3Before);
|
|
4528
|
+
const r10 = runState(['verify-fail'], dir, env);
|
|
4529
|
+
assertExit(r10, 0);
|
|
4530
|
+
assertOut(r10, 'VERIFY-FAIL: 1/3');
|
|
4531
|
+
const stCh3After = readScenarioState(dir);
|
|
4532
|
+
if (stCh3After.verifyFailuresByChange?.ch3 !== 1) {
|
|
4533
|
+
throw new Error('verify-fail 应按 change 递增 verify 计数,实际 '
|
|
4534
|
+
+ JSON.stringify(stCh3After.verifyFailuresByChange));
|
|
4535
|
+
}
|
|
4536
|
+
if (JSON.stringify(stCh3After.fixRoundsByChange) !== JSON.stringify({ ch: 2, ch2: 1, ch3: 5 })) {
|
|
4537
|
+
throw new Error('verify 失败计数与 Fix 轮次计数不得串扰(fixRoundsByChange 被改写): '
|
|
4538
|
+
+ JSON.stringify(stCh3After.fixRoundsByChange));
|
|
4539
|
+
}
|
|
3751
4540
|
},
|
|
3752
4541
|
},
|
|
3753
4542
|
|
|
@@ -4110,11 +4899,16 @@ const SCENARIOS = [
|
|
|
4110
4899
|
// 启发式安全侧边界锚定 / 零提交正式语义 / SUMMARY·TASK7·三文档模板保真 / 技能加载前置门 /
|
|
4111
4900
|
// next·entry 输出点名 / 技能加载措辞 / next 进行中节点保护扩展) ----------
|
|
4112
4901
|
|
|
4113
|
-
// 154:
|
|
4114
|
-
// 不得各自定义 looksLikeObjectLiteral,必须从 state-schema.mjs import
|
|
4115
|
-
|
|
4902
|
+
// 154: 单一来源静态锁(设计语义 / AC-1 + F-3 / AC-5)——① workflow-state.mjs 与
|
|
4903
|
+
// workflow-handoff.mjs 不得各自定义 looksLikeObjectLiteral,必须从 state-schema.mjs import
|
|
4904
|
+
//(单一来源 fail-closed);② F-3:workflow-guard/state/handoff 三消费脚本均须从
|
|
4905
|
+
// route-node.mjs import EXECUTE_FAMILY_NODE_IDS,且源码中不得再出现 execute 家族成员内联 pair
|
|
4906
|
+
//(<ident> === 'execute' || <ident> === 'subagent-execute',正反顺序)→ 0 命中。
|
|
4907
|
+
// 允许清单:单节点分支 / hasSubagentNode 协议判定 / 证据键与文案不参与 pair 断言。
|
|
4908
|
+
// ② 该轮修复在既有场景内扩展(不新增顶层编号)。
|
|
4909
|
+
|
|
4116
4910
|
{
|
|
4117
|
-
name: '154
|
|
4911
|
+
name: '154 单一来源静态锁:state/handoff 不内置 looksLikeObjectLiteral + 三消费脚本 import EXECUTE_FAMILY_NODE_IDS 且无内联 pair',
|
|
4118
4912
|
run: (dir) => {
|
|
4119
4913
|
const schemaPath = path.join(__dirname, 'state-schema.mjs');
|
|
4120
4914
|
const script = `
|
|
@@ -4134,6 +4928,62 @@ const SCENARIOS = [
|
|
|
4134
4928
|
const res = spawnSync(process.execPath, ['-e', script, STATE, HANDOFF, schemaPath], { encoding: 'utf8', timeout: 60000 });
|
|
4135
4929
|
assertExit(res, 0);
|
|
4136
4930
|
assertOut(res, 'SINGLE SOURCE OK');
|
|
4931
|
+
|
|
4932
|
+
// ===== F-3(AC-5):三消费脚本 execute 家族成员单一来源静态锁 ====
|
|
4933
|
+
// ① import 断言:枚举 import 语句后匹配 source + 具名符号(容忍重排/多行/其它符号共存)。
|
|
4934
|
+
const importRe = /import\s*\{([\s\S]*?)\}\s*from\s*['"]([^'"]+)['"]/g;
|
|
4935
|
+
const hasNamedImport = (text, source, name) => {
|
|
4936
|
+
importRe.lastIndex = 0;
|
|
4937
|
+
let m;
|
|
4938
|
+
while ((m = importRe.exec(text)) !== null) {
|
|
4939
|
+
if (m[2] === source && m[1].split(',').some((s) => s.trim() === name)) return true;
|
|
4940
|
+
}
|
|
4941
|
+
return false;
|
|
4942
|
+
};
|
|
4943
|
+
// ② 内联 pair 检测器:`=== 'execute'` 与 `=== 'subagent-execute'` 经 `||` 直连(正反顺序)。
|
|
4944
|
+
// 只命中双侧 === || === 组合;单节点分支(&& / 单 compare)、协议判定、证据键不命中
|
|
4945
|
+
//(下方合成正/负例自锚,防检测器退化为永不生效或误伤允许形态)。
|
|
4946
|
+
const pairRe = /(?:[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*===\s*'execute'\s*\)?\s*\|\|\s*\(?\s*[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*===\s*'subagent-execute')|(?:[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*===\s*'subagent-execute'\s*\)?\s*\|\|\s*\(?\s*[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*===\s*'execute')/g;
|
|
4947
|
+
const detectorPositive = [
|
|
4948
|
+
"(node.id === 'execute' || node.id === 'subagent-execute')",
|
|
4949
|
+
"(detectedNode === 'subagent-execute' || detectedNode === 'execute')",
|
|
4950
|
+
"(nodeId === 'execute' || requestNode === 'subagent-execute')",
|
|
4951
|
+
];
|
|
4952
|
+
const detectorNegative = [
|
|
4953
|
+
"if (node.id === 'execute' && state.activeChange) {",
|
|
4954
|
+
"if (node.id === 'subagent-execute' && state.activeChange) {",
|
|
4955
|
+
"(protocol.nodes ?? []).some(n => n.id === 'subagent-execute')",
|
|
4956
|
+
"state.evidence['subagent-execute'] = state.evidence['subagent-execute'] || {};",
|
|
4957
|
+
"hasSubagentNode(protocol)",
|
|
4958
|
+
];
|
|
4959
|
+
const issues = [];
|
|
4960
|
+
for (const candidate of detectorPositive) {
|
|
4961
|
+
pairRe.lastIndex = 0;
|
|
4962
|
+
if (!pairRe.test(candidate)) issues.push('内联 pair 检测器自身失效:未命中已知历史形态 ' + JSON.stringify(candidate));
|
|
4963
|
+
}
|
|
4964
|
+
for (const candidate of detectorNegative) {
|
|
4965
|
+
pairRe.lastIndex = 0;
|
|
4966
|
+
if (pairRe.test(candidate)) issues.push('内联 pair 检测器误报允许形态:' + JSON.stringify(candidate));
|
|
4967
|
+
}
|
|
4968
|
+
const familySources = [
|
|
4969
|
+
['workflow-guard.mjs', GUARD],
|
|
4970
|
+
['workflow-state.mjs', STATE],
|
|
4971
|
+
['workflow-handoff.mjs', HANDOFF],
|
|
4972
|
+
];
|
|
4973
|
+
for (const [sourceName, sourceFile] of familySources) {
|
|
4974
|
+
const text = fs.readFileSync(sourceFile, 'utf8');
|
|
4975
|
+
if (!hasNamedImport(text, './route-node.mjs', 'EXECUTE_FAMILY_NODE_IDS')) {
|
|
4976
|
+
issues.push(sourceName + ' 未从 ./route-node.mjs import EXECUTE_FAMILY_NODE_IDS(execute 家族成员须单一来源)');
|
|
4977
|
+
}
|
|
4978
|
+
const sourceLines = text.split('\n');
|
|
4979
|
+
pairRe.lastIndex = 0;
|
|
4980
|
+
let m;
|
|
4981
|
+
while ((m = pairRe.exec(text)) !== null) {
|
|
4982
|
+
const lineNo = text.slice(0, m.index).split('\n').length;
|
|
4983
|
+
issues.push(sourceName + ':' + lineNo + ' 出现 execute 家族成员内联 pair(应改用 EXECUTE_FAMILY_NODE_IDS.has(...)): ' + sourceLines[lineNo - 1].trim());
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
if (issues.length > 0) throw new Error(issues.join(String.fromCharCode(10)));
|
|
4137
4987
|
},
|
|
4138
4988
|
},
|
|
4139
4989
|
|
|
@@ -4185,12 +5035,16 @@ const SCENARIOS = [
|
|
|
4185
5035
|
},
|
|
4186
5036
|
},
|
|
4187
5037
|
|
|
4188
|
-
// 157: 零提交任务正例(设计语义 / AC-5
|
|
4189
|
-
// 无任何提交 → 跳过提交文件子集校验并输出可审计"零提交"提示(不误 BLOCK
|
|
4190
|
-
//
|
|
5038
|
+
// 157: 零提交任务正例(设计语义 / AC-5 / AC-7)——① request write_files 为空 + 契约显式 noCommit +
|
|
5039
|
+
// result 无任何提交 → 跳过提交文件子集校验并输出可审计"零提交"提示(不误 BLOCK);
|
|
5040
|
+
// ② 真实 request(F-6):临时 git 仓 + .gitignore 忽略 .specs/,TASK write_files 全为字面
|
|
5041
|
+
// .specs/... 路径 → 引擎记 handoffRequests.<id>.noCommit=true(可证明全部 gitignored);
|
|
5042
|
+
// result 回传无 commitHash 的零提交契约 → 记录成功、输出"零提交"、无 HANDOFF ERROR。
|
|
5043
|
+
// 修复前 request 只认「<write_files> 元素存在且为空」→ ② 无 noCommit → 预期 RED。
|
|
4191
5044
|
{
|
|
4192
|
-
name: '157
|
|
5045
|
+
name: '157 零提交正例:空 write_files 跳过校验;全字面 gitignored 真实 request 记 noCommit',
|
|
4193
5046
|
run: (dir) => {
|
|
5047
|
+
// ① 空 write_files 既有正例(request 落库夹具;零回归锚)
|
|
4194
5048
|
const st = baseState('subagent-execute');
|
|
4195
5049
|
st.newChange = true;
|
|
4196
5050
|
st.evidence['subagent-execute'] = { handoffRequests: { T01: { description: 'zero-commit task', writeFiles: [] } } };
|
|
@@ -4204,15 +5058,117 @@ const SCENARIOS = [
|
|
|
4204
5058
|
})], dir);
|
|
4205
5059
|
assertExit(res, 0);
|
|
4206
5060
|
assertOut(res, '零提交');
|
|
5061
|
+
// ② 全字面 gitignored 正例:临时 git 仓 + .gitignore 忽略 .specs/;真实 request 自动解析 TASK.md
|
|
5062
|
+
execFileSync('git', ['init'], { cwd: dir, stdio: 'ignore' });
|
|
5063
|
+
const git = (...args) => execFileSync('git', args, { cwd: dir, stdio: 'ignore' });
|
|
5064
|
+
writeFile(dir, '.gitignore', '.specs/\n');
|
|
5065
|
+
writeFile(dir, 'baseline.js', 'export const baseline = 1;\n');
|
|
5066
|
+
git('add', '.gitignore', 'baseline.js');
|
|
5067
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'init baseline');
|
|
5068
|
+
// write_files 全为字面 .specs/...(被 .gitignore 忽略;不要求预先存在——check-ignore 按规则判)
|
|
5069
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5070
|
+
+ '<task id="T02" status="done"><action>写变更内部面工件</action>'
|
|
5071
|
+
+ '<write_files>\n.specs/' + CHANGE_ID + '/notes/T02.md\n.specs/' + CHANGE_ID + '/T02-SUMMARY.md\n</write_files>'
|
|
5072
|
+
+ '<verify>node --check baseline.js</verify></task>\n');
|
|
5073
|
+
fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID, '.skill-loads'), { recursive: true });
|
|
5074
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/subagent-execute-flow-comet-dev.json',
|
|
5075
|
+
JSON.stringify({ node: 'subagent-execute', skill: 'flow-comet-dev', protocol: '4-dev.md', at: '2026-08-01T00:00:00.000Z' }, null, 2) + '\n');
|
|
5076
|
+
const st2 = baseState('subagent-execute');
|
|
5077
|
+
st2.newChange = true;
|
|
5078
|
+
writeState(dir, st2);
|
|
5079
|
+
const resReq = runHandoff(['request', 'T02', 'delegate docs-only slice'], dir);
|
|
5080
|
+
assertExit(resReq, 0);
|
|
5081
|
+
assertOut(resReq, 'HANDOFF REQUEST: T02');
|
|
5082
|
+
// 先断资格落库(RED 取证点:修复前 request 只认空 write_files → 此断言先红),后断审计文案
|
|
5083
|
+
const stAfter = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5084
|
+
const req = stAfter.evidence['subagent-execute'].handoffRequests.T02;
|
|
5085
|
+
if (!req || req.noCommit !== true) {
|
|
5086
|
+
throw new Error('全字面 gitignored write_files 应记 noCommit:true,实际 ' + JSON.stringify(req));
|
|
5087
|
+
}
|
|
5088
|
+
assertOut(resReq, '零提交资格');
|
|
5089
|
+
const resZero = runHandoff(['result', 'T02', JSON.stringify({
|
|
5090
|
+
status: 'DONE', taskId: 'T02', noCommit: true,
|
|
5091
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
5092
|
+
redEvidence: { command: 'node --check baseline.js', output: 'no output(RED 锚点)' },
|
|
5093
|
+
greenEvidence: { command: 'node --check baseline.js', output: 'ok' },
|
|
5094
|
+
})], dir);
|
|
5095
|
+
assertExit(resZero, 0);
|
|
5096
|
+
assertOut(resZero, '零提交');
|
|
5097
|
+
assertNotOut(resZero, 'HANDOFF ERROR');
|
|
5098
|
+
// ③ m-13 result 重验失败(.gitignore 变化)新 change:HANDOFF ERROR + request.noCommit 置 false
|
|
5099
|
+
// + 不落/不覆盖 result(资格建立后把 .specs/ 从忽略规则移除 → 重验失败)
|
|
5100
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
5101
|
+
const priorCompletedAt = JSON.parse(fs.readFileSync(statePath, 'utf8'))
|
|
5102
|
+
.evidence['subagent-execute'].handoffResult.T02.completedAt;
|
|
5103
|
+
writeFile(dir, '.gitignore', 'baseline-only\n');
|
|
5104
|
+
const resRevalBlock = runHandoff(['result', 'T02', JSON.stringify({
|
|
5105
|
+
status: 'DONE', taskId: 'T02', noCommit: true,
|
|
5106
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
5107
|
+
redEvidence: { command: 'node --check baseline.js', output: 'ok' },
|
|
5108
|
+
greenEvidence: { command: 'node --check baseline.js', output: 'ok' },
|
|
5109
|
+
})], dir);
|
|
5110
|
+
assertExit(resRevalBlock, 1);
|
|
5111
|
+
assertOut(resRevalBlock, 'HANDOFF ERROR');
|
|
5112
|
+
assertOut(resRevalBlock, 'noCommit=false');
|
|
5113
|
+
assertOut(resRevalBlock, '不落 result');
|
|
5114
|
+
const stRevalBlock = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
5115
|
+
const reqBlocked = stRevalBlock.evidence['subagent-execute'].handoffRequests.T02;
|
|
5116
|
+
if (!reqBlocked || reqBlocked.noCommit !== false) {
|
|
5117
|
+
throw new Error('result 重验失败应把 request.noCommit 置 false,实际 ' + JSON.stringify(reqBlocked));
|
|
5118
|
+
}
|
|
5119
|
+
if (stRevalBlock.evidence['subagent-execute'].handoffResult.T02.completedAt !== priorCompletedAt) {
|
|
5120
|
+
throw new Error('新 change result 重验失败不得覆盖既有 handoffResult(completedAt 变化)');
|
|
5121
|
+
}
|
|
5122
|
+
// F6 审计:忽略规则变化(过期资格)撤销必须留 at/reason,且失败类别与既有归类一致
|
|
5123
|
+
assertRevocationAudit(reqBlocked, 'stale-eligibility', '157③ 新 change .gitignore 变化');
|
|
5124
|
+
assertOut(resRevalBlock, 'revokedAt=');
|
|
5125
|
+
assertOut(resRevalBlock, 'revokeReason=stale-eligibility');
|
|
5126
|
+
// ④ 旧 change 同构造:HANDOFF WARN + 照常落 result + noCommit 同样置 false(渐进兼容)
|
|
5127
|
+
writeFile(dir, '.gitignore', '.specs/\n'); // 恢复忽略规则 → 重新 request 取得资格
|
|
5128
|
+
const stReReq = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
5129
|
+
delete stReReq.newChange; // 旧 change = 缺省/null(validator 不接受 false)
|
|
5130
|
+
writeState(dir, stReReq);
|
|
5131
|
+
assertExit(runHandoff(['request', 'T02', 'delegate docs-only slice again'], dir), 0);
|
|
5132
|
+
const stReReqAfter = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
5133
|
+
if (stReReqAfter.evidence['subagent-execute'].handoffRequests.T02.noCommit !== true) {
|
|
5134
|
+
throw new Error('恢复忽略规则后重新 request 应重新取得 noCommit 资格,实际 '
|
|
5135
|
+
+ JSON.stringify(stReReqAfter.evidence['subagent-execute'].handoffRequests.T02));
|
|
5136
|
+
}
|
|
5137
|
+
const legacyCompletedAt = stReReqAfter.evidence['subagent-execute'].handoffResult.T02.completedAt;
|
|
5138
|
+
writeFile(dir, '.gitignore', 'baseline-only\n');
|
|
5139
|
+
const resRevalWarn = runHandoff(['result', 'T02', JSON.stringify({
|
|
5140
|
+
status: 'DONE', taskId: 'T02', noCommit: true,
|
|
5141
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
5142
|
+
redEvidence: { command: 'node --check baseline.js', output: 'ok' },
|
|
5143
|
+
greenEvidence: { command: 'node --check baseline.js', output: 'ok' },
|
|
5144
|
+
})], dir);
|
|
5145
|
+
assertExit(resRevalWarn, 0);
|
|
5146
|
+
assertOut(resRevalWarn, 'HANDOFF WARN');
|
|
5147
|
+
assertOut(resRevalWarn, 'noCommit=false');
|
|
5148
|
+
const stRevalWarn = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
5149
|
+
if (stRevalWarn.evidence['subagent-execute'].handoffRequests.T02.noCommit !== false) {
|
|
5150
|
+
throw new Error('旧 change 重验失败同样应撤销 request.noCommit,实际 '
|
|
5151
|
+
+ JSON.stringify(stRevalWarn.evidence['subagent-execute'].handoffRequests.T02));
|
|
5152
|
+
}
|
|
5153
|
+
// F6 审计:旧 change 渐进撤销同样必须留 at/reason(与失败类别对应)
|
|
5154
|
+
assertRevocationAudit(stRevalWarn.evidence['subagent-execute'].handoffRequests.T02,
|
|
5155
|
+
'stale-eligibility', '157④ 旧 change .gitignore 变化');
|
|
5156
|
+
assertOut(resRevalWarn, 'revokeReason=stale-eligibility');
|
|
5157
|
+
const legacyResult = stRevalWarn.evidence['subagent-execute'].handoffResult.T02;
|
|
5158
|
+
if (!legacyResult || legacyResult.completedAt === legacyCompletedAt || legacyResult.result.noCommit !== true) {
|
|
5159
|
+
throw new Error('旧 change 重验失败应照常落 result(渐进),实际 ' + JSON.stringify(legacyResult));
|
|
5160
|
+
}
|
|
4207
5161
|
},
|
|
4208
5162
|
},
|
|
4209
5163
|
|
|
4210
|
-
// 158: 零提交滥用负例(设计语义 / AC-6
|
|
4211
|
-
// 不得借零提交声明绕过真实提交检查:仍走完整提交文件子集校验(越界 → 新 change BLOCK),且输出
|
|
4212
|
-
// 可审计的"零提交声明与 write_files 非空矛盾"
|
|
4213
|
-
//
|
|
5164
|
+
// 158: 零提交滥用负例(设计语义 / AC-6 / AC-8)——① write_files 非空任务的结果契约声称 noCommit
|
|
5165
|
+
// → 不得借零提交声明绕过真实提交检查:仍走完整提交文件子集校验(越界 → 新 change BLOCK),且输出
|
|
5166
|
+
// 可审计的"零提交声明与 write_files 非空矛盾"提示;
|
|
5167
|
+
// ② F-6 请求侧 fail-closed:glob 魔法 / 路径越界(../)/ 非 git 仓 / 非 git top-level 的 runRoot
|
|
5168
|
+
// → request 不记 noCommit(不阻断原流程、仍记 writeFiles);
|
|
5169
|
+
// ③ 请求无资格 + 契约声称 noCommit → 仍完整校验(WARN + 越界 BLOCK,零提交声明无效)。
|
|
4214
5170
|
{
|
|
4215
|
-
name: '158
|
|
5171
|
+
name: '158 零提交滥用负例:非空声称 noCommit 仍完整校验;glob/越界/非 git/非 top-level 请求不记 noCommit',
|
|
4216
5172
|
run: (dir) => {
|
|
4217
5173
|
const g = (args) => spawnSync('git', args, { cwd: dir, encoding: 'utf8' });
|
|
4218
5174
|
g(['init', '-q']);
|
|
@@ -4237,6 +5193,165 @@ const SCENARIOS = [
|
|
|
4237
5193
|
assertExit(res, 1);
|
|
4238
5194
|
assertOut(res, '超出 writeFiles 范围');
|
|
4239
5195
|
assertOut(res, '零提交');
|
|
5196
|
+
// ② F-6 请求侧 fail-closed:不具资格形态 → request 不记 noCommit、不阻断原流程。
|
|
5197
|
+
// 夹具加强:.gitignore 同时忽略 src/gen/ 与 .specs/——globs/子目录锚的路径在缺判定时会
|
|
5198
|
+
// 被 git check-ignore 命中,故必须由字面/包含判定本身拒绝,锚才具备判别力(可反向构造红)。
|
|
5199
|
+
writeFile(dir, '.gitignore', 'src/gen/\n.specs/\n');
|
|
5200
|
+
// 请求夹具(旧 change 语义:技能加载门 WARN 渐进,不干扰本锚)
|
|
5201
|
+
writeState(dir, baseState('subagent-execute'));
|
|
5202
|
+
const readReq = (id) => {
|
|
5203
|
+
const s = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5204
|
+
return (s.evidence['subagent-execute'].handoffRequests || {})[id];
|
|
5205
|
+
};
|
|
5206
|
+
const requestWithWriteFiles = (id, writeFilesElement) => {
|
|
5207
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5208
|
+
+ '<task id="' + id + '" status="done"><action>边界任务</action>'
|
|
5209
|
+
+ '<write_files>' + writeFilesElement + '</write_files>'
|
|
5210
|
+
+ '<verify>node --check allowed.js</verify></task>\n');
|
|
5211
|
+
const r = runHandoff(['request', id, 'boundary slice'], dir);
|
|
5212
|
+
assertExit(r, 0);
|
|
5213
|
+
return r;
|
|
5214
|
+
};
|
|
5215
|
+
// ②a glob 魔法 `*` → 无可证明资格(不展开 glob、不享受零提交)
|
|
5216
|
+
const resGlob = requestWithWriteFiles('T02', 'src/gen/*.mjs');
|
|
5217
|
+
assertNotOut(resGlob, 'HANDOFF ERROR');
|
|
5218
|
+
const reqGlob = readReq('T02');
|
|
5219
|
+
if (!reqGlob || reqGlob.noCommit === true) {
|
|
5220
|
+
throw new Error('glob write_files 不应具备零提交资格,实际 ' + JSON.stringify(reqGlob));
|
|
5221
|
+
}
|
|
5222
|
+
if (!Array.isArray(reqGlob.writeFiles) || reqGlob.writeFiles[0] !== 'src/gen/*.mjs') {
|
|
5223
|
+
throw new Error('不具资格也不得丢失 writeFiles 记录: ' + JSON.stringify(reqGlob.writeFiles));
|
|
5224
|
+
}
|
|
5225
|
+
// ②b 路径越界(../ 逃逸 runRoot)→ 无资格
|
|
5226
|
+
requestWithWriteFiles('T03', '../../outside.md');
|
|
5227
|
+
const reqEscape = readReq('T03');
|
|
5228
|
+
if (!reqEscape || reqEscape.noCommit === true) {
|
|
5229
|
+
throw new Error('../ 逃逸 write_files 不应具备零提交资格,实际 ' + JSON.stringify(reqEscape));
|
|
5230
|
+
}
|
|
5231
|
+
// ②c 非 git 仓(独立临时目录,无 .git)→ 无资格;场景自建临时目录须自清理
|
|
5232
|
+
//(运行器只回收场景主目录;残留校验会抓走漏——故 try/finally 内自删)
|
|
5233
|
+
const nonGit = makeTmp();
|
|
5234
|
+
try {
|
|
5235
|
+
writeFile(nonGit, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5236
|
+
+ '<task id="T04" status="done"><action>边界任务</action>'
|
|
5237
|
+
+ '<write_files>.specs/' + CHANGE_ID + '/x.md</write_files>'
|
|
5238
|
+
+ '<verify>node --check allowed.js</verify></task>\n');
|
|
5239
|
+
writeState(nonGit, baseState('subagent-execute'));
|
|
5240
|
+
const resNonGit = runHandoff(['request', 'T04', 'non-git slice'], nonGit);
|
|
5241
|
+
assertExit(resNonGit, 0);
|
|
5242
|
+
const stNonGit = JSON.parse(fs.readFileSync(path.join(nonGit, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5243
|
+
const reqNonGit = stNonGit.evidence['subagent-execute'].handoffRequests.T04;
|
|
5244
|
+
if (!reqNonGit || reqNonGit.noCommit === true) {
|
|
5245
|
+
throw new Error('非 git 仓不应具备零提交资格,实际 ' + JSON.stringify(reqNonGit));
|
|
5246
|
+
}
|
|
5247
|
+
} finally {
|
|
5248
|
+
fs.rmSync(nonGit, { recursive: true, force: true });
|
|
5249
|
+
}
|
|
5250
|
+
// ②d runRoot 非 git top-level(仓内子目录)→ 无资格
|
|
5251
|
+
writeFile(dir, 'sub/.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5252
|
+
+ '<task id="T05" status="done"><action>边界任务</action>'
|
|
5253
|
+
+ '<write_files>.specs/' + CHANGE_ID + '/x.md</write_files>'
|
|
5254
|
+
+ '<verify>node --check allowed.js</verify></task>\n');
|
|
5255
|
+
const sub = path.join(dir, 'sub');
|
|
5256
|
+
writeState(sub, baseState('subagent-execute'));
|
|
5257
|
+
const resSub = runHandoff(['request', 'T05', 'subdir slice'], sub);
|
|
5258
|
+
assertExit(resSub, 0);
|
|
5259
|
+
const stSub = JSON.parse(fs.readFileSync(path.join(sub, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5260
|
+
const reqSub = stSub.evidence['subagent-execute'].handoffRequests.T05;
|
|
5261
|
+
if (!reqSub || reqSub.noCommit === true) {
|
|
5262
|
+
throw new Error('runRoot 非 git top-level 不应具备零提交资格,实际 ' + JSON.stringify(reqSub));
|
|
5263
|
+
}
|
|
5264
|
+
// ②e/②f m-13 symlink/junction 逃逸(Windows junction 先例):request 时刻逐段 lstat
|
|
5265
|
+
// 拒绝 symlink/junction 祖先;result 时刻对资格重验——资格建立后把真实目录替换为
|
|
5266
|
+
// junction 指向 runRoot 外 → 新 change HANDOFF ERROR、noCommit 撤销、不落 result。
|
|
5267
|
+
const outsideDir = makeTmp();
|
|
5268
|
+
const linkPathA = path.join(dir, 'linked-out');
|
|
5269
|
+
const linkPathB = path.join(dir, 'linked-out2');
|
|
5270
|
+
const linkType = process.platform === 'win32' ? 'junction' : 'dir';
|
|
5271
|
+
try {
|
|
5272
|
+
writeFile(outsideDir, 'escape.md', 'outside\n');
|
|
5273
|
+
// ②e request 资格拒绝:write_files 祖先段为 junction(目标在 runRoot 外),即使
|
|
5274
|
+
// .gitignore 命中该路径也不得授予零提交(旧实现只看 check-ignore → noCommit:true = RED)
|
|
5275
|
+
fs.symlinkSync(outsideDir, linkPathA, linkType);
|
|
5276
|
+
writeFile(dir, '.gitignore', 'linked-out/\n');
|
|
5277
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5278
|
+
+ '<task id="T06" status="done"><action>symlink 边界任务</action>'
|
|
5279
|
+
+ '<write_files>linked-out/escape.md</write_files>'
|
|
5280
|
+
+ '<verify>node --check allowed.js</verify></task>\n');
|
|
5281
|
+
writeState(dir, baseState('subagent-execute'));
|
|
5282
|
+
const resLink = runHandoff(['request', 'T06', 'symlink slice'], dir);
|
|
5283
|
+
assertExit(resLink, 0);
|
|
5284
|
+
const stLink = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5285
|
+
const reqLink = stLink.evidence['subagent-execute'].handoffRequests.T06;
|
|
5286
|
+
if (!reqLink || reqLink.noCommit === true) {
|
|
5287
|
+
throw new Error('symlink/junction 祖先不得具备零提交资格(fail-closed),实际 ' + JSON.stringify(reqLink));
|
|
5288
|
+
}
|
|
5289
|
+
// ②f result 重验拒绝:先以真实目录建立资格,再把目录替换为 junction → 重验失败
|
|
5290
|
+
writeFile(dir, 'linked-out2/escape.md', 'inside\n');
|
|
5291
|
+
writeFile(dir, '.gitignore', 'linked-out2/\n');
|
|
5292
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
5293
|
+
+ '<task id="T07" status="done"><action>junction 重验边界任务</action>'
|
|
5294
|
+
+ '<write_files>linked-out2/escape.md</write_files>'
|
|
5295
|
+
+ '<verify>node --check allowed.js</verify></task>\n');
|
|
5296
|
+
fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID, '.skill-loads'), { recursive: true });
|
|
5297
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/subagent-execute-flow-comet-dev.json',
|
|
5298
|
+
JSON.stringify({ node: 'subagent-execute', skill: 'flow-comet-dev', protocol: '4-dev.md', at: '2026-08-01T00:00:00.000Z' }, null, 2) + '\n');
|
|
5299
|
+
const stReqLink = baseState('subagent-execute');
|
|
5300
|
+
stReqLink.newChange = true;
|
|
5301
|
+
writeState(dir, stReqLink);
|
|
5302
|
+
const resReqLink = runHandoff(['request', 'T07', 'junction revalidate slice'], dir);
|
|
5303
|
+
assertExit(resReqLink, 0);
|
|
5304
|
+
const stReqLinkAfter = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5305
|
+
if (stReqLinkAfter.evidence['subagent-execute'].handoffRequests.T07.noCommit !== true) {
|
|
5306
|
+
throw new Error('真实目录 + 命中忽略规则时 request 应取得 noCommit 资格,实际 '
|
|
5307
|
+
+ JSON.stringify(stReqLinkAfter.evidence['subagent-execute'].handoffRequests.T07));
|
|
5308
|
+
}
|
|
5309
|
+
fs.rmSync(linkPathB, { recursive: true, force: true });
|
|
5310
|
+
fs.symlinkSync(outsideDir, linkPathB, linkType);
|
|
5311
|
+
const resRevalLink = runHandoff(['result', 'T07', JSON.stringify({
|
|
5312
|
+
status: 'DONE', taskId: 'T07', noCommit: true,
|
|
5313
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
5314
|
+
redEvidence: { command: 'node --check allowed.js', output: 'ok' },
|
|
5315
|
+
greenEvidence: { command: 'node --check allowed.js', output: 'ok' },
|
|
5316
|
+
})], dir);
|
|
5317
|
+
assertExit(resRevalLink, 1);
|
|
5318
|
+
assertOut(resRevalLink, 'HANDOFF ERROR');
|
|
5319
|
+
assertOut(resRevalLink, 'noCommit=false');
|
|
5320
|
+
const stRevalLink = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5321
|
+
if (stRevalLink.evidence['subagent-execute'].handoffRequests.T07.noCommit !== false) {
|
|
5322
|
+
throw new Error('junction 逃逸重验失败应撤销 request.noCommit,实际 '
|
|
5323
|
+
+ JSON.stringify(stRevalLink.evidence['subagent-execute'].handoffRequests.T07));
|
|
5324
|
+
}
|
|
5325
|
+
// F6 审计:symlink/junction 逃逸撤销留 at/reason,类别与既有失败归类一致
|
|
5326
|
+
assertRevocationAudit(stRevalLink.evidence['subagent-execute'].handoffRequests.T07,
|
|
5327
|
+
'symlink-junction-escape', '158②f junction/symlink 重验');
|
|
5328
|
+
assertOut(resRevalLink, 'revokeReason=symlink-junction-escape');
|
|
5329
|
+
if (stRevalLink.evidence['subagent-execute'].handoffResult?.T07) {
|
|
5330
|
+
throw new Error('junction 逃逸重验失败不得落 handoffResult');
|
|
5331
|
+
}
|
|
5332
|
+
} finally {
|
|
5333
|
+
for (const linkPath of [linkPathA, linkPathB]) {
|
|
5334
|
+
try { fs.unlinkSync(linkPath); } catch { try { fs.rmdirSync(linkPath); } catch { /* 已移除 */ } }
|
|
5335
|
+
}
|
|
5336
|
+
fs.rmSync(outsideDir, { recursive: true, force: true });
|
|
5337
|
+
}
|
|
5338
|
+
// ③ 请求无资格(glob)+ 契约声称 noCommit → 仍完整提交文件子集校验(越界新 change BLOCK)
|
|
5339
|
+
const stIneligible = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
5340
|
+
stIneligible.newChange = true;
|
|
5341
|
+
writeState(dir, stIneligible);
|
|
5342
|
+
writeFile(dir, 'src/deep/rogue.js', 'export const deepRogue = 1;\n');
|
|
5343
|
+
g(['add', 'src/deep/rogue.js']);
|
|
5344
|
+
g(['commit', '-qm', 'deep rogue']);
|
|
5345
|
+
const deepHash = g(['rev-parse', 'HEAD']).stdout.trim();
|
|
5346
|
+
const resIneligible = runHandoff(['result', 'T02', JSON.stringify({
|
|
5347
|
+
status: 'DONE', taskId: 'T02', noCommit: true, commitHash: deepHash,
|
|
5348
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
5349
|
+
redEvidence: { command: 'node --check allowed.js', output: 'ok' },
|
|
5350
|
+
greenEvidence: { command: 'node --check allowed.js', output: 'ok' },
|
|
5351
|
+
})], dir);
|
|
5352
|
+
assertExit(resIneligible, 1);
|
|
5353
|
+
assertOut(resIneligible, '契约声明零提交但 write_files 非空');
|
|
5354
|
+
assertOut(resIneligible, '超出 writeFiles 范围');
|
|
4240
5355
|
},
|
|
4241
5356
|
},
|
|
4242
5357
|
|
|
@@ -4258,14 +5373,30 @@ const SCENARIOS = [
|
|
|
4258
5373
|
'- **完成时间**: 2026-08-20 10:00',
|
|
4259
5374
|
'- **AI 角色**: Dev',
|
|
4260
5375
|
].join('\n');
|
|
4261
|
-
const
|
|
4262
|
-
'## 做了什么\n\n实现 T01(TDD:先写失败场景再实现)。',
|
|
4263
|
-
'## 改动文件\n\n| 文件 | 性质 | 说明 |\n|---|---|---|\n| src/t1.mjs | 修改 | 实现 T01 |',
|
|
4264
|
-
'## verify 输出\n\n```\nnode --check src/t1.mjs\n```',
|
|
4265
|
-
'## 6 维自查\n\n- 功能: 通过(brooks-review 已跑)\n- 性能: 无影响\n- 安全: 无影响\n- 兼容: 通过\n- 可观测: 通过\n- 可维护: 通过',
|
|
4266
|
-
'##
|
|
4267
|
-
'##
|
|
4268
|
-
|
|
5376
|
+
const sectionText = {
|
|
5377
|
+
what: '## 做了什么\n\n实现 T01(TDD:先写失败场景再实现)。',
|
|
5378
|
+
files: '## 改动文件\n\n| 文件 | 性质 | 说明 |\n|---|---|---|\n| src/t1.mjs | 修改 | 实现 T01 |',
|
|
5379
|
+
verify: '## verify 输出\n\n```\nnode --check src/t1.mjs\n```',
|
|
5380
|
+
sixDim: '## 6 维自查\n\n- 功能: 通过(brooks-review 已跑)\n- 性能: 无影响\n- 安全: 无影响\n- 兼容: 通过\n- 可观测: 通过\n- 可维护: 通过',
|
|
5381
|
+
db: '## 数据库迁移\n\nN/A:本任务无 schema 变更。',
|
|
5382
|
+
bounds: '## 越界检查\n\n仅修改 src/t1.mjs,无越界。',
|
|
5383
|
+
breaking: '## 破坏性变更\n\nN/A:本任务不涉及破坏性变更。',
|
|
5384
|
+
deviation: '## 决策与偏离\n\n无偏离。',
|
|
5385
|
+
newWork: '## 是否触发新工作\n\n无。',
|
|
5386
|
+
done: '## 完成判定\n\n- TASK.md 中对应任务已勾选:是',
|
|
5387
|
+
method: '## 自检方法\n\nbrooks-review',
|
|
5388
|
+
};
|
|
5389
|
+
// 模板序 = flow-kit/templates/SUMMARY.md 全部 H2(含 5 个条件段);## 自检方法 不属骨架,
|
|
5390
|
+
// 单独按位置校核(文末或紧随 ## 越界检查两种合法位置)。
|
|
5391
|
+
const skeletonOrder = [sectionText.what, sectionText.files, sectionText.verify, sectionText.sixDim,
|
|
5392
|
+
sectionText.db, sectionText.bounds, sectionText.breaking, sectionText.deviation, sectionText.newWork, sectionText.done];
|
|
5393
|
+
const fullSections = [...skeletonOrder, sectionText.method]; // 自检方法在文末(合法位置一)
|
|
5394
|
+
const afterBoundsSections = [...skeletonOrder.slice(0, 6), sectionText.method, ...skeletonOrder.slice(6)]; // 紧随越界(合法位置二)
|
|
5395
|
+
const illegalSelfSections = [...skeletonOrder.slice(0, 4), sectionText.method, ...skeletonOrder.slice(4)]; // 自检方法夹在中间(非法)
|
|
5396
|
+
const missingTailSections = [...skeletonOrder.slice(0, 9), sectionText.method]; // 缺尾段 完成判定
|
|
5397
|
+
const outOfOrderSections = [
|
|
5398
|
+
...skeletonOrder.slice(0, 5), sectionText.bounds, sectionText.db, ...skeletonOrder.slice(6), sectionText.method,
|
|
5399
|
+
]; // 数据库迁移排到越界检查之后(段序偏离)
|
|
4269
5400
|
const compose = (title, order) =>
|
|
4270
5401
|
[title, '', header, '', '---', '', order.join('\n\n')].join('\n');
|
|
4271
5402
|
const setupExecute = (newChange) => {
|
|
@@ -4279,7 +5410,7 @@ const SCENARIOS = [
|
|
|
4279
5410
|
};
|
|
4280
5411
|
// ① 新 change:缺 `# SUMMARY:` 标题(段齐全)→ BLOCK
|
|
4281
5412
|
setupExecute(true);
|
|
4282
|
-
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# T01-SUMMARY',
|
|
5413
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# T01-SUMMARY', fullSections));
|
|
4283
5414
|
const res1 = runGuard(['exit', 'execute'], dir);
|
|
4284
5415
|
assertExit(res1, 1);
|
|
4285
5416
|
assertOut(res1, 'BLOCKED');
|
|
@@ -4290,34 +5421,108 @@ const SCENARIOS = [
|
|
|
4290
5421
|
'- **Task ID**: T01',
|
|
4291
5422
|
].join('\n');
|
|
4292
5423
|
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md',
|
|
4293
|
-
['# SUMMARY: T01 - 实现 T01', '', headerMissing, '', '---', '',
|
|
5424
|
+
['# SUMMARY: T01 - 实现 T01', '', headerMissing, '', '---', '', fullSections.join('\n\n')].join('\n'));
|
|
4294
5425
|
const res2 = runGuard(['exit', 'execute'], dir);
|
|
4295
5426
|
assertExit(res2, 1);
|
|
4296
5427
|
assertOut(res2, 'BLOCKED');
|
|
4297
5428
|
// ③ 新 change:段序乱(自检方法提前、做了什么滞后)→ BLOCK
|
|
4298
|
-
const scrambled = [
|
|
5429
|
+
const scrambled = [
|
|
5430
|
+
sectionText.verify, sectionText.bounds, sectionText.sixDim, sectionText.method,
|
|
5431
|
+
sectionText.what, sectionText.files, sectionText.db, sectionText.breaking,
|
|
5432
|
+
sectionText.deviation, sectionText.newWork, sectionText.done,
|
|
5433
|
+
];
|
|
4299
5434
|
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', scrambled));
|
|
4300
5435
|
const res3 = runGuard(['exit', 'execute'], dir);
|
|
4301
5436
|
assertExit(res3, 1);
|
|
4302
5437
|
assertOut(res3, 'BLOCKED');
|
|
4303
5438
|
// ④ 合法变体:大小写(# Summary: …)→ 通过
|
|
4304
5439
|
setupExecute(true);
|
|
4305
|
-
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# Summary: T01 - 实现 T01',
|
|
5440
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# Summary: T01 - 实现 T01', fullSections));
|
|
4306
5441
|
const res4 = runGuard(['exit', 'execute'], dir);
|
|
4307
5442
|
assertExit(res4, 0);
|
|
4308
5443
|
assertOut(res4, 'ALL CHECKS PASSED');
|
|
4309
5444
|
// ⑤ 合法变体:括号后缀 → 通过
|
|
4310
5445
|
setupExecute(true);
|
|
4311
|
-
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01(含说明括号)',
|
|
5446
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01(含说明括号)', fullSections));
|
|
4312
5447
|
const res5 = runGuard(['exit', 'execute'], dir);
|
|
4313
5448
|
assertExit(res5, 0);
|
|
4314
5449
|
assertOut(res5, 'ALL CHECKS PASSED');
|
|
4315
5450
|
// ⑥ 旧 change:缺标题 → WARN 渐进不阻断
|
|
4316
5451
|
setupExecute(false);
|
|
4317
|
-
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# T01-SUMMARY',
|
|
5452
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# T01-SUMMARY', fullSections));
|
|
4318
5453
|
const res6 = runGuard(['exit', 'execute'], dir);
|
|
4319
5454
|
assertExit(res6, 0);
|
|
4320
5455
|
assertOut(res6, 'WARN');
|
|
5456
|
+
// ⑦ 起:写入 SUMMARY 模板副本——M1 全骨架硬阻断只在 runRoot 内存在
|
|
5457
|
+
// flow-kit/templates/SUMMARY.md 时生效(模板缺失仅内置骨架提示,不新增 BLOCK)。
|
|
5458
|
+
// 维护者工作副本含 vendored flow-kit → 复制真实模板;CI 全新检出 flow-kit 被
|
|
5459
|
+
// .gitignore 排除(不可分发)→ 用与真实模板 H2 逐字对齐的内置镜像(skeleton 派生结果
|
|
5460
|
+
// 等价),保证硬阻断锚在两级载体都可执行、不静默跳过。
|
|
5461
|
+
const realSummaryTemplate = path.join(REPO_ROOT, 'flow-kit', 'templates', 'SUMMARY.md');
|
|
5462
|
+
const summaryTemplateFixture = fs.existsSync(realSummaryTemplate)
|
|
5463
|
+
? fs.readFileSync(realSummaryTemplate, 'utf8')
|
|
5464
|
+
: [
|
|
5465
|
+
'# SUMMARY: <T01 - 任务名>',
|
|
5466
|
+
'',
|
|
5467
|
+
'## 做了什么(一段话)',
|
|
5468
|
+
'',
|
|
5469
|
+
'## 改动文件',
|
|
5470
|
+
'',
|
|
5471
|
+
'## verify 输出(必填)',
|
|
5472
|
+
'',
|
|
5473
|
+
'## 6 维自查(生产代码改动必填 · 来自 4-dev 步骤 4)',
|
|
5474
|
+
'',
|
|
5475
|
+
'## 数据库迁移(涉及 schema 变更必填 · 来自 4-dev 步骤 1.7 / R4.5)',
|
|
5476
|
+
'',
|
|
5477
|
+
'## 越界检查(必填 · 来自 4-dev 步骤 5 / R6.5 / B3 老项目护栏)',
|
|
5478
|
+
'',
|
|
5479
|
+
'## 破坏性变更(涉及破坏性改动必填 · 来自 4-dev 步骤 1.8 / R4.6 / B4 老项目护栏)',
|
|
5480
|
+
'',
|
|
5481
|
+
'## 决策与偏离(如有)',
|
|
5482
|
+
'',
|
|
5483
|
+
'## 是否触发新工作',
|
|
5484
|
+
'',
|
|
5485
|
+
'## 完成判定',
|
|
5486
|
+
'',
|
|
5487
|
+
].join('\n');
|
|
5488
|
+
writeFile(dir, 'flow-kit/templates/SUMMARY.md', summaryTemplateFixture);
|
|
5489
|
+
// ⑦ 新 change 缺尾段(完成判定)→ BLOCK + 缺段 + 「补 N/A 段」恢复指引
|
|
5490
|
+
setupExecute(true);
|
|
5491
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', missingTailSections));
|
|
5492
|
+
const res7 = runGuard(['exit', 'execute'], dir);
|
|
5493
|
+
assertExit(res7, 1);
|
|
5494
|
+
assertOut(res7, 'BLOCKED');
|
|
5495
|
+
assertOut(res7, '完成判定');
|
|
5496
|
+
assertOut(res7, 'N/A');
|
|
5497
|
+
// ⑧ 段序偏离(数据库迁移排到越界检查之后)→ BLOCK + 段序 + 缺段点可定位
|
|
5498
|
+
setupExecute(true);
|
|
5499
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', outOfOrderSections));
|
|
5500
|
+
const res8 = runGuard(['exit', 'execute'], dir);
|
|
5501
|
+
assertExit(res8, 1);
|
|
5502
|
+
assertOut(res8, 'BLOCKED');
|
|
5503
|
+
assertOut(res8, '段序');
|
|
5504
|
+
assertOut(res8, '数据库迁移');
|
|
5505
|
+
// ⑨ 合法位置一:## 自检方法 位于文末 → 通过(真实模板在场)
|
|
5506
|
+
setupExecute(true);
|
|
5507
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', fullSections));
|
|
5508
|
+
const res9 = runGuard(['exit', 'execute'], dir);
|
|
5509
|
+
assertExit(res9, 0);
|
|
5510
|
+
assertOut(res9, 'ALL CHECKS PASSED');
|
|
5511
|
+
assertNotOut(res9, 'BLOCKED');
|
|
5512
|
+
// ⑩ 合法位置二:## 自检方法 紧随 ## 越界检查 之后 → 通过(真实模板在场)
|
|
5513
|
+
setupExecute(true);
|
|
5514
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', afterBoundsSections));
|
|
5515
|
+
const res10 = runGuard(['exit', 'execute'], dir);
|
|
5516
|
+
assertExit(res10, 0);
|
|
5517
|
+
assertOut(res10, 'ALL CHECKS PASSED');
|
|
5518
|
+
assertNotOut(res10, 'BLOCKED');
|
|
5519
|
+
// ⑪ 自检方法位置非法(夹在 6 维自查与数据库迁移之间)→ BLOCK
|
|
5520
|
+
setupExecute(true);
|
|
5521
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', compose('# SUMMARY: T01 - 实现 T01', illegalSelfSections));
|
|
5522
|
+
const res11 = runGuard(['exit', 'execute'], dir);
|
|
5523
|
+
assertExit(res11, 1);
|
|
5524
|
+
assertOut(res11, 'BLOCKED');
|
|
5525
|
+
assertOut(res11, '自检方法');
|
|
4321
5526
|
},
|
|
4322
5527
|
},
|
|
4323
5528
|
|
|
@@ -4438,16 +5643,285 @@ const SCENARIOS = [
|
|
|
4438
5643
|
const resOld = runState(['record', 'plan', '{"summary":"plan done"}'], dir, env);
|
|
4439
5644
|
assertExit(resOld, 0);
|
|
4440
5645
|
assertOut(resOld, 'WARN');
|
|
4441
|
-
},
|
|
4442
|
-
},
|
|
4443
5646
|
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
5647
|
+
// ===== M-02 request 时刻归属门禁(AC-2 不误伤面)=====
|
|
5648
|
+
// 正确节点成功 / 串行错配 BLOCK / 未 entry WARN / done 与显式 write-files 旁路 /
|
|
5649
|
+
// 协议无对应 enabled 节点跳过 / 协议不可读可见 WARN 后放行(不静默)。归属门禁位于
|
|
5650
|
+
// 技能声明门之后——新 change 夹具必须放入本节点声明标记,否则先被技能门 BLOCK,
|
|
5651
|
+
// 测不到归属门禁本身。
|
|
5652
|
+
const writeMarker = (node) => {
|
|
5653
|
+
fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID, '.skill-loads'), { recursive: true });
|
|
5654
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/' + node + '-flow-comet-dev.json',
|
|
5655
|
+
JSON.stringify({ node, skill: 'flow-comet-dev', protocol: '4-dev.md', at: '2026-08-01T00:00:00.000Z' }, null, 2) + '\n');
|
|
5656
|
+
};
|
|
5657
|
+
const taskXml = (id, attrs, writeFiles) =>
|
|
5658
|
+
'# TASK\n\n<task id="' + id + '" ' + attrs + '><action>实现 ' + id + '</action>'
|
|
5659
|
+
+ '<write_files>' + writeFiles + '</write_files><verify>node --check src/x.mjs</verify></task>\n';
|
|
5660
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
5661
|
+
// ④ 正确节点(subagent-execute)+ pending 并行 → 成功落库(不误伤)
|
|
5662
|
+
writeMarker('subagent-execute');
|
|
5663
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P01', 'parallel="true" status="pending"', 'src/p01.mjs'));
|
|
5664
|
+
const stOk = baseState('subagent-execute');
|
|
5665
|
+
stOk.newChange = true;
|
|
5666
|
+
stOk.enteredNodes = ['subagent-execute'];
|
|
5667
|
+
writeState(dir, stOk);
|
|
5668
|
+
const resOk = runHandoff(['request', 'P01', 'delegate'], dir, env);
|
|
5669
|
+
assertExit(resOk, 0);
|
|
5670
|
+
assertOut(resOk, 'HANDOFF REQUEST: P01');
|
|
5671
|
+
const recOk = readScenarioState(dir).evidence?.['subagent-execute']?.handoffRequests?.P01;
|
|
5672
|
+
if (!recOk) throw new Error('正确节点并行 pending 请求应成功落库,实际 ' + JSON.stringify(recOk));
|
|
5673
|
+
// ⑤ 串行 pending 在 subagent-execute 请求(目标 execute 不匹配)→ BLOCK + 字节零改写
|
|
5674
|
+
writeMarker('execute');
|
|
5675
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('S01', 'parallel="false" status="pending"', 'src/s01.mjs'));
|
|
5676
|
+
const stSerial = baseState('subagent-execute');
|
|
5677
|
+
stSerial.newChange = true;
|
|
5678
|
+
stSerial.enteredNodes = ['subagent-execute'];
|
|
5679
|
+
writeState(dir, stSerial);
|
|
5680
|
+
const beforeSerial = fs.readFileSync(statePath, 'utf8');
|
|
5681
|
+
const resSerial = runHandoff(['request', 'S01', 'serial slice'], dir, env);
|
|
5682
|
+
assertExit(resSerial, 1);
|
|
5683
|
+
assertOut(resSerial, 'BLOCKED: 任务 S01(串行 pending)应归属节点 execute');
|
|
5684
|
+
assertOut(resSerial, 'entry execute');
|
|
5685
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeSerial) {
|
|
5686
|
+
throw new Error('串行错配 BLOCK 必须 state 字节零改写');
|
|
5687
|
+
}
|
|
5688
|
+
// ⑥ 正确节点但尚未 entry → 仅 WARN + 照常落库
|
|
5689
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('S02', 'parallel="false" status="pending"', 'src/s02.mjs'));
|
|
5690
|
+
const stNotEntered = baseState('execute');
|
|
5691
|
+
stNotEntered.newChange = true; // enteredNodes 缺 execute
|
|
5692
|
+
writeState(dir, stNotEntered);
|
|
5693
|
+
const resNotEntered = runHandoff(['request', 'S02', 'serial slice'], dir, env);
|
|
5694
|
+
assertExit(resNotEntered, 0);
|
|
5695
|
+
assertOut(resNotEntered, 'WARN: 任务 S02 的归属节点 execute 与原始 currentNode 一致');
|
|
5696
|
+
assertOut(resNotEntered, '尚未 entry');
|
|
5697
|
+
assertOut(resNotEntered, 'HANDOFF REQUEST: S02');
|
|
5698
|
+
// ⑦ done 任务补录(非 pending)→ 归属门禁跳过,不误伤
|
|
5699
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('D01', 'parallel="true" status="done"', 'src/d01.mjs'));
|
|
5700
|
+
const stDone = baseState('execute');
|
|
5701
|
+
stDone.newChange = true;
|
|
5702
|
+
stDone.enteredNodes = ['execute'];
|
|
5703
|
+
writeState(dir, stDone);
|
|
5704
|
+
const resDone = runHandoff(['request', 'D01', 'backfill'], dir, env);
|
|
5705
|
+
assertExit(resDone, 0);
|
|
5706
|
+
assertNotOut(resDone, 'BLOCKED');
|
|
5707
|
+
assertOut(resDone, 'HANDOFF REQUEST: D01');
|
|
5708
|
+
// ⑧ 显式 --write-files 且 TASK 无匹配任务 → 可见 WARN + 跳过归属门禁(不误伤)
|
|
5709
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n<!-- 无匹配任务块 -->\n');
|
|
5710
|
+
const stExplicit = baseState('execute');
|
|
5711
|
+
stExplicit.newChange = true;
|
|
5712
|
+
stExplicit.enteredNodes = ['execute'];
|
|
5713
|
+
writeState(dir, stExplicit);
|
|
5714
|
+
const resExplicit = runHandoff(['request', 'X01', 'explicit slice', '--write-files', 'src/x01.mjs'], dir, env);
|
|
5715
|
+
assertExit(resExplicit, 0);
|
|
5716
|
+
assertOut(resExplicit, '显式 --write-files 且 TASK.md 无匹配任务 X01');
|
|
5717
|
+
assertOut(resExplicit, 'HANDOFF REQUEST: X01');
|
|
5718
|
+
assertNotOut(resExplicit, 'BLOCKED');
|
|
5719
|
+
// ⑨ 协议无对应 enabled 节点 → 跳过归属门禁(删除 subagent-execute 节点):驻留 execute
|
|
5720
|
+
// 但任务为并行 pending——若实现不做协议感知会误判目标 subagent-execute ≠ execute 而 BLOCK
|
|
5721
|
+
writeMarker('execute');
|
|
5722
|
+
const proto = JSON.parse(fs.readFileSync(path.join(dir, 'reference', 'workflow-protocol.json'), 'utf8'));
|
|
5723
|
+
const noSubProto = { ...proto, nodes: proto.nodes.filter((n) => n.id !== 'subagent-execute') };
|
|
5724
|
+
writeFile(dir, 'reference/protocol-nosub.json', JSON.stringify(noSubProto, null, 2) + '\n');
|
|
5725
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P02', 'parallel="true" status="pending"', 'src/p02.mjs'));
|
|
5726
|
+
const stNoSub = baseState('execute');
|
|
5727
|
+
stNoSub.newChange = true;
|
|
5728
|
+
stNoSub.enteredNodes = ['execute'];
|
|
5729
|
+
writeState(dir, stNoSub);
|
|
5730
|
+
const resNoSub = runHandoff(['request', 'P02', 'no-sub protocol'], dir,
|
|
5731
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'protocol-nosub.json') });
|
|
5732
|
+
assertExit(resNoSub, 0);
|
|
5733
|
+
assertNotOut(resNoSub, 'BLOCKED');
|
|
5734
|
+
assertNotOut(resNoSub, '本次未执行归属校验'); // 协议可读且无对应 enabled 节点 → 跳过校验,不产生归属 WARN
|
|
5735
|
+
assertOut(resNoSub, 'HANDOFF REQUEST: P02');
|
|
5736
|
+
// ⑩ 节点被 disabled → 同样跳过归属门禁
|
|
5737
|
+
const disabledProto = { ...proto, nodes: proto.nodes.map((n) => (n.id === 'subagent-execute' ? { ...n, disabled: true } : n)) };
|
|
5738
|
+
writeFile(dir, 'reference/protocol-disabled.json', JSON.stringify(disabledProto, null, 2) + '\n');
|
|
5739
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P03', 'parallel="true" status="pending"', 'src/p03.mjs'));
|
|
5740
|
+
const stDisabled = baseState('execute');
|
|
5741
|
+
stDisabled.newChange = true;
|
|
5742
|
+
stDisabled.enteredNodes = ['execute'];
|
|
5743
|
+
writeState(dir, stDisabled);
|
|
5744
|
+
const resDisabled = runHandoff(['request', 'P03', 'disabled protocol'], dir,
|
|
5745
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'protocol-disabled.json') });
|
|
5746
|
+
assertExit(resDisabled, 0);
|
|
5747
|
+
assertNotOut(resDisabled, 'BLOCKED');
|
|
5748
|
+
assertNotOut(resDisabled, '本次未执行归属校验'); // disabled 节点语义与缺节点一致 → 跳过校验且无归属 WARN
|
|
5749
|
+
assertOut(resDisabled, 'HANDOFF REQUEST: P03');
|
|
5750
|
+
// ⑪ pending 并行任务依赖未满足 → BLOCK 指引与 next 实际输出一致(next 按串行消化输出
|
|
5751
|
+
// execute);依赖满足后按 next 输出进入委托节点,request 恢复成功——无 entry 死路。
|
|
5752
|
+
writeIntakeArtifacts(dir);
|
|
5753
|
+
const unmetDepsTask =
|
|
5754
|
+
'<task id="S03" parallel="false" status="pending"><action>实现 S03</action><write_files>src/s03.mjs</write_files><verify>node --check src/s03.mjs</verify></task>\n' +
|
|
5755
|
+
'<task id="P04" parallel="true" status="pending"><action>实现 P04</action><write_files>src/p04.mjs</write_files><verify>node --check src/p04.mjs</verify><depends_on>S03</depends_on></task>\n';
|
|
5756
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + unmetDepsTask);
|
|
5757
|
+
const stUnmet = baseState('execute');
|
|
5758
|
+
stUnmet.newChange = true;
|
|
5759
|
+
stUnmet.enteredNodes = ['execute'];
|
|
5760
|
+
stUnmet.completedNodes = ['open', 'design', 'plan'];
|
|
5761
|
+
stUnmet.evidence = { plan: { summary: 'plan done' } };
|
|
5762
|
+
writeState(dir, stUnmet);
|
|
5763
|
+
const unmetBytesBefore = fs.readFileSync(statePath, 'utf8');
|
|
5764
|
+
const resUnmet = runHandoff(['request', 'P04', 'parallel slice with unmet deps'], dir, env);
|
|
5765
|
+
assertExit(resUnmet, 1);
|
|
5766
|
+
assertOut(resUnmet, 'BLOCKED: 任务 P04(并行 pending)当前不可委托:依赖未满足');
|
|
5767
|
+
assertOut(resUnmet, '未完成: S03');
|
|
5768
|
+
assertOut(resUnmet, 'workflow-state next');
|
|
5769
|
+
assertOut(resUnmet, '若输出 execute 表示依赖未满足');
|
|
5770
|
+
assertOut(resUnmet, '待任务变为可委托');
|
|
5771
|
+
assertNotOut(resUnmet, 'entry subagent-execute');
|
|
5772
|
+
if (fs.readFileSync(statePath, 'utf8') !== unmetBytesBefore) {
|
|
5773
|
+
throw new Error('依赖未满足 BLOCK 必须 state 字节零改写');
|
|
5774
|
+
}
|
|
5775
|
+
if (readScenarioState(dir).evidence?.['subagent-execute']?.handoffRequests?.P04) {
|
|
5776
|
+
throw new Error('依赖未满足 BLOCK 不得落 handoffRequests');
|
|
5777
|
+
}
|
|
5778
|
+
const resUnmetNext = runState(['next'], dir, env);
|
|
5779
|
+
assertExit(resUnmetNext, 0);
|
|
5780
|
+
if (!/^NODE: execute$/m.test(resUnmetNext.output)) {
|
|
5781
|
+
throw new Error('依赖未满足时 next 应输出 execute:\n' + resUnmetNext.output);
|
|
5782
|
+
}
|
|
5783
|
+
// 依赖满足:串行任务消化完成后 next 输出 subagent-execute;按输出 entry 后 request 成功
|
|
5784
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
5785
|
+
'# TASK\n\n<task id="S03" parallel="false" status="done"><action>实现 S03</action><write_files>src/s03.mjs</write_files><verify>node --check src/s03.mjs</verify></task>\n'
|
|
5786
|
+
+ '<task id="P04" parallel="true" status="pending"><action>实现 P04</action><write_files>src/p04.mjs</write_files><verify>node --check src/p04.mjs</verify><depends_on>S03</depends_on></task>\n');
|
|
5787
|
+
const afterSerial = readScenarioState(dir);
|
|
5788
|
+
afterSerial.completedNodes = [...new Set([...(afterSerial.completedNodes || []), 'execute'])];
|
|
5789
|
+
afterSerial.evidence = { ...(afterSerial.evidence || {}), execute: { summary: 'serial digest done' } };
|
|
5790
|
+
writeState(dir, afterSerial);
|
|
5791
|
+
const resDelegableNext = runState(['next'], dir, env);
|
|
5792
|
+
assertExit(resDelegableNext, 0);
|
|
5793
|
+
if (!/^NODE: subagent-execute$/m.test(resDelegableNext.output)) {
|
|
5794
|
+
throw new Error('依赖满足后 next 应输出 subagent-execute:\n' + resDelegableNext.output);
|
|
5795
|
+
}
|
|
5796
|
+
if (readScenarioState(dir).currentNode !== 'subagent-execute') {
|
|
5797
|
+
throw new Error('依赖满足后 next 应把工作归属推到 subagent-execute');
|
|
5798
|
+
}
|
|
5799
|
+
writeMarker('subagent-execute');
|
|
5800
|
+
assertExit(runGuard(['entry', 'subagent-execute'], dir, env), 0);
|
|
5801
|
+
const resRecovered = runHandoff(['request', 'P04', 'now delegable'], dir, env);
|
|
5802
|
+
assertExit(resRecovered, 0);
|
|
5803
|
+
assertOut(resRecovered, 'HANDOFF REQUEST: P04');
|
|
5804
|
+
// ⑫ 协议不可读(默认解析指向 runRoot 外的内置协议,受保护读取拒绝)→ 可见 WARN(原因 +
|
|
5805
|
+
// 「本次未执行归属校验」)+ 放行语义不变。修复前此形态静默 skip(无 WARN、照常落库)=假绿。
|
|
5806
|
+
writeMarker('execute');
|
|
5807
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P05', 'parallel="true" status="pending"', 'src/p05.mjs'));
|
|
5808
|
+
const stNoProtocol = baseState('execute');
|
|
5809
|
+
stNoProtocol.newChange = true;
|
|
5810
|
+
stNoProtocol.enteredNodes = ['execute'];
|
|
5811
|
+
writeState(dir, stNoProtocol);
|
|
5812
|
+
const resNoProtocol = runHandoff(['request', 'P05', 'no protocol'], dir, { FLOW_COMET_PROTOCOL: '' });
|
|
5813
|
+
assertExit(resNoProtocol, 0);
|
|
5814
|
+
assertOut(resNoProtocol, 'WARN:');
|
|
5815
|
+
assertOut(resNoProtocol, '本次未执行归属校验');
|
|
5816
|
+
assertOut(resNoProtocol, '协议路径不在当前项目根内');
|
|
5817
|
+
assertOut(resNoProtocol, 'HANDOFF REQUEST: P05');
|
|
5818
|
+
assertNotOut(resNoProtocol, 'BLOCKED');
|
|
5819
|
+
if (!readScenarioState(dir).evidence?.['subagent-execute']?.handoffRequests?.P05) {
|
|
5820
|
+
throw new Error('协议不可读应可见 WARN 后照常落库(放行语义不变),实际未落请求记录');
|
|
5821
|
+
}
|
|
5822
|
+
// ⑬ 协议文件缺失(显式指向 runRoot 内不存在的路径)→ 同类可见 WARN(原因=文件不存在)+ 放行
|
|
5823
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P06', 'parallel="true" status="pending"', 'src/p06.mjs'));
|
|
5824
|
+
const stProtocolMissing = baseState('execute');
|
|
5825
|
+
stProtocolMissing.newChange = true;
|
|
5826
|
+
stProtocolMissing.enteredNodes = ['execute'];
|
|
5827
|
+
writeState(dir, stProtocolMissing);
|
|
5828
|
+
const resProtocolMissing = runHandoff(['request', 'P06', 'missing protocol'], dir,
|
|
5829
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'protocol-missing.json') });
|
|
5830
|
+
assertExit(resProtocolMissing, 0);
|
|
5831
|
+
assertOut(resProtocolMissing, 'WARN:');
|
|
5832
|
+
assertOut(resProtocolMissing, '本次未执行归属校验');
|
|
5833
|
+
assertOut(resProtocolMissing, '协议文件不存在');
|
|
5834
|
+
assertOut(resProtocolMissing, 'HANDOFF REQUEST: P06');
|
|
5835
|
+
assertNotOut(resProtocolMissing, 'BLOCKED');
|
|
5836
|
+
// 旧 change 同形态 → 同样仅可见 WARN + 照常落库(协议不可读不区分新旧 change 新增硬 BLOCK)
|
|
5837
|
+
const stProtocolMissingOld = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
5838
|
+
delete stProtocolMissingOld.newChange;
|
|
5839
|
+
writeState(dir, stProtocolMissingOld);
|
|
5840
|
+
const resProtocolMissingOld = runHandoff(['request', 'P06', 'missing protocol legacy'], dir,
|
|
5841
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'protocol-missing.json') });
|
|
5842
|
+
assertExit(resProtocolMissingOld, 0);
|
|
5843
|
+
assertOut(resProtocolMissingOld, '本次未执行归属校验');
|
|
5844
|
+
assertOut(resProtocolMissingOld, 'HANDOFF REQUEST: P06');
|
|
5845
|
+
assertNotOut(resProtocolMissingOld, 'BLOCKED');
|
|
5846
|
+
// ⑭ 协议解析失败(非法 JSON 文件)→ 同类可见 WARN(原因=不是合法 JSON)+ 放行
|
|
5847
|
+
writeFile(dir, 'reference/protocol-broken.json', '{ not-json\n');
|
|
5848
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskXml('P07', 'parallel="true" status="pending"', 'src/p07.mjs'));
|
|
5849
|
+
const stProtocolBroken = baseState('execute');
|
|
5850
|
+
stProtocolBroken.newChange = true;
|
|
5851
|
+
stProtocolBroken.enteredNodes = ['execute'];
|
|
5852
|
+
writeState(dir, stProtocolBroken);
|
|
5853
|
+
const resProtocolBroken = runHandoff(['request', 'P07', 'broken protocol'], dir,
|
|
5854
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'protocol-broken.json') });
|
|
5855
|
+
assertExit(resProtocolBroken, 0);
|
|
5856
|
+
assertOut(resProtocolBroken, 'WARN:');
|
|
5857
|
+
assertOut(resProtocolBroken, '本次未执行归属校验');
|
|
5858
|
+
assertOut(resProtocolBroken, '不是合法 JSON');
|
|
5859
|
+
assertOut(resProtocolBroken, 'HANDOFF REQUEST: P07');
|
|
5860
|
+
assertNotOut(resProtocolBroken, 'BLOCKED');
|
|
5861
|
+
// ⑮ state 协议绑定:init --protocol 指向自定义协议(无 execute / subagent-execute
|
|
5862
|
+
// 节点)→ state.protocolPath 持久化;后续 request 按该协议判定,串行 pending 无对应
|
|
5863
|
+
// enabled 委托节点 → 跳过归属校验。若协议来源未持久化,env 指向内置协议会把串行
|
|
5864
|
+
// pending 误判为归属 execute → BLOCK(修复前 RED)。
|
|
5865
|
+
const boundChange = 'bound-proto';
|
|
5866
|
+
const boundProtocol = {
|
|
5867
|
+
...proto,
|
|
5868
|
+
nodes: proto.nodes.filter((n) => n.id !== 'execute' && n.id !== 'subagent-execute'),
|
|
5869
|
+
};
|
|
5870
|
+
writeFile(dir, 'reference/protocol-bound.json', JSON.stringify(boundProtocol, null, 2) + '\n');
|
|
5871
|
+
assertExit(runState(['init', boundChange, '--init-skip', '--protocol', 'reference/protocol-bound.json'], dir), 0);
|
|
5872
|
+
writeFile(dir, '.specs/' + boundChange + '/TASK.md', taskXml('B01', 'parallel="false" status="pending"', 'src/b01.mjs'));
|
|
5873
|
+
const resBound = runHandoff(['request', 'B01', 'bound protocol serial'], dir,
|
|
5874
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') });
|
|
5875
|
+
assertExit(resBound, 0);
|
|
5876
|
+
assertOut(resBound, 'HANDOFF REQUEST: B01');
|
|
5877
|
+
assertNotOut(resBound, 'BLOCKED');
|
|
5878
|
+
assertNotOut(resBound, '本次未执行归属校验'); // 协议可读且无对应 enabled 节点 → 跳过校验,不产生不可读 WARN
|
|
5879
|
+
const boundState = readScenarioState(dir);
|
|
5880
|
+
if (boundState.protocolPath !== 'reference/protocol-bound.json') {
|
|
5881
|
+
throw new Error('init 应把解析后的协议路径持久化为项目根相对形态,实际: ' + JSON.stringify(boundState.protocolPath));
|
|
5882
|
+
}
|
|
5883
|
+
if (!boundState.evidence?.['subagent-execute']?.handoffRequests?.B01) {
|
|
5884
|
+
throw new Error('state 绑定协议下的 request 应照常落库');
|
|
5885
|
+
}
|
|
5886
|
+
// ⑯ state.protocolPath 存在但不可读 → 不回退 env/默认(回退会按内置协议把串行 pending
|
|
5887
|
+
// 误判为归属 execute → BLOCK);可见 WARN 说明来源 +「本次未执行归属校验」后放行。
|
|
5888
|
+
const boundMissingState = readScenarioState(dir);
|
|
5889
|
+
boundMissingState.protocolPath = 'reference/protocol-bound-missing.json';
|
|
5890
|
+
writeState(dir, boundMissingState);
|
|
5891
|
+
writeFile(dir, '.specs/' + boundChange + '/TASK.md', taskXml('B02', 'parallel="false" status="pending"', 'src/b02.mjs'));
|
|
5892
|
+
const resBoundMissing = runHandoff(['request', 'B02', 'bound protocol unreadable'], dir,
|
|
5893
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') });
|
|
5894
|
+
assertExit(resBoundMissing, 0);
|
|
5895
|
+
assertOut(resBoundMissing, 'WARN:');
|
|
5896
|
+
assertOut(resBoundMissing, '本次未执行归属校验');
|
|
5897
|
+
assertOut(resBoundMissing, 'state.protocolPath');
|
|
5898
|
+
assertOut(resBoundMissing, '协议文件不存在');
|
|
5899
|
+
assertOut(resBoundMissing, 'HANDOFF REQUEST: B02');
|
|
5900
|
+
assertNotOut(resBoundMissing, 'BLOCKED');
|
|
5901
|
+
if (!readScenarioState(dir).evidence?.['subagent-execute']?.handoffRequests?.B02) {
|
|
5902
|
+
throw new Error('state.protocolPath 不可读应可见 WARN 后照常落库');
|
|
5903
|
+
}
|
|
5904
|
+
// ⑰ 旧 state(无 protocolPath 字段)→ env/默认回退不回归:env 指向内置协议时,串行
|
|
5905
|
+
// pending 在 open 节点发起仍按内置协议归属 execute → BLOCK(缺字段 = 渐进兼容路径)。
|
|
5906
|
+
const legacyBoundState = readScenarioState(dir);
|
|
5907
|
+
delete legacyBoundState.protocolPath;
|
|
5908
|
+
legacyBoundState.currentNode = 'open';
|
|
5909
|
+
writeState(dir, legacyBoundState);
|
|
5910
|
+
writeFile(dir, '.specs/' + boundChange + '/TASK.md', taskXml('B03', 'parallel="false" status="pending"', 'src/b03.mjs'));
|
|
5911
|
+
const resLegacyBound = runHandoff(['request', 'B03', 'legacy state no binding'], dir,
|
|
5912
|
+
{ FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') });
|
|
5913
|
+
assertExit(resLegacyBound, 1);
|
|
5914
|
+
assertOut(resLegacyBound, 'BLOCKED: 任务 B03(串行 pending)应归属节点 execute');
|
|
5915
|
+
},
|
|
5916
|
+
},
|
|
5917
|
+
|
|
5918
|
+
// 163: next / guard entry 输出点名加载(设计语义 / AC-17)——`workflow-state next` 与
|
|
5919
|
+
// `workflow-guard entry` 输出应含 `LOAD SKILL: <skill>(用 Skill 工具,禁止跳过)`。
|
|
5920
|
+
// 当前 printNext / entry 无该行 → 预期 RED。
|
|
5921
|
+
{
|
|
5922
|
+
name: '163 next / entry 输出点名 LOAD SKILL:用 Skill 工具,禁止跳过',
|
|
5923
|
+
run: (dir) => {
|
|
5924
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
4451
5925
|
// ① next:open 节点 → 输出点名 flow-comet-open
|
|
4452
5926
|
fs.mkdirSync(path.join(dir, '.specs', CHANGE_ID), { recursive: true });
|
|
4453
5927
|
const st = baseState('open');
|
|
@@ -4645,6 +6119,8 @@ const SCENARIOS = [
|
|
|
4645
6119
|
// 170: 零提交旁路收紧——noCommit 结果若携带 tracked 提交:新 change BLOCKED / 旧 change
|
|
4646
6120
|
// HANDOFF WARN;空提交(--allow-empty)正例通过。锚定 AC-1(防「空 write_files 声明」
|
|
4647
6121
|
// 成为携带任意提交的逃逸口——bot 评审 Major)。
|
|
6122
|
+
// ④ F-6 请求侧补 tracked 负例:write_files 路径虽被 .gitignore 命中、但该路径已 tracked
|
|
6123
|
+
//(index-aware check-ignore 退出 1)→ 不记 noCommit(tracked 提交仍走完整子集校验)。
|
|
4648
6124
|
{
|
|
4649
6125
|
name: '170 零提交旁路:携带 tracked 提交新 BLOCK / 旧 WARN / 空提交通过',
|
|
4650
6126
|
run: (dir) => {
|
|
@@ -4686,6 +6162,84 @@ const SCENARIOS = [
|
|
|
4686
6162
|
const res3 = runHandoff(['result', 'T11', payload('T11', hashEmpty)], dir);
|
|
4687
6163
|
assertExit(res3, 0);
|
|
4688
6164
|
assertOut(res3, '提交为空,校验通过');
|
|
6165
|
+
// ④ F-6 请求侧 tracked 负例:路径被 .gitignore 命中但已被 index 跟踪 → check-ignore 退出 1
|
|
6166
|
+
writeFile(dir, '.gitignore', '.specs/\n');
|
|
6167
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/tracked.md', 'tracked\n');
|
|
6168
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'add', '-f', '.specs/' + CHANGE_ID + '/tracked.md');
|
|
6169
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'track ignored file');
|
|
6170
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
6171
|
+
+ '<task id="T12" status="done"><action>边界任务</action>'
|
|
6172
|
+
+ '<write_files>.specs/' + CHANGE_ID + '/tracked.md</write_files>'
|
|
6173
|
+
+ '<verify>node --check src/x.js</verify></task>\n');
|
|
6174
|
+
writeState(dir, baseState('subagent-execute'));
|
|
6175
|
+
const resReqTracked = runHandoff(['request', 'T12', 'tracked path slice'], dir);
|
|
6176
|
+
assertExit(resReqTracked, 0);
|
|
6177
|
+
const stTracked = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
6178
|
+
const reqTracked = stTracked.evidence['subagent-execute'].handoffRequests.T12;
|
|
6179
|
+
if (!reqTracked || reqTracked.noCommit === true) {
|
|
6180
|
+
throw new Error('tracked 文件路径不应具备零提交资格,实际 ' + JSON.stringify(reqTracked));
|
|
6181
|
+
}
|
|
6182
|
+
// ④b m-13 result 重验:request 时路径不存在(记资格),随后路径被强制跟踪 →
|
|
6183
|
+
// result 重验失败撤销 noCommit,失败类别 = became-tracked,且留 at/reason 审计。
|
|
6184
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n'
|
|
6185
|
+
+ '<task id="T15" status="done"><action>tracked-after-request 边界任务</action>'
|
|
6186
|
+
+ '<write_files>.specs/' + CHANGE_ID + '/T15.md</write_files>'
|
|
6187
|
+
+ '<verify>node --check src/x.js</verify></task>\n');
|
|
6188
|
+
writeState(dir, baseState('subagent-execute'));
|
|
6189
|
+
const resReqT15 = runHandoff(['request', 'T15', 'tracked-after-request slice'], dir);
|
|
6190
|
+
assertExit(resReqT15, 0);
|
|
6191
|
+
const stReqT15 = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
6192
|
+
if (stReqT15.evidence['subagent-execute'].handoffRequests.T15.noCommit !== true) {
|
|
6193
|
+
throw new Error('request 时未跟踪且被忽略的路径应取得 noCommit 资格,实际 '
|
|
6194
|
+
+ JSON.stringify(stReqT15.evidence['subagent-execute'].handoffRequests.T15));
|
|
6195
|
+
}
|
|
6196
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T15.md', 'tracked after request\n');
|
|
6197
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'add', '-f', '.specs/' + CHANGE_ID + '/T15.md');
|
|
6198
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'track after request');
|
|
6199
|
+
stReqT15.newChange = true;
|
|
6200
|
+
writeState(dir, stReqT15);
|
|
6201
|
+
const resRevokeTracked = runHandoff(['result', 'T15', payload('T15', '')], dir);
|
|
6202
|
+
assertExit(resRevokeTracked, 1);
|
|
6203
|
+
assertOut(resRevokeTracked, 'HANDOFF ERROR');
|
|
6204
|
+
assertOut(resRevokeTracked, 'revokeReason=became-tracked');
|
|
6205
|
+
const stRevokeTracked = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
6206
|
+
assertRevocationAudit(stRevokeTracked.evidence['subagent-execute'].handoffRequests.T15,
|
|
6207
|
+
'became-tracked', '170④b 路径变 tracked 重验');
|
|
6208
|
+
if (stRevokeTracked.evidence['subagent-execute'].handoffResult?.T15) {
|
|
6209
|
+
throw new Error('tracked 重验失败不得落 result');
|
|
6210
|
+
}
|
|
6211
|
+
// ⑤ merge commit 负例(evil merge):merge 提交独有的越界文件不得绕过完整提交子集校验
|
|
6212
|
+
// → 新 change BLOCK 且列出越界文件(merge 与普通提交走同一 fail-closed 路径)
|
|
6213
|
+
const branch = execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
|
|
6214
|
+
git('checkout', '-q', '-b', 'feature-merge');
|
|
6215
|
+
writeFile(dir, 'src/feature-merge.js', 'feature\n');
|
|
6216
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'add', 'src/feature-merge.js');
|
|
6217
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'feature branch');
|
|
6218
|
+
git('checkout', '-q', branch);
|
|
6219
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'merge', '--no-ff', '--no-commit', 'feature-merge');
|
|
6220
|
+
writeFile(dir, 'src/evil-merge.js', 'evil\n');
|
|
6221
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'add', 'src/evil-merge.js');
|
|
6222
|
+
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-q', '-m', 'evil merge');
|
|
6223
|
+
const mergeHash = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
|
|
6224
|
+
const stMerge = baseState('subagent-execute');
|
|
6225
|
+
stMerge.newChange = true;
|
|
6226
|
+
stMerge.evidence['subagent-execute'] = { handoffRequests: { T13: { description: 'merge boundary', writeFiles: ['src/x.js'] } } };
|
|
6227
|
+
writeState(dir, stMerge);
|
|
6228
|
+
const resMerge = runHandoff(['result', 'T13', payload('T13', mergeHash)], dir);
|
|
6229
|
+
assertExit(resMerge, 1);
|
|
6230
|
+
assertOut(resMerge, '超出 writeFiles 范围');
|
|
6231
|
+
assertOut(resMerge, 'src/evil-merge.js');
|
|
6232
|
+
// ⑥ invalid hash 负例:非法 commitHash 不得被静默当作合法提交——必须输出可见 HANDOFF ERROR
|
|
6233
|
+
//(记录不被拒绝是既有渐进语义;此处锚定「可见报错 + 不作为合法提交校验」的契约边界)
|
|
6234
|
+
const stInvalidHash = baseState('subagent-execute');
|
|
6235
|
+
stInvalidHash.newChange = true;
|
|
6236
|
+
stInvalidHash.evidence['subagent-execute'] = { handoffRequests: { T14: { description: 'invalid hash', writeFiles: ['src/x.js'] } } };
|
|
6237
|
+
writeState(dir, stInvalidHash);
|
|
6238
|
+
const resInvalidHash = runHandoff(['result', 'T14', payload('T14', 'not-a-commit-hash')], dir);
|
|
6239
|
+
assertExit(resInvalidHash, 0);
|
|
6240
|
+
assertOut(resInvalidHash, 'HANDOFF ERROR');
|
|
6241
|
+
assertOut(resInvalidHash, 'commitHash 格式非法');
|
|
6242
|
+
assertNotOut(resInvalidHash, '提交为空,校验通过');
|
|
4689
6243
|
},
|
|
4690
6244
|
},
|
|
4691
6245
|
|
|
@@ -5262,7 +6816,7 @@ const SCENARIOS = [
|
|
|
5262
6816
|
}
|
|
5263
6817
|
const res = runPrepareEnv(['--target', proj, '--platform', 'dsh'], dir, { DSH_HOME: path.join(dir, 'dshhome'), ...env });
|
|
5264
6818
|
assertExit(res, 0);
|
|
5265
|
-
assertOut(res, '[
|
|
6819
|
+
assertOut(res, '[flow-comet] 已获取 flow-kit(锁定 9b5dda7)');
|
|
5266
6820
|
const fk = path.join(proj, 'flow-kit');
|
|
5267
6821
|
const head = execFileSync('git', ['-C', fk, 'rev-parse', 'HEAD'], { encoding: 'utf8', timeout: 60000 }).trim();
|
|
5268
6822
|
if (head !== '9b5dda7206ae841230f118348d660ad8d0ae2830') throw new Error('flow-kit HEAD 非锁定点: ' + head);
|
|
@@ -5337,7 +6891,7 @@ const SCENARIOS = [
|
|
|
5337
6891
|
GIT_CONFIG_VALUE_0: 'http://127.0.0.1:9',
|
|
5338
6892
|
});
|
|
5339
6893
|
assertExit(res, 0);
|
|
5340
|
-
assertOut(res, '[
|
|
6894
|
+
assertOut(res, '[flow-comet] 警告: flow-kit 自动获取失败');
|
|
5341
6895
|
assertOut(res, '手动获取指引');
|
|
5342
6896
|
assertOut(res, '已准备环境');
|
|
5343
6897
|
if (!fs.existsSync(path.join(proj, '.dsh', 'skills', 'flow-comet', 'SKILL.md'))) throw new Error('安装器其余职责未继续');
|
|
@@ -5414,16 +6968,64 @@ const SCENARIOS = [
|
|
|
5414
6968
|
},
|
|
5415
6969
|
},
|
|
5416
6970
|
|
|
5417
|
-
// 193: bridge-check
|
|
6971
|
+
// 193: bridge-check 版本比较语义——dev 态后缀归一后按基础版本比较。子锚:
|
|
6972
|
+
// ① 载体原始戳(权威源=发布标记 / 安装副本=dev 戳)vs 不可识别戳 → 原始戳配对 +
|
|
6973
|
+
// 归一基础版本双打印,FAIL exit 1(保留 raw-stamp pairing);
|
|
6974
|
+
// ② release 态严格相等(两原始值逐字相同)→ 既有 `==` 报告健康 exit 0(release 语义不变);
|
|
6975
|
+
// ③ dev 态安装副本形态(INSTALLED_VERSION=<发布>-<N>-g<hash>)vs 同基础 loader → 归一后健康 exit 0;
|
|
6976
|
+
// ④ 两侧均带 dev 后缀且基础版本一致 → 归一后健康 exit 0;
|
|
6977
|
+
// ⑤ 基础版本不同(两侧均可带 dev 后缀)→ 归一后仍 FAIL exit 1(双值双打印);
|
|
6978
|
+
// ⑥ 语义化预发布标识(-rc.N)不属 dev 态后缀、不得剥离 → 仍 FAIL exit 1;
|
|
6979
|
+
// ⑦ release 对 release 失配 → 归一不误判健康,仍 FAIL exit 1。
|
|
6980
|
+
// 期望值从载体自身 INSTALLED_VERSION 归一出的基础版本派生——权威源(发布标记)与安装副本
|
|
6981
|
+
// (git describe dev 戳)两载体形态均可移植;不得再以原始戳冒充归一后的期望值。
|
|
5418
6982
|
{
|
|
5419
|
-
name: '193 bridge-check
|
|
6983
|
+
name: '193 bridge-check 版本比较:dev 态同基础健康 / 基础失配与预发布仍 FAIL exit 1',
|
|
5420
6984
|
run: (dir) => {
|
|
6985
|
+
// ⑧ 便携复制锚:源路径含非 ASCII 字符时仍能完整复制技能树——旧实现用 fs.cpSync,在 Windows 上
|
|
6986
|
+
// 会让进程静默崩溃(中文路径项目内本套件曾中断于本场景)。比对用「相对路径 + 条目类型 +
|
|
6987
|
+
// 内容哈希(文件)/ 链接目标(符号链接)」全量清单:只比条目数会放过「少一个、多一个改名」
|
|
6988
|
+
// 这类等数错误,也无法发现内容被改写。
|
|
6989
|
+
{
|
|
6990
|
+
const cjkSource = path.join(dir, '源-中文-技能树');
|
|
6991
|
+
const cjkTarget = path.join(dir, '复制-目标');
|
|
6992
|
+
copyTreePortable(path.join(__dirname, '..'), cjkSource);
|
|
6993
|
+
copyTreePortable(cjkSource, cjkTarget);
|
|
6994
|
+
const listTree = (root, base = '', out = []) => {
|
|
6995
|
+
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
6996
|
+
const rel = base ? base + '/' + entry.name : entry.name;
|
|
6997
|
+
const full = path.join(root, entry.name);
|
|
6998
|
+
if (entry.isDirectory()) listTree(full, rel, out);
|
|
6999
|
+
else if (entry.isSymbolicLink()) out.push('link ' + rel + ' -> ' + fs.readlinkSync(full));
|
|
7000
|
+
else out.push('file ' + rel + ' ' + createHash('sha256').update(fs.readFileSync(full)).digest('hex'));
|
|
7001
|
+
}
|
|
7002
|
+
return out.sort();
|
|
7003
|
+
};
|
|
7004
|
+
const expected = listTree(path.join(__dirname, '..'));
|
|
7005
|
+
const actual = listTree(cjkTarget);
|
|
7006
|
+
if (expected.length !== actual.length) {
|
|
7007
|
+
throw new Error('非 ASCII 源路径的递归复制条目数不一致:期望 ' + expected.length + ',实际 ' + actual.length);
|
|
7008
|
+
}
|
|
7009
|
+
for (let i = 0; i < expected.length; i += 1) {
|
|
7010
|
+
if (expected[i] !== actual[i]) {
|
|
7011
|
+
throw new Error('非 ASCII 源路径的递归复制内容不一致(第 ' + (i + 1) + ' 项):期望 ' + expected[i] + ',实际 ' + actual[i]);
|
|
7012
|
+
}
|
|
7013
|
+
}
|
|
7014
|
+
}
|
|
5421
7015
|
const { dshHome, installedVersion } = writeBridgeFixture(dir, { loaderStamp: '9.9.9-fixture-skew' });
|
|
5422
|
-
const
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
assertOut(
|
|
5426
|
-
assertOut(
|
|
7016
|
+
const baseVersion = fixtureBridgeBaseVersion(installedVersion);
|
|
7017
|
+
const skew = runBridgeCheck(dir, dshHome);
|
|
7018
|
+
assertExit(skew, 1);
|
|
7019
|
+
assertOut(skew, '[FAIL] 版本偏斜: loader BRIDGE_VERSION=9.9.9-fixture-skew != 项目 INSTALLED_VERSION=' + installedVersion + '(归一基础版本: loader=9.9.9-fixture-skew / installed=' + baseVersion + ')——两值如上');
|
|
7020
|
+
assertOut(skew, 'bridge-check: 失配 1 项——exit 1');
|
|
7021
|
+
|
|
7022
|
+
// ②~⑦ 安装副本子锚表:执行器逐个跑真实 CLI;期望值均由 baseVersion / devVersion 派生。
|
|
7023
|
+
const devVersion = fixtureIsBridgeDevVersion(installedVersion)
|
|
7024
|
+
? installedVersion
|
|
7025
|
+
: baseVersion + '-11-g93d96c0';
|
|
7026
|
+
for (const subAnchor of bridgeCopyVersionSubAnchorCases(baseVersion, devVersion)) {
|
|
7027
|
+
assertInstalledCopyBridgeVersionCase(dir, subAnchor);
|
|
7028
|
+
}
|
|
5427
7029
|
},
|
|
5428
7030
|
},
|
|
5429
7031
|
|
|
@@ -7332,46 +8934,2583 @@ const SCENARIOS = [
|
|
|
7332
8934
|
assertOut(res, 'EACCES');
|
|
7333
8935
|
},
|
|
7334
8936
|
},
|
|
7335
|
-
];
|
|
7336
8937
|
|
|
7337
|
-
//
|
|
8938
|
+
// 244: 维护文档机检(docs-governance)——docs/internal 死引用 + ROADMAP 最低结构。
|
|
8939
|
+
// 判别力四类:正例(干净夹具通过)/ 反例(死引用必须报告且含来源与目标)/
|
|
8940
|
+
// 越界(ROADMAP 缺段必须报告)/ 恢复(修复后通过);另锁「整组缺席即跳过」语义。
|
|
8941
|
+
{
|
|
8942
|
+
name: '244 维护文档机检:docs/internal 死引用与 ROADMAP 结构(docs-governance)',
|
|
8943
|
+
run: (dir) => {
|
|
8944
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
8945
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md` 与 `docs/internal/missing-file.md`。\n');
|
|
8946
|
+
const problems = internalDocsProblems(dir);
|
|
8947
|
+
if (!problems.some((p) => p.includes('FIXTURE.md:1') && p.includes('missing-file.md'))) {
|
|
8948
|
+
throw new Error('死引用未被报告(或未带行号): ' + JSON.stringify(problems));
|
|
8949
|
+
}
|
|
8950
|
+
if (!problems.some((p) => p.includes('死引用')) || problems.length !== 1) {
|
|
8951
|
+
throw new Error('死引用判定应恰好 1 条(合法引用不得误报): ' + JSON.stringify(problems));
|
|
8952
|
+
}
|
|
8953
|
+
// 覆盖:.specs/adr 目标面 + allowlist 分支(未来路径不得被报)
|
|
8954
|
+
writeFile(dir, '.specs/adr/ADR-FIXTURE.md', '见 `docs/internal/missing-adr-target.md` 与 `.specs/archive/CONTEXT-history.md`。\n');
|
|
8955
|
+
const adrProblems = internalDocsProblems(dir);
|
|
8956
|
+
if (!adrProblems.some((p) => p.includes('ADR-FIXTURE.md') && p.includes('missing-adr-target.md'))) {
|
|
8957
|
+
throw new Error('adr 面死引用未被报告: ' + JSON.stringify(adrProblems));
|
|
8958
|
+
}
|
|
8959
|
+
if (adrProblems.some((p) => p.includes('CONTEXT-history.md'))) {
|
|
8960
|
+
throw new Error('allowlist 未来路径被误报: ' + JSON.stringify(adrProblems));
|
|
8961
|
+
}
|
|
8962
|
+
fs.rmSync(path.join(dir, '.specs', 'adr', 'ADR-FIXTURE.md'));
|
|
8963
|
+
// 恢复:修好引用 → 通过
|
|
8964
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
8965
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
8966
|
+
throw new Error('修复后应通过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
8967
|
+
}
|
|
8968
|
+
// 越界:删段 → 结构问题必须报告
|
|
8969
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n## Next\n## Later\n');
|
|
8970
|
+
const structProblems = internalDocsProblems(dir);
|
|
8971
|
+
if (!structProblems.some((p) => p.includes('Open decisions'))) {
|
|
8972
|
+
throw new Error('ROADMAP 缺段未被报告: ' + JSON.stringify(structProblems));
|
|
8973
|
+
}
|
|
8974
|
+
// 整组缺席(CI / worktree 形态)→ 跳过,不误红
|
|
8975
|
+
fs.rmSync(path.join(dir, 'docs/internal'), { recursive: true, force: true });
|
|
8976
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
8977
|
+
throw new Error('组目录缺席时应跳过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
8978
|
+
}
|
|
8979
|
+
},
|
|
8980
|
+
},
|
|
7338
8981
|
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7343
|
-
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
}
|
|
8982
|
+
// 245: Fix 回退态共享判定(共享判定 / AC-1 基础谓词)——正例:review / verify 驻留 + TASK 存在
|
|
8983
|
+
// pending 任务 + resolveNextNode(completedNodes) === execute;反例三类:非源节点驻留 /
|
|
8984
|
+
// 无 pending 任务(路由仍回 execute,证明 pending 是独立条件)/ 路由不回 execute(前置产物缺失)。
|
|
8985
|
+
{
|
|
8986
|
+
name: '245 resolveFixRollbackState:源节点 + pending 串/并行 → 目标节点(路由/完成态反例)',
|
|
8987
|
+
run: async (dir) => {
|
|
8988
|
+
const isRollback = requireRouteNodeExport('resolveFixRollbackState');
|
|
8989
|
+
const protocol = readScenarioProtocol(dir);
|
|
8990
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
8991
|
+
const pendingTasks = '# TASK\n\n' + fixTaskBlock('T01', 'pending') + '\n';
|
|
8992
|
+
writeIntakeArtifacts(dir);
|
|
8993
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', pendingTasks);
|
|
8994
|
+
const baseArgs = { runRoot: dir, changeName: CHANGE_ID, protocol, completedNodes };
|
|
8995
|
+
// 夹具前提:该 completedNodes 下共享路由确实推导回 execute(谓词第三条件成立)
|
|
8996
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'execute') {
|
|
8997
|
+
throw new Error('夹具前提失效:串行 pending 任务在场时 resolveNextNode 应推导 execute');
|
|
8998
|
+
}
|
|
8999
|
+
const fromReview = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
9000
|
+
if (fromReview !== 'execute') {
|
|
9001
|
+
throw new Error('review 驻留 + 串行 pending 应归位 execute,实际 ' + JSON.stringify(fromReview));
|
|
9002
|
+
}
|
|
9003
|
+
const fromVerify = await isRollback({ ...baseArgs, currentNode: 'verify' });
|
|
9004
|
+
if (fromVerify !== 'execute') {
|
|
9005
|
+
throw new Error('verify 驻留 + 串行 pending 应归位 execute,实际 ' + JSON.stringify(fromVerify));
|
|
9006
|
+
}
|
|
9007
|
+
// pending 并行(依赖已满足):共享路由推 subagent-execute → 目标节点为 subagent-execute
|
|
9008
|
+
// (并行修复任务同样必须归位到 execute 家族,不得因节点 id 差异绕过闭环)。
|
|
9009
|
+
const parallelPending = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
9010
|
+
+ '<task id="P-FIX-01" parallel="true" status="pending">'
|
|
9011
|
+
+ '<action>实现 P-FIX-01</action><write_files>src/p-fix-01.mjs</write_files>'
|
|
9012
|
+
+ '<verify>node --check src/p-fix-01.mjs</verify></task>\n';
|
|
9013
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', parallelPending);
|
|
9014
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'subagent-execute') {
|
|
9015
|
+
throw new Error('夹具前提失效:可委托 parallel pending 在场时 resolveNextNode 应推导 subagent-execute');
|
|
9016
|
+
}
|
|
9017
|
+
const parallelReview = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
9018
|
+
if (parallelReview !== 'subagent-execute') {
|
|
9019
|
+
throw new Error('review 驻留 + 并行 pending 应归位 subagent-execute,实际 ' + JSON.stringify(parallelReview));
|
|
9020
|
+
}
|
|
9021
|
+
const parallelVerify = await isRollback({ ...baseArgs, currentNode: 'verify' });
|
|
9022
|
+
if (parallelVerify !== 'subagent-execute') {
|
|
9023
|
+
throw new Error('verify 驻留 + 并行 pending 应归位 subagent-execute,实际 ' + JSON.stringify(parallelVerify));
|
|
9024
|
+
}
|
|
9025
|
+
// 反例①:非 review/verify 驻留(pending 与路由条件仍成立)→ null
|
|
9026
|
+
const fromExecute = await isRollback({ ...baseArgs, currentNode: 'execute' });
|
|
9027
|
+
if (fromExecute !== null) {
|
|
9028
|
+
throw new Error('非源节点驻留应为 null,实际 ' + JSON.stringify(fromExecute));
|
|
9029
|
+
}
|
|
9030
|
+
// 反例②:无 pending(全 done 但缺 SUMMARY 与出口事件)→ 无闭合信号 → null
|
|
9031
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
9032
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'execute') {
|
|
9033
|
+
throw new Error('夹具前提失效:全 done 且缺 SUMMARY 时 resolveNextNode 应仍推导 execute');
|
|
9034
|
+
}
|
|
9035
|
+
const noPending = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
9036
|
+
if (noPending !== null) {
|
|
9037
|
+
throw new Error('无 pending 且无出口事件应为 null,实际 ' + JSON.stringify(noPending));
|
|
9038
|
+
}
|
|
9039
|
+
// 反例③:pending 在场但前置产物缺失 → 路由退回 design(非 execute 家族)→ null
|
|
9040
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', pendingTasks);
|
|
9041
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID, 'DESIGN.md'));
|
|
9042
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'design') {
|
|
9043
|
+
throw new Error('夹具前提失效:DESIGN.md 缺失时 resolveNextNode 应推导 design');
|
|
9044
|
+
}
|
|
9045
|
+
const notExecute = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
9046
|
+
if (notExecute !== null) {
|
|
9047
|
+
throw new Error('路由不回 execute 家族时应为 null,实际 ' + JSON.stringify(notExecute));
|
|
9048
|
+
}
|
|
9049
|
+
// 反例④:history 最新 execute 出口事件属于另一个 change(state.history 跨 change 保留)
|
|
9050
|
+
// → 不得当作当前 change 的闭合签名(否则 change A 的修复签名会误拦 change B 的源节点出口)。
|
|
9051
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
|
|
9052
|
+
'# DESIGN\n\n## 0. 技术栈\n\nNode\n\n## 决策清单\n\n| # | D | R |\n|---|---|---|\n| D1 | x | y |');
|
|
9053
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
9054
|
+
const crossChange = await isRollback({
|
|
9055
|
+
...baseArgs,
|
|
9056
|
+
currentNode: 'review',
|
|
9057
|
+
history: [{
|
|
9058
|
+
event: 'exit-applied', node: 'execute', change: 'other-change',
|
|
9059
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: '0'.repeat(64),
|
|
9060
|
+
}],
|
|
9061
|
+
});
|
|
9062
|
+
if (crossChange !== null) {
|
|
9063
|
+
throw new Error('其它 change 的出口签名不得判定当前 change 未闭合(应为 null),实际 ' + JSON.stringify(crossChange));
|
|
9064
|
+
}
|
|
9065
|
+
// done-but-unclosed:任务全 done + execute 家族已在 completedNodes + 最新家族出口签名过时
|
|
9066
|
+
// → 返回该出口事件记录的家族节点(execute / subagent-execute 均可作为归位目标)。
|
|
9067
|
+
const staleFamilyEvent = (node) => ({
|
|
9068
|
+
event: 'exit-applied', node, at: '2026-09-21T00:00:00.000Z',
|
|
9069
|
+
taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
9070
|
+
});
|
|
9071
|
+
const doneFamily = await isRollback({
|
|
9072
|
+
...baseArgs, currentNode: 'review', history: [staleFamilyEvent('subagent-execute')],
|
|
9073
|
+
});
|
|
9074
|
+
if (doneFamily !== 'subagent-execute') {
|
|
9075
|
+
throw new Error('全 done + 家族出口签名过时(subagent-execute)应归位 subagent-execute,实际 ' + JSON.stringify(doneFamily));
|
|
9076
|
+
}
|
|
9077
|
+
const doneExecute = await isRollback({
|
|
9078
|
+
...baseArgs, currentNode: 'verify', history: [staleFamilyEvent('execute')],
|
|
9079
|
+
});
|
|
9080
|
+
if (doneExecute !== 'execute') {
|
|
9081
|
+
throw new Error('全 done + 家族出口签名过时(execute)应归位 execute,实际 ' + JSON.stringify(doneExecute));
|
|
9082
|
+
}
|
|
9083
|
+
// completedNodes 只要求家族中至少一个:execute 缺席、subagent-execute 在场同样成立。
|
|
9084
|
+
const doneOtherFamily = await isRollback({
|
|
9085
|
+
...baseArgs,
|
|
9086
|
+
completedNodes: ['open', 'design', 'plan', 'subagent-execute'],
|
|
9087
|
+
currentNode: 'review',
|
|
9088
|
+
history: [staleFamilyEvent('subagent-execute')],
|
|
9089
|
+
});
|
|
9090
|
+
if (doneOtherFamily !== 'subagent-execute') {
|
|
9091
|
+
throw new Error('completedNodes 含 subagent-execute(execute 缺席)时应归位 subagent-execute,实际 ' + JSON.stringify(doneOtherFamily));
|
|
9092
|
+
}
|
|
9093
|
+
// 最新家族出口签名与当前任务集一致 → 本批已闭合 → null(不得反复回退)。
|
|
9094
|
+
const currentSignature = await routeNodeModule.taskSetSignature(
|
|
9095
|
+
fs.readFileSync(path.join(dir, '.specs', CHANGE_ID, 'TASK.md'), 'utf8'));
|
|
9096
|
+
const closed = await isRollback({
|
|
9097
|
+
...baseArgs,
|
|
9098
|
+
currentNode: 'review',
|
|
9099
|
+
history: [{
|
|
9100
|
+
event: 'exit-applied', node: 'subagent-execute',
|
|
9101
|
+
at: '2026-09-22T00:00:00.000Z', taskSetSignature: currentSignature,
|
|
9102
|
+
}],
|
|
9103
|
+
});
|
|
9104
|
+
if (closed !== null) {
|
|
9105
|
+
throw new Error('出口签名与当前任务集一致时应为 null(已闭合),实际 ' + JSON.stringify(closed));
|
|
9106
|
+
}
|
|
7360
9107
|
|
|
7361
|
-
|
|
9108
|
+
// ---------- m-12 轮次计数纯函数锚(唯一写点 applyFixRollbackRound)----------
|
|
9109
|
+
// 第 1~3 轮递增并带审计后缀;第 4 轮新 change BLOCK 且不写计数器;用户显式授权后
|
|
9110
|
+
// 放行该轮;旧 change 缺字段缺省 0 不 BLOCK;done-but-unclosed 分支不计数。
|
|
9111
|
+
const applyRound = requireRouteNodeExport('applyFixRollbackRound');
|
|
9112
|
+
const roundState = {
|
|
9113
|
+
activeChange: CHANGE_ID,
|
|
9114
|
+
currentNode: 'review',
|
|
9115
|
+
evidence: { review: { summary: 'pending fix' } },
|
|
9116
|
+
newChange: true,
|
|
9117
|
+
};
|
|
9118
|
+
const pendingDecision = { kind: 'pending', target: 'execute' };
|
|
9119
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
9120
|
+
const applied = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
9121
|
+
if (!applied.counted || applied.blocked || applied.round !== round
|
|
9122
|
+
|| applied.auditSuffix !== '(第 ' + round + '/3 轮)') {
|
|
9123
|
+
throw new Error('第 ' + round + ' 轮应计数并输出轮次审计后缀,实际 ' + JSON.stringify(applied));
|
|
9124
|
+
}
|
|
9125
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== round) {
|
|
9126
|
+
throw new Error('第 ' + round + ' 轮后计数器应为 ' + round + ',实际 '
|
|
9127
|
+
+ JSON.stringify(roundState.fixRoundsByChange));
|
|
9128
|
+
}
|
|
9129
|
+
}
|
|
9130
|
+
const blocked = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
9131
|
+
if (!blocked.blocked || blocked.counted || blocked.round !== 4) {
|
|
9132
|
+
throw new Error('新 change 第 4 轮应 BLOCK 且不计数,实际 ' + JSON.stringify(blocked));
|
|
9133
|
+
}
|
|
9134
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
9135
|
+
throw new Error('第 4 轮 BLOCK 不得写计数器(应保持 3),实际 '
|
|
9136
|
+
+ JSON.stringify(roundState.fixRoundsByChange));
|
|
9137
|
+
}
|
|
9138
|
+
if (!String(blocked.blockedMessage).includes('继续修') || !String(blocked.blockedMessage).includes('停止')) {
|
|
9139
|
+
throw new Error('第 4 轮 BLOCK 消息应含「继续修/停止」决策指引,实际 ' + JSON.stringify(blocked.blockedMessage));
|
|
9140
|
+
}
|
|
9141
|
+
// F5 fail-closed:完整授权形态 = round 正整数 + at/source 非空字符串;任一缺失、类型非法、
|
|
9142
|
+
// 空串/纯空白一律按未授权处理——第 4 轮继续 BLOCK、不计数、不写 state(state 字节零改写)。
|
|
9143
|
+
const invalidOverrides = [
|
|
9144
|
+
['仅 round(缺 at/source)', { round: 4 }],
|
|
9145
|
+
['缺 at', { round: 4, source: 'fixture-user' }],
|
|
9146
|
+
['缺 source', { round: 4, at: '2026-09-25T00:00:00.000Z' }],
|
|
9147
|
+
['round 为字符串', { round: '4', at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
9148
|
+
['round 为零', { round: 0, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
9149
|
+
['round 为负数', { round: -1, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
9150
|
+
['round 为小数', { round: 4.5, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
9151
|
+
['at 类型非法(数字)', { round: 4, at: 123, source: 'fixture-user' }],
|
|
9152
|
+
['source 类型非法(数组)', { round: 4, at: '2026-09-25T00:00:00.000Z', source: ['fixture-user'] }],
|
|
9153
|
+
['at 空串', { round: 4, at: '', source: 'fixture-user' }],
|
|
9154
|
+
['source 空串', { round: 4, at: '2026-09-25T00:00:00.000Z', source: '' }],
|
|
9155
|
+
['at 纯空白', { round: 4, at: ' ', source: 'fixture-user' }],
|
|
9156
|
+
['source 纯空白', { round: 4, at: '2026-09-25T00:00:00.000Z', source: '\t' }],
|
|
9157
|
+
['override 为 null', null],
|
|
9158
|
+
];
|
|
9159
|
+
for (const [label, badOverride] of invalidOverrides) {
|
|
9160
|
+
roundState.evidence.review.fixRoundOverride = badOverride;
|
|
9161
|
+
const badResult = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
9162
|
+
if (!badResult.blocked || badResult.counted || badResult.overrideUsed || badResult.round !== 4
|
|
9163
|
+
|| roundState.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
9164
|
+
throw new Error('F5 非法授权形态必须按未授权 fail-closed BLOCK 且零改写(' + label + '),实际 '
|
|
9165
|
+
+ JSON.stringify({ badResult, rounds: roundState.fixRoundsByChange }));
|
|
9166
|
+
}
|
|
9167
|
+
}
|
|
9168
|
+
// 合法三元组(嵌套 evidence)→ 放行被 BLOCK 的那一轮并留审计
|
|
9169
|
+
roundState.evidence.review.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
9170
|
+
const override = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
9171
|
+
if (!override.counted || !override.overrideUsed || override.blocked || override.round !== 4) {
|
|
9172
|
+
throw new Error('用户显式授权后第 4 轮应放行并标记 overrideUsed,实际 ' + JSON.stringify(override));
|
|
9173
|
+
}
|
|
9174
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== 4) {
|
|
9175
|
+
throw new Error('授权放行后计数器应为 4,实际 ' + JSON.stringify(roundState.fixRoundsByChange));
|
|
9176
|
+
}
|
|
9177
|
+
// 旧 change 缺轮次字段 → 缺省 0、不因计数 BLOCK
|
|
9178
|
+
const legacyRoundState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: false };
|
|
9179
|
+
const legacyRound = applyRound({ state: legacyRoundState, sourceNode: 'review', decision: pendingDecision });
|
|
9180
|
+
if (!legacyRound.counted || legacyRound.blocked || legacyRound.round !== 1) {
|
|
9181
|
+
throw new Error('旧 change 缺省 0 应可从第 1 轮计数,实际 ' + JSON.stringify(legacyRound));
|
|
9182
|
+
}
|
|
9183
|
+
if (legacyRoundState.fixRoundsByChange?.[CHANGE_ID] !== 1) {
|
|
9184
|
+
throw new Error('旧 change 第 1 轮应写入缺省容器,实际 ' + JSON.stringify(legacyRoundState.fixRoundsByChange));
|
|
9185
|
+
}
|
|
9186
|
+
// 分支② done-but-unclosed 不计数(计数语义 = 一次受控归位)
|
|
9187
|
+
const unclosedState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: true };
|
|
9188
|
+
const unclosedRound = applyRound({ state: unclosedState, sourceNode: 'review', decision: { kind: 'unclosed', target: 'execute' } });
|
|
9189
|
+
if (unclosedRound.counted || unclosedRound.round !== null || unclosedState.fixRoundsByChange) {
|
|
9190
|
+
throw new Error('done-but-unclosed 分支不得计数/建容器,实际 '
|
|
9191
|
+
+ JSON.stringify({ unclosedRound, rounds: unclosedState.fixRoundsByChange }));
|
|
9192
|
+
}
|
|
9193
|
+
},
|
|
9194
|
+
},
|
|
7362
9195
|
|
|
7363
|
-
//
|
|
7364
|
-
//
|
|
7365
|
-
//
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
|
|
7372
|
-
|
|
7373
|
-
|
|
7374
|
-
|
|
9196
|
+
// 246: execute 后第一个未完成节点推导(共享推导基础)——按协议 route 顺序跳过全部
|
|
9197
|
+
// execute 家族节点(execute / subagent-execute 均不参与后置推导),返回其后首个未完成
|
|
9198
|
+
// 节点:review → verify → archive;协议无 execute 家族 → null(调用方再用 review/verify 收窄)。
|
|
9199
|
+
{
|
|
9200
|
+
name: '246 firstIncompletePostExecNode:execute 家族后首个未完成节点(review→verify→archive;无 execute 家族→null)',
|
|
9201
|
+
run: (dir) => {
|
|
9202
|
+
const firstIncomplete = requireRouteNodeExport('firstIncompletePostExecNode');
|
|
9203
|
+
const protocol = readScenarioProtocol(dir);
|
|
9204
|
+
const pre = ['open', 'design', 'plan'];
|
|
9205
|
+
// subagent-execute(execute 家族)未完成不作为后置节点,首个后置节点应为 review
|
|
9206
|
+
const review = firstIncomplete({ protocol, completedNodes: [...pre, 'execute'] });
|
|
9207
|
+
if (review !== 'review') {
|
|
9208
|
+
throw new Error('execute 已完成、subagent-execute 未完成时应为 review,实际 ' + JSON.stringify(review));
|
|
9209
|
+
}
|
|
9210
|
+
const verify = firstIncomplete({ protocol, completedNodes: [...pre, 'execute', 'subagent-execute', 'review'] });
|
|
9211
|
+
if (verify !== 'verify') {
|
|
9212
|
+
throw new Error('review 已完成时应为 verify,实际 ' + JSON.stringify(verify));
|
|
9213
|
+
}
|
|
9214
|
+
const archive = firstIncomplete({ protocol, completedNodes: [...pre, 'execute', 'subagent-execute', 'review', 'verify'] });
|
|
9215
|
+
if (archive !== 'archive') {
|
|
9216
|
+
throw new Error('review/verify 均已完成时应为 archive,实际 ' + JSON.stringify(archive));
|
|
9217
|
+
}
|
|
9218
|
+
const noExecuteFamily = firstIncomplete({ protocol: { nodes: [{ id: 'alpha' }, { id: 'beta' }] }, completedNodes: [] });
|
|
9219
|
+
if (noExecuteFamily !== null) {
|
|
9220
|
+
throw new Error('协议无 execute 家族时应为 null,实际 ' + JSON.stringify(noExecuteFamily));
|
|
9221
|
+
}
|
|
9222
|
+
},
|
|
9223
|
+
},
|
|
9224
|
+
|
|
9225
|
+
// 247: Fix 回程节点推导(共享推导基础)——TASK 全 done → 取 execute 后首个未完成节点,
|
|
9226
|
+
// 仅 review/verify 可作回程源(archive / 完成态 → null);仍有 pending / TASK 缺失 /
|
|
9227
|
+
// 零任务块一律 null(fail-closed,不许用半解析结果回程)。
|
|
9228
|
+
{
|
|
9229
|
+
name: '247 resolveFixReturnNode:全 done 且源节点未完成 → 源节点;否则 null(pending/缺失/零任务块)+ classifyFixReturnCause 基础锚',
|
|
9230
|
+
run: async (dir) => {
|
|
9231
|
+
const fixReturn = requireRouteNodeExport('resolveFixReturnNode');
|
|
9232
|
+
const protocol = readScenarioProtocol(dir);
|
|
9233
|
+
const completedNodes = ['open', 'design', 'plan', 'execute'];
|
|
9234
|
+
writeIntakeArtifacts(dir);
|
|
9235
|
+
const taskPath = path.join(dir, '.specs', CHANGE_ID, 'TASK.md');
|
|
9236
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
9237
|
+
'# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T02', 'done') + '\n');
|
|
9238
|
+
const baseArgs = { runRoot: dir, changeName: CHANGE_ID, protocol, completedNodes };
|
|
9239
|
+
const sourceReview = await fixReturn(baseArgs);
|
|
9240
|
+
if (sourceReview !== 'review') {
|
|
9241
|
+
throw new Error('review 未完成、任务全 done 时应为 review,实际 ' + JSON.stringify(sourceReview));
|
|
9242
|
+
}
|
|
9243
|
+
const sourceVerify = await fixReturn({ ...baseArgs, completedNodes: [...completedNodes, 'subagent-execute', 'review'] });
|
|
9244
|
+
if (sourceVerify !== 'verify') {
|
|
9245
|
+
throw new Error('review 已完成、verify 未完成时应为 verify,实际 ' + JSON.stringify(sourceVerify));
|
|
9246
|
+
}
|
|
9247
|
+
const pastSources = await fixReturn({ ...baseArgs, completedNodes: [...completedNodes, 'subagent-execute', 'review', 'verify'] });
|
|
9248
|
+
if (pastSources !== null) {
|
|
9249
|
+
throw new Error('review/verify 均已完成(首个未完成为 archive)时应为 null,实际 ' + JSON.stringify(pastSources));
|
|
9250
|
+
}
|
|
9251
|
+
// 反例:仍有 pending 任务 → null(即使 resolveNextNode 会推导回 execute)
|
|
9252
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
9253
|
+
'# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T02', 'pending') + '\n');
|
|
9254
|
+
const stillPending = await fixReturn(baseArgs);
|
|
9255
|
+
if (stillPending !== null) {
|
|
9256
|
+
throw new Error('仍有 pending 任务时应为 null,实际 ' + JSON.stringify(stillPending));
|
|
9257
|
+
}
|
|
9258
|
+
// 反例:TASK.md 缺失 → null
|
|
9259
|
+
fs.rmSync(taskPath);
|
|
9260
|
+
const missingTask = await fixReturn(baseArgs);
|
|
9261
|
+
if (missingTask !== null) {
|
|
9262
|
+
throw new Error('TASK.md 缺失时应为 null,实际 ' + JSON.stringify(missingTask));
|
|
9263
|
+
}
|
|
9264
|
+
// 反例:零任务块(仅占位)→ null
|
|
9265
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n<!-- 占位 -->\n');
|
|
9266
|
+
const noBlocks = await fixReturn(baseArgs);
|
|
9267
|
+
if (noBlocks !== null) {
|
|
9268
|
+
throw new Error('零任务块时应为 null,实际 ' + JSON.stringify(noBlocks));
|
|
9269
|
+
}
|
|
9270
|
+
|
|
9271
|
+
// ——classifyFixReturnCause 基础锚(T01:历史签名全量发散 + Fix 结构标记 + unknown 回退)——
|
|
9272
|
+
// 分类器缺失时在此显式 RED(requireRouteNodeExport),不做半成品静默通过。
|
|
9273
|
+
const classifyCause = requireRouteNodeExport('classifyFixReturnCause');
|
|
9274
|
+
const signatureOf = (text) => routeNodeModule.taskSetSignature(text);
|
|
9275
|
+
const familyExit = (node, signature, extra = {}) => ({
|
|
9276
|
+
event: 'exit-applied', node, at: '2026-09-24T00:00:00.000Z',
|
|
9277
|
+
taskSetSignature: signature, ...extra,
|
|
9278
|
+
});
|
|
9279
|
+
const plainTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n';
|
|
9280
|
+
const plainSignature = signatureOf(plainTaskText);
|
|
9281
|
+
const divergentSignature = '0'.repeat(64);
|
|
9282
|
+
// ① 签名发散:历史任一出口签名 ≠ 当前任务集签名 → fix(无 Fix 标记也成立)
|
|
9283
|
+
const divergence = classifyCause({
|
|
9284
|
+
history: [familyExit('execute', divergentSignature)],
|
|
9285
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9286
|
+
});
|
|
9287
|
+
if (divergence !== 'fix') {
|
|
9288
|
+
throw new Error('历史签名全量发散应判 fix,实际 ' + JSON.stringify(divergence));
|
|
9289
|
+
}
|
|
9290
|
+
// ② 签名相等:唯一出口签名 == 当前 TASK 签名且无 Fix 标记 → normal
|
|
9291
|
+
const equalCause = classifyCause({
|
|
9292
|
+
history: [familyExit('subagent-execute', plainSignature)],
|
|
9293
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9294
|
+
});
|
|
9295
|
+
if (equalCause !== 'normal') {
|
|
9296
|
+
throw new Error('签名一致且无 Fix 标记应判 normal,实际 ' + JSON.stringify(equalCause));
|
|
9297
|
+
}
|
|
9298
|
+
// ③ 无签名事件:空串签名 / history 缺席 / 非家族节点 / 其它 change → unknown(都不误判 normal)
|
|
9299
|
+
const emptySignature = classifyCause({
|
|
9300
|
+
history: [familyExit('execute', '')],
|
|
9301
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9302
|
+
});
|
|
9303
|
+
if (emptySignature !== 'unknown') {
|
|
9304
|
+
throw new Error('空签名事件应判 unknown,实际 ' + JSON.stringify(emptySignature));
|
|
9305
|
+
}
|
|
9306
|
+
const missingHistory = classifyCause({ taskContent: plainTaskText, fixSectionTitle: 'Fix 任务' });
|
|
9307
|
+
if (missingHistory !== 'unknown') {
|
|
9308
|
+
throw new Error('history 缺席应判 unknown,实际 ' + JSON.stringify(missingHistory));
|
|
9309
|
+
}
|
|
9310
|
+
const otherChangeOnly = classifyCause({
|
|
9311
|
+
history: [familyExit('execute', divergentSignature, { change: 'other-change' })],
|
|
9312
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9313
|
+
});
|
|
9314
|
+
if (otherChangeOnly !== 'unknown') {
|
|
9315
|
+
throw new Error('其它 change 的出口事件不得参与分类(应为 unknown),实际 ' + JSON.stringify(otherChangeOnly));
|
|
9316
|
+
}
|
|
9317
|
+
const nonFamilyOnly = classifyCause({
|
|
9318
|
+
history: [familyExit('review', divergentSignature)],
|
|
9319
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9320
|
+
});
|
|
9321
|
+
if (nonFamilyOnly !== 'unknown') {
|
|
9322
|
+
throw new Error('非 execute 家族出口事件不得参与分类(应为 unknown),实际 ' + JSON.stringify(nonFamilyOnly));
|
|
9323
|
+
}
|
|
9324
|
+
// ④ Fix 段内任务块(故意用非 FIX 编号 T02,排除全文编号规则干扰)→ fix(结构标记)
|
|
9325
|
+
const fixSectionWithTask = plainTaskText
|
|
9326
|
+
+ '\n## Fix 任务(来自 REVIEW / INTEGRATION)\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
9327
|
+
const sectionMarker = classifyCause({
|
|
9328
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
9329
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: 'Fix 任务',
|
|
9330
|
+
});
|
|
9331
|
+
if (sectionMarker !== 'fix') {
|
|
9332
|
+
throw new Error('Fix 段内含 task 块应判 fix,实际 ' + JSON.stringify(sectionMarker));
|
|
9333
|
+
}
|
|
9334
|
+
// ⑤ Fix 段无任务(仅标题与占位)→ normal(切片边界正确、不把其它段标题误当 Fix 段)
|
|
9335
|
+
const fixSectionEmpty = plainTaskText + '\n## Fix 任务(来自 REVIEW / INTEGRATION)\n\n<!-- 占位 -->\n';
|
|
9336
|
+
const emptySection = classifyCause({
|
|
9337
|
+
history: [familyExit('execute', signatureOf(fixSectionEmpty))],
|
|
9338
|
+
changeName: CHANGE_ID, taskContent: fixSectionEmpty, fixSectionTitle: 'Fix 任务',
|
|
9339
|
+
});
|
|
9340
|
+
if (emptySection !== 'normal') {
|
|
9341
|
+
throw new Error('Fix 段无任务块应判 normal,实际 ' + JSON.stringify(emptySection));
|
|
9342
|
+
}
|
|
9343
|
+
// ⑥ 全文任务 id 修复任务编号前缀(Fix 段之外、文件尾追加形态)→ fix
|
|
9344
|
+
const tailTFix = plainTaskText + '\n## 其它\n\n' + fixTaskBlock('T-FIX-01', 'done') + '\n';
|
|
9345
|
+
const tailPFix = plainTaskText + '\n## 其它\n\n' + fixTaskBlock('P-FIX-01', 'done') + '\n';
|
|
9346
|
+
for (const [label, text] of [['T-FIX-01', tailTFix], ['P-FIX-01', tailPFix]]) {
|
|
9347
|
+
const idMarker = classifyCause({
|
|
9348
|
+
history: [familyExit('execute', signatureOf(text))],
|
|
9349
|
+
changeName: CHANGE_ID, taskContent: text, fixSectionTitle: 'Fix 任务',
|
|
9350
|
+
});
|
|
9351
|
+
if (idMarker !== 'fix') {
|
|
9352
|
+
throw new Error(label + ' 编号(Fix 段外)应判 fix,实际 ' + JSON.stringify(idMarker));
|
|
9353
|
+
}
|
|
9354
|
+
}
|
|
9355
|
+
// ⑦ 标题缺失回退:fixSectionTitle 缺席 / 空串 → 回退内置「Fix 任务」仍命中结构标记;
|
|
9356
|
+
// 传入标题优先于内置(Fix 段在场但传入无关标题,结构规则不命中 → normal)。
|
|
9357
|
+
for (const [label, title] of [['缺席', undefined], ['空串', '']]) {
|
|
9358
|
+
const fallback = classifyCause({
|
|
9359
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
9360
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: title,
|
|
9361
|
+
});
|
|
9362
|
+
if (fallback !== 'fix') {
|
|
9363
|
+
throw new Error('fixSectionTitle ' + label + ' 应回退内置「Fix 任务」判 fix,实际 ' + JSON.stringify(fallback));
|
|
9364
|
+
}
|
|
9365
|
+
}
|
|
9366
|
+
const customTitlePriority = classifyCause({
|
|
9367
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
9368
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: '修复任务',
|
|
9369
|
+
});
|
|
9370
|
+
if (customTitlePriority !== 'normal') {
|
|
9371
|
+
throw new Error('传入标题应优先于内置(无关标题不得命中 Fix 段)应判 normal,实际 ' + JSON.stringify(customTitlePriority));
|
|
9372
|
+
}
|
|
9373
|
+
// ⑧ 多波次历史:旧签名 ≠ 当前、最新签名 == 当前 → 全量扫描仍判 fix(只看最新会误判 normal)
|
|
9374
|
+
const multiWave = classifyCause({
|
|
9375
|
+
history: [
|
|
9376
|
+
familyExit('execute', divergentSignature, { at: '2026-09-20T00:00:00.000Z' }),
|
|
9377
|
+
familyExit('subagent-execute', plainSignature, { at: '2026-09-24T00:00:00.000Z' }),
|
|
9378
|
+
],
|
|
9379
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9380
|
+
});
|
|
9381
|
+
if (multiWave !== 'fix') {
|
|
9382
|
+
throw new Error('多波次历史旧签名发散(最新签名 == 当前)应判 fix(全量扫描),实际 ' + JSON.stringify(multiWave));
|
|
9383
|
+
}
|
|
9384
|
+
// ⑨ legacy 事件(无 change 字段)与既有 latestExecuteExitEvent 兼容语义一致:参与分类
|
|
9385
|
+
const legacyDivergence = classifyCause({
|
|
9386
|
+
history: [{ event: 'exit-applied', node: 'execute', at: '2026-09-20T00:00:00.000Z', taskSetSignature: divergentSignature }],
|
|
9387
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9388
|
+
});
|
|
9389
|
+
if (legacyDivergence !== 'fix') {
|
|
9390
|
+
throw new Error('无 change 字段的 legacy 出口事件应参与分类(发散 → fix),实际 ' + JSON.stringify(legacyDivergence));
|
|
9391
|
+
}
|
|
9392
|
+
|
|
9393
|
+
// ⑩ m-14 签名算法版本三态 + 冻结锚(分类器与 C3 消费点共用 route-node 谓词)
|
|
9394
|
+
// 冻结锚:算法版本升级必须先更新版本决策与测试锚——本断言变红强制该决策。
|
|
9395
|
+
if (routeNodeModule.TASK_SET_SIGNATURE_ALGO !== 'v1') {
|
|
9396
|
+
throw new Error('签名算法版本冻结锚失效:期望 v1,实际 '
|
|
9397
|
+
+ JSON.stringify(routeNodeModule.TASK_SET_SIGNATURE_ALGO)
|
|
9398
|
+
+ '——升级算法前必须先更新版本决策与测试锚');
|
|
9399
|
+
}
|
|
9400
|
+
const parseSig = requireRouteNodeExport('parseTaskSetSignature');
|
|
9401
|
+
const sameSig = requireRouteNodeExport('sameTaskSetSignature');
|
|
9402
|
+
const sigSkew = requireRouteNodeExport('taskSetSignatureVersionSkew');
|
|
9403
|
+
const versioned = routeNodeModule.taskSetSignature(plainTaskText);
|
|
9404
|
+
if (!/^v1:[0-9a-f]{64}$/.test(versioned)) {
|
|
9405
|
+
throw new Error('新版本签名值应为 v1:<sha256 hex>,实际 ' + JSON.stringify(versioned));
|
|
9406
|
+
}
|
|
9407
|
+
const versionedParsed = parseSig(versioned);
|
|
9408
|
+
if (!versionedParsed || versionedParsed.algo !== 'v1'
|
|
9409
|
+
|| versionedParsed.digest !== parseSig(signatureOf(plainTaskText)).digest) {
|
|
9410
|
+
throw new Error('parseTaskSetSignature 应解析 vN:<digest> 元数据,实际 ' + JSON.stringify(versionedParsed));
|
|
9411
|
+
}
|
|
9412
|
+
// legacy 裸 hex 按 v1 语义(旧 taskHash / 旧事件)
|
|
9413
|
+
const legacyParsed = parseSig(versionedParsed.digest);
|
|
9414
|
+
if (!legacyParsed || legacyParsed.algo !== 'v1' || legacyParsed.digest !== versionedParsed.digest) {
|
|
9415
|
+
throw new Error('legacy 裸 hex 应按 v1 解析,实际 ' + JSON.stringify(legacyParsed));
|
|
9416
|
+
}
|
|
9417
|
+
// C3 三态谓词:同版本同 digest 一致 / 同版本不同 digest 不一致 / 跨版本 skew 跳过比对
|
|
9418
|
+
if (!sameSig(versioned, 'v1:' + versionedParsed.digest)
|
|
9419
|
+
|| sameSig(versioned, 'v1:' + divergentSignature)
|
|
9420
|
+
|| sameSig(versioned, 'v2:' + versionedParsed.digest)) {
|
|
9421
|
+
throw new Error('同版本一致性谓词三态错误(sameTaskSetSignature)');
|
|
9422
|
+
}
|
|
9423
|
+
if (!sigSkew(versioned, 'v2:' + versionedParsed.digest)
|
|
9424
|
+
|| sigSkew(versioned, versioned)
|
|
9425
|
+
|| sigSkew(versioned, versionedParsed.digest)) {
|
|
9426
|
+
throw new Error('跨版本 skew 谓词三态错误(taskSetSignatureVersionSkew)');
|
|
9427
|
+
}
|
|
9428
|
+
if (parseSig('v1:not-a-digest') !== null || parseSig('') !== null || parseSig(null) !== null) {
|
|
9429
|
+
throw new Error('非法签名形态应解析为 null(fail-closed)');
|
|
9430
|
+
}
|
|
9431
|
+
// 分类器三态:新版本相等 → normal;legacy 裸 hex 相等 → normal(legacy=v1);
|
|
9432
|
+
// 跨版本 / 声明版本与值不一致 → 跳过比对(unknown,不误判 fix)。
|
|
9433
|
+
const versionedEqual = classifyCause({
|
|
9434
|
+
history: [familyExit('execute', versioned)],
|
|
9435
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9436
|
+
});
|
|
9437
|
+
if (versionedEqual !== 'normal') {
|
|
9438
|
+
throw new Error('新版本签名相等应判 normal,实际 ' + JSON.stringify(versionedEqual));
|
|
9439
|
+
}
|
|
9440
|
+
const legacyEqual = classifyCause({
|
|
9441
|
+
history: [familyExit('execute', versionedParsed.digest)],
|
|
9442
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9443
|
+
});
|
|
9444
|
+
if (legacyEqual !== 'normal') {
|
|
9445
|
+
throw new Error('legacy 裸 hex 与当前摘要相等应判 normal(legacy=v1),实际 ' + JSON.stringify(legacyEqual));
|
|
9446
|
+
}
|
|
9447
|
+
const crossVersion = classifyCause({
|
|
9448
|
+
history: [familyExit('execute', 'v2:' + divergentSignature, { signatureAlgo: 'v2' })],
|
|
9449
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9450
|
+
});
|
|
9451
|
+
if (crossVersion !== 'unknown') {
|
|
9452
|
+
throw new Error('跨算法版本历史事件应跳过比对(unknown,不误判 fix),实际 ' + JSON.stringify(crossVersion));
|
|
9453
|
+
}
|
|
9454
|
+
const mismatchedDeclared = classifyCause({
|
|
9455
|
+
history: [familyExit('execute', versioned, { signatureAlgo: 'v2' })],
|
|
9456
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
9457
|
+
});
|
|
9458
|
+
if (mismatchedDeclared !== 'unknown') {
|
|
9459
|
+
throw new Error('signatureAlgo 与值版本不一致的畸形事件应跳过(unknown),实际 ' + JSON.stringify(mismatchedDeclared));
|
|
9460
|
+
}
|
|
9461
|
+
},
|
|
9462
|
+
},
|
|
9463
|
+
|
|
9464
|
+
// 248: entry execute 受控归位(review 源)——Fix 回退态(review 驻留 + TASK pending + 共享谓词
|
|
9465
|
+
// 路由 execute)直接 entry execute:currentNode 归位 execute 并写盘 + FIX-BATCH 审计行;
|
|
9466
|
+
// 反例无 pending(全 done)→ 谓词 false 不归位(currentNode 保持 review、无审计行);
|
|
9467
|
+
// 边界:execute 尚未在 completedNodes(前序欠账态)但共享谓词成立 → 前置拦截不生效仍归位。
|
|
9468
|
+
{
|
|
9469
|
+
name: '248 entry execute 受控归位:review 源 Fix 态 → currentNode=execute + 审计行',
|
|
9470
|
+
run: (dir) => {
|
|
9471
|
+
writeIntakeArtifacts(dir);
|
|
9472
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
9473
|
+
const st = {
|
|
9474
|
+
activeChange: CHANGE_ID,
|
|
9475
|
+
currentNode: 'review',
|
|
9476
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
9477
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
9478
|
+
evidence: {
|
|
9479
|
+
execute: { summary: 'first pass executed' },
|
|
9480
|
+
review: { summary: 'review in progress' },
|
|
9481
|
+
},
|
|
9482
|
+
verifyFailures: 0,
|
|
9483
|
+
executionMode: 'subagent',
|
|
9484
|
+
directOverride: false,
|
|
9485
|
+
newChange: true,
|
|
9486
|
+
};
|
|
9487
|
+
// ① 正例:pending Fix 任务在场 → 受控归位 + 审计行 + 真实写盘
|
|
9488
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
9489
|
+
writeState(dir, st);
|
|
9490
|
+
const res = runGuard(['entry', 'execute'], dir);
|
|
9491
|
+
assertExit(res, 0);
|
|
9492
|
+
assertOut(res, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
9493
|
+
assertOut(res, 'ENTRY OK: execute');
|
|
9494
|
+
let after = readScenarioState(dir);
|
|
9495
|
+
if (after.currentNode !== 'execute') {
|
|
9496
|
+
throw new Error('受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
9497
|
+
}
|
|
9498
|
+
// ② 反例:无 pending(全 done)→ 不归位(机器字段保持 review;无审计行)
|
|
9499
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
9500
|
+
writeState(dir, st);
|
|
9501
|
+
const resNoFix = runGuard(['entry', 'execute'], dir);
|
|
9502
|
+
assertExit(resNoFix, 0);
|
|
9503
|
+
assertNotOut(resNoFix, 'FIX-BATCH');
|
|
9504
|
+
after = readScenarioState(dir);
|
|
9505
|
+
if (after.currentNode !== 'review') {
|
|
9506
|
+
throw new Error('无 pending 时 entry execute 不应归位(currentNode 应保持 review),实际 ' + JSON.stringify(after.currentNode));
|
|
9507
|
+
}
|
|
9508
|
+
// ③ 边界:execute 不在 completedNodes(欠账态)但共享谓词成立 → 前置拦截不生效,仍受控归位
|
|
9509
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
9510
|
+
writeState(dir, { ...st, completedNodes: ['open', 'design', 'plan'] });
|
|
9511
|
+
const resDrift = runGuard(['entry', 'execute'], dir);
|
|
9512
|
+
assertExit(resDrift, 0);
|
|
9513
|
+
assertOut(resDrift, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
9514
|
+
after = readScenarioState(dir);
|
|
9515
|
+
if (after.currentNode !== 'execute') {
|
|
9516
|
+
throw new Error('欠账态受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
9517
|
+
}
|
|
9518
|
+
// ④ m-12 第 1~3 轮递增(AC-4):逐轮重置驻留态,审计后缀第 n/3 轮且计数器同步 +1
|
|
9519
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
9520
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
9521
|
+
writeState(dir, st);
|
|
9522
|
+
const stRound = readScenarioState(dir);
|
|
9523
|
+
stRound.fixRoundsByChange = { [CHANGE_ID]: round - 1 };
|
|
9524
|
+
writeState(dir, stRound);
|
|
9525
|
+
const resRound = runGuard(['entry', 'execute'], dir);
|
|
9526
|
+
assertExit(resRound, 0);
|
|
9527
|
+
assertOut(resRound, 'FIX-BATCH: 受控归位 execute(源节点 review)(第 ' + round + '/3 轮)');
|
|
9528
|
+
const stAfterRound = readScenarioState(dir);
|
|
9529
|
+
if (stAfterRound.fixRoundsByChange?.[CHANGE_ID] !== round) {
|
|
9530
|
+
throw new Error('第 ' + round + ' 轮 entry 归位后计数器应为 ' + round + ',实际 '
|
|
9531
|
+
+ JSON.stringify(stAfterRound.fixRoundsByChange));
|
|
9532
|
+
}
|
|
9533
|
+
}
|
|
9534
|
+
// ⑤ 第 4 轮新 change BLOCK:state 字节零改写(不写 currentNode、不写计数器)
|
|
9535
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 3 } });
|
|
9536
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
9537
|
+
const beforeRound4 = fs.readFileSync(statePath, 'utf8');
|
|
9538
|
+
const resRound4 = runGuard(['entry', 'execute'], dir);
|
|
9539
|
+
assertExit(resRound4, 1);
|
|
9540
|
+
assertOut(resRound4, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
9541
|
+
assertOut(resRound4, '继续修');
|
|
9542
|
+
assertOut(resRound4, '停止');
|
|
9543
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeRound4) {
|
|
9544
|
+
throw new Error('第 4 轮 BLOCK 必须 state 字节零改写(不写 currentNode/计数器)');
|
|
9545
|
+
}
|
|
9546
|
+
const stBlocked = readScenarioState(dir);
|
|
9547
|
+
if (stBlocked.currentNode !== 'review' || stBlocked.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
9548
|
+
throw new Error('第 4 轮 BLOCK 后 currentNode 应保持 review、计数器保持 3,实际 '
|
|
9549
|
+
+ JSON.stringify({ currentNode: stBlocked.currentNode, rounds: stBlocked.fixRoundsByChange }));
|
|
9550
|
+
}
|
|
9551
|
+
// ⑤b F5:非法授权形态(仅 round,缺 at/source)在真实 entry 链路上仍按未授权 fail-closed——
|
|
9552
|
+
// 继续 BLOCK、state 字节零改写、currentNode 保持 review、计数器保持 3。
|
|
9553
|
+
const stBadOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
9554
|
+
stBadOverride.evidence.review.fixRoundOverride = { round: 4 };
|
|
9555
|
+
writeState(dir, stBadOverride);
|
|
9556
|
+
const badOverrideBytes = fs.readFileSync(statePath, 'utf8');
|
|
9557
|
+
const resBadOverride = runGuard(['entry', 'execute'], dir);
|
|
9558
|
+
assertExit(resBadOverride, 1);
|
|
9559
|
+
assertOut(resBadOverride, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
9560
|
+
assertNotOut(resBadOverride, '(第 4/3 轮)');
|
|
9561
|
+
if (fs.readFileSync(statePath, 'utf8') !== badOverrideBytes) {
|
|
9562
|
+
throw new Error('F5 缺 at/source 的授权形态必须在 entry 链路上 state 字节零改写');
|
|
9563
|
+
}
|
|
9564
|
+
const stBadAfter = readScenarioState(dir);
|
|
9565
|
+
if (stBadAfter.currentNode !== 'review' || stBadAfter.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
9566
|
+
throw new Error('F5 缺 at/source 不得放行第 4 轮(currentNode 保持 review、计数保持 3),实际 '
|
|
9567
|
+
+ JSON.stringify({ currentNode: stBadAfter.currentNode, rounds: stBadAfter.fixRoundsByChange }));
|
|
9568
|
+
}
|
|
9569
|
+
// ⑥ 用户显式授权(嵌套 evidence,完整三元组)→ 放行第 4 轮并写 currentNode + 计数器
|
|
9570
|
+
const stOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
9571
|
+
stOverride.evidence.review.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
9572
|
+
writeState(dir, stOverride);
|
|
9573
|
+
const resOverride = runGuard(['entry', 'execute'], dir);
|
|
9574
|
+
assertExit(resOverride, 0);
|
|
9575
|
+
assertOut(resOverride, '(第 4/3 轮)');
|
|
9576
|
+
const stAuthorized = readScenarioState(dir);
|
|
9577
|
+
if (stAuthorized.currentNode !== 'execute' || stAuthorized.fixRoundsByChange?.[CHANGE_ID] !== 4) {
|
|
9578
|
+
throw new Error('授权后第 4 轮应放行归位(currentNode=execute、计数器=4),实际 '
|
|
9579
|
+
+ JSON.stringify({ currentNode: stAuthorized.currentNode, rounds: stAuthorized.fixRoundsByChange }));
|
|
9580
|
+
}
|
|
9581
|
+
},
|
|
9582
|
+
},
|
|
9583
|
+
|
|
9584
|
+
// 249: entry execute 受控归位(verify 源)——verify 驻留 + 进行中证据/enteredNodes 在场时,
|
|
9585
|
+
// Fix 回退态归位不被进行中保护分支挡回 verify(归位是显式分支);无 pending 反例不归位。
|
|
9586
|
+
{
|
|
9587
|
+
name: '249 entry execute 受控归位:verify 源 Fix 态 → currentNode=execute + 审计行(进行中证据不挡)',
|
|
9588
|
+
run: (dir) => {
|
|
9589
|
+
writeIntakeArtifacts(dir);
|
|
9590
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
9591
|
+
const st = {
|
|
9592
|
+
activeChange: CHANGE_ID,
|
|
9593
|
+
currentNode: 'verify',
|
|
9594
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
9595
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'],
|
|
9596
|
+
evidence: {
|
|
9597
|
+
execute: { summary: 'first pass executed' },
|
|
9598
|
+
review: { summary: 'review complete' },
|
|
9599
|
+
verify: { summary: 'verify in progress' },
|
|
9600
|
+
},
|
|
9601
|
+
verifyFailures: 0,
|
|
9602
|
+
executionMode: 'subagent',
|
|
9603
|
+
directOverride: false,
|
|
9604
|
+
newChange: true,
|
|
9605
|
+
};
|
|
9606
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
9607
|
+
writeState(dir, st);
|
|
9608
|
+
const res = runGuard(['entry', 'execute'], dir);
|
|
9609
|
+
assertExit(res, 0);
|
|
9610
|
+
assertOut(res, 'FIX-BATCH: 受控归位 execute(源节点 verify)');
|
|
9611
|
+
let after = readScenarioState(dir);
|
|
9612
|
+
if (after.currentNode !== 'execute') {
|
|
9613
|
+
throw new Error('verify 源受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
9614
|
+
}
|
|
9615
|
+
// 反例:全 done(无 pending)→ 不归位,currentNode 保持 verify
|
|
9616
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
9617
|
+
writeState(dir, st);
|
|
9618
|
+
const resNoFix = runGuard(['entry', 'execute'], dir);
|
|
9619
|
+
assertExit(resNoFix, 0);
|
|
9620
|
+
assertNotOut(resNoFix, 'FIX-BATCH');
|
|
9621
|
+
after = readScenarioState(dir);
|
|
9622
|
+
if (after.currentNode !== 'verify') {
|
|
9623
|
+
throw new Error('无 pending 时 entry execute 不应归位(currentNode 应保持 verify),实际 ' + JSON.stringify(after.currentNode));
|
|
9624
|
+
}
|
|
9625
|
+
// ③ m-12/AC-5 计数隔离:verify 源归位只增 Fix 轮次,verify 失败计数保持不动
|
|
9626
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
9627
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 1 }, verifyFailuresByChange: { [CHANGE_ID]: 2 } });
|
|
9628
|
+
const resRound2 = runGuard(['entry', 'execute'], dir);
|
|
9629
|
+
assertExit(resRound2, 0);
|
|
9630
|
+
assertOut(resRound2, '受控归位 execute(源节点 verify)(第 2/3 轮)');
|
|
9631
|
+
let stIsolated = readScenarioState(dir);
|
|
9632
|
+
if (stIsolated.fixRoundsByChange?.[CHANGE_ID] !== 2 || stIsolated.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
9633
|
+
throw new Error('verify 源归位应只增 Fix 轮次(2)、verify 失败计数保持 2,实际 '
|
|
9634
|
+
+ JSON.stringify({ rounds: stIsolated.fixRoundsByChange, verifyFailures: stIsolated.verifyFailuresByChange }));
|
|
9635
|
+
}
|
|
9636
|
+
// ④ 第 4 轮 BLOCK + state 字节零改写 + 授权放行(verify 源)
|
|
9637
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 3 }, verifyFailuresByChange: { [CHANGE_ID]: 2 } });
|
|
9638
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
9639
|
+
const beforeBlocked = fs.readFileSync(statePath, 'utf8');
|
|
9640
|
+
const resBlocked = runGuard(['entry', 'execute'], dir);
|
|
9641
|
+
assertExit(resBlocked, 1);
|
|
9642
|
+
assertOut(resBlocked, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
9643
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeBlocked) {
|
|
9644
|
+
throw new Error('verify 源第 4 轮 BLOCK 必须 state 字节零改写');
|
|
9645
|
+
}
|
|
9646
|
+
const stVBlocked = readScenarioState(dir);
|
|
9647
|
+
if (stVBlocked.currentNode !== 'verify' || stVBlocked.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
9648
|
+
throw new Error('verify 源第 4 轮 BLOCK 后 currentNode/verify 计数不得改写,实际 '
|
|
9649
|
+
+ JSON.stringify({ currentNode: stVBlocked.currentNode, verifyFailures: stVBlocked.verifyFailuresByChange }));
|
|
9650
|
+
}
|
|
9651
|
+
const stVOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
9652
|
+
stVOverride.evidence.verify.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
9653
|
+
writeState(dir, stVOverride);
|
|
9654
|
+
const resVOverride = runGuard(['entry', 'execute'], dir);
|
|
9655
|
+
assertExit(resVOverride, 0);
|
|
9656
|
+
assertOut(resVOverride, '(第 4/3 轮)');
|
|
9657
|
+
const stVAfter = readScenarioState(dir);
|
|
9658
|
+
if (stVAfter.currentNode !== 'execute' || stVAfter.fixRoundsByChange?.[CHANGE_ID] !== 4
|
|
9659
|
+
|| stVAfter.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
9660
|
+
throw new Error('verify 源授权放行后应 currentNode=execute、轮次=4、verify 计数保持 2,实际 '
|
|
9661
|
+
+ JSON.stringify({ currentNode: stVAfter.currentNode, rounds: stVAfter.fixRoundsByChange, verifyFailures: stVAfter.verifyFailuresByChange }));
|
|
9662
|
+
}
|
|
9663
|
+
},
|
|
9664
|
+
},
|
|
9665
|
+
|
|
9666
|
+
// 250: exit execute --apply Fix 二次完成回源(review 源)——execute 在 exit 前已在
|
|
9667
|
+
// completedNodes + TASK 全 done:REVIEW.md 已在场(resolveNextNode 会按产物跳过 review 到
|
|
9668
|
+
// verify)但 review 未完成 → 受控回程 review(源节点出口必须真实执行,不被产物存在性跳过)。
|
|
9669
|
+
// 本场景族拆自原 250 单场景,断言与失败信息保持不变;本段覆盖回源归属与出口事件形状。
|
|
9670
|
+
{
|
|
9671
|
+
name: '250 exit execute --apply Fix 二次完成:回源 review(REVIEW.md 在场但不按产物跳过)',
|
|
9672
|
+
run: (dir) => {
|
|
9673
|
+
writeIntakeArtifacts(dir);
|
|
9674
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
9675
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
9676
|
+
writeFixReturnSummaries(dir, ['T01', 'T-FIX-01']);
|
|
9677
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', FIX_RETURN_REVIEW_TEXT);
|
|
9678
|
+
writeState(dir, {
|
|
9679
|
+
activeChange: CHANGE_ID,
|
|
9680
|
+
currentNode: 'execute',
|
|
9681
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
9682
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
9683
|
+
evidence: {
|
|
9684
|
+
execute: { summary: 'fix batch executed' },
|
|
9685
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(['T01', 'T-FIX-01']) },
|
|
9686
|
+
review: { summary: 'review in progress' },
|
|
9687
|
+
},
|
|
9688
|
+
verifyFailures: 0,
|
|
9689
|
+
executionMode: 'subagent',
|
|
9690
|
+
directOverride: false,
|
|
9691
|
+
newChange: true,
|
|
9692
|
+
});
|
|
9693
|
+
const res = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9694
|
+
assertExit(res, 0);
|
|
9695
|
+
assertOut(res, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9696
|
+
assertOut(res, 'NODE: review');
|
|
9697
|
+
assertNotOut(res, 'NODE: verify');
|
|
9698
|
+
const after = readScenarioState(dir);
|
|
9699
|
+
if (after.currentNode !== 'review') {
|
|
9700
|
+
throw new Error('Fix 回程后 currentNode 应为 review,实际 ' + JSON.stringify(after.currentNode));
|
|
9701
|
+
}
|
|
9702
|
+
// 出口事件须带本 change 归属 + 任务集签名(跨 change 保留 history 时按 change 过滤)。
|
|
9703
|
+
const lastExit = (after.history || []).filter((e) => e && e.event === 'exit-applied').pop();
|
|
9704
|
+
if (!lastExit || lastExit.node !== 'execute' || lastExit.change !== CHANGE_ID
|
|
9705
|
+
|| typeof lastExit.taskSetSignature !== 'string' || lastExit.taskSetSignature === '') {
|
|
9706
|
+
throw new Error('exit execute --apply 应记录带 change 与 taskSetSignature 的出口事件,实际 '
|
|
9707
|
+
+ JSON.stringify(lastExit));
|
|
9708
|
+
}
|
|
9709
|
+
|
|
9710
|
+
// 250e 源未 entry 的真实 Fix:修复任务 + enteredNodes 不含源节点 review + 历史无
|
|
9711
|
+
// 签名(旧态)→ 结构标记仍恢复 fix 标签,保留 FIX-BATCH;不误判 unknown、不卡死。
|
|
9712
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
9713
|
+
writeState(dir, fixReturnBaseState({
|
|
9714
|
+
evidence: fixReturnFamilyEvidence(['T01', 'T-FIX-01']),
|
|
9715
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
9716
|
+
history: [],
|
|
9717
|
+
}));
|
|
9718
|
+
const resSourceNotEntered = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9719
|
+
assertExit(resSourceNotEntered, 0);
|
|
9720
|
+
assertOut(resSourceNotEntered, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9721
|
+
assertOut(resSourceNotEntered, 'NODE: review');
|
|
9722
|
+
assertNotOut(resSourceNotEntered, 'RETURN: 回源节点');
|
|
9723
|
+
assertNotOut(resSourceNotEntered, 'BLOCKED');
|
|
9724
|
+
},
|
|
9725
|
+
},
|
|
9726
|
+
|
|
9727
|
+
// 250b: 回程行分类与 Fix 段标题路径——历史全量扫描 / 旧态未分类 / 模板派生与缺失回退。
|
|
9728
|
+
// 本场景族拆自原 250 单场景,断言与失败信息保持不变。
|
|
9729
|
+
{
|
|
9730
|
+
name: '250b 回程行分类与 Fix 段标题路径:历史扫描、旧态未分类、模板派生与回退',
|
|
9731
|
+
run: (dir) => {
|
|
9732
|
+
writeIntakeArtifacts(dir);
|
|
9733
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
9734
|
+
writeFixReturnSummaries(dir, ['T01', 'T-FIX-01']);
|
|
9735
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', FIX_RETURN_REVIEW_TEXT);
|
|
9736
|
+
|
|
9737
|
+
// 250d 反向构造(L-064)——与 250c 一一对应证明分类依据是历史全量扫描(不是只看
|
|
9738
|
+
// 最新):① 无 Fix 编号任务 + 旧签名 ≠ 当前 + 最新签名 == 当前 → 仍判 fix(发散证据
|
|
9739
|
+
// 不依赖结构标记);② 同任务集仅保留最新(签名 == 当前)→ 必须中性 RETURN。
|
|
9740
|
+
const plainTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n';
|
|
9741
|
+
const plainSignature = routeNodeModule.taskSetSignature(plainTaskText);
|
|
9742
|
+
writeFile(dir, taskPath, plainTaskText);
|
|
9743
|
+
writeState(dir, fixReturnBaseState({
|
|
9744
|
+
history: [
|
|
9745
|
+
{
|
|
9746
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
9747
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
9748
|
+
},
|
|
9749
|
+
{
|
|
9750
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
9751
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: plainSignature,
|
|
9752
|
+
},
|
|
9753
|
+
],
|
|
9754
|
+
}));
|
|
9755
|
+
const resDivergentPlain = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9756
|
+
assertExit(resDivergentPlain, 0);
|
|
9757
|
+
assertOut(resDivergentPlain, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9758
|
+
assertNotOut(resDivergentPlain, 'RETURN: 回源节点');
|
|
9759
|
+
writeState(dir, fixReturnBaseState({
|
|
9760
|
+
history: [{
|
|
9761
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
9762
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: plainSignature,
|
|
9763
|
+
}],
|
|
9764
|
+
}));
|
|
9765
|
+
const resLatestOnlyEqual = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9766
|
+
assertExit(resLatestOnlyEqual, 0);
|
|
9767
|
+
assertOut(resLatestOnlyEqual, 'RETURN: 回源节点 review(execute 出口已完成;正常多趟收尾,非 Fix 回修)');
|
|
9768
|
+
assertNotOut(resLatestOnlyEqual, 'FIX-BATCH');
|
|
9769
|
+
|
|
9770
|
+
// 250f 旧态无签名无标记:历史家族出口无签名 + 任务集无 Fix 标记 → RETURN 未分类;
|
|
9771
|
+
// 不 BLOCK、不出现 FIX-BATCH;NODE/state 与收口前一致(只有审计行变化)。
|
|
9772
|
+
writeState(dir, fixReturnBaseState({
|
|
9773
|
+
history: [{
|
|
9774
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
9775
|
+
at: '2026-09-19T00:00:00.000Z',
|
|
9776
|
+
}],
|
|
9777
|
+
}));
|
|
9778
|
+
const beforeUnknown = readScenarioState(dir);
|
|
9779
|
+
const resUnknown = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9780
|
+
assertExit(resUnknown, 0);
|
|
9781
|
+
assertOut(resUnknown, 'RETURN: 回源节点 review(execute 出口已完成;旧 state 缺闭合/修复证据,未分类)');
|
|
9782
|
+
assertOut(resUnknown, 'NODE: review');
|
|
9783
|
+
assertNotOut(resUnknown, 'FIX-BATCH');
|
|
9784
|
+
assertNotOut(resUnknown, 'BLOCKED');
|
|
9785
|
+
const afterUnknown = readScenarioState(dir);
|
|
9786
|
+
if (afterUnknown.currentNode !== 'review' || afterUnknown.completedNodes.join(',') !== FIX_RETURN_FAMILY_COMPLETED) {
|
|
9787
|
+
throw new Error('未分类回程应只覆盖路由到 review 且 completedNodes 不变,实际 '
|
|
9788
|
+
+ JSON.stringify({ currentNode: afterUnknown.currentNode, completedNodes: afterUnknown.completedNodes }));
|
|
9789
|
+
}
|
|
9790
|
+
assertStateOnlyChanged(beforeUnknown, afterUnknown, {
|
|
9791
|
+
label: '250f 旧态未分类回程',
|
|
9792
|
+
allowed: ['currentNode', 'status', 'history'],
|
|
9793
|
+
});
|
|
9794
|
+
|
|
9795
|
+
// 250g Fix 段标题从 flow-kit/templates/TASK.md 派生(决策 4):模板段名含括号说明 +
|
|
9796
|
+
// 段内非 FIX 编号任务 → 结构标记命中 fix(模板读取路径真实被执行;标题由模板派生)。
|
|
9797
|
+
writeFile(dir, 'flow-kit/templates/TASK.md',
|
|
9798
|
+
'# TASK 模板\n\n## Fix 任务(来自 REVIEW / INTEGRATION)\n');
|
|
9799
|
+
const sectionTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
9800
|
+
+ '## Fix 任务(来自 REVIEW / INTEGRATION)\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
9801
|
+
writeFile(dir, taskPath, sectionTaskText);
|
|
9802
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T02-SUMMARY.md', strictSummary('T02'));
|
|
9803
|
+
const sectionSignature = routeNodeModule.taskSetSignature(sectionTaskText);
|
|
9804
|
+
writeState(dir, fixReturnBaseState({
|
|
9805
|
+
evidence: fixReturnFamilyEvidence(['T01', 'T02']),
|
|
9806
|
+
history: [{
|
|
9807
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
9808
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: sectionSignature,
|
|
9809
|
+
}],
|
|
9810
|
+
}));
|
|
9811
|
+
const resSection = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9812
|
+
assertExit(resSection, 0);
|
|
9813
|
+
assertOut(resSection, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9814
|
+
assertNotOut(resSection, 'RETURN: 回源节点');
|
|
9815
|
+
|
|
9816
|
+
// 250h m-06 模板缺失 + 闭合 ATX + 非 FIX 编号:guard 无模板派生标题 → 回退内置
|
|
9817
|
+
// 「Fix 任务」,段内 T02 由结构标记判 fix(模板缺席不得让 Fix 批次漏判)。
|
|
9818
|
+
fs.rmSync(path.join(dir, 'flow-kit', 'templates', 'TASK.md'), { force: true });
|
|
9819
|
+
const missingTplTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
9820
|
+
+ '## Fix 任务 ##\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
9821
|
+
writeFile(dir, taskPath, missingTplTaskText);
|
|
9822
|
+
writeState(dir, fixReturnBaseState({ evidence: fixReturnFamilyEvidence(['T01', 'T02']), history: [] }));
|
|
9823
|
+
const resMissingTpl = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9824
|
+
assertExit(resMissingTpl, 0);
|
|
9825
|
+
assertOut(resMissingTpl, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9826
|
+
assertNotOut(resMissingTpl, 'RETURN: 回源节点');
|
|
9827
|
+
assertNotOut(resMissingTpl, 'BLOCKED');
|
|
9828
|
+
|
|
9829
|
+
// 250i m-06 模板基名不同(Fix Tasks)+ 闭合 ATX + 非 FIX 编号:标题归一来自共享权威,
|
|
9830
|
+
// 语言后缀可变仍命中 Fix 段(旧硬编码中文基名会漏判 → RETURN-normal)。
|
|
9831
|
+
writeFile(dir, 'flow-kit/templates/TASK.md',
|
|
9832
|
+
'# TASK 模板\n\n## Fix Tasks(来自 REVIEW / INTEGRATION)\n');
|
|
9833
|
+
const renamedTplTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
9834
|
+
+ '## Fix Tasks ##\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
9835
|
+
writeFile(dir, taskPath, renamedTplTaskText);
|
|
9836
|
+
writeState(dir, fixReturnBaseState({ evidence: fixReturnFamilyEvidence(['T01', 'T02']), history: [] }));
|
|
9837
|
+
const resRenamedTpl = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9838
|
+
assertExit(resRenamedTpl, 0);
|
|
9839
|
+
assertOut(resRenamedTpl, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9840
|
+
assertNotOut(resRenamedTpl, 'RETURN: 回源节点');
|
|
9841
|
+
assertNotOut(resRenamedTpl, 'BLOCKED');
|
|
9842
|
+
},
|
|
9843
|
+
},
|
|
9844
|
+
|
|
9845
|
+
// 250c: 多趟收尾与签名元数据——中性回程 / 多波次真实修复 / 任务集签名同版本三态。
|
|
9846
|
+
// 本场景族拆自原 250 单场景,断言与失败信息保持不变。
|
|
9847
|
+
{
|
|
9848
|
+
name: '250c 多趟收尾与签名元数据:中性回程、多波次修复、任务集签名三态',
|
|
9849
|
+
run: (dir) => {
|
|
9850
|
+
writeIntakeArtifacts(dir);
|
|
9851
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
9852
|
+
writeFixReturnSummaries(dir, ['T01', 'T-FIX-01']);
|
|
9853
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', FIX_RETURN_REVIEW_TEXT);
|
|
9854
|
+
// state 不变量统一走 assertStateOnlyChanged(白名单外深比 + history 旧前缀稳定 + 恰新增
|
|
9855
|
+
// 一条 exit-applied)——白名单仅 currentNode(既有路由覆盖 next)、status(既有 apply 写
|
|
9856
|
+
// running/completed)、history(既有出口事件追加);execute 证据的 completedChecks 已预置,
|
|
9857
|
+
// 不在白名单内假豁免。
|
|
9858
|
+
|
|
9859
|
+
// 250b 正常多趟最终 exit:无 Fix 任务、历史家族出口签名 == 当前 TASK 签名 → 中性
|
|
9860
|
+
// RETURN(正常多趟收尾,非 Fix 回修);不得出现 FIX-BATCH;NODE/state 与收口前一致。
|
|
9861
|
+
const normalTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n';
|
|
9862
|
+
const normalSignature = routeNodeModule.taskSetSignature(normalTaskText);
|
|
9863
|
+
writeFile(dir, taskPath, normalTaskText);
|
|
9864
|
+
writeState(dir, fixReturnBaseState({
|
|
9865
|
+
history: [{
|
|
9866
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
9867
|
+
at: '2026-09-23T00:00:00.000Z', taskSetSignature: normalSignature,
|
|
9868
|
+
}],
|
|
9869
|
+
}));
|
|
9870
|
+
const beforeNormal = readScenarioState(dir);
|
|
9871
|
+
const resNormal = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9872
|
+
assertExit(resNormal, 0);
|
|
9873
|
+
assertOut(resNormal, 'RETURN: 回源节点 review(execute 出口已完成;正常多趟收尾,非 Fix 回修)');
|
|
9874
|
+
assertOut(resNormal, 'NODE: review');
|
|
9875
|
+
assertNotOut(resNormal, 'FIX-BATCH');
|
|
9876
|
+
assertNotOut(resNormal, 'NODE: verify');
|
|
9877
|
+
const afterNormal = readScenarioState(dir);
|
|
9878
|
+
if (afterNormal.currentNode !== 'review' || afterNormal.completedNodes.join(',') !== FIX_RETURN_FAMILY_COMPLETED) {
|
|
9879
|
+
throw new Error('正常多趟回程应只覆盖路由到 review 且 completedNodes 不变,实际 '
|
|
9880
|
+
+ JSON.stringify({ currentNode: afterNormal.currentNode, completedNodes: afterNormal.completedNodes }));
|
|
9881
|
+
}
|
|
9882
|
+
const [normalAppended] = assertStateOnlyChanged(beforeNormal, afterNormal, {
|
|
9883
|
+
label: '250b 正常多趟回程',
|
|
9884
|
+
allowed: ['currentNode', 'status', 'history'],
|
|
9885
|
+
});
|
|
9886
|
+
// m-14 新版本元数据锚:exit-applied 事件带 signatureAlgo 且签名值为 vN:<digest> 形态
|
|
9887
|
+
if (!normalAppended || normalAppended.node !== 'execute' || normalAppended.change !== CHANGE_ID
|
|
9888
|
+
|| normalAppended.taskSetSignature !== normalSignature
|
|
9889
|
+
|| !/^v\d+:[0-9a-f]{64}$/.test(String(normalAppended.taskSetSignature))
|
|
9890
|
+
|| normalAppended.signatureAlgo !== routeNodeModule.TASK_SET_SIGNATURE_ALGO) {
|
|
9891
|
+
throw new Error('正常多趟出口事件应记录本 change + vN:<digest> 签名 + signatureAlgo 元数据,实际 '
|
|
9892
|
+
+ JSON.stringify(normalAppended));
|
|
9893
|
+
}
|
|
9894
|
+
const normalExit = (afterNormal.history || []).pop();
|
|
9895
|
+
if (!normalExit || normalExit.node !== 'execute' || normalExit.change !== CHANGE_ID
|
|
9896
|
+
|| normalExit.taskSetSignature !== normalSignature) {
|
|
9897
|
+
throw new Error('正常多趟出口事件形状应与既有一致(node/change/taskSetSignature),实际 '
|
|
9898
|
+
+ JSON.stringify(normalExit));
|
|
9899
|
+
}
|
|
9900
|
+
|
|
9901
|
+
// 250c 多波次真实 Fix:历史旧签名 ≠ 当前、最新签名 == 当前(只看最新会漏判)→ 保留
|
|
9902
|
+
// FIX-BATCH(全量扫描);TASK 含修复任务与结构标记。
|
|
9903
|
+
const multiWaveTaskText = fixBatchTaskText('done');
|
|
9904
|
+
const multiWaveSignature = routeNodeModule.taskSetSignature(multiWaveTaskText);
|
|
9905
|
+
writeFile(dir, taskPath, multiWaveTaskText);
|
|
9906
|
+
writeState(dir, fixReturnBaseState({
|
|
9907
|
+
evidence: fixReturnFamilyEvidence(['T01', 'T-FIX-01']),
|
|
9908
|
+
history: [
|
|
9909
|
+
{
|
|
9910
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
9911
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
9912
|
+
},
|
|
9913
|
+
{
|
|
9914
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
9915
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: multiWaveSignature,
|
|
9916
|
+
},
|
|
9917
|
+
],
|
|
9918
|
+
}));
|
|
9919
|
+
const resMultiWave = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9920
|
+
assertExit(resMultiWave, 0);
|
|
9921
|
+
assertOut(resMultiWave, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
9922
|
+
assertOut(resMultiWave, 'NODE: review');
|
|
9923
|
+
assertNotOut(resMultiWave, 'RETURN: 回源节点');
|
|
9924
|
+
|
|
9925
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T02-SUMMARY.md', strictSummary('T02'));
|
|
9926
|
+
// 250j~l m-14 C3 三态(guard exit 入口签名比对消费点):同版本一致 → 放行;
|
|
9927
|
+
// 同版本不一致 → BLOCK;跨算法版本 → SIGNATURE-ALGO WARN 跳过比对不阻断。
|
|
9928
|
+
writeFile(dir, 'flow-kit/templates/TASK.md',
|
|
9929
|
+
'# TASK 模板\n\n## Fix Tasks(来自 REVIEW / INTEGRATION)\n');
|
|
9930
|
+
const renamedTplTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
9931
|
+
+ '## Fix Tasks ##\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
9932
|
+
writeFile(dir, taskPath, renamedTplTaskText);
|
|
9933
|
+
const c3Evidence = fixReturnFamilyEvidence(['T01', 'T02']);
|
|
9934
|
+
const c3Digest = routeNodeModule.parseTaskSetSignature(
|
|
9935
|
+
routeNodeModule.taskSetSignature(renamedTplTaskText))?.digest;
|
|
9936
|
+
writeState(dir, fixReturnBaseState({ evidence: c3Evidence, history: [], taskHash: routeNodeModule.taskSetSignature(renamedTplTaskText) }));
|
|
9937
|
+
const resC3Same = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9938
|
+
assertExit(resC3Same, 0);
|
|
9939
|
+
assertNotOut(resC3Same, 'BLOCKED');
|
|
9940
|
+
// 同版本不一致(占位 digest)→ 新 change BLOCK 任务集被修改
|
|
9941
|
+
writeState(dir, fixReturnBaseState({ evidence: c3Evidence, history: [], taskHash: 'v1:' + '0'.repeat(64) }));
|
|
9942
|
+
const resC3Diff = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9943
|
+
assertExit(resC3Diff, 1);
|
|
9944
|
+
assertOut(resC3Diff, 'BLOCKED: TASK.md 任务集被修改');
|
|
9945
|
+
// 跨算法版本(v2 值 + v2 声明)→ 不可比,WARN 跳过比对,不误拦任务集
|
|
9946
|
+
writeState(dir, fixReturnBaseState({ evidence: c3Evidence, history: [], taskHash: 'v2:' + c3Digest }));
|
|
9947
|
+
const resC3Skew = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9948
|
+
assertExit(resC3Skew, 0);
|
|
9949
|
+
assertOut(resC3Skew, 'SIGNATURE-ALGO WARN');
|
|
9950
|
+
assertNotOut(resC3Skew, 'BLOCKED: TASK.md 任务集被修改');
|
|
9951
|
+
},
|
|
9952
|
+
},
|
|
9953
|
+
|
|
9954
|
+
// 251: exit execute --apply Fix 二次完成回源(verify 源)——TEST.md/UAT.md 已在场
|
|
9955
|
+
// (resolveNextNode 会按产物跳过 verify 去 archive)但 verify 未完成 → 受控回程 verify。
|
|
9956
|
+
{
|
|
9957
|
+
name: '251 exit execute --apply Fix 二次完成:回源 verify(TEST/UAT 在场但不按产物跳过)',
|
|
9958
|
+
run: (dir) => {
|
|
9959
|
+
writeIntakeArtifacts(dir);
|
|
9960
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTaskText('done'));
|
|
9961
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
9962
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
9963
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
9964
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\n审查结论已记录;待回源 verify 重新出口。\n');
|
|
9965
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```bash\nnode -e "1"\n```\n');
|
|
9966
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n## 验收\n\n- 通过\n');
|
|
9967
|
+
writeState(dir, {
|
|
9968
|
+
activeChange: CHANGE_ID,
|
|
9969
|
+
currentNode: 'execute',
|
|
9970
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
9971
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'],
|
|
9972
|
+
evidence: {
|
|
9973
|
+
execute: { summary: 'fix batch executed' },
|
|
9974
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(['T01', 'T-FIX-01']) },
|
|
9975
|
+
review: { summary: 'review complete' },
|
|
9976
|
+
verify: { summary: 'verify in progress' },
|
|
9977
|
+
},
|
|
9978
|
+
verifyFailures: 0,
|
|
9979
|
+
executionMode: 'subagent',
|
|
9980
|
+
directOverride: false,
|
|
9981
|
+
newChange: true,
|
|
9982
|
+
});
|
|
9983
|
+
const res = runGuard(['exit', 'execute', '--apply'], dir);
|
|
9984
|
+
assertExit(res, 0);
|
|
9985
|
+
assertOut(res, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
9986
|
+
assertOut(res, 'NODE: verify');
|
|
9987
|
+
assertNotOut(res, 'NODE: archive');
|
|
9988
|
+
const after = readScenarioState(dir);
|
|
9989
|
+
if (after.currentNode !== 'verify') {
|
|
9990
|
+
throw new Error('Fix 回程后 currentNode 应为 verify,实际 ' + JSON.stringify(after.currentNode));
|
|
9991
|
+
}
|
|
9992
|
+
},
|
|
9993
|
+
},
|
|
9994
|
+
|
|
9995
|
+
// 252: 越界拦截 + 恢复 + 旧 change 渐进——源节点(review/verify)驻留且 TASK 有 pending Fix
|
|
9996
|
+
// 任务时直接 exit 源节点收场:新 change BLOCKED 且含恢复指引(不许静默跳过 execute 出口门禁);
|
|
9997
|
+
// 按指引 entry execute 归位 → 完成修复 → exit execute 回源节点可恢复;
|
|
9998
|
+
// done-but-unclosed 变体(全任务 done 但本批 execute 出口未重跑:history 最新 exit execute
|
|
9999
|
+
// 签名与当前任务集不等)同样 BLOCKED 且 state 零改写,闭合后源节点出口恢复通过;
|
|
10000
|
+
// 旧 change(无 newChange 标记)保持渐进 WARN 不阻断(向后兼容)。
|
|
10001
|
+
{
|
|
10002
|
+
name: '252 越界:源节点 + pending/done-but-unclosed Fix 直接 exit 源节点 BLOCK(新)/WARN(旧)+ 恢复闭环',
|
|
10003
|
+
run: (dir) => {
|
|
10004
|
+
writeIntakeArtifacts(dir);
|
|
10005
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
10006
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
10007
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10008
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
10009
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\n审查发现需修复项,Fix 任务已追加;待 execute 出口完成后重新出口。\n');
|
|
10010
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
10011
|
+
const reviewState = {
|
|
10012
|
+
activeChange: CHANGE_ID,
|
|
10013
|
+
currentNode: 'review',
|
|
10014
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
10015
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
10016
|
+
evidence: {
|
|
10017
|
+
execute: { summary: 'first pass executed' },
|
|
10018
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(['T01']) },
|
|
10019
|
+
review: { summary: 'review in progress' },
|
|
10020
|
+
},
|
|
10021
|
+
verifyFailures: 0,
|
|
10022
|
+
executionMode: 'subagent',
|
|
10023
|
+
directOverride: false,
|
|
10024
|
+
newChange: true,
|
|
10025
|
+
};
|
|
10026
|
+
// ① 新 change:review 源直接 exit review --apply → BLOCKED + 恢复指引(不得静默放行)
|
|
10027
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10028
|
+
writeState(dir, reviewState);
|
|
10029
|
+
const resBlock = runGuard(['exit', 'review', '--apply'], dir);
|
|
10030
|
+
assertExit(resBlock, 1);
|
|
10031
|
+
assertOut(resBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10032
|
+
assertOut(resBlock, 'entry execute');
|
|
10033
|
+
assertNotOut(resBlock, 'ALL CHECKS PASSED');
|
|
10034
|
+
let after = readScenarioState(dir);
|
|
10035
|
+
if (after.currentNode !== 'review' || after.completedNodes.includes('review')) {
|
|
10036
|
+
throw new Error('BLOCK 不得改写 state(review 未完成/未推进),实际 '
|
|
10037
|
+
+ JSON.stringify({ currentNode: after.currentNode, completedNodes: after.completedNodes }));
|
|
10038
|
+
}
|
|
10039
|
+
// ② 恢复:entry execute 受控归位 → 完成 Fix 任务并补 SUMMARY/handoff → exit execute 回源 review
|
|
10040
|
+
const recEntry = runGuard(['entry', 'execute'], dir);
|
|
10041
|
+
assertExit(recEntry, 0);
|
|
10042
|
+
assertOut(recEntry, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
10043
|
+
after = readScenarioState(dir);
|
|
10044
|
+
if (after.currentNode !== 'execute') {
|
|
10045
|
+
throw new Error('恢复步 entry execute 应归位 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10046
|
+
}
|
|
10047
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10048
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10049
|
+
after = readScenarioState(dir);
|
|
10050
|
+
after.evidence['subagent-execute'] = after.evidence['subagent-execute'] || {};
|
|
10051
|
+
after.evidence['subagent-execute'].handoffResult = {
|
|
10052
|
+
...(after.evidence['subagent-execute'].handoffResult || {}),
|
|
10053
|
+
...handoffFor(['T-FIX-01']),
|
|
10054
|
+
};
|
|
10055
|
+
writeState(dir, after);
|
|
10056
|
+
const recExit = runGuard(['exit', 'execute', '--apply'], dir);
|
|
10057
|
+
assertExit(recExit, 0);
|
|
10058
|
+
assertOut(recExit, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
10059
|
+
if (readScenarioState(dir).currentNode !== 'review') {
|
|
10060
|
+
throw new Error('恢复闭环 exit execute 后应回源 review,实际 ' + JSON.stringify(readScenarioState(dir).currentNode));
|
|
10061
|
+
}
|
|
10062
|
+
// ③ 新 change:verify 源 + TEST/UAT 产物在场(原路径会跳过 verify 去 archive)→ 同样 BLOCKED
|
|
10063
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```bash\nnode -e "1"\n```\n');
|
|
10064
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n## 验收\n\n- 通过\n');
|
|
10065
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10066
|
+
writeState(dir, {
|
|
10067
|
+
...reviewState,
|
|
10068
|
+
currentNode: 'verify',
|
|
10069
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
10070
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'],
|
|
10071
|
+
evidence: { ...reviewState.evidence, verify: { summary: 'verify in progress' } },
|
|
10072
|
+
});
|
|
10073
|
+
const resVerifyBlock = runGuard(['exit', 'verify', '--apply'], dir);
|
|
10074
|
+
assertExit(resVerifyBlock, 1);
|
|
10075
|
+
assertOut(resVerifyBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10076
|
+
assertOut(resVerifyBlock, 'entry execute');
|
|
10077
|
+
assertNotOut(resVerifyBlock, 'ALL CHECKS PASSED');
|
|
10078
|
+
after = readScenarioState(dir);
|
|
10079
|
+
if (after.currentNode !== 'verify' || after.completedNodes.includes('verify')) {
|
|
10080
|
+
throw new Error('verify 源 BLOCK 不得改写 state,实际 '
|
|
10081
|
+
+ JSON.stringify({ currentNode: after.currentNode, completedNodes: after.completedNodes }));
|
|
10082
|
+
}
|
|
10083
|
+
// ③b 越界恢复指引优先于通用 entry 提示:同路径但无 enter 痕迹(enteredNodes 缺失)
|
|
10084
|
+
// 仍须给 Fix 恢复指引(不得被「未执行 entry 直接 exit」通用提示覆盖)。
|
|
10085
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10086
|
+
writeState(dir, { ...reviewState, enteredNodes: [] });
|
|
10087
|
+
const resNoEntryBlock = runGuard(['exit', 'review', '--apply'], dir);
|
|
10088
|
+
assertExit(resNoEntryBlock, 1);
|
|
10089
|
+
assertOut(resNoEntryBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10090
|
+
assertNotOut(resNoEntryBlock, '未执行 entry 直接 exit');
|
|
10091
|
+
// ③c 新 change done-but-unclosed(review 源):Fix 任务已 done,但 history 最新 exit
|
|
10092
|
+
// execute 签名仍是追加前值(本批 execute 出口从未重跑)→ 必须 BLOCKED 且 state 字节零
|
|
10093
|
+
// 改写(修复前此路径静默放行为 NODE: verify / archive)。
|
|
10094
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10095
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10096
|
+
writeState(dir, { ...reviewState, history: fixBatchHistoryWithStaleExecuteExit() });
|
|
10097
|
+
const staleReviewBytes = fs.readFileSync(statePath, 'utf8');
|
|
10098
|
+
const resDoneBlock = runGuard(['exit', 'review', '--apply'], dir);
|
|
10099
|
+
assertExit(resDoneBlock, 1);
|
|
10100
|
+
assertOut(resDoneBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10101
|
+
assertOut(resDoneBlock, 'entry execute');
|
|
10102
|
+
assertOut(resDoneBlock, 'workflow-state.mjs next');
|
|
10103
|
+
assertOut(resDoneBlock, '恢复');
|
|
10104
|
+
assertNotOut(resDoneBlock, 'ALL CHECKS PASSED');
|
|
10105
|
+
if (fs.readFileSync(statePath, 'utf8') !== staleReviewBytes) {
|
|
10106
|
+
throw new Error('done-but-unclosed BLOCK 不得改写 state 字节');
|
|
10107
|
+
}
|
|
10108
|
+
// ③c-2 恢复闭环:entry execute 归位 → 补 handoff → exit execute --apply 写当前签名 →
|
|
10109
|
+
// 回源 review → exit review 通过(闭合后 done 变体不再拦截)。
|
|
10110
|
+
const recDoneEntry = runGuard(['entry', 'execute'], dir);
|
|
10111
|
+
assertExit(recDoneEntry, 0);
|
|
10112
|
+
assertOut(recDoneEntry, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
10113
|
+
after = readScenarioState(dir);
|
|
10114
|
+
if (after.currentNode !== 'execute') {
|
|
10115
|
+
throw new Error('done-but-unclosed 恢复步 entry execute 应归位 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10116
|
+
}
|
|
10117
|
+
after.evidence['subagent-execute'] = after.evidence['subagent-execute'] || {};
|
|
10118
|
+
after.evidence['subagent-execute'].handoffResult = {
|
|
10119
|
+
...(after.evidence['subagent-execute'].handoffResult || {}),
|
|
10120
|
+
...handoffFor(['T-FIX-01']),
|
|
10121
|
+
};
|
|
10122
|
+
writeState(dir, after);
|
|
10123
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-execute', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
10124
|
+
const recDoneExit = runGuard(['exit', 'execute', '--apply'], dir);
|
|
10125
|
+
assertExit(recDoneExit, 0);
|
|
10126
|
+
assertOut(recDoneExit, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
10127
|
+
assertOut(recDoneExit, 'NODE: review');
|
|
10128
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
10129
|
+
assertExit(runGuard(['entry', 'review'], dir), 0);
|
|
10130
|
+
const recDoneReview = runGuard(['exit', 'review', '--apply'], dir);
|
|
10131
|
+
assertExit(recDoneReview, 0);
|
|
10132
|
+
assertOut(recDoneReview, 'ALL CHECKS PASSED');
|
|
10133
|
+
assertNotOut(recDoneReview, 'BLOCKED');
|
|
10134
|
+
// ③d 新 change done-but-unclosed(verify 源):TEST/UAT 在场(原路径会跳过 verify 去
|
|
10135
|
+
// archive)+ 全 Fix 任务 done + 最新 exit execute 签名过时 → BLOCKED,验证命令未执行,
|
|
10136
|
+
// state 字节零改写;闭合后 exit verify 真实执行验证命令并推进 archive。
|
|
10137
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md',
|
|
10138
|
+
'# TEST\n\n## 验证命令\n\n```\nnode -e "require(\'fs\').writeFileSync(\'verify-gate-ran.txt\', \'GATE-RAN\')"\n```\n');
|
|
10139
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n## 验收\n\n- 通过\n');
|
|
10140
|
+
const gateMarker = path.join(dir, 'verify-gate-ran.txt');
|
|
10141
|
+
fs.rmSync(gateMarker, { force: true });
|
|
10142
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10143
|
+
writeState(dir, {
|
|
10144
|
+
...reviewState,
|
|
10145
|
+
currentNode: 'verify',
|
|
10146
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
10147
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'],
|
|
10148
|
+
evidence: { ...reviewState.evidence, review: { summary: 'review complete' }, verify: { summary: 'verify in progress' } },
|
|
10149
|
+
history: fixBatchHistoryWithStaleExecuteExit(),
|
|
10150
|
+
});
|
|
10151
|
+
const staleVerifyBytes = fs.readFileSync(statePath, 'utf8');
|
|
10152
|
+
const resDoneVerifyBlock = runGuard(['exit', 'verify', '--apply'], dir);
|
|
10153
|
+
assertExit(resDoneVerifyBlock, 1);
|
|
10154
|
+
assertOut(resDoneVerifyBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10155
|
+
assertOut(resDoneVerifyBlock, 'entry execute');
|
|
10156
|
+
assertNotOut(resDoneVerifyBlock, 'ALL CHECKS PASSED');
|
|
10157
|
+
if (fs.existsSync(gateMarker)) throw new Error('done-but-unclosed verify BLOCK 不得执行验证命令');
|
|
10158
|
+
if (fs.readFileSync(statePath, 'utf8') !== staleVerifyBytes) {
|
|
10159
|
+
throw new Error('done-but-unclosed verify BLOCK 不得改写 state 字节');
|
|
10160
|
+
}
|
|
10161
|
+
const recDoneVerifyEntry = runGuard(['entry', 'execute'], dir);
|
|
10162
|
+
assertExit(recDoneVerifyEntry, 0);
|
|
10163
|
+
assertOut(recDoneVerifyEntry, 'FIX-BATCH: 受控归位 execute(源节点 verify)');
|
|
10164
|
+
after = readScenarioState(dir);
|
|
10165
|
+
after.evidence['subagent-execute'] = after.evidence['subagent-execute'] || {};
|
|
10166
|
+
after.evidence['subagent-execute'].handoffResult = {
|
|
10167
|
+
...(after.evidence['subagent-execute'].handoffResult || {}),
|
|
10168
|
+
...handoffFor(['T-FIX-01']),
|
|
10169
|
+
};
|
|
10170
|
+
writeState(dir, after);
|
|
10171
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-execute', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
10172
|
+
const recDoneVerifyExit = runGuard(['exit', 'execute', '--apply'], dir);
|
|
10173
|
+
assertExit(recDoneVerifyExit, 0);
|
|
10174
|
+
assertOut(recDoneVerifyExit, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
10175
|
+
assertOut(recDoneVerifyExit, 'NODE: verify');
|
|
10176
|
+
assertExit(runState(['skill-load', 'verify', 'flow-comet-verify', '--prompt', 'flow-kit/prompts/7-integration.md'], dir, env), 0);
|
|
10177
|
+
assertExit(runGuard(['entry', 'verify'], dir), 0);
|
|
10178
|
+
const recDoneVerify = runGuard(['exit', 'verify', '--apply'], dir);
|
|
10179
|
+
assertExit(recDoneVerify, 0);
|
|
10180
|
+
assertOut(recDoneVerify, 'ALL CHECKS PASSED');
|
|
10181
|
+
assertOut(recDoneVerify, 'NODE: archive');
|
|
10182
|
+
if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
|
|
10183
|
+
throw new Error('闭合后 verify 出口未真实执行 TEST.md 验证命令(副作用文件缺失/内容不符)');
|
|
10184
|
+
}
|
|
10185
|
+
// ④ 旧 change(无 newChange 标记)pending 同路径:渐进 WARN 不阻断(向后兼容)
|
|
10186
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10187
|
+
writeState(dir, { ...reviewState, newChange: false });
|
|
10188
|
+
const resOld = runGuard(['exit', 'review'], dir);
|
|
10189
|
+
assertExit(resOld, 0);
|
|
10190
|
+
assertOut(resOld, 'FIX-BATCH WARN');
|
|
10191
|
+
assertOut(resOld, 'ALL CHECKS PASSED');
|
|
10192
|
+
// ④b 过渡态渐进(feature 之前创建的 state 无 exit execute 签名字段):全 done 也不得
|
|
10193
|
+
// 仅凭「签名缺席」误判未闭合——无签名记录 → done 变体不成立,源节点出口保持可走
|
|
10194
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10195
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10196
|
+
writeState(dir, { ...reviewState, history: [{ event: 'exit-applied', node: 'execute', at: '2026-09-19T00:00:00.000Z' }] });
|
|
10197
|
+
const resLegacyState = runGuard(['exit', 'review', '--apply'], dir);
|
|
10198
|
+
assertExit(resLegacyState, 0);
|
|
10199
|
+
assertNotOut(resLegacyState, 'BLOCKED');
|
|
10200
|
+
assertOut(resLegacyState, 'ALL CHECKS PASSED');
|
|
10201
|
+
// ⑤ 并行 Fix 任务(pending)+ review 源:直接 exit review 仍 BLOCKED;next/entry 归位
|
|
10202
|
+
// subagent-execute;修复后 exit subagent-execute --apply 为第二趟完成 → 回源 review,
|
|
10203
|
+
// 源节点出口随后真实执行(闭合后不得再拦)。
|
|
10204
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('pending'));
|
|
10205
|
+
writeState(dir, reviewState);
|
|
10206
|
+
const rParBlock = runGuard(['exit', 'review', '--apply'], dir);
|
|
10207
|
+
assertExit(rParBlock, 1);
|
|
10208
|
+
assertOut(rParBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10209
|
+
assertNotOut(rParBlock, 'ALL CHECKS PASSED');
|
|
10210
|
+
writeState(dir, reviewState);
|
|
10211
|
+
const rParNext = runState(['next'], dir, env);
|
|
10212
|
+
assertExit(rParNext, 0);
|
|
10213
|
+
assertOut(rParNext, 'FIX-BATCH: 归位 subagent-execute(源节点 review)');
|
|
10214
|
+
assertOut(rParNext, 'NODE: subagent-execute');
|
|
10215
|
+
assertNotOut(rParNext, 'NODE: execute');
|
|
10216
|
+
writeState(dir, reviewState);
|
|
10217
|
+
const rParEntry = runGuard(['entry', 'subagent-execute'], dir);
|
|
10218
|
+
assertExit(rParEntry, 0);
|
|
10219
|
+
assertOut(rParEntry, 'FIX-BATCH: 受控归位 subagent-execute(源节点 review)');
|
|
10220
|
+
after = readScenarioState(dir);
|
|
10221
|
+
if (after.currentNode !== 'subagent-execute') {
|
|
10222
|
+
throw new Error('并行回退态 entry subagent-execute 后 currentNode 应为 subagent-execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10223
|
+
}
|
|
10224
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('done'));
|
|
10225
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/P-FIX-01-SUMMARY.md', strictSummary('P-FIX-01'));
|
|
10226
|
+
after.evidence['subagent-execute'] = after.evidence['subagent-execute'] || {};
|
|
10227
|
+
after.evidence['subagent-execute'].summary = 'parallel fix delegated and collected';
|
|
10228
|
+
after.evidence['subagent-execute'].handoffResult = {
|
|
10229
|
+
...(after.evidence['subagent-execute'].handoffResult || {}),
|
|
10230
|
+
...handoffFor(['P-FIX-01']),
|
|
10231
|
+
};
|
|
10232
|
+
writeState(dir, after);
|
|
10233
|
+
assertExit(runState(['skill-load', 'subagent-execute', 'flow-comet-dev', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
10234
|
+
const rParExit = runGuard(['exit', 'subagent-execute', '--apply'], dir);
|
|
10235
|
+
assertExit(rParExit, 0);
|
|
10236
|
+
assertOut(rParExit, 'FIX-BATCH: 回源节点 review(subagent-execute 出口已完成)');
|
|
10237
|
+
assertOut(rParExit, 'NODE: review');
|
|
10238
|
+
after = readScenarioState(dir);
|
|
10239
|
+
if (after.currentNode !== 'review') {
|
|
10240
|
+
throw new Error('并行修复第二趟出口后应回源 review,实际 ' + JSON.stringify(after.currentNode));
|
|
10241
|
+
}
|
|
10242
|
+
const parFamilyExit = (after.history || [])
|
|
10243
|
+
.filter((e) => e && e.event === 'exit-applied' && e.node === 'subagent-execute').pop();
|
|
10244
|
+
if (!parFamilyExit || parFamilyExit.change !== CHANGE_ID
|
|
10245
|
+
|| typeof parFamilyExit.taskSetSignature !== 'string' || parFamilyExit.taskSetSignature === '') {
|
|
10246
|
+
throw new Error('并行修复出口应记录本 change + taskSetSignature 的家族出口事件,实际 ' + JSON.stringify(parFamilyExit));
|
|
10247
|
+
}
|
|
10248
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
10249
|
+
assertExit(runGuard(['entry', 'review'], dir), 0);
|
|
10250
|
+
const rParSource = runGuard(['exit', 'review', '--apply'], dir);
|
|
10251
|
+
assertExit(rParSource, 0);
|
|
10252
|
+
assertOut(rParSource, 'ALL CHECKS PASSED');
|
|
10253
|
+
assertNotOut(rParSource, 'BLOCKED');
|
|
10254
|
+
// ⑥ verify 源 + 并行 pending:直接 exit verify 同样 BLOCKED(不得绕过家族生命周期)。
|
|
10255
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('pending'));
|
|
10256
|
+
writeState(dir, {
|
|
10257
|
+
...reviewState,
|
|
10258
|
+
currentNode: 'verify',
|
|
10259
|
+
completedNodes: [...reviewState.completedNodes, 'review'],
|
|
10260
|
+
enteredNodes: [...reviewState.enteredNodes, 'verify'],
|
|
10261
|
+
evidence: { ...reviewState.evidence, review: { summary: 'review complete' }, verify: { summary: 'verify in progress' } },
|
|
10262
|
+
});
|
|
10263
|
+
const rParVerifyBlock = runGuard(['exit', 'verify', '--apply'], dir);
|
|
10264
|
+
assertExit(rParVerifyBlock, 1);
|
|
10265
|
+
assertOut(rParVerifyBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10266
|
+
assertNotOut(rParVerifyBlock, 'ALL CHECKS PASSED');
|
|
10267
|
+
// ⑦ done-but-unclosed 并行变体:全 done + 最新家族出口事件(subagent-execute)签名过时
|
|
10268
|
+
// → 直接 exit review BLOCKED;entry 归位 subagent-execute;第二趟出口写当前签名并回源。
|
|
10269
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('done'));
|
|
10270
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/P-FIX-01-SUMMARY.md', strictSummary('P-FIX-01'));
|
|
10271
|
+
writeState(dir, { ...reviewState, history: fixBatchHistoryWithStaleFamilyExit('subagent-execute') });
|
|
10272
|
+
const rDoneParBlock = runGuard(['exit', 'review', '--apply'], dir);
|
|
10273
|
+
assertExit(rDoneParBlock, 1);
|
|
10274
|
+
assertOut(rDoneParBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
10275
|
+
assertNotOut(rDoneParBlock, 'ALL CHECKS PASSED');
|
|
10276
|
+
const rDoneParEntry = runGuard(['entry', 'subagent-execute'], dir);
|
|
10277
|
+
assertExit(rDoneParEntry, 0);
|
|
10278
|
+
assertOut(rDoneParEntry, 'FIX-BATCH: 受控归位 subagent-execute(源节点 review)');
|
|
10279
|
+
after = readScenarioState(dir);
|
|
10280
|
+
after.evidence['subagent-execute'] = after.evidence['subagent-execute'] || {};
|
|
10281
|
+
after.evidence['subagent-execute'].handoffResult = {
|
|
10282
|
+
...(after.evidence['subagent-execute'].handoffResult || {}),
|
|
10283
|
+
...handoffFor(['P-FIX-01']),
|
|
10284
|
+
};
|
|
10285
|
+
writeState(dir, after);
|
|
10286
|
+
assertExit(runState(['skill-load', 'subagent-execute', 'flow-comet-dev', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
10287
|
+
const rDoneParExit = runGuard(['exit', 'subagent-execute', '--apply'], dir);
|
|
10288
|
+
assertExit(rDoneParExit, 0);
|
|
10289
|
+
assertOut(rDoneParExit, 'FIX-BATCH: 回源节点 review(subagent-execute 出口已完成)');
|
|
10290
|
+
if (readScenarioState(dir).currentNode !== 'review') {
|
|
10291
|
+
throw new Error('done-but-unclosed 并行变体闭合后应回源 review,实际 ' + JSON.stringify(readScenarioState(dir).currentNode));
|
|
10292
|
+
}
|
|
10293
|
+
// ④c change 隔离:history 最新 exit 事件属于另一个 change(state.history 跨 change 保留)
|
|
10294
|
+
// → 不得拿它当本 change 的闭合签名;本 change 无该字段的出口事件,done 变体不成立。
|
|
10295
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10296
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10297
|
+
writeState(dir, {
|
|
10298
|
+
...reviewState,
|
|
10299
|
+
history: [{
|
|
10300
|
+
event: 'exit-applied', node: 'execute', change: 'other-change',
|
|
10301
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
10302
|
+
}],
|
|
10303
|
+
});
|
|
10304
|
+
const resOtherChange = runGuard(['exit', 'review', '--apply'], dir);
|
|
10305
|
+
assertExit(resOtherChange, 0);
|
|
10306
|
+
assertNotOut(resOtherChange, 'BLOCKED');
|
|
10307
|
+
assertOut(resOtherChange, 'ALL CHECKS PASSED');
|
|
10308
|
+
},
|
|
10309
|
+
},
|
|
10310
|
+
|
|
10311
|
+
// 253: next Fix 回退态显式归位——源节点(review/verify)驻留 + TASK 有 pending
|
|
10312
|
+
// Fix 任务 + 共享路由回 execute 时,next 必须显式归位 execute、写盘并输出审计行,不再依赖
|
|
10313
|
+
// inProgress 保护副作用(修复前 next 仍输出源节点)。反例:全 done 无 pending → 不归位;
|
|
10314
|
+
// done-but-unclosed(全 done + history 最新 exit execute 签名仍是追加前值)同样必须归位。
|
|
10315
|
+
{
|
|
10316
|
+
name: '253 next Fix 回退态显式归位:review/verify 源 + 审计行(无 pending 反例不归位;done-but-unclosed 归位)',
|
|
10317
|
+
run: (dir) => {
|
|
10318
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10319
|
+
writeIntakeArtifacts(dir);
|
|
10320
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
10321
|
+
const base = {
|
|
10322
|
+
activeChange: CHANGE_ID,
|
|
10323
|
+
currentNode: 'review',
|
|
10324
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
10325
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
10326
|
+
evidence: {
|
|
10327
|
+
execute: { summary: 'first pass executed' },
|
|
10328
|
+
review: { summary: 'review in progress' },
|
|
10329
|
+
},
|
|
10330
|
+
verifyFailures: 0,
|
|
10331
|
+
executionMode: 'subagent',
|
|
10332
|
+
directOverride: false,
|
|
10333
|
+
newChange: true,
|
|
10334
|
+
};
|
|
10335
|
+
// ① review 源:pending Fix 任务在场 → NODE: execute + 审计行 + 机器字段归位写盘
|
|
10336
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10337
|
+
writeState(dir, base);
|
|
10338
|
+
const resReview = runState(['next'], dir, env);
|
|
10339
|
+
assertExit(resReview, 0);
|
|
10340
|
+
assertOut(resReview, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
10341
|
+
assertOut(resReview, 'NODE: execute');
|
|
10342
|
+
assertNotOut(resReview, 'NODE: review');
|
|
10343
|
+
assertNotOut(resReview, 'NODE: verify');
|
|
10344
|
+
assertNotOut(resReview, 'BLOCKED');
|
|
10345
|
+
let after = readScenarioState(dir);
|
|
10346
|
+
if (after.currentNode !== 'execute') {
|
|
10347
|
+
throw new Error('review 源回退态 next 后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10348
|
+
}
|
|
10349
|
+
// ② verify 源(review 已完成)→ 同样显式归位 + 审计行 + 写盘
|
|
10350
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10351
|
+
writeState(dir, {
|
|
10352
|
+
...base,
|
|
10353
|
+
currentNode: 'verify',
|
|
10354
|
+
completedNodes: [...base.completedNodes, 'review'],
|
|
10355
|
+
enteredNodes: [...base.enteredNodes, 'verify'],
|
|
10356
|
+
evidence: { ...base.evidence, review: { summary: 'review complete' }, verify: { summary: 'verify in progress' } },
|
|
10357
|
+
});
|
|
10358
|
+
const resVerify = runState(['next'], dir, env);
|
|
10359
|
+
assertExit(resVerify, 0);
|
|
10360
|
+
assertOut(resVerify, 'FIX-BATCH: 归位 execute(源节点 verify)');
|
|
10361
|
+
assertOut(resVerify, 'NODE: execute');
|
|
10362
|
+
assertNotOut(resVerify, 'NODE: verify');
|
|
10363
|
+
assertNotOut(resVerify, 'BLOCKED');
|
|
10364
|
+
after = readScenarioState(dir);
|
|
10365
|
+
if (after.currentNode !== 'execute') {
|
|
10366
|
+
throw new Error('verify 源回退态 next 后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10367
|
+
}
|
|
10368
|
+
// ③ 反例:全 done(无 pending Fix 任务)→ 非回退态,不得归位 execute(回程逻辑另行覆盖)
|
|
10369
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10370
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
10371
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10372
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
10373
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\nFix 批次由 execute 完成,待回源重新出口。\n');
|
|
10374
|
+
writeState(dir, base);
|
|
10375
|
+
const resNoFix = runState(['next'], dir, env);
|
|
10376
|
+
assertExit(resNoFix, 0);
|
|
10377
|
+
assertNotOut(resNoFix, 'FIX-BATCH: 归位 execute');
|
|
10378
|
+
// ③ 全局缺席:无 pending Fix 任务的回程态,state 侧无 Fix 因果——不得出现任何 FIX-BATCH
|
|
10379
|
+
// (含旧「回程源节点」误标形态;回程中性行由 RETURN 覆盖)
|
|
10380
|
+
assertNotOut(resNoFix, 'FIX-BATCH');
|
|
10381
|
+
assertNotOut(resNoFix, 'NODE: execute');
|
|
10382
|
+
assertOut(resNoFix, 'NODE: review');
|
|
10383
|
+
after = readScenarioState(dir);
|
|
10384
|
+
if (after.currentNode !== 'review') {
|
|
10385
|
+
throw new Error('无 pending 时不应归位 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10386
|
+
}
|
|
10387
|
+
// ④ done-but-unclosed 回退态(全 done + history 最新 exit execute 签名仍是追加前值):
|
|
10388
|
+
// next 同样显式归位 execute(修复前 done 变体无恢复通道,next 停在源节点)。
|
|
10389
|
+
writeState(dir, { ...base, history: fixBatchHistoryWithStaleExecuteExit() });
|
|
10390
|
+
const resDoneRollback = runState(['next'], dir, env);
|
|
10391
|
+
assertExit(resDoneRollback, 0);
|
|
10392
|
+
assertOut(resDoneRollback, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
10393
|
+
assertOut(resDoneRollback, 'NODE: execute');
|
|
10394
|
+
assertNotOut(resDoneRollback, 'NODE: review');
|
|
10395
|
+
assertNotOut(resDoneRollback, 'BLOCKED');
|
|
10396
|
+
after = readScenarioState(dir);
|
|
10397
|
+
if (after.currentNode !== 'execute') {
|
|
10398
|
+
throw new Error('done-but-unclosed 回退态 next 后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10399
|
+
}
|
|
10400
|
+
// ⑤ review 源 + 并行 pending Fix 任务:next 必须归位 subagent-execute(并行路由目标),
|
|
10401
|
+
// 不得停在源节点,也不得错配回 execute。
|
|
10402
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('pending'));
|
|
10403
|
+
writeState(dir, base);
|
|
10404
|
+
const resParallelReview = runState(['next'], dir, env);
|
|
10405
|
+
assertExit(resParallelReview, 0);
|
|
10406
|
+
assertOut(resParallelReview, 'FIX-BATCH: 归位 subagent-execute(源节点 review)');
|
|
10407
|
+
assertOut(resParallelReview, 'NODE: subagent-execute');
|
|
10408
|
+
assertNotOut(resParallelReview, 'NODE: review');
|
|
10409
|
+
assertNotOut(resParallelReview, 'NODE: execute');
|
|
10410
|
+
assertNotOut(resParallelReview, 'BLOCKED');
|
|
10411
|
+
after = readScenarioState(dir);
|
|
10412
|
+
if (after.currentNode !== 'subagent-execute') {
|
|
10413
|
+
throw new Error('review 源并行回退态 next 后 currentNode 应为 subagent-execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10414
|
+
}
|
|
10415
|
+
// ⑥ verify 源 + 并行 pending Fix 任务:同样归位 subagent-execute。
|
|
10416
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('pending'));
|
|
10417
|
+
writeState(dir, {
|
|
10418
|
+
...base,
|
|
10419
|
+
currentNode: 'verify',
|
|
10420
|
+
completedNodes: [...base.completedNodes, 'review'],
|
|
10421
|
+
enteredNodes: [...base.enteredNodes, 'verify'],
|
|
10422
|
+
evidence: { ...base.evidence, review: { summary: 'review complete' }, verify: { summary: 'verify in progress' } },
|
|
10423
|
+
});
|
|
10424
|
+
const resParallelVerify = runState(['next'], dir, env);
|
|
10425
|
+
assertExit(resParallelVerify, 0);
|
|
10426
|
+
assertOut(resParallelVerify, 'FIX-BATCH: 归位 subagent-execute(源节点 verify)');
|
|
10427
|
+
assertOut(resParallelVerify, 'NODE: subagent-execute');
|
|
10428
|
+
assertNotOut(resParallelVerify, 'NODE: verify');
|
|
10429
|
+
assertNotOut(resParallelVerify, 'BLOCKED');
|
|
10430
|
+
after = readScenarioState(dir);
|
|
10431
|
+
if (after.currentNode !== 'subagent-execute') {
|
|
10432
|
+
throw new Error('verify 源并行回退态 next 后 currentNode 应为 subagent-execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10433
|
+
}
|
|
10434
|
+
// ⑦ done-but-unclosed 并行变体(全 done + 最新 exit subagent-execute 签名过时):
|
|
10435
|
+
// next 必须按事件记录的家族节点归位 subagent-execute。
|
|
10436
|
+
writeFile(dir, taskPath, fixBatchParallelTaskText('done'));
|
|
10437
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/P-FIX-01-SUMMARY.md', strictSummary('P-FIX-01'));
|
|
10438
|
+
writeState(dir, { ...base, history: fixBatchHistoryWithStaleFamilyExit('subagent-execute') });
|
|
10439
|
+
const resDoneParallel = runState(['next'], dir, env);
|
|
10440
|
+
assertExit(resDoneParallel, 0);
|
|
10441
|
+
assertOut(resDoneParallel, 'FIX-BATCH: 归位 subagent-execute(源节点 review)');
|
|
10442
|
+
assertOut(resDoneParallel, 'NODE: subagent-execute');
|
|
10443
|
+
assertNotOut(resDoneParallel, 'NODE: execute');
|
|
10444
|
+
assertNotOut(resDoneParallel, 'BLOCKED');
|
|
10445
|
+
after = readScenarioState(dir);
|
|
10446
|
+
if (after.currentNode !== 'subagent-execute') {
|
|
10447
|
+
throw new Error('done-but-unclosed 并行变体 next 后 currentNode 应为 subagent-execute,实际 ' + JSON.stringify(after.currentNode));
|
|
10448
|
+
}
|
|
10449
|
+
// ⑧ m-12 next 入口第 1~3 轮递增:逐轮重置驻留 review,审计后缀第 n/3 轮且计数器同步 +1
|
|
10450
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10451
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
10452
|
+
writeState(dir, base);
|
|
10453
|
+
const stRound = readScenarioState(dir);
|
|
10454
|
+
stRound.fixRoundsByChange = { [CHANGE_ID]: round - 1 };
|
|
10455
|
+
writeState(dir, stRound);
|
|
10456
|
+
const resRound = runState(['next'], dir, env);
|
|
10457
|
+
assertExit(resRound, 0);
|
|
10458
|
+
assertOut(resRound, 'FIX-BATCH: 归位 execute(源节点 review)(第 ' + round + '/3 轮)');
|
|
10459
|
+
const stAfterRound = readScenarioState(dir);
|
|
10460
|
+
if (stAfterRound.fixRoundsByChange?.[CHANGE_ID] !== round) {
|
|
10461
|
+
throw new Error('next 第 ' + round + ' 轮归位后计数器应为 ' + round + ',实际 '
|
|
10462
|
+
+ JSON.stringify(stAfterRound.fixRoundsByChange));
|
|
10463
|
+
}
|
|
10464
|
+
}
|
|
10465
|
+
// ⑨ 第 4 轮新 change BLOCK:state 字节零改写(不写 currentNode、不写计数器)
|
|
10466
|
+
writeState(dir, { ...base, fixRoundsByChange: { [CHANGE_ID]: 3 } });
|
|
10467
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
10468
|
+
const beforeRound4 = fs.readFileSync(statePath, 'utf8');
|
|
10469
|
+
const resRound4 = runState(['next'], dir, env);
|
|
10470
|
+
assertExit(resRound4, 1);
|
|
10471
|
+
assertOut(resRound4, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
10472
|
+
assertOut(resRound4, '继续修');
|
|
10473
|
+
assertOut(resRound4, '停止');
|
|
10474
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeRound4) {
|
|
10475
|
+
throw new Error('next 第 4 轮 BLOCK 必须 state 字节零改写');
|
|
10476
|
+
}
|
|
10477
|
+
const stBlocked = readScenarioState(dir);
|
|
10478
|
+
if (stBlocked.currentNode !== 'review' || stBlocked.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
10479
|
+
throw new Error('next 第 4 轮 BLOCK 后 currentNode/计数器不得改写,实际 '
|
|
10480
|
+
+ JSON.stringify({ currentNode: stBlocked.currentNode, rounds: stBlocked.fixRoundsByChange }));
|
|
10481
|
+
}
|
|
10482
|
+
// ⑨b F5:非法授权形态(仅 round,缺 at/source)在 next 链路上仍按未授权 fail-closed——
|
|
10483
|
+
// 继续 BLOCK、state 字节零改写、currentNode 保持 review、计数器保持 3。
|
|
10484
|
+
const stBadOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
10485
|
+
stBadOverride.evidence.review.fixRoundOverride = { round: 4 };
|
|
10486
|
+
writeState(dir, stBadOverride);
|
|
10487
|
+
const badOverrideBytes = fs.readFileSync(statePath, 'utf8');
|
|
10488
|
+
const resBadOverride = runState(['next'], dir, env);
|
|
10489
|
+
assertExit(resBadOverride, 1);
|
|
10490
|
+
assertOut(resBadOverride, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
10491
|
+
assertNotOut(resBadOverride, '(第 4/3 轮)');
|
|
10492
|
+
if (fs.readFileSync(statePath, 'utf8') !== badOverrideBytes) {
|
|
10493
|
+
throw new Error('F5 缺 at/source 的授权形态必须在 next 链路上 state 字节零改写');
|
|
10494
|
+
}
|
|
10495
|
+
const stBadAfter = readScenarioState(dir);
|
|
10496
|
+
if (stBadAfter.currentNode !== 'review' || stBadAfter.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
10497
|
+
throw new Error('F5 缺 at/source 不得放行第 4 轮(currentNode 保持 review、计数保持 3),实际 '
|
|
10498
|
+
+ JSON.stringify({ currentNode: stBadAfter.currentNode, rounds: stBadAfter.fixRoundsByChange }));
|
|
10499
|
+
}
|
|
10500
|
+
// ⑩ 用户显式授权(嵌套 evidence,完整三元组)→ next 第 4 轮放行并写盘
|
|
10501
|
+
const stOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
10502
|
+
stOverride.evidence.review.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
10503
|
+
writeState(dir, stOverride);
|
|
10504
|
+
const resOverride = runState(['next'], dir, env);
|
|
10505
|
+
assertExit(resOverride, 0);
|
|
10506
|
+
assertOut(resOverride, '(第 4/3 轮)');
|
|
10507
|
+
const stAuthorized = readScenarioState(dir);
|
|
10508
|
+
if (stAuthorized.currentNode !== 'execute' || stAuthorized.fixRoundsByChange?.[CHANGE_ID] !== 4) {
|
|
10509
|
+
throw new Error('next 授权后第 4 轮应放行归位(currentNode=execute、计数器=4),实际 '
|
|
10510
|
+
+ JSON.stringify({ currentNode: stAuthorized.currentNode, rounds: stAuthorized.fixRoundsByChange }));
|
|
10511
|
+
}
|
|
10512
|
+
},
|
|
10513
|
+
},
|
|
10514
|
+
|
|
10515
|
+
// 254: next Fix 回程豁免(review 源)——exit execute --apply 把 currentNode 推回 review 后,
|
|
10516
|
+
// REVIEW.md 已在场会让 resolveNextNode 按产物跳过未出口的 review;next 必须在源节点未完成时
|
|
10517
|
+
// 显式放行 review(审计行 + 只读不改写 state),不依赖 inProgress 保护副作用;无 review 证据的
|
|
10518
|
+
// 引擎回程态同样放行(修复前缺审计行 / 漂移 verify / 无证据时 BLOCK)。
|
|
10519
|
+
{
|
|
10520
|
+
name: '254 next Fix 回程豁免:review 源(REVIEW.md 在场不跳过;无 inProgress 证据也不 BLOCK)',
|
|
10521
|
+
run: (dir) => {
|
|
10522
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10523
|
+
writeIntakeArtifacts(dir);
|
|
10524
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTaskText('done'));
|
|
10525
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
10526
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10527
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
10528
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\nFix 批次由 execute 完成,待回源重新出口。\n');
|
|
10529
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
10530
|
+
const base = {
|
|
10531
|
+
activeChange: CHANGE_ID,
|
|
10532
|
+
currentNode: 'review',
|
|
10533
|
+
completedNodes,
|
|
10534
|
+
enteredNodes: [...completedNodes, 'review'],
|
|
10535
|
+
evidence: { execute: { summary: 'fix batch executed' }, review: { summary: 'review in progress' } },
|
|
10536
|
+
verifyFailures: 0,
|
|
10537
|
+
executionMode: 'subagent',
|
|
10538
|
+
directOverride: false,
|
|
10539
|
+
newChange: true,
|
|
10540
|
+
};
|
|
10541
|
+
// ① 真实回程态(review 已 entry)→ 审计行 + NODE: review + state 只读不改写
|
|
10542
|
+
writeState(dir, base);
|
|
10543
|
+
const res = runState(['next'], dir, env);
|
|
10544
|
+
assertExit(res, 0);
|
|
10545
|
+
assertOut(res, 'RETURN: 回程源节点 review');
|
|
10546
|
+
assertOut(res, 'NODE: review');
|
|
10547
|
+
assertNotOut(res, 'NODE: verify');
|
|
10548
|
+
assertNotOut(res, 'BLOCKED');
|
|
10549
|
+
let after = readScenarioState(dir);
|
|
10550
|
+
if (after.currentNode !== 'review' || after.completedNodes.join(',') !== completedNodes.join(',')) {
|
|
10551
|
+
throw new Error('回程豁免不得改写 state,实际 '
|
|
10552
|
+
+ JSON.stringify({ currentNode: after.currentNode, completedNodes: after.completedNodes }));
|
|
10553
|
+
}
|
|
10554
|
+
// ② 引擎回程态(review 无 evidence/entered;末位已完成节点证据在场)→ 仍放行 review,不漂移 verify
|
|
10555
|
+
writeState(dir, {
|
|
10556
|
+
...base,
|
|
10557
|
+
enteredNodes: completedNodes.slice(),
|
|
10558
|
+
evidence: { execute: { summary: 'fix batch executed' }, 'subagent-execute': { summary: 'delegated' } },
|
|
10559
|
+
});
|
|
10560
|
+
const resNoEvidence = runState(['next'], dir, env);
|
|
10561
|
+
assertExit(resNoEvidence, 0);
|
|
10562
|
+
assertOut(resNoEvidence, 'RETURN: 回程源节点 review');
|
|
10563
|
+
assertOut(resNoEvidence, 'NODE: review');
|
|
10564
|
+
assertNotOut(resNoEvidence, 'NODE: verify');
|
|
10565
|
+
assertNotOut(resNoEvidence, 'BLOCKED');
|
|
10566
|
+
after = readScenarioState(dir);
|
|
10567
|
+
if (after.currentNode !== 'review') {
|
|
10568
|
+
throw new Error('无 inProgress 证据的回程态 next 后 currentNode 应保持 review,实际 ' + JSON.stringify(after.currentNode));
|
|
10569
|
+
}
|
|
10570
|
+
// ③ 无任何 evidence 的引擎回程态 → 回程豁免先于「疑似未 exit」门禁,不 BLOCK
|
|
10571
|
+
writeState(dir, { ...base, enteredNodes: [], evidence: {} });
|
|
10572
|
+
const resNoAnyEvidence = runState(['next'], dir, env);
|
|
10573
|
+
assertExit(resNoAnyEvidence, 0);
|
|
10574
|
+
assertOut(resNoAnyEvidence, 'RETURN: 回程源节点 review');
|
|
10575
|
+
assertOut(resNoAnyEvidence, 'NODE: review');
|
|
10576
|
+
assertNotOut(resNoAnyEvidence, 'BLOCKED');
|
|
10577
|
+
after = readScenarioState(dir);
|
|
10578
|
+
if (after.currentNode !== 'review') {
|
|
10579
|
+
throw new Error('回程豁免不得因证据缺失被门禁改写 currentNode,实际 ' + JSON.stringify(after.currentNode));
|
|
10580
|
+
}
|
|
10581
|
+
},
|
|
10582
|
+
},
|
|
10583
|
+
|
|
10584
|
+
// 255: next Fix 回程豁免(verify 源)——TEST.md + UAT.md 已在场会让 resolveNextNode 按
|
|
10585
|
+
// 产物跳过未出口的 verify 去 archive;next 必须显式放行 verify(审计行 + 只读不改写 state);
|
|
10586
|
+
// 无 verify 证据时不得漂移 archive;完全无证据时不得被「疑似未 exit」门禁 BLOCK。
|
|
10587
|
+
{
|
|
10588
|
+
name: '255 next Fix 回程豁免:verify 源(TEST/UAT 在场不跳过;不漂移 archive/不 BLOCK)',
|
|
10589
|
+
run: (dir) => {
|
|
10590
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10591
|
+
writeIntakeArtifacts(dir);
|
|
10592
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTaskText('done'));
|
|
10593
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
10594
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10595
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
10596
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\nreview passed,待回源 verify 重新出口。\n');
|
|
10597
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```\necho ok\n```\n');
|
|
10598
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n## 验收\n\n- 通过\n');
|
|
10599
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'];
|
|
10600
|
+
const base = {
|
|
10601
|
+
activeChange: CHANGE_ID,
|
|
10602
|
+
currentNode: 'verify',
|
|
10603
|
+
completedNodes,
|
|
10604
|
+
enteredNodes: [...completedNodes, 'verify'],
|
|
10605
|
+
evidence: {
|
|
10606
|
+
execute: { summary: 'fix batch executed' },
|
|
10607
|
+
review: { summary: 'review complete' },
|
|
10608
|
+
verify: { summary: 'verify in progress' },
|
|
10609
|
+
},
|
|
10610
|
+
verifyFailures: 0,
|
|
10611
|
+
executionMode: 'subagent',
|
|
10612
|
+
directOverride: false,
|
|
10613
|
+
newChange: true,
|
|
10614
|
+
};
|
|
10615
|
+
// ① 真实回程态(verify 已 entry)→ 审计行 + NODE: verify + state 只读不改写
|
|
10616
|
+
writeState(dir, base);
|
|
10617
|
+
const res = runState(['next'], dir, env);
|
|
10618
|
+
assertExit(res, 0);
|
|
10619
|
+
assertOut(res, 'RETURN: 回程源节点 verify');
|
|
10620
|
+
assertOut(res, 'NODE: verify');
|
|
10621
|
+
assertNotOut(res, 'NODE: archive');
|
|
10622
|
+
assertNotOut(res, 'BLOCKED');
|
|
10623
|
+
let after = readScenarioState(dir);
|
|
10624
|
+
if (after.currentNode !== 'verify' || after.completedNodes.join(',') !== completedNodes.join(',')) {
|
|
10625
|
+
throw new Error('回程豁免不得改写 state,实际 '
|
|
10626
|
+
+ JSON.stringify({ currentNode: after.currentNode, completedNodes: after.completedNodes }));
|
|
10627
|
+
}
|
|
10628
|
+
// ② 引擎回程态(verify 无 evidence/entered;末位已完成节点证据在场)→ 不漂移 archive
|
|
10629
|
+
writeState(dir, {
|
|
10630
|
+
...base,
|
|
10631
|
+
enteredNodes: completedNodes.slice(),
|
|
10632
|
+
evidence: { execute: { summary: 'fix batch executed' }, review: { summary: 'review complete' } },
|
|
10633
|
+
});
|
|
10634
|
+
const resNoEvidence = runState(['next'], dir, env);
|
|
10635
|
+
assertExit(resNoEvidence, 0);
|
|
10636
|
+
assertOut(resNoEvidence, 'RETURN: 回程源节点 verify');
|
|
10637
|
+
assertOut(resNoEvidence, 'NODE: verify');
|
|
10638
|
+
assertNotOut(resNoEvidence, 'NODE: archive');
|
|
10639
|
+
assertNotOut(resNoEvidence, 'BLOCKED');
|
|
10640
|
+
after = readScenarioState(dir);
|
|
10641
|
+
if (after.currentNode !== 'verify') {
|
|
10642
|
+
throw new Error('无 inProgress 证据的回程态 next 后 currentNode 应保持 verify,实际 ' + JSON.stringify(after.currentNode));
|
|
10643
|
+
}
|
|
10644
|
+
// ③ 无任何 evidence → 回程豁免先于「疑似未 exit」门禁,不 BLOCK
|
|
10645
|
+
writeState(dir, { ...base, enteredNodes: [], evidence: {} });
|
|
10646
|
+
const resNoAnyEvidence = runState(['next'], dir, env);
|
|
10647
|
+
assertExit(resNoAnyEvidence, 0);
|
|
10648
|
+
assertOut(resNoAnyEvidence, 'RETURN: 回程源节点 verify');
|
|
10649
|
+
assertOut(resNoAnyEvidence, 'NODE: verify');
|
|
10650
|
+
assertNotOut(resNoAnyEvidence, 'BLOCKED');
|
|
10651
|
+
},
|
|
10652
|
+
},
|
|
10653
|
+
|
|
10654
|
+
// 256: 负例回归——正常多趟中间态(execute 已完成 + 依赖已满足的 parallel pending 任务)
|
|
10655
|
+
// 必须照常路由 subagent-execute:回退谓词(源节点限制)与回程谓词(任务全 done 限制)都不成立,
|
|
10656
|
+
// 不得被 Fix 两态分支误分流到 review/verify,也不得输出 FIX-BATCH 审计行。
|
|
10657
|
+
{
|
|
10658
|
+
name: '256 负例:正常多趟中间态(execute 已完成 + 可委托 parallel pending)不误分流',
|
|
10659
|
+
run: (dir) => {
|
|
10660
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10661
|
+
writeIntakeArtifacts(dir);
|
|
10662
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', renderMultiWaveTasks(['T01', 'P01', 'P02', 'T02']));
|
|
10663
|
+
for (const id of ['T01', 'P01', 'P02', 'T02']) {
|
|
10664
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/' + id + '-SUMMARY.md', strictSummary(id));
|
|
10665
|
+
}
|
|
10666
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
10667
|
+
writeState(dir, {
|
|
10668
|
+
activeChange: CHANGE_ID,
|
|
10669
|
+
currentNode: 'execute',
|
|
10670
|
+
completedNodes,
|
|
10671
|
+
enteredNodes: completedNodes.slice(),
|
|
10672
|
+
evidence: {
|
|
10673
|
+
execute: { summary: 'serial wave complete' },
|
|
10674
|
+
'subagent-execute': { summary: 'wave 1 delegated and collected' },
|
|
10675
|
+
},
|
|
10676
|
+
verifyFailures: 0,
|
|
10677
|
+
executionMode: 'subagent',
|
|
10678
|
+
directOverride: false,
|
|
10679
|
+
newChange: true,
|
|
10680
|
+
});
|
|
10681
|
+
const res = runState(['next'], dir, env);
|
|
10682
|
+
assertExit(res, 0);
|
|
10683
|
+
assertOut(res, 'NODE: subagent-execute');
|
|
10684
|
+
assertNotOut(res, 'NODE: review');
|
|
10685
|
+
assertNotOut(res, 'NODE: verify');
|
|
10686
|
+
assertNotOut(res, 'FIX-BATCH');
|
|
10687
|
+
assertNotOut(res, 'BLOCKED');
|
|
10688
|
+
const after = readScenarioState(dir);
|
|
10689
|
+
if (after.currentNode !== 'subagent-execute') {
|
|
10690
|
+
throw new Error('正常多趟中间态应路由 subagent-execute,实际 currentNode=' + JSON.stringify(after.currentNode));
|
|
10691
|
+
}
|
|
10692
|
+
},
|
|
10693
|
+
},
|
|
10694
|
+
|
|
10695
|
+
// 257: 旧 change 兼容——无 newChange: true 的回退态与回程态都不新增 BLOCK,
|
|
10696
|
+
// 且 NODE 输出与判定正确(回退 → execute;回程 → 源节点)。
|
|
10697
|
+
{
|
|
10698
|
+
name: '257 旧 change 兼容:无 newChange 的回退/回程态不新增 BLOCK 且 NODE 正确',
|
|
10699
|
+
run: (dir) => {
|
|
10700
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
10701
|
+
writeIntakeArtifacts(dir);
|
|
10702
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
10703
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
10704
|
+
const oldState = {
|
|
10705
|
+
activeChange: CHANGE_ID,
|
|
10706
|
+
currentNode: 'review',
|
|
10707
|
+
completedNodes,
|
|
10708
|
+
enteredNodes: [...completedNodes, 'review'],
|
|
10709
|
+
evidence: { execute: { summary: 'first pass executed' }, review: { summary: 'review in progress' } },
|
|
10710
|
+
verifyFailures: 0,
|
|
10711
|
+
executionMode: 'subagent',
|
|
10712
|
+
directOverride: false,
|
|
10713
|
+
// newChange 缺省/null = 旧 change 渐进形态(newChange 校验只接受 true/缺失/null)
|
|
10714
|
+
};
|
|
10715
|
+
// ① 旧 change 回退态(pending Fix 任务)→ NODE: execute + 审计行,不得 BLOCK
|
|
10716
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
10717
|
+
writeState(dir, oldState);
|
|
10718
|
+
const resRollback = runState(['next'], dir, env);
|
|
10719
|
+
assertExit(resRollback, 0);
|
|
10720
|
+
assertNotOut(resRollback, 'BLOCKED');
|
|
10721
|
+
assertOut(resRollback, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
10722
|
+
assertOut(resRollback, 'NODE: execute');
|
|
10723
|
+
// 旧 change 缺 fixRoundsByChange 字段 → 缺省 0,从第 1 轮计数且不 BLOCK(AC-5 旧兼容)
|
|
10724
|
+
assertOut(resRollback, '(第 1/3 轮)');
|
|
10725
|
+
const stLegacyRollback = readScenarioState(dir);
|
|
10726
|
+
if (stLegacyRollback.currentNode !== 'execute' || stLegacyRollback.fixRoundsByChange?.[CHANGE_ID] !== 1) {
|
|
10727
|
+
throw new Error('旧 change 回退态 next 后应归位 execute 且计数器缺省 0→1,实际 '
|
|
10728
|
+
+ JSON.stringify({ currentNode: stLegacyRollback.currentNode, rounds: stLegacyRollback.fixRoundsByChange }));
|
|
10729
|
+
}
|
|
10730
|
+
// ② 旧 change 回程态(无 newChange 字段:全 done + REVIEW.md + 源节点未完成)→ NODE: review,不得 BLOCK
|
|
10731
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
10732
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', strictSummary('T01'));
|
|
10733
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', strictSummary('T-FIX-01'));
|
|
10734
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md',
|
|
10735
|
+
'# REVIEW\n\n## 发现\n\n### Critical\n\n- 无\n\n### Major\n\n- 无\n\n### Minor\n\n- 无\n\n## 结论\n\n待回源出口。\n');
|
|
10736
|
+
writeState(dir, oldState);
|
|
10737
|
+
const resReturn = runState(['next'], dir, env);
|
|
10738
|
+
assertExit(resReturn, 0);
|
|
10739
|
+
assertNotOut(resReturn, 'BLOCKED');
|
|
10740
|
+
assertOut(resReturn, 'RETURN: 回程源节点 review');
|
|
10741
|
+
assertOut(resReturn, 'NODE: review');
|
|
10742
|
+
assertNotOut(resReturn, 'NODE: verify');
|
|
10743
|
+
if (readScenarioState(dir).currentNode !== 'review') {
|
|
10744
|
+
throw new Error('旧 change 回程态 next 后 currentNode 应保持 review,实际 ' + JSON.stringify(readScenarioState(dir).currentNode));
|
|
10745
|
+
}
|
|
10746
|
+
// ③ 旧 change 无签名、无 Fix 标记的回程态(决策 2/3 旧态边界):state 侧同样只输出中性
|
|
10747
|
+
// RETURN 回程行——缺 taskSetSignature、TASK 无 Fix 段/编号 → 不得冒充 FIX-BATCH。
|
|
10748
|
+
writeFile(dir, taskPath, '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
10749
|
+
writeState(dir, oldState);
|
|
10750
|
+
const resReturnNoMarker = runState(['next'], dir, env);
|
|
10751
|
+
assertExit(resReturnNoMarker, 0);
|
|
10752
|
+
assertNotOut(resReturnNoMarker, 'BLOCKED');
|
|
10753
|
+
assertNotOut(resReturnNoMarker, 'FIX-BATCH');
|
|
10754
|
+
assertOut(resReturnNoMarker, 'RETURN: 回程源节点 review(源节点产物在场且未出口;保留源节点跑出口)');
|
|
10755
|
+
assertOut(resReturnNoMarker, 'NODE: review');
|
|
10756
|
+
if (readScenarioState(dir).currentNode !== 'review') {
|
|
10757
|
+
throw new Error('旧 change 无标记回程态 next 后 currentNode 应保持 review,实际 ' + JSON.stringify(readScenarioState(dir).currentNode));
|
|
10758
|
+
}
|
|
10759
|
+
},
|
|
10760
|
+
},
|
|
10761
|
+
|
|
10762
|
+
// 258: 三节点 SKILL 文本锁(AC-9 / T05 已落地)——execute/review/verify 均含
|
|
10763
|
+
// 「## Fix 批次状态机路径」段,段内含受控归位 + 回源节点跑出口 + 禁止绕过;不得把
|
|
10764
|
+
// 直接 exit 源节点收场或 advance 当正常路径(反捷径文本锚)。
|
|
10765
|
+
// 布局感知(级 3 e2e 副本缺陷):技能树从 suite 脚本自身位置推导
|
|
10766
|
+
// (<skillsRoot>/flow-comet/scripts/ → 组件技能为 <skillsRoot> 下同级目录),权威源
|
|
10767
|
+
// .flow-comet/skills/ 与安装副本 .claude|.agents|.dsh/skills/ 同一相对布局通吃。
|
|
10768
|
+
{
|
|
10769
|
+
name: '258 技能文本锁:三节点 SKILL 含 Fix 批次状态机路径(禁止直接 exit/advance 为正常路径)',
|
|
10770
|
+
run: (dir) => {
|
|
10771
|
+
const componentSkills = ['flow-comet-execute', 'flow-comet-review', 'flow-comet-verify'];
|
|
10772
|
+
// 布局感知回归锚(合成安装副本):suite 位于 <skillsRoot>/flow-comet/scripts/ 时组件技能
|
|
10773
|
+
// 必须解析到同级 <skillsRoot>/<skill>/SKILL.md——与权威源 .flow-comet 布局无关
|
|
10774
|
+
//(旧实现硬编码 REPO_ROOT/.flow-comet/skills → 此锚变红)。
|
|
10775
|
+
const syntheticSkillsRoot = path.join(dir, 'synthetic-carrier', '.claude', 'skills');
|
|
10776
|
+
const syntheticScriptsDir = path.join(syntheticSkillsRoot, 'flow-comet', 'scripts');
|
|
10777
|
+
for (const nodeSkill of componentSkills) {
|
|
10778
|
+
writeFile(dir, path.join('synthetic-carrier', '.claude', 'skills', nodeSkill, 'SKILL.md'),
|
|
10779
|
+
'## Fix 批次状态机路径\n\n受控归位(合成布局锚)\n');
|
|
10780
|
+
const expected = path.join(syntheticSkillsRoot, nodeSkill, 'SKILL.md');
|
|
10781
|
+
const resolved = resolveComponentSkillFile(nodeSkill, syntheticScriptsDir);
|
|
10782
|
+
if (resolved !== expected) {
|
|
10783
|
+
throw new Error('技能树布局感知解析错误:期望 ' + expected + ',实际 ' + resolved);
|
|
10784
|
+
}
|
|
10785
|
+
}
|
|
10786
|
+
// 显式失败锚(MECHANISM 三·6):组件技能缺失时必须报错并给指引,不得静默跳过/空过。
|
|
10787
|
+
const emptyScriptsDir = path.join(dir, 'empty-carrier', '.dsh', 'skills', 'flow-comet', 'scripts');
|
|
10788
|
+
let missingError = null;
|
|
10789
|
+
try {
|
|
10790
|
+
resolveComponentSkillFile('flow-comet-execute', emptyScriptsDir);
|
|
10791
|
+
} catch (e) {
|
|
10792
|
+
missingError = e.message;
|
|
10793
|
+
}
|
|
10794
|
+
if (!missingError
|
|
10795
|
+
|| !missingError.includes('技能树布局定位失败')
|
|
10796
|
+
|| !missingError.includes(path.join('flow-comet-execute', 'SKILL.md'))) {
|
|
10797
|
+
throw new Error('组件技能缺失时未显式失败并给指引: ' + JSON.stringify(missingError));
|
|
10798
|
+
}
|
|
10799
|
+
// 真实三节点文本锁:从本 suite 自身位置推导技能树(不假定权威源布局)。逐份断言:
|
|
10800
|
+
// 段在场 + 6 关键词 + 反 advance 捷径 + 不得把直接 exit 源节点收场当正常路径;同时收集
|
|
10801
|
+
// 段正文(同一区间:首个 ## Fix 批次状态机路径 → 下一 ## 或 EOF,标题不计入)供 F-4 互比。
|
|
10802
|
+
const sectionEntries = [];
|
|
10803
|
+
for (const nodeSkill of componentSkills) {
|
|
10804
|
+
const file = resolveComponentSkillFile(nodeSkill);
|
|
10805
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
10806
|
+
const match = text.match(/(?:^|\r?\n)## Fix 批次状态机路径\r?\n([\s\S]*?)(?=\r?\n## |$)/);
|
|
10807
|
+
if (!match) {
|
|
10808
|
+
throw new Error(nodeSkill + ' SKILL.md 缺「## Fix 批次状态机路径」段');
|
|
10809
|
+
}
|
|
10810
|
+
const section = match[1];
|
|
10811
|
+
for (const keyword of ['受控归位', 'NODE: execute', '回源节点跑出口', 'entry <源节点>', 'exit <源节点> --apply', '禁止绕过']) {
|
|
10812
|
+
if (!section.includes(keyword)) {
|
|
10813
|
+
throw new Error(nodeSkill + ' Fix 批次状态机路径段缺关键词: ' + keyword);
|
|
10814
|
+
}
|
|
10815
|
+
}
|
|
10816
|
+
if (section.includes('advance')) {
|
|
10817
|
+
throw new Error(nodeSkill + ' Fix 批次状态机路径段不得把 advance 作为正常路径');
|
|
10818
|
+
}
|
|
10819
|
+
for (const line of section.split(/\r?\n/)) {
|
|
10820
|
+
if (line.includes('直接') && line.includes('exit') && !/禁止|不得|会被 BLOCKED/.test(line)) {
|
|
10821
|
+
throw new Error(nodeSkill + ' Fix 批次状态机路径段不得把直接 exit 源节点收场作为正常路径: ' + line.trim());
|
|
10822
|
+
}
|
|
10823
|
+
}
|
|
10824
|
+
// F-4 段一致性锁:CRLF→LF 归一、不 trim(行尾/空白差异同样算漂移),正文参与三份互比。
|
|
10825
|
+
const normalized = section.replace(/\r\n/g, '\n');
|
|
10826
|
+
sectionEntries.push({ nodeSkill, body: normalized, hash: createHash('sha256').update(normalized, 'utf8').digest('hex') });
|
|
10827
|
+
}
|
|
10828
|
+
// F-4:三份段正文必须非空且逐字完全一致(当前无合法 per-node 差异)——任一单文件漂移即
|
|
10829
|
+
// 套件失败;失败信息给出三份 hash 与首处差异位置/上下文(L-064 反向构造证明判别力)。
|
|
10830
|
+
const emptyEntry = sectionEntries.find((entry) => entry.body.trim() === '');
|
|
10831
|
+
if (emptyEntry) {
|
|
10832
|
+
throw new Error('Fix 批次状态机路径段不得为空: ' + emptyEntry.nodeSkill);
|
|
10833
|
+
}
|
|
10834
|
+
const baselineEntry = sectionEntries[0];
|
|
10835
|
+
for (const entry of sectionEntries.slice(1)) {
|
|
10836
|
+
if (entry.body === baselineEntry.body) continue;
|
|
10837
|
+
const limit = Math.min(baselineEntry.body.length, entry.body.length);
|
|
10838
|
+
let diffIndex = 0;
|
|
10839
|
+
while (diffIndex < limit && baselineEntry.body[diffIndex] === entry.body[diffIndex]) diffIndex += 1;
|
|
10840
|
+
const context = baselineEntry.body.slice(Math.max(0, diffIndex - 40), diffIndex + 40);
|
|
10841
|
+
throw new Error('Fix 批次状态机路径段三份 SKILL 正文不一致(F-4 段一致性锁):'
|
|
10842
|
+
+ baselineEntry.nodeSkill + ' sha256=' + baselineEntry.hash
|
|
10843
|
+
+ ' vs ' + entry.nodeSkill + ' sha256=' + entry.hash
|
|
10844
|
+
+ ';首处差异 @' + diffIndex + '(基准上下文: ' + JSON.stringify(context) + ')');
|
|
10845
|
+
}
|
|
10846
|
+
},
|
|
10847
|
+
},
|
|
10848
|
+
|
|
10849
|
+
// 259: 受控重入正例(AC-1 / AC-10)——archive 已 entry + 归档目录仍在原位 + 完整授权
|
|
10850
|
+
// 三元组 → 一次调用完成:备份落盘(全量快照 + 可核验 sha256 指纹)→ 转移落地
|
|
10851
|
+
// (currentNode=target / completedNodes=前驱交集 / status=running)→ 审计事件(含 change
|
|
10852
|
+
// 归属与授权留痕)→ 可审计的 REENTRY 行。
|
|
10853
|
+
{
|
|
10854
|
+
name: '259 受控重入正例:archive → verify 备份·转移·审计事件·授权留痕全链路',
|
|
10855
|
+
run: (dir) => {
|
|
10856
|
+
writeReentryChangeDir(dir);
|
|
10857
|
+
writeState(dir, reentryArchiveState());
|
|
10858
|
+
const beforeState = readScenarioState(dir);
|
|
10859
|
+
const res = runReenter(dir, 'verify', { source: 'user-approval', reason: '归档后发现缺陷,需回到验证节点' });
|
|
10860
|
+
assertExit(res, 0);
|
|
10861
|
+
assertOut(res, 'REENTRY');
|
|
10862
|
+
assertOut(res, 'archive');
|
|
10863
|
+
assertOut(res, 'verify');
|
|
10864
|
+
assertOut(res, '1/3');
|
|
10865
|
+
assertOut(res, 'user-approval');
|
|
10866
|
+
assertOut(res, 'REASON: 归档后发现缺陷,需回到验证节点');
|
|
10867
|
+
const st = readScenarioState(dir);
|
|
10868
|
+
if (st.currentNode !== 'verify') {
|
|
10869
|
+
throw new Error('转移应把 currentNode 置为 target(verify),实际 ' + JSON.stringify(st.currentNode));
|
|
10870
|
+
}
|
|
10871
|
+
if (!isDeepStrictEqual(st.completedNodes, REENTRY_EXPECTED_INTERSECTION.verify)) {
|
|
10872
|
+
throw new Error('completedNodes 应为前驱交集 ' + JSON.stringify(REENTRY_EXPECTED_INTERSECTION.verify)
|
|
10873
|
+
+ ',实际 ' + JSON.stringify(st.completedNodes));
|
|
10874
|
+
}
|
|
10875
|
+
if (st.status !== 'running') {
|
|
10876
|
+
throw new Error('重入应把 status 置为 running,实际 ' + JSON.stringify(st.status));
|
|
10877
|
+
}
|
|
10878
|
+
// 除四类机器字段与 evidence(授权留痕)外,state 其余字段逐项不变、不得新增/删除
|
|
10879
|
+
const mutable = new Set(['currentNode', 'completedNodes', 'status', 'history', 'evidence']);
|
|
10880
|
+
for (const key of Object.keys(st)) {
|
|
10881
|
+
if (mutable.has(key)) continue;
|
|
10882
|
+
if (!isDeepStrictEqual(beforeState[key], st[key])) {
|
|
10883
|
+
throw new Error('受控重入不得改写 ' + key + ':before=' + JSON.stringify(beforeState[key])
|
|
10884
|
+
+ ' after=' + JSON.stringify(st[key]));
|
|
10885
|
+
}
|
|
10886
|
+
}
|
|
10887
|
+
for (const key of Object.keys(beforeState)) {
|
|
10888
|
+
if (!(key in st)) throw new Error('受控重入不得删除 state 字段: ' + key);
|
|
10889
|
+
}
|
|
10890
|
+
// history:旧前缀逐字稳定 + 恰新增一条 reentry-applied
|
|
10891
|
+
const history = Array.isArray(st.history) ? st.history : [];
|
|
10892
|
+
if (history.length !== beforeState.history.length + 1) {
|
|
10893
|
+
throw new Error('history 应恰新增 1 条,实际新增 ' + (history.length - beforeState.history.length)
|
|
10894
|
+
+ ':' + JSON.stringify(history.slice(beforeState.history.length)));
|
|
10895
|
+
}
|
|
10896
|
+
if (!isDeepStrictEqual(history.slice(0, beforeState.history.length), beforeState.history)) {
|
|
10897
|
+
throw new Error('history 旧前缀被改写(既有事件必须逐字稳定)');
|
|
10898
|
+
}
|
|
10899
|
+
const event = history[history.length - 1];
|
|
10900
|
+
if (!event || event.event !== 'reentry-applied') {
|
|
10901
|
+
throw new Error('新增 history 事件应为 reentry-applied:' + JSON.stringify(event));
|
|
10902
|
+
}
|
|
10903
|
+
if (event.from !== 'archive' || event.to !== 'verify') {
|
|
10904
|
+
throw new Error('审计事件应记录 from=archive / to=verify,实际 '
|
|
10905
|
+
+ JSON.stringify({ from: event.from, to: event.to }));
|
|
10906
|
+
}
|
|
10907
|
+
if (event.round !== 1) {
|
|
10908
|
+
throw new Error('首次重入轮次应为 1,实际 ' + JSON.stringify(event.round));
|
|
10909
|
+
}
|
|
10910
|
+
if (event.change !== CHANGE_ID) {
|
|
10911
|
+
throw new Error('reentry-applied 事件必须带 change 字段(跨 change 轮次隔离的唯一依据),实际 '
|
|
10912
|
+
+ JSON.stringify(event.change));
|
|
10913
|
+
}
|
|
10914
|
+
if (typeof event.at !== 'string' || Number.isNaN(Date.parse(event.at))) {
|
|
10915
|
+
throw new Error('审计事件应带可解析的 at 时间戳,实际 ' + JSON.stringify(event.at));
|
|
10916
|
+
}
|
|
10917
|
+
const authorization = event.authorization;
|
|
10918
|
+
if (!authorization || authorization.round !== 1 || authorization.source !== 'user-approval'
|
|
10919
|
+
|| authorization.target !== 'verify'
|
|
10920
|
+
|| typeof authorization.at !== 'string' || authorization.at.trim() === '') {
|
|
10921
|
+
throw new Error('审计事件 authorization 记录不完整(round / at / source / target 与本次调用绑定):'
|
|
10922
|
+
+ JSON.stringify(authorization));
|
|
10923
|
+
}
|
|
10924
|
+
if (typeof event.backup !== 'string' || event.backup.trim() === '') {
|
|
10925
|
+
throw new Error('审计事件应记录备份路径,实际 ' + JSON.stringify(event.backup));
|
|
10926
|
+
}
|
|
10927
|
+
if (typeof event.fingerprint !== 'string' || !/^[0-9a-f]{64}$/.test(event.fingerprint)) {
|
|
10928
|
+
throw new Error('审计事件应记录 sha256 指纹(64 位小写十六进制),实际 ' + JSON.stringify(event.fingerprint));
|
|
10929
|
+
}
|
|
10930
|
+
// 授权嵌套留痕(evidence.<target>.reentryAuthorization)
|
|
10931
|
+
const record = st.evidence?.verify?.reentryAuthorization;
|
|
10932
|
+
if (!record) {
|
|
10933
|
+
throw new Error('evidence.verify.reentryAuthorization 授权留痕缺失:' + JSON.stringify(st.evidence));
|
|
10934
|
+
}
|
|
10935
|
+
if (record.round !== 1 || record.source !== 'user-approval' || record.target !== 'verify'
|
|
10936
|
+
|| typeof record.at !== 'string' || record.at.trim() === '') {
|
|
10937
|
+
throw new Error('授权留痕字段不完整:' + JSON.stringify(record));
|
|
10938
|
+
}
|
|
10939
|
+
if (record.backup !== event.backup || record.fingerprint !== event.fingerprint) {
|
|
10940
|
+
throw new Error('授权留痕的 backup / fingerprint 应与审计事件一致:' + JSON.stringify({ record, event }));
|
|
10941
|
+
}
|
|
10942
|
+
// --reason 必须落盘(事件 + 嵌套授权记录):只打印不落盘的必填参数无法支撑事后审计追溯
|
|
10943
|
+
if (event.reason !== '归档后发现缺陷,需回到验证节点') {
|
|
10944
|
+
throw new Error('审计事件应记录本次 --reason(可追溯),实际 ' + JSON.stringify(event.reason));
|
|
10945
|
+
}
|
|
10946
|
+
if (record.reason !== event.reason) {
|
|
10947
|
+
throw new Error('授权留痕的 reason 应与审计事件逐字一致:' + JSON.stringify({ record: record.reason, event: event.reason }));
|
|
10948
|
+
}
|
|
10949
|
+
// 备份:路径形态 + 全量快照语义 + 指纹可核验
|
|
10950
|
+
const backupPath = path.isAbsolute(event.backup) ? event.backup : path.join(dir, event.backup);
|
|
10951
|
+
if (!fs.existsSync(backupPath)) {
|
|
10952
|
+
throw new Error('备份文件不在场:' + backupPath);
|
|
10953
|
+
}
|
|
10954
|
+
const backupRel = path.relative(dir, backupPath).split(path.sep).join('/');
|
|
10955
|
+
if (!backupRel.startsWith('.specs/' + CHANGE_ID + '/.reentry-backups/')
|
|
10956
|
+
|| !/-pre-verify\.json$/.test(path.basename(backupPath))) {
|
|
10957
|
+
throw new Error('备份路径应符合 .specs/<id>/.reentry-backups/<ISO>-pre-<target>.json,实际 ' + backupRel);
|
|
10958
|
+
}
|
|
10959
|
+
const backupBytes = fs.readFileSync(backupPath);
|
|
10960
|
+
const fingerprint = createHash('sha256').update(backupBytes).digest('hex');
|
|
10961
|
+
if (fingerprint !== event.fingerprint) {
|
|
10962
|
+
throw new Error('备份指纹与文件内容不一致(AC-9 可核验):事件=' + event.fingerprint + ' 实算=' + fingerprint);
|
|
10963
|
+
}
|
|
10964
|
+
if (!isDeepStrictEqual(JSON.parse(backupBytes.toString('utf8')), beforeState)) {
|
|
10965
|
+
throw new Error('备份应为重入前 state 的全量快照');
|
|
10966
|
+
}
|
|
10967
|
+
},
|
|
10968
|
+
},
|
|
10969
|
+
|
|
10970
|
+
// 260: 授权门禁 fail-closed(AC-2)——缺授权 / source 空串 / source 纯空白 → BLOCK、
|
|
10971
|
+
// state 字节零改写、零备份、零事件;授权形态(round 正整数、at / source 非空字符串、
|
|
10972
|
+
// target 与授权一致)由 route-node 纯函数单一权威判定(形态锚 + 合法形态放行对照)。
|
|
10973
|
+
{
|
|
10974
|
+
name: '260 授权 fail-closed:缺授权·空/纯空白 source BLOCK 零改写 + 形态纯函数锚',
|
|
10975
|
+
run: (dir) => {
|
|
10976
|
+
writeReentryChangeDir(dir);
|
|
10977
|
+
writeState(dir, reentryArchiveState());
|
|
10978
|
+
const bytes = readStateBytes(dir);
|
|
10979
|
+
const blockedCases = [
|
|
10980
|
+
['缺授权(无 --authorized-by / --reason)', () => runReenter(dir, 'verify')],
|
|
10981
|
+
['source 空串', () => runReenter(dir, 'verify', { source: '', reason: 'x' })],
|
|
10982
|
+
['source 纯空白', () => runReenter(dir, 'verify', { source: ' ', reason: 'x' })],
|
|
10983
|
+
];
|
|
10984
|
+
for (const [label, call] of blockedCases) {
|
|
10985
|
+
const res = call();
|
|
10986
|
+
assertExit(res, 1);
|
|
10987
|
+
assertOut(res, 'BLOCKED');
|
|
10988
|
+
assertStateBytesUnchanged(dir, bytes, label);
|
|
10989
|
+
}
|
|
10990
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
10991
|
+
throw new Error('授权非法路径不得产生备份:' + JSON.stringify(reentryBackupFiles(dir)));
|
|
10992
|
+
}
|
|
10993
|
+
const st = readScenarioState(dir);
|
|
10994
|
+
const reentryEvents = (st.history || []).filter((e) => e.event === 'reentry-applied');
|
|
10995
|
+
if (reentryEvents.length !== 0) {
|
|
10996
|
+
throw new Error('授权非法路径不得写审计事件:' + JSON.stringify(reentryEvents));
|
|
10997
|
+
}
|
|
10998
|
+
// 授权形态纯函数锚:malformed 一律 ok:false,合法 ok:true(放行侧对照)
|
|
10999
|
+
const valid = { round: 1, at: '2026-09-20T00:00:00.000Z', source: 'user-approval', target: 'verify' };
|
|
11000
|
+
assertReentryAuthorizationShape(valid, 'verify', true, '合法三元组');
|
|
11001
|
+
const malformed = [
|
|
11002
|
+
['缺 authorization', undefined],
|
|
11003
|
+
['round=0', { ...valid, round: 0 }],
|
|
11004
|
+
['round=-1', { ...valid, round: -1 }],
|
|
11005
|
+
['round=1.5 非整数', { ...valid, round: 1.5 }],
|
|
11006
|
+
['round="1" 类型错误', { ...valid, round: '1' }],
|
|
11007
|
+
['round 缺失', { ...valid, round: undefined }],
|
|
11008
|
+
['at=42 类型错误', { ...valid, at: 42 }],
|
|
11009
|
+
['at 空串', { ...valid, at: '' }],
|
|
11010
|
+
['at 纯空白', { ...valid, at: ' ' }],
|
|
11011
|
+
['at 缺失', { ...valid, at: undefined }],
|
|
11012
|
+
['source=[] 类型错误', { ...valid, source: [] }],
|
|
11013
|
+
['source 空串', { ...valid, source: '' }],
|
|
11014
|
+
['source 纯空白', { ...valid, source: ' ' }],
|
|
11015
|
+
['source 缺失', { ...valid, source: undefined }],
|
|
11016
|
+
['target 与授权不一致', { ...valid, target: 'execute' }],
|
|
11017
|
+
];
|
|
11018
|
+
for (const [label, authorization] of malformed) {
|
|
11019
|
+
assertReentryAuthorizationShape(authorization, 'verify', false, label);
|
|
11020
|
+
}
|
|
11021
|
+
// 综合判定:archive 源 + 合法 target + 形态非法授权 → block(不抛异常),合法 → apply
|
|
11022
|
+
const decide = requireRouteNodeExport('resolveReentryDecision');
|
|
11023
|
+
const protocol = readScenarioProtocol(dir);
|
|
11024
|
+
const decideState = {
|
|
11025
|
+
activeChange: CHANGE_ID,
|
|
11026
|
+
currentNode: 'archive',
|
|
11027
|
+
completedNodes: [...REENTRY_FULL_COMPLETED],
|
|
11028
|
+
history: [],
|
|
11029
|
+
};
|
|
11030
|
+
for (const [label, authorization] of malformed) {
|
|
11031
|
+
const decision = decide({ protocol, state: decideState, target: 'verify', authorization });
|
|
11032
|
+
if (!decision || decision.ok !== false || decision.action !== 'block') {
|
|
11033
|
+
throw new Error('[' + label + '] resolveReentryDecision 应返回 block,实际 ' + JSON.stringify(decision));
|
|
11034
|
+
}
|
|
11035
|
+
}
|
|
11036
|
+
const applied = decide({ protocol, state: decideState, target: 'verify', authorization: valid });
|
|
11037
|
+
if (!applied || applied.ok !== true || applied.action !== 'apply' || applied.round !== 1) {
|
|
11038
|
+
throw new Error('合法授权 + archive 源应返回 apply / 第 1 轮,实际 ' + JSON.stringify(applied));
|
|
11039
|
+
}
|
|
11040
|
+
},
|
|
11041
|
+
},
|
|
11042
|
+
|
|
11043
|
+
// 261: 越界拦截(AC-5 / AC-6 / AC-7)——目标不在白名单 / 协议 disabled 节点 / 源不是
|
|
11044
|
+
// archive / status=completed / 归档移动已发生 / 超轮次上限:一律 BLOCK 且 state 字节零改写;
|
|
11045
|
+
// 轮次按 change 隔离(他 change 的历史事件不占本 change 配额)——同场景断言 BLOCK 与放行两态。
|
|
11046
|
+
{
|
|
11047
|
+
name: '261 越界拦截:目标/协议/源/归档移动/上限全 BLOCK 零改写 + 轮次跨 change 隔离',
|
|
11048
|
+
run: (dir) => {
|
|
11049
|
+
// ① 目标不在白名单(design / open / archive 自身)
|
|
11050
|
+
for (const target of ['design', 'open', 'archive']) {
|
|
11051
|
+
writeReentryChangeDir(dir);
|
|
11052
|
+
writeState(dir, reentryArchiveState());
|
|
11053
|
+
const bytes = readStateBytes(dir);
|
|
11054
|
+
const res = runReenter(dir, target, { source: 'user-approval', reason: 'x' });
|
|
11055
|
+
assertExit(res, 1);
|
|
11056
|
+
assertOut(res, 'BLOCKED');
|
|
11057
|
+
assertStateBytesUnchanged(dir, bytes, '目标越界: ' + target);
|
|
11058
|
+
}
|
|
11059
|
+
// ② 协议 disabled 节点不可作目标(自定义协议禁用 verify)
|
|
11060
|
+
const customProtocolPath = path.join(dir, 'reentry-protocol-disabled.json');
|
|
11061
|
+
const customProtocol = readScenarioProtocol(dir);
|
|
11062
|
+
customProtocol.nodes.find((n) => n.id === 'verify').disabled = true;
|
|
11063
|
+
writeFile(dir, 'reentry-protocol-disabled.json', JSON.stringify(customProtocol, null, 2) + '\n');
|
|
11064
|
+
writeState(dir, reentryArchiveState());
|
|
11065
|
+
const bytesDisabled = readStateBytes(dir);
|
|
11066
|
+
const resDisabled = runReenter(dir, 'verify', {
|
|
11067
|
+
source: 'user-approval', reason: 'x', extra: ['--protocol', customProtocolPath],
|
|
11068
|
+
});
|
|
11069
|
+
assertExit(resDisabled, 1);
|
|
11070
|
+
assertOut(resDisabled, 'BLOCKED');
|
|
11071
|
+
assertStateBytesUnchanged(dir, bytesDisabled, '协议 disabled 节点');
|
|
11072
|
+
// ③ 源不是 archive(execute 驻留;目标 verify 形态未成立 → 不被空操作短路)
|
|
11073
|
+
writeState(dir, reentryArchiveState({ currentNode: 'execute' }));
|
|
11074
|
+
const bytesSource = readStateBytes(dir);
|
|
11075
|
+
const resSource = runReenter(dir, 'verify', { source: 'user-approval', reason: 'x' });
|
|
11076
|
+
assertExit(resSource, 1);
|
|
11077
|
+
assertOut(resSource, 'BLOCKED');
|
|
11078
|
+
assertStateBytesUnchanged(dir, bytesSource, '源不是 archive');
|
|
11079
|
+
// ④ status=completed(归档已出口 / 已发布形态)→ BLOCK + 人工处置或新 change 指引
|
|
11080
|
+
writeState(dir, reentryArchiveState({ status: 'completed' }));
|
|
11081
|
+
const bytesCompleted = readStateBytes(dir);
|
|
11082
|
+
const resCompleted = runReenter(dir, 'verify', { source: 'user-approval', reason: 'x' });
|
|
11083
|
+
assertExit(resCompleted, 1);
|
|
11084
|
+
assertOut(resCompleted, 'BLOCKED');
|
|
11085
|
+
assertOutMatches(resCompleted, /人工|新 ?change|hotfix/, 'status=completed 指引');
|
|
11086
|
+
assertStateBytesUnchanged(dir, bytesCompleted, 'status=completed');
|
|
11087
|
+
// ⑤ 归档移动已发生(.specs/<id>/ 不在原位,已搬入 .specs/archive/<日期>-<id>/)
|
|
11088
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID), { recursive: true, force: true });
|
|
11089
|
+
writeFile(dir, '.specs/archive/2026-09-26-' + CHANGE_ID + '/CHANGE.md', '# CHANGE\n\n## Why\n\n已归档。\n');
|
|
11090
|
+
writeState(dir, reentryArchiveState());
|
|
11091
|
+
const bytesMoved = readStateBytes(dir);
|
|
11092
|
+
const resMoved = runReenter(dir, 'verify', { source: 'user-approval', reason: 'x' });
|
|
11093
|
+
assertExit(resMoved, 1);
|
|
11094
|
+
assertOut(resMoved, 'BLOCKED');
|
|
11095
|
+
assertOutMatches(resMoved, /人工|新 ?change|hotfix/, '归档移动已发生指引');
|
|
11096
|
+
assertStateBytesUnchanged(dir, bytesMoved, '归档移动已发生');
|
|
11097
|
+
// ⑥ 超轮次上限:本 change 已有 3 条 reentry-applied → 第 4 次 BLOCK + 「继续 / 停止」指引
|
|
11098
|
+
writeReentryChangeDir(dir);
|
|
11099
|
+
writeState(dir, reentryArchiveState({
|
|
11100
|
+
history: [reentryHistoryEvent(1), reentryHistoryEvent(2), reentryHistoryEvent(3)],
|
|
11101
|
+
}));
|
|
11102
|
+
const bytesCapped = readStateBytes(dir);
|
|
11103
|
+
const resCapped = runReenter(dir, 'verify', { source: 'user-approval', reason: 'x' });
|
|
11104
|
+
assertExit(resCapped, 1);
|
|
11105
|
+
assertOut(resCapped, 'BLOCKED');
|
|
11106
|
+
assertOut(resCapped, '继续');
|
|
11107
|
+
assertOut(resCapped, '停止');
|
|
11108
|
+
assertStateBytesUnchanged(dir, bytesCapped, '超轮次上限');
|
|
11109
|
+
// ⑦ 轮次跨 change 隔离:他 change 的 3 条事件不占本 change 配额 → 放行且为第 1 轮
|
|
11110
|
+
writeState(dir, reentryArchiveState({
|
|
11111
|
+
history: [
|
|
11112
|
+
reentryHistoryEvent(1, 'other-change'),
|
|
11113
|
+
reentryHistoryEvent(2, 'other-change'),
|
|
11114
|
+
reentryHistoryEvent(3, 'other-change'),
|
|
11115
|
+
],
|
|
11116
|
+
}));
|
|
11117
|
+
const resIsolated = runReenter(dir, 'verify', { source: 'user-approval', reason: 'x' });
|
|
11118
|
+
assertExit(resIsolated, 0);
|
|
11119
|
+
assertOut(resIsolated, '1/3');
|
|
11120
|
+
const isolatedState = readScenarioState(dir);
|
|
11121
|
+
const appliedEvent = (isolatedState.history || [])
|
|
11122
|
+
.find((e) => e.event === 'reentry-applied' && e.change === CHANGE_ID);
|
|
11123
|
+
if (!appliedEvent || appliedEvent.round !== 1) {
|
|
11124
|
+
throw new Error('他 change 的轮次事件不应占用本 change 配额(本 change 应为第 1 轮),实际 '
|
|
11125
|
+
+ JSON.stringify(appliedEvent));
|
|
11126
|
+
}
|
|
11127
|
+
// ⑧ select 入口收紧:多段路径(归档相对路径形态)与保留目录名不得被选为 activeChange
|
|
11128
|
+
const selectEnv = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
11129
|
+
fs.mkdirSync(path.join(dir, '.specs', 'archive', '2026-09-26-' + CHANGE_ID), { recursive: true });
|
|
11130
|
+
const beforeSelect = readStateBytes(dir);
|
|
11131
|
+
assertExit(runState(['select', 'archive/2026-09-26-' + CHANGE_ID], dir, selectEnv), 1);
|
|
11132
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 归档相对路径');
|
|
11133
|
+
assertExit(runState(['select', 'archive'], dir, selectEnv), 1);
|
|
11134
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 保留目录名');
|
|
11135
|
+
// ⑧b 名字变体族:保留目录名大小写变体(ARCHIVE/Archive)、真实目录名的大小写变体(CH)与
|
|
11136
|
+
// 首尾空白变体在大小写不敏感文件系统上同样可达,但会让 activeChange 与实际目录名不一致
|
|
11137
|
+
// (轮次事件按 activeChange 精确匹配 → 配额被换键重置)→ 一律拒绝且 state 字节零改写
|
|
11138
|
+
assertExit(runState(['select', 'ARCHIVE'], dir, selectEnv), 1);
|
|
11139
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 保留目录名大小写变体');
|
|
11140
|
+
assertExit(runState(['select', 'Archive'], dir, selectEnv), 1);
|
|
11141
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 保留目录名混合大小写变体');
|
|
11142
|
+
const caseVariant = String(CHANGE_ID).toUpperCase();
|
|
11143
|
+
if (caseVariant !== CHANGE_ID) {
|
|
11144
|
+
assertExit(runState(['select', caseVariant], dir, selectEnv), 1);
|
|
11145
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 真实目录名大小写变体');
|
|
11146
|
+
}
|
|
11147
|
+
assertExit(runState(['select', ' ' + CHANGE_ID + ' '], dir, selectEnv), 1);
|
|
11148
|
+
assertStateBytesUnchanged(dir, beforeSelect, 'select 首尾空白变体');
|
|
11149
|
+
if (readScenarioState(dir).activeChange !== CHANGE_ID) {
|
|
11150
|
+
throw new Error('被拒绝的 select 不得改写 activeChange:' + JSON.stringify(readScenarioState(dir).activeChange));
|
|
11151
|
+
}
|
|
11152
|
+
// ⑨ change 键被换成归档相对路径(换键重置轮次配额的绕过形态)→ 写盘前 BLOCK:本 change 的
|
|
11153
|
+
// 3 条事件既不得被换键忽略,也不得产生新事件 / 备份 / 机器字段改写
|
|
11154
|
+
writeState(dir, reentryArchiveState({
|
|
11155
|
+
activeChange: 'archive/2026-09-26-' + CHANGE_ID,
|
|
11156
|
+
history: [reentryHistoryEvent(1), reentryHistoryEvent(2), reentryHistoryEvent(3)],
|
|
11157
|
+
}));
|
|
11158
|
+
const nestedBytes = readStateBytes(dir);
|
|
11159
|
+
const nestedBackupsBefore = reentryBackupFiles(dir).length;
|
|
11160
|
+
const nestedRes = runReenter(dir, 'verify', { source: 'user-approval', reason: '换键重入' });
|
|
11161
|
+
assertExit(nestedRes, 1);
|
|
11162
|
+
assertOut(nestedRes, 'BLOCKED');
|
|
11163
|
+
assertStateBytesUnchanged(dir, nestedBytes, '归档相对路径 change 名');
|
|
11164
|
+
if (reentryBackupFiles(dir).length !== nestedBackupsBefore) {
|
|
11165
|
+
throw new Error('归档相对路径 change 名不得产生备份');
|
|
11166
|
+
}
|
|
11167
|
+
// ⑩ history 存在但非数组 → fail-closed BLOCK,不得静默清空覆盖审计历史
|
|
11168
|
+
writeReentryChangeDir(dir);
|
|
11169
|
+
writeState(dir, reentryArchiveState({ history: 'corrupted-history' }));
|
|
11170
|
+
const corruptBytes = readStateBytes(dir);
|
|
11171
|
+
const corruptRes = runReenter(dir, 'verify', { source: 'user-approval', reason: 'history 损坏' });
|
|
11172
|
+
assertExit(corruptRes, 1);
|
|
11173
|
+
assertOut(corruptRes, 'BLOCKED');
|
|
11174
|
+
assertOut(corruptRes, 'history');
|
|
11175
|
+
assertStateBytesUnchanged(dir, corruptBytes, '非数组 history');
|
|
11176
|
+
if (readScenarioState(dir).history !== 'corrupted-history') {
|
|
11177
|
+
throw new Error('损坏的 history 不得被静默清空覆盖:' + JSON.stringify(readScenarioState(dir).history));
|
|
11178
|
+
}
|
|
11179
|
+
// ⑪ 备份写入包含性:.specs/<change> 为 junction(指向 runRoot 外)→ BLOCK 零改写,
|
|
11180
|
+
// runRoot 外不得出现任何备份字节
|
|
11181
|
+
const linkedOutsideDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flow-comet-reentry-outside-'));
|
|
11182
|
+
writeFile(linkedOutsideDir, 'CHANGE.md', '# CHANGE\n\n## Why\n\njunction 目标。\n');
|
|
11183
|
+
const linkedName = 'linked-change';
|
|
11184
|
+
fs.symlinkSync(linkedOutsideDir, path.join(dir, '.specs', linkedName), 'junction');
|
|
11185
|
+
writeState(dir, reentryArchiveState({ activeChange: linkedName }));
|
|
11186
|
+
const linkedBytes = readStateBytes(dir);
|
|
11187
|
+
const linkedRes = runReenter(dir, 'verify', { source: 'user-approval', reason: 'junction 逃逸' });
|
|
11188
|
+
assertExit(linkedRes, 1);
|
|
11189
|
+
assertOut(linkedRes, 'BLOCKED');
|
|
11190
|
+
assertStateBytesUnchanged(dir, linkedBytes, 'junction 逃逸');
|
|
11191
|
+
if (fs.existsSync(path.join(linkedOutsideDir, '.reentry-backups'))) {
|
|
11192
|
+
throw new Error('junction 逃逸不得在 runRoot 外产生备份:'
|
|
11193
|
+
+ JSON.stringify(fs.readdirSync(path.join(linkedOutsideDir, '.reentry-backups'))));
|
|
11194
|
+
}
|
|
11195
|
+
fs.rmSync(linkedOutsideDir, { recursive: true, force: true });
|
|
11196
|
+
try { fs.rmSync(path.join(dir, '.specs', linkedName), { recursive: true, force: true }); } catch { /* 场景目录整体清理兜底 */ }
|
|
11197
|
+
// ⑫ 上限后的显式授权续轮(AC-7 后半句):合法授权 → 放行并计下一轮(事件 / 授权留痕带
|
|
11198
|
+
// 续轮标记与原因);授权轮次不足或未达上限即传续轮 → BLOCK 且 state 字节零改写
|
|
11199
|
+
const threeRounds = [reentryHistoryEvent(1), reentryHistoryEvent(2), reentryHistoryEvent(3)];
|
|
11200
|
+
writeReentryChangeDir(dir);
|
|
11201
|
+
writeState(dir, reentryArchiveState({ history: threeRounds }));
|
|
11202
|
+
const continued = runReenter(dir, 'verify', {
|
|
11203
|
+
source: 'admin-approval', reason: '上限后显式授权续轮', extra: ['--continue-round', '4'],
|
|
11204
|
+
});
|
|
11205
|
+
assertExit(continued, 0);
|
|
11206
|
+
assertOut(continued, 'REENTRY');
|
|
11207
|
+
assertOut(continued, '续轮');
|
|
11208
|
+
const continuedState = readScenarioState(dir);
|
|
11209
|
+
if (continuedState.currentNode !== 'verify') {
|
|
11210
|
+
throw new Error('续轮放行后 currentNode 应为 verify,实际 ' + JSON.stringify(continuedState.currentNode));
|
|
11211
|
+
}
|
|
11212
|
+
const continuedEvent = (continuedState.history || [])
|
|
11213
|
+
.filter((e) => e.event === 'reentry-applied')
|
|
11214
|
+
.pop();
|
|
11215
|
+
if (!continuedEvent || continuedEvent.round !== 4 || continuedEvent.change !== CHANGE_ID
|
|
11216
|
+
|| continuedEvent.continuationAuthorized !== true
|
|
11217
|
+
|| continuedEvent.reason !== '上限后显式授权续轮') {
|
|
11218
|
+
throw new Error('续轮审计事件字段不符(round=4 / change / 续轮标记 / reason):' + JSON.stringify(continuedEvent));
|
|
11219
|
+
}
|
|
11220
|
+
const continuedRecord = continuedState.evidence?.verify?.reentryAuthorization;
|
|
11221
|
+
if (!continuedRecord || continuedRecord.continuationAuthorized !== true
|
|
11222
|
+
|| continuedRecord.reason !== '上限后显式授权续轮') {
|
|
11223
|
+
throw new Error('续轮授权留痕不符:' + JSON.stringify(continuedRecord));
|
|
11224
|
+
}
|
|
11225
|
+
writeState(dir, reentryArchiveState({ history: threeRounds }));
|
|
11226
|
+
const insufficientBytes = readStateBytes(dir);
|
|
11227
|
+
const insufficient = runReenter(dir, 'verify', {
|
|
11228
|
+
source: 'admin-approval', reason: '轮次不足', extra: ['--continue-round', '3'],
|
|
11229
|
+
});
|
|
11230
|
+
assertExit(insufficient, 1);
|
|
11231
|
+
assertOut(insufficient, 'BLOCKED');
|
|
11232
|
+
assertStateBytesUnchanged(dir, insufficientBytes, '续轮授权轮次不足');
|
|
11233
|
+
writeState(dir, reentryArchiveState());
|
|
11234
|
+
const earlyBytes = readStateBytes(dir);
|
|
11235
|
+
const early = runReenter(dir, 'verify', {
|
|
11236
|
+
source: 'admin-approval', reason: '未达上限', extra: ['--continue-round', '4'],
|
|
11237
|
+
});
|
|
11238
|
+
assertExit(early, 1);
|
|
11239
|
+
assertOut(early, 'BLOCKED');
|
|
11240
|
+
assertStateBytesUnchanged(dir, earlyBytes, '未达上限即传续轮');
|
|
11241
|
+
// ⑬ 写盘失败路径:原子写因临时路径被占而失败 → 非零退出、state 不截断、本次孤儿备份回滚
|
|
11242
|
+
writeReentryChangeDir(dir);
|
|
11243
|
+
writeState(dir, reentryArchiveState());
|
|
11244
|
+
const atomicBytes = readStateBytes(dir);
|
|
11245
|
+
const atomicBackupsBefore = reentryBackupFiles(dir);
|
|
11246
|
+
const blockedTempDir = path.join(dir, '.flow-comet', 'flow-comet-state.json.tmp');
|
|
11247
|
+
fs.mkdirSync(blockedTempDir, { recursive: true });
|
|
11248
|
+
const atomicRes = runReenter(dir, 'verify', { source: 'user-approval', reason: '模拟写盘失败' });
|
|
11249
|
+
assertExit(atomicRes, 1);
|
|
11250
|
+
assertStateBytesUnchanged(dir, atomicBytes, '写盘失败路径');
|
|
11251
|
+
if (!isDeepStrictEqual(reentryBackupFiles(dir), atomicBackupsBefore)) {
|
|
11252
|
+
throw new Error('写盘失败必须回滚本次孤儿备份:before=' + JSON.stringify(atomicBackupsBefore)
|
|
11253
|
+
+ ' after=' + JSON.stringify(reentryBackupFiles(dir)));
|
|
11254
|
+
}
|
|
11255
|
+
fs.rmSync(blockedTempDir, { recursive: true, force: true });
|
|
11256
|
+
},
|
|
11257
|
+
},
|
|
11258
|
+
|
|
11259
|
+
// 262: 恢复链(AC-2 的「BLOCK → 补全授权 → 放行」/ 编排顺序 / 幂等重放)——未授权 BLOCK 且
|
|
11260
|
+
// 字节零改写、零备份;补齐授权三元组后放行(备份 + 转移 + 审计);重复同目标调用 = 空操作
|
|
11261
|
+
// (放行 + 可见提示 + 零备份新增 + 零计数 + 零事件 + 字节零改写)。
|
|
11262
|
+
{
|
|
11263
|
+
name: '262 恢复链:未授权 BLOCK → 补全授权放行 → 重复同目标空操作(零副作用)',
|
|
11264
|
+
run: (dir) => {
|
|
11265
|
+
writeReentryChangeDir(dir);
|
|
11266
|
+
writeState(dir, reentryArchiveState());
|
|
11267
|
+
const blockedBytes = readStateBytes(dir);
|
|
11268
|
+
const resBlocked = runReenter(dir, 'verify');
|
|
11269
|
+
assertExit(resBlocked, 1);
|
|
11270
|
+
assertOut(resBlocked, 'BLOCKED');
|
|
11271
|
+
assertStateBytesUnchanged(dir, blockedBytes, '未授权 BLOCK');
|
|
11272
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
11273
|
+
throw new Error('未授权 BLOCK 不得产生备份');
|
|
11274
|
+
}
|
|
11275
|
+
const resAllowed = runReenter(dir, 'verify', { source: 'user-approval', reason: '用户显式授权重入' });
|
|
11276
|
+
assertExit(resAllowed, 0);
|
|
11277
|
+
assertOut(resAllowed, 'REENTRY');
|
|
11278
|
+
const appliedState = readScenarioState(dir);
|
|
11279
|
+
if (appliedState.currentNode !== 'verify') {
|
|
11280
|
+
throw new Error('补全授权后应放行并把 currentNode 置为 verify,实际 ' + JSON.stringify(appliedState.currentNode));
|
|
11281
|
+
}
|
|
11282
|
+
const backupsAfterApply = reentryBackupFiles(dir);
|
|
11283
|
+
if (backupsAfterApply.length !== 1) {
|
|
11284
|
+
throw new Error('放行应恰产生 1 份备份,实际 ' + JSON.stringify(backupsAfterApply));
|
|
11285
|
+
}
|
|
11286
|
+
const appliedEvents = (appliedState.history || []).filter((e) => e.event === 'reentry-applied');
|
|
11287
|
+
if (appliedEvents.length !== 1) {
|
|
11288
|
+
throw new Error('放行应恰写 1 条 reentry-applied 事件,实际 ' + JSON.stringify(appliedEvents));
|
|
11289
|
+
}
|
|
11290
|
+
const noopBytes = readStateBytes(dir);
|
|
11291
|
+
const resNoop = runReenter(dir, 'verify', { source: 'user-approval', reason: '重复调用同目标' });
|
|
11292
|
+
assertExit(resNoop, 0);
|
|
11293
|
+
assertNotOut(resNoop, 'BLOCKED');
|
|
11294
|
+
if (outputText(resNoop).trim() === '') {
|
|
11295
|
+
throw new Error('空操作应打印一条可见提示');
|
|
11296
|
+
}
|
|
11297
|
+
assertStateBytesUnchanged(dir, noopBytes, '重复同目标空操作');
|
|
11298
|
+
if (!isDeepStrictEqual(reentryBackupFiles(dir), backupsAfterApply)) {
|
|
11299
|
+
throw new Error('空操作不得新增备份:' + JSON.stringify(reentryBackupFiles(dir)));
|
|
11300
|
+
}
|
|
11301
|
+
const noopState = readScenarioState(dir);
|
|
11302
|
+
if ((noopState.history || []).length !== (appliedState.history || []).length) {
|
|
11303
|
+
throw new Error('空操作不得写事件:history 长度由 ' + (appliedState.history || []).length
|
|
11304
|
+
+ ' 变为 ' + (noopState.history || []).length);
|
|
11305
|
+
}
|
|
11306
|
+
},
|
|
11307
|
+
},
|
|
11308
|
+
|
|
11309
|
+
// 263: 旧 change(无 newChange 字段 · AC-3 与本 change 的显式例外)——授权门禁对一切
|
|
11310
|
+
// change 无条件 fail-closed:旧 change 未授权同样 BLOCK(安全面不因 change 新旧降级);
|
|
11311
|
+
// 合法授权放行并与新 change 走同一转移 / 审计路径。
|
|
11312
|
+
{
|
|
11313
|
+
name: '263 旧 change:未授权仍 BLOCK(显式例外)+ 合法授权放行',
|
|
11314
|
+
run: (dir) => {
|
|
11315
|
+
writeReentryChangeDir(dir);
|
|
11316
|
+
const legacyState = reentryArchiveState();
|
|
11317
|
+
delete legacyState.newChange;
|
|
11318
|
+
writeState(dir, legacyState);
|
|
11319
|
+
const blockedBytes = readStateBytes(dir);
|
|
11320
|
+
const resBlocked = runReenter(dir, 'verify');
|
|
11321
|
+
assertExit(resBlocked, 1);
|
|
11322
|
+
assertOut(resBlocked, 'BLOCKED');
|
|
11323
|
+
assertStateBytesUnchanged(dir, blockedBytes, '旧 change 未授权');
|
|
11324
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
11325
|
+
throw new Error('旧 change 未授权 BLOCK 不得产生备份');
|
|
11326
|
+
}
|
|
11327
|
+
const resAllowed = runReenter(dir, 'verify', { source: 'user-approval', reason: '旧 change 显式授权' });
|
|
11328
|
+
assertExit(resAllowed, 0);
|
|
11329
|
+
assertOut(resAllowed, 'REENTRY');
|
|
11330
|
+
const st = readScenarioState(dir);
|
|
11331
|
+
if (st.currentNode !== 'verify') {
|
|
11332
|
+
throw new Error('旧 change 合法授权应放行并转移,实际 ' + JSON.stringify(st.currentNode));
|
|
11333
|
+
}
|
|
11334
|
+
if (!isDeepStrictEqual(st.completedNodes, REENTRY_EXPECTED_INTERSECTION.verify)) {
|
|
11335
|
+
throw new Error('旧 change 转移后 completedNodes 应为前驱交集,实际 ' + JSON.stringify(st.completedNodes));
|
|
11336
|
+
}
|
|
11337
|
+
const appliedEvent = (st.history || []).find((e) => e.event === 'reentry-applied');
|
|
11338
|
+
if (!appliedEvent || appliedEvent.change !== CHANGE_ID || appliedEvent.round !== 1) {
|
|
11339
|
+
throw new Error('旧 change 的审计事件应带 change 且为第 1 轮,实际 ' + JSON.stringify(appliedEvent));
|
|
11340
|
+
}
|
|
11341
|
+
// 最小旧 state(仅 7 个键、无 readState 兼容默认字段):apply 只写本次实际改动的字段,
|
|
11342
|
+
// 兼容默认值不得随重入回写(键集逐项不变——「其余字段零改写」口径覆盖真实最小旧 state)
|
|
11343
|
+
const minimalLegacy = {
|
|
11344
|
+
activeChange: CHANGE_ID,
|
|
11345
|
+
currentNode: 'archive',
|
|
11346
|
+
completedNodes: [...REENTRY_FULL_COMPLETED],
|
|
11347
|
+
evidence: {},
|
|
11348
|
+
verifyFailures: 0,
|
|
11349
|
+
status: 'running',
|
|
11350
|
+
history: [{ event: 'exit-applied', node: 'verify', at: '2026-09-20T00:00:00.000Z', change: CHANGE_ID }],
|
|
11351
|
+
};
|
|
11352
|
+
writeState(dir, minimalLegacy);
|
|
11353
|
+
const minimalKeysBefore = Object.keys(readScenarioState(dir)).sort();
|
|
11354
|
+
const minimalRes = runReenter(dir, 'verify', { source: 'user-approval', reason: '最小旧 state 重入' });
|
|
11355
|
+
assertExit(minimalRes, 0);
|
|
11356
|
+
assertOut(minimalRes, 'REENTRY');
|
|
11357
|
+
const minimalAfter = readScenarioState(dir);
|
|
11358
|
+
const minimalKeysAfter = Object.keys(minimalAfter).sort();
|
|
11359
|
+
if (!isDeepStrictEqual(minimalKeysAfter, minimalKeysBefore)) {
|
|
11360
|
+
throw new Error('最小旧 state 重入后键集必须逐项不变(兼容默认值不得回写):before='
|
|
11361
|
+
+ JSON.stringify(minimalKeysBefore) + ' after=' + JSON.stringify(minimalKeysAfter));
|
|
11362
|
+
}
|
|
11363
|
+
for (const defaultKey of ['executionMode', 'directOverride', 'branchMode', 'enablePrReview', 'branchPrefix']) {
|
|
11364
|
+
if (defaultKey in minimalAfter) {
|
|
11365
|
+
throw new Error('readState 兼容默认字段不得随重入回写: ' + defaultKey);
|
|
11366
|
+
}
|
|
11367
|
+
}
|
|
11368
|
+
},
|
|
11369
|
+
},
|
|
11370
|
+
|
|
11371
|
+
// 264: history 事件类型集合静态锚(唯一事件类型例外 / 禁止扩散)——扫描引擎生产脚本的
|
|
11372
|
+
// 事件类型字面量:写侧集合必须恰为 {exit-applied, reentry-applied}(reenter 写侧未落地即
|
|
11373
|
+
// RED),读侧集合必须 ⊆ 允许集(出现第三种事件类型即红);另锚 reentry-applied 写点必须
|
|
11374
|
+
// 带 change 字段(事件对象的动态断言在 259 / 263)。
|
|
11375
|
+
{
|
|
11376
|
+
name: '264 history 事件类型集合静态锚:既有类型 + reentry-applied(新增即红)',
|
|
11377
|
+
run: () => {
|
|
11378
|
+
const allowed = ['exit-applied', 'reentry-applied'];
|
|
11379
|
+
const scripts = fs.readdirSync(__dirname)
|
|
11380
|
+
.filter((f) => f.endsWith('.mjs') && f !== 'guard-self-test.mjs' && f !== 'system-test.mjs');
|
|
11381
|
+
const writers = new Set();
|
|
11382
|
+
const readers = new Set();
|
|
11383
|
+
let writeSite = null;
|
|
11384
|
+
for (const file of scripts) {
|
|
11385
|
+
const text = fs.readFileSync(path.join(__dirname, file), 'utf8');
|
|
11386
|
+
for (const match of text.matchAll(/event:\s*'([a-z][a-z-]*)'/g)) {
|
|
11387
|
+
writers.add(match[1]);
|
|
11388
|
+
if (match[1] === 'reentry-applied') writeSite = { file, text, index: match.index };
|
|
11389
|
+
}
|
|
11390
|
+
for (const match of text.matchAll(/\.event\s*(?:===|!==)\s*'([a-z][a-z-]*)'/g)) {
|
|
11391
|
+
readers.add(match[1]);
|
|
11392
|
+
}
|
|
11393
|
+
}
|
|
11394
|
+
const extra = [...new Set([...writers, ...readers])].filter((type) => !allowed.includes(type));
|
|
11395
|
+
if (extra.length > 0) {
|
|
11396
|
+
throw new Error('history 事件类型出现允许集外的新类型(唯一事件类型例外不得扩散): ' + extra.join(', ')
|
|
11397
|
+
+ ';写侧=' + [...writers].join(',') + ';读侧=' + [...readers].join(','));
|
|
11398
|
+
}
|
|
11399
|
+
const missingWriters = allowed.filter((type) => !writers.has(type));
|
|
11400
|
+
if (missingWriters.length > 0) {
|
|
11401
|
+
throw new Error('history 事件类型写侧缺类型(reenter 未落地即 RED): ' + missingWriters.join(', ')
|
|
11402
|
+
+ ';实际写侧=' + [...writers].join(','));
|
|
11403
|
+
}
|
|
11404
|
+
if (!writeSite) {
|
|
11405
|
+
throw new Error('reentry-applied 写点缺失(审计事件必须由引擎脚本写入)');
|
|
11406
|
+
}
|
|
11407
|
+
const windowText = writeSite.text.slice(writeSite.index, writeSite.index + 800);
|
|
11408
|
+
if (!/\bchange\s*:/.test(windowText)) {
|
|
11409
|
+
throw new Error('reentry-applied 写点必须带 change 字段(跨 change 轮次隔离依据): ' + writeSite.file);
|
|
11410
|
+
}
|
|
11411
|
+
},
|
|
11412
|
+
},
|
|
11413
|
+
|
|
11414
|
+
// 265: 幂等锚(空操作判定)——目标形态已成立(currentNode=target 且 completedNodes 已等于
|
|
11415
|
+
// 前驱交集)时重复调用 = 空操作:放行 + 可见提示 + 不备份 / 不计数 / 不写事件 / state 字节
|
|
11416
|
+
// 零改写。夹具直接构造目标形态(不经 apply 路径),同时锁定判定顺序:空操作短路必须先于
|
|
11417
|
+
// 源判定——否则 currentNode=verify ≠ archive 会先被源门禁误 BLOCK;但空操作短路不得先于
|
|
11418
|
+
// 上限判定——达上限的同目标形态必须走人工裁决 BLOCK(不得以空操作退出 0)。
|
|
11419
|
+
{
|
|
11420
|
+
name: '265 幂等锚:目标形态已成立的重复调用 = 空操作(零备份·零计数·零事件·零改写),超限同目标仍 BLOCK',
|
|
11421
|
+
run: (dir) => {
|
|
11422
|
+
writeReentryChangeDir(dir);
|
|
11423
|
+
writeState(dir, reentryArchiveState({
|
|
11424
|
+
currentNode: 'verify',
|
|
11425
|
+
completedNodes: [...REENTRY_EXPECTED_INTERSECTION.verify],
|
|
11426
|
+
}));
|
|
11427
|
+
const bytes = readStateBytes(dir);
|
|
11428
|
+
const beforeHistoryLength = (readScenarioState(dir).history || []).length;
|
|
11429
|
+
const res = runReenter(dir, 'verify', { source: 'user-approval', reason: '重复调用同目标' });
|
|
11430
|
+
assertExit(res, 0);
|
|
11431
|
+
assertNotOut(res, 'BLOCKED');
|
|
11432
|
+
if (outputText(res).trim() === '') {
|
|
11433
|
+
throw new Error('空操作应打印一条可见提示');
|
|
11434
|
+
}
|
|
11435
|
+
assertStateBytesUnchanged(dir, bytes, '目标形态已成立的空操作');
|
|
11436
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
11437
|
+
throw new Error('空操作不得备份:' + JSON.stringify(reentryBackupFiles(dir)));
|
|
11438
|
+
}
|
|
11439
|
+
const st = readScenarioState(dir);
|
|
11440
|
+
if ((st.history || []).length !== beforeHistoryLength) {
|
|
11441
|
+
throw new Error('空操作不得写事件:history 长度由 ' + beforeHistoryLength + ' 变为 ' + (st.history || []).length);
|
|
11442
|
+
}
|
|
11443
|
+
if ((st.history || []).some((e) => e.event === 'reentry-applied')) {
|
|
11444
|
+
throw new Error('空操作不得写入 reentry-applied 事件');
|
|
11445
|
+
}
|
|
11446
|
+
// 上限判定必须先于空操作短路:达到上限的 change 即使处于同目标形态也走人工裁决 BLOCK,
|
|
11447
|
+
// 不得以空操作退出 0(幂等豁免不越过上限;state 仍字节零改写)
|
|
11448
|
+
writeState(dir, reentryArchiveState({
|
|
11449
|
+
currentNode: 'verify',
|
|
11450
|
+
completedNodes: [...REENTRY_EXPECTED_INTERSECTION.verify],
|
|
11451
|
+
history: [reentryHistoryEvent(1), reentryHistoryEvent(2), reentryHistoryEvent(3)],
|
|
11452
|
+
}));
|
|
11453
|
+
const cappedBytes = readStateBytes(dir);
|
|
11454
|
+
const cappedRes = runReenter(dir, 'verify', { source: 'user-approval', reason: '超限同目标' });
|
|
11455
|
+
assertExit(cappedRes, 1);
|
|
11456
|
+
assertOut(cappedRes, 'BLOCKED');
|
|
11457
|
+
assertOut(cappedRes, '继续');
|
|
11458
|
+
assertOut(cappedRes, '停止');
|
|
11459
|
+
assertNotOut(cappedRes, '空操作');
|
|
11460
|
+
assertStateBytesUnchanged(dir, cappedBytes, '超限同目标形态');
|
|
11461
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
11462
|
+
throw new Error('超限同目标形态不得产生备份:' + JSON.stringify(reentryBackupFiles(dir)));
|
|
11463
|
+
}
|
|
11464
|
+
if ((readScenarioState(dir).history || []).length !== 3) {
|
|
11465
|
+
throw new Error('超限同目标形态不得追加审计事件');
|
|
11466
|
+
}
|
|
11467
|
+
},
|
|
11468
|
+
},
|
|
11469
|
+
];
|
|
11470
|
+
// ---------- 运行 ----------
|
|
11471
|
+
|
|
11472
|
+
for (const sc of SCENARIOS) {
|
|
11473
|
+
const dir = makeTmp();
|
|
11474
|
+
try {
|
|
11475
|
+
// T06: 协议路径适配——真实项目协议位于 <项目根>/reference/workflow-protocol.json(runRoot 内)。
|
|
11476
|
+
// T03 起 workflow-guard 用 readProtocolFile(protected-path:协议路径必须在 runRoot 内),
|
|
11477
|
+
// 场景 runRoot=tmpdir、内置协议默认路径在 packageRoot(tmpdir 外)→ 复制到 <dir>/reference/ 内,
|
|
11478
|
+
// 由 runGuard 的 FLOW_COMET_PROTOCOL env 指向场景内副本。场景内 writeFile('reference/...') 或
|
|
11479
|
+
// --protocol CLI 覆盖保持后写优先语义(CLI --protocol 优先级高于 env)。
|
|
11480
|
+
const builtinCopy = path.join(dir, 'reference', 'workflow-protocol.json');
|
|
11481
|
+
fs.mkdirSync(path.dirname(builtinCopy), { recursive: true });
|
|
11482
|
+
fs.copyFileSync(BUILTIN_PROTOCOL_SOURCE, builtinCopy);
|
|
11483
|
+
await sc.run(dir);
|
|
11484
|
+
passed += 1;
|
|
11485
|
+
console.log('PASS: ' + sc.name);
|
|
11486
|
+
} catch (e) {
|
|
11487
|
+
failures.push({ name: sc.name, error: e.message });
|
|
11488
|
+
console.error('FAIL: ' + sc.name + '\n' + e.message);
|
|
11489
|
+
} finally {
|
|
11490
|
+
fs.rmSync(dir, { recursive: true, force: true });
|
|
11491
|
+
}
|
|
11492
|
+
}
|
|
11493
|
+
|
|
11494
|
+
console.log('RESULT: ' + passed + '/' + SCENARIOS.length + ' scenarios passed');
|
|
11495
|
+
|
|
11496
|
+
// 文档一致性自检(场景数纪律 + 公开产物零代号纪律工具化,2026-08-10):
|
|
11497
|
+
// ① 场景数:受检清单文档须与 SCENARIOS.length 一致(全变体检查),且清单条目必须真实存在
|
|
11498
|
+
// (AC-14:缺失显式报告,不静默跳过);
|
|
11499
|
+
// ② 公开产物零代号:公开文档不得含过程代号(场景编号/修复编号/批次/缺陷编号/问题级/验证代号/验证轮次/未公开概念——历史 CHANGELOG 回归实证)。
|
|
11500
|
+
// 仅权威源检出执行;安装副本(目标项目)无 flow-comet 文档面,跳过。
|
|
11501
|
+
if (isAuthoritativeSourceRepo()) {
|
|
11502
|
+
// ① 计数一致性受检清单(分发组恒检 + 维护者组整组在场时检;判据与场景 105 共用同一实现)
|
|
11503
|
+
// SCENARIO_COUNT_FILES(_MAINTAINER) / SYSTEM_TEST_COUNT_FILES(_MAINTAINER) 为模块级常量
|
|
11504
|
+
// (见文件头定义)——场景数与系统测试集项数两套计数合并检查
|
|
11505
|
+
for (const problem of countSyncProblems()) {
|
|
11506
|
+
failures.push({ name: '计数一致性', error: problem });
|
|
11507
|
+
console.error('FAIL: 计数一致性\n' + problem);
|
|
11508
|
+
}
|
|
11509
|
+
|
|
11510
|
+
// ①b 维护文档机检(docs/internal 死引用 + ROADMAP 最低结构;整组缺席即跳过)
|
|
11511
|
+
for (const problem of internalDocsProblems()) {
|
|
11512
|
+
failures.push({ name: '维护文档机检', error: problem });
|
|
11513
|
+
console.error('FAIL: 维护文档机检\n' + problem);
|
|
7375
11514
|
}
|
|
7376
11515
|
|
|
7377
11516
|
// ② 公开文档零代号(公开产物纪律——CHANGELOG 历史 S 编号回归的教训,2026-08-10)
|