@aibyzero/cm-workflow 0.16.8 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +54 -0
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +30 -5
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +95 -13
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +489 -51
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {spawnSync} from 'node:child_process';
|
|
6
|
+
import {fileURLToPath} from 'node:url';
|
|
7
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
8
|
+
import {cli,identity,request,fixture,runCli} from './cm-ai-host-fixture.mjs';
|
|
9
|
+
|
|
10
|
+
for(const variant of ['codex','claude','protected'])test(`automatic fix ${variant} CLI starts before QA and finishes through original transport`,async()=>{
|
|
11
|
+
const runtime=variant==='protected'?'codex':variant;
|
|
12
|
+
const f=fixture();f.workflow=true;f.fix=true;f.runtime=runtime;
|
|
13
|
+
try{
|
|
14
|
+
f.protected=variant==='protected';
|
|
15
|
+
const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));definition.scope.push('README.md');
|
|
16
|
+
if(f.protected){const nested=path.join(f.codeProject,'specs');fs.renameSync(f.specsDir,nested);f.specsDir=nested;definition.specsDir=nested;}
|
|
17
|
+
fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
18
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.json'),JSON.stringify({version:1,...(f.protected?{runtimes:{available:'codex'}}:{}),policies:{auto_fix:'auto',delivery:'diff'}}));
|
|
19
|
+
fs.writeFileSync(path.join(f.codeProject,'red.mjs'),"import {value} from './target.mjs';if(value!==43){console.error('BUG');process.exit(1)}");
|
|
20
|
+
fs.writeFileSync(path.join(f.codeProject,'baseline.mjs'),"import {value} from './target.mjs';if(typeof value!=='number')process.exit(1)");
|
|
21
|
+
const bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
22
|
+
const fake=path.join(bin,runtime);fs.copyFileSync(fileURLToPath(new URL(`./fixtures/${runtime}-review-process.mjs`,import.meta.url)),fake);fs.chmodSync(fake,0o700);
|
|
23
|
+
if(f.protected){
|
|
24
|
+
const located=spawnSync('/usr/bin/which',['codex'],{encoding:'utf8'});assert.equal(located.status,0);
|
|
25
|
+
const real=located.stdout.trim(),reviewFixture=fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url));
|
|
26
|
+
fs.writeFileSync(fake,String.raw`#!${process.execPath}
|
|
27
|
+
const fs=require('node:fs'),cp=require('node:child_process'),a=require('node:assert/strict');
|
|
28
|
+
const args=process.argv.slice(2),real=${JSON.stringify(real)};
|
|
29
|
+
if(args[0]==='sandbox'){const r=cp.spawnSync(real,args,{stdio:'inherit'});process.exit(r.status??1);}
|
|
30
|
+
let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',()=>{
|
|
31
|
+
if(!input.includes('<cm-developer-data-json>')){
|
|
32
|
+
const r=cp.spawnSync(process.execPath,[${JSON.stringify(reviewFixture)},...args],{input,encoding:'utf8'});
|
|
33
|
+
process.stdout.write(r.stdout??'');process.stderr.write(r.stderr??'');process.exit(r.status??1);
|
|
34
|
+
}
|
|
35
|
+
const profile=[];for(let i=0;i<args.length;i++)if(args[i]==='-c'&&/^(default_permissions=|permissions.cm-specs=)/.test(args[i+1]))profile.push(args[i],args[i+1]);
|
|
36
|
+
a.equal(profile.length,4);
|
|
37
|
+
const code="const fs=require('node:fs');fs.writeFileSync('target.mjs','export const value = 42;\\n');fs.writeFileSync('README.md','# Before fix\\n');";
|
|
38
|
+
const r=cp.spawnSync(real,['sandbox','-P','cm-specs','--include-managed-config','-C',process.cwd(),...profile,'--',process.execPath,'-e',code],{encoding:'utf8'});
|
|
39
|
+
if(r.status!==0){process.stderr.write(r.stderr??'');process.exit(1);}
|
|
40
|
+
for(const row of [{type:'thread.started',thread_id:'synthetic-protected-developer'},{type:'turn.started'},
|
|
41
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify({outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}})}},{type:'turn.completed'}])process.stdout.write(JSON.stringify(row)+'\n');
|
|
42
|
+
});
|
|
43
|
+
`,{mode:0o700});
|
|
44
|
+
// Every original fix command also asserts actual native specs/instruction protection.
|
|
45
|
+
const assertion="import fs from 'node:fs';import a from 'node:assert/strict';"
|
|
46
|
+
+"for(const file of ['specs/1.work/tasks.md','AGENTS.md'])a.throws(()=>fs.writeFileSync(file,'forged'),e=>['EPERM','EACCES'].includes(e.code));\n";
|
|
47
|
+
for(const name of ['red.mjs','baseline.mjs'])fs.writeFileSync(path.join(f.codeProject,name),assertion+fs.readFileSync(path.join(f.codeProject,name),'utf8'));
|
|
48
|
+
}
|
|
49
|
+
f.env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(f.root,'private-logs')};
|
|
50
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime',runtime],
|
|
51
|
+
{encoding:'utf8',env:f.env,timeout:5000});
|
|
52
|
+
assert.equal(preview.status,0,preview.stderr);
|
|
53
|
+
const review=JSON.parse(preview.stdout),reviewFile=path.join(f.root,'review.json');
|
|
54
|
+
fs.writeFileSync(reviewFile,JSON.stringify(review));
|
|
55
|
+
const command=[process.execPath,'red.mjs'];
|
|
56
|
+
const workflowFile=path.join(f.root,'workflow.json');
|
|
57
|
+
fs.writeFileSync(workflowFile,JSON.stringify({documentationPaths:['README.md'],applicableAgentFiles:[],
|
|
58
|
+
qa:{commands:[{id:'value-check',command,caseIds:[]}],environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1',scope:'local'}}}));
|
|
59
|
+
const permissions=['red-test','baseline','repair','regression','final-review','walkthrough','finish'];
|
|
60
|
+
const reviewHost=createFixReviewHost({codeProject:f.codeProject,hostContextId:'native-host-fixture',runtime,review,
|
|
61
|
+
permissions:permissions.map(name=>`--allow-${name}`)});
|
|
62
|
+
const configuration={hostContextId:'native-host-fixture',...(runtime==='claude'?{runtime}:{}),defect:'Exported value must be 43',
|
|
63
|
+
...(f.protected?{protectSpecs:true}:{}),
|
|
64
|
+
causeReview:reviewHost.reviewer,reproduction:{cwd:f.codeProject,command,expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
65
|
+
redTest:{cwd:f.codeProject,testFiles:['red.mjs'],command,expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
66
|
+
baseline:{cwd:f.codeProject,testFiles:['baseline.mjs'],commands:[{id:'baseline',command:[process.execPath,'baseline.mjs']}],timeoutMs:2000},
|
|
67
|
+
repair:{scope:['target.mjs','README.md'],requirements:['requirements.md']},
|
|
68
|
+
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read exported value'],expected:['43'],kind:'commands',command}]}};
|
|
69
|
+
const template=path.join(f.root,'template.json');fs.writeFileSync(template,JSON.stringify({specsRoot:f.specsDir,feature:'1.work',identity,configuration}));
|
|
70
|
+
f.args.push('--runtime',runtime,'--review-config',reviewFile,'--workflow-config',workflowFile,'--allow-qa',
|
|
71
|
+
'--qa-fix-template-config',template,'--qa-fix-review-config',reviewFile,'--allow-qa-fix-start','--auto-qa-fix',
|
|
72
|
+
...permissions.map(name=>`--allow-qa-fix-${name}`));
|
|
73
|
+
if(f.protected){
|
|
74
|
+
const protectedFile=path.join(f.root,'protected.json');
|
|
75
|
+
fs.writeFileSync(protectedFile,JSON.stringify({model:'fixture',timeoutMs:5000,checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
|
|
76
|
+
f.args.push('--protected-config',protectedFile,'--allow-provider-development-attempt','1');
|
|
77
|
+
fs.writeFileSync(template,JSON.stringify({specsRoot:f.specsDir,feature:'1.work',identity,configuration:{...configuration,protectSpecs:false}}));
|
|
78
|
+
const denied=await runCli(f,'normal');assert.equal(denied.code,1);assert(denied.stderr.includes('protected_fix_required'));
|
|
79
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));fs.writeFileSync(template,JSON.stringify({specsRoot:f.specsDir,feature:'1.work',identity,configuration}));
|
|
80
|
+
}
|
|
81
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'运行日志.jsonl')),false);
|
|
82
|
+
const first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
83
|
+
assert.equal(first.rows.find(row=>row.requestId==='advance').result.code,'run_done',JSON.stringify(first.rows.at(-1)));
|
|
84
|
+
for(const kind of [...(f.protected?[]:['develop']),'fix_diagnose','fix_repair','fix_retrospective'])assert.equal(first.calls.filter(item=>item===kind).length,1,kind);
|
|
85
|
+
if(f.protected)assert(!first.calls.some(kind=>['develop','check','documentation_sync'].includes(kind)));
|
|
86
|
+
assert(first.calls.includes('fix_learning')); // Original owner refreshes Learning before multiple stages.
|
|
87
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
88
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='advance').result.code,'run_done');
|
|
89
|
+
assert.deepEqual(resumed.calls,['documentation_inspect']);
|
|
90
|
+
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
91
|
+
assert.equal(rows.filter(row=>row.workflow==='cm-ai'&&row.event==='test_run'&&row.phase==='start').length,2);
|
|
92
|
+
assert.equal(rows.filter(row=>row.workflow==='cm-ai'&&row.event==='run_done').length,1);
|
|
93
|
+
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[x] T-001'));
|
|
94
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
for(const runtime of ['codex','claude'])for(const initialWorkflow of ['absent','qa-null','qa'])test(`configured ${runtime} CLI starts development and resumes through direct review and resumes via the original review worker/gate workflow=${initialWorkflow}`,async()=>{
|
|
98
|
+
const workflow=initialWorkflow==='qa';
|
|
99
|
+
const f=fixture();
|
|
100
|
+
try{
|
|
101
|
+
f.workflow=workflow;
|
|
102
|
+
if(runtime==='claude'){f.runtime=runtime;f.args.push('--runtime',runtime);}
|
|
103
|
+
if(workflow){
|
|
104
|
+
const definition=JSON.parse(fs.readFileSync(f.config,'utf8'));definition.scope.push('README.md');
|
|
105
|
+
fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
106
|
+
}
|
|
107
|
+
const bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
108
|
+
const fake=path.join(bin,runtime);fs.copyFileSync(fileURLToPath(new URL(`./fixtures/${runtime}-review-process.mjs`,import.meta.url)),fake);
|
|
109
|
+
fs.chmodSync(fake,0o700);f.env={...process.env,PATH:bin+path.delimiter+process.env.PATH};
|
|
110
|
+
// Actual separate CLI and loopback diagnostic process; the executable is synthetic.
|
|
111
|
+
let review;
|
|
112
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture',
|
|
113
|
+
...(runtime==='claude'?['--runtime','claude']:[])],
|
|
114
|
+
{encoding:'utf8',env:f.env,timeout:5000});
|
|
115
|
+
assert.equal(preview.status,0,preview.stderr);
|
|
116
|
+
review=JSON.parse(preview.stdout);assert.equal(review.preflight.passed,true);
|
|
117
|
+
if(runtime==='codex')assert.equal(review.preflight.real_model_requests,0);
|
|
118
|
+
else assert.equal(review.preflight.isolation,'macos-loopback-sandbox');
|
|
119
|
+
assert.equal(review.preflight.listener_closed,true);
|
|
120
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
121
|
+
f.args.push('--review-config',config);
|
|
122
|
+
if(runtime==='claude'){
|
|
123
|
+
fs.writeFileSync(config,JSON.stringify({...review,preflight:{...review.preflight,provider:'codex'}}));
|
|
124
|
+
const denied=spawnSync(process.execPath,[cli,...f.args],{encoding:'utf8',env:f.env,timeout:3000});
|
|
125
|
+
assert.equal(denied.status,1);assert(denied.stderr.includes('tool_preflight_missing'));
|
|
126
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
127
|
+
fs.writeFileSync(config,JSON.stringify(review));
|
|
128
|
+
}
|
|
129
|
+
if(workflow){
|
|
130
|
+
const workflowFile=path.join(f.root,'workflow.json');
|
|
131
|
+
fs.writeFileSync(workflowFile,JSON.stringify({documentationPaths:['README.md'],applicableAgentFiles:[],
|
|
132
|
+
qa:{commands:[{id:'value-check',command:[process.execPath,'-e',"import('./target.mjs').then(m=>{if(m.value!==42)process.exit(1)})"],caseIds:[]}],
|
|
133
|
+
environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1',scope:'local'}}}));
|
|
134
|
+
f.args.push('--workflow-config',workflowFile);
|
|
135
|
+
const denied=spawnSync(process.execPath,[cli,...f.args],{encoding:'utf8',env:f.env,timeout:5000});
|
|
136
|
+
assert.equal(denied.status,1);assert(denied.stderr.includes('qa_authorization_required'));
|
|
137
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
138
|
+
f.args.push('--allow-qa');
|
|
139
|
+
}
|
|
140
|
+
if(!workflow)fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Fixture value 42\n');
|
|
141
|
+
const attachmentFile=path.join(f.root,'attachment.json');
|
|
142
|
+
const attachmentConfig={documentationPaths:[],applicableAgentFiles:[],
|
|
143
|
+
qa:{commands:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],caseIds:[]}],
|
|
144
|
+
environment:{kind:'web',carrier:'browser',target:'http://127.0.0.1',scope:'local'}}};
|
|
145
|
+
if(initialWorkflow==='qa-null'){
|
|
146
|
+
fs.writeFileSync(attachmentFile,JSON.stringify({...attachmentConfig,qa:null}));
|
|
147
|
+
f.args.push('--workflow-config',attachmentFile);
|
|
148
|
+
}
|
|
149
|
+
f.operation='start';const first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
150
|
+
assert.equal(first.rows.find(row=>row.requestId==='advance').result.code,null);
|
|
151
|
+
const initialArgs=[...f.args];
|
|
152
|
+
const attemptAttachment=()=>{
|
|
153
|
+
fs.writeFileSync(attachmentFile,JSON.stringify(attachmentConfig));
|
|
154
|
+
if(initialWorkflow==='absent')f.args.push('--workflow-config',attachmentFile);
|
|
155
|
+
f.args.push('--allow-qa');
|
|
156
|
+
};
|
|
157
|
+
if(!workflow){
|
|
158
|
+
attemptAttachment();
|
|
159
|
+
const early=await runCli(f,'normal','resume');
|
|
160
|
+
assert.equal(early.code,1);assert.match(early.stderr,/qa_attach_not_completed/);assert.deepEqual(early.calls,[]);
|
|
161
|
+
f.args=[...initialArgs];
|
|
162
|
+
if(initialWorkflow==='qa-null')fs.writeFileSync(attachmentFile,JSON.stringify({...attachmentConfig,qa:null}));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-001'));
|
|
166
|
+
f.operation='advance';
|
|
167
|
+
const completed=await runCli(f,'authorized-review','resume');assert.equal(completed.code,0,completed.stderr);
|
|
168
|
+
assert.deepEqual(completed.calls,workflow?['check','qa_assess','documentation_inspect']:['check']);
|
|
169
|
+
const result=completed.rows.find(row=>row.requestId==='advance').result;
|
|
170
|
+
assert.equal(result.state,workflow?'run_done':'fixture_completed');assert.equal(result.code,workflow?'run_done':'qa_decision_required');
|
|
171
|
+
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[x] T-001'));
|
|
172
|
+
const reopened=await runCli(f,'normal','resume');assert.equal(reopened.code,0,reopened.stderr);
|
|
173
|
+
assert.deepEqual(reopened.calls,workflow?['documentation_inspect']:[]);
|
|
174
|
+
assert.equal(reopened.rows.find(row=>row.requestId==='advance').result.code,workflow?'run_done':'qa_decision_required');
|
|
175
|
+
if(!workflow){
|
|
176
|
+
const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
177
|
+
const before=JSON.parse(fs.readFileSync(stateFile,'utf8'));
|
|
178
|
+
attemptAttachment();
|
|
179
|
+
// Explicit QA permission is still required, even though task work is done.
|
|
180
|
+
f.args.pop();
|
|
181
|
+
const denied=await runCli(f,'normal','resume');assert.equal(denied.code,1);
|
|
182
|
+
assert.match(denied.stderr,/qa_authorization_required/);assert.deepEqual(denied.calls,[]);
|
|
183
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(stateFile,'utf8')),before);
|
|
184
|
+
f.args.push('--allow-qa');
|
|
185
|
+
// No hidden host-context or definition changes can ride the attachment.
|
|
186
|
+
const originalHost=f.args[6];f.args[6]='different-host';
|
|
187
|
+
const changedHost=await runCli(f,'normal','resume');assert.equal(changedHost.code,1);
|
|
188
|
+
assert.match(changedHost.stderr,/fingerprint_mismatch/);f.args[6]=originalHost;
|
|
189
|
+
const originalDefinition=fs.readFileSync(f.config,'utf8');
|
|
190
|
+
for(const field of ['scope','requirements']){
|
|
191
|
+
const changed=JSON.parse(originalDefinition);changed[field].push('extra.md');
|
|
192
|
+
fs.writeFileSync(f.config,JSON.stringify(changed));
|
|
193
|
+
const rejected=await runCli(f,'normal','resume');assert.equal(rejected.code,1);
|
|
194
|
+
assert.match(rejected.stderr,/fingerprint_mismatch/);fs.writeFileSync(f.config,originalDefinition);
|
|
195
|
+
}
|
|
196
|
+
f.workflow=true;
|
|
197
|
+
const {readRunnerHistory}=await import('../runtime/js/cm-ai/durable-runner-state.mjs');
|
|
198
|
+
const {digest}=await import('../runtime/js/cm-ai/effect-contract.mjs');
|
|
199
|
+
const history=readRunnerHistory(before.records,before.records[0].payload.config,3);
|
|
200
|
+
f.request={...request('qa','advance'),packageDigest:history.state.reviewPackage.packageDigest};
|
|
201
|
+
const attached=await runCli(f,'authorized-review','resume');assert.equal(attached.code,0,attached.stderr);
|
|
202
|
+
assert.deepEqual(attached.calls,['qa_assess']);
|
|
203
|
+
assert.equal(attached.rows.find(row=>row.requestId==='advance').result.code,'qa_triggered');
|
|
204
|
+
delete f.request;
|
|
205
|
+
// A killed no-result N6 run needs a fresh, explicit resume permission.
|
|
206
|
+
// The option is transport authority, never part of the stored fingerprint.
|
|
207
|
+
const {recordCmAiQaRun}=await import('../runtime/js/cm-ai/cm-ai-qa-log.mjs');
|
|
208
|
+
recordCmAiQaRun({specsDir:f.specsDir,codeProject:f.codeProject,feature:'1.work',identity,
|
|
209
|
+
packageDigest:history.state.reviewPackage.packageDigest,testRunId:'interrupted-qa',mode:'commands',caseCount:1,
|
|
210
|
+
phase:'start',logHome:path.join(f.root,'logs')});
|
|
211
|
+
const unknown=await runCli(f,'normal','resume');assert.equal(unknown.code,0,unknown.stderr);
|
|
212
|
+
assert.equal(unknown.rows.find(row=>row.requestId==='advance').result.code,'qa_execution_unknown');
|
|
213
|
+
assert.deepEqual(unknown.calls,[]);
|
|
214
|
+
f.args.push('--rerun-unknown-qa');
|
|
215
|
+
const finished=await runCli(f,'normal','resume');assert.equal(finished.code,0,finished.stderr);
|
|
216
|
+
f.args.pop();
|
|
217
|
+
assert.deepEqual(finished.calls,['documentation_inspect']);
|
|
218
|
+
assert.equal(finished.rows.find(row=>row.requestId==='advance').result.state,'run_done');
|
|
219
|
+
const qaRows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
|
|
220
|
+
.filter(row=>row.event==='test_run');
|
|
221
|
+
assert.deepEqual(qaRows.filter(row=>row.phase==='start').map(row=>row.attempt),[1,1]);
|
|
222
|
+
assert.equal(qaRows.filter(row=>row.phase==='abandoned').length,1);
|
|
223
|
+
const after=JSON.parse(fs.readFileSync(stateFile,'utf8'));
|
|
224
|
+
assert.deepEqual(after.fingerprints,before.fingerprints);
|
|
225
|
+
assert.deepEqual(after.records.slice(0,before.records.length),before.records);
|
|
226
|
+
const records=after.records.filter(row=>row.payload.type==='qa-attached');assert.equal(records.length,1);
|
|
227
|
+
assert.deepEqual(Object.keys(records[0].payload.record).sort(),['attachedAt','hostContextId','qaFingerprint','version']);
|
|
228
|
+
assert.equal(records[0].payload.record.hostContextId,'native-host-fixture');
|
|
229
|
+
// Replay rejects a duplicate even with a correctly recalculated hash chain.
|
|
230
|
+
const last=records[0],body={...last,seq:after.records.length+1,
|
|
231
|
+
id:`runner.${String(after.records.length+1).padStart(6,'0')}`,previousDigest:after.records.at(-1).digest};
|
|
232
|
+
delete body.digest;
|
|
233
|
+
assert.throws(()=>readRunnerHistory([...after.records,{...body,digest:digest(body)}],
|
|
234
|
+
after.records[0].payload.config,3),{code:'qa_attachment_duplicate'});
|
|
235
|
+
assert.equal(readRunnerHistory(after.records,after.records[0].payload.config,3).state.state,'fixture_completed');
|
|
236
|
+
// Crash prefix: attachment durable, audit row absent. Resume repairs it.
|
|
237
|
+
const log=path.join(f.specsDir,'运行日志.jsonl');
|
|
238
|
+
fs.writeFileSync(log,fs.readFileSync(log,'utf8').trim().split('\n')
|
|
239
|
+
.filter(line=>JSON.parse(line).phase!=='qa_attach').join('\n')+'\n');
|
|
240
|
+
const again=await runCli(f,'normal','resume');assert.equal(again.code,0,again.stderr);
|
|
241
|
+
assert.deepEqual(again.calls,['documentation_inspect']);
|
|
242
|
+
assert.deepEqual(JSON.parse(fs.readFileSync(stateFile,'utf8')),after);
|
|
243
|
+
const logs=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
244
|
+
const attachLogs=logs.filter(row=>row.event==='decision'&&row.phase==='qa_attach');assert.equal(attachLogs.length,1);
|
|
245
|
+
assert.equal(attachLogs[0].qaFingerprint,records[0].payload.record.qaFingerprint);
|
|
246
|
+
assert.equal(logs.filter(row=>row.event==='test_run'&&row.phase==='start').length,2);
|
|
247
|
+
// Removing QA after it was bound cannot fall back to the original config.
|
|
248
|
+
const attachedArgs=[...f.args];f.args=[...initialArgs];
|
|
249
|
+
if(initialWorkflow==='qa-null')fs.writeFileSync(attachmentFile,JSON.stringify({...attachmentConfig,qa:null}));
|
|
250
|
+
const removed=await runCli(f,'normal','resume');assert.equal(removed.code,1);assert.match(removed.stderr,/fingerprint_mismatch/);
|
|
251
|
+
f.args=attachedArgs;
|
|
252
|
+
fs.writeFileSync(attachmentFile,JSON.stringify({...attachmentConfig,qa:{...attachmentConfig.qa,
|
|
253
|
+
commands:[{id:'different',command:[process.execPath,'--version'],caseIds:[]}]}}));
|
|
254
|
+
const changed=await runCli(f,'normal','resume');assert.equal(changed.code,1);assert.match(changed.stderr,/fingerprint_mismatch/);
|
|
255
|
+
assert.deepEqual(changed.calls,[]);assert.deepEqual(JSON.parse(fs.readFileSync(stateFile,'utf8')),after);
|
|
256
|
+
}
|
|
257
|
+
if(workflow){
|
|
258
|
+
const file=f.args[f.args.indexOf('--workflow-config')+1];
|
|
259
|
+
const config=JSON.parse(fs.readFileSync(file,'utf8'));config.qa.commands[0].id='different';
|
|
260
|
+
fs.writeFileSync(file,JSON.stringify(config));
|
|
261
|
+
const changed=await runCli(f,'normal','resume');assert.equal(changed.code,1);assert.match(changed.stderr,/fingerprint_mismatch/);
|
|
262
|
+
const rows=fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse);
|
|
263
|
+
assert.equal(rows.filter(row=>row.event==='run_done').length,1);
|
|
264
|
+
assert.equal(rows.filter(row=>row.event==='test_run'&&row.phase==='start').length,1);
|
|
265
|
+
}
|
|
266
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
267
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
// Shared real-host fixture for the cm-ai-host*.test.mjs files (the Codex-sandbox
|
|
2
|
+
// set that CI cannot host). Importing it isolates CM_WORKFLOW_HOME/LOG_HOME for the
|
|
3
|
+
// importing test file and sweeps every fixture root for leaked processes when that
|
|
4
|
+
// file finishes, exactly as the single file did before it was split.
|
|
5
|
+
// Not a test file itself; every fixture works in its own temporary root.
|
|
6
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
7
|
+
import {after} from 'node:test';
|
|
8
|
+
import assert from 'node:assert/strict';
|
|
9
|
+
import fs from 'node:fs';
|
|
10
|
+
import os from 'node:os';
|
|
11
|
+
import path from 'node:path';
|
|
12
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
13
|
+
import {fileURLToPath} from 'node:url';
|
|
14
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
15
|
+
import {claudeReviewFingerprint} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
16
|
+
import {guardFixtureSource,killFixtureProcesses} from './fixtures/process-cleanup.mjs';
|
|
17
|
+
|
|
18
|
+
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
19
|
+
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-host-home-'));
|
|
20
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
21
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
22
|
+
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
23
|
+
// Every fixture root is swept once the file finishes: a surviving fake CLI or
|
|
24
|
+
// host is a leak even if its test passed (2026-09-28: fake reviewers ran 17h).
|
|
25
|
+
const fixtureRoots=new Set();
|
|
26
|
+
after(()=>{
|
|
27
|
+
const leaked=[...fixtureRoots].flatMap(root=>killFixtureProcesses(root));
|
|
28
|
+
assert.deepEqual(leaked.map(row=>row.command.slice(0,160)),[],'fixture processes outlived their tests');
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
32
|
+
export const identity={repositoryId:'host-fixture',runId:'host-fixture-run',taskId:'T-001',attempt:1};
|
|
33
|
+
export const request=(operation,requestId=operation)=>({version:1,operation,requestId,identity});
|
|
34
|
+
|
|
35
|
+
export function fixture(){
|
|
36
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-native-host-')));fixtureRoots.add(root);
|
|
37
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.work',config=path.join(root,'run.json');
|
|
38
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
39
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
40
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
41
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
42
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
43
|
+
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope:['target.mjs'],requirements:['requirements.md']}));
|
|
44
|
+
const reviewFile=path.join(root,'synthetic-review.json');
|
|
45
|
+
const f={root,specsDir,codeProject,config,reviewFile,args:['serve','--config',config,'--mode','create','--host-context','native-host-fixture','--allow-development']};
|
|
46
|
+
installSyntheticReview(f);
|
|
47
|
+
return f;
|
|
48
|
+
}
|
|
49
|
+
export function syntheticReviewConfig(codeProject,runtime='codex',model='fixture'){
|
|
50
|
+
return {model,disabledSkills:[],preflight:{passed:true,provider:runtime,cli_model:model,prompt_transport:'stdin',
|
|
51
|
+
config_fingerprint:(runtime==='claude'?claudeReviewFingerprint:configFingerprint)({cwd:codeProject,model,disabledSkills:[]})}};
|
|
52
|
+
}
|
|
53
|
+
// Only review output is synthetic. Any sandbox request delegates to the actual
|
|
54
|
+
// installed Codex, preserving native write-protection and command checks.
|
|
55
|
+
export function installSyntheticReview(f){
|
|
56
|
+
const bin=path.join(f.root,'synthetic-review-bin');fs.mkdirSync(bin,{recursive:true});
|
|
57
|
+
const real=spawnSync('/usr/bin/which',['codex'],{encoding:'utf8'}).stdout.trim();
|
|
58
|
+
for(const runtime of ['codex','claude']){
|
|
59
|
+
const source=fileURLToPath(new URL(`./fixtures/${runtime}-review-process.mjs`,import.meta.url));
|
|
60
|
+
fs.writeFileSync(path.join(bin,runtime),`#!${process.execPath}\n`
|
|
61
|
+
+`const {spawnSync}=await import('node:child_process');\n`
|
|
62
|
+
+`if(process.argv[2]==='sandbox'){const r=spawnSync(${JSON.stringify(real)},process.argv.slice(2),{stdio:'inherit'});process.exitCode=r.status??1;}\n`
|
|
63
|
+
+`else await import(${JSON.stringify(new URL('file://'+source).href)});\n`,{mode:0o700});
|
|
64
|
+
}
|
|
65
|
+
f.env={...(f.env??process.env),PATH:bin+path.delimiter+(f.env?.PATH??process.env.PATH),
|
|
66
|
+
CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')};
|
|
67
|
+
if(f.reviewFile)fs.writeFileSync(f.reviewFile,JSON.stringify(syntheticReviewConfig(f.codeProject,f.runtime)));
|
|
68
|
+
return f;
|
|
69
|
+
}
|
|
70
|
+
// Explicit review configs retain the case's intended missing/stale preflight.
|
|
71
|
+
export const launchArgs=f=>{
|
|
72
|
+
if(f.args.includes('--review-config'))return f.args;
|
|
73
|
+
const index=f.args.indexOf('--review-runtime'),hostIndex=f.args.indexOf('--runtime');
|
|
74
|
+
const runtime=index>=0?f.args[index+1]:hostIndex>=0?f.args[hostIndex+1]:'codex';
|
|
75
|
+
fs.writeFileSync(f.reviewFile,JSON.stringify(syntheticReviewConfig(f.codeProject,runtime)));
|
|
76
|
+
return [...f.args,'--review-config',f.reviewFile];
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export function runCli(f,mode,action='create'){
|
|
80
|
+
return new Promise((resolve,reject)=>{
|
|
81
|
+
const args=[...launchArgs(f)];args[4]=action;
|
|
82
|
+
const child=spawn(process.execPath,[cli,...args],{stdio:['pipe','pipe','pipe'],env:f.env??process.env});
|
|
83
|
+
let buffer='',stderr='',closed=false,sessionId;const rows=[],calls=[];
|
|
84
|
+
// Provider children run in their own process groups: stopping only the host
|
|
85
|
+
// would orphan a hung fake reviewer, so failure and watchdog paths stop the
|
|
86
|
+
// whole fixture tree. f.watchdog(expire) may replace the timer; it returns a disarm function.
|
|
87
|
+
let disarm=()=>{};
|
|
88
|
+
const fail=error=>{
|
|
89
|
+
disarm();child.kill('SIGKILL');
|
|
90
|
+
try{killFixtureProcesses(f.root);}catch(cleanup){error=new AggregateError([error,cleanup],String(error?.message??error));}
|
|
91
|
+
reject(error);
|
|
92
|
+
};
|
|
93
|
+
disarm=(f.watchdog??(expire=>{const timer=setTimeout(expire,Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000));
|
|
94
|
+
return ()=>clearTimeout(timer);}))(()=>fail(new Error('host fixture timed out')));
|
|
95
|
+
child.stderr.on('data',chunk=>{stderr+=chunk;});
|
|
96
|
+
child.once('error',reject);
|
|
97
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
98
|
+
const response=(row,result)=>({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
|
|
99
|
+
child.stdout.on('data',chunk=>{
|
|
100
|
+
buffer+=chunk;
|
|
101
|
+
let newline;
|
|
102
|
+
while((newline=buffer.indexOf('\n'))!==-1){
|
|
103
|
+
const line=buffer.slice(0,newline);buffer=buffer.slice(newline+1);
|
|
104
|
+
if(!line)continue;
|
|
105
|
+
try{
|
|
106
|
+
const row=JSON.parse(line);rows.push(row);
|
|
107
|
+
if(row.type==='host_ready')sessionId=row.sessionId;
|
|
108
|
+
if(row.type==='host_request'){
|
|
109
|
+
calls.push(row.kind);
|
|
110
|
+
if(row.kind==='develop'){
|
|
111
|
+
const material=row.payload.request.payload.specification;
|
|
112
|
+
assert.equal(material.task.id,'T-001');assert.equal(material.task.description,'fixture');
|
|
113
|
+
assert.deepEqual(material.sources,buildManifest(f.specsDir));
|
|
114
|
+
assert.equal(material.designExcerpt,fs.readFileSync(path.join(f.specsDir,'1.work','design.md'),'utf8'));
|
|
115
|
+
assert.deepEqual(row.payload.request.payload.scope,JSON.parse(fs.readFileSync(f.config)).scope);
|
|
116
|
+
}
|
|
117
|
+
if(action!=='create')assert((f.develop&&row.kind==='develop')||(mode==='authorized-review'&&['check','qa_assess','documentation_inspect'].includes(row.kind))
|
|
118
|
+
||(f.workflow&&row.kind==='documentation_inspect')||(f.qaBrowser&&row.kind==='qa_browser'),'resume must not resend development');
|
|
119
|
+
if(mode==='disconnect'){child.stdin.end();continue;}
|
|
120
|
+
if(mode==='cancel'){send(request('status'));send(request('cancel'));continue;}
|
|
121
|
+
if(f.fix&&row.kind==='fix_learning'){
|
|
122
|
+
send(response(row,{contextDigest:row.payload.contextDigest,status:'no_relevant_lesson',summary:'Synthetic no project lessons'}));
|
|
123
|
+
}else if(f.fix&&row.kind==='fix_diagnose'){
|
|
124
|
+
send(response(row,{status:'diagnosed',rootCause:'Wrong exported constant',affectedPaths:['target.mjs','README.md'],
|
|
125
|
+
affectedModules:['value'],plan:'Set value and documentation to 43',crossLayer:false,
|
|
126
|
+
investigation:{discardedAlternatives:[],boundaryAnalysis:null}}));
|
|
127
|
+
}else if(f.fix&&row.kind==='fix_repair'){
|
|
128
|
+
if(f.protected){
|
|
129
|
+
assert.equal(row.payload.editMode,'protected-text-v1');
|
|
130
|
+
send(response(row,{outcome:'repaired',edits:[
|
|
131
|
+
{path:'target.mjs',beforeSha256:row.payload.expected['target.mjs'],content:'export const value = 43;\n'},
|
|
132
|
+
{path:'README.md',beforeSha256:row.payload.expected['README.md'],content:'# Fixture value\n\nExports value = 43.\n'}]}));
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
fs.writeFileSync(path.join(f.codeProject,'target.mjs'),'export const value = 43;\n');
|
|
136
|
+
fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Fixture value\n\nExports value = 43.\n');
|
|
137
|
+
send(response(row,{outcome:'repaired'}));
|
|
138
|
+
}else if(f.fix&&row.kind==='fix_retrospective'){
|
|
139
|
+
send(response(row,{status:'no_new_lesson',candidates:[],reason:null}));
|
|
140
|
+
}else if(row.kind==='develop'&&f.develop){
|
|
141
|
+
send(response(row,f.develop(row.payload)));
|
|
142
|
+
}else if(row.kind==='develop'){
|
|
143
|
+
assert.equal(row.payload.request.provider,f.runtime??'codex');
|
|
144
|
+
assert.equal(row.payload.route.runtime,f.runtime??'codex');
|
|
145
|
+
assert.equal(row.payload.route.role,'coder');
|
|
146
|
+
assert.equal(row.payload.route.route_state,'current-runtime');
|
|
147
|
+
assert.equal(row.payload.codeProject,f.codeProject);
|
|
148
|
+
assert.deepEqual(row.payload.request.payload.scope,f.workflow?['target.mjs','README.md']:['target.mjs']);
|
|
149
|
+
// Wrong-session self-reported results must not settle the live call.
|
|
150
|
+
send({...response(row,{status:'succeeded',value:{outcome:'implemented'}}),sessionId:'wrong-session'});
|
|
151
|
+
fs.writeFileSync(path.join(f.codeProject,'target.mjs'),'export const value = 42;\n');
|
|
152
|
+
send(response(row,{status:'succeeded',value:{outcome:'implemented',
|
|
153
|
+
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}}}));
|
|
154
|
+
}else if(row.kind==='documentation_sync'){
|
|
155
|
+
assert(f.workflow);assert.deepEqual(row.payload.paths,['README.md']);
|
|
156
|
+
fs.writeFileSync(path.join(f.codeProject,'README.md'),'# Verified fixture value\n\nExports value = 42.\n');
|
|
157
|
+
send(response(row,{status:'completed'}));
|
|
158
|
+
}else if(row.kind==='qa_assess'){
|
|
159
|
+
assert(f.workflow);assert.equal(row.payload.pending,0);
|
|
160
|
+
send(response(row,{confirmed:true}));
|
|
161
|
+
}else if(row.kind==='qa_browser'&&f.qaBrowser){
|
|
162
|
+
send(response(row,f.qaBrowser(row.payload)));
|
|
163
|
+
}else if(row.kind==='documentation_inspect'){
|
|
164
|
+
assert(f.workflow);assert(fs.readFileSync(path.join(f.codeProject,'README.md'),'utf8').includes(f.fix?'43':'42'));
|
|
165
|
+
const {syncId,identity,packageDigest,contextDigest}=row.payload;
|
|
166
|
+
send(response(row,{syncId,identity,packageDigest,contextDigest,status:'completed',reason:'Actual fixture README checked',
|
|
167
|
+
at:new Date().toISOString().replace(/\.\d{3}Z$/,'Z')}));
|
|
168
|
+
}else{
|
|
169
|
+
assert.equal(row.kind,'check');
|
|
170
|
+
assert.equal(row.payload.route.role,'tester');
|
|
171
|
+
assert.equal(row.payload.route.route_state,'local-tool');
|
|
172
|
+
const command=[process.execPath,'--check',path.join(f.codeProject,'target.mjs')];
|
|
173
|
+
const checked=spawnSync(command[0],command.slice(1),{timeout:3000});assert.equal(checked.status,0);
|
|
174
|
+
send(response(row,[{id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Actual isolated node --check exited 0'}]));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if(row.requestId==='advance'&&row.result&&!closed){
|
|
178
|
+
closed=true;
|
|
179
|
+
if(mode!=='disconnect'||action==='resume')send({type:'host_close',sessionId});
|
|
180
|
+
}
|
|
181
|
+
}catch(error){fail(error);return;}
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
child.once('close',code=>{disarm();resolve({code,stderr,rows,calls});});
|
|
185
|
+
send(f.request??{...request(f.operation??'advance'),requestId:'advance'});
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// Real local child processes with synthetic provider output. Only `codex sandbox`
|
|
191
|
+
// delegates to the installed CLI; no real model is ever requested.
|
|
192
|
+
export function installDispatchFakes(f){
|
|
193
|
+
const bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
194
|
+
const located=spawnSync('/usr/bin/which',['codex'],{encoding:'utf8'});assert.equal(located.status,0);
|
|
195
|
+
for(const provider of ['codex','claude']){
|
|
196
|
+
const reviewFixture=fileURLToPath(new URL(`./fixtures/${provider}-review-process.mjs`,import.meta.url));
|
|
197
|
+
fs.writeFileSync(path.join(bin,provider),String.raw`#!${process.execPath}
|
|
198
|
+
const fs=require('node:fs'),cp=require('node:child_process'),a=require('node:assert/strict');
|
|
199
|
+
const provider=${JSON.stringify(provider)},args=process.argv.slice(2),real=${JSON.stringify(located.stdout.trim())};
|
|
200
|
+
if(args[0]==='sandbox'){const r=cp.spawnSync(real,args,{stdio:'inherit'});process.exit(r.status??1);}
|
|
201
|
+
let prompt='';process.stdin.on('data',s=>prompt+=s);process.stdin.on('end',()=>{
|
|
202
|
+
if(!prompt.includes('<cm-developer-data-json>')){
|
|
203
|
+
if(prompt.includes('<cm-review-data-json>')){
|
|
204
|
+
const material=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]).reviewPackage.specification;
|
|
205
|
+
a.equal(material.feature,'1.work');a.equal(material.task.id,'T-001');a.equal(material.sources.length,3);
|
|
206
|
+
}
|
|
207
|
+
const r=cp.spawnSync(process.execPath,[${JSON.stringify(reviewFixture)},...args],{input:prompt,encoding:'utf8'});
|
|
208
|
+
process.stdout.write(r.stdout??'');process.stderr.write(r.stderr??'');process.exit(r.status??1);
|
|
209
|
+
}
|
|
210
|
+
const material=JSON.parse(prompt.split('<cm-developer-data-json>\n')[1].split('\n')[0]).specification;
|
|
211
|
+
a.equal(material.feature,'1.work');a.equal(material.task.description,'fixture');a.equal(material.sources.length,3);
|
|
212
|
+
const content='export const value = 42;\n';
|
|
213
|
+
const value={outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
214
|
+
let events;
|
|
215
|
+
if(provider==='codex'){
|
|
216
|
+
const profile=[];for(let i=0;i<args.length;i++)if(args[i]==='-c'&&/^(default_permissions=|permissions.cm-specs=)/.test(args[i+1]))profile.push(args[i],args[i+1]);
|
|
217
|
+
a.equal(profile.length,4);
|
|
218
|
+
const r=cp.spawnSync(real,['sandbox','-P','cm-specs','--include-managed-config','-C',process.cwd(),...profile,'--',process.execPath,'-e',"require('node:fs').writeFileSync('target.mjs',"+JSON.stringify(content)+")"],{encoding:'utf8'});
|
|
219
|
+
if(r.status!==0){process.stderr.write(r.stderr??'');process.exit(1);}
|
|
220
|
+
events=[{type:'thread.started',thread_id:'synthetic-coder-codex'},{type:'turn.started'},
|
|
221
|
+
{type:'item.completed',item:{type:'agent_message',text:JSON.stringify(value)}},{type:'turn.completed'}];
|
|
222
|
+
}else{
|
|
223
|
+
a.equal(args[args.indexOf('--tools')+1],'Read,Grep,Glob');a.equal(args[args.indexOf('--allowedTools')+1],'Read,Grep,Glob');
|
|
224
|
+
a.equal(args[args.indexOf('--permission-mode')+1],'dontAsk');a(args.includes('--no-session-persistence'));
|
|
225
|
+
a(args.includes('--json-schema'));const schema=JSON.parse(args[args.indexOf('--json-schema')+1]);
|
|
226
|
+
a.equal(Object.hasOwn(schema,'$schema'),false);a.equal(Object.hasOwn(schema,'$id'),false);
|
|
227
|
+
a.deepEqual(schema.properties.status.enum,['succeeded','failed']);
|
|
228
|
+
a(prompt.includes('Protected current-host mode: do not write files'));
|
|
229
|
+
a.equal(fs.existsSync('target.mjs'),false);
|
|
230
|
+
const expected=JSON.parse(prompt.trim().split('\n').at(-1)).expected;
|
|
231
|
+
const proposal={status:'succeeded',value,edits:[{path:'target.mjs',beforeSha256:expected['target.mjs'],content}]};
|
|
232
|
+
const session_id='synthetic-coder-claude';
|
|
233
|
+
events=[{type:'system',subtype:'init',session_id},{type:'assistant',session_id,parent_tool_use_id:null,message:{role:'assistant',content:[{type:'text',text:'proposal'}]}},
|
|
234
|
+
{type:'result',session_id,subtype:'success',is_error:false,num_turns:1,result:'',structured_output:proposal}];
|
|
235
|
+
}
|
|
236
|
+
for(const event of events)process.stdout.write(JSON.stringify(event)+'\n');
|
|
237
|
+
});
|
|
238
|
+
`,{mode:0o700});
|
|
239
|
+
}
|
|
240
|
+
f.env={...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export function protectedResultFixture(){
|
|
244
|
+
const f=fixture(),definition=JSON.parse(fs.readFileSync(f.config));
|
|
245
|
+
const nested=path.join(f.codeProject,'specs');fs.renameSync(f.specsDir,nested);
|
|
246
|
+
f.specsDir=nested;definition.specsDir=nested;fs.writeFileSync(f.config,JSON.stringify(definition));
|
|
247
|
+
const config=path.join(f.root,'conversation-protection.json');
|
|
248
|
+
fs.writeFileSync(config,JSON.stringify({timeoutMs:5000,
|
|
249
|
+
checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
|
|
250
|
+
f.args.push('--protected-conversation-config',config);
|
|
251
|
+
f.env={...f.env,CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs')};
|
|
252
|
+
return f;
|
|
253
|
+
}
|
|
254
|
+
export const implementedValue=()=>({outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
255
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}});
|
|
256
|
+
export const lastCheckpoint=f=>JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json')))
|
|
257
|
+
.records.filter(row=>row.payload.type==='effect-checkpoint').at(-1).payload.checkpoint;
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
// Step 21: exercise actual worker timers/cleanup and durable CLI restart, with
|
|
261
|
+
// synthetic providers only. The installed Codex is used solely for sandbox checks.
|
|
262
|
+
export function installTimeoutReviewer(f,runtime){
|
|
263
|
+
installDispatchFakes(f);
|
|
264
|
+
const fake=path.join(f.root,'bin',runtime),delegate=fake+'-delegate';
|
|
265
|
+
fs.renameSync(fake,delegate);
|
|
266
|
+
const modeFile=path.join(f.root,'review-mode.json');
|
|
267
|
+
fs.writeFileSync(modeFile,JSON.stringify('approved'));
|
|
268
|
+
fs.writeFileSync(fake,guardFixtureSource(String.raw`#!${process.execPath}
|
|
269
|
+
const fs=require('node:fs'),cp=require('node:child_process'),crypto=require('node:crypto');
|
|
270
|
+
const args=process.argv.slice(2),runtime=${JSON.stringify(runtime)},modeFile=${JSON.stringify(modeFile)};
|
|
271
|
+
if(args[0]==='sandbox'){const r=cp.spawnSync(${JSON.stringify(delegate)},args,{stdio:'inherit'});process.exit(r.status??1);}
|
|
272
|
+
let prompt='';process.stdin.on('data',s=>prompt+=s);process.stdin.on('end',()=>{
|
|
273
|
+
const mode=JSON.parse(fs.readFileSync(modeFile));
|
|
274
|
+
if(mode==='approved'||!prompt.includes('<cm-review-data-json>')){
|
|
275
|
+
const r=cp.spawnSync(${JSON.stringify(delegate)},args,{input:prompt,encoding:'utf8'});
|
|
276
|
+
process.stdout.write(r.stdout??'');process.stderr.write(r.stderr??'');process.exit(r.status??1);
|
|
277
|
+
}
|
|
278
|
+
const thread=crypto.randomUUID(),send=e=>process.stdout.write(JSON.stringify(e)+'\n');
|
|
279
|
+
if(runtime==='codex'){
|
|
280
|
+
send({type:'thread.started',thread_id:thread});send({type:'turn.started'});
|
|
281
|
+
if(mode==='result')send({type:'item.completed',item:{type:'agent_message',text:'{"verdict":"approved"}'}});
|
|
282
|
+
}else{
|
|
283
|
+
send({type:'system',subtype:'init',session_id:thread});
|
|
284
|
+
if(mode==='result'){
|
|
285
|
+
send({type:'assistant',session_id:thread,parent_tool_use_id:null,
|
|
286
|
+
message:{role:'assistant',content:[{type:'text',text:'{"verdict":"approved"}'}]}});
|
|
287
|
+
send({type:'result',subtype:'success',session_id:thread,is_error:false,num_turns:1,structured_output:{verdict:'approved'},result:'{"verdict":"approved"}'});
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
// A hung reviewer announces its pid so the watchdog regression can find it.
|
|
291
|
+
fs.writeFileSync(modeFile+'.hung',String(process.pid));
|
|
292
|
+
setInterval(()=>{},1000);
|
|
293
|
+
});
|
|
294
|
+
`),{mode:0o700});
|
|
295
|
+
return mode=>fs.writeFileSync(modeFile,JSON.stringify(mode));
|
|
296
|
+
}
|