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,830 @@
|
|
|
1
|
+
// items/b.mjs — 条目分区:A 组尾部(Fix 回路三项)+ B 组条目(声明机制:skill-load / record / exit 校验)
|
|
2
|
+
//
|
|
3
|
+
// 数据层约定:同 items/a.mjs 头注(只承载 ENTRIES;夹具从 lib/system-fixtures.mjs 取;组文件之间零 import)。
|
|
4
|
+
// 组界:本文件先承载 A 组尾部三项、再承载 B 组条目——与套件入口的拼接顺序一致(见 items/a.mjs 头注)。
|
|
5
|
+
|
|
6
|
+
import fs from 'fs';
|
|
7
|
+
import path from 'path';
|
|
8
|
+
import { assertExit, assertNotOut, assertOut, runGuard, runHandoff, runState, writeFile, writeState } from '../lib/test-helpers.mjs';
|
|
9
|
+
import { serialTaskBlock, fixBatchParallelTaskText, fixBatchTwoFixTaskText, fixBatchHistoryWithStaleExecuteExit, writeFixBatchFixture, CHANGE_ID, readStateFile, writeIntakeArtifacts, fullContract, execSummaryFixture, fixBatchReviewDoc, completeFixTaskAndRecord, assertNodeLine, assertNotNodeLine } from '../lib/system-fixtures.mjs';
|
|
10
|
+
|
|
11
|
+
export const ENTRIES = [
|
|
12
|
+
|
|
13
|
+
{
|
|
14
|
+
// review 源 Fix 闭环(真实命令链路):execute 已首次完成、review 驻留 +「Fix 任务」段追加
|
|
15
|
+
// pending 修复任务 → 直接 exit review --apply 被拦(旧绕过路径会静默跳过 execute 生命周期);
|
|
16
|
+
// next 受控归位 execute 并写盘 → 完成修复任务后 record/exit execute --apply 回源 review →
|
|
17
|
+
// review 出口门禁真实执行(发现条目缺处置标记仍 BLOCKED,补齐后通过)并推进 verify。
|
|
18
|
+
// 修复前 next 停在 review(无 NODE: execute / 无归位审计行)→ 本项应失败(RED 锚)。
|
|
19
|
+
name: 'A21 review 源 Fix 闭环:next 归位 execute → 出口回源 review → 审查出口真实执行(真实命令)',
|
|
20
|
+
run: (dir) => {
|
|
21
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
22
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending' });
|
|
23
|
+
|
|
24
|
+
// ① 旧绕过路径:Fix 任务仍 pending 时直接 exit review --apply → 新 change BLOCKED + 恢复指引
|
|
25
|
+
const bypass = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
26
|
+
assertExit(bypass, 1);
|
|
27
|
+
assertOut(bypass, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
28
|
+
assertOut(bypass, 'Fix 批次');
|
|
29
|
+
assertOut(bypass, 'entry execute');
|
|
30
|
+
assertOut(bypass, 'workflow-state.mjs next');
|
|
31
|
+
assertNotOut(bypass, 'ALL CHECKS PASSED');
|
|
32
|
+
let st = readStateFile(dir);
|
|
33
|
+
if (st.currentNode !== 'review' || st.completedNodes.includes('review')) {
|
|
34
|
+
throw new Error('越界 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 首轮计数与 verify 失败计数互相独立:先记一次 verify 失败,归位不得改动其计数。
|
|
38
|
+
assertExit(runState(['verify-fail'], dir, env), 0);
|
|
39
|
+
// ② next 受控归位 execute:显式审计行 + 真实写盘(不得停在源节点)
|
|
40
|
+
const nxt = runState(['next'], dir, env);
|
|
41
|
+
assertExit(nxt, 0);
|
|
42
|
+
assertOut(nxt, 'FIX-BATCH: 归位 execute(源节点 review)(第 1/3 轮)');
|
|
43
|
+
assertNodeLine(nxt, 'execute');
|
|
44
|
+
assertNotNodeLine(nxt, 'review');
|
|
45
|
+
st = readStateFile(dir);
|
|
46
|
+
if (st.currentNode !== 'execute') {
|
|
47
|
+
throw new Error('归位后 currentNode 应为 execute,实际 ' + JSON.stringify(st.currentNode));
|
|
48
|
+
}
|
|
49
|
+
if (st.completedNodes.includes('review')) {
|
|
50
|
+
throw new Error('归位不得把源节点标完成: ' + JSON.stringify(st.completedNodes));
|
|
51
|
+
}
|
|
52
|
+
if (!st.evidence?.review) {
|
|
53
|
+
throw new Error('归位不得清掉源节点证据: ' + JSON.stringify(st.evidence));
|
|
54
|
+
}
|
|
55
|
+
if (st.fixRoundsByChange?.ch !== 1) {
|
|
56
|
+
throw new Error('首轮受控归位应计数 1: ' + JSON.stringify(st.fixRoundsByChange));
|
|
57
|
+
}
|
|
58
|
+
if (st.verifyFailuresByChange?.ch !== 1) {
|
|
59
|
+
throw new Error('Fix 轮次计数不得改写 verify 失败计数: ' + JSON.stringify(st.verifyFailuresByChange));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ③ 完成修复任务(标 done + 逐任务 SUMMARY + 重载声明 + record execute)
|
|
63
|
+
completeFixTaskAndRecord(dir, env);
|
|
64
|
+
|
|
65
|
+
// 收口前基线(只读):出口前后完成节点集合不变,目的地仍为未完成的 review
|
|
66
|
+
const a21Before = readStateFile(dir);
|
|
67
|
+
// ④ exit execute --apply 跑四类出口后回源 review(REVIEW.md 在场也不得按产物跳 verify)
|
|
68
|
+
const ex = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
69
|
+
assertExit(ex, 0);
|
|
70
|
+
assertOut(ex, 'ALL CHECKS PASSED');
|
|
71
|
+
assertOut(ex, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
72
|
+
assertNodeLine(ex, 'review');
|
|
73
|
+
assertNotNodeLine(ex, 'verify');
|
|
74
|
+
assertNotOut(ex, 'RETURN: 回源节点');
|
|
75
|
+
assertNotOut(ex, '未分类');
|
|
76
|
+
st = readStateFile(dir);
|
|
77
|
+
if (st.currentNode !== 'review' || st.completedNodes.includes('review')) {
|
|
78
|
+
throw new Error('回源后应停在未完成的 review: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
79
|
+
}
|
|
80
|
+
if (JSON.stringify(st.completedNodes) !== JSON.stringify(a21Before.completedNodes)) {
|
|
81
|
+
throw new Error('Fix 回源收尾不得改写完成节点集合(仅审计行分类变化): 收口前 '
|
|
82
|
+
+ JSON.stringify(a21Before.completedNodes) + ' 收口后 ' + JSON.stringify(st.completedNodes));
|
|
83
|
+
}
|
|
84
|
+
const a21PostNext = runState(['next'], dir, env);
|
|
85
|
+
assertExit(a21PostNext, 0);
|
|
86
|
+
assertNodeLine(a21PostNext, 'review');
|
|
87
|
+
|
|
88
|
+
// ⑤ 回源 review 出口门禁真实执行:缺处置标记 → BLOCKED;补齐后同出口通过并推进 verify
|
|
89
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
90
|
+
assertExit(runGuard(['entry', 'review'], dir, env), 0);
|
|
91
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', fixBatchReviewDoc(false));
|
|
92
|
+
const gate = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
93
|
+
assertExit(gate, 1);
|
|
94
|
+
assertOut(gate, 'BLOCKED');
|
|
95
|
+
assertOut(gate, '处置');
|
|
96
|
+
assertNotOut(gate, 'ALL CHECKS PASSED');
|
|
97
|
+
st = readStateFile(dir);
|
|
98
|
+
if (st.currentNode !== 'review' || st.completedNodes.includes('review')) {
|
|
99
|
+
throw new Error('审查出口 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
100
|
+
}
|
|
101
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', fixBatchReviewDoc(true));
|
|
102
|
+
const pass = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
103
|
+
assertExit(pass, 0);
|
|
104
|
+
assertOut(pass, 'ALL CHECKS PASSED');
|
|
105
|
+
assertNodeLine(pass, 'verify');
|
|
106
|
+
st = readStateFile(dir);
|
|
107
|
+
if (st.currentNode !== 'verify' || !st.completedNodes.includes('review')) {
|
|
108
|
+
throw new Error('审查出口通过后应推进 verify: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
109
|
+
}
|
|
110
|
+
if (st.fixRoundsByChange?.ch !== 1) {
|
|
111
|
+
throw new Error('审查出口通过不得清零 Fix 轮次计数: ' + JSON.stringify(st.fixRoundsByChange));
|
|
112
|
+
}
|
|
113
|
+
if (st.verifyFailuresByChange?.ch !== 1) {
|
|
114
|
+
throw new Error('审查出口不得改写 verify 失败计数: ' + JSON.stringify(st.verifyFailuresByChange));
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
// verify 源 Fix 回程(真实命令链路):review 已完成、verify 驻留 + pending 修复任务;
|
|
120
|
+
// TEST/UAT 已在场(正常产物推导会跳过未出口的 verify 去 archive)→ 修复前 next 停在 verify /
|
|
121
|
+
// 产物推导会跳过 verify;修复后 next 归位 execute,exit execute --apply 回源 verify 并真实跑
|
|
122
|
+
// verify 出口(验证命令落盘副作用文件 + 推进 archive)。
|
|
123
|
+
name: 'A22 verify 源 Fix 回程:回 verify 而非跳过 archive + verify 出口真实执行(真实命令)',
|
|
124
|
+
run: (dir) => {
|
|
125
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
126
|
+
const gateMarker = path.join(dir, 'verify-gate-ran.txt');
|
|
127
|
+
writeFixBatchFixture(dir, { kind: 'verify', fixStatus: 'pending' });
|
|
128
|
+
|
|
129
|
+
// ① 旧绕过路径:pending 修复任务时直接 exit verify --apply → BLOCKED,且验证命令未被执行
|
|
130
|
+
const bypass = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
131
|
+
assertExit(bypass, 1);
|
|
132
|
+
assertOut(bypass, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
133
|
+
assertOut(bypass, 'entry execute');
|
|
134
|
+
assertNotOut(bypass, 'ALL CHECKS PASSED');
|
|
135
|
+
if (fs.existsSync(gateMarker)) throw new Error('越界 BLOCK 不得执行 verify 验证命令');
|
|
136
|
+
let st = readStateFile(dir);
|
|
137
|
+
if (st.currentNode !== 'verify' || st.completedNodes.includes('verify')) {
|
|
138
|
+
throw new Error('越界 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// ② next 受控归位 execute(源节点 verify)
|
|
142
|
+
const nxt = runState(['next'], dir, env);
|
|
143
|
+
assertExit(nxt, 0);
|
|
144
|
+
assertOut(nxt, 'FIX-BATCH: 归位 execute(源节点 verify)');
|
|
145
|
+
assertNodeLine(nxt, 'execute');
|
|
146
|
+
assertNotNodeLine(nxt, 'verify');
|
|
147
|
+
st = readStateFile(dir);
|
|
148
|
+
if (st.currentNode !== 'execute') {
|
|
149
|
+
throw new Error('归位后 currentNode 应为 execute,实际 ' + JSON.stringify(st.currentNode));
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// ③ 完成修复任务并 record execute
|
|
153
|
+
completeFixTaskAndRecord(dir, env);
|
|
154
|
+
|
|
155
|
+
// 收口前基线(只读):出口前后完成节点集合不变,目的地仍为未完成的 verify
|
|
156
|
+
const a22Before = readStateFile(dir);
|
|
157
|
+
// ④ exit execute --apply:不按产物跳过 verify → 回源 verify(不是 archive)
|
|
158
|
+
const ex = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
159
|
+
assertExit(ex, 0);
|
|
160
|
+
assertOut(ex, 'ALL CHECKS PASSED');
|
|
161
|
+
assertOut(ex, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
162
|
+
assertNodeLine(ex, 'verify');
|
|
163
|
+
assertNotNodeLine(ex, 'archive');
|
|
164
|
+
assertNotOut(ex, 'RETURN: 回源节点');
|
|
165
|
+
assertNotOut(ex, '未分类');
|
|
166
|
+
st = readStateFile(dir);
|
|
167
|
+
if (st.currentNode !== 'verify' || st.completedNodes.includes('verify')) {
|
|
168
|
+
throw new Error('回源后应停在未完成的 verify: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
169
|
+
}
|
|
170
|
+
if (JSON.stringify(st.completedNodes) !== JSON.stringify(a22Before.completedNodes)) {
|
|
171
|
+
throw new Error('Fix 回源收尾不得改写完成节点集合(仅审计行分类变化): 收口前 '
|
|
172
|
+
+ JSON.stringify(a22Before.completedNodes) + ' 收口后 ' + JSON.stringify(st.completedNodes));
|
|
173
|
+
}
|
|
174
|
+
const a22PostNext = runState(['next'], dir, env);
|
|
175
|
+
assertExit(a22PostNext, 0);
|
|
176
|
+
assertNodeLine(a22PostNext, 'verify');
|
|
177
|
+
|
|
178
|
+
// ⑤ 回源 verify 出口真实执行:验证命令落盘 + 推进 archive
|
|
179
|
+
assertExit(runState(['skill-load', 'verify', 'flow-comet-verify', '--prompt', 'flow-kit/prompts/7-integration.md'], dir, env), 0);
|
|
180
|
+
assertExit(runGuard(['entry', 'verify'], dir, env), 0);
|
|
181
|
+
const vf = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
182
|
+
assertExit(vf, 0);
|
|
183
|
+
assertOut(vf, 'ALL CHECKS PASSED');
|
|
184
|
+
assertNodeLine(vf, 'archive');
|
|
185
|
+
if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
|
|
186
|
+
throw new Error('verify 出口未真实执行 TEST.md 验证命令(副作用文件缺失/内容不符)');
|
|
187
|
+
}
|
|
188
|
+
st = readStateFile(dir);
|
|
189
|
+
if (st.currentNode !== 'archive' || !st.completedNodes.includes('verify')) {
|
|
190
|
+
throw new Error('验证出口通过后应推进 archive: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
// 越界拦截 + done-but-unclosed 回放 + 旧 change 兼容(真实命令链路):
|
|
196
|
+
// ① 新 change review/pending → BLOCKED + state 不变;
|
|
197
|
+
// ② 事故回放——Fix 任务全 done 但 history 最新 exit execute 签名仍是追加前值
|
|
198
|
+
// (从未重跑 execute 出口)→ 同出口 BLOCKED + state 字节零改写(修复前被错误断言为通过);
|
|
199
|
+
// ③ 正对照——按指引 entry execute + exit execute --apply 真闭合后,review 出口通过;
|
|
200
|
+
// ④⑤ verify 源 pending / done-but-unclosed 同样 BLOCKED 且验证命令不执行,⑥ 闭合后通过;
|
|
201
|
+
// ⑦⑧⑨ 旧 change(无 new change 标记)同形态渐进 WARN 放行、next 归位可达、验证出口真实执行。
|
|
202
|
+
name: 'A23 Fix 越界拦截与旧 change 渐进:源节点直接 exit BLOCK(新)/WARN(旧)不卡死(真实命令)',
|
|
203
|
+
run: (dir) => {
|
|
204
|
+
const env = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
205
|
+
const gateMarker = path.join(dir, 'verify-gate-ran.txt');
|
|
206
|
+
const statePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
207
|
+
|
|
208
|
+
// ① 新 change review 源 + pending:直接 exit review --apply → BLOCKED + 恢复指引 + state 不变
|
|
209
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending' });
|
|
210
|
+
const rBlock = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
211
|
+
assertExit(rBlock, 1);
|
|
212
|
+
assertOut(rBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
213
|
+
assertOut(rBlock, '未跑出口');
|
|
214
|
+
assertOut(rBlock, '恢复');
|
|
215
|
+
assertOut(rBlock, 'entry execute');
|
|
216
|
+
assertOut(rBlock, 'workflow-state.mjs next');
|
|
217
|
+
assertNotOut(rBlock, 'ALL CHECKS PASSED');
|
|
218
|
+
let st = readStateFile(dir);
|
|
219
|
+
if (st.currentNode !== 'review' || st.completedNodes.includes('review')) {
|
|
220
|
+
throw new Error('review 源越界 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ② 事故回放形态:Fix 任务已全 done,但 history 最新 exit execute 记录的是追加前签名
|
|
224
|
+
//(done 后从未再跑 execute 出口)→ 修复前静默放行,修复后必须 BLOCKED + state 字节零改写
|
|
225
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'done' });
|
|
226
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', execSummaryFixture('T-FIX-01'));
|
|
227
|
+
const doneUnclosed = readStateFile(dir);
|
|
228
|
+
doneUnclosed.history = fixBatchHistoryWithStaleExecuteExit();
|
|
229
|
+
writeState(dir, doneUnclosed);
|
|
230
|
+
const doneBytes = fs.readFileSync(statePath, 'utf8');
|
|
231
|
+
const rDoneBlock = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
232
|
+
assertExit(rDoneBlock, 1);
|
|
233
|
+
assertOut(rDoneBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
234
|
+
assertOut(rDoneBlock, 'entry execute');
|
|
235
|
+
assertOut(rDoneBlock, 'workflow-state.mjs next');
|
|
236
|
+
assertNotOut(rDoneBlock, 'ALL CHECKS PASSED');
|
|
237
|
+
if (fs.readFileSync(statePath, 'utf8') !== doneBytes) {
|
|
238
|
+
throw new Error('done-but-unclosed 越界 BLOCK 不得改写 state 字节');
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// ③ 正对照:同夹具按指引真闭合(entry execute → 完成声明/record → exit execute --apply 写当前
|
|
242
|
+
// 签名并回源 review)→ 再 exit review --apply 通过(拦截只针对未闭合态,不误伤正常路径)
|
|
243
|
+
assertExit(runGuard(['entry', 'execute'], dir, env), 0);
|
|
244
|
+
completeFixTaskAndRecord(dir, env);
|
|
245
|
+
const rClosedExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
246
|
+
assertExit(rClosedExit, 0);
|
|
247
|
+
assertOut(rClosedExit, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
248
|
+
assertNotOut(rClosedExit, 'RETURN: 回源节点');
|
|
249
|
+
assertNodeLine(rClosedExit, 'review');
|
|
250
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
251
|
+
assertExit(runGuard(['entry', 'review'], dir, env), 0);
|
|
252
|
+
const rReviewPass = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
253
|
+
assertExit(rReviewPass, 0);
|
|
254
|
+
assertOut(rReviewPass, 'ALL CHECKS PASSED');
|
|
255
|
+
assertNotOut(rReviewPass, 'BLOCKED');
|
|
256
|
+
assertNodeLine(rReviewPass, 'verify');
|
|
257
|
+
|
|
258
|
+
// ③b 并行 Fix 任务(可委托 parallel pending)+ review 源(真实命令链路):
|
|
259
|
+
// 直接 exit review BLOCKED;next 归位 subagent-execute;完成委托后第二趟
|
|
260
|
+
// exit subagent-execute --apply 回源 review;源节点出口真实执行并推进 verify。
|
|
261
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending', parallelFix: true });
|
|
262
|
+
const pBypass = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
263
|
+
assertExit(pBypass, 1);
|
|
264
|
+
assertOut(pBypass, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
265
|
+
assertNotOut(pBypass, 'ALL CHECKS PASSED');
|
|
266
|
+
let pSt = readStateFile(dir);
|
|
267
|
+
if (pSt.currentNode !== 'review' || pSt.completedNodes.includes('review')) {
|
|
268
|
+
throw new Error('并行越界 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: pSt.currentNode, completedNodes: pSt.completedNodes }));
|
|
269
|
+
}
|
|
270
|
+
const pNext = runState(['next'], dir, env);
|
|
271
|
+
assertExit(pNext, 0);
|
|
272
|
+
assertOut(pNext, 'FIX-BATCH: 归位 subagent-execute(源节点 review)');
|
|
273
|
+
assertNodeLine(pNext, 'subagent-execute');
|
|
274
|
+
assertNotNodeLine(pNext, 'execute');
|
|
275
|
+
pSt = readStateFile(dir);
|
|
276
|
+
if (pSt.currentNode !== 'subagent-execute') {
|
|
277
|
+
throw new Error('并行回退归位后 currentNode 应为 subagent-execute,实际 ' + JSON.stringify(pSt.currentNode));
|
|
278
|
+
}
|
|
279
|
+
// 完成并行修复任务:标记 done + 摘要 + 真实 handoff request/result + skill-load/record。
|
|
280
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchParallelTaskText('done'));
|
|
281
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/P-FIX-01-SUMMARY.md', execSummaryFixture('P-FIX-01'));
|
|
282
|
+
// 委托前先加载节点技能声明(新 change 两层加载模型:request 命令要求标记在位)。
|
|
283
|
+
assertExit(runState(['skill-load', 'subagent-execute', 'flow-comet-dev', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
284
|
+
for (const taskId of ['T01', 'P-FIX-01']) {
|
|
285
|
+
assertExit(runHandoff(['request', taskId, taskId + ' 委托', '--write-files', 'src/' + taskId.toLowerCase() + '.mjs'], dir), 0);
|
|
286
|
+
assertExit(runHandoff(['result', taskId, fullContract('abcd1234abcd1234abcd1234abcd1234abcd1234', taskId)], dir), 0);
|
|
287
|
+
}
|
|
288
|
+
assertExit(runState(['record', 'subagent-execute', '{"summary":"parallel fix delegated and collected"}'], dir, env), 0);
|
|
289
|
+
const pExit = runGuard(['exit', 'subagent-execute', '--apply'], dir, env);
|
|
290
|
+
assertExit(pExit, 0);
|
|
291
|
+
assertOut(pExit, 'ALL CHECKS PASSED');
|
|
292
|
+
assertOut(pExit, 'FIX-BATCH: 回源节点 review(subagent-execute 出口已完成)');
|
|
293
|
+
assertNotOut(pExit, 'RETURN: 回源节点');
|
|
294
|
+
assertNodeLine(pExit, 'review');
|
|
295
|
+
pSt = readStateFile(dir);
|
|
296
|
+
if (pSt.currentNode !== 'review') {
|
|
297
|
+
throw new Error('并行修复第二趟出口应回源 review,实际 ' + JSON.stringify(pSt.currentNode));
|
|
298
|
+
}
|
|
299
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
300
|
+
assertExit(runGuard(['entry', 'review'], dir, env), 0);
|
|
301
|
+
const pReviewPass = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
302
|
+
assertExit(pReviewPass, 0);
|
|
303
|
+
assertOut(pReviewPass, 'ALL CHECKS PASSED');
|
|
304
|
+
assertNodeLine(pReviewPass, 'verify');
|
|
305
|
+
// ④ 新 change verify 源 + pending:直接 exit verify --apply → BLOCKED,验证命令未执行
|
|
306
|
+
fs.rmSync(gateMarker, { force: true });
|
|
307
|
+
writeFixBatchFixture(dir, { kind: 'verify', fixStatus: 'pending' });
|
|
308
|
+
const vBlock = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
309
|
+
assertExit(vBlock, 1);
|
|
310
|
+
assertOut(vBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
311
|
+
assertOut(vBlock, 'entry execute');
|
|
312
|
+
assertNotOut(vBlock, 'ALL CHECKS PASSED');
|
|
313
|
+
if (fs.existsSync(gateMarker)) throw new Error('越界 BLOCK 不得执行 verify 验证命令');
|
|
314
|
+
st = readStateFile(dir);
|
|
315
|
+
if (st.currentNode !== 'verify' || st.completedNodes.includes('verify')) {
|
|
316
|
+
throw new Error('verify 源越界 BLOCK 不得改写 state: ' + JSON.stringify({ currentNode: st.currentNode, completedNodes: st.completedNodes }));
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// ⑤ verify 源 done-but-unclosed 回放(独立复核实跑形态):review 已完成 + TEST/UAT 在场
|
|
320
|
+
//(原路径会跳过 verify 去 archive)+ 全 done + 最新 execute exit 签名过时 → BLOCKED,验证命令
|
|
321
|
+
// 不执行、state 字节零改写;⑥ 按指引闭合后 exit verify 真实执行验证命令并推进 archive
|
|
322
|
+
writeFixBatchFixture(dir, { kind: 'verify', fixStatus: 'done' });
|
|
323
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', execSummaryFixture('T-FIX-01'));
|
|
324
|
+
const verifyDoneUnclosed = readStateFile(dir);
|
|
325
|
+
verifyDoneUnclosed.history = fixBatchHistoryWithStaleExecuteExit();
|
|
326
|
+
writeState(dir, verifyDoneUnclosed);
|
|
327
|
+
const verifyDoneBytes = fs.readFileSync(statePath, 'utf8');
|
|
328
|
+
const vDoneBlock = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
329
|
+
assertExit(vDoneBlock, 1);
|
|
330
|
+
assertOut(vDoneBlock, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
331
|
+
assertOut(vDoneBlock, 'entry execute');
|
|
332
|
+
assertNotOut(vDoneBlock, 'ALL CHECKS PASSED');
|
|
333
|
+
if (fs.existsSync(gateMarker)) throw new Error('done-but-unclosed 越界 BLOCK 不得执行 verify 验证命令');
|
|
334
|
+
if (fs.readFileSync(statePath, 'utf8') !== verifyDoneBytes) {
|
|
335
|
+
throw new Error('verify done-but-unclosed 越界 BLOCK 不得改写 state 字节');
|
|
336
|
+
}
|
|
337
|
+
assertExit(runGuard(['entry', 'execute'], dir, env), 0);
|
|
338
|
+
completeFixTaskAndRecord(dir, env);
|
|
339
|
+
const vClosedExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
340
|
+
assertExit(vClosedExit, 0);
|
|
341
|
+
assertOut(vClosedExit, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
342
|
+
assertNotOut(vClosedExit, 'RETURN: 回源节点');
|
|
343
|
+
assertNodeLine(vClosedExit, 'verify');
|
|
344
|
+
assertExit(runState(['skill-load', 'verify', 'flow-comet-verify', '--prompt', 'flow-kit/prompts/7-integration.md'], dir, env), 0);
|
|
345
|
+
assertExit(runGuard(['entry', 'verify'], dir, env), 0);
|
|
346
|
+
const vPass = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
347
|
+
assertExit(vPass, 0);
|
|
348
|
+
assertOut(vPass, 'ALL CHECKS PASSED');
|
|
349
|
+
assertNodeLine(vPass, 'archive');
|
|
350
|
+
if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
|
|
351
|
+
throw new Error('闭合后 verify 出口未真实执行 TEST.md 验证命令(副作用文件缺失/内容不符)');
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// ⑦ 旧 change review 源 + pending:直接 exit review --apply → FIX-BATCH WARN 渐进放行(不 BLOCK、不死结)
|
|
355
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending', newChange: false });
|
|
356
|
+
const oldExit = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
357
|
+
assertExit(oldExit, 0);
|
|
358
|
+
assertOut(oldExit, 'FIX-BATCH WARN');
|
|
359
|
+
assertNotOut(oldExit, 'BLOCKED');
|
|
360
|
+
assertOut(oldExit, 'ALL CHECKS PASSED');
|
|
361
|
+
assertNodeLine(oldExit, 'execute'); // pending 修复任务使路由继续回 execute(流程未卡死)
|
|
362
|
+
st = readStateFile(dir);
|
|
363
|
+
if (st.currentNode !== 'execute') {
|
|
364
|
+
throw new Error('旧 change 渐进放行后 currentNode 应为 execute,实际 ' + JSON.stringify(st.currentNode));
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// ⑧ 旧 change next 入口:pending 修复 + 源节点驻留 → 不新增 BLOCK,归位 execute 可继续
|
|
368
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending', newChange: false });
|
|
369
|
+
const oldNext = runState(['next'], dir, env);
|
|
370
|
+
assertExit(oldNext, 0);
|
|
371
|
+
assertNotOut(oldNext, 'BLOCKED');
|
|
372
|
+
assertOut(oldNext, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
373
|
+
assertNodeLine(oldNext, 'execute');
|
|
374
|
+
st = readStateFile(dir);
|
|
375
|
+
if (st.currentNode !== 'execute') {
|
|
376
|
+
throw new Error('旧 change next 归位后 currentNode 应为 execute,实际 ' + JSON.stringify(st.currentNode));
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ⑨ 旧 change verify 源 + pending:直接 exit verify --apply → WARN 渐进且验证出口真实执行、不卡死
|
|
380
|
+
fs.rmSync(gateMarker, { force: true });
|
|
381
|
+
writeFixBatchFixture(dir, { kind: 'verify', fixStatus: 'pending', newChange: false });
|
|
382
|
+
const oldVerify = runGuard(['exit', 'verify', '--apply'], dir, env);
|
|
383
|
+
assertExit(oldVerify, 0);
|
|
384
|
+
assertOut(oldVerify, 'FIX-BATCH WARN');
|
|
385
|
+
assertNotOut(oldVerify, 'BLOCKED');
|
|
386
|
+
assertOut(oldVerify, 'ALL CHECKS PASSED');
|
|
387
|
+
assertNodeLine(oldVerify, 'execute'); // pending 修复任务使路由继续回 execute
|
|
388
|
+
if (!fs.existsSync(gateMarker) || fs.readFileSync(gateMarker, 'utf8') !== 'GATE-RAN') {
|
|
389
|
+
throw new Error('旧 change verify 出口未真实执行 TEST.md 验证命令(渐进不等于跳过门禁)');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
// ⑩ 多波次真实 Fix:第一波收口后追加第二波;第三趟收口时历史最新签名已等于当前签名、
|
|
393
|
+
// 更早签名仍发散——全量签名扫描不得被最新签名覆盖,仍须保留 FIX-BATCH 锚。
|
|
394
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending' });
|
|
395
|
+
assertExit(runState(['next'], dir, env), 0); // 受控归位 execute
|
|
396
|
+
completeFixTaskAndRecord(dir, env); // 第一波:单修复任务 done + 声明/record
|
|
397
|
+
const wave1 = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
398
|
+
assertExit(wave1, 0);
|
|
399
|
+
assertOut(wave1, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
400
|
+
assertNotOut(wave1, 'RETURN: 回源节点');
|
|
401
|
+
// 第二波:追加第二个修复任务(任务集签名发散)→ 归位 → 两任务完成后收口
|
|
402
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTwoFixTaskText('pending', 'pending'));
|
|
403
|
+
const wave2Next = runState(['next'], dir, env);
|
|
404
|
+
assertExit(wave2Next, 0);
|
|
405
|
+
assertOut(wave2Next, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
406
|
+
assertNodeLine(wave2Next, 'execute');
|
|
407
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTwoFixTaskText('done', 'done'));
|
|
408
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', execSummaryFixture('T-FIX-01'));
|
|
409
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-02-SUMMARY.md', execSummaryFixture('T-FIX-02'));
|
|
410
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-execute', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
411
|
+
assertExit(runState(['record', 'execute', '{"summary":"fix wave two executed","parallelTakeoverApproved":true}'], dir, env), 0);
|
|
412
|
+
const wave2 = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
413
|
+
assertExit(wave2, 0);
|
|
414
|
+
assertOut(wave2, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
415
|
+
assertNotOut(wave2, 'RETURN: 回源节点');
|
|
416
|
+
// 第三趟(把工作归属置回 execute 后直达真实出口,不改任务集):历史最新签名已==当前签名、
|
|
417
|
+
// 更早签名仍发散——全量签名扫描不得被最新签名覆盖,仍须保留 FIX-BATCH 锚。
|
|
418
|
+
const stWave3 = readStateFile(dir);
|
|
419
|
+
stWave3.currentNode = 'execute';
|
|
420
|
+
writeState(dir, stWave3);
|
|
421
|
+
const wave3 = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
422
|
+
assertExit(wave3, 0);
|
|
423
|
+
assertOut(wave3, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
424
|
+
assertNotOut(wave3, 'RETURN: 回源节点');
|
|
425
|
+
const waveState = readStateFile(dir);
|
|
426
|
+
const waveExits = (waveState.history || []).filter((event) =>
|
|
427
|
+
event && event.event === 'exit-applied' && (event.node === 'execute' || event.node === 'subagent-execute'));
|
|
428
|
+
if (waveExits.length < 3) {
|
|
429
|
+
throw new Error('多波次收口应留下至少三条 execute 家族出口事件: ' + JSON.stringify(waveExits));
|
|
430
|
+
}
|
|
431
|
+
const latestSignature = waveExits[waveExits.length - 1].taskSetSignature;
|
|
432
|
+
if (latestSignature !== waveExits[waveExits.length - 2].taskSetSignature) {
|
|
433
|
+
throw new Error('第三趟收口后最新签名应已等于当前任务集签名(夹具前提)');
|
|
434
|
+
}
|
|
435
|
+
if (latestSignature === waveExits[0].taskSetSignature) {
|
|
436
|
+
throw new Error('多波次任务集签名应已发散(夹具前提): ' + latestSignature);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// ⑪ 源未 entry 的真实 Fix:分类只认历史签名/Fix 结构标记,不依赖 enteredNodes → 仍 FIX-BATCH
|
|
440
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending' });
|
|
441
|
+
const noEntryState = readStateFile(dir);
|
|
442
|
+
noEntryState.enteredNodes = (noEntryState.enteredNodes || []).filter((nodeId) => nodeId !== 'review');
|
|
443
|
+
writeState(dir, noEntryState);
|
|
444
|
+
const noEntryNext = runState(['next'], dir, env);
|
|
445
|
+
assertExit(noEntryNext, 0);
|
|
446
|
+
assertOut(noEntryNext, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
447
|
+
completeFixTaskAndRecord(dir, env);
|
|
448
|
+
const noEntryExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
449
|
+
assertExit(noEntryExit, 0);
|
|
450
|
+
assertOut(noEntryExit, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
451
|
+
assertNotOut(noEntryExit, 'RETURN: 回源节点');
|
|
452
|
+
assertNodeLine(noEntryExit, 'review');
|
|
453
|
+
|
|
454
|
+
// ⑫ 旧态证据不足:无签名历史、无 Fix 标记 → 中性未分类 RETURN,不 BLOCK、不冒充 Fix、不卡死
|
|
455
|
+
writeIntakeArtifacts(dir);
|
|
456
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
457
|
+
'# TASK\n\n## 任务清单\n\n' + serialTaskBlock('T01', 'done') + '\n');
|
|
458
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', execSummaryFixture('T01'));
|
|
459
|
+
writeState(dir, {
|
|
460
|
+
activeChange: CHANGE_ID,
|
|
461
|
+
currentNode: 'execute',
|
|
462
|
+
completedNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute'],
|
|
463
|
+
enteredNodes: ['open', 'design', 'plan', 'execute', 'subagent-execute', 'review'],
|
|
464
|
+
evidence: { execute: { summary: 'first pass executed' }, review: { summary: 'review reopened' } },
|
|
465
|
+
verifyFailures: 0,
|
|
466
|
+
executionMode: 'subagent',
|
|
467
|
+
directOverride: false,
|
|
468
|
+
});
|
|
469
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-execute', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
470
|
+
assertExit(runState(['record', 'execute', '{"summary":"legacy state closure","parallelTakeoverApproved":true}'], dir, env), 0);
|
|
471
|
+
const legacyExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
472
|
+
assertExit(legacyExit, 0);
|
|
473
|
+
assertOut(legacyExit, 'RETURN: 回源节点 review(execute 出口已完成;旧 state 缺闭合/修复证据,未分类)');
|
|
474
|
+
assertNotOut(legacyExit, 'FIX-BATCH');
|
|
475
|
+
assertNotOut(legacyExit, 'BLOCKED');
|
|
476
|
+
assertNodeLine(legacyExit, 'review');
|
|
477
|
+
const legacyState = readStateFile(dir);
|
|
478
|
+
if (legacyState.currentNode !== 'review') {
|
|
479
|
+
throw new Error('旧态未分类回程应停在 review: ' + JSON.stringify(legacyState.currentNode));
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ⑬ 受控归位轮次真实链路(review 源):第 1~3 轮输出「第 n/3 轮」并递增计数;第 4 轮新
|
|
483
|
+
// change BLOCK(state 字节零改写、currentNode 保持 review);用户显式授权(嵌套证据)
|
|
484
|
+
// 后放行;verify 失败计数与轮次计数各自独立;旧 change 第 4 轮渐进 WARN 放行。
|
|
485
|
+
const fixRoundsText = (statuses) => '# TASK\n\n## 任务清单\n\n' + serialTaskBlock('T01', 'done')
|
|
486
|
+
+ '\n\n## Fix 任务(来自 REVIEW / INTEGRATION)\n\n'
|
|
487
|
+
+ statuses.map((s, i) => serialTaskBlock('T-FIX-0' + (i + 1), s)).join('\n') + '\n';
|
|
488
|
+
const doneStatuses = (n) => Array.from({ length: n }, () => 'done');
|
|
489
|
+
const assertRoundCounters = (round, label) => {
|
|
490
|
+
const s = readStateFile(dir);
|
|
491
|
+
if (s.fixRoundsByChange?.ch !== round) {
|
|
492
|
+
throw new Error(label + ' 受控归位轮次应为 ' + round + ': ' + JSON.stringify(s.fixRoundsByChange));
|
|
493
|
+
}
|
|
494
|
+
if (s.verifyFailuresByChange?.ch !== 2) {
|
|
495
|
+
throw new Error(label + ' 不得改写 verify 失败计数(应保持 2): ' + JSON.stringify(s.verifyFailuresByChange));
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
const completeFixRound = (n) => {
|
|
499
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixRoundsText(doneStatuses(n)));
|
|
500
|
+
for (let i = 1; i <= n; i++) {
|
|
501
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-0' + i + '-SUMMARY.md', execSummaryFixture('T-FIX-0' + i));
|
|
502
|
+
}
|
|
503
|
+
assertExit(runState(['skill-load', 'execute', 'flow-comet-execute', '--prompt', 'flow-kit/prompts/4-dev.md'], dir, env), 0);
|
|
504
|
+
// entry 记录 taskHash:签名值必须带算法版本前缀(新链路 vN 前缀形态)
|
|
505
|
+
assertExit(runGuard(['entry', 'execute'], dir, env), 0);
|
|
506
|
+
const stHash = readStateFile(dir);
|
|
507
|
+
if (!/^v1:[0-9a-f]{64}$/.test(String(stHash.taskHash))) {
|
|
508
|
+
throw new Error('execute entry 应写入带算法版本前缀的任务集签名: ' + JSON.stringify(stHash.taskHash));
|
|
509
|
+
}
|
|
510
|
+
assertExit(runState(['record', 'execute', '{"summary":"fix round ' + n + ' executed","parallelTakeoverApproved":true}'], dir, env), 0);
|
|
511
|
+
const closed = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
512
|
+
assertExit(closed, 0);
|
|
513
|
+
assertOut(closed, 'FIX-BATCH: 回源节点 review(execute 出口已完成)');
|
|
514
|
+
const stEvent = readStateFile(dir);
|
|
515
|
+
const lastExit = [...(stEvent.history || [])].reverse()
|
|
516
|
+
.find((e) => e.event === 'exit-applied' && e.node === 'execute');
|
|
517
|
+
if (!lastExit || lastExit.signatureAlgo !== 'v1' || !/^v1:[0-9a-f]{64}$/.test(String(lastExit.taskSetSignature))) {
|
|
518
|
+
throw new Error('execute 出口事件应携带算法版本元数据(signatureAlgo + vN 前缀签名): ' + JSON.stringify(lastExit));
|
|
519
|
+
}
|
|
520
|
+
if (stEvent.currentNode !== 'review') {
|
|
521
|
+
throw new Error('第 ' + n + ' 轮收口应回到未完成的 review: ' + JSON.stringify(stEvent.currentNode));
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending' });
|
|
526
|
+
// verify 失败计数先落到 2——后续 4 轮归位都不得触碰该值
|
|
527
|
+
assertExit(runState(['verify-fail'], dir, env), 0);
|
|
528
|
+
const vfTwo = runState(['verify-fail'], dir, env);
|
|
529
|
+
assertExit(vfTwo, 0);
|
|
530
|
+
assertOut(vfTwo, 'VERIFY-FAIL: 2/3');
|
|
531
|
+
for (let round = 1; round <= 3; round++) {
|
|
532
|
+
const rollback = runState(['next'], dir, env);
|
|
533
|
+
assertExit(rollback, 0);
|
|
534
|
+
assertOut(rollback, 'FIX-BATCH: 归位 execute(源节点 review)');
|
|
535
|
+
assertOut(rollback, '(第 ' + round + '/3 轮)');
|
|
536
|
+
assertRoundCounters(round, '第 ' + round + ' 轮');
|
|
537
|
+
completeFixRound(round);
|
|
538
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixRoundsText([...doneStatuses(round), 'pending']));
|
|
539
|
+
}
|
|
540
|
+
// 第 4 轮:新 change BLOCK;state 字节零改写、currentNode 保持 review、轮次仍为 3
|
|
541
|
+
const round4Bytes = fs.readFileSync(statePath, 'utf8');
|
|
542
|
+
const round4Block = runState(['next'], dir, env);
|
|
543
|
+
assertExit(round4Block, 1);
|
|
544
|
+
assertOut(round4Block, 'BLOCKED');
|
|
545
|
+
assertOut(round4Block, '第 4 轮需用户决策');
|
|
546
|
+
assertOut(round4Block, '继续修');
|
|
547
|
+
assertOut(round4Block, '停止');
|
|
548
|
+
assertOut(round4Block, 'fixRoundOverride');
|
|
549
|
+
if (fs.readFileSync(statePath, 'utf8') !== round4Bytes) {
|
|
550
|
+
throw new Error('第 4 轮 BLOCK 不得改写 state 字节(currentNode/计数均不得变化)');
|
|
551
|
+
}
|
|
552
|
+
let round4State = readStateFile(dir);
|
|
553
|
+
if (round4State.currentNode !== 'review') {
|
|
554
|
+
throw new Error('第 4 轮 BLOCK 不得改写 currentNode: ' + JSON.stringify(round4State.currentNode));
|
|
555
|
+
}
|
|
556
|
+
assertRoundCounters(3, '第 4 轮 BLOCK 后');
|
|
557
|
+
// F5 真实链路:不完整授权(仅 round,缺 at/source)按未授权 fail-closed——仍 BLOCK 且
|
|
558
|
+
// state 字节零改写;随后补全完整三元组才放行(BLOCK → 非法形态仍 BLOCK → 完整授权 → 放行)。
|
|
559
|
+
round4State.evidence.review = {
|
|
560
|
+
...(round4State.evidence.review || {}),
|
|
561
|
+
fixRoundOverride: { round: 4 },
|
|
562
|
+
};
|
|
563
|
+
writeState(dir, round4State);
|
|
564
|
+
const incompleteBytes = fs.readFileSync(statePath, 'utf8');
|
|
565
|
+
const round4Incomplete = runState(['next'], dir, env);
|
|
566
|
+
assertExit(round4Incomplete, 1);
|
|
567
|
+
assertOut(round4Incomplete, 'BLOCKED');
|
|
568
|
+
assertNotOut(round4Incomplete, '(第 4/3 轮)');
|
|
569
|
+
if (fs.readFileSync(statePath, 'utf8') !== incompleteBytes) {
|
|
570
|
+
throw new Error('F5 缺 at/source 的不完整授权必须 fail-closed:state 字节零改写');
|
|
571
|
+
}
|
|
572
|
+
assertRoundCounters(3, 'F5 不完整授权 BLOCK 后');
|
|
573
|
+
if (readStateFile(dir).currentNode !== 'review') {
|
|
574
|
+
throw new Error('F5 不完整授权不得改写 currentNode(应保持 review)');
|
|
575
|
+
}
|
|
576
|
+
// 用户显式授权:嵌套 evidence 补全 round/at/source 三元组 → 同一入口放行第 4 轮
|
|
577
|
+
round4State = readStateFile(dir);
|
|
578
|
+
round4State.evidence.review = {
|
|
579
|
+
...(round4State.evidence.review || {}),
|
|
580
|
+
fixRoundOverride: { round: 4, at: new Date().toISOString(), source: 'user' },
|
|
581
|
+
};
|
|
582
|
+
writeState(dir, round4State);
|
|
583
|
+
const round4Authorized = runState(['next'], dir, env);
|
|
584
|
+
assertExit(round4Authorized, 0);
|
|
585
|
+
assertOut(round4Authorized, 'FIX-BATCH: 归位 execute(源节点 review)(第 4/3 轮)');
|
|
586
|
+
round4State = readStateFile(dir);
|
|
587
|
+
if (round4State.currentNode !== 'execute' || round4State.fixRoundsByChange?.ch !== 4) {
|
|
588
|
+
throw new Error('授权后应放行第 4 轮并计数到 4: '
|
|
589
|
+
+ JSON.stringify({ currentNode: round4State.currentNode, rounds: round4State.fixRoundsByChange }));
|
|
590
|
+
}
|
|
591
|
+
completeFixRound(4);
|
|
592
|
+
// 轮次计数不影响 verify 预算:同一 change 继续失败到 3/3 仍可用,第 4 次才超限
|
|
593
|
+
const vfThree = runState(['verify-fail'], dir, env);
|
|
594
|
+
assertExit(vfThree, 0);
|
|
595
|
+
assertOut(vfThree, 'VERIFY-FAIL: 3/3');
|
|
596
|
+
const vfFour = runState(['verify-fail'], dir, env);
|
|
597
|
+
assertExit(vfFour, 1);
|
|
598
|
+
assertOut(vfFour, '超限');
|
|
599
|
+
if (readStateFile(dir).fixRoundsByChange?.ch !== 4) {
|
|
600
|
+
throw new Error('verify 失败累计不得改写 Fix 轮次计数: ' + JSON.stringify(readStateFile(dir).fixRoundsByChange));
|
|
601
|
+
}
|
|
602
|
+
// 旧 change 第 4 轮渐进:WARN 后照常归位(不 BLOCK、不卡死)
|
|
603
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'pending', newChange: false });
|
|
604
|
+
const oldRoundState = readStateFile(dir);
|
|
605
|
+
oldRoundState.fixRoundsByChange = { ch: 3 };
|
|
606
|
+
writeState(dir, oldRoundState);
|
|
607
|
+
const oldRound4 = runState(['next'], dir, env);
|
|
608
|
+
assertExit(oldRound4, 0);
|
|
609
|
+
assertOut(oldRound4, 'FIX-BATCH WARN');
|
|
610
|
+
assertOut(oldRound4, '(第 4/3 轮)');
|
|
611
|
+
assertNotOut(oldRound4, 'BLOCKED');
|
|
612
|
+
const oldRoundAfter = readStateFile(dir);
|
|
613
|
+
if (oldRoundAfter.currentNode !== 'execute' || oldRoundAfter.fixRoundsByChange?.ch !== 4) {
|
|
614
|
+
throw new Error('旧 change 第 4 轮应渐进归位并计数: '
|
|
615
|
+
+ JSON.stringify({ currentNode: oldRoundAfter.currentNode, rounds: oldRoundAfter.fixRoundsByChange }));
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// ⑭ 签名算法版本可判别(真实命令链路):跨版本(v2 事件 vs 当前 v1)不做同版本比对——
|
|
619
|
+
// 不得把正常回程误判为未闭合 Fix;同版本 legacy 裸 hex 按既有语义参与(②⑤ 已锚)。
|
|
620
|
+
writeFixBatchFixture(dir, { kind: 'review', fixStatus: 'done' });
|
|
621
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T-FIX-01-SUMMARY.md', execSummaryFixture('T-FIX-01'));
|
|
622
|
+
const versionSkewState = readStateFile(dir);
|
|
623
|
+
versionSkewState.history = [{
|
|
624
|
+
event: 'exit-applied', node: 'execute', change: CHANGE_ID, at: '2026-09-20T00:00:00.000Z',
|
|
625
|
+
taskSetSignature: 'v2:' + '0'.repeat(64), signatureAlgo: 'v2',
|
|
626
|
+
}];
|
|
627
|
+
writeState(dir, versionSkewState);
|
|
628
|
+
// 清掉本项先前 verify 子场景遗留的 TEST/UAT,使回程路由确定为 verify(夹具前提)
|
|
629
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID, 'TEST.md'), { force: true });
|
|
630
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID, 'UAT.md'), { force: true });
|
|
631
|
+
assertExit(runState(['skill-load', 'review', 'flow-comet-review', '--prompt', 'flow-kit/prompts/6-review.md'], dir, env), 0);
|
|
632
|
+
assertExit(runGuard(['entry', 'review'], dir, env), 0);
|
|
633
|
+
const skewExit = runGuard(['exit', 'review', '--apply'], dir, env);
|
|
634
|
+
assertExit(skewExit, 0);
|
|
635
|
+
assertOut(skewExit, 'ALL CHECKS PASSED');
|
|
636
|
+
assertNotOut(skewExit, 'BLOCKED: 存在未归位/未跑出口的 Fix 批次');
|
|
637
|
+
assertNodeLine(skewExit, 'verify');
|
|
638
|
+
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
|
|
642
|
+
// ---------- B. 声明机制(skill-load / record / exit 校验) ----------
|
|
643
|
+
|
|
644
|
+
{
|
|
645
|
+
name: 'B1 skill-load:声明标记写入(协议归属)',
|
|
646
|
+
run: (dir) => {
|
|
647
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
648
|
+
writeFile(dir, 'flow-kit/prompts/0-change.md', '# 阶段 0 · CHANGE\n\n## 角色\n\n你是 Changeer。\n');
|
|
649
|
+
const res = runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir);
|
|
650
|
+
assertExit(res, 0);
|
|
651
|
+
assertOut(res, 'SKILL-LOAD: open flow-comet-change');
|
|
652
|
+
const markerPath = path.join(dir, '.specs', CHANGE_ID, '.skill-loads', 'open-flow-comet-change.json');
|
|
653
|
+
if (!fs.existsSync(markerPath)) throw new Error('标记文件未生成: ' + markerPath);
|
|
654
|
+
const marker = JSON.parse(fs.readFileSync(markerPath, 'utf8'));
|
|
655
|
+
if (marker.node !== 'open' || marker.skill !== 'flow-comet-change') {
|
|
656
|
+
throw new Error('标记 node/skill 字段不符: ' + JSON.stringify(marker));
|
|
657
|
+
}
|
|
658
|
+
if (marker.protocol !== '0-change.md') {
|
|
659
|
+
throw new Error('标记 protocol 应为 --prompt 参数的 basename: ' + JSON.stringify(marker.protocol));
|
|
660
|
+
}
|
|
661
|
+
if (typeof marker.at !== 'string' || Number.isNaN(Date.parse(marker.at))) {
|
|
662
|
+
throw new Error('标记缺 ISO 时间戳: ' + JSON.stringify(marker));
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
{
|
|
668
|
+
name: 'B2 skill-load:非法参数拒绝且不落标记',
|
|
669
|
+
run: (dir) => {
|
|
670
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
671
|
+
const noArgs = runState(['skill-load'], dir);
|
|
672
|
+
assertExit(noArgs, 1);
|
|
673
|
+
assertOut(noArgs, 'skill-load requires <node> <skill>');
|
|
674
|
+
const badNode = runState(['skill-load', 'bogus', 'flow-comet-change'], dir);
|
|
675
|
+
assertExit(badNode, 1);
|
|
676
|
+
assertOut(badNode, 'skill-load node 非法');
|
|
677
|
+
const badSkill = runState(['skill-load', 'open', 'bad/name'], dir);
|
|
678
|
+
assertExit(badSkill, 1);
|
|
679
|
+
assertOut(badSkill, 'skill-load skill 名非法');
|
|
680
|
+
// --prompt 越界(不在 flow-kit/prompts/ 下)
|
|
681
|
+
const badPrompt = runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'reference/workflow-protocol.json'], dir);
|
|
682
|
+
assertExit(badPrompt, 1);
|
|
683
|
+
assertOut(badPrompt, 'skill-load --prompt 路径必须位于 flow-kit/prompts/ 下');
|
|
684
|
+
// 全部拒绝后 .skill-loads/ 不产生任何标记
|
|
685
|
+
const loadsDir = path.join(dir, '.specs', CHANGE_ID, '.skill-loads');
|
|
686
|
+
if (fs.existsSync(loadsDir) && fs.readdirSync(loadsDir).length > 0) {
|
|
687
|
+
throw new Error('非法参数不应写入标记: ' + fs.readdirSync(loadsDir).join(', '));
|
|
688
|
+
}
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
|
|
692
|
+
{
|
|
693
|
+
name: 'B3 record:缺声明标记拦截',
|
|
694
|
+
run: (dir) => {
|
|
695
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
696
|
+
const res = runState(['record', 'open', JSON.stringify({ summary: 'done', completedChecks: ['required-skill:open.flow-comet-change'] })], dir);
|
|
697
|
+
assertExit(res, 1);
|
|
698
|
+
assertOut(res, 'BLOCKED');
|
|
699
|
+
assertOut(res, '缺少对应声明标记');
|
|
700
|
+
assertOut(res, 'workflow-state.mjs skill-load open flow-comet-change');
|
|
701
|
+
// 拦截先于写入——evidence 不得落库
|
|
702
|
+
const st = readStateFile(dir);
|
|
703
|
+
if (st.evidence && st.evidence.open) throw new Error('拦截后不应写入 evidence: ' + JSON.stringify(st.evidence.open));
|
|
704
|
+
},
|
|
705
|
+
},
|
|
706
|
+
|
|
707
|
+
{
|
|
708
|
+
name: 'B4 record:声明后记录通过',
|
|
709
|
+
run: (dir) => {
|
|
710
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
711
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change'], dir), 0);
|
|
712
|
+
const res = runState(['record', 'open', JSON.stringify({ summary: 'done', completedChecks: ['required-skill:open.flow-comet-change'] })], dir);
|
|
713
|
+
assertExit(res, 0);
|
|
714
|
+
assertOut(res, 'EVIDENCE: open');
|
|
715
|
+
const st = readStateFile(dir);
|
|
716
|
+
if (!st.evidence.open || st.evidence.open.summary !== 'done') {
|
|
717
|
+
throw new Error('record 未写入 evidence: ' + JSON.stringify(st.evidence));
|
|
718
|
+
}
|
|
719
|
+
},
|
|
720
|
+
},
|
|
721
|
+
|
|
722
|
+
{
|
|
723
|
+
name: 'B5 record:声明时间序自洽拦截',
|
|
724
|
+
run: (dir) => {
|
|
725
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
726
|
+
// 标记 at 晚于记录时间(手工构造未来时间戳)→ 标记必须先于记录声明
|
|
727
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/open-flow-comet-change.json',
|
|
728
|
+
JSON.stringify({ node: 'open', skill: 'flow-comet-change', protocol: '0-change.md', at: '2999-12-31T00:00:00.000Z' }, null, 2) + '\n');
|
|
729
|
+
const res = runState(['record', 'open', JSON.stringify({ summary: 'done', completedChecks: ['required-skill:open.flow-comet-change'] })], dir);
|
|
730
|
+
assertExit(res, 1);
|
|
731
|
+
assertOut(res, 'BLOCKED');
|
|
732
|
+
assertOut(res, '标记必须先于记录声明');
|
|
733
|
+
},
|
|
734
|
+
},
|
|
735
|
+
|
|
736
|
+
{
|
|
737
|
+
name: 'B6 record:损坏声明标记 fail-closed',
|
|
738
|
+
run: (dir) => {
|
|
739
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
740
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/open-flow-comet-change.json', '{oops\n');
|
|
741
|
+
const res = runState(['record', 'open', JSON.stringify({ summary: 'done', completedChecks: ['required-skill:open.flow-comet-change'] })], dir);
|
|
742
|
+
assertExit(res, 1);
|
|
743
|
+
assertOut(res, 'BLOCKED');
|
|
744
|
+
assertOut(res, '声明标记损坏');
|
|
745
|
+
},
|
|
746
|
+
},
|
|
747
|
+
|
|
748
|
+
{
|
|
749
|
+
name: 'B7 record:委托范围条目豁免(有委托通过 / 无委托拦截)',
|
|
750
|
+
run: (dir) => {
|
|
751
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
752
|
+
assertExit(runState(['skill-load', 'subagent-execute', 'flow-comet-dev'], dir), 0);
|
|
753
|
+
const payload = JSON.stringify({ summary: 'delegated', completedChecks: ['required-skill:subagent-execute.flow-comet-dev'] });
|
|
754
|
+
// 无委托记录 → 拦截(handoff scope 条目以共用证据库的委托记录为证据)
|
|
755
|
+
const blocked = runState(['record', 'subagent-execute', payload], dir);
|
|
756
|
+
assertExit(blocked, 1);
|
|
757
|
+
assertOut(blocked, 'BLOCKED');
|
|
758
|
+
assertOut(blocked, '无委托记录');
|
|
759
|
+
// 委托并回传契约后 → 通过(request 声明边界——新 change 强制 write_files 来源)
|
|
760
|
+
assertExit(runHandoff(['request', 'T01', 'T01 委托', '--write-files', 'src/t1.mjs'], dir), 0);
|
|
761
|
+
assertExit(runHandoff(['result', 'T01', JSON.stringify({
|
|
762
|
+
commitHash: 'deadbeef',
|
|
763
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
764
|
+
greenEvidence: { command: 'node --check src/t1.mjs' },
|
|
765
|
+
redEvidence: { command: 'node --check src/t1.mjs' },
|
|
766
|
+
})], dir), 0);
|
|
767
|
+
const pass = runState(['record', 'subagent-execute', payload], dir);
|
|
768
|
+
assertExit(pass, 0);
|
|
769
|
+
assertOut(pass, 'EVIDENCE: subagent-execute');
|
|
770
|
+
},
|
|
771
|
+
},
|
|
772
|
+
|
|
773
|
+
{
|
|
774
|
+
name: 'B8 exit:协议声明标记校验(record 自动补通过 / 手动声明 / 空协议·损坏拦截)',
|
|
775
|
+
run: (dir) => {
|
|
776
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
777
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
778
|
+
writeIntakeArtifacts(dir);
|
|
779
|
+
writeFile(dir, 'flow-kit/prompts/0-change.md', '# 阶段 0 · CHANGE\n\n## 角色\n\n你是 Changeer。\n');
|
|
780
|
+
// ① M5: record 自动补声明标记 → 出口通过(无需手动 skill-load)
|
|
781
|
+
assertExit(runState(['record', 'open', '{"summary":"intake complete"}'], dir), 0);
|
|
782
|
+
const autoMarker = path.join(dir, '.specs', CHANGE_ID, '.skill-loads', 'open-flow-comet-change.json');
|
|
783
|
+
if (!fs.existsSync(autoMarker)) throw new Error('record 自动声明标记缺失: open-flow-comet-change.json');
|
|
784
|
+
assertExit(runGuard(['entry', 'open'], dir), 0);
|
|
785
|
+
const rAuto = runGuard(['exit', 'open'], dir);
|
|
786
|
+
assertExit(rAuto, 0);
|
|
787
|
+
assertOut(rAuto, 'ALL CHECKS PASSED');
|
|
788
|
+
assertNotOut(rAuto, 'BLOCKED');
|
|
789
|
+
// ② 手动 skill-load --prompt(protocol = basename)覆盖自动标记 → 出口通过
|
|
790
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
791
|
+
const rPass = runGuard(['exit', 'open'], dir);
|
|
792
|
+
assertExit(rPass, 0);
|
|
793
|
+
assertOut(rPass, 'ALL CHECKS PASSED');
|
|
794
|
+
assertNotOut(rPass, 'BLOCKED');
|
|
795
|
+
// ③ 未传 --prompt → 标记 protocol = null → 拦截(fail-closed;open 两个 requiredSkillCalls 均覆盖为 null)
|
|
796
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change'], dir), 0);
|
|
797
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-requirement'], dir), 0);
|
|
798
|
+
const rNull = runGuard(['exit', 'open'], dir);
|
|
799
|
+
assertExit(rNull, 1);
|
|
800
|
+
assertOut(rNull, 'exit 缺协议声明标记');
|
|
801
|
+
// ④ 损坏标记(protocol 非本节点协议集)→ 拦截(fail-closed)
|
|
802
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/.skill-loads/open-flow-comet-change.json',
|
|
803
|
+
JSON.stringify({ node: 'open', skill: 'flow-comet-change', protocol: '9-other.md', at: '2026-08-01T00:00:00.000Z' }, null, 2) + '\n');
|
|
804
|
+
const rCorrupt = runGuard(['exit', 'open'], dir);
|
|
805
|
+
assertExit(rCorrupt, 1);
|
|
806
|
+
assertOut(rCorrupt, 'exit 缺协议声明标记');
|
|
807
|
+
},
|
|
808
|
+
},
|
|
809
|
+
|
|
810
|
+
{
|
|
811
|
+
name: 'B9 旧项目兼容:record 自动补声明后照常通过',
|
|
812
|
+
run: (dir) => {
|
|
813
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
814
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
815
|
+
// 旧格式记录:completedChecks 无 required-skill 条目 → 不校验标记,通过
|
|
816
|
+
const rA = runState(['record', 'open', JSON.stringify({ summary: 'legacy', completedChecks: ['unit-tests'] })], dir);
|
|
817
|
+
assertExit(rA, 0);
|
|
818
|
+
assertOut(rA, 'EVIDENCE: open');
|
|
819
|
+
// 无 completedChecks 的纯 summary 记录 → 通过(record 自动补声明标记)
|
|
820
|
+
assertExit(runState(['record', 'open', JSON.stringify({ summary: 'plain' })], dir), 0);
|
|
821
|
+
// 出口:record 已自动补标记 → 无兼容警告,正常通过
|
|
822
|
+
writeIntakeArtifacts(dir);
|
|
823
|
+
assertExit(runGuard(['entry', 'open'], dir), 0);
|
|
824
|
+
const rC = runGuard(['exit', 'open'], dir);
|
|
825
|
+
assertExit(rC, 0);
|
|
826
|
+
assertOut(rC, 'ALL CHECKS PASSED');
|
|
827
|
+
assertNotOut(rC, 'SKILL-LOAD WARN');
|
|
828
|
+
},
|
|
829
|
+
},
|
|
830
|
+
];
|