@aibyzero/cm-workflow 0.16.4 → 0.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +8 -0
- package/CHANGELOG.md +50 -0
- package/README.md +12 -1
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +115 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +12 -4
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +18 -11
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +92 -20
- package/scripts/cm-ai-batch-drive.test.mjs +164 -3
- package/scripts/cm-ai-batch-host.mjs +27 -11
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +479 -47
- package/scripts/cm-ai-drive.test.mjs +240 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +84 -25
- package/scripts/cm-ai-host.test.mjs +232 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +25 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +9 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +12 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +261 -42
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -87,7 +87,8 @@ test('the batch driver decides retryability from the shared predicate', async ()
|
|
|
87
87
|
const {default:fs}=await import('node:fs');
|
|
88
88
|
const {developmentRetryable}=await import('../runtime/js/cm-ai/cm-ai-conversation-entry.mjs');
|
|
89
89
|
const source=fs.readFileSync(new URL('./cm-ai-batch-run.mjs',import.meta.url),'utf8');
|
|
90
|
-
assert.match(source,/import \{
|
|
90
|
+
assert.match(source,/import \{[^}]*\bdevelopmentRetryable\b[^}]*\} from '\.\.\/runtime\/js\/cm-ai\/cm-ai-conversation-entry\.mjs'/);
|
|
91
|
+
assert.match(source,/import \{[^}]*\bcompletionRetryable\b[^}]*\} from '\.\.\/runtime\/js\/cm-ai\/cm-ai-conversation-entry\.mjs'/);
|
|
91
92
|
assert.match(source,/\|\|developmentRetryable\(status\)\)await call\('start'\)/);
|
|
92
93
|
assert.equal(/status\.code==='developer_result_invalid'/.test(source),false,
|
|
93
94
|
'batch driver still carries its own copy of the retryable code list');
|
|
@@ -41,15 +41,22 @@ function fixture(browserCase,{blocking=true,tests=['logic','commands','browser']
|
|
|
41
41
|
fs.writeFileSync(workflow,JSON.stringify({documentationPaths:[],applicableAgentFiles:[],
|
|
42
42
|
qa:{commands:[{id:'unit',command:[process.execPath,'--version'],caseIds:browserCase?[]:['TC-001']}],
|
|
43
43
|
environment:{kind:'web',carrier:'browser',target:'https://example.invalid/fixture',scope:'local'}}}));
|
|
44
|
+
// create requires a bound review configuration; this one grants no review attempt.
|
|
45
|
+
const review=path.join(root,'placeholder-review.json');fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{}}));
|
|
44
46
|
return {root,specsDir,codeProject,config,workflow,
|
|
45
47
|
args:['serve','--config',config,'--mode','create','--host-context','gate-fixture','--allow-development',
|
|
46
|
-
'--workflow-config',workflow,'--allow-qa']};
|
|
48
|
+
'--workflow-config',workflow,'--allow-qa','--review-config',review]};
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
const launch=(f,...extra)=>spawnSync(process.execPath,[cli,...f.args,...extra],{encoding:'utf8',timeout:20000,env:{...process.env,NODE_NO_WARNINGS:'1'}});
|
|
50
52
|
function rejected(result,code){
|
|
51
53
|
assert.equal(result.error,undefined);assert.equal(result.status,1,result.stderr);
|
|
52
|
-
|
|
54
|
+
const parsed=JSON.parse(result.stderr);
|
|
55
|
+
assert.equal(parsed.error.code,code);
|
|
56
|
+
if(['browser_capability_required','browser_capability_unavailable'].includes(code))
|
|
57
|
+
assert.match(parsed.error.reason,/--browser-qa available\|unavailable.*interactive QA/);
|
|
58
|
+
else if(code==='invalid_arguments')assert.match(parsed.error.reason,/--browser-qa/);
|
|
59
|
+
else assert.deepEqual(parsed,{error:{code}});
|
|
53
60
|
}
|
|
54
61
|
function started(f,...extra){
|
|
55
62
|
const result=launch(f,...extra);
|
|
@@ -76,6 +83,18 @@ test('the browser gate fires exactly when the approved contract can select a bro
|
|
|
76
83
|
}finally{fs.rmSync(withoutBrowser.root,{recursive:true,force:true});}
|
|
77
84
|
});
|
|
78
85
|
|
|
86
|
+
test('iOS simulator carrier is named in the launch diagnostic',()=>{
|
|
87
|
+
const f=fixture(true);
|
|
88
|
+
try{
|
|
89
|
+
const workflow=JSON.parse(fs.readFileSync(f.workflow,'utf8'));
|
|
90
|
+
workflow.qa.environment={kind:'app',carrier:'ios-simulator',target:'fixture-app',scope:'local'};
|
|
91
|
+
fs.writeFileSync(f.workflow,JSON.stringify(workflow));
|
|
92
|
+
const result=launch(f);
|
|
93
|
+
rejected(result,'browser_capability_required');
|
|
94
|
+
assert.match(JSON.parse(result.stderr).error.reason,/ios-simulator/);
|
|
95
|
+
}finally{fs.rmSync(f.root,{recursive:true,force:true});}
|
|
96
|
+
});
|
|
97
|
+
|
|
79
98
|
test('resume requires a fresh assertion and reopens the run created by available',()=>{
|
|
80
99
|
const f=fixture(true);
|
|
81
100
|
try{
|
|
@@ -12,7 +12,7 @@ function fixture(t,exit=0){
|
|
|
12
12
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
13
13
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-check-drive.mjs',
|
|
14
14
|
'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs',
|
|
15
|
-
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
15
|
+
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
16
16
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
17
17
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
18
18
|
}
|
|
@@ -19,7 +19,7 @@ function fixture(t,exitCode=0){
|
|
|
19
19
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-check-host-'))),project=path.join(dir,'project');fs.mkdirSync(project);
|
|
20
20
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
21
21
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs',
|
|
22
|
-
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
22
|
+
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
23
23
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
24
24
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
25
25
|
}
|
|
@@ -282,7 +282,7 @@ for module in \
|
|
|
282
282
|
cm-ai-learning-handoff-writer.mjs cm-ai-learning-writer.mjs cm-ai-qa-log.mjs \
|
|
283
283
|
cm-ai-run-finalizer.mjs codex-config.mjs codex-review-adapter.mjs contracts.mjs \
|
|
284
284
|
durable-runner-state.mjs effect-contract.mjs execution-store.mjs gate-bridge.mjs \
|
|
285
|
-
host.mjs host-session.mjs index.mjs provider-review-observation.mjs review-package.mjs \
|
|
285
|
+
host.mjs host-session.mjs diagnostic-reason.mjs index.mjs provider-review-observation.mjs review-package.mjs \
|
|
286
286
|
review-result.schema.json review-runner.mjs task-commit-codec.mjs task-commit.mjs \
|
|
287
287
|
task-owner.mjs task-runner.mjs worker-codex.mjs; do
|
|
288
288
|
require_file "runtime/js/cm-ai/$module"
|
|
@@ -9,6 +9,7 @@ import {createProjectExecution} from '../runtime/js/cm-ai/host-project-execution
|
|
|
9
9
|
import {buildClaudeDeveloperPrompt} from '../runtime/js/cm-ai/claude-developer-adapter.mjs';
|
|
10
10
|
import {protectedTextInstructions} from '../runtime/js/cm-ai/host-conversation-execution.mjs';
|
|
11
11
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
12
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
12
13
|
|
|
13
14
|
const identity={repositoryId:'proposal-fixture',runId:'proposal-run',taskId:'T-001',attempt:1};
|
|
14
15
|
const proposal={status:'succeeded',value:{outcome:'implemented'},edits:[{path:'target.txt',beforeSha256:null,content:'safe text\n'}]};
|
|
@@ -25,7 +26,8 @@ function fixture(t){
|
|
|
25
26
|
function fakeWorker(cwd,{value=proposal,mode='normal',timeoutMs=3000,noticeEvents=[],noticeAt=1,onNotice,
|
|
26
27
|
resultFields={},toolName='Read',toolResultId='read-1',
|
|
27
28
|
assistantContent=[{type:'text',text:'proposal'}]}={}){
|
|
28
|
-
|
|
29
|
+
// The timeout mode hangs; the guard ends it if this test process dies first.
|
|
30
|
+
const source=`${ownerGuardSource()}let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',()=>{
|
|
29
31
|
if(!input.includes('Return {status,value,edits}'))process.exit(9);
|
|
30
32
|
if(${JSON.stringify(mode)}==='timeout'){setInterval(()=>{},1000);return;}
|
|
31
33
|
const session_id='synthetic-claude-developer';
|
|
@@ -8,6 +8,7 @@ import * as zlib from 'node:zlib';
|
|
|
8
8
|
import {spawn,spawnSync} from 'node:child_process';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
10
|
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
11
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
11
12
|
import {previewClaudeTools,claudeProbeSandbox,createClaudeModelMarkerDetector} from '../runtime/js/cm-ai/claude-tool-preview.mjs';
|
|
12
13
|
import {previewPromptTransport,writePreviewPrompt} from '../runtime/js/cm-ai/tool-preview.mjs';
|
|
13
14
|
|
|
@@ -107,7 +108,7 @@ test('probe accepts at most two compliant requests and validates every request',
|
|
|
107
108
|
for(const [name,requests,passed] of cases)await t.test(name,async()=>{
|
|
108
109
|
// Keep the fixture alive after SIGTERM so the worker's real cleanup captures
|
|
109
110
|
// the entire sequence deterministically, without delaying the probe's abort.
|
|
110
|
-
const source
|
|
111
|
+
const source=`${ownerGuardSource()}process.on('SIGTERM',()=>{});setInterval(()=>{},1000);
|
|
111
112
|
let input='';process.stdin.on('data',s=>input+=s);process.stdin.on('end',async()=>{
|
|
112
113
|
for(const request of ${JSON.stringify(requests)}){
|
|
113
114
|
const response=await fetch(process.env.ANTHROPIC_BASE_URL+'/v1/messages',{method:'POST',
|
|
@@ -191,10 +192,17 @@ test('Claude preflight CLI exits 1 with model_recognized false and leaves normal
|
|
|
191
192
|
assert.ok(run.stdout.trim(),run.stderr);
|
|
192
193
|
const receipt=JSON.parse(run.stdout);
|
|
193
194
|
assert.equal(receipt.preflight.passed,expectedExit===0);
|
|
195
|
+
assert.equal(receipt.timeoutMs,900000);
|
|
194
196
|
assert.equal(receipt.preflight.request_checks.find(check=>Object.hasOwn(check,'model_matches'))?.model_matches,true);
|
|
195
197
|
if(expectedExit===1)assert.deepEqual(receipt.preflight.request_checks.at(-1),
|
|
196
198
|
{model_recognized:false,reported_model:model});
|
|
197
199
|
else assert.equal(receipt.preflight.request_checks.some(check=>Object.hasOwn(check,'model_recognized')),false);
|
|
200
|
+
if(expectedExit===1){
|
|
201
|
+
assert.match(run.stderr,/fixture-unrecognized-model/);
|
|
202
|
+
assert.match(run.stderr,/claude-opus-5/);
|
|
203
|
+
assert.match(run.stderr,/installed Claude CLI/);
|
|
204
|
+
assert.match(run.stderr,/2\.1\.274 \(Claude Code\)/);
|
|
205
|
+
}
|
|
198
206
|
assert.equal(run.stdout.includes('CM-PROBE-001'),false);
|
|
199
207
|
}
|
|
200
208
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
@@ -321,3 +321,28 @@ test('exhausted retries do not decide success or suppress provider failure',()=>
|
|
|
321
321
|
}
|
|
322
322
|
}
|
|
323
323
|
});
|
|
324
|
+
|
|
325
|
+
// Claude CLI 2.1.274 reports an API failure as a synthetic assistant message
|
|
326
|
+
// with a string error class. Before any tool call it names a retryable class;
|
|
327
|
+
// anything else keeps the fail-closed unexpected_assistant.
|
|
328
|
+
test('API error classes before any tool call name the reviewer failure',()=>{
|
|
329
|
+
const [init]=transcript();
|
|
330
|
+
const apiError=error=>({type:'assistant',session_id:'fresh-review',parent_tool_use_id:null,error,is_api_error_message:true,
|
|
331
|
+
message:{role:'assistant',content:[{type:'text',text:'API Error'}]}});
|
|
332
|
+
for(const [error,code] of [['authentication_failed','reviewer_auth_failed'],['billing_error','reviewer_billing_error'],
|
|
333
|
+
['rate_limit','reviewer_rate_limited'],['server_error','reviewer_server_error'],['model_not_found','reviewer_model_not_found'],
|
|
334
|
+
['invalid_request','reviewer_api_error'],['__proto__','reviewer_api_error']]){
|
|
335
|
+
const events=[],stream=createClaudeReviewStream(event=>events.push(event));stream.accept(init);
|
|
336
|
+
assert.throws(()=>stream.accept(apiError(error)),{code});
|
|
337
|
+
assert.deepEqual(events.map(event=>event.event),['thread.started','turn.started']);
|
|
338
|
+
assert.throws(()=>stream.finish(),{code:'incomplete_result'});
|
|
339
|
+
}
|
|
340
|
+
for(const messages of [
|
|
341
|
+
[assistant([tool('t1','Bash')]),toolResult('t1',true),apiError('rate_limit')],
|
|
342
|
+
[{...apiError('rate_limit'),parent_tool_use_id:'child'}],
|
|
343
|
+
[apiError({type:'rate_limit'})],
|
|
344
|
+
]){
|
|
345
|
+
const stream=createClaudeReviewStream(()=>{});stream.accept(init);
|
|
346
|
+
assert.throws(()=>messages.forEach(message=>stream.accept(message)),{code:'unexpected_assistant'});
|
|
347
|
+
}
|
|
348
|
+
});
|
|
@@ -6,6 +6,7 @@ import {spawn} from 'node:child_process';
|
|
|
6
6
|
import {createHash} from 'node:crypto';
|
|
7
7
|
import {readFileSync} from 'node:fs';
|
|
8
8
|
import {claudeWorker,claudeReviewArgs,claudeReviewFingerprint,claudePreflightMatches} from '../runtime/js/cm-ai/worker-claude.mjs';
|
|
9
|
+
import {killProcessGroup,ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
9
10
|
|
|
10
11
|
const config={cwd:'/tmp',model:'claude-fixture',cli:'never-dispatch-real-cli'};
|
|
11
12
|
const receipt={passed:true,provider:'claude',prompt_transport:'stdin',config_fingerprint:claudeReviewFingerprint(config)};
|
|
@@ -164,14 +165,16 @@ test('failure, timeout, explicit cancellation and missing preflight remain disti
|
|
|
164
165
|
test('timeout kills inherited-pipe descendants, including TERM-ignoring children',
|
|
165
166
|
{skip:process.platform==='win32'},async()=>{
|
|
166
167
|
for (const descendantStdio of ['inherit','ignore']) {
|
|
167
|
-
let descendant;
|
|
168
|
+
let descendant,leader;
|
|
169
|
+
// Both guards watch this test process, never the leader, so a missed group kill still shows.
|
|
170
|
+
const hung=ownerGuardSource()+"process.on('SIGTERM',()=>{});setInterval(()=>{},1000)";
|
|
168
171
|
const worker=claudeWorker({...config,preflight:receipt,timeoutMs:300,
|
|
169
172
|
spawnProcess:(_cli,_args,options)=>{
|
|
170
173
|
const child=spawn(process.execPath,['-e',
|
|
171
|
-
|
|
172
|
-
|
|
174
|
+
`${ownerGuardSource()}const {spawn}=require('node:child_process');const c=spawn(process.execPath,['-e',
|
|
175
|
+
${JSON.stringify(hung)}],{stdio:['ignore','${descendantStdio}','${descendantStdio}']});
|
|
173
176
|
process.stderr.write(String(c.pid)+'\\n');setInterval(()=>{},1000);`],options);
|
|
174
|
-
child.stderr.on('data',chunk=>{descendant=Number(String(chunk).trim());});
|
|
177
|
+
leader=child.pid;child.stderr.on('data',chunk=>{descendant=Number(String(chunk).trim());});
|
|
175
178
|
return child;
|
|
176
179
|
}});
|
|
177
180
|
try {
|
|
@@ -180,7 +183,11 @@ test('timeout kills inherited-pipe descendants, including TERM-ignoring children
|
|
|
180
183
|
assert.equal(result.code,'timeout');assert.ok(Date.now()-started<4000);
|
|
181
184
|
assert.ok(Date.now()-started>=1200,'leader close must not cancel group escalation');
|
|
182
185
|
assert.ok(Number.isInteger(descendant));
|
|
186
|
+
const gone=()=>{try{process.kill(descendant,0);return false;}catch(error){return error.code==='ESRCH';}};
|
|
187
|
+
for(const deadline=Date.now()+3000;!gone()&&Date.now()<deadline;)await new Promise(resolve=>setTimeout(resolve,25));
|
|
188
|
+
assert.ok(gone(),'group SIGKILL must reach the TERM-ignoring descendant');
|
|
183
189
|
} finally {
|
|
190
|
+
killProcessGroup(leader);
|
|
184
191
|
if(Number.isInteger(descendant))try{process.kill(descendant,'SIGKILL');}catch{}
|
|
185
192
|
}
|
|
186
193
|
}
|
|
@@ -9,8 +9,10 @@ import {commonArgs} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
|
9
9
|
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
10
10
|
import {requestFor} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
11
|
import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
12
|
+
import {ownerGuardSource} from './fixtures/process-cleanup.mjs';
|
|
12
13
|
|
|
13
|
-
|
|
14
|
+
// The hang mode never exits on its own; the guard ends it if this test process dies first.
|
|
15
|
+
const script=`${ownerGuardSource()}let input='';process.stdin.on('data',x=>input+=x);process.stdin.on('end',()=>{
|
|
14
16
|
const emit=x=>process.stdout.write(JSON.stringify(x)+'\\n');
|
|
15
17
|
emit({type:'thread.started',thread_id:'isolated-fixture'});emit({type:'turn.started'});
|
|
16
18
|
if(process.argv[1]==='hang'){setInterval(()=>{},1000);return;}
|
|
@@ -139,7 +141,7 @@ test('cancellation kills a TERM-resistant descendant inheriting output pipes',()
|
|
|
139
141
|
const descendant=`process.on('SIGTERM',()=>{});
|
|
140
142
|
process.stdout.write(JSON.stringify({type:'item.started',item:{type:'command_execution',id:'descendant-ready'}})+'\\n');
|
|
141
143
|
setTimeout(()=>{require('node:fs').writeFileSync('leaked.txt','still running');process.exit(0);},2500);`;
|
|
142
|
-
const parent
|
|
144
|
+
const parent=`${ownerGuardSource()}process.stdin.resume();
|
|
143
145
|
process.stdout.write(JSON.stringify({type:'thread.started',thread_id:'tree'})+'\\n');
|
|
144
146
|
process.stdout.write(JSON.stringify({type:'turn.started'})+'\\n');
|
|
145
147
|
require('node:child_process').spawn(process.execPath,['-e',${JSON.stringify(descendant)}],{stdio:['ignore','inherit','inherit']});
|
package/scripts/cm-failover.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import path from 'node:path';
|
|
|
7
7
|
import childProcess from 'node:child_process';
|
|
8
8
|
// Single source of truth for role primary/standby; shared with the cm-ai host.
|
|
9
9
|
import {ROLE_ROUTING} from '../runtime/js/cm-ai/runtime-failover.mjs';
|
|
10
|
+
import {taskDeclarations,approvedTaskGrammar,TASK_GRAMMAR} from '../runtime/js/spec-task-line.mjs';
|
|
10
11
|
|
|
11
12
|
export {ROLE_ROUTING};
|
|
12
13
|
|
|
@@ -37,17 +38,16 @@ function readDirectory(dir,label){
|
|
|
37
38
|
return fs.readdirSync(dir,{withFileTypes:true});
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
//
|
|
41
|
-
|
|
41
|
+
// Task declarations use the shared tasks.md grammar (spec-task-line.mjs);
|
|
42
|
+
// anything else, including fenced examples, is prose.
|
|
43
|
+
export function parseTasks(text,grammar=TASK_GRAMMAR){
|
|
42
44
|
const tasks=[],seen=new Set();
|
|
43
|
-
for(const
|
|
44
|
-
const
|
|
45
|
-
if(!match)continue;
|
|
46
|
-
const id=match[2];
|
|
45
|
+
for(const declaration of taskDeclarations(text,{grammar})){
|
|
46
|
+
const id=declaration.id;
|
|
47
47
|
if(!TASK_RE.test(id))continue;
|
|
48
48
|
if(seen.has(id))throw new FailoverError(`tasks.md contains a duplicate task id: ${id}`);
|
|
49
49
|
seen.add(id);
|
|
50
|
-
tasks.push({id,done:
|
|
50
|
+
tasks.push({id,done:declaration.completed,title:declaration.rest.replace(/^[::\s]+/u,'').trim()});
|
|
51
51
|
}
|
|
52
52
|
if(tasks.length===0)throw new FailoverError('tasks.md declares no `- [ ] T-xxx:` task line');
|
|
53
53
|
return tasks;
|
|
@@ -136,7 +136,7 @@ export function classifyBreakpoint(task,attempts){
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
function inspectFeature(featureDir,feature){
|
|
139
|
-
const tasks=parseTasks(readTextFile(path.join(featureDir,'tasks.md'),'tasks.md'));
|
|
139
|
+
const tasks=parseTasks(readTextFile(path.join(featureDir,'tasks.md'),'tasks.md'),approvedTaskGrammar(path.dirname(featureDir)));
|
|
140
140
|
const reviewsDir=path.join(featureDir,'.reviews');
|
|
141
141
|
let entries=new Set();
|
|
142
142
|
if(fs.existsSync(reviewsDir))
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import test from 'node:test';
|
|
1
|
+
import test,{after} from 'node:test';
|
|
2
2
|
import assert from 'node:assert/strict';
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import os from 'node:os';
|
|
@@ -14,6 +14,15 @@ import {createFixReviewHost} from '../runtime/js/cm-fix/host-review.mjs';
|
|
|
14
14
|
import {configFingerprint} from '../runtime/js/cm-ai/codex-config.mjs';
|
|
15
15
|
import {fixHandoffEvidence,fixDefectHandoffEvidence} from '../runtime/js/cm-fix/handoff.mjs';
|
|
16
16
|
|
|
17
|
+
// Never write the real ~/.cm-workflow home or its global log from this suite.
|
|
18
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-fix-abandon-home-'));
|
|
19
|
+
const savedHome={CM_WORKFLOW_HOME:process.env.CM_WORKFLOW_HOME,CM_WORKFLOW_LOG_HOME:process.env.CM_WORKFLOW_LOG_HOME};
|
|
20
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'home');process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
21
|
+
after(()=>{
|
|
22
|
+
for(const [key,value] of Object.entries(savedHome)){if(value===undefined)delete process.env[key];else process.env[key]=value;}
|
|
23
|
+
fs.rmSync(isolatedHome,{recursive:true,force:true});
|
|
24
|
+
});
|
|
25
|
+
|
|
17
26
|
const diagnosis={status:'diagnosed',rootCause:'Wrong value',affectedPaths:['value.mjs'],
|
|
18
27
|
affectedModules:['value'],plan:'Correct value',crossLayer:false};
|
|
19
28
|
|
|
@@ -41,11 +50,13 @@ async function fixture(t,{observation=false,reviewMode=null,crossLayer=false,les
|
|
|
41
50
|
permissions:['--allow-final-review','--allow-cause-review','--allow-repair'],workerFactory:()=>async({prompt},{onEvent})=>{
|
|
42
51
|
reviews++;
|
|
43
52
|
const data=JSON.parse(prompt.split('<cm-review-data-json>\n')[1]);
|
|
44
|
-
onEvent({event:'thread.started',provider_thread:`fixture-review-${reviews}`});
|
|
45
|
-
if(reviewMode==='lost'||
|
|
53
|
+
onEvent({event:'thread.started',provider_thread:`fixture-review-${reviewMode==='first_lost_same_thread'?1:reviews}`});
|
|
54
|
+
if(reviewMode==='lost'||['second_lost','second_lost_retry'].includes(reviewMode)&&reviews===2
|
|
55
|
+
||['first_lost','first_lost_same_thread'].includes(reviewMode)&&reviews===1)throw Error('Synthetic lost review result');
|
|
46
56
|
for(const event of [{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
47
57
|
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
48
|
-
const verdict=['changes_requested','second_lost'].includes(reviewMode)
|
|
58
|
+
const verdict=['changes_requested','second_lost'].includes(reviewMode)||reviewMode==='second_lost_retry'&&reviews===1
|
|
59
|
+
?'changes_requested':'approved';
|
|
49
60
|
return {status:'succeeded',value:{verdict,packageDigest:data.reviewPackage.packageDigest,
|
|
50
61
|
examinedPaths:data.examinedPaths,
|
|
51
62
|
findings:verdict==='changes_requested'?[{id:'F1',severity:'P2',path:'value.mjs',message:'Revise value',evidence:'Fixture'}]:[],
|
|
@@ -60,7 +71,7 @@ async function fixture(t,{observation=false,reviewMode=null,crossLayer=false,les
|
|
|
60
71
|
return crossLayer?{...diagnosis,crossLayer:true}:diagnosis;
|
|
61
72
|
}
|
|
62
73
|
if(kind==='fix_repair'){
|
|
63
|
-
if(['changes_requested','second_lost'].includes(reviewMode)&&payload.identity.attempt===2&&loseRevisionRepair){
|
|
74
|
+
if(['changes_requested','second_lost','second_lost_retry'].includes(reviewMode)&&payload.identity.attempt===2&&loseRevisionRepair){
|
|
64
75
|
loseRevisionRepair=false;throw Error('Lost revision repair answer');
|
|
65
76
|
}
|
|
66
77
|
fs.writeFileSync(path.join(cwd,'value.mjs'),payload.identity.attempt===2?'export const value=2; // revised\n':'export const value=2;\n');
|
|
@@ -381,3 +392,110 @@ test('revision final review cannot use local abandonment',async t=>{
|
|
|
381
392
|
assert.equal(f.owner().status().pending,'revision_final_review');
|
|
382
393
|
assert.throws(()=>f.owner().abandonStep({authorized:true,reason:'Review result lost'}),{code:'fix_abandon_unavailable'});
|
|
383
394
|
});
|
|
395
|
+
|
|
396
|
+
// #15: a registered cause or second-round final review with no review result
|
|
397
|
+
// gets one audited abandonment and a retry on a fresh reviewer thread.
|
|
398
|
+
const causeDecide=async f=>{const pkg=f.owner().causeReviewPackage();
|
|
399
|
+
await f.reviewHost.authority.hostDecisionProvider.decide({identity:f.identity,packageDigest:pkg.packageDigest},new AbortController().signal);};
|
|
400
|
+
const reviewEvents=f=>fs.readFileSync(path.join(f.specsRoot,'运行日志.jsonl'),'utf8').trim().split('\n').map(JSON.parse)
|
|
401
|
+
.filter(row=>row.event==='abandon');
|
|
402
|
+
|
|
403
|
+
test('#15 a no-result cause review is abandoned once, audited, and retried on a fresh reviewer thread',async t=>{
|
|
404
|
+
const f=await fixture(t,{reviewMode:'first_lost',crossLayer:true});
|
|
405
|
+
assert.equal((await f.owner().advance({authorized:true})).stage,'cause_review_required');
|
|
406
|
+
await causeDecide(f);
|
|
407
|
+
const lost=await f.owner().reviewCause();
|
|
408
|
+
assert.equal(lost.stage,'unknown');assert.equal(lost.pending,'cause_review');assert.equal(lost.reviewAbandonable,'cause_review');
|
|
409
|
+
const before=fs.readFileSync(f.statePath);
|
|
410
|
+
assert.throws(()=>f.owner().abandonStep({authorized:true,reason:'Review result lost'}),{code:'fix_abandon_unavailable'});
|
|
411
|
+
assert.throws(()=>f.owner().abandonReview({authorized:false,reason:'Review result lost'}),{code:'fix_review_abandon_authorization_required'});
|
|
412
|
+
assert.throws(()=>f.owner().abandonReview({authorized:true,reason:'two\nlines'}),{code:'fix_review_abandon_reason_required'});
|
|
413
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
414
|
+
const abandoned=f.owner().abandonReview({authorized:true,reason:'Reviewer process confirmed stopped'});
|
|
415
|
+
assert.equal(abandoned.stage,'cause_review_required');
|
|
416
|
+
assert.equal(abandoned.causeReviewAbandonment.providerThreadId,'fixture-review-1');
|
|
417
|
+
assert.equal(abandoned.causeReviewAbandonment.resultDigest,null);
|
|
418
|
+
assert.equal(f.reopen().status().stage,'cause_review_required');
|
|
419
|
+
await causeDecide(f);
|
|
420
|
+
assert.equal((await f.owner().reviewCause()).stage,'red_test_required');
|
|
421
|
+
const ids=f.records().map(row=>row.id).filter(id=>id.startsWith('fix-cause'));
|
|
422
|
+
assert.deepEqual(ids,['fix-cause-registered','fix-cause-started','fix-cause-abandoned',
|
|
423
|
+
'fix-cause-retry-registered','fix-cause-retry-started','fix-cause-retry-result']);
|
|
424
|
+
assert.equal(f.records().find(row=>row.id==='fix-cause-retry-started').payload.providerThreadId,'fixture-review-2');
|
|
425
|
+
assert.equal(f.reviews(),2);
|
|
426
|
+
assert(fs.existsSync(path.join(f.specsRoot,'.reviews','fix-abandon-cause-r1.md')));
|
|
427
|
+
assert.deepEqual(reviewEvents(f).map(row=>[row.phase,row.pending,row.reason]),[['cause_review','cause_review','Reviewer process confirmed stopped']]);
|
|
428
|
+
assert.equal(f.reopen().status().stage,'red_test_required');
|
|
429
|
+
assert.equal(f.owner().status().causeReview.providerThreadId,'fixture-review-2');
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('#15 a second no-result cause review exhausts the one-time budget without changing the store',async t=>{
|
|
433
|
+
const f=await fixture(t,{reviewMode:'lost',crossLayer:true});
|
|
434
|
+
await f.owner().advance({authorized:true});await causeDecide(f);
|
|
435
|
+
assert.equal((await f.owner().reviewCause()).stage,'unknown');
|
|
436
|
+
f.owner().abandonReview({authorized:true,reason:'First reviewer stopped'});
|
|
437
|
+
await causeDecide(f);
|
|
438
|
+
const again=await f.owner().reviewCause();
|
|
439
|
+
assert.equal(again.stage,'unknown');assert.equal(again.reviewAbandonBudgetExhausted,true);assert.equal(again.reviewAbandonable,undefined);
|
|
440
|
+
const before=fs.readFileSync(f.statePath);
|
|
441
|
+
assert.throws(()=>f.owner().abandonReview({authorized:true,reason:'Second reviewer stopped'}),{code:'fix_review_abandon_budget_exhausted'});
|
|
442
|
+
assert.deepEqual(fs.readFileSync(f.statePath),before);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
test('#15 an abandonment record must bind the exact registration and thread',async t=>{
|
|
446
|
+
const f=await fixture(t,{reviewMode:'lost',crossLayer:true});
|
|
447
|
+
await f.owner().advance({authorized:true});await causeDecide(f);await f.owner().reviewCause();
|
|
448
|
+
const registration=f.records().find(row=>row.id==='fix-cause-registered');
|
|
449
|
+
const forged={invocationId:registration.payload.request.invocationId,registrationDigest:'0'.repeat(64),
|
|
450
|
+
providerThreadId:'fixture-review-1',resultDigest:null,reason:'Forged',abandonedAt:Date.now()};
|
|
451
|
+
assert.throws(()=>f.append('fix-cause-abandoned','result',forged),{code:'fix_review_abandon_mismatch'});
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('#15 the fix host needs the dedicated --allow-abandon-review for abandon_review and its status points to it',async t=>{
|
|
455
|
+
const f=await fixture(t,{reviewMode:'lost',crossLayer:true});
|
|
456
|
+
await f.owner().advance({authorized:true});await causeDecide(f);await f.owner().reviewCause();
|
|
457
|
+
const config={...f.configuration,specsRoot:f.specsRoot,identity:f.identity};
|
|
458
|
+
// Local step abandonment authority does not extend to a reviewer invocation.
|
|
459
|
+
for(const permissions of [['--allow-reproduction'],['--allow-reproduction','--allow-abandon']]){
|
|
460
|
+
const refused=createFixHost({owner:f.owner(),config,permissions});
|
|
461
|
+
await assert.rejects(refused.handle({requestId:'abandon',operation:'abandon_review',reason:'Stopped'}),{code:'fix_review_abandon_authorization_required'});
|
|
462
|
+
}
|
|
463
|
+
const allowed=createFixHost({owner:f.owner(),config,permissions:['--allow-reproduction','--allow-abandon-review']});
|
|
464
|
+
assert.match((await allowed.handle({requestId:'status',operation:'status'})).progress.nextAction,/abandon_review/);
|
|
465
|
+
assert.equal((await allowed.handle({requestId:'abandon',operation:'abandon_review',reason:'Stopped'})).stage,'cause_review_required');
|
|
466
|
+
});
|
|
467
|
+
|
|
468
|
+
test('#15 a no-result second-round final review is abandoned once and retried on a fresh thread',async t=>{
|
|
469
|
+
const f=await fixture(t,{reviewMode:'second_lost_retry'});
|
|
470
|
+
await toRevision(f);await completeRevisionRepair(f);
|
|
471
|
+
await f.owner().runRegression({authorized:true});await f.owner().retrospect();
|
|
472
|
+
assert.equal(f.owner().createHandoff().stage,'revision_final_review_required');
|
|
473
|
+
const decide=async()=>{const pkg=f.owner().finalReviewPackage();
|
|
474
|
+
await f.reviewHost.finalAuthority.hostDecisionProvider.decide({identity:f.owner().status().revision.nextIdentity,
|
|
475
|
+
packageDigest:pkg.packageDigest},new AbortController().signal);};
|
|
476
|
+
await decide();
|
|
477
|
+
const lost=await f.owner().reviewFinal();
|
|
478
|
+
assert.equal(lost.stage,'unknown');assert.equal(lost.pending,'revision_final_review');
|
|
479
|
+
assert.equal(lost.reviewAbandonable,'revision_final_review');
|
|
480
|
+
assert.equal(f.owner().abandonReview({authorized:true,reason:'Second reviewer stopped'}).stage,'revision_final_review_required');
|
|
481
|
+
assert.equal(f.reopen().status().stage,'revision_final_review_required');
|
|
482
|
+
await decide();
|
|
483
|
+
assert.equal((await f.owner().reviewFinal()).stage,'revision_final_review_evidence_required');
|
|
484
|
+
const ids=f.records().map(row=>row.id).filter(id=>id.startsWith('fix-revision-final'));
|
|
485
|
+
assert.deepEqual(ids,['fix-revision-final-registered','fix-revision-final-started','fix-revision-final-abandoned',
|
|
486
|
+
'fix-revision-final-retry-registered','fix-revision-final-retry-started','fix-revision-final-retry-result']);
|
|
487
|
+
assert.notEqual(f.records().find(row=>row.id==='fix-revision-final-retry-started').payload.providerThreadId,
|
|
488
|
+
f.records().find(row=>row.id==='fix-revision-final-started').payload.providerThreadId);
|
|
489
|
+
assert.equal(f.owner().publishReview().stage,'revision_completion_gate_required');
|
|
490
|
+
assert.equal(f.reopen().status().stage,'revision_completion_gate_required');
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
test('#15 the retried cause review refuses the abandoned reviewer thread',async t=>{
|
|
494
|
+
const f=await fixture(t,{reviewMode:'first_lost_same_thread',crossLayer:true});
|
|
495
|
+
await f.owner().advance({authorized:true});await causeDecide(f);await f.owner().reviewCause();
|
|
496
|
+
f.owner().abandonReview({authorized:true,reason:'Reviewer process confirmed stopped'});
|
|
497
|
+
await causeDecide(f);
|
|
498
|
+
const reused=await f.owner().reviewCause();
|
|
499
|
+
assert.equal(reused.stage,'unknown');assert.equal(reused.pending,'cause_review');
|
|
500
|
+
assert(!f.records().some(row=>row.id==='fix-cause-retry-started'));
|
|
501
|
+
});
|
|
@@ -57,6 +57,8 @@ test('cause package binds only selected current source and never advances the fi
|
|
|
57
57
|
requestedModel:'synthetic',contextId:'logical-review',payload:{reviewPackage:first,priorReview:null}});
|
|
58
58
|
assert.match(buildCauseReviewPrompt(request,provider),/pre-implementation review/);
|
|
59
59
|
assert.match(buildCauseReviewPrompt(request,provider),/Rewrite all callers/);
|
|
60
|
+
assert.match(buildCauseReviewPrompt(request,provider),/approved requires zero P0, P1 and P2 findings/);
|
|
61
|
+
assert.match(buildCauseReviewPrompt(request,provider),/changes_requested requires at least one P0, P1 or P2 finding/);
|
|
60
62
|
assert.throws(()=>buildReviewPrompt(request,provider));
|
|
61
63
|
const expectation=JSON.stringify({request,developerThreadId:'author',excludedThreadIds:['fixture-host']});
|
|
62
64
|
const observation={version:1,kind:'cm-provider-review-observation',requestDigest:request.requestDigest,
|
package/scripts/cm-fix-drive.mjs
CHANGED
|
@@ -21,20 +21,22 @@
|
|
|
21
21
|
// "runtime": "codex" | "claude", 缺省 codex
|
|
22
22
|
// "reviewConfig": "review.json", 可选
|
|
23
23
|
// "permissions": ["--allow-red-test", ...], 原样传给宿主,不另造一套词
|
|
24
|
-
// "answers": "answers", 答案目录;abandon_step 可省略
|
|
25
|
-
// "reason": "旧本地步骤结果丢失" abandon_step
|
|
24
|
+
// "answers": "answers", 答案目录;abandon_step / abandon_review 可省略
|
|
25
|
+
// "reason": "旧本地步骤结果丢失" abandon_step 必填并需 --allow-abandon;abandon_review 必填并需 --allow-abandon-review
|
|
26
|
+
// "inputLimit": 1048576 可选;宿主输入与应答上限(65536–4194304,默认 65536)
|
|
26
27
|
// }
|
|
27
28
|
//
|
|
28
29
|
// answers/ 里按反问种类放文件,一种一个:
|
|
29
30
|
// learning.json {status, summary} 恢复时若存档里已有记录会自动复用
|
|
30
31
|
// diagnosis.json 诊断结论对象
|
|
31
32
|
// retrospective.json {status, candidates, reason}
|
|
32
|
-
// test-edits.json {"仓库内路径": "本目录下的内容文件"}
|
|
33
|
-
// repair-edits.json
|
|
33
|
+
// test-edits.json {"仓库内路径": "本目录下的内容文件"};修订轮用 test-edits-a2.json
|
|
34
|
+
// repair-edits.json 同上;修订轮用 repair-edits-a2.json
|
|
34
35
|
import fs from 'node:fs';
|
|
35
36
|
import path from 'node:path';
|
|
36
37
|
import {fileURLToPath} from 'node:url';
|
|
37
38
|
import {fixEvidenceNames} from '../runtime/js/cm-fix/layout.mjs';
|
|
39
|
+
import {readExecutionSnapshot} from '../runtime/js/cm-ai/execution-snapshot.mjs';
|
|
38
40
|
import {stderr,stop,readJson,loadPlanFile,requireFields,preflightAnswers,driveHost} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
39
41
|
|
|
40
42
|
const here=path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -55,18 +57,22 @@ const ASKS={
|
|
|
55
57
|
const READ_ONLY=new Set(['status','final_review_package','completion_evidence','cause_review_package']);
|
|
56
58
|
const KNOWN=new Set([...Object.keys(ASKS),...READ_ONLY,'cancel','handoff','publish_review','check_n5',
|
|
57
59
|
'publish_dossier','learning_writeback','walkthrough','finish','final_review','cause_review',
|
|
58
|
-
'recover_final_review','abandon_step','resume','revision_test_check']);
|
|
60
|
+
'recover_final_review','abandon_step','abandon_review','resume','revision_test_check']);
|
|
59
61
|
|
|
60
62
|
function loadPlan(){
|
|
61
63
|
const {operation,plan,base}=loadPlanFile({name:'cm-fix-drive.mjs',known:KNOWN});
|
|
62
|
-
|
|
64
|
+
const abandoning=['abandon_step','abandon_review'].includes(operation);
|
|
65
|
+
requireFields(plan,['config','cwd','mode','hostContext','permissions',...(abandoning?[]:['answers'])]);
|
|
63
66
|
if(!['create','resume'].includes(plan.mode))stop(2,'mode 只能是 create 或 resume');
|
|
64
67
|
if(!Array.isArray(plan.permissions)||plan.permissions.some(p=>!/^--allow-[a-z-]+$/.test(p)))
|
|
65
68
|
stop(2,'permissions 必须是 --allow-xxx 形式的数组,原样传给宿主');
|
|
66
|
-
|
|
69
|
+
const abandonFlag=operation==='abandon_review'?'--allow-abandon-review':'--allow-abandon';
|
|
70
|
+
if(abandoning&&(!plan.permissions.includes(abandonFlag)||typeof plan.reason!=='string'
|
|
67
71
|
||!plan.reason.trim().length||Buffer.byteLength(plan.reason,'utf8')>1000||/[\r\n\0\u0085\u2028\u2029]/.test(plan.reason)))
|
|
68
|
-
stop(2
|
|
72
|
+
stop(2,`${operation} 需要 PLAN.reason(单行,最多 1000 字节)和 ${abandonFlag}`);
|
|
69
73
|
if(plan.originalHostContext&&plan.mode!=='resume')stop(2,'originalHostContext 只在 resume 时有意义');
|
|
74
|
+
if(Object.hasOwn(plan,'inputLimit')&&!(Number.isSafeInteger(plan.inputLimit)&&plan.inputLimit>=65536&&plan.inputLimit<=4194304))
|
|
75
|
+
stop(2,'inputLimit 需要 65536–4194304 的整数(字节)');
|
|
70
76
|
const resolve=p=>path.resolve(base,p);
|
|
71
77
|
return {operation,plan,paths:{config:resolve(plan.config),answers:plan.answers?resolve(plan.answers):null,
|
|
72
78
|
review:plan.reviewConfig?resolve(plan.reviewConfig):null}};
|
|
@@ -81,12 +87,33 @@ function recordedLearning(config,cwd){
|
|
|
81
87
|
const record=stored?.records?.find(row=>row.kind==='result'&&/^fix-learning-/.test(row.id));
|
|
82
88
|
return record?.payload?.application??null;
|
|
83
89
|
}
|
|
90
|
+
function answerRound(config,operation,cwd){
|
|
91
|
+
if(!['repair','author_tests'].includes(operation))return 1;
|
|
92
|
+
const archive=config.specsRoot??path.join(cwd,'docs','fixes');
|
|
93
|
+
const state=path.join(archive,'.reviews','.execution',config.identity.runId,'state.json');
|
|
94
|
+
if(!fs.existsSync(state))return 1;
|
|
95
|
+
try{
|
|
96
|
+
const snapshot=readExecutionSnapshot({specsRoot:archive,identity:{
|
|
97
|
+
repositoryId:config.identity.repositoryId,runId:config.identity.runId}});
|
|
98
|
+
return snapshot.records.some(row=>row.id==='fix-revision-prepared')?2:1;
|
|
99
|
+
}catch(error){stop(2,`无法只读检查 cm-fix 修订轮次: ${error.code??error.message}`);}
|
|
100
|
+
}
|
|
101
|
+
function roundAnswerName(root,kind,round){
|
|
102
|
+
const legacy=`${kind}.json`,first=`${kind}-a1.json`;
|
|
103
|
+
if(round===1){
|
|
104
|
+
if(fs.existsSync(path.join(root,legacy))&&fs.existsSync(path.join(root,first)))
|
|
105
|
+
stop(2,`${legacy} 与 ${first} 不能同时存在`);
|
|
106
|
+
return fs.existsSync(path.join(root,first))?first:legacy;
|
|
107
|
+
}
|
|
108
|
+
return `${kind}-a${round}.json`;
|
|
109
|
+
}
|
|
84
110
|
|
|
85
111
|
function preflight({operation,plan,paths}){
|
|
86
112
|
const config=readJson(paths.config,'宿主配置');
|
|
87
113
|
if(config===undefined)stop(2,`宿主配置不存在: ${paths.config}`);
|
|
88
114
|
if(path.resolve(plan.cwd)!==path.resolve(config.reproduction?.cwd??''))
|
|
89
115
|
stop(2,`PLAN.cwd 与 config.reproduction.cwd 不一致`);
|
|
116
|
+
const round=answerRound(config,operation,plan.cwd);
|
|
90
117
|
const need=(kind,file)=>{const value=readJson(path.join(paths.answers,file),kind);
|
|
91
118
|
if(value===undefined)stop(2,`步骤 ${operation} 会反问「${kind}」,但答案文件不存在: ${path.join(paths.answers,file)}\n 先把它写好,再来调驾驱员。缺答案而硬发指令,会把这次运行做死。`);
|
|
92
119
|
return value;};
|
|
@@ -98,7 +125,8 @@ function preflight({operation,plan,paths}){
|
|
|
98
125
|
}
|
|
99
126
|
if(kind==='diagnosis')return need('诊断','diagnosis.json');
|
|
100
127
|
if(kind==='retrospective')return need('复盘','retrospective.json');
|
|
101
|
-
const
|
|
128
|
+
const file=roundAnswerName(paths.answers,kind,round);
|
|
129
|
+
const map=need(kind==='test-edits'?'测试内容':'修复内容',file);
|
|
102
130
|
for(const [target,local] of Object.entries(map)){
|
|
103
131
|
const file=path.join(paths.answers,local);
|
|
104
132
|
if(!fs.existsSync(file))stop(2,`${kind}.json 把 ${target} 指向 ${file},但那个文件不存在`);
|
|
@@ -125,13 +153,14 @@ function preflight({operation,plan,paths}){
|
|
|
125
153
|
stderr(`注意:受保护模式的沙箱跑不了 tsx / vitest 这类要开本地 socket 的命令:${command.join(' ')}\n 见 skills/cm-fix/references/js-host.md「同仓 specs 的受保护修复」`);
|
|
126
154
|
}
|
|
127
155
|
}
|
|
128
|
-
return {config,answers};
|
|
156
|
+
return {config,answers,round};
|
|
129
157
|
}
|
|
130
158
|
|
|
131
159
|
function hostArgs({plan,paths}){
|
|
132
160
|
return [HOST,'serve','--config',paths.config,'--mode',plan.mode,'--host-context',plan.hostContext,'--allow-reproduction',
|
|
133
161
|
...(plan.originalHostContext?['--original-host-context',plan.originalHostContext]:[]),
|
|
134
162
|
'--runtime',plan.runtime??'codex',
|
|
163
|
+
...(Object.hasOwn(plan,'inputLimit')?['--input-limit',String(plan.inputLimit)]:[]),
|
|
135
164
|
...(paths.review?['--review-config',paths.review]:[]),
|
|
136
165
|
...plan.permissions];
|
|
137
166
|
}
|
|
@@ -142,6 +171,9 @@ function answerFor(row,answers,paths){
|
|
|
142
171
|
if(kind==='fix_diagnose')return answers.diagnosis;
|
|
143
172
|
if(kind==='fix_retrospective')return answers.retrospective;
|
|
144
173
|
if(kind==='fix_test_author'||kind==='fix_repair'){
|
|
174
|
+
const requestAttempt=payload.identity?.attempt??payload.request?.identity?.attempt;
|
|
175
|
+
if(requestAttempt!==undefined&&requestAttempt!==paths.round)
|
|
176
|
+
throw Error(`修订轮次 ${requestAttempt} 与已预检答案轮次 ${paths.round} 不一致`);
|
|
145
177
|
const map=answers[kind==='fix_repair'?'repair-edits':'test-edits'],expected=payload.expected??{};
|
|
146
178
|
const edits=[];
|
|
147
179
|
for(const [target,local] of Object.entries(map)){
|
|
@@ -157,12 +189,12 @@ function answerFor(row,answers,paths){
|
|
|
157
189
|
|
|
158
190
|
function main(){
|
|
159
191
|
const loaded=loadPlan();
|
|
160
|
-
const {answers}=preflight(loaded);
|
|
192
|
+
const {answers,round}=preflight(loaded);
|
|
161
193
|
const {operation,plan,paths}=loaded;
|
|
162
194
|
driveHost({host:HOST,args:hostArgs(loaded).slice(1),cwd:path.resolve(plan.cwd),operation,
|
|
163
|
-
request:{...(
|
|
195
|
+
request:{...(['abandon_step','abandon_review'].includes(operation)?{reason:plan.reason}:{}),
|
|
164
196
|
...(operation==='prepare_revision'&&Object.hasOwn(plan,'revisionTests')?{tests:plan.revisionTests}:{})},
|
|
165
|
-
answers,paths,answerFor});
|
|
197
|
+
answers,paths:{...paths,round},answerFor});
|
|
166
198
|
}
|
|
167
199
|
|
|
168
200
|
main();
|