@open-mercato/cli 0.6.7 → 0.6.8-develop.6875.1.871a4afc94

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 +24 -7
  3. package/dist/agentic/claude-code/hooks/entity-migration-check.ts +32 -88
  4. package/dist/agentic/codex/enforcement-rules.md +2 -16
  5. package/dist/agentic/cursor/hooks/entity-migration-check.mjs +19 -50
  6. package/dist/agentic/cursor/rules/entity-guard.mdc +9 -21
  7. package/dist/agentic/cursor/rules/generated-guard.mdc +3 -5
  8. package/dist/agentic/cursor/rules/open-mercato.mdc +3 -29
  9. package/dist/agentic/guides/ai-workflows.md +76 -0
  10. package/dist/agentic/guides/architecture.md +107 -0
  11. package/dist/agentic/guides/backend-ui.md +80 -0
  12. package/dist/agentic/guides/contracts.md +92 -0
  13. package/dist/agentic/guides/extensions.md +121 -0
  14. package/dist/agentic/guides/framework-extension-points.md +36 -0
  15. package/dist/agentic/guides/integrations.md +81 -0
  16. package/dist/agentic/guides/module-facts.json +115537 -3951
  17. package/dist/agentic/guides/module-system.md +12 -127
  18. package/dist/agentic/guides/modules/ai_assistant.md +227 -28
  19. package/dist/agentic/guides/modules/api_docs.md +58 -2
  20. package/dist/agentic/guides/modules/api_keys.md +92 -7
  21. package/dist/agentic/guides/modules/attachments.md +119 -14
  22. package/dist/agentic/guides/modules/audit_logs.md +131 -10
  23. package/dist/agentic/guides/modules/auth.md +276 -33
  24. package/dist/agentic/guides/modules/business_rules.md +149 -14
  25. package/dist/agentic/guides/modules/catalog.md +475 -43
  26. package/dist/agentic/guides/modules/channel_gmail.md +82 -3
  27. package/dist/agentic/guides/modules/channel_imap.md +82 -3
  28. package/dist/agentic/guides/modules/checkout.md +299 -27
  29. package/dist/agentic/guides/modules/communication_channels.md +315 -33
  30. package/dist/agentic/guides/modules/configs.md +104 -8
  31. package/dist/agentic/guides/modules/content.md +57 -2
  32. package/dist/agentic/guides/modules/currencies.md +152 -17
  33. package/dist/agentic/guides/modules/customer_accounts.md +387 -45
  34. package/dist/agentic/guides/modules/customers.md +746 -85
  35. package/dist/agentic/guides/modules/dashboards.md +155 -10
  36. package/dist/agentic/guides/modules/data_sync.md +149 -16
  37. package/dist/agentic/guides/modules/design_system.md +102 -0
  38. package/dist/agentic/guides/modules/dictionaries.md +107 -12
  39. package/dist/agentic/guides/modules/directory.md +148 -15
  40. package/dist/agentic/guides/modules/entities.md +145 -13
  41. package/dist/agentic/guides/modules/events.md +59 -2
  42. package/dist/agentic/guides/modules/feature_toggles.md +119 -9
  43. package/dist/agentic/guides/modules/gateway_stripe.md +92 -4
  44. package/dist/agentic/guides/modules/generators.md +45 -2
  45. package/dist/agentic/guides/modules/inbox_ops.md +207 -27
  46. package/dist/agentic/guides/modules/integrations.md +146 -16
  47. package/dist/agentic/guides/modules/messages.md +223 -24
  48. package/dist/agentic/guides/modules/notifications.md +96 -8
  49. package/dist/agentic/guides/modules/onboarding.md +77 -6
  50. package/dist/agentic/guides/modules/payment_gateways.md +164 -21
  51. package/dist/agentic/guides/modules/perspectives.md +77 -7
  52. package/dist/agentic/guides/modules/planner.md +136 -18
  53. package/dist/agentic/guides/modules/portal.md +93 -2
  54. package/dist/agentic/guides/modules/progress.md +104 -14
  55. package/dist/agentic/guides/modules/query_index.md +154 -15
  56. package/dist/agentic/guides/modules/record_locks.md +206 -21
  57. package/dist/agentic/guides/modules/resources.md +197 -30
  58. package/dist/agentic/guides/modules/sales.md +678 -84
  59. package/dist/agentic/guides/modules/scheduler.md +133 -14
  60. package/dist/agentic/guides/modules/search.md +170 -6
  61. package/dist/agentic/guides/modules/security.md +294 -35
  62. package/dist/agentic/guides/modules/shipping_carriers.md +134 -18
  63. package/dist/agentic/guides/modules/sso.md +151 -26
  64. package/dist/agentic/guides/modules/staff.md +369 -57
  65. package/dist/agentic/guides/modules/storage_s3.md +95 -5
  66. package/dist/agentic/guides/modules/sync_akeneo.md +85 -3
  67. package/dist/agentic/guides/modules/sync_excel.md +75 -6
  68. package/dist/agentic/guides/modules/system_status_overlays.md +60 -2
  69. package/dist/agentic/guides/modules/translations.md +104 -10
  70. package/dist/agentic/guides/modules/webhooks.md +203 -24
  71. package/dist/agentic/guides/modules/wms.md +441 -46
  72. package/dist/agentic/guides/modules/workflows.md +302 -43
  73. package/dist/agentic/guides/spec-delivery.md +22 -0
  74. package/dist/agentic/guides/testing-debugging.md +80 -0
  75. package/dist/agentic/guides/upstream/AGENTS.md +299 -0
  76. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +316 -0
  77. package/dist/agentic/guides/upstream/manifest.json +8 -0
  78. package/dist/agentic/shared/AGENTS.md.template +124 -311
  79. package/dist/agentic/shared/ai/agentic.config.json +2 -0
  80. package/dist/agentic/shared/ai/harness/README.md +50 -0
  81. package/dist/agentic/shared/ai/harness/RELEASE.md +57 -0
  82. package/dist/agentic/shared/ai/harness/cases.json +13680 -0
  83. package/dist/agentic/shared/ai/harness/cases.schema.json +133 -0
  84. package/dist/agentic/shared/ai/harness/fixtures/index.json +49 -0
  85. package/dist/agentic/shared/ai/harness/fixtures/seeds.json +162 -0
  86. package/dist/agentic/shared/ai/harness/generated-code-review-policy.md +21 -0
  87. package/dist/agentic/shared/ai/harness/generated-code-review-response.schema.json +96 -0
  88. package/dist/agentic/shared/ai/harness/generated-code-review-result.schema.json +172 -0
  89. package/dist/agentic/shared/ai/harness/release-matrix.json +158 -0
  90. package/dist/agentic/shared/ai/harness/release-result.schema.json +219 -0
  91. package/dist/agentic/shared/ai/harness/result.schema.json +76 -0
  92. package/dist/agentic/shared/ai/harness/routing-response.schema.json +12 -0
  93. package/dist/agentic/shared/ai/harness/target-validation-result.schema.json +73 -0
  94. package/dist/agentic/shared/ai/harness/validators.json +78 -0
  95. package/dist/agentic/shared/ai/harness/writable-ast-oracles.mjs +2121 -0
  96. package/dist/agentic/shared/ai/harness/writable-behavior-oracles.mjs +1096 -0
  97. package/dist/agentic/shared/ai/lessons/_template.md +16 -0
  98. package/dist/agentic/shared/ai/lessons.md +26 -3
  99. package/dist/agentic/shared/ai/review-checklist.md +36 -0
  100. package/dist/agentic/shared/ai/skills/om-auto-implement-spec/SKILL.md +21 -0
  101. package/dist/agentic/shared/ai/skills/om-auto-review-pr/SKILL.md +4 -0
  102. package/dist/agentic/shared/ai/skills/om-auto-upgrade-0.6.6-to-0.6.7/SKILL.md +98 -0
  103. package/dist/agentic/shared/ai/skills/om-backend-ui-design/SKILL.md +20 -241
  104. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/crud-surfaces.md +16 -0
  105. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/frontend-and-design-system.md +53 -0
  106. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/page-and-navigation.md +13 -0
  107. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/quality-states.md +11 -0
  108. package/dist/agentic/shared/ai/skills/om-build-workflow/SKILL.md +30 -0
  109. package/dist/agentic/shared/ai/skills/om-build-workflow/references/activity-contracts.md +12 -0
  110. package/dist/agentic/shared/ai/skills/om-build-workflow/references/durability-and-progress.md +13 -0
  111. package/dist/agentic/shared/ai/skills/om-build-workflow/references/workflow-design.md +14 -0
  112. package/dist/agentic/shared/ai/skills/om-create-ai-agent/SKILL.md +28 -0
  113. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/attachments-and-overrides.md +12 -0
  114. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/module-agents-and-tools.md +22 -0
  115. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/orchestrator-agents.md +12 -0
  116. package/dist/agentic/shared/ai/skills/om-create-ai-agent/references/surface-selector.md +19 -0
  117. package/dist/agentic/shared/ai/skills/om-data-model-design/SKILL.md +16 -601
  118. package/dist/agentic/shared/ai/skills/om-data-model-design/references/integrity-and-concurrency.md +19 -0
  119. package/dist/agentic/shared/ai/skills/om-data-model-design/references/migration-workflow.md +13 -0
  120. package/dist/agentic/shared/ai/skills/om-data-model-design/references/schema-design.md +14 -0
  121. package/dist/agentic/shared/ai/skills/om-data-model-design/references/sensitive-data.md +10 -0
  122. package/dist/agentic/shared/ai/skills/om-eject-and-customize/SKILL.md +14 -310
  123. package/dist/agentic/shared/ai/skills/om-eject-and-customize/references/decision-and-procedure.md +17 -0
  124. package/dist/agentic/shared/ai/skills/om-evolve-harness/SKILL.md +29 -0
  125. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-template.md +100 -0
  126. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/case-workflow.md +16 -0
  127. package/dist/agentic/shared/ai/skills/om-evolve-harness/references/owner-selection.md +17 -0
  128. package/dist/agentic/shared/ai/skills/om-framework-context/SKILL.md +25 -0
  129. package/dist/agentic/shared/ai/skills/om-framework-context/references/resolver-procedure.md +11 -0
  130. package/dist/agentic/shared/ai/skills/om-framework-context/references/skew-and-escalation.md +13 -0
  131. package/dist/agentic/shared/ai/skills/om-help/SKILL.md +15 -97
  132. package/dist/agentic/shared/ai/skills/om-help/references/delivery-workflows.md +18 -0
  133. package/dist/agentic/shared/ai/skills/om-help/references/task-families.md +20 -0
  134. package/dist/agentic/shared/ai/skills/om-implement-spec/SKILL.md +33 -152
  135. package/dist/agentic/shared/ai/skills/om-implement-spec/references/phases-and-gates.md +33 -0
  136. package/dist/agentic/shared/ai/skills/om-implement-spec/references/planning-and-progress.md +40 -0
  137. package/dist/agentic/shared/ai/skills/om-implement-spec/references/report-templates.md +27 -0
  138. package/dist/agentic/shared/ai/skills/om-implement-spec/references/spec-resolution.md +24 -0
  139. package/dist/agentic/shared/ai/skills/om-integration-builder/SKILL.md +24 -708
  140. package/dist/agentic/shared/ai/skills/om-integration-builder/references/package-and-activation.md +16 -0
  141. package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +14 -0
  142. package/dist/agentic/shared/ai/skills/om-integration-builder/references/security-and-reliability.md +15 -0
  143. package/dist/agentic/shared/ai/skills/om-integration-builder/references/sync-and-files.md +12 -0
  144. package/dist/agentic/shared/ai/skills/om-judge-agent-session/SKILL.md +34 -0
  145. package/dist/agentic/shared/ai/skills/om-judge-agent-session/agents/openai.yaml +4 -0
  146. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/agentic-setup.md +11 -0
  147. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/input-normalization.md +31 -0
  148. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/judge-workflow.md +39 -0
  149. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/report-template.md +43 -0
  150. package/dist/agentic/shared/ai/skills/om-judge-agent-session/references/rules.md +11 -0
  151. package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +20 -820
  152. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/api-and-domain.md +19 -0
  153. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/business-one-shot-blueprints.md +172 -0
  154. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/data-and-migrations.md +12 -0
  155. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/discovery-surface-catalog.md +83 -0
  156. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/module-surfaces.md +21 -0
  157. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/planning.md +11 -0
  158. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/runtime-cache-and-queues.md +22 -0
  159. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/verification.md +13 -0
  160. package/dist/agentic/shared/ai/skills/om-share-this-session/SKILL.md +41 -0
  161. package/dist/agentic/shared/ai/skills/om-share-this-session/references/agentic-setup.md +19 -0
  162. package/dist/agentic/shared/ai/skills/om-share-this-session/references/bundle-preparation.md +44 -0
  163. package/dist/agentic/shared/ai/skills/om-share-this-session/references/consent-and-review.md +39 -0
  164. package/dist/agentic/shared/ai/skills/om-share-this-session/references/publication.md +20 -0
  165. package/dist/agentic/shared/ai/skills/om-share-this-session/references/report-templates.md +57 -0
  166. package/dist/agentic/shared/ai/skills/om-share-this-session/references/rules.md +11 -0
  167. package/dist/agentic/shared/ai/skills/om-share-this-session/scripts/prepare-share-bundle.mjs +486 -0
  168. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +19 -843
  169. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +18 -0
  170. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +27 -0
  171. package/dist/agentic/shared/ai/skills/om-system-extension/references/read-write-roundtrip.md +13 -0
  172. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +41 -0
  173. package/dist/agentic/shared/ai/skills/om-system-extension/references/verification.md +11 -0
  174. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/SKILL.md +15 -63
  175. package/dist/agentic/shared/ai/skills/om-trim-unused-modules/references/dependency-and-redirect.md +15 -0
  176. package/dist/agentic/shared/ai/skills/om-troubleshooter/SKILL.md +16 -467
  177. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnosis-map.md +16 -0
  178. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/regression-oracles.md +14 -0
  179. package/dist/agentic/shared/ai/skills/tiers.json +143 -21
  180. package/dist/agentic/shared/ai/skills/tiers.schema.json +52 -40
  181. package/dist/agentic/shared/ai/specs/README.md +4 -3
  182. package/dist/agentic/shared/ai/specs/SPEC-000-template.md +226 -10
  183. package/dist/agentic/shared/ai/trackers/github.md +108 -4
  184. package/dist/agentic/shared/scripts/agent-harness-tool-server.mjs +187 -0
  185. package/dist/agentic/shared/scripts/check-lessons.mjs +178 -0
  186. package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +2958 -0
  187. package/dist/agentic/shared/scripts/execution-sandbox.mjs +329 -0
  188. package/dist/agentic/shared/scripts/framework-context.mjs +888 -0
  189. package/dist/agentic/shared/scripts/install-skills.mjs +1029 -0
  190. package/dist/agentic/shared/scripts/install-skills.sh +4 -694
  191. package/dist/agentic/shared/scripts/prepare-agent-harness-fixture.mjs +222 -0
  192. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +1774 -0
  193. package/dist/bin.js +13 -1
  194. package/dist/bin.js.map +2 -2
  195. package/dist/lib/__integration__/TC-INT-008.spec.js +88 -8
  196. package/dist/lib/__integration__/TC-INT-008.spec.js.map +2 -2
  197. package/dist/lib/agentic-init.js +13 -3
  198. package/dist/lib/agentic-init.js.map +2 -2
  199. package/dist/lib/agentic-setup.js +434 -186
  200. package/dist/lib/agentic-setup.js.map +2 -2
  201. package/dist/lib/generators/extensions/injection-widgets.js +20 -0
  202. package/dist/lib/generators/extensions/injection-widgets.js.map +2 -2
  203. package/dist/lib/generators/module-extension-facts.js +1840 -0
  204. package/dist/lib/generators/module-extension-facts.js.map +7 -0
  205. package/dist/lib/generators/module-fact-sources.js +70 -0
  206. package/dist/lib/generators/module-fact-sources.js.map +7 -0
  207. package/dist/lib/generators/module-facts-discovery.js +41 -7
  208. package/dist/lib/generators/module-facts-discovery.js.map +2 -2
  209. package/dist/lib/generators/module-facts.js +1387 -45
  210. package/dist/lib/generators/module-facts.js.map +3 -3
  211. package/dist/lib/generators/module-override-targets.js +688 -0
  212. package/dist/lib/generators/module-override-targets.js.map +7 -0
  213. package/dist/lib/generators/module-registry.js +11 -5
  214. package/dist/lib/generators/module-registry.js.map +2 -2
  215. package/dist/lib/load-env.js +24 -0
  216. package/dist/lib/load-env.js.map +7 -0
  217. package/dist/lib/resolver.js +2 -0
  218. package/dist/lib/resolver.js.map +2 -2
  219. package/dist/lib/telemetry-init.js +358 -0
  220. package/dist/lib/telemetry-init.js.map +7 -0
  221. package/dist/lib/testing/integration.js +5 -0
  222. package/dist/lib/testing/integration.js.map +2 -2
  223. package/dist/mercato.js +23 -1
  224. package/dist/mercato.js.map +2 -2
  225. package/package.json +13 -11
  226. package/src/bin.ts +33 -1
  227. package/src/lib/__integration__/TC-INT-008.spec.ts +107 -9
  228. package/src/lib/__tests__/agentic-init.test.ts +41 -5
  229. package/src/lib/__tests__/agentic-setup.ownership.test.ts +386 -0
  230. package/src/lib/__tests__/injection-widget-id-validation.test.ts +184 -0
  231. package/src/lib/__tests__/load-env.test.ts +65 -0
  232. package/src/lib/__tests__/telemetry-init.test.ts +298 -0
  233. package/src/lib/agentic-init.ts +15 -3
  234. package/src/lib/agentic-setup.ts +573 -222
  235. package/src/lib/generators/__tests__/activation-adapter-coverage.test.ts +92 -0
  236. package/src/lib/generators/__tests__/module-extension-activations.test.ts +762 -0
  237. package/src/lib/generators/__tests__/module-extension-facts.test.ts +404 -0
  238. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +88 -2
  239. package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +1 -0
  240. package/src/lib/generators/__tests__/module-facts.discovery.test.ts +54 -10
  241. package/src/lib/generators/__tests__/module-facts.extension-hosts.test.ts +108 -0
  242. package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +561 -0
  243. package/src/lib/generators/__tests__/module-facts.source-links.test.ts +119 -0
  244. package/src/lib/generators/__tests__/module-override-targets.roundtrip.test.ts +149 -0
  245. package/src/lib/generators/__tests__/module-override-targets.test.ts +304 -0
  246. package/src/lib/generators/__tests__/module-subset.test.ts +18 -0
  247. package/src/lib/generators/extensions/injection-widgets.ts +51 -0
  248. package/src/lib/generators/module-extension-facts.ts +2365 -0
  249. package/src/lib/generators/module-fact-sources.ts +108 -0
  250. package/src/lib/generators/module-facts-discovery.ts +58 -7
  251. package/src/lib/generators/module-facts.ts +1851 -46
  252. package/src/lib/generators/module-override-targets.ts +863 -0
  253. package/src/lib/generators/module-registry.ts +16 -6
  254. package/src/lib/load-env.ts +30 -0
  255. package/src/lib/resolver.ts +3 -0
  256. package/src/lib/telemetry-init.ts +461 -0
  257. package/src/lib/testing/__tests__/integration.test.ts +4 -0
  258. package/src/lib/testing/integration.ts +5 -0
  259. package/src/mercato.ts +26 -1
  260. package/dist/agentic/guides/cache.md +0 -45
  261. package/dist/agentic/guides/core.md +0 -453
  262. package/dist/agentic/guides/events.md +0 -117
  263. package/dist/agentic/guides/queue.md +0 -53
  264. package/dist/agentic/guides/search.md +0 -115
  265. package/dist/agentic/guides/shared.md +0 -108
  266. package/dist/agentic/guides/ui.md +0 -347
  267. package/dist/agentic/shared/ai/skills/om-auto-continue-pr-loop/SKILL.md +0 -27
  268. package/dist/agentic/shared/ai/skills/om-auto-create-pr-loop/SKILL.md +0 -27
  269. package/dist/agentic/shared/ai/skills/om-backend-ui-design/references/ui-components.md +0 -260
  270. package/dist/agentic/shared/ai/skills/om-data-model-design/references/mikro-orm-cheatsheet.md +0 -146
  271. package/dist/agentic/shared/ai/skills/om-help/references/skills-catalog.md +0 -84
  272. package/dist/agentic/shared/ai/skills/om-help/references/workflow-sequences.md +0 -193
  273. package/dist/agentic/shared/ai/skills/om-integration-builder/STANDALONE.md +0 -34
  274. package/dist/agentic/shared/ai/skills/om-integration-builder/references/adapter-contracts.md +0 -762
  275. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/naming-conventions.md +0 -50
  276. package/dist/agentic/shared/ai/skills/om-module-scaffold/references/navigation-patterns.md +0 -97
  277. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-contracts.md +0 -271
  278. package/dist/agentic/shared/ai/skills/om-troubleshooter/references/diagnostic-commands.md +0 -101
@@ -0,0 +1,119 @@
1
+ import fs from 'node:fs'
2
+ import os from 'node:os'
3
+ import path from 'node:path'
4
+ import { extractModuleFacts, renderModuleFactsMarkdown } from '../module-facts'
5
+
6
+ function writeFixture(root: string, relativePath: string, source: string): void {
7
+ const filePath = path.join(root, relativePath)
8
+ fs.mkdirSync(path.dirname(filePath), { recursive: true })
9
+ fs.writeFileSync(filePath, source)
10
+ }
11
+
12
+ describe('module-facts source-linked extension surfaces', () => {
13
+ let temporaryRoot: string
14
+ let moduleRoot: string
15
+
16
+ beforeAll(() => {
17
+ temporaryRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'module-facts-source-links-'))
18
+ moduleRoot = path.join(temporaryRoot, 'facts')
19
+ writeFixture(moduleRoot, 'index.ts', "export const metadata = { title: 'Facts' }\n")
20
+ writeFixture(
21
+ moduleRoot,
22
+ 'api/records/route.ts',
23
+ "export const metadata = { path: '/facts/records-custom' }\nexport async function GET() {}\n",
24
+ )
25
+ writeFixture(moduleRoot, 'backend/page.tsx', 'export default function FactsPage() { return null }\n')
26
+ writeFixture(
27
+ moduleRoot,
28
+ 'backend/facts/items/[id]/page.tsx',
29
+ 'export default function FactItemPage() { return null }\n',
30
+ )
31
+ writeFixture(
32
+ moduleRoot,
33
+ 'frontend/facts/portal/[id]/page.tsx',
34
+ 'export default function FactPortalPage() { return null }\n',
35
+ )
36
+ writeFixture(
37
+ moduleRoot,
38
+ 'cli.ts',
39
+ "const commands = [{ command: 'facts:sync' }, { command: 'facts:check' }]\nexport default commands\n",
40
+ )
41
+ writeFixture(
42
+ moduleRoot,
43
+ 'ai-tools/tools-pack.ts',
44
+ "type FactsAiToolDefinition = { name: string; description: string }\nconst inspectTool: FactsAiToolDefinition = { name: 'facts.inspect', description: 'Inspect facts' }\nexport default [inspectTool]\n",
45
+ )
46
+ writeFixture(
47
+ moduleRoot,
48
+ 'ai-tools.ts',
49
+ "type FactsAiToolDefinition = { name: string; description: string }\nconst listTool: FactsAiToolDefinition = { name: 'facts.list', description: 'List facts' }\nexport const aiTools = [listTool]\nexport default aiTools\n",
50
+ )
51
+ writeFixture(
52
+ moduleRoot,
53
+ 'ai-agents.ts',
54
+ "type AiAgentDefinition = { id: string; label: string }\nconst AGENT_ID = 'facts.assistant'\nconst agent: AiAgentDefinition = { id: AGENT_ID, label: 'Facts assistant' }\nexport const aiAgents = [agent]\nexport default aiAgents\n",
55
+ )
56
+ })
57
+
58
+ afterAll(() => {
59
+ fs.rmSync(temporaryRoot, { recursive: true, force: true })
60
+ })
61
+
62
+ it('emits portable source links for routes, pages, commands, tools, and agents', () => {
63
+ const registrySource = `export const modules = [{
64
+ id: 'facts',
65
+ apis: [{
66
+ path: '/facts/records-custom',
67
+ handlers: { GET: async () => undefined },
68
+ metadata: { GET: { requireFeatures: ['facts.view'] } },
69
+ }],
70
+ }]`
71
+ const facts = extractModuleFacts({
72
+ moduleId: 'facts',
73
+ moduleRoot,
74
+ sourcePackage: '@open-mercato/example',
75
+ sourceVersion: '1.2.3',
76
+ registrySource,
77
+ })
78
+
79
+ expect(facts.sourceRoot).toBe('node_modules/@open-mercato/example/src/modules/facts')
80
+ expect(facts.apiRoutes).toEqual([
81
+ {
82
+ path: '/facts/records-custom',
83
+ methods: ['GET'],
84
+ auth: { GET: { requireFeatures: ['facts.view'] } },
85
+ sourcePath: 'node_modules/@open-mercato/example/src/modules/facts/api/records/route.ts',
86
+ },
87
+ ])
88
+ expect(facts.backendPages).toEqual([
89
+ {
90
+ path: '/backend/facts',
91
+ sourcePath: 'node_modules/@open-mercato/example/src/modules/facts/backend/page.tsx',
92
+ },
93
+ {
94
+ path: '/backend/facts/items/[id]',
95
+ sourcePath: 'node_modules/@open-mercato/example/src/modules/facts/backend/facts/items/[id]/page.tsx',
96
+ },
97
+ ])
98
+ expect(facts.frontendPages).toEqual([
99
+ {
100
+ path: '/facts/portal/[id]',
101
+ sourcePath: 'node_modules/@open-mercato/example/src/modules/facts/frontend/facts/portal/[id]/page.tsx',
102
+ },
103
+ ])
104
+ expect(facts.cli).toEqual(['facts:sync', 'facts:check'])
105
+ expect(facts.cliCommands.map((command) => command.command)).toEqual(['facts:sync', 'facts:check'])
106
+ expect(facts.aiTools.map((tool) => tool.name)).toEqual(['facts.inspect', 'facts.list'])
107
+ expect(facts.aiAgents.map((agentFact) => agentFact.id)).toEqual(['facts.assistant'])
108
+
109
+ const markdown = renderModuleFactsMarkdown(facts)
110
+ expect(markdown).toContain('## Backend pages')
111
+ expect(markdown).toContain('## Frontend pages')
112
+ expect(markdown).toContain('## CLI commands')
113
+ expect(markdown).toContain('## AI tools / MCP capabilities')
114
+ expect(markdown).toContain('## AI agents')
115
+ expect(markdown).toContain(
116
+ '(../../../node_modules/@open-mercato/example/src/modules/facts/api/records/route.ts)',
117
+ )
118
+ })
119
+ })
@@ -0,0 +1,149 @@
1
+ import {
2
+ applyApiOverridesToManifests,
3
+ applyDiOverrides,
4
+ applyDiOverridesToContainer,
5
+ applyInjectionWidgetOverridesToEntries,
6
+ applyPageGuardOverridesToEntries,
7
+ applyPageOverridesToManifests,
8
+ applyWorkerOverridesToDescriptors,
9
+ resetModuleContractOverridesForTests,
10
+ } from '@open-mercato/shared/modules/overrides'
11
+ import type { ModuleFactsJsonEntry } from '../module-facts'
12
+ import { collectModuleOverrideTargets, type ModuleOverrideTarget } from '../module-override-targets'
13
+
14
+ const SOURCE_ROOT = 'node_modules/@open-mercato/core/src/modules/demo'
15
+
16
+ function facts(): ModuleFactsJsonEntry {
17
+ return {
18
+ title: null, description: null, coreVersion: null, sourcePackage: '@open-mercato/core',
19
+ sourceVersion: null, sourceRoot: SOURCE_ROOT,
20
+ entities: [], events: [], aclFeatures: ['demo.view'],
21
+ apiRoutes: [{ path: '/demo/items', methods: ['GET', 'POST'], auth: {}, sourcePath: `${SOURCE_ROOT}/api/items/route.ts` }],
22
+ diTokens: ['demoService'], searchEntities: [], hostTokens: { entityIds: [], tableIds: [] },
23
+ notifications: [], cli: [], backendPages: [{ path: '/backend/demo/list', sourcePath: `${SOURCE_ROOT}/backend/demo/list/page.tsx` }],
24
+ frontendPages: [{ path: '/demo-portal', sourcePath: `${SOURCE_ROOT}/frontend/demo-portal/page.tsx` }],
25
+ cliCommands: [], aiTools: [], aiAgents: [],
26
+ factSources: [{ kind: 'acl-feature', id: 'demo.view', source: { sourcePath: `${SOURCE_ROOT}/acl.ts` } }],
27
+ ownedContracts: {
28
+ worker: [{ kind: 'worker', id: 'demo.worker', source: { sourcePath: `${SOURCE_ROOT}/workers/demo.ts`, line: 3 }, metadata: { queue: 'demo', concurrency: 1 } }],
29
+ 'page-middleware': [{ kind: 'page-middleware', id: 'demo.guard', source: { sourcePath: `${SOURCE_ROOT}/backend/middleware.ts`, line: 2 }, metadata: { surface: 'backend' } }],
30
+ 'di-registration': [{ kind: 'di-registration', id: 'demoService', source: { sourcePath: `${SOURCE_ROOT}/di.ts`, line: 5 }, metadata: { registrationKind: 'class' } }],
31
+ },
32
+ extensionSurfaces: {
33
+ hosts: [], unresolved: [],
34
+ contributions: [
35
+ { id: 'demo.widget@profile:demo:slot', kind: 'widget', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/widgets/injection-table.ts`, symbol: 'injectionTable' }, details: { payload: 'render', registryKey: 'demo.widget', executionGuard: 'host' } },
36
+ { id: 'demo.mutation-guard', kind: 'mutation-guard', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/data/guards.ts`, symbol: 'demo.mutation-guard' }, details: { entityId: 'demo.entity', operations: ['create'], capabilities: ['block'], optimisticLock: 'preserved' } },
37
+ ],
38
+ },
39
+ }
40
+ }
41
+
42
+ const TARGETS = collectModuleOverrideTargets(facts()).overrideTargets
43
+ function key(domain: string, pathTail: string): string {
44
+ const target = TARGETS.find((t: ModuleOverrideTarget) => t.domain === domain && t.path[t.path.length - 1] === pathTail)
45
+ if (!target || target.key === undefined) throw new Error(`[internal] no keyed ${domain} target for ${pathTail}`)
46
+ return target.key
47
+ }
48
+
49
+ afterEach(() => resetModuleContractOverridesForTests())
50
+
51
+ describe('runtime resolver round-trip — positive', () => {
52
+ it('selects the intended API route method by the generated public key', () => {
53
+ const getKey = key('routes', 'GET /api/demo/items')
54
+ const routes = [{ moduleId: 'demo', path: '/demo/items', methods: ['GET', 'POST'], load: async () => ({}) }]
55
+ const result = applyApiOverridesToManifests(routes as never, { [getKey]: null })
56
+ expect(result).toHaveLength(1)
57
+ expect(result[0].methods).toEqual(['POST'])
58
+ })
59
+
60
+ it('selects the intended backend and frontend page by the generated application-route key', () => {
61
+ const backendKey = key('routes', 'backend:/backend/demo/list')
62
+ const frontendKey = key('routes', 'frontend:/demo-portal')
63
+ const backend = applyPageOverridesToManifests([{ moduleId: 'demo', path: '/backend/demo/list', load: async () => ({}) }] as never, { [backendKey]: null }, 'backend')
64
+ const frontend = applyPageOverridesToManifests([{ moduleId: 'demo', path: '/demo-portal', load: async () => ({}) }] as never, { [frontendKey]: null }, 'frontend')
65
+ expect(backend).toHaveLength(0)
66
+ expect(frontend).toHaveLength(0)
67
+ })
68
+
69
+ it('selects the intended worker / injection widget / page middleware by exact key', () => {
70
+ const workers = applyWorkerOverridesToDescriptors(
71
+ [{ id: 'demo.worker', queue: 'demo', concurrency: 1, handler: () => undefined }],
72
+ { [key('workers', 'demo.worker')]: null },
73
+ )
74
+ expect(workers).toHaveLength(0)
75
+
76
+ const widgets = applyInjectionWidgetOverridesToEntries(
77
+ [{ moduleId: 'demo', key: 'demo.widget', loader: async () => ({}) }] as never,
78
+ { [key('widgets', 'demo.widget')]: null },
79
+ )
80
+ expect(widgets).toHaveLength(0)
81
+
82
+ const guards = applyPageGuardOverridesToEntries(
83
+ [{ moduleId: 'demo', middleware: [{ id: 'demo.guard', run: async () => undefined }] }] as never,
84
+ { [key('guards', 'demo.guard')]: null },
85
+ )
86
+ expect(guards[0].middleware).toHaveLength(0)
87
+ })
88
+
89
+ it('unregisters the exact DI token via the generated key', () => {
90
+ const unregistered: string[] = []
91
+ const container = {
92
+ register: () => container,
93
+ unregister: (name: string) => { unregistered.push(name); return container },
94
+ registrations: { demoService: {} as unknown },
95
+ }
96
+ applyDiOverrides({ [key('di', 'demoService')]: null })
97
+ applyDiOverridesToContainer(container)
98
+ expect(unregistered).toEqual(['demoService'])
99
+ })
100
+ })
101
+
102
+ describe('runtime resolver round-trip — negative (malformed variants do not select)', () => {
103
+ it('a lowercased / method-less API key does not select the manifest entry', () => {
104
+ const getKey = key('routes', 'GET /api/demo/items')
105
+ expect(getKey).toMatch(/^(GET|POST|PUT|PATCH|DELETE) \/api\//)
106
+ const routes = [{ moduleId: 'demo', path: '/demo/items', methods: ['GET', 'POST'], load: async () => ({}) }]
107
+ const lowercased = applyApiOverridesToManifests(routes as never, { 'get /api/demo/items': null })
108
+ expect(lowercased[0].methods).toEqual(['GET', 'POST'])
109
+ const methodless = applyApiOverridesToManifests(routes as never, { '/api/demo/items': null })
110
+ expect(methodless[0].methods).toEqual(['GET', 'POST'])
111
+ })
112
+
113
+ it('a UI filesystem path does not select a page; the generated application route does', () => {
114
+ const filesystemPath = `${SOURCE_ROOT}/backend/demo/list/page.tsx`
115
+ const wrong = applyPageOverridesToManifests([{ moduleId: 'demo', path: '/backend/demo/list', load: async () => ({}) }] as never, { [filesystemPath]: null }, 'backend')
116
+ expect(wrong).toHaveLength(1)
117
+ const backendKey = key('routes', 'backend:/backend/demo/list')
118
+ expect(backendKey).not.toContain('.tsx')
119
+ expect(backendKey.startsWith('backend:')).toBe(true)
120
+ })
121
+
122
+ it('a flattened nested widget key does not select the injection entry', () => {
123
+ const flattened = applyInjectionWidgetOverridesToEntries(
124
+ [{ moduleId: 'demo', key: 'demo.widget', loader: async () => ({}) }] as never,
125
+ { 'widgets.injection.demo.widget': null },
126
+ )
127
+ expect(flattened).toHaveLength(1)
128
+ })
129
+
130
+ it('a mutation-guard id under page guards does not drop the page middleware', () => {
131
+ const guards = applyPageGuardOverridesToEntries(
132
+ [{ moduleId: 'demo', middleware: [{ id: 'demo.guard', run: async () => undefined }] }] as never,
133
+ { 'demo.mutation-guard': null },
134
+ )
135
+ expect(guards[0].middleware).toHaveLength(1)
136
+ // the mutation guard is never emitted as a guards target
137
+ expect(TARGETS.some((t) => t.domain === 'guards' && t.key === 'demo.mutation-guard')).toBe(false)
138
+ })
139
+
140
+ it('an unknown DI token is never emitted; emitted tokens correspond to real registrations', () => {
141
+ expect(TARGETS.some((t) => t.domain === 'di' && t.key === 'nope')).toBe(false)
142
+ expect(TARGETS.some((t) => t.domain === 'di' && t.key === 'demoService')).toBe(true)
143
+ })
144
+
145
+ it('framework-only nav.groupOrder is never attached to a module target', () => {
146
+ expect(TARGETS.some((t) => t.domain === 'nav')).toBe(false)
147
+ expect(TARGETS.some((t) => JSON.stringify(t.path) === JSON.stringify(['nav', 'groupOrder']))).toBe(false)
148
+ })
149
+ })
@@ -0,0 +1,304 @@
1
+ import type { ModuleFactsJsonEntry } from '../module-facts'
2
+ import {
3
+ ALL_OVERRIDE_DOMAINS,
4
+ MODULE_OVERRIDE_TARGET_ADAPTERS,
5
+ collectModuleOverrideTargets,
6
+ computeOverrideTargetId,
7
+ } from '../module-override-targets'
8
+
9
+ const SOURCE_ROOT = 'node_modules/@open-mercato/core/src/modules/demo'
10
+ const MODULE_ID = 'demo'
11
+
12
+ function baseFacts(overrides: Partial<ModuleFactsJsonEntry> = {}): ModuleFactsJsonEntry {
13
+ return {
14
+ title: 'Demo',
15
+ description: null,
16
+ coreVersion: null,
17
+ sourcePackage: '@open-mercato/core',
18
+ sourceVersion: null,
19
+ sourceRoot: SOURCE_ROOT,
20
+ entities: [],
21
+ events: [],
22
+ aclFeatures: ['demo.view'],
23
+ apiRoutes: [
24
+ { path: '/demo/items', methods: ['GET', 'POST'], auth: {}, sourcePath: `${SOURCE_ROOT}/api/items/route.ts` },
25
+ ],
26
+ diTokens: ['demoService'],
27
+ searchEntities: [],
28
+ hostTokens: { entityIds: [], tableIds: [] },
29
+ notifications: ['demo.alert'],
30
+ cli: ['demo:seed'],
31
+ backendPages: [{ path: '/backend/demo/list', sourcePath: `${SOURCE_ROOT}/backend/demo/list/page.tsx` }],
32
+ frontendPages: [{ path: '/demo-portal', sourcePath: `${SOURCE_ROOT}/frontend/demo-portal/page.tsx` }],
33
+ cliCommands: [{ command: 'demo:seed', sourcePath: `${SOURCE_ROOT}/cli.ts` }],
34
+ aiTools: [{ name: 'demo.tool', sourcePath: `${SOURCE_ROOT}/ai-tools.ts` }],
35
+ aiAgents: [{ id: 'demo.agent', sourcePath: `${SOURCE_ROOT}/ai-agents.ts` }],
36
+ factSources: [
37
+ { kind: 'acl-feature', id: 'demo.view', source: { sourcePath: `${SOURCE_ROOT}/acl.ts` } },
38
+ { kind: 'notification', id: 'demo.alert', source: { sourcePath: `${SOURCE_ROOT}/notifications.ts` } },
39
+ ],
40
+ ownedContracts: {
41
+ worker: [{ kind: 'worker', id: 'demo.worker', source: { sourcePath: `${SOURCE_ROOT}/workers/demo.ts`, line: 3 } }],
42
+ 'page-middleware': [{ kind: 'page-middleware', id: 'demo.guard', source: { sourcePath: `${SOURCE_ROOT}/backend/middleware.ts`, line: 2 }, metadata: { surface: 'backend' } }],
43
+ setup: [{ kind: 'setup', id: 'demo:setup', source: { sourcePath: `${SOURCE_ROOT}/setup.ts`, line: 1 }, metadata: { hooks: ['seedDefaults', 'seedExamples', 'onTenantCreated', 'installStuff'], roles: ['admin'] } }],
44
+ 'di-registration': [{ kind: 'di-registration', id: 'demoService', source: { sourcePath: `${SOURCE_ROOT}/di.ts`, line: 5 }, metadata: { registrationKind: 'class', lifetime: 'scoped' } }],
45
+ encryption: [{ kind: 'encryption', id: 'demo:secret', source: { sourcePath: `${SOURCE_ROOT}/encryption.ts`, line: 2 }, metadata: { fields: ['token'] } }],
46
+ 'ai-extension': [
47
+ { kind: 'ai-extension', id: 'agent-extension:other.agent', source: { sourcePath: `${SOURCE_ROOT}/ai-agents.extensions.ts`, line: 1 }, metadata: { target: 'agent', mode: 'extension', targetAgentId: 'other.agent' } },
48
+ { kind: 'ai-extension', id: 'agent-override:other.assistant', source: { sourcePath: `${SOURCE_ROOT}/ai-agents.ts`, line: 7 }, metadata: { target: 'agent', mode: 'override', overrideKey: 'other.assistant' } },
49
+ { kind: 'ai-extension', id: 'tool-override:other.tool', source: { sourcePath: `${SOURCE_ROOT}/ai-tools.ts`, line: 9 }, metadata: { target: 'tool', mode: 'override', overrideKey: 'other.tool' } },
50
+ ],
51
+ },
52
+ extensionSurfaces: {
53
+ hosts: [],
54
+ unresolved: [],
55
+ contributions: [
56
+ { id: 'demo:sub', kind: 'subscriber', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/subscribers/demo.ts`, symbol: 'metadata' }, details: { event: 'demo.e', subscriberId: 'demo:sub', persistent: true, sync: false } },
57
+ { id: 'demo.interceptor', kind: 'api-interceptor', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/api/interceptors.ts`, symbol: 'demo.interceptor' }, details: { route: 'items', methods: ['POST'], phases: ['before'], activation: 'crud-pipeline', timeoutMs: 2000, failurePosture: 'fallback' } },
58
+ { id: 'demo.cmd', kind: 'command-interceptor', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/commands/interceptors.ts`, symbol: 'demo.cmd' }, details: { targetCommand: 'demo.thing.update', phases: ['before-execute'] } },
59
+ { id: 'demo.enricher', kind: 'response-enricher', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/data/enrichers.ts`, symbol: 'demo.enricher' }, details: { targetEntity: 'demo.entity', surfaces: ['list'], timeoutMs: 2000, fallback: 'none', critical: false, cachePosture: 'record-pure' } },
60
+ { id: 'demo.widget@profile:demo:slot', kind: 'widget', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/widgets/injection-table.ts`, symbol: 'injectionTable' }, details: { payload: 'render', registryKey: 'demo.widget', executionGuard: 'host' } },
61
+ { id: 'dashboard:demo.card', kind: 'widget', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/widgets/dashboard/card/widget.ts`, symbol: 'widget.metadata' }, details: { payload: 'dashboard', registryKey: 'demo.card', executionGuard: 'both' } },
62
+ { id: 'demo.table-widget@data-table:demo.list:columns', kind: 'data-table', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/widgets/injection-table.ts`, symbol: 'injectionTable' }, details: { payload: 'column', tableId: 'demo.list', executionGuard: 'host' } },
63
+ { id: 'demo.override.0:section:demo.login', kind: 'component-override', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/widgets/components.ts`, symbol: 'componentOverrides' }, details: { handle: 'section:demo.login', mode: 'replace', propsContract: 'x' } },
64
+ { id: 'demo.mutation-guard', kind: 'mutation-guard', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/data/guards.ts`, symbol: 'demo.mutation-guard' }, details: { entityId: 'demo.entity', operations: ['create'], capabilities: ['block'], optimisticLock: 'preserved' } },
65
+ { id: 'notification:demo.alert', kind: 'specialized-registry', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/notifications.ts`, symbol: 'demo.alert' }, details: { registry: 'notification', registryId: 'demo.alert', specialistRoute: 'notifications' } },
66
+ { id: 'demo.alert-handler', kind: 'browser-reaction', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/notifications.handlers.ts`, symbol: 'notificationHandlers' }, details: { transports: ['notification-effect'], hooks: ['useNotificationEffect'], audienceScopeContract: 'tenant', overrideKey: 'demo.alert-handler' } },
67
+ { id: 'demo.notification-handler.1', kind: 'browser-reaction', targets: [], scopeContract: '', source: { path: `${SOURCE_ROOT}/notifications.handlers.ts`, symbol: 'notificationHandlers' }, details: { transports: ['notification-effect'], hooks: ['useNotificationEffect'], audienceScopeContract: 'tenant' } },
68
+ ],
69
+ },
70
+ ...overrides,
71
+ }
72
+ }
73
+
74
+ function targetFor(facts: ModuleFactsJsonEntry, domain: string, key?: string) {
75
+ const { overrideTargets } = collectModuleOverrideTargets(facts)
76
+ return overrideTargets.find((target) => target.domain === domain && (key === undefined || target.key === key))
77
+ }
78
+
79
+ describe('module override targets — adapter registry coverage', () => {
80
+ it('covers every runtime override domain with an adapter or explicit framework-only classification', () => {
81
+ const adaptersByDomain = new Map(MODULE_OVERRIDE_TARGET_ADAPTERS.map((adapter) => [adapter.domain, adapter]))
82
+ for (const domain of ALL_OVERRIDE_DOMAINS) {
83
+ const adapter = adaptersByDomain.get(domain)
84
+ expect(adapter).toBeDefined()
85
+ }
86
+ for (const adapter of MODULE_OVERRIDE_TARGET_ADAPTERS) {
87
+ expect(ALL_OVERRIDE_DOMAINS).toContain(adapter.domain)
88
+ }
89
+ // exactly the 16 runtime domains, one adapter each
90
+ expect(ALL_OVERRIDE_DOMAINS).toHaveLength(16)
91
+ expect(MODULE_OVERRIDE_TARGET_ADAPTERS).toHaveLength(16)
92
+ })
93
+
94
+ it('classifies nav as framework-only (never a module target)', () => {
95
+ const navAdapter = MODULE_OVERRIDE_TARGET_ADAPTERS.find((adapter) => adapter.domain === 'nav')
96
+ expect(navAdapter?.frameworkOnly).toBe(true)
97
+ expect(navAdapter?.collect(baseFacts())).toEqual([])
98
+ const { overrideTargets } = collectModuleOverrideTargets(baseFacts())
99
+ expect(overrideTargets.some((target) => target.domain === 'nav')).toBe(false)
100
+ expect(overrideTargets.some((target) => JSON.stringify(target.path) === JSON.stringify(['nav', 'groupOrder']))).toBe(false)
101
+ })
102
+ })
103
+
104
+ describe('module override targets — golden target per domain family', () => {
105
+ const { overrideTargets } = collectModuleOverrideTargets(baseFacts())
106
+ const byPath = (path: string[]) => overrideTargets.find((target) => JSON.stringify(target.path) === JSON.stringify(path))
107
+
108
+ it.each([
109
+ ['ai', ['ai', 'agents', 'demo.agent'], 'demo.agent', ['disable-replace']],
110
+ ['ai', ['ai', 'tools', 'demo.tool'], 'demo.tool', ['disable-replace']],
111
+ ['ai', ['ai', 'extensions'], undefined, ['additive']],
112
+ ['routes', ['routes', 'api', 'GET /api/demo/items'], 'GET /api/demo/items', ['disable-replace']],
113
+ ['routes', ['routes', 'api', 'POST /api/demo/items'], 'POST /api/demo/items', ['disable-replace']],
114
+ ['routes', ['routes', 'pages', 'backend:/backend/demo/list'], 'backend:/backend/demo/list', ['disable-replace']],
115
+ ['routes', ['routes', 'pages', 'frontend:/demo-portal'], 'frontend:/demo-portal', ['disable-replace']],
116
+ ['events', ['events', 'subscribers', 'demo:sub'], 'demo:sub', ['disable-replace']],
117
+ ['workers', ['workers', 'demo.worker'], 'demo.worker', ['disable-replace']],
118
+ ['widgets', ['widgets', 'injection', 'demo.widget'], 'demo.widget', ['disable-replace']],
119
+ ['widgets', ['widgets', 'injection', 'demo.table-widget'], 'demo.table-widget', ['disable-replace']],
120
+ ['widgets', ['widgets', 'dashboard', 'demo.card'], 'demo.card', ['disable-replace']],
121
+ ['widgets', ['widgets', 'components', 'section:demo.login'], 'section:demo.login', ['disable-replace']],
122
+ ['notifications', ['notifications', 'types', 'demo.alert'], 'demo.alert', ['disable-replace']],
123
+ ['interceptors', ['interceptors', 'demo.interceptor'], 'demo.interceptor', ['disable-replace']],
124
+ ['commandInterceptors', ['commandInterceptors', 'demo.cmd'], 'demo.cmd', ['disable-replace']],
125
+ ['enrichers', ['enrichers', 'demo.enricher'], 'demo.enricher', ['disable-replace']],
126
+ ['guards', ['guards', 'demo.guard'], 'demo.guard', ['disable-replace']],
127
+ ['cli', ['cli', 'demo:seed'], 'demo:seed', ['disable-replace']],
128
+ ['setup', ['setup', 'seedDefaults'], undefined, ['replace']],
129
+ ['acl', ['acl', 'features', 'demo.view'], 'demo.view', ['disable-replace']],
130
+ ['di', ['di', 'demoService'], 'demoService', ['disable-replace']],
131
+ ['encryption', ['encryption', 'maps', 'demo:secret'], 'demo:secret', ['disable-replace']],
132
+ ])('emits %s target at %j', (domain, path, key, modes) => {
133
+ const target = byPath(path as string[])
134
+ expect(target).toBeDefined()
135
+ expect(target?.domain).toBe(domain)
136
+ expect(target?.key).toBe(key)
137
+ expect(target?.modes).toEqual(modes)
138
+ expect(target?.factRef.factSection.length).toBeGreaterThan(0)
139
+ expect(target?.source.sourcePath.length).toBeGreaterThan(0)
140
+ expect(target?.id).toBe(computeOverrideTargetId(MODULE_ID, domain as never, path as string[]))
141
+ })
142
+
143
+ it('emits the supported setup hook/profile paths only (not unsupported hooks)', () => {
144
+ const setupPaths = overrideTargets.filter((t) => t.domain === 'setup').map((t) => t.path[1]).sort()
145
+ expect(setupPaths).toEqual(['defaultRoleFeatures', 'onTenantCreated', 'seedDefaults', 'seedExamples'])
146
+ expect(setupPaths).not.toContain('installStuff')
147
+ })
148
+ })
149
+
150
+ describe('module override targets — invariants', () => {
151
+ const facts = baseFacts()
152
+ const { overrideTargets } = collectModuleOverrideTargets(facts)
153
+
154
+ it('holds the terminal-key invariant for every adapter/target', () => {
155
+ for (const target of overrideTargets) {
156
+ if (target.key !== undefined) {
157
+ expect(target.path[target.path.length - 1]).toBe(target.key)
158
+ } else {
159
+ // keyless targets are structured singleton properties, never a lookup key
160
+ expect(['ai/extensions', 'setup']).toContain(
161
+ target.path[0] === 'setup' ? 'setup' : target.path.join('/'),
162
+ )
163
+ }
164
+ }
165
+ })
166
+
167
+ it('preserves nested widget and AI paths without flattening keys', () => {
168
+ const widget = targetFor(facts, 'widgets', 'demo.widget')
169
+ expect(widget?.path).toEqual(['widgets', 'injection', 'demo.widget'])
170
+ const agent = targetFor(facts, 'ai', 'demo.agent')
171
+ expect(agent?.path).toEqual(['ai', 'agents', 'demo.agent'])
172
+ // never collapse to a single flattened dotted segment
173
+ for (const target of overrideTargets) {
174
+ expect(target.path.some((segment) => segment === `${target.domain}.injection` || segment === `${target.domain}.agents`)).toBe(false)
175
+ }
176
+ })
177
+
178
+ it('points CLI override targets at the source-bearing command fact', () => {
179
+ const cli = targetFor(facts, 'cli', 'demo:seed')
180
+ expect(cli?.factRef).toEqual({ factSection: 'cliCommands', factKey: 'demo:seed' })
181
+ })
182
+
183
+ it('exposes DI tokens with the safe-metadata-only note and no runtime value/body', () => {
184
+ const di = targetFor(facts, 'di', 'demoService')
185
+ expect(di?.notes).toEqual(['safe-metadata-only'])
186
+ expect(di?.factRef).toEqual({ factSection: 'ownedContracts.di-registration', factKey: 'demoService' })
187
+ const serialized = JSON.stringify(di)
188
+ for (const forbidden of ['register', 'asClass', 'asFunction', 'asValue', 'handler', 'resolve', 'lifetime', 'value']) {
189
+ expect(serialized).not.toContain(forbidden)
190
+ }
191
+ })
192
+
193
+ it('keeps page middleware under guards and never emits a mutation guard there', () => {
194
+ const guard = targetFor(facts, 'guards', 'demo.guard')
195
+ expect(guard?.notes).toEqual(['page-middleware-not-mutation-guard'])
196
+ expect(guard?.factRef.factSection).toBe('ownedContracts.page-middleware')
197
+ const guardsTargets = overrideTargets.filter((t) => t.domain === 'guards')
198
+ expect(guardsTargets.every((t) => t.key !== 'demo.mutation-guard')).toBe(true)
199
+ expect(guardsTargets.every((t) => !t.source.sourcePath.includes('data/guards.ts'))).toBe(true)
200
+ })
201
+
202
+ it('sorts deterministically and regenerates byte-identically', () => {
203
+ const first = collectModuleOverrideTargets(baseFacts())
204
+ const second = collectModuleOverrideTargets(baseFacts())
205
+ expect(JSON.stringify(second)).toBe(JSON.stringify(first))
206
+ const domains = first.overrideTargets.map((t) => t.domain)
207
+ expect(domains).toEqual([...domains].sort((a, b) => a.localeCompare(b)))
208
+ })
209
+ })
210
+
211
+ describe('module override targets — deterministic diagnostics (never a guessed key)', () => {
212
+ it('emits missing-source and no target when the route source cannot be proven', () => {
213
+ const facts = baseFacts({
214
+ apiRoutes: [{ path: '/demo/items', methods: ['GET'], auth: {}, sourcePath: null }],
215
+ })
216
+ const { overrideTargets, overrideTargetDiagnostics } = collectModuleOverrideTargets(facts)
217
+ expect(overrideTargets.some((t) => t.domain === 'routes' && t.path[1] === 'api')).toBe(false)
218
+ const diag = overrideTargetDiagnostics.find((d) => d.domain === 'routes' && d.code === 'missing-source')
219
+ expect(diag).toBeDefined()
220
+ expect(diag?.moduleId).toBe(MODULE_ID)
221
+ expect(diag?.candidatePath).toEqual(['routes', 'api', 'GET /api/demo/items'])
222
+ expect(diag?.source).toBeUndefined()
223
+ })
224
+
225
+ it('emits missing-source when an acl feature has no indexed provenance', () => {
226
+ const facts = baseFacts({ factSources: [] })
227
+ const { overrideTargets, overrideTargetDiagnostics } = collectModuleOverrideTargets(facts)
228
+ expect(overrideTargets.some((t) => t.domain === 'acl')).toBe(false)
229
+ expect(overrideTargetDiagnostics.some((d) => d.domain === 'acl' && d.code === 'missing-source')).toBe(true)
230
+ })
231
+ })
232
+
233
+ describe('module override targets — keyed AI, notification handlers, setup profiles', () => {
234
+ it('emits exact ai.agents/ai.tools targets for keyed overrides and keeps extensions additive', () => {
235
+ const { overrideTargets } = collectModuleOverrideTargets(baseFacts())
236
+ const aiPaths = overrideTargets
237
+ .filter((target) => target.domain === 'ai')
238
+ .map((target) => target.path.join('.'))
239
+ .sort()
240
+ expect(aiPaths).toEqual([
241
+ 'ai.agents.demo.agent',
242
+ 'ai.agents.other.assistant',
243
+ 'ai.extensions',
244
+ 'ai.tools.demo.tool',
245
+ 'ai.tools.other.tool',
246
+ ])
247
+
248
+ const agentOverride = overrideTargets.find(
249
+ (target) => target.domain === 'ai' && target.key === 'other.assistant',
250
+ )
251
+ expect(agentOverride?.factRef).toEqual({
252
+ factSection: 'ownedContracts.ai-extension',
253
+ factKey: 'agent-override:other.assistant',
254
+ })
255
+ expect(agentOverride?.source.sourcePath).toBe(`${SOURCE_ROOT}/ai-agents.ts`)
256
+
257
+ const extensions = overrideTargets.find(
258
+ (target) => target.domain === 'ai' && target.path.join('.') === 'ai.extensions',
259
+ )
260
+ expect(extensions?.key).toBeUndefined()
261
+ expect(extensions?.factRef.factKey).toBe('agent-extension:other.agent')
262
+ expect(JSON.stringify(overrideTargets)).not.toContain('replacement')
263
+ })
264
+
265
+ it('emits notifications.handlers targets keyed by the declared handler id', () => {
266
+ const { overrideTargets, overrideTargetDiagnostics } = collectModuleOverrideTargets(baseFacts())
267
+ const handler = overrideTargets.find(
268
+ (target) => target.domain === 'notifications' && target.path[1] === 'handlers',
269
+ )
270
+ expect(handler?.path).toEqual(['notifications', 'handlers', 'demo.alert-handler'])
271
+ expect(handler?.key).toBe('demo.alert-handler')
272
+ expect(handler?.factRef).toEqual({
273
+ factSection: 'extensionSurfaces.contributions',
274
+ factKey: 'demo.alert-handler',
275
+ })
276
+
277
+ // A handler that declares no id cannot be addressed by runtime.
278
+ expect(overrideTargets.some((target) => target.path[2] === 'demo.notification-handler.1')).toBe(false)
279
+ expect(overrideTargetDiagnostics).toEqual(expect.arrayContaining([
280
+ expect.objectContaining({
281
+ code: 'unsupported-dynamic-key',
282
+ domain: 'notifications',
283
+ candidatePath: ['notifications', 'handlers'],
284
+ }),
285
+ ]))
286
+ })
287
+
288
+ it('emits setup.defaultCustomerRoleFeatures when customer-role profiles are declared', () => {
289
+ const withoutProfiles = collectModuleOverrideTargets(baseFacts()).overrideTargets
290
+ expect(withoutProfiles.some((target) => target.path.join('.') === 'setup.defaultCustomerRoleFeatures')).toBe(false)
291
+
292
+ const facts = baseFacts()
293
+ const setupFact = (facts.ownedContracts?.setup ?? [])[0]
294
+ const withProfiles = collectModuleOverrideTargets(baseFacts({
295
+ ownedContracts: {
296
+ ...facts.ownedContracts,
297
+ setup: [{ ...setupFact, metadata: { ...setupFact.metadata, customerRoles: ['portal-admin'] } }],
298
+ },
299
+ })).overrideTargets
300
+ const target = withProfiles.find((entry) => entry.path.join('.') === 'setup.defaultCustomerRoleFeatures')
301
+ expect(target).toBeDefined()
302
+ expect(target?.factRef).toEqual({ factSection: 'ownedContracts.setup', factKey: 'demo:setup' })
303
+ })
304
+ })
@@ -702,6 +702,24 @@ export function GET() {
702
702
  expect(output).toContain('features:')
703
703
  })
704
704
 
705
+ it('normalizes singular app-owned integration exports without requiring plural properties', async () => {
706
+ touchFile(
707
+ path.join(tmpDir, 'app', 'src', 'modules', 'mailbox', 'integration.ts'),
708
+ "export const integration = { id: 'mailbox' }\nexport default integration\n",
709
+ )
710
+ const resolver = createMockResolver(tmpDir, [{ id: 'mailbox', from: '@app' }])
711
+ const result = await generateModuleRegistry({ resolver, quiet: true })
712
+
713
+ expect(result.errors).toEqual([])
714
+ for (const file of ['modules.generated.ts', 'modules.runtime.generated.ts']) {
715
+ const output = readGenerated(tmpDir, file)!
716
+ expect(output).toContain('as unknown as { integrations?:')
717
+ expect(output).toContain('.integration ? [')
718
+ expect(output).not.toMatch(/INTEGRATION_[A-Za-z0-9_]+\.integrations/)
719
+ expect(output).not.toMatch(/INTEGRATION_[A-Za-z0-9_]+\.bundles/)
720
+ }
721
+ })
722
+
705
723
  it('escapes generated module specifiers for lazy imports', async () => {
706
724
  touchFile(
707
725
  path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'safe_mod', 'subscribers', `o'hare.ts`),