embark-mcp
Version:
MCP server proxy for Embark code search
152 lines (126 loc) • 5.34 kB
JavaScript
/**
* Test script for multi-repository filtering with environment variables
*
* This script tests the INCLUDE_REPOSITORY_URLS and EXCLUDE_REPOSITORY_URLS
* environment variable functionality.
*/
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
// Colors for terminal output
const colors = {
reset: '\x1b[0m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
gray: '\x1b[90m',
cyan: '\x1b[36m',
};
function log(message, color = colors.reset) {
console.log(`${color}${message}${colors.reset}`);
}
function logSuccess(message) {
log(`✓ ${message}`, colors.green);
}
function logInfo(message) {
log(`ℹ ${message}`, colors.blue);
}
function logSection(message) {
log(`\n${'='.repeat(60)}`, colors.cyan);
log(message, colors.cyan);
log('='.repeat(60), colors.cyan);
}
/**
* Main test runner
*/
async function runTests() {
log('='.repeat(60), colors.blue);
log('Multi-Repository Filter Testing', colors.blue);
log('='.repeat(60), colors.blue);
logInfo('This test demonstrates the multi-repository search functionality');
logInfo('with INCLUDE_REPOSITORY_URLS and EXCLUDE_REPOSITORY_URLS environment variables\n');
// Test scenarios
const scenarios = [
{
name: 'No filters (search all discovered repositories)',
env: {},
description: 'When no filter env vars are set, all discovered repositories are searched',
},
{
name: 'Include filter (search only specified repositories)',
env: {
INCLUDE_REPOSITORY_URLS: 'https://github.com/owner/repo1.git,https://github.com/owner/repo2.git'
},
description: 'Only repositories in INCLUDE_REPOSITORY_URLS are searched',
},
{
name: 'Exclude filter (skip specified repositories)',
env: {
EXCLUDE_REPOSITORY_URLS: 'https://github.com/owner/large-repo.git'
},
description: 'All repositories except those in EXCLUDE_REPOSITORY_URLS are searched',
},
{
name: 'Both filters (include then exclude)',
env: {
INCLUDE_REPOSITORY_URLS: 'https://github.com/owner/repo1.git,https://github.com/owner/repo2.git,https://github.com/owner/repo3.git',
EXCLUDE_REPOSITORY_URLS: 'https://github.com/owner/repo3.git'
},
description: 'Include list is applied first, then exclude list removes specific repos',
},
];
scenarios.forEach((scenario, index) => {
logSection(`Scenario ${index + 1}: ${scenario.name}`);
logInfo(scenario.description);
if (Object.keys(scenario.env).length === 0) {
log('\n No environment variables set', colors.gray);
} else {
log('\n Environment variables:', colors.gray);
Object.entries(scenario.env).forEach(([key, value]) => {
log(` ${key}=${value}`, colors.gray);
});
}
log('\n To test this scenario, run:', colors.yellow);
const envVars = Object.entries(scenario.env)
.map(([key, value]) => `${key}="${value}"`)
.join(' ');
const command = envVars
? ` ${envVars} node dist/index.js`
: ` node dist/index.js`;
log(command, colors.yellow);
});
logSection('Implementation Details');
logInfo('How it works:');
log(' 1. Server discovers all Git repositories from workspace roots', colors.gray);
log(' 2. Before each search, repositories are filtered based on env vars:', colors.gray);
log(' - If INCLUDE_REPOSITORY_URLS is set: only those repos are kept', colors.gray);
log(' - If EXCLUDE_REPOSITORY_URLS is set: those repos are removed', colors.gray);
log(' 3. If multiple repos remain after filtering: multi-repo search', colors.gray);
log(' 4. If only one repo remains: single-repo search (cleaner output)', colors.gray);
log(' 5. If no repos remain: error message', colors.gray);
logSection('Configuration Format');
log(' INCLUDE_REPOSITORY_URLS: Comma-separated list of Git URLs to include', colors.gray);
log(' Example: export INCLUDE_REPOSITORY_URLS="https://github.com/owner/repo1.git,https://github.com/owner/repo2.git"', colors.gray);
log('\n EXCLUDE_REPOSITORY_URLS: Comma-separated list of Git URLs to exclude', colors.gray);
log(' Example: export EXCLUDE_REPOSITORY_URLS="https://github.com/owner/large-repo.git"', colors.gray);
logSection('Backward Compatibility');
log(' ✓ Existing single-repository setups continue to work', colors.green);
log(' ✓ REPOSITORY_GIT_REMOTE_URL env var still supported as fallback', colors.green);
log(' ✓ No breaking changes to existing tool parameters', colors.green);
logSection('Summary');
logSuccess('Multi-repository search is now implemented!');
log(' • By default: searches all discovered repositories', colors.gray);
log(' • With INCLUDE_REPOSITORY_URLS: searches only specified repos', colors.gray);
log(' • With EXCLUDE_REPOSITORY_URLS: searches all except specified repos', colors.gray);
log(' • Results are aggregated with clear repository labels', colors.gray);
log(' • Parallel search execution for better performance', colors.gray);
log('\n');
}
// Run tests
runTests().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});