@ai.ntellect/core 0.6.9 → 0.6.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/graph/engine.ts +1 -1
- package/package.json +1 -1
- package/test/graph/controller.test.ts +0 -182
package/graph/engine.ts
CHANGED
package/package.json
CHANGED
@@ -1,182 +0,0 @@
|
|
1
|
-
import { GraphController } from "@/graph/controller";
|
2
|
-
import { GraphDefinition } from "@/types";
|
3
|
-
import { expect } from "chai";
|
4
|
-
import { z } from "zod";
|
5
|
-
|
6
|
-
describe("Controller", () => {
|
7
|
-
// Define test schema
|
8
|
-
const TestSchema = z.object({
|
9
|
-
status: z.string(),
|
10
|
-
count: z.number(),
|
11
|
-
});
|
12
|
-
|
13
|
-
type TestState = z.infer<typeof TestSchema>;
|
14
|
-
|
15
|
-
// Sample workflow definitions
|
16
|
-
const simpleWorkflow: GraphDefinition<TestState> = {
|
17
|
-
name: "simple-workflow",
|
18
|
-
entryNode: "start",
|
19
|
-
nodes: {
|
20
|
-
start: {
|
21
|
-
name: "start",
|
22
|
-
execute: async (state: any) => ({
|
23
|
-
...state,
|
24
|
-
status: "completed",
|
25
|
-
count: state.count + 1,
|
26
|
-
}),
|
27
|
-
relationships: [],
|
28
|
-
},
|
29
|
-
},
|
30
|
-
schema: TestSchema,
|
31
|
-
};
|
32
|
-
|
33
|
-
const complexWorkflow: GraphDefinition<TestState> = {
|
34
|
-
name: "complex-workflow",
|
35
|
-
entryNode: "first",
|
36
|
-
nodes: {
|
37
|
-
first: {
|
38
|
-
name: "first",
|
39
|
-
execute: async (state: any) => ({
|
40
|
-
...state,
|
41
|
-
status: "step1",
|
42
|
-
count: state.count + 2,
|
43
|
-
}),
|
44
|
-
relationships: [],
|
45
|
-
},
|
46
|
-
},
|
47
|
-
schema: TestSchema,
|
48
|
-
};
|
49
|
-
|
50
|
-
let controller: GraphController<TestState>;
|
51
|
-
|
52
|
-
beforeEach(() => {
|
53
|
-
controller = new GraphController<TestState>();
|
54
|
-
});
|
55
|
-
|
56
|
-
describe("Basic Execution", () => {
|
57
|
-
it("should execute a single workflow successfully", async () => {
|
58
|
-
const actions = [
|
59
|
-
{
|
60
|
-
name: "simple-workflow",
|
61
|
-
parameters: [
|
62
|
-
{ name: "status", value: "initial" },
|
63
|
-
{ name: "count", value: 0 },
|
64
|
-
],
|
65
|
-
},
|
66
|
-
];
|
67
|
-
|
68
|
-
const result = await controller.run(actions, [simpleWorkflow]);
|
69
|
-
|
70
|
-
expect(result.context).to.deep.equal({
|
71
|
-
status: "completed",
|
72
|
-
count: 1,
|
73
|
-
});
|
74
|
-
});
|
75
|
-
|
76
|
-
it("should handle multiple workflows", async () => {
|
77
|
-
const actions = [
|
78
|
-
{
|
79
|
-
name: "complex-workflow",
|
80
|
-
parameters: [
|
81
|
-
{ name: "status", value: "initial" },
|
82
|
-
{ name: "count", value: 0 },
|
83
|
-
],
|
84
|
-
},
|
85
|
-
];
|
86
|
-
|
87
|
-
const result = await controller.run(actions, [
|
88
|
-
simpleWorkflow,
|
89
|
-
complexWorkflow,
|
90
|
-
]);
|
91
|
-
|
92
|
-
expect(result.context).to.deep.equal({
|
93
|
-
status: "step1",
|
94
|
-
count: 2,
|
95
|
-
});
|
96
|
-
});
|
97
|
-
});
|
98
|
-
|
99
|
-
describe("Error Handling", () => {
|
100
|
-
it("should throw error when no actions provided", async () => {
|
101
|
-
try {
|
102
|
-
await controller.run([], [simpleWorkflow]);
|
103
|
-
expect.fail("Should have thrown an error");
|
104
|
-
} catch (error) {
|
105
|
-
expect((error as Error).message).to.equal("No actions provided");
|
106
|
-
}
|
107
|
-
});
|
108
|
-
|
109
|
-
it("should throw error when workflow not found", async () => {
|
110
|
-
const actions = [
|
111
|
-
{
|
112
|
-
name: "non-existent-workflow",
|
113
|
-
parameters: [
|
114
|
-
{ name: "status", value: "initial" },
|
115
|
-
{ name: "count", value: 0 },
|
116
|
-
],
|
117
|
-
},
|
118
|
-
];
|
119
|
-
|
120
|
-
try {
|
121
|
-
await controller.run(actions, [simpleWorkflow]);
|
122
|
-
expect.fail("Should have thrown an error");
|
123
|
-
} catch (error) {
|
124
|
-
expect((error as Error).message).to.equal(
|
125
|
-
"Graph not found: non-existent-workflow"
|
126
|
-
);
|
127
|
-
}
|
128
|
-
});
|
129
|
-
});
|
130
|
-
|
131
|
-
describe("Parameter Handling", () => {
|
132
|
-
it("should correctly process workflow parameters", async () => {
|
133
|
-
const actions = [
|
134
|
-
{
|
135
|
-
name: "simple-workflow",
|
136
|
-
parameters: [
|
137
|
-
{ name: "status", value: "custom-initial" },
|
138
|
-
{ name: "count", value: 10 },
|
139
|
-
],
|
140
|
-
},
|
141
|
-
];
|
142
|
-
|
143
|
-
const result = await controller.run(actions, [simpleWorkflow]);
|
144
|
-
|
145
|
-
expect(result.context).to.deep.equal({
|
146
|
-
status: "completed",
|
147
|
-
count: 11,
|
148
|
-
});
|
149
|
-
});
|
150
|
-
});
|
151
|
-
|
152
|
-
describe("Multiple Actions", () => {
|
153
|
-
it("should process the first action only", async () => {
|
154
|
-
const actions = [
|
155
|
-
{
|
156
|
-
name: "simple-workflow",
|
157
|
-
parameters: [
|
158
|
-
{ name: "status", value: "initial" },
|
159
|
-
{ name: "count", value: 0 },
|
160
|
-
],
|
161
|
-
},
|
162
|
-
{
|
163
|
-
name: "complex-workflow",
|
164
|
-
parameters: [
|
165
|
-
{ name: "status", value: "initial" },
|
166
|
-
{ name: "count", value: 5 },
|
167
|
-
],
|
168
|
-
},
|
169
|
-
];
|
170
|
-
|
171
|
-
const result = await controller.run(actions, [
|
172
|
-
simpleWorkflow,
|
173
|
-
complexWorkflow,
|
174
|
-
]);
|
175
|
-
|
176
|
-
expect(result.context).to.deep.equal({
|
177
|
-
status: "completed",
|
178
|
-
count: 1,
|
179
|
-
});
|
180
|
-
});
|
181
|
-
});
|
182
|
-
});
|