Files
mcp/test-ui-tool.js
zeekay 7195df0566 feat: Add award-winning landing page example using unified ui tool
- Created complete landing page with @hanzo/ui components
- Demonstrates ui tool's ability to compose complex UIs
- Includes hero, features, testimonials, pricing, and CTA sections
- Production-ready code with animations and dark theme
- Validates dev agent can use ui tool effectively
- Comprehensive testing suite for all UI tool methods
- Matrix test report showing 80% success rate
2025-09-19 00:08:55 -05:00

148 lines
4.9 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* MATRIX TEST SUITE FOR UNIFIED UI TOOL
* Testing all methods with parallel execution
*/
import { createMCPServer } from './dist/index.js';
const testMethods = [
{ method: 'list_components', args: {} },
{ method: 'get_component', args: { name: 'button' } },
{ method: 'get_source', args: { name: 'button' } },
{ method: 'get_demo', args: { name: 'button' } },
{ method: 'add_component', args: { name: 'button', framework: 'react' } },
{ method: 'list_blocks', args: {} },
{ method: 'list_styles', args: {} },
{ method: 'search', args: { query: 'modal' } },
{ method: 'installation_guide', args: { framework: 'nextjs' } },
{ method: 'compare_frameworks', args: {} },
{ method: 'convert_framework', args: { component: 'button', from: 'react', to: 'vue' } }
];
async function testUITool() {
console.log('šŸ”“šŸ’Š ENTERING THE MATRIX - UI TOOL TEST SUITE\n');
try {
// Create server with default configuration (unifiedUITool is in allTools by default)
const server = await createMCPServer({
name: 'test-hanzo-mcp',
version: '1.0.0'
});
console.log(`āœ… Server created with ${server.tools.length} tools\n`);
// List all tool names to find the UI tool
console.log('Available tools:');
server.tools.forEach(t => {
if (t.name.includes('ui') || t.name.includes('UI')) {
console.log(` - ${t.name} (UI-related)`);
}
});
// Find the UI tool - it might be named differently
const uiTool = server.tools.find(t => t.name === 'ui' || t.name === 'unified_ui' || t.name === 'ui_unified');
if (!uiTool) {
console.error('\nāŒ UI tool not found! Available UI-related tools:');
server.tools.filter(t => t.name.toLowerCase().includes('ui')).forEach(t => {
console.error(` - ${t.name}: ${t.description?.substring(0, 50)}...`);
});
process.exit(1);
}
console.log(`\nāœ… UI tool found: ${uiTool.name}\n`);
console.log('⚔ Executing all methods in parallel...\n');
// Execute all test methods in parallel
const startTime = Date.now();
const results = await Promise.allSettled(
testMethods.map(async (test, index) => {
const start = Date.now();
try {
const result = await uiTool.handler({ method: test.method, ...test.args });
const duration = Date.now() - start;
return {
index,
method: test.method,
success: !result.isError,
duration,
outputLength: result.content?.[0]?.text?.length || 0
};
} catch (error) {
return {
index,
method: test.method,
success: false,
duration: Date.now() - start,
error: error.message
};
}
})
);
const totalDuration = Date.now() - startTime;
// Display results
console.log('šŸŒ€ TEST RESULTS:\n');
console.log('=' .repeat(60));
results.forEach((result, index) => {
if (result.status === 'fulfilled') {
const r = result.value;
const status = r.success ? 'āœ…' : 'āŒ';
console.log(`${status} [${r.index + 1}/${testMethods.length}] ${r.method}`);
console.log(` Duration: ${r.duration}ms`);
if (r.outputLength) {
console.log(` Output: ${r.outputLength} chars`);
}
if (r.error) {
console.log(` Error: ${r.error}`);
}
} else {
console.log(`āŒ [${index + 1}/${testMethods.length}] Failed: ${result.reason}`);
}
});
console.log('=' .repeat(60));
// Statistics
const successCount = results.filter(r =>
r.status === 'fulfilled' && r.value.success
).length;
console.log('\nšŸ“Š STATISTICS:');
console.log(`Total methods tested: ${testMethods.length}`);
console.log(`Successful: ${successCount}`);
console.log(`Failed: ${testMethods.length - successCount}`);
console.log(`Total execution time: ${totalDuration}ms`);
console.log(`Average per method: ${Math.round(totalDuration / testMethods.length)}ms`);
// Test framework switching
console.log('\nšŸ”„ TESTING FRAMEWORK SWITCHING:');
const frameworks = ['hanzo', 'hanzo-native', 'hanzo-vue', 'hanzo-svelte'];
for (const fw of frameworks) {
try {
const result = await uiTool.handler({
method: 'add_component',
name: 'button',
framework: fw === 'hanzo' ? 'react' : fw.replace('hanzo-', '')
});
console.log(`āœ… Framework ${fw}: ${result.isError ? 'FAILED' : 'SUCCESS'}`);
} catch (error) {
console.log(`āŒ Framework ${fw}: ERROR - ${error.message}`);
}
}
console.log('\nšŸ’Š THE MATRIX HAS BEEN TESTED - NEO OUT');
} catch (error) {
console.error('āŒ Fatal error:', error);
process.exit(1);
}
}
// Execute the test
testUITool();