mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
feat(core): add domain/flow/step prefixes to node ID normalization
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
@@ -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<string, string> = {
|
||||
@@ -18,6 +19,9 @@ const TYPE_TO_PREFIX: Record<string, string> = {
|
||||
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}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user