@aibyzero/cm-workflow 0.16.5 → 0.16.7
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 +14 -0
- package/CHANGELOG.md +19 -1
- package/README.md +17 -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 +28 -7
- package/docs/js-workflow-control.md +96 -6
- package/docs/live-evidence-drivers.md +62 -0
- package/docs/next-steps.md +15 -10
- 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/claude-review-adapter.mjs +7 -4
- package/runtime/js/cm-ai/claude-tool-preview.mjs +4 -4
- package/runtime/js/cm-ai/cm-ai-admission.mjs +34 -10
- package/runtime/js/cm-ai/cm-ai-context-refresh.mjs +9 -5
- package/runtime/js/cm-ai/cm-ai-conversation-entry.mjs +111 -34
- package/runtime/js/cm-ai/cm-ai-qa-log.mjs +93 -31
- package/runtime/js/cm-ai/cm-ai-run-finalizer.mjs +13 -57
- package/runtime/js/cm-ai/codex-config.mjs +3 -2
- package/runtime/js/cm-ai/codex-review-adapter.mjs +34 -15
- package/runtime/js/cm-ai/committed-rule-basis.mjs +76 -0
- package/runtime/js/cm-ai/developer-adapter.mjs +8 -5
- package/runtime/js/cm-ai/drive-bootstrap.mjs +22 -12
- package/runtime/js/cm-ai/drive-core.mjs +9 -3
- package/runtime/js/cm-ai/durable-runner-state.mjs +146 -14
- package/runtime/js/cm-ai/effect-contract.mjs +1 -1
- package/runtime/js/cm-ai/execution-policy.mjs +58 -0
- 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/host-bootstrap.mjs +70 -20
- package/runtime/js/cm-ai/host-check.mjs +30 -4
- package/runtime/js/cm-ai/host-conversation-execution.mjs +59 -17
- package/runtime/js/cm-ai/host-documentation.mjs +2 -2
- 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 +54 -8
- package/runtime/js/cm-ai/host-qa-fix-owner.mjs +22 -5
- package/runtime/js/cm-ai/host-session.mjs +1 -1
- package/runtime/js/cm-ai/host-workflow-capabilities.mjs +3 -1
- package/runtime/js/cm-ai/knowledge-closeout.mjs +56 -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 +36 -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 +89 -0
- package/runtime/js/cm-ai/owned-process-cleanup.mjs +22 -0
- package/runtime/js/cm-ai/provider-review-observation.mjs +15 -0
- package/runtime/js/cm-ai/provider-usage.mjs +39 -0
- package/runtime/js/cm-ai/review-package.mjs +11 -0
- 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/status-projection.mjs +93 -0
- package/runtime/js/cm-ai/task-runner.mjs +176 -25
- 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 +183 -40
- package/runtime/js/cm-fix/final-review.mjs +18 -10
- package/runtime/js/cm-fix/finish.mjs +2 -19
- package/runtime/js/cm-fix/host-review.mjs +25 -6
- package/runtime/js/cm-fix/host.mjs +4 -1
- package/runtime/js/cm-fix/layout.mjs +1 -1
- package/runtime/js/cm-fix/log-events.mjs +29 -0
- package/runtime/js/cm-fix/metrics.mjs +3 -2
- package/runtime/js/cm-fix/progress.mjs +4 -0
- package/runtime/js/cm-fix/review-reconciliation.mjs +64 -0
- package/runtime/js/cm-prd/analysis.mjs +5 -2
- package/runtime/js/cm-prd/response-recovery.mjs +23 -0
- package/runtime/js/cm-prd/review-host.mjs +2 -1
- package/runtime/js/cm-prd/review-publication.mjs +23 -13
- package/runtime/js/cm-prd/review-time.mjs +29 -0
- package/runtime/js/cm-prd/session.mjs +53 -6
- package/runtime/js/cm-security/finalize.mjs +32 -0
- package/runtime/js/cm-test/recovery.mjs +4 -4
- package/runtime/review.md +5 -0
- package/runtime/task-gates.md +6 -0
- package/runtime/workflow-config.md +10 -1
- package/scripts/cm-ai-admission.mjs +14 -3
- package/scripts/cm-ai-batch-drive.mjs +52 -23
- package/scripts/cm-ai-batch-drive.test.mjs +47 -2
- package/scripts/cm-ai-batch-host.mjs +44 -16
- package/scripts/cm-ai-batch-run.mjs +77 -29
- package/scripts/cm-ai-bootstrap-flow.test.mjs +3 -2
- package/scripts/cm-ai-bootstrap-merge.test.mjs +118 -1
- package/scripts/cm-ai-bootstrap.test.mjs +80 -87
- package/scripts/cm-ai-conversation-entry-ops.test.mjs +15 -0
- package/scripts/cm-ai-develop-driver-gaps.test.mjs +102 -0
- package/scripts/cm-ai-drive-bootstrap-rules.test.mjs +2 -2
- package/scripts/cm-ai-drive.mjs +73 -28
- package/scripts/cm-ai-drive.test.mjs +119 -1
- package/scripts/cm-ai-feature-selection.test.mjs +178 -0
- package/scripts/cm-ai-host.mjs +79 -27
- package/scripts/cm-ai-host.test.mjs +88 -0
- package/scripts/cm-ai-operator-guidance.test.mjs +94 -0
- package/scripts/cm-ai-progress.test.mjs +521 -0
- package/scripts/cm-ai-protected-scope.test.mjs +194 -0
- package/scripts/cm-ai-qa-config-revision.test.mjs +21 -0
- package/scripts/cm-ai-review-failure.test.mjs +71 -11
- package/scripts/cm-ai-run.mjs +94 -19
- package/scripts/cm-ai-run.test.mjs +2 -1
- package/scripts/cm-bootstrap-review-recovery.test.mjs +70 -0
- package/scripts/cm-check-drive.test.mjs +1 -0
- package/scripts/cm-check-runtime.sh +11 -0
- package/scripts/cm-claude-install-layout.test.mjs +26 -0
- package/scripts/cm-claude-probe.test.mjs +1 -1
- 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-fix-drive.mjs +28 -13
- package/scripts/cm-fix-final-review.test.mjs +11 -6
- package/scripts/cm-fix-host.mjs +17 -10
- package/scripts/cm-fix-large-log.test.mjs +113 -0
- 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 +7 -1
- package/scripts/cm-host-qa-executor.test.mjs +329 -3
- package/scripts/cm-knowledge-closeout.test.mjs +160 -0
- package/scripts/cm-live-evidence.test.mjs +64 -0
- package/scripts/cm-log-event.mjs +34 -7
- package/scripts/cm-log-event.py +15 -0
- package/scripts/cm-model-setup.mjs +79 -0
- package/scripts/cm-prd-drive.mjs +32 -11
- package/scripts/cm-prd-drive.test.mjs +15 -0
- package/scripts/cm-prd-host.mjs +26 -6
- package/scripts/cm-prd-host.test.mjs +4 -0
- package/scripts/cm-prd-review-host.test.mjs +17 -0
- package/scripts/cm-prd-session-recovery.test.mjs +44 -2
- package/scripts/cm-prd-task-grouping.test.mjs +206 -0
- package/scripts/cm-release-smoke.sh +5 -1
- package/scripts/cm-review-scope-recovery.test.mjs +5 -3
- 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-task-gate-correction.test.mjs +117 -0
- package/scripts/cm-task-gate.mjs +146 -10
- package/scripts/cm-task-gate.py +1 -0
- package/scripts/cm-test-branch-impact.test.mjs +11 -0
- 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/live-evidence-driver.mjs +35 -0
- package/scripts/fixtures/process-cleanup.mjs +3 -1
- package/scripts/test-cm-native-usage.py +62 -0
- package/scripts/test-external-model-setup.py +91 -0
- package/scripts/test-model-configuration-write.py +201 -0
- package/scripts/test-npm-install.py +10 -1
- 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 +16 -7
- 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 +30 -2
- package/skills/cm-prd/SKILL.md +5 -4
- package/skills/cm-prd/references/spec-self-check.md +3 -1
- 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,70 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import {fixture,open} from './fixtures/bootstrap-review-runner.mjs';
|
|
6
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
7
|
+
import {runnerStatus} from '../runtime/js/cm-ai/durable-runner-state.mjs';
|
|
8
|
+
import {createCmAiConversationEntry} from '../runtime/js/cm-ai/cm-ai-conversation-entry.mjs';
|
|
9
|
+
|
|
10
|
+
const FIXTURE_TIMEOUT_MS=Number(process.env.CM_TEST_FIXTURE_TIMEOUT_MS??60000);
|
|
11
|
+
function rechain(records){
|
|
12
|
+
let previousDigest=null;
|
|
13
|
+
for(const row of records){row.previousDigest=previousDigest;const {digest:old,...body}=row;row.digest=digest(body);previousDigest=row.digest;}
|
|
14
|
+
return records;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
test('legacy unknown bootstrap checkpoint recovers its original package without redispatch',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
18
|
+
const f=fixture(t);
|
|
19
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
20
|
+
run=open(f,'T-002');assert.equal((await run.effect('develop')).state,'awaiting_review');
|
|
21
|
+
const calls=[...f.calls],storePath=path.join(f.specsDir,'.reviews','.execution','run-T-002','state.json');
|
|
22
|
+
const saved=run.store.snapshot(),rows=structuredClone(saved.records),originalPackage=rows.at(-1).payload.checkpoint.reviewPackage;
|
|
23
|
+
assert(originalPackage);run.close();
|
|
24
|
+
// Model the exact older checkpoint shape: the developer succeeded and the
|
|
25
|
+
// host retained checks and Learning evidence, but package validation threw.
|
|
26
|
+
const checkpoint=rows.at(-1).payload.checkpoint;
|
|
27
|
+
checkpoint.state='unknown';checkpoint.code='execution_error';checkpoint.reason=null;checkpoint.reviewPackage=null;
|
|
28
|
+
checkpoint.cache.at(-1).result=runnerStatus(checkpoint,rows[0].payload.config);
|
|
29
|
+
rechain(rows);
|
|
30
|
+
const {revision:oldRevision,...body}=saved,legacy={...body,records:rows};
|
|
31
|
+
assert(oldRevision);
|
|
32
|
+
fs.writeFileSync(storePath,JSON.stringify({...legacy,revision:digest(legacy)})+'\n');
|
|
33
|
+
run=open(f,'T-002','resume');
|
|
34
|
+
assert.equal(run.runner.status().state,'unknown');assert.equal(run.runner.status().bootstrapReviewRecovery,true);
|
|
35
|
+
const entry=createCmAiConversationEntry({specsDir:f.specsDir,codeProject:f.codeProject,feature:'0.bootstrap',
|
|
36
|
+
identity:run.definition.identity,runner:run.runner,allowBootstrapReviewRecovery:true});
|
|
37
|
+
const statusBefore=run.store.snapshot();
|
|
38
|
+
const guidance=(await entry.handle({version:1,operation:'status',requestId:'recovery-status',identity:run.definition.identity})).guidance;
|
|
39
|
+
assert.equal(guidance.recoveryOperation,'bootstrap_review_recover');assert.match(guidance.nextStep,/不重新派发开发/);
|
|
40
|
+
assert.equal(guidance.authorizationGranted,false);assert.deepEqual(run.store.snapshot(),statusBefore);
|
|
41
|
+
const recovery=await entry.handle({version:1,operation:'bootstrap_review_recover',requestId:'recover-bootstrap',
|
|
42
|
+
identity:run.definition.identity,reason:'Original package validation rejected an unchanged rule'});
|
|
43
|
+
assert.equal(recovery.outcome,'advanced',JSON.stringify(recovery));
|
|
44
|
+
assert.equal(recovery.pendingAction,'decision');
|
|
45
|
+
const result=run.runner.status();
|
|
46
|
+
assert.equal(result.state,'awaiting_review',JSON.stringify(result));
|
|
47
|
+
assert.equal(result.packageDigest,originalPackage.packageDigest);
|
|
48
|
+
assert.equal(run.store.snapshot().records.at(-1).payload.type,'bootstrap-review-recovered');
|
|
49
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
50
|
+
run=open(f,'T-002','resume');assert.equal(run.runner.status().state,'awaiting_review');
|
|
51
|
+
assert.equal((await run.effect('review')).state,'approved');
|
|
52
|
+
const completed=await run.effect('complete');assert.equal(completed.state,'fixture_completed',JSON.stringify(completed));run.close();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('instruction bootstrap review material limits never grant a developer redispatch',{timeout:FIXTURE_TIMEOUT_MS},async t=>{
|
|
56
|
+
const f=fixture(t);
|
|
57
|
+
let run=open(f,'T-001');await run.effect('develop');await run.effect('review');await run.effect('complete');run.close();
|
|
58
|
+
run=open(f,'T-002','create',{afterCheck:()=>{
|
|
59
|
+
fs.mkdirSync(path.join(f.codeProject,'notes'),{recursive:true});
|
|
60
|
+
fs.writeFileSync(path.join(f.codeProject,'notes','AGENTS.md'),'x'.repeat(2100*1024));
|
|
61
|
+
}});
|
|
62
|
+
const result=await run.effect('develop');
|
|
63
|
+
assert.equal(result.state,'unknown',JSON.stringify(result));assert.equal(result.code,'limit_exceeded');
|
|
64
|
+
assert.equal(run.runner.status().bootstrapReviewRecovery,undefined);
|
|
65
|
+
const calls=[...f.calls];run.close();
|
|
66
|
+
run=open(f,'T-002','resume');
|
|
67
|
+
const retry=await run.effect('develop','-retry');
|
|
68
|
+
assert.equal(retry.outcome,'rejected');assert.equal(retry.code,'stage_mismatch');
|
|
69
|
+
assert.deepEqual(f.calls,calls);run.close();
|
|
70
|
+
});
|
|
@@ -12,6 +12,7 @@ function fixture(t,exit=0){
|
|
|
12
12
|
t.after(()=>fs.rmSync(dir,{recursive:true,force:true}));
|
|
13
13
|
for(const file of ['scripts/cm-check-entry.mjs','scripts/cm-check-host.mjs','scripts/cm-check-drive.mjs',
|
|
14
14
|
'scripts/cm-workflow-config.mjs','runtime/js/cm-check/host.mjs','runtime/js/cm-ai/drive-core.mjs',
|
|
15
|
+
'runtime/js/cm-ai/operator-guidance.mjs',
|
|
15
16
|
'runtime/js/cm-ai/host-tool-bridge.mjs','runtime/js/cm-ai/host-session.mjs','runtime/js/cm-ai/diagnostic-reason.mjs','runtime/js/cm-ai/effect-contract.mjs',
|
|
16
17
|
'runtime/js/cm-ai/contracts.mjs','runtime/js/cm-init/draft-inspection.mjs','skills/cm-check/SKILL.md']){
|
|
17
18
|
fs.mkdirSync(path.dirname(path.join(dir,file)),{recursive:true});fs.copyFileSync(path.join(root,file),path.join(dir,file));
|
|
@@ -310,8 +310,19 @@ require_file "scripts/cm-openai-compatible-call.py"
|
|
|
310
310
|
require_file "scripts/test-cm-openai-compatible-call.py"
|
|
311
311
|
require_file "scripts/cm-task-gate.mjs"
|
|
312
312
|
require_file "scripts/cm-task-gate.test.mjs"
|
|
313
|
+
require_file "scripts/cm-task-gate-correction.test.mjs"
|
|
314
|
+
HUMAN_CORRECTION_DOC="docs/human-correction.md"
|
|
315
|
+
if [ "$MODE" != "plugin" ]; then
|
|
316
|
+
HUMAN_CORRECTION_DOC="cm-workflow/docs/human-correction.md"
|
|
317
|
+
fi
|
|
318
|
+
require_file "$HUMAN_CORRECTION_DOC"
|
|
313
319
|
require_file "scripts/cm-task-gate.py"
|
|
314
320
|
require_file "scripts/test-task-gate.py"
|
|
321
|
+
for correction_command in prepare-human-correction publish-human-correction-review; do
|
|
322
|
+
grep -Fq "$correction_command" "$ROOT/scripts/cm-task-gate.mjs" &&
|
|
323
|
+
grep -Fq "$correction_command" "$ROOT/$HUMAN_CORRECTION_DOC" ||
|
|
324
|
+
fail "human correction command/document pair incomplete: $correction_command"
|
|
325
|
+
done
|
|
315
326
|
require_file "scripts/cm-workflow-config.mjs"
|
|
316
327
|
require_file "scripts/cm-workflow-config.test.mjs"
|
|
317
328
|
# Group 4: user runtimes.yml producers <-> authoritative consumer.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
const source=fileURLToPath(new URL('..',import.meta.url));
|
|
9
|
+
test('real isolated Claude install checks correction docs at its installed layout and refuses a missing document',
|
|
10
|
+
{skip:process.platform==='win32',timeout:180000},t=>{
|
|
11
|
+
const home=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-claude-install-layout-')));
|
|
12
|
+
t.after(()=>fs.rmSync(home,{recursive:true,force:true}));
|
|
13
|
+
const target=path.join(home,'.claude'),env={...process.env,HOME:home,CLAUDE_HOME:target,
|
|
14
|
+
CM_WORKFLOW_HOME:path.join(home,'user'),CM_WORKFLOW_LOG_HOME:path.join(home,'logs')};
|
|
15
|
+
const installed=spawnSync('/bin/bash',[path.join(source,'install.sh'),'--yes'],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
|
|
16
|
+
assert.equal(installed.status,0,installed.stdout+installed.stderr);
|
|
17
|
+
assert.match(installed.stdout,/cm runtime check: PASSED \(claude-compat v/);
|
|
18
|
+
const doc=path.join(target,'cm-workflow/docs/human-correction.md');
|
|
19
|
+
assert.equal(fs.readFileSync(doc,'utf8'),fs.readFileSync(path.join(source,'docs/human-correction.md'),'utf8'));
|
|
20
|
+
assert.equal(fs.existsSync(path.join(target,'docs/human-correction.md')),false);
|
|
21
|
+
fs.unlinkSync(doc);
|
|
22
|
+
const rejected=spawnSync('/bin/bash',[path.join(target,'scripts/cm-check-runtime.sh'),'--project',source],{cwd:source,env,encoding:'utf8',timeout:120000,maxBuffer:4*1024*1024});
|
|
23
|
+
assert.notEqual(rejected.status,0);
|
|
24
|
+
assert.match(rejected.stderr,/missing cm-workflow\/docs\/human-correction\.md/);
|
|
25
|
+
assert.match(rejected.stderr,/human correction command\/document pair incomplete/);
|
|
26
|
+
});
|
|
@@ -40,7 +40,7 @@ test('fake Claude process stderr marker yields only its reported model',async()=
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// Darwin fixtures run in the dedicated macOS CI job and were exercised locally.
|
|
44
44
|
// The sink intentionally retains protocol checks, never the decoded body bytes.
|
|
45
45
|
for(const encoding of ['gzip','zstd','br'])test(`Claude probe ${encoding} body reaches only its declared decoder`,
|
|
46
46
|
{skip:process.platform!=='darwin'||(encoding==='zstd'&&typeof zlib.zstdCompressSync!=='function')},async()=>{
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Small metadata fallback for Codex versions without the old optional helpers.
|
|
3
|
+
|
|
4
|
+
Official plugin-creator still owns marketplace registration; Codex CLI validates
|
|
5
|
+
and installs the plugin. This script only reads a marketplace name or updates a
|
|
6
|
+
staged plugin's cache version. It never installs or edits user configuration.
|
|
7
|
+
"""
|
|
8
|
+
import datetime
|
|
9
|
+
import hashlib
|
|
10
|
+
import json
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
import re
|
|
13
|
+
import sys
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def object_pairs(pairs):
|
|
17
|
+
value = {}
|
|
18
|
+
for key, item in pairs:
|
|
19
|
+
if key in value:
|
|
20
|
+
raise ValueError('duplicate JSON key: ' + key)
|
|
21
|
+
value[key] = item
|
|
22
|
+
return value
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def read_object(file):
|
|
26
|
+
if file.is_symlink() or not file.is_file():
|
|
27
|
+
raise ValueError('metadata must be a regular non-symlink file')
|
|
28
|
+
value = json.loads(file.read_text(encoding='utf-8'), object_pairs_hook=object_pairs)
|
|
29
|
+
if not isinstance(value, dict):
|
|
30
|
+
raise ValueError('metadata must be a JSON object')
|
|
31
|
+
return value
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def main(args):
|
|
35
|
+
if len(args) != 2 or args[0] not in ('marketplace-name', 'initialize-marketplace', 'cache-version'):
|
|
36
|
+
raise ValueError('usage: cm-codex-plugin-metadata.py {marketplace-name|initialize-marketplace|cache-version} PATH')
|
|
37
|
+
operation, raw = args
|
|
38
|
+
if operation == 'initialize-marketplace':
|
|
39
|
+
file = Path(raw)
|
|
40
|
+
marketplace = read_object(file)
|
|
41
|
+
if marketplace.get('name') == '[TODO: marketplace-name]':
|
|
42
|
+
plugins = marketplace.get('plugins')
|
|
43
|
+
if not isinstance(plugins, list) or len(plugins) != 1 or not isinstance(plugins[0], dict) or plugins[0].get('name') != 'cm-workflow':
|
|
44
|
+
raise ValueError('initial marketplace must be the official fresh CM scaffold')
|
|
45
|
+
marketplace['name'] = 'personal'
|
|
46
|
+
interface = marketplace.get('interface')
|
|
47
|
+
if isinstance(interface, dict) and interface.get('displayName') == '[TODO: display-name]':
|
|
48
|
+
interface['displayName'] = 'Personal plugins'
|
|
49
|
+
file.write_text(json.dumps(marketplace, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
50
|
+
elif not isinstance(marketplace.get('name'), str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]*', marketplace['name']):
|
|
51
|
+
raise ValueError('initial marketplace requires a valid name or official placeholder')
|
|
52
|
+
return
|
|
53
|
+
if operation == 'marketplace-name':
|
|
54
|
+
name = read_object(Path(raw)).get('name')
|
|
55
|
+
if not isinstance(name, str) or not re.fullmatch(r'[A-Za-z0-9][A-Za-z0-9_.-]*', name):
|
|
56
|
+
raise ValueError('marketplace requires a valid name')
|
|
57
|
+
print(name)
|
|
58
|
+
return
|
|
59
|
+
root = Path(raw)
|
|
60
|
+
if root.is_symlink() or not root.is_dir():
|
|
61
|
+
raise ValueError('stage must be a real directory')
|
|
62
|
+
file = root / '.codex-plugin' / 'plugin.json'
|
|
63
|
+
if file.parent.is_symlink():
|
|
64
|
+
raise ValueError('manifest parent must be a real directory')
|
|
65
|
+
plugin = read_object(file)
|
|
66
|
+
version = (root / 'VERSION').read_text(encoding='utf-8').strip()
|
|
67
|
+
if plugin.get('name') != 'cm-workflow' or not re.fullmatch(r'\d+\.\d+\.\d+', version):
|
|
68
|
+
raise ValueError('cache version requires a CM plugin and base VERSION')
|
|
69
|
+
if plugin.get('version', '').split('+', 1)[0] != version:
|
|
70
|
+
raise ValueError('manifest base version must match VERSION')
|
|
71
|
+
stamp = datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%d%H%M%S%f')
|
|
72
|
+
fingerprint = hashlib.sha256(file.read_bytes()).hexdigest()[:12]
|
|
73
|
+
plugin['version'] = version + '+codex.' + stamp + '.' + fingerprint
|
|
74
|
+
file.write_text(json.dumps(plugin, ensure_ascii=False, indent=2) + '\n', encoding='utf-8')
|
|
75
|
+
print(plugin['version'])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == '__main__':
|
|
79
|
+
try:
|
|
80
|
+
main(sys.argv[1:])
|
|
81
|
+
except (ValueError, OSError) as error:
|
|
82
|
+
print('ERROR: ' + str(error), file=sys.stderr)
|
|
83
|
+
raise SystemExit(1)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import {spawnSync} from 'node:child_process';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
const script=fileURLToPath(new URL('./cm-codex-plugin-metadata.py',import.meta.url));
|
|
9
|
+
function fixture(t){
|
|
10
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-plugin-metadata-')));
|
|
11
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
12
|
+
const run=(operation,file)=>spawnSync(process.env.CM_PYTHON_BIN||'python3',[script,operation,file],{encoding:'utf8'});
|
|
13
|
+
return {root,run};
|
|
14
|
+
}
|
|
15
|
+
test('metadata fallback reads marketplace identity without rewriting other plugins or user bytes',t=>{
|
|
16
|
+
const {root,run}=fixture(t),file=path.join(root,'marketplace.json');
|
|
17
|
+
const bytes='{"name":"local-personal","plugins":[{"name":"unrelated"}]}\n';fs.writeFileSync(file,bytes);
|
|
18
|
+
const result=run('marketplace-name',file);assert.equal(result.status,0,result.stderr);assert.equal(result.stdout,'local-personal\n');assert.equal(fs.readFileSync(file,'utf8'),bytes);
|
|
19
|
+
for(const value of ['[]','{"name":"bad@name"}','{"name":"good","name":"other"}']){
|
|
20
|
+
fs.writeFileSync(file,value);assert.equal(run('marketplace-name',file).status,1);
|
|
21
|
+
assert.equal(fs.readFileSync(file,'utf8'),value);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
test('cache version fallback keeps manifest contents and source base while yielding distinct build identities',t=>{
|
|
25
|
+
const {root,run}=fixture(t);fs.mkdirSync(path.join(root,'.codex-plugin'));
|
|
26
|
+
const file=path.join(root,'.codex-plugin/plugin.json'),before={name:'cm-workflow',version:'0.16.5',skills:'./skills',interface:{displayName:'CM'}};
|
|
27
|
+
fs.writeFileSync(file,JSON.stringify(before));fs.writeFileSync(path.join(root,'VERSION'),'0.16.5\n');
|
|
28
|
+
const first=run('cache-version',root);assert.equal(first.status,0,first.stderr);
|
|
29
|
+
const after=JSON.parse(fs.readFileSync(file));assert.match(after.version,/^0\.16\.5\+codex\.\d{20}\.[a-f0-9]{12}$/);
|
|
30
|
+
assert.deepEqual({...after,version:before.version},before);assert.equal(fs.readFileSync(path.join(root,'VERSION'),'utf8'),'0.16.5\n');
|
|
31
|
+
const second=run('cache-version',root);assert.equal(second.status,0,second.stderr);assert.notEqual(first.stdout,second.stdout);
|
|
32
|
+
});
|
|
33
|
+
test('metadata fallback rejects unsafe manifests and stages before writing',t=>{
|
|
34
|
+
const {root,run}=fixture(t);fs.mkdirSync(path.join(root,'.codex-plugin'));fs.writeFileSync(path.join(root,'VERSION'),'0.16.5');
|
|
35
|
+
const file=path.join(root,'.codex-plugin/plugin.json');
|
|
36
|
+
for(const data of [{name:'other',version:'0.16.5'},{name:'cm-workflow',version:'0.16.4'}]){
|
|
37
|
+
const bytes=JSON.stringify(data);fs.writeFileSync(file,bytes);assert.equal(run('cache-version',root).status,1);assert.equal(fs.readFileSync(file,'utf8'),bytes);
|
|
38
|
+
}
|
|
39
|
+
const external=path.join(root,'external');fs.writeFileSync(external,'{"name":"cm-workflow","version":"0.16.5"}');
|
|
40
|
+
fs.unlinkSync(file);fs.symlinkSync(external,file);assert.equal(run('cache-version',root).status,1);assert.equal(fs.readFileSync(external,'utf8'),'{"name":"cm-workflow","version":"0.16.5"}');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Uses the same placeholder emitted by the current official creator; installed
|
|
44
|
+
// user names and sibling plugins must not be normalized during an upgrade.
|
|
45
|
+
test('fresh official marketplace placeholder gets a valid personal name while existing identity is preserved',t=>{
|
|
46
|
+
const {root,run}=fixture(t),file=path.join(root,'marketplace.json');
|
|
47
|
+
const seed={name:'[TODO: marketplace-name]',interface:{displayName:'[TODO: display-name]'},plugins:[{name:'cm-workflow',source:{source:'local',path:'./plugins/cm-workflow'}}]};
|
|
48
|
+
fs.writeFileSync(file,JSON.stringify(seed));assert.equal(run('initialize-marketplace',file).status,0);
|
|
49
|
+
assert.equal(run('marketplace-name',file).stdout,'personal\n');
|
|
50
|
+
const initialized=JSON.parse(fs.readFileSync(file));assert.deepEqual(initialized.plugins,seed.plugins);
|
|
51
|
+
const existing=JSON.stringify({name:'existing-personal',plugins:[...seed.plugins,{name:'other'}]});
|
|
52
|
+
fs.writeFileSync(file,existing);assert.equal(run('initialize-marketplace',file).status,0);assert.equal(fs.readFileSync(file,'utf8'),existing);
|
|
53
|
+
seed.plugins.push({name:'other'});const invalid=JSON.stringify(seed);fs.writeFileSync(file,invalid);
|
|
54
|
+
assert.equal(run('initialize-marketplace',file).status,1);assert.equal(fs.readFileSync(file,'utf8'),invalid);
|
|
55
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
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 {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
7
|
+
const identity={repositoryId:'fixture',runId:'efficiency',taskId:'T-001',attempt:1};
|
|
8
|
+
function fixture(t){const cwd=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-efficiency-check-')));t.after(()=>fs.rmSync(cwd,{recursive:true,force:true}));return cwd;}
|
|
9
|
+
const control=()=>({signal:new AbortController().signal});
|
|
10
|
+
const command=[process.execPath,'-e',"require('node:fs').appendFileSync('executions','x');console.log('tests 3\\npass 3\\nfail 0')"];
|
|
11
|
+
test('declared adjacent identical checks share one execution; final acceptance executes again',async t=>{
|
|
12
|
+
const cwd=fixture(t),output=[],progress=[];
|
|
13
|
+
const check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'tests',command},{id:'ui',command,sameExecutionAs:'tests'}],
|
|
14
|
+
onOutput:value=>{output.push(value.chunk.toString());},onProgress:value=>{progress.push(value);}});
|
|
15
|
+
const rows=await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'x');
|
|
16
|
+
assert.deepEqual(rows.map(r=>r.id),['tests','ui']);assert(rows.every(r=>r.outcome==='passed'));
|
|
17
|
+
assert.match(rows[1].evidence,/same execution as tests;.*tests 3/);assert.equal(output.length,1);
|
|
18
|
+
assert.equal(progress.filter(p=>p.phase==='start').length,1);
|
|
19
|
+
await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'xx');
|
|
20
|
+
});
|
|
21
|
+
test('identical commands without explicit alias continue to execute twice',async t=>{
|
|
22
|
+
const cwd=fixture(t),check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'one',command},{id:'two',command}]});
|
|
23
|
+
await check({identity},control());assert.equal(fs.readFileSync(path.join(cwd,'executions'),'utf8'),'xx');
|
|
24
|
+
});
|
|
25
|
+
test('alias requires opt-in, same command, adjacent source and unique identity',t=>{
|
|
26
|
+
const cwd=fixture(t),base=[{id:'one',command},{id:'two',command,sameExecutionAs:'one'}];
|
|
27
|
+
assert.throws(()=>createHostCheck({cwd,commands:base}),/invalid_input/);
|
|
28
|
+
for(const commands of [[base[1]], [base[0],{...base[1],command:[process.execPath,'--version']}],
|
|
29
|
+
[base[0],{id:'other',command},base[1]], [base[0],{...base[1],id:'one'}]])
|
|
30
|
+
assert.throws(()=>createHostCheck({cwd,reuseDeclared:true,commands}));
|
|
31
|
+
assert(!fs.existsSync(path.join(cwd,'executions')));
|
|
32
|
+
});
|
|
33
|
+
test('failed original command is never recycled into a passed alias',async t=>{
|
|
34
|
+
const cwd=fixture(t),fail=[process.execPath,'-e','process.exit(1)'];
|
|
35
|
+
const check=createHostCheck({cwd,reuseDeclared:true,commands:[{id:'one',command:fail},{id:'two',command:fail,sameExecutionAs:'one'}]});
|
|
36
|
+
const rows=await check({identity},control());assert.equal(rows.length,1);assert.equal(rows[0].outcome,'failed');
|
|
37
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// Fault injection only: no real process enumeration, listener or provider call.
|
|
2
|
+
import test from 'node:test';
|
|
3
|
+
import assert from 'node:assert/strict';
|
|
4
|
+
import fs from 'node:fs';
|
|
5
|
+
import os from 'node:os';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import http from 'node:http';
|
|
8
|
+
import {EventEmitter} from 'node:events';
|
|
9
|
+
import {spawnSync} from 'node:child_process';
|
|
10
|
+
import {main} from './cm-ai-host.mjs';
|
|
11
|
+
import {runLiveDriver} from './fixtures/live-evidence-driver.mjs';
|
|
12
|
+
|
|
13
|
+
function temporary(t){
|
|
14
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-efficiency-diagnostic-')));
|
|
15
|
+
t.after(()=>fs.rmSync(root,{recursive:true,force:true}));return root;
|
|
16
|
+
}
|
|
17
|
+
for(const [systemCode,syscall,address,expected] of [
|
|
18
|
+
['EPERM','listen','127.0.0.1',true],['EACCES','listen','127.0.0.1',true],
|
|
19
|
+
['EPERM','open','127.0.0.1',false],['EPERM','listen','192.0.2.1',false],
|
|
20
|
+
])test(`preflight safe fault diagnostic: ${systemCode}/${syscall}/${address}`,async t=>{
|
|
21
|
+
const root=temporary(t),codeProject=path.join(root,'code'),specsDir=path.join(root,'specs');
|
|
22
|
+
fs.mkdirSync(codeProject);fs.mkdirSync(specsDir);
|
|
23
|
+
const definition=path.join(root,'run.json');fs.writeFileSync(definition,JSON.stringify({version:1,
|
|
24
|
+
codeProject,specsDir,feature:'1.work',identity:{repositoryId:'fixture',runId:'diagnostic-run',taskId:'T-1',attempt:1},
|
|
25
|
+
scope:['target.mjs'],requirements:[]}));
|
|
26
|
+
const savedCreate=http.createServer,savedExists=fs.existsSync,platform=Object.getOwnPropertyDescriptor(process,'platform');
|
|
27
|
+
let listened=0,closed=0,stdout='',stderr='';
|
|
28
|
+
class FailedListener extends EventEmitter{
|
|
29
|
+
listen(port,host){assert.equal(port,0);assert.equal(host,'127.0.0.1');listened++;
|
|
30
|
+
queueMicrotask(()=>this.emit('error',Object.assign(Error('private synthetic error details'),{code:systemCode,syscall,address})));return this;}
|
|
31
|
+
address(){throw Error('worker dispatch must not be reached');}
|
|
32
|
+
closeAllConnections(){}
|
|
33
|
+
close(callback){closed++;callback();}
|
|
34
|
+
}
|
|
35
|
+
try{
|
|
36
|
+
// Model the supported platform without invoking its isolation primitive.
|
|
37
|
+
Object.defineProperty(process,'platform',{...platform,value:'darwin'});
|
|
38
|
+
fs.existsSync=value=>value==='/usr/bin/sandbox-exec'||savedExists(value);
|
|
39
|
+
http.createServer=()=>new FailedListener();
|
|
40
|
+
const status=await main(['preflight','--config',definition,'--review-model','fixture','--runtime','claude'],
|
|
41
|
+
{output:{write:value=>{stdout+=value;}},error:{write:value=>{stderr+=value;}}});
|
|
42
|
+
assert.equal(status,1);assert.equal(stdout,'');assert.equal(listened,1);assert.equal(closed,1);
|
|
43
|
+
const expectedError={code:'host_launch_failed',...(expected?{diagnostic:{operation:'listen',systemCode,address:'loopback'}}:{})};
|
|
44
|
+
assert.deepEqual(JSON.parse(stderr),{error:expectedError});
|
|
45
|
+
assert(!stderr.includes('private synthetic'));assert.equal(savedExists(path.join(specsDir,'.reviews')),false);
|
|
46
|
+
}finally{http.createServer=savedCreate;fs.existsSync=savedExists;Object.defineProperty(process,'platform',platform);}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
for(const mode of ['missing','not-executable','failed-command'])test(`process listing fails closed with bounded diagnostic: ${mode}`,t=>{
|
|
50
|
+
const root=temporary(t),bin=path.join(root,'bin');fs.mkdirSync(bin);
|
|
51
|
+
if(mode==='not-executable')fs.writeFileSync(path.join(bin,'ps'),'synthetic',{mode:0o600});
|
|
52
|
+
if(mode==='failed-command')fs.writeFileSync(path.join(bin,'ps'),`#!${process.execPath}\nprocess.stderr.write('private synthetic process detail');process.exit(7);\n`,{mode:0o700});
|
|
53
|
+
const helper=new URL('./fixtures/process-cleanup.mjs',import.meta.url).href;
|
|
54
|
+
const result=spawnSync(process.execPath,['--input-type=module','-e',`
|
|
55
|
+
import {fixtureProcesses} from ${JSON.stringify(helper)};
|
|
56
|
+
try{fixtureProcesses(${JSON.stringify(root)});process.exitCode=2;}
|
|
57
|
+
catch(error){process.stdout.write(JSON.stringify({code:error.code,diagnostic:error.diagnostic}));}`],
|
|
58
|
+
{encoding:'utf8',env:{...process.env,PATH:bin},timeout:5000});
|
|
59
|
+
assert.equal(result.status,0,result.stderr);
|
|
60
|
+
assert.deepEqual(JSON.parse(result.stdout),{code:'fixture_process_listing_failed',diagnostic:{command:'ps',
|
|
61
|
+
status:mode==='failed-command'?7:null,signal:null,systemCode:mode==='missing'?'ENOENT':mode==='not-executable'?'EACCES':null}});
|
|
62
|
+
assert(!result.stdout.includes('private synthetic'));assert.equal(result.stderr,'');
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('live fixture watchdog remains a failure and retains only bounded diagnostics',async t=>{
|
|
66
|
+
const root=temporary(t),driver=path.join(root,'driver.mjs');
|
|
67
|
+
fs.writeFileSync(driver,"process.stdout.write('private synthetic stdout');process.stderr.write('private synthetic stderr');setInterval(()=>{},1000);\n");
|
|
68
|
+
await assert.rejects(runLiveDriver(driver,path.join(root,'plan.json'),'advance',()=>{throw Error('no request expected');},{timeoutMs:700}),error=>{
|
|
69
|
+
assert.equal(error.code,'fixture_driver_timeout');assert.equal(error.diagnostic.timeoutMs,700);
|
|
70
|
+
assert(error.diagnostic.elapsedMs>=700);assert.equal(error.diagnostic.requestCount,0);
|
|
71
|
+
assert(error.diagnostic.stdoutBytes>0);assert(error.diagnostic.stderrBytes>0);
|
|
72
|
+
assert(!JSON.stringify(error).includes('private synthetic'));return true;
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Reproducible, synthetic, offline only. Byte counts are not model tokens.
|
|
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 {compactReviewData,expandReviewData} from '../runtime/js/cm-ai/review-presentation.mjs';
|
|
8
|
+
import {createHostCheck} from '../runtime/js/cm-ai/host-check.mjs';
|
|
9
|
+
import {digest} from '../runtime/js/cm-ai/effect-contract.mjs';
|
|
10
|
+
const text=Buffer.from('Fixture AC-001 and interface contract: return all case results.\n'.repeat(1024));
|
|
11
|
+
const file={path:'fixture.txt',size:text.length,sha256:createHash('sha256').update(text).digest('hex'),contentBase64:text.toString('base64')};
|
|
12
|
+
const data={reviewPackage:{packageDigest:'a'.repeat(64),changes:[{path:file.path,before:file,after:file}],
|
|
13
|
+
specification:{acceptanceCriteria:['AC-001'],interfaceContracts:['all case results'],systemContext:'Synthetic offline fixture'},
|
|
14
|
+
checks:[{id:'cases',outcome:'passed',evidence:'All synthetic case records retained'}]},priorReview:null,examinedPaths:[file.path]};
|
|
15
|
+
const presented=compactReviewData(data);
|
|
16
|
+
if(digest(expandReviewData(presented))!==digest(data))throw Error('evidence changed');
|
|
17
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-efficiency-offline-')));
|
|
18
|
+
try{
|
|
19
|
+
const counts={};
|
|
20
|
+
for(const enabled of [false,true]){
|
|
21
|
+
const cwd=path.join(root,String(enabled));fs.mkdirSync(cwd);
|
|
22
|
+
const command=[process.execPath,'-e',"require('node:fs').appendFileSync('physical-checks','x');console.log('synthetic check passed')"];
|
|
23
|
+
const check=createHostCheck({cwd,reuseDeclared:enabled,commands:[{id:'original',command},{id:'declared-same',command,...(enabled?{sameExecutionAs:'original'}:{})}]});
|
|
24
|
+
const phases=[];
|
|
25
|
+
for(const stage of ['development','final-acceptance']){
|
|
26
|
+
const rows=await check({identity:{repositoryId:'offline',runId:'offline-fixture',taskId:'T-001',attempt:1}},{signal:new AbortController().signal});
|
|
27
|
+
if(rows.length!==2||rows.some(row=>row.outcome!=='passed'))throw Error('check coverage changed');
|
|
28
|
+
phases.push({stage,coveredChecks:rows.length,physicalExecutionsSoFar:fs.readFileSync(path.join(cwd,'physical-checks'),'utf8').length});
|
|
29
|
+
}
|
|
30
|
+
counts[enabled?'enabled':'legacy']=phases;
|
|
31
|
+
}
|
|
32
|
+
process.stdout.write(JSON.stringify({kind:'synthetic-offline-experiment',version:1,
|
|
33
|
+
presentation:{fullBytes:Buffer.byteLength(JSON.stringify(data)),compactBytes:Buffer.byteLength(JSON.stringify(presented)),exactRoundTrip:true},
|
|
34
|
+
checks:counts,providerCalls:0,providerTokens:null,productionSavings:null},null,2)+'\n');
|
|
35
|
+
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
@@ -0,0 +1,48 @@
|
|
|
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 {EXECUTION_POLICY_V1,readExecutionPolicy,readBatchExecutionPolicy,freezeBatchExecutionPolicy,readFixExecutionPolicy} from '../runtime/js/cm-ai/execution-policy.mjs';
|
|
7
|
+
import {openFixExecution} from '../runtime/js/cm-fix/execution.mjs';
|
|
8
|
+
function fixture(t){
|
|
9
|
+
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'cm-efficiency-policy-')));t.after(()=>fs.rmSync(root,{recursive:true,force:true}));
|
|
10
|
+
const specsDir=path.join(root,'specs'),cwd=path.join(root,'code');fs.mkdirSync(specsDir);fs.mkdirSync(cwd);
|
|
11
|
+
return {root,specsDir,cwd};
|
|
12
|
+
}
|
|
13
|
+
test('versioned policy rejects incomplete, unknown and altered versions',()=>{
|
|
14
|
+
assert.deepEqual(readExecutionPolicy(EXECUTION_POLICY_V1),EXECUTION_POLICY_V1);
|
|
15
|
+
for(const raw of [{...EXECUTION_POLICY_V1,version:2},{version:1},{...EXECUTION_POLICY_V1,usage:'estimated'},{...EXECUTION_POLICY_V1,unknown:true}])assert.throws(()=>readExecutionPolicy(raw),{code:'execution_policy_invalid'});
|
|
16
|
+
});
|
|
17
|
+
test('batch policy is opt-in, immutable, binding checked and retained after disabling flag',async t=>{
|
|
18
|
+
const f=fixture(t),batch={repositoryId:'fixture',batchId:'batch-original',specsDir:f.specsDir,codeProject:f.cwd,tasks:[]};
|
|
19
|
+
assert.equal(readBatchExecutionPolicy({batch,started:false}),null);
|
|
20
|
+
const policy=readBatchExecutionPolicy({batch,started:false,enabled:true});await freezeBatchExecutionPolicy(batch,policy);
|
|
21
|
+
const dir=path.join(f.specsDir,'.cm-execution-policy-v1','.reviews','.execution'),run=fs.readdirSync(dir)[0],file=path.join(dir,run,'state.json'),bytes=fs.readFileSync(file);
|
|
22
|
+
assert.deepEqual(readBatchExecutionPolicy({batch,started:true}),EXECUTION_POLICY_V1);
|
|
23
|
+
await freezeBatchExecutionPolicy(batch,policy);assert.deepEqual(fs.readFileSync(file),bytes);
|
|
24
|
+
assert.throws(()=>readBatchExecutionPolicy({batch:{...batch,tasks:['changed']},started:true}),{code:'execution_policy_batch_binding'});assert.deepEqual(fs.readFileSync(file),bytes);
|
|
25
|
+
});
|
|
26
|
+
test('legacy batch cannot acquire policy after starting and creates no namespace',t=>{
|
|
27
|
+
const f=fixture(t),batch={repositoryId:'fixture',batchId:'batch-original',specsDir:f.specsDir};
|
|
28
|
+
assert.equal(readBatchExecutionPolicy({batch,started:true}),null);
|
|
29
|
+
assert.throws(()=>readBatchExecutionPolicy({batch,started:true,enabled:true}),{code:'execution_policy_legacy_run'});
|
|
30
|
+
assert(!fs.existsSync(path.join(f.specsDir,'.cm-execution-policy-v1')));
|
|
31
|
+
});
|
|
32
|
+
for(const optimized of [false,true])test(`${optimized?'new':'legacy'} fix policy resumes without mutating original configuration bytes`,t=>{
|
|
33
|
+
const f=fixture(t),config={specsRoot:f.specsDir,identity:{repositoryId:'fixture',runId:'fix-policy',taskId:'T-FIX-policy',attempt:1},
|
|
34
|
+
reproduction:{cwd:f.cwd,command:[process.execPath,'-e',"console.error('BUG');process.exit(1)"],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:1000}};
|
|
35
|
+
const policy=readFixExecutionPolicy({config,mode:'create',enabled:optimized});
|
|
36
|
+
const owner=openFixExecution({specsRoot:f.specsDir,identity:config.identity,create:true,configuration:{hostContextId:'original-host',defect:'Fixture',reproduction:config.reproduction,...(policy?{executionPolicy:policy}:{})}});owner.close();
|
|
37
|
+
const file=path.join(f.specsDir,'.reviews','.execution','fix-policy','state.json'),bytes=fs.readFileSync(file);
|
|
38
|
+
assert.deepEqual(readFixExecutionPolicy({config,mode:'resume'}),policy);
|
|
39
|
+
if(!optimized)assert.throws(()=>readFixExecutionPolicy({config,mode:'resume',enabled:true}),{code:'execution_policy_legacy_run'});
|
|
40
|
+
assert.deepEqual(fs.readFileSync(file),bytes);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('batch start log alone prevents retrofitting a legacy execution policy',t=>{
|
|
44
|
+
const f=fixture(t),batch={repositoryId:'fixture',batchId:'batch-log-only',specsDir:f.specsDir};
|
|
45
|
+
const file=path.join(f.specsDir,'运行日志.jsonl'),bytes=JSON.stringify({workflow:'cm-ai',run_id:batch.batchId,event:'decision',phase:'batch_start'})+'\n';fs.writeFileSync(file,bytes);
|
|
46
|
+
assert.throws(()=>readBatchExecutionPolicy({batch,started:false,enabled:true}),{code:'execution_policy_legacy_run'});
|
|
47
|
+
assert.equal(fs.readFileSync(file,'utf8'),bytes);assert(!fs.existsSync(path.join(f.specsDir,'.cm-execution-policy-v1')));
|
|
48
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import {createHash} from 'node:crypto';
|
|
4
|
+
import {compactReviewData,expandReviewData} from '../runtime/js/cm-ai/review-presentation.mjs';
|
|
5
|
+
const file=(path,bytes)=>({path,type:'file',mode:420,size:bytes.length,sha256:createHash('sha256').update(bytes).digest('hex'),contentBase64:bytes.toString('base64')});
|
|
6
|
+
test('complete inline presentation preserves AC/interface/context and all exact file bytes',()=>{
|
|
7
|
+
const text=Buffer.from('Fixture \"quotes\"\n中文 content\n'.repeat(1000));
|
|
8
|
+
const original={reviewPackage:{packageDigest:'a'.repeat(64),changes:[{path:'fixture.json',before:file('fixture.json',text),after:file('fixture.json',text)}],
|
|
9
|
+
specification:{acceptanceCriteria:['AC-001'],interfaceContracts:['GET /fixture'],systemContext:'Required deployment context'},
|
|
10
|
+
handoff:file('handoff.json',Buffer.from('{"case":"UI-001","passed":true}')),checks:[{id:'ui',command:['test-ui'],outcome:'passed',exitCode:0,evidence:'Case UI-001 passed'}]},
|
|
11
|
+
priorReview:{verdict:'changes_requested',findings:[{severity:'P1',message:'Original finding'}]},examinedPaths:['fixture.json']};
|
|
12
|
+
const bytes=JSON.stringify(original),presented=compactReviewData(original);
|
|
13
|
+
assert.deepEqual(expandReviewData(presented),original);assert.equal(JSON.stringify(original),bytes);
|
|
14
|
+
assert.equal(Object.keys(presented.contents).length,2);assert.equal(presented.contents['content-1'].encoding,'utf8');
|
|
15
|
+
assert(JSON.stringify(presented).length<bytes.length);assert.deepEqual(presented.reviewPackage.specification,original.reviewPackage.specification);
|
|
16
|
+
assert.deepEqual(presented.reviewPackage.checks,original.reviewPackage.checks);assert.deepEqual(presented.priorReview,original.priorReview);
|
|
17
|
+
});
|
|
18
|
+
test('binary, invalid UTF8 and BOM preserve base64 instead of silently changing bytes',()=>{
|
|
19
|
+
for(const bytes of [Buffer.from([0xff,0x80]),Buffer.from([0xef,0xbb,0xbf,0x61]),Buffer.from([0,1,2])]){
|
|
20
|
+
const original={reviewPackage:{packageDigest:'a'.repeat(64),materials:[file('binary',bytes)]},priorReview:null,examinedPaths:['binary']};
|
|
21
|
+
assert.deepEqual(expandReviewData(compactReviewData(original)),original);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
test('wrong SHA, byte size or noncanonical base64 cannot become review presentation',()=>{
|
|
25
|
+
const entry=file('file',Buffer.from('evidence'));
|
|
26
|
+
for(const bad of [{...entry,sha256:'a'.repeat(64)},{...entry,size:500},{...entry,contentBase64:entry.contentBase64+'!'}])
|
|
27
|
+
assert.throws(()=>compactReviewData({reviewPackage:{packageDigest:'b'.repeat(64),changes:[bad]},priorReview:null,examinedPaths:['file']}),/review_presentation_invalid/);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
test('presentation refuses reserved reference keys rather than overwriting evidence',()=>{
|
|
31
|
+
const data={reviewPackage:{packageDigest:'a'.repeat(64),materials:[file('file',Buffer.from('evidence'))]},priorReview:null,examinedPaths:['file']};
|
|
32
|
+
for(const bad of [{...data,contents:{evidence:'original'}},{...data,presentation:{evidence:'original'}},
|
|
33
|
+
{...data,reviewPackage:{...data.reviewPackage,materials:[{...data.reviewPackage.materials[0],contentRef:'original'}]}}])
|
|
34
|
+
assert.throws(()=>compactReviewData(bad),/review_presentation_invalid/);
|
|
35
|
+
});
|