@elevasis/core 0.20.0 → 0.22.0
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/dist/index.d.ts +524 -6
- package/dist/index.js +417 -42
- package/dist/knowledge/index.d.ts +151 -1
- package/dist/organization-model/index.d.ts +524 -6
- package/dist/organization-model/index.js +417 -42
- package/dist/test-utils/index.d.ts +270 -1
- package/dist/test-utils/index.js +407 -41
- package/package.json +5 -5
- package/src/_gen/__tests__/__snapshots__/contracts.md.snap +501 -303
- package/src/auth/multi-tenancy/permissions.ts +20 -8
- package/src/business/README.md +2 -2
- package/src/business/acquisition/api-schemas.test.ts +198 -0
- package/src/business/acquisition/api-schemas.ts +250 -9
- package/src/business/acquisition/build-templates.test.ts +28 -0
- package/src/business/acquisition/build-templates.ts +20 -8
- package/src/business/acquisition/index.ts +12 -0
- package/src/business/acquisition/types.ts +6 -1
- package/src/business/clients/api-schemas.test.ts +115 -0
- package/src/business/clients/api-schemas.ts +158 -0
- package/src/business/clients/index.ts +1 -0
- package/src/business/deals/api-schemas.ts +8 -0
- package/src/business/index.ts +5 -2
- package/src/business/projects/types.ts +19 -0
- package/src/execution/engine/__tests__/fixtures/test-agents.ts +10 -8
- package/src/execution/engine/agent/core/__tests__/agent.test.ts +16 -12
- package/src/execution/engine/agent/core/__tests__/error-passthrough.test.ts +4 -3
- package/src/execution/engine/agent/core/types.ts +25 -15
- package/src/execution/engine/agent/index.ts +6 -4
- package/src/execution/engine/agent/reasoning/__tests__/request-builder.test.ts +24 -18
- package/src/execution/engine/index.ts +3 -0
- package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.test.ts +55 -0
- package/src/execution/engine/tools/integration/server/adapters/apify/apify-adapter.ts +107 -41
- package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.test.ts +48 -0
- package/src/execution/engine/tools/integration/server/adapters/apollo/apollo-adapter.ts +99 -0
- package/src/execution/engine/tools/integration/server/adapters/apollo/index.ts +1 -0
- package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.test.ts +18 -0
- package/src/execution/engine/tools/integration/server/adapters/clickup/clickup-adapter.ts +194 -0
- package/src/execution/engine/tools/integration/server/adapters/clickup/index.ts +7 -0
- package/src/execution/engine/workflow/types.ts +7 -0
- package/src/integrations/credentials/api-schemas.ts +21 -2
- package/src/integrations/credentials/schemas.ts +200 -164
- package/src/organization-model/README.md +10 -3
- package/src/organization-model/__tests__/defaults.test.ts +6 -0
- package/src/organization-model/__tests__/domains/resources.test.ts +188 -0
- package/src/organization-model/__tests__/domains/roles.test.ts +402 -347
- package/src/organization-model/__tests__/domains/systems.test.ts +193 -0
- package/src/organization-model/__tests__/knowledge.test.ts +39 -0
- package/src/organization-model/__tests__/prospecting-ssot.test.ts +7 -4
- package/src/organization-model/__tests__/resolve.test.ts +1 -1
- package/src/organization-model/defaults.ts +24 -3
- package/src/organization-model/domains/knowledge.ts +3 -2
- package/src/organization-model/domains/prospecting.ts +182 -25
- package/src/organization-model/domains/resources.ts +88 -0
- package/src/organization-model/domains/roles.ts +93 -55
- package/src/organization-model/domains/sales.ts +24 -3
- package/src/organization-model/domains/systems.ts +46 -0
- package/src/organization-model/icons.ts +1 -0
- package/src/organization-model/index.ts +2 -0
- package/src/organization-model/organization-model.mdx +33 -14
- package/src/organization-model/published.ts +52 -1
- package/src/organization-model/schema.ts +121 -0
- package/src/organization-model/types.ts +46 -1
- package/src/platform/api/types.ts +38 -35
- package/src/platform/constants/versions.ts +1 -1
- package/src/platform/registry/__tests__/resource-registry.test.ts +2051 -2005
- package/src/platform/registry/__tests__/validation.test.ts +1343 -1086
- package/src/platform/registry/index.ts +14 -0
- package/src/platform/registry/resource-registry.ts +40 -2
- package/src/platform/registry/serialization.ts +241 -202
- package/src/platform/registry/serialized-types.ts +1 -0
- package/src/platform/registry/types.ts +411 -361
- package/src/platform/registry/validation.ts +743 -513
- package/src/projects/api-schemas.ts +290 -267
- package/src/reference/_generated/contracts.md +501 -303
- package/src/reference/glossary.md +8 -3
- package/src/server.ts +2 -0
- package/src/supabase/database.types.ts +121 -0
|
@@ -1,1086 +1,1343 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Test: Registry Validation Utilities
|
|
3
|
-
* Tests for ExecutionInterface-to-inputSchema validation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, it, expect } from 'vitest'
|
|
7
|
-
import { z } from 'zod'
|
|
8
|
-
import { validateExecutionInterface, RegistryValidationError } from '../validation'
|
|
9
|
-
import { ResourceRegistry } from '../resource-registry'
|
|
10
|
-
import type { WorkflowDefinition } from '../../../execution/engine/workflow/types'
|
|
11
|
-
import type { AgentDefinition } from '../../../execution/engine/agent/core/types'
|
|
12
|
-
import type { OrganizationRegistry } from '../resource-registry'
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
{ name: '
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{ name: '
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
{ name: '
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
{ name: '
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
{ name: '
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
{ name: '
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
})
|
|
364
|
-
|
|
365
|
-
it('
|
|
366
|
-
const
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
}
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
}
|
|
802
|
-
]
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
const
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
]
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
const registry: OrganizationRegistry = {
|
|
1021
|
-
'test-org': {
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Test: Registry Validation Utilities
|
|
3
|
+
* Tests for ExecutionInterface-to-inputSchema validation
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { afterEach, describe, it, expect, vi } from 'vitest'
|
|
7
|
+
import { z } from 'zod'
|
|
8
|
+
import { validateExecutionInterface, validateResourceGovernance, RegistryValidationError } from '../validation'
|
|
9
|
+
import { ResourceRegistry } from '../resource-registry'
|
|
10
|
+
import type { WorkflowDefinition } from '../../../execution/engine/workflow/types'
|
|
11
|
+
import type { AgentDefinition } from '../../../execution/engine/agent/core/types'
|
|
12
|
+
import type { OrganizationRegistry } from '../resource-registry'
|
|
13
|
+
import type { ResourceEntry } from '../../../organization-model/domains/resources'
|
|
14
|
+
|
|
15
|
+
describe('validateExecutionInterface', () => {
|
|
16
|
+
describe('required field validation', () => {
|
|
17
|
+
it('should pass when all required schema fields have form fields', () => {
|
|
18
|
+
const inputSchema = z.object({
|
|
19
|
+
name: z.string(),
|
|
20
|
+
email: z.string()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
const executionInterface = {
|
|
24
|
+
form: {
|
|
25
|
+
fields: [
|
|
26
|
+
{ name: 'name', required: true },
|
|
27
|
+
{ name: 'email', required: true }
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
expect(() => {
|
|
33
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
34
|
+
}).not.toThrow()
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('should throw when required schema field is missing from form', () => {
|
|
38
|
+
const inputSchema = z.object({
|
|
39
|
+
name: z.string(),
|
|
40
|
+
email: z.string()
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const executionInterface = {
|
|
44
|
+
form: {
|
|
45
|
+
fields: [
|
|
46
|
+
{ name: 'name', required: true }
|
|
47
|
+
// Missing 'email' field
|
|
48
|
+
]
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
expect(() => {
|
|
53
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
54
|
+
}).toThrow(RegistryValidationError)
|
|
55
|
+
expect(() => {
|
|
56
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
57
|
+
}).toThrow('missing required field "email"')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('should throw when form field is not marked required but schema field is required', () => {
|
|
61
|
+
const inputSchema = z.object({
|
|
62
|
+
name: z.string() // Required
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
const executionInterface = {
|
|
66
|
+
form: {
|
|
67
|
+
fields: [
|
|
68
|
+
{ name: 'name', required: false } // Not marked required
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
expect(() => {
|
|
74
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
75
|
+
}).toThrow(RegistryValidationError)
|
|
76
|
+
expect(() => {
|
|
77
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
78
|
+
}).toThrow('should be required')
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('should pass when optional schema field is missing from form', () => {
|
|
82
|
+
const inputSchema = z.object({
|
|
83
|
+
name: z.string(),
|
|
84
|
+
description: z.string().optional()
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const executionInterface = {
|
|
88
|
+
form: {
|
|
89
|
+
fields: [
|
|
90
|
+
{ name: 'name', required: true }
|
|
91
|
+
// 'description' is optional, so OK to omit
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
expect(() => {
|
|
97
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
98
|
+
}).not.toThrow()
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('should pass when optional schema field has non-required form field', () => {
|
|
102
|
+
const inputSchema = z.object({
|
|
103
|
+
name: z.string(),
|
|
104
|
+
description: z.string().optional()
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
const executionInterface = {
|
|
108
|
+
form: {
|
|
109
|
+
fields: [
|
|
110
|
+
{ name: 'name', required: true },
|
|
111
|
+
{ name: 'description', required: false }
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
expect(() => {
|
|
117
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
118
|
+
}).not.toThrow()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('field mapping validation', () => {
|
|
123
|
+
it('should pass with valid field mappings', () => {
|
|
124
|
+
const inputSchema = z.object({
|
|
125
|
+
taskName: z.string(),
|
|
126
|
+
priority: z.string()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
const executionInterface = {
|
|
130
|
+
form: {
|
|
131
|
+
fields: [
|
|
132
|
+
{ name: 'task_name', required: true },
|
|
133
|
+
{ name: 'prio', required: true }
|
|
134
|
+
],
|
|
135
|
+
fieldMappings: {
|
|
136
|
+
task_name: 'taskName',
|
|
137
|
+
prio: 'priority'
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
expect(() => {
|
|
143
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
144
|
+
}).not.toThrow()
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should throw when field mapping points to non-existent schema field', () => {
|
|
148
|
+
const inputSchema = z.object({
|
|
149
|
+
name: z.string()
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
// Include a valid mapping for 'name' so we get past the required field check,
|
|
153
|
+
// then add an extra field that maps to a non-existent schema field
|
|
154
|
+
const executionInterface = {
|
|
155
|
+
form: {
|
|
156
|
+
fields: [
|
|
157
|
+
{ name: 'userName', required: true },
|
|
158
|
+
{ name: 'extraField', required: false }
|
|
159
|
+
],
|
|
160
|
+
fieldMappings: {
|
|
161
|
+
userName: 'name', // Valid mapping
|
|
162
|
+
extraField: 'nonExistentField' // Invalid mapping
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
expect(() => {
|
|
168
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
169
|
+
}).toThrow(RegistryValidationError)
|
|
170
|
+
expect(() => {
|
|
171
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
172
|
+
}).toThrow('maps to non-existent schema field "nonExistentField"')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
it('should throw when form field without mapping has no matching schema field', () => {
|
|
176
|
+
const inputSchema = z.object({
|
|
177
|
+
name: z.string()
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
const executionInterface = {
|
|
181
|
+
form: {
|
|
182
|
+
fields: [
|
|
183
|
+
{ name: 'name', required: true },
|
|
184
|
+
{ name: 'unknownField', required: false }
|
|
185
|
+
]
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
expect(() => {
|
|
190
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
191
|
+
}).toThrow(RegistryValidationError)
|
|
192
|
+
expect(() => {
|
|
193
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
194
|
+
}).toThrow('maps to non-existent schema field "unknownField"')
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('should throw with flatten suggestion when form field uses nested notation', () => {
|
|
198
|
+
const inputSchema = z.object({
|
|
199
|
+
name: z.string()
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
const executionInterface = {
|
|
203
|
+
form: {
|
|
204
|
+
fields: [
|
|
205
|
+
{ name: 'name', required: true },
|
|
206
|
+
{ name: 'criteria.targetTitles', required: true }
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
expect(() => {
|
|
212
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
213
|
+
}).toThrow(RegistryValidationError)
|
|
214
|
+
expect(() => {
|
|
215
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
216
|
+
}).toThrow('uses nested notation')
|
|
217
|
+
expect(() => {
|
|
218
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
219
|
+
}).toThrow('Flatten the inputSchema')
|
|
220
|
+
})
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
describe('default values (effectively optional)', () => {
|
|
224
|
+
it('should treat fields with defaults as optional', () => {
|
|
225
|
+
const inputSchema = z.object({
|
|
226
|
+
name: z.string(),
|
|
227
|
+
priority: z.string().default('medium')
|
|
228
|
+
})
|
|
229
|
+
|
|
230
|
+
const executionInterface = {
|
|
231
|
+
form: {
|
|
232
|
+
fields: [
|
|
233
|
+
{ name: 'name', required: true }
|
|
234
|
+
// 'priority' has default, so OK to omit
|
|
235
|
+
]
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
expect(() => {
|
|
240
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
241
|
+
}).not.toThrow()
|
|
242
|
+
})
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
describe('enum fields', () => {
|
|
246
|
+
it('should validate enum fields correctly', () => {
|
|
247
|
+
const inputSchema = z.object({
|
|
248
|
+
priority: z.enum(['low', 'medium', 'high'])
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
const executionInterface = {
|
|
252
|
+
form: {
|
|
253
|
+
fields: [{ name: 'priority', required: true }]
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
expect(() => {
|
|
258
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
259
|
+
}).not.toThrow()
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
describe('empty schema', () => {
|
|
264
|
+
it('should pass with empty schema and no form fields', () => {
|
|
265
|
+
const inputSchema = z.object({})
|
|
266
|
+
|
|
267
|
+
const executionInterface = {
|
|
268
|
+
form: {
|
|
269
|
+
fields: []
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
expect(() => {
|
|
274
|
+
validateExecutionInterface('test-org', 'test-resource', executionInterface, inputSchema)
|
|
275
|
+
}).not.toThrow()
|
|
276
|
+
})
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
|
|
280
|
+
describe('validateResourceGovernance', () => {
|
|
281
|
+
afterEach(() => {
|
|
282
|
+
vi.unstubAllEnvs()
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
const systemA = {
|
|
286
|
+
id: 'sys.lead-gen',
|
|
287
|
+
title: 'Lead Gen',
|
|
288
|
+
description: 'Lead generation system.',
|
|
289
|
+
kind: 'operational' as const,
|
|
290
|
+
governedByKnowledge: [],
|
|
291
|
+
drivesGoals: [],
|
|
292
|
+
status: 'active' as const
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const systemB = {
|
|
296
|
+
id: 'sys.crm',
|
|
297
|
+
title: 'CRM',
|
|
298
|
+
description: 'CRM system.',
|
|
299
|
+
kind: 'operational' as const,
|
|
300
|
+
governedByKnowledge: [],
|
|
301
|
+
drivesGoals: [],
|
|
302
|
+
status: 'active' as const
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const workflowResource: ResourceEntry = {
|
|
306
|
+
id: 'lead-import',
|
|
307
|
+
kind: 'workflow',
|
|
308
|
+
systemId: 'sys.lead-gen',
|
|
309
|
+
status: 'active'
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const agentResource: ResourceEntry = {
|
|
313
|
+
id: 'lead-import',
|
|
314
|
+
kind: 'agent',
|
|
315
|
+
systemId: 'sys.lead-gen',
|
|
316
|
+
status: 'active',
|
|
317
|
+
agentKind: 'specialist',
|
|
318
|
+
sessionCapable: false
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const createGovernedWorkflow = (
|
|
322
|
+
resource = workflowResource,
|
|
323
|
+
overrides: Partial<WorkflowDefinition['config']> = {}
|
|
324
|
+
): WorkflowDefinition => ({
|
|
325
|
+
config: {
|
|
326
|
+
resourceId: resource.id,
|
|
327
|
+
name: `Workflow ${resource.id}`,
|
|
328
|
+
description: `Test workflow ${resource.id}`,
|
|
329
|
+
version: '1.0.0',
|
|
330
|
+
type: 'workflow',
|
|
331
|
+
status: 'dev',
|
|
332
|
+
resource: resource as Extract<ResourceEntry, { kind: 'workflow' }>,
|
|
333
|
+
...overrides
|
|
334
|
+
},
|
|
335
|
+
contract: {
|
|
336
|
+
inputSchema: z.object({ data: z.string() }),
|
|
337
|
+
outputSchema: z.object({ result: z.boolean() })
|
|
338
|
+
},
|
|
339
|
+
steps: {},
|
|
340
|
+
entryPoint: 'start'
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
const createRawWorkflow = (resourceId = workflowResource.id): WorkflowDefinition => ({
|
|
344
|
+
config: {
|
|
345
|
+
resourceId,
|
|
346
|
+
name: `Workflow ${resourceId}`,
|
|
347
|
+
description: `Test workflow ${resourceId}`,
|
|
348
|
+
version: '1.0.0',
|
|
349
|
+
type: 'workflow',
|
|
350
|
+
status: 'dev'
|
|
351
|
+
},
|
|
352
|
+
contract: {
|
|
353
|
+
inputSchema: z.object({ data: z.string() }),
|
|
354
|
+
outputSchema: z.object({ result: z.boolean() })
|
|
355
|
+
},
|
|
356
|
+
steps: {},
|
|
357
|
+
entryPoint: 'start'
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
const createModel = (resources: ResourceEntry[] = [workflowResource], systems = [systemA]) => ({
|
|
361
|
+
systems: { systems },
|
|
362
|
+
resources: { entries: resources }
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
it('passes when code resources are descriptor-backed and match active OM Resources and Systems', () => {
|
|
366
|
+
const result = validateResourceGovernance(
|
|
367
|
+
'test-org',
|
|
368
|
+
{
|
|
369
|
+
version: '1.0.0',
|
|
370
|
+
workflows: [createGovernedWorkflow()]
|
|
371
|
+
},
|
|
372
|
+
createModel(),
|
|
373
|
+
{ mode: 'strict' }
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
expect(result.valid).toBe(true)
|
|
377
|
+
expect(result.issues).toEqual([])
|
|
378
|
+
})
|
|
379
|
+
|
|
380
|
+
it('throws in strict mode when an active OM resource has no code-side resource', () => {
|
|
381
|
+
expect(() =>
|
|
382
|
+
validateResourceGovernance(
|
|
383
|
+
'test-org',
|
|
384
|
+
{
|
|
385
|
+
version: '1.0.0',
|
|
386
|
+
workflows: []
|
|
387
|
+
},
|
|
388
|
+
createModel(),
|
|
389
|
+
{ mode: 'strict' }
|
|
390
|
+
)
|
|
391
|
+
).toThrow("OM resource 'lead-import' has no matching code-side resource")
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
it('defaults to strict mode after cutover', () => {
|
|
395
|
+
expect(() =>
|
|
396
|
+
validateResourceGovernance(
|
|
397
|
+
'test-org',
|
|
398
|
+
{
|
|
399
|
+
version: '1.0.0',
|
|
400
|
+
workflows: []
|
|
401
|
+
},
|
|
402
|
+
createModel()
|
|
403
|
+
)
|
|
404
|
+
).toThrow("OM resource 'lead-import' has no matching code-side resource")
|
|
405
|
+
})
|
|
406
|
+
|
|
407
|
+
it('downgrades strict failures to warnings in warn-only mode', () => {
|
|
408
|
+
const warnings: string[] = []
|
|
409
|
+
|
|
410
|
+
const result = validateResourceGovernance(
|
|
411
|
+
'test-org',
|
|
412
|
+
{
|
|
413
|
+
version: '1.0.0',
|
|
414
|
+
workflows: []
|
|
415
|
+
},
|
|
416
|
+
createModel(),
|
|
417
|
+
{
|
|
418
|
+
mode: 'warn-only',
|
|
419
|
+
onWarning: (issue) => warnings.push(issue.message)
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
expect(result.valid).toBe(false)
|
|
424
|
+
expect(result.issues.map((issue) => issue.type)).toContain('missing-code-resource')
|
|
425
|
+
expect(warnings).toEqual(["[test-org] OM resource 'lead-import' has no matching code-side resource."])
|
|
426
|
+
})
|
|
427
|
+
|
|
428
|
+
it('honors ELEVASIS_RESOURCE_VALIDATOR=warn-only as the permanent escape hatch', () => {
|
|
429
|
+
vi.stubEnv('ELEVASIS_RESOURCE_VALIDATOR', 'warn-only')
|
|
430
|
+
const warnings: string[] = []
|
|
431
|
+
|
|
432
|
+
const result = validateResourceGovernance(
|
|
433
|
+
'test-org',
|
|
434
|
+
{
|
|
435
|
+
version: '1.0.0',
|
|
436
|
+
workflows: []
|
|
437
|
+
},
|
|
438
|
+
createModel(),
|
|
439
|
+
{
|
|
440
|
+
onWarning: (issue) => warnings.push(issue.message)
|
|
441
|
+
}
|
|
442
|
+
)
|
|
443
|
+
|
|
444
|
+
expect(result.valid).toBe(false)
|
|
445
|
+
expect(result.mode).toBe('warn-only')
|
|
446
|
+
expect(result.issues.map((issue) => issue.type)).toContain('missing-code-resource')
|
|
447
|
+
expect(warnings).toEqual(["[test-org] OM resource 'lead-import' has no matching code-side resource."])
|
|
448
|
+
})
|
|
449
|
+
|
|
450
|
+
it('reports a code-side resource with no active OM resource', () => {
|
|
451
|
+
const extraResource: ResourceEntry = {
|
|
452
|
+
...workflowResource,
|
|
453
|
+
id: 'extra-workflow'
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
expect(() =>
|
|
457
|
+
validateResourceGovernance(
|
|
458
|
+
'test-org',
|
|
459
|
+
{
|
|
460
|
+
version: '1.0.0',
|
|
461
|
+
workflows: [createGovernedWorkflow(extraResource)]
|
|
462
|
+
},
|
|
463
|
+
createModel([], [systemA]),
|
|
464
|
+
{ mode: 'strict' }
|
|
465
|
+
)
|
|
466
|
+
).toThrow("Code-side resource 'extra-workflow' has no active OM Resource descriptor")
|
|
467
|
+
})
|
|
468
|
+
|
|
469
|
+
it('reports runtime/OM type mismatches', () => {
|
|
470
|
+
expect(() =>
|
|
471
|
+
validateResourceGovernance(
|
|
472
|
+
'test-org',
|
|
473
|
+
{
|
|
474
|
+
version: '1.0.0',
|
|
475
|
+
workflows: [createRawWorkflow('lead-import')]
|
|
476
|
+
},
|
|
477
|
+
createModel([agentResource]),
|
|
478
|
+
{ mode: 'strict' }
|
|
479
|
+
)
|
|
480
|
+
).toThrow("Resource 'lead-import' type mismatch: code has 'workflow', OM has 'agent'")
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
it('reports descriptor/OM system mismatches', () => {
|
|
484
|
+
const codeDescriptor: ResourceEntry = {
|
|
485
|
+
...workflowResource,
|
|
486
|
+
systemId: 'sys.crm'
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
expect(() =>
|
|
490
|
+
validateResourceGovernance(
|
|
491
|
+
'test-org',
|
|
492
|
+
{
|
|
493
|
+
version: '1.0.0',
|
|
494
|
+
workflows: [createGovernedWorkflow(codeDescriptor)]
|
|
495
|
+
},
|
|
496
|
+
createModel([workflowResource], [systemA, systemB]),
|
|
497
|
+
{ mode: 'strict' }
|
|
498
|
+
)
|
|
499
|
+
).toThrow("Resource 'lead-import' system mismatch: code descriptor has 'sys.crm', OM has 'sys.lead-gen'")
|
|
500
|
+
})
|
|
501
|
+
|
|
502
|
+
it('reports active OM resources that reference missing Systems', () => {
|
|
503
|
+
const resourceWithMissingSystem: ResourceEntry = {
|
|
504
|
+
...workflowResource,
|
|
505
|
+
systemId: 'sys.missing'
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
expect(() =>
|
|
509
|
+
validateResourceGovernance(
|
|
510
|
+
'test-org',
|
|
511
|
+
{
|
|
512
|
+
version: '1.0.0',
|
|
513
|
+
workflows: [createGovernedWorkflow(resourceWithMissingSystem)]
|
|
514
|
+
},
|
|
515
|
+
createModel([resourceWithMissingSystem], [systemA]),
|
|
516
|
+
{ mode: 'strict' }
|
|
517
|
+
)
|
|
518
|
+
).toThrow("OM resource 'lead-import' references missing System 'sys.missing'")
|
|
519
|
+
})
|
|
520
|
+
|
|
521
|
+
it('reports raw runtime resourceId authoring when a descriptor is required', () => {
|
|
522
|
+
expect(() =>
|
|
523
|
+
validateResourceGovernance(
|
|
524
|
+
'test-org',
|
|
525
|
+
{
|
|
526
|
+
version: '1.0.0',
|
|
527
|
+
workflows: [createRawWorkflow()]
|
|
528
|
+
},
|
|
529
|
+
createModel(),
|
|
530
|
+
{ mode: 'strict' }
|
|
531
|
+
)
|
|
532
|
+
).toThrow("Code-side resource 'lead-import' authors raw resourceId/type values")
|
|
533
|
+
})
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
describe('ResourceRegistry - ExecutionInterface validation integration', () => {
|
|
537
|
+
it('should throw on registry construction when interface misses required field', () => {
|
|
538
|
+
const workflow: WorkflowDefinition = {
|
|
539
|
+
config: {
|
|
540
|
+
resourceId: 'test-workflow',
|
|
541
|
+
name: 'Test Workflow',
|
|
542
|
+
description: 'Test',
|
|
543
|
+
version: '1.0.0',
|
|
544
|
+
type: 'workflow',
|
|
545
|
+
status: 'dev'
|
|
546
|
+
},
|
|
547
|
+
contract: {
|
|
548
|
+
inputSchema: z.object({
|
|
549
|
+
taskName: z.string(),
|
|
550
|
+
priority: z.string()
|
|
551
|
+
}),
|
|
552
|
+
outputSchema: z.object({})
|
|
553
|
+
},
|
|
554
|
+
steps: {},
|
|
555
|
+
entryPoint: 'start',
|
|
556
|
+
interface: {
|
|
557
|
+
form: {
|
|
558
|
+
fields: [
|
|
559
|
+
{ name: 'taskName', label: 'Task Name', type: 'text', required: true }
|
|
560
|
+
// Missing 'priority' field
|
|
561
|
+
]
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const registry: OrganizationRegistry = {
|
|
567
|
+
'test-org': {
|
|
568
|
+
workflows: [workflow]
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
expect(() => {
|
|
573
|
+
new ResourceRegistry(registry)
|
|
574
|
+
}).toThrow('missing required field "priority"')
|
|
575
|
+
})
|
|
576
|
+
|
|
577
|
+
it('should throw when agent interface misses required field', () => {
|
|
578
|
+
const agent: AgentDefinition = {
|
|
579
|
+
config: {
|
|
580
|
+
resourceId: 'test-agent',
|
|
581
|
+
name: 'Test Agent',
|
|
582
|
+
description: 'Test',
|
|
583
|
+
version: '1.0.0',
|
|
584
|
+
type: 'agent',
|
|
585
|
+
status: 'dev',
|
|
586
|
+
systemPrompt: 'You are a test agent'
|
|
587
|
+
},
|
|
588
|
+
contract: {
|
|
589
|
+
inputSchema: z.object({
|
|
590
|
+
task: z.string(),
|
|
591
|
+
context: z.string()
|
|
592
|
+
}),
|
|
593
|
+
outputSchema: z.object({})
|
|
594
|
+
},
|
|
595
|
+
tools: [],
|
|
596
|
+
modelConfig: {
|
|
597
|
+
provider: 'mock',
|
|
598
|
+
model: 'mock',
|
|
599
|
+
apiKey: 'test'
|
|
600
|
+
},
|
|
601
|
+
interface: {
|
|
602
|
+
form: {
|
|
603
|
+
fields: [
|
|
604
|
+
{ name: 'task', label: 'Task', type: 'textarea', required: true }
|
|
605
|
+
// Missing 'context' field
|
|
606
|
+
]
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
const registry: OrganizationRegistry = {
|
|
612
|
+
'test-org': {
|
|
613
|
+
agents: [agent]
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
expect(() => {
|
|
618
|
+
new ResourceRegistry(registry)
|
|
619
|
+
}).toThrow('missing required field "context"')
|
|
620
|
+
})
|
|
621
|
+
|
|
622
|
+
it('should pass when interface correctly matches schema', () => {
|
|
623
|
+
const workflow: WorkflowDefinition = {
|
|
624
|
+
config: {
|
|
625
|
+
resourceId: 'valid-workflow',
|
|
626
|
+
name: 'Valid Workflow',
|
|
627
|
+
description: 'Test',
|
|
628
|
+
version: '1.0.0',
|
|
629
|
+
type: 'workflow',
|
|
630
|
+
status: 'dev'
|
|
631
|
+
},
|
|
632
|
+
contract: {
|
|
633
|
+
inputSchema: z.object({
|
|
634
|
+
taskName: z.string(),
|
|
635
|
+
priority: z.enum(['low', 'medium', 'high']),
|
|
636
|
+
description: z.string().optional()
|
|
637
|
+
}),
|
|
638
|
+
outputSchema: z.object({})
|
|
639
|
+
},
|
|
640
|
+
steps: {},
|
|
641
|
+
entryPoint: 'start',
|
|
642
|
+
interface: {
|
|
643
|
+
form: {
|
|
644
|
+
title: 'Run Workflow',
|
|
645
|
+
fields: [
|
|
646
|
+
{ name: 'taskName', label: 'Task Name', type: 'text', required: true },
|
|
647
|
+
{ name: 'priority', label: 'Priority', type: 'select', required: true },
|
|
648
|
+
{ name: 'description', label: 'Description', type: 'textarea', required: false }
|
|
649
|
+
]
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
const registry: OrganizationRegistry = {
|
|
655
|
+
'test-org': {
|
|
656
|
+
workflows: [workflow]
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
expect(() => {
|
|
661
|
+
new ResourceRegistry(registry)
|
|
662
|
+
}).not.toThrow()
|
|
663
|
+
})
|
|
664
|
+
|
|
665
|
+
it('should pass when workflow has no interface (optional)', () => {
|
|
666
|
+
const workflow: WorkflowDefinition = {
|
|
667
|
+
config: {
|
|
668
|
+
resourceId: 'no-interface-workflow',
|
|
669
|
+
name: 'No Interface Workflow',
|
|
670
|
+
description: 'Test',
|
|
671
|
+
version: '1.0.0',
|
|
672
|
+
type: 'workflow',
|
|
673
|
+
status: 'dev'
|
|
674
|
+
},
|
|
675
|
+
contract: {
|
|
676
|
+
inputSchema: z.object({ data: z.string() }),
|
|
677
|
+
outputSchema: z.object({})
|
|
678
|
+
},
|
|
679
|
+
steps: {},
|
|
680
|
+
entryPoint: 'start'
|
|
681
|
+
// No interface - should pass
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const registry: OrganizationRegistry = {
|
|
685
|
+
'test-org': {
|
|
686
|
+
workflows: [workflow]
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
expect(() => {
|
|
691
|
+
new ResourceRegistry(registry)
|
|
692
|
+
}).not.toThrow()
|
|
693
|
+
})
|
|
694
|
+
})
|
|
695
|
+
|
|
696
|
+
describe('Relationship Validation', () => {
|
|
697
|
+
// Helper to create minimal mock resources
|
|
698
|
+
const createMockWorkflow = (resourceId: string): WorkflowDefinition => ({
|
|
699
|
+
config: {
|
|
700
|
+
resourceId,
|
|
701
|
+
name: `Workflow ${resourceId}`,
|
|
702
|
+
description: `Test workflow ${resourceId}`,
|
|
703
|
+
version: '1.0.0',
|
|
704
|
+
type: 'workflow',
|
|
705
|
+
status: 'dev'
|
|
706
|
+
},
|
|
707
|
+
contract: {
|
|
708
|
+
inputSchema: z.object({ data: z.string() }),
|
|
709
|
+
outputSchema: z.object({ result: z.boolean() })
|
|
710
|
+
},
|
|
711
|
+
steps: {},
|
|
712
|
+
entryPoint: 'start'
|
|
713
|
+
})
|
|
714
|
+
|
|
715
|
+
const createMockAgent = (resourceId: string): AgentDefinition => ({
|
|
716
|
+
config: {
|
|
717
|
+
resourceId,
|
|
718
|
+
name: `Agent ${resourceId}`,
|
|
719
|
+
description: `Test agent ${resourceId}`,
|
|
720
|
+
version: '1.0.0',
|
|
721
|
+
type: 'agent',
|
|
722
|
+
status: 'dev',
|
|
723
|
+
systemPrompt: 'You are a test agent'
|
|
724
|
+
},
|
|
725
|
+
contract: {
|
|
726
|
+
inputSchema: z.object({ query: z.string() }),
|
|
727
|
+
outputSchema: z.object({ response: z.string() })
|
|
728
|
+
},
|
|
729
|
+
tools: [],
|
|
730
|
+
modelConfig: {
|
|
731
|
+
provider: 'mock',
|
|
732
|
+
model: 'mock',
|
|
733
|
+
apiKey: 'test-key'
|
|
734
|
+
}
|
|
735
|
+
})
|
|
736
|
+
|
|
737
|
+
describe('validateTriggers (new field names)', () => {
|
|
738
|
+
it('validates trigger.triggers.agents exist (using resourceId)', () => {
|
|
739
|
+
const agent = createMockAgent('test-agent')
|
|
740
|
+
const registry: OrganizationRegistry = {
|
|
741
|
+
'test-org': {
|
|
742
|
+
agents: [agent],
|
|
743
|
+
triggers: [
|
|
744
|
+
{
|
|
745
|
+
resourceId: 'test-trigger',
|
|
746
|
+
type: 'trigger',
|
|
747
|
+
triggerType: 'webhook',
|
|
748
|
+
name: 'Test Trigger',
|
|
749
|
+
description: 'Test trigger',
|
|
750
|
+
version: '1.0.0',
|
|
751
|
+
status: 'dev',
|
|
752
|
+
triggers: { agents: ['test-agent'] }
|
|
753
|
+
}
|
|
754
|
+
]
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
expect(() => {
|
|
759
|
+
new ResourceRegistry(registry)
|
|
760
|
+
}).not.toThrow()
|
|
761
|
+
})
|
|
762
|
+
|
|
763
|
+
it('validates trigger.triggers.workflows exist (using resourceId)', () => {
|
|
764
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
765
|
+
const registry: OrganizationRegistry = {
|
|
766
|
+
'test-org': {
|
|
767
|
+
workflows: [workflow],
|
|
768
|
+
triggers: [
|
|
769
|
+
{
|
|
770
|
+
resourceId: 'test-trigger',
|
|
771
|
+
type: 'trigger',
|
|
772
|
+
triggerType: 'schedule',
|
|
773
|
+
name: 'Test Trigger',
|
|
774
|
+
description: 'Test trigger',
|
|
775
|
+
version: '1.0.0',
|
|
776
|
+
status: 'dev',
|
|
777
|
+
triggers: { workflows: ['test-workflow'] }
|
|
778
|
+
}
|
|
779
|
+
]
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
expect(() => {
|
|
784
|
+
new ResourceRegistry(registry)
|
|
785
|
+
}).not.toThrow()
|
|
786
|
+
})
|
|
787
|
+
|
|
788
|
+
it('throws for trigger triggering non-existent agent (via relationships)', () => {
|
|
789
|
+
// Note: Trigger relationships are now declared via ResourceRelationships
|
|
790
|
+
const registry: OrganizationRegistry = {
|
|
791
|
+
'test-org': {
|
|
792
|
+
triggers: [
|
|
793
|
+
{
|
|
794
|
+
resourceId: 'test-trigger',
|
|
795
|
+
type: 'trigger',
|
|
796
|
+
triggerType: 'webhook',
|
|
797
|
+
name: 'Test Trigger',
|
|
798
|
+
description: 'Test trigger',
|
|
799
|
+
version: '1.0.0',
|
|
800
|
+
status: 'dev'
|
|
801
|
+
}
|
|
802
|
+
],
|
|
803
|
+
relationships: {
|
|
804
|
+
'test-trigger': {
|
|
805
|
+
triggers: { agents: ['non-existent-agent'] }
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
expect(() => {
|
|
812
|
+
new ResourceRegistry(registry)
|
|
813
|
+
}).toThrow('non-existent-agent')
|
|
814
|
+
})
|
|
815
|
+
|
|
816
|
+
it('throws for trigger triggering non-existent workflow (via relationships)', () => {
|
|
817
|
+
// Note: Trigger relationships are now declared via ResourceRelationships
|
|
818
|
+
const registry: OrganizationRegistry = {
|
|
819
|
+
'test-org': {
|
|
820
|
+
triggers: [
|
|
821
|
+
{
|
|
822
|
+
resourceId: 'test-trigger',
|
|
823
|
+
type: 'trigger',
|
|
824
|
+
triggerType: 'event',
|
|
825
|
+
name: 'Test Trigger',
|
|
826
|
+
description: 'Test trigger',
|
|
827
|
+
version: '1.0.0',
|
|
828
|
+
status: 'dev'
|
|
829
|
+
}
|
|
830
|
+
],
|
|
831
|
+
relationships: {
|
|
832
|
+
'test-trigger': {
|
|
833
|
+
triggers: { workflows: ['non-existent-workflow'] }
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
expect(() => {
|
|
840
|
+
new ResourceRegistry(registry)
|
|
841
|
+
}).toThrow('non-existent-workflow')
|
|
842
|
+
})
|
|
843
|
+
|
|
844
|
+
it('allows trigger with no relationships (triggers are metadata only)', () => {
|
|
845
|
+
// Note: Triggers without relationships are now valid - they're just metadata
|
|
846
|
+
// The trigger's targets are defined in ResourceRelationships, not on the trigger itself
|
|
847
|
+
const registry: OrganizationRegistry = {
|
|
848
|
+
'test-org': {
|
|
849
|
+
triggers: [
|
|
850
|
+
{
|
|
851
|
+
resourceId: 'test-trigger',
|
|
852
|
+
type: 'trigger',
|
|
853
|
+
triggerType: 'webhook',
|
|
854
|
+
name: 'Test Trigger',
|
|
855
|
+
description: 'Test trigger',
|
|
856
|
+
version: '1.0.0',
|
|
857
|
+
status: 'dev'
|
|
858
|
+
}
|
|
859
|
+
]
|
|
860
|
+
// No relationships - trigger is just metadata
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
expect(() => {
|
|
865
|
+
new ResourceRegistry(registry)
|
|
866
|
+
}).not.toThrow()
|
|
867
|
+
})
|
|
868
|
+
|
|
869
|
+
it('allows trigger with empty relationships object', () => {
|
|
870
|
+
// Note: Empty relationships are valid - triggers without targets are allowed
|
|
871
|
+
const registry: OrganizationRegistry = {
|
|
872
|
+
'test-org': {
|
|
873
|
+
triggers: [
|
|
874
|
+
{
|
|
875
|
+
resourceId: 'test-trigger',
|
|
876
|
+
type: 'trigger',
|
|
877
|
+
triggerType: 'manual',
|
|
878
|
+
name: 'Test Trigger',
|
|
879
|
+
description: 'Test trigger',
|
|
880
|
+
version: '1.0.0',
|
|
881
|
+
status: 'dev'
|
|
882
|
+
}
|
|
883
|
+
],
|
|
884
|
+
relationships: {}
|
|
885
|
+
}
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
expect(() => {
|
|
889
|
+
new ResourceRegistry(registry)
|
|
890
|
+
}).not.toThrow()
|
|
891
|
+
})
|
|
892
|
+
})
|
|
893
|
+
|
|
894
|
+
describe('validateResourceRelationships', () => {
|
|
895
|
+
it('validates resource.triggers.agents exist', () => {
|
|
896
|
+
const agent1 = createMockAgent('agent-1')
|
|
897
|
+
const agent2 = createMockAgent('agent-2')
|
|
898
|
+
const registry: OrganizationRegistry = {
|
|
899
|
+
'test-org': {
|
|
900
|
+
agents: [agent1, agent2],
|
|
901
|
+
relationships: {
|
|
902
|
+
'agent-1': {
|
|
903
|
+
triggers: { agents: ['agent-2'] }
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
expect(() => {
|
|
910
|
+
new ResourceRegistry(registry)
|
|
911
|
+
}).not.toThrow()
|
|
912
|
+
})
|
|
913
|
+
|
|
914
|
+
it('validates resource.triggers.workflows exist', () => {
|
|
915
|
+
const agent = createMockAgent('test-agent')
|
|
916
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
917
|
+
const registry: OrganizationRegistry = {
|
|
918
|
+
'test-org': {
|
|
919
|
+
agents: [agent],
|
|
920
|
+
workflows: [workflow],
|
|
921
|
+
relationships: {
|
|
922
|
+
'test-agent': {
|
|
923
|
+
triggers: { workflows: ['test-workflow'] }
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
expect(() => {
|
|
930
|
+
new ResourceRegistry(registry)
|
|
931
|
+
}).not.toThrow()
|
|
932
|
+
})
|
|
933
|
+
|
|
934
|
+
it('validates resource.uses.integrations exist', () => {
|
|
935
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
936
|
+
const registry: OrganizationRegistry = {
|
|
937
|
+
'test-org': {
|
|
938
|
+
workflows: [workflow],
|
|
939
|
+
integrations: [
|
|
940
|
+
{
|
|
941
|
+
resourceId: 'integration-shopify',
|
|
942
|
+
type: 'integration',
|
|
943
|
+
provider: 'custom',
|
|
944
|
+
credentialName: 'shopify-prod',
|
|
945
|
+
name: 'Shopify Integration',
|
|
946
|
+
description: 'E-commerce integration',
|
|
947
|
+
version: '1.0.0',
|
|
948
|
+
status: 'prod'
|
|
949
|
+
}
|
|
950
|
+
],
|
|
951
|
+
relationships: {
|
|
952
|
+
'test-workflow': {
|
|
953
|
+
uses: { integrations: ['integration-shopify'] }
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
|
|
959
|
+
expect(() => {
|
|
960
|
+
new ResourceRegistry(registry)
|
|
961
|
+
}).not.toThrow()
|
|
962
|
+
})
|
|
963
|
+
|
|
964
|
+
it('throws for relationship declared for non-existent resource', () => {
|
|
965
|
+
const registry: OrganizationRegistry = {
|
|
966
|
+
'test-org': {
|
|
967
|
+
relationships: {
|
|
968
|
+
'non-existent-resource': {
|
|
969
|
+
triggers: { agents: ['some-agent'] }
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
expect(() => {
|
|
976
|
+
new ResourceRegistry(registry)
|
|
977
|
+
}).toThrow('[test-org] Relationship declared for non-existent resource: non-existent-resource')
|
|
978
|
+
})
|
|
979
|
+
|
|
980
|
+
it('throws for relationship triggering non-existent agent', () => {
|
|
981
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
982
|
+
const registry: OrganizationRegistry = {
|
|
983
|
+
'test-org': {
|
|
984
|
+
workflows: [workflow],
|
|
985
|
+
relationships: {
|
|
986
|
+
'test-workflow': {
|
|
987
|
+
triggers: { agents: ['non-existent-agent'] }
|
|
988
|
+
}
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
expect(() => {
|
|
994
|
+
new ResourceRegistry(registry)
|
|
995
|
+
}).toThrow("[test-org] Resource 'test-workflow' triggers non-existent agent: non-existent-agent")
|
|
996
|
+
})
|
|
997
|
+
|
|
998
|
+
it('throws for relationship using non-existent integration', () => {
|
|
999
|
+
const agent = createMockAgent('test-agent')
|
|
1000
|
+
const registry: OrganizationRegistry = {
|
|
1001
|
+
'test-org': {
|
|
1002
|
+
agents: [agent],
|
|
1003
|
+
relationships: {
|
|
1004
|
+
'test-agent': {
|
|
1005
|
+
uses: { integrations: ['non-existent-integration'] }
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
expect(() => {
|
|
1012
|
+
new ResourceRegistry(registry)
|
|
1013
|
+
}).toThrow("[test-org] Resource 'test-agent' uses non-existent integration: non-existent-integration")
|
|
1014
|
+
})
|
|
1015
|
+
})
|
|
1016
|
+
|
|
1017
|
+
describe('validateExternalResources (forward-only)', () => {
|
|
1018
|
+
it('validates external.triggers.agents exist', () => {
|
|
1019
|
+
const agent = createMockAgent('test-agent')
|
|
1020
|
+
const registry: OrganizationRegistry = {
|
|
1021
|
+
'test-org': {
|
|
1022
|
+
agents: [agent],
|
|
1023
|
+
externalResources: [
|
|
1024
|
+
{
|
|
1025
|
+
resourceId: 'external-n8n-workflow',
|
|
1026
|
+
type: 'external',
|
|
1027
|
+
platform: 'n8n',
|
|
1028
|
+
name: 'N8N Workflow',
|
|
1029
|
+
description: 'External automation',
|
|
1030
|
+
version: '1.0.0',
|
|
1031
|
+
status: 'prod',
|
|
1032
|
+
triggers: { agents: ['test-agent'] }
|
|
1033
|
+
}
|
|
1034
|
+
]
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
expect(() => {
|
|
1039
|
+
new ResourceRegistry(registry)
|
|
1040
|
+
}).not.toThrow()
|
|
1041
|
+
})
|
|
1042
|
+
|
|
1043
|
+
it('validates external.triggers.workflows exist', () => {
|
|
1044
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
1045
|
+
const registry: OrganizationRegistry = {
|
|
1046
|
+
'test-org': {
|
|
1047
|
+
workflows: [workflow],
|
|
1048
|
+
externalResources: [
|
|
1049
|
+
{
|
|
1050
|
+
resourceId: 'external-zapier-zap',
|
|
1051
|
+
type: 'external',
|
|
1052
|
+
platform: 'zapier',
|
|
1053
|
+
name: 'Zapier Zap',
|
|
1054
|
+
description: 'External automation',
|
|
1055
|
+
version: '1.0.0',
|
|
1056
|
+
status: 'prod',
|
|
1057
|
+
triggers: { workflows: ['test-workflow'] }
|
|
1058
|
+
}
|
|
1059
|
+
]
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
expect(() => {
|
|
1064
|
+
new ResourceRegistry(registry)
|
|
1065
|
+
}).not.toThrow()
|
|
1066
|
+
})
|
|
1067
|
+
|
|
1068
|
+
it('validates external.uses.integrations exist', () => {
|
|
1069
|
+
const registry: OrganizationRegistry = {
|
|
1070
|
+
'test-org': {
|
|
1071
|
+
integrations: [
|
|
1072
|
+
{
|
|
1073
|
+
resourceId: 'integration-slack',
|
|
1074
|
+
type: 'integration',
|
|
1075
|
+
provider: 'custom',
|
|
1076
|
+
credentialName: 'slack-prod',
|
|
1077
|
+
name: 'Slack Integration',
|
|
1078
|
+
description: 'Chat integration',
|
|
1079
|
+
version: '1.0.0',
|
|
1080
|
+
status: 'prod'
|
|
1081
|
+
}
|
|
1082
|
+
],
|
|
1083
|
+
externalResources: [
|
|
1084
|
+
{
|
|
1085
|
+
resourceId: 'external-make-scenario',
|
|
1086
|
+
type: 'external',
|
|
1087
|
+
platform: 'make',
|
|
1088
|
+
name: 'Make Scenario',
|
|
1089
|
+
description: 'External automation',
|
|
1090
|
+
version: '1.0.0',
|
|
1091
|
+
status: 'prod',
|
|
1092
|
+
uses: { integrations: ['integration-slack'] }
|
|
1093
|
+
}
|
|
1094
|
+
]
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
expect(() => {
|
|
1099
|
+
new ResourceRegistry(registry)
|
|
1100
|
+
}).not.toThrow()
|
|
1101
|
+
})
|
|
1102
|
+
|
|
1103
|
+
it('validates external resourceId does not conflict with internal resources', () => {
|
|
1104
|
+
const workflow = createMockWorkflow('conflicting-id')
|
|
1105
|
+
const registry: OrganizationRegistry = {
|
|
1106
|
+
'test-org': {
|
|
1107
|
+
workflows: [workflow],
|
|
1108
|
+
externalResources: [
|
|
1109
|
+
{
|
|
1110
|
+
resourceId: 'conflicting-id',
|
|
1111
|
+
type: 'external',
|
|
1112
|
+
platform: 'other',
|
|
1113
|
+
name: 'Conflicting External',
|
|
1114
|
+
description: 'Should conflict',
|
|
1115
|
+
version: '1.0.0',
|
|
1116
|
+
status: 'dev'
|
|
1117
|
+
}
|
|
1118
|
+
]
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
expect(() => {
|
|
1123
|
+
new ResourceRegistry(registry)
|
|
1124
|
+
}).toThrow("[test-org] External resource ID 'conflicting-id' conflicts with internal resource ID")
|
|
1125
|
+
})
|
|
1126
|
+
|
|
1127
|
+
it('does NOT validate triggeredBy (field removed)', () => {
|
|
1128
|
+
// This test ensures we don't validate triggeredBy field (it's been removed)
|
|
1129
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
1130
|
+
const registry: OrganizationRegistry = {
|
|
1131
|
+
'test-org': {
|
|
1132
|
+
workflows: [workflow],
|
|
1133
|
+
externalResources: [
|
|
1134
|
+
{
|
|
1135
|
+
resourceId: 'external-resource',
|
|
1136
|
+
type: 'external',
|
|
1137
|
+
platform: 'n8n',
|
|
1138
|
+
name: 'External Resource',
|
|
1139
|
+
description: 'Has no triggeredBy field',
|
|
1140
|
+
version: '1.0.0',
|
|
1141
|
+
status: 'prod',
|
|
1142
|
+
triggers: { workflows: ['test-workflow'] }
|
|
1143
|
+
// No triggeredBy field - this is correct and should pass
|
|
1144
|
+
}
|
|
1145
|
+
]
|
|
1146
|
+
}
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
expect(() => {
|
|
1150
|
+
new ResourceRegistry(registry)
|
|
1151
|
+
}).not.toThrow()
|
|
1152
|
+
})
|
|
1153
|
+
|
|
1154
|
+
it('throws for external resource with conflicting ID', () => {
|
|
1155
|
+
const agent = createMockAgent('duplicate-id')
|
|
1156
|
+
const registry: OrganizationRegistry = {
|
|
1157
|
+
'test-org': {
|
|
1158
|
+
agents: [agent],
|
|
1159
|
+
externalResources: [
|
|
1160
|
+
{
|
|
1161
|
+
resourceId: 'duplicate-id',
|
|
1162
|
+
type: 'external',
|
|
1163
|
+
platform: 'n8n',
|
|
1164
|
+
name: 'Duplicate ID',
|
|
1165
|
+
description: 'Conflicts with agent',
|
|
1166
|
+
version: '1.0.0',
|
|
1167
|
+
status: 'dev'
|
|
1168
|
+
}
|
|
1169
|
+
]
|
|
1170
|
+
}
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
expect(() => {
|
|
1174
|
+
new ResourceRegistry(registry)
|
|
1175
|
+
}).toThrow("[test-org] External resource ID 'duplicate-id' conflicts with internal resource ID")
|
|
1176
|
+
})
|
|
1177
|
+
})
|
|
1178
|
+
|
|
1179
|
+
describe('validateHumanCheckpoints', () => {
|
|
1180
|
+
it('validates requestedBy.agents exist', () => {
|
|
1181
|
+
const agent = createMockAgent('test-agent')
|
|
1182
|
+
const registry: OrganizationRegistry = {
|
|
1183
|
+
'test-org': {
|
|
1184
|
+
agents: [agent],
|
|
1185
|
+
humanCheckpoints: [
|
|
1186
|
+
{
|
|
1187
|
+
resourceId: 'approval-queue',
|
|
1188
|
+
type: 'human',
|
|
1189
|
+
name: 'Approval Queue',
|
|
1190
|
+
description: 'Human approval checkpoint',
|
|
1191
|
+
version: '1.0.0',
|
|
1192
|
+
status: 'prod',
|
|
1193
|
+
requestedBy: { agents: ['test-agent'] }
|
|
1194
|
+
}
|
|
1195
|
+
]
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
expect(() => {
|
|
1200
|
+
new ResourceRegistry(registry)
|
|
1201
|
+
}).not.toThrow()
|
|
1202
|
+
})
|
|
1203
|
+
|
|
1204
|
+
it('validates requestedBy.workflows exist', () => {
|
|
1205
|
+
const workflow = createMockWorkflow('test-workflow')
|
|
1206
|
+
const registry: OrganizationRegistry = {
|
|
1207
|
+
'test-org': {
|
|
1208
|
+
workflows: [workflow],
|
|
1209
|
+
humanCheckpoints: [
|
|
1210
|
+
{
|
|
1211
|
+
resourceId: 'review-queue',
|
|
1212
|
+
type: 'human',
|
|
1213
|
+
name: 'Review Queue',
|
|
1214
|
+
description: 'Human review checkpoint',
|
|
1215
|
+
version: '1.0.0',
|
|
1216
|
+
status: 'prod',
|
|
1217
|
+
requestedBy: { workflows: ['test-workflow'] }
|
|
1218
|
+
}
|
|
1219
|
+
]
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
expect(() => {
|
|
1224
|
+
new ResourceRegistry(registry)
|
|
1225
|
+
}).not.toThrow()
|
|
1226
|
+
})
|
|
1227
|
+
|
|
1228
|
+
it('validates routesTo.agents exist', () => {
|
|
1229
|
+
const agent = createMockAgent('fulfillment-agent')
|
|
1230
|
+
const registry: OrganizationRegistry = {
|
|
1231
|
+
'test-org': {
|
|
1232
|
+
agents: [agent],
|
|
1233
|
+
humanCheckpoints: [
|
|
1234
|
+
{
|
|
1235
|
+
resourceId: 'approval-queue',
|
|
1236
|
+
type: 'human',
|
|
1237
|
+
name: 'Approval Queue',
|
|
1238
|
+
description: 'Human approval checkpoint',
|
|
1239
|
+
version: '1.0.0',
|
|
1240
|
+
status: 'prod',
|
|
1241
|
+
routesTo: { agents: ['fulfillment-agent'] }
|
|
1242
|
+
}
|
|
1243
|
+
]
|
|
1244
|
+
}
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
expect(() => {
|
|
1248
|
+
new ResourceRegistry(registry)
|
|
1249
|
+
}).not.toThrow()
|
|
1250
|
+
})
|
|
1251
|
+
|
|
1252
|
+
it('validates routesTo.workflows exist', () => {
|
|
1253
|
+
const workflow = createMockWorkflow('fulfillment-workflow')
|
|
1254
|
+
const registry: OrganizationRegistry = {
|
|
1255
|
+
'test-org': {
|
|
1256
|
+
workflows: [workflow],
|
|
1257
|
+
humanCheckpoints: [
|
|
1258
|
+
{
|
|
1259
|
+
resourceId: 'approval-queue',
|
|
1260
|
+
type: 'human',
|
|
1261
|
+
name: 'Approval Queue',
|
|
1262
|
+
description: 'Human approval checkpoint',
|
|
1263
|
+
version: '1.0.0',
|
|
1264
|
+
status: 'prod',
|
|
1265
|
+
routesTo: { workflows: ['fulfillment-workflow'] }
|
|
1266
|
+
}
|
|
1267
|
+
]
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
expect(() => {
|
|
1272
|
+
new ResourceRegistry(registry)
|
|
1273
|
+
}).not.toThrow()
|
|
1274
|
+
})
|
|
1275
|
+
|
|
1276
|
+
it('throws for requestedBy referencing non-existent agent', () => {
|
|
1277
|
+
const registry: OrganizationRegistry = {
|
|
1278
|
+
'test-org': {
|
|
1279
|
+
humanCheckpoints: [
|
|
1280
|
+
{
|
|
1281
|
+
resourceId: 'approval-queue',
|
|
1282
|
+
type: 'human',
|
|
1283
|
+
name: 'Approval Queue',
|
|
1284
|
+
description: 'Human approval checkpoint',
|
|
1285
|
+
version: '1.0.0',
|
|
1286
|
+
status: 'prod',
|
|
1287
|
+
requestedBy: { agents: ['non-existent-agent'] }
|
|
1288
|
+
}
|
|
1289
|
+
]
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
expect(() => {
|
|
1294
|
+
new ResourceRegistry(registry)
|
|
1295
|
+
}).toThrow("[test-org] Human checkpoint 'approval-queue' requestedBy non-existent agent: non-existent-agent")
|
|
1296
|
+
})
|
|
1297
|
+
|
|
1298
|
+
it('throws for routesTo referencing non-existent workflow', () => {
|
|
1299
|
+
const registry: OrganizationRegistry = {
|
|
1300
|
+
'test-org': {
|
|
1301
|
+
humanCheckpoints: [
|
|
1302
|
+
{
|
|
1303
|
+
resourceId: 'approval-queue',
|
|
1304
|
+
type: 'human',
|
|
1305
|
+
name: 'Approval Queue',
|
|
1306
|
+
description: 'Human approval checkpoint',
|
|
1307
|
+
version: '1.0.0',
|
|
1308
|
+
status: 'prod',
|
|
1309
|
+
routesTo: { workflows: ['non-existent-workflow'] }
|
|
1310
|
+
}
|
|
1311
|
+
]
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
expect(() => {
|
|
1316
|
+
new ResourceRegistry(registry)
|
|
1317
|
+
}).toThrow("[test-org] Human checkpoint 'approval-queue' routesTo non-existent workflow: non-existent-workflow")
|
|
1318
|
+
})
|
|
1319
|
+
|
|
1320
|
+
it('throws for human checkpoint with conflicting ID', () => {
|
|
1321
|
+
const workflow = createMockWorkflow('conflicting-id')
|
|
1322
|
+
const registry: OrganizationRegistry = {
|
|
1323
|
+
'test-org': {
|
|
1324
|
+
workflows: [workflow],
|
|
1325
|
+
humanCheckpoints: [
|
|
1326
|
+
{
|
|
1327
|
+
resourceId: 'conflicting-id',
|
|
1328
|
+
type: 'human',
|
|
1329
|
+
name: 'Conflicting Checkpoint',
|
|
1330
|
+
description: 'Conflicts with workflow',
|
|
1331
|
+
version: '1.0.0',
|
|
1332
|
+
status: 'dev'
|
|
1333
|
+
}
|
|
1334
|
+
]
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
|
|
1338
|
+
expect(() => {
|
|
1339
|
+
new ResourceRegistry(registry)
|
|
1340
|
+
}).toThrow("[test-org] Human checkpoint ID 'conflicting-id' conflicts with internal resource ID")
|
|
1341
|
+
})
|
|
1342
|
+
})
|
|
1343
|
+
})
|