MCPcopy Create free account
hub / github.com/ShipSecAI/studio / wouldCreateCycle

Function wouldCreateCycle

frontend/src/utils/connectionValidation.ts:176–194  ·  view source on GitHub ↗

* Detect if a connection would create a cycle

(newConnection: Connection, existingEdges: Edge[])

Source from the content-addressed store, hash-verified

174 * Detect if a connection would create a cycle
175 */
176function wouldCreateCycle(newConnection: Connection, existingEdges: Edge[]): boolean {
177 const { source, target } = newConnection;
178
179 if (!source || !target) return false;
180
181 const visited = new Set<string>();
182
183 function hasPath(from: string, to: string): boolean {
184 if (from === to) return true;
185 if (visited.has(from)) return false;
186
187 visited.add(from);
188
189 const outgoingEdges = existingEdges.filter((edge) => edge.source === from);
190 return outgoingEdges.some((edge) => hasPath(edge.target, to));
191 }
192
193 return hasPath(target, source);
194}
195
196/**
197 * Get validation warnings for a node (e.g., required inputs not connected)

Callers 1

validateConnectionFunction · 0.85

Calls 1

hasPathFunction · 0.85

Tested by

no test coverage detected