@open-mercato/cli 0.11.1-develop.8432.1.c98419720f → 0.11.1-develop.8441.1.92a9090201
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.
- package/dist/agentic/guides/module-facts.json +162 -162
- package/dist/agentic/guides/module-facts.v2.json +162 -162
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/business_rules/index.md +1 -1
- package/dist/agentic/guides/modules/carrier_inpost/index.md +1 -1
- package/dist/agentic/guides/modules/cart/index.md +1 -1
- package/dist/agentic/guides/modules/catalog/index.md +1 -1
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/index.md +1 -1
- package/dist/agentic/guides/modules/design_system/index.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/index.md +1 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/scheduler/index.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/security/index.md +1 -1
- package/dist/agentic/guides/modules/seeds/index.md +1 -1
- package/dist/agentic/guides/modules/shipping_carriers/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/manifest.json +1 -1
- package/dist/mercato.js +3 -1
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +134 -1
- 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.
|
|
3
|
+
"version": "0.11.1-develop.8441.1.92a9090201",
|
|
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.
|
|
64
|
-
"@open-mercato/queue": "0.11.1-develop.
|
|
65
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
66
|
-
"@open-mercato/telemetry": "0.11.1-develop.
|
|
63
|
+
"@open-mercato/events": "0.11.1-develop.8441.1.92a9090201",
|
|
64
|
+
"@open-mercato/queue": "0.11.1-develop.8441.1.92a9090201",
|
|
65
|
+
"@open-mercato/shared": "0.11.1-develop.8441.1.92a9090201",
|
|
66
|
+
"@open-mercato/telemetry": "0.11.1-develop.8441.1.92a9090201",
|
|
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.
|
|
78
|
+
"@open-mercato/shared": "0.11.1-develop.8441.1.92a9090201"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.11.1-develop.8441.1.92a9090201",
|
|
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(
|
|
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
|
-
|
|
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 {
|