mirror of
https://github.com/Egonex-AI/Understand-Anything.git
synced 2026-06-22 10:58:03 +08:00
test: add alias chain detection guards
Ensures no alias value is itself an alias key, which would cause single-pass normalization to produce a non-canonical value that Zod then rejects. Catches this class of bug at test time. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
fd0df15d1c
commit
4b22ed7336
@@ -1,5 +1,10 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { validateGraph, normalizeGraph } from "../schema.js";
|
||||
import {
|
||||
validateGraph,
|
||||
normalizeGraph,
|
||||
NODE_TYPE_ALIASES,
|
||||
EDGE_TYPE_ALIASES,
|
||||
} from "../schema.js";
|
||||
import type { KnowledgeGraph } from "../types.js";
|
||||
|
||||
const validGraph: KnowledgeGraph = {
|
||||
@@ -239,4 +244,22 @@ describe("schema validation", () => {
|
||||
const result = validateGraph(graph);
|
||||
expect(result.success).toBe(false);
|
||||
});
|
||||
|
||||
it("NODE_TYPE_ALIASES values are never alias keys (no chains)", () => {
|
||||
for (const [alias, target] of Object.entries(NODE_TYPE_ALIASES)) {
|
||||
expect(
|
||||
NODE_TYPE_ALIASES,
|
||||
`chain detected: ${alias} → ${target} → ${NODE_TYPE_ALIASES[target]}`,
|
||||
).not.toHaveProperty(target);
|
||||
}
|
||||
});
|
||||
|
||||
it("EDGE_TYPE_ALIASES values are never alias keys (no chains)", () => {
|
||||
for (const [alias, target] of Object.entries(EDGE_TYPE_ALIASES)) {
|
||||
expect(
|
||||
EDGE_TYPE_ALIASES,
|
||||
`chain detected: ${alias} → ${target} → ${EDGE_TYPE_ALIASES[target]}`,
|
||||
).not.toHaveProperty(target);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user