@aibyzero/cm-workflow 0.16.4 → 0.16.6
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 +22 -0
- package/CHANGELOG.md +57 -0
- package/README.md +22 -4
- package/THIRD_PARTY_NOTICES.md +9 -0
- package/VERSION +1 -1
- package/docs/architecture.md +43 -0
- package/docs/execution-optimizations.md +33 -0
- package/docs/external-models.md +114 -0
- package/docs/fixes/.reviews/20260929-bootstrap-unchanged-review-r1.md +7 -0
- package/docs/fixes/.reviews/20260930-develop-package-limit-recovery-r4.md +9 -0
- package/docs/fixes/20260929-bootstrap-rule-refresh-conflict.md +22 -0
- package/docs/fixes/20260929-bootstrap-unchanged-review.md +26 -0
- package/docs/fixes/20260930-develop-package-limit-recovery.md +65 -0
- package/docs/human-correction.md +31 -0
- package/docs/installation.md +48 -7
- package/docs/js-workflow-control.md +293 -33
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- package/docs/runtime-failover.md +1 -1
- package/docs/untested-branches.md +27 -4
- package/docs/user-guide.md +23 -8
- package/install-codex.sh +28 -11
- 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-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -0
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- 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 +208 -34
- 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 +181 -57
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +15 -58
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +56 -17
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- 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 +315 -0
- package/runtime/js/cm-ai/drive-core.mjs +47 -9
- package/runtime/js/cm-ai/durable-runner-state.mjs +413 -56
- 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-policy.mjs +58 -0
- 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/external-group-models.mjs +53 -0
- package/runtime/js/cm-ai/external-model-launch.mjs +23 -0
- package/runtime/js/cm-ai/external-models.mjs +52 -0
- package/runtime/js/cm-ai/external-run-guard.mjs +96 -0
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +126 -29
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +66 -20
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-progress.mjs +80 -0
- package/runtime/js/cm-ai/host-project-execution.mjs +16 -11
- package/runtime/js/cm-ai/host-qa-executor.mjs +23 -9
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +23 -6
- 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 +16 -5
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -0
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/legacy-model-run-preview.mjs +24 -0
- package/runtime/js/cm-ai/legacy-model-settings.mjs +59 -0
- package/runtime/js/cm-ai/live-evidence.mjs +96 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/model-configuration-file.mjs +63 -0
- package/runtime/js/cm-ai/model_configuration_write.py +214 -0
- package/runtime/js/cm-ai/native-usage-log.mjs +26 -0
- package/runtime/js/cm-ai/operator-guidance.mjs +86 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +68 -9
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- 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 +438 -31
- package/runtime/js/cm-ai/review-presentation.mjs +45 -0
- package/runtime/js/cm-ai/review-reconciliation.mjs +20 -0
- 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/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +658 -75
- package/runtime/js/cm-ai/tool-preview.mjs +8 -4
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-ai/worker-claude.mjs +63 -19
- package/runtime/js/cm-ai/worker-codex-developer.mjs +15 -9
- package/runtime/js/cm-ai/worker-codex.mjs +45 -19
- package/runtime/js/cm-fix/cause-evidence.mjs +5 -3
- package/runtime/js/cm-fix/cause-invocation.mjs +6 -3
- package/runtime/js/cm-fix/cause-package.mjs +10 -1
- package/runtime/js/cm-fix/execution.mjs +279 -52
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/host-review.mjs +32 -9
- package/runtime/js/cm-fix/host.mjs +6 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/progress.mjs +5 -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-fix/review-reconciliation.mjs +64 -0
- 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/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +27 -15
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-prd/summary.mjs +3 -1
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +10 -3
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- 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 +135 -34
- package/scripts/cm-ai-batch-drive.test.mjs +209 -3
- package/scripts/cm-ai-batch-host.mjs +63 -24
- package/scripts/cm-ai-batch-host.test.mjs +2 -1
- package/scripts/cm-ai-batch-run.mjs +101 -34
- 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 +159 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +162 -0
- package/scripts/cm-ai-bootstrap.test.mjs +174 -89
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +97 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +924 -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 +526 -60
- package/scripts/cm-ai-drive.test.mjs +336 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +142 -43
- 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-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +187 -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 +977 -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 +206 -62
- package/scripts/cm-ai-run.test.mjs +6 -4
- 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-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.test.mjs +2 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +12 -1
- package/scripts/cm-claude-developer-worker.test.mjs +3 -1
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +10 -2
- 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-codex-plugin-metadata.py +83 -0
- package/scripts/cm-codex-plugin-metadata.test.mjs +55 -0
- package/scripts/cm-efficiency-checks.test.mjs +37 -0
- package/scripts/cm-efficiency-diagnostics.test.mjs +74 -0
- package/scripts/cm-efficiency-offline.mjs +35 -0
- package/scripts/cm-efficiency-policy.test.mjs +48 -0
- package/scripts/cm-efficiency-presentation.test.mjs +35 -0
- package/scripts/cm-efficiency-response.test.mjs +117 -0
- package/scripts/cm-efficiency-usage.test.mjs +148 -0
- package/scripts/cm-external-batch-host.test.mjs +157 -0
- package/scripts/cm-external-fix-host.test.mjs +281 -0
- package/scripts/cm-external-fix-reconciliation.test.mjs +105 -0
- package/scripts/cm-external-group-models.test.mjs +60 -0
- package/scripts/cm-external-model-host.test.mjs +180 -0
- package/scripts/cm-external-model-recovery.test.mjs +108 -0
- package/scripts/cm-external-models.test.mjs +89 -0
- package/scripts/cm-external-process-cleanup.test.mjs +71 -0
- package/scripts/cm-external-qa-fix.test.mjs +170 -0
- package/scripts/cm-external-review-reconciliation.test.mjs +314 -0
- 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 +70 -23
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +24 -14
- package/scripts/cm-fix-protected-edits.test.mjs +12 -0
- package/scripts/cm-fix-rediagnosis.test.mjs +168 -0
- package/scripts/cm-fix-review-budget.test.mjs +147 -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 +213 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +25 -2
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-completion.test.mjs +75 -0
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-host.mjs +13 -4
- 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-release-smoke.sh +5 -1
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-runtime-i18n.mjs +15 -4
- package/scripts/cm-runtime-install.mjs +8 -4
- package/scripts/cm-runtime.mjs +116 -23
- package/scripts/cm-runtime.test.mjs +121 -12
- package/scripts/cm-security.test.mjs +32 -0
- 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-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +164 -20
- package/scripts/cm-task-gate.py +2 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/cm-test-drive.mjs +10 -4
- package/scripts/cm-test-drive.test.mjs +14 -1
- package/scripts/cm-tool-preview-context.test.mjs +12 -0
- package/scripts/cm-usage-report.py +22 -3
- package/scripts/cm-workflow-config.mjs +10 -1
- package/scripts/fixtures/bootstrap-review-runner.mjs +102 -0
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +101 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +11 -2
- 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/SKILL.md +2 -2
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/N8-finish.md +5 -0
- package/skills/cm-ai/references/js-host.md +270 -43
- package/skills/cm-ai/references/knowledge-closeout.md +90 -0
- package/skills/cm-fix/SKILL.md +1 -1
- package/skills/cm-fix/references/js-host.md +52 -3
- package/skills/cm-prd/references/js-change-recovery.md +1 -1
- package/skills/cm-prd/references/js-host.md +6 -0
- package/skills/cm-runtime/SKILL.md +29 -6
- package/skills/cm-security/SKILL.md +4 -2
- package/skills/cm-security/references/scan-contract.md +1 -0
- package/templates/cm-workflow.yml +1 -1
|
@@ -4,6 +4,7 @@ import assert from 'node:assert/strict';
|
|
|
4
4
|
import fs from 'node:fs';
|
|
5
5
|
import os from 'node:os';
|
|
6
6
|
import path from 'node:path';
|
|
7
|
+
import {createHash} from 'node:crypto';
|
|
7
8
|
import {spawn,spawnSync} from 'node:child_process';
|
|
8
9
|
import {fileURLToPath} from 'node:url';
|
|
9
10
|
import {createHostBootstrap} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
@@ -14,92 +15,12 @@ import {createDeveloperRun,validateDeveloperScope} from '../runtime/js/cm-ai/dev
|
|
|
14
15
|
import {inspectCmAiAdmission} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
15
16
|
import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
16
17
|
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
18
|
+
import {readRunnerHistory,runnerStatus,developBudgetExhausted} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
17
19
|
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
18
20
|
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
19
21
|
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
20
22
|
|
|
21
|
-
|
|
22
|
-
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-bootstrap-home-'));
|
|
23
|
-
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
24
|
-
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
25
|
-
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
26
|
-
|
|
27
|
-
const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
|
|
28
|
-
const selection={versionControl:'none',modules:['frontend'],analysis:'Approved synthetic JavaScript project'};
|
|
29
|
-
const checks=()=>Object.fromEntries(['commands','globs','file_references','constraint_preservation','rule_applicability']
|
|
30
|
-
.map(name=>[name,{status:'verified',evidence:'Synthetic semantic report for the local fixture'}]));
|
|
31
|
-
function fixture(t){
|
|
32
|
-
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-')));
|
|
33
|
-
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
34
|
-
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
35
|
-
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,'0.bootstrap'),{recursive:true});fs.mkdirSync(path.join(specsDir,'.reviews'));
|
|
36
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','requirements.md'),'# Requirements\nSynthetic approved scaffold and project instructions.\n');
|
|
37
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','design.md'),'# Design\nJavaScript; no Git; frontend module.\n');
|
|
38
|
-
fs.writeFileSync(path.join(specsDir,'0.bootstrap','tasks.md'),'- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 .claude/ 规范(cm-init)\n');
|
|
39
|
-
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.bootstrap'],specFiles:buildManifest(specsDir)}));
|
|
40
|
-
return {root,codeProject,specsDir,calls:[],reviews:[],businessCalls:0};
|
|
41
|
-
}
|
|
42
|
-
function definition(f,taskId){
|
|
43
|
-
return {version:1,codeProject:f.codeProject,specsDir:f.specsDir,feature:'0.bootstrap',
|
|
44
|
-
identity:{repositoryId:'bootstrap-fixture',runId:'run-'+taskId,taskId,attempt:1},
|
|
45
|
-
scope:taskId==='T-001'?['app.mjs']:[...cmInitRuleTargets(selection)],requirements:[]};
|
|
46
|
-
}
|
|
47
|
-
function reply(f,kind,payload){
|
|
48
|
-
f.calls.push(kind);
|
|
49
|
-
if(kind==='init_generate')return {status:'generated',documents:payload.targets.map(file=>({path:file,
|
|
50
|
-
content:file==='AGENTS.md'&&fs.existsSync(path.join(f.codeProject,file))?fs.readFileSync(path.join(f.codeProject,file),'utf8'):
|
|
51
|
-
file==='.claude/CLAUDE.md'?'# Fixture instructions\n'+payload.targets.filter(p=>p.startsWith('.claude/rules/'))
|
|
52
|
-
.map(p=>'@rules/'+path.basename(p)).join('\n')+'\n':'# Fixture instructions\nUse approved scope.\n'}))};
|
|
53
|
-
if(kind==='init_verify')return {checks:checks(),constraintChanges:[],application:{status:'no_relevant_lesson',note:null},
|
|
54
|
-
retrospective:f.lesson&&f.calls.filter(kind=>kind==='init_verify').length===1
|
|
55
|
-
?{status:'lesson_candidate',candidates:[{classification:'structured',trigger:'Bootstrap recovery',
|
|
56
|
-
action:'Preserve reviewed instruction lessons across attempts',evidence:['app.mjs']}],reason:null}
|
|
57
|
-
:{status:'no_new_lesson',candidates:[],reason:null}};
|
|
58
|
-
assert.fail('unexpected host call '+kind);
|
|
59
|
-
}
|
|
60
|
-
function open(f,taskId,mode='create',overrides={}){
|
|
61
|
-
const d=definition(f,taskId),bridge={call:async(kind,payload)=>overrides.reply?overrides.reply(kind,payload):reply(f,kind,payload)};
|
|
62
|
-
const bootstrap=createHostBootstrap({definition:d,workflowRoot,selection:taskId==='T-001'?null:selection,bridge,
|
|
63
|
-
allowWrite:overrides.allowWrite??true});
|
|
64
|
-
const store=openTaskExecutionStore({tasksPath:path.join(f.specsDir,'0.bootstrap','tasks.md'),feature:'bootstrap',specsRoot:f.specsDir,
|
|
65
|
-
identity:{repositoryId:d.identity.repositoryId,runId:d.identity.runId},
|
|
66
|
-
fingerprints:{workflow:digest('bootstrap-test'),config:digest({d,bootstrap:bootstrap.configuration}),inputs:digest(taskId)},create:mode==='create'});
|
|
67
|
-
const developer={provider:'codex',requestedModel:'synthetic',contextId:'scaffold-author',run:createDeveloperRun({provider:'codex',requestedModel:'synthetic',worker:async request=>{
|
|
68
|
-
f.businessCalls++;assert(!request.prompt.includes('"scope":["AGENTS.md"'));
|
|
69
|
-
assert(request.prompt.includes(Buffer.from('JavaScript; no Git; frontend module.').toString('base64').slice(0,12))
|
|
70
|
-
||request.prompt.includes('0.bootstrap/design.md'));
|
|
71
|
-
fs.writeFileSync(path.join(f.codeProject,'app.mjs'),'export const fixture = true;\n');
|
|
72
|
-
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
73
|
-
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
74
|
-
}})};
|
|
75
|
-
const runner=createTaskRunner({root:f.codeProject,identity:d.identity,scope:d.scope,requirements:d.requirements,bootstrap,
|
|
76
|
-
taskLearning:{feature:'0.bootstrap',hostHandoff:true},developer,excludedContexts:['main'],timeoutMs:5000,
|
|
77
|
-
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic-review',allowed:true,available:true,contexts:['review-one','review-two'],
|
|
78
|
-
run:async(request,{onEvent})=>{f.reviews.push(request.payload.reviewPackage);
|
|
79
|
-
onEvent({event:'thread.started',provider_thread:'actual-review-'+request.identity.attempt});
|
|
80
|
-
onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
|
|
81
|
-
onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
82
|
-
const revise=f.requestRevision&&taskId==='T-002'&&request.identity.attempt===1;
|
|
83
|
-
return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
84
|
-
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
|
|
85
|
-
message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
|
|
86
|
-
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],authorize:(request,{authorizationAt})=>{
|
|
87
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
|
|
88
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
89
|
-
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
|
|
90
|
-
decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
91
|
-
return {...body,grantDigest:digest(body)};
|
|
92
|
-
}},
|
|
93
|
-
check:createHostCheck({cwd:f.codeProject,timeoutMs:1000,commands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}]}),
|
|
94
|
-
taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
|
|
95
|
-
persistence:{store,mode,version:3}});
|
|
96
|
-
return {runner,store,definition:d,close:()=>store.close(),effect:kind=>{
|
|
97
|
-
const identity=runner.status().identity;
|
|
98
|
-
return runner.executeEffect({version:1,id:kind+'-'+identity.attempt,kind,identity,...(kind==='develop'?{
|
|
99
|
-
learningInput:inspectCmAiTaskLearningInput({specsDir:f.specsDir,codeProject:f.codeProject,feature:'0.bootstrap',identity,
|
|
100
|
-
applicableAgentFiles:[]},{admission:runner.inspectBootstrapAdmission()})}:{})});
|
|
101
|
-
}};
|
|
102
|
-
}
|
|
23
|
+
import {workflowRoot,selection,fixture,definition,reply,open} from './fixtures/bootstrap-review-runner.mjs';
|
|
103
24
|
|
|
104
25
|
function prepareCli(f){
|
|
105
26
|
const config=path.join(f.root,'run.json'),bin=path.join(f.root,'bin');fs.mkdirSync(bin);
|
|
@@ -143,7 +64,9 @@ function runCli(f,config,mode,operation){
|
|
|
143
64
|
if(row.type==='host_ready')sessionId=row.sessionId;
|
|
144
65
|
if(row.type==='host_request'){
|
|
145
66
|
calls.push(row.kind);let response;
|
|
146
|
-
if(['init_generate','init_verify'].includes(row.kind)){assert
|
|
67
|
+
if(['init_generate','init_verify'].includes(row.kind)){assert(mode==='create'||f.resumeInit);
|
|
68
|
+
response=reply(f,row.kind,row.payload);
|
|
69
|
+
if(row.kind==='init_verify'&&f.failVerify>0){f.failVerify--;response.checks.commands={status:'failed',evidence:'npm test exited 1'};}}
|
|
147
70
|
else if(row.kind==='qa_assess')response={scores:{scope:5,risk:5,accumulation:5,boundary:5},
|
|
148
71
|
changes:{api:false,migration:false,authentication:false,authorization:false,payment:false}};
|
|
149
72
|
else if(row.kind==='documentation_inspect'){
|
|
@@ -211,8 +134,8 @@ test('bootstrap denies missing authority before intent and a newly authorized la
|
|
|
211
134
|
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
212
135
|
});
|
|
213
136
|
|
|
214
|
-
for(const scenario of ['existing-instructions','
|
|
215
|
-
test('rules task preserves files
|
|
137
|
+
for(const scenario of ['existing-instructions','target-drift'])
|
|
138
|
+
test('rules task preserves files on conflict: '+scenario,{timeout:5000},async t=>{
|
|
216
139
|
const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
|
|
217
140
|
// A previously accepted scaffold is test setup, not a second execution path.
|
|
218
141
|
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('[ ] T-001','[x] T-001'));
|
|
@@ -227,10 +150,172 @@ test('rules task preserves files and original unknown outcome: '+scenario,{timeo
|
|
|
227
150
|
}
|
|
228
151
|
return response;
|
|
229
152
|
}});
|
|
230
|
-
const
|
|
153
|
+
const expected=scenario==='existing-instructions'?'blocked':'unknown';
|
|
154
|
+
const result=await run.effect('develop');assert.equal(result.state,expected);run.close();
|
|
155
|
+
if(scenario==='existing-instructions'){
|
|
156
|
+
assert.equal(result.code,'bootstrap_instruction_conflict');
|
|
157
|
+
assert.equal(result.calls.length,0);
|
|
158
|
+
}
|
|
231
159
|
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
232
|
-
|
|
233
|
-
else assert.match(fs.readFileSync(agents,'utf8'),/user|User/);
|
|
160
|
+
assert.match(fs.readFileSync(agents,'utf8'),/user|User/);
|
|
234
161
|
const before=[...f.calls],resumed=open(f,'T-002','resume');
|
|
235
|
-
assert.equal(resumed.runner.status().state,
|
|
162
|
+
assert.equal(resumed.runner.status().state,expected);resumed.close();assert.deepEqual(f.calls,before);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test('completed same-feature rules task refreshes committed rules and replays its evidence',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
166
|
+
const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
|
|
167
|
+
fs.appendFileSync(tasks,'- [ ] T-010: 同步 AGENTS.md 与 .claude/ 规则\n');
|
|
168
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:['0.bootstrap'],
|
|
169
|
+
specFiles:buildManifest(f.specsDir)}));
|
|
170
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
171
|
+
f.lesson=true;
|
|
172
|
+
run=open(f,'T-002');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
173
|
+
const git=(...args)=>{const result=spawnSync('git',args,{cwd:f.codeProject,encoding:'utf8'});
|
|
174
|
+
assert.equal(result.status,0,result.stderr);return result.stdout.trim();};
|
|
175
|
+
git('init','-q');git('config','user.email','fixture@example.test');git('config','user.name','Fixture');
|
|
176
|
+
git('add','.');git('commit','-qm','Committed bootstrap rules');
|
|
177
|
+
const previous=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
178
|
+
assert.match(previous,/## 项目教训/);
|
|
179
|
+
const testing=path.join(f.codeProject,'.claude/rules/testing.md');
|
|
180
|
+
const committedTesting=fs.readFileSync(testing,'utf8');
|
|
181
|
+
fs.writeFileSync(testing,'# Staged rules drift\n');git('add','--','.claude/rules/testing.md');
|
|
182
|
+
fs.writeFileSync(testing,committedTesting);
|
|
183
|
+
const callsBefore=f.calls.length;
|
|
184
|
+
run=open(f,'T-010','create');
|
|
185
|
+
const blocked=await run.effect('develop');
|
|
186
|
+
assert.equal(blocked.state,'blocked');assert.equal(blocked.code,'bootstrap_instruction_conflict');
|
|
187
|
+
assert.equal(f.calls.length,callsBefore);run.close();
|
|
188
|
+
git('reset','-q','--','.claude/rules/testing.md');
|
|
189
|
+
run=open(f,'T-010','resume',{reply:(kind,payload)=>{
|
|
190
|
+
const answer=reply(f,kind,payload);
|
|
191
|
+
if(kind==='init_generate')answer.documents=answer.documents.map(document=>({path:document.path,
|
|
192
|
+
content:document.path==='AGENTS.md'?'# Refreshed rules\n\nNew invariant.\n'
|
|
193
|
+
:document.path==='.claude/rules/security.md'?fs.readFileSync(path.join(f.codeProject,document.path),'utf8')
|
|
194
|
+
:document.content+'Refreshed.\n'}));
|
|
195
|
+
return answer;
|
|
196
|
+
}});
|
|
197
|
+
assert.equal((await run.effect('develop','-after-restore')).state,'awaiting_review');
|
|
198
|
+
const pkg=run.runner.status().packageDigest;
|
|
199
|
+
assert(pkg);assert.equal(run.store.snapshot().records.at(-1).payload.checkpoint.reviewPackage.changes.length,5);
|
|
200
|
+
assert.deepEqual(run.store.snapshot().records.at(-1).payload.checkpoint.reviewPackage.unchangedScope,
|
|
201
|
+
[{path:'.claude/rules/security.md',sha256:run.store.snapshot().records.at(-1).payload.checkpoint.learningResult.bootstrap.files
|
|
202
|
+
.find(file=>file.path==='.claude/rules/security.md').afterSha256}]);run.close();
|
|
203
|
+
const refreshed=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
204
|
+
assert.match(refreshed,/# Refreshed rules/);
|
|
205
|
+
assert(refreshed.includes(previous.slice(previous.indexOf('## 项目教训'))));
|
|
206
|
+
run=open(f,'T-010','resume');assert.equal(run.runner.status().state,'awaiting_review');
|
|
207
|
+
assert.equal((await run.effect('review')).state,'approved');
|
|
208
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
test('bootstrap review mismatch blocks and rejects recovery when handoff content no longer matches',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
212
|
+
const f=fixture(t);
|
|
213
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
214
|
+
const security=path.join(f.codeProject,'.claude/rules/security.md');
|
|
215
|
+
let originalSecurity;
|
|
216
|
+
run=open(f,'T-002','create',{afterCheck:()=>{originalSecurity=fs.readFileSync(security);
|
|
217
|
+
fs.writeFileSync(security,'# Concurrent drift\n');}});
|
|
218
|
+
const blocked=await run.effect('develop');
|
|
219
|
+
assert.equal(blocked.state,'blocked',JSON.stringify(blocked));assert.equal(blocked.code,'bootstrap_review_mismatch');
|
|
220
|
+
assert.equal(run.runner.status().bootstrapReviewRecovery,true);
|
|
221
|
+
const calls=[...f.calls],journalBefore=run.store.snapshot().records.length;
|
|
222
|
+
const evidence=run.store.snapshot().records.at(-1).payload.checkpoint.learningResult.bootstrap;
|
|
223
|
+
const expected=evidence.files.find(file=>file.path==='.claude/rules/security.md').afterSha256;
|
|
224
|
+
run.close();
|
|
225
|
+
fs.writeFileSync(security,originalSecurity);
|
|
226
|
+
assert.equal(createHash('sha256').update(fs.readFileSync(security)).digest('hex'),expected);
|
|
227
|
+
run=open(f,'T-002','resume');
|
|
228
|
+
assert.equal(run.runner.status().state,'blocked');
|
|
229
|
+
const recovered=run.runner.recoverBootstrapReview({allowed:true,reason:'Checked original bootstrap evidence and handoff'});
|
|
230
|
+
assert.equal(recovered.outcome,'rejected');assert.equal(recovered.code,'bootstrap_review_recovery_mismatch');
|
|
231
|
+
assert.equal(run.store.snapshot().records.length,journalBefore);
|
|
232
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const ruleHashes=f=>Object.fromEntries(cmInitRuleTargets(selection).map(file=>{
|
|
236
|
+
const target=path.join(f.codeProject,file);return [file,fs.existsSync(target)?digest(fs.readFileSync(target,'utf8')):null];}));
|
|
237
|
+
const journal=f=>JSON.parse(fs.readFileSync(path.join(f.specsDir,'.reviews','.execution','run-T-002','state.json'),'utf8')).records;
|
|
238
|
+
function rechain(records){
|
|
239
|
+
let previousDigest=null;
|
|
240
|
+
for(const row of records){row.previousDigest=previousDigest;const {digest:old,...body}=row;row.digest=digest(body);previousDigest=row.digest;}
|
|
241
|
+
return records;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
test('round-2 live init_verify that fails blocks retryably and the same attempt redoes it against its recorded rules',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
245
|
+
const f=fixture(t),tasks=path.join(f.specsDir,'0.bootstrap','tasks.md');
|
|
246
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('[ ] T-001','[x] T-001'));
|
|
247
|
+
fs.writeFileSync(path.join(f.codeProject,'app.mjs'),'export const fixture = true;\n');
|
|
248
|
+
f.requestRevision=true;f.lesson=true;
|
|
249
|
+
let failNext=false;const reply2=(kind,payload)=>{
|
|
250
|
+
const response=reply(f,kind,payload);
|
|
251
|
+
if(kind==='init_verify'&&failNext){failNext=false;response.checks.commands={status:'failed',evidence:'npm test exited 1'};
|
|
252
|
+
response.checks.globs={status:'verified',evidence:' '};}
|
|
253
|
+
return response;
|
|
254
|
+
};
|
|
255
|
+
let run=open(f,'T-002','create',{reply:reply2});
|
|
256
|
+
assert.equal((await run.effect('develop')).state,'awaiting_review');
|
|
257
|
+
assert.equal((await run.effect('review')).state,'changes_requested');
|
|
258
|
+
const recorded=ruleHashes(f);assert(Object.values(recorded).every(Boolean));
|
|
259
|
+
failNext=true;
|
|
260
|
+
const blocked=await run.effect('develop');
|
|
261
|
+
assert.equal(blocked.state,'blocked');assert.equal(blocked.code,'bootstrap_verification_failed');
|
|
262
|
+
const status=run.runner.status();
|
|
263
|
+
assert.equal(status.identity.attempt,2);assert.equal(status.state,'blocked');
|
|
264
|
+
assert.match(status.reason,/^bootstrap_verification_failed: .*commands: failed; npm test exited 1.*globs: verified; \(no evidence\)/);
|
|
265
|
+
assert.equal(status.calls.at(-1).failureResult.code,'bootstrap_verification_failed');
|
|
266
|
+
// Nothing was written and the round-1 evidence the retry binds to is kept.
|
|
267
|
+
assert.deepEqual(ruleHashes(f),recorded);assert.equal(f.reviews.length,1);run.close();
|
|
268
|
+
// A resumed process replays the blocked journal and redoes the same attempt.
|
|
269
|
+
run=open(f,'T-002','resume',{reply:reply2});
|
|
270
|
+
assert.equal(run.runner.status().code,'bootstrap_verification_failed');
|
|
271
|
+
const calls=f.calls.length,retried=await run.effect('develop','-retry-1');
|
|
272
|
+
assert.equal(retried.state,'awaiting_review',JSON.stringify(run.runner.status()));
|
|
273
|
+
assert.deepEqual(f.calls.slice(calls),['init_generate','init_verify']);
|
|
274
|
+
assert.equal(run.runner.status().identity.attempt,2);
|
|
275
|
+
assert.equal((await run.effect('review')).state,'approved');
|
|
276
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
277
|
+
assert.equal(f.reviews.length,2);assert.match(fs.readFileSync(path.join(f.codeProject,'.claude','rules','frontend.md'),'utf8'),/Revised for the review findings/);
|
|
278
|
+
const replay=open(f,'T-002','resume');assert.equal(replay.runner.status().state,'fixture_completed');replay.close();
|
|
279
|
+
|
|
280
|
+
// Replay accepts the blocked checkpoint strictly; forged or legacy shapes are judged as before.
|
|
281
|
+
const rows=journal(f),config=rows[0].payload.config;
|
|
282
|
+
const index=rows.findIndex(row=>row.payload.checkpoint?.code==='bootstrap_verification_failed');assert(index>0);
|
|
283
|
+
const blockedState=readRunnerHistory(rechain(structuredClone(rows.slice(0,index+1))),config,3).state;
|
|
284
|
+
assert.equal(blockedState.code,'bootstrap_verification_failed');
|
|
285
|
+
// The retry is admitted through the shared develop budget guard, like every other retryable block.
|
|
286
|
+
assert.equal(developBudgetExhausted(blockedState),false);
|
|
287
|
+
const spent=structuredClone(blockedState.calls.at(-1));
|
|
288
|
+
assert.equal(developBudgetExhausted({...blockedState,calls:[...blockedState.calls,spent,spent]}),true);
|
|
289
|
+
const forged=(change,expected)=>{const records=structuredClone(rows.slice(0,index+1)),checkpoint=records.at(-1).payload.checkpoint;
|
|
290
|
+
change(checkpoint);checkpoint.cache.at(-1).result=runnerStatus(checkpoint,config);
|
|
291
|
+
const replayed=()=>readRunnerHistory(rechain(records),config,3);
|
|
292
|
+
if(expected===null)return replayed();assert.throws(replayed,{code:expected});};
|
|
293
|
+
forged(checkpoint=>{checkpoint.learningResult=null;},'runner_history_mismatch');
|
|
294
|
+
forged(checkpoint=>{checkpoint.code='develop_checks_not_passed';},'runner_transition');
|
|
295
|
+
forged(checkpoint=>{checkpoint.state='awaiting_review';checkpoint.code=null;checkpoint.reason=null;},'runner_learning');
|
|
296
|
+
// The shape an older version wrote for the same answer: an unknown developer call.
|
|
297
|
+
const legacy=forged(checkpoint=>{const call=checkpoint.calls.at(-1);delete call.failureResult;call.terminal='unknown';call.resultDigest=null;
|
|
298
|
+
checkpoint.state='unknown';checkpoint.code='bootstrap_verification_blocked';checkpoint.reason=null;checkpoint.learningResult=null;},null);
|
|
299
|
+
assert.equal(legacy.state.state,'unknown');
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test('current-session host: round-1 init_verify that fails blocks and a resumed advance redoes it in the same run',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
303
|
+
const f=fixture(t);
|
|
304
|
+
const run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
305
|
+
const cli=prepareCli(f);f.failVerify=1;
|
|
306
|
+
const blocked=await runCli(f,cli,'create','advance');
|
|
307
|
+
assert.equal(blocked.code,0,blocked.stderr);
|
|
308
|
+
assert.equal(blocked.result.state,'blocked',JSON.stringify(blocked.result));assert.equal(blocked.result.code,'bootstrap_verification_failed');
|
|
309
|
+
assert.equal(blocked.result.pendingAction,'resume');
|
|
310
|
+
assert.deepEqual(f.calls,['init_generate','init_verify']);
|
|
311
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'AGENTS.md')),false);assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
312
|
+
f.resumeInit=true;
|
|
313
|
+
const completed=await runCli(f,cli,'resume','advance');
|
|
314
|
+
assert.equal(completed.code,0,completed.stderr);assert.equal(completed.result.state,'run_done',JSON.stringify(completed.result));
|
|
315
|
+
assert.deepEqual(f.calls,['init_generate','init_verify','init_generate','init_verify']);
|
|
316
|
+
// One run: the blocked develop and the redone one share its journal.
|
|
317
|
+
assert.deepEqual(fs.readdirSync(path.join(f.specsDir,'.reviews','.execution')).filter(name=>name.startsWith('run-')),['run-T-001','run-T-002']);
|
|
318
|
+
assert(journal(f).some(row=>row.payload.checkpoint?.code==='bootstrap_verification_failed'));
|
|
319
|
+
const status=await runCli(f,cli,'resume','status');assert.equal(status.code,0,status.stderr);
|
|
320
|
+
assert.equal(status.result.state,'fixture_completed');assert.deepEqual(status.calls,[]);
|
|
236
321
|
});
|
|
@@ -10,6 +10,7 @@ import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
|
10
10
|
const identity={repositoryId:'fixture',runId:'conversation-ops',taskId:'T-001',attempt:1};
|
|
11
11
|
const packageDigest='8'.repeat(64);
|
|
12
12
|
const operation=(name,requestId=name)=>({version:1,operation:name,requestId,identity,packageDigest,testRunId:null});
|
|
13
|
+
const control=name=>({version:1,operation:name,requestId:name,identity});
|
|
13
14
|
|
|
14
15
|
async function fixture(run){
|
|
15
16
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-conversation-ops-')));
|
|
@@ -21,18 +22,94 @@ async function fixture(run){
|
|
|
21
22
|
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature]}));
|
|
22
23
|
fs.writeFileSync(path.join(codeProject,'README.md'),'existing project\n');
|
|
23
24
|
let current={state:'ready',code:null,identity,packageDigest},effects=0;
|
|
24
|
-
|
|
25
|
+
let execute=async()=>{throw Error('unexpected runner effect');};
|
|
26
|
+
const runner={status:()=>current,executeEffect:async effect=>{effects++;return execute(effect);},
|
|
25
27
|
cancel:()=>current,run:async()=>current};
|
|
26
28
|
const entry=extra=>createCmAiConversationEntry({specsDir,codeProject,feature,identity,runner,
|
|
27
29
|
applicableAgentFiles:[],...extra});
|
|
28
30
|
const complete=()=>{current={...current,state:'fixture_completed'};};
|
|
31
|
+
const setStatus=(state,code,reason)=>{current={...current,state,code,...(reason?{reason}:{})};};
|
|
29
32
|
const seedQa=()=>recordCmAiQaDecision({specsDir,codeProject,feature,identity,packageDigest,
|
|
30
33
|
logHome:path.join(root,'logs'),decision:{decisionId:'qa-skipped',identity,packageDigest,
|
|
31
34
|
status:'skipped',reason:'fixture',score:4,at:'2026-09-04T15:10:00-07:00'}});
|
|
32
|
-
try{return await run({root,specsDir,codeProject,entry,complete,seedQa,effects:()=>effects
|
|
35
|
+
try{return await run({root,specsDir,codeProject,entry,complete,setStatus,seedQa,effects:()=>effects,
|
|
36
|
+
setExecutor:fn=>{execute=fn;},setCompletionBlocks:fn=>{runner.completionBlocks=fn;},status:()=>current});}
|
|
33
37
|
finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
34
38
|
}
|
|
35
39
|
|
|
40
|
+
test('A4 completion retry routes a new effect id through the same run',()=>fixture(async f=>{
|
|
41
|
+
f.setStatus('blocked','completion_checks_changed');f.setCompletionBlocks(()=>1);
|
|
42
|
+
let expectedId='complete-1-retry-1';
|
|
43
|
+
f.setExecutor(effect=>{
|
|
44
|
+
assert.equal(effect.kind,'complete');assert.equal(effect.id,expectedId);
|
|
45
|
+
f.setStatus('fixture_completed',null);return f.status();
|
|
46
|
+
});
|
|
47
|
+
const entry=f.entry(),before=await entry.handle(control('status'));
|
|
48
|
+
assert.equal(before.pendingAction,'complete');
|
|
49
|
+
const result=await entry.handle({version:1,operation:'complete',requestId:'complete',identity,packageDigest});
|
|
50
|
+
assert.equal(result.state,'fixture_completed',JSON.stringify(result));assert.equal(f.effects(),1);
|
|
51
|
+
f.setStatus('blocked','completion_checks_changed');f.setCompletionBlocks(()=>2);
|
|
52
|
+
expectedId='complete-1-retry-2';
|
|
53
|
+
await entry.handle(control('advance'));
|
|
54
|
+
assert.equal(f.effects(),2);
|
|
55
|
+
}));
|
|
56
|
+
|
|
57
|
+
test('check output block reaches operator status with paths and resume action',()=>fixture(async f=>{
|
|
58
|
+
f.setStatus('blocked','check_output_out_of_scope','out_of_scope: build/product');
|
|
59
|
+
const result=await f.entry().handle(control('status'));
|
|
60
|
+
assert.equal(result.code,'check_output_out_of_scope');
|
|
61
|
+
assert.equal(result.pendingAction,'resume');
|
|
62
|
+
assert.equal(result.reason,'out_of_scope: build/product');
|
|
63
|
+
assert.equal(result.guidance.recoveryOperation,'advance');assert.match(result.guidance.nextStep,/保留用户改动/);
|
|
64
|
+
assert.equal(f.effects(),0);
|
|
65
|
+
}));
|
|
66
|
+
|
|
67
|
+
test('in-flight status explains waiting and never offers abandonment or another developer dispatch',()=>fixture(async f=>{
|
|
68
|
+
f.setStatus('blocked','completion_checks_changed');f.setCompletionBlocks(()=>1);let release;
|
|
69
|
+
const started=new Promise(resolve=>{release=resolve;});let enter;
|
|
70
|
+
const entered=new Promise(resolve=>{enter=resolve;});
|
|
71
|
+
f.setExecutor(async()=>{f.setStatus('unknown','execution_error');enter();await started;return f.status();});
|
|
72
|
+
const entry=f.entry(),active=entry.handle({version:1,operation:'complete',requestId:'complete',identity,packageDigest});await entered;
|
|
73
|
+
const status=await entry.handle(control('status'));
|
|
74
|
+
assert.equal(status.guidance.recoveryOperation,null);assert.match(status.guidance.summary,/仍有操作在执行/);
|
|
75
|
+
assert.equal(f.effects(),1);release();await active;
|
|
76
|
+
const idle=await entry.handle(control('status'));
|
|
77
|
+
assert.match(idle.guidance.nextStep,/只读核对/);assert.equal(f.effects(),1);
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
test('review package drift reports paths and suppresses refused decision and completion actions',()=>fixture(async f=>{
|
|
81
|
+
f.setStatus('blocked','review_package_changed','out_of_scope: App.xcodeproj/user.xcuserstate');
|
|
82
|
+
const entry=f.entry();const status=await entry.handle(control('status'));
|
|
83
|
+
assert.equal(status.pendingAction,'none');assert.match(status.reason,/xcuserstate/);
|
|
84
|
+
for(const operation of ['decision','complete']){
|
|
85
|
+
const result=await entry.handle({version:1,operation,requestId:operation,identity,packageDigest});
|
|
86
|
+
assert.equal(result.outcome,'rejected');assert.equal(result.code,'review_package_changed');
|
|
87
|
+
assert.match(result.reason,/xcuserstate/);
|
|
88
|
+
}
|
|
89
|
+
assert.equal(f.effects(),0);
|
|
90
|
+
}));
|
|
91
|
+
|
|
92
|
+
test('completion package drift advertises complete retry and uses a fresh effect id',()=>fixture(async f=>{
|
|
93
|
+
f.setStatus('blocked','completion_package_changed','out_of_scope: unexpected.txt');
|
|
94
|
+
f.setCompletionBlocks(()=>1);
|
|
95
|
+
f.setExecutor(effect=>{
|
|
96
|
+
assert.equal(effect.id,'complete-1-retry-1');f.setStatus('fixture_completed',null);return f.status();
|
|
97
|
+
});
|
|
98
|
+
const entry=f.entry();assert.equal((await entry.handle(control('status'))).pendingAction,'complete');
|
|
99
|
+
assert.equal((await entry.handle({version:1,operation:'complete',requestId:'complete',identity,packageDigest})).state,'fixture_completed');
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
test('completion package drift keeps complete unavailable until cleanup',()=>fixture(async f=>{
|
|
103
|
+
f.setStatus('blocked','completion_package_changed','out_of_scope: unexpected.txt');
|
|
104
|
+
const entry=f.entry({});
|
|
105
|
+
const current=f.status();current.retryReady=false;
|
|
106
|
+
const status=await entry.handle(control('status'));
|
|
107
|
+
assert.equal(status.pendingAction,'none');
|
|
108
|
+
const refused=await entry.handle({version:1,operation:'complete',requestId:'complete',identity,packageDigest});
|
|
109
|
+
assert.equal(refused.outcome,'rejected');assert.equal(refused.code,'completion_package_changed');
|
|
110
|
+
assert.match(refused.reason,/unexpected.txt/);assert.equal(f.effects(),0);
|
|
111
|
+
}));
|
|
112
|
+
|
|
36
113
|
test('context_refresh requires a completed task and returns its bound context summary',()=>fixture(async f=>{
|
|
37
114
|
const request=operation('context_refresh');
|
|
38
115
|
assert.equal((await f.entry().handle(request)).code,'context_not_ready');
|
|
@@ -47,6 +124,24 @@ test('context_refresh requires a completed task and returns its bound context su
|
|
|
47
124
|
assert.equal(f.effects(),0);
|
|
48
125
|
}));
|
|
49
126
|
|
|
127
|
+
test('idle unknown cancel reports unchanged durable state',()=>fixture(async f=>{
|
|
128
|
+
f.setStatus('unknown','reconciliation_required');
|
|
129
|
+
const entry=f.entry(),result=await entry.handle(control('cancel'));
|
|
130
|
+
assert.equal(result.outcome,'reported');
|
|
131
|
+
assert.equal(result.state,'unknown');
|
|
132
|
+
assert.equal(result.code,'reconciliation_required');
|
|
133
|
+
assert.equal(result.pendingAction,'reconcile');
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
test('cancel stops an in-flight advance on a completed runner',()=>fixture(async f=>{
|
|
137
|
+
f.complete();
|
|
138
|
+
const entry=f.entry(),advance=entry.handle(control('advance'));
|
|
139
|
+
const cancelled=await entry.handle(control('cancel'));
|
|
140
|
+
assert.equal(cancelled.outcome,'cancelled');
|
|
141
|
+
assert.equal(cancelled.state,'fixture_completed');
|
|
142
|
+
assert.equal((await advance).code,'cancelled');
|
|
143
|
+
}));
|
|
144
|
+
|
|
50
145
|
test('run_finalize requires documentation sync and returns the final outcome without runner effects',()=>fixture(async f=>{
|
|
51
146
|
f.complete();f.seedQa();
|
|
52
147
|
const refresh=await f.entry().handle(operation('context_refresh'));
|