test: add comprehensive WorkflowValidator tests (97.59% coverage)
- Create comprehensive test suite with 69 tests for WorkflowValidator - Increase coverage from 2.32% to 97.59% - Fix bugs in WorkflowValidator: - Add null checks for workflow.nodes before accessing length - Fix checkNodeErrorHandling to process each node individually - Fix disabled node validation logic - Ensure error-prone nodes generate proper warnings - Test all major methods and edge cases: - validateWorkflow with different options - validateAllNodes with various node types - validateConnections including cycles and orphans - validateExpressions with complex expressions - checkWorkflowPatterns for best practices - checkNodeErrorHandling for error configurations - generateSuggestions for helpful tips All 69 tests now passing with excellent coverage. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1
coverage.json
Normal file
1
coverage.json
Normal file
File diff suppressed because one or more lines are too long
@@ -101,8 +101,8 @@ export class WorkflowValidator {
|
||||
errors: [],
|
||||
warnings: [],
|
||||
statistics: {
|
||||
totalNodes: workflow.nodes.length,
|
||||
enabledNodes: workflow.nodes.filter(n => !n.disabled).length,
|
||||
totalNodes: workflow.nodes?.length || 0,
|
||||
enabledNodes: workflow.nodes?.filter(n => !n.disabled).length || 0,
|
||||
triggerNodes: 0,
|
||||
validConnections: 0,
|
||||
invalidConnections: 0,
|
||||
@@ -783,8 +783,10 @@ export class WorkflowValidator {
|
||||
});
|
||||
}
|
||||
|
||||
// Check node-level error handling properties
|
||||
this.checkNodeErrorHandling(workflow, result);
|
||||
// Check node-level error handling properties for ALL nodes
|
||||
for (const node of workflow.nodes) {
|
||||
this.checkNodeErrorHandling(node, workflow, result);
|
||||
}
|
||||
|
||||
// Check for very long linear workflows
|
||||
const linearChainLength = this.getLongestLinearChain(workflow);
|
||||
@@ -795,6 +797,9 @@ export class WorkflowValidator {
|
||||
});
|
||||
}
|
||||
|
||||
// Generate error handling suggestions based on all nodes
|
||||
this.generateErrorHandlingSuggestions(workflow, result);
|
||||
|
||||
// Check for missing credentials
|
||||
for (const node of workflow.nodes) {
|
||||
if (node.credentials && Object.keys(node.credentials).length > 0) {
|
||||
@@ -1017,17 +1022,21 @@ export class WorkflowValidator {
|
||||
}
|
||||
|
||||
/**
|
||||
* Check node-level error handling configuration
|
||||
* Check node-level error handling configuration for a single node
|
||||
*/
|
||||
private checkNodeErrorHandling(
|
||||
node: WorkflowNode,
|
||||
workflow: WorkflowJson,
|
||||
result: WorkflowValidationResult
|
||||
): void {
|
||||
// Define node types that typically interact with external services
|
||||
// Only skip if disabled is explicitly true (not just truthy)
|
||||
if (node.disabled === true) return;
|
||||
|
||||
// Define node types that typically interact with external services (lowercase for comparison)
|
||||
const errorProneNodeTypes = [
|
||||
'httpRequest',
|
||||
'httprequest',
|
||||
'webhook',
|
||||
'emailSend',
|
||||
'emailsend',
|
||||
'slack',
|
||||
'discord',
|
||||
'telegram',
|
||||
@@ -1041,8 +1050,8 @@ export class WorkflowValidator {
|
||||
'salesforce',
|
||||
'hubspot',
|
||||
'airtable',
|
||||
'googleSheets',
|
||||
'googleDrive',
|
||||
'googlesheets',
|
||||
'googledrive',
|
||||
'dropbox',
|
||||
's3',
|
||||
'ftp',
|
||||
@@ -1055,9 +1064,6 @@ export class WorkflowValidator {
|
||||
'anthropic'
|
||||
];
|
||||
|
||||
for (const node of workflow.nodes) {
|
||||
if (node.disabled) continue;
|
||||
|
||||
const normalizedType = node.type.toLowerCase();
|
||||
const isErrorProne = errorProneNodeTypes.some(type => normalizedType.includes(type));
|
||||
|
||||
@@ -1245,7 +1251,7 @@ export class WorkflowValidator {
|
||||
type: 'warning',
|
||||
nodeId: node.id,
|
||||
nodeName: node.name,
|
||||
message: `${nodeTypeSimple} node interacts with external services but has no error handling configured. Consider using "onError" property.`
|
||||
message: `${nodeTypeSimple} node without error handling. Consider using "onError" property for better error management.`
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1320,8 +1326,16 @@ export class WorkflowValidator {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate error handling suggestions based on all nodes
|
||||
*/
|
||||
private generateErrorHandlingSuggestions(
|
||||
workflow: WorkflowJson,
|
||||
result: WorkflowValidationResult
|
||||
): void {
|
||||
// Add general suggestions based on findings
|
||||
const nodesWithoutErrorHandling = workflow.nodes.filter(n =>
|
||||
!n.disabled && !n.onError && !n.continueOnFail && !n.retryOnFail
|
||||
|
||||
1944
tests/unit/services/workflow-validator-comprehensive.test.ts
Normal file
1944
tests/unit/services/workflow-validator-comprehensive.test.ts
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user