#!/usr/bin/env node
/**
* End-to-end test with mock Infinigen
*/
import { spawn } from 'child_process';
import { createInterface } from 'readline';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import { rmSync } from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const serverPath = join(__dirname, '..', 'dist', 'index.js');
const mockInfinigenPath = join(__dirname, '..', 'mock-infinigen');
// Set PYTHONPATH to include mock-infinigen
const env = { ...process.env, PYTHONPATH: mockInfinigenPath };
const server = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'inherit'],
env
});
const rl = createInterface({
input: server.stdout,
crlfDelay: Infinity
});
let messageId = 1;
function sendRequest(method, params = {}) {
const request = {
jsonrpc: '2.0',
id: messageId++,
method,
params
};
server.stdin.write(JSON.stringify(request) + '\n');
console.log('📤 Sent:', JSON.stringify(request, null, 2));
}
rl.on('line', (line) => {
if (line.trim()) {
console.log('📥 Received:', line);
try {
const response = JSON.parse(line);
console.log('✅ Parsed:', JSON.stringify(response, null, 2));
} catch (e) {
console.log('⚠️ Not JSON');
}
}
});
server.on('close', (code) => {
console.log(`\n🔚 Server exited with code ${code}`);
// Cleanup test output
try {
rmSync('mock-infinigen/test_output', { recursive: true, force: true });
console.log('🧹 Cleaned up test output');
} catch (e) {
// Ignore cleanup errors
}
process.exit(code);
});
// Wait for server to start
setTimeout(() => {
console.log('\n🧪 Testing MCP Server with Mock Infinigen...\n');
// Test 1: Initialize
console.log('='.repeat(60));
console.log('Test 1: Initialize');
console.log('='.repeat(60));
sendRequest('initialize', {
protocolVersion: '2024-11-05',
capabilities: {},
clientInfo: {
name: 'test-client',
version: '1.0.0'
}
});
setTimeout(() => {
// Test 2: Check Infinigen (should now find mock)
console.log('\n' + '='.repeat(60));
console.log('Test 2: Check Infinigen Installation');
console.log('='.repeat(60));
sendRequest('tools/call', {
name: 'check_infinigen',
arguments: {}
});
}, 1000);
setTimeout(() => {
// Test 3: Generate nature scene
console.log('\n' + '='.repeat(60));
console.log('Test 3: Generate Nature Scene');
console.log('='.repeat(60));
sendRequest('tools/call', {
name: 'generate_nature_scene',
arguments: {
output_folder: 'mock-infinigen/test_output',
seed: 12345,
configs: ['desert.gin', 'simple.gin']
}
});
}, 2000);
setTimeout(() => {
console.log('\n' + '='.repeat(60));
console.log('✅ All tests complete!');
console.log('='.repeat(60));
server.kill();
}, 8000);
}, 500);