@aibyzero/cm-workflow 0.15.5 → 0.16.1
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 +45 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +174 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/checklist-coverage.mjs +70 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +12 -2
- package/runtime/js/cm-ai/durable-runner-state.mjs +12 -1
- package/runtime/js/cm-ai/effect-contract.mjs +31 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +91 -3
- package/runtime/js/cm-ai/host-handoff.mjs +59 -1
- package/runtime/js/cm-ai/host-session.mjs +21 -2
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +4 -1
- package/runtime/js/cm-ai/review-package.mjs +29 -3
- package/runtime/js/cm-ai/task-runner.mjs +44 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +17 -4
- package/runtime/js/cm-fix/execution.mjs +30 -22
- package/runtime/js/cm-fix/final-review.mjs +18 -11
- package/runtime/js/cm-fix/finish.mjs +14 -1
- package/runtime/js/cm-security/scan.mjs +7 -1
- package/scripts/cm-ai-batch-host.mjs +18 -6
- package/scripts/cm-ai-batch-run.mjs +12 -4
- package/scripts/cm-ai-checklist-coverage.test.mjs +116 -0
- package/scripts/cm-ai-execution-diagnostic.test.mjs +68 -0
- package/scripts/cm-ai-host.mjs +7 -2
- package/scripts/cm-ai-qa-recovery-args.test.mjs +80 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +53 -0
- package/scripts/cm-ai-run.mjs +2 -1
- package/scripts/cm-ai-verification-gate.test.mjs +116 -0
- package/scripts/cm-fix-cross-session-host.test.mjs +100 -0
- package/scripts/cm-fix-execution.test.mjs +33 -0
- package/scripts/cm-fix-host.mjs +11 -5
- package/scripts/cm-fix-repair-owner.test.mjs +22 -18
- package/scripts/cm-host-handoff.test.mjs +116 -1
- package/scripts/cm-host-session-diagnostic.test.mjs +82 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +85 -0
- package/scripts/cm-review-inventory.test.mjs +42 -0
- package/scripts/cm-security.test.mjs +24 -0
- package/skills/cm-ai/references/N3-execute-task.md +10 -0
- package/skills/cm-fix/references/js-host.md +18 -1
- package/templates/auto-update/cm-update.sh +51 -0
|
@@ -19,13 +19,17 @@ import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
|
19
19
|
import {readProjectInstructionContext} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
20
20
|
|
|
21
21
|
test('durable repair registers before write, preserves cause approval history and never redispatches lost results',async()=>{
|
|
22
|
-
for(const mode of ['revision','revision-approved','revision-lost','normal','lost','cause','cause-map','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
22
|
+
for(const mode of ['revision','revision-approved','revision-draft-mr','revision-lost','normal','lost','cause','cause-map','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
23
23
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-repair-owner-')));
|
|
24
24
|
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
25
25
|
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
26
26
|
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
27
27
|
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
28
|
-
|
|
28
|
+
// 收尾只关心「交付模式没在中途变过」,不关心它是哪一种:Git 是单独的 delivery
|
|
29
|
+
// 事件,不是 task_done 的前提。draft-mr 是 cm-init 给带 remote 的仓库生成的默认值。
|
|
30
|
+
const approvedRevision=['revision-approved','revision-draft-mr'].includes(mode);
|
|
31
|
+
if(approvedRevision)fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),
|
|
32
|
+
JSON.stringify({version:1,policies:{delivery:mode==='revision-draft-mr'?'draft-mr':'diff'}}));
|
|
29
33
|
const identity={repositoryId:'fixture',runId:'repair-owner',taskId:'T-FIX-owner',attempt:1};
|
|
30
34
|
const mapPaths=mode==='cause-map'?['docs/codebase-context/00-index.md','docs/codebase-context/07-business-logic.md','docs/codebase-context/09-changelog.md']:[];
|
|
31
35
|
const mapPlan='Create partial value map; cover value.mjs only; other modules unverified.';
|
|
@@ -37,7 +41,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
37
41
|
repair:{scope:['value.mjs',...mapPaths],requirements:['value.mjs']},...(mode.startsWith('cause')||mode.startsWith('revision')?{causeReview:reviewer}:{})}};
|
|
38
42
|
if(mode==='handoff-large')options.configuration.redTest.command=[process.execPath,'-e',
|
|
39
43
|
"import('./value.mjs').then(({value})=>{if(value!==2){process.stderr.write('BUG'+'x'.repeat(128*1024-3));process.exitCode=1;}});//"+'x'.repeat(31*1024)];
|
|
40
|
-
if(
|
|
44
|
+
if(approvedRevision)options.configuration.walkthrough={timeoutMs:2000,flows:[{id:'value-flow',modules:['one'],steps:['Read corrected value'],expected:['Value is 2'],kind:'commands',command:[process.execPath,'red.mjs']}]};
|
|
41
45
|
const authority=createHostReviewAuthority({hostContextId:'fixture-host',reviewerId:reviewer.reviewerId,adapterId:reviewer.adapterId,decide:async()=>({status:'approved'})});
|
|
42
46
|
const causeReview={authorize:authority.authorize,run:createCauseReviewRun(async({prompt},{onEvent})=>{
|
|
43
47
|
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
@@ -47,7 +51,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
47
51
|
},'codex')};
|
|
48
52
|
const learning={contextDigest:digest([]),files:[],application:{contextDigest:digest([]),status:'no_relevant_lesson',summary:'No project instructions in synthetic fixture'}};
|
|
49
53
|
const prepare=async()=>{
|
|
50
|
-
if(
|
|
54
|
+
if(!approvedRevision||!fs.existsSync(path.join(cwd,'AGENTS.md')))return learning;
|
|
51
55
|
const files=readProjectInstructionContext(cwd,[]).map(({content,...metadata})=>metadata);
|
|
52
56
|
return {files,contextDigest:digest(files),application:{contextDigest:digest(files),status:'applied',summary:'Preserve reviewed first-round lessons'}};
|
|
53
57
|
};
|
|
@@ -55,14 +59,14 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
55
59
|
bridge.attach(row=>{
|
|
56
60
|
if(row.type!=='host_request')return;
|
|
57
61
|
let result={status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['one'],crossLayer:mode.startsWith('cause'),plan:mode==='cause-map'?mapPlan:'Correct constant'};
|
|
58
|
-
if(
|
|
62
|
+
if(approvedRevision)result.investigation={discardedAlternatives:[],boundaryAnalysis:null};
|
|
59
63
|
if(row.kind==='fix_retrospective'){
|
|
60
64
|
const state=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json')));
|
|
61
65
|
assert.equal(state.records.at(-1).id,row.payload.identity.attempt===2?'fix-revision-retrospective-intent':'fix-retrospective-intent');retrospectives++;
|
|
62
66
|
if(mode==='retrospective-lost'){bridge.close();return;}
|
|
63
67
|
result=mode.startsWith('lesson')?{status:mode==='lesson-pending'?'writeback_pending':'lesson_candidate',candidates:[{classification:'structured',trigger:'Wrong constant',action:'Keep regression check',evidence:['red.mjs']}],reason:mode==='lesson-pending'?'Human assessment required':null}
|
|
64
68
|
:{status:'no_new_lesson',candidates:[],reason:null};
|
|
65
|
-
if(
|
|
69
|
+
if(approvedRevision)result={status:'lesson_candidate',candidates:[{classification:'structured',trigger:row.payload.identity.attempt===2?'Second repair boundary':'First repair boundary',action:'Keep value regression',evidence:['red.mjs']}],reason:null};
|
|
66
70
|
}
|
|
67
71
|
if(row.kind==='fix_repair'){
|
|
68
72
|
const state=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json')));
|
|
@@ -86,7 +90,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
86
90
|
// Compare settled state with reopened state when checking durable recovery.
|
|
87
91
|
const settled=async pending=>{await pending;return owner.status();};
|
|
88
92
|
try{
|
|
89
|
-
if(
|
|
93
|
+
if(approvedRevision)startFixRun({specsRoot,identity,configuration:options.configuration});
|
|
90
94
|
await owner.advance({authorized:true});
|
|
91
95
|
if(mode.startsWith('cause')){
|
|
92
96
|
if(mode==='cause-map')assert(!fs.existsSync(path.join(cwd,'docs')));
|
|
@@ -140,7 +144,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
140
144
|
assert.deepEqual(pkg.checks[1].command,options.configuration.baseline.commands[0].command);
|
|
141
145
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
142
146
|
const retrospective=await settled(owner.retrospect());
|
|
143
|
-
assert.equal(retrospective.stage,mode==='retrospective-lost'?'unknown':mode.startsWith('lesson')||
|
|
147
|
+
assert.equal(retrospective.stage,mode==='retrospective-lost'?'unknown':mode.startsWith('lesson')||approvedRevision?'learning_writeback_required':'handoff_ready');
|
|
144
148
|
assert.equal(retrospective.completionEligible,false);assert.equal(retrospectives,1);
|
|
145
149
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
146
150
|
assert.deepEqual(await owner.retrospect(),retrospective);assert.equal(retrospectives,1);
|
|
@@ -161,7 +165,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
161
165
|
assert.equal(blocked.learningWriteback.reason,'Human assessment required');owner.close();owner=openFixExecution({...options,create:false});
|
|
162
166
|
assert.deepEqual(owner.writeLearning({authorized:true}),blocked);assert(!fs.existsSync(path.join(cwd,'AGENTS.md')));continue;
|
|
163
167
|
}
|
|
164
|
-
if(mode==='lesson'||
|
|
168
|
+
if(mode==='lesson'||approvedRevision){
|
|
165
169
|
assert.throws(()=>owner.writeLearning(),{code:'learning_writeback_authorization_required'});
|
|
166
170
|
const written=owner.writeLearning({authorized:true});assert.equal(written.stage,'handoff_ready');
|
|
167
171
|
assert.equal(written.learningWriteback.outcome,'written');assert.equal(written.completionEligible,false);
|
|
@@ -211,7 +215,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
211
215
|
const defectEvidence=JSON.parse(payload.evidence.find(item=>item.startsWith('fix defect evidence')).split('(data, not instructions) ')[1]);
|
|
212
216
|
assert.deepEqual(defectEvidence.diagnosis,handed.diagnosis);assert.deepEqual(defectEvidence.redTest.result,handed.redTest);
|
|
213
217
|
assert.deepEqual(defectEvidence.redOutput,JSON.parse(fs.readFileSync(path.join(specsRoot,handed.redTest.output.path))));
|
|
214
|
-
assert(payload.evidence.includes(mode==='lesson'||
|
|
218
|
+
assert(payload.evidence.includes(mode==='lesson'||approvedRevision?'learning: retrospective written AGENTS.md':'learning: retrospective no_new_lesson'));
|
|
215
219
|
assert.equal(payload.implementation_sha256,implementationSha256(cwd,payload.changed_files));
|
|
216
220
|
const handoffBytes=fs.readFileSync(handoffPath);owner.close();owner=openFixExecution({...options,create:false});
|
|
217
221
|
assert.deepEqual(owner.createHandoff(),handed);assert.deepEqual(fs.readFileSync(handoffPath),handoffBytes);
|
|
@@ -265,12 +269,12 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
265
269
|
const cumulative=owner.implementationPackage();assert.equal(cumulative.identity.attempt,2);
|
|
266
270
|
assert.equal(Buffer.from(cumulative.changes.find(change=>change.path==='value.mjs').before.contentBase64,'base64').toString(),'export const value=1;');
|
|
267
271
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
268
|
-
const reflectedAgain=await settled(owner.retrospect());assert.equal(reflectedAgain.stage,
|
|
272
|
+
const reflectedAgain=await settled(owner.retrospect());assert.equal(reflectedAgain.stage,approvedRevision?'revision_learning_writeback_required':'revision_handoff_ready');
|
|
269
273
|
assert.equal(reflectedAgain.revisionRetrospective.identity.attempt,2);assert.equal(retrospectives,2);
|
|
270
274
|
assert.equal(reflectedAgain.revisionRetrospective.packageDigest,cumulative.packageDigest);assert.equal(reflectedAgain.completionEligible,false);
|
|
271
275
|
owner.close();owner=openFixExecution({...options,create:false});assert.deepEqual(owner.status(),reflectedAgain);
|
|
272
276
|
assert.deepEqual(await owner.retrospect(),reflectedAgain);assert.equal(retrospectives,2);
|
|
273
|
-
if(
|
|
277
|
+
if(approvedRevision){
|
|
274
278
|
assert.throws(()=>owner.writeLearning(),{code:'learning_writeback_authorization_required'});
|
|
275
279
|
assert.equal(owner.createHandoff().stage,'revision_learning_writeback_required');
|
|
276
280
|
const written=owner.writeLearning({authorized:true});assert.equal(written.stage,'revision_handoff_ready');
|
|
@@ -286,7 +290,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
286
290
|
const secondPath=path.join(specsRoot,'.reviews','fix-owner-T-FIX-owner-a2-handoff.json');
|
|
287
291
|
const secondBytes=fs.readFileSync(secondPath),secondHandoff=loadHandoff(secondPath,{task:identity.taskId,attempt:2});
|
|
288
292
|
assert(secondHandoff.evidence.some(item=>item.startsWith('fix prior review')&&item.includes('F1')));
|
|
289
|
-
if(
|
|
293
|
+
if(approvedRevision){assert(secondHandoff.evidence.includes('learning: retrospective written AGENTS.md'));assert(secondHandoff.changed_files.includes('AGENTS.md'));}
|
|
290
294
|
assert.deepEqual(fs.readFileSync(handoffPath),handoffBytes);assert.equal(handedAgain.completionEligible,false);
|
|
291
295
|
const reviewAgain=owner.finalReviewPackage();assert.equal(reviewAgain.identity.attempt,2);assert.equal(reviewAgain.handoff.sha256,handedAgain.revisionHandoff.handoffSha256);
|
|
292
296
|
assert.equal(Buffer.from(reviewAgain.changes.find(change=>change.path==='value.mjs').before.contentBase64,'base64').toString(),'export const value=1;');
|
|
@@ -300,15 +304,15 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
300
304
|
for(const event of [{event:'thread.started',provider_thread:'second-revision-reviewer'},{event:'turn.started',item_type:null},
|
|
301
305
|
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])assert.equal(onEvent(event),true);
|
|
302
306
|
return {status:'succeeded',value:{...request.payload.priorReview,packageDigest:reviewAgain.packageDigest,examinedPaths:reviewPaths(reviewAgain),
|
|
303
|
-
...(
|
|
307
|
+
...(approvedRevision?{verdict:'approved',findings:[]}: {})}};
|
|
304
308
|
}}});
|
|
305
309
|
assert.equal((await owner.reviewFinal()).stage,'revision_final_review_evidence_required');
|
|
306
|
-
const reviewedAgain=owner.publishReview();assert.equal(reviewedAgain.stage,
|
|
310
|
+
const reviewedAgain=owner.publishReview();assert.equal(reviewedAgain.stage,approvedRevision?'revision_completion_gate_required':'revision_review_limit_reached');
|
|
307
311
|
assert.equal(reviewedAgain.completionEligible,false);assert.equal(calls,2);
|
|
308
312
|
owner.close();owner=openFixExecution({...options,create:false});assert.deepEqual(owner.status(),reviewedAgain);
|
|
309
313
|
assert.deepEqual(await owner.reviewFinal(),reviewedAgain);assert.equal(calls,2);
|
|
310
314
|
await assert.rejects(owner.prepareRevision({authorized:true}),{code:'fix_revision_unavailable'});
|
|
311
|
-
if(
|
|
315
|
+
if(approvedRevision){
|
|
312
316
|
const gated=owner.checkCompletionGate();assert.equal(gated.stage,'revision_post_review_regression_required');
|
|
313
317
|
assert.equal(gated.revisionN5.gate.attempt,2);assert.equal(gated.completionEligible,false);
|
|
314
318
|
const reviewPath=path.join(specsRoot,'.reviews','fix-owner-T-FIX-owner-r2.md'),reviewBytes=fs.readFileSync(reviewPath);
|
|
@@ -355,8 +359,8 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
355
359
|
assert(archive.includes('先前轮次(历史记录,不替代当前审查)'));assert(archive.includes('changes_requested'));
|
|
356
360
|
assert(fs.readFileSync(path.join(specsRoot,'METRICS.md'),'utf8').includes('| 2 | 1 |'));
|
|
357
361
|
}
|
|
358
|
-
fs.appendFileSync(path.join(cwd,'value.mjs'),' ');assert.equal(owner.status().stage,
|
|
359
|
-
if(
|
|
362
|
+
fs.appendFileSync(path.join(cwd,'value.mjs'),' ');assert.equal(owner.status().stage,approvedRevision?'revision_learning_writeback_evidence_required':'revision_repair_evidence_required');
|
|
363
|
+
if(approvedRevision){assert.equal(owner.status().completionEligible,false);assert.equal(owner.status().completionHistory.runDoneEventIds.length,1);}
|
|
360
364
|
assert.deepEqual(owner.status().revision,revised.revision);continue;
|
|
361
365
|
}
|
|
362
366
|
if(mode==='cause'){
|
|
@@ -28,8 +28,9 @@ test('host handoff uses existing gate and binds actual changed bytes',()=>fixtur
|
|
|
28
28
|
const handoff=loadHandoff(input.handoffPath,{task:'T-001',attempt:1});
|
|
29
29
|
assert.deepEqual(handoff.changed_files,['a.mjs']);
|
|
30
30
|
assert.equal(handoff.implementation_sha256,implementationSha256(input.root,['a.mjs']));
|
|
31
|
+
// Republishing the same bytes is the crash-after-link case: already published.
|
|
31
32
|
const before=fs.readFileSync(input.handoffPath);
|
|
32
|
-
assert.
|
|
33
|
+
assert.equal(createHostHandoff(input).status,'ready_for_review');
|
|
33
34
|
assert.deepEqual(fs.readFileSync(input.handoffPath),before);
|
|
34
35
|
}));
|
|
35
36
|
test('failed host check produces blocked handoff rather than invented success',()=>fixture(input=>{
|
|
@@ -56,3 +57,117 @@ test('new host handoff feeds existing Learning writer and verifier',()=>fixture(
|
|
|
56
57
|
const evidence=loadHandoff(input.handoffPath).evidence;
|
|
57
58
|
assert.equal(evidence.filter(x=>x.startsWith('cm-learning-')).length,2);
|
|
58
59
|
}));
|
|
60
|
+
|
|
61
|
+
// A run that dies before review leaves a handoff behind. Refusing to replace it
|
|
62
|
+
// blocks every later attempt of that task forever, which is what #81 reported.
|
|
63
|
+
// Approval evidence still must never be overwritten, so the receipt decides.
|
|
64
|
+
function collisionFixture(fn){
|
|
65
|
+
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-handoff-collision-')));
|
|
66
|
+
const root=path.join(temp,'code'),reviews=path.join(temp,'reviews');fs.mkdirSync(root);fs.mkdirSync(reviews);
|
|
67
|
+
fs.writeFileSync(path.join(root,'a.mjs'),'old');fs.writeFileSync(path.join(root,'requirements.md'),'synthetic task');
|
|
68
|
+
const handoffPath=path.join(reviews,'9.demo-T-001-a1-handoff.json');
|
|
69
|
+
const build=body=>{
|
|
70
|
+
fs.writeFileSync(path.join(root,'a.mjs'),'old');
|
|
71
|
+
const baseline=captureReviewBaseline({root,identity:{repositoryId:'test',runId:'run',taskId:'T-001',attempt:1},
|
|
72
|
+
scope:['a.mjs'],requirements:['requirements.md']});
|
|
73
|
+
fs.writeFileSync(path.join(root,'a.mjs'),body);
|
|
74
|
+
return {root,baseline,handoffPath,
|
|
75
|
+
checks:[{id:'unit',command:['node','--test'],outcome:'passed',exitCode:0,evidence:'host fixture check'}]};
|
|
76
|
+
};
|
|
77
|
+
try{fn({reviews,handoffPath,build});}finally{fs.rmSync(temp,{recursive:true,force:true});}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
test('an unreviewed handoff from a dead run is archived so the retry can publish',()=>collisionFixture(f=>{
|
|
81
|
+
createHostHandoff(f.build('first attempt'));
|
|
82
|
+
const stale=fs.readFileSync(f.handoffPath);
|
|
83
|
+
assert.equal(createHostHandoff(f.build('second attempt')).status,'ready_for_review');
|
|
84
|
+
const republished=fs.readFileSync(f.handoffPath);
|
|
85
|
+
assert.notDeepEqual(republished,stale);
|
|
86
|
+
const archive=path.join(f.reviews,'.superseded');
|
|
87
|
+
const archived=fs.readdirSync(archive);
|
|
88
|
+
assert.equal(archived.length,1);
|
|
89
|
+
assert.match(archived[0],/^9\.demo-T-001-a1-handoff\.json\.[0-9a-f]{16}$/);
|
|
90
|
+
assert.deepEqual(fs.readFileSync(path.join(archive,archived[0])),stale);
|
|
91
|
+
}));
|
|
92
|
+
|
|
93
|
+
test('a handoff the matching receipt names is never replaced',()=>collisionFixture(f=>{
|
|
94
|
+
createHostHandoff(f.build('first attempt'));
|
|
95
|
+
const reviewed=fs.readFileSync(f.handoffPath);
|
|
96
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),
|
|
97
|
+
['---','at: 2026-01-01T00:00:00.000Z','reviewer: claude-cli','independent: true','task: T-001',
|
|
98
|
+
'attempt: 1','round: 1','verdict: approved','handoff: 9.demo-T-001-a1-handoff.json',
|
|
99
|
+
'handoff_sha256: '+'0'.repeat(64),'blocking_findings: 0','---',''].join('\n'));
|
|
100
|
+
assert.throws(()=>createHostHandoff(f.build('second attempt')),error=>error.code==='handoff_exists');
|
|
101
|
+
assert.deepEqual(fs.readFileSync(f.handoffPath),reviewed);
|
|
102
|
+
assert.equal(fs.existsSync(path.join(f.reviews,'.superseded')),false);
|
|
103
|
+
}));
|
|
104
|
+
|
|
105
|
+
test('a receipt for another handoff does not protect this one',()=>collisionFixture(f=>{
|
|
106
|
+
createHostHandoff(f.build('first attempt'));
|
|
107
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),
|
|
108
|
+
['---','verdict: approved','handoff: 9.demo-T-002-a1-handoff.json','---',''].join('\n'));
|
|
109
|
+
assert.equal(createHostHandoff(f.build('second attempt')).status,'ready_for_review');
|
|
110
|
+
assert.equal(fs.readdirSync(path.join(f.reviews,'.superseded')).length,1);
|
|
111
|
+
}));
|
|
112
|
+
|
|
113
|
+
// The receipt names the handoff it reviewed inside its front matter, and the
|
|
114
|
+
// scope list after that line is as long as the task's changed file list. Reading
|
|
115
|
+
// a fixed number of lines made the decision depend on field order; a reordering
|
|
116
|
+
// would silently turn reviewed evidence into a supersedable leftover.
|
|
117
|
+
const receipt=(handoffName,scopeLength,{order='handoff-first',terminated=true}={})=>{
|
|
118
|
+
const head=['---','at: 2026-01-01T00:00:00.000Z','reviewer: claude-cli','independent: true',
|
|
119
|
+
'task: T-001','attempt: 1','round: 1','verdict: approved'];
|
|
120
|
+
const bound=[`handoff: ${handoffName}`,'handoff_sha256: '+'0'.repeat(64),'blocking_findings: 0'];
|
|
121
|
+
const scope=['scope:',...Array.from({length:scopeLength},(_,i)=>` - src/file${i}.mjs`)];
|
|
122
|
+
return [...head,...(order==='handoff-first'?[...bound,...scope]:[...scope,...bound]),
|
|
123
|
+
...(terminated?['---','','No blocking findings.']:[])].join('\n');
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
test('a reviewed handoff stays protected however long the scope list is',()=>collisionFixture(f=>{
|
|
127
|
+
createHostHandoff(f.build('first attempt'));
|
|
128
|
+
const reviewed=fs.readFileSync(f.handoffPath);
|
|
129
|
+
// 200 scope entries push the handoff line far past any fixed window.
|
|
130
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),
|
|
131
|
+
receipt('9.demo-T-001-a1-handoff.json',200));
|
|
132
|
+
assert.throws(()=>createHostHandoff(f.build('second attempt')),error=>error.code==='handoff_exists');
|
|
133
|
+
assert.deepEqual(fs.readFileSync(f.handoffPath),reviewed);
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
test('a reviewed handoff stays protected if the front matter is reordered',()=>collisionFixture(f=>{
|
|
137
|
+
createHostHandoff(f.build('first attempt'));
|
|
138
|
+
const reviewed=fs.readFileSync(f.handoffPath);
|
|
139
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),
|
|
140
|
+
receipt('9.demo-T-001-a1-handoff.json',40,{order:'scope-first'}));
|
|
141
|
+
assert.throws(()=>createHostHandoff(f.build('second attempt')),error=>error.code==='handoff_exists');
|
|
142
|
+
assert.deepEqual(fs.readFileSync(f.handoffPath),reviewed);
|
|
143
|
+
}));
|
|
144
|
+
|
|
145
|
+
test('a receipt that is not recognisable front matter fails closed',()=>collisionFixture(f=>{
|
|
146
|
+
createHostHandoff(f.build('first attempt'));
|
|
147
|
+
const reviewed=fs.readFileSync(f.handoffPath);
|
|
148
|
+
for(const body of [
|
|
149
|
+
receipt('9.demo-T-001-a1-handoff.json',3,{terminated:false}), // 未闭合
|
|
150
|
+
'no front matter at all\nhandoff: 9.demo-T-001-a1-handoff.json\n', // 没有起始 ---
|
|
151
|
+
]){
|
|
152
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),body);
|
|
153
|
+
assert.throws(()=>createHostHandoff(f.build('second attempt')),error=>error.code==='handoff_exists');
|
|
154
|
+
assert.deepEqual(fs.readFileSync(f.handoffPath),reviewed);
|
|
155
|
+
}
|
|
156
|
+
}));
|
|
157
|
+
|
|
158
|
+
test('a handoff line in the body rather than the front matter does not protect',()=>collisionFixture(f=>{
|
|
159
|
+
// Only the front matter binds a receipt to a handoff; prose must not.
|
|
160
|
+
createHostHandoff(f.build('first attempt'));
|
|
161
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),
|
|
162
|
+
['---','verdict: approved','---','','handoff: 9.demo-T-001-a1-handoff.json'].join('\n'));
|
|
163
|
+
assert.equal(createHostHandoff(f.build('second attempt')).status,'ready_for_review');
|
|
164
|
+
assert.equal(fs.readdirSync(path.join(f.reviews,'.superseded')).length,1);
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
test('an oversized receipt fails closed instead of being parsed',()=>collisionFixture(f=>{
|
|
168
|
+
createHostHandoff(f.build('first attempt'));
|
|
169
|
+
const reviewed=fs.readFileSync(f.handoffPath);
|
|
170
|
+
fs.writeFileSync(path.join(f.reviews,'9.demo-T-001-r1.md'),'x'.repeat(256*1024+1));
|
|
171
|
+
assert.throws(()=>createHostHandoff(f.build('second attempt')),error=>error.code==='handoff_exists');
|
|
172
|
+
assert.deepEqual(fs.readFileSync(f.handoffPath),reviewed);
|
|
173
|
+
}));
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import {PassThrough} from 'node:stream';
|
|
4
|
+
|
|
5
|
+
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
6
|
+
|
|
7
|
+
// Drives one request through the real JSONL transport and returns both channels.
|
|
8
|
+
async function exchange(request,handle){
|
|
9
|
+
const input=new PassThrough(),output=new PassThrough(),errorOutput=new PassThrough();
|
|
10
|
+
const replies=[],diagnostics=[];
|
|
11
|
+
output.on('data',chunk=>{for(const line of chunk.toString().split('\n'))if(line.trim())replies.push(JSON.parse(line));});
|
|
12
|
+
errorOutput.on('data',chunk=>{for(const line of chunk.toString().split('\n'))if(line.trim())diagnostics.push(JSON.parse(line));});
|
|
13
|
+
const serving=serveCmAiHost({host:{handle},input,output,errorOutput});
|
|
14
|
+
input.write(JSON.stringify(request)+'\n');
|
|
15
|
+
input.end();
|
|
16
|
+
await serving;
|
|
17
|
+
await new Promise(resolve=>setImmediate(resolve));
|
|
18
|
+
return {replies,diagnostics};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const failing=code=>()=>{throw Object.assign(new Error(code),{code});};
|
|
22
|
+
|
|
23
|
+
test('the redacted reply is unchanged and the real code goes to stderr', async () => {
|
|
24
|
+
// The peer must keep seeing host_request_failed: which codes may cross that
|
|
25
|
+
// boundary is a deliberate design, not an oversight.
|
|
26
|
+
const {replies,diagnostics}=await exchange({operation:'save_draft',requestId:'r1'},
|
|
27
|
+
failing('prd_review_sections_missing'));
|
|
28
|
+
assert.deepEqual(replies,[{requestId:'r1',error:{code:'host_request_failed'}}]);
|
|
29
|
+
assert.deepEqual(diagnostics,[{diagnostic:'host_request_failed',operation:'save_draft',
|
|
30
|
+
code:'prd_review_sections_missing'}]);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('the failing operation is named so a strict field set can be told apart', async () => {
|
|
34
|
+
const {diagnostics}=await exchange({operation:'final_review_package',requestId:'r2'},
|
|
35
|
+
failing('invalid_input'));
|
|
36
|
+
assert.equal(diagnostics[0].operation,'final_review_package');
|
|
37
|
+
assert.equal(diagnostics[0].code,'invalid_input');
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('a success emits no diagnostic', async () => {
|
|
41
|
+
const {replies,diagnostics}=await exchange({operation:'status',requestId:'r3'},
|
|
42
|
+
async()=>({outcome:'reported'}));
|
|
43
|
+
assert.deepEqual(replies,[{requestId:'r3',result:{outcome:'reported'}}]);
|
|
44
|
+
assert.deepEqual(diagnostics,[]);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('an error carrying no code still produces one line', async () => {
|
|
48
|
+
const {replies,diagnostics}=await exchange({operation:'advance',requestId:'r4'},
|
|
49
|
+
()=>{throw new Error('anonymous failure');});
|
|
50
|
+
assert.deepEqual(replies,[{requestId:'r4',error:{code:'host_request_failed'}}]);
|
|
51
|
+
assert.deepEqual(diagnostics,[{diagnostic:'host_request_failed',operation:'advance',detail:'unavailable'}]);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the raw message never reaches either channel', async () => {
|
|
55
|
+
// Assembled at runtime so the safety scanner does not see a key-shaped literal.
|
|
56
|
+
const secret=['sk','live','0123456789abcdef'].join('-')+' leaked from provider output';
|
|
57
|
+
const {replies,diagnostics}=await exchange({operation:'advance',requestId:'r5'},
|
|
58
|
+
()=>{throw Object.assign(new Error(secret),{code:'invalid_input'});});
|
|
59
|
+
const text=JSON.stringify(replies)+JSON.stringify(diagnostics);
|
|
60
|
+
assert.equal(text.includes(['sk','live'].join('-')),false);
|
|
61
|
+
assert.equal(text.includes('leaked'),false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('a malformed request is rejected without a diagnostic', async () => {
|
|
65
|
+
// invalid_request already says what is wrong; it never reaches host.handle.
|
|
66
|
+
const {replies,diagnostics}=await exchange({operation:'not_an_operation',requestId:'r6'},
|
|
67
|
+
()=>{throw new Error('unreachable');});
|
|
68
|
+
assert.deepEqual(replies,[{requestId:null,error:{code:'invalid_request'}}]);
|
|
69
|
+
assert.deepEqual(diagnostics,[]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a stderr that throws does not change the reply', async () => {
|
|
73
|
+
const input=new PassThrough(),output=new PassThrough();
|
|
74
|
+
const replies=[];
|
|
75
|
+
output.on('data',chunk=>{for(const line of chunk.toString().split('\n'))if(line.trim())replies.push(JSON.parse(line));});
|
|
76
|
+
const errorOutput={write(){throw new Error('stderr is gone');}};
|
|
77
|
+
const serving=serveCmAiHost({host:{handle:failing('invalid_input')},input,output,errorOutput});
|
|
78
|
+
input.write(JSON.stringify({operation:'advance',requestId:'r7'})+'\n');
|
|
79
|
+
input.end();
|
|
80
|
+
await serving;
|
|
81
|
+
assert.deepEqual(replies,[{requestId:'r7',error:{code:'host_request_failed'}}]);
|
|
82
|
+
});
|
|
@@ -75,3 +75,88 @@ test('legacy baselines retain already-recorded dependency files and their drift
|
|
|
75
75
|
fs.unlinkSync(path.join(root,'.venv','recorded.txt'));
|
|
76
76
|
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'});
|
|
77
77
|
});
|
|
78
|
+
|
|
79
|
+
function installCocoaPods(root,prefix){
|
|
80
|
+
const pods=path.join(root,prefix);
|
|
81
|
+
fs.mkdirSync(path.join(pods,'Headers/Private/DoubleConversion/double-conversion'),{recursive:true});
|
|
82
|
+
fs.mkdirSync(path.join(pods,'Pods.xcodeproj'));
|
|
83
|
+
fs.writeFileSync(path.join(pods,'Manifest.lock'),'PODFILE CHECKSUM: synthetic');
|
|
84
|
+
fs.writeFileSync(path.join(path.dirname(pods),'Podfile.lock'),'PODFILE CHECKSUM: synthetic');
|
|
85
|
+
fs.writeFileSync(path.join(pods,'DoubleConversion.h'),'generated pod header');
|
|
86
|
+
fs.symlinkSync('../../../../DoubleConversion.h',path.join(pods,'Headers/Private/DoubleConversion/double-conversion/bignum-dtoa.h'));
|
|
87
|
+
return pods;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
test('generated CocoaPods trees stay out of the snapshot instead of blocking it',t=>{
|
|
91
|
+
const {root,options}=fixture(t);
|
|
92
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
93
|
+
const baseline=captureReviewBaseline(options);
|
|
94
|
+
// Podfile.lock is authored and checked in; only the generated tree disappears.
|
|
95
|
+
assert.deepEqual(baseline.files.map(f=>f.path),
|
|
96
|
+
['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
|
|
97
|
+
fs.writeFileSync(path.join(root,'src/main.py'),'after');
|
|
98
|
+
const pkg=createReviewPackage({root,baseline,checks});
|
|
99
|
+
assert.equal(verifyReviewPackage({root,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
100
|
+
for(const field of ['scope','requirements'])
|
|
101
|
+
assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),{code:'excluded_snapshot_path'});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('an authored pods directory is still snapshotted and its symlinks still fail closed',t=>{
|
|
105
|
+
const {root,options}=fixture(t);
|
|
106
|
+
fs.mkdirSync(path.join(root,'src/pods'),{recursive:true});
|
|
107
|
+
fs.writeFileSync(path.join(root,'src/pods/scheduler.py'),'business code');
|
|
108
|
+
assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
|
|
109
|
+
['requirements.md','src/main.py','src/pods/scheduler.py']);
|
|
110
|
+
fs.symlinkSync('../../requirements.md',path.join(root,'src/pods/linked.py'));
|
|
111
|
+
assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
test('a Pods directory missing any one CocoaPods artefact keeps the symlink guard',t=>{
|
|
115
|
+
for(const missing of ['Pods/Manifest.lock','Pods/Pods.xcodeproj','Podfile.lock']){
|
|
116
|
+
const {root,options}=fixture(t);
|
|
117
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
118
|
+
fs.rmSync(path.join(root,'mobile/ios',missing),{recursive:true,force:true});
|
|
119
|
+
assert.throws(()=>captureReviewBaseline(options),{code:'unsupported_file'},missing);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// The traversal and the scope guard must ask one predicate, not two that agree
|
|
124
|
+
// by coincidence. They once did not: the traversal probed every directory for
|
|
125
|
+
// the generated entries while the guard additionally required the name "pods".
|
|
126
|
+
// A directory called src/ holding an empty Manifest.lock and an empty
|
|
127
|
+
// Pods.xcodeproj/ was then skipped whole — taking a file explicitly declared in
|
|
128
|
+
// scope out of the review with no error raised anywhere.
|
|
129
|
+
test('a directory that is not named pods is never treated as a generated tree',t=>{
|
|
130
|
+
const {root,options}=fixture(t);
|
|
131
|
+
fs.writeFileSync(path.join(root,'src/Manifest.lock'),'');
|
|
132
|
+
fs.mkdirSync(path.join(root,'src/Pods.xcodeproj'));
|
|
133
|
+
fs.writeFileSync(path.join(root,'Podfile.lock'),'');
|
|
134
|
+
const baseline=captureReviewBaseline(options);
|
|
135
|
+
assert.ok(baseline.files.some(f=>f.path==='src/main.py'),
|
|
136
|
+
'a declared scope file was silently dropped from the snapshot');
|
|
137
|
+
// A file added inside the disguise must stay visible: out_of_scope is the
|
|
138
|
+
// snapshot seeing it and refusing it, which is the opposite of vanishing.
|
|
139
|
+
fs.writeFileSync(path.join(root,'src/added.py'),'new');
|
|
140
|
+
fs.writeFileSync(path.join(root,'src/main.py'),'after');
|
|
141
|
+
assert.throws(()=>createReviewPackage({root,baseline,checks}),{code:'out_of_scope'},
|
|
142
|
+
'a file added after the baseline stayed invisible to the review package');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Whatever the predicate accepts leaves the review silently, so the two callers
|
|
146
|
+
// must never diverge again. Assert they are the same predicate, not two rules.
|
|
147
|
+
test('the scope guard rejects exactly what the traversal skips',t=>{
|
|
148
|
+
const {root,options}=fixture(t);
|
|
149
|
+
installCocoaPods(root,'mobile/ios/Pods');
|
|
150
|
+
assert.deepEqual(captureReviewBaseline(options).files.map(f=>f.path),
|
|
151
|
+
['mobile/ios/Podfile.lock','requirements.md','src/main.py']);
|
|
152
|
+
for(const field of ['scope','requirements'])
|
|
153
|
+
assert.throws(()=>captureReviewBaseline({...options,[field]:['mobile/ios/Pods/DoubleConversion.h']}),
|
|
154
|
+
{code:'excluded_snapshot_path'},field);
|
|
155
|
+
// Remove one artefact: the tree comes back into the snapshot, and the guard
|
|
156
|
+
// must stop rejecting it in the same step.
|
|
157
|
+
fs.rmSync(path.join(root,'mobile/ios/Podfile.lock'));
|
|
158
|
+
fs.rmSync(path.join(root,'mobile/ios/Pods/Headers'),{recursive:true,force:true});
|
|
159
|
+
assert.ok(captureReviewBaseline(options).files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'));
|
|
160
|
+
assert.deepEqual(captureReviewBaseline({...options,scope:['mobile/ios/Pods/DoubleConversion.h']})
|
|
161
|
+
.files.some(f=>f.path==='mobile/ios/Pods/DoubleConversion.h'),true);
|
|
162
|
+
});
|
|
@@ -296,3 +296,45 @@ test('new specification and legacy packages both retain receipt completion eligi
|
|
|
296
296
|
assert.equal(verifyReviewPackage({root:f.code,baseline:pkg===current?baseline:legacyBaseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
297
297
|
}
|
|
298
298
|
});
|
|
299
|
+
|
|
300
|
+
// A repository that merely contains mobile/.env.example used to be impossible
|
|
301
|
+
// to review: walk() validates every discovered path, so the placeholder aborted
|
|
302
|
+
// the whole baseline capture rather than being skipped. Committed placeholders
|
|
303
|
+
// are ordinary source; the real secret files must still be refused.
|
|
304
|
+
test('committed environment placeholders are inventoried while real secret files stay refused',()=>fixture(root=>{
|
|
305
|
+
fs.mkdirSync(path.join(root,'mobile'));
|
|
306
|
+
write(root,'mobile/.env.example','API_URL=https://example.invalid\n');
|
|
307
|
+
write(root,'.env.sample','TOKEN=replace-me\n');
|
|
308
|
+
const baseline=capture(root);
|
|
309
|
+
const inventoried=baseline.files.map(f=>f.path);
|
|
310
|
+
assert.ok(inventoried.includes('mobile/.env.example'),'placeholder missing from the inventory');
|
|
311
|
+
assert.ok(inventoried.includes('.env.sample'),'placeholder missing from the inventory');
|
|
312
|
+
// Inventoried means hashed, not disclosed: only selected scope carries a body.
|
|
313
|
+
const placeholder=baseline.files.find(f=>f.path==='mobile/.env.example');
|
|
314
|
+
assert.equal(placeholder.contentBase64,undefined);
|
|
315
|
+
assert.equal(typeof placeholder.sha256,'string');
|
|
316
|
+
|
|
317
|
+
// Selecting a placeholder as ordinary source is allowed too.
|
|
318
|
+
const selected=captureReviewBaseline({root,identity,scope:['mobile/.env.example'],
|
|
319
|
+
requirements:['requirements.md']}).files.find(f=>f.path==='mobile/.env.example');
|
|
320
|
+
assert.equal(Buffer.from(selected.contentBase64,'base64').toString(),
|
|
321
|
+
'API_URL=https://example.invalid\n');
|
|
322
|
+
|
|
323
|
+
for(const secret of ['.env','.env.local','.env.production','.env.example.bak']){
|
|
324
|
+
write(root,secret,'SECRET=1\n');
|
|
325
|
+
assert.throws(()=>capture(root),{code:'unsupported_path'},`${secret} was not refused`);
|
|
326
|
+
assert.throws(()=>captureReviewBaseline({root,identity,scope:[secret],
|
|
327
|
+
requirements:['requirements.md']}),{code:'unsupported_path'},`${secret} was selectable`);
|
|
328
|
+
fs.rmSync(path.join(root,secret));
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// The placeholder name must not become a way to smuggle a real secret in.
|
|
332
|
+
fs.writeFileSync(path.join(root,'.env'),'SECRET=real\n');
|
|
333
|
+
fs.symlinkSync('.env',path.join(root,'.env.disguise'));
|
|
334
|
+
fs.renameSync(path.join(root,'.env.disguise'),path.join(root,'.env.template'));
|
|
335
|
+
assert.throws(()=>capture(root),{code:'unsupported_path'},'the .env sibling was not refused');
|
|
336
|
+
fs.rmSync(path.join(root,'.env'));
|
|
337
|
+
assert.throws(()=>capture(root),/unsupported_file|unsupported_path|read_failed/,
|
|
338
|
+
'a symlink wearing a placeholder name was captured');
|
|
339
|
+
fs.rmSync(path.join(root,'.env.template'));
|
|
340
|
+
}));
|
|
@@ -58,6 +58,30 @@ test('no change is distinct from partial and missing tools do not pass',t=>{
|
|
|
58
58
|
assert.ok(r.tools.every(v=>v.reason==='tool_missing'));assert.equal(r.aiReview,'pending');
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
+
// .env.example and friends are committed placeholder files meant to be copied.
|
|
62
|
+
// Treating them as real secret files hid exactly the case worth scanning: a real
|
|
63
|
+
// key pasted into the example. Only these four explicit suffixes are readable.
|
|
64
|
+
test('committed env examples are scanned while real env files stay protected',t=>{
|
|
65
|
+
const f=fixture(t);
|
|
66
|
+
for(const name of ['.env.example','.env.sample','.env.template','.env.dist'])f.put(name,'API_KEY=replace-me\n');
|
|
67
|
+
f.put('nested/.env.example','TOKEN=replace-me\n');
|
|
68
|
+
for(const name of ['.env','.env.local','.env.production','.env.example.bak'])f.put(name,'API_KEY=real\n');
|
|
69
|
+
f.git('add','.');
|
|
70
|
+
const r=inventory(f.project,{all:true});
|
|
71
|
+
const gap=name=>r.gaps.some(v=>v.path===name&&v.reason==='protected_path_not_read');
|
|
72
|
+
const read=name=>r.files.some(v=>v.path===name);
|
|
73
|
+
for(const name of ['.env.example','.env.sample','.env.template','.env.dist','nested/.env.example']){
|
|
74
|
+
assert.equal(read(name),true,`${name} 应当被扫描`);
|
|
75
|
+
assert.equal(gap(name),false,`${name} 不应记为受保护跳过`);
|
|
76
|
+
}
|
|
77
|
+
// Real secret files keep their existing protection, including a suffix that
|
|
78
|
+
// merely contains "example" rather than ending with it.
|
|
79
|
+
for(const name of ['.env','.env.local','.env.production','.env.example.bak']){
|
|
80
|
+
assert.equal(gap(name),true,`${name} 应当仍被保护`);
|
|
81
|
+
assert.equal(read(name),false,`${name} 不应被读取`);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
61
85
|
test('symlink ancestor, protected files and scanner controls are visible gaps',t=>{
|
|
62
86
|
const f=fixture(t);f.put('dir/file.py','ok');f.put('.env','private fixture');f.put('.gitleaks.toml','malicious rule');f.git('add','.');
|
|
63
87
|
fs.renameSync(path.join(f.project,'dir'),path.join(f.base,'outside'));
|
|
@@ -106,6 +106,16 @@ AGENTS.md 增量写回;将学习结果、文件摘要记入已有交接字段
|
|
|
106
106
|
`../../../runtime/task-gates.md`。子代理只能返回候选字段;由主执行者核对并落盘,
|
|
107
107
|
不得让子代理写 `.reviews/`。`ready_for_review` 必须所有 verification 都是 `passed`,
|
|
108
108
|
且 blockers/scope_deviation 为空;`changed_files` 使用正斜杠分隔的项目相对路径。
|
|
109
|
+
|
|
110
|
+
**交付前逐条核对任务的 `verification`**:开发请求的 `specification.task.verification`
|
|
111
|
+
来自 `tasks.md` 的「验证要求」段(由 `runtime/js/cm-ai/specification-material.mjs` 提取)。
|
|
112
|
+
把它当检查清单,**逐条**写出满足它的证据位置——哪个文件哪一行、哪次命令的哪段输出。
|
|
113
|
+
有一条对不上就补做,补不了就写 `blocked` 说明缺口,不得交付。要求里写「分别记录
|
|
114
|
+
A、B、C 三种状态」就必须三种都在,写「在 X 路径上走查」就必须是 X 而不是等价替代;
|
|
115
|
+
用了替身(命令桩、脚本派发事件、非指定服务器)时,在证据里显式标注边界,不要让
|
|
116
|
+
结论读起来像端到端验证过。这一步不是形式:本仓库实跑统计显示末任务
|
|
117
|
+
(承担 feature 级走查与证据文档的那个)第一轮审查通过率仅 1/5,被打回的 P2 全部是
|
|
118
|
+
「证据没满足任务里已写明的验证要求」——不是代码缺陷,是本可在此自查掉的遗漏。
|
|
109
119
|
否则写 `blocked` 并停止,不进入 N4。写 handoff 前,必须以完全相同的
|
|
110
120
|
`changed_files` 计算实现内容摘要:
|
|
111
121
|
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
纯视觉替代、裸项目走下文原owner分支,不能伪造命令或specs跨过。
|
|
12
12
|
2. 从当前真实宿主确定 `--runtime codex|claude`,不能让模型选择另一端规避失败。
|
|
13
13
|
用真实会话身份作为 `--host-context`;恢复必须保留原身份、配置与 runtime,不冒用旧会话。
|
|
14
|
+
换会话恢复时,`--host-context` 填当前真实会话,另加 `--original-host-context` 填创建这次运行的旧会话 ID
|
|
15
|
+
(取自 `specs/.reviews/.execution/<runId>/state.json` 首条 `fix-configuration` 记录的
|
|
16
|
+
`configuration.hostContextId`)。durable 配置与指纹保持原样、旧记录一字不改;填错只会 `fingerprint_mismatch`
|
|
17
|
+
失败退出。两个会话身份都算宿主:授权凭据两者皆可,reviewer 必须同时独立于两者。同会话重开不带此参数。
|
|
14
18
|
3. 配置是数据文件,不是脚本模块。读取 `../../../scripts/cm-fix-host.mjs` 的配置解析与
|
|
15
19
|
`--help`,按已批准范围填写 `specsRoot`、`identity`、`defect`、`reproduction`;后者为
|
|
16
20
|
`{cwd, command, expectedFailure:{exitCode,outputIncludes}, timeoutMs}`,命令使用 argv 数组。
|
|
@@ -46,6 +50,17 @@ node "{CM_WORKFLOW_ROOT}/scripts/cm-fix-host.mjs" serve \
|
|
|
46
50
|
复现/红测/存量基线/修后及审后回归/命令走查使用同一原生specs只读沙箱;日志、证据和Learning仍由原owner负责。
|
|
47
51
|
固定命令执行器使用本机Codex sandbox,不调用模型;Claude宿主的推理和Review仍属Claude,不借用Codex身份或诊断。
|
|
48
52
|
|
|
53
|
+
沙箱里 `network={enabled=false}`,而这个开关同时管着 unix domain socket 的 listen。于是**凡是要开本地
|
|
54
|
+
IPC socket 的命令都会失败**,典型的是 `tsx` CLI(启动时在 TMPDIR 建 `<pid>.pipe`,报
|
|
55
|
+
`Error: listen EPERM`),`vitest` 等同理;写 TMPDIR 文件本身不受影响。这不是配置能绕开的:放开它就等于
|
|
56
|
+
给测试命令放开整个外网。配 `baseline.commands` / `redTest` / `walkthrough` 时请避开这类命令,例如把
|
|
57
|
+
`npm test`(内部串联 12 个 `tsx xxx.test.ts`)换成逐文件的
|
|
58
|
+
`node --import ./node_modules/tsx/dist/loader.mjs <file>`,覆盖面不变而沙箱能跑。
|
|
59
|
+
|
|
60
|
+
沙箱内失败只会留下 `outcome:"failed"` 和 `host check exited N`——原始输出**有意**不进证据(可能含密钥、
|
|
61
|
+
且不稳定)。要看真实原因,手工重放 `specsPermissionArgs` 拼出的那条 `codex sandbox ... -- <命令>`。
|
|
62
|
+
配置里留了跑不了的命令,代价是修复前后都失败、回归判 `unresolved_failure`,整轮卡在 `regression_blocked`。
|
|
63
|
+
|
|
49
64
|
`fix_test_author`/`fix_repair`请求若有`editMode:"protected-text-v1"`,当前会话只读取和生成提案,**不直接修改文件**。
|
|
50
65
|
按请求scope和expected返回`{outcome,edits:[{path,beforeSha256,content}]}`,content为完整UTF-8正文,null删除已有文件,
|
|
51
66
|
beforeSha256严格复制expected中该路径的摘要(原不存在则null);不能改路径范围或先自行落盘。blocked须edits为空数组。
|
|
@@ -132,7 +147,9 @@ handoff → 最终独立 Review/发布 → 原 N5 → 审后回归/走查 →
|
|
|
132
147
|
第二次修复仍需 fresh 独立 Review;不得重置 ≤2 轮上限。unknown 不重派。
|
|
133
148
|
|
|
134
149
|
修复完成仅认原 `finish` 的当前结果与证据;待授权、失败、漂移、缺证据如实报告,
|
|
135
|
-
|
|
150
|
+
不手工补成功。finish 接受 `policies.delivery` 的任一取值,只要求它在收尾写记录期间不变;
|
|
151
|
+
它写档案/METRICS/task_done,**不执行 Git**——branch/draft-mr 的提交、推送、开 MR 仍由执行者按
|
|
152
|
+
SKILL 第 7 步单独完成并记 `delivery` 事件。Git/发布/安装都不在这些开关的权限内。
|
|
136
153
|
退出通道用 `host_close` 或 EOF;只有用户明确取消才发 `cancel`。
|
|
137
154
|
|
|
138
155
|
本接线是源 Skill 指令,不证明安装副本已加载或真实双宿主验收。保持原输出格式,
|