feat: add install catalog and project config autodetection

This commit is contained in:
Affaan Mustafa
2026-03-24 03:53:45 -07:00
parent cc60bf6b65
commit b4296c7095
11 changed files with 496 additions and 6 deletions

View File

@@ -0,0 +1,104 @@
/**
* Tests for scripts/catalog.js
*/
const assert = require('assert');
const path = require('path');
const { execFileSync } = require('child_process');
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'catalog.js');
function run(args = []) {
try {
const stdout = execFileSync('node', [SCRIPT, ...args], {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 10000,
});
return { code: 0, stdout, stderr: '' };
} catch (error) {
return {
code: error.status || 1,
stdout: error.stdout || '',
stderr: error.stderr || '',
};
}
}
function test(name, fn) {
try {
fn();
console.log(` \u2713 ${name}`);
return true;
} catch (error) {
console.log(` \u2717 ${name}`);
console.log(` Error: ${error.message}`);
return false;
}
}
function runTests() {
console.log('\n=== Testing catalog.js ===\n');
let passed = 0;
let failed = 0;
if (test('shows help with no arguments', () => {
const result = run();
assert.strictEqual(result.code, 0);
assert.ok(result.stdout.includes('Discover ECC install components and profiles'));
})) passed++; else failed++;
if (test('shows help with an explicit help flag', () => {
const result = run(['--help']);
assert.strictEqual(result.code, 0);
assert.ok(result.stdout.includes('Usage:'));
assert.ok(result.stdout.includes('node scripts/catalog.js show <component-id>'));
})) passed++; else failed++;
if (test('lists install profiles', () => {
const result = run(['profiles']);
assert.strictEqual(result.code, 0);
assert.ok(result.stdout.includes('Install profiles'));
assert.ok(result.stdout.includes('core'));
})) passed++; else failed++;
if (test('filters components by family and emits JSON', () => {
const result = run(['components', '--family', 'language', '--json']);
assert.strictEqual(result.code, 0, result.stderr);
const parsed = JSON.parse(result.stdout);
assert.ok(Array.isArray(parsed.components));
assert.ok(parsed.components.length > 0);
assert.ok(parsed.components.every(component => component.family === 'language'));
assert.ok(parsed.components.some(component => component.id === 'lang:typescript'));
assert.ok(parsed.components.every(component => component.id !== 'framework:nextjs'));
})) passed++; else failed++;
if (test('shows a resolved component payload', () => {
const result = run(['show', 'framework:nextjs', '--json']);
assert.strictEqual(result.code, 0, result.stderr);
const parsed = JSON.parse(result.stdout);
assert.strictEqual(parsed.id, 'framework:nextjs');
assert.strictEqual(parsed.family, 'framework');
assert.deepStrictEqual(parsed.moduleIds, ['framework-language']);
assert.ok(Array.isArray(parsed.modules));
assert.strictEqual(parsed.modules[0].id, 'framework-language');
})) passed++; else failed++;
if (test('fails on unknown subcommands', () => {
const result = run(['bogus']);
assert.strictEqual(result.code, 1);
assert.ok(result.stderr.includes('Unknown catalog command'));
})) passed++; else failed++;
if (test('fails on unknown component ids', () => {
const result = run(['show', 'framework:not-real']);
assert.strictEqual(result.code, 1);
assert.ok(result.stderr.includes('Unknown install component'));
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}
runTests();

View File

@@ -65,6 +65,7 @@ function main() {
const result = runCli(['--help']);
assert.strictEqual(result.status, 0);
assert.match(result.stdout, /ECC selective-install CLI/);
assert.match(result.stdout, /catalog/);
assert.match(result.stdout, /list-installed/);
assert.match(result.stdout, /doctor/);
}],
@@ -93,6 +94,13 @@ function main() {
assert.ok(Array.isArray(payload.profiles));
assert.ok(payload.profiles.length > 0);
}],
['delegates catalog command', () => {
const result = runCli(['catalog', 'show', 'framework:nextjs', '--json']);
assert.strictEqual(result.status, 0, result.stderr);
const payload = parseJson(result.stdout);
assert.strictEqual(payload.id, 'framework:nextjs');
assert.deepStrictEqual(payload.moduleIds, ['framework-language']);
}],
['delegates lifecycle commands', () => {
const homeDir = createTempDir('ecc-cli-home-');
const projectRoot = createTempDir('ecc-cli-project-');
@@ -127,6 +135,11 @@ function main() {
assert.strictEqual(result.status, 0, result.stderr);
assert.match(result.stdout, /Usage: node scripts\/repair\.js/);
}],
['supports help for the catalog subcommand', () => {
const result = runCli(['help', 'catalog']);
assert.strictEqual(result.status, 0, result.stderr);
assert.match(result.stdout, /node scripts\/catalog\.js show <component-id>/);
}],
['fails on unknown commands instead of treating them as installs', () => {
const result = runCli(['bogus']);
assert.strictEqual(result.status, 1);

View File

@@ -358,6 +358,67 @@ function runTests() {
}
})) passed++; else failed++;
if (test('auto-detects ecc-install.json from the project root', () => {
const homeDir = createTempDir('install-apply-home-');
const projectDir = createTempDir('install-apply-project-');
const configPath = path.join(projectDir, 'ecc-install.json');
try {
fs.writeFileSync(configPath, JSON.stringify({
version: 1,
target: 'claude',
profile: 'developer',
include: ['capability:security'],
exclude: ['capability:orchestration'],
}, null, 2));
const result = run([], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
assert.ok(fs.existsSync(path.join(homeDir, '.claude', 'skills', 'security-review', 'SKILL.md')));
assert.ok(!fs.existsSync(path.join(homeDir, '.claude', 'skills', 'dmux-workflows', 'SKILL.md')));
const state = readJson(path.join(homeDir, '.claude', 'ecc', 'install-state.json'));
assert.strictEqual(state.request.profile, 'developer');
assert.deepStrictEqual(state.request.includeComponents, ['capability:security']);
assert.deepStrictEqual(state.request.excludeComponents, ['capability:orchestration']);
assert.ok(state.resolution.selectedModules.includes('security'));
assert.ok(!state.resolution.selectedModules.includes('orchestration'));
} finally {
cleanup(homeDir);
cleanup(projectDir);
}
})) passed++; else failed++;
if (test('preserves legacy language installs when a project config is present', () => {
const homeDir = createTempDir('install-apply-home-');
const projectDir = createTempDir('install-apply-project-');
const configPath = path.join(projectDir, 'ecc-install.json');
try {
fs.writeFileSync(configPath, JSON.stringify({
version: 1,
target: 'claude',
profile: 'developer',
include: ['capability:security'],
}, null, 2));
const result = run(['typescript'], { cwd: projectDir, homeDir });
assert.strictEqual(result.code, 0, result.stderr);
const state = readJson(path.join(homeDir, '.claude', 'ecc', 'install-state.json'));
assert.strictEqual(state.request.legacyMode, true);
assert.deepStrictEqual(state.request.legacyLanguages, ['typescript']);
assert.strictEqual(state.request.profile, null);
assert.deepStrictEqual(state.request.includeComponents, []);
assert.ok(state.resolution.selectedModules.includes('framework-language'));
assert.ok(!state.resolution.selectedModules.includes('security'));
} finally {
cleanup(homeDir);
cleanup(projectDir);
}
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}

View File

@@ -8,11 +8,12 @@ const { execFileSync } = require('child_process');
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'install-plan.js');
function run(args = []) {
function run(args = [], options = {}) {
try {
const stdout = execFileSync('node', [SCRIPT, ...args], {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
cwd: options.cwd,
timeout: 10000,
});
return { code: 0, stdout, stderr: '' };
@@ -135,6 +136,31 @@ function runTests() {
}
})) passed++; else failed++;
if (test('auto-detects planning intent from project ecc-install.json', () => {
const configDir = path.join(__dirname, '..', 'fixtures', 'tmp-install-plan-autodetect');
const configPath = path.join(configDir, 'ecc-install.json');
try {
require('fs').mkdirSync(configDir, { recursive: true });
require('fs').writeFileSync(configPath, JSON.stringify({
version: 1,
target: 'cursor',
profile: 'core',
include: ['capability:security'],
}, null, 2));
const result = run(['--json'], { cwd: configDir });
assert.strictEqual(result.code, 0, result.stderr);
const parsed = JSON.parse(result.stdout);
assert.strictEqual(parsed.target, 'cursor');
assert.strictEqual(parsed.profileId, 'core');
assert.deepStrictEqual(parsed.includedComponentIds, ['capability:security']);
assert.ok(parsed.selectedModuleIds.includes('security'));
} finally {
require('fs').rmSync(configDir, { recursive: true, force: true });
}
})) passed++; else failed++;
if (test('fails on unknown arguments', () => {
const result = run(['--unknown-flag']);
assert.strictEqual(result.code, 1);