CRITICAL BUG FIX: Fixed array index corruption in multi-output nodes
(Switch, IF with multiple handlers, Merge) when rewiring connections.
Problem:
- applyRemoveConnection() filtered out empty arrays after removing connections
- This caused indices to shift in multi-output nodes
- Example: Switch.main = [[H0], [H1], [H2]] -> remove H1 -> [[H0], [H2]]
- H2 moved from index 2 to index 1, corrupting workflow structure
Root Cause:
```typescript
// Line 697 - BUGGY CODE:
workflow.connections[node][output] =
connections.filter(conns => conns.length > 0);
```
Solution:
- Only remove trailing empty arrays
- Preserve intermediate empty arrays to maintain index integrity
- Example: [[H0], [], [H2]] stays [[H0], [], [H2]] not [[H0], [H2]]
Impact:
- Prevents production-breaking workflow corruption
- Fixes rewireConnection operation for multi-output nodes
- Critical for AI agents working with complex workflows
Testing:
- Added integration test for Switch node rewiring with array index verification
- Test creates 4-output Switch node, rewires middle connection
- Verifies indices 0, 2, 3 unchanged after rewiring index 1
- All 137 unit tests + 12 integration tests passing
Discovered by: @agent-n8n-mcp-tester during comprehensive testing
Issue: #272 (Connection Operations - Phase 1)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
**Critical Fix**: Tests now properly test the MCP handler layer (the actual product) instead of raw API client.
**Changes**:
- All 15 tests now use `handleCreateWorkflow()` MCP handler
- Tests validate `McpToolResponse` structure (`success`, `data`, `error`)
- Created `mcp-context.ts` helper for configuring InstanceContext
- Fixed ERROR_HANDLING_WORKFLOW to add main connection (MCP validation requirement)
- Updated error/edge case tests to expect validation failures (correct MCP behavior)
**MCP Handler Validation**:
- Error scenarios now correctly expect `success: false` with validation errors
- Edge cases updated to reflect MCP handler's proper pre-validation
- Documents that MCP validation is CORRECT behavior (catches errors early)
**Test Results**: All 15 scenarios passing
- 8 valid workflow tests → expect `success: true`
- 7 validation tests (errors/edge cases) → expect `success: false`
**Why This Matters**:
AI assistants interact with MCP handlers, not raw API client. Testing the wrong layer would miss MCP-specific logic and validation.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Implements comprehensive workflow creation tests against real n8n instance
with 15 test scenarios covering P0 bugs, base nodes, advanced features,
error scenarios, and edge cases.
Key Changes:
- Added 15 workflow creation test scenarios in create-workflow.test.ts
- Fixed critical MSW interference with real API calls
- Fixed environment loading priority (.env before test defaults)
- Implemented multi-level cleanup with webhook workflow preservation
- Migrated from webhook IDs to webhook URLs configuration
- Added TypeScript type safety fixes (26 errors resolved)
- Updated test names to reflect actual n8n API behavior
Bug Fixes:
- Removed MSW from integration test setup (was blocking real API calls)
- Fixed .env loading order to preserve real credentials over test defaults
- Added type guards for undefined workflow IDs
- Fixed position arrays to use proper tuple types [number, number]
- Added literal types for executionOrder and settings values
Test Coverage:
- P0: Critical bug verification (FULL vs SHORT node type format)
- P1: Base n8n nodes (webhook, HTTP, langchain, multi-node)
- P2: Advanced features (connections, settings, expressions, error handling)
- Error scenarios (documents actual n8n API validation behavior)
- Edge cases (minimal workflows, empty connections, no settings)
Technical Improvements:
- Cleanup strategy preserves pre-activated webhook workflows
- Single webhook URL accepts all HTTP methods (GET, POST, PUT, DELETE)
- Environment-aware credential loading with validation
- Comprehensive test context for resource tracking
All 15 tests passing ✅
TypeScript: 0 errors ✅🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Complete implementation of Phase 1 foundation for n8n API integration tests.
Establishes core utilities, fixtures, and infrastructure for testing all 17 n8n API handlers against real n8n instance.
Changes:
- Add integration test environment configuration to .env.example
- Create comprehensive test utilities infrastructure:
* credentials.ts: Environment-aware credential management (local .env vs CI secrets)
* n8n-client.ts: Singleton API client wrapper with health checks
* test-context.ts: Resource tracking and automatic cleanup
* cleanup-helpers.ts: Multi-level cleanup strategies (orphaned, age-based, tag-based)
* fixtures.ts: 6 pre-built workflow templates (webhook, HTTP, multi-node, error handling, AI, expressions)
* factories.ts: Dynamic node/workflow builders with 15+ factory functions
* webhook-workflows.ts: Webhook workflow configs and setup instructions
- Add npm scripts:
* test:integration:n8n: Run n8n API integration tests
* test:cleanup:orphans: Clean up orphaned test resources
- Create cleanup script for CI/manual use
Documentation:
- Add comprehensive integration testing plan (550 lines)
- Add Phase 1 completion summary with lessons learned
Key Features:
- Automatic credential detection (CI vs local)
- Multi-level cleanup (test, suite, CI, orphan)
- 6 workflow fixtures covering common scenarios
- 15+ factory functions for dynamic test data
- Support for 4 HTTP methods (GET, POST, PUT, DELETE) via pre-activated webhook workflows
- TypeScript-first with full type safety
- Comprehensive error handling with helpful messages
Total: ~1,520 lines of production-ready code + 650 lines of documentation
Ready for Phase 2: Workflow creation tests
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>