diff --git a/understand-anything-plugin/packages/core/src/__tests__/domain-normalize.test.ts b/understand-anything-plugin/packages/core/src/__tests__/domain-normalize.test.ts new file mode 100644 index 0000000..77bd37f --- /dev/null +++ b/understand-anything-plugin/packages/core/src/__tests__/domain-normalize.test.ts @@ -0,0 +1,37 @@ +import { describe, it, expect } from "vitest"; +import { normalizeNodeId } from "../analyzer/normalize-graph.js"; + +describe("domain node ID normalization", () => { + it("normalizes domain node IDs", () => { + const result = normalizeNodeId("domain:order-management", { + type: "domain", + name: "Order Management", + }); + expect(result).toBe("domain:order-management"); + }); + + it("normalizes flow node IDs", () => { + const result = normalizeNodeId("flow:create-order", { + type: "flow", + name: "Create Order", + }); + expect(result).toBe("flow:create-order"); + }); + + it("normalizes step node IDs with filePath", () => { + const result = normalizeNodeId("step:create-order:validate", { + type: "step", + name: "Validate", + filePath: "src/validators/order.ts", + }); + expect(result).toBe("step:src/validators/order.ts:validate"); + }); + + it("normalizes step node IDs without filePath", () => { + const result = normalizeNodeId("step:validate", { + type: "step", + name: "Validate", + }); + expect(result).toBe("step:validate"); + }); +}); diff --git a/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts b/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts index 9409693..f8c7698 100644 --- a/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts +++ b/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts @@ -2,6 +2,7 @@ const VALID_PREFIXES = new Set([ "file", "func", "class", "module", "concept", "config", "document", "service", "table", "endpoint", "pipeline", "schema", "resource", + "domain", "flow", "step", ]); const TYPE_TO_PREFIX: Record = { @@ -18,6 +19,9 @@ const TYPE_TO_PREFIX: Record = { pipeline: "pipeline", schema: "schema", resource: "resource", + domain: "domain", + flow: "flow", + step: "step", }; /** @@ -68,6 +72,13 @@ export function normalizeNodeId( const { prefix, path } = stripToValidPrefix(trimmed); if (prefix) { + // For step nodes with filePath, reconstruct as step:filePath:stepSlug + if (node.type === "step" && node.filePath) { + // Use the last colon-separated segment of the path as the step slug + const lastColon = path.lastIndexOf(":"); + const stepSlug = lastColon >= 0 ? path.slice(lastColon + 1) : path; + return `${prefix}:${node.filePath}:${stepSlug}`; + } return `${prefix}:${path}`; }