mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
fix(core): improve step ID normalization and add missing test coverage
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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}`;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user