fix(diff-engine): scope addConnection duplicate check to sourceIndex (#738)#750
Open
SAY-5 wants to merge 1 commit intoczlonkowski:mainfrom
Open
fix(diff-engine): scope addConnection duplicate check to sourceIndex (#738)#750SAY-5 wants to merge 1 commit intoczlonkowski:mainfrom
SAY-5 wants to merge 1 commit intoczlonkowski:mainfrom
Conversation
…zlonkowski#738) Closes czlonkowski#738. `validateAddConnection` checked uniqueness on (source, sourceOutput, target) only, scanning the entire `existing: Connection[][]` array across all sourceIndex slots. Two outputs of a Switch node fanning into the same target node — e.g. several branches sharing a fallback / error handler, the original bug report's setup — got rejected with 'Connection already exists' even though (source, sourceIndex=N, target) wasn't actually a duplicate. Fix: resolve sourceIndex via resolveSmartParameters (same helper applyAddConnection / rewire already use, which honours sourceIndex, case=, branch=, and the numeric-sourceOutput remap from czlonkowski#537/czlonkowski#659) and only check the existing[sourceIndex] slot. The error message now also reports the offending sourceIndex so callers can spot a genuine duplicate vs. an unrelated index. Tests - New 'should allow connecting different sourceIndex outputs to the same target (czlonkowski#738)': pre-wire Slack -> HTTP at index 0, addConnection at index 1, expect success and both indices populated. - New 'should still reject duplicate connections at the same sourceIndex (czlonkowski#738)': re-add the same edge at the same index, expect 'Connection already exists' AND 'sourceIndex=0' in the message. - Existing 'should reject duplicate connections' still passes — the default sourceIndex 0 path is unchanged. Verified locally: `npx vitest run tests/unit/services/workflow-diff-engine.test.ts -t addConnection` runs 7 passing tests; reverting the validation block to the old (sourceIndex-blind) version makes both new czlonkowski#738 tests fail. Signed-off-by: SAY-5 <say.apm35@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #738.
What
validateAddConnectionchecked uniqueness on(source, sourceOutput, target)only, scanning the entireexisting: Connection[][]arrayacross all
sourceIndexslots. Two outputs of a Switch node fanninginto the same target node — e.g. several branches sharing a
fallback / error handler, exactly the scenario in the bug report — got
rejected with
Connection already existseven though(source, sourceIndex=N, target)wasn't actually a duplicate.Fix
validateAddConnectionnow:sourceIndexviaresolveSmartParameters, the same helperapplyAddConnectionand rewire already use (it honourssourceIndex,case=,branch=, and the numeric-sourceOutput remap fromaddConnection operation creates malformed connection types for multi-output nodes (IF, Switch) #537 / addConnection creates broken connections with "type": "0" instead of "type": "main" #659);
existing[sourceIndex]slot for the target;sourceIndexin the error message so callerscan distinguish a genuine duplicate from an unrelated index.
Tests
tests/unit/services/workflow-diff-engine.test.ts:should allow connecting different sourceIndex outputs to the same target (#738): pre-wiresSlack -> HTTP RequestatsourceIndex=0;addConnectionatsourceIndex=1is accepted; theresulting workflow has both indices populated.
should still reject duplicate connections at the same sourceIndex (#738): re-adding the same edge at the same index stillerrors with
Connection already existsand now includessourceIndex=0in the message.should reject duplicate connectionscontinues topass — the default-sourceIndex-0 path is unchanged.
Verification
npx vitest run tests/unit/services/workflow-diff-engine.test.ts -t addConnection→ 7 passing tests.
the old sourceIndex-blind code makes both new addConnection throws "Connection already exists" when connecting multiple Switch outputs to same target node #738 tests fail —
i.e. the new tests catch the regression cleanly.