@aibyzero/cm-workflow 0.16.8 → 0.17.0
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 +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- 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 +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- 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/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- 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 +53 -9
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -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-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -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 +629 -121
- 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-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- 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 +80 -10
- 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 +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- 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 +71 -10
- 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 +89 -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 +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -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 +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +489 -51
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- 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 +23 -5
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- 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 +36 -1
- 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 +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- 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-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- 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-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- 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 +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -63,9 +63,25 @@ function fixture(runtime='codex'){
|
|
|
63
63
|
...(runtime==='claude'?['--runtime','claude']:[])]};
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
// operations are sent one after another (each after the previous reply); the
|
|
67
|
+
// session closes after the last. failDevelop: task ids whose next develop
|
|
68
|
+
// answer is a bare failure after the session wrote (develop_answer_missing).
|
|
69
|
+
// Use an actual first-round review finding for a launch-only revision pause.
|
|
70
|
+
// The synthetic native process still emits its normal bound review observation.
|
|
71
|
+
function requestFirstRevision(f,taskIds,nativeFile=path.join(f.root,'bin',f.runtime)){
|
|
72
|
+
const fake=nativeFile;
|
|
73
|
+
const first=`${JSON.stringify(taskIds)}.includes(data.reviewPackage.identity.taskId)&&data.reviewPackage.identity.attempt===1`;
|
|
74
|
+
const source=fs.readFileSync(fake,'utf8');
|
|
75
|
+
assert(source.includes("verdict:'approved'")&&source.includes('findings:[]'),'native review fixture must retain its known response fields');
|
|
76
|
+
fs.writeFileSync(fake,source
|
|
77
|
+
.replace("verdict:'approved'",`verdict:(${first})?'changes_requested':'approved'`)
|
|
78
|
+
.replace('findings:[]',`findings:(${first})?[{id:'F1',severity:'P2',path:'task'+Number(data.reviewPackage.identity.taskId.slice(-1))+'.mjs',message:'Recheck the export in a revision',evidence:'Synthetic first-round review finding'}]:[]`));
|
|
79
|
+
return taskIds.flatMap(taskId=>['--hold-revision',`1.work/${taskId}`]);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function execute(f,{cancel=false,args=[],operations=[{operation:'advance',requestId:'advance'}],failDevelop=new Set()}={}){
|
|
67
83
|
return new Promise((resolve,reject)=>{
|
|
68
|
-
const child=spawn(process.execPath,[cli,...f.args,...
|
|
84
|
+
const child=spawn(process.execPath,[cli,...f.args,...args],
|
|
69
85
|
{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
70
86
|
let buffer='',stderr='',sessionId;const calls=[],rows=[];
|
|
71
87
|
const timer=setTimeout(()=>{child.kill('SIGTERM');reject(Error('batch host timeout'));},Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
@@ -91,8 +107,9 @@ function execute(f,approvals,{cancel=false}={}){
|
|
|
91
107
|
assert.deepEqual(payload.request.payload.scope,f.batch.tasks[n-1].scope);
|
|
92
108
|
assert.equal(payload.request.payload.specification.task.id,identity.taskId);
|
|
93
109
|
assert.deepEqual(payload.request.payload.specification.sources,buildManifest(f.specsDir));
|
|
94
|
-
const content=`export const value = ${40+n};\n`;
|
|
110
|
+
const content=`export const value = ${40+n};\n${identity.attempt===2?"// Revised after the independent review finding.\n":""}`;
|
|
95
111
|
if(!f.protected)fs.writeFileSync(path.join(cwd,`task${n}.mjs`),content);
|
|
112
|
+
if(failDevelop.delete(identity.taskId)){respond(row,{status:'failed',code:'session_error'});continue;}
|
|
96
113
|
respond(row,{status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
97
114
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},...(f.protected?{edits:
|
|
98
115
|
payload.request.payload.scope.map(file=>({path:file,beforeSha256:payload.expected[file],
|
|
@@ -103,8 +120,7 @@ function execute(f,approvals,{cancel=false}={}){
|
|
|
103
120
|
const result=spawnSync(command[0],command.slice(1));assert.equal(result.status,0);
|
|
104
121
|
return {id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Actual Node syntax check exited 0'};
|
|
105
122
|
});respond(row,checks);
|
|
106
|
-
}else if(row.kind==='qa_assess')respond(row,{
|
|
107
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}});
|
|
123
|
+
}else if(row.kind==='qa_assess')respond(row,{confirmed:true});
|
|
108
124
|
else if(row.kind==='documentation_sync'){
|
|
109
125
|
assert.equal(identity.taskId,'T-002');assert.deepEqual(payload.paths,['README.md']);
|
|
110
126
|
fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Exports 41 and 42\n');respond(row,{status:'completed'});
|
|
@@ -115,12 +131,17 @@ function execute(f,approvals,{cancel=false}={}){
|
|
|
115
131
|
at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')});
|
|
116
132
|
}else assert.fail(`Unexpected ${row.kind}`);
|
|
117
133
|
}
|
|
118
|
-
|
|
134
|
+
const index=operations.findIndex(item=>item.requestId===row.requestId);
|
|
135
|
+
if(index>=0&&(row.result||row.error)){
|
|
136
|
+
if(index+1<operations.length)send(operations[index+1]);else send({type:'host_close',sessionId});
|
|
137
|
+
}
|
|
119
138
|
}catch(error){clearTimeout(timer);child.kill('SIGTERM');reject(error);}
|
|
120
139
|
}
|
|
121
140
|
});
|
|
122
|
-
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,
|
|
123
|
-
|
|
141
|
+
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,calls,rows,
|
|
142
|
+
results:Object.fromEntries(operations.map(item=>[item.requestId,rows.find(row=>row.requestId===item.requestId)?.result])),
|
|
143
|
+
result:rows.find(row=>row.requestId===operations.at(-1).requestId)?.result});});
|
|
144
|
+
send(operations[0]);
|
|
124
145
|
});
|
|
125
146
|
}
|
|
126
147
|
|
|
@@ -138,55 +159,65 @@ test('protected Claude batch uses actual sandbox edits/checks and original two-t
|
|
|
138
159
|
fs.writeFileSync(protection,JSON.stringify({timeoutMs:5000,checkCommands:[{id:'syntax',command:[process.execPath,'-e',
|
|
139
160
|
"const fs=require('node:fs'),a=require('node:assert/strict');a.throws(()=>fs.writeFileSync('specs/1.work/tasks.md','bad'));a.throws(()=>fs.writeFileSync('AGENTS.md','bad'));for(const p of fs.readdirSync('.').filter(p=>/^task.*mjs$/.test(p)))a.match(fs.readFileSync(p,'utf8'),/export const value = 4[12];/);"]}]}));
|
|
140
161
|
f.args.push('--protected-conversation-config',protection);
|
|
141
|
-
const result=await execute(f
|
|
162
|
+
const result=await execute(f);
|
|
142
163
|
assert.equal(result.code,0,result.stderr);assert.equal(result.result.state,'run_done',JSON.stringify(result.result));
|
|
143
164
|
assert.deepEqual(result.calls,['T-001:develop','T-001:qa_assess','T-002:develop','T-002:qa_assess','T-002:documentation_inspect']);
|
|
144
165
|
assert.equal(fs.readFileSync(path.join(nested,'1.work/tasks.md'),'utf8').match(/\[x\]/g).length,2);
|
|
145
|
-
const resume=await execute(f
|
|
166
|
+
const resume=await execute(f);assert.equal(resume.result.state,'run_done');assert.deepEqual(resume.calls,['T-002:documentation_inspect']);
|
|
146
167
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
147
168
|
});
|
|
148
169
|
|
|
149
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves
|
|
170
|
+
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI preserves held review revisions and reaches one original run_done without duplicate completion`,async()=>{
|
|
150
171
|
const f=fixture(runtime);
|
|
151
172
|
try{
|
|
152
|
-
const
|
|
153
|
-
|
|
173
|
+
const bundle=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
174
|
+
bundle.workflows['1.work/T-001'].qa.criticalPaths={payment:['task1.mjs']};
|
|
175
|
+
fs.writeFileSync(f.config,JSON.stringify(bundle));
|
|
176
|
+
const held=requestFirstRevision(f,['T-002']);
|
|
177
|
+
const first=await execute(f,{args:held});assert.equal(first.code,0,first.stderr);
|
|
178
|
+
assert.equal(first.result.identity.taskId,'T-002');assert.equal(first.result.state,'changes_requested');
|
|
179
|
+
assert.equal(first.result.identity.attempt,2);assert.equal(first.result.code,'revision_answer_required');
|
|
154
180
|
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-002'));
|
|
155
181
|
assert.deepEqual(first.calls,['T-001:develop','T-001:check','T-001:check','T-001:qa_assess',
|
|
156
182
|
'T-002:develop','T-002:documentation_sync','T-002:check']);
|
|
157
183
|
const original=fs.readFileSync(f.config,'utf8'),changed=JSON.parse(original);
|
|
158
184
|
changed.workflows['1.work/T-002'].documentationPaths=[];
|
|
159
185
|
fs.writeFileSync(f.config,JSON.stringify(changed));
|
|
160
|
-
const drift=await execute(f
|
|
186
|
+
const drift=await execute(f);
|
|
161
187
|
assert.equal(drift.result.outcome,'blocked');assert.deepEqual(drift.calls,[]);
|
|
162
188
|
fs.writeFileSync(f.config,original);
|
|
163
189
|
if(runtime==='claude'){
|
|
164
190
|
const saved=[...f.args];f.args[f.args.length-1]='codex';
|
|
165
|
-
const wrongRuntime=await execute(f
|
|
191
|
+
const wrongRuntime=await execute(f);assert.equal(wrongRuntime.result.outcome,'blocked');
|
|
166
192
|
assert.deepEqual(wrongRuntime.calls,[]);f.args=saved;
|
|
167
193
|
}
|
|
168
|
-
const second=await execute(f
|
|
194
|
+
const second=await execute(f);assert.equal(second.code,0,second.stderr);
|
|
169
195
|
assert.equal(second.result.state,'run_done',JSON.stringify(second.result));
|
|
170
|
-
assert.deepEqual(second.calls,['T-002:
|
|
171
|
-
|
|
196
|
+
assert.deepEqual(second.calls,['T-002:develop','T-002:documentation_sync','T-002:check','T-002:check',
|
|
197
|
+
'T-002:qa_assess','T-002:documentation_inspect']);
|
|
198
|
+
const reopened=await execute(f);assert.equal(reopened.code,0,reopened.stderr);
|
|
172
199
|
assert.equal(reopened.result.state,'run_done',JSON.stringify(reopened.result));
|
|
173
200
|
assert.deepEqual(reopened.calls,['T-002:documentation_inspect']);
|
|
174
201
|
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
175
202
|
assert.equal(rows.filter(row=>row.event==='run_done').length,1);
|
|
176
203
|
assert.equal(rows.filter(row=>row.event==='decision'&&row.phase==='batch_handoff').length,1);
|
|
177
204
|
assert.equal(rows.filter(row=>row.event==='test_run'&&row.phase==='start').length,2);
|
|
205
|
+
const taskQa=rows.filter(row=>row.event==='qa'&&row.task==='T-001');
|
|
206
|
+
assert.equal(taskQa.length,1);
|
|
207
|
+
assert.equal(taskQa[0].status,'triggered');
|
|
208
|
+
assert(taskQa[0].reason.split(',').includes('payment'));
|
|
209
|
+
assert.equal(taskQa[0].score,null);
|
|
210
|
+
assert.equal(taskQa[0].changed_files_source,'review_package');
|
|
178
211
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
179
212
|
});
|
|
180
213
|
|
|
181
|
-
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable
|
|
214
|
+
for(const runtime of ['codex','claude'])test(`${runtime} batch CLI cancellation remains durable`,async()=>{
|
|
182
215
|
const f=fixture(runtime);
|
|
183
216
|
try{
|
|
184
|
-
const
|
|
185
|
-
assert.equal(bad.status,1);assert(bad.stderr.includes('review_task_mismatch'));assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
186
|
-
const stopped=await execute(f,[],{cancel:true});assert.equal(stopped.code,0,stopped.stderr);
|
|
217
|
+
const stopped=await execute(f,{cancel:true});assert.equal(stopped.code,0,stopped.stderr);
|
|
187
218
|
assert.equal(stopped.result.code,'cancelled');assert.equal(stopped.calls.length,1);
|
|
188
219
|
assert(stopped.rows.some(row=>row.requestId==='status'));
|
|
189
|
-
const reopened=await execute(f
|
|
220
|
+
const reopened=await execute(f);assert.equal(reopened.result.code,'cancelled');assert.deepEqual(reopened.calls,[]);
|
|
190
221
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
191
222
|
});
|
|
192
223
|
|
|
@@ -205,11 +236,12 @@ test('parallel member loopback preflights bind worktree cwd, stop before start a
|
|
|
205
236
|
git(['add','-A']);git(['commit','--allow-empty','-m','synthetic baseline']);
|
|
206
237
|
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
207
238
|
fs.writeFileSync(fail,'fail second member');
|
|
208
|
-
const processFixture=
|
|
239
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
240
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
209
241
|
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
210
242
|
const fs=require('node:fs'),cp=require('node:child_process');
|
|
211
243
|
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
212
|
-
fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
244
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
213
245
|
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
214
246
|
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
215
247
|
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
@@ -217,12 +249,13 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
217
249
|
});
|
|
218
250
|
`,{mode:0o700});
|
|
219
251
|
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
|
|
220
|
-
const failed=await execute(f
|
|
252
|
+
const failed=await execute(f);
|
|
221
253
|
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
222
254
|
assert.equal(failed.result.currentTask,'1.work/T-002');assert.deepEqual(failed.calls,[]);
|
|
223
255
|
assert.equal(probes().length,2);
|
|
224
256
|
fs.unlinkSync(fail);
|
|
225
|
-
const
|
|
257
|
+
const held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
258
|
+
const first=await execute(f,{args:held});assert.equal(first.result.code,'revision_answer_required',JSON.stringify(first));
|
|
226
259
|
assert.equal(first.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(first));
|
|
227
260
|
const directory=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
228
261
|
const receipts=[1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8'));
|
|
@@ -234,17 +267,210 @@ let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',(
|
|
|
234
267
|
assert(probes().includes(cwd));
|
|
235
268
|
}
|
|
236
269
|
assert.equal(probes().length,3);
|
|
237
|
-
const resumed=await execute(f,
|
|
270
|
+
const resumed=await execute(f,{args:held});assert.equal(resumed.result.code,'revision_answer_required');assert.deepEqual(resumed.calls,[]);
|
|
238
271
|
assert.equal(probes().length,3);
|
|
239
272
|
assert.deepEqual([1,2].map(n=>fs.readFileSync(path.join(directory,`preflight-T-00${n}.json`),'utf8')),receipts);
|
|
240
273
|
const stale=JSON.parse(receipts[1]);stale.preflight.config_fingerprint='0'.repeat(64);
|
|
241
274
|
fs.writeFileSync(path.join(directory,'preflight-T-002.json'),JSON.stringify(stale));
|
|
242
|
-
const refreshed=await execute(f,
|
|
275
|
+
const refreshed=await execute(f,{args:held});assert.equal(refreshed.result.code,'revision_answer_required');assert.deepEqual(refreshed.calls,[]);
|
|
243
276
|
assert.equal(probes().length,4);
|
|
244
277
|
assert.equal(fs.readFileSync(path.join(directory,'preflight-T-002.json'),'utf8'),receipts[1]);
|
|
245
278
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
246
279
|
});
|
|
247
280
|
|
|
281
|
+
// 53c385e moved the execution-policy member preflight cache out of .reviews/.execution.
|
|
282
|
+
// A batch that had already cached there (old layout) was refused by the external run
|
|
283
|
+
// guard on every later launch. The exact old cache now moves to the current location
|
|
284
|
+
// and is reused without a new loopback; anything else is refused with a reason.
|
|
285
|
+
function legacyParallelFixture(){
|
|
286
|
+
const f=fixture();f.parallel=true;
|
|
287
|
+
f.batch.tasks=[1,2,3].map(n=>({feature:'1.work',taskId:`T-00${n}`,scope:[`task${n}.mjs`],requirements:['requirements.md']}));
|
|
288
|
+
f.batch.parallel=[['1.work/T-001','1.work/T-002']];
|
|
289
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
|
|
290
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
291
|
+
const original=JSON.parse(fs.readFileSync(f.config,'utf8')).workflows['1.work/T-001'];
|
|
292
|
+
fs.writeFileSync(f.config,JSON.stringify({batch:f.batch,workflows:Object.fromEntries(f.batch.tasks.map(task=>[`1.work/${task.taskId}`,original]))}));
|
|
293
|
+
f.legacy=path.join(f.specsDir,'.reviews','.execution',f.batch.batchId);
|
|
294
|
+
f.current=path.join(f.specsDir,'.reviews','external-preflight',f.batch.batchId);
|
|
295
|
+
f.worktree=taskId=>path.join(f.root,'.cm-worktrees',f.batch.batchId.slice(0,8),taskId);
|
|
296
|
+
return f;
|
|
297
|
+
}
|
|
298
|
+
const legacyReceipt=(f,taskId,extra={})=>JSON.stringify({model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',
|
|
299
|
+
config_fingerprint:configFingerprint({cwd:f.worktree(taskId),model:'fixture',disabledSkills:[]}),prompt_transport:'stdin',
|
|
300
|
+
real_model_requests:0,listener_closed:true,...extra}})+'\n';
|
|
301
|
+
function writeLegacy(f,files){
|
|
302
|
+
fs.mkdirSync(f.legacy,{recursive:true,mode:0o700});fs.chmodSync(f.legacy,0o700);
|
|
303
|
+
for(const [name,bytes] of Object.entries(files))fs.writeFileSync(path.join(f.legacy,name),bytes,{mode:0o600});
|
|
304
|
+
}
|
|
305
|
+
test('execution-policy batch moves an exact old-layout member preflight cache out of the run directory and reuses it',async()=>{
|
|
306
|
+
const f=legacyParallelFixture();
|
|
307
|
+
try{
|
|
308
|
+
const log=path.join(f.root,'probe-cwds.jsonl'),fail=path.join(f.root,'fail-probe');
|
|
309
|
+
fs.writeFileSync(fail,'fail second member');
|
|
310
|
+
const processFixture=path.join(f.root,'native-review-process.mjs');
|
|
311
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),processFixture);
|
|
312
|
+
fs.writeFileSync(path.join(f.root,'bin','codex'),`#!${process.execPath}
|
|
313
|
+
const fs=require('node:fs'),cp=require('node:child_process');
|
|
314
|
+
const args=process.argv.slice(2),cwd=args[args.indexOf('--cd')+1];
|
|
315
|
+
if(args.includes('model_provider="cm_local_tool_preview"'))fs.appendFileSync(${JSON.stringify(log)},JSON.stringify(cwd)+'\\n');
|
|
316
|
+
if(cwd.endsWith('T-002')&&fs.existsSync(${JSON.stringify(fail)}))process.exit(1);
|
|
317
|
+
let input='';process.stdin.on('data',part=>input+=part);process.stdin.on('end',()=>{
|
|
318
|
+
const result=cp.spawnSync(process.execPath,[${JSON.stringify(processFixture)},...args],{input,encoding:'utf8'});
|
|
319
|
+
process.stdout.write(result.stdout??'');process.stderr.write(result.stderr??'');process.exit(result.status??1);
|
|
320
|
+
});
|
|
321
|
+
`,{mode:0o700});
|
|
322
|
+
const probes=()=>fs.readFileSync(log,'utf8').trim().split('\n').length;
|
|
323
|
+
const policy=['--execution-optimizations'];
|
|
324
|
+
// Stop before any member run exists (T-002's loopback fails): T-001 gets a real receipt.
|
|
325
|
+
const failed=await execute(f,{args:policy});
|
|
326
|
+
assert.equal(failed.result.code,'review_preflight_failed',JSON.stringify(failed));
|
|
327
|
+
fs.unlinkSync(fail);
|
|
328
|
+
const real=fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8');
|
|
329
|
+
// Old layout: the same receipts under .reviews/.execution/<batchId>, nothing at the new place.
|
|
330
|
+
const second=JSON.parse(real);second.preflight.config_fingerprint=configFingerprint({cwd:f.worktree('T-002'),model:'fixture',disabledSkills:[]});
|
|
331
|
+
const receipts={'preflight-T-001.json':real,'preflight-T-002.json':JSON.stringify(second)+'\n'};
|
|
332
|
+
assert.deepEqual(Object.keys(JSON.parse(receipts['preflight-T-002.json'])),Object.keys(JSON.parse(real)));
|
|
333
|
+
fs.rmSync(path.dirname(f.current),{recursive:true});writeLegacy(f,receipts);
|
|
334
|
+
const before=probes(),held=requestFirstRevision(f,['T-001','T-002'],processFixture);
|
|
335
|
+
const resumed=await execute(f,{args:[...policy,...held]});
|
|
336
|
+
assert.equal(resumed.code,0,resumed.stderr);
|
|
337
|
+
assert.equal(resumed.result.code,'revision_answer_required',JSON.stringify(resumed.result));
|
|
338
|
+
assert.equal(resumed.calls.filter(call=>call.endsWith(':develop')).length,2,JSON.stringify(resumed.calls));
|
|
339
|
+
assert.equal(probes(),before,'migrated receipts are reused without a new loopback');
|
|
340
|
+
assert(!fs.existsSync(f.legacy));
|
|
341
|
+
for(const [name,bytes] of Object.entries(receipts))assert.equal(fs.readFileSync(path.join(f.current,name),'utf8'),bytes);
|
|
342
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
343
|
+
});
|
|
344
|
+
test('old-layout preflight cache that is not the exact old shape or binding is refused with a reason and left untouched',async()=>{
|
|
345
|
+
const {migrateLegacyPreflightCache}=await import('./cm-ai-batch-host.mjs');
|
|
346
|
+
const review={model:'fixture',preflight:{},disabledSkills:[]};
|
|
347
|
+
const cases=[
|
|
348
|
+
['an unrelated entry',f=>({'preflight-T-001.json':legacyReceipt(f,'T-001'),'state.json':'{}'}),/state\.json/],
|
|
349
|
+
['a non-member task',f=>({'preflight-T-003.json':legacyReceipt(f,'T-003')}),/preflight-T-003\.json/],
|
|
350
|
+
['a stale fingerprint',f=>({'preflight-T-001.json':legacyReceipt(f,'T-001',{config_fingerprint:'0'.repeat(64)})}),/指纹/],
|
|
351
|
+
['another member cwd',f=>({'preflight-T-002.json':legacyReceipt(f,'T-001')}),/指纹/],
|
|
352
|
+
['a reviewer budget',f=>({'preflight-T-001.json':JSON.stringify({...JSON.parse(legacyReceipt(f,'T-001')),timeoutMs:5})}),/不一致/],
|
|
353
|
+
['not a cache',f=>({'preflight-T-001.json':'{"model":"fixture"}'}),/格式/],
|
|
354
|
+
];
|
|
355
|
+
for(const [label,files,pattern] of cases){
|
|
356
|
+
const f=legacyParallelFixture();
|
|
357
|
+
try{
|
|
358
|
+
const content=files(f);writeLegacy(f,content);
|
|
359
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),error=>error.code==='legacy_preflight_cache_invalid'
|
|
360
|
+
&&pattern.test(error.reason)&&/下一步/.test(error.reason)&&error.reason.includes(f.legacy),label);
|
|
361
|
+
assert.deepEqual(fs.readdirSync(f.legacy).sort(),Object.keys(content).sort(),label);
|
|
362
|
+
assert(!fs.existsSync(f.current),label);
|
|
363
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
364
|
+
}
|
|
365
|
+
const f=legacyParallelFixture();
|
|
366
|
+
try{
|
|
367
|
+
// Symlinked file, loose directory mode, and a differing file at the new place: refused.
|
|
368
|
+
writeLegacy(f,{});fs.symlinkSync(path.join(f.root,'review.json'),path.join(f.legacy,'preflight-T-001.json'));
|
|
369
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),/legacy_preflight_cache_invalid/);
|
|
370
|
+
fs.unlinkSync(path.join(f.legacy,'preflight-T-001.json'));
|
|
371
|
+
writeLegacy(f,{'preflight-T-001.json':legacyReceipt(f,'T-001'),'preflight-T-002.json':legacyReceipt(f,'T-002')});
|
|
372
|
+
fs.chmodSync(f.legacy,0o755);
|
|
373
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),/legacy_preflight_cache_invalid/);
|
|
374
|
+
fs.chmodSync(f.legacy,0o700);
|
|
375
|
+
fs.mkdirSync(f.current,{recursive:true,mode:0o700});
|
|
376
|
+
fs.writeFileSync(path.join(f.current,'preflight-T-002.json'),legacyReceipt(f,'T-002',{listener_closed:false}),{mode:0o600});
|
|
377
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),error=>/已有不同内容/.test(error.reason));
|
|
378
|
+
assert.equal(fs.readdirSync(f.legacy).length,2);
|
|
379
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,null,'codex'),/legacy_preflight_cache_invalid/);
|
|
380
|
+
// An identical copy already at the new place drops the old one; the other one moves.
|
|
381
|
+
fs.writeFileSync(path.join(f.current,'preflight-T-002.json'),legacyReceipt(f,'T-002'));
|
|
382
|
+
assert.deepEqual(migrateLegacyPreflightCache(f.batch,review,'codex'),{moved:['preflight-T-001.json'],dropped:['preflight-T-002.json']});
|
|
383
|
+
assert(!fs.existsSync(f.legacy));
|
|
384
|
+
assert.equal(fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8'),legacyReceipt(f,'T-001'));
|
|
385
|
+
// Idempotent: nothing left to migrate.
|
|
386
|
+
assert.deepEqual(migrateLegacyPreflightCache(f.batch,review,'codex'),{moved:[],dropped:[]});
|
|
387
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
388
|
+
});
|
|
389
|
+
// Batch 4 review round 1: the migration commits without overwriting, validates the
|
|
390
|
+
// exact bytes it moves, re-checks both sides before dropping a duplicate and leaves
|
|
391
|
+
// a resumable state when it stops part way. fs is patched at the commit step only.
|
|
392
|
+
test('old-layout preflight migration never overwrites, re-checks what it commits and resumes an interrupted move',async()=>{
|
|
393
|
+
const {migrateLegacyPreflightCache}=await import('./cm-ai-batch-host.mjs');
|
|
394
|
+
const review={model:'fixture',preflight:{},disabledSkills:[]};
|
|
395
|
+
const {linkSync,unlinkSync}=fs;
|
|
396
|
+
const run=async(label,files,patch,check)=>{
|
|
397
|
+
const f=legacyParallelFixture();
|
|
398
|
+
try{
|
|
399
|
+
writeLegacy(f,files(f));
|
|
400
|
+
if(patch.existing){fs.mkdirSync(f.current,{recursive:true,mode:0o700});
|
|
401
|
+
for(const [name,bytes] of Object.entries(patch.existing(f)))fs.writeFileSync(path.join(f.current,name),bytes,{mode:0o600});}
|
|
402
|
+
if(patch.link)fs.linkSync=(...args)=>{patch.link(f,...args);return linkSync.apply(fs,args);};
|
|
403
|
+
if(patch.unlink)fs.unlinkSync=(...args)=>{patch.unlink(f,...args);return unlinkSync.apply(fs,args);};
|
|
404
|
+
let error=null;try{migrateLegacyPreflightCache(f.batch,review,'codex');}catch(cause){error=cause;}
|
|
405
|
+
finally{fs.linkSync=linkSync;fs.unlinkSync=unlinkSync;}
|
|
406
|
+
await check(f,error,label);
|
|
407
|
+
}finally{fs.linkSync=linkSync;fs.unlinkSync=unlinkSync;fs.rmSync(f.root,{recursive:true,force:true});}
|
|
408
|
+
};
|
|
409
|
+
const one=f=>({'preflight-T-001.json':legacyReceipt(f,'T-001')});
|
|
410
|
+
const refused=(error,pattern,label)=>assert(error?.code==='legacy_preflight_cache_invalid'&&pattern.test(error.reason),`${label}: ${error?.code} ${error?.reason}`);
|
|
411
|
+
// A different file appears at the target between planning and commit: not replaced.
|
|
412
|
+
await run('target appears',one,{link:(f,from,to)=>{if(!fs.existsSync(to))fs.writeFileSync(to,'other\n',{mode:0o600});}},(f,error,label)=>{
|
|
413
|
+
refused(error,/在迁移时出现/,label);
|
|
414
|
+
assert.equal(fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8'),'other\n');
|
|
415
|
+
assert.equal(fs.readFileSync(path.join(f.legacy,'preflight-T-001.json'),'utf8'),legacyReceipt(f,'T-001'));
|
|
416
|
+
});
|
|
417
|
+
// The source changes in place (same inode) after validation: the link is undone.
|
|
418
|
+
await run('source rewritten',one,{link:(f,from)=>fs.writeFileSync(from,legacyReceipt(f,'T-001',{listener_closed:false}))},(f,error,label)=>{
|
|
419
|
+
refused(error,/被改动/,label);
|
|
420
|
+
assert(!fs.existsSync(path.join(f.current,'preflight-T-001.json')));
|
|
421
|
+
assert(fs.existsSync(path.join(f.legacy,'preflight-T-001.json')));
|
|
422
|
+
});
|
|
423
|
+
// A duplicate's new copy changes after planning: the old copy is kept.
|
|
424
|
+
await run('duplicate changed',f=>({'preflight-T-001.json':legacyReceipt(f,'T-001'),'preflight-T-002.json':legacyReceipt(f,'T-002')}),
|
|
425
|
+
{existing:f=>({'preflight-T-002.json':legacyReceipt(f,'T-002')}),
|
|
426
|
+
link:f=>fs.writeFileSync(path.join(f.current,'preflight-T-002.json'),legacyReceipt(f,'T-002',{listener_closed:false}))},(f,error,label)=>{
|
|
427
|
+
refused(error,/被改动/,label);
|
|
428
|
+
assert(fs.existsSync(path.join(f.legacy,'preflight-T-002.json')));
|
|
429
|
+
});
|
|
430
|
+
// A stop after the link (both names on one inode) is finished by the next launch.
|
|
431
|
+
await run('interrupted move',one,{unlink:(f,file)=>{if(file.startsWith(f.legacy))throw Object.assign(new Error('crash'),{code:'synthetic_crash'});}},(f,error,label)=>{
|
|
432
|
+
assert.equal(error?.code,'synthetic_crash',label);
|
|
433
|
+
const a=fs.lstatSync(path.join(f.legacy,'preflight-T-001.json')),b=fs.lstatSync(path.join(f.current,'preflight-T-001.json'));
|
|
434
|
+
assert.deepEqual([a.ino,a.nlink],[b.ino,2]);
|
|
435
|
+
assert.deepEqual(migrateLegacyPreflightCache(f.batch,review,'codex'),{moved:['preflight-T-001.json'],dropped:[]});
|
|
436
|
+
assert(!fs.existsSync(f.legacy));
|
|
437
|
+
assert.equal(fs.lstatSync(path.join(f.current,'preflight-T-001.json')).nlink,1);
|
|
438
|
+
assert.equal(fs.readFileSync(path.join(f.current,'preflight-T-001.json'),'utf8'),legacyReceipt(f,'T-001'));
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
// Batch 4 review round 1: the target directory and its parent are checked before any
|
|
442
|
+
// delete or move, also when every old file is a duplicate (nothing to move).
|
|
443
|
+
test('old-layout preflight migration refuses a symlinked target even when every old file is a duplicate',async()=>{
|
|
444
|
+
const {migrateLegacyPreflightCache}=await import('./cm-ai-batch-host.mjs');
|
|
445
|
+
const review={model:'fixture',preflight:{},disabledSkills:[]};
|
|
446
|
+
for(const linked of ['target','parent']){
|
|
447
|
+
const f=legacyParallelFixture();
|
|
448
|
+
try{
|
|
449
|
+
const files={'preflight-T-001.json':legacyReceipt(f,'T-001'),'preflight-T-002.json':legacyReceipt(f,'T-002')};
|
|
450
|
+
writeLegacy(f,files);
|
|
451
|
+
// The real directory holds identical copies; the expected path only links to it.
|
|
452
|
+
const elsewhere=path.join(f.root,'elsewhere'),real=path.join(elsewhere,linked==='target'?'':f.batch.batchId);
|
|
453
|
+
fs.mkdirSync(real,{recursive:true,mode:0o700});fs.chmodSync(elsewhere,0o700);
|
|
454
|
+
for(const [name,bytes] of Object.entries(files))fs.writeFileSync(path.join(real,name),bytes,{mode:0o600});
|
|
455
|
+
if(linked==='target'){fs.mkdirSync(path.dirname(f.current),{recursive:true,mode:0o700});fs.symlinkSync(elsewhere,f.current);}
|
|
456
|
+
else fs.symlinkSync(elsewhere,path.dirname(f.current));
|
|
457
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),
|
|
458
|
+
error=>error.code==='legacy_preflight_cache_invalid'&&/不是权限 0700 的普通目录/.test(error.reason),linked);
|
|
459
|
+
assert.deepEqual(fs.readdirSync(f.legacy).sort(),Object.keys(files).sort(),linked);
|
|
460
|
+
for(const [name,bytes] of Object.entries(files))assert.equal(fs.readFileSync(path.join(f.legacy,name),'utf8'),bytes);
|
|
461
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
462
|
+
}
|
|
463
|
+
// A target copy that breaks the file constraints (mode, links) is refused too.
|
|
464
|
+
const f=legacyParallelFixture();
|
|
465
|
+
try{
|
|
466
|
+
writeLegacy(f,{'preflight-T-001.json':legacyReceipt(f,'T-001')});
|
|
467
|
+
fs.mkdirSync(f.current,{recursive:true,mode:0o700});
|
|
468
|
+
fs.writeFileSync(path.join(f.current,'preflight-T-001.json'),legacyReceipt(f,'T-001'),{mode:0o644});
|
|
469
|
+
assert.throws(()=>migrateLegacyPreflightCache(f.batch,review,'codex'),/legacy_preflight_cache_invalid/);
|
|
470
|
+
assert(fs.existsSync(path.join(f.legacy,'preflight-T-001.json')));
|
|
471
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
472
|
+
});
|
|
473
|
+
|
|
248
474
|
test('provider development grants select worktree runtimes and keep the serial task on protected conversation transport',async()=>{
|
|
249
475
|
const f=fixture();
|
|
250
476
|
try{
|
|
@@ -260,10 +486,10 @@ test('provider development grants select worktree runtimes and keep the serial t
|
|
|
260
486
|
const workerModule=new URL('../runtime/js/cm-ai/codex-config.mjs',import.meta.url).href;
|
|
261
487
|
fs.writeFileSync(stub,`
|
|
262
488
|
import {configFingerprint} from ${JSON.stringify(workerModule)};
|
|
263
|
-
export {readConversationReviewConfiguration,readConversationProtection} from ${JSON.stringify(hostModule)};
|
|
489
|
+
export {readConversationReviewConfiguration,readConversationReviewConfigurationValue,readConversationProtection} from ${JSON.stringify(hostModule)};
|
|
264
490
|
export {parseHostInputLimit,inputLimitReason} from ${JSON.stringify(sessionModule)};
|
|
265
491
|
export const calls=[];export let scheduler;
|
|
266
|
-
export {batchTaskRunId} from ${JSON.stringify(new URL('./cm-ai-batch-run.mjs',import.meta.url).href)};
|
|
492
|
+
export {batchTaskRunId,BATCH_MEMBER_ACTIONS} from ${JSON.stringify(new URL('./cm-ai-batch-run.mjs',import.meta.url).href)};
|
|
267
493
|
export function createConversationExecution(...args){calls.push(args);return {};}
|
|
268
494
|
export async function runReviewPreflight(definition,{model}){return {model,disabledSkills:[],preflight:{passed:true,
|
|
269
495
|
cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:definition.codeProject,model})}};}
|
|
@@ -306,3 +532,49 @@ export async function serveCmAiHost({host}){await host.handle({});}
|
|
|
306
532
|
}
|
|
307
533
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
308
534
|
});
|
|
535
|
+
|
|
536
|
+
// Q24 (real host): a serial member whose develop answer came back as a bare failure
|
|
537
|
+
// after the session wrote stops at develop_redo. The batch host used to accept only
|
|
538
|
+
// advance/status/cancel/reconcile_review, so the batch stayed stuck there. Now the
|
|
539
|
+
// batch host forwards develop_redo to that member's run (same cm-ai entry, one-shot
|
|
540
|
+
// per-member grant) and the next advance redoes the round and finishes the batch.
|
|
541
|
+
test('Q24 batch host recovers a serial member stopped at develop_redo and continues the batch',async()=>{
|
|
542
|
+
const f=fixture();
|
|
543
|
+
try{
|
|
544
|
+
const first=await execute(f,{failDevelop:new Set(['T-001'])});
|
|
545
|
+
assert.equal(first.code,0,first.stderr);
|
|
546
|
+
assert.deepEqual([first.result.state,first.result.code,first.result.pendingAction],['blocked','develop_answer_missing','develop_redo'],JSON.stringify(first.result));
|
|
547
|
+
assert.match(first.result.guidance.nextStep,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(first.calls,['T-001:develop']);
|
|
548
|
+
const redo={operation:'develop_redo',requestId:'redo',taskKey:'1.work/T-001',reason:'会话已停止修改代码'};
|
|
549
|
+
// advance alone never redispatches; the operation needs its per-member grant.
|
|
550
|
+
const refused=await execute(f,{operations:[{operation:'advance',requestId:'advance'},redo]});
|
|
551
|
+
assert.equal(refused.results.advance.pendingAction,'develop_redo');
|
|
552
|
+
assert.deepEqual([refused.result.outcome,refused.result.code],['rejected','batch_member_action_authorization_required']);
|
|
553
|
+
assert.match(refused.result.reason,/--allow-develop-redo 1\.work\/T-001/);assert.deepEqual(refused.calls,[]);
|
|
554
|
+
const bad=spawnSync(process.execPath,[cli,...f.args,'--allow-develop-redo','1.work/T-999'],{env:f.env,encoding:'utf8',timeout:5000});
|
|
555
|
+
assert.equal(bad.status,1);assert.match(bad.stderr,/invalid_arguments/);assert.match(bad.stderr,/FEATURE\/TASK/);
|
|
556
|
+
for(const [flag,code] of [['--revise-qa-config','batch_qa_revision_unavailable'],['--rebind-spec-material','batch_spec_rebind_unavailable']]){
|
|
557
|
+
const unsupported=spawnSync(process.execPath,[cli,...f.args,flag,'x'],{env:f.env,encoding:'utf8',timeout:5000});
|
|
558
|
+
assert.equal(unsupported.status,1);assert.match(unsupported.stderr,new RegExp(code));assert.match(unsupported.stderr,/出口/);
|
|
559
|
+
}
|
|
560
|
+
const recovered=await execute(f,{args:['--allow-develop-redo','1.work/T-001'],
|
|
561
|
+
operations:[redo,{operation:'advance',requestId:'advance'}]});
|
|
562
|
+
assert.equal(recovered.code,0,recovered.stderr);
|
|
563
|
+
assert.deepEqual([recovered.results.redo.outcome,recovered.results.redo.pendingAction,recovered.results.redo.taskKey],
|
|
564
|
+
['recorded','resume','1.work/T-001'],JSON.stringify(recovered.results.redo));
|
|
565
|
+
assert.equal(recovered.result.state,'run_done',JSON.stringify(recovered.result));
|
|
566
|
+
assert.deepEqual(recovered.calls.slice(0,2),['T-001:develop','T-001:check']);
|
|
567
|
+
assert(recovered.calls.includes('T-002:develop'));
|
|
568
|
+
assert.equal(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').match(/\[x\]/g).length,2);
|
|
569
|
+
const {batchTaskRunId}=await import('./cm-ai-batch-run.mjs');
|
|
570
|
+
const records=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',batchTaskRunId(f.batch.batchId,'1.work/T-001'),'state.json'),'utf8')).records;
|
|
571
|
+
assert.equal(records.filter(row=>row.payload.type==='develop-answer-redo').length,1);
|
|
572
|
+
// After cancel the batch stays stopped; a forwarded operation cannot reopen it.
|
|
573
|
+
const g=fixture();
|
|
574
|
+
try{
|
|
575
|
+
const stopped=await execute(g,{cancel:true});assert.equal(stopped.result.code,'cancelled');
|
|
576
|
+
const after=await execute(g,{args:['--allow-develop-redo','1.work/T-001'],operations:[redo]});
|
|
577
|
+
assert.deepEqual([after.result.outcome,after.result.code],['blocked','cancelled']);
|
|
578
|
+
}finally{fs.rmSync(g.root,{recursive:true,force:true});}
|
|
579
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
580
|
+
});
|