diff --git a/src/lib/__tests__/graphUtils.test.ts b/src/lib/__tests__/graphUtils.test.ts index 7c0c3aa..64b2551 100644 --- a/src/lib/__tests__/graphUtils.test.ts +++ b/src/lib/__tests__/graphUtils.test.ts @@ -208,7 +208,7 @@ describe("graph traversal helpers", () => { expect(affectedEdges).toHaveLength(4); }); - it("detects cycles and marks nodes with errors", async () => { + it("detects cycles and returns true without mutating input nodes", async () => { const { checkForCyclesAndMarkErrors } = await loadGraphUtils(); const nodes = [createNode("x"), createNode("y")]; nodes.forEach((n) => (n.data.dirty = false)); @@ -217,9 +217,10 @@ describe("graph traversal helpers", () => { const hasCycle = checkForCyclesAndMarkErrors(nodes, edges); expect(hasCycle).toBe(true); + // input nodes must not be mutated – caller owns state updates nodes.forEach((node) => { - expect(node.data.error).toBe(true); - expect(node.data.extendedError).toMatch(/Cycle detected/); + expect(node.data.error).toBeUndefined(); + expect(node.data.extendedError).toBeUndefined(); }); }); }); diff --git a/src/lib/graphUtils.ts b/src/lib/graphUtils.ts index 436c3ca..043f47c 100644 --- a/src/lib/graphUtils.ts +++ b/src/lib/graphUtils.ts @@ -448,7 +448,7 @@ export function mergePartialResultsIntoFullGraph( * Flags cycles instantly so the user doesn’t have to wait for the API * to complain. * - * @returns `true` if a cycle was found (and nodes were marked with errors) + * @returns `true` if a cycle was found */ export function checkForCyclesAndMarkErrors( affectedNodes: Node[], @@ -479,14 +479,6 @@ export function checkForCyclesAndMarkErrors( } } - /* --- mark error if not all processed --------------------------------------- */ - const hasCycle = processed !== affectedNodes.length; - if (hasCycle) { - affectedNodes.forEach((n) => { - n.data.error = true; - n.data.extendedError = - "Cycle detected in this sub-graph – calculation aborted."; - }); - } - return hasCycle; + /* --- detect cycle if not all nodes were processed -------------------------- */ + return processed !== affectedNodes.length; }