@aibyzero/cm-workflow 0.16.4 → 0.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +8 -0
- package/CHANGELOG.md +50 -0
- package/README.md +12 -1
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +92 -20
- package/scripts/cm-ai-batch-drive.test.mjs +164 -3
- package/scripts/cm-ai-batch-host.mjs +27 -11
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +479 -47
- package/scripts/cm-ai-drive.test.mjs +240 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +84 -25
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +261 -42
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
// #17/#18: the project is refused run_done while feature 1's QA FAILs; its QA
|
|
2
|
+
// fix is still accepted after a later, separately reviewed task changed the tree.
|
|
3
|
+
import test,{after} from 'node:test';
|
|
4
|
+
import assert from 'node:assert/strict';
|
|
5
|
+
import fs from 'node:fs';
|
|
6
|
+
import os from 'node:os';
|
|
7
|
+
import path from 'node:path';
|
|
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 {createHostReviewAuthority} from '../runtime/js/cm-ai/host-review-authority.mjs';
|
|
13
|
+
import {createQaFixOwnerHost} from '../runtime/js/cm-ai/host-qa-fix-owner.mjs';
|
|
14
|
+
import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
15
|
+
import {qaFixIdentity} from '../runtime/js/cm-fix/qa-source.mjs';
|
|
16
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
17
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
18
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
19
|
+
import {readProjectInstructionContext} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
20
|
+
import {attemptBaseline,readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
21
|
+
import {validateAcceptedFix} from '../runtime/js/cm-ai/accepted-fix.mjs';
|
|
22
|
+
import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/review-package.mjs';
|
|
23
|
+
import {appendFits,openExecutionStore} from '../runtime/js/cm-ai/execution-store.mjs';
|
|
24
|
+
import {composeFixCode,inspectFixCodeAssociation} from '../runtime/js/cm-ai/fix-code-association.mjs';
|
|
25
|
+
import {approvedReviewAt,fixReviewedAt,resolveDeliverySteps} from '../runtime/js/cm-ai/reviewed-deliveries.mjs';
|
|
26
|
+
|
|
27
|
+
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-later-delivery-'));
|
|
28
|
+
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
29
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolated,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolated,'logs');
|
|
30
|
+
after(()=>{
|
|
31
|
+
for(const [key,value] of Object.entries(saved)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
32
|
+
fs.rmSync(isolated,{recursive:true,force:true});
|
|
33
|
+
});
|
|
34
|
+
const events=(onEvent,thread)=>{
|
|
35
|
+
for(const event of [{event:'thread.started',provider_thread:thread},{event:'turn.started',item_type:null},
|
|
36
|
+
{event:'item.completed',item_type:'agent_message'},{event:'turn.completed',item_type:null},
|
|
37
|
+
{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// The later task is reviewed before the QA fix, so in both variants it is the
|
|
41
|
+
// fix's recorded preceding step (v1 -> later -> fix). shared: it also rewrites
|
|
42
|
+
// the earlier task's value.mjs, so the fix's own before-state depends on it.
|
|
43
|
+
for(const variant of ['separate','shared'])test(`#18 a QA fix for an earlier feature is accepted after a later reviewed task (${variant}); #17 the project reaches run_done only then`,async()=>{
|
|
44
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'project-')));
|
|
45
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');fs.mkdirSync(codeProject);
|
|
46
|
+
for(const [feature,task] of [['1.value','T-001'],['2.more','T-002']]){
|
|
47
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
48
|
+
for(const name of ['requirements','design'])fs.writeFileSync(path.join(specsDir,feature,`${name}.md`),'# Synthetic fixture');
|
|
49
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),`- [ ] ${task}: implement\n`);
|
|
50
|
+
}
|
|
51
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['1.value','2.more'],specFiles:buildManifest(specsDir)}));
|
|
52
|
+
fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=0;');
|
|
53
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'Value should be 2.');
|
|
54
|
+
fs.writeFileSync(path.join(codeProject,'red.mjs'),"import {value} from './value.mjs';if(value!==2){console.error('BUG');process.exit(1)}");
|
|
55
|
+
fs.writeFileSync(path.join(codeProject,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
56
|
+
fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
57
|
+
let qaRuns=0,childReviews=0,documentation=0;
|
|
58
|
+
const execution=({feature,write,retrospective={status:'no_new_lesson',candidates:[],reason:null},qa})=>{
|
|
59
|
+
const authority=createHostReviewAuthority({hostContextId:'parent-host',reviewerId:'reviewer',adapterId:'codex-review-adapter',
|
|
60
|
+
decide:async()=>({status:'approved'})});
|
|
61
|
+
return {configuration:{kind:'synthetic-parent-fix'},timeoutMs:2000,excludedContexts:['parent-host'],hostDecision:null,
|
|
62
|
+
hostDecisionProvider:authority.hostDecisionProvider,
|
|
63
|
+
developer:{provider:'codex',requestedModel:'synthetic',contextId:'author',run:createCodexDeveloperRun({requestedModel:'synthetic',worker:async()=>{
|
|
64
|
+
write();return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},retrospective}};}})},
|
|
65
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',allowed:true,available:true,
|
|
66
|
+
contexts:['parent-review-1','parent-review-2'],run:async(request,{onEvent})=>{
|
|
67
|
+
events(onEvent,`synthetic-review-${request.identity.runId}`);
|
|
68
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
69
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic review'}};}}],
|
|
70
|
+
reviewInvocation:{developerThreadId:'author',excludedThreadIds:['parent-host'],authorize:authority.authorize},
|
|
71
|
+
check:createHostCheck({cwd:codeProject,commands:[{id:'existing',command:[process.execPath,'existing.mjs']}]}),
|
|
72
|
+
qaLogHome:path.join(root,'logs'),qaDecisionProvider:{timeoutMs:1000,decide:async binding=>({decisionId:`qa-${binding.identity.runId}`,
|
|
73
|
+
identity:binding.identity,packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-28T01:00:00Z'})},
|
|
74
|
+
qaExecutor:{mode:'commands',caseCount:1,timeoutMs:1000,run:async binding=>{
|
|
75
|
+
const result=qa(binding),report=path.join(specsDir,'.reviews',`${binding.testRunId}.md`);
|
|
76
|
+
fs.writeFileSync(report,`Synthetic QA ${result}`);
|
|
77
|
+
return {result,passed:result==='PASS'?1:0,failed:result==='FAIL'?1:0,blocked:0,report};}},
|
|
78
|
+
applicableAgentFiles:[],documentationProvider:{timeoutMs:1000,inspect:async binding=>{documentation++;return {
|
|
79
|
+
syncId:binding.syncId,identity:binding.identity,packageDigest:binding.packageDigest,contextDigest:binding.contextDigest,
|
|
80
|
+
status:'completed',reason:'Synthetic documentation unchanged',at:'2026-09-28T02:00:00Z'};}}};
|
|
81
|
+
};
|
|
82
|
+
const identity={repositoryId:'fixture',runId:'parent-run',taskId:'T-001',attempt:1};
|
|
83
|
+
const definition={version:1,specsDir,codeProject,feature:'1.value',identity,scope:['value.mjs'],requirements:['requirements.md']};
|
|
84
|
+
const parentExecution=execution({feature:'1.value',write:()=>fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1;'),
|
|
85
|
+
qa:()=>(++qaRuns===1?'FAIL':'PASS')});
|
|
86
|
+
const request=operation=>({version:1,requestId:operation,operation,identity});
|
|
87
|
+
let parent=null,serial=null;
|
|
88
|
+
try{
|
|
89
|
+
parent=await openControlRun(definition,'create',parentExecution);
|
|
90
|
+
const failed=await parent.host.handle(request('advance'));
|
|
91
|
+
assert.equal(failed.code,'qa_failed',JSON.stringify(failed));
|
|
92
|
+
parent.close();parent=null;
|
|
93
|
+
// The later task of another feature lands first: a reviewed AGENTS.md lesson and a new file.
|
|
94
|
+
const laterIdentity={repositoryId:'fixture',runId:'later-run',taskId:'T-002',attempt:1};
|
|
95
|
+
const laterDefinition={version:1,specsDir,codeProject,feature:'2.more',identity:laterIdentity,
|
|
96
|
+
scope:variant==='shared'?['more.mjs','value.mjs']:['more.mjs'],requirements:['requirements.md']};
|
|
97
|
+
const laterExecution=execution({feature:'2.more',write:()=>{fs.writeFileSync(path.join(codeProject,'more.mjs'),'export const more=1;');
|
|
98
|
+
if(variant==='shared')fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=1; // shared with a later task');},
|
|
99
|
+
retrospective:{status:'lesson_candidate',reason:null,candidates:[{classification:'structured',trigger:'Later lesson',
|
|
100
|
+
action:'Keep value constants in one module',evidence:['more.mjs']}]},qa:()=>'PASS'});
|
|
101
|
+
let later=await openControlRun(laterDefinition,'create',laterExecution);
|
|
102
|
+
const refused=await later.host.handle({version:1,requestId:'later',operation:'advance',identity:laterIdentity});later.close();
|
|
103
|
+
assert.equal(refused.code,'project_qa_not_passed',JSON.stringify(refused));
|
|
104
|
+
assert.deepEqual(refused.outstandingQa.map(item=>[item.feature,item.runId,item.status]),[['1.value','parent-run','qa_failed']]);
|
|
105
|
+
assert.equal(documentation,0);
|
|
106
|
+
assert(fs.readFileSync(path.join(codeProject,'AGENTS.md'),'utf8').includes('Later lesson'));
|
|
107
|
+
// Back to feature 1: repair its QA failure through the original child owner.
|
|
108
|
+
const qaSource={feature:'1.value',identity,packageDigest:failed.packageDigest,testRunId:failed.fixHandoff.source.testRunId,
|
|
109
|
+
handoffDigest:failed.fixHandoff.handoffDigest};
|
|
110
|
+
const childIdentity=qaFixIdentity(qaSource),permissions=['--allow-red-test','--allow-baseline','--allow-repair',
|
|
111
|
+
'--allow-regression','--allow-final-review','--allow-walkthrough','--allow-finish'];
|
|
112
|
+
const review={model:'synthetic',disabledSkills:[],preflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
|
|
113
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic',disabledSkills:[],promptTransport:'stdin'})}};
|
|
114
|
+
const reviewHost=createFixReviewHost({codeProject,hostContextId:'parent-host',review,permissions,workerFactory:()=>async({prompt},{onEvent})=>{
|
|
115
|
+
childReviews++;const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);events(onEvent,`synthetic-child-review-${childReviews}`);
|
|
116
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:data.reviewPackage.packageDigest,
|
|
117
|
+
examinedPaths:data.examinedPaths,findings:[],summary:'Synthetic independent child review'}};}});
|
|
118
|
+
const configuration={hostContextId:'parent-host',qaSource,defect:'Value must be 2',causeReview:reviewHost.reviewer,
|
|
119
|
+
reproduction:{cwd:codeProject,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
120
|
+
redTest:{cwd:codeProject,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
121
|
+
baseline:{cwd:codeProject,testFiles:['existing.mjs'],commands:[{id:'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
122
|
+
repair:{scope:['value.mjs'],requirements:['requirements.md']},
|
|
123
|
+
walkthrough:{timeoutMs:2000,flows:[{id:'value',modules:['value'],steps:['Read value'],expected:['2'],kind:'commands',command:[process.execPath,'red.mjs']}]}};
|
|
124
|
+
parent=await openControlRun(definition,'resume',parentExecution);
|
|
125
|
+
serial=createQaFixOwnerHost({parent,hostContextId:'parent-host',parentHostContextId:'parent-host',
|
|
126
|
+
reopenParent:()=>openControlRun(definition,'resume',parentExecution),fix:{specsRoot:specsDir,identity:childIdentity,configuration},
|
|
127
|
+
allowStart:true,fixPermissions:permissions,fixAuthorities:{authority:reviewHost.authority,finalAuthority:reviewHost.finalAuthority},
|
|
128
|
+
fixExecution:{...reviewHost.execution,
|
|
129
|
+
// The child rereads the project instructions, now including the later lesson.
|
|
130
|
+
prepare:async()=>{const files=readProjectInstructionContext(codeProject).map(({content,...metadata})=>metadata),contextDigest=digest(files);
|
|
131
|
+
return {files,contextDigest,application:{contextDigest,status:'no_relevant_lesson',summary:'Fixture'}};},
|
|
132
|
+
bridge:{async call(kind){
|
|
133
|
+
if(kind==='fix_diagnose')return {status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['value'],
|
|
134
|
+
plan:'Change 1 to 2',crossLayer:false,investigation:{discardedAlternatives:[],boundaryAnalysis:null}};
|
|
135
|
+
if(kind==='fix_repair'){fs.writeFileSync(path.join(codeProject,'value.mjs'),'export const value=2;');return {outcome:'repaired'};}
|
|
136
|
+
if(kind==='fix_retrospective')return {status:'no_new_lesson',candidates:[],reason:null};
|
|
137
|
+
throw Error(`Unexpected host capability: ${kind}`);
|
|
138
|
+
}}}});
|
|
139
|
+
parent=null;
|
|
140
|
+
// The earlier run is not locked by the later reviewed delivery.
|
|
141
|
+
assert.equal((await serial.handle(request('status'))).code,null);
|
|
142
|
+
const bound={...request('fix_advance'),packageDigest:failed.packageDigest,testRunId:qaSource.testRunId};
|
|
143
|
+
assert.equal((await serial.handle(bound)).fixStage,'red_test_required');
|
|
144
|
+
let result;
|
|
145
|
+
for(const fixOperation of ['red_test','baseline','repair','regression','retrospective','handoff','final_review',
|
|
146
|
+
'publish_review','check_n5','post_review_regression','walkthrough','finish']){
|
|
147
|
+
result=await serial.handle({...bound,operation:'fix_action',fixOperation});
|
|
148
|
+
assert.notEqual(result.fixStage,'unknown',`${fixOperation}: ${JSON.stringify(result)}`);
|
|
149
|
+
}
|
|
150
|
+
assert.equal(result.code,'qa_fix_completed',JSON.stringify(result));
|
|
151
|
+
assert.equal(result.accepted.qaRound,1);
|
|
152
|
+
const association=result.accepted.association;
|
|
153
|
+
assert.equal(association.version,2);
|
|
154
|
+
// The record is compact: run id and package digest; the transitions come from the store.
|
|
155
|
+
assert.ok(association.laterDeliveries.every(step=>Object.keys(step).sort().join()==='beforeFix,packageDigest,runId'));
|
|
156
|
+
const parentAfter=()=>{const {records}=JSON.parse(fs.readFileSync(path.join(specsDir,'.reviews','.execution',identity.runId,'state.json')));
|
|
157
|
+
return approvedReviewAt(readRunnerHistory(records,records[0].payload.config,3).state);};
|
|
158
|
+
const resolve=(steps,after=parentAfter())=>resolveDeliverySteps({specsRoot:specsDir,root:codeProject,identity,after,steps});
|
|
159
|
+
assert.deepEqual(resolve(association.laterDeliveries).map(step=>[step.beforeFix,step.runId,step.pkg.changes.map(change=>change.path).sort()]),
|
|
160
|
+
[[0,'later-run',['AGENTS.md','more.mjs',...(variant==='shared'?['value.mjs']:[])]]]);
|
|
161
|
+
serial.close();serial=null;
|
|
162
|
+
// Durable replay reproduces the association from the journal alone.
|
|
163
|
+
const state=JSON.parse(fs.readFileSync(path.join(specsDir,'.reviews','.execution',identity.runId,'state.json')));
|
|
164
|
+
const history=readRunnerHistory(state.records,state.records[0].payload.config,3);
|
|
165
|
+
const accepted=state.records.find(row=>row.payload.type==='qa-fix-accepted').payload.record;
|
|
166
|
+
const check=(record,resolveSteps=resolve)=>validateAcceptedFix({record,previous:[],baseline:attemptBaseline(history.original,history.state.attempt),
|
|
167
|
+
parentPackage:history.state.reviewPackage,feature:'1.value',resolveSteps});
|
|
168
|
+
check(accepted);
|
|
169
|
+
if(variant==='shared'){
|
|
170
|
+
// The recorded step is re-proved against the real later run's store, and only
|
|
171
|
+
// as a delivery reviewed after this run's own approving review.
|
|
172
|
+
const proof=after=>resolve(accepted.association.laterDeliveries,after);
|
|
173
|
+
proof(approvedReviewAt(history.state));
|
|
174
|
+
assert.throws(()=>proof(Number.MAX_SAFE_INTEGER-1),{code:'fix_association_unverified'});
|
|
175
|
+
// The fix's own place in the order is the final review registration its
|
|
176
|
+
// evidence cites, for exactly its package.
|
|
177
|
+
assert.ok(Number.isSafeInteger(fixReviewedAt(specsDir,accepted.evidence)));
|
|
178
|
+
assert.equal(fixReviewedAt(specsDir,{...accepted.evidence,reviewPackage:{...accepted.evidence.reviewPackage,packageDigest:'0'.repeat(64)}}),null);
|
|
179
|
+
const stripped=structuredClone(accepted);stripped.association={...stripped.association,version:1};delete stripped.association.laterDeliveries;
|
|
180
|
+
assert.throws(()=>check(stripped),{code:'fix_before_mismatch'});
|
|
181
|
+
const forged=structuredClone(accepted);forged.association.currentFilesDigest='0'.repeat(64);
|
|
182
|
+
assert.throws(()=>check(forged),{code:'fix_association_invalid'});
|
|
183
|
+
// Pure journal replay has no stores: it checks shape and chain only.
|
|
184
|
+
check(forged,null);
|
|
185
|
+
}
|
|
186
|
+
parent=await openControlRun(definition,'resume',parentExecution);
|
|
187
|
+
const done=await parent.host.handle(request('advance'));
|
|
188
|
+
assert.equal(done.code,'run_done',JSON.stringify(done));assert.equal(qaRuns,2);
|
|
189
|
+
parent.close();parent=null;
|
|
190
|
+
later=await openControlRun(laterDefinition,'resume',laterExecution);
|
|
191
|
+
const finished=await later.host.handle({version:1,requestId:'later-again',operation:'advance',identity:laterIdentity});later.close();
|
|
192
|
+
assert.equal(finished.code,'run_done',JSON.stringify(finished));
|
|
193
|
+
if(variant==='shared'){
|
|
194
|
+
// A forged journal record with every chain digest recomputed replays (pure
|
|
195
|
+
// replay has no stores), but the open-time re-proof and live checks refuse it.
|
|
196
|
+
const statePath=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json'),original=fs.readFileSync(statePath);
|
|
197
|
+
const forge=mutate=>{
|
|
198
|
+
const saved=JSON.parse(original);const records=structuredClone(saved.records);
|
|
199
|
+
const index=records.findIndex(row=>row.payload.type==='qa-fix-accepted'),record=records[index].payload.record;
|
|
200
|
+
mutate(record.association);check(record,null);
|
|
201
|
+
for(let at=index;at<records.length;at++){
|
|
202
|
+
const {digest:ignored,...body}=records[at];body.previousDigest=at?records[at-1].digest:null;records[at]={...body,digest:digest(body)};
|
|
203
|
+
}
|
|
204
|
+
const {revision,...body}=saved,next={...body,records};
|
|
205
|
+
fs.writeFileSync(statePath,JSON.stringify({...next,revision:digest(next)})+'\n');
|
|
206
|
+
};
|
|
207
|
+
const status=async()=>{const run=await openControlRun(definition,'resume',parentExecution);
|
|
208
|
+
try{return await run.host.handle(request('status'));}finally{run.close();}};
|
|
209
|
+
try{
|
|
210
|
+
// A run that does not exist: replay cannot re-prove it, every live use refuses it.
|
|
211
|
+
forge(a=>{a.laterDeliveries[0].runId='ghost-run';a.laterDeliveries[0].packageDigest='e'.repeat(64);});
|
|
212
|
+
const ghost=await status();
|
|
213
|
+
assert.equal(ghost.code,'correction_review_required');assert.match(ghost.reason,/无法按其运行存档核实/);
|
|
214
|
+
// The real run with a package it never reviewed.
|
|
215
|
+
forge(a=>{a.laterDeliveries[0].packageDigest='f'.repeat(64);});
|
|
216
|
+
await assert.rejects(openControlRun(definition,'resume',parentExecution),{code:'fix_association_unverified'});
|
|
217
|
+
// A real step with a composition digest it does not give is re-proved at open.
|
|
218
|
+
forge(a=>{a.currentFilesDigest='0'.repeat(64);});
|
|
219
|
+
await assert.rejects(openControlRun(definition,'resume',parentExecution),{code:'fix_association_invalid'});
|
|
220
|
+
}finally{fs.writeFileSync(statePath,original);}
|
|
221
|
+
assert.equal((await status()).code,null);
|
|
222
|
+
}
|
|
223
|
+
}finally{serial?.close();parent?.close();}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
// Two files x.mjs/y.mjs; each writer captures its own baseline first, so its
|
|
227
|
+
// package records the reviewed before-state it actually saw.
|
|
228
|
+
function unitRoot(prefix,files){
|
|
229
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(isolated,prefix)));
|
|
230
|
+
for(const [name,content] of Object.entries({...files,'req.md':'r\n'}))fs.writeFileSync(path.join(root,name),content);
|
|
231
|
+
const checks=[{id:'c',command:['true'],outcome:'passed',exitCode:0,evidence:'ok'}];
|
|
232
|
+
const write=(runId,scope,edits)=>{
|
|
233
|
+
const baseline=captureReviewBaseline({root,identity:{repositoryId:'unit',runId,taskId:`T-${runId}`,attempt:1},scope,requirements:['req.md']});
|
|
234
|
+
for(const [name,content] of Object.entries(edits))fs.writeFileSync(path.join(root,name),content);
|
|
235
|
+
return {baseline,pkg:createReviewPackage({root,baseline,checks})};
|
|
236
|
+
};
|
|
237
|
+
return {root,write};
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
// Resolved steps, as the runner reads them from the named runs' stores.
|
|
241
|
+
const resolveFrom=runs=>steps=>steps.map(step=>{const found=runs[step.runId];
|
|
242
|
+
assert.equal(found.pkg.packageDigest,step.packageDigest);return {...step,pkg:found.pkg};});
|
|
243
|
+
|
|
244
|
+
test('#18 every later delivery and the QA fix apply in durable review order: (A,0)->(B,1)->(A,2)->(B,0), then the fix x B->C',()=>{
|
|
245
|
+
const {root,write}=unitRoot('ordered-',{'x.mjs':'base\n','y.mjs':'0\n'});
|
|
246
|
+
const scope=['x.mjs','y.mjs'];
|
|
247
|
+
// Parent (reviewed at 10), three later tasks (20, 30, 40), the fix (50).
|
|
248
|
+
const parent=write('parent',scope,{'x.mjs':'A\n'});
|
|
249
|
+
const d1=write('d1',scope,{'x.mjs':'B\n','y.mjs':'1\n'}),d2=write('d2',scope,{'x.mjs':'A\n','y.mjs':'2\n'});
|
|
250
|
+
const d3=write('d3',scope,{'x.mjs':'B\n','y.mjs':'0\n'}),fix=write('fix',['x.mjs'],{'x.mjs':'C\n'});
|
|
251
|
+
const deliveries=()=>[{runId:'d3',packages:[{pkg:d3.pkg,reviewedAt:40}]},{runId:'d1',packages:[{pkg:d1.pkg,reviewedAt:20}]},
|
|
252
|
+
{runId:'d2',packages:[{pkg:d2.pkg,reviewedAt:30}]}];
|
|
253
|
+
const resolve=resolveFrom({d1,d2,d3});
|
|
254
|
+
const input={root,baseline:parent.baseline,parentPackage:parent.pkg,fixPackages:[fix.pkg],after:10,deliveries,
|
|
255
|
+
fixTime:pkg=>pkg.packageDigest===fix.pkg.packageDigest?50:null};
|
|
256
|
+
assert.throws(()=>composeFixCode(input),{code:'fix_before_mismatch'});
|
|
257
|
+
const association=inspectFixCodeAssociation({...input,extend:true});
|
|
258
|
+
// Exactly the ordered list used, compact.
|
|
259
|
+
assert.equal(association.version,2);
|
|
260
|
+
assert.deepEqual(association.laterDeliveries,[['d1',d1],['d2',d2],['d3',d3]].map(([runId,item])=>({beforeFix:0,runId,packageDigest:item.pkg.packageDigest})));
|
|
261
|
+
const steps=association.laterDeliveries;
|
|
262
|
+
assert.equal(association.currentFilesDigest,digest(composeFixCode({...input,steps:resolve(steps)}).files));
|
|
263
|
+
assert.equal(digest(inspectFixCodeAssociation({...input,steps})),digest(association));
|
|
264
|
+
// Status replays the record as it is: a missing or reordered list does not
|
|
265
|
+
// compose, and a recorded step that is no longer a completed delivery is refused.
|
|
266
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps:[]}),{code:'fix_before_mismatch'});
|
|
267
|
+
for(const wrong of [steps.slice(1),[steps[1],steps[0],steps[2]]])
|
|
268
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps:wrong}),{code:'fix_current_code_unexplained'});
|
|
269
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps,deliveries:()=>deliveries().slice(1)}),{code:'fix_association_unverified'});
|
|
270
|
+
// The fix sits at its own durable time: without one there is no order, and
|
|
271
|
+
// reviewed before d3 it no longer finds x=B.
|
|
272
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,extend:true,fixTime:null}),{code:'fix_association_unverified'});
|
|
273
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,extend:true,fixTime:()=>35}),{code:'fix_before_mismatch'});
|
|
274
|
+
// Every delivery counts: leaving one out, or one reviewed before the parent, breaks the chain.
|
|
275
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,extend:true,deliveries:()=>deliveries().filter(item=>item.runId!=='d2')}),
|
|
276
|
+
error=>error.code==='fix_current_code_unexplained'&&error.paths.join()==='x.mjs,y.mjs');
|
|
277
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,extend:true,after:25}),{code:'fix_current_code_unexplained'});
|
|
278
|
+
// A later task reviewed after the fix is applied live on top, never recorded.
|
|
279
|
+
const tail=write('tail',['y.mjs'],{'y.mjs':'9\n'});
|
|
280
|
+
const withTail=()=>[...deliveries(),{runId:'tail',packages:[{pkg:tail.pkg,reviewedAt:60}]}];
|
|
281
|
+
assert.equal(digest(inspectFixCodeAssociation({...input,steps,deliveries:withTail})),digest(association));
|
|
282
|
+
fs.writeFileSync(path.join(root,'y.mjs'),'0\n');
|
|
283
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps,deliveries:withTail}),
|
|
284
|
+
error=>error.code==='fix_current_code_unexplained'&&error.paths.join()==='y.mjs');
|
|
285
|
+
inspectFixCodeAssociation({...input,steps});
|
|
286
|
+
// The root CM config is tolerated only where other runs' deliveries are read;
|
|
287
|
+
// without them the historical exact match holds.
|
|
288
|
+
fs.writeFileSync(path.join(root,'.cm-workflow.yml'),'version: 1\n');
|
|
289
|
+
inspectFixCodeAssociation({...input,steps});
|
|
290
|
+
const {deliveries:ignored,...bare}=input;
|
|
291
|
+
assert.throws(()=>inspectFixCodeAssociation({...bare,root,baseline:d3.baseline,parentPackage:d3.pkg,fixPackages:[fix.pkg]}),
|
|
292
|
+
{code:'fix_current_code_unexplained'});
|
|
293
|
+
fs.rmSync(path.join(root,'.cm-workflow.yml'));
|
|
294
|
+
inspectFixCodeAssociation({...bare,root,baseline:d3.baseline,parentPackage:d3.pkg,fixPackages:[fix.pkg]});
|
|
295
|
+
if(process.platform!=='win32'){
|
|
296
|
+
// A mode-only change to the fixed file after acceptance is not explained either.
|
|
297
|
+
fs.chmodSync(path.join(root,'x.mjs'),0o755);
|
|
298
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps}),{code:'fix_current_code_unexplained'});
|
|
299
|
+
fs.chmodSync(path.join(root,'x.mjs'),0o644);
|
|
300
|
+
inspectFixCodeAssociation({...input,steps});
|
|
301
|
+
// Nor is one on a file whose content no reviewed package touched.
|
|
302
|
+
fs.chmodSync(path.join(root,'req.md'),0o755);
|
|
303
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,steps}),
|
|
304
|
+
error=>error.code==='fix_current_code_unexplained'&&error.paths.join()==='req.md');
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test('#18 a delivery reviewed before the fix but committed after its acceptance is applied after it; the next fix records it before itself',()=>{
|
|
309
|
+
const {root,write}=unitRoot('late-',{'x.mjs':'0\n','late.mjs':'0\n','tail.mjs':'0\n'});
|
|
310
|
+
const parent=write('parent',['x.mjs'],{'x.mjs':'A\n'});
|
|
311
|
+
// late is reviewed at 20, before the fix's final review (30), but is still unfinished when the fix is accepted.
|
|
312
|
+
const late=write('late',['late.mjs'],{'late.mjs':'1\n'}),fix=write('fix',['x.mjs'],{'x.mjs':'B\n'});
|
|
313
|
+
const input={root,baseline:parent.baseline,parentPackage:parent.pkg,after:10,fixTime:pkg=>({[fix.pkg.packageDigest]:30})[pkg.packageDigest]??null};
|
|
314
|
+
// At acceptance its change is not in the tree and the run is not a completed delivery.
|
|
315
|
+
fs.writeFileSync(path.join(root,'late.mjs'),'0\n');
|
|
316
|
+
const accepted=inspectFixCodeAssociation({...input,fixPackages:[fix.pkg],extend:true,deliveries:()=>[]});
|
|
317
|
+
assert.equal(accepted.version,1);
|
|
318
|
+
// It commits later on normal recovery: the accepted record still holds.
|
|
319
|
+
fs.writeFileSync(path.join(root,'late.mjs'),'1\n');
|
|
320
|
+
const all=[{runId:'late',packages:[{pkg:late.pkg,reviewedAt:20}]}];
|
|
321
|
+
assert.equal(digest(inspectFixCodeAssociation({...input,fixPackages:[fix.pkg],deliveries:()=>all})),digest(accepted));
|
|
322
|
+
// It still applies strictly after the fix: an unreviewed change to its file is named.
|
|
323
|
+
fs.writeFileSync(path.join(root,'late.mjs'),'X\n');
|
|
324
|
+
assert.throws(()=>inspectFixCodeAssociation({...input,fixPackages:[fix.pkg],deliveries:()=>all}),
|
|
325
|
+
error=>error.code==='fix_current_code_unexplained'&&error.paths.join()==='late.mjs');
|
|
326
|
+
fs.writeFileSync(path.join(root,'late.mjs'),'1\n');
|
|
327
|
+
// A second fix (final review at 50) takes every delivery not yet recorded and reviewed before it, in order.
|
|
328
|
+
const tail=write('tail',['tail.mjs'],{'tail.mjs':'1\n'}),second=write('second',['x.mjs'],{'x.mjs':'C\n'});
|
|
329
|
+
const both=[...all,{runId:'tail',packages:[{pkg:tail.pkg,reviewedAt:40}]}];
|
|
330
|
+
const time=pkg=>({[fix.pkg.packageDigest]:30,[second.pkg.packageDigest]:50})[pkg.packageDigest]??null;
|
|
331
|
+
const extended=inspectFixCodeAssociation({...input,fixTime:time,fixPackages:[fix.pkg,second.pkg],extend:true,
|
|
332
|
+
steps:accepted.laterDeliveries??[],deliveries:()=>both});
|
|
333
|
+
assert.deepEqual(extended.laterDeliveries.map(step=>[step.beforeFix,step.runId]),[[1,'late'],[1,'tail']]);
|
|
334
|
+
assert.equal(extended.currentFilesDigest,digest(composeFixCode({baseline:parent.baseline,parentPackage:parent.pkg,
|
|
335
|
+
fixPackages:[fix.pkg,second.pkg],steps:resolveFrom({late,tail})(extended.laterDeliveries)}).files));
|
|
336
|
+
assert.equal(digest(inspectFixCodeAssociation({...input,fixPackages:[fix.pkg,second.pkg],steps:extended.laterDeliveries,deliveries:()=>both})),
|
|
337
|
+
digest(extended));
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test('#18 a large history stays a compact record: 200 deliveries of 20 files each before the fix',()=>{
|
|
341
|
+
const names=Array.from({length:20},(_,index)=>`g${String(index).padStart(2,'0')}.mjs`);
|
|
342
|
+
const {root,write}=unitRoot('large-',{...Object.fromEntries(names.map(name=>[name,'0\n'])),'value.mjs':'0\n'});
|
|
343
|
+
const parent=write('parent',['value.mjs'],{'value.mjs':'1\n'});
|
|
344
|
+
const runs=Array.from({length:200},(_,index)=>{const runId=`r${String(index).padStart(3,'0')}`;
|
|
345
|
+
return {runId,...write(runId,names,Object.fromEntries(names.map(name=>[name,`${index+1}\n`])))};});
|
|
346
|
+
const fix=write('fix',['value.mjs'],{'value.mjs':'2\n'});
|
|
347
|
+
const association=inspectFixCodeAssociation({root,baseline:parent.baseline,parentPackage:parent.pkg,fixPackages:[fix.pkg],extend:true,
|
|
348
|
+
after:10,deliveries:()=>runs.map((item,index)=>({runId:item.runId,packages:[{pkg:item.pkg,reviewedAt:20+index}]})),fixTime:()=>1000});
|
|
349
|
+
assert.equal(association.laterDeliveries.length,200);
|
|
350
|
+
// 4,000 file transitions, yet the record stays well under the journal's 1 MiB record limit.
|
|
351
|
+
assert.ok(Buffer.byteLength(JSON.stringify(association))<32*1024,String(Buffer.byteLength(JSON.stringify(association))));
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('#18 a 13-file delivery and 13 later one-file deliveries before the fix are all recorded, in order, quickly',()=>{
|
|
355
|
+
const names=Array.from({length:13},(_,index)=>`f${String(index).padStart(2,'0')}.mjs`);
|
|
356
|
+
const {root,write}=unitRoot('many-',{...Object.fromEntries(names.map(name=>[name,'0\n'])),'value.mjs':'0\n'});
|
|
357
|
+
const parent=write('parent',['value.mjs'],{'value.mjs':'1\n'});
|
|
358
|
+
const wide=write('wide',names,Object.fromEntries(names.map(name=>[name,'1\n'])));
|
|
359
|
+
const narrow=names.map((name,index)=>{const runId=`n${String(index).padStart(2,'0')}`;return {runId,...write(runId,[name],{[name]:'2\n'})};});
|
|
360
|
+
const fix=write('fix',['value.mjs'],{'value.mjs':'2\n'});
|
|
361
|
+
const deliveries=()=>[...narrow.map((item,index)=>({runId:item.runId,packages:[{pkg:item.pkg,reviewedAt:30+index}]})).reverse(),
|
|
362
|
+
{runId:'wide',packages:[{pkg:wide.pkg,reviewedAt:20}]}];
|
|
363
|
+
const started=process.hrtime.bigint();
|
|
364
|
+
const association=inspectFixCodeAssociation({root,baseline:parent.baseline,parentPackage:parent.pkg,fixPackages:[fix.pkg],extend:true,
|
|
365
|
+
after:10,deliveries,fixTime:()=>100});
|
|
366
|
+
assert.ok(Number(process.hrtime.bigint()-started)/1e6<5000);
|
|
367
|
+
assert.deepEqual(association.laterDeliveries.map(item=>item.runId),['wide',...narrow.map(item=>item.runId)]);
|
|
368
|
+
assert.ok(association.laterDeliveries.every(item=>item.beforeFix===0));
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('#18 the accepted-fix size check mirrors the store exactly: a record one byte over is refused before append',()=>{
|
|
372
|
+
const specsRoot=fs.realpathSync(fs.mkdtempSync(path.join(isolated,'store-')));
|
|
373
|
+
const options={specsRoot,identity:{repositoryId:'size',runId:'size-run'},fingerprints:{workflow:'a'.repeat(64),config:'b'.repeat(64),inputs:'c'.repeat(64)}};
|
|
374
|
+
let store=openExecutionStore({...options,create:true});
|
|
375
|
+
try{
|
|
376
|
+
const input=(id,n)=>({id,kind:'result',payload:{s:'x'.repeat(n)},expectedRevision:store.snapshot().revision});
|
|
377
|
+
const limit=1024*1024-Buffer.byteLength(JSON.stringify({s:''}));
|
|
378
|
+
assert.equal(appendFits(store.snapshot(),input('fits',limit)),true);
|
|
379
|
+
store.append(input('fits',limit));
|
|
380
|
+
assert.equal(appendFits(store.snapshot(),input('over',limit+1)),false);
|
|
381
|
+
assert.throws(()=>store.append(input('over',limit+1)),{code:'limit_exceeded'});
|
|
382
|
+
}finally{store.close();}
|
|
383
|
+
});
|