@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
|
@@ -18,6 +18,8 @@ test(`real multi-task runner keeps QA and recovery authoritative: ${mode}`,()=>b
|
|
|
18
18
|
|
|
19
19
|
for(const mode of ['parallel','parallel-retry','parallel-conflict','parallel-resume'])
|
|
20
20
|
test(`parallel batch runs real isolated members: ${mode}`,()=>batchFixture(mode));
|
|
21
|
+
test('A4 parallel member retries changed completion checks in its original run',()=>batchFixture('parallel-completion-retry'));
|
|
22
|
+
test('D1 parallel member retries failed develop checks before review',()=>batchFixture('parallel-develop-check-retry'));
|
|
21
23
|
|
|
22
24
|
test('ready member merges before blocked member preserves reason in log and WIP and falls back only once',async()=>{
|
|
23
25
|
for(const withReason of [true,false])await batchFixture('parallel-recovery',{terminalAgain:true,withReason});
|
|
@@ -27,6 +29,8 @@ test('serial fallback resumes from log and automatically commits its completed t
|
|
|
27
29
|
{blockedIds:['T-001']},{blockedIds:['T-001','T-002']}])await batchFixture('parallel-recovery',options);
|
|
28
30
|
});
|
|
29
31
|
test('final serial task commits durably and commit information survives resume',()=>batchFixture('final-commit'));
|
|
32
|
+
test('a batch member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('review-provider-retry'));
|
|
33
|
+
test('a parallel member whose reviewer failed without a verdict resumes its one review retry',()=>batchFixture('parallel-review-provider-retry'));
|
|
30
34
|
test('dirty batch entry lists files and creates no member worktrees',()=>batchFixture('parallel-dirty'));
|
|
31
35
|
|
|
32
36
|
test('parallel groups reject transitive prerequisites, not just direct edges',()=>{
|
|
@@ -95,14 +99,14 @@ async function batchFixture(mode,options={}){
|
|
|
95
99
|
const config={version:1,repositoryId:'batch-fixture',batchId:'batch-fixture',specsDir,codeProject,
|
|
96
100
|
...(parallel?{parallel:[[`${feature}/T-001`,`${feature}/T-002`]]}:{}),
|
|
97
101
|
tasks:(parallel?['T-001','T-002','T-003']:['T-001','T-002']).map((taskId,index)=>({feature,taskId,scope:[`file${index}.js`],requirements:['requirements.md']}))};
|
|
98
|
-
const calls=[],qaCalls=[],assessments=[],blockedEvidence=[];let qaReady=mode!=='qa-resume',started;
|
|
102
|
+
const calls=[],qaCalls=[],assessments=[],blockedEvidence=[],checkCalls=new Map();let qaReady=mode!=='qa-resume',started;
|
|
99
103
|
const began=new Promise(resolve=>{started=resolve;});
|
|
100
|
-
let conflictHead=null,interrupted=false;
|
|
104
|
+
let conflictHead=null,interrupted=false,reviewFailed=false;
|
|
101
105
|
const executionFor=async(definition,{parallelMember=false}={})=>({configuration:{kind:'batch-fixture-v1',...(parallelMember?{parallelMember:true}:{})},timeoutMs:3000,
|
|
102
106
|
excludedContexts:['host'],hostDecision:{status:'approved'},applicableAgentFiles:[],
|
|
103
107
|
developer:{provider:'codex',requestedModel:'fixture',contextId:'author',run:createCodexDeveloperRun({requestedModel:'fixture',
|
|
104
108
|
worker:async({prompt},{signal})=>{
|
|
105
|
-
const
|
|
109
|
+
const data=JSON.parse(prompt.split('<cm-developer-data-json>\n')[1]),material=data.specification;
|
|
106
110
|
assert.equal(material.task.id,definition.identity.taskId);
|
|
107
111
|
assert.deepEqual(material.sources,buildManifest(specsDir));
|
|
108
112
|
if(recovery&&!parallelMember&&blockedIds.includes(definition.identity.taskId)){
|
|
@@ -124,7 +128,9 @@ async function batchFixture(mode,options={}){
|
|
|
124
128
|
assert.equal(fs.readFileSync(path.join(codeProject,config.tasks.find(task=>task.taskId===id).scope[0]),'utf8'),'implemented\n');
|
|
125
129
|
}
|
|
126
130
|
}
|
|
127
|
-
|
|
131
|
+
// A second attempt must change the rejected bytes (develop_unchanged_after_review).
|
|
132
|
+
calls.push(definition.identity.taskId);fs.writeFileSync(path.join(definition.codeProject,definition.scope[0]),
|
|
133
|
+
data.identity.attempt===1?'implemented\n':'implemented again\n');
|
|
128
134
|
if(recovery&&blockedIds.includes(definition.identity.taskId)&&(parallelMember||options.terminalAgain))
|
|
129
135
|
return {status:'succeeded',value:{outcome:'blocked',...(options.withReason?{reason:'Expected stub throws; waiting for peer'}:{})}};
|
|
130
136
|
if(parallel&&definition.identity.taskId==='T-002')await new Promise(resolve=>setTimeout(resolve,50));
|
|
@@ -145,13 +151,26 @@ async function batchFixture(mode,options={}){
|
|
|
145
151
|
}
|
|
146
152
|
return {status:'succeeded',value:{outcome:'implemented',application,retrospective}};
|
|
147
153
|
}})},
|
|
148
|
-
check:async()=>
|
|
154
|
+
check:async()=>{
|
|
155
|
+
const key=definition.identity.taskId,count=(checkCalls.get(key)??0)+1;checkCalls.set(key,count);
|
|
156
|
+
const failed=parallelMember&&key==='T-002'
|
|
157
|
+
&&(mode==='parallel-completion-retry'&&count===2||mode==='parallel-develop-check-retry'&&count===1);
|
|
158
|
+
return [{id:'fixture',command:['fixture'],outcome:failed?'failed':'passed',exitCode:failed?1:0,
|
|
159
|
+
evidence:failed?'Synthetic transient failure':'Synthetic task check'}];
|
|
160
|
+
},
|
|
149
161
|
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',allowed:true,available:true,
|
|
150
162
|
contexts:['review-1','review-2'],run:(request,{onEvent})=>{
|
|
151
163
|
assert.equal(request.payload.reviewPackage.specification.task.id,definition.identity.taskId);
|
|
152
164
|
assert.deepEqual(request.payload.reviewPackage.specification.sources,buildManifest(specsDir));
|
|
153
165
|
if(mode==='learning'&&request.identity.taskId==='T-001')
|
|
154
166
|
assert(request.payload.reviewPackage.changes.some(change=>change.path==='AGENTS.md'));
|
|
167
|
+
if(mode.endsWith('review-provider-retry')&&request.identity.taskId==='T-001'&&!reviewFailed){
|
|
168
|
+
reviewFailed=true;
|
|
169
|
+
// Claude CLI rate limit: no tool call, no verdict, process exited.
|
|
170
|
+
for(const event of [{event:'thread.started',provider_thread:'review-rate-limited'},{event:'turn.started',item_type:null},
|
|
171
|
+
{event:'process_closed',exit_code:1,signal:null,timed_out:false}])onEvent(event);
|
|
172
|
+
return {status:'failed',code:'reviewer_rate_limited'};
|
|
173
|
+
}
|
|
155
174
|
for(const event of [{event:'thread.started',provider_thread:`review-${request.identity.taskId}`},
|
|
156
175
|
{event:'turn.started',item_type:null},{event:'item.completed',item_type:'agent_message'},
|
|
157
176
|
{event:'turn.completed',item_type:null},{event:'process_closed',exit_code:0,signal:null,timed_out:false}])onEvent(event);
|
|
@@ -237,6 +256,33 @@ async function batchFixture(mode,options={}){
|
|
|
237
256
|
const recovered=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
238
257
|
assert.equal(recovered.find(row=>row.phase==='batch_handoff').task_commit,commit.task_commit);
|
|
239
258
|
}
|
|
259
|
+
if(mode==='parallel-completion-retry'){
|
|
260
|
+
assert.equal(result.code,'completion_checks_changed',JSON.stringify(result));
|
|
261
|
+
const logfile=path.join(specsDir,'运行日志.jsonl');
|
|
262
|
+
let rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
263
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
264
|
+
assert(fs.existsSync(path.join(root,'.cm-worktrees',config.batchId.slice(0,8),'T-002')));
|
|
265
|
+
result=await open().handle({operation:'advance',requestId:'retry-completion'});
|
|
266
|
+
assert.equal(result.code,'run_done',JSON.stringify(result));
|
|
267
|
+
rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
268
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
269
|
+
assert.equal(checkCalls.get('T-002'),3);
|
|
270
|
+
assert.deepEqual(calls,['T-001','T-002','T-003']);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
if(mode==='parallel-develop-check-retry'){
|
|
274
|
+
assert.equal(result.code,'develop_checks_not_passed',JSON.stringify(result));
|
|
275
|
+
const logfile=path.join(specsDir,'运行日志.jsonl');
|
|
276
|
+
let rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
277
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
278
|
+
result=await open().handle({operation:'advance',requestId:'retry-develop-check'});
|
|
279
|
+
assert.equal(result.code,'run_done',JSON.stringify(result));
|
|
280
|
+
rows=fs.readFileSync(logfile,'utf8').trim().split('\n').map(JSON.parse);
|
|
281
|
+
assert.equal(rows.filter(row=>row.phase==='batch_member_blocked').length,0);
|
|
282
|
+
assert.equal(checkCalls.get('T-002'),3);
|
|
283
|
+
assert.equal(calls.filter(task=>task==='T-002').length,2);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
240
286
|
if(recovery&&options.crashAt){assert(interrupted);result=await open().handle({operation:'advance',requestId:'resume-recovery'});}
|
|
241
287
|
if(recovery){
|
|
242
288
|
// Assert outside the worker: worker exceptions intentionally become unknown terminals.
|
|
@@ -277,6 +323,11 @@ async function batchFixture(mode,options={}){
|
|
|
277
323
|
for(const task of ['T-001','T-002'])assert.throws(()=>git(codeProject,['rev-parse','--verify',`refs/heads/cm/work/${task}`]));
|
|
278
324
|
return;
|
|
279
325
|
}
|
|
326
|
+
if(mode.endsWith('review-provider-retry')){
|
|
327
|
+
assert.equal(result.state,'pending_review',JSON.stringify(result));assert.equal(result.code,'review_provider_failed');
|
|
328
|
+
assert.match(result.reason,/^reviewer_rate_limited: /);assert.deepEqual(calls,parallel?['T-001','T-002']:['T-001']);
|
|
329
|
+
result=await open().handle({operation:'advance',requestId:'retry-review'});
|
|
330
|
+
}
|
|
280
331
|
if(mode==='qa-resume'){
|
|
281
332
|
assert.equal(result.code,'qa_decision_required');assert.deepEqual(calls,['T-001']);
|
|
282
333
|
assert(fs.readFileSync(path.join(specsDir,feature,'tasks.md'),'utf8').includes('[x] T-001'));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
7
|
+
import {bootstrapDriverGap} from './cm-ai-drive.mjs';
|
|
8
|
+
import {hostResponseFailed} from '../runtime/js/cm-ai/drive-core.mjs';
|
|
9
|
+
|
|
10
|
+
function fixture(t){
|
|
11
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-bootstrap-drive-')));
|
|
12
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
13
|
+
const specsDir=path.join(root,'specs5'),codeProject=path.join(root,'app'),feature='1.bootstrap';
|
|
14
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
15
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# iOS SwiftUI scaffold and rules\n');
|
|
16
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Split specs5/app roots\n');
|
|
17
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范(cm-init)\n');
|
|
18
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
19
|
+
const configuration=path.join(root,'bootstrap.json');
|
|
20
|
+
fs.writeFileSync(configuration,JSON.stringify({selection:{versionControl:'local',modules:[],analysis:'SwiftUI iOS app'}}));
|
|
21
|
+
const definition={specsDir,codeProject,feature,identity:{repositoryId:'app',runId:'t002',taskId:'T-002',attempt:1},
|
|
22
|
+
scope:['AGENTS.md','.claude/CLAUDE.md','.claude/rules/coding-style.md','.claude/rules/testing.md',
|
|
23
|
+
'.claude/rules/security.md','.claude/rules/git-workflow.md']};
|
|
24
|
+
return {configuration,definition};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
test('rules bootstrap is driver-supported for a pure rules scope on first and second attempt',t=>{
|
|
28
|
+
const f=fixture(t),permissions=['--bootstrap-config',f.configuration,'--allow-bootstrap-write'];
|
|
29
|
+
for(const attempt of [1,2])for(const operation of ['advance','start','resume'])
|
|
30
|
+
assert.equal(bootstrapDriverGap(operation,{...f.definition,identity:{...f.definition.identity,attempt}},permissions),null);
|
|
31
|
+
const provider=bootstrapDriverGap('advance',f.definition,[...permissions,'--protected-config','protected.json']);
|
|
32
|
+
assert.match(provider,/--protected-config/);assert.match(provider,/cm-ai-host\.mjs serve/);
|
|
33
|
+
assert.equal(bootstrapDriverGap('advance',{...f.definition,identity:{...f.definition.identity,taskId:'T-001'}},permissions),null);
|
|
34
|
+
assert.equal(bootstrapDriverGap('advance',f.definition,[]),null);
|
|
35
|
+
assert.equal(bootstrapDriverGap('status',f.definition,permissions),null);
|
|
36
|
+
assert.match(bootstrapDriverGap('advance',{...f.definition,identity:{...f.definition.identity,taskId:'T-999'}},permissions),/预检失败.*宿主未启动/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test('unknown and reconcile host responses are failures even when a result is returned',()=>{
|
|
40
|
+
assert.equal(hostResponseFailed({result:{state:'unknown',code:'execution_error',pendingAction:'reconcile'}}),true);
|
|
41
|
+
assert.equal(hostResponseFailed({result:{state:'unknown',code:'execution_error',pendingAction:null}}),true);
|
|
42
|
+
assert.equal(hostResponseFailed({result:{state:'blocked',pendingAction:'reconcile'}}),true);
|
|
43
|
+
assert.equal(hostResponseFailed({result:{state:'awaiting_review',pendingAction:'decision'}}),false);
|
|
44
|
+
assert.equal(hostResponseFailed({error:{code:'invalid_input'}}),true);
|
|
45
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
2
|
+
import test,{after} from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {createHostBootstrap} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
9
|
+
import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
10
|
+
import {createTaskRunner} from '../runtime/js/cm-ai/task-runner.mjs';
|
|
11
|
+
import {openTaskExecutionStore} from '../runtime/js/cm-ai/task-owner.mjs';
|
|
12
|
+
import {createDeveloperRun,validateDeveloperScope} from '../runtime/js/cm-ai/developer-adapter.mjs';
|
|
13
|
+
import {inspectCmAiAdmission} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
14
|
+
import {inspectCmAiContextRefresh,inspectCmAiTaskLearningInput} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
15
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
16
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
17
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
18
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
19
|
+
|
|
20
|
+
// Keep runtime declarations and log mirrors independent of the invoking user's home.
|
|
21
|
+
const isolatedWorkflowHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-ai-bootstrap-home-'));
|
|
22
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedWorkflowHome,'user');
|
|
23
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedWorkflowHome,'logs');
|
|
24
|
+
after(()=>fs.rmSync(isolatedWorkflowHome,{recursive:true,force:true}));
|
|
25
|
+
|
|
26
|
+
const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
|
|
27
|
+
const selection={versionControl:'none',modules:['frontend'],analysis:'Approved synthetic JavaScript project'};
|
|
28
|
+
const checks=()=>Object.fromEntries(['commands','globs','file_references','constraint_preservation','rule_applicability']
|
|
29
|
+
.map(name=>[name,{status:'verified',evidence:'Synthetic semantic report for the local fixture'}]));
|
|
30
|
+
function fixture(t,feature='0.bootstrap'){
|
|
31
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-')));
|
|
32
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
33
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
34
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(path.join(specsDir,'.reviews'));
|
|
35
|
+
fs.writeFileSync(path.join(specsDir,feature,'requirements.md'),'# Requirements\nSynthetic approved scaffold and project instructions.\n');
|
|
36
|
+
fs.writeFileSync(path.join(specsDir,feature,'design.md'),'# Design\nJavaScript; no Git; frontend module.\n');
|
|
37
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [ ] T-001: 生成项目骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 和 .claude/ 规范(cm-init)\n');
|
|
38
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
39
|
+
return {root,codeProject,specsDir,feature,calls:[],reviews:[],businessCalls:0};
|
|
40
|
+
}
|
|
41
|
+
function definition(f,taskId){
|
|
42
|
+
return {version:1,codeProject:f.codeProject,specsDir:f.specsDir,feature:f.feature,
|
|
43
|
+
identity:{repositoryId:'bootstrap-fixture',runId:'run-'+taskId,taskId,attempt:1},
|
|
44
|
+
scope:taskId==='T-001'?['app.mjs']:[...cmInitRuleTargets(selection)],requirements:[]};
|
|
45
|
+
}
|
|
46
|
+
function reply(f,kind,payload){
|
|
47
|
+
f.calls.push(kind);
|
|
48
|
+
if(kind==='init_generate')return {status:'generated',documents:payload.targets.map(file=>({path:file,
|
|
49
|
+
content:file==='AGENTS.md'&&f.replaceAgentsDraft?'# Generated project rules\n':
|
|
50
|
+
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,f.feature,'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(`${f.feature}/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:f.scaffoldLesson?{status:'lesson_candidate',candidates:[{classification:'structured',
|
|
74
|
+
trigger:'T-001 scaffold',action:'Preserve the original Learning section',evidence:['app.mjs']}],reason:null}
|
|
75
|
+
:{status:'no_new_lesson',candidates:[],reason:null}}};
|
|
76
|
+
}})};
|
|
77
|
+
const runner=createTaskRunner({root:f.codeProject,identity:d.identity,scope:d.scope,requirements:d.requirements,bootstrap,
|
|
78
|
+
taskLearning:{feature:f.feature,hostHandoff:true},developer,excludedContexts:['main'],timeoutMs:5000,
|
|
79
|
+
reviewers:[{id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic-review',allowed:true,available:true,contexts:['review-one','review-two'],
|
|
80
|
+
run:async(request,{onEvent})=>{f.reviews.push(request.payload.reviewPackage);
|
|
81
|
+
onEvent({event:'thread.started',provider_thread:'actual-review-'+request.identity.attempt});
|
|
82
|
+
onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
|
|
83
|
+
onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
84
|
+
const revise=f.requestRevision&&taskId==='T-002'&&request.identity.attempt===1;
|
|
85
|
+
return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
86
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
|
|
87
|
+
message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
|
|
88
|
+
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],authorize:(request,{authorizationAt})=>{
|
|
89
|
+
const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
|
|
90
|
+
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
91
|
+
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
|
|
92
|
+
decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
93
|
+
return {...body,grantDigest:digest(body)};
|
|
94
|
+
}},
|
|
95
|
+
check:createHostCheck({cwd:f.codeProject,timeoutMs:1000,commands:[{id:'syntax',command:[process.execPath,'--check','app.mjs']}]}),
|
|
96
|
+
taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
|
|
97
|
+
persistence:{store,mode,version:3}});
|
|
98
|
+
return {runner,store,definition:d,close:()=>store.close(),effect:kind=>{
|
|
99
|
+
const identity=runner.status().identity;
|
|
100
|
+
return runner.executeEffect({version:1,id:kind+'-'+identity.attempt,kind,identity,...(kind==='develop'?{
|
|
101
|
+
learningInput:inspectCmAiTaskLearningInput({specsDir:f.specsDir,codeProject:f.codeProject,feature:f.feature,identity,
|
|
102
|
+
applicableAgentFiles:[]},{admission:runner.inspectBootstrapAdmission()})}:{})});
|
|
103
|
+
}};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
for(const feature of ['1.bootstrap','0.bootstrap'])
|
|
108
|
+
test(`approved ${feature} completes T-001 and T-002 with Learning preserved through fake independent review`,{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
109
|
+
const f=fixture(t,feature);f.scaffoldLesson=true;
|
|
110
|
+
assert.equal(inspectCmAiAdmission(f).nextTask.feature,feature);
|
|
111
|
+
let run=open(f,'T-001');assert.equal((await run.effect('develop')).state,'awaiting_review');
|
|
112
|
+
const before=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
113
|
+
const lesson=before.slice(before.indexOf('## 项目教训'));
|
|
114
|
+
assert.match(lesson,/T-001 scaffold/);run.close();
|
|
115
|
+
run=open(f,'T-001','resume');assert.equal((await run.effect('review')).state,'approved');
|
|
116
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
117
|
+
f.replaceAgentsDraft=true;
|
|
118
|
+
run=open(f,'T-002','create',{allowWrite:false});
|
|
119
|
+
assert.deepEqual(await run.effect('develop'),{outcome:'rejected',code:'bootstrap_write_authorization_required'});
|
|
120
|
+
run.close();
|
|
121
|
+
run=open(f,'T-002','resume');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
|
|
122
|
+
const after=fs.readFileSync(path.join(f.codeProject,'AGENTS.md'),'utf8');
|
|
123
|
+
assert(after.includes(lesson));assert.match(after,/# Generated project rules/);
|
|
124
|
+
assert(fs.existsSync(path.join(f.codeProject,'.claude','CLAUDE.md')));
|
|
125
|
+
assert(fs.existsSync(path.join(f.codeProject,'.claude','rules','testing.md')));
|
|
126
|
+
assert.throws(()=>validateDeveloperScope(['AGENTS.md']),{code:'protected_scope'});
|
|
127
|
+
run=open(f,'T-002','resume');assert.equal((await run.effect('review')).state,'approved');
|
|
128
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
129
|
+
assert.equal(f.reviews.length,2);
|
|
130
|
+
assert.match(fs.readFileSync(path.join(f.specsDir,feature,'tasks.md'),'utf8'),/\[x\] T-002/);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('numbered bootstrap blocks pre-existing non-Learning instructions before dispatch',async t=>{
|
|
134
|
+
const f=fixture(t,'1.bootstrap');
|
|
135
|
+
let run=open(f,'T-001');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
|
|
136
|
+
run=open(f,'T-001','resume');assert.equal((await run.effect('review')).state,'approved');
|
|
137
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
138
|
+
const agents=path.join(f.codeProject,'AGENTS.md');fs.writeFileSync(agents,'# Existing user rules\n');
|
|
139
|
+
run=open(f,'T-002');const result=await run.effect('develop');run.close();
|
|
140
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'bootstrap_instruction_conflict');
|
|
141
|
+
assert.equal(result.calls.length,0);
|
|
142
|
+
assert.equal(fs.readFileSync(agents,'utf8'),'# Existing user rules\n');
|
|
143
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('Learning appearing after the task baseline cannot be adopted as bootstrap input',async t=>{
|
|
147
|
+
const f=fixture(t,'1.bootstrap');
|
|
148
|
+
let run=open(f,'T-001');assert.equal((await run.effect('develop')).state,'awaiting_review');run.close();
|
|
149
|
+
run=open(f,'T-001','resume');assert.equal((await run.effect('review')).state,'approved');
|
|
150
|
+
assert.equal((await run.effect('complete')).state,'fixture_completed');run.close();
|
|
151
|
+
run=open(f,'T-002');
|
|
152
|
+
const agents=path.join(f.codeProject,'AGENTS.md');fs.writeFileSync(agents,'## 项目教训\n\n- late change\n');
|
|
153
|
+
const result=await run.effect('develop');run.close();
|
|
154
|
+
assert.equal(result.outcome,'rejected');
|
|
155
|
+
assert.equal(result.code,'package_mismatch');
|
|
156
|
+
assert.match(result.reason,/AGENTS\.md/);
|
|
157
|
+
assert.equal(fs.existsSync(path.join(f.codeProject,'.claude')),false);
|
|
158
|
+
assert.equal(fs.readFileSync(agents,'utf8'),'## 项目教训\n\n- late change\n');
|
|
159
|
+
});
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
9
|
+
import {createHostBootstrap,mergeBootstrapAgents,validateBootstrapReviewPackage} from '../runtime/js/cm-ai/host-bootstrap.mjs';
|
|
10
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
11
|
+
import {bootstrapReviewRecoverable} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
12
|
+
import {cmInitRuleTargets} from '../runtime/js/cm-init/draft-generation.mjs';
|
|
13
|
+
|
|
14
|
+
const workflowRoot=fileURLToPath(new URL('..',import.meta.url)).replace(/\/$/,'');
|
|
15
|
+
const selection={versionControl:'none',modules:[],analysis:'Fixture project'};
|
|
16
|
+
|
|
17
|
+
test('bootstrap AGENTS merge preserves existing Learning bytes and other constraints',()=>{
|
|
18
|
+
const lesson='## 项目教训\r\n\r\n- **T-001 lesson**:原样保留。\r\n';
|
|
19
|
+
const existing='# Existing rule\r\n\r\n'+lesson;
|
|
20
|
+
const generated='# Generated rules\n\n# Existing rule\r\n\r\n';
|
|
21
|
+
const merged=mergeBootstrapAgents(existing,generated);
|
|
22
|
+
assert(merged.includes('# Existing rule\r\n\r\n'));
|
|
23
|
+
assert(merged.includes(lesson));
|
|
24
|
+
assert.equal(merged.split(lesson).length,2);
|
|
25
|
+
assert.throws(()=>mergeBootstrapAgents(existing,'# Generated rules\n'),{code:'bootstrap_instruction_conflict'});
|
|
26
|
+
assert.throws(()=>mergeBootstrapAgents(existing,generated+'## 项目教训\n- changed\n'),{code:'bootstrap_instruction_conflict'});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('approved rule refresh replaces the rule body but preserves Learning bytes',()=>{
|
|
30
|
+
const lesson='## 项目教训\r\n\r\n- **Earlier lesson**:逐字保留。\r\n';
|
|
31
|
+
const existing='# Old rules\r\n\r\n'+lesson;
|
|
32
|
+
const generated='# Updated rules\n\nNew approved invariant.\n';
|
|
33
|
+
assert.equal(mergeBootstrapAgents(existing,generated,{refresh:true}),generated+'\n'+lesson);
|
|
34
|
+
assert.throws(()=>mergeBootstrapAgents(existing,generated+'\n## 项目教训\n- rewritten\n',{refresh:true}),
|
|
35
|
+
{code:'bootstrap_instruction_conflict'});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test('bootstrap review requires a changed entry only when the final target differs from its original bytes',()=>{
|
|
39
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt:1};
|
|
40
|
+
const paths=['AGENTS.md','.claude/rules/security.md'];
|
|
41
|
+
const original='a'.repeat(64),updated='b'.repeat(64);
|
|
42
|
+
const configuration={instructionPaths:paths};
|
|
43
|
+
const body={version:1,workflow:'cm-ai',phase:'bootstrap_instructions',identity,invocationId:'fixture-invocation',
|
|
44
|
+
configurationDigest:digest(configuration),files:[
|
|
45
|
+
{path:paths[0],beforeSha256:original,afterSha256:updated},
|
|
46
|
+
{path:paths[1],beforeSha256:original,afterSha256:original}],
|
|
47
|
+
contextFiles:[{scope:'project',path:paths[0],sha256:updated},
|
|
48
|
+
{scope:'project',path:paths[1],sha256:original}]};
|
|
49
|
+
const evidence={...body,evidenceDigest:digest(body)};
|
|
50
|
+
const pkg={scope:paths,changes:[{path:paths[0],before:{sha256:original},after:{sha256:updated}}],
|
|
51
|
+
unchangedScope:[{path:paths[1],sha256:original}]};
|
|
52
|
+
const writeback={outcome:'no_new_lesson'};
|
|
53
|
+
assert.doesNotThrow(()=>validateBootstrapReviewPackage(pkg,evidence,configuration,identity,writeback));
|
|
54
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,changes:[]},evidence,configuration,identity,writeback),
|
|
55
|
+
{code:'bootstrap_review_mismatch'});
|
|
56
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,scope:[paths[0]]},evidence,configuration,identity,writeback),
|
|
57
|
+
{code:'bootstrap_review_mismatch'});
|
|
58
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,unchangedScope:[]},evidence,configuration,identity,writeback),
|
|
59
|
+
{code:'bootstrap_review_mismatch'});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
for(const attempt of [1,2])test(`attempt ${attempt} retry may restore a written rule to the original baseline`,()=>{
|
|
63
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt};
|
|
64
|
+
const paths=['AGENTS.md','.claude/rules/security.md'];
|
|
65
|
+
const original='a'.repeat(64),updated='b'.repeat(64);
|
|
66
|
+
const configuration={instructionPaths:paths};
|
|
67
|
+
const body={version:1,workflow:'cm-ai',phase:'bootstrap_instructions',identity,invocationId:'second-attempt',
|
|
68
|
+
configurationDigest:digest(configuration),files:[
|
|
69
|
+
{path:paths[0],beforeSha256:original,afterSha256:updated},
|
|
70
|
+
{path:paths[1],beforeSha256:updated,afterSha256:original}],
|
|
71
|
+
contextFiles:[{scope:'project',path:paths[0],sha256:updated},
|
|
72
|
+
{scope:'project',path:paths[1],sha256:original}]};
|
|
73
|
+
const pkg={scope:paths,changes:[{path:paths[0],before:{sha256:original},after:{sha256:updated}}],
|
|
74
|
+
unchangedScope:[{path:paths[1],sha256:original}]};
|
|
75
|
+
assert.doesNotThrow(()=>validateBootstrapReviewPackage(pkg,{...body,evidenceDigest:digest(body)},
|
|
76
|
+
configuration,identity,{outcome:'no_new_lesson'}));
|
|
77
|
+
assert.throws(()=>validateBootstrapReviewPackage({...pkg,unchangedScope:[{path:paths[1],sha256:updated}]},
|
|
78
|
+
{...body,evidenceDigest:digest(body)},configuration,identity,{outcome:'no_new_lesson'}),
|
|
79
|
+
{code:'bootstrap_review_mismatch'});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test('only a completed bootstrap develop with retained passing evidence offers local review recovery',()=>{
|
|
83
|
+
const state={state:'unknown',code:'execution_error',attempt:1,reviewPackage:null,receipt:null,reviewInvocation:null,
|
|
84
|
+
calls:[{terminal:'succeeded'}],currentChecks:[{kind:'command',outcome:'passed',exitCode:0}],
|
|
85
|
+
learningResult:{bootstrap:{files:[]},writeback:{outcome:'no_new_lesson'}},
|
|
86
|
+
cache:[{effect:{kind:'develop',identity:{attempt:1}},result:{state:'unknown',code:'execution_error'}}]};
|
|
87
|
+
const bootstrap={mode:'instructions'};
|
|
88
|
+
assert.equal(bootstrapReviewRecoverable(state,null,bootstrap),true);
|
|
89
|
+
assert.equal(bootstrapReviewRecoverable({...state,reviewPackage:{}},null,bootstrap),false);
|
|
90
|
+
assert.equal(bootstrapReviewRecoverable({...state,currentChecks:[{kind:'command',outcome:'failed',exitCode:1}]},null,bootstrap),false);
|
|
91
|
+
assert.equal(bootstrapReviewRecoverable(state,{kind:'develop'},bootstrap),false);
|
|
92
|
+
assert.equal(bootstrapReviewRecoverable({...state,state:'unknown',code:'reconciliation_required'},null,bootstrap),false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test('later same-feature rules task binds clean committed targets and rejects drift',t=>{
|
|
96
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-refresh-')));
|
|
97
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
98
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.bootstrap';
|
|
99
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
100
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Approved fixture\n');
|
|
101
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: 生成骨架 scaffold\n- [x] T-002: 生成 AGENTS.md 与 .claude/ 规则\n- [ ] T-010: 同步 AGENTS.md 与 .claude/ 规则\n');
|
|
102
|
+
const targets=cmInitRuleTargets(selection);
|
|
103
|
+
for(const file of targets){const target=path.join(codeProject,file);fs.mkdirSync(path.dirname(target),{recursive:true});
|
|
104
|
+
fs.writeFileSync(target,file==='AGENTS.md'?'# Existing rules\n\n## 项目教训\n\n- Prior lesson\n':'# Existing rules\n');}
|
|
105
|
+
const git=(...args)=>{const result=spawnSync('git',args,{cwd:codeProject,encoding:'utf8'});
|
|
106
|
+
assert.equal(result.status,0,result.stderr);return result.stdout.trim();};
|
|
107
|
+
git('init','-q');git('config','user.email','fixture@example.test');git('config','user.name','Fixture');
|
|
108
|
+
git('add','--',...targets);git('commit','-qm','Bootstrap rules');
|
|
109
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
110
|
+
const identity={repositoryId:'fixture',runId:'refresh',taskId:'T-010',attempt:1};
|
|
111
|
+
const definition={version:1,specsDir,codeProject,feature,identity,scope:targets,requirements:[]};
|
|
112
|
+
const bootstrap=createHostBootstrap({definition,workflowRoot,selection,bridge:{call:async()=>{throw Error('unused');}},allowWrite:true});
|
|
113
|
+
assert.equal(bootstrap.configuration.committedBasis.commit,git('rev-parse','HEAD'));
|
|
114
|
+
assert.deepEqual(bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}).originals.map(x=>x.path),targets);
|
|
115
|
+
fs.writeFileSync(path.join(codeProject,'.claude/rules/testing.md'),'# Uncommitted change\n');
|
|
116
|
+
assert.throws(()=>bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
117
|
+
{code:'bootstrap_instruction_conflict'});
|
|
118
|
+
git('add','--','.claude/rules/testing.md');
|
|
119
|
+
fs.writeFileSync(path.join(codeProject,'.claude/rules/testing.md'),'# Existing rules\n');
|
|
120
|
+
assert.throws(()=>bootstrap.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
121
|
+
{code:'bootstrap_instruction_conflict'});
|
|
122
|
+
const unavailable=createHostBootstrap({definition,workflowRoot,selection,
|
|
123
|
+
bridge:{call:async()=>{throw Error('unused');}},allowWrite:true});
|
|
124
|
+
assert.equal(unavailable.configuration.committedBasisRequired,true);
|
|
125
|
+
assert.deepEqual(unavailable.configuration.committedBasis,bootstrap.configuration.committedBasis);
|
|
126
|
+
assert.throws(()=>unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null}),
|
|
127
|
+
{code:'bootstrap_instruction_conflict'});
|
|
128
|
+
git('reset','-q','--','.claude/rules/testing.md');
|
|
129
|
+
assert.deepEqual(unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null})
|
|
130
|
+
.originals.map(item=>item.path),targets);
|
|
131
|
+
const marker=path.join(root,'git-config-executed'),driver=path.join(root,'git-driver');
|
|
132
|
+
fs.writeFileSync(driver,`#!/bin/sh\ntouch '${marker}'\ncat\n`,{mode:0o700});
|
|
133
|
+
fs.writeFileSync(path.join(codeProject,'.gitattributes'),'AGENTS.md filter=probe\n');
|
|
134
|
+
git('config','core.fsmonitor',driver);
|
|
135
|
+
git('config','filter.probe.clean',driver);
|
|
136
|
+
git('config','filter.probe.process',driver);
|
|
137
|
+
git('config','filter.probe.required','true');
|
|
138
|
+
assert.deepEqual(unavailable.assertInstructionBaseline({identity,previous:null,previousWriteback:null})
|
|
139
|
+
.originals.map(item=>item.path),targets);
|
|
140
|
+
assert.equal(fs.existsSync(marker),false);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('numbered approved bootstrap binds fixed rules targets and its own requirements',t=>{
|
|
144
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-bootstrap-compat-')));
|
|
145
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
146
|
+
const specsDir=path.join(root,'specs'),codeProject=path.join(root,'code'),feature='1.bootstrap';
|
|
147
|
+
fs.mkdirSync(path.join(specsDir,feature),{recursive:true});fs.mkdirSync(codeProject);
|
|
148
|
+
for(const name of ['requirements.md','design.md'])fs.writeFileSync(path.join(specsDir,feature,name),'# Approved fixture\n');
|
|
149
|
+
fs.writeFileSync(path.join(specsDir,feature,'tasks.md'),'- [x] T-001: 生成骨架 scaffold\n- [ ] T-002: 生成 AGENTS.md 与 .claude/ 规则\n');
|
|
150
|
+
fs.writeFileSync(path.join(codeProject,'app.mjs'),'export const fixture=true;\n');
|
|
151
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
152
|
+
const definition={version:1,specsDir,codeProject,feature,identity:{repositoryId:'fixture',runId:'rules',taskId:'T-002',attempt:1},
|
|
153
|
+
scope:[...cmInitRuleTargets(selection)],requirements:[]};
|
|
154
|
+
const bootstrap=createHostBootstrap({definition,workflowRoot,selection,bridge:{call:async()=>{throw Error('unused');}},allowWrite:true});
|
|
155
|
+
assert.equal(bootstrap.configuration.feature,feature);
|
|
156
|
+
assert.deepEqual(bootstrap.configuration.bootstrapRequirements.files.map(file=>file.path),
|
|
157
|
+
[`${feature}/design.md`,`${feature}/requirements.md`]);
|
|
158
|
+
assert(bootstrap.configuration.instructionPaths.includes('AGENTS.md'));
|
|
159
|
+
assert(bootstrap.configuration.instructionPaths.includes('.claude/CLAUDE.md'));
|
|
160
|
+
assert.throws(()=>createHostBootstrap({definition:{...definition,feature:'2.bootstrap'},workflowRoot,
|
|
161
|
+
selection,bridge:{call:async()=>{throw Error('unused');}},allowWrite:true}),{code:'bootstrap_task_required'});
|
|
162
|
+
});
|