fix: improve rewireConnection validation to check specific sourceIndex

Addresses code review feedback - rewireConnection now validates that a
connection exists at the SPECIFIC sourceIndex, not just at any index.

Problem:
- Previous validation checked if connection existed at ANY index
- Could cause confusing runtime errors instead of clear validation errors
- Example: Connection exists at index 0, but rewireConnection uses index 1

Fix:
- Resolve smart parameters to get actual sourceIndex
- Validate connection exists at connections[sourceOutput][sourceIndex]
- Provide clear error message with specific index

Impact:
- Better validation error messages
- Prevents confusing runtime errors
- Clearer feedback to AI agents

Code Review: High priority fix from @agent-code-reviewer

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-10-06 08:15:01 +02:00
parent 59e4cb85ac
commit 44568a6edd

View File

@@ -484,20 +484,22 @@ export class WorkflowDiffEngine {
}
// Resolve smart parameters (branch, case) before validating connections
const { sourceOutput } = this.resolveSmartParameters(workflow, operation);
const { sourceOutput, sourceIndex } = this.resolveSmartParameters(workflow, operation);
// Validate that connection from source to "from" exists
// Validate that connection from source to "from" exists at the specific index
const connections = workflow.connections[sourceNode.name]?.[sourceOutput];
if (!connections) {
return `No connections found from "${sourceNode.name}" on output "${sourceOutput}"`;
}
const hasConnection = connections.some(conns =>
conns.some(c => c.node === fromNode.name)
);
if (!connections[sourceIndex]) {
return `No connections found from "${sourceNode.name}" on output "${sourceOutput}" at index ${sourceIndex}`;
}
const hasConnection = connections[sourceIndex].some(c => c.node === fromNode.name);
if (!hasConnection) {
return `No connection exists from "${sourceNode.name}" to "${fromNode.name}" on output "${sourceOutput}"`;
return `No connection exists from "${sourceNode.name}" to "${fromNode.name}" on output "${sourceOutput}" at index ${sourceIndex}"`;
}
return null;