@aibyzero/cm-workflow 0.13.3 → 0.15.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 +26 -0
- package/README.md +22 -1
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +2 -0
- package/docs/user-guide.md +3 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +1 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +53 -22
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +4 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +40 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +103 -23
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -4
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +5 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +17 -5
- package/runtime/js/cm-ai/durable-runner-state.mjs +7 -2
- package/runtime/js/cm-ai/effect-contract.mjs +8 -1
- package/runtime/js/cm-ai/execution-store.mjs +25 -5
- package/runtime/js/cm-ai/host-check.mjs +20 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +5 -4
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +43 -21
- package/runtime/js/cm-ai/host-qa-policy.mjs +3 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +41 -3
- package/runtime/js/cm-ai/task-runner.mjs +1 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +2 -1
- package/runtime/js/cm-fix/cause-package.mjs +3 -1
- package/runtime/js/cm-fix/dossier.mjs +7 -2
- package/runtime/js/cm-fix/reproduce.mjs +26 -5
- package/runtime/js/cm-init/draft-generation.mjs +3 -2
- package/runtime/js/cm-init/draft-inspection.mjs +17 -3
- package/runtime/js/cm-init/review-evidence.mjs +1 -1
- package/runtime/js/cm-prd/summary.mjs +6 -8
- package/runtime/js/cm-security/finalize.mjs +164 -0
- package/runtime/js/specs-status.mjs +66 -0
- package/scripts/cm-ai-admission.mjs +46 -7
- package/scripts/cm-ai-admission.test.mjs +50 -0
- package/scripts/cm-ai-batch-host.mjs +72 -10
- package/scripts/cm-ai-batch-host.test.mjs +128 -4
- package/scripts/cm-ai-batch-run.mjs +351 -17
- package/scripts/cm-ai-batch-run.test.mjs +190 -13
- package/scripts/cm-ai-bootstrap.test.mjs +3 -2
- package/scripts/cm-ai-host.mjs +38 -21
- package/scripts/cm-ai-host.test.mjs +68 -4
- package/scripts/cm-ai-nested-execution.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +25 -15
- package/scripts/cm-ai-run.test.mjs +48 -0
- package/scripts/cm-blocked-reason.test.mjs +104 -0
- package/scripts/cm-capability-gate.test.mjs +179 -0
- package/scripts/cm-codex-developer-adapter.test.mjs +70 -0
- package/scripts/cm-fix-cause-package.test.mjs +18 -1
- package/scripts/cm-fix-execution.test.mjs +31 -0
- package/scripts/cm-fix-host-review.test.mjs +2 -1
- package/scripts/cm-fix-host.test.mjs +2 -1
- package/scripts/cm-fix-observation-dossier.test.mjs +2 -0
- package/scripts/cm-fix-qa-source.test.mjs +1 -3
- package/scripts/cm-fix-reproduce.test.mjs +53 -2
- package/scripts/cm-fix-review-recovery.test.mjs +4 -3
- package/scripts/cm-host-check.test.mjs +22 -0
- package/scripts/cm-host-qa-executor.test.mjs +302 -3
- package/scripts/cm-host-qa-policy.test.mjs +34 -0
- package/scripts/cm-init-draft-generation.test.mjs +24 -3
- package/scripts/cm-init-draft-inspection.test.mjs +80 -0
- package/scripts/cm-init-host.mjs +2 -2
- package/scripts/cm-init-host.test.mjs +3 -1
- package/scripts/cm-init-session.test.mjs +37 -0
- package/scripts/cm-log-event.mjs +28 -7
- package/scripts/cm-prd-design-phase.test.mjs +2 -1
- package/scripts/cm-prd-host.test.mjs +3 -2
- package/scripts/cm-prd-session-recovery.test.mjs +5 -4
- package/scripts/cm-security.mjs +12 -4
- package/scripts/cm-security.test.mjs +109 -0
- package/scripts/cm-specs-status.test.mjs +130 -0
- package/scripts/cm-workflow-config.mjs +4 -0
- package/scripts/test-shell-compat.sh +0 -0
- package/skills/cm-ai/references/N1-init.md +20 -15
- package/skills/cm-ai/references/N6-qa-eval.md +9 -4
- package/skills/cm-ai/references/js-host.md +10 -0
- package/skills/cm-fix/SKILL.md +5 -4
- package/skills/cm-fix/references/js-host.md +13 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-init/references/runtime-declaration.md +2 -0
- package/skills/cm-prd/SKILL.md +9 -8
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-security/SKILL.md +11 -6
- package/skills/cm-security/references/scan-contract.md +45 -1
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import {preQaConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attac
|
|
|
10
10
|
import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
11
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
12
12
|
|
|
13
|
-
const usage='cm-ai-run.mjs serve --config
|
|
13
|
+
const usage='cm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
14
14
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
15
15
|
// In-process provenance only; a config flag cannot certify protected callbacks.
|
|
16
16
|
const protectedExecutions=new WeakMap();
|
|
@@ -126,15 +126,22 @@ export async function createCodexExecution(configuration,authority){
|
|
|
126
126
|
|
|
127
127
|
export function readRunDefinition(file){
|
|
128
128
|
const info=fs.lstatSync(file);
|
|
129
|
-
if(!info.isFile()||info.isSymbolicLink()
|
|
129
|
+
if(!info.isFile()||info.isSymbolicLink())fail('invalid_config: not a regular file');
|
|
130
|
+
if(info.size>64*1024)fail('invalid_config: file exceeds 64KiB');
|
|
130
131
|
return validateRunDefinition(JSON.parse(fs.readFileSync(file,'utf8')));
|
|
131
132
|
}
|
|
132
133
|
export function validateRunDefinition(input){
|
|
133
134
|
const value=structuredClone(input);
|
|
134
135
|
const keys=['version','specsDir','codeProject','feature','identity','scope','requirements'];
|
|
135
136
|
if(value&&Object.hasOwn(value,'codeProjects'))keys.push('codeProjects');
|
|
136
|
-
if(!value||typeof value!=='object'
|
|
137
|
-
|
|
137
|
+
if(!value||typeof value!=='object')fail('invalid_config: expected an object');
|
|
138
|
+
const unexpected=Object.keys(value).filter(key=>!keys.includes(key));
|
|
139
|
+
const missing=keys.filter(key=>!Object.hasOwn(value,key));
|
|
140
|
+
if(unexpected.length||missing.length)fail('invalid_config: '+[
|
|
141
|
+
...(unexpected.length?[`unexpected keys ${unexpected.join(',')}`]:[]),
|
|
142
|
+
...(missing.length?[`missing keys ${missing.join(',')}`]:[]),
|
|
143
|
+
].join('; '));
|
|
144
|
+
if(value.version!==1)fail('invalid_config: version must be 1');
|
|
138
145
|
if(typeof value.feature!=='string'||!/^\d+\.[^/\\]+$/.test(value.feature))fail('invalid_feature');
|
|
139
146
|
for(const key of ['specsDir','codeProject']){
|
|
140
147
|
if(typeof value[key]!=='string'||!path.isAbsolute(value[key]))fail('invalid_path');
|
|
@@ -160,15 +167,16 @@ export function validateRunDefinition(input){
|
|
|
160
167
|
return value;
|
|
161
168
|
}
|
|
162
169
|
|
|
163
|
-
export async function openControlRun(definition,mode,execution=null,{rerunUnknownQa=false}={}){
|
|
170
|
+
export async function openControlRun(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,parallelSelection=null}={}){
|
|
164
171
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
165
172
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
166
173
|
const {conversationProtection}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
167
174
|
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
168
|
-
if(typeof rerunUnknownQa!=='boolean'||
|
|
175
|
+
if(typeof rerunUnknownQa!=='boolean'||typeof rerunBlockedQa!=='boolean'||rerunUnknownQa&&rerunBlockedQa
|
|
176
|
+
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
169
177
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
170
178
|
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
171
|
-
const {inspectCmAiAdmission}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
179
|
+
const {inspectCmAiAdmission,matchesCmAiTaskSelection}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
172
180
|
const {captureReviewBaseline}=await import('../runtime/js/cm-ai/review-package.mjs');
|
|
173
181
|
if(execution!==null){
|
|
174
182
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
@@ -199,21 +207,22 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
199
207
|
const {bootstrapConfiguration}=await import('../runtime/js/cm-ai/host-bootstrap.mjs');
|
|
200
208
|
bootstrapConfig=bootstrapConfiguration(execution.bootstrap,{root:codeProject,identity,scope,feature});
|
|
201
209
|
}
|
|
210
|
+
if(parallelSelection!==null)parallelSelection=JSON.parse(JSON.stringify(parallelSelection));
|
|
202
211
|
const selectedRoots=definition.codeProjects?codeProjectPaths(codeProject,resolveCodeProjects(codeProject,definition.codeProjects)):null;
|
|
203
212
|
if(selectedRoots){
|
|
204
213
|
if(!execution||conversationProtection(execution)===null)fail('multi_root_protection_required');
|
|
205
214
|
for(const root of definition.codeProjects){
|
|
206
215
|
const selected=inspectCmAiAdmission({specsDir,codeProject:root});
|
|
207
|
-
if(mode==='create'
|
|
216
|
+
if(mode==='create'&&!matchesCmAiTaskSelection(selected,feature,identity.taskId,parallelSelection))
|
|
208
217
|
return {blocked:selected,close:()=>{}};
|
|
209
218
|
}
|
|
210
219
|
}
|
|
211
220
|
const developer=execution?.documentationSync
|
|
212
221
|
?(await import('../runtime/js/cm-ai/host-documentation.mjs')).withHostDocumentation({developer:execution.developer,
|
|
213
|
-
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope}):execution?.developer;
|
|
222
|
+
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope,parallelSelection}):execution?.developer;
|
|
214
223
|
const admission=inspectCmAiAdmission({specsDir,codeProject});
|
|
215
224
|
if(mode==='create'&&admission.state!=='ready')return {blocked:admission,close:()=>{}};
|
|
216
|
-
if(mode==='create'
|
|
225
|
+
if(mode==='create'&&!matchesCmAiTaskSelection(admission,feature,identity.taskId,parallelSelection))fail('task_selection_mismatch');
|
|
217
226
|
const tasksPath=path.join(specsDir,feature,'tasks.md');
|
|
218
227
|
const featureSlug=feature.replace(/^\d+\./,'');
|
|
219
228
|
const reviewsDir=path.join(specsDir,'.reviews');
|
|
@@ -226,7 +235,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
226
235
|
...(selectedRoots?{codeProjectPaths:selectedRoots}:{})};
|
|
227
236
|
if(mode==='create')captureReviewBaseline(baselineOptions);
|
|
228
237
|
// Definition is data, never an import path, command, grant or executable callback.
|
|
229
|
-
const configMaterial=execution===null?definition:{definition,execution:execution.configuration,
|
|
238
|
+
const configMaterial=execution===null?(parallelSelection===null?definition:{definition,parallelSelection}):{definition,...(parallelSelection===null?{}:{parallelSelection}),execution:execution.configuration,
|
|
230
239
|
...(bootstrapConfig?{bootstrap:bootstrapConfig}:{}),
|
|
231
240
|
...(Object.hasOwn(execution,'developmentAttempt')?{developmentAuthorization:'per-attempt-v1'}:{}),
|
|
232
241
|
...(execution.hostDecisionProvider?{hostDecisionProvider:{version:1,timeoutMs:execution.hostDecisionProvider.timeoutMs}}:{}),
|
|
@@ -263,7 +272,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
263
272
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
264
273
|
// Only the genuine, fingerprint-matching empty initializer can be finished.
|
|
265
274
|
// Never reset/recreate a journal that contains any event.
|
|
266
|
-
if(admission
|
|
275
|
+
if(!matchesCmAiTaskSelection(admission,feature,identity.taskId,parallelSelection))
|
|
267
276
|
fail('initialization_admission_required');
|
|
268
277
|
captureReviewBaseline(baselineOptions);
|
|
269
278
|
runnerMode='create';
|
|
@@ -279,7 +288,7 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
279
288
|
reviewInvocation:execution.reviewInvocation,check:execution.check,
|
|
280
289
|
excludedContexts:execution.excludedContexts,timeoutMs:execution.timeoutMs,
|
|
281
290
|
taskLearning:{feature,hostHandoff:true}})},
|
|
282
|
-
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
291
|
+
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,...(parallelSelection===null?{}:{parallelSelection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
283
292
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
284
293
|
});
|
|
285
294
|
if(attaching||attached){
|
|
@@ -312,8 +321,9 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
312
321
|
if(run.blocked){output.write(JSON.stringify({outcome:'blocked',admission:run.blocked})+'\n');return 1;}
|
|
313
322
|
await serveCmAiHost({host:run.host,input,output});return 0;
|
|
314
323
|
}catch(cause){
|
|
315
|
-
//
|
|
316
|
-
const code=typeof cause.code==='string'
|
|
324
|
+
// Config diagnostics contain field names/reasons, never field values or provider text.
|
|
325
|
+
const code=typeof cause.code==='string'&&(/^[a-z_]+$/.test(cause.code)
|
|
326
|
+
||cause.code.startsWith('invalid_config: '))?cause.code:'control_failed';
|
|
317
327
|
error.write(JSON.stringify({error:{code}})+'\n');return 1;
|
|
318
328
|
}finally{run?.close();}
|
|
319
329
|
}
|
|
@@ -267,6 +267,22 @@ test('control config does not accept executable callbacks or self-reported autho
|
|
|
267
267
|
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
268
268
|
}));
|
|
269
269
|
|
|
270
|
+
test('run definition errors identify unexpected and missing fields through the CLI',()=>fixture(async f=>{
|
|
271
|
+
const {validateRunDefinition}=await import('./cm-ai-run.mjs');
|
|
272
|
+
const missing={...f.definition};delete missing.requirements;
|
|
273
|
+
for(const [definition,code] of [
|
|
274
|
+
[{...f.definition,runtime:'codex'},'invalid_config: unexpected keys runtime'],
|
|
275
|
+
[missing,'invalid_config: missing keys requirements'],
|
|
276
|
+
]){
|
|
277
|
+
assert.throws(()=>validateRunDefinition(definition),error=>error.code===code);
|
|
278
|
+
fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
279
|
+
const result=f.invoke('create',[]);
|
|
280
|
+
assert.equal(result.status,1);
|
|
281
|
+
assert.deepEqual(JSON.parse(result.stderr),{error:{code}});
|
|
282
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
283
|
+
}
|
|
284
|
+
}));
|
|
285
|
+
|
|
270
286
|
for(const operation of ['start','advance'])
|
|
271
287
|
test(`JSONL status and cancel bypass an in-flight real runner effect: ${operation}`, {skip:!platform},()=>fixture(async f=>{
|
|
272
288
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
@@ -370,3 +386,35 @@ test('stalled response backlog is bounded and fails explicitly',async()=>{
|
|
|
370
386
|
input.end(Array.from({length:70},(_,i)=>JSON.stringify(request('status',`status-${i}`))).join('\n')+'\n');
|
|
371
387
|
await rejected;
|
|
372
388
|
});
|
|
389
|
+
|
|
390
|
+
test('trusted parallel selection binds admission, Learning, start and resume fingerprints', {skip:!platform},()=>fixture(async f=>{
|
|
391
|
+
const {openControlRun}=await import('./cm-ai-run.mjs');
|
|
392
|
+
const {inspectCmAiTaskLearningInput}=await import('../runtime/js/cm-ai/cm-ai-context-refresh.mjs');
|
|
393
|
+
const {createCodexDeveloperRun}=await import('../runtime/js/cm-ai/codex-developer-adapter.mjs');
|
|
394
|
+
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
395
|
+
fs.writeFileSync(path.join(f.specsDir,'1.login','tasks.md'),'- [ ] T-001: first\n- [ ] T-002: second\n- [ ] T-003: final\n\n- T-003 依赖 T-001, T-002\n');
|
|
396
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.login'],specFiles:buildManifest(f.specsDir)}));
|
|
397
|
+
const definition={...f.definition,identity:{...identity,taskId:'T-002'}},parallelSelection={version:1,group:['T-001','T-002']};
|
|
398
|
+
const learning={specsDir:f.specsDir,codeProject:f.codeProject,feature:'1.login',identity:definition.identity,applicableAgentFiles:[]};
|
|
399
|
+
assert.throws(()=>inspectCmAiTaskLearningInput(learning),{code:'learning_context_invalid'});
|
|
400
|
+
assert.equal(inspectCmAiTaskLearningInput(learning,{parallelSelection}).identity.taskId,'T-002');
|
|
401
|
+
const execution={configuration:{kind:'selection-fixture'},timeoutMs:2000,excludedContexts:['host'],hostDecision:null,
|
|
402
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.js'),'selected implementation\n');return {status:'succeeded',value:{outcome:'implemented',
|
|
403
|
+
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
404
|
+
check:async()=>[{id:'check',command:['fixture'],outcome:'passed',exitCode:0,evidence:'fixture'}],reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',
|
|
405
|
+
requestedModel:'fixture',allowed:true,available:true,contexts:['review-1','review-2'],
|
|
406
|
+
run:async()=>{throw new Error('no review');}}],
|
|
407
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host'],authorize:()=>{throw new Error('no review');}}};
|
|
408
|
+
await assert.rejects(openControlRun(definition,'create',execution),{code:'task_selection_mismatch'});
|
|
409
|
+
await assert.rejects(openControlRun(definition,'create',execution,{parallelSelection:{version:1,group:['T-001','T-003']}}),{code:'task_selection_mismatch'});
|
|
410
|
+
const direct=createCmAiHost({runner:{root:f.codeProject,identity:definition.identity,scope:['a.js'],requirements:['requirements.md'],
|
|
411
|
+
developer:execution.developer,check:execution.check,commit:async()=>{throw new Error('no commit');},reviewers:[],excludedContexts:['host']},
|
|
412
|
+
entry:{specsDir:f.specsDir,codeProject:f.codeProject,feature:'1.login',identity:definition.identity}});
|
|
413
|
+
assert.equal((await direct.handle({version:1,operation:'start',requestId:'ordinary',identity:definition.identity})).code,'task_mismatch');
|
|
414
|
+
let run=await openControlRun(definition,'create',execution,{parallelSelection});
|
|
415
|
+
const result=await run.host.handle({version:1,operation:'start',requestId:'selected',identity:definition.identity});
|
|
416
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));run.close();
|
|
417
|
+
await assert.rejects(openControlRun(definition,'resume',execution),{code:'fingerprint_mismatch'});
|
|
418
|
+
await assert.rejects(openControlRun(definition,'resume',execution,{parallelSelection:{version:1,group:['T-002','T-003']}}),{code:'fingerprint_mismatch'});
|
|
419
|
+
run=await openControlRun(definition,'resume',execution,{parallelSelection});run.close();
|
|
420
|
+
}));
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
7
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
8
|
+
import {createDeveloperRun} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
9
|
+
import {digest,terminalFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
|
+
import {invalidDeveloperCall,readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
11
|
+
|
|
12
|
+
const reason='等待接口授权\n\tPeer implementation is unavailable';
|
|
13
|
+
async function fixture(value,provider,fn){
|
|
14
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-blocked-reason-')));
|
|
15
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
16
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
17
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
18
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
19
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
20
|
+
fs.writeFileSync(path.join(codeProject,'a.js'),'base\n');
|
|
21
|
+
const identity={repositoryId:'blocked-fixture',runId:'blocked-run',taskId:'T-001',attempt:1};
|
|
22
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:['a.js'],requirements:[]};
|
|
23
|
+
let dispatched=0,terminal,request,run;
|
|
24
|
+
const adapter=createDeveloperRun({provider,requestedModel:'fixture',worker:async()=>{
|
|
25
|
+
dispatched++;return {status:'succeeded',value};
|
|
26
|
+
}});
|
|
27
|
+
const execution={configuration:{kind:'blocked-fixture-v1'},timeoutMs:3000,excludedContexts:['host'],
|
|
28
|
+
hostDecision:{status:'approved'},applicableAgentFiles:[],qaLogHome:path.join(root,'logs'),
|
|
29
|
+
developer:{provider,requestedModel:'fixture',contextId:'author',run:async(r,c)=>{
|
|
30
|
+
request=r;terminal=await adapter(r,c);return terminal;
|
|
31
|
+
}},
|
|
32
|
+
check:()=>assert.fail('blocked must not run checks'),
|
|
33
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',
|
|
34
|
+
allowed:true,available:true,contexts:['review-1','review-2'],run:()=>assert.fail('blocked must not run review')}],
|
|
35
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['host'],authorize:()=>assert.fail('blocked must not authorize review')},
|
|
36
|
+
};
|
|
37
|
+
const statePath=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
38
|
+
const read=()=>JSON.parse(fs.readFileSync(statePath,'utf8'));
|
|
39
|
+
const handle=operation=>run.host.handle({version:1,operation,requestId:operation,identity});
|
|
40
|
+
const close=()=>{run?.close();run=null;};
|
|
41
|
+
const open=async(mode='resume')=>{close();run=await openControlRun(definition,mode,execution);assert(!run.blocked);return run;};
|
|
42
|
+
try{
|
|
43
|
+
await open('create');const status=await handle('start');
|
|
44
|
+
await fn({status,terminal,request,read,handle,open,close,statePath,dispatched:()=>dispatched});
|
|
45
|
+
}finally{close();fs.rmSync(root,{recursive:true,force:true});}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test('blocked reason preserves terminal, call digest and entry blocked/failed with or without reason',async()=>{
|
|
49
|
+
for(const provider of ['codex','claude'])for(const value of [{outcome:'blocked',reason},{outcome:'blocked'}]){
|
|
50
|
+
await fixture(value,provider,async f=>{
|
|
51
|
+
assert.equal(f.terminal.status,'failed');assert.equal(f.terminal.accepted,true);assert.equal(f.terminal.result,null);
|
|
52
|
+
assert.deepEqual([f.status.state,f.status.code],['blocked','failed']);
|
|
53
|
+
const call=f.read().records.at(-1).payload.checkpoint.calls.at(-1);
|
|
54
|
+
assert.equal(call.blockedReason,value.reason);assert.equal(f.terminal.blockedReason,value.reason);
|
|
55
|
+
assert.equal(Object.hasOwn(call,'blockedReason'),Object.hasOwn(value,'reason'));
|
|
56
|
+
assert.equal(Object.hasOwn(f.terminal,'blockedReason'),Object.hasOwn(value,'reason'));
|
|
57
|
+
assert.equal(call.resultDigest,digest(null));assert(!Object.hasOwn(call,'failureResult'));
|
|
58
|
+
assert.equal(invalidDeveloperCall(call),false);
|
|
59
|
+
await f.handle('resume');assert.equal(f.dispatched(),1);
|
|
60
|
+
const base={...f.terminal,blockedReason:reason};
|
|
61
|
+
for(const invalid of ['', ' \n\t',null,1,'x'.repeat(1001),'界'.repeat(334),
|
|
62
|
+
...Array.from({length:32},(_,i)=>i).filter(i=>i!==9&&i!==10).map(i=>'text'+String.fromCharCode(i))])
|
|
63
|
+
assert.throws(()=>terminalFor({...base,blockedReason:invalid},f.request));
|
|
64
|
+
for(const valid of ['x'.repeat(1000),'界'.repeat(333)+'x',' reason\n\t'])
|
|
65
|
+
assert.equal(terminalFor({...base,blockedReason:valid},f.request).blockedReason,valid);
|
|
66
|
+
for(const status of ['succeeded','unknown','cancelled','unavailable','auth_required','permission_denied'])
|
|
67
|
+
assert.throws(()=>terminalFor({...base,status,result:status==='succeeded'?{outcome:'implemented'}:null,
|
|
68
|
+
accepted:!['unavailable','auth_required','permission_denied'].includes(status)},f.request));
|
|
69
|
+
assert.throws(()=>terminalFor(base,{...f.request,role:'reviewer'}));
|
|
70
|
+
assert.throws(()=>terminalFor({...base,result:{code:'invalid_result',reason:'invalid_input'}},f.request));
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
test('blocked reason survives reopen, legacy absence replays and changed reason bytes fail the record chain',async()=>{
|
|
76
|
+
for(const value of [{outcome:'blocked',reason},{outcome:'blocked'}])await fixture(value,'codex',async f=>{
|
|
77
|
+
const original=f.read();await f.open();
|
|
78
|
+
const status=await f.handle('status');assert.deepEqual([status.state,status.code],['blocked','failed']);
|
|
79
|
+
assert.deepEqual(f.read(),original);assert.equal(f.dispatched(),1);
|
|
80
|
+
const checkpoint=original.records.at(-1).payload.checkpoint;
|
|
81
|
+
assert.equal(checkpoint.calls.at(-1).blockedReason,value.reason);
|
|
82
|
+
const replay=readRunnerHistory(original.records,original.records[0].payload.config,3);
|
|
83
|
+
assert.equal(replay.state.calls.at(-1).blockedReason,value.reason);
|
|
84
|
+
if(!Object.hasOwn(value,'reason'))return;
|
|
85
|
+
// Recompute the outer checksum only: rejection must come from the existing record chain.
|
|
86
|
+
f.close();const tampered=structuredClone(original);
|
|
87
|
+
tampered.records.at(-1).payload.checkpoint.calls.at(-1).blockedReason+='!';
|
|
88
|
+
const {revision,...body}=tampered;
|
|
89
|
+
fs.writeFileSync(f.statePath,JSON.stringify({...body,revision:digest(body)}));
|
|
90
|
+
await assert.rejects(f.open(),{code:'store_corrupt'});
|
|
91
|
+
// Even with valid record hashes, replay still enforces the optional field's grammar.
|
|
92
|
+
for(const mutate of [call=>{call.blockedReason=' ';},call=>{call.blockedReason='bad\rtext';},
|
|
93
|
+
call=>{call.blockedReason='界'.repeat(334);},call=>{call.blockedReason=null;},
|
|
94
|
+
call=>{call.terminal='unknown';},call=>{call.failureResult={code:'invalid_result',reason:'invalid_input'};
|
|
95
|
+
call.resultDigest=digest(call.failureResult);},call=>{call.resultDigest=digest(reason);}]){
|
|
96
|
+
const records=structuredClone(original.records);mutate(records.at(-1).payload.checkpoint.calls.at(-1));
|
|
97
|
+
for(let i=0;i<records.length;i++){
|
|
98
|
+
const {digest:checksum,...record}=records[i];record.previousDigest=i?records[i-1].digest:null;
|
|
99
|
+
records[i]={...record,digest:digest(record)};
|
|
100
|
+
}
|
|
101
|
+
assert.throws(()=>readRunnerHistory(records,records[0].payload.config,3));
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
// Launch-time browser capability gate. The host cannot probe whether the
|
|
2
|
+
// launching session can drive a browser; these tests cover the declaration
|
|
3
|
+
// contract only, not any detection claim.
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import test,{after} from 'node:test';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {spawnSync} from 'node:child_process';
|
|
10
|
+
import {fileURLToPath} from 'node:url';
|
|
11
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
+
import {loadConfig} from './cm-workflow-config.mjs';
|
|
13
|
+
|
|
14
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-capability-home-'));
|
|
15
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'user');
|
|
16
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
17
|
+
after(()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
|
|
18
|
+
|
|
19
|
+
const batchCli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
|
|
20
|
+
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
21
|
+
const identity={repositoryId:'gate','runId':'gate-run',taskId:'T-001',attempt:1};
|
|
22
|
+
|
|
23
|
+
function fixture(browserCase,{blocking=true,tests=['logic','commands','browser']}={}){
|
|
24
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-capability-gate-')));
|
|
25
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
26
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
27
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
28
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'- [AC-001]: fixture\n');
|
|
29
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{tests}}));
|
|
30
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
31
|
+
fs.writeFileSync(path.join(specsDir,feature,'test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',
|
|
32
|
+
cases:[{id:'TC-001',kind:browserCase?'browser':'logic',blocking,origin:'user',acIds:['AC-001'],taskIds:['T-001'],
|
|
33
|
+
title:'Synthetic',preconditions:[],steps:['Observe fixture'],expected:['Fixture works'],cleanup:[]}]}));
|
|
34
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),
|
|
35
|
+
JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
36
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
37
|
+
const config=path.join(root,'run.json');
|
|
38
|
+
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,
|
|
39
|
+
scope:['target.mjs'],requirements:['requirements.md']}));
|
|
40
|
+
const workflow=path.join(root,'workflow.json');
|
|
41
|
+
fs.writeFileSync(workflow,JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
|
|
42
|
+
qa:{commands:[{id:'unit',command:[process.execPath,'--version'],caseIds:browserCase?[]:['TC-001']}],
|
|
43
|
+
environment:{kind:'web',carrier:'browser',target:'https://example.invalid/fixture',scope:'local'}}}));
|
|
44
|
+
return {root,specsDir,codeProject,config,workflow,
|
|
45
|
+
args:['serve','--config',config,'--mode','create','--host-context','gate-fixture','--allow-development',
|
|
46
|
+
'--workflow-config',workflow,'--allow-qa']};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const launch=(f,...extra)=>spawnSync(process.execPath,[cli,...f.args,...extra],{encoding:'utf8',timeout:20000,env:{...process.env,NODE_NO_WARNINGS:'1'}});
|
|
50
|
+
function rejected(result,code){
|
|
51
|
+
assert.equal(result.error,undefined);assert.equal(result.status,1,result.stderr);
|
|
52
|
+
assert.deepEqual(JSON.parse(result.stderr),{error:{code}});
|
|
53
|
+
}
|
|
54
|
+
function started(f,...extra){
|
|
55
|
+
const result=launch(f,...extra);
|
|
56
|
+
assert.equal(result.error,undefined);assert.equal(result.status,0,result.stderr);
|
|
57
|
+
const runDir=path.join(f.specsDir,'.reviews','.execution',identity.runId);
|
|
58
|
+
assert(fs.statSync(path.join(runDir,'writer.sqlite')).isFile());
|
|
59
|
+
const state=JSON.parse(fs.readFileSync(path.join(runDir,'state.json'),'utf8'));
|
|
60
|
+
assert.equal(state.version,1);assert.deepEqual(state.identity,{repositoryId:identity.repositoryId,runId:identity.runId});
|
|
61
|
+
return state;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
test('the browser gate fires exactly when the approved contract can select a browser case',()=>{
|
|
65
|
+
const withBrowser=fixture(true);
|
|
66
|
+
try{
|
|
67
|
+
rejected(launch(withBrowser),'browser_capability_required');
|
|
68
|
+
rejected(launch(withBrowser,'--browser-qa','unavailable'),'browser_capability_unavailable');
|
|
69
|
+
rejected(launch(withBrowser,'--browser-qa','sometimes'),'invalid_arguments');
|
|
70
|
+
started(withBrowser,'--browser-qa','available');
|
|
71
|
+
}finally{fs.rmSync(withBrowser.root,{recursive:true,force:true});}
|
|
72
|
+
const withoutBrowser=fixture(false);
|
|
73
|
+
try{
|
|
74
|
+
rejected(launch(withoutBrowser,'--browser-qa','available'),'invalid_arguments');
|
|
75
|
+
started(withoutBrowser);
|
|
76
|
+
}finally{fs.rmSync(withoutBrowser.root,{recursive:true,force:true});}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('resume requires a fresh assertion and reopens the run created by available',()=>{
|
|
80
|
+
const f=fixture(true);
|
|
81
|
+
try{
|
|
82
|
+
const created=started(f,'--browser-qa','available');
|
|
83
|
+
f.args[4]='resume';
|
|
84
|
+
rejected(launch(f),'browser_capability_required');
|
|
85
|
+
rejected(launch(f,'--browser-qa','unavailable'),'browser_capability_unavailable');
|
|
86
|
+
const resumed=started(f,'--browser-qa','available');
|
|
87
|
+
assert.deepEqual(resumed.fingerprints,created.fingerprints);
|
|
88
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
for(const [blocking,tests,applicable] of [
|
|
92
|
+
[false,['logic'],false], [false,['logic','browser'],true], [true,['logic'],true],
|
|
93
|
+
])test(`single-task applicability: blocking=${blocking}, tests=${tests}`,()=>{
|
|
94
|
+
const f=fixture(true,{blocking,tests});
|
|
95
|
+
try{
|
|
96
|
+
// T-001 remains pending: deferral must not remove an applicable capability gate.
|
|
97
|
+
if(applicable){
|
|
98
|
+
rejected(launch(f),'browser_capability_required');
|
|
99
|
+
started(f,'--browser-qa','available');
|
|
100
|
+
}else{
|
|
101
|
+
rejected(launch(f,'--browser-qa','available'),'invalid_arguments');
|
|
102
|
+
started(f);
|
|
103
|
+
}
|
|
104
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function batchFixture(options){
|
|
108
|
+
const f=fixture(true,options),feature='2.browser';
|
|
109
|
+
fs.renameSync(path.join(f.specsDir,'1.work'),path.join(f.specsDir,feature));
|
|
110
|
+
const source=path.join(f.specsDir,feature,'test-cases.json');
|
|
111
|
+
const contract=JSON.parse(fs.readFileSync(source,'utf8'));contract.feature='browser';
|
|
112
|
+
fs.writeFileSync(source,JSON.stringify(contract));
|
|
113
|
+
fs.mkdirSync(path.join(f.specsDir,'1.work'));
|
|
114
|
+
for(const name of ['requirements.md','design.md','tasks.md'])
|
|
115
|
+
fs.copyFileSync(path.join(f.specsDir,feature,name),path.join(f.specsDir,'1.work',name));
|
|
116
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',
|
|
117
|
+
features:['1.work',feature],specFiles:buildManifest(f.specsDir)}));
|
|
118
|
+
const batch={version:1,repositoryId:'gate',batchId:'batch-gate',specsDir:f.specsDir,codeProject:f.codeProject,
|
|
119
|
+
tasks:['1.work',feature].map(feature=>({feature,taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']}))};
|
|
120
|
+
const workflow=JSON.parse(fs.readFileSync(f.workflow,'utf8'));
|
|
121
|
+
fs.writeFileSync(f.config,JSON.stringify({batch,workflows:Object.fromEntries(
|
|
122
|
+
batch.tasks.map(task=>[`${task.feature}/${task.taskId}`,workflow]))}));
|
|
123
|
+
// Intentionally withhold QA authorization: passing the capability gate must
|
|
124
|
+
// reach this exact later error, before any batch Git/provider side effects.
|
|
125
|
+
f.args=['serve','--config',f.config,'--host-context','gate-fixture','--allow-development'];
|
|
126
|
+
return f;
|
|
127
|
+
}
|
|
128
|
+
const launchBatch=(f,...extra)=>spawnSync(process.execPath,[batchCli,...f.args,...extra],{encoding:'utf8',timeout:20000,env:{...process.env,NODE_NO_WARNINGS:'1'}});
|
|
129
|
+
for(const [blocking,tests,applicable] of [
|
|
130
|
+
[false,['logic'],false], [false,['logic','browser'],true], [true,['logic'],true],
|
|
131
|
+
])test(`batch checks the second feature: blocking=${blocking}, tests=${tests}`,()=>{
|
|
132
|
+
const f=batchFixture({blocking,tests});
|
|
133
|
+
try{
|
|
134
|
+
if(applicable){
|
|
135
|
+
rejected(launchBatch(f),'browser_capability_required');
|
|
136
|
+
rejected(launchBatch(f,'--browser-qa','unavailable'),'browser_capability_unavailable');
|
|
137
|
+
rejected(launchBatch(f,'--browser-qa','available'),'qa_authorization_required');
|
|
138
|
+
}else{
|
|
139
|
+
rejected(launchBatch(f,'--browser-qa','available'),'invalid_arguments');
|
|
140
|
+
rejected(launchBatch(f),'qa_authorization_required');
|
|
141
|
+
}
|
|
142
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
for(const [name,contents] of [['JSON','{'],['UTF-8',Buffer.from([0xff])]])
|
|
146
|
+
test(`malformed ${name} test contracts retain a specific error at both entrypoints`,()=>{
|
|
147
|
+
for(const batch of [false,true]){
|
|
148
|
+
const f=batch?batchFixture({}):fixture(true);
|
|
149
|
+
try{
|
|
150
|
+
fs.writeFileSync(path.join(f.specsDir,batch?'2.browser':'1.work','test-cases.json'),contents);
|
|
151
|
+
rejected((batch?launchBatch:launch)(f,'--browser-qa','available'),'test_cases_invalid');
|
|
152
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
test('declaring browser tests requires the role that serves them',()=>{
|
|
157
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-capability-config-')));
|
|
158
|
+
const write=body=>fs.writeFileSync(path.join(root,'.cm-workflow.json'),JSON.stringify(body));
|
|
159
|
+
const base={version:1,runtimes:{available:'codex'},
|
|
160
|
+
roles:{coder:{adapter:'codex-cli',model:'default',source:'subscription'},
|
|
161
|
+
reviewer:{adapter:'codex-cli',model:'default',source:'subscription'},
|
|
162
|
+
browser_qa:{adapter:'browser',model:'none',source:'local'}},
|
|
163
|
+
policies:{tests:['logic','browser']}};
|
|
164
|
+
try{
|
|
165
|
+
write(base);
|
|
166
|
+
assert.deepEqual(loadConfig({projectRoot:root}).policies.tests,['logic','browser']);
|
|
167
|
+
const missing=structuredClone(base);missing.roles.browser_qa={adapter:'local',model:'none',source:'local'};
|
|
168
|
+
write(missing);
|
|
169
|
+
assert.throws(()=>loadConfig({projectRoot:root}),/roles\.browser_qa\.adapter is not browser/);
|
|
170
|
+
const defaultPolicy=structuredClone(missing);delete defaultPolicy.policies;
|
|
171
|
+
write(defaultPolicy);
|
|
172
|
+
assert.throws(()=>loadConfig({projectRoot:root}),/roles\.browser_qa\.adapter is not browser/);
|
|
173
|
+
delete defaultPolicy.roles.browser_qa;write(defaultPolicy);
|
|
174
|
+
assert.equal(loadConfig({projectRoot:root}).roles.browser_qa.adapter,'browser');
|
|
175
|
+
const logicOnly=structuredClone(missing);logicOnly.policies.tests=['logic'];
|
|
176
|
+
write(logicOnly);
|
|
177
|
+
assert.deepEqual(loadConfig({projectRoot:root}).policies.tests,['logic']);
|
|
178
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
179
|
+
});
|
|
@@ -1,9 +1,36 @@
|
|
|
1
1
|
import test from 'node:test';
|
|
2
|
+
import {readFileSync} from 'node:fs';
|
|
3
|
+
import {validateClaudeProposal} from '../runtime/js/cm-ai/worker-claude-developer.mjs';
|
|
2
4
|
import assert from 'node:assert/strict';
|
|
3
5
|
import {requestFor,terminalFor,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
4
6
|
import * as codex from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
5
7
|
import * as claude from '../runtime/js/cm-ai/claude-developer-adapter.mjs';
|
|
6
8
|
import {validateDeveloperValue} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
9
|
+
import {invalidDeveloperCall} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
10
|
+
|
|
11
|
+
test('blocked reason is bounded for both providers while durable failure stays non-retryable',async()=>{
|
|
12
|
+
for(const [provider,create,build] of [
|
|
13
|
+
['codex',codex.createCodexDeveloperRun,codex.buildCodexDeveloperPrompt],
|
|
14
|
+
['claude',claude.createClaudeDeveloperRun,claude.buildClaudeDeveloperPrompt],
|
|
15
|
+
])for(const learning of [false,true]){
|
|
16
|
+
const identity={repositoryId:'test',runId:'run',taskId:'T-001',attempt:1},feature='1.fixture',learningFiles=[];
|
|
17
|
+
const r=requestFor({invocationId:'dev-1',identity,role:'developer',provider,requestedModel:'fixture',contextId:'developer',
|
|
18
|
+
payload:{scope:['src/a.mjs'],requirements:[],priorReview:null,...(learning?{learningInput:{version:1,workflow:'cm-ai',
|
|
19
|
+
phase:'task_learning_input',feature,identity,learningFiles,learningDigest:digest({version:1,feature,identity,files:learningFiles})}}:{})}});
|
|
20
|
+
const value={outcome:'blocked',reason:'等待契约\nExpected stub throws'};
|
|
21
|
+
assert.equal(validateDeveloperValue(value,r).reason,value.reason);
|
|
22
|
+
assert(build(r).includes('A blocked result may include reason'));
|
|
23
|
+
for(const reason of ['x'.repeat(1000),'界'.repeat(333)+'x',''])validateDeveloperValue({...value,reason},r);
|
|
24
|
+
for(const reason of ['x'.repeat(1001),'界'.repeat(334),'NUL\0',12])assert.throws(()=>validateDeveloperValue({...value,reason},r));
|
|
25
|
+
assert.throws(()=>validateDeveloperValue({...value,extra:true},r));
|
|
26
|
+
assert.throws(()=>validateDeveloperValue({...value,outcome:'implemented'},r));
|
|
27
|
+
const run=create({requestedModel:'fixture',worker:async()=>({status:'succeeded',value})});
|
|
28
|
+
const result=await run(r,{signal:new AbortController().signal});
|
|
29
|
+
assert.equal(result.status,'failed');assert.equal(result.result,null);
|
|
30
|
+
assert.equal(invalidDeveloperCall({terminal:result.status}),false);
|
|
31
|
+
assert.throws(()=>terminalFor({...result,result:{code:'developer_blocked',reason:value.reason}},r));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
7
34
|
for(const [provider,createCodexDeveloperRun,buildCodexDeveloperPrompt] of [
|
|
8
35
|
['codex',codex.createCodexDeveloperRun,codex.buildCodexDeveloperPrompt],
|
|
9
36
|
['claude',claude.createClaudeDeveloperRun,claude.buildClaudeDeveloperPrompt],
|
|
@@ -131,3 +158,46 @@ test('structured developer failures cannot broaden reviewer or unknown envelopes
|
|
|
131
158
|
assert.throws(()=>terminalFor({...raw,result:{...raw.result,retryable:true}},dev));
|
|
132
159
|
assert.throws(()=>terminalFor({...raw,result:{code:'made_up',reason:'invalid_input'}},dev));
|
|
133
160
|
});
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
test('nullable developer reason preserves outcome semantics with and without Learning',async()=>{
|
|
164
|
+
for(const learning of [false,true])for(const provider of ['codex','claude']){
|
|
165
|
+
const identity={repositoryId:'test',runId:'run',taskId:'T-001',attempt:1},feature='1.fixture',learningFiles=[];
|
|
166
|
+
const r=requestFor({invocationId:'dev-1',identity,role:'developer',provider,requestedModel:'fixture',contextId:'developer',
|
|
167
|
+
payload:{scope:['src/a.mjs'],requirements:[],priorReview:null,...(learning?{learningInput:{version:1,workflow:'cm-ai',
|
|
168
|
+
phase:'task_learning_input',feature,identity,learningFiles,learningDigest:digest({version:1,feature,identity,files:learningFiles})}}:{})}});
|
|
169
|
+
for(const outcome of ['implemented','blocked'])for(const reason of [null,'Required module is missing']){
|
|
170
|
+
const value={outcome,reason,...(learning?{application:{status:'no_relevant_lesson',note:null},
|
|
171
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}:{})};
|
|
172
|
+
const transported=provider==='claude'?validateClaudeProposal({status:'succeeded',value,edits:[]}).value:value;
|
|
173
|
+
assert.deepEqual(transported,value);
|
|
174
|
+
const invalid=outcome==='implemented'&&reason!==null;
|
|
175
|
+
if(invalid)assert.throws(()=>validateDeveloperValue(transported,r));
|
|
176
|
+
else if(reason===null){
|
|
177
|
+
const {reason:omitted,...withoutReason}=value;
|
|
178
|
+
assert.deepEqual(validateDeveloperValue(transported,r),validateDeveloperValue(withoutReason,r));
|
|
179
|
+
assert.equal(value.reason,null); // Validation does not mutate worker output.
|
|
180
|
+
}else assert.equal(validateDeveloperValue(transported,r).reason,reason);
|
|
181
|
+
const create=provider==='codex'?codex.createCodexDeveloperRun:claude.createClaudeDeveloperRun;
|
|
182
|
+
const result=await create({requestedModel:'fixture',worker:async()=>({status:'succeeded',value:transported})})(r,{signal:new AbortController().signal});
|
|
183
|
+
assert.equal(result.status,outcome==='implemented'&&!invalid?'succeeded':'failed');
|
|
184
|
+
if(invalid)assert.equal(result.result.code,'invalid_result');
|
|
185
|
+
else if(outcome==='blocked'){
|
|
186
|
+
assert.equal(result.result,null);
|
|
187
|
+
assert.equal(result.blockedReason,reason===null?undefined:reason);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
test('developer schemas expose nullable reason without relaxing strict object shapes',()=>{
|
|
194
|
+
for(const name of ['codex-developer-basic-output','codex-developer-output','claude-developer-proposal']){
|
|
195
|
+
const schema=JSON.parse(readFileSync(new URL(`../runtime/js/cm-ai/${name}.schema.json`,import.meta.url),'utf8'));
|
|
196
|
+
const value=name.startsWith('claude')?schema.properties.value:schema;
|
|
197
|
+
assert.deepEqual(value.properties.reason,{type:['string','null']});
|
|
198
|
+
assert.equal(schema.additionalProperties,false);
|
|
199
|
+
assert.equal(value.additionalProperties,false);
|
|
200
|
+
if(name.startsWith('codex'))assert.deepEqual([...value.required].sort(),Object.keys(value.properties).sort());
|
|
201
|
+
else assert.deepEqual(value.required,['outcome']);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
@@ -5,9 +5,10 @@ import os from 'node:os';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
7
7
|
import {readReviewSourceFiles} from '../runtime/js/cm-ai/review-package.mjs';
|
|
8
|
-
import {requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
8
|
+
import {requestFor,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
9
9
|
import {buildCauseReviewPrompt,buildReviewPrompt} from '../runtime/js/cm-ai/codex-review-adapter.mjs';
|
|
10
10
|
import {inspectProviderCauseReview,inspectProviderReview} from '../runtime/js/cm-ai/provider-review-observation.mjs';
|
|
11
|
+
import {readFixCausePackage} from '../runtime/js/cm-fix/cause-package.mjs';
|
|
11
12
|
import {inspectFixInvestigation} from '../runtime/js/cm-fix/investigation.mjs';
|
|
12
13
|
|
|
13
14
|
test('cause package binds only selected current source and never advances the fix',async()=>{
|
|
@@ -32,6 +33,22 @@ test('cause package binds only selected current source and never advances the fi
|
|
|
32
33
|
assert.equal((await owner.advance({authorized:true})).stage,'cause_review_required');
|
|
33
34
|
const first=owner.causeReviewPackage();assert.equal(first.files.length,1);
|
|
34
35
|
assert.deepEqual(first.diagnosis.investigation,investigation);
|
|
36
|
+
const withReproduction=reproduction=>{const {packageDigest,...body}=first;
|
|
37
|
+
const value={...body,reproduction};return {...value,packageDigest:digest(value)};};
|
|
38
|
+
const visual={status:'reproduced',next:'diagnose',observation:{kind:'visual',phase:'before',
|
|
39
|
+
carrier:{path:path.join(root,'before.png'),sha256:'a'.repeat(64),kind:'screenshot',description:'Synthetic carrier metadata'},
|
|
40
|
+
environment:{scope:'local',kind:'web',carrier:'browser',target:'fixture'},reason:'Synthetic visual fixture'},
|
|
41
|
+
attempts:[{scenario:'Inspect fixture',dimension:'按描述',outcome:'reproduced'}]};
|
|
42
|
+
for(const reproduction of [first.reproduction,visual]){
|
|
43
|
+
assert.equal(readFixCausePackage(withReproduction(reproduction)).reproduction.attempts.at(-1).outcome,'reproduced');
|
|
44
|
+
const {attempts,...legacy}=reproduction;
|
|
45
|
+
assert.deepEqual(readFixCausePackage(withReproduction(legacy)).reproduction,legacy);
|
|
46
|
+
for(const outcome of ['not_reproduced','unsupported','invalid']){
|
|
47
|
+
const attempt={...attempts[0],outcome};
|
|
48
|
+
assert.throws(()=>readFixCausePackage(withReproduction({...legacy,attempts:[attempt]})),
|
|
49
|
+
{code:outcome==='invalid'?'invalid_fix_reproduction_attempts':'fix_reproduction_attempts_mismatch'});
|
|
50
|
+
}
|
|
51
|
+
}
|
|
35
52
|
assert.equal(Buffer.from(first.files[0].contentBase64,'base64').toString(),'export const value=1;');
|
|
36
53
|
assert.equal(JSON.stringify(first).includes('SYNTHETIC_NOT_FOR_PACKAGE'),false);
|
|
37
54
|
for(const provider of ['codex','claude']){
|