@aibyzero/cm-workflow 0.16.3 → 0.16.5
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 +8 -0
- package/CHANGELOG.md +59 -0
- package/README.md +55 -3
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/next-steps.md +14 -24
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +30 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +20 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +6 -2
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +14 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +19 -10
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +93 -21
- package/scripts/cm-ai-batch-drive.test.mjs +171 -3
- package/scripts/cm-ai-batch-host.mjs +37 -13
- package/scripts/cm-ai-batch-host.test.mjs +26 -0
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +480 -47
- package/scripts/cm-ai-drive.test.mjs +247 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +89 -25
- package/scripts/cm-ai-host.test.mjs +274 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.mjs +4 -3
- package/scripts/cm-check-drive.test.mjs +17 -1
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +57 -1
- package/scripts/cm-check-runtime.sh +16 -7
- package/scripts/cm-claude-developer-worker.test.mjs +43 -2
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +68 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +105 -2
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +13 -7
- package/scripts/cm-prd-drive.test.mjs +10 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +40 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +31 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-shell-compat.sh +67 -0
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +264 -40
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +3 -3
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +30 -0
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -7,20 +7,101 @@ import path from 'node:path';
|
|
|
7
7
|
import {spawn,spawnSync} from 'node:child_process';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
10
|
-
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
10
|
+
import {createConversationExecution,main as hostMain} from './cm-ai-host.mjs';
|
|
11
|
+
import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
|
|
11
12
|
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
13
|
+
import {fixtureProcesses,guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
|
|
12
14
|
|
|
13
15
|
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
14
16
|
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-host-home-'));
|
|
15
17
|
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
16
18
|
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
17
19
|
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
20
|
+
// Every fixture root is swept once the file finishes: a surviving fake CLI or
|
|
21
|
+
// host is a leak even if its test passed (2026-09-28: fake reviewers ran 17h).
|
|
22
|
+
const fixtureRoots=new Set();
|
|
23
|
+
after(()=>{
|
|
24
|
+
const leaked=[...fixtureRoots].flatMap(root=>killFixtureProcesses(root));
|
|
25
|
+
assert.deepEqual(leaked.map(row=>row.command.slice(0,160)),[],'fixture processes outlived their tests');
|
|
26
|
+
});
|
|
18
27
|
|
|
19
28
|
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
20
29
|
const identity={repositoryId:'host-fixture',runId:'host-fixture-run',taskId:'T-001',attempt:1};
|
|
21
30
|
const request=(operation,requestId=operation)=>({version:1,operation,requestId,identity});
|
|
31
|
+
test('single host input limit parsing and transport pass-through need no running host',async()=>{
|
|
32
|
+
const {serveHostTransport}=await import('./cm-ai-host.mjs');
|
|
33
|
+
assert.equal(typeof serveHostTransport,'function');
|
|
34
|
+
const seen=[];
|
|
35
|
+
for(const raw of [undefined,'65536','1048576','4194304']){
|
|
36
|
+
await serveHostTransport({host:{}},raw,async options=>{seen.push(options.inputLimit);});
|
|
37
|
+
}
|
|
38
|
+
assert.deepEqual(seen,[65536,65536,1048576,4194304]);
|
|
39
|
+
for(const raw of ['65535','4194305','1.5','NaN']){
|
|
40
|
+
await assert.rejects(serveHostTransport({host:{}},raw,async()=>{}),/invalid_arguments/);
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
test('single host help documents input limit',()=>{
|
|
44
|
+
const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
|
|
45
|
+
assert.equal(help.status,0);assert.match(help.stdout,/--input-limit BYTES/);
|
|
46
|
+
});
|
|
47
|
+
test('single host CLI rejects out-of-range and non-integer input limits before opening a run',()=>{
|
|
48
|
+
for(const raw of ['65535','4194305','1.5']){
|
|
49
|
+
const run=spawnSync(process.execPath,[cli,'serve','--config','unused','--mode','create',
|
|
50
|
+
'--host-context','fixture','--allow-development','--input-limit',raw],{encoding:'utf8'});
|
|
51
|
+
assert.equal(run.status,1);assert.match(run.stderr,/invalid_arguments/);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
test('killing a real host at develop request leaves the original effect intent for recovery',async()=>{
|
|
55
|
+
const f=fixture();
|
|
56
|
+
try{
|
|
57
|
+
let buffer='',sawDevelop=false,stderr='';
|
|
58
|
+
const child=spawn(process.execPath,[cli,...launchArgs(f)],{stdio:['pipe','pipe','pipe'],env:process.env});
|
|
59
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
60
|
+
const done=new Promise((resolve,reject)=>{
|
|
61
|
+
const timer=setTimeout(()=>{child.kill('SIGKILL');reject(new Error('host kill fixture timed out: '+stderr));},10000);
|
|
62
|
+
child.stdout.on('data',chunk=>{
|
|
63
|
+
buffer+=chunk;
|
|
64
|
+
let newline;
|
|
65
|
+
while((newline=buffer.indexOf('\n'))!==-1){
|
|
66
|
+
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);
|
|
67
|
+
if(!line)continue;
|
|
68
|
+
const row=JSON.parse(line);
|
|
69
|
+
if(row.type==='host_ready')child.stdin.write(JSON.stringify(request('advance'))+'\n');
|
|
70
|
+
if(row.type==='host_request'&&row.kind==='develop'){sawDevelop=true;child.kill('SIGKILL');}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
child.once('error',error=>{clearTimeout(timer);reject(error);});
|
|
74
|
+
child.once('exit',(code,signal)=>{clearTimeout(timer);resolve({code,signal});});
|
|
75
|
+
});
|
|
76
|
+
const exited=await done;
|
|
77
|
+
assert.equal(sawDevelop,true,stderr);assert.equal(exited.signal,'SIGKILL');
|
|
78
|
+
const state=JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'),'utf8'));
|
|
79
|
+
assert(state.records.some(row=>row.payload.type==='effect-intent'&&row.payload.effect.kind==='develop'));
|
|
80
|
+
assert.equal(state.records.some(row=>row.payload.type==='effect-checkpoint'),false);
|
|
81
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
82
|
+
});
|
|
83
|
+
test('resume accepts a changed transport input limit without changing the durable fingerprint',async()=>{
|
|
84
|
+
const f=fixture(),bridge=createHostToolBridge();
|
|
85
|
+
try{
|
|
86
|
+
const definition=readRunDefinition(f.config);
|
|
87
|
+
const execution=createConversationExecution(definition,'native-host-fixture',bridge,null,null,null,false,'codex');
|
|
88
|
+
const first=await openControlRun(definition,'create',execution);first.close();
|
|
89
|
+
const state=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
90
|
+
const before=JSON.parse(fs.readFileSync(state,'utf8')).fingerprints;
|
|
91
|
+
let limit;
|
|
92
|
+
const {serveHostTransport}=await import('./cm-ai-host.mjs');
|
|
93
|
+
await serveHostTransport({host:{}},'65536',async options=>{limit=options.inputLimit;});
|
|
94
|
+
assert.equal(limit,65536);
|
|
95
|
+
const resumed=await openControlRun(definition,'resume',execution);resumed.close();
|
|
96
|
+
const otherSession=createConversationExecution(definition,'other-host-fixture',bridge,null,null,null,false,'codex');
|
|
97
|
+
await assert.rejects(openControlRun(definition,'resume',otherSession),{code:'fingerprint_mismatch'});
|
|
98
|
+
await serveHostTransport({host:{}},'1048576',async options=>{limit=options.inputLimit;});
|
|
99
|
+
assert.equal(limit,1048576);
|
|
100
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(state,'utf8')).fingerprints,before);
|
|
101
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
102
|
+
});
|
|
22
103
|
function fixture(){
|
|
23
|
-
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));
|
|
104
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));fixtureRoots.add(root);
|
|
24
105
|
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',config=path.join(root,'run.json');
|
|
25
106
|
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
26
107
|
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
@@ -28,15 +109,97 @@ function fixture(){
|
|
|
28
109
|
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
29
110
|
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
30
111
|
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope:['target.mjs'],requirements:['requirements.md']}));
|
|
31
|
-
|
|
112
|
+
// create requires a bound review configuration; it grants no review attempt.
|
|
113
|
+
const reviewFile=path.join(root,'placeholder-review.json');
|
|
114
|
+
fs.writeFileSync(reviewFile,JSON.stringify({model:'fixture',preflight:{}}));
|
|
115
|
+
return {root,specsDir,codeProject,config,reviewFile,args:['serve','--config',config,'--mode','create','--host-context','native-host-fixture','--allow-development']};
|
|
32
116
|
}
|
|
117
|
+
// A test that supplies its own --review-config keeps it; others use the placeholder.
|
|
118
|
+
const launchArgs=f=>f.args.includes('--review-config')?f.args:[...f.args,'--review-config',f.reviewFile];
|
|
119
|
+
|
|
120
|
+
test('D1 SIGKILL at a real host develop request leaves an intent without checkpoint',async()=>{
|
|
121
|
+
const f=fixture();
|
|
122
|
+
try{
|
|
123
|
+
const result=await new Promise((resolve,reject)=>{
|
|
124
|
+
const child=spawn(process.execPath,[cli,...launchArgs(f)],{stdio:['pipe','pipe','pipe']});
|
|
125
|
+
let buffer='',asked=false;
|
|
126
|
+
const timer=setTimeout(()=>{child.kill('SIGKILL');reject(Error('host request timeout'));},15000);
|
|
127
|
+
child.once('error',error=>{clearTimeout(timer);reject(error);});
|
|
128
|
+
child.stdout.on('data',chunk=>{
|
|
129
|
+
buffer+=chunk;
|
|
130
|
+
for(let newline;(newline=buffer.indexOf('\n'))!==-1;){
|
|
131
|
+
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);
|
|
132
|
+
if(!line)continue;
|
|
133
|
+
const row=JSON.parse(line);
|
|
134
|
+
if(row.type==='host_ready')child.stdin.write(JSON.stringify(request('advance'))+'\n');
|
|
135
|
+
if(row.type==='host_request'&&row.kind==='develop'){asked=true;child.kill('SIGKILL');}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
child.once('close',(code,signal)=>{clearTimeout(timer);resolve({code,signal,asked});});
|
|
139
|
+
});
|
|
140
|
+
assert.equal(result.signal,'SIGKILL');assert.equal(result.asked,true);
|
|
141
|
+
const state=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
142
|
+
const records=JSON.parse(fs.readFileSync(state,'utf8')).records;
|
|
143
|
+
assert.equal(records.at(-1).payload.type,'effect-intent');
|
|
144
|
+
assert.equal(records.some(row=>row.payload.type==='effect-checkpoint'),false);
|
|
145
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
test('split-root SwiftUI Claude control run creates a baseline beside Git-ignored Xcode and SwiftPM output',async()=>{
|
|
149
|
+
const f=fixture(),bridge=createHostToolBridge();
|
|
150
|
+
try{
|
|
151
|
+
const specs5=path.join(f.root,'specs5'),app=path.join(f.root,'app');
|
|
152
|
+
fs.renameSync(f.specsDir,specs5);fs.renameSync(f.codeProject,app);
|
|
153
|
+
fs.mkdirSync(path.join(app,'Sources'));fs.writeFileSync(path.join(app,'Sources','App.swift'),'import SwiftUI\n');
|
|
154
|
+
fs.writeFileSync(path.join(app,'.gitignore'),'custom-cache/\n');
|
|
155
|
+
assert.equal(spawnSync('git',['init','-q',app]).status,0);
|
|
156
|
+
fs.mkdirSync(path.join(app,'.build'));fs.symlinkSync('missing',path.join(app,'.build','workspace-state'));
|
|
157
|
+
fs.mkdirSync(path.join(app,'custom-cache'));fs.symlinkSync('missing',path.join(app,'custom-cache','linked'));
|
|
158
|
+
fs.mkdirSync(path.join(app,'DerivedData','Build'),{recursive:true});
|
|
159
|
+
for(let i=0;i<10005;i++)fs.writeFileSync(path.join(app,'DerivedData','Build',String(i)),'');
|
|
160
|
+
fs.mkdirSync(path.join(app,'App.xcodeproj','xcuserdata'),{recursive:true});
|
|
161
|
+
fs.writeFileSync(path.join(app,'App.xcodeproj','xcuserdata','UserInterfaceState.xcuserstate'),'bplist00');
|
|
162
|
+
fs.writeFileSync(path.join(app,'.DS_Store'),'finder');
|
|
163
|
+
const run=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
164
|
+
fs.writeFileSync(f.config,JSON.stringify({...run,specsDir:specs5,codeProject:app,scope:['Sources/App.swift']}));
|
|
165
|
+
const definition=readRunDefinition(f.config);
|
|
166
|
+
const execution=createConversationExecution(definition,'native-host-fixture',bridge,null,null,null,false,'claude');
|
|
167
|
+
const opened=await openControlRun(definition,'create',execution);
|
|
168
|
+
try{
|
|
169
|
+
const baseline=opened.runner?.baseline??JSON.parse(fs.readFileSync(path.join(specs5,'.reviews','.execution',identity.runId,'state.json'),'utf8')).records[0].payload.baseline;
|
|
170
|
+
assert(baseline.files.some(file=>file.path==='Sources/App.swift'));
|
|
171
|
+
assert(!baseline.files.some(file=>/\.build|DerivedData|xcuserdata|custom-cache|DS_Store/.test(file.path)));
|
|
172
|
+
}finally{opened.close();}
|
|
173
|
+
}finally{bridge.close();fs.rmSync(f.root,{recursive:true,force:true});}
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test('host create reports the offending unsupported file on stderr before transport starts',async()=>{
|
|
177
|
+
const f=fixture(),lines=[];
|
|
178
|
+
try{
|
|
179
|
+
fs.symlinkSync('missing',path.join(f.codeProject,'alien.swift'));
|
|
180
|
+
const exit=await hostMain(launchArgs(f),{input:{},output:{write(){}},error:{write(value){lines.push(value);}}});
|
|
181
|
+
assert.equal(exit,1);
|
|
182
|
+
assert.match(lines.join(''),/\[host\] unsupported_file: alien\.swift/);
|
|
183
|
+
assert.match(lines.join(''),/"reason":"unsupported_file: alien\.swift"/);
|
|
184
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
185
|
+
});
|
|
33
186
|
|
|
34
187
|
function runCli(f,mode,action='create'){
|
|
35
188
|
return new Promise((resolve,reject)=>{
|
|
36
|
-
const args=[...f
|
|
189
|
+
const args=[...launchArgs(f)];args[4]=action;
|
|
37
190
|
const child=spawn(process.execPath,[cli,...args],{stdio:['pipe','pipe','pipe'],env:f.env??process.env});
|
|
38
191
|
let buffer='',stderr='',closed=false,sessionId;const rows=[],calls=[];
|
|
39
|
-
|
|
192
|
+
// Provider children run in their own process groups: stopping only the host
|
|
193
|
+
// would orphan a hung fake reviewer, so failure and watchdog paths stop the
|
|
194
|
+
// whole fixture tree. f.watchdog(expire) may replace the timer; it returns a disarm function.
|
|
195
|
+
let disarm=()=>{};
|
|
196
|
+
const fail=error=>{
|
|
197
|
+
disarm();child.kill('SIGKILL');
|
|
198
|
+
try{killFixtureProcesses(f.root);}catch(cleanup){error=new AggregateError([error,cleanup],String(error?.message??error));}
|
|
199
|
+
reject(error);
|
|
200
|
+
};
|
|
201
|
+
disarm=(f.watchdog??(expire=>{const timer=setTimeout(expire,Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
202
|
+
return ()=>clearTimeout(timer);}))(()=>fail(new Error('host fixture timed out')));
|
|
40
203
|
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
41
204
|
child.once('error',reject);
|
|
42
205
|
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
@@ -124,10 +287,10 @@ function runCli(f,mode,action='create'){
|
|
|
124
287
|
closed=true;
|
|
125
288
|
if(mode!=='disconnect'||action==='resume')send({type:'host_close',sessionId});
|
|
126
289
|
}
|
|
127
|
-
}catch(error){
|
|
290
|
+
}catch(error){fail(error);return;}
|
|
128
291
|
}
|
|
129
292
|
});
|
|
130
|
-
child.once('close',code=>{
|
|
293
|
+
child.once('close',code=>{disarm();resolve({code,stderr,rows,calls});});
|
|
131
294
|
send(f.request??request('advance'));
|
|
132
295
|
});
|
|
133
296
|
}
|
|
@@ -747,7 +910,7 @@ function installTimeoutReviewer(f,runtime){
|
|
|
747
910
|
fs.renameSync(fake,delegate);
|
|
748
911
|
const modeFile=path.join(f.root,'review-mode.json');
|
|
749
912
|
fs.writeFileSync(modeFile,JSON.stringify('approved'));
|
|
750
|
-
fs.writeFileSync(fake,String.raw`#!${process.execPath}
|
|
913
|
+
fs.writeFileSync(fake,guardFixtureSource(String.raw`#!${process.execPath}
|
|
751
914
|
const fs=require('node:fs'),cp=require('node:child_process'),crypto=require('node:crypto');
|
|
752
915
|
const args=process.argv.slice(2),runtime=${JSON.stringify(runtime)},modeFile=${JSON.stringify(modeFile)};
|
|
753
916
|
if(args[0]==='sandbox'){const r=cp.spawnSync(${JSON.stringify(delegate)},args,{stdio:'inherit'});process.exit(r.status??1);}
|
|
@@ -769,9 +932,11 @@ let prompt='';process.stdin.on('data',s=>prompt+=s);process.stdin.on('end',()=>{
|
|
|
769
932
|
send({type:'result',subtype:'success',session_id:thread,is_error:false,num_turns:1,result:'{"verdict":"approved"}'});
|
|
770
933
|
}
|
|
771
934
|
}
|
|
935
|
+
// A hung reviewer announces its pid so the watchdog regression can find it.
|
|
936
|
+
fs.writeFileSync(modeFile+'.hung',String(process.pid));
|
|
772
937
|
setInterval(()=>{},1000);
|
|
773
938
|
});
|
|
774
|
-
|
|
939
|
+
`),{mode:0o700});
|
|
775
940
|
return mode=>fs.writeFileSync(modeFile,JSON.stringify(mode));
|
|
776
941
|
}
|
|
777
942
|
for(const [runtime,second] of [['codex','approved'],['claude','approved'],['codex','timeout'],['codex','result'],['claude','result']])
|
|
@@ -782,18 +947,22 @@ test(`protected conversation review timeout ${runtime} -> ${second}`,async()=>{
|
|
|
782
947
|
const setMode=installTimeoutReviewer(f,runtime);
|
|
783
948
|
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime',runtime],
|
|
784
949
|
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
785
|
-
const
|
|
950
|
+
const review=JSON.parse(preview.stdout);assert.equal(review.timeoutMs,900000);
|
|
951
|
+
delete review.timeoutMs;
|
|
952
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
786
953
|
f.args.push('--review-config',config,'--allow-review-attempt','1');
|
|
787
954
|
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
788
955
|
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
789
956
|
setMode(second==='result'?'result':'timeout');
|
|
790
957
|
const start=Date.now(),first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
791
958
|
const result=first.rows.find(row=>row.requestId==='advance').result;
|
|
792
|
-
// A
|
|
959
|
+
// A legacy review config without timeoutMs inherits the protected conversation's 5s reviewer budget.
|
|
793
960
|
assert(Date.now()-start>=4900);assert(Date.now()-start<14000);
|
|
794
961
|
assert.equal(result.state,second==='result'?'unknown':'pending_review');
|
|
795
962
|
assert.equal(result.code,second==='result'?'transport_timeout':'review_transport_timeout');
|
|
796
|
-
|
|
963
|
+
// A final message cut off by the timeout is never retried by itself; its
|
|
964
|
+
// only exit is the explicit, audited abandon_review (see cm-ai-review-failure).
|
|
965
|
+
assert.equal(result.pendingAction,second==='result'?'abandon_review':'resume');
|
|
797
966
|
const before=lastCheckpoint(f),original=before.reviewInvocation;
|
|
798
967
|
assert.equal(before.calls.at(-1).terminal,second==='result'?'unknown':'failed');
|
|
799
968
|
assert.equal(original.result.outcome,'timed_out');
|
|
@@ -834,6 +1003,39 @@ test(`protected conversation review timeout ${runtime} -> ${second}`,async()=>{
|
|
|
834
1003
|
}
|
|
835
1004
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
836
1005
|
});
|
|
1006
|
+
// Regression (2026-09-28): a host stopped by the fixture watchdog while its
|
|
1007
|
+
// detached fake reviewer hung left that reviewer running for 17+ hours.
|
|
1008
|
+
test('fixture watchdog stopping a host mid-review leaves no process from the fixture root',async()=>{
|
|
1009
|
+
const f=protectedResultFixture();
|
|
1010
|
+
try{
|
|
1011
|
+
f.runtime='claude';f.args.push('--runtime','claude');
|
|
1012
|
+
const setMode=installTimeoutReviewer(f,'claude');
|
|
1013
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime','claude'],
|
|
1014
|
+
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
1015
|
+
// Keep the 15-minute reviewer budget: only the watchdog can end this review.
|
|
1016
|
+
const review=JSON.parse(preview.stdout);assert.equal(review.timeoutMs,900000);
|
|
1017
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
1018
|
+
f.args.push('--review-config',config,'--allow-review-attempt','1');
|
|
1019
|
+
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
1020
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
1021
|
+
setMode('timeout');
|
|
1022
|
+
const hung=path.join(f.root,'review-mode.json.hung');
|
|
1023
|
+
// Fire as soon as the reviewer hangs, but never later than the usual
|
|
1024
|
+
// fixture deadline: a host stalled before review is a bounded failure.
|
|
1025
|
+
f.watchdog=expire=>{
|
|
1026
|
+
const poll=setInterval(()=>{if(fs.existsSync(hung)&&fs.readFileSync(hung,'utf8')){clearInterval(poll);expire();}},25);
|
|
1027
|
+
const limit=setTimeout(expire,Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
1028
|
+
return ()=>{clearInterval(poll);clearTimeout(limit);};
|
|
1029
|
+
};
|
|
1030
|
+
await assert.rejects(runCli(f,'normal'),/host fixture timed out/);
|
|
1031
|
+
assert(fs.existsSync(hung),'the host was stopped by the outer deadline before its reviewer hung');
|
|
1032
|
+
const reviewer=Number(fs.readFileSync(hung,'utf8'));assert(Number.isSafeInteger(reviewer)&&reviewer>1);
|
|
1033
|
+
const gone=()=>{try{process.kill(reviewer,0);return false;}catch(error){return error.code==='ESRCH';}};
|
|
1034
|
+
for(const deadline=Date.now()+3000;!gone()&&Date.now()<deadline;)await new Promise(resolve=>setTimeout(resolve,25));
|
|
1035
|
+
assert(gone(),`hung fake reviewer ${reviewer} survived the watchdog`);
|
|
1036
|
+
assert.deepEqual(fixtureProcesses(f.root),[]);
|
|
1037
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1038
|
+
});
|
|
837
1039
|
|
|
838
1040
|
test('new host refuses unapproved manifest bytes before any developer call',async()=>{
|
|
839
1041
|
const f=fixture();
|
|
@@ -988,3 +1190,63 @@ test('F7 CLI explicitly revises missing QA commands after N5 and resumes the sam
|
|
|
988
1190
|
assert.deepEqual(JSON.parse(fs.readFileSync(stateFile)),after);
|
|
989
1191
|
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
990
1192
|
});
|
|
1193
|
+
|
|
1194
|
+
// Protected current-session driver answers (#10, #11, #31). These reach the real
|
|
1195
|
+
// Codex sandbox that applies protected edits, so they live in this excluded file.
|
|
1196
|
+
const protectedDriver=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
1197
|
+
function protectedDriveFixture({scope,files={},checkCommands=[{id:'noop',command:['/usr/bin/true']}]}){
|
|
1198
|
+
const f=fixture(),definition=JSON.parse(fs.readFileSync(f.config,'utf8'));
|
|
1199
|
+
definition.scope=scope;fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
1200
|
+
for(const [file,content] of Object.entries(files)){
|
|
1201
|
+
fs.mkdirSync(path.dirname(path.join(f.codeProject,file)),{recursive:true});
|
|
1202
|
+
fs.writeFileSync(path.join(f.codeProject,file),content);fs.chmodSync(path.join(f.codeProject,file),0o644);
|
|
1203
|
+
}
|
|
1204
|
+
const answers=path.join(f.root,'answers');fs.mkdirSync(answers);
|
|
1205
|
+
fs.writeFileSync(path.join(f.root,'protection.json'),JSON.stringify({checkCommands,timeoutMs:120000}));
|
|
1206
|
+
f.content=(name,bytes)=>fs.writeFileSync(path.join(answers,name),bytes);
|
|
1207
|
+
f.developAnswer=edits=>fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',
|
|
1208
|
+
value:implementedValue(),edits}));
|
|
1209
|
+
f.drive=(permissions=[],umask='022')=>{
|
|
1210
|
+
const plan=path.join(f.root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
1211
|
+
fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'create',hostContext:'native-host-fixture',
|
|
1212
|
+
permissions:['--protected-conversation-config','protection.json','--review-config',f.reviewFile,...permissions],answers:'answers'}));
|
|
1213
|
+
return spawnSync('/bin/sh',['-c',`umask ${umask}; exec "$0" "$@"`,process.execPath,protectedDriver,'--plan',plan,'advance'],
|
|
1214
|
+
{encoding:'utf8',timeout:120000,
|
|
1215
|
+
env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')}});
|
|
1216
|
+
};
|
|
1217
|
+
return f;
|
|
1218
|
+
}
|
|
1219
|
+
const lastPackageChanges=f=>new Map(lastCheckpoint(f).reviewPackage.changes.map(change=>[change.path,change]));
|
|
1220
|
+
test('#10 the driver carries a protected develop reply above 64 KiB once --input-limit is raised',()=>{
|
|
1221
|
+
const f=protectedDriveFixture({scope:['App.xcodeproj/project.pbxproj']});
|
|
1222
|
+
try{
|
|
1223
|
+
const content='// !$*UTF8*$!\n'+'\t\tA1D0000000000000000001 /* x */ = {isa = PBXBuildFile; };\n'.repeat(1500);
|
|
1224
|
+
f.content('pbxproj.txt',content);f.developAnswer({'App.xcodeproj/project.pbxproj':'pbxproj.txt'});
|
|
1225
|
+
const run=f.drive(['--input-limit','1048576']);
|
|
1226
|
+
assert.equal(run.signal,null,'driver waited on a rejected reply');assert.equal(run.status,0,run.stderr);
|
|
1227
|
+
assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review',run.stdout);
|
|
1228
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'App.xcodeproj','project.pbxproj'),'utf8'),content);
|
|
1229
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1230
|
+
});
|
|
1231
|
+
test('#11 #31 protected driver deletes, sets the executable bit, creates new files 0644 and keeps BOM/CRLF text exact',()=>{
|
|
1232
|
+
const f=protectedDriveFixture({scope:['scripts/test.sh','old/Legacy.swift','new/Legacy.swift','App/Home.swift'],
|
|
1233
|
+
files:{'scripts/test.sh':'#!/bin/sh\necho TEST SUCCEEDED\n','old/Legacy.swift':'// legacy\n'},
|
|
1234
|
+
checkCommands:[{id:'test',command:['./scripts/test.sh']}]});
|
|
1235
|
+
try{
|
|
1236
|
+
const home=Buffer.from('import SwiftUI\r\nstruct Home {}\r\n','utf8');
|
|
1237
|
+
f.content('legacy.swift','// legacy\n');f.content('home.swift',home);
|
|
1238
|
+
f.developAnswer({'scripts/test.sh':{mode:'0755'},'old/Legacy.swift':{delete:true},
|
|
1239
|
+
'new/Legacy.swift':'legacy.swift','App/Home.swift':'home.swift'});
|
|
1240
|
+
const run=f.drive([],'077');
|
|
1241
|
+
assert.equal(run.status,0,run.stderr);assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review',run.stdout);
|
|
1242
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'scripts/test.sh')).mode&0o777,0o755);
|
|
1243
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'old/Legacy.swift')),false);
|
|
1244
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'new/Legacy.swift')).mode&0o777,0o644);
|
|
1245
|
+
assert.equal(fs.statSync(path.join(f.codeProject,'App/Home.swift')).mode&0o777,0o644);
|
|
1246
|
+
assert.deepEqual(fs.readFileSync(path.join(f.codeProject,'App/Home.swift')),home);
|
|
1247
|
+
const changes=lastPackageChanges(f);
|
|
1248
|
+
assert.equal(changes.get('scripts/test.sh').before.mode,0o644);assert.equal(changes.get('scripts/test.sh').after.mode,0o755);
|
|
1249
|
+
assert.equal(changes.get('old/Legacy.swift').after,null);
|
|
1250
|
+
assert.equal(changes.get('new/Legacy.swift').after.mode,0o644);
|
|
1251
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
1252
|
+
});
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// #25 launch-input mistakes name the input instead of a bare code.
|
|
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 {buildManifest} from './cm-spec-manifest.mjs';
|
|
10
|
+
import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
|
|
11
|
+
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
12
|
+
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
13
|
+
|
|
14
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-launch-diagnostics-home-'));
|
|
15
|
+
process.env.CM_WORKFLOW_HOME=path.join(home,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(home,'logs');
|
|
16
|
+
after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
17
|
+
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
18
|
+
const driver=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
19
|
+
const identity={repositoryId:'launch-fixture',runId:'launch-fixture-run',taskId:'T-001',attempt:1};
|
|
20
|
+
|
|
21
|
+
function fixture(t){
|
|
22
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-launch-diagnostics-')));
|
|
23
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
24
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work';
|
|
25
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
26
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
27
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
28
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
29
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
30
|
+
const config=path.join(root,'run.json'),review=path.join(root,'review.json'),workflow=path.join(root,'workflow.json');
|
|
31
|
+
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope:['target.mjs'],requirements:['requirements.md']}));
|
|
32
|
+
fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{}}));
|
|
33
|
+
fs.writeFileSync(workflow,JSON.stringify({documentationPaths:[],applicableAgentFiles:[],qa:null}));
|
|
34
|
+
const env={...process.env,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs'),NODE_NO_WARNINGS:'1'};
|
|
35
|
+
const host=(mode,{hostContext='session-a',extra=[]}={})=>{
|
|
36
|
+
const result=spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context',hostContext,
|
|
37
|
+
'--allow-development',...extra],{encoding:'utf8',env,timeout:20000,
|
|
38
|
+
input:JSON.stringify({version:1,operation:'status',requestId:'status',identity})+'\n'});
|
|
39
|
+
const line=result.stderr.split('\n').find(item=>item.startsWith('{"error"'));
|
|
40
|
+
return {...result,error:line?JSON.parse(line).error:null};
|
|
41
|
+
};
|
|
42
|
+
return {root,specsDir,codeProject,config,review,workflow,env,host};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
test('create without --review-config is refused with the reason and leaves no run',t=>{
|
|
46
|
+
const f=fixture(t);
|
|
47
|
+
const refused=f.host('create');
|
|
48
|
+
assert.equal(refused.status,1);assert.equal(refused.error.code,'review_configuration_required');
|
|
49
|
+
assert.match(refused.error.reason,/--review-config/);assert.match(refused.error.reason,/preflight/);
|
|
50
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);
|
|
51
|
+
const created=f.host('create',{extra:['--review-config',f.review]});
|
|
52
|
+
assert.equal(created.status,0,created.stderr);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('fingerprint_mismatch names the launch input that differs',t=>{
|
|
56
|
+
const f=fixture(t);
|
|
57
|
+
assert.equal(f.host('create',{extra:['--runtime','claude','--review-config',f.review]}).status,0);
|
|
58
|
+
const same=f.host('resume',{extra:['--runtime','claude','--review-config',f.review]});
|
|
59
|
+
assert.equal(same.status,0,same.stderr);
|
|
60
|
+
for(const [label,options,pattern] of [
|
|
61
|
+
['runtime omitted',{extra:['--review-config',f.review]},/--runtime:创建时为 claude,本次为 codex/],
|
|
62
|
+
['review config omitted',{extra:['--runtime','claude']},/--review-config:创建时用了审查模型 fixture,本次没有提供/],
|
|
63
|
+
['other session without --original-host-context',{hostContext:'session-b',extra:['--runtime','claude','--review-config',f.review]},
|
|
64
|
+
/--host-context:创建会话为 session-a.*--original-host-context session-a/],
|
|
65
|
+
['workflow config added',{extra:['--runtime','claude','--review-config',f.review,'--workflow-config',f.workflow]},
|
|
66
|
+
/--workflow-config/],
|
|
67
|
+
]){
|
|
68
|
+
const result=f.host('resume',options);
|
|
69
|
+
assert.equal(result.status,1,label);assert.equal(result.error.code,'fingerprint_mismatch',label);
|
|
70
|
+
assert.match(result.error.reason,pattern,label);
|
|
71
|
+
}
|
|
72
|
+
// The explicit cross-session form still reopens: the diagnosis never widens the check.
|
|
73
|
+
assert.equal(f.host('resume',{hostContext:'session-b',extra:['--original-host-context','session-a',
|
|
74
|
+
'--runtime','claude','--review-config',f.review]}).status,0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('a legacy run created without review config explains why the config cannot be added on resume',async t=>{
|
|
78
|
+
const f=fixture(t),bridge=createHostToolBridge();
|
|
79
|
+
try{
|
|
80
|
+
// Shape written by earlier versions: no review binding at create.
|
|
81
|
+
const definition=readRunDefinition(f.config);
|
|
82
|
+
const created=await openControlRun(definition,'create',createConversationExecution(definition,'session-a',bridge,null,null,null,false,'claude'));
|
|
83
|
+
created.close();
|
|
84
|
+
}finally{bridge.close();}
|
|
85
|
+
const result=f.host('resume',{extra:['--runtime','claude','--review-config',f.review]});
|
|
86
|
+
assert.equal(result.status,1);assert.equal(result.error.code,'fingerprint_mismatch');
|
|
87
|
+
assert.match(result.error.reason,/创建时没有审查配置.*不能补加.*cancel/);
|
|
88
|
+
assert.equal(f.host('resume',{extra:['--runtime','claude']}).status,0,'the original launch still reopens it');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('driver PLAN without runtime reaches the host diagnosis for a Claude run',t=>{
|
|
92
|
+
const f=fixture(t);
|
|
93
|
+
assert.equal(f.host('create',{extra:['--runtime','claude','--review-config',f.review]}).status,0);
|
|
94
|
+
const plan=path.join(f.root,'plan.json');
|
|
95
|
+
fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'resume',hostContext:'session-a',
|
|
96
|
+
permissions:['--review-config','review.json']}));
|
|
97
|
+
const result=spawnSync(process.execPath,[driver,'--plan',plan,'status'],{encoding:'utf8',env:f.env,timeout:30000});
|
|
98
|
+
assert.notEqual(result.status,0);
|
|
99
|
+
assert.match(result.stderr,/fingerprint_mismatch/);assert.match(result.stderr,/--runtime:创建时为 claude/);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('invalid_arguments names the argument',t=>{
|
|
103
|
+
const f=fixture(t);
|
|
104
|
+
for(const [extra,pattern] of [
|
|
105
|
+
[['--allow-qa','--review-config',f.review],/--allow-qa 需要同时提供 --workflow-config/],
|
|
106
|
+
[['--workflow-config',f.workflow,'--allow-qa','--review-config',f.review],/qa 不为 null/],
|
|
107
|
+
[['--browser-qa','available','--review-config',f.review],/没有适用的交互式 QA/],
|
|
108
|
+
[['--no-such-flag'],/未知参数:--no-such-flag/],
|
|
109
|
+
[['--review-config',f.review,'--review-config',f.review],/参数重复:--review-config/],
|
|
110
|
+
[['--allow-review-attempt','3','--review-config',f.review],/只接受 1 或 2/],
|
|
111
|
+
[['--input-limit','12'],/--input-limit/],
|
|
112
|
+
]){
|
|
113
|
+
const result=f.host('create',{extra});
|
|
114
|
+
assert.equal(result.status,1,extra.join(' '));assert.equal(result.error.code,'invalid_arguments',extra.join(' '));
|
|
115
|
+
assert.match(result.error.reason,pattern,extra.join(' '));
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
test('usage marks --review-config as required at create',()=>{
|
|
120
|
+
const help=spawnSync(process.execPath,[cli,'--help'],{encoding:'utf8'});
|
|
121
|
+
assert.equal(help.status,0);assert.match(help.stdout,/--allow-development --review-config PATH \(required at create/);
|
|
122
|
+
assert.doesNotMatch(help.stdout,/\[--review-config PATH\]/);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('a new batch requires --review-config like single-task create; a started batch keeps its launch',async t=>{
|
|
126
|
+
const f=fixture(t),batchCli=fileURLToPath(new URL('./cm-ai-batch-host.mjs',import.meta.url));
|
|
127
|
+
const {batchTaskRunId}=await import('./cm-ai-batch-run.mjs');
|
|
128
|
+
const batch={version:1,repositoryId:'launch-fixture',batchId:'launch-batch-1',specsDir:f.specsDir,codeProject:f.codeProject,
|
|
129
|
+
tasks:[{feature:'1.work',taskId:'T-001',scope:['target.mjs'],requirements:['requirements.md']}]};
|
|
130
|
+
const config=path.join(f.root,'batch.json');fs.writeFileSync(config,JSON.stringify({batch,workflows:{'1.work/T-001':null}}));
|
|
131
|
+
const launch=extra=>{const result=spawnSync(process.execPath,[batchCli,'serve','--config',config,'--host-context','batch-host',
|
|
132
|
+
'--allow-development',...extra],{encoding:'utf8',env:f.env,timeout:20000,input:''});
|
|
133
|
+
const line=result.stderr.split('\n').find(item=>item.startsWith('{"error"'));return {...result,error:line?JSON.parse(line).error:null};};
|
|
134
|
+
const refused=launch([]);
|
|
135
|
+
assert.equal(refused.status,1);assert.equal(refused.error.code,'review_configuration_required');
|
|
136
|
+
assert.match(refused.error.reason,/新批次必须带 --review-config/);
|
|
137
|
+
assert.equal(launch(['--review-config',f.review]).status,0);
|
|
138
|
+
// A batch whose member run already exists resumes with its original launch.
|
|
139
|
+
const store=path.join(f.specsDir,'.reviews','.execution',batchTaskRunId(batch.batchId,'1.work/T-001'));
|
|
140
|
+
fs.mkdirSync(store,{recursive:true});fs.writeFileSync(path.join(store,'state.json'),'{}');
|
|
141
|
+
assert.equal(launch([]).status,0,'no review_configuration_required for a started batch');
|
|
142
|
+
});
|
|
@@ -148,14 +148,20 @@ test('a selected root may contain protected specs but specs cannot be a selected
|
|
|
148
148
|
assert.throws(()=>captureReviewBaseline({...options,specsRoot,codeProjectPaths:['apps/api/specs']}),{code:'protected_specs'});
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
test('single-root baseline
|
|
151
|
+
test('single-root baseline and package bind ignore policy with an empty unchanged scope',t=>{
|
|
152
152
|
const {root}=fixture(t),single=path.join(root,'apps/api');
|
|
153
153
|
const baseline=captureReviewBaseline({root:single,identity,scope:['source.mjs'],requirements:['requirement.md']});
|
|
154
|
-
assert.deepEqual(Object.keys(baseline).sort(),['version','kind','identity','rootDigest','scope','requirements','files','baselineDigest'].sort());
|
|
154
|
+
assert.deepEqual(Object.keys(baseline).sort(),['version','kind','identity','rootDigest','scope','requirements','files','ignorePolicy','baselineDigest'].sort());
|
|
155
|
+
assert.deepEqual(Object.keys(baseline.ignorePolicy).sort(),
|
|
156
|
+
['version','builtinDigest','mode','ignoredPaths','ignoredDirectories','coreExcludesFile'].sort());
|
|
157
|
+
assert.equal(baseline.ignorePolicy.version,2);
|
|
158
|
+
assert.deepEqual(readReviewBaseline(baseline),baseline);
|
|
155
159
|
assert.deepEqual(baseline,resign(baseline,'baselineDigest'));
|
|
156
160
|
write(single,'source.mjs','changed\n');const pkg=createReviewPackage({root:single,baseline,checks});
|
|
157
161
|
assert.deepEqual(Object.keys(pkg).sort(),['version','kind','identity','rootDigest','baseIdentity','scope','changes','unchangedScope','requirements','checks',
|
|
158
|
-
'artifactDigest','requirementsDigest','checksDigest','packageDigest'].sort());
|
|
162
|
+
'ignorePolicy','artifactDigest','requirementsDigest','checksDigest','packageDigest'].sort());
|
|
163
|
+
assert.deepEqual(pkg.ignorePolicy,baseline.ignorePolicy);
|
|
164
|
+
assert.deepEqual(readReviewPackage(pkg),pkg);
|
|
159
165
|
assert.deepEqual(pkg.unchangedScope,[]);
|
|
160
166
|
assert.equal(verifyReviewPackage({root:single,baseline,checks,reviewPackage:pkg,expectedDigest:pkg.packageDigest}).outcome,'matched');
|
|
161
167
|
});
|