@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
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
// #12 a spec change re-approved mid-task: status tells the truth, a change that
|
|
2
|
+
// leaves this task's material untouched is explicitly rebound, anything else
|
|
3
|
+
// fails closed naming what changed and keeps a working recovery chain.
|
|
4
|
+
import test,{after} from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import os from 'node:os';
|
|
8
|
+
import path from 'node:path';
|
|
9
|
+
import {spawnSync} from 'node:child_process';
|
|
10
|
+
import {fileURLToPath} from 'node:url';
|
|
11
|
+
import {buildManifest} from './cm-spec-manifest.mjs';
|
|
12
|
+
import {openControlRun} from './cm-ai-run.mjs';
|
|
13
|
+
import {approveCmAiSpecs,inspectCmAiAdmission} from '../runtime/js/cm-ai/cm-ai-admission.mjs';
|
|
14
|
+
import {writeSpecsStatus,readSpecsStatus} from '../runtime/js/specs-status.mjs';
|
|
15
|
+
import {createCodexDeveloperRun} from '../runtime/js/cm-ai/codex-developer-adapter.mjs';
|
|
16
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
17
|
+
import {reviewPaths} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
18
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
19
|
+
import {readRunnerHistory} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
20
|
+
|
|
21
|
+
const home=fs.mkdtempSync(path.join(os.tmpdir(),'cm-spec-rebind-home-'));
|
|
22
|
+
process.env.CM_WORKFLOW_HOME=path.join(home,'user');process.env.CM_WORKFLOW_LOG_HOME=path.join(home,'logs');
|
|
23
|
+
after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
24
|
+
const cli=fileURLToPath(new URL('./cm-ai-host.mjs',import.meta.url));
|
|
25
|
+
|
|
26
|
+
function fixture(t){
|
|
27
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-spec-rebind-')));
|
|
28
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
29
|
+
const codeProject=path.join(root,'code'),specsDir=path.join(root,'specs'),feature='1.work';
|
|
30
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(path.join(specsDir,feature),{recursive:true});
|
|
31
|
+
fs.writeFileSync(path.join(codeProject,'a.mjs'),'export const a=1;\n');fs.writeFileSync(path.join(codeProject,'requirements.md'),'fixture\n');
|
|
32
|
+
const file=name=>path.join(specsDir,feature,name);
|
|
33
|
+
fs.writeFileSync(file('requirements.md'),'# Requirements\n- [ ] [AC-001] a exports new\n');
|
|
34
|
+
fs.writeFileSync(file('design.md'),'# Design\nsimple\n');
|
|
35
|
+
fs.writeFileSync(file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b\n\n- T-002 依赖 T-001\n');
|
|
36
|
+
fs.writeFileSync(path.join(specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[feature],specFiles:buildManifest(specsDir)}));
|
|
37
|
+
const identity=(runId='rebind-run-0001')=>({repositoryId:'rebind-fixture',runId,taskId:'T-001',attempt:1});
|
|
38
|
+
const definition=(runId)=>({version:1,specsDir,codeProject,feature,identity:identity(runId),scope:['a.mjs'],requirements:['requirements.md']});
|
|
39
|
+
return {root,codeProject,specsDir,feature,file,identity,definition};
|
|
40
|
+
}
|
|
41
|
+
// The cm-prd --change publication (awaiting_review) followed by the real CLI approve gate.
|
|
42
|
+
function reapprove(f){
|
|
43
|
+
const prior=readSpecsStatus(f.specsDir).value,specFiles=buildManifest(f.specsDir);
|
|
44
|
+
writeSpecsStatus(f.specsDir,{status:'awaiting_review',summaryDigest:'a'.repeat(64),at:new Date().toISOString(),
|
|
45
|
+
features:prior.features,specFiles,testCases:[],approval:null});
|
|
46
|
+
const approved=approveCmAiSpecs({specsDir:f.specsDir,codeProject:f.codeProject,approvalResponse:'开始'});
|
|
47
|
+
assert.equal(approved.approveRefused,undefined);
|
|
48
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).state,'ready');
|
|
49
|
+
}
|
|
50
|
+
function executionFor(f,{decision=null,onReview=()=>{},onDevelop=()=>{}}={}){
|
|
51
|
+
const reviewer={id:'reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'fixture',
|
|
52
|
+
allowed:true,available:true,contexts:['review-one','review-two'],run:(request,{onEvent})=>{
|
|
53
|
+
onReview();
|
|
54
|
+
onEvent({event:'thread.started',provider_thread:`thread-${request.identity.runId}`});
|
|
55
|
+
onEvent({event:'turn.started',item_type:null});onEvent({event:'item.completed',item_type:'agent_message'});
|
|
56
|
+
onEvent({event:'turn.completed',item_type:null});onEvent({event:'process_closed',exit_code:0,signal:null,timed_out:false});
|
|
57
|
+
return {status:'succeeded',value:{verdict:'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
58
|
+
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:[],summary:'Synthetic review'}};
|
|
59
|
+
}};
|
|
60
|
+
return {configuration:{kind:'synthetic-host-v1'},timeoutMs:2000,excludedContexts:['control'],
|
|
61
|
+
developer:{provider:'codex',requestedModel:'fixture',contextId:'developer',run:createCodexDeveloperRun({
|
|
62
|
+
requestedModel:'fixture',worker:async()=>{fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'export const a=2;\n');onDevelop();
|
|
63
|
+
return {status:'succeeded',value:{outcome:'implemented',application:{status:'no_relevant_lesson',note:null},
|
|
64
|
+
retrospective:{status:'no_new_lesson',candidates:[],reason:null}}};}})},
|
|
65
|
+
reviewers:[reviewer],reviewInvocation:{developerThreadId:'author-thread',excludedThreadIds:['control'],
|
|
66
|
+
authorize:(request,{authorizationAt})=>{
|
|
67
|
+
const body={version:1,kind:'cm-review-dispatch-grant',grantId:`grant-${request.identity.runId}`,
|
|
68
|
+
adapterId:'codex-review-adapter',invocationId:request.invocationId,requestDigest:request.requestDigest,
|
|
69
|
+
identity:request.identity,reviewerId:'reviewer',logicalContextId:request.contextId,
|
|
70
|
+
packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'control',decisionId:'approved',
|
|
71
|
+
decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
72
|
+
return {...body,grantDigest:digest(body)};
|
|
73
|
+
}},hostDecision:decision,check:createHostCheck({cwd:f.codeProject,
|
|
74
|
+
commands:[{id:'syntax',command:[process.execPath,'--check','a.mjs']}]})};
|
|
75
|
+
}
|
|
76
|
+
async function withRun(f,mode,options,run,runId){
|
|
77
|
+
const opened=await openControlRun(f.definition(runId),mode,executionFor(f,options),options);
|
|
78
|
+
try{return await run(opened.host,f.identity(runId));}finally{opened.close();}
|
|
79
|
+
}
|
|
80
|
+
const ask=(host,identity,operation,extra={})=>host.handle({version:1,operation,requestId:operation,identity,...extra});
|
|
81
|
+
async function awaitingReview(f){
|
|
82
|
+
return withRun(f,'create',{},async(host,identity)=>{
|
|
83
|
+
const result=await ask(host,identity,'advance');
|
|
84
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));assert.equal(result.code,'decision_required');
|
|
85
|
+
return result.packageDigest;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const stateFile=(f,runId='rebind-run-0001')=>path.join(f.specsDir,'.reviews','.execution',runId,'state.json');
|
|
89
|
+
|
|
90
|
+
test('another task changed and re-approved: status names spec_drift and the rebind; the rebind keeps the delivery',async t=>{
|
|
91
|
+
const f=fixture(t),packageDigest=await awaitingReview(f);
|
|
92
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b(导出 3)\n\n- T-002 依赖 T-001\n');
|
|
93
|
+
reapprove(f);
|
|
94
|
+
await withRun(f,'resume',{decision:{status:'approved'}},async(host,identity)=>{
|
|
95
|
+
const status=await ask(host,identity,'status');
|
|
96
|
+
assert.equal(status.state,'awaiting_review');assert.equal(status.code,'spec_drift');
|
|
97
|
+
assert.equal(status.pendingAction,'spec_rebind');
|
|
98
|
+
assert.match(status.reason,/1\.work\/tasks\.md/);assert.match(status.reason,/--rebind-spec-material/);
|
|
99
|
+
const decision=await ask(host,identity,'decision',{packageDigest});
|
|
100
|
+
assert.equal(decision.outcome,'rejected');assert.equal(decision.code,'spec_drift');
|
|
101
|
+
assert.equal(decision.pendingAction,'spec_rebind');
|
|
102
|
+
});
|
|
103
|
+
const before=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records.length;
|
|
104
|
+
await withRun(f,'resume',{decision:{status:'approved'},specRebindReason:'T-002 描述调整,不涉及 T-001'},async(host,identity)=>{
|
|
105
|
+
const status=await ask(host,identity,'status');
|
|
106
|
+
assert.equal(status.code,null);assert.equal(status.pendingAction,'decision');assert.equal(status.packageDigest,packageDigest);
|
|
107
|
+
const done=await ask(host,identity,'advance');
|
|
108
|
+
assert.equal(done.state,'fixture_completed',JSON.stringify(done));
|
|
109
|
+
});
|
|
110
|
+
const records=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records;
|
|
111
|
+
const rebound=records.filter(row=>row.payload.type==='specification-rebound');
|
|
112
|
+
assert.equal(rebound.length,1);assert.equal(records.indexOf(rebound[0]),before);
|
|
113
|
+
assert.deepEqual(rebound[0].payload.record.files,['1.work/tasks.md']);
|
|
114
|
+
assert.equal(rebound[0].payload.record.reason,'T-002 描述调整,不涉及 T-001');
|
|
115
|
+
assert.equal(readRunnerHistory(records,records[0].payload.config,3).state.state,'fixture_completed');
|
|
116
|
+
assert.match(fs.readFileSync(f.file('tasks.md'),'utf8'),/\[x\] T-001/);
|
|
117
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-002');
|
|
118
|
+
// Idempotent relaunch with the same flag writes nothing new.
|
|
119
|
+
await withRun(f,'resume',{specRebindReason:'again'},async()=>{});
|
|
120
|
+
assert.equal(JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records.length,records.length);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('a change to what the run saw fails closed, names it, and both recovery exits work end to end',async t=>{
|
|
124
|
+
const f=fixture(t),packageDigest=await awaitingReview(f);
|
|
125
|
+
fs.writeFileSync(f.file('design.md'),'# Design\nsimple, now with a cache\n');
|
|
126
|
+
reapprove(f);
|
|
127
|
+
await withRun(f,'resume',{},async(host,identity)=>{
|
|
128
|
+
const status=await ask(host,identity,'status');
|
|
129
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');
|
|
130
|
+
assert.match(status.reason,/1\.work\/design\.md/);assert.match(status.reason,/设计摘录/);
|
|
131
|
+
assert.match(status.reason,/不能换绑/);assert.match(status.reason,/--supersede-reviewed-evidence/);
|
|
132
|
+
});
|
|
133
|
+
await assert.rejects(withRun(f,'resume',{specRebindReason:'想继续'},async()=>{}),error=>{
|
|
134
|
+
assert.equal(error.code,'spec_rebind_refused');assert.match(error.reason,/设计摘录/);return true;});
|
|
135
|
+
assert.equal(JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records.some(row=>row.payload.type==='specification-rebound'),false);
|
|
136
|
+
// Exit 1: revert the spec and re-approve; the same run continues.
|
|
137
|
+
fs.writeFileSync(f.file('design.md'),'# Design\nsimple\n');reapprove(f);
|
|
138
|
+
await withRun(f,'resume',{},async(host,identity)=>{
|
|
139
|
+
const status=await ask(host,identity,'status');assert.equal(status.code,null);assert.equal(status.pendingAction,'decision');
|
|
140
|
+
assert.equal(status.packageDigest,packageDigest);
|
|
141
|
+
});
|
|
142
|
+
// Exit 2: keep the new design; cancel, restore the run's code, supersede and redo.
|
|
143
|
+
fs.writeFileSync(f.file('design.md'),'# Design\nsimple, now with a cache\n');reapprove(f);
|
|
144
|
+
await withRun(f,'resume',{},async(host,identity)=>{assert.equal((await ask(host,identity,'cancel')).state,'cancelled');});
|
|
145
|
+
fs.writeFileSync(path.join(f.codeProject,'a.mjs'),'export const a=1;\n');
|
|
146
|
+
const redone=await withRun(f,'create',{decision:{status:'approved'},supersedeReason:'设计变更后重做'},
|
|
147
|
+
(host,identity)=>ask(host,identity,'advance'),'rebind-run-0002');
|
|
148
|
+
assert.equal(redone.state,'fixture_completed',JSON.stringify(redone));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('a rebind cannot carry changed content: a later content change still drifts',async t=>{
|
|
152
|
+
const f=fixture(t);await awaitingReview(f);
|
|
153
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
154
|
+
await withRun(f,'resume',{specRebindReason:'只改了 T-002'},async()=>{});
|
|
155
|
+
fs.appendFileSync(f.file('requirements.md'),'- [ ] [AC-002] b exports 3\n');reapprove(f);
|
|
156
|
+
await withRun(f,'resume',{},async(host,identity)=>{
|
|
157
|
+
const status=await ask(host,identity,'status');
|
|
158
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');assert.match(status.reason,/验收标准/);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Whether a verdict survives a spec change during the review itself belongs to
|
|
163
|
+
// the review-drift handling (PR #164). Whatever that stops at, status must not
|
|
164
|
+
// advertise an action the run would refuse.
|
|
165
|
+
test('a spec change during review never leaves status advertising a refused action',async t=>{
|
|
166
|
+
const f=fixture(t);
|
|
167
|
+
await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'advance')).state,'awaiting_review'));
|
|
168
|
+
const changeDuringReview=()=>{
|
|
169
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 审查期间改了\n\n- T-002 依赖 T-001\n');reapprove(f);};
|
|
170
|
+
await withRun(f,'resume',{decision:{status:'approved'},onReview:changeDuringReview},async(host,identity)=>{
|
|
171
|
+
await ask(host,identity,'advance');
|
|
172
|
+
const status=await ask(host,identity,'status');
|
|
173
|
+
assert.equal(status.code,'spec_drift');assert(['spec_rebind','none'].includes(status.pendingAction),status.pendingAction);
|
|
174
|
+
assert.equal(typeof status.reason,'string');
|
|
175
|
+
if(status.pendingAction==='none')assert.match(status.reason,/--supersede-reviewed-evidence/);
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
test('host CLI accepts the rebind only on resume with a single-line reason',t=>{
|
|
180
|
+
const f=fixture(t),config=path.join(f.root,'run.json'),review=path.join(f.root,'review.json');
|
|
181
|
+
fs.writeFileSync(config,JSON.stringify(f.definition('rebind-cli-run')));
|
|
182
|
+
fs.writeFileSync(review,JSON.stringify({model:'fixture',preflight:{}}));
|
|
183
|
+
const launch=(mode,extra)=>{
|
|
184
|
+
const result=spawnSync(process.execPath,[cli,'serve','--config',config,'--mode',mode,'--host-context','cli-host',
|
|
185
|
+
'--allow-development','--review-config',review,...extra],{encoding:'utf8',timeout:20000,input:'',
|
|
186
|
+
env:{...process.env,CM_WORKFLOW_HOME:path.join(f.root,'home'),CM_WORKFLOW_LOG_HOME:path.join(f.root,'logs'),NODE_NO_WARNINGS:'1'}});
|
|
187
|
+
return {...result,error:JSON.parse(result.stderr.split('\n').find(line=>line.startsWith('{"error"'))??'null')?.error??null};
|
|
188
|
+
};
|
|
189
|
+
for(const [mode,extra] of [['create',['--rebind-spec-material','--spec-rebind-reason','x']],
|
|
190
|
+
['resume',['--rebind-spec-material']],['resume',['--spec-rebind-reason','x']]]){
|
|
191
|
+
const result=launch(mode,extra);
|
|
192
|
+
assert.equal(result.status,1);assert.equal(result.error.code,'spec_rebind_unavailable');
|
|
193
|
+
assert.match(result.error.reason,/--rebind-spec-material/);
|
|
194
|
+
}
|
|
195
|
+
assert.equal(launch('create',[]).status,0);
|
|
196
|
+
const nothing=launch('resume',['--rebind-spec-material','--spec-rebind-reason','没有规格变化']);
|
|
197
|
+
assert.equal(nothing.status,0,nothing.stderr);
|
|
198
|
+
const records=JSON.parse(fs.readFileSync(stateFile(f,'rebind-cli-run'),'utf8')).records;
|
|
199
|
+
assert.equal(records.some(row=>row.payload.type==='specification-rebound'),false,'no drift means no record');
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
test('a run rebound before its first delivery develops against the re-approved spec',async t=>{
|
|
203
|
+
const f=fixture(t);
|
|
204
|
+
await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'status')).state,'ready'));
|
|
205
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
206
|
+
await withRun(f,'resume',{},async(host,identity)=>{
|
|
207
|
+
const status=await ask(host,identity,'status');
|
|
208
|
+
assert.equal(status.state,'ready');assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'spec_rebind');
|
|
209
|
+
assert.equal((await ask(host,identity,'advance')).code,'spec_drift');
|
|
210
|
+
});
|
|
211
|
+
await withRun(f,'resume',{specRebindReason:'只改了 T-002'},async(host,identity)=>{
|
|
212
|
+
const result=await ask(host,identity,'advance');
|
|
213
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
test('journal replay accepts a rebind only bound to this run material and before completion',async t=>{
|
|
218
|
+
const f=fixture(t);await awaitingReview(f);
|
|
219
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
220
|
+
await withRun(f,'resume',{specRebindReason:'只改了 T-002'},async()=>{});
|
|
221
|
+
const records=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records,config=records[0].payload.config;
|
|
222
|
+
const index=records.findIndex(row=>row.payload.type==='specification-rebound');
|
|
223
|
+
const reseal=(list,at,payload)=>{
|
|
224
|
+
const out=structuredClone(list.slice(0,at));const body={...list[at],payload,previousDigest:out.at(-1).digest};
|
|
225
|
+
delete body.digest;out.push({...body,digest:digest(body)});return out;
|
|
226
|
+
};
|
|
227
|
+
assert.equal(readRunnerHistory(records,config,3).state.state,'awaiting_review');
|
|
228
|
+
const forged={...records[index].payload,record:{...records[index].payload.record,boundDigest:'0'.repeat(64)}};
|
|
229
|
+
assert.throws(()=>readRunnerHistory(reseal(records,index,forged),config,3),error=>error.code==='spec_rebind_invalid');
|
|
230
|
+
// After completion no effect remains, so a rebind record is not valid history.
|
|
231
|
+
await withRun(f,'resume',{decision:{status:'approved'}},async(host,identity)=>
|
|
232
|
+
assert.equal((await ask(host,identity,'advance')).state,'fixture_completed'));
|
|
233
|
+
const done=JSON.parse(fs.readFileSync(stateFile(f),'utf8')).records;
|
|
234
|
+
const late={...records[index],seq:done.length+1,id:`runner.${String(done.length+1).padStart(6,'0')}`};
|
|
235
|
+
assert.throws(()=>readRunnerHistory(reseal([...done,late],done.length,records[index].payload),config,3),
|
|
236
|
+
error=>error.code==='spec_rebind_invalid');
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
test('a spec change while the developer works stops the run with its real exits',async t=>{
|
|
240
|
+
const f=fixture(t);
|
|
241
|
+
const changeDuringDevelop=()=>{fs.writeFileSync(f.file('design.md'),'# Design\nchanged mid-develop\n');reapprove(f);};
|
|
242
|
+
await withRun(f,'create',{onDevelop:changeDuringDevelop},async(host,identity)=>{
|
|
243
|
+
const result=await ask(host,identity,'advance');
|
|
244
|
+
assert.equal(result.state,'blocked');assert.equal(result.code,'spec_drift');
|
|
245
|
+
const status=await ask(host,identity,'status');
|
|
246
|
+
assert.equal(status.pendingAction,'none');assert.match(status.reason,/--supersede-reviewed-evidence/);
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Cross-review blocker: a requirement can span lines, and a task item can carry
|
|
251
|
+
// sub-bullets. Neither appears in the one-line material, so the rebind must not
|
|
252
|
+
// decide from the material alone.
|
|
253
|
+
async function multiLineRun(f){
|
|
254
|
+
fs.writeFileSync(f.file('requirements.md'),'# Requirements\n- [ ] [AC-001] Store user data\n 必须静态加密\n- [ ] [AC-002] b exports 3\n');
|
|
255
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n - 约束:保留旧接口\n- [ ] T-002: 新增 b\n - 约束:导出 3\n\n## 验证要求\n- T-002: node --test b\n\n## 依赖关系\n- T-002 依赖 T-001\n');
|
|
256
|
+
reapprove(f);
|
|
257
|
+
return awaitingReview(f);
|
|
258
|
+
}
|
|
259
|
+
const statusOf=f=>withRun(f,'resume',{},(host,identity)=>ask(host,identity,'status'));
|
|
260
|
+
for(const [label,file,from,to,pattern] of [
|
|
261
|
+
['acceptance continuation line','requirements.md',' 必须静态加密',' 允许明文存储',/requirements\.md(整份核对/],
|
|
262
|
+
['requirements prose without an AC marker','requirements.md','# Requirements\n','# Requirements\n所有数据保留 7 天\n',/requirements\.md(整份核对/],
|
|
263
|
+
['this task sub-bullet','tasks.md',' - 约束:保留旧接口',' - 约束:删除旧接口',/本任务的条目/],
|
|
264
|
+
['shared tasks.md prose','tasks.md','# tasks\n','# tasks\n全部任务必须补日志\n',/本任务的条目/],
|
|
265
|
+
['a dependency of this task','tasks.md','- T-002 依赖 T-001\n','- T-002 依赖 T-001\n- T-001 依赖 T-000\n',/本任务的条目/],
|
|
266
|
+
// Re-review blocker: a line naming this task belongs to its scope wherever it sits.
|
|
267
|
+
['another task sub-item naming this task','tasks.md',' - 约束:导出 3',' - 约束:导出 3\n - T-001 must encrypt backups',/本任务的条目/],
|
|
268
|
+
['a new task depending on this one','tasks.md',' - 约束:导出 3',' - 约束:导出 3\n- [ ] T-003: [NEW] 新增 c\n- T-003 依赖 T-001',/本任务的条目/],
|
|
269
|
+
])test(`multi-line spec: a change to ${label} is refused, naming it`,async t=>{
|
|
270
|
+
const f=fixture(t);await multiLineRun(f);
|
|
271
|
+
fs.writeFileSync(f.file(file),fs.readFileSync(f.file(file),'utf8').replace(from,to));
|
|
272
|
+
if(label==='a dependency of this task')fs.writeFileSync(f.file('tasks.md'),
|
|
273
|
+
fs.readFileSync(f.file('tasks.md'),'utf8').replace('# tasks\n','# tasks\n- [x] T-000: 前置\n'));
|
|
274
|
+
reapprove(f);
|
|
275
|
+
const status=await statusOf(f);
|
|
276
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none',status.reason);
|
|
277
|
+
assert.match(status.reason,pattern);assert.match(status.reason,/不能换绑/);
|
|
278
|
+
await assert.rejects(withRun(f,'resume',{specRebindReason:'试图换绑'},async()=>{}),error=>error.code==='spec_rebind_refused');
|
|
279
|
+
});
|
|
280
|
+
test('multi-line spec: other tasks items, sub-bullets, verification and new tasks not naming this one stay rebindable',async t=>{
|
|
281
|
+
const f=fixture(t),packageDigest=await multiLineRun(f);
|
|
282
|
+
fs.writeFileSync(f.file('tasks.md'),fs.readFileSync(f.file('tasks.md'),'utf8')
|
|
283
|
+
.replace('- [ ] T-002: 新增 b\n - 约束:导出 3','- [ ] T-002: 新增 b(改)\n - 约束:导出 4\n - 新增子项\n- [ ] T-003: [NEW] 新增 c')
|
|
284
|
+
.replace('- T-002: node --test b','- T-002: node --test b c')
|
|
285
|
+
.replace('- T-002 依赖 T-001\n','- T-002 依赖 T-001\n- T-003 依赖 T-002\n'));
|
|
286
|
+
reapprove(f);
|
|
287
|
+
const status=await statusOf(f);
|
|
288
|
+
assert.equal(status.pendingAction,'spec_rebind',status.reason);assert.match(status.reason,/1\.work\/tasks\.md/);
|
|
289
|
+
await withRun(f,'resume',{decision:{status:'approved'},specRebindReason:'只改了 T-002 并新增 T-003'},async(host,identity)=>{
|
|
290
|
+
const current=await ask(host,identity,'status');
|
|
291
|
+
assert.equal(current.code,null);assert.equal(current.packageDigest,packageDigest);
|
|
292
|
+
assert.equal((await ask(host,identity,'advance')).state,'fixture_completed');
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
test('a run bound before taskScopeDigest keeps verifying but is never rebindable',async t=>{
|
|
297
|
+
const f=fixture(t);
|
|
298
|
+
await withRun(f,'create',{},async(host,identity)=>assert.equal((await ask(host,identity,'status')).state,'ready'));
|
|
299
|
+
// Legacy-shaped journal: the init baseline material without taskScopeDigest.
|
|
300
|
+
const file=stateFile(f),state=JSON.parse(fs.readFileSync(file,'utf8'));
|
|
301
|
+
assert.equal(state.records.length,1);
|
|
302
|
+
const init=state.records[0],{baselineDigest,...baseline}=init.payload.baseline;
|
|
303
|
+
assert.match(baseline.specification.taskScopeDigest,/^[a-f0-9]{64}$/);
|
|
304
|
+
const {taskScopeDigest,...material}=baseline.specification;
|
|
305
|
+
const legacyBaseline={...baseline,specification:material};
|
|
306
|
+
const {digest:oldDigest,...body}=init;
|
|
307
|
+
const record={...body,payload:{...init.payload,baseline:{...legacyBaseline,baselineDigest:digest(legacyBaseline)}}};
|
|
308
|
+
const records=[{...record,digest:digest(record)}],{revision,...rest}=state,next={...rest,records};
|
|
309
|
+
fs.writeFileSync(file,JSON.stringify({...next,revision:digest(next)})+'\n');
|
|
310
|
+
await withRun(f,'resume',{},async(host,identity)=>{
|
|
311
|
+
const status=await ask(host,identity,'status');assert.equal(status.state,'ready');assert.equal(status.code,null);
|
|
312
|
+
});
|
|
313
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
314
|
+
const status=await statusOf(f);
|
|
315
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');assert.match(status.reason,/旧版本创建/);
|
|
316
|
+
await assert.rejects(withRun(f,'resume',{specRebindReason:'旧运行'},async()=>{}),error=>error.code==='spec_rebind_refused');
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test('test cases: another task case may change, this task case may not',async t=>{
|
|
320
|
+
const f=fixture(t);
|
|
321
|
+
const testCase=(id,taskId,title)=>({id,origin:'user',kind:'logic',blocking:true,acIds:['AC-001'],taskIds:[taskId],
|
|
322
|
+
title,preconditions:[],steps:['Run it'],expected:['Works'],cleanup:[]});
|
|
323
|
+
const write=cases=>fs.writeFileSync(f.file('test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',cases}));
|
|
324
|
+
write([testCase('TC-001','T-001','a exports new'),testCase('TC-002','T-002','b exports 3')]);reapprove(f);
|
|
325
|
+
await awaitingReview(f);
|
|
326
|
+
write([testCase('TC-001','T-001','a exports new'),testCase('TC-002','T-002','b exports 3 and 4')]);reapprove(f);
|
|
327
|
+
assert.equal((await statusOf(f)).pendingAction,'spec_rebind');
|
|
328
|
+
write([testCase('TC-001','T-001','a exports newer'),testCase('TC-002','T-002','b exports 3 and 4')]);reapprove(f);
|
|
329
|
+
const status=await statusOf(f);
|
|
330
|
+
assert.equal(status.pendingAction,'none');assert.match(status.reason,/本任务测试用例/);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
test('task scope keeps shared fenced text after another task item',async()=>{
|
|
334
|
+
const {taskScopeText}=await import('../runtime/js/cm-ai/specification-material.mjs');
|
|
335
|
+
const before='- [ ] T-001: a\n - 子项\n- [ ] T-002: b\n - b 子项\n```\n所有任务都要加密\n```\n## 验证要求\n- T-002: test b\n- T-001: test a\n- T-002 依赖 T-001\n';
|
|
336
|
+
const scope=taskScopeText(before,'T-001');
|
|
337
|
+
assert.match(scope,/子项/);assert.match(scope,/所有任务都要加密/);assert.match(scope,/- T-001: test a/);
|
|
338
|
+
assert.match(scope,/- T-002 依赖 T-001/,'a line naming this task is in scope wherever it sits');
|
|
339
|
+
assert.doesNotMatch(scope,/b 子项|T-002: b|test b/);
|
|
340
|
+
assert.notEqual(taskScopeText(before.replace('所有任务都要加密','所有任务可明文'),'T-001'),scope);
|
|
341
|
+
assert.equal(taskScopeText(before.replace(' - b 子项',' - b 子项改'),'T-001'),scope);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test('a line naming this task under another task item changes: refused',async t=>{
|
|
345
|
+
const f=fixture(t);
|
|
346
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b\n - T-001 must encrypt backups\n\n## 依赖关系\n- T-002 依赖 T-001\n');
|
|
347
|
+
reapprove(f);await awaitingReview(f);
|
|
348
|
+
fs.writeFileSync(f.file('tasks.md'),fs.readFileSync(f.file('tasks.md'),'utf8').replace('T-001 must encrypt backups','T-001 may store plaintext backups'));
|
|
349
|
+
reapprove(f);
|
|
350
|
+
const status=await statusOf(f);
|
|
351
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');assert.match(status.reason,/本任务的条目/);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
test('another task test case that names this task changes: refused',async t=>{
|
|
355
|
+
const f=fixture(t);
|
|
356
|
+
const testCase=(id,taskId,title,steps)=>({id,origin:'user',kind:'logic',blocking:true,acIds:['AC-001'],taskIds:[taskId],
|
|
357
|
+
title,preconditions:[],steps,expected:['Works'],cleanup:[]});
|
|
358
|
+
const write=steps=>fs.writeFileSync(f.file('test-cases.json'),JSON.stringify({schemaVersion:'1.0',feature:'work',
|
|
359
|
+
cases:[testCase('TC-001','T-001','a exports new',['Run a']),testCase('TC-002','T-002','b exports 3',steps)]}));
|
|
360
|
+
write(['Run b','Check T-001 backups are encrypted']);reapprove(f);await awaitingReview(f);
|
|
361
|
+
write(['Run b','Check T-001 backups may be plaintext']);reapprove(f);
|
|
362
|
+
const status=await statusOf(f);
|
|
363
|
+
assert.equal(status.pendingAction,'none');assert.match(status.reason,/本任务的条目/);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Re-review major: an approval recorded before the shared grammar keeps its
|
|
367
|
+
// original parse. Under the old parser `T-001:` is prose, not a duplicate task.
|
|
368
|
+
test('an approval recorded before the shared grammar keeps parsing with the old grammar end to end',async t=>{
|
|
369
|
+
const f=fixture(t);
|
|
370
|
+
const tasks='# tasks\n- [ ] T-001: 修改 a\n- [ ] T-001:示例写法(旧解析器视为说明)\n- [ ] T-002: 新增 b\n\n- T-002 依赖 T-001\n';
|
|
371
|
+
fs.writeFileSync(f.file('tasks.md'),tasks);
|
|
372
|
+
// Legacy-shaped approval: no taskGrammar field.
|
|
373
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[f.feature],specFiles:buildManifest(f.specsDir)}));
|
|
374
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-001');
|
|
375
|
+
const done=await withRun(f,'create',{decision:{status:'approved'}},(host,identity)=>ask(host,identity,'advance'));
|
|
376
|
+
assert.equal(done.state,'fixture_completed',JSON.stringify(done));
|
|
377
|
+
const after=fs.readFileSync(f.file('tasks.md'),'utf8');
|
|
378
|
+
assert.equal(after,tasks.replace('- [ ] T-001: 修改 a','- [x] T-001: 修改 a'),'the old mark-done flips only the real task');
|
|
379
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-002');
|
|
380
|
+
// supersede reads the tick with the same old grammar: one task, already ticked.
|
|
381
|
+
await assert.rejects(withRun(f,'create',{supersedeReason:'重跑'},async()=>{},'rebind-run-legacy-2'),
|
|
382
|
+
error=>error.code==='supersede_unavailable'&&/已将任务标为完成/.test(error.reason));
|
|
383
|
+
// A new approval would bind the shared grammar, under which the same bytes are a
|
|
384
|
+
// duplicate: it is refused, naming the line, instead of stranding the approval.
|
|
385
|
+
const refused=reapproveRaw(f);
|
|
386
|
+
assert.equal(refused.approveRefused,'task_grammar_conflict');
|
|
387
|
+
assert.match(refused.approveReason,/1\.work\/tasks\.md 第 3 行/);assert.match(refused.approveReason,/围栏/);
|
|
388
|
+
assert.equal(readSpecsStatus(f.specsDir).value.taskGrammar,undefined);
|
|
389
|
+
fs.writeFileSync(f.file('tasks.md'),fs.readFileSync(f.file('tasks.md'),'utf8')
|
|
390
|
+
.replace('- [ ] T-001:示例写法(旧解析器视为说明)','```\n- [ ] T-001:示例写法(旧解析器视为说明)\n```'));
|
|
391
|
+
assert.equal(reapproveRaw(f).approveRefused,undefined);
|
|
392
|
+
assert.equal(readSpecsStatus(f.specsDir).value.taskGrammar,2);
|
|
393
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-002');
|
|
394
|
+
});
|
|
395
|
+
function reapproveRaw(f){
|
|
396
|
+
const prior=readSpecsStatus(f.specsDir).value,specFiles=buildManifest(f.specsDir);
|
|
397
|
+
writeSpecsStatus(f.specsDir,{status:'awaiting_review',summaryDigest:'a'.repeat(64),at:new Date().toISOString(),
|
|
398
|
+
features:prior.features,specFiles,testCases:[],approval:null});
|
|
399
|
+
return approveCmAiSpecs({specsDir:f.specsDir,codeProject:f.codeProject,approvalResponse:'开始'});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
test('re-approving another feature is refused while an untouched feature would change meaning',async t=>{
|
|
403
|
+
const f=fixture(t);
|
|
404
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-001:旧示例\n');
|
|
405
|
+
const other=path.join(f.specsDir,'2.other');fs.mkdirSync(other);
|
|
406
|
+
for(const [name,body] of [['requirements.md','# R\n- [ ] [AC-001] other\n'],['design.md','# D\n'],['tasks.md','- [ ] T-001: other\n']])
|
|
407
|
+
fs.writeFileSync(path.join(other,name),body);
|
|
408
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[f.feature,'2.other'],specFiles:buildManifest(f.specsDir)}));
|
|
409
|
+
await awaitingReview(f);
|
|
410
|
+
fs.writeFileSync(path.join(other,'design.md'),'# D\nchanged\n');
|
|
411
|
+
const refused=reapproveRaw(f);
|
|
412
|
+
assert.equal(refused.approveRefused,'task_grammar_conflict');assert.match(refused.approveReason,/1\.work\/tasks\.md 第 3 行/);
|
|
413
|
+
assert.equal(readSpecsStatus(f.specsDir).value.status,'awaiting_review','nothing approved under the new grammar');
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
// Fourth review: a unique full-width example is not a duplicate, but it would
|
|
417
|
+
// silently become a pending task when the project moves to the shared grammar.
|
|
418
|
+
function legacyTwoFeatures(f,workTasks){
|
|
419
|
+
fs.writeFileSync(f.file('tasks.md'),workTasks);
|
|
420
|
+
const other=path.join(f.specsDir,'2.other');fs.mkdirSync(other);
|
|
421
|
+
for(const [name,body] of [['requirements.md','# R\n- [ ] [AC-001] other\n'],['design.md','# D\n'],['tasks.md','- [ ] T-001: other\n']])
|
|
422
|
+
fs.writeFileSync(path.join(other,name),body);
|
|
423
|
+
fs.writeFileSync(path.join(f.specsDir,'.cm-specs-status'),JSON.stringify({status:'approved',features:[f.feature,'2.other'],specFiles:buildManifest(f.specsDir)}));
|
|
424
|
+
return other;
|
|
425
|
+
}
|
|
426
|
+
test('moving to the shared grammar is refused when a unique example would become a task',async t=>{
|
|
427
|
+
const f=fixture(t),other=legacyTwoFeatures(f,'# tasks\n- [x] T-001: 已完成\n- [ ] T-099:示例写法\n');
|
|
428
|
+
assert.deepEqual(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).features.map(item=>item.total),[1,1]);
|
|
429
|
+
fs.writeFileSync(path.join(other,'design.md'),'# D\nchanged\n');
|
|
430
|
+
const refused=reapproveRaw(f);
|
|
431
|
+
assert.equal(refused.approveRefused,'task_grammar_conflict');
|
|
432
|
+
assert.match(refused.approveReason,/1\.work\/tasks\.md 在新任务行语法下任务集合会变化:第 3 行 - \[ \] T-099:示例写法/);
|
|
433
|
+
assert.equal(readSpecsStatus(f.specsDir).value.status,'awaiting_review');
|
|
434
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [x] T-001: 已完成\n```\n- [ ] T-099:示例写法\n```\n');
|
|
435
|
+
assert.equal(reapproveRaw(f).approveRefused,undefined);assert.equal(readSpecsStatus(f.specsDir).value.taskGrammar,2);
|
|
436
|
+
// Once on the shared grammar, later approvals need no reconciliation: a real
|
|
437
|
+
// full-width task written afterwards is a task.
|
|
438
|
+
fs.appendFileSync(f.file('tasks.md'),'- [ ] T-002:新任务\n');
|
|
439
|
+
const prior=readSpecsStatus(f.specsDir).value;
|
|
440
|
+
writeSpecsStatus(f.specsDir,{status:'awaiting_review',summaryDigest:'a'.repeat(64),at:new Date().toISOString(),
|
|
441
|
+
features:prior.features,specFiles:buildManifest(f.specsDir),testCases:[],approval:null,taskGrammar:2});
|
|
442
|
+
assert.equal(approveCmAiSpecs({specsDir:f.specsDir,codeProject:f.codeProject,approvalResponse:'开始'}).approveRefused,undefined);
|
|
443
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-002');
|
|
444
|
+
});
|
|
445
|
+
test('a first approval with no earlier status binds the shared grammar directly',t=>{
|
|
446
|
+
const f=fixture(t);
|
|
447
|
+
fs.rmSync(path.join(f.specsDir,'.cm-specs-status'));
|
|
448
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001:全角冒号任务\n');
|
|
449
|
+
assert.equal(approveCmAiSpecs({specsDir:f.specsDir,codeProject:f.codeProject,approvalResponse:'开始'}).approveRefused,undefined);
|
|
450
|
+
assert.equal(readSpecsStatus(f.specsDir).value.taskGrammar,2);
|
|
451
|
+
assert.equal(inspectCmAiAdmission({specsDir:f.specsDir,codeProject:f.codeProject}).nextTask.id,'T-001');
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
test('a parallel batch member is offered only the spec revert exit',async()=>{
|
|
455
|
+
const {batchMemberResult}=await import('./cm-ai-batch-run.mjs');
|
|
456
|
+
const drift={state:'blocked',code:'spec_drift',pendingAction:'spec_rebind',reason:'变更文件:1.work/tasks.md;需要换绑'};
|
|
457
|
+
const parallel=batchMemberResult(drift,{parallel:true}),serial=batchMemberResult(drift);
|
|
458
|
+
assert.equal(parallel.pendingAction,'none');assert.match(parallel.reason,/还原这些规格改动/);
|
|
459
|
+
assert.match(parallel.reason,/并行组成员没有单独重做的出口/);assert.doesNotMatch(parallel.reason,/--supersede-reviewed-evidence|取消本批次/);
|
|
460
|
+
assert.match(serial.reason,/--supersede-reviewed-evidence/);
|
|
461
|
+
const other={state:'awaiting_review',pendingAction:'none'};assert.equal(batchMemberResult(other,{parallel:true}),other);
|
|
462
|
+
});
|
|
463
|
+
// Batch members cannot take --rebind-spec-material (a single-task resume flag),
|
|
464
|
+
// so the batch never advertises spec_rebind; it names the exits that exist.
|
|
465
|
+
test('a batch member never advertises spec_rebind and names the real exits',async t=>{
|
|
466
|
+
const f=fixture(t),{createCmAiBatch}=await import('./cm-ai-batch-run.mjs');
|
|
467
|
+
const git=args=>assert.equal(spawnSync('git',['-C',f.codeProject,...args],{encoding:'utf8'}).status,0);
|
|
468
|
+
git(['init','-q','-b','main']);git(['config','user.name','F']);git(['config','user.email','f@example.invalid']);
|
|
469
|
+
git(['add','-A']);git(['commit','-qm','base']);
|
|
470
|
+
const batch=()=>createCmAiBatch({configuration:{version:1,repositoryId:'rebind-fixture',batchId:'rebind-batch-1',
|
|
471
|
+
specsDir:f.specsDir,codeProject:f.codeProject,tasks:['T-001','T-002'].map(taskId=>({feature:f.feature,taskId,
|
|
472
|
+
scope:[taskId==='T-001'?'a.mjs':'b.mjs'],requirements:['requirements.md']}))},
|
|
473
|
+
executionFor:async()=>executionFor(f),logHome:path.join(f.root,'batch-logs')});
|
|
474
|
+
const first=await batch().handle({operation:'advance',requestId:'batch-advance'});
|
|
475
|
+
assert.equal(first.state,'awaiting_review',JSON.stringify(first));
|
|
476
|
+
fs.writeFileSync(f.file('tasks.md'),'# tasks\n- [ ] T-001: 修改 a\n- [ ] T-002: 新增 b 改\n\n- T-002 依赖 T-001\n');reapprove(f);
|
|
477
|
+
const status=await batch().handle({operation:'status',requestId:'batch-status'});
|
|
478
|
+
assert.equal(status.code,'spec_drift');assert.equal(status.pendingAction,'none');
|
|
479
|
+
assert.match(status.reason,/1\.work\/tasks\.md/);assert.match(status.reason,/批次成员不能换绑/);
|
|
480
|
+
assert.match(status.reason,/--supersede-reviewed-evidence/);assert.doesNotMatch(status.reason,/--rebind-spec-material/);
|
|
481
|
+
});
|