@open-mercato/cli 0.11.1-develop.8784.1.e9d95a72f5 → 0.11.1-develop.8843.1.b02f9b125d
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/AGENTS.md +2 -0
- package/dist/agentic/guides/architecture.md +1 -0
- package/dist/agentic/guides/module-facts.json +2453 -1146
- package/dist/agentic/guides/module-facts.v2.json +2453 -1146
- 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/ai_assistant/owned-contract-module-metadata.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/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/auth/owned-contract-module-metadata.md +1 -1
- 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/cart/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +11 -8
- package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -5
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +11 -8
- package/dist/agentic/guides/modules/catalog/index.md +2 -2
- package/dist/agentic/guides/modules/catalog/owned-contract-module-metadata.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_gmail/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/owned-contract-module-metadata.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/exact-override-targets.md +2 -2
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/workers.md +2 -2
- package/dist/agentic/guides/modules/configs/acl-features.md +2 -1
- package/dist/agentic/guides/modules/configs/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/configs/entities.md +0 -1
- package/dist/agentic/guides/modules/configs/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/configs/host-extension-points.md +10 -0
- package/dist/agentic/guides/modules/configs/index.md +5 -3
- package/dist/agentic/guides/modules/configs/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/configs/setup.md +1 -1
- package/dist/agentic/guides/modules/configs/umes-diagnostics.md +9 -0
- package/dist/agentic/guides/modules/configs/umes-hosts.md +9 -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/active-extension-bindings.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/acl-features.md +2 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -0
- package/dist/agentic/guides/modules/customers/contribution-resolutions.md +2 -0
- package/dist/agentic/guides/modules/customers/di-registrations-rich.md +8 -5
- package/dist/agentic/guides/modules/customers/domain-commands.md +1 -1
- package/dist/agentic/guides/modules/customers/exact-override-targets.md +11 -5
- package/dist/agentic/guides/modules/customers/index.md +5 -5
- package/dist/agentic/guides/modules/customers/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/customers/umes-contributions.md +2 -0
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -10
- package/dist/agentic/guides/modules/dashboards/contribution-resolutions.md +0 -10
- package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +0 -10
- package/dist/agentic/guides/modules/dashboards/index.md +5 -5
- package/dist/agentic/guides/modules/dashboards/umes-contributions.md +0 -10
- 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/devices/owned-contract-module-metadata.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/ecommerce/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/entities/owned-contract-module-metadata.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/events/owned-contract-module-metadata.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/integrations/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/ledger/index.md +1 -1
- 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/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/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/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/active-extension-bindings.md +8 -0
- package/dist/agentic/guides/modules/sales/contribution-resolutions.md +8 -0
- package/dist/agentic/guides/modules/sales/di-registrations-rich.md +31 -30
- package/dist/agentic/guides/modules/sales/di-service-tokens.md +5 -5
- package/dist/agentic/guides/modules/sales/exact-override-targets.md +39 -30
- package/dist/agentic/guides/modules/sales/index.md +5 -5
- package/dist/agentic/guides/modules/sales/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/sales/umes-contributions.md +8 -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/search/owned-contract-module-metadata.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/active-extension-bindings.md +2 -1
- package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -0
- package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/staff/index.md +8 -8
- package/dist/agentic/guides/modules/staff/umes-contributions.md +1 -0
- 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/upgrade_actions/cli-commands.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/contribution-resolutions.md +12 -0
- package/dist/agentic/guides/modules/upgrade_actions/entities.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/exact-override-targets.md +12 -0
- package/dist/agentic/guides/modules/upgrade_actions/index.md +18 -0
- package/dist/agentic/guides/modules/upgrade_actions/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/upgrade_actions/umes-contributions.md +12 -0
- 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/index.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/production-deployment.md +6 -0
- package/dist/agentic/guides/reference-module-facts.json +1 -1
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +17 -9
- package/dist/agentic/guides/upstream/manifest.json +2 -2
- package/dist/agentic/shared/AGENTS.md.template +1 -1
- package/dist/agentic/shared/ai/harness/cases.json +7 -7
- package/dist/lib/generators/extensions/dashboard-widgets.js +46 -4
- package/dist/lib/generators/extensions/dashboard-widgets.js.map +2 -2
- package/dist/lib/generators/extensions/workflows.js +25 -2
- package/dist/lib/generators/extensions/workflows.js.map +2 -2
- package/dist/lib/generators/module-facts.js +2 -0
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-registry.js +35 -6
- package/dist/lib/generators/module-registry.js.map +2 -2
- package/dist/lib/module-coupling/analyze.js +391 -0
- package/dist/lib/module-coupling/analyze.js.map +7 -0
- package/dist/lib/module-diagnostics.js +160 -0
- package/dist/lib/module-diagnostics.js.map +7 -0
- package/dist/lib/module-index.js +103 -0
- package/dist/lib/module-index.js.map +7 -0
- 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-discovery.js +20 -15
- package/dist/lib/testing/integration-discovery.js.map +3 -3
- package/dist/mercato.js +45 -5
- 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/__tests__/rotation-json-output.test.ts +13 -0
- package/src/lib/__tests__/module-diagnostics.test.ts +207 -0
- package/src/lib/__tests__/modules-config.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.customers.fixture.test.ts +2 -1
- package/src/lib/generators/__tests__/module-facts.owned-contracts.test.ts +2 -2
- package/src/lib/generators/__tests__/module-registry-requires-enforcement.test.ts +18 -0
- package/src/lib/generators/__tests__/output-snapshots.test.ts +19 -0
- package/src/lib/generators/__tests__/registry-variant-parity.test.ts +95 -19
- package/src/lib/generators/__tests__/structural-contracts.test.ts +18 -0
- package/src/lib/generators/extensions/dashboard-widgets.ts +49 -3
- package/src/lib/generators/extensions/workflows.ts +26 -2
- package/src/lib/generators/module-facts.ts +2 -0
- package/src/lib/generators/module-registry.ts +55 -7
- package/src/lib/module-coupling/analyze.ts +464 -0
- package/src/lib/module-diagnostics.ts +182 -0
- package/src/lib/module-index.ts +133 -0
- package/src/lib/testing/__tests__/ephemeral-database-guard.test.ts +88 -0
- package/src/lib/testing/__tests__/integration-discovery.test.ts +26 -2
- package/src/lib/testing/ephemeral-database-guard.ts +105 -0
- package/src/lib/testing/integration-discovery.ts +19 -11
- package/src/mercato.ts +47 -5
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.8843.1.b02f9b125d",
|
|
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.8843.1.b02f9b125d",
|
|
64
|
+
"@open-mercato/queue": "0.11.1-develop.8843.1.b02f9b125d",
|
|
65
|
+
"@open-mercato/shared": "0.11.1-develop.8843.1.b02f9b125d",
|
|
66
|
+
"@open-mercato/telemetry": "0.11.1-develop.8843.1.b02f9b125d",
|
|
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.8843.1.b02f9b125d"
|
|
79
79
|
},
|
|
80
80
|
"devDependencies": {
|
|
81
|
-
"@open-mercato/shared": "0.11.1-develop.
|
|
81
|
+
"@open-mercato/shared": "0.11.1-develop.8843.1.b02f9b125d",
|
|
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()
|
|
@@ -32,6 +32,19 @@ describe('rotation dispatcher JSON progress', () => {
|
|
|
32
32
|
expect(stdout.mock.calls.flat().join('\n')).toContain('Running entities:rotate-encryption-key')
|
|
33
33
|
})
|
|
34
34
|
|
|
35
|
+
it('prints a readable lock refusal for operators', async () => {
|
|
36
|
+
delete process.env.OM_ROTATION_PROGRESS
|
|
37
|
+
const message = 'ROTATION_RUN_LOCKED:1ca9d863-bee9-4f54-aac8-e8ab42163ccb'
|
|
38
|
+
registerCliModules([{
|
|
39
|
+
id: 'entities',
|
|
40
|
+
cli: [{ command: 'rotate-encryption-key', run: async () => { throw new Error(`[internal] ${message}`) } }],
|
|
41
|
+
} as Module])
|
|
42
|
+
jest.spyOn(console, 'log').mockImplementation()
|
|
43
|
+
const humanError = jest.spyOn(console, 'error').mockImplementation()
|
|
44
|
+
expect(await run(['node', 'mercato', 'entities', 'rotate-encryption-key'])).toBe(1)
|
|
45
|
+
expect(humanError).toHaveBeenCalledWith(`💥 Failed: ${message}`)
|
|
46
|
+
})
|
|
47
|
+
|
|
35
48
|
it.each([
|
|
36
49
|
['entities', 'rotate-encryption-key', undefined],
|
|
37
50
|
['entities', 'rotate-encryption-key', 'plain'],
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import { analyzeModuleCoupling } from '../module-coupling/analyze'
|
|
5
|
+
import { runModuleDiagnostics } from '../module-diagnostics'
|
|
6
|
+
import { buildModuleIndex, inactiveModuleDependencies, missingModuleRequirements, resolveIndexedModule, type IndexedModule } from '../module-index'
|
|
7
|
+
import { createResolver } from '../resolver'
|
|
8
|
+
|
|
9
|
+
let root: string
|
|
10
|
+
|
|
11
|
+
function fixture(file: string, contents: string): void {
|
|
12
|
+
const target = path.join(root, file)
|
|
13
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
14
|
+
fs.writeFileSync(target, contents)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function moduleSource(module: string, suffix: string, contents: string): void {
|
|
18
|
+
fixture(`src/modules/${module}/${suffix}`, contents)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function register(...ids: string[]): void {
|
|
22
|
+
fixture('src/modules.ts', `export const enabledModules = [${ids.map((id) => `{ id: '${id}', from: '@app' }`).join(', ')}]`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function descriptor(id: string, other = ''): void {
|
|
26
|
+
moduleSource(id, 'index.ts', `export const metadata = { name: '${id}'${other ? `, ${other}` : ''} }`)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'module-diagnostics-'))
|
|
31
|
+
fixture('package.json', '{"name":"fixture","version":"1.0.0"}')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.restoreAllMocks()
|
|
36
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('indexes local and packaged module declarations and reports transitive inactive hard dependencies', () => {
|
|
40
|
+
register('first')
|
|
41
|
+
descriptor('first', "requires: ['second'], optionalRequires: ['addon']")
|
|
42
|
+
descriptor('second', "requires: ['third']")
|
|
43
|
+
descriptor('third', "requires: ['first']")
|
|
44
|
+
fixture('node_modules/@open-mercato/core/package.json', '{"name":"@open-mercato/core","version":"2.0.0"}')
|
|
45
|
+
fixture('node_modules/@open-mercato/core/dist/modules/addon/index.js',
|
|
46
|
+
"exports.metadata = { name: 'addon', requires: ['third'], optionalRequires: ['first'] }")
|
|
47
|
+
|
|
48
|
+
const index = buildModuleIndex(createResolver(root))
|
|
49
|
+
expect(index.find((module) => module.id === 'addon')).toMatchObject({
|
|
50
|
+
packageName: '@open-mercato/core', version: '2.0.0', enabled: false, requires: ['third'], optionalRequires: ['first'],
|
|
51
|
+
})
|
|
52
|
+
const first = index.find((module) => module.id === 'first')!
|
|
53
|
+
expect(missingModuleRequirements(first, index)).toEqual([
|
|
54
|
+
{ requirement: 'second', path: ['first', 'second'] },
|
|
55
|
+
{ requirement: 'third', path: ['first', 'second', 'third'] },
|
|
56
|
+
])
|
|
57
|
+
expect(inactiveModuleDependencies(index)).toEqual([{ source: first, target: 'addon' }])
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('checks import, route and DI ownership, optional guards, and integration declarations from source', () => {
|
|
61
|
+
register('core_user', 'provider')
|
|
62
|
+
descriptor('core_user', "optionalRequires: ['provider']")
|
|
63
|
+
descriptor('provider')
|
|
64
|
+
descriptor('unrelated', "requires: ['core_user']")
|
|
65
|
+
moduleSource('core_user', 'i18n/en.json', '{"core_user.optionalRequires.provider":"Provider sync"}')
|
|
66
|
+
moduleSource('provider', 'api/read/route.ts', "export const metadata = { path: '/custom/endpoint' }; export const GET = () => null")
|
|
67
|
+
moduleSource('provider', 'di.ts',
|
|
68
|
+
'export const register = (container) => container.register({ providerService: asFunction(createService) })')
|
|
69
|
+
moduleSource('core_user', 'service.ts', [
|
|
70
|
+
"import type { PrivateShape } from '../unrelated/contract'",
|
|
71
|
+
"export async function list() { return fetch('/api/custom/endpoint') }",
|
|
72
|
+
"export async function useOther() { return import('../unrelated/runtime') }",
|
|
73
|
+
].join('\n'))
|
|
74
|
+
moduleSource('core_user', 'guarded.ts',
|
|
75
|
+
"export function guarded(container) { try { return container.resolve('providerService') } catch { return null } }")
|
|
76
|
+
moduleSource('core_user', '__integration__/TC-TEST-001.spec.ts', "test('provider', () => fetch('/api/custom/endpoint'))")
|
|
77
|
+
moduleSource('core_user', '__integration__/TC-TEST-002.spec.ts',
|
|
78
|
+
"export const meta = { dependsOnModules: ['provider'] }; test('provider', () => fetch('/api/custom/endpoint'))")
|
|
79
|
+
|
|
80
|
+
moduleSource('core_user', '__integration__/nested/meta.ts',
|
|
81
|
+
"export const meta = { requiredModules: ['provider'] }")
|
|
82
|
+
moduleSource('core_user', '__integration__/nested/TC-TEST-003.spec.ts',
|
|
83
|
+
"test('provider', () => fetch('/api/custom/endpoint'))")
|
|
84
|
+
moduleSource('core_user', '__integration__/TC-TEST-004.meta.ts',
|
|
85
|
+
"export const meta = { requiresModules: ['provider'] }")
|
|
86
|
+
moduleSource('core_user', '__integration__/TC-TEST-004.spec.ts',
|
|
87
|
+
"test('provider', () => fetch('/api/custom/endpoint'))")
|
|
88
|
+
moduleSource('core_user', '__integration__/helpers/provider.ts',
|
|
89
|
+
"export const read = () => fetch('/api/custom/endpoint')")
|
|
90
|
+
moduleSource('core_user', '__integration__/TC-TEST-005.spec.ts',
|
|
91
|
+
"export const meta = { optionalModules: ['provider'] }; test('provider', () => fetch('/api/custom/endpoint'))")
|
|
92
|
+
|
|
93
|
+
const facts = analyzeModuleCoupling(buildModuleIndex(createResolver(root)))
|
|
94
|
+
expect(facts.findings.map(({ rule, target, kind }) => ({ rule, target, kind }))).toEqual([
|
|
95
|
+
{ rule: 'R4', target: 'provider', kind: 'api-path' },
|
|
96
|
+
{ rule: 'R2', target: 'provider', kind: 'api-path' },
|
|
97
|
+
{ rule: 'R1', target: 'unrelated', kind: 'import' },
|
|
98
|
+
{ rule: 'R5', target: 'unrelated', kind: 'import' },
|
|
99
|
+
])
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('exempts kernel references from declaration rules but detects reverse edges from non-kernel modules', () => {
|
|
103
|
+
register('auth', 'directory', 'plugin')
|
|
104
|
+
descriptor('auth', "requires: ['directory', 'plugin']")
|
|
105
|
+
descriptor('directory')
|
|
106
|
+
descriptor('plugin')
|
|
107
|
+
moduleSource('directory', 'runtime.ts', "export const internal = () => import('../auth/index')")
|
|
108
|
+
moduleSource('plugin', 'runtime.ts', "export const internal = () => import('../auth/index')")
|
|
109
|
+
moduleSource('plugin', '__integration__/TC-TEST-003.spec.ts', "test('kernel', () => import('../auth/index'))")
|
|
110
|
+
|
|
111
|
+
const facts = analyzeModuleCoupling(buildModuleIndex(createResolver(root)))
|
|
112
|
+
expect(facts.findings.map(({ rule, module, target }) => ({ rule, module, target }))).toEqual([
|
|
113
|
+
{ rule: 'R5', module: 'plugin', target: 'auth' },
|
|
114
|
+
])
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('prints all six doctor groups, supports JSON, and only blocks optional drift in strict mode', () => {
|
|
118
|
+
register('auth', 'directory', 'reader')
|
|
119
|
+
descriptor('auth')
|
|
120
|
+
descriptor('directory')
|
|
121
|
+
descriptor('reader', "requires: ['missing'], optionalRequires: ['addon']")
|
|
122
|
+
descriptor('addon')
|
|
123
|
+
descriptor('peer')
|
|
124
|
+
moduleSource('reader', 'i18n/en.json', '{"reader.optionalRequires.addon":"Optional export"}')
|
|
125
|
+
moduleSource('reader', 'references.ts',
|
|
126
|
+
"export async function peers() { await import('../peer/index'); await fetch('/api/not-found') }")
|
|
127
|
+
moduleSource('reader', 'extension-points.ts',
|
|
128
|
+
"export const extensionPoints = defineModuleExtensionPoints({ moduleId: 'reader', hosts: { index: injectionExtensionHost({ family: 'generic', spotId: 'reader:host', supported: ['render-widget'], source: 'references.ts', minContributions: 1 }) } })")
|
|
129
|
+
const output = jest.spyOn(console, 'log').mockImplementation(() => {})
|
|
130
|
+
const resolver = createResolver(root)
|
|
131
|
+
expect(runModuleDiagnostics('doctor', ['--json'], resolver)).toBe(1)
|
|
132
|
+
const doctor = JSON.parse(output.mock.calls.at(-1)?.[0] ?? '{}')
|
|
133
|
+
expect(doctor).toMatchObject({ version: 1, enabled: ['auth', 'directory', 'reader'] })
|
|
134
|
+
expect(doctor.findings.map((finding: { group: string }) => finding.group)).toEqual([
|
|
135
|
+
'missing-kernel', 'missing-hard', 'inactive-optional', 'undeclared-or-upstream', 'missing-contributions', 'dangling',
|
|
136
|
+
])
|
|
137
|
+
expect(doctor.findings[2].message).toContain('Optional export')
|
|
138
|
+
|
|
139
|
+
expect(runModuleDiagnostics('list', ['--all', '--json'], resolver)).toBe(0)
|
|
140
|
+
const modules = JSON.parse(output.mock.calls.at(-1)?.[0] ?? '{}')
|
|
141
|
+
expect(modules.modules).toEqual(expect.arrayContaining([
|
|
142
|
+
expect.objectContaining({ id: 'addon', enabled: false }),
|
|
143
|
+
expect.objectContaining({ id: 'reader', requires: ['missing'], optionalRequires: ['addon'] }),
|
|
144
|
+
]))
|
|
145
|
+
|
|
146
|
+
register('auth', 'directory', 'api_keys', 'reader')
|
|
147
|
+
descriptor('api_keys')
|
|
148
|
+
descriptor('reader', "optionalRequires: ['addon']")
|
|
149
|
+
expect(runModuleDiagnostics('doctor', [], resolver)).toBe(0)
|
|
150
|
+
expect(runModuleDiagnostics('doctor', ['--strict'], resolver)).toBe(1)
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('recognizes an InboxOps action contribution without accepting other module imports', () => {
|
|
154
|
+
register('reader', 'inbox_ops')
|
|
155
|
+
descriptor('reader')
|
|
156
|
+
descriptor('inbox_ops')
|
|
157
|
+
moduleSource('reader', 'inbox-actions.ts', "import { helper } from '../inbox_ops/helpers'; export default [helper]")
|
|
158
|
+
moduleSource('reader', 'runtime.ts', "import '../inbox_ops/helpers'")
|
|
159
|
+
moduleSource('inbox_ops', 'helpers.ts', 'export const helper = {}')
|
|
160
|
+
|
|
161
|
+
const report = analyzeModuleCoupling(buildModuleIndex(createResolver(root)))
|
|
162
|
+
expect(report.findings).toEqual([expect.objectContaining({
|
|
163
|
+
rule: 'R1', module: 'reader', target: 'inbox_ops', file: expect.stringContaining('runtime.ts'),
|
|
164
|
+
})])
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
it('keeps a package-qualified requirement bound to its intended provider', () => {
|
|
168
|
+
const base = { id: 'provider', version: '1.0.0', roots: [], requires: [], optionalRequires: [] }
|
|
169
|
+
const enabled: IndexedModule = { ...base, packageName: '@example/alternate', locators: ['@example/alternate'], enabled: true }
|
|
170
|
+
const installed: IndexedModule = { ...base, packageName: '@example/provider', locators: ['@example/provider'], enabled: false }
|
|
171
|
+
const entries = [enabled, installed]
|
|
172
|
+
expect(resolveIndexedModule('@example/provider', entries)).toBe(installed)
|
|
173
|
+
expect(resolveIndexedModule('provider', entries)).toBe(enabled)
|
|
174
|
+
expect(missingModuleRequirements({ ...enabled, id: 'reader', requires: ['@example/provider'] }, entries))
|
|
175
|
+
.toEqual([{ requirement: '@example/provider', path: ['reader', 'provider'] }])
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('reads the feature ID in a hasFeature call', () => {
|
|
179
|
+
register('reader', 'provider')
|
|
180
|
+
descriptor('reader')
|
|
181
|
+
descriptor('provider')
|
|
182
|
+
moduleSource('provider', 'acl.ts', "export const features = [{ id: 'provider.view', title: 'View', module: 'provider' }]")
|
|
183
|
+
moduleSource('reader', 'runtime.ts', "export const canView = (grants) => hasFeature(grants, 'provider.view')")
|
|
184
|
+
const report = analyzeModuleCoupling(buildModuleIndex(createResolver(root)))
|
|
185
|
+
expect(report.findings).toEqual([expect.objectContaining({
|
|
186
|
+
rule: 'R1', module: 'reader', target: 'provider', kind: 'feature',
|
|
187
|
+
})])
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
it('does not count a widget whose required module is absent', () => {
|
|
191
|
+
register('reader', 'provider')
|
|
192
|
+
descriptor('reader')
|
|
193
|
+
descriptor('provider')
|
|
194
|
+
descriptor('addon')
|
|
195
|
+
moduleSource('reader', 'extension-points.ts',
|
|
196
|
+
"export const extensionPoints = defineModuleExtensionPoints({ moduleId: 'reader', hosts: { index: injectionExtensionHost({ family: 'generic', spotId: 'reader:host', supported: ['render-widget'], source: 'references.ts', minContributions: 1 }) } })")
|
|
197
|
+
moduleSource('provider', 'widgets/injection-table.ts',
|
|
198
|
+
"export const injectionTable = { 'reader:host': ['provider.widget'] }")
|
|
199
|
+
moduleSource('provider', 'widgets/injection/example/widget.ts',
|
|
200
|
+
"export default { metadata: { id: 'provider.widget', requiredModules: ['addon'] } }")
|
|
201
|
+
const resolver = createResolver(root)
|
|
202
|
+
expect(analyzeModuleCoupling(buildModuleIndex(resolver)).contributions)
|
|
203
|
+
.toEqual([expect.objectContaining({ count: 0, minimum: 1, spotId: 'reader:host' })])
|
|
204
|
+
|
|
205
|
+
register('reader', 'provider', 'addon')
|
|
206
|
+
expect(analyzeModuleCoupling(buildModuleIndex(resolver)).contributions).toEqual([])
|
|
207
|
+
})
|
|
@@ -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/ },
|
|
@@ -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',
|
|
@@ -31,7 +31,7 @@ describe('module-facts owned contracts + provenance (Spec 1)', () => {
|
|
|
31
31
|
writeFixture(
|
|
32
32
|
moduleRoot,
|
|
33
33
|
'index.ts',
|
|
34
|
-
"export const metadata = { name: 'facts', title: 'Facts', version: '1.2.3', requires: ['auth', 'catalog'], ejectable: true }\n",
|
|
34
|
+
"export const metadata = { name: 'facts', title: 'Facts', version: '1.2.3', requires: ['auth', 'catalog'], optionalRequires: ['customers'], ejectable: true }\n",
|
|
35
35
|
)
|
|
36
36
|
writeFixture(
|
|
37
37
|
moduleRoot,
|
|
@@ -213,7 +213,7 @@ describe('module-facts owned contracts + provenance (Spec 1)', () => {
|
|
|
213
213
|
it('extracts module-metadata owned contract with only safe scalar fields', () => {
|
|
214
214
|
const fact = ownedById(facts, 'module-metadata', 'facts')
|
|
215
215
|
expect(fact).toBeDefined()
|
|
216
|
-
expect(fact?.metadata).toEqual({ name: 'facts', version: '1.2.3', requires: ['auth', 'catalog'], ejectable: true })
|
|
216
|
+
expect(fact?.metadata).toEqual({ name: 'facts', version: '1.2.3', requires: ['auth', 'catalog'], optionalRequires: ['customers'], ejectable: true })
|
|
217
217
|
expect(fact?.source.sourcePath).toBe('node_modules/@open-mercato/example/src/modules/facts/index.ts')
|
|
218
218
|
})
|
|
219
219
|
|
|
@@ -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([
|
|
@@ -671,6 +671,25 @@ function captureGeneratedFiles(): Map<string, string> {
|
|
|
671
671
|
}
|
|
672
672
|
|
|
673
673
|
describe('generator output compatibility', () => {
|
|
674
|
+
it('only imports the validating workflow registrar when the engine is enabled', async () => {
|
|
675
|
+
const workflowEngine = { id: 'workflows', from: '@open-mercato/core' }
|
|
676
|
+
touchFile(pkgModulePath('workflows', 'index.ts'), "export const metadata = { name: 'workflows' }\n")
|
|
677
|
+
touchFile(
|
|
678
|
+
pkgModulePath('workflows', 'lib', 'code-registry.ts'),
|
|
679
|
+
'export function registerCodeWorkflows(_workflows: unknown[]) {}\n',
|
|
680
|
+
)
|
|
681
|
+
await generateModuleRegistry({ resolver: createMockResolver([workflowEngine]), quiet: true })
|
|
682
|
+
expect(readGenerated('workflows.generated.ts')).not.toContain('/modules/workflows/lib/code-registry')
|
|
683
|
+
expect(readGenerated('workflow-registrations.generated.ts')).toContain(
|
|
684
|
+
'import { registerCodeWorkflows } from "@open-mercato/core/modules/workflows/lib/code-registry"',
|
|
685
|
+
)
|
|
686
|
+
expect(readGenerated('workflow-registrations.generated.ts')).toContain('registerCodeWorkflows(allCodeWorkflows)')
|
|
687
|
+
|
|
688
|
+
await generateModuleRegistry({ resolver: createMockResolver([]), quiet: true })
|
|
689
|
+
expect(readGenerated('workflow-registrations.generated.ts')).toContain('export function registerGeneratedCodeWorkflows()')
|
|
690
|
+
expect(readGenerated('workflow-registrations.generated.ts')).not.toContain('/modules/workflows/lib/code-registry')
|
|
691
|
+
})
|
|
692
|
+
|
|
674
693
|
const registryFiles = [
|
|
675
694
|
'ai-tools.generated.ts',
|
|
676
695
|
'ai-agents.generated.ts',
|