Skip to content

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

fix(core): improve step ID normalization and add missing test coverage

Lum1104005758b92230
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
index 77bd37f3..54c90f93 100644
--- a/understand-anything-plugin/packages/core/src/__tests__/domain-normalize.test.ts
+++ b/understand-anything-plugin/packages/core/src/__tests__/domain-normalize.test.ts
@@ -1,7 +1,7 @@
import { describe, it, expect } from "vitest";
import { normalizeNodeId } from "../analyzer/normalize-graph.js";
-describe("domain node ID normalization", () => {
+describe("normalizeNodeId — domain types", () => {
it("normalizes domain node IDs", () => {
const result = normalizeNodeId("domain:order-management", {
type: "domain",
@@ -34,4 +34,13 @@ describe("domain node ID normalization", () => {
});
expect(result).toBe("step:validate");
});
+
+ it("normalizes bare step name with filePath", () => {
+ const result = normalizeNodeId("validate", {
+ type: "step",
+ name: "Validate",
+ filePath: "src/validators/order.ts",
+ });
+ expect(result).toBe("step:src/validators/order.ts: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 f8c76981..6d71c44d 100644
--- a/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts
+++ b/understand-anything-plugin/packages/core/src/analyzer/normalize-graph.ts
@@ -72,7 +72,11 @@ export function normalizeNodeId(
const { prefix, path } = stripToValidPrefix(trimmed);
if (prefix) {
- // For step nodes with filePath, reconstruct as step:filePath:stepSlug
+ // For step nodes with filePath, reconstruct as step:filePath:stepSlug.
+ // This intentionally drops the flow slug (e.g. "create-order" in
+ // "step:create-order:validate") — the normalized form anchors to
+ // file paths instead of flow parentage, so the ID is stable across
+ // renames of the parent flow.
if (node.type === "step" && node.filePath) {
// Use the last colon-separated segment of the path as the step slug
const lastColon = path.lastIndexOf(":");
@@ -92,6 +96,11 @@ export function normalizeNodeId(
) {
return `${expectedPrefix}:${node.filePath}:${node.name}`;
}
+ // For step nodes with filePath, reconstruct as step:filePath:slug
+ if (node.type === "step" && node.filePath) {
+ const slug = path.toLowerCase().replace(/\s+/g, "-");
+ return `${expectedPrefix}:${node.filePath}:${slug}`;
+ }
return `${expectedPrefix}:${path}`;
}