flow-comet 1.6.1 → 1.6.3
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 +94 -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} +22 -30
- 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/reference/workflow-protocol.json +1 -1
- package/.flow-comet/skills/flow-comet/scripts/comet-check.mjs +5 -4
- package/.flow-comet/skills/flow-comet/scripts/comet-hook-guard.mjs +260 -17
- package/.flow-comet/skills/flow-comet/scripts/context-init.mjs +129 -3
- package/.flow-comet/skills/flow-comet/scripts/context-scan.mjs +396 -0
- package/.flow-comet/skills/flow-comet/scripts/evolve.mjs +778 -0
- package/.flow-comet/skills/flow-comet/scripts/guard-self-test.mjs +5432 -194
- package/.flow-comet/skills/flow-comet/scripts/health.mjs +664 -0
- package/.flow-comet/skills/flow-comet/scripts/route-node.mjs +51 -4
- package/.flow-comet/skills/flow-comet/scripts/state-schema.mjs +68 -0
- package/.flow-comet/skills/flow-comet/scripts/system-test.mjs +1479 -11
- package/.flow-comet/skills/flow-comet/scripts/time-utils.mjs +133 -0
- package/.flow-comet/skills/flow-comet/scripts/workflow-guard.mjs +197 -5
- package/.flow-comet/skills/flow-comet/scripts/workflow-handoff.mjs +115 -6
- package/.flow-comet/skills/flow-comet/scripts/workflow-state.mjs +261 -29
- package/.flow-comet/skills/flow-comet-archive/SKILL.md +10 -19
- package/.flow-comet/skills/flow-comet-change/SKILL.md +10 -1
- package/.flow-comet/skills/flow-comet-compose/SKILL.md +1 -1
- package/.flow-comet/skills/flow-comet-design/SKILL.md +8 -6
- package/.flow-comet/skills/flow-comet-evolve/SKILL.md +46 -11
- package/.flow-comet/skills/flow-comet-execute/SKILL.md +58 -16
- package/.flow-comet/skills/flow-comet-health/SKILL.md +57 -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 +29 -4
- package/.flow-comet/skills/flow-comet-verify/SKILL.md +8 -17
- package/README.md +5 -5
- package/package.json +1 -1
- package/scripts/dsh-bridge.mjs +59 -26
- package/scripts/prepare-env.mjs +165 -1
- 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
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
// purge 语义/描述符驱动/dsh 平台断言/loader 版本戳重装断言/hook 注入形态无关断言与旧条目幂等升级/
|
|
23
23
|
// 旧布局状态迁移后状态可读与流程可继续/契约核对 CLI 参数化目录解析与缺省回退回归锚/
|
|
24
24
|
// 分发面包体边界·可发布性清单与 bin 双入口(权威源真跑·副本回传显式「不适用」结果标记)
|
|
25
|
+
// ·安装器升级路径清理(权威源已删除或改名的生成物不得残留·反向探针 + 幂等)
|
|
25
26
|
// 与 init 词元红线)
|
|
26
27
|
// L. 执行遗漏防护(entry 进入证据/空退出豁免/空仓库提示)
|
|
27
28
|
//
|
|
@@ -600,6 +601,42 @@ function assertPackageBoundary(root) {
|
|
|
600
601
|
console.log(' 包体边界: ' + files.length + ' 文件,技能树 ' + skillsOnDisk.length + ' 文件逐文件在场,私有面零命中 ✓');
|
|
601
602
|
}
|
|
602
603
|
|
|
604
|
+
// ③b workflow contract 检查(`comet-check.mjs`):包内**必含面清单**的自动锚。它此前全仓无任何
|
|
605
|
+
// CI/套件调用——清单漂移没有红灯(本批移出两个参考文件时只能靠手工同步清单)。判据两层:
|
|
606
|
+
// ① 真实执行权威源的该脚本 → exit 0 且输出 `workflow-contract-ok`(清单与真实树一致);
|
|
607
|
+
// ② 反向构造(同一判据驱动):把技能树复制到临时载体、删掉清单里的一个必含文件 → 该脚本必须
|
|
608
|
+
// exit ≠ 0 且报 `Missing required workflow contract files`(清单是真在查,不是恒真输出)。
|
|
609
|
+
function assertWorkflowContractCheck(scratch) {
|
|
610
|
+
const checker = path.join(__dirname, 'comet-check.mjs');
|
|
611
|
+
if (!fs.existsSync(checker)) throw new Error('缺少 comet-check.mjs: ' + checker);
|
|
612
|
+
const runChecker = (script) => {
|
|
613
|
+
const res = spawnSync(process.execPath, [script], { cwd: path.dirname(script), encoding: 'utf8', timeout: 60000 });
|
|
614
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
615
|
+
};
|
|
616
|
+
const real = runChecker(checker);
|
|
617
|
+
if (real.status !== 0 || !real.output.includes('workflow-contract-ok')) {
|
|
618
|
+
throw new Error('comet-check.mjs 未通过(包内必含面清单与真实树漂移)\n退出码 ' + real.status
|
|
619
|
+
+ '\n输出:\n' + real.output);
|
|
620
|
+
}
|
|
621
|
+
// 反向构造:临时载体上一份技能树副本,删掉清单中的一个必含文件 ⇒ 必失败。
|
|
622
|
+
const carrier = path.join(scratch, 'contract-carrier');
|
|
623
|
+
fs.mkdirSync(carrier, { recursive: true });
|
|
624
|
+
fs.cpSync(path.join(__dirname, '..', '..'), path.join(carrier, 'skills'), { recursive: true });
|
|
625
|
+
const copiedChecker = path.join(carrier, 'skills', 'flow-comet', 'scripts', 'comet-check.mjs');
|
|
626
|
+
const removedRel = path.join('skills', 'flow-comet', 'reference', 'decision-points.md');
|
|
627
|
+
const removedAbs = path.join(carrier, removedRel);
|
|
628
|
+
if (!fs.existsSync(removedAbs)) {
|
|
629
|
+
throw new Error('反向构造前提不成立:清单必含文件不在副本内 ' + removedRel);
|
|
630
|
+
}
|
|
631
|
+
fs.rmSync(removedAbs);
|
|
632
|
+
const broken = runChecker(copiedChecker);
|
|
633
|
+
if (broken.status === 0 || !broken.output.includes('Missing required workflow contract files')) {
|
|
634
|
+
throw new Error('comet-check.mjs 反向构造判别力缺失(删掉清单必含文件后仍通过)\n退出码 '
|
|
635
|
+
+ broken.status + '\n输出:\n' + broken.output);
|
|
636
|
+
}
|
|
637
|
+
console.log(' workflow contract 检查: 权威源 exit 0(workflow-contract-ok)+ 缺件副本必失败 ✓');
|
|
638
|
+
}
|
|
639
|
+
|
|
603
640
|
// ③ bin 双入口契约:两个命令名同指同一安装器(同一实现 = 行为一致的结构事实)。返回安装器绝对路径。
|
|
604
641
|
function assertBinContract(pkg, root) {
|
|
605
642
|
const binTarget = 'scripts/prepare-env.mjs';
|
|
@@ -701,6 +738,214 @@ function assertInitTokenContract(installer, cwd) {
|
|
|
701
738
|
console.log(' init 词元: `init --help` 退 0 且含 fcomet init / 裸形态行为不变 / 变形·重复词元 4 例退 1 且报未知参数 ✓');
|
|
702
739
|
}
|
|
703
740
|
|
|
741
|
+
// ---------- 安装器升级路径清理断言助手(生成物镜像面:权威源已删除 / 改名的条目不得残留) ----------
|
|
742
|
+
|
|
743
|
+
// 升级路径清理断言(分发面:安装器的生成物镜像面)——判据 = 真实安装器命令序列 + 文件系统事实,
|
|
744
|
+
// 而不是「安装器退出码为 0」(后者会被「安装照常成功」恒真满足,清理实现整体缺席也不会变红):
|
|
745
|
+
// ① 删该删的:镜像目录内「权威源已不存在」的条目,重装后必须消失(含清空后的目录本身);
|
|
746
|
+
// ② 不该删的必不删(反向探针,逐条):权威源仍存在的文件 / 用户自有技能(无 flow-comet
|
|
747
|
+
// 命名空间)/ 命名空间内但权威源整个技能目录不在场(安装器没有生成清单,无法判定该目录
|
|
748
|
+
// 「确由上次生成写入」)/ copyTree 目标但路径不含命名空间(.claude/rules)/ 项目根用户文件;
|
|
749
|
+
// ③ 输出可核对:被清理条目逐条打印;④ 幂等:第二次重装零清理项、零报错。
|
|
750
|
+
// 夹具名刻意取合成形态,不占用真实工件名(将来权威源重新引入同名文件时夹具前提不失配)——
|
|
751
|
+
// 同时以「权威源确实不含该名」为前提断言,防止夹具退化成恒真空过。
|
|
752
|
+
function assertInstallerUpgradePathCleanup(scratch) {
|
|
753
|
+
const pkgCtx = resolvePackageContext();
|
|
754
|
+
if (pkgCtx.kind === 'copy') {
|
|
755
|
+
console.log(' 不适用(安装副本侧:' + pkgCtx.reason + ')——安装器升级路径清理断言仅权威源侧可判,本项计通过');
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
const installer = path.join(pkgCtx.root, 'scripts', 'prepare-env.mjs');
|
|
759
|
+
const target = path.join(scratch, 'upgrade-path');
|
|
760
|
+
fs.mkdirSync(target, { recursive: true });
|
|
761
|
+
seedForeignFlowKit(target); // 预置同名非上游目录:flow-kit 走「已跳过」路径,零网络接触
|
|
762
|
+
const skillsRoot = path.join(target, '.claude', 'skills');
|
|
763
|
+
const runInstall = () => runInstallerOnce(installer, target);
|
|
764
|
+
const mustNotExist = (rel, label) => {
|
|
765
|
+
const p = path.join(skillsRoot, rel);
|
|
766
|
+
if (fs.existsSync(p)) throw new Error('升级重装后权威源已不存在的生成物仍残留(' + label + '): ' + p);
|
|
767
|
+
};
|
|
768
|
+
const mustExist = (rel, label) => {
|
|
769
|
+
const p = path.join(skillsRoot, rel);
|
|
770
|
+
if (!fs.existsSync(p)) throw new Error('升级重装误删了不该删的条目(' + label + '): ' + p);
|
|
771
|
+
};
|
|
772
|
+
// ① 首次安装(等价「上一代生成物」:内容与权威源一致)
|
|
773
|
+
assertExit(runInstall(), 0);
|
|
774
|
+
// ② 夹具:模拟上一代生成、而权威源已删除 / 改名的三类形态(文件 / 嵌套文件 / 目录树 + 空目录)
|
|
775
|
+
const staleFile = 'flow-comet/legacy-guidance.md';
|
|
776
|
+
const staleNested = 'flow-comet/reference/legacy-notes.md';
|
|
777
|
+
const staleDir = 'flow-comet/reference/legacy-subagents';
|
|
778
|
+
const staleEmptyDir = 'flow-comet/reference/legacy-empty';
|
|
779
|
+
writeFile(target, path.posix.join('.claude/skills', staleFile), 'stale\n');
|
|
780
|
+
writeFile(target, path.posix.join('.claude/skills', staleNested), 'stale\n');
|
|
781
|
+
writeFile(target, path.posix.join('.claude/skills', staleDir, 'author.md'), 'stale\n');
|
|
782
|
+
fs.mkdirSync(path.join(skillsRoot, staleEmptyDir), { recursive: true });
|
|
783
|
+
for (const rel of [staleFile, staleNested, staleDir, staleEmptyDir]) {
|
|
784
|
+
if (fs.existsSync(path.join(pkgCtx.root, '.flow-comet', 'skills', rel))) {
|
|
785
|
+
throw new Error('夹具前提失效:权威源已含 ' + rel + '——请改用其它合成名');
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
// ③ 反向探针夹具(不该删的必不删)
|
|
789
|
+
writeFile(target, '.claude/skills/my-own-skill/SKILL.md', 'user skill\n');
|
|
790
|
+
writeFile(target, '.claude/skills/flow-comet-fork/SKILL.md', 'unattributable dir\n');
|
|
791
|
+
writeFile(target, '.claude/rules/user-rule.md', 'user rule\n');
|
|
792
|
+
writeFile(target, 'USER_KEEP.md', 'user file\n');
|
|
793
|
+
// ④ 升级重装(真实安装器第二次运行同一平台)
|
|
794
|
+
const upgrade = runInstall();
|
|
795
|
+
assertExit(upgrade, 0);
|
|
796
|
+
// ⑤ 删该删的(三类形态逐条)
|
|
797
|
+
mustNotExist(staleFile, '改名残留文件');
|
|
798
|
+
mustNotExist(staleNested, '移出残留文件');
|
|
799
|
+
mustNotExist(staleDir, '残留目录(内容清空后应一并移除)');
|
|
800
|
+
mustNotExist(staleEmptyDir, '残留空目录');
|
|
801
|
+
// ⑥ 不该删的必不删(逐条反向探针)
|
|
802
|
+
mustExist('flow-comet/reference/entry-detail.md', '权威源仍存在的文件');
|
|
803
|
+
mustExist('flow-comet/SKILL.md', '权威源技能主体');
|
|
804
|
+
mustExist('my-own-skill/SKILL.md', '用户自有技能(无 flow-comet 命名空间)');
|
|
805
|
+
mustExist('flow-comet-fork/SKILL.md', '命名空间内但权威源整个技能目录不在场——归属不可判定,fail-closed 保留');
|
|
806
|
+
if (!fs.existsSync(path.join(target, '.claude', 'rules', 'user-rule.md'))) {
|
|
807
|
+
throw new Error('白名单外生成面(.claude/rules)的用户文件被误删');
|
|
808
|
+
}
|
|
809
|
+
if (!fs.existsSync(path.join(target, 'USER_KEEP.md'))) throw new Error('项目根用户文件被误删');
|
|
810
|
+
// ⑦ 输出可核对:被清理条目逐条打印(人可复核「删了什么」)
|
|
811
|
+
for (const rel of [staleFile, staleNested, staleDir, staleEmptyDir]) {
|
|
812
|
+
const name = path.posix.basename(rel);
|
|
813
|
+
if (!upgrade.output.includes(name)) {
|
|
814
|
+
throw new Error('清理输出未逐条打印被清理条目(缺 ' + name + '):\n' + upgrade.output);
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
// ⑦b 播报标记钉死:⑧ 的「重跑无清理项」是**负向**断言——标记一旦改名它便恒真;正向锚在此
|
|
818
|
+
// (标记须在首次升级输出里在场),标记契约的漂移因此必然红,而不是静默失效。
|
|
819
|
+
if (!upgrade.output.includes('镜像清理: 已删除')) {
|
|
820
|
+
throw new Error('升级重装输出缺清理播报标记「镜像清理: 已删除」:\n' + upgrade.output);
|
|
821
|
+
}
|
|
822
|
+
// ⑧ 幂等:第二次重装零清理项、零报错(重复跑不删多、不重复打印)
|
|
823
|
+
const again = runInstall();
|
|
824
|
+
assertExit(again, 0);
|
|
825
|
+
if (again.output.includes('镜像清理')) {
|
|
826
|
+
throw new Error('幂等失配:第二次重装仍报告清理动作:\n' + again.output);
|
|
827
|
+
}
|
|
828
|
+
console.log(' 升级路径清理: 残留 4 项消失(文件 / 嵌套文件 / 目录树 / 空目录)+ 6 条反向探针保留 + 输出可核对 + 幂等 ✓');
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
// 安装器单次真实运行(两处安装器分发面断言共用同一命令形态——同一知识只有一份实现)
|
|
832
|
+
function runInstallerOnce(script, target) {
|
|
833
|
+
const res = spawnSync(process.execPath, [script, '--target', target, '--platform', 'claude-code'], {
|
|
834
|
+
cwd: target, encoding: 'utf8', timeout: 120000,
|
|
835
|
+
});
|
|
836
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
// 把 linkPath 置为指向 targetDir 的链接(夹具构造与清理共用):递归删除会跟随链接目标,
|
|
840
|
+
// 故先按链接自身解链,再删可能残留的普通目录。
|
|
841
|
+
function replaceWithLink(linkPath, targetDir) {
|
|
842
|
+
try {
|
|
843
|
+
if (fs.lstatSync(linkPath).isSymbolicLink()) fs.unlinkSync(linkPath);
|
|
844
|
+
} catch { /* 不在场——无需解链 */ }
|
|
845
|
+
fs.rmSync(linkPath, { recursive: true, force: true });
|
|
846
|
+
fs.mkdirSync(path.dirname(linkPath), { recursive: true });
|
|
847
|
+
fs.symlinkSync(targetDir, linkPath, 'junction');
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
// 镜像清理的**根级** fail-closed 断言(同上一条属同一分发面项)——判据 = 真实安装器命令序列 + 文件系统事实:
|
|
851
|
+
// 根以下的条目层检查拦不住「镜像根自身是链接」:readdir 会跟随进链接目标,清理动作落在**项目之外**,
|
|
852
|
+
// 而播报打印的仍是项目内的表象路径(真实落点不可见)。两条判据各需一个变体驱动,缺任一变体则
|
|
853
|
+
// 对应那条判据整体缺席也不会有红灯:
|
|
854
|
+
// 变体 A「镜像根自身是指向项目外目录的链接」 ⇒ 根级链接判据(不跟随);
|
|
855
|
+
// 变体 B「父级目录是链接、镜像根自身是普通目录」 ⇒ 真实路径包含性判据(词法路径仍在项目内,
|
|
856
|
+
// 只有解析真实路径才能证否;此变体下 A 判据必然不命中,故它是包含性判据的独占探针)。
|
|
857
|
+
// 断言(两变体同):链接目标内的项目外文件**必不消失** + 输出含逐条保留原因 + 重复运行零删除项。
|
|
858
|
+
// 反向构造见 assertMirrorRootReverseConstruction(同一判据驱动,证明断言不恒真空过)。
|
|
859
|
+
function assertMirrorRootLinkFailClosed(scratch, pkgCtx) {
|
|
860
|
+
if (pkgCtx.kind === 'copy') {
|
|
861
|
+
console.log(' 不适用(安装副本侧:' + pkgCtx.reason + ')——镜像清理根级判据的探针仅权威源侧可判,本组计通过');
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
const installer = path.join(pkgCtx.root, 'scripts', 'prepare-env.mjs');
|
|
865
|
+
// 变体 A:镜像根自身 = 指向项目外目录的链接
|
|
866
|
+
const targetA = path.join(scratch, 'mirror-root-link-self');
|
|
867
|
+
const outsideA = path.join(scratch, 'mirror-root-link-self-outside');
|
|
868
|
+
seedForeignFlowKit(targetA);
|
|
869
|
+
writeFile(outsideA, 'EXTERNAL-NOTE.md', 'out-of-tree user content\n');
|
|
870
|
+
writeFile(outsideA, path.posix.join('nested', 'DEEP-NOTE.md'), 'out-of-tree user content\n');
|
|
871
|
+
replaceWithLink(path.join(targetA, '.claude', 'skills', 'flow-comet'), outsideA);
|
|
872
|
+
// 变体 B:父级目录 = 链接(镜像根自身是目标内的普通目录)
|
|
873
|
+
const targetB = path.join(scratch, 'mirror-root-link-ancestor');
|
|
874
|
+
const outsideB = path.join(scratch, 'mirror-root-link-ancestor-outside');
|
|
875
|
+
seedForeignFlowKit(targetB);
|
|
876
|
+
writeFile(outsideB, path.posix.join('flow-comet', 'EXTERNAL-NOTE.md'), 'out-of-tree user content\n');
|
|
877
|
+
replaceWithLink(path.join(targetB, '.claude', 'skills'), outsideB);
|
|
878
|
+
const mirrorB = path.join(targetB, '.claude', 'skills', 'flow-comet');
|
|
879
|
+
if (!fs.existsSync(mirrorB) || fs.lstatSync(mirrorB).isSymbolicLink()) {
|
|
880
|
+
throw new Error('变体 B 前提失效:镜像根自身不是普通目录(应只有父级是链接): ' + mirrorB);
|
|
881
|
+
}
|
|
882
|
+
const variants = [
|
|
883
|
+
{ label: '镜像根自身为链接', target: targetA, outsideFile: path.join(outsideA, 'EXTERNAL-NOTE.md'), reasonPattern: /镜像根是符号链接\/junction/ },
|
|
884
|
+
{ label: '镜像根真实路径越界', target: targetB, outsideFile: path.join(outsideB, 'flow-comet', 'EXTERNAL-NOTE.md'), reasonPattern: /越出目标项目根/ },
|
|
885
|
+
];
|
|
886
|
+
for (const v of variants) assertLinkTargetPreserved(installer, v);
|
|
887
|
+
assertMirrorRootReverseConstruction(scratch, pkgCtx, installer, variants);
|
|
888
|
+
console.log(' 镜像清理根级判据: 根自身为链接 / 真实路径越界 两变体下项目外文件保全 + 保留原因可见 + 幂等;'
|
|
889
|
+
+ '反向构造(判据改恒真)两变体必被越界删除 ✓');
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
// 「链接目标内的项目外文件必不消失」断言(两变体同形):项目外文件仍在 + 输出含逐条保留原因 +
|
|
893
|
+
// 原因指明命中的判据 + 重复运行零删除项且文件仍在(保留是**可见的决定**,不是静默跳过)。
|
|
894
|
+
function assertLinkTargetPreserved(installer, { label, target, outsideFile, reasonPattern }) {
|
|
895
|
+
const first = runInstallerOnce(installer, target);
|
|
896
|
+
assertExit(first, 0);
|
|
897
|
+
if (!fs.existsSync(outsideFile)) {
|
|
898
|
+
throw new Error(label + ':镜像清理越界删除了项目之外的文件(真实落点 ' + outsideFile + ')\n输出:\n' + first.output);
|
|
899
|
+
}
|
|
900
|
+
if (!first.output.includes('镜像清理保留')) {
|
|
901
|
+
throw new Error(label + ':输出未逐条打印保留原因——fail-closed 保留必须是可见的决定\n输出:\n' + first.output);
|
|
902
|
+
}
|
|
903
|
+
if (!reasonPattern.test(first.output)) {
|
|
904
|
+
throw new Error(label + ':保留原因未指明命中判据(缺 ' + reasonPattern + ')\n输出:\n' + first.output);
|
|
905
|
+
}
|
|
906
|
+
const second = runInstallerOnce(installer, target);
|
|
907
|
+
assertExit(second, 0);
|
|
908
|
+
if (second.output.includes('镜像清理: 已删除')) {
|
|
909
|
+
throw new Error(label + ':重复运行仍报告删除动作(幂等失配)\n输出:\n' + second.output);
|
|
910
|
+
}
|
|
911
|
+
if (!fs.existsSync(outsideFile)) {
|
|
912
|
+
throw new Error(label + ':重复运行后项目之外的文件消失(' + outsideFile + ')');
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
|
|
916
|
+
// 反向构造(同一判据驱动):把两处根级判据分别中和为恒真后重跑同一变体 ⇒ 项目外文件**必被删除**;
|
|
917
|
+
// 判据落点漂移(判据句被改写)时「前提不成立」先行报错,避免变异无处落点而假绿。
|
|
918
|
+
// 变异副本建在临时载体上并自带捆绑源(安装器从**自身位置**推导权威树,故载体需含 .flow-comet/skills)。
|
|
919
|
+
function assertMirrorRootReverseConstruction(scratch, pkgCtx, installer, variants) {
|
|
920
|
+
const carrier = path.join(scratch, 'mirror-root-carrier');
|
|
921
|
+
const original = fs.readFileSync(installer, 'utf8');
|
|
922
|
+
const neutralizedContainment = original.replace(
|
|
923
|
+
'if (!isRealPathInside(dstRoot, projectRoot)) {',
|
|
924
|
+
'if (false && !isRealPathInside(dstRoot, projectRoot)) {'
|
|
925
|
+
);
|
|
926
|
+
if (neutralizedContainment === original) {
|
|
927
|
+
throw new Error('反向构造前提不成立:真实路径包含性判据的落点未找到(判据句已漂移,变异无处落点)');
|
|
928
|
+
}
|
|
929
|
+
const neutralized = neutralizedContainment.replace(
|
|
930
|
+
'if (rootStat.isSymbolicLink()) {',
|
|
931
|
+
'if (false && rootStat.isSymbolicLink()) {'
|
|
932
|
+
);
|
|
933
|
+
if (neutralized === neutralizedContainment) {
|
|
934
|
+
throw new Error('反向构造前提不成立:根级链接判据的落点未找到(判据句已漂移,变异无处落点)');
|
|
935
|
+
}
|
|
936
|
+
fs.mkdirSync(path.join(carrier, 'scripts'), { recursive: true });
|
|
937
|
+
fs.writeFileSync(path.join(carrier, 'scripts', 'prepare-env.mjs'), neutralized, 'utf8');
|
|
938
|
+
fs.cpSync(path.join(pkgCtx.root, '.flow-comet', 'skills'), path.join(carrier, '.flow-comet', 'skills'), { recursive: true });
|
|
939
|
+
const mutated = path.join(carrier, 'scripts', 'prepare-env.mjs');
|
|
940
|
+
for (const v of variants) {
|
|
941
|
+
const res = runInstallerOnce(mutated, v.target);
|
|
942
|
+
assertExit(res, 0);
|
|
943
|
+
if (fs.existsSync(v.outsideFile)) {
|
|
944
|
+
throw new Error(v.label + ' 反向构造判别力缺失:判据被中和后项目之外的文件仍在(断言可能是恒真空过)\n输出:\n' + res.output);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
704
949
|
// ---------- 桥接 loader 版本戳重装断言助手(临时 DSH_HOME 重装链路) ----------
|
|
705
950
|
|
|
706
951
|
// 从权威源 loader 提取版本戳(与安装器/检查器同一锚点标记行;动态取值,版本演进零维护)
|
|
@@ -845,6 +1090,20 @@ function execSummaryFixture(taskId) {
|
|
|
845
1090
|
].join('\n');
|
|
846
1091
|
}
|
|
847
1092
|
|
|
1093
|
+
// 同夹具的「段内大写 Z 早于方法名」变体(真实机检标记形态):6 维自查段体首行是含大写 Z 的机检
|
|
1094
|
+
// 标记说明,方法声明行在其后。段尾判定若把大写 Z 当串尾(惰性段体在段内首个 Z 处提前收尾),
|
|
1095
|
+
// 方法声明被截掉 ⇒ execute 家族出口误判「6 维自查未声明自检方法」而 BLOCK。
|
|
1096
|
+
// 夹具前提不成立(段标题形态变化)即抛错——不让变体静默退化成与基线逐字节相同的形态。
|
|
1097
|
+
function execSummaryWithMachineMarker(taskId) {
|
|
1098
|
+
const base = execSummaryFixture(taskId);
|
|
1099
|
+
const sixDimHead = '## 6 维自查\n\n';
|
|
1100
|
+
if (!base.includes(sixDimHead)) {
|
|
1101
|
+
throw new Error('夹具前提失效:SUMMARY 夹具缺 6 维自查段标题形态 ' + JSON.stringify(sixDimHead));
|
|
1102
|
+
}
|
|
1103
|
+
return base.replace(sixDimHead,
|
|
1104
|
+
sixDimHead + '> 本任务 diff 属零逻辑改动(机检标记 ZERO-LOGIC-CHANGE-OK),按协议执行 PR Review。\n\n');
|
|
1105
|
+
}
|
|
1106
|
+
|
|
848
1107
|
// ---------- Fix 批次真实命令链路夹具(A21~A23 共用) ----------
|
|
849
1108
|
|
|
850
1109
|
// 串行任务块(字段齐备:可过 task-parsing 解析与 guard 结构校验)
|
|
@@ -962,6 +1221,310 @@ function assertNotNodeLine(res, nodeId) {
|
|
|
962
1221
|
}
|
|
963
1222
|
}
|
|
964
1223
|
|
|
1224
|
+
// ---------- explain <node> 契约对账(节点现问) ----------
|
|
1225
|
+
// 期望值一律**现场从协议 JSON 派生**(本段不手抄第二份字段表):解析实现输出后逐字段与
|
|
1226
|
+
// `nodes[] / outputSchemas[]` 的声明比对。行前缀与分隔符是契约形态的一部分——不可解析即报问题
|
|
1227
|
+
// (不静默跳过)。反向构造探针复用同一判据(声明侧抽掉一条 guardrail / 一个 artifact / 改描述)。
|
|
1228
|
+
|
|
1229
|
+
// ARTIFACT 行:`<id> [<kind>] required|optional → <路径 | 路径>`(kind 可缺省;无路径 → 未声明路径)。
|
|
1230
|
+
function parseExplainArtifactLine(value) {
|
|
1231
|
+
const arrow = value.split(' → ');
|
|
1232
|
+
if (arrow.length !== 2) throw new Error('ARTIFACT 行缺「… → 路径」形态: ' + value);
|
|
1233
|
+
const requiredMatch = arrow[0].match(/ (required|optional)$/);
|
|
1234
|
+
if (!requiredMatch) throw new Error('ARTIFACT 行缺 required/optional 标注: ' + value);
|
|
1235
|
+
const head = arrow[0].slice(0, arrow[0].length - requiredMatch[0].length);
|
|
1236
|
+
const kindMatch = head.match(/^(.*) \[([^\]]+)\]$/);
|
|
1237
|
+
return {
|
|
1238
|
+
id: kindMatch ? kindMatch[1] : head,
|
|
1239
|
+
kind: kindMatch ? kindMatch[2] : null,
|
|
1240
|
+
required: requiredMatch[1] === 'required',
|
|
1241
|
+
paths: arrow[1] === '(未声明路径)' ? [] : arrow[1].split(' | '),
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1244
|
+
|
|
1245
|
+
// GUARDRAIL 行:`<id> | <label> | <validation>`。
|
|
1246
|
+
function parseExplainGuardrailLine(value) {
|
|
1247
|
+
const parts = value.split(' | ');
|
|
1248
|
+
if (parts.length !== 3) throw new Error('GUARDRAIL 行缺三段(id | label | validation): ' + value);
|
|
1249
|
+
return { id: parts[0], label: parts[1], validation: parts[2] };
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
// REQUIRED-SKILL 行:`<skill> | scope=<…> | enforcement=<…> | reason=<…>`。
|
|
1253
|
+
function parseExplainSkillLine(value) {
|
|
1254
|
+
const parts = value.split(' | ');
|
|
1255
|
+
if (parts.length !== 4) throw new Error('REQUIRED-SKILL 行缺四段(skill | scope= | enforcement= | reason=): ' + value);
|
|
1256
|
+
const [skill, scope, enforcement, reason] = parts;
|
|
1257
|
+
if (!scope.startsWith('scope=') || !enforcement.startsWith('enforcement=') || !reason.startsWith('reason=')) {
|
|
1258
|
+
throw new Error('REQUIRED-SKILL 行的键名形态不符: ' + value);
|
|
1259
|
+
}
|
|
1260
|
+
return { skill, scope: scope.slice(6), enforcement: enforcement.slice(12), reason: reason.slice(7) };
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
function parseExplainOutput(output) {
|
|
1264
|
+
const parsed = {
|
|
1265
|
+
attributes: {}, schemas: [], artifacts: [], evidence: [], guardrails: [], guardrailsNone: false,
|
|
1266
|
+
skills: [], skillsNone: false, commands: [],
|
|
1267
|
+
};
|
|
1268
|
+
let schemaIndex = -1;
|
|
1269
|
+
for (const rawLine of String(output).split(/\r?\n/)) {
|
|
1270
|
+
const line = rawLine.trim();
|
|
1271
|
+
if (line === '') continue;
|
|
1272
|
+
const value = line.slice(line.indexOf(': ') + 2);
|
|
1273
|
+
if (line.startsWith('NODE: ')) parsed.attributes.node = value;
|
|
1274
|
+
else if (line.startsWith('LABEL: ')) parsed.attributes.label = value;
|
|
1275
|
+
else if (line.startsWith('KIND: ')) parsed.attributes.kind = value;
|
|
1276
|
+
else if (line.startsWith('DISABLED: ')) parsed.attributes.disabled = value;
|
|
1277
|
+
else if (line.startsWith('OUTPUT-SCHEMA: ')) {
|
|
1278
|
+
parsed.schemas.push(value);
|
|
1279
|
+
schemaIndex += 1;
|
|
1280
|
+
parsed.artifacts.push([]);
|
|
1281
|
+
parsed.evidence.push([]);
|
|
1282
|
+
} else if (line.startsWith('ARTIFACT: ')) {
|
|
1283
|
+
if (schemaIndex < 0) throw new Error('ARTIFACT 行先于 OUTPUT-SCHEMA 行: ' + line);
|
|
1284
|
+
parsed.artifacts[schemaIndex].push(parseExplainArtifactLine(value));
|
|
1285
|
+
} else if (line.startsWith('EVIDENCE: ')) {
|
|
1286
|
+
if (schemaIndex < 0) throw new Error('EVIDENCE 行先于 OUTPUT-SCHEMA 行: ' + line);
|
|
1287
|
+
parsed.evidence[schemaIndex].push(value);
|
|
1288
|
+
} else if (line.startsWith('GUARDRAIL: ')) {
|
|
1289
|
+
if (value === '(none)') parsed.guardrailsNone = true;
|
|
1290
|
+
else parsed.guardrails.push(parseExplainGuardrailLine(value));
|
|
1291
|
+
} else if (line.startsWith('REQUIRED-SKILL: ')) {
|
|
1292
|
+
if (value === '(none)') parsed.skillsNone = true;
|
|
1293
|
+
else parsed.skills.push(parseExplainSkillLine(value));
|
|
1294
|
+
} else if (line.startsWith('COMMAND ')) parsed.commands.push(line);
|
|
1295
|
+
else throw new Error('explain 输出含未识别的行形态: ' + line);
|
|
1296
|
+
}
|
|
1297
|
+
return parsed;
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
// 期望值比对(解析结果 vs 协议声明;两侧同源,锚里不手抄字段表)。
|
|
1301
|
+
function expectExplainField(problems, nodeId, actual, declared, field) {
|
|
1302
|
+
if (actual !== declared) {
|
|
1303
|
+
problems.push('节点 ' + nodeId + ' 的 ' + field + ' 与协议声明不一致: 输出 '
|
|
1304
|
+
+ JSON.stringify(actual) + ' / 声明 ' + JSON.stringify(declared));
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
// ① outputSchema 名与描述 + ② 每个 artifact 的 id·kind·required·路径(pathBase: specs-root ⇒ .specs/
|
|
1309
|
+
// 前缀)与每个 evidence 的 id (required)。
|
|
1310
|
+
function explainSchemaProblems(node, parsed, schemaById) {
|
|
1311
|
+
const problems = [];
|
|
1312
|
+
const declaredSchemas = node.outputSchemas ?? [];
|
|
1313
|
+
const expectedSchemaLines = declaredSchemas.length === 0
|
|
1314
|
+
? ['(none)']
|
|
1315
|
+
: declaredSchemas.map((schemaId) => {
|
|
1316
|
+
const schema = schemaById.get(schemaId);
|
|
1317
|
+
return schemaId + (schema && schema.description ? ' — ' + schema.description : '');
|
|
1318
|
+
});
|
|
1319
|
+
expectExplainField(problems, node.id, parsed.schemas.join(' ␟ '), expectedSchemaLines.join(' ␟ '), 'OUTPUT-SCHEMA 行');
|
|
1320
|
+
declaredSchemas.forEach((schemaId, index) => {
|
|
1321
|
+
const schema = schemaById.get(schemaId);
|
|
1322
|
+
const declaredArtifacts = (schema?.artifacts ?? []).map((artifact) => ({
|
|
1323
|
+
id: artifact.id ?? '(unnamed)',
|
|
1324
|
+
kind: artifact.kind ?? null,
|
|
1325
|
+
required: artifact.required !== false,
|
|
1326
|
+
paths: (artifact.paths ?? []).map((declaredPath) =>
|
|
1327
|
+
(artifact.pathBase === 'specs-root' ? '.specs/' : '') + String(declaredPath)),
|
|
1328
|
+
}));
|
|
1329
|
+
const actualArtifacts = parsed.artifacts[index] ?? [];
|
|
1330
|
+
const artifactsMatch = actualArtifacts.length === declaredArtifacts.length
|
|
1331
|
+
&& actualArtifacts.every((actual, position) => actual.id === declaredArtifacts[position].id
|
|
1332
|
+
&& actual.kind === declaredArtifacts[position].kind
|
|
1333
|
+
&& actual.required === declaredArtifacts[position].required
|
|
1334
|
+
&& actual.paths.join(' | ') === declaredArtifacts[position].paths.join(' | '));
|
|
1335
|
+
if (!artifactsMatch) {
|
|
1336
|
+
problems.push('节点 ' + node.id + '/' + schemaId + ' 的 artifact 对账不一致: 输出 '
|
|
1337
|
+
+ JSON.stringify(actualArtifacts) + ' / 声明 ' + JSON.stringify(declaredArtifacts));
|
|
1338
|
+
}
|
|
1339
|
+
const declaredEvidence = (schema?.evidence ?? []).length === 0
|
|
1340
|
+
? '(none)'
|
|
1341
|
+
: (schema.evidence ?? []).map((evidence) =>
|
|
1342
|
+
evidence.id + (evidence.required === false ? ' (optional)' : ' (required)')).join(' | ');
|
|
1343
|
+
expectExplainField(problems, node.id, (parsed.evidence[index] ?? []).join(' | '),
|
|
1344
|
+
declaredEvidence, schemaId + ' 的 EVIDENCE 行');
|
|
1345
|
+
});
|
|
1346
|
+
return problems;
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
// ③ 每条 guardrail 的 id·label·validation 与 ④ 每条 requiredSkillCall 的 skill·scope·enforcement·reason
|
|
1350
|
+
// (空集合 → '(none)' 行的在场性同判)。
|
|
1351
|
+
function explainGuardrailAndSkillProblems(node, parsed) {
|
|
1352
|
+
const problems = [];
|
|
1353
|
+
const declaredGuardrails = (node.guardrails ?? []).map((guardrail) => ({
|
|
1354
|
+
id: guardrail.id ?? '(unnamed)', label: guardrail.label ?? '-', validation: guardrail.validation ?? '-',
|
|
1355
|
+
}));
|
|
1356
|
+
if ((declaredGuardrails.length === 0) !== parsed.guardrailsNone) {
|
|
1357
|
+
problems.push('节点 ' + node.id + ' 的 guardrail 空集合形态与声明不一致((none) 行在场性不符)');
|
|
1358
|
+
}
|
|
1359
|
+
expectExplainField(problems, node.id, JSON.stringify(parsed.guardrails), JSON.stringify(declaredGuardrails), 'guardrail');
|
|
1360
|
+
const declaredSkills = (node.requiredSkillCalls ?? []).map((call) => ({
|
|
1361
|
+
skill: call.skill ?? '(unnamed)', scope: call.scope ?? '-',
|
|
1362
|
+
enforcement: call.enforcement ?? '-', reason: call.reason ?? '-',
|
|
1363
|
+
}));
|
|
1364
|
+
if ((declaredSkills.length === 0) !== parsed.skillsNone) {
|
|
1365
|
+
problems.push('节点 ' + node.id + ' 的 requiredSkillCall 空集合形态与声明不一致((none) 行在场性不符)');
|
|
1366
|
+
}
|
|
1367
|
+
expectExplainField(problems, node.id, JSON.stringify(parsed.skills), JSON.stringify(declaredSkills), 'requiredSkillCall');
|
|
1368
|
+
return problems;
|
|
1369
|
+
}
|
|
1370
|
+
|
|
1371
|
+
// ⑤ 三条命令:节点 id 与 --apply 形态 + 脚本根形态(三条同根、指向技能包 scripts 目录)+ 脚本
|
|
1372
|
+
// 路径整体带双引号(含空格的安装根下不被 shell 分词——引号是契约形态的一部分,缺引号即红)。
|
|
1373
|
+
function explainCommandProblems(node, parsed) {
|
|
1374
|
+
const commandPatterns = [
|
|
1375
|
+
[/^COMMAND entry: node "(.+?)\/workflow-guard\.mjs" entry (.+)$/, 'entry'],
|
|
1376
|
+
[/^COMMAND exit: node "(.+?)\/workflow-guard\.mjs" exit (.+) --apply$/, 'exit'],
|
|
1377
|
+
[/^COMMAND record: node "(.+?)\/workflow-state\.mjs" record (.+) '\{"summary":"<完成摘要>"\}'$/, 'record'],
|
|
1378
|
+
];
|
|
1379
|
+
if (parsed.commands.length !== commandPatterns.length) {
|
|
1380
|
+
return ['节点 ' + node.id + ' 的 COMMAND 行数 ' + parsed.commands.length + ' ≠ 3'];
|
|
1381
|
+
}
|
|
1382
|
+
const problems = [];
|
|
1383
|
+
const scriptsRoots = new Set();
|
|
1384
|
+
parsed.commands.forEach((line, index) => {
|
|
1385
|
+
const [pattern, kind] = commandPatterns[index];
|
|
1386
|
+
const match = line.match(pattern);
|
|
1387
|
+
if (!match) {
|
|
1388
|
+
problems.push('节点 ' + node.id + ' 的 ' + kind + ' 命令形态不符: ' + line);
|
|
1389
|
+
return;
|
|
1390
|
+
}
|
|
1391
|
+
scriptsRoots.add(match[1]);
|
|
1392
|
+
if (match[2] !== node.id) problems.push('节点 ' + node.id + ' 的 ' + kind + ' 命令节点 id 不符: ' + match[2]);
|
|
1393
|
+
});
|
|
1394
|
+
if (scriptsRoots.size !== 1) {
|
|
1395
|
+
problems.push('节点 ' + node.id + ' 的三条命令脚本根不一致: ' + [...scriptsRoots].join(' / '));
|
|
1396
|
+
}
|
|
1397
|
+
const scriptsRoot = [...scriptsRoots][0] ?? '';
|
|
1398
|
+
if (!/skills\/flow-comet\/scripts$/.test(scriptsRoot)) {
|
|
1399
|
+
problems.push('节点 ' + node.id + ' 的命令脚本根不指向技能包 scripts 目录: ' + scriptsRoot);
|
|
1400
|
+
} else if (__dirname.replace(/\\/g, '/').includes('/.flow-comet/skills/')
|
|
1401
|
+
&& scriptsRoot !== '.claude/skills/flow-comet/scripts') {
|
|
1402
|
+
// 权威源检出:命令路径 = 设计形态(安装副本按运行根形态化,已由上面同一判据约束)
|
|
1403
|
+
problems.push('权威源检出的命令脚本根应为设计形态 .claude/skills/flow-comet/scripts: ' + scriptsRoot);
|
|
1404
|
+
}
|
|
1405
|
+
return problems;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
// 逐字段对账(单一实现:真实判据与反向构造探针共用):四类字段 + 三条命令。
|
|
1409
|
+
function explainContractProblems(protocol, explainOutputs) {
|
|
1410
|
+
const problems = [];
|
|
1411
|
+
const schemaById = new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
|
|
1412
|
+
for (const node of protocol.nodes ?? []) {
|
|
1413
|
+
const output = explainOutputs.get(node.id);
|
|
1414
|
+
if (typeof output !== 'string') {
|
|
1415
|
+
problems.push('节点 ' + node.id + ' 缺 explain 输出(未对账)');
|
|
1416
|
+
continue;
|
|
1417
|
+
}
|
|
1418
|
+
let parsed;
|
|
1419
|
+
try {
|
|
1420
|
+
parsed = parseExplainOutput(output);
|
|
1421
|
+
} catch (error) {
|
|
1422
|
+
problems.push('节点 ' + node.id + ' 的 explain 输出形态不可解析: ' + error.message);
|
|
1423
|
+
continue;
|
|
1424
|
+
}
|
|
1425
|
+
expectExplainField(problems, node.id, parsed.attributes.node, node.id, 'NODE');
|
|
1426
|
+
expectExplainField(problems, node.id, parsed.attributes.label ?? null, node.label ?? null, 'LABEL');
|
|
1427
|
+
expectExplainField(problems, node.id, parsed.attributes.kind ?? null, node.kind ?? null, 'KIND');
|
|
1428
|
+
expectExplainField(problems, node.id, parsed.attributes.disabled ?? null,
|
|
1429
|
+
node.disabled === true ? 'true(该节点在当前协议中被停用)' : null, 'DISABLED');
|
|
1430
|
+
problems.push(...explainSchemaProblems(node, parsed, schemaById));
|
|
1431
|
+
problems.push(...explainGuardrailAndSkillProblems(node, parsed));
|
|
1432
|
+
problems.push(...explainCommandProblems(node, parsed));
|
|
1433
|
+
}
|
|
1434
|
+
return problems;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
// explain 的三种 fail-closed 形态(非法节点 / 缺参 / 拿选项当节点名):都非零退出并列出全部合法节点。
|
|
1438
|
+
function assertExplainFailClosed(dir, protocolDecl) {
|
|
1439
|
+
const legalNodes = protocolDecl.nodes.map((protocolNode) => protocolNode.id).join('/');
|
|
1440
|
+
const forms = [
|
|
1441
|
+
['非法节点', ['explain', 'not-a-node'], 'explain node 非法: not-a-node'],
|
|
1442
|
+
['缺参', ['explain'], 'explain requires a <node> id'],
|
|
1443
|
+
['选项当节点名', ['explain', '--help'], 'explain requires a <node> id'],
|
|
1444
|
+
];
|
|
1445
|
+
for (const [form, args, expected] of forms) {
|
|
1446
|
+
const res = runState(args, dir);
|
|
1447
|
+
assertExit(res, 1);
|
|
1448
|
+
assertOut(res, expected);
|
|
1449
|
+
assertOut(res, legalNodes);
|
|
1450
|
+
if (form === '非法节点') assertOut(res, '(协议节点: ' + legalNodes + ')');
|
|
1451
|
+
}
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
// 夹具协议(声明副本)下的 explain 输出——真实协议 env 通道;夹具文件跑完即清。
|
|
1455
|
+
function explainOutputsForDeclaration(dir, decl) {
|
|
1456
|
+
const probeProtocolFile = path.join(dir, 'reference', 'workflow-protocol-probe.json');
|
|
1457
|
+
fs.writeFileSync(probeProtocolFile, JSON.stringify(decl, null, 2), 'utf8');
|
|
1458
|
+
const outputs = new Map();
|
|
1459
|
+
for (const protocolNode of decl.nodes) {
|
|
1460
|
+
const res = runState(['explain', protocolNode.id], dir, { FLOW_COMET_PROTOCOL: probeProtocolFile });
|
|
1461
|
+
assertExit(res, 0);
|
|
1462
|
+
outputs.set(protocolNode.id, res.output);
|
|
1463
|
+
}
|
|
1464
|
+
fs.rmSync(probeProtocolFile, { force: true });
|
|
1465
|
+
return outputs;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
// 反向构造(L-106):把协议声明副本的一条 guardrail / 一个 artifact 抽掉、改一条 schema 描述 ⇒ 对账
|
|
1469
|
+
// 必报对应字段;再把真实输出里的脚本路径引号去掉 ⇒ 必报命令形态不符(证明断言不恒真空过——
|
|
1470
|
+
// 没有这一侧,把引号从实现里拿掉也能全绿)。返回问题描述数组(空 = 判别力齐备)。
|
|
1471
|
+
function explainReverseConstructionProblems(dir, protocolDecl, explainOutputs) {
|
|
1472
|
+
const probeNode = protocolDecl.nodes.find((protocolNode) => (protocolNode.guardrails ?? []).length > 0);
|
|
1473
|
+
const probeSchema = (protocolDecl.outputSchemas ?? []).find((schema) => (schema.artifacts ?? []).length > 0);
|
|
1474
|
+
const owner = probeSchema === undefined ? undefined
|
|
1475
|
+
: protocolDecl.nodes.find((protocolNode) => (protocolNode.outputSchemas ?? []).includes(probeSchema.id));
|
|
1476
|
+
if (probeNode === undefined || probeSchema === undefined || owner === undefined) {
|
|
1477
|
+
return ['反向构造前提不成立:协议声明里找不到带 guardrail 的节点 / 带 artifact 的 schema / schema 归属节点'];
|
|
1478
|
+
}
|
|
1479
|
+
const variants = [
|
|
1480
|
+
['抽掉一条 guardrail', (decl) => {
|
|
1481
|
+
decl.nodes.find((protocolNode) => protocolNode.id === probeNode.id).guardrails = [];
|
|
1482
|
+
}, probeNode.id, 'guardrail'],
|
|
1483
|
+
['抽掉一个 artifact', (decl) => {
|
|
1484
|
+
decl.outputSchemas.find((schema) => schema.id === probeSchema.id).artifacts = [];
|
|
1485
|
+
}, owner.id, 'artifact'],
|
|
1486
|
+
['改掉一条 schema 描述', (decl) => {
|
|
1487
|
+
const target = decl.outputSchemas.find((schema) => schema.id === probeSchema.id);
|
|
1488
|
+
target.description = (probeSchema.description ?? '') + '(反向构造探针)';
|
|
1489
|
+
}, owner.id, 'OUTPUT-SCHEMA'],
|
|
1490
|
+
];
|
|
1491
|
+
const problems = [];
|
|
1492
|
+
for (const [form, mutate, affectedNodeId, expectedField] of variants) {
|
|
1493
|
+
const mutatedDecl = JSON.parse(JSON.stringify(protocolDecl));
|
|
1494
|
+
mutate(mutatedDecl);
|
|
1495
|
+
const probeOutputs = explainOutputsForDeclaration(dir, mutatedDecl);
|
|
1496
|
+
if (probeOutputs.get(affectedNodeId) === explainOutputs.get(affectedNodeId)) {
|
|
1497
|
+
problems.push('反向构造前提不成立(' + form + ':夹具协议未改变 explain 输出——协议 env 通道未生效)');
|
|
1498
|
+
continue;
|
|
1499
|
+
}
|
|
1500
|
+
const probeProblems = explainContractProblems(protocolDecl, probeOutputs);
|
|
1501
|
+
if (!probeProblems.some((problem) => problem.includes(expectedField))) {
|
|
1502
|
+
problems.push('反向构造判别力缺失(' + form + ' 未被判分叉): ' + (probeProblems.join('; ') || '(零问题)'));
|
|
1503
|
+
}
|
|
1504
|
+
}
|
|
1505
|
+
// ④ 引号形态(③ 的另一面,不需重跑):真实输出去掉脚本路径引号 ⇒ 逐节点必报命令形态不符。
|
|
1506
|
+
const dequoted = new Map();
|
|
1507
|
+
for (const [nodeId, output] of explainOutputs) {
|
|
1508
|
+
const text = String(output);
|
|
1509
|
+
const stripped = text.replace(/(node )"([^"\n]*\.mjs)"/g, '$1$2');
|
|
1510
|
+
if (stripped === text) {
|
|
1511
|
+
problems.push('反向构造前提不成立(节点 ' + nodeId + ' 的输出里没有带引号的脚本路径——引号判据无从判别)');
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
dequoted.set(nodeId, stripped);
|
|
1515
|
+
}
|
|
1516
|
+
if (dequoted.size > 0) {
|
|
1517
|
+
const dequotedProblems = explainContractProblems(protocolDecl, new Map([...explainOutputs, ...dequoted]));
|
|
1518
|
+
for (const nodeId of dequoted.keys()) {
|
|
1519
|
+
if (!dequotedProblems.some((problem) => problem.includes('节点 ' + nodeId + ' 的')
|
|
1520
|
+
&& problem.includes('命令形态不符'))) {
|
|
1521
|
+
problems.push('反向构造判别力缺失(去掉节点 ' + nodeId + ' 的脚本路径引号未被判命令形态不符)');
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
return problems;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
965
1528
|
// 混排多波 TASK:双并行开路 → 串行衔接(依赖双并行)→ 收尾并行(依赖串行衔接)。
|
|
966
1529
|
// 各任务 status 由入参映射(任务 id → 'pending'|'done')控制;status 变更不影响任务集签名
|
|
967
1530
|
// (签名仅保留 id/parallel 与块内容,剥离 status 类属性)。串行衔接置于两并行波之间——
|
|
@@ -1119,7 +1682,121 @@ function parseStatusOutput(root) {
|
|
|
1119
1682
|
return JSON.parse(res.output.slice(start, end + 1));
|
|
1120
1683
|
}
|
|
1121
1684
|
|
|
1122
|
-
// ----------
|
|
1685
|
+
// ---------- 侧命令(evolve / health / context-scan)与 ui-design 门:真实命令链路材料 ----------
|
|
1686
|
+
// 与 guard-self-test 同构:判据走真实 CLI;零写入判据用树指纹(相对路径清单 + 文件 sha256)。
|
|
1687
|
+
const SIDE_EVOLVE = path.join(__dirname, 'evolve.mjs');
|
|
1688
|
+
const SIDE_HEALTH = path.join(__dirname, 'health.mjs');
|
|
1689
|
+
const SIDE_CONTEXT_SCAN = path.join(__dirname, 'context-scan.mjs');
|
|
1690
|
+
// 时间形态的单一来源:侧命令产物的日期分量按同一实现推导(测试侧不复制第二份格式化)
|
|
1691
|
+
const timeUtilsModule = await import(pathToFileURL(path.join(__dirname, 'time-utils.mjs')).href);
|
|
1692
|
+
const localDate = (value = new Date()) => timeUtilsModule.formatLocalDate(value);
|
|
1693
|
+
|
|
1694
|
+
// 侧命令真实调用:协议环境与 runState / runGuard / runHook 同形(FLOW_COMET_PROTOCOL 指向场景内副本)
|
|
1695
|
+
// ——协议路径的唯一权威是 state-schema 的选择器(state.protocolPath > 环境变量 > 内置默认),侧命令
|
|
1696
|
+
// 的 state 通道子进程必须看到与门禁同一份来源。构造「无环境变量」的场景用 `{ FLOW_COMET_PROTOCOL: '' }`。
|
|
1697
|
+
function runSideScript(script, args, root, envOverrides = {}) {
|
|
1698
|
+
const res = spawnSync(process.execPath, [script, ...args], {
|
|
1699
|
+
cwd: root,
|
|
1700
|
+
env: {
|
|
1701
|
+
...process.env,
|
|
1702
|
+
FLOW_COMET_PROTOCOL: path.join(root, 'reference', 'workflow-protocol.json'),
|
|
1703
|
+
...envOverrides,
|
|
1704
|
+
},
|
|
1705
|
+
encoding: 'utf8',
|
|
1706
|
+
timeout: 120000,
|
|
1707
|
+
});
|
|
1708
|
+
return { status: res.status ?? 1, output: String(res.stdout || '') + String(res.stderr || '') };
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
function treeFingerprint(root) {
|
|
1712
|
+
const rows = [];
|
|
1713
|
+
const walk = (dir) => {
|
|
1714
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true })
|
|
1715
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
1716
|
+
for (const entry of entries) {
|
|
1717
|
+
const full = path.join(dir, entry.name);
|
|
1718
|
+
const rel = path.relative(root, full).split(path.sep).join('/');
|
|
1719
|
+
if (entry.isDirectory()) { rows.push(rel + '/'); walk(full); continue; }
|
|
1720
|
+
rows.push(rel + ' ' + createHash('sha256').update(fs.readFileSync(full)).digest('hex'));
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
walk(root);
|
|
1724
|
+
return rows.join('\n');
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
function readText(root, rel) {
|
|
1728
|
+
return fs.readFileSync(path.join(root, rel), 'utf8');
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
function assertEqual(actual, expected, label) {
|
|
1732
|
+
if (actual !== expected) {
|
|
1733
|
+
throw new Error(label + ':期望 ' + JSON.stringify(expected) + ',实际 ' + JSON.stringify(actual));
|
|
1734
|
+
}
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
function assertTrue(condition, message) {
|
|
1738
|
+
if (!condition) throw new Error(message);
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
// 跨过下一个秒边界(`last_intel_scan` 为秒级精度:同一秒内的两次写入取值可能相同,双落点漂移不可判)。
|
|
1742
|
+
// 轮询到「严格晚于目标秒」才返回——等待上限约 1.05s,比固定 sleep 短且不受调用时刻影响。
|
|
1743
|
+
function waitForNextSecond() {
|
|
1744
|
+
const target = Math.floor(Date.now() / 1000) + 1;
|
|
1745
|
+
while (Math.floor(Date.now() / 1000) <= target) {
|
|
1746
|
+
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
// 七段 CONTEXT 骨架(域语言段带模板表格表头;intel-scan 元数据段三字段齐——结构校验的通过形态)。
|
|
1751
|
+
// 与 guard-self-test.mjs 的同名夹具**同形镜像**(两份载体刻意独立、不互相 import:夹具若从被测模块
|
|
1752
|
+
// 派生,锚点会退化成同义反复)——改段名 / 字段名时必须两份同改(与词表镜像同纪律)。
|
|
1753
|
+
// `last_intel_scan` 行取**真实生成件形态**:取值词元 + 行尾说明(`--init-context` 的生成物即此形;
|
|
1754
|
+
// 写侧 `context-scan` 只替换首个取值词元、说明原样保留)——裸取值词元夹具下「读侧取整行剩余文本」
|
|
1755
|
+
// 的口径缺陷在本项不可见(见 M7 的单变量对照)。
|
|
1756
|
+
const INTEL_FIELD_SUFFIX = ' (首次接入生成时留占位;由 `init --init-context` 或 `context-scan` 记录扫描时间)';
|
|
1757
|
+
function contextFixtureText() {
|
|
1758
|
+
return [
|
|
1759
|
+
'# 项目上下文', '',
|
|
1760
|
+
'## 项目概要', '', '- 夹具概要', '',
|
|
1761
|
+
'## 技术栈', '', '- Node.js(ESM)', '',
|
|
1762
|
+
'## 域语言', '', '| 术语 | 定义 |', '|---|---|', '| 夹具 | 测试用 |', '',
|
|
1763
|
+
'## 已锁决策', '', '- [2026-09-01] 夹具决策 — 来自 @.specs/CONTEXT.md', '',
|
|
1764
|
+
'## 默认偏好', '', '- 夹具偏好', '',
|
|
1765
|
+
'## 既有抽象索引', '', '- 夹具既有抽象', '',
|
|
1766
|
+
'## intel-scan 元数据', '',
|
|
1767
|
+
'- **last_intel_scan**: 2026-09-01T10:00:00+08:00' + INTEL_FIELD_SUFFIX,
|
|
1768
|
+
'- **scanner**: flow-comet',
|
|
1769
|
+
'- **下次重扫建议**: 3 个月后', '',
|
|
1770
|
+
].join('\n');
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
// ---------- 系统测试项(A~M 十三类) ----------
|
|
1774
|
+
|
|
1775
|
+
// AC-2:EVOLVE 报告的三个子句(`## 扫描范围` / `已扫 change 清单` / `未应用` 记账 + 未应用项段)
|
|
1776
|
+
// 判据——纯函数,合成输入可驱动判别力(缺任一子句 → 必报,见 M1 的反向构造)。
|
|
1777
|
+
function evolveReportClauseProblems(reportText) {
|
|
1778
|
+
const problems = [];
|
|
1779
|
+
if (!reportText.includes('## 扫描范围')) problems.push('缺「## 扫描范围」段');
|
|
1780
|
+
if (!reportText.includes('- 已扫 change 清单:')) problems.push('缺「已扫 change 清单」行');
|
|
1781
|
+
if (!/未应用 \d+ 条/.test(reportText)) problems.push('缺「未应用 N 条」记账');
|
|
1782
|
+
if (!reportText.includes('## 未应用项')) problems.push('缺「## 未应用项」段');
|
|
1783
|
+
return problems;
|
|
1784
|
+
}
|
|
1785
|
+
|
|
1786
|
+
// AC-3:`## evolve 元数据` 三字段端到端判据(段在场 + 三字段齐备 + 取值与 state / 本次执行工具一致)。
|
|
1787
|
+
function evolveSectionFieldProblems(contextText, ts, scanner) {
|
|
1788
|
+
const section = /## evolve 元数据[\s\S]*?(?=\n## |\s*$)/.exec(contextText);
|
|
1789
|
+
if (section === null) return ['缺 `## evolve 元数据` 段'];
|
|
1790
|
+
const body = section[0];
|
|
1791
|
+
const problems = [];
|
|
1792
|
+
for (const [key, value] of [['last_evolve_at', ts], ['scanner', scanner]]) {
|
|
1793
|
+
const found = new RegExp('- \\*\\*' + key + '\\*\\*: `([^`]*)`').exec(body);
|
|
1794
|
+
if (found === null) problems.push('段内缺字段 ' + key);
|
|
1795
|
+
else if (found[1] !== value) problems.push('段内 ' + key + ' 取值不符: ' + JSON.stringify(found[1]));
|
|
1796
|
+
}
|
|
1797
|
+
if (!/- \*\*下次建议\*\*: `[^`]+`/.test(body)) problems.push('段内缺非空的 `下次建议` 字段');
|
|
1798
|
+
return problems;
|
|
1799
|
+
}
|
|
1123
1800
|
|
|
1124
1801
|
const TEST_ITEMS = [
|
|
1125
1802
|
// ---------- A. 状态机与路由 ----------
|
|
@@ -1175,7 +1852,7 @@ const TEST_ITEMS = [
|
|
|
1175
1852
|
},
|
|
1176
1853
|
|
|
1177
1854
|
{
|
|
1178
|
-
name: 'A4 status
|
|
1855
|
+
name: 'A4 status/explain:节点推导、节点现问契约(逐字段对账 + fail-closed + 只读)与无活跃兜底',
|
|
1179
1856
|
run: (dir) => {
|
|
1180
1857
|
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
1181
1858
|
// 无产物 → 首节点
|
|
@@ -1187,6 +1864,31 @@ const TEST_ITEMS = [
|
|
|
1187
1864
|
const s2 = runState(['status'], dir);
|
|
1188
1865
|
assertExit(s2, 0);
|
|
1189
1866
|
assertOut(s2, '"currentNode": "design"');
|
|
1867
|
+
// —— explain <node>:节点现问契约(真实子进程,零 mock;契约声明源 = 协议 JSON)——
|
|
1868
|
+
// 8 节点逐个逐字段对账(label / kind / outputSchema 名与描述 / artifact / evidence / guardrail /
|
|
1869
|
+
// requiredSkillCall / 三条命令)+ 三种 fail-closed 形态 + 只读性 + 反向构造(声明副本抽掉一条
|
|
1870
|
+
// guardrail / 一个 artifact、改一条 schema 描述 ⇒ 对账必报;判据与探针见模块级单一实现)。
|
|
1871
|
+
const protocolDecl = JSON.parse(fs.readFileSync(path.join(dir, 'reference', 'workflow-protocol.json'), 'utf8'));
|
|
1872
|
+
const stateFilePath = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
1873
|
+
const stateHashBefore = createHash('sha256').update(fs.readFileSync(stateFilePath)).digest('hex');
|
|
1874
|
+
const statusBefore = runState(['status'], dir);
|
|
1875
|
+
const explainOutputs = new Map();
|
|
1876
|
+
for (const protocolNode of protocolDecl.nodes) {
|
|
1877
|
+
const res = runState(['explain', protocolNode.id], dir);
|
|
1878
|
+
assertExit(res, 0);
|
|
1879
|
+
assertOut(res, 'NODE: ' + protocolNode.id);
|
|
1880
|
+
explainOutputs.set(protocolNode.id, res.output);
|
|
1881
|
+
}
|
|
1882
|
+
const contractProblems = explainContractProblems(protocolDecl, explainOutputs);
|
|
1883
|
+
assertTrue(contractProblems.length === 0,
|
|
1884
|
+
'explain 输出与协议 JSON 声明不一致: ' + contractProblems.join('; '));
|
|
1885
|
+
// 只读性:调用前后状态文件 sha256 全等 + status 读数逐字不变(explain 不写 state、不改路由)
|
|
1886
|
+
assertEqual(createHash('sha256').update(fs.readFileSync(stateFilePath)).digest('hex'), stateHashBefore,
|
|
1887
|
+
'explain 改写了状态文件(只读通道被破坏)');
|
|
1888
|
+
assertEqual(runState(['status'], dir).output, statusBefore.output, 'explain 改动了路由读数(只读通道被破坏)');
|
|
1889
|
+
assertExplainFailClosed(dir, protocolDecl);
|
|
1890
|
+
const probeProblems = explainReverseConstructionProblems(dir, protocolDecl, explainOutputs);
|
|
1891
|
+
assertTrue(probeProblems.length === 0, '反向构造判别力缺失: ' + probeProblems.join('; '));
|
|
1190
1892
|
// 无 state 无工件 → no-change 兜底
|
|
1191
1893
|
fs.rmSync(path.join(dir, '.flow-comet'), { recursive: true });
|
|
1192
1894
|
const s3 = runState(['status'], dir);
|
|
@@ -1709,7 +2411,7 @@ const TEST_ITEMS = [
|
|
|
1709
2411
|
// 补显式 depends_on 后放行;旧 change 形态仅 WARN 不阻断;修复任务族(id 带修复前缀)
|
|
1710
2412
|
// 不参与该族——其顺序由修复生命周期保证,回修同一文件是必然形态。修复前 plan 出口无这些
|
|
1711
2413
|
// 检测 = 预期 RED。
|
|
1712
|
-
name: 'A16 plan 出口文件依赖检出:写写重叠 BLOCK 与恢复 + 读写弱判 WARN + 同文件跨任务无依赖路径(真实命令)',
|
|
2414
|
+
name: 'A16 plan 出口文件依赖检出:写写重叠 BLOCK 与恢复 + glob 单侧/双侧/不重叠 + 读写弱判 WARN + 同文件跨任务无依赖路径(真实命令)',
|
|
1713
2415
|
run: (dir) => {
|
|
1714
2416
|
driveThroughDesign(dir);
|
|
1715
2417
|
const planEnv = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
@@ -1741,6 +2443,39 @@ const TEST_ITEMS = [
|
|
|
1741
2443
|
assertOut(blocked, 'BLOCKED');
|
|
1742
2444
|
assertOut(blocked, 'bak_a.txt');
|
|
1743
2445
|
assertOut(blocked, 'depends_on');
|
|
2446
|
+
// glob 形态重叠(单侧元字符 × 字面路径):修复前逐字相等判定漏检 ⇒ 静默放行(本段即 RED);
|
|
2447
|
+
// 反向构造:改为互不重叠 / 段数不等 / 段内不匹配 ⇒ 放行(判据不恒真空过);双侧 glob ⇒ 保守判重叠。
|
|
2448
|
+
const globPair = (firstWrite, secondWrite, secondDeps = '') =>
|
|
2449
|
+
C1 +
|
|
2450
|
+
'<task id="G01" parallel="true" status="pending"><action>实现 G01</action><write_files>' + firstWrite + '</write_files><verify>node --check src/x.mjs</verify></task>\n' +
|
|
2451
|
+
'<task id="G02" parallel="true" status="pending"><action>实现 G02</action><write_files>' + secondWrite + '</write_files><verify>node --check src/x.mjs</verify>' + secondDeps + '</task>\n';
|
|
2452
|
+
planTask(globPair('src/glob/*.mjs', 'src/glob/foo.mjs'));
|
|
2453
|
+
const globBlocked = exitPlanNoApply();
|
|
2454
|
+
assertExit(globBlocked, 1);
|
|
2455
|
+
assertOut(globBlocked, 'BLOCKED');
|
|
2456
|
+
assertOut(globBlocked, 'G01×G02');
|
|
2457
|
+
assertOut(globBlocked, 'src/glob/*.mjs');
|
|
2458
|
+
assertOut(globBlocked, 'src/glob/foo.mjs');
|
|
2459
|
+
assertOut(globBlocked, 'depends_on');
|
|
2460
|
+
planTask(globPair('src/glob/*.mjs', 'src/glob/deep/foo.mjs'));
|
|
2461
|
+
const depthMismatch = exitPlanNoApply();
|
|
2462
|
+
assertExit(depthMismatch, 0);
|
|
2463
|
+
assertNotOut(depthMismatch, 'BLOCKED');
|
|
2464
|
+
planTask(globPair('src/glob/*.mjs', 'src/glob/foo.js'));
|
|
2465
|
+
const suffixMismatch = exitPlanNoApply();
|
|
2466
|
+
assertExit(suffixMismatch, 0);
|
|
2467
|
+
assertNotOut(suffixMismatch, 'BLOCKED');
|
|
2468
|
+
planTask(globPair('src/glob/*.mjs', 'src/glob/*.js'));
|
|
2469
|
+
const doubleGlob = exitPlanNoApply();
|
|
2470
|
+
assertExit(doubleGlob, 1);
|
|
2471
|
+
assertOut(doubleGlob, 'BLOCKED');
|
|
2472
|
+
assertOut(doubleGlob, 'G01×G02');
|
|
2473
|
+
// 恢复(真实链路):按指引补显式 depends_on(重叠路径不改)⇒ 同一出口放行
|
|
2474
|
+
planTask(globPair('src/glob/*.mjs', 'src/glob/foo.mjs', '<depends_on>G01</depends_on>'));
|
|
2475
|
+
const globRecovered = exitPlanNoApply();
|
|
2476
|
+
assertExit(globRecovered, 0);
|
|
2477
|
+
assertOut(globRecovered, 'ALL CHECKS PASSED');
|
|
2478
|
+
assertNotOut(globRecovered, 'BLOCKED');
|
|
1744
2479
|
// 同一文件跨任务族(负例):两个非修复任务写入同一文件、彼此无依赖路径(串行拆分同样构成
|
|
1745
2480
|
// 「未显式排序的同文件多任务」)→ 新 change BLOCKED,消息含任务对与重叠文件 + 恢复指引。
|
|
1746
2481
|
// 同夹具并列一对修复任务(id 带修复前缀)写同一文件且无依赖路径——该族不参与判定,
|
|
@@ -3122,6 +3857,55 @@ const TEST_ITEMS = [
|
|
|
3122
3857
|
throw new Error('零提交 result 应真实写入 state');
|
|
3123
3858
|
}
|
|
3124
3859
|
|
|
3860
|
+
// ⑫b 并行 × 零提交(真实 request/result 链路):同一零提交资格在 parallel="true" 任务上
|
|
3861
|
+
// 照常成立——并行维度不改四属性映射:① 写权限走身份通道、② 提交隔离走既有 noCommit
|
|
3862
|
+
// 资格(零提交 ⇒ 无提交,提交隔离由「无提交」满足)。任务归属 subagent-execute
|
|
3863
|
+
// (并行 pending),request 记 noCommit:true、result 回传无 commitHash 的零提交契约
|
|
3864
|
+
// ⇒ exit 0、不因并行维度被契约校验拦。前提在场锚:TASK.md 该任务确带 parallel="true",
|
|
3865
|
+
// 且归属校验真实执行(协议可读、节点已 entry——不静默退化成串行/跳过形态)。
|
|
3866
|
+
const parallelTaskPath = path.join(dir, '.specs', CHANGE_ID, 'TASK.md');
|
|
3867
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md',
|
|
3868
|
+
'# TASK\n\n<task id="P16" parallel="true" status="pending"><action>并行账本同步</action>'
|
|
3869
|
+
+ '<write_files>.specs/' + CHANGE_ID + '/P16-SUMMARY.md</write_files>'
|
|
3870
|
+
+ '<verify>echo ok</verify></task>\n');
|
|
3871
|
+
if (!fs.readFileSync(parallelTaskPath, 'utf8').includes('<task id="P16" parallel="true" status="pending">')) {
|
|
3872
|
+
throw new Error('并行 × 零提交锚的前提失效:TASK.md 未标 parallel="true"');
|
|
3873
|
+
}
|
|
3874
|
+
assertExit(runState(['skill-load', 'subagent-execute', 'flow-comet-dev', '--prompt', 'flow-kit/prompts/4-dev.md'], dir), 0);
|
|
3875
|
+
const stParallel = readStateFile(dir);
|
|
3876
|
+
stParallel.currentNode = 'subagent-execute';
|
|
3877
|
+
stParallel.enteredNodes = ['open', 'design', 'plan', 'execute', 'subagent-execute'];
|
|
3878
|
+
stParallel.newChange = true;
|
|
3879
|
+
writeState(dir, stParallel);
|
|
3880
|
+
const parallelEnv = { FLOW_COMET_PROTOCOL: path.join(dir, 'reference', 'workflow-protocol.json') };
|
|
3881
|
+
const reqParallel = runHandoff(['request', 'P16', '并行零提交任务委托'], dir, parallelEnv);
|
|
3882
|
+
assertExit(reqParallel, 0);
|
|
3883
|
+
assertOut(reqParallel, 'HANDOFF REQUEST: P16');
|
|
3884
|
+
assertOut(reqParallel, 'HANDOFF 零提交资格: P16');
|
|
3885
|
+
assertNotOut(reqParallel, '本次未执行归属校验');
|
|
3886
|
+
assertNotOut(reqParallel, '尚未 entry');
|
|
3887
|
+
const parallelReqRecord = readStateFile(dir).evidence['subagent-execute'].handoffRequests.P16;
|
|
3888
|
+
if (!parallelReqRecord || parallelReqRecord.noCommit !== true) {
|
|
3889
|
+
throw new Error('并行任务的字面 gitignored write_files 应同样记录 noCommit:true: ' + JSON.stringify(parallelReqRecord));
|
|
3890
|
+
}
|
|
3891
|
+
const resParallel = runHandoff(['result', 'P16', JSON.stringify({
|
|
3892
|
+
status: 'DONE', taskId: 'P16', noCommit: true,
|
|
3893
|
+
completedChecks: ['required-skill:subagent-execute.flow-comet-dev'],
|
|
3894
|
+
redEvidence: { command: 'echo ok' },
|
|
3895
|
+
greenEvidence: { command: 'echo ok', output: 'ok' },
|
|
3896
|
+
})], dir);
|
|
3897
|
+
assertExit(resParallel, 0);
|
|
3898
|
+
assertOut(resParallel, 'HANDOFF RESULT: P16');
|
|
3899
|
+
assertOut(resParallel, 'HANDOFF 零提交: P16');
|
|
3900
|
+
assertNotOut(resParallel, 'HANDOFF ERROR');
|
|
3901
|
+
assertNotOut(resParallel, 'BLOCKED');
|
|
3902
|
+
const parallelResultRecord = readStateFile(dir).evidence['subagent-execute'].handoffResult.P16;
|
|
3903
|
+
if (!parallelResultRecord || parallelResultRecord.result?.noCommit !== true
|
|
3904
|
+
|| parallelResultRecord.result.commitHash !== undefined) {
|
|
3905
|
+
throw new Error('并行零提交 result 应写入无 commitHash 的契约: ' + JSON.stringify(parallelResultRecord));
|
|
3906
|
+
}
|
|
3907
|
+
console.log(' AC-9 并行×零提交: parallel="true" 任务 request 记 noCommit:true → result 无 commitHash 契约通过(exit 0)✓');
|
|
3908
|
+
|
|
3125
3909
|
// ⑬ 零提交负例:无资格形态(glob / .. 越界 / 非 git 仓 / tracked 文件)→ request 不记 noCommit
|
|
3126
3910
|
const assertNoCommitNotRecorded = (root, taskId, label) => {
|
|
3127
3911
|
const requestState = readStateFile(root);
|
|
@@ -3470,7 +4254,7 @@ const TEST_ITEMS = [
|
|
|
3470
4254
|
},
|
|
3471
4255
|
|
|
3472
4256
|
{
|
|
3473
|
-
name: 'C3 委托后 exit:证据键名契约与契约校验(通过 /
|
|
4257
|
+
name: 'C3 委托后 exit:证据键名契约与契约校验(通过 / 空交接拦截 / 在飞委托拦·收工放行 / 留痕可读)',
|
|
3474
4258
|
run: (dir) => {
|
|
3475
4259
|
gitInit(dir);
|
|
3476
4260
|
writeFile(dir, 'src/p1.mjs', 'export const x = 1;\n');
|
|
@@ -3538,6 +4322,74 @@ const TEST_ITEMS = [
|
|
|
3538
4322
|
const rDeclPass = runGuard(['exit', 'subagent-execute'], dir);
|
|
3539
4323
|
assertExit(rDeclPass, 0);
|
|
3540
4324
|
assertOut(rDeclPass, 'ALL CHECKS PASSED');
|
|
4325
|
+
// ⑬ 验证隔离真实链路(在飞委托 = 写者未收工):登记第二个委托请求而不落结果 ⇒ 出口
|
|
4326
|
+
// BLOCKED 并点名未收工任务 + 恢复指引;收工(落结果)后同一出口放行——「同一时刻只有
|
|
4327
|
+
// 一个写者」的机器可判形态走真实命令序列(request → exit 拦 → result → exit 放行)。
|
|
4328
|
+
writeFile(dir, 'src/p2.mjs', 'export const y = 2;\n');
|
|
4329
|
+
execFileSync('git', ['add', 'src/p2.mjs'], { cwd: dir });
|
|
4330
|
+
execFileSync('git', ['-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'feat: p2'], { cwd: dir });
|
|
4331
|
+
const hash2 = execFileSync('git', ['rev-parse', 'HEAD'], { cwd: dir, encoding: 'utf8' }).trim();
|
|
4332
|
+
assertExit(runHandoff(['request', 'P02', '委托实现 P02', '--write-files', 'src/p2.mjs'], dir), 0);
|
|
4333
|
+
const inFlightBlocked = runGuard(['exit', 'subagent-execute'], dir);
|
|
4334
|
+
assertExit(inFlightBlocked, 1);
|
|
4335
|
+
assertOut(inFlightBlocked, '在飞委托');
|
|
4336
|
+
assertOut(inFlightBlocked, '待写入者收工后重跑');
|
|
4337
|
+
assertOut(inFlightBlocked, 'P02');
|
|
4338
|
+
assertExit(runHandoff(['result', 'P02', fullContract(hash2, 'P02')], dir), 0);
|
|
4339
|
+
const collected = runGuard(['exit', 'subagent-execute'], dir);
|
|
4340
|
+
assertExit(collected, 0);
|
|
4341
|
+
assertOut(collected, 'ALL CHECKS PASSED');
|
|
4342
|
+
assertNotOut(collected, '在飞委托');
|
|
4343
|
+
// ⑮ 撤回通道真实链路(被遗弃的交接的受支持出口):登记第三个委托而不落结果 ⇒ 出口拦并给出
|
|
4344
|
+
// 该命令的恢复指引;用 workflow-handoff.mjs withdraw 撤回(原地留痕 withdrawnAt /
|
|
4345
|
+
// withdrawnBy,历史不删)⇒ 同一出口放行。反向构造:守卫不忽略已撤回的 request ⇒ 放行断言
|
|
4346
|
+
// 必红;撤回是终态 ⇒ 同一条目再次 result 被拒(撤回不被事后「复活」)。
|
|
4347
|
+
assertExit(runHandoff(['request', 'P03', '委托实现 P03', '--write-files', 'src/p3.mjs'], dir), 0);
|
|
4348
|
+
const abandonedBlocked = runGuard(['exit', 'subagent-execute'], dir);
|
|
4349
|
+
assertExit(abandonedBlocked, 1);
|
|
4350
|
+
assertOut(abandonedBlocked, '在飞委托');
|
|
4351
|
+
assertOut(abandonedBlocked, 'workflow-handoff.mjs withdraw');
|
|
4352
|
+
const noSource = runHandoff(['withdraw', 'P03'], dir);
|
|
4353
|
+
assertExit(noSource, 1);
|
|
4354
|
+
assertOut(noSource, '--by');
|
|
4355
|
+
const withdrawRes = runHandoff(['withdraw', 'P03', '--by', 'coordinator', '--reason', '零提交复验失败后作废'], dir);
|
|
4356
|
+
assertExit(withdrawRes, 0);
|
|
4357
|
+
assertOut(withdrawRes, 'HANDOFF WITHDRAW: P03');
|
|
4358
|
+
const stWithdraw = readStateFile(dir);
|
|
4359
|
+
const p03 = stWithdraw.evidence?.['subagent-execute']?.handoffRequests?.P03;
|
|
4360
|
+
if (!p03 || typeof p03.withdrawnAt !== 'string' || p03.withdrawnAt.trim() === '' || p03.withdrawnBy !== 'coordinator') {
|
|
4361
|
+
throw new Error('撤回留痕未落原记录(withdrawnAt + withdrawnBy): ' + JSON.stringify(p03));
|
|
4362
|
+
}
|
|
4363
|
+
if (!Array.isArray(p03.writeFiles) || p03.writeFiles[0] !== 'src/p3.mjs') {
|
|
4364
|
+
throw new Error('撤回不得删除原 request 字段(writeFiles 应原样保留): ' + JSON.stringify(p03));
|
|
4365
|
+
}
|
|
4366
|
+
// 时间纪律(真实链路):新写入路径走 time-utils 单一权威 ⇒ withdrawnAt 为标准形态
|
|
4367
|
+
// (本地时间 + 显式偏移),非裸 Z 拼接。
|
|
4368
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(p03.withdrawnAt)) {
|
|
4369
|
+
throw new Error('withdrawnAt 应为标准形态(本地时间 + 显式偏移,走 time-utils 的 nowTimestamp): '
|
|
4370
|
+
+ JSON.stringify(p03.withdrawnAt));
|
|
4371
|
+
}
|
|
4372
|
+
const releasedExit = runGuard(['exit', 'subagent-execute'], dir);
|
|
4373
|
+
assertExit(releasedExit, 0);
|
|
4374
|
+
assertOut(releasedExit, 'ALL CHECKS PASSED');
|
|
4375
|
+
assertNotOut(releasedExit, '在飞委托');
|
|
4376
|
+
const revived = runHandoff(['result', 'P03', fullContract(hash2, 'P03')], dir);
|
|
4377
|
+
assertExit(revived, 1);
|
|
4378
|
+
assertOut(revived, '已撤回(终态)');
|
|
4379
|
+
// ⑯ 派遣留痕可读且零新增 state 顶层字段:留痕落在既有嵌套字段(与 handoffRequests /
|
|
4380
|
+
// handoffResult 同族),state 顶层不得出现任何留痕族键。
|
|
4381
|
+
const stTrace = readStateFile(dir);
|
|
4382
|
+
if (!stTrace.evidence?.['subagent-execute']?.handoffRequests?.P02) {
|
|
4383
|
+
throw new Error('委派留痕未落嵌套证据字段(handoffRequests.P02 缺失): ' + JSON.stringify(stTrace.evidence));
|
|
4384
|
+
}
|
|
4385
|
+
if (stTrace.handoffRequests !== undefined || stTrace.handoffResult !== undefined) {
|
|
4386
|
+
throw new Error('留痕出现在 state 顶层字段(应为嵌套同族形态)');
|
|
4387
|
+
}
|
|
4388
|
+
for (const key of Object.keys(stTrace)) {
|
|
4389
|
+
if (/handoff|delegation|dispatch|trace/i.test(key)) {
|
|
4390
|
+
throw new Error('state 顶层出现留痕族字段: ' + key + '(零新增顶层字段约束被破坏)');
|
|
4391
|
+
}
|
|
4392
|
+
}
|
|
3541
4393
|
},
|
|
3542
4394
|
},
|
|
3543
4395
|
|
|
@@ -4193,7 +5045,8 @@ const TEST_ITEMS = [
|
|
|
4193
5045
|
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
|
|
4194
5046
|
'# DESIGN\n\n- **Change ID**: ' + CHANGE_ID + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
|
|
4195
5047
|
writeFile(dir, '.specs/' + CHANGE_ID + '/TASK.md', fixBatchTaskText('pending'));
|
|
4196
|
-
|
|
5048
|
+
// 段内大写 Z 形态的 SUMMARY(方法声明在其后):该出口的 exit 0 即「段尾判定正确」的真实链路锚
|
|
5049
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/T01-SUMMARY.md', execSummaryWithMachineMarker('T01'));
|
|
4197
5050
|
// 源节点前序产物齐备:REVIEW.md 在场(已处置)——否则回源 verify 出口后的产物推导会把
|
|
4198
5051
|
// 下一跳判回 review(产物即真相),组合链路的终点断言无法到达 archive。
|
|
4199
5052
|
writeFile(dir, '.specs/' + CHANGE_ID + '/REVIEW.md', fixBatchReviewDoc(true));
|
|
@@ -4218,6 +5071,10 @@ const TEST_ITEMS = [
|
|
|
4218
5071
|
const execExit = runGuard(['exit', 'execute', '--apply'], dir, env);
|
|
4219
5072
|
assertExit(execExit, 0);
|
|
4220
5073
|
assertOut(execExit, 'ALL CHECKS PASSED');
|
|
5074
|
+
// 段尾判定锚(新 / 旧 change 两态都不许出现该拦因):T01 的 6 维自查段内大写 Z 在方法声明
|
|
5075
|
+
// **之前**——段体若把大写 Z 当串尾而提前收尾,该出口会报「6 维自查未声明使用」(新 change
|
|
5076
|
+
// BLOCK / 旧 change 同句 WARN),本条对两态都构成判别。
|
|
5077
|
+
assertNotOut(execExit, '6 维自查未声明使用');
|
|
4221
5078
|
assertOut(execExit, 'FIX-BATCH: 回源节点 verify(execute 出口已完成)');
|
|
4222
5079
|
assertNodeLine(execExit, 'verify');
|
|
4223
5080
|
assertNotNodeLine(execExit, 'archive');
|
|
@@ -4235,6 +5092,19 @@ const TEST_ITEMS = [
|
|
|
4235
5092
|
throw new Error(summaryName + ' 缺六维自查 / 自检方法段(execute 家族出口之一)');
|
|
4236
5093
|
}
|
|
4237
5094
|
}
|
|
5095
|
+
// 夹具形态自证(判别力前提 · 抽掉必报的反面):T01 的 6 维自查段内「大写 Z 说明行」必须
|
|
5096
|
+
// **早于**方法声明、且两者都在该段内——否则上面那次出口放行与该段尾判定无关,锚会静默
|
|
5097
|
+
// 退化成假绿(形态不符即抛错,不静默跳过)。
|
|
5098
|
+
const t01SummaryText = fs.readFileSync(path.join(dir, '.specs', CHANGE_ID, 'T01-SUMMARY.md'), 'utf8');
|
|
5099
|
+
const sixDimAt = t01SummaryText.indexOf('## 6 维自查');
|
|
5100
|
+
const nextSectionAt = sixDimAt >= 0 ? t01SummaryText.indexOf('\n## ', sixDimAt) : -1;
|
|
5101
|
+
const zMarkerAt = sixDimAt >= 0 ? t01SummaryText.indexOf('ZERO-LOGIC-CHANGE-OK', sixDimAt) : -1;
|
|
5102
|
+
const declaredAt = sixDimAt >= 0 ? t01SummaryText.indexOf('brooks-review', sixDimAt) : -1;
|
|
5103
|
+
if (!(sixDimAt >= 0 && zMarkerAt > sixDimAt && declaredAt > zMarkerAt
|
|
5104
|
+
&& (nextSectionAt === -1 || declaredAt < nextSectionAt))) {
|
|
5105
|
+
throw new Error('T01-SUMMARY 的 6 维自查段须为「大写 Z 说明行在前、方法声明行在后」形态(段尾判定锚的判别力前提): '
|
|
5106
|
+
+ JSON.stringify({ sixDimAt, zMarkerAt, declaredAt, nextSectionAt }));
|
|
5107
|
+
}
|
|
4238
5108
|
const execEvent = (chainState.history || [])
|
|
4239
5109
|
.filter((e) => e.event === 'exit-applied' && e.node === 'execute')
|
|
4240
5110
|
.pop();
|
|
@@ -5207,7 +6077,7 @@ const TEST_ITEMS = [
|
|
|
5207
6077
|
// 形状不符 fail-closed/项目根包含性含 8.3 短路径/退出码映射/guard 路径存在漂移防护;
|
|
5208
6078
|
// apply 集成:tools/pre-execute 监听器分派——子代理放行/协调者走 guard/越界·形状 deny 不受身份)
|
|
5209
6079
|
{
|
|
5210
|
-
name: 'K11 桥接 loader:纯函数与 apply 分派断言(
|
|
6080
|
+
name: 'K11 桥接 loader:纯函数与 apply 分派断言(映射/包含性/退出映射/身份分派/最小保护集)',
|
|
5211
6081
|
run: async (dir) => {
|
|
5212
6082
|
const repoRoot = path.resolve(__dirname, '..', '..', '..', '..');
|
|
5213
6083
|
if (!fs.existsSync(path.join(repoRoot, '.flow-comet', 'skills', 'flow-comet'))) return; // 安装副本无权威源
|
|
@@ -5370,14 +6240,15 @@ const TEST_ITEMS = [
|
|
|
5370
6240
|
// 项目根常规用长形态(与桥接对 file_path 的规范化一致,对应真实会话规范 cwd);
|
|
5371
6241
|
// 短形态 cwd 的场景由桥接的项目根规范化修复,⑦f 断言锁死(fail-open 已封闭)。
|
|
5372
6242
|
const longTarget = bridge.realpathExistingPath(target); // realpathSync.native——展开 8.3 短名
|
|
5373
|
-
// ⑦a 子代理(depth=1)写项目内源码 → next()
|
|
6243
|
+
// ⑦a 子代理(depth=1)写项目内源码 → next() 被调(守卫按身份分派放行——桥接不短路,
|
|
6244
|
+
// 身份深度随 env 透传,判定与最小保护集统一由守卫拥有)
|
|
5374
6245
|
{
|
|
5375
6246
|
let usedNext = false;
|
|
5376
6247
|
const res = await preExec(
|
|
5377
6248
|
{ name: 'Write', arguments: { file_path: path.join(longTarget, 'src', 'a.mjs') }, agent: { cwd: longTarget, session: { header: { delegationDepth: 1 } } } },
|
|
5378
6249
|
() => { usedNext = true; },
|
|
5379
6250
|
);
|
|
5380
|
-
if (!usedNext) throw new Error('子代理写源码应放行(next 被调)
|
|
6251
|
+
if (!usedNext) throw new Error('子代理写源码应放行(next 被调)——身份分派分支缺失');
|
|
5381
6252
|
if (res) throw new Error('子代理写源码不应返回 deny: ' + JSON.stringify(res));
|
|
5382
6253
|
}
|
|
5383
6254
|
// ⑦b 协调者(delegationDepth 缺失=0)同目标写 → 走真实 guard 白名单 → BLOCK deny
|
|
@@ -5442,7 +6313,106 @@ const TEST_ITEMS = [
|
|
|
5442
6313
|
throw new Error('短形态 cwd 协调者写源码应走 guard 白名单拦截(deny): ' + JSON.stringify(res));
|
|
5443
6314
|
}
|
|
5444
6315
|
}
|
|
5445
|
-
|
|
6316
|
+
// ⑦g 最小保护集在桥接侧真实生效(身份放行不放行机器面):子代理(depth=1)写项目内
|
|
6317
|
+
// 机器状态文件 → 桥接透传身份深度、守卫保护集 BLOCK → deny;对照 = ⑦a 同身份写源码
|
|
6318
|
+
// 放行。反向构造:桥接恢复「身份短路直接 next」⇒ 本断言必红(保护集形同虚设)。
|
|
6319
|
+
{
|
|
6320
|
+
let usedNext = false;
|
|
6321
|
+
const res = await preExec(
|
|
6322
|
+
{ name: 'Write', arguments: { file_path: path.join(longTarget, '.flow-comet', 'flow-comet-state.json') }, agent: { cwd: longTarget, session: { header: { delegationDepth: 1 } } } },
|
|
6323
|
+
() => { usedNext = true; },
|
|
6324
|
+
);
|
|
6325
|
+
if (usedNext) throw new Error('子代理写机器状态文件不应 next——身份放行不得放行最小保护集');
|
|
6326
|
+
if (!res || res.kind !== 'deny' || !res.reason.includes('state 文件')) {
|
|
6327
|
+
throw new Error('子代理写机器状态文件应 deny(含 state 文件语义): ' + JSON.stringify(res));
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6330
|
+
// ⑦h 最小保护集的协议目标同判:子代理(depth=1)写本次运行实际生效的协议文件
|
|
6331
|
+
// (守卫按自身 packageRoot 解析——安装副本内的 reference/workflow-protocol.json)
|
|
6332
|
+
// → deny;该路径在项目根内,故本断言与 ⑦d 的越界 deny 相互独立(保护集非越界判定)。
|
|
6333
|
+
{
|
|
6334
|
+
const protocolInTarget = path.join(longTarget, '.dsh', 'skills', 'flow-comet', 'reference', 'workflow-protocol.json');
|
|
6335
|
+
let usedNext = false;
|
|
6336
|
+
const res = await preExec(
|
|
6337
|
+
{ name: 'Write', arguments: { file_path: protocolInTarget }, agent: { cwd: longTarget, session: { header: { delegationDepth: 1 } } } },
|
|
6338
|
+
() => { usedNext = true; },
|
|
6339
|
+
);
|
|
6340
|
+
if (usedNext) throw new Error('子代理写协议保护路径不应 next——身份放行不得放行协议面');
|
|
6341
|
+
if (!res || res.kind !== 'deny' || !res.reason.includes('协议文件')) {
|
|
6342
|
+
throw new Error('子代理写协议保护路径应 deny(含协议文件语义): ' + JSON.stringify(res));
|
|
6343
|
+
}
|
|
6344
|
+
}
|
|
6345
|
+
// ⑦i 最小保护集对盘符根拼写(Windows 上 Git-Bash 类 shell 的 `/d/<剩余>` 形态)同样成立:
|
|
6346
|
+
// Bash 命令级写入的目标经既有提取器抽出后按写入目标解析的字面归一处理 ⇒ 与盘符拼写
|
|
6347
|
+
// 同判 deny。归一前该拼写被错解到「当前盘根之下」⇒ 保护集两道判据同时空转(身份放行
|
|
6348
|
+
// 下静默 next = fail-open)。对照 = 同一身份的盘符根拼写源码仍放行(保护集不扩大)。
|
|
6349
|
+
// 该拼写是 Windows 上 Git-Bash 类 shell 的自然产物;非 win32 载体上它是普通 POSIX 绝对
|
|
6350
|
+
// 路径,语义不同 ⇒ 显式不适用(不静默跳过——未验证 ≠ 通过)。
|
|
6351
|
+
const hasDriveRoot = /^[A-Za-z]:[\\/]/.test(longTarget);
|
|
6352
|
+
if (process.platform === 'win32' && hasDriveRoot) {
|
|
6353
|
+
const driveRootSpelling = (p) => '/' + p[0].toLowerCase() + p.slice(2).replaceAll('\\', '/');
|
|
6354
|
+
const spellingCases = [
|
|
6355
|
+
['机器状态文件', driveRootSpelling(path.join(longTarget, '.flow-comet', 'flow-comet-state.json')), 'state 文件'],
|
|
6356
|
+
['项目内源码', driveRootSpelling(path.join(longTarget, 'src', 'a.mjs')), null],
|
|
6357
|
+
];
|
|
6358
|
+
for (const [label, spelled, denyMarker] of spellingCases) {
|
|
6359
|
+
let usedNext = false;
|
|
6360
|
+
const res = await preExec(
|
|
6361
|
+
{ name: 'Bash', arguments: { command: 'cp "' + spelled + '" "' + spelled + '"' }, agent: { cwd: longTarget, session: { header: { delegationDepth: 1 } } } },
|
|
6362
|
+
() => { usedNext = true; },
|
|
6363
|
+
);
|
|
6364
|
+
if (denyMarker === null) {
|
|
6365
|
+
if (!usedNext) throw new Error(label + '的盘符根拼写应放行(next)——保护集不得扩大: ' + JSON.stringify(res));
|
|
6366
|
+
continue;
|
|
6367
|
+
}
|
|
6368
|
+
if (usedNext) throw new Error(label + '的盘符根拼写不应 next——身份放行不得放行最小保护集');
|
|
6369
|
+
if (!res || res.kind !== 'deny' || !res.reason.includes(denyMarker)) {
|
|
6370
|
+
throw new Error(label + '的盘符根拼写应 deny(含 ' + denyMarker + ' 语义): ' + JSON.stringify(res));
|
|
6371
|
+
}
|
|
6372
|
+
}
|
|
6373
|
+
console.log(' 盘符根拼写与盘符拼写同判(机器面 deny / 源码放行)✓');
|
|
6374
|
+
} else {
|
|
6375
|
+
console.log(' (盘符根拼写断言显式不适用——非 win32 载体上该拼写是普通 POSIX 绝对路径)');
|
|
6376
|
+
}
|
|
6377
|
+
// ⑦j 桥接通道标记的作用域收紧(同型真实链路格):CC / Codex 生成的 hook **直接**调用守卫、
|
|
6378
|
+
// 不经桥接——同一目标、同一深度值,经桥接 ⇒ 放行(⑦a 已覆盖),绕过桥接直接调守卫
|
|
6379
|
+
// ⇒ 深度变量虽在场也不作数:守卫按协调者语义走白名单 ⇒ deny;同一调用补上通道标记
|
|
6380
|
+
// ⇒ 按键控的身份通道放行(证明判据键在标记上,不是「直接调用一律拦」)。
|
|
6381
|
+
// 反向构造:守卫去掉标记要求 ⇒ 继承形态必红(继承来的深度变量被当成子代理身份 ⇒ 源码写入放行)。
|
|
6382
|
+
{
|
|
6383
|
+
const guardAbs = path.join(longTarget, guardRel);
|
|
6384
|
+
const probeInput = JSON.stringify({
|
|
6385
|
+
tool_name: 'Write',
|
|
6386
|
+
tool_input: { file_path: path.join(longTarget, 'src', 'c.mjs') },
|
|
6387
|
+
});
|
|
6388
|
+
const directEnvs = [
|
|
6389
|
+
['继承形态(无通道标记)', { FLOW_COMET_AGENT_DEPTH: '1' }, 2],
|
|
6390
|
+
['通道标记在场', { FLOW_COMET_AGENT_DEPTH: '1', FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh-bridge' }, 0],
|
|
6391
|
+
['标记值不符(近形状)', { FLOW_COMET_AGENT_DEPTH: '1', FLOW_COMET_AGENT_DEPTH_SOURCE: 'dsh' }, 2],
|
|
6392
|
+
];
|
|
6393
|
+
for (const [label, overrides, expected] of directEnvs) {
|
|
6394
|
+
const res = spawnSync(process.execPath, [guardAbs, 'before_tool'], {
|
|
6395
|
+
cwd: longTarget,
|
|
6396
|
+
input: probeInput,
|
|
6397
|
+
env: { ...process.env, ...overrides },
|
|
6398
|
+
encoding: 'utf8',
|
|
6399
|
+
timeout: 60000,
|
|
6400
|
+
});
|
|
6401
|
+
const out = String(res.stdout || '') + String(res.stderr || '');
|
|
6402
|
+
if ((res.status ?? 1) !== expected) {
|
|
6403
|
+
throw new Error('桥接通道标记直接调用格「' + label + '」预期 exit ' + expected
|
|
6404
|
+
+ ',实际 exit ' + String(res.status) + ': ' + out.trim().slice(0, 160));
|
|
6405
|
+
}
|
|
6406
|
+
if (expected === 2 && !out.includes('BLOCKED')) {
|
|
6407
|
+
throw new Error('桥接通道标记直接调用格「' + label + '」拦截报文缺 BLOCKED: ' + out.trim().slice(0, 160));
|
|
6408
|
+
}
|
|
6409
|
+
if (expected === 0 && !out.includes('(subagent identity)')) {
|
|
6410
|
+
throw new Error('桥接通道标记直接调用格「' + label + '」应走身份通道放行: ' + out.trim().slice(0, 160));
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6413
|
+
console.log(' 桥接通道标记:继承形态按协调者拦 / 标记在场走身份放行 / 近形状标记不认 ✓');
|
|
6414
|
+
}
|
|
6415
|
+
console.log(' bridge.apply 分派集成(子代理放行/协调者拦/越界·形状 deny 不受身份/保护集拦)✓');
|
|
5446
6416
|
},
|
|
5447
6417
|
},
|
|
5448
6418
|
|
|
@@ -5938,10 +6908,14 @@ const TEST_ITEMS = [
|
|
|
5938
6908
|
},
|
|
5939
6909
|
},
|
|
5940
6910
|
|
|
5941
|
-
// K18: 分发面(npm 包形态)——可发布性清单 + 包体边界 + bin 双入口 + init
|
|
6911
|
+
// K18: 分发面(npm 包形态)——可发布性清单 + 包体边界 + bin 双入口 + init 词元形态与红线
|
|
6912
|
+
// + 安装器升级路径清理(镜像目录内「权威源已不存在」的条目在重装后必须消失:含反向探针
|
|
6913
|
+
// 与幂等断言;`.claude/rules` 一类无命名空间的生成面 fail-closed 不纳入删除面)
|
|
6914
|
+
// + 安装器镜像清理的**根级** fail-closed(镜像根自身为链接 / 真实路径越出项目根两变体:
|
|
6915
|
+
// 项目外文件必不消失 + 保留原因可见 + 幂等 + 反向构造证明判别力)。
|
|
5942
6916
|
// 权威源侧真跑断言(npm pack --dry-run 的真实产物清单在场才算通过);安装副本侧输出显式
|
|
5943
6917
|
// 「不适用」行并回传同语义的结果标记计通过(禁止静默跳过——「未验证 ≠ 通过」)。
|
|
5944
|
-
//
|
|
6918
|
+
// 各断言见上方同名助手;结果标记由运行器按环境判据断言(distributionSurface 契约)。
|
|
5945
6919
|
{
|
|
5946
6920
|
name: 'K18 分发面:环境判据与包体边界·bin 双入口(权威源真跑/副本显式不适用)与 init 词元红线',
|
|
5947
6921
|
distributionSurface: true,
|
|
@@ -5951,12 +6925,19 @@ const TEST_ITEMS = [
|
|
|
5951
6925
|
assertPackageContextJudgment(dir);
|
|
5952
6926
|
const pkgCtx = resolvePackageContext();
|
|
5953
6927
|
const marker = DISTRIBUTION_MARKERS[pkgCtx.kind];
|
|
6928
|
+
// 安装器分发面断言(升级路径清理):权威源侧真跑真实命令序列,安装副本侧输出显式
|
|
6929
|
+
// 「不适用」行(两侧都出声——副本侧不是静默跳过);故置于环境分支之前调用。
|
|
6930
|
+
assertInstallerUpgradePathCleanup(dir);
|
|
6931
|
+
// 安装器分发面断言(镜像清理的根级 fail-closed):同一注入点的第二组判据——根自身为链接 /
|
|
6932
|
+
// 真实路径越界两变体 + 反向构造;副本侧同样输出显式「不适用」行。
|
|
6933
|
+
assertMirrorRootLinkFailClosed(dir, pkgCtx);
|
|
5954
6934
|
if (pkgCtx.kind === 'copy') {
|
|
5955
6935
|
console.log(' 不适用(安装副本侧:' + pkgCtx.reason + ')——包体边界/bin 断言仅权威源侧可判,本项计通过');
|
|
5956
6936
|
return marker;
|
|
5957
6937
|
}
|
|
5958
6938
|
assertPublishableManifest(pkgCtx.pkg);
|
|
5959
6939
|
assertPackageBoundary(pkgCtx.root);
|
|
6940
|
+
assertWorkflowContractCheck(dir);
|
|
5960
6941
|
assertInitTokenContract(assertBinContract(pkgCtx.pkg, pkgCtx.root), dir);
|
|
5961
6942
|
return marker;
|
|
5962
6943
|
},
|
|
@@ -6102,6 +7083,493 @@ const TEST_ITEMS = [
|
|
|
6102
7083
|
assertOut(r, 'EMPTY-REPO');
|
|
6103
7084
|
},
|
|
6104
7085
|
},
|
|
7086
|
+
|
|
7087
|
+
// ---------- M. 侧命令(evolve / health / context-scan)与 ui-design 门:真实命令链路 ----------
|
|
7088
|
+
|
|
7089
|
+
{
|
|
7090
|
+
name: 'M1 evolve 真实链路:scan 零写入 → apply 落盘·报告·双落点 → 幂等 → 反例零改动',
|
|
7091
|
+
run: (dir) => {
|
|
7092
|
+
writeFile(dir, '.specs/archive/2026-09-10-fixture/DESIGN.md',
|
|
7093
|
+
'# DESIGN\n\n## 5. 其它段\n\nOTHER-SECTION-MARKER\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 夹具抽象条目(真实链路)\n');
|
|
7094
|
+
// 第二个归档 change 提供第二条候选(同段同类):AC-2 的「只批准一项 → 其余候选零改动 +
|
|
7095
|
+
// 报告按「未应用 N 条」记账」需要一条**未被批准**的真实候选,否则该子句恒为 0 条。
|
|
7096
|
+
writeFile(dir, '.specs/archive/2026-09-10b-fixture/DESIGN.md',
|
|
7097
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 未被批准的夹具条目(其余候选零改动)\n');
|
|
7098
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7099
|
+
writeState(dir, baseState('open'));
|
|
7100
|
+
|
|
7101
|
+
const before = treeFingerprint(dir);
|
|
7102
|
+
const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
7103
|
+
assertExit(scan, 0);
|
|
7104
|
+
assertOut(scan, 'EVOLVE: 窗口');
|
|
7105
|
+
assertOut(scan, '2026-09-10-fixture#1');
|
|
7106
|
+
assertNotOut(scan, 'OTHER-SECTION-MARKER');
|
|
7107
|
+
if (treeFingerprint(dir) !== before) throw new Error('scan 必须零写入(树指纹应逐项一致)');
|
|
7108
|
+
|
|
7109
|
+
const apply = runSideScript(SIDE_EVOLVE,
|
|
7110
|
+
['apply', '2026-09-10-fixture#1', '--root', dir, '--scanner', 'flow-comet-evolve'], dir);
|
|
7111
|
+
assertExit(apply, 0);
|
|
7112
|
+
assertOut(apply, 'EVOLVE-OK');
|
|
7113
|
+
assertOut(apply, 'EVOLVE: 双落点一致 state = ');
|
|
7114
|
+
const contextText = readText(dir, '.specs/CONTEXT.md');
|
|
7115
|
+
if (!contextText.includes('夹具抽象条目(真实链路)')) throw new Error('目标段未出现已批准的条目');
|
|
7116
|
+
if (!contextText.includes('来源 @.specs/archive/2026-09-10-fixture/DESIGN.md')) {
|
|
7117
|
+
throw new Error('条目缺来源标注');
|
|
7118
|
+
}
|
|
7119
|
+
if (contextText.includes('未被批准的夹具条目')) {
|
|
7120
|
+
throw new Error('未批准的候选被写入了目标文档(AC-2「仅该项被写入」被破坏)');
|
|
7121
|
+
}
|
|
7122
|
+
const evolveReport = path.join(dir, '.specs', 'evolve', localDate() + '-EVOLVE.md');
|
|
7123
|
+
if (!fs.existsSync(evolveReport)) throw new Error('EVOLVE 报告未落盘: ' + evolveReport);
|
|
7124
|
+
|
|
7125
|
+
// AC-2 报告子句(此前只断言「报告存在」):扫描范围 + 已扫 change 清单 + 未应用记账。
|
|
7126
|
+
const reportText = fs.readFileSync(evolveReport, 'utf8');
|
|
7127
|
+
const clauseProblems = evolveReportClauseProblems(reportText);
|
|
7128
|
+
assertEqual(clauseProblems.length, 0, 'EVOLVE 报告缺 AC-2 声明的子句: ' + clauseProblems.join(' | '));
|
|
7129
|
+
assertTrue(reportText.includes('2026-09-10b-fixture'),
|
|
7130
|
+
'报告的「已扫 change 清单」未列出第二个归档 change');
|
|
7131
|
+
assertTrue(reportText.includes('未应用 1 条'), '报告未按「本次应用 1 / 未应用 1」记账');
|
|
7132
|
+
assertTrue(reportText.includes('2026-09-10b-fixture#1'), '「未应用项」段未列出未批准的候选 id');
|
|
7133
|
+
// 判别力(合成输入驱动同一判据):逐个子句从真实报告里移除 → 必报(判据不恒真空过)
|
|
7134
|
+
for (const clause of ['## 扫描范围', '- 已扫 change 清单:', '## 未应用项']) {
|
|
7135
|
+
const mutated = reportText.replace(clause, '(反向构造:子句被移除)');
|
|
7136
|
+
assertTrue(mutated !== reportText, '反向构造前提不成立(真实报告缺子句): ' + clause);
|
|
7137
|
+
assertTrue(evolveReportClauseProblems(mutated).length > 0,
|
|
7138
|
+
'报告缺子句未被判违规(判别力缺失): ' + clause);
|
|
7139
|
+
}
|
|
7140
|
+
|
|
7141
|
+
const state = readStateFile(dir);
|
|
7142
|
+
if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(String(state.last_evolve_at))) {
|
|
7143
|
+
throw new Error('双落点 state 侧形态非法: ' + JSON.stringify(state.last_evolve_at));
|
|
7144
|
+
}
|
|
7145
|
+
if (!contextText.includes(state.last_evolve_at)) throw new Error('双落点取值不一致(段侧与 state)');
|
|
7146
|
+
// AC-3 三字段端到端(此前只断言时间戳一个):段在场 + `last_evolve_at` / `scanner` /
|
|
7147
|
+
// `下次建议` 齐备且取值与 state、本次执行工具一致。
|
|
7148
|
+
const fieldProblems = evolveSectionFieldProblems(contextText, state.last_evolve_at, 'flow-comet-evolve');
|
|
7149
|
+
assertEqual(fieldProblems.length, 0, 'AC-3 三字段端到端: ' + fieldProblems.join(' | '));
|
|
7150
|
+
// 判别力(合成输入驱动同一判据):三字段各自移除 / 取值写错 → 必报
|
|
7151
|
+
const withoutField = contextText.replace(/- \*\*下次建议\*\*: `[^`]*`\n/, '');
|
|
7152
|
+
assertTrue(withoutField !== contextText, '反向构造前提不成立(段内无「下次建议」字段)');
|
|
7153
|
+
assertTrue(evolveSectionFieldProblems(withoutField, state.last_evolve_at, 'flow-comet-evolve').length > 0,
|
|
7154
|
+
'段内缺「下次建议」字段未被判违规');
|
|
7155
|
+
assertTrue(evolveSectionFieldProblems(contextText, state.last_evolve_at, 'other-scanner').length > 0,
|
|
7156
|
+
'段内 scanner 取值与本次执行工具不符未被判违规');
|
|
7157
|
+
assertTrue(evolveSectionFieldProblems(contextText.replace('## evolve 元数据', '## 其它段'),
|
|
7158
|
+
state.last_evolve_at, 'flow-comet-evolve').length > 0, '段缺席未被判违规');
|
|
7159
|
+
|
|
7160
|
+
const again = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
|
|
7161
|
+
assertExit(again, 0);
|
|
7162
|
+
assertOut(again, 'EVOLVE-OK');
|
|
7163
|
+
const occurrences = readText(dir, '.specs/CONTEXT.md').split('夹具抽象条目(真实链路)').length - 1;
|
|
7164
|
+
assertEqual(occurrences, 1, '重复应用同一候选的条目出现次数(幂等)');
|
|
7165
|
+
|
|
7166
|
+
// 幂等判据不得依赖**当天日期**:标记注释里写的是当次运行的本地日期,隔天重跑时它必然失配;
|
|
7167
|
+
// 而条目文本一旦被人工改写,`body.includes(entry)` 也同时失配 ⇒ 同一候选被二次插入。
|
|
7168
|
+
// 两臂同变异、单变量——对照臂只改条目文本(标记保持当天),处理臂再把标记日期改到过去
|
|
7169
|
+
// (= 隔天重跑的等效输入):后者若仍幂等,就说明判别依据与日期无关,而对照臂同时证明
|
|
7170
|
+
// 「条目被改写」本身不会让判据失效(不是靠变异把两臂都弄红)。
|
|
7171
|
+
// 变异必须**打断条目文本本身**(在来源标注之前插入):只往行尾追加的话,`entry` 仍是该行的
|
|
7172
|
+
// 连续子串,`body.includes(entry)` 照旧命中——变异就没碰到要考的那条判据(锚会恒绿)。
|
|
7173
|
+
const editEntry = (text) => {
|
|
7174
|
+
const lines = text.split('\n');
|
|
7175
|
+
const at = lines.findIndex((line) => line.includes('夹具抽象条目(真实链路)'));
|
|
7176
|
+
assertTrue(at >= 0, '反向构造前提不成立(目标段无该条目行)');
|
|
7177
|
+
lines[at] = lines[at].replace(' · 来源 @.specs/', ' · 人工改写 · 来源 @.specs/');
|
|
7178
|
+
assertTrue(lines[at].includes(' · 人工改写 · 来源 @.specs/'),
|
|
7179
|
+
'反向构造前提不成立(条目行未含来源标注,变异无处落点)');
|
|
7180
|
+
return lines.join('\n');
|
|
7181
|
+
};
|
|
7182
|
+
const backdate = (text, date) => {
|
|
7183
|
+
const from = '<!-- flow-comet-evolve ' + localDate() + ':';
|
|
7184
|
+
assertTrue(text.includes(from), '反向构造前提不成立(目标段无当日标记注释)');
|
|
7185
|
+
return text.replace(from, '<!-- flow-comet-evolve ' + date + ':');
|
|
7186
|
+
};
|
|
7187
|
+
const countEntry = () => readText(dir, '.specs/CONTEXT.md').split('夹具抽象条目(真实链路)').length - 1;
|
|
7188
|
+
const edited = editEntry(readText(dir, '.specs/CONTEXT.md'));
|
|
7189
|
+
assertTrue(!edited.includes('- 夹具抽象条目(真实链路) · 来源 @.specs/'),
|
|
7190
|
+
'反向构造前提不成立(条目文本仍是连续子串,entry 判据未被扰动)');
|
|
7191
|
+
writeFile(dir, '.specs/CONTEXT.md', edited);
|
|
7192
|
+
const sameDay = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
|
|
7193
|
+
assertExit(sameDay, 0);
|
|
7194
|
+
assertOut(sameDay, 'EVOLVE-OK');
|
|
7195
|
+
assertNotOut(sameDay, 'EVOLVE-APPLY: [2026-09-10-fixture#1]');
|
|
7196
|
+
assertEqual(countEntry(), 1, '条目文本被改写后同日重跑:同一候选被二次插入');
|
|
7197
|
+
|
|
7198
|
+
writeFile(dir, '.specs/CONTEXT.md',
|
|
7199
|
+
backdate(editEntry(readText(dir, '.specs/CONTEXT.md')), '2000-01-01'));
|
|
7200
|
+
const crossDay = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-10-fixture#1', '--root', dir], dir);
|
|
7201
|
+
assertExit(crossDay, 0);
|
|
7202
|
+
assertOut(crossDay, 'EVOLVE-OK');
|
|
7203
|
+
assertNotOut(crossDay, 'EVOLVE-APPLY: [2026-09-10-fixture#1]');
|
|
7204
|
+
assertEqual(countEntry(), 1, '跨日重跑同一候选:标记的日期分量失配 → 条目被二次插入');
|
|
7205
|
+
|
|
7206
|
+
const stateBefore = readStateBytes(dir);
|
|
7207
|
+
const contextBefore = readText(dir, '.specs/CONTEXT.md');
|
|
7208
|
+
const unknown = runSideScript(SIDE_EVOLVE, ['apply', 'no-such-id#1', '--root', dir], dir);
|
|
7209
|
+
assertExit(unknown, 1);
|
|
7210
|
+
assertOut(unknown, '候选 id 未找到');
|
|
7211
|
+
if (!readStateBytes(dir).equals(stateBefore)) throw new Error('未知 id 反例改写了 state');
|
|
7212
|
+
assertEqual(readText(dir, '.specs/CONTEXT.md'), contextBefore, '未知 id 反例改写了目标文档');
|
|
7213
|
+
|
|
7214
|
+
writeFile(dir, '.specs/archive/2026-09-11-contract/DESIGN.md',
|
|
7215
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 跨模块契约\n\n- 夹具契约条目\n');
|
|
7216
|
+
const absent = runSideScript(SIDE_EVOLVE, ['apply', '2026-09-11-contract#1', '--root', dir], dir);
|
|
7217
|
+
assertExit(absent, 1);
|
|
7218
|
+
assertOut(absent, '目标文档不在场');
|
|
7219
|
+
if (!readStateBytes(dir).equals(stateBefore)) throw new Error('目标文档缺席反例改写了 state');
|
|
7220
|
+
assertEqual(readText(dir, '.specs/CONTEXT.md'), contextBefore, '目标文档缺席反例改写了目标文档');
|
|
7221
|
+
},
|
|
7222
|
+
},
|
|
7223
|
+
|
|
7224
|
+
{
|
|
7225
|
+
name: 'M2 health 真实链路:确定性层 + 增补层两态自洽 + --stdout 与落盘一致 + 不写 state',
|
|
7226
|
+
run: (dir) => {
|
|
7227
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7228
|
+
writeFile(dir, '.specs/LESSONS.md', '# LESSONS\n\n### L-001 首条\n\n### L-002 次条\n');
|
|
7229
|
+
writeState(dir, baseState('open'));
|
|
7230
|
+
const stateBytes = readStateBytes(dir);
|
|
7231
|
+
|
|
7232
|
+
const res = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir);
|
|
7233
|
+
assertExit(res, 0);
|
|
7234
|
+
assertOut(res, '## 确定性层(机器可判)');
|
|
7235
|
+
assertOut(res, '- 缺失编号(0):无');
|
|
7236
|
+
assertOut(res, '## 增补层(代码体检工具的 4 维结果 · 可选)');
|
|
7237
|
+
assertOut(res, '## 降级声明');
|
|
7238
|
+
assertOut(res, '## 易变行声明(两次运行的允许差异集合)');
|
|
7239
|
+
// 两态自洽:在场判定与降级声明必须同向(环境决定哪一态,形态不得自相矛盾)
|
|
7240
|
+
const present = res.output.includes('- **在场判定**:在场');
|
|
7241
|
+
assertEqual(res.output.includes('- **brooks-lint**:在场'), present, '增补层在场判定与降级声明的同向性');
|
|
7242
|
+
assertOut(res, present ? '- **来源标注(必填)**' : '- **brooks-lint**:不可用——探测面逐项未命中');
|
|
7243
|
+
|
|
7244
|
+
const reportFile = path.join(dir, '.specs', 'health', localDate() + '-HEALTH.md');
|
|
7245
|
+
assertTrue(fs.existsSync(reportFile), '报告未按 <日期>-HEALTH.md 形态落盘: ' + reportFile);
|
|
7246
|
+
// `--stdout` = 落盘报告正文原样在前 + `HEALTH:` 审计行追加在后(审计行是 CLI 摘要,
|
|
7247
|
+
// 不进报告字节——报告仍是唯一写入面;正文部分与落盘逐字节一致)
|
|
7248
|
+
const reportText = fs.readFileSync(reportFile, 'utf8');
|
|
7249
|
+
assertTrue(res.output.startsWith(reportText), '--stdout 的报告正文应与落盘逐字节一致(审计行追加在后)');
|
|
7250
|
+
assertOut(res, 'HEALTH: 报告 `.specs/health/' + localDate() + '-HEALTH.md`');
|
|
7251
|
+
assertOut(res, 'HEALTH-DONE');
|
|
7252
|
+
if (!readStateBytes(dir).equals(stateBytes)) throw new Error('health 改写了运行状态文件');
|
|
7253
|
+
|
|
7254
|
+
// 审计行与报告路径**恒输出**:不带 `--stdout` 时 stdout 只给摘要(报告正文不回流),
|
|
7255
|
+
// 调用方据此确认「跑没跑、落在哪」——此前该形态 stdout 为空、报告路径无处可见。
|
|
7256
|
+
const quiet = runSideScript(SIDE_HEALTH, ['--root', dir], dir);
|
|
7257
|
+
assertExit(quiet, 0);
|
|
7258
|
+
assertOut(quiet, 'HEALTH: 报告 `.specs/health/' + localDate() + '-HEALTH.md`');
|
|
7259
|
+
assertOut(quiet, 'HEALTH-DONE');
|
|
7260
|
+
assertTrue(!quiet.output.includes('## 确定性层(机器可判)'), '不带 --stdout 时报告正文不应回流到标准输出');
|
|
7261
|
+
if (!readStateBytes(dir).equals(stateBytes)) throw new Error('不带 --stdout 的一轮改写了运行状态文件');
|
|
7262
|
+
|
|
7263
|
+
// 对照态:隔离 HOME/USERPROFILE(用户级落点全部缺席)→ 增补层逐项不在场仍 exit 0
|
|
7264
|
+
const isolatedHome = path.join(dir, 'isolated-home');
|
|
7265
|
+
fs.mkdirSync(isolatedHome, { recursive: true });
|
|
7266
|
+
const isolated = runSideScript(SIDE_HEALTH, ['--root', dir, '--stdout'], dir,
|
|
7267
|
+
{ HOME: isolatedHome, USERPROFILE: isolatedHome });
|
|
7268
|
+
assertExit(isolated, 0);
|
|
7269
|
+
assertOut(isolated, '- **在场判定**:不在场——下列探测面逐项未命中(未安装 / 未加载)');
|
|
7270
|
+
assertOut(isolated, '- **brooks-lint**:不可用——探测面逐项未命中');
|
|
7271
|
+
assertOut(isolated, '## 确定性层(机器可判)');
|
|
7272
|
+
if (!readStateBytes(dir).equals(stateBytes)) throw new Error('health 对照态改写了运行状态文件');
|
|
7273
|
+
},
|
|
7274
|
+
},
|
|
7275
|
+
|
|
7276
|
+
{
|
|
7277
|
+
name: 'M3 context-scan 真实链路:init 后首扫建基线 → 工件变化 → 重扫出差分 + 双落点 + 不扰动路由',
|
|
7278
|
+
run: (dir) => {
|
|
7279
|
+
assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
|
|
7280
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7281
|
+
|
|
7282
|
+
const first = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
7283
|
+
assertExit(first, 0);
|
|
7284
|
+
assertOut(first, 'CONTEXT-SCAN: 基线 无(本次为基线,无差异可比)');
|
|
7285
|
+
assertOut(first, 'CONTEXT-SCAN-DONE');
|
|
7286
|
+
const stateAfterFirst = readStateFile(dir);
|
|
7287
|
+
assertEqual(stateAfterFirst.currentNode, 'open', '重扫不得改动路由字段 currentNode');
|
|
7288
|
+
assertEqual(stateAfterFirst.activeChange, CHANGE_ID, '重扫不得改动 activeChange');
|
|
7289
|
+
|
|
7290
|
+
const contextText = readText(dir, '.specs/CONTEXT.md');
|
|
7291
|
+
writeFile(dir, '.specs/CONTEXT.md',
|
|
7292
|
+
contextText.replace('## 既有抽象索引\n', '## 既有抽象索引\n\n- 新增抽象条目(真实链路)\n'));
|
|
7293
|
+
const second = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
7294
|
+
assertExit(second, 0);
|
|
7295
|
+
assertOut(second, '差异 新增 1 ');
|
|
7296
|
+
assertOut(second, 'CONTEXT-SCAN-DONE');
|
|
7297
|
+
|
|
7298
|
+
const report = readText(dir, '.specs/context-scan/' + localDate() + '-SCAN.md');
|
|
7299
|
+
assertTrue(report.includes('### 新增(1)'), '工件缺「新增(1)」段');
|
|
7300
|
+
assertTrue(report.includes('新增抽象条目(真实链路)'), '工件的新增段未列出新增的抽象索引条目');
|
|
7301
|
+
const stateAfterSecond = readStateFile(dir);
|
|
7302
|
+
assertTrue(report.includes(stateAfterSecond.last_intel_scan), '工件与 state 的扫描时刻不一致');
|
|
7303
|
+
assertTrue(readText(dir, '.specs/CONTEXT.md').includes(stateAfterSecond.last_intel_scan),
|
|
7304
|
+
'CONTEXT 段侧与 state 的扫描时刻不一致(双落点)');
|
|
7305
|
+
|
|
7306
|
+
const status = runState(['status'], dir);
|
|
7307
|
+
assertExit(status, 0);
|
|
7308
|
+
assertEqual(parseStatusOutput(dir).currentNode, 'open', '重扫后 status 的节点推导');
|
|
7309
|
+
},
|
|
7310
|
+
},
|
|
7311
|
+
|
|
7312
|
+
{
|
|
7313
|
+
name: 'M4 ui-design 门真实链路:entry design → 缺件 BLOCK → 补件·声明 → exit --apply 放行',
|
|
7314
|
+
run: (dir) => {
|
|
7315
|
+
assertExit(runState(['init', CHANGE_ID], dir), 0);
|
|
7316
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
7317
|
+
writeIntakeArtifacts(dir);
|
|
7318
|
+
fs.appendFileSync(path.join(dir, '.specs', CHANGE_ID, 'CHANGE.md'),
|
|
7319
|
+
'\n## 视觉调性(Visual Tone)\n\n现代、克制的工具型界面。\n');
|
|
7320
|
+
assertExit(runState(['record', 'open', '{"summary":"intake complete"}'], dir), 0);
|
|
7321
|
+
assertExit(runGuard(['entry', 'open'], dir), 0);
|
|
7322
|
+
assertExit(runGuard(['exit', 'open', '--apply'], dir), 0);
|
|
7323
|
+
|
|
7324
|
+
assertExit(runState(['skill-load', 'design', 'flow-comet-design', '--prompt', 'flow-kit/prompts/2-design.md'], dir), 0);
|
|
7325
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/DESIGN.md',
|
|
7326
|
+
'# DESIGN\n\n- **Change ID**: ' + CHANGE_ID + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
|
|
7327
|
+
assertExit(runState(['record', 'design', '{"summary":"design done"}'], dir), 0);
|
|
7328
|
+
assertExit(runGuard(['entry', 'design'], dir), 0);
|
|
7329
|
+
|
|
7330
|
+
// 负例:前端判据成立(「视觉调性」段在场且未标不适用)而工件缺席 → BLOCKED + 恢复路径
|
|
7331
|
+
const blocked = runGuard(['exit', 'design'], dir);
|
|
7332
|
+
assertExit(blocked, 1);
|
|
7333
|
+
assertOut(blocked, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
7334
|
+
assertOut(blocked, '恢复: 补 .specs/' + CHANGE_ID + '/UI-DESIGN.md');
|
|
7335
|
+
|
|
7336
|
+
// 恢复:补工件 + 真实 skill-load 声明(出口不再自动补写该绑定)→ 出口放行并落状态
|
|
7337
|
+
writeFile(dir, '.specs/' + CHANGE_ID + '/UI-DESIGN.md',
|
|
7338
|
+
'# UI-DESIGN\n\n## 1. 设计 token\n\n- 主色 `oklch(0.6 0.1 250)`\n');
|
|
7339
|
+
const undeclared = runGuard(['exit', 'design'], dir);
|
|
7340
|
+
assertExit(undeclared, 1);
|
|
7341
|
+
assertOut(undeclared, 'required-skill:design.flow-comet-ui-design');
|
|
7342
|
+
assertOut(undeclared, '不再由出口自动补写');
|
|
7343
|
+
assertExit(runState(['skill-load', 'design', 'flow-comet-ui-design', '--prompt', 'flow-kit/prompts/2a-ui-design.md'], dir), 0);
|
|
7344
|
+
assertExit(runState(['record', 'design',
|
|
7345
|
+
'{"summary":"design done with ui-design","completedChecks":["required-skill:design.flow-comet-design","required-skill:design.flow-comet-ui-design"]}'], dir), 0);
|
|
7346
|
+
const passed = runGuard(['exit', 'design', '--apply'], dir);
|
|
7347
|
+
assertExit(passed, 0);
|
|
7348
|
+
assertOut(passed, 'ALL CHECKS PASSED');
|
|
7349
|
+
assertNotOut(passed, 'UI-DESIGN: skipped');
|
|
7350
|
+
|
|
7351
|
+
// AC-10 的「跳过」半(此前只在 L1):第二个 change 走完整真实命令链路到 design 出口——
|
|
7352
|
+
// ① fail-open 反向控制:段内自然句子「不适用于暗色主题…」不是结构形态 → 仍判前端、缺件 BLOCKED;
|
|
7353
|
+
// ② 结构形态(`适用性` 标签的字段值位)→ 可见跳过 + 命中片段回显,且不要求工件与该声明。
|
|
7354
|
+
const nfChange = CHANGE_ID + '-nf';
|
|
7355
|
+
const nfChangeFile = path.join(dir, '.specs', nfChange, 'CHANGE.md');
|
|
7356
|
+
assertExit(runState(['init', nfChange, '--init-skip'], dir), 0);
|
|
7357
|
+
assertExit(runState(['skill-load', 'open', 'flow-comet-change', '--prompt', 'flow-kit/prompts/0-change.md'], dir), 0);
|
|
7358
|
+
writeIntakeArtifacts(dir, nfChange);
|
|
7359
|
+
fs.appendFileSync(nfChangeFile,
|
|
7360
|
+
'\n## 视觉调性(Visual Tone)\n\n不适用于暗色主题,本 change 仅覆盖浅色分支。\n');
|
|
7361
|
+
assertExit(runState(['record', 'open', '{"summary":"intake complete"}'], dir), 0);
|
|
7362
|
+
assertExit(runGuard(['entry', 'open'], dir), 0);
|
|
7363
|
+
assertExit(runGuard(['exit', 'open', '--apply'], dir), 0);
|
|
7364
|
+
assertExit(runState(['skill-load', 'design', 'flow-comet-design', '--prompt', 'flow-kit/prompts/2-design.md'], dir), 0);
|
|
7365
|
+
writeFile(dir, '.specs/' + nfChange + '/DESIGN.md',
|
|
7366
|
+
'# DESIGN\n\n- **Change ID**: ' + nfChange + '\n\n## 0. 技术栈选定\n\nNode.js(ESM)\n\n## 决策清单\n\n- [ ] 循环路由\n');
|
|
7367
|
+
assertExit(runState(['record', 'design', '{"summary":"design done"}'], dir), 0);
|
|
7368
|
+
assertExit(runGuard(['entry', 'design'], dir), 0);
|
|
7369
|
+
|
|
7370
|
+
const failOpen = runGuard(['exit', 'design'], dir);
|
|
7371
|
+
assertExit(failOpen, 1);
|
|
7372
|
+
assertOut(failOpen, 'BLOCKED: design 出口缺 UI-DESIGN.md');
|
|
7373
|
+
assertNotOut(failOpen, 'UI-DESIGN: skipped');
|
|
7374
|
+
|
|
7375
|
+
// 恢复:改段为结构形态(`- 适用性:不适用(…)`)→ 同一 change 出口放行并回显命中片段
|
|
7376
|
+
writeFile(dir, '.specs/' + nfChange + '/CHANGE.md',
|
|
7377
|
+
'# CHANGE\n\n- **Change ID**: ' + nfChange + '\n\n## Why(为什么做)\n\n变更目标。\n\n'
|
|
7378
|
+
+ '## 视觉调性(Visual Tone)\n\n- 适用性:不适用(CLI 工具,无用户可见界面)\n');
|
|
7379
|
+
const skipped = runGuard(['exit', 'design', '--apply'], dir);
|
|
7380
|
+
assertExit(skipped, 0);
|
|
7381
|
+
assertOut(skipped, 'UI-DESIGN: skipped(非前端)');
|
|
7382
|
+
assertOut(skipped, '命中片段: - 适用性:不适用(CLI 工具,无用户可见界面)');
|
|
7383
|
+
assertNotOut(skipped, 'required-skill:design.flow-comet-ui-design');
|
|
7384
|
+
assertNotOut(skipped, 'BLOCKED');
|
|
7385
|
+
},
|
|
7386
|
+
},
|
|
7387
|
+
|
|
7388
|
+
{
|
|
7389
|
+
name: 'M5 evolve 基线跨 change 保留:真实 init 换 change → 基线在场 + 到期提示 + 窗口过滤',
|
|
7390
|
+
run: (dir) => {
|
|
7391
|
+
const formatStamp = timeUtilsModule.formatLocalTimestamp;
|
|
7392
|
+
const dayMs = 24 * 60 * 60 * 1000;
|
|
7393
|
+
const dateDaysAgo = (days) => localDate(new Date(Date.now() - days * dayMs));
|
|
7394
|
+
// 窗口两侧各一条带 §9 的归档 change;基线落在两者之间(窗口过滤按目录名日期前缀)
|
|
7395
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(101) + '-before-baseline/DESIGN.md',
|
|
7396
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口外条目\n');
|
|
7397
|
+
writeFile(dir, '.specs/archive/' + dateDaysAgo(99) + '-after-baseline/DESIGN.md',
|
|
7398
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 窗口内条目\n');
|
|
7399
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7400
|
+
|
|
7401
|
+
// 跨 change 的持久性只走真实命令:init 首个 change → 唯一写通道落基线 → init 换 change
|
|
7402
|
+
assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
|
|
7403
|
+
const baseline = formatStamp(new Date(Date.now() - 100 * dayMs));
|
|
7404
|
+
const setRes = runState(['config', 'set', 'last_evolve_at', baseline], dir);
|
|
7405
|
+
assertExit(setRes, 0);
|
|
7406
|
+
assertOut(setRes, 'CONFIG: last_evolve_at = ' + baseline);
|
|
7407
|
+
assertExit(runState(['init', CHANGE_ID + '-2', '--init-skip'], dir), 0);
|
|
7408
|
+
const state = readStateFile(dir);
|
|
7409
|
+
assertEqual(state.activeChange, CHANGE_ID + '-2', 'init 后 activeChange');
|
|
7410
|
+
assertEqual(state.last_evolve_at, baseline, 'init 跨 change 保留 last_evolve_at');
|
|
7411
|
+
|
|
7412
|
+
const status = runState(['status'], dir);
|
|
7413
|
+
assertExit(status, 0);
|
|
7414
|
+
assertOut(status, 'EVOLVE-DUE: 上次架构沉淀 ' + baseline);
|
|
7415
|
+
assertOut(status, '超阈值 60 天');
|
|
7416
|
+
assertEqual(parseStatusOutput(dir).status, 'running', '提示行在场时 status 的 JSON 块解析');
|
|
7417
|
+
|
|
7418
|
+
const scan = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
7419
|
+
assertExit(scan, 0);
|
|
7420
|
+
assertOut(scan, '窗口 起始 = ' + baseline);
|
|
7421
|
+
assertOut(scan, '归档 2 个 · 窗口内 1 个 · 含沉淀段 1 个');
|
|
7422
|
+
assertOut(scan, 'after-baseline#1');
|
|
7423
|
+
assertNotOut(scan, 'before-baseline#');
|
|
7424
|
+
assertNotOut(scan, '无基线(首次运行,全量扫描)');
|
|
7425
|
+
|
|
7426
|
+
// AC-18 的第二个触发因(该时刻之后新增 ≥ 5 个带 §9 的归档 change)——同一条真实 `status` 链路:
|
|
7427
|
+
// 基线换成新鲜值(未达天数阈值)→ 其后补 5 个带 §9 的归档 change → 提示改按新增数给出;
|
|
7428
|
+
// 取走一个(4 个)→ 回到静默(零噪音)。基线换值仍走 `config set` 唯一写通道。
|
|
7429
|
+
const freshBaseline = formatStamp(new Date(Date.now() - 30 * dayMs));
|
|
7430
|
+
const setFresh = runState(['config', 'set', 'last_evolve_at', freshBaseline], dir);
|
|
7431
|
+
assertExit(setFresh, 0);
|
|
7432
|
+
assertOut(setFresh, 'CONFIG: last_evolve_at = ' + freshBaseline);
|
|
7433
|
+
const freshStatus = runState(['status'], dir);
|
|
7434
|
+
assertExit(freshStatus, 0);
|
|
7435
|
+
assertNotOut(freshStatus, 'EVOLVE-DUE'); // 天数阈值未达 + 新基线之后新增 0(既有两条归档早于它)
|
|
7436
|
+
const countArchive = (offset) => dateDaysAgo(30 - offset) + '-count-' + offset;
|
|
7437
|
+
for (let offset = 1; offset <= 5; offset += 1) {
|
|
7438
|
+
writeFile(dir, '.specs/archive/' + countArchive(offset) + '/DESIGN.md',
|
|
7439
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n- 计数触发条目 ' + offset + '\n');
|
|
7440
|
+
}
|
|
7441
|
+
const byCount = runState(['status'], dir);
|
|
7442
|
+
assertExit(byCount, 0);
|
|
7443
|
+
assertOut(byCount, 'EVOLVE-DUE: 上次架构沉淀 ' + freshBaseline);
|
|
7444
|
+
assertOut(byCount, '其后新增 5 个带 §9 的归档 change,达阈值 5 个');
|
|
7445
|
+
assertEqual(parseStatusOutput(dir).status, 'running', '按新增数提示时 status 的 JSON 块解析');
|
|
7446
|
+
fs.rmSync(path.join(dir, '.specs', 'archive', countArchive(5)), { recursive: true, force: true });
|
|
7447
|
+
assertNotOut(runState(['status'], dir), 'EVOLVE-DUE');
|
|
7448
|
+
},
|
|
7449
|
+
},
|
|
7450
|
+
|
|
7451
|
+
{
|
|
7452
|
+
name: 'M6 侧命令 CLI 契约真实链路:--root 两形态·--help·未知参数一致 + 损坏 state fail-closed + 协议绑定独占',
|
|
7453
|
+
run: (dir) => {
|
|
7454
|
+
writeFile(dir, '.specs/archive/2026-10-02-fixture/DESIGN.md',
|
|
7455
|
+
'# DESIGN\n\n## 9. 架构沉淀\n\n### 可复用抽象\n\n- 契约夹具条目(真实链路)\n');
|
|
7456
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7457
|
+
writeState(dir, baseState('open'));
|
|
7458
|
+
|
|
7459
|
+
// ① 三命令等号形与空格形等价(修复前 evolve 的等号形报「未知参数」exit 1)
|
|
7460
|
+
const evolveEq = runSideScript(SIDE_EVOLVE, ['scan', '--root=' + dir], dir);
|
|
7461
|
+
assertExit(evolveEq, 0);
|
|
7462
|
+
assertOut(evolveEq, '2026-10-02-fixture#1');
|
|
7463
|
+
const evolveSpace = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
7464
|
+
assertExit(evolveSpace, 0);
|
|
7465
|
+
assertOut(evolveSpace, 'EVOLVE: 窗口');
|
|
7466
|
+
assertExit(runSideScript(SIDE_HEALTH, ['--root=' + dir], dir), 0);
|
|
7467
|
+
assertExit(runSideScript(SIDE_CONTEXT_SCAN, ['--root=' + dir], dir), 0);
|
|
7468
|
+
|
|
7469
|
+
// ② `--help` 三命令一致(各列自身命令形态);未知参数三命令一致(exit 1)
|
|
7470
|
+
assertOut(runSideScript(SIDE_EVOLVE, ['--help'], dir), 'evolve.mjs apply');
|
|
7471
|
+
assertOut(runSideScript(SIDE_HEALTH, ['-h'], dir), 'health.mjs');
|
|
7472
|
+
assertOut(runSideScript(SIDE_CONTEXT_SCAN, ['--help'], dir), 'context-scan.mjs');
|
|
7473
|
+
for (const script of [SIDE_EVOLVE, SIDE_HEALTH, SIDE_CONTEXT_SCAN]) {
|
|
7474
|
+
const unknown = runSideScript(script, ['--bogus'], dir);
|
|
7475
|
+
assertExit(unknown, 1);
|
|
7476
|
+
assertOut(unknown, '未知参数: --bogus');
|
|
7477
|
+
}
|
|
7478
|
+
|
|
7479
|
+
// ③ 损坏 state 的真实链路:scan 必须 BLOCKED 且零写入,不再输出「无基线(首次运行,全量扫描)」
|
|
7480
|
+
const stateFile = path.join(dir, '.flow-comet', 'flow-comet-state.json');
|
|
7481
|
+
const stateText = fs.readFileSync(stateFile, 'utf8');
|
|
7482
|
+
fs.writeFileSync(stateFile, stateText.slice(0, Math.floor(stateText.length / 2)), 'utf8');
|
|
7483
|
+
const before = treeFingerprint(dir);
|
|
7484
|
+
const blocked = runSideScript(SIDE_EVOLVE, ['scan', '--root', dir], dir);
|
|
7485
|
+
assertExit(blocked, 1);
|
|
7486
|
+
assertOut(blocked, 'BLOCKED');
|
|
7487
|
+
assertNotOut(blocked, '无基线(首次运行,全量扫描)');
|
|
7488
|
+
if (treeFingerprint(dir) !== before) throw new Error('损坏 state 的 scan 轮有写入(树指纹应逐项一致)');
|
|
7489
|
+
|
|
7490
|
+
// ④ 协议绑定独占的真实链路:项目内约定副本坏掉 + state.protocolPath 好 → apply 必须成功
|
|
7491
|
+
fs.copyFileSync(BUILTIN_PROTOCOL_SOURCE, path.join(dir, 'bound-protocol.json'));
|
|
7492
|
+
fs.writeFileSync(path.join(dir, 'reference', 'workflow-protocol.json'),
|
|
7493
|
+
'{"schemaVersion": 99, "nodes": []}\n', 'utf8');
|
|
7494
|
+
writeState(dir, { ...baseState('open'), protocolPath: 'bound-protocol.json' });
|
|
7495
|
+
const applied = runSideScript(SIDE_EVOLVE, ['apply', '2026-10-02-fixture#1', '--root', dir], dir,
|
|
7496
|
+
{ FLOW_COMET_PROTOCOL: '' });
|
|
7497
|
+
assertExit(applied, 0);
|
|
7498
|
+
assertOut(applied, 'EVOLVE-OK');
|
|
7499
|
+
assertOut(applied, '双落点一致 state = ');
|
|
7500
|
+
assertTrue(fs.existsSync(path.join(dir, '.specs', 'evolve', localDate() + '-EVOLVE.md')),
|
|
7501
|
+
'协议绑定链路下 EVOLVE 报告未落盘');
|
|
7502
|
+
},
|
|
7503
|
+
},
|
|
7504
|
+
|
|
7505
|
+
// M7 扫描时刻双落点真实链路(夹具段行 = 真实生成件形态:取值词元 + 行尾说明)——① 首扫后同刻同
|
|
7506
|
+
// 形态即**静默**(整行口径的读侧在此恒亮)② 真漂移必须提示且**类别正确**(不得误报「段内取值
|
|
7507
|
+
// 不是合法时间戳」)③ 提示点名的 `context-scan` 跑过后,未刷新路径的 `init` **静默**(收敛可达)
|
|
7508
|
+
// ④ 单变量对照:只剥掉行尾说明仍静默(判别条件是词元口径,不是有没有说明)。
|
|
7509
|
+
{
|
|
7510
|
+
name: 'M7 扫描时刻双落点真实链路:带说明行同刻静默 + 漂移类别正确 + 重扫收敛 + 单变量对照',
|
|
7511
|
+
run: (dir) => {
|
|
7512
|
+
const parse = timeUtilsModule.parseTimestamp;
|
|
7513
|
+
assertExit(runState(['init', CHANGE_ID, '--init-skip'], dir), 0);
|
|
7514
|
+
writeFile(dir, '.specs/CONTEXT.md', contextFixtureText());
|
|
7515
|
+
|
|
7516
|
+
// ① 首扫:双落点建立(段侧与 state 同刻同形态);段行的行尾说明原样保留(写侧只换取值词元)
|
|
7517
|
+
const scan = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
7518
|
+
assertExit(scan, 0);
|
|
7519
|
+
assertOut(scan, 'CONTEXT-SCAN-DONE');
|
|
7520
|
+
const scanned = readStateFile(dir).last_intel_scan;
|
|
7521
|
+
assertTrue(readText(dir, '.specs/CONTEXT.md').includes(scanned), '首扫后段侧应与 state 同刻同形态');
|
|
7522
|
+
assertTrue(readText(dir, '.specs/CONTEXT.md').includes(INTEL_FIELD_SUFFIX),
|
|
7523
|
+
'重扫改写了段行的行尾说明(写侧只应替换取值词元)');
|
|
7524
|
+
|
|
7525
|
+
// ①' 带说明行的同刻同形态 ⇒ 静默(未刷新路径的 init 不改写既有取值)
|
|
7526
|
+
const quietLanded = runState(['init', CHANGE_ID], dir);
|
|
7527
|
+
assertExit(quietLanded, 0);
|
|
7528
|
+
assertEqual(readStateFile(dir).last_intel_scan, scanned, '未刷新路径应原样保留既有扫描时刻');
|
|
7529
|
+
assertNotOut(quietLanded, 'INIT-NOTICE');
|
|
7530
|
+
|
|
7531
|
+
// ② 真实时间流逝(跨过下一个秒边界)——秒级精度下同一秒内的两次写入取值可能相同,漂移不可判
|
|
7532
|
+
waitForNextSecond();
|
|
7533
|
+
|
|
7534
|
+
// ③ 原症状顺序:`init --init-context` 记录扫描时刻——形态统一(本地时间 + 显式偏移)+ 漂移可见
|
|
7535
|
+
// 且类别正确(两侧同为本地+偏移形态、仅时刻不同 ⇒ 「刻与形态均不一致」)
|
|
7536
|
+
const reinit = runState(['init', CHANGE_ID, '--init-context'], dir);
|
|
7537
|
+
assertExit(reinit, 0);
|
|
7538
|
+
assertOut(reinit, 'INIT-DONE');
|
|
7539
|
+
const stateAfter = readStateFile(dir).last_intel_scan;
|
|
7540
|
+
assertTrue(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:\d{2}$/.test(stateAfter),
|
|
7541
|
+
'init 写入的扫描时刻形态非「本地时间 + 显式偏移」: ' + stateAfter);
|
|
7542
|
+
assertTrue(parse(stateAfter) > parse(scanned),
|
|
7543
|
+
'init 写入的扫描时刻应晚于首扫(不得回退): ' + stateAfter + ' vs ' + scanned);
|
|
7544
|
+
assertTrue(readText(dir, '.specs/CONTEXT.md').includes(scanned),
|
|
7545
|
+
'init 不应改写 CONTEXT 段(该段行的写通道是 context-scan)');
|
|
7546
|
+
assertOut(reinit, 'INIT-NOTICE');
|
|
7547
|
+
assertOut(reinit, stateAfter);
|
|
7548
|
+
assertOut(reinit, scanned);
|
|
7549
|
+
assertOut(reinit, '刻与形态均不一致');
|
|
7550
|
+
assertNotOut(reinit, '段内取值不是合法时间戳');
|
|
7551
|
+
assertOut(reinit, 'context-scan');
|
|
7552
|
+
|
|
7553
|
+
// ④ 重扫收敛 → 双落点一致(行尾说明仍在);此后未刷新路径的 init 零提示(不误报)
|
|
7554
|
+
const converge = runSideScript(SIDE_CONTEXT_SCAN, ['--root', dir], dir);
|
|
7555
|
+
assertExit(converge, 0);
|
|
7556
|
+
assertOut(converge, 'CONTEXT-SCAN-DONE');
|
|
7557
|
+
const converged = readStateFile(dir).last_intel_scan;
|
|
7558
|
+
assertTrue(readText(dir, '.specs/CONTEXT.md').includes(converged), '重扫后双落点应收敛');
|
|
7559
|
+
const quiet = runState(['init', CHANGE_ID], dir);
|
|
7560
|
+
assertExit(quiet, 0);
|
|
7561
|
+
assertEqual(readStateFile(dir).last_intel_scan, converged, '未刷新路径应原样保留既有扫描时刻');
|
|
7562
|
+
assertNotOut(quiet, 'INIT-NOTICE');
|
|
7563
|
+
|
|
7564
|
+
// ⑤ 单变量对照:**只**剥掉段行的行尾说明(取值词元不变、state 不变)→ 仍然静默
|
|
7565
|
+
const bare = readText(dir, '.specs/CONTEXT.md').replace(INTEL_FIELD_SUFFIX, '');
|
|
7566
|
+
assertTrue(bare !== readText(dir, '.specs/CONTEXT.md'), '单变量对照前提不成立:段行不含夹具行尾说明');
|
|
7567
|
+
writeFile(dir, '.specs/CONTEXT.md', bare);
|
|
7568
|
+
const quietBare = runState(['init', CHANGE_ID], dir);
|
|
7569
|
+
assertExit(quietBare, 0);
|
|
7570
|
+
assertNotOut(quietBare, 'INIT-NOTICE');
|
|
7571
|
+
},
|
|
7572
|
+
},
|
|
6105
7573
|
];
|
|
6106
7574
|
|
|
6107
7575
|
// ---------- 运行 ----------
|