mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-06 17:23:28 +08:00
feat: support disabling bundled mcp servers
This commit is contained in:
62
tests/lib/mcp-config.test.js
Normal file
62
tests/lib/mcp-config.test.js
Normal file
@@ -0,0 +1,62 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const { filterMcpConfig, parseDisabledMcpServers } = require('../../scripts/lib/mcp-config');
|
||||
|
||||
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 mcp-config.js ===\n');
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
||||
if (test('parseDisabledMcpServers dedupes and trims values', () => {
|
||||
assert.deepStrictEqual(
|
||||
parseDisabledMcpServers(' github,exa ,github,,playwright '),
|
||||
['github', 'exa', 'playwright']
|
||||
);
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('filterMcpConfig removes disabled servers and preserves others', () => {
|
||||
const result = filterMcpConfig({
|
||||
mcpServers: {
|
||||
github: { command: 'npx' },
|
||||
exa: { url: 'https://mcp.exa.ai/mcp' },
|
||||
memory: { command: 'npx' },
|
||||
},
|
||||
_comments: { usage: 'demo' },
|
||||
}, ['github', 'memory']);
|
||||
|
||||
assert.deepStrictEqual(result.removed, ['github', 'memory']);
|
||||
assert.deepStrictEqual(Object.keys(result.config.mcpServers), ['exa']);
|
||||
assert.deepStrictEqual(result.config._comments, { usage: 'demo' });
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('filterMcpConfig leaves config unchanged when no disabled servers are provided', () => {
|
||||
const result = filterMcpConfig({
|
||||
mcpServers: {
|
||||
github: { command: 'npx' },
|
||||
},
|
||||
}, []);
|
||||
|
||||
assert.deepStrictEqual(result.removed, []);
|
||||
assert.deepStrictEqual(Object.keys(result.config.mcpServers), ['github']);
|
||||
})) passed++; else failed++;
|
||||
|
||||
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
}
|
||||
|
||||
runTests();
|
||||
@@ -7,6 +7,7 @@ const fs = require('fs');
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { execFileSync } = require('child_process');
|
||||
const { applyInstallPlan } = require('../../scripts/lib/install/apply');
|
||||
|
||||
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'install-apply.js');
|
||||
|
||||
@@ -440,6 +441,80 @@ function runTests() {
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('filters copied mcp config files when ECC_DISABLED_MCPS is set', () => {
|
||||
const tempDir = createTempDir('install-apply-mcp-');
|
||||
const sourcePath = path.join(tempDir, '.mcp.json');
|
||||
const destinationPath = path.join(tempDir, 'installed', '.mcp.json');
|
||||
const installStatePath = path.join(tempDir, 'installed', 'ecc-install-state.json');
|
||||
const previousValue = process.env.ECC_DISABLED_MCPS;
|
||||
|
||||
try {
|
||||
fs.mkdirSync(path.dirname(sourcePath), { recursive: true });
|
||||
fs.writeFileSync(sourcePath, JSON.stringify({
|
||||
mcpServers: {
|
||||
github: { command: 'npx' },
|
||||
exa: { url: 'https://mcp.exa.ai/mcp' },
|
||||
memory: { command: 'npx' },
|
||||
},
|
||||
}, null, 2));
|
||||
|
||||
process.env.ECC_DISABLED_MCPS = 'github,memory';
|
||||
|
||||
applyInstallPlan({
|
||||
targetRoot: path.join(tempDir, 'installed'),
|
||||
installStatePath,
|
||||
statePreview: {
|
||||
schemaVersion: 'ecc.install.v1',
|
||||
installedAt: new Date().toISOString(),
|
||||
target: {
|
||||
id: 'test-install',
|
||||
kind: 'project',
|
||||
root: path.join(tempDir, 'installed'),
|
||||
installStatePath,
|
||||
},
|
||||
request: {
|
||||
profile: null,
|
||||
modules: ['test-mcp'],
|
||||
includeComponents: [],
|
||||
excludeComponents: [],
|
||||
legacyLanguages: [],
|
||||
legacyMode: false,
|
||||
},
|
||||
resolution: {
|
||||
selectedModules: ['test-mcp'],
|
||||
skippedModules: [],
|
||||
},
|
||||
source: {
|
||||
repoVersion: null,
|
||||
repoCommit: null,
|
||||
manifestVersion: 1,
|
||||
},
|
||||
operations: [],
|
||||
},
|
||||
operations: [{
|
||||
kind: 'copy-file',
|
||||
moduleId: 'test-mcp',
|
||||
sourcePath,
|
||||
sourceRelativePath: '.mcp.json',
|
||||
destinationPath,
|
||||
strategy: 'preserve-relative-path',
|
||||
ownership: 'managed',
|
||||
scaffoldOnly: false,
|
||||
}],
|
||||
});
|
||||
|
||||
const installed = readJson(destinationPath);
|
||||
assert.deepStrictEqual(Object.keys(installed.mcpServers), ['exa']);
|
||||
} finally {
|
||||
if (previousValue === undefined) {
|
||||
delete process.env.ECC_DISABLED_MCPS;
|
||||
} else {
|
||||
process.env.ECC_DISABLED_MCPS = previousValue;
|
||||
}
|
||||
cleanup(tempDir);
|
||||
}
|
||||
})) passed++; else failed++;
|
||||
|
||||
if (test('reinstall does not duplicate managed hook entries', () => {
|
||||
const homeDir = createTempDir('install-apply-home-');
|
||||
const projectDir = createTempDir('install-apply-project-');
|
||||
|
||||
Reference in New Issue
Block a user