@aibyzero/cm-workflow 0.16.2 → 0.16.4
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/AGENTS.md +4 -0
- package/CHANGELOG.md +147 -0
- package/README.md +44 -3
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +46 -7
- package/docs/next-steps.md +100 -0
- package/docs/untested-branches.md +24 -18
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +18 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
- package/runtime/js/cm-ai/cm-ai-admission.mjs +7 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
- package/runtime/js/cm-ai/drive-core.mjs +68 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
- package/runtime/js/cm-ai/effect-contract.mjs +4 -3
- package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
- package/runtime/js/cm-ai/host-handoff.mjs +9 -14
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
- package/runtime/js/cm-ai/host-session.mjs +10 -3
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
- package/runtime/js/cm-ai/task-runner.mjs +41 -8
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
- package/runtime/js/cm-fix/cause-package.mjs +21 -0
- package/runtime/js/cm-fix/dossier.mjs +40 -1
- package/runtime/js/cm-fix/execution.mjs +360 -83
- package/runtime/js/cm-fix/host.mjs +7 -3
- package/runtime/js/cm-fix/layout.mjs +14 -6
- package/runtime/js/cm-fix/progress.mjs +14 -0
- package/runtime/js/cm-fix/protected-edits.mjs +1 -1
- package/runtime/js/cm-fix/red-test.mjs +7 -6
- package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
- package/runtime/js/cm-fix/regression.mjs +16 -10
- package/runtime/js/cm-fix/repair.mjs +16 -13
- package/runtime/js/cm-fix/test-author.mjs +2 -1
- package/runtime/js/cm-fix/test-extension.mjs +45 -0
- package/runtime/js/cm-prd/accepted-design.mjs +28 -9
- package/runtime/js/cm-prd/analysis.mjs +68 -16
- package/runtime/js/cm-prd/change.mjs +21 -1
- package/runtime/js/cm-prd/draft-save.mjs +96 -2
- package/runtime/js/cm-prd/failed-correction.mjs +51 -0
- package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
- package/runtime/js/cm-prd/review-correction.mjs +3 -0
- package/runtime/js/cm-prd/review-disposition.mjs +33 -15
- package/runtime/js/cm-prd/review-findings.mjs +2 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -0
- package/runtime/js/cm-prd/review-preparation.mjs +28 -1
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
- package/runtime/js/cm-prd/session.mjs +5 -5
- package/runtime/js/cm-prd/split-design.mjs +67 -0
- package/runtime/js/cm-prd/summary.mjs +57 -10
- package/runtime/js/cm-refactor/workflow.mjs +100 -19
- package/runtime/js/specs-status.mjs +6 -2
- package/scripts/cm-ai-admission.mjs +2 -0
- package/scripts/cm-ai-batch-drive.mjs +251 -0
- package/scripts/cm-ai-batch-drive.test.mjs +159 -0
- package/scripts/cm-ai-batch-host.mjs +13 -5
- package/scripts/cm-ai-batch-host.test.mjs +25 -0
- package/scripts/cm-ai-contracts.test.mjs +30 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
- package/scripts/cm-ai-drive.mjs +335 -0
- package/scripts/cm-ai-drive.test.mjs +258 -0
- package/scripts/cm-ai-fix-integration.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +48 -20
- package/scripts/cm-ai-host.test.mjs +79 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
- package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
- package/scripts/cm-ai-review-timeout.test.mjs +30 -0
- package/scripts/cm-ai-run.mjs +59 -11
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
- package/scripts/cm-ai-session-chain.test.mjs +261 -0
- package/scripts/cm-ai-supersede.test.mjs +320 -0
- package/scripts/cm-check-drive.mjs +94 -0
- package/scripts/cm-check-drive.test.mjs +78 -0
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +103 -0
- package/scripts/cm-check-runtime.sh +15 -6
- package/scripts/cm-claude-developer-worker.test.mjs +40 -1
- package/scripts/cm-claude-probe.test.mjs +117 -2
- package/scripts/cm-claude-review-stream.test.mjs +43 -0
- package/scripts/cm-fix-abandon.test.mjs +383 -0
- package/scripts/cm-fix-cause-package.test.mjs +31 -1
- package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
- package/scripts/cm-fix-drive.mjs +168 -0
- package/scripts/cm-fix-drive.test.mjs +117 -0
- package/scripts/cm-fix-escalation.test.mjs +214 -0
- package/scripts/cm-fix-execution.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +4 -2
- package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
- package/scripts/cm-fix-qa-source.test.mjs +3 -3
- package/scripts/cm-fix-session-chain.test.mjs +244 -0
- package/scripts/cm-fix-test-extension.test.mjs +246 -0
- package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
- package/scripts/cm-host-handoff.test.mjs +37 -0
- package/scripts/cm-idea-drive.mjs +99 -0
- package/scripts/cm-idea-drive.test.mjs +50 -0
- package/scripts/cm-init-drive.mjs +191 -0
- package/scripts/cm-init-drive.test.mjs +59 -0
- package/scripts/cm-log-event.mjs +9 -0
- package/scripts/cm-prd-completion.test.mjs +30 -2
- package/scripts/cm-prd-design-phase.test.mjs +355 -15
- package/scripts/cm-prd-drive.mjs +314 -0
- package/scripts/cm-prd-drive.test.mjs +164 -0
- package/scripts/cm-prd-host.mjs +46 -17
- package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
- package/scripts/cm-prd-review-disposition.test.mjs +133 -7
- package/scripts/cm-prd-review-gate.mjs +23 -4
- package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
- package/scripts/cm-prd-summary.test.mjs +79 -4
- package/scripts/cm-refactor-drive.mjs +237 -0
- package/scripts/cm-refactor-drive.test.mjs +77 -0
- package/scripts/cm-refactor-gaps.test.mjs +276 -0
- package/scripts/cm-refactor-host.test.mjs +1 -48
- package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
- package/scripts/cm-specs-status.test.mjs +19 -0
- package/scripts/cm-test-drive.mjs +132 -0
- package/scripts/cm-test-drive.test.mjs +91 -0
- package/scripts/cm-test-session.test.mjs +117 -0
- package/scripts/correction-check.test.mjs +38 -0
- package/scripts/fixtures/claude-model-marker.mjs +6 -0
- package/scripts/fixtures/claude-review-process.mjs +7 -0
- package/scripts/fixtures/cm-refactor.mjs +56 -0
- package/scripts/test-shell-compat.sh +67 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -0
- package/skills/cm-ai/references/N8-finish.md +1 -0
- package/skills/cm-ai/references/js-host.md +85 -3
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +4 -2
- package/skills/cm-fix/SKILL.md +11 -4
- package/skills/cm-fix/references/js-host.md +67 -2
- package/skills/cm-fix/references/test-extension.md +57 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-prd/SKILL.md +8 -8
- package/skills/cm-prd/references/js-change-recovery.md +71 -0
- package/skills/cm-prd/references/js-host.md +64 -2
- package/skills/cm-prd/references/spec-self-check.md +14 -2
- package/skills/cm-refactor/SKILL.md +5 -0
- package/skills/cm-refactor/references/js-batch.md +3 -1
- package/skills/cm-refactor/references/js-host.md +49 -0
- package/skills/cm-test/references/js-host.md +5 -0
- package/skills/cm-test/references/unit-coverage.md +2 -2
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
2
|
+
import test,{after} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
10
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
11
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
12
|
+
import {createHostQaExecutor} from '../runtime/js/cm-ai/host-qa-executor.mjs';
|
|
13
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
15
|
+
import {previousQaMaterial,qaRevisionChain} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
16
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-revision-home-'));
|
|
17
|
+
const savedEnvironment={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
18
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'config');
|
|
19
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
20
|
+
after(()=>{
|
|
21
|
+
for(const [key,value] of Object.entries(savedEnvironment)){
|
|
22
|
+
if(value===undefined)delete process.env[key];else process.env[key]=value;
|
|
23
|
+
}
|
|
24
|
+
fs.rmSync(isolatedHome,{recursive:true,force:true});
|
|
25
|
+
});
|
|
26
|
+
const identity={repositoryId:'control-fixture',runId:'control-run',taskId:'T-001',attempt:1};
|
|
27
|
+
const request=operation=>({version:1,operation,requestId:operation,identity});
|
|
28
|
+
async function fixture(fn){
|
|
29
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-control-')));
|
|
30
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.login';
|
|
31
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject,{recursive:true});
|
|
32
|
+
fs.writeFileSync(path.join(codeProject,'a.js'),'old\n');
|
|
33
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'fixture\n');
|
|
34
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Requirements\n');
|
|
35
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Design\n');
|
|
36
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: implement\n');
|
|
37
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
38
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:['a.js'],requirements:['requirements.md']};
|
|
39
|
+
const config=path.join(root,'run.json');fs.writeFileSync(config,JSON.stringify(definition));
|
|
40
|
+
try{await fn({root,specsDir,codeProject,definition,config});}
|
|
41
|
+
finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
async function completed(f,{attach=false,twoAttempts=false}={}){
|
|
46
|
+
let calls=0,reviews=0;
|
|
47
|
+
const execution={configuration:{kind:'synthetic-host-v1'},timeoutMs:2000,excludedContexts:['main'],
|
|
48
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'dev',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
49
|
+
calls++;fs.writeFileSync(path.join(f.codeProject,'a.js'),'new\n');
|
|
50
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
51
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
52
|
+
}})},
|
|
53
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',
|
|
54
|
+
allowed:true,available:true,contexts:['review-1','review-2'],run:(request,{onEvent})=>{
|
|
55
|
+
reviews++;
|
|
56
|
+
onEvent({event:'thread.started',provider_thread:`actual-review-${request.identity.attempt}`});
|
|
57
|
+
onEvent({event:'turn.started',item_type:null});
|
|
58
|
+
onEvent({event:'item.completed',item_type:'agent_message'});
|
|
59
|
+
onEvent({event:'turn.completed',item_type:null});
|
|
60
|
+
onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
61
|
+
const verdict=twoAttempts&&request.identity.attempt===1?'changes_requested':'approved';
|
|
62
|
+
return {status:'succeeded',value:{verdict,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
63
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:verdict==='approved'?[]:
|
|
64
|
+
[{id:'F1',severity:'P2',path:'a.js',message:'Review again',evidence:'Synthetic first attempt'}],summary:'Synthetic review'}};
|
|
65
|
+
}}],
|
|
66
|
+
reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main'],
|
|
67
|
+
authorize:(request,{authorizationAt})=>{
|
|
68
|
+
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.attempt}`,adapterId:'codex-review-adapter',
|
|
69
|
+
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
70
|
+
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
71
|
+
hostContextId:'main',decisionId:`decision-${request.identity.attempt}`,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
72
|
+
return {...body,grantDigest:digest(body)};
|
|
73
|
+
}},
|
|
74
|
+
hostDecision:{status:'approved'},
|
|
75
|
+
check:createHostCheck({cwd:f.codeProject,commands:[{id:'content',command:[process.execPath,'-e',
|
|
76
|
+
"require('node:assert/strict').equal(require('node:fs').readFileSync('a.js','utf8'),'new\\n')"]}]})};
|
|
77
|
+
|
|
78
|
+
const qa={commands:[],environment:{kind:'web',carrier:'browser',target:'fixture',scope:'local'}};
|
|
79
|
+
execution.configuration={kind:'synthetic-host-v1',hostContextId:'main',workflow:{qa,documentationPaths:[],applicableAgentFiles:[]}};
|
|
80
|
+
execution.qaLogHome=path.join(f.root,'logs');
|
|
81
|
+
execution.qaDecisionProvider={timeoutMs:1000,decide:async binding=>({decisionId:'host-qa',identity:binding.identity,
|
|
82
|
+
packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-07T20:00:00Z'})};
|
|
83
|
+
const configure=qa=>{
|
|
84
|
+
execution.configuration.workflow.qa=qa;
|
|
85
|
+
execution.qaExecutor=createHostQaExecutor({codeProject:f.codeProject,specsDir:f.specsDir,feature:'1.login',
|
|
86
|
+
requirements:['requirements.md'],runtime:'codex',...qa,timeoutMs:60000,logHome:execution.qaLogHome});
|
|
87
|
+
};
|
|
88
|
+
configure(qa);
|
|
89
|
+
const provider=execution.qaDecisionProvider;
|
|
90
|
+
if(attach){execution.configuration.workflow.qa=null;delete execution.qaExecutor;delete execution.qaDecisionProvider;}
|
|
91
|
+
let run=await openControlRun(f.definition,'create',execution);
|
|
92
|
+
let result=await run.host.handle(request('advance'));run.close();
|
|
93
|
+
if(attach){
|
|
94
|
+
assert.equal(result.code,'qa_decision_required');configure(qa);execution.qaDecisionProvider=provider;
|
|
95
|
+
run=await openControlRun(f.definition,'resume',execution);result=await run.host.handle(request('advance'));run.close();
|
|
96
|
+
}
|
|
97
|
+
assert.equal(result.code,'qa_result_blocked',JSON.stringify(result));
|
|
98
|
+
assert.equal(result.state,'fixture_completed');
|
|
99
|
+
assert.equal(calls,twoAttempts?2:1);assert.equal(reviews,twoAttempts?2:1);
|
|
100
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,'1.login','tasks.md'),'utf8'),/\[x\]/);
|
|
101
|
+
return {execution,configure,qa,counts:()=>({calls,reviews})};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
test('F7 probe: completed N5 plus commands-unavailable has no existing resume exit',()=>fixture(async f=>{
|
|
105
|
+
const {execution,configure,qa}=await completed(f);
|
|
106
|
+
const state=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json')));
|
|
107
|
+
const reports=fs.readdirSync(path.join(f.specsDir,'.reviews')).filter(p=>p.endsWith('-execution.md'));
|
|
108
|
+
assert.equal(reports.length,1);assert.match(fs.readFileSync(path.join(f.specsDir,'.reviews',reports[0]),'utf8'),/commands-unavailable/);
|
|
109
|
+
let run=await openControlRun(f.definition,'resume',execution,{rerunBlockedQa:true});
|
|
110
|
+
const blocked=await run.host.handle(request('advance'));run.close();
|
|
111
|
+
assert.equal(blocked.code,'qa_rerun_not_blocked_by_evidence');
|
|
112
|
+
configure({...qa,commands:[{id:'syntax',command:[process.execPath,'--check','a.js'],caseIds:[]}]});
|
|
113
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution),{code:'fingerprint_mismatch'});
|
|
114
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,{rerunBlockedQa:true}),{code:'fingerprint_mismatch'});
|
|
115
|
+
run=await openControlRun({...f.definition,identity:{...identity,runId:'replacement'}},'create',execution);
|
|
116
|
+
assert.equal(run.blocked.state,'complete');run.close();
|
|
117
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'))),state);
|
|
118
|
+
console.log('F7 probe: commands-unavailable -> qa_rerun_not_blocked_by_evidence; fixed config -> fingerprint_mismatch; new run -> admission complete');
|
|
119
|
+
}));
|
|
120
|
+
|
|
121
|
+
const statePath=f=>path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
122
|
+
const snapshot=f=>JSON.parse(fs.readFileSync(statePath(f)));
|
|
123
|
+
const fixedQa=qa=>({...qa,commands:[{id:'version',command:[process.execPath,'--version'],caseIds:[]}]});
|
|
124
|
+
const revision=qa=>({qaConfigRevision:{previousWorkflow:{qa,documentationPaths:[],applicableAgentFiles:[]},reason:'Correct missing project QA command'}});
|
|
125
|
+
|
|
126
|
+
test('F7 revision resumes N6, preserves N5 and history, replays without authorization flag',()=>fixture(async f=>{
|
|
127
|
+
const {execution,configure,qa,counts}=await completed(f),before=snapshot(f);
|
|
128
|
+
const review=path.join(f.specsDir,'.reviews','login-T-001-r1.md'),receipt=fs.readFileSync(review);
|
|
129
|
+
const log=path.join(f.specsDir,'运行日志.jsonl'),logBefore=fs.readFileSync(log,'utf8');
|
|
130
|
+
configure(fixedQa(qa));
|
|
131
|
+
let run=await openControlRun(f.definition,'resume',execution,revision(qa));
|
|
132
|
+
let result=await run.host.handle(request('advance'));run.close();
|
|
133
|
+
assert.notEqual(result.code,'qa_result_blocked');
|
|
134
|
+
const after=snapshot(f),records=after.records.filter(r=>r.payload.type==='qa-config-revised');
|
|
135
|
+
assert.equal(records.length,1);assert.deepEqual(after.fingerprints,before.fingerprints);
|
|
136
|
+
assert.deepEqual(after.records.slice(0,before.records.length),before.records);
|
|
137
|
+
assert(fs.readFileSync(review).equals(receipt));assert.deepEqual(counts(),{calls:1,reviews:1});
|
|
138
|
+
assert(fs.readFileSync(log,'utf8').startsWith(logBefore));
|
|
139
|
+
const rows=fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse).filter(r=>r.event==='test_run');
|
|
140
|
+
assert.deepEqual(rows.filter(r=>r.phase==='start').map(r=>r.attempt),[1,2]);
|
|
141
|
+
assert.equal(rows.filter(r=>r.phase==='superseded'&&r.reason==='qa_configuration_revision').length,1);
|
|
142
|
+
assert.equal(rows.filter(r=>r.phase==='complete').at(-1).result,'PASS');
|
|
143
|
+
run=await openControlRun(f.definition,'resume',execution);await run.host.handle(request('advance'));run.close();
|
|
144
|
+
assert.deepEqual(snapshot(f),after);
|
|
145
|
+
configure(qa);await assert.rejects(openControlRun(f.definition,'resume',execution),{code:'fingerprint_mismatch'});
|
|
146
|
+
}));
|
|
147
|
+
|
|
148
|
+
test('F7 revision rejects create, missing reason, unrelated drift and exhausted QA budget',()=>fixture(async f=>{
|
|
149
|
+
const {execution,configure,qa}=await completed(f);configure(fixedQa(qa));
|
|
150
|
+
await assert.rejects(openControlRun(f.definition,'create',execution,revision(qa)),{code:'qa_revision_authorization_required'});
|
|
151
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,{qaConfigRevision:{...revision(qa).qaConfigRevision,reason:' '}}),{code:'qa_revision_authorization_required'});
|
|
152
|
+
execution.configuration.unrelated='drift';
|
|
153
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,revision(qa)),{code:'fingerprint_mismatch'});
|
|
154
|
+
delete execution.configuration.unrelated;
|
|
155
|
+
execution.configuration.workflow.documentationPaths=['a.js'];
|
|
156
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,revision(qa)),{code:'fingerprint_mismatch'});
|
|
157
|
+
execution.configuration.workflow.documentationPaths=[];
|
|
158
|
+
await assert.rejects(openControlRun({...f.definition,scope:['a.js','unrelated.mjs']},'resume',execution,revision(qa)),{code:'fingerprint_mismatch'});
|
|
159
|
+
let prior=qa;
|
|
160
|
+
for(let round=2;round<=3;round++){
|
|
161
|
+
const next={...prior,environment:{...prior.environment,target:`fixture-${round}`}};configure(next);
|
|
162
|
+
const run=await openControlRun(f.definition,'resume',execution,revision(prior));
|
|
163
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_result_blocked');run.close();prior=next;
|
|
164
|
+
}
|
|
165
|
+
configure(fixedQa(prior));const before=snapshot(f);
|
|
166
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,revision(prior)),{code:'qa_round_invalid'});
|
|
167
|
+
assert.deepEqual(snapshot(f),before);
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
test('F7 revision repairs journal-only crash, repeated authorization is idempotent, stale QA is rejected',()=>fixture(async f=>{
|
|
171
|
+
const {execution,configure,qa}=await completed(f);configure(fixedQa(qa));
|
|
172
|
+
let run=await openControlRun(f.definition,'resume',execution,revision(qa));run.close();
|
|
173
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(f.specsDir,'.cm-status.json'))).state,'qa_pending');
|
|
174
|
+
const saved=snapshot(f),record=saved.records.at(-1).payload.record;
|
|
175
|
+
const log=path.join(f.specsDir,'运行日志.jsonl');
|
|
176
|
+
const {inspectCmAiQaResult}=await import('../runtime/js/cm-ai/cm-ai-qa-log.mjs');
|
|
177
|
+
const binding={specsDir:f.specsDir,feature:'1.login',identity,packageDigest:record.packageDigest,testRunId:record.testRunId};
|
|
178
|
+
assert.throws(()=>inspectCmAiQaResult(binding),{code:'qa_result_superseded'});
|
|
179
|
+
const before=fs.readFileSync(log,'utf8');
|
|
180
|
+
// Actual crash prefix: journal durable, mirror append not yet written.
|
|
181
|
+
fs.writeFileSync(log,before.split('\n').filter(line=>!line||JSON.parse(line).reason!=='qa_configuration_revision').join('\n'));
|
|
182
|
+
run=await openControlRun(f.definition,'resume',execution,revision(qa));run.close();
|
|
183
|
+
assert.deepEqual(snapshot(f),saved);
|
|
184
|
+
assert.throws(()=>inspectCmAiQaResult(binding),{code:'qa_result_superseded'});
|
|
185
|
+
run=await openControlRun(f.definition,'resume',execution);await run.host.handle(request('advance'));run.close();
|
|
186
|
+
const rows=fs.readFileSync(log,'utf8').trim().split('\n').map(JSON.parse);
|
|
187
|
+
assert.equal(rows.filter(r=>r.reason==='qa_configuration_revision').length,1);
|
|
188
|
+
assert.deepEqual(rows.filter(r=>r.event==='test_run'&&r.phase==='start').map(r=>r.attempt),[1,2]);
|
|
189
|
+
}));
|
|
190
|
+
|
|
191
|
+
test('F7 revision chain rejects forged predecessor, record package and unrecorded config drift',()=>fixture(async f=>{
|
|
192
|
+
const {execution,configure,qa}=await completed(f);configure(fixedQa(qa));
|
|
193
|
+
const run=await openControlRun(f.definition,'resume',execution,revision(qa));run.close();
|
|
194
|
+
const saved=snapshot(f),{readRunnerHistory}=await import('../runtime/js/cm-ai/durable-runner-state.mjs');
|
|
195
|
+
const rechain=records=>records.map((r,index)=>{
|
|
196
|
+
const {digest:ignored,...body}=r;body.previousDigest=index?records[index-1].digest:null;
|
|
197
|
+
const next={...body,digest:digest(body)};records[index]=next;return next;
|
|
198
|
+
});
|
|
199
|
+
for(const [field,value,code] of [['fromFingerprint','b'.repeat(64),'qa_revision_chain_invalid'],['packageDigest','b'.repeat(64),'package_mismatch']]){
|
|
200
|
+
const records=structuredClone(saved.records);records.at(-1).payload.record[field]=value;
|
|
201
|
+
assert.throws(()=>readRunnerHistory(rechain(records),saved.records[0].payload.config,3),{code});
|
|
202
|
+
}
|
|
203
|
+
configure({...fixedQa(qa),environment:{...qa.environment,target:'unrecorded'}});
|
|
204
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution),{code:'fingerprint_mismatch'});
|
|
205
|
+
assert.deepEqual(snapshot(f),saved);
|
|
206
|
+
}));
|
|
207
|
+
|
|
208
|
+
test('F7 CLI requires resume, QA permission, old config and a reason before opening a run',()=>fixture(async f=>{
|
|
209
|
+
const host=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
210
|
+
const args=['serve','--config',f.config,'--mode','resume','--host-context','main','--allow-development'];
|
|
211
|
+
for(const extra of [['--revise-qa-config','missing.json'],['--qa-config-revision-reason','fix'],
|
|
212
|
+
['--allow-qa','--revise-qa-config','missing.json'],
|
|
213
|
+
['--allow-qa','--revise-qa-config','missing.json','--qa-config-revision-reason','fix','--rerun-blocked-qa']]){
|
|
214
|
+
const result=spawnSync(process.execPath,[host,...args,...extra],{encoding:'utf8',input:'',timeout:10000});
|
|
215
|
+
assert.equal(result.status,1);assert.match(result.stderr,/qa_revision_authorization_required/);
|
|
216
|
+
}
|
|
217
|
+
}));
|
|
218
|
+
|
|
219
|
+
test('F7 revision follows qa-attached and can supersede a completed PASS without renewing N5',()=>fixture(async f=>{
|
|
220
|
+
const {execution,configure,qa,counts}=await completed(f,{attach:true});
|
|
221
|
+
const before=snapshot(f),fixed=fixedQa(qa);configure(fixed);
|
|
222
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution),{code:'fingerprint_mismatch'});
|
|
223
|
+
assert.deepEqual(snapshot(f),before);
|
|
224
|
+
let run=await openControlRun(f.definition,'resume',execution,revision(qa));
|
|
225
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
226
|
+
const changed={...fixed,environment:{...fixed.environment,target:'corrected-environment'},timeoutMs:3000};configure(changed);
|
|
227
|
+
run=await openControlRun(f.definition,'resume',execution,revision(fixed));
|
|
228
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
229
|
+
run=await openControlRun(f.definition,'resume',execution);run.close();
|
|
230
|
+
const after=snapshot(f);assert.deepEqual(after.records.slice(0,before.records.length),before.records);
|
|
231
|
+
assert.equal(after.records.filter(r=>r.payload.type==='qa-attached').length,1);
|
|
232
|
+
assert.equal(after.records.filter(r=>r.payload.type==='qa-config-revised').length,2);
|
|
233
|
+
assert.deepEqual(counts(),{calls:1,reviews:1});
|
|
234
|
+
}));
|
|
235
|
+
|
|
236
|
+
test('F7 revision cannot authorize source drift or an unknown QA invocation',()=>fixture(async f=>{
|
|
237
|
+
const {execution,configure,qa}=await completed(f);configure(fixedQa(qa));
|
|
238
|
+
const before=snapshot(f),source=path.join(f.codeProject,'a.js');
|
|
239
|
+
fs.writeFileSync(source,'drift\n');
|
|
240
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,revision(qa)),{code:'qa_revision_not_completed'});
|
|
241
|
+
fs.writeFileSync(source,'new\n');
|
|
242
|
+
const log=path.join(f.specsDir,'运行日志.jsonl');
|
|
243
|
+
const lines=fs.readFileSync(log,'utf8').trim().split('\n');
|
|
244
|
+
const last=lines.findLastIndex(line=>{const r=JSON.parse(line);return r.event==='test_run'&&r.phase==='complete';});
|
|
245
|
+
fs.writeFileSync(log,lines.slice(0,last).join('\n')+'\n');
|
|
246
|
+
await assert.rejects(openControlRun(f.definition,'resume',execution,revision(qa)),{code:'qa_result_incomplete'});
|
|
247
|
+
assert.deepEqual(snapshot(f),before);
|
|
248
|
+
}));
|
|
249
|
+
|
|
250
|
+
test('F7 revision binds the completed development attempt independently of the QA round',()=>fixture(async f=>{
|
|
251
|
+
const {execution,configure,qa,counts}=await completed(f,{twoAttempts:true});configure(fixedQa(qa));
|
|
252
|
+
const before=snapshot(f);let run=await openControlRun(f.definition,'resume',execution,revision(qa));
|
|
253
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
254
|
+
run=await openControlRun(f.definition,'resume',execution);run.close();
|
|
255
|
+
assert.deepEqual(snapshot(f).records.slice(0,before.records.length),before.records);
|
|
256
|
+
assert.deepEqual(counts(),{calls:2,reviews:2});
|
|
257
|
+
}));
|
|
258
|
+
|
|
259
|
+
test('F7 review R1: QA revision refuses non-QA workflow changes at reconstruction and resume',()=>fixture(async f=>{
|
|
260
|
+
const {execution,configure,qa}=await completed(f),before=snapshot(f);
|
|
261
|
+
configure(fixedQa(qa));
|
|
262
|
+
execution.configuration.workflow.documentationPaths=['a.js'];
|
|
263
|
+
const options=revision(qa);
|
|
264
|
+
await assert.rejects(async()=>{
|
|
265
|
+
const run=await openControlRun(f.definition,'resume',execution,options);run.close();
|
|
266
|
+
},{code:'fingerprint_mismatch'});
|
|
267
|
+
assert.deepEqual(snapshot(f),before);
|
|
268
|
+
// The original store fingerprint also rejects this resume. Exercise the
|
|
269
|
+
// reconstruction boundary independently so that fallback cannot mask its loss.
|
|
270
|
+
const executor=execution.qaExecutor;
|
|
271
|
+
const material={definition:f.definition,execution:execution.configuration,
|
|
272
|
+
qaDecisionProvider:'host-v1',qaTimeoutMs:execution.qaDecisionProvider.timeoutMs,
|
|
273
|
+
qaExecutor:{version:1,mode:executor.mode,caseCount:executor.caseCount,
|
|
274
|
+
timeoutMs:executor.timeoutMs,configuration:executor.configuration}};
|
|
275
|
+
assert.throws(()=>previousQaMaterial(material,options.qaConfigRevision.previousWorkflow),{code:'fingerprint_mismatch'});
|
|
276
|
+
}));
|
|
277
|
+
|
|
278
|
+
test('F7 review R2: two revisions require strictly increasing QA rounds in both chain readers',()=>fixture(async f=>{
|
|
279
|
+
const {execution,configure,qa}=await completed(f),fixed=fixedQa(qa);
|
|
280
|
+
configure(fixed);
|
|
281
|
+
let run=await openControlRun(f.definition,'resume',execution,revision(qa));
|
|
282
|
+
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
283
|
+
configure({...fixed,environment:{...fixed.environment,target:'second-revision'}});
|
|
284
|
+
run=await openControlRun(f.definition,'resume',execution,revision(fixed));run.close();
|
|
285
|
+
const saved=snapshot(f),revisions=saved.records.filter(r=>r.payload.type==='qa-config-revised');
|
|
286
|
+
assert.deepEqual(revisions.map(r=>r.payload.record.qaRound),[1,2]);
|
|
287
|
+
assert(revisions[1].payload.record.qaRound>revisions[0].payload.record.qaRound);
|
|
288
|
+
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
289
|
+
assert.equal(rows.find(r=>r.event==='test_run'&&r.phase==='complete'&&r.attempt===2)?.result,'PASS');
|
|
290
|
+
const {readRunnerHistory}=await import('../runtime/js/cm-ai/durable-runner-state.mjs');
|
|
291
|
+
assert.doesNotThrow(()=>qaRevisionChain(saved));
|
|
292
|
+
assert.doesNotThrow(()=>readRunnerHistory(saved.records,saved.records[0].payload.config,3));
|
|
293
|
+
for(const [first,second] of [[1,1],[2,1]]){
|
|
294
|
+
// Mutate only a synthetic in-memory journal. Re-seal it so hash validation
|
|
295
|
+
// does not hide a missing semantic round-order check. Both rounds stay valid.
|
|
296
|
+
const forged=structuredClone(saved),changed=forged.records.filter(r=>r.payload.type==='qa-config-revised');
|
|
297
|
+
changed[0].payload.record.qaRound=first;changed[1].payload.record.qaRound=second;
|
|
298
|
+
for(let i=0;i<forged.records.length;i++){
|
|
299
|
+
const {digest:ignored,...body}=forged.records[i];
|
|
300
|
+
body.previousDigest=i?forged.records[i-1].digest:null;
|
|
301
|
+
forged.records[i]={...body,digest:digest(body)};
|
|
302
|
+
}
|
|
303
|
+
const {revision:ignored,...body}=forged;forged.revision=digest(body);
|
|
304
|
+
assert.throws(()=>qaRevisionChain(forged),{code:'qa_revision_chain_invalid'},`chain rounds ${first} -> ${second}`);
|
|
305
|
+
assert.throws(()=>readRunnerHistory(forged.records,forged.records[0].payload.config,3),
|
|
306
|
+
{code:'qa_revision_chain_invalid'},`replay rounds ${first} -> ${second}`);
|
|
307
|
+
}
|
|
308
|
+
assert.deepEqual(snapshot(f),saved);
|
|
309
|
+
}));
|
|
310
|
+
|
|
311
|
+
test('F7 review R3: normal resume rejects QA and non-QA drift from the recorded chain end',()=>fixture(async f=>{
|
|
312
|
+
const {execution,configure,qa,counts}=await completed(f),fixed=fixedQa(qa);
|
|
313
|
+
configure(fixed);
|
|
314
|
+
let run=await openControlRun(f.definition,'resume',execution,revision(qa));run.close();
|
|
315
|
+
const saved=snapshot(f),log=path.join(f.specsDir,'运行日志.jsonl'),logBefore=fs.readFileSync(log);
|
|
316
|
+
run=await openControlRun(f.definition,'resume',execution);run.close();
|
|
317
|
+
for(const drift of ['qa','non-qa']){
|
|
318
|
+
configure(drift==='qa'?{...fixed,environment:{...fixed.environment,target:'not-the-chain-end'}}:fixed);
|
|
319
|
+
execution.configuration.workflow.documentationPaths=drift==='non-qa'?['a.js']:[];
|
|
320
|
+
await assert.rejects(async()=>{
|
|
321
|
+
const opened=await openControlRun(f.definition,'resume',execution);opened.close();
|
|
322
|
+
},{code:'fingerprint_mismatch'},`${drift} drift must not inherit the recorded revision`);
|
|
323
|
+
assert.deepEqual(snapshot(f),saved);assert(fs.readFileSync(log).equals(logBefore));
|
|
324
|
+
}
|
|
325
|
+
configure(fixed);execution.configuration.workflow.documentationPaths=[];
|
|
326
|
+
run=await openControlRun(f.definition,'resume',execution);run.close();
|
|
327
|
+
assert.deepEqual(counts(),{calls:1,reviews:1});
|
|
328
|
+
}));
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
10
|
+
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
11
|
+
import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
12
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
|
+
import {qaFixIdentity} from '../runtime/js/cm-fix/qa-source.mjs';
|
|
14
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
15
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
16
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
17
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
18
|
+
|
|
19
|
+
// Real parent/child stores and grants; synthetic provider results. No native
|
|
20
|
+
// Codex sandbox, network, install or user's runtime configuration is needed.
|
|
21
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'qa-fix-session-home-'));
|
|
22
|
+
process.env.CM_WORKFLOW_HOME=path.join(home,'user');
|
|
23
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(home,'logs');
|
|
24
|
+
after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
25
|
+
const A='session-A',B='session-B',C='session-C';
|
|
26
|
+
const prepare=async()=>({files:[],contextDigest:digest([]),application:{contextDigest:digest([]),
|
|
27
|
+
status:'no_relevant_lesson',summary:'Synthetic fixture'}});
|
|
28
|
+
const diagnosis={status:'diagnosed',rootCause:'Wrong constant across layers',affectedPaths:['value.mjs'],
|
|
29
|
+
affectedModules:['value'],plan:'Set value to 2 after review',crossLayer:true};
|
|
30
|
+
function events(onEvent,thread){
|
|
31
|
+
for(const event of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},
|
|
32
|
+
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
|
|
33
|
+
{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
34
|
+
}
|
|
35
|
+
async function fixture(t,{childHost=A,causeContext=null}={}){
|
|
36
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'qa-fix-session-')));
|
|
37
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.value';
|
|
38
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
39
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=0;');
|
|
40
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'Value must be 2.');
|
|
41
|
+
fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
42
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
43
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
44
|
+
for(const name of ['requirements','design'])fs.writeFileSync(path.join(specsDir,feature,`${name}.md`),'# Fixture');
|
|
45
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: implement value\n');
|
|
46
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
47
|
+
const identity={repositoryId:'fixture',runId:'qa-parent',taskId:'T-001',attempt:1};
|
|
48
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:['value.mjs'],requirements:['requirements.md']};
|
|
49
|
+
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
50
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'})}};
|
|
51
|
+
const workflow={documentationPaths:[],applicableAgentFiles:[],qa:{commands:[{id:'value',command:[process.execPath,'red.mjs'],caseIds:[]}],
|
|
52
|
+
environment:{kind:'web',carrier:'browser',target:'synthetic-local',scope:'local'}}};
|
|
53
|
+
const bridge={async call(kind){
|
|
54
|
+
assert.equal(kind,'develop');fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;');
|
|
55
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
56
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
57
|
+
}};
|
|
58
|
+
const executionFor=live=>{
|
|
59
|
+
const execution=createConversationExecution(definition,live,bridge,review,1,workflow,true,'codex',
|
|
60
|
+
live===A?{}:{originalHostContextId:A});
|
|
61
|
+
execution.check=createHostCheck({cwd:codeProject,commands:[{id:'existing',command:[process.execPath,'existing.mjs']}]});
|
|
62
|
+
execution.reviewers[0].run=async(request,{onEvent})=>{
|
|
63
|
+
events(onEvent,'synthetic-parent-review');
|
|
64
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
65
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic review'}};
|
|
66
|
+
};
|
|
67
|
+
execution.qaDecisionProvider={...execution.qaDecisionProvider,decide:async binding=>({decisionId:'qa-parent',identity:binding.identity,
|
|
68
|
+
packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-08T01:00:00Z'})};
|
|
69
|
+
execution.qaExecutor={...execution.qaExecutor,run:async()=>{
|
|
70
|
+
const report=path.join(specsDir,'.reviews','qa-failure.md');fs.writeFileSync(report,'Synthetic QA FAIL: value must be 2.');
|
|
71
|
+
return {result:'FAIL',passed:0,failed:1,blocked:0,report};
|
|
72
|
+
}};
|
|
73
|
+
return execution;
|
|
74
|
+
};
|
|
75
|
+
let parent=null,owner=null;
|
|
76
|
+
t.after(()=>{owner?.close();parent?.close();fs.rmSync(root,{recursive:true,force:true});});
|
|
77
|
+
const request=operation=>({version:1,requestId:operation,operation,identity});
|
|
78
|
+
parent=await openControlRun(definition,'create',executionFor(A));
|
|
79
|
+
const failed=await parent.host.handle(request('advance'));
|
|
80
|
+
assert.equal(failed.code,'qa_failed',JSON.stringify(failed));parent.close();parent=null;
|
|
81
|
+
const qaSource={feature,identity,packageDigest:failed.packageDigest,testRunId:failed.fixHandoff.source.testRunId,
|
|
82
|
+
handoffDigest:failed.fixHandoff.handoffDigest};
|
|
83
|
+
const permissions=['--allow-cause-review'];
|
|
84
|
+
const reviewHost=live=>createFixReviewHost({codeProject,hostContextId:live,review,permissions,workerFactory:()=>async({prompt},{onEvent})=>{
|
|
85
|
+
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);events(onEvent,'synthetic-child-review');
|
|
86
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,
|
|
87
|
+
examinedPaths:['value.mjs'],findings:[],summary:'Synthetic cause review'}};
|
|
88
|
+
}});
|
|
89
|
+
const configuration={hostContextId:childHost,defect:'Value must be 2',qaSource,
|
|
90
|
+
causeReview:{...reviewHost(A).reviewer,...(causeContext?{contextId:causeContext}:{})},
|
|
91
|
+
reproduction:{cwd:codeProject,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000}};
|
|
92
|
+
const fix={specsRoot:specsDir,identity:qaFixIdentity(qaSource),configuration};
|
|
93
|
+
const childDir=path.join(specsDir,'.reviews','.execution',fix.identity.runId),statePath=path.join(childDir,'state.json');
|
|
94
|
+
const bound=operation=>({...request(operation),packageDigest:failed.packageDigest,testRunId:qaSource.testRunId});
|
|
95
|
+
const close=()=>{owner?.close();owner=null;};
|
|
96
|
+
const open=async(live,{allowStart=true,template=false,allowAbandon=false,lostDiagnosis=false}={})=>{
|
|
97
|
+
close();const execution=executionFor(live);assert.equal(execution.configuration.hostContextId,A);
|
|
98
|
+
parent=await openControlRun(definition,'resume',execution);
|
|
99
|
+
const rh=reviewHost(live);
|
|
100
|
+
const {qaSource:ignored,...templateConfiguration}=configuration;
|
|
101
|
+
owner=createQaFixOwnerHost({parent,hostContextId:live,parentHostContextId:execution.configuration.hostContextId,
|
|
102
|
+
reopenParent:()=>openControlRun(definition,'resume',execution),allowStart,
|
|
103
|
+
...(template?{template:{specsRoot:specsDir,feature,identity,configuration:templateConfiguration}}:{fix}),
|
|
104
|
+
fixPermissions:allowAbandon?[...permissions,'--allow-abandon']:permissions,
|
|
105
|
+
fixAuthorities:{authority:rh.authority,finalAuthority:rh.finalAuthority},
|
|
106
|
+
fixExecution:{...rh.execution,prepare,bridge:{async call(kind){assert.equal(kind,'fix_diagnose');
|
|
107
|
+
if(lostDiagnosis)throw Error('Synthetic lost diagnosis');return diagnosis;}}}});
|
|
108
|
+
parent=null;return owner;
|
|
109
|
+
};
|
|
110
|
+
const records=()=>JSON.parse(fs.readFileSync(statePath)).records;
|
|
111
|
+
const bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
112
|
+
const fake=path.join(bin,'codex');fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),fake);fs.chmodSync(fake,0o700);
|
|
113
|
+
for(const [name,value] of Object.entries({run:definition,review,workflow,fix}))fs.writeFileSync(path.join(root,`${name}.json`),JSON.stringify(value));
|
|
114
|
+
return {open,close,bound,fix,childDir,statePath,records,reviewHost,root,bin,request};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Exercise the actual CLI assembly as well as the direct owner. The CLI only
|
|
118
|
+
// resumes/status/reviews here: these operations do not require a native sandbox.
|
|
119
|
+
async function cli(f,live,operation,{runtime='codex',flags=[]}={}){
|
|
120
|
+
f.close();fs.writeFileSync(path.join(f.root,'fix.json'),JSON.stringify(f.fix));
|
|
121
|
+
const args=['serve','--config',path.join(f.root,'run.json'),'--mode','resume','--host-context',live,'--allow-development',
|
|
122
|
+
'--original-host-context',A,'--review-config',path.join(f.root,'review.json'),'--workflow-config',path.join(f.root,'workflow.json'),'--allow-qa',
|
|
123
|
+
'--qa-fix-owner-config',path.join(f.root,'fix.json'),'--allow-qa-fix-start','--runtime',runtime,
|
|
124
|
+
'--qa-fix-review-config',path.join(f.root,'review.json'),'--allow-qa-fix-cause-review',...flags];
|
|
125
|
+
return new Promise((resolve,reject)=>{
|
|
126
|
+
const child=spawn(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),...args],
|
|
127
|
+
{env:{...process.env,PATH:f.bin+path.delimiter+process.env.PATH},stdio:['pipe','pipe','pipe']});
|
|
128
|
+
let buffer='',stderr='',sessionId;const rows=[];
|
|
129
|
+
const timer=setTimeout(()=>{child.kill();reject(Error('QA-fix CLI timed out'));},15000);
|
|
130
|
+
child.on('error',error=>{clearTimeout(timer);reject(error);});
|
|
131
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
132
|
+
child.stdout.on('data',chunk=>{
|
|
133
|
+
buffer+=chunk;
|
|
134
|
+
while(buffer.includes('\n')){
|
|
135
|
+
const end=buffer.indexOf('\n'),line=buffer.slice(0,end);buffer=buffer.slice(end+1);if(!line)continue;
|
|
136
|
+
try{
|
|
137
|
+
const row=JSON.parse(line);rows.push(row);
|
|
138
|
+
if(row.type==='host_ready')sessionId=row.sessionId;
|
|
139
|
+
if(row.type==='host_request'){
|
|
140
|
+
assert(['fix_learning','fix_diagnose'].includes(row.kind),row.kind);
|
|
141
|
+
const result=row.kind==='fix_learning'
|
|
142
|
+
?{contextDigest:row.payload.contextDigest,status:'no_relevant_lesson',summary:'Synthetic fixture'}:diagnosis;
|
|
143
|
+
child.stdin.write(JSON.stringify({type:'host_result',sessionId:row.sessionId,callId:row.callId,
|
|
144
|
+
requestDigest:row.requestDigest,result})+'\n');
|
|
145
|
+
}
|
|
146
|
+
if(row.requestId===operation.requestId)child.stdin.write(JSON.stringify({type:'host_close',sessionId})+'\n');
|
|
147
|
+
}catch(error){child.kill();clearTimeout(timer);reject(error);}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
child.on('close',code=>{clearTimeout(timer);resolve({code,stderr,rows,result:rows.find(row=>row.requestId===operation.requestId)?.result});});
|
|
151
|
+
child.stdin.write(JSON.stringify(operation)+'\n');
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
test('A creates; B advances and signs; C reads the same child without writing',async t=>{
|
|
156
|
+
const f=await fixture(t);
|
|
157
|
+
let owner=await f.open(A);assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
158
|
+
f.close();const before=f.records();
|
|
159
|
+
owner=await f.open(B);assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
160
|
+
assert.equal((await owner.handle({...f.bound('fix_action'),fixOperation:'cause_review'})).fixStage,'red_test_required');
|
|
161
|
+
f.close();const after=f.records();assert.deepEqual(after.slice(0,before.length),before);
|
|
162
|
+
assert.deepEqual(after.slice(before.length,before.length+2).map(row=>row.id),['fix-host-joined-1','fix-cause-registered']);
|
|
163
|
+
assert.deepEqual(after.find(row=>row.id==='fix-host-joined-1').payload,{hostContextId:B});
|
|
164
|
+
assert.equal(after.find(row=>row.id==='fix-cause-registered').payload.grant.hostContextId,B);
|
|
165
|
+
const bytes=fs.readFileSync(f.statePath);
|
|
166
|
+
owner=await f.open(C,{allowStart:false});assert.equal((await owner.handle(f.bound('fix_status'))).fixStage,'red_test_required');f.close();
|
|
167
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
for(const template of [false,true])for(const childHost of [A,B,'session-X'])test(`new ${template?'template':'fixed'} child host ${childHost} from B`,async t=>{
|
|
171
|
+
const f=await fixture(t,{childHost}),owner=await f.open(B,{template});
|
|
172
|
+
if(childHost==='session-X'){
|
|
173
|
+
await assert.rejects(owner.handle(f.bound('fix_advance')),{code:'qa_fix_host_mismatch'});
|
|
174
|
+
assert.equal(fs.existsSync(f.childDir),false);
|
|
175
|
+
assert.equal((await owner.handle(f.request('status'))).state,'fixture_completed');
|
|
176
|
+
}else assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
for(const operation of ['fix_status','fix_advance'])test(`live cause reviewer is rejected on ${operation}, parent reopens`,async t=>{
|
|
180
|
+
const f=await fixture(t,{causeContext:B});
|
|
181
|
+
let owner=await f.open(A);await owner.handle(f.bound('fix_advance'));f.close();
|
|
182
|
+
const bytes=fs.readFileSync(f.statePath);owner=await f.open(B,{allowStart:operation!=='fix_status'});
|
|
183
|
+
await assert.rejects(owner.handle(f.bound(operation)),{code:'invalid_cause_reviewer'});
|
|
184
|
+
assert.equal((await owner.handle(f.request('status'))).state,'fixture_completed');f.close();
|
|
185
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test('owner requires a valid live host id',async t=>{
|
|
189
|
+
const f=await fixture(t);
|
|
190
|
+
for(const hostContextId of [undefined,'invalid host'])assert.throws(()=>createQaFixOwnerHost({hostContextId,parentHostContextId:A,
|
|
191
|
+
fix:f.fix,parent:null,reopenParent:()=>{}}),{code:'invalid_input'});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
test('reviewer metadata is independent of live host identity',async t=>{
|
|
195
|
+
const f=await fixture(t);assert.deepEqual(f.reviewHost(A).reviewer,f.reviewHost(B).reviewer);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
test('CLI resumes A child in B and signs the child grant as B; C reopens',async t=>{
|
|
199
|
+
const f=await fixture(t),owner=await f.open(A);await owner.handle(f.bound('fix_advance'));f.close();
|
|
200
|
+
const signed=await cli(f,B,{...f.bound('fix_action'),fixOperation:'cause_review'});
|
|
201
|
+
assert.equal(signed.code,0,signed.stderr);assert.equal(signed.result?.fixStage,'red_test_required',JSON.stringify(signed));
|
|
202
|
+
assert.equal(f.records().find(row=>row.id==='fix-cause-registered').payload.grant.hostContextId,B);
|
|
203
|
+
assert.deepEqual(f.records().find(row=>row.id==='fix-host-joined-1').payload,{hostContextId:B});
|
|
204
|
+
const bytes=fs.readFileSync(f.statePath),read=await cli(f,C,f.bound('fix_status'));
|
|
205
|
+
assert.equal(read.code,0,read.stderr);assert.equal(read.result?.fixStage,'red_test_required',JSON.stringify(read));
|
|
206
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test('CLI still refuses a child runtime differing from the host runtime',async t=>{
|
|
210
|
+
const f=await fixture(t,{childHost:B});f.fix.configuration.runtime='claude';
|
|
211
|
+
const result=await cli(f,B,f.bound('fix_status'));
|
|
212
|
+
assert.equal(result.code,1);assert.match(result.stderr,/"code":"qa_fix_host_mismatch"/);
|
|
213
|
+
assert.equal(fs.existsSync(f.childDir),false);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
for(const childHost of [A,B,'session-X'])test(`CLI new child host ${childHost} from resumed parent B`,async t=>{
|
|
217
|
+
const f=await fixture(t,{childHost}),result=await cli(f,B,f.bound('fix_advance'));
|
|
218
|
+
if(childHost==='session-X'){
|
|
219
|
+
assert.match(result.stderr,/qa_fix_host_mismatch/);assert.equal(fs.existsSync(f.childDir),false);
|
|
220
|
+
}else{
|
|
221
|
+
assert.equal(result.code,0,result.stderr);assert.equal(result.result?.fixStage,'cause_review_required',JSON.stringify(result));
|
|
222
|
+
}
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test('existing child creator B is accepted by C, but configuration drift is refused',async t=>{
|
|
226
|
+
const f=await fixture(t,{childHost:B});let owner=await f.open(B);
|
|
227
|
+
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');f.close();
|
|
228
|
+
const bytes=fs.readFileSync(f.statePath);owner=await f.open(C);
|
|
229
|
+
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');f.close();
|
|
230
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
231
|
+
f.fix.configuration.hostContextId=C;owner=await f.open(C);
|
|
232
|
+
await assert.rejects(owner.handle(f.bound('fix_status')),{code:'fingerprint_mismatch'});
|
|
233
|
+
assert.equal((await owner.handle(f.request('status'))).state,'fixture_completed');f.close();
|
|
234
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('QA-fix child abandons a lost local diagnosis only with its dedicated CLI flag',async t=>{
|
|
238
|
+
const f=await fixture(t);
|
|
239
|
+
let owner=await f.open(A,{lostDiagnosis:true});
|
|
240
|
+
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'unknown');
|
|
241
|
+
assert.equal(f.records().at(-1).id,'fix-diagnose-intent');
|
|
242
|
+
f.close();
|
|
243
|
+
const request={...f.bound('fix_action'),fixOperation:'abandon_step',reason:'Child diagnosis response lost'};
|
|
244
|
+
const before=fs.readFileSync(f.statePath);
|
|
245
|
+
const denied=await cli(f,A,request);
|
|
246
|
+
assert.match(denied.stderr,/fix_abandon_unavailable/);
|
|
247
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
248
|
+
const allowed=await cli(f,A,request,{flags:['--allow-qa-fix-abandon']});
|
|
249
|
+
assert.equal(allowed.code,0,allowed.stderr);
|
|
250
|
+
assert.equal(allowed.result?.fixStage,'diagnose');
|
|
251
|
+
assert(f.records().some(row=>row.id==='fix-abandoned-1'));
|
|
252
|
+
owner=await f.open(A);
|
|
253
|
+
assert.equal((await owner.handle(f.bound('fix_advance'))).fixStage,'cause_review_required');
|
|
254
|
+
assert(f.records().some(row=>row.id==='fix-diagnose-retry-1-result'));
|
|
255
|
+
});
|