@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8665.1.2455b2503c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (285) hide show
  1. package/.turbo/turbo-build.log +4 -2
  2. package/AGENTS.md +3 -0
  3. package/dist/agentic/guides/architecture.md +2 -2
  4. package/dist/agentic/guides/extensions.md +7 -2
  5. package/dist/agentic/guides/framework-extension-points.md +1 -0
  6. package/dist/agentic/guides/infrastructure-providers.md +20 -0
  7. package/dist/agentic/guides/integrations.md +2 -2
  8. package/dist/agentic/guides/module-facts.json +2564 -265
  9. package/dist/agentic/guides/module-facts.v2.json +2580 -265
  10. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  11. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  12. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  13. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  14. package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
  15. package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
  16. package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
  17. package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
  18. package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
  19. package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
  20. package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
  21. package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
  22. package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
  23. package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
  24. package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
  25. package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
  26. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  27. package/dist/agentic/guides/modules/attachments/workers.md +1 -1
  28. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  29. package/dist/agentic/guides/modules/auth/index.md +1 -1
  30. package/dist/agentic/guides/modules/availability/index.md +1 -1
  31. package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
  32. package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
  33. package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
  34. package/dist/agentic/guides/modules/backups/index.md +5 -2
  35. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  36. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  37. package/dist/agentic/guides/modules/cart/index.md +1 -1
  38. package/dist/agentic/guides/modules/catalog/acl-features.md +2 -1
  39. package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
  40. package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
  41. package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
  42. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
  43. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
  44. package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
  45. package/dist/agentic/guides/modules/catalog/entities.md +1 -0
  46. package/dist/agentic/guides/modules/catalog/events.md +4 -1
  47. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
  48. package/dist/agentic/guides/modules/catalog/index.md +9 -9
  49. package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
  50. package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
  51. package/dist/agentic/guides/modules/catalog/workers.md +1 -0
  52. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  53. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  54. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  55. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  56. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  57. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  58. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  59. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  60. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  61. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  62. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  63. package/dist/agentic/guides/modules/configs/index.md +1 -1
  64. package/dist/agentic/guides/modules/content/index.md +1 -1
  65. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  66. package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
  67. package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
  68. package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
  69. package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
  70. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  71. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
  72. package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
  73. package/dist/agentic/guides/modules/customers/index.md +3 -3
  74. package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
  75. package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
  76. package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
  77. package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
  78. package/dist/agentic/guides/modules/dashboards/index.md +2 -3
  79. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  80. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  81. package/dist/agentic/guides/modules/devices/index.md +1 -1
  82. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  83. package/dist/agentic/guides/modules/directory/index.md +1 -1
  84. package/dist/agentic/guides/modules/documents/index.md +1 -1
  85. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  86. package/dist/agentic/guides/modules/entities/index.md +1 -1
  87. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  88. package/dist/agentic/guides/modules/events/index.md +1 -1
  89. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  90. package/dist/agentic/guides/modules/forms/index.md +1 -1
  91. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  92. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  93. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  94. package/dist/agentic/guides/modules/generators/index.md +1 -1
  95. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  96. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
  97. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
  98. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
  99. package/dist/agentic/guides/modules/integrations/index.md +2 -2
  100. package/dist/agentic/guides/modules/integrations/setup.md +1 -1
  101. package/dist/agentic/guides/modules/integrations/workers.md +3 -1
  102. package/dist/agentic/guides/modules/messages/index.md +1 -1
  103. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  104. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  105. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  106. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  107. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  108. package/dist/agentic/guides/modules/planner/index.md +1 -1
  109. package/dist/agentic/guides/modules/portal/index.md +1 -1
  110. package/dist/agentic/guides/modules/progress/index.md +1 -1
  111. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  112. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  113. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  114. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  115. package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
  116. package/dist/agentic/guides/modules/resources/index.md +1 -1
  117. package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
  118. package/dist/agentic/guides/modules/resources/setup.md +1 -1
  119. package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
  120. package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
  121. package/dist/agentic/guides/modules/sales/index.md +3 -3
  122. package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -0
  123. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  124. package/dist/agentic/guides/modules/search/index.md +1 -1
  125. package/dist/agentic/guides/modules/security/index.md +1 -1
  126. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  127. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  128. package/dist/agentic/guides/modules/sso/index.md +1 -1
  129. package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
  130. package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
  131. package/dist/agentic/guides/modules/staff/index.md +1 -1
  132. package/dist/agentic/guides/modules/staff/workers.md +1 -1
  133. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  134. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  135. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  136. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  137. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  138. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  139. package/dist/agentic/guides/modules/translations/index.md +1 -1
  140. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  141. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  142. package/dist/agentic/guides/modules/wms/index.md +1 -1
  143. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  144. package/dist/agentic/guides/reference-module-facts.json +811 -21
  145. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
  146. package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
  147. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
  148. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
  149. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  150. package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
  151. package/dist/agentic/guides/reference-modules/example/events.md +2 -1
  152. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
  153. package/dist/agentic/guides/reference-modules/example/index.md +7 -7
  154. package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
  155. package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
  156. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
  157. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
  158. package/dist/agentic/guides/upstream/AGENTS.md +5 -4
  159. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
  160. package/dist/agentic/guides/upstream/manifest.json +3 -3
  161. package/dist/agentic/shared/AGENTS.md.template +11 -15
  162. package/dist/agentic/shared/ai/harness/README.md +4 -2
  163. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  164. package/dist/agentic/shared/ai/harness/cases.json +1420 -41
  165. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  166. package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
  167. package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
  168. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  169. package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
  170. package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
  171. package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
  172. package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
  173. package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
  174. package/dist/lib/cache-provider-manifest.js +9 -0
  175. package/dist/lib/cache-provider-manifest.js.map +7 -0
  176. package/dist/lib/generate-child-process.js +21 -3
  177. package/dist/lib/generate-child-process.js.map +2 -2
  178. package/dist/lib/generate-watch-events.js +135 -19
  179. package/dist/lib/generate-watch-events.js.map +2 -2
  180. package/dist/lib/generate-watch-plan.js +170 -0
  181. package/dist/lib/generate-watch-plan.js.map +7 -0
  182. package/dist/lib/generate-watch-runner.js +54 -0
  183. package/dist/lib/generate-watch-runner.js.map +7 -0
  184. package/dist/lib/generate-watch-structure.js +578 -203
  185. package/dist/lib/generate-watch-structure.js.map +3 -3
  186. package/dist/lib/generators/ast/writers.js +5 -1
  187. package/dist/lib/generators/ast/writers.js.map +2 -2
  188. package/dist/lib/generators/cache-providers.js +80 -0
  189. package/dist/lib/generators/cache-providers.js.map +7 -0
  190. package/dist/lib/generators/extensions/agent-files.js +1 -0
  191. package/dist/lib/generators/extensions/agent-files.js.map +2 -2
  192. package/dist/lib/generators/form-section-ast.js +156 -0
  193. package/dist/lib/generators/form-section-ast.js.map +7 -0
  194. package/dist/lib/generators/form-section-extension-compiler.js +568 -0
  195. package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
  196. package/dist/lib/generators/form-section-extension-source.js +245 -0
  197. package/dist/lib/generators/form-section-extension-source.js.map +7 -0
  198. package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
  199. package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
  200. package/dist/lib/generators/form-sections.js +773 -0
  201. package/dist/lib/generators/form-sections.js.map +7 -0
  202. package/dist/lib/generators/index.js +2 -0
  203. package/dist/lib/generators/index.js.map +2 -2
  204. package/dist/lib/generators/module-entities.js +21 -2
  205. package/dist/lib/generators/module-entities.js.map +2 -2
  206. package/dist/lib/generators/module-extension-facts.js +2 -1
  207. package/dist/lib/generators/module-extension-facts.js.map +2 -2
  208. package/dist/lib/generators/module-facts.js +30 -1
  209. package/dist/lib/generators/module-facts.js.map +2 -2
  210. package/dist/lib/generators/module-override-targets.js +24 -2
  211. package/dist/lib/generators/module-override-targets.js.map +2 -2
  212. package/dist/lib/generators/module-registry.js +223 -194
  213. package/dist/lib/generators/module-registry.js.map +3 -3
  214. package/dist/lib/generators/openapi.js +51 -18
  215. package/dist/lib/generators/openapi.js.map +2 -2
  216. package/dist/lib/generators/web-research-adapters.js +54 -22
  217. package/dist/lib/generators/web-research-adapters.js.map +2 -2
  218. package/dist/lib/in-process-generate-watcher.js +98 -75
  219. package/dist/lib/in-process-generate-watcher.js.map +2 -2
  220. package/dist/lib/post-generate-invalidation.js +20 -1
  221. package/dist/lib/post-generate-invalidation.js.map +2 -2
  222. package/dist/lib/resolver.js +195 -1
  223. package/dist/lib/resolver.js.map +3 -3
  224. package/dist/lib/single-instance-strategy-guard.js +26 -3
  225. package/dist/lib/single-instance-strategy-guard.js.map +2 -2
  226. package/dist/mercato.js +106 -50
  227. package/dist/mercato.js.map +2 -2
  228. package/jest.config.cjs +2 -0
  229. package/package.json +7 -7
  230. package/src/__tests__/mercato.test.ts +18 -0
  231. package/src/__tests__/rotation-json-output.test.ts +52 -0
  232. package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
  233. package/src/lib/__tests__/generate-child-process.test.ts +30 -0
  234. package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
  235. package/src/lib/__tests__/generate-watch-plan.test.ts +99 -0
  236. package/src/lib/__tests__/generate-watch-runner.test.ts +138 -0
  237. package/src/lib/__tests__/generate-watch-structure.test.ts +556 -1
  238. package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
  239. package/src/lib/__tests__/module-inspection.test.ts +17 -11
  240. package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
  241. package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
  242. package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
  243. package/src/lib/cache-provider-manifest.ts +8 -0
  244. package/src/lib/generate-child-process.ts +26 -3
  245. package/src/lib/generate-watch-events.ts +189 -17
  246. package/src/lib/generate-watch-plan.ts +180 -0
  247. package/src/lib/generate-watch-runner.ts +63 -0
  248. package/src/lib/generate-watch-structure.ts +670 -227
  249. package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
  250. package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
  251. package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
  252. package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
  253. package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
  254. package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
  255. package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
  256. package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
  257. package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
  258. package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
  259. package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
  260. package/src/lib/generators/__tests__/openapi.test.ts +147 -10
  261. package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
  262. package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
  263. package/src/lib/generators/ast/writers.ts +6 -1
  264. package/src/lib/generators/cache-providers.ts +111 -0
  265. package/src/lib/generators/extension.ts +2 -0
  266. package/src/lib/generators/extensions/agent-files.ts +1 -0
  267. package/src/lib/generators/form-section-ast.ts +166 -0
  268. package/src/lib/generators/form-section-extension-compiler.ts +632 -0
  269. package/src/lib/generators/form-section-extension-source.ts +308 -0
  270. package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
  271. package/src/lib/generators/form-sections.ts +896 -0
  272. package/src/lib/generators/index.ts +1 -0
  273. package/src/lib/generators/module-entities.ts +22 -4
  274. package/src/lib/generators/module-extension-facts.ts +1 -0
  275. package/src/lib/generators/module-facts.ts +40 -0
  276. package/src/lib/generators/module-override-targets.ts +19 -0
  277. package/src/lib/generators/module-registry.ts +246 -202
  278. package/src/lib/generators/openapi.ts +65 -20
  279. package/src/lib/generators/web-research-adapters.ts +76 -21
  280. package/src/lib/in-process-generate-watcher.ts +151 -96
  281. package/src/lib/post-generate-invalidation.ts +28 -1
  282. package/src/lib/resolver.ts +218 -0
  283. package/src/lib/single-instance-strategy-guard.ts +51 -1
  284. package/src/mercato.ts +117 -57
  285. package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
@@ -1,7 +1,14 @@
1
1
  import fs from 'node:fs'
2
2
  import os from 'node:os'
3
3
  import path from 'node:path'
4
- import { calculateGenerateWatchStructureChecksum } from '../generate-watch-structure'
4
+ import {
5
+ calculateGenerateWatchStructureChecksum,
6
+ collectGenerateWatchStructureSnapshot,
7
+ createGenerateWatchStructureCache,
8
+ diffGenerateWatchStructureSnapshots,
9
+ type GenerateWatchStructureOptions,
10
+ } from '../generate-watch-structure'
11
+ import { planGenerateWatchChanges, type GenerateWatchSnapshot } from '../generate-watch-plan'
5
12
 
6
13
  function write(filePath: string, content: string): void {
7
14
  fs.mkdirSync(path.dirname(filePath), { recursive: true })
@@ -374,3 +381,551 @@ describe('calculateGenerateWatchStructureChecksum', () => {
374
381
  expect(checksumModule(modulesFile, appModule, distModule)).not.toBe(before)
375
382
  })
376
383
  })
384
+
385
+ describe('structured generator inputs', () => {
386
+ let root: string
387
+ let pkg: string
388
+ let app: string
389
+ let options: GenerateWatchStructureOptions
390
+
391
+ beforeEach(() => {
392
+ root = fs.mkdtempSync(path.join(os.tmpdir(), 'om-watch-snapshot-'))
393
+ pkg = path.join(root, 'packages/core/src/modules/customers')
394
+ app = path.join(root, 'app/src/modules/customers')
395
+ fs.mkdirSync(pkg, { recursive: true })
396
+ fs.mkdirSync(app, { recursive: true })
397
+ options = { modulesFile: path.join(root, 'app/src/modules.ts'), moduleRoots: [{ appBase: app, pkgBase: pkg }] }
398
+ write(options.modulesFile, 'export const enabledModules = []')
399
+ })
400
+
401
+ afterEach(() => {
402
+ jest.restoreAllMocks()
403
+ fs.rmSync(root, { recursive: true, force: true })
404
+ })
405
+
406
+ function capture(): GenerateWatchSnapshot {
407
+ return collectGenerateWatchStructureSnapshot(options)
408
+ }
409
+
410
+ function changesSince(previous: GenerateWatchSnapshot) {
411
+ const next = capture()
412
+ return { next, changes: diffGenerateWatchStructureSnapshots(previous, next) }
413
+ }
414
+
415
+ it('runs full generation when a CrudForm section definition is added, edited, or removed', () => {
416
+ const definition = path.join(app, 'form-sections.ts')
417
+ const baseline = capture()
418
+ write(definition, 'export const crudFormSections = {}')
419
+ const added = changesSince(baseline)
420
+ expect(added.changes).toContainEqual(expect.objectContaining({
421
+ kind: 'add', category: 'configuration', path: definition,
422
+ }))
423
+ expect(planGenerateWatchChanges(added.changes).mode).toBe('full')
424
+
425
+ write(definition, 'export const crudFormSections = { descriptors: [] }')
426
+ const edited = changesSince(added.next)
427
+ expect(planGenerateWatchChanges(edited.changes).mode).toBe('full')
428
+
429
+ fs.rmSync(definition)
430
+ const removed = changesSince(edited.next)
431
+ expect(planGenerateWatchChanges(removed.changes).mode).toBe('full')
432
+ })
433
+
434
+ it('reuses cached content until stat identity changes or the file is deleted', () => {
435
+ const route = path.join(pkg, 'api/items/route.ts')
436
+ const helper = path.join(pkg, 'api/items/helper.ts')
437
+ write(route, 'import { value } from "./helper"; export const GET = () => value')
438
+ write(helper, 'export const value = 1')
439
+ const cache = createGenerateWatchStructureCache()
440
+ const readSpy = jest.spyOn(fs, 'readFileSync')
441
+
442
+ collectGenerateWatchStructureSnapshot(options, cache)
443
+ const readsAfterFirstCapture = readSpy.mock.calls.length
444
+ collectGenerateWatchStructureSnapshot(options, cache)
445
+ expect(readSpy).toHaveBeenCalledTimes(readsAfterFirstCapture)
446
+
447
+ write(helper, 'export const value = 200')
448
+ collectGenerateWatchStructureSnapshot(options, cache)
449
+ expect(readSpy.mock.calls.length).toBeGreaterThan(readsAfterFirstCapture)
450
+ const readsAfterChange = readSpy.mock.calls.length
451
+
452
+ fs.rmSync(helper)
453
+ collectGenerateWatchStructureSnapshot(options, cache)
454
+ write(helper, 'export const value = 300')
455
+ collectGenerateWatchStructureSnapshot(options, cache)
456
+ expect(readSpy.mock.calls.length).toBeGreaterThan(readsAfterChange)
457
+ })
458
+
459
+ it('preserves unreachable cache entries only for uncertain captures and prunes them after authoritative removal', () => {
460
+ const route = path.join(pkg, 'api/items/route.ts')
461
+ const helper = path.join(pkg, 'api/items/helper.ts')
462
+ write(route, 'import { value } from "./helper"; export const GET = () => value')
463
+ write(helper, 'export const value = 1')
464
+ const cache = createGenerateWatchStructureCache()
465
+ const readSpy = jest.spyOn(fs, 'readFileSync')
466
+ const moduleRoots = options.moduleRoots
467
+
468
+ collectGenerateWatchStructureSnapshot(options, cache)
469
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(1)
470
+
471
+ options.moduleRoots = []
472
+ options.webResearchAdapterFullReasons = ['Cannot scan adapter packages']
473
+ collectGenerateWatchStructureSnapshot(options, cache)
474
+ options.moduleRoots = moduleRoots
475
+ delete options.webResearchAdapterFullReasons
476
+ collectGenerateWatchStructureSnapshot(options, cache)
477
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(1)
478
+
479
+ options.moduleRoots = []
480
+ collectGenerateWatchStructureSnapshot(options, cache)
481
+ options.moduleRoots = moduleRoots
482
+ collectGenerateWatchStructureSnapshot(options, cache)
483
+ expect(readSpy.mock.calls.filter(([file]) => file === helper)).toHaveLength(2)
484
+ })
485
+
486
+ it('includes deterministic adapter scan uncertainty in snapshot full fallback reasons', () => {
487
+ options.webResearchAdapterFullReasons = [
488
+ 'Cannot scan web-research adapter packages: /z',
489
+ 'Cannot scan web-research adapter packages: /a',
490
+ 'Cannot scan web-research adapter packages: /z',
491
+ ]
492
+
493
+ const snapshot = capture()
494
+
495
+ expect(snapshot.fullReasons).toEqual([
496
+ 'Cannot scan web-research adapter packages: /a',
497
+ 'Cannot scan web-research adapter packages: /z',
498
+ ])
499
+ expect(planGenerateWatchChanges([], snapshot.fullReasons).mode).toBe('full')
500
+ })
501
+
502
+ it('preserves module identity when an identical route moves between existing roots', () => {
503
+ const second = path.join(root, 'packages/core/src/modules/sales')
504
+ fs.mkdirSync(second, { recursive: true })
505
+ options.moduleRoots.push({ appBase: path.join(root, 'app/src/modules/sales'), pkgBase: second })
506
+ const route = 'api/items/route.ts'
507
+ write(path.join(pkg, route), 'export const GET = () => null')
508
+ const before = capture()
509
+ fs.renameSync(path.join(pkg, route), path.join(second, 'route.tmp'))
510
+ write(path.join(second, route), 'export const GET = () => null')
511
+ fs.rmSync(path.join(second, 'route.tmp'))
512
+ const { changes } = changesSince(before)
513
+ expect(changes).toEqual(expect.arrayContaining([
514
+ expect.objectContaining({ kind: 'delete', category: 'api-route', path: path.join(pkg, route) }),
515
+ expect.objectContaining({ kind: 'add', category: 'api-route', path: path.join(second, route) }),
516
+ ]))
517
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['main', 'runtime', 'api-routes'])
518
+ })
519
+
520
+ it('detects identical cli conventions moving between modules', () => {
521
+ const second = path.join(root, 'packages/core/src/modules/sales')
522
+ fs.mkdirSync(second, { recursive: true })
523
+ options.moduleRoots.push({ appBase: path.join(root, 'app/src/modules/sales'), pkgBase: second })
524
+ write(path.join(pkg, 'cli.ts'), 'export default []')
525
+ const before = capture()
526
+ fs.renameSync(path.join(pkg, 'cli.ts'), path.join(second, 'cli.ts'))
527
+ const { changes } = changesSince(before)
528
+ expect(changes).toEqual(expect.arrayContaining([
529
+ expect.objectContaining({ kind: 'delete', category: 'cli', path: path.join(pkg, 'cli.ts') }),
530
+ expect.objectContaining({ kind: 'add', category: 'cli', path: path.join(second, 'cli.ts') }),
531
+ ]))
532
+ })
533
+
534
+ it('keeps source additions, compiled arrival, edits and deletions as separate transitions', () => {
535
+ const source = path.join(root, 'node_modules/@example/pkg/src/modules/customers')
536
+ const dist = path.join(root, 'node_modules/@example/pkg/dist/modules/customers')
537
+ fs.mkdirSync(source, { recursive: true })
538
+ fs.mkdirSync(dist, { recursive: true })
539
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
540
+ const sourceRoute = path.join(source, 'api/items/route.ts')
541
+ const runtimeRoute = path.join(dist, 'api/items/route.js')
542
+ let before = capture()
543
+ write(sourceRoute, 'export const GET = () => null')
544
+ let result = changesSince(before)
545
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'add', path: sourceRoute, category: 'api-route' }))
546
+ before = result.next
547
+ write(runtimeRoute, 'export const GET = () => null')
548
+ result = changesSince(before)
549
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'add', path: runtimeRoute, category: 'api-route' }))
550
+ before = result.next
551
+ write(runtimeRoute, 'export const POST = () => null')
552
+ result = changesSince(before)
553
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'change', path: runtimeRoute, category: 'api-route' }))
554
+ before = result.next
555
+ fs.rmSync(runtimeRoute)
556
+ result = changesSince(before)
557
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'delete', path: runtimeRoute, category: 'api-route' }))
558
+ write(runtimeRoute, 'export const POST = () => null')
559
+ before = capture()
560
+ fs.rmSync(sourceRoute)
561
+ result = changesSince(before)
562
+ expect(result.changes).toContainEqual(expect.objectContaining({ kind: 'delete', path: sourceRoute, category: 'api-route' }))
563
+ expect([...result.next.records.values()].filter((record) => record.category === 'api-route')).toEqual([])
564
+ })
565
+
566
+ it.each(['cli', 'di', 'search', 'events'] as const)(
567
+ 'retains cached standalone %s runtime inputs after source-mirror convention deletion',
568
+ (category) => {
569
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
570
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
571
+ fs.mkdirSync(source, { recursive: true })
572
+ fs.mkdirSync(dist, { recursive: true })
573
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
574
+ const sourceFile = path.join(source, `${category}.ts`)
575
+ const runtimeFile = path.join(dist, `${category}.js`)
576
+ const cache = createGenerateWatchStructureCache()
577
+ const snapshot = () => collectGenerateWatchStructureSnapshot(options, cache)
578
+ const empty = snapshot()
579
+
580
+ write(sourceFile, 'export const metadata = { value: 1 }')
581
+ const sourceOnly = snapshot()
582
+ expect(diffGenerateWatchStructureSnapshots(empty, sourceOnly)).toContainEqual(
583
+ expect.objectContaining({ category, path: sourceFile, kind: 'add' }),
584
+ )
585
+ write(runtimeFile, 'export const metadata = { value: 1 }')
586
+ const paired = snapshot()
587
+ expect(diffGenerateWatchStructureSnapshots(sourceOnly, paired)).toContainEqual(
588
+ expect.objectContaining({ category, path: runtimeFile, kind: 'add' }),
589
+ )
590
+
591
+ fs.rmSync(sourceFile)
592
+ const runtimeOnly = snapshot()
593
+ const removedSource = diffGenerateWatchStructureSnapshots(paired, runtimeOnly)
594
+ expect(removedSource).toContainEqual(expect.objectContaining({ category, path: sourceFile, kind: 'delete' }))
595
+ expect(removedSource).not.toContainEqual(expect.objectContaining({ path: runtimeFile, kind: 'delete' }))
596
+ expect([...runtimeOnly.records.values()]).toContainEqual(expect.objectContaining({
597
+ category, path: runtimeFile, key: expect.stringContaining(':runtime'),
598
+ }))
599
+ expect(runtimeOnly.fullReasons).toEqual([])
600
+ const readSpy = jest.spyOn(fs, 'readFileSync')
601
+ expect(snapshot().checksum).toBe(runtimeOnly.checksum)
602
+ expect(readSpy).not.toHaveBeenCalled()
603
+ readSpy.mockRestore()
604
+
605
+ write(runtimeFile, 'export const metadata = { value: 2 }')
606
+ const editedRuntime = snapshot()
607
+ const changes = diffGenerateWatchStructureSnapshots(runtimeOnly, editedRuntime)
608
+ expect(changes).toContainEqual(expect.objectContaining({ category, path: runtimeFile, kind: 'change' }))
609
+ expect(changes.every((change) => change.category === category)).toBe(true)
610
+ expect(planGenerateWatchChanges(changes).mode).toBe('incremental')
611
+
612
+ fs.rmSync(runtimeFile)
613
+ const removedRuntime = snapshot()
614
+ expect(diffGenerateWatchStructureSnapshots(editedRuntime, removedRuntime)).toContainEqual(
615
+ expect.objectContaining({ category, path: runtimeFile, kind: 'delete' }),
616
+ )
617
+ expect(removedRuntime.checksum).toBe(empty.checksum)
618
+ },
619
+ )
620
+
621
+ it('shadows stale compiled conventions with app overrides and inherits runtime helper categories', () => {
622
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
623
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
624
+ fs.mkdirSync(source, { recursive: true })
625
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
626
+ const runtimeFile = path.join(dist, 'cli.js')
627
+ const helper = path.join(dist, 'lib/cli-options.js')
628
+ const appFile = path.join(app, 'cli.ts')
629
+ write(runtimeFile, 'import { value } from "./lib/cli-options"; export default value')
630
+ write(helper, 'export const value = 1')
631
+ write(appFile, 'export default []')
632
+ const overridden = capture()
633
+
634
+ write(runtimeFile, 'import { value } from "./lib/cli-options"; export default [value]')
635
+ write(helper, 'export const value = 2')
636
+ expect(capture().checksum).toBe(overridden.checksum)
637
+
638
+ fs.rmSync(appFile)
639
+ const revealed = capture()
640
+ expect(diffGenerateWatchStructureSnapshots(overridden, revealed)).toContainEqual(
641
+ expect.objectContaining({ category: 'cli', path: runtimeFile, kind: 'add' }),
642
+ )
643
+ write(helper, 'export const value = 3')
644
+ const { changes } = changesSince(revealed)
645
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'cli', path: helper, kind: 'change' }))
646
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['main', 'cli'])
647
+ })
648
+
649
+ it('handles dist-only modules and source-mirror authority appearing later', () => {
650
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
651
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
652
+ write(path.join(dist, 'workers/job.js'), 'export default async function job() {}')
653
+ const before = capture()
654
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
655
+ fs.mkdirSync(source, { recursive: true })
656
+ const { changes } = changesSince(before)
657
+ expect(changes).toContainEqual(expect.objectContaining({ kind: 'delete', category: 'workers' }))
658
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
659
+ })
660
+
661
+ it('honors app overrides across extensions and reveals package inputs on deletion', () => {
662
+ write(path.join(pkg, 'workers/job.js'), 'export default async function job() {}')
663
+ const before = capture()
664
+ write(path.join(app, 'workers/job.ts'), 'export default async function job() {}')
665
+ const overridden = capture()
666
+ expect(diffGenerateWatchStructureSnapshots(before, overridden)).toContainEqual(
667
+ expect.objectContaining({ category: 'workers', path: path.join(app, 'workers/job.ts') }),
668
+ )
669
+ write(path.join(pkg, 'workers/job.js'), 'export default async function hiddenJob() {}')
670
+ expect(capture().checksum).toBe(overridden.checksum)
671
+ fs.rmSync(path.join(app, 'workers/job.ts'))
672
+ const { changes } = changesSince(overridden)
673
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'workers', path: path.join(pkg, 'workers/job.js') }))
674
+ })
675
+
676
+ it('tracks command ids and deletion while excluding command helpers and tests', () => {
677
+ const before = capture()
678
+ for (const file of ['index.ts', 'shared.ts', 'factory.ts', 'save.test.ts', 'save.d.ts']) {
679
+ write(path.join(pkg, 'commands', file), 'export const ignored = true')
680
+ }
681
+ expect(capture().checksum).toBe(before.checksum)
682
+ const command = path.join(pkg, 'commands/nested/save.ts')
683
+ write(command, 'export const command = { id: \"customers.save\" }')
684
+ const added = capture()
685
+ write(command, 'export const command = { id: \"customers.update\" }')
686
+ expect(changesSince(added).changes).toContainEqual(expect.objectContaining({ category: 'commands', kind: 'change', path: command }))
687
+ fs.rmSync(command)
688
+ expect(changesSince(added).changes).toContainEqual(expect.objectContaining({ category: 'commands', kind: 'delete', path: command }))
689
+ })
690
+
691
+ it('tracks legacy method APIs and preserves the command-interceptor overlap', () => {
692
+ const before = capture()
693
+ write(path.join(pkg, 'api/get/items.ts'), 'export default function handler() {}')
694
+ write(path.join(pkg, 'commands/interceptors.ts'), 'export const interceptors = []')
695
+ const { changes } = changesSince(before)
696
+ const plan = planGenerateWatchChanges(changes)
697
+ expect(plan.mode).toBe('incremental')
698
+ expect(plan.groups).toEqual(['registry', 'openapi'])
699
+ expect(plan.registryOutputs).toEqual(['main', 'runtime', 'api-routes', 'commands', 'registry.command-interceptors'])
700
+ })
701
+
702
+ it('uses locale membership and merge-side identity without hashing translation values', () => {
703
+ const locale = path.join(pkg, 'i18n/en.json')
704
+ write(locale, '{\"hello\":\"Hello\"}')
705
+ const before = capture()
706
+ write(locale, '{\"hello\":\"Hi\"}')
707
+ expect(capture().checksum).toBe(before.checksum)
708
+ write(path.join(app, 'i18n/en.json'), '{\"hello\":\"Custom\"}')
709
+ expect(changesSince(before).changes).toContainEqual(expect.objectContaining({ category: 'i18n', kind: 'add', path: path.join(app, 'i18n/en.json') }))
710
+ const merged = capture()
711
+ fs.rmSync(locale)
712
+ expect(changesSince(merged).changes).toContainEqual(expect.objectContaining({ category: 'i18n', kind: 'delete', path: locale }))
713
+ })
714
+
715
+ it('reads built-in-style static plugin descriptors and watches arbitrary nested contributions', () => {
716
+ write(path.join(pkg, 'generators.ts'), `
717
+ import type { GeneratorPlugin } from '@open-mercato/shared/modules/generators'
718
+ const file = 'custom/nested.items.ts'
719
+ const plugin: GeneratorPlugin = { id: 'test.items', conventionFile: file, buildOutput: () => '' }
720
+ export const generatorPlugins = [plugin]
721
+ export default generatorPlugins
722
+ `)
723
+ const before = capture()
724
+ expect(before.fullReasons).toEqual([])
725
+ write(path.join(pkg, 'custom/nested.items.ts'), 'export default [\"entry\"]')
726
+ const { changes } = changesSince(before)
727
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'generator-plugin', kind: 'add' }))
728
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
729
+ const contributed = capture()
730
+ fs.rmSync(path.join(pkg, 'generators.ts'))
731
+ expect(planGenerateWatchChanges(changesSince(contributed).changes).mode).toBe('full')
732
+ })
733
+
734
+ it('falls back explicitly for dynamic plugin descriptors instead of missing contributions', () => {
735
+ write(path.join(pkg, 'generators.ts'), 'export const generatorPlugins = makePlugins()')
736
+ const snapshot = capture()
737
+ expect(snapshot.fullReasons).toEqual([])
738
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(snapshot, capture())).mode).toBe('none')
739
+ const contribution = path.join(pkg, 'custom/unknown.items.ts')
740
+ write(contribution, 'export const items = [\"new\"]')
741
+ const { changes } = changesSince(snapshot)
742
+ const plan = planGenerateWatchChanges(changes)
743
+ expect(plan.mode).toBe('full')
744
+ expect(plan.reasons).toContain(`Generator plugin dependency changed: ${contribution}`)
745
+ })
746
+
747
+ it('inherits backend-page planning through transitive metadata helpers', () => {
748
+ write(path.join(pkg, 'backend/page.tsx'), 'export default function Page() { return null }')
749
+ write(path.join(pkg, 'backend/page.meta.ts'), 'import { label } from "../lib/label"; export const metadata = { label }')
750
+ write(path.join(pkg, 'lib/label.ts'), 'export { label } from "./nested"')
751
+ write(path.join(pkg, 'lib/nested.ts'), 'export const label = "First"')
752
+ const before = capture()
753
+ write(path.join(pkg, 'components/Unrelated.tsx'), 'export default () => null')
754
+ expect(capture().checksum).toBe(before.checksum)
755
+ const nested = path.join(pkg, 'lib/nested.ts')
756
+ write(nested, 'export const label = "Second"')
757
+ const { changes } = changesSince(before)
758
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'backend-page', path: nested }))
759
+ const plan = planGenerateWatchChanges(changes)
760
+ expect(plan.mode).toBe('incremental')
761
+ expect(plan.registryOutputs).toEqual(['main', 'runtime', 'app', 'backend-routes'])
762
+ })
763
+
764
+ it('tracks page default-export shape without treating ordinary page rendering edits as structural', () => {
765
+ const page = path.join(pkg, 'backend/page.tsx')
766
+ write(page, 'export default function Page() { return null }')
767
+ const before = capture()
768
+ write(page, 'export default function Page() { return \"Updated render\" }')
769
+ expect(capture().checksum).toBe(before.checksum)
770
+ write(page, 'export function Page() { return null }')
771
+ expect(changesSince(before).changes).toContainEqual(expect.objectContaining({ category: 'backend-page', kind: 'change' }))
772
+ })
773
+
774
+ it('tracks entity override and legacy schema selection candidates', () => {
775
+ const before = capture()
776
+ write(path.join(pkg, 'db/schema.ts'), 'export class Customer {}')
777
+ write(path.join(app, 'data/entities.override.ts'), 'export class CustomCustomer {}')
778
+ const { changes } = changesSince(before)
779
+ expect(changes.every((change) => change.category === 'entities')).toBe(true)
780
+ expect(planGenerateWatchChanges(changes).groups).toEqual(['entity-ids', 'entities'])
781
+ })
782
+
783
+ it('tracks standalone package-generated entity metadata as an entity input', () => {
784
+ const packageRoot = path.join(root, 'node_modules/pkg')
785
+ const dist = path.join(packageRoot, 'dist/modules/customers')
786
+ fs.mkdirSync(dist, { recursive: true })
787
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
788
+ const before = capture()
789
+ const ids = path.join(packageRoot, 'dist/generated/entities.ids.generated.js')
790
+ write(ids, 'export const E = { customers: { person: \"customers:person\" } }')
791
+ const { changes } = changesSince(before)
792
+ expect(changes).toContainEqual(expect.objectContaining({ category: 'entities', path: ids }))
793
+ expect(planGenerateWatchChanges(changes).groups).toEqual(['entity-ids', 'entities'])
794
+ const usingDist = capture()
795
+ const direct = path.join(packageRoot, 'generated')
796
+ expect([...usingDist.records.values()]).toContainEqual(expect.objectContaining({
797
+ category: 'entities', path: direct, fingerprint: 'missing',
798
+ }))
799
+ fs.mkdirSync(direct)
800
+ const switched = changesSince(usingDist)
801
+ expect(switched.changes).toContainEqual(expect.objectContaining({ category: 'entities', path: direct, kind: 'change' }))
802
+ expect(switched.changes).toContainEqual(expect.objectContaining({ category: 'entities', path: ids, kind: 'delete' }))
803
+ })
804
+
805
+ it('does not broaden API plans when OpenAPI also reports the same route input', () => {
806
+ const route = path.join(pkg, 'api/items/route.ts')
807
+ write(route, 'export const GET = () => null')
808
+ options.openapiInputs = [route]
809
+ const before = capture()
810
+ write(route, 'export const POST = () => null')
811
+ expect(planGenerateWatchChanges(changesSince(before).changes).groups).toEqual(['registry', 'openapi'])
812
+ })
813
+
814
+ it('unions inherited categories and extension identity when seeds share a helper', () => {
815
+ const search = path.join(pkg, 'search.ts')
816
+ const notifications = path.join(pkg, 'notifications.ts')
817
+ const helper = path.join(pkg, 'lib/search-options.ts')
818
+ write(search, 'import { enabled } from "./lib/search-options"; export const searchConfig = { enabled }')
819
+ write(notifications, 'import { enabled } from "./lib/search-options"; export const handlers = enabled ? [] : []')
820
+ write(helper, 'export const enabled = false')
821
+ options.openapiInputs = [search]
822
+ const before = capture()
823
+ write(helper, 'export const enabled = true')
824
+ const changes = changesSince(before).changes
825
+ expect(changes.filter((change) => change.path === helper).map((change) => change.category).sort())
826
+ .toEqual(['extension', 'openapi', 'search'])
827
+ expect(changes).toContainEqual(expect.objectContaining({
828
+ category: 'extension', extensionId: 'registry.notifications', path: helper,
829
+ }))
830
+ const plan = planGenerateWatchChanges(changes)
831
+ expect(plan.mode).toBe('incremental')
832
+ expect(plan.groups).toEqual(['registry', 'openapi'])
833
+ expect(plan.registryOutputs).toEqual(['registry.search', 'registry.notifications'])
834
+ })
835
+
836
+ it('plans cache-provider generation only when the manifest appears or disappears', () => {
837
+ const manifest = path.join(root, 'app/src/providers/cache.ts')
838
+ options.cacheProviderInputs = [manifest]
839
+ const before = capture()
840
+ write(manifest, 'export const cacheProviders = []')
841
+ const added = capture()
842
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(before, added)).groups).toEqual(['cache-providers'])
843
+
844
+ write(manifest, 'export const cacheProviders = [fixture]')
845
+ expect(changesSince(added).changes).toEqual([])
846
+
847
+ fs.unlinkSync(manifest)
848
+ expect(planGenerateWatchChanges(changesSince(added).changes).groups).toEqual(['cache-providers'])
849
+ })
850
+
851
+ it('plans OpenAPI helpers and adapter manifests without a full fallback', () => {
852
+ const openapiInput = path.join(root, 'app/src/openapi.ts')
853
+ const openapiHelper = path.join(root, 'app/src/openapi-helper.ts')
854
+ const adapterManifest = path.join(root, 'packages/adapter/package.json')
855
+ write(openapiInput, 'export { schema } from "./openapi-helper"')
856
+ write(openapiHelper, 'export const schema = { version: 1 }')
857
+ write(adapterManifest, '{"name":"adapter","openMercato":{"webResearchAdapter":{"id":"first"}}}')
858
+ options.openapiInputs = [openapiInput]
859
+ options.webResearchAdapterInputs = [adapterManifest]
860
+ const manifestReadSpy = jest.spyOn(fs, 'readFileSync')
861
+ const before = capture()
862
+ expect(manifestReadSpy.mock.calls.some(([file]) => file === adapterManifest)).toBe(false)
863
+ manifestReadSpy.mockRestore()
864
+ write(openapiHelper, 'export const schema = { version: 2 }')
865
+ write(adapterManifest, '{"name":"adapter","openMercato":{"webResearchAdapter":{"id":"second"}}}')
866
+ const changes = changesSince(before).changes
867
+ expect(changes).toEqual(expect.arrayContaining([
868
+ expect.objectContaining({ category: 'openapi', path: openapiHelper }),
869
+ expect.objectContaining({ category: 'web-research-adapters', path: adapterManifest }),
870
+ ]))
871
+ const plan = planGenerateWatchChanges(changes)
872
+ expect(plan.mode).toBe('incremental')
873
+ expect(plan.groups).toEqual(['web-research-adapters', 'openapi'])
874
+ })
875
+
876
+ it('detects supervisor override calls outside module conventions without tracking unrelated component edits', () => {
877
+ const file = path.join(root, 'app/src/components/Setup.tsx')
878
+ write(file, 'export const setup = () => null')
879
+ const before = capture()
880
+ write(file, 'import { applyWorkerOverrides as apply } from \"@open-mercato/shared/modules/overrides\"; apply({})')
881
+ const { changes } = changesSince(before)
882
+ expect(planGenerateWatchChanges(changes).registryOutputs).toEqual(['supervisor'])
883
+ })
884
+
885
+ it('normalizes root property ordering while retaining module order as configuration', () => {
886
+ const before = capture()
887
+ options.moduleRoots = [{ pkgBase: pkg, appBase: app }]
888
+ expect(capture().checksum).toBe(before.checksum)
889
+ const second = { appBase: path.join(root, 'app/src/modules/sales'), pkgBase: path.join(root, 'packages/core/src/modules/sales') }
890
+ options.moduleRoots.push(second)
891
+ const ordered = capture()
892
+ options.moduleRoots.reverse()
893
+ const { changes } = changesSince(ordered)
894
+ expect(planGenerateWatchChanges(changes).mode).toBe('full')
895
+ expect(changes).toEqual(expect.arrayContaining([expect.objectContaining({ category: 'configuration' })]))
896
+ })
897
+
898
+ it('observes compiled page metadata updates independently of source edits', () => {
899
+ const source = path.join(root, 'node_modules/pkg/src/modules/customers')
900
+ const dist = path.join(root, 'node_modules/pkg/dist/modules/customers')
901
+ options.moduleRoots = [{ appBase: app, pkgBase: dist }]
902
+ write(path.join(source, 'backend/page.tsx'), 'export default function Page() { return null }')
903
+ write(path.join(source, 'backend/page.meta.ts'), 'export const metadata = { label: "First" }')
904
+ write(path.join(dist, 'backend/page.js'), 'export default function Page() { return null }')
905
+ const compiledMeta = path.join(dist, 'backend/page.meta.js')
906
+ write(compiledMeta, 'export const metadata = { label: "First" }')
907
+ let before = capture()
908
+ write(path.join(source, 'backend/page.meta.ts'), 'export const metadata = { label: "Second" }')
909
+ let result = changesSince(before)
910
+ expect(planGenerateWatchChanges(result.changes).registryOutputs).toEqual(['main', 'runtime', 'app', 'backend-routes'])
911
+ before = result.next
912
+ write(compiledMeta, 'export const metadata = { label: "Second" }')
913
+ result = changesSince(before)
914
+ expect(result.changes).toContainEqual(expect.objectContaining({ category: 'backend-page', path: compiledMeta, kind: 'change' }))
915
+ })
916
+
917
+ it('does not interpret read and scan failures as authoritative deletion', () => {
918
+ write(path.join(pkg, 'workers/job.ts'), 'export default () => null')
919
+ const before = capture()
920
+ const readSpy = jest.spyOn(fs, 'readFileSync').mockImplementation(() => { throw new Error('denied') })
921
+ const unreadable = capture()
922
+ readSpy.mockRestore()
923
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(before, unreadable), unreadable.fullReasons).mode).toBe('full')
924
+ expect(unreadable.fullReasons).toEqual(expect.arrayContaining([expect.stringContaining('Cannot read generator input:')]))
925
+ const scanSpy = jest.spyOn(fs, 'readdirSync').mockImplementation(() => { throw new Error('denied') })
926
+ const unscannable = capture()
927
+ scanSpy.mockRestore()
928
+ expect(planGenerateWatchChanges(diffGenerateWatchStructureSnapshots(before, unscannable), unscannable.fullReasons).mode).toBe('full')
929
+ expect(unscannable.fullReasons).toEqual(expect.arrayContaining([expect.stringContaining('Cannot scan generator inputs:')]))
930
+ })
931
+ })