fix: handleUpdateWorkflow validation bug causing all update tests to fail

**Root Cause:**
The handleUpdateWorkflow handler was validating workflow structure WITHOUT
fetching the current workflow when BOTH nodes and connections were provided.
This caused validation to fail because required fields like 'name' were missing
from the partial update data.

**The Bug:**
```typescript
// BEFORE (buggy):
if (!updateData.nodes || !updateData.connections) {
  const current = await client.getWorkflow(id);
  fullWorkflow = { ...current, ...updateData };
}
// Only fetched current workflow if ONE was missing
// When BOTH provided, fullWorkflow = updateData (missing 'name')
```

**The Fix:**
```typescript
// AFTER (fixed):
const current = await client.getWorkflow(id);
const fullWorkflow = { ...current, ...updateData };
// ALWAYS fetch current workflow for validation
// Ensures all required fields present
```

**Impact:**
- All 5 failing update tests now pass
- Validation now has complete workflow context (name, id, etc.)
- No breaking changes to API or behavior

**Tests affected:**
- Update Nodes
- Update Connections
- Update Settings
- Update Name
- Multiple Properties

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
czlonkowski
2025-10-04 16:52:29 +02:00
parent 2e19eaa309
commit fc973d83db

View File

@@ -552,16 +552,12 @@ export async function handleUpdateWorkflow(args: unknown, context?: InstanceCont
// If nodes/connections are being updated, validate the structure // If nodes/connections are being updated, validate the structure
if (updateData.nodes || updateData.connections) { if (updateData.nodes || updateData.connections) {
// Fetch current workflow if only partial update // Always fetch current workflow for validation (need all fields like name)
let fullWorkflow = updateData as Partial<Workflow>; const current = await client.getWorkflow(id);
const fullWorkflow = {
if (!updateData.nodes || !updateData.connections) { ...current,
const current = await client.getWorkflow(id); ...updateData
fullWorkflow = { };
...current,
...updateData
};
}
// Validate workflow structure (n8n API expects FULL form: n8n-nodes-base.*) // Validate workflow structure (n8n API expects FULL form: n8n-nodes-base.*)
const errors = validateWorkflowStructure(fullWorkflow); const errors = validateWorkflowStructure(fullWorkflow);