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