flow-comet 1.6.2 → 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/SKILL.md +64 -46
- package/.flow-comet/skills/flow-comet/reference/KNOWN-ISSUES-template.md +1 -1
- package/.flow-comet/skills/flow-comet/reference/commit-discipline.md +32 -0
- package/.flow-comet/skills/flow-comet/reference/dirty-worktree.md +1 -1
- package/.flow-comet/skills/flow-comet/{GUIDANCE.md → reference/entry-detail.md} +18 -28
- package/.flow-comet/skills/flow-comet/reference/fix-loop.md +57 -0
- package/.flow-comet/skills/flow-comet/reference/platform-facts.md +58 -0
- package/.flow-comet/skills/flow-comet/reference/replan.md +23 -0
- package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +5 -4
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +266 -25
- 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 -16325
- 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 +73 -1077
- 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 +14 -1
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +58 -6692
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +4 -4
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +151 -2428
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +116 -9
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +29 -2086
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
- package/.flow-comet/skills/flow-comet-change/SKILL.md +2 -3
- package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +6 -6
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
- package/.flow-comet/skills/flow-comet-integration/SKILL.md +8 -5
- package/.flow-comet/skills/flow-comet-open/SKILL.md +5 -1
- package/.flow-comet/skills/flow-comet-plan/GUIDANCE.md +1 -1
- package/.flow-comet/skills/flow-comet-plan/SKILL.md +8 -8
- package/.flow-comet/skills/flow-comet-review/SKILL.md +9 -12
- package/.flow-comet/skills/flow-comet-subagent-execute/SKILL.md +59 -16
- package/.flow-comet/skills/flow-comet-task/SKILL.md +3 -2
- package/.flow-comet/skills/flow-comet-ui-design/SKILL.md +3 -3
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
- package/README.md +53 -70
- package/package.json +3 -2
- package/scripts/dsh-bridge.mjs +59 -26
- 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 +36 -1164
- package/.flow-comet/skills/flow-comet/reference/TEST-MATRIX.md +0 -116
- package/.flow-comet/skills/flow-comet/reference/composition-report.md +0 -65
- package/.flow-comet/skills/flow-comet/reference/dsh-platform.md +0 -184
- package/.flow-comet/skills/flow-comet/reference/resolved-skills.json +0 -661
- package/.flow-comet/skills/flow-comet/reference/skill-review.md +0 -13
- package/.flow-comet/skills/flow-comet/reference/subagents/script-author.md +0 -7
- package/.flow-comet/skills/flow-comet/reference/worktree-notes.md +0 -70
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
// items/h.mjs — H 组条目(verify 与归档)
|
|
2
|
+
//
|
|
3
|
+
// 组文件约定:`export const ENTRIES = [...]`(元素含 name 与 run;计数派生按此聚合,见 lib/count-derivation.mjs)。
|
|
4
|
+
// 跨组共用夹具在 lib/system-fixtures.mjs(组文件只承载 ENTRIES 数据与组内私有夹具,组文件之间零 import)。
|
|
5
|
+
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { execFileSync, spawnSync } from 'child_process';
|
|
9
|
+
import { createHash } from 'crypto';
|
|
10
|
+
import { assertExit, assertNotOut, assertOut, runGuard, runHandoff, runState, writeFile, writeState } from '../lib/test-helpers.mjs';
|
|
11
|
+
import { CHANGE_ID, assertNodeLine, assertNotNodeLine, completeFixTaskAndRecord, driveThroughDesign, execSummaryFixture, fixBatchReviewDoc, fixBatchTaskText, fullContract, parseStatusOutput, readStateBytes, readStateFile, writeIntakeArtifacts } from '../lib/system-fixtures.mjs';
|
|
12
|
+
|
|
13
|
+
// 同夹具的「段内大写 Z 早于方法名」变体(真实机检标记形态):6 维自查段体首行是含大写 Z 的机检
|
|
14
|
+
// 标记说明,方法声明行在其后。段尾判定若把大写 Z 当串尾(惰性段体在段内首个 Z 处提前收尾),
|
|
15
|
+
// 方法声明被截掉 ⇒ execute 家族出口误判「6 维自查未声明自检方法」而 BLOCK。
|
|
16
|
+
// 夹具前提不成立(段标题形态变化)即抛错——不让变体静默退化成与基线逐字节相同的形态。
|
|
17
|
+
function execSummaryWithMachineMarker(taskId) {
|
|
18
|
+
const base = execSummaryFixture(taskId);
|
|
19
|
+
const sixDimHead = '## 6 维自查\n\n';
|
|
20
|
+
if (!base.includes(sixDimHead)) {
|
|
21
|
+
throw new Error('夹具前提失效:SUMMARY 夹具缺 6 维自查段标题形态 ' + JSON.stringify(sixDimHead));
|
|
22
|
+
}
|
|
23
|
+
return base.replace(sixDimHead,
|
|
24
|
+
sixDimHead + '> 本任务 diff 属零逻辑改动(机检标记 ZERO-LOGIC-CHANGE-OK),按协议执行 PR Review。\n\n');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ---------- 受控重入真实命令链路夹具(H5~H8 共用) ----------
|
|
28
|
+
|
|
29
|
+
// archive 已 entry 形态的完成集(built-in 协议:open → verify 全部完成;archive 已进入未出口)
|
|
30
|
+
const ARCHIVE_ENTRY_COMPLETED_NODES = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review', 'verify'];
|
|
31
|
+
// 前驱交集结果:目标 verify 的前驱 = 上述完成集去掉 verify 自身(按协议顺序)
|
|
32
|
+
const REENTRY_VERIFY_PREDECESSORS = ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'];
|
|
33
|
+
|
|
34
|
+
// 重入前夹具:临时 runRoot 内 init → archive 已 entry 形态(前序节点全部完成、activeChange 在场、
|
|
35
|
+
// status=running、.specs/<id>/ 未移动、TASK.md 在场)。协议由 runState/runGuard 显式注入
|
|
36
|
+
// FLOW_COMET_PROTOCOL(门禁不得静默跳过)。
|
|
37
|
+
function seedArchiveEntryState(root, changeId = CHANGE_ID) {
|
|
38
|
+
assertExit(runState(['init', changeId, '--init-skip'], root), 0);
|
|
39
|
+
assertExit(runState(['skill-load', 'archive', 'flow-comet-integration', '--prompt', 'flow-kit/prompts/7-integration.md'], root), 0);
|
|
40
|
+
writeFile(root, '.specs/' + changeId + '/TASK.md',
|
|
41
|
+
'# TASK\n\n<task id="T01" parallel="false" status="done"><action>初版实现</action>' +
|
|
42
|
+
'<write_files>src/t01.mjs</write_files><verify>node --check src/t01.mjs</verify><done>落地</done></task>\n');
|
|
43
|
+
const st = readStateFile(root);
|
|
44
|
+
st.currentNode = 'archive';
|
|
45
|
+
st.completedNodes = ARCHIVE_ENTRY_COMPLETED_NODES.slice();
|
|
46
|
+
st.status = 'running';
|
|
47
|
+
st.enteredNodes = ARCHIVE_ENTRY_COMPLETED_NODES.concat('archive');
|
|
48
|
+
writeState(root, st);
|
|
49
|
+
assertExit(runState(['record', 'archive', '{"summary":"archived"}'], root), 0);
|
|
50
|
+
assertExit(runGuard(['entry', 'archive'], root), 0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 备份目录/文件读取(.specs/<id>/.reentry-backups/)
|
|
54
|
+
function reentryBackupDir(root, changeId = CHANGE_ID) {
|
|
55
|
+
return path.join(root, '.specs', changeId, '.reentry-backups');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function reentryBackupFiles(root, changeId = CHANGE_ID) {
|
|
59
|
+
return fs.existsSync(reentryBackupDir(root, changeId)) ? fs.readdirSync(reentryBackupDir(root, changeId)) : [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// reentry-applied 事件过滤(state.history 追加记录)
|
|
63
|
+
function reentryEventsOf(state) {
|
|
64
|
+
return (state.history || []).filter((e) => e && e.event === 'reentry-applied');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 事件 backup 字段 → 实际文件路径(相对 runRoot 的路径或仅文件名两种写法都接受)
|
|
68
|
+
function resolveReentryBackupPath(root, changeId, event) {
|
|
69
|
+
if (!event || typeof event.backup !== 'string' || event.backup.trim() === '') return null;
|
|
70
|
+
const raw = event.backup;
|
|
71
|
+
const candidates = path.isAbsolute(raw)
|
|
72
|
+
? [raw]
|
|
73
|
+
: [path.resolve(root, raw), path.join(reentryBackupDir(root, changeId), path.basename(raw))];
|
|
74
|
+
return candidates.find((p) => fs.existsSync(p)) || null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// ---------- 受控计划重校重签(replan)与强制推进留痕真实命令链路夹具(H9~H11 共用) ----------
|
|
78
|
+
|
|
79
|
+
// 任务集构造:基础串行任务(status 可切)+ 可追加的并行就绪任务(计划外修订用)
|
|
80
|
+
// + 可选的同文件跨任务对(第三族:两条串行任务写同一路径——并行形态会先被写写强判族命中,
|
|
81
|
+
// 串行拆分才是「同文件跨任务且无依赖路径」的判据面;crossTaskPair='deps' 时补显式 depends_on)。
|
|
82
|
+
function replanTaskText(options = {}) {
|
|
83
|
+
const lines = ['# TASK', '',
|
|
84
|
+
'<task id="S01" parallel="false" status="' + (options.s01Status || 'pending') + '">'
|
|
85
|
+
+ '<action>实现 S01</action><write_files>src/s01.mjs</write_files>'
|
|
86
|
+
+ '<verify>node --check src/s01.mjs</verify></task>'];
|
|
87
|
+
for (const id of options.parallelPending || []) {
|
|
88
|
+
lines.push('<task id="' + id + '" parallel="true" status="pending">'
|
|
89
|
+
+ '<action>实现计划外新增的 ' + id + '</action>'
|
|
90
|
+
+ '<write_files>src/' + id.toLowerCase() + '.mjs</write_files>'
|
|
91
|
+
+ '<verify>node --check src/' + id.toLowerCase() + '.mjs</verify></task>');
|
|
92
|
+
}
|
|
93
|
+
if (options.crossTaskPair) {
|
|
94
|
+
const deps = options.crossTaskPair === 'deps' ? '<depends_on>X1</depends_on>' : '';
|
|
95
|
+
lines.push('<task id="X1" parallel="false" status="pending">'
|
|
96
|
+
+ '<action>实现 X1</action><write_files>src/shared-cross.mjs</write_files>'
|
|
97
|
+
+ '<verify>node --check src/shared-cross.mjs</verify></task>');
|
|
98
|
+
lines.push('<task id="X2" parallel="false" status="pending">'
|
|
99
|
+
+ '<action>实现 X2</action><write_files>src/shared-cross.mjs</write_files>'
|
|
100
|
+
+ '<verify>node --check src/shared-cross.mjs</verify>' + deps + '</task>');
|
|
101
|
+
}
|
|
102
|
+
return lines.join('\n') + '\n';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// execute 已 entry 的真实链路前奏:#init → open/design 出口 → plan 出口 → 任务集 → record +
|
|
106
|
+
// entry execute(entry 真实记录任务集签名)。返回后调用方可修订任务集触发签名不匹配现场。
|
|
107
|
+
function seedExecuteEntryState(dir, taskText) {
|
|
108
|
+
driveThroughDesign(dir);
|
|
109
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', taskText);
|
|
110
|
+
assertExit(runState(['skill-load', 'plan', 'flow-comet-plan', '--prompt', 'flow-kit/prompts/3-task.md'], dir), 0);
|
|
111
|
+
assertExit(runState(['record', 'plan', '{"summary":"plan done"}'], dir), 0);
|
|
112
|
+
assertExit(runGuard(['entry', 'plan'], dir), 0);
|
|
113
|
+
const planExit = runGuard(['exit', 'plan', '--apply'], dir);
|
|
114
|
+
assertExit(planExit, 0);
|
|
115
|
+
assertNodeLine(planExit, 'execute');
|
|
116
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-dev', '--prompt', 'flow-kit/prompts/4-dev.md'], dir), 0);
|
|
117
|
+
assertExit(runState(['record', 'execute', '{"summary":"implementation recorded"}'], dir), 0);
|
|
118
|
+
assertExit(runGuard(['entry', 'execute'], dir), 0);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// 串行 pending 任务的真实委托留证(execute 归属:request + result 契约回传)
|
|
122
|
+
function completeSerialTaskWithHandoff(dir, taskId, writeFilesRel) {
|
|
123
|
+
assertExit(runHandoff(['request', taskId, taskId + ' 委托', '--write-files', writeFilesRel], dir), 0);
|
|
124
|
+
assertExit(runHandoff(['result', taskId, fullContract('abcd1234abcd1234abcd1234abcd1234abcd1234', taskId)], dir), 0);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// replan 备份清单(.specs/<id>/replan-backups/)
|
|
128
|
+
function replanBackupFiles(dir, changeId = CHANGE_ID) {
|
|
129
|
+
const backupDir = path.join(dir, '.specs', changeId, 'replan-backups');
|
|
130
|
+
return fs.existsSync(backupDir) ? fs.readdirSync(backupDir).sort() : [];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// replan-applied 事件过滤(轮次按 change 从 history 派生)
|
|
134
|
+
function replanEventsOf(state) {
|
|
135
|
+
return (state.history || []).filter((e) => e && e.event === 'replan-applied');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// status 输出的 JSON 块解析(命令行尾巴行不进 JSON)
|
|
139
|
+
|
|
140
|
+
export const ENTRIES = [
|
|
141
|
+
// ---------- H. verify 与归档 ----------
|
|
142
|
+
|
|
143
|
+
{
|
|
144
|
+
name: 'H1 verify:验证命令真实执行与超时配置',
|
|
145
|
+
run: (dir) => {
|
|
146
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
147
|
+
assertExit(runState(['skill-load', 'verify', 'flow-comet-integration', '--prompt', 'flow-kit/prompts/7-integration.md'], dir), 0);
|
|
148
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n通过\n');
|
|
149
|
+
assertExit(runState(['record', 'verify', '{"summary":"verified"}'], dir), 0);
|
|
150
|
+
const st = readStateFile(dir);
|
|
151
|
+
st.currentNode = 'verify';
|
|
152
|
+
writeState(dir, st);
|
|
153
|
+
// ① 快速命令 → 出口通过
|
|
154
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```bash\nnode -e "1"\n```\n');
|
|
155
|
+
assertExit(runGuard(['entry', 'verify'], dir), 0);
|
|
156
|
+
const pass = runGuard(['exit', 'verify'], dir);
|
|
157
|
+
assertExit(pass, 0);
|
|
158
|
+
assertOut(pass, 'ALL CHECKS PASSED');
|
|
159
|
+
// ② 缺省超时(未设 env)保持大值:耗时命令通过
|
|
160
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n## 验证命令\n\n```bash\nnode -e "setTimeout(()=>{}, 1500)"\n```\n');
|
|
161
|
+
const defaultTimeout = runGuard(['exit', 'verify'], dir);
|
|
162
|
+
assertExit(defaultTimeout, 0);
|
|
163
|
+
assertOut(defaultTimeout, 'ALL CHECKS PASSED');
|
|
164
|
+
// ③ 环境覆盖生效:小超时 → 超时拦截(不设 env 时同命令走缺省会通过——覆盖被忽略即红)
|
|
165
|
+
const timedOut = runGuard(['exit', 'verify'], dir, { FLOW_COMET_VERIFY_TIMEOUT_MS: '500' });
|
|
166
|
+
// 超时 kill 的 cmd 孙进程(node)孤儿化后短暂存活,其 cwd 锁定场景目录
|
|
167
|
+
// (Windows:父 cmd 被杀、孙进程继续跑完自身定时器)——断言前同步等待其自然退出
|
|
168
|
+
execFileSync(process.execPath, ['-e', 'setTimeout(()=>{}, 2000)']);
|
|
169
|
+
assertExit(timedOut, 1);
|
|
170
|
+
assertOut(timedOut, 'BLOCKED: verify 命令失败');
|
|
171
|
+
assertOut(timedOut, 'timeout 500ms');
|
|
172
|
+
// 子断言:失败计数按 change 写入(guard 侧)
|
|
173
|
+
const stTimed = readStateFile(dir);
|
|
174
|
+
if (!stTimed.verifyFailuresByChange || stTimed.verifyFailuresByChange[CHANGE_ID] < 1) {
|
|
175
|
+
throw new Error('exit verify 失败计数未按 change 写入: ' + JSON.stringify(stTimed.verifyFailuresByChange));
|
|
176
|
+
}
|
|
177
|
+
// ④ 无验证命令 → 拦截(严格版要求)
|
|
178
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md', '# TEST\n\n无验证命令段。\n');
|
|
179
|
+
const noCmd = runGuard(['exit', 'verify'], dir);
|
|
180
|
+
assertExit(noCmd, 1);
|
|
181
|
+
assertOut(noCmd, 'BLOCKED: TEST.md 需声明 ## 验证命令 段');
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
{
|
|
186
|
+
name: 'H2 归档:完整流程(遗留清单 + 移动 + 完成态)',
|
|
187
|
+
run: (dir) => {
|
|
188
|
+
assertExit(runState(['init', 'arch-demo'], dir), 0);
|
|
189
|
+
assertExit(runState(['skill-load', 'archive', 'flow-comet-integration', '--prompt', 'flow-kit/prompts/7-integration.md'], dir), 0);
|
|
190
|
+
// 节点推进到归档(模拟前序节点出口已完成的状态——被测机制是归档出口本身)
|
|
191
|
+
const st0 = readStateFile(dir);
|
|
192
|
+
st0.currentNode = 'archive';
|
|
193
|
+
writeState(dir, st0);
|
|
194
|
+
assertExit(runState(['record', 'archive', '{"summary":"archived"}'], dir), 0);
|
|
195
|
+
// ① 未移动(无归档目录)→ 出口拦截(缺归档产物)
|
|
196
|
+
assertExit(runGuard(['entry', 'archive'], dir), 0);
|
|
197
|
+
const blocked = runGuard(['exit', 'archive'], dir);
|
|
198
|
+
assertExit(blocked, 1);
|
|
199
|
+
assertOut(blocked, 'missing Output Schema artifacts');
|
|
200
|
+
// ② 遗留问题清单(显式无遗留)随工件写入
|
|
201
|
+
writeFile(dir, '.specs/arch-demo/KNOWN-ISSUES.md', '# KNOWN-ISSUES\n\n无遗留问题\n');
|
|
202
|
+
// ③ 移动目录到归档路径(真实归档流程:先移动后出口)
|
|
203
|
+
fs.mkdirSync(path.join(dir, '.specs', 'archive'), { recursive: true });
|
|
204
|
+
fs.renameSync(path.join(dir, '.specs', 'arch-demo'), path.join(dir, '.specs', 'archive', '2026-08-11-arch-demo'));
|
|
205
|
+
if (fs.existsSync(path.join(dir, '.specs', 'arch-demo'))) throw new Error('移动后源目录应不存在');
|
|
206
|
+
if (!fs.existsSync(path.join(dir, '.specs', 'archive', '2026-08-11-arch-demo', 'KNOWN-ISSUES.md'))) {
|
|
207
|
+
throw new Error('遗留问题清单应随工件归档');
|
|
208
|
+
}
|
|
209
|
+
// ④ 出口 --apply → 通过 + 归档完成态(清空活跃项目)
|
|
210
|
+
const pass = runGuard(['exit', 'archive', '--apply'], dir);
|
|
211
|
+
assertExit(pass, 0);
|
|
212
|
+
assertOut(pass, 'ALL CHECKS PASSED');
|
|
213
|
+
const st = readStateFile(dir);
|
|
214
|
+
if (st.activeChange !== null) throw new Error('归档后 activeChange 应为 null: ' + JSON.stringify(st.activeChange));
|
|
215
|
+
if (st.currentNode !== null) throw new Error('归档后 currentNode 应为 null');
|
|
216
|
+
if (st.status !== 'completed') throw new Error('归档后 status 应为 completed');
|
|
217
|
+
const status = runState(['status'], dir);
|
|
218
|
+
assertExit(status, 0);
|
|
219
|
+
assertOut(status, '"status": "no-change"');
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
{
|
|
224
|
+
name: 'H3 归档:归档路径声明标记查找',
|
|
225
|
+
run: (dir) => {
|
|
226
|
+
assertExit(runState(['init', 'arch-mk'], dir), 0);
|
|
227
|
+
writeFile(dir, 'flow-kit/prompts/0-change.md', '# 阶段 0 · CHANGE\n\n## 角色\n\n你是 Changeer。\n');
|
|
228
|
+
writeFile(dir, 'flow-kit/prompts/7-integration.md', '# 阶段 7 · INTEGRATION\n\n## 角色\n\n你是 Integrationer。\n');
|
|
229
|
+
// 遗留清单(协议 required 产物——随目录移动进归档)
|
|
230
|
+
writeFile(dir, '.specs/arch-mk/KNOWN-ISSUES.md', '# KNOWN-ISSUES\n\n无遗留问题\n');
|
|
231
|
+
// 归档前声明标记(open + archive 节点)
|
|
232
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
233
|
+
assertExit(runState(['skill-load', 'archive', 'flow-comet-integration', '--prompt', 'flow-kit/prompts/7-integration.md'], dir), 0);
|
|
234
|
+
// 节点推进到归档(模拟前序节点出口已完成的状态)
|
|
235
|
+
const st0 = readStateFile(dir);
|
|
236
|
+
st0.currentNode = 'archive';
|
|
237
|
+
writeState(dir, st0);
|
|
238
|
+
assertExit(runState(['record', 'archive', '{"summary":"archived"}'], dir), 0);
|
|
239
|
+
// 移动(标记随目录进入归档路径)
|
|
240
|
+
fs.mkdirSync(path.join(dir, '.specs', 'archive'), { recursive: true });
|
|
241
|
+
fs.renameSync(path.join(dir, '.specs', 'arch-mk'), path.join(dir, '.specs', 'archive', '2026-08-11-arch-mk'));
|
|
242
|
+
const markerInArchive = path.join(dir, '.specs', 'archive', '2026-08-11-arch-mk', '.skill-loads', 'archive-flow-comet-integration.json');
|
|
243
|
+
if (!fs.existsSync(markerInArchive)) throw new Error('声明标记应随目录移入归档路径');
|
|
244
|
+
// 出口:标记经归档路径解析命中(活动路径已不存在)→ 通过且无兼容警告
|
|
245
|
+
assertExit(runGuard(['entry', 'archive'], dir), 0);
|
|
246
|
+
const pass = runGuard(['exit', 'archive', '--apply'], dir);
|
|
247
|
+
assertExit(pass, 0);
|
|
248
|
+
assertOut(pass, 'ALL CHECKS PASSED');
|
|
249
|
+
assertNotOut(pass, 'SKILL-LOAD WARN');
|
|
250
|
+
assertNotOut(pass, 'exit 缺协议声明标记');
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
{
|
|
255
|
+
name: 'H4 归档:M5 自动补标记写归档路径,不重建活动目录',
|
|
256
|
+
run: (dir) => {
|
|
257
|
+
// 归档顺序(先移目录后 record)下,record archive 的 M5 自动补声明标记应写归档路径
|
|
258
|
+
// (.skill-loads/ 随目录移动),不得重建已归档的活动目录(归档移动语义)
|
|
259
|
+
assertExit(runState(['init', 'arch-m5'], dir), 0);
|
|
260
|
+
writeFile(dir, 'flow-kit/prompts/0-change.md', '# 阶段 0 · CHANGE\n\n## 角色\n\n你是 Changeer。\n');
|
|
261
|
+
writeFile(dir, 'flow-kit/prompts/7-integration.md', '# 阶段 7 · INTEGRATION\n\n## 角色\n\n你是 Integrationer。\n');
|
|
262
|
+
// 手动 skill-load(活动路径标记,随目录移动进归档)
|
|
263
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
264
|
+
assertExit(runState(['skill-load', 'archive', 'flow-comet-integration', '--prompt', 'flow-kit/prompts/7-integration.md'], dir), 0);
|
|
265
|
+
// 推进到 archive
|
|
266
|
+
const st0 = readStateFile(dir);
|
|
267
|
+
st0.currentNode = 'archive';
|
|
268
|
+
writeState(dir, st0);
|
|
269
|
+
// 移动目录到归档(真实归档流程:先移动后 record/exit)
|
|
270
|
+
fs.mkdirSync(path.join(dir, '.specs', 'archive'), { recursive: true });
|
|
271
|
+
fs.renameSync(path.join(dir, '.specs', 'arch-m5'), path.join(dir, '.specs', 'archive', '2026-08-14-arch-m5'));
|
|
272
|
+
// record archive(移动后)——M5 自动补 archive 声明标记
|
|
273
|
+
const rec = runState(['record', 'archive', '{"summary":"archived"}'], dir);
|
|
274
|
+
assertExit(rec, 0);
|
|
275
|
+
// 断言 1:活动目录不得重建(归档移动语义——M5 不得重建已归档的活动目录)
|
|
276
|
+
if (fs.existsSync(path.join(dir, '.specs', 'arch-m5'))) {
|
|
277
|
+
throw new Error('M5 在归档后重建了活动目录(残留): .specs/arch-m5/');
|
|
278
|
+
}
|
|
279
|
+
// 断言 2:归档路径有 M5 自动补的 archive 标记(标记随目录移动后的归属路径)
|
|
280
|
+
const markerInArchive = path.join(dir, '.specs', 'archive', '2026-08-14-arch-m5', '.skill-loads', 'archive-flow-comet-integration.json');
|
|
281
|
+
if (!fs.existsSync(markerInArchive)) {
|
|
282
|
+
throw new Error('归档路径缺 M5 自动补标记: ' + markerInArchive);
|
|
283
|
+
}
|
|
284
|
+
// 变体:change 从未 skill-load(活动与归档路径皆无 .skill-loads)→ record 不得重建
|
|
285
|
+
// 活动目录(修复前 targetLoadsDir 回退活动路径,writeJson 的 mkdir 会重建已归档目录)
|
|
286
|
+
assertExit(runState(['init', 'arch-m5b'], dir), 0);
|
|
287
|
+
assertExit(runState(['skill-load', 'archive', 'flow-comet-integration'], dir), 0);
|
|
288
|
+
const stB = readStateFile(dir);
|
|
289
|
+
stB.currentNode = 'archive';
|
|
290
|
+
writeState(dir, stB);
|
|
291
|
+
fs.renameSync(path.join(dir, '.specs', 'arch-m5b'), path.join(dir, '.specs', 'archive', '2026-08-14-arch-m5b'));
|
|
292
|
+
const recB = runState(['record', 'archive', '{"summary":"archived"}'], dir);
|
|
293
|
+
assertExit(recB, 0);
|
|
294
|
+
if (fs.existsSync(path.join(dir, '.specs', 'arch-m5b'))) {
|
|
295
|
+
throw new Error('M5 在双路径皆无时重建了活动目录(残留): .specs/arch-m5b/');
|
|
296
|
+
}
|
|
297
|
+
// 变体:归档后 skill-load 报错须引导 record 自动补路径(真实会话实证:归档后手动声明
|
|
298
|
+
// 不可行,消息须指明 M5 自动补仍可写归档路径标记)
|
|
299
|
+
const slArchive = runState(['skill-load', 'archive', 'flow-comet-integration'], dir);
|
|
300
|
+
assertExit(slArchive, 1);
|
|
301
|
+
assertOut(slArchive, 'record 自动补写');
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
|
|
305
|
+
// ---------- H5~H8: archive 源受控重入真实命令链路 ----------
|
|
306
|
+
|
|
307
|
+
{
|
|
308
|
+
name: 'H5 受控重入:未授权调用 fail-closed 且 state 字节零改写',
|
|
309
|
+
run: (dir) => {
|
|
310
|
+
seedArchiveEntryState(dir);
|
|
311
|
+
const before = readStateBytes(dir);
|
|
312
|
+
// ② 未授权(缺 --authorized-by)→ 非零退出 + 授权形态指引 + 零改写
|
|
313
|
+
const noAuth = runState(['reenter', 'verify', '--reason', '归档后发现缺陷'], dir);
|
|
314
|
+
assertExit(noAuth, 1);
|
|
315
|
+
assertOut(noAuth, 'reenter');
|
|
316
|
+
assertOut(noAuth, 'authorized-by');
|
|
317
|
+
if (!readStateBytes(dir).equals(before)) throw new Error('未授权调用改写了 state 字节');
|
|
318
|
+
if (reentryBackupFiles(dir).length !== 0) {
|
|
319
|
+
throw new Error('未授权调用产生了备份: ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
320
|
+
}
|
|
321
|
+
// ② 授权源为纯空白 → 同样 fail-closed 且零改写
|
|
322
|
+
const blankAuth = runState(['reenter', 'verify', '--authorized-by', ' ', '--reason', 'x'], dir);
|
|
323
|
+
assertExit(blankAuth, 1);
|
|
324
|
+
if (!readStateBytes(dir).equals(before)) throw new Error('空白授权源调用改写了 state 字节');
|
|
325
|
+
const st = readStateFile(dir);
|
|
326
|
+
if (st.currentNode !== 'archive') throw new Error('未授权调用改写了 currentNode: ' + JSON.stringify(st.currentNode));
|
|
327
|
+
if (reentryEventsOf(st).length !== 0) throw new Error('未授权调用写入了 reentry-applied 事件');
|
|
328
|
+
},
|
|
329
|
+
},
|
|
330
|
+
|
|
331
|
+
{
|
|
332
|
+
name: 'H6 受控重入:完整授权链路(转移+嵌套证据+审计事件+备份指纹+审计行)',
|
|
333
|
+
run: (dir) => {
|
|
334
|
+
seedArchiveEntryState(dir);
|
|
335
|
+
const beforeState = readStateFile(dir);
|
|
336
|
+
const res = runState(['reenter', 'verify', '--authorized-by', '用户裁决', '--reason', '归档后发现验证缺口'], dir);
|
|
337
|
+
assertExit(res, 0);
|
|
338
|
+
const st = readStateFile(dir);
|
|
339
|
+
// ③ 转移语义:currentNode = 目标、completedNodes = 前驱交集、status = running
|
|
340
|
+
if (st.currentNode !== 'verify') throw new Error('重入后 currentNode 应为 verify: ' + JSON.stringify(st.currentNode));
|
|
341
|
+
if (JSON.stringify(st.completedNodes) !== JSON.stringify(REENTRY_VERIFY_PREDECESSORS)) {
|
|
342
|
+
throw new Error('重入后 completedNodes 应为 verify 前驱交集 ' + JSON.stringify(REENTRY_VERIFY_PREDECESSORS)
|
|
343
|
+
+ ',实际 ' + JSON.stringify(st.completedNodes));
|
|
344
|
+
}
|
|
345
|
+
if (st.status !== 'running') throw new Error('重入后 status 应为 running: ' + JSON.stringify(st.status));
|
|
346
|
+
// ③ 授权嵌套记录(evidence.<目标节点>.reentryAuthorization)
|
|
347
|
+
const auth = st.evidence && st.evidence.verify ? st.evidence.verify.reentryAuthorization : null;
|
|
348
|
+
if (!auth || typeof auth !== 'object') {
|
|
349
|
+
throw new Error('缺 evidence.verify.reentryAuthorization: ' + JSON.stringify(st.evidence));
|
|
350
|
+
}
|
|
351
|
+
if (auth.round !== 1 || auth.target !== 'verify' || auth.source !== '用户裁决') {
|
|
352
|
+
throw new Error('授权记录形态不符: ' + JSON.stringify(auth));
|
|
353
|
+
}
|
|
354
|
+
if (typeof auth.at !== 'string' || auth.at.trim() === '') throw new Error('授权记录缺 at: ' + JSON.stringify(auth));
|
|
355
|
+
// ③ 审计事件——change 必填(轮次按 change 隔离)
|
|
356
|
+
const events = reentryEventsOf(st);
|
|
357
|
+
if (events.length !== 1) throw new Error('应恰一条 reentry-applied 事件: ' + JSON.stringify(events));
|
|
358
|
+
const ev = events[0];
|
|
359
|
+
if (ev.from !== 'archive' || ev.to !== 'verify' || ev.round !== 1 || ev.change !== CHANGE_ID) {
|
|
360
|
+
throw new Error('reentry-applied 事件字段不符: ' + JSON.stringify(ev));
|
|
361
|
+
}
|
|
362
|
+
if (!ev.authorization || ev.authorization.source !== '用户裁决' || ev.authorization.round !== 1) {
|
|
363
|
+
throw new Error('事件 authorization 不符: ' + JSON.stringify(ev.authorization));
|
|
364
|
+
}
|
|
365
|
+
if (typeof ev.at !== 'string' || ev.at.trim() === '') throw new Error('事件缺 at: ' + JSON.stringify(ev));
|
|
366
|
+
// ③ 备份在场 + 指纹与文件 sha256 一致 + 全量快照语义(AC-9)
|
|
367
|
+
const backupPath = resolveReentryBackupPath(dir, CHANGE_ID, ev);
|
|
368
|
+
if (!backupPath) throw new Error('事件 backup 指向的备份文件不在场: ' + JSON.stringify(ev.backup));
|
|
369
|
+
if (!/-pre-verify\.json$/.test(backupPath)) {
|
|
370
|
+
throw new Error('备份命名应为 <UTC ISO>-pre-<target>.json: ' + backupPath);
|
|
371
|
+
}
|
|
372
|
+
const backupBytes = fs.readFileSync(backupPath);
|
|
373
|
+
const backupState = JSON.parse(backupBytes.toString('utf8'));
|
|
374
|
+
if (backupState.currentNode !== beforeState.currentNode || backupState.status !== beforeState.status
|
|
375
|
+
|| JSON.stringify(backupState.completedNodes) !== JSON.stringify(beforeState.completedNodes)) {
|
|
376
|
+
throw new Error('备份应为重入前 state 全量快照: ' + JSON.stringify(backupState));
|
|
377
|
+
}
|
|
378
|
+
if (reentryEventsOf(backupState).length !== 0) throw new Error('备份不应含本次重入事件');
|
|
379
|
+
const fingerprint = createHash('sha256').update(backupBytes).digest('hex');
|
|
380
|
+
const recorded = String(ev.fingerprint || '').toLowerCase().replace(/^sha256:/, '');
|
|
381
|
+
if (recorded !== fingerprint) {
|
|
382
|
+
throw new Error('事件指纹与备份文件 sha256 不一致: ' + JSON.stringify(ev.fingerprint) + ' vs ' + fingerprint);
|
|
383
|
+
}
|
|
384
|
+
// ④ 审计行:REENTRY 前缀 + 来源 archive + 目标 + 轮次 n/3 + 备份路径
|
|
385
|
+
assertOut(res, 'REENTRY');
|
|
386
|
+
assertOut(res, 'archive');
|
|
387
|
+
assertOut(res, 'verify');
|
|
388
|
+
assertOut(res, '1/3');
|
|
389
|
+
assertOut(res, path.basename(backupPath));
|
|
390
|
+
const backups = reentryBackupFiles(dir);
|
|
391
|
+
if (backups.length !== 1) throw new Error('成功重入应恰一份备份: ' + JSON.stringify(backups));
|
|
392
|
+
},
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
{
|
|
396
|
+
name: 'H7 受控重入:幂等重放零改写与按备份手工回滚可执行',
|
|
397
|
+
run: (dir) => {
|
|
398
|
+
seedArchiveEntryState(dir);
|
|
399
|
+
const first = runState(['reenter', 'verify', '--authorized-by', '用户裁决', '--reason', '首次重入'], dir);
|
|
400
|
+
assertExit(first, 0);
|
|
401
|
+
const afterFirst = readStateBytes(dir);
|
|
402
|
+
const ev = reentryEventsOf(readStateFile(dir))[0];
|
|
403
|
+
const backupPath = resolveReentryBackupPath(dir, CHANGE_ID, ev);
|
|
404
|
+
if (!backupPath) throw new Error('首次重入后缺备份文件: ' + JSON.stringify(ev));
|
|
405
|
+
// ⑤ 幂等重放:同目标再调用 → 空操作(state 字节零改写、不新增备份/事件)
|
|
406
|
+
const replay = runState(['reenter', 'verify', '--authorized-by', '用户裁决', '--reason', '重复调用'], dir);
|
|
407
|
+
assertExit(replay, 0);
|
|
408
|
+
if (!readStateBytes(dir).equals(afterFirst)) throw new Error('幂等重放改写了 state 字节');
|
|
409
|
+
if (reentryEventsOf(readStateFile(dir)).length !== 1) throw new Error('幂等重放重复写入 reentry-applied 事件');
|
|
410
|
+
if (reentryBackupFiles(dir).length !== 1) {
|
|
411
|
+
throw new Error('幂等重放新增了备份: ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
412
|
+
}
|
|
413
|
+
// ⑦ 手工回滚(AC-9):按备份文件覆盖 → status 可读且语义回到重入前
|
|
414
|
+
const backupBytes = fs.readFileSync(backupPath);
|
|
415
|
+
fs.writeFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), backupBytes);
|
|
416
|
+
const status = runState(['status'], dir);
|
|
417
|
+
assertExit(status, 0);
|
|
418
|
+
assertOut(status, '"stateCurrentNode": "archive"');
|
|
419
|
+
assertOut(status, '"change": "' + CHANGE_ID + '"');
|
|
420
|
+
const restored = readStateFile(dir);
|
|
421
|
+
if (restored.currentNode !== 'archive') throw new Error('回滚后 currentNode 未回到 archive: ' + JSON.stringify(restored.currentNode));
|
|
422
|
+
if (JSON.stringify(restored.completedNodes) !== JSON.stringify(ARCHIVE_ENTRY_COMPLETED_NODES)) {
|
|
423
|
+
throw new Error('回滚后 completedNodes 未回到重入前形态: ' + JSON.stringify(restored.completedNodes));
|
|
424
|
+
}
|
|
425
|
+
if (reentryEventsOf(restored).length !== 0) throw new Error('回滚后不应残留本次 reentry-applied 事件');
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
|
|
429
|
+
{
|
|
430
|
+
name: 'H8 受控重入:上限 BLOCK、显式授权续轮与重入后闭环组合链路(真实命令)',
|
|
431
|
+
run: (dir) => {
|
|
432
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
433
|
+
const gateMarker = path.join(dir, 'verify-gate-ran.txt');
|
|
434
|
+
seedArchiveEntryState(dir);
|
|
435
|
+
// 真实链路跑满 3 轮:每轮成功后把归属重置回 archive 已 entry 形态(模拟流程再次归档进入),
|
|
436
|
+
// history 事件保留——轮次按 change 从事件派生
|
|
437
|
+
for (let round = 1; round <= 3; round += 1) {
|
|
438
|
+
const res = runState(['reenter', 'verify', '--authorized-by', '用户裁决', '--reason', '第 ' + round + ' 轮'], dir);
|
|
439
|
+
assertExit(res, 0);
|
|
440
|
+
if (reentryEventsOf(readStateFile(dir)).length !== round) {
|
|
441
|
+
throw new Error('第 ' + round + ' 轮后 reentry-applied 事件数应为 ' + round);
|
|
442
|
+
}
|
|
443
|
+
const st = readStateFile(dir);
|
|
444
|
+
st.currentNode = 'archive';
|
|
445
|
+
st.completedNodes = ARCHIVE_ENTRY_COMPLETED_NODES.slice();
|
|
446
|
+
st.status = 'running';
|
|
447
|
+
writeState(dir, st);
|
|
448
|
+
}
|
|
449
|
+
if (reentryBackupFiles(dir).length !== 3) {
|
|
450
|
+
throw new Error('三轮应产生三份备份: ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
451
|
+
}
|
|
452
|
+
const beforeFourth = readStateBytes(dir);
|
|
453
|
+
// ⑥ 第 4 次 → BLOCK + 人工裁决指引(继续 / 停止)+ state 字节零改写
|
|
454
|
+
const fourth = runState(['reenter', 'execute', '--authorized-by', '用户裁决', '--reason', '第 4 轮'], dir);
|
|
455
|
+
assertExit(fourth, 1);
|
|
456
|
+
assertOut(fourth, 'BLOCK');
|
|
457
|
+
assertOut(fourth, '继续');
|
|
458
|
+
assertOut(fourth, '停止');
|
|
459
|
+
if (!readStateBytes(dir).equals(beforeFourth)) throw new Error('超上限调用改写了 state 字节');
|
|
460
|
+
if (reentryEventsOf(readStateFile(dir)).length !== 3) throw new Error('超上限调用写入了 reentry-applied 事件');
|
|
461
|
+
if (reentryBackupFiles(dir).length !== 3) {
|
|
462
|
+
throw new Error('超上限调用新增了备份: ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
463
|
+
}
|
|
464
|
+
// ⑦ 上限判定先于空操作短路:同目标形态 + 3 条本 change 事件 → 仍 BLOCK 零改写
|
|
465
|
+
{
|
|
466
|
+
const capped = readStateFile(dir);
|
|
467
|
+
capped.currentNode = 'verify';
|
|
468
|
+
capped.completedNodes = REENTRY_VERIFY_PREDECESSORS.slice();
|
|
469
|
+
writeState(dir, capped);
|
|
470
|
+
const cappedBytes = readStateBytes(dir);
|
|
471
|
+
const sameTarget = runState(['reenter', 'verify', '--authorized-by', '用户裁决', '--reason', '超限同目标重放'], dir);
|
|
472
|
+
assertExit(sameTarget, 1);
|
|
473
|
+
assertOut(sameTarget, 'BLOCK');
|
|
474
|
+
assertOut(sameTarget, '继续');
|
|
475
|
+
assertNotOut(sameTarget, '空操作');
|
|
476
|
+
if (!readStateBytes(dir).equals(cappedBytes)) throw new Error('超限同目标形态改写了 state 字节');
|
|
477
|
+
if (reentryEventsOf(readStateFile(dir)).length !== 3) throw new Error('超限同目标形态写入了 reentry-applied 事件');
|
|
478
|
+
const reset = readStateFile(dir);
|
|
479
|
+
reset.currentNode = 'archive';
|
|
480
|
+
reset.completedNodes = ARCHIVE_ENTRY_COMPLETED_NODES.slice();
|
|
481
|
+
reset.status = 'running';
|
|
482
|
+
writeState(dir, reset);
|
|
483
|
+
}
|
|
484
|
+
// ⑧ 续轮授权不足(授权轮次 < 已用 + 1)→ BLOCK 零改写:上限裁决点不可被残缺授权绕过
|
|
485
|
+
{
|
|
486
|
+
const insufficientBytes = readStateBytes(dir);
|
|
487
|
+
const insufficient = runState(['reenter', 'verify', '--authorized-by', '用户授权', '--reason', '轮次不足', '--continue-round', '3'], dir);
|
|
488
|
+
assertExit(insufficient, 1);
|
|
489
|
+
assertOut(insufficient, 'BLOCK');
|
|
490
|
+
if (!readStateBytes(dir).equals(insufficientBytes)) throw new Error('续轮授权轮次不足改写了 state 字节');
|
|
491
|
+
}
|
|
492
|
+
// ⑨ 上限后的显式授权续轮(AC-7 后半句)→ 放行并计第 4 轮:审计事件 / 嵌套授权留痕带续轮
|
|
493
|
+
// 标记与原因,备份链新增一份
|
|
494
|
+
const continued = runState(['reenter', 'verify', '--authorized-by', '用户授权续轮', '--reason', '第 4 轮显式授权续轮', '--continue-round', '4'], dir);
|
|
495
|
+
assertExit(continued, 0);
|
|
496
|
+
assertOut(continued, 'REENTRY');
|
|
497
|
+
assertOut(continued, '续轮');
|
|
498
|
+
assertOut(continued, '4');
|
|
499
|
+
const continuedState = readStateFile(dir);
|
|
500
|
+
if (continuedState.currentNode !== 'verify') {
|
|
501
|
+
throw new Error('续轮放行后 currentNode 应为 verify: ' + JSON.stringify(continuedState.currentNode));
|
|
502
|
+
}
|
|
503
|
+
const continuedEvents = reentryEventsOf(continuedState);
|
|
504
|
+
const continuedEvent = continuedEvents[continuedEvents.length - 1];
|
|
505
|
+
if (!continuedEvent || continuedEvent.round !== 4 || continuedEvent.change !== CHANGE_ID
|
|
506
|
+
|| continuedEvent.continuationAuthorized !== true
|
|
507
|
+
|| continuedEvent.reason !== '第 4 轮显式授权续轮') {
|
|
508
|
+
throw new Error('续轮审计事件字段不符(round=4 / change / 续轮标记 / reason): ' + JSON.stringify(continuedEvent));
|
|
509
|
+
}
|
|
510
|
+
if (continuedState.evidence?.verify?.reentryAuthorization?.continuationAuthorized !== true) {
|
|
511
|
+
throw new Error('续轮授权留痕缺失: ' + JSON.stringify(continuedState.evidence?.verify));
|
|
512
|
+
}
|
|
513
|
+
if (reentryBackupFiles(dir).length !== 4) {
|
|
514
|
+
throw new Error('续轮放行应新增一份备份(共 4 份): ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
515
|
+
}
|
|
516
|
+
// ⑩ 组合真实链路(AC-8):续轮后的 verify 驻留态 → 追加 pending 修复任务 → 受控归位
|
|
517
|
+
// execute → 执行家族四类出口真实执行 → 回源 verify 出口真实执行(验证命令副作用)→ archive
|
|
518
|
+
writeIntakeArtifacts(dir);
|
|
519
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
|
|
520
|
+
'# DESIGN\n\n- **Change ID**: ' + CHANGE_ID + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
|
|
521
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTaskText('pending'));
|
|
522
|
+
// 段内大写 Z 形态的 SUMMARY(方法声明在其后):该出口的 exit 0 即「段尾判定正确」的真实链路锚
|
|
523
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', execSummaryWithMachineMarker('T01'));
|
|
524
|
+
// 源节点前序产物齐备:REVIEW.md 在场(已处置)——否则回源 verify 出口后的产物推导会把
|
|
525
|
+
// 下一跳判回 review(产物即真相),组合链路的终点断言无法到达 archive。
|
|
526
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', fixBatchReviewDoc(true));
|
|
527
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TEST.md',
|
|
528
|
+
'# TEST\n\n## 验证命令\n\n```\nnode -e "require(\'fs\').writeFileSync(\'verify-gate-ran.txt\', \'GATE-RAN\')"\n```\n');
|
|
529
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UAT.md', '# UAT\n\n## 验收\n\n- 通过\n');
|
|
530
|
+
// 受控归位:next 检出 pending 修复任务 → FIX-BATCH 归位 execute(真实写盘)
|
|
531
|
+
const reposition = runState(['next'], dir, env);
|
|
532
|
+
assertExit(reposition, 0);
|
|
533
|
+
assertOut(reposition, 'FIX-BATCH: 归位 execute(源节点 verify)');
|
|
534
|
+
assertNodeLine(reposition, 'execute');
|
|
535
|
+
let chainState = readStateFile(dir);
|
|
536
|
+
if (chainState.currentNode !== 'execute') {
|
|
537
|
+
throw new Error('受控归位后 currentNode 应为 execute: ' + JSON.stringify(chainState.currentNode));
|
|
538
|
+
}
|
|
539
|
+
if (chainState.completedNodes.includes('verify')) {
|
|
540
|
+
throw new Error('受控归位不得把源节点标完成: ' + JSON.stringify(chainState.completedNodes));
|
|
541
|
+
}
|
|
542
|
+
// 完成修复任务(标 done + 逐任务 SUMMARY + 重载声明 + record execute)
|
|
543
|
+
completeFixTaskAndRecord(dir, env);
|
|
544
|
+
// execute 家族四类出口真实跑通:全任务 done / 逐任务 SUMMARY / 六段自查与自检方法 / 任务集签名
|
|
545
|
+
const execExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
546
|
+
assertExit(execExit, 0);
|
|
547
|
+
assertOut(execExit, 'ALL CHECKS PASSED');
|
|
548
|
+
// 段尾判定锚(新 / 旧 change 两态都不许出现该拦因):T01 的 6 维自查段内大写 Z 在方法声明
|
|
549
|
+
// **之前**——段体若把大写 Z 当串尾而提前收尾,该出口会报「6 维自查未声明使用」(新 change
|
|
550
|
+
// BLOCK / 旧 change 同句 WARN),本条对两态都构成判别。
|
|
551
|
+
assertNotOut(execExit, '6 维自查未声明使用');
|
|
552
|
+
assertOut(execExit, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
553
|
+
assertNodeLine(execExit, 'verify');
|
|
554
|
+
assertNotNodeLine(execExit, 'archive');
|
|
555
|
+
chainState = readStateFile(dir);
|
|
556
|
+
if (chainState.currentNode !== 'verify' || chainState.completedNodes.includes('verify')) {
|
|
557
|
+
throw new Error('回源后应停在未完成的 verify: ' + JSON.stringify({ node: chainState.currentNode, completed: chainState.completedNodes }));
|
|
558
|
+
}
|
|
559
|
+
if (!fs.existsSync(path.join(dir, '.specs', CHANGE_ID, 'T01-SUMMARY.md'))
|
|
560
|
+
|| !fs.existsSync(path.join(dir, '.specs', CHANGE_ID, 'T-FIX-01-SUMMARY.md'))) {
|
|
561
|
+
throw new Error('逐任务 SUMMARY 必须在场(execute 家族出口之一)');
|
|
562
|
+
}
|
|
563
|
+
for (const summaryName of ['T01-SUMMARY.md', 'T-FIX-01-SUMMARY.md']) {
|
|
564
|
+
const summaryText = fs.readFileSync(path.join(dir, '.specs', CHANGE_ID, summaryName), 'utf8');
|
|
565
|
+
if (!/##\s*6 维自查/.test(summaryText) || !/##\s*自检方法/.test(summaryText)) {
|
|
566
|
+
throw new Error(summaryName + ' 缺六维自查 / 自检方法段(execute 家族出口之一)');
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
// 夹具形态自证(判别力前提 · 抽掉必报的反面):T01 的 6 维自查段内「大写 Z 说明行」必须
|
|
570
|
+
// **早于**方法声明、且两者都在该段内——否则上面那次出口放行与该段尾判定无关,锚会静默
|
|
571
|
+
// 退化成假绿(形态不符即抛错,不静默跳过)。
|
|
572
|
+
const t01SummaryText = fs.readFileSync(path.join(dir, '.specs', CHANGE_ID, 'T01-SUMMARY.md'), 'utf8');
|
|
573
|
+
const sixDimAt = t01SummaryText.indexOf('## 6 维自查');
|
|
574
|
+
const nextSectionAt = sixDimAt >= 0 ? t01SummaryText.indexOf('\n## ', sixDimAt) : -1;
|
|
575
|
+
const zMarkerAt = sixDimAt >= 0 ? t01SummaryText.indexOf('ZERO-LOGIC-CHANGE-OK', sixDimAt) : -1;
|
|
576
|
+
const declaredAt = sixDimAt >= 0 ? t01SummaryText.indexOf('brooks-review', sixDimAt) : -1;
|
|
577
|
+
if (!(sixDimAt >= 0 && zMarkerAt > sixDimAt && declaredAt > zMarkerAt
|
|
578
|
+
&& (nextSectionAt === -1 || declaredAt < nextSectionAt))) {
|
|
579
|
+
throw new Error('T01-SUMMARY 的 6 维自查段须为「大写 Z 说明行在前、方法声明行在后」形态(段尾判定锚的判别力前提): '
|
|
580
|
+
+ JSON.stringify({ sixDimAt, zMarkerAt, declaredAt, nextSectionAt }));
|
|
581
|
+
}
|
|
582
|
+
const execEvent = (chainState.history || [])
|
|
583
|
+
.filter((e) => e.event === 'exit-applied' && e.node === 'execute')
|
|
584
|
+
.pop();
|
|
585
|
+
if (!execEvent || !/^v1:[0-9a-f]{64}$/.test(String(execEvent.taskSetSignature || ''))) {
|
|
586
|
+
throw new Error('execute 家族出口必须记录任务集签名(出口之一): ' + JSON.stringify(execEvent));
|
|
587
|
+
}
|
|
588
|
+
if (!chainState.evidence?.execute?.summary) {
|
|
589
|
+
throw new Error('execute 出口证据缺失: ' + JSON.stringify(chainState.evidence?.execute));
|
|
590
|
+
}
|
|
591
|
+
// 源节点(verify)出口真实重跑:验证命令落盘副作用 + 推进 archive
|
|
592
|
+
assertExit(runState(['skill-load', 'verify', 'flow-comet-verify', '--prompt', 'flow-kit/prompts/7-integration.md'], dir, env), 0);
|
|
593
|
+
assertExit(runState(['record', 'verify', '{"summary":"回源复验完成"}'], dir, env), 0);
|
|
594
|
+
assertExit(runGuard(['entry', 'verify'], dir, env), 0);
|
|
595
|
+
const verifyExit = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
596
|
+
assertExit(verifyExit, 0);
|
|
597
|
+
assertOut(verifyExit, 'ALL CHECKS PASSED');
|
|
598
|
+
assertNodeLine(verifyExit, 'archive');
|
|
599
|
+
if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
|
|
600
|
+
throw new Error('回源 verify 出口未真实执行 TEST.md 验证命令(副作用文件缺失/内容不符)');
|
|
601
|
+
}
|
|
602
|
+
const finalState = readStateFile(dir);
|
|
603
|
+
if (finalState.currentNode !== 'archive' || !finalState.completedNodes.includes('verify')) {
|
|
604
|
+
throw new Error('组合链路终点应为 archive 且 verify 已完成: ' + JSON.stringify({ node: finalState.currentNode, completed: finalState.completedNodes }));
|
|
605
|
+
}
|
|
606
|
+
if (reentryEventsOf(finalState).length !== 4) {
|
|
607
|
+
throw new Error('组合链路不得丢失重入审计事件(应为 4 条): ' + reentryEventsOf(finalState).length);
|
|
608
|
+
}
|
|
609
|
+
if (reentryBackupFiles(dir).length !== 4) {
|
|
610
|
+
throw new Error('组合链路不得新增 / 丢失备份(应为 4 份): ' + JSON.stringify(reentryBackupFiles(dir)));
|
|
611
|
+
}
|
|
612
|
+
},
|
|
613
|
+
},
|
|
614
|
+
|
|
615
|
+
// ---------- H9~H11: 受控计划重校重签(replan)与强制推进留痕真实命令链路 ----------
|
|
616
|
+
|
|
617
|
+
{
|
|
618
|
+
name: 'H9 replan 解死锁:execute 相位修订任务集(含并行就绪任务)→ 重签 → 出口放行 → next 正常路由',
|
|
619
|
+
run: (dir) => {
|
|
620
|
+
seedExecuteEntryState(dir, replanTaskText());
|
|
621
|
+
// 真实委托留证(串行 pending → execute 归属)→ SUMMARY 齐备,出口四类校验可通过
|
|
622
|
+
completeSerialTaskWithHandoff(dir, 'S01', 'src/s01.mjs');
|
|
623
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/S01-SUMMARY.md', execSummaryFixture('S01'));
|
|
624
|
+
// 任务集修订(死锁现场):原任务完成 + 计划外新增的并行就绪任务
|
|
625
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', replanTaskText({ s01Status: 'done', parallelPending: ['P02'] }));
|
|
626
|
+
const beforeBytes = readStateBytes(dir);
|
|
627
|
+
// ① 前进被签名门禁挡住:exit execute → BLOCKED(任务集被修改)+ 零改写
|
|
628
|
+
const blocked = runGuard(['exit', 'execute', '--apply'], dir);
|
|
629
|
+
assertExit(blocked, 1);
|
|
630
|
+
assertOut(blocked, 'BLOCKED');
|
|
631
|
+
assertOut(blocked, '签名不匹配');
|
|
632
|
+
if (!readStateBytes(dir).equals(beforeBytes)) throw new Error('签名门禁 BLOCK 改写了 state 字节');
|
|
633
|
+
// ② 受控重校重签(唯一合规出口):授权 + 原因 + 重签 + 双写留痕 + 备份
|
|
634
|
+
const replan = runState(['replan', '计划有缺陷:新增并行任务 P02', '--authorized-by', '用户裁决'], dir);
|
|
635
|
+
assertExit(replan, 0);
|
|
636
|
+
assertOut(replan, 'REPLAN');
|
|
637
|
+
const st = readStateFile(dir);
|
|
638
|
+
const events = replanEventsOf(st);
|
|
639
|
+
if (events.length !== 1 || events[0].change !== CHANGE_ID || events[0].node !== 'execute') {
|
|
640
|
+
throw new Error('replan-applied 审计事件不符: ' + JSON.stringify(events));
|
|
641
|
+
}
|
|
642
|
+
if (!st.evidence || !st.evidence.execute || !st.evidence.execute.replanAuthorization) {
|
|
643
|
+
throw new Error('缺 evidence.execute.replanAuthorization 授权留痕: ' + JSON.stringify(st.evidence));
|
|
644
|
+
}
|
|
645
|
+
if (replanBackupFiles(dir).length !== 1) {
|
|
646
|
+
throw new Error('重签应恰产生一份备份: ' + JSON.stringify(replanBackupFiles(dir)));
|
|
647
|
+
}
|
|
648
|
+
// ③ 同一出口再跑 → 放行(不再报签名不匹配),路由到委托节点(并行就绪任务)
|
|
649
|
+
const exitRes = runGuard(['exit', 'execute', '--apply'], dir);
|
|
650
|
+
assertExit(exitRes, 0);
|
|
651
|
+
assertOut(exitRes, 'ALL CHECKS PASSED');
|
|
652
|
+
assertNodeLine(exitRes, 'subagent-execute');
|
|
653
|
+
// ④ next 正常路由(死锁解除后可继续推进)
|
|
654
|
+
const next = runState(['next'], dir);
|
|
655
|
+
assertExit(next, 0);
|
|
656
|
+
assertNodeLine(next, 'subagent-execute');
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
|
|
660
|
+
{
|
|
661
|
+
name: 'H10 replan 授权 fail-closed 与轮次上限:未授权零改写 · 同文件跨任务族分级拦截与恢复 · 第 4 次 BLOCK · 显式续轮放行(真实命令)',
|
|
662
|
+
run: (dir) => {
|
|
663
|
+
seedExecuteEntryState(dir, replanTaskText());
|
|
664
|
+
// 修订任务集 → 进入「签名不匹配」的适用现场
|
|
665
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', replanTaskText({ parallelPending: ['P01'] }));
|
|
666
|
+
const beforeBytes = readStateBytes(dir);
|
|
667
|
+
// ① 缺授权 / 空授权 / 纯空白授权 / 缺原因 → BLOCKED 且 state 字节零改写、零备份、零事件
|
|
668
|
+
const blockedCalls = [
|
|
669
|
+
['缺 --authorized-by', ['replan', '计划有缺陷:新增并行任务 P01']],
|
|
670
|
+
['--authorized-by 空串', ['replan', '计划有缺陷:新增并行任务 P01', '--authorized-by', '']],
|
|
671
|
+
['--authorized-by 纯空白', ['replan', '计划有缺陷:新增并行任务 P01', '--authorized-by', ' ']],
|
|
672
|
+
['缺位置 reason', ['replan', '--authorized-by', '用户裁决']],
|
|
673
|
+
];
|
|
674
|
+
for (const [label, args] of blockedCalls) {
|
|
675
|
+
const res = runState(args, dir);
|
|
676
|
+
assertExit(res, 1);
|
|
677
|
+
assertOut(res, 'BLOCKED');
|
|
678
|
+
if (!readStateBytes(dir).equals(beforeBytes)) throw new Error(label + ':改写了 state 字节');
|
|
679
|
+
}
|
|
680
|
+
if (replanBackupFiles(dir).length !== 0) {
|
|
681
|
+
throw new Error('未授权调用产生了备份: ' + JSON.stringify(replanBackupFiles(dir)));
|
|
682
|
+
}
|
|
683
|
+
if (replanEventsOf(readStateFile(dir)).length !== 0) {
|
|
684
|
+
throw new Error('未授权调用写入了 replan-applied 事件');
|
|
685
|
+
}
|
|
686
|
+
// ② 真实链路跑满 3 轮(每轮重新修订任务集 → 重签;轮次按 change 从事件派生)。第 1 轮以
|
|
687
|
+
// 「同文件跨任务且无依赖路径」的修订开场,逐档验证 replan 与 plan 出口同族的分级消费:
|
|
688
|
+
// 旧 change 形态仅 WARN 且照常重签(渐进不卡死)→ 新 change 形态 BLOCK 且状态零改写
|
|
689
|
+
// (BLOCK 早于备份与任何写盘:零新增备份、零新增事件、state 字节不变)→ 按恢复指引补显式
|
|
690
|
+
// depends_on 后复签通过(同一通道,不做校验豁免)。
|
|
691
|
+
const parallelIds = ['P01', 'P02', 'P03', 'P04'];
|
|
692
|
+
const oldChangeState = readStateFile(dir);
|
|
693
|
+
delete oldChangeState.newChange;
|
|
694
|
+
writeState(dir, oldChangeState);
|
|
695
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
696
|
+
replanTaskText({ parallelPending: ['P01'], crossTaskPair: 'no-deps' }));
|
|
697
|
+
const crossWarn = runState(['replan', '计划缺陷重校 1(旧 change 形态)', '--authorized-by', '用户裁决'], dir);
|
|
698
|
+
assertExit(crossWarn, 0);
|
|
699
|
+
assertOut(crossWarn, 'REPLAN');
|
|
700
|
+
assertOut(crossWarn, 'WARN: TASK.md 同文件跨任务且无依赖路径');
|
|
701
|
+
assertOut(crossWarn, 'X1×X2(src/shared-cross.mjs)');
|
|
702
|
+
assertNotOut(crossWarn, 'BLOCKED');
|
|
703
|
+
if (replanEventsOf(readStateFile(dir)).length !== 1) {
|
|
704
|
+
throw new Error('旧 change 形态应照常重签并写入第 1 条 replan-applied 事件');
|
|
705
|
+
}
|
|
706
|
+
const afterWarnState = readStateFile(dir);
|
|
707
|
+
afterWarnState.newChange = true;
|
|
708
|
+
writeState(dir, afterWarnState);
|
|
709
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
710
|
+
replanTaskText({ parallelPending: ['P01', 'P02'], crossTaskPair: 'no-deps' }));
|
|
711
|
+
const crossBytes = readStateBytes(dir);
|
|
712
|
+
const crossBlocked = runState(['replan', '计划缺陷重校(新 change 形态)', '--authorized-by', '用户裁决'], dir);
|
|
713
|
+
assertExit(crossBlocked, 1);
|
|
714
|
+
assertOut(crossBlocked, 'BLOCKED');
|
|
715
|
+
assertOut(crossBlocked, '同文件跨任务且无依赖路径');
|
|
716
|
+
assertOut(crossBlocked, 'X1×X2(src/shared-cross.mjs)');
|
|
717
|
+
assertOut(crossBlocked, '补显式 depends_on 或合并为一个任务');
|
|
718
|
+
assertNotOut(crossBlocked, 'REPLAN:');
|
|
719
|
+
if (!readStateBytes(dir).equals(crossBytes)) throw new Error('replan 第三族 BLOCK 改写了 state 字节');
|
|
720
|
+
if (replanBackupFiles(dir).length !== 1) {
|
|
721
|
+
throw new Error('replan 第三族 BLOCK 不得新增备份(应仍为第 1 轮那一份): ' + JSON.stringify(replanBackupFiles(dir)));
|
|
722
|
+
}
|
|
723
|
+
if (replanEventsOf(readStateFile(dir)).length !== 1) {
|
|
724
|
+
throw new Error('replan 第三族 BLOCK 不得写入 replan-applied 事件');
|
|
725
|
+
}
|
|
726
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
727
|
+
replanTaskText({ parallelPending: ['P01', 'P02'], crossTaskPair: 'deps' }));
|
|
728
|
+
const crossRecovered = runState(['replan', '计划缺陷重校 2(已补 depends_on)', '--authorized-by', '用户裁决'], dir);
|
|
729
|
+
assertExit(crossRecovered, 0);
|
|
730
|
+
assertOut(crossRecovered, 'REPLAN');
|
|
731
|
+
if (replanEventsOf(readStateFile(dir)).length !== 2) {
|
|
732
|
+
throw new Error('补显式 depends_on 后复签应写入第 2 条 replan-applied 事件');
|
|
733
|
+
}
|
|
734
|
+
// 第 3 轮:常规修订(轮次按 change 从事件累计)
|
|
735
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', replanTaskText({ parallelPending: parallelIds.slice(0, 3) }));
|
|
736
|
+
const thirdRound = runState(['replan', '计划缺陷重校 3', '--authorized-by', '用户裁决'], dir);
|
|
737
|
+
assertExit(thirdRound, 0);
|
|
738
|
+
assertOut(thirdRound, 'REPLAN');
|
|
739
|
+
if (replanEventsOf(readStateFile(dir)).length !== 3) {
|
|
740
|
+
throw new Error('第 3 轮后 replan-applied 事件数应为 3');
|
|
741
|
+
}
|
|
742
|
+
if (replanBackupFiles(dir).length !== 3) {
|
|
743
|
+
throw new Error('三轮应产生三份备份: ' + JSON.stringify(replanBackupFiles(dir)));
|
|
744
|
+
}
|
|
745
|
+
// ③ 第 4 次 → BLOCK + 人工裁决指引(继续 / 停止)+ state 字节零改写
|
|
746
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', replanTaskText({ parallelPending: parallelIds }));
|
|
747
|
+
const beforeFourth = readStateBytes(dir);
|
|
748
|
+
const fourth = runState(['replan', '计划缺陷重校(上限后未授权)', '--authorized-by', '用户裁决'], dir);
|
|
749
|
+
assertExit(fourth, 1);
|
|
750
|
+
assertOut(fourth, 'BLOCK');
|
|
751
|
+
assertOut(fourth, '继续');
|
|
752
|
+
assertOut(fourth, '停止');
|
|
753
|
+
if (!readStateBytes(dir).equals(beforeFourth)) throw new Error('超上限调用改写了 state 字节');
|
|
754
|
+
if (replanEventsOf(readStateFile(dir)).length !== 3) throw new Error('超上限调用写入了 replan-applied 事件');
|
|
755
|
+
if (replanBackupFiles(dir).length !== 3) {
|
|
756
|
+
throw new Error('超上限调用新增了备份: ' + JSON.stringify(replanBackupFiles(dir)));
|
|
757
|
+
}
|
|
758
|
+
// ④ 续轮授权不足(n < 已用 + 1)→ BLOCK 零改写:上限裁决点不可被残缺授权绕过
|
|
759
|
+
const insufficientBytes = readStateBytes(dir);
|
|
760
|
+
const insufficient = runState(['replan', '计划缺陷重校(续轮不足)', '--authorized-by', '用户授权', '--continue-round', '3'], dir);
|
|
761
|
+
assertExit(insufficient, 1);
|
|
762
|
+
assertOut(insufficient, 'BLOCK');
|
|
763
|
+
if (!readStateBytes(dir).equals(insufficientBytes)) throw new Error('续轮授权不足改写了 state 字节');
|
|
764
|
+
// ⑤ 显式授权续轮(n = 已用 + 1)→ 放行并计第 4 轮:审计行标注续轮,事件 / 留痕带续轮标记
|
|
765
|
+
const continued = runState(['replan', '计划缺陷重校(上限后显式续轮)', '--authorized-by', '用户授权续轮', '--continue-round', '4'], dir);
|
|
766
|
+
assertExit(continued, 0);
|
|
767
|
+
assertOut(continued, 'REPLAN');
|
|
768
|
+
assertOut(continued, '续轮');
|
|
769
|
+
const continuedState = readStateFile(dir);
|
|
770
|
+
const continuedEvents = replanEventsOf(continuedState);
|
|
771
|
+
const continuedEvent = continuedEvents[continuedEvents.length - 1];
|
|
772
|
+
if (!continuedEvent || continuedEvent.round !== 4 || continuedEvent.change !== CHANGE_ID
|
|
773
|
+
|| continuedEvent.continuationAuthorized !== true) {
|
|
774
|
+
throw new Error('续轮审计事件字段不符(round=4 / change / 续轮标记): ' + JSON.stringify(continuedEvent));
|
|
775
|
+
}
|
|
776
|
+
if (!continuedState.evidence || !continuedState.evidence.execute
|
|
777
|
+
|| continuedState.evidence.execute.replanAuthorization.continuationAuthorized !== true) {
|
|
778
|
+
throw new Error('续轮授权留痕缺失: ' + JSON.stringify(continuedState.evidence && continuedState.evidence.execute));
|
|
779
|
+
}
|
|
780
|
+
if (replanBackupFiles(dir).length !== 4) {
|
|
781
|
+
throw new Error('续轮放行应新增一份备份(共 4 份): ' + JSON.stringify(replanBackupFiles(dir)));
|
|
782
|
+
}
|
|
783
|
+
},
|
|
784
|
+
},
|
|
785
|
+
|
|
786
|
+
{
|
|
787
|
+
name: 'H11 advance 留痕:advance-forced 事件 + status.forcedNodes 派生可见(真实命令)',
|
|
788
|
+
run: (dir) => {
|
|
789
|
+
assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
|
|
790
|
+
writeIntakeArtifacts(dir);
|
|
791
|
+
const res = runState(['advance'], dir);
|
|
792
|
+
assertExit(res, 0);
|
|
793
|
+
assertOut(res, 'Advanced to: design');
|
|
794
|
+
assertOut(res, 'ADVANCE-AUDIT');
|
|
795
|
+
const st = readStateFile(dir);
|
|
796
|
+
const events = (st.history || []).filter((e) => e && e.event === 'advance-forced');
|
|
797
|
+
if (events.length !== 1) {
|
|
798
|
+
throw new Error('advance 应恰写一条 advance-forced 事件: ' + JSON.stringify(events));
|
|
799
|
+
}
|
|
800
|
+
const event = events[0];
|
|
801
|
+
if (event.node !== 'open' || event.change !== CHANGE_ID || event.reason !== 'advance') {
|
|
802
|
+
throw new Error('advance-forced 事件字段不符: ' + JSON.stringify(event));
|
|
803
|
+
}
|
|
804
|
+
if (JSON.stringify(event.skipped) !== JSON.stringify(['exit:open'])) {
|
|
805
|
+
throw new Error("advance-forced 事件应记录 skipped: ['exit:open']: " + JSON.stringify(event.skipped));
|
|
806
|
+
}
|
|
807
|
+
if (typeof event.at !== 'string' || event.at.trim() === '') throw new Error('advance-forced 缺 at: ' + JSON.stringify(event.at));
|
|
808
|
+
const status = parseStatusOutput(dir);
|
|
809
|
+
if (!Array.isArray(status.forcedNodes) || !status.forcedNodes.includes('open')) {
|
|
810
|
+
throw new Error('status.forcedNodes 应含强制推进且无出口证据的 open: ' + JSON.stringify(status.forcedNodes));
|
|
811
|
+
}
|
|
812
|
+
},
|
|
813
|
+
},
|
|
814
|
+
|
|
815
|
+
];
|