-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathgeneric-ai-nodes.test.ts
More file actions
96 lines (86 loc) · 2.86 KB
/
Copy pathgeneric-ai-nodes.test.ts
File metadata and controls
96 lines (86 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { describe, it, expect } from "vitest";
import {
GENERIC_AI_NODES,
resolveAvailableGenericNodes,
type GenericNodeCapability
} from "../src/prompts/workflow-authoring-knowledge.js";
import type { NodeMetadata } from "@nodetool-ai/node-sdk";
const VALID_CAPABILITIES: GenericNodeCapability[] = [
"text_to_image",
"image_to_image",
"text_to_video",
"image_to_video",
"reference_to_video",
"text_to_speech",
"automatic_speech_recognition",
"generate_embedding",
"generate_message"
];
function stubMeta(node_type: string): NodeMetadata {
return {
title: node_type,
description: "",
namespace: node_type.split(".").slice(0, -1).join("."),
node_type,
properties: [],
outputs: []
};
}
/** Registry that only knows the given node types via getMetadata. */
function lookupOf(known: string[]) {
const set = new Set(known);
return {
getMetadata: (t: string): NodeMetadata | undefined =>
set.has(t) ? stubMeta(t) : undefined
};
}
describe("GENERIC_AI_NODES catalog", () => {
it("has unique node types", () => {
const types = GENERIC_AI_NODES.map((n) => n.type);
expect(new Set(types).size).toBe(types.length);
});
it("uses only known capabilities", () => {
for (const node of GENERIC_AI_NODES) {
expect(VALID_CAPABILITIES).toContain(node.capability);
}
});
it("only the Agent step declines a model property", () => {
for (const node of GENERIC_AI_NODES) {
if (node.type === "nodetool.agents.Agent") {
expect(node.acceptsModel).toBe(false);
} else {
expect(node.acceptsModel).toBe(true);
}
}
});
});
describe("resolveAvailableGenericNodes", () => {
it("returns the full catalog when the registry can't be introspected", () => {
const { available, missing } = resolveAvailableGenericNodes(
{} as Record<string, never>
);
expect(available).toEqual([...GENERIC_AI_NODES]);
expect(missing).toEqual([]);
});
it("returns the full catalog when the registry knows none of them", () => {
const { available, missing } = resolveAvailableGenericNodes(lookupOf([]));
expect(available).toEqual([...GENERIC_AI_NODES]);
expect(missing).toEqual([]);
});
it("drops nodes the registry lacks and reports them as missing", () => {
const present = GENERIC_AI_NODES.slice(0, 2).map((n) => n.type);
const { available, missing } = resolveAvailableGenericNodes(
lookupOf(present)
);
expect(available.map((n) => n.type)).toEqual(present);
expect(missing).toEqual(
GENERIC_AI_NODES.slice(2).map((n) => n.type)
);
});
it("returns no missing when the registry has every catalog node", () => {
const all = GENERIC_AI_NODES.map((n) => n.type);
const { available, missing } = resolveAvailableGenericNodes(lookupOf(all));
expect(available.map((n) => n.type)).toEqual(all);
expect(missing).toEqual([]);
});
});