@aibyzero/cm-workflow 0.16.9 → 0.17.1
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 +18 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +16 -1
- package/VERSION +1 -1
- package/docs/architecture.md +29 -13
- 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/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +104 -85
- 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/claude-review-stream.mjs +12 -8
- 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 +112 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +124 -25
- 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-check.mjs +3 -1
- 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-session.mjs +41 -8
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +25 -9
- 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 +57 -54
- 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 +41 -101
- 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-prd/summary.mjs +27 -12
- 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 +61 -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 +83 -47
- 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 +46 -14
- 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 +192 -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 +57 -27
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +46 -87
- 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 +47 -16
- 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 +34 -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-operator-guidance.test.mjs +56 -0
- 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 +35 -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-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-stream.test.mjs +36 -0
- package/scripts/cm-claude-worker.test.mjs +21 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-external-batch-host.test.mjs +38 -17
- 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-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- 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-host-stage-observer.test.mjs +41 -0
- 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 +135 -29
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-drive.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +31 -0
- package/scripts/cm-release-smoke.sh +2 -14
- 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/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- 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 +98 -29
- 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
|
@@ -9,6 +9,7 @@ import {fileURLToPath} from 'node:url';
|
|
|
9
9
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
10
10
|
import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
|
|
11
11
|
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
12
|
+
import {syntheticReviewConfig} from './cm-ai-host-fixture.mjs';
|
|
12
13
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
13
14
|
|
|
14
15
|
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-launch-diagnostics-home-'));
|
|
@@ -29,10 +30,11 @@ function fixture(t){
|
|
|
29
30
|
fs.writeFileSync(path.join(codeProject,'requirements.md'),'# Fixture\n');
|
|
30
31
|
const config=path.join(root,'run.json'),review=path.join(root,'review.json'),workflow=path.join(root,'workflow.json');
|
|
31
32
|
fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature,identity,scope:['target.mjs'],requirements:['requirements.md']}));
|
|
32
|
-
fs.writeFileSync(review,JSON.stringify(
|
|
33
|
+
fs.writeFileSync(review,JSON.stringify(syntheticReviewConfig(codeProject,'claude')));
|
|
33
34
|
fs.writeFileSync(workflow,JSON.stringify({documentationPaths:[],applicableAgentFiles:[],qa:null}));
|
|
34
35
|
const env={...process.env,CM_WORKFLOW_HOME:path.join(root,'home'),CM_WORKFLOW_LOG_HOME:path.join(root,'logs'),NODE_NO_WARNINGS:'1'};
|
|
35
36
|
const host=(mode,{hostContext='session-a',extra=[]}={})=>{
|
|
37
|
+
fs.writeFileSync(review,JSON.stringify(syntheticReviewConfig(codeProject,extra.includes('claude')?'claude':'codex')));
|
|
36
38
|
const result=spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context',hostContext,
|
|
37
39
|
'--allow-development',...extra],{encoding:'utf8',env,timeout:20000,
|
|
38
40
|
input:JSON.stringify({version:1,operation:'status',requestId:'status',identity})+'\n'});
|
|
@@ -46,7 +48,7 @@ test('create without --review-config is refused with the reason and leaves no ru
|
|
|
46
48
|
const f=fixture(t);
|
|
47
49
|
const refused=f.host('create');
|
|
48
50
|
assert.equal(refused.status,1);assert.equal(refused.error.code,'review_configuration_required');
|
|
49
|
-
assert.match(refused.error.reason,/--review-config/);assert.match(refused.error.reason
|
|
51
|
+
assert.match(refused.error.reason,/--review-config/);assert.match(refused.error.reason,/自动派发 fresh Review/);
|
|
50
52
|
assert.equal(fs.existsSync(path.join(f.specsDir,'.reviews','.execution',identity.runId)),false);
|
|
51
53
|
const created=f.host('create',{extra:['--review-config',f.review]});
|
|
52
54
|
assert.equal(created.status,0,created.stderr);
|
|
@@ -94,6 +96,7 @@ test('driver PLAN without runtime reaches the host diagnosis for a Claude run',t
|
|
|
94
96
|
const plan=path.join(f.root,'plan.json');
|
|
95
97
|
fs.writeFileSync(plan,JSON.stringify({config:'run.json',mode:'resume',hostContext:'session-a',
|
|
96
98
|
permissions:['--review-config','review.json']}));
|
|
99
|
+
fs.writeFileSync(f.review,JSON.stringify(syntheticReviewConfig(f.codeProject,'codex')));
|
|
97
100
|
const result=spawnSync(process.execPath,[driver,'--plan',plan,'status'],{encoding:'utf8',env:f.env,timeout:30000});
|
|
98
101
|
assert.notEqual(result.status,0);
|
|
99
102
|
assert.match(result.stderr,/fingerprint_mismatch/);assert.match(result.stderr,/--runtime:创建时为 claude/);
|
|
@@ -107,7 +110,6 @@ test('invalid_arguments names the argument',t=>{
|
|
|
107
110
|
[['--browser-qa','available','--review-config',f.review],/没有适用的交互式 QA/],
|
|
108
111
|
[['--no-such-flag'],/未知参数:--no-such-flag/],
|
|
109
112
|
[['--review-config',f.review,'--review-config',f.review],/参数重复:--review-config/],
|
|
110
|
-
[['--allow-review-attempt','3','--review-config',f.review],/只接受 1 或 2/],
|
|
111
113
|
[['--input-limit','12'],/--input-limit/],
|
|
112
114
|
]){
|
|
113
115
|
const result=f.host('create',{extra});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Synthetic, hash-valid historical envelopes exercise the actual CLI before
|
|
2
|
+
// fingerprint reconstruction. They are refusal fixtures, not review evidence.
|
|
3
|
+
import test 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 {spawnSync} from 'node:child_process';
|
|
9
|
+
import {fileURLToPath} from 'node:url';
|
|
10
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
const root=fileURLToPath(new URL('..',import.meta.url));
|
|
12
|
+
function fixture(t,payload){
|
|
13
|
+
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-legacy-history-')));
|
|
14
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
15
|
+
const specsDir=path.join(dir,'specs'),codeProject=path.join(dir,'code'),identity={repositoryId:'fixture',runId:'old-run-fixture',taskId:'T-001',attempt:1};
|
|
16
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(specsDir);
|
|
17
|
+
const execution=path.join(specsDir,'.reviews','.execution',identity.runId);
|
|
18
|
+
fs.mkdirSync(execution,{recursive:true,mode:0o700});
|
|
19
|
+
fs.chmodSync(path.join(specsDir,'.reviews','.execution'),0o700);
|
|
20
|
+
const body={version:1,seq:1,id:'registration',kind:'intent',payload,previousDigest:null};
|
|
21
|
+
const state={version:1,identity:{repositoryId:identity.repositoryId,runId:identity.runId},
|
|
22
|
+
fingerprints:{workflow:digest('old-workflow'),config:digest('old-config'),inputs:digest('old-inputs')},records:[{...body,digest:digest(body)}]};
|
|
23
|
+
const file=path.join(execution,'state.json');fs.writeFileSync(file,JSON.stringify({...state,revision:digest(state)})+'\n',{mode:0o600});
|
|
24
|
+
const config=path.join(dir,'run.json');fs.writeFileSync(config,JSON.stringify({version:1,specsDir,codeProject,feature:'1.work',identity,scope:['a.js'],requirements:[]}));
|
|
25
|
+
const before=fs.readFileSync(file);
|
|
26
|
+
const invoke=(script,args)=>spawnSync(process.execPath,[path.join(root,'scripts',script),...args],{encoding:'utf8',input:'',timeout:10000,
|
|
27
|
+
env:{...process.env,CM_WORKFLOW_HOME:path.join(dir,'home'),CM_WORKFLOW_LOG_HOME:path.join(dir,'logs')}});
|
|
28
|
+
return {config,file,before,invoke,execution};
|
|
29
|
+
}
|
|
30
|
+
for(const field of ['grant','authorizationAt'])test(`legacy ${field} refuses at both CLI entries before fingerprint/preflight and never writes`,t=>{
|
|
31
|
+
const f=fixture(t,{type:'review-invocation-registered',[field]:field==='grant'?{kind:'cm-review-dispatch-grant'}:1});
|
|
32
|
+
for(const [script,args] of [
|
|
33
|
+
['cm-ai-run.mjs',['serve','--config',f.config,'--mode','resume']],
|
|
34
|
+
['cm-ai-host.mjs',['serve','--config',f.config,'--mode','resume','--host-context','fixture-host','--allow-development']],
|
|
35
|
+
]){
|
|
36
|
+
const run=f.invoke(script,args);assert.equal(run.status,1,run.stderr);
|
|
37
|
+
const error=JSON.parse(run.stderr.trim().split('\n').at(-1)).error;
|
|
38
|
+
assert.equal(error.code,'runner_invocation');assert.match(error.reason,/旧授权协议不支持恢复/);
|
|
39
|
+
assert.match(error.reason,/inspect-history --config/);assert.doesNotMatch(error.reason,/沿用原文件和参数/);
|
|
40
|
+
assert.equal(run.stdout,'');assert.deepEqual(fs.readFileSync(f.file),f.before);
|
|
41
|
+
assert.deepEqual(fs.readdirSync(f.execution),['state.json']);
|
|
42
|
+
}
|
|
43
|
+
const inspected=f.invoke('cm-ai-run.mjs',['inspect-history','--config',f.config]);assert.equal(inspected.status,0,inspected.stderr);
|
|
44
|
+
const history=JSON.parse(inspected.stdout);assert.equal(history.records[0].type,'review-invocation-registered');
|
|
45
|
+
assert.equal(history.records[0].legacyReviewGrant,true);assert.deepEqual(fs.readFileSync(f.file),f.before);
|
|
46
|
+
assert.equal(Object.hasOwn(history.records[0],'grant'),false);
|
|
47
|
+
});
|
|
48
|
+
test('read-only history validates store digest and never bypasses corrupt evidence',t=>{
|
|
49
|
+
const f=fixture(t,{type:'review-invocation-registered',grant:{}});
|
|
50
|
+
const raw=JSON.parse(f.before);raw.records[0].payload.grant.changed=true;fs.writeFileSync(f.file,JSON.stringify(raw)+'\n');
|
|
51
|
+
const bytes=fs.readFileSync(f.file),run=f.invoke('cm-ai-run.mjs',['inspect-history','--config',f.config]);
|
|
52
|
+
assert.equal(run.status,1);assert.match(run.stderr,/store_corrupt/);assert.equal(run.stdout,'');assert.deepEqual(fs.readFileSync(f.file),bytes);
|
|
53
|
+
});
|
|
@@ -12,7 +12,7 @@ import {fileURLToPath,pathToFileURL} from 'node:url';
|
|
|
12
12
|
import {CHECK_DRIVE_COPIED_FILES} from './cm-check-drive-files.mjs';
|
|
13
13
|
|
|
14
14
|
const root=fileURLToPath(new URL('..',import.meta.url));
|
|
15
|
-
const GUIDANCE='runtime/js/cm-ai/operator-guidance.mjs'
|
|
15
|
+
const GUIDANCE='runtime/js/cm-ai/operator-guidance.mjs';
|
|
16
16
|
|
|
17
17
|
// Copy exactly `files` (optionally appending `append` to `entry`) and import `entry` from the copy.
|
|
18
18
|
function importFromCopy(t,entry,files,append=''){
|
|
@@ -26,11 +26,8 @@ function importFromCopy(t,entry,files,append=''){
|
|
|
26
26
|
{encoding:'utf8',cwd:dir});
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
test('
|
|
30
|
-
const run=importFromCopy(t,
|
|
31
|
-
});
|
|
32
|
-
test('operator-guidance.mjs imports with only itself and review-dispatch-limits.mjs copied',t=>{
|
|
33
|
-
const run=importFromCopy(t,GUIDANCE,[GUIDANCE,LIMITS]);assert.equal(run.status,0,run.stderr);
|
|
29
|
+
test('operator-guidance.mjs imports with only itself copied',t=>{
|
|
30
|
+
const run=importFromCopy(t,GUIDANCE,[GUIDANCE]);assert.equal(run.status,0,run.stderr);
|
|
34
31
|
});
|
|
35
32
|
test('operator-guidance.mjs imports from exactly the partial runtime cm-check-drive.test.mjs copies',t=>{
|
|
36
33
|
const run=importFromCopy(t,GUIDANCE,CHECK_DRIVE_COPIED_FILES);assert.equal(run.status,0,run.stderr);
|
|
@@ -52,6 +49,6 @@ for(const [name,append] of REACH)
|
|
|
52
49
|
assert.match(run.stderr,/ERR_MODULE_NOT_FOUND/);
|
|
53
50
|
});
|
|
54
51
|
test('guard fails when operator-guidance.mjs gains an import of a file only the wider cm-check copy has',t=>{
|
|
55
|
-
const run=importFromCopy(t,GUIDANCE,[GUIDANCE
|
|
52
|
+
const run=importFromCopy(t,GUIDANCE,[GUIDANCE],"\nimport x from './effect-contract.mjs'\n");
|
|
56
53
|
assert.notEqual(run.status,0);assert.match(run.stderr,/ERR_MODULE_NOT_FOUND/);
|
|
57
54
|
});
|
|
@@ -253,8 +253,7 @@ test('integrated original multi-root conversation completes one task and resumes
|
|
|
253
253
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:definition.scope.map(file=>({
|
|
254
254
|
path:file,beforeSha256:payload.expected[file],content:'export const value = 2;\\n'}))};
|
|
255
255
|
}
|
|
256
|
-
if(kind==='qa_assess')return {
|
|
257
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
256
|
+
if(kind==='qa_assess')return {confirmed:true};
|
|
258
257
|
assert.equal(kind,'documentation_inspect');
|
|
259
258
|
for(const file of definition.scope)assert.equal(fs.readFileSync(path.join(definition.codeProject,file),'utf8'),'export const value = 2;\\n');
|
|
260
259
|
const {syncId,identity,packageDigest,contextDigest}=payload;
|
|
@@ -263,11 +262,12 @@ test('integrated original multi-root conversation completes one task and resumes
|
|
|
263
262
|
}};
|
|
264
263
|
const review={model:'fixture',disabledSkills:[],preflight:{passed:true,provider:'claude',cli_model:'fixture',prompt_transport:'stdin',
|
|
265
264
|
config_fingerprint:claudeReviewFingerprint({cwd:definition.codeProject,model:'fixture'})}};
|
|
266
|
-
const execution=createConversationExecution(definition,'multi-root-host',bridge,review,
|
|
265
|
+
const execution=createConversationExecution(definition,'multi-root-host',bridge,review,null,
|
|
267
266
|
workflow,true,'claude',{protection});
|
|
268
267
|
const run=await openControlRun(definition,mode,execution);
|
|
269
268
|
assert(run.host,JSON.stringify(run));
|
|
270
|
-
|
|
269
|
+
// Preserve the explicit pre-review checkpoint; advance now also performs review and closeout.
|
|
270
|
+
try{const result=await run.host.handle({version:1,operation:mode==='create'?'start':'advance',requestId:mode==='create'?'start':'advance',identity:definition.identity});
|
|
271
271
|
process.stdout.write(JSON.stringify({result,calls,checkpoint:run.checkpoint()}));}finally{run.close();}`;
|
|
272
272
|
const invoke=mode=>JSON.parse(execFileSync(process.execPath,['--input-type=module','-e',source,configFile,mode],
|
|
273
273
|
{env,encoding:'utf8',timeout:18000,maxBuffer:2*1024*1024}));
|
|
@@ -36,8 +36,7 @@ function workflowCli(args,codeProject,documentationStatus='completed'){
|
|
|
36
36
|
const row=JSON.parse(line);
|
|
37
37
|
if(row.type==='host_request'){
|
|
38
38
|
calls.push(row.kind);let value;
|
|
39
|
-
if(row.kind==='qa_assess')value={
|
|
40
|
-
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
39
|
+
if(row.kind==='qa_assess')value={confirmed:true};
|
|
41
40
|
else{
|
|
42
41
|
assert.equal(row.kind,'documentation_inspect','no unprotected write/check request');
|
|
43
42
|
assert.equal(fs.readFileSync(path.join(codeProject,'README.md'),'utf8'),'# Updated\n');
|
|
@@ -74,8 +73,7 @@ async function fixture(fn){
|
|
|
74
73
|
"require('node:assert/strict').equal(require('node:fs').readFileSync('a.js','utf8'),'new\\n')"]}],
|
|
75
74
|
reviewerPreflight:{passed:true,cli_model:'synthetic',prompt_transport:'stdin',
|
|
76
75
|
config_fingerprint:configFingerprint({cwd:codeProject,model:'synthetic'})}};
|
|
77
|
-
const authority={authorizeDevelopment:()=>({status:'approved'})
|
|
78
|
-
authorizeReview:()=>assert.fail('No real review authorization'),hostDecision:{status:'denied',code:'permission_denied'}};
|
|
76
|
+
const authority={authorizeDevelopment:()=>({status:'approved'})};
|
|
79
77
|
try{await fn({root,definition,config,authority});}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
80
78
|
}
|
|
81
79
|
|
|
@@ -99,12 +97,12 @@ for(const runtime of ['codex','claude'])test(`protected ${runtime} conversation
|
|
|
99
97
|
const wrong={...definition,scope:['b.js']};
|
|
100
98
|
await assert.rejects(openControlRun(wrong,'create',execution),{code:'execution_definition_mismatch'});
|
|
101
99
|
let run=await openControlRun(definition,'create',execution);
|
|
102
|
-
try{const result=await run.host.handle(request('
|
|
100
|
+
try{const result=await run.host.handle(request('start'));assert.equal(result.code,null,JSON.stringify(result));}
|
|
103
101
|
finally{run.close();}
|
|
104
102
|
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n');
|
|
105
103
|
assert.equal(calls,1);
|
|
106
104
|
run=await openControlRun(definition,'resume',make());
|
|
107
|
-
try{const result=await run.host.handle(request('
|
|
105
|
+
try{const result=await run.host.handle(request('start'));assert.equal(result.code,null);assert.equal(calls,1);}
|
|
108
106
|
finally{run.close();}
|
|
109
107
|
assert.match(fs.readFileSync(path.join(definition.specsDir,definition.feature,'tasks.md'),'utf8'),/\[ \]/);
|
|
110
108
|
}));
|
|
@@ -214,8 +212,7 @@ let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end'
|
|
|
214
212
|
documentationPaths:['README.md'],applicableAgentFiles:[]};
|
|
215
213
|
fs.writeFileSync(workflowFile,JSON.stringify(workflow));
|
|
216
214
|
const args=['serve','--config',runFile,'--mode','create','--host-context','host','--allow-development',
|
|
217
|
-
'--protected-config',protectedFile,'--allow-provider-development-attempt','1','--review-config',reviewFile,
|
|
218
|
-
'--allow-review-attempt','1','--workflow-config',workflowFile,'--allow-qa'];
|
|
215
|
+
'--protected-config',protectedFile,'--allow-provider-development-attempt','1','--review-config',reviewFile,'--workflow-config',workflowFile,'--allow-qa'];
|
|
219
216
|
const denied=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),...args.slice(0,-1)],{encoding:'utf8',timeout:5000});
|
|
220
217
|
assert.equal(denied.status,1);assert(denied.stderr.includes('qa_authorization_required'));
|
|
221
218
|
assert(!fs.existsSync(path.join(config.specsRoot,'.reviews')));
|
|
@@ -243,21 +240,21 @@ let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end'
|
|
|
243
240
|
assert.equal(logs.find(row=>row.event==='test_run'&&row.phase==='complete').result,'PASS');
|
|
244
241
|
return;
|
|
245
242
|
}
|
|
246
|
-
const invoke=(mode,flags=[],attempt='1')=>{
|
|
243
|
+
const invoke=(mode,flags=[],attempt='1',operation='advance')=>{
|
|
247
244
|
const child=spawnSync(process.execPath,[fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url)),
|
|
248
245
|
'serve','--config',runFile,'--mode',mode,'--host-context','host','--allow-development',
|
|
249
246
|
'--protected-config',protectedFile,'--allow-provider-development-attempt',attempt,'--review-config',reviewFile,...flags],
|
|
250
|
-
{encoding:'utf8',input:JSON.stringify(request(
|
|
247
|
+
{encoding:'utf8',input:JSON.stringify({...request(operation),identity:{...identity,attempt:Number(attempt)}})+'\n',timeout:12000});
|
|
251
248
|
assert.equal(child.status,0,child.stderr);
|
|
252
249
|
const rows=child.stdout.trim().split('\n').map(JSON.parse);
|
|
253
250
|
assert(!rows.some(row=>row.type==='host_request'),'protected mode never asks current host to perform unprotected writes');
|
|
254
|
-
return rows.find(row=>row.requestId===
|
|
251
|
+
return rows.find(row=>row.requestId===operation).result;
|
|
255
252
|
};
|
|
256
|
-
assert.equal(invoke('create').state,'awaiting_review');
|
|
253
|
+
assert.equal(invoke('create',[],'1','start').state,'awaiting_review');
|
|
257
254
|
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
258
|
-
assert.equal(invoke('resume').state,'awaiting_review');
|
|
255
|
+
assert.equal(invoke('resume',[],'1','start').state,'awaiting_review');
|
|
259
256
|
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
260
|
-
let result=invoke('resume',[
|
|
257
|
+
let result=invoke('resume',[]);
|
|
261
258
|
if(launch==='revision'){
|
|
262
259
|
assert.equal(result.state,'changes_requested');assert.equal(result.identity.attempt,2);
|
|
263
260
|
assert.equal(result.code,'provider_development_authorization_required');
|
|
@@ -266,9 +263,9 @@ let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end'
|
|
|
266
263
|
const before=fs.readFileSync(journal);assert(!before.includes('"id":"develop-2"'));
|
|
267
264
|
assert.equal(invoke('resume').code,'provider_development_authorization_required');
|
|
268
265
|
assert.deepEqual(fs.readFileSync(journal),before,'waiting for permission does not mutate the journal');
|
|
269
|
-
result=invoke('resume',[],'2');assert.equal(result.state,'awaiting_review');
|
|
266
|
+
result=invoke('resume',[],'2','start');assert.equal(result.state,'awaiting_review');
|
|
270
267
|
assert.equal(fs.readFileSync(calls,'utf8'),'developer\nreview\ndeveloper\n');
|
|
271
|
-
result=invoke('resume',[
|
|
268
|
+
result=invoke('resume',[],'2');
|
|
272
269
|
}
|
|
273
270
|
assert.equal(result.state,'fixture_completed',JSON.stringify(result));
|
|
274
271
|
assert.equal(result.code,'qa_decision_required');
|
|
@@ -281,8 +278,8 @@ let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end'
|
|
|
281
278
|
}
|
|
282
279
|
const execution=await createCodexExecution(config,authority);
|
|
283
280
|
run=await openControlRun(definition,'create',execution);
|
|
284
|
-
const result=await run.host.handle(request('
|
|
285
|
-
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.outcome,'
|
|
281
|
+
const result=await run.host.handle(request('start'));
|
|
282
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.outcome,'advanced');
|
|
286
283
|
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
287
284
|
assert.equal(fs.readFileSync(path.join(definition.codeProject,'a.js'),'utf8'),'new\n');
|
|
288
285
|
const task=path.join(definition.specsDir,definition.feature,'tasks.md');
|
|
@@ -293,7 +290,7 @@ let input='';process.stdin.on('data',chunk=>input+=chunk);process.stdin.on('end'
|
|
|
293
290
|
assert(!handoff.changed_files.some(file=>file.startsWith('specs/')));
|
|
294
291
|
run.close();run=null;
|
|
295
292
|
run=await openControlRun(definition,'resume',await createCodexExecution(config,authority));
|
|
296
|
-
assert.equal((await run.host.handle(request('
|
|
293
|
+
assert.equal((await run.host.handle(request('start'))).state,'awaiting_review');
|
|
297
294
|
assert.equal(fs.readFileSync(calls,'utf8'),'developer\n');
|
|
298
295
|
assert.equal(fs.readFileSync(task,'utf8'),'- [ ] T-001: implement\n');
|
|
299
296
|
}finally{run?.close();process.env.PATH=previousPath;}
|
|
@@ -117,3 +117,59 @@ test('V5 the second no-result redispatch asks for the operator stop confirmation
|
|
|
117
117
|
const g=explain('blocked','review_transport_timeout','abandon_review',{reviewRedispatchStopRequired:true});
|
|
118
118
|
assert.equal(g.recoveryOperation,'abandon_review');assert.match(g.nextStep,/确认原审查进程/);assert.equal(g.authorizationGranted,false);
|
|
119
119
|
});
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
test('recovery guidance selects protocol and surface without changing native results',()=>{
|
|
123
|
+
const cases=[['unknown','execution_error','abandon_effect'],['unknown','execution_error','abandon_review'],
|
|
124
|
+
['blocked','bootstrap_review_mismatch','bootstrap_review_recover'],['blocked','develop_answer_missing','develop_redo'],
|
|
125
|
+
['blocked','documentation_sync_answer_missing','develop_redo']];
|
|
126
|
+
for(const protocol of ['legacy','v2'])for(const surface of ['single','batch'])for(const [state,code,action] of cases){
|
|
127
|
+
const input=result(state,code,action),before=JSON.stringify(input);
|
|
128
|
+
const value={...input,guidance:operatorGuidance(input,{protocol})};
|
|
129
|
+
const output=surface==='batch'?batchMemberResult(value,{protocol,taskKey:'1.work/T-001'}):value;
|
|
130
|
+
const rendered=guidanceText(output);
|
|
131
|
+
assert.equal(output.guidance.recoveryOperation,action);assert.equal(output.guidance.authorizationGranted,false);
|
|
132
|
+
assert.equal(JSON.stringify(input),before);
|
|
133
|
+
assert.equal(output.state,input.state);assert.equal(output.code,input.code);assert.equal(output.pendingAction,input.pendingAction);
|
|
134
|
+
if(protocol==='v2'){
|
|
135
|
+
assert.doesNotMatch(rendered,/--allow-|--supersede-reviewed-evidence/);
|
|
136
|
+
assert.match(rendered,/status/);assert.match(rendered,/expectedControl/);assert.match(rendered,/snapshot_changed/);
|
|
137
|
+
assert.match(rendered,/不自动刷新/);
|
|
138
|
+
}else assert.match(rendered,/--allow-/);
|
|
139
|
+
if(surface==='batch')assert.match(rendered,/批次/);
|
|
140
|
+
if(code==='documentation_sync_answer_missing')assert.match(rendered,/停止修改文档/);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
test('v2 exhausted recovery and launch recovery never advertise legacy exits',()=>{
|
|
145
|
+
for(const code of ['review_redispatch_limit','documentation_sync_retry_limit','check_answer_retry_limit','complete_recheck_limit','develop_redo_limit']){
|
|
146
|
+
for(const protocol of ['legacy','v2'])for(const surface of ['single','batch']){
|
|
147
|
+
const input=result('blocked',code,'none');input.guidance=operatorGuidance(input,{protocol});
|
|
148
|
+
const output=surface==='batch'?batchMemberResult(input,{protocol}):input;
|
|
149
|
+
assert.equal(output.guidance.recoveryOperation,null);
|
|
150
|
+
if(protocol==='v2'){assert.doesNotMatch(guidanceText(output),/--supersede-reviewed-evidence|--accept-superseded-code-drift/);
|
|
151
|
+
assert.match(guidanceText(output),/保留/);}
|
|
152
|
+
else assert.match(guidanceText(output),/--supersede-reviewed-evidence/);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
for(const refusal of ['review_process_unverified','review_observation_invalid','review_boundary_unverified','review_abandon_budget_exhausted']){
|
|
156
|
+
const input=result('unknown','transport_incomplete','reconcile',{reviewAbandonRefusal:refusal});
|
|
157
|
+
input.guidance=operatorGuidance(input,{protocol:'v2'});
|
|
158
|
+
assert.doesNotMatch(guidanceText(input),/--supersede-reviewed-evidence/);
|
|
159
|
+
}
|
|
160
|
+
const qa=result('fixture_completed','qa_execution_unknown','reconcile');qa.guidance=operatorGuidance(qa,{protocol:'v2'});
|
|
161
|
+
assert.match(guidanceText(qa),/launchControlTarget/);assert.match(guidanceText(qa),/--expected-control/);
|
|
162
|
+
assert.doesNotMatch(guidanceText(qa),/--supersede-reviewed-evidence/);
|
|
163
|
+
const batch=batchMemberResult(qa,{protocol:'v2'});
|
|
164
|
+
assert.doesNotMatch(guidanceText(batch),/--rerun-unknown-qa|--expected-control/);
|
|
165
|
+
const drift=result('blocked','spec_drift','spec_rebind',{reason:'synthetic'});drift.guidance=operatorGuidance(drift,{protocol:'v2'});
|
|
166
|
+
assert.doesNotMatch(JSON.stringify(batchMemberResult(drift,{protocol:'v2'})),/--supersede-reviewed-evidence/);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
test('batch advance guidance uses the batch entry for every native resume family',()=>{
|
|
170
|
+
for(const code of ['documentation_sync_interrupted','develop_answer_missing','develop_out_of_scope','check_answer_missing','develop_checks_not_passed']){
|
|
171
|
+
const input=result('blocked',code,'resume');input.guidance=operatorGuidance(input);
|
|
172
|
+
const output=batchMemberResult(input);
|
|
173
|
+
assert.match(guidanceText(output),/原批次入口/);assert.doesNotMatch(guidanceText(output),/恢复原运行/);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
@@ -7,6 +7,7 @@ import childProcess,{spawn,spawnSync} from 'node:child_process';
|
|
|
7
7
|
import {fileURLToPath} from 'node:url';
|
|
8
8
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
9
|
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
10
|
+
import {installSyntheticReview,syntheticReviewConfig} from './cm-ai-host-fixture.mjs';
|
|
10
11
|
import {createConversationExecution} from './cm-ai-host.mjs';
|
|
11
12
|
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
12
13
|
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
@@ -35,14 +36,15 @@ function fixture(t){
|
|
|
35
36
|
fs.writeFileSync(path.join(answers,'target.txt'),'export const value=42;\n');
|
|
36
37
|
fs.writeFileSync(path.join(answers,'develop.json'),JSON.stringify({status:'succeeded',value:{outcome:'implemented',
|
|
37
38
|
application:{status:'no_relevant_lesson',note:null},retrospective:{status:'no_new_lesson',candidates:[],reason:null}},edits:{'target.mjs':'target.txt'}}));
|
|
38
|
-
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify(
|
|
39
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify(syntheticReviewConfig(codeProject)));
|
|
39
40
|
const plan=(checks,extra={})=>{
|
|
40
41
|
const file=path.join(root,'plan.json');
|
|
42
|
+
fs.writeFileSync(path.join(root,'review.json'),JSON.stringify(syntheticReviewConfig(codeProject,extra.runtime??'codex')));
|
|
41
43
|
fs.writeFileSync(file,JSON.stringify({config:'run.json',mode:'create',hostContext:'progress-fixture-host',
|
|
42
44
|
permissions:['--review-config','review.json'],answers:'answers',checks,...extra}));return file;
|
|
43
45
|
};
|
|
44
|
-
const
|
|
45
|
-
const run=(checks,extra={})=>spawnSync(process.execPath,[driver,'--plan',plan(checks,extra),
|
|
46
|
+
const local=installSyntheticReview({root,codeProject});const env=local.env;
|
|
47
|
+
const run=(checks,extra={},operation='start')=>spawnSync(process.execPath,[driver,'--plan',plan(checks,extra),operation],{encoding:'utf8',timeout:30000,env});
|
|
46
48
|
return {root,specsDir,codeProject,feature,definition,statusPath,old,env,plan,run,
|
|
47
49
|
status:()=>JSON.parse(fs.readFileSync(statusPath,'utf8')),
|
|
48
50
|
events:()=>fs.readFileSync(path.join(specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)};
|
|
@@ -62,7 +64,7 @@ for(const runtime of ['codex','claude'])test(`${runtime}: live check replaces ol
|
|
|
62
64
|
const events=f.events().filter(row=>row.event==='progress');
|
|
63
65
|
assert(events.some(row=>row.phase==='start'&&row.phase_name==='developing'));
|
|
64
66
|
assert(events.some(row=>row.phase==='start'&&row.phase_name==='checking'));
|
|
65
|
-
assert(!events.some(row=>row.phase_name==='reviewing'),'
|
|
67
|
+
assert(!events.some(row=>row.phase_name==='reviewing'),'start stops after development without dispatching review');
|
|
66
68
|
for(const start of events.filter(row=>row.phase==='start'))assert(events.some(row=>row.phase==='complete'&&row.operation_id===start.operation_id));
|
|
67
69
|
assert(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8').includes('- [ ] T-001'));
|
|
68
70
|
});
|
|
@@ -102,12 +104,12 @@ test('guidance survives original-run status and recovery without writing it into
|
|
|
102
104
|
const after=snapshot();assert.deepEqual(after.records.slice(0,before.records.length),before.records);
|
|
103
105
|
assert.equal(JSON.stringify(after.records).includes('recoveryOperation'),false);
|
|
104
106
|
assert(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8').includes('- [ ] T-001'));
|
|
105
|
-
assert(!f.events().some(row=>row.phase_name==='reviewing'),'
|
|
107
|
+
assert(!f.events().some(row=>row.phase_name==='reviewing'),'start recovery preserves the development stage');
|
|
106
108
|
});
|
|
107
109
|
|
|
108
110
|
test('a quiet command announces its start before finishing and preserves the JSON result channel',async t=>{
|
|
109
111
|
const f=fixture(t),plan=f.plan([check('quiet',"setTimeout(()=>process.exit(0),700)")]);
|
|
110
|
-
const child=spawn(process.execPath,[driver,'--plan',plan,'
|
|
112
|
+
const child=spawn(process.execPath,[driver,'--plan',plan,'start'],{env:f.env,stdio:['ignore','pipe','pipe']});
|
|
111
113
|
let out='',err='',seen=false,code;
|
|
112
114
|
const timer=setTimeout(()=>child.kill('SIGKILL'),20000);t.after(()=>{clearTimeout(timer);if(child.exitCode===null)child.kill('SIGKILL');});
|
|
113
115
|
child.stdout.on('data',b=>{out+=b;});child.stderr.on('data',b=>{
|
|
@@ -437,14 +439,14 @@ for(const verdict of ['approved','changes_requested'])test(`${verdict}: review p
|
|
|
437
439
|
assert.equal(f.status().state,'awaiting_review');assert.equal(fs.existsSync(observed),false);
|
|
438
440
|
const plan=f.plan(undefined,{mode:'resume',originalHostContext:'progress-fixture-host',answers:undefined,
|
|
439
441
|
packageDigest:JSON.parse(first.stdout).result.packageDigest,
|
|
440
|
-
permissions:['--review-config','review.json'
|
|
442
|
+
permissions:['--review-config','review.json']});
|
|
441
443
|
const run=spawnSync(process.execPath,[driver,'--plan',plan,'decision'],{env:f.env,encoding:'utf8',timeout:30000});
|
|
442
444
|
assert.equal(run.status,0,run.stderr);assert.equal(JSON.parse(run.stdout).result.state,verdict,run.stdout+run.stderr);
|
|
443
445
|
assert.equal(JSON.parse(fs.readFileSync(observed)).state,'reviewing');assert.equal(f.status().state,verdict);
|
|
444
446
|
assert.equal(f.status().attempt,verdict==='approved'?1:2);
|
|
445
447
|
assert(fs.readFileSync(path.join(f.specsDir,f.feature,'tasks.md'),'utf8').includes('- [ ] T-001'));
|
|
446
448
|
if(verdict==='approved'){
|
|
447
|
-
const completed=f.run([check('ok','0')],{mode:'resume',originalHostContext:'progress-fixture-host'});
|
|
449
|
+
const completed=f.run([check('ok','0')],{mode:'resume',originalHostContext:'progress-fixture-host'},'advance');
|
|
448
450
|
assert.equal(completed.status,0,completed.stderr);
|
|
449
451
|
assert.equal(JSON.parse(completed.stdout).result.state,'fixture_completed',completed.stdout+completed.stderr);
|
|
450
452
|
assert.equal(f.status().state,'fixture_completed');assert.equal(f.status().node,'N5');
|
|
@@ -16,6 +16,7 @@ import {captureReviewBaseline,createReviewPackage} from '../runtime/js/cm-ai/rev
|
|
|
16
16
|
import {explainReviewedDrift} from '../runtime/js/cm-ai/fix-code-association.mjs';
|
|
17
17
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
18
18
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
19
|
+
import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
19
20
|
|
|
20
21
|
const isolated=fs.mkdtempSync(path.join(os.tmpdir(),'cm-project-qa-gate-'));
|
|
21
22
|
const saved={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
@@ -63,19 +64,15 @@ function project(){
|
|
|
63
64
|
return {status:'succeeded',value:{verdict:result,packageDigest:review.payload.reviewPackage.packageDigest,
|
|
64
65
|
examinedPaths:reviewPaths(review.payload.reviewPackage),findings:result==='approved'?[]:
|
|
65
66
|
[{id:'F1',severity:'P2',path:'b.mjs',message:'Again',evidence:'Synthetic'}],summary:'Synthetic review'}};}}],
|
|
66
|
-
reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
67
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${review.identity.runId}-${review.identity.attempt}`,
|
|
68
|
-
adapterId:'codex-review-adapter',invocationId:review.invocationId,requestDigest:review.requestDigest,identity:review.identity,
|
|
69
|
-
reviewerId:'reviewer',logicalContextId:review.contextId,packageDigest:review.payload.reviewPackage.packageDigest,hostContextId:'control',
|
|
70
|
-
decisionId:'decision',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
71
|
-
return {...body,grantDigest:digest(body)};}},
|
|
72
|
-
hostDecision:{status:'approved'},check:createHostCheck({cwd:codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
67
|
+
reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
73
68
|
qaLogHome:logHome,applicableAgentFiles:[],
|
|
74
69
|
documentationProvider:{timeoutMs:5000,inspect:async binding=>{state.documentation++;
|
|
75
70
|
return {syncId:binding.syncId,identity:binding.identity,packageDigest:binding.packageDigest,contextDigest:binding.contextDigest,
|
|
76
71
|
status:'completed',reason:'Documentation checked',at:'2026-09-28T00:00:00Z'};}},
|
|
77
|
-
qaDecisionProvider:{timeoutMs:1000,decide:async binding=>(
|
|
78
|
-
|
|
72
|
+
qaDecisionProvider:{timeoutMs:1000,decide:async binding=>{assert.equal(binding.changedFiles.source,'review_package');
|
|
73
|
+
assert(binding.changedFiles.paths.includes(feature==='1.work'?'a.mjs':'b.mjs'));
|
|
74
|
+
return ({decisionId:`qa-${binding.identity.runId}`,identity:binding.identity,
|
|
75
|
+
packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-28T00:00:00Z',...decision});}},
|
|
79
76
|
qaExecutor:createExecutor({specsDir,codeProject,feature,requirements:['requirements.md'],runtime:'codex',
|
|
80
77
|
commands:[{id:'unit',command:[process.execPath,'--check','a.mjs'],caseIds:[]}],environment,timeoutMs:60000,logHome,
|
|
81
78
|
browser:browser??(async browserRequest=>{
|
|
@@ -98,6 +95,36 @@ function project(){
|
|
|
98
95
|
}
|
|
99
96
|
const status=p=>JSON.parse(fs.readFileSync(path.join(p.specsDir,'.cm-status.json'),'utf8'));
|
|
100
97
|
|
|
98
|
+
test('qaChangedFiles rejects stale_qa before completion and for a mismatched digest after completion',async()=>{
|
|
99
|
+
const p=project(),identity=p.first.identity;
|
|
100
|
+
const terminal=(request,result)=>({version:1,invocationId:request.invocationId,
|
|
101
|
+
contextId:request.contextId,provider:request.provider,effectiveModel:'fixture',status:'succeeded',accepted:true,result});
|
|
102
|
+
const runner=createTaskRunner({root:p.codeProject,identity,scope:p.first.scope,requirements:p.first.requirements,
|
|
103
|
+
excludedContexts:['control'],timeoutMs:5000,
|
|
104
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:request=>{
|
|
105
|
+
fs.writeFileSync(path.join(p.codeProject,'a.mjs'),'export const a=1;\n');
|
|
106
|
+
return terminal(request,{outcome:'implemented'});}},
|
|
107
|
+
reviewers:[{id:'reviewer',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
108
|
+
contexts:['review-one','review-two'],run:request=>terminal(request,{verdict:'approved',
|
|
109
|
+
packageDigest:request.payload.reviewPackage.packageDigest,examinedPaths:reviewPaths(request.payload.reviewPackage),
|
|
110
|
+
findings:[],summary:'Synthetic review'})}],
|
|
111
|
+
check:()=>[{id:'syntax',command:[process.execPath,'--check','a.mjs'],outcome:'passed',exitCode:0,evidence:'fixture'}],
|
|
112
|
+
commit:()=>({outcome:'fixture_completed'})});
|
|
113
|
+
const effect=kind=>({version:1,id:`${kind}-1`,identity,kind});
|
|
114
|
+
const developed=await runner.executeEffect(effect('develop'));
|
|
115
|
+
assert.equal(developed.state,'awaiting_review',JSON.stringify(developed));
|
|
116
|
+
const reviewed=await runner.executeEffect(effect('review'));
|
|
117
|
+
assert.equal(reviewed.state,'approved',JSON.stringify(reviewed));
|
|
118
|
+
assert.throws(()=>runner.qaChangedFiles(reviewed.packageDigest),{code:'stale_qa'});
|
|
119
|
+
const completed=await runner.executeEffect(effect('complete'));
|
|
120
|
+
assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));
|
|
121
|
+
assert.equal(completed.packageDigest,reviewed.packageDigest);
|
|
122
|
+
const wrongDigest=(completed.packageDigest[0]==='0'?'1':'0')+completed.packageDigest.slice(1);
|
|
123
|
+
assert.throws(()=>runner.qaChangedFiles(wrongDigest),{code:'stale_qa'});
|
|
124
|
+
assert.deepEqual(runner.qaChangedFiles(completed.packageDigest),{paths:['a.mjs'],source:'review_package'});
|
|
125
|
+
assert.equal(runner.status().state,'fixture_completed');
|
|
126
|
+
});
|
|
127
|
+
|
|
101
128
|
test('#17 an earlier feature whose QA is BLOCKED keeps the project from run_done until it is recovered; #18 its recovery survives a later reviewed task',async()=>{
|
|
102
129
|
const p=project();
|
|
103
130
|
const blocked=await p.advance(p.first,p.firstExecution(),'create');
|
|
@@ -362,7 +389,7 @@ test('#17 a skip is fine while tasks remain, but a terminal feature whose latest
|
|
|
362
389
|
fs.writeFileSync(tasks,'- [ ] T-001: first\n- [ ] T-002: fixture\n');p.reapprove();
|
|
363
390
|
const first=p.definition('1.work','T-001',['a.mjs']);
|
|
364
391
|
const skipped=await p.advance(first,p.execution('1.work',{write:()=>fs.writeFileSync(path.join(p.codeProject,'a.mjs'),'export const a=1;\n'),
|
|
365
|
-
decision:{status:'skipped',reason:'
|
|
392
|
+
decision:{status:'skipped',reason:'no_fixed_trigger',score:null}}),'create');
|
|
366
393
|
assert.equal(skipped.code,'context_refreshed',JSON.stringify(skipped));
|
|
367
394
|
const midway=inspectCmAiAdmission({specsDir:p.specsDir,codeProject:p.codeProject});
|
|
368
395
|
assert.equal(midway.nextTask.id,'T-002');assert(!midway.warnings.some(line=>line.includes('QA 未通过')),JSON.stringify(midway.warnings));
|
|
@@ -89,8 +89,7 @@ async function runnerFixture(t,scope){
|
|
|
89
89
|
check:()=>{throw new Error('checks must not run');},
|
|
90
90
|
taskCompletion:{reviewsDir,handoffs:[1,2].map(n=>path.join(reviewsDir,`api-native-reading-T-006-a${n}-handoff.json`))},
|
|
91
91
|
taskLearning:{feature:FEATURE,hostHandoff:true},
|
|
92
|
-
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']
|
|
93
|
-
authorize:()=>{throw new Error('review must not be authorized');}}};
|
|
92
|
+
reviewInvocation:{developerThreadId:'actual-developer',excludedThreadIds:['actual-main']}};
|
|
94
93
|
const make=mode=>createTaskRunner({...options,persistence:{store,mode,version:3}});
|
|
95
94
|
const statePath=path.join(reviewsDir,'.execution',identity.runId,'state.json');
|
|
96
95
|
const reopen=()=>{store.close();store=openTaskExecutionStore({...owner,create:false});return make('resume');};
|
|
@@ -80,15 +80,7 @@ function buildExecution(f,{twoAttempts=false}={}){
|
|
|
80
80
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:verdict==='approved'?[]:
|
|
81
81
|
[{id:'F1',severity:'P2',path:'a.js',message:'Review again',evidence:'Synthetic first attempt'}],summary:'Synthetic review'}};
|
|
82
82
|
}}],
|
|
83
|
-
reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main'],
|
|
84
|
-
authorize:(request,{authorizationAt})=>{
|
|
85
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.attempt}`,adapterId:'codex-review-adapter',
|
|
86
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,
|
|
87
|
-
reviewerId:'reviewer',logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,
|
|
88
|
-
hostContextId:'main',decisionId:`decision-${request.identity.attempt}`,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
89
|
-
return {...body,grantDigest:digest(body)};
|
|
90
|
-
}},
|
|
91
|
-
hostDecision:{status:'approved'},
|
|
83
|
+
reviewInvocation:{developerThreadId:'host-author',excludedThreadIds:['main']},
|
|
92
84
|
check:createHostCheck({cwd:f.codeProject,commands:[{id:'content',command:[process.execPath,'-e',
|
|
93
85
|
"require('node:assert/strict').match(require('node:fs').readFileSync('a.js','utf8'),/^new( 2)?\\n$/)"]}]})};
|
|
94
86
|
|
|
@@ -44,9 +44,9 @@ const environment={kind:'web',carrier:'browser',target:'fixture',scope:'local'};
|
|
|
44
44
|
const syntax=[{id:'unit',command:[process.execPath,'--check','a.mjs'],caseIds:[]}];
|
|
45
45
|
|
|
46
46
|
// The real current-conversation factory builds the built-in QA executor.
|
|
47
|
-
const conversation=(f,commands=syntax)=>createConversationExecution(f.definition,'host-session-1',
|
|
47
|
+
const conversation=(f,commands=syntax,criticalPaths=undefined)=>createConversationExecution(f.definition,'host-session-1',
|
|
48
48
|
{call:async()=>{throw new Error('not dispatched');}},null,null,
|
|
49
|
-
{qa:{commands,environment},documentationPaths:[],applicableAgentFiles:[]},true,'claude');
|
|
49
|
+
{qa:{commands,environment,...(criticalPaths===undefined?{}:{criticalPaths})},documentationPaths:[],applicableAgentFiles:[]},true,'claude');
|
|
50
50
|
async function opens(f,mode,execution,options){
|
|
51
51
|
const run=await openControlRun(f.definition,mode,execution,options);run.close();
|
|
52
52
|
}
|
|
@@ -88,13 +88,7 @@ function synthetic(f,{commands=syntax,browser=null}={}){
|
|
|
88
88
|
onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
89
89
|
return {status:'succeeded',value:{verdict:'approved',packageDigest:review.payload.reviewPackage.packageDigest,
|
|
90
90
|
examinedPaths:reviewPaths(review.payload.reviewPackage),findings:[],summary:'Synthetic review'}};}}],
|
|
91
|
-
reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
92
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${review.identity.attempt}`,adapterId:'codex-review-adapter',
|
|
93
|
-
invocationId:review.invocationId,requestDigest:review.requestDigest,identity:review.identity,reviewerId:'reviewer',
|
|
94
|
-
logicalContextId:review.contextId,packageDigest:review.payload.reviewPackage.packageDigest,hostContextId:'control',
|
|
95
|
-
decisionId:'decision',decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
96
|
-
return {...body,grantDigest:digest(body)};}},
|
|
97
|
-
hostDecision:{status:'approved'},check:createHostCheck({cwd:f.codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
91
|
+
reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control']},check:createHostCheck({cwd:f.codeProject,commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]}),
|
|
98
92
|
qaLogHome:logHome,
|
|
99
93
|
qaDecisionProvider:{timeoutMs:1000,decide:async binding=>({decisionId:'qa-decision',identity:binding.identity,
|
|
100
94
|
packageDigest:binding.packageDigest,status:'triggered',reason:'feature_complete',score:null,at:'2026-09-28T00:00:00Z'})},
|
|
@@ -155,3 +149,12 @@ test('#14 a store fingerprinted in the historical plan form still opens and adva
|
|
|
155
149
|
assert.equal((await run.host.handle(request('advance'))).code,'qa_passed');run.close();
|
|
156
150
|
assert.equal(JSON.parse(fs.readFileSync(state)).fingerprints.config,digest(legacy));
|
|
157
151
|
});
|
|
152
|
+
|
|
153
|
+
test('N6 registered critical paths use existing workflow QA seam and fingerprint',async()=>{
|
|
154
|
+
const f=fixture();userRuntimes('codex-codes');
|
|
155
|
+
const registry={payment:['src/payments/**'],api:['a.mjs']};
|
|
156
|
+
const execution=conversation(f,syntax,registry);
|
|
157
|
+
await opens(f,'create',execution);
|
|
158
|
+
await opens(f,'resume',conversation(f,syntax,registry));
|
|
159
|
+
await assert.rejects(opens(f,'resume',conversation(f,syntax,{payment:['src/billing/**']})),{code:'fingerprint_mismatch'});
|
|
160
|
+
});
|
|
@@ -56,7 +56,7 @@ async function fixture(t,{childHost=A,causeContext=null,lostCauseReviews=0,rejec
|
|
|
56
56
|
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
57
57
|
}};
|
|
58
58
|
const executionFor=live=>{
|
|
59
|
-
const execution=createConversationExecution(definition,live,bridge,review,
|
|
59
|
+
const execution=createConversationExecution(definition,live,bridge,review,null,workflow,true,'codex',
|
|
60
60
|
live===A?{}:{originalHostContextId:A});
|
|
61
61
|
execution.check=createHostCheck({cwd:codeProject,commands:[{id:'existing',command:[process.execPath,'existing.mjs']}]});
|
|
62
62
|
execution.reviewers[0].run=async(request,{onEvent})=>{
|
|
@@ -100,13 +100,13 @@ async function fixture(t,{childHost=A,causeContext=null,lostCauseReviews=0,rejec
|
|
|
100
100
|
const childDir=path.join(specsDir,'.reviews','.execution',fix.identity.runId),statePath=path.join(childDir,'state.json');
|
|
101
101
|
const bound=operation=>({...request(operation),packageDigest:failed.packageDigest,testRunId:qaSource.testRunId});
|
|
102
102
|
const close=()=>{owner?.close();owner=null;};
|
|
103
|
-
const open=async(live,{allowStart=true,template=false,allowAbandon=false,lostDiagnosis=false,extraPermissions=[]}={})=>{
|
|
103
|
+
const open=async(live,{allowStart=true,template=false,allowAbandon=false,lostDiagnosis=false,extraPermissions=[],controlPolicy=null}={})=>{
|
|
104
104
|
close();const execution=executionFor(live);assert.equal(execution.configuration.hostContextId,A);
|
|
105
105
|
parent=await openControlRun(definition,'resume',execution);
|
|
106
106
|
const rh=reviewHost(live);
|
|
107
107
|
const {qaSource:ignored,...templateConfiguration}=configuration;
|
|
108
108
|
owner=createQaFixOwnerHost({parent,hostContextId:live,parentHostContextId:execution.configuration.hostContextId,
|
|
109
|
-
reopenParent:()=>openControlRun(definition,'resume',execution),allowStart,
|
|
109
|
+
reopenParent:()=>openControlRun(definition,'resume',execution),allowStart,controlPolicy,
|
|
110
110
|
...(template?{template:{specsRoot:specsDir,feature,identity,configuration:templateConfiguration}}:{fix}),
|
|
111
111
|
fixPermissions:[...permissions,...(allowAbandon?['--allow-abandon']:[]),...extraPermissions],
|
|
112
112
|
fixAuthorities:{authority:rh.authority,finalAuthority:rh.finalAuthority},
|
|
@@ -192,6 +192,21 @@ for(const operation of ['fix_status','fix_advance'])test(`live cause reviewer is
|
|
|
192
192
|
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
+
test('v2 child recovery refuses a stale child snapshot with unchanged parent and preserves child records',async t=>{
|
|
196
|
+
const f=await fixture(t),policy={version:2,development:'conversation',bootstrap:'disabled',qa:'run',qaFix:'manual'};
|
|
197
|
+
let owner=await f.open(A,{controlPolicy:policy,allowAbandon:true});
|
|
198
|
+
await owner.handle(f.bound('fix_advance'));
|
|
199
|
+
const preview=(await owner.handle(f.bound('fix_status'))).childControlTarget;
|
|
200
|
+
assert.equal(preview.runId,f.fix.identity.runId);assert.equal(preview.revision,JSON.parse(fs.readFileSync(f.statePath)).revision);
|
|
201
|
+
// Advance the real child only; the completed parent identity/package stay unchanged.
|
|
202
|
+
await owner.handle({...f.bound('fix_action'),fixOperation:'cause_review'});
|
|
203
|
+
const bytes=fs.readFileSync(f.statePath);
|
|
204
|
+
await assert.rejects(owner.handle({...f.bound('fix_action'),fixOperation:'abandon_step',reason:'Synthetic stale recovery',expectedFixControl:preview}),
|
|
205
|
+
{code:'snapshot_changed'});
|
|
206
|
+
assert.deepEqual(fs.readFileSync(f.statePath),bytes);
|
|
207
|
+
assert.equal((await owner.handle(f.request('status'))).state,'fixture_completed');
|
|
208
|
+
});
|
|
209
|
+
|
|
195
210
|
test('owner requires a valid live host id',async t=>{
|
|
196
211
|
const f=await fixture(t);
|
|
197
212
|
for(const hostContextId of [undefined,'invalid host'])assert.throws(()=>createQaFixOwnerHost({hostContextId,parentHostContextId:A,
|