mirror of
https://github.com/czlonkowski/n8n-mcp.git
synced 2026-01-30 22:42:04 +00:00
Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8405497263 | ||
|
|
7a66f71c23 | ||
|
|
9cbbc6bb67 | ||
|
|
fbce712714 | ||
|
|
f13685fcd7 | ||
|
|
89b1ef2354 | ||
|
|
951d5b7e1b | ||
|
|
263753254a | ||
|
|
2896e393d3 | ||
|
|
9fa1c44149 | ||
|
|
e217d022d6 | ||
|
|
ca150287c9 | ||
|
|
5825a85ccc | ||
|
|
fecc584145 | ||
|
|
09bbcd7001 |
70
CHANGELOG.md
70
CHANGELOG.md
@@ -5,6 +5,76 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.14.2] - 2025-09-29
|
||||
|
||||
### Fixed
|
||||
- Validation false positives for Google Drive nodes with 'fileFolder' resource
|
||||
- Added node type normalization to handle both `n8n-nodes-base.` and `nodes-base.` prefixes correctly
|
||||
- Fixed resource validation to properly recognize all valid resource types
|
||||
- Default operations are now properly applied when not specified
|
||||
- Property visibility is now correctly checked with defaults applied
|
||||
- Code node validation incorrectly flagging valid n8n expressions as syntax errors
|
||||
- Removed overly aggressive regex pattern `/\)\s*\)\s*{/` that flagged valid expressions
|
||||
- Valid patterns like `$('NodeName').first().json` are now correctly recognized
|
||||
- Function chaining and method chaining no longer trigger false positives
|
||||
- Enhanced error handling in repository methods based on code review feedback
|
||||
- Added try-catch blocks to `getNodePropertyDefaults` and `getDefaultOperationForResource`
|
||||
- Validates data structures before accessing to prevent crashes with malformed node data
|
||||
- Returns safe defaults on errors to ensure validation continues
|
||||
|
||||
### Added
|
||||
- Comprehensive test coverage for validation fixes in `tests/unit/services/validation-fixes.test.ts`
|
||||
- New repository methods for better default value handling:
|
||||
- `getNodePropertyDefaults()` - retrieves default values for node properties
|
||||
- `getDefaultOperationForResource()` - gets default operation for a specific resource
|
||||
|
||||
### Changed
|
||||
- Enhanced `filterPropertiesByMode` to return both filtered properties and config with defaults applied
|
||||
- Improved node type validation to accept both valid prefix formats
|
||||
|
||||
## [2.14.1] - 2025-09-26
|
||||
|
||||
### Changed
|
||||
- **BREAKING**: Refactored telemetry system with major architectural improvements
|
||||
- Split 636-line TelemetryManager into 7 focused modules (event-tracker, batch-processor, event-validator, rate-limiter, circuit-breaker, workflow-sanitizer, config-manager)
|
||||
- Changed TelemetryManager constructor to private, use `getInstance()` method now
|
||||
- Implemented lazy initialization pattern to avoid early singleton creation
|
||||
|
||||
### Added
|
||||
- Security & Privacy enhancements for telemetry:
|
||||
- Comprehensive input validation with Zod schemas
|
||||
- Enhanced sanitization of sensitive data (URLs, API keys, emails)
|
||||
- Expanded sensitive key detection patterns (25+ patterns)
|
||||
- Row Level Security on Supabase backend
|
||||
- Data deletion contact info (romuald@n8n-mcp.com)
|
||||
- Performance & Reliability improvements:
|
||||
- Sliding window rate limiter (100 events/minute)
|
||||
- Circuit breaker pattern for network failures
|
||||
- Dead letter queue for failed events
|
||||
- Exponential backoff with jitter for retries
|
||||
- Performance monitoring with overhead tracking (<5%)
|
||||
- Memory-safe array limits in rate limiter
|
||||
- Comprehensive test coverage enhancements:
|
||||
- Added 662 lines of new telemetry tests
|
||||
- Enhanced config-manager tests with 17 new edge cases
|
||||
- Enhanced workflow-sanitizer tests with 19 new edge cases
|
||||
- Improved coverage from 63% to 91% for telemetry module
|
||||
- Branch coverage improved from 69% to 87%
|
||||
|
||||
### Fixed
|
||||
- TypeScript lint errors in telemetry test files
|
||||
- Corrected variable name conflicts in integration tests
|
||||
- Fixed process.exit mock implementation in batch-processor tests
|
||||
- Fixed tuple type annotations for workflow node positions
|
||||
- Resolved MockInstance type import issues
|
||||
- Test failures in CI pipeline
|
||||
- Fixed test timeouts caused by improper fake timer usage
|
||||
- Resolved Timer.unref() compatibility issues
|
||||
- Fixed event validator filtering standalone 'key' property
|
||||
- Corrected batch processor circuit breaker behavior
|
||||
- TypeScript error in telemetry test preventing CI build
|
||||
- Added @supabase/supabase-js to Docker builder stage and runtime dependencies
|
||||
|
||||
## [2.14.0] - 2025-09-26
|
||||
|
||||
### Added
|
||||
|
||||
10
README.md
10
README.md
@@ -4,7 +4,7 @@
|
||||
[](https://github.com/czlonkowski/n8n-mcp)
|
||||
[](https://www.npmjs.com/package/n8n-mcp)
|
||||
[](https://codecov.io/gh/czlonkowski/n8n-mcp)
|
||||
[](https://github.com/czlonkowski/n8n-mcp/actions)
|
||||
[](https://github.com/czlonkowski/n8n-mcp/actions)
|
||||
[](https://github.com/n8n-io/n8n)
|
||||
[](https://github.com/czlonkowski/n8n-mcp/pkgs/container/n8n-mcp)
|
||||
[](https://railway.com/deploy/n8n-mcp?referralCode=n8n-mcp)
|
||||
@@ -817,7 +817,7 @@ docker run --rm ghcr.io/czlonkowski/n8n-mcp:latest --version
|
||||
|
||||
## 🧪 Testing
|
||||
|
||||
The project includes a comprehensive test suite with **1,356 tests** ensuring code quality and reliability:
|
||||
The project includes a comprehensive test suite with **2,883 tests** ensuring code quality and reliability:
|
||||
|
||||
```bash
|
||||
# Run all tests
|
||||
@@ -837,9 +837,9 @@ npm run test:bench # Performance benchmarks
|
||||
|
||||
### Test Suite Overview
|
||||
|
||||
- **Total Tests**: 1,356 (100% passing)
|
||||
- **Unit Tests**: 1,107 tests across 44 files
|
||||
- **Integration Tests**: 249 tests across 14 files
|
||||
- **Total Tests**: 2,883 (100% passing)
|
||||
- **Unit Tests**: 2,526 tests across 99 files
|
||||
- **Integration Tests**: 357 tests across 20 files
|
||||
- **Execution Time**: ~2.5 minutes in CI
|
||||
- **Test Framework**: Vitest (for speed and TypeScript support)
|
||||
- **Mocking**: MSW for API mocking, custom mocks for databases
|
||||
|
||||
BIN
data/nodes.db
BIN
data/nodes.db
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "n8n-mcp",
|
||||
"version": "2.14.1",
|
||||
"version": "2.14.2",
|
||||
"description": "Integration between n8n workflow automation and Model Context Protocol (MCP)",
|
||||
"main": "dist/index.js",
|
||||
"bin": {
|
||||
|
||||
@@ -377,4 +377,78 @@ export class NodeRepository {
|
||||
|
||||
return allResources;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get default values for node properties
|
||||
*/
|
||||
getNodePropertyDefaults(nodeType: string): Record<string, any> {
|
||||
try {
|
||||
const node = this.getNode(nodeType);
|
||||
if (!node || !node.properties) return {};
|
||||
|
||||
const defaults: Record<string, any> = {};
|
||||
|
||||
for (const prop of node.properties) {
|
||||
if (prop.name && prop.default !== undefined) {
|
||||
defaults[prop.name] = prop.default;
|
||||
}
|
||||
}
|
||||
|
||||
return defaults;
|
||||
} catch (error) {
|
||||
// Log error and return empty defaults rather than throwing
|
||||
console.error(`Error getting property defaults for ${nodeType}:`, error);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the default operation for a specific resource
|
||||
*/
|
||||
getDefaultOperationForResource(nodeType: string, resource?: string): string | undefined {
|
||||
try {
|
||||
const node = this.getNode(nodeType);
|
||||
if (!node || !node.properties) return undefined;
|
||||
|
||||
// Find operation property that's visible for this resource
|
||||
for (const prop of node.properties) {
|
||||
if (prop.name === 'operation') {
|
||||
// If there's a resource dependency, check if it matches
|
||||
if (resource && prop.displayOptions?.show?.resource) {
|
||||
// Validate displayOptions structure
|
||||
const resourceDep = prop.displayOptions.show.resource;
|
||||
if (!Array.isArray(resourceDep) && typeof resourceDep !== 'string') {
|
||||
continue; // Skip malformed displayOptions
|
||||
}
|
||||
|
||||
const allowedResources = Array.isArray(resourceDep)
|
||||
? resourceDep
|
||||
: [resourceDep];
|
||||
|
||||
if (!allowedResources.includes(resource)) {
|
||||
continue; // This operation property doesn't apply to our resource
|
||||
}
|
||||
}
|
||||
|
||||
// Return the default value if it exists
|
||||
if (prop.default !== undefined) {
|
||||
return prop.default;
|
||||
}
|
||||
|
||||
// If no default but has options, return the first option's value
|
||||
if (prop.options && Array.isArray(prop.options) && prop.options.length > 0) {
|
||||
const firstOption = prop.options[0];
|
||||
return typeof firstOption === 'string' ? firstOption : firstOption.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// Log error and return undefined rather than throwing
|
||||
// This ensures validation continues even with malformed node data
|
||||
console.error(`Error getting default operation for ${nodeType}:`, error);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
@@ -2659,24 +2659,19 @@ Full documentation is being prepared. For now, use get_node_essentials for confi
|
||||
expressionsValidated: result.statistics.expressionsValidated,
|
||||
errorCount: result.errors.length,
|
||||
warningCount: result.warnings.length
|
||||
}
|
||||
};
|
||||
|
||||
if (result.errors.length > 0) {
|
||||
response.errors = result.errors.map(e => ({
|
||||
},
|
||||
// Always include errors and warnings arrays for consistent API response
|
||||
errors: result.errors.map(e => ({
|
||||
node: e.nodeName || 'workflow',
|
||||
message: e.message,
|
||||
details: e.details
|
||||
}));
|
||||
}
|
||||
|
||||
if (result.warnings.length > 0) {
|
||||
response.warnings = result.warnings.map(w => ({
|
||||
})),
|
||||
warnings: result.warnings.map(w => ({
|
||||
node: w.nodeName || 'workflow',
|
||||
message: w.message,
|
||||
details: w.details
|
||||
}));
|
||||
}
|
||||
}))
|
||||
};
|
||||
|
||||
if (result.suggestions.length > 0) {
|
||||
response.suggestions = result.suggestions;
|
||||
|
||||
@@ -108,16 +108,16 @@ export class ConfigValidator {
|
||||
* Check for missing required properties
|
||||
*/
|
||||
private static checkRequiredProperties(
|
||||
properties: any[],
|
||||
config: Record<string, any>,
|
||||
properties: any[],
|
||||
config: Record<string, any>,
|
||||
errors: ValidationError[]
|
||||
): void {
|
||||
for (const prop of properties) {
|
||||
if (!prop || !prop.name) continue; // Skip invalid properties
|
||||
|
||||
|
||||
if (prop.required) {
|
||||
const value = config[prop.name];
|
||||
|
||||
|
||||
// Check if property is missing or has null/undefined value
|
||||
if (!(prop.name in config)) {
|
||||
errors.push({
|
||||
@@ -133,6 +133,14 @@ export class ConfigValidator {
|
||||
message: `Required property '${prop.displayName || prop.name}' cannot be null or undefined`,
|
||||
fix: `Provide a valid value for ${prop.name}`
|
||||
});
|
||||
} else if (typeof value === 'string' && value.trim() === '') {
|
||||
// Check for empty strings which are invalid for required string properties
|
||||
errors.push({
|
||||
type: 'missing_required',
|
||||
property: prop.name,
|
||||
message: `Required property '${prop.displayName || prop.name}' cannot be empty`,
|
||||
fix: `Provide a valid value for ${prop.name}`
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { OperationSimilarityService } from './operation-similarity-service';
|
||||
import { ResourceSimilarityService } from './resource-similarity-service';
|
||||
import { NodeRepository } from '../database/node-repository';
|
||||
import { DatabaseAdapter } from '../database/database-adapter';
|
||||
import { normalizeNodeType } from '../utils/node-type-utils';
|
||||
|
||||
export type ValidationMode = 'full' | 'operation' | 'minimal';
|
||||
export type ValidationProfile = 'strict' | 'runtime' | 'ai-friendly' | 'minimal';
|
||||
@@ -76,17 +77,17 @@ export class EnhancedConfigValidator extends ConfigValidator {
|
||||
|
||||
// Extract operation context from config
|
||||
const operationContext = this.extractOperationContext(config);
|
||||
|
||||
// Filter properties based on mode and operation
|
||||
const filteredProperties = this.filterPropertiesByMode(
|
||||
|
||||
// Filter properties based on mode and operation, and get config with defaults
|
||||
const { properties: filteredProperties, configWithDefaults } = this.filterPropertiesByMode(
|
||||
properties,
|
||||
config,
|
||||
mode,
|
||||
operationContext
|
||||
);
|
||||
|
||||
// Perform base validation on filtered properties
|
||||
const baseResult = super.validate(nodeType, config, filteredProperties);
|
||||
|
||||
// Perform base validation on filtered properties with defaults applied
|
||||
const baseResult = super.validate(nodeType, configWithDefaults, filteredProperties);
|
||||
|
||||
// Enhance the result
|
||||
const enhancedResult: EnhancedValidationResult = {
|
||||
@@ -136,31 +137,56 @@ export class EnhancedConfigValidator extends ConfigValidator {
|
||||
|
||||
/**
|
||||
* Filter properties based on validation mode and operation
|
||||
* Returns both filtered properties and config with defaults
|
||||
*/
|
||||
private static filterPropertiesByMode(
|
||||
properties: any[],
|
||||
config: Record<string, any>,
|
||||
mode: ValidationMode,
|
||||
operation: OperationContext
|
||||
): any[] {
|
||||
): { properties: any[], configWithDefaults: Record<string, any> } {
|
||||
// Apply defaults for visibility checking
|
||||
const configWithDefaults = this.applyNodeDefaults(properties, config);
|
||||
|
||||
let filteredProperties: any[];
|
||||
switch (mode) {
|
||||
case 'minimal':
|
||||
// Only required properties that are visible
|
||||
return properties.filter(prop =>
|
||||
prop.required && this.isPropertyVisible(prop, config)
|
||||
filteredProperties = properties.filter(prop =>
|
||||
prop.required && this.isPropertyVisible(prop, configWithDefaults)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case 'operation':
|
||||
// Only properties relevant to the current operation
|
||||
return properties.filter(prop =>
|
||||
this.isPropertyRelevantToOperation(prop, config, operation)
|
||||
filteredProperties = properties.filter(prop =>
|
||||
this.isPropertyRelevantToOperation(prop, configWithDefaults, operation)
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case 'full':
|
||||
default:
|
||||
// All properties (current behavior)
|
||||
return properties;
|
||||
filteredProperties = properties;
|
||||
break;
|
||||
}
|
||||
|
||||
return { properties: filteredProperties, configWithDefaults };
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply node defaults to configuration for accurate visibility checking
|
||||
*/
|
||||
private static applyNodeDefaults(properties: any[], config: Record<string, any>): Record<string, any> {
|
||||
const result = { ...config };
|
||||
|
||||
for (const prop of properties) {
|
||||
if (prop.name && prop.default !== undefined && result[prop.name] === undefined) {
|
||||
result[prop.name] = prop.default;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -675,11 +701,25 @@ export class EnhancedConfigValidator extends ConfigValidator {
|
||||
return;
|
||||
}
|
||||
|
||||
// Normalize the node type for repository lookups
|
||||
const normalizedNodeType = normalizeNodeType(nodeType);
|
||||
|
||||
// Apply defaults for validation
|
||||
const configWithDefaults = { ...config };
|
||||
|
||||
// If operation is undefined but resource is set, get the default operation for that resource
|
||||
if (configWithDefaults.operation === undefined && configWithDefaults.resource !== undefined) {
|
||||
const defaultOperation = this.nodeRepository.getDefaultOperationForResource(normalizedNodeType, configWithDefaults.resource);
|
||||
if (defaultOperation !== undefined) {
|
||||
configWithDefaults.operation = defaultOperation;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate resource field if present
|
||||
if (config.resource !== undefined) {
|
||||
// Remove any existing resource error from base validator to replace with our enhanced version
|
||||
result.errors = result.errors.filter(e => e.property !== 'resource');
|
||||
const validResources = this.nodeRepository.getNodeResources(nodeType);
|
||||
const validResources = this.nodeRepository.getNodeResources(normalizedNodeType);
|
||||
const resourceIsValid = validResources.some(r => {
|
||||
const resourceValue = typeof r === 'string' ? r : r.value;
|
||||
return resourceValue === config.resource;
|
||||
@@ -690,7 +730,7 @@ export class EnhancedConfigValidator extends ConfigValidator {
|
||||
let suggestions: any[] = [];
|
||||
try {
|
||||
suggestions = this.resourceSimilarityService.findSimilarResources(
|
||||
nodeType,
|
||||
normalizedNodeType,
|
||||
config.resource,
|
||||
3
|
||||
);
|
||||
@@ -749,22 +789,27 @@ export class EnhancedConfigValidator extends ConfigValidator {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate operation field if present
|
||||
if (config.operation !== undefined) {
|
||||
// Validate operation field - now we check configWithDefaults which has defaults applied
|
||||
// Only validate if operation was explicitly set (not undefined) OR if we're using a default
|
||||
if (config.operation !== undefined || configWithDefaults.operation !== undefined) {
|
||||
// Remove any existing operation error from base validator to replace with our enhanced version
|
||||
result.errors = result.errors.filter(e => e.property !== 'operation');
|
||||
const validOperations = this.nodeRepository.getNodeOperations(nodeType, config.resource);
|
||||
|
||||
// Use the operation from configWithDefaults for validation (which includes the default if applied)
|
||||
const operationToValidate = configWithDefaults.operation || config.operation;
|
||||
const validOperations = this.nodeRepository.getNodeOperations(normalizedNodeType, config.resource);
|
||||
const operationIsValid = validOperations.some(op => {
|
||||
const opValue = op.operation || op.value || op;
|
||||
return opValue === config.operation;
|
||||
return opValue === operationToValidate;
|
||||
});
|
||||
|
||||
if (!operationIsValid && config.operation !== '') {
|
||||
// Only report error if the explicit operation is invalid (not for defaults)
|
||||
if (!operationIsValid && config.operation !== undefined && config.operation !== '') {
|
||||
// Find similar operations
|
||||
let suggestions: any[] = [];
|
||||
try {
|
||||
suggestions = this.operationSimilarityService.findSimilarOperations(
|
||||
nodeType,
|
||||
normalizedNodeType,
|
||||
config.operation,
|
||||
config.resource,
|
||||
3
|
||||
|
||||
@@ -141,12 +141,21 @@ export class ExpressionValidator {
|
||||
const jsonPattern = new RegExp(this.VARIABLE_PATTERNS.json.source, this.VARIABLE_PATTERNS.json.flags);
|
||||
while ((match = jsonPattern.exec(expr)) !== null) {
|
||||
result.usedVariables.add('$json');
|
||||
|
||||
|
||||
if (!context.hasInputData && !context.isInLoop) {
|
||||
result.warnings.push(
|
||||
'Using $json but node might not have input data'
|
||||
);
|
||||
}
|
||||
|
||||
// Check for suspicious property names that might be test/invalid data
|
||||
const fullMatch = match[0];
|
||||
if (fullMatch.includes('.invalid') || fullMatch.includes('.undefined') ||
|
||||
fullMatch.includes('.null') || fullMatch.includes('.test')) {
|
||||
result.warnings.push(
|
||||
`Property access '${fullMatch}' looks suspicious - verify this property exists in your data`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for $node references
|
||||
|
||||
@@ -1132,8 +1132,11 @@ export class NodeSpecificValidators {
|
||||
const syntaxPatterns = [
|
||||
{ pattern: /const\s+const/, message: 'Duplicate const declaration' },
|
||||
{ pattern: /let\s+let/, message: 'Duplicate let declaration' },
|
||||
{ pattern: /\)\s*\)\s*{/, message: 'Extra closing parenthesis before {' },
|
||||
{ pattern: /}\s*}$/, message: 'Extra closing brace at end' }
|
||||
// Removed overly simplistic parenthesis check - it was causing false positives
|
||||
// for valid patterns like $('NodeName').first().json or func()()
|
||||
// { pattern: /\)\s*\)\s*{/, message: 'Extra closing parenthesis before {' },
|
||||
// Only check for multiple closing braces at the very end (more likely to be an error)
|
||||
{ pattern: /}\s*}\s*}\s*}$/, message: 'Multiple closing braces at end - check your nesting' }
|
||||
];
|
||||
|
||||
syntaxPatterns.forEach(({ pattern, message }) => {
|
||||
|
||||
@@ -364,19 +364,6 @@ export class WorkflowValidator {
|
||||
});
|
||||
}
|
||||
}
|
||||
// FIRST: Check for common invalid patterns before database lookup
|
||||
if (node.type.startsWith('nodes-base.')) {
|
||||
// This is ALWAYS invalid in workflows - must use n8n-nodes-base prefix
|
||||
const correctType = node.type.replace('nodes-base.', 'n8n-nodes-base.');
|
||||
result.errors.push({
|
||||
type: 'error',
|
||||
nodeId: node.id,
|
||||
nodeName: node.name,
|
||||
message: `Invalid node type: "${node.type}". Use "${correctType}" instead. Node types in workflows must use the full package name.`
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
// Get node definition - try multiple formats
|
||||
let nodeInfo = this.nodeRepository.getNode(node.type);
|
||||
|
||||
|
||||
@@ -18,7 +18,9 @@ describe('EnhancedConfigValidator - Integration Tests', () => {
|
||||
getNode: vi.fn(),
|
||||
getNodeOperations: vi.fn().mockReturnValue([]),
|
||||
getNodeResources: vi.fn().mockReturnValue([]),
|
||||
getOperationsForResource: vi.fn().mockReturnValue([])
|
||||
getOperationsForResource: vi.fn().mockReturnValue([]),
|
||||
getDefaultOperationForResource: vi.fn().mockReturnValue(undefined),
|
||||
getNodePropertyDefaults: vi.fn().mockReturnValue({})
|
||||
};
|
||||
|
||||
mockResourceService = {
|
||||
|
||||
@@ -99,15 +99,15 @@ describe('EnhancedConfigValidator', () => {
|
||||
// Mock isPropertyVisible to return true
|
||||
vi.spyOn(EnhancedConfigValidator as any, 'isPropertyVisible').mockReturnValue(true);
|
||||
|
||||
const filtered = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
const result = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
properties,
|
||||
{ resource: 'message', operation: 'send' },
|
||||
'operation',
|
||||
{ resource: 'message', operation: 'send' }
|
||||
);
|
||||
|
||||
expect(filtered).toHaveLength(1);
|
||||
expect(filtered[0].name).toBe('channel');
|
||||
expect(result.properties).toHaveLength(1);
|
||||
expect(result.properties[0].name).toBe('channel');
|
||||
});
|
||||
|
||||
it('should handle minimal validation mode', () => {
|
||||
@@ -459,7 +459,7 @@ describe('EnhancedConfigValidator', () => {
|
||||
// Remove the mock to test real implementation
|
||||
vi.restoreAllMocks();
|
||||
|
||||
const filtered = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
const result = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
properties,
|
||||
{ resource: 'message', operation: 'send' },
|
||||
'operation',
|
||||
@@ -467,9 +467,9 @@ describe('EnhancedConfigValidator', () => {
|
||||
);
|
||||
|
||||
// Should include messageChannel and sharedProperty, but not userEmail
|
||||
expect(filtered).toHaveLength(2);
|
||||
expect(filtered.map(p => p.name)).toContain('messageChannel');
|
||||
expect(filtered.map(p => p.name)).toContain('sharedProperty');
|
||||
expect(result.properties).toHaveLength(2);
|
||||
expect(result.properties.map(p => p.name)).toContain('messageChannel');
|
||||
expect(result.properties.map(p => p.name)).toContain('sharedProperty');
|
||||
});
|
||||
|
||||
it('should handle properties without displayOptions in operation mode', () => {
|
||||
@@ -487,7 +487,7 @@ describe('EnhancedConfigValidator', () => {
|
||||
|
||||
vi.restoreAllMocks();
|
||||
|
||||
const filtered = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
const result = EnhancedConfigValidator['filterPropertiesByMode'](
|
||||
properties,
|
||||
{ resource: 'user' },
|
||||
'operation',
|
||||
@@ -495,9 +495,9 @@ describe('EnhancedConfigValidator', () => {
|
||||
);
|
||||
|
||||
// Should include property without displayOptions
|
||||
expect(filtered.map(p => p.name)).toContain('alwaysVisible');
|
||||
expect(result.properties.map(p => p.name)).toContain('alwaysVisible');
|
||||
// Should not include conditionalProperty (wrong resource)
|
||||
expect(filtered.map(p => p.name)).not.toContain('conditionalProperty');
|
||||
expect(result.properties.map(p => p.name)).not.toContain('conditionalProperty');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
377
tests/unit/services/validation-fixes.test.ts
Normal file
377
tests/unit/services/validation-fixes.test.ts
Normal file
@@ -0,0 +1,377 @@
|
||||
/**
|
||||
* Test cases for validation fixes - specifically for false positives
|
||||
*/
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
||||
import { WorkflowValidator } from '../../../src/services/workflow-validator';
|
||||
import { EnhancedConfigValidator } from '../../../src/services/enhanced-config-validator';
|
||||
import { NodeRepository } from '../../../src/database/node-repository';
|
||||
import { DatabaseAdapter, PreparedStatement, RunResult } from '../../../src/database/database-adapter';
|
||||
|
||||
// Mock logger to prevent console output
|
||||
vi.mock('@/utils/logger', () => ({
|
||||
Logger: vi.fn().mockImplementation(() => ({
|
||||
error: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
info: vi.fn(),
|
||||
debug: vi.fn()
|
||||
}))
|
||||
}));
|
||||
|
||||
// Create a complete mock for DatabaseAdapter
|
||||
class MockDatabaseAdapter implements DatabaseAdapter {
|
||||
private statements = new Map<string, MockPreparedStatement>();
|
||||
private mockData = new Map<string, any>();
|
||||
|
||||
prepare = vi.fn((sql: string) => {
|
||||
if (!this.statements.has(sql)) {
|
||||
this.statements.set(sql, new MockPreparedStatement(sql, this.mockData));
|
||||
}
|
||||
return this.statements.get(sql)!;
|
||||
});
|
||||
|
||||
exec = vi.fn();
|
||||
close = vi.fn();
|
||||
pragma = vi.fn();
|
||||
transaction = vi.fn((fn: () => any) => fn());
|
||||
checkFTS5Support = vi.fn(() => true);
|
||||
inTransaction = false;
|
||||
|
||||
// Test helper to set mock data
|
||||
_setMockData(key: string, value: any) {
|
||||
this.mockData.set(key, value);
|
||||
}
|
||||
|
||||
// Test helper to get statement by SQL
|
||||
_getStatement(sql: string) {
|
||||
return this.statements.get(sql);
|
||||
}
|
||||
}
|
||||
|
||||
class MockPreparedStatement implements PreparedStatement {
|
||||
run = vi.fn((...params: any[]): RunResult => ({ changes: 1, lastInsertRowid: 1 }));
|
||||
get = vi.fn();
|
||||
all = vi.fn(() => []);
|
||||
iterate = vi.fn();
|
||||
pluck = vi.fn(() => this);
|
||||
expand = vi.fn(() => this);
|
||||
raw = vi.fn(() => this);
|
||||
columns = vi.fn(() => []);
|
||||
bind = vi.fn(() => this);
|
||||
|
||||
constructor(private sql: string, private mockData: Map<string, any>) {
|
||||
// Configure get() based on SQL pattern
|
||||
if (sql.includes('SELECT * FROM nodes WHERE node_type = ?')) {
|
||||
this.get = vi.fn((nodeType: string) => this.mockData.get(`node:${nodeType}`));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
describe('Validation Fixes for False Positives', () => {
|
||||
let repository: any;
|
||||
let mockAdapter: MockDatabaseAdapter;
|
||||
let validator: WorkflowValidator;
|
||||
|
||||
beforeEach(() => {
|
||||
mockAdapter = new MockDatabaseAdapter();
|
||||
repository = new NodeRepository(mockAdapter);
|
||||
|
||||
// Add findSimilarNodes method for WorkflowValidator
|
||||
repository.findSimilarNodes = vi.fn().mockReturnValue([]);
|
||||
|
||||
// Initialize services
|
||||
EnhancedConfigValidator.initializeSimilarityServices(repository);
|
||||
|
||||
validator = new WorkflowValidator(repository, EnhancedConfigValidator);
|
||||
|
||||
// Mock Google Drive node data
|
||||
const googleDriveNodeData = {
|
||||
node_type: 'nodes-base.googleDrive',
|
||||
package_name: 'n8n-nodes-base',
|
||||
display_name: 'Google Drive',
|
||||
description: 'Access Google Drive',
|
||||
category: 'input',
|
||||
development_style: 'programmatic',
|
||||
is_ai_tool: 0,
|
||||
is_trigger: 0,
|
||||
is_webhook: 0,
|
||||
is_versioned: 1,
|
||||
version: '3',
|
||||
properties_schema: JSON.stringify([
|
||||
{
|
||||
name: 'resource',
|
||||
type: 'options',
|
||||
default: 'file',
|
||||
options: [
|
||||
{ value: 'file', name: 'File' },
|
||||
{ value: 'fileFolder', name: 'File/Folder' },
|
||||
{ value: 'folder', name: 'Folder' },
|
||||
{ value: 'drive', name: 'Shared Drive' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'operation',
|
||||
type: 'options',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['fileFolder']
|
||||
}
|
||||
},
|
||||
default: 'search',
|
||||
options: [
|
||||
{ value: 'search', name: 'Search' }
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'queryString',
|
||||
type: 'string',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['fileFolder'],
|
||||
operation: ['search']
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'filter',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['fileFolder'],
|
||||
operation: ['search']
|
||||
}
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'folderId',
|
||||
type: 'resourceLocator',
|
||||
default: { mode: 'list', value: '' }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
name: 'options',
|
||||
type: 'collection',
|
||||
displayOptions: {
|
||||
show: {
|
||||
resource: ['fileFolder'],
|
||||
operation: ['search']
|
||||
}
|
||||
},
|
||||
default: {},
|
||||
options: [
|
||||
{
|
||||
name: 'fields',
|
||||
type: 'multiOptions',
|
||||
default: []
|
||||
}
|
||||
]
|
||||
}
|
||||
]),
|
||||
operations: JSON.stringify([]),
|
||||
credentials_required: JSON.stringify([]),
|
||||
documentation: null,
|
||||
outputs: null,
|
||||
output_names: null
|
||||
};
|
||||
|
||||
// Set mock data for node retrieval
|
||||
mockAdapter._setMockData('node:nodes-base.googleDrive', googleDriveNodeData);
|
||||
mockAdapter._setMockData('node:n8n-nodes-base.googleDrive', googleDriveNodeData);
|
||||
});
|
||||
|
||||
describe('Google Drive fileFolder Resource Validation', () => {
|
||||
it('should validate fileFolder as a valid resource', () => {
|
||||
const config = {
|
||||
resource: 'fileFolder'
|
||||
};
|
||||
|
||||
const node = repository.getNode('nodes-base.googleDrive');
|
||||
const result = EnhancedConfigValidator.validateWithMode(
|
||||
'nodes-base.googleDrive',
|
||||
config,
|
||||
node.properties,
|
||||
'operation',
|
||||
'ai-friendly'
|
||||
);
|
||||
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
// Should not have resource error
|
||||
const resourceError = result.errors.find(e => e.property === 'resource');
|
||||
expect(resourceError).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should apply default operation when not specified', () => {
|
||||
const config = {
|
||||
resource: 'fileFolder'
|
||||
// operation is not specified, should use default 'search'
|
||||
};
|
||||
|
||||
const node = repository.getNode('nodes-base.googleDrive');
|
||||
const result = EnhancedConfigValidator.validateWithMode(
|
||||
'nodes-base.googleDrive',
|
||||
config,
|
||||
node.properties,
|
||||
'operation',
|
||||
'ai-friendly'
|
||||
);
|
||||
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
// Should not have operation error
|
||||
const operationError = result.errors.find(e => e.property === 'operation');
|
||||
expect(operationError).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should not warn about properties being unused when default operation is applied', () => {
|
||||
const config = {
|
||||
resource: 'fileFolder',
|
||||
// operation not specified, will use default 'search'
|
||||
queryString: '=',
|
||||
filter: {
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: '={{ $json.id }}',
|
||||
mode: 'id'
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fields: ['id', 'kind', 'mimeType', 'name', 'webViewLink']
|
||||
}
|
||||
};
|
||||
|
||||
const node = repository.getNode('nodes-base.googleDrive');
|
||||
const result = EnhancedConfigValidator.validateWithMode(
|
||||
'nodes-base.googleDrive',
|
||||
config,
|
||||
node.properties,
|
||||
'operation',
|
||||
'ai-friendly'
|
||||
);
|
||||
|
||||
// Should be valid
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
// Should not have warnings about properties not being used
|
||||
const propertyWarnings = result.warnings.filter(w =>
|
||||
w.message.includes("won't be used") || w.message.includes("not used")
|
||||
);
|
||||
expect(propertyWarnings.length).toBe(0);
|
||||
});
|
||||
|
||||
it.skip('should validate complete workflow with Google Drive nodes', async () => {
|
||||
const workflow = {
|
||||
name: 'Test Google Drive Workflow',
|
||||
nodes: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Google Drive',
|
||||
type: 'n8n-nodes-base.googleDrive',
|
||||
typeVersion: 3,
|
||||
position: [100, 100] as [number, number],
|
||||
parameters: {
|
||||
resource: 'fileFolder',
|
||||
queryString: '=',
|
||||
filter: {
|
||||
folderId: {
|
||||
__rl: true,
|
||||
value: '={{ $json.id }}',
|
||||
mode: 'id'
|
||||
}
|
||||
},
|
||||
options: {
|
||||
fields: ['id', 'kind', 'mimeType', 'name', 'webViewLink']
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: {}
|
||||
};
|
||||
|
||||
let result;
|
||||
try {
|
||||
result = await validator.validateWorkflow(workflow, {
|
||||
validateNodes: true,
|
||||
validateConnections: true,
|
||||
validateExpressions: true,
|
||||
profile: 'ai-friendly'
|
||||
});
|
||||
} catch (error) {
|
||||
console.log('Validation threw error:', error);
|
||||
throw error;
|
||||
}
|
||||
|
||||
// Debug output
|
||||
if (!result.valid) {
|
||||
console.log('Validation errors:', JSON.stringify(result.errors, null, 2));
|
||||
console.log('Validation warnings:', JSON.stringify(result.warnings, null, 2));
|
||||
}
|
||||
|
||||
// Should be valid
|
||||
expect(result.valid).toBe(true);
|
||||
|
||||
// Should not have "Invalid resource" errors
|
||||
const resourceErrors = result.errors.filter((e: any) =>
|
||||
e.message.includes('Invalid resource') && e.message.includes('fileFolder')
|
||||
);
|
||||
expect(resourceErrors.length).toBe(0);
|
||||
});
|
||||
|
||||
it('should still report errors for truly invalid resources', () => {
|
||||
const config = {
|
||||
resource: 'invalidResource'
|
||||
};
|
||||
|
||||
const node = repository.getNode('nodes-base.googleDrive');
|
||||
const result = EnhancedConfigValidator.validateWithMode(
|
||||
'nodes-base.googleDrive',
|
||||
config,
|
||||
node.properties,
|
||||
'operation',
|
||||
'ai-friendly'
|
||||
);
|
||||
|
||||
expect(result.valid).toBe(false);
|
||||
|
||||
// Should have resource error for invalid resource
|
||||
const resourceError = result.errors.find(e => e.property === 'resource');
|
||||
expect(resourceError).toBeDefined();
|
||||
expect(resourceError!.message).toContain('Invalid resource "invalidResource"');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Node Type Validation', () => {
|
||||
it('should accept both n8n-nodes-base and nodes-base prefixes', async () => {
|
||||
const workflow1 = {
|
||||
name: 'Test with n8n-nodes-base prefix',
|
||||
nodes: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Google Drive',
|
||||
type: 'n8n-nodes-base.googleDrive',
|
||||
typeVersion: 3,
|
||||
position: [100, 100] as [number, number],
|
||||
parameters: {
|
||||
resource: 'file'
|
||||
}
|
||||
}
|
||||
],
|
||||
connections: {}
|
||||
};
|
||||
|
||||
const result1 = await validator.validateWorkflow(workflow1);
|
||||
|
||||
// Should not have errors about node type format
|
||||
const typeErrors1 = result1.errors.filter((e: any) =>
|
||||
e.message.includes('Invalid node type') ||
|
||||
e.message.includes('must use the full package name')
|
||||
);
|
||||
expect(typeErrors1.length).toBe(0);
|
||||
|
||||
// Note: nodes-base prefix might still be invalid in actual workflows
|
||||
// but the validator shouldn't incorrectly suggest it's always wrong
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -507,13 +507,14 @@ describe('WorkflowValidator - Comprehensive Tests', () => {
|
||||
expect(mockNodeRepository.getNode).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should error for invalid node type starting with nodes-base', async () => {
|
||||
it('should accept both nodes-base and n8n-nodes-base prefixes as valid', async () => {
|
||||
// This test verifies the fix for false positives - both prefixes are valid
|
||||
const workflow = {
|
||||
nodes: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Webhook',
|
||||
type: 'nodes-base.webhook', // Missing n8n- prefix
|
||||
type: 'nodes-base.webhook', // This is now valid (normalized internally)
|
||||
position: [100, 100],
|
||||
parameters: {}
|
||||
}
|
||||
@@ -521,11 +522,24 @@ describe('WorkflowValidator - Comprehensive Tests', () => {
|
||||
connections: {}
|
||||
} as any;
|
||||
|
||||
// Mock the normalized node lookup
|
||||
(mockNodeRepository.getNode as any) = vi.fn((type: string) => {
|
||||
if (type === 'nodes-base.webhook') {
|
||||
return {
|
||||
nodeType: 'nodes-base.webhook',
|
||||
displayName: 'Webhook',
|
||||
properties: [],
|
||||
isVersioned: false
|
||||
};
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
||||
const result = await validator.validateWorkflow(workflow as any);
|
||||
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.errors.some(e => e.message.includes('Invalid node type: "nodes-base.webhook"'))).toBe(true);
|
||||
expect(result.errors.some(e => e.message.includes('Use "n8n-nodes-base.webhook" instead'))).toBe(true);
|
||||
// Should NOT error for nodes-base prefix - it's valid!
|
||||
expect(result.valid).toBe(true);
|
||||
expect(result.errors.some(e => e.message.includes('Invalid node type'))).toBe(false);
|
||||
});
|
||||
|
||||
it.skip('should handle unknown node types with suggestions', async () => {
|
||||
@@ -1826,11 +1840,11 @@ describe('WorkflowValidator - Comprehensive Tests', () => {
|
||||
parameters: {},
|
||||
typeVersion: 2
|
||||
},
|
||||
// Node with wrong type format
|
||||
// Node with valid alternative prefix (no longer an error)
|
||||
{
|
||||
id: '2',
|
||||
name: 'HTTP1',
|
||||
type: 'nodes-base.httpRequest', // Wrong prefix
|
||||
type: 'nodes-base.httpRequest', // Valid prefix (normalized internally)
|
||||
position: [300, 100],
|
||||
parameters: {}
|
||||
},
|
||||
@@ -1900,12 +1914,11 @@ describe('WorkflowValidator - Comprehensive Tests', () => {
|
||||
|
||||
const result = await validator.validateWorkflow(workflow as any);
|
||||
|
||||
// Should have multiple errors
|
||||
// Should have multiple errors (but not for the nodes-base prefix)
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.errors.length).toBeGreaterThan(3);
|
||||
expect(result.errors.length).toBeGreaterThan(2); // Reduced by 1 since nodes-base prefix is now valid
|
||||
|
||||
// Specific errors
|
||||
expect(result.errors.some(e => e.message.includes('Invalid node type: "nodes-base.httpRequest"'))).toBe(true);
|
||||
// Specific errors (removed the invalid node type error as it's no longer invalid)
|
||||
expect(result.errors.some(e => e.message.includes('Missing required property \'typeVersion\''))).toBe(true);
|
||||
expect(result.errors.some(e => e.message.includes('Node-level properties onError are in the wrong location'))).toBe(true);
|
||||
expect(result.errors.some(e => e.message.includes('Connection uses node ID \'5\' instead of node name'))).toBe(true);
|
||||
|
||||
@@ -448,9 +448,32 @@ describe('WorkflowValidator - Simple Unit Tests', () => {
|
||||
expect(result.warnings.some(w => w.message.includes('Outdated typeVersion'))).toBe(true);
|
||||
});
|
||||
|
||||
it('should detect invalid node type format', async () => {
|
||||
// Arrange
|
||||
const mockRepository = createMockRepository({});
|
||||
it('should normalize and validate nodes-base prefix to find the node', async () => {
|
||||
// Arrange - Test that nodes-base prefix is normalized to find the node
|
||||
// The repository only has the node under the normalized key
|
||||
const nodeData = {
|
||||
'nodes-base.webhook': { // Repository has it under normalized form
|
||||
type: 'nodes-base.webhook',
|
||||
displayName: 'Webhook',
|
||||
isVersioned: true,
|
||||
version: 2,
|
||||
properties: []
|
||||
}
|
||||
};
|
||||
|
||||
// Mock repository that simulates the normalization behavior
|
||||
const mockRepository = {
|
||||
getNode: vi.fn((type: string) => {
|
||||
// First call with original type returns null
|
||||
// Second call with normalized type returns the node
|
||||
if (type === 'nodes-base.webhook') {
|
||||
return nodeData['nodes-base.webhook'];
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
findSimilarNodes: vi.fn().mockReturnValue([])
|
||||
};
|
||||
|
||||
const mockValidatorClass = createMockValidatorClass({
|
||||
valid: true,
|
||||
errors: [],
|
||||
@@ -461,14 +484,15 @@ describe('WorkflowValidator - Simple Unit Tests', () => {
|
||||
validator = new WorkflowValidator(mockRepository as any, mockValidatorClass as any);
|
||||
|
||||
const workflow = {
|
||||
name: 'Invalid Type Format',
|
||||
name: 'Valid Alternative Prefix',
|
||||
nodes: [
|
||||
{
|
||||
id: '1',
|
||||
name: 'Webhook',
|
||||
type: 'nodes-base.webhook', // Invalid format
|
||||
type: 'nodes-base.webhook', // Using the alternative prefix
|
||||
position: [250, 300] as [number, number],
|
||||
parameters: {}
|
||||
parameters: {},
|
||||
typeVersion: 2
|
||||
}
|
||||
],
|
||||
connections: {}
|
||||
@@ -477,12 +501,12 @@ describe('WorkflowValidator - Simple Unit Tests', () => {
|
||||
// Act
|
||||
const result = await validator.validateWorkflow(workflow as any);
|
||||
|
||||
// Assert
|
||||
expect(result.valid).toBe(false);
|
||||
expect(result.errors.some(e =>
|
||||
e.message.includes('Invalid node type') &&
|
||||
e.message.includes('Use "n8n-nodes-base.webhook" instead')
|
||||
)).toBe(true);
|
||||
// Assert - The node should be found through normalization
|
||||
expect(result.valid).toBe(true);
|
||||
expect(result.errors).toHaveLength(0);
|
||||
|
||||
// Verify the repository was called (once with original, once with normalized)
|
||||
expect(mockRepository.getNode).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user