@open-mercato/cli 0.9.1-develop.7575.1.8480826a9b → 0.10.1-develop.7577.1.477f2486e5

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 (177) hide show
  1. package/.turbo/turbo-build.log +5 -1
  2. package/dist/agentic/guides/architecture.md +2 -0
  3. package/dist/agentic/guides/customers-calendar.md +57 -0
  4. package/dist/agentic/guides/extensions.md +2 -0
  5. package/dist/agentic/guides/module-facts.json +4287 -699
  6. package/dist/agentic/guides/module-facts.v2.json +4287 -699
  7. package/dist/agentic/guides/module-tool.md +35 -0
  8. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  9. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  10. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  11. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  12. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  13. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  14. package/dist/agentic/guides/modules/auth/index.md +1 -1
  15. package/dist/agentic/guides/modules/availability/index.md +1 -1
  16. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  17. package/dist/agentic/guides/modules/catalog/acl-features.md +3 -1
  18. package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +3 -3
  19. package/dist/agentic/guides/modules/catalog/cli-commands.md +1 -0
  20. package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +2 -0
  21. package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +5 -4
  22. package/dist/agentic/guides/modules/catalog/di-service-tokens.md +2 -1
  23. package/dist/agentic/guides/modules/catalog/entities.md +1 -0
  24. package/dist/agentic/guides/modules/catalog/exact-override-targets.md +10 -4
  25. package/dist/agentic/guides/modules/catalog/index.md +5 -5
  26. package/dist/agentic/guides/modules/catalog/umes-contributions.md +2 -0
  27. package/dist/agentic/guides/modules/catalog/umes-hosts.md +1 -0
  28. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  29. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  30. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  31. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  32. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  33. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  34. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  35. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  36. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  37. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  38. package/dist/agentic/guides/modules/configs/index.md +1 -1
  39. package/dist/agentic/guides/modules/content/index.md +1 -1
  40. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  41. package/dist/agentic/guides/modules/customer_accounts/incoming-installed-contributions.md +13 -0
  42. package/dist/agentic/guides/modules/customer_accounts/index.md +3 -2
  43. package/dist/agentic/guides/modules/customer_groups/active-extension-bindings.md +1 -1
  44. package/dist/agentic/guides/modules/customer_groups/incoming-installed-contributions.md +11 -0
  45. package/dist/agentic/guides/modules/customer_groups/index.md +3 -2
  46. package/dist/agentic/guides/modules/customers/active-extension-bindings.md +5 -5
  47. package/dist/agentic/guides/modules/customers/di-registrations-rich.md +5 -3
  48. package/dist/agentic/guides/modules/customers/exact-override-targets.md +5 -3
  49. package/dist/agentic/guides/modules/customers/index.md +2 -2
  50. package/dist/agentic/guides/modules/customers/owned-contract-module-metadata.md +1 -1
  51. package/dist/agentic/guides/modules/customers/umes-hosts.md +2 -0
  52. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  53. package/dist/agentic/guides/modules/data_sync/di-registrations-rich.md +8 -8
  54. package/dist/agentic/guides/modules/data_sync/di-service-tokens.md +4 -4
  55. package/dist/agentic/guides/modules/data_sync/exact-override-targets.md +8 -8
  56. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  57. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  58. package/dist/agentic/guides/modules/devices/index.md +1 -1
  59. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  60. package/dist/agentic/guides/modules/directory/index.md +1 -1
  61. package/dist/agentic/guides/modules/documents/index.md +1 -1
  62. package/dist/agentic/guides/modules/ecommerce/acl-features.md +15 -0
  63. package/dist/agentic/guides/modules/ecommerce/active-extension-bindings.md +12 -0
  64. package/dist/agentic/guides/modules/ecommerce/backend-pages.md +12 -0
  65. package/dist/agentic/guides/modules/ecommerce/contribution-resolutions.md +32 -0
  66. package/dist/agentic/guides/modules/ecommerce/di-registrations-rich.md +11 -0
  67. package/dist/agentic/guides/modules/ecommerce/di-service-tokens.md +11 -0
  68. package/dist/agentic/guides/modules/ecommerce/entities.md +13 -0
  69. package/dist/agentic/guides/modules/ecommerce/events.md +22 -0
  70. package/dist/agentic/guides/modules/ecommerce/exact-override-targets.md +41 -0
  71. package/dist/agentic/guides/modules/ecommerce/index.md +26 -0
  72. package/dist/agentic/guides/modules/ecommerce/notifications.md +12 -0
  73. package/dist/agentic/guides/modules/ecommerce/owned-contract-module-metadata.md +11 -0
  74. package/dist/agentic/guides/modules/ecommerce/search-entities.md +11 -0
  75. package/dist/agentic/guides/modules/ecommerce/setup.md +11 -0
  76. package/dist/agentic/guides/modules/ecommerce/umes-contributions.md +32 -0
  77. package/dist/agentic/guides/modules/ecommerce/umes-hosts.md +27 -0
  78. package/dist/agentic/guides/modules/entities/index.md +1 -1
  79. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  80. package/dist/agentic/guides/modules/events/index.md +1 -1
  81. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  82. package/dist/agentic/guides/modules/forms/index.md +1 -1
  83. package/dist/agentic/guides/modules/gateway_stripe/di-registrations-rich.md +1 -1
  84. package/dist/agentic/guides/modules/gateway_stripe/exact-override-targets.md +1 -1
  85. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  86. package/dist/agentic/guides/modules/gateway_tpay/acl-features.md +12 -0
  87. package/dist/agentic/guides/modules/gateway_tpay/cli-commands.md +12 -0
  88. package/dist/agentic/guides/modules/gateway_tpay/contribution-resolutions.md +12 -0
  89. package/dist/agentic/guides/modules/gateway_tpay/di-registrations-rich.md +11 -0
  90. package/dist/agentic/guides/modules/gateway_tpay/exact-override-targets.md +17 -0
  91. package/dist/agentic/guides/modules/gateway_tpay/index.md +19 -0
  92. package/dist/agentic/guides/modules/gateway_tpay/owned-contract-module-metadata.md +11 -0
  93. package/dist/agentic/guides/modules/gateway_tpay/setup.md +11 -0
  94. package/dist/agentic/guides/modules/gateway_tpay/umes-contributions.md +12 -0
  95. package/dist/agentic/guides/modules/generators/index.md +1 -1
  96. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  97. package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +9 -8
  98. package/dist/agentic/guides/modules/integrations/di-service-tokens.md +5 -4
  99. package/dist/agentic/guides/modules/integrations/exact-override-targets.md +9 -8
  100. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  101. package/dist/agentic/guides/modules/messages/index.md +1 -1
  102. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  103. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  104. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  105. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  106. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  107. package/dist/agentic/guides/modules/planner/index.md +1 -1
  108. package/dist/agentic/guides/modules/portal/index.md +1 -1
  109. package/dist/agentic/guides/modules/portal/owned-contract-module-metadata.md +1 -1
  110. package/dist/agentic/guides/modules/progress/index.md +1 -1
  111. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  112. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  113. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  114. package/dist/agentic/guides/modules/resources/index.md +1 -1
  115. package/dist/agentic/guides/modules/sales/index.md +1 -1
  116. package/dist/agentic/guides/modules/scheduler/exact-override-targets.md +1 -1
  117. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  118. package/dist/agentic/guides/modules/scheduler/workers.md +1 -1
  119. package/dist/agentic/guides/modules/search/index.md +1 -1
  120. package/dist/agentic/guides/modules/security/index.md +1 -1
  121. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  122. package/dist/agentic/guides/modules/shipping_carriers/exact-override-targets.md +1 -1
  123. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  124. package/dist/agentic/guides/modules/shipping_carriers/workers.md +1 -1
  125. package/dist/agentic/guides/modules/sso/index.md +1 -1
  126. package/dist/agentic/guides/modules/staff/index.md +1 -1
  127. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  128. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  129. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  130. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  131. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  132. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  133. package/dist/agentic/guides/modules/translations/index.md +1 -1
  134. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  135. package/dist/agentic/guides/modules/webhooks/exact-override-targets.md +2 -2
  136. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  137. package/dist/agentic/guides/modules/webhooks/workers.md +2 -2
  138. package/dist/agentic/guides/modules/wms/events.md +2 -1
  139. package/dist/agentic/guides/modules/wms/index.md +1 -1
  140. package/dist/agentic/guides/modules/wms/umes-hosts.md +1 -0
  141. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  142. package/dist/agentic/guides/modules/workflows/owned-contract-module-metadata.md +1 -1
  143. package/dist/agentic/guides/reference-module-facts.json +443 -25
  144. package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +2 -0
  145. package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +9 -4
  146. package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -2
  147. package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
  148. package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +12 -6
  149. package/dist/agentic/guides/reference-modules/example/index.md +4 -4
  150. package/dist/agentic/guides/reference-modules/example/umes-contributions.md +10 -5
  151. package/dist/agentic/guides/reference-modules/example/umes-hosts.md +1 -0
  152. package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +46 -0
  153. package/dist/agentic/guides/upstream/manifest.json +2 -2
  154. package/dist/agentic/shared/AGENTS.md.template +1 -0
  155. package/dist/agentic/shared/ai/harness/README.md +6 -2
  156. package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
  157. package/dist/agentic/shared/ai/harness/cases.json +371 -39
  158. package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
  159. package/dist/agentic/shared/ai/harness/design-system-inventory.json +63 -3
  160. package/dist/agentic/shared/ai/harness/source-link-inventory.json +316 -8
  161. package/dist/agentic/shared/ai/harness/validators.json +1 -1
  162. package/dist/agentic/shared/ai/skills/om-integration-builder/references/provider-families.md +1 -1
  163. package/dist/agentic/shared/ai/skills/om-module-scaffold/SKILL.md +2 -0
  164. package/dist/agentic/shared/scripts/evaluate-agent-harness.mjs +78 -9
  165. package/dist/agentic/shared/scripts/execution-sandbox.mjs +8 -7
  166. package/dist/bin.js +2 -0
  167. package/dist/bin.js.map +2 -2
  168. package/dist/lib/testing/integration.js +2 -0
  169. package/dist/lib/testing/integration.js.map +2 -2
  170. package/dist/mercato.js +87 -17
  171. package/dist/mercato.js.map +2 -2
  172. package/package.json +8 -8
  173. package/src/__tests__/mercato.test.ts +480 -0
  174. package/src/bin.ts +5 -0
  175. package/src/lib/__tests__/bin-next-subpath-hook.test.ts +25 -0
  176. package/src/lib/testing/integration.ts +2 -0
  177. package/src/mercato.ts +104 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/cli",
3
- "version": "0.9.1-develop.7575.1.8480826a9b",
3
+ "version": "0.10.1-develop.7577.1.477f2486e5",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -60,10 +60,10 @@
60
60
  "@mikro-orm/decorators": "^7.1.14",
61
61
  "@mikro-orm/migrations": "^7.1.14",
62
62
  "@mikro-orm/postgresql": "^7.1.14",
63
- "@open-mercato/events": "0.9.1-develop.7575.1.8480826a9b",
64
- "@open-mercato/queue": "0.9.1-develop.7575.1.8480826a9b",
65
- "@open-mercato/shared": "0.9.1-develop.7575.1.8480826a9b",
66
- "@open-mercato/telemetry": "0.9.1-develop.7575.1.8480826a9b",
63
+ "@open-mercato/events": "0.10.1-develop.7577.1.477f2486e5",
64
+ "@open-mercato/queue": "0.10.1-develop.7577.1.477f2486e5",
65
+ "@open-mercato/shared": "0.10.1-develop.7577.1.477f2486e5",
66
+ "@open-mercato/telemetry": "0.10.1-develop.7577.1.477f2486e5",
67
67
  "cross-spawn": "^7.0.6",
68
68
  "pg": "8.23.0",
69
69
  "semver": "^7.8.5",
@@ -74,10 +74,10 @@
74
74
  "typescript-js": "npm:typescript@6.0.3"
75
75
  },
76
76
  "peerDependencies": {
77
- "@open-mercato/shared": "0.9.1-develop.7575.1.8480826a9b"
77
+ "@open-mercato/shared": "0.10.1-develop.7577.1.477f2486e5"
78
78
  },
79
79
  "devDependencies": {
80
- "@open-mercato/shared": "0.9.1-develop.7575.1.8480826a9b",
80
+ "@open-mercato/shared": "0.10.1-develop.7577.1.477f2486e5",
81
81
  "@types/jest": "^30.0.0",
82
82
  "jest": "^30.4.2",
83
83
  "ts-jest": "^29.4.12"
@@ -90,5 +90,5 @@
90
90
  "url": "https://github.com/open-mercato/open-mercato",
91
91
  "directory": "packages/cli"
92
92
  },
93
- "stableVersion": "0.9.0"
93
+ "stableVersion": "0.10.0"
94
94
  }
@@ -3,7 +3,9 @@ import {
3
3
  registerCliModules,
4
4
  getCliModules,
5
5
  hasCliModules,
6
+ isHelpRequest,
6
7
  padByCodePointWidth,
8
+ resolveEnvBootstrapOptions,
7
9
  run,
8
10
  } from '../mercato'
9
11
  import { pathIncludes } from '../lib/__tests__/path-helpers'
@@ -187,6 +189,264 @@ describe('padByCodePointWidth', () => {
187
189
  })
188
190
  })
189
191
 
192
+ describe('--help never triggers side effects (issue #5581)', () => {
193
+ beforeEach(() => {
194
+ jest.restoreAllMocks()
195
+ })
196
+
197
+ describe('isHelpRequest', () => {
198
+ it('matches the long and short help flags in any position', () => {
199
+ expect(isHelpRequest(['db', 'generate', '--help'])).toBe(true)
200
+ expect(isHelpRequest(['-h'])).toBe(true)
201
+ })
202
+
203
+ it('does not match arguments that merely contain the flag text', () => {
204
+ expect(isHelpRequest(['db', 'generate'])).toBe(false)
205
+ expect(isHelpRequest(['--help-me'])).toBe(false)
206
+ expect(isHelpRequest(['--no-help'])).toBe(false)
207
+ expect(isHelpRequest([])).toBe(false)
208
+ })
209
+ })
210
+
211
+ describe('resolveEnvBootstrapOptions', () => {
212
+ it('refuses to create .env from .env.example for a help invocation', () => {
213
+ expect(resolveEnvBootstrapOptions(['db', 'generate', '--help'])).toEqual({
214
+ createIfMissing: false,
215
+ quiet: true,
216
+ })
217
+ expect(resolveEnvBootstrapOptions(['-h'])).toEqual({ createIfMissing: false, quiet: true })
218
+ })
219
+
220
+ it('still creates .env for a real command invocation', () => {
221
+ expect(resolveEnvBootstrapOptions(['db', 'generate'])).toEqual({
222
+ createIfMissing: true,
223
+ quiet: false,
224
+ })
225
+ })
226
+
227
+ it('keeps the pre-existing deploy and telemetry opt-outs', () => {
228
+ expect(resolveEnvBootstrapOptions(['deploy', 'railway'])).toEqual({
229
+ createIfMissing: false,
230
+ quiet: true,
231
+ })
232
+ expect(resolveEnvBootstrapOptions(['telemetry', 'init'])).toEqual({
233
+ createIfMissing: false,
234
+ quiet: true,
235
+ })
236
+ })
237
+ })
238
+
239
+ describe('dispatcher help branch', () => {
240
+ it('prints usage instead of running db:generate when --help is passed', async () => {
241
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
242
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
243
+ const dbGenerate = jest.fn()
244
+
245
+ registerCliModules([
246
+ {
247
+ id: 'db',
248
+ cli: [{ command: 'generate', help: 'Writes migrations. Applies nothing.', run: dbGenerate }],
249
+ } as any,
250
+ ])
251
+
252
+ const exitCode = await run(['node', 'mercato', 'db', 'generate', '--help'])
253
+
254
+ expect(exitCode).toBe(0)
255
+ expect(dbGenerate).not.toHaveBeenCalled()
256
+ const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
257
+ expect(printed).toContain('mercato db generate [args]')
258
+ expect(printed).toContain('Writes migrations. Applies nothing.')
259
+
260
+ consoleLogSpy.mockRestore()
261
+ consoleErrorSpy.mockRestore()
262
+ })
263
+
264
+ it('prints usage instead of running db:migrate when -h is passed', async () => {
265
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
266
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
267
+ const dbMigrate = jest.fn()
268
+
269
+ registerCliModules([
270
+ { id: 'db', cli: [{ command: 'migrate', run: dbMigrate }] } as any,
271
+ ])
272
+
273
+ const exitCode = await run(['node', 'mercato', 'db', 'migrate', '-h'])
274
+
275
+ expect(exitCode).toBe(0)
276
+ expect(dbMigrate).not.toHaveBeenCalled()
277
+
278
+ consoleLogSpy.mockRestore()
279
+ consoleErrorSpy.mockRestore()
280
+ })
281
+
282
+ it('prints usage instead of destroying data when greenfield --yes --help is passed', async () => {
283
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
284
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
285
+ const dbGreenfield = jest.fn()
286
+
287
+ registerCliModules([
288
+ {
289
+ id: 'db',
290
+ cli: [{
291
+ command: 'greenfield',
292
+ help: 'Destroys all data.',
293
+ run: dbGreenfield,
294
+ }],
295
+ } as any,
296
+ ])
297
+
298
+ // --yes is the flag that skips greenfield's confirmation prompt, so pairing it with
299
+ // --help is the scenario that must never reach `run`, regardless of flag order.
300
+ const exitCode = await run(['node', 'mercato', 'db', 'greenfield', '--yes', '--help'])
301
+
302
+ expect(exitCode).toBe(0)
303
+ expect(dbGreenfield).not.toHaveBeenCalled()
304
+
305
+ consoleLogSpy.mockRestore()
306
+ consoleErrorSpy.mockRestore()
307
+ })
308
+
309
+ it('forwards --help to commands that declare handlesHelp', async () => {
310
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
311
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
312
+ const deploy = jest.fn()
313
+
314
+ registerCliModules([
315
+ { id: 'deploy', cli: [{ command: 'railway', handlesHelp: true, run: deploy }] } as any,
316
+ ])
317
+
318
+ const exitCode = await run(['node', 'mercato', 'deploy', 'railway', '--help'])
319
+
320
+ expect(exitCode).toBe(0)
321
+ expect(deploy).toHaveBeenCalledWith(['--help'])
322
+
323
+ consoleLogSpy.mockRestore()
324
+ consoleErrorSpy.mockRestore()
325
+ })
326
+
327
+ it('lists the module commands when the help flag sits in the command slot', async () => {
328
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
329
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
330
+ const dbGenerate = jest.fn()
331
+
332
+ registerCliModules([
333
+ {
334
+ id: 'db',
335
+ cli: [
336
+ { command: 'generate', run: dbGenerate },
337
+ { command: 'migrate', run: jest.fn() },
338
+ ],
339
+ } as any,
340
+ ])
341
+
342
+ const exitCode = await run(['node', 'mercato', 'db', '--help'])
343
+
344
+ expect(exitCode).toBe(0)
345
+ expect(dbGenerate).not.toHaveBeenCalled()
346
+ expect(consoleErrorSpy).not.toHaveBeenCalled()
347
+ const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
348
+ expect(printed).toContain('Commands for "db": generate, migrate')
349
+
350
+ consoleLogSpy.mockRestore()
351
+ consoleErrorSpy.mockRestore()
352
+ })
353
+
354
+ it('lets a self-documenting command print its own subcommand help', async () => {
355
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
356
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
357
+ // Mirrors packages/core/src/modules/configs/cli.ts, whose `cache` command routes
358
+ // --help to its own printCacheHelp() rather than to the dispatcher's generic usage.
359
+ const cache = jest.fn((rest: string[]) => {
360
+ if (rest[0] === '--help') console.log('configs cache: stats | purge | structural')
361
+ })
362
+
363
+ registerCliModules([
364
+ { id: 'configs', cli: [{ command: 'cache', handlesHelp: true, run: cache }] } as any,
365
+ ])
366
+
367
+ const exitCode = await run(['node', 'mercato', 'configs', 'cache', '--help'])
368
+
369
+ expect(exitCode).toBe(0)
370
+ expect(cache).toHaveBeenCalledWith(['--help'])
371
+ const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
372
+ expect(printed).toContain('configs cache: stats | purge | structural')
373
+ expect(printed).not.toContain('Usage: ✨ mercato configs cache [args]')
374
+
375
+ consoleLogSpy.mockRestore()
376
+ consoleErrorSpy.mockRestore()
377
+ })
378
+
379
+ it('still runs the command when no help flag is present', async () => {
380
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
381
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
382
+ const dbGenerate = jest.fn()
383
+
384
+ registerCliModules([
385
+ { id: 'db', cli: [{ command: 'generate', run: dbGenerate }] } as any,
386
+ ])
387
+
388
+ const exitCode = await run(['node', 'mercato', 'db', 'generate'])
389
+
390
+ expect(exitCode).toBe(0)
391
+ expect(dbGenerate).toHaveBeenCalled()
392
+
393
+ consoleLogSpy.mockRestore()
394
+ consoleErrorSpy.mockRestore()
395
+ })
396
+ })
397
+
398
+ describe('top-level command help', () => {
399
+ it('prints usage instead of initializing the app when init --help is passed', async () => {
400
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
401
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
402
+
403
+ const exitCode = await run(['node', 'mercato', 'init', '--help'])
404
+
405
+ expect(exitCode).toBe(0)
406
+ const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
407
+ expect(printed).toContain('Usage: mercato init')
408
+
409
+ consoleLogSpy.mockRestore()
410
+ consoleErrorSpy.mockRestore()
411
+ })
412
+
413
+ it('prints usage instead of seeding when seed:defaults --help is passed', async () => {
414
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
415
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
416
+
417
+ const exitCode = await run(['node', 'mercato', 'seed:defaults', '--help'])
418
+
419
+ expect(exitCode).toBe(0)
420
+ const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
421
+ expect(printed).toContain('Usage: mercato seed:defaults')
422
+
423
+ consoleLogSpy.mockRestore()
424
+ consoleErrorSpy.mockRestore()
425
+ })
426
+
427
+ it.each(['constructor', 'toString', 'valueOf', 'hasOwnProperty', '__proto__'])(
428
+ 'reports %s as an unknown module instead of matching an inherited prototype key',
429
+ async (inheritedKey) => {
430
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
431
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
432
+
433
+ registerCliModules([
434
+ { id: 'db', cli: [{ command: 'generate', run: jest.fn() }] } as any,
435
+ ])
436
+
437
+ const exitCode = await run(['node', 'mercato', inheritedKey, '--help'])
438
+
439
+ expect(exitCode).toBe(1)
440
+ const errors = consoleErrorSpy.mock.calls.map((call) => String(call[0])).join('\n')
441
+ expect(errors).toContain(`Module not found: "${inheritedKey}"`)
442
+
443
+ consoleLogSpy.mockRestore()
444
+ consoleErrorSpy.mockRestore()
445
+ },
446
+ )
447
+ })
448
+ })
449
+
190
450
  describe('db command failure output', () => {
191
451
  const originalDatabaseUrl = process.env.DATABASE_URL
192
452
 
@@ -313,6 +573,110 @@ describe('db command failure output', () => {
313
573
  })
314
574
  })
315
575
 
576
+ describe('module command exit signal propagation', () => {
577
+ let consoleErrorSpy: jest.SpyInstance
578
+ let consoleLogSpy: jest.SpyInstance
579
+
580
+ beforeEach(() => {
581
+ jest.restoreAllMocks()
582
+ consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
583
+ consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
584
+ })
585
+
586
+ afterEach(() => {
587
+ consoleErrorSpy.mockRestore()
588
+ consoleLogSpy.mockRestore()
589
+ process.exitCode = undefined
590
+ })
591
+
592
+ it('propagates a non-zero process.exitCode set by a command that does not throw', async () => {
593
+ registerCliModules([
594
+ {
595
+ id: 'reporting',
596
+ cli: [{
597
+ command: 'export',
598
+ run: jest.fn().mockImplementation(async () => {
599
+ process.exitCode = 1
600
+ }),
601
+ }],
602
+ } as any,
603
+ ])
604
+
605
+ const exitCode = await run(['node', 'mercato', 'reporting', 'export'])
606
+
607
+ expect(exitCode).toBe(1)
608
+ })
609
+
610
+ it('preserves the exact exit code a command signals rather than collapsing it to 1', async () => {
611
+ registerCliModules([
612
+ {
613
+ id: 'reporting',
614
+ cli: [{
615
+ command: 'export',
616
+ run: jest.fn().mockImplementation(async () => {
617
+ process.exitCode = 42
618
+ }),
619
+ }],
620
+ } as any,
621
+ ])
622
+
623
+ const exitCode = await run(['node', 'mercato', 'reporting', 'export'])
624
+
625
+ expect(exitCode).toBe(42)
626
+ })
627
+
628
+ it('returns 0 for a command that completes without signalling a failure', async () => {
629
+ registerCliModules([
630
+ {
631
+ id: 'reporting',
632
+ cli: [{ command: 'export', run: jest.fn().mockResolvedValue(undefined) }],
633
+ } as any,
634
+ ])
635
+
636
+ const exitCode = await run(['node', 'mercato', 'reporting', 'export'])
637
+
638
+ expect(exitCode).toBe(0)
639
+ })
640
+
641
+ it('ignores a non-zero process.exitCode inherited from before the command ran', async () => {
642
+ process.exitCode = 7
643
+
644
+ registerCliModules([
645
+ {
646
+ id: 'reporting',
647
+ cli: [{ command: 'export', run: jest.fn().mockResolvedValue(undefined) }],
648
+ } as any,
649
+ ])
650
+
651
+ const exitCode = await run(['node', 'mercato', 'reporting', 'export'])
652
+
653
+ expect(exitCode).toBe(0)
654
+ expect(process.exitCode).toBe(7)
655
+ })
656
+
657
+ it('still reports 1 when a command throws, regardless of process.exitCode', async () => {
658
+ process.exitCode = 7
659
+
660
+ registerCliModules([
661
+ {
662
+ id: 'reporting',
663
+ cli: [{
664
+ command: 'export',
665
+ run: jest.fn().mockImplementation(async () => {
666
+ process.exitCode = 3
667
+ throw new Error('export failed')
668
+ }),
669
+ }],
670
+ } as any,
671
+ ])
672
+
673
+ const exitCode = await run(['node', 'mercato', 'reporting', 'export'])
674
+
675
+ expect(exitCode).toBe(1)
676
+ expect(process.exitCode).toBe(7)
677
+ })
678
+ })
679
+
316
680
  describe('init command failure output', () => {
317
681
  const originalDatabaseUrl = process.env.DATABASE_URL
318
682
 
@@ -529,6 +893,122 @@ describe('init command failure output', () => {
529
893
  consoleErrorSpy.mockRestore()
530
894
  consoleLogSpy.mockRestore()
531
895
  })
896
+
897
+ function mockInitDependencies({
898
+ authSetup,
899
+ }: {
900
+ authSetup: jest.Mock
901
+ }) {
902
+ jest.doMock('child_process', () => ({
903
+ execSync: jest.fn(),
904
+ }))
905
+ jest.doMock('pg', () => ({
906
+ Client: jest.fn().mockImplementation(() => ({
907
+ connect: jest.fn().mockResolvedValue(undefined),
908
+ query: jest.fn().mockResolvedValue({
909
+ rows: [{ org_id: 'org-1', tenant_id: 'tenant-1' }],
910
+ }),
911
+ end: jest.fn().mockResolvedValue(undefined),
912
+ })),
913
+ }))
914
+ jest.doMock('../lib/generators', () => ({
915
+ generateEntityIds: jest.fn().mockResolvedValue(undefined),
916
+ generateModuleRegistries: jest.fn().mockResolvedValue(undefined),
917
+ generateModuleEntities: jest.fn().mockResolvedValue(undefined),
918
+ generateModuleDi: jest.fn().mockResolvedValue(undefined),
919
+ generateModulePackageSources: jest.fn().mockResolvedValue(undefined),
920
+ generateWebResearchAdapters: jest.fn().mockResolvedValue(undefined),
921
+ generateOpenApi: jest.fn().mockResolvedValue(undefined),
922
+ }))
923
+ jest.doMock('../lib/db', () => ({
924
+ dbMigrate: jest.fn().mockResolvedValue(undefined),
925
+ }))
926
+ jest.doMock('../lib/resolver', () => ({
927
+ createResolver: () => ({
928
+ getAppDir: () => '/tmp/test-app',
929
+ }),
930
+ }))
931
+ jest.doMock('@open-mercato/shared/lib/bootstrap/dynamicLoader', () => ({
932
+ bootstrapFromAppRoot: jest.fn().mockResolvedValue({
933
+ modules: [
934
+ {
935
+ id: 'configs',
936
+ cli: [{ command: 'restore-defaults', run: jest.fn().mockResolvedValue(undefined) }],
937
+ },
938
+ {
939
+ id: 'auth',
940
+ cli: [
941
+ { command: 'setup', run: authSetup },
942
+ { command: 'seed-roles', run: jest.fn().mockResolvedValue(undefined) },
943
+ ],
944
+ },
945
+ {
946
+ id: 'entities',
947
+ cli: [{ command: 'seed-encryption', run: jest.fn().mockResolvedValue(undefined) }],
948
+ },
949
+ {
950
+ id: 'query_index',
951
+ cli: [{ command: 'reindex', run: jest.fn().mockResolvedValue(undefined) }],
952
+ },
953
+ ],
954
+ }),
955
+ }))
956
+ jest.doMock('@open-mercato/shared/lib/di/container', () => ({
957
+ createRequestContainer: jest.fn().mockResolvedValue({
958
+ resolve: jest.fn().mockReturnValue({}),
959
+ }),
960
+ }))
961
+ jest.doMock(
962
+ '@open-mercato/core/modules/auth/lib/setup-app',
963
+ () => ({
964
+ ensureCustomRoleAcls: jest.fn().mockResolvedValue(undefined),
965
+ }),
966
+ { virtual: true },
967
+ )
968
+ }
969
+
970
+ it('passes --include-demo-users to auth setup by default', async () => {
971
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
972
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
973
+ const authSetup = jest.fn().mockResolvedValue(undefined)
974
+ mockInitDependencies({ authSetup })
975
+
976
+ const mercato = await import('../mercato')
977
+ const exitCode = await mercato.run(['node', 'mercato', 'init'])
978
+
979
+ expect(exitCode).toBe(0)
980
+ expect(authSetup).toHaveBeenCalledWith(expect.arrayContaining(['--include-demo-users']))
981
+ expect(consoleLogSpy).toHaveBeenCalledWith('👤 Demo accounts (admin@/employee@): enabled')
982
+ const loggedLines = consoleLogSpy.mock.calls.map((args) => args.join(' '))
983
+ expect(loggedLines.some((line) => line.includes('🧰 Admin:'))).toBe(true)
984
+ expect(loggedLines.some((line) => line.includes('👷 Employee:'))).toBe(true)
985
+
986
+ consoleErrorSpy.mockRestore()
987
+ consoleLogSpy.mockRestore()
988
+ })
989
+
990
+ it('skips --include-demo-users when --no-demo-users is passed', async () => {
991
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
992
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
993
+ const authSetup = jest.fn().mockResolvedValue(undefined)
994
+ mockInitDependencies({ authSetup })
995
+
996
+ const mercato = await import('../mercato')
997
+ const exitCode = await mercato.run(['node', 'mercato', 'init', '--no-demo-users'])
998
+
999
+ expect(exitCode).toBe(0)
1000
+ expect(authSetup).toHaveBeenCalled()
1001
+ expect(authSetup.mock.calls[0][0]).not.toContain('--include-demo-users')
1002
+ expect(consoleLogSpy).toHaveBeenCalledWith(
1003
+ '👤 Demo accounts (admin@/employee@): skipped (--no-demo-users)',
1004
+ )
1005
+ const loggedLines = consoleLogSpy.mock.calls.map((args) => args.join(' '))
1006
+ expect(loggedLines.some((line) => line.includes('🧰 Admin:'))).toBe(false)
1007
+ expect(loggedLines.some((line) => line.includes('👷 Employee:'))).toBe(false)
1008
+
1009
+ consoleErrorSpy.mockRestore()
1010
+ consoleLogSpy.mockRestore()
1011
+ })
532
1012
  })
533
1013
 
534
1014
  describe('seed:defaults command', () => {
package/src/bin.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  * Uses dynamic app resolution to find generated files at .mercato/generated/
6
6
  */
7
7
  import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/runtime'
8
+ import { installNextSubpathResolveHook } from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'
8
9
  import { resolveCliBootstrapMode, type CliBootstrapMode } from './lib/cli-bootstrap-mode.js'
9
10
  import { flushBeforeExit } from './lib/flush-before-exit.js'
10
11
  // `run` is imported dynamically inside `main()` so telemetry can initialize
@@ -72,6 +73,10 @@ async function tryBootstrap(mode: Exclude<CliBootstrapMode, 'none'>): Promise<bo
72
73
 
73
74
  async function main(): Promise<void> {
74
75
  assertNode24Runtime()
76
+ // Commands and workers run in plain Node, where a bare `next/<subpath>` such
77
+ // as `next/dynamic` or `next/link` does not resolve (#7102). Install the
78
+ // retry-with-`.js` hook before any package dist can be imported.
79
+ installNextSubpathResolveHook()
75
80
  const bootstrapMode = resolveCliBootstrapMode(process.argv)
76
81
 
77
82
  if (bootstrapMode !== 'none') {
@@ -0,0 +1,25 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+
4
+ /**
5
+ * Regression (#7102): CLI commands and workers load package dists that import
6
+ * bare `next/dynamic`, `next/link`, … which plain Node ESM cannot resolve. The
7
+ * entry must install the resolve hook before anything can import such a dist.
8
+ */
9
+ describe('bin.ts next/<subpath> resolve hook', () => {
10
+ const binSource = fs.readFileSync(path.resolve(__dirname, '../../bin.ts'), 'utf8')
11
+
12
+ it('imports the shared resolve hook', () => {
13
+ expect(binSource).toContain(
14
+ "import { installNextSubpathResolveHook } from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'",
15
+ )
16
+ })
17
+
18
+ it('installs the hook before bootstrapping or loading the mercato entry', () => {
19
+ const installCall = binSource.indexOf('installNextSubpathResolveHook()')
20
+ expect(installCall).toBeGreaterThan(-1)
21
+ expect(installCall).toBeLessThan(binSource.indexOf('await loadAppEnv()'))
22
+ expect(installCall).toBeLessThan(binSource.indexOf('await tryBootstrap(bootstrapMode)'))
23
+ expect(installCall).toBeLessThan(binSource.indexOf("const { run } = await import('./mercato.js')"))
24
+ })
25
+ })
@@ -2211,6 +2211,7 @@ function buildReusableEnvironment(
2211
2211
  OM_TEST_BROWSER_TELEMETRY_MODE: 'opt-in',
2212
2212
  OM_DISABLE_EMAIL_DELIVERY: '0',
2213
2213
  OM_ENABLE_TEST_CHANNEL_SEEDING: 'true',
2214
+ OM_ENABLE_TEST_OAUTH_GRANTS: 'true',
2214
2215
  OM_ENABLE_TEST_EMAIL_CAPTURE_DELIVERY: 'true',
2215
2216
  OM_TEST_SYSTEM_EMAIL_CAPTURE_PATH: EPHEMERAL_SYSTEM_EMAIL_CAPTURE_PATH,
2216
2217
  OM_TEST_EMAIL_CAPTURE_ACCESS_TOKEN: TEST_EMAIL_CAPTURE_ACCESS_TOKEN,
@@ -3612,6 +3613,7 @@ export async function startEphemeralEnvironment(options: EphemeralRuntimeOptions
3612
3613
  // also carries the `om_test_browser_telemetry=on` cookie, which only TC-TELEMETRY-002 sets.
3613
3614
  OM_TEST_BROWSER_TELEMETRY_MODE: 'opt-in',
3614
3615
  OM_ENABLE_TEST_CHANNEL_SEEDING: 'true',
3616
+ OM_ENABLE_TEST_OAUTH_GRANTS: 'true',
3615
3617
  OM_ENABLE_TEST_EMAIL_CAPTURE_DELIVERY: 'true',
3616
3618
  OM_TEST_SYSTEM_EMAIL_CAPTURE_PATH: EPHEMERAL_SYSTEM_EMAIL_CAPTURE_PATH,
3617
3619
  OM_TEST_EMAIL_CAPTURE_ACCESS_TOKEN: TEST_EMAIL_CAPTURE_ACCESS_TOKEN,