@aibyzero/cm-workflow 0.16.4 → 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 +50 -0
- package/README.md +12 -1
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- 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 +12 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -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 +12 -4
- 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-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 +3 -1
- 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 +10 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +92 -20
- package/scripts/cm-ai-batch-drive.test.mjs +164 -3
- package/scripts/cm-ai-batch-host.mjs +27 -11
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- 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 +479 -47
- package/scripts/cm-ai-drive.test.mjs +240 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +84 -25
- package/scripts/cm-ai-host.test.mjs +232 -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.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +25 -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 +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -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 +9 -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 +12 -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-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 +261 -42
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -6,7 +6,10 @@ import path from 'node:path';
|
|
|
6
6
|
import {spawnSync} from 'node:child_process';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
-
import {
|
|
9
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
10
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
12
|
+
import {qaFixAnswerFor,projectDevelopAttempts} from './cm-ai-drive.mjs';
|
|
10
13
|
|
|
11
14
|
const DRIVER=fileURLToPath(new URL('./cm-ai-drive.mjs',import.meta.url));
|
|
12
15
|
const identity={repositoryId:'drive-fixture',runId:'drive-run',taskId:'T-001',attempt:1};
|
|
@@ -17,7 +20,7 @@ test('help prints the plan command without launching a host',()=>{
|
|
|
17
20
|
function fixture(t){
|
|
18
21
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-')));
|
|
19
22
|
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
20
|
-
const specsDir=path.join(root,'
|
|
23
|
+
const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),feature='1.work';
|
|
21
24
|
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
22
25
|
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
23
26
|
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
@@ -26,22 +29,155 @@ function fixture(t){
|
|
|
26
29
|
fs.writeFileSync(path.join(root,'run.json'),JSON.stringify({version:1,specsDir,codeProject,feature,identity,
|
|
27
30
|
scope:['target.mjs'],requirements:['requirements.md']}));
|
|
28
31
|
const answers=path.join(root,'answers');fs.mkdirSync(answers);
|
|
32
|
+
const bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
29
33
|
const write=(name,value)=>fs.writeFileSync(path.join(answers,name),JSON.stringify(value));
|
|
34
|
+
// create requires a bound review configuration; this one grants no review attempt.
|
|
35
|
+
fs.writeFileSync(path.join(root,'placeholder-review.json'),JSON.stringify({model:'fixture',preflight:{}}));
|
|
30
36
|
const plan=(extra={})=>{const file=path.join(root,`plan-${Math.random().toString(36).slice(2)}.json`);
|
|
31
|
-
|
|
32
|
-
permissions:[],answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra}
|
|
37
|
+
const value={config:'run.json',mode:'create',hostContext:'drive-host-a',
|
|
38
|
+
permissions:[],answers:'answers',checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}],...extra};
|
|
39
|
+
if(!value.permissions.includes('--review-config'))value.permissions=[...value.permissions,'--review-config','placeholder-review.json'];
|
|
40
|
+
fs.writeFileSync(file,JSON.stringify(value));
|
|
33
41
|
return file;};
|
|
34
|
-
const drive=(file,operation)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],
|
|
35
|
-
{encoding:'utf8',timeout
|
|
42
|
+
const drive=(file,operation,timeout=30000)=>spawnSync(process.execPath,[DRIVER,'--plan',file,operation],
|
|
43
|
+
{encoding:'utf8',timeout,env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_HOME:path.join(root,'home'),
|
|
36
44
|
CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}});
|
|
37
45
|
const store=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
38
|
-
return {root,codeProject,specsDir,answers,write,plan,drive,store};
|
|
46
|
+
return {root,codeProject,specsDir,answers,bin,write,plan,drive,store};
|
|
39
47
|
}
|
|
40
48
|
const develop={status:'succeeded',value:{outcome:'implemented',
|
|
41
49
|
application:{status:'no_relevant_lesson',note:null},
|
|
42
50
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},
|
|
43
51
|
edits:{'target.mjs':'target-content.mjs'}};
|
|
44
52
|
function prepared(f){f.write('develop.json',develop);fs.writeFileSync(path.join(f.answers,'target-content.mjs'),'export const value = 42;\n');}
|
|
53
|
+
function changesRequestedReview(f){
|
|
54
|
+
const source=fs.readFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),'utf8');
|
|
55
|
+
const fake=source.replace("verdict:'approved'","verdict:'changes_requested'")
|
|
56
|
+
.replace('findings:[]',"findings:[{id:'F1',severity:'P2',path:'target.mjs',message:'Revise the value',evidence:'Fixture finding'}]");
|
|
57
|
+
const cli=path.join(f.bin,'codex');fs.writeFileSync(cli,fake,{mode:0o700});
|
|
58
|
+
fs.writeFileSync(path.join(f.root,'review.json'),JSON.stringify({model:'fixture',preflight:{passed:true,
|
|
59
|
+
cli_model:'fixture',prompt_transport:'stdin',config_fingerprint:configFingerprint({cwd:f.codeProject,model:'fixture'})}}));
|
|
60
|
+
return ['--review-config','review.json','--allow-review-attempt','1'];
|
|
61
|
+
}
|
|
62
|
+
function reviewPending(f){
|
|
63
|
+
prepared(f);const permissions=changesRequestedReview(f);
|
|
64
|
+
const first=f.drive(f.plan({permissions:permissions.slice(0,2)}),'advance');assert.equal(first.status,0,first.stderr);
|
|
65
|
+
return {permissions,packageDigest:JSON.parse(first.stdout).result.packageDigest};
|
|
66
|
+
}
|
|
67
|
+
function assertActionableFirstReviewHint(stderr){
|
|
68
|
+
assert.match(stderr,/develop-a2\.json/);
|
|
69
|
+
assert.match(stderr,/审查后可能直接进入第 2 轮 develop/);
|
|
70
|
+
assert.match(stderr,/移除 --allow-review-attempt 1/);
|
|
71
|
+
assert.match(stderr,/awaiting_review/);
|
|
72
|
+
assert.match(stderr,/packageDigest.*decision/);
|
|
73
|
+
assert.match(stderr,/\.reviews\/work-T-001-r1\.md/);
|
|
74
|
+
assert.match(stderr,/预先写.*develop-a2\.json/);
|
|
75
|
+
assert.match(stderr,/逐字节相同时.*develop_unchanged_after_review/);
|
|
76
|
+
}
|
|
77
|
+
test('review-enabled advance refuses missing second-round answer before host launch',t=>{
|
|
78
|
+
const f=fixture(t),{permissions,packageDigest}=reviewPending(f),before=fs.readFileSync(f.store);
|
|
79
|
+
const run=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions}),'advance');
|
|
80
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/develop-a2\.json/);
|
|
81
|
+
assert.match(run.stderr,/decision/);assert.match(run.stderr,new RegExp(packageDigest));
|
|
82
|
+
assert.match(run.stderr,/\.reviews\/work-T-001-r1\.md/);
|
|
83
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
84
|
+
});
|
|
85
|
+
test('retryable blocked state projects the same develop attempt',()=>{
|
|
86
|
+
for(const code of ['developer_result_invalid','verification_precheck_failed','check_output_out_of_scope','develop_checks_not_passed'])
|
|
87
|
+
assert.deepEqual(projectDevelopAttempts({state:'blocked',code,attempt:2},'advance',[]).attempts,[2]);
|
|
88
|
+
assert.deepEqual(projectDevelopAttempts({state:'blocked',code:'checks_not_passed',attempt:2},'advance',[]).attempts,[]);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('D1 real host retries a check-output-blocked develop with a fresh effect id',t=>{
|
|
92
|
+
const f=fixture(t);prepared(f);
|
|
93
|
+
const definition=JSON.parse(fs.readFileSync(path.join(f.root,'run.json'),'utf8'));
|
|
94
|
+
definition.scope=['App/ContentView.swift'];fs.writeFileSync(path.join(f.root,'run.json'),JSON.stringify(definition));
|
|
95
|
+
fs.writeFileSync(path.join(f.answers,'ContentView.swift'),'import SwiftUI\nstruct ContentView: View { var body: some View { Text("Ready") } }\n');
|
|
96
|
+
f.write('develop.json',{...develop,edits:{'App/ContentView.swift':'ContentView.swift'}});
|
|
97
|
+
const dirty=[{id:'build',command:[process.execPath,'-e',"require('node:fs').mkdirSync('build',{recursive:true});require('node:fs').writeFileSync('build/out.o','x')"]}];
|
|
98
|
+
const first=f.drive(f.plan({runtime:'claude',checks:dirty}),'advance');assert.equal(first.status,0,first.stderr);
|
|
99
|
+
assert.equal(JSON.parse(first.stdout).result.code,'check_output_out_of_scope');
|
|
100
|
+
fs.rmSync(path.join(f.codeProject,'build'),{recursive:true});
|
|
101
|
+
const clean=[{id:'build',command:[process.execPath,'-e','0']}];
|
|
102
|
+
const second=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',runtime:'claude',checks:clean}),'advance');
|
|
103
|
+
assert.equal(second.status,0,second.stderr);
|
|
104
|
+
assert.equal(JSON.parse(second.stdout).result.state,'awaiting_review');
|
|
105
|
+
assert.match(second.stderr,/应答 develop/);
|
|
106
|
+
const intents=JSON.parse(fs.readFileSync(f.store)).records.filter(r=>r.payload.type==='effect-intent').map(r=>r.payload.effect.id);
|
|
107
|
+
assert.deepEqual(intents,['develop-1','develop-1-retry-1']);
|
|
108
|
+
assert.match(fs.readFileSync(path.join(f.codeProject,'App','ContentView.swift'),'utf8'),/import SwiftUI/);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('D1 per-check timeout lets a 61 second check finish under a 65 second limit',t=>{
|
|
112
|
+
const f=fixture(t);prepared(f);
|
|
113
|
+
const checks=[{id:'slow',command:[process.execPath,'-e','setTimeout(()=>{},61000)'],timeoutMs:65000}];
|
|
114
|
+
const run=f.drive(f.plan({checkTimeoutMs:1000,checks}),'advance',80000);
|
|
115
|
+
assert.equal(run.status,0,run.stderr);
|
|
116
|
+
assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review');
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for(const plan of [{checkTimeoutMs:0},{checks:[{id:'syntax',command:[process.execPath,'--check','target.mjs'],timeoutMs:3600001}]}])
|
|
120
|
+
test(`D1 single driver rejects invalid timeout before host launch ${Object.keys(plan)[0]}`,t=>{
|
|
121
|
+
const f=fixture(t);prepared(f);
|
|
122
|
+
const run=f.drive(f.plan(plan),'advance');
|
|
123
|
+
assert.equal(run.status,2);assert.match(run.stderr,/[tT]imeoutMs/);assert.equal(fs.existsSync(f.store),false);
|
|
124
|
+
});
|
|
125
|
+
test('review-authorized create preflights a possible second develop round',t=>{
|
|
126
|
+
const f=fixture(t);prepared(f);const permissions=changesRequestedReview(f);
|
|
127
|
+
const run=f.drive(f.plan({permissions}),'advance');
|
|
128
|
+
assert.equal(run.status,2,run.stderr);assertActionableFirstReviewHint(run.stderr);
|
|
129
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
130
|
+
});
|
|
131
|
+
test('review-authorized resume from ready gives the same two paths before launch',t=>{
|
|
132
|
+
const f=fixture(t);prepared(f);const permissions=changesRequestedReview(f);
|
|
133
|
+
const status=f.drive(f.plan({permissions:permissions.slice(0,2),answers:undefined,checks:undefined}),'status');
|
|
134
|
+
assert.equal(status.status,0,status.stderr);assert.equal(JSON.parse(status.stdout).result.state,'ready');
|
|
135
|
+
const before=fs.readFileSync(f.store);
|
|
136
|
+
const run=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions}),'advance');
|
|
137
|
+
assert.equal(run.status,2,run.stderr);assertActionableFirstReviewHint(run.stderr);
|
|
138
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
139
|
+
});
|
|
140
|
+
test('create advance without review authorization accepts only develop.json',t=>{
|
|
141
|
+
const f=fixture(t);prepared(f);const permissions=changesRequestedReview(f).slice(0,2);
|
|
142
|
+
assert.equal(fs.existsSync(path.join(f.answers,'develop-a2.json')),false);
|
|
143
|
+
const run=f.drive(f.plan({permissions}),'advance');assert.equal(run.status,0,run.stderr);
|
|
144
|
+
assert.equal(JSON.parse(run.stdout).result.state,'awaiting_review');
|
|
145
|
+
});
|
|
146
|
+
test('decision dispatches only review and leaves changes_requested for authored revision',t=>{
|
|
147
|
+
const f=fixture(t),{permissions,packageDigest}=reviewPending(f);
|
|
148
|
+
const run=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions,
|
|
149
|
+
packageDigest,answers:undefined,checks:undefined}),'decision');
|
|
150
|
+
assert.equal(run.status,0,run.stderr);
|
|
151
|
+
assert.equal(JSON.parse(run.stdout).result.state,'changes_requested');
|
|
152
|
+
assert.equal(JSON.parse(run.stdout).result.identity.attempt,2);
|
|
153
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
154
|
+
});
|
|
155
|
+
test('advance applies develop-a2 content after changes_requested review',t=>{
|
|
156
|
+
const f=fixture(t),{permissions}=reviewPending(f);
|
|
157
|
+
fs.writeFileSync(path.join(f.answers,'target-a2.mjs'),'export const value = 43;\n');
|
|
158
|
+
f.write('develop-a2.json',{...develop,edits:{'target.mjs':'target-a2.mjs'}});
|
|
159
|
+
const run=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions}),'advance');
|
|
160
|
+
assert.equal(run.status,0,run.stderr);
|
|
161
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 43;\n');
|
|
162
|
+
assert.equal(JSON.parse(run.stdout).result.identity.attempt,2);
|
|
163
|
+
});
|
|
164
|
+
test('both first-round develop filenames are refused before launch',t=>{
|
|
165
|
+
const f=fixture(t);prepared(f);f.write('develop-a1.json',develop);
|
|
166
|
+
const run=f.drive(f.plan(),'advance');assert.equal(run.status,2,run.stderr);
|
|
167
|
+
assert.match(run.stderr,/develop\.json.*develop-a1\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
168
|
+
});
|
|
169
|
+
test('develop-a1 alone is accepted for a new run',t=>{
|
|
170
|
+
const f=fixture(t);prepared(f);fs.renameSync(path.join(f.answers,'develop.json'),path.join(f.answers,'develop-a1.json'));
|
|
171
|
+
const run=f.drive(f.plan(),'advance');assert.equal(run.status,0,run.stderr);
|
|
172
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
173
|
+
});
|
|
174
|
+
test('malformed develop-a2 is rejected before review launch',t=>{
|
|
175
|
+
const f=fixture(t),{permissions}=reviewPending(f),before=fs.readFileSync(f.store);
|
|
176
|
+
f.write('develop-a2.json',{status:'succeeded',value:{outcome:'implemented'},edits:{}});
|
|
177
|
+
const run=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions}),'advance');
|
|
178
|
+
assert.equal(run.status,2,run.stderr);assert.match(run.stderr,/答案格式错误/);
|
|
179
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
180
|
+
});
|
|
45
181
|
function qaFixture(f,kinds,caseIds=[]){
|
|
46
182
|
const featureRoot=path.join(f.specsDir,'1.work');
|
|
47
183
|
fs.writeFileSync(path.join(featureRoot,'requirements.md'),'- [AC-001]: fixture\n');
|
|
@@ -73,6 +209,88 @@ test('create and advance run authored edits and actual check, then resume with o
|
|
|
73
209
|
assert.equal(resumed.status,0,resumed.stderr);assert.equal(JSON.parse(resumed.stdout).result.code,'decision_required');
|
|
74
210
|
});
|
|
75
211
|
|
|
212
|
+
test('driver resumes an interrupted develop and sends the bound abandon_effect request',t=>{
|
|
213
|
+
const f=fixture(t);prepared(f);
|
|
214
|
+
const first=f.drive(f.plan(),'advance');assert.equal(first.status,0,first.stderr);
|
|
215
|
+
const current=JSON.parse(fs.readFileSync(f.store,'utf8'));
|
|
216
|
+
const index=current.records.findIndex(row=>row.payload.type==='effect-intent'
|
|
217
|
+
&&row.payload.effect.kind==='develop');assert(index>=0);
|
|
218
|
+
const {revision,...body}=current;body.records=current.records.slice(0,index+1);
|
|
219
|
+
fs.writeFileSync(f.store,JSON.stringify({...body,revision:digest(body)})+'\n');
|
|
220
|
+
fs.rmSync(path.join(f.codeProject,'target.mjs'));
|
|
221
|
+
const plan=f.plan({mode:'resume',permissions:['--allow-abandon-effect'],
|
|
222
|
+
reason:'Old host and its checks have exited'});
|
|
223
|
+
const result=f.drive(plan,'abandon_effect');assert.equal(result.status,0,result.stderr);
|
|
224
|
+
const response=JSON.parse(result.stdout).result;
|
|
225
|
+
assert.equal(response.state,'cancelled');assert.equal(response.code,'effect_abandoned');
|
|
226
|
+
const saved=JSON.parse(fs.readFileSync(f.store,'utf8'));
|
|
227
|
+
assert.deepEqual(saved.records.slice(-2).map(row=>row.payload.type),['effect-intent','effect-abandoned']);
|
|
228
|
+
});
|
|
229
|
+
test('real host drives split-root bootstrap scaffold, then refuses rules without answer files before creating T-002 run',
|
|
230
|
+
{skip:process.platform!=='darwin'},t=>{
|
|
231
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-drive-bootstrap-')));
|
|
232
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
233
|
+
const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),feature='1.bootstrap';
|
|
234
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
235
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# SwiftUI scaffold and rules\n');
|
|
236
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Split specs5 and app roots\n');
|
|
237
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范(cm-init)\n');
|
|
238
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
239
|
+
const answers=path.join(root,'answers'),bin=path.join(root,'bin');fs.mkdirSync(answers);fs.mkdirSync(bin);
|
|
240
|
+
fs.writeFileSync(path.join(answers,'app-content.mjs'),'export const app = true;\n');
|
|
241
|
+
fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({...develop,edits:{'app.mjs':'app-content.mjs'}}));
|
|
242
|
+
const config=path.join(root,'run.json'),bootstrap=path.join(root,'bootstrap.json');
|
|
243
|
+
const plan=path.join(root,'plan.json'),selection={versionControl:'local',modules:[],analysis:'SwiftUI iOS app'};
|
|
244
|
+
const writeRun=(taskId,scope)=>fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,
|
|
245
|
+
identity:{repositoryId:'app',runId:`bootstrap-${taskId}`,taskId,attempt:1},scope,requirements:[]}));
|
|
246
|
+
const writePlan=(mode,permissions,extra={})=>fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode,
|
|
247
|
+
hostContext:'drive-bootstrap-host',runtime:'claude',permissions,answers:'answers',
|
|
248
|
+
checks:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}],...extra}));
|
|
249
|
+
const env={...process.env,PATH:bin+path.delimiter+process.env.PATH,
|
|
250
|
+
CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs')};
|
|
251
|
+
const drive=operation=>spawnSync(process.execPath,[DRIVER,'--plan',plan,operation],{encoding:'utf8',timeout:30000,env});
|
|
252
|
+
writeRun('T-001',['app.mjs']);fs.writeFileSync(bootstrap,JSON.stringify({selection:null}));
|
|
253
|
+
const reviewCli=path.join(bin,'claude');
|
|
254
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/claude-review-process.mjs',import.meta.url)),reviewCli);
|
|
255
|
+
fs.chmodSync(reviewCli,0o700);
|
|
256
|
+
const preview=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),
|
|
257
|
+
'preflight','--config',config,'--review-model','fixture','--runtime','claude'],
|
|
258
|
+
{encoding:'utf8',timeout:10000,env});
|
|
259
|
+
assert.equal(preview.status,0,preview.stderr);
|
|
260
|
+
fs.writeFileSync(path.join(root,'review.json'),preview.stdout);
|
|
261
|
+
writePlan('create',['--bootstrap-config','bootstrap.json','--allow-bootstrap-write','--review-config','review.json']);
|
|
262
|
+
const scaffold=drive('advance');assert.equal(scaffold.status,0,scaffold.stderr);
|
|
263
|
+
const first=JSON.parse(scaffold.stdout).result;assert.equal(first.state,'awaiting_review');
|
|
264
|
+
assert.equal(fs.readFileSync(path.join(codeProject,'app.mjs'),'utf8'),'export const app = true;\n');
|
|
265
|
+
writePlan('resume',['--bootstrap-config','bootstrap.json','--allow-bootstrap-write','--review-config','review.json',
|
|
266
|
+
'--allow-review-attempt','1'],{packageDigest:first.packageDigest});
|
|
267
|
+
const review=drive('decision');
|
|
268
|
+
assert.equal(review.status,0,review.stderr);assert.equal(JSON.parse(review.stdout).result.state,'approved');
|
|
269
|
+
writePlan('resume',['--bootstrap-config','bootstrap.json','--allow-bootstrap-write','--review-config','review.json']);
|
|
270
|
+
const completed=drive('advance');assert.equal(completed.status,0,completed.stderr);
|
|
271
|
+
assert.equal(JSON.parse(completed.stdout).result.state,'fixture_completed');
|
|
272
|
+
assert.match(fs.readFileSync(path.join(specsDir,feature,'tasks.md'),'utf8'),/\[x\] T-001/);
|
|
273
|
+
writeRun('T-002',cmInitRuleTargets(selection,codeProject));
|
|
274
|
+
fs.writeFileSync(bootstrap,JSON.stringify({selection}));
|
|
275
|
+
writePlan('create',['--bootstrap-config','bootstrap.json','--allow-bootstrap-write']);
|
|
276
|
+
const rules=drive('advance');assert.equal(rules.status,2,rules.stderr);
|
|
277
|
+
assert.match(rules.stderr,/会反问 init_generate,但答案文件不存在: .*init-generate\.json/);
|
|
278
|
+
assert.equal(fs.existsSync(path.join(specsDir,'.reviews','.execution','bootstrap-T-002')),false);
|
|
279
|
+
assert.equal(fs.existsSync(path.join(codeProject,'.claude')),false);
|
|
280
|
+
});
|
|
281
|
+
test('driver requires resume, flag and one-line reason for abandon_effect before launch',t=>{
|
|
282
|
+
const f=fixture(t);
|
|
283
|
+
for(const plan of [
|
|
284
|
+
{mode:'create',permissions:['--allow-abandon-effect'],reason:'host exited'},
|
|
285
|
+
{mode:'resume',permissions:[],reason:'host exited'},
|
|
286
|
+
{mode:'resume',permissions:['--allow-abandon-effect'],reason:'line one\nline two'},
|
|
287
|
+
{mode:'resume',permissions:['--allow-abandon-effect'],reason:'x'.repeat(501)}]){
|
|
288
|
+
const run=f.drive(f.plan(plan),'abandon_effect');assert.equal(run.status,2,run.stderr);
|
|
289
|
+
assert.match(run.stderr,/abandon_effect 需要 resume/);
|
|
290
|
+
assert.equal(fs.existsSync(f.store),false);
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
|
|
76
294
|
test('missing develop answer is refused before store creation',t=>{
|
|
77
295
|
const f=fixture(t);const run=f.drive(f.plan(),'advance');
|
|
78
296
|
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
@@ -166,10 +384,16 @@ test('protected conversation still requires the authored develop answer',t=>{
|
|
|
166
384
|
permissions:['--protected-conversation-config','protection.json']}),'advance');
|
|
167
385
|
assert.equal(run.status,2);assert.match(run.stderr,/develop\.json/);assert.equal(fs.existsSync(f.store),false);
|
|
168
386
|
});
|
|
169
|
-
test('resume
|
|
387
|
+
test('same-session resume may omit originalHostContext and cross-session omission fails exact fingerprint',t=>{
|
|
170
388
|
const f=fixture(t);prepared(f);
|
|
171
|
-
|
|
172
|
-
|
|
389
|
+
assert.equal(f.drive(f.plan(),'advance').status,0);
|
|
390
|
+
const before=fs.readFileSync(f.store);
|
|
391
|
+
const same=f.drive(f.plan({mode:'resume',answers:undefined,checks:undefined}),'status');
|
|
392
|
+
assert.equal(same.status,0,same.stderr);
|
|
393
|
+
assert.equal(JSON.parse(same.stdout).result.state,'awaiting_review');
|
|
394
|
+
const cross=f.drive(f.plan({mode:'resume',hostContext:'drive-host-b',answers:undefined,checks:undefined}),'status');
|
|
395
|
+
assert.equal(cross.status,1,cross.stderr);assert.match(cross.stderr,/fingerprint_mismatch/);
|
|
396
|
+
assert.deepEqual(fs.readFileSync(f.store),before);
|
|
173
397
|
});
|
|
174
398
|
test('supersession flags reach create and incomplete or resume pairs stop before host launch',t=>{
|
|
175
399
|
const f=fixture(t);prepared(f);
|
|
@@ -177,11 +401,17 @@ test('supersession flags reach create and incomplete or resume pairs stop before
|
|
|
177
401
|
const create=f.drive(f.plan({permissions:both}),'advance');
|
|
178
402
|
assert.equal(create.status,1,create.stderr);
|
|
179
403
|
assert.match(create.stderr,/supersede_unavailable/);
|
|
404
|
+
const accepted=f.drive(f.plan({permissions:[...both,'--accept-superseded-code-drift']}),'advance');
|
|
405
|
+
assert.equal(accepted.status,1,accepted.stderr);
|
|
406
|
+
assert.match(accepted.stderr,/supersede_unavailable/);
|
|
180
407
|
for(const permissions of [['--supersede-reviewed-evidence'],['--supersede-reason','operator restart']]){
|
|
181
408
|
const refused=f.drive(f.plan({permissions}),'advance');
|
|
182
409
|
assert.equal(refused.status,2,refused.stderr);
|
|
183
410
|
assert.match(refused.stderr,/supersede-reviewed-evidence.*supersede-reason/);
|
|
184
411
|
}
|
|
412
|
+
const orphan=f.drive(f.plan({permissions:['--accept-superseded-code-drift']}),'advance');
|
|
413
|
+
assert.equal(orphan.status,2,orphan.stderr);
|
|
414
|
+
assert.match(orphan.stderr,/accept-superseded-code-drift.*supersede-reviewed-evidence/);
|
|
185
415
|
const resumed=f.drive(f.plan({mode:'resume',originalHostContext:'drive-host-a',permissions:both}),'status');
|
|
186
416
|
assert.equal(resumed.status,2,resumed.stderr);
|
|
187
417
|
assert.match(resumed.stderr,/supersede.*create/);
|