@multiplier-labs/stepflow 0.3.1
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/.github/workflows/publish.yml +30 -0
- package/README.md +408 -0
- package/dist/chunk-FQCT3I2A.js +1512 -0
- package/dist/chunk-FQCT3I2A.js.map +1 -0
- package/dist/chunk-GXY66V7Q.js +111 -0
- package/dist/chunk-GXY66V7Q.js.map +1 -0
- package/dist/chunk-U5QGN3RT.js +715 -0
- package/dist/chunk-U5QGN3RT.js.map +1 -0
- package/dist/chunk-XCF4PLN7.js +575 -0
- package/dist/chunk-XCF4PLN7.js.map +1 -0
- package/dist/events/index.d.ts +346 -0
- package/dist/events/index.js +11 -0
- package/dist/events/index.js.map +1 -0
- package/dist/index-CPfGsmrp.d.ts +567 -0
- package/dist/index.d.ts +748 -0
- package/dist/index.js +1707 -0
- package/dist/index.js.map +1 -0
- package/dist/scheduler/index.d.ts +6 -0
- package/dist/scheduler/index.js +12 -0
- package/dist/scheduler/index.js.map +1 -0
- package/dist/storage/index.d.ts +402 -0
- package/dist/storage/index.js +13 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/types-BVShq7zT.d.ts +150 -0
- package/dist/types-BlwFEGzj.d.ts +276 -0
- package/dist/types-DzkEqnQJ.d.ts +75 -0
- package/docs/github-packages-setup.md +97 -0
- package/docs/stepflow-api-reference.md +1662 -0
- package/package.json +85 -0
- package/src/core/engine.test.ts +1421 -0
- package/src/core/engine.ts +717 -0
- package/src/core/index.ts +7 -0
- package/src/core/orchestrator.ts +590 -0
- package/src/core/types.ts +242 -0
- package/src/events/index.ts +8 -0
- package/src/events/memory.test.ts +109 -0
- package/src/events/memory.ts +95 -0
- package/src/events/socketio.test.ts +428 -0
- package/src/events/socketio.ts +269 -0
- package/src/events/types.ts +121 -0
- package/src/events/webhook.test.ts +695 -0
- package/src/events/webhook.ts +591 -0
- package/src/index.ts +270 -0
- package/src/planning/index.ts +52 -0
- package/src/planning/planner.ts +601 -0
- package/src/planning/planning.test.ts +790 -0
- package/src/planning/registry.test.ts +445 -0
- package/src/planning/registry.ts +369 -0
- package/src/planning/types.ts +570 -0
- package/src/scheduler/cron.test.ts +480 -0
- package/src/scheduler/cron.ts +449 -0
- package/src/scheduler/index.ts +18 -0
- package/src/scheduler/postgres-persistence.test.ts +906 -0
- package/src/scheduler/postgres-persistence.ts +546 -0
- package/src/scheduler/sqlite-persistence.test.ts +235 -0
- package/src/scheduler/sqlite-persistence.ts +268 -0
- package/src/scheduler/types.ts +78 -0
- package/src/storage/index.ts +27 -0
- package/src/storage/memory.test.ts +399 -0
- package/src/storage/memory.ts +248 -0
- package/src/storage/postgres.ts +1550 -0
- package/src/storage/sqlite.test.ts +593 -0
- package/src/storage/sqlite.ts +662 -0
- package/src/storage/types.ts +368 -0
- package/src/utils/errors.test.ts +152 -0
- package/src/utils/errors.ts +191 -0
- package/src/utils/id.ts +21 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/logger.test.ts +127 -0
- package/src/utils/logger.ts +96 -0
- package/src/utils/postgres-deps.ts +63 -0
- package/src/utils/retry.test.ts +197 -0
- package/src/utils/retry.ts +121 -0
- package/tsconfig.json +21 -0
- package/tsup.config.ts +14 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
MemoryStepHandlerRegistry,
|
|
4
|
+
MemoryRecipeRegistry,
|
|
5
|
+
createRegistry,
|
|
6
|
+
} from "./registry";
|
|
7
|
+
import type { Recipe, RegisteredStepHandler } from "./types";
|
|
8
|
+
|
|
9
|
+
describe("MemoryStepHandlerRegistry", () => {
|
|
10
|
+
let registry: MemoryStepHandlerRegistry;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
registry = new MemoryStepHandlerRegistry();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should register and retrieve a handler", () => {
|
|
17
|
+
const handler: RegisteredStepHandler = {
|
|
18
|
+
id: "handler.a",
|
|
19
|
+
description: "Handler A",
|
|
20
|
+
handler: async () => "result",
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
registry.register(handler);
|
|
24
|
+
|
|
25
|
+
expect(registry.get("handler.a")).toBeDefined();
|
|
26
|
+
expect(registry.get("handler.a")?.id).toBe("handler.a");
|
|
27
|
+
expect(registry.has("handler.a")).toBe(true);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("should throw on duplicate registration", () => {
|
|
31
|
+
registry.register({ id: "h1", handler: async () => {} });
|
|
32
|
+
|
|
33
|
+
expect(() =>
|
|
34
|
+
registry.register({ id: "h1", handler: async () => {} }),
|
|
35
|
+
).toThrow("Step handler 'h1' is already registered");
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("should return undefined for non-existent handler", () => {
|
|
39
|
+
expect(registry.get("nonexistent")).toBeUndefined();
|
|
40
|
+
expect(registry.has("nonexistent")).toBe(false);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should list all handlers", () => {
|
|
44
|
+
registry.register({ id: "h1", handler: async () => {} });
|
|
45
|
+
registry.register({ id: "h2", handler: async () => {} });
|
|
46
|
+
|
|
47
|
+
const list = registry.list();
|
|
48
|
+
expect(list).toHaveLength(2);
|
|
49
|
+
expect(list.map((h) => h.id).sort()).toEqual(["h1", "h2"]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("should list handlers by tag", () => {
|
|
53
|
+
registry.register({
|
|
54
|
+
id: "h1",
|
|
55
|
+
handler: async () => {},
|
|
56
|
+
tags: ["ai", "text"],
|
|
57
|
+
});
|
|
58
|
+
registry.register({ id: "h2", handler: async () => {}, tags: ["ai"] });
|
|
59
|
+
registry.register({ id: "h3", handler: async () => {}, tags: ["io"] });
|
|
60
|
+
|
|
61
|
+
const aiHandlers = registry.listByTag("ai");
|
|
62
|
+
expect(aiHandlers).toHaveLength(2);
|
|
63
|
+
expect(aiHandlers.map((h) => h.id).sort()).toEqual(["h1", "h2"]);
|
|
64
|
+
|
|
65
|
+
expect(registry.listByTag("nonexistent")).toEqual([]);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("should resolve handler reference to handler function", () => {
|
|
69
|
+
const fn = async () => "resolved";
|
|
70
|
+
registry.register({ id: "h1", handler: fn });
|
|
71
|
+
|
|
72
|
+
expect(registry.resolve("h1")).toBe(fn);
|
|
73
|
+
expect(registry.resolve("nonexistent")).toBeUndefined();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("should clear all handlers and tag indexes", () => {
|
|
77
|
+
registry.register({ id: "h1", handler: async () => {}, tags: ["t1"] });
|
|
78
|
+
registry.clear();
|
|
79
|
+
|
|
80
|
+
expect(registry.list()).toHaveLength(0);
|
|
81
|
+
expect(registry.listByTag("t1")).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe("MemoryRecipeRegistry", () => {
|
|
86
|
+
let registry: MemoryRecipeRegistry;
|
|
87
|
+
|
|
88
|
+
const makeRecipe = (overrides: Partial<Recipe> = {}): Recipe => ({
|
|
89
|
+
id: "recipe-1",
|
|
90
|
+
name: "Recipe 1",
|
|
91
|
+
workflowKind: "test.workflow",
|
|
92
|
+
variant: "default",
|
|
93
|
+
steps: [{ key: "s1", name: "S1", handlerRef: "h1" }],
|
|
94
|
+
...overrides,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
beforeEach(() => {
|
|
98
|
+
registry = new MemoryRecipeRegistry();
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
describe("register / get / has", () => {
|
|
102
|
+
it("should register and retrieve a recipe", () => {
|
|
103
|
+
const recipe = makeRecipe();
|
|
104
|
+
registry.register(recipe);
|
|
105
|
+
|
|
106
|
+
expect(registry.get("recipe-1")).toEqual(recipe);
|
|
107
|
+
expect(registry.has("recipe-1")).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("should throw on duplicate recipe id", () => {
|
|
111
|
+
registry.register(makeRecipe());
|
|
112
|
+
|
|
113
|
+
expect(() => registry.register(makeRecipe())).toThrow(
|
|
114
|
+
"Recipe 'recipe-1' is already registered",
|
|
115
|
+
);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("should throw on duplicate kind:variant", () => {
|
|
119
|
+
registry.register(makeRecipe({ id: "r1" }));
|
|
120
|
+
|
|
121
|
+
expect(() => registry.register(makeRecipe({ id: "r2" }))).toThrow(
|
|
122
|
+
"Recipe variant 'default' for 'test.workflow' is already registered",
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("should return undefined for non-existent recipe", () => {
|
|
127
|
+
expect(registry.get("nonexistent")).toBeUndefined();
|
|
128
|
+
expect(registry.has("nonexistent")).toBe(false);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe("registerAll", () => {
|
|
133
|
+
it("should register multiple recipes", () => {
|
|
134
|
+
registry.registerAll([
|
|
135
|
+
makeRecipe({ id: "r1", variant: "fast" }),
|
|
136
|
+
makeRecipe({ id: "r2", variant: "slow" }),
|
|
137
|
+
]);
|
|
138
|
+
|
|
139
|
+
expect(registry.list()).toHaveLength(2);
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("getByKind", () => {
|
|
144
|
+
it("should return recipes matching a workflow kind", () => {
|
|
145
|
+
registry.register(makeRecipe({ id: "r1", variant: "v1" }));
|
|
146
|
+
registry.register(makeRecipe({ id: "r2", variant: "v2" }));
|
|
147
|
+
registry.register(
|
|
148
|
+
makeRecipe({ id: "r3", workflowKind: "other", variant: "default" }),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const results = registry.getByKind("test.workflow");
|
|
152
|
+
expect(results).toHaveLength(2);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("should return empty array for unknown kind", () => {
|
|
156
|
+
expect(registry.getByKind("unknown")).toEqual([]);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("getVariant", () => {
|
|
161
|
+
it("should return recipe by kind and variant", () => {
|
|
162
|
+
registry.register(makeRecipe({ id: "r1", variant: "fast" }));
|
|
163
|
+
registry.register(
|
|
164
|
+
makeRecipe({ id: "r2", workflowKind: "other", variant: "default" }),
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
expect(registry.getVariant("test.workflow", "fast")?.id).toBe("r1");
|
|
168
|
+
expect(
|
|
169
|
+
registry.getVariant("test.workflow", "nonexistent"),
|
|
170
|
+
).toBeUndefined();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("getDefault", () => {
|
|
175
|
+
it('should return the "default" variant', () => {
|
|
176
|
+
registry.register(makeRecipe({ id: "r1", variant: "default" }));
|
|
177
|
+
registry.register(makeRecipe({ id: "r2", variant: "fast" }));
|
|
178
|
+
|
|
179
|
+
expect(registry.getDefault("test.workflow")?.id).toBe("r1");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it("should fall back to lowest priority recipe", () => {
|
|
183
|
+
registry.register(
|
|
184
|
+
makeRecipe({ id: "r1", variant: "fast", priority: 10 }),
|
|
185
|
+
);
|
|
186
|
+
registry.register(makeRecipe({ id: "r2", variant: "slow", priority: 1 }));
|
|
187
|
+
|
|
188
|
+
expect(registry.getDefault("test.workflow")?.id).toBe("r2");
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("should return undefined for unknown kind", () => {
|
|
192
|
+
expect(registry.getDefault("unknown")).toBeUndefined();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should handle recipes without explicit priority", () => {
|
|
196
|
+
registry.register(makeRecipe({ id: "r1", variant: "v1" }));
|
|
197
|
+
|
|
198
|
+
expect(registry.getDefault("test.workflow")?.id).toBe("r1");
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
describe("listVariants", () => {
|
|
203
|
+
it("should list all variants for a kind", () => {
|
|
204
|
+
registry.register(makeRecipe({ id: "r1", variant: "fast" }));
|
|
205
|
+
registry.register(makeRecipe({ id: "r2", variant: "slow" }));
|
|
206
|
+
|
|
207
|
+
expect(registry.listVariants("test.workflow").sort()).toEqual([
|
|
208
|
+
"fast",
|
|
209
|
+
"slow",
|
|
210
|
+
]);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("query", () => {
|
|
215
|
+
beforeEach(() => {
|
|
216
|
+
registry.register(
|
|
217
|
+
makeRecipe({ id: "r1", variant: "fast", tags: ["ai"] }),
|
|
218
|
+
);
|
|
219
|
+
registry.register(
|
|
220
|
+
makeRecipe({
|
|
221
|
+
id: "r2",
|
|
222
|
+
variant: "slow",
|
|
223
|
+
tags: ["legacy"],
|
|
224
|
+
workflowKind: "other",
|
|
225
|
+
}),
|
|
226
|
+
);
|
|
227
|
+
registry.register(
|
|
228
|
+
makeRecipe({
|
|
229
|
+
id: "r3",
|
|
230
|
+
variant: "conditional",
|
|
231
|
+
workflowKind: "other",
|
|
232
|
+
conditions: [{ field: "size", operator: "gt", value: 100 }],
|
|
233
|
+
}),
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it("should filter by workflowKind", () => {
|
|
238
|
+
const results = registry.query({ workflowKind: "other" });
|
|
239
|
+
expect(results).toHaveLength(2);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should filter by variant", () => {
|
|
243
|
+
const results = registry.query({ variant: "fast" });
|
|
244
|
+
expect(results).toHaveLength(1);
|
|
245
|
+
expect(results[0].id).toBe("r1");
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it("should filter by tags", () => {
|
|
249
|
+
const results = registry.query({ tags: ["ai"] });
|
|
250
|
+
expect(results).toHaveLength(1);
|
|
251
|
+
expect(results[0].id).toBe("r1");
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
it("should filter by matchConditions", () => {
|
|
255
|
+
const results = registry.query({ matchConditions: { size: 200 } });
|
|
256
|
+
// r1 has no conditions (passes), r2 has no conditions (passes), r3 has size > 100 (passes)
|
|
257
|
+
expect(results).toHaveLength(3);
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("should exclude recipes where conditions fail", () => {
|
|
261
|
+
const results = registry.query({ matchConditions: { size: 50 } });
|
|
262
|
+
// r3 has size > 100 which fails for 50
|
|
263
|
+
expect(results).toHaveLength(2);
|
|
264
|
+
expect(results.find((r) => r.id === "r3")).toBeUndefined();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
describe("condition evaluation", () => {
|
|
269
|
+
const registerConditional = (
|
|
270
|
+
field: string,
|
|
271
|
+
operator: string,
|
|
272
|
+
value?: unknown,
|
|
273
|
+
) => {
|
|
274
|
+
const id = `cond-${Math.random()}`;
|
|
275
|
+
registry.register(
|
|
276
|
+
makeRecipe({
|
|
277
|
+
id,
|
|
278
|
+
variant: id,
|
|
279
|
+
conditions: [{ field, operator: operator as any, value }],
|
|
280
|
+
}),
|
|
281
|
+
);
|
|
282
|
+
return id;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
it("should evaluate eq/neq", () => {
|
|
286
|
+
const eqId = registerConditional("x", "eq", 5);
|
|
287
|
+
const neqId = registerConditional("x", "neq", 5);
|
|
288
|
+
|
|
289
|
+
let results = registry.query({ matchConditions: { x: 5 } });
|
|
290
|
+
expect(results.find((r) => r.id === eqId)).toBeDefined();
|
|
291
|
+
|
|
292
|
+
results = registry.query({ matchConditions: { x: 3 } });
|
|
293
|
+
expect(results.find((r) => r.id === eqId)).toBeUndefined();
|
|
294
|
+
expect(results.find((r) => r.id === neqId)).toBeDefined();
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("should evaluate gt/gte/lt/lte", () => {
|
|
298
|
+
const gtId = registerConditional("n", "gt", 10);
|
|
299
|
+
const gteId = registerConditional("n", "gte", 10);
|
|
300
|
+
const ltId = registerConditional("n", "lt", 10);
|
|
301
|
+
const lteId = registerConditional("n", "lte", 10);
|
|
302
|
+
|
|
303
|
+
let results = registry.query({ matchConditions: { n: 15 } });
|
|
304
|
+
expect(results.find((r) => r.id === gtId)).toBeDefined();
|
|
305
|
+
expect(results.find((r) => r.id === gteId)).toBeDefined();
|
|
306
|
+
expect(results.find((r) => r.id === ltId)).toBeUndefined();
|
|
307
|
+
|
|
308
|
+
results = registry.query({ matchConditions: { n: 10 } });
|
|
309
|
+
expect(results.find((r) => r.id === gtId)).toBeUndefined();
|
|
310
|
+
expect(results.find((r) => r.id === gteId)).toBeDefined();
|
|
311
|
+
expect(results.find((r) => r.id === lteId)).toBeDefined();
|
|
312
|
+
|
|
313
|
+
results = registry.query({ matchConditions: { n: 5 } });
|
|
314
|
+
expect(results.find((r) => r.id === ltId)).toBeDefined();
|
|
315
|
+
expect(results.find((r) => r.id === lteId)).toBeDefined();
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("should return false for gt/lt with non-number values", () => {
|
|
319
|
+
const gtId = registerConditional("x", "gt", 10);
|
|
320
|
+
|
|
321
|
+
const results = registry.query({
|
|
322
|
+
matchConditions: { x: "not a number" },
|
|
323
|
+
});
|
|
324
|
+
expect(results.find((r) => r.id === gtId)).toBeUndefined();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("should evaluate contains for strings", () => {
|
|
328
|
+
const id = registerConditional("text", "contains", "hello");
|
|
329
|
+
|
|
330
|
+
let results = registry.query({
|
|
331
|
+
matchConditions: { text: "say hello world" },
|
|
332
|
+
});
|
|
333
|
+
expect(results.find((r) => r.id === id)).toBeDefined();
|
|
334
|
+
|
|
335
|
+
results = registry.query({ matchConditions: { text: "no match" } });
|
|
336
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("should evaluate contains for arrays", () => {
|
|
340
|
+
const id = registerConditional("tags", "contains", "important");
|
|
341
|
+
|
|
342
|
+
const results = registry.query({
|
|
343
|
+
matchConditions: { tags: ["important", "other"] },
|
|
344
|
+
});
|
|
345
|
+
expect(results.find((r) => r.id === id)).toBeDefined();
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("should return false for contains with non-string/non-array", () => {
|
|
349
|
+
const id = registerConditional("x", "contains", "test");
|
|
350
|
+
|
|
351
|
+
const results = registry.query({ matchConditions: { x: 42 } });
|
|
352
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
it("should evaluate matches (regex)", () => {
|
|
356
|
+
const id = registerConditional("name", "matches", "^test-\\d+$");
|
|
357
|
+
|
|
358
|
+
let results = registry.query({ matchConditions: { name: "test-123" } });
|
|
359
|
+
expect(results.find((r) => r.id === id)).toBeDefined();
|
|
360
|
+
|
|
361
|
+
results = registry.query({ matchConditions: { name: "not-matching" } });
|
|
362
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it("should return false for matches with invalid regex", () => {
|
|
366
|
+
const id = registerConditional("x", "matches", "[invalid");
|
|
367
|
+
|
|
368
|
+
const results = registry.query({ matchConditions: { x: "anything" } });
|
|
369
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("should return false for matches with non-string field", () => {
|
|
373
|
+
const id = registerConditional("x", "matches", ".*");
|
|
374
|
+
|
|
375
|
+
const results = registry.query({ matchConditions: { x: 42 } });
|
|
376
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
377
|
+
});
|
|
378
|
+
|
|
379
|
+
it("should evaluate exists/notExists", () => {
|
|
380
|
+
const existsId = registerConditional("field", "exists");
|
|
381
|
+
const notExistsId = registerConditional("field", "notExists");
|
|
382
|
+
|
|
383
|
+
let results = registry.query({ matchConditions: { field: "present" } });
|
|
384
|
+
expect(results.find((r) => r.id === existsId)).toBeDefined();
|
|
385
|
+
expect(results.find((r) => r.id === notExistsId)).toBeUndefined();
|
|
386
|
+
|
|
387
|
+
results = registry.query({ matchConditions: { field: "" } });
|
|
388
|
+
expect(results.find((r) => r.id === existsId)).toBeUndefined();
|
|
389
|
+
expect(results.find((r) => r.id === notExistsId)).toBeDefined();
|
|
390
|
+
|
|
391
|
+
results = registry.query({ matchConditions: { field: null } });
|
|
392
|
+
expect(results.find((r) => r.id === existsId)).toBeUndefined();
|
|
393
|
+
expect(results.find((r) => r.id === notExistsId)).toBeDefined();
|
|
394
|
+
|
|
395
|
+
results = registry.query({ matchConditions: {} });
|
|
396
|
+
expect(results.find((r) => r.id === existsId)).toBeUndefined();
|
|
397
|
+
expect(results.find((r) => r.id === notExistsId)).toBeDefined();
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("should handle nested field paths", () => {
|
|
401
|
+
const id = registerConditional("a.b.c", "eq", 42);
|
|
402
|
+
|
|
403
|
+
let results = registry.query({
|
|
404
|
+
matchConditions: { a: { b: { c: 42 } } },
|
|
405
|
+
});
|
|
406
|
+
expect(results.find((r) => r.id === id)).toBeDefined();
|
|
407
|
+
|
|
408
|
+
results = registry.query({ matchConditions: { a: { b: { c: 99 } } } });
|
|
409
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
it("should return undefined for missing nested path segments", () => {
|
|
413
|
+
const id = registerConditional("a.b.c", "exists");
|
|
414
|
+
|
|
415
|
+
const results = registry.query({ matchConditions: { a: "not-object" } });
|
|
416
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
it("should return false for unknown operator", () => {
|
|
420
|
+
const id = registerConditional("x", "unknownOp" as any, 1);
|
|
421
|
+
|
|
422
|
+
const results = registry.query({ matchConditions: { x: 1 } });
|
|
423
|
+
expect(results.find((r) => r.id === id)).toBeUndefined();
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
describe("clear", () => {
|
|
428
|
+
it("should clear all registries", () => {
|
|
429
|
+
registry.register(makeRecipe({ id: "r1", variant: "v1", tags: ["t1"] }));
|
|
430
|
+
registry.clear();
|
|
431
|
+
|
|
432
|
+
expect(registry.list()).toHaveLength(0);
|
|
433
|
+
expect(registry.getByKind("test.workflow")).toEqual([]);
|
|
434
|
+
expect(registry.listVariants("test.workflow")).toEqual([]);
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
describe("createRegistry", () => {
|
|
440
|
+
it("should return a combined registry", () => {
|
|
441
|
+
const reg = createRegistry();
|
|
442
|
+
expect(reg.recipes).toBeInstanceOf(MemoryRecipeRegistry);
|
|
443
|
+
expect(reg.handlers).toBeInstanceOf(MemoryStepHandlerRegistry);
|
|
444
|
+
});
|
|
445
|
+
});
|