@aibyzero/cm-workflow 0.16.8 → 0.16.9
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/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +19 -0
- package/README.md +14 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +25 -1
- package/docs/next-steps.md +8 -2
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +111 -20
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +69 -22
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +951 -43
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -4
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +44 -9
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +40 -3
- package/runtime/js/cm-ai/operator-guidance.mjs +112 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +18 -0
- package/runtime/js/cm-ai/review-package.mjs +10 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +636 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +79 -9
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +312 -0
- package/runtime/js/notify.mjs +137 -33
- package/runtime/js/policy-binding-compat.mjs +54 -0
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +70 -2
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +96 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +55 -10
- package/scripts/cm-ai-batch-drive.test.mjs +65 -0
- package/scripts/cm-ai-batch-host.mjs +132 -13
- package/scripts/cm-ai-batch-host.test.mjs +255 -7
- package/scripts/cm-ai-batch-run-fixture.mjs +499 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +38 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +184 -22
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +104 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +153 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +4 -3
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive.mjs +64 -22
- package/scripts/cm-ai-drive.test.mjs +29 -2
- package/scripts/cm-ai-host-cli-workflow.test.mjs +271 -0
- package/scripts/cm-ai-host-fixture.mjs +268 -0
- package/scripts/cm-ai-host-protected.test.mjs +251 -0
- package/scripts/cm-ai-host.mjs +27 -15
- package/scripts/cm-ai-host.test.mjs +17 -759
- package/scripts/cm-ai-light-modules.test.mjs +57 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-protected-scope.test.mjs +7 -3
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +78 -11
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +56 -10
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +475 -0
- package/scripts/cm-ai-review-failure.test.mjs +124 -13
- package/scripts/cm-ai-review-timeout.test.mjs +188 -10
- package/scripts/cm-ai-run.mjs +15 -6
- package/scripts/cm-ai-supersede.test.mjs +486 -41
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +18 -2
- package/scripts/cm-external-model-recovery.test.mjs +29 -3
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +35 -0
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +22 -10
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +900 -0
- package/scripts/cm-notify-read-drift.test.mjs +205 -0
- package/scripts/cm-notify.mjs +469 -0
- package/scripts/cm-notify.test.mjs +221 -4
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/policy-binding-compat.test.mjs +99 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +27 -1
- package/skills/cm-ai/references/js-host-recovery.md +120 -8
- package/skills/cm-ai/references/js-host.md +14 -7
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +16 -3
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -4,7 +4,7 @@ import fs from 'node:fs';
|
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {spawn,spawnSync} from 'node:child_process';
|
|
7
|
-
import {notify,readNotifyConfig,buildNotifyMessage,driveNotice,NOTIFY_LIMITS,NOTIFY_WORKFLOWS} from '../runtime/js/notify.mjs';
|
|
7
|
+
import {notify,readNotifyConfig,parseNotifyConfig,buildNotifyMessage,normalizeNotifyText,driveNotice,NOTIFY_LIMITS,NOTIFY_WORKFLOWS,DEFAULT_NOTIFY_TEXT} from '../runtime/js/notify.mjs';
|
|
8
8
|
|
|
9
9
|
const NOW=Date.parse('2026-10-08T08:00:00.000Z');
|
|
10
10
|
const DRIVE_CORE=new URL('../runtime/js/cm-ai/drive-core.mjs',import.meta.url).href;
|
|
@@ -50,6 +50,65 @@ test('invalid config turns the feature off: relative command, bad version, bad w
|
|
|
50
50
|
assert.deepEqual(readNotifyConfig(h.env),{command:['/bin/true'],waitMs:30000,checkWaitMs:2700000,idleMs:2700000});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
// The runtime reads notify.json through the same safe boundary as /cm:notify:
|
|
54
|
+
// no symlink, regular file only, 64 KiB cap, non-blocking open. Every refusal
|
|
55
|
+
// turns notices off with one notify.log line; nothing throws or waits.
|
|
56
|
+
// Each probe runs in its own process: the log line is once per process, and a
|
|
57
|
+
// build that blocks on a FIFO fails by timeout instead of hanging the suite.
|
|
58
|
+
const posix=process.platform!=='win32';
|
|
59
|
+
const CONFIG={version:1,command:['/bin/true']},PARSED={command:['/bin/true'],waitMs:600000,checkWaitMs:2700000,idleMs:2700000};
|
|
60
|
+
const NOTIFY_URL=new URL('../runtime/js/notify.mjs',import.meta.url).href;
|
|
61
|
+
function probe(h){
|
|
62
|
+
const child=spawnSync(process.execPath,['--input-type=module','-e',
|
|
63
|
+
`import {readNotifyConfig,notify} from ${JSON.stringify(NOTIFY_URL)};
|
|
64
|
+
console.log(JSON.stringify({config:readNotifyConfig(process.env),sent:notify({key:'k'},{env:process.env})}));`],
|
|
65
|
+
{env:{...process.env,CM_WORKFLOW_HOME:h.dir},encoding:'utf8',timeout:5000,killSignal:'SIGKILL'});
|
|
66
|
+
assert.equal(child.error,undefined,'reading notify.json made the runtime wait');
|
|
67
|
+
assert.equal(child.status,0,child.stderr);
|
|
68
|
+
return JSON.parse(child.stdout);
|
|
69
|
+
}
|
|
70
|
+
const OFF={config:null,sent:{sent:false,reason:'off'}};
|
|
71
|
+
const unreadable=(h,reason)=>assert.match(h.log(),new RegExp(`config - key=- off invalid_config unreadable_${reason}\\n$`));
|
|
72
|
+
|
|
73
|
+
test('runtime read: notify.json that is a symlink is never read, even to a valid config; a normal file still is',{skip:!posix},t=>{
|
|
74
|
+
const h=home(t);const file=path.join(h.dir,'notify.json'),real=path.join(h.dir,'real-config.json');
|
|
75
|
+
fs.writeFileSync(real,JSON.stringify(CONFIG));fs.rmSync(file);fs.symlinkSync(real,file);
|
|
76
|
+
assert.deepEqual(probe(h),OFF);unreadable(h,'not_regular_file');assert.equal(h.rows().length,0);
|
|
77
|
+
// A dangling link is a link too: refused and logged, not treated as "missing".
|
|
78
|
+
const dangling=home(t);fs.rmSync(path.join(dangling.dir,'notify.json'));fs.symlinkSync(path.join(dangling.dir,'nowhere.json'),path.join(dangling.dir,'notify.json'));
|
|
79
|
+
assert.deepEqual(probe(dangling),OFF);unreadable(dangling,'not_regular_file');
|
|
80
|
+
// The same content as a regular file reads exactly as before.
|
|
81
|
+
fs.rmSync(file);fs.writeFileSync(file,JSON.stringify(CONFIG));
|
|
82
|
+
assert.deepEqual(probe(h).config,PARSED);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('runtime read: a FIFO at notify.json is refused at once, never waited on',{skip:!posix},t=>{
|
|
86
|
+
const h=home(t);const file=path.join(h.dir,'notify.json');
|
|
87
|
+
fs.rmSync(file);assert.equal(spawnSync('mkfifo',['-m','600',file]).status,0);
|
|
88
|
+
assert.deepEqual(probe(h),OFF);unreadable(h,'not_regular_file');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('runtime read: notify.json over 64 KiB is refused; exactly 64 KiB is still read',{skip:!posix},t=>{
|
|
92
|
+
const json=JSON.stringify(CONFIG),pad=n=>json+' '.repeat(n-Buffer.byteLength(json));
|
|
93
|
+
const over=home(t);fs.writeFileSync(path.join(over.dir,'notify.json'),pad(64*1024+1));
|
|
94
|
+
assert.deepEqual(probe(over),OFF);unreadable(over,'too_large');
|
|
95
|
+
const exact=home(t);fs.writeFileSync(path.join(exact.dir,'notify.json'),pad(64*1024));
|
|
96
|
+
assert.deepEqual(probe(exact).config,PARSED);assert.equal(exact.log(),'');
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('runtime read: a missing file stays silent, a directory is a logged off, a BOM file behaves as before (not_json)',{skip:!posix},t=>{
|
|
100
|
+
const missing=home(t);fs.rmSync(path.join(missing.dir,'notify.json'));
|
|
101
|
+
assert.deepEqual(probe(missing),OFF);assert.equal(missing.log(),'');
|
|
102
|
+
const dir=home(t);fs.rmSync(path.join(dir.dir,'notify.json'));fs.mkdirSync(path.join(dir.dir,'notify.json'));
|
|
103
|
+
assert.deepEqual(probe(dir),OFF);unreadable(dir,'not_regular_file');
|
|
104
|
+
// Same as the plain read it replaces: the BOM is not stripped, JSON.parse rejects it.
|
|
105
|
+
const bom=home(t);fs.writeFileSync(path.join(bom.dir,'notify.json'),'\uFEFF'+JSON.stringify(CONFIG));
|
|
106
|
+
assert.deepEqual(probe(bom),OFF);assert.match(bom.log(),/config - key=- off invalid_config not_json\n$/);
|
|
107
|
+
// Invalid UTF-8 never throws; it is just an invalid file.
|
|
108
|
+
const bad=home(t);fs.writeFileSync(path.join(bad.dir,'notify.json'),Buffer.from([0x7b,0xff,0xfe,0x7d]));
|
|
109
|
+
assert.deepEqual(probe(bad),OFF);assert.match(bad.log(),/off invalid_config not_json\n$/);
|
|
110
|
+
});
|
|
111
|
+
|
|
53
112
|
test('message is bounded and built only from the structured fields',()=>{
|
|
54
113
|
const long='x'.repeat(2000);
|
|
55
114
|
const message=buildNotifyMessage({...fields('k'),workflow:long,project:'/very/secret/path/'+long,runId:long,task:long,
|
|
@@ -60,10 +119,168 @@ test('message is bounded and built only from the structured fields',()=>{
|
|
|
60
119
|
for(const forbidden of ['DIFF-CONTENT','LOG-CONTENT','SECRET','push.env','/srv/','/very/secret','~/secret','\0'])
|
|
61
120
|
assert(!message.body.includes(forbidden)&&!message.title.includes(forbidden),forbidden);
|
|
62
121
|
assert.match(message.body,/<路径>/);
|
|
63
|
-
const short=buildNotifyMessage(fields('k'),{now:NOW});
|
|
122
|
+
const short=buildNotifyMessage(fields('k'),{now:NOW,timeZone:'Asia/Shanghai'});
|
|
64
123
|
assert.equal(short.title,'CM cm-fix 需要人处理 · demo-app');
|
|
65
|
-
assert.
|
|
66
|
-
assert.
|
|
124
|
+
assert.equal(short.body,'下一步:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
125
|
+
assert.doesNotMatch(short.body,/运行:|run-1|CM 不会自动继续/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('done shows only project, task and local time; empty fields are left out',()=>{
|
|
129
|
+
const done=buildNotifyMessage(fields('k',{event:'done',stage:'run_done',code:'run_done',nextAction:'建议在新会话里开始下一个任务'}),
|
|
130
|
+
{now:NOW,timeZone:'Asia/Shanghai'});
|
|
131
|
+
assert.equal(done.title,'CM cm-fix 流程已结束 · demo-app');
|
|
132
|
+
assert.equal(done.body,'项目:demo-app\n任务:T-001\n时间:16:00');
|
|
133
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'done',task:null}),{now:NOW,timeZone:'UTC'}).body,'项目:demo-app\n时间:08:00');
|
|
134
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai',event:'waiting'},{now:NOW,timeZone:'America/New_York'}).body,'流程:cm-ai\n时间:04:00');
|
|
135
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai'},{now:Date.parse('2026-10-08T16:05:00.000Z'),timeZone:'Asia/Shanghai'}).body,'流程:cm-ai\n时间:00:05');
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
test('without an injected time zone the clock follows the process TZ',()=>{
|
|
139
|
+
const script=`import {buildNotifyMessage} from ${JSON.stringify(new URL('../runtime/js/notify.mjs',import.meta.url).href)};
|
|
140
|
+
process.stdout.write(buildNotifyMessage({workflow:'cm-ai',event:'done',project:'/p/demo'},{now:${NOW}}).body);`;
|
|
141
|
+
for(const [tz,clock] of [['Asia/Shanghai','16:00'],['UTC','08:00'],['America/Los_Angeles','01:00']]){
|
|
142
|
+
const run=spawnSync(process.execPath,['--input-type=module','-e',script],{encoding:'utf8',env:{...process.env,TZ:tz}});
|
|
143
|
+
assert.equal(run.status,0,run.stderr);assert.equal(run.stdout,`项目:demo\n时间:${clock}`);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Optional notify.json `text`. Expected strings below are written out by hand
|
|
148
|
+
// from the default layout, not computed by the code under test.
|
|
149
|
+
const EVENTS=[['done','流程已结束'],['waiting','等待会话应答'],['idle','疑似空转'],['idle_waiting','在等你'],
|
|
150
|
+
['dead','宿主已退出未收尾'],['stuck','需要人处理'],[undefined,'需要人处理']];
|
|
151
|
+
test('custom text: without `text` (or with an empty one) every event is byte-identical to the default',()=>{
|
|
152
|
+
const at={now:NOW,timeZone:'Asia/Shanghai'};
|
|
153
|
+
for(const [event,headline] of EVENTS){
|
|
154
|
+
const base=buildNotifyMessage(fields('k',{event}),at);
|
|
155
|
+
assert.equal(base.title,`CM cm-fix ${headline} · demo-app`,String(event));
|
|
156
|
+
assert.equal(base.body,event==='done'?'项目:demo-app\n任务:T-001\n时间:16:00'
|
|
157
|
+
:'下一步:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
158
|
+
for(const text of [{},DEFAULT_NOTIFY_TEXT,null,normalizeNotifyText({}).text])
|
|
159
|
+
assert.deepEqual(buildNotifyMessage(fields('k',{event}),{...at,text}),base,`${event} ${JSON.stringify(text)}`);
|
|
160
|
+
}
|
|
161
|
+
const plainConfig=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true']}));
|
|
162
|
+
assert.deepEqual(plainConfig,{config:{command:['/bin/true'],waitMs:600000,checkWaitMs:2700000,idleMs:2700000}});
|
|
163
|
+
assert.equal(Object.hasOwn(plainConfig.config,'text'),false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('custom text: prefix, headlines, field order (runId included) and labels',()=>{
|
|
167
|
+
const at={now:NOW,timeZone:'Asia/Shanghai'};
|
|
168
|
+
const text={titlePrefix:'【工作流】',headlines:{done:'完工',waiting:'等你回话',idle:'没动静',idle_waiting:'该你了',dead:'宿主没了',default:'卡住了'},
|
|
169
|
+
fields:{default:['code','runId','time'],done:['time','task']},labels:{code:'代码',runId:'编号',time:'时刻',task:'工单'}};
|
|
170
|
+
const parsed=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text}));
|
|
171
|
+
assert.equal(parsed.textReason,undefined);
|
|
172
|
+
const custom=parsed.config.text;
|
|
173
|
+
const want={done:'完工',waiting:'等你回话',idle:'没动静',idle_waiting:'该你了',dead:'宿主没了',stuck:'卡住了'};
|
|
174
|
+
for(const [event,headline] of Object.entries(want)){
|
|
175
|
+
const message=buildNotifyMessage(fields('k',{event}),{...at,text:custom});
|
|
176
|
+
assert.equal(message.title,`【工作流】 cm-fix ${headline} · demo-app`);
|
|
177
|
+
assert.equal(message.body,event==='done'?'时刻:16:00\n工单:T-001':'代码:checks_not_passed\n编号:run-1\n时刻:16:00');
|
|
178
|
+
}
|
|
179
|
+
// Partial text: only what is given changes; an empty prefix drops it from the title.
|
|
180
|
+
const partial=buildNotifyMessage(fields('k'),{...at,text:{titlePrefix:'',labels:{nextAction:'先做'}}});
|
|
181
|
+
assert.equal(partial.title,'cm-fix 需要人处理 · demo-app');
|
|
182
|
+
assert.equal(partial.body,'先做:核对 reason 后恢复原运行\n项目:demo-app\n流程:cm-fix\n任务:T-001\n阶段:blocked\n原因:checks_not_passed\n时间:16:00');
|
|
183
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'waiting'}),{...at,text:{headlines:{waiting:'等'}}}).title,'CM cm-fix 等 · demo-app');
|
|
184
|
+
assert.equal(buildNotifyMessage(fields('k',{event:'idle'}),{...at,text:{headlines:{waiting:'等'}}}).title,'CM cm-fix 疑似空转 · demo-app');
|
|
185
|
+
// Empty field values are still left out under a custom order.
|
|
186
|
+
assert.equal(buildNotifyMessage({workflow:'cm-ai'},{...at,text:{fields:{default:['runId','workflow','time']}}}).body,'流程:cm-ai\n时间:16:00');
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
test('custom text strings are cleaned like field values: paths redacted, control characters removed, each capped',()=>{
|
|
190
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
191
|
+
const text=normalizeNotifyText({titlePrefix:'CM\u0007/Users/example/secret',
|
|
192
|
+
headlines:{default:'卡住\n见/srv/private/push.env\u001b[31m'},labels:{nextAction:'C:\\Users\\example\\a.txt\u0000下一步',project:'~/proj',code:'\\\\srv\\share\\x'}}).text;
|
|
193
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
194
|
+
for(const forbidden of ['/Users','example\\','secret','/srv/','push.env','~/proj','\\\\srv','\u0007','\u001b','\u0000','\n见'])
|
|
195
|
+
assert(!message.title.includes(forbidden)&&!message.body.split('\n').map(line=>line.split(':')[0]).join('|').includes(forbidden),JSON.stringify(forbidden));
|
|
196
|
+
assert.equal(message.title,'CM <路径> cm-fix 卡住 见<路径> [31m · demo-app');
|
|
197
|
+
assert.equal(message.body.split('\n')[0],'<路径> 下一步:核对 reason 后恢复原运行');
|
|
198
|
+
assert.match(message.body,/\n<路径>:demo-app\n/);
|
|
199
|
+
assert.match(message.body,/\n<路径>:checks_not_passed\n/);
|
|
200
|
+
// Caps: prefix 16, headline 24, label 12 characters (… included); title 60, body 500.
|
|
201
|
+
const long=normalizeNotifyText({titlePrefix:'前'.repeat(40),headlines:{default:'标'.repeat(40)},labels:{nextAction:'签'.repeat(40)}}).text;
|
|
202
|
+
assert.equal(long.titlePrefix,'前'.repeat(15)+'…');assert.equal(long.headlines.default,'标'.repeat(23)+'…');
|
|
203
|
+
assert.equal(long.labels.nextAction,'签'.repeat(11)+'…');
|
|
204
|
+
const huge='x'.repeat(2000);
|
|
205
|
+
const big=buildNotifyMessage({...fields('k'),workflow:huge,project:huge,runId:huge,task:huge,stage:huge,code:huge,nextAction:huge},
|
|
206
|
+
{...at,text:{...long,fields:{default:['nextAction','runId','project','workflow','task','stage','code','time']}}});
|
|
207
|
+
assert.equal(Array.from(big.title).length,NOTIFY_LIMITS.titleChars);
|
|
208
|
+
assert(Array.from(big.body).length<=NOTIFY_LIMITS.bodyChars);
|
|
209
|
+
assert.match(big.body,/^签{11}…:x{199}…\n/);
|
|
210
|
+
assert.match(big.body,/\n运行:x{63}…\n/);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test('custom text loses bidi and zero-width characters; a string left with nothing visible is invalid',()=>{
|
|
214
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
215
|
+
const hidden=['','','','','','','','','','','','',
|
|
216
|
+
'','','','','','','\u{e0041}'];
|
|
217
|
+
const text=normalizeNotifyText({titlePrefix:`C${hidden.join('')}M`,headlines:{default:`卡住了`},
|
|
218
|
+
labels:{code:'原因',task:'工单'}}).text;
|
|
219
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
220
|
+
for(const char of hidden)assert(!message.title.includes(char)&&!message.body.includes(char),`U+${char.codePointAt(0).toString(16)}`);
|
|
221
|
+
assert.equal(message.title,'CM cm-fix 卡住了 · demo-app');
|
|
222
|
+
assert.match(message.body,/\n工单:T-001\n/);assert.match(message.body,/\n原因:checks_not_passed\n/);
|
|
223
|
+
// Nothing visible left: the whole text is invalid and the default text is used.
|
|
224
|
+
for(const [value,reason] of [[{headlines:{default:''}},'headlines'],[{labels:{code:' '}},'labels'],
|
|
225
|
+
[{titlePrefix:''},'title_prefix'],[{titlePrefix:' '},'title_prefix'],[{headlines:{done:'̀'}},'headlines']]){
|
|
226
|
+
assert.equal(normalizeNotifyText(value).reason,reason,JSON.stringify(value));
|
|
227
|
+
assert.equal(parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text:value})).textReason,reason);
|
|
228
|
+
assert.deepEqual(buildNotifyMessage(fields('k'),{...at,text:value}),buildNotifyMessage(fields('k'),at));
|
|
229
|
+
}
|
|
230
|
+
// Field values are not part of the text layer: the default path is unchanged.
|
|
231
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'T-1'}),at).body.split('\n')[3],'任务:T-1');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test('custom text redacts absolute paths even when letters touch them; field values keep the shared rule',()=>{
|
|
235
|
+
const at={now:NOW,timeZone:'UTC'};
|
|
236
|
+
for(const [raw,want] of [['see/Users/example/key','see<路径>'],['seeC:\\Users\\example\\key','see<路径>'],['seeC:/Users/example/key','see<路径>'],
|
|
237
|
+
['see\\\\srv\\share\\key','see<路径>'],['see~/proj/key','see<路径>'],['卡在/srv/a,再看','卡在<路径>,再看'],
|
|
238
|
+
['x1/etc/passwd y','x1<路径> y'],['CI/CD','CI<路径>'],['停\u0007/tmp/a','停 <路径>'],['停\u200b/tmp/a','停<路径>'],
|
|
239
|
+
['相对 a\\b 保留','相对 a\\b 保留']]){
|
|
240
|
+
const text=normalizeNotifyText({headlines:{default:raw},labels:{code:raw}}).text;
|
|
241
|
+
assert.equal(text.headlines.default,want,raw);assert.equal(text.labels.code,want.slice(0,12),raw);
|
|
242
|
+
const message=buildNotifyMessage(fields('k'),{...at,text});
|
|
243
|
+
assert.equal(message.title,`CM cm-fix ${want} · demo-app`,raw);
|
|
244
|
+
for(const leak of ['/Users','Users\\','\\\\srv','/srv','~/proj','/etc','/tmp'])assert(!message.title.includes(leak)&&!message.body.includes(leak),`${raw} ${leak}`);
|
|
245
|
+
}
|
|
246
|
+
// The shared rule for field values (and so the default text) is unchanged.
|
|
247
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'see/Users/example/key'}),at).body.split('\n')[3],'任务:see/Users/example/key');
|
|
248
|
+
assert.equal(buildNotifyMessage(fields('k',{task:'见 /Users/example/key'}),at).body.split('\n')[3],'任务:见 <路径>');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
test('invalid text falls back to the default text with one text_config log line; notices stay on',async t=>{
|
|
252
|
+
const bad=[[null,'text'],['标题','text'],[[],'text'],[{subject:'x'},'text_key'],[{titlePrefix:7},'title_prefix'],
|
|
253
|
+
[{titlePrefix:'\u0007'},'title_prefix'],[{headlines:{stuck:'x'}},'headlines'],[{headlines:{done:''}},'headlines'],
|
|
254
|
+
[{headlines:{done:'\u0001\u0002'}},'headlines'],[{headlines:'x'},'headlines'],[{labels:{secret:'x'}},'labels'],
|
|
255
|
+
[{labels:{task:3}},'labels'],[{fields:{default:['nextAction','diff']}},'fields'],[{fields:{default:[]}},'fields'],
|
|
256
|
+
[{fields:{default:['task','task']}},'fields'],[{fields:{stuck:['task']}},'fields'],[{fields:{done:'task'}},'fields'],
|
|
257
|
+
[{fields:{done:['toString']}},'fields']];
|
|
258
|
+
for(const [text,reason] of bad){
|
|
259
|
+
const parsed=parseNotifyConfig(JSON.stringify({version:1,command:['/bin/true'],text}));
|
|
260
|
+
assert.equal(parsed.reason,undefined,JSON.stringify(text));assert.equal(parsed.textReason,reason,JSON.stringify(text));
|
|
261
|
+
assert.equal(parsed.config.text,undefined);assert.deepEqual(parsed.config.command,['/bin/true']);
|
|
262
|
+
assert.deepEqual(buildNotifyMessage(fields('k'),{now:NOW,timeZone:'UTC',text}),buildNotifyMessage(fields('k'),{now:NOW,timeZone:'UTC'}));
|
|
263
|
+
}
|
|
264
|
+
// End to end: the typo does not silence the notice, it goes out in the default text, and notify.log says why once.
|
|
265
|
+
const h=home(t,{config:{text:{fields:{default:['nextAction','diff']}}}});
|
|
266
|
+
assert.equal(readNotifyConfig(h.env).text,undefined);
|
|
267
|
+
assert.deepEqual(notify(fields('typo'),{env:h.env,now:NOW}),{sent:true,reason:'launched'});
|
|
268
|
+
assert(await h.until(()=>h.rows().length===1));
|
|
269
|
+
assert.equal(h.rows()[0].title,'CM cm-fix 需要人处理 · demo-app');
|
|
270
|
+
assert.match(h.rows()[0].body,/^下一步:核对 reason 后恢复原运行\n项目:demo-app\n/);
|
|
271
|
+
readNotifyConfig(h.env);
|
|
272
|
+
const lines=h.log().split('\n').filter(line=>line.includes('text_config'));
|
|
273
|
+
assert.equal(lines.length,1,h.log());assert.match(lines[0],/ config - key=- default_text text_config fields$/);
|
|
274
|
+
assert.doesNotMatch(h.log(),/off invalid_config/);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
test('custom text reaches the command in CM_NOTIFY_TITLE/BODY and the stdin JSON',async t=>{
|
|
278
|
+
const h=home(t,{config:{text:{titlePrefix:'提醒',headlines:{default:'卡住了'},fields:{default:['task','code']},labels:{task:'工单'}}}});
|
|
279
|
+
assert.equal(notify(fields('custom'),{env:h.env,now:NOW}).sent,true);
|
|
280
|
+
assert(await h.until(()=>h.rows().length===1));
|
|
281
|
+
const [row]=h.rows();
|
|
282
|
+
assert.equal(row.title,'提醒 cm-fix 卡住了 · demo-app');assert.equal(row.body,'工单:T-001\n原因:checks_not_passed');
|
|
283
|
+
assert.equal(row.stdin.title,row.title);assert.equal(row.stdin.body,row.body);assert.equal(row.stdin.runId,'run-1');
|
|
67
284
|
});
|
|
68
285
|
|
|
69
286
|
test('sends through env and stdin once per key; the same key within 6 hours is skipped',async t=>{
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
// P1-4 (O02, O05/O06): a recorded answer the host then refused can be discarded
|
|
2
|
+
// and asked again under the same pending operation (real prd-4b8e48aa shape:
|
|
3
|
+
// change-mode prd_generate); one interrupted or unpublishable prd_review attempt
|
|
4
|
+
// can be abandoned with an explicit flag and reason, releasing the gate claim
|
|
5
|
+
// for a fresh independent review (real prd-29b5f91e shape: a split review that
|
|
6
|
+
// came back self-degraded for an independent request). A recorded review that
|
|
7
|
+
// would publish is never abandoned.
|
|
8
|
+
import test,{after} from 'node:test';
|
|
9
|
+
import assert from 'node:assert/strict';
|
|
10
|
+
import fs from 'node:fs';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import os from 'node:os';
|
|
13
|
+
import {spawn} from 'node:child_process';
|
|
14
|
+
import {once} from 'node:events';
|
|
15
|
+
import {createInterface} from 'node:readline';
|
|
16
|
+
import {fileURLToPath} from 'node:url';
|
|
17
|
+
import {inspectPrdReview} from './cm-prd-review-gate.mjs';
|
|
18
|
+
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
19
|
+
|
|
20
|
+
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-home-'));
|
|
21
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
22
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
23
|
+
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
24
|
+
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
25
|
+
const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08 | v1 | original |\n';
|
|
26
|
+
const docs=()=>[
|
|
27
|
+
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
28
|
+
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
29
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
30
|
+
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |','| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')
|
|
31
|
+
+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
32
|
+
function fixture(t){const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gaps-')));
|
|
33
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));fs.mkdirSync(path.join(dir,'docs'));fs.mkdirSync(path.join(dir,'mirror'));
|
|
34
|
+
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic guide');fs.mkdirSync(path.join(dir,'1.guide'));
|
|
35
|
+
for(const doc of docs())fs.writeFileSync(path.join(dir,'1.guide',doc.path),doc.content,{mode:0o600});return dir;}
|
|
36
|
+
async function client(t,dir,respond,{session,change=true,review=false,abandon=false}={}){
|
|
37
|
+
const child=spawn(process.execPath,[path.join(root,'scripts/cm-prd-host.mjs'),'serve','--skill-dir',path.join(root,'skills/cm-prd'),
|
|
38
|
+
'--project',dir,'--specs',dir,'--runtime','codex','--allow-log-write','--allow-spec-write',
|
|
39
|
+
...(change?['--change','1.guide']:[]),...(session?['--session',session]:[]),
|
|
40
|
+
...(review?['--allow-review-write','--allow-disposition-write','--host-context','synthetic-author']:[]),
|
|
41
|
+
...(abandon?['--allow-review-abandon']:[])],
|
|
42
|
+
{env:{...process.env,CM_WORKFLOW_LOG_HOME:path.join(dir,'mirror')},stdio:['pipe','pipe','pipe']});
|
|
43
|
+
t.after(()=>{if(child.exitCode===null)child.kill();});let error='',sessionId,seq=0;
|
|
44
|
+
child.stderr.on('data',bytes=>error+=bytes);const pending=new Map();let readyResolve,readyReject;
|
|
45
|
+
const ready=new Promise((yes,no)=>{readyResolve=yes;readyReject=no;});
|
|
46
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
47
|
+
createInterface({input:child.stdout}).on('line',line=>{const message=JSON.parse(line);
|
|
48
|
+
if(message.type==='host_ready'){sessionId=message.sessionId;readyResolve();}
|
|
49
|
+
else if(message.type==='host_request')Promise.resolve().then(()=>respond(message,child)).then(result=>{
|
|
50
|
+
if(result!==undefined)send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,result});
|
|
51
|
+
}).catch(readyReject);
|
|
52
|
+
else if(message.requestId&&pending.has(message.requestId)){pending.get(message.requestId)(message);pending.delete(message.requestId);}
|
|
53
|
+
});
|
|
54
|
+
child.on('close',code=>{if(!sessionId)readyReject(Error(error));for(const resolve of pending.values())resolve({closed:code,error});pending.clear();});
|
|
55
|
+
await ready;
|
|
56
|
+
return {stderr:()=>error,request:async(operation,fields={})=>{const requestId=`test-${++seq}`;return new Promise(resolve=>{
|
|
57
|
+
pending.set(requestId,resolve);send({requestId,operation,...fields});});},
|
|
58
|
+
close:async()=>{send({type:'host_close',sessionId});const [code]=await once(child,'close');assert.equal(code,0,error);}};
|
|
59
|
+
}
|
|
60
|
+
const stateOf=(dir,runId)=>JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-sessions',runId,'state.json'),'utf8'));
|
|
61
|
+
const generate=payload=>{const all=revised(),full=payload.phase==='change_tasks';
|
|
62
|
+
return {status:full?'draft':'documents',summary:'Add example',features:[{directory:'1.guide',
|
|
63
|
+
documents:all.filter(doc=>full||doc.path==='requirements.md'||payload.phase==='change_design'&&doc.path==='design.md'),
|
|
64
|
+
...(full?{testCasesReason:'no_observable_behavior'}:{})}],removed:[]};};
|
|
65
|
+
|
|
66
|
+
test('O02: a recorded prd_generate answer the host refused is discarded and asked again',{timeout:30000},async t=>{
|
|
67
|
+
const dir=fixture(t);let bad=true,generated=0;
|
|
68
|
+
const respond=({kind,payload})=>{
|
|
69
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'Add example',openQuestions:[]};
|
|
70
|
+
assert.equal(kind,'prd_generate');generated++;
|
|
71
|
+
// The refused shape: recorded first, validated after (features missing).
|
|
72
|
+
return bad?{status:'documents',summary:'Add example',removed:[]}:generate(payload);
|
|
73
|
+
};
|
|
74
|
+
let c=await client(t,dir,respond);
|
|
75
|
+
assert.equal((await c.request('start',{text:'Add example'})).result.stage,'change_requirements');
|
|
76
|
+
assert.ok((await c.request('advance',{text:'Requirements'})).error,'the refused answer fails the operation');
|
|
77
|
+
const {runId}=(await c.request('status')).result;await c.close();
|
|
78
|
+
let state=stateOf(dir,runId);const recorded=state.active.calls.at(-1);
|
|
79
|
+
assert.equal(recorded.kind,'prd_generate');assert.ok(Object.hasOwn(recorded,'result'));
|
|
80
|
+
c=await client(t,dir,respond,{session:runId});
|
|
81
|
+
// Before: a plain resume replays the same refused answer forever.
|
|
82
|
+
assert.ok((await c.request('resume',{resolution:null})).error);
|
|
83
|
+
assert.equal((await c.request('advance',{text:'again'})).result.reason,'prd_operation_recovery_required');
|
|
84
|
+
const resolution={callId:recorded.callId,requestDigest:recorded.requestDigest,discard:true,evidence:'会话答复缺 features,被宿主拒收'};
|
|
85
|
+
// prd_review / binding / evidence guards.
|
|
86
|
+
assert.equal((await c.request('resume',{resolution:{...resolution,requestDigest:'wrong'}})).result.reason,'prd_recovery_binding');
|
|
87
|
+
assert.equal((await c.request('resume',{resolution:{...resolution,evidence:' '}})).result.reason,'prd_recovery_evidence_required');
|
|
88
|
+
bad=false;
|
|
89
|
+
const reply=await c.request('resume',{resolution});
|
|
90
|
+
assert.equal(reply.result?.stage,'change_design',JSON.stringify(reply)+c.stderr());
|
|
91
|
+
assert.equal(generated,2,'asked again under the same pending operation');
|
|
92
|
+
state=stateOf(dir,runId);
|
|
93
|
+
assert.equal(state.active,null);assert.equal(state.discardedAnswers.length,1);
|
|
94
|
+
assert.deepEqual([state.discardedAnswers[0].kind,state.discardedAnswers[0].callId,state.discardedAnswers[0].operation],
|
|
95
|
+
['prd_generate',recorded.callId,'advance']);
|
|
96
|
+
await c.close();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('O05/O06: an unpublishable recorded split review is abandoned with --allow-review-abandon, then reviewed afresh',{timeout:40000},async t=>{
|
|
100
|
+
const dir=fixture(t);let reviews=0,degraded=true,conflict=false;
|
|
101
|
+
const respond=({kind,payload})=>{
|
|
102
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
103
|
+
if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
|
|
104
|
+
...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
|
|
105
|
+
if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
|
|
106
|
+
checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
|
|
107
|
+
assert.equal(kind,'prd_review');reviews++;
|
|
108
|
+
if(conflict)fs.mkdirSync(path.join(dir,'.reviews/prd-new-guide-split-r1.md'));
|
|
109
|
+
const result={verdict:'approved',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic no findings'};
|
|
110
|
+
// The prd-29b5f91e shape: an independent request answered self-degraded with a degradedReason.
|
|
111
|
+
return degraded?{reviewer:'self-degraded',contextId:'synthetic-author',independent:false,at:'2026-09-08T00:00:00.000Z',
|
|
112
|
+
result,degradedReason:'Synthetic reviewer unavailable'}
|
|
113
|
+
:{reviewer:'codex-subagent',contextId:'synthetic-independent',independent:true,at:'2026-09-08T00:00:00.000Z',result};
|
|
114
|
+
};
|
|
115
|
+
let c=await client(t,dir,respond,{change:false,review:true});
|
|
116
|
+
await c.request('start',{text:'New guide'});await c.request('advance',{text:'Draft'});await c.request('advance',{text:'Check'});
|
|
117
|
+
await c.request('save_draft');
|
|
118
|
+
const runId=(await c.request('status')).result.runId;
|
|
119
|
+
const initial=await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'});
|
|
120
|
+
assert.equal(initial.result.reviewState.status,'review_unknown',JSON.stringify(initial));
|
|
121
|
+
await c.close();
|
|
122
|
+
const gateArgs={stage:'split',feature:'new-guide',evidence:path.join(dir,'.reviews/prd-new-guide-split-r1.md'),
|
|
123
|
+
receipt:path.join(dir,'.reviews/prd-new-guide-split-disposition.json')};
|
|
124
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'dispatch_unknown');
|
|
125
|
+
const call=stateOf(dir,runId).active.calls.find(item=>item.kind==='prd_review');
|
|
126
|
+
const resolution={callId:call.callId,requestDigest:call.requestDigest,abandonReview:true,evidence:'独立审查回成了 self-degraded,原结果不可发布'};
|
|
127
|
+
// Without the explicit flag the claim stays.
|
|
128
|
+
c=await client(t,dir,respond,{session:runId,change:false,review:true});
|
|
129
|
+
assert.equal((await c.request('resume',{resolution})).result.reason,'prd_review_abandon_not_enabled');await c.close();
|
|
130
|
+
c=await client(t,dir,respond,{session:runId,change:false,review:true,abandon:true});
|
|
131
|
+
const abandoned=await c.request('resume',{resolution});
|
|
132
|
+
assert.equal(abandoned.result?.recovery,null,JSON.stringify(abandoned)+c.stderr());
|
|
133
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'dispatch_once');
|
|
134
|
+
const record=JSON.parse(fs.readFileSync(path.join(dir,'.reviews/prd-new-guide-split-dispatch-abandoned-1.json'),'utf8'));
|
|
135
|
+
assert.deepEqual([record.status,record.call_id,record.reason],['abandoned',call.callId,resolution.evidence]);
|
|
136
|
+
assert.equal(stateOf(dir,runId).abandonedReviews.length,1);
|
|
137
|
+
// A fresh independent review is claimed, dispatched and published as the review evidence.
|
|
138
|
+
degraded=false;
|
|
139
|
+
const fresh=await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'});
|
|
140
|
+
assert.equal(fresh.result.reviewState.status,'review_recorded',JSON.stringify(fresh));
|
|
141
|
+
assert.equal(reviews,2);assert.equal(fs.existsSync(path.join(dir,'.reviews/prd-new-guide-split-r2.md')),false);
|
|
142
|
+
assert.equal(inspectPrdReview(gateArgs).outcome,'resume_disposition');
|
|
143
|
+
await c.close();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('O05/O06: a recorded review that would publish is never abandoned',{timeout:40000},async t=>{
|
|
147
|
+
const dir=fixture(t);let conflicted=false;
|
|
148
|
+
const respond=({kind,payload})=>{
|
|
149
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'New documentation',sourcePaths:['docs/input.md'],openQuestions:[]};
|
|
150
|
+
if(kind==='prd_generate')return {status:'draft',summary:'New guide',features:[{name:'new-guide',documents:docs().map(doc=>({
|
|
151
|
+
...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]};
|
|
152
|
+
if(kind==='prd_self_check')return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
|
|
153
|
+
checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic original context check']}))}))};
|
|
154
|
+
// A valid independent review whose publication fails (the evidence path is taken).
|
|
155
|
+
if(!conflicted){conflicted=true;fs.mkdirSync(path.join(dir,'.reviews/prd-new-guide-split-r1.md'));}
|
|
156
|
+
return {reviewer:'codex-subagent',contextId:'synthetic-independent',independent:true,at:'2026-09-08T00:00:00.000Z',
|
|
157
|
+
result:{verdict:'approved',packageDigest:payload.package.packageDigest,examinedPaths:payload.examinedPaths,findings:[],summary:'Synthetic no findings'}};
|
|
158
|
+
};
|
|
159
|
+
let c=await client(t,dir,respond,{change:false,review:true,abandon:true});
|
|
160
|
+
await c.request('start',{text:'New guide'});await c.request('advance',{text:'Draft'});await c.request('advance',{text:'Check'});
|
|
161
|
+
await c.request('save_draft');
|
|
162
|
+
const runId=(await c.request('status')).result.runId;
|
|
163
|
+
assert.equal((await c.request('final_review',{stage:'split',feature:'2.new-guide',mode:'independent'})).result.reviewState.status,'review_unknown');
|
|
164
|
+
const call=stateOf(dir,runId).active.calls.find(item=>item.kind==='prd_review');
|
|
165
|
+
const before=stateOf(dir,runId);
|
|
166
|
+
const refused=await c.request('resume',{resolution:{callId:call.callId,requestDigest:call.requestDigest,abandonReview:true,evidence:'想换一个审查'}});
|
|
167
|
+
assert.equal(refused.result.reason,'prd_review_result_publishable');
|
|
168
|
+
assert.deepEqual(stateOf(dir,runId),before);
|
|
169
|
+
assert.equal(fs.readdirSync(path.join(dir,'.reviews')).some(name=>name.includes('dispatch-abandoned')),false);
|
|
170
|
+
await c.close();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('O02: at most two discards per call kind in a session; prd_review and prd_correct are never discarded',async t=>{
|
|
174
|
+
const dir=fixture(t),session=openPrdSession({specs:dir,sessionId:'prd-discard-cap',identity:{entry:{fixture:true},runtime:'codex'}});
|
|
175
|
+
try{
|
|
176
|
+
session.begin({requestId:'one',operation:'advance',text:'x'},null);
|
|
177
|
+
const discard=call=>session.discardAnswer({callId:call.callId,requestDigest:call.requestDigest,discard:true,evidence:'被宿主拒收'});
|
|
178
|
+
for(let index=0;index<2;index++){
|
|
179
|
+
await session.call('prd_generate',{n:index},new AbortController().signal,async()=>({bad:true}));
|
|
180
|
+
discard(session.state.active.calls.at(-1));
|
|
181
|
+
}
|
|
182
|
+
await session.call('prd_generate',{n:3},new AbortController().signal,async()=>({bad:true}));
|
|
183
|
+
assert.throws(()=>discard(session.state.active.calls.at(-1)),{code:'prd_answer_discard_limit'});
|
|
184
|
+
assert.equal(session.state.discardedAnswers.length,2);
|
|
185
|
+
}finally{session.close();}
|
|
186
|
+
const other=openPrdSession({specs:dir,sessionId:'prd-discard-review',identity:{entry:{fixture:true},runtime:'codex'}});
|
|
187
|
+
try{
|
|
188
|
+
other.begin({requestId:'two',operation:'final_review',stage:'split',feature:'1.guide',mode:'independent'},null);
|
|
189
|
+
await other.call('prd_review',{package:{packageDigest:'0'.repeat(64)}},new AbortController().signal,async()=>({reviewer:'x'}));
|
|
190
|
+
const call=other.state.active.calls[0];
|
|
191
|
+
assert.throws(()=>other.discardAnswer({callId:call.callId,requestDigest:call.requestDigest,discard:true,evidence:'x'}),{code:'prd_review_recovery_required'});
|
|
192
|
+
}finally{other.close();}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test('O05/O06: the gate finishes a release interrupted after the abandoned record, without a new record or slot',async t=>{
|
|
196
|
+
const {claimPrdReview,abandonPrdReviewAttempt}=await import('./cm-prd-review-gate.mjs');
|
|
197
|
+
const dir=fixture(t),reviews=path.join(dir,'.reviews');fs.mkdirSync(reviews,{mode:0o700});
|
|
198
|
+
const args={stage:'split',feature:'guide',evidence:path.join(reviews,'prd-guide-split-r1.md'),receipt:path.join(reviews,'prd-guide-split-disposition.json')};
|
|
199
|
+
const dispatch=path.join(reviews,'prd-guide-split-dispatch.json');
|
|
200
|
+
for(const [index,call] of ['call-1','call-2'].entries()){
|
|
201
|
+
claimPrdReview({...args,package_sha256:String(index+1).repeat(64)});
|
|
202
|
+
const claim=fs.readFileSync(dispatch);
|
|
203
|
+
assert.equal(abandonPrdReviewAttempt({...args,call_id:call,reason:'原审查不可用'}).outcome,'abandoned');
|
|
204
|
+
// Simulate the crash window: the record is durable, the claim is back.
|
|
205
|
+
fs.writeFileSync(dispatch,claim,{mode:0o600});
|
|
206
|
+
assert.equal(inspectPrdReview(args).outcome,'dispatch_unknown');
|
|
207
|
+
const resumed=abandonPrdReviewAttempt({...args,call_id:call,reason:'原审查不可用'});
|
|
208
|
+
assert.deepEqual([resumed.outcome,resumed.abandoned],['release_completed',index+1]);
|
|
209
|
+
assert.equal(inspectPrdReview(args).outcome,'dispatch_once');
|
|
210
|
+
}
|
|
211
|
+
assert.deepEqual(fs.readdirSync(reviews).filter(name=>name.includes('abandoned')).sort(),
|
|
212
|
+
['prd-guide-split-dispatch-abandoned-1.json','prd-guide-split-dispatch-abandoned-2.json']);
|
|
213
|
+
// A different call on a new claim still meets the cap.
|
|
214
|
+
claimPrdReview({...args,package_sha256:'3'.repeat(64)});
|
|
215
|
+
assert.throws(()=>abandonPrdReviewAttempt({...args,call_id:'call-3',reason:'x'}),{code:'prd_review_abandon_limit'});
|
|
216
|
+
});
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -79,7 +79,7 @@ function load(){
|
|
|
79
79
|
catch(e){fail('准入或配置无效',e.code??e.message);}
|
|
80
80
|
if(admission.status!=='ready'&&!(plan.session&&admission.mode==='change'&&admission.reason==='feature_missing'))
|
|
81
81
|
fail('准入失败',admission.reason??admission.status);
|
|
82
|
-
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--execution-optimizations','--allow-spec-write','--allow-review-write','--allow-disposition-write'].includes(p)))
|
|
82
|
+
if(!Array.isArray(plan.permissions??[])||!(plan.permissions??[]).every(p=>['--execution-optimizations','--allow-spec-write','--allow-review-write','--allow-disposition-write','--allow-review-abandon'].includes(p)))
|
|
83
83
|
stop(2,'permissions 只能包含宿主支持的写入开关');
|
|
84
84
|
if(new Set(plan.permissions??[]).size!==(plan.permissions??[]).length)stop(2,'permissions 不可重复');
|
|
85
85
|
if(plan.predecessor&&!fs.existsSync(resolve(plan.predecessor)))stop(2,`predecessor 文件不存在: ${resolve(plan.predecessor)}`);
|
|
@@ -137,14 +137,25 @@ function load(){
|
|
|
137
137
|
if(operation==='resume'){
|
|
138
138
|
if(!Object.hasOwn(request,'resolution'))stop(2,'resume 缺少 PLAN.request.resolution(null 或绑定的回执)');
|
|
139
139
|
if(request.resolution!==null){
|
|
140
|
-
const v=request.resolution;exact(v,['callId','requestDigest','result','evidence','abandon'],'resolution');
|
|
140
|
+
const v=request.resolution;exact(v,['callId','requestDigest','result','evidence','abandon','discard','abandonReview'],'resolution');
|
|
141
141
|
const pending=state.active.calls.find(c=>c.callId===v.callId);
|
|
142
|
-
|
|
142
|
+
// discard: re-ask the last recorded answer the host refused (its answer file is preflighted below).
|
|
143
|
+
if(v.discard===true){
|
|
144
|
+
if(!pending||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)||Object.hasOwn(v,'result')
|
|
145
|
+
||!Object.hasOwn(pending,'result')||state.active.calls.at(-1)!==pending||['prd_review','prd_correct'].includes(pending.kind))
|
|
146
|
+
stop(2,'discard 只能作废最后一个已记录且被拒的应答(不含 prd_review、prd_correct),需要 callId/requestDigest/evidence');
|
|
147
|
+
}else if(v.abandonReview===true){
|
|
148
|
+
if(!pending||pending.kind!=='prd_review'||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)||Object.hasOwn(v,'result')
|
|
149
|
+
||!plan.permissions?.includes('--allow-review-write')||!plan.permissions?.includes('--allow-review-abandon'))
|
|
150
|
+
stop(2,'abandonReview 需要 prd_review 的 callId/requestDigest/evidence,以及 --allow-review-write 与 --allow-review-abandon');
|
|
151
|
+
}else if(!pending||pending.requestDigest!==v.requestDigest||!nonempty(v.evidence)
|
|
143
152
|
||Object.hasOwn(pending,'result')||(v.abandon===true?Object.hasOwn(v,'result'):!Object.hasOwn(v,'result')))
|
|
144
153
|
stop(2,'resume 缺少有效 callId/requestDigest/result/evidence 绑定');
|
|
145
154
|
if(v.abandon===true&&state.active.calls.some(c=>c.kind==='prd_review'))stop(2,'prd_review 不可 abandon');
|
|
155
|
+
// O03: a late original result for execution evidence cannot be relayed from a static file;
|
|
156
|
+
// abandon the operation and send it again, so the evidence is produced afresh (live runner / contextChecks).
|
|
146
157
|
if(v.abandon!==true&&['prd_materials','prd_self_check'].includes(pending.kind))
|
|
147
|
-
stop(2,`resume 的 ${pending.kind} 是执行证据,不能从静态 resolution.result
|
|
158
|
+
stop(2,`resume 的 ${pending.kind} 是执行证据,不能从静态 resolution.result 应答;改用 resolution {callId,requestDigest,abandon:true,evidence} 放弃原操作,再重发同一操作(${pending.kind==='prd_materials'?'PLAN.liveEvidence 实时读取材料':'PLAN.contextChecks 重新执行检查'})`);
|
|
148
159
|
}
|
|
149
160
|
}
|
|
150
161
|
if(operation==='replace_inputs'){
|
|
@@ -170,12 +181,14 @@ function load(){
|
|
|
170
181
|
asks.push('prd_materials');asks.push('prd_analyze');}
|
|
171
182
|
}
|
|
172
183
|
if(operation==='final_review')asks.push('prd_review');
|
|
184
|
+
if(operation==='resume'&&request.resolution?.discard===true)
|
|
185
|
+
asks.push(state.active.calls.find(c=>c.callId===request.resolution.callId).kind);
|
|
173
186
|
if(operation==='correct_findings')asks.push('prd_correct');
|
|
174
187
|
if(operation==='prepare_summary')asks.push('prd_summary');
|
|
175
188
|
if(operation==='review_disposition'&&request.stage==='split'&&request.decisions.some(d=>d.status==='applied'))asks.push('prd_self_check');
|
|
176
189
|
if(operation==='resume'&&request.resolution===null){
|
|
177
190
|
const pending=state.active.calls.find(c=>!Object.hasOwn(c,'result'));
|
|
178
|
-
if(pending)stop(2,`resume 尚缺原调用结果:${pending.kind} ${pending.callId} ${pending.requestDigest}
|
|
191
|
+
if(pending)stop(2,`resume 尚缺原调用结果:${pending.kind} ${pending.callId} ${pending.requestDigest};找到原回执就填 resolution.result,找不到且不含 prd_review 时用 abandon:true 放弃后重发原操作`);
|
|
179
192
|
}
|
|
180
193
|
let live;
|
|
181
194
|
try{live=driverLiveEvidence(plan,{base,protectedRoots:[project,specs],allowedKinds:['prd_materials']});}
|
|
@@ -177,3 +177,18 @@ test('real host unknown call resumes with its original callId and requestDigest'
|
|
|
177
177
|
assert.equal(resumed.status,0,resumed.stderr);assert.equal(resumed.json.result.stage,'analysis_ready');
|
|
178
178
|
assert.equal(JSON.parse(fs.readFileSync(f.store(session))).active,null);
|
|
179
179
|
});
|
|
180
|
+
|
|
181
|
+
// O03: a late original result for execution evidence is never relayed from a static
|
|
182
|
+
// file; the driver names the exit (abandon, then send the operation again).
|
|
183
|
+
test('resume with a static result for pending self-check evidence points to abandon and a fresh run',t=>{
|
|
184
|
+
const f=fixture(t);f.write('analyze.json',analyzed);
|
|
185
|
+
const started=f.drive('start');assert.equal(started.status,0,started.stderr);
|
|
186
|
+
const runId=started.json.result.runId,store=f.store(runId),state=JSON.parse(fs.readFileSync(store,'utf8'));
|
|
187
|
+
state.active={request:{requestId:'drive',operation:'advance',text:'Check'},before:state.checkpoint,
|
|
188
|
+
calls:[{kind:'prd_self_check',callId:'call-1',requestDigest:'0'.repeat(64),payload:{}}]};
|
|
189
|
+
fs.writeFileSync(store,JSON.stringify(state),{mode:0o600});
|
|
190
|
+
const run=f.drive('resume',{session:runId,request:{resolution:{callId:'call-1',requestDigest:'0'.repeat(64),result:{},evidence:'late'}}});
|
|
191
|
+
assert.equal(run.status,2);assert.match(run.stderr,/abandon:true/);assert.match(run.stderr,/contextChecks/);
|
|
192
|
+
const missing=f.drive('resume',{session:runId,request:{resolution:null}});
|
|
193
|
+
assert.equal(missing.status,2);assert.match(missing.stderr,/abandon:true 放弃后重发原操作/);
|
|
194
|
+
});
|