@aibyzero/cm-workflow 0.13.3 → 0.15.2
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 +41 -0
- package/README.md +34 -1
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +55 -0
- package/docs/user-guide.md +3 -0
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +1 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +53 -22
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +4 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +40 -17
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +103 -23
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -4
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +5 -2
- package/runtime/js/cm-ai/codex-developer-output.schema.json +2 -1
- package/runtime/js/cm-ai/developer-adapter.mjs +17 -5
- package/runtime/js/cm-ai/durable-runner-state.mjs +7 -2
- package/runtime/js/cm-ai/effect-contract.mjs +8 -1
- package/runtime/js/cm-ai/execution-store.mjs +25 -5
- package/runtime/js/cm-ai/host-check.mjs +20 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +5 -4
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +46 -24
- package/runtime/js/cm-ai/host-qa-policy.mjs +3 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +41 -3
- package/runtime/js/cm-ai/qa-environment.mjs +22 -0
- package/runtime/js/cm-ai/task-runner.mjs +1 -0
- package/runtime/js/cm-ai/worker-claude-developer.mjs +2 -1
- package/runtime/js/cm-fix/cause-package.mjs +3 -1
- package/runtime/js/cm-fix/dossier.mjs +7 -2
- package/runtime/js/cm-fix/reproduce.mjs +26 -5
- package/runtime/js/cm-fix/visual.mjs +3 -2
- package/runtime/js/cm-fix/walkthrough.mjs +2 -1
- package/runtime/js/cm-init/draft-generation.mjs +3 -2
- package/runtime/js/cm-init/draft-inspection.mjs +17 -3
- package/runtime/js/cm-init/review-evidence.mjs +1 -1
- package/runtime/js/cm-prd/summary.mjs +6 -8
- package/runtime/js/cm-security/finalize.mjs +164 -0
- package/runtime/js/cm-test/host.mjs +2 -2
- package/runtime/js/specs-status.mjs +66 -0
- package/runtime/project-context.md +4 -1
- package/scripts/cm-ai-admission.mjs +46 -7
- package/scripts/cm-ai-admission.test.mjs +50 -0
- package/scripts/cm-ai-batch-host.mjs +72 -10
- package/scripts/cm-ai-batch-host.test.mjs +128 -4
- package/scripts/cm-ai-batch-run.mjs +366 -17
- package/scripts/cm-ai-batch-run.test.mjs +222 -13
- package/scripts/cm-ai-bootstrap.test.mjs +3 -2
- package/scripts/cm-ai-host.mjs +38 -21
- package/scripts/cm-ai-host.test.mjs +68 -4
- package/scripts/cm-ai-nested-execution.test.mjs +1 -1
- package/scripts/cm-ai-run.mjs +25 -15
- package/scripts/cm-ai-run.test.mjs +48 -0
- package/scripts/cm-blocked-reason.test.mjs +104 -0
- package/scripts/cm-capability-gate.test.mjs +179 -0
- package/scripts/cm-check-update.mjs +5 -2
- package/scripts/cm-check-update.test.mjs +21 -0
- package/scripts/cm-codex-developer-adapter.test.mjs +70 -0
- package/scripts/cm-fix-cause-package.test.mjs +18 -1
- package/scripts/cm-fix-execution.test.mjs +31 -0
- package/scripts/cm-fix-host-review.test.mjs +2 -1
- package/scripts/cm-fix-host.test.mjs +2 -1
- package/scripts/cm-fix-observation-dossier.test.mjs +2 -0
- package/scripts/cm-fix-qa-source.test.mjs +1 -3
- package/scripts/cm-fix-reproduce.test.mjs +53 -2
- package/scripts/cm-fix-review-recovery.test.mjs +4 -3
- package/scripts/cm-host-check.test.mjs +22 -0
- package/scripts/cm-host-qa-executor.test.mjs +302 -3
- package/scripts/cm-host-qa-policy.test.mjs +34 -0
- package/scripts/cm-init-draft-generation.test.mjs +24 -3
- package/scripts/cm-init-draft-inspection.test.mjs +80 -0
- package/scripts/cm-init-host.mjs +2 -2
- package/scripts/cm-init-host.test.mjs +3 -1
- package/scripts/cm-init-session.test.mjs +37 -0
- package/scripts/cm-log-event.mjs +28 -7
- package/scripts/cm-prd-design-phase.test.mjs +2 -1
- package/scripts/cm-prd-host.test.mjs +3 -2
- package/scripts/cm-prd-session-recovery.test.mjs +5 -4
- package/scripts/cm-qa-environment.test.mjs +30 -0
- package/scripts/cm-security.mjs +12 -4
- package/scripts/cm-security.test.mjs +109 -0
- package/scripts/cm-specs-status.test.mjs +130 -0
- package/scripts/cm-workflow-config.mjs +4 -0
- package/scripts/test-shell-compat.sh +0 -0
- package/skills/cm-ai/references/N1-init.md +22 -15
- package/skills/cm-ai/references/N5-mark-done.md +5 -2
- package/skills/cm-ai/references/N6-qa-eval.md +9 -4
- package/skills/cm-ai/references/js-host.md +25 -0
- package/skills/cm-fix/SKILL.md +5 -4
- package/skills/cm-fix/references/js-host.md +13 -0
- package/skills/cm-idea/SKILL.md +2 -0
- package/skills/cm-init/references/runtime-declaration.md +2 -0
- package/skills/cm-prd/SKILL.md +9 -8
- package/skills/cm-prd/references/spec-self-check.md +1 -0
- package/skills/cm-security/SKILL.md +14 -7
- package/skills/cm-security/references/scan-contract.md +45 -1
- package/skills/cm-test/references/js-host.md +4 -3
- package/templates/dashboard/dashboard.html +2 -2
|
@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
5
5
|
import path from 'node:path';
|
|
6
|
+
import {inspectCmAiQaTaskContext} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
6
7
|
import {createHostQaDecisionProvider,decideHostQaPolicy} from '../runtime/js/cm-ai/host-qa-policy.mjs';
|
|
7
8
|
|
|
8
9
|
const low=()=>({scores:{scope:1,risk:1,accumulation:1,boundary:1},
|
|
@@ -57,3 +58,36 @@ test('N6 derives consecutive work from original task inventory and QA log withou
|
|
|
57
58
|
await assert.rejects(stale.decide(binding,new AbortController().signal),{code:'stale_qa'});
|
|
58
59
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
59
60
|
});
|
|
61
|
+
|
|
62
|
+
test('step30 unseen excludes closed features, includes other open features, and preserves since-trigger skips',async()=>{
|
|
63
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-qa-policy-')));
|
|
64
|
+
try{
|
|
65
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code');fs.mkdirSync(codeProject);
|
|
66
|
+
fs.writeFileSync(path.join(codeProject,'source.js'),'// fixture\n');
|
|
67
|
+
const features=['1.closed-a','2.closed-b','3.closed-c','4.current','5.later'];
|
|
68
|
+
for(const [index,feature] of features.entries()){
|
|
69
|
+
const dir=path.join(specsDir,feature);fs.mkdirSync(dir,{recursive:true});
|
|
70
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(dir,name),'# Fixture\n');
|
|
71
|
+
const count=index<2?4:index===2?3:index===3?4:1;
|
|
72
|
+
fs.writeFileSync(path.join(dir,'tasks.md'),Array.from({length:count},(_,i)=>
|
|
73
|
+
`- [${index<3||index===3&&i===0?'x':' '}] T-00${i+1}: task`).join('\n')+'\n');
|
|
74
|
+
}
|
|
75
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features}));
|
|
76
|
+
const log=path.join(specsDir,'运行日志.jsonl');fs.writeFileSync(log,'');
|
|
77
|
+
const binding={specsDir,codeProject,feature:'4.current',identity:{repositoryId:'fixture',runId:'run-current',taskId:'T-001',attempt:1},packageDigest:'a'.repeat(64)};
|
|
78
|
+
const seen=[],provider=createHostQaDecisionProvider({timeoutMs:1000,assess:async input=>{seen.push(input.unassessedTasks);return low();}});
|
|
79
|
+
const decide=()=>provider.decide(binding,new AbortController().signal);
|
|
80
|
+
assert.equal((await decide()).status,'skipped');assert.equal(seen.at(-1),1);
|
|
81
|
+
const legacyCompletedWithoutQa=inspectCmAiQaTaskContext({...binding,taskId:binding.identity.taskId}).completed.length;
|
|
82
|
+
assert.equal(legacyCompletedWithoutQa,12);
|
|
83
|
+
console.log('STEP30 history',JSON.stringify({legacyCompletedWithoutQa,unassessedTasks:seen.at(-1),closedFeatures:3}));
|
|
84
|
+
fs.writeFileSync(path.join(specsDir,'5.later','tasks.md'),'- [x] T-001: done\n- [ ] T-002: pending\n');
|
|
85
|
+
await decide();assert.equal(seen.at(-1),2);
|
|
86
|
+
const row={schema_version:1,workflow:'cm-ai',event:'qa',node:'N6',feature:'1.closed-a',task:'T-001',
|
|
87
|
+
repository_id:'fixture',run_id:'historical',attempt:1,package_digest:'b'.repeat(64),decision_id:'old-decision',
|
|
88
|
+
status:'skipped',reason:'fixture',score:4,at:'2026-09-07T01:00:00Z'};
|
|
89
|
+
fs.writeFileSync(log,JSON.stringify(row)+'\n');await decide();assert.equal(seen.at(-1),3);
|
|
90
|
+
fs.appendFileSync(log,JSON.stringify({...row,feature:'2.closed-b',status:'triggered',score:null})+'\n');
|
|
91
|
+
await decide();assert.equal(seen.at(-1),2);
|
|
92
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
93
|
+
});
|
|
@@ -5,12 +5,34 @@ import os from 'node:os';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import {fileURLToPath} from 'node:url';
|
|
7
7
|
import {generateCmInitRules} from './cm-init-entry.mjs';
|
|
8
|
+
import {runtimePreset} from './cm-workflow-config.mjs';
|
|
9
|
+
import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
|
|
8
10
|
|
|
9
11
|
const repository=fileURLToPath(new URL('..',import.meta.url));
|
|
10
12
|
const selection={versionControl:'none',modules:['frontend'],analysis:'Synthetic web project; commands remain unverified.'};
|
|
11
13
|
function documents(request){return request.targets.map(file=>({path:file,content:file==='AGENTS.md'
|
|
12
14
|
?'# Fixture\nKeep original restriction.\n':file==='.claude/CLAUDE.md'
|
|
13
15
|
?'# Fixture\n@rules/testing.md\n':`# ${file}\nFixture rule.\n`}));}
|
|
16
|
+
test('init generation: selected preset reaches inspection for raw and corrected template drafts',async()=>{
|
|
17
|
+
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-generate-')));
|
|
18
|
+
try{
|
|
19
|
+
fs.writeFileSync(path.join(project,'README.md'),'# Synthetic library\n');
|
|
20
|
+
for(const corrected of [false,true]){
|
|
21
|
+
const result=await generateCmInitRules({project,skillDir:path.join(repository,'skills/cm-init')},
|
|
22
|
+
{...selection,modules:[],runtimes:{available:'both',preset:'codex-codes'}},{generate:async request=>{
|
|
23
|
+
const template=request.templates.find(item=>item.target==='.cm-workflow.yml').content;
|
|
24
|
+
const content=corrected?editRuntimeDeclaration(template,'.cm-workflow.yml',runtimePreset('codex-codes')):template;
|
|
25
|
+
assert.ok(request.constraints.some(item=>item.startsWith('New config only:')));
|
|
26
|
+
return {status:'generated',documents:documents(request).map(document=>document.path==='.cm-workflow.yml'
|
|
27
|
+
?{...document,content}:document)};
|
|
28
|
+
}});
|
|
29
|
+
assert.equal(result.inspection.status,corrected?'structurally_checked':'blocked');
|
|
30
|
+
assert.equal(result.inspection.issues.some(issue=>issue.code==='runtimes_preset_mismatch'),!corrected);
|
|
31
|
+
assert.equal(result.inspection.issues.filter(issue=>issue.severity==='warning').length,2);
|
|
32
|
+
assert.equal(fs.existsSync(path.join(project,'.cm-workflow.yml')),false);
|
|
33
|
+
}
|
|
34
|
+
}finally{fs.rmSync(project,{recursive:true,force:true});}
|
|
35
|
+
});
|
|
14
36
|
test('init generation: real repository templates feed host draft and existing inspection without writes',async()=>{
|
|
15
37
|
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-generate-')));
|
|
16
38
|
try{
|
|
@@ -56,8 +78,7 @@ for(const filename of [null,'.cm-workflow.yml','.cm-workflow.yaml','.cm-workflow
|
|
|
56
78
|
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-runtime-')));
|
|
57
79
|
const target=filename??'.cm-workflow.yml';
|
|
58
80
|
const prior=filename?.endsWith('.json')?'{"version":1,"project":{"type":"custom"}}':'version: 1\nproject:\n type: custom\n';
|
|
59
|
-
const content=target
|
|
60
|
-
:'version: 1\nproject:\n type: custom\nruntimes:\n available: codex\n';
|
|
81
|
+
const content=editRuntimeDeclaration(prior,target,runtimePreset('codex-only'));
|
|
61
82
|
try{
|
|
62
83
|
fs.writeFileSync(path.join(project,'README.md'),'# Fixture\n');
|
|
63
84
|
if(filename)fs.writeFileSync(path.join(project,filename),prior);
|
|
@@ -70,7 +91,7 @@ for(const filename of [null,'.cm-workflow.yml','.cm-workflow.yaml','.cm-workflow
|
|
|
70
91
|
assert.equal(template.fallbackRequired,false);
|
|
71
92
|
assert.equal(request.existing.at(-1).content,filename?prior:null);
|
|
72
93
|
assert.deepEqual(request.selection.runtimes,{available:'codex',preset:'codex-only'});
|
|
73
|
-
assert.ok(request.constraints.includes('Config file: fill
|
|
94
|
+
assert.ok(request.constraints.includes('Config file: fill runtimes.available and roles.coder/reviewer adapter+source per preset; for existing configs keep every other value; no secrets.'));
|
|
74
95
|
return {status:'generated',documents:documents(request).map(document=>document.path===target?{path:target,content}:document)};
|
|
75
96
|
}});
|
|
76
97
|
assert.equal(result.status,'draft_generated');assert.equal(result.inspection.status,'structurally_checked');
|
|
@@ -6,10 +6,90 @@ import os from 'node:os';
|
|
|
6
6
|
import {spawnSync} from 'node:child_process';
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {inspectCmInitDraft} from '../runtime/js/cm-init/draft-inspection.mjs';
|
|
9
|
+
import {loadConfig,runtimePreset,runtimesSource} from './cm-workflow-config.mjs';
|
|
10
|
+
import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
|
|
9
11
|
const repository=fileURLToPath(new URL('..',import.meta.url));
|
|
10
12
|
const draft=()=>[{path:'AGENTS.md',content:'# Project\n'},
|
|
11
13
|
{path:'.claude/CLAUDE.md',content:'# Project\n@rules/testing.md\n'},
|
|
12
14
|
{path:'.claude/rules/testing.md',content:'# Testing\n'}];
|
|
15
|
+
test('init draft: inherited preset rejects raw template, accepts all edited presets and leaves declared projects unchanged',()=>{
|
|
16
|
+
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-preset-')));
|
|
17
|
+
const oldHome=process.env.CM_WORKFLOW_HOME;
|
|
18
|
+
try{
|
|
19
|
+
process.env.CM_WORKFLOW_HOME=path.join(project,'user');fs.mkdirSync(process.env.CM_WORKFLOW_HOME);
|
|
20
|
+
fs.writeFileSync(path.join(process.env.CM_WORKFLOW_HOME,'runtimes.yml'),'runtimes: {available: both}\npreset: codex-codes\n');
|
|
21
|
+
const inherited=loadConfig({projectRoot:project});
|
|
22
|
+
assert.equal(runtimesSource(inherited),'user');
|
|
23
|
+
assert.equal(inherited.runtimes.available,'both');
|
|
24
|
+
const template=fs.readFileSync(path.join(repository,'templates/cm-workflow.yml'),'utf8');
|
|
25
|
+
const selection={versionControl:'remote',modules:['frontend'],analysis:'Synthetic fixture',
|
|
26
|
+
runtimes:{available:'both',preset:'codex-codes'}};
|
|
27
|
+
const inspect=(content,choice=selection)=>inspectCmInitDraft({project,selection:choice,
|
|
28
|
+
documents:[...draft(),{path:'.cm-workflow.yml',content}]});
|
|
29
|
+
const rejected=inspect(template);
|
|
30
|
+
assert.equal(rejected.status,'blocked');
|
|
31
|
+
assert.deepEqual(rejected.issues,[{path:'.cm-workflow.yml',code:'runtimes_preset_mismatch',
|
|
32
|
+
expected:runtimePreset('codex-codes'),actual:{runtimes:{available:'both'},roles:{
|
|
33
|
+
coder:{adapter:'current-ai',source:'local'},reviewer:{adapter:'current-ai',source:'local'}}}}]);
|
|
34
|
+
for(const preset of ['codex-only','claude-only','codex-codes','claude-codes']){
|
|
35
|
+
const expected=runtimePreset(preset);
|
|
36
|
+
const accepted=inspect(editRuntimeDeclaration(template,'.cm-workflow.yml',expected),
|
|
37
|
+
{...selection,runtimes:{available:expected.runtimes.available,preset}});
|
|
38
|
+
assert.equal(accepted.status,'structurally_checked');assert.deepEqual(accepted.issues,[]);
|
|
39
|
+
}
|
|
40
|
+
assert.equal(fs.existsSync(path.join(project,'.cm-workflow.yml')),false);
|
|
41
|
+
fs.writeFileSync(path.join(project,'.cm-workflow.yml'),template);
|
|
42
|
+
const {runtimes,...existingSelection}=selection;
|
|
43
|
+
assert.equal(inspect(template,existingSelection).status,'structurally_checked');
|
|
44
|
+
assert.deepEqual(inspect(template,existingSelection).issues,[]);
|
|
45
|
+
assert.equal(inspect(template).status,'blocked'); // A supplied selection also applies to existing targets.
|
|
46
|
+
assert.equal(fs.readFileSync(path.join(project,'.cm-workflow.yml'),'utf8'),template);
|
|
47
|
+
}finally{
|
|
48
|
+
if(oldHome===undefined)delete process.env.CM_WORKFLOW_HOME;else process.env.CM_WORKFLOW_HOME=oldHome;
|
|
49
|
+
fs.rmSync(project,{recursive:true,force:true});
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('init draft: compares available and both role adapter/source fields separately',()=>{
|
|
54
|
+
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-preset-')));
|
|
55
|
+
try{
|
|
56
|
+
for(const [role,field,value] of [['coder','adapter','current-ai'],['reviewer','adapter','current-ai'],
|
|
57
|
+
['coder','source','local'],['reviewer','source','local'],[null,'available','both']]){
|
|
58
|
+
const expected=runtimePreset('codex-only'),actual=structuredClone(expected);
|
|
59
|
+
if(role)actual.roles[role][field]=value;else actual.runtimes.available=value;
|
|
60
|
+
// both + current-ai avoids the shared parser's independent same-provider rule.
|
|
61
|
+
if(!role){actual.roles.coder.adapter='current-ai';actual.roles.reviewer.adapter='current-ai';}
|
|
62
|
+
const result=inspectCmInitDraft({project,selection:{runtimes:{available:'codex',preset:'codex-only'}},
|
|
63
|
+
documents:[...draft(),{path:'.cm-workflow.json',content:JSON.stringify({version:1,...actual})}]});
|
|
64
|
+
assert.equal(result.status,'blocked');
|
|
65
|
+
assert.deepEqual(result.issues,[{path:'.cm-workflow.json',code:'runtimes_preset_mismatch',expected,actual}]);
|
|
66
|
+
}
|
|
67
|
+
}finally{fs.rmSync(project,{recursive:true,force:true});}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('init draft: project policy warnings apply only to new configs and never hide blocking issues',()=>{
|
|
71
|
+
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-policy-')));
|
|
72
|
+
const value={version:1,...runtimePreset('codex-codes'),policies:{delivery:'draft-mr',tests:['logic','browser']}};
|
|
73
|
+
const inspect=(selection,config=value)=>inspectCmInitDraft({project,selection,
|
|
74
|
+
documents:[...draft(),{path:'.cm-workflow.json',content:JSON.stringify(config)}]});
|
|
75
|
+
try{
|
|
76
|
+
for(const versionControl of ['local','none','remote'])for(const modules of [[],['backend-api'],['frontend'],['miniprogram']]){
|
|
77
|
+
const result=inspect({versionControl,modules});
|
|
78
|
+
const codes=[...(versionControl==='remote'?[]:['delivery_requires_remote']),
|
|
79
|
+
...(modules.some(name=>['frontend','miniprogram'].includes(name))?[]:['browser_tests_without_ui'])];
|
|
80
|
+
assert.equal(result.status,'structurally_checked');
|
|
81
|
+
assert.deepEqual(result.issues,codes.map(code=>({path:'.cm-workflow.json',code,severity:'warning'})));
|
|
82
|
+
}
|
|
83
|
+
for(const delivery of ['branch','diff'])assert.deepEqual(inspect({versionControl:'local',modules:[]},
|
|
84
|
+
{...value,policies:{delivery,tests:['logic']}}).issues,[]);
|
|
85
|
+
const mismatch=inspect({versionControl:'local',modules:[],runtimes:{available:'both',preset:'claude-codes'}});
|
|
86
|
+
assert.equal(mismatch.status,'blocked');assert.equal(mismatch.issues.length,3);
|
|
87
|
+
fs.writeFileSync(path.join(project,'.cm-workflow.json'),JSON.stringify(value));
|
|
88
|
+
assert.deepEqual(inspect({versionControl:'local',modules:[]}).issues,[]);
|
|
89
|
+
const changed=inspect({versionControl:'local',modules:[]},{...value,policies:{delivery:'diff',tests:['logic']}});
|
|
90
|
+
assert.equal(changed.status,'blocked');assert.equal(changed.issues[0].code,'existing_config_fields_changed');
|
|
91
|
+
}finally{fs.rmSync(project,{recursive:true,force:true});}
|
|
92
|
+
});
|
|
13
93
|
test('init draft CLI: proposals reference each other; existing changes remain review-required and unwritten',()=>{
|
|
14
94
|
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-draft-')));
|
|
15
95
|
try{
|
package/scripts/cm-init-host.mjs
CHANGED
|
@@ -71,7 +71,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
71
71
|
stage=restored.report.status==='matches_reviewed_draft'?'rules_present':'draft_generated';
|
|
72
72
|
}
|
|
73
73
|
const current=()=>{
|
|
74
|
-
const inspection=inspectCmInitDraft({project:admission.project,documents:result.documents});
|
|
74
|
+
const inspection=inspectCmInitDraft({project:admission.project,documents:result.documents,selection});
|
|
75
75
|
need(inspection.status==='structurally_checked','init_draft_structural_failure');
|
|
76
76
|
need(digest(inspection.changes)===digest(result.inspection.changes),'init_verification_project_changed');
|
|
77
77
|
};
|
|
@@ -86,7 +86,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
86
86
|
const documents=message.documents;
|
|
87
87
|
need(Array.isArray(documents)&&documents.length===result.documents.length
|
|
88
88
|
&&documents.every(document=>result.documents.some(prior=>prior.path===document?.path)),'init_revision_scope_changed');
|
|
89
|
-
const inspection=inspectCmInitDraft({project:admission.project,documents});
|
|
89
|
+
const inspection=inspectCmInitDraft({project:admission.project,documents,selection});
|
|
90
90
|
need(inspection.status==='structurally_checked','init_draft_structural_failure');
|
|
91
91
|
revisionHistory.push({draftDigest:digest(result.documents),verification,confirmation,review});
|
|
92
92
|
result={...result,documents,inspection,status:'draft_generated'};
|
|
@@ -9,6 +9,8 @@ import {createInterface} from 'node:readline';
|
|
|
9
9
|
import {once} from 'node:events';
|
|
10
10
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {publishCmInitReviewEvidence} from '../runtime/js/cm-init/review-evidence.mjs';
|
|
12
|
+
import {runtimePreset} from './cm-workflow-config.mjs';
|
|
13
|
+
import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
|
|
12
14
|
const repository=fileURLToPath(new URL('..',import.meta.url));
|
|
13
15
|
for(const mode of ['generate','generate-runtime','cancel','verify','unverified','verify-drift','confirm','confirm-approve','confirm-reject','confirm-drift','review-package','review-package-drift','review-package-encoding','review-result-approved','review-result-changes','review-result-self','review-result-digest','write-success','write-partial','write-denied','write-drift','write-evidence-conflict','write-evidence-permissions'])test(`init host actual JSONL CLI: ${mode}`,{timeout:5000},async()=>{
|
|
14
16
|
const project=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-init-host-')));
|
|
@@ -66,7 +68,7 @@ for(const mode of ['generate','generate-runtime','cancel','verify','unverified',
|
|
|
66
68
|
assert.equal(message.kind,'init_generate');
|
|
67
69
|
if(mode==='cancel')send({requestId:'cancel',operation:'cancel'});
|
|
68
70
|
else send({type:'host_result',sessionId,callId:message.callId,requestDigest:message.requestDigest,
|
|
69
|
-
result:{status:'generated',documents:message.payload.targets.map(file=>({path:file,content:file==='.cm-workflow.yml'?'version: 1\
|
|
71
|
+
result:{status:'generated',documents:message.payload.targets.map(file=>({path:file,content:file==='.cm-workflow.yml'?editRuntimeDeclaration('version: 1\n',file,runtimePreset('codex-only')):'# Fixture\nPreserve original rule\n'}))}});
|
|
70
72
|
}
|
|
71
73
|
}else if(message.requestId==='generate')send(['generate','generate-runtime','cancel'].includes(mode)
|
|
72
74
|
?{requestId:'status',operation:'status'}:{requestId:'verify',operation:'advance'});
|
|
@@ -7,6 +7,8 @@ import {spawn} from 'node:child_process';
|
|
|
7
7
|
import {createInterface} from 'node:readline';
|
|
8
8
|
import {once} from 'node:events';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
|
+
import {runtimePreset} from './cm-workflow-config.mjs';
|
|
11
|
+
import {editRuntimeDeclaration} from './cm-runtime-edit.mjs';
|
|
10
12
|
const root=fileURLToPath(new URL('..',import.meta.url));
|
|
11
13
|
const analyzed={status:'analyzed',selection:{versionControl:'none',modules:[],analysis:'Synthetic local project'},
|
|
12
14
|
evidence:'Synthetic source observation',noGitDecision:'explicit_user_refusal'};
|
|
@@ -48,6 +50,41 @@ function reply(message){
|
|
|
48
50
|
result:{verdict:'approved',packageDigest:message.payload.package.packageDigest,examinedPaths:message.payload.package.examinedPaths,findings:[],summary:'Synthetic independent review'}};
|
|
49
51
|
assert.fail('unexpected host call '+message.kind);
|
|
50
52
|
}
|
|
53
|
+
test('runtime preset mismatch blocks verification after restart and cannot enter through revision',{timeout:10000},async t=>{
|
|
54
|
+
const f=fixture(t),calls=[];
|
|
55
|
+
const selection={...analyzed.selection,runtimes:{available:'both',preset:'codex-codes'}};
|
|
56
|
+
const template=fs.readFileSync(path.join(root,'templates/cm-workflow.yml'),'utf8');
|
|
57
|
+
let corrected=false;
|
|
58
|
+
const respond=message=>{
|
|
59
|
+
calls.push(message.kind);
|
|
60
|
+
if(message.kind==='init_generate')return {status:'generated',documents:message.payload.targets.map(file=>({path:file,
|
|
61
|
+
content:file==='.cm-workflow.yml'?(corrected?editRuntimeDeclaration(template,file,runtimePreset('codex-codes')):template):'# Synthetic rules\n'}))};
|
|
62
|
+
if(message.kind==='init_verify')return checks('unverified');
|
|
63
|
+
return reply(message);
|
|
64
|
+
};
|
|
65
|
+
let c=await client(t,f,respond);
|
|
66
|
+
const generated=(await c.request('advance',{selection})).result;
|
|
67
|
+
assert.equal(generated.inspection.status,'blocked');
|
|
68
|
+
assert.ok(generated.inspection.issues.some(issue=>issue.code==='runtimes_preset_mismatch'));await c.close();
|
|
69
|
+
c=await client(t,f,respond);
|
|
70
|
+
assert.equal((await c.request('advance')).error.code,'host_request_failed');
|
|
71
|
+
const blocked=(await c.request('status')).result;
|
|
72
|
+
assert.equal(blocked.stage,'draft_generated'); // A rejected operation restores the persisted checkpoint.
|
|
73
|
+
assert.equal(blocked.result.inspection.status,'blocked');await c.close();
|
|
74
|
+
assert.deepEqual(calls,['init_generate']);
|
|
75
|
+
// Start a separate fixture session; a failed structural check does not authorize recovery or writes.
|
|
76
|
+
const revised=fixture(t);corrected=true;
|
|
77
|
+
c=await client(t,revised,respond);
|
|
78
|
+
const valid=(await c.request('advance',{selection})).result;
|
|
79
|
+
assert.equal(valid.inspection.status,'structurally_checked');
|
|
80
|
+
assert.equal(valid.inspection.issues.filter(issue=>issue.severity==='warning').length,2);
|
|
81
|
+
assert.equal((await c.request('advance')).result.stage,'verification_blocked');
|
|
82
|
+
const documents=valid.documents.map(document=>document.path==='.cm-workflow.yml'?{...document,content:template}:document);
|
|
83
|
+
assert.equal((await c.request('prepare_revision',{documents})).error.code,'host_request_failed');
|
|
84
|
+
assert.deepEqual((await c.request('status')).result.result.documents,valid.documents);await c.close();
|
|
85
|
+
assert.equal(fs.existsSync(path.join(f.project,'.cm-workflow.yml')),false);
|
|
86
|
+
assert.equal(fs.existsSync(path.join(revised.project,'.cm-workflow.yml')),false);
|
|
87
|
+
});
|
|
51
88
|
test('new CLI processes retain analysis, draft, blocked verification and revision; no recovered write permission',{timeout:10000},async t=>{
|
|
52
89
|
const f=fixture(t),calls=[];let verifyCount=0;
|
|
53
90
|
fs.writeFileSync(path.join(f.project,'AGENTS.md'),'# Original constraint\n');
|
package/scripts/cm-log-event.mjs
CHANGED
|
@@ -15,7 +15,7 @@ export const TERMINAL_EVENTS=new Set(['done','run_done']);
|
|
|
15
15
|
export const RESOURCE_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
16
16
|
const RESOURCE_PHASES=new Set(['acquired','released','cleanup_failed']);
|
|
17
17
|
const TEST_RUN_GUARDED_EVENTS=new Set([...TERMINAL_EVENTS,'task_done']);
|
|
18
|
-
const TEST_RUN_PHASES=new Set(['start','case_start','case_complete','case_blocked','complete','abandoned']);
|
|
18
|
+
const TEST_RUN_PHASES=new Set(['start','case_start','case_complete','case_blocked','complete','abandoned','superseded']);
|
|
19
19
|
const MODEL_USAGE_TOKEN_FIELDS=new Set(['input_tokens','output_tokens','cache_read_tokens','cache_write_tokens']);
|
|
20
20
|
const MODEL_USAGE_STATES=new Set(['observed','unavailable']);
|
|
21
21
|
const MODEL_USAGE_OUTCOMES=new Set(['success','error','blocked','cancelled']);
|
|
@@ -116,7 +116,7 @@ export function validateResourceEvent(event,phase,data){
|
|
|
116
116
|
function validateTestRunEvent(event,phase,data){
|
|
117
117
|
if(event!=='test_run'||phase===null||phase===undefined)return;
|
|
118
118
|
if(!TEST_RUN_PHASES.has(phase))
|
|
119
|
-
throw new UsageError('test_run events require phase start, case_start, case_complete, case_blocked, or
|
|
119
|
+
throw new UsageError('test_run events require phase start, case_start, case_complete, case_blocked, complete, abandoned, or superseded');
|
|
120
120
|
if(phase.startsWith('case_')&&(typeof data.case_id!=='string'||!RESOURCE_ID.test(data.case_id)))
|
|
121
121
|
throw new UsageError('test_run case events require a valid case_id');
|
|
122
122
|
}
|
|
@@ -195,6 +195,10 @@ export function unclosedResources(states){
|
|
|
195
195
|
}
|
|
196
196
|
|
|
197
197
|
function applyTestRunTransition(active,openCases,phase,caseId){
|
|
198
|
+
if(phase==='superseded'){
|
|
199
|
+
if(active||openCases.size)throw new UsageError('QA superseded requires a completed invocation');
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
198
202
|
if(phase==='start'){
|
|
199
203
|
if(active)throw new UsageError('test_run start has no preceding complete');
|
|
200
204
|
if(openCases.size)throw new UsageError('test_run state contains cases without an active run');
|
|
@@ -330,8 +334,21 @@ function validateQaAbandonment(state,event){
|
|
|
330
334
|
throw new UsageError('QA abandonment requires the matching active invocation with only PASS results and matching partial_pass_cases');
|
|
331
335
|
}
|
|
332
336
|
|
|
337
|
+
function validateQaSupersession(state,event){
|
|
338
|
+
const {start,complete}=state;
|
|
339
|
+
if(state.active||state.superseded||!start||!complete||complete.result!=='BLOCKED'||complete.failed!==0
|
|
340
|
+
||complete.blocked<=0||start.attempt>=3||event.workflow!=='cm-ai'||event.node!=='N6'
|
|
341
|
+
||event.reason!=='host_evidence_problem'||event.previous_test_run_id!==start.operation_id
|
|
342
|
+
||!Array.isArray(event.blocked_cases)||event.blocked_cases.length!==complete.blocked
|
|
343
|
+
||new Set(event.blocked_cases).size!==event.blocked_cases.length
|
|
344
|
+
||!event.blocked_cases.every(value=>typeof value==='string'&&RESOURCE_ID.test(value))
|
|
345
|
+
||!['repository_id','run_id','feature','task','package_digest','qa_decision_id','operation_id','attempt','mode','case_count']
|
|
346
|
+
.every(key=>event[key]!==undefined&&event[key]===start[key]&&event[key]===complete[key]))
|
|
347
|
+
throw new UsageError('QA superseded requires the matching completed BLOCKED invocation and blocked_cases');
|
|
348
|
+
}
|
|
349
|
+
|
|
333
350
|
function loadTestRunState(file,runId){
|
|
334
|
-
let active=false,start=null,hasNonPassResult=false,abandoned=false;
|
|
351
|
+
let active=false,start=null,complete=null,hasNonPassResult=false,abandoned=false,superseded=false;
|
|
335
352
|
const openCases=new Set(),partialPassCases=new Set();
|
|
336
353
|
for(const value of readJsonLines(file,{strict:true})){
|
|
337
354
|
if(!value||typeof value!=='object'||value.run_id!==runId||value.event!=='test_run'||value.phase===null||value.phase===undefined)continue;
|
|
@@ -341,23 +358,26 @@ function loadTestRunState(file,runId){
|
|
|
341
358
|
throw new UsageError('test_run state log contains a malformed case event');
|
|
342
359
|
if(phase==='complete'&&!active&&!openCases.size)continue;
|
|
343
360
|
if(phase==='abandoned')validateQaAbandonment({active,start,hasNonPassResult,partialPassCases},value);
|
|
361
|
+
if(phase==='superseded')validateQaSupersession({active,start,complete,superseded},value);
|
|
344
362
|
active=applyTestRunTransition(active,openCases,phase,typeof caseId==='string'?caseId:null);
|
|
345
|
-
if(phase==='start'){start=value;hasNonPassResult=false;partialPassCases.clear();abandoned=false;}
|
|
363
|
+
if(phase==='start'){start=value;complete=null;hasNonPassResult=false;partialPassCases.clear();abandoned=false;superseded=false;}
|
|
364
|
+
if(phase==='complete')complete=value;
|
|
346
365
|
if(phase==='case_complete'){
|
|
347
366
|
if(value.result==='PASS')partialPassCases.add(caseId);
|
|
348
367
|
else hasNonPassResult=true;
|
|
349
368
|
}
|
|
350
369
|
if(phase==='case_blocked')hasNonPassResult=true;
|
|
351
370
|
if(phase==='abandoned')abandoned=true;
|
|
371
|
+
if(phase==='superseded')superseded=true;
|
|
352
372
|
}
|
|
353
|
-
return {active,openCases,start,hasNonPassResult,partialPassCases,abandoned};
|
|
373
|
+
return {active,openCases,start,complete,hasNonPassResult,partialPassCases,abandoned,superseded};
|
|
354
374
|
}
|
|
355
375
|
|
|
356
376
|
// Read-only reuse of the writer's existing resource/test lifecycle guards by
|
|
357
377
|
// the batch coordinator. No new terminal event or task completion authority.
|
|
358
378
|
export function inspectRunClosure(file,runId){
|
|
359
379
|
const resources=unclosedResources(loadResourceStates(file,runId)),tests=loadTestRunState(file,runId);
|
|
360
|
-
return {closed:resources.length===0&&!tests.active&&!tests.abandoned&&tests.openCases.size===0};
|
|
380
|
+
return {closed:resources.length===0&&!tests.active&&!tests.abandoned&&!tests.superseded&&tests.openCases.size===0};
|
|
361
381
|
}
|
|
362
382
|
|
|
363
383
|
function compactJson(value){return `${JSON.stringify(value)}\n`;}
|
|
@@ -475,7 +495,7 @@ export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),u
|
|
|
475
495
|
if(existing===null&&((event.event==='test_run'&&event.phase!==undefined)||TEST_RUN_GUARDED_EVENTS.has(event.event)))try{
|
|
476
496
|
testRun=loadTestRunState(authoritativeLog,built.runId);
|
|
477
497
|
}catch(error){throw new UsageError(`test_run state cannot be verified: ${error.name}`);}
|
|
478
|
-
if(existing===null&&TEST_RUN_GUARDED_EVENTS.has(event.event)&&(testRun.active||testRun.abandoned||testRun.openCases.size)){
|
|
498
|
+
if(existing===null&&TEST_RUN_GUARDED_EVENTS.has(event.event)&&(testRun.active||testRun.abandoned||testRun.superseded||testRun.openCases.size)){
|
|
479
499
|
const detail=[];
|
|
480
500
|
if(testRun.active)detail.push('active invocation');
|
|
481
501
|
if(testRun.openCases.size)detail.push(`open cases: ${[...testRun.openCases].sort().join(', ')}`);
|
|
@@ -486,6 +506,7 @@ export function writeLogEvent(rawInput,{environment=process.env,now=new Date(),u
|
|
|
486
506
|
if(unclosedResources(loadResourceStates(authoritativeLog,built.runId)).length)
|
|
487
507
|
throw new UsageError('QA abandonment blocked by unclosed resources');
|
|
488
508
|
}
|
|
509
|
+
if(existing===null&&event.event==='test_run'&&event.phase==='superseded')validateQaSupersession(testRun,event);
|
|
489
510
|
if(existing===null&&event.event==='test_run'&&event.phase!==undefined)
|
|
490
511
|
applyTestRunTransition(testRun.active,testRun.openCases,event.phase,event.case_id??null);
|
|
491
512
|
|
|
@@ -14,6 +14,7 @@ import {inspectPrdDraft} from '../runtime/js/cm-prd/draft.mjs';
|
|
|
14
14
|
import {runPrdHostReview} from '../runtime/js/cm-prd/review-host.mjs';
|
|
15
15
|
import {inspectPrdFindings} from '../runtime/js/cm-prd/review-findings.mjs';
|
|
16
16
|
import {recordPrdHostDisposition} from '../runtime/js/cm-prd/review-disposition.mjs';
|
|
17
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
17
18
|
const riskSignals=high=>({greenfieldAdr:false,architectureOrDataFlow:high,newRuntimeDependencyOrToolchain:false,
|
|
18
19
|
publicContractDataOrSecurity:false,fiveOrMoreFunctions:false});
|
|
19
20
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
@@ -116,7 +117,7 @@ test('late design response cannot erase an existing draft or reset self-check ro
|
|
|
116
117
|
assert.equal(host.status().selfCheckRound,1);assert.deepEqual(host.status().draft,original);
|
|
117
118
|
assert.equal(host.status().designDraft,null);
|
|
118
119
|
});
|
|
119
|
-
for(const mode of ['saved','rewrite','drift','late-risk','promote','saved-promote'])test(`actual CLI disposed design to tasks: ${mode}`, {timeout:
|
|
120
|
+
for(const mode of ['saved','rewrite','drift','late-risk','promote','saved-promote'])test(`actual CLI disposed design to tasks: ${mode}`, {timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
120
121
|
const promotes=['promote','saved-promote'].includes(mode),succeeds=['saved','late-risk','promote','saved-promote'].includes(mode);
|
|
121
122
|
let originalDigest;
|
|
122
123
|
const dir=fixture(t);fs.mkdirSync(path.join(dir,'mirror'));
|
|
@@ -9,8 +9,9 @@ import {createInterface} from 'node:readline';
|
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
10
|
import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
|
|
11
11
|
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
12
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
12
13
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
13
|
-
for(const mode of ['codex','claude','cancel','cases','materials','draft','self-check'])test(`PRD actual CLI and original log adapter: ${mode}`,{timeout:
|
|
14
|
+
for(const mode of ['codex','claude','cancel','cases','materials','draft','self-check'])test(`PRD actual CLI and original log adapter: ${mode}`,{timeout:FIXTURE_TIMEOUT_MS},async()=>{
|
|
14
15
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-host-')));
|
|
15
16
|
for(const name of ['docs','mirror'])fs.mkdirSync(path.join(dir,name));
|
|
16
17
|
fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic requirement');
|
|
@@ -178,7 +179,7 @@ for(const mode of ['codex','claude','cancel','cases','materials','draft','self-c
|
|
|
178
179
|
}finally{child.kill();lines.close();await closed;fs.rmSync(dir,{recursive:true,force:true});}
|
|
179
180
|
});
|
|
180
181
|
|
|
181
|
-
for(const known of [true,false])test(`summary without draft uses only current durable session scope: ${known}`,{timeout:
|
|
182
|
+
for(const known of [true,false])test(`summary without draft uses only current durable session scope: ${known}`,{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
182
183
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-summary-session-')));
|
|
183
184
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
184
185
|
for(const name of ['docs','mirror','1.history','2.current'])fs.mkdirSync(path.join(dir,name));
|
|
@@ -9,6 +9,7 @@ import {createInterface} from 'node:readline';
|
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
10
|
import {openPrdSession} from '../runtime/js/cm-prd/session.mjs';
|
|
11
11
|
import {createCmPrdAnalysis} from '../runtime/js/cm-prd/analysis.mjs';
|
|
12
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
12
13
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
13
14
|
const sessionId='prd-recovery-fixture';
|
|
14
15
|
async function fixture(t,{ready=false,change=false}={}){
|
|
@@ -94,7 +95,7 @@ test('unknown summary exposes session reasons, abandon restores before and permi
|
|
|
94
95
|
await c.close();await retry;
|
|
95
96
|
});
|
|
96
97
|
|
|
97
|
-
for(const mode of ['summary','analysis','change'])test(`cancel clears pending ${mode} and stays terminal across restart`,{timeout:
|
|
98
|
+
for(const mode of ['summary','analysis','change'])test(`cancel clears pending ${mode} and stays terminal across restart`,{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
98
99
|
const f=await fixture(t,{ready:mode==='analysis',change:mode==='change'});let c=await client(t,f);
|
|
99
100
|
const pending=c.request(mode==='summary'?'prepare_summary':'start',mode==='summary'?{}:{text:'Analyze'});
|
|
100
101
|
const call=await c.wait(m=>m.type==='host_request');
|
|
@@ -109,7 +110,7 @@ for(const mode of ['summary','analysis','change'])test(`cancel clears pending ${
|
|
|
109
110
|
assert.equal(f.state().active,null);await c.close();
|
|
110
111
|
});
|
|
111
112
|
|
|
112
|
-
test('old cancelled checkpoint with active is normalized without replay', {timeout:
|
|
113
|
+
test('old cancelled checkpoint with active is normalized without replay', {timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
113
114
|
const f=await fixture(t);await unknownSummary(t,f);
|
|
114
115
|
const session=f.open(),checkpoint=session.state.checkpoint;
|
|
115
116
|
session.checkpoint({...checkpoint,analysis:{...checkpoint.analysis,stage:'cancelled'}});session.close();
|
|
@@ -127,7 +128,7 @@ async function seedCalls(f,calls,request={requestId:'original',operation:'prepar
|
|
|
127
128
|
}
|
|
128
129
|
}finally{session.close();}
|
|
129
130
|
}
|
|
130
|
-
for(const mixed of [false,true])test(`abandon rejects any prd_review call in operation: mixed=${mixed}`,{timeout:
|
|
131
|
+
for(const mixed of [false,true])test(`abandon rejects any prd_review call in operation: mixed=${mixed}`,{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
131
132
|
const f=await fixture(t);await seedCalls(f,mixed?[{kind:'prd_review',result:{}},{kind:'prd_self_check'}]:[{kind:'prd_review'}]);
|
|
132
133
|
const before=f.state(),target=before.active.calls.at(-1),c=await client(t,f);
|
|
133
134
|
const resolution={callId:target.callId,requestDigest:target.requestDigest,abandon:true,evidence:'Synthetic discard request'};
|
|
@@ -135,7 +136,7 @@ for(const mixed of [false,true])test(`abandon rejects any prd_review call in ope
|
|
|
135
136
|
assert.equal(result.recovery.calls.length,before.active.calls.length);assert.deepEqual(f.state(),before);await c.close();
|
|
136
137
|
});
|
|
137
138
|
|
|
138
|
-
test('turn and replay errors are visible while unrelated errors remain redacted', {timeout:
|
|
139
|
+
test('turn and replay errors are visible while unrelated errors remain redacted', {timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
139
140
|
const f=await fixture(t,{ready:true});let c=await client(t,f);
|
|
140
141
|
assert.equal(blocked(await c.request('advance',{text:'Too early'}),'prd_turn_not_ready').recovery,null);
|
|
141
142
|
assert.equal((await c.request('save_draft')).error.code,'host_request_failed');await c.close();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {QA_ENVIRONMENT_CARRIERS,QA_ENVIRONMENT_SCOPES,isQaEnvironmentCarrier} from '../runtime/js/cm-ai/qa-environment.mjs';
|
|
4
|
+
|
|
5
|
+
test('carrier table covers every cm-prd delivery form plus backend, CLI and library projects',()=>{
|
|
6
|
+
// cm-prd confirms Web / iOS / Android / 小程序 / 桌面 / 多端 with the user, and
|
|
7
|
+
// separately recognises projects with no deployment form (local tools, libraries).
|
|
8
|
+
assert.deepEqual(Object.keys(QA_ENVIRONMENT_CARRIERS).sort(),
|
|
9
|
+
['app','desktop','library','miniprogram','service','web']);
|
|
10
|
+
for(const [kind,carrier] of [['web','browser'],['app','ios-simulator'],['app','android-emulator'],
|
|
11
|
+
['app','device'],['miniprogram','wechat-devtools'],['miniprogram','device'],
|
|
12
|
+
['desktop','app-window'],['service','cli'],['service','http-api'],['library','none']]){
|
|
13
|
+
assert.equal(isQaEnvironmentCarrier(kind,carrier),true,`${kind}/${carrier}`);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
test('carriers stay bound to their own kind and unknown values are rejected',()=>{
|
|
18
|
+
for(const [kind,carrier] of [['service','browser'],['library','cli'],['desktop','device'],
|
|
19
|
+
['web','app-window'],['backend','cli'],['service','shell'],['','']]){
|
|
20
|
+
assert.equal(isQaEnvironmentCarrier(kind,carrier),false,`${kind}/${carrier}`);
|
|
21
|
+
}
|
|
22
|
+
assert.equal(isQaEnvironmentCarrier('__proto__','cli'),false);
|
|
23
|
+
assert.deepEqual([...QA_ENVIRONMENT_SCOPES],['local','test']);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('the shared table is frozen so one consumer cannot mutate it for the others',()=>{
|
|
27
|
+
assert.throws(()=>{QA_ENVIRONMENT_CARRIERS.service=['anything'];},TypeError);
|
|
28
|
+
assert.throws(()=>{QA_ENVIRONMENT_CARRIERS.web.push('app-window');},TypeError);
|
|
29
|
+
assert.equal(isQaEnvironmentCarrier('web','app-window'),false);
|
|
30
|
+
});
|
package/scripts/cm-security.mjs
CHANGED
|
@@ -3,27 +3,35 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import {fileURLToPath} from 'node:url';
|
|
5
5
|
import {scan} from '../runtime/js/cm-security/scan.mjs';
|
|
6
|
+
import {finalize} from '../runtime/js/cm-security/finalize.mjs';
|
|
6
7
|
|
|
7
8
|
export function main(argv){
|
|
8
9
|
let project=process.cwd();const options={};const seen=new Set();
|
|
9
10
|
for(let i=0;i<argv.length;i++){
|
|
10
11
|
const key=argv[i];
|
|
11
|
-
if(key==='--help')return {help:'cm-security.mjs [--project PATH] [--all] [--inventory] [--semgrep-rules EXTERNAL_FILE] [--osv-db EXTERNAL_CACHE_DIR]'};
|
|
12
|
+
if(key==='--help')return {help:'cm-security.mjs [--project PATH] [--all] [--inventory] [--semgrep-rules EXTERNAL_FILE] [--osv-db EXTERNAL_CACHE_DIR] | [--project PATH] --finalize --scan EXTERNAL_JSON --review EXTERNAL_JSON'};
|
|
12
13
|
if(seen.has(key))throw new Error('duplicate_argument');seen.add(key);
|
|
13
14
|
if(key==='--all')options.all=true;
|
|
14
15
|
else if(key==='--inventory')options.inventoryOnly=true;
|
|
15
|
-
else if(
|
|
16
|
+
else if(key==='--finalize')options.finalize=true;
|
|
17
|
+
else if(['--project','--semgrep-rules','--osv-db','--scan','--review'].includes(key)){
|
|
16
18
|
const value=argv[++i];if(!value||value.startsWith('--'))throw new Error('argument_value_required');
|
|
17
19
|
if(key==='--project')project=value;
|
|
18
|
-
else options[
|
|
20
|
+
else options[({'--semgrep-rules':'semgrepRules','--osv-db':'osvDb','--scan':'scanFile','--review':'reviewFile'})[key]]=value;
|
|
19
21
|
}else throw new Error('unknown_argument');
|
|
20
22
|
}
|
|
23
|
+
if(options.finalize){
|
|
24
|
+
if(options.all||options.inventoryOnly||options.semgrepRules||options.osvDb)throw new Error('finalize_mode_conflict');
|
|
25
|
+
if(!options.scanFile||!options.reviewFile)throw new Error('finalize_inputs_required');
|
|
26
|
+
return finalize(fs.realpathSync(project),options);
|
|
27
|
+
}
|
|
28
|
+
if(options.scanFile||options.reviewFile)throw new Error('finalize_mode_required');
|
|
21
29
|
return scan(fs.realpathSync(project),options);
|
|
22
30
|
}
|
|
23
31
|
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){
|
|
24
32
|
try{
|
|
25
33
|
const result=main(process.argv.slice(2));console.log(JSON.stringify(result,null,2));
|
|
26
|
-
process.exitCode=result.help?0:result.result==='BLOCKED'?2:result.findings?.length?1:result.result==='NO_CHANGES'?0:3;
|
|
34
|
+
process.exitCode=result.help?0:result.result==='BLOCKED'?2:(result.findingsCount||result.findings?.length)?1:result.result==='NO_CHANGES'?0:3;
|
|
27
35
|
}catch(error){
|
|
28
36
|
// Do not echo paths, input values, source snippets or scanner stderr from exceptions.
|
|
29
37
|
console.log(JSON.stringify({result:'BLOCKED',coverage:'PARTIAL',reason:/^[a-z0-9_]+$/.test(error.message)?error.message:'scan_failed'}));
|