@aibyzero/cm-workflow 0.16.8 → 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 +31 -0
- package/README.md +22 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-notify.md +3 -0
- 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 +119 -78
- package/docs/next-steps.md +19 -2
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +105 -5
- package/package.json +2 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +49 -13
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +103 -68
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +79 -27
- package/runtime/js/cm-ai/code-projects.mjs +4 -1
- package/runtime/js/cm-ai/control-policy.mjs +111 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +7 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +9 -0
- package/runtime/js/cm-ai/durable-runner-state.mjs +883 -69
- package/runtime/js/cm-ai/effect-abandon-log.mjs +5 -2
- package/runtime/js/cm-ai/effect-contract.mjs +6 -1
- package/runtime/js/cm-ai/external-run-guard.mjs +18 -7
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +4 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +33 -24
- package/runtime/js/cm-ai/host-documentation.mjs +53 -12
- package/runtime/js/cm-ai/host-project-execution.mjs +2 -2
- package/runtime/js/cm-ai/host-qa-executor.mjs +49 -4
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +53 -9
- 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 +1 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +43 -3
- 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 +89 -3
- package/runtime/js/cm-ai/provider-review-observation.mjs +50 -0
- package/runtime/js/cm-ai/qa-resource-release.mjs +46 -0
- package/runtime/js/cm-ai/qa-round-budget.mjs +13 -0
- package/runtime/js/cm-ai/review-package.mjs +26 -5
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +1 -1
- package/runtime/js/cm-ai/task-commit.mjs +39 -0
- package/runtime/js/cm-ai/task-runner.mjs +629 -121
- package/runtime/js/cm-ai/worker-claude-developer.mjs +9 -0
- package/runtime/js/cm-ai/worker-claude.mjs +10 -3
- package/runtime/js/cm-ai/worker-process-identity.mjs +43 -0
- package/runtime/js/cm-fix/execution.mjs +176 -48
- package/runtime/js/cm-fix/host.mjs +2 -1
- package/runtime/js/cm-fix/pinned-baseline.mjs +24 -0
- package/runtime/js/cm-fix/progress.mjs +13 -3
- package/runtime/js/cm-fix/protected-edits.mjs +10 -3
- package/runtime/js/cm-fix/repair.mjs +11 -3
- package/runtime/js/cm-fix/test-author.mjs +10 -3
- package/runtime/js/cm-idea/session.mjs +67 -4
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-correction.mjs +10 -4
- 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/session.mjs +43 -0
- package/runtime/js/cm-refactor/records.mjs +98 -8
- package/runtime/js/cm-refactor/workflow.mjs +80 -10
- package/runtime/js/cm-test/host.mjs +10 -3
- package/runtime/js/cm-test/session.mjs +45 -6
- package/runtime/js/notify-safe-read.mjs +49 -0
- package/runtime/js/notify-send.mjs +313 -0
- package/runtime/js/notify.mjs +164 -37
- package/runtime/js/policy-binding-compat.mjs +55 -0
- package/runtime/review.md +52 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/ci-test-shards.mjs +67 -0
- package/scripts/ci-test-shards.test.mjs +64 -0
- package/scripts/ci-test-weights.json +222 -0
- package/scripts/cm-ai-abandon-effect-position.test.mjs +71 -10
- package/scripts/cm-ai-answer-gap-dispatch.test.mjs +86 -0
- package/scripts/cm-ai-answer-gap-driver.test.mjs +51 -0
- package/scripts/cm-ai-answer-gap-fixture.mjs +89 -0
- package/scripts/cm-ai-answer-gap-recheck.test.mjs +70 -0
- package/scripts/cm-ai-answer-gap-redo.test.mjs +103 -0
- package/scripts/cm-ai-batch-drive.mjs +98 -34
- package/scripts/cm-ai-batch-drive.test.mjs +124 -16
- package/scripts/cm-ai-batch-host.mjs +167 -29
- package/scripts/cm-ai-batch-host.test.mjs +303 -31
- package/scripts/cm-ai-batch-run-fixture.mjs +452 -0
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +26 -0
- package/scripts/cm-ai-batch-run-parallel.test.mjs +7 -0
- package/scripts/cm-ai-batch-run-reschedule.test.mjs +17 -0
- package/scripts/cm-ai-batch-run.mjs +213 -25
- package/scripts/cm-ai-batch-run.test.mjs +21 -341
- 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 +97 -0
- package/scripts/cm-ai-develop-call-timeout.test.mjs +146 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +37 -23
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +424 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +54 -25
- package/scripts/cm-ai-drive.mjs +142 -58
- package/scripts/cm-ai-drive.test.mjs +70 -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 +267 -0
- package/scripts/cm-ai-host-fixture.mjs +296 -0
- package/scripts/cm-ai-host-protected.test.mjs +253 -0
- package/scripts/cm-ai-host.mjs +122 -100
- package/scripts/cm-ai-host.test.mjs +35 -776
- 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 +54 -0
- 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 +30 -5
- 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 +8 -5
- package/scripts/cm-ai-qa-answer-gaps.test.mjs +99 -0
- 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 +95 -13
- 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 +59 -14
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +137 -32
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +132 -67
- package/scripts/cm-ai-run.mjs +91 -28
- 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 +489 -51
- 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 +8 -0
- package/scripts/cm-check-drive.test.mjs +2 -5
- package/scripts/cm-check-runtime.sh +4 -2
- package/scripts/cm-claude-developer-worker.test.mjs +15 -0
- package/scripts/cm-claude-review-stream.test.mjs +21 -16
- package/scripts/cm-claude-review-synthetic.test.mjs +155 -0
- package/scripts/cm-claude-worker.test.mjs +23 -5
- 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 +32 -12
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-abandon.test.mjs +163 -10
- package/scripts/cm-fix-drive-unprotected.test.mjs +37 -0
- package/scripts/cm-fix-drive.mjs +25 -7
- package/scripts/cm-fix-host.mjs +8 -7
- package/scripts/cm-fix-review-budget.test.mjs +13 -0
- package/scripts/cm-fix-review-recovery.test.mjs +36 -1
- package/scripts/cm-host-answer-timeout.test.mjs +65 -0
- package/scripts/cm-host-call-kinds.test.mjs +28 -0
- package/scripts/cm-host-documentation.test.mjs +49 -0
- package/scripts/cm-host-qa-executor.test.mjs +23 -12
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-idea-answer-gaps.test.mjs +164 -0
- package/scripts/cm-idea-drive.mjs +49 -11
- package/scripts/cm-idea-drive.test.mjs +66 -0
- package/scripts/cm-idea-host.mjs +106 -16
- package/scripts/cm-init-answer-gaps.test.mjs +258 -0
- package/scripts/cm-init-drive.mjs +41 -7
- package/scripts/cm-init-host.mjs +61 -12
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-log-event.mjs +21 -10
- package/scripts/cm-notify-command.test.mjs +936 -0
- package/scripts/cm-notify-read-drift.test.mjs +270 -0
- package/scripts/cm-notify.mjs +481 -0
- package/scripts/cm-notify.test.mjs +312 -23
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-answer-gaps.test.mjs +216 -0
- package/scripts/cm-prd-drive.mjs +18 -5
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +37 -4
- package/scripts/cm-prd-review-disposition.test.mjs +6 -1
- package/scripts/cm-prd-review-gate.mjs +56 -0
- package/scripts/cm-refactor-answer-gaps.test.mjs +206 -0
- package/scripts/cm-refactor-drive.mjs +52 -8
- package/scripts/cm-refactor-drive.test.mjs +44 -0
- package/scripts/cm-refactor-host.test.mjs +10 -6
- package/scripts/cm-release-smoke.sh +2 -0
- 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-answer-gaps.test.mjs +151 -0
- package/scripts/cm-test-drive.mjs +21 -5
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/claude-review-process.mjs +1 -1
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +103 -0
- package/scripts/scan-public-safety.py +4 -0
- package/scripts/validate-public-repo.py +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 +85 -11
- package/skills/cm-ai/references/js-host-recovery.md +181 -21
- package/skills/cm-ai/references/js-host.md +76 -32
- package/skills/cm-check/SKILL.md +3 -3
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-fix/references/js-host.md +44 -5
- package/skills/cm-idea/references/js-host.md +27 -2
- package/skills/cm-init/references/js-host.md +17 -4
- package/skills/cm-notify/SKILL.md +34 -0
- package/skills/cm-prd/references/js-change-recovery.md +35 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/skills/cm-refactor/references/js-host.md +17 -0
- package/skills/cm-test/references/js-host.md +14 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {spawnSync} from 'node:child_process';
|
|
6
|
+
import {readRunDefinition,openControlRun} from './cm-ai-run.mjs';
|
|
7
|
+
import {checkN4} from './cm-task-gate.mjs';
|
|
8
|
+
import {cli,identity,request,fixture,runCli,installDispatchFakes,protectedResultFixture,implementedValue,lastCheckpoint,installTimeoutReviewer,syntheticReviewConfig} from './cm-ai-host-fixture.mjs';
|
|
9
|
+
|
|
10
|
+
for(const [available,coder,reviewer,runtime] of [
|
|
11
|
+
['codex','codex','codex','codex'],['codex','codex','codex','claude'],['claude','claude','claude','codex'],
|
|
12
|
+
['both','codex','claude','claude'],['both','claude','codex','codex'],
|
|
13
|
+
])test(`protected dispatch ${available}: ${runtime} host -> ${coder} coder -> ${reviewer} reviewer`,async()=>{
|
|
14
|
+
const f=fixture();f.operation='start';
|
|
15
|
+
try{
|
|
16
|
+
installDispatchFakes(f);
|
|
17
|
+
fs.writeFileSync(path.join(f.codeProject,'.cm-workflow.json'),JSON.stringify({version:1,runtimes:{available},
|
|
18
|
+
roles:{coder:{adapter:`${coder}-cli`},reviewer:{adapter:`${reviewer}-cli`}}}));
|
|
19
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime',reviewer],
|
|
20
|
+
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
21
|
+
const reviewFile=path.join(f.root,'review.json'),protectedFile=path.join(f.root,'protected.json');
|
|
22
|
+
fs.writeFileSync(reviewFile,preview.stdout);
|
|
23
|
+
fs.writeFileSync(protectedFile,JSON.stringify({model:'fixture',timeoutMs:5000,
|
|
24
|
+
checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
|
|
25
|
+
f.args.push('--runtime',runtime,'--review-config',reviewFile,'--protected-config',protectedFile);
|
|
26
|
+
const denied=await runCli(f,'normal');assert.equal(denied.code,1);assert.match(denied.stderr,/provider_development_authorization_required/);
|
|
27
|
+
assert(!fs.existsSync(path.join(f.codeProject,'target.mjs')));assert(!fs.existsSync(path.join(f.specsDir,'.reviews')));
|
|
28
|
+
f.args.push('--allow-provider-development-attempt','1');
|
|
29
|
+
const first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
30
|
+
assert.equal(first.rows.find(row=>row.requestId==='advance').result.code,null);assert.deepEqual(first.calls,[]);
|
|
31
|
+
assert.equal(fs.readFileSync(path.join(f.codeProject,'target.mjs'),'utf8'),'export const value = 42;\n');
|
|
32
|
+
const readRoutes=()=>fs.readFileSync(path.join(f.specsDir,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
|
|
33
|
+
.filter(row=>row.phase==='route'&&row.event==='decision');
|
|
34
|
+
assert.equal(readRoutes().filter(row=>row.role==='coder'&&row.route_state===(coder===runtime?'current-runtime':'cli-dispatch')).length,1);
|
|
35
|
+
assert.equal(readRoutes().filter(row=>row.role==='reviewer').length,0);
|
|
36
|
+
f.operation='advance';
|
|
37
|
+
const reviewed=await runCli(f,'normal','resume');assert.equal(reviewed.code,0,reviewed.stderr);
|
|
38
|
+
assert.equal(reviewed.rows.find(row=>row.requestId==='advance').result.state,'fixture_completed',JSON.stringify(reviewed.rows));
|
|
39
|
+
const route=readRoutes().find(row=>row.role==='reviewer');assert(route);
|
|
40
|
+
assert.equal(route.adapter,`${reviewer}-cli`);assert.equal(route.route_state,reviewer===runtime?'current-runtime':'cli-dispatch');
|
|
41
|
+
const receipt=fs.readFileSync(path.join(f.specsDir,'.reviews','work-T-001-r1.md'),'utf8');
|
|
42
|
+
assert.match(receipt,new RegExp(`reviewer: ${reviewer}-cli`));assert.match(receipt,/independent: true/);
|
|
43
|
+
const gate=checkN4({handoff:path.join(f.specsDir,'.reviews','work-T-001-a1-handoff.json'),
|
|
44
|
+
reviewsDir:path.join(f.specsDir,'.reviews'),feature:'work',task:'T-001',projectRoot:f.codeProject});
|
|
45
|
+
assert.equal(gate.content_bound,true);
|
|
46
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
for(const available of ['unknown','codex'])test(`legacy protected ${available} run refuses the retired CLI assembly without changing its recorded contexts`,async()=>{
|
|
50
|
+
const f=fixture();f.operation='start';
|
|
51
|
+
try{
|
|
52
|
+
installDispatchFakes(f);
|
|
53
|
+
const projectConfig=path.join(f.codeProject,'.cm-workflow.json');
|
|
54
|
+
const declaration={version:1,...(available==='codex'?{runtimes:{available}}:{})};
|
|
55
|
+
fs.writeFileSync(projectConfig,JSON.stringify(declaration));
|
|
56
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture'],
|
|
57
|
+
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
58
|
+
const reviewFile=path.join(f.root,'review.json'),protectedFile=path.join(f.root,'protected.json');
|
|
59
|
+
fs.writeFileSync(reviewFile,preview.stdout);
|
|
60
|
+
fs.writeFileSync(protectedFile,JSON.stringify({model:'fixture',timeoutMs:5000,
|
|
61
|
+
checkCommands:[{id:'syntax',command:[process.execPath,'--check','target.mjs']}]}));
|
|
62
|
+
// The original unmodified createCodexExecution constructs a genuine old run;
|
|
63
|
+
// no hand-written fingerprints, journals or approval receipts.
|
|
64
|
+
const initializer=path.join(f.root,'old-host.mjs');
|
|
65
|
+
fs.writeFileSync(initializer,`
|
|
66
|
+
import fs from 'node:fs';
|
|
67
|
+
import {readRunDefinition,createCodexExecution,openControlRun} from ${JSON.stringify(new URL('./cm-ai-run.mjs',import.meta.url).href)};
|
|
68
|
+
const definition=readRunDefinition(${JSON.stringify(f.config)}),review=JSON.parse(fs.readFileSync(${JSON.stringify(reviewFile)}));
|
|
69
|
+
const config=JSON.parse(fs.readFileSync(${JSON.stringify(protectedFile)}));
|
|
70
|
+
|
|
71
|
+
const execution=await createCodexExecution({codeProject:definition.codeProject,specsRoot:definition.specsDir,
|
|
72
|
+
developerModel:config.model,checkCommands:config.checkCommands,timeoutMs:config.timeoutMs,
|
|
73
|
+
hostContextId:'native-host-fixture',developerContextId:'cm-protected-author',reviewerModel:review.model,
|
|
74
|
+
reviewerPreflight:review.preflight,disabledSkills:review.disabledSkills},
|
|
75
|
+
{developmentAttempt:1,
|
|
76
|
+
authorizeDevelopment:()=>({status:'approved'})});
|
|
77
|
+
const run=await openControlRun(definition,'create',execution);
|
|
78
|
+
try{console.log(JSON.stringify(await run.host.handle(${JSON.stringify(request('start'))})));}finally{run.close();}
|
|
79
|
+
`);
|
|
80
|
+
const old=spawnSync(process.execPath,[initializer],{encoding:'utf8',env:f.env,timeout:10000});
|
|
81
|
+
assert.equal(old.status,0,old.stderr);assert.equal(JSON.parse(old.stdout).code,null);
|
|
82
|
+
f.args.push('--protected-config',protectedFile,'--allow-provider-development-attempt','1','--review-config',reviewFile);
|
|
83
|
+
// A changed two-provider declaration cannot recover through Codex-only compatibility.
|
|
84
|
+
fs.writeFileSync(projectConfig,JSON.stringify({version:1,runtimes:{available:'both'},
|
|
85
|
+
roles:{coder:{adapter:'claude-cli'},reviewer:{adapter:'codex-cli'}}}));
|
|
86
|
+
const mismatch=await runCli(f,'normal','resume');assert.equal(mismatch.code,1);assert.match(mismatch.stderr,/fingerprint_mismatch/);
|
|
87
|
+
assert(!fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[x]'));
|
|
88
|
+
fs.writeFileSync(projectConfig,JSON.stringify(declaration));
|
|
89
|
+
// Runtime routing now determines the reviewer before the exact old assembly
|
|
90
|
+
// fingerprint is checked; the diagnostic preflight must match that route.
|
|
91
|
+
fs.writeFileSync(reviewFile,JSON.stringify(syntheticReviewConfig(f.codeProject,available==='unknown'?'claude':'codex')));
|
|
92
|
+
const stateFile=path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json');
|
|
93
|
+
const before=fs.readFileSync(stateFile);
|
|
94
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,1,resumed.stderr);
|
|
95
|
+
assert.match(resumed.stderr,/fingerprint_mismatch/);
|
|
96
|
+
assert.match(resumed.stderr,/旧 createCodexExecution.*停用/);
|
|
97
|
+
assert.match(resumed.stderr,/inspect-history --config/);
|
|
98
|
+
assert.deepEqual(resumed.calls,[]);assert.equal(resumed.rows.some(row=>row.type==='host_ready'),false);
|
|
99
|
+
assert.deepEqual(fs.readFileSync(stateFile),before);
|
|
100
|
+
assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[ ] T-001'));
|
|
101
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
test('protected local invalid_result writes nothing and corrected CLI resume keeps run and attempt',async()=>{
|
|
106
|
+
const f=protectedResultFixture();f.operation='start';const target=path.join(f.codeProject,'target.mjs');
|
|
107
|
+
try{
|
|
108
|
+
f.develop=payload=>{
|
|
109
|
+
assert.equal(payload.editMode,'protected-text-v1');assert.equal(payload.expected['target.mjs'],null);
|
|
110
|
+
return {status:'succeeded',value:{...implementedValue(),
|
|
111
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:'No new lesson'}},
|
|
112
|
+
edits:[{path:'target.mjs',beforeSha256:null,content:'export const value = 42;\n'}]};
|
|
113
|
+
};
|
|
114
|
+
for(const mode of ['create',...Array(6).fill('resume')]){
|
|
115
|
+
const rejected=await runCli(f,'normal',mode);assert.equal(rejected.code,0,rejected.stderr);
|
|
116
|
+
const result=rejected.rows.find(row=>row.requestId==='advance').result;
|
|
117
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'developer_result_invalid');
|
|
118
|
+
assert.equal(result.pendingAction,'resume');assert.deepEqual(result.identity,identity);
|
|
119
|
+
assert(!fs.existsSync(target));
|
|
120
|
+
const checkpoint=lastCheckpoint(f);assert.equal(checkpoint.calls.at(-1).terminal,'failed');
|
|
121
|
+
assert.deepEqual(checkpoint.calls.at(-1).failureResult,{code:'invalid_result',reason:'invalid_input',retryable:true});
|
|
122
|
+
}
|
|
123
|
+
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
124
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
125
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
126
|
+
const result=resumed.rows.find(row=>row.requestId==='advance').result;
|
|
127
|
+
assert.equal(result.state,'awaiting_review');assert.equal(result.code,null);
|
|
128
|
+
assert.deepEqual(result.identity,identity);assert.equal(fs.readFileSync(target,'utf8'),'export const value = 42;\n');
|
|
129
|
+
assert.deepEqual(lastCheckpoint(f).calls.map(call=>call.terminal),[...Array(7).fill('failed'),'succeeded']);
|
|
130
|
+
const reopened=await runCli(f,'normal','resume');assert.equal(reopened.code,0,reopened.stderr);
|
|
131
|
+
assert.deepEqual(reopened.calls,[]);assert.equal(reopened.rows.find(row=>row.requestId==='advance').result.code,null);
|
|
132
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
for(const matches of [true,false])test(`protected old proposal compares exact output with expected disk hashes: matches=${matches}`,async()=>{
|
|
136
|
+
const f=protectedResultFixture();f.operation='start';const target=path.join(f.codeProject,'target.mjs');
|
|
137
|
+
try{
|
|
138
|
+
// Simulate a proposal already applied before this invocation was rejected.
|
|
139
|
+
const content='export const value = 42;\n';
|
|
140
|
+
f.develop=()=>({status:'succeeded',value:{...implementedValue(),
|
|
141
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:'invalid'}},edits:[]});
|
|
142
|
+
const failed=await runCli(f,'normal');assert.equal(failed.code,0,failed.stderr);
|
|
143
|
+
assert.equal(failed.rows.find(row=>row.requestId==='advance').result.code,'developer_result_invalid');
|
|
144
|
+
fs.writeFileSync(target,matches?content:'export const value = 99;\n');
|
|
145
|
+
const before=fs.readFileSync(target);
|
|
146
|
+
f.develop=()=>({status:'succeeded',value:implementedValue(),
|
|
147
|
+
edits:[{path:'target.mjs',beforeSha256:null,content}]});
|
|
148
|
+
const run=await runCli(f,'normal','resume');assert.equal(run.code,0,run.stderr);
|
|
149
|
+
const result=run.rows.find(row=>row.requestId==='advance').result;
|
|
150
|
+
assert.equal(result.state,matches?'awaiting_review':'blocked');
|
|
151
|
+
assert.equal(result.code,matches?null:'protected_edit_stale');
|
|
152
|
+
assert.deepEqual(fs.readFileSync(target),before);
|
|
153
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
154
|
+
assert.deepEqual(resumed.calls,[]);
|
|
155
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='advance').result.code,result.code);
|
|
156
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
for(const mode of ['blocked','disconnect'])test(`protected ${mode} cannot use the local invalid-result retry entry`,async()=>{
|
|
160
|
+
const f=protectedResultFixture();
|
|
161
|
+
try{
|
|
162
|
+
f.develop=()=>({status:'succeeded',value:{...implementedValue(),outcome:'blocked'},edits:[]});
|
|
163
|
+
const result=await runCli(f,mode==='disconnect'?'disconnect':'normal');assert.equal(result.code,0,result.stderr);
|
|
164
|
+
const status=result.rows.find(row=>row.requestId==='advance').result;
|
|
165
|
+
assert.equal(status.state,mode==='blocked'?'blocked':'unknown');
|
|
166
|
+
assert.equal(status.code,mode==='blocked'?'failed':'unknown');
|
|
167
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
168
|
+
assert.deepEqual(resumed.calls,[]);
|
|
169
|
+
assert.equal(resumed.rows.find(row=>row.requestId==='advance').result.state,status.state);
|
|
170
|
+
assert(!fs.existsSync(path.join(f.codeProject,'target.mjs')));
|
|
171
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
for(const variant of ['delete-absent','missing-edits','extra-field'])test(`protected malformed proposal ${variant} fails before sandbox writes`,async()=>{
|
|
175
|
+
const f=protectedResultFixture();
|
|
176
|
+
try{
|
|
177
|
+
f.develop=()=>({status:'succeeded',value:implementedValue(),
|
|
178
|
+
...(variant==='missing-edits'?{}:{edits:[{path:'target.mjs',beforeSha256:null,
|
|
179
|
+
content:variant==='delete-absent'?null:'export const value = 42;\n'}]}),
|
|
180
|
+
...(variant==='extra-field'?{extra:true}:{})});
|
|
181
|
+
const result=await runCli(f,'normal');assert.equal(result.code,0,result.stderr);
|
|
182
|
+
const status=result.rows.find(row=>row.requestId==='advance').result;
|
|
183
|
+
assert.equal(status.state,'blocked');assert.equal(status.code,'developer_result_invalid');
|
|
184
|
+
assert.equal(lastCheckpoint(f).calls.at(-1).terminal,'failed');
|
|
185
|
+
assert(!fs.existsSync(path.join(f.codeProject,'target.mjs')));
|
|
186
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
for(const [runtime,second] of [['codex','approved'],['claude','approved'],['codex','timeout'],['codex','result'],['claude','result']])
|
|
191
|
+
test(`protected conversation review timeout ${runtime} -> ${second}`,async()=>{
|
|
192
|
+
const f=protectedResultFixture();
|
|
193
|
+
try{
|
|
194
|
+
f.runtime=runtime;f.args.push('--runtime',runtime);
|
|
195
|
+
const setMode=installTimeoutReviewer(f,runtime);
|
|
196
|
+
const preview=spawnSync(process.execPath,[cli,'preflight','--config',f.config,'--review-model','fixture','--runtime',runtime],
|
|
197
|
+
{encoding:'utf8',env:f.env,timeout:5000});assert.equal(preview.status,0,preview.stderr);
|
|
198
|
+
const review=JSON.parse(preview.stdout);assert.equal(review.timeoutMs,900000);
|
|
199
|
+
delete review.timeoutMs;
|
|
200
|
+
const config=path.join(f.root,'review.json');fs.writeFileSync(config,JSON.stringify(review));
|
|
201
|
+
f.args.push('--review-config',config);f.operation='advance';
|
|
202
|
+
f.develop=payload=>({status:'succeeded',value:implementedValue(),
|
|
203
|
+
edits:[{path:'target.mjs',beforeSha256:payload.expected['target.mjs'],content:'export const value = 42;\n'}]});
|
|
204
|
+
setMode(second==='result'?'result':'timeout');
|
|
205
|
+
const start=Date.now(),first=await runCli(f,'normal');assert.equal(first.code,0,first.stderr);
|
|
206
|
+
const result=first.rows.find(row=>row.requestId==='advance').result;
|
|
207
|
+
// A legacy review config without timeoutMs inherits the protected conversation's 5s reviewer budget.
|
|
208
|
+
assert(Date.now()-start>=4900);assert(Date.now()-start<14000);
|
|
209
|
+
assert.equal(result.state,second==='result'?'unknown':'pending_review');
|
|
210
|
+
assert.equal(result.code,second==='result'?'transport_timeout':'review_transport_timeout');
|
|
211
|
+
// A final message cut off by the timeout is never retried by itself; its
|
|
212
|
+
// only exit is the explicit, audited abandon_review (see cm-ai-review-failure).
|
|
213
|
+
assert.equal(result.pendingAction,second==='result'?'abandon_review':'resume');
|
|
214
|
+
const before=lastCheckpoint(f),original=before.reviewInvocation;
|
|
215
|
+
assert.equal(before.calls.at(-1).terminal,second==='result'?'unknown':'failed');
|
|
216
|
+
assert.equal(original.result.outcome,'timed_out');
|
|
217
|
+
assert.equal(original.result.reconciliationRequired,second==='result');
|
|
218
|
+
assert.equal(original.result.inspection.code,'transport_timeout');
|
|
219
|
+
assert.equal(original.result.observation.events.at(-1).event,'process_closed');
|
|
220
|
+
assert.equal(original.result.observation.events.at(-1).timed_out,true);
|
|
221
|
+
const snapshot=()=>JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution',identity.runId,'state.json')));
|
|
222
|
+
const {readRunnerHistory}=await import('../runtime/js/cm-ai/durable-runner-state.mjs');
|
|
223
|
+
const history=snapshot(),configuration=history.records[0].payload.config;
|
|
224
|
+
assert.equal(readRunnerHistory(history.records,configuration,3).state.state,result.state);
|
|
225
|
+
// Prefix recovery never redispatches an invocation whose checkpoint is absent.
|
|
226
|
+
for(const type of ['review-invocation-registered','review-invocation-started','review-invocation-result']){
|
|
227
|
+
const index=history.records.findIndex(row=>row.payload.type===type);
|
|
228
|
+
const recovered=readRunnerHistory(history.records.slice(0,index+1),configuration,3);
|
|
229
|
+
assert.equal(recovered.state.state,'unknown');assert.equal(recovered.state.code,'reconciliation_required');
|
|
230
|
+
}
|
|
231
|
+
setMode(second==='result'?'approved':second);
|
|
232
|
+
const resumed=await runCli(f,'normal','resume');assert.equal(resumed.code,0,resumed.stderr);
|
|
233
|
+
const end=resumed.rows.find(row=>row.requestId==='advance').result,after=lastCheckpoint(f);
|
|
234
|
+
assert.deepEqual(end.identity,identity);assert.deepEqual(resumed.calls,[]);
|
|
235
|
+
if(second==='result'){
|
|
236
|
+
assert.equal(end.state,'unknown');assert.deepEqual(after,before);
|
|
237
|
+
}else{
|
|
238
|
+
assert.equal(end.state,second==='approved'?'fixture_completed':'blocked');
|
|
239
|
+
assert.equal(end.code,second==='approved'?'qa_decision_required':'review_transport_timeout');
|
|
240
|
+
assert.equal(after.cache.find(entry=>entry.effect.id==='review-1-retry-1').effect.identity.attempt,1);
|
|
241
|
+
assert.notEqual(after.reviewInvocation.registration.binding.invocationId,original.registration.binding.invocationId);
|
|
242
|
+
assert.notEqual(after.reviewInvocation.registration.binding.requestDigest,original.registration.binding.requestDigest);
|
|
243
|
+
assert.notEqual(after.reviewInvocation.started,original.started);
|
|
244
|
+
assert.deepEqual(after.calls.slice(0,before.calls.length),before.calls);
|
|
245
|
+
assert.deepEqual(after.cache.slice(0,before.cache.length),before.cache);
|
|
246
|
+
if(second==='timeout'){
|
|
247
|
+
const blocked=await runCli(f,'normal','resume');assert.equal(blocked.code,0,blocked.stderr);
|
|
248
|
+
assert.equal(blocked.rows.find(row=>row.requestId==='advance').result.state,'blocked');
|
|
249
|
+
assert.deepEqual(lastCheckpoint(f),after);
|
|
250
|
+
}else assert(fs.readFileSync(path.join(f.specsDir,'1.work','tasks.md'),'utf8').includes('[x] T-001'));
|
|
251
|
+
}
|
|
252
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
253
|
+
});
|