@aibyzero/cm-workflow 0.19.0 → 0.20.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/AGENTS.md +8 -0
- package/CHANGELOG.md +8 -0
- package/README.md +8 -1
- package/VERSION +1 -1
- package/docs/architecture.md +3 -0
- package/docs/cm-acceptance-completion.md +185 -0
- package/docs/installation.md +1 -1
- package/package.json +1 -1
- package/runtime/js/autonomy.mjs +159 -3
- package/runtime/js/check-coverage.mjs +130 -0
- package/runtime/js/cm-ai/acceptance-contract.mjs +252 -0
- package/runtime/js/cm-ai/claude-developer-proposal.schema.json +18 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +14 -6
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +10 -6
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +8 -3
- package/runtime/js/cm-ai/codex-developer-basic-output.schema.json +1 -1
- package/runtime/js/cm-ai/codex-developer-output.schema.json +1 -1
- package/runtime/js/cm-ai/completion-summary.mjs +187 -0
- package/runtime/js/cm-ai/control-policy.mjs +3 -1
- package/runtime/js/cm-ai/delivery-evidence.mjs +173 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +4 -0
- package/runtime/js/cm-ai/drive-core.mjs +6 -2
- package/runtime/js/cm-ai/durable-runner-state.mjs +2 -2
- package/runtime/js/cm-ai/gate-bridge.mjs +13 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +26 -14
- package/runtime/js/cm-ai/host-progress.mjs +2 -1
- package/runtime/js/cm-ai/log-rows.mjs +3 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +110 -4
- package/runtime/js/cm-ai/requirement-evidence.mjs +4 -2
- package/runtime/js/cm-ai/review-package.mjs +2 -2
- package/runtime/js/cm-ai/specification-material.mjs +57 -12
- package/runtime/js/cm-ai/task-runner.mjs +38 -13
- package/runtime/js/cm-ai/verification-auto.mjs +6 -4
- package/runtime/js/cm-prd/acceptance-preview.mjs +203 -0
- package/runtime/js/cm-prd/change.mjs +17 -1
- package/runtime/js/cm-prd/summary.mjs +5 -0
- package/runtime/js/node-test-selection.mjs +38 -0
- package/runtime/js/run-analysis.mjs +153 -0
- package/runtime/js/session-boundary.mjs +17 -5
- package/runtime/js/session-handoff.mjs +5 -2
- package/scripts/cm-acceptance-preview.mjs +26 -0
- package/scripts/cm-acceptance-preview.test.mjs +156 -0
- package/scripts/cm-ai-acceptance-contract.test.mjs +185 -0
- package/scripts/cm-ai-admission.test.mjs +5 -2
- package/scripts/cm-ai-blockage.test.mjs +120 -0
- package/scripts/cm-ai-checklist-coverage.test.mjs +5 -2
- package/scripts/cm-ai-completion-summary.test.mjs +154 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +8 -2
- package/scripts/cm-ai-progress.test.mjs +7 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +55 -4
- package/scripts/cm-ai-run.test.mjs +23 -1
- package/scripts/cm-ai-spec-rebind.test.mjs +51 -15
- package/scripts/cm-ai-verification-auto.test.mjs +33 -8
- package/scripts/cm-ai-verification-gate.test.mjs +1 -1
- package/scripts/cm-autonomy-acceptance.test.mjs +212 -0
- package/scripts/cm-autonomy-review-r1.test.mjs +93 -0
- package/scripts/cm-autonomy.mjs +3 -1
- package/scripts/cm-autonomy.test.mjs +10 -9
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-delivery-evidence.mjs +59 -0
- package/scripts/cm-delivery-evidence.test.mjs +177 -0
- package/scripts/cm-drive-liveness.test.mjs +6 -0
- package/scripts/cm-driver-light-import.test.mjs +32 -0
- package/scripts/cm-mandatory-check-coverage.test.mjs +82 -0
- package/scripts/cm-node-test-selection.test.mjs +108 -0
- package/scripts/cm-notify-read-drift.test.mjs +6 -3
- package/scripts/cm-prd-completion.test.mjs +12 -0
- package/scripts/cm-prd-host.mjs +3 -1
- package/scripts/cm-prd-host.test.mjs +18 -1
- package/scripts/cm-prd-summary.test.mjs +19 -4
- package/scripts/cm-review-inventory.test.mjs +21 -6
- package/scripts/cm-run-analysis.mjs +21 -0
- package/scripts/cm-run-analysis.test.mjs +120 -0
- package/scripts/cm-start-check.mjs +60 -53
- package/scripts/cm-start-check.test.mjs +76 -1
- package/scripts/cm-usage-report.py +8 -3
- package/scripts/cm019-r1-contract.test.mjs +137 -0
- package/scripts/cm019-review-gates.test.mjs +97 -0
- package/skills/cm-ai/references/js-host.md +5 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -0
|
@@ -71,14 +71,15 @@ test('under autonomy a driver stop waits and a finished unit is not paged',t=>{
|
|
|
71
71
|
assert.equal(notice(limit).delivery,'later');assert.equal(notice(done),null);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
test('standing approval
|
|
75
|
-
const cases=list=>JSON.stringify({schemaVersion:1,feature:'login',cases:list});
|
|
76
|
-
const user={id:'TC-001',origin:'user',title:'login works'
|
|
77
|
-
|
|
74
|
+
test('standing approval preserves existing obligations while allowing scope expansion and optional generated cases',()=>{
|
|
75
|
+
const cases=list=>JSON.stringify({schemaVersion:'1.0',feature:'login',cases:list});
|
|
76
|
+
const user={id:'TC-001',origin:'user',kind:'logic',blocking:true,title:'login works',acIds:['AC-001'],taskIds:['T-001'],
|
|
77
|
+
preconditions:[],steps:['sign in'],expected:['signed in'],cleanup:[]},generated={...user,id:'TC-002',origin:'generated',blocking:false,title:'g'};
|
|
78
|
+
const before={directories:['1.login'],files:{'1.login/requirements.md':'R','1.login/design.md':'D','1.login/tasks.md':'- [ ] T-001: implement login\n - 范围: `login.js`\n',
|
|
78
79
|
'1.login/test-cases.json':cases([user,generated])}};
|
|
79
|
-
const proposal=(files={},over={})=>({changedUserCases:[],removed:[],...over,files:{...before.files,'1.login/tasks.md':'
|
|
80
|
+
const proposal=(files={},over={})=>({changedUserCases:[],removed:[],...over,files:{...before.files,'1.login/tasks.md':'- [ ] T-001: implement login\n - 范围: `login.js`, `helper.js`\n',...files}});
|
|
80
81
|
assert.equal(standingProposalProblem(before,proposal()),null);
|
|
81
|
-
assert.equal(standingProposalProblem(before,proposal({'1.login/
|
|
82
|
+
assert.equal(standingProposalProblem(before,proposal({'1.login/test-cases.json':cases([user])})),null);
|
|
82
83
|
const refused=[
|
|
83
84
|
[proposal({'1.login/requirements.md':'R2'}),'提案改了需求'],
|
|
84
85
|
[proposal({},{changedUserCases:[{id:'TC-001'}]}),'提案删除或减弱了用户用例'],
|
|
@@ -100,14 +101,14 @@ test('standing approval covers design, tasks and generated cases, never requirem
|
|
|
100
101
|
test('check-proposal judges against the specs on disk and reopen counts to the limit',t=>{
|
|
101
102
|
const h=home(t),specs=path.join(h.dir,'specs'),feature=path.join(specs,'1.login');
|
|
102
103
|
fs.mkdirSync(feature,{recursive:true});
|
|
103
|
-
for(const [name,content] of [['requirements.md','R'],['design.md','D'],['tasks.md','T']])fs.writeFileSync(path.join(feature,name),content);
|
|
104
|
+
for(const [name,content] of [['requirements.md','R'],['design.md','D'],['tasks.md','- [ ] T-001: login\n - 范围: `login.js`\n']])fs.writeFileSync(path.join(feature,name),content);
|
|
104
105
|
const file=path.join(h.dir,'proposal.json'),check=files=>{
|
|
105
106
|
fs.writeFileSync(file,JSON.stringify({result:{proposal:{changedUserCases:[],removed:[],files}}}));
|
|
106
107
|
return h.run('check-proposal','--specs-dir',specs,'--proposal',file);
|
|
107
108
|
};
|
|
108
|
-
const ok=check({'1.login/requirements.md':'R','1.login/design.md':'D','1.login/tasks.md':'
|
|
109
|
+
const ok=check({'1.login/requirements.md':'R','1.login/design.md':'D','1.login/tasks.md':'- [ ] T-001: login\n - 范围: `login.js`, `helper.js`\n'});
|
|
109
110
|
assert.equal(ok.code,0);assert.match(ok.out,/可以按常设授权自行批准/);
|
|
110
|
-
const no=check({'1.login/requirements.md':'R2','1.login/design.md':'D','1.login/tasks.md':'
|
|
111
|
+
const no=check({'1.login/requirements.md':'R2','1.login/design.md':'D','1.login/tasks.md':'- [ ] T-001: login\n - 范围: `login.js`, `helper.js`\n'});
|
|
111
112
|
assert.equal(no.code,1);assert.match(no.out,/提案改了需求.*不要发送 decision/);
|
|
112
113
|
assert.equal(h.run('check-proposal','--specs-dir',specs,'--proposal',path.join(h.dir,'missing.json')).code,1);
|
|
113
114
|
const reopen=()=>h.run('reopen','--project',h.dir,'--task','1.login/T-004');
|
|
@@ -284,7 +284,7 @@ for module in \
|
|
|
284
284
|
durable-runner-state.mjs effect-contract.mjs execution-store.mjs gate-bridge.mjs \
|
|
285
285
|
host.mjs host-session.mjs diagnostic-reason.mjs index.mjs provider-review-observation.mjs review-package.mjs \
|
|
286
286
|
review-result.schema.json review-runner.mjs task-commit-codec.mjs task-commit.mjs \
|
|
287
|
-
task-owner.mjs task-runner.mjs worker-codex.mjs operator-guidance.mjs; do
|
|
287
|
+
task-owner.mjs task-runner.mjs worker-codex.mjs operator-guidance.mjs completion-summary.mjs delivery-evidence.mjs; do
|
|
288
288
|
require_file "runtime/js/cm-ai/$module"
|
|
289
289
|
done
|
|
290
290
|
# completion_rework is a paired producer/consumer contract, including transport.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import {pathToFileURL} from 'node:url';
|
|
4
|
+
import {createInterface} from 'node:readline/promises';
|
|
5
|
+
import {need} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
6
|
+
import {previewDelivery,recordDelivery,deliveryCandidate,deliveryProjection,deliveryLines,readDeliveryRecords} from '../runtime/js/cm-ai/delivery-evidence.mjs';
|
|
7
|
+
|
|
8
|
+
const usage=`Usage: cm-delivery-evidence.mjs preview|record|status|history --specs DIR
|
|
9
|
+
preview/record/status: --repository ID --run ID --feature NAME --artifact FILE
|
|
10
|
+
preview/record: --kind acceptance|deployment --actor NAME --environment NAME --note TEXT --report FILE
|
|
11
|
+
acceptance: --outcome accepted|rejected|revoked
|
|
12
|
+
deployment: --execution succeeded|failed --verification passed|failed|unknown [--verification-report FILE]
|
|
13
|
+
--json is allowed for read-only commands. record always requires an interactive terminal.
|
|
14
|
+
Records are local human declarations, not authenticated identity or remote verification.`;
|
|
15
|
+
export async function deliveryMain(argv,{input=process.stdin,output=process.stdout,error=process.stderr}={}){
|
|
16
|
+
try{
|
|
17
|
+
if(argv.length===1&&argv[0]==='--help'){output.write(usage+'\n');return 0;}
|
|
18
|
+
const operation=argv[0];need(['preview','record','status','history'].includes(operation),'delivery_invalid_arguments');
|
|
19
|
+
const values={},flags=new Set(['specs','repository','run','feature','artifact','kind','actor','environment','note','report','outcome','execution','verification','verification-report']);
|
|
20
|
+
let asJson=false;
|
|
21
|
+
for(let i=1;i<argv.length;i++){
|
|
22
|
+
if(argv[i]==='--json'){need(!asJson,'delivery_invalid_arguments');asJson=true;continue;}
|
|
23
|
+
const name=argv[i]?.slice(2);need(argv[i]?.startsWith('--')&&flags.has(name)&&!Object.hasOwn(values,name)
|
|
24
|
+
&&typeof argv[i+1]==='string'&&!argv[i+1].startsWith('--'),'delivery_invalid_arguments');values[name]=argv[++i];
|
|
25
|
+
}
|
|
26
|
+
need(typeof values.specs==='string','delivery_invalid_arguments');
|
|
27
|
+
const specsDir=path.resolve(values.specs);
|
|
28
|
+
const needed=operation==='history'?['specs']:['specs','repository','run','feature','artifact'];
|
|
29
|
+
if(['preview','record'].includes(operation))needed.push('kind','actor','environment','note','report',
|
|
30
|
+
...(values.kind==='acceptance'?['outcome']:['execution','verification']));
|
|
31
|
+
const allowed=new Set([...needed,...(values.kind==='deployment'&&['preview','record'].includes(operation)?['verification-report']:[])]);
|
|
32
|
+
need(needed.every(key=>Object.hasOwn(values,key))&&Object.keys(values).every(key=>allowed.has(key)),'delivery_invalid_arguments');
|
|
33
|
+
if(operation==='record')need(!asJson&&input.isTTY===true&&output.isTTY===true,'delivery_interactive_terminal_required');
|
|
34
|
+
let value;
|
|
35
|
+
if(operation==='history')value=readDeliveryRecords(specsDir);
|
|
36
|
+
else {
|
|
37
|
+
const options={specsDir,repositoryId:values.repository,runId:values.run,feature:values.feature,artifact:path.resolve(values.artifact)};
|
|
38
|
+
if(operation==='status'){
|
|
39
|
+
const candidate=deliveryCandidate(options);
|
|
40
|
+
value=deliveryProjection({...options,identity:candidate.identity,packageDigest:candidate.packageDigest,specificationDigest:candidate.specificationDigest,artifactSha256:candidate.artifact.sha256});
|
|
41
|
+
}else{
|
|
42
|
+
Object.assign(options,{kind:values.kind,statement:{actor:values.actor,environment:values.environment,note:values.note,
|
|
43
|
+
...(values.kind==='acceptance'?{outcome:values.outcome}:{execution:values.execution,verification:values.verification})},
|
|
44
|
+
report:path.resolve(values.report),verificationReport:values['verification-report']?path.resolve(values['verification-report']):null});
|
|
45
|
+
if(operation==='preview')value=previewDelivery(options);
|
|
46
|
+
else value=await recordDelivery(options,{confirm:async(preview,phrase)=>{
|
|
47
|
+
output.write(JSON.stringify(preview,null,2)+'\n此操作仅记录上述声明,不执行部署,也不证明声明者身份。\n');
|
|
48
|
+
const rl=createInterface({input,output});
|
|
49
|
+
try{return await rl.question(`请由验收/部署负责人核对后输入完整确认串:\n${phrase}\n> `);}finally{rl.close();}
|
|
50
|
+
}});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if(operation==='status'&&!asJson)output.write(deliveryLines(value).join('\n')+'\n');
|
|
54
|
+
else output.write(JSON.stringify(value,null,asJson?0:2)+'\n');
|
|
55
|
+
return 0;
|
|
56
|
+
}catch(e){const code=typeof e?.code==='string'&&/^[a-z][a-z0-9_]{0,63}$/.test(e.code)?e.code:'delivery_evidence_unavailable';
|
|
57
|
+
error.write(JSON.stringify({error:{code}})+'\n');return 2;}
|
|
58
|
+
}
|
|
59
|
+
if(process.argv[1]&&import.meta.url===pathToFileURL(path.resolve(process.argv[1])).href)process.exitCode=await deliveryMain(process.argv.slice(2));
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
10
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
11
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
12
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
13
|
+
import {previewDelivery,recordDelivery,deliveryCandidate,deliveryProjection,deliveryLines,readDeliveryRecords,deliveryFile} from '../runtime/js/cm-ai/delivery-evidence.mjs';
|
|
14
|
+
import {completionSummary,completionLines} from '../runtime/js/cm-ai/completion-summary.mjs';
|
|
15
|
+
import {deliveryMain} from './cm-delivery-evidence.mjs';
|
|
16
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
17
|
+
import {PassThrough,Writable} from 'node:stream';
|
|
18
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-delivery-fixture-')));
|
|
19
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
20
|
+
process.env.CM_WORKFLOW_HOME=path.join(root,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(root,'logs');
|
|
21
|
+
after(()=>{for(const [k,v] of Object.entries(saved))if(v===undefined)delete process.env[k];else process.env[k]=v;fs.rmSync(root,{recursive:true,force:true});});
|
|
22
|
+
const identity={repositoryId:'delivery-fixture',runId:'delivery-run',taskId:'T-001',attempt:1},feature='1.demo';
|
|
23
|
+
const cli=fileURLToPath(new URL('./cm-delivery-evidence.mjs',import.meta.url));
|
|
24
|
+
async function fixture(){
|
|
25
|
+
const local=fs.mkdtempSync(path.join(root,'project-')),specsDir=path.join(local,'specs'),codeProject=path.join(local,'code');
|
|
26
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
27
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'export const a=1;\n');fs.writeFileSync(path.join(codeProject,'requirements.md'),'fixture\n');
|
|
28
|
+
for(const [name,body] of [['requirements.md','# R\n'],['design.md','# D\n'],['tasks.md','- [ ] T-001: fixture\n- [ ] T-002: remaining\n']])fs.writeFileSync(path.join(specsDir,feature,name),body);
|
|
29
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
30
|
+
const definition={version:1,codeProject,specsDir,feature,identity,scope:['a.mjs'],requirements:['requirements.md']};
|
|
31
|
+
const execution={configuration:{kind:'synthetic-host-v1'},timeoutMs:4000,excludedContexts:['control'],
|
|
32
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:createCodexDeveloperRun({requestedModel:'fixture',worker:async()=>{
|
|
33
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'export const a=2;\n');
|
|
34
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
35
|
+
check:createHostCheck({cwd:codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
36
|
+
verificationGate:async request=>request.acceptanceContract?{satisfied:true,items:request.acceptanceContract.obligations.map(item=>({...item,satisfied:true,evidence:'Synthetic fixture verified'}))}:{satisfied:true},
|
|
37
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,contexts:['review1','review2'],run:(request,{onEvent})=>{
|
|
38
|
+
onEvent({event:'thread.started',provider_thread:'independent-fixture'});onEvent({event:'turn.started',item_type:null});
|
|
39
|
+
onEvent({event:'item.completed',item_type:'agent_message'});onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
40
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic independent review'}};
|
|
41
|
+
}}],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']}};
|
|
42
|
+
let opened=await openControlRun(definition,'create',execution);
|
|
43
|
+
const ask=()=>opened.host.handle({version:1,operation:'advance',requestId:'advance',identity});
|
|
44
|
+
try{assert.equal((await opened.host.handle({version:1,operation:'start',requestId:'start',identity})).state,'awaiting_review');}finally{opened.close();}
|
|
45
|
+
opened=await openControlRun(definition,'resume',execution,{decision:{status:'approved'}});let result;
|
|
46
|
+
try{result=await ask();assert.equal(result.state,'fixture_completed',JSON.stringify(result));}finally{opened.close();}
|
|
47
|
+
const artifact=path.join(local,'build.txt'),report=path.join(local,'owner-report.txt'),verificationReport=path.join(local,'deployed-check.txt');
|
|
48
|
+
fs.writeFileSync(artifact,'build bytes');fs.writeFileSync(report,'human observed flow');fs.writeFileSync(verificationReport,'post deploy check');
|
|
49
|
+
const options={specsDir,repositoryId:identity.repositoryId,runId:identity.runId,feature,artifact,kind:'acceptance',
|
|
50
|
+
statement:{actor:'fixture-owner',environment:'staging',outcome:'accepted',note:'fixture manual declaration'},report};
|
|
51
|
+
const projection=()=>{const candidate=deliveryCandidate(options);return deliveryProjection({...options,identity,packageDigest:candidate.packageDigest,specificationDigest:candidate.specificationDigest});};
|
|
52
|
+
return {local,specsDir,codeProject,options,verificationReport,result,projection};
|
|
53
|
+
}
|
|
54
|
+
const accept={confirm:async(_preview,phrase)=>phrase};
|
|
55
|
+
|
|
56
|
+
test('real completed owner: preview is read-only, explicit declaration is bound and cannot finish a feature',async()=>{
|
|
57
|
+
const f=await fixture(),journal=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json'),bytes=fs.readFileSync(journal),mtime=fs.statSync(journal).mtimeMs;
|
|
58
|
+
const preview=previewDelivery(f.options);assert.equal(preview.candidate.packageDigest,f.result.packageDigest);
|
|
59
|
+
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.delivery')),false);
|
|
60
|
+
assert.equal(f.projection().productAcceptance.status,'unknown');
|
|
61
|
+
await assert.rejects(recordDelivery(f.options),{code:'delivery_confirmation_required'});
|
|
62
|
+
await assert.rejects(recordDelivery(f.options,{confirm:async()=> 'yes'}),{code:'delivery_confirmation_refused'});
|
|
63
|
+
const record=await recordDelivery(f.options,accept);assert.equal(record.sequence,1);assert.equal(record.provenance,'interactive-terminal-declaration');
|
|
64
|
+
assert.equal(readDeliveryRecords(f.specsDir).length,1);assert.equal(f.projection().productAcceptance.status,'recorded');
|
|
65
|
+
const summary=completionSummary({specsDir:f.specsDir,feature,result:f.result});
|
|
66
|
+
assert.equal(summary.productAcceptance.status,'recorded');assert.notEqual(summary.feature.status,'passed');assert.notEqual(summary.project.status,'completed');
|
|
67
|
+
assert.match(completionLines(summary).at(-1),/staging \[.*\] 声明已记录(accepted)/);
|
|
68
|
+
assert.deepEqual(fs.readFileSync(journal),bytes);assert.equal(fs.statSync(journal).mtimeMs,mtime);
|
|
69
|
+
const rejected=await recordDelivery({...f.options,statement:{...f.options.statement,outcome:'rejected'}},accept);
|
|
70
|
+
assert.equal(rejected.previousDigest,record.recordDigest);assert.equal(readDeliveryRecords(f.specsDir).length,2);
|
|
71
|
+
assert.equal(f.projection().productAcceptance.environments[0].statement.outcome,'rejected');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('confirmation rechecks artifact, report, code candidate and record head; no stale approval is applied',async()=>{
|
|
75
|
+
const f=await fixture();
|
|
76
|
+
for(const file of [f.options.artifact,f.options.report,path.join(f.codeProject,'a.mjs')]){
|
|
77
|
+
const original=fs.readFileSync(file);
|
|
78
|
+
await assert.rejects(recordDelivery(f.options,{confirm:async(_p,phrase)=>{fs.appendFileSync(file,'drift');return phrase;}}));
|
|
79
|
+
fs.writeFileSync(file,original);assert.equal(readDeliveryRecords(f.specsDir).length,0);
|
|
80
|
+
}
|
|
81
|
+
await assert.rejects(recordDelivery(f.options,{confirm:async(_p,phrase)=>{await recordDelivery(f.options,accept);return phrase;}}),{code:'delivery_preview_changed'});
|
|
82
|
+
assert.equal(readDeliveryRecords(f.specsDir).length,1);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('latest declaration, environment and candidate are never replaced by an older success',async()=>{
|
|
86
|
+
const f=await fixture();await recordDelivery(f.options,accept);
|
|
87
|
+
const candidate=deliveryCandidate(f.options),base={specsDir:f.specsDir,feature,identity,packageDigest:candidate.packageDigest,specificationDigest:candidate.specificationDigest};
|
|
88
|
+
assert.equal(deliveryProjection({...base,packageDigest:'f'.repeat(64)}).productAcceptance.status,'stale');
|
|
89
|
+
assert.equal(deliveryProjection({...base,current:false}).productAcceptance.status,'stale');
|
|
90
|
+
const code=path.join(f.codeProject,'a.mjs'),before=fs.readFileSync(code);fs.appendFileSync(code,'// changed');
|
|
91
|
+
assert.equal(completionSummary({specsDir:f.specsDir,feature,result:f.result}).productAcceptance.status,'stale');
|
|
92
|
+
fs.writeFileSync(code,before);
|
|
93
|
+
assert.equal(deliveryProjection({...base,artifactSha256:'b'.repeat(64)}).productAcceptance.status,'stale');
|
|
94
|
+
fs.appendFileSync(f.options.report,'changed');assert.equal(deliveryProjection(base).productAcceptance.status,'stale');
|
|
95
|
+
fs.writeFileSync(f.options.report,'human observed flow');
|
|
96
|
+
await recordDelivery({...f.options,statement:{...f.options.statement,environment:'production',outcome:'revoked'}},accept);
|
|
97
|
+
const value=deliveryProjection(base);assert.equal(value.productAcceptance.environments.length,2);
|
|
98
|
+
assert.match(deliveryLines(value)[0],/production \[.*\] 声明已记录(revoked)/);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test('deployment execution and post-deployment verification remain distinct, with separate evidence',async()=>{
|
|
102
|
+
const f=await fixture(),options={...f.options,kind:'deployment',statement:{actor:'fixture-operator',environment:'staging',execution:'succeeded',verification:'unknown',note:'deployment declaration'}};
|
|
103
|
+
await recordDelivery(options,accept);assert.equal(f.projection().deployment.environments[0].statement.verification,'unknown');
|
|
104
|
+
await assert.rejects(recordDelivery({...options,statement:{...options.statement,verification:'passed'}},accept),{code:'delivery_verification_report_required'});
|
|
105
|
+
await recordDelivery({...options,statement:{...options.statement,verification:'passed'},verificationReport:f.verificationReport},accept);
|
|
106
|
+
fs.appendFileSync(f.verificationReport,'changed');assert.equal(f.projection().deployment.status,'stale');
|
|
107
|
+
await recordDelivery({...options,statement:{...options.statement,execution:'failed'}},accept);
|
|
108
|
+
assert.equal(f.projection().deployment.environments[0].statement.execution,'failed');assert.equal(readDeliveryRecords(f.specsDir).length,3);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('malformed records and unsafe source links fail closed; read-only CLI cannot bypass terminal confirmation',async()=>{
|
|
112
|
+
const f=await fixture();await recordDelivery(f.options,accept);
|
|
113
|
+
const file=path.join(f.specsDir,'.reviews','.delivery','000001','record.json'),original=fs.readFileSync(file);
|
|
114
|
+
const raw=JSON.parse(original);raw.statement.outcome='accepted-by-ai';fs.writeFileSync(file,JSON.stringify(raw));
|
|
115
|
+
assert.throws(()=>readDeliveryRecords(f.specsDir));assert.equal(f.projection().productAcceptance.status,'unknown');fs.writeFileSync(file,original);
|
|
116
|
+
const linked=path.join(f.local,'linked.txt');fs.symlinkSync(f.options.artifact,linked);assert.throws(()=>deliveryFile(linked));
|
|
117
|
+
const args=['--specs',f.specsDir,'--repository',identity.repositoryId,'--run',identity.runId,'--feature',feature,'--artifact',f.options.artifact];
|
|
118
|
+
const status=spawnSync(process.execPath,[cli,'status',...args,'--json'],{encoding:'utf8'});assert.equal(status.status,0,status.stderr);assert.equal(JSON.parse(status.stdout).productAcceptance.status,'recorded');
|
|
119
|
+
const recordArgs=[...args,'--kind','acceptance','--actor','owner','--environment','staging','--note','tested','--report',f.options.report,'--outcome','accepted'];
|
|
120
|
+
const refused=spawnSync(process.execPath,[cli,'record',...recordArgs],{encoding:'utf8',input:'yes\n'});
|
|
121
|
+
assert.equal(refused.status,2);assert.match(refused.stderr,/delivery_interactive_terminal_required/);assert.equal(readDeliveryRecords(f.specsDir).length,1);
|
|
122
|
+
const bypass=spawnSync(process.execPath,[cli,'record',...recordArgs,'--yes'],{encoding:'utf8'});assert.equal(bypass.status,2);
|
|
123
|
+
assert.deepEqual(fs.readFileSync(file),original);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('interactive CLI records only the displayed digest; competing publication cannot overwrite history',async()=>{
|
|
127
|
+
const f=await fixture(),input=new PassThrough();input.isTTY=true;
|
|
128
|
+
let shown='',errors='';const output=new Writable({write(chunk,_encoding,done){const value=chunk.toString();shown+=value;
|
|
129
|
+
const phrase=value.match(/RECORD acceptance [a-f0-9]{64}/)?.[0];if(phrase)queueMicrotask(()=>input.write(phrase+'\n'));done();}});output.isTTY=true;
|
|
130
|
+
const args=['record','--specs',f.specsDir,'--repository',identity.repositoryId,'--run',identity.runId,'--feature',feature,'--artifact',f.options.artifact,
|
|
131
|
+
'--kind','acceptance','--actor','fixture-owner','--environment','staging','--note','manual fixture','--report',f.options.report,'--outcome','accepted'];
|
|
132
|
+
assert.equal(await deliveryMain(args,{input,output,error:{write(value){errors+=value;}}}),0,errors);input.destroy();
|
|
133
|
+
assert.match(shown,/interactive-terminal-declaration/);assert.equal(readDeliveryRecords(f.specsDir).length,1);
|
|
134
|
+
const originalRename=fs.renameSync;let collided=false;
|
|
135
|
+
fs.renameSync=function(from,to){if(!collided&&to.endsWith('000002')){collided=true;fs.mkdirSync(to);
|
|
136
|
+
fs.writeFileSync(path.join(to,'record.json'),fs.readFileSync(path.join(from,'record.json')));}
|
|
137
|
+
return originalRename(from,to);};
|
|
138
|
+
try{await assert.rejects(recordDelivery(f.options,accept),{code:'delivery_concurrent_write'});}finally{fs.renameSync=originalRename;}
|
|
139
|
+
assert.equal(readDeliveryRecords(f.specsDir).length,2,'one atomic publication survives collision');
|
|
140
|
+
await recordDelivery(f.options,accept);assert.equal(readDeliveryRecords(f.specsDir).length,3,'losing stage does not block later append');
|
|
141
|
+
fs.renameSync=()=>{throw Object.assign(new Error('fixture interrupted publication'),{code:'EIO'});};
|
|
142
|
+
try{await assert.rejects(recordDelivery(f.options,accept),{code:'EIO'});}finally{fs.renameSync=originalRename;}
|
|
143
|
+
assert.equal(readDeliveryRecords(f.specsDir).length,3);
|
|
144
|
+
await recordDelivery(f.options,accept);assert.equal(readDeliveryRecords(f.specsDir).length,4,'interrupted unpublished stage is preserved without corrupting committed rows');
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('record capacity is rejected before confirmation, preserving a fully readable ledger',async()=>{
|
|
148
|
+
const f=await fixture(),first=await recordDelivery(f.options,accept);let previous=first.recordDigest;
|
|
149
|
+
const {recordDigest,...template}=first;
|
|
150
|
+
for(let sequence=2;sequence<=1000;sequence++){
|
|
151
|
+
const body={...template,sequence,previousDigest:previous},record={...body,recordDigest:digest(body)};
|
|
152
|
+
const dir=path.join(f.specsDir,'.reviews','.delivery',String(sequence).padStart(6,'0'));fs.mkdirSync(dir);
|
|
153
|
+
fs.writeFileSync(path.join(dir,'record.json'),JSON.stringify(record)+'\n');previous=record.recordDigest;
|
|
154
|
+
}
|
|
155
|
+
let asked=false;await assert.rejects(recordDelivery(f.options,{confirm:async()=>{asked=true;return 'yes';}}),{code:'delivery_record_limit'});
|
|
156
|
+
assert.equal(asked,false);assert.equal(readDeliveryRecords(f.specsDir).length,1000);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
test('R1 G8 environment casing and surrounding spaces cannot hide a later revocation',async()=>{
|
|
160
|
+
const f=await fixture();await recordDelivery(f.options,accept);
|
|
161
|
+
await recordDelivery({...f.options,statement:{...f.options.statement,environment:'Staging ',outcome:'revoked'}},accept);
|
|
162
|
+
const value=f.projection().productAcceptance;assert.equal(value.environments.length,1);
|
|
163
|
+
assert.equal(value.environments[0].environment,'staging');assert.equal(value.environments[0].statement.outcome,'revoked');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
test('R1 G9 harmless Finder metadata does not hide delivery records while malformed entries still fail',async()=>{
|
|
167
|
+
const f=await fixture();await recordDelivery(f.options,accept);
|
|
168
|
+
const dir=path.join(f.specsDir,'.reviews','.delivery');fs.writeFileSync(path.join(dir,'.DS_Store'),'finder metadata');
|
|
169
|
+
assert.equal(readDeliveryRecords(f.specsDir).length,1);assert.equal(f.projection().productAcceptance.status,'recorded');
|
|
170
|
+
fs.mkdirSync(path.join(dir,'garbage'));assert.throws(()=>readDeliveryRecords(f.specsDir));
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test('R1 G10 a display evidence budget reports unknown without hashing a large artifact',async()=>{
|
|
174
|
+
const f=await fixture();await recordDelivery(f.options,accept);const candidate=deliveryCandidate(f.options);
|
|
175
|
+
const value=deliveryProjection({...f.options,identity,packageDigest:candidate.packageDigest,specificationDigest:candidate.specificationDigest,maxEvidenceBytes:1});
|
|
176
|
+
assert.equal(value.productAcceptance.status,'unknown');assert.equal(value.productAcceptance.environments[0].reason,'delivery_evidence_budget_exceeded');
|
|
177
|
+
});
|
|
@@ -81,3 +81,9 @@ for(const mode of ['watchdog','unexpected-exit'])test(`owned same-group worker c
|
|
|
81
81
|
await new Promise(resolve=>setTimeout(resolve,50));
|
|
82
82
|
assert.throws(()=>process.kill(pid,0),{code:'ESRCH'});
|
|
83
83
|
});
|
|
84
|
+
|
|
85
|
+
test('R1 G11 malformed optional completion display does not change the returned business result',t=>{
|
|
86
|
+
const out=run(t,`ready();process.stdin.once('data',()=>send({requestId:'drive',result:{state:'fixture_completed',completion:{version:1}}}));process.stdin.on('end',()=>process.exit(0));`);
|
|
87
|
+
assert.equal(out.status,0,out.stderr);assert.equal(JSON.parse(out.stdout).result.state,'fixture_completed');
|
|
88
|
+
assert.match(out.stderr,/完成摘要显示失败/);
|
|
89
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath,pathToFileURL} from 'node:url';
|
|
8
|
+
import {CHECK_DRIVE_COPIED_FILES} from './cm-check-drive-files.mjs';
|
|
9
|
+
|
|
10
|
+
const root=fileURLToPath(new URL('..',import.meta.url));
|
|
11
|
+
test('R1 B1 shared driver imports from the original check-only runtime without runner dependencies',t=>{
|
|
12
|
+
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-light-driver-')));
|
|
13
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
14
|
+
for(const file of CHECK_DRIVE_COPIED_FILES){
|
|
15
|
+
const target=path.join(dir,file);fs.mkdirSync(path.dirname(target),{recursive:true});fs.copyFileSync(path.join(root,file),target);
|
|
16
|
+
}
|
|
17
|
+
for(const file of ['completion-summary.mjs','delivery-evidence.mjs','task-runner.mjs'])
|
|
18
|
+
assert.equal(fs.existsSync(path.join(dir,'runtime/js/cm-ai',file)),false,'test uses the original partial runtime inventory');
|
|
19
|
+
const source=`import {driveHost} from ${JSON.stringify(pathToFileURL(path.join(dir,'runtime/js/cm-ai/drive-core.mjs')).href)};
|
|
20
|
+
import {completionLines,deliveryLines} from ${JSON.stringify(pathToFileURL(path.join(dir,'runtime/js/cm-ai/operator-guidance.mjs')).href)};
|
|
21
|
+
if(typeof driveHost!=='function'||completionLines(null).length!==0||deliveryLines({}).length!==2)process.exitCode=1;`;
|
|
22
|
+
const run=spawnSync(process.execPath,['--input-type=module','-e',source],{cwd:dir,encoding:'utf8'});
|
|
23
|
+
assert.equal(run.status,0,run.stderr);assert.equal(run.stdout,'');
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('R1 B1 legacy formatter exports reuse the exact lightweight formatting functions',async()=>{
|
|
27
|
+
const light=await import('../runtime/js/cm-ai/operator-guidance.mjs');
|
|
28
|
+
const completion=await import('../runtime/js/cm-ai/completion-summary.mjs');
|
|
29
|
+
const delivery=await import('../runtime/js/cm-ai/delivery-evidence.mjs');
|
|
30
|
+
assert.equal(typeof light.completionLines,'function');assert.equal(typeof light.deliveryLines,'function');
|
|
31
|
+
assert.equal(completion.completionLines,light.completionLines);assert.equal(delivery.deliveryLines,light.deliveryLines);
|
|
32
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import {mandatoryCheckCoverage} from '../runtime/js/check-coverage.mjs';
|
|
4
|
+
|
|
5
|
+
const xcode = (...selection) => ['/usr/bin/xcodebuild', 'test', '-scheme', 'App', ...selection];
|
|
6
|
+
const coverage = (requiredTests, ...commands) => mandatoryCheckCoverage({requiredTests, commands});
|
|
7
|
+
|
|
8
|
+
test('frozen Xcode test selection rejects omitted classes and skipped methods', () => {
|
|
9
|
+
const required = ['AppUITests/OldTests', 'AppUITests/NewTests'];
|
|
10
|
+
assert.deepEqual(coverage(required, xcode('-only-testing:AppUITests/NewTests')),
|
|
11
|
+
{satisfied: false, missing: required, unverifiable: ['AppUITests/NewTests']});
|
|
12
|
+
assert.deepEqual(coverage(required, xcode('-only-testing:AppUITests')),
|
|
13
|
+
{satisfied:false,missing:required,unverifiable:required});
|
|
14
|
+
assert.equal(coverage(['AppUITests/OldTests'], xcode('-only-testing:AppUITests', '-skip-testing:AppUITests/OldTests/testExisting')).satisfied, false);
|
|
15
|
+
assert.deepEqual(coverage(['AppUITests/OldTests'], ['/usr/bin/xcrun', 'xcodebuild', ...xcode('-only-testing:AppUITests/OldTests').slice(1)]),
|
|
16
|
+
{satisfied:false,missing:['AppUITests/OldTests'],unverifiable:['AppUITests/OldTests']});
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('build, enumeration and values named test are not execution selection', () => {
|
|
20
|
+
for (const command of [xcode('-enumerate-tests'), xcode('-showBuildSettings'),
|
|
21
|
+
['/usr/bin/xcodebuild', '-resultBundlePath', 'test', 'build-for-testing']])
|
|
22
|
+
assert.equal(coverage(['AppUITests/OldTests'], command).satisfied, false, JSON.stringify(command));
|
|
23
|
+
assert.deepEqual(coverage(['AppUITests/OldTests'], xcode('-only-testing', 'AppUITests/OldTests')).unverifiable,
|
|
24
|
+
['AppUITests/OldTests']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('a wrapper mentioning a test or xcodebuild cannot prove mandatory coverage', () => {
|
|
28
|
+
for (const command of [['bash', 'checks.sh', 'AppUITests/OldTests'],
|
|
29
|
+
['echo', 'xcodebuild', 'test'], [process.execPath, 'wrapper.js', 'AppUITests/OldTests']]) {
|
|
30
|
+
const result = coverage(['AppUITests/OldTests'], command);
|
|
31
|
+
assert.deepEqual(result, {satisfied: false, missing: ['AppUITests/OldTests'], unverifiable: ['AppUITests/OldTests']});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('direct Node test files and explicit node --test files are supported without substring matches', () => {
|
|
36
|
+
assert.equal(coverage(['test/a.test.js'], [process.execPath, 'test/a.test.js']).satisfied, true);
|
|
37
|
+
assert.equal(coverage(['test/a.test.js', 'test/b.test.js'], [process.execPath, '--test', './test/a.test.js', 'test/b.test.js']).satisfied, true);
|
|
38
|
+
assert.deepEqual(coverage(['test/a.test.js', 'test/b.test.js'], [process.execPath, '--test', 'test/a.test.js']),
|
|
39
|
+
{satisfied: false, missing: ['test/b.test.js'], unverifiable: []});
|
|
40
|
+
assert.equal(coverage(['test/a.test.js'], [process.execPath, '--test', 'test/a.test.js.bak']).satisfied, false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('Node filters, discovery, globs and unmodeled options remain unverifiable', () => {
|
|
44
|
+
for (const args of [['--test'], ['--test', 'test/*.test.js'], ['--test', '--test-name-pattern=easy', 'test/a.test.js'],
|
|
45
|
+
['--test', '--test-shard=1/2', 'test/a.test.js'], ['--test', '--test-only', 'test/a.test.js'],
|
|
46
|
+
['--eval', "require('./test/a.test.js')"]])
|
|
47
|
+
assert.deepEqual(coverage(['test/a.test.js'], [process.execPath, ...args]),
|
|
48
|
+
{satisfied: false, missing: ['test/a.test.js'], unverifiable: ['test/a.test.js']}, JSON.stringify(args));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('commands from another test family cannot satisfy a frozen test identifier', () => {
|
|
52
|
+
assert.deepEqual(coverage(['test/a.test.js'], xcode()).unverifiable, ['test/a.test.js']);
|
|
53
|
+
assert.deepEqual(coverage(['AppUITests/OldTests.swift'], xcode()).unverifiable, ['AppUITests/OldTests.swift']);
|
|
54
|
+
assert.deepEqual(coverage(['AppUITests/OldTests'], [process.execPath, 'AppUITests/OldTests']).unverifiable, ['AppUITests/OldTests']);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('approved subsets are respected; no contract obligations does not expand the gate', () => {
|
|
58
|
+
assert.deepEqual(coverage(['AppUITests/NewTests'], xcode('-only-testing:AppUITests/NewTests')),
|
|
59
|
+
{satisfied:false,missing:['AppUITests/NewTests'],unverifiable:['AppUITests/NewTests']});
|
|
60
|
+
assert.deepEqual(coverage([], ['bash', 'unknown.sh']), {satisfied: true, missing: [], unverifiable: []});
|
|
61
|
+
assert.deepEqual(coverage(['test/a.js']), {satisfied: false, missing: ['test/a.js'], unverifiable: []});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
test('invalid frozen test identities are rejected and input is never mutated', () => {
|
|
65
|
+
for (const requiredTests of [null, [''], ['a', 'a'], ['../a'], ['/a'], ['a\0b']])
|
|
66
|
+
assert.throws(() => mandatoryCheckCoverage({requiredTests, commands: []}), {code: 'mandatory_check_contract_invalid'});
|
|
67
|
+
const requiredTests = Object.freeze(['test/a.test.js']);
|
|
68
|
+
const commands = Object.freeze([Object.freeze([process.execPath, '--test', 'test/a.test.js'])]);
|
|
69
|
+
assert.equal(mandatoryCheckCoverage({requiredTests, commands}).satisfied, true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('a program basename or PATH lookup is not a trusted test engine identity', () => {
|
|
73
|
+
for (const binary of ['node', './node', '/project/node'])
|
|
74
|
+
assert.deepEqual(coverage(['test/a.test.js'], [binary, '--test', 'test/a.test.js']).unverifiable, ['test/a.test.js']);
|
|
75
|
+
for (const binary of ['xcodebuild', '/project/xcodebuild'])
|
|
76
|
+
assert.deepEqual(coverage(['AppUITests/OldTests'], [binary, 'test']).unverifiable, ['AppUITests/OldTests']);
|
|
77
|
+
});
|
|
78
|
+
test('unmodeled Xcode configuration selectors and future flags remain unverifiable',()=>{
|
|
79
|
+
for(const args of [['-only-test-configuration','SmokeOnly'],['-skip-test-configuration','FullTests'],
|
|
80
|
+
['-testPlan','Subset'],['-future-filter','Easy'],['SWIFT_ACTIVE_COMPILATION_CONDITIONS=OMIT_TESTS']])
|
|
81
|
+
assert.deepEqual(coverage(['AppTests/ImportantTests'],xcode(...args)).unverifiable,['AppTests/ImportantTests']);
|
|
82
|
+
});
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {spawnSync} from 'node:child_process';
|
|
6
|
+
import test from 'node:test';
|
|
7
|
+
import {selectedNodeTestFiles} from '../runtime/js/node-test-selection.mjs';
|
|
8
|
+
import {mandatoryCheckCoverage} from '../runtime/js/check-coverage.mjs';
|
|
9
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
10
|
+
import {acceptanceCoverage} from '../runtime/js/cm-ai/acceptance-contract.mjs';
|
|
11
|
+
|
|
12
|
+
const files=['a.test.mjs','b.test.mjs'];
|
|
13
|
+
const argv=(...options)=>[process.execPath,'--test',...options,...files];
|
|
14
|
+
const coverage=command=>mandatoryCheckCoverage({requiredTests:files,commands:[command]});
|
|
15
|
+
const identity={repositoryId:'node-selection',runId:'native-fixture',taskId:'T-001',attempt:1};
|
|
16
|
+
const supported=spawnSync(process.execPath,['--help'],{encoding:'utf8'}).stdout;
|
|
17
|
+
|
|
18
|
+
test('native non-filtering options select exact explicit files without changing argv',()=>{
|
|
19
|
+
for(const options of [
|
|
20
|
+
['--test-concurrency=2'],['--test-concurrency','2'],
|
|
21
|
+
['--test-timeout=1000'],['--test-timeout','1000'],
|
|
22
|
+
...['tap','spec','dot'].flatMap(value=>[['--test-reporter',value],[`--test-reporter=${value}`]]),
|
|
23
|
+
['--test-reporter=tap','--test-reporter-destination=stdout'],
|
|
24
|
+
['--test-reporter','spec','--test-reporter-destination','stderr'],
|
|
25
|
+
['--test-concurrency=2','--test-timeout=1000','--test-reporter=dot','--'],
|
|
26
|
+
]){
|
|
27
|
+
const command=Object.freeze(argv(...options));
|
|
28
|
+
assert.deepEqual(selectedNodeTestFiles(command),files,JSON.stringify(options));
|
|
29
|
+
assert.deepEqual(coverage(command),{satisfied:true,missing:[],unverifiable:[]});
|
|
30
|
+
}
|
|
31
|
+
assert.deepEqual(selectedNodeTestFiles([process.execPath,'--test-reporter=tap','--test','./a.test.mjs']),['a.test.mjs']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('every supported option rejects absent, invalid or duplicate values',()=>{
|
|
35
|
+
const cases=[
|
|
36
|
+
['--test-concurrency'],['--test-timeout'],['--test-reporter'],['--test-reporter-destination'],
|
|
37
|
+
...['0','-1','1.5','Infinity','2147483648','01',''].flatMap(value=>[
|
|
38
|
+
[`--test-concurrency=${value}`],[`--test-timeout=${value}`]]),
|
|
39
|
+
['--test-reporter=./custom.mjs'],['--test-reporter=node:custom'],['--test-reporter='],
|
|
40
|
+
['--test-reporter-destination=stdout'],
|
|
41
|
+
['--test-reporter=tap','--test-reporter-destination=a.test.mjs'],
|
|
42
|
+
['--test-reporter=tap','--test-reporter-destination='],
|
|
43
|
+
['--test','--test'],
|
|
44
|
+
...[['--test-concurrency=1'],['--test-timeout=1000'],['--test-reporter=tap'],
|
|
45
|
+
['--test-reporter=tap','--test-reporter-destination=stdout']].map(options=>[...options,...options]),
|
|
46
|
+
];
|
|
47
|
+
for(const options of cases)assert.deepEqual(coverage(argv(...options)),
|
|
48
|
+
{satisfied:false,missing:files,unverifiable:files},JSON.stringify(options));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('filters, npm wrappers, custom execution hooks and unknown options stay unverifiable',()=>{
|
|
52
|
+
for(const options of [
|
|
53
|
+
['--test-name-pattern=small'],['--test-skip-pattern=important'],['--test-shard=1/2'],['--test-only'],
|
|
54
|
+
['--test-rerun-failures=prior.json'],['--test-global-setup=setup.mjs'],['--test-isolation=none'],
|
|
55
|
+
['--import=preload.mjs'],['--require=preload.cjs'],['--experimental-config-file=config.json'],
|
|
56
|
+
['--test-update-snapshots'],['--future-filter=small'],['--test-reporter=tap','--test-only'],
|
|
57
|
+
])assert.deepEqual(coverage(argv(...options)).unverifiable,files,JSON.stringify(options));
|
|
58
|
+
for(const command of [['npm','test','--',...files],['npm','run','test','--',...files],
|
|
59
|
+
['node','--test',...files],['/project/node','--test',...files]])
|
|
60
|
+
assert.deepEqual(coverage(command).unverifiable,files);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('options stop at the first file and missing files remain missing',()=>{
|
|
64
|
+
for(const command of [[process.execPath,'--test','a.test.mjs','--test-concurrency=1','b.test.mjs'],
|
|
65
|
+
[process.execPath,'--test','*.test.mjs'],[process.execPath,'--test'],
|
|
66
|
+
[process.execPath,'--test-reporter=tap',...files],
|
|
67
|
+
[process.execPath,'--test','--','--test-only',...files]])
|
|
68
|
+
assert.deepEqual(coverage(command).unverifiable,files);
|
|
69
|
+
assert.deepEqual(coverage([process.execPath,'--test','--test-reporter=tap','./a.test.mjs']),
|
|
70
|
+
{satisfied:false,missing:['b.test.mjs'],unverifiable:[]});
|
|
71
|
+
assert.deepEqual(coverage([process.execPath,'--test','--test-reporter=tap','a.test.mjs.bak']),
|
|
72
|
+
{satisfied:false,missing:files,unverifiable:[]});
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// Real native subprocesses, isolated temporary files, no npm or external access.
|
|
76
|
+
// Options unavailable in an older supported Node are not injected into user
|
|
77
|
+
// commands; here those specific executions are explicitly skipped.
|
|
78
|
+
for(const [name,options] of [
|
|
79
|
+
['concurrency',['--test-concurrency','1']],
|
|
80
|
+
['timeout',['--test-timeout=1000']],
|
|
81
|
+
['tap',['--test-reporter=tap']],['spec',['--test-reporter','spec']],['dot',['--test-reporter=dot']],
|
|
82
|
+
['destination',['--test-reporter=tap','--test-reporter-destination','stderr']],
|
|
83
|
+
['separator',['--test-reporter=tap','--',]],
|
|
84
|
+
])test(`actual host Node execution with ${name} preserves both selected files`,
|
|
85
|
+
{skip:!supported.includes(options[0].split('=')[0])},async()=>{
|
|
86
|
+
const cwd=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-node-selection-')));
|
|
87
|
+
try{
|
|
88
|
+
for(const [index,file] of files.entries())fs.writeFileSync(path.join(cwd,file),
|
|
89
|
+
`import test from 'node:test';import fs from 'node:fs';test('selected ${index}',()=>fs.writeFileSync('ran-${index}','yes'));\n`);
|
|
90
|
+
const command=argv(...options),check=createHostCheck({cwd,commands:[{id:'node-tests',command}],timeoutMs:10000});
|
|
91
|
+
const observed=await check({identity},{signal:new AbortController().signal});
|
|
92
|
+
assert.equal(observed[0].outcome,'passed');assert.deepEqual(observed[0].command,command);
|
|
93
|
+
for(let index=0;index<files.length;index++)assert.equal(fs.readFileSync(path.join(cwd,`ran-${index}`),'utf8'),'yes');
|
|
94
|
+
assert.equal(acceptanceCoverage({requiredTests:files,requiredCommands:[['node',...command.slice(1)]]},observed).satisfied,true);
|
|
95
|
+
}finally{fs.rmSync(cwd,{recursive:true,force:true});}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
test('native command failure remains failure even when its file selection is modeled',async()=>{
|
|
99
|
+
const cwd=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-node-selection-fail-')));
|
|
100
|
+
try{
|
|
101
|
+
fs.writeFileSync(path.join(cwd,files[0]),"import test from 'node:test';test('failure',()=>{throw Error('fixture');});\n");
|
|
102
|
+
const command=[process.execPath,'--test','--test-reporter=tap',files[0]],
|
|
103
|
+
check=createHostCheck({cwd,commands:[{id:'node-tests',command}],timeoutMs:10000});
|
|
104
|
+
const observed=await check({identity},{signal:new AbortController().signal});
|
|
105
|
+
assert.equal(observed[0].outcome,'failed');
|
|
106
|
+
assert.equal(acceptanceCoverage({requiredTests:[files[0]],requiredCommands:[['node',...command.slice(1)]]},observed).satisfied,false);
|
|
107
|
+
}finally{fs.rmSync(cwd,{recursive:true,force:true});}
|
|
108
|
+
});
|
|
@@ -256,10 +256,13 @@ test('importing runtime/js/notify.mjs has no process-exit side effect, also when
|
|
|
256
256
|
assert.equal(plain.status,0,plain.stderr);assert.match(plain.stdout,/imported/);
|
|
257
257
|
// Simulated Node without import.meta.main: copy the whole import graph with
|
|
258
258
|
// every `import.meta.main` replaced by `undefined`, import that copy.
|
|
259
|
-
const copy=(files,dir)=>{for(const file of files){
|
|
260
|
-
const target=path.
|
|
259
|
+
const copy=(files,dir,root=dir)=>{for(const file of files){
|
|
260
|
+
const target=path.resolve(dir,file);
|
|
261
|
+
assert(target.startsWith(path.resolve(root)+path.sep),`copied module must stay inside the fixture: ${file}`);
|
|
262
|
+
fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
261
263
|
fs.writeFileSync(target,fs.readFileSync(new URL(file,RUNTIME),'utf8').replaceAll('import.meta.main','undefined'));}};
|
|
262
|
-
const
|
|
264
|
+
const repositoryCopy=sandbox(t),runtimeCopy=path.join(repositoryCopy,'runtime/js');
|
|
265
|
+
copy(graph.concat(['notify-run.mjs']),runtimeCopy,repositoryCopy);
|
|
263
266
|
const simulated=importChild(path.join(runtimeCopy,'notify.mjs'));
|
|
264
267
|
assert.equal(simulated.status,0,simulated.stderr);assert.match(simulated.stdout,/imported/);
|
|
265
268
|
// Negative control: the same simulation does kill an import of the sender,
|
|
@@ -73,6 +73,18 @@ test('actual change CLI resumes unsaved phase across processes and stops at huma
|
|
|
73
73
|
c=await client(t,dir,respond,{session:runId});assert.equal((await c.request('status')).result.stage,'change_design');
|
|
74
74
|
for(const text of ['Design','Tasks','Check']){result=await c.request('advance',{text});assert.ok(result.result,JSON.stringify(result));}
|
|
75
75
|
assert.equal(result.result.stage,'change_confirmation');const proposalDigest=result.result.proposal.proposalDigest;
|
|
76
|
+
assert.equal(result.result.acceptancePreview.proposalDigest,proposalDigest);
|
|
77
|
+
assert.equal(result.result.acceptancePreview.sourceKind,'proposed_documents');
|
|
78
|
+
assert.equal(result.result.acceptancePreview.taskGrammar,1,'unpublished existing change retains legacy grammar');
|
|
79
|
+
assert.equal(result.result.acceptancePreview.approvalAuthorized,false);
|
|
80
|
+
assert.equal(result.result.acceptancePreview.executionAuthorized,false);
|
|
81
|
+
const checkpointPath=path.join(dir,'.reviews/prd-sessions',runId,'state.json'),checkpoint=fs.readFileSync(checkpointPath);
|
|
82
|
+
const sourcePath=path.join(dir,'1.guide/requirements.md'),originalSource=fs.readFileSync(sourcePath);
|
|
83
|
+
fs.appendFileSync(sourcePath,'\nExternal edit\n');
|
|
84
|
+
const stale=await c.request('status');assert.equal(stale.result.acceptancePreview.status,'stale');
|
|
85
|
+
assert.equal(stale.result.acceptancePreview.proposalDigest,proposalDigest);
|
|
86
|
+
assert.deepEqual(fs.readFileSync(checkpointPath),checkpoint,'preview status does not rewrite the session');
|
|
87
|
+
fs.writeFileSync(sourcePath,originalSource);
|
|
76
88
|
assert.equal((await c.request('save_draft')).error.code,'host_request_failed');
|
|
77
89
|
assert.ok((await c.request('decision',{proposalDigest,approved:true,allowUserCaseChanges:false})).result);
|
|
78
90
|
result=await c.request('save_draft');assert.equal(result.result.status,'awaiting_review');assert.equal(result.result.counts.preservedCompletedTasks,1);
|
package/scripts/cm-prd-host.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import {createPrdDispositionOwner} from '../runtime/js/cm-prd/review-disposition
|
|
|
16
16
|
import {savePrdDraft,savePrdDesign,savePrdPromotedDraft} from '../runtime/js/cm-prd/draft-save.mjs';
|
|
17
17
|
import {createPrdCorrectionOwner,inspectPrdCorrectionRecovery,resumePrdCorrection} from '../runtime/js/cm-prd/review-correction.mjs';
|
|
18
18
|
import {createPrdSummaryOwner,publishPrdAwaitingReview} from '../runtime/js/cm-prd/summary.mjs';
|
|
19
|
+
import {currentAcceptancePreview} from '../runtime/js/cm-prd/acceptance-preview.mjs';
|
|
19
20
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
20
21
|
import {serveCmAiHost} from '../runtime/js/cm-ai/host-session.mjs';
|
|
21
22
|
import {need,shape,json,id,digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
@@ -138,6 +139,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
138
139
|
// Repair older cancelled checkpoints without replaying their retained call.
|
|
139
140
|
if(cancelled&&!ended){reviewController.abort();session.commit(checkpoint());}
|
|
140
141
|
const status=()=>ended?{stage:'inputs_replaced',runId,replacement:ended,completionAuthorized:false}:({...change?.status()??analysis.status(),...(predecessor?{predecessor}:{}),runId,logWriteEnabled:true,reviewState,summaryState,publishedSummary,
|
|
142
|
+
...(summaryState?.acceptancePreview?{acceptancePreview:currentAcceptancePreview({specs:admission.specs,preview:summaryState.acceptancePreview})}:{}),
|
|
141
143
|
recovery:session.state.active?{request:session.state.active.request,calls:session.state.active.calls.map(({callId,requestDigest,kind,result})=>
|
|
142
144
|
({callId,requestDigest,kind,status:result===undefined?'unknown':'recorded'}))}:null});
|
|
143
145
|
const handle=async raw=>{
|
|
@@ -185,7 +187,7 @@ export async function main(argv=process.argv.slice(2),{input=process.stdin,outpu
|
|
|
185
187
|
summaryState=null;
|
|
186
188
|
try{
|
|
187
189
|
need(Array.isArray(currentFeatures)&¤tFeatures.length>0,'prd_summary_scope_unknown');
|
|
188
|
-
summaryState=await summarize(admission.specs,{currentFeatures},reviewController.signal);return summaryState;
|
|
190
|
+
summaryState=await summarize(admission.specs,{currentFeatures,taskGrammar:session.versions().taskGrammar},reviewController.signal);return summaryState;
|
|
189
191
|
}catch(cause){
|
|
190
192
|
// The shared transport redacts thrown errors. Keep this recoverable
|
|
191
193
|
// scope failure visible without changing that transport contract.
|