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,1484 @@
|
|
|
1
|
+
// 场景组 l — 时间形态与单源结构锚 · 侧命令(evolve / health / context-scan)与 ui-design 门
|
|
2
|
+
// 元素形态:`{ name, run }`;计数由 `lib/count-derivation.mjs` 从本目录聚合,不手抄数字。
|
|
3
|
+
// 组界按场景名前缀与文件内既有分段划,与入口 `SCENARIOS` 的拼接顺序一致。
|
|
4
|
+
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import {
|
|
8
|
+
assertEqual,
|
|
9
|
+
assertExit,
|
|
10
|
+
assertNotOut,
|
|
11
|
+
assertOut,
|
|
12
|
+
assertTrue,
|
|
13
|
+
baseState,
|
|
14
|
+
cleanupTmpDir,
|
|
15
|
+
runGuard,
|
|
16
|
+
writeFile,
|
|
17
|
+
writeState,
|
|
18
|
+
} from '../lib/test-helpers.mjs';
|
|
19
|
+
import {
|
|
20
|
+
CHANGE_ID,
|
|
21
|
+
REPO_ROOT,
|
|
22
|
+
SCRIPTS_DIR,
|
|
23
|
+
SIDE_CONTEXT_SCAN,
|
|
24
|
+
SIDE_EVOLVE,
|
|
25
|
+
SIDE_HEALTH,
|
|
26
|
+
SKILL_PROTOCOL_FILE,
|
|
27
|
+
contextInitModule,
|
|
28
|
+
copyEngineTree,
|
|
29
|
+
engineConsumersOf,
|
|
30
|
+
engineDefinitionHits,
|
|
31
|
+
engineScriptTexts,
|
|
32
|
+
fingerprintChanges,
|
|
33
|
+
handoffFor,
|
|
34
|
+
hasNamedImport,
|
|
35
|
+
makeTmp,
|
|
36
|
+
requireModuleExport,
|
|
37
|
+
runSideScript,
|
|
38
|
+
skillTreeDocFiles,
|
|
39
|
+
skillsRootForScriptsDir,
|
|
40
|
+
stateSchemaModule,
|
|
41
|
+
timeSingleSourceConsumerProblems,
|
|
42
|
+
timeUtilsModule,
|
|
43
|
+
treeFingerprint,
|
|
44
|
+
} from '../lib/test-fixtures.mjs';
|
|
45
|
+
import {
|
|
46
|
+
REPLAN_STALE_SIGNATURE,
|
|
47
|
+
REPLAN_TASK_INITIAL,
|
|
48
|
+
assertStateBytesUnchanged,
|
|
49
|
+
parseStatusJson,
|
|
50
|
+
readScenarioState,
|
|
51
|
+
readStateBytes,
|
|
52
|
+
replanBackupFiles,
|
|
53
|
+
replanEventsOf,
|
|
54
|
+
replanExecuteState,
|
|
55
|
+
runGuardWithProtocol,
|
|
56
|
+
runStateWithProtocol,
|
|
57
|
+
} from '../lib/test-assertions.mjs';
|
|
58
|
+
import {
|
|
59
|
+
ATOMIC_TEMP_SUFFIX_RE,
|
|
60
|
+
EVOLVE_METADATA_FIELD_LINES,
|
|
61
|
+
FRONTEND_CRITERION_AUTHORITY_REL,
|
|
62
|
+
FRONTEND_CRITERION_POINTER_RELS,
|
|
63
|
+
FRONTEND_CRITERION_STRUCTURE_GROUPS,
|
|
64
|
+
REPO_CONTEXT_FILE,
|
|
65
|
+
VISUAL_TONE_APPLICABLE,
|
|
66
|
+
VISUAL_TONE_FIELD_MARKER,
|
|
67
|
+
VISUAL_TONE_LINE_HEAD_MARKER,
|
|
68
|
+
VISUAL_TONE_NATURAL_SENTENCE,
|
|
69
|
+
VISUAL_TONE_NOT_APPLICABLE,
|
|
70
|
+
VISUAL_TONE_SUBDIMENSION_FIELD,
|
|
71
|
+
atomicWriteIdiomHits,
|
|
72
|
+
contextFixtureText,
|
|
73
|
+
frontendCriterionAuthorityBlock,
|
|
74
|
+
frontendCriterionProseProblems,
|
|
75
|
+
frontendCriterionRedirectProblems,
|
|
76
|
+
intelFieldToken,
|
|
77
|
+
singleSourceImportProblems,
|
|
78
|
+
uniqueTempNameHits,
|
|
79
|
+
writeDesignExitFixture,
|
|
80
|
+
writeUiDesignBindingVariant,
|
|
81
|
+
} from '../lib/text-anchor-checks.mjs';
|
|
82
|
+
|
|
83
|
+
export const ENTRIES = [
|
|
84
|
+
|
|
85
|
+
// 274: M6 收窄——空退出豁免仅适用于「无任何串行任务」的全并行 change;含串行任务
|
|
86
|
+
// (parallel="false"/缺省,无论 pending/done)时豁免不生效,产物校验照常执行。
|
|
87
|
+
// 夹具用旧 change 语义(无 newChange):done 缺 SUMMARY 在 M2 只 WARN → 放行与否
|
|
88
|
+
// 唯一取决于 M6 是否跳过 task-summaries 产物校验(隔离判据;新 change 由 M2 硬门先行,
|
|
89
|
+
// 无法观察 M6 行为)。修复前 emptyExitApproved 无条件跳过 → exit 0(本场景 RED)。
|
|
90
|
+
{
|
|
91
|
+
name: '274 execute exit BLOCKED:含串行任务的 change 空退出豁免不生效(M6 收窄)',
|
|
92
|
+
run: (dir) => {
|
|
93
|
+
const st = baseState('execute');
|
|
94
|
+
st.evidence.execute = { summary: '陈旧空退出标记', emptyExitApproved: true };
|
|
95
|
+
st.evidence['subagent-execute'] = { handoffResult: handoffFor(['T01']) };
|
|
96
|
+
writeState(dir, st);
|
|
97
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
98
|
+
'# TASK\n\n<task id="T01" parallel="false" status="done"><action>串行任务已完成但缺 SUMMARY</action><write_files>src/t1.mjs</write_files><verify>node --check src/t1.mjs</verify></task>\n');
|
|
99
|
+
const res = runGuard(['exit', 'execute', '--apply'], dir);
|
|
100
|
+
assertExit(res, 1);
|
|
101
|
+
assertOut(res, 'BLOCKED');
|
|
102
|
+
assertOut(res, 'task-summaries');
|
|
103
|
+
assertOut(res, 'EMPTY-EXIT 未生效');
|
|
104
|
+
assertNotOut(res, '豁免已生效');
|
|
105
|
+
// 反向子锚:全并行 change 时豁免仍生效,且输出被跳过项清单(补既有全 parallel 通过锚)
|
|
106
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
107
|
+
'# TASK\n\n<task id="P01" parallel="true" status="pending"><action>并行任务</action><write_files>src/p1.mjs</write_files><verify>node --check src/p1.mjs</verify></task>\n');
|
|
108
|
+
const resParallel = runGuard(['exit', 'execute', '--apply'], dir);
|
|
109
|
+
assertExit(resParallel, 0);
|
|
110
|
+
assertOut(resParallel, '豁免已生效');
|
|
111
|
+
assertOut(resParallel, 'EMPTY-EXIT-SKIPPED');
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
// 275: replan 任务内容缺失 fail-closed(引擎既有分支的回归锚)——TASK.md 不存在 / 为空(0 字节)
|
|
115
|
+
// 时,真实 CLI 的 replan 必须 BLOCKED、消息给出 fail-closed 指引,且 state 字节零改写、零备份、
|
|
116
|
+
// 零审计事件(判定必须先于任何写盘;不得以「空任务集签名」判幂等空操作放行)。纯空白是边界:
|
|
117
|
+
// 非空串不落 task-content-missing,但同样 fail-closed 拒绝重签(无 <task> 块)。对照:同一夹具
|
|
118
|
+
// 下 TASK.md 恢复为可解析任务集 → replan 放行(证明 BLOCK 来自内容缺失而非夹具畸形)。
|
|
119
|
+
{
|
|
120
|
+
name: '275 replan 任务内容缺失/为空 → BLOCKED fail-closed 零改写(含放行对照)',
|
|
121
|
+
run: (dir) => {
|
|
122
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/CHANGE.md', '# CHANGE\n\n## Why\n\n任务内容缺失回归锚。\n');
|
|
123
|
+
writeState(dir, replanExecuteState({ taskHash: REPLAN_STALE_SIGNATURE }));
|
|
124
|
+
const beforeBytes = readStateBytes(dir);
|
|
125
|
+
const blockedCases = [
|
|
126
|
+
['TASK.md 缺失', null],
|
|
127
|
+
['TASK.md 为空(0 字节)', ''],
|
|
128
|
+
];
|
|
129
|
+
for (const [label, content] of blockedCases) {
|
|
130
|
+
if (content === null) {
|
|
131
|
+
fs.rmSync(path.join(dir, '.specs', CHANGE_ID, 'TASK.md'), { force: true });
|
|
132
|
+
} else {
|
|
133
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', content);
|
|
134
|
+
}
|
|
135
|
+
const res = runStateWithProtocol(dir, ['replan', '计划缺陷重校', '--authorized-by', 'user-approval']);
|
|
136
|
+
assertExit(res, 1);
|
|
137
|
+
assertOut(res, 'BLOCKED');
|
|
138
|
+
assertOut(res, '任务内容缺失');
|
|
139
|
+
assertOut(res, 'fail-closed');
|
|
140
|
+
assertOut(res, 'TASK.md');
|
|
141
|
+
assertStateBytesUnchanged(dir, beforeBytes, label);
|
|
142
|
+
}
|
|
143
|
+
// 边界:纯空白非空串 → 不落 task-content-missing,但同样拒绝重签(无 <task> 块),零改写
|
|
144
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', ' \n');
|
|
145
|
+
const blank = runStateWithProtocol(dir, ['replan', '计划缺陷重校', '--authorized-by', 'user-approval']);
|
|
146
|
+
assertExit(blank, 1);
|
|
147
|
+
assertOut(blank, 'BLOCKED');
|
|
148
|
+
assertOut(blank, '无 <task> 块');
|
|
149
|
+
assertOut(blank, '零改写');
|
|
150
|
+
assertStateBytesUnchanged(dir, beforeBytes, 'TASK.md 纯空白');
|
|
151
|
+
// 三条 BLOCK 路径都不得产生备份 / 审计事件(写盘前拦截)
|
|
152
|
+
if (replanBackupFiles(dir).length !== 0) {
|
|
153
|
+
throw new Error('内容缺失路径不得产生备份: ' + JSON.stringify(replanBackupFiles(dir)));
|
|
154
|
+
}
|
|
155
|
+
if (replanEventsOf(readScenarioState(dir)).length !== 0) {
|
|
156
|
+
throw new Error('内容缺失路径不得写审计事件: ' + JSON.stringify(replanEventsOf(readScenarioState(dir))));
|
|
157
|
+
}
|
|
158
|
+
// 放行对照:同夹具下 TASK.md 可解析 → replan 真实重签成功(判别力:BLOCK 不是夹具畸形导致)
|
|
159
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', REPLAN_TASK_INITIAL);
|
|
160
|
+
const ok = runStateWithProtocol(dir, ['replan', '计划缺陷重校', '--authorized-by', 'user-approval']);
|
|
161
|
+
assertExit(ok, 0);
|
|
162
|
+
assertOut(ok, 'REPLAN');
|
|
163
|
+
if (replanEventsOf(readScenarioState(dir)).length !== 1) {
|
|
164
|
+
throw new Error('放行对照应恰写 1 条 replan-applied 事件');
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
|
|
169
|
+
// 276: 时间形态三态——本地 `+HH:mm` 与历史 `Z`(含毫秒)合法且解析等值;纯日期 / 缺时区 /
|
|
170
|
+
// 偏移缺冒号 / 日历不自洽(2026-02-30,Date.parse 会静默滚动)一律非法。判据走 time-utils
|
|
171
|
+
// 的导出(与消费脚本同一实现,不在套件里复制第二份)。
|
|
172
|
+
{
|
|
173
|
+
name: '276 时间形态三态:本地 +HH:mm / 历史 Z(含毫秒)合法等值,形态不符与日历不自洽非法',
|
|
174
|
+
run: () => {
|
|
175
|
+
const parse = requireModuleExport(timeUtilsModule, 'parseTimestamp', 'time-utils.mjs');
|
|
176
|
+
const format = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
177
|
+
const isValid = requireModuleExport(timeUtilsModule, 'isValidTimestamp', 'time-utils.mjs');
|
|
178
|
+
|
|
179
|
+
const localWithOffset = '2026-10-02T18:30:00+08:00';
|
|
180
|
+
const zulu = '2026-10-02T10:30:00Z';
|
|
181
|
+
const zuluMillis = '2026-10-02T10:30:00.500Z';
|
|
182
|
+
assertEqual(parse(localWithOffset), Date.parse(localWithOffset), '本地 +HH:mm 形态解析');
|
|
183
|
+
assertEqual(parse(zulu), Date.parse(zulu), '历史 Z 形态解析');
|
|
184
|
+
assertEqual(parse(zuluMillis), Date.parse(zuluMillis), '历史 Z + 毫秒解析');
|
|
185
|
+
assertEqual(parse(localWithOffset), parse(zulu), '同一时刻的两种形态解析等值');
|
|
186
|
+
assertEqual(parse(zuluMillis) - parse(zulu), 500, '毫秒分量参与解析');
|
|
187
|
+
|
|
188
|
+
const illegal = [
|
|
189
|
+
['2026-10-02', '纯日期(无法表达时刻)'],
|
|
190
|
+
['2026-10-02T10:30:00', '缺时区'],
|
|
191
|
+
['2026-10-02T10:30:00+0800', '偏移缺冒号'],
|
|
192
|
+
['2026-10-02T10:30:00+24:00', '偏移越界'],
|
|
193
|
+
['2026-10-02T10:30:00-08:60', '偏移分钟越界'],
|
|
194
|
+
['2026-02-30T00:00:00Z', '日历不自洽'],
|
|
195
|
+
['2026-13-01T00:00:00Z', '月份越界'],
|
|
196
|
+
['不是时间', '垃圾值'],
|
|
197
|
+
['', '空串'],
|
|
198
|
+
[null, '非字符串'],
|
|
199
|
+
];
|
|
200
|
+
for (const [value, label] of illegal) {
|
|
201
|
+
assertTrue(Number.isNaN(parse(value)),
|
|
202
|
+
'非法形态未被拒绝: ' + label + ' = ' + JSON.stringify(value));
|
|
203
|
+
assertTrue(!isValid(value), 'isValidTimestamp 未拒绝非法形态: ' + label);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// 生成侧:本地时间 + 显式偏移;生成 → 解析回环等值(秒级精度)
|
|
207
|
+
const instant = Date.parse('2026-10-02T10:30:15Z');
|
|
208
|
+
const formatted = format(new Date(instant));
|
|
209
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(formatted),
|
|
210
|
+
'生成形态非「本地时间 + 显式偏移」: ' + formatted);
|
|
211
|
+
assertEqual(parse(formatted), instant, '生成 → 解析回环');
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
|
|
215
|
+
// 277: 单源结构锚——时间与窗口判据(formatLocalTimestamp / nowTimestamp / parseTimestamp /
|
|
216
|
+
// hasSection9 / isArchivedAfterTimestamp)在全引擎**各只有一处定义**,消费方(**消费面 = 入口 ∪
|
|
217
|
+
// `lib/**`**,由真实引用派生,不写文件名清单)一律从 time-utils 取值(含 init 写扫描时刻的
|
|
218
|
+
// nowTimestamp:形态单一来源是双落点一致的形态前提)。判据形态:消费方与其取用符号由代码里的
|
|
219
|
+
// 真实引用派生——模块再切分 / 再搬家不必改锚,新增消费方自动进入对账;说明符由消费方位置解析
|
|
220
|
+
//(`lib/` 内是 `'../time-utils.mjs'`),不写死单层形态。
|
|
221
|
+
// 判别力边界(「第二份内联实现必然让本场景变红」只在**同名**时成立):
|
|
222
|
+
// ① 定义面按**同名定义**计数:同名第二份实现(函数声明 / const 箭头)即变红;
|
|
223
|
+
// ② 消费面按**具名取用自单源模块 + 真实调用**判定(不是纯文本存在性):消费脚本内联同名实现
|
|
224
|
+
// 顶替导出会变红——旧判据 `text.includes(name + '(')` 会被内联同名实现满足,属假绿形态;
|
|
225
|
+
// ③ **不在本锚覆盖内**:与单源导出**不同名**、且消费方仍保留一次真实调用的等价内联实现——
|
|
226
|
+
// 那类形态由各判据族的形态锚分族承担(如 295 日期前缀 / 298 裸拼接),本锚不冒充覆盖它。
|
|
227
|
+
// 判别力由合成反向构造(同名第二份定义 / 未具名取用的内联实现)+ 递归面探针(真实形态 shadow
|
|
228
|
+
// 树:`lib/` 下放第二份实现 → 定义面检出 2)常驻证明。
|
|
229
|
+
{
|
|
230
|
+
name: '277 单源结构锚:时间与窗口判据全引擎各一处定义,消费面(入口 ∪ lib)零内联',
|
|
231
|
+
run: () => {
|
|
232
|
+
const singleSource = ['formatLocalTimestamp', 'nowTimestamp', 'parseTimestamp', 'hasSection9', 'isArchivedAfterTimestamp'];
|
|
233
|
+
const sourceRel = 'time-utils.mjs';
|
|
234
|
+
for (const name of singleSource) {
|
|
235
|
+
const hits = engineDefinitionHits(name);
|
|
236
|
+
assertEqual(hits.length, 1, name + ' 的定义面数量(全引擎应恰 1 处)实际 ' + JSON.stringify(hits));
|
|
237
|
+
assertEqual(hits[0].file, sourceRel, name + ' 的定义文件');
|
|
238
|
+
assertEqual(hits[0].count, 1, name + ' 在 ' + hits[0].file + ' 内的定义处数');
|
|
239
|
+
}
|
|
240
|
+
// 消费面(派生):逐符号取真实引用者、去掉单源模块本身 —— 旧形态的四文件白名单在此被
|
|
241
|
+
// 「入口 ∪ lib/**」取代(迁移到 lib/ 的消费方不再掉出受检面)。
|
|
242
|
+
const consumerSymbols = ['isValidTimestamp', 'daysSince', 'hasSection9', 'isArchivedAfterTimestamp',
|
|
243
|
+
'nowTimestamp', 'parseTimestamp', 'formatLocalTimestamp', 'formatLocalDate', 'archiveDateFromName'];
|
|
244
|
+
const texts = engineScriptTexts();
|
|
245
|
+
const consumerFace = new Map();
|
|
246
|
+
for (const symbol of consumerSymbols) {
|
|
247
|
+
for (const rel of engineConsumersOf(symbol)) {
|
|
248
|
+
if (rel === sourceRel) continue;
|
|
249
|
+
consumerFace.set(rel, [...(consumerFace.get(rel) ?? []), symbol]);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
assertTrue(consumerFace.size >= 4,
|
|
253
|
+
'时间单源消费面收缩(入口 ∪ lib 的消费方应≥4 个模块): ' + JSON.stringify([...consumerFace.keys()]));
|
|
254
|
+
for (const [file, symbols] of consumerFace) {
|
|
255
|
+
const problems = timeSingleSourceConsumerProblems(texts.get(file), symbols, file, sourceRel);
|
|
256
|
+
assertEqual(problems.length, 0, '消费面单源违规: ' + problems.join(' | '));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 反向构造 ①(合成目录 · 纯函数):同名第二份定义 → 定义面检出 2(判据不恒真空过)。
|
|
260
|
+
// 样例经拼接构造,避免套件自身源码携带定义形态字面量而污染真实面计数(本套件同样在扫描面内)。
|
|
261
|
+
const definitionSample = (name) => 'function ' + name + '(date) { return String(date); }\n';
|
|
262
|
+
const synthetic = makeTmp();
|
|
263
|
+
try {
|
|
264
|
+
writeFile(synthetic, 'single.mjs', definitionSample('formatLocalTimestamp'));
|
|
265
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', synthetic).length, 1, '合成目录单份定义检出数');
|
|
266
|
+
writeFile(synthetic, 'second.mjs', definitionSample('formatLocalTimestamp'));
|
|
267
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', synthetic).length, 2,
|
|
268
|
+
'合成目录同名第二份定义检出数(判据须变红)');
|
|
269
|
+
} finally {
|
|
270
|
+
cleanupTmpDir(synthetic);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// 反向构造 ①b(递归面探针 · **真实形态 shadow 树**):把引擎脚本树整棵复制到合成根,在 `lib/`
|
|
274
|
+
// 下放一处同名第二份实现 ⇒ 定义面检出 2。平铺扫描的旧形态只看顶层 ⇒ 这里恒为 1(本探针即
|
|
275
|
+
// 红)——这正是「迁出的实现对结构锚静默失明」的缺陷形态。
|
|
276
|
+
const shadow = makeTmp();
|
|
277
|
+
try {
|
|
278
|
+
const shadowScripts = copyEngineTree(shadow);
|
|
279
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', shadowScripts).length, 1,
|
|
280
|
+
'shadow 树基线(单份定义)检出数');
|
|
281
|
+
writeFile(shadowScripts, path.join('lib', 'second.mjs'), definitionSample('formatLocalTimestamp'));
|
|
282
|
+
assertEqual(engineDefinitionHits('formatLocalTimestamp', shadowScripts).length, 2,
|
|
283
|
+
'lib/ 下的第二份实现必须被递归面检出(平铺面会静默失明)');
|
|
284
|
+
} finally {
|
|
285
|
+
cleanupTmpDir(shadow);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// 反向构造 ②(合成文本 · 纯函数):内联同名实现顶替导出——旧子串判据会放过、本锚必须拒绝;
|
|
289
|
+
// 另两态证明判据不恒真(具名 import 但零调用 → 必报;具名 import + 真实调用 → 零问题)。
|
|
290
|
+
// 同一拼接纪律:调用形态的 `name + '('` 可以字面出现(它不是定义形态),定义形态不可。
|
|
291
|
+
const inlined = 'function ' + 'parseTimestamp(text) {\n return Date.parse(text);\n}\n'
|
|
292
|
+
+ "parseTimestamp('2026-10-02T10:00:00+08:00');\n";
|
|
293
|
+
assertTrue(inlined.includes('parseTimestamp('), '反向构造前提不成立:旧子串判据本应命中内联实现');
|
|
294
|
+
const inlinedProblems = timeSingleSourceConsumerProblems(inlined, ['parseTimestamp'], 'synthetic.mjs', sourceRel);
|
|
295
|
+
assertTrue(inlinedProblems.some((problem) => problem.includes('未从 ' + sourceRel + ' 取用')),
|
|
296
|
+
'内联同名实现未被判违规(旧判据的假绿形态): ' + JSON.stringify(inlinedProblems));
|
|
297
|
+
const importedOnly = "import { parseTimestamp } from './time-utils.mjs';\nconst unused = 1;\n";
|
|
298
|
+
assertTrue(timeSingleSourceConsumerProblems(importedOnly, ['parseTimestamp'], 'synthetic.mjs', sourceRel)
|
|
299
|
+
.some((problem) => problem.includes('未真实消费')), '具名 import 但零调用未被判违规');
|
|
300
|
+
const genuine = "import { parseTimestamp } from './time-utils.mjs';\n"
|
|
301
|
+
+ 'export const instant = (value) => parseTimestamp(value);\n';
|
|
302
|
+
assertEqual(timeSingleSourceConsumerProblems(genuine, ['parseTimestamp'], 'synthetic.mjs', sourceRel).length, 0,
|
|
303
|
+
'具名 import + 真实调用不应被判违规');
|
|
304
|
+
// 说明符由**消费方位置**解析(lib/ 内是 `'../time-utils.mjs'`):同一对(import + 调用)在 lib/
|
|
305
|
+
// 位置采样必须同样零问题——写死 `'./time-utils.mjs'` 的旧形态在此必然误红。
|
|
306
|
+
const genuineInLib = "import { parseTimestamp } from '../time-utils.mjs';\n"
|
|
307
|
+
+ 'export const instant = (value) => parseTimestamp(value);\n';
|
|
308
|
+
assertEqual(timeSingleSourceConsumerProblems(genuineInLib, ['parseTimestamp'], 'lib/x.mjs', sourceRel).length, 0,
|
|
309
|
+
'lib/ 位置的单源取用不应被判违规(说明符须按消费方位置解析)');
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
// 278: evolve 增量窗口与历史 `Z` 兼容——窗口内入选 / 窗口外排除 / 无基线全量;扫描严格限定在
|
|
314
|
+
// 设计文档的沉淀段(其它段的标记串不得出现在输出);`scan` 零写入用树指纹对照。
|
|
315
|
+
{
|
|
316
|
+
name: '278 evolve 窗口:窗口内入选·窗口外排除·无基线全量 + 历史 Z 兼容 + 只读沉淀段 + 零写入',
|
|
317
|
+
run: (dir) => {
|
|
318
|
+
writeFile(dir, '.specs/archive/2026-08-20-old/DESIGN.md',
|
|
319
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
|
|
320
|
+
writeFile(dir, '.specs/archive/2026-09-10-new/DESIGN.md',
|
|
321
|
+
'# DESIGN\n\n## 5. 其它段\n\nOTHER-SECTION-MARKER\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
|
|
322
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
323
|
+
const state = baseState('open');
|
|
324
|
+
state.last_evolve_at = '2026-09-01T00:00:00Z'; // 历史 Z 形态基线
|
|
325
|
+
writeState(dir, state);
|
|
326
|
+
|
|
327
|
+
const before = treeFingerprint(dir);
|
|
328
|
+
const res = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
329
|
+
assertExit(res, 0);
|
|
330
|
+
assertOut(res, 'EVOLVE: 扫描');
|
|
331
|
+
assertOut(res, '窗口 起始 = 2026-09-01T00:00:00Z');
|
|
332
|
+
assertOut(res, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
|
|
333
|
+
assertOut(res, '2026-09-10-new#1');
|
|
334
|
+
assertNotOut(res, '2026-08-20-old#');
|
|
335
|
+
assertNotOut(res, 'OTHER-SECTION-MARKER'); // 只读沉淀段:其它段的标记串不进候选
|
|
336
|
+
const written = fingerprintChanges(before, treeFingerprint(dir));
|
|
337
|
+
assertEqual(written.length, 0, 'scan 必须零写入,实际树变化: ' + JSON.stringify(written));
|
|
338
|
+
|
|
339
|
+
// 等值的 `+00:00` 形态给出同一窗口(兼容历史 Z 与本地偏移两种写法,不是两套语义)
|
|
340
|
+
const offsetState = { ...state, last_evolve_at: '2026-09-01T00:00:00+00:00' };
|
|
341
|
+
writeState(dir, offsetState);
|
|
342
|
+
const offsetRes = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
343
|
+
assertExit(offsetRes, 0);
|
|
344
|
+
assertOut(offsetRes, '窗口 起始 = 2026-09-01T00:00:00+00:00');
|
|
345
|
+
assertOut(offsetRes, '窗口内 1 个');
|
|
346
|
+
assertNotOut(offsetRes, '上次沉淀时间不可解析');
|
|
347
|
+
|
|
348
|
+
// 不可解析的基线 → 显式按全量扫描(不静默当成「无新增」)
|
|
349
|
+
writeState(dir, { ...state, last_evolve_at: '不是时间' });
|
|
350
|
+
const broken = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
351
|
+
assertExit(broken, 0);
|
|
352
|
+
assertOut(broken, '上次沉淀时间不可解析(按全量扫描)');
|
|
353
|
+
assertOut(broken, '窗口内 2 个');
|
|
354
|
+
|
|
355
|
+
// 无基线(字段缺席)→ 全量扫描
|
|
356
|
+
writeState(dir, baseState('open'));
|
|
357
|
+
const noBaseline = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
358
|
+
assertExit(noBaseline, 0);
|
|
359
|
+
assertOut(noBaseline, '无基线(首次运行,全量扫描)');
|
|
360
|
+
assertOut(noBaseline, '窗口内 2 个');
|
|
361
|
+
assertOut(noBaseline, '2026-08-20-old#1');
|
|
362
|
+
},
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
// 279: 到期提示两因与静默——「距今 > 60 天」或「该时刻之后新增 ≥ 5 个带 §9 的归档 change」
|
|
366
|
+
// 达阈值即输出 `EVOLVE-DUE`(提示行不含花括号,status 的 JSON 块仍可被既有消费方解析);
|
|
367
|
+
// 未达阈值 / 字段缺席(从未跑过 evolve)一律零输出;非法值经 `config set` 写入 → BLOCKED 零改写。
|
|
368
|
+
{
|
|
369
|
+
name: '279 到期提示:按天数·按新增数达阈值提示,未达阈值与字段缺席静默,JSON 块可解析',
|
|
370
|
+
run: (dir) => {
|
|
371
|
+
const formatStamp = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
372
|
+
const formatDate = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs');
|
|
373
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
374
|
+
const stampDaysAgo = (days) => formatStamp(new Date(Date.now() - days * dayMs));
|
|
375
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/CHANGE.md', '# CHANGE\n\n## Why(为什么做)\n\n夹具。\n');
|
|
376
|
+
|
|
377
|
+
// ① 按天数:距今 100 天 → 提示行 + JSON 块仍可解析
|
|
378
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: stampDaysAgo(100) });
|
|
379
|
+
const aged = runStateWithProtocol(dir, ['status']);
|
|
380
|
+
assertExit(aged, 0);
|
|
381
|
+
assertOut(aged, 'EVOLVE-DUE: 上次架构沉淀');
|
|
382
|
+
assertOut(aged, '超阈值 60 天');
|
|
383
|
+
assertEqual(parseStatusJson(aged).status, 'running', '提示行在场时 status 的 JSON 块解析');
|
|
384
|
+
|
|
385
|
+
// ② 未达阈值(新鲜)→ 静默;③ 字段缺席(从未跑过 evolve)→ 同样静默
|
|
386
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: stampDaysAgo(1) });
|
|
387
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
388
|
+
writeState(dir, baseState('open'));
|
|
389
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
390
|
+
|
|
391
|
+
// ④ 按新增数:基线之后 5 个带 §9 的归档 change → 提示;取走一个(4 个)→ 静默
|
|
392
|
+
const baselineMs = Date.now() - 30 * dayMs;
|
|
393
|
+
const baselineStamp = formatStamp(new Date(baselineMs));
|
|
394
|
+
const archiveDirName = (offsetDays) => formatDate(new Date(baselineMs + offsetDays * dayMs)) + '-new-' + offsetDays;
|
|
395
|
+
for (let offset = 1; offset <= 5; offset += 1) {
|
|
396
|
+
writeFile(dir, '.specs/archive/' + archiveDirName(offset) + '/DESIGN.md',
|
|
397
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 条目 ' + offset + '\n');
|
|
398
|
+
}
|
|
399
|
+
writeState(dir, { ...baseState('open'), last_evolve_at: baselineStamp });
|
|
400
|
+
const byCount = runStateWithProtocol(dir, ['status']);
|
|
401
|
+
assertExit(byCount, 0);
|
|
402
|
+
assertOut(byCount, 'EVOLVE-DUE: 上次架构沉淀');
|
|
403
|
+
assertOut(byCount, '其后新增 5 个带 §9 的归档 change,达阈值 5 个');
|
|
404
|
+
parseStatusJson(byCount);
|
|
405
|
+
fs.rmSync(path.join(dir, '.specs', 'archive', archiveDirName(5)), { recursive: true, force: true });
|
|
406
|
+
assertNotOut(runStateWithProtocol(dir, ['status']), 'EVOLVE-DUE');
|
|
407
|
+
|
|
408
|
+
// ⑤ 非法值经唯一写通道写入 → BLOCKED 且 state 字节零改写
|
|
409
|
+
const beforeBytes = readStateBytes(dir);
|
|
410
|
+
const illegal = runStateWithProtocol(dir, ['config', 'set', 'last_evolve_at', '2026-02-30T00:00:00Z']);
|
|
411
|
+
assertExit(illegal, 1);
|
|
412
|
+
assertOut(illegal, 'BLOCKED');
|
|
413
|
+
assertOut(illegal, 'last_evolve_at');
|
|
414
|
+
assertStateBytesUnchanged(dir, beforeBytes, 'last_evolve_at 非法值');
|
|
415
|
+
},
|
|
416
|
+
},
|
|
417
|
+
|
|
418
|
+
// 280: health 复现性——同一冻结树两次运行,差异必须落在报告的「易变行声明」集合内(声明的
|
|
419
|
+
// 差异集合之外逐字节一致);`--stdout` 与落盘逐字节相同;state 零改写(报告是唯一写入面)。
|
|
420
|
+
{
|
|
421
|
+
name: '280 health 两次运行:易变行声明之外逐字节一致 + --stdout 与落盘相同 + state 零改写',
|
|
422
|
+
run: (dir) => {
|
|
423
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
424
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
|
|
425
|
+
writeState(dir, baseState('open'));
|
|
426
|
+
const stateBytes = readStateBytes(dir);
|
|
427
|
+
|
|
428
|
+
const first = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
429
|
+
assertExit(first, 0);
|
|
430
|
+
assertOut(first, '## 确定性层(机器可判)');
|
|
431
|
+
assertOut(first, '### 1 · 项目上下文一致性');
|
|
432
|
+
assertOut(first, '### 2 · 经验条目编号连续性');
|
|
433
|
+
assertOut(first, '- 缺失编号(0):无');
|
|
434
|
+
assertOut(first, '## 增补层(代码体检工具的 4 维结果 · 可选)');
|
|
435
|
+
assertOut(first, '## 降级声明');
|
|
436
|
+
assertOut(first, '## 易变行声明(两次运行的允许差异集合)');
|
|
437
|
+
|
|
438
|
+
const second = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
439
|
+
assertExit(second, 0);
|
|
440
|
+
const volatilePrefixes = ['- **生成时间**:', '- 最近 30 天提交数:'];
|
|
441
|
+
const firstLines = first.output.split('\n');
|
|
442
|
+
const secondLines = second.output.split('\n');
|
|
443
|
+
const differing = [];
|
|
444
|
+
for (let i = 0; i < Math.max(firstLines.length, secondLines.length); i += 1) {
|
|
445
|
+
if (firstLines[i] === secondLines[i]) continue;
|
|
446
|
+
const line = firstLines[i] ?? secondLines[i] ?? '';
|
|
447
|
+
if (volatilePrefixes.some((prefix) => line.startsWith(prefix))) continue;
|
|
448
|
+
differing.push('第 ' + (i + 1) + ' 行 ' + JSON.stringify(firstLines[i]) + ' → ' + JSON.stringify(secondLines[i]));
|
|
449
|
+
}
|
|
450
|
+
assertEqual(differing.length, 0, '两次运行的差异落在易变行声明之外: ' + differing.join(' | '));
|
|
451
|
+
|
|
452
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
453
|
+
const reportFile = path.join(dir, '.specs', 'health', today + '-HEALTH.md');
|
|
454
|
+
assertTrue(fs.existsSync(reportFile), '报告未按 <日期>-HEALTH.md 形态落盘: ' + reportFile);
|
|
455
|
+
// `--stdout` = 落盘报告正文原样在前 + `HEALTH:` 审计行追加在后:审计行是 CLI 摘要而非报告
|
|
456
|
+
// 内容,不进报告字节(报告仍是唯一写入面);正文部分与落盘逐字节一致。
|
|
457
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
458
|
+
assertTrue(second.output.startsWith(reportText),
|
|
459
|
+
'--stdout 的报告正文应与落盘逐字节一致(审计行追加在后): ' + JSON.stringify(second.output.slice(0, 120)));
|
|
460
|
+
assertOut(second, 'HEALTH: 报告 `.specs/health/' + today + '-HEALTH.md`');
|
|
461
|
+
assertOut(second, 'HEALTH-DONE');
|
|
462
|
+
assertOut(second, '- **写入边界**:只写本报告文件;不改代码、不写运行状态文件(本命令不新增任何状态字段)');
|
|
463
|
+
assertStateBytesUnchanged(dir, stateBytes, 'health 运行后');
|
|
464
|
+
// 同日重跑不与自己对比(否则报告自我污染、复现性判据失效)
|
|
465
|
+
assertOut(second, '基线:无(`.specs/health` 下无日期不同的历史报告)');
|
|
466
|
+
},
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// 281: health 缺可选工具的两态之一——隔离 HOME/USERPROFILE(用户级插件缓存与用户技能目录
|
|
470
|
+
// 都落主目录)→ 增补层逐项不在场、降级声明可见,确定性层照常完整、退出码 0(可选工具缺席
|
|
471
|
+
// 不构成失败;本机实际装有 brooks,故须隔离而不是假设)。
|
|
472
|
+
{
|
|
473
|
+
name: '281 health 隔离 HOME:增补层逐项不在场 + 降级声明可见 + 确定性层完整 + exit 0',
|
|
474
|
+
run: (dir) => {
|
|
475
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
476
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n');
|
|
477
|
+
const isolatedHome = path.join(dir, 'isolated-home');
|
|
478
|
+
fs.mkdirSync(isolatedHome, { recursive: true });
|
|
479
|
+
|
|
480
|
+
const isolated = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir,
|
|
481
|
+
{ HOME: isolatedHome, USERPROFILE: isolatedHome });
|
|
482
|
+
assertExit(isolated, 0);
|
|
483
|
+
assertOut(isolated, '- **在场判定**:不在场——下列探测面逐项未命中(未安装 / 未加载)');
|
|
484
|
+
assertOut(isolated, 'Claude Code 插件缓存(用户级)');
|
|
485
|
+
assertOut(isolated, '- **降级**:4 维结果缺省;报告只由确定性层构成(判据不因缺可选工具而失败)');
|
|
486
|
+
assertOut(isolated, '- **brooks-lint**:不可用——探测面逐项未命中');
|
|
487
|
+
assertOut(isolated, '## 确定性层(机器可判)');
|
|
488
|
+
assertOut(isolated, '### 5 · 版本历史统计(git)');
|
|
489
|
+
assertOut(isolated, '缺席不影响本命令成功(退出码 0)');
|
|
490
|
+
|
|
491
|
+
// 对照:未隔离运行同样以完整报告 + 退出码 0 收尾(在场与否随环境,报告形态不变)
|
|
492
|
+
const openEnv = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
493
|
+
assertExit(openEnv, 0);
|
|
494
|
+
assertOut(openEnv, '- **探测面(固定清单 · 逐项判定)**:');
|
|
495
|
+
assertOut(openEnv, '## 确定性层(机器可判)');
|
|
496
|
+
},
|
|
497
|
+
},
|
|
498
|
+
|
|
499
|
+
// 282: context-scan 首次无基线与二次差异——首次显式声明「本次为基线,无差异可比」;第二次
|
|
500
|
+
// 逐项比对出新增;同一秒连续重扫不得误 BLOCK;双落点(state 的 last_intel_scan 与 CONTEXT
|
|
501
|
+
// 的 `## intel-scan 元数据` 字段)取值一致;工件含机器快照标记。
|
|
502
|
+
{
|
|
503
|
+
name: '282 context-scan 首次无基线 → 二次差异:新增可比 + 同秒重扫 exit 0 + 双落点一致',
|
|
504
|
+
run: (dir) => {
|
|
505
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
506
|
+
writeState(dir, baseState('open'));
|
|
507
|
+
|
|
508
|
+
const first = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
509
|
+
assertExit(first, 0);
|
|
510
|
+
assertOut(first, 'CONTEXT-SCAN: 基线 无(本次为基线,无差异可比)');
|
|
511
|
+
assertOut(first, 'CONTEXT-SCAN: 差异 无(本次为基线,无差异可比)');
|
|
512
|
+
assertOut(first, 'CONTEXT-SCAN-DONE');
|
|
513
|
+
|
|
514
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
515
|
+
const reportFile = path.join(dir, '.specs', 'context-scan', today + '-SCAN.md');
|
|
516
|
+
assertTrue(fs.existsSync(reportFile), '扫描工件未落盘: ' + reportFile);
|
|
517
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
518
|
+
assertTrue(reportText.includes('<!-- context-scan-snapshot -->'), '工件缺机器快照标记');
|
|
519
|
+
assertTrue(/```json\r?\n/.test(reportText.slice(reportText.indexOf('<!-- context-scan-snapshot -->'))),
|
|
520
|
+
'机器快照标记之后缺 json 块');
|
|
521
|
+
|
|
522
|
+
// 同一秒连续重扫(取值未变)不得被误判成字段行形态不符
|
|
523
|
+
const immediate = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
524
|
+
assertExit(immediate, 0);
|
|
525
|
+
assertOut(immediate, 'CONTEXT-SCAN-DONE');
|
|
526
|
+
|
|
527
|
+
// 双落点:state 的 last_intel_scan 与 CONTEXT 段内字段**取值词元**一致(夹具段行带行尾说明)
|
|
528
|
+
const structure = requireModuleExport(contextInitModule, 'extractContextStructure', 'context-init.mjs')(
|
|
529
|
+
fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8'));
|
|
530
|
+
const landed = intelFieldToken(structure.metadata['intel-scan 元数据'].last_intel_scan.value);
|
|
531
|
+
const stateFile = JSON.parse(fs.readFileSync(path.join(dir, '.flow-comet', 'flow-comet-state.json'), 'utf8'));
|
|
532
|
+
assertEqual(stateFile.last_intel_scan, landed, '双落点取值(state 与 CONTEXT 段)');
|
|
533
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(landed),
|
|
534
|
+
'落盘扫描时刻形态非「本地时间 + 显式偏移」: ' + landed);
|
|
535
|
+
|
|
536
|
+
// 二次差异:新增一份 AI 上下文文档 → 差异段「新增」列出该条目(条目在工件内,摘要行只给计数)
|
|
537
|
+
writeFile(dir, 'AGENTS.md', '# AGENTS\n\n夹具。\n');
|
|
538
|
+
const second = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
539
|
+
assertExit(second, 0);
|
|
540
|
+
assertOut(second, 'CONTEXT-SCAN: 基线');
|
|
541
|
+
assertOut(second, '差异 新增 1 ');
|
|
542
|
+
assertOut(second, 'CONTEXT-SCAN-DONE');
|
|
543
|
+
const diffReport = fs.readFileSync(reportFile, 'utf8');
|
|
544
|
+
assertTrue(diffReport.includes('### 新增(1)'), '工件缺「新增(1)」段');
|
|
545
|
+
assertTrue(diffReport.includes('- AI 上下文文档 · AGENTS.md'),
|
|
546
|
+
'工件的新增段未列出新增的 AI 上下文文档');
|
|
547
|
+
},
|
|
548
|
+
},
|
|
549
|
+
|
|
550
|
+
// 283: context-scan 四类边界——① 既有基线不含机器快照 → 显式「无法比对」(不静默省略差异段);
|
|
551
|
+
// ② 结构校验不通过的一轮零写入且基线不前进(工件与 state 逐字节不变);③ 未初始化项目 →
|
|
552
|
+
// INIT-GENERATE 指引 + 零写入 + exit 1;④ state 在场但字段非法 → CONTEXT 段零改写
|
|
553
|
+
// (校验先于两次写入,双落点不被拆成两半)。
|
|
554
|
+
{
|
|
555
|
+
name: '283 context-scan 边界:旧基线无快照显式无法比对 / BLOCK 轮不推进基线 / 未初始化零写入 / state 字段非法零改写',
|
|
556
|
+
run: (dir) => {
|
|
557
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
558
|
+
writeState(dir, baseState('open'));
|
|
559
|
+
|
|
560
|
+
// ① 旧基线不含机器快照(人读工件的历史形态)
|
|
561
|
+
const legacyBaseline = path.join(dir, '.specs', 'context-scan', '2020-01-01-SCAN.md');
|
|
562
|
+
fs.mkdirSync(path.dirname(legacyBaseline), { recursive: true });
|
|
563
|
+
fs.writeFileSync(legacyBaseline, '# 项目上下文重扫报告 · 2020-01-01\n\n(历史工件,无机器快照块)\n', 'utf8');
|
|
564
|
+
const legacyRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
565
|
+
assertExit(legacyRes, 0);
|
|
566
|
+
assertOut(legacyRes, 'CONTEXT-SCAN: 差异 无(既有基线不含机器快照,无法比对)');
|
|
567
|
+
assertOut(legacyRes, 'CONTEXT-SCAN-DONE');
|
|
568
|
+
|
|
569
|
+
// ② 结构校验不通过的一轮:零写入,基线不前进
|
|
570
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
571
|
+
const baselineFile = path.join(dir, '.specs', 'context-scan', today + '-SCAN.md');
|
|
572
|
+
assertTrue(fs.existsSync(baselineFile), '本轮基线工件应在场: ' + baselineFile);
|
|
573
|
+
const baselineBytes = fs.readFileSync(baselineFile);
|
|
574
|
+
const stateBytes = readStateBytes(dir);
|
|
575
|
+
fs.writeFileSync(path.join(dir, '.specs', 'CONTEXT.md'),
|
|
576
|
+
contextFixtureText().replace('## 默认偏好\n', ''), 'utf8');
|
|
577
|
+
const blocked = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
578
|
+
assertExit(blocked, 1);
|
|
579
|
+
assertOut(blocked, 'BLOCKED: CONTEXT.md 未通过结构校验');
|
|
580
|
+
assertTrue(fs.readFileSync(baselineFile).equals(baselineBytes), 'BLOCK 的一轮改写了基线工件');
|
|
581
|
+
assertStateBytesUnchanged(dir, stateBytes, 'context-scan BLOCK 轮');
|
|
582
|
+
|
|
583
|
+
// ③ 未初始化项目:INIT-GENERATE 指引 + 零写入 + exit 1
|
|
584
|
+
const fresh = path.join(dir, 'fresh-project');
|
|
585
|
+
fs.mkdirSync(fresh, { recursive: true });
|
|
586
|
+
const freshBefore = treeFingerprint(fresh);
|
|
587
|
+
const freshRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', fresh], fresh);
|
|
588
|
+
assertExit(freshRes, 1);
|
|
589
|
+
assertOut(freshRes, 'INIT-GENERATE');
|
|
590
|
+
assertOut(freshRes, 'BLOCKED');
|
|
591
|
+
const freshChanges = fingerprintChanges(freshBefore, treeFingerprint(fresh));
|
|
592
|
+
assertEqual(freshChanges.length, 0, '未初始化项目必须零写入,实际树变化: ' + JSON.stringify(freshChanges));
|
|
593
|
+
|
|
594
|
+
// ④ state 在场但字段非法(写闸门会拒):CONTEXT 段必须零改写。校验此前排在 CONTEXT 改写之后
|
|
595
|
+
// ⇒ 段侧先落新扫描时刻、state 侧被拒,双落点被拆成两半(且段侧指向引擎根本不认的时刻)。
|
|
596
|
+
// 与同一命令的损坏态判定(preflight ②:状态不可信 → 零元数据写入)是同一姿态。
|
|
597
|
+
const badStateRoot = path.join(dir, 'bad-state-field');
|
|
598
|
+
writeFile(badStateRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
599
|
+
writeState(badStateRoot, { ...baseState('open'), executionMode: 'not-a-mode' });
|
|
600
|
+
const badContextBefore = fs.readFileSync(path.join(badStateRoot, '.specs', 'CONTEXT.md'));
|
|
601
|
+
const badStateBytes = readStateBytes(badStateRoot);
|
|
602
|
+
const badStateRes = runSideScript(SIDE_CONTEXT_SCAN, ['--root', badStateRoot], badStateRoot);
|
|
603
|
+
assertExit(badStateRes, 1);
|
|
604
|
+
assertOut(badStateRes, 'BLOCKED');
|
|
605
|
+
assertTrue(fs.readFileSync(path.join(badStateRoot, '.specs', 'CONTEXT.md')).equals(badContextBefore),
|
|
606
|
+
'state 字段非法的一轮改写了 CONTEXT 段(双落点被拆成两半)');
|
|
607
|
+
assertStateBytesUnchanged(badStateRoot, badStateBytes, 'context-scan state 字段非法轮');
|
|
608
|
+
},
|
|
609
|
+
},
|
|
610
|
+
|
|
611
|
+
// 284: 本仓 CONTEXT 的七段校验 + 可选的 `## evolve 元数据` 段语义——缺席不报(没跑过架构
|
|
612
|
+
// 沉淀的项目不补段);在场则三字段必须齐(跑过一次却写残的半成品正是要拦的形态);判据
|
|
613
|
+
// **限定在段内**(别处的同名字段不得让残缺的 evolve 段蒙混过关)。
|
|
614
|
+
// ① 是本仓真实文件的**维护者形态**断言(.specs/ 被 gitignore):文件结构性缺席(CI 全新检出 /
|
|
615
|
+
// worktree)时输出可见 SKIP 行(未验证 ≠ 通过),**在场时判据逐字不变**;②~⑤ 恒检(夹具驱动)。
|
|
616
|
+
{
|
|
617
|
+
name: '284 CONTEXT 七段校验 + evolve 元数据可选段:缺席不报·在场缺一即报·判据限段内',
|
|
618
|
+
run: async () => {
|
|
619
|
+
const validate = requireModuleExport(contextInitModule, 'validateContext', 'context-init.mjs');
|
|
620
|
+
|
|
621
|
+
// ① 本仓 CONTEXT.md 通过七段校验(真实文件,非夹具)——文件缺席即非维护者形态,可见跳过
|
|
622
|
+
if (fs.existsSync(REPO_CONTEXT_FILE)) {
|
|
623
|
+
const repo = await validate(REPO_ROOT);
|
|
624
|
+
assertEqual(repo.missingSections.length, 0, '本仓 CONTEXT.md 缺段: ' + JSON.stringify(repo.missingSections));
|
|
625
|
+
assertEqual(repo.formatIssues.length, 0, '本仓 CONTEXT.md 格式问题: ' + JSON.stringify(repo.formatIssues));
|
|
626
|
+
} else {
|
|
627
|
+
console.log('SKIP: 284 的本仓 CONTEXT 面(.specs/CONTEXT.md 为流程工件面,可能结构性缺席)'
|
|
628
|
+
+ '——本仓 CONTEXT 缺席 = 非维护者形态;本次检出未校验本仓 CONTEXT.md 的七段与 evolve 元数据段语义,'
|
|
629
|
+
+ '请在维护者主树重跑本套件');
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// ② 夹具:七段齐备、evolve 段缺席 → 通过(可选段的缺席不报)
|
|
633
|
+
const project = makeTmp();
|
|
634
|
+
try {
|
|
635
|
+
writeFile(project, '.specs/CONTEXT.md', contextFixtureText());
|
|
636
|
+
const absent = await validate(project);
|
|
637
|
+
assertEqual(absent.missingSections.length, 0, '七段骨架缺段: ' + JSON.stringify(absent.missingSections));
|
|
638
|
+
assertEqual(absent.formatIssues.length, 0, 'evolve 段缺席不应报格式问题: ' + JSON.stringify(absent.formatIssues));
|
|
639
|
+
|
|
640
|
+
// ③ evolve 段在场且三字段齐 → 通过
|
|
641
|
+
writeFile(project, '.specs/CONTEXT.md',
|
|
642
|
+
contextFixtureText({ evolveSection: EVOLVE_METADATA_FIELD_LINES }));
|
|
643
|
+
const complete = await validate(project);
|
|
644
|
+
assertEqual(complete.formatIssues.length, 0, 'evolve 段齐备仍报格式问题: ' + JSON.stringify(complete.formatIssues));
|
|
645
|
+
|
|
646
|
+
// ④ 段内缺一个字段 → 报「evolve 元数据三字段」
|
|
647
|
+
writeFile(project, '.specs/CONTEXT.md',
|
|
648
|
+
contextFixtureText({ evolveSection: EVOLVE_METADATA_FIELD_LINES.slice(0, 2) }));
|
|
649
|
+
const incomplete = await validate(project);
|
|
650
|
+
assertTrue(incomplete.formatIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
651
|
+
'evolve 段缺字段未报出: ' + JSON.stringify(incomplete.formatIssues));
|
|
652
|
+
|
|
653
|
+
// ⑤ 判据限段内:缺的那个字段出现在**其它段**里,不得让残缺的 evolve 段蒙混过关
|
|
654
|
+
writeFile(project, '.specs/CONTEXT.md', contextFixtureText({
|
|
655
|
+
evolveSection: EVOLVE_METADATA_FIELD_LINES.slice(0, 2),
|
|
656
|
+
tail: '## 其它段\n\n- **下次建议**: 别处的同名字段',
|
|
657
|
+
}));
|
|
658
|
+
const outside = await validate(project);
|
|
659
|
+
assertTrue(outside.formatIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
660
|
+
'判据未限定段内(别处的同名字段放行了残缺段): ' + JSON.stringify(outside.formatIssues));
|
|
661
|
+
} finally {
|
|
662
|
+
cleanupTmpDir(project);
|
|
663
|
+
}
|
|
664
|
+
},
|
|
665
|
+
},
|
|
666
|
+
|
|
667
|
+
// 285: design 出口 ui-design 门四类——正例(前端齐备 + 真实声明 → 放行)/ 负例(缺工件
|
|
668
|
+
// BLOCKED、缺声明 BLOCKED 且不再自动补写)/ 越界(非前端 → 可见跳过,不要求工件与声明)/
|
|
669
|
+
// 恢复(旧 change 前端缺件 → WARN 渐进不卡死)。前端判据是结构级:CHANGE.md「视觉调性」段。
|
|
670
|
+
{
|
|
671
|
+
name: '285 ui-design 门四类:前端齐备放行 / 前端缺件 BLOCK / 非前端可见跳过 / 旧 change WARN',
|
|
672
|
+
run: (dir) => {
|
|
673
|
+
// 正例:前端(「视觉调性」段在场且未标注不适用)+ 工件齐备 + 真实声明
|
|
674
|
+
writeDesignExitFixture(dir, {
|
|
675
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
676
|
+
});
|
|
677
|
+
const positive = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
678
|
+
assertExit(positive, 0);
|
|
679
|
+
assertOut(positive, 'ALL CHECKS PASSED');
|
|
680
|
+
assertNotOut(positive, 'UI-DESIGN: skipped');
|
|
681
|
+
|
|
682
|
+
// 负例 A:前端缺 UI-DESIGN.md → BLOCKED + 两条恢复路径
|
|
683
|
+
writeDesignExitFixture(dir, {
|
|
684
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
685
|
+
});
|
|
686
|
+
const missingArtifact = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
687
|
+
assertExit(missingArtifact, 1);
|
|
688
|
+
assertOut(missingArtifact, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
689
|
+
assertOut(missingArtifact, '恢复: 补 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
|
|
690
|
+
|
|
691
|
+
// 负例 B:工件齐备但缺 `required-skill:design.flow-comet-ui-design` → BLOCKED(出口不再自动补写)
|
|
692
|
+
writeDesignExitFixture(dir, {
|
|
693
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: false,
|
|
694
|
+
});
|
|
695
|
+
const missingDeclaration = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
696
|
+
assertExit(missingDeclaration, 1);
|
|
697
|
+
assertOut(missingDeclaration, 'BLOCKED: missing required Skill evidence: required-skill:design.flow-comet-ui-design');
|
|
698
|
+
assertOut(missingDeclaration, '不再由出口自动补写');
|
|
699
|
+
|
|
700
|
+
// 越界:非前端(「视觉调性」段标注不适用)→ 可见跳过,不要求工件、也不要求该声明
|
|
701
|
+
writeDesignExitFixture(dir, {
|
|
702
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
703
|
+
});
|
|
704
|
+
const nonFrontend = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
705
|
+
assertExit(nonFrontend, 0);
|
|
706
|
+
assertOut(nonFrontend, 'UI-DESIGN: skipped(非前端)');
|
|
707
|
+
assertOut(nonFrontend, 'ALL CHECKS PASSED');
|
|
708
|
+
|
|
709
|
+
// 恢复:旧 change 前端缺件 → WARN 渐进(不阻断,也不静默放行)
|
|
710
|
+
writeDesignExitFixture(dir, {
|
|
711
|
+
newChange: false, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
712
|
+
});
|
|
713
|
+
const legacy = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
714
|
+
assertExit(legacy, 0);
|
|
715
|
+
assertOut(legacy, 'UI-DESIGN WARN: 缺 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
|
|
716
|
+
assertOut(legacy, '旧 change 渐进不阻断');
|
|
717
|
+
},
|
|
718
|
+
},
|
|
719
|
+
|
|
720
|
+
// 286: ui-design 强制等级的文本一致性锚——协议 `design.requiredSkillCalls[flow-comet-ui-design]`
|
|
721
|
+
// 为 `guarded`,**五份**技能文本(ui-design 技能 / 入口 SKILL / design 节点 SKILL / 入口展开册
|
|
722
|
+
// `reference/entry-detail.md` / change 阶段 SKILL)不得残留 `advisory` 表述且须同时点名该绑定与
|
|
723
|
+
// `guarded`。等级只在协议里表达一次,文本是它的散文副本:副本漂移即红(旧表述「advisory,不要求
|
|
724
|
+
// 声明」正是被本锚拦下的形态)。
|
|
725
|
+
// **判据散文口径(ADR-016 重定向)**:原判据要求**五份文本各自**陈述五个结构 token,且反向构造
|
|
726
|
+
// 断言**每份**文本都含「词形边界」——T05 把口径收归 `flow-comet-ui-design` 册一处权威后,那一侧
|
|
727
|
+
// 会以两种方式失败(五份各自的 token 缺失 + 反向构造前提不成立)。新判据三件套:**一处权威**
|
|
728
|
+
//(ui-design 册陈述五个结构 token 且零旧口径)+ **入口册指针在场**(各引用册以条件句指向该册)
|
|
729
|
+
// + **该口径正文唯一**(块级跨距:任何其它分发文本不得含权威口径段的 ≥120 字符逐字副本)。
|
|
730
|
+
{
|
|
731
|
+
name: '286 ui-design 强制等级一致性锚:协议 guarded + 五处技能文本零 advisory 残留 + 结构判据散文口径',
|
|
732
|
+
run: () => {
|
|
733
|
+
const protocol = JSON.parse(fs.readFileSync(SKILL_PROTOCOL_FILE, 'utf8'));
|
|
734
|
+
const designNode = (protocol.nodes ?? []).find((node) => node.id === 'design');
|
|
735
|
+
assertTrue(designNode !== undefined, '协议缺 design 节点');
|
|
736
|
+
const binding = (designNode.requiredSkillCalls ?? []).find((call) => call.skill === 'flow-comet-ui-design');
|
|
737
|
+
assertTrue(binding !== undefined, '协议 design 节点缺 flow-comet-ui-design 绑定');
|
|
738
|
+
assertEqual(binding.enforcement, 'guarded', '协议 flow-comet-ui-design 绑定的强制等级');
|
|
739
|
+
|
|
740
|
+
const skillsRoot = skillsRootForScriptsDir(SCRIPTS_DIR);
|
|
741
|
+
const texts = {
|
|
742
|
+
'flow-comet-ui-design/SKILL.md': path.join(skillsRoot, 'flow-comet-ui-design', 'SKILL.md'),
|
|
743
|
+
'flow-comet/SKILL.md': path.join(skillsRoot, 'flow-comet', 'SKILL.md'),
|
|
744
|
+
'flow-comet-design/SKILL.md': path.join(skillsRoot, 'flow-comet-design', 'SKILL.md'),
|
|
745
|
+
'flow-comet/reference/entry-detail.md': path.join(skillsRoot, 'flow-comet', 'reference', 'entry-detail.md'),
|
|
746
|
+
'flow-comet-change/SKILL.md': path.join(skillsRoot, 'flow-comet-change', 'SKILL.md'),
|
|
747
|
+
};
|
|
748
|
+
const textByRel = new Map();
|
|
749
|
+
for (const [label, file] of Object.entries(texts)) {
|
|
750
|
+
const text = fs.readFileSync(file, 'utf8');
|
|
751
|
+
textByRel.set(label, text);
|
|
752
|
+
assertTrue(!/advisory/i.test(text), label + ' 残留 advisory 等级表述(协议为 guarded)');
|
|
753
|
+
assertTrue(text.includes('guarded'), label + ' 未点名 guarded 等级');
|
|
754
|
+
assertTrue(text.includes('flow-comet-ui-design'), label + ' 未点名 flow-comet-ui-design 绑定');
|
|
755
|
+
}
|
|
756
|
+
// —— 结构判据散文口径的三件套(重定向后判据;纯函数 + 合成文本面驱动)——
|
|
757
|
+
const criterionSources = {
|
|
758
|
+
authorityRel: FRONTEND_CRITERION_AUTHORITY_REL,
|
|
759
|
+
authorityText: textByRel.get(FRONTEND_CRITERION_AUTHORITY_REL),
|
|
760
|
+
pointerDocs: new Map(FRONTEND_CRITERION_POINTER_RELS.map(([rel]) => [rel, textByRel.get(rel)])),
|
|
761
|
+
docs: new Map(skillTreeDocFiles().map(([rel, file]) => [rel, fs.readFileSync(file, 'utf8')])),
|
|
762
|
+
};
|
|
763
|
+
const criterionProblems = frontendCriterionRedirectProblems(criterionSources);
|
|
764
|
+
assertEqual(criterionProblems.length, 0, '判据散文口径未对齐: ' + criterionProblems.join(' | '));
|
|
765
|
+
// 反向构造(合成输入驱动同一判据,证明它不恒真空过):
|
|
766
|
+
// ① 结构词缺一 → 必报;② 旧口径句注入权威处 → 必报「残留旧口径」;
|
|
767
|
+
// ③ 权威口径段复制进第二册 → 必报「第二份正文」(原「五份各自陈述」的方向已反转);
|
|
768
|
+
// ④ 抽掉入口册指针 → 必报「指针不在场」。
|
|
769
|
+
const structuralSample = '前端判据是结构级的:独立行 / 行首 / 适用性标签的字段值位三种形态,'
|
|
770
|
+
+ '标记后须成词形边界,命中片段回显。\n';
|
|
771
|
+
assertEqual(frontendCriterionProseProblems('sample', structuralSample).length, 0,
|
|
772
|
+
'结构口径样本不应被判违规(判据不恒真)');
|
|
773
|
+
const staleSamples = [
|
|
774
|
+
'前端判据是结构级的:`CHANGE.md` 的「视觉调性」段在场且段内未标注「不适用」。',
|
|
775
|
+
'段在场,段内**不含**字面「不适用」',
|
|
776
|
+
'非前端项目:在段内标注「不适用」两个字面。',
|
|
777
|
+
];
|
|
778
|
+
for (const stale of staleSamples) {
|
|
779
|
+
const probed = frontendCriterionRedirectProblems({
|
|
780
|
+
...criterionSources,
|
|
781
|
+
authorityText: criterionSources.authorityText + '\n' + stale + '\n',
|
|
782
|
+
});
|
|
783
|
+
assertTrue(probed.some((problem) => problem.includes('残留旧口径')),
|
|
784
|
+
'旧口径样本未被判违规: ' + JSON.stringify(stale) + ' → ' + JSON.stringify(probed));
|
|
785
|
+
}
|
|
786
|
+
for (const group of FRONTEND_CRITERION_STRUCTURE_GROUPS) {
|
|
787
|
+
// OR 组的反向构造必须抽掉**整组** token(只抽一个会被组内另一形态满足而恒真)。
|
|
788
|
+
const strippedText = group.reduce((acc, token) => acc.split(token).join('(反向构造:抽掉)'),
|
|
789
|
+
criterionSources.authorityText);
|
|
790
|
+
const stripped = frontendCriterionRedirectProblems({
|
|
791
|
+
...criterionSources,
|
|
792
|
+
authorityText: strippedText,
|
|
793
|
+
});
|
|
794
|
+
assertTrue(stripped.some((problem) => problem.includes('未陈述结构形态')),
|
|
795
|
+
'权威处抽掉结构形态组「' + group.join(' / ') + '」未被判违规: ' + JSON.stringify(stripped));
|
|
796
|
+
}
|
|
797
|
+
const criterionBlock = frontendCriterionAuthorityBlock(criterionSources.authorityText);
|
|
798
|
+
assertTrue(criterionBlock !== null, '权威口径段切片为空(缺「结构形态」三种任一 → 仍判前端 的整段)');
|
|
799
|
+
const copied = frontendCriterionRedirectProblems({
|
|
800
|
+
...criterionSources,
|
|
801
|
+
docs: new Map(criterionSources.docs).set('flow-comet-design/SKILL.md',
|
|
802
|
+
criterionSources.docs.get('flow-comet-design/SKILL.md') + '\n' + criterionBlock + '\n'),
|
|
803
|
+
});
|
|
804
|
+
assertTrue(copied.some((problem) => problem.includes('第二份正文')),
|
|
805
|
+
'权威口径段复制进第二册未被判违规: ' + JSON.stringify(copied));
|
|
806
|
+
const pointerStripped = frontendCriterionRedirectProblems({
|
|
807
|
+
...criterionSources,
|
|
808
|
+
pointerDocs: new Map([...criterionSources.pointerDocs].map(([rel, text]) => [rel,
|
|
809
|
+
text.split('唯一权威').join('(反向构造:抽掉指针)')])),
|
|
810
|
+
});
|
|
811
|
+
assertTrue(pointerStripped.some((problem) => problem.includes('指针不在场')),
|
|
812
|
+
'抽掉各册指针未被判违规: ' + JSON.stringify(pointerStripped));
|
|
813
|
+
// 行为口径的散文锚:非前端可见跳过 + 旧 change 渐进(与 285 的行为断言同源)
|
|
814
|
+
const uiDesignSkill = fs.readFileSync(texts['flow-comet-ui-design/SKILL.md'], 'utf8');
|
|
815
|
+
assertTrue(uiDesignSkill.includes('UI-DESIGN: skipped(非前端)'), 'ui-design 技能缺非前端跳过口径');
|
|
816
|
+
assertTrue(uiDesignSkill.includes('旧 change') && uiDesignSkill.includes('WARN'),
|
|
817
|
+
'ui-design 技能缺旧 change 渐进口径');
|
|
818
|
+
},
|
|
819
|
+
},
|
|
820
|
+
|
|
821
|
+
// 287: 真实 `init` 跨 change 的 evolve 基线保留——`last_evolve_at` 与 `last_intel_scan` 同形
|
|
822
|
+
// (两者都是**项目级**字段:换 change 不该丢)。场景 278/279 的窗口与到期锚全用 `writeState` 直注
|
|
823
|
+
// (覆盖缺口:那条旁路绕开了 init 的保留清单,本缺陷因此完整逃过 286+90);
|
|
824
|
+
// 本场景**全程只走真实 `init` 子命令**,证明的是「跨 change 持久性」这条正常路径:
|
|
825
|
+
// 设基线 → init 新 change → 基线仍在 + `status` 的 EVOLVE-DUE 仍生效 + `evolve scan` 窗口仍按基线过滤。
|
|
826
|
+
// 断言面刻意覆盖 C1 的全部三条后果(字段丢失 / 到期提示消失 / 窗口静默退化为全量)。
|
|
827
|
+
{
|
|
828
|
+
name: '287 真实 init 跨 change:last_evolve_at 保留(基线在场·到期提示仍生效·扫描窗口仍过滤)',
|
|
829
|
+
run: (dir) => {
|
|
830
|
+
const formatStamp = requireModuleExport(timeUtilsModule, 'formatLocalTimestamp', 'time-utils.mjs');
|
|
831
|
+
const formatDate = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs');
|
|
832
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
833
|
+
const dateDaysAgo = (days) => formatDate(new Date(Date.now() - days * dayMs));
|
|
834
|
+
// 窗口两侧各一条带 §9 的归档 change(窗口过滤按目录名日期前缀判定,基线落在两者之间)
|
|
835
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(101) + '-before-baseline/DESIGN.md',
|
|
836
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
|
|
837
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(99) + '-after-baseline/DESIGN.md',
|
|
838
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
|
|
839
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
840
|
+
|
|
841
|
+
// ① 真实 init 建首个 change → 经**唯一写通道**落基线(100 天前:到期判据按天数必然触发)
|
|
842
|
+
assertExit(runStateWithProtocol(dir, ['init', CHANGE_ID, '--init-skip']), 0);
|
|
843
|
+
const baseline = formatStamp(new Date(Date.now() - 100 * dayMs));
|
|
844
|
+
const setRes = runStateWithProtocol(dir, ['config', 'set', 'last_evolve_at', baseline]);
|
|
845
|
+
assertExit(setRes, 0);
|
|
846
|
+
assertOut(setRes, 'CONFIG: last_evolve_at = ' + baseline);
|
|
847
|
+
|
|
848
|
+
// ② 真实 init 换 change——跨 change 的全部动作就是这一步(不碰 writeState)
|
|
849
|
+
const secondInit = runStateWithProtocol(dir, ['init', CHANGE_ID + '-2', '--init-skip']);
|
|
850
|
+
assertExit(secondInit, 0);
|
|
851
|
+
const state = JSON.parse(readStateBytes(dir));
|
|
852
|
+
assertEqual(state.activeChange, CHANGE_ID + '-2', 'init 后 activeChange');
|
|
853
|
+
assertEqual(state.last_evolve_at, baseline, 'init 跨 change 保留 last_evolve_at');
|
|
854
|
+
|
|
855
|
+
// ③ 到期提示仍生效(AC-18 的跨 change 形态)+ 提示行在场时 status 的 JSON 块仍可解析
|
|
856
|
+
const status = runStateWithProtocol(dir, ['status']);
|
|
857
|
+
assertExit(status, 0);
|
|
858
|
+
assertOut(status, 'EVOLVE-DUE: 上次架构沉淀 ' + baseline);
|
|
859
|
+
assertOut(status, '超阈值 60 天');
|
|
860
|
+
assertEqual(parseStatusJson(status).status, 'running', '提示行在场时 status 的 JSON 块解析');
|
|
861
|
+
|
|
862
|
+
// ④ 增量窗口仍按基线过滤(AC-4 的跨 change 形态):窗口内入选、窗口外排除,
|
|
863
|
+
// 且**不**退回「无基线(首次运行,全量扫描)」——后者正是窗口静默退化为全量的形态
|
|
864
|
+
const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
865
|
+
assertExit(scan, 0);
|
|
866
|
+
assertOut(scan, '窗口 起始 = ' + baseline);
|
|
867
|
+
assertOut(scan, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
|
|
868
|
+
assertOut(scan, 'after-baseline#1');
|
|
869
|
+
assertNotOut(scan, 'before-baseline#');
|
|
870
|
+
assertNotOut(scan, '无基线(首次运行,全量扫描)');
|
|
871
|
+
},
|
|
872
|
+
},
|
|
873
|
+
|
|
874
|
+
// 288: ui-design 工件门按协议绑定键控(负例面:协议删掉绑定)——闸门开关由协议里的 binding
|
|
875
|
+
// 表达(在场 ∧ 等级 = guarded),门禁侧只复用同一登记表 / requiredSkillCalls 查询,不存在第二份
|
|
876
|
+
// 键表。四类:负例(删绑定 → 门随绑定退场,且留可见「门未启用」行,不静默消失)/ 正例(绑定在
|
|
877
|
+
// 场且 guarded → 前端缺件仍 BLOCKED,键控未误伤既有语义)/ 越界(绑定缺席时 design 的另一
|
|
878
|
+
// guarded 绑定仍由出口自动补写——其它绑定路径逐字不变)/ 恢复(协议写回 guarded 绑定 → 门重新
|
|
879
|
+
// 拦住,键控是活判据不是一次性快照)。
|
|
880
|
+
{
|
|
881
|
+
name: '288 ui-design 门按协议绑定键控:删绑定门退场(可见行)/ 在场仍拦 / 其它绑定零改动 / 写回即恢复',
|
|
882
|
+
run: (dir) => {
|
|
883
|
+
// 负例:协议删掉该绑定 → 前端判据成立且缺件也不再拦(门随绑定退场)
|
|
884
|
+
writeUiDesignBindingVariant(dir, 'absent');
|
|
885
|
+
writeDesignExitFixture(dir, {
|
|
886
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
887
|
+
});
|
|
888
|
+
const absent = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
889
|
+
assertExit(absent, 0);
|
|
890
|
+
assertOut(absent, 'ALL CHECKS PASSED');
|
|
891
|
+
assertOut(absent, 'UI-DESIGN: 门未启用(协议 design 节点未登记 flow-comet-ui-design 绑定)');
|
|
892
|
+
assertNotOut(absent, 'BLOCKED');
|
|
893
|
+
assertNotOut(absent, 'UI-DESIGN: skipped');
|
|
894
|
+
|
|
895
|
+
// 越界:绑定缺席时 design 的另一 guarded 绑定(flow-comet-design)仍由出口自动补写——
|
|
896
|
+
// 零真实声明也放行,证明自动补语义只在登记表命中的绑定上改道
|
|
897
|
+
writeDesignExitFixture(dir, {
|
|
898
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: false, declareDesign: false,
|
|
899
|
+
});
|
|
900
|
+
const otherBindings = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
901
|
+
assertExit(otherBindings, 0);
|
|
902
|
+
assertOut(otherBindings, 'ALL CHECKS PASSED');
|
|
903
|
+
|
|
904
|
+
// 正例:协议写回 guarded 绑定 → 同一夹具、同一 change 立刻恢复拦截(与既有语义逐字一致)
|
|
905
|
+
writeUiDesignBindingVariant(dir, 'guarded');
|
|
906
|
+
writeDesignExitFixture(dir, {
|
|
907
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
908
|
+
});
|
|
909
|
+
const guardedInPlace = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
910
|
+
assertExit(guardedInPlace, 1);
|
|
911
|
+
assertOut(guardedInPlace, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
912
|
+
assertNotOut(guardedInPlace, 'UI-DESIGN: 门未启用');
|
|
913
|
+
|
|
914
|
+
// 恢复:补齐工件 + 真实声明 → 出口放行(恢复路径未被键控改动波及)
|
|
915
|
+
writeDesignExitFixture(dir, {
|
|
916
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
917
|
+
});
|
|
918
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
919
|
+
assertExit(recovered, 0);
|
|
920
|
+
assertOut(recovered, 'ALL CHECKS PASSED');
|
|
921
|
+
},
|
|
922
|
+
},
|
|
923
|
+
|
|
924
|
+
// 289: ui-design 工件门按协议绑定键控(负例面:等级降回 advisory)——`enforcement` 是该门的单一
|
|
925
|
+
// 表达处:等级非 guarded ⇒ 门不适用,且该绑定的出口自动补写回到未登记路径的原语义(声明照旧
|
|
926
|
+
// 由出口代记)。四类:负例(advisory → 不再拦)/ 正例(写回 guarded → 仍拦)/ 越界(同一节点
|
|
927
|
+
// 的另一绑定不受影响)/ 恢复(等级回到 guarded 即恢复拦截)。
|
|
928
|
+
{
|
|
929
|
+
name: '289 ui-design 门按协议等级键控:调回 advisory 不再拦且自动补写原语义 / 写回 guarded 即恢复',
|
|
930
|
+
run: (dir) => {
|
|
931
|
+
// 负例:等级调回 advisory → 缺工件 + 零真实声明也放行(自动补写保持原语义)
|
|
932
|
+
writeUiDesignBindingVariant(dir, 'advisory');
|
|
933
|
+
writeDesignExitFixture(dir, {
|
|
934
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
935
|
+
});
|
|
936
|
+
const advisory = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
937
|
+
assertExit(advisory, 0);
|
|
938
|
+
assertOut(advisory, 'ALL CHECKS PASSED');
|
|
939
|
+
assertOut(advisory, 'UI-DESIGN: 门未启用(协议 design 绑定等级 = advisory,非 guarded)');
|
|
940
|
+
assertNotOut(advisory, 'BLOCKED');
|
|
941
|
+
assertNotOut(advisory, 'UI-DESIGN: skipped');
|
|
942
|
+
|
|
943
|
+
// 越界:同一节点的另一 guarded 绑定零真实声明仍放行(自动补语义未被本次键控改道)
|
|
944
|
+
writeDesignExitFixture(dir, {
|
|
945
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: false, declareDesign: false,
|
|
946
|
+
});
|
|
947
|
+
const otherBindings = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
948
|
+
assertExit(otherBindings, 0);
|
|
949
|
+
assertOut(otherBindings, 'ALL CHECKS PASSED');
|
|
950
|
+
|
|
951
|
+
// 正例:等级写回 guarded → 缺件与缺声明双拦截同时回来
|
|
952
|
+
writeUiDesignBindingVariant(dir, 'guarded');
|
|
953
|
+
writeDesignExitFixture(dir, {
|
|
954
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: false, declareUiDesign: true,
|
|
955
|
+
});
|
|
956
|
+
const guardedInPlace = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
957
|
+
assertExit(guardedInPlace, 1);
|
|
958
|
+
assertOut(guardedInPlace, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
959
|
+
assertNotOut(guardedInPlace, 'UI-DESIGN: 门未启用');
|
|
960
|
+
|
|
961
|
+
// 恢复:补齐工件 + 真实声明 → 放行
|
|
962
|
+
writeDesignExitFixture(dir, {
|
|
963
|
+
newChange: true, visualTone: VISUAL_TONE_APPLICABLE, uiDesign: true, declareUiDesign: true,
|
|
964
|
+
});
|
|
965
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
966
|
+
assertExit(recovered, 0);
|
|
967
|
+
assertOut(recovered, 'ALL CHECKS PASSED');
|
|
968
|
+
},
|
|
969
|
+
},
|
|
970
|
+
|
|
971
|
+
// 290: 前端判据的负向标记是结构约束(不是裸子串)——三种结构形态(独立行 / 行首 / 字段值位)
|
|
972
|
+
// 任一命中即判非前端并**回显命中片段**;自然句子与子维度字段里的标记词一律不关掉整道门。
|
|
973
|
+
// 四类:负例(行首的「不适用于暗色主题」与结构形态的 `- 暗色主题:不适用` → 仍判前端,前端
|
|
974
|
+
// 缺件照样 BLOCKED)/ 正例(独立行带括注、行首带理由、字段值位三种形态可见跳过并回显片段)/
|
|
975
|
+
// 越界(段外独立行不参与判据,判据限段内)/ 恢复(改段即放行)。
|
|
976
|
+
{
|
|
977
|
+
name: '290 负向标记结构约束:独立行·行首·字段值位跳过并回显片段 / 自然句子·子维度字段·段外标记不关闸',
|
|
978
|
+
run: (dir) => {
|
|
979
|
+
// 负例:自然句子(标记词在行首且后接「于」,句内再出现一次)→ 判据仍是前端 ⇒ 缺件 BLOCKED
|
|
980
|
+
writeDesignExitFixture(dir, {
|
|
981
|
+
newChange: true, visualTone: VISUAL_TONE_NATURAL_SENTENCE, uiDesign: false, declareUiDesign: true,
|
|
982
|
+
});
|
|
983
|
+
const naturalSentence = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
984
|
+
assertExit(naturalSentence, 1);
|
|
985
|
+
assertOut(naturalSentence, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
986
|
+
assertNotOut(naturalSentence, 'UI-DESIGN: skipped');
|
|
987
|
+
assertNotOut(naturalSentence, '命中片段');
|
|
988
|
+
|
|
989
|
+
// 负例(结构形态的越界面):子维度字段 `- 暗色主题:不适用` 是结构形态但主体不是本 change
|
|
990
|
+
// 的适用性 ⇒ 仍判前端(标签表把可误伤的字段形态挡在外面)
|
|
991
|
+
writeDesignExitFixture(dir, {
|
|
992
|
+
newChange: true, visualTone: VISUAL_TONE_SUBDIMENSION_FIELD, uiDesign: false, declareUiDesign: true,
|
|
993
|
+
});
|
|
994
|
+
const subDimensionField = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
995
|
+
assertExit(subDimensionField, 1);
|
|
996
|
+
assertOut(subDimensionField, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
997
|
+
assertNotOut(subDimensionField, 'UI-DESIGN: skipped');
|
|
998
|
+
|
|
999
|
+
// 越界:标记出现在「视觉调性」段之外的独立行 → 不参与判据(判据限段内)
|
|
1000
|
+
writeDesignExitFixture(dir, {
|
|
1001
|
+
newChange: true,
|
|
1002
|
+
visualTone: VISUAL_TONE_APPLICABLE,
|
|
1003
|
+
changeTail: '\n## 范围排除(Out of Scope)\n\n不适用。\n',
|
|
1004
|
+
uiDesign: false,
|
|
1005
|
+
declareUiDesign: true,
|
|
1006
|
+
});
|
|
1007
|
+
const outsideSection = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
1008
|
+
assertExit(outsideSection, 1);
|
|
1009
|
+
assertOut(outsideSection, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
1010
|
+
assertNotOut(outsideSection, 'UI-DESIGN: skipped');
|
|
1011
|
+
|
|
1012
|
+
// 正例 A:独立行(带括注理由)→ 可见跳过 + 回显命中片段
|
|
1013
|
+
writeDesignExitFixture(dir, {
|
|
1014
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
1015
|
+
});
|
|
1016
|
+
const standalone = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
1017
|
+
assertExit(standalone, 0);
|
|
1018
|
+
assertOut(standalone, 'UI-DESIGN: skipped(非前端)');
|
|
1019
|
+
assertOut(standalone, '命中片段: 不适用(非前端项目)。');
|
|
1020
|
+
assertNotOut(standalone, 'BLOCKED');
|
|
1021
|
+
|
|
1022
|
+
// 正例 B:字段值位(`- 适用性:不适用(…)`)→ 同样判非前端(结构形态之二,非行首)
|
|
1023
|
+
writeDesignExitFixture(dir, {
|
|
1024
|
+
newChange: true, visualTone: VISUAL_TONE_FIELD_MARKER, uiDesign: false, declareUiDesign: false,
|
|
1025
|
+
});
|
|
1026
|
+
const fieldValue = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
1027
|
+
assertExit(fieldValue, 0);
|
|
1028
|
+
assertOut(fieldValue, 'UI-DESIGN: skipped(非前端)');
|
|
1029
|
+
assertOut(fieldValue, '命中片段: - 适用性:不适用(CLI 工具,无用户可见界面)');
|
|
1030
|
+
assertNotOut(fieldValue, 'BLOCKED');
|
|
1031
|
+
|
|
1032
|
+
// 正例 C:行首形态(标记 + 破折号理由,非独立行)→ 同样判非前端
|
|
1033
|
+
writeDesignExitFixture(dir, {
|
|
1034
|
+
newChange: true, visualTone: VISUAL_TONE_LINE_HEAD_MARKER, uiDesign: false, declareUiDesign: false,
|
|
1035
|
+
});
|
|
1036
|
+
const lineHead = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
1037
|
+
assertExit(lineHead, 0);
|
|
1038
|
+
assertOut(lineHead, 'UI-DESIGN: skipped(非前端)');
|
|
1039
|
+
assertOut(lineHead, '命中片段: 不适用 —— CLI 工具,无用户可见界面。');
|
|
1040
|
+
assertNotOut(lineHead, 'BLOCKED');
|
|
1041
|
+
|
|
1042
|
+
// 恢复:把调性段改成结构形态(标注路径)→ 同一 change 放行,命中片段一并回显
|
|
1043
|
+
writeDesignExitFixture(dir, {
|
|
1044
|
+
newChange: true, visualTone: VISUAL_TONE_NOT_APPLICABLE, uiDesign: false, declareUiDesign: false,
|
|
1045
|
+
});
|
|
1046
|
+
const recovered = runGuardWithProtocol(dir, ['exit', 'design']);
|
|
1047
|
+
assertExit(recovered, 0);
|
|
1048
|
+
assertOut(recovered, 'UI-DESIGN: skipped(非前端)');
|
|
1049
|
+
assertOut(recovered, '命中片段: 不适用(非前端项目)。');
|
|
1050
|
+
},
|
|
1051
|
+
},
|
|
1052
|
+
|
|
1053
|
+
// 291: 原子写单一来源——「同目录固定 `.tmp` + rename + 失败清理」惯用法在**引擎面**(入口 ∪
|
|
1054
|
+
// `lib/**`)内只允许两处形态:单一来源模块 state-schema.mjs 的**唯一实现**,与 guard 的受保护
|
|
1055
|
+
// 写入**硬化通道**(唯一临时名;由形态锚认出,是已登记例外而非漏网)。消费方(**消费面 = 入口 ∪
|
|
1056
|
+
// `lib/**`**,由真实引用派生)一律消费同一导出、零内联。判别力:① 具名导出被真实消费(import +
|
|
1057
|
+
// 调用,不是纯文本存在性);② **反向构造**——第二份实现丢进合成引擎目录,检出数必须从 2 变 3
|
|
1058
|
+
//(证明检出不恒真空过);③ 递归面探针(真实形态 shadow 树:`lib/` 下放第二份实现必红)。
|
|
1059
|
+
{
|
|
1060
|
+
name: '291 原子写单一来源:引擎面唯一实现 + 硬化通道边界锚 + 消费面零内联 + 反向构造判别力',
|
|
1061
|
+
run: async () => {
|
|
1062
|
+
// ① 惯用法唯一实现(受检面 = 引擎面;硬化通道由 ①b 的形态锚认出并计入允许集)
|
|
1063
|
+
const idiom = atomicWriteIdiomHits(SCRIPTS_DIR);
|
|
1064
|
+
const hardening = uniqueTempNameHits(SCRIPTS_DIR);
|
|
1065
|
+
assertEqual(hardening.length, 1, '「唯一临时名」硬化通道应恰一处(形态锚)实际 ' + JSON.stringify(hardening));
|
|
1066
|
+
const definition = engineDefinitionHits('writeFileAtomic');
|
|
1067
|
+
assertEqual(definition.length, 1, 'writeFileAtomic 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(definition));
|
|
1068
|
+
assertEqual(definition[0].file, 'state-schema.mjs', 'writeFileAtomic 定义文件');
|
|
1069
|
+
assertEqual(idiom.length, 2, '原子写惯用法在引擎面内应恰两处(唯一实现 + 硬化通道)实际 ' + JSON.stringify(idiom));
|
|
1070
|
+
assertEqual(idiom.find((hit) => hit.file === definition[0].file)?.count, 1,
|
|
1071
|
+
'唯一实现模块内惯用法处数(应为 1)实际 ' + JSON.stringify(idiom));
|
|
1072
|
+
assertTrue(idiom.some((hit) => hit.file === hardening[0].file),
|
|
1073
|
+
'硬化通道必须同时是惯用法指纹的一处(形态退回固定 `.tmp` 时本锚与 ①b 同时变红)');
|
|
1074
|
+
|
|
1075
|
+
// ①b 边界锚(可见,不静默排除):guard 的受保护写入是独立安全硬化通道——唯一临时名 + 快照
|
|
1076
|
+
// 复核;形态一旦退回「固定 `<目标>.tmp`」惯用法即红(检出 0 处),强制重新评估它是否落回收敛面。
|
|
1077
|
+
const guardText = engineScriptTexts().get('workflow-guard.mjs');
|
|
1078
|
+
assertEqual(typeof guardText, 'string', 'workflow-guard.mjs 不在引擎面内(受检面收缩?)');
|
|
1079
|
+
assertTrue(hasNamedImport(guardText, './state-schema.mjs', 'RUNTIME_STATE_PATH'),
|
|
1080
|
+
'workflow-guard 未从 state-schema.mjs import 运行时路径常量(单源关系被破坏,收敛面须重评)');
|
|
1081
|
+
|
|
1082
|
+
// ② 具名导出行为可用(落盘、无临时残留、失败路径 fail-closed)
|
|
1083
|
+
const writeAtomic = requireModuleExport(stateSchemaModule, 'writeFileAtomic', 'state-schema.mjs');
|
|
1084
|
+
const probe = makeTmp();
|
|
1085
|
+
try {
|
|
1086
|
+
const target = path.join(probe, 'nested', 'out.json');
|
|
1087
|
+
await writeAtomic(target, '{"ok":true}\n');
|
|
1088
|
+
assertEqual(fs.readFileSync(target, 'utf8'), '{"ok":true}\n', '原子写落盘内容');
|
|
1089
|
+
assertTrue(!fs.existsSync(target + '.tmp'), '原子写成功路径不得残留临时文件');
|
|
1090
|
+
const blocked = path.join(probe, 'blocked.txt');
|
|
1091
|
+
fs.mkdirSync(blocked + '.tmp');
|
|
1092
|
+
let thrown = null;
|
|
1093
|
+
try { await writeAtomic(blocked, '半写'); } catch (e) { thrown = e; }
|
|
1094
|
+
assertTrue(thrown !== null, '临时路径被占用时原子写必须抛错(fail-closed)');
|
|
1095
|
+
assertTrue(!fs.existsSync(blocked), '失败路径不得留下半写目标文件');
|
|
1096
|
+
} finally {
|
|
1097
|
+
cleanupTmpDir(probe);
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
// ③ 消费面(派生 · 入口 ∪ lib/**):具名取用自单源模块 + 真实调用 + 零内联第二份实现
|
|
1101
|
+
const atomicSymbols = ['writeJsonAtomic', 'writeFileAtomic'];
|
|
1102
|
+
const texts = engineScriptTexts();
|
|
1103
|
+
const consumers = new Map();
|
|
1104
|
+
for (const symbol of atomicSymbols) {
|
|
1105
|
+
for (const rel of engineConsumersOf(symbol)) {
|
|
1106
|
+
if (rel === definition[0].file) continue;
|
|
1107
|
+
consumers.set(rel, [...(consumers.get(rel) ?? []), symbol]);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
assertTrue(consumers.size >= 4,
|
|
1111
|
+
'原子写消费面收缩(入口 ∪ lib 的消费方应≥4 个模块): ' + JSON.stringify([...consumers.keys()]));
|
|
1112
|
+
for (const [file, symbols] of consumers) {
|
|
1113
|
+
const text = texts.get(file);
|
|
1114
|
+
for (const symbol of symbols) {
|
|
1115
|
+
assertTrue(text.includes(symbol + '('), file + ' 未真实消费 ' + symbol + '(单一权威应被调用)');
|
|
1116
|
+
}
|
|
1117
|
+
const inline = (text.match(ATOMIC_TEMP_SUFFIX_RE) ?? []).length;
|
|
1118
|
+
assertEqual(inline, 0, file + ' 仍内联原子写惯用法(第二份实现)处数');
|
|
1119
|
+
}
|
|
1120
|
+
// 单源面(定义唯一 + 消费方一律取用):同一判据驱动,消费面由真实引用派生
|
|
1121
|
+
for (const symbol of atomicSymbols) {
|
|
1122
|
+
const symbolProblems = singleSourceImportProblems({ symbol, sourceRel: definition[0].file, texts });
|
|
1123
|
+
assertEqual(symbolProblems.length, 0, '原子写单源面被破坏(' + symbol + '): ' + symbolProblems.join(' | '));
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
// ④ 反向构造(数据驱动 · 不依赖全局计数地板):真实形态 shadow 树——`lib/` 下放第二份实现
|
|
1127
|
+
// ⇒ 惯用法检出数从 2 变 3(平铺面只会看到顶层那 1 处,本探针即红)。
|
|
1128
|
+
const shadow = makeTmp();
|
|
1129
|
+
try {
|
|
1130
|
+
const shadowScripts = copyEngineTree(shadow);
|
|
1131
|
+
assertEqual(atomicWriteIdiomHits(shadowScripts).length, 2, 'shadow 树基线(唯一实现 + 硬化通道)');
|
|
1132
|
+
writeFile(shadowScripts, path.join('lib', 'second.mjs'),
|
|
1133
|
+
"export async function duplicateWriter(file, text) {\n"
|
|
1134
|
+
+ " const temporary = file + '.tmp';\n"
|
|
1135
|
+
+ ' await fs.writeFile(temporary, text);\n'
|
|
1136
|
+
+ ' await fs.rename(temporary, file);\n'
|
|
1137
|
+
+ '}\n');
|
|
1138
|
+
assertEqual(atomicWriteIdiomHits(shadowScripts).length, 3,
|
|
1139
|
+
'lib/ 下的第二份实现必须被递归面检出(平铺面会静默失明)');
|
|
1140
|
+
} finally {
|
|
1141
|
+
cleanupTmpDir(shadow);
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1144
|
+
// ④ 反向构造:合成引擎目录(单文件 1 处 → 检出 1;再放第二份实现 → 检出 2)——
|
|
1145
|
+
// 证明③的判据确实会因第二份实现变红,而非恒真空过。
|
|
1146
|
+
const synthetic = makeTmp();
|
|
1147
|
+
try {
|
|
1148
|
+
writeFile(synthetic, 'single.mjs',
|
|
1149
|
+
"export async function duplicateWriter(file, text) {\n"
|
|
1150
|
+
+ " const temporary = file + '.tmp';\n"
|
|
1151
|
+
+ ' await fs.writeFile(temporary, text);\n'
|
|
1152
|
+
+ ' await fs.rename(temporary, file);\n'
|
|
1153
|
+
+ '}\n');
|
|
1154
|
+
assertEqual(atomicWriteIdiomHits(synthetic).length, 1, '合成目录单实现检出数');
|
|
1155
|
+
writeFile(synthetic, 'second.mjs',
|
|
1156
|
+
"async function anotherWriter(file, text) {\n"
|
|
1157
|
+
+ " const temporary = file + '.tmp';\n"
|
|
1158
|
+
+ ' await fs.writeFile(temporary, text);\n'
|
|
1159
|
+
+ ' await fs.rename(temporary, file);\n'
|
|
1160
|
+
+ '}\n');
|
|
1161
|
+
assertEqual(atomicWriteIdiomHits(synthetic).length, 2, '合成目录第二份实现检出数(判据须变红)');
|
|
1162
|
+
} finally {
|
|
1163
|
+
cleanupTmpDir(synthetic);
|
|
1164
|
+
}
|
|
1165
|
+
},
|
|
1166
|
+
},
|
|
1167
|
+
|
|
1168
|
+
// 292: evolve 元数据字段面单一来源——`## evolve 元数据` 的段名与三字段名在 state-schema.mjs
|
|
1169
|
+
// 唯一导出,写方(evolve)与校验方(context-init)同源消费、零内联字面量;容差收窄到单形:
|
|
1170
|
+
// 无生产者的旧别名「下次同步建议」不再被静默接受,而是**可见**的格式提示(点名旧别名 + 应改
|
|
1171
|
+
// 写的字段名)。写→校一致性用真实链路:evolve apply 生成的段必须零格式问题通过校验。
|
|
1172
|
+
{
|
|
1173
|
+
name: '292 evolve 元数据单一来源:常量集唯一导出·写校同源·旧别名收窄为可见提示',
|
|
1174
|
+
run: async (dir) => {
|
|
1175
|
+
// ① 常量集唯一导出 + 取值单形(去掉无生产者的旧别名是**取值**层面的收窄)
|
|
1176
|
+
for (const name of ['EVOLVE_METADATA_SECTION', 'EVOLVE_METADATA_FIELDS']) {
|
|
1177
|
+
const hits = engineDefinitionHits(name);
|
|
1178
|
+
assertEqual(hits.length, 1, name + ' 定义面(全引擎应恰 1 处)实际 ' + JSON.stringify(hits));
|
|
1179
|
+
assertEqual(hits[0].file, 'state-schema.mjs', name + ' 定义文件');
|
|
1180
|
+
}
|
|
1181
|
+
const section = requireModuleExport(stateSchemaModule, 'EVOLVE_METADATA_SECTION', 'state-schema.mjs');
|
|
1182
|
+
const fields = requireModuleExport(stateSchemaModule, 'EVOLVE_METADATA_FIELDS', 'state-schema.mjs');
|
|
1183
|
+
assertEqual(section, 'evolve 元数据', '段名常量取值');
|
|
1184
|
+
assertEqual(fields.join(','), ['last_evolve_at', 'scanner', '下次建议'].join(','), '三字段常量取值');
|
|
1185
|
+
|
|
1186
|
+
// ② 写方与校验方同源消费 + 零内联字面量(第二份表达即变红)
|
|
1187
|
+
for (const file of ['evolve.mjs', 'context-init.mjs']) {
|
|
1188
|
+
const text = fs.readFileSync(path.join(SCRIPTS_DIR, file), 'utf8');
|
|
1189
|
+
assertTrue(hasNamedImport(text, './state-schema.mjs', 'EVOLVE_METADATA_SECTION'),
|
|
1190
|
+
file + ' 未从 state-schema.mjs import 段名常量');
|
|
1191
|
+
assertTrue(text.includes('EVOLVE_METADATA_FIELDS'), file + ' 未消费字段常量集');
|
|
1192
|
+
assertTrue(!/'evolve 元数据'/.test(text), file + ' 仍内联段名字面量(第二份表达)');
|
|
1193
|
+
assertTrue(!/'下次建议'/.test(text), file + ' 仍内联第三字段字面量(第二份表达)');
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
// ③ 写→校一致性(真实链路):evolve apply 产出的段必须被校验方无问题接收
|
|
1197
|
+
writeFile(dir, '.specs/archive/2026-10-02-fixture/DESIGN.md',
|
|
1198
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 夹具抽象条目(元数据单一来源)\n');
|
|
1199
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
1200
|
+
writeState(dir, baseState('open'));
|
|
1201
|
+
const apply = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-fixture#1', '--root', dir], dir);
|
|
1202
|
+
assertExit(apply, 0);
|
|
1203
|
+
assertOut(apply, 'EVOLVE-OK');
|
|
1204
|
+
const written = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
1205
|
+
for (const field of fields) {
|
|
1206
|
+
assertTrue(written.includes('**' + field + '**'), '写方产出的段缺字段 ' + field);
|
|
1207
|
+
}
|
|
1208
|
+
const validate = requireModuleExport(contextInitModule, 'validateContext', 'context-init.mjs');
|
|
1209
|
+
const consistent = await validate(dir);
|
|
1210
|
+
assertEqual(consistent.missingSections.length, 0,
|
|
1211
|
+
'夹具七段骨架缺段: ' + JSON.stringify(consistent.missingSections));
|
|
1212
|
+
assertEqual(consistent.formatIssues.length, 0,
|
|
1213
|
+
'写方产物未通过校验方(同源失配): ' + JSON.stringify(consistent.formatIssues));
|
|
1214
|
+
|
|
1215
|
+
// ④ 容差收窄判别力:旧别名顶替第三字段 → 必报,且提示点名旧别名与应写字段(可见,不静默)
|
|
1216
|
+
const aliased = contextFixtureText({ evolveSection: [
|
|
1217
|
+
'- **' + fields[0] + '**: `2026-10-02T10:00:00+08:00`',
|
|
1218
|
+
'- **' + fields[1] + '**: `flow-comet-evolve`',
|
|
1219
|
+
'- **下次同步建议**: 约 60 天后',
|
|
1220
|
+
] });
|
|
1221
|
+
writeFile(dir, '.specs/CONTEXT.md', aliased);
|
|
1222
|
+
const aliasedIssues = (await validate(dir)).formatIssues;
|
|
1223
|
+
assertTrue(aliasedIssues.some((issue) => issue.includes('evolve 元数据三字段')),
|
|
1224
|
+
'旧别名未被收窄(仍静默通过): ' + JSON.stringify(aliasedIssues));
|
|
1225
|
+
assertTrue(aliasedIssues.some((issue) => issue.includes('下次同步建议') && issue.includes('不再接受')),
|
|
1226
|
+
'旧别名未给出可见格式提示: ' + JSON.stringify(aliasedIssues));
|
|
1227
|
+
},
|
|
1228
|
+
},
|
|
1229
|
+
|
|
1230
|
+
// 293: 侧命令 CLI 契约——三条横向命令的 `--root` 两种形态 / `--stdout` / `--help` /
|
|
1231
|
+
// 未知参数走**同一份**共享助手:等号形三命令一致(修复前 evolve 报「未知参数: --root=.」exit 1)、
|
|
1232
|
+
// `--help`/`-h` 三命令一致(修复前只有 health 有)、空格形与未知参数的退出码语义保持不变;
|
|
1233
|
+
// 位置参数语义由各命令自持(evolve 的 scan/apply 子命令与候选 id)。结构锚:带引号的 `--root`
|
|
1234
|
+
// 解析形态与「未知参数」构造在三条命令里**只允许出现在共享助手一处**,第二份自写脚手架即红。
|
|
1235
|
+
{
|
|
1236
|
+
name: '293 侧命令 CLI 契约:--root 两形态·--stdout·--help 三命令同形 + 未知参数语义不变 + 解析面单源',
|
|
1237
|
+
run: (dir) => {
|
|
1238
|
+
writeFile(dir, '.specs/archive/2026-10-02-cli/DESIGN.md',
|
|
1239
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- CLI 契约夹具条目\n');
|
|
1240
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
1241
|
+
writeState(dir, baseState('open'));
|
|
1242
|
+
|
|
1243
|
+
// ① 等号形 `--root=<目录>`:三命令等价(修复前 evolve 是唯一不支持的一条)
|
|
1244
|
+
const evolveEq = runSideScript(SIDE_EVOLVE, ['scan', '--root=' + dir], dir);
|
|
1245
|
+
assertExit(evolveEq, 0);
|
|
1246
|
+
assertOut(evolveEq, 'EVOLVE: 窗口');
|
|
1247
|
+
assertOut(evolveEq, '2026-10-02-cli#1');
|
|
1248
|
+
const healthEq = runSideScript(SIDE_HEALTH, ['--root=' + dir, '--stdout'], dir);
|
|
1249
|
+
assertExit(healthEq, 0);
|
|
1250
|
+
assertOut(healthEq, '## 确定性层(机器可判)');
|
|
1251
|
+
const scanEq = runSideScript(SIDE_CONTEXT_SCAN, ['--root=' + dir], dir);
|
|
1252
|
+
assertExit(scanEq, 0);
|
|
1253
|
+
assertOut(scanEq, 'CONTEXT-SCAN-DONE');
|
|
1254
|
+
|
|
1255
|
+
// ② 空格形 `--root <目录>`:向后兼容(三命令语义不变)
|
|
1256
|
+
const evolveSpace = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
1257
|
+
assertExit(evolveSpace, 0);
|
|
1258
|
+
assertOut(evolveSpace, 'EVOLVE: 窗口');
|
|
1259
|
+
const healthSpace = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
1260
|
+
assertExit(healthSpace, 0);
|
|
1261
|
+
assertOut(healthSpace, '## 确定性层(机器可判)');
|
|
1262
|
+
const scanSpace = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
1263
|
+
assertExit(scanSpace, 0);
|
|
1264
|
+
assertOut(scanSpace, 'CONTEXT-SCAN-DONE');
|
|
1265
|
+
|
|
1266
|
+
// ③ `--help` / `-h`:三命令一律打印**自己的**用法后 exit 0(用法里各自列出自身命令形态)
|
|
1267
|
+
const helpCases = [
|
|
1268
|
+
{ args: ['--help'], keywords: ['evolve.mjs scan', 'evolve.mjs apply', '--stdout'] },
|
|
1269
|
+
{ args: ['-h'], keywords: ['health.mjs', '--root', '--stdout'] },
|
|
1270
|
+
{ args: ['--help'], keywords: ['context-scan.mjs', '--root', '--stdout'] },
|
|
1271
|
+
];
|
|
1272
|
+
const helpScripts = [SIDE_EVOLVE, SIDE_HEALTH, SIDE_CONTEXT_SCAN];
|
|
1273
|
+
for (let i = 0; i < helpScripts.length; i += 1) {
|
|
1274
|
+
const res = runSideScript(helpScripts[i], helpCases[i].args, dir);
|
|
1275
|
+
assertExit(res, 0);
|
|
1276
|
+
for (const keyword of helpCases[i].keywords) assertOut(res, keyword);
|
|
1277
|
+
}
|
|
1278
|
+
// 子命令之后的 `--help` 同样短路(不因缺候选 id 报用法错误)
|
|
1279
|
+
const applyHelp = runSideScript(SIDE_EVOLVE, ['apply', '--help'], dir);
|
|
1280
|
+
assertExit(applyHelp, 0);
|
|
1281
|
+
assertOut(applyHelp, 'evolve.mjs apply');
|
|
1282
|
+
// `--stdout` 三命令均被接受(evolve 的 scan 本就全量输出到标准输出)
|
|
1283
|
+
assertExit(runSideScript(SIDE_EVOLVE, ['scan', '--stdout', '--root', dir], dir), 0);
|
|
1284
|
+
// evolve 的 `--stdout` 语义 = 本次追加进报告的内容原样输出(与落盘块逐字节相同);
|
|
1285
|
+
// 命令自有取值开关的等号形同样走共享助手(`--scanner=<文本>`)
|
|
1286
|
+
const applyOut = runSideScript(SIDE_EVOLVE,
|
|
1287
|
+
['apply', '2026-10-02-cli#1', '--root', dir, '--stdout', '--scanner=契约夹具扫描器'], dir);
|
|
1288
|
+
assertExit(applyOut, 0);
|
|
1289
|
+
assertOut(applyOut, 'EVOLVE-OK');
|
|
1290
|
+
const today = requireModuleExport(timeUtilsModule, 'formatLocalDate', 'time-utils.mjs')(new Date());
|
|
1291
|
+
const evolveReport = fs.readFileSync(path.join(dir, '.specs', 'evolve', today + '-EVOLVE.md'), 'utf8');
|
|
1292
|
+
assertTrue(applyOut.output.includes(evolveReport),
|
|
1293
|
+
'--stdout 输出应与落盘报告块逐字节一致(stdout 与文件各自渲染即漂移)');
|
|
1294
|
+
assertTrue(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8').includes('契约夹具扫描器'),
|
|
1295
|
+
'命令自有取值开关(--scanner=<文本>)未生效');
|
|
1296
|
+
|
|
1297
|
+
// ④ 未知参数:三命令一律 exit 1 且点名该词元(既有退出码语义不变)
|
|
1298
|
+
for (const script of helpScripts) {
|
|
1299
|
+
const unknown = runSideScript(script, ['--bogus'], dir);
|
|
1300
|
+
assertExit(unknown, 1);
|
|
1301
|
+
assertOut(unknown, '未知参数: --bogus');
|
|
1302
|
+
}
|
|
1303
|
+
// 位置参数语义按命令自持:evolve 的 scan 拒位置参数、apply 缺候选 id 仍报用法错误
|
|
1304
|
+
const scanExtra = runSideScript(SIDE_EVOLVE, ['scan', 'extra'], dir);
|
|
1305
|
+
assertExit(scanExtra, 1);
|
|
1306
|
+
assertOut(scanExtra, 'scan 不接受位置参数: extra');
|
|
1307
|
+
const applyEmpty = runSideScript(SIDE_EVOLVE, ['apply', '--root', dir], dir);
|
|
1308
|
+
assertExit(applyEmpty, 1);
|
|
1309
|
+
assertOut(applyEmpty, 'apply 需要至少一个候选 id');
|
|
1310
|
+
// 取值开关悬空 → 用法错误(三命令同一文案、同一退出码)
|
|
1311
|
+
for (const script of helpScripts) {
|
|
1312
|
+
const dangling = runSideScript(script, ['--root'], dir);
|
|
1313
|
+
assertExit(dangling, 1);
|
|
1314
|
+
assertOut(dangling, '--root 需要一个目录参数');
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
// ⑤ 结构锚:解析形态只此一处(共享助手);两个消费方具名 import + 真实调用
|
|
1318
|
+
const parseFace = new Map(helpScripts.map((script) => [path.basename(script), fs.readFileSync(script, 'utf8')]));
|
|
1319
|
+
const rootTokenFiles = [...parseFace].filter(([, text]) => text.includes("'--root'")).map(([file]) => file);
|
|
1320
|
+
assertEqual(rootTokenFiles.join(','), 'evolve.mjs',
|
|
1321
|
+
'带引号的 `--root` 解析形态应只出现在共享助手一处(实际: ' + (rootTokenFiles.join(',') || '无') + ')');
|
|
1322
|
+
const unknownTokenFiles = [...parseFace].filter(([, text]) => text.includes('未知参数: ')).map(([file]) => file);
|
|
1323
|
+
assertEqual(unknownTokenFiles.join(','), 'evolve.mjs',
|
|
1324
|
+
'「未知参数」构造应只出现在共享助手一处(实际: ' + (unknownTokenFiles.join(',') || '无') + ')');
|
|
1325
|
+
for (const file of ['health.mjs', 'context-scan.mjs']) {
|
|
1326
|
+
const text = parseFace.get(file);
|
|
1327
|
+
assertTrue(hasNamedImport(text, './evolve.mjs', 'parseSideCommandArgs'),
|
|
1328
|
+
file + ' 未从共享助手模块具名 import parseSideCommandArgs(第二份脚手架或未接线)');
|
|
1329
|
+
assertTrue(text.includes('parseSideCommandArgs('), file + ' 未真实调用共享助手');
|
|
1330
|
+
}
|
|
1331
|
+
},
|
|
1332
|
+
},
|
|
1333
|
+
|
|
1334
|
+
// 294: 损坏 state 的 fail-closed 与「首次运行」口径收窄 + 协议路径单源——
|
|
1335
|
+
// ① state 文件在场但不可解析(含顶层非对象)→ `evolve scan` BLOCKED 且零写入,不再谎称
|
|
1336
|
+
// 「无基线(首次运行,全量扫描)」把增量窗口静默退化为全量;② 「首次运行」只限
|
|
1337
|
+
// 「state 可读且字段缺席」,state 不在场另有措辞(不冒充首次运行);③ 协议路径走
|
|
1338
|
+
// state-schema 的唯一选择器:state.protocolPath 绑定**独占**(项目内约定副本坏掉也必须成功、
|
|
1339
|
+
// 绑定本身坏掉也不回退候选布局),本模块零候选布局表。
|
|
1340
|
+
{
|
|
1341
|
+
name: '294 损坏 state fail-closed:scan/apply BLOCKED 零写入·首次运行口径收窄 + 协议路径走单源选择器',
|
|
1342
|
+
run: (dir) => {
|
|
1343
|
+
writeFile(dir, '.specs/archive/2026-10-02-state/DESIGN.md',
|
|
1344
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 状态口径夹具条目\n');
|
|
1345
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
1346
|
+
const stateFile = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
1347
|
+
writeState(dir, baseState('open'));
|
|
1348
|
+
|
|
1349
|
+
// ① state 不在场:显式点名「state 不在场」,不冒充「首次运行」(全量扫描仍可用)
|
|
1350
|
+
fs.rmSync(stateFile);
|
|
1351
|
+
const noState = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
1352
|
+
assertExit(noState, 0);
|
|
1353
|
+
assertOut(noState, 'state 不在场');
|
|
1354
|
+
assertNotOut(noState, '无基线(首次运行,全量扫描)');
|
|
1355
|
+
|
|
1356
|
+
// ② state 可读且字段缺席 = 唯一的「首次运行」口径(全量扫描)
|
|
1357
|
+
writeState(dir, baseState('open'));
|
|
1358
|
+
const firstRun = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
1359
|
+
assertExit(firstRun, 0);
|
|
1360
|
+
assertOut(firstRun, '无基线(首次运行,全量扫描)');
|
|
1361
|
+
assertOut(firstRun, '窗口内 1 个');
|
|
1362
|
+
|
|
1363
|
+
// ③ 损坏 state(JSON 截断):fail-closed —— BLOCKED + 零写入,不再退化成全量扫描
|
|
1364
|
+
const stateText = fs.readFileSync(stateFile, 'utf8');
|
|
1365
|
+
const truncated = stateText.slice(0, Math.max(1, Math.floor(stateText.length / 2)));
|
|
1366
|
+
fs.writeFileSync(stateFile, truncated, 'utf8');
|
|
1367
|
+
const damagedBytes = readStateBytes(dir);
|
|
1368
|
+
const before = treeFingerprint(dir);
|
|
1369
|
+
const blocked = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
1370
|
+
assertExit(blocked, 1);
|
|
1371
|
+
assertOut(blocked, 'BLOCKED');
|
|
1372
|
+
assertOut(blocked, '无法解析');
|
|
1373
|
+
assertNotOut(blocked, '首次运行');
|
|
1374
|
+
assertNotOut(blocked, '候选清单');
|
|
1375
|
+
assertEqual(readStateBytes(dir), damagedBytes, '损坏 state 的 scan 轮改写了 state');
|
|
1376
|
+
assertEqual(fingerprintChanges(before, treeFingerprint(dir)).join(' | '), '',
|
|
1377
|
+
'损坏 state 的 scan 轮有写入');
|
|
1378
|
+
|
|
1379
|
+
// ④ 顶层非对象(数组)同样判「不可信」——不得冒充「字段缺席」
|
|
1380
|
+
fs.writeFileSync(stateFile, '[]\n', 'utf8');
|
|
1381
|
+
const arrayState = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
1382
|
+
assertExit(arrayState, 1);
|
|
1383
|
+
assertOut(arrayState, 'BLOCKED');
|
|
1384
|
+
assertOut(arrayState, '无法解析');
|
|
1385
|
+
|
|
1386
|
+
// ⑤ 损坏态下 apply 同样 fail-closed:目标文档 / 报告 / state 三处零改动
|
|
1387
|
+
fs.writeFileSync(stateFile, truncated, 'utf8');
|
|
1388
|
+
const contextBefore = fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8');
|
|
1389
|
+
const applyBlocked = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-state#1', '--root', dir], dir);
|
|
1390
|
+
assertExit(applyBlocked, 1);
|
|
1391
|
+
assertOut(applyBlocked, 'BLOCKED');
|
|
1392
|
+
assertEqual(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8'), contextBefore,
|
|
1393
|
+
'损坏 state 的 apply 轮改写了目标文档');
|
|
1394
|
+
assertTrue(!fs.existsSync(path.join(dir, '.specs', 'evolve')), '损坏 state 的 apply 轮落了报告');
|
|
1395
|
+
|
|
1396
|
+
// ⑥ 协议路径单源:state.protocolPath 绑定独占——项目内约定副本坏掉,绑定好 → 必须成功
|
|
1397
|
+
// (修复前的候选布局表先命中 <根>/reference/workflow-protocol.json → 子进程按坏协议 BLOCK)
|
|
1398
|
+
writeFile(dir, '.specs/archive/2026-10-02-proto/DESIGN.md',
|
|
1399
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 协议绑定夹具条目\n');
|
|
1400
|
+
fs.writeFileSync(path.join(dir, 'reference', 'workflow-protocol.json'),
|
|
1401
|
+
'{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
1402
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(dir, 'bound-protocol.json'));
|
|
1403
|
+
writeState(dir, { ...baseState('open'), protocolPath: 'bound-protocol.json' });
|
|
1404
|
+
const bound = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-proto#1', '--root', dir], dir,
|
|
1405
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
1406
|
+
assertExit(bound, 0);
|
|
1407
|
+
assertOut(bound, 'EVOLVE-OK');
|
|
1408
|
+
assertTrue(fs.readFileSync(path.join(dir, '.specs', 'CONTEXT.md'), 'utf8').includes('协议绑定夹具条目'),
|
|
1409
|
+
'状态绑定协议下的 apply 未落盘条目');
|
|
1410
|
+
|
|
1411
|
+
// ⑦ 绑定本身坏掉 → fail-closed 可见(不回退项目内约定副本),指引指向绑定修正
|
|
1412
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(dir, 'reference', 'workflow-protocol.json'));
|
|
1413
|
+
fs.writeFileSync(path.join(dir, 'broken-protocol.json'), '{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
1414
|
+
writeState(dir, { ...baseState('open'), protocolPath: 'broken-protocol.json' });
|
|
1415
|
+
const brokenBytes = readStateBytes(dir);
|
|
1416
|
+
const broken = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-proto#1', '--root', dir], dir,
|
|
1417
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
1418
|
+
assertExit(broken, 1);
|
|
1419
|
+
assertOut(broken, 'state 写入通道失败');
|
|
1420
|
+
assertOut(broken, 'state.protocolPath');
|
|
1421
|
+
assertEqual(readStateBytes(dir), brokenBytes, '绑定损坏的 apply 轮改写了 state');
|
|
1422
|
+
|
|
1423
|
+
// ⑧ 写入前先验 state 通道(协议闸门):通道排在文档之后,不预验就有半成品——候选**未应用过**
|
|
1424
|
+
// (目标文档必然会被改写),绑定指向 schema 非法的根内副本 ⇒ 必须零文档改动、零报告、零 state。
|
|
1425
|
+
const halfRoot = path.join(dir, 'half-write');
|
|
1426
|
+
writeFile(halfRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
1427
|
+
writeFile(halfRoot, '.specs/archive/2026-10-02-half/DESIGN.md',
|
|
1428
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 半成品夹具条目\n');
|
|
1429
|
+
fs.writeFileSync(path.join(halfRoot, 'broken-protocol.json'), '{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
1430
|
+
writeState(halfRoot, { ...baseState('open'), protocolPath: 'broken-protocol.json' });
|
|
1431
|
+
const halfContextBefore = fs.readFileSync(path.join(halfRoot, '.specs', 'CONTEXT.md'));
|
|
1432
|
+
const halfStateBefore = readStateBytes(halfRoot);
|
|
1433
|
+
const half = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-half#1', '--root', halfRoot], halfRoot,
|
|
1434
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
1435
|
+
assertExit(half, 1);
|
|
1436
|
+
assertOut(half, 'state 写入通道失败');
|
|
1437
|
+
assertOut(half, 'state.protocolPath');
|
|
1438
|
+
assertTrue(fs.readFileSync(path.join(halfRoot, '.specs', 'CONTEXT.md')).equals(halfContextBefore),
|
|
1439
|
+
'state 通道不可用的 apply 轮改写了目标文档(写入前未验通道 ⇒ 半成品)');
|
|
1440
|
+
assertStateBytesUnchanged(halfRoot, halfStateBefore, 'state 通道不可用的 apply 轮');
|
|
1441
|
+
assertTrue(!fs.existsSync(path.join(halfRoot, '.specs', 'evolve')),
|
|
1442
|
+
'state 通道不可用的 apply 轮落了报告');
|
|
1443
|
+
|
|
1444
|
+
// ⑨ 第二条确定性闸门(state 字段非法)同样必须在文档写入之前拦下——通道预验不能只验协议。
|
|
1445
|
+
// 协议经 state.protocolPath 绑到根内合法副本(这一格只考字段闸门,不考协议闸门)。
|
|
1446
|
+
const fieldRoot = path.join(dir, 'half-write-field');
|
|
1447
|
+
writeFile(fieldRoot, '.specs/CONTEXT.md', contextFixtureText());
|
|
1448
|
+
writeFile(fieldRoot, '.specs/archive/2026-10-02-field/DESIGN.md',
|
|
1449
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 字段闸门夹具条目\n');
|
|
1450
|
+
fs.mkdirSync(path.join(fieldRoot, 'reference'), { recursive: true });
|
|
1451
|
+
fs.copyFileSync(SKILL_PROTOCOL_FILE, path.join(fieldRoot, 'reference', 'workflow-protocol.json'));
|
|
1452
|
+
writeState(fieldRoot, {
|
|
1453
|
+
...baseState('open'), executionMode: 'not-a-mode', protocolPath: 'reference/workflow-protocol.json',
|
|
1454
|
+
});
|
|
1455
|
+
const fieldContextBefore = fs.readFileSync(path.join(fieldRoot, '.specs', 'CONTEXT.md'));
|
|
1456
|
+
const fieldStateBefore = readStateBytes(fieldRoot);
|
|
1457
|
+
const fieldGate = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-field#1', '--root', fieldRoot], fieldRoot,
|
|
1458
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
1459
|
+
assertExit(fieldGate, 1);
|
|
1460
|
+
assertOut(fieldGate, 'state 写入通道失败');
|
|
1461
|
+
assertOut(fieldGate, 'executionMode');
|
|
1462
|
+
assertTrue(fs.readFileSync(path.join(fieldRoot, '.specs', 'CONTEXT.md')).equals(fieldContextBefore),
|
|
1463
|
+
'state 字段非法的一轮改写了目标文档(写入前未验字段闸门 ⇒ 半成品)');
|
|
1464
|
+
assertStateBytesUnchanged(fieldRoot, fieldStateBefore, 'state 字段非法的 apply 轮');
|
|
1465
|
+
|
|
1466
|
+
// ⑩ 结构锚:本模块不再自持候选布局表;协议路径只经 state-schema 的唯一导出选择;
|
|
1467
|
+
// state 三态读入口两条侧命令共用一个实现(第二份内联即红)
|
|
1468
|
+
const evolveText = fs.readFileSync(SIDE_EVOLVE, 'utf8');
|
|
1469
|
+
assertTrue(hasNamedImport(evolveText, './state-schema.mjs', 'resolveProtocolPathWithState'),
|
|
1470
|
+
'evolve.mjs 未从 state-schema.mjs 具名 import 协议路径选择器');
|
|
1471
|
+
assertTrue(evolveText.includes('resolveProtocolPathWithState('), 'evolve.mjs 未真实调用协议路径选择器');
|
|
1472
|
+
assertTrue(!evolveText.includes("'reference', 'workflow-protocol.json'"),
|
|
1473
|
+
'evolve.mjs 仍自持项目内约定副本候选(第二套「协议在哪」表达)');
|
|
1474
|
+
assertTrue(!evolveText.includes("'.flow-comet', 'skills'"),
|
|
1475
|
+
'evolve.mjs 仍自持权威源布局候选(第二套「协议在哪」表达)');
|
|
1476
|
+
const scanText = fs.readFileSync(SIDE_CONTEXT_SCAN, 'utf8');
|
|
1477
|
+
assertTrue(hasNamedImport(scanText, './evolve.mjs', 'readStateInfo'),
|
|
1478
|
+
'context-scan.mjs 未共用 state 三态读入口(第二份读盘实现)');
|
|
1479
|
+
assertTrue(scanText.includes('readStateInfo('), 'context-scan.mjs 未真实调用共用的 state 读入口');
|
|
1480
|
+
assertTrue(!/function\s+readStateFile\b/.test(scanText),
|
|
1481
|
+
'context-scan.mjs 仍保留本地 state 读实现(三态判定第二份表达)');
|
|
1482
|
+
},
|
|
1483
|
+
},
|
|
1484
|
+
];
|