mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-02-06 05:23:08 +00:00
Implemented comprehensive node version upgrade functionality with intelligent migration and breaking change detection. Key Features: - Smart version upgrades (typeversion-upgrade fix type) - Version migration guidance (version-migration fix type) - Auto-migration for Execute Workflow v1.0→v1.1 (adds inputFieldMapping) - Auto-migration for Webhook v2.0→v2.1 (generates webhookId) - Breaking changes registry with extensible patterns - AI-friendly post-update validation guidance - Confidence-based application (HIGH/MEDIUM/LOW) Architecture: - NodeVersionService: Version discovery and comparison - BreakingChangeDetector: Registry + dynamic schema comparison - NodeMigrationService: Smart property migrations - PostUpdateValidator: Step-by-step migration instructions - Enhanced database schema: node_versions, version_property_changes tables Services Created: - src/services/breaking-changes-registry.ts - src/services/breaking-change-detector.ts - src/services/node-version-service.ts - src/services/node-migration-service.ts - src/services/post-update-validator.ts Database Enhanced: - src/database/schema.sql (new version tracking tables) - src/database/node-repository.ts (15+ version query methods) Autofixer Integration: - src/services/workflow-auto-fixer.ts (async, new fix types) - src/mcp/handlers-n8n-manager.ts (await generateFixes) - src/mcp/tools-n8n-manager.ts (schema with new fix types) Documentation: - src/mcp/tool-docs/workflow_management/n8n-autofix-workflow.ts - CHANGELOG.md (comprehensive feature documentation) Testing: - Fixed all test scripts to await async generateFixes() - Added test workflow for Execute Workflow v1.0 upgrade testing Bug Fixes: - Fixed MCP tool schema enum to include new fix types - Fixed confidence type mapping (lowercase → uppercase) Conceived by Romuald Członkowski - www.aiadvisors.pl/en
149 lines
4.6 KiB
JavaScript
149 lines
4.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Test script for webhook path autofixer functionality
|
|
*/
|
|
|
|
import { NodeRepository } from '../database/node-repository';
|
|
import { createDatabaseAdapter } from '../database/database-adapter';
|
|
import { WorkflowAutoFixer } from '../services/workflow-auto-fixer';
|
|
import { WorkflowValidator } from '../services/workflow-validator';
|
|
import { EnhancedConfigValidator } from '../services/enhanced-config-validator';
|
|
import { Workflow } from '../types/n8n-api';
|
|
import { Logger } from '../utils/logger';
|
|
import { join } from 'path';
|
|
|
|
const logger = new Logger({ prefix: '[TestWebhookAutofix]' });
|
|
|
|
// Test workflow with webhook missing path
|
|
const testWorkflow: Workflow = {
|
|
id: 'test_webhook_fix',
|
|
name: 'Test Webhook Autofix',
|
|
active: false,
|
|
nodes: [
|
|
{
|
|
id: '1',
|
|
name: 'Webhook',
|
|
type: 'n8n-nodes-base.webhook',
|
|
typeVersion: 2.1,
|
|
position: [250, 300],
|
|
parameters: {}, // Empty parameters - missing path
|
|
},
|
|
{
|
|
id: '2',
|
|
name: 'HTTP Request',
|
|
type: 'n8n-nodes-base.httpRequest',
|
|
typeVersion: 4.2,
|
|
position: [450, 300],
|
|
parameters: {
|
|
url: 'https://api.example.com/data',
|
|
method: 'GET'
|
|
}
|
|
}
|
|
],
|
|
connections: {
|
|
'Webhook': {
|
|
main: [[{
|
|
node: 'HTTP Request',
|
|
type: 'main',
|
|
index: 0
|
|
}]]
|
|
}
|
|
},
|
|
settings: {
|
|
executionOrder: 'v1'
|
|
},
|
|
staticData: undefined
|
|
};
|
|
|
|
async function testWebhookAutofix() {
|
|
logger.info('Testing webhook path autofixer...');
|
|
|
|
// Initialize database and repository
|
|
const dbPath = join(process.cwd(), 'data', 'nodes.db');
|
|
const adapter = await createDatabaseAdapter(dbPath);
|
|
const repository = new NodeRepository(adapter);
|
|
|
|
// Create validators
|
|
const validator = new WorkflowValidator(repository, EnhancedConfigValidator);
|
|
const autoFixer = new WorkflowAutoFixer(repository);
|
|
|
|
// Step 1: Validate workflow to identify issues
|
|
logger.info('Step 1: Validating workflow to identify issues...');
|
|
const validationResult = await validator.validateWorkflow(testWorkflow);
|
|
|
|
console.log('\n📋 Validation Summary:');
|
|
console.log(`- Valid: ${validationResult.valid}`);
|
|
console.log(`- Errors: ${validationResult.errors.length}`);
|
|
console.log(`- Warnings: ${validationResult.warnings.length}`);
|
|
|
|
if (validationResult.errors.length > 0) {
|
|
console.log('\n❌ Errors found:');
|
|
validationResult.errors.forEach(error => {
|
|
console.log(` - [${error.nodeName || error.nodeId}] ${error.message}`);
|
|
});
|
|
}
|
|
|
|
// Step 2: Generate fixes (preview mode)
|
|
logger.info('\nStep 2: Generating fixes in preview mode...');
|
|
|
|
const fixResult = await autoFixer.generateFixes(
|
|
testWorkflow,
|
|
validationResult,
|
|
[], // No expression format issues to pass
|
|
{
|
|
applyFixes: false, // Preview mode
|
|
fixTypes: ['webhook-missing-path'] // Only test webhook fixes
|
|
}
|
|
);
|
|
|
|
console.log('\n🔧 Fix Results:');
|
|
console.log(`- Summary: ${fixResult.summary}`);
|
|
console.log(`- Total fixes: ${fixResult.stats.total}`);
|
|
console.log(`- Webhook path fixes: ${fixResult.stats.byType['webhook-missing-path']}`);
|
|
|
|
if (fixResult.fixes.length > 0) {
|
|
console.log('\n📝 Detailed Fixes:');
|
|
fixResult.fixes.forEach(fix => {
|
|
console.log(` - Node: ${fix.node}`);
|
|
console.log(` Field: ${fix.field}`);
|
|
console.log(` Type: ${fix.type}`);
|
|
console.log(` Before: ${fix.before || 'undefined'}`);
|
|
console.log(` After: ${fix.after}`);
|
|
console.log(` Confidence: ${fix.confidence}`);
|
|
console.log(` Description: ${fix.description}`);
|
|
});
|
|
}
|
|
|
|
if (fixResult.operations.length > 0) {
|
|
console.log('\n🔄 Operations to Apply:');
|
|
fixResult.operations.forEach(op => {
|
|
if (op.type === 'updateNode') {
|
|
console.log(` - Update Node: ${op.nodeId}`);
|
|
console.log(` Updates: ${JSON.stringify(op.updates, null, 2)}`);
|
|
}
|
|
});
|
|
}
|
|
|
|
// Step 3: Verify UUID format
|
|
if (fixResult.fixes.length > 0) {
|
|
const webhookFix = fixResult.fixes.find(f => f.type === 'webhook-missing-path');
|
|
if (webhookFix) {
|
|
const uuid = webhookFix.after as string;
|
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
const isValidUUID = uuidRegex.test(uuid);
|
|
|
|
console.log('\n✅ UUID Validation:');
|
|
console.log(` - Generated UUID: ${uuid}`);
|
|
console.log(` - Valid format: ${isValidUUID ? 'Yes' : 'No'}`);
|
|
}
|
|
}
|
|
|
|
logger.info('\n✨ Webhook autofix test completed successfully!');
|
|
}
|
|
|
|
// Run test
|
|
testWebhookAutofix().catch(error => {
|
|
logger.error('Test failed:', error);
|
|
process.exit(1);
|
|
}); |