@open-mercato/cli 0.6.7-develop.6862.1.c11a64ce0a → 0.6.7

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 (278) hide show
  1. package/.turbo/turbo-build.log +4 -4
  2. package/build.mjs +7 -24
  3. package/dist/agentic/claude-code/hooks/entity-migration-check.ts +88 -32
  4. package/dist/agentic/codex/enforcement-rules.md +16 -2
  5. package/dist/agentic/cursor/hooks/entity-migration-check.mjs +50 -19
  6. package/dist/agentic/cursor/rules/entity-guard.mdc +21 -9
  7. package/dist/agentic/cursor/rules/generated-guard.mdc +5 -3
  8. package/dist/agentic/cursor/rules/open-mercato.mdc +29 -3
  9. package/dist/agentic/guides/cache.md +45 -0
  10. package/dist/agentic/guides/core.md +453 -0
  11. package/dist/agentic/guides/events.md +117 -0
  12. package/dist/agentic/guides/module-facts.json +3833 -115419
  13. package/dist/agentic/guides/module-system.md +127 -12
  14. package/dist/agentic/guides/modules/ai_assistant.md +28 -227
  15. package/dist/agentic/guides/modules/api_docs.md +2 -58
  16. package/dist/agentic/guides/modules/api_keys.md +7 -92
  17. package/dist/agentic/guides/modules/attachments.md +14 -119
  18. package/dist/agentic/guides/modules/audit_logs.md +10 -131
  19. package/dist/agentic/guides/modules/auth.md +33 -276
  20. package/dist/agentic/guides/modules/business_rules.md +14 -149
  21. package/dist/agentic/guides/modules/catalog.md +43 -475
  22. package/dist/agentic/guides/modules/channel_gmail.md +3 -82
  23. package/dist/agentic/guides/modules/channel_imap.md +3 -82
  24. package/dist/agentic/guides/modules/checkout.md +27 -299
  25. package/dist/agentic/guides/modules/communication_channels.md +33 -315
  26. package/dist/agentic/guides/modules/configs.md +8 -104
  27. package/dist/agentic/guides/modules/content.md +2 -57
  28. package/dist/agentic/guides/modules/currencies.md +17 -152
  29. package/dist/agentic/guides/modules/customer_accounts.md +45 -387
  30. package/dist/agentic/guides/modules/customers.md +85 -746
  31. package/dist/agentic/guides/modules/dashboards.md +10 -155
  32. package/dist/agentic/guides/modules/data_sync.md +16 -149
  33. package/dist/agentic/guides/modules/dictionaries.md +12 -107
  34. package/dist/agentic/guides/modules/directory.md +15 -148
  35. package/dist/agentic/guides/modules/entities.md +13 -145
  36. package/dist/agentic/guides/modules/events.md +2 -59
  37. package/dist/agentic/guides/modules/feature_toggles.md +9 -119
  38. package/dist/agentic/guides/modules/gateway_stripe.md +4 -92
  39. package/dist/agentic/guides/modules/generators.md +2 -45
  40. package/dist/agentic/guides/modules/inbox_ops.md +27 -207
  41. package/dist/agentic/guides/modules/integrations.md +16 -146
  42. package/dist/agentic/guides/modules/messages.md +24 -223
  43. package/dist/agentic/guides/modules/notifications.md +8 -96
  44. package/dist/agentic/guides/modules/onboarding.md +6 -77
  45. package/dist/agentic/guides/modules/payment_gateways.md +21 -164
  46. package/dist/agentic/guides/modules/perspectives.md +7 -77
  47. package/dist/agentic/guides/modules/planner.md +18 -136
  48. package/dist/agentic/guides/modules/portal.md +2 -93
  49. package/dist/agentic/guides/modules/progress.md +14 -104
  50. package/dist/agentic/guides/modules/query_index.md +15 -154
  51. package/dist/agentic/guides/modules/record_locks.md +21 -206
  52. package/dist/agentic/guides/modules/resources.md +30 -197
  53. package/dist/agentic/guides/modules/sales.md +84 -678
  54. package/dist/agentic/guides/modules/scheduler.md +14 -133
  55. package/dist/agentic/guides/modules/search.md +6 -170
  56. package/dist/agentic/guides/modules/security.md +35 -294
  57. package/dist/agentic/guides/modules/shipping_carriers.md +18 -134
  58. package/dist/agentic/guides/modules/sso.md +26 -151
  59. package/dist/agentic/guides/modules/staff.md +57 -369
  60. package/dist/agentic/guides/modules/storage_s3.md +5 -95
  61. package/dist/agentic/guides/modules/sync_akeneo.md +3 -85
  62. package/dist/agentic/guides/modules/sync_excel.md +6 -75
  63. package/dist/agentic/guides/modules/system_status_overlays.md +2 -60
  64. package/dist/agentic/guides/modules/translations.md +10 -104
  65. package/dist/agentic/guides/modules/webhooks.md +24 -203
  66. package/dist/agentic/guides/modules/wms.md +46 -441
  67. package/dist/agentic/guides/modules/workflows.md +43 -302
  68. package/dist/agentic/guides/queue.md +53 -0
  69. package/dist/agentic/guides/search.md +115 -0
  70. package/dist/agentic/guides/shared.md +108 -0
  71. package/dist/agentic/guides/ui.md +347 -0
  72. package/dist/agentic/shared/AGENTS.md.template +311 -124
  73. package/dist/agentic/shared/ai/agentic.config.json +0 -2
  74. package/dist/agentic/shared/ai/lessons.md +3 -26
  75. package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +27 -0
  76. package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +27 -0
  77. package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +0 -4
  78. package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +241 -20
  79. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +260 -0
  80. package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +601 -16
  81. package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +146 -0
  82. package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +310 -14
  83. package/dist/agentic/shared/ai/skills/om-help/SKILL.md +97 -15
  84. package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +84 -0
  85. package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +193 -0
  86. package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +152 -33
  87. package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +708 -24
  88. package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +34 -0
  89. package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +762 -0
  90. package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +820 -20
  91. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +50 -0
  92. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +97 -0
  93. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +843 -19
  94. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +271 -0
  95. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +63 -15
  96. package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +467 -16
  97. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +101 -0
  98. package/dist/agentic/shared/ai/skills/tiers.json +21 -143
  99. package/dist/agentic/shared/ai/skills/tiers.schema.json +40 -52
  100. package/dist/agentic/shared/ai/specs/README.md +3 -4
  101. package/dist/agentic/shared/ai/specs/SPEC-000-template.md +10 -226
  102. package/dist/agentic/shared/ai/trackers/github.md +4 -108
  103. package/dist/agentic/shared/scripts/install-skills.sh +694 -4
  104. package/dist/bin.js +1 -13
  105. package/dist/bin.js.map +2 -2
  106. package/dist/lib/__integration__/TC-INT-008.spec.js +8 -88
  107. package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
  108. package/dist/lib/agentic-init.js +3 -13
  109. package/dist/lib/agentic-init.js.map +2 -2
  110. package/dist/lib/agentic-setup.js +186 -418
  111. package/dist/lib/agentic-setup.js.map +2 -2
  112. package/dist/lib/generators/extensions/injection-widgets.js +0 -20
  113. package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
  114. package/dist/lib/generators/module-facts-discovery.js +7 -41
  115. package/dist/lib/generators/module-facts-discovery.js.map +2 -2
  116. package/dist/lib/generators/module-facts.js +45 -1387
  117. package/dist/lib/generators/module-facts.js.map +3 -3
  118. package/dist/lib/generators/module-registry.js +5 -11
  119. package/dist/lib/generators/module-registry.js.map +2 -2
  120. package/dist/lib/resolver.js +0 -2
  121. package/dist/lib/resolver.js.map +2 -2
  122. package/dist/lib/testing/integration.js +0 -5
  123. package/dist/lib/testing/integration.js.map +2 -2
  124. package/dist/mercato.js +1 -23
  125. package/dist/mercato.js.map +2 -2
  126. package/package.json +11 -13
  127. package/src/bin.ts +1 -33
  128. package/src/lib/__integration__/TC-INT-008.spec.ts +9 -107
  129. package/src/lib/__tests__/agentic-init.test.ts +5 -41
  130. package/src/lib/agentic-init.ts +3 -15
  131. package/src/lib/agentic-setup.ts +224 -530
  132. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +2 -88
  133. package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +0 -1
  134. package/src/lib/generators/__tests__/module-facts.discovery.test.ts +10 -54
  135. package/src/lib/generators/__tests__/module-subset.test.ts +0 -18
  136. package/src/lib/generators/extensions/injection-widgets.ts +0 -51
  137. package/src/lib/generators/module-facts-discovery.ts +7 -58
  138. package/src/lib/generators/module-facts.ts +46 -1851
  139. package/src/lib/generators/module-registry.ts +6 -16
  140. package/src/lib/resolver.ts +0 -3
  141. package/src/lib/testing/__tests__/integration.test.ts +0 -4
  142. package/src/lib/testing/integration.ts +0 -5
  143. package/src/mercato.ts +1 -26
  144. package/dist/agentic/guides/ai-workflows.md +0 -76
  145. package/dist/agentic/guides/architecture.md +0 -107
  146. package/dist/agentic/guides/backend-ui.md +0 -80
  147. package/dist/agentic/guides/contracts.md +0 -92
  148. package/dist/agentic/guides/extensions.md +0 -121
  149. package/dist/agentic/guides/framework-extension-points.md +0 -36
  150. package/dist/agentic/guides/integrations.md +0 -81
  151. package/dist/agentic/guides/modules/design_system.md +0 -102
  152. package/dist/agentic/guides/spec-delivery.md +0 -22
  153. package/dist/agentic/guides/testing-debugging.md +0 -80
  154. package/dist/agentic/guides/upstream/AGENTS.md +0 -298
  155. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +0 -316
  156. package/dist/agentic/guides/upstream/manifest.json +0 -8
  157. package/dist/agentic/shared/ai/harness/README.md +0 -50
  158. package/dist/agentic/shared/ai/harness/RELEASE.md +0 -57
  159. package/dist/agentic/shared/ai/harness/cases.json +0 -13680
  160. package/dist/agentic/shared/ai/harness/cases.schema.json +0 -133
  161. package/dist/agentic/shared/ai/harness/fixtures/index.json +0 -49
  162. package/dist/agentic/shared/ai/harness/fixtures/seeds.json +0 -162
  163. package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +0 -21
  164. package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +0 -96
  165. package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +0 -172
  166. package/dist/agentic/shared/ai/harness/release-matrix.json +0 -158
  167. package/dist/agentic/shared/ai/harness/release-result.schema.json +0 -219
  168. package/dist/agentic/shared/ai/harness/result.schema.json +0 -76
  169. package/dist/agentic/shared/ai/harness/routing-response.schema.json +0 -12
  170. package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +0 -73
  171. package/dist/agentic/shared/ai/harness/validators.json +0 -78
  172. package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +0 -2121
  173. package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +0 -1096
  174. package/dist/agentic/shared/ai/lessons/_template.md +0 -16
  175. package/dist/agentic/shared/ai/review-checklist.md +0 -36
  176. package/dist/agentic/shared/ai/skills/om-auto-implement-spec/SKILL.md +0 -21
  177. package/dist/agentic/shared/ai/skills/om-auto-upgrade-0.6.6-to-0.6.7/SKILL.md +0 -98
  178. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +0 -16
  179. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +0 -53
  180. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +0 -13
  181. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +0 -11
  182. package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +0 -30
  183. package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +0 -12
  184. package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +0 -13
  185. package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +0 -14
  186. package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +0 -28
  187. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +0 -12
  188. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +0 -22
  189. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +0 -12
  190. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +0 -19
  191. package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +0 -19
  192. package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +0 -13
  193. package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +0 -14
  194. package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +0 -10
  195. package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +0 -17
  196. package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +0 -29
  197. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +0 -100
  198. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +0 -16
  199. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +0 -17
  200. package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +0 -25
  201. package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +0 -11
  202. package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +0 -13
  203. package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +0 -18
  204. package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +0 -20
  205. package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +0 -33
  206. package/dist/agentic/shared/ai/skills/om-implement-spec/references/planning-and-progress.md +0 -40
  207. package/dist/agentic/shared/ai/skills/om-implement-spec/references/report-templates.md +0 -27
  208. package/dist/agentic/shared/ai/skills/om-implement-spec/references/spec-resolution.md +0 -24
  209. package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +0 -16
  210. package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +0 -14
  211. package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +0 -15
  212. package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +0 -12
  213. package/dist/agentic/shared/ai/skills/om-judge-agent-session/SKILL.md +0 -34
  214. package/dist/agentic/shared/ai/skills/om-judge-agent-session/agents/openai.yaml +0 -4
  215. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/agentic-setup.md +0 -11
  216. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/input-normalization.md +0 -31
  217. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/judge-workflow.md +0 -39
  218. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/report-template.md +0 -43
  219. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/rules.md +0 -11
  220. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +0 -19
  221. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +0 -172
  222. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +0 -12
  223. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +0 -83
  224. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +0 -21
  225. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +0 -11
  226. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +0 -22
  227. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +0 -13
  228. package/dist/agentic/shared/ai/skills/om-share-this-session/SKILL.md +0 -41
  229. package/dist/agentic/shared/ai/skills/om-share-this-session/references/agentic-setup.md +0 -19
  230. package/dist/agentic/shared/ai/skills/om-share-this-session/references/bundle-preparation.md +0 -44
  231. package/dist/agentic/shared/ai/skills/om-share-this-session/references/consent-and-review.md +0 -39
  232. package/dist/agentic/shared/ai/skills/om-share-this-session/references/publication.md +0 -20
  233. package/dist/agentic/shared/ai/skills/om-share-this-session/references/report-templates.md +0 -57
  234. package/dist/agentic/shared/ai/skills/om-share-this-session/references/rules.md +0 -11
  235. package/dist/agentic/shared/ai/skills/om-share-this-session/scripts/prepare-share-bundle.mjs +0 -486
  236. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +0 -18
  237. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +0 -27
  238. package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +0 -13
  239. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +0 -41
  240. package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +0 -11
  241. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +0 -15
  242. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +0 -16
  243. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +0 -14
  244. package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +0 -187
  245. package/dist/agentic/shared/scripts/check-lessons.mjs +0 -178
  246. package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +0 -2958
  247. package/dist/agentic/shared/scripts/execution-sandbox.mjs +0 -329
  248. package/dist/agentic/shared/scripts/framework-context.mjs +0 -888
  249. package/dist/agentic/shared/scripts/install-skills.mjs +0 -1029
  250. package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +0 -222
  251. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +0 -1774
  252. package/dist/lib/generators/module-extension-facts.js +0 -1840
  253. package/dist/lib/generators/module-extension-facts.js.map +0 -7
  254. package/dist/lib/generators/module-fact-sources.js +0 -70
  255. package/dist/lib/generators/module-fact-sources.js.map +0 -7
  256. package/dist/lib/generators/module-override-targets.js +0 -688
  257. package/dist/lib/generators/module-override-targets.js.map +0 -7
  258. package/dist/lib/load-env.js +0 -24
  259. package/dist/lib/load-env.js.map +0 -7
  260. package/dist/lib/telemetry-init.js +0 -358
  261. package/dist/lib/telemetry-init.js.map +0 -7
  262. package/src/lib/__tests__/agentic-setup.ownership.test.ts +0 -386
  263. package/src/lib/__tests__/injection-widget-id-validation.test.ts +0 -184
  264. package/src/lib/__tests__/load-env.test.ts +0 -65
  265. package/src/lib/__tests__/telemetry-init.test.ts +0 -298
  266. package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +0 -92
  267. package/src/lib/generators/__tests__/module-extension-activations.test.ts +0 -762
  268. package/src/lib/generators/__tests__/module-extension-facts.test.ts +0 -404
  269. package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +0 -108
  270. package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +0 -561
  271. package/src/lib/generators/__tests__/module-facts.source-links.test.ts +0 -119
  272. package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +0 -149
  273. package/src/lib/generators/__tests__/module-override-targets.test.ts +0 -304
  274. package/src/lib/generators/module-extension-facts.ts +0 -2365
  275. package/src/lib/generators/module-fact-sources.ts +0 -108
  276. package/src/lib/generators/module-override-targets.ts +0 -863
  277. package/src/lib/load-env.ts +0 -30
  278. package/src/lib/telemetry-init.ts +0 -461
@@ -1,298 +0,0 @@
1
- import path from 'node:path'
2
- import fs from 'node:fs'
3
- import os from 'node:os'
4
- import * as ts from 'typescript'
5
- import { runTelemetryInit } from '../telemetry-init'
6
-
7
- const TEMPLATE_DIR = path.join(__dirname, '../../../../../packages/create-app/template')
8
- const TEMPLATE_DISPATCHER = path.join(TEMPLATE_DIR, 'src/app/api/[...slug]/route.ts')
9
- const TEMPLATE_NEXT_CONFIG = path.join(TEMPLATE_DIR, 'next.config.ts')
10
- const TEMPLATE_INSTRUMENTATION = path.join(TEMPLATE_DIR, 'src/instrumentation.ts')
11
-
12
- // The telemetry statements the shipped scaffold wires into the dispatcher — the
13
- // oracle for "did the command reproduce the real wiring?". Read from the live
14
- // template so this test fails loudly if the scaffold's wiring changes and the
15
- // command doesn't keep up.
16
- const TELEMETRY_DISPATCHER_LINES = [
17
- "import { getTelemetryRuntime } from '@open-mercato/shared/lib/telemetry/runtime'",
18
- 'getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, finalResponse.status, startedAt)',
19
- 'getTelemetryRuntime()?.recordHttpDuration(method, match.route.path, 500, startedAt)',
20
- 'getTelemetryRuntime()?.reportError(error, {',
21
- ]
22
-
23
- /** Assert a string is syntactically valid TypeScript (parse errors, not types). */
24
- function assertParses(code: string, label: string): void {
25
- const sf = ts.createSourceFile(`${label}.ts`, code, ts.ScriptTarget.Latest, true)
26
- const diagnostics = (sf as unknown as { parseDiagnostics?: ts.Diagnostic[] }).parseDiagnostics ?? []
27
- const messages = diagnostics.map((d) => ts.flattenDiagnosticMessageText(d.messageText, '\n'))
28
- expect({ label, messages }).toEqual({ label, messages: [] })
29
- }
30
-
31
- /** Turn the live wired template dispatcher back into a pre-telemetry one. */
32
- function stripTelemetry(src: string): string {
33
- return src
34
- .replace(/\n[ \t]*getTelemetryRuntime\(\)\?\.reportError\(error, \{[\s\S]*?\n[ \t]*\}\)/, '')
35
- .split('\n')
36
- .filter(
37
- (line) =>
38
- !line.includes("from '@open-mercato/telemetry'") &&
39
- !line.includes("from '@open-mercato/telemetry/nextjs'") &&
40
- !line.includes("from '@open-mercato/shared/lib/telemetry/runtime'") &&
41
- !line.includes('recordHttpDuration('),
42
- )
43
- .join('\n')
44
- }
45
-
46
- const NEXT_CONFIG = `import type { NextConfig } from 'next'
47
-
48
- const nextConfig: NextConfig = {
49
- serverExternalPackages: [
50
- 'esbuild',
51
- ],
52
- }
53
-
54
- export default nextConfig
55
- `
56
-
57
- function baseFixture(dir: string): void {
58
- fs.mkdirSync(path.join(dir, 'src', 'app', 'api', '[...slug]'), { recursive: true })
59
- fs.writeFileSync(path.join(dir, 'src', 'modules.ts'), 'export const enabledModules = []\n')
60
- fs.writeFileSync(
61
- path.join(dir, 'package.json'),
62
- JSON.stringify({ name: 'my-app', dependencies: { '@open-mercato/shared': '1.2.3' } }, null, 2) + '\n',
63
- )
64
- fs.writeFileSync(path.join(dir, '.env.example'), 'DATABASE_URL=postgres://localhost/app\n')
65
- fs.writeFileSync(path.join(dir, 'next.config.ts'), NEXT_CONFIG)
66
- }
67
-
68
- const SIMPLE_DISPATCHER = `import { NextResponse, type NextRequest } from 'next/server'
69
- import { findApiRouteManifestMatch } from '@open-mercato/shared/modules/registry'
70
- import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'
71
-
72
- async function handleRequest(method: string, req: NextRequest): Promise<Response> {
73
- const startedAt = Date.now()
74
- const match = { route: { path: '/api/thing' } }
75
- try {
76
- const finalResponse = NextResponse.json({ ok: true })
77
- return finalResponse
78
- } catch (error) {
79
- throw error
80
- }
81
- }
82
- `
83
-
84
- describe('mercato telemetry init', () => {
85
- let tmpDir: string
86
- let cwd: string
87
- let logSpy: jest.SpyInstance
88
- let errorSpy: jest.SpyInstance
89
-
90
- beforeEach(() => {
91
- tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'telemetry-init-'))
92
- cwd = process.cwd()
93
- process.chdir(tmpDir)
94
- logSpy = jest.spyOn(console, 'log').mockImplementation(() => {})
95
- errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {})
96
- })
97
-
98
- afterEach(() => {
99
- process.chdir(cwd)
100
- logSpy.mockRestore()
101
- errorSpy.mockRestore()
102
- fs.rmSync(tmpDir, { recursive: true, force: true })
103
- })
104
-
105
- const read = (rel: string) => fs.readFileSync(path.join(tmpDir, rel), 'utf8')
106
- const dispatcherPath = 'src/app/api/[...slug]/route.ts'
107
-
108
- it('rejects a directory that is not an Open Mercato app', async () => {
109
- const code = await runTelemetryInit([])
110
- expect(code).toBe(1)
111
- expect(errorSpy).toHaveBeenCalled()
112
- })
113
-
114
- it('wires all files in a pre-telemetry app', async () => {
115
- baseFixture(tmpDir)
116
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
117
- const code = await runTelemetryInit([])
118
- expect(code).toBe(0)
119
-
120
- const pkg = JSON.parse(read('package.json'))
121
- expect(pkg.dependencies['@open-mercato/telemetry']).toBe('1.2.3')
122
- expect(pkg.optionalDependencies['bullmq-otel']).toBe('^1.3.1')
123
-
124
- expect(read('.env.example')).toContain('TELEMETRY_BACKEND')
125
- expect(read('.env.example')).toContain('OTEL_EXPORTER_OTLP_ENDPOINT')
126
- expect(read('src/instrumentation.ts')).toContain('registerTelemetryForNextjs')
127
-
128
- const nextConfig = read('next.config.ts')
129
- expect(nextConfig).toContain('@open-mercato/telemetry/nextjs-config')
130
- expect(nextConfig).toContain('...telemetryServerExternalPackages')
131
-
132
- const route = read(dispatcherPath)
133
- for (const line of TELEMETRY_DISPATCHER_LINES) expect(route).toContain(line)
134
- })
135
-
136
- it('every patched file is syntactically valid TypeScript', async () => {
137
- baseFixture(tmpDir)
138
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
139
- await runTelemetryInit([])
140
- assertParses(read('next.config.ts'), 'next.config')
141
- assertParses(read('src/instrumentation.ts'), 'instrumentation')
142
- assertParses(read(dispatcherPath), 'dispatcher')
143
- JSON.parse(read('package.json')) // valid JSON
144
- })
145
-
146
- it('reproduces the live template dispatcher wiring (round-trip)', async () => {
147
- baseFixture(tmpDir)
148
- const wired = fs.readFileSync(TEMPLATE_DISPATCHER, 'utf8')
149
- const preTelemetry = stripTelemetry(wired)
150
- // sanity: the derived pre-telemetry file no longer imports telemetry but still parses
151
- expect(preTelemetry).not.toContain('@open-mercato/telemetry')
152
- assertParses(preTelemetry, 'stripped-template')
153
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), preTelemetry)
154
-
155
- await runTelemetryInit([])
156
-
157
- const patched = read(dispatcherPath)
158
- assertParses(patched, 'patched-template')
159
- for (const line of TELEMETRY_DISPATCHER_LINES) expect(patched).toContain(line)
160
- // the success metric lands before the response return, the 500 funnel in the catch
161
- expect(patched.indexOf('finalResponse.status, startedAt')).toBeLessThan(patched.indexOf('return finalResponse'))
162
- expect(patched.indexOf('reportError(error, {')).toBeLessThan(patched.indexOf(', 500, startedAt'))
163
- })
164
-
165
- it('is a no-op on the real (already-wired) template files', async () => {
166
- baseFixture(tmpDir)
167
- fs.copyFileSync(TEMPLATE_DISPATCHER, path.join(tmpDir, dispatcherPath))
168
- fs.copyFileSync(TEMPLATE_NEXT_CONFIG, path.join(tmpDir, 'next.config.ts'))
169
- fs.copyFileSync(TEMPLATE_INSTRUMENTATION, path.join(tmpDir, 'src', 'instrumentation.ts'))
170
- const before = {
171
- route: read(dispatcherPath),
172
- nextConfig: read('next.config.ts'),
173
- instrumentation: read('src/instrumentation.ts'),
174
- }
175
- await runTelemetryInit([])
176
- expect(read(dispatcherPath)).toBe(before.route)
177
- expect(read('next.config.ts')).toBe(before.nextConfig)
178
- expect(read('src/instrumentation.ts')).toBe(before.instrumentation)
179
- })
180
-
181
- it('patches a recognizable-but-modified dispatcher (extra imports/code, anchors intact)', async () => {
182
- baseFixture(tmpDir)
183
- const modified = SIMPLE_DISPATCHER.replace(
184
- "import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'",
185
- "import { isCrudHttpError } from '@open-mercato/shared/lib/crud/errors'\nimport { auditLog } from '@/lib/audit'",
186
- ).replace('const match = { route: { path: \'/api/thing\' } }', 'const match = { route: { path: \'/api/thing\' } }\n auditLog(method)')
187
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), modified)
188
-
189
- await runTelemetryInit([])
190
- const patched = read(dispatcherPath)
191
- assertParses(patched, 'modified-dispatcher')
192
- for (const line of TELEMETRY_DISPATCHER_LINES) expect(patched).toContain(line)
193
- expect(patched).toContain("import { auditLog } from '@/lib/audit'") // preserved custom code
194
- })
195
-
196
- it('leaves an unrecognizable dispatcher untouched and prints the manual snippet', async () => {
197
- baseFixture(tmpDir)
198
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), `export async function GET() { return new Response('custom') }\n`)
199
- await runTelemetryInit([])
200
- const route = read(dispatcherPath)
201
- expect(route).not.toContain('@open-mercato/telemetry')
202
- expect(route).toBe(`export async function GET() { return new Response('custom') }\n`)
203
- const printed = logSpy.mock.calls.flat().join('\n')
204
- expect(printed).toContain('manual step for src/app/api/[...slug]/route.ts')
205
- })
206
-
207
- it('handles next.config variations (single-line array, no trailing comma) and stays valid', async () => {
208
- baseFixture(tmpDir)
209
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
210
- fs.writeFileSync(
211
- path.join(tmpDir, 'next.config.ts'),
212
- `import type { NextConfig } from 'next'\nconst nextConfig: NextConfig = { serverExternalPackages: ['esbuild'] }\nexport default nextConfig\n`,
213
- )
214
- await runTelemetryInit([])
215
- const nextConfig = read('next.config.ts')
216
- assertParses(nextConfig, 'single-line-next-config')
217
- expect(nextConfig).toContain('...telemetryServerExternalPackages')
218
- expect(nextConfig).toContain('@open-mercato/telemetry/nextjs-config')
219
- })
220
-
221
- it('migrates the legacy nextjs import before adding the missing spread', async () => {
222
- baseFixture(tmpDir)
223
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
224
- fs.writeFileSync(
225
- path.join(tmpDir, 'next.config.ts'),
226
- `import type { NextConfig } from 'next'\nimport { telemetryServerExternalPackages } from '@open-mercato/telemetry/nextjs'\nconst nextConfig: NextConfig = { serverExternalPackages: ['esbuild', 'bullmq'] }\nexport default nextConfig\n`,
227
- )
228
-
229
- await runTelemetryInit([])
230
-
231
- const nextConfig = read('next.config.ts')
232
- assertParses(nextConfig, 'legacy-next-config')
233
- expect(nextConfig).toContain("from '@open-mercato/telemetry/nextjs-config'")
234
- expect(nextConfig).not.toContain("from '@open-mercato/telemetry/nextjs'")
235
- expect(nextConfig).toContain("['esbuild', 'bullmq', ...telemetryServerExternalPackages]")
236
- })
237
-
238
- it('flags next.config as manual when serverExternalPackages is absent', async () => {
239
- baseFixture(tmpDir)
240
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
241
- fs.writeFileSync(
242
- path.join(tmpDir, 'next.config.ts'),
243
- `import type { NextConfig } from 'next'\nconst nextConfig: NextConfig = { distDir: '.next' }\nexport default nextConfig\n`,
244
- )
245
- await runTelemetryInit([])
246
- expect(read('next.config.ts')).not.toContain('telemetryServerExternalPackages')
247
- const printed = logSpy.mock.calls.flat().join('\n')
248
- expect(printed).toContain('manual step for next.config.ts')
249
- })
250
-
251
- it('inserts into a pre-existing custom instrumentation.ts and preserves its body', async () => {
252
- baseFixture(tmpDir)
253
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
254
- fs.writeFileSync(
255
- path.join(tmpDir, 'src', 'instrumentation.ts'),
256
- `export async function register(): Promise<void> {\n console.log('custom warmup')\n}\n`,
257
- )
258
- await runTelemetryInit([])
259
- const instrumentation = read('src/instrumentation.ts')
260
- assertParses(instrumentation, 'custom-instrumentation')
261
- expect(instrumentation).toContain('registerTelemetryForNextjs')
262
- expect(instrumentation).toContain("console.log('custom warmup')") // preserved
263
- })
264
-
265
- it('is idempotent — a second run changes nothing and does not double-insert', async () => {
266
- baseFixture(tmpDir)
267
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
268
- await runTelemetryInit([])
269
- const after1 = {
270
- pkg: read('package.json'),
271
- env: read('.env.example'),
272
- instrumentation: read('src/instrumentation.ts'),
273
- nextConfig: read('next.config.ts'),
274
- route: read(dispatcherPath),
275
- }
276
-
277
- await runTelemetryInit([])
278
- expect(read('package.json')).toBe(after1.pkg)
279
- expect(read('.env.example')).toBe(after1.env)
280
- expect(read('src/instrumentation.ts')).toBe(after1.instrumentation)
281
- expect(read('next.config.ts')).toBe(after1.nextConfig)
282
- expect(read(dispatcherPath)).toBe(after1.route)
283
-
284
- const route = read(dispatcherPath)
285
- expect((read('next.config.ts').match(/@open-mercato\/telemetry\/nextjs-config/g) ?? []).length).toBe(1)
286
- expect((route.match(/from '@open-mercato\/shared\/lib\/telemetry\/runtime'/g) ?? []).length).toBe(1)
287
- })
288
-
289
- it('dry run writes nothing', async () => {
290
- baseFixture(tmpDir)
291
- fs.writeFileSync(path.join(tmpDir, dispatcherPath), SIMPLE_DISPATCHER)
292
- const before = read('next.config.ts')
293
- await runTelemetryInit(['--dry-run'])
294
- expect(read('next.config.ts')).toBe(before)
295
- expect(fs.existsSync(path.join(tmpDir, 'src', 'instrumentation.ts'))).toBe(false)
296
- expect(JSON.parse(read('package.json')).dependencies['@open-mercato/telemetry']).toBeUndefined()
297
- })
298
- })
@@ -1,92 +0,0 @@
1
- import {
2
- ACTIVATION_ADAPTERS,
3
- ALL_ACTIVATION_KINDS,
4
- ALL_CONTRIBUTION_KINDS,
5
- CONTRIBUTION_ACTIVATION_CLASSIFICATION,
6
- } from '../module-extension-facts'
7
- import type {
8
- ModuleExtensionActivationKind,
9
- ModuleExtensionContributionKind,
10
- } from '@open-mercato/shared/modules/widgets/extension-points'
11
-
12
- // Explicit expected inventories. Adding a UMES activation kind or contribution
13
- // kind to the shared union forces the typed Record in module-extension-facts.ts
14
- // to gain a key (compile-time gate) AND requires updating these lists (this
15
- // coverage gate), so an unclassified kind cannot ship silently.
16
- const EXPECTED_ACTIVATION_KINDS: ModuleExtensionActivationKind[] = [
17
- 'crud-response-enricher',
18
- 'query-enricher',
19
- 'mutation-guard',
20
- 'api-interceptor-bridge',
21
- 'command-interceptor-bridge',
22
- 'widget-injection-consumer',
23
- 'component-extension-consumer',
24
- 'dashboard-host-consumer',
25
- ]
26
-
27
- const EXPECTED_CONTRIBUTION_KINDS: ModuleExtensionContributionKind[] = [
28
- 'widget',
29
- 'data-table',
30
- 'crud-form',
31
- 'component-override',
32
- 'response-enricher',
33
- 'api-interceptor',
34
- 'command-interceptor',
35
- 'mutation-guard',
36
- 'entity-extension',
37
- 'subscriber',
38
- 'browser-reaction',
39
- 'specialized-registry',
40
- 'module-override',
41
- ]
42
-
43
- // Route/entity-bound contribution kinds MUST bind through an activation adapter —
44
- // never be silently classified as capability-only.
45
- const ROUTE_OR_ENTITY_BOUND_KINDS: ModuleExtensionContributionKind[] = [
46
- 'response-enricher',
47
- 'mutation-guard',
48
- 'api-interceptor',
49
- 'command-interceptor',
50
- ]
51
-
52
- describe('activation adapter coverage', () => {
53
- it('registers exactly the expected closed set of activation adapters', () => {
54
- expect([...ALL_ACTIVATION_KINDS].sort()).toEqual([...EXPECTED_ACTIVATION_KINDS].sort())
55
- expect(Object.keys(ACTIVATION_ADAPTERS).sort()).toEqual([...EXPECTED_ACTIVATION_KINDS].sort())
56
- })
57
-
58
- it('classifies exactly the expected closed set of contribution kinds', () => {
59
- expect([...ALL_CONTRIBUTION_KINDS].sort()).toEqual([...EXPECTED_CONTRIBUTION_KINDS].sort())
60
- expect(Object.keys(CONTRIBUTION_ACTIVATION_CLASSIFICATION).sort()).toEqual([...EXPECTED_CONTRIBUTION_KINDS].sort())
61
- })
62
-
63
- it('maps every contribution kind to a real adapter whose contributionKinds accept it, or to a tested capability-only classification', () => {
64
- for (const kind of ALL_CONTRIBUTION_KINDS) {
65
- const classification = CONTRIBUTION_ACTIVATION_CLASSIFICATION[kind]
66
- if (classification === 'capability-only') {
67
- expect(ROUTE_OR_ENTITY_BOUND_KINDS).not.toContain(kind)
68
- continue
69
- }
70
- expect(classification.length).toBeGreaterThan(0)
71
- for (const activationKind of classification) {
72
- const adapter = ACTIVATION_ADAPTERS[activationKind]
73
- expect(adapter).toBeDefined()
74
- expect(adapter.contributionKinds).toContain(kind)
75
- }
76
- }
77
- })
78
-
79
- it('requires every route/entity-bound contribution kind to have an activation adapter (never capability-only)', () => {
80
- for (const kind of ROUTE_OR_ENTITY_BOUND_KINDS) {
81
- const classification = CONTRIBUTION_ACTIVATION_CLASSIFICATION[kind]
82
- expect(classification).not.toBe('capability-only')
83
- }
84
- })
85
-
86
- it('keeps a call-site-object adapter for every kind that distinguishes bound from capability-only by opt-in', () => {
87
- const callSiteKinds = ALL_ACTIVATION_KINDS.filter((kind) => ACTIVATION_ADAPTERS[kind].mode === 'call-site-object')
88
- // Enricher (response + query) and mutation-guard opt-ins are the only surfaces
89
- // whose activation presence is NOT implied by mere host existence.
90
- expect(callSiteKinds.sort()).toEqual(['crud-response-enricher', 'mutation-guard', 'query-enricher'])
91
- })
92
- })