@open-mercato/cli 0.11.1-develop.8557.1.e615240a3e → 0.11.1-develop.8567.1.a167594505
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/.turbo/turbo-build.log +6 -2
- package/dist/agentic/guides/module-facts.json +330 -195
- package/dist/agentic/guides/module-facts.v2.json +330 -195
- 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/di-registrations-rich.md +1 -1
- package/dist/agentic/guides/modules/api_keys/di-service-tokens.md +1 -1
- package/dist/agentic/guides/modules/api_keys/exact-override-targets.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/di-registrations-rich.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/di-service-tokens.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/exact-override-targets.md +2 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +2 -2
- 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/backups/index.md +12 -0
- package/dist/agentic/guides/modules/backups/owned-contract-module-metadata.md +11 -0
- 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/exact-override-targets.md +2 -2
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/setup.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/di-registrations-rich.md +2 -2
- package/dist/agentic/guides/modules/record_locks/di-service-tokens.md +2 -2
- package/dist/agentic/guides/modules/record_locks/exact-override-targets.md +2 -2
- 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/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/search/index.md +1 -1
- package/dist/agentic/guides/modules/search/setup.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/di-registrations-rich.md +10 -10
- package/dist/agentic/guides/modules/workflows/di-service-tokens.md +10 -10
- package/dist/agentic/guides/modules/workflows/exact-override-targets.md +10 -10
- 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/bin.js +2 -1
- package/dist/bin.js.map +2 -2
- package/dist/lib/rotation-kms-warning-presentation.js +12 -0
- package/dist/lib/rotation-kms-warning-presentation.js.map +7 -0
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +105 -0
- package/src/bin.ts +2 -1
- package/src/lib/__tests__/rotation-kms-warning-presentation.test.ts +73 -0
- package/src/lib/generators/__tests__/instance-config-defaults-discovery.test.ts +195 -0
- package/src/lib/rotation-kms-warning-presentation.ts +11 -0
|
@@ -661,6 +661,29 @@ describe('--help never triggers side effects (issue #5581)', () => {
|
|
|
661
661
|
consoleErrorSpy.mockRestore()
|
|
662
662
|
})
|
|
663
663
|
|
|
664
|
+
it('prints usage instead of executing configs restore-defaults when --help is passed', async () => {
|
|
665
|
+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
666
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
667
|
+
const restoreDefaults = jest.fn()
|
|
668
|
+
|
|
669
|
+
registerCliModules([
|
|
670
|
+
{
|
|
671
|
+
id: 'configs',
|
|
672
|
+
cli: [{ command: 'restore-defaults', run: restoreDefaults }],
|
|
673
|
+
} as any,
|
|
674
|
+
])
|
|
675
|
+
|
|
676
|
+
const exitCode = await run(['node', 'mercato', 'configs', 'restore-defaults', '--help'])
|
|
677
|
+
|
|
678
|
+
expect(exitCode).toBe(0)
|
|
679
|
+
expect(restoreDefaults).not.toHaveBeenCalled()
|
|
680
|
+
const printed = consoleLogSpy.mock.calls.map((call) => String(call[0])).join('\n')
|
|
681
|
+
expect(printed).toContain('mercato configs restore-defaults [args]')
|
|
682
|
+
|
|
683
|
+
consoleLogSpy.mockRestore()
|
|
684
|
+
consoleErrorSpy.mockRestore()
|
|
685
|
+
})
|
|
686
|
+
|
|
664
687
|
it('still runs the command when no help flag is present', async () => {
|
|
665
688
|
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
666
689
|
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
@@ -1180,12 +1203,94 @@ describe('init command failure output', () => {
|
|
|
1180
1203
|
)
|
|
1181
1204
|
expect(configsRestoreDefaults).toHaveBeenCalledTimes(expectedRestoreCount)
|
|
1182
1205
|
expect(authSetup).toHaveBeenCalled()
|
|
1206
|
+
if (configsEnabled) {
|
|
1207
|
+
expect(configsRestoreDefaults.mock.invocationCallOrder[0]).toBeLessThan(
|
|
1208
|
+
authSetup.mock.invocationCallOrder[0],
|
|
1209
|
+
)
|
|
1210
|
+
}
|
|
1183
1211
|
expect(queryIndexReindex).toHaveBeenCalledWith(['--force', '--tenant', 'tenant-1'])
|
|
1184
1212
|
|
|
1185
1213
|
consoleErrorSpy.mockRestore()
|
|
1186
1214
|
consoleLogSpy.mockRestore()
|
|
1187
1215
|
})
|
|
1188
1216
|
|
|
1217
|
+
it('aborts init with nonzero exit and never runs auth setup when configs restore-defaults fails', async () => {
|
|
1218
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
1219
|
+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
1220
|
+
|
|
1221
|
+
const configsRestoreDefaults = jest.fn().mockRejectedValue(new Error('strict restore rollback'))
|
|
1222
|
+
const authSetup = jest.fn().mockResolvedValue(undefined)
|
|
1223
|
+
const authSeedRoles = jest.fn().mockResolvedValue(undefined)
|
|
1224
|
+
const entitiesSeedEncryption = jest.fn().mockResolvedValue(undefined)
|
|
1225
|
+
const queryIndexReindex = jest.fn().mockResolvedValue(undefined)
|
|
1226
|
+
|
|
1227
|
+
jest.doMock('child_process', () => ({
|
|
1228
|
+
execSync: jest.fn(),
|
|
1229
|
+
}))
|
|
1230
|
+
jest.doMock('pg', () => ({
|
|
1231
|
+
Client: jest.fn().mockImplementation(() => ({
|
|
1232
|
+
connect: jest.fn().mockResolvedValue(undefined),
|
|
1233
|
+
query: jest.fn().mockResolvedValue({ rows: [] }),
|
|
1234
|
+
end: jest.fn().mockResolvedValue(undefined),
|
|
1235
|
+
})),
|
|
1236
|
+
}))
|
|
1237
|
+
jest.doMock('../lib/generators', () => ({
|
|
1238
|
+
generateEntityIds: jest.fn().mockResolvedValue(undefined),
|
|
1239
|
+
generateModuleRegistries: jest.fn().mockResolvedValue(undefined),
|
|
1240
|
+
generateModuleEntities: jest.fn().mockResolvedValue(undefined),
|
|
1241
|
+
generateModuleDi: jest.fn().mockResolvedValue(undefined),
|
|
1242
|
+
generateModulePackageSources: jest.fn().mockResolvedValue(undefined),
|
|
1243
|
+
generateWebResearchAdapters: jest.fn().mockResolvedValue(undefined),
|
|
1244
|
+
generateOpenApi: jest.fn().mockResolvedValue(undefined),
|
|
1245
|
+
}))
|
|
1246
|
+
jest.doMock('../lib/db', () => ({
|
|
1247
|
+
dbMigrate: jest.fn().mockResolvedValue(undefined),
|
|
1248
|
+
}))
|
|
1249
|
+
jest.doMock('../lib/resolver', () => ({
|
|
1250
|
+
createResolver: () => ({
|
|
1251
|
+
getAppDir: () => '/tmp/test-app',
|
|
1252
|
+
}),
|
|
1253
|
+
}))
|
|
1254
|
+
jest.doMock('@open-mercato/shared/lib/bootstrap/dynamicLoader', () => ({
|
|
1255
|
+
bootstrapFromAppRoot: jest.fn().mockResolvedValue({
|
|
1256
|
+
modules: [
|
|
1257
|
+
{
|
|
1258
|
+
id: 'configs',
|
|
1259
|
+
cli: [{ command: 'restore-defaults', run: configsRestoreDefaults }],
|
|
1260
|
+
},
|
|
1261
|
+
{
|
|
1262
|
+
id: 'auth',
|
|
1263
|
+
cli: [
|
|
1264
|
+
{ command: 'setup', run: authSetup },
|
|
1265
|
+
{ command: 'seed-roles', run: authSeedRoles },
|
|
1266
|
+
],
|
|
1267
|
+
},
|
|
1268
|
+
{
|
|
1269
|
+
id: 'entities',
|
|
1270
|
+
cli: [{ command: 'seed-encryption', run: entitiesSeedEncryption }],
|
|
1271
|
+
},
|
|
1272
|
+
{
|
|
1273
|
+
id: 'query_index',
|
|
1274
|
+
cli: [{ command: 'reindex', run: queryIndexReindex }],
|
|
1275
|
+
},
|
|
1276
|
+
],
|
|
1277
|
+
}),
|
|
1278
|
+
}))
|
|
1279
|
+
|
|
1280
|
+
const mercato = await import('../mercato')
|
|
1281
|
+
const exitCode = await mercato.run(['node', 'mercato', 'init'])
|
|
1282
|
+
|
|
1283
|
+
expect(exitCode).toBe(1)
|
|
1284
|
+
expect(configsRestoreDefaults).toHaveBeenCalledTimes(1)
|
|
1285
|
+
expect(authSetup).not.toHaveBeenCalled()
|
|
1286
|
+
expect(authSeedRoles).not.toHaveBeenCalled()
|
|
1287
|
+
expect(entitiesSeedEncryption).not.toHaveBeenCalled()
|
|
1288
|
+
expect(queryIndexReindex).not.toHaveBeenCalled()
|
|
1289
|
+
|
|
1290
|
+
consoleErrorSpy.mockRestore()
|
|
1291
|
+
consoleLogSpy.mockRestore()
|
|
1292
|
+
})
|
|
1293
|
+
|
|
1189
1294
|
function mockInitDependencies({
|
|
1190
1295
|
authSetup,
|
|
1191
1296
|
}: {
|
package/src/bin.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { isTelemetryBackendEnabled } from '@open-mercato/shared/lib/telemetry/ru
|
|
|
8
8
|
import { installNextSubpathResolveHook } from '@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook'
|
|
9
9
|
import { resolveCliBootstrapMode, type CliBootstrapMode } from './lib/cli-bootstrap-mode.js'
|
|
10
10
|
import { flushBeforeExit } from './lib/flush-before-exit.js'
|
|
11
|
+
import { runWithRotationKmsWarningPresentation } from './lib/rotation-kms-warning-presentation.js'
|
|
11
12
|
// `run` is imported dynamically inside `main()` so telemetry can initialize
|
|
12
13
|
// before the mercato entry (and its Postgres driver) loads — see main().
|
|
13
14
|
|
|
@@ -125,7 +126,7 @@ async function main(): Promise<void> {
|
|
|
125
126
|
process.exit(code ?? 0)
|
|
126
127
|
}
|
|
127
128
|
|
|
128
|
-
main
|
|
129
|
+
runWithRotationKmsWarningPresentation(process.argv, main).catch((error: unknown) => {
|
|
129
130
|
if (error instanceof Error) {
|
|
130
131
|
console.error(error.message)
|
|
131
132
|
} else {
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { runWithRotationKmsWarningPresentation } from '../rotation-kms-warning-presentation'
|
|
2
|
+
import { writeKmsWarning } from '@open-mercato/shared/lib/encryption/kms-warning-presentation'
|
|
3
|
+
const originalEnv = { ...process.env }
|
|
4
|
+
afterEach(() => { process.env = { ...originalEnv }; jest.restoreAllMocks() })
|
|
5
|
+
|
|
6
|
+
test('exact rotation route captures warnings before bootstrap and after environment loads inside main', async () => {
|
|
7
|
+
delete process.env.OM_ROTATION_PROGRESS
|
|
8
|
+
process.env.NO_COLOR = ''
|
|
9
|
+
const output = jest.spyOn(process.stderr, 'write').mockReturnValue(true)
|
|
10
|
+
await runWithRotationKmsWarningPresentation(['node', 'mercato', 'entities', 'rotate-encryption-key'], async () => {
|
|
11
|
+
writeKmsWarning(['normal before env'])
|
|
12
|
+
process.env.OM_ROTATION_PROGRESS = 'json'
|
|
13
|
+
writeKmsWarning(['🚨 bootstrap warning', 'Retain the previous root', 'Source: EXPLICIT_SETTING'])
|
|
14
|
+
await Promise.resolve()
|
|
15
|
+
writeKmsWarning(['handler warning'])
|
|
16
|
+
})
|
|
17
|
+
expect(output.mock.calls[0][0]).toBe('normal before env\n')
|
|
18
|
+
for (const [chunk] of output.mock.calls.slice(1)) expect(JSON.parse(String(chunk))).toMatchObject({ schemaVersion: 1, type: 'phase.changed', runId: 'rotation', phase: 'rotation.kms.warning', rowsDone: '0', rowsTotal: '0', rowsTotalExact: false, bytesDone: '0', chunksDone: 0, at: expect.any(String) })
|
|
19
|
+
expect(JSON.parse(String(output.mock.calls[1][0])).entity).toBe('bootstrap warning\nRetain the previous root\nSource: EXPLICIT_SETTING')
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
test.each([
|
|
23
|
+
['entities', 'rotate-encryption-key-extra'], ['other', 'rotate-encryption-key'], ['entities', 'list'],
|
|
24
|
+
])('unrelated route %s %s retains normal warning even with JSON rotation env', (module, command) => {
|
|
25
|
+
process.env.OM_ROTATION_PROGRESS = 'json'; process.env.NO_COLOR = ''
|
|
26
|
+
const output = jest.spyOn(process.stderr, 'write').mockReturnValue(true)
|
|
27
|
+
runWithRotationKmsWarningPresentation(['node', 'mercato', module, command], () => writeKmsWarning(['visible normal warning']))
|
|
28
|
+
expect(output).toHaveBeenCalledWith('visible normal warning\n')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
// Execute the actual bin entry with a synthetic bootstrap graph, without an app,
|
|
32
|
+
// credentials, driver or network. Warnings fire during env load and bootstrap,
|
|
33
|
+
// before the command handler, so wrapping only run() cannot satisfy this test.
|
|
34
|
+
test.each([['entities', 'rotate-encryption-key', true], ['entities', 'list', false]])('actual bin scopes %s/%s before environment loading and bootstrap', async (module, command, structured) => {
|
|
35
|
+
const fs = await import('node:fs/promises')
|
|
36
|
+
const os = await import('node:os')
|
|
37
|
+
const path = await import('node:path')
|
|
38
|
+
const { spawnSync } = await import('node:child_process')
|
|
39
|
+
const { build } = await import('esbuild')
|
|
40
|
+
const directory = await fs.mkdtemp(path.join(os.tmpdir(), 'om-bin-kms-warning-'))
|
|
41
|
+
try {
|
|
42
|
+
const warningImport = "import { writeKmsWarning } from '@open-mercato/shared/lib/encryption/kms-warning-presentation';"
|
|
43
|
+
const fixtures: Record<string, string> = {
|
|
44
|
+
'@open-mercato/telemetry': 'export const initTelemetry = async () => {}',
|
|
45
|
+
'./lib/dev-supervisor-manifest.js': 'export const canUseLightweightDevSupervisor=()=>false; export const loadDevSupervisorManifest=()=>null; export const registerDevSupervisorManifest=()=>{}',
|
|
46
|
+
'@open-mercato/shared/lib/telemetry/runtime': 'export const isTelemetryBackendEnabled = () => false',
|
|
47
|
+
'@open-mercato/shared/lib/bootstrap/next-subpath-resolve-hook': 'export const installNextSubpathResolveHook = () => {}',
|
|
48
|
+
'./lib/cli-bootstrap-mode.js': "export const resolveCliBootstrapMode = () => 'full'",
|
|
49
|
+
'./lib/flush-before-exit.js': 'export const flushBeforeExit = async () => {}',
|
|
50
|
+
'./lib/resolver.js': 'export const createResolver = () => ({getAppDir: () => "/fixture-app"})',
|
|
51
|
+
'./lib/load-env.js': warningImport + 'export const loadAppEnv = async () => { process.env.OM_ROTATION_PROGRESS="json"; writeKmsWarning(["environment custody warning"]) }',
|
|
52
|
+
'@open-mercato/shared/lib/bootstrap/dynamicLoader': warningImport + 'export const bootstrapFromAppRoot = async () => { writeKmsWarning(["bootstrap custody warning"]); return {modules:[]} }',
|
|
53
|
+
'./mercato.js': warningImport + 'export const registerCliModules = () => {}; export const run = async () => { writeKmsWarning(["handler custody warning"]); return 0 }',
|
|
54
|
+
}
|
|
55
|
+
const output = path.join(directory, 'bin.mjs')
|
|
56
|
+
await build({ entryPoints: [path.resolve(__dirname, '../../bin.ts')], outfile: output, bundle: true, platform: 'node', format: 'esm', logLevel: 'silent', plugins: [{
|
|
57
|
+
name: 'fixture-bootstrap', setup(builder) {
|
|
58
|
+
builder.onResolve({ filter: /.*/ }, args => {
|
|
59
|
+
if (args.path in fixtures) return { path: args.path, namespace: 'fixture' }
|
|
60
|
+
if (args.path === '@open-mercato/shared/lib/encryption/kms-warning-presentation') return { path: path.resolve(__dirname, '../../../../shared/src/lib/encryption/kms-warning-presentation.ts') }
|
|
61
|
+
return undefined
|
|
62
|
+
})
|
|
63
|
+
builder.onLoad({ filter: /.*/, namespace: 'fixture' }, args => ({ contents: fixtures[args.path], loader: 'js' }))
|
|
64
|
+
},
|
|
65
|
+
}] })
|
|
66
|
+
const env = { ...process.env, NO_COLOR: '' }; delete env.OM_ROTATION_PROGRESS
|
|
67
|
+
const child = spawnSync(process.execPath, [output, module, command], { env, encoding: 'utf8' })
|
|
68
|
+
expect(child.status).toBe(0); expect(child.stdout).toBe('')
|
|
69
|
+
const lines = child.stderr.trim().split('\n')
|
|
70
|
+
if (structured) expect(lines.map(line => JSON.parse(line))).toEqual(['environment custody warning', 'bootstrap custody warning', 'handler custody warning'].map(entity => expect.objectContaining({ schemaVersion: 1, type: 'phase.changed', phase: 'rotation.kms.warning', entity })))
|
|
71
|
+
else expect(lines).toEqual(['environment custody warning', 'bootstrap custody warning', 'handler custody warning'])
|
|
72
|
+
} finally { await fs.rm(directory, { recursive: true, force: true }) }
|
|
73
|
+
})
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import type { ModuleEntry, PackageResolver } from '../../resolver'
|
|
5
|
+
import {
|
|
6
|
+
generateModuleRegistry,
|
|
7
|
+
generateModuleRegistryApp,
|
|
8
|
+
generateModuleRegistryCli,
|
|
9
|
+
} from '../module-registry'
|
|
10
|
+
|
|
11
|
+
let fileMtimeNonce = 0
|
|
12
|
+
|
|
13
|
+
function touchFile(filePath: string, content = ''): void {
|
|
14
|
+
fs.mkdirSync(path.dirname(filePath), { recursive: true })
|
|
15
|
+
fs.writeFileSync(filePath, content)
|
|
16
|
+
const mtime = new Date(Date.now() + fileMtimeNonce)
|
|
17
|
+
fileMtimeNonce += 1
|
|
18
|
+
fs.utimesSync(filePath, mtime, mtime)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createMonorepoResolver(tmpDir: string, enabled: ModuleEntry[]): PackageResolver {
|
|
22
|
+
const outputDir = path.join(tmpDir, 'output', 'generated')
|
|
23
|
+
fs.mkdirSync(outputDir, { recursive: true })
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
isMonorepo: () => true,
|
|
27
|
+
getRootDir: () => tmpDir,
|
|
28
|
+
getAppDir: () => path.join(tmpDir, 'app'),
|
|
29
|
+
getOutputDir: () => outputDir,
|
|
30
|
+
getModulesConfigPath: () => path.join(tmpDir, 'app', 'src', 'modules.ts'),
|
|
31
|
+
discoverPackages: () => [],
|
|
32
|
+
loadEnabledModules: () => enabled,
|
|
33
|
+
getModulePaths: (entry: ModuleEntry) => {
|
|
34
|
+
const pkgDir = entry.from === '@open-mercato/search' ? 'search' : 'core'
|
|
35
|
+
return {
|
|
36
|
+
appBase: path.join(tmpDir, 'app', 'src', 'modules', entry.id),
|
|
37
|
+
pkgBase: path.join(tmpDir, 'packages', pkgDir, 'src', 'modules', entry.id),
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
getModuleImportBase: (entry: ModuleEntry) => ({
|
|
41
|
+
appBase: `@/modules/${entry.id}`,
|
|
42
|
+
pkgBase: `${entry.from ?? '@open-mercato/core'}/modules/${entry.id}`,
|
|
43
|
+
}),
|
|
44
|
+
getPackageOutputDir: () => outputDir,
|
|
45
|
+
getPackageRoot: () => path.join(tmpDir, 'packages', 'core'),
|
|
46
|
+
} as unknown as PackageResolver
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function createStandalonePackedResolver(tmpDir: string, enabled: ModuleEntry[]): PackageResolver {
|
|
50
|
+
const outputDir = path.join(tmpDir, '.mercato', 'generated')
|
|
51
|
+
fs.mkdirSync(outputDir, { recursive: true })
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
isMonorepo: () => false,
|
|
55
|
+
getRootDir: () => tmpDir,
|
|
56
|
+
getAppDir: () => tmpDir,
|
|
57
|
+
getOutputDir: () => outputDir,
|
|
58
|
+
getModulesConfigPath: () => path.join(tmpDir, 'src', 'modules.ts'),
|
|
59
|
+
discoverPackages: () => [],
|
|
60
|
+
loadEnabledModules: () => enabled,
|
|
61
|
+
getModulePaths: (entry: ModuleEntry) => ({
|
|
62
|
+
appBase: path.join(tmpDir, 'src', 'modules', entry.id),
|
|
63
|
+
pkgBase: path.join(tmpDir, 'node_modules', entry.from ?? '@open-mercato/core', 'dist', 'modules', entry.id),
|
|
64
|
+
}),
|
|
65
|
+
getModuleImportBase: (entry: ModuleEntry) => ({
|
|
66
|
+
appBase: `@/modules/${entry.id}`,
|
|
67
|
+
pkgBase: `${entry.from ?? '@open-mercato/core'}/modules/${entry.id}`,
|
|
68
|
+
}),
|
|
69
|
+
getPackageOutputDir: () => outputDir,
|
|
70
|
+
getPackageRoot: () => path.join(tmpDir, 'node_modules', '@open-mercato/core'),
|
|
71
|
+
} as unknown as PackageResolver
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
describe('instanceConfigDefaults setup discovery and client-bundle isolation', () => {
|
|
75
|
+
const createdDirs: string[] = []
|
|
76
|
+
|
|
77
|
+
afterEach(() => {
|
|
78
|
+
while (createdDirs.length > 0) {
|
|
79
|
+
const dir = createdDirs.pop()!
|
|
80
|
+
fs.rmSync(dir, { recursive: true, force: true })
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
it('discovers setup.ts for enabled app-local and workspace modules, omits disabled owners, and keeps client/metadata outputs isolated', async () => {
|
|
85
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'instance-defaults-monorepo-'))
|
|
86
|
+
createdDirs.push(tmpDir)
|
|
87
|
+
|
|
88
|
+
touchFile(
|
|
89
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'index.ts'),
|
|
90
|
+
"export const metadata = { id: 'notifications' }\n",
|
|
91
|
+
)
|
|
92
|
+
touchFile(
|
|
93
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'setup.ts'),
|
|
94
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'delivery_strategies', value: { panelPath: '/backend/notifications' } }] }\nexport default setup\n",
|
|
95
|
+
)
|
|
96
|
+
touchFile(
|
|
97
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'backend', 'notifications', 'page.tsx'),
|
|
98
|
+
'export default function NotificationsPage() { return null }\n',
|
|
99
|
+
)
|
|
100
|
+
touchFile(
|
|
101
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'api', 'notifications', 'route.ts'),
|
|
102
|
+
"export const metadata = { GET: { requireAuth: true } }\nexport async function GET() { return new Response('ok') }\n",
|
|
103
|
+
)
|
|
104
|
+
touchFile(
|
|
105
|
+
path.join(tmpDir, 'packages', 'core', 'src', 'modules', 'notifications', 'i18n', 'en.json'),
|
|
106
|
+
JSON.stringify({ notifications: { title: 'Notifications' } }),
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
// Disabled workspace owner (not listed in enabled modules)
|
|
110
|
+
touchFile(
|
|
111
|
+
path.join(tmpDir, 'packages', 'search', 'src', 'modules', 'search', 'index.ts'),
|
|
112
|
+
"export const metadata = { id: 'search' }\n",
|
|
113
|
+
)
|
|
114
|
+
touchFile(
|
|
115
|
+
path.join(tmpDir, 'packages', 'search', 'src', 'modules', 'search', 'setup.ts'),
|
|
116
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'auto_index_enabled', value: true, legacyStorageNamespace: 'vector' }] }\nexport default setup\n",
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
// Enabled app-local owner
|
|
120
|
+
touchFile(
|
|
121
|
+
path.join(tmpDir, 'app', 'src', 'modules', 'custom_defaults', 'index.ts'),
|
|
122
|
+
"export const metadata = { id: 'custom_defaults' }\n",
|
|
123
|
+
)
|
|
124
|
+
touchFile(
|
|
125
|
+
path.join(tmpDir, 'app', 'src', 'modules', 'custom_defaults', 'setup.ts'),
|
|
126
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'feature_flag', value: true }] }\nexport default setup\n",
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const resolver = createMonorepoResolver(tmpDir, [
|
|
130
|
+
{ id: 'notifications', from: '@open-mercato/core' },
|
|
131
|
+
{ id: 'custom_defaults', from: '@app' },
|
|
132
|
+
])
|
|
133
|
+
|
|
134
|
+
await generateModuleRegistry({ resolver, quiet: true })
|
|
135
|
+
await generateModuleRegistryApp({ resolver, quiet: true })
|
|
136
|
+
await generateModuleRegistryCli({ resolver, quiet: true })
|
|
137
|
+
|
|
138
|
+
const outDir = resolver.getOutputDir()
|
|
139
|
+
const serverRegistry = fs.readFileSync(path.join(outDir, 'modules.generated.ts'), 'utf8')
|
|
140
|
+
const bootstrapRegistry = fs.readFileSync(path.join(outDir, 'modules.bootstrap.generated.ts'), 'utf8')
|
|
141
|
+
const cliRegistry = fs.readFileSync(path.join(outDir, 'modules.cli.generated.ts'), 'utf8')
|
|
142
|
+
|
|
143
|
+
for (const content of [serverRegistry, bootstrapRegistry, cliRegistry]) {
|
|
144
|
+
expect(content).toContain('@open-mercato/core/modules/notifications/setup')
|
|
145
|
+
expect(content).toContain('modules/custom_defaults/setup')
|
|
146
|
+
expect(content).toContain('SETUP_custom_defaults_')
|
|
147
|
+
expect(content).not.toContain('modules/search/setup')
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Client and route-metadata generated artifacts must never reach setup.ts providers.
|
|
151
|
+
for (const isolatedArtifact of [
|
|
152
|
+
'api-route-metadata.generated.ts',
|
|
153
|
+
'backend-route-metadata.generated.ts',
|
|
154
|
+
'modules.i18n.generated.ts',
|
|
155
|
+
'dashboard-widgets.generated.ts',
|
|
156
|
+
'injection-widgets.generated.ts',
|
|
157
|
+
'injection-tables.generated.ts',
|
|
158
|
+
'enabled-module-ids.generated.ts',
|
|
159
|
+
]) {
|
|
160
|
+
const artifactPath = path.join(outDir, isolatedArtifact)
|
|
161
|
+
if (!fs.existsSync(artifactPath)) continue
|
|
162
|
+
const artifact = fs.readFileSync(artifactPath, 'utf8')
|
|
163
|
+
expect(artifact).not.toContain('/setup')
|
|
164
|
+
expect(artifact).not.toContain('instanceConfigDefaults')
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('discovers compiled setup.js from packed node_modules packages in standalone apps', async () => {
|
|
169
|
+
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'instance-defaults-packed-'))
|
|
170
|
+
createdDirs.push(tmpDir)
|
|
171
|
+
|
|
172
|
+
touchFile(
|
|
173
|
+
path.join(tmpDir, 'node_modules', '@open-mercato/search', 'dist', 'modules', 'search', 'index.js'),
|
|
174
|
+
"export const metadata = { id: 'search' }\n",
|
|
175
|
+
)
|
|
176
|
+
touchFile(
|
|
177
|
+
path.join(tmpDir, 'node_modules', '@open-mercato/search', 'dist', 'modules', 'search', 'setup.js'),
|
|
178
|
+
"export const setup = { instanceConfigDefaults: () => [{ name: 'auto_index_enabled', value: true, legacyStorageNamespace: 'vector' }] }\nexport default setup\n",
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
const resolver = createStandalonePackedResolver(tmpDir, [
|
|
182
|
+
{ id: 'search', from: '@open-mercato/search' },
|
|
183
|
+
])
|
|
184
|
+
|
|
185
|
+
await generateModuleRegistry({ resolver, quiet: true })
|
|
186
|
+
await generateModuleRegistryCli({ resolver, quiet: true })
|
|
187
|
+
|
|
188
|
+
const outDir = resolver.getOutputDir()
|
|
189
|
+
const serverRegistry = fs.readFileSync(path.join(outDir, 'modules.generated.ts'), 'utf8')
|
|
190
|
+
const cliRegistry = fs.readFileSync(path.join(outDir, 'modules.cli.generated.ts'), 'utf8')
|
|
191
|
+
|
|
192
|
+
expect(serverRegistry).toContain('@open-mercato/search/modules/search/setup')
|
|
193
|
+
expect(cliRegistry).toContain('@open-mercato/search/modules/search/setup')
|
|
194
|
+
})
|
|
195
|
+
})
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { runWithKmsWarningWriter } from '@open-mercato/shared/lib/encryption/kms-warning-presentation'
|
|
2
|
+
|
|
3
|
+
/** Establish presentation before app env loading and bootstrap can activate KMS. */
|
|
4
|
+
export function runWithRotationKmsWarningPresentation<T>(argv: readonly string[], operation: () => T): T {
|
|
5
|
+
if (argv[2] !== 'entities' || argv[3] !== 'rotate-encryption-key') return operation()
|
|
6
|
+
return runWithKmsWarningWriter(lines => {
|
|
7
|
+
// App env may be loaded inside operation; do not decide from entry-time env.
|
|
8
|
+
if (process.env.OM_ROTATION_PROGRESS !== 'json') return false
|
|
9
|
+
process.stderr.write(JSON.stringify({ schemaVersion: 1, type: 'phase.changed', runId: 'rotation', phase: 'rotation.kms.warning', entity: lines.map(line => line.replace(/^\s*🚨\uFE0F?\s*/u, '')).join('\n'), rowsDone: '0', rowsTotal: '0', rowsTotalExact: false, bytesDone: '0', chunksDone: 0, at: new Date().toISOString() }) + '\n')
|
|
10
|
+
}, operation)
|
|
11
|
+
}
|