@aibyzero/cm-workflow 0.16.2 → 0.16.3
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 +4 -0
- package/CHANGELOG.md +138 -0
- package/README.md +2 -2
- package/VERSION +1 -1
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +46 -7
- package/docs/next-steps.md +110 -0
- package/docs/untested-branches.md +24 -18
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-tool-preview.mjs +45 -6
- package/runtime/js/cm-ai/cm-ai-admission.mjs +5 -0
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +22 -12
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +70 -5
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +5 -5
- package/runtime/js/cm-ai/drive-core.mjs +68 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +42 -9
- package/runtime/js/cm-ai/effect-contract.mjs +4 -3
- package/runtime/js/cm-ai/execution-snapshot.mjs +40 -0
- package/runtime/js/cm-ai/host-conversation-execution.mjs +8 -5
- package/runtime/js/cm-ai/host-handoff.mjs +9 -14
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +12 -7
- package/runtime/js/cm-ai/host-session.mjs +2 -2
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/qa-config-revision.mjs +85 -0
- package/runtime/js/cm-ai/review-evidence-file.mjs +18 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +144 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +34 -0
- package/runtime/js/cm-ai/task-runner.mjs +41 -8
- package/runtime/js/cm-fix/cause-invocation.mjs +9 -5
- package/runtime/js/cm-fix/cause-package.mjs +21 -0
- package/runtime/js/cm-fix/dossier.mjs +40 -1
- package/runtime/js/cm-fix/execution.mjs +360 -83
- package/runtime/js/cm-fix/host.mjs +7 -3
- package/runtime/js/cm-fix/layout.mjs +14 -6
- package/runtime/js/cm-fix/progress.mjs +14 -0
- package/runtime/js/cm-fix/protected-edits.mjs +1 -1
- package/runtime/js/cm-fix/red-test.mjs +7 -6
- package/runtime/js/cm-fix/regression-evidence.mjs +6 -3
- package/runtime/js/cm-fix/regression.mjs +16 -10
- package/runtime/js/cm-fix/repair.mjs +16 -13
- package/runtime/js/cm-fix/test-author.mjs +2 -1
- package/runtime/js/cm-fix/test-extension.mjs +45 -0
- package/runtime/js/cm-prd/accepted-design.mjs +28 -9
- package/runtime/js/cm-prd/analysis.mjs +68 -16
- package/runtime/js/cm-prd/change.mjs +21 -1
- package/runtime/js/cm-prd/draft-save.mjs +96 -2
- package/runtime/js/cm-prd/failed-correction.mjs +51 -0
- package/runtime/js/cm-prd/inputs-replaced.mjs +122 -0
- package/runtime/js/cm-prd/review-correction.mjs +3 -0
- package/runtime/js/cm-prd/review-disposition.mjs +33 -15
- package/runtime/js/cm-prd/review-findings.mjs +2 -2
- package/runtime/js/cm-prd/review-host.mjs +2 -0
- package/runtime/js/cm-prd/review-preparation.mjs +28 -1
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check-revision.mjs +81 -0
- package/runtime/js/cm-prd/session.mjs +5 -5
- package/runtime/js/cm-prd/split-design.mjs +67 -0
- package/runtime/js/cm-prd/summary.mjs +53 -8
- package/runtime/js/cm-refactor/workflow.mjs +100 -19
- package/scripts/cm-ai-batch-drive.mjs +251 -0
- package/scripts/cm-ai-batch-drive.test.mjs +152 -0
- package/scripts/cm-ai-contracts.test.mjs +30 -0
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +62 -0
- package/scripts/cm-ai-drive.mjs +334 -0
- package/scripts/cm-ai-drive.test.mjs +251 -0
- package/scripts/cm-ai-fix-integration.test.mjs +1 -1
- package/scripts/cm-ai-host.mjs +41 -18
- package/scripts/cm-ai-host.test.mjs +37 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +328 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +255 -0
- package/scripts/cm-ai-qa-fix-policy.test.mjs +79 -0
- package/scripts/cm-ai-review-timeout.test.mjs +30 -0
- package/scripts/cm-ai-run.mjs +59 -11
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +29 -0
- package/scripts/cm-ai-session-chain.test.mjs +261 -0
- package/scripts/cm-ai-supersede.test.mjs +320 -0
- package/scripts/cm-check-drive.mjs +93 -0
- package/scripts/cm-check-drive.test.mjs +62 -0
- package/scripts/cm-check-host.test.mjs +47 -0
- package/scripts/cm-claude-probe.test.mjs +117 -2
- package/scripts/cm-fix-abandon.test.mjs +383 -0
- package/scripts/cm-fix-cause-package.test.mjs +31 -1
- package/scripts/cm-fix-cross-session-host.test.mjs +17 -5
- package/scripts/cm-fix-drive.mjs +168 -0
- package/scripts/cm-fix-drive.test.mjs +117 -0
- package/scripts/cm-fix-escalation.test.mjs +214 -0
- package/scripts/cm-fix-execution.test.mjs +26 -0
- package/scripts/cm-fix-host.mjs +4 -2
- package/scripts/cm-fix-observation-dossier.test.mjs +34 -9
- package/scripts/cm-fix-qa-source.test.mjs +3 -3
- package/scripts/cm-fix-session-chain.test.mjs +244 -0
- package/scripts/cm-fix-test-extension.test.mjs +246 -0
- package/scripts/cm-fix-visual-carrier.test.mjs +66 -0
- package/scripts/cm-host-handoff.test.mjs +37 -0
- package/scripts/cm-idea-drive.mjs +99 -0
- package/scripts/cm-idea-drive.test.mjs +50 -0
- package/scripts/cm-init-drive.mjs +191 -0
- package/scripts/cm-init-drive.test.mjs +59 -0
- package/scripts/cm-log-event.mjs +9 -0
- package/scripts/cm-prd-design-phase.test.mjs +355 -15
- package/scripts/cm-prd-drive.mjs +308 -0
- package/scripts/cm-prd-drive.test.mjs +154 -0
- package/scripts/cm-prd-host.mjs +46 -17
- package/scripts/cm-prd-inputs-replaced.test.mjs +237 -0
- package/scripts/cm-prd-review-disposition.test.mjs +133 -7
- package/scripts/cm-prd-review-gate.mjs +23 -4
- package/scripts/cm-prd-self-check-revision.test.mjs +302 -0
- package/scripts/cm-prd-summary.test.mjs +48 -4
- package/scripts/cm-refactor-drive.mjs +237 -0
- package/scripts/cm-refactor-drive.test.mjs +77 -0
- package/scripts/cm-refactor-gaps.test.mjs +276 -0
- package/scripts/cm-refactor-host.test.mjs +1 -48
- package/scripts/cm-refactor-judge-revision.test.mjs +253 -0
- package/scripts/cm-test-drive.mjs +132 -0
- package/scripts/cm-test-drive.test.mjs +91 -0
- package/scripts/cm-test-session.test.mjs +117 -0
- package/scripts/correction-check.test.mjs +38 -0
- package/scripts/fixtures/claude-model-marker.mjs +6 -0
- package/scripts/fixtures/claude-review-process.mjs +7 -0
- package/scripts/fixtures/cm-refactor.mjs +56 -0
- package/skills/cm-ai/SKILL.md +1 -1
- package/skills/cm-ai/references/N4-review.md +2 -0
- package/skills/cm-ai/references/N8-finish.md +1 -0
- package/skills/cm-ai/references/js-host.md +80 -3
- package/skills/cm-check/references/js-host.md +2 -0
- package/skills/cm-fix/SKILL.md +11 -4
- package/skills/cm-fix/references/js-host.md +67 -2
- package/skills/cm-fix/references/test-extension.md +57 -0
- package/skills/cm-idea/references/js-host.md +2 -0
- package/skills/cm-init/references/js-host.md +2 -0
- package/skills/cm-prd/SKILL.md +8 -8
- package/skills/cm-prd/references/js-change-recovery.md +41 -0
- package/skills/cm-prd/references/js-host.md +64 -2
- package/skills/cm-prd/references/spec-self-check.md +14 -2
- package/skills/cm-refactor/SKILL.md +5 -0
- package/skills/cm-refactor/references/js-batch.md +3 -1
- package/skills/cm-refactor/references/js-host.md +49 -0
- package/skills/cm-test/references/js-host.md +5 -0
- package/skills/cm-test/references/unit-coverage.md +2 -2
|
@@ -0,0 +1,79 @@
|
|
|
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 {recordCmAiQaDecision,recordCmAiQaRun} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
7
|
+
import {readHostQaFixHandoff} from '../runtime/js/cm-ai/host-qa-fix.mjs';
|
|
8
|
+
|
|
9
|
+
// policies.auto_fix 决定 QA 失败之后往哪走,模板把三个取值都写给用户看
|
|
10
|
+
// (explicit | never | auto),但 never 从来没有测试走过——docs/untested-branches.md
|
|
11
|
+
// 的 A 类第一条。这里把整张真值表钉死,包括「轮次耗尽压过策略」这条优先级:
|
|
12
|
+
// 那正是只测了一两个取值时最容易写反的地方。
|
|
13
|
+
function fixture(t,{autoFix=null,rounds=1}={}){
|
|
14
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'qa-fix-policy-')));
|
|
15
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
16
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),logHome=path.join(root,'logs');
|
|
17
|
+
fs.mkdirSync(path.join(specsDir,'.reviews'),{recursive:true});fs.mkdirSync(codeProject);
|
|
18
|
+
// 不写配置文件时走 loadConfig 的缺省,这本身也是一条要覆盖的路径。
|
|
19
|
+
if(autoFix!==null)fs.writeFileSync(path.join(codeProject,'.cm-workflow.json'),
|
|
20
|
+
JSON.stringify({version:1,policies:{auto_fix:autoFix}}));
|
|
21
|
+
const identity={repositoryId:'qa-policy',runId:'qa-policy-run',taskId:'T-001',attempt:2};
|
|
22
|
+
const binding={specsDir,codeProject,feature:'1.work',identity,packageDigest:'a'.repeat(64)};
|
|
23
|
+
const report=path.join(specsDir,'.reviews','qa-failure.md');
|
|
24
|
+
fs.writeFileSync(report,'Synthetic QA FAIL');
|
|
25
|
+
recordCmAiQaDecision({...binding,logHome,decision:{decisionId:'qa-decision',identity,
|
|
26
|
+
packageDigest:binding.packageDigest,status:'triggered',reason:'fixture',score:null,at:'2026-09-08T01:00:00Z'}});
|
|
27
|
+
const qa={...binding,mode:'commands',caseCount:1,logHome};
|
|
28
|
+
let testRunId;
|
|
29
|
+
for(let round=1;round<=rounds;round++){
|
|
30
|
+
testRunId=`qa-round-${round}`;
|
|
31
|
+
const step={...qa,testRunId,...(round>1?{qaRound:round}:{})};
|
|
32
|
+
recordCmAiQaRun({...step,phase:'start'});
|
|
33
|
+
recordCmAiQaRun({...step,phase:'complete',result:{result:'FAIL',passed:0,failed:1,blocked:0,report}});
|
|
34
|
+
}
|
|
35
|
+
return {binding,testRunId};
|
|
36
|
+
}
|
|
37
|
+
const handoffFor=(t,options)=>{
|
|
38
|
+
const {binding,testRunId}=fixture(t,options);
|
|
39
|
+
return readHostQaFixHandoff({...binding,testRunId});
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
test('every auto_fix value routes a QA failure to its own outcome',t=>{
|
|
43
|
+
// 三个取值各自对应一种去向:never 直接堵死,explicit 要人点头,auto 才派发。
|
|
44
|
+
for(const [autoFix,status,reason] of [
|
|
45
|
+
['never','blocked','auto_fix_disabled'],
|
|
46
|
+
['explicit','authorization_required','fix_authorization_required'],
|
|
47
|
+
['auto','dispatch_required','fix_dispatch_required']]){
|
|
48
|
+
const handoff=handoffFor(t,{autoFix});
|
|
49
|
+
assert.equal(handoff.policy,autoFix);
|
|
50
|
+
assert.equal(handoff.status,status,autoFix);
|
|
51
|
+
assert.equal(handoff.reason,reason,autoFix);
|
|
52
|
+
// 无论哪种去向,交接本身都不是派发凭据。
|
|
53
|
+
assert.equal(handoff.execution,'not_started',autoFix);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
test('the round limit overrides the policy, including the two that would otherwise proceed',t=>{
|
|
58
|
+
// 第三轮之后无论策略是什么都堵死,而且理由要说是轮次耗尽,不是策略。
|
|
59
|
+
// never 本来就 blocked,容易掩盖这条优先级,所以三个取值都验。
|
|
60
|
+
for(const autoFix of ['never','explicit','auto']){
|
|
61
|
+
const handoff=handoffFor(t,{autoFix,rounds:3});
|
|
62
|
+
assert.equal(handoff.status,'blocked',autoFix);
|
|
63
|
+
assert.equal(handoff.reason,'qa_round_limit',autoFix);
|
|
64
|
+
assert.equal(handoff.policy,autoFix,'被限流不代表把策略改写掉');
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('an unreadable auto_fix value is refused instead of being treated as one of the three',t=>{
|
|
69
|
+
assert.throws(()=>handoffFor(t,{autoFix:'sometimes'}),error=>
|
|
70
|
+
// 配置校验先拦下来也算通过:要的是「不会被当成三者之一放行」。
|
|
71
|
+
error.code==='qa_fix_policy_unavailable'||/auto_fix/.test(String(error.message)));
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('the default configuration still resolves to one of the three outcomes',t=>{
|
|
75
|
+
// 项目没写 .cm-workflow.json 时也必须落在契约内,不能是 undefined 或崩掉。
|
|
76
|
+
const handoff=handoffFor(t,{autoFix:null});
|
|
77
|
+
assert.ok(['never','explicit','auto'].includes(handoff.policy));
|
|
78
|
+
assert.ok(['blocked','authorization_required','dispatch_required'].includes(handoff.status));
|
|
79
|
+
});
|
|
@@ -79,6 +79,36 @@ const timeoutRun=(request,{onEvent})=>{
|
|
|
79
79
|
};
|
|
80
80
|
const retryEffect=(f,attempt=1)=>({...f.effect('review',attempt),id:`review-${attempt}-retry-1`});
|
|
81
81
|
|
|
82
|
+
test('V3 expired dispatch grant is journaled as grant_expired without adapter dispatch',()=>fixture(async f=>{
|
|
83
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
84
|
+
const end=await runner.executeEffect(f.effect('review'));
|
|
85
|
+
assert.equal(end.state,'pending_review');assert.equal(end.code,'grant_expired');assert.equal(f.dispatches(),0);
|
|
86
|
+
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
87
|
+
assert.equal(end.reviewInvocation.result.reason,'grant_expired');
|
|
88
|
+
assert.equal(end.reviewInvocation.result.dispatchAt,200);
|
|
89
|
+
assert.equal(end.reviewInvocation.registration.grant.expiresAt,150);
|
|
90
|
+
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
91
|
+
const saved=f.getStore().snapshot();
|
|
92
|
+
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'grant_expired');
|
|
93
|
+
assert.deepEqual(saved.records.slice(-3).map(record=>record.payload.type),
|
|
94
|
+
['review-invocation-registered','review-invocation-result','effect-checkpoint']);
|
|
95
|
+
assert.deepEqual(f.reopen().status(),end);
|
|
96
|
+
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{grant.expiresAt=150;})}));
|
|
97
|
+
|
|
98
|
+
test('V3 non-monotonic dispatch clock is journaled as clock_invalid without adapter dispatch',()=>fixture(async f=>{
|
|
99
|
+
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
100
|
+
const end=await runner.executeEffect(f.effect('review'));
|
|
101
|
+
assert.equal(end.state,'pending_review');assert.equal(end.code,'clock_invalid');assert.equal(f.dispatches(),0);
|
|
102
|
+
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
103
|
+
assert.equal(end.reviewInvocation.result.reason,'clock_invalid');
|
|
104
|
+
assert.equal(end.reviewInvocation.result.dispatchAt,99);
|
|
105
|
+
assert.equal(end.reviewInvocation.registration.registeredAt,101);
|
|
106
|
+
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
107
|
+
const saved=f.getStore().snapshot();
|
|
108
|
+
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'clock_invalid');
|
|
109
|
+
assert.deepEqual(f.reopen().status(),end);
|
|
110
|
+
},{times:[100,101,99]}));
|
|
111
|
+
|
|
82
112
|
test('runner timer without a result shares pending/blocked timeout transitions and replay',()=>fixture(async f=>{
|
|
83
113
|
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
84
114
|
const end=await runner.executeEffect(f.effect('review'));
|
package/scripts/cm-ai-run.mjs
CHANGED
|
@@ -9,6 +9,10 @@ import {resolveCodeProjects,codeProjectPaths,assertCodeProjectSelections} from '
|
|
|
9
9
|
import {preQaConfigurations,readQaAttachment} from '../runtime/js/cm-ai/qa-attachment.mjs';
|
|
10
10
|
import {recordCmAiQaAttachment} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
11
11
|
import {isSupportedExecutionPlatform} from '../runtime/js/cm-ai/execution-platform.mjs';
|
|
12
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
13
|
+
import {previousQaMaterial,qaConfigurationSlice,qaInvariantDigest,qaRevisionChain,verifyQaRevisionMaterial} from '../runtime/js/cm-ai/qa-config-revision.mjs';
|
|
14
|
+
import {inspectCmAiQaRevisionTarget,recordCmAiQaConfigurationRevision} from '../runtime/js/cm-ai/cm-ai-qa-log.mjs';
|
|
15
|
+
import {prepareReviewedEvidenceSupersession,archiveReviewedEvidence,recordEvidenceSupersession} from '../runtime/js/cm-ai/reviewed-evidence-supersede.mjs';
|
|
12
16
|
|
|
13
17
|
const usage='cm-ai-run.mjs serve --config RUN_DEFINITION.json --mode create|resume (no provider dispatch)\nNew runs bind approved specification material from specsDir; requirements may be [] or supplemental code-project files. Manifest drift blocks as spec_drift; legacy journals retain their original format.';
|
|
14
18
|
const fail=code=>{throw Object.assign(new Error(code),{code});};
|
|
@@ -167,11 +171,15 @@ export function validateRunDefinition(input){
|
|
|
167
171
|
return value;
|
|
168
172
|
}
|
|
169
173
|
|
|
170
|
-
export async function openControlRun(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,parallelSelection=null}={}){
|
|
174
|
+
export async function openControlRun(definition,mode,execution=null,{rerunUnknownQa=false,rerunBlockedQa=false,parallelSelection=null,qaConfigRevision=null,supersedeReason=null}={}){
|
|
171
175
|
// Check before importing node:sqlite: legacy Node users get a useful error.
|
|
172
176
|
if(!isSupportedExecutionPlatform())fail('unsupported_runner_platform');
|
|
173
177
|
const {conversationProtection}=await import('../runtime/js/cm-ai/host-conversation-execution.mjs');
|
|
174
178
|
if(!['create','resume'].includes(mode))fail('invalid_mode');
|
|
179
|
+
if(supersedeReason!==null&&mode!=='create')fail('supersede_unavailable');
|
|
180
|
+
if(qaConfigRevision!==null&&(mode!=='resume'||!execution?.qaExecutor||rerunUnknownQa||rerunBlockedQa
|
|
181
|
+
||typeof qaConfigRevision.reason!=='string'||!qaConfigRevision.reason.trim()||qaConfigRevision.reason.length>500
|
|
182
|
+
||/[\r\n\0]/.test(qaConfigRevision.reason)||!qaConfigRevision.previousWorkflow))fail('qa_revision_authorization_required');
|
|
175
183
|
if(typeof rerunUnknownQa!=='boolean'||typeof rerunBlockedQa!=='boolean'||rerunUnknownQa&&rerunBlockedQa
|
|
176
184
|
||(rerunUnknownQa||rerunBlockedQa)&&(mode!=='resume'||!execution?.qaExecutor))fail('qa_recovery_authorization_required');
|
|
177
185
|
const {openTaskExecutionStore}=await import('../runtime/js/cm-ai/task-owner.mjs');
|
|
@@ -202,6 +210,11 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
202
210
|
&&definition.specsDir.startsWith(definition.codeProject+path.sep)&&!protection)fail('nested_specs_protection_required');
|
|
203
211
|
}
|
|
204
212
|
const {specsDir,codeProject,feature,identity,scope,requirements}=definition;
|
|
213
|
+
const tasksPath=path.join(specsDir,feature,'tasks.md');
|
|
214
|
+
const featureSlug=feature.replace(/^\d+\./,'');
|
|
215
|
+
const reviewsDir=path.join(specsDir,'.reviews');
|
|
216
|
+
const supersession=mode==='create'&&supersedeReason!==null
|
|
217
|
+
?prepareReviewedEvidenceSupersession({specsDir,codeProject,feature,identity,reason:supersedeReason,tasksPath}):null;
|
|
205
218
|
let bootstrapConfig=null;
|
|
206
219
|
if(execution?.bootstrap){
|
|
207
220
|
const {bootstrapConfiguration}=await import('../runtime/js/cm-ai/host-bootstrap.mjs');
|
|
@@ -223,9 +236,6 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
223
236
|
const admission=inspectCmAiAdmission({specsDir,codeProject});
|
|
224
237
|
if(mode==='create'&&admission.state!=='ready')return {blocked:admission,close:()=>{}};
|
|
225
238
|
if(mode==='create'&&!matchesCmAiTaskSelection(admission,feature,identity.taskId,parallelSelection))fail('task_selection_mismatch');
|
|
226
|
-
const tasksPath=path.join(specsDir,feature,'tasks.md');
|
|
227
|
-
const featureSlug=feature.replace(/^\d+\./,'');
|
|
228
|
-
const reviewsDir=path.join(specsDir,'.reviews');
|
|
229
239
|
const handoffs=[1,2].map(attempt=>path.join(reviewsDir,`${featureSlug}-${identity.taskId}-a${attempt}-handoff.json`));
|
|
230
240
|
// Reuse the runner's real validator before creating durable state. A failed
|
|
231
241
|
// baseline must not strand an otherwise unused run ID.
|
|
@@ -251,22 +261,36 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
251
261
|
config:sha(configMaterial),inputs:sha({feature,task:identity.taskId})};
|
|
252
262
|
const storeOptions={tasksPath,feature:featureSlug,specsRoot:specsDir,
|
|
253
263
|
identity:{repositoryId:identity.repositoryId,runId:identity.runId},fingerprints,create:mode==='create'};
|
|
254
|
-
let store,attaching=false;
|
|
264
|
+
let store,attaching=false,priorMaterial=null;
|
|
265
|
+
if(qaConfigRevision!==null)priorMaterial=previousQaMaterial(configMaterial,qaConfigRevision.previousWorkflow);
|
|
255
266
|
try{store=openTaskExecutionStore(storeOptions);}
|
|
256
267
|
catch(error){
|
|
257
268
|
if(mode!=='resume'||error.code!=='fingerprint_mismatch')throw error;
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
269
|
+
const snapshot=readExecutionSnapshot({specsRoot:specsDir,identity:storeOptions.identity});
|
|
270
|
+
const last=qaRevisionChain(snapshot).revisions.at(-1);
|
|
271
|
+
if(priorMaterial&&last?.toFingerprint===fingerprints.config&&last.fromFingerprint===sha(priorMaterial)
|
|
272
|
+
&&last.reason===qaConfigRevision.reason)priorMaterial=null;
|
|
273
|
+
if(priorMaterial||snapshot.records.some(row=>row.payload.type==='qa-config-revised')){
|
|
274
|
+
verifyQaRevisionMaterial(snapshot,configMaterial,priorMaterial);
|
|
275
|
+
store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:snapshot.fingerprints.config}});
|
|
276
|
+
}
|
|
277
|
+
if(!store){
|
|
278
|
+
for(const previous of preQaConfigurations(configMaterial)){
|
|
279
|
+
try{store=openTaskExecutionStore({...storeOptions,fingerprints:{...fingerprints,config:sha(previous)}});break;}
|
|
280
|
+
catch(cause){if(cause.code!=='fingerprint_mismatch')throw cause;}
|
|
281
|
+
}
|
|
282
|
+
if(!store)throw error;
|
|
283
|
+
attaching=true;
|
|
261
284
|
}
|
|
262
|
-
if(!store)throw error;
|
|
263
|
-
attaching=true;
|
|
264
285
|
}
|
|
265
286
|
try{
|
|
287
|
+
const chain=qaRevisionChain(store.snapshot());
|
|
288
|
+
if(chain.revisions.length&&chain.fingerprint!==fingerprints.config&&!priorMaterial)fail('fingerprint_mismatch');
|
|
289
|
+
if(chain.revisions.length||priorMaterial)verifyQaRevisionMaterial(store.snapshot(),configMaterial,priorMaterial);
|
|
266
290
|
const attachments=store.snapshot().records.filter(row=>row.payload.type==='qa-attached');
|
|
267
291
|
if(attachments.length>1)fail('qa_attachment_duplicate');
|
|
268
292
|
const attached=attachments.length?readQaAttachment(attachments[0].payload.record):null;
|
|
269
|
-
if(attached&&attached.qaFingerprint!==fingerprints.config)fail('fingerprint_mismatch');
|
|
293
|
+
if(attached&&!chain.revisions.length&&!priorMaterial&&attached.qaFingerprint!==fingerprints.config)fail('fingerprint_mismatch');
|
|
270
294
|
if(attaching&&store.snapshot().records.length===0)fail('qa_attach_not_completed');
|
|
271
295
|
let runnerMode=mode;
|
|
272
296
|
if(mode==='resume'&&store.snapshot().records.length===0){
|
|
@@ -292,6 +316,13 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
292
316
|
entry:{specsDir,codeProject,feature,identity,rerunUnknownQa,rerunBlockedQa,...(parallelSelection===null?{}:{parallelSelection}),...(execution===null?{}:{hostDecision:execution.hostDecision,
|
|
293
317
|
...Object.fromEntries(['developmentAttempt','hostDecisionProvider','qaDecisionProvider','qaLogHome','qaExecutor','applicableAgentFiles','documentationProvider','documentationResult'].filter(key=>Object.hasOwn(execution,key)).map(key=>[key,execution[key]]))})},
|
|
294
318
|
});
|
|
319
|
+
const recorded=store.snapshot().records.find(row=>row.payload.type==='evidence-superseded')?.payload.record??null;
|
|
320
|
+
if(supersession!==null||recorded!==null){
|
|
321
|
+
const record=host.supersedeEvidence(supersession??recorded);
|
|
322
|
+
archiveReviewedEvidence(reviewsDir,record);
|
|
323
|
+
recordEvidenceSupersession({specsDir,codeProject,identity,record,
|
|
324
|
+
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
325
|
+
}
|
|
295
326
|
if(attaching||attached){
|
|
296
327
|
const record=host.attachQa(attached??{version:1,qaFingerprint:fingerprints.config,
|
|
297
328
|
attachedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),hostContextId:execution.configuration.hostContextId});
|
|
@@ -300,6 +331,23 @@ export async function openControlRun(definition,mode,execution=null,{rerunUnknow
|
|
|
300
331
|
recordCmAiQaAttachment({specsDir,codeProject,feature,identity,record,
|
|
301
332
|
...(execution.qaLogHome?{logHome:execution.qaLogHome}:{})});
|
|
302
333
|
}
|
|
334
|
+
const qaBinding={specsDir,codeProject,feature,identity,
|
|
335
|
+
...(execution?.qaLogHome?{logHome:execution.qaLogHome}:{})};
|
|
336
|
+
// Repair a crash after the journal append, before the log supersession.
|
|
337
|
+
for(const record of chain.revisions)recordCmAiQaConfigurationRevision({...qaBinding,identity:{...identity,attempt:record.taskAttempt},packageDigest:record.packageDigest},record);
|
|
338
|
+
if(priorMaterial){
|
|
339
|
+
if(sha(priorMaterial)===fingerprints.config)fail('qa_revision_unchanged');
|
|
340
|
+
const current=await host.handle({version:1,operation:'status',requestId:'qa-revision-status',identity});
|
|
341
|
+
if(current.state!=='fixture_completed'||current.code!==null)fail('qa_revision_not_completed');
|
|
342
|
+
const binding={...qaBinding,identity:current.identity,packageDigest:current.packageDigest};
|
|
343
|
+
const target=inspectCmAiQaRevisionTarget(binding);
|
|
344
|
+
const record=host.reviseQa({version:1,fromFingerprint:sha(priorMaterial),toFingerprint:fingerprints.config,
|
|
345
|
+
invariantDigest:qaInvariantDigest(configMaterial),previousQaDigest:sha(qaConfigurationSlice(priorMaterial)),qaDigest:sha(qaConfigurationSlice(configMaterial)),
|
|
346
|
+
reason:qaConfigRevision.reason,hostContextId:execution.configuration.hostContextId,
|
|
347
|
+
revisedAt:new Date().toISOString().replace(/\.\d{3}Z$/,'Z'),packageDigest:current.packageDigest,
|
|
348
|
+
testRunId:target.testRunId,qaRound:target.qaRound,taskAttempt:current.identity.attempt});
|
|
349
|
+
recordCmAiQaConfigurationRevision(binding,record);
|
|
350
|
+
}
|
|
303
351
|
return {host:{async handle(request){
|
|
304
352
|
if(execution===null&&!['status','cancel'].includes(request.operation)){
|
|
305
353
|
// Do not imply an unavailable execution adapter was dispatched.
|
|
@@ -0,0 +1,29 @@
|
|
|
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 {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
7
|
+
|
|
8
|
+
test('adapter exception code getter cannot escape the runner failure boundary',async t=>{
|
|
9
|
+
const root=fs.mkdtempSync(path.join(os.tmpdir(),'cm-runner-error-code-'));
|
|
10
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
11
|
+
fs.writeFileSync(path.join(root,'code.js'),'old\n');
|
|
12
|
+
fs.writeFileSync(path.join(root,'requirements.md'),'fixture\n');
|
|
13
|
+
const identity={repositoryId:'fixture',runId:'error-code',taskId:'T-001',attempt:1};
|
|
14
|
+
let getterReads=0;
|
|
15
|
+
const runner=createTaskRunner({root,identity,scope:['code.js'],requirements:['requirements.md'],
|
|
16
|
+
excludedContexts:['main'],timeoutMs:1000,
|
|
17
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:()=>{
|
|
18
|
+
const error=new Error('adapter failure');
|
|
19
|
+
Object.defineProperty(error,'code',{get(){getterReads++;throw new Error('private getter');}});
|
|
20
|
+
throw error;
|
|
21
|
+
}},
|
|
22
|
+
reviewers:[{id:'reviewer',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
23
|
+
contexts:['review-one','review-two'],run:()=>{throw new Error('must not review');}}],
|
|
24
|
+
check:()=>[],commit:()=>{throw new Error('must not commit');}});
|
|
25
|
+
const result=await runner.executeEffect({version:1,id:'develop-1',identity,kind:'develop'});
|
|
26
|
+
assert.equal(result.state,'unknown');
|
|
27
|
+
assert.equal(result.code,'execution_error');
|
|
28
|
+
assert.equal(getterReads,0);
|
|
29
|
+
});
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import test,{after} 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 {spawn,spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
10
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
11
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
12
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
13
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
14
|
+
import {readRunnerHistory,runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
15
|
+
|
|
16
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'ai-chain-home-'));
|
|
17
|
+
process.env.CM_WORKFLOW_HOME=path.join(home,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(home,'logs');
|
|
18
|
+
after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
19
|
+
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
20
|
+
const identity={repositoryId:'chain-fixture',runId:'chain-run',taskId:'T-001',attempt:1};
|
|
21
|
+
function fixture(t){
|
|
22
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'ai-session-chain-')));
|
|
23
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
24
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work';
|
|
25
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
26
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Fixture\n');
|
|
27
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: fixture\n');
|
|
28
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
29
|
+
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
30
|
+
const definition={version:1,codeProject,specsDir,feature,identity,scope:['target.mjs'],requirements:['requirements.md']};
|
|
31
|
+
const config=path.join(root,'run.json');fs.writeFileSync(config,JSON.stringify(definition));
|
|
32
|
+
const bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
33
|
+
// Synthetic diagnostic receipt and fake CLI only: no real preflight/model/network.
|
|
34
|
+
const fake=path.join(bin,'codex');
|
|
35
|
+
fs.copyFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),fake);fs.chmodSync(fake,0o700);
|
|
36
|
+
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
37
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture',disabledSkills:[],promptTransport:'stdin'})}};
|
|
38
|
+
const reviewFile=path.join(root,'review.json');fs.writeFileSync(reviewFile,JSON.stringify(review));
|
|
39
|
+
const stateFile=path.join(specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
40
|
+
const records=()=>JSON.parse(fs.readFileSync(stateFile)).records;
|
|
41
|
+
return {root,definition,codeProject,specsDir,config,review,reviewFile,records,fake,
|
|
42
|
+
env:{...process.env,PATH:bin+path.delimiter+process.env.PATH,CM_WORKFLOW_LOG_HOME:path.join(root,'logs')}};
|
|
43
|
+
}
|
|
44
|
+
function launch(f,{host='session-A',original,mode='resume',operation='status',review=false}={}){
|
|
45
|
+
return new Promise((resolve,reject)=>{
|
|
46
|
+
const args=['serve','--config',f.config,'--mode',mode,'--host-context',host,'--allow-development','--review-config',f.reviewFile,
|
|
47
|
+
...(original===undefined?[]:['--original-host-context',original]),...(review?['--allow-review-attempt',String(review===true?1:review)]:[])];
|
|
48
|
+
const child=spawn(process.execPath,[cli,...args],{env:f.env,stdio:['pipe','pipe','pipe']});
|
|
49
|
+
let buffer='',stderr='';const rows=[];
|
|
50
|
+
const timer=setTimeout(()=>{child.kill();reject(Error('session chain timeout'));},15000);
|
|
51
|
+
child.on('error',reject);child.stderr.on('data',chunk=>stderr+=chunk);
|
|
52
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
53
|
+
child.stdout.on('data',chunk=>{
|
|
54
|
+
buffer+=chunk;let index;
|
|
55
|
+
while((index=buffer.indexOf('\n'))>=0){
|
|
56
|
+
const line=buffer.slice(0,index);buffer=buffer.slice(index+1);if(!line)continue;
|
|
57
|
+
try{
|
|
58
|
+
const row=JSON.parse(line);rows.push(row);
|
|
59
|
+
if(row.type==='host_request'){
|
|
60
|
+
let result;
|
|
61
|
+
if(row.kind==='develop'){
|
|
62
|
+
fs.writeFileSync(path.join(f.codeProject,'target.mjs'),'export const value = 42;\n');
|
|
63
|
+
result={status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
64
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
65
|
+
}else{
|
|
66
|
+
assert.equal(row.kind,'check');const command=[process.execPath,'--check',path.join(f.codeProject,'target.mjs')];
|
|
67
|
+
assert.equal(spawnSync(command[0],command.slice(1)).status,0);
|
|
68
|
+
result=[{id:'syntax',command,outcome:'passed',exitCode:0,evidence:'Isolated node --check passed'}];
|
|
69
|
+
}
|
|
70
|
+
send({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result});
|
|
71
|
+
}
|
|
72
|
+
if(row.requestId===operation&&row.result)send({type:'host_close',sessionId:rows.find(r=>r.type==='host_ready').sessionId});
|
|
73
|
+
}catch(error){child.kill();clearTimeout(timer);reject(error);}
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
child.once('close',code=>{clearTimeout(timer);resolve({code,stderr,rows,result:rows.find(r=>r.requestId===operation)?.result});});
|
|
77
|
+
send({version:1,operation,requestId:operation,identity});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const ok=run=>{assert.equal(run.code,0,run.stderr);return run.result;};
|
|
81
|
+
async function created(t){const f=fixture(t);assert.equal(ok(await launch(f,{mode:'create',operation:'advance'})).code,'decision_required');return f;}
|
|
82
|
+
async function reviewed(t,host='session-B'){
|
|
83
|
+
const f=await created(t);f.before=f.records().map(row=>JSON.stringify(row));
|
|
84
|
+
assert.equal(ok(await launch(f,{host,original:'session-A',operation:'advance',review:true})).state,'fixture_completed');return f;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
test('CLI cross-session resume preserves same-session stage and requires original flag',async t=>{
|
|
88
|
+
const f=await created(t),before=f.records();
|
|
89
|
+
const same=ok(await launch(f)),cross=ok(await launch(f,{host:'session-B',original:'session-A'}));
|
|
90
|
+
assert.deepEqual(cross,same);assert.deepEqual(f.records(),before);
|
|
91
|
+
const wrong=await launch(f,{host:'session-B'});assert.equal(wrong.code,1);assert.match(wrong.stderr,/fingerprint_mismatch/);
|
|
92
|
+
assert.deepEqual(ok(await launch(f,{original:'session-A'})),same);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('original-host-context on create fails before opening store, including equal ids',async t=>{
|
|
96
|
+
for(const original of ['session-A','session-B']){
|
|
97
|
+
const f=fixture(t),run=await launch(f,{mode:'create',original});
|
|
98
|
+
assert.equal(run.code,1);assert.match(run.stderr,/original_host_context_unavailable/);
|
|
99
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test('A creates, B signs review, C declaring only A replays the completed run',async t=>{
|
|
104
|
+
const f=await reviewed(t),before=f.records();
|
|
105
|
+
for(const host of ['session-C','session-B','session-A']){
|
|
106
|
+
assert.equal(ok(await launch(f,{host,original:'session-A'})).state,'fixture_completed');
|
|
107
|
+
assert.deepEqual(f.records(),before);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test('joining host is journaled once immediately before its grant; old records keep exact bytes',async t=>{
|
|
112
|
+
const f=await reviewed(t),rows=f.records(),joins=rows.filter(r=>r.payload.type==='host-joined');
|
|
113
|
+
assert.equal(joins.length,1);assert.equal(joins[0].kind,'result');
|
|
114
|
+
assert.deepEqual(joins[0].payload,{version:3,protocol:'cm-task-runner',type:'host-joined',hostContextId:'session-B'});
|
|
115
|
+
const index=rows.indexOf(joins[0]);assert.equal(rows[index+1].payload.type,'review-invocation-registered');
|
|
116
|
+
assert.equal(rows[index+1].payload.grant.hostContextId,'session-B');
|
|
117
|
+
assert.deepEqual(rows.slice(0,f.before.length).map(row=>JSON.stringify(row)),f.before);
|
|
118
|
+
for(const host of ['session-B','session-C'])ok(await launch(f,{host,original:'session-A'}));
|
|
119
|
+
assert.deepEqual(f.records(),rows);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('durable session signing adds no joined record',async t=>{
|
|
123
|
+
const f=await reviewed(t,'session-A');assert(!f.records().some(r=>r.payload.type==='host-joined'));
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
test('a recorded reviewer thread cannot reopen as live host',async t=>{
|
|
127
|
+
const f=await reviewed(t,'session-A'),before=f.records();
|
|
128
|
+
const host=before.find(r=>r.payload.type==='review-invocation-started').payload.providerThreadId;
|
|
129
|
+
const result=await launch(f,{host,original:'session-A'});assert.equal(result.code,1);assert.match(result.stderr,/not_independent/);
|
|
130
|
+
assert.deepEqual(f.records(),before);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('conversation factory keeps durable metadata but live author identity and authority',async t=>{
|
|
134
|
+
const f=fixture(t),bridge={async call(){return {status:'failed',code:'synthetic'};}};
|
|
135
|
+
const a=createConversationExecution(f.definition,'session-A',bridge,f.review);
|
|
136
|
+
const b=createConversationExecution(f.definition,'session-B',bridge,f.review,null,null,false,'codex',{originalHostContextId:'session-A'});
|
|
137
|
+
assert.deepEqual(b.configuration,a.configuration);assert.deepEqual(b.excludedContexts,a.excludedContexts);
|
|
138
|
+
assert.deepEqual(b.reviewInvocation.excludedThreadIds,a.reviewInvocation.excludedThreadIds);
|
|
139
|
+
assert.equal(b.reviewInvocation.hostContextId,'session-B');
|
|
140
|
+
for(const host of ['cm-conversation-author','cm-conversation-review-1']){
|
|
141
|
+
assert.throws(()=>createConversationExecution(f.definition,host,bridge,null,null,null,false,'codex',{originalHostContextId:'session-A'}),{code:'not_independent'});
|
|
142
|
+
assert.throws(()=>createConversationExecution(f.definition,'session-B',bridge,null,null,null,false,'codex',{originalHostContextId:host}),{code:'not_independent'});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Rehash synthetic grammar vectors, never edit an actual run or manufacture a grant.
|
|
147
|
+
function chain(rows){let previousDigest=null;return rows.map((row,index)=>{
|
|
148
|
+
const body={version:1,seq:index+1,id:`runner.${String(index+1).padStart(6,'0')}`,kind:row.kind,payload:row.payload,previousDigest};
|
|
149
|
+
const record={...body,digest:digest(body)};previousDigest=record.digest;return record;
|
|
150
|
+
});}
|
|
151
|
+
test('V3 joined-host grammar rejects misplaced, duplicate, durable and extra records',async t=>{
|
|
152
|
+
const f=await reviewed(t),rows=f.records(),config=rows[0].payload.config;
|
|
153
|
+
const at=rows.findIndex(r=>r.payload.type==='host-joined'),join=rows[at];assert(at>0);
|
|
154
|
+
const read=items=>readRunnerHistory(chain(items),config,3);
|
|
155
|
+
const prefix=rows.slice(0,at);
|
|
156
|
+
assert.deepEqual(runnerStatus(read(prefix).state,config),runnerStatus(read([...prefix,join]).state,config));
|
|
157
|
+
assert.throws(()=>read([rows[0],join]),{code:'runner_invocation'});
|
|
158
|
+
assert.throws(()=>read([...prefix,join,join]),{code:'runner_invocation'});
|
|
159
|
+
assert.throws(()=>read([...prefix,{...join,payload:{...join.payload,hostContextId:'session-A'}}]),{code:'runner_invocation'});
|
|
160
|
+
assert.throws(()=>read([...prefix,{...join,payload:{...join.payload,extra:true}}]),{code:'invalid_input'});
|
|
161
|
+
assert.throws(()=>read([...rows.slice(0,at+2),{...join,payload:{...join.payload,hostContextId:'session-C'}}]),{code:'runner_invocation'});
|
|
162
|
+
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('V3 joined-host grammar rejects an earlier reviewer joining before a later review registration',async t=>{
|
|
166
|
+
const f=await created(t);reviewerResult(f,{thread:'earlier-reviewer',changes:true});
|
|
167
|
+
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
|
|
168
|
+
assert.equal(revised.state,'awaiting_review');assert.equal(revised.code,'decision_required');
|
|
169
|
+
const rows=f.records(),config=rows[0].payload.config;
|
|
170
|
+
const reviewerThread=rows.find(r=>r.payload.type==='review-invocation-started').payload.providerThreadId;
|
|
171
|
+
const firstIntent=rows.find(r=>r.payload.type==='effect-intent'&&r.payload.effect.kind==='review');
|
|
172
|
+
const join=rows.find(r=>r.payload.type==='host-joined');
|
|
173
|
+
// Only synthetic copies enter chain(): the on-disk run remains untouched.
|
|
174
|
+
const prefix=[...rows,{...firstIntent,payload:{...firstIntent.payload,effect:{...firstIntent.payload.effect,
|
|
175
|
+
id:'synthetic-review-2',identity:{...identity,attempt:2}}}}];
|
|
176
|
+
const read=hostContextId=>readRunnerHistory(chain([...prefix,{...join,payload:{...join.payload,hostContextId}}]),config,3);
|
|
177
|
+
// An independent host at the same location is legal, so the failing vector
|
|
178
|
+
// reaches reviewer independence rather than ordering, identity or chain checks.
|
|
179
|
+
const legal=read('independent-new-host');
|
|
180
|
+
assert.equal(legal.pending.kind,'review');assert.equal(legal.pending.identity.attempt,2);
|
|
181
|
+
assert.equal(legal.joinedHosts.at(-1),'independent-new-host');
|
|
182
|
+
assert.throws(()=>read(reviewerThread),{code:'not_independent'});
|
|
183
|
+
assert.deepEqual(f.records(),rows);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
test('development after cross-session reopen reports live provider thread without changing init',async t=>{
|
|
188
|
+
const f=fixture(t);ok(await launch(f,{mode:'create'}));const before=f.records();
|
|
189
|
+
assert.equal(ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance'})).code,'decision_required');
|
|
190
|
+
const rows=f.records();assert.deepEqual(rows.slice(0,before.length),before);
|
|
191
|
+
assert.deepEqual(rows[0].payload.config.reviewInvocation,{developerThreadId:'cm-conversation-author',excludedThreadIds:['session-A']});
|
|
192
|
+
const call=rows.filter(r=>r.payload.type==='effect-checkpoint').at(-1).payload.checkpoint.calls[0];
|
|
193
|
+
assert.equal(call.providerThreadId,'session-B');assert(!rows.some(r=>r.payload.type==='host-joined'));
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
function reviewerResult(f,{thread,changes=false}){
|
|
197
|
+
let source=fs.readFileSync(fileURLToPath(new URL('./fixtures/codex-review-process.mjs',import.meta.url)),'utf8');
|
|
198
|
+
if(thread)source=source.replace('thread_id:randomUUID()',`thread_id:${JSON.stringify(thread)}`);
|
|
199
|
+
if(changes)source=source.replace("verdict:'approved'","verdict:'changes_requested'")
|
|
200
|
+
.replace('findings:[]',"findings:[{id:'F1',severity:'P2',path:'target.mjs',message:'Synthetic revision',evidence:'Fixture evidence'}]");
|
|
201
|
+
fs.writeFileSync(f.fake,source);
|
|
202
|
+
}
|
|
203
|
+
for(const thread of ['session-A','session-B'])test(`live reviewer cannot be durable or live host: ${thread}`,async t=>{
|
|
204
|
+
const f=await created(t);reviewerResult(f,{thread});
|
|
205
|
+
const result=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
|
|
206
|
+
assert.equal(result.state,'unknown');
|
|
207
|
+
assert(!f.records().some(r=>r.payload.type==='review-invocation-started'));
|
|
208
|
+
// Invalid observations also remain replayable from a third session.
|
|
209
|
+
assert.equal(ok(await launch(f,{host:'session-C',original:'session-A'})).state,'unknown');
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test('second review excludes earlier joined host even when the current host is C',async t=>{
|
|
213
|
+
const f=await created(t);reviewerResult(f,{changes:true});
|
|
214
|
+
const revised=ok(await launch(f,{host:'session-B',original:'session-A',operation:'advance',review:true}));
|
|
215
|
+
// advance also develops attempt 2, then waits for its separate review grant.
|
|
216
|
+
assert.equal(revised.state,'awaiting_review');assert.equal(revised.code,'decision_required');
|
|
217
|
+
reviewerResult(f,{thread:'session-B'});
|
|
218
|
+
const result=ok(await launch(f,{host:'session-C',original:'session-A',operation:'advance',review:2}));
|
|
219
|
+
assert.equal(result.state,'unknown');
|
|
220
|
+
const rows=f.records();assert.equal(rows.filter(r=>r.payload.type==='review-invocation-started').length,1);
|
|
221
|
+
assert.deepEqual(rows.filter(r=>r.payload.type==='host-joined').map(r=>r.payload.hostContextId),['session-B','session-C']);
|
|
222
|
+
assert.equal(ok(await launch(f,{host:'session-D',original:'session-A'})).state,'unknown');
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
// Exercise the grant/history defect independently of the new CLI flag. Assemble
|
|
227
|
+
// the durable and live factory outputs at the trusted host boundary: old code
|
|
228
|
+
// can open B with these unchanged bytes, but rejects B's grant as unauthorized.
|
|
229
|
+
test('runner session chain without CLI reaches B grant and replays it in C',async t=>{
|
|
230
|
+
const f=fixture(t);
|
|
231
|
+
const bridge={async call(kind){
|
|
232
|
+
if(kind==='develop'){
|
|
233
|
+
fs.writeFileSync(path.join(f.codeProject,'target.mjs'),'export const value = 42;\n');
|
|
234
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
235
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
236
|
+
}
|
|
237
|
+
assert.equal(kind,'check');
|
|
238
|
+
return [{id:'check',command:['synthetic'],outcome:'passed',exitCode:0,evidence:'Synthetic runner fixture'}];
|
|
239
|
+
}};
|
|
240
|
+
const durable=createConversationExecution(f.definition,'session-A',bridge,f.review);
|
|
241
|
+
const execution=(host,allow=false)=>{
|
|
242
|
+
const live=createConversationExecution(f.definition,host,bridge,f.review,allow?1:null);
|
|
243
|
+
return {...live,configuration:durable.configuration,excludedContexts:durable.excludedContexts,
|
|
244
|
+
reviewInvocation:{...live.reviewInvocation,excludedThreadIds:durable.reviewInvocation.excludedThreadIds},
|
|
245
|
+
reviewers:live.reviewers.map(reviewer=>({...reviewer,run(request,{onEvent}){
|
|
246
|
+
for(const event of [{event:'thread.started',provider_thread:'synthetic-reviewer'},
|
|
247
|
+
{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
248
|
+
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
249
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
250
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic runner fixture'}};
|
|
251
|
+
}}))};
|
|
252
|
+
};
|
|
253
|
+
async function session(host,mode,operation,allow=false){
|
|
254
|
+
const run=await openControlRun(f.definition,mode,execution(host,allow));
|
|
255
|
+
try{return await run.host.handle({version:1,operation,requestId:operation,identity});}finally{run.close();}
|
|
256
|
+
}
|
|
257
|
+
assert.equal((await session('session-A','create','advance')).code,'decision_required');
|
|
258
|
+
const reviewed=await session('session-B','resume','advance',true);
|
|
259
|
+
assert.equal(reviewed.state,'fixture_completed',JSON.stringify(reviewed));
|
|
260
|
+
assert.equal((await session('session-C','resume','status')).state,'fixture_completed');
|
|
261
|
+
});
|