test-live-composition.mjs•6.07 kB
#!/usr/bin/env node
/**
* EuConquisto Composer MCP Test - Real Composition Creation
*
* This script tests the complete composition creation workflow:
* 1. Launch MCP server
* 2. Execute complete-composition-workflow tool
* 3. Create "Composição Teste MCP" with browser automation
* 4. Verify composition creation and URL capture
*/
import { spawn } from 'child_process';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
console.log("🚀 EuConquisto Composer MCP Live Test");
console.log("=".repeat(70));
console.log("Test: Create 'Composição Teste MCP' via real browser automation");
console.log("Target: https://composer.euconquisto.com");
console.log("Expected: Chromium launch → Auth → Create → Configure → Save");
console.log("=".repeat(70));
// Test configuration
const testPayload = {
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "complete-composition-workflow",
"arguments": {
"title": "Composição Teste MCP",
"description": "Composição de teste criada via automação MCP para verificação de funcionalidade",
"author": "Sistema MCP Browser Automation",
"navigate": true
}
}
};
console.log("📋 Test Configuration:");
console.log(JSON.stringify(testPayload, null, 2));
console.log("\n🎬 Starting browser automation test...");
// Launch MCP server
const serverProcess = spawn('node', ['dist/index.js'], {
cwd: __dirname,
stdio: ['pipe', 'pipe', 'pipe']
});
let output = '';
let errorOutput = '';
let testResult = null;
let browserLaunched = false;
let compositionCreated = false;
// Monitor server output
serverProcess.stdout.on('data', (data) => {
const text = data.toString();
output += text;
// Look for JSON-RPC response
if (text.includes('"jsonrpc"') && text.includes('"result"')) {
try {
const lines = text.split('\n');
for (const line of lines) {
if (line.trim() && line.includes('"jsonrpc"')) {
testResult = JSON.parse(line);
console.log("\n✅ Received JSON-RPC Response!");
break;
}
}
} catch (e) {
console.log("📋 Raw response received:", text);
}
}
});
// Monitor server logs
serverProcess.stderr.on('data', (data) => {
const text = data.toString();
errorOutput += text;
// Check for browser automation indicators
if (text.includes('Browser automation initialized')) {
browserLaunched = true;
console.log("🌐 Browser automation initialized!");
}
if (text.includes('Successfully navigated to Composer')) {
console.log("🔐 Successfully authenticated with Composer!");
}
if (text.includes('New composition created successfully')) {
compositionCreated = true;
console.log("🆕 New composition created!");
}
if (text.includes('Composition saved successfully')) {
console.log("💾 Composition saved successfully!");
}
if (text.includes('Complete composition workflow finished successfully')) {
console.log("🎉 Complete workflow finished!");
}
// Show real-time progress
if (text.includes('🚀') || text.includes('📝') || text.includes('⚙️') || text.includes('💾') || text.includes('✅')) {
console.log(`📢 ${text.trim()}`);
}
});
// Send test command
const testInput = JSON.stringify(testPayload) + '\n';
console.log("📨 Sending test command to MCP server...");
serverProcess.stdin.write(testInput);
serverProcess.stdin.end();
// Set timeout for test completion
const timeout = setTimeout(() => {
console.log("\n⏰ Test timeout reached (60 seconds), terminating...");
serverProcess.kill('SIGTERM');
}, 60000);
// Handle test completion
serverProcess.on('close', (code) => {
clearTimeout(timeout);
console.log("\n" + "=".repeat(70));
console.log("🏁 TEST COMPLETION REPORT");
console.log("=".repeat(70));
console.log(`Exit Code: ${code}`);
console.log(`Browser Launched: ${browserLaunched ? '✅ Yes' : '❌ No'}`);
console.log(`Composition Created: ${compositionCreated ? '✅ Yes' : '❌ No'}`);
console.log(`Test Result Received: ${testResult ? '✅ Yes' : '❌ No'}`);
if (testResult) {
console.log("\n📋 Final Test Result:");
console.log(JSON.stringify(testResult, null, 2));
// Parse the result content
try {
const content = testResult.result?.content?.[0]?.text;
if (content) {
const resultData = JSON.parse(content);
console.log("\n🎯 Composition Creation Results:");
console.log(`Success: ${resultData.success ? '✅' : '❌'}`);
console.log(`Message: ${resultData.message}`);
if (resultData.compositionURL) {
console.log(`Composition URL: ${resultData.compositionURL}`);
}
if (resultData.workflow) {
console.log("Workflow Steps:");
Object.entries(resultData.workflow).forEach(([step, status]) => {
console.log(` ${step}: ${status}`);
});
}
}
} catch (e) {
console.log("Could not parse result content");
}
}
if (errorOutput) {
console.log("\n📢 Server Logs (Last 1000 chars):");
console.log(errorOutput.slice(-1000));
}
console.log("=".repeat(70));
// Final assessment
const testPassed = testResult && browserLaunched && compositionCreated;
console.log(`\n🎯 FINAL ASSESSMENT: ${testPassed ? '✅ TEST PASSED' : '❌ TEST FAILED'}`);
if (testPassed) {
console.log("🎉 Successfully created 'Composição Teste MCP' via browser automation!");
} else {
console.log("❌ Test did not complete successfully. Check logs above for details.");
}
});
// Handle process errors
serverProcess.on('error', (error) => {
clearTimeout(timeout);
console.error('❌ Server process error:', error);
});
console.log("\n⏳ Test in progress... Please wait for browser automation to complete.");
console.log("💡 A Chromium browser window should open automatically.");