flow-comet 1.6.3 → 1.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.flow-comet/skills/flow-comet/INSTALLED_VERSION +1 -1
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +11 -13
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +6 -6
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +67 -18878
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/items/a.mjs +1030 -0
- package/.flow-comet/skills/flow-comet/scripts/items/b.mjs +830 -0
- package/.flow-comet/skills/flow-comet/scripts/items/c.mjs +781 -0
- package/.flow-comet/skills/flow-comet/scripts/items/d.mjs +99 -0
- package/.flow-comet/skills/flow-comet/scripts/items/e.mjs +185 -0
- package/.flow-comet/skills/flow-comet/scripts/items/f.mjs +90 -0
- package/.flow-comet/skills/flow-comet/scripts/items/g.mjs +59 -0
- package/.flow-comet/skills/flow-comet/scripts/items/h.mjs +815 -0
- package/.flow-comet/skills/flow-comet/scripts/items/i.mjs +77 -0
- package/.flow-comet/skills/flow-comet/scripts/items/j.mjs +75 -0
- package/.flow-comet/skills/flow-comet/scripts/items/k.mjs +1427 -0
- package/.flow-comet/skills/flow-comet/scripts/items/l.mjs +275 -0
- package/.flow-comet/skills/flow-comet/scripts/items/m.mjs +614 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/count-derivation.mjs +97 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/fix-loop-node.mjs +196 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-evidence-gates.mjs +553 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-gates.mjs +837 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-routing.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-state-io.mjs +404 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-template-fidelity.mjs +302 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/guard-uidesign.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/reentry-node.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/replan-node.mjs +209 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-branch.mjs +49 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-bridgecheck.mjs +201 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-admin.mjs +141 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-flow.mjs +700 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-commands-recovery.mjs +578 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-determine.mjs +52 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-evolve-hint.mjs +55 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-explain.mjs +106 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-intelscan.mjs +58 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-io.mjs +147 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/state-skillmarkers.mjs +189 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/system-fixtures.mjs +1441 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/task-graph.mjs +471 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-assertions.mjs +509 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-fixtures.mjs +1228 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/test-helpers.mjs +237 -0
- package/.flow-comet/skills/flow-comet/scripts/lib/text-anchor-checks.mjs +2484 -0
- package/.flow-comet/skills/flow-comet/scripts/protocol-utils.mjs +2 -2
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +72 -1123
- package/.flow-comet/skills/flow-comet/scripts/scenarios/a.mjs +966 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/b.mjs +1233 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/c.mjs +1382 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/d.mjs +483 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/e.mjs +1388 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/f.mjs +1466 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/g.mjs +1364 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/h.mjs +1287 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/i.mjs +1436 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/j.mjs +1384 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/k.mjs +1338 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/l.mjs +1484 -0
- package/.flow-comet/skills/flow-comet/scripts/scenarios/m.mjs +971 -0
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +1 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -7559
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2476
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +5 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +27 -2190
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/README.md +52 -69
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +2 -2
- package/scripts/lib/installer-cleanup.mjs +152 -0
- package/scripts/lib/installer-flowkit.mjs +119 -0
- package/scripts/lib/installer-hooks.mjs +363 -0
- package/scripts/lib/installer-loader.mjs +220 -0
- package/scripts/lib/installer-migrate.mjs +236 -0
- package/scripts/lib/installer-platforms.mjs +314 -0
- package/scripts/prepare-env.mjs +21 -1313
|
@@ -0,0 +1,1436 @@
|
|
|
1
|
+
// 场景组 i — 命令写判定取向 · CONTEXT 段标题归一 · gitignore 访问故障 · 维护文档机检 · Fix 路由纯函数与受控归位
|
|
2
|
+
// 元素形态:`{ name, run }`;计数由 `lib/count-derivation.mjs` 从本目录聚合,不手抄数字。
|
|
3
|
+
// 组界按场景名前缀与文件内既有分段划,与入口 `SCENARIOS` 的拼接顺序一致。
|
|
4
|
+
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import { spawnSync } from 'child_process';
|
|
8
|
+
import {
|
|
9
|
+
assertExit,
|
|
10
|
+
assertNotOut,
|
|
11
|
+
assertOut,
|
|
12
|
+
runGuard,
|
|
13
|
+
writeFile,
|
|
14
|
+
writeState,
|
|
15
|
+
} from '../lib/test-helpers.mjs';
|
|
16
|
+
import {
|
|
17
|
+
CHANGE_ID,
|
|
18
|
+
PREPARE_ENV,
|
|
19
|
+
SCRIPTS_DIR,
|
|
20
|
+
handoffFor,
|
|
21
|
+
routeNodeModule,
|
|
22
|
+
scriptTreeFiles,
|
|
23
|
+
strictSummary,
|
|
24
|
+
writeIntakeArtifacts,
|
|
25
|
+
} from '../lib/test-fixtures.mjs';
|
|
26
|
+
import {
|
|
27
|
+
FIX_RETURN_FAMILY_COMPLETED,
|
|
28
|
+
FIX_RETURN_REVIEW_TEXT,
|
|
29
|
+
STALE_FIX_BATCH_SIGNATURE,
|
|
30
|
+
assertStateOnlyChanged,
|
|
31
|
+
fixBatchTaskText,
|
|
32
|
+
fixReturnBaseState,
|
|
33
|
+
fixReturnFamilyEvidence,
|
|
34
|
+
fixTaskBlock,
|
|
35
|
+
readScenarioProtocol,
|
|
36
|
+
readScenarioState,
|
|
37
|
+
requireRouteNodeExport,
|
|
38
|
+
writeFixReturnSummaries,
|
|
39
|
+
} from '../lib/test-assertions.mjs';
|
|
40
|
+
import {
|
|
41
|
+
PUBLIC_CODE_RE,
|
|
42
|
+
commentCodeProblems,
|
|
43
|
+
internalDocsProblems,
|
|
44
|
+
isDeclaredReferenceSkip,
|
|
45
|
+
maintainerFaceSkips,
|
|
46
|
+
vocabularyMirrorProblems,
|
|
47
|
+
} from '../lib/text-anchor-checks.mjs';
|
|
48
|
+
|
|
49
|
+
export const ENTRIES = [
|
|
50
|
+
|
|
51
|
+
// 243: `.gitignore` 读取的**访问类故障**(非「确实不存在」)不得当作「文件缺失」。
|
|
52
|
+
// 当作缺失时 existing='' 且 fileExists=false → 后续 writeFileSync 用默认 flag 'w' 把用户既有
|
|
53
|
+
// .gitignore **截断**为仅含受管条目(数据破坏);而该调用的自述契约是「失败即中止,可重跑自愈」。
|
|
54
|
+
// 修复后访问类故障原样抛出 → 安装中止且用户文件逐字节不变(与 lstatIfExists 同语义)。
|
|
55
|
+
// 故障注入用 `--require` 预加载(同场景 233 手法),只命中该项目的 .gitignore,其余读取走真实实现。
|
|
56
|
+
{
|
|
57
|
+
name: '243 .gitignore 读取访问类故障 → 中止安装且用户文件不被改写',
|
|
58
|
+
run: (dir) => {
|
|
59
|
+
if (!fs.existsSync(PREPARE_ENV)) return;
|
|
60
|
+
const proj = path.join(dir, 'proj-gitignore-fault');
|
|
61
|
+
fs.mkdirSync(proj, { recursive: true });
|
|
62
|
+
const initial = '# 用户既有内容\nnode_modules/\ndist/\n';
|
|
63
|
+
fs.writeFileSync(path.join(proj, '.gitignore'), initial, 'utf8');
|
|
64
|
+
const preloadName = 'gitignore-read-fault-preload.cjs';
|
|
65
|
+
writeFile(dir, preloadName, [
|
|
66
|
+
"const fs = require('node:fs');",
|
|
67
|
+
"const path = require('node:path');",
|
|
68
|
+
"const target = path.resolve(String(process.env.GITIGNORE_FAULT_TARGET || ''));",
|
|
69
|
+
'const realReadFileSync = fs.readFileSync;',
|
|
70
|
+
'fs.readFileSync = function (file, ...rest) {',
|
|
71
|
+
" if (target !== '' && path.resolve(String(file)) === target) {",
|
|
72
|
+
" const error = new Error('EACCES: permission denied, open ' + JSON.stringify(String(file)));",
|
|
73
|
+
" error.code = 'EACCES';",
|
|
74
|
+
' throw error;',
|
|
75
|
+
' }',
|
|
76
|
+
' return realReadFileSync.call(fs, file, ...rest);',
|
|
77
|
+
'};',
|
|
78
|
+
'',
|
|
79
|
+
].join('\n'));
|
|
80
|
+
const spawned = spawnSync(
|
|
81
|
+
process.execPath,
|
|
82
|
+
['--require', path.join(dir, preloadName), PREPARE_ENV, '--target', proj, '--platform', 'claude-code'],
|
|
83
|
+
{
|
|
84
|
+
cwd: dir,
|
|
85
|
+
env: { ...process.env, GITIGNORE_FAULT_TARGET: path.join(proj, '.gitignore') },
|
|
86
|
+
encoding: 'utf8',
|
|
87
|
+
timeout: 120000,
|
|
88
|
+
},
|
|
89
|
+
);
|
|
90
|
+
const res = { status: spawned.status ?? 1, output: String(spawned.stdout || '') + String(spawned.stderr || '') };
|
|
91
|
+
const after = fs.readFileSync(path.join(proj, '.gitignore'), 'utf8');
|
|
92
|
+
if (after !== initial) {
|
|
93
|
+
throw new Error('访问类故障下用户 .gitignore 被改写(应原样保留):\n' + JSON.stringify({ initial, after }, null, 2));
|
|
94
|
+
}
|
|
95
|
+
if (res.status === 0) throw new Error('读取访问类故障应中止安装(exit 非 0),实际 exit 0\n' + res.output);
|
|
96
|
+
assertOut(res, 'EACCES');
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// 244a: 维护文档机检(docs-governance)——死引用基线:正例(干净夹具通过)/ 反例(死引用必须
|
|
101
|
+
// 报告且含来源与目标)/ 覆盖面(.specs/adr + allowlist 未来路径)/ 恢复(修复后通过)。
|
|
102
|
+
{
|
|
103
|
+
name: '244a 维护文档机检:死引用正反例 + adr 面 + allowlist + 恢复',
|
|
104
|
+
run: (dir) => {
|
|
105
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
106
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md` 与 `docs/internal/missing-file.md`。\n');
|
|
107
|
+
const problems = internalDocsProblems(dir);
|
|
108
|
+
if (!problems.some((p) => p.includes('FIXTURE.md:1') && p.includes('missing-file.md'))) {
|
|
109
|
+
throw new Error('死引用未被报告(或未带行号): ' + JSON.stringify(problems));
|
|
110
|
+
}
|
|
111
|
+
if (!problems.some((p) => p.includes('死引用')) || problems.length !== 1) {
|
|
112
|
+
throw new Error('死引用判定应恰好 1 条(合法引用不得误报): ' + JSON.stringify(problems));
|
|
113
|
+
}
|
|
114
|
+
// 覆盖:.specs/adr 目标面 + allowlist 分支(未来路径不得被报)
|
|
115
|
+
writeFile(dir, '.specs/adr/ADR-FIXTURE.md', '见 `docs/internal/missing-adr-target.md` 与 `.specs/archive/CONTEXT-history.md`。\n');
|
|
116
|
+
const adrProblems = internalDocsProblems(dir);
|
|
117
|
+
if (!adrProblems.some((p) => p.includes('ADR-FIXTURE.md') && p.includes('missing-adr-target.md'))) {
|
|
118
|
+
throw new Error('adr 面死引用未被报告: ' + JSON.stringify(adrProblems));
|
|
119
|
+
}
|
|
120
|
+
if (adrProblems.some((p) => p.includes('CONTEXT-history.md'))) {
|
|
121
|
+
throw new Error('allowlist 未来路径被误报: ' + JSON.stringify(adrProblems));
|
|
122
|
+
}
|
|
123
|
+
fs.rmSync(path.join(dir, '.specs', 'adr', 'ADR-FIXTURE.md'));
|
|
124
|
+
// 恢复:修好引用 → 通过
|
|
125
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
126
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
127
|
+
throw new Error('修复后应通过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// 244b: 扫描面扩展——三册显式清单(.specs 三册)正/反例;树根相对形态(flow-comet-* 技能目录 /
|
|
133
|
+
// rules)解析正例与同族缺目标反例(窄域规则的判别力证据)。
|
|
134
|
+
{
|
|
135
|
+
name: '244b 维护文档机检:三册扫描面 + 树根相对形态解析',
|
|
136
|
+
run: (dir) => {
|
|
137
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
138
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
139
|
+
// —— 扫描面扩展:三册显式清单(.specs/CONTEXT.md / LESSONS.md / CHANGELOG.md)——
|
|
140
|
+
// 正例:三册在场且互相引用(册间互引)→ 合法引用不得误报
|
|
141
|
+
writeFile(dir, '.specs/CONTEXT.md', '见 `docs/internal/ROADMAP.md` 与 `.specs/LESSONS.md`。\n');
|
|
142
|
+
writeFile(dir, '.specs/LESSONS.md', '见 `.specs/CONTEXT.md`。\n');
|
|
143
|
+
writeFile(dir, '.specs/CHANGELOG.md', '见 `.specs/LESSONS.md`。\n');
|
|
144
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
145
|
+
throw new Error('三册合法引用不得误报: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
146
|
+
}
|
|
147
|
+
// 反例:逐册注入一行死引用——每册都必须被扫到,且报告需带册名与行号
|
|
148
|
+
for (const [book, deadRef] of [
|
|
149
|
+
['.specs/CONTEXT.md', 'docs/internal/missing-context-target.md'],
|
|
150
|
+
['.specs/LESSONS.md', 'docs/internal/missing-lessons-target.md'],
|
|
151
|
+
['.specs/CHANGELOG.md', 'docs/internal/missing-changelog-target.md'],
|
|
152
|
+
]) {
|
|
153
|
+
writeFile(dir, book, '第一行。\n见 `' + deadRef + '`。\n');
|
|
154
|
+
const bookProblems = internalDocsProblems(dir);
|
|
155
|
+
if (!bookProblems.some((p) => p.includes(path.posix.basename(book) + ':2') && p.includes(deadRef))) {
|
|
156
|
+
throw new Error(book + ' 死引用未被报告(三册扫描面缺失): ' + JSON.stringify(bookProblems));
|
|
157
|
+
}
|
|
158
|
+
if (bookProblems.length !== 1) {
|
|
159
|
+
throw new Error(book + ' 死引用判定应恰 1 条: ' + JSON.stringify(bookProblems));
|
|
160
|
+
}
|
|
161
|
+
writeFile(dir, book, '见 `.specs/CONTEXT.md`。\n'); // 修复 → 复绿
|
|
162
|
+
}
|
|
163
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
164
|
+
throw new Error('三册修复后应通过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
165
|
+
}
|
|
166
|
+
// —— 解析基准扩展:树根相对形态(flow-comet-* 技能目录 / rules)——
|
|
167
|
+
// 正例:目标真实存在(技能树根 / 规则树根各一)→ 不报
|
|
168
|
+
writeFile(dir, '.flow-comet/skills/flow-comet-fixture/SKILL.md', '# fixture\n');
|
|
169
|
+
writeFile(dir, '.flow-comet/rules/fixture-rule.md', '# rule\n');
|
|
170
|
+
writeFile(dir, 'docs/internal/FIXTURE.md',
|
|
171
|
+
'见 `flow-comet-fixture/SKILL.md` 与 `rules/fixture-rule.md` 与 `docs/internal/ROADMAP.md`。\n');
|
|
172
|
+
const treePositive = internalDocsProblems(dir);
|
|
173
|
+
if (treePositive.length !== 0) {
|
|
174
|
+
throw new Error('树根相对形态(技能目录 / 规则树)既有目标应解析通过: ' + JSON.stringify(treePositive));
|
|
175
|
+
}
|
|
176
|
+
// 反例(窄域规则判别力):同族形态但目标不存在,且顶层目录在仓库根不存在——
|
|
177
|
+
// 旧判定会以「顶层整体缺席 → 跳过」静默放行,窄域规则必须按死引用报告
|
|
178
|
+
writeFile(dir, 'docs/internal/FIXTURE.md',
|
|
179
|
+
'见 `flow-comet-missing-fixture/SKILL.md` 与 `rules/missing-rule.md` 与 `docs/internal/ROADMAP.md`。\n');
|
|
180
|
+
const treeNegative = internalDocsProblems(dir);
|
|
181
|
+
for (const deadRef of ['flow-comet-missing-fixture/SKILL.md', 'rules/missing-rule.md']) {
|
|
182
|
+
if (!treeNegative.some((p) => p.includes('FIXTURE.md:1') && p.includes(deadRef))) {
|
|
183
|
+
throw new Error('同族缺目标(' + deadRef + ')必须按死引用报告(窄域规则): ' + JSON.stringify(treeNegative));
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
|
|
189
|
+
// 244c: 声明式允许面族(外部命名空间 / 退役命名空间 / 决策册角色)+ 行号存在与不越界 +
|
|
190
|
+
// 表头新鲜度 + ROADMAP「Now 段不得引用已归档 change-id」。
|
|
191
|
+
{
|
|
192
|
+
name: '244c 维护文档机检:声明式允许面 + 行号越界 + 表头新鲜度 + Now 段归档 id',
|
|
193
|
+
run: (dir) => {
|
|
194
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
195
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
196
|
+
// —— in-place 增锚(声明式族:外部命名空间 / 退役命名空间 / 示例)——旧语义
|
|
197
|
+
// "顶层段不存在即静默跳过"在此被替换:允许面必须显式登记,未登记者一律按死引用报告
|
|
198
|
+
// (fail-closed;旧逻辑对下列②③两种形态都静默放过——判别力差异即反向构造证据)。
|
|
199
|
+
// ① 外部命名空间族(前缀声明)→ 仍跳过(平台侧命名空间在本仓库根天然不存在)
|
|
200
|
+
writeFile(dir, 'docs/internal/FIXTURE.md',
|
|
201
|
+
'见 `DSH_HOME/skills/x/SKILL.md` 与 `dsh-tui/lib/a.js` 与 `dsh-base/cordis.patch.yml` 与 `docs/internal/ROADMAP.md`。\n');
|
|
202
|
+
const externalProblems = internalDocsProblems(dir);
|
|
203
|
+
if (externalProblems.length !== 0) {
|
|
204
|
+
throw new Error('声明式外部命名空间族不得误报: ' + JSON.stringify(externalProblems));
|
|
205
|
+
}
|
|
206
|
+
// ② 退役命名空间:登记在案(记录迁移的决策件)→ 跳过;未登记文件里的同形态引用 → 必须按死引用报
|
|
207
|
+
writeFile(dir, '.specs/adr/ADR-009-runtime-namespace.md', '见 `.comet/config.yaml` 与 `.comet/flow-comet-state.json`。\n');
|
|
208
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `.comet/config.yaml` 与 `docs/internal/ROADMAP.md`。\n');
|
|
209
|
+
const retiredProblems = internalDocsProblems(dir);
|
|
210
|
+
if (!retiredProblems.some((p) => p.includes('FIXTURE.md:1') && p.includes('.comet/config.yaml'))) {
|
|
211
|
+
throw new Error('未登记的退役命名空间引用必须按死引用报告: ' + JSON.stringify(retiredProblems));
|
|
212
|
+
}
|
|
213
|
+
if (retiredProblems.some((p) => p.includes('ADR-009-runtime-namespace.md'))) {
|
|
214
|
+
throw new Error('登记在案的迁移记录件不得误报: ' + JSON.stringify(retiredProblems));
|
|
215
|
+
}
|
|
216
|
+
// ②b 允许面按角色 / 前缀匹配(改名不误报):同一决策件 / 同族后续决策件换名后仍须跳过——
|
|
217
|
+
// 精确 ref 硬编码下改名即静默失配 → 合法历史迁移记录被误报死引用(误红会诱导维护者
|
|
218
|
+
// 删掉历史事实)。本锚即"改名后仍正确跳过"的反向构造。
|
|
219
|
+
fs.renameSync(path.join(dir, '.specs', 'adr', 'ADR-009-runtime-namespace.md'),
|
|
220
|
+
path.join(dir, '.specs', 'adr', 'ADR-009-runtime-namespace-renamed.md'));
|
|
221
|
+
writeFile(dir, '.specs/adr/ADR-010-namespace-followup.md', '见 `.comet/config.yaml`。\n');
|
|
222
|
+
const renamedProblems = internalDocsProblems(dir);
|
|
223
|
+
for (const renamed of ['ADR-009-runtime-namespace-renamed.md', 'ADR-010-namespace-followup.md']) {
|
|
224
|
+
if (renamedProblems.some((p) => p.includes(renamed))) {
|
|
225
|
+
throw new Error('决策件改名后不得误报死引用(按前缀匹配退役命名空间允许面): ' + renamed
|
|
226
|
+
+ ' → ' + JSON.stringify(renamedProblems));
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
// ②c 决策册角色匹配(角色面正 / 反例;角色判定直接锚 + 引用面不得被角色面放宽)
|
|
230
|
+
if (!isDeclaredReferenceSkip('.specs/CONTEXT.md', '.comet/config.yaml')
|
|
231
|
+
|| !isDeclaredReferenceSkip('.specs/CONTEXT-decisions.md', '.comet/flow-comet-state.json')) {
|
|
232
|
+
throw new Error('决策册角色(含改名形态)必须按角色命中退役命名空间允许面');
|
|
233
|
+
}
|
|
234
|
+
if (isDeclaredReferenceSkip('.specs/CONTEXT-decisions.md', 'docs/internal/missing-target.md')
|
|
235
|
+
|| isDeclaredReferenceSkip('.specs/OTHER.md', '.comet/config.yaml')) {
|
|
236
|
+
throw new Error('允许面不得面化:引用面(退役命名空间前缀)与文件面(角色 / 前缀)须同时命中');
|
|
237
|
+
}
|
|
238
|
+
// 反例(fail-closed 仍成立):非登记角色的同形态引用 → 必须照报(允许面不得变成宽面)
|
|
239
|
+
writeFile(dir, '.specs/adr/ADR-008-unrelated.md', '见 `.comet/config.yaml`。\n');
|
|
240
|
+
const unrelatedProblems = internalDocsProblems(dir);
|
|
241
|
+
if (!unrelatedProblems.some((p) => p.includes('ADR-008-unrelated.md') && p.includes('.comet/config.yaml'))) {
|
|
242
|
+
throw new Error('非登记角色的退役命名空间引用必须照报: ' + JSON.stringify(unrelatedProblems));
|
|
243
|
+
}
|
|
244
|
+
fs.rmSync(path.join(dir, '.specs', 'adr', 'ADR-009-runtime-namespace-renamed.md'));
|
|
245
|
+
fs.rmSync(path.join(dir, '.specs', 'adr', 'ADR-010-namespace-followup.md'));
|
|
246
|
+
fs.rmSync(path.join(dir, '.specs', 'adr', 'ADR-008-unrelated.md'));
|
|
247
|
+
// 夹具移除后本组不再产生任何报告(判别力反向确认:上面三类断言确由这些夹具驱动,
|
|
248
|
+
// 不是被其它夹具的既有报告蒙对)。此处只对本组文件断言——docs/internal/FIXTURE.md
|
|
249
|
+
// 仍带着上一段夹具的未登记引用(其报告由上一段断言负责)。
|
|
250
|
+
const afterAllowlistCleanup = internalDocsProblems(dir);
|
|
251
|
+
for (const removed of ['ADR-009-runtime-namespace-renamed.md', 'ADR-010-namespace-followup.md', 'ADR-008-unrelated.md']) {
|
|
252
|
+
if (afterAllowlistCleanup.some((p) => p.includes(removed))) {
|
|
253
|
+
throw new Error('允许面夹具移除后不得再报该文件: ' + removed + ' → ' + JSON.stringify(afterAllowlistCleanup));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
// ③ 已移除临时区(未登记形态)→ 必须报(真实残留曾因旧跳过语义长期不可见)
|
|
257
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `.verify-tools/level3-smoke.mjs` 与 `docs/internal/ROADMAP.md`。\n');
|
|
258
|
+
const residueProblems = internalDocsProblems(dir);
|
|
259
|
+
if (!residueProblems.some((p) => p.includes('FIXTURE.md:1') && p.includes('.verify-tools/level3-smoke.mjs'))) {
|
|
260
|
+
throw new Error('未登记的临时区引用必须按死引用报告: ' + JSON.stringify(residueProblems));
|
|
261
|
+
}
|
|
262
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
263
|
+
// —— 行号存在与不越界(结构级):引用解析成功后才校验行号 ——
|
|
264
|
+
writeFile(dir, 'docs/internal/TARGET.md', '第一行\n第二行\n第三行\n');
|
|
265
|
+
writeFile(dir, 'docs/internal/FIXTURE.md',
|
|
266
|
+
'见 `docs/internal/TARGET.md:1` 与 `docs/internal/TARGET.md:1-3` 与 `docs/internal/TARGET.md:2,3`。\n');
|
|
267
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
268
|
+
throw new Error('合法行号引用(单值 / 区间 / 逗号列表)不得误报: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
269
|
+
}
|
|
270
|
+
// 反例:越界(旧实现只判路径存在性,行号部分根本不参与解析 → 必然放过)
|
|
271
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/TARGET.md:99`。\n');
|
|
272
|
+
const lineProblems = internalDocsProblems(dir);
|
|
273
|
+
if (!(lineProblems.some((p) => p.includes('行号越界') && p.includes('FIXTURE.md:1')
|
|
274
|
+
&& p.includes('TARGET.md:99') && p.includes('目标共')))) {
|
|
275
|
+
throw new Error('越界行号未被报告(应含「行号越界」+ 受检文件:行 + 目标:行号 + 目标行数): '
|
|
276
|
+
+ JSON.stringify(lineProblems));
|
|
277
|
+
}
|
|
278
|
+
// 反例:下界(第 0 行不存在)
|
|
279
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/TARGET.md:0`。\n');
|
|
280
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('行号越界') && p.includes('TARGET.md:0'))) {
|
|
281
|
+
throw new Error('下界越界(引用第 0 行)未被报告: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
282
|
+
}
|
|
283
|
+
// 反例:尾随换行不得让目标文件被算成"多一行"——3 行文件引 `:4` 必须越界
|
|
284
|
+
// (旧实现按 split 段数计行,尾随空段被算作一行 → :4 被放过)
|
|
285
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/TARGET.md:4`。\n');
|
|
286
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('行号越界') && p.includes('TARGET.md:4'))) {
|
|
287
|
+
throw new Error('尾随换行被算成额外一行(3 行目标文件引 :4 未报越界): '
|
|
288
|
+
+ JSON.stringify(internalDocsProblems(dir)));
|
|
289
|
+
}
|
|
290
|
+
// 反例:**空文件 = 0 行**——空目标文件的任何行号都越界(按 split 段数计会得 1 行 → `:1` 被放过)
|
|
291
|
+
writeFile(dir, 'docs/internal/EMPTY.md', '');
|
|
292
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/EMPTY.md:1`。\n');
|
|
293
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('行号越界') && p.includes('EMPTY.md:1'))) {
|
|
294
|
+
throw new Error('空目标文件引 :1 未报越界(空文件应为 0 行): ' + JSON.stringify(internalDocsProblems(dir)));
|
|
295
|
+
}
|
|
296
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'EMPTY.md'));
|
|
297
|
+
// 反例:区间上端越界(区间取两端逐一校验)
|
|
298
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/TARGET.md:2-99`。\n');
|
|
299
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('行号越界') && p.includes('TARGET.md:99'))) {
|
|
300
|
+
throw new Error('区间上端越界未被报告: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
301
|
+
}
|
|
302
|
+
// 反例:逗号列表中的越界项
|
|
303
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/TARGET.md:1,99`。\n');
|
|
304
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('行号越界') && p.includes('TARGET.md:99'))) {
|
|
305
|
+
throw new Error('逗号列表中的越界项未被报告: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
306
|
+
}
|
|
307
|
+
// 并列写法护栏:首段带文件扩展名的 token 不是路径引用(两个文件名并列)→ 不参与解析;
|
|
308
|
+
// 同一行里真实的越界引用照报(证明护栏没有把整行一起吞掉——判据必须收窄到"首段带扩展名")
|
|
309
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `TEST.md/REVIEW.md` 与 `docs/internal/TARGET.md:99`。\n');
|
|
310
|
+
const parallelProblems = internalDocsProblems(dir);
|
|
311
|
+
if (parallelProblems.some((p) => p.includes('TEST.md/REVIEW.md'))) {
|
|
312
|
+
throw new Error('并列写法(首段带扩展名)不得按路径引用解析: ' + JSON.stringify(parallelProblems));
|
|
313
|
+
}
|
|
314
|
+
if (!parallelProblems.some((p) => p.includes('TARGET.md:99'))) {
|
|
315
|
+
throw new Error('并列写法护栏不得吞掉同一行的真实越界引用: ' + JSON.stringify(parallelProblems));
|
|
316
|
+
}
|
|
317
|
+
// 目标本身不存在时只报死引用,不叠报行号越界(同一处只报一次)
|
|
318
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/MISSING-TARGET.md:99`。\n');
|
|
319
|
+
const missingTargetProblems = internalDocsProblems(dir);
|
|
320
|
+
if (!missingTargetProblems.some((p) => p.includes('死引用') && p.includes('MISSING-TARGET.md'))) {
|
|
321
|
+
throw new Error('不存在的目标应报死引用: ' + JSON.stringify(missingTargetProblems));
|
|
322
|
+
}
|
|
323
|
+
if (missingTargetProblems.some((p) => p.includes('行号越界'))) {
|
|
324
|
+
throw new Error('目标不存在时不得叠报行号越界: ' + JSON.stringify(missingTargetProblems));
|
|
325
|
+
}
|
|
326
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'TARGET.md'));
|
|
327
|
+
writeFile(dir, 'docs/internal/FIXTURE.md', '见 `docs/internal/ROADMAP.md`。\n');
|
|
328
|
+
// —— 表头新鲜度(内容锚:表头日期 ≥ 正文最大日期;未声明表头 → 跳过)——
|
|
329
|
+
writeFile(dir, 'docs/internal/HEADER.md', '> 最后更新:2026-01-01\n\n正文提到 2026-02-02 的事。\n');
|
|
330
|
+
const staleHeaderProblems = internalDocsProblems(dir);
|
|
331
|
+
if (!(staleHeaderProblems.some((p) => p.includes('表头不新鲜') && p.includes('HEADER.md')
|
|
332
|
+
&& p.includes('2026-01-01') && p.includes('2026-02-02')))) {
|
|
333
|
+
throw new Error('表头落后于正文最大日期未被报告(应含文件与两侧日期): ' + JSON.stringify(staleHeaderProblems));
|
|
334
|
+
}
|
|
335
|
+
writeFile(dir, 'docs/internal/HEADER.md', '> 最后更新:2026-02-02\n\n正文提到 2026-02-02 的事。\n');
|
|
336
|
+
if (internalDocsProblems(dir).some((p) => p.includes('表头不新鲜'))) {
|
|
337
|
+
throw new Error('表头与正文最大日期相等(新鲜)不得误报: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
338
|
+
}
|
|
339
|
+
writeFile(dir, 'docs/internal/HEADER.md', '正文提到 2026-12-31 的事,但本册没声明表头。\n');
|
|
340
|
+
if (internalDocsProblems(dir).some((p) => p.includes('表头不新鲜'))) {
|
|
341
|
+
throw new Error('未声明表头的目标必须跳过(登记边界): ' + JSON.stringify(internalDocsProblems(dir)));
|
|
342
|
+
}
|
|
343
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'HEADER.md'));
|
|
344
|
+
// —— `## Now` 段不得出现已归档 change-id(旧逻辑无此判据 → 必然放过)——
|
|
345
|
+
writeFile(dir, '.specs/archive/2026-01-01-archived-fixture/CHANGE.md', '# 归档夹具\n');
|
|
346
|
+
writeFile(dir, 'docs/internal/ROADMAP.md',
|
|
347
|
+
'# 路线图\n\n> 最后更新:2026-01-01\n\n## Now\n\n- 在办:archived-fixture 的后续\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
348
|
+
const nowProblems = internalDocsProblems(dir);
|
|
349
|
+
if (!nowProblems.some((p) => p.includes('Now 段含已归档 change-id: archived-fixture'))) {
|
|
350
|
+
throw new Error('在办段引用已归档 change-id 未被报告: ' + JSON.stringify(nowProblems));
|
|
351
|
+
}
|
|
352
|
+
// 正例:同一 id 只出现在 Now 段之外 → 不报(判据只约束在办段,历史段本就该记已归档项)
|
|
353
|
+
writeFile(dir, 'docs/internal/ROADMAP.md',
|
|
354
|
+
'# 路线图\n\n> 最后更新:2026-01-01\n\n## Now\n\n- 在办:别的主题\n\n## Next\n\n## Later\n\n- 历史:archived-fixture\n\n## Open decisions\n');
|
|
355
|
+
if (internalDocsProblems(dir).some((p) => p.includes('Now 段含已归档'))) {
|
|
356
|
+
throw new Error('Now 段之外的归档 id 不得误报: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
357
|
+
}
|
|
358
|
+
// 反例:归档 id 必须**整词**匹配——`archived-fixture-v2` 含 `archived-fixture` 但不得误报
|
|
359
|
+
// (旧实现用 includes 子串匹配 → 短 id 会命中更长 id 或同族更长 id 的中间)
|
|
360
|
+
writeFile(dir, 'docs/internal/ROADMAP.md',
|
|
361
|
+
'# 路线图\n\n> 最后更新:2026-01-01\n\n## Now\n\n- 在办:archived-fixture-v2 的后续\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
362
|
+
if (internalDocsProblems(dir).some((p) => p.includes('Now 段含已归档 change-id'))) {
|
|
363
|
+
throw new Error('归档 id 子串误命中(archived-fixture-v2 不得命中 archived-fixture): '
|
|
364
|
+
+ JSON.stringify(internalDocsProblems(dir)));
|
|
365
|
+
}
|
|
366
|
+
// 定位口径锚:文件头目录说明行里出现被反引号包住的同名标题字样时,段定位必须仍命中真实
|
|
367
|
+
// 在办段(按行首标题扫描,而不是按子串首次出现位置切段——后者会切出极短窗口使判据恒过)
|
|
368
|
+
writeFile(dir, 'docs/internal/ROADMAP.md',
|
|
369
|
+
'# 路线图\n\n> 最后更新:2026-01-01\n\n目录说明:`## Now` 与 `## Next` 两段。\n\n## Now\n\n- 在办:archived-fixture\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
370
|
+
if (!internalDocsProblems(dir).some((p) => p.includes('Now 段含已归档 change-id: archived-fixture'))) {
|
|
371
|
+
throw new Error('目录说明行含标题字样时仍须命中真实在办段(标题扫描口径): ' + JSON.stringify(internalDocsProblems(dir)));
|
|
372
|
+
}
|
|
373
|
+
fs.rmSync(path.join(dir, '.specs', 'archive'), { recursive: true, force: true });
|
|
374
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
375
|
+
},
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
// 244d: ROADMAP 最低结构 + 维护者面缺席可见化描述符(在场 → 无描述符;缺段 → 结构问题必报)。
|
|
379
|
+
{
|
|
380
|
+
name: '244d 维护文档机检:ROADMAP 四段结构 + 缺席描述符',
|
|
381
|
+
run: (dir) => {
|
|
382
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
383
|
+
// 缺席可见化描述符(正例):维护者面全在场 → 无跳过描述符
|
|
384
|
+
if (maintainerFaceSkips(dir).length !== 0) {
|
|
385
|
+
throw new Error('维护者面在场时应无跳过描述符: ' + JSON.stringify(maintainerFaceSkips(dir)));
|
|
386
|
+
}
|
|
387
|
+
// 越界:删段 → 结构问题必须报告
|
|
388
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n## Next\n## Later\n');
|
|
389
|
+
const structProblems = internalDocsProblems(dir);
|
|
390
|
+
if (!structProblems.some((p) => p.includes('Open decisions'))) {
|
|
391
|
+
throw new Error('ROADMAP 缺段未被报告: ' + JSON.stringify(structProblems));
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
// 244e: 读取失败可见化(「未执行 ≠ 通过」)——目标扫描侧与 ROADMAP 结构检查侧都必须把不可读
|
|
397
|
+
// 目标报成问题条目(含「无法读取: <rel>: <err 摘要>」),不得静默跳过、也不得抛出崩溃。
|
|
398
|
+
{
|
|
399
|
+
name: '244e 维护文档机检:不可读目标可见化(扫描侧 + ROADMAP 结构侧)',
|
|
400
|
+
run: (dir) => {
|
|
401
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
402
|
+
// —— in-place 增锚(F4:读取失败可见化)——以同名目录替换 .md 文件 → readFileSync
|
|
403
|
+
// 抛 EISDIR(目录读取错误,跨平台同码);旧实现 catch → continue 静默跳过,该目标既无
|
|
404
|
+
// FAIL 也无 SKIP(「未执行 ≠ 通过」的静默通道)→ 必须报告
|
|
405
|
+
// 「无法读取: <rel>: <err 摘要>」。前置:ROADMAP 复原为完整结构,确保本锚的失败只可能
|
|
406
|
+
// 来自不可读目标(无结构噪声)。
|
|
407
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
408
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
409
|
+
throw new Error('不可读目标锚前置:干净夹具应通过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
410
|
+
}
|
|
411
|
+
fs.mkdirSync(path.join(dir, 'docs/internal', 'UNREADABLE.md'), { recursive: true });
|
|
412
|
+
const unreadableProblems = internalDocsProblems(dir);
|
|
413
|
+
if (!unreadableProblems.some((p) => p.includes('无法读取: docs/internal/UNREADABLE.md'))) {
|
|
414
|
+
throw new Error('不可读目标被静默跳过(应报告「无法读取: <rel>: <err 摘要>」): ' + JSON.stringify(unreadableProblems));
|
|
415
|
+
}
|
|
416
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'UNREADABLE.md'), { recursive: true, force: true });
|
|
417
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
418
|
+
throw new Error('移除不可读目标后应复绿: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
419
|
+
}
|
|
420
|
+
// —— 本批 in-place 增锚(F4 语义的结构检查侧补齐)——:目标扫描的读取失败已可见化,但
|
|
421
|
+
// ROADMAP 结构检查此前仍对同一路径直接 readFileSync——ROADMAP 自身不可读(同名目录 →
|
|
422
|
+
// EISDIR / 访问类错误)时未捕获异常会把整个套件打成堆栈崩溃,而不是给出可见问题条目。
|
|
423
|
+
// 夹具把 ROADMAP.md 换成同名目录(其余受检面保持合法,失败只可能来自该目标)→ 断言
|
|
424
|
+
// 返回问题数组且含「无法读取: docs/internal/ROADMAP.md」(不是抛出),且不得以「结构缺段」
|
|
425
|
+
// 噪声替代读取失败可见化(读取失败即跳过四段结构检查);移除目录、写回合法 ROADMAP → 复绿。
|
|
426
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'ROADMAP.md'), { force: true });
|
|
427
|
+
fs.mkdirSync(path.join(dir, 'docs/internal', 'ROADMAP.md'), { recursive: true });
|
|
428
|
+
const unreadableRoadmap = internalDocsProblems(dir);
|
|
429
|
+
if (!Array.isArray(unreadableRoadmap)) {
|
|
430
|
+
throw new Error('ROADMAP 不可读时应返回问题数组(不得抛出): ' + String(unreadableRoadmap));
|
|
431
|
+
}
|
|
432
|
+
if (!unreadableRoadmap.some((p) => p.includes('无法读取: docs/internal/ROADMAP.md'))) {
|
|
433
|
+
throw new Error('ROADMAP 自身不可读未被报告(应含「无法读取: docs/internal/ROADMAP.md」): ' + JSON.stringify(unreadableRoadmap));
|
|
434
|
+
}
|
|
435
|
+
if (unreadableRoadmap.some((p) => p.includes('ROADMAP 结构缺段'))) {
|
|
436
|
+
throw new Error('ROADMAP 读取失败时不得继续四段结构检查: ' + JSON.stringify(unreadableRoadmap));
|
|
437
|
+
}
|
|
438
|
+
fs.rmSync(path.join(dir, 'docs/internal', 'ROADMAP.md'), { recursive: true, force: true });
|
|
439
|
+
writeFile(dir, 'docs/internal/ROADMAP.md', '# 路线图\n\n## Now\n\n## Next\n\n## Later\n\n## Open decisions\n');
|
|
440
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
441
|
+
throw new Error('ROADMAP 写回合法结构后应复绿: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
442
|
+
}
|
|
443
|
+
// 整组缺席(CI / worktree 形态)→ 跳过,不误红:目标面 = docs/internal 与 .specs/adr 与
|
|
444
|
+
// 三册——组缺席判据是「全部目标面缺席」(targets.length === 0),故夹具同步移除三册。
|
|
445
|
+
fs.rmSync(path.join(dir, 'docs/internal'), { recursive: true, force: true });
|
|
446
|
+
fs.rmSync(path.join(dir, '.specs'), { recursive: true, force: true });
|
|
447
|
+
if (internalDocsProblems(dir).length !== 0) {
|
|
448
|
+
throw new Error('目标面整组缺席时应跳过: ' + JSON.stringify(internalDocsProblems(dir)));
|
|
449
|
+
}
|
|
450
|
+
// 缺席可见化描述符(反例):维护者面整体缺席 → 逐面给出「面名 + 原因」,
|
|
451
|
+
// 供套件底部输出可见 SKIP 行;本节同时锁住「判定语义零变化」(上面跳过断言)。
|
|
452
|
+
const skips = maintainerFaceSkips(dir);
|
|
453
|
+
if (skips.length !== 2) {
|
|
454
|
+
throw new Error('维护者面缺席应给出 2 条跳过描述符,实际 ' + JSON.stringify(skips));
|
|
455
|
+
}
|
|
456
|
+
for (const skip of skips) {
|
|
457
|
+
if (typeof skip.face !== 'string' || skip.face.trim() === ''
|
|
458
|
+
|| typeof skip.reason !== 'string' || skip.reason.trim() === '') {
|
|
459
|
+
throw new Error('跳过描述符须含面名与原因: ' + JSON.stringify(skip));
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (!skips.some((s) => s.face.includes('计数') && s.reason.includes('docs/internal'))) {
|
|
463
|
+
throw new Error('计数面跳过描述符应说明 docs/internal 缺席: ' + JSON.stringify(skips));
|
|
464
|
+
}
|
|
465
|
+
if (!skips.some((s) => s.face.includes('机检') && s.reason.includes('目标面'))) {
|
|
466
|
+
throw new Error('维护文档机检面跳过描述符应说明目标面缺席: ' + JSON.stringify(skips));
|
|
467
|
+
}
|
|
468
|
+
// —— 本批 in-place 增锚(公开产物零代号判据 + 词表镜像漂移判据)——
|
|
469
|
+
// 与 .githooks 词表单一来源同判据(该文件主仓私有、不随技能包分发;本文件内保留同义镜像,
|
|
470
|
+
// 两处同改)。① 表驱动等价性:词表**每个分支**各一条正例(分支被删 / 被收窄过头 → 该行
|
|
471
|
+
// 先红)与一条对应反例(分支被放宽成裸词 / 宽前缀 → 该行先红)——反例按"放宽后会被误
|
|
472
|
+
// 命中的合法或无关形态"选取,故"某分支被动过"必然落在某个(正例,反例)对上;
|
|
473
|
+
// ② 本文件注释层零残留(清理后不许回潮);③ 词表镜像漂移判据夹具锚(同源 → 绿 /
|
|
474
|
+
// 改一字符 → 红且消息含两侧片段与长度 / 私有面缺席 → 显式"无法执行"而非静默放过)。
|
|
475
|
+
// 注意:形态字面量只能写在非注释行——本锚的②正是扫注释层。
|
|
476
|
+
const CODE_BRANCH_SAMPLES = [
|
|
477
|
+
['场景编号', 'S12', 'S1234'],
|
|
478
|
+
['修复族 id', 'T-FIX-01', 'FIX-01'],
|
|
479
|
+
['批次连字符前缀', 'batch-2', 'batch-name'],
|
|
480
|
+
['缺陷编号', 'D-12', 'D-abc'],
|
|
481
|
+
['优先级编号', 'P3', 'P9'],
|
|
482
|
+
['验证轮次', 'round 3', 'round-table'],
|
|
483
|
+
['英文本地实践词', 'dogfood', 'dog food'],
|
|
484
|
+
['内部标识词', '内部', '内卷'],
|
|
485
|
+
['批次加编号', '批次 D', '批次发布'],
|
|
486
|
+
['批加编号', '批 2', '第一批 2 次'],
|
|
487
|
+
['批加编号(序数与批之间有空格)', '批 2', '第 1 批 2 次'],
|
|
488
|
+
['级加编号', '级 3', '级联'],
|
|
489
|
+
['验收代号', 'UAT-7', 'UAT-x'],
|
|
490
|
+
['工作项编号', 'R-14', 'ADR-013'],
|
|
491
|
+
['工作项编号(三位不截断)', 'R-14', 'R-123'],
|
|
492
|
+
];
|
|
493
|
+
for (const [label, hit, miss] of CODE_BRANCH_SAMPLES) {
|
|
494
|
+
if (!PUBLIC_CODE_RE.test(hit)) {
|
|
495
|
+
throw new Error('词表分支缺失或被收窄过头(正例不再命中): ' + label + ' → ' + JSON.stringify(hit));
|
|
496
|
+
}
|
|
497
|
+
if (PUBLIC_CODE_RE.test(miss)) {
|
|
498
|
+
throw new Error('词表分支被放宽(反例被误命中): ' + label + ' → ' + JSON.stringify(miss));
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
for (const legit of ['PR-130', '维护批次', '批处理', 'Fix 批次']) {
|
|
502
|
+
if (PUBLIC_CODE_RE.test(legit)) {
|
|
503
|
+
throw new Error('合法相似子串被零代号判据误报: ' + legit);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
// ③ 词表镜像漂移判据(夹具驱动;不依赖真实私有面在场——权威源与安装副本两形态都可跑)
|
|
507
|
+
const mirrorFixtureRel = path.posix.join('.githooks', 'internal-codes.mjs');
|
|
508
|
+
const mirrorText = 'export const BANNED = /' + PUBLIC_CODE_RE.source + '/;\n';
|
|
509
|
+
writeFile(dir, mirrorFixtureRel, mirrorText);
|
|
510
|
+
const mirrorOk = vocabularyMirrorProblems(dir);
|
|
511
|
+
if (mirrorOk.length !== 0) {
|
|
512
|
+
throw new Error('同源词表镜像不得报漂移: ' + JSON.stringify(mirrorOk));
|
|
513
|
+
}
|
|
514
|
+
// 逐字符比对必有判别力:镜像侧改动一个字符(这里放宽一条分支)→ 必报,且消息可定位
|
|
515
|
+
const driftedSource = PUBLIC_CODE_RE.source.replace('dogfood', 'dogfoods');
|
|
516
|
+
if (driftedSource === PUBLIC_CODE_RE.source) {
|
|
517
|
+
throw new Error('夹具前提失效:漂移注入未改变镜像 source(词表分支名已变)');
|
|
518
|
+
}
|
|
519
|
+
writeFile(dir, mirrorFixtureRel, 'export const BANNED = /' + driftedSource + '/;\n');
|
|
520
|
+
const driftProblems = vocabularyMirrorProblems(dir);
|
|
521
|
+
if (!driftProblems.some((p) => p.includes('词表镜像漂移') && p.includes('主仓侧片段')
|
|
522
|
+
&& p.includes('套件侧片段') && p.includes('首个差异位置')
|
|
523
|
+
&& p.includes(String(driftedSource.length)) && p.includes(String(PUBLIC_CODE_RE.source.length)))) {
|
|
524
|
+
throw new Error('镜像侧改动一个字符必须报漂移且消息含两侧片段与长度: ' + JSON.stringify(driftProblems));
|
|
525
|
+
}
|
|
526
|
+
writeFile(dir, mirrorFixtureRel, mirrorText);
|
|
527
|
+
if (vocabularyMirrorProblems(dir).length !== 0) {
|
|
528
|
+
throw new Error('镜像还原后应复绿: ' + JSON.stringify(vocabularyMirrorProblems(dir)));
|
|
529
|
+
}
|
|
530
|
+
// 私有面结构性缺席(安装副本形态)→ 显式"判据无法执行",不得静默返回空
|
|
531
|
+
fs.rmSync(path.join(dir, '.githooks'), { recursive: true, force: true });
|
|
532
|
+
const mirrorMissing = vocabularyMirrorProblems(dir);
|
|
533
|
+
if (!mirrorMissing.some((p) => p.includes('无法执行') && p.includes(mirrorFixtureRel))) {
|
|
534
|
+
throw new Error('私有面缺席必须显式报告判据未执行(未验证 ≠ 通过): ' + JSON.stringify(mirrorMissing));
|
|
535
|
+
}
|
|
536
|
+
// ② 分发面源码的**注释层零残留**(清理后不许回潮):受检面 = 技能树内全部脚本(入口 + `lib/**`
|
|
537
|
+
// + `scenarios/**` + `items/**`,递归派生)——拆分后注释量最大的新模块全在面内;旧形态只扫
|
|
538
|
+
// 入口单文件(19,023 行 → 211 行)会让判据仍在、判别力消失(拆分的隐蔽缺陷形态)。
|
|
539
|
+
// 注释行判定与词表判据同口径(行首 `//` / `*` / `/*`);真实判据与反向构造探针共用
|
|
540
|
+
// `commentCodeProblems`(单一实现,探针不与锚漂移)。
|
|
541
|
+
const selfFace = scriptTreeFiles();
|
|
542
|
+
const faceTexts = new Map(selfFace.map((rel) => [rel, fs.readFileSync(path.join(SCRIPTS_DIR, rel), 'utf8')]));
|
|
543
|
+
const commentFound = commentCodeProblems(faceTexts);
|
|
544
|
+
if (commentFound.length !== 0) {
|
|
545
|
+
throw new Error('分发面源码注释层仍有未公开概念字样(判据锚:注释层零残留): ' + commentFound.join(', '));
|
|
546
|
+
}
|
|
547
|
+
// ②b 面有效性(防「面收缩成空集」的恒真空过):受检面必须覆盖到 `lib/` 与 `scenarios/`。
|
|
548
|
+
if (!selfFace.some((rel) => rel.startsWith('lib/')) || !selfFace.some((rel) => rel.startsWith('scenarios/'))) {
|
|
549
|
+
throw new Error('注释层受检面未覆盖 lib/ 与 scenarios/(受检面收缩,判据退化为恒真): '
|
|
550
|
+
+ JSON.stringify(selfFace.slice(0, 8)));
|
|
551
|
+
}
|
|
552
|
+
// ②c 反向构造(判别力数据驱动):在**面内**任取一个 `lib/` 文件注入一处过程代号**注释行** ⇒
|
|
553
|
+
// 必红;还原 ⇒ 复绿。样例经拼接构造(本判据自身就写在面内文件里,字面量直写会自伤)。
|
|
554
|
+
const probeRel = selfFace.find((rel) => rel.startsWith('lib/'));
|
|
555
|
+
if (probeRel === undefined) throw new Error('反向构造前提不成立:面内无 lib/ 文件');
|
|
556
|
+
const probeSample = 'S' + '99 场景编号(反向构造)';
|
|
557
|
+
const injectedInFace = new Map(faceTexts).set(probeRel, faceTexts.get(probeRel) + '\n// ' + probeSample + '\n');
|
|
558
|
+
if (!commentCodeProblems(injectedInFace).some((problem) => problem.startsWith(probeRel + ':'))) {
|
|
559
|
+
throw new Error('反向构造判别力缺失(面内注入过程代号注释未被判违规)');
|
|
560
|
+
}
|
|
561
|
+
if (commentCodeProblems(faceTexts).length !== 0) {
|
|
562
|
+
throw new Error('反向构造还原后未复绿(判据受输入顺序影响)');
|
|
563
|
+
}
|
|
564
|
+
// ②d 面边界为真:受检面 = 技能树内**脚本**(`.mjs`)全集——同树的文档 / `reference/` 不参与
|
|
565
|
+
// (受检面由脚本目录树派生,非脚本文件结构性地不在其中)。
|
|
566
|
+
const nonScript = selfFace.filter((rel) => !rel.endsWith('.mjs'));
|
|
567
|
+
if (nonScript.length !== 0) {
|
|
568
|
+
throw new Error('注释层受检面混入非脚本文件(面边界失效): ' + JSON.stringify(nonScript.slice(0, 5)));
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
},
|
|
572
|
+
|
|
573
|
+
// 245: Fix 回退态共享判定(共享判定 / AC-1 基础谓词)——正例:review / verify 驻留 + TASK 存在
|
|
574
|
+
// pending 任务 + resolveNextNode(completedNodes) === execute;反例三类:非源节点驻留 /
|
|
575
|
+
// 无 pending 任务(路由仍回 execute,证明 pending 是独立条件)/ 路由不回 execute(前置产物缺失)。
|
|
576
|
+
{
|
|
577
|
+
name: '245 resolveFixRollbackState:源节点 + pending 串/并行 → 目标节点(路由/完成态反例)',
|
|
578
|
+
run: async (dir) => {
|
|
579
|
+
const isRollback = requireRouteNodeExport('resolveFixRollbackState');
|
|
580
|
+
const protocol = readScenarioProtocol(dir);
|
|
581
|
+
const completedNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
582
|
+
const pendingTasks = '# TASK\n\n' + fixTaskBlock('T01', 'pending') + '\n';
|
|
583
|
+
writeIntakeArtifacts(dir);
|
|
584
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', pendingTasks);
|
|
585
|
+
const baseArgs = { runRoot: dir, changeName: CHANGE_ID, protocol, completedNodes };
|
|
586
|
+
// 夹具前提:该 completedNodes 下共享路由确实推导回 execute(谓词第三条件成立)
|
|
587
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'execute') {
|
|
588
|
+
throw new Error('夹具前提失效:串行 pending 任务在场时 resolveNextNode 应推导 execute');
|
|
589
|
+
}
|
|
590
|
+
const fromReview = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
591
|
+
if (fromReview !== 'execute') {
|
|
592
|
+
throw new Error('review 驻留 + 串行 pending 应归位 execute,实际 ' + JSON.stringify(fromReview));
|
|
593
|
+
}
|
|
594
|
+
const fromVerify = await isRollback({ ...baseArgs, currentNode: 'verify' });
|
|
595
|
+
if (fromVerify !== 'execute') {
|
|
596
|
+
throw new Error('verify 驻留 + 串行 pending 应归位 execute,实际 ' + JSON.stringify(fromVerify));
|
|
597
|
+
}
|
|
598
|
+
// pending 并行(依赖已满足):共享路由推 subagent-execute → 目标节点为 subagent-execute
|
|
599
|
+
// (并行修复任务同样必须归位到 execute 家族,不得因节点 id 差异绕过闭环)。
|
|
600
|
+
const parallelPending = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
601
|
+
+ '<task id="P-FIX-01" parallel="true" status="pending">'
|
|
602
|
+
+ '<action>实现 P-FIX-01</action><write_files>src/p-fix-01.mjs</write_files>'
|
|
603
|
+
+ '<verify>node --check src/p-fix-01.mjs</verify></task>\n';
|
|
604
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', parallelPending);
|
|
605
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'subagent-execute') {
|
|
606
|
+
throw new Error('夹具前提失效:可委托 parallel pending 在场时 resolveNextNode 应推导 subagent-execute');
|
|
607
|
+
}
|
|
608
|
+
const parallelReview = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
609
|
+
if (parallelReview !== 'subagent-execute') {
|
|
610
|
+
throw new Error('review 驻留 + 并行 pending 应归位 subagent-execute,实际 ' + JSON.stringify(parallelReview));
|
|
611
|
+
}
|
|
612
|
+
const parallelVerify = await isRollback({ ...baseArgs, currentNode: 'verify' });
|
|
613
|
+
if (parallelVerify !== 'subagent-execute') {
|
|
614
|
+
throw new Error('verify 驻留 + 并行 pending 应归位 subagent-execute,实际 ' + JSON.stringify(parallelVerify));
|
|
615
|
+
}
|
|
616
|
+
// 反例①:非 review/verify 驻留(pending 与路由条件仍成立)→ null
|
|
617
|
+
const fromExecute = await isRollback({ ...baseArgs, currentNode: 'execute' });
|
|
618
|
+
if (fromExecute !== null) {
|
|
619
|
+
throw new Error('非源节点驻留应为 null,实际 ' + JSON.stringify(fromExecute));
|
|
620
|
+
}
|
|
621
|
+
// 反例②:无 pending(全 done 但缺 SUMMARY 与出口事件)→ 无闭合信号 → null
|
|
622
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
623
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'execute') {
|
|
624
|
+
throw new Error('夹具前提失效:全 done 且缺 SUMMARY 时 resolveNextNode 应仍推导 execute');
|
|
625
|
+
}
|
|
626
|
+
const noPending = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
627
|
+
if (noPending !== null) {
|
|
628
|
+
throw new Error('无 pending 且无出口事件应为 null,实际 ' + JSON.stringify(noPending));
|
|
629
|
+
}
|
|
630
|
+
// 反例③:pending 在场但前置产物缺失 → 路由退回 design(非 execute 家族)→ null
|
|
631
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', pendingTasks);
|
|
632
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID, 'DESIGN.md'));
|
|
633
|
+
if ((await routeNodeModule.resolveNextNode(baseArgs)) !== 'design') {
|
|
634
|
+
throw new Error('夹具前提失效:DESIGN.md 缺失时 resolveNextNode 应推导 design');
|
|
635
|
+
}
|
|
636
|
+
const notExecute = await isRollback({ ...baseArgs, currentNode: 'review' });
|
|
637
|
+
if (notExecute !== null) {
|
|
638
|
+
throw new Error('路由不回 execute 家族时应为 null,实际 ' + JSON.stringify(notExecute));
|
|
639
|
+
}
|
|
640
|
+
// 反例④:history 最新 execute 出口事件属于另一个 change(state.history 跨 change 保留)
|
|
641
|
+
// → 不得当作当前 change 的闭合签名(否则 change A 的修复签名会误拦 change B 的源节点出口)。
|
|
642
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
|
|
643
|
+
'# DESIGN\n\n## 0. 技术栈\n\nNode\n\n## 决策清单\n\n| # | D | R |\n|---|---|---|\n| D1 | x | y |');
|
|
644
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n');
|
|
645
|
+
const crossChange = await isRollback({
|
|
646
|
+
...baseArgs,
|
|
647
|
+
currentNode: 'review',
|
|
648
|
+
history: [{
|
|
649
|
+
event: 'exit-applied', node: 'execute', change: 'other-change',
|
|
650
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: '0'.repeat(64),
|
|
651
|
+
}],
|
|
652
|
+
});
|
|
653
|
+
if (crossChange !== null) {
|
|
654
|
+
throw new Error('其它 change 的出口签名不得判定当前 change 未闭合(应为 null),实际 ' + JSON.stringify(crossChange));
|
|
655
|
+
}
|
|
656
|
+
// done-but-unclosed:任务全 done + execute 家族已在 completedNodes + 最新家族出口签名过时
|
|
657
|
+
// → 返回该出口事件记录的家族节点(execute / subagent-execute 均可作为归位目标)。
|
|
658
|
+
const staleFamilyEvent = (node) => ({
|
|
659
|
+
event: 'exit-applied', node, at: '2026-09-21T00:00:00.000Z',
|
|
660
|
+
taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
661
|
+
});
|
|
662
|
+
const doneFamily = await isRollback({
|
|
663
|
+
...baseArgs, currentNode: 'review', history: [staleFamilyEvent('subagent-execute')],
|
|
664
|
+
});
|
|
665
|
+
if (doneFamily !== 'subagent-execute') {
|
|
666
|
+
throw new Error('全 done + 家族出口签名过时(subagent-execute)应归位 subagent-execute,实际 ' + JSON.stringify(doneFamily));
|
|
667
|
+
}
|
|
668
|
+
const doneExecute = await isRollback({
|
|
669
|
+
...baseArgs, currentNode: 'verify', history: [staleFamilyEvent('execute')],
|
|
670
|
+
});
|
|
671
|
+
if (doneExecute !== 'execute') {
|
|
672
|
+
throw new Error('全 done + 家族出口签名过时(execute)应归位 execute,实际 ' + JSON.stringify(doneExecute));
|
|
673
|
+
}
|
|
674
|
+
// completedNodes 只要求家族中至少一个:execute 缺席、subagent-execute 在场同样成立。
|
|
675
|
+
const doneOtherFamily = await isRollback({
|
|
676
|
+
...baseArgs,
|
|
677
|
+
completedNodes: ['open', 'design', 'plan', 'subagent-execute'],
|
|
678
|
+
currentNode: 'review',
|
|
679
|
+
history: [staleFamilyEvent('subagent-execute')],
|
|
680
|
+
});
|
|
681
|
+
if (doneOtherFamily !== 'subagent-execute') {
|
|
682
|
+
throw new Error('completedNodes 含 subagent-execute(execute 缺席)时应归位 subagent-execute,实际 ' + JSON.stringify(doneOtherFamily));
|
|
683
|
+
}
|
|
684
|
+
// 最新家族出口签名与当前任务集一致 → 本批已闭合 → null(不得反复回退)。
|
|
685
|
+
const currentSignature = await routeNodeModule.taskSetSignature(
|
|
686
|
+
fs.readFileSync(path.join(dir, '.specs', CHANGE_ID, 'TASK.md'), 'utf8'));
|
|
687
|
+
const closed = await isRollback({
|
|
688
|
+
...baseArgs,
|
|
689
|
+
currentNode: 'review',
|
|
690
|
+
history: [{
|
|
691
|
+
event: 'exit-applied', node: 'subagent-execute',
|
|
692
|
+
at: '2026-09-22T00:00:00.000Z', taskSetSignature: currentSignature,
|
|
693
|
+
}],
|
|
694
|
+
});
|
|
695
|
+
if (closed !== null) {
|
|
696
|
+
throw new Error('出口签名与当前任务集一致时应为 null(已闭合),实际 ' + JSON.stringify(closed));
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
// ---------- m-12 轮次计数纯函数锚(唯一写点 applyFixRollbackRound)----------
|
|
700
|
+
// 第 1~3 轮递增并带审计后缀;第 4 轮新 change BLOCK 且不写计数器;用户显式授权后
|
|
701
|
+
// 放行该轮;旧 change 缺字段缺省 0 不 BLOCK;done-but-unclosed 分支不计数。
|
|
702
|
+
const applyRound = requireRouteNodeExport('applyFixRollbackRound');
|
|
703
|
+
const roundState = {
|
|
704
|
+
activeChange: CHANGE_ID,
|
|
705
|
+
currentNode: 'review',
|
|
706
|
+
evidence: { review: { summary: 'pending fix' } },
|
|
707
|
+
newChange: true,
|
|
708
|
+
};
|
|
709
|
+
const pendingDecision = { kind: 'pending', target: 'execute' };
|
|
710
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
711
|
+
const applied = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
712
|
+
if (!applied.counted || applied.blocked || applied.round !== round
|
|
713
|
+
|| applied.auditSuffix !== '(第 ' + round + '/3 轮)') {
|
|
714
|
+
throw new Error('第 ' + round + ' 轮应计数并输出轮次审计后缀,实际 ' + JSON.stringify(applied));
|
|
715
|
+
}
|
|
716
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== round) {
|
|
717
|
+
throw new Error('第 ' + round + ' 轮后计数器应为 ' + round + ',实际 '
|
|
718
|
+
+ JSON.stringify(roundState.fixRoundsByChange));
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
const blocked = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
722
|
+
if (!blocked.blocked || blocked.counted || blocked.round !== 4) {
|
|
723
|
+
throw new Error('新 change 第 4 轮应 BLOCK 且不计数,实际 ' + JSON.stringify(blocked));
|
|
724
|
+
}
|
|
725
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
726
|
+
throw new Error('第 4 轮 BLOCK 不得写计数器(应保持 3),实际 '
|
|
727
|
+
+ JSON.stringify(roundState.fixRoundsByChange));
|
|
728
|
+
}
|
|
729
|
+
if (!String(blocked.blockedMessage).includes('继续修') || !String(blocked.blockedMessage).includes('停止')) {
|
|
730
|
+
throw new Error('第 4 轮 BLOCK 消息应含「继续修/停止」决策指引,实际 ' + JSON.stringify(blocked.blockedMessage));
|
|
731
|
+
}
|
|
732
|
+
// F5 fail-closed:完整授权形态 = round 正整数 + at/source 非空字符串;任一缺失、类型非法、
|
|
733
|
+
// 空串/纯空白一律按未授权处理——第 4 轮继续 BLOCK、不计数、不写 state(state 字节零改写)。
|
|
734
|
+
const invalidOverrides = [
|
|
735
|
+
['仅 round(缺 at/source)', { round: 4 }],
|
|
736
|
+
['缺 at', { round: 4, source: 'fixture-user' }],
|
|
737
|
+
['缺 source', { round: 4, at: '2026-09-25T00:00:00.000Z' }],
|
|
738
|
+
['round 为字符串', { round: '4', at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
739
|
+
['round 为零', { round: 0, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
740
|
+
['round 为负数', { round: -1, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
741
|
+
['round 为小数', { round: 4.5, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' }],
|
|
742
|
+
['at 类型非法(数字)', { round: 4, at: 123, source: 'fixture-user' }],
|
|
743
|
+
['source 类型非法(数组)', { round: 4, at: '2026-09-25T00:00:00.000Z', source: ['fixture-user'] }],
|
|
744
|
+
['at 空串', { round: 4, at: '', source: 'fixture-user' }],
|
|
745
|
+
['source 空串', { round: 4, at: '2026-09-25T00:00:00.000Z', source: '' }],
|
|
746
|
+
['at 纯空白', { round: 4, at: ' ', source: 'fixture-user' }],
|
|
747
|
+
['source 纯空白', { round: 4, at: '2026-09-25T00:00:00.000Z', source: '\t' }],
|
|
748
|
+
['override 为 null', null],
|
|
749
|
+
];
|
|
750
|
+
for (const [label, badOverride] of invalidOverrides) {
|
|
751
|
+
roundState.evidence.review.fixRoundOverride = badOverride;
|
|
752
|
+
const badResult = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
753
|
+
if (!badResult.blocked || badResult.counted || badResult.overrideUsed || badResult.round !== 4
|
|
754
|
+
|| roundState.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
755
|
+
throw new Error('F5 非法授权形态必须按未授权 fail-closed BLOCK 且零改写(' + label + '),实际 '
|
|
756
|
+
+ JSON.stringify({ badResult, rounds: roundState.fixRoundsByChange }));
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
// 合法三元组(嵌套 evidence)→ 放行被 BLOCK 的那一轮并留审计
|
|
760
|
+
roundState.evidence.review.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
761
|
+
const override = applyRound({ state: roundState, sourceNode: 'review', decision: pendingDecision });
|
|
762
|
+
if (!override.counted || !override.overrideUsed || override.blocked || override.round !== 4) {
|
|
763
|
+
throw new Error('用户显式授权后第 4 轮应放行并标记 overrideUsed,实际 ' + JSON.stringify(override));
|
|
764
|
+
}
|
|
765
|
+
if (roundState.fixRoundsByChange?.[CHANGE_ID] !== 4) {
|
|
766
|
+
throw new Error('授权放行后计数器应为 4,实际 ' + JSON.stringify(roundState.fixRoundsByChange));
|
|
767
|
+
}
|
|
768
|
+
// 旧 change 缺轮次字段 → 缺省 0、不因计数 BLOCK
|
|
769
|
+
const legacyRoundState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: false };
|
|
770
|
+
const legacyRound = applyRound({ state: legacyRoundState, sourceNode: 'review', decision: pendingDecision });
|
|
771
|
+
if (!legacyRound.counted || legacyRound.blocked || legacyRound.round !== 1) {
|
|
772
|
+
throw new Error('旧 change 缺省 0 应可从第 1 轮计数,实际 ' + JSON.stringify(legacyRound));
|
|
773
|
+
}
|
|
774
|
+
if (legacyRoundState.fixRoundsByChange?.[CHANGE_ID] !== 1) {
|
|
775
|
+
throw new Error('旧 change 第 1 轮应写入缺省容器,实际 ' + JSON.stringify(legacyRoundState.fixRoundsByChange));
|
|
776
|
+
}
|
|
777
|
+
// 分支② done-but-unclosed 不计数(计数语义 = 一次受控归位)
|
|
778
|
+
const unclosedState = { activeChange: CHANGE_ID, currentNode: 'review', evidence: {}, newChange: true };
|
|
779
|
+
const unclosedRound = applyRound({ state: unclosedState, sourceNode: 'review', decision: { kind: 'unclosed', target: 'execute' } });
|
|
780
|
+
if (unclosedRound.counted || unclosedRound.round !== null || unclosedState.fixRoundsByChange) {
|
|
781
|
+
throw new Error('done-but-unclosed 分支不得计数/建容器,实际 '
|
|
782
|
+
+ JSON.stringify({ unclosedRound, rounds: unclosedState.fixRoundsByChange }));
|
|
783
|
+
}
|
|
784
|
+
},
|
|
785
|
+
},
|
|
786
|
+
|
|
787
|
+
// 246: execute 后第一个未完成节点推导(共享推导基础)——按协议 route 顺序跳过全部
|
|
788
|
+
// execute 家族节点(execute / subagent-execute 均不参与后置推导),返回其后首个未完成
|
|
789
|
+
// 节点:review → verify → archive;协议无 execute 家族 → null(调用方再用 review/verify 收窄)。
|
|
790
|
+
{
|
|
791
|
+
name: '246 firstIncompletePostExecNode:execute 家族后首个未完成节点(review→verify→archive;无 execute 家族→null)',
|
|
792
|
+
run: (dir) => {
|
|
793
|
+
const firstIncomplete = requireRouteNodeExport('firstIncompletePostExecNode');
|
|
794
|
+
const protocol = readScenarioProtocol(dir);
|
|
795
|
+
const pre = ['open', 'design', 'plan'];
|
|
796
|
+
// subagent-execute(execute 家族)未完成不作为后置节点,首个后置节点应为 review
|
|
797
|
+
const review = firstIncomplete({ protocol, completedNodes: [...pre, 'execute'] });
|
|
798
|
+
if (review !== 'review') {
|
|
799
|
+
throw new Error('execute 已完成、subagent-execute 未完成时应为 review,实际 ' + JSON.stringify(review));
|
|
800
|
+
}
|
|
801
|
+
const verify = firstIncomplete({ protocol, completedNodes: [...pre, 'execute', 'subagent-execute', 'review'] });
|
|
802
|
+
if (verify !== 'verify') {
|
|
803
|
+
throw new Error('review 已完成时应为 verify,实际 ' + JSON.stringify(verify));
|
|
804
|
+
}
|
|
805
|
+
const archive = firstIncomplete({ protocol, completedNodes: [...pre, 'execute', 'subagent-execute', 'review', 'verify'] });
|
|
806
|
+
if (archive !== 'archive') {
|
|
807
|
+
throw new Error('review/verify 均已完成时应为 archive,实际 ' + JSON.stringify(archive));
|
|
808
|
+
}
|
|
809
|
+
const noExecuteFamily = firstIncomplete({ protocol: { nodes: [{ id: 'alpha' }, { id: 'beta' }] }, completedNodes: [] });
|
|
810
|
+
if (noExecuteFamily !== null) {
|
|
811
|
+
throw new Error('协议无 execute 家族时应为 null,实际 ' + JSON.stringify(noExecuteFamily));
|
|
812
|
+
}
|
|
813
|
+
},
|
|
814
|
+
},
|
|
815
|
+
|
|
816
|
+
// 247: Fix 回程节点推导(共享推导基础)——TASK 全 done → 取 execute 后首个未完成节点,
|
|
817
|
+
// 仅 review/verify 可作回程源(archive / 完成态 → null);仍有 pending / TASK 缺失 /
|
|
818
|
+
// 零任务块一律 null(fail-closed,不许用半解析结果回程)。
|
|
819
|
+
{
|
|
820
|
+
name: '247 resolveFixReturnNode:全 done 且源节点未完成 → 源节点;否则 null(pending/缺失/零任务块)+ classifyFixReturnCause 基础锚',
|
|
821
|
+
run: async (dir) => {
|
|
822
|
+
const fixReturn = requireRouteNodeExport('resolveFixReturnNode');
|
|
823
|
+
const protocol = readScenarioProtocol(dir);
|
|
824
|
+
const completedNodes = ['open', 'design', 'plan', 'execute'];
|
|
825
|
+
writeIntakeArtifacts(dir);
|
|
826
|
+
const taskPath = path.join(dir, '.specs', CHANGE_ID, 'TASK.md');
|
|
827
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
828
|
+
'# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T02', 'done') + '\n');
|
|
829
|
+
const baseArgs = { runRoot: dir, changeName: CHANGE_ID, protocol, completedNodes };
|
|
830
|
+
const sourceReview = await fixReturn(baseArgs);
|
|
831
|
+
if (sourceReview !== 'review') {
|
|
832
|
+
throw new Error('review 未完成、任务全 done 时应为 review,实际 ' + JSON.stringify(sourceReview));
|
|
833
|
+
}
|
|
834
|
+
const sourceVerify = await fixReturn({ ...baseArgs, completedNodes: [...completedNodes, 'subagent-execute', 'review'] });
|
|
835
|
+
if (sourceVerify !== 'verify') {
|
|
836
|
+
throw new Error('review 已完成、verify 未完成时应为 verify,实际 ' + JSON.stringify(sourceVerify));
|
|
837
|
+
}
|
|
838
|
+
const pastSources = await fixReturn({ ...baseArgs, completedNodes: [...completedNodes, 'subagent-execute', 'review', 'verify'] });
|
|
839
|
+
if (pastSources !== null) {
|
|
840
|
+
throw new Error('review/verify 均已完成(首个未完成为 archive)时应为 null,实际 ' + JSON.stringify(pastSources));
|
|
841
|
+
}
|
|
842
|
+
// 反例:仍有 pending 任务 → null(即使 resolveNextNode 会推导回 execute)
|
|
843
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
844
|
+
'# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n' + fixTaskBlock('T02', 'pending') + '\n');
|
|
845
|
+
const stillPending = await fixReturn(baseArgs);
|
|
846
|
+
if (stillPending !== null) {
|
|
847
|
+
throw new Error('仍有 pending 任务时应为 null,实际 ' + JSON.stringify(stillPending));
|
|
848
|
+
}
|
|
849
|
+
// 反例:TASK.md 缺失 → null
|
|
850
|
+
fs.rmSync(taskPath);
|
|
851
|
+
const missingTask = await fixReturn(baseArgs);
|
|
852
|
+
if (missingTask !== null) {
|
|
853
|
+
throw new Error('TASK.md 缺失时应为 null,实际 ' + JSON.stringify(missingTask));
|
|
854
|
+
}
|
|
855
|
+
// 反例:零任务块(仅占位)→ null
|
|
856
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', '# TASK\n\n<!-- 占位 -->\n');
|
|
857
|
+
const noBlocks = await fixReturn(baseArgs);
|
|
858
|
+
if (noBlocks !== null) {
|
|
859
|
+
throw new Error('零任务块时应为 null,实际 ' + JSON.stringify(noBlocks));
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// ——classifyFixReturnCause 基础锚(T01:历史签名全量发散 + Fix 结构标记 + unknown 回退)——
|
|
863
|
+
// 分类器缺失时在此显式 RED(requireRouteNodeExport),不做半成品静默通过。
|
|
864
|
+
const classifyCause = requireRouteNodeExport('classifyFixReturnCause');
|
|
865
|
+
const signatureOf = (text) => routeNodeModule.taskSetSignature(text);
|
|
866
|
+
const familyExit = (node, signature, extra = {}) => ({
|
|
867
|
+
event: 'exit-applied', node, at: '2026-09-24T00:00:00.000Z',
|
|
868
|
+
taskSetSignature: signature, ...extra,
|
|
869
|
+
});
|
|
870
|
+
const plainTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n';
|
|
871
|
+
const plainSignature = signatureOf(plainTaskText);
|
|
872
|
+
const divergentSignature = '0'.repeat(64);
|
|
873
|
+
// ① 签名发散:历史任一出口签名 ≠ 当前任务集签名 → fix(无 Fix 标记也成立)
|
|
874
|
+
const divergence = classifyCause({
|
|
875
|
+
history: [familyExit('execute', divergentSignature)],
|
|
876
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
877
|
+
});
|
|
878
|
+
if (divergence !== 'fix') {
|
|
879
|
+
throw new Error('历史签名全量发散应判 fix,实际 ' + JSON.stringify(divergence));
|
|
880
|
+
}
|
|
881
|
+
// ② 签名相等:唯一出口签名 == 当前 TASK 签名且无 Fix 标记 → normal
|
|
882
|
+
const equalCause = classifyCause({
|
|
883
|
+
history: [familyExit('subagent-execute', plainSignature)],
|
|
884
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
885
|
+
});
|
|
886
|
+
if (equalCause !== 'normal') {
|
|
887
|
+
throw new Error('签名一致且无 Fix 标记应判 normal,实际 ' + JSON.stringify(equalCause));
|
|
888
|
+
}
|
|
889
|
+
// ③ 无签名事件:空串签名 / history 缺席 / 非家族节点 / 其它 change → unknown(都不误判 normal)
|
|
890
|
+
const emptySignature = classifyCause({
|
|
891
|
+
history: [familyExit('execute', '')],
|
|
892
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
893
|
+
});
|
|
894
|
+
if (emptySignature !== 'unknown') {
|
|
895
|
+
throw new Error('空签名事件应判 unknown,实际 ' + JSON.stringify(emptySignature));
|
|
896
|
+
}
|
|
897
|
+
const missingHistory = classifyCause({ taskContent: plainTaskText, fixSectionTitle: 'Fix 任务' });
|
|
898
|
+
if (missingHistory !== 'unknown') {
|
|
899
|
+
throw new Error('history 缺席应判 unknown,实际 ' + JSON.stringify(missingHistory));
|
|
900
|
+
}
|
|
901
|
+
const otherChangeOnly = classifyCause({
|
|
902
|
+
history: [familyExit('execute', divergentSignature, { change: 'other-change' })],
|
|
903
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
904
|
+
});
|
|
905
|
+
if (otherChangeOnly !== 'unknown') {
|
|
906
|
+
throw new Error('其它 change 的出口事件不得参与分类(应为 unknown),实际 ' + JSON.stringify(otherChangeOnly));
|
|
907
|
+
}
|
|
908
|
+
const nonFamilyOnly = classifyCause({
|
|
909
|
+
history: [familyExit('review', divergentSignature)],
|
|
910
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
911
|
+
});
|
|
912
|
+
if (nonFamilyOnly !== 'unknown') {
|
|
913
|
+
throw new Error('非 execute 家族出口事件不得参与分类(应为 unknown),实际 ' + JSON.stringify(nonFamilyOnly));
|
|
914
|
+
}
|
|
915
|
+
// ④ Fix 段内任务块(故意用非 FIX 编号 T02,排除全文编号规则干扰)→ fix(结构标记)
|
|
916
|
+
const fixSectionWithTask = plainTaskText
|
|
917
|
+
+ '\n## Fix 任务(来自 REVIEW / INTEGRATION)\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
918
|
+
const sectionMarker = classifyCause({
|
|
919
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
920
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: 'Fix 任务',
|
|
921
|
+
});
|
|
922
|
+
if (sectionMarker !== 'fix') {
|
|
923
|
+
throw new Error('Fix 段内含 task 块应判 fix,实际 ' + JSON.stringify(sectionMarker));
|
|
924
|
+
}
|
|
925
|
+
// ⑤ Fix 段无任务(仅标题与占位)→ normal(切片边界正确、不把其它段标题误当 Fix 段)
|
|
926
|
+
const fixSectionEmpty = plainTaskText + '\n## Fix 任务(来自 REVIEW / INTEGRATION)\n\n<!-- 占位 -->\n';
|
|
927
|
+
const emptySection = classifyCause({
|
|
928
|
+
history: [familyExit('execute', signatureOf(fixSectionEmpty))],
|
|
929
|
+
changeName: CHANGE_ID, taskContent: fixSectionEmpty, fixSectionTitle: 'Fix 任务',
|
|
930
|
+
});
|
|
931
|
+
if (emptySection !== 'normal') {
|
|
932
|
+
throw new Error('Fix 段无任务块应判 normal,实际 ' + JSON.stringify(emptySection));
|
|
933
|
+
}
|
|
934
|
+
// ⑥ 全文任务 id 修复任务编号前缀(Fix 段之外、文件尾追加形态)→ fix
|
|
935
|
+
const tailTFix = plainTaskText + '\n## 其它\n\n' + fixTaskBlock('T-FIX-01', 'done') + '\n';
|
|
936
|
+
const tailPFix = plainTaskText + '\n## 其它\n\n' + fixTaskBlock('P-FIX-01', 'done') + '\n';
|
|
937
|
+
for (const [label, text] of [['T-FIX-01', tailTFix], ['P-FIX-01', tailPFix]]) {
|
|
938
|
+
const idMarker = classifyCause({
|
|
939
|
+
history: [familyExit('execute', signatureOf(text))],
|
|
940
|
+
changeName: CHANGE_ID, taskContent: text, fixSectionTitle: 'Fix 任务',
|
|
941
|
+
});
|
|
942
|
+
if (idMarker !== 'fix') {
|
|
943
|
+
throw new Error(label + ' 编号(Fix 段外)应判 fix,实际 ' + JSON.stringify(idMarker));
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
// ⑦ 标题缺失回退:fixSectionTitle 缺席 / 空串 → 回退内置「Fix 任务」仍命中结构标记;
|
|
947
|
+
// 传入标题优先于内置(Fix 段在场但传入无关标题,结构规则不命中 → normal)。
|
|
948
|
+
for (const [label, title] of [['缺席', undefined], ['空串', '']]) {
|
|
949
|
+
const fallback = classifyCause({
|
|
950
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
951
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: title,
|
|
952
|
+
});
|
|
953
|
+
if (fallback !== 'fix') {
|
|
954
|
+
throw new Error('fixSectionTitle ' + label + ' 应回退内置「Fix 任务」判 fix,实际 ' + JSON.stringify(fallback));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const customTitlePriority = classifyCause({
|
|
958
|
+
history: [familyExit('execute', signatureOf(fixSectionWithTask))],
|
|
959
|
+
changeName: CHANGE_ID, taskContent: fixSectionWithTask, fixSectionTitle: '修复任务',
|
|
960
|
+
});
|
|
961
|
+
if (customTitlePriority !== 'normal') {
|
|
962
|
+
throw new Error('传入标题应优先于内置(无关标题不得命中 Fix 段)应判 normal,实际 ' + JSON.stringify(customTitlePriority));
|
|
963
|
+
}
|
|
964
|
+
// ⑧ 多波次历史:旧签名 ≠ 当前、最新签名 == 当前 → 全量扫描仍判 fix(只看最新会误判 normal)
|
|
965
|
+
const multiWave = classifyCause({
|
|
966
|
+
history: [
|
|
967
|
+
familyExit('execute', divergentSignature, { at: '2026-09-20T00:00:00.000Z' }),
|
|
968
|
+
familyExit('subagent-execute', plainSignature, { at: '2026-09-24T00:00:00.000Z' }),
|
|
969
|
+
],
|
|
970
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
971
|
+
});
|
|
972
|
+
if (multiWave !== 'fix') {
|
|
973
|
+
throw new Error('多波次历史旧签名发散(最新签名 == 当前)应判 fix(全量扫描),实际 ' + JSON.stringify(multiWave));
|
|
974
|
+
}
|
|
975
|
+
// ⑨ legacy 事件(无 change 字段)与既有 latestExecuteExitEvent 兼容语义一致:参与分类
|
|
976
|
+
const legacyDivergence = classifyCause({
|
|
977
|
+
history: [{ event: 'exit-applied', node: 'execute', at: '2026-09-20T00:00:00.000Z', taskSetSignature: divergentSignature }],
|
|
978
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
979
|
+
});
|
|
980
|
+
if (legacyDivergence !== 'fix') {
|
|
981
|
+
throw new Error('无 change 字段的 legacy 出口事件应参与分类(发散 → fix),实际 ' + JSON.stringify(legacyDivergence));
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
// ⑩ m-14 签名算法版本三态 + 冻结锚(分类器与 C3 消费点共用 route-node 谓词)
|
|
985
|
+
// 冻结锚:算法版本升级必须先更新版本决策与测试锚——本断言变红强制该决策。
|
|
986
|
+
if (routeNodeModule.TASK_SET_SIGNATURE_ALGO !== 'v1') {
|
|
987
|
+
throw new Error('签名算法版本冻结锚失效:期望 v1,实际 '
|
|
988
|
+
+ JSON.stringify(routeNodeModule.TASK_SET_SIGNATURE_ALGO)
|
|
989
|
+
+ '——升级算法前必须先更新版本决策与测试锚');
|
|
990
|
+
}
|
|
991
|
+
const parseSig = requireRouteNodeExport('parseTaskSetSignature');
|
|
992
|
+
const sameSig = requireRouteNodeExport('sameTaskSetSignature');
|
|
993
|
+
const sigSkew = requireRouteNodeExport('taskSetSignatureVersionSkew');
|
|
994
|
+
const versioned = routeNodeModule.taskSetSignature(plainTaskText);
|
|
995
|
+
if (!/^v1:[0-9a-f]{64}$/.test(versioned)) {
|
|
996
|
+
throw new Error('新版本签名值应为 v1:<sha256 hex>,实际 ' + JSON.stringify(versioned));
|
|
997
|
+
}
|
|
998
|
+
const versionedParsed = parseSig(versioned);
|
|
999
|
+
if (!versionedParsed || versionedParsed.algo !== 'v1'
|
|
1000
|
+
|| versionedParsed.digest !== parseSig(signatureOf(plainTaskText)).digest) {
|
|
1001
|
+
throw new Error('parseTaskSetSignature 应解析 vN:<digest> 元数据,实际 ' + JSON.stringify(versionedParsed));
|
|
1002
|
+
}
|
|
1003
|
+
// legacy 裸 hex 按 v1 语义(旧 taskHash / 旧事件)
|
|
1004
|
+
const legacyParsed = parseSig(versionedParsed.digest);
|
|
1005
|
+
if (!legacyParsed || legacyParsed.algo !== 'v1' || legacyParsed.digest !== versionedParsed.digest) {
|
|
1006
|
+
throw new Error('legacy 裸 hex 应按 v1 解析,实际 ' + JSON.stringify(legacyParsed));
|
|
1007
|
+
}
|
|
1008
|
+
// C3 三态谓词:同版本同 digest 一致 / 同版本不同 digest 不一致 / 跨版本 skew 跳过比对
|
|
1009
|
+
if (!sameSig(versioned, 'v1:' + versionedParsed.digest)
|
|
1010
|
+
|| sameSig(versioned, 'v1:' + divergentSignature)
|
|
1011
|
+
|| sameSig(versioned, 'v2:' + versionedParsed.digest)) {
|
|
1012
|
+
throw new Error('同版本一致性谓词三态错误(sameTaskSetSignature)');
|
|
1013
|
+
}
|
|
1014
|
+
if (!sigSkew(versioned, 'v2:' + versionedParsed.digest)
|
|
1015
|
+
|| sigSkew(versioned, versioned)
|
|
1016
|
+
|| sigSkew(versioned, versionedParsed.digest)) {
|
|
1017
|
+
throw new Error('跨版本 skew 谓词三态错误(taskSetSignatureVersionSkew)');
|
|
1018
|
+
}
|
|
1019
|
+
if (parseSig('v1:not-a-digest') !== null || parseSig('') !== null || parseSig(null) !== null) {
|
|
1020
|
+
throw new Error('非法签名形态应解析为 null(fail-closed)');
|
|
1021
|
+
}
|
|
1022
|
+
// 分类器三态:新版本相等 → normal;legacy 裸 hex 相等 → normal(legacy=v1);
|
|
1023
|
+
// 跨版本 / 声明版本与值不一致 → 跳过比对(unknown,不误判 fix)。
|
|
1024
|
+
const versionedEqual = classifyCause({
|
|
1025
|
+
history: [familyExit('execute', versioned)],
|
|
1026
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
1027
|
+
});
|
|
1028
|
+
if (versionedEqual !== 'normal') {
|
|
1029
|
+
throw new Error('新版本签名相等应判 normal,实际 ' + JSON.stringify(versionedEqual));
|
|
1030
|
+
}
|
|
1031
|
+
const legacyEqual = classifyCause({
|
|
1032
|
+
history: [familyExit('execute', versionedParsed.digest)],
|
|
1033
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
1034
|
+
});
|
|
1035
|
+
if (legacyEqual !== 'normal') {
|
|
1036
|
+
throw new Error('legacy 裸 hex 与当前摘要相等应判 normal(legacy=v1),实际 ' + JSON.stringify(legacyEqual));
|
|
1037
|
+
}
|
|
1038
|
+
const crossVersion = classifyCause({
|
|
1039
|
+
history: [familyExit('execute', 'v2:' + divergentSignature, { signatureAlgo: 'v2' })],
|
|
1040
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
1041
|
+
});
|
|
1042
|
+
if (crossVersion !== 'unknown') {
|
|
1043
|
+
throw new Error('跨算法版本历史事件应跳过比对(unknown,不误判 fix),实际 ' + JSON.stringify(crossVersion));
|
|
1044
|
+
}
|
|
1045
|
+
const mismatchedDeclared = classifyCause({
|
|
1046
|
+
history: [familyExit('execute', versioned, { signatureAlgo: 'v2' })],
|
|
1047
|
+
changeName: CHANGE_ID, taskContent: plainTaskText, fixSectionTitle: 'Fix 任务',
|
|
1048
|
+
});
|
|
1049
|
+
if (mismatchedDeclared !== 'unknown') {
|
|
1050
|
+
throw new Error('signatureAlgo 与值版本不一致的畸形事件应跳过(unknown),实际 ' + JSON.stringify(mismatchedDeclared));
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
},
|
|
1054
|
+
|
|
1055
|
+
// 248: entry execute 受控归位(review 源)——Fix 回退态(review 驻留 + TASK pending + 共享谓词
|
|
1056
|
+
// 路由 execute)直接 entry execute:currentNode 归位 execute 并写盘 + FIX-BATCH 审计行;
|
|
1057
|
+
// 反例无 pending(全 done)→ 谓词 false 不归位(currentNode 保持 review、无审计行);
|
|
1058
|
+
// 边界:execute 尚未在 completedNodes(前序欠账态)但共享谓词成立 → 前置拦截不生效仍归位。
|
|
1059
|
+
{
|
|
1060
|
+
name: '248 entry execute 受控归位:review 源 Fix 态 → currentNode=execute + 审计行',
|
|
1061
|
+
run: (dir) => {
|
|
1062
|
+
writeIntakeArtifacts(dir);
|
|
1063
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
1064
|
+
const st = {
|
|
1065
|
+
activeChange: CHANGE_ID,
|
|
1066
|
+
currentNode: 'review',
|
|
1067
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
1068
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
1069
|
+
evidence: {
|
|
1070
|
+
execute: { summary: 'first pass executed' },
|
|
1071
|
+
review: { summary: 'review in progress' },
|
|
1072
|
+
},
|
|
1073
|
+
verifyFailures: 0,
|
|
1074
|
+
executionMode: 'subagent',
|
|
1075
|
+
directOverride: false,
|
|
1076
|
+
newChange: true,
|
|
1077
|
+
};
|
|
1078
|
+
// ① 正例:pending Fix 任务在场 → 受控归位 + 审计行 + 真实写盘
|
|
1079
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
1080
|
+
writeState(dir, st);
|
|
1081
|
+
const res = runGuard(['entry', 'execute'], dir);
|
|
1082
|
+
assertExit(res, 0);
|
|
1083
|
+
assertOut(res, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
1084
|
+
assertOut(res, 'ENTRY OK: execute');
|
|
1085
|
+
let after = readScenarioState(dir);
|
|
1086
|
+
if (after.currentNode !== 'execute') {
|
|
1087
|
+
throw new Error('受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
1088
|
+
}
|
|
1089
|
+
// ② 反例:无 pending(全 done)→ 不归位(机器字段保持 review;无审计行)
|
|
1090
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
1091
|
+
writeState(dir, st);
|
|
1092
|
+
const resNoFix = runGuard(['entry', 'execute'], dir);
|
|
1093
|
+
assertExit(resNoFix, 0);
|
|
1094
|
+
assertNotOut(resNoFix, 'FIX-BATCH');
|
|
1095
|
+
after = readScenarioState(dir);
|
|
1096
|
+
if (after.currentNode !== 'review') {
|
|
1097
|
+
throw new Error('无 pending 时 entry execute 不应归位(currentNode 应保持 review),实际 ' + JSON.stringify(after.currentNode));
|
|
1098
|
+
}
|
|
1099
|
+
// ③ 边界:execute 不在 completedNodes(欠账态)但共享谓词成立 → 前置拦截不生效,仍受控归位
|
|
1100
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
1101
|
+
writeState(dir, { ...st, completedNodes: ['open', 'design', 'plan'] });
|
|
1102
|
+
const resDrift = runGuard(['entry', 'execute'], dir);
|
|
1103
|
+
assertExit(resDrift, 0);
|
|
1104
|
+
assertOut(resDrift, 'FIX-BATCH: 受控归位 execute(源节点 review)');
|
|
1105
|
+
after = readScenarioState(dir);
|
|
1106
|
+
if (after.currentNode !== 'execute') {
|
|
1107
|
+
throw new Error('欠账态受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
1108
|
+
}
|
|
1109
|
+
// ④ m-12 第 1~3 轮递增(AC-4):逐轮重置驻留态,审计后缀第 n/3 轮且计数器同步 +1
|
|
1110
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
1111
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
1112
|
+
writeState(dir, st);
|
|
1113
|
+
const stRound = readScenarioState(dir);
|
|
1114
|
+
stRound.fixRoundsByChange = { [CHANGE_ID]: round - 1 };
|
|
1115
|
+
writeState(dir, stRound);
|
|
1116
|
+
const resRound = runGuard(['entry', 'execute'], dir);
|
|
1117
|
+
assertExit(resRound, 0);
|
|
1118
|
+
assertOut(resRound, 'FIX-BATCH: 受控归位 execute(源节点 review)(第 ' + round + '/3 轮)');
|
|
1119
|
+
const stAfterRound = readScenarioState(dir);
|
|
1120
|
+
if (stAfterRound.fixRoundsByChange?.[CHANGE_ID] !== round) {
|
|
1121
|
+
throw new Error('第 ' + round + ' 轮 entry 归位后计数器应为 ' + round + ',实际 '
|
|
1122
|
+
+ JSON.stringify(stAfterRound.fixRoundsByChange));
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
// ⑤ 第 4 轮新 change BLOCK:state 字节零改写(不写 currentNode、不写计数器)
|
|
1126
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 3 } });
|
|
1127
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
1128
|
+
const beforeRound4 = fs.readFileSync(statePath, 'utf8');
|
|
1129
|
+
const resRound4 = runGuard(['entry', 'execute'], dir);
|
|
1130
|
+
assertExit(resRound4, 1);
|
|
1131
|
+
assertOut(resRound4, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
1132
|
+
assertOut(resRound4, '继续修');
|
|
1133
|
+
assertOut(resRound4, '停止');
|
|
1134
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeRound4) {
|
|
1135
|
+
throw new Error('第 4 轮 BLOCK 必须 state 字节零改写(不写 currentNode/计数器)');
|
|
1136
|
+
}
|
|
1137
|
+
const stBlocked = readScenarioState(dir);
|
|
1138
|
+
if (stBlocked.currentNode !== 'review' || stBlocked.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
1139
|
+
throw new Error('第 4 轮 BLOCK 后 currentNode 应保持 review、计数器保持 3,实际 '
|
|
1140
|
+
+ JSON.stringify({ currentNode: stBlocked.currentNode, rounds: stBlocked.fixRoundsByChange }));
|
|
1141
|
+
}
|
|
1142
|
+
// ⑤b F5:非法授权形态(仅 round,缺 at/source)在真实 entry 链路上仍按未授权 fail-closed——
|
|
1143
|
+
// 继续 BLOCK、state 字节零改写、currentNode 保持 review、计数器保持 3。
|
|
1144
|
+
const stBadOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
1145
|
+
stBadOverride.evidence.review.fixRoundOverride = { round: 4 };
|
|
1146
|
+
writeState(dir, stBadOverride);
|
|
1147
|
+
const badOverrideBytes = fs.readFileSync(statePath, 'utf8');
|
|
1148
|
+
const resBadOverride = runGuard(['entry', 'execute'], dir);
|
|
1149
|
+
assertExit(resBadOverride, 1);
|
|
1150
|
+
assertOut(resBadOverride, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
1151
|
+
assertNotOut(resBadOverride, '(第 4/3 轮)');
|
|
1152
|
+
if (fs.readFileSync(statePath, 'utf8') !== badOverrideBytes) {
|
|
1153
|
+
throw new Error('F5 缺 at/source 的授权形态必须在 entry 链路上 state 字节零改写');
|
|
1154
|
+
}
|
|
1155
|
+
const stBadAfter = readScenarioState(dir);
|
|
1156
|
+
if (stBadAfter.currentNode !== 'review' || stBadAfter.fixRoundsByChange?.[CHANGE_ID] !== 3) {
|
|
1157
|
+
throw new Error('F5 缺 at/source 不得放行第 4 轮(currentNode 保持 review、计数保持 3),实际 '
|
|
1158
|
+
+ JSON.stringify({ currentNode: stBadAfter.currentNode, rounds: stBadAfter.fixRoundsByChange }));
|
|
1159
|
+
}
|
|
1160
|
+
// ⑥ 用户显式授权(嵌套 evidence,完整三元组)→ 放行第 4 轮并写 currentNode + 计数器
|
|
1161
|
+
const stOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
1162
|
+
stOverride.evidence.review.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
1163
|
+
writeState(dir, stOverride);
|
|
1164
|
+
const resOverride = runGuard(['entry', 'execute'], dir);
|
|
1165
|
+
assertExit(resOverride, 0);
|
|
1166
|
+
assertOut(resOverride, '(第 4/3 轮)');
|
|
1167
|
+
const stAuthorized = readScenarioState(dir);
|
|
1168
|
+
if (stAuthorized.currentNode !== 'execute' || stAuthorized.fixRoundsByChange?.[CHANGE_ID] !== 4) {
|
|
1169
|
+
throw new Error('授权后第 4 轮应放行归位(currentNode=execute、计数器=4),实际 '
|
|
1170
|
+
+ JSON.stringify({ currentNode: stAuthorized.currentNode, rounds: stAuthorized.fixRoundsByChange }));
|
|
1171
|
+
}
|
|
1172
|
+
},
|
|
1173
|
+
},
|
|
1174
|
+
|
|
1175
|
+
// 249: entry execute 受控归位(verify 源)——verify 驻留 + 进行中证据/enteredNodes 在场时,
|
|
1176
|
+
// Fix 回退态归位不被进行中保护分支挡回 verify(归位是显式分支);无 pending 反例不归位。
|
|
1177
|
+
{
|
|
1178
|
+
name: '249 entry execute 受控归位:verify 源 Fix 态 → currentNode=execute + 审计行(进行中证据不挡)',
|
|
1179
|
+
run: (dir) => {
|
|
1180
|
+
writeIntakeArtifacts(dir);
|
|
1181
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
1182
|
+
const st = {
|
|
1183
|
+
activeChange: CHANGE_ID,
|
|
1184
|
+
currentNode: 'verify',
|
|
1185
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
1186
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'],
|
|
1187
|
+
evidence: {
|
|
1188
|
+
execute: { summary: 'first pass executed' },
|
|
1189
|
+
review: { summary: 'review complete' },
|
|
1190
|
+
verify: { summary: 'verify in progress' },
|
|
1191
|
+
},
|
|
1192
|
+
verifyFailures: 0,
|
|
1193
|
+
executionMode: 'subagent',
|
|
1194
|
+
directOverride: false,
|
|
1195
|
+
newChange: true,
|
|
1196
|
+
};
|
|
1197
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
1198
|
+
writeState(dir, st);
|
|
1199
|
+
const res = runGuard(['entry', 'execute'], dir);
|
|
1200
|
+
assertExit(res, 0);
|
|
1201
|
+
assertOut(res, 'FIX-BATCH: 受控归位 execute(源节点 verify)');
|
|
1202
|
+
let after = readScenarioState(dir);
|
|
1203
|
+
if (after.currentNode !== 'execute') {
|
|
1204
|
+
throw new Error('verify 源受控归位后 currentNode 应为 execute,实际 ' + JSON.stringify(after.currentNode));
|
|
1205
|
+
}
|
|
1206
|
+
// 反例:全 done(无 pending)→ 不归位,currentNode 保持 verify
|
|
1207
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
1208
|
+
writeState(dir, st);
|
|
1209
|
+
const resNoFix = runGuard(['entry', 'execute'], dir);
|
|
1210
|
+
assertExit(resNoFix, 0);
|
|
1211
|
+
assertNotOut(resNoFix, 'FIX-BATCH');
|
|
1212
|
+
after = readScenarioState(dir);
|
|
1213
|
+
if (after.currentNode !== 'verify') {
|
|
1214
|
+
throw new Error('无 pending 时 entry execute 不应归位(currentNode 应保持 verify),实际 ' + JSON.stringify(after.currentNode));
|
|
1215
|
+
}
|
|
1216
|
+
// ③ m-12/AC-5 计数隔离:verify 源归位只增 Fix 轮次,verify 失败计数保持不动
|
|
1217
|
+
writeFile(dir, taskPath, fixBatchTaskText('pending'));
|
|
1218
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 1 }, verifyFailuresByChange: { [CHANGE_ID]: 2 } });
|
|
1219
|
+
const resRound2 = runGuard(['entry', 'execute'], dir);
|
|
1220
|
+
assertExit(resRound2, 0);
|
|
1221
|
+
assertOut(resRound2, '受控归位 execute(源节点 verify)(第 2/3 轮)');
|
|
1222
|
+
let stIsolated = readScenarioState(dir);
|
|
1223
|
+
if (stIsolated.fixRoundsByChange?.[CHANGE_ID] !== 2 || stIsolated.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
1224
|
+
throw new Error('verify 源归位应只增 Fix 轮次(2)、verify 失败计数保持 2,实际 '
|
|
1225
|
+
+ JSON.stringify({ rounds: stIsolated.fixRoundsByChange, verifyFailures: stIsolated.verifyFailuresByChange }));
|
|
1226
|
+
}
|
|
1227
|
+
// ④ 第 4 轮 BLOCK + state 字节零改写 + 授权放行(verify 源)
|
|
1228
|
+
writeState(dir, { ...st, fixRoundsByChange: { [CHANGE_ID]: 3 }, verifyFailuresByChange: { [CHANGE_ID]: 2 } });
|
|
1229
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
1230
|
+
const beforeBlocked = fs.readFileSync(statePath, 'utf8');
|
|
1231
|
+
const resBlocked = runGuard(['entry', 'execute'], dir);
|
|
1232
|
+
assertExit(resBlocked, 1);
|
|
1233
|
+
assertOut(resBlocked, 'BLOCKED: Fix 批次受控归位已达 3 轮上限');
|
|
1234
|
+
if (fs.readFileSync(statePath, 'utf8') !== beforeBlocked) {
|
|
1235
|
+
throw new Error('verify 源第 4 轮 BLOCK 必须 state 字节零改写');
|
|
1236
|
+
}
|
|
1237
|
+
const stVBlocked = readScenarioState(dir);
|
|
1238
|
+
if (stVBlocked.currentNode !== 'verify' || stVBlocked.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
1239
|
+
throw new Error('verify 源第 4 轮 BLOCK 后 currentNode/verify 计数不得改写,实际 '
|
|
1240
|
+
+ JSON.stringify({ currentNode: stVBlocked.currentNode, verifyFailures: stVBlocked.verifyFailuresByChange }));
|
|
1241
|
+
}
|
|
1242
|
+
const stVOverride = JSON.parse(fs.readFileSync(statePath, 'utf8'));
|
|
1243
|
+
stVOverride.evidence.verify.fixRoundOverride = { round: 4, at: '2026-09-25T00:00:00.000Z', source: 'fixture-user' };
|
|
1244
|
+
writeState(dir, stVOverride);
|
|
1245
|
+
const resVOverride = runGuard(['entry', 'execute'], dir);
|
|
1246
|
+
assertExit(resVOverride, 0);
|
|
1247
|
+
assertOut(resVOverride, '(第 4/3 轮)');
|
|
1248
|
+
const stVAfter = readScenarioState(dir);
|
|
1249
|
+
if (stVAfter.currentNode !== 'execute' || stVAfter.fixRoundsByChange?.[CHANGE_ID] !== 4
|
|
1250
|
+
|| stVAfter.verifyFailuresByChange?.[CHANGE_ID] !== 2) {
|
|
1251
|
+
throw new Error('verify 源授权放行后应 currentNode=execute、轮次=4、verify 计数保持 2,实际 '
|
|
1252
|
+
+ JSON.stringify({ currentNode: stVAfter.currentNode, rounds: stVAfter.fixRoundsByChange, verifyFailures: stVAfter.verifyFailuresByChange }));
|
|
1253
|
+
}
|
|
1254
|
+
},
|
|
1255
|
+
},
|
|
1256
|
+
|
|
1257
|
+
// 250: exit execute --apply Fix 二次完成回源(review 源)——execute 在 exit 前已在
|
|
1258
|
+
// completedNodes + TASK 全 done:REVIEW.md 已在场(resolveNextNode 会按产物跳过 review 到
|
|
1259
|
+
// verify)但 review 未完成 → 受控回程 review(源节点出口必须真实执行,不被产物存在性跳过)。
|
|
1260
|
+
// 本场景族拆自原 250 单场景,断言与失败信息保持不变;本段覆盖回源归属与出口事件形状。
|
|
1261
|
+
{
|
|
1262
|
+
name: '250 exit execute --apply Fix 二次完成:回源 review(REVIEW.md 在场但不按产物跳过)',
|
|
1263
|
+
run: (dir) => {
|
|
1264
|
+
writeIntakeArtifacts(dir);
|
|
1265
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
1266
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
1267
|
+
writeFixReturnSummaries(dir, ['T01', 'T-FIX-01']);
|
|
1268
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', FIX_RETURN_REVIEW_TEXT);
|
|
1269
|
+
writeState(dir, {
|
|
1270
|
+
activeChange: CHANGE_ID,
|
|
1271
|
+
currentNode: 'execute',
|
|
1272
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
1273
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
1274
|
+
evidence: {
|
|
1275
|
+
execute: { summary: 'fix batch executed' },
|
|
1276
|
+
'subagent-execute': { summary: 'delegated', handoffResult: handoffFor(['T01', 'T-FIX-01']) },
|
|
1277
|
+
review: { summary: 'review in progress' },
|
|
1278
|
+
},
|
|
1279
|
+
verifyFailures: 0,
|
|
1280
|
+
executionMode: 'subagent',
|
|
1281
|
+
directOverride: false,
|
|
1282
|
+
newChange: true,
|
|
1283
|
+
});
|
|
1284
|
+
const res = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1285
|
+
assertExit(res, 0);
|
|
1286
|
+
assertOut(res, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1287
|
+
assertOut(res, 'NODE: review');
|
|
1288
|
+
assertNotOut(res, 'NODE: verify');
|
|
1289
|
+
const after = readScenarioState(dir);
|
|
1290
|
+
if (after.currentNode !== 'review') {
|
|
1291
|
+
throw new Error('Fix 回程后 currentNode 应为 review,实际 ' + JSON.stringify(after.currentNode));
|
|
1292
|
+
}
|
|
1293
|
+
// 出口事件须带本 change 归属 + 任务集签名(跨 change 保留 history 时按 change 过滤)。
|
|
1294
|
+
const lastExit = (after.history || []).filter((e) => e && e.event === 'exit-applied').pop();
|
|
1295
|
+
if (!lastExit || lastExit.node !== 'execute' || lastExit.change !== CHANGE_ID
|
|
1296
|
+
|| typeof lastExit.taskSetSignature !== 'string' || lastExit.taskSetSignature === '') {
|
|
1297
|
+
throw new Error('exit execute --apply 应记录带 change 与 taskSetSignature 的出口事件,实际 '
|
|
1298
|
+
+ JSON.stringify(lastExit));
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// 250e 源未 entry 的真实 Fix:修复任务 + enteredNodes 不含源节点 review + 历史无
|
|
1302
|
+
// 签名(旧态)→ 结构标记仍恢复 fix 标签,保留 FIX-BATCH;不误判 unknown、不卡死。
|
|
1303
|
+
writeFile(dir, taskPath, fixBatchTaskText('done'));
|
|
1304
|
+
writeState(dir, fixReturnBaseState({
|
|
1305
|
+
evidence: fixReturnFamilyEvidence(['T01', 'T-FIX-01']),
|
|
1306
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
1307
|
+
history: [],
|
|
1308
|
+
}));
|
|
1309
|
+
const resSourceNotEntered = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1310
|
+
assertExit(resSourceNotEntered, 0);
|
|
1311
|
+
assertOut(resSourceNotEntered, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1312
|
+
assertOut(resSourceNotEntered, 'NODE: review');
|
|
1313
|
+
assertNotOut(resSourceNotEntered, 'RETURN: 回源节点');
|
|
1314
|
+
assertNotOut(resSourceNotEntered, 'BLOCKED');
|
|
1315
|
+
},
|
|
1316
|
+
},
|
|
1317
|
+
|
|
1318
|
+
// 250b: 回程行分类与 Fix 段标题路径——历史全量扫描 / 旧态未分类 / 模板派生与缺失回退。
|
|
1319
|
+
// 本场景族拆自原 250 单场景,断言与失败信息保持不变。
|
|
1320
|
+
{
|
|
1321
|
+
name: '250b 回程行分类与 Fix 段标题路径:历史扫描、旧态未分类、模板派生与回退',
|
|
1322
|
+
run: (dir) => {
|
|
1323
|
+
writeIntakeArtifacts(dir);
|
|
1324
|
+
const taskPath = '.specs/' + CHANGE_ID + '/TASK.md';
|
|
1325
|
+
writeFixReturnSummaries(dir, ['T01', 'T-FIX-01']);
|
|
1326
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', FIX_RETURN_REVIEW_TEXT);
|
|
1327
|
+
|
|
1328
|
+
// 本族反向构造——与上文正向断言一一对应,证明分类依据是历史全量扫描(不是只看
|
|
1329
|
+
// 最新):① 无 Fix 编号任务 + 旧签名 ≠ 当前 + 最新签名 == 当前 → 仍判 fix(发散证据
|
|
1330
|
+
// 不依赖结构标记);② 同任务集仅保留最新(签名 == 当前)→ 必须中性 RETURN。
|
|
1331
|
+
const plainTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n';
|
|
1332
|
+
const plainSignature = routeNodeModule.taskSetSignature(plainTaskText);
|
|
1333
|
+
writeFile(dir, taskPath, plainTaskText);
|
|
1334
|
+
writeState(dir, fixReturnBaseState({
|
|
1335
|
+
history: [
|
|
1336
|
+
{
|
|
1337
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
1338
|
+
at: '2026-09-20T00:00:00.000Z', taskSetSignature: STALE_FIX_BATCH_SIGNATURE,
|
|
1339
|
+
},
|
|
1340
|
+
{
|
|
1341
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
1342
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: plainSignature,
|
|
1343
|
+
},
|
|
1344
|
+
],
|
|
1345
|
+
}));
|
|
1346
|
+
const resDivergentPlain = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1347
|
+
assertExit(resDivergentPlain, 0);
|
|
1348
|
+
assertOut(resDivergentPlain, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1349
|
+
assertNotOut(resDivergentPlain, 'RETURN: 回源节点');
|
|
1350
|
+
writeState(dir, fixReturnBaseState({
|
|
1351
|
+
history: [{
|
|
1352
|
+
event: 'exit-applied', node: 'subagent-execute', change: CHANGE_ID,
|
|
1353
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: plainSignature,
|
|
1354
|
+
}],
|
|
1355
|
+
}));
|
|
1356
|
+
const resLatestOnlyEqual = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1357
|
+
assertExit(resLatestOnlyEqual, 0);
|
|
1358
|
+
assertOut(resLatestOnlyEqual, 'RETURN: 回源节点 review(execute 出口已完成;正常多趟收尾,非 Fix 回修)');
|
|
1359
|
+
assertNotOut(resLatestOnlyEqual, 'FIX-BATCH');
|
|
1360
|
+
|
|
1361
|
+
// 250f 旧态无签名无标记:历史家族出口无签名 + 任务集无 Fix 标记 → RETURN 未分类;
|
|
1362
|
+
// 不 BLOCK、不出现 FIX-BATCH;NODE/state 与收口前一致(只有审计行变化)。
|
|
1363
|
+
writeState(dir, fixReturnBaseState({
|
|
1364
|
+
history: [{
|
|
1365
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
1366
|
+
at: '2026-09-19T00:00:00.000Z',
|
|
1367
|
+
}],
|
|
1368
|
+
}));
|
|
1369
|
+
const beforeUnknown = readScenarioState(dir);
|
|
1370
|
+
const resUnknown = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1371
|
+
assertExit(resUnknown, 0);
|
|
1372
|
+
assertOut(resUnknown, 'RETURN: 回源节点 review(execute 出口已完成;旧 state 缺闭合/修复证据,未分类)');
|
|
1373
|
+
assertOut(resUnknown, 'NODE: review');
|
|
1374
|
+
assertNotOut(resUnknown, 'FIX-BATCH');
|
|
1375
|
+
assertNotOut(resUnknown, 'BLOCKED');
|
|
1376
|
+
const afterUnknown = readScenarioState(dir);
|
|
1377
|
+
if (afterUnknown.currentNode !== 'review' || afterUnknown.completedNodes.join(',') !== FIX_RETURN_FAMILY_COMPLETED) {
|
|
1378
|
+
throw new Error('未分类回程应只覆盖路由到 review 且 completedNodes 不变,实际 '
|
|
1379
|
+
+ JSON.stringify({ currentNode: afterUnknown.currentNode, completedNodes: afterUnknown.completedNodes }));
|
|
1380
|
+
}
|
|
1381
|
+
assertStateOnlyChanged(beforeUnknown, afterUnknown, {
|
|
1382
|
+
label: '250f 旧态未分类回程',
|
|
1383
|
+
allowed: ['currentNode', 'status', 'history'],
|
|
1384
|
+
});
|
|
1385
|
+
|
|
1386
|
+
// 250g Fix 段标题从 flow-kit/templates/TASK.md 派生(决策 4):模板段名含括号说明 +
|
|
1387
|
+
// 段内非 FIX 编号任务 → 结构标记命中 fix(模板读取路径真实被执行;标题由模板派生)。
|
|
1388
|
+
writeFile(dir, 'flow-kit/templates/TASK.md',
|
|
1389
|
+
'# TASK 模板\n\n## Fix 任务(来自 REVIEW / INTEGRATION)\n');
|
|
1390
|
+
const sectionTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
1391
|
+
+ '## Fix 任务(来自 REVIEW / INTEGRATION)\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
1392
|
+
writeFile(dir, taskPath, sectionTaskText);
|
|
1393
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T02-SUMMARY.md', strictSummary('T02'));
|
|
1394
|
+
const sectionSignature = routeNodeModule.taskSetSignature(sectionTaskText);
|
|
1395
|
+
writeState(dir, fixReturnBaseState({
|
|
1396
|
+
evidence: fixReturnFamilyEvidence(['T01', 'T02']),
|
|
1397
|
+
history: [{
|
|
1398
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID,
|
|
1399
|
+
at: '2026-09-24T00:00:00.000Z', taskSetSignature: sectionSignature,
|
|
1400
|
+
}],
|
|
1401
|
+
}));
|
|
1402
|
+
const resSection = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1403
|
+
assertExit(resSection, 0);
|
|
1404
|
+
assertOut(resSection, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1405
|
+
assertNotOut(resSection, 'RETURN: 回源节点');
|
|
1406
|
+
|
|
1407
|
+
// 250h m-06 模板缺失 + 闭合 ATX + 非 FIX 编号:guard 无模板派生标题 → 回退内置
|
|
1408
|
+
// 「Fix 任务」,段内 T02 由结构标记判 fix(模板缺席不得让 Fix 批次漏判)。
|
|
1409
|
+
fs.rmSync(path.join(dir, 'flow-kit', 'templates', 'TASK.md'), { force: true });
|
|
1410
|
+
const missingTplTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
1411
|
+
+ '## Fix 任务 ##\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
1412
|
+
writeFile(dir, taskPath, missingTplTaskText);
|
|
1413
|
+
writeState(dir, fixReturnBaseState({ evidence: fixReturnFamilyEvidence(['T01', 'T02']), history: [] }));
|
|
1414
|
+
const resMissingTpl = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1415
|
+
assertExit(resMissingTpl, 0);
|
|
1416
|
+
assertOut(resMissingTpl, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1417
|
+
assertNotOut(resMissingTpl, 'RETURN: 回源节点');
|
|
1418
|
+
assertNotOut(resMissingTpl, 'BLOCKED');
|
|
1419
|
+
|
|
1420
|
+
// 250i m-06 模板基名不同(Fix Tasks)+ 闭合 ATX + 非 FIX 编号:标题归一来自共享权威,
|
|
1421
|
+
// 语言后缀可变仍命中 Fix 段(旧硬编码中文基名会漏判 → RETURN-normal)。
|
|
1422
|
+
writeFile(dir, 'flow-kit/templates/TASK.md',
|
|
1423
|
+
'# TASK 模板\n\n## Fix Tasks(来自 REVIEW / INTEGRATION)\n');
|
|
1424
|
+
const renamedTplTaskText = '# TASK\n\n' + fixTaskBlock('T01', 'done') + '\n'
|
|
1425
|
+
+ '## Fix Tasks ##\n\n' + fixTaskBlock('T02', 'done') + '\n';
|
|
1426
|
+
writeFile(dir, taskPath, renamedTplTaskText);
|
|
1427
|
+
writeState(dir, fixReturnBaseState({ evidence: fixReturnFamilyEvidence(['T01', 'T02']), history: [] }));
|
|
1428
|
+
const resRenamedTpl = runGuard(['exit', 'execute', '--apply'], dir);
|
|
1429
|
+
assertExit(resRenamedTpl, 0);
|
|
1430
|
+
assertOut(resRenamedTpl, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
1431
|
+
assertNotOut(resRenamedTpl, 'RETURN: 回源节点');
|
|
1432
|
+
assertNotOut(resRenamedTpl, 'BLOCKED');
|
|
1433
|
+
},
|
|
1434
|
+
},
|
|
1435
|
+
|
|
1436
|
+
];
|