@aibyzero/cm-workflow 0.16.9 → 0.17.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/CHANGELOG.md +12 -0
- package/README.md +9 -1
- package/VERSION +1 -1
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +101 -84
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +3 -0
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +1 -24
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +36 -99
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +62 -38
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +34 -8
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +124 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +43 -84
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
- package/scripts/cm-ai-host-fixture.mjs +38 -10
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +19 -18
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +1 -2
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +15 -128
- package/scripts/cm-ai-run.mjs +78 -24
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +3 -10
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-worker.test.mjs +5 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-external-batch-host.test.mjs +30 -11
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +91 -19
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +65 -28
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
|
@@ -29,8 +29,7 @@ const POSIX={skip:process.platform==='win32'?'host-check QA commands and the fix
|
|
|
29
29
|
const identity={repositoryId:'qa-rerun-fixture',runId:'qa-rerun-run',taskId:'T-001',attempt:1};
|
|
30
30
|
const simulator={kind:'app',carrier:'ios-simulator',target:'Fixture-iPhone',scope:'local'};
|
|
31
31
|
const service={kind:'service',carrier:'cli',target:'node',scope:'local'};
|
|
32
|
-
const lowRisk={
|
|
33
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
32
|
+
const lowRisk={confirmed:true};
|
|
34
33
|
|
|
35
34
|
// The QA command stands in for xcodebuild/simulator scripts. It reads a mode
|
|
36
35
|
// file outside both roots, so switching the "environment" never touches the
|
|
@@ -115,7 +114,7 @@ function failingStartShim(f){
|
|
|
115
114
|
function launch(f,{mode='resume',operation='advance',workflow=null,extra=[],answers={},review=true,pathPrefix=null}={}){
|
|
116
115
|
return new Promise((resolve,reject)=>{
|
|
117
116
|
const args=['serve','--config',f.config,'--mode',mode,'--host-context','session-A','--allow-development',
|
|
118
|
-
'--review-config',f.reviewFile,...(review?[
|
|
117
|
+
'--review-config',f.reviewFile,...(review?[]:[]),
|
|
119
118
|
...(workflow?['--workflow-config',workflow,'--allow-qa']:[]),...extra];
|
|
120
119
|
const env=pathPrefix?{...f.env,PATH:pathPrefix+path.delimiter+f.env.PATH}:f.env;
|
|
121
120
|
const child=spawn(process.execPath,[cli,...args],{env,stdio:['pipe','pipe','pipe']});
|
|
@@ -305,7 +304,7 @@ test('#26 a wrong QA workflow config is revised before any QA round, without con
|
|
|
305
304
|
const f=fixture(t);
|
|
306
305
|
const wrong=f.workflow('workflow-old',{commands:[{id:'probe',command:[process.execPath,'-e','process.exit(3)'],caseIds:[]}],environment:service});
|
|
307
306
|
const fixed=f.workflow('workflow-new',probeQa());
|
|
308
|
-
const waiting=done(await launch(f,{mode:'create',workflow:wrong,
|
|
307
|
+
const waiting=done(await launch(f,{mode:'create',workflow:wrong,operation:'start'}));
|
|
309
308
|
assert.equal(waiting.state,'awaiting_review',JSON.stringify(waiting));
|
|
310
309
|
const before=f.journal();
|
|
311
310
|
const drift=await launch(f,{workflow:fixed,review:false});
|
|
@@ -9,7 +9,7 @@ import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
|
9
9
|
import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
|
|
10
10
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {createCmAiTaskLearningApplication,createCmAiTaskLearningRetrospective} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
12
|
-
import {writeHandoff} from '
|
|
12
|
+
import {writeHandoff} from './fixtures/native-gate-fixture.mjs';
|
|
13
13
|
|
|
14
14
|
const identity={repositoryId:'fixture',runId:'review-drift',taskId:'T-001',attempt:1};
|
|
15
15
|
const terminal=(request,result)=>({version:1,invocationId:request.invocationId,
|
|
@@ -117,9 +117,9 @@ function fixture(t,{reviewTimeoutMs=null}={}){
|
|
|
117
117
|
const records=()=>JSON.parse(fs.readFileSync(store,'utf8')).records;
|
|
118
118
|
const replay=()=>{const rows=records();return readRunnerHistory(rows,rows[0].payload.config,3);};
|
|
119
119
|
const calls=()=>fs.existsSync(callsFile)?fs.readFileSync(callsFile,'utf8').trim().split('\n').map(line=>JSON.parse(line)):[];
|
|
120
|
-
const review=(attempt=1)=>['--review-config','review.json'
|
|
120
|
+
const review=(attempt=1)=>['--review-config','review.json'];
|
|
121
121
|
const awaitingReview=()=>{
|
|
122
|
-
const first=drive(plan(),'
|
|
122
|
+
const first=drive(plan(),'start');assert.equal(first.status,0,first.stderr);
|
|
123
123
|
assert.equal(first.result.state,'awaiting_review');return first.result.packageDigest;
|
|
124
124
|
};
|
|
125
125
|
const decide=(packageDigest,attempt=1)=>drive(plan({mode:'resume',permissions:review(attempt),packageDigest,answers:undefined,checks:undefined}),'decision');
|
|
@@ -198,15 +198,15 @@ test(`#8 ${error==='authentication_failed'?'real Claude CLI':'in-process Claude
|
|
|
198
198
|
assert.deepEqual(result.observation.events.map(event=>event.event),['thread.started','turn.started','process_closed']);
|
|
199
199
|
const history=f.replay();assert.equal(history.state.state,'pending_review');assert.equal(history.state.code,'review_provider_failed');
|
|
200
200
|
if(error!=='authentication_failed')return;
|
|
201
|
-
// After logging in, the same attempt is reviewed once more with a
|
|
201
|
+
// After logging in, the same attempt is reviewed once more with a fresh invocation binding.
|
|
202
202
|
f.behave({mode:'ok'});
|
|
203
203
|
const approved=f.decide(packageDigest);
|
|
204
204
|
assert.equal(approved.status,0,approved.stderr);assert.equal(approved.result.state,'approved');
|
|
205
205
|
assert.deepEqual(f.intents(),['develop-1','review-1','review-1-retry-1']);
|
|
206
206
|
const registrations=f.records().filter(row=>row.payload.type==='review-invocation-registered');
|
|
207
207
|
assert.equal(registrations.length,2);
|
|
208
|
-
assert.notEqual(registrations[0].payload.
|
|
209
|
-
assert.notEqual(registrations[0].payload.
|
|
208
|
+
assert.notEqual(registrations[0].payload.binding.invocationId,registrations[1].payload.binding.invocationId);
|
|
209
|
+
assert.notEqual(registrations[0].payload.binding.requestDigest,registrations[1].payload.binding.requestDigest);
|
|
210
210
|
assert.equal(f.replay().state.state,'approved');assert.equal(f.calls().length,2);
|
|
211
211
|
});
|
|
212
212
|
|
|
@@ -409,13 +409,7 @@ test('#8 legacy unknown results replay unchanged and forged failed results are r
|
|
|
409
409
|
// Runner-level fixture: the real V3 task runner and execution store with
|
|
410
410
|
// synthetic developer/reviewer adapters, for bounds the driver cannot reach fast.
|
|
411
411
|
const checksPassed=[{id:'check',command:['synthetic'],outcome:'passed',exitCode:0,evidence:'fixture'}];
|
|
412
|
-
|
|
413
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.invocationId}`,adapterId:`${request.provider}-review-adapter`,
|
|
414
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
415
|
-
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
416
|
-
hostContextId:'actual-main',decisionId:'decision-1',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
417
|
-
return {...body,grantDigest:digest(body)};
|
|
418
|
-
};
|
|
412
|
+
|
|
419
413
|
const reviewEvents=(onEvent,request,{result=true,close=true}={})=>{
|
|
420
414
|
onEvent({event:'thread.started',provider_thread:`thread-${request.invocationId}`});
|
|
421
415
|
onEvent({event:'turn.started',item_type:null});
|
|
@@ -448,7 +442,6 @@ async function runnerFixture(t,fn,{timeoutMs=1000,reviewTimeoutMs,reviewerProvid
|
|
|
448
442
|
check:request=>checks(request),
|
|
449
443
|
taskCompletion:{reviewsDir,handoffs:[path.join(reviewsDir,'a1.json'),path.join(reviewsDir,'a2.json')]},
|
|
450
444
|
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main'],
|
|
451
|
-
authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt),
|
|
452
445
|
...(reviewTimeoutMs===undefined?{}:{timeoutMs:reviewTimeoutMs})}};
|
|
453
446
|
const make=(mode,extra={})=>createTaskRunner({...options,reviewInvocation:{...options.reviewInvocation,...extra},persistence:{store,mode,version:3}});
|
|
454
447
|
const reopen=(extra={})=>{store.close();store=openTaskExecutionStore({...owner,create:false});return make('resume',extra);};
|
|
@@ -499,7 +492,8 @@ test('#20 the conversation factory sizes the review race above the reviewer budg
|
|
|
499
492
|
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');fs.mkdirSync(codeProject);fs.mkdirSync(specsDir);
|
|
500
493
|
const definition={codeProject,specsDir,feature:'1.work',identity,scope:['code.js'],requirements:[]};
|
|
501
494
|
const bridge={call:()=>assert.fail('no host call expected')};
|
|
502
|
-
const preflight={passed:true,provider:'claude',prompt_transport:'stdin',
|
|
495
|
+
const preflight={passed:true,provider:'claude',prompt_transport:'stdin',
|
|
496
|
+
config_fingerprint:claudeReviewFingerprint({cwd:codeProject,model:'fixture'})};
|
|
503
497
|
return import('../runtime/js/cm-ai/host-conversation-execution.mjs').then(({createConversationExecution,REVIEW_BOUND_MARGIN_MS})=>{
|
|
504
498
|
for(const [reviewTimeout,expected] of [[3000000,3000000+REVIEW_BOUND_MARGIN_MS],[3600000,3660000],[null,1800000],[60000,1800000]]){
|
|
505
499
|
const review={model:'fixture',disabledSkills:[],preflight,...(reviewTimeout===null?{}:{timeoutMs:reviewTimeout})};
|
|
@@ -522,7 +516,7 @@ test('#20 the real host passes the raised review bound from review-config into t
|
|
|
522
516
|
const definition=readRunDefinition(path.join(f.root,'run.json'));
|
|
523
517
|
const review=readConversationReviewConfiguration(path.join(f.root,'review.json'));
|
|
524
518
|
const execution=createConversationExecution(definition,'review-host-a',{call:()=>assert.fail('no host call expected')},
|
|
525
|
-
review,
|
|
519
|
+
review,null,null,false,'claude');
|
|
526
520
|
const run=await openControlRun(definition,'resume',execution);
|
|
527
521
|
t.after(()=>run.close());
|
|
528
522
|
const delays=[],originalTimer=globalThis.setTimeout;
|
|
@@ -899,7 +893,7 @@ test('an approved run already holding all six effects (old grammar) completes (r
|
|
|
899
893
|
for(let round=1;round<=4;round++)
|
|
900
894
|
assert.equal(run('advance',round===1?{mode:'create',originalHostContext:undefined}:{}).result.code,'develop_checks_not_passed');
|
|
901
895
|
fs.writeFileSync(marker,'pass\n');
|
|
902
|
-
const delivered=run('
|
|
896
|
+
const delivered=run('start');assert.equal(delivered.result.state,'awaiting_review',JSON.stringify(delivered.result));
|
|
903
897
|
const packageDigest=delivered.result.packageDigest;
|
|
904
898
|
assert.equal(run('decision',{permissions:f.review(1),packageDigest}).result.state,'approved');
|
|
905
899
|
const {completedEffectCount,effectSlotFree}=await import('../runtime/js/cm-ai/durable-runner-state.mjs');
|
|
@@ -947,7 +941,7 @@ function completionFixture(t){
|
|
|
947
941
|
}
|
|
948
942
|
test('repeated completion re-check blocks stop at completion_retry_limit instead of an uncompletable approval (real host)',t=>{
|
|
949
943
|
const f=completionFixture(t);f.pass(true);
|
|
950
|
-
const delivered=f.run('
|
|
944
|
+
const delivered=f.run('start',{mode:'create'});
|
|
951
945
|
assert.equal(delivered.status,0,delivered.stderr);assert.equal(delivered.result.state,'awaiting_review');
|
|
952
946
|
const packageDigest=delivered.result.packageDigest;
|
|
953
947
|
assert.equal(f.run('decision',{review:true,packageDigest}).result.state,'approved');
|
|
@@ -980,7 +974,7 @@ test('completion re-checks no longer eat the six effects: develop blocks plus re
|
|
|
980
974
|
const f=completionFixture(t);f.pass(false);
|
|
981
975
|
for(const mode of ['create','resume'])assert.equal(f.run('advance',{mode}).result.code,'develop_checks_not_passed');
|
|
982
976
|
f.pass(true);
|
|
983
|
-
const delivered=f.run('
|
|
977
|
+
const delivered=f.run('start');assert.equal(delivered.result.state,'awaiting_review');
|
|
984
978
|
const packageDigest=delivered.result.packageDigest;
|
|
985
979
|
assert.equal(f.run('decision',{review:true,packageDigest}).result.state,'approved');
|
|
986
980
|
// Four effects held; three re-check blocks would previously have used the rest.
|
|
@@ -994,7 +988,7 @@ test('completion re-checks no longer eat the six effects: develop blocks plus re
|
|
|
994
988
|
|
|
995
989
|
test('#retry-limit replay accepts the completion limit only once the re-check bound is spent',t=>{
|
|
996
990
|
const f=completionFixture(t);f.pass(true);
|
|
997
|
-
const packageDigest=f.run('
|
|
991
|
+
const packageDigest=f.run('start',{mode:'create'}).result.packageDigest;
|
|
998
992
|
f.run('decision',{review:true,packageDigest});f.pass(false);
|
|
999
993
|
for(let block=1;block<=4;block++)f.run('complete',{packageDigest});
|
|
1000
994
|
const records=f.records(),configuration=records[0].payload.config;
|
|
@@ -5,6 +5,7 @@ import path from 'node:path';
|
|
|
5
5
|
import test from 'node:test';
|
|
6
6
|
|
|
7
7
|
import {readConversationReviewConfiguration,formatClaudeModelHint} from './cm-ai-host.mjs';
|
|
8
|
+
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
8
9
|
import {createConversationExecution,resolveReviewTimeout} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
9
10
|
|
|
10
11
|
const preflight={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:'x'};
|
|
@@ -68,7 +69,8 @@ test('review timeout changes do not alter the authorized execution configuration
|
|
|
68
69
|
const definition={codeProject,specsDir,feature:'1.work',identity:{repositoryId:'fixture',runId:'run',taskId:'T-001',attempt:1},
|
|
69
70
|
scope:['code.js'],requirements:[]};
|
|
70
71
|
const bridge={call:()=>assert.fail('no host call expected')};
|
|
71
|
-
const review={model:'fixture',disabledSkills:[],preflight
|
|
72
|
+
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,cli_model:'fixture',prompt_transport:'stdin',
|
|
73
|
+
config_fingerprint:configFingerprint({cwd:codeProject,model:'fixture'})}};
|
|
72
74
|
const earlier=createConversationExecution(definition,'host-fixture',bridge,{...review,timeoutMs:60000});
|
|
73
75
|
const later=createConversationExecution(definition,'host-fixture',bridge,{...review,timeoutMs:900000});
|
|
74
76
|
assert.deepEqual(earlier.configuration,later.configuration);
|
|
@@ -17,13 +17,6 @@ import {recordReviewAbandonment} from '../runtime/js/cm-ai/review-abandon-log.mj
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
const checks=[{id:'check',command:['synthetic'],outcome:'passed',exitCode:0,evidence:'fixture'}];
|
|
20
|
-
const grantFor=(request,authorizationAt,change=grant=>grant)=>{
|
|
21
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.invocationId}`,adapterId:`${request.provider}-review-adapter`,
|
|
22
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
23
|
-
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
24
|
-
hostContextId:'actual-main',decisionId:'decision-1',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
25
|
-
change(body);return {...body,grantDigest:digest(body)};
|
|
26
|
-
};
|
|
27
20
|
const events=(onEvent,thread='actual-review')=>{
|
|
28
21
|
onEvent({event:'thread.started',provider_thread:thread});
|
|
29
22
|
onEvent({event:'turn.started',item_type:null});
|
|
@@ -32,7 +25,7 @@ const events=(onEvent,thread='actual-review')=>{
|
|
|
32
25
|
onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
33
26
|
};
|
|
34
27
|
|
|
35
|
-
async function fixture(fn,{reviewRun,
|
|
28
|
+
async function fixture(fn,{reviewRun,times,timeoutMs=1000,provider='codex'}={}) {
|
|
36
29
|
const temp=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-review-v3-')));
|
|
37
30
|
const root=path.join(temp,'code'),specsRoot=path.join(temp,'specs'),reviewsDir=path.join(specsRoot,'.reviews');
|
|
38
31
|
fs.mkdirSync(root);fs.mkdirSync(reviewsDir,{recursive:true});
|
|
@@ -56,8 +49,7 @@ async function fixture(fn,{reviewRun,authorize,times,timeoutMs=1000,provider='co
|
|
|
56
49
|
dispatches++;lateEvent=control.onEvent;return (reviewRun??defaultRun)(request,control);
|
|
57
50
|
}}],check:()=>checks,
|
|
58
51
|
taskCompletion:{reviewsDir,handoffs:[path.join(reviewsDir,'a1.json'),path.join(reviewsDir,'a2.json')]},
|
|
59
|
-
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']
|
|
60
|
-
authorize:authorize??((request,{authorizationAt})=>grantFor(request,authorizationAt))}};
|
|
52
|
+
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']}};
|
|
61
53
|
const make=mode=>{
|
|
62
54
|
const old=Date.now,values=times?[...times]:null;if(values)Date.now=()=>values.length>1?values.shift():values[0];
|
|
63
55
|
try{return createTaskRunner({...options,persistence:{store,mode,version:3}});}finally{Date.now=old;}
|
|
@@ -85,106 +77,6 @@ const timeoutRun=(request,{onEvent})=>{
|
|
|
85
77
|
};
|
|
86
78
|
const retryEffect=(f,attempt=1)=>({...f.effect('review',attempt),id:`review-${attempt}-retry-1`});
|
|
87
79
|
|
|
88
|
-
test('V3 expired dispatch grant is journaled as grant_expired without adapter dispatch',()=>fixture(async f=>{
|
|
89
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
90
|
-
const end=await runner.executeEffect(f.effect('review'));
|
|
91
|
-
assert.equal(end.state,'pending_review');assert.equal(end.code,'grant_expired');assert.equal(f.dispatches(),0);
|
|
92
|
-
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
93
|
-
assert.equal(end.reviewInvocation.result.reason,'grant_expired');
|
|
94
|
-
assert.equal(end.reviewInvocation.result.dispatchAt,200);
|
|
95
|
-
assert.equal(end.reviewInvocation.registration.grant.expiresAt,150);
|
|
96
|
-
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
97
|
-
const saved=f.getStore().snapshot();
|
|
98
|
-
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'grant_expired');
|
|
99
|
-
assert.deepEqual(saved.records.slice(-3).map(record=>record.payload.type),
|
|
100
|
-
['review-invocation-registered','review-invocation-result','effect-checkpoint']);
|
|
101
|
-
assert.deepEqual(f.reopen().status(),end);
|
|
102
|
-
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{grant.expiresAt=150;})}));
|
|
103
|
-
|
|
104
|
-
// Batch 4 review round 1: a registered review that was never dispatched (expired
|
|
105
|
-
// grant) left the run at pending_review/grant_expired with no usable exit. No
|
|
106
|
-
// reviewer ran, so the round redispatches under a fresh grant (new effect id), the
|
|
107
|
-
// not-dispatched effect holds no call or effect slot, and the journal replays.
|
|
108
|
-
test('a never-dispatched review (grant_expired) redispatches in its own run under a fresh grant and replays',()=>{
|
|
109
|
-
let expired=true;
|
|
110
|
-
return fixture(async f=>{
|
|
111
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
112
|
-
const end=await runner.executeEffect(f.effect('review'));
|
|
113
|
-
assert.deepEqual([end.state,end.code,f.dispatches()],['pending_review','grant_expired',0]);
|
|
114
|
-
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.calls.at(-1).started,false);
|
|
115
|
-
const saved=f.getStore().snapshot(),history=readRunnerHistory(saved.records,saved.records[0].payload.config,3);
|
|
116
|
-
assert.equal(completedEffectCount(history.state.cache,history.state.calls),1,'the never-dispatched review holds no effect slot');
|
|
117
|
-
// The cached effect id still replays the not-dispatched result unchanged.
|
|
118
|
-
const resumed=f.reopen();assert.deepEqual(await resumed.executeEffect(f.effect('review')),end);assert.equal(f.dispatches(),0);
|
|
119
|
-
expired=false;
|
|
120
|
-
const approved=await resumed.executeEffect({...f.effect('review'),id:'review-1-retry-1'});
|
|
121
|
-
assert.equal(approved.state,'approved',JSON.stringify(approved));assert.equal(f.dispatches(),1);
|
|
122
|
-
assert.equal(approved.calls.filter(call=>call.terminal==='not_dispatched').length,1);
|
|
123
|
-
assert.deepEqual(f.reopen().status(),approved);
|
|
124
|
-
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{if(expired)grant.expiresAt=150;})});
|
|
125
|
-
});
|
|
126
|
-
// Batch 4 review round 2: never-dispatched redispatches hold no call or effect slot
|
|
127
|
-
// but have their own bound, two per review round. The third not-dispatched end is an
|
|
128
|
-
// explicit limit block; live status and the replayed projection read the same count.
|
|
129
|
-
test('never-dispatched review redispatches stop at review_not_dispatched_limit after two, identically live and replayed',()=>{
|
|
130
|
-
let expiring=3;
|
|
131
|
-
return fixture(async f=>{
|
|
132
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
133
|
-
let end=await runner.executeEffect(f.effect('review'));expiring--;
|
|
134
|
-
assert.deepEqual([end.state,end.code],['pending_review','grant_expired']);
|
|
135
|
-
for(const retry of [1,2]){
|
|
136
|
-
const next=f.reopen();
|
|
137
|
-
// Still redispatchable: same review round, no call or effect slot spent.
|
|
138
|
-
end=await next.executeEffect({...f.effect('review'),id:`review-1-retry-${retry}`});expiring--;
|
|
139
|
-
if(retry===1)assert.deepEqual([end.state,end.code],['pending_review','grant_expired']);
|
|
140
|
-
}
|
|
141
|
-
assert.equal(f.dispatches(),0);
|
|
142
|
-
assert.equal(end.state,'blocked');assert.equal(end.code,'review_not_dispatched_limit');
|
|
143
|
-
assert.match(end.reason,/^review_not_dispatched_limit: .*3 次.*派发前作废/);
|
|
144
|
-
const saved=f.getStore().snapshot(),config=saved.records[0].payload.config,history=readRunnerHistory(saved.records,config,3);
|
|
145
|
-
assert.deepEqual([history.state.state,history.state.code],['pending_review','grant_expired']);
|
|
146
|
-
assert.equal(completedEffectCount(history.state.cache,history.state.calls),1);
|
|
147
|
-
const projected=projectedRunnerStatus(history,config);
|
|
148
|
-
assert.deepEqual([projected.state,projected.code,projected.reason],[end.state,end.code,end.reason]);
|
|
149
|
-
// Replay applies the same stop: a journal carrying a fourth review intent is refused.
|
|
150
|
-
const intent=saved.records.findLast(record=>record.kind==='intent'&&record.payload.effect?.id==='review-1-retry-2');
|
|
151
|
-
assert(intent,'retry-2 intent');
|
|
152
|
-
const {digest:ignored,...body}=JSON.parse(JSON.stringify(intent).replaceAll('review-1-retry-2','review-1-retry-3'));
|
|
153
|
-
const last=saved.records.at(-1),forged={...body,seq:last.seq+1,id:`runner.${String(saved.records.length+1).padStart(6,'0')}`,previousDigest:last.digest};
|
|
154
|
-
assert.throws(()=>readRunnerHistory([...saved.records,{...forged,digest:digest(forged)}],config,3),{code:'runner_stage'});
|
|
155
|
-
const reopened=f.reopen();assert.deepEqual(reopened.status(),end);
|
|
156
|
-
// No fourth registration, even with a grant that would dispatch.
|
|
157
|
-
const refused=await reopened.executeEffect({...f.effect('review'),id:'review-1-retry-3'});
|
|
158
|
-
assert.deepEqual([refused.outcome,refused.code],['rejected','review_not_dispatched_limit']);
|
|
159
|
-
assert.equal(f.getStore().snapshot().records.length,saved.records.length);assert.equal(f.dispatches(),0);
|
|
160
|
-
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{if(expiring>0)grant.expiresAt=150;})});
|
|
161
|
-
});
|
|
162
|
-
// The bound counts not-dispatched ends only: two of them, then a dispatched review, is approved.
|
|
163
|
-
test('a review dispatched on the second never-dispatched redispatch is accepted',()=>{
|
|
164
|
-
let expiring=2;
|
|
165
|
-
return fixture(async f=>{
|
|
166
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
167
|
-
await runner.executeEffect(f.effect('review'));expiring--;
|
|
168
|
-
await f.reopen().executeEffect({...f.effect('review'),id:'review-1-retry-1'});expiring--;
|
|
169
|
-
const approved=await f.reopen().executeEffect({...f.effect('review'),id:'review-1-retry-2'});
|
|
170
|
-
assert.equal(approved.state,'approved',JSON.stringify(approved));assert.equal(f.dispatches(),1);
|
|
171
|
-
assert.deepEqual(f.reopen().status(),approved);
|
|
172
|
-
},{times:[100,101,200],authorize:(request,{authorizationAt})=>grantFor(request,authorizationAt,grant=>{if(expiring>0)grant.expiresAt=150;})});
|
|
173
|
-
});
|
|
174
|
-
test('V3 non-monotonic dispatch clock is journaled as clock_invalid without adapter dispatch',()=>fixture(async f=>{
|
|
175
|
-
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
176
|
-
const end=await runner.executeEffect(f.effect('review'));
|
|
177
|
-
assert.equal(end.state,'pending_review');assert.equal(end.code,'clock_invalid');assert.equal(f.dispatches(),0);
|
|
178
|
-
assert.equal(end.reviewInvocation.result.outcome,'not_dispatched');
|
|
179
|
-
assert.equal(end.reviewInvocation.result.reason,'clock_invalid');
|
|
180
|
-
assert.equal(end.reviewInvocation.result.dispatchAt,99);
|
|
181
|
-
assert.equal(end.reviewInvocation.registration.registeredAt,101);
|
|
182
|
-
assert.equal(end.calls.at(-1).terminal,'not_dispatched');assert.equal(end.receipt,null);
|
|
183
|
-
const saved=f.getStore().snapshot();
|
|
184
|
-
assert.equal(readRunnerHistory(saved.records,saved.records[0].payload.config,3).state.code,'clock_invalid');
|
|
185
|
-
assert.deepEqual(f.reopen().status(),end);
|
|
186
|
-
},{times:[100,101,99]}));
|
|
187
|
-
|
|
188
80
|
test('runner timer without a result shares pending/blocked timeout transitions and replay',()=>fixture(async f=>{
|
|
189
81
|
const runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
190
82
|
const end=await runner.executeEffect(f.effect('review'));
|
|
@@ -221,7 +113,7 @@ test('runner timer without a result shares pending/blocked timeout transitions a
|
|
|
221
113
|
onEvent({event:'thread.started',provider_thread:`thread-${request.invocationId}`});return new Promise(()=>{});
|
|
222
114
|
}}));
|
|
223
115
|
|
|
224
|
-
test('each attempt gets one retry without consuming the six-effect budget or reusing
|
|
116
|
+
test('each attempt gets one retry without consuming the six-effect budget or reusing bindings',()=>fixture(async f=>{
|
|
225
117
|
const attempts=new Map();
|
|
226
118
|
f.options.reviewers[0].run=(request,control)=>{
|
|
227
119
|
const attempt=request.identity.attempt,count=(attempts.get(attempt)??0)+1;attempts.set(attempt,count);
|
|
@@ -238,8 +130,8 @@ test('each attempt gets one retry without consuming the six-effect budget or reu
|
|
|
238
130
|
runner=f.reopen();assert.deepEqual(runner.status(),first);
|
|
239
131
|
const second=await runner.executeEffect(retryEffect(f,attempt));
|
|
240
132
|
assert.equal(second.state,attempt===1?'changes_requested':'approved');
|
|
241
|
-
assert.notEqual(first.reviewInvocation.registration.
|
|
242
|
-
assert.notEqual(first.reviewInvocation.registration.
|
|
133
|
+
assert.notEqual(first.reviewInvocation.registration.binding.invocationId,second.reviewInvocation.registration.binding.invocationId);
|
|
134
|
+
assert.notEqual(first.reviewInvocation.registration.binding.requestDigest,second.reviewInvocation.registration.binding.requestDigest);
|
|
243
135
|
runner=f.reopen();assert.deepEqual(runner.status(),second);
|
|
244
136
|
}
|
|
245
137
|
const records=f.getStore().snapshot().records,history=readRunnerHistory(records,records[0].payload.config,3);
|
|
@@ -271,10 +163,10 @@ test('interrupted V3 review needs explicit abandonment and replays the audited e
|
|
|
271
163
|
const next=f.reopen();
|
|
272
164
|
const result=await next.executeEffect(retryEffect(f));
|
|
273
165
|
assert.equal(result.state,'approved');
|
|
274
|
-
assert.notEqual(result.reviewInvocation.registration.
|
|
275
|
-
abandoned.reviewInvocation.registration.
|
|
276
|
-
assert.notEqual(result.reviewInvocation.registration.
|
|
277
|
-
abandoned.reviewInvocation.registration.
|
|
166
|
+
assert.notEqual(result.reviewInvocation.registration.binding.invocationId,
|
|
167
|
+
abandoned.reviewInvocation.registration.binding.invocationId);
|
|
168
|
+
assert.notEqual(result.reviewInvocation.registration.binding.requestDigest,
|
|
169
|
+
abandoned.reviewInvocation.registration.binding.requestDigest);
|
|
278
170
|
}));
|
|
279
171
|
|
|
280
172
|
test('registered review without a started record can also be abandoned',()=>fixture(async f=>{
|
|
@@ -342,7 +234,7 @@ test('conversation reports unknown cancel truthfully, then consumes abandonment
|
|
|
342
234
|
assert.equal((await noFlag.handle(request('abandon_review',{reason:'old process exited'}))).outcome,'rejected');
|
|
343
235
|
assert.deepEqual(f.getStore().snapshot(),before);
|
|
344
236
|
const entry=createCmAiConversationEntry({specsDir:path.dirname(f.tasksPath),codeProject:f.root,
|
|
345
|
-
feature:'feature',identity:f.options.identity,runner,allowAbandonReview:true
|
|
237
|
+
feature:'feature',identity:f.options.identity,runner,allowAbandonReview:true});
|
|
346
238
|
const cancelled=await entry.handle(request('cancel'));
|
|
347
239
|
assert.equal(cancelled.outcome,'reported');assert.equal(cancelled.state,'unknown');
|
|
348
240
|
assert.equal(cancelled.pendingAction,'abandon_review');
|
|
@@ -502,7 +394,7 @@ test(`factory passes exact configured timeout to ${runtime} reviewer, provider m
|
|
|
502
394
|
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,provider:runtime,cli_model:'fixture',
|
|
503
395
|
prompt_transport:'stdin',config_fingerprint:(runtime==='codex'?configFingerprint:claudeReviewFingerprint)(workerOptions)}};
|
|
504
396
|
const timeoutMs=providerMode?6789:5123;
|
|
505
|
-
const execution=createConversationExecution(definition,'host-test',{call:()=>assert.fail('unexpected host call')},review,
|
|
397
|
+
const execution=createConversationExecution(definition,'host-test',{call:()=>assert.fail('unexpected host call')},review,null,null,false,runtime,
|
|
506
398
|
{protection:{checkCommands:[{id:'syntax',command:[process.execPath,'--version']}],timeoutMs},
|
|
507
399
|
...(providerMode?{providerDevelopment:{model:'fixture',attempt:1,coderRuntime:runtime,reviewerRuntime:runtime}}:{})});
|
|
508
400
|
const timers=[],originalTimer=globalThis.setTimeout;
|
|
@@ -526,21 +418,16 @@ test(`factory passes exact configured timeout to ${runtime} reviewer, provider m
|
|
|
526
418
|
}finally{t.mock.restoreAll();syncBuiltinESMExports();}
|
|
527
419
|
}));
|
|
528
420
|
|
|
529
|
-
for(const boundary of ['
|
|
421
|
+
for(const boundary of ['package-drift','cancelled'])
|
|
530
422
|
test(`retry preserves original authorization/package/cancellation boundary: ${boundary}`,()=>fixture(async f=>{
|
|
531
|
-
if(boundary==='stale-grant'){
|
|
532
|
-
let firstGrant;
|
|
533
|
-
f.options.reviewInvocation.authorize=(request,{authorizationAt})=>firstGrant??=grantFor(request,authorizationAt);
|
|
534
|
-
}
|
|
535
423
|
let runner=f.make();await runner.executeEffect(f.effect('develop'));
|
|
536
424
|
const pending=await runner.executeEffect(f.effect('review'));assert.equal(pending.state,'pending_review');
|
|
537
425
|
if(boundary==='package-drift')fs.writeFileSync(path.join(f.root,'code.js'),'outside drift\n');
|
|
538
426
|
if(boundary==='cancelled')runner.cancel();
|
|
539
|
-
|
|
427
|
+
runner=f.reopen();
|
|
540
428
|
const result=await runner.executeEffect(retryEffect(f));
|
|
541
|
-
assert.equal(result.code,boundary==='
|
|
429
|
+
assert.equal(result.code,boundary==='package-drift'?'package_mismatch':'stage_mismatch');
|
|
542
430
|
assert.equal(f.dispatches(),1);
|
|
543
|
-
if(boundary==='stale-grant')assert.equal(f.reopen().status().state,'unknown');
|
|
544
431
|
},{reviewRun:timeoutRun}));
|
|
545
432
|
|
|
546
433
|
// V5 (A33): a reviewer whose worker proved its process gone without a final
|
|
@@ -619,7 +506,7 @@ test('review-redispatch replay refuses forged, duplicate and over-limit records'
|
|
|
619
506
|
const duplicate=structuredClone(records.slice(0,at+1));duplicate.push(structuredClone(records[at]));
|
|
620
507
|
assert.throws(()=>readRunnerHistory(resequence(duplicate),config,3),{code:'runner_review_redispatch'});
|
|
621
508
|
const third=structuredClone(records);third.push({...structuredClone(records[at]),payload:{...records[at].payload,
|
|
622
|
-
effectId:'review-1-retry-2',invocationId:readRunnerHistory(records,config,3).state.reviewInvocation.registration.
|
|
509
|
+
effectId:'review-1-retry-2',invocationId:readRunnerHistory(records,config,3).state.reviewInvocation.registration.binding.invocationId}});
|
|
623
510
|
assert.throws(()=>readRunnerHistory(resequence(third),config,3),{code:'runner_review_redispatch'});
|
|
624
511
|
// A journal without the record (older version) replays the spent block unchanged;
|
|
625
512
|
// drivers read it through the same projection the host shows.
|