@open-mercato/cli 0.11.1-develop.8433.1.e3ebfc0705 → 0.11.1-develop.8442.1.89aff724e8

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 (91) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/agentic/guides/module-facts.json +162 -162
  3. package/dist/agentic/guides/module-facts.v2.json +162 -162
  4. package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
  5. package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
  6. package/dist/agentic/guides/modules/api_docs/index.md +1 -1
  7. package/dist/agentic/guides/modules/api_keys/index.md +1 -1
  8. package/dist/agentic/guides/modules/attachments/index.md +1 -1
  9. package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
  10. package/dist/agentic/guides/modules/auth/index.md +1 -1
  11. package/dist/agentic/guides/modules/availability/index.md +1 -1
  12. package/dist/agentic/guides/modules/business_rules/index.md +1 -1
  13. package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
  14. package/dist/agentic/guides/modules/cart/index.md +1 -1
  15. package/dist/agentic/guides/modules/catalog/index.md +1 -1
  16. package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
  17. package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
  18. package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
  19. package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
  20. package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
  21. package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
  22. package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
  23. package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
  24. package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
  25. package/dist/agentic/guides/modules/checkout/index.md +1 -1
  26. package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
  27. package/dist/agentic/guides/modules/configs/index.md +1 -1
  28. package/dist/agentic/guides/modules/content/index.md +1 -1
  29. package/dist/agentic/guides/modules/currencies/index.md +1 -1
  30. package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
  31. package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
  32. package/dist/agentic/guides/modules/customers/index.md +1 -1
  33. package/dist/agentic/guides/modules/dashboards/index.md +1 -1
  34. package/dist/agentic/guides/modules/data_sync/index.md +1 -1
  35. package/dist/agentic/guides/modules/design_system/index.md +1 -1
  36. package/dist/agentic/guides/modules/devices/index.md +1 -1
  37. package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
  38. package/dist/agentic/guides/modules/directory/index.md +1 -1
  39. package/dist/agentic/guides/modules/documents/index.md +1 -1
  40. package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
  41. package/dist/agentic/guides/modules/entities/index.md +1 -1
  42. package/dist/agentic/guides/modules/eudr/index.md +1 -1
  43. package/dist/agentic/guides/modules/events/index.md +1 -1
  44. package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
  45. package/dist/agentic/guides/modules/forms/index.md +1 -1
  46. package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
  47. package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
  48. package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
  49. package/dist/agentic/guides/modules/generators/index.md +1 -1
  50. package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
  51. package/dist/agentic/guides/modules/integrations/index.md +1 -1
  52. package/dist/agentic/guides/modules/messages/index.md +1 -1
  53. package/dist/agentic/guides/modules/notifications/index.md +1 -1
  54. package/dist/agentic/guides/modules/onboarding/index.md +1 -1
  55. package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
  56. package/dist/agentic/guides/modules/perspectives/index.md +1 -1
  57. package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
  58. package/dist/agentic/guides/modules/planner/index.md +1 -1
  59. package/dist/agentic/guides/modules/portal/index.md +1 -1
  60. package/dist/agentic/guides/modules/progress/index.md +1 -1
  61. package/dist/agentic/guides/modules/promotions/index.md +1 -1
  62. package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
  63. package/dist/agentic/guides/modules/query_index/index.md +1 -1
  64. package/dist/agentic/guides/modules/record_locks/index.md +1 -1
  65. package/dist/agentic/guides/modules/resources/index.md +1 -1
  66. package/dist/agentic/guides/modules/sales/index.md +1 -1
  67. package/dist/agentic/guides/modules/scheduler/index.md +1 -1
  68. package/dist/agentic/guides/modules/search/index.md +1 -1
  69. package/dist/agentic/guides/modules/security/index.md +1 -1
  70. package/dist/agentic/guides/modules/seeds/index.md +1 -1
  71. package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
  72. package/dist/agentic/guides/modules/sso/index.md +1 -1
  73. package/dist/agentic/guides/modules/staff/index.md +1 -1
  74. package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
  75. package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
  76. package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
  77. package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
  78. package/dist/agentic/guides/modules/telemetry/index.md +1 -1
  79. package/dist/agentic/guides/modules/tillio/index.md +1 -1
  80. package/dist/agentic/guides/modules/translations/index.md +1 -1
  81. package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
  82. package/dist/agentic/guides/modules/webhooks/index.md +1 -1
  83. package/dist/agentic/guides/modules/wms/index.md +1 -1
  84. package/dist/agentic/guides/modules/workflows/index.md +1 -1
  85. package/dist/agentic/guides/reference-module-facts.json +1 -1
  86. package/dist/agentic/guides/upstream/manifest.json +1 -1
  87. package/dist/mercato.js +3 -1
  88. package/dist/mercato.js.map +2 -2
  89. package/package.json +7 -7
  90. package/src/__tests__/mercato.test.ts +134 -1
  91. package/src/mercato.ts +4 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-mercato/cli",
3
- "version": "0.11.1-develop.8433.1.e3ebfc0705",
3
+ "version": "0.11.1-develop.8442.1.89aff724e8",
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.11.1-develop.8433.1.e3ebfc0705",
64
- "@open-mercato/queue": "0.11.1-develop.8433.1.e3ebfc0705",
65
- "@open-mercato/shared": "0.11.1-develop.8433.1.e3ebfc0705",
66
- "@open-mercato/telemetry": "0.11.1-develop.8433.1.e3ebfc0705",
63
+ "@open-mercato/events": "0.11.1-develop.8442.1.89aff724e8",
64
+ "@open-mercato/queue": "0.11.1-develop.8442.1.89aff724e8",
65
+ "@open-mercato/shared": "0.11.1-develop.8442.1.89aff724e8",
66
+ "@open-mercato/telemetry": "0.11.1-develop.8442.1.89aff724e8",
67
67
  "cross-spawn": "^7.0.6",
68
68
  "minisearch": "7.2.0",
69
69
  "pg": "8.23.0",
@@ -75,10 +75,10 @@
75
75
  "typescript-js": "npm:typescript@6.0.3"
76
76
  },
77
77
  "peerDependencies": {
78
- "@open-mercato/shared": "0.11.1-develop.8433.1.e3ebfc0705"
78
+ "@open-mercato/shared": "0.11.1-develop.8442.1.89aff724e8"
79
79
  },
80
80
  "devDependencies": {
81
- "@open-mercato/shared": "0.11.1-develop.8433.1.e3ebfc0705",
81
+ "@open-mercato/shared": "0.11.1-develop.8442.1.89aff724e8",
82
82
  "@types/jest": "^30.0.0",
83
83
  "jest": "^30.4.2",
84
84
  "ts-jest": "^29.4.12"
@@ -12,8 +12,12 @@ import { pathIncludes } from '../lib/__tests__/path-helpers'
12
12
 
13
13
  type MockChildAutoExit = { code: number | null; signal?: NodeJS.Signals | null } | undefined
14
14
  type MockChildSpawnRouter = (args: string[]) => MockChildAutoExit
15
+ type MockChildKillExitCodeRouter = (args: string[]) => number | undefined
15
16
 
16
- function buildMockChildProcessModule(routeAutoExit: MockChildSpawnRouter) {
17
+ function buildMockChildProcessModule(
18
+ routeAutoExit: MockChildSpawnRouter,
19
+ routeKillExitCode: MockChildKillExitCodeRouter = () => undefined,
20
+ ) {
17
21
  const { EventEmitter } = jest.requireActual('node:events')
18
22
 
19
23
  const createChild = (spawnargs: string[], autoExit?: MockChildAutoExit) => {
@@ -29,6 +33,14 @@ function buildMockChildProcessModule(routeAutoExit: MockChildSpawnRouter) {
29
33
  if (child.exitCode !== null || child.signalCode !== null) {
30
34
  return true
31
35
  }
36
+ const handledExitCode = routeKillExitCode(spawnargs.slice(1))
37
+ if (typeof handledExitCode === 'number') {
38
+ child.exitCode = handledExitCode
39
+ queueMicrotask(() => {
40
+ child.emit('exit', handledExitCode, null)
41
+ })
42
+ return true
43
+ }
32
44
  child.signalCode = signal
33
45
  queueMicrotask(() => {
34
46
  child.emit('exit', null, signal)
@@ -65,6 +77,37 @@ function buildMockChildProcessModule(routeAutoExit: MockChildSpawnRouter) {
65
77
  }
66
78
  }
67
79
 
80
+ const nextExitsWithCodeWhenKilled = (exitCode: number): MockChildKillExitCodeRouter => (args) =>
81
+ pathIncludes(args[0] ?? '', 'next/dist/bin/next') ? exitCode : undefined
82
+
83
+ async function runServerAndSendSignal(
84
+ mercato: typeof import('../mercato'),
85
+ command: 'start' | 'dev',
86
+ signal: 'SIGINT' | 'SIGTERM',
87
+ ): Promise<number> {
88
+ const listenersBefore = new Set(process.listeners(signal))
89
+ try {
90
+ const pending = mercato.run(['node', 'mercato', 'server', command])
91
+ const { spawn } = await import('child_process')
92
+ const nextSpawned = () => (spawn as jest.Mock).mock.calls.some((call) =>
93
+ pathIncludes(call[1]?.[0] ?? '', 'next/dist/bin/next') && call[1]?.includes(command),
94
+ )
95
+ for (let attempt = 0; attempt < 1000 && !nextSpawned(); attempt += 1) {
96
+ await new Promise((resolve) => setImmediate(resolve))
97
+ }
98
+ expect(nextSpawned()).toBe(true)
99
+ for (let attempt = 0; attempt < 20; attempt += 1) {
100
+ await new Promise((resolve) => setImmediate(resolve))
101
+ }
102
+ process.emit(signal, signal)
103
+ return await pending
104
+ } finally {
105
+ for (const listener of process.listeners(signal)) {
106
+ if (!listenersBefore.has(listener)) process.removeListener(signal, listener)
107
+ }
108
+ }
109
+ }
110
+
68
111
  const eventsWorkerFixture: Pick<Module, 'id' | 'workers'> = {
69
112
  id: 'events',
70
113
  workers: [
@@ -87,6 +130,92 @@ const schedulerCliFixture: Pick<Module, 'id' | 'cli'> = {
87
130
  ],
88
131
  }
89
132
 
133
+ function mockServerFileSystem(extra: Record<string, unknown> = {}) {
134
+ jest.doMock('node:fs', () => {
135
+ const actual = jest.requireActual('node:fs')
136
+ return {
137
+ ...actual,
138
+ existsSync: jest.fn((candidate: string) =>
139
+ pathIncludes(candidate, 'next/dist/bin/next') || pathIncludes(candidate, '@open-mercato/cli/bin/mercato'),
140
+ ),
141
+ ...extra,
142
+ }
143
+ })
144
+ }
145
+
146
+ function mockDevServerEnvironment() {
147
+ mockServerFileSystem({ unlinkSync: jest.fn() })
148
+ jest.doMock('../lib/generators', () => ({
149
+ generateModulePackageSources: jest.fn().mockResolvedValue(undefined),
150
+ generateWebResearchAdapters: jest.fn().mockResolvedValue(undefined),
151
+ }))
152
+ jest.doMock('../lib/resolver', () => ({
153
+ resolveEnvironment: () => ({ appDir: '/tmp/test-app', rootDir: '/tmp/test-root' }),
154
+ createResolver: () => ({}),
155
+ }))
156
+ }
157
+
158
+ function mockStartServerEnvironment() {
159
+ mockServerFileSystem()
160
+ jest.doMock('../lib/resolver', () => ({
161
+ resolveEnvironment: () => ({ appDir: '/tmp/test-app', rootDir: '/tmp/test-root' }),
162
+ }))
163
+ jest.doMock('../lib/server-start-lock', () => ({
164
+ acquireServerStartLock: jest.fn(() => ({ release: jest.fn() })),
165
+ }))
166
+ }
167
+
168
+ function registerShutdownExitCodeTests(command: 'start' | 'dev', mockEnvironment: () => void) {
169
+ it.each([
170
+ ['SIGTERM', 143],
171
+ ['SIGINT', 130],
172
+ ] as const)('exits cleanly when Next.js handles %s itself and exits with code %i during shutdown', async (signal, nextExitCode) => {
173
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
174
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
175
+ mockEnvironment()
176
+ jest.doMock('child_process', () =>
177
+ buildMockChildProcessModule(() => undefined, nextExitsWithCodeWhenKilled(nextExitCode)),
178
+ )
179
+
180
+ const mercato = await import('../mercato')
181
+ mercato.registerCliModules([eventsWorkerFixture as Module])
182
+ const exitCode = await runServerAndSendSignal(mercato, command, signal)
183
+
184
+ expect(exitCode).toBe(0)
185
+ expect(consoleErrorSpy).not.toHaveBeenCalled()
186
+ const { spawn } = await import('child_process')
187
+ const spawnMock = spawn as jest.Mock
188
+ const nextChild = spawnMock.mock.results.find((_result, index) =>
189
+ pathIncludes(spawnMock.mock.calls[index][1]?.[0] ?? '', 'next/dist/bin/next'),
190
+ )?.value
191
+ expect(nextChild?.exitCode).toBe(nextExitCode)
192
+
193
+ consoleErrorSpy.mockRestore()
194
+ consoleLogSpy.mockRestore()
195
+ })
196
+
197
+ it('still fails when Next.js exits with code 143 without a shutdown request', async () => {
198
+ const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
199
+ const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
200
+ process.env.AUTO_SPAWN_WORKERS = 'false'
201
+ mockEnvironment()
202
+ jest.doMock('child_process', () =>
203
+ buildMockChildProcessModule((args) =>
204
+ pathIncludes(args[0] ?? '', 'next/dist/bin/next') ? { code: 143 } : undefined,
205
+ ),
206
+ )
207
+
208
+ const mercato = await import('../mercato')
209
+ const exitCode = await mercato.run(['node', 'mercato', 'server', command])
210
+
211
+ expect(exitCode).toBe(1)
212
+ expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('exited unexpectedly with exit code 143.'))
213
+
214
+ consoleErrorSpy.mockRestore()
215
+ consoleLogSpy.mockRestore()
216
+ })
217
+ }
218
+
90
219
  describe('mercato CLI module registration', () => {
91
220
  beforeEach(() => {
92
221
  // Reset module state by re-importing
@@ -1862,6 +1991,8 @@ describe('server dev managed process exits', () => {
1862
1991
  consoleLogSpy.mockRestore()
1863
1992
  })
1864
1993
 
1994
+ registerShutdownExitCodeTests('dev', mockDevServerEnvironment)
1995
+
1865
1996
  it('retries the Next.js dev server once when it exits before reporting ready', async () => {
1866
1997
  const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
1867
1998
  const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
@@ -2608,6 +2739,8 @@ describe('server start managed process exits', () => {
2608
2739
  consoleLogSpy.mockRestore()
2609
2740
  })
2610
2741
 
2742
+ registerShutdownExitCodeTests('start', mockStartServerEnvironment)
2743
+
2611
2744
  it('restarts the managed dev runtime when an app env file changes', async () => {
2612
2745
  const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
2613
2746
  const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
package/src/mercato.ts CHANGED
@@ -586,6 +586,8 @@ function isExpectedManagedExitSignal(signal: NodeJS.Signals | null): boolean {
586
586
  return signal === 'SIGINT' || signal === 'SIGTERM'
587
587
  }
588
588
 
589
+ const SHUTDOWN_SIGNAL_EXIT_CODES = new Set([130, 143])
590
+
589
591
  function isExpectedManagedExit(
590
592
  result: ManagedProcessExitResult,
591
593
  options: { stopping?: boolean } = {},
@@ -595,7 +597,8 @@ function isExpectedManagedExit(
595
597
  // Queue workers handle SIGINT/SIGTERM themselves so they can close queue
596
598
  // resources before exiting. That graceful path calls process.exit(0), which
597
599
  // reports as { code: 0, signal: null } to the supervising server process.
598
- return options.stopping === true && result.code === 0
600
+ if (options.stopping !== true) return false
601
+ return result.code === 0 || (result.code !== null && SHUTDOWN_SIGNAL_EXIT_CODES.has(result.code))
599
602
  }
600
603
 
601
604
  function formatManagedProcessExitStatus(result: ManagedProcessExitResult): string {