@@ -252,6 +252,58 @@ describe("canConnectPorts - data type compatibility", () => {
252252 const inPort : Port = { id : "in" , nodeId : "b" , type : "input" , label : "in" , position : "left" , dataType : "json" } ;
253253 expect ( canConnectPorts ( outPort , inPort , defA , defB ) ) . toBe ( true ) ;
254254 } ) ;
255+
256+ it ( "uses port dataType when multiple definitions share same id (instances pattern)" , ( ) => {
257+ // Simulates a node with multiple PortDefinitions that share the same id
258+ // but have different dataTypes, selected via `instances` function.
259+ // Example: artifact-io with scope-out having typed-object, object, string, binary variants
260+ const defWithMultipleSameIdPorts = baseNodeDef ( "ArtifactIO" , [
261+ { id : "scope-out" , type : "output" , label : "Scope (Typed Object)" , position : "right" , dataType : "typed-object" , instances : ( ) => 0 } ,
262+ { id : "scope-out" , type : "output" , label : "Scope (Object)" , position : "right" , dataType : "object" , instances : ( ) => 0 } ,
263+ { id : "scope-out" , type : "output" , label : "Scope (String)" , position : "right" , dataType : "string" , instances : ( ) => 1 } , // Active one
264+ { id : "scope-out" , type : "output" , label : "Scope (Binary)" , position : "right" , dataType : "binary" , instances : ( ) => 0 } ,
265+ ] ) ;
266+ const defConsumer = baseNodeDef ( "Consumer" , [
267+ { id : "in" , type : "input" , label : "in" , position : "left" , dataType : "string" } ,
268+ ] ) ;
269+
270+ // The derived Port has dataType: "string" from the active definition
271+ const derivedPort : Port = {
272+ id : "scope-out" ,
273+ definitionId : "scope-out" ,
274+ nodeId : "artifact" ,
275+ type : "output" ,
276+ label : "Scope (String)" ,
277+ position : "right" ,
278+ dataType : "string" , // Set during port derivation from active PortDefinition
279+ } ;
280+ const consumerPort : Port = {
281+ id : "in" ,
282+ nodeId : "consumer" ,
283+ type : "input" ,
284+ label : "in" ,
285+ position : "left" ,
286+ dataType : "string" ,
287+ } ;
288+
289+ // Should connect because Port.dataType is "string" (not "typed-object" from first matching definition)
290+ expect ( canConnectPorts ( derivedPort , consumerPort , defWithMultipleSameIdPorts , defConsumer ) ) . toBe ( true ) ;
291+
292+ // Verify incompatible type is rejected
293+ const binaryConsumer = baseNodeDef ( "BinaryConsumer" , [
294+ { id : "in" , type : "input" , label : "in" , position : "left" , dataType : "binary" } ,
295+ ] ) ;
296+ const binaryPort : Port = {
297+ id : "in" ,
298+ nodeId : "binary-consumer" ,
299+ type : "input" ,
300+ label : "in" ,
301+ position : "left" ,
302+ dataType : "binary" ,
303+ } ;
304+ // Should NOT connect because string !== binary
305+ expect ( canConnectPorts ( derivedPort , binaryPort , defWithMultipleSameIdPorts , binaryConsumer ) ) . toBe ( false ) ;
306+ } ) ;
255307} ) ;
256308
257309describe ( "canConnectPorts - maxConnections default/unlimited" , ( ) => {
0 commit comments