@aibyzero/cm-workflow 0.16.9 → 0.17.1
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 +4 -0
- package/CHANGELOG.md +18 -1
- package/CONTRIBUTING.md +47 -0
- package/README.md +16 -1
- package/VERSION +1 -1
- package/docs/architecture.md +29 -13
- package/docs/cm-control-policy-v2.md +331 -0
- package/docs/execution-optimizations.md +1 -1
- package/docs/external-models.md +3 -3
- package/docs/fixes/20261013-claude-preinit-ui-invalidate.md +48 -0
- package/docs/human-correction.md +5 -5
- package/docs/installation.md +1 -1
- package/docs/js-workflow-control.md +104 -85
- package/docs/next-steps.md +11 -0
- package/docs/untested-branches.md +2 -3
- package/docs/user-guide.md +3 -3
- package/package.json +1 -1
- package/runtime/js/cm-ai/claude-review-stream.mjs +12 -8
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +13 -69
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +10 -5
- package/runtime/js/cm-ai/control-policy.mjs +112 -0
- package/runtime/js/cm-ai/drive-bootstrap.mjs +11 -8
- package/runtime/js/cm-ai/drive-core.mjs +124 -25
- package/runtime/js/cm-ai/durable-runner-state.mjs +32 -126
- package/runtime/js/cm-ai/gate-bridge.mjs +4 -4
- package/runtime/js/cm-ai/host-check.mjs +3 -1
- package/runtime/js/cm-ai/host-conversation-execution.mjs +22 -20
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +11 -2
- package/runtime/js/cm-ai/host-qa-policy.mjs +63 -21
- package/runtime/js/cm-ai/host-review-authority.mjs +2 -2
- package/runtime/js/cm-ai/host-review-file.mjs +1 -1
- package/runtime/js/cm-ai/host-session.mjs +41 -8
- package/runtime/js/cm-ai/host-stage-observer.mjs +26 -0
- package/runtime/js/cm-ai/host-tool-bridge.mjs +25 -9
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +21 -10
- package/runtime/js/cm-ai/host.mjs +1 -2
- package/runtime/js/cm-ai/operator-guidance.mjs +57 -54
- package/runtime/js/cm-ai/review-package.mjs +16 -4
- package/runtime/js/cm-ai/reviewed-deliveries.mjs +1 -1
- package/runtime/js/cm-ai/task-runner.mjs +41 -101
- package/runtime/js/cm-init/review-evidence.mjs +3 -1
- package/runtime/js/cm-prd/review-host.mjs +1 -1
- package/runtime/js/cm-prd/review-publication.mjs +5 -3
- package/runtime/js/cm-prd/summary.mjs +27 -12
- package/runtime/js/cm-refactor/workflow.mjs +1 -1
- package/runtime/js/notify-send.mjs +15 -14
- package/runtime/js/notify.mjs +27 -4
- package/runtime/js/policy-binding-compat.mjs +2 -1
- package/runtime/review.md +61 -7
- package/runtime/task-gates.md +107 -9
- package/scripts/cm-ai-abandon-effect-position.test.mjs +1 -8
- package/scripts/cm-ai-answer-gap-driver.test.mjs +12 -12
- package/scripts/cm-ai-answer-gap-fixture.mjs +1 -8
- package/scripts/cm-ai-batch-drive.mjs +50 -31
- package/scripts/cm-ai-batch-drive.test.mjs +62 -19
- package/scripts/cm-ai-batch-host.mjs +39 -20
- package/scripts/cm-ai-batch-host.test.mjs +83 -47
- package/scripts/cm-ai-batch-run-fixture.mjs +6 -53
- package/scripts/cm-ai-batch-run-member-stops.test.mjs +0 -12
- package/scripts/cm-ai-batch-run.mjs +46 -14
- package/scripts/cm-ai-bootstrap-flow.test.mjs +1 -7
- package/scripts/cm-ai-bootstrap.test.mjs +2 -3
- package/scripts/cm-ai-control-launch.test.mjs +219 -0
- package/scripts/cm-ai-control-policy.test.mjs +192 -0
- package/scripts/cm-ai-control-v2-drive.test.mjs +270 -0
- package/scripts/cm-ai-develop-answer-invalid.test.mjs +1 -8
- package/scripts/cm-ai-develop-call-timeout.test.mjs +1 -8
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +33 -20
- package/scripts/cm-ai-direct-review.test.mjs +348 -0
- package/scripts/cm-ai-documentation-sync-gap.test.mjs +3 -3
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +57 -27
- package/scripts/cm-ai-drive.mjs +96 -54
- package/scripts/cm-ai-drive.test.mjs +46 -87
- package/scripts/cm-ai-fix-integration.test.mjs +3 -5
- package/scripts/cm-ai-fix-later-delivery.test.mjs +3 -6
- package/scripts/cm-ai-fix-run-delivery.test.mjs +3 -6
- package/scripts/cm-ai-host-cli-workflow.test.mjs +6 -10
- package/scripts/cm-ai-host-fixture.mjs +47 -16
- package/scripts/cm-ai-host-protected.test.mjs +35 -33
- package/scripts/cm-ai-host.mjs +103 -93
- package/scripts/cm-ai-host.test.mjs +34 -18
- package/scripts/cm-ai-launch-diagnostics.test.mjs +5 -3
- package/scripts/cm-ai-legacy-history.test.mjs +53 -0
- package/scripts/cm-ai-light-modules.test.mjs +4 -7
- package/scripts/cm-ai-multi-root.test.mjs +4 -4
- package/scripts/cm-ai-nested-execution.test.mjs +16 -19
- package/scripts/cm-ai-operator-guidance.test.mjs +56 -0
- package/scripts/cm-ai-progress.test.mjs +10 -8
- package/scripts/cm-ai-project-qa-gate.test.mjs +37 -10
- package/scripts/cm-ai-protected-scope.test.mjs +1 -2
- package/scripts/cm-ai-qa-config-revision.test.mjs +1 -9
- package/scripts/cm-ai-qa-fingerprint-config.test.mjs +12 -9
- package/scripts/cm-ai-qa-fix-cross-session.test.mjs +18 -3
- package/scripts/cm-ai-qa-fixed-log.test.mjs +41 -0
- package/scripts/cm-ai-qa-recovery-args.test.mjs +7 -0
- package/scripts/cm-ai-qa-rerun-timeouts.test.mjs +3 -4
- package/scripts/cm-ai-review-drift-precedence.test.mjs +1 -1
- package/scripts/cm-ai-review-failure.test.mjs +13 -19
- package/scripts/cm-ai-review-timeout-config.test.mjs +3 -1
- package/scripts/cm-ai-review-timeout.test.mjs +35 -128
- package/scripts/cm-ai-run.mjs +78 -24
- package/scripts/cm-ai-run.test.mjs +11 -38
- package/scripts/cm-ai-selection-guard.test.mjs +2 -2
- package/scripts/cm-ai-session-chain.test.mjs +18 -15
- package/scripts/cm-ai-spec-rebind.test.mjs +14 -18
- package/scripts/cm-ai-supersede.test.mjs +3 -10
- package/scripts/cm-blocked-reason.test.mjs +2 -3
- package/scripts/cm-capability-gate.test.mjs +33 -1
- package/scripts/cm-check-drive-files.mjs +1 -1
- package/scripts/cm-check-host.test.mjs +1 -1
- package/scripts/cm-check-runtime.sh +1 -1
- package/scripts/cm-claude-probe.test.mjs +26 -0
- package/scripts/cm-claude-review-stream.test.mjs +36 -0
- package/scripts/cm-claude-worker.test.mjs +21 -3
- package/scripts/cm-controlled-correction.test.mjs +469 -0
- package/scripts/cm-drive-liveness.test.mjs +83 -0
- package/scripts/cm-external-batch-host.test.mjs +38 -17
- package/scripts/cm-external-model-host.test.mjs +1 -1
- package/scripts/cm-external-model-recovery.test.mjs +3 -9
- package/scripts/cm-external-qa-fix.test.mjs +1 -1
- package/scripts/cm-external-review-reconciliation.test.mjs +6 -24
- package/scripts/cm-fix-review-recovery.test.mjs +1 -1
- package/scripts/cm-host-diagnostic.test.mjs +33 -0
- package/scripts/cm-host-liveness.test.mjs +150 -0
- package/scripts/cm-host-qa-executor.test.mjs +1 -2
- package/scripts/cm-host-qa-policy.test.mjs +43 -16
- package/scripts/cm-host-review-authority.test.mjs +0 -31
- package/scripts/cm-host-stage-observer.test.mjs +41 -0
- package/scripts/cm-knowledge-closeout.test.mjs +3 -3
- package/scripts/cm-notify-command.test.mjs +54 -18
- package/scripts/cm-notify-read-drift.test.mjs +69 -4
- package/scripts/cm-notify.mjs +16 -4
- package/scripts/cm-notify.test.mjs +135 -29
- package/scripts/cm-patrol.test.mjs +3 -2
- package/scripts/cm-prd-drive.test.mjs +1 -1
- package/scripts/cm-prd-self-check-revision.test.mjs +15 -0
- package/scripts/cm-prd-session-recovery.test.mjs +5 -3
- package/scripts/cm-prd-summary.test.mjs +31 -0
- package/scripts/cm-release-smoke.sh +2 -14
- package/scripts/cm-task-gate-correction.test.mjs +69 -16
- package/scripts/cm-task-gate.mjs +368 -34
- package/scripts/cm-task-gate.py +2 -0
- package/scripts/cm-task-gate.test.mjs +252 -4
- package/scripts/cm-test-suite.mjs +109 -0
- package/scripts/cm-test-suite.test.mjs +162 -0
- package/scripts/fixtures/bootstrap-review-runner.mjs +1 -7
- package/scripts/fixtures/host-diagnostic.mjs +33 -0
- package/scripts/fixtures/native-gate-fixture.mjs +18 -0
- package/scripts/policy-binding-compat.test.mjs +4 -0
- package/skills/cm-ai/SKILL.md +8 -6
- package/skills/cm-ai/references/N3-execute-task.md +17 -2
- package/skills/cm-ai/references/N4-review.md +11 -21
- package/skills/cm-ai/references/N5-mark-done.md +1 -1
- package/skills/cm-ai/references/N6-qa-eval.md +49 -21
- package/skills/cm-ai/references/js-host-modes.md +35 -14
- package/skills/cm-ai/references/js-host-qa-recovery.md +60 -12
- package/skills/cm-ai/references/js-host-recovery.md +95 -47
- package/skills/cm-ai/references/js-host.md +98 -29
- package/skills/cm-fix/SKILL.md +12 -0
- package/skills/cm-init/references/js-host.md +1 -1
- package/skills/cm-prd/references/js-host.md +1 -1
- package/skills/cm-refactor/SKILL.md +12 -0
- package/runtime/js/cm-ai/review-dispatch-limits.mjs +0 -18
- package/scripts/cm-ai-review-dispatch-exit.test.mjs +0 -475
|
@@ -8,7 +8,7 @@ import {spawn,spawnSync} from 'node:child_process';
|
|
|
8
8
|
import {fileURLToPath} from 'node:url';
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
-
GateError,checkN4,checkN5,implementationSha256,loadHandoff,prepareMarkDone,verifyMarkDonePlan,
|
|
11
|
+
GateError,checkN4,checkN5,implementationSha256,loadHandoff,prepareMarkDone,verifyMarkDonePlan,validateReview,
|
|
12
12
|
checkParallelWrite,markDoneLocked,
|
|
13
13
|
} from './cm-task-gate.mjs';
|
|
14
14
|
|
|
@@ -66,7 +66,7 @@ test('Skill Learning gate rejects missing or pending records and binds reviewed
|
|
|
66
66
|
const handoff=path.join(reviews,'login-T-001-a1-handoff.json'),review=path.join(reviews,'login-T-001-r1.md');
|
|
67
67
|
const tasks=path.join(root,'tasks.md');fs.writeFileSync(tasks,'- [ ] T-001: fixture\n');
|
|
68
68
|
writeHandoff(handoff,{implementation:implementationSha256(root,['src/example.ts'])});
|
|
69
|
-
const options={handoff,reviewsDir:reviews,feature:'login',task:'T-001',projectRoot:root,requireLearning:true};
|
|
69
|
+
const options={handoff,reviewsDir:reviews,feature:'login',task:'T-001',projectRoot:root,requireLearning:true,allowLegacyUnbound:true};
|
|
70
70
|
assert.throws(()=>checkN4(options),/Learning/);
|
|
71
71
|
const payload=JSON.parse(fs.readFileSync(handoff));
|
|
72
72
|
const save=()=>{fs.writeFileSync(handoff,JSON.stringify(payload));writeReview(review,{handoff});};
|
|
@@ -85,7 +85,7 @@ test('Skill Learning gate rejects missing or pending records and binds reviewed
|
|
|
85
85
|
assert.throws(()=>checkN5(options),/content changed/);
|
|
86
86
|
payload.evidence=['learning: no_relevant_lesson','learning: retrospective no_new_lesson'];
|
|
87
87
|
payload.changed_files=['src/example.ts'];payload.implementation_sha256=implementationSha256(root,payload.changed_files);save();
|
|
88
|
-
const args=['mark-done','--require-learning','--handoff',handoff,'--reviews-dir',reviews,'--feature','login','--task','T-001','--tasks',tasks,'--project-root',root];
|
|
88
|
+
const args=['mark-done','--allow-legacy-unbound','--require-learning','--handoff',handoff,'--reviews-dir',reviews,'--feature','login','--task','T-001','--tasks',tasks,'--project-root',root];
|
|
89
89
|
payload.evidence=['synthetic implementation check passed'];save();
|
|
90
90
|
assert.equal(checkN5({...options,requireLearning:false}).outcome,'approved');
|
|
91
91
|
const blocked=spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...args],{encoding:'utf8'});
|
|
@@ -161,7 +161,7 @@ test('JS task gate binds N4/N5 to current implementation bytes and rejects drift
|
|
|
161
161
|
const digest=implementationSha256(project,['src/example.ts']);
|
|
162
162
|
const handoff=path.join(reviews,'bound-T-001-a1-handoff.json');
|
|
163
163
|
writeHandoff(handoff,{implementation:digest});writeReview(path.join(reviews,'bound-T-001-r1.md'),{handoff});
|
|
164
|
-
const selectors={handoff,reviewsDir:reviews,feature:'bound',task:'T-001',projectRoot:project};
|
|
164
|
+
const selectors={handoff,reviewsDir:reviews,feature:'bound',task:'T-001',projectRoot:project,allowLegacyUnbound:true};
|
|
165
165
|
assert.equal(checkN4(selectors).content_bound,true);assert.equal(checkN5(selectors).content_bound,true);
|
|
166
166
|
const cli=spawnSync(process.execPath,[jsGate,'hash-implementation','--project-root',project,'--file','src/example.ts'],{encoding:'utf8'});
|
|
167
167
|
assert.equal(cli.status,0,cli.stderr);assert.equal(JSON.parse(cli.stdout).implementation_sha256,digest);
|
|
@@ -200,3 +200,251 @@ test('Windows lock serializes two task completions without losing either checkbo
|
|
|
200
200
|
for(const result of results)assert.equal(result.status,0,result.stderr);
|
|
201
201
|
assert.equal(fs.readFileSync(tasks,'utf8'),'- [x] T-001: first\r\n- [x] T-002: second\r\n');
|
|
202
202
|
}));
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
test('reviewer and independent fields validate declaration format and consistency',()=>fixture(root=>{
|
|
206
|
+
const handoff=path.join(root,'handoff.json'),review=path.join(root,'review.md');
|
|
207
|
+
writeHandoff(handoff);writeReview(review,{handoff});
|
|
208
|
+
const original=fs.readFileSync(review,'utf8'),selected={task:'T-001',attempt:1,handoff,changedFiles:['src/example.ts']};
|
|
209
|
+
assert.equal(validateReview(review,selected).reviewer,'codex-subagent');
|
|
210
|
+
for(const [before,after] of [
|
|
211
|
+
['reviewer: codex-subagent','reviewer: unknown-source'],
|
|
212
|
+
['independent: true','independent: yes'],
|
|
213
|
+
['independent: true','independent: false'],
|
|
214
|
+
['reviewer: codex-subagent','reviewer: self-degraded'],
|
|
215
|
+
]){
|
|
216
|
+
fs.writeFileSync(review,original.replace(before,after));
|
|
217
|
+
assert.throws(()=>validateReview(review,selected),undefined,after);
|
|
218
|
+
}
|
|
219
|
+
fs.writeFileSync(review,original.replace('reviewer: codex-subagent','reviewer: self-degraded')
|
|
220
|
+
.replace('independent: true','independent: false').replace('scope:','degraded_reason: Declared fallback source\nscope:'));
|
|
221
|
+
assert.equal(validateReview(review,selected).reviewer,'self-degraded');
|
|
222
|
+
}));
|
|
223
|
+
|
|
224
|
+
// Compatibility inventory fixtures use the public CLI before any source edit.
|
|
225
|
+
function inventoryFixture(root,{nested=false}={}){
|
|
226
|
+
const reviewsDir=path.join(root,nested?'specs/.reviews':'.reviews');fs.mkdirSync(reviewsDir,{recursive:true});
|
|
227
|
+
fs.mkdirSync(path.join(root,'src'));fs.writeFileSync(path.join(root,'src/example.ts'),'before');
|
|
228
|
+
const selectors={projectRoot:root,reviewsDir,feature:'inventory',task:'T-001',
|
|
229
|
+
handoff:path.join(reviewsDir,'inventory-T-001-a1-handoff.json')};
|
|
230
|
+
const capture=()=>spawnSync(process.execPath,[jsGate,'capture-baseline','--project-root',root,
|
|
231
|
+
'--reviews-dir',reviewsDir,'--feature','inventory','--task','T-001'],{encoding:'utf8'});
|
|
232
|
+
const deliver=(files=['src/example.ts'],attempt=1)=>{
|
|
233
|
+
selectors.handoff=path.join(reviewsDir,`inventory-T-001-a${attempt}-handoff.json`);
|
|
234
|
+
writeHandoff(selectors.handoff,{attempt,implementation:implementationSha256(root,files)});
|
|
235
|
+
const payload=JSON.parse(fs.readFileSync(selectors.handoff));payload.changed_files=files;
|
|
236
|
+
fs.writeFileSync(selectors.handoff,JSON.stringify(payload));
|
|
237
|
+
const review=path.join(reviewsDir,`inventory-T-001-r${attempt}.md`);
|
|
238
|
+
writeReview(review,{handoff:selectors.handoff,attempt});
|
|
239
|
+
fs.writeFileSync(review,fs.readFileSync(review,'utf8').replace(' - src/example.ts',files.map(p=>` - ${p}`).join('\n')));
|
|
240
|
+
};
|
|
241
|
+
return {selectors,capture,deliver,baseline:path.join(reviewsDir,'inventory-T-001-baseline.json')};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
test('Python mark-done emits UTF-8 JSON and errors under cp1252',()=>fixture(root=>{
|
|
245
|
+
const f=inventoryFixture(root,{nested:true});f.deliver();
|
|
246
|
+
const tasksPath=path.join(root,'specs/tasks.md');fs.writeFileSync(tasksPath,'- [ ] T-001: fixture\n');
|
|
247
|
+
const args=['mark-done','--allow-legacy-unbound','--handoff',f.selectors.handoff,
|
|
248
|
+
'--reviews-dir',f.selectors.reviewsDir,'--feature','inventory','--task','T-001',
|
|
249
|
+
'--tasks',tasksPath,'--project-root',root];
|
|
250
|
+
const run=()=>spawnSync(process.env.CM_PYTHON_BIN||'python3',[pythonGate,...args],
|
|
251
|
+
{env:{...process.env,PYTHONIOENCODING:'cp1252'}});
|
|
252
|
+
const done=run();
|
|
253
|
+
assert.equal(done.status,0,done.stderr.toString('utf8'));
|
|
254
|
+
const stdout=done.stdout.toString('utf8');assert.deepEqual(Buffer.from(stdout,'utf8'),done.stdout);
|
|
255
|
+
const result=JSON.parse(stdout);
|
|
256
|
+
assert.equal(result.inventory,'unverified');
|
|
257
|
+
assert.equal(result.inventory_note,'未捕获编辑前基线,不保证清单完整,只保证已列文件的内容绑定');
|
|
258
|
+
assert.match(fs.readFileSync(tasksPath,'utf8'),/\[x\]/);
|
|
259
|
+
|
|
260
|
+
fs.writeFileSync(tasksPath,'- [ ] T-001: fixture\n');assert.equal(f.capture().status,0);
|
|
261
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'after');fs.writeFileSync(path.join(root,'extra.ts'),'omitted');
|
|
262
|
+
f.deliver();
|
|
263
|
+
const blocked=run(),stderr=blocked.stderr.toString('utf8');
|
|
264
|
+
assert.equal(blocked.status,1);assert.equal(blocked.stdout.length,0);
|
|
265
|
+
assert.deepEqual(Buffer.from(stderr,'utf8'),blocked.stderr);
|
|
266
|
+
assert.match(stderr,/ERROR:.*改了但没列: extra.ts/);assert.doesNotMatch(stderr,/Traceback|UnicodeEncodeError/);
|
|
267
|
+
assert.match(fs.readFileSync(tasksPath,'utf8'),/\[ \]/);
|
|
268
|
+
}));
|
|
269
|
+
|
|
270
|
+
test('library default N4 and N5 preserve exact results without an editing baseline',()=>fixture(root=>{
|
|
271
|
+
const f=inventoryFixture(root);f.deliver();
|
|
272
|
+
const n4={gate:'n4',task:'T-001',attempt:1,outcome:'ready_for_review',
|
|
273
|
+
handoff_sha256:createHash('sha256').update(fs.readFileSync(f.selectors.handoff)).digest('hex'),content_bound:true};
|
|
274
|
+
const n5={gate:'n5',task:'T-001',attempt:1,outcome:'approved',
|
|
275
|
+
review:path.join(f.selectors.reviewsDir,'inventory-T-001-r1.md'),content_bound:true};
|
|
276
|
+
assert.equal(JSON.stringify(checkN5(f.selectors)),JSON.stringify(n5));
|
|
277
|
+
assert.equal(JSON.stringify(checkN4(f.selectors)),JSON.stringify(n4));
|
|
278
|
+
// Even an invalid CLI baseline must not change a library caller's contract.
|
|
279
|
+
fs.writeFileSync(f.baseline,'invalid baseline');
|
|
280
|
+
assert.equal(JSON.stringify(checkN5(f.selectors)),JSON.stringify(n5));
|
|
281
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'drift');
|
|
282
|
+
for(const check of [checkN4,checkN5])assert.throws(()=>check(f.selectors),
|
|
283
|
+
{name:'GateError',message:'implementation content changed after handoff'});
|
|
284
|
+
}));
|
|
285
|
+
|
|
286
|
+
test('library default prepare and verify mark done succeed without an editing baseline',()=>fixture(root=>{
|
|
287
|
+
const f=inventoryFixture(root,{nested:true});f.deliver();
|
|
288
|
+
const tasksPath=path.join(root,'specs/tasks.md');fs.writeFileSync(tasksPath,'- [ ] T-001: fixture\n');
|
|
289
|
+
const selectors={...f.selectors,tasksPath},plan=prepareMarkDone(selectors);
|
|
290
|
+
assert.equal(plan.protocol,'cm-mark-done-plan');assert.equal(plan.evidence.length,2);
|
|
291
|
+
assert.equal(Buffer.from(plan.afterBase64,'base64').toString(),'- [x] T-001: fixture\n');
|
|
292
|
+
assert(!Object.keys(plan).some(key=>key.startsWith('inventory')));
|
|
293
|
+
assert.equal(JSON.stringify(verifyMarkDonePlan(selectors,plan.planDigest)),
|
|
294
|
+
JSON.stringify({outcome:'matched',planDigest:plan.planDigest}));
|
|
295
|
+
assert.throws(()=>verifyMarkDonePlan(selectors,'0'.repeat(64)),
|
|
296
|
+
{name:'GateError',message:'preparation plan changed; refusing stale proposal'});
|
|
297
|
+
}));
|
|
298
|
+
|
|
299
|
+
for(const command of ['check-n4','check-n5','prepare-mark-done','verify-mark-done-plan','mark-done-locked']){
|
|
300
|
+
test(`CLI ${command} requires an editing baseline`,()=>fixture(root=>{
|
|
301
|
+
const f=inventoryFixture(root,{nested:true});f.deliver();
|
|
302
|
+
const tasksPath=path.join(root,'specs/tasks.md');fs.writeFileSync(tasksPath,'- [ ] T-001: fixture\n');
|
|
303
|
+
const args=[command,'--handoff',f.selectors.handoff,'--reviews-dir',f.selectors.reviewsDir,
|
|
304
|
+
'--feature','inventory','--task','T-001','--project-root',root];
|
|
305
|
+
if(command.includes('mark-done'))args.push('--tasks',tasksPath);
|
|
306
|
+
if(['verify-mark-done-plan','mark-done-locked'].includes(command))args.push('--expected-plan-digest','0'.repeat(64));
|
|
307
|
+
const lock=process.platform==='win32'?path.join(f.selectors.reviewsDir,'.cm-task-write.lock')
|
|
308
|
+
:path.join(f.selectors.reviewsDir,'.execution/writer.sqlite');
|
|
309
|
+
if(command==='mark-done-locked'){fs.mkdirSync(path.dirname(lock),{recursive:true});fs.writeFileSync(lock,'');}
|
|
310
|
+
const result=spawnSync(process.execPath,[jsGate,...args],{encoding:'utf8',env:{...process.env,
|
|
311
|
+
CM_TASK_GATE_LOCK_ADAPTER:'1',CM_TASK_GATE_LOCK_PARENT_PID:String(process.pid),CM_TASK_GATE_WRITER_LOCK:lock}});
|
|
312
|
+
assert.equal(result.status,1,result.stderr);assert.match(result.stderr,/missing editing baseline/);
|
|
313
|
+
assert.equal(result.stdout,'');assert.equal(fs.readFileSync(tasksPath,'utf8'),'- [ ] T-001: fixture\n');
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
test('inventory baseline capture seals metadata only and refuses overwrite',()=>fixture(root=>{
|
|
318
|
+
const f=inventoryFixture(root);fs.writeFileSync(path.join(root,'AGENTS.md'),'x'.repeat(1024*1024+1));
|
|
319
|
+
const result=f.capture();assert.equal(result.status,0,result.stderr);
|
|
320
|
+
const b=JSON.parse(fs.readFileSync(f.baseline));
|
|
321
|
+
assert.equal(b.kind,'cm-task-inventory-baseline');assert.deepEqual(b.identity,{feature:'inventory',task:'T-001'});
|
|
322
|
+
assert.match(b.rootDigest,/^[a-f0-9]{64}$/);assert.match(b.baselineDigest,/^[a-f0-9]{64}$/);
|
|
323
|
+
assert.equal(b.ignorePolicy.version,2);assert(!b.files.some(file=>'contentBase64' in file));
|
|
324
|
+
assert.deepEqual(b.files.map(file=>file.path),['AGENTS.md','src/example.ts']);
|
|
325
|
+
const original=fs.readFileSync(f.baseline);assert.notEqual(f.capture().status,0);assert.deepEqual(fs.readFileSync(f.baseline),original);
|
|
326
|
+
}));
|
|
327
|
+
|
|
328
|
+
test('inventory missing baseline refuses N4 and N5 unless legacy flag is explicit',()=>fixture(root=>{
|
|
329
|
+
const f=inventoryFixture(root);f.deliver();
|
|
330
|
+
for(const check of [checkN4,checkN5]){
|
|
331
|
+
assert.throws(()=>check({...f.selectors,inventory:'required'}),/baseline/);
|
|
332
|
+
const result=check({...f.selectors,inventory:'required',allowLegacyUnbound:true});assert.equal(result.inventory,'unverified');
|
|
333
|
+
assert.equal(result.inventory_note,'未捕获编辑前基线,不保证清单完整,只保证已列文件的内容绑定');
|
|
334
|
+
assert.equal(result.content_bound,true);
|
|
335
|
+
}
|
|
336
|
+
}));
|
|
337
|
+
|
|
338
|
+
test('inventory exact set catches omitted additions and falsely listed unchanged files',()=>fixture(root=>{
|
|
339
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
340
|
+
fs.writeFileSync(path.join(root,'extra.ts'),'extra');f.deliver();
|
|
341
|
+
for(const check of [checkN4,checkN5])assert.throws(()=>check({...f.selectors,inventory:'required'}),error=>
|
|
342
|
+
error instanceof GateError&&/改了但没列.*extra.ts/.test(error.message)&&/列了但没改.*src\/example.ts/.test(error.message));
|
|
343
|
+
f.deliver(['extra.ts']);assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:1,modified:0,deleted:0});
|
|
344
|
+
}));
|
|
345
|
+
|
|
346
|
+
test('inventory deletion must be listed and keeps missing-file content binding',()=>fixture(root=>{
|
|
347
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
348
|
+
fs.unlinkSync(path.join(root,'src/example.ts'));f.deliver([]);
|
|
349
|
+
for(const check of [checkN4,checkN5])assert.throws(()=>check({...f.selectors,inventory:'required'}),/改了但没列.*src\/example.ts/);
|
|
350
|
+
f.deliver();assert.equal(checkN4({...f.selectors,inventory:'required'}).inventory,'verified');
|
|
351
|
+
assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:0,modified:0,deleted:1});
|
|
352
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'recreated');assert.throws(()=>checkN5({...f.selectors,inventory:'required'}),/content changed/);
|
|
353
|
+
}));
|
|
354
|
+
|
|
355
|
+
test('inventory excludes root reviews and nested specs evidence throughout N4 and N5',()=>fixture(root=>{
|
|
356
|
+
const f=inventoryFixture(root,{nested:true});assert.equal(f.capture().status,0);
|
|
357
|
+
fs.mkdirSync(path.join(root,'.reviews'));fs.writeFileSync(path.join(root,'.reviews','unrelated-review.md'),'audit');
|
|
358
|
+
for(const p of ['specs/运行日志.jsonl','specs/.cm-status.json','specs/tasks.md'])fs.writeFileSync(path.join(root,p),'runtime');
|
|
359
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'after');f.deliver();
|
|
360
|
+
assert.equal(checkN4({...f.selectors,inventory:'required'}).inventory,'verified');
|
|
361
|
+
assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:0,modified:1,deleted:0});
|
|
362
|
+
}));
|
|
363
|
+
|
|
364
|
+
// Only the code root's own .reviews and the specs subtree are evidence; a
|
|
365
|
+
// nested directory that merely shares the name is ordinary code.
|
|
366
|
+
test('inventory counts a nested directory named .reviews as code',()=>fixture(root=>{
|
|
367
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
368
|
+
fs.mkdirSync(path.join(root,'src/.reviews'));fs.writeFileSync(path.join(root,'src/.reviews/data.md'),'code');
|
|
369
|
+
fs.writeFileSync(path.join(root,'.reviews','unrelated-review.md'),'audit');
|
|
370
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'after');f.deliver();
|
|
371
|
+
assert.throws(()=>checkN4({...f.selectors,inventory:'required'}),/改了但没列: src\/\.reviews\/data\.md/);
|
|
372
|
+
f.deliver(['src/example.ts','src/.reviews/data.md']);
|
|
373
|
+
assert.equal(checkN4({...f.selectors,inventory:'required'}).inventory,'verified');
|
|
374
|
+
assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:1,modified:1,deleted:0});
|
|
375
|
+
}));
|
|
376
|
+
|
|
377
|
+
test('inventory includes executable-only changes and cumulative attempt two edits',()=>fixture(root=>{
|
|
378
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
379
|
+
if(process.platform==='win32')fs.writeFileSync(path.join(root,'src/example.ts'),'after');
|
|
380
|
+
else fs.chmodSync(path.join(root,'src/example.ts'),0o755);
|
|
381
|
+
f.deliver();
|
|
382
|
+
assert.deepEqual(checkN4({...f.selectors,inventory:'required'}).inventory_counts,{added:0,modified:1,deleted:0});
|
|
383
|
+
writeReview(path.join(f.selectors.reviewsDir,'inventory-T-001-r1.md'),{handoff:f.selectors.handoff,verdict:'changes_requested'});
|
|
384
|
+
fs.writeFileSync(path.join(root,'next.ts'),'second edit');f.deliver(['src/example.ts','next.ts'],2);
|
|
385
|
+
assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:1,modified:1,deleted:0});
|
|
386
|
+
}));
|
|
387
|
+
|
|
388
|
+
test('inventory limit_exceeded identifies file and never writes a partial baseline',()=>fixture(root=>{
|
|
389
|
+
const f=inventoryFixture(root),large=path.join(root,'too-large.bin');fs.writeFileSync(large,'');fs.truncateSync(large,1024*1024*1024+1);
|
|
390
|
+
const result=f.capture();assert.notEqual(result.status,0);assert.match(result.stderr,/limit_exceeded.*too-large.bin/);
|
|
391
|
+
assert(!fs.existsSync(f.baseline));
|
|
392
|
+
}));
|
|
393
|
+
|
|
394
|
+
test('inventory baseline tampering or root mismatch cannot degrade through legacy flag',()=>fixture(root=>{
|
|
395
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
396
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'after');f.deliver();
|
|
397
|
+
const original=fs.readFileSync(f.baseline),b=JSON.parse(original);b.files[0].sha256='0'.repeat(64);
|
|
398
|
+
fs.writeFileSync(f.baseline,JSON.stringify(b));assert.throws(()=>checkN4({...f.selectors,inventory:'required',allowLegacyUnbound:true}),/baseline/);
|
|
399
|
+
fs.writeFileSync(f.baseline,original);const other=path.join(root,'other');fs.mkdirSync(path.join(other,'src'),{recursive:true});
|
|
400
|
+
fs.writeFileSync(path.join(other,'src/example.ts'),'after');
|
|
401
|
+
assert.throws(()=>checkN4({...f.selectors,inventory:'required',projectRoot:other}),/baseline/);
|
|
402
|
+
}));
|
|
403
|
+
|
|
404
|
+
test('inventory stable policy unions old and current decisions on both sides while retaining AGENTS',()=>fixture(root=>{
|
|
405
|
+
const f=inventoryFixture(root);assert.equal(spawnSync('git',['init','-q',root]).status,0);
|
|
406
|
+
fs.writeFileSync(path.join(root,'.gitignore'),'old-cache/\n');
|
|
407
|
+
fs.mkdirSync(path.join(root,'old-cache'));fs.writeFileSync(path.join(root,'old-cache/value'),'ignored before');
|
|
408
|
+
fs.mkdirSync(path.join(root,'new-cache'));fs.writeFileSync(path.join(root,'new-cache/value'),'present before');
|
|
409
|
+
fs.mkdirSync(path.join(root,'node_modules'));fs.symlinkSync('/nonexistent/fixture',path.join(root,'node_modules/link'));
|
|
410
|
+
assert.equal(f.capture().status,0);
|
|
411
|
+
const ignoreMode=JSON.parse(fs.readFileSync(f.baseline)).ignorePolicy.mode;
|
|
412
|
+
if(process.platform!=='win32')assert.equal(ignoreMode,'git');
|
|
413
|
+
fs.writeFileSync(path.join(root,'.gitignore'),'new-cache/\n');
|
|
414
|
+
fs.writeFileSync(path.join(root,'old-cache/value'),'ignored by baseline');
|
|
415
|
+
fs.writeFileSync(path.join(root,'new-cache/value'),'ignored now');
|
|
416
|
+
fs.writeFileSync(path.join(root,'new-cache/AGENTS.md'),'must be reviewed');
|
|
417
|
+
f.deliver(['.gitignore']);assert.throws(()=>checkN4({...f.selectors,inventory:'required'}),/改了但没列.*new-cache\/AGENTS.md/);
|
|
418
|
+
f.deliver(['.gitignore','new-cache/AGENTS.md']);
|
|
419
|
+
if(process.platform==='win32'&&ignoreMode!=='git'){
|
|
420
|
+
for(const check of [checkN4,checkN5])assert.throws(()=>check({...f.selectors,inventory:'required'}),error=>
|
|
421
|
+
error instanceof GateError&&/改了但没列:.*new-cache\/value/.test(error.message)
|
|
422
|
+
&&/改了但没列:.*old-cache\/value/.test(error.message));
|
|
423
|
+
}else assert.deepEqual(checkN5({...f.selectors,inventory:'required'}).inventory_counts,{added:1,modified:1,deleted:0});
|
|
424
|
+
}));
|
|
425
|
+
|
|
426
|
+
test('inventory count budget refuses the triggering file and bounds both mismatch lists',()=>fixture(root=>{
|
|
427
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
428
|
+
for(let i=0;i<23;i++)fs.writeFileSync(path.join(root,`added-${String(i).padStart(2,'0')}.ts`),'new');
|
|
429
|
+
const extras=Array.from({length:22},(_,i)=>`missing-${String(i).padStart(2,'0')}.ts`);f.deliver(extras);
|
|
430
|
+
assert.throws(()=>checkN4({...f.selectors,inventory:'required'}),error=>/改了但没列:.*\(\+3 more\); 列了但没改:.*\(\+2 more\)/.test(error.message)
|
|
431
|
+
&&!error.message.includes('added-20.ts')&&!error.message.includes('missing-20.ts'));
|
|
432
|
+
fs.unlinkSync(f.baseline);
|
|
433
|
+
const empty=path.join(root,'empty');fs.mkdirSync(empty);
|
|
434
|
+
for(let i=0;i<10000;i++)fs.writeFileSync(path.join(empty,`f-${String(i).padStart(5,'0')}`),'');
|
|
435
|
+
const result=f.capture();assert.notEqual(result.status,0);assert.match(result.stderr,/limit_exceeded: empty\/f-09977.*file count > 10000/);
|
|
436
|
+
assert(!fs.existsSync(f.baseline));
|
|
437
|
+
}));
|
|
438
|
+
|
|
439
|
+
test('inventory baseline and evidence symlinks refuse instead of legacy degradation',()=>fixture(root=>{
|
|
440
|
+
const f=inventoryFixture(root);assert.equal(f.capture().status,0);
|
|
441
|
+
fs.writeFileSync(path.join(root,'src/example.ts'),'after');f.deliver();
|
|
442
|
+
const bytes=fs.readFileSync(f.baseline);fs.unlinkSync(f.baseline);
|
|
443
|
+
const target=path.join(f.selectors.reviewsDir,'other-baseline.json');fs.writeFileSync(target,bytes);fs.symlinkSync(target,f.baseline);
|
|
444
|
+
assert.throws(()=>checkN4({...f.selectors,inventory:'required',allowLegacyUnbound:true}),/baseline/);
|
|
445
|
+
fs.unlinkSync(f.baseline);fs.writeFileSync(f.baseline,bytes);
|
|
446
|
+
// A nested entry merely named .reviews is ordinary code: a symlink there is
|
|
447
|
+
// refused like any other symlink in the inventory, never treated as evidence.
|
|
448
|
+
fs.mkdirSync(path.join(root,'linked'));fs.symlinkSync(f.selectors.reviewsDir,path.join(root,'linked/.reviews'));
|
|
449
|
+
assert.throws(()=>checkN4({...f.selectors,inventory:'required'}),/unsupported_file: linked\/\.reviews/);
|
|
450
|
+
}));
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// One native sandbox inventory for CI exclusions, local runs and release smoke.
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawn} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
import {assignShards, readWeights} from './ci-test-shards.mjs';
|
|
9
|
+
|
|
10
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
11
|
+
export const nativeTests = Object.freeze([
|
|
12
|
+
'scripts/cm-ai-batch-host.test.mjs',
|
|
13
|
+
'scripts/cm-ai-bootstrap.test.mjs',
|
|
14
|
+
'scripts/cm-ai-host.test.mjs',
|
|
15
|
+
'scripts/cm-ai-host-cli-workflow.test.mjs',
|
|
16
|
+
'scripts/cm-ai-host-protected.test.mjs',
|
|
17
|
+
'scripts/cm-ai-multi-root.test.mjs',
|
|
18
|
+
'scripts/cm-ai-nested-execution.test.mjs',
|
|
19
|
+
'scripts/cm-fix-protected-edits.test.mjs',
|
|
20
|
+
'scripts/cm-host-check.test.mjs',
|
|
21
|
+
].sort());
|
|
22
|
+
|
|
23
|
+
export function inventory(repo = root) {
|
|
24
|
+
const discover = dir => fs.readdirSync(path.join(repo, dir), {withFileTypes: true})
|
|
25
|
+
.filter(entry => entry.isFile() && entry.name.endsWith('.test.mjs'))
|
|
26
|
+
.map(entry => `${dir}/${entry.name}`).sort();
|
|
27
|
+
const all = discover('scripts');
|
|
28
|
+
const native = [...nativeTests];
|
|
29
|
+
if (native.length !== 9 || new Set(native).size !== 9) throw new Error('native inventory must contain exactly nine unique tests');
|
|
30
|
+
for (const file of native) if (!all.includes(file)) throw new Error(`missing native test: ${file}`);
|
|
31
|
+
const ordinary = all.filter(file => !native.includes(file));
|
|
32
|
+
const combined = [...ordinary, ...native];
|
|
33
|
+
if (new Set(combined).size !== all.length || combined.length !== all.length ||
|
|
34
|
+
combined.some(file => !all.includes(file))) throw new Error('test groups must cover scripts tests exactly once');
|
|
35
|
+
const history = discover('experiments/js-orchestration');
|
|
36
|
+
return {ordinary, native, history};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function selectTests(groups, group, {shards, index} = {}) {
|
|
40
|
+
if (!Object.hasOwn(groups, group)) throw new Error('group must be ordinary, native or history');
|
|
41
|
+
const files = groups[group];
|
|
42
|
+
if (shards === undefined && index === undefined) return files;
|
|
43
|
+
if (!Number.isInteger(shards) || shards < 1 || !Number.isInteger(index) || index < 0 || index >= shards)
|
|
44
|
+
throw new Error('--shards and --index must specify a positive count and an index in [0, shards)');
|
|
45
|
+
return assignShards(files, shards, readWeights())[index].files;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async function runTests(files, concurrency) {
|
|
49
|
+
if (files.length === 0) throw new Error('selected test group or shard is empty');
|
|
50
|
+
const temp = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-test-suite-'));
|
|
51
|
+
const workflowHome = path.join(temp, 'workflow'), logHome = path.join(temp, 'logs');
|
|
52
|
+
fs.mkdirSync(workflowHome); fs.mkdirSync(logHome);
|
|
53
|
+
const args = ['--test', ...(concurrency === undefined ? [] : [`--test-concurrency=${concurrency}`]), ...files];
|
|
54
|
+
let child, requestedSignal;
|
|
55
|
+
const handlers = new Map();
|
|
56
|
+
try {
|
|
57
|
+
child = spawn(process.execPath, args, {cwd: root, stdio: 'inherit', detached: process.platform !== 'win32',
|
|
58
|
+
env: {...process.env, CM_WORKFLOW_HOME: workflowHome, CM_WORKFLOW_LOG_HOME: logHome}});
|
|
59
|
+
for (const signal of ['SIGINT', 'SIGTERM', 'SIGHUP']) {
|
|
60
|
+
const handler = () => {
|
|
61
|
+
requestedSignal ??= signal;
|
|
62
|
+
if (!child.pid) return;
|
|
63
|
+
try {
|
|
64
|
+
if (process.platform === 'win32') child.kill(signal);
|
|
65
|
+
else process.kill(-child.pid, signal);
|
|
66
|
+
} catch (error) { if (error.code !== 'ESRCH') throw error; }
|
|
67
|
+
};
|
|
68
|
+
handlers.set(signal, handler); process.on(signal, handler);
|
|
69
|
+
}
|
|
70
|
+
const result = await new Promise((resolve, reject) => {
|
|
71
|
+
child.once('error', reject);
|
|
72
|
+
child.once('close', (code, signal) => resolve({code, signal}));
|
|
73
|
+
});
|
|
74
|
+
return {code: result.code ?? 1, signal: requestedSignal ?? result.signal};
|
|
75
|
+
} finally {
|
|
76
|
+
for (const [signal, handler] of handlers) process.off(signal, handler);
|
|
77
|
+
fs.rmSync(temp, {recursive: true, force: true});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function main(argv) {
|
|
82
|
+
const [command, ...rest] = argv;
|
|
83
|
+
if (!['check', 'list', 'run'].includes(command)) throw new Error('usage: cm-test-suite.mjs check | list|run ordinary|native|history [--shards N --index I] [--concurrency N]');
|
|
84
|
+
if (command === 'check') {
|
|
85
|
+
if (rest.length) throw new Error('check takes no arguments');
|
|
86
|
+
const groups = inventory();
|
|
87
|
+
for (const [group, files] of Object.entries(groups)) process.stdout.write(`${group}: ${files.length} files\n`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const group = rest.shift(), options = {};
|
|
91
|
+
for (let i = 0; i < rest.length; i += 2) {
|
|
92
|
+
const key = rest[i];
|
|
93
|
+
if (!['--shards', '--index', '--concurrency'].includes(key) || Object.hasOwn(options, key.slice(2)))
|
|
94
|
+
throw new Error(`unknown or repeated option: ${key}`);
|
|
95
|
+
if (!/^\d+$/.test(rest[i + 1] ?? '')) throw new Error(`invalid value for ${key}`);
|
|
96
|
+
options[key.slice(2)] = Number(rest[i + 1]);
|
|
97
|
+
}
|
|
98
|
+
if (options.concurrency !== undefined && (command !== 'run' || !Number.isSafeInteger(options.concurrency) || options.concurrency < 1))
|
|
99
|
+
throw new Error('--concurrency must be a positive integer for run');
|
|
100
|
+
const files = selectTests(inventory(), group, options);
|
|
101
|
+
if (command === 'list') { for (const file of files) process.stdout.write(`${file}\n`); return; }
|
|
102
|
+
const result = await runTests(files, options.concurrency);
|
|
103
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
104
|
+
else process.exitCode = result.code;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
if (process.argv[1] && fs.realpathSync(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
108
|
+
main(process.argv.slice(2)).catch(error => { process.stderr.write(`cm-test-suite: ${error.message}\n`); process.exitCode = 1; });
|
|
109
|
+
}
|
|
@@ -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 {createHash} from 'node:crypto';
|
|
7
|
+
import {spawn, spawnSync} from 'node:child_process';
|
|
8
|
+
import {fileURLToPath} from 'node:url';
|
|
9
|
+
import {nativeTests, inventory, selectTests} from './cm-test-suite.mjs';
|
|
10
|
+
import {assignShards, readWeights} from './ci-test-shards.mjs';
|
|
11
|
+
|
|
12
|
+
const root = fileURLToPath(new URL('..', import.meta.url));
|
|
13
|
+
function cliEnv(env) {
|
|
14
|
+
const copy = {...env};
|
|
15
|
+
delete copy.NODE_TEST_CONTEXT; // The CLI starts an independent node --test invocation.
|
|
16
|
+
return copy;
|
|
17
|
+
}
|
|
18
|
+
const cli = (args, cwd = root, env = process.env) => spawnSync(process.execPath,
|
|
19
|
+
[path.join(cwd, 'scripts/cm-test-suite.mjs'), ...args], {cwd, env: cliEnv(env), encoding: 'utf8'});
|
|
20
|
+
|
|
21
|
+
function fixture(t, source = 'import test from "node:test"; test("fixture",()=>{});') {
|
|
22
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'cm-test-suite-fixture-'));
|
|
23
|
+
t.after(() => fs.rmSync(dir, {recursive: true, force: true}));
|
|
24
|
+
fs.mkdirSync(path.join(dir, 'scripts'));
|
|
25
|
+
fs.mkdirSync(path.join(dir, 'experiments/js-orchestration'), {recursive: true});
|
|
26
|
+
for (const name of ['cm-test-suite.mjs', 'ci-test-shards.mjs', 'ci-test-weights.json'])
|
|
27
|
+
fs.copyFileSync(path.join(root, 'scripts', name), path.join(dir, 'scripts', name));
|
|
28
|
+
for (const file of nativeTests) fs.writeFileSync(path.join(dir, file), '');
|
|
29
|
+
fs.writeFileSync(path.join(dir, 'scripts/example.test.mjs'), source);
|
|
30
|
+
fs.writeFileSync(path.join(dir, 'experiments/js-orchestration/history.test.mjs'), source);
|
|
31
|
+
return dir;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
test('approved native inventory is fixed, complete and disjoint from ordinary tests', () => {
|
|
35
|
+
assert.equal(nativeTests.length, 9);
|
|
36
|
+
// Approval fingerprint prevents additions, omissions and substitutions without a reviewed change.
|
|
37
|
+
assert.equal(createHash('sha256').update(nativeTests.join('\n')).digest('hex'), 'e036b229f15e0acca13f43c29a35a2cbc830b1dcdd812b1f379b46253f3eadce');
|
|
38
|
+
const groups = inventory(root);
|
|
39
|
+
const discovered = fs.readdirSync(path.join(root, 'scripts'))
|
|
40
|
+
.filter(name => name.endsWith('.test.mjs')).map(name => `scripts/${name}`).sort();
|
|
41
|
+
assert.deepEqual([...groups.ordinary, ...groups.native].sort(), discovered);
|
|
42
|
+
assert.equal(new Set([...groups.ordinary, ...groups.native]).size, discovered.length);
|
|
43
|
+
assert.deepEqual(groups.native, nativeTests);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('listing every group is install-free and ordinary shards reuse the existing assignment', () => {
|
|
47
|
+
for (const group of ['ordinary', 'native', 'history']) {
|
|
48
|
+
const run = cli(['list', group]);
|
|
49
|
+
assert.equal(run.status, 0, run.stderr);
|
|
50
|
+
assert.deepEqual(run.stdout.trim().split('\n'), inventory(root)[group]);
|
|
51
|
+
}
|
|
52
|
+
const groups = inventory(root);
|
|
53
|
+
const shards = assignShards(groups.ordinary, 4, readWeights());
|
|
54
|
+
for (let index = 0; index < 4; index++)
|
|
55
|
+
assert.deepEqual(selectTests(groups, 'ordinary', {shards: 4, index}), shards[index].files);
|
|
56
|
+
assert.deepEqual(shards.flatMap(shard => shard.files).sort(), groups.ordinary);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('new ordinary tests are included and missing native members stop the CLI', t => {
|
|
60
|
+
const dir = fixture(t);
|
|
61
|
+
fs.writeFileSync(path.join(dir, 'scripts/new.test.mjs'), '');
|
|
62
|
+
assert.match(cli(['list', 'ordinary'], dir).stdout, /scripts\/new.test.mjs/);
|
|
63
|
+
fs.unlinkSync(path.join(dir, nativeTests[0]));
|
|
64
|
+
const run = cli(['check'], dir);
|
|
65
|
+
assert.notEqual(run.status, 0);
|
|
66
|
+
assert.match(run.stderr, /missing native test/);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test('runner isolates both CM homes and cleans up after success', t => {
|
|
70
|
+
const dir = fixture(t, `import test from 'node:test'; import assert from 'node:assert/strict';
|
|
71
|
+
import fs from 'node:fs';
|
|
72
|
+
test('isolation',()=>{
|
|
73
|
+
assert.notEqual(process.env.CM_WORKFLOW_HOME, process.env.CALLER_HOME);
|
|
74
|
+
assert.notEqual(process.env.CM_WORKFLOW_LOG_HOME, process.env.CALLER_LOG_HOME);
|
|
75
|
+
assert(fs.statSync(process.env.CM_WORKFLOW_HOME).isDirectory());
|
|
76
|
+
assert(fs.statSync(process.env.CM_WORKFLOW_LOG_HOME).isDirectory());
|
|
77
|
+
fs.writeFileSync(process.env.CAPTURE, JSON.stringify([process.env.CM_WORKFLOW_HOME,process.env.CM_WORKFLOW_LOG_HOME]));
|
|
78
|
+
});`);
|
|
79
|
+
const capture = path.join(dir, 'capture.json');
|
|
80
|
+
const callerHome = path.join(dir, 'caller-home'), callerLogs = path.join(dir, 'caller-logs');
|
|
81
|
+
const run = cli(['run', 'ordinary', '--concurrency', '1'], dir,
|
|
82
|
+
{...process.env, CM_WORKFLOW_HOME: callerHome, CM_WORKFLOW_LOG_HOME: callerLogs,
|
|
83
|
+
CALLER_HOME: callerHome, CALLER_LOG_HOME: callerLogs, CAPTURE: capture});
|
|
84
|
+
assert.equal(run.status, 0, run.stderr + run.stdout);
|
|
85
|
+
for (const item of JSON.parse(fs.readFileSync(capture))) assert.equal(fs.existsSync(item), false);
|
|
86
|
+
assert.equal(fs.existsSync(callerHome), false);
|
|
87
|
+
assert.equal(fs.existsSync(callerLogs), false);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('explicit concurrency reaches the Node runner', t => {
|
|
91
|
+
const source = `import test from 'node:test'; import fs from 'node:fs'; import assert from 'node:assert/strict';
|
|
92
|
+
test('overlap',async()=>{
|
|
93
|
+
fs.writeFileSync(process.env.CAPTURE+'/'+process.pid,'ready');
|
|
94
|
+
const deadline=Date.now()+5000;
|
|
95
|
+
while(fs.readdirSync(process.env.CAPTURE).length<2 && Date.now()<deadline)
|
|
96
|
+
await new Promise(resolve=>setTimeout(resolve,10));
|
|
97
|
+
assert.equal(fs.readdirSync(process.env.CAPTURE).length,2,'both test files must run concurrently');
|
|
98
|
+
});`;
|
|
99
|
+
const dir = fixture(t, source), capture = path.join(dir, 'parallel');
|
|
100
|
+
fs.mkdirSync(capture);
|
|
101
|
+
fs.writeFileSync(path.join(dir, 'scripts/second.test.mjs'), source);
|
|
102
|
+
const run = cli(['run', 'ordinary', '--concurrency', '2'], dir, {...process.env, CAPTURE: capture});
|
|
103
|
+
assert.equal(run.status, 0, run.stderr + run.stdout);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
test('failed tests fail exactly once in ordinary and historical groups', t => {
|
|
107
|
+
const dir = fixture(t, `import test from 'node:test'; import fs from 'node:fs';
|
|
108
|
+
test('fail',()=>{fs.appendFileSync(process.env.CAPTURE,'attempt\\n');throw new Error('intentional fixture failure');});`);
|
|
109
|
+
for (const group of ['ordinary', 'history']) {
|
|
110
|
+
const capture = path.join(dir, `${group}.txt`);
|
|
111
|
+
const run = cli(['run', group], dir, {...process.env, CAPTURE: capture});
|
|
112
|
+
assert.equal(run.status, 1, run.stderr + run.stdout);
|
|
113
|
+
assert.equal(fs.readFileSync(capture, 'utf8'), 'attempt\n');
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
test('invalid arguments fail before running tests', t => {
|
|
118
|
+
const dir = fixture(t, 'throw new Error("must not execute");');
|
|
119
|
+
for (const args of [['run', 'unknown'], ['run', 'ordinary', '--concurrency', '0'],
|
|
120
|
+
['run', 'ordinary', '--shards', '4'], ['list', 'ordinary', '--index', '0'],
|
|
121
|
+
['run', 'ordinary', '--shards', '2', '--index', '2'], ['run', 'ordinary', '--retry']]) {
|
|
122
|
+
const run = cli(args, dir);
|
|
123
|
+
assert.notEqual(run.status, 0);
|
|
124
|
+
assert.doesNotMatch(run.stdout + run.stderr, /must not execute/);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('parent signals reach tests, preserve failure and remove temporary homes', {skip: process.platform === 'win32'}, async t => {
|
|
129
|
+
const dir = fixture(t, `import fs from 'node:fs';
|
|
130
|
+
process.on('SIGTERM',()=>{fs.writeFileSync(process.env.SIGNAL_CAPTURE,'received'); process.exit(0);});
|
|
131
|
+
fs.writeFileSync(process.env.CAPTURE, process.env.CM_WORKFLOW_HOME);
|
|
132
|
+
setInterval(()=>{},1000);`);
|
|
133
|
+
const capture = path.join(dir, 'ready'), signalCapture = path.join(dir, 'signal');
|
|
134
|
+
const child = spawn(process.execPath, [path.join(dir, 'scripts/cm-test-suite.mjs'), 'run', 'ordinary'],
|
|
135
|
+
{cwd: dir, env: cliEnv({...process.env, CAPTURE: capture, SIGNAL_CAPTURE: signalCapture}), stdio: 'ignore'});
|
|
136
|
+
t.after(() => { if (child.exitCode === null && child.signalCode === null) child.kill('SIGKILL'); });
|
|
137
|
+
const closed = new Promise(resolve => child.on('close', (code, signal) => resolve({code, signal})));
|
|
138
|
+
const deadline = Date.now() + 10000;
|
|
139
|
+
while (!fs.existsSync(capture) && Date.now() < deadline) await new Promise(resolve => setTimeout(resolve, 20));
|
|
140
|
+
assert(fs.existsSync(capture), 'test child did not become ready');
|
|
141
|
+
child.kill('SIGTERM');
|
|
142
|
+
let timer;
|
|
143
|
+
const result = await Promise.race([closed, new Promise((_, reject) => {
|
|
144
|
+
timer = setTimeout(() => reject(new Error('signal not propagated')), 10000);
|
|
145
|
+
})]).finally(() => clearTimeout(timer));
|
|
146
|
+
assert.equal(result.signal, 'SIGTERM');
|
|
147
|
+
assert.equal(fs.readFileSync(signalCapture, 'utf8'), 'received');
|
|
148
|
+
assert.equal(fs.existsSync(fs.readFileSync(capture, 'utf8')), false);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('CI and release smoke consume the same entrypoint without a second exclusion list', () => {
|
|
152
|
+
const ci = fs.readFileSync(path.join(root, '.github/workflows/ci.yml'), 'utf8');
|
|
153
|
+
const release = fs.readFileSync(path.join(root, 'scripts/cm-release-smoke.sh'), 'utf8');
|
|
154
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs check/);
|
|
155
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs run ordinary --shards 4 --index \$\{\{ matrix\.shard \}\}/);
|
|
156
|
+
assert.match(ci, /node scripts\/cm-test-suite\.mjs run history --concurrency 4/);
|
|
157
|
+
assert.match(release, /node "\$ROOT\/scripts\/cm-test-suite\.mjs" run native/);
|
|
158
|
+
for (const file of nativeTests) {
|
|
159
|
+
assert(!ci.includes(path.basename(file, '.test.mjs')), 'CI duplicated the native inventory');
|
|
160
|
+
assert(!release.includes(file), 'release duplicated the native inventory');
|
|
161
|
+
}
|
|
162
|
+
});
|
|
@@ -83,13 +83,7 @@ export function open(f,taskId,mode='create',overrides={}){
|
|
|
83
83
|
return {status:'succeeded',value:{verdict:revise?'changes_requested':'approved',packageDigest:request.payload.reviewPackage.packageDigest,
|
|
84
84
|
examinedPaths:reviewPaths(request.payload.reviewPackage),findings:revise?[{id:'F1',severity:'P2',path:'AGENTS.md',
|
|
85
85
|
message:'Reverify instruction applicability',evidence:'Synthetic revision fixture'}]:[],summary:'Synthetic independent review'}};}}],
|
|
86
|
-
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main'],
|
|
87
|
-
const body={version:1,kind:'cm-review-dispatch-grant',grantId:'grant-'+request.identity.attempt,adapterId:'codex-review-adapter',
|
|
88
|
-
invocationId:request.invocationId,requestDigest:request.requestDigest,identity:request.identity,reviewerId:'reviewer',
|
|
89
|
-
logicalContextId:request.contextId,packageDigest:request.payload.reviewPackage.packageDigest,hostContextId:'main',
|
|
90
|
-
decisionId:'decision-'+request.identity.attempt,decision:'approved',issuedAt:authorizationAt,expiresAt:authorizationAt+60000};
|
|
91
|
-
return {...body,grantDigest:digest(body)};
|
|
92
|
-
}},
|
|
86
|
+
reviewInvocation:{developerThreadId:'scaffold-author',excludedThreadIds:['main']},
|
|
93
87
|
check:overrides.afterCheck?async (input,control)=>{const result=await hostCheck(input,control);overrides.afterCheck();return result;}:hostCheck,
|
|
94
88
|
taskCompletion:{reviewsDir:path.join(f.specsDir,'.reviews'),handoffs:[1,2].map(a=>path.join(f.specsDir,'.reviews',`bootstrap-${taskId}-a${a}-handoff.json`))},
|
|
95
89
|
persistence:{store,mode,version:3}});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Fixture-only metadata, following live-evidence-driver's bounded diagnostics.
|
|
2
|
+
// Never retain request IDs, paths, payloads, command lines or stderr contents.
|
|
3
|
+
const operations=new Set(['advance','start','status','fix_status','cancel','resume','host_close','host_result','eof']);
|
|
4
|
+
const kinds=new Set(['develop','check','review','complete','qa_assess','qa_browser','documentation_sync','documentation_inspect']);
|
|
5
|
+
const states=new Set(['idle','developing','pending_review','reviewing','fixture_completed','blocked','unknown','cancelled',
|
|
6
|
+
'requirements_analysis','awaiting_user','status_only']);
|
|
7
|
+
const codes=new Set(['develop_answer_missing','host_busy','execution_error','host_launch_failed','invalid_arguments']);
|
|
8
|
+
const signals=new Set(['SIGTERM','SIGKILL','SIGINT','SIGABRT','SIGSEGV','SIGHUP','SIGPIPE']);
|
|
9
|
+
const allowed=(set,value)=>set.has(value)?value:value==null?null:'other';
|
|
10
|
+
|
|
11
|
+
export function hostDiagnostic(child,{timeoutMs=null,now=()=>performance.now()}={}){
|
|
12
|
+
const started=now(),events=[];
|
|
13
|
+
let stdoutBytes=0,stderrBytes=0,exitCode=null,signal=null,closed=false;
|
|
14
|
+
let lastOperation=null,lastKind=null,lastState=null,lastCode=null,eventCount=0;
|
|
15
|
+
const elapsed=()=>Math.max(0,Math.round(now()-started));
|
|
16
|
+
const mark=(direction,row={})=>{
|
|
17
|
+
const operation=allowed(operations,row.operation??row.type);
|
|
18
|
+
const kind=allowed(kinds,row.kind),state=allowed(states,row.result?.state??row.result?.stage);
|
|
19
|
+
const code=allowed(codes,row.result?.code??row.error?.code);
|
|
20
|
+
if(direction==='send'&&operation)lastOperation=operation;
|
|
21
|
+
if(kind)lastKind=kind;if(state)lastState=state;if(code)lastCode=code;
|
|
22
|
+
events.push({n:++eventCount,elapsedMs:elapsed(),direction,operation,kind,state,code});
|
|
23
|
+
if(events.length>32)events.shift();
|
|
24
|
+
};
|
|
25
|
+
child.stdout?.on('data',chunk=>{stdoutBytes+=Buffer.byteLength(chunk);});
|
|
26
|
+
child.stderr?.on('data',chunk=>{stderrBytes+=Buffer.byteLength(chunk);});
|
|
27
|
+
child.once('close',(code,value)=>{closed=true;exitCode=Number.isInteger(code)?code:null;signal=allowed(signals,value);});
|
|
28
|
+
const snapshot=()=>({pid:Number.isInteger(child.pid)?child.pid:null,timeoutMs,elapsedMs:elapsed(),
|
|
29
|
+
closed,exitCode,signal,stdoutBytes,stderrBytes,eventCount,lastOperation,lastKind,lastState,lastCode,
|
|
30
|
+
events:events.map(event=>({...event}))});
|
|
31
|
+
return {send:row=>mark('send',row),receive:row=>mark('receive',row),snapshot,
|
|
32
|
+
attach:error=>Object.assign(error,{diagnostic:snapshot()})};
|
|
33
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Test-only handoff/review builders; production gates remain the authority.
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {createHash} from 'node:crypto';
|
|
5
|
+
import {implementationSha256} from '../cm-task-gate.mjs';
|
|
6
|
+
|
|
7
|
+
export function writeHandoff(file,root,files,attempt=1){
|
|
8
|
+
fs.writeFileSync(file,JSON.stringify({schema_version:1,task_id:'T-001',attempt,status:'ready_for_review',
|
|
9
|
+
changed_files:files,implementation_sha256:implementationSha256(root,files),
|
|
10
|
+
verification:[{command:'fixture',status:'passed',evidence:'synthetic check'}],
|
|
11
|
+
evidence:['synthetic check'],blockers:[],scope_deviation:[]}));
|
|
12
|
+
}
|
|
13
|
+
export function writeReview(file,handoff,attempt=1,verdict='approved'){
|
|
14
|
+
const payload=JSON.parse(fs.readFileSync(handoff));
|
|
15
|
+
const sha=createHash('sha256').update(fs.readFileSync(handoff)).digest('hex');
|
|
16
|
+
const body=verdict==='approved'?'Zero findings.':'Changes required.';
|
|
17
|
+
fs.writeFileSync(file,`---\nat: 2026-09-07T00:00:00Z\nreviewer: codex-subagent\nindependent: true\ntask: T-001\nattempt: ${attempt}\nround: ${attempt}\nverdict: ${verdict}\nblocking_findings: ${verdict==='approved'?0:1}\nhandoff: ${path.basename(handoff)}\nhandoff_sha256: ${sha}\nscope:\n${payload.changed_files.map(p=>` - ${p}`).join('\n')}\n---\n\n${body} Synthetic review.\n`);
|
|
18
|
+
}
|