diff --git a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/edgeAggregation.test.ts b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/edgeAggregation.test.ts index f5196c33..b1df2dc4 100644 --- a/understand-anything-plugin/packages/dashboard/src/utils/__tests__/edgeAggregation.test.ts +++ b/understand-anything-plugin/packages/dashboard/src/utils/__tests__/edgeAggregation.test.ts @@ -1,6 +1,15 @@ import { describe, it, expect } from "vitest"; -import { aggregateContainerEdges } from "../edgeAggregation"; -import type { GraphEdge, EdgeType } from "@understand-anything/core/types"; +import { + aggregateContainerEdges, + aggregateLayerEdges, + computePortals, +} from "../edgeAggregation"; +import type { + GraphEdge, + EdgeType, + KnowledgeGraph, + Layer, +} from "@understand-anything/core/types"; const ce = (source: string, target: string, type: EdgeType = "calls"): GraphEdge => ({ source, @@ -10,6 +19,29 @@ const ce = (source: string, target: string, type: EdgeType = "calls"): GraphEdge weight: 1, }); +const makeGraph = (layers: Layer[], edges: GraphEdge[]): KnowledgeGraph => ({ + version: "1.0.0", + project: { + name: "test", + languages: [], + frameworks: [], + description: "", + analyzedAt: "", + gitCommitHash: "", + }, + nodes: [], + edges, + layers, + tour: [], +}); + +const layer = (id: string, nodeIds: string[]): Layer => ({ + id, + name: id, + description: "", + nodeIds, +}); + describe("aggregateContainerEdges", () => { it("returns empty arrays for empty input", () => { const r = aggregateContainerEdges([], new Map()); @@ -77,3 +109,27 @@ describe("aggregateContainerEdges", () => { expect(r.interContainerAggregated).toHaveLength(2); }); }); + +describe("aggregateLayerEdges / computePortals", () => { + it("does not collide when layer ids contain the '|' separator character", () => { + // Pre-fix: key was `${a}|${b}` so the sorted pair ("x|y","z") -> "x|y|z" + // and the sorted pair ("x","y|z") -> "x|y|z" both map to one key, + // silently dropping one layer-edge. Length-prefixing the first id fixes it. + const graph = makeGraph( + [ + layer("x|y", ["a"]), + layer("z", ["b"]), + layer("x", ["c"]), + layer("y|z", ["d"]), + ], + [ce("a", "b"), ce("c", "d")], + ); + + expect(aggregateLayerEdges(graph)).toHaveLength(2); + + const portals = computePortals(graph, "x"); + expect(portals).toHaveLength(1); + expect(portals[0].layerId).toBe("y|z"); + expect(portals[0].connectionCount).toBe(1); + }); +}); diff --git a/understand-anything-plugin/packages/dashboard/src/utils/edgeAggregation.ts b/understand-anything-plugin/packages/dashboard/src/utils/edgeAggregation.ts index 3e47a7e6..a7343385 100644 Binary files a/understand-anything-plugin/packages/dashboard/src/utils/edgeAggregation.ts and b/understand-anything-plugin/packages/dashboard/src/utils/edgeAggregation.ts differ