@aibyzero/cm-workflow 0.10.6 → 0.12.0
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 +2 -0
- package/CHANGELOG.md +58 -0
- package/README.md +17 -3
- package/VERSION +1 -1
- package/compat/claude-commands/cm-security.md +3 -0
- package/docs/architecture.md +62 -1
- package/docs/installation.md +14 -2
- package/docs/user-guide.md +31 -3
- package/install-codex.sh +1 -1
- package/package.json +3 -1
- package/runtime/js/cm-ai/host-tool-bridge.mjs +1 -1
- package/runtime/js/cm-ai/review-result.schema.json +0 -1
- package/runtime/js/cm-fix/execution.mjs +2 -2
- package/runtime/js/cm-fix/repair.mjs +6 -2
- package/runtime/js/cm-security/scan.mjs +263 -0
- package/runtime/js/cm-test/branch-impact.mjs +151 -0
- package/runtime/js/cm-test/host.mjs +28 -8
- package/runtime/js/cm-test/unit-coverage.mjs +206 -0
- package/runtime/project-context.md +6 -0
- package/scripts/cm-check-runtime.sh +23 -1
- package/scripts/cm-check-update.mjs +200 -0
- package/scripts/cm-check-update.test.mjs +186 -0
- package/scripts/cm-fix-repair-owner.test.mjs +24 -6
- package/scripts/cm-fix-repair.test.mjs +9 -2
- package/scripts/cm-fix-review-baseline.test.mjs +19 -1
- package/scripts/cm-release-smoke.sh +3 -0
- package/scripts/cm-review-schema.test.mjs +15 -0
- package/scripts/cm-security.mjs +32 -0
- package/scripts/cm-security.test.mjs +203 -0
- package/scripts/cm-test-branch-impact.test.mjs +186 -0
- package/scripts/cm-test-entry.mjs +6 -1
- package/scripts/cm-test-host.mjs +2 -2
- package/scripts/cm-unit-coverage.mjs +16 -0
- package/scripts/cm-unit-coverage.test.mjs +126 -0
- package/scripts/validate-public-repo.py +2 -1
- package/skills/cm-ai/references/N3-execute-task.md +12 -1
- package/skills/cm-ai/references/N8-finish.md +5 -4
- package/skills/cm-check/SKILL.md +44 -7
- package/skills/cm-check/references/js-host.md +4 -1
- package/skills/cm-doc-syncer/SKILL.md +22 -3
- package/skills/cm-fix/SKILL.md +11 -2
- package/skills/cm-fix/references/js-host.md +4 -0
- package/skills/cm-prd/SKILL.md +3 -3
- package/skills/cm-prd/references/context-scope.md +17 -13
- package/skills/cm-security/SKILL.md +55 -0
- package/skills/cm-security/references/scan-contract.md +43 -0
- package/skills/cm-test/SKILL.md +24 -7
- package/skills/cm-test/references/branch-impact.md +70 -0
- package/skills/cm-test/references/js-host.md +14 -2
- package/skills/cm-test/references/unit-coverage.md +97 -0
- package/skills/codebase-context/SKILL.md +11 -24
- package/skills/codebase-context/references/writeback.md +66 -0
|
@@ -0,0 +1,186 @@
|
|
|
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 {compareVersions, updateInstallation} from './cm-check-update.mjs';
|
|
7
|
+
|
|
8
|
+
function fixture(t, runtime = 'codex') {
|
|
9
|
+
const home = fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(), 'cm-update-test-')));
|
|
10
|
+
t.after(() => fs.rmSync(home, {recursive: true, force: true}));
|
|
11
|
+
const root = path.join(home, runtime === 'codex' ? 'plugins/cm-workflow' : '.claude');
|
|
12
|
+
const write = (file, value) => { fs.mkdirSync(path.dirname(file), {recursive: true}); fs.writeFileSync(file, value); };
|
|
13
|
+
const versionFile = runtime === 'codex' ? 'VERSION' : 'templates/cm-VERSION';
|
|
14
|
+
write(path.join(root, versionFile), '0.10.6\n');
|
|
15
|
+
write(path.join(root, 'skills/cm-check/SKILL.md'), '# cm-check');
|
|
16
|
+
write(path.join(root, 'scripts/cm-check-host.mjs'), '// host');
|
|
17
|
+
if (runtime === 'codex') write(path.join(home, '.agents/plugins/marketplace.json'), '{"name":"personal"}');
|
|
18
|
+
const calls = [];
|
|
19
|
+
const state = {home, root, write, calls, latest: '0.11.0', installerStatus: 0, writeVersion: true};
|
|
20
|
+
state.options = {env: {HOME: home, npm_config_registry: 'https://invalid.example'}, platform: 'darwin',
|
|
21
|
+
query: async () => state.latest,
|
|
22
|
+
run: (command, args, options) => {
|
|
23
|
+
calls.push({command, args, options});
|
|
24
|
+
if (command === 'npm') {
|
|
25
|
+
const source = path.join(options.cwd, 'node_modules/@aibyzero/cm-workflow');
|
|
26
|
+
write(path.join(source, 'package.json'), JSON.stringify({name: '@aibyzero/cm-workflow', version: state.latest}));
|
|
27
|
+
write(path.join(source, 'VERSION'), state.latest);
|
|
28
|
+
write(path.join(source, runtime === 'codex' ? 'install-codex.sh' : 'install.sh'), '# installer');
|
|
29
|
+
return {status: 0};
|
|
30
|
+
}
|
|
31
|
+
if (state.writeVersion) write(path.join(root, versionFile), state.latest);
|
|
32
|
+
return {status: state.installerStatus};
|
|
33
|
+
}};
|
|
34
|
+
state.input = {skillDir: path.join(root, 'skills/cm-check'), runtime};
|
|
35
|
+
return state;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test('stable version ordering is numeric and rejects tags, prereleases and shell input', () => {
|
|
39
|
+
assert.equal(compareVersions('0.11.0', '0.9.99'), 1);
|
|
40
|
+
assert.equal(compareVersions('1.0.0', '1.0.0'), 0);
|
|
41
|
+
assert.equal(compareVersions('0.11.0', '1.0.0'), -1);
|
|
42
|
+
for (const version of ['latest', '01.2.3', '1.0.0-beta', '1.0.0;touch nope', '1.0.0\n']) {
|
|
43
|
+
assert.throws(() => compareVersions(version, '1.0.0'));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
for (const runtime of ['codex', 'claude']) test(`${runtime}: default upgrade uses pinned npm and existing installer, then verifies disk`, async t => {
|
|
48
|
+
const f = fixture(t, runtime);
|
|
49
|
+
const report = await updateInstallation(f.input, f.options);
|
|
50
|
+
assert.equal(report.status, 'updated');
|
|
51
|
+
assert.equal(report.installed, '0.11.0');
|
|
52
|
+
assert.equal(report.workflowRoot, f.root);
|
|
53
|
+
assert.equal(f.calls.length, 2);
|
|
54
|
+
assert.ok(f.calls[0].args.includes('@aibyzero/cm-workflow@0.11.0'));
|
|
55
|
+
assert.ok(f.calls[0].args.includes('--ignore-scripts'));
|
|
56
|
+
assert.ok(f.calls[0].args.includes('--@aibyzero:registry=https://registry.npmjs.org/'));
|
|
57
|
+
assert.equal(f.calls[0].options.env.npm_config_registry, undefined);
|
|
58
|
+
assert.equal(f.calls[1].args[1], '--yes');
|
|
59
|
+
assert.equal(f.calls[1].options.stdio[0], 'ignore');
|
|
60
|
+
assert.equal(fs.existsSync(f.calls[0].options.cwd), false);
|
|
61
|
+
assert.equal(fs.existsSync(`${f.root}.cm-check-update.lock`), false);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
for (const latest of ['0.10.6', '0.9.0']) test(`no download when latest ${latest} is equal or older`, async t => {
|
|
65
|
+
const f = fixture(t); f.latest = latest;
|
|
66
|
+
assert.equal((await updateInstallation(f.input, f.options)).status, latest === '0.10.6' ? 'current' : 'ahead');
|
|
67
|
+
assert.equal(f.calls.length, 0);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('offline or invalid registry metadata permits local checks but never claims current', async t => {
|
|
71
|
+
const f = fixture(t);
|
|
72
|
+
for (const query of [async () => {throw new Error('network');}, async () => '1.0.0-beta']) {
|
|
73
|
+
const report = await updateInstallation(f.input, {...f.options, query});
|
|
74
|
+
assert.equal(report.status, 'offline');
|
|
75
|
+
assert.equal(report.workflowRoot, f.root);
|
|
76
|
+
}
|
|
77
|
+
assert.equal(f.calls.length, 0);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
test('source checkout and unknown package managers are never overwritten', async t => {
|
|
81
|
+
const f = fixture(t);
|
|
82
|
+
f.write(path.join(f.root, '.git'), 'gitdir: elsewhere');
|
|
83
|
+
assert.equal((await updateInstallation(f.input, f.options)).status, 'unmanaged');
|
|
84
|
+
fs.unlinkSync(path.join(f.root, '.git'));
|
|
85
|
+
const moved = path.join(f.home, 'source'); fs.renameSync(f.root, moved);
|
|
86
|
+
assert.equal((await updateInstallation({...f.input, skillDir: path.join(moved, 'skills/cm-check')}, f.options)).status, 'unmanaged');
|
|
87
|
+
assert.equal(f.calls.length, 0);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('old active cache checks newer managed installation without reinstalling or downgrading', async t => {
|
|
91
|
+
const f = fixture(t);
|
|
92
|
+
const cache = path.join(f.home, '.codex/plugins/cache/personal/cm-workflow/old');
|
|
93
|
+
f.write(path.join(cache, 'VERSION'), '0.10.6');
|
|
94
|
+
f.write(path.join(cache, 'skills/cm-check/SKILL.md'), '# old');
|
|
95
|
+
f.write(path.join(f.root, 'VERSION'), '0.11.0');
|
|
96
|
+
const input = {...f.input, skillDir: path.join(cache, 'skills/cm-check')};
|
|
97
|
+
const report = await updateInstallation(input, f.options);
|
|
98
|
+
assert.equal(report.status, 'current'); assert.equal(report.workflowRoot, f.root);
|
|
99
|
+
assert.equal(report.installed, '0.11.0'); assert.equal(f.calls.length, 0);
|
|
100
|
+
f.write(path.join(cache, 'VERSION'), '0.12.0');
|
|
101
|
+
assert.equal((await updateInstallation(input, f.options)).status, 'blocked');
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
test('another upgrade completed before locking cannot be downgraded by stale registry data', async t => {
|
|
105
|
+
const f = fixture(t), mkdir = fs.mkdirSync;
|
|
106
|
+
t.mock.method(fs, 'mkdirSync', (dir, options) => {
|
|
107
|
+
if (dir === `${f.root}.cm-check-update.lock`) fs.writeFileSync(path.join(f.root, 'VERSION'), '0.12.0');
|
|
108
|
+
return mkdir(dir, options);
|
|
109
|
+
});
|
|
110
|
+
const report = await updateInstallation(f.input, f.options);
|
|
111
|
+
assert.equal(report.status, 'ahead'); assert.equal(report.installed, '0.12.0');
|
|
112
|
+
assert.equal(f.calls.length, 0);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('an external installer changing the version during download blocks the stale installer', async t => {
|
|
116
|
+
const f = fixture(t), run = f.options.run;
|
|
117
|
+
f.options.run = (...args) => {
|
|
118
|
+
const result = run(...args);
|
|
119
|
+
f.write(path.join(f.root, 'VERSION'), '0.12.0');
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
assert.equal((await updateInstallation(f.input, f.options)).status, 'blocked');
|
|
123
|
+
assert.equal(f.calls.length, 1);
|
|
124
|
+
assert.equal(fs.readFileSync(path.join(f.root, 'VERSION'), 'utf8'), '0.12.0');
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
for (const [runtime, key] of [['codex', 'HOME'], ['codex', 'CODEX_HOME'], ['claude', 'CLAUDE_HOME']]) {
|
|
128
|
+
test(`relative ${key} cannot redirect installation when cwd changes`, async t => {
|
|
129
|
+
const f = fixture(t, runtime); f.options.env[key] = '.';
|
|
130
|
+
const report = await updateInstallation(f.input, f.options);
|
|
131
|
+
assert.equal(report.status, 'blocked'); assert.match(report.reason, /absolute path/);
|
|
132
|
+
assert.equal(f.calls.length, 0);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
test('redirected marketplace ancestor is rejected even before its JSON file exists', async t => {
|
|
137
|
+
const f = fixture(t), outside = path.join(f.home, 'redirected');
|
|
138
|
+
fs.rmSync(path.join(f.home, '.agents'), {recursive: true}); fs.mkdirSync(outside);
|
|
139
|
+
fs.symlinkSync(outside, path.join(f.home, '.agents'), 'dir');
|
|
140
|
+
const report = await updateInstallation(f.input, f.options);
|
|
141
|
+
assert.equal(report.status, 'blocked'); assert.equal(f.calls.length, 0);
|
|
142
|
+
assert.deepEqual(fs.readdirSync(outside), []);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test('marketplace symlink introduced during download cannot redirect the installer', async t => {
|
|
146
|
+
const f = fixture(t), run = f.options.run;
|
|
147
|
+
f.options.run = (...args) => {
|
|
148
|
+
const result = run(...args), file = path.join(f.home, '.agents/plugins/marketplace.json');
|
|
149
|
+
fs.unlinkSync(file); fs.symlinkSync(path.join(f.home, 'not-created.json'), file);
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
assert.equal((await updateInstallation(f.input, f.options)).status, 'blocked');
|
|
153
|
+
assert.equal(f.calls.length, 1);
|
|
154
|
+
assert.equal(fs.existsSync(path.join(f.home, 'not-created.json')), false);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
for (const mode of ['failure', 'false-success', 'download-failure', 'wrong-package', 'lock', 'unsupported', 'symlink']) {
|
|
158
|
+
test(`upgrade ${mode} is blocked without claiming success`, async t => {
|
|
159
|
+
const f = fixture(t);
|
|
160
|
+
if (mode === 'failure') { f.installerStatus = 1; f.writeVersion = false; }
|
|
161
|
+
if (mode === 'false-success') f.writeVersion = false;
|
|
162
|
+
if (mode === 'download-failure') f.options.run = () => ({status: 1});
|
|
163
|
+
if (mode === 'wrong-package') {
|
|
164
|
+
const run = f.options.run;
|
|
165
|
+
f.options.run = (...args) => {
|
|
166
|
+
const result = run(...args);
|
|
167
|
+
f.write(path.join(args[2].cwd, 'node_modules/@aibyzero/cm-workflow/package.json'), '{"name":"other","version":"0.11.0"}');
|
|
168
|
+
return result;
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (mode === 'lock') fs.mkdirSync(`${f.root}.cm-check-update.lock`);
|
|
172
|
+
if (mode === 'unsupported') f.options.platform = 'win32';
|
|
173
|
+
if (mode === 'symlink') {
|
|
174
|
+
const destination = path.join(f.home, 'redirected'); fs.renameSync(f.root, destination);
|
|
175
|
+
fs.symlinkSync(destination, f.root, 'dir');
|
|
176
|
+
// A canonical root outside the managed path is explicitly unmanaged.
|
|
177
|
+
assert.equal((await updateInstallation(f.input, f.options)).status, 'unmanaged');
|
|
178
|
+
assert.equal(f.calls.length, 0); return;
|
|
179
|
+
}
|
|
180
|
+
const report = await updateInstallation(f.input, f.options);
|
|
181
|
+
assert.equal(report.status, 'blocked');
|
|
182
|
+
assert.equal(fs.readFileSync(path.join(f.root, 'VERSION'), 'utf8').trim(), '0.10.6');
|
|
183
|
+
if (mode === 'lock') assert.equal(fs.existsSync(`${f.root}.cm-check-update.lock`), true);
|
|
184
|
+
else assert.equal(fs.existsSync(`${f.root}.cm-check-update.lock`), false);
|
|
185
|
+
});
|
|
186
|
+
}
|
|
@@ -19,7 +19,7 @@ import {startFixRun} from '../runtime/js/cm-fix/start.mjs';
|
|
|
19
19
|
import {readProjectInstructionContext} from '../runtime/js/cm-ai/cm-ai-context-refresh.mjs';
|
|
20
20
|
|
|
21
21
|
test('durable repair registers before write, preserves cause approval history and never redispatches lost results',async()=>{
|
|
22
|
-
for(const mode of ['revision','revision-approved','revision-lost','normal','lost','cause','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
22
|
+
for(const mode of ['revision','revision-approved','revision-lost','normal','lost','cause','cause-map','unfixed','regression-intent','lesson','retrospective-lost','lesson-intent','lesson-pending','handoff-forged','handoff-legacy','handoff-large']){
|
|
23
23
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-repair-owner-')));
|
|
24
24
|
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
25
25
|
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
@@ -27,12 +27,14 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
27
27
|
fs.writeFileSync(path.join(cwd,'existing.mjs'),"import {value} from './value.mjs';if(typeof value!=='number')process.exit(1)");
|
|
28
28
|
if(mode==='revision-approved')fs.writeFileSync(path.join(cwd,'.cm-workflow.json'),JSON.stringify({version:1,policies:{delivery:'diff'}}));
|
|
29
29
|
const identity={repositoryId:'fixture',runId:'repair-owner',taskId:'T-FIX-owner',attempt:1};
|
|
30
|
+
const mapPaths=mode==='cause-map'?['docs/codebase-context/00-index.md','docs/codebase-context/07-business-logic.md','docs/codebase-context/09-changelog.md']:[];
|
|
31
|
+
const mapPlan='Create partial value map; cover value.mjs only; other modules unverified.';
|
|
30
32
|
const reviewer={reviewerId:'cause-reviewer',adapterId:'codex-review-adapter',provider:'codex',requestedModel:'synthetic',contextId:'review-context',excludedThreadIds:mode==='cause'?Array.from({length:32},(_,index)=>`excluded-${index}`):[]};
|
|
31
33
|
const options={identity,specsRoot,create:true,configuration:{hostContextId:'fixture-host',defect:'Wrong constant',
|
|
32
34
|
reproduction:{cwd,command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
33
35
|
redTest:{cwd,testFiles:['red.mjs'],command:[process.execPath,'red.mjs'],expectedFailure:{exitCode:1,outputIncludes:'BUG'},timeoutMs:2000},
|
|
34
36
|
baseline:{cwd,testFiles:['existing.mjs'],commands:[{id:mode==='normal'?'x'.repeat(128):'existing',command:[process.execPath,'existing.mjs']}],timeoutMs:2000},
|
|
35
|
-
repair:{scope:['value.mjs'],requirements:['value.mjs']},...(mode
|
|
37
|
+
repair:{scope:['value.mjs',...mapPaths],requirements:['value.mjs']},...(mode.startsWith('cause')||mode.startsWith('revision')?{causeReview:reviewer}:{})}};
|
|
36
38
|
if(mode==='handoff-large')options.configuration.redTest.command=[process.execPath,'-e',
|
|
37
39
|
"import('./value.mjs').then(({value})=>{if(value!==2){process.stderr.write('BUG'+'x'.repeat(128*1024-3));process.exitCode=1;}});//"+'x'.repeat(31*1024)];
|
|
38
40
|
if(mode==='revision-approved')options.configuration.walkthrough={timeoutMs:2000,flows:[{id:'value-flow',modules:['one'],steps:['Read corrected value'],expected:['Value is 2'],kind:'commands',command:[process.execPath,'red.mjs']}]};
|
|
@@ -52,7 +54,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
52
54
|
const bridge=createHostToolBridge();let writes=0,retrospectives=0;
|
|
53
55
|
bridge.attach(row=>{
|
|
54
56
|
if(row.type!=='host_request')return;
|
|
55
|
-
let result={status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['one'],crossLayer:mode
|
|
57
|
+
let result={status:'diagnosed',rootCause:'Wrong constant',affectedPaths:['value.mjs'],affectedModules:['one'],crossLayer:mode.startsWith('cause'),plan:mode==='cause-map'?mapPlan:'Correct constant'};
|
|
56
58
|
if(mode==='revision-approved')result.investigation={discardedAlternatives:[],boundaryAnalysis:null};
|
|
57
59
|
if(row.kind==='fix_retrospective'){
|
|
58
60
|
const state=JSON.parse(fs.readFileSync(path.join(specsRoot,'.reviews','.execution',identity.runId,'state.json')));
|
|
@@ -67,6 +69,13 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
67
69
|
assert.equal(state.records.at(-1).id,row.payload.identity.attempt===2?'fix-revision-repair-intent':'fix-repair-intent');writes++;
|
|
68
70
|
if(row.payload.identity.attempt===2){assert.equal(row.payload.priorReview.review.findings[0].id,'F1');assert.deepEqual(row.payload.scope,['value.mjs']);}
|
|
69
71
|
fs.writeFileSync(path.join(cwd,'value.mjs'),row.payload.identity.attempt===2?'export const value=2; // reviewed boundary repair':mode==='unfixed'?'export const value=3;':'export const value=2;');
|
|
72
|
+
if(mode==='cause-map'){
|
|
73
|
+
assert.deepEqual(row.payload.diagnosis.affectedPaths,['value.mjs']);
|
|
74
|
+
for(const file of mapPaths){
|
|
75
|
+
assert(row.payload.scope.includes(file));fs.mkdirSync(path.dirname(path.join(cwd,file)),{recursive:true});
|
|
76
|
+
fs.writeFileSync(path.join(cwd,file),'# Partial map\nvalue.mjs exports value=2; only this module verified.\n');
|
|
77
|
+
}
|
|
78
|
+
}
|
|
70
79
|
if(mode==='revision-lost'&&row.payload.identity.attempt===2){bridge.close();return;}
|
|
71
80
|
if(mode==='lost'){bridge.close();return;}result={outcome:'repaired'};
|
|
72
81
|
}
|
|
@@ -79,7 +88,8 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
79
88
|
try{
|
|
80
89
|
if(mode==='revision-approved')startFixRun({specsRoot,identity,configuration:options.configuration});
|
|
81
90
|
await owner.advance({authorized:true});
|
|
82
|
-
if(mode
|
|
91
|
+
if(mode.startsWith('cause')){
|
|
92
|
+
if(mode==='cause-map')assert(!fs.existsSync(path.join(cwd,'docs')));
|
|
83
93
|
const pkg=owner.causeReviewPackage();await authority.hostDecisionProvider.decide({identity,packageDigest:pkg.packageDigest},new AbortController().signal);
|
|
84
94
|
await owner.reviewCause();
|
|
85
95
|
}
|
|
@@ -101,7 +111,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
101
111
|
owner=openFixExecution({...options,create:false},{bridge,prepare,causeReview,assertReviewReady(){}});
|
|
102
112
|
result=owner.status();assert.equal(result.stage,'regression_required');
|
|
103
113
|
}
|
|
104
|
-
assert.equal(result.completionEligible,false);if(mode
|
|
114
|
+
assert.equal(result.completionEligible,false);if(mode.startsWith('cause'))assert.equal(result.causeReview.review.verdict,'approved');
|
|
105
115
|
owner.close();
|
|
106
116
|
assert.throws(()=>openFixExecution({...options,create:false,configuration:{...options.configuration,
|
|
107
117
|
repair:{...options.configuration.repair,scope:['AGENTS.md']}}}),{code:'protected_scope'});
|
|
@@ -125,7 +135,7 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
125
135
|
if(mode==='unfixed')assert.throws(()=>owner.implementationPackage(),{code:'fix_not_ready_for_handoff'});
|
|
126
136
|
else{
|
|
127
137
|
const pkg=owner.implementationPackage();
|
|
128
|
-
assert.deepEqual(pkg.changes.map(change=>change.path),['value.mjs']);
|
|
138
|
+
assert.deepEqual(pkg.changes.map(change=>change.path),[...mapPaths,'value.mjs']);
|
|
129
139
|
assert.deepEqual(pkg.checks.map(check=>check.id),['red-test','baseline.1']);
|
|
130
140
|
assert.deepEqual(pkg.checks[1].command,options.configuration.baseline.commands[0].command);
|
|
131
141
|
owner.close();owner=openFixExecution({...options,create:false},{bridge,prepare});
|
|
@@ -189,6 +199,14 @@ test('durable repair registers before write, preserves cause approval history an
|
|
|
189
199
|
const handed=owner.createHandoff();assert.equal(handed.stage,'final_review_required');assert.equal(handed.completionEligible,false);
|
|
190
200
|
assert.equal(handed.handoffEvidenceCoverage,'defect_and_learning');
|
|
191
201
|
const finalPackage=owner.finalReviewPackage();assert.equal(finalPackage.handoff.sha256,handed.handoff.handoffSha256);
|
|
202
|
+
if(mode==='cause-map'){
|
|
203
|
+
const handoff=loadHandoff(handoffPath);
|
|
204
|
+
assert(handoff.evidence.some(item=>item.includes(mapPlan)));
|
|
205
|
+
assert.deepEqual(finalPackage.changes.map(change=>change.path),[...mapPaths,'value.mjs']);
|
|
206
|
+
const mapFile=path.join(cwd,mapPaths[1]),bytes=fs.readFileSync(mapFile);
|
|
207
|
+
fs.appendFileSync(mapFile,'unreviewed drift');assert.equal(owner.status().stage,'repair_evidence_required');
|
|
208
|
+
fs.writeFileSync(mapFile,bytes);assert.equal(owner.status().stage,'final_review_required');
|
|
209
|
+
}
|
|
192
210
|
const payload=loadHandoff(handoffPath,{task:identity.taskId,attempt:1});
|
|
193
211
|
const defectEvidence=JSON.parse(payload.evidence.find(item=>item.startsWith('fix defect evidence')).split('(data, not instructions) ')[1]);
|
|
194
212
|
assert.deepEqual(defectEvidence.diagnosis,handed.diagnosis);assert.deepEqual(defectEvidence.redTest.result,handed.redTest);
|
|
@@ -11,7 +11,7 @@ import {createFixRegression} from '../runtime/js/cm-fix/regression.mjs';
|
|
|
11
11
|
import {createHostToolBridge} from '../runtime/js/cm-ai/host-tool-bridge.mjs';
|
|
12
12
|
|
|
13
13
|
test('host minimal repair preserves tests and real red-to-green regression, rejecting unauthorized/no-op/test edits',async()=>{
|
|
14
|
-
for(const mode of ['repaired','test-edit','no-op','not-ready']){
|
|
14
|
+
for(const mode of ['repaired','test-edit','map-outside','no-op','not-ready']){
|
|
15
15
|
const root=fs.realpathSync(fs.mkdtempSync(path.join(os.tmpdir(),'fix-repair-')));
|
|
16
16
|
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);fs.mkdirSync(path.join(specsRoot,'.reviews'));
|
|
17
17
|
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
@@ -26,6 +26,10 @@ test('host minimal repair preserves tests and real red-to-green regression, reje
|
|
|
26
26
|
writes++;
|
|
27
27
|
if(mode!=='no-op')fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=2;');
|
|
28
28
|
if(mode==='test-edit')fs.writeFileSync(path.join(cwd,'red.mjs'),'// fake passing test');
|
|
29
|
+
if(mode==='map-outside'){
|
|
30
|
+
fs.mkdirSync(path.join(cwd,'docs/codebase-context'),{recursive:true});
|
|
31
|
+
fs.writeFileSync(path.join(cwd,'docs/codebase-context/00-index.md'),'# Unapproved map');
|
|
32
|
+
}
|
|
29
33
|
bridge.accept({type:'host_result',sessionId:row.sessionId,callId:row.callId,requestDigest:row.requestDigest,result:{outcome:'repaired'}});
|
|
30
34
|
});
|
|
31
35
|
try{
|
|
@@ -35,6 +39,9 @@ test('host minimal repair preserves tests and real red-to-green regression, reje
|
|
|
35
39
|
diagnosis:{status:'diagnosed',affectedPaths:['value.mjs','red.mjs'],rootCause:'Wrong constant'},redTest,baseline,redEvidence,beforeBaseline};
|
|
36
40
|
const capabilities={bridge,assertReviewReady(){ready++;if(mode==='not-ready')throw Object.assign(new Error('not ready'),{code:'review_unavailable'});}};
|
|
37
41
|
assert.throws(()=>prepareFixRepair({...options,scope:['red.mjs']},capabilities),{code:'repair_test_scope_forbidden'});
|
|
42
|
+
for(const file of ['docs/unrelated.md','docs/codebase-context/extra.md','docs/codebase-context/.scan-meta.json']){
|
|
43
|
+
assert.throws(()=>prepareFixRepair({...options,scope:['value.mjs',file]},capabilities),{code:'repair_scope_mismatch'});
|
|
44
|
+
}
|
|
38
45
|
const repair=prepareFixRepair(options,capabilities);
|
|
39
46
|
const control={authorized:true,signal,register(value){registered++;assert.equal(value.baselineDigest,repair.baseline.baselineDigest);}};
|
|
40
47
|
await assert.rejects(repair.execute({...control,authorized:false}),{code:'repair_authorization_required'});
|
|
@@ -44,7 +51,7 @@ test('host minimal repair preserves tests and real red-to-green regression, reje
|
|
|
44
51
|
assert.equal(regression.status,'passed');assert.equal(regression.completionEligible,false);
|
|
45
52
|
await assert.rejects(repair.execute(control),{code:'repair_already_attempted'});
|
|
46
53
|
}else{
|
|
47
|
-
await assert.rejects(repair.execute(control),{code:mode==='test-edit'?'red_test_files_changed':mode==='no-op'?'repair_no_changes':'review_unavailable'});
|
|
54
|
+
await assert.rejects(repair.execute(control),{code:mode==='test-edit'?'red_test_files_changed':mode==='map-outside'?'out_of_scope':mode==='no-op'?'repair_no_changes':'review_unavailable'});
|
|
48
55
|
if(mode==='not-ready'){assert.equal(writes,0);assert.equal(registered,0);}
|
|
49
56
|
}
|
|
50
57
|
}finally{bridge.close();fs.rmSync(root,{recursive:true,force:true});}
|
|
@@ -15,6 +15,9 @@ test('one original review baseline includes authored test and business repair, r
|
|
|
15
15
|
const cwd=path.join(root,'code'),specsRoot=path.join(root,'specs');fs.mkdirSync(cwd);fs.mkdirSync(specsRoot);
|
|
16
16
|
fs.writeFileSync(path.join(cwd,'value.mjs'),'export const value=1;');
|
|
17
17
|
fs.writeFileSync(path.join(cwd,'requirements.md'),'fixture');
|
|
18
|
+
fs.mkdirSync(path.join(cwd,'docs'));
|
|
19
|
+
const mapPath='docs/map.md',mapBody='# Map\nA caller reads the numeric value; the relationship is unchanged.\n';
|
|
20
|
+
fs.writeFileSync(path.join(cwd,mapPath),mapBody);
|
|
18
21
|
const identity={repositoryId:'fixture',runId:'combined-review',taskId:'T-FIX-demo',attempt:1};
|
|
19
22
|
const options={codeProject:cwd,specsRoot,identity,testFiles:['red.mjs'],requirements:['requirements.md'],defect:'Constant bug',diagnosis:{},reproduction:{}};
|
|
20
23
|
try{
|
|
@@ -22,7 +25,7 @@ test('one original review baseline includes authored test and business repair, r
|
|
|
22
25
|
fs.writeFileSync(path.join(cwd,'red.mjs'),"import {value} from './value.mjs';if(value!==2)process.exit(1)");return {outcome:'authored'};
|
|
23
26
|
}}});
|
|
24
27
|
const authorResult=await author.execute({authorized:true,signal:new AbortController().signal,register(){}});
|
|
25
|
-
const capture=()=>captureReviewBaseline({root:cwd,specsRoot,identity,scope:['value.mjs'],requirements:['value.mjs']});
|
|
28
|
+
const capture=()=>captureReviewBaseline({root:cwd,specsRoot,identity,scope:['value.mjs'],requirements:['value.mjs',mapPath]});
|
|
26
29
|
const repairBaseline=capture();
|
|
27
30
|
const input={authorBaseline:author.baseline,authorResult,repairBaseline};
|
|
28
31
|
const combined=composeFixReviewBaseline(input);
|
|
@@ -32,6 +35,13 @@ test('one original review baseline includes authored test and business repair, r
|
|
|
32
35
|
const checks=await createHostCheck({cwd,commands:[{id:'target',command:[process.execPath,'red.mjs']}]})({identity},{signal:new AbortController().signal});
|
|
33
36
|
assert.equal(checks[0].outcome,'passed');
|
|
34
37
|
const pkg=createReviewPackage({root:cwd,baseline:combined,checks});
|
|
38
|
+
const map=pkg.requirements.find(file=>file.path===mapPath);
|
|
39
|
+
assert(map,'unchanged referenced maps must reach independent Review as read-only material');
|
|
40
|
+
assert.equal(Buffer.from(map.contentBase64,'base64').toString(),mapBody);
|
|
41
|
+
assert(!pkg.scope.includes(mapPath));assert(!pkg.changes.some(change=>change.path===mapPath));
|
|
42
|
+
fs.writeFileSync(path.join(cwd,mapPath),'unapproved rewrite');
|
|
43
|
+
assert.throws(()=>createReviewPackage({root:cwd,baseline:combined,checks}),{code:'out_of_scope'});
|
|
44
|
+
fs.writeFileSync(path.join(cwd,mapPath),mapBody);
|
|
35
45
|
assert.deepEqual(pkg.changes.map(change=>change.path),['red.mjs','value.mjs']);
|
|
36
46
|
assert.equal(pkg.changes[0].before,null);assert.equal(pkg.changes[1].before.contentBase64,Buffer.from('export const value=1;').toString('base64'));
|
|
37
47
|
assert.throws(()=>composeFixReviewBaseline({...input,repairBaseline:capture()}),{code:'fix_review_interstage_drift'});
|
|
@@ -43,6 +53,7 @@ test('one original review baseline includes authored test and business repair, r
|
|
|
43
53
|
const continued=continueFixReviewBaseline(expanded,nextIdentity);
|
|
44
54
|
assert.deepEqual(continued.files,expanded.files);assert.deepEqual(continued.scope,expanded.scope);
|
|
45
55
|
const cumulative=createReviewPackage({root:cwd,baseline:continued,checks});
|
|
56
|
+
assert.equal(Buffer.from(cumulative.requirements.find(file=>file.path===mapPath).contentBase64,'base64').toString(),mapBody);
|
|
46
57
|
assert.equal(cumulative.identity.attempt,2);
|
|
47
58
|
assert.deepEqual(cumulative.changes.map(change=>change.path),['AGENTS.md','red.mjs','value.mjs']);
|
|
48
59
|
assert.equal(cumulative.changes[0].before,null);assert.equal(cumulative.changes[1].before,null);
|
|
@@ -50,5 +61,12 @@ test('one original review baseline includes authored test and business repair, r
|
|
|
50
61
|
assert.match(Buffer.from(cumulative.changes[2].after.contentBase64,'base64').toString(),/second repair/);
|
|
51
62
|
assert.throws(()=>continueFixReviewBaseline(expanded,{...nextIdentity,runId:'different'}),{code:'fix_review_baseline_mismatch'});
|
|
52
63
|
assert.throws(()=>continueFixReviewBaseline(continued,nextIdentity),{code:'fix_review_baseline_mismatch'});
|
|
64
|
+
// An approved map deletion needs its before image, not an after-file requirement.
|
|
65
|
+
const deletionBaseline=captureReviewBaseline({root:cwd,specsRoot,identity,scope:[mapPath],requirements:['value.mjs']});
|
|
66
|
+
fs.unlinkSync(path.join(cwd,mapPath));
|
|
67
|
+
const deleted=createReviewPackage({root:cwd,baseline:deletionBaseline,checks});
|
|
68
|
+
assert.equal(deleted.changes.length,1);assert.equal(deleted.changes[0].after,null);
|
|
69
|
+
assert.equal(Buffer.from(deleted.changes[0].before.contentBase64,'base64').toString(),mapBody);
|
|
70
|
+
assert(!deleted.requirements.some(file=>file.path===mapPath));
|
|
53
71
|
}finally{fs.rmSync(root,{recursive:true,force:true});}
|
|
54
72
|
});
|
|
@@ -69,5 +69,8 @@ HOME="$TEMP_HOME" CODEX_HOME="$TEMP_CODEX_HOME" \
|
|
|
69
69
|
"$TEMP_HOME/plugins/cm-workflow/scripts/cm-check-runtime.sh" \
|
|
70
70
|
--project "$TEMP_HOME/plugins/cm-workflow"
|
|
71
71
|
|
|
72
|
+
[ -f "$TEMP_HOME/plugins/cm-workflow/CHANGELOG.md" ] || fail "installed changelog missing"
|
|
73
|
+
cmp -s "$ROOT/CHANGELOG.md" "$TEMP_HOME/plugins/cm-workflow/CHANGELOG.md" || fail "installed changelog differs from source"
|
|
74
|
+
|
|
72
75
|
VERSION="$(tr -d '[:space:]' < "$ROOT/VERSION")"
|
|
73
76
|
echo "cm release surface smoke: PASSED (v${VERSION})"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import test from 'node:test';
|
|
2
|
+
import assert from 'node:assert/strict';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import {reviewResult} from '../runtime/js/cm-ai/review-runner.mjs';
|
|
5
|
+
|
|
6
|
+
test('provider schema avoids unsupported uniqueness keyword; local gate rejects duplicate or missing paths',()=>{
|
|
7
|
+
const schema=JSON.parse(fs.readFileSync(new URL('../runtime/js/cm-ai/review-result.schema.json',import.meta.url),'utf8'));
|
|
8
|
+
assert.equal(Object.hasOwn(schema.properties.examinedPaths,'uniqueItems'),false);
|
|
9
|
+
const pkg={packageDigest:'a'.repeat(64),changes:[{path:'code.mjs'}],requirements:[{path:'requirements.md'}]};
|
|
10
|
+
const result={verdict:'approved',packageDigest:pkg.packageDigest,examinedPaths:['code.mjs','requirements.md'],findings:[],summary:'Reviewed both files'};
|
|
11
|
+
assert.equal(reviewResult(result,pkg).verdict,'approved');
|
|
12
|
+
for(const examinedPaths of [['code.mjs','code.mjs','requirements.md'],['code.mjs'],['code.mjs','requirements.md','other.mjs']]){
|
|
13
|
+
assert.throws(()=>reviewResult({...result,examinedPaths},pkg),/missing_material/);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import {fileURLToPath} from 'node:url';
|
|
5
|
+
import {scan} from '../runtime/js/cm-security/scan.mjs';
|
|
6
|
+
|
|
7
|
+
export function main(argv){
|
|
8
|
+
let project=process.cwd();const options={};const seen=new Set();
|
|
9
|
+
for(let i=0;i<argv.length;i++){
|
|
10
|
+
const key=argv[i];
|
|
11
|
+
if(key==='--help')return {help:'cm-security.mjs [--project PATH] [--all] [--inventory] [--semgrep-rules EXTERNAL_FILE] [--osv-db EXTERNAL_CACHE_DIR]'};
|
|
12
|
+
if(seen.has(key))throw new Error('duplicate_argument');seen.add(key);
|
|
13
|
+
if(key==='--all')options.all=true;
|
|
14
|
+
else if(key==='--inventory')options.inventoryOnly=true;
|
|
15
|
+
else if(['--project','--semgrep-rules','--osv-db'].includes(key)){
|
|
16
|
+
const value=argv[++i];if(!value||value.startsWith('--'))throw new Error('argument_value_required');
|
|
17
|
+
if(key==='--project')project=value;
|
|
18
|
+
else options[key==='--semgrep-rules'?'semgrepRules':'osvDb']=value;
|
|
19
|
+
}else throw new Error('unknown_argument');
|
|
20
|
+
}
|
|
21
|
+
return scan(fs.realpathSync(project),options);
|
|
22
|
+
}
|
|
23
|
+
if(process.argv[1]&&path.resolve(process.argv[1])===fileURLToPath(import.meta.url)){
|
|
24
|
+
try{
|
|
25
|
+
const result=main(process.argv.slice(2));console.log(JSON.stringify(result,null,2));
|
|
26
|
+
process.exitCode=result.help?0:result.result==='BLOCKED'?2:result.findings?.length?1:result.result==='NO_CHANGES'?0:3;
|
|
27
|
+
}catch(error){
|
|
28
|
+
// Do not echo paths, input values, source snippets or scanner stderr from exceptions.
|
|
29
|
+
console.log(JSON.stringify({result:'BLOCKED',coverage:'PARTIAL',reason:/^[a-z0-9_]+$/.test(error.message)?error.message:'scan_failed'}));
|
|
30
|
+
process.exitCode=2;
|
|
31
|
+
}
|
|
32
|
+
}
|