@elevasis/core 0.23.0 → 0.24.1

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