@aibyzero/cm-workflow 0.16.6 → 0.16.8
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 +29 -0
- package/README.md +32 -1
- package/VERSION +1 -1
- package/assets/readme/workflow-recovery-detailed.png +0 -0
- package/assets/readme/workflow-stages-detailed.png +0 -0
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +84 -9
- package/docs/user-guide.md +104 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-admission.mjs +37 -11
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +56 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +172 -33
- package/runtime/js/cm-ai/codex-review-adapter.mjs +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +2 -2
- package/runtime/js/cm-ai/drive-core.mjs +17 -4
- package/runtime/js/cm-ai/durable-runner-state.mjs +29 -0
- package/runtime/js/cm-ai/execution-store.mjs +4 -2
- package/runtime/js/cm-ai/host-conversation-execution.mjs +11 -3
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +89 -19
- package/runtime/js/cm-ai/host-session.mjs +46 -6
- package/runtime/js/cm-ai/host-tool-bridge.mjs +15 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -2
- package/runtime/js/cm-ai/log-rows.mjs +36 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +3 -0
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +29 -6
- package/runtime/js/cm-ai/task-runner.mjs +6 -1
- package/runtime/js/cm-fix/cause-package.mjs +37 -8
- package/runtime/js/cm-fix/diagnosis.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +189 -148
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/investigation.mjs +25 -9
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +3 -1
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- package/runtime/js/cm-test/recovery.mjs +4 -4
- package/runtime/js/notify-run.mjs +26 -0
- package/runtime/js/notify.mjs +388 -0
- package/runtime/model-efficiency.md +17 -0
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +2 -2
- package/scripts/cm-ai-batch-host.mjs +7 -2
- package/scripts/cm-ai-batch-run.mjs +11 -2
- package/scripts/cm-ai-batch-run.test.mjs +9 -1
- package/scripts/cm-ai-drive.mjs +18 -4
- package/scripts/cm-ai-drive.test.mjs +30 -0
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-fix-run-delivery.test.mjs +138 -0
- package/scripts/cm-ai-host.mjs +20 -8
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +71 -4
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +77 -4
- package/scripts/cm-ai-run.mjs +36 -5
- package/scripts/cm-fix-abandon.test.mjs +89 -3
- package/scripts/cm-fix-cause-package.test.mjs +33 -0
- package/scripts/cm-fix-drive.mjs +9 -1
- package/scripts/cm-fix-host.mjs +1 -1
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +71 -4
- package/scripts/cm-host-qa-executor.test.mjs +429 -3
- package/scripts/cm-log-event.mjs +53 -6
- package/scripts/cm-notify.test.mjs +468 -0
- package/scripts/cm-patrol.mjs +83 -0
- package/scripts/cm-patrol.test.mjs +161 -0
- package/scripts/cm-prd-host.mjs +13 -2
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- package/scripts/cm-test-branch-impact.test.mjs +11 -0
- package/scripts/cm-token-report.mjs +497 -0
- package/scripts/cm-token-report.test.mjs +346 -0
- package/skills/cm-ai/SKILL.md +7 -3
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +2 -2
- package/skills/cm-ai/references/js-host-modes.md +90 -0
- package/skills/cm-ai/references/js-host-qa-recovery.md +110 -0
- package/skills/cm-ai/references/js-host-recovery.md +199 -0
- package/skills/cm-ai/references/js-host.md +69 -330
- package/skills/cm-fix/SKILL.md +2 -0
- package/skills/cm-fix/references/js-host.md +16 -9
- package/skills/cm-prd/SKILL.md +7 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
|
@@ -6,7 +6,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
6
6
|
import {inspectCmAiAdmission,approveCmAiSpecs,matchesCmAiTaskSelection,explainCmAiTaskSelection} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
7
7
|
import {validateRunDefinition} from './cm-ai-run.mjs';
|
|
8
8
|
|
|
9
|
-
const usage='usage: cm-ai-admission.mjs --specs-dir PATH --code-project PATH [--code-project PATH ...] [--approval-response TEXT | --yes] [--approve --approval-response TEXT (no --yes)] [--print-run-definition --scope a,b [--task T-xxx] [--requirements c,d] [--run-id X] [--repository-id Y]]';
|
|
9
|
+
const usage='usage: cm-ai-admission.mjs --specs-dir PATH --code-project PATH [--code-project PATH ...] [--approval-response TEXT | --yes] [--approve --approval-response TEXT (no --yes)] [--feature N.slug] [--print-run-definition --scope a,b [--task T-xxx] [--requirements c,d] [--run-id X] [--repository-id Y]]';
|
|
10
10
|
|
|
11
11
|
function parse(argv){
|
|
12
12
|
const result={codeProjects:[]};
|
|
@@ -26,7 +26,7 @@ function parse(argv){
|
|
|
26
26
|
if(index+1>=argv.length||result.codeProjects.length>=16)throw new Error('invalid arguments');
|
|
27
27
|
result.codeProjects.push(argv[++index]);continue;
|
|
28
28
|
}
|
|
29
|
-
const key={'--specs-dir':'specsDir','--approval-response':'approvalResponse',
|
|
29
|
+
const key={'--specs-dir':'specsDir','--approval-response':'approvalResponse','--feature':'feature',
|
|
30
30
|
'--scope':'scope','--task':'task','--requirements':'requirements','--run-id':'runId','--repository-id':'repositoryId'}[flag];
|
|
31
31
|
if(!key||index+1>=argv.length||Object.hasOwn(result,key))throw new Error('invalid arguments');
|
|
32
32
|
result[key]=argv[++index];
|
|
@@ -40,6 +40,10 @@ function parse(argv){
|
|
|
40
40
|
|
|
41
41
|
function buildRunDefinition(admission,input){
|
|
42
42
|
if(!admission.codeProject)throw new Error('--print-run-definition requires one --code-project');
|
|
43
|
+
// An explicit feature never yields another feature's definition.
|
|
44
|
+
if(input.feature!==undefined&&admission.nextTask.feature!==input.feature)
|
|
45
|
+
throw Object.assign(new Error('feature_tasks_terminal'),{code:'feature_tasks_terminal',
|
|
46
|
+
reason:`所选 feature ${input.feature} 已无待办任务,不为其他 feature 生成运行定义;请明确选择下一个 feature`});
|
|
43
47
|
const selected=input.task===undefined?admission.nextTask:{feature:admission.nextTask.feature,id:input.task};
|
|
44
48
|
if(input.task!==undefined&&!matchesCmAiTaskSelection(admission,selected.feature,selected.id,{version:1,taskId:input.task}))
|
|
45
49
|
throw Object.assign(new Error('task_selection_mismatch'),{code:'task_selection_mismatch',
|
|
@@ -57,7 +61,8 @@ function buildRunDefinition(admission,input){
|
|
|
57
61
|
identity:{repositoryId,runId:input.runId??`${selected.feature.replace(/^\d+\./,'')}-${selected.id}`,
|
|
58
62
|
taskId:selected.id,attempt:1},
|
|
59
63
|
scope:list(input.scope),requirements:list(input.requirements),
|
|
60
|
-
...(input.task===undefined?{}:{taskSelection:{version:1,taskId:selected.id}})
|
|
64
|
+
...(input.task===undefined?{}:{taskSelection:{version:1,taskId:selected.id}}),
|
|
65
|
+
...(input.feature===undefined?{}:{featureSelection:{version:1,feature:input.feature}})};
|
|
61
66
|
return validateRunDefinition(definition);
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -82,6 +87,12 @@ export function main(argv=process.argv.slice(2)){
|
|
|
82
87
|
projectAdmissions:projectResults.map(item=>({codeProject:item.codeProject,state:item.state,reason:item.reason}))};
|
|
83
88
|
if(result.state==='awaiting_spec_approval'&&(result.approvalIntent!=='explicit'||input.assumeYes))
|
|
84
89
|
result.message='确认规格摘要后,用 --approval-response 传入用户原话,并明确回复“开始”。';
|
|
90
|
+
// An explicit feature with nothing left never prints a definition, whether the
|
|
91
|
+
// project still has other work (ready) or none (complete).
|
|
92
|
+
if(input.printRunDefinition&&!result.approveRefused&&input.feature!==undefined&&result.requestedFeatureComplete===input.feature){
|
|
93
|
+
process.stderr.write(`${JSON.stringify({error:{code:'feature_tasks_terminal',
|
|
94
|
+
reason:`所选 feature ${input.feature} 已无待办任务,不为其他 feature 生成运行定义;请明确选择下一个 feature`}})}\n`);return 1;
|
|
95
|
+
}
|
|
85
96
|
if(input.printRunDefinition&&!result.approveRefused&&result.state==='ready'){
|
|
86
97
|
try{process.stdout.write(`${JSON.stringify(buildRunDefinition(result,input))}\n`);return 0;}
|
|
87
98
|
catch(error){process.stderr.write(`${JSON.stringify({error:{code:error.code??error.message,
|
|
@@ -131,9 +131,9 @@ function preflight(){
|
|
|
131
131
|
if(bundle.workflows[key]!==null)validateHostWorkflowConfiguration(bundle.workflows[key]);
|
|
132
132
|
}
|
|
133
133
|
// Use the batch owner's selection/parallel-group validator without opening a run.
|
|
134
|
-
createCmAiBatch({configuration:batch,executionFor:async()=>({}),
|
|
134
|
+
createCmAiBatch({configuration:batch,executionFor:async()=>({}),bootstrapKeys:Object.keys(bundle.bootstraps??{}),
|
|
135
135
|
logHome:path.join(batch.specsDir,'.reviews','host-log-mirror')});
|
|
136
|
-
}catch(error){stop(2,`批次定义、scope 或 workflow 无效: ${error.code??error.message}`);}
|
|
136
|
+
}catch(error){stop(2,`批次定义、scope 或 workflow 无效: ${error.code??error.message}${error.code==='protected_scope'&&typeof error.reason==='string'?`;${error.reason}`:''}`);}
|
|
137
137
|
const log=path.join(batch.specsDir,'运行日志.jsonl');
|
|
138
138
|
const stores=Array.from(definitions.values(),d=>path.join(batch.specsDir,'.reviews','.execution',d.identity.runId,'state.json'));
|
|
139
139
|
const hasLog=fs.existsSync(log),hasStore=stores.some(file=>fs.existsSync(file));
|
|
@@ -6,6 +6,7 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {createCmAiBatch,batchTaskRunId} from './cm-ai-batch-run.mjs';
|
|
9
|
+
import {assertCreatableScope} from './cm-ai-run.mjs';
|
|
9
10
|
import {createConversationExecution,readConversationReviewConfiguration,readConversationProtection,runReviewPreflight} from './cm-ai-host.mjs';
|
|
10
11
|
import {loadConfig,resolveProtectedRuntimes} from './cm-workflow-config.mjs';
|
|
11
12
|
import {preflightMatches} from '../runtime/js/cm-ai/worker-codex.mjs';
|
|
@@ -120,6 +121,10 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
120
121
|
}else need(false,'invalid_arguments');
|
|
121
122
|
}
|
|
122
123
|
const started=keys.some(key=>fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,key),'state.json')));
|
|
124
|
+
// Same read-only create gate as the batch owner, before any model or policy configuration is read or frozen.
|
|
125
|
+
for(const [index,task] of batch.tasks.entries())
|
|
126
|
+
if(!Object.hasOwn(bootstraps??{},keys[index])&&!fs.existsSync(path.join(batch.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,keys[index]),'state.json')))
|
|
127
|
+
try{assertCreatableScope(task.scope);}catch(cause){cause.reason=`${keys[index]}: ${cause.reason}`;throw cause;}
|
|
123
128
|
const executionPolicy=readBatchExecutionPolicy({batch,started,enabled:executionPolicyEnabled});
|
|
124
129
|
const routes=providerConfig?resolveProtectedRuntimes(loadConfig({projectRoot:batch.codeProject}),runtime??'codex'):{reviewerRuntime:runtime??'codex'};
|
|
125
130
|
const externalModels=readBatchExternalModels({batch,started,enabled:externalEnabled,inputFile:externalFile,providers:[routes.coderRuntime,routes.reviewerRuntime].filter(Boolean)});
|
|
@@ -164,7 +169,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
164
169
|
let reconciling=false;
|
|
165
170
|
const driver=createCmAiBatch({configuration:{...batch,...(externalModels?{externalModels}:{}),...(executionPolicy?{executionPolicy}:{})},logHome:path.join(batch.specsDir,'.reviews','host-log-mirror'),
|
|
166
171
|
runtime:runtime??'codex',checkCommands:(providerConfig??protection)?.checkCommands??null,checkTimeoutMs:(providerConfig??protection)?.timeoutMs??60000,
|
|
167
|
-
rerunUnknownQa,rerunBlockedQa,holdRevisions:[...holds],
|
|
172
|
+
rerunUnknownQa,rerunBlockedQa,holdRevisions:[...holds],bootstrapKeys:Object.keys(bootstraps??{}),
|
|
168
173
|
executionFor:async(definition,{parallelMember=false}={})=>{
|
|
169
174
|
await freezeBatchExecutionPolicy(batch,executionPolicy);
|
|
170
175
|
freezeBatchExternalModels(batch,externalModels);
|
|
@@ -191,7 +196,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
191
196
|
try{await serveHostTransport({host,input,output,toolBridge:bridge},inputLimitRaw);}
|
|
192
197
|
finally{if(rawMode)input.setRawMode(false);}
|
|
193
198
|
return 0;
|
|
194
|
-
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required'].includes(code)
|
|
199
|
+
}catch(cause){const code=safeCode(cause);error.write(JSON.stringify({error:{code,...(['browser_capability_required','browser_capability_unavailable','invalid_arguments','review_configuration_required','protected_scope'].includes(code)
|
|
195
200
|
&&typeof cause.reason==='string'?{reason:cause.reason}:{}),...(code==='request_too_large'?{reason:inputLimitReason(cause.limit)}:{})}})+'\n');return 1;}
|
|
196
201
|
finally{bridge?.close();}
|
|
197
202
|
}
|
|
@@ -7,7 +7,7 @@ import fs from 'node:fs';
|
|
|
7
7
|
import path from 'node:path';
|
|
8
8
|
import {spawnSync} from 'node:child_process';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
|
-
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
10
|
+
import {openControlRun,validateRunDefinition,assertCreatableScope} from './cm-ai-run.mjs';
|
|
11
11
|
import {developmentRetryable,completionRetryable,reviewRetryable} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
12
12
|
import {batchOperatorGuidance} from '../runtime/js/cm-ai/operator-guidance.mjs';
|
|
13
13
|
import {digest,json,shape,need,id,hex} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
@@ -39,7 +39,7 @@ export function batchMemberResult(result,{parallel=false}={}){
|
|
|
39
39
|
:`${revert};或取消本批次,还原该任务已改动的代码后,用单任务宿主 cm-ai-host.mjs 以 --supersede-reviewed-evidence --supersede-reason 原因 新建运行重做该任务。`}));
|
|
40
40
|
}
|
|
41
41
|
export function createCmAiBatch({configuration,executionFor,logHome,runtime='codex',checkCommands=null,checkTimeoutMs=60000,
|
|
42
|
-
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[]}){
|
|
42
|
+
rerunUnknownQa=false,rerunBlockedQa=false,holdRevisions=[],bootstrapKeys=[]}){
|
|
43
43
|
const config=json(configuration);
|
|
44
44
|
shape(config,['version','repositoryId','batchId','specsDir','codeProject','tasks',...['externalModels','executionPolicy','codeProjects','parallel'].filter(name=>Object.hasOwn(config,name))]);
|
|
45
45
|
need(config.version===1);id(config.repositoryId);id(config.batchId);need(config.batchId.length>=8);
|
|
@@ -70,6 +70,10 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
70
70
|
identity:{repositoryId:config.repositoryId,runId:batchTaskRunId(config.batchId,key(task)),
|
|
71
71
|
taskId:task.taskId,attempt:1},scope:task.scope,requirements:task.requirements});
|
|
72
72
|
need(definition.specsDir===config.specsDir&&definition.codeProject===config.codeProject,'invalid_path');
|
|
73
|
+
// A member that will be created is refused before the batch locks, logs or
|
|
74
|
+
// prepares a worktree; an existing member keeps its own recovery path.
|
|
75
|
+
if(!bootstrapKeys.includes(key(task))&&!fs.existsSync(path.join(config.specsDir,'.reviews','.execution',definition.identity.runId,'state.json')))
|
|
76
|
+
try{assertCreatableScope(definition.scope);}catch(error){error.reason=`${key(task)}: ${error.reason}`;throw error;}
|
|
73
77
|
plans.set(key(task),definition);
|
|
74
78
|
}
|
|
75
79
|
// Tasks whose second-round answer is not written yet stop after a changes_requested review.
|
|
@@ -200,6 +204,11 @@ export function createCmAiBatch({configuration,executionFor,logHome,runtime='cod
|
|
|
200
204
|
}
|
|
201
205
|
function prepareGroup(group){
|
|
202
206
|
const state=progress(),remaining=group.filter(key=>membership.has(key)&&!state.done.has(key));
|
|
207
|
+
// A member may only create files (js-host.md 3.1): every scope path of a member
|
|
208
|
+
// about to get its worktree must be absent from HEAD. Checked for the whole group
|
|
209
|
+
// before any worktree exists; started members are not rechecked.
|
|
210
|
+
for(const key of remaining)if(!fs.existsSync(location(key).worktree))for(const file of plans.get(key).scope)
|
|
211
|
+
need(spawnSync('git',['-C',config.codeProject,'cat-file','-e',`HEAD:${file}`],gitOptions()).status!==0,'parallel_scope_existing_file');
|
|
203
212
|
for(const key of remaining){
|
|
204
213
|
const {worktree,branch}=location(key);
|
|
205
214
|
if(!fs.existsSync(worktree)){
|
|
@@ -32,6 +32,7 @@ test('final serial task commits durably and commit information survives resume',
|
|
|
32
32
|
test('a batch member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('review-provider-retry'));
|
|
33
33
|
test('a parallel member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('parallel-review-provider-retry'));
|
|
34
34
|
test('dirty batch entry lists files and creates no member worktrees',()=>batchFixture('parallel-dirty'));
|
|
35
|
+
test('a parallel member whose scope file already exists on HEAD is refused before any worktree',()=>batchFixture('parallel-existing'));
|
|
35
36
|
|
|
36
37
|
test('parallel groups reject transitive prerequisites, not just direct edges',()=>{
|
|
37
38
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-batch-transitive-')));
|
|
@@ -95,7 +96,7 @@ async function batchFixture(mode,options={}){
|
|
|
95
96
|
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
96
97
|
const git=(cwd,args)=>{const result=spawnSync('git',['-C',cwd,...args],{encoding:'utf8'});assert.equal(result.status,0,result.stderr);return result.stdout.trim();};
|
|
97
98
|
{git(codeProject,['init','-b','main']);git(codeProject,['config','user.name','Fixture']);git(codeProject,['config','user.email','fixture@example.invalid']);
|
|
98
|
-
fs.writeFileSync(path.join(codeProject,'file0.js'),'base\n');git(codeProject,['add','-A']);git(codeProject,['commit','-m','fixture baseline']);}
|
|
99
|
+
fs.writeFileSync(path.join(codeProject,parallel?'base.js':'file0.js'),'base\n');git(codeProject,['add','-A']);git(codeProject,['commit','-m','fixture baseline']);}
|
|
99
100
|
const config={version:1,repositoryId:'batch-fixture',batchId:'batch-fixture',specsDir,codeProject,
|
|
100
101
|
...(parallel?{parallel:[[`${feature}/T-001`,`${feature}/T-002`]]}:{}),
|
|
101
102
|
tasks:(parallel?['T-001','T-002','T-003']:['T-001','T-002']).map((taskId,index)=>({feature,taskId,scope:[`file${index}.js`],requirements:['requirements.md']}))};
|
|
@@ -211,6 +212,13 @@ async function batchFixture(mode,options={}){
|
|
|
211
212
|
packageDigest:binding.packageDigest,contextDigest:binding.contextDigest,status:'completed',reason:'Synthetic docs',at:'2026-09-08T01:00:00Z'})},
|
|
212
213
|
});
|
|
213
214
|
const open=()=>createCmAiBatch({configuration:config,executionFor,logHome:path.join(root,'logs')});
|
|
215
|
+
if(mode==='parallel-existing'){
|
|
216
|
+
// T-002's scope file is committed on HEAD, so it is an edit, not a new file.
|
|
217
|
+
fs.writeFileSync(path.join(codeProject,'file1.js'),'existing\n');git(codeProject,['add','file1.js']);git(codeProject,['commit','-m','existing file']);
|
|
218
|
+
await assert.rejects(open().handle({operation:'advance',requestId:'existing'}),error=>error.code==='parallel_scope_existing_file');
|
|
219
|
+
assert.deepEqual(calls,[]);assert(!fs.existsSync(path.join(root,'.cm-worktrees')));
|
|
220
|
+
assert.equal(git(codeProject,['status','--porcelain']),'');return;
|
|
221
|
+
}
|
|
214
222
|
if(mode==='parallel-dirty'){
|
|
215
223
|
fs.writeFileSync(path.join(codeProject,'dirty.txt'),'user-owned\n');
|
|
216
224
|
const result=await open().handle({operation:'advance',requestId:'dirty'});
|
package/scripts/cm-ai-drive.mjs
CHANGED
|
@@ -84,7 +84,8 @@ const PAIR_FLAGS=new Set(['--external-models-config','--allow-review-attempt','-
|
|
|
84
84
|
'--input-limit',
|
|
85
85
|
'--protected-conversation-config','--protected-config','--revise-qa-config','--qa-config-revision-reason','--qa-environment-failure',
|
|
86
86
|
'--qa-fix-owner-config','--qa-fix-template-config','--qa-fix-review-config','--browser-qa',
|
|
87
|
-
'--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--spec-rebind-reason'
|
|
87
|
+
'--bootstrap-config','--allow-provider-development-attempt','--supersede-reason','--spec-rebind-reason',
|
|
88
|
+
'--review-runtime','--feature']);
|
|
88
89
|
const FLAG_FLAGS=new Set(['--execution-optimizations','--external-models','--allow-development','--allow-qa','--allow-qa-fix-start','--auto-qa-fix',
|
|
89
90
|
'--verification-precheck',
|
|
90
91
|
'--allow-bootstrap-write','--allow-abandon-review','--allow-abandon-effect','--allow-bootstrap-review-recovery','--rerun-unknown-qa','--rerun-blocked-qa','--failover',
|
|
@@ -252,7 +253,7 @@ export function projectDevelopCheckpoint({preview,codeProject,attempt,value,proj
|
|
|
252
253
|
const {definition}=preview,identity={...definition.identity,attempt};
|
|
253
254
|
if(value.value?.outcome!=='implemented')return null;
|
|
254
255
|
const learningInput=inspectCmAiTaskLearningInput({specsDir:definition.specsDir,codeProject,feature:definition.feature,
|
|
255
|
-
identity,applicableAgentFiles:[]},{admission:null,parallelSelection:preview.parallelSelection});
|
|
256
|
+
identity,applicableAgentFiles:[],...(definition.featureSelection?{featureSelection:definition.featureSelection.feature}:{})},{admission:null,parallelSelection:preview.parallelSelection});
|
|
256
257
|
const binding={feature:definition.feature,identity,learningDigest:learningInput.learningDigest};
|
|
257
258
|
const application=createCmAiTaskLearningApplication({...binding,...value.value.application});
|
|
258
259
|
const retrospective=createCmAiTaskLearningRetrospective({...binding,...value.value.retrospective});
|
|
@@ -455,7 +456,10 @@ function predictedQaAsks(definition,qa){
|
|
|
455
456
|
const taskWasPending=!completed.has(definition.identity.taskId);
|
|
456
457
|
completed.add(definition.identity.taskId);
|
|
457
458
|
const pendingAfter=context.pending-(taskWasPending?1:0);
|
|
458
|
-
|
|
459
|
+
// A case bound only to [DROPPED] tasks is never planned, so never asked.
|
|
460
|
+
const dropped=new Set(context.dropped);
|
|
461
|
+
const cases=plan.cases.filter(item=>!(item.taskIds.length>0&&item.taskIds.every(taskId=>dropped.has(taskId))))
|
|
462
|
+
.filter(item=>pendingAfter===0||item.taskIds.every(taskId=>completed.has(taskId)));
|
|
459
463
|
const asks=[];
|
|
460
464
|
// The current executor still calls logic() for mapped cases; command evidence
|
|
461
465
|
// only affects the later verdict. Keep the preflight conservative until that
|
|
@@ -575,6 +579,15 @@ function load(){
|
|
|
575
579
|
if(!fs.existsSync(config))stop(2,`运行定义不存在: ${config}`);
|
|
576
580
|
let definition;
|
|
577
581
|
try{definition=readRunDefinition(config);}catch(error){stop(2,`运行定义无效或 codeProject/specsDir 无法解析: ${error.code??error.message}`);}
|
|
582
|
+
// --feature is forwarded to the host, which binds it as featureSelection.
|
|
583
|
+
// Use that same effective definition here (Learning input, bootstrap checks).
|
|
584
|
+
const featureAt=permissions.indexOf('--feature');
|
|
585
|
+
if(featureAt!==-1){
|
|
586
|
+
const selected=permissions[featureAt+1];
|
|
587
|
+
if(selected!==definition.feature||definition.featureSelection&&definition.featureSelection.feature!==selected)
|
|
588
|
+
stop(2,`--feature ${selected} 必须与运行定义的 feature ${definition.feature} 一致`);
|
|
589
|
+
definition={...definition,featureSelection:{version:1,feature:selected}};
|
|
590
|
+
}
|
|
578
591
|
if(plan.mode==='create')try{assertCreatableRunId(definition.identity);}
|
|
579
592
|
catch(error){stop(2,`运行定义的 ${error.code.replace(/^invalid_config: /,'')};宿主未启动,请换一个更长的 runId`);}
|
|
580
593
|
const store=path.join(definition.specsDir,'.reviews','.execution',definition.identity.runId);
|
|
@@ -595,7 +608,8 @@ function load(){
|
|
|
595
608
|
for(let i=0;i<permissions.length;i++)if(PAIR_FLAGS.has(permissions[i])
|
|
596
609
|
&&permissions[i]!=='--allow-review-attempt'&&permissions[i]!=='--browser-qa'
|
|
597
610
|
&&permissions[i]!=='--qa-config-revision-reason'&&permissions[i]!=='--qa-environment-failure'&&permissions[i]!=='--allow-provider-development-attempt'
|
|
598
|
-
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'
|
|
611
|
+
&&permissions[i]!=='--supersede-reason'&&permissions[i]!=='--spec-rebind-reason'&&permissions[i]!=='--input-limit'
|
|
612
|
+
&&permissions[i]!=='--review-runtime'&&permissions[i]!=='--feature'){
|
|
599
613
|
const file=path.resolve(base,permissions[i+1]);if(!fs.existsSync(file))stop(2,`${permissions[i]} 文件不存在: ${file}`);
|
|
600
614
|
permissions[i+1]=file;permissionFiles.push(file);i++;
|
|
601
615
|
}
|
|
@@ -456,6 +456,14 @@ test('cases bound to another unfinished task do not require QA runners yet',t=>{
|
|
|
456
456
|
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
457
457
|
assert(fs.existsSync(f.store),run.stderr);
|
|
458
458
|
});
|
|
459
|
+
test('cases bound only to a dropped task never require QA runners',t=>{
|
|
460
|
+
const f=fixture(t);prepared(f);
|
|
461
|
+
fs.writeFileSync(path.join(f.specsDir,'1.work','tasks.md'),'- [ ] T-001: current\n- [ ] ~~T-002: column~~ `[DROPPED v2: 暂缓]`\n');
|
|
462
|
+
const run=f.drive(qaFixture(f,[{kind:'logic',expected:'Dropped logic',taskIds:['T-002']},
|
|
463
|
+
{kind:'browser',expected:'Dropped browser',taskIds:['T-002']}]),'advance');
|
|
464
|
+
assert.doesNotMatch(run.stderr,/缺少真实执行 runner/);
|
|
465
|
+
assert(fs.existsSync(f.store),run.stderr);
|
|
466
|
+
});
|
|
459
467
|
test('protected conversation still requires the authored develop answer',t=>{
|
|
460
468
|
const f=fixture(t);fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands:[
|
|
461
469
|
{id:'syntax',command:[process.execPath,'--check','target.mjs']}],timeoutMs:60000}));
|
|
@@ -582,3 +590,25 @@ test('legacy real driver rejects optimization aliases before any host or command
|
|
|
582
590
|
const result=f.drive(f.plan({checks:[{id:'one',command},{id:'two',command,sameExecutionAs:'one'}]}),'advance');
|
|
583
591
|
assert.notEqual(result.status,0);assert(!fs.existsSync(f.store));assert(!fs.existsSync(path.join(f.codeProject,'marker')));
|
|
584
592
|
});
|
|
593
|
+
// The driver forwards the explicit batch choice and the cross-tool review
|
|
594
|
+
// binding, and previews with the same effective definition as the host.
|
|
595
|
+
test('driver forwards --feature for a later approved feature and --review-runtime for a cross-tool run',t=>{
|
|
596
|
+
const f=fixture(t);
|
|
597
|
+
const early=path.join(f.specsDir,'0.early');fs.mkdirSync(early);
|
|
598
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(early,name),'# Early\n');
|
|
599
|
+
fs.writeFileSync(path.join(early,'tasks.md'),'- [ ] T-001: earlier batch\n');
|
|
600
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.early','1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
601
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),'version: 1\nruntimes: {available: both}\nroles:\n coder: {adapter: codex-cli, source: subscription}\n reviewer: {adapter: claude-cli, source: subscription}\n');
|
|
602
|
+
const bare={answers:undefined,checks:undefined};
|
|
603
|
+
const unselected=f.drive(f.plan({...bare}),'status');
|
|
604
|
+
assert.notEqual(unselected.status,0);assert.match(unselected.stdout+unselected.stderr,/task_selection_mismatch/);
|
|
605
|
+
const wrong=f.drive(f.plan({...bare,permissions:['--feature','0.early']}),'status');
|
|
606
|
+
assert.equal(wrong.status,2);assert.match(wrong.stderr,/必须与运行定义的 feature 1\.work 一致/);
|
|
607
|
+
const bound=['--feature','1.work','--review-runtime','claude'];
|
|
608
|
+
const created=f.drive(f.plan({...bare,permissions:bound}),'status');
|
|
609
|
+
assert.equal(created.status,0,created.stderr);assert.equal(fs.existsSync(f.store),true);
|
|
610
|
+
const resumed=f.drive(f.plan({...bare,mode:'resume',permissions:bound}),'status');
|
|
611
|
+
assert.equal(resumed.status,0,resumed.stderr);
|
|
612
|
+
const unbound=f.drive(f.plan({...bare,mode:'resume'}),'status');
|
|
613
|
+
assert.notEqual(unbound.status,0);assert.match(unbound.stdout+unbound.stderr,/fingerprint_mismatch/);
|
|
614
|
+
});
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Explicit batch (feature) selection. An approved cross-feature order may run a
|
|
2
|
+
// later feature while an earlier one still has pending tasks: the 2026-10-06
|
|
3
|
+
// AI潮 6.api-native-reading batch before 5.author-column T-009/T-010. Without an
|
|
4
|
+
// explicit selection, admission still picks the lowest-numbered pending feature.
|
|
5
|
+
import nodeTest from 'node:test';
|
|
6
|
+
import assert from 'node:assert/strict';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import path from 'node:path';
|
|
10
|
+
import {spawnSync} from 'node:child_process';
|
|
11
|
+
import {fileURLToPath} from 'node:url';
|
|
12
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
13
|
+
import {inspectCmAiAdmission,isFinalCmAiTask} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
14
|
+
import {inspectCmAiContextRefresh} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
15
|
+
import {openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
16
|
+
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
17
|
+
|
|
18
|
+
const platform=isSupportedExecutionPlatform();
|
|
19
|
+
const test=(name,fn)=>nodeTest(name,{skip:!platform},fn);
|
|
20
|
+
const admissionCli=fileURLToPath(new URL('./cm-ai-admission.mjs',import.meta.url));
|
|
21
|
+
const runCli=fileURLToPath(new URL('./cm-ai-run.mjs',import.meta.url));
|
|
22
|
+
const EARLY='5.author',LATER='6.reader';
|
|
23
|
+
|
|
24
|
+
function project(t,{later='- [ ] T-001: reader contract\n- [ ] T-002: mapping\n\n## 依赖\n\n- T-002 依赖 T-001\n'}={}){
|
|
25
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-feature-selection-')));
|
|
26
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
27
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');
|
|
28
|
+
fs.mkdirSync(codeProject);fs.writeFileSync(path.join(codeProject,'a.js'),'old\n');
|
|
29
|
+
for(const [feature,tasks] of [[EARLY,'- [x] T-008: done\n- [ ] T-009: after the reader batch\n'],[LATER,later]]){
|
|
30
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
31
|
+
for(const file of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,file),`# ${feature}\n`);
|
|
32
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),tasks);
|
|
33
|
+
}
|
|
34
|
+
const approve=()=>fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',
|
|
35
|
+
features:[EARLY,LATER],specFiles:buildManifest(specsDir)}));
|
|
36
|
+
approve();
|
|
37
|
+
const admission=(...args)=>{
|
|
38
|
+
const out=spawnSync(process.execPath,[admissionCli,'--specs-dir',specsDir,'--code-project',codeProject,...args],{encoding:'utf8'});
|
|
39
|
+
return {...out,json:out.stdout.trim()?JSON.parse(out.stdout):null};
|
|
40
|
+
};
|
|
41
|
+
const definition=(taskId,extra={})=>({version:1,specsDir,codeProject,feature:LATER,
|
|
42
|
+
identity:{repositoryId:'fixture',runId:`reader-${taskId}-run`,taskId,attempt:1},scope:['a.js'],requirements:[],...extra});
|
|
43
|
+
const selected={featureSelection:{version:1,feature:LATER}};
|
|
44
|
+
return {root,specsDir,codeProject,approve,admission,definition,selected};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
test('without an explicit choice admission still selects the lowest-numbered pending feature',t=>{
|
|
48
|
+
const f=project(t);
|
|
49
|
+
const result=f.admission();
|
|
50
|
+
assert.equal(result.status,0,result.stderr);
|
|
51
|
+
assert.deepEqual(result.json.nextTask,{feature:EARLY,id:'T-009',description:'after the reader batch'});
|
|
52
|
+
assert.equal(Object.hasOwn(result.json,'requestedFeatureComplete'),false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('an explicit later feature is selected with its own dependency rule and the earlier feature untouched',t=>{
|
|
56
|
+
const f=project(t);
|
|
57
|
+
const tasksBefore=fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md'));
|
|
58
|
+
const result=f.admission('--feature',LATER);
|
|
59
|
+
assert.equal(result.status,0,result.stderr);
|
|
60
|
+
assert.equal(result.json.state,'ready');
|
|
61
|
+
assert.deepEqual(result.json.nextTask,{feature:LATER,id:'T-001',description:'reader contract'});
|
|
62
|
+
// T-002 depends on T-001: only T-001 is eligible.
|
|
63
|
+
assert.deepEqual(result.json.eligibleTasks,[{feature:LATER,id:'T-001'}]);
|
|
64
|
+
assert.deepEqual(result.json.features.map(item=>[item.name,item.pending]),[[EARLY,1],[LATER,2]]);
|
|
65
|
+
assert.deepEqual(fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md')),tasksBefore);
|
|
66
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
67
|
+
assert.equal(printed.status,0,printed.stderr);
|
|
68
|
+
assert.deepEqual(printed.json.featureSelection,{version:1,feature:LATER});
|
|
69
|
+
assert.equal(printed.json.feature,LATER);assert.equal(printed.json.identity.taskId,'T-001');
|
|
70
|
+
const blocked=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js','--task','T-002');
|
|
71
|
+
assert.equal(blocked.status,1);assert.match(blocked.stderr,/task_selection_mismatch/);assert.match(blocked.stderr,/T-001 尚未完成/);
|
|
72
|
+
const missing=f.admission('--feature','7.missing');
|
|
73
|
+
assert.equal(missing.status,1);assert.equal(missing.json.reason,'feature_selection_invalid');
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('an explicit choice keeps every approval gate: manifest drift and unapproved specs still block',t=>{
|
|
77
|
+
const f=project(t);
|
|
78
|
+
fs.appendFileSync(path.join(f.specsDir,EARLY,'requirements.md'),'drift\n');
|
|
79
|
+
const drift=f.admission('--feature',LATER);
|
|
80
|
+
assert.equal(drift.status,1);assert.equal(drift.json.reason,'spec_drift');
|
|
81
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:[EARLY,LATER]}));
|
|
82
|
+
const pending=f.admission('--feature',LATER);
|
|
83
|
+
assert.equal(pending.json.state,'awaiting_spec_approval');assert.equal(pending.json.nextTask,null);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
test('a completed selected feature is reported and never yields another feature definition or run',async t=>{
|
|
87
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
88
|
+
const result=f.admission('--feature',LATER);
|
|
89
|
+
assert.equal(result.status,0,result.stderr);
|
|
90
|
+
assert.equal(result.json.requestedFeatureComplete,LATER);
|
|
91
|
+
assert.equal(result.json.nextTask.feature,EARLY);
|
|
92
|
+
assert.match(result.json.warnings.join(' '),new RegExp(`所选 feature ${LATER} 已无待办任务`));
|
|
93
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
94
|
+
assert.equal(printed.status,1);assert.equal(printed.stdout,'');assert.match(printed.stderr,/feature_tasks_terminal/);
|
|
95
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001',f.selected)),'create'),
|
|
96
|
+
error=>error.code==='task_selection_mismatch'&&/已无待办任务/.test(error.reason));
|
|
97
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test('a run creates for an explicit later feature, refuses without it, and refuses a task whose dependency is pending',async t=>{
|
|
101
|
+
const f=project(t);
|
|
102
|
+
// Unchanged 0.16.7 behaviour without an explicit choice.
|
|
103
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001')),'create'),
|
|
104
|
+
error=>error.code==='task_selection_mismatch'&&error.reason.includes(`当前 feature ${EARLY}`)&&error.reason.includes('--feature'));
|
|
105
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-002',f.selected)),'create'),
|
|
106
|
+
error=>error.code==='task_selection_mismatch'&&error.reason.includes('T-001 尚未完成'));
|
|
107
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
108
|
+
const config=path.join(f.root,'run.json');fs.writeFileSync(config,JSON.stringify(f.definition('T-001',f.selected)));
|
|
109
|
+
const invoke=mode=>{
|
|
110
|
+
const out=spawnSync(process.execPath,[runCli,'serve','--config',config,'--mode',mode],{encoding:'utf8',timeout:20000,
|
|
111
|
+
input:[{version:1,operation:'status',requestId:'status',identity:f.definition('T-001').identity}].map(JSON.stringify).join('\n')+'\n'});
|
|
112
|
+
return {...out,rows:out.stdout.trim().split('\n').filter(Boolean).map(JSON.parse)};
|
|
113
|
+
};
|
|
114
|
+
const created=invoke('create');
|
|
115
|
+
assert.equal(created.status,0,created.stderr);
|
|
116
|
+
assert.equal(created.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
117
|
+
const journal=path.join(f.specsDir,'.reviews','.execution','reader-T-001-run','state.json');
|
|
118
|
+
const before=fs.readFileSync(journal);
|
|
119
|
+
const resumed=invoke('resume');
|
|
120
|
+
assert.equal(resumed.status,0,resumed.stderr);
|
|
121
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
122
|
+
assert.deepEqual(fs.readFileSync(journal),before);
|
|
123
|
+
// The selection is part of the durable definition: dropping it changes the run.
|
|
124
|
+
fs.writeFileSync(config,JSON.stringify(f.definition('T-001')));
|
|
125
|
+
const dropped=invoke('resume');assert.equal(dropped.status,1);assert.match(dropped.stderr,/fingerprint_mismatch/);
|
|
126
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,EARLY,'tasks.md'),'utf8'),/- \[ \] T-009/);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('in-run admission for an explicit run reads the selected feature (context refresh and last-task check)',t=>{
|
|
130
|
+
const f=project(t,{later:'- [ ] T-001: reader contract\n'});
|
|
131
|
+
const input={specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,applicableAgentFiles:[]};
|
|
132
|
+
assert.throws(()=>inspectCmAiContextRefresh(input),{code:'context_invalid'});
|
|
133
|
+
const refresh=inspectCmAiContextRefresh({...input,featureSelection:LATER});
|
|
134
|
+
assert.deepEqual(refresh.nextTask,{feature:LATER,id:'T-001',description:'reader contract'});
|
|
135
|
+
assert.throws(()=>inspectCmAiContextRefresh({...input,featureSelection:EARLY}),{code:'context_invalid'});
|
|
136
|
+
assert.throws(()=>isFinalCmAiTask({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,taskId:'T-001'}),
|
|
137
|
+
{code:'documentation_admission_required'});
|
|
138
|
+
// Two tasks are pending in the project (T-009 too): not the final task.
|
|
139
|
+
assert.equal(isFinalCmAiTask({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,taskId:'T-001',featureSelection:LATER}),false);
|
|
140
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.feature,EARLY);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('run definitions accept featureSelection only for their own feature',t=>{
|
|
144
|
+
const f=project(t);
|
|
145
|
+
assert.deepEqual(validateRunDefinition(f.definition('T-001',f.selected)).featureSelection,{version:1,feature:LATER});
|
|
146
|
+
for(const bad of [{version:1,feature:EARLY},{version:2,feature:LATER},{version:1,feature:LATER,extra:true},null])
|
|
147
|
+
assert.throws(()=>validateRunDefinition(f.definition('T-001',{featureSelection:bad})),{code:'invalid_feature_selection'});
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
test('the human approval phrase 可以,请开始开发 is an explicit start; looser phrasings are not',t=>{
|
|
151
|
+
const f=project(t);
|
|
152
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review',features:[EARLY,LATER]}));
|
|
153
|
+
for(const reply of ['可以,请开始开发','可以,请开始开发。'])
|
|
154
|
+
assert.equal(f.admission('--approval-response',reply).json.approvalIntent,'explicit',reply);
|
|
155
|
+
for(const reply of ['开始开发','请开始开发','可以,请开始开发,但别现在做','可以'])
|
|
156
|
+
assert.equal(f.admission('--approval-response',reply).json.approvalIntent,'not_approval',reply);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('after its last task an explicit run still refreshes context; the next task is the project own one',t=>{
|
|
160
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
161
|
+
const refresh=inspectCmAiContextRefresh({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER,applicableAgentFiles:[],featureSelection:LATER});
|
|
162
|
+
assert.equal(refresh.state,'ready');assert.equal(refresh.nextTask.feature,EARLY);
|
|
163
|
+
assert(refresh.contextFiles.some(file=>file.path===`${LATER}/tasks.md`));
|
|
164
|
+
const admission=inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject,feature:LATER});
|
|
165
|
+
assert.deepEqual(admission.features.map(item=>item.name),[EARLY,LATER]);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
test('with every task done an explicit feature still refuses to print or create, not exit 0',async t=>{
|
|
169
|
+
const f=project(t,{later:'- [x] T-001: reader contract\n'});
|
|
170
|
+
fs.writeFileSync(path.join(f.specsDir,EARLY,'tasks.md'),'- [x] T-008: done\n- [x] T-009: done\n');f.approve();
|
|
171
|
+
const admission=f.admission('--feature',LATER);
|
|
172
|
+
assert.equal(admission.json.state,'complete');assert.equal(admission.json.requestedFeatureComplete,LATER);
|
|
173
|
+
const printed=f.admission('--feature',LATER,'--print-run-definition','--scope','a.js');
|
|
174
|
+
assert.equal(printed.status,1);assert.equal(printed.stdout,'');assert.match(printed.stderr,/feature_tasks_terminal/);
|
|
175
|
+
await assert.rejects(openControlRun(validateRunDefinition(f.definition('T-001',f.selected)),'create'),
|
|
176
|
+
error=>error.code==='task_selection_mismatch'&&/已无待办任务/.test(error.reason));
|
|
177
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution')),false);
|
|
178
|
+
});
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// A standalone cm-fix run that changed a completed cm-ai task's files, was
|
|
2
|
+
// independently reviewed and closed normally, is a later reviewed delivery of
|
|
3
|
+
// that task's code root (2026-10-08, AI潮 author-column-T-010 after
|
|
4
|
+
// api-native-reading-fix-story-return: --rerun-blocked-qa stopped at
|
|
5
|
+
// correction_review_required naming only the fix's reviewed files).
|
|
6
|
+
import test,{after} from 'node:test';
|
|
7
|
+
import assert from 'node:assert/strict';
|
|
8
|
+
import fs from 'node:fs';
|
|
9
|
+
import os from 'node:os';
|
|
10
|
+
import path from 'node:path';
|
|
11
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
13
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
14
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
15
|
+
import {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
16
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
17
|
+
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
18
|
+
import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
|
|
19
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
20
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
21
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
22
|
+
import {completedReviewedDeliveries} from '../runtime/js/cm-ai/reviewed-deliveries.mjs';
|
|
23
|
+
|
|
24
|
+
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-run-delivery-'));
|
|
25
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
26
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
|
|
27
|
+
after(()=>{
|
|
28
|
+
for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
29
|
+
fs.rmSync(isolated,{recursive:true,force:true});
|
|
30
|
+
});
|
|
31
|
+
const events=(onEvent,thread)=>{
|
|
32
|
+
for(const event of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},
|
|
33
|
+
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
|
|
34
|
+
{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// A cm-ai task completes (value 0 -> 1, QA PASS, run_done); then a standalone
|
|
38
|
+
// cm-fix run in the same specs and code root repairs value 1 -> 2, stopping
|
|
39
|
+
// before or after its normal closeout.
|
|
40
|
+
async function completedTaskThenFix({finish}){
|
|
41
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'project-')));
|
|
42
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');fs.mkdirSync(codeProject);
|
|
43
|
+
fs.mkdirSync(path.join(specsDir,'1.value'),{recursive:true});
|
|
44
|
+
for(const name of ['requirements','design'])fs.writeFileSync(path.join(specsDir,'1.value',`${name}.md`),'# Synthetic fixture');
|
|
45
|
+
fs.writeFileSync(path.join(specsDir,'1.value','tasks.md'),'- [ ] T-001: implement\n');
|
|
46
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.value'],specFiles:buildManifest(specsDir)}));
|
|
47
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=0;');
|
|
48
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'Value should be 2.');
|
|
49
|
+
fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
50
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
51
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
52
|
+
const authority=createHostReviewAuthority({hostContextId:'parent-host',reviewerId:'reviewer',adapterId:'codex-review-adapter',
|
|
53
|
+
decide:async()=>({status:'approved'})});
|
|
54
|
+
const execution={configuration:{kind:'synthetic-parent'},timeoutMs:2000,excludedContexts:['parent-host'],hostDecision:null,
|
|
55
|
+
hostDecisionProvider:authority.hostDecisionProvider,
|
|
56
|
+
developer:{provider:'codex',requestedModel:'synthetic',contextId:'author',run:createCodexDeveloperRun({requestedModel:'synthetic',worker:async()=>{
|
|
57
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
|
|
58
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
59
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
60
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',allowed:true,available:true,
|
|
61
|
+
contexts:['parent-review-1','parent-review-2'],run:async(request,{onEvent})=>{
|
|
62
|
+
events(onEvent,`synthetic-review-${request.identity.runId}`);
|
|
63
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
64
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic review'}};}}],
|
|
65
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['parent-host'],authorize:authority.authorize},
|
|
66
|
+
check:createHostCheck({cwd:codeProject,commands:[{id:'existing',command:[process.execPath,'existing.mjs']}]}),
|
|
67
|
+
qaLogHome:path.join(root,'logs'),qaDecisionProvider:{timeoutMs:1000,decide:async binding=>({decisionId:`qa-${binding.identity.runId}`,
|
|
68
|
+
identity:binding.identity,packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-10-08T01:00:00Z'})},
|
|
69
|
+
qaExecutor:{mode:'commands',caseCount:1,timeoutMs:1000,run:async binding=>{
|
|
70
|
+
const report=path.join(specsDir,'.reviews',`${binding.testRunId}.md`);fs.writeFileSync(report,'Synthetic QA PASS');
|
|
71
|
+
return {result:'PASS',passed:1,failed:0,blocked:0,report};}},
|
|
72
|
+
applicableAgentFiles:[],documentationProvider:{timeoutMs:1000,inspect:async binding=>({
|
|
73
|
+
syncId:binding.syncId,identity:binding.identity,packageDigest:binding.packageDigest,contextDigest:binding.contextDigest,
|
|
74
|
+
status:'completed',reason:'Synthetic documentation unchanged',at:'2026-10-08T02:00:00Z'})}};
|
|
75
|
+
const identity={repositoryId:'fixture',runId:'parent-run',taskId:'T-001',attempt:1};
|
|
76
|
+
const definition={version:1,specsDir,codeProject,feature:'1.value',identity,scope:['value.mjs'],requirements:['requirements.md']};
|
|
77
|
+
const parent=await openControlRun(definition,'create',execution);
|
|
78
|
+
try{assert.equal((await parent.host.handle({version:1,requestId:'first',operation:'advance',identity})).code,'run_done');}
|
|
79
|
+
finally{parent.close();}
|
|
80
|
+
|
|
81
|
+
const fixIdentity={repositoryId:'fixture',runId:'story-fix',taskId:'T-FIX-story-fix',attempt:1};
|
|
82
|
+
const permissions=['--allow-reproduction','--allow-red-test','--allow-baseline','--allow-repair','--allow-regression','--allow-final-review','--allow-walkthrough','--allow-finish'];
|
|
83
|
+
const review={model:'synthetic',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
|
|
84
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic',disabledSkills:[]})}};
|
|
85
|
+
let reviews=0;
|
|
86
|
+
const reviewHost=createFixReviewHost({codeProject,hostContextId:'fix-host',review,permissions,workerFactory:()=>async({prompt},{onEvent})=>{
|
|
87
|
+
reviews++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);events(onEvent,`synthetic-fix-review-${reviews}`);
|
|
88
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,
|
|
89
|
+
findings:[],summary:'Synthetic independent fix review'}};}});
|
|
90
|
+
const config={identity:fixIdentity,defect:'Value must be 2',
|
|
91
|
+
reproduction:{cwd:codeProject,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
92
|
+
redTest:{cwd:codeProject,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
93
|
+
baseline:{cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
94
|
+
repair:{scope:['value.mjs'],requirements:['requirements.md']},
|
|
95
|
+
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
|
|
96
|
+
const configuration={hostContextId:'fix-host',...config,causeReview:reviewHost.reviewer};delete configuration.identity;
|
|
97
|
+
const learning={contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No fixture instructions'}};
|
|
98
|
+
const bridge={async call(kind){
|
|
99
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong constant',plan:'Change 1 to 2',affectedPaths:['value.mjs'],
|
|
100
|
+
affectedModules:['value'],crossLayer:false,investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
|
|
101
|
+
if(kind==='fix_repair'){fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=2;');return {outcome:'repaired'};}
|
|
102
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
103
|
+
throw Error(kind);
|
|
104
|
+
}};
|
|
105
|
+
const owner=openFixExecution({specsRoot:specsDir,identity:fixIdentity,configuration,create:true},{...reviewHost.execution,bridge,prepare:async()=>learning});
|
|
106
|
+
try{
|
|
107
|
+
const host=createFixHost({owner,config:{...config,specsRoot:specsDir},permissions,authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority});
|
|
108
|
+
for(const operation of ['advance','red_test','baseline','repair','regression','retrospective','handoff','final_review','publish_review',
|
|
109
|
+
'check_n5','post_review_regression','walkthrough',...(finish?['finish']:[])]){
|
|
110
|
+
const result=await host.handle({requestId:operation,operation});assert(!result?.error,`${operation}: ${JSON.stringify(result)}`);
|
|
111
|
+
}
|
|
112
|
+
assert.equal(owner.status().stage,finish?'completed':'closeout_required');
|
|
113
|
+
}finally{owner.close();}
|
|
114
|
+
assert(reviews>=1);
|
|
115
|
+
const status=async()=>{const run=await openControlRun(definition,'resume',execution);
|
|
116
|
+
try{return await run.host.handle({version:1,requestId:`status-${Math.random()}`,operation:'status',identity});}finally{run.close();}};
|
|
117
|
+
return {codeProject,specsDir,identity,status};
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
test('a completed, independently reviewed cm-fix run is a later reviewed delivery; an unreviewed edit is still refused',{timeout:120000},async()=>{
|
|
121
|
+
const {codeProject,specsDir,identity,status}=await completedTaskThenFix({finish:true});
|
|
122
|
+
const deliveries=completedReviewedDeliveries({specsRoot:specsDir,root:codeProject,identity});
|
|
123
|
+
assert.deepEqual(deliveries.map(item=>[item.runId,item.taskId,item.packages.map(entry=>entry.pkg.changes.map(change=>change.path))]),
|
|
124
|
+
[['story-fix','T-FIX-story-fix',[['value.mjs']]]]);
|
|
125
|
+
assert(Number.isSafeInteger(deliveries[0].packages[0].reviewedAt));
|
|
126
|
+
const accepted=await status();
|
|
127
|
+
assert.equal(accepted.state,'fixture_completed');assert.equal(accepted.code,null,JSON.stringify(accepted));
|
|
128
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(value!==2)process.exit(1)");
|
|
129
|
+
const refused=await status();
|
|
130
|
+
assert.equal(refused.code,'correction_review_required');assert.equal(refused.reason,'未经审查的改动:existing.mjs');
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('a cm-fix run that has not reached its normal completed closeout is not a reviewed delivery',{timeout:120000},async()=>{
|
|
134
|
+
const {codeProject,specsDir,identity,status}=await completedTaskThenFix({finish:false});
|
|
135
|
+
assert.deepEqual(completedReviewedDeliveries({specsRoot:specsDir,root:codeProject,identity}),[]);
|
|
136
|
+
const refused=await status();
|
|
137
|
+
assert.equal(refused.code,'correction_review_required');assert.equal(refused.reason,'未经审查的改动:value.mjs');
|
|
138
|
+
});
|