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