@open-mercato/cli 0.11.1-develop.8593.1.50784dae35 → 0.11.1-develop.8665.1.2455b2503c

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 (263) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/AGENTS.md +2 -0
  3. package/dist/agentic/guides/architecture.md +2 -2
  4. package/dist/agentic/guides/extensions.md +7 -2
  5. package/dist/agentic/guides/framework-extension-points.md +1 -0
  6. package/dist/agentic/guides/infrastructure-providers.md +20 -0
  7. package/dist/agentic/guides/integrations.md +2 -2
  8. package/dist/agentic/guides/module-facts.json +2564 -265
  9. package/dist/agentic/guides/module-facts.v2.json +2580 -265
  10. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  11. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  12. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  13. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  14. package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
  15. package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
  16. package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
  17. package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
  18. package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
  19. package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
  20. package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
  21. package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
  22. package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
  23. package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
  24. package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
  25. package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
  26. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  27. package/dist/agentic/guides/modules/attachments/workers.md +1 -1
  28. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  29. package/dist/agentic/guides/modules/auth/index.md +1 -1
  30. package/dist/agentic/guides/modules/availability/index.md +1 -1
  31. package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
  32. package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
  33. package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
  34. package/dist/agentic/guides/modules/backups/index.md +5 -2
  35. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  36. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  37. package/dist/agentic/guides/modules/cart/index.md +1 -1
  38. package/dist/agentic/guides/modules/catalog/acl-features.md +2 -1
  39. package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
  40. package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
  41. package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
  42. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
  43. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
  44. package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
  45. package/dist/agentic/guides/modules/catalog/entities.md +1 -0
  46. package/dist/agentic/guides/modules/catalog/events.md +4 -1
  47. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
  48. package/dist/agentic/guides/modules/catalog/index.md +9 -9
  49. package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
  50. package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
  51. package/dist/agentic/guides/modules/catalog/workers.md +1 -0
  52. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  53. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  54. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  55. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  56. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  57. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  58. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  59. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  60. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  61. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  62. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  63. package/dist/agentic/guides/modules/configs/index.md +1 -1
  64. package/dist/agentic/guides/modules/content/index.md +1 -1
  65. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  66. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  67. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  68. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  69. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  70. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  71. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  72. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  73. package/dist/agentic/guides/modules/customers/index.md +3 -3
  74. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  75. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  76. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  77. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  78. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  79. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  80. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  81. package/dist/agentic/guides/modules/devices/index.md +1 -1
  82. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  83. package/dist/agentic/guides/modules/directory/index.md +1 -1
  84. package/dist/agentic/guides/modules/documents/index.md +1 -1
  85. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  86. package/dist/agentic/guides/modules/entities/index.md +1 -1
  87. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  88. package/dist/agentic/guides/modules/events/index.md +1 -1
  89. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  90. package/dist/agentic/guides/modules/forms/index.md +1 -1
  91. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  92. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  93. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  94. package/dist/agentic/guides/modules/generators/index.md +1 -1
  95. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  96. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  97. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  98. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  99. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  100. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  101. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  102. package/dist/agentic/guides/modules/messages/index.md +1 -1
  103. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  104. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  105. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  106. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  107. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  108. package/dist/agentic/guides/modules/planner/index.md +1 -1
  109. package/dist/agentic/guides/modules/portal/index.md +1 -1
  110. package/dist/agentic/guides/modules/progress/index.md +1 -1
  111. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  112. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  113. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  114. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  115. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  116. package/dist/agentic/guides/modules/resources/index.md +1 -1
  117. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  118. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  119. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  120. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  121. package/dist/agentic/guides/modules/sales/index.md +3 -3
  122. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  123. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  124. package/dist/agentic/guides/modules/search/index.md +1 -1
  125. package/dist/agentic/guides/modules/security/index.md +1 -1
  126. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  127. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  128. package/dist/agentic/guides/modules/sso/index.md +1 -1
  129. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  130. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  131. package/dist/agentic/guides/modules/staff/index.md +1 -1
  132. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  133. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  134. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  135. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  136. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  137. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  138. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  139. package/dist/agentic/guides/modules/translations/index.md +1 -1
  140. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  141. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  142. package/dist/agentic/guides/modules/wms/index.md +1 -1
  143. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  144. package/dist/agentic/guides/reference-module-facts.json +811 -21
  145. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  146. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  147. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  148. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  149. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  150. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  151. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  152. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  153. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  154. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  155. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  156. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  157. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  158. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  159. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  160. package/dist/agentic/guides/upstream/manifest.json +3 -3
  161. package/dist/agentic/shared/AGENTS.md.template +11 -15
  162. package/dist/agentic/shared/ai/harness/README.md +4 -2
  163. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  164. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  165. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  166. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  167. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  168. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  169. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  170. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  171. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  172. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  173. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  174. package/dist/lib/cache-provider-manifest.js +9 -0
  175. package/dist/lib/cache-provider-manifest.js.map +7 -0
  176. package/dist/lib/generate-watch-plan.js +4 -0
  177. package/dist/lib/generate-watch-plan.js.map +2 -2
  178. package/dist/lib/generate-watch-runner.js +1 -0
  179. package/dist/lib/generate-watch-runner.js.map +2 -2
  180. package/dist/lib/generate-watch-structure.js +2 -0
  181. package/dist/lib/generate-watch-structure.js.map +2 -2
  182. package/dist/lib/generators/ast/writers.js +5 -1
  183. package/dist/lib/generators/ast/writers.js.map +2 -2
  184. package/dist/lib/generators/cache-providers.js +80 -0
  185. package/dist/lib/generators/cache-providers.js.map +7 -0
  186. package/dist/lib/generators/form-section-ast.js +156 -0
  187. package/dist/lib/generators/form-section-ast.js.map +7 -0
  188. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  189. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  190. package/dist/lib/generators/form-section-extension-source.js +245 -0
  191. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  192. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  193. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  194. package/dist/lib/generators/form-sections.js +773 -0
  195. package/dist/lib/generators/form-sections.js.map +7 -0
  196. package/dist/lib/generators/index.js +2 -0
  197. package/dist/lib/generators/index.js.map +2 -2
  198. package/dist/lib/generators/module-entities.js +21 -2
  199. package/dist/lib/generators/module-entities.js.map +2 -2
  200. package/dist/lib/generators/module-extension-facts.js +2 -1
  201. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  202. package/dist/lib/generators/module-facts.js +30 -1
  203. package/dist/lib/generators/module-facts.js.map +2 -2
  204. package/dist/lib/generators/module-override-targets.js +24 -2
  205. package/dist/lib/generators/module-override-targets.js.map +2 -2
  206. package/dist/lib/generators/module-registry.js +75 -3
  207. package/dist/lib/generators/module-registry.js.map +2 -2
  208. package/dist/lib/generators/openapi.js +27 -17
  209. package/dist/lib/generators/openapi.js.map +2 -2
  210. package/dist/lib/post-generate-invalidation.js +20 -1
  211. package/dist/lib/post-generate-invalidation.js.map +2 -2
  212. package/dist/lib/resolver.js +195 -1
  213. package/dist/lib/resolver.js.map +3 -3
  214. package/dist/lib/single-instance-strategy-guard.js +26 -3
  215. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  216. package/dist/mercato.js +34 -6
  217. package/dist/mercato.js.map +2 -2
  218. package/jest.config.cjs +2 -0
  219. package/package.json +7 -7
  220. package/src/__tests__/mercato.test.ts +18 -0
  221. package/src/__tests__/rotation-json-output.test.ts +52 -0
  222. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  223. package/src/lib/__tests__/generate-watch-plan.test.ts +3 -2
  224. package/src/lib/__tests__/generate-watch-runner.test.ts +13 -1
  225. package/src/lib/__tests__/generate-watch-structure.test.ts +34 -0
  226. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  227. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  228. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  229. package/src/lib/cache-provider-manifest.ts +8 -0
  230. package/src/lib/generate-watch-plan.ts +6 -3
  231. package/src/lib/generate-watch-runner.ts +1 -0
  232. package/src/lib/generate-watch-structure.ts +5 -1
  233. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  234. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  235. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  236. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  237. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  238. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  239. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  240. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  241. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  242. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  243. package/src/lib/generators/__tests__/openapi.test.ts +60 -13
  244. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  245. package/src/lib/generators/ast/writers.ts +6 -1
  246. package/src/lib/generators/cache-providers.ts +111 -0
  247. package/src/lib/generators/form-section-ast.ts +166 -0
  248. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  249. package/src/lib/generators/form-section-extension-source.ts +308 -0
  250. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  251. package/src/lib/generators/form-sections.ts +896 -0
  252. package/src/lib/generators/index.ts +1 -0
  253. package/src/lib/generators/module-entities.ts +22 -4
  254. package/src/lib/generators/module-extension-facts.ts +1 -0
  255. package/src/lib/generators/module-facts.ts +40 -0
  256. package/src/lib/generators/module-override-targets.ts +19 -0
  257. package/src/lib/generators/module-registry.ts +80 -4
  258. package/src/lib/generators/openapi.ts +31 -20
  259. package/src/lib/post-generate-invalidation.ts +28 -1
  260. package/src/lib/resolver.ts +218 -0
  261. package/src/lib/single-instance-strategy-guard.ts +51 -1
  262. package/src/mercato.ts +32 -4
  263. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -1,10 +1,24 @@
1
+ import {
2
+ defineCacheProvider,
3
+ defineCacheProviderRegistration,
4
+ resetCacheProviderSelectionForTests,
5
+ setCacheProviderRegistrations,
6
+ type CacheProviderPlacement,
7
+ } from '@open-mercato/cache/provider'
8
+ import { loadCacheProviderManifest } from '../cache-provider-manifest'
1
9
  import {
2
10
  assertSingleInstanceStrategies,
3
11
  evaluateSingleInstanceGuard,
12
+ readInfraStrategySnapshot,
13
+ resolveEffectiveCacheProviderSnapshot,
4
14
  SingleInstanceStrategyError,
5
15
  type InfraStrategySnapshot,
6
16
  } from '../single-instance-strategy-guard'
7
17
 
18
+ jest.mock('../cache-provider-manifest', () => ({ loadCacheProviderManifest: jest.fn() }))
19
+
20
+ const loadManifestMock = jest.mocked(loadCacheProviderManifest)
21
+
8
22
  const singleInstanceSnapshot: InfraStrategySnapshot = {
9
23
  cacheStrategy: 'memory',
10
24
  queueStrategy: 'local',
@@ -94,6 +108,37 @@ describe('evaluateSingleInstanceGuard', () => {
94
108
  })
95
109
  })
96
110
 
111
+ describe('stock cache strategy characterization', () => {
112
+ it('reads CACHE_STRATEGY into the snapshot and defaults to memory', () => {
113
+ expect(readInfraStrategySnapshot({ CACHE_STRATEGY: 'redis' }).cacheStrategy).toBe('redis')
114
+ expect(readInfraStrategySnapshot({ CACHE_STRATEGY: ' sqlite ' }).cacheStrategy).toBe('sqlite')
115
+ expect(readInfraStrategySnapshot({}).cacheStrategy).toBe('memory')
116
+ expect(readInfraStrategySnapshot({ CACHE_STRATEGY: '' }).cacheStrategy).toBe('memory')
117
+ })
118
+
119
+ it('treats a redis cache as multi-instance safe', () => {
120
+ const result = evaluateSingleInstanceGuard(
121
+ { ...multiInstanceSafeSnapshot, cacheStrategy: 'redis' },
122
+ { NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' },
123
+ )
124
+ expect(result.offenders.find((offender) => offender.component === 'cache')).toBeUndefined()
125
+ })
126
+
127
+ it.each([['memory'], ['sqlite'], ['jsonfile']])(
128
+ 'reports a %s cache as a CACHE_STRATEGY offender',
129
+ (cacheStrategy) => {
130
+ const result = evaluateSingleInstanceGuard(
131
+ { ...multiInstanceSafeSnapshot, cacheStrategy },
132
+ { NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' },
133
+ )
134
+ expect(result.action).toBe('fail')
135
+ expect(result.offenders).toEqual([
136
+ { component: 'cache', envVar: 'CACHE_STRATEGY', configured: cacheStrategy, safeValues: ['redis'] },
137
+ ])
138
+ },
139
+ )
140
+ })
141
+
97
142
  describe('assertSingleInstanceStrategies', () => {
98
143
  function createLogger() {
99
144
  return {
@@ -136,3 +181,87 @@ describe('assertSingleInstanceStrategies', () => {
136
181
  expect(logger.error).not.toHaveBeenCalled()
137
182
  })
138
183
  })
184
+
185
+ describe('single-instance guard with a registered cache provider', () => {
186
+ const productionMultiInstance = { NODE_ENV: 'production', OM_MULTI_INSTANCE: '1' }
187
+
188
+ it('treats a provider with shared placement as multi-instance safe regardless of CACHE_STRATEGY', () => {
189
+ const result = evaluateSingleInstanceGuard(
190
+ { ...multiInstanceSafeSnapshot, cacheStrategy: 'memory', cacheProvider: { id: 'acme/shared', placement: 'shared' } },
191
+ productionMultiInstance,
192
+ )
193
+ expect(result.action).toBe('ok')
194
+ expect(result.offenders).toHaveLength(0)
195
+ })
196
+
197
+ it('reports a local provider as a CACHE_PROVIDER offender even when CACHE_STRATEGY=redis', () => {
198
+ const result = evaluateSingleInstanceGuard(
199
+ { ...multiInstanceSafeSnapshot, cacheProvider: { id: 'acme/local', placement: 'local' } },
200
+ productionMultiInstance,
201
+ )
202
+ expect(result.action).toBe('fail')
203
+ expect(result.offenders).toEqual([
204
+ expect.objectContaining({ component: 'cache', envVar: 'CACHE_PROVIDER', configured: 'acme/local' }),
205
+ ])
206
+ })
207
+
208
+ it('carries the provider snapshot through readInfraStrategySnapshot only when one is resolved', () => {
209
+ expect(readInfraStrategySnapshot({}, { cacheProvider: null })).not.toHaveProperty('cacheProvider')
210
+ expect(readInfraStrategySnapshot({}, { cacheProvider: { id: 'acme/x', placement: 'shared' } }).cacheProvider)
211
+ .toEqual({ id: 'acme/x', placement: 'shared' })
212
+ })
213
+ })
214
+
215
+ describe('resolveEffectiveCacheProviderSnapshot', () => {
216
+ function registerProvider(placement: CacheProviderPlacement) {
217
+ const definition = defineCacheProvider<Record<string, never>>({
218
+ id: 'acme/fake',
219
+ settings: { safeParse: () => ({ success: true, data: {} }) },
220
+ capability: () => ({ placement }),
221
+ create: () => { throw new Error('must not connect during the guard') },
222
+ })
223
+ setCacheProviderRegistrations([
224
+ defineCacheProviderRegistration({ id: 'acme/fake', load: async () => definition, settings: () => ({}) }),
225
+ ])
226
+ }
227
+
228
+ beforeEach(() => {
229
+ resetCacheProviderSelectionForTests()
230
+ loadManifestMock.mockReset()
231
+ })
232
+
233
+ afterAll(() => {
234
+ resetCacheProviderSelectionForTests()
235
+ })
236
+
237
+ it('returns null without loading the manifest for stock deployments', async () => {
238
+ await expect(resolveEffectiveCacheProviderSnapshot('/app', { CACHE_STRATEGY: 'redis' })).resolves.toBeNull()
239
+ expect(loadManifestMock).not.toHaveBeenCalled()
240
+ })
241
+
242
+ it.each([['shared'], ['local']] as const)('loads the manifest and reports the %s placement', async (placement) => {
243
+ loadManifestMock.mockImplementation(async () => {
244
+ registerProvider(placement)
245
+ return []
246
+ })
247
+
248
+ const snapshot = await resolveEffectiveCacheProviderSnapshot('/app', {
249
+ CACHE_PROVIDER: 'acme/fake',
250
+ CACHE_PROVIDER_NAMESPACE: 'guard-ns',
251
+ })
252
+
253
+ expect(loadManifestMock).toHaveBeenCalledWith('/app')
254
+ expect(snapshot).toEqual({ id: 'acme/fake', placement })
255
+ })
256
+
257
+ it('propagates a provider selection error so the start aborts', async () => {
258
+ loadManifestMock.mockImplementation(async () => {
259
+ setCacheProviderRegistrations([])
260
+ return []
261
+ })
262
+
263
+ await expect(
264
+ resolveEffectiveCacheProviderSnapshot('/app', { CACHE_PROVIDER: 'acme/fake', CACHE_PROVIDER_NAMESPACE: 'guard-ns' }),
265
+ ).rejects.toMatchObject({ name: 'CacheProviderError', code: 'not_registered' })
266
+ })
267
+ })
@@ -0,0 +1,8 @@
1
+ import type { CacheProviderRegistration } from '@open-mercato/shared/lib/cache/providers'
2
+
3
+ /** Load app provider registrations for CLI commands that do not bootstrap the full app. */
4
+ export async function loadCacheProviderManifest(appDir: string): Promise<CacheProviderRegistration[]> {
5
+ const { loadCacheProviderManifestFromAppRoot } = await import('@open-mercato/shared/lib/bootstrap/dynamicLoader')
6
+ const format = typeof process.env.JEST_WORKER_ID === 'string' ? 'cjs' : 'esm'
7
+ return loadCacheProviderManifestFromAppRoot(appDir, { format })
8
+ }
@@ -2,7 +2,7 @@ export type GenerateWatchCategory =
2
2
  | 'api-route' | 'frontend-page' | 'backend-page' | 'commands' | 'di' | 'entities'
3
3
  | 'search' | 'events' | 'subscribers' | 'workers' | 'dashboard-widgets'
4
4
  | 'injection-widgets' | 'cli' | 'i18n' | 'registry-convention' | 'extension'
5
- | 'openapi' | 'web-research-adapters' | 'generator-plugin' | 'configuration' | 'unknown'
5
+ | 'openapi' | 'web-research-adapters' | 'cache-providers' | 'generator-plugin' | 'configuration' | 'unknown'
6
6
 
7
7
  export type GenerateWatchRecord = {
8
8
  key: string
@@ -29,7 +29,7 @@ export type GenerateWatchChange = {
29
29
 
30
30
  export type GenerateWatchGroup =
31
31
  | 'entity-ids' | 'registry' | 'entities' | 'di' | 'package-sources'
32
- | 'web-research-adapters' | 'openapi'
32
+ | 'web-research-adapters' | 'cache-providers' | 'openapi'
33
33
 
34
34
  export type GenerateWatchPlan = {
35
35
  mode: 'full' | 'incremental' | 'none'
@@ -40,7 +40,7 @@ export type GenerateWatchPlan = {
40
40
  }
41
41
 
42
42
  const GROUP_ORDER: readonly GenerateWatchGroup[] = [
43
- 'entity-ids', 'registry', 'entities', 'di', 'package-sources', 'web-research-adapters', 'openapi',
43
+ 'entity-ids', 'registry', 'entities', 'di', 'package-sources', 'web-research-adapters', 'cache-providers', 'openapi',
44
44
  ]
45
45
 
46
46
  const REGISTRY_ORDER = [
@@ -88,6 +88,9 @@ export function planGenerateWatchChanges(
88
88
  case 'web-research-adapters':
89
89
  groups.add('web-research-adapters')
90
90
  break
91
+ case 'cache-providers':
92
+ groups.add('cache-providers')
93
+ break
91
94
  case 'frontend-page':
92
95
  registry('main', 'runtime', 'app', 'frontend-routes')
93
96
  break
@@ -53,6 +53,7 @@ export async function runGenerateWatchSuite(
53
53
  if (selected('di')) record(await generators.generateModuleDi({ resolver, quiet }))
54
54
  if (selected('package-sources')) record(await generators.generateModulePackageSources({ resolver, quiet }))
55
55
  if (selected('web-research-adapters')) record(await generators.generateWebResearchAdapters({ resolver, quiet }))
56
+ if (selected('cache-providers')) record(await generators.generateCacheProviders({ resolver, quiet }))
56
57
  if (cascadeReason) {
57
58
  if (onOpenApiCascade) onOpenApiCascade(cascadeReason)
58
59
  else if (!quiet) console.log(`[generate:watch] Cascading; groups=openapi; reason=${cascadeReason}`)
@@ -25,6 +25,7 @@ export type GenerateWatchStructureOptions = {
25
25
  additionalInputs?: string[]
26
26
  /** Inputs consumed specifically by OpenAPI generation. */
27
27
  openapiInputs?: string[]
28
+ cacheProviderInputs?: string[]
28
29
  /** Candidate package manifests consumed specifically by web-research adapter discovery. */
29
30
  webResearchAdapterInputs?: string[]
30
31
  /** Adapter discovery failures that make this capture non-authoritative. */
@@ -534,6 +535,8 @@ function addModule(collector: SnapshotCollector, roots: WatchRoots, index: numbe
534
535
  ]))
535
536
  const convention = (relativePath: string, kind: InputKind) => collector.pair(identity, roots, `${relativePath}.ts`, kind)
536
537
  for (const relativePath of REGISTRY_CONVENTIONS) convention(relativePath, { category: 'registry-convention' })
538
+ // Section definitions can change shared field sets, route manifests, and OpenAPI together.
539
+ convention('form-sections', { category: 'configuration' })
537
540
  for (const [relativePath, extensionId] of Object.entries(EXTENSION_CONVENTIONS)) {
538
541
  convention(relativePath, { category: 'extension', extensionId })
539
542
  }
@@ -651,7 +654,7 @@ export function collectGenerateWatchStructureSnapshot(
651
654
  inputs: readonly string[] | undefined,
652
655
  kind: InputKind,
653
656
  keyPrefix: string,
654
- mode: 'content' | 'stat' = 'content',
657
+ mode: 'content' | 'stat' | 'membership' = 'content',
655
658
  ) => {
656
659
  for (const input of ordered(inputs)) {
657
660
  const stat = collector.stat(input)
@@ -666,6 +669,7 @@ export function collectGenerateWatchStructureSnapshot(
666
669
  'web-research-adapter-input',
667
670
  'stat',
668
671
  )
672
+ addSpecializedInputs(options.cacheProviderInputs, { category: 'cache-providers' }, 'cache-provider-input', 'membership')
669
673
  collector.supervisor(path.dirname(options.modulesFile))
670
674
  collector.dependencies(path.dirname(options.modulesFile))
671
675
  // A dynamic descriptor is valid source, not a transient failed capture. Until
@@ -0,0 +1,102 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import type { PackageResolver } from '../../resolver'
5
+ import {
6
+ CACHE_PROVIDERS_CHECKSUM_FILE,
7
+ CACHE_PROVIDERS_GENERATED_FILE,
8
+ generateCacheProviders,
9
+ } from '../cache-providers'
10
+
11
+ let appDir: string
12
+ let outputDir: string
13
+
14
+ function createMockResolver(): PackageResolver {
15
+ return {
16
+ getAppDir: () => appDir,
17
+ getOutputDir: () => outputDir,
18
+ } as unknown as PackageResolver
19
+ }
20
+
21
+ function readGenerated(): string {
22
+ return fs.readFileSync(path.join(outputDir, CACHE_PROVIDERS_GENERATED_FILE), 'utf8')
23
+ }
24
+
25
+ beforeEach(() => {
26
+ appDir = fs.mkdtempSync(path.join(os.tmpdir(), 'om-cache-providers-'))
27
+ fs.mkdirSync(path.join(appDir, 'src/providers'), { recursive: true })
28
+ outputDir = path.join(appDir, '.mercato', 'generated')
29
+ })
30
+
31
+ afterEach(() => {
32
+ fs.rmSync(appDir, { recursive: true, force: true })
33
+ })
34
+
35
+ describe('generateCacheProviders', () => {
36
+ it('emits an empty typed manifest when the app has no src/providers/cache file', async () => {
37
+ const result = await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
38
+
39
+ const content = readGenerated()
40
+ expect(result.filesWritten).toEqual([path.join(outputDir, CACHE_PROVIDERS_GENERATED_FILE)])
41
+ expect(content).toContain("import type { CacheProviderRegistration } from '@open-mercato/cache/provider'")
42
+ expect(content).toContain('export const cacheProviders: CacheProviderRegistration[] = []')
43
+ expect(content).not.toContain('src/providers/cache\'')
44
+ expect(fs.existsSync(path.join(outputDir, CACHE_PROVIDERS_CHECKSUM_FILE))).toBe(true)
45
+ })
46
+
47
+ it('re-exports the app manifest through a literal extensionless relative import', async () => {
48
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.ts'), 'throw new Error("must not be evaluated")\n')
49
+
50
+ await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
51
+
52
+ const content = readGenerated()
53
+ expect(content).toContain("import { cacheProviders as appCacheProviders } from '../../src/providers/cache'")
54
+ expect(content).toContain('export const cacheProviders: CacheProviderRegistration[] = appCacheProviders')
55
+ expect(path.resolve(outputDir, '../../src/providers/cache.ts')).toBe(path.join(appDir, 'src/providers/cache.ts'))
56
+ })
57
+
58
+ it('accepts a JavaScript manifest', async () => {
59
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.js'), 'export const cacheProviders = []\n')
60
+
61
+ await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
62
+
63
+ expect(readGenerated()).toContain("from '../../src/providers/cache'")
64
+ })
65
+
66
+ it('rejects ambiguous and unsupported manifest files', async () => {
67
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.ts'), '')
68
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.js'), '')
69
+ await expect(generateCacheProviders({ resolver: createMockResolver(), quiet: true })).rejects.toThrow(
70
+ /Multiple cache provider manifests/,
71
+ )
72
+
73
+ fs.rmSync(path.join(appDir, 'src/providers/cache.js'))
74
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.mts'), '')
75
+ await expect(generateCacheProviders({ resolver: createMockResolver(), quiet: true })).rejects.toThrow(
76
+ /Unsupported cache provider manifest src\/providers\/cache\.mts/,
77
+ )
78
+ })
79
+
80
+ it('is deterministic and leaves the output untouched on rerun', async () => {
81
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.ts'), 'export const cacheProviders = []\n')
82
+ await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
83
+ const first = readGenerated()
84
+
85
+ const rerun = await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
86
+
87
+ expect(rerun.filesWritten).toEqual([])
88
+ expect(rerun.filesUnchanged).toEqual([path.join(outputDir, CACHE_PROVIDERS_GENERATED_FILE)])
89
+ expect(readGenerated()).toBe(first)
90
+ })
91
+
92
+ it('switches back to the empty manifest when the app file is removed', async () => {
93
+ fs.writeFileSync(path.join(appDir, 'src/providers/cache.ts'), 'export const cacheProviders = []\n')
94
+ await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
95
+ fs.rmSync(path.join(appDir, 'src/providers/cache.ts'))
96
+
97
+ const result = await generateCacheProviders({ resolver: createMockResolver(), quiet: true })
98
+
99
+ expect(result.filesWritten).toHaveLength(1)
100
+ expect(readGenerated()).toContain('export const cacheProviders: CacheProviderRegistration[] = []')
101
+ })
102
+ })
@@ -0,0 +1,85 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import type { PackageResolver } from '../../resolver'
5
+ import { generateModuleRegistries } from '../module-registry'
6
+
7
+ const modulePath = 'app/src/modules/example'
8
+ const originalRoute = `
9
+ import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
10
+ export const crudRoute = makeCrudRoute({
11
+ metadata: { PUT: { requireAuth: true } },
12
+ orm: { entity: ExampleRecord },
13
+ actions: { update: { commandId: 'example.records.update' } },
14
+ })
15
+ export const { metadata, PUT } = crudRoute
16
+ `
17
+
18
+ let root: string
19
+
20
+ function write(file: string, source: string): void {
21
+ const target = path.join(root, modulePath, file)
22
+ fs.mkdirSync(path.dirname(target), { recursive: true })
23
+ fs.writeFileSync(target, source)
24
+ }
25
+
26
+ function generate() {
27
+ const appRoot = path.join(root, 'app')
28
+ const output = path.join(appRoot, '.mercato', 'generated')
29
+ const resolver: PackageResolver = {
30
+ isMonorepo: () => true,
31
+ getRootDir: () => root,
32
+ getAppDir: () => appRoot,
33
+ getOutputDir: () => output,
34
+ getModulesConfigPath: () => path.join(appRoot, 'src/modules.ts'),
35
+ discoverPackages: () => [],
36
+ loadEnabledModules: () => [{ id: 'example', from: '@app' }],
37
+ getModulePaths: () => ({ appBase: path.join(root, modulePath), pkgBase: path.join(root, 'package') }),
38
+ getModuleImportBase: () => ({ appBase: '@/modules/example', pkgBase: '@open-mercato/core/modules/example' }),
39
+ getPackageOutputDir: () => output,
40
+ getPackageRoot: () => path.join(root, 'package'),
41
+ }
42
+ return generateModuleRegistries({ resolver, quiet: true })
43
+ }
44
+
45
+ function addDerivedHost(routePath: string): void {
46
+ write(`api/${routePath}/route.ts`, originalRoute)
47
+ write('descriptor.client.ts', "export const crudFormSectionRuntime = { id: 'example.edit', roundTripId: 'example.edit@v1' }")
48
+ write('form-sections.ts', `
49
+ import { defineCrudFormSections, lazyCrudFormSectionRuntime } from '@open-mercato/shared/modules/form-sections'
50
+ import { defineCrudRouteSectionHost } from '@open-mercato/shared/lib/crud/form-sections/derived-route-host'
51
+ import { crudRoute } from './api/${routePath}/route'
52
+ export const crudFormSections = defineCrudFormSections({
53
+ hostFacts: [{ id: 'example.edit', roundTripId: 'example.edit@v1', hostResourceKind: 'example.records' }],
54
+ derivedHosts: [defineCrudRouteSectionHost({
55
+ hostId: 'example.record', formVariant: 'default', formOperation: 'update', hostDescriptorId: 'example.edit',
56
+ route: crudRoute, sections: [{ id: 'details', writes: 'parent' }],
57
+ })],
58
+ runtimes: [{ id: 'example.edit', roundTripId: 'example.edit@v1',
59
+ load: lazyCrudFormSectionRuntime(() => import('./descriptor.client')),
60
+ }],
61
+ })
62
+ `)
63
+ }
64
+
65
+ beforeEach(() => {
66
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'crud-form-section-route-'))
67
+ })
68
+
69
+ afterEach(() => {
70
+ fs.rmSync(root, { recursive: true, force: true })
71
+ })
72
+
73
+ it.each(['Records/section-policy', 'records/[id]', 'records/[...rest]'])('rejects overlapping API path %s', async (pathPattern) => {
74
+ addDerivedHost('records')
75
+ write(`api/${pathPattern}/route.ts`, `
76
+ export const metadata = { PUT: { requireAuth: true } }
77
+ export async function PUT() { return new Response() }
78
+ `)
79
+ await expect(generate()).rejects.toThrow(/conflicts with an existing API route/)
80
+ })
81
+
82
+ it('rejects a parameterized original host route', async () => {
83
+ addDerivedHost('records/[id]')
84
+ await expect(generate()).rejects.toThrow(/literal API path without parameters/)
85
+ })
@@ -0,0 +1,53 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { createGeneratorResult } from '../../utils'
5
+ import { writeCrudFormSectionRegistries } from '../form-sections'
6
+
7
+ const externalFact = {
8
+ integrationId: 'example.erp',
9
+ contractId: 'example.brand_mirror@v1',
10
+ maxAttempts: 3,
11
+ preCommitValidation: 'read-only',
12
+ coalesce: 'latest-state',
13
+ fencing: 'remote-monotonic-revision/v1',
14
+ }
15
+
16
+ function fixture(atomicity: string, externalDelivery?: Record<string, unknown>) {
17
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'form-section-outbox-'))
18
+ const source = path.join(root, 'form-sections.ts')
19
+ const fact = {
20
+ id: 'example.brand', roundTripId: 'example.brand@v1', ownerModuleId: 'example',
21
+ targetEntityId: 'example.brand_mirror', atomicity, externalDelivery,
22
+ }
23
+ fs.writeFileSync(source, `
24
+ export const crudFormSections = defineCrudFormSections({
25
+ sinks: [defineCrudFormSectionSink({ fact: ${JSON.stringify(fact)}, schema: serverSchema })],
26
+ })
27
+ `)
28
+ const build = () => writeCrudFormSectionRegistries({
29
+ modules: [{
30
+ modId: 'example', roots: { appBase: root, pkgBase: root },
31
+ resolve: (relative) => relative === 'form-sections.ts'
32
+ ? { fromApp: true, absolutePath: source, importPath: '@/modules/example/form-sections' } : null,
33
+ }],
34
+ identities: [{ id: 'example' }], requiresByModule: new Map(), outputDir: root,
35
+ structureChecksum: 'test', result: createGeneratorResult(), quiet: true,
36
+ })
37
+ return { build, clean: () => fs.rmSync(root, { force: true, recursive: true }) }
38
+ }
39
+
40
+ it.each([
41
+ ['outbox', undefined, /requires a literal externalDelivery/],
42
+ ['outbox', { ...externalFact, fencing: 'lease-only' }, /remote-monotonic-revision\/v1/],
43
+ ['outbox', { ...externalFact, contractId: 'example.other@v1' }, /requires contractId/],
44
+ ['host-transaction', externalFact, /invalid atomicity or externalDelivery/],
45
+ ] as const)('rejects %s declarations with invalid delivery facts', (atomicity, external, error) => {
46
+ const { build, clean } = fixture(atomicity, external)
47
+ try { expect(build).toThrow(error) } finally { clean() }
48
+ })
49
+
50
+ it('accepts a literal monotonic outbox provider contract', () => {
51
+ const { build, clean } = fixture('outbox', externalFact)
52
+ try { expect(build).not.toThrow() } finally { clean() }
53
+ })