mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
chore(dashboard): address Task 4 review minors
- Length-prefix the inter-container bucket key to eliminate collision risk when container ids contain the separator (e.g. folder names with spaces). Adds a regression test. - Rename AggregatedContainerEdge.types -> edgeTypes for symmetry with the existing LayerEdgeAggregation.edgeTypes field. - Drop the as-cast in the test helper by giving it the real EdgeType literal type and a complete object shape. - Reword the JSDoc to match what the function actually does (silently drop unmapped endpoints; callers needing strict can pre-filter). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+20
-4
@@ -1,9 +1,12 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { aggregateContainerEdges } from "../edgeAggregation";
|
||||
import type { GraphEdge } from "@understand-anything/core/types";
|
||||
import type { GraphEdge, EdgeType } from "@understand-anything/core/types";
|
||||
|
||||
const ce = (source: string, target: string, type: string = "calls"): GraphEdge =>
|
||||
({ source, target, type }) as GraphEdge;
|
||||
const ce = (source: string, target: string, type: EdgeType = "calls"): GraphEdge => ({
|
||||
source,
|
||||
target,
|
||||
type,
|
||||
});
|
||||
|
||||
describe("aggregateContainerEdges", () => {
|
||||
it("returns empty arrays for empty input", () => {
|
||||
@@ -36,7 +39,7 @@ describe("aggregateContainerEdges", () => {
|
||||
expect(agg.sourceContainerId).toBe("auth");
|
||||
expect(agg.targetContainerId).toBe("cart");
|
||||
expect(agg.count).toBe(3);
|
||||
expect(agg.types.sort()).toEqual(["calls", "imports"]);
|
||||
expect(agg.edgeTypes.sort()).toEqual(["calls", "imports"]);
|
||||
});
|
||||
|
||||
it("treats opposite directions as separate aggregated edges", () => {
|
||||
@@ -58,4 +61,17 @@ describe("aggregateContainerEdges", () => {
|
||||
expect(r.intraContainer).toEqual([]);
|
||||
expect(r.interContainerAggregated).toEqual([]);
|
||||
});
|
||||
|
||||
it("does not collide when container ids contain the separator character", () => {
|
||||
// Pre-fix: key was `${sc} ${tc}` so `("x y", "z")` and `("x", "y z")`
|
||||
// would both map to `"x y z"`. Length-prefix on source prevents this.
|
||||
const m = new Map([
|
||||
["a", "x y"],
|
||||
["b", "z"],
|
||||
["c", "x"],
|
||||
["d", "y z"],
|
||||
]);
|
||||
const r = aggregateContainerEdges([ce("a", "b"), ce("c", "d")], m);
|
||||
expect(r.interContainerAggregated).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user