@aibyzero/cm-workflow 0.16.3 → 0.16.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.codex-plugin/plugin.json +1 -1
- package/AGENTS.md +8 -0
- package/CHANGELOG.md +59 -0
- package/README.md +55 -3
- package/VERSION +1 -1
- package/docs/installation.md +21 -1
- package/docs/js-workflow-control.md +245 -33
- package/docs/next-steps.md +14 -24
- package/docs/runtime-failover.md +1 -1
- package/package.json +1 -1
- package/runtime/js/cm-ai/accepted-fix.mjs +23 -5
- package/runtime/js/cm-ai/bootstrap-feature.mjs +15 -0
- package/runtime/js/cm-ai/claude-review-stream.mjs +30 -0
- package/runtime/js/cm-ai/cm-ai-admission.mjs +116 -41
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +3 -2
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +137 -22
- package/runtime/js/cm-ai/cm-ai-learning-handoff-writer.mjs +11 -9
- package/runtime/js/cm-ai/cm-ai-learning-writer.mjs +22 -5
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +180 -53
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +2 -1
- package/runtime/js/cm-ai/codex-review-adapter.mjs +24 -4
- package/runtime/js/cm-ai/developer-adapter.mjs +6 -2
- package/runtime/js/cm-ai/diagnostic-reason.mjs +10 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +305 -0
- package/runtime/js/cm-ai/drive-core.mjs +39 -7
- package/runtime/js/cm-ai/durable-runner-state.mjs +307 -53
- package/runtime/js/cm-ai/effect-abandon-log.mjs +19 -0
- package/runtime/js/cm-ai/effect-contract.mjs +44 -2
- package/runtime/js/cm-ai/execution-store-limits.mjs +18 -0
- package/runtime/js/cm-ai/execution-store.mjs +6 -4
- package/runtime/js/cm-ai/fix-code-association.mjs +171 -18
- package/runtime/js/cm-ai/host-bootstrap.mjs +68 -21
- package/runtime/js/cm-ai/host-conversation-execution.mjs +16 -4
- package/runtime/js/cm-ai/host-handoff.mjs +13 -6
- package/runtime/js/cm-ai/host-qa-executor.mjs +21 -7
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +4 -4
- package/runtime/js/cm-ai/host-qa-policy.mjs +16 -7
- package/runtime/js/cm-ai/host-session.mjs +20 -5
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +13 -4
- package/runtime/js/cm-ai/host.mjs +1 -1
- package/runtime/js/cm-ai/launch-mismatch.mjs +42 -0
- package/runtime/js/cm-ai/log-rows.mjs +21 -0
- package/runtime/js/cm-ai/project-qa-gate.mjs +84 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +53 -9
- package/runtime/js/cm-ai/qa-config-revision.mjs +44 -10
- package/runtime/js/cm-ai/review-abandon-log.mjs +21 -0
- package/runtime/js/cm-ai/review-package.mjs +427 -31
- package/runtime/js/cm-ai/review-runner.mjs +47 -1
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +97 -0
- package/runtime/js/cm-ai/reviewed-evidence-supersede.mjs +104 -10
- package/runtime/js/cm-ai/reviewed-evidence-supersession-record.mjs +42 -3
- package/runtime/js/cm-ai/specification-material.mjs +154 -12
- package/runtime/js/cm-ai/task-commit.mjs +2 -2
- package/runtime/js/cm-ai/task-runner.mjs +502 -65
- package/runtime/js/cm-ai/worker-claude-developer.mjs +16 -7
- package/runtime/js/cm-fix/execution.mjs +109 -25
- package/runtime/js/cm-fix/host-review.mjs +7 -3
- package/runtime/js/cm-fix/host.mjs +3 -1
- package/runtime/js/cm-fix/progress.mjs +1 -0
- package/runtime/js/cm-fix/protected-edits.mjs +15 -4
- package/runtime/js/cm-fix/qa-source.mjs +6 -4
- package/runtime/js/cm-prd/analysis.mjs +2 -1
- package/runtime/js/cm-prd/change.mjs +28 -10
- package/runtime/js/cm-prd/draft.mjs +5 -2
- package/runtime/js/cm-prd/review-preparation.mjs +10 -3
- package/runtime/js/cm-prd/review-publication.mjs +4 -2
- package/runtime/js/cm-prd/self-check.mjs +6 -3
- package/runtime/js/cm-prd/summary.mjs +6 -2
- package/runtime/js/cm-prd/validation-reason.mjs +20 -0
- package/runtime/js/spec-task-line.mjs +117 -0
- package/runtime/js/specs-status.mjs +14 -3
- package/scripts/cm-ai-abandon-effect-position.test.mjs +201 -0
- package/scripts/cm-ai-admission.mjs +19 -10
- package/scripts/cm-ai-admission.test.mjs +65 -1
- package/scripts/cm-ai-batch-drive.mjs +93 -21
- package/scripts/cm-ai-batch-drive.test.mjs +171 -3
- package/scripts/cm-ai-batch-host.mjs +37 -13
- package/scripts/cm-ai-batch-host.test.mjs +26 -0
- package/scripts/cm-ai-batch-run.mjs +33 -10
- package/scripts/cm-ai-batch-run.test.mjs +56 -5
- package/scripts/cm-ai-bootstrap-driver-preflight.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap-flow.test.mjs +158 -0
- package/scripts/cm-ai-bootstrap-merge.test.mjs +45 -0
- package/scripts/cm-ai-bootstrap.test.mjs +99 -7
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +82 -2
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +822 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +468 -0
- package/scripts/cm-ai-drive-timeout.test.mjs +17 -0
- package/scripts/cm-ai-drive.mjs +480 -47
- package/scripts/cm-ai-drive.test.mjs +247 -10
- package/scripts/cm-ai-fix-later-delivery.test.mjs +383 -0
- package/scripts/cm-ai-host.mjs +89 -25
- package/scripts/cm-ai-host.test.mjs +274 -12
- package/scripts/cm-ai-launch-diagnostics.test.mjs +142 -0
- package/scripts/cm-ai-multi-root.test.mjs +9 -3
- package/scripts/cm-ai-project-qa-gate.test.mjs +308 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +166 -15
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +157 -0
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +27 -2
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +400 -0
- package/scripts/cm-ai-review-drift-precedence.test.mjs +90 -0
- package/scripts/cm-ai-review-failure.test.mjs +917 -0
- package/scripts/cm-ai-review-timeout-config.test.mjs +29 -7
- package/scripts/cm-ai-review-timeout.test.mjs +199 -4
- package/scripts/cm-ai-run.mjs +160 -60
- package/scripts/cm-ai-run.test.mjs +4 -3
- package/scripts/cm-ai-runner-error-code-regression.test.mjs +219 -0
- package/scripts/cm-ai-selection-guard.test.mjs +100 -0
- package/scripts/cm-ai-session-chain.test.mjs +7 -3
- package/scripts/cm-ai-spec-rebind.test.mjs +481 -0
- package/scripts/cm-ai-supersede.test.mjs +571 -17
- package/scripts/cm-ai-verification-gate.test.mjs +2 -1
- package/scripts/cm-capability-gate.test.mjs +21 -2
- package/scripts/cm-check-drive.mjs +4 -3
- package/scripts/cm-check-drive.test.mjs +17 -1
- package/scripts/cm-check-entry.mjs +13 -2
- package/scripts/cm-check-host.mjs +2 -2
- package/scripts/cm-check-host.test.mjs +57 -1
- package/scripts/cm-check-runtime.sh +16 -7
- package/scripts/cm-claude-developer-worker.test.mjs +43 -2
- package/scripts/cm-claude-probe.test.mjs +9 -1
- package/scripts/cm-claude-review-stream.test.mjs +68 -0
- package/scripts/cm-claude-worker.test.mjs +11 -4
- package/scripts/cm-codex-developer-worker.test.mjs +4 -2
- package/scripts/cm-failover.mjs +8 -8
- package/scripts/cm-fix-abandon.test.mjs +123 -5
- package/scripts/cm-fix-cause-package.test.mjs +2 -0
- package/scripts/cm-fix-drive.mjs +45 -13
- package/scripts/cm-fix-drive.test.mjs +36 -1
- package/scripts/cm-fix-host.mjs +9 -6
- package/scripts/cm-fix-review-budget.test.mjs +141 -0
- package/scripts/cm-fixture-process-cleanup.test.mjs +95 -0
- package/scripts/cm-host-check.test.mjs +6 -3
- package/scripts/cm-host-qa-executor.test.mjs +192 -17
- package/scripts/cm-host-session-diagnostic.test.mjs +10 -0
- package/scripts/cm-interactive-qa-diagnostic.test.mjs +53 -0
- package/scripts/cm-log-event.mjs +17 -0
- package/scripts/cm-log-event.test.mjs +31 -0
- package/scripts/cm-prd-completion.test.mjs +105 -2
- package/scripts/cm-prd-draft.test.mjs +14 -0
- package/scripts/cm-prd-drive.mjs +13 -7
- package/scripts/cm-prd-drive.test.mjs +10 -0
- package/scripts/cm-prd-gate-diagnostic.test.mjs +100 -0
- package/scripts/cm-prd-review-gate.mjs +126 -81
- package/scripts/cm-prd-review-gate.test.mjs +105 -1
- package/scripts/cm-prd-review-preparation.test.mjs +15 -0
- package/scripts/cm-prd-review-publication.test.mjs +6 -0
- package/scripts/cm-prd-self-check.test.mjs +6 -0
- package/scripts/cm-prd-summary.test.mjs +40 -0
- package/scripts/cm-review-dependency-snapshot.test.mjs +15 -0
- package/scripts/cm-review-inventory.test.mjs +253 -1
- package/scripts/cm-spec-manifest.mjs +28 -10
- package/scripts/cm-spec-manifest.test.mjs +8 -4
- package/scripts/cm-spec-task-line.test.mjs +138 -0
- package/scripts/cm-specs-status.test.mjs +31 -1
- package/scripts/cm-task-gate.mjs +18 -10
- package/scripts/cm-task-gate.py +1 -1
- package/scripts/cm-test-branch-impact.test.mjs +6 -3
- package/scripts/fixtures/claude-review-process.mjs +1 -0
- package/scripts/fixtures/process-cleanup.mjs +99 -0
- package/scripts/test-cm-log-event.py +2 -0
- package/scripts/test-cm-prd-review-gate.py +2 -1
- package/scripts/test-npm-install.py +1 -1
- package/scripts/test-scan-public-safety.py +1 -1
- package/scripts/test-shell-compat.sh +67 -0
- package/scripts/test-spec-manifest.py +16 -8
- package/scripts/test-task-gate.py +2 -2
- package/scripts/test-workflow-config.py +1 -0
- package/scripts/validate-public-repo.py +1 -0
- package/skills/cm-ai/references/N1-init.md +1 -1
- package/skills/cm-ai/references/js-host.md +264 -40
- package/skills/cm-check/SKILL.md +6 -1
- package/skills/cm-check/references/js-host.md +3 -3
- package/skills/cm-fix/references/js-host.md +22 -1
- package/skills/cm-prd/references/js-change-recovery.md +30 -0
- package/skills/cm-prd/references/js-host.md +6 -0
|
@@ -3,11 +3,11 @@ import assert from 'node:assert/strict';
|
|
|
3
3
|
import fs from 'node:fs';
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import os from 'node:os';
|
|
6
|
-
import {spawn} from 'node:child_process';
|
|
6
|
+
import {spawn,spawnSync} from 'node:child_process';
|
|
7
7
|
import {once} from 'node:events';
|
|
8
8
|
import {createInterface} from 'node:readline';
|
|
9
9
|
import {fileURLToPath} from 'node:url';
|
|
10
|
-
import {inspectPrdChangeSnapshot,inspectPrdChangeProposal,applyPrdChange} from '../runtime/js/cm-prd/change.mjs';
|
|
10
|
+
import {inspectPrdChangeSnapshot,inspectPrdChangeProposal,applyPrdChange,assertPrdReviewsSettled} from '../runtime/js/cm-prd/change.mjs';
|
|
11
11
|
import {loadConfig} from './cm-workflow-config.mjs';
|
|
12
12
|
import {recordPrdReview} from './cm-prd-review-gate.mjs';
|
|
13
13
|
|
|
@@ -83,6 +83,34 @@ test('actual change CLI resumes unsaved phase across processes and stops at huma
|
|
|
83
83
|
c=await client(t,dir,()=>assert.fail('completed recovery must not call host'),{session:runId});
|
|
84
84
|
assert.equal((await c.request('status')).result.stage,'awaiting_review');await c.close();
|
|
85
85
|
});
|
|
86
|
+
test('approved change retains revision history for the next real cm-prd change',t=>{
|
|
87
|
+
const dir=fixture(t),reviews=path.join(dir,'.reviews');fs.mkdirSync(reviews);
|
|
88
|
+
const evidence=path.join(reviews,'prd-guide-split-r1.md'),receipt=path.join(reviews,'prd-guide-split-disposition.json');
|
|
89
|
+
fs.writeFileSync(evidence,'---\nat: 2026-09-08T00:00:00Z\nreviewer: codex-subagent\nindependent: true\nscope:\n - 1.guide/tasks.md\n---\nSynthetic original review');
|
|
90
|
+
recordPrdReview({stage:'split',feature:'guide',evidence,receipt,disposition:'no_findings',finding_count:0,unresolved_count:0,
|
|
91
|
+
artifact:docs().map(doc=>path.join(dir,'1.guide',doc.path))});
|
|
92
|
+
const selected=['1.guide'],config=loadConfig({projectRoot:dir});
|
|
93
|
+
const before=inspectPrdChangeSnapshot(dir);
|
|
94
|
+
const proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'Add example',removed:[],features:[
|
|
95
|
+
{directory:'1.guide',documents:revised(),testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
96
|
+
const proposalDigest=proposal.proposalDigest;
|
|
97
|
+
const saved=applyPrdChange({specs:dir,before,proposal,selected});
|
|
98
|
+
assert.equal(saved.status,'awaiting_review');
|
|
99
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'))).revisionDigest,proposalDigest);
|
|
100
|
+
const approval=spawnSync(process.execPath,[path.join(root,'scripts/cm-ai-admission.mjs'),'--specs-dir',dir,
|
|
101
|
+
'--code-project',dir,'--approve','--approval-response','开始'],{encoding:'utf8'});
|
|
102
|
+
assert.equal(approval.status,0,approval.stdout+approval.stderr);
|
|
103
|
+
assert.doesNotThrow(()=>assertPrdReviewsSettled(dir,['1.guide'],{requireSplit:true}));
|
|
104
|
+
const nextDocs=revised().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v2 | change |',
|
|
105
|
+
'| 2026-09-08 | v2 | change |\n| 2026-09-08 | v3 | another change |')+
|
|
106
|
+
(doc.path==='tasks.md'?'\n- [ ] T-004: [NEW] More examples\n':'\nMore detail\n')}));
|
|
107
|
+
const nextBefore=inspectPrdChangeSnapshot(dir);
|
|
108
|
+
const nextProposal=inspectPrdChangeProposal(nextBefore,{status:'draft',summary:'Another guide change',removed:[],features:[
|
|
109
|
+
{directory:'1.guide',documents:nextDocs,testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
110
|
+
const secondSaved=applyPrdChange({specs:dir,before:nextBefore,proposal:nextProposal,selected});
|
|
111
|
+
assert.equal(secondSaved.status,'awaiting_review');
|
|
112
|
+
assert.equal(JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'))).revisionDigest,nextProposal.proposalDigest);
|
|
113
|
+
});
|
|
86
114
|
test('unknown host generation resumes only its exact original receipt, no repeat call', {timeout:25000},async t=>{
|
|
87
115
|
const dir=fixture(t);let original;
|
|
88
116
|
let c=await client(t,dir,message=>{
|
|
@@ -127,6 +155,81 @@ test('change cannot invent completion or erase completed lines; user case change
|
|
|
127
155
|
const synthetic={...before,files:{...before.files,'1.guide/test-cases.json':JSON.stringify({cases:[{id:'TC-001',origin:'user',expected:'Original user intent'}]})}};
|
|
128
156
|
const proposal=inspectPrdChangeProposal(synthetic,raw,['1.guide'],config);assert.equal(proposal.changedUserCases.length,1);
|
|
129
157
|
});
|
|
158
|
+
// Same declaration grammar as admission/N5: a completed task without a colon is still guarded.
|
|
159
|
+
test('change guards completed tasks written without a colon or with a full-width colon',t=>{
|
|
160
|
+
const dir=fixture(t),config=loadConfig({projectRoot:dir});
|
|
161
|
+
// Approved under the shared grammar (taskGrammar 2), where both spellings are declarations.
|
|
162
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'approved',taskGrammar:2}),{mode:0o600});
|
|
163
|
+
for(const spelling of ['- [x] T-001 Existing guide','- [x] T-001:Existing guide']){
|
|
164
|
+
fs.writeFileSync(path.join(dir,'1.guide/tasks.md'),docs()[2].content.replace('- [x] T-001: Existing guide',spelling),{mode:0o600});
|
|
165
|
+
const before=inspectPrdChangeSnapshot(dir),task=revised().find(doc=>doc.path==='tasks.md');
|
|
166
|
+
const erased={status:'draft',summary:'Change',removed:[],features:[{directory:'1.guide',
|
|
167
|
+
documents:revised().map(doc=>doc.path==='tasks.md'?{...doc,content:task.content.replace('- [x] T-001: Existing guide',spelling.replace('[x]','[ ]'))}:doc),
|
|
168
|
+
testCasesReason:'no_observable_behavior'}]};
|
|
169
|
+
assert.throws(()=>inspectPrdChangeProposal(before,erased,['1.guide'],config),/prd_completed_task_changed/,spelling);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
// The approved original is read with its approval's grammar: under a legacy
|
|
173
|
+
// approval an unfenced full-width example is prose, not the completed task.
|
|
174
|
+
test('change guard reads the approved original with the legacy grammar',t=>{
|
|
175
|
+
const dir=fixture(t),config=loadConfig({projectRoot:dir}),example='- [ ] T-001:旧写法示例';
|
|
176
|
+
fs.writeFileSync(path.join(dir,'1.guide/tasks.md'),docs()[2].content.replace('- [x] T-001: Existing guide\n',
|
|
177
|
+
`- [x] T-001: Existing guide\n${example}\n`),{mode:0o600});
|
|
178
|
+
const before=inspectPrdChangeSnapshot(dir),task=revised().find(doc=>doc.path==='tasks.md');
|
|
179
|
+
const fenced={status:'draft',summary:'Fence the old example',removed:[],features:[{directory:'1.guide',
|
|
180
|
+
documents:revised().map(doc=>doc.path==='tasks.md'?{...doc,content:task.content.replace('- [x] T-001: Existing guide\n',
|
|
181
|
+
`- [x] T-001: Existing guide\n\`\`\`md\n${example}\n\`\`\`\n`)}:doc),testCasesReason:'no_observable_behavior'}]};
|
|
182
|
+
const proposal=inspectPrdChangeProposal(before,fenced,['1.guide'],config);
|
|
183
|
+
assert.equal(proposal.proposalDigest.length,64);
|
|
184
|
+
});
|
|
185
|
+
// Fifth review: two cm-prd --change runs before re-approval keep the grammar the
|
|
186
|
+
// last approval bound, carried through the awaiting_review status of the first.
|
|
187
|
+
function sharedGrammarFixture(t){
|
|
188
|
+
const dir=fixture(t),tasks=path.join(dir,'1.guide/tasks.md');
|
|
189
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
190
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'approved',taskGrammar:2}),{mode:0o600});
|
|
191
|
+
return dir;
|
|
192
|
+
}
|
|
193
|
+
const fullWidth=docs=>docs.map(doc=>doc.path==='tasks.md'?{...doc,content:doc.content.replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix')}:doc);
|
|
194
|
+
const status=dir=>JSON.parse(fs.readFileSync(path.join(dir,'.cm-specs-status'),'utf8'));
|
|
195
|
+
test('a second change of the same feature before re-approval keeps the approved grammar',t=>{
|
|
196
|
+
const dir=sharedGrammarFixture(t),config=loadConfig({projectRoot:dir}),selected=['1.guide'];
|
|
197
|
+
const first=fullWidth(revised());
|
|
198
|
+
let before=inspectPrdChangeSnapshot(dir);
|
|
199
|
+
let proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'First',removed:[],features:[{directory:'1.guide',
|
|
200
|
+
documents:first,testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
201
|
+
applyPrdChange({specs:dir,before,proposal,selected});
|
|
202
|
+
assert.equal(status(dir).status,'awaiting_review');assert.equal(status(dir).taskGrammar,2);
|
|
203
|
+
const second=first.map(doc=>({...doc,content:doc.content+'\n| 2026-09-08 | v3 | again |\n'
|
|
204
|
+
+(doc.path==='tasks.md'?'- [ ] T-004: [NEW] Another example\n':'Again\n')}));
|
|
205
|
+
before=inspectPrdChangeSnapshot(dir);
|
|
206
|
+
proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'Second',removed:[],features:[{directory:'1.guide',
|
|
207
|
+
documents:second,testCasesReason:'no_observable_behavior'}]},selected,config);
|
|
208
|
+
applyPrdChange({specs:dir,before,proposal,selected});
|
|
209
|
+
assert.equal(status(dir).taskGrammar,2);
|
|
210
|
+
});
|
|
211
|
+
test('a second change of another feature before re-approval still carries the approved grammar',t=>{
|
|
212
|
+
const dir=sharedGrammarFixture(t),config=loadConfig({projectRoot:dir});
|
|
213
|
+
let before=inspectPrdChangeSnapshot(dir);
|
|
214
|
+
let proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'First',removed:[],features:[{directory:'1.guide',
|
|
215
|
+
documents:fullWidth(revised()),testCasesReason:'no_observable_behavior'}]},['1.guide'],config);
|
|
216
|
+
applyPrdChange({specs:dir,before,proposal,selected:['1.guide']});
|
|
217
|
+
before=inspectPrdChangeSnapshot(dir);
|
|
218
|
+
proposal=inspectPrdChangeProposal(before,{status:'draft',summary:'Second',removed:[],features:[{directory:'2.extra',
|
|
219
|
+
documents:docs().map(doc=>({...doc,content:doc.content.replace('[x]','[ ]')})),testCasesReason:'no_observable_behavior'}]},[],config);
|
|
220
|
+
applyPrdChange({specs:dir,before,proposal,selected:[]});
|
|
221
|
+
assert.equal(status(dir).status,'awaiting_review');assert.equal(status(dir).taskGrammar,2);
|
|
222
|
+
});
|
|
223
|
+
test('an unapproved legacy status never switches the change guard to the shared grammar',t=>{
|
|
224
|
+
const dir=fixture(t),config=loadConfig({projectRoot:dir}),tasks=path.join(dir,'1.guide/tasks.md');
|
|
225
|
+
fs.writeFileSync(tasks,fs.readFileSync(tasks,'utf8').replace('- [ ] T-002: Draft appendix','- [ ] T-002:Draft appendix'),{mode:0o600});
|
|
226
|
+
fs.writeFileSync(path.join(dir,'.cm-specs-status'),JSON.stringify({status:'awaiting_review'}),{mode:0o600});
|
|
227
|
+
const before=inspectPrdChangeSnapshot(dir);
|
|
228
|
+
// Under the old grammar the full-width line is prose, so rewriting it as a
|
|
229
|
+
// task in the proposal is a new task and needs its [NEW] mark.
|
|
230
|
+
assert.throws(()=>inspectPrdChangeProposal(before,{status:'draft',summary:'Change',removed:[],features:[{directory:'1.guide',
|
|
231
|
+
documents:revised(),testCasesReason:'no_observable_behavior'}]},['1.guide'],config),/prd_change_new_task_invalid/);
|
|
232
|
+
});
|
|
130
233
|
test('generate_cases false retains unchanged existing generated cases, forbids new generation',t=>{
|
|
131
234
|
const dir=fixture(t),before=inspectPrdChangeSnapshot(dir),config=loadConfig({projectRoot:dir});
|
|
132
235
|
const contract={schemaVersion:'1.0',feature:'guide',cases:[{id:'TC-001',origin:'generated',kind:'logic',blocking:true,
|
|
@@ -18,6 +18,20 @@ test('draft structure refuses missing triad, unsafe path and dropped user cases'
|
|
|
18
18
|
const unsafe=draft();unsafe.features[0].documents[0].path='../AGENTS.md';assert.throws(()=>inspectPrdDraft(unsafe,options));
|
|
19
19
|
assert.throws(()=>inspectPrdDraft(draft(),{...options,userCasesProvided:true}));
|
|
20
20
|
});
|
|
21
|
+
test('draft case reason identifies the feature field without accepting non-null values',()=>{
|
|
22
|
+
const value=draft(),feature=value.features[0];
|
|
23
|
+
feature.documents.push({path:'test-cases.json',content:JSON.stringify({schemaVersion:'1.0',feature:'guide',cases:[]})});
|
|
24
|
+
assert.throws(()=>inspectPrdDraft(value,{nextIndex:1,generateCases:true,userCasesProvided:false}),error=>
|
|
25
|
+
error.code==='prd_draft_cases_invalid'&&error.reason?.field==='features[0].testCasesReason'
|
|
26
|
+
&&/must be null when test cases are present/.test(error.reason.expected));
|
|
27
|
+
});
|
|
28
|
+
test('oversize draft reports the 64 KiB limit and actual serialized bytes',()=>{
|
|
29
|
+
const value=draft();value.summary='a'.repeat(65536);
|
|
30
|
+
const actual=Buffer.byteLength(JSON.stringify(value));
|
|
31
|
+
assert.throws(()=>inspectPrdDraft(value,{nextIndex:1,generateCases:true,userCasesProvided:false}),error=>
|
|
32
|
+
error.code==='limit_exceeded'&&error.reason?.field==='draft'
|
|
33
|
+
&&error.reason.limitBytes===65536&&error.reason.actualBytes===actual);
|
|
34
|
+
});
|
|
21
35
|
test('analysis -> planner clarification -> draft preserves scope and does not write',async t=>{
|
|
22
36
|
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-draft-')));
|
|
23
37
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
package/scripts/cm-prd-drive.mjs
CHANGED
|
@@ -274,17 +274,23 @@ function validate(kind,value,ctx){
|
|
|
274
274
|
}
|
|
275
275
|
}
|
|
276
276
|
let loaded;
|
|
277
|
+
export async function runPrdContextChecks(cwd,commands){
|
|
278
|
+
const results=[];
|
|
279
|
+
for(const command of commands){
|
|
280
|
+
const run=createHostCheck({cwd,commands:[command],onOutput:({stream,chunk})=>{
|
|
281
|
+
process.stderr.write(`[drive check ${command.id} ${stream}] ${chunk}`);
|
|
282
|
+
}});
|
|
283
|
+
const [item]=await run({identity:{repositoryId:'prd',runId:'prd-check',taskId:'prd-check',attempt:1}},
|
|
284
|
+
{signal:new AbortController().signal});
|
|
285
|
+
results.push(item);if(item.outcome!=='passed')break;
|
|
286
|
+
}
|
|
287
|
+
return results;
|
|
288
|
+
}
|
|
277
289
|
async function answerFor(row,answers){
|
|
278
290
|
const v=answers[row.kind];
|
|
279
291
|
if(row.kind==='prd_materials')return null;
|
|
280
292
|
if(row.kind==='prd_self_check'){
|
|
281
|
-
const results=
|
|
282
|
-
for(const command of loaded.plan.contextChecks){
|
|
283
|
-
const run=createHostCheck({cwd:loaded.admission.project,commands:[command],onOutput:({stream,chunk})=>process.stderr.write(`[drive check ${command.id} ${stream}] ${chunk}`)});
|
|
284
|
-
const [item]=await run({identity:{repositoryId:'prd',runId:'prd-check',taskId:'prd-check',attempt:1}},
|
|
285
|
-
{signal:new AbortController().signal});
|
|
286
|
-
results.push(item);if(item.outcome!=='passed')break;
|
|
287
|
-
}
|
|
293
|
+
const results=await runPrdContextChecks(loaded.admission.project,loaded.plan.contextChecks);
|
|
288
294
|
const draft=row.payload.draft;const evidence=results.map(r=>`${r.id}: ${r.evidence}`);
|
|
289
295
|
return {draftDigest:draft.draftDigest,features:draft.features.map(f=>({directory:f.directory,
|
|
290
296
|
checks:draft.mechanicalSelfCheck.pending.map(id=>({id,status:results.every(r=>r.outcome==='passed')?
|
|
@@ -6,6 +6,7 @@ import path from 'node:path';
|
|
|
6
6
|
import {spawn,spawnSync} from 'node:child_process';
|
|
7
7
|
import {createInterface} from 'node:readline';
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {runPrdContextChecks} from './cm-prd-drive.mjs';
|
|
9
10
|
|
|
10
11
|
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
11
12
|
const driver=path.join(root,'scripts/cm-prd-drive.mjs');
|
|
@@ -33,6 +34,15 @@ const draft={status:'draft',summary:'Synthetic documentation draft',features:[{n
|
|
|
33
34
|
documents:[{path:'requirements.md',content:'## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Document setup.'},
|
|
34
35
|
{path:'design.md',content:'## 方案摘要\nSynthetic design'},
|
|
35
36
|
{path:'tasks.md',content:'- [ ] T-001: Update guide'}]}]};
|
|
37
|
+
test('contextChecks with stdout and stderr record a passed command',async t=>{
|
|
38
|
+
const f=fixture(t);
|
|
39
|
+
const checks=await runPrdContextChecks(f.project,[{id:'output',command:[process.execPath,'-e',
|
|
40
|
+
"console.log('x');console.error('y')"]}]);
|
|
41
|
+
assert.notEqual(checks[0].evidence,'host check: output_capture_failed');
|
|
42
|
+
assert.equal(checks[0].outcome,'passed');
|
|
43
|
+
assert.equal(checks[0].exitCode,0);
|
|
44
|
+
assert.match(checks[0].evidence,/exited 0/);
|
|
45
|
+
});
|
|
36
46
|
function draftReady(t){
|
|
37
47
|
const f=fixture(t);f.write('analyze.json',analyzed);f.write('generate.json',draft);
|
|
38
48
|
const start=f.drive('start');assert.equal(start.status,0,start.stderr);
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// A review-gate refusal inside the real cm-prd host must reach the operator as a
|
|
2
|
+
// stable code and a reason naming the receipt and artifact (stderr only), instead
|
|
3
|
+
// of host_request_failed with detail:"unavailable". The peer reply is unchanged.
|
|
4
|
+
import test,{after} from 'node:test';
|
|
5
|
+
import assert from 'node:assert/strict';
|
|
6
|
+
import fs from 'node:fs';
|
|
7
|
+
import path from 'node:path';
|
|
8
|
+
import os from 'node:os';
|
|
9
|
+
import {spawn} from 'node:child_process';
|
|
10
|
+
import {once} from 'node:events';
|
|
11
|
+
import {createInterface} from 'node:readline';
|
|
12
|
+
import {fileURLToPath} from 'node:url';
|
|
13
|
+
import {recordPrdReview} from './cm-prd-review-gate.mjs';
|
|
14
|
+
|
|
15
|
+
// Runtime declarations and log mirrors never touch the invoking user's home.
|
|
16
|
+
const isolatedHome=fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gate-diagnostic-home-'));
|
|
17
|
+
process.env.CM_WORKFLOW_HOME=path.join(isolatedHome,'user');
|
|
18
|
+
process.env.CM_WORKFLOW_LOG_HOME=path.join(isolatedHome,'logs');
|
|
19
|
+
after(()=>fs.rmSync(isolatedHome,{recursive:true,force:true}));
|
|
20
|
+
const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'..');
|
|
21
|
+
|
|
22
|
+
const version='\n| 日期 | 版本 | 说明 |\n| --- | --- | --- |\n| 2026-09-08 | v1 | original |\n';
|
|
23
|
+
const docs=()=>[
|
|
24
|
+
{path:'requirements.md',content:'## 需求版本'+version+'\n## 功能需求\n1. [F-001] Guide\n- [ ] [AC-001] Read guide\n'},
|
|
25
|
+
{path:'design.md',content:'## 设计版本'+version+'\n## 方案摘要\nExisting guide\n'},
|
|
26
|
+
{path:'tasks.md',content:'## 任务版本'+version+'\n- [x] T-001: Existing guide\n- [ ] T-002: Draft appendix\n'}];
|
|
27
|
+
const revised=()=>docs().map(doc=>({path:doc.path,content:doc.content.replace('| 2026-09-08 | v1 | original |',
|
|
28
|
+
'| 2026-09-08 | v1 | original |\n| 2026-09-08 | v2 | change |')+(doc.path==='tasks.md'?'\n- [ ] T-003: [NEW] Add example\n':'\nUpdated example\n')}));
|
|
29
|
+
|
|
30
|
+
function fixture(t){
|
|
31
|
+
const dir=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-prd-gate-diagnostic-')));
|
|
32
|
+
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
33
|
+
fs.mkdirSync(path.join(dir,'docs'));fs.writeFileSync(path.join(dir,'docs/input.md'),'Synthetic guide');
|
|
34
|
+
fs.mkdirSync(path.join(dir,'1.guide'));
|
|
35
|
+
for(const doc of docs())fs.writeFileSync(path.join(dir,'1.guide',doc.path),doc.content,{mode:0o600});
|
|
36
|
+
const reviews=path.join(dir,'.reviews');fs.mkdirSync(reviews,{mode:0o700});
|
|
37
|
+
const evidence=path.join(reviews,'prd-guide-split-r1.md'),receipt=path.join(reviews,'prd-guide-split-disposition.json');
|
|
38
|
+
fs.writeFileSync(evidence,'---\nat: 2026-09-08T00:00:00Z\nreviewer: codex-subagent\nindependent: true\nscope:\n - 1.guide/tasks.md\n---\nSynthetic original review',{mode:0o600});
|
|
39
|
+
recordPrdReview({stage:'split',feature:'guide',evidence,receipt,disposition:'no_findings',finding_count:0,unresolved_count:0,
|
|
40
|
+
artifact:docs().map(doc=>path.join(dir,'1.guide',doc.path))});
|
|
41
|
+
return dir;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Drives the real host: start -> confirmation -> decision -> save_draft.
|
|
45
|
+
async function hostChange(t,dir){
|
|
46
|
+
const child=spawn(process.execPath,[path.join(root,'scripts/cm-prd-host.mjs'),'serve','--skill-dir',path.join(root,'skills/cm-prd'),
|
|
47
|
+
'--project',dir,'--specs',dir,'--runtime','codex','--allow-log-write','--allow-spec-write','--change','1.guide'],
|
|
48
|
+
{env:process.env,stdio:['pipe','pipe','pipe']});
|
|
49
|
+
t.after(()=>{if(child.exitCode===null)child.kill();});
|
|
50
|
+
let stderr='',sessionId,seq=0;child.stderr.on('data',bytes=>stderr+=bytes);
|
|
51
|
+
const pending=new Map();let ready,failed;const started=new Promise((yes,no)=>{ready=yes;failed=no;});
|
|
52
|
+
const send=value=>child.stdin.write(JSON.stringify(value)+'\n');
|
|
53
|
+
const respond=({kind,payload})=>{
|
|
54
|
+
if(kind==='prd_analyze')return {status:'analyzed',summary:'Add example',openQuestions:[]};
|
|
55
|
+
if(kind==='prd_generate'){const full=payload.phase==='change_tasks';
|
|
56
|
+
return {status:full?'draft':'documents',summary:'Add example',features:[{directory:'1.guide',
|
|
57
|
+
documents:revised().filter(doc=>full||doc.path==='requirements.md'||payload.phase==='change_design'&&doc.path==='design.md'),
|
|
58
|
+
...(full?{testCasesReason:'no_observable_behavior'}:{})}],removed:[]};}
|
|
59
|
+
assert.equal(kind,'prd_self_check');
|
|
60
|
+
return {draftDigest:payload.draft.draftDigest,features:payload.draft.features.map(f=>({directory:f.directory,
|
|
61
|
+
checks:payload.draft.mechanicalSelfCheck.pending.map(id=>({id,status:'passed',evidence:['Synthetic exact task and code inspection']}))}))};
|
|
62
|
+
};
|
|
63
|
+
createInterface({input:child.stdout}).on('line',line=>{const message=JSON.parse(line);
|
|
64
|
+
if(message.type==='host_ready'){sessionId=message.sessionId;ready();}
|
|
65
|
+
else if(message.type==='host_request')send({type:'host_result',sessionId,callId:message.callId,
|
|
66
|
+
requestDigest:message.requestDigest,result:respond(message)});
|
|
67
|
+
else if(message.requestId&&pending.has(message.requestId)){pending.get(message.requestId)(message);pending.delete(message.requestId);}
|
|
68
|
+
});
|
|
69
|
+
child.on('close',()=>{if(!sessionId)failed(Error(stderr));});
|
|
70
|
+
await started;
|
|
71
|
+
const request=(operation,fields={})=>new Promise(resolve=>{const requestId=`r-${++seq}`;pending.set(requestId,resolve);send({requestId,operation,...fields});});
|
|
72
|
+
let reply=await request('start',{text:'Add example'});
|
|
73
|
+
for(const text of ['Requirements','Design','Tasks','Check'])reply=await request('advance',{text});
|
|
74
|
+
assert.equal(reply.result.stage,'change_confirmation',JSON.stringify(reply));
|
|
75
|
+
const proposalDigest=reply.result.proposal.proposalDigest;
|
|
76
|
+
assert.equal((await request('decision',{proposalDigest,approved:true,allowUserCaseChanges:false})).result.stage,'confirmed');
|
|
77
|
+
const saved=await request('save_draft');
|
|
78
|
+
send({type:'host_close',sessionId});const [code]=await once(child,'close');assert.equal(code,0,stderr);
|
|
79
|
+
return {saved,diagnostics:stderr.split('\n').filter(line=>line.startsWith('{')).map(line=>JSON.parse(line))};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
test('a stale review stops save_draft with the gate code and the receipt and artifact on stderr', {timeout:120000},async t=>{
|
|
83
|
+
const dir=fixture(t);
|
|
84
|
+
fs.appendFileSync(path.join(dir,'1.guide/design.md'),'\nEdited after its review\n');
|
|
85
|
+
const before=fs.readFileSync(path.join(dir,'1.guide/design.md'));
|
|
86
|
+
const {saved,diagnostics}=await hostChange(t,dir);
|
|
87
|
+
assert.deepEqual(saved.error,{code:'host_request_failed'});
|
|
88
|
+
assert.equal(diagnostics.length,1);
|
|
89
|
+
const [diagnostic]=diagnostics;
|
|
90
|
+
assert.deepEqual({diagnostic:diagnostic.diagnostic,operation:diagnostic.operation,code:diagnostic.code},
|
|
91
|
+
{diagnostic:'host_request_failed',operation:'save_draft',code:'prd_review_artifact_changed'});
|
|
92
|
+
assert.equal(diagnostic.detail,undefined);
|
|
93
|
+
assert.deepEqual(Object.keys(diagnostic.reason).sort(),['artifact','currentSha256','receipt','recordedSha256']);
|
|
94
|
+
assert.equal(diagnostic.reason.receipt,'.reviews/prd-guide-split-disposition.json');
|
|
95
|
+
assert.equal(diagnostic.reason.artifact,'1.guide/design.md');
|
|
96
|
+
assert.notEqual(diagnostic.reason.recordedSha256,diagnostic.reason.currentSha256);
|
|
97
|
+
// Nothing was written: the refusal happens before the save touches specs.
|
|
98
|
+
assert.ok(fs.readFileSync(path.join(dir,'1.guide/design.md')).equals(before));
|
|
99
|
+
assert.equal(fs.existsSync(path.join(dir,'.cm-specs-status')),false);
|
|
100
|
+
});
|