@open-mercato/cli 0.11.1-develop.8805.1.6357054d1a → 0.11.1-develop.8880.1.3acdbfc734
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 +8 -2
- package/dist/agentic/guides/module-facts.json +1575 -307
- package/dist/agentic/guides/module-facts.v2.json +1575 -307
- package/dist/agentic/guides/modules/agent_orchestrator/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/agent_orchestrator/workers.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/assisted_selling/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/di-registrations-rich.md +2 -1
- package/dist/agentic/guides/modules/auth/di-service-tokens.md +2 -1
- package/dist/agentic/guides/modules/auth/exact-override-targets.md +2 -1
- package/dist/agentic/guides/modules/auth/index.md +2 -2
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +4 -4
- package/dist/agentic/guides/modules/catalog/index.md +2 -2
- package/dist/agentic/guides/modules/catalog/umes-hosts.md +3 -1
- package/dist/agentic/guides/modules/catalog/workers.md +4 -4
- 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/encryption.md +2 -1
- package/dist/agentic/guides/modules/communication_channels/entities.md +1 -0
- package/dist/agentic/guides/modules/communication_channels/events.md +2 -1
- package/dist/agentic/guides/modules/communication_channels/exact-override-targets.md +4 -2
- package/dist/agentic/guides/modules/communication_channels/index.md +3 -3
- package/dist/agentic/guides/modules/communication_channels/umes-hosts.md +2 -0
- package/dist/agentic/guides/modules/communication_channels/workers.md +2 -1
- package/dist/agentic/guides/modules/configs/entities.md +0 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/configs/umes-hosts.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/currencies/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +3 -3
- package/dist/agentic/guides/modules/customer_accounts/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/umes-hosts.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customer_groups/umes-hosts.md +1 -1
- package/dist/agentic/guides/modules/customers/acl-features.md +2 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +12 -12
- package/dist/agentic/guides/modules/customers/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/customers/domain-commands.md +1 -1
- package/dist/agentic/guides/modules/customers/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/customers/index.md +1 -1
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +3 -3
- package/dist/agentic/guides/modules/dashboards/index.md +1 -1
- package/dist/agentic/guides/modules/data_sync/active-extension-bindings.md +3 -3
- 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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/devices/index.md +1 -1
- package/dist/agentic/guides/modules/devices/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/active-extension-bindings.md +2 -2
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/active-extension-bindings.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/ecommerce/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/entities/active-extension-bindings.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/active-extension-bindings.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/active-extension-bindings.md +3 -3
- 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/ledger/index.md +2 -2
- package/dist/agentic/guides/modules/ledger/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/maintenance/contribution-resolutions.md +11 -0
- package/dist/agentic/guides/modules/maintenance/events.md +14 -0
- package/dist/agentic/guides/modules/maintenance/exact-override-targets.md +11 -0
- package/dist/agentic/guides/modules/maintenance/index.md +17 -0
- package/dist/agentic/guides/modules/maintenance/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/maintenance/umes-contributions.md +11 -0
- package/dist/agentic/guides/modules/maintenance/umes-hosts.md +14 -0
- 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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/exact-override-targets.md +3 -3
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/setup.md +1 -1
- package/dist/agentic/guides/modules/perspectives/active-extension-bindings.md +2 -2
- 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/phone_calls/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/planner/active-extension-bindings.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/domain-commands.md +1 -0
- package/dist/agentic/guides/modules/promotions/index.md +2 -2
- package/dist/agentic/guides/modules/promotions/umes-hosts.md +2 -0
- package/dist/agentic/guides/modules/push_notifications/index.md +2 -2
- package/dist/agentic/guides/modules/push_notifications/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/query_index/active-extension-bindings.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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/sales/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/sales/index.md +1 -1
- package/dist/agentic/guides/modules/sales/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/acl-features.md +12 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/entities.md +12 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/exact-override-targets.md +13 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/index.md +17 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/setup.md +11 -0
- package/dist/agentic/guides/modules/sales_invoices_gl_posting/umes-hosts.md +12 -0
- 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/active-extension-bindings.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/sync_excel/umes-hosts.md +1 -0
- 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/active-extension-bindings.md +2 -2
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/upgrade_actions/cli-commands.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/entities.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/upgrade_actions/index.md +5 -2
- package/dist/agentic/guides/modules/upgrade_actions/umes-hosts.md +11 -0
- 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/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/wms/exact-override-targets.md +2 -2
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/wms/setup.md +1 -1
- package/dist/agentic/guides/modules/workflows/domain-commands.md +3 -0
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/umes-hosts.md +2 -0
- package/dist/agentic/guides/production-deployment.md +6 -0
- package/dist/agentic/guides/reference-module-facts.json +12 -13
- package/dist/agentic/guides/reference-modules/example/index.md +1 -1
- package/dist/agentic/guides/reference-modules/example/umes-hosts.md +1 -1
- package/dist/agentic/guides/upstream/AGENTS.md +2 -3
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +18 -9
- package/dist/agentic/guides/upstream/manifest.json +3 -3
- package/dist/agentic/shared/AGENTS.md.template +1 -1
- package/dist/agentic/shared/ai/harness/cases.json +7 -7
- package/dist/lib/generators/module-extension-facts.js +5 -6
- package/dist/lib/generators/module-extension-facts.js.map +2 -2
- package/dist/lib/generators/module-registry.js +28 -0
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/testing/ephemeral-database-guard.js +89 -0
- package/dist/lib/testing/ephemeral-database-guard.js.map +7 -0
- package/dist/lib/testing/integration.js +4 -0
- package/dist/lib/testing/integration.js.map +2 -2
- package/dist/mercato.js +26 -3
- package/dist/mercato.js.map +2 -2
- package/package.json +7 -7
- package/src/__tests__/init-ephemeral-database.test.ts +112 -0
- package/src/__tests__/mercato.test.ts +15 -0
- package/src/lib/__tests__/modules-config.test.ts +1 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +18 -0
- package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +2 -1
- package/src/lib/generators/__tests__/module-registry-requires-enforcement.test.ts +18 -0
- package/src/lib/generators/__tests__/registry-variant-parity.test.ts +95 -19
- package/src/lib/generators/module-extension-facts.ts +5 -10
- package/src/lib/generators/module-registry.ts +44 -0
- package/src/lib/testing/__tests__/ephemeral-database-guard.test.ts +88 -0
- package/src/lib/testing/ephemeral-database-guard.ts +105 -0
- package/src/lib/testing/integration.ts +4 -0
- package/src/mercato.ts +26 -3
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.8880.1.3acdbfc734",
|
|
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.8880.1.3acdbfc734",
|
|
64
|
+
"@open-mercato/queue": "0.11.1-develop.8880.1.3acdbfc734",
|
|
65
|
+
"@open-mercato/shared": "0.11.1-develop.8880.1.3acdbfc734",
|
|
66
|
+
"@open-mercato/telemetry": "0.11.1-develop.8880.1.3acdbfc734",
|
|
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.8880.1.3acdbfc734"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.11.1-develop.8880.1.3acdbfc734",
|
|
82
82
|
"@types/jest": "^30.0.0",
|
|
83
83
|
"jest": "^30.4.2",
|
|
84
84
|
"ts-jest": "^29.4.12"
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
|
3
|
+
import os from 'node:os'
|
|
4
|
+
import path from 'node:path'
|
|
5
|
+
|
|
6
|
+
describe('guarded init uses the effective child database before mutation', () => {
|
|
7
|
+
const ownedUrl = 'postgresql://owned:private-test-value@127.0.0.1:6543/owned_fixture'
|
|
8
|
+
const marker = 'open-mercato-ephemeral:38ee43df-19e4-444e-b5c5-8e56b55c9d0c'
|
|
9
|
+
const originalDatabaseUrl = process.env.DATABASE_URL
|
|
10
|
+
const originalNodeEnv = process.env.NODE_ENV
|
|
11
|
+
const originalRedisUrl = process.env.REDIS_URL
|
|
12
|
+
const originalInitFlow = process.env.OM_INIT_FLOW
|
|
13
|
+
const originalReinstall = process.env.OM_INIT_REINSTALL
|
|
14
|
+
const originalSuperadminPassword = process.env.OM_INIT_SUPERADMIN_PASSWORD
|
|
15
|
+
let directory: string
|
|
16
|
+
let proofPath: string
|
|
17
|
+
const query = jest.fn()
|
|
18
|
+
const connect = jest.fn()
|
|
19
|
+
const end = jest.fn()
|
|
20
|
+
const clientConstructor = jest.fn()
|
|
21
|
+
const generatorBoundary = jest.fn()
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
jest.resetModules()
|
|
25
|
+
jest.restoreAllMocks()
|
|
26
|
+
directory = mkdtempSync(path.join(os.tmpdir(), 'init-owned-database-'))
|
|
27
|
+
proofPath = path.join(directory, 'guard.json')
|
|
28
|
+
writeFileSync(proofPath, JSON.stringify({ version: 1, databaseName: 'owned_fixture', connectionDigest: createHash('sha256').update('postgresql://owned@127.0.0.1:6543/owned_fixture').digest('hex'), ownershipMarker: marker }), { mode: 0o600 })
|
|
29
|
+
process.env.NODE_ENV = 'production'
|
|
30
|
+
process.env.DATABASE_URL = ownedUrl
|
|
31
|
+
process.env.REDIS_URL = ''
|
|
32
|
+
process.env.OM_INIT_SUPERADMIN_PASSWORD = 'Guard-Test-Password-2026!'
|
|
33
|
+
connect.mockReset().mockResolvedValue(undefined)
|
|
34
|
+
end.mockReset().mockResolvedValue(undefined)
|
|
35
|
+
query.mockReset().mockResolvedValue({ rows: [{ database_name: 'owned_fixture', ownership_marker: 'not-owned' }] })
|
|
36
|
+
clientConstructor.mockReset().mockImplementation(() => ({ connect, query, end }))
|
|
37
|
+
jest.doMock('pg', () => ({ Client: clientConstructor }))
|
|
38
|
+
jest.doMock('../lib/resolver', () => ({ createResolver: () => ({ getAppDir: () => directory }) }))
|
|
39
|
+
generatorBoundary.mockReset().mockRejectedValue(new Error('[internal] Test boundary prevents initialization writes.'))
|
|
40
|
+
jest.doMock('../lib/generators', () => ({ generateEntityIds: generatorBoundary }))
|
|
41
|
+
jest.doMock('../lib/db', () => ({ dbMigrate: jest.fn().mockRejectedValue(new Error('[internal] Test boundary prevents database migrations.')) }))
|
|
42
|
+
jest.spyOn(console, 'log').mockImplementation(() => undefined)
|
|
43
|
+
jest.spyOn(console, 'error').mockImplementation(() => undefined)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
afterEach(() => {
|
|
47
|
+
jest.dontMock('pg')
|
|
48
|
+
jest.dontMock('../lib/resolver')
|
|
49
|
+
jest.dontMock('../lib/generators')
|
|
50
|
+
jest.dontMock('../lib/db')
|
|
51
|
+
jest.dontMock('ioredis')
|
|
52
|
+
jest.restoreAllMocks()
|
|
53
|
+
rmSync(directory, { recursive: true, force: true })
|
|
54
|
+
if (originalDatabaseUrl === undefined) delete process.env.DATABASE_URL
|
|
55
|
+
else process.env.DATABASE_URL = originalDatabaseUrl
|
|
56
|
+
for (const [key, value] of Object.entries({ NODE_ENV: originalNodeEnv, REDIS_URL: originalRedisUrl, OM_INIT_FLOW: originalInitFlow, OM_INIT_REINSTALL: originalReinstall, OM_INIT_SUPERADMIN_PASSWORD: originalSuperadminPassword })) {
|
|
57
|
+
if (value === undefined) delete process.env[key]
|
|
58
|
+
else process.env[key] = value
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it.each([undefined, 'postgresql://control:other-test-value@127.0.0.1:6544/control_fixture'])('refuses stripped or replaced effective database configuration: %s', async (databaseUrl) => {
|
|
63
|
+
if (databaseUrl === undefined) delete process.env.DATABASE_URL
|
|
64
|
+
else process.env.DATABASE_URL = databaseUrl
|
|
65
|
+
const { run } = await import('../mercato')
|
|
66
|
+
await expect(run(['node', 'mercato', 'init', '--reinstall', `--ephemeral-database-guard=${proofPath}`])).resolves.toBe(1)
|
|
67
|
+
expect(clientConstructor).not.toHaveBeenCalled()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('refuses the fallback loaded through the normal app dotenv path before any connection', async () => {
|
|
71
|
+
delete process.env.DATABASE_URL
|
|
72
|
+
writeFileSync(path.join(directory, '.env'), 'DATABASE_URL=postgresql://control:other-test-value@127.0.0.1:6544/control_fixture\n')
|
|
73
|
+
const { run } = await import('../mercato')
|
|
74
|
+
await expect(run(['node', 'mercato', 'init', '--reinstall', `--ephemeral-database-guard=${proofPath}`])).resolves.toBe(1)
|
|
75
|
+
expect(clientConstructor).not.toHaveBeenCalled()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('checks the actual connected ownership marker and never drops on a mismatch', async () => {
|
|
79
|
+
const { run } = await import('../mercato')
|
|
80
|
+
await expect(run(['node', 'mercato', 'init', '--reinstall', `--ephemeral-database-guard=${proofPath}`])).resolves.toBe(1)
|
|
81
|
+
expect(connect).toHaveBeenCalledTimes(1)
|
|
82
|
+
expect(end).toHaveBeenCalledTimes(1)
|
|
83
|
+
expect(query.mock.calls).toHaveLength(1)
|
|
84
|
+
expect(query.mock.calls[0][0]).toMatch(/^SELECT current_database\(\)/)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('rechecks ownership on the connection that would perform DROP', async () => {
|
|
88
|
+
query.mockResolvedValueOnce({ rows: [{ database_name: 'owned_fixture', ownership_marker: marker }] })
|
|
89
|
+
const { run } = await import('../mercato')
|
|
90
|
+
await expect(run(['node', 'mercato', 'init', '--reinstall', `--ephemeral-database-guard=${proofPath}`])).resolves.toBe(1)
|
|
91
|
+
expect(clientConstructor).toHaveBeenCalledTimes(2)
|
|
92
|
+
expect(end).toHaveBeenCalledTimes(2)
|
|
93
|
+
expect(query.mock.calls).toHaveLength(2)
|
|
94
|
+
expect(query.mock.calls.every(([statement]) => String(statement).startsWith('SELECT'))).toBe(true)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('does not flush an unowned Redis service after verifying the disposable database', async () => {
|
|
98
|
+
process.env.REDIS_URL = 'redis://127.0.0.1:6533/0'
|
|
99
|
+
const redisConstructor = jest.fn()
|
|
100
|
+
jest.doMock('ioredis', () => ({ default: redisConstructor }))
|
|
101
|
+
query.mockImplementation(async (statement: string) => ({
|
|
102
|
+
rows: statement.startsWith('SELECT current_database')
|
|
103
|
+
? [{ database_name: 'owned_fixture', ownership_marker: marker }]
|
|
104
|
+
: [],
|
|
105
|
+
}))
|
|
106
|
+
const { run } = await import('../mercato')
|
|
107
|
+
await expect(run(['node', 'mercato', 'init', '--reinstall', `--ephemeral-database-guard=${proofPath}`])).resolves.toBe(1)
|
|
108
|
+
expect(generatorBoundary).toHaveBeenCalledTimes(1)
|
|
109
|
+
expect(redisConstructor).not.toHaveBeenCalled()
|
|
110
|
+
expect(clientConstructor).toHaveBeenCalledTimes(2)
|
|
111
|
+
})
|
|
112
|
+
})
|
|
@@ -734,6 +734,20 @@ describe('--help never triggers side effects (issue #5581)', () => {
|
|
|
734
734
|
consoleErrorSpy.mockRestore()
|
|
735
735
|
})
|
|
736
736
|
|
|
737
|
+
it('reports that maintenance requires Enterprise and leaves global help available', async () => {
|
|
738
|
+
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation()
|
|
739
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation()
|
|
740
|
+
try {
|
|
741
|
+
registerCliModules([])
|
|
742
|
+
expect(await run(['node', 'mercato', '--help'])).toBe(0)
|
|
743
|
+
expect(await run(['node', 'mercato', 'maintenance', 'status'])).toBe(1)
|
|
744
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(expect.stringContaining('OM_ENABLE_ENTERPRISE_MODULES=true'))
|
|
745
|
+
} finally {
|
|
746
|
+
consoleLogSpy.mockRestore()
|
|
747
|
+
consoleErrorSpy.mockRestore()
|
|
748
|
+
}
|
|
749
|
+
})
|
|
750
|
+
|
|
737
751
|
it.each(['constructor', 'toString', 'valueOf', 'hasOwnProperty', '__proto__'])(
|
|
738
752
|
'reports %s as an unknown module instead of matching an inherited prototype key',
|
|
739
753
|
async (inheritedKey) => {
|
|
@@ -1286,6 +1300,7 @@ describe('init command failure output', () => {
|
|
|
1286
1300
|
const exitCode = await mercato.run(['node', 'mercato', 'init'])
|
|
1287
1301
|
|
|
1288
1302
|
expect(exitCode).toBe(1)
|
|
1303
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith('❌ Initialization failed:', 'strict restore rollback')
|
|
1289
1304
|
expect(configsRestoreDefaults).toHaveBeenCalledTimes(1)
|
|
1290
1305
|
expect(authSetup).not.toHaveBeenCalled()
|
|
1291
1306
|
expect(authSeedRoles).not.toHaveBeenCalled()
|
|
@@ -273,6 +273,7 @@ describe('modules-config', () => {
|
|
|
273
273
|
{ id: 'storage_s3', from: '@open-mercato/storage-s3', flag: /OM_ENABLE_STORAGE_S3=true/ },
|
|
274
274
|
{ id: 'record_locks', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES=true/ },
|
|
275
275
|
{ id: 'system_status_overlays', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES=true/ },
|
|
276
|
+
{ id: 'maintenance', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES=true/ },
|
|
276
277
|
{ id: 'sso', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES_SSO=true/ },
|
|
277
278
|
{ id: 'security', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES_SECURITY=true/ },
|
|
278
279
|
{ id: 'agent_orchestrator', from: '@open-mercato/enterprise', flag: /OM_ENABLE_ENTERPRISE_MODULES_AGENTS=true/ },
|
|
@@ -27,6 +27,24 @@ describe('module extension facts', () => {
|
|
|
27
27
|
fs.rmSync(moduleRoot, { recursive: true, force: true })
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
+
it('keeps the API entity host when a custom route migrates to the registry', () => {
|
|
31
|
+
write(moduleRoot, 'api/settings/route.ts', `
|
|
32
|
+
const RESOURCE_KIND = 'alpha.settings'
|
|
33
|
+
export async function PUT(req) {
|
|
34
|
+
await runRouteMutationGuards({ container, req, auth, input: { resourceKind: RESOURCE_KIND, operation: 'update' } })
|
|
35
|
+
}
|
|
36
|
+
`)
|
|
37
|
+
const facts = extractModuleExtensionFacts({
|
|
38
|
+
moduleId: 'alpha', moduleRoot, sourceRoot: 'src/modules/alpha',
|
|
39
|
+
entities: [], events: [], apiRoutes: [], searchEntities: [],
|
|
40
|
+
})
|
|
41
|
+
expect(facts.hosts).toContainEqual(expect.objectContaining({
|
|
42
|
+
id: 'alpha.settings',
|
|
43
|
+
capabilities: expect.arrayContaining(['mutation-guard']),
|
|
44
|
+
source: expect.objectContaining({ symbol: 'alpha.settings', path: expect.stringContaining('api/settings/route.ts') }),
|
|
45
|
+
}))
|
|
46
|
+
})
|
|
47
|
+
|
|
30
48
|
it('expands declared host families and preserves fact references and browser transports', () => {
|
|
31
49
|
write(moduleRoot, 'extension-points.ts', `
|
|
32
50
|
import { defineModuleExtensionPoints, dataTableExtensionHost, crudFormExtensionHost, injectionExtensionHost } from 'x'
|
|
@@ -43,7 +43,8 @@ describe('module-facts customers fixture (T1 anti-drift guard)', () => {
|
|
|
43
43
|
// share your OWN conversation, so the existing `customers.*` admin wildcard
|
|
44
44
|
// grants no escalation).
|
|
45
45
|
expect(facts.events).toHaveLength(51)
|
|
46
|
-
expect(facts.aclFeatures).toHaveLength(
|
|
46
|
+
expect(facts.aclFeatures).toHaveLength(23)
|
|
47
|
+
expect(facts.aclFeatures).toContain('sales.reopen')
|
|
47
48
|
expect(facts.searchEntities).toEqual([
|
|
48
49
|
'customers:customer_person_profile',
|
|
49
50
|
'customers:customer_company_profile',
|
|
@@ -97,6 +97,24 @@ describe('module registry enforces metadata.requires', () => {
|
|
|
97
97
|
exitSpy.mockRestore()
|
|
98
98
|
})
|
|
99
99
|
|
|
100
|
+
it('generates the ecommerce registry with both optional customer modules disabled', async () => {
|
|
101
|
+
const ecommerceModule = path.resolve(__dirname, '../../../../../core/src/modules/ecommerce/index.ts')
|
|
102
|
+
touchFile(pkgModulePath('ecommerce', 'index.ts'), fs.readFileSync(ecommerceModule, 'utf8'))
|
|
103
|
+
for (const id of ['catalog', 'sales', 'customer_accounts', 'customer_groups']) {
|
|
104
|
+
touchFile(pkgModulePath(id, 'index.ts'), `export const metadata = { name: '${id}' }\n`)
|
|
105
|
+
}
|
|
106
|
+
const resolver = createMockResolver(
|
|
107
|
+
['ecommerce', 'catalog', 'sales'].map((id) => ({ id, from: '@open-mercato/core' })),
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
const result = await generateModuleRegistry({ resolver, quiet: true })
|
|
111
|
+
const registry = fs.readFileSync(path.join(outputDir, 'modules.generated.ts'), 'utf8')
|
|
112
|
+
|
|
113
|
+
expect(result.errors).toEqual([])
|
|
114
|
+
expect(registry).toContain('@open-mercato/core/modules/ecommerce')
|
|
115
|
+
expect(registry).not.toMatch(/customer_accounts|customer_groups/)
|
|
116
|
+
})
|
|
117
|
+
|
|
100
118
|
it('generates cleanly once the declared dependency is enabled', async () => {
|
|
101
119
|
scaffoldDependentFixture()
|
|
102
120
|
const resolver = createMockResolver([
|
|
@@ -17,7 +17,7 @@ import path from 'node:path'
|
|
|
17
17
|
import os from 'node:os'
|
|
18
18
|
import ts from 'typescript-js'
|
|
19
19
|
import type { PackageResolver, ModuleEntry } from '../../resolver'
|
|
20
|
-
import { generateModuleRegistry, generateModuleRegistryApp, generateModuleRegistryCli } from '../module-registry'
|
|
20
|
+
import { generateModuleRegistries, generateModuleRegistry, generateModuleRegistryApp, generateModuleRegistryCli } from '../module-registry'
|
|
21
21
|
|
|
22
22
|
/** Properties both registry variants must agree on, per module. */
|
|
23
23
|
const SHARED_PROPERTIES = [
|
|
@@ -35,10 +35,19 @@ const SHARED_PROPERTIES = [
|
|
|
35
35
|
'setup',
|
|
36
36
|
'runtime',
|
|
37
37
|
'defaultEncryptionMaps',
|
|
38
|
+
'upgradeActions',
|
|
38
39
|
'integrations',
|
|
39
40
|
'bundles',
|
|
40
41
|
] as const
|
|
41
42
|
|
|
43
|
+
const SERVER_REGISTRY_FILES = [
|
|
44
|
+
'modules.generated.ts',
|
|
45
|
+
'modules.runtime.generated.ts',
|
|
46
|
+
'modules.app.generated.ts',
|
|
47
|
+
'modules.bootstrap.generated.ts',
|
|
48
|
+
'modules.cli.generated.ts',
|
|
49
|
+
]
|
|
50
|
+
|
|
42
51
|
let tmpDir: string
|
|
43
52
|
let outputDir: string
|
|
44
53
|
let fileMtimeNonce = 0
|
|
@@ -55,22 +64,28 @@ function pkgModulePath(modId: string, ...segments: string[]): string {
|
|
|
55
64
|
return path.join(tmpDir, 'packages', 'core', 'src', 'modules', modId, ...segments)
|
|
56
65
|
}
|
|
57
66
|
|
|
58
|
-
function
|
|
67
|
+
function appModulePath(modId: string, ...segments: string[]): string {
|
|
68
|
+
return path.join(tmpDir, 'app', 'src', 'modules', modId, ...segments)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function createMockResolver(enabled: ModuleEntry[], generatedDir = outputDir): PackageResolver {
|
|
72
|
+
const getPackageName = (entry: ModuleEntry): string =>
|
|
73
|
+
entry.from?.startsWith('@open-mercato/') ? entry.from : '@open-mercato/core'
|
|
59
74
|
return {
|
|
60
75
|
isMonorepo: () => true,
|
|
61
76
|
getRootDir: () => tmpDir,
|
|
62
77
|
getAppDir: () => path.join(tmpDir, 'app'),
|
|
63
|
-
getOutputDir: () =>
|
|
78
|
+
getOutputDir: () => generatedDir,
|
|
64
79
|
getModulesConfigPath: () => path.join(tmpDir, 'app', 'src', 'modules.ts'),
|
|
65
80
|
discoverPackages: () => [],
|
|
66
81
|
loadEnabledModules: () => enabled,
|
|
67
82
|
getModulePaths: (entry: ModuleEntry) => ({
|
|
68
83
|
appBase: path.join(tmpDir, 'app', 'src', 'modules', entry.id),
|
|
69
|
-
pkgBase: path.join(tmpDir, 'packages', '
|
|
84
|
+
pkgBase: path.join(tmpDir, 'packages', getPackageName(entry).slice('@open-mercato/'.length), 'src', 'modules', entry.id),
|
|
70
85
|
}),
|
|
71
86
|
getModuleImportBase: (entry: ModuleEntry) => ({
|
|
72
87
|
appBase: `@/modules/${entry.id}`,
|
|
73
|
-
pkgBase:
|
|
88
|
+
pkgBase: `${getPackageName(entry)}/modules/${entry.id}`,
|
|
74
89
|
}),
|
|
75
90
|
getPackageOutputDir: () => outputDir,
|
|
76
91
|
getPackageRoot: () => path.join(tmpDir, 'packages', 'core'),
|
|
@@ -118,17 +133,36 @@ function scaffoldFixture(): ModuleEntry[] {
|
|
|
118
133
|
touchFile(pkgModulePath('orders', 'ce.ts'), "export const entities = [{ id: 'orders:custom', fields: [{ id: 'note', kind: 'text' }] }]\n")
|
|
119
134
|
touchFile(pkgModulePath('orders', 'i18n', 'en.json'), JSON.stringify({ orders: { title: 'Orders' } }))
|
|
120
135
|
touchFile(pkgModulePath('orders', 'cli.ts'), 'export default { command: "orders", run: async () => {} }\n')
|
|
136
|
+
touchFile(
|
|
137
|
+
pkgModulePath('orders', 'upgrades.ts'),
|
|
138
|
+
"import action from './upgrades/0.1.0-backfill'\nexport const upgradeActions = [action]\nexport default upgradeActions\n",
|
|
139
|
+
)
|
|
140
|
+
touchFile(
|
|
141
|
+
pkgModulePath('orders', 'upgrades', '0.1.0-backfill.ts'),
|
|
142
|
+
"export default { id: 'orders.backfill', version: '0.1.0', messageKey: 'm', ctaKey: 'c', successKey: 's', run: async () => {} }\n",
|
|
143
|
+
)
|
|
144
|
+
touchFile(appModulePath('shop', 'index.ts'), "export const metadata = { id: 'shop', label: 'Shop' }\n")
|
|
145
|
+
touchFile(
|
|
146
|
+
appModulePath('shop', 'upgrades.ts'),
|
|
147
|
+
"export const upgradeActions = [{ id: 'shop.seed', version: '0.1.0', messageKey: 'm', ctaKey: 'c', successKey: 's', run: async () => {} }]\n",
|
|
148
|
+
)
|
|
121
149
|
|
|
122
150
|
touchFile(pkgModulePath('bare', 'index.ts'), "export const metadata = { id: 'bare', label: 'Bare' }\n")
|
|
151
|
+
touchFile(
|
|
152
|
+
path.join(tmpDir, 'packages', 'upgrade-actions', 'src', 'modules', 'upgrade_actions', 'index.ts'),
|
|
153
|
+
"export const metadata = { id: 'upgrade_actions', label: 'Upgrade actions' }\n",
|
|
154
|
+
)
|
|
123
155
|
|
|
124
156
|
return [
|
|
125
157
|
{ id: 'orders', from: '@open-mercato/core' },
|
|
126
158
|
{ id: 'bare', from: '@open-mercato/core' },
|
|
159
|
+
{ id: 'shop', from: '@app' },
|
|
160
|
+
{ id: 'upgrade_actions', from: '@open-mercato/upgrade-actions' },
|
|
127
161
|
]
|
|
128
162
|
}
|
|
129
163
|
|
|
130
|
-
function readGenerated(fileName: string): string {
|
|
131
|
-
const filePath = path.join(
|
|
164
|
+
function readGenerated(fileName: string, generatedDir = outputDir): string {
|
|
165
|
+
const filePath = path.join(generatedDir, fileName)
|
|
132
166
|
if (!fs.existsSync(filePath)) throw new Error(`Expected generated file not found: ${fileName}`)
|
|
133
167
|
return fs.readFileSync(filePath, 'utf8')
|
|
134
168
|
}
|
|
@@ -183,6 +217,7 @@ function restrictTo(names: Set<string>, allowed: readonly string[]): string[] {
|
|
|
183
217
|
}
|
|
184
218
|
|
|
185
219
|
describe('module registry variant parity', () => {
|
|
220
|
+
let enabledModules: ModuleEntry[]
|
|
186
221
|
let mainVariant: Map<string, Set<string>>
|
|
187
222
|
let runtimeVariant: Map<string, Set<string>>
|
|
188
223
|
let appVariant: Map<string, Set<string>>
|
|
@@ -192,7 +227,8 @@ describe('module registry variant parity', () => {
|
|
|
192
227
|
outputDir = path.join(tmpDir, 'app', '.mercato', 'generated')
|
|
193
228
|
fs.mkdirSync(outputDir, { recursive: true })
|
|
194
229
|
|
|
195
|
-
|
|
230
|
+
enabledModules = scaffoldFixture()
|
|
231
|
+
const resolver = createMockResolver(enabledModules)
|
|
196
232
|
const mainResult = await generateModuleRegistry({ resolver, quiet: true })
|
|
197
233
|
const appResult = await generateModuleRegistryApp({ resolver, quiet: true })
|
|
198
234
|
const cliResult = await generateModuleRegistryCli({ resolver, quiet: true })
|
|
@@ -214,7 +250,7 @@ describe('module registry variant parity', () => {
|
|
|
214
250
|
|
|
215
251
|
it('discovers the same module ids in every variant', () => {
|
|
216
252
|
const ids = [...mainVariant.keys()].sort()
|
|
217
|
-
expect(ids).toEqual(['bare', 'orders'])
|
|
253
|
+
expect(ids).toEqual(['bare', 'orders', 'shop', 'upgrade_actions'])
|
|
218
254
|
expect([...runtimeVariant.keys()].sort()).toEqual(ids)
|
|
219
255
|
expect([...appVariant.keys()].sort()).toEqual(ids)
|
|
220
256
|
})
|
|
@@ -247,20 +283,12 @@ describe('module registry variant parity', () => {
|
|
|
247
283
|
// reads the app and bootstrap registries. A convention file that reaches only some of them is a
|
|
248
284
|
// runtime that starts in some processes and not others, with nothing to say so.
|
|
249
285
|
it('emits the module runtime in every registry a process can read', () => {
|
|
250
|
-
const
|
|
251
|
-
'modules.generated.ts',
|
|
252
|
-
'modules.runtime.generated.ts',
|
|
253
|
-
'modules.app.generated.ts',
|
|
254
|
-
'modules.bootstrap.generated.ts',
|
|
255
|
-
'modules.cli.generated.ts',
|
|
256
|
-
]
|
|
257
|
-
|
|
258
|
-
const carriesRuntime = registryFiles.map((fileName) => {
|
|
286
|
+
const carriesRuntime = SERVER_REGISTRY_FILES.map((fileName) => {
|
|
259
287
|
const byId = parseModulePropertiesById(readGenerated(fileName), fileName)
|
|
260
288
|
return [fileName, byId.get('orders')?.has('runtime'), byId.get('bare')?.has('runtime')]
|
|
261
289
|
})
|
|
262
290
|
|
|
263
|
-
expect(carriesRuntime).toEqual(
|
|
291
|
+
expect(carriesRuntime).toEqual(SERVER_REGISTRY_FILES.map((fileName) => [fileName, true, false]))
|
|
264
292
|
})
|
|
265
293
|
|
|
266
294
|
// The IIFE `namespaceFallback` emits narrows `unknown` to `{}`. That satisfies `setup`, whose
|
|
@@ -279,6 +307,54 @@ describe('module registry variant parity', () => {
|
|
|
279
307
|
}
|
|
280
308
|
})
|
|
281
309
|
|
|
310
|
+
it('emits module-owned upgrade actions in every server registry when the consumer is registered', () => {
|
|
311
|
+
const carriesUpgradeActions = SERVER_REGISTRY_FILES.map((fileName) => {
|
|
312
|
+
const byId = parseModulePropertiesById(readGenerated(fileName), fileName)
|
|
313
|
+
return [
|
|
314
|
+
fileName,
|
|
315
|
+
byId.get('orders')?.has('upgradeActions'),
|
|
316
|
+
byId.get('shop')?.has('upgradeActions'),
|
|
317
|
+
byId.get('bare')?.has('upgradeActions'),
|
|
318
|
+
]
|
|
319
|
+
})
|
|
320
|
+
|
|
321
|
+
expect(carriesUpgradeActions).toEqual(SERVER_REGISTRY_FILES.map((fileName) => [fileName, true, true, false]))
|
|
322
|
+
expect(readGenerated('modules.cli.generated.ts')).toMatch(/import \* as UPGRADES_orders from ["']@open-mercato\/core\/modules\/orders\/upgrades["']/)
|
|
323
|
+
expect(readGenerated('modules.cli.generated.ts')).toMatch(/import \* as UPGRADES_shop from ["'][./]*\/?.*modules\/shop\/upgrades["']/)
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
it('omits upgrade action registrations and imports when the installed consumer is disabled', async () => {
|
|
327
|
+
const disabledOutputDir = path.join(path.dirname(outputDir), 'disabled-generated')
|
|
328
|
+
fs.cpSync(outputDir, disabledOutputDir, { recursive: true })
|
|
329
|
+
const resolver = createMockResolver(enabledModules.filter((entry) => entry.id !== 'upgrade_actions'), disabledOutputDir)
|
|
330
|
+
const results = await generateModuleRegistries({ resolver, quiet: true })
|
|
331
|
+
expect(results.map((result) => result.errors)).toEqual([[], [], []])
|
|
332
|
+
|
|
333
|
+
for (const fileName of SERVER_REGISTRY_FILES) {
|
|
334
|
+
const content = readGenerated(fileName, disabledOutputDir)
|
|
335
|
+
const byId = parseModulePropertiesById(content, fileName)
|
|
336
|
+
expect(byId.get('orders')?.has('upgradeActions')).toBe(false)
|
|
337
|
+
expect(byId.get('shop')?.has('upgradeActions')).toBe(false)
|
|
338
|
+
expect(byId.has('upgrade_actions')).toBe(false)
|
|
339
|
+
expect(content).not.toMatch(/UPGRADES_|@open-mercato\/upgrade-actions/)
|
|
340
|
+
}
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
it('keeps upgrade action handlers out of client, route-manifest and i18n artifacts', () => {
|
|
344
|
+
const serverRegistries = new Set(SERVER_REGISTRY_FILES)
|
|
345
|
+
const leaking = fs
|
|
346
|
+
.readdirSync(outputDir)
|
|
347
|
+
.filter((fileName) => fileName.endsWith('.ts') && !serverRegistries.has(fileName))
|
|
348
|
+
.filter((fileName) => /modules\/(orders|shop)\/upgrades/.test(fs.readFileSync(path.join(outputDir, fileName), 'utf8')))
|
|
349
|
+
expect(leaking).toEqual([])
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it('does not renumber existing convention imports when a module adds upgrades.ts', () => {
|
|
353
|
+
const content = readGenerated('modules.app.generated.ts')
|
|
354
|
+
expect(content).toContain('UPGRADES_orders')
|
|
355
|
+
expect(content).not.toMatch(/UPGRADES_orders_\d/)
|
|
356
|
+
})
|
|
357
|
+
|
|
282
358
|
describe('known, intentional divergences', () => {
|
|
283
359
|
it('only the main variant carries eager api handlers and the cli entry point', () => {
|
|
284
360
|
expect(mainVariant.get('orders')!.has('apis')).toBe(true)
|
|
@@ -847,16 +847,11 @@ function apiExtensionHostIds(moduleId: string, moduleRoot: string): ApiExtension
|
|
|
847
847
|
}
|
|
848
848
|
}
|
|
849
849
|
}
|
|
850
|
-
if (
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
const input = node.arguments[1] ? staticValue(node.arguments[1], context) : undefined
|
|
856
|
-
const entityId = isStaticObject(input) ? stringValue(input.resourceKind) : undefined
|
|
857
|
-
if (entityId) {
|
|
858
|
-
entityIds.add(entityId)
|
|
859
|
-
if (!entitySourceFiles[entityId]) entitySourceFiles[entityId] = filePath
|
|
850
|
+
if (ts.isCallExpression(node)) {
|
|
851
|
+
const bridge = readMutationGuardBridge(node, context)
|
|
852
|
+
if (bridge) {
|
|
853
|
+
entityIds.add(bridge.entityId)
|
|
854
|
+
if (!entitySourceFiles[bridge.entityId]) entitySourceFiles[bridge.entityId] = filePath
|
|
860
855
|
}
|
|
861
856
|
}
|
|
862
857
|
node.forEachChild(visit)
|
|
@@ -102,6 +102,7 @@ export interface ModuleRegistryOptions {
|
|
|
102
102
|
interface ModuleRegistryDiscovery {
|
|
103
103
|
enabled: ModuleEntry[]
|
|
104
104
|
modules: ModuleRegistryDiscoveryEntry[]
|
|
105
|
+
hasUpgradeActionsModule: boolean
|
|
105
106
|
identities: ReturnType<typeof getEnabledModuleIdentities>
|
|
106
107
|
getStructureChecksum: () => string
|
|
107
108
|
getCrudFormSections: () => ReturnType<typeof prepareCrudFormSectionRegistries>
|
|
@@ -2230,6 +2231,7 @@ async function createModuleRegistryDiscovery(
|
|
|
2230
2231
|
return {
|
|
2231
2232
|
enabled,
|
|
2232
2233
|
modules,
|
|
2234
|
+
hasUpgradeActionsModule: enabled.some((entry) => entry.id === 'upgrade_actions'),
|
|
2233
2235
|
identities,
|
|
2234
2236
|
getStructureChecksum: () => structureChecksum ??= calculateStructureChecksum(Array.from(trackedRoots)),
|
|
2235
2237
|
getCrudFormSections,
|
|
@@ -3717,6 +3719,27 @@ function resolveConventionFile(
|
|
|
3717
3719
|
return { importName, importPath, fromApp: resolved.fromApp }
|
|
3718
3720
|
}
|
|
3719
3721
|
|
|
3722
|
+
function resolveUpgradeActionsFile(
|
|
3723
|
+
resolved: ResolvedFile | null,
|
|
3724
|
+
modId: string,
|
|
3725
|
+
importTargets: string[][],
|
|
3726
|
+
): string | null {
|
|
3727
|
+
if (!resolved) return null
|
|
3728
|
+
const importName = `UPGRADES_${toVar(modId)}`
|
|
3729
|
+
const statement = buildImportStatement(`* as ${importName}`, sanitizeGeneratedModuleSpecifier(resolved.importPath))
|
|
3730
|
+
for (const target of importTargets) target.push(statement)
|
|
3731
|
+
return importName
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
function buildUpgradeActionsValue(importName: string): WriterFunction {
|
|
3735
|
+
return namespaceFallback({
|
|
3736
|
+
importName,
|
|
3737
|
+
members: ['default', 'upgradeActions'],
|
|
3738
|
+
fallback: emptyArray(),
|
|
3739
|
+
castType: "import('@open-mercato/shared/modules/upgrade-actions').UpgradeActionDefinition[]",
|
|
3740
|
+
})
|
|
3741
|
+
}
|
|
3742
|
+
|
|
3720
3743
|
type ModuleRegistryRenderOptions = ModuleRegistryOptions & {
|
|
3721
3744
|
discovery: ModuleRegistryDiscovery
|
|
3722
3745
|
skipCommands?: boolean
|
|
@@ -3974,6 +3997,10 @@ async function generateModuleRegistryFromDiscovery(options: ModuleRegistryRender
|
|
|
3974
3997
|
if (encryption) encryptionImportName = encryption.importName
|
|
3975
3998
|
}
|
|
3976
3999
|
|
|
4000
|
+
const upgradeActionsImportName = discovery.hasUpgradeActionsModule
|
|
4001
|
+
? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports, runtimeImports])
|
|
4002
|
+
: null
|
|
4003
|
+
|
|
3977
4004
|
// 11b. Integration manifest: integration.ts
|
|
3978
4005
|
{
|
|
3979
4006
|
const resolved = discovered.resolve('integration.ts')
|
|
@@ -4191,6 +4218,9 @@ async function generateModuleRegistryFromDiscovery(options: ModuleRegistryRender
|
|
|
4191
4218
|
}),
|
|
4192
4219
|
})
|
|
4193
4220
|
}
|
|
4221
|
+
if (upgradeActionsImportName) {
|
|
4222
|
+
setupAndBeyondEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
|
|
4223
|
+
}
|
|
4194
4224
|
if (integrationExports) {
|
|
4195
4225
|
setupAndBeyondEntries.push({
|
|
4196
4226
|
name: 'integrations',
|
|
@@ -4585,6 +4615,10 @@ async function generateModuleRegistryAppFromDiscovery(options: ModuleRegistryRen
|
|
|
4585
4615
|
if (encryption) encryptionImportName = encryption.importName
|
|
4586
4616
|
}
|
|
4587
4617
|
|
|
4618
|
+
const upgradeActionsImportName = discovery.hasUpgradeActionsModule
|
|
4619
|
+
? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports, bootstrapImports])
|
|
4620
|
+
: null
|
|
4621
|
+
|
|
4588
4622
|
{
|
|
4589
4623
|
const resolved = discovered.resolve('integration.ts')
|
|
4590
4624
|
if (resolved) {
|
|
@@ -4792,6 +4826,9 @@ async function generateModuleRegistryAppFromDiscovery(options: ModuleRegistryRen
|
|
|
4792
4826
|
}),
|
|
4793
4827
|
})
|
|
4794
4828
|
}
|
|
4829
|
+
if (upgradeActionsImportName) {
|
|
4830
|
+
moduleEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
|
|
4831
|
+
}
|
|
4795
4832
|
if (integrationImportName) {
|
|
4796
4833
|
moduleEntries.push({
|
|
4797
4834
|
name: 'integrations',
|
|
@@ -4982,6 +5019,10 @@ async function generateModuleRegistryCliFromDiscovery(options: ModuleRegistryRen
|
|
|
4982
5019
|
if (encryption) encryptionImportName = encryption.importName
|
|
4983
5020
|
}
|
|
4984
5021
|
|
|
5022
|
+
const upgradeActionsImportName = discovery.hasUpgradeActionsModule
|
|
5023
|
+
? resolveUpgradeActionsFile(discovered.resolve('upgrades.ts'), modId, [imports])
|
|
5024
|
+
: null
|
|
5025
|
+
|
|
4985
5026
|
// Integration manifest: integration.ts
|
|
4986
5027
|
{
|
|
4987
5028
|
const resolved = discovered.resolve('integration.ts')
|
|
@@ -5167,6 +5208,9 @@ async function generateModuleRegistryCliFromDiscovery(options: ModuleRegistryRen
|
|
|
5167
5208
|
}),
|
|
5168
5209
|
})
|
|
5169
5210
|
}
|
|
5211
|
+
if (upgradeActionsImportName) {
|
|
5212
|
+
moduleEntries.push({ name: 'upgradeActions', value: buildUpgradeActionsValue(upgradeActionsImportName) })
|
|
5213
|
+
}
|
|
5170
5214
|
if (integrationImportName) {
|
|
5171
5215
|
moduleEntries.push({
|
|
5172
5216
|
name: 'integrations',
|