@aibyzero/cm-workflow 0.16.6 → 0.16.7
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 +12 -1
- package/README.md +7 -1
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +48 -6
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-admission.mjs +34 -10
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +32 -14
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +92 -27
- 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/durable-runner-state.mjs +29 -0
- 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 +52 -6
- 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/task-runner.mjs +6 -1
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- 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/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 +6 -2
- package/scripts/cm-ai-drive.mjs +14 -3
- package/scripts/cm-ai-drive.test.mjs +22 -0
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-host.mjs +18 -6
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-run.mjs +36 -5
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- package/scripts/cm-host-qa-executor.test.mjs +308 -3
- package/scripts/cm-log-event.mjs +26 -5
- 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/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +3 -2
- package/skills/cm-prd/SKILL.md +5 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
|
@@ -184,6 +184,23 @@ test('host create reports the offending unsupported file on stderr before transp
|
|
|
184
184
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
test('host create refuses a scope with AGENTS.md and lists the protected paths before any journal exists',async()=>{
|
|
188
|
+
const f=fixture(),lines=[],output=[];
|
|
189
|
+
try{
|
|
190
|
+
const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
191
|
+
fs.writeFileSync(f.config,JSON.stringify({...definition,scope:['target.mjs','AGENTS.md','.claude/rules/security.md']}));
|
|
192
|
+
fs.writeFileSync(path.join(f.codeProject,'AGENTS.md'),'# rules\n');
|
|
193
|
+
const exit=await hostMain(launchArgs(f),{input:{},output:{write(value){output.push(value);}},error:{write(value){lines.push(value);}}});
|
|
194
|
+
assert.equal(exit,1);assert.deepEqual(output,[]);
|
|
195
|
+
const error=JSON.parse(lines.join('').trim().split('\n').at(-1)).error;
|
|
196
|
+
assert.equal(error.code,'protected_scope');
|
|
197
|
+
assert.match(error.reason,/AGENTS\.md、\.claude\/rules\/security\.md/);
|
|
198
|
+
assert.doesNotMatch(error.reason,/target\.mjs/);
|
|
199
|
+
// No init, no intent, no execution directory, no review record of any kind.
|
|
200
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews')),false);
|
|
201
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
202
|
+
});
|
|
203
|
+
|
|
187
204
|
function runCli(f,mode,action='create'){
|
|
188
205
|
return new Promise((resolve,reject)=>{
|
|
189
206
|
const args=[...launchArgs(f)];args[4]=action;
|
|
@@ -1250,3 +1267,74 @@ test('#11 #31 protected driver deletes, sets the executable bit, creates new fil
|
|
|
1250
1267
|
assert.equal(changes.get('new/Legacy.swift').after.mode,0o644);
|
|
1251
1268
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1252
1269
|
});
|
|
1270
|
+
|
|
1271
|
+
// Explicit batch choice (2026-10-06 AI潮 6.api-native-reading before 5.author-column).
|
|
1272
|
+
const withEarlierPendingFeature=f=>{
|
|
1273
|
+
const early=path.join(f.specsDir,'0.early');fs.mkdirSync(early);
|
|
1274
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(early,name),'# Early\n');
|
|
1275
|
+
fs.writeFileSync(path.join(early,'tasks.md'),'- [ ] T-001: earlier batch, after this one\n');
|
|
1276
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.early','1.work'],specFiles:buildManifest(f.specsDir)}));
|
|
1277
|
+
};
|
|
1278
|
+
const serveOnce=(f,extra,mode='create')=>{
|
|
1279
|
+
const args=[...launchArgs(f)];args[4]=mode;
|
|
1280
|
+
const out=spawnSync(process.execPath,[cli,...args,...extra],{encoding:'utf8',timeout:20000,
|
|
1281
|
+
input:[request('status')].map(JSON.stringify).join('\n')+'\n'});
|
|
1282
|
+
return {...out,rows:out.stdout.trim().split('\n').filter(Boolean).map(JSON.parse)};
|
|
1283
|
+
};
|
|
1284
|
+
test('host --feature creates a later approved feature run; without it the original task_selection_mismatch stays',()=>{
|
|
1285
|
+
const f=fixture();
|
|
1286
|
+
try{
|
|
1287
|
+
withEarlierPendingFeature(f);
|
|
1288
|
+
const refused=serveOnce(f,[]);
|
|
1289
|
+
assert.equal(refused.status,1);assert.match(refused.stderr,/task_selection_mismatch/);assert.match(refused.stderr,/--feature 1\.work/);
|
|
1290
|
+
const wrong=serveOnce(f,['--feature','0.early']);
|
|
1291
|
+
assert.equal(wrong.status,1);assert.match(wrong.stderr,/invalid_arguments/);
|
|
1292
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);
|
|
1293
|
+
const created=serveOnce(f,['--feature','1.work']);
|
|
1294
|
+
assert.equal(created.status,0,created.stderr);
|
|
1295
|
+
assert.equal(created.rows[0].type,'host_ready');
|
|
1296
|
+
assert.equal(created.rows.find(row=>row.requestId==='status').result.identity.taskId,'T-001');
|
|
1297
|
+
const resumed=serveOnce(f,['--feature','1.work'],'resume');
|
|
1298
|
+
assert.equal(resumed.status,0,resumed.stderr);assert.equal(resumed.rows[0].type,'host_ready');
|
|
1299
|
+
// The choice is bound into the run: resuming without it is a different run.
|
|
1300
|
+
const unbound=serveOnce(f,[],'resume');
|
|
1301
|
+
assert.equal(unbound.status,1);assert.match(unbound.stderr,/fingerprint_mismatch/);
|
|
1302
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'0.early','tasks.md'),'utf8'),/- \[ \] T-001/);
|
|
1303
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
// Kept from the 0.16.6 project patch: runs T-001..T-003 of that batch were
|
|
1307
|
+
// created with --runtime codex --review-runtime claude and resume only with it.
|
|
1308
|
+
const crossToolRoles='version: 1\nruntimes: {available: both}\nroles:\n coder: {adapter: codex-cli, source: subscription}\n reviewer: {adapter: claude-cli, source: subscription}\n';
|
|
1309
|
+
test('--review-runtime binds the other tool as reviewer and must be repeated on resume',async()=>{
|
|
1310
|
+
const f=fixture(),bridge=createHostToolBridge();
|
|
1311
|
+
try{
|
|
1312
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
1313
|
+
const definition=readRunDefinition(f.config);
|
|
1314
|
+
const {claudeReviewFingerprint}=await import('../runtime/js/cm-ai/worker-claude.mjs');
|
|
1315
|
+
const model='fixture';const review={model,disabledSkills:[],preflight:{passed:true,provider:'claude',
|
|
1316
|
+
config_fingerprint:claudeReviewFingerprint({cwd:f.codeProject,model}),prompt_transport:'stdin'}};
|
|
1317
|
+
const make=options=>createConversationExecution(definition,'native-host-fixture',bridge,review,null,null,false,'codex',options);
|
|
1318
|
+
const original=make({reviewRuntime:'claude'});
|
|
1319
|
+
assert.equal(original.developer.provider,'codex');assert.equal(original.reviewers[0].provider,'claude');
|
|
1320
|
+
assert.equal(original.configuration.reviewRuntime,'claude');
|
|
1321
|
+
const first=await openControlRun(definition,'create',original);first.close();
|
|
1322
|
+
const resumed=await openControlRun(definition,'resume',make({reviewRuntime:'claude'}));resumed.close();
|
|
1323
|
+
await assert.rejects(openControlRun(definition,'resume',make({})),{code:'fingerprint_mismatch'});
|
|
1324
|
+
assert.throws(()=>make({reviewRuntime:'codex'}),{code:'runtime_selection_mismatch'});
|
|
1325
|
+
assert.throws(()=>make({reviewRuntime:'other'}),{code:'invalid_runtime'});
|
|
1326
|
+
assert.throws(()=>createConversationExecution(definition,'native-host-fixture',bridge,{...review,preflight:{}},1,null,false,'codex',{reviewRuntime:'claude'}),{code:'tool_preflight_missing'});
|
|
1327
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1328
|
+
});
|
|
1329
|
+
test('ordinary CLI accepts --review-runtime claude under a Codex host and refuses an invalid runtime before any journal',()=>{
|
|
1330
|
+
for(const reviewRuntime of ['claude','other']){
|
|
1331
|
+
const f=fixture();
|
|
1332
|
+
try{
|
|
1333
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.yml'),crossToolRoles);
|
|
1334
|
+
const out=serveOnce(f,['--runtime','codex','--review-runtime',reviewRuntime]);
|
|
1335
|
+
if(reviewRuntime==='claude'){assert.equal(out.status,0,out.stderr);assert.equal(out.rows[0].type,'host_ready');}
|
|
1336
|
+
else{assert.equal(out.status,1);assert.match(out.stderr,/invalid_runtime/);
|
|
1337
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);}
|
|
1338
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
// A task scope with project rules or workflow evidence (AGENTS.md, .claude/,
|
|
2
|
+
// tasks.md, .cm-*) can never be developed: the developer adapter refuses it
|
|
3
|
+
// before any provider runs. Regression for the 2026-10-06 dogfood T-006 run,
|
|
4
|
+
// which a pre-gate host stranded at unknown/execution_error with no exit.
|
|
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 {digest,requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
import {protectedScopePaths,validateDeveloperScope} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
12
|
+
import {readRunnerHistory,runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
13
|
+
import {assertNoUnrecordedPriorCode,prepareReviewedEvidenceSupersession} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
14
|
+
import {assertCreatableScope,openControlRun,validateRunDefinition} from './cm-ai-run.mjs';
|
|
15
|
+
import {createCmAiBatch} from './cm-ai-batch-run.mjs';
|
|
16
|
+
import {operatorGuidance} from '../runtime/js/cm-ai/operator-guidance.mjs';
|
|
17
|
+
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
18
|
+
|
|
19
|
+
const skip=!isSupportedExecutionPlatform();
|
|
20
|
+
const test=(name,fn)=>nodeTest(name,{skip},fn);
|
|
21
|
+
const PROTECTED=['AGENTS.md','.claude/rules/security.md'];
|
|
22
|
+
// The T-006 production shape: a task-learning (V3) run of a numbered feature.
|
|
23
|
+
const FEATURE='6.api-native-reading';
|
|
24
|
+
|
|
25
|
+
test('protected scope paths are listed by the same rule the developer adapter enforces',()=>{
|
|
26
|
+
const scope=['src/app.js',...PROTECTED,'docs/CLAUDE.md','specs/tasks.md','.cm-workflow.yml','.codex/config.toml'];
|
|
27
|
+
assert.deepEqual(protectedScopePaths(scope),[...PROTECTED,'docs/CLAUDE.md','specs/tasks.md','.cm-workflow.yml','.codex/config.toml']);
|
|
28
|
+
assert.deepEqual(protectedScopePaths(['src/app.js','docs/agents-guide.md']),[]);
|
|
29
|
+
for(const file of protectedScopePaths(scope))assert.throws(()=>validateDeveloperScope(['src/app.js',file]),{code:'protected_scope'});
|
|
30
|
+
assert.doesNotThrow(()=>validateDeveloperScope(['src/app.js','docs/agents-guide.md']));
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
function projectFixture(t){
|
|
34
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-protected-create-')));
|
|
35
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
36
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');
|
|
37
|
+
fs.mkdirSync(path.join(specsDir,FEATURE),{recursive:true});fs.mkdirSync(codeProject);
|
|
38
|
+
fs.writeFileSync(path.join(specsDir,FEATURE,'tasks.md'),'- [ ] T-006: fixture\n');
|
|
39
|
+
fs.writeFileSync(path.join(codeProject,'AGENTS.md'),'# rules\n');
|
|
40
|
+
return {root,specsDir,codeProject};
|
|
41
|
+
}
|
|
42
|
+
const reviewsAbsent=f=>assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews')),false,'a refused create must leave no .reviews/.execution');
|
|
43
|
+
|
|
44
|
+
test('create refuses a scope with AGENTS.md before any journal, listing only the protected paths',async t=>{
|
|
45
|
+
const f=projectFixture(t);
|
|
46
|
+
const definition=validateRunDefinition({version:1,specsDir:f.specsDir,codeProject:f.codeProject,feature:FEATURE,
|
|
47
|
+
identity:{repositoryId:'fixture',runId:'api-native-reading-T-006',taskId:'T-006',attempt:1},
|
|
48
|
+
scope:['src/app.js',...PROTECTED],requirements:[]});
|
|
49
|
+
assert.throws(()=>assertCreatableScope(definition.scope),error=>error.code==='protected_scope'
|
|
50
|
+
&&error.paths.join()===PROTECTED.join()&&error.reason.includes('AGENTS.md、.claude/rules/security.md')&&!error.reason.includes('src/app.js'));
|
|
51
|
+
await assert.rejects(openControlRun(definition,'create'),error=>error.code==='protected_scope'&&error.reason.includes('AGENTS.md'));
|
|
52
|
+
reviewsAbsent(f);
|
|
53
|
+
assert.doesNotThrow(()=>assertCreatableScope(['src/app.js','docs/agents-guide.md']));
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a batch refuses a member to be created with a protected scope before it locks, logs or opens any run',t=>{
|
|
57
|
+
const f=projectFixture(t);let opened=0;
|
|
58
|
+
const configuration={version:1,repositoryId:'fixture',batchId:'protected-scope-batch',specsDir:f.specsDir,codeProject:f.codeProject,
|
|
59
|
+
tasks:[{feature:FEATURE,taskId:'T-005',scope:['src/app.js'],requirements:[]},
|
|
60
|
+
{feature:FEATURE,taskId:'T-006',scope:['src/tab.js',...PROTECTED],requirements:[]}]};
|
|
61
|
+
assert.throws(()=>createCmAiBatch({configuration,executionFor:async()=>{opened++;return {};},logHome:path.join(f.root,'logs')}),
|
|
62
|
+
error=>error.code==='protected_scope'&&error.reason.startsWith(`${FEATURE}/T-006: `)&&error.reason.includes('.claude/rules/security.md'));
|
|
63
|
+
assert.equal(opened,0);reviewsAbsent(f);
|
|
64
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'运行日志.jsonl')),false);assert.equal(fs.existsSync(path.join(f.root,'logs')),false);
|
|
65
|
+
// A bootstrap rule task keeps its own instruction targets (host-bootstrap checks its business scope).
|
|
66
|
+
assert.doesNotThrow(()=>createCmAiBatch({configuration,executionFor:async()=>({}),logHome:path.join(f.root,'logs'),
|
|
67
|
+
bootstrapKeys:[`${FEATURE}/T-006`]}));
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
async function runnerFixture(t,scope){
|
|
71
|
+
const {createTaskRunner}=await import('../runtime/js/cm-ai/task-runner.mjs');
|
|
72
|
+
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
73
|
+
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-protected-scope-')));
|
|
74
|
+
const root=path.join(temp,'code'),specsRoot=path.join(temp,'specs'),reviewsDir=path.join(specsRoot,'.reviews');
|
|
75
|
+
fs.mkdirSync(path.join(root,'.claude','rules'),{recursive:true});fs.mkdirSync(reviewsDir,{recursive:true});
|
|
76
|
+
fs.mkdirSync(path.join(specsRoot,FEATURE));
|
|
77
|
+
const tasksPath=path.join(specsRoot,FEATURE,'tasks.md');fs.writeFileSync(tasksPath,'- [ ] T-006: fixture\n');
|
|
78
|
+
for(const [file,content] of Object.entries({'code.js':'old\n','requirements.md':'fixture\n','AGENTS.md':'# rules\n',
|
|
79
|
+
'.claude/rules/security.md':'# security\n'}))fs.writeFileSync(path.join(root,file),content);
|
|
80
|
+
const identity={repositoryId:'fixture',runId:'api-native-reading-T-006',taskId:'T-006',attempt:1};
|
|
81
|
+
const owner={tasksPath,feature:'api-native-reading',specsRoot,identity:{repositoryId:identity.repositoryId,runId:identity.runId},
|
|
82
|
+
fingerprints:{workflow:digest('protected-scope'),config:digest('fixture'),inputs:digest('original')},create:true};
|
|
83
|
+
let store=openTaskExecutionStore(owner),developerCalls=0,developerRun=()=>{throw new Error('developer must not run');};
|
|
84
|
+
const options={root,identity,scope,requirements:['requirements.md'],excludedContexts:['main'],timeoutMs:1000,
|
|
85
|
+
developer:{provider:'claude',requestedModel:'current-session',contextId:'cm-conversation-author',
|
|
86
|
+
run:(...args)=>{developerCalls++;return developerRun(...args);}},
|
|
87
|
+
reviewers:[{id:'reviewer',adapterId:'claude-review-adapter',provider:'claude',requestedModel:'fixture',allowed:true,
|
|
88
|
+
available:true,contexts:['review-1','review-2'],run:()=>{throw new Error('reviewer must not run');}}],
|
|
89
|
+
check:()=>{throw new Error('checks must not run');},
|
|
90
|
+
taskCompletion:{reviewsDir,handoffs:[1,2].map(n=>path.join(reviewsDir,`api-native-reading-T-006-a${n}-handoff.json`))},
|
|
91
|
+
taskLearning:{feature:FEATURE,hostHandoff:true},
|
|
92
|
+
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main'],
|
|
93
|
+
authorize:()=>{throw new Error('review must not be authorized');}}};
|
|
94
|
+
const make=mode=>createTaskRunner({...options,persistence:{store,mode,version:3}});
|
|
95
|
+
const statePath=path.join(reviewsDir,'.execution',identity.runId,'state.json');
|
|
96
|
+
const reopen=()=>{store.close();store=openTaskExecutionStore({...owner,create:false});return make('resume');};
|
|
97
|
+
t.after(()=>{store.close();fs.rmSync(temp,{recursive:true,force:true});});
|
|
98
|
+
const files=[{scope:'project',path:'AGENTS.md',sha256:digest('agents')}];
|
|
99
|
+
const learningInput={version:1,workflow:'cm-ai',phase:'task_learning_input',feature:FEATURE,identity,
|
|
100
|
+
learningDigest:digest({version:1,feature:FEATURE,identity,files}),learningFiles:files};
|
|
101
|
+
const develop=(id='develop-1')=>({version:1,id,identity,kind:'develop',learningInput});
|
|
102
|
+
return {identity,options,statePath,root,specsRoot,tasksPath,develop,make:()=>make('create'),resume:()=>make('resume'),reopen,records:()=>store.snapshot().records,
|
|
103
|
+
developerCalls:()=>developerCalls,setDeveloper:fn=>{developerRun=fn;},close:()=>store.close(),
|
|
104
|
+
reopenStore:()=>{store=openTaskExecutionStore({...owner,create:false});}};
|
|
105
|
+
}
|
|
106
|
+
function rechain(records){
|
|
107
|
+
let previousDigest=null;
|
|
108
|
+
for(const row of records){row.previousDigest=previousDigest;const {digest:old,...body}=row;row.digest=digest(body);previousDigest=row.digest;}
|
|
109
|
+
return records;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
test('a protected scope blocks before dispatch as a definite blocked/protected_scope, never unknown',async t=>{
|
|
113
|
+
const f=await runnerFixture(t,['code.js',...PROTECTED]);
|
|
114
|
+
const result=await f.make().executeEffect(f.develop());
|
|
115
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'protected_scope');
|
|
116
|
+
for(const file of PROTECTED)assert(result.reason.includes(file),result.reason);
|
|
117
|
+
assert.equal(f.developerCalls(),0);assert.deepEqual(result.calls,[]);
|
|
118
|
+
assert.deepEqual(f.records().map(row=>row.payload.type),['init','effect-intent','effect-checkpoint']);
|
|
119
|
+
// The block replays as recorded, is terminal, and a later develop is refused without dispatch.
|
|
120
|
+
const resumed=f.reopen();
|
|
121
|
+
assert.equal(resumed.status().state,'blocked');assert.equal(resumed.status().code,'protected_scope');
|
|
122
|
+
const retry=await resumed.executeEffect(f.develop('develop-2'));
|
|
123
|
+
assert.equal(retry.outcome,'rejected');assert.equal(retry.code,'stage_mismatch');assert.equal(f.developerCalls(),0);
|
|
124
|
+
const guidance=operatorGuidance({workflow:'cm-ai',identity:f.identity,state:'blocked',code:'protected_scope',pendingAction:'none'});
|
|
125
|
+
assert.equal(guidance.recoveryOperation,null);assert.match(guidance.nextStep,/新 runId/);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Rewrite the new checkpoint into the exact shape a pre-gate host journaled for
|
|
129
|
+
// T-006: the adapter's refusal escaped as unknown/execution_error with one
|
|
130
|
+
// started developer call that never returned (state.json of 2026-10-05).
|
|
131
|
+
function strandLikeT006(f){
|
|
132
|
+
const state=JSON.parse(fs.readFileSync(f.statePath,'utf8')),records=state.records;
|
|
133
|
+
const init=records[0].payload,intent=records[1].payload.effect,last=records[2];
|
|
134
|
+
const session=init.session,original=init.baseline,config=init.config;
|
|
135
|
+
const request=requestFor({invocationId:`${session}.1`,identity:{...config.identity,attempt:1},role:'developer',
|
|
136
|
+
provider:config.developer.provider,requestedModel:config.developer.requestedModel,contextId:config.developer.contextId,
|
|
137
|
+
payload:{scope:config.scope,requirements:original.files.filter(file=>config.requirements.includes(file.path)),priorReview:null,
|
|
138
|
+
learningInput:intent.learningInput}});
|
|
139
|
+
const call={invocationId:request.invocationId,contextId:config.developer.contextId,provider:config.developer.provider,
|
|
140
|
+
requestedModel:config.developer.requestedModel,effectiveModel:'unknown',channel:'fixture',started:true,terminal:'unknown',
|
|
141
|
+
requestDigest:request.requestDigest,resultDigest:null};
|
|
142
|
+
const checkpoint={...last.payload.checkpoint,state:'unknown',code:'execution_error',reason:null,sequence:1,calls:[call]};
|
|
143
|
+
checkpoint.cache=[{effect:intent,digest:digest(intent),result:runnerStatus(checkpoint,config)}];
|
|
144
|
+
records[2]={...last,payload:{...last.payload,checkpoint}};
|
|
145
|
+
const {revision,...body}=state;body.records=rechain(records);
|
|
146
|
+
f.close();fs.writeFileSync(f.statePath,JSON.stringify({...body,revision:digest(body)})+'\n',{mode:0o600});f.reopenStore();
|
|
147
|
+
return call;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
test('a stranded T-006 journal replays as blocked/protected_scope and its records stay byte for byte',async t=>{
|
|
151
|
+
const f=await runnerFixture(t,['code.js',...PROTECTED]);
|
|
152
|
+
await f.make().executeEffect(f.develop());
|
|
153
|
+
const call=strandLikeT006(f);
|
|
154
|
+
const legacyBytes=fs.readFileSync(f.statePath);
|
|
155
|
+
const records=JSON.parse(legacyBytes).records;
|
|
156
|
+
assert.deepEqual(records.map(row=>row.payload.type),['init','effect-intent','effect-checkpoint']);
|
|
157
|
+
assert.equal(records[2].payload.checkpoint.state,'unknown');assert.equal(records[2].payload.checkpoint.code,'execution_error');
|
|
158
|
+
// Before this fix the same records had no exit: unknown, reconcile, and no pending intent to abandon.
|
|
159
|
+
const history=readRunnerHistory(records,records[0].payload.config,3);
|
|
160
|
+
assert.equal(history.pending,null);assert.equal(history.pendingAbandonable,false);
|
|
161
|
+
assert.equal(history.state.state,'blocked');assert.equal(history.state.code,'protected_scope');
|
|
162
|
+
for(const file of PROTECTED)assert(history.state.reason.includes(file),history.state.reason);
|
|
163
|
+
const resumed=f.resume();
|
|
164
|
+
const status=resumed.status();
|
|
165
|
+
assert.equal(status.state,'blocked');assert.equal(status.code,'protected_scope');
|
|
166
|
+
assert.deepEqual(status.calls,[call]);
|
|
167
|
+
const retry=await resumed.executeEffect(f.develop('develop-2'));
|
|
168
|
+
assert.equal(retry.outcome,'rejected');assert.equal(f.developerCalls(),0);
|
|
169
|
+
// abandon_effect is not needed and still refuses: there is no pending intent.
|
|
170
|
+
assert.equal(resumed.abandonEffect({allowed:true,reason:'protected scope'}).outcome,'rejected');
|
|
171
|
+
assert.equal(records[2].payload.checkpoint.learningResult,null);
|
|
172
|
+
// The exit: a new run by the original gates. Both read the stranded journal and admit it.
|
|
173
|
+
f.close();
|
|
174
|
+
const next={specsDir:f.specsRoot,codeProject:f.root,feature:FEATURE,tasksPath:f.tasksPath,
|
|
175
|
+
identity:{...f.identity,runId:'api-native-reading-T-006-r2'}};
|
|
176
|
+
assert.doesNotThrow(()=>assertNoUnrecordedPriorCode(next));
|
|
177
|
+
const supersession=prepareReviewedEvidenceSupersession({...next,reason:'scope 移除受保护规则文件后重建'});
|
|
178
|
+
assert.deepEqual(supersession.previousRunIds,[f.identity.runId]);
|
|
179
|
+
f.reopenStore();
|
|
180
|
+
assert.deepEqual(fs.readFileSync(f.statePath),legacyBytes);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
test('the same unknown developer shape without a protected scope is still unknown',async t=>{
|
|
184
|
+
const f=await runnerFixture(t,['code.js']);
|
|
185
|
+
f.setDeveloper(()=>{throw new Error('adapter failure');});
|
|
186
|
+
const result=await f.make().executeEffect(f.develop());
|
|
187
|
+
assert.equal(result.state,'unknown');assert.equal(result.code,'execution_error');assert.equal(f.developerCalls(),1);
|
|
188
|
+
// The genuine pre-gate shape has the same call fields the T-006 rewrite uses.
|
|
189
|
+
assert.deepEqual(Object.keys(result.calls[0]),['invocationId','contextId','provider','requestedModel','effectiveModel',
|
|
190
|
+
'channel','started','terminal','requestDigest','resultDigest']);
|
|
191
|
+
assert.equal(result.calls[0].terminal,'unknown');assert.equal(result.calls[0].resultDigest,null);
|
|
192
|
+
const resumed=f.reopen();
|
|
193
|
+
assert.equal(resumed.status().state,'unknown');assert.equal(resumed.status().code,'execution_error');
|
|
194
|
+
});
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -20,6 +20,7 @@ import {recordEffectAbandonment} from '../runtime/js/cm-ai/effect-abandon-log.mj
|
|
|
20
20
|
import {reviewConsumedHandoff,reviewedHandoffConflict} from '../runtime/js/cm-ai/host-handoff.mjs';
|
|
21
21
|
import {RUN_ID_RULE,validRunId} from './cm-log-event.mjs';
|
|
22
22
|
import {JOURNAL_PAYLOAD_LIMIT,boundedReason} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
23
|
+
import {protectedScopePaths} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
23
24
|
import {closeoutPolicyCandidates} from '../runtime/js/cm-ai/knowledge-closeout.mjs';
|
|
24
25
|
|
|
25
26
|
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.';
|
|
@@ -114,7 +115,7 @@ export async function createCodexExecution(configuration,authority){
|
|
|
114
115
|
// original checks/handoff/Review. The semantic bridge never writes it.
|
|
115
116
|
const {isFinalCmAiTask}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
116
117
|
const sync=documentationPaths.length>0&&isFinalCmAiTask({specsDir:specsRoot,codeProject:config.codeProject,
|
|
117
|
-
feature:workflowDefinition.feature,taskId:bound.identity.taskId});
|
|
118
|
+
feature:workflowDefinition.feature,taskId:bound.identity.taskId,featureSelection:workflowDefinition.featureSelection?.feature});
|
|
118
119
|
const protectedWorker=sync?(request,control)=>worker({...request,prompt:
|
|
119
120
|
'Before returning, inspect and synchronize these already-approved ordinary documentation paths with the implemented behavior. '
|
|
120
121
|
+'Keep accurate unchanged documents unchanged. No extra scope or protected instruction writes. '
|
|
@@ -150,6 +151,7 @@ export function validateRunDefinition(input){
|
|
|
150
151
|
const keys=['version','specsDir','codeProject','feature','identity','scope','requirements'];
|
|
151
152
|
if(value&&Object.hasOwn(value,'codeProjects'))keys.push('codeProjects');
|
|
152
153
|
if(value&&Object.hasOwn(value,'taskSelection'))keys.push('taskSelection');
|
|
154
|
+
if(value&&Object.hasOwn(value,'featureSelection'))keys.push('featureSelection');
|
|
153
155
|
if(!value||typeof value!=='object')fail('invalid_config: expected an object');
|
|
154
156
|
const unexpected=Object.keys(value).filter(key=>!keys.includes(key));
|
|
155
157
|
const missing=keys.filter(key=>!Object.hasOwn(value,key));
|
|
@@ -172,6 +174,11 @@ export function validateRunDefinition(input){
|
|
|
172
174
|
if(Object.hasOwn(value,'taskSelection')&&(!value.taskSelection||value.taskSelection.version!==1
|
|
173
175
|
||Object.keys(value.taskSelection).sort().join(',')!=='taskId,version'
|
|
174
176
|
||value.taskSelection.taskId!==value.identity.taskId))fail('invalid_task_selection');
|
|
177
|
+
// Explicit batch choice: run this approved feature even while an earlier one
|
|
178
|
+
// has pending tasks. Bound into the definition, so it is part of the run.
|
|
179
|
+
if(Object.hasOwn(value,'featureSelection')&&(!value.featureSelection||value.featureSelection.version!==1
|
|
180
|
+
||Object.keys(value.featureSelection).sort().join(',')!=='feature,version'
|
|
181
|
+
||value.featureSelection.feature!==value.feature))fail('invalid_feature_selection');
|
|
175
182
|
for(const key of ['scope','requirements']){
|
|
176
183
|
if(!Array.isArray(value[key])||(!value[key].length&&!(key==='requirements'))||value[key].length>256
|
|
177
184
|
||value[key].some(p=>typeof p!=='string'||!p||p.includes('\\')||p.includes('\0')
|
|
@@ -185,6 +192,18 @@ export function validateRunDefinition(input){
|
|
|
185
192
|
}
|
|
186
193
|
return value;
|
|
187
194
|
}
|
|
195
|
+
// Read-only, shared by every create entry before it locks, logs or builds an
|
|
196
|
+
// execution: the single-task host, openControlRun and the batch owner.
|
|
197
|
+
export function assertCreatableScope(scope){
|
|
198
|
+
const paths=protectedScopePaths(scope);
|
|
199
|
+
if(paths.length)throw Object.assign(new Error('protected_scope'),{code:'protected_scope',paths,reason:protectedScopeReason(paths)});
|
|
200
|
+
}
|
|
201
|
+
export function protectedScopeReason(paths){
|
|
202
|
+
const listed=paths.slice(0,20).join('、')+(paths.length>20?` 等 ${paths.length} 个`:'');
|
|
203
|
+
return `任务 scope 含受保护路径:${listed}。开发者不能写项目规则(AGENTS.md、CLAUDE.md、.claude/、.codex/)、`
|
|
204
|
+
+'tasks.md、.cm-* 或审查记录;未建运行,未写任何运行记录。从 scope 移除这些路径后重新生成运行定义再 create;'
|
|
205
|
+
+'规则文件的修改走 docs/js-workflow-control.md「项目规则文件的修改通道」。';
|
|
206
|
+
}
|
|
188
207
|
// Create-time only: an existing journal keeps resuming (and can be abandoned)
|
|
189
208
|
// exactly as before, while a new run can no longer strand its first develop
|
|
190
209
|
// effect on a run ID the run log refuses.
|
|
@@ -235,6 +254,11 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
235
254
|
const {conversationProtection,externalConversationDefinition}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
236
255
|
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
237
256
|
if(mode==='create')assertCreatableRunId(definition?.identity);
|
|
257
|
+
// The developer adapter refuses these paths on every dispatch. Refuse the
|
|
258
|
+
// run here, before any journal, intent or execution directory exists, so it
|
|
259
|
+
// cannot strand its first develop effect. A bootstrap run's own instruction
|
|
260
|
+
// paths are checked by createHostBootstrap against its business scope.
|
|
261
|
+
if(mode==='create'&&!execution?.bootstrap)assertCreatableScope(definition?.scope);
|
|
238
262
|
if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
|
|
239
263
|
if(allowAbandonEffect&&mode!=='resume')fail('effect_abandon_unavailable');
|
|
240
264
|
if(allowBootstrapReviewRecovery&&mode!=='resume')fail('bootstrap_review_recovery_unavailable');
|
|
@@ -250,7 +274,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
250
274
|
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
251
275
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
252
276
|
const {createCmAiHost}=await import('../runtime/js/cm-ai/host.mjs');
|
|
253
|
-
const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
277
|
+
const {inspectCmAiAdmission,matchesCmAiTaskSelection,explainCmAiTaskSelection,selectedFeature}=await import('../runtime/js/cm-ai/cm-ai-admission.mjs');
|
|
254
278
|
const {captureReviewBaseline}=await import('../runtime/js/cm-ai/review-package.mjs');
|
|
255
279
|
if(execution!==null){
|
|
256
280
|
const {shape,json,validCallTimeout}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
@@ -299,15 +323,21 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
299
323
|
if(selectedRoots){
|
|
300
324
|
if(!execution||conversationProtection(execution)===null)fail('multi_root_protection_required');
|
|
301
325
|
for(const root of definition.codeProjects){
|
|
302
|
-
const selected=inspectCmAiAdmission({specsDir,codeProject:root});
|
|
326
|
+
const selected=inspectCmAiAdmission({specsDir,codeProject:root,...selectedFeature(definition.featureSelection?.feature)});
|
|
303
327
|
if(mode==='create'&&!matchesCmAiTaskSelection(selected,feature,identity.taskId,selection))
|
|
304
328
|
return {blocked:selected,close:()=>{}};
|
|
305
329
|
}
|
|
306
330
|
}
|
|
307
331
|
const developer=execution?.documentationSync
|
|
308
332
|
?(await import('../runtime/js/cm-ai/host-documentation.mjs')).withHostDocumentation({developer:execution.developer,
|
|
309
|
-
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope,parallelSelection:selection
|
|
310
|
-
|
|
333
|
+
documentationSync:execution.documentationSync,specsDir,codeProject,feature,scope,parallelSelection:selection,
|
|
334
|
+
featureSelection:definition.featureSelection?.feature}):execution?.developer;
|
|
335
|
+
const admission=inspectCmAiAdmission({specsDir,codeProject,...selectedFeature(definition.featureSelection?.feature)});
|
|
336
|
+
// An explicitly selected feature with nothing left never creates a run, even
|
|
337
|
+
// when the project as a whole is complete.
|
|
338
|
+
if(mode==='create'&&definition.featureSelection&&admission.requestedFeatureComplete===feature)
|
|
339
|
+
throw Object.assign(new Error('task_selection_mismatch'),{code:'task_selection_mismatch',
|
|
340
|
+
reason:explainCmAiTaskSelection({...admission,state:'ready'},{feature,taskId:identity.taskId,selection})});
|
|
311
341
|
if(mode==='create'&&admission.state!=='ready')return {blocked:admission,close:()=>{}};
|
|
312
342
|
if(mode==='create'&&!matchesCmAiTaskSelection(admission,feature,identity.taskId,selection))
|
|
313
343
|
throw Object.assign(new Error('task_selection_mismatch'),{code:'task_selection_mismatch',
|
|
@@ -433,6 +463,7 @@ async function openControlRunOwned(definition,mode,execution=null,{rerunUnknownQ
|
|
|
433
463
|
taskLearning:{feature,hostHandoff:true}})},
|
|
434
464
|
// The entry validates the declaration (single line, with --rerun-blocked-qa) before any durable write.
|
|
435
465
|
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,
|
|
466
|
+
...(definition.featureSelection?{featureSelection:definition.featureSelection.feature}:{}),
|
|
436
467
|
...(knowledgeCloseout===null?{}:{knowledgeCloseout,...(definition.codeProjects?{codeProjects:definition.codeProjects}:{})}),
|
|
437
468
|
...(qaEnvironmentFailure===null?{}:{qaEnvironmentFailure}),allowAbandonReview,allowAbandonEffect,allowBootstrapReviewRecovery,...(holdRevision?{holdRevision}:{}),...(selection===null?{}:{parallelSelection:selection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
438
469
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// A project's 运行日志.jsonl only grows. Past 1 MiB, cm-fix read it whole under
|
|
2
|
+
// the review-material limit and every fix run failed at its completion
|
|
3
|
+
// projection, including each later resume (2026-10-07, AI潮
|
|
4
|
+
// api-native-reading-fix-story-return: check_n5 limit_exceeded, then every resume).
|
|
5
|
+
import test 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 {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
11
|
+
import {createFixHost} from '../runtime/js/cm-fix/host.mjs';
|
|
12
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
|
+
import {eventsAt} from '../runtime/js/cm-fix/finish.mjs';
|
|
14
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
15
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
16
|
+
import {readReviewSourceFiles} from '../runtime/js/cm-ai/review-package.mjs';
|
|
17
|
+
|
|
18
|
+
const MiB=1024*1024;
|
|
19
|
+
// Valid rows of other runs and workflows, as a long-lived project accumulates.
|
|
20
|
+
function growLog(file,bytes){
|
|
21
|
+
const filler='x'.repeat(900);let written=0,index=0;
|
|
22
|
+
const lines=[];
|
|
23
|
+
while(written<bytes){
|
|
24
|
+
const line=JSON.stringify({schema_version:1,workflow:index%2?'cm-ai':'cm-prd',event:'progress',phase:'start',
|
|
25
|
+
run_id:`other-run-${index}`,at:'2026-10-01T00:00:00Z',detail:filler})+'\n';
|
|
26
|
+
lines.push(line);written+=Buffer.byteLength(line);index++;
|
|
27
|
+
}
|
|
28
|
+
fs.appendFileSync(file,lines.join(''));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
test('cm-fix completes check_n5, post_review_regression, walkthrough and finish with a run log above 1 MiB',{timeout:120000},async t=>{
|
|
32
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-large-log-')));
|
|
33
|
+
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
34
|
+
const logHome=process.env.CM_WORKFLOW_LOG_HOME;process.env.CM_WORKFLOW_LOG_HOME=path.join(root,'mirror');
|
|
35
|
+
t.after(()=>{if(logHome===undefined)delete process.env.CM_WORKFLOW_LOG_HOME;else process.env.CM_WORKFLOW_LOG_HOME=logHome;
|
|
36
|
+
fs.rmSync(root,{recursive:true,force:true});});
|
|
37
|
+
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
38
|
+
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
39
|
+
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
40
|
+
fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
41
|
+
const config={identity:{repositoryId:'fixture',runId:'large-log',taskId:'T-FIX-large-log',attempt:1},defect:'Wrong value',
|
|
42
|
+
reproduction:{cwd,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
43
|
+
redTest:{cwd,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
44
|
+
baseline:{cwd,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
45
|
+
repair:{scope:['value.mjs'],requirements:['value.mjs']},
|
|
46
|
+
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['value is 2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
|
|
47
|
+
const permissions=['--allow-reproduction','--allow-red-test','--allow-baseline','--allow-repair','--allow-regression','--allow-final-review','--allow-walkthrough','--allow-finish'];
|
|
48
|
+
const model='synthetic',review={model,disabledSkills:[],preflight:{passed:true,cli_model:model,prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd,model,disabledSkills:[]})}};
|
|
49
|
+
let calls=0;
|
|
50
|
+
const workerFactory=()=>async({prompt},{onEvent})=>{
|
|
51
|
+
calls++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
52
|
+
onEvent({event:'thread.started',provider_thread:`thread-${calls}`});
|
|
53
|
+
for(const event of [{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
54
|
+
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
55
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic'}};
|
|
56
|
+
};
|
|
57
|
+
const reviewHost=createFixReviewHost({codeProject:cwd,hostContextId:'fixture-host',review,permissions,workerFactory});
|
|
58
|
+
const configuration={hostContextId:'fixture-host',...config,causeReview:reviewHost.reviewer};delete configuration.identity;
|
|
59
|
+
const learning={contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No fixture instructions'}};
|
|
60
|
+
const bridge={async call(kind){
|
|
61
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong value',plan:'Correct value',affectedPaths:['value.mjs'],affectedModules:['value'],crossLayer:false,investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
|
|
62
|
+
if(kind==='fix_repair'){fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;');return {outcome:'repaired'};}
|
|
63
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
64
|
+
throw Error(kind);
|
|
65
|
+
}};
|
|
66
|
+
const options={specsRoot,identity:config.identity,configuration,create:true};
|
|
67
|
+
const execution={...reviewHost.execution,bridge,prepare:async()=>learning};
|
|
68
|
+
let owner=openFixExecution(options,execution);t.after(()=>owner.close());
|
|
69
|
+
const hostFor=current=>createFixHost({owner:current,config:{...config,specsRoot},permissions,authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority});
|
|
70
|
+
let host=hostFor(owner);
|
|
71
|
+
const run=async operation=>{const result=await host.handle({requestId:operation,operation});assert(!result?.error,`${operation}: ${JSON.stringify(result)}`);return result;};
|
|
72
|
+
for(const operation of ['advance','red_test','baseline','repair','regression','retrospective','handoff','final_review','publish_review'])await run(operation);
|
|
73
|
+
const log=path.join(specsRoot,'运行日志.jsonl');
|
|
74
|
+
growLog(log,MiB+256*1024);
|
|
75
|
+
assert(fs.statSync(log).size>MiB);
|
|
76
|
+
// The old whole-file read: exactly the limit this run would have hit.
|
|
77
|
+
assert.throws(()=>readReviewSourceFiles(specsRoot,['运行日志.jsonl']),{code:'limit_exceeded'});
|
|
78
|
+
const ownRows=eventsAt(specsRoot).filter(row=>row.run_id===config.identity.runId);
|
|
79
|
+
assert(ownRows.length>0&&eventsAt(specsRoot).every(row=>row.workflow==='cm-fix'));
|
|
80
|
+
await run('check_n5');
|
|
81
|
+
// A resume opens the owner and projects completion from the log again.
|
|
82
|
+
owner.close();owner=openFixExecution({...options,create:false},execution);host=hostFor(owner);
|
|
83
|
+
for(const operation of ['post_review_regression','walkthrough'])await run(operation);
|
|
84
|
+
growLog(log,64*1024);
|
|
85
|
+
const finished=await run('finish');
|
|
86
|
+
assert.equal(finished.stage??finished.result?.stage,'completed',JSON.stringify(finished));
|
|
87
|
+
owner.close();owner=openFixExecution({...options,create:false},execution);
|
|
88
|
+
assert.equal(owner.status().stage,'completed');
|
|
89
|
+
// Completion still binds this run only: the dossier row and the completion events are its own.
|
|
90
|
+
const done=eventsAt(specsRoot).filter(row=>row.run_id===config.identity.runId&&['task_done','run_done'].includes(row.event));
|
|
91
|
+
assert.deepEqual(done.map(row=>row.event),['task_done','run_done']);
|
|
92
|
+
assert(calls>=1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('the streamed log reader keeps the single-link, no-symlink and plain-JSON guarantees of the old reader',async t=>{
|
|
96
|
+
const {readStableLogRows}=await import('../runtime/js/cm-ai/log-rows.mjs');
|
|
97
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-stable-log-')));t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
98
|
+
const log=path.join(root,'运行日志.jsonl');
|
|
99
|
+
// An accepted historical row of another workflow nested deeper than the host
|
|
100
|
+
// object normalizer allows (40): it must not block a cm-fix read.
|
|
101
|
+
let deep={};for(let index=0;index<60;index++)deep={nested:deep};
|
|
102
|
+
fs.writeFileSync(log,[{workflow:'cm-prd',run_id:'other',data:deep},{workflow:'cm-fix',run_id:'mine',n:1},{workflow:'cm-fix',run_id:'mine',n:2}]
|
|
103
|
+
.map(row=>JSON.stringify(row)).join('\n')+'\n\n');
|
|
104
|
+
const pick=row=>row.workflow==='cm-fix';
|
|
105
|
+
assert.deepEqual(readStableLogRows(log,pick,'fix_log_failed').map(row=>row.n),[1,2]);
|
|
106
|
+
const link=path.join(root,'hard.jsonl');fs.linkSync(log,link);
|
|
107
|
+
assert.throws(()=>readStableLogRows(log,pick,'fix_log_failed'),{code:'fix_log_failed'});
|
|
108
|
+
fs.unlinkSync(link);
|
|
109
|
+
const symlink=path.join(root,'symlink.jsonl');fs.symlinkSync(log,symlink);
|
|
110
|
+
assert.throws(()=>readStableLogRows(symlink,pick,'fix_log_failed'),{code:'fix_log_failed'});
|
|
111
|
+
fs.appendFileSync(log,'{not json\n');
|
|
112
|
+
assert.throws(()=>readStableLogRows(log,pick,'fix_log_failed'),{code:'fix_log_failed'});
|
|
113
|
+
});
|