fix: CRITICAL - branch parameter now correctly maps to sourceIndex, not sourceOutput

Found by n8n-mcp-tester agent: IF nodes in n8n store connections as:
  IF.main[0] (true branch)
  IF.main[1] (false branch)
NOT as IF.true and IF.false

Previous implementation (WRONG):
- branch='true' → sourceOutput='true'

Correct implementation (FIXED):
- branch='true' → sourceIndex=0, sourceOutput='main'
- branch='false' → sourceIndex=1, sourceOutput='main'

Changes:
- resolveSmartParameters(): branch now sets sourceIndex, not sourceOutput
- Type definition comments updated to reflect correct mapping
- All unit tests fixed to expect connections under 'main' with correct indices
- All 141 tests passing with correct behavior

This was caught by integration testing against real n8n API, not by unit tests.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-10-05 23:38:26 +02:00
parent ee125c52f8
commit a7bfa73479
3 changed files with 25 additions and 17 deletions

View File

@@ -648,10 +648,12 @@ export class WorkflowDiffEngine {
let sourceIndex = operation.sourceIndex ?? 0;
// Smart parameter: branch (for IF nodes)
if (operation.branch && !operation.sourceOutput) {
// Only apply if sourceOutput not explicitly set
// IF nodes use 'main' output with index 0 (true) or 1 (false)
if (operation.branch !== undefined && operation.sourceIndex === undefined) {
// Only apply if sourceIndex not explicitly set
if (sourceNode?.type === 'n8n-nodes-base.if') {
sourceOutput = operation.branch; // 'true' or 'false'
sourceIndex = operation.branch === 'true' ? 0 : 1;
// sourceOutput remains 'main' (do not change it)
}
}