@open-mercato/cli 0.11.1-develop.8589.1.db1a76ea60 → 0.11.1-develop.8665.1.2455b2503c
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 +4 -2
- package/AGENTS.md +3 -0
- package/dist/agentic/guides/architecture.md +2 -2
- package/dist/agentic/guides/extensions.md +7 -2
- package/dist/agentic/guides/framework-extension-points.md +1 -0
- package/dist/agentic/guides/infrastructure-providers.md +20 -0
- package/dist/agentic/guides/integrations.md +2 -2
- package/dist/agentic/guides/module-facts.json +2564 -265
- package/dist/agentic/guides/module-facts.v2.json +2580 -265
- package/dist/agentic/guides/modules/agent_orchestrator/index.md +1 -1
- package/dist/agentic/guides/modules/ai_assistant/index.md +1 -1
- package/dist/agentic/guides/modules/api_docs/index.md +1 -1
- package/dist/agentic/guides/modules/api_keys/index.md +1 -1
- package/dist/agentic/guides/modules/assisted_selling/acl-features.md +16 -0
- package/dist/agentic/guides/modules/assisted_selling/contribution-resolutions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/domain-commands.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/entities.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/events.md +22 -0
- package/dist/agentic/guides/modules/assisted_selling/exact-override-targets.md +17 -0
- package/dist/agentic/guides/modules/assisted_selling/index.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/owned-contract-module-metadata.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/setup.md +11 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-contributions.md +21 -0
- package/dist/agentic/guides/modules/assisted_selling/umes-hosts.md +23 -0
- package/dist/agentic/guides/modules/attachments/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/attachments/index.md +1 -1
- package/dist/agentic/guides/modules/attachments/workers.md +1 -1
- package/dist/agentic/guides/modules/audit_logs/index.md +1 -1
- package/dist/agentic/guides/modules/auth/index.md +1 -1
- package/dist/agentic/guides/modules/availability/index.md +1 -1
- package/dist/agentic/guides/modules/backups/di-registrations-rich.md +11 -0
- package/dist/agentic/guides/modules/backups/di-service-tokens.md +11 -0
- package/dist/agentic/guides/modules/backups/exact-override-targets.md +11 -0
- package/dist/agentic/guides/modules/backups/index.md +5 -2
- 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/acl-features.md +2 -1
- package/dist/agentic/guides/modules/catalog/active-extension-bindings.md +2 -0
- package/dist/agentic/guides/modules/catalog/backend-pages.md +1 -0
- package/dist/agentic/guides/modules/catalog/contribution-resolutions.md +5 -0
- package/dist/agentic/guides/modules/catalog/di-registrations-rich.md +8 -7
- package/dist/agentic/guides/modules/catalog/di-service-tokens.md +5 -4
- package/dist/agentic/guides/modules/catalog/domain-commands.md +2 -0
- package/dist/agentic/guides/modules/catalog/entities.md +1 -0
- package/dist/agentic/guides/modules/catalog/events.md +4 -1
- package/dist/agentic/guides/modules/catalog/exact-override-targets.md +13 -7
- package/dist/agentic/guides/modules/catalog/index.md +9 -9
- package/dist/agentic/guides/modules/catalog/umes-contributions.md +5 -0
- package/dist/agentic/guides/modules/catalog/umes-hosts.md +4 -0
- package/dist/agentic/guides/modules/catalog/workers.md +1 -0
- package/dist/agentic/guides/modules/channel_apns/index.md +1 -1
- package/dist/agentic/guides/modules/channel_discord/index.md +1 -1
- package/dist/agentic/guides/modules/channel_expo/index.md +1 -1
- package/dist/agentic/guides/modules/channel_fcm/index.md +1 -1
- package/dist/agentic/guides/modules/channel_gmail/index.md +1 -1
- package/dist/agentic/guides/modules/channel_imap/index.md +1 -1
- package/dist/agentic/guides/modules/channel_resend/index.md +1 -1
- package/dist/agentic/guides/modules/channel_ses/index.md +1 -1
- package/dist/agentic/guides/modules/channel_smtp/index.md +1 -1
- package/dist/agentic/guides/modules/checkout/index.md +1 -1
- package/dist/agentic/guides/modules/communication_channels/index.md +1 -1
- package/dist/agentic/guides/modules/configs/index.md +1 -1
- package/dist/agentic/guides/modules/content/index.md +1 -1
- package/dist/agentic/guides/modules/currencies/index.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/active-extension-bindings.md +1 -1
- package/dist/agentic/guides/modules/customer_accounts/exact-override-targets.md +2 -0
- package/dist/agentic/guides/modules/customer_accounts/index.md +2 -2
- package/dist/agentic/guides/modules/customer_accounts/workers.md +2 -0
- package/dist/agentic/guides/modules/customer_groups/index.md +1 -1
- package/dist/agentic/guides/modules/customers/active-extension-bindings.md +2 -1
- package/dist/agentic/guides/modules/customers/incoming-installed-contributions.md +1 -0
- package/dist/agentic/guides/modules/customers/index.md +3 -3
- package/dist/agentic/guides/modules/customers/umes-hosts.md +1 -0
- package/dist/agentic/guides/modules/dashboards/active-extension-bindings.md +0 -1
- package/dist/agentic/guides/modules/dashboards/cli-commands.md +1 -0
- package/dist/agentic/guides/modules/dashboards/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/dashboards/index.md +2 -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/index.md +1 -1
- package/dist/agentic/guides/modules/dictionaries/index.md +1 -1
- package/dist/agentic/guides/modules/directory/index.md +1 -1
- package/dist/agentic/guides/modules/documents/index.md +1 -1
- package/dist/agentic/guides/modules/ecommerce/index.md +1 -1
- package/dist/agentic/guides/modules/entities/index.md +1 -1
- package/dist/agentic/guides/modules/eudr/index.md +1 -1
- package/dist/agentic/guides/modules/events/index.md +1 -1
- package/dist/agentic/guides/modules/feature_toggles/index.md +1 -1
- package/dist/agentic/guides/modules/forms/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_autopay/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_stripe/index.md +1 -1
- package/dist/agentic/guides/modules/gateway_tpay/index.md +1 -1
- package/dist/agentic/guides/modules/generators/index.md +1 -1
- package/dist/agentic/guides/modules/inbox_ops/index.md +1 -1
- package/dist/agentic/guides/modules/integrations/di-registrations-rich.md +8 -8
- package/dist/agentic/guides/modules/integrations/di-service-tokens.md +4 -4
- package/dist/agentic/guides/modules/integrations/exact-override-targets.md +14 -12
- package/dist/agentic/guides/modules/integrations/index.md +2 -2
- package/dist/agentic/guides/modules/integrations/setup.md +1 -1
- package/dist/agentic/guides/modules/integrations/workers.md +3 -1
- package/dist/agentic/guides/modules/messages/index.md +1 -1
- package/dist/agentic/guides/modules/notifications/index.md +1 -1
- package/dist/agentic/guides/modules/onboarding/index.md +1 -1
- package/dist/agentic/guides/modules/payment_gateways/index.md +1 -1
- package/dist/agentic/guides/modules/perspectives/index.md +1 -1
- package/dist/agentic/guides/modules/phone_calls/index.md +1 -1
- package/dist/agentic/guides/modules/planner/index.md +1 -1
- package/dist/agentic/guides/modules/portal/index.md +1 -1
- package/dist/agentic/guides/modules/progress/index.md +1 -1
- package/dist/agentic/guides/modules/promotions/index.md +1 -1
- package/dist/agentic/guides/modules/push_notifications/index.md +1 -1
- package/dist/agentic/guides/modules/query_index/index.md +1 -1
- package/dist/agentic/guides/modules/record_locks/index.md +1 -1
- package/dist/agentic/guides/modules/resources/exact-override-targets.md +3 -3
- package/dist/agentic/guides/modules/resources/index.md +1 -1
- package/dist/agentic/guides/modules/resources/owned-contract-module-metadata.md +1 -1
- package/dist/agentic/guides/modules/resources/setup.md +1 -1
- package/dist/agentic/guides/modules/sales/contribution-resolutions.md +1 -0
- package/dist/agentic/guides/modules/sales/exact-override-targets.md +1 -0
- package/dist/agentic/guides/modules/sales/index.md +3 -3
- package/dist/agentic/guides/modules/sales/umes-contributions.md +1 -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/index.md +1 -1
- package/dist/agentic/guides/modules/sso/index.md +1 -1
- package/dist/agentic/guides/modules/staff/contribution-resolutions.md +1 -1
- package/dist/agentic/guides/modules/staff/exact-override-targets.md +1 -1
- package/dist/agentic/guides/modules/staff/index.md +1 -1
- package/dist/agentic/guides/modules/staff/workers.md +1 -1
- package/dist/agentic/guides/modules/storage_s3/index.md +1 -1
- package/dist/agentic/guides/modules/sync_akeneo/index.md +1 -1
- package/dist/agentic/guides/modules/sync_excel/index.md +1 -1
- package/dist/agentic/guides/modules/system_status_overlays/index.md +1 -1
- package/dist/agentic/guides/modules/telemetry/index.md +1 -1
- package/dist/agentic/guides/modules/tillio/index.md +1 -1
- package/dist/agentic/guides/modules/translations/index.md +1 -1
- package/dist/agentic/guides/modules/warranty_claims/index.md +1 -1
- package/dist/agentic/guides/modules/webhooks/index.md +1 -1
- package/dist/agentic/guides/modules/wms/index.md +1 -1
- package/dist/agentic/guides/modules/workflows/index.md +1 -1
- package/dist/agentic/guides/reference-module-facts.json +811 -21
- package/dist/agentic/guides/reference-modules/example/active-extension-bindings.md +1 -0
- package/dist/agentic/guides/reference-modules/example/backend-pages.md +2 -0
- package/dist/agentic/guides/reference-modules/example/contribution-resolutions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/di-registrations-rich.md +3 -3
- package/dist/agentic/guides/reference-modules/example/di-service-tokens.md +1 -1
- package/dist/agentic/guides/reference-modules/example/entities.md +2 -0
- package/dist/agentic/guides/reference-modules/example/events.md +2 -1
- package/dist/agentic/guides/reference-modules/example/exact-override-targets.md +25 -8
- package/dist/agentic/guides/reference-modules/example/index.md +7 -7
- package/dist/agentic/guides/reference-modules/example/notifications.md +1 -0
- package/dist/agentic/guides/reference-modules/example/setup.md +1 -1
- package/dist/agentic/guides/reference-modules/example/umes-contributions.md +3 -1
- package/dist/agentic/guides/reference-modules/example/umes-hosts.md +4 -0
- package/dist/agentic/guides/upstream/AGENTS.md +5 -4
- package/dist/agentic/guides/upstream/BACKWARD_COMPATIBILITY.md +37 -20
- package/dist/agentic/guides/upstream/manifest.json +3 -3
- package/dist/agentic/shared/AGENTS.md.template +11 -15
- package/dist/agentic/shared/ai/harness/README.md +4 -2
- package/dist/agentic/shared/ai/harness/RELEASE.md +4 -4
- package/dist/agentic/shared/ai/harness/cases.json +1420 -41
- package/dist/agentic/shared/ai/harness/cases.schema.json +4 -4
- package/dist/agentic/shared/ai/harness/design-system-inventory.json +640 -142
- package/dist/agentic/shared/ai/harness/source-link-inventory.json +223 -16
- package/dist/agentic/shared/ai/harness/validators.json +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/SKILL.md +1 -1
- package/dist/agentic/shared/ai/skills/om-system-extension/references/extension-branches.md +25 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/mechanism-selector.md +1 -0
- package/dist/agentic/shared/ai/skills/om-system-extension/references/unified-overrides.md +2 -0
- package/dist/agentic/shared/scripts/run-agent-harness-release.mjs +21 -1
- package/dist/lib/cache-provider-manifest.js +9 -0
- package/dist/lib/cache-provider-manifest.js.map +7 -0
- package/dist/lib/generate-child-process.js +21 -3
- package/dist/lib/generate-child-process.js.map +2 -2
- package/dist/lib/generate-watch-events.js +135 -19
- package/dist/lib/generate-watch-events.js.map +2 -2
- package/dist/lib/generate-watch-plan.js +170 -0
- package/dist/lib/generate-watch-plan.js.map +7 -0
- package/dist/lib/generate-watch-runner.js +54 -0
- package/dist/lib/generate-watch-runner.js.map +7 -0
- package/dist/lib/generate-watch-structure.js +578 -203
- package/dist/lib/generate-watch-structure.js.map +3 -3
- package/dist/lib/generators/ast/writers.js +5 -1
- package/dist/lib/generators/ast/writers.js.map +2 -2
- package/dist/lib/generators/cache-providers.js +80 -0
- package/dist/lib/generators/cache-providers.js.map +7 -0
- package/dist/lib/generators/extensions/agent-files.js +1 -0
- package/dist/lib/generators/extensions/agent-files.js.map +2 -2
- package/dist/lib/generators/form-section-ast.js +156 -0
- package/dist/lib/generators/form-section-ast.js.map +7 -0
- package/dist/lib/generators/form-section-extension-compiler.js +568 -0
- package/dist/lib/generators/form-section-extension-compiler.js.map +7 -0
- package/dist/lib/generators/form-section-extension-source.js +245 -0
- package/dist/lib/generators/form-section-extension-source.js.map +7 -0
- package/dist/lib/generators/form-section-runtime-revisions.js +184 -0
- package/dist/lib/generators/form-section-runtime-revisions.js.map +7 -0
- package/dist/lib/generators/form-sections.js +773 -0
- package/dist/lib/generators/form-sections.js.map +7 -0
- package/dist/lib/generators/index.js +2 -0
- package/dist/lib/generators/index.js.map +2 -2
- package/dist/lib/generators/module-entities.js +21 -2
- package/dist/lib/generators/module-entities.js.map +2 -2
- package/dist/lib/generators/module-extension-facts.js +2 -1
- package/dist/lib/generators/module-extension-facts.js.map +2 -2
- package/dist/lib/generators/module-facts.js +30 -1
- package/dist/lib/generators/module-facts.js.map +2 -2
- package/dist/lib/generators/module-override-targets.js +24 -2
- package/dist/lib/generators/module-override-targets.js.map +2 -2
- package/dist/lib/generators/module-registry.js +223 -194
- package/dist/lib/generators/module-registry.js.map +3 -3
- package/dist/lib/generators/openapi.js +51 -18
- package/dist/lib/generators/openapi.js.map +2 -2
- package/dist/lib/generators/web-research-adapters.js +54 -22
- package/dist/lib/generators/web-research-adapters.js.map +2 -2
- package/dist/lib/in-process-generate-watcher.js +98 -75
- package/dist/lib/in-process-generate-watcher.js.map +2 -2
- package/dist/lib/post-generate-invalidation.js +20 -1
- package/dist/lib/post-generate-invalidation.js.map +2 -2
- package/dist/lib/resolver.js +195 -1
- package/dist/lib/resolver.js.map +3 -3
- package/dist/lib/single-instance-strategy-guard.js +26 -3
- package/dist/lib/single-instance-strategy-guard.js.map +2 -2
- package/dist/mercato.js +106 -50
- package/dist/mercato.js.map +2 -2
- package/jest.config.cjs +2 -0
- package/package.json +7 -7
- package/src/__tests__/mercato.test.ts +18 -0
- package/src/__tests__/rotation-json-output.test.ts +52 -0
- package/src/lib/__tests__/cache-provider-manifest.test.ts +76 -0
- package/src/lib/__tests__/generate-child-process.test.ts +30 -0
- package/src/lib/__tests__/generate-watch-events.test.ts +377 -8
- package/src/lib/__tests__/generate-watch-plan.test.ts +99 -0
- package/src/lib/__tests__/generate-watch-runner.test.ts +138 -0
- package/src/lib/__tests__/generate-watch-structure.test.ts +556 -1
- package/src/lib/__tests__/in-process-generate-watcher.test.ts +393 -6
- package/src/lib/__tests__/module-inspection.test.ts +17 -11
- package/src/lib/__tests__/post-generate-invalidation.test.ts +108 -0
- package/src/lib/__tests__/resolver.form-section-gates.test.ts +82 -0
- package/src/lib/__tests__/single-instance-strategy-guard.test.ts +129 -0
- package/src/lib/cache-provider-manifest.ts +8 -0
- package/src/lib/generate-child-process.ts +26 -3
- package/src/lib/generate-watch-events.ts +189 -17
- package/src/lib/generate-watch-plan.ts +180 -0
- package/src/lib/generate-watch-runner.ts +63 -0
- package/src/lib/generate-watch-structure.ts +670 -227
- package/src/lib/generators/__tests__/cache-providers.test.ts +102 -0
- package/src/lib/generators/__tests__/derived-crud-route-collisions.test.ts +85 -0
- package/src/lib/generators/__tests__/form-section-outbox.test.ts +53 -0
- package/src/lib/generators/__tests__/form-sections.test.ts +896 -0
- package/src/lib/generators/__tests__/incremental-registry.test.ts +262 -0
- package/src/lib/generators/__tests__/module-extension-facts.test.ts +1 -0
- package/src/lib/generators/__tests__/module-facts.bc-guard.test.ts +8 -6
- package/src/lib/generators/__tests__/module-facts.example-fact-coverage.test.ts +37 -13
- package/src/lib/generators/__tests__/module-facts.local-reference.test.ts +13 -0
- package/src/lib/generators/__tests__/module-override-targets.test.ts +2 -3
- package/src/lib/generators/__tests__/module-subset.test.ts +1 -1
- package/src/lib/generators/__tests__/openapi.test.ts +147 -10
- package/src/lib/generators/__tests__/structural-contracts.test.ts +2 -2
- package/src/lib/generators/__tests__/web-research-adapters.test.ts +298 -87
- package/src/lib/generators/ast/writers.ts +6 -1
- package/src/lib/generators/cache-providers.ts +111 -0
- package/src/lib/generators/extension.ts +2 -0
- package/src/lib/generators/extensions/agent-files.ts +1 -0
- package/src/lib/generators/form-section-ast.ts +166 -0
- package/src/lib/generators/form-section-extension-compiler.ts +632 -0
- package/src/lib/generators/form-section-extension-source.ts +308 -0
- package/src/lib/generators/form-section-runtime-revisions.ts +211 -0
- package/src/lib/generators/form-sections.ts +896 -0
- package/src/lib/generators/index.ts +1 -0
- package/src/lib/generators/module-entities.ts +22 -4
- package/src/lib/generators/module-extension-facts.ts +1 -0
- package/src/lib/generators/module-facts.ts +40 -0
- package/src/lib/generators/module-override-targets.ts +19 -0
- package/src/lib/generators/module-registry.ts +246 -202
- package/src/lib/generators/openapi.ts +65 -20
- package/src/lib/generators/web-research-adapters.ts +76 -21
- package/src/lib/in-process-generate-watcher.ts +151 -96
- package/src/lib/post-generate-invalidation.ts +28 -1
- package/src/lib/resolver.ts +218 -0
- package/src/lib/single-instance-strategy-guard.ts +51 -1
- package/src/mercato.ts +117 -57
- package/dist/agentic/guides/modules/dashboards/incoming-installed-contributions.md +0 -11
|
@@ -0,0 +1,896 @@
|
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
import type { CrudFormSectionServerModule } from '@open-mercato/shared/modules/form-sections'
|
|
5
|
+
import { registerMutationGuards } from '@open-mercato/shared/lib/crud/mutation-guard-store'
|
|
6
|
+
import { registerCrudFormSectionClientRegistry, type CrudFormSectionClientRegistry } from '@open-mercato/shared/lib/crud/form-sections/client-registry'
|
|
7
|
+
import { computeCrudFormSectionClientFingerprint, crudFormSectionHostKey } from '@open-mercato/shared/lib/crud/form-sections/composition'
|
|
8
|
+
import { buildCrudFormSectionManifest } from '@open-mercato/shared/lib/crud/form-sections/manifest'
|
|
9
|
+
import { encodeCurrentCrudFormSectionPolicyToken } from '@open-mercato/shared/lib/crud/form-sections/policy-token'
|
|
10
|
+
import { loadCrudFormSectionComposition, selectCrudFormSectionComposition } from '../../../../../ui/src/backend/injection/crud-form-section-composition'
|
|
11
|
+
import { projectCrudFormSectionCustomFields } from '../../../../../ui/src/backend/injection/crud-form-section-custom-fields'
|
|
12
|
+
import { projectCrudFormSectionSubmission } from '../../../../../ui/src/backend/injection/crud-form-section-submission'
|
|
13
|
+
import { fixtureGuards } from '../../../../../../.ai/qa/fixtures/crudform-section-policy/parity/parity-authority'
|
|
14
|
+
import type { ModuleEntry, PackageResolver } from '../../resolver'
|
|
15
|
+
import { generateModuleRegistries, generateModuleRegistryApp } from '../module-registry'
|
|
16
|
+
import { generatedDerivedCrudRouteIndex, readDerivedCrudFormSectionRouteIndex } from '../form-sections'
|
|
17
|
+
|
|
18
|
+
jest.mock('@open-mercato/ui/backend/crud-form-extensions', () =>
|
|
19
|
+
jest.requireActual('../../../../../ui/src/backend/crud-form-extensions'), { virtual: true })
|
|
20
|
+
jest.mock('@open-mercato/ui/backend/crud-form-field-granular', () =>
|
|
21
|
+
jest.requireActual('../../../../../ui/src/backend/crud-form-field-granular'), { virtual: true })
|
|
22
|
+
jest.mock('@open-mercato/ui/backend/injection/crud-form-section-runtime', () =>
|
|
23
|
+
jest.requireActual('../../../../../ui/src/backend/injection/crud-form-section-runtime'), { virtual: true })
|
|
24
|
+
|
|
25
|
+
let root: string
|
|
26
|
+
|
|
27
|
+
function write(relativePath: string, source: string): void {
|
|
28
|
+
const target = path.join(root, relativePath)
|
|
29
|
+
fs.mkdirSync(path.dirname(target), { recursive: true })
|
|
30
|
+
fs.writeFileSync(target, source)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function resolver(enabled: ModuleEntry[], standalone = false): PackageResolver {
|
|
34
|
+
const packageRoot = path.join(root, 'package')
|
|
35
|
+
const appRoot = path.join(root, 'app')
|
|
36
|
+
const output = path.join(appRoot, '.mercato', 'generated')
|
|
37
|
+
return {
|
|
38
|
+
isMonorepo: () => !standalone,
|
|
39
|
+
getRootDir: () => root,
|
|
40
|
+
getAppDir: () => appRoot,
|
|
41
|
+
getOutputDir: () => output,
|
|
42
|
+
getModulesConfigPath: () => path.join(appRoot, 'src', 'modules.ts'),
|
|
43
|
+
discoverPackages: () => [],
|
|
44
|
+
loadEnabledModules: () => enabled,
|
|
45
|
+
getModulePaths: ({ id }) => ({
|
|
46
|
+
appBase: path.join(appRoot, 'src', 'modules', id),
|
|
47
|
+
pkgBase: path.join(packageRoot, standalone ? 'dist' : 'src', 'modules', id),
|
|
48
|
+
}),
|
|
49
|
+
getModuleImportBase: ({ id }) => ({
|
|
50
|
+
appBase: `@/modules/${id}`,
|
|
51
|
+
pkgBase: `@open-mercato/core/modules/${id}`,
|
|
52
|
+
}),
|
|
53
|
+
getPackageOutputDir: () => output,
|
|
54
|
+
getPackageRoot: () => packageRoot,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function generated(kind: 'facts' | 'runtime'): string {
|
|
59
|
+
return fs.readFileSync(path.join(root, 'app/.mercato/generated', `crud-form-section-${kind}.generated.ts`), 'utf8')
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function identity(id: string, version = 1): string {
|
|
63
|
+
return JSON.stringify({ id, roundTripId: `${id}@v${version}` })
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function declaration(
|
|
67
|
+
id: string,
|
|
68
|
+
options: {
|
|
69
|
+
kind?: 'hostFacts' | 'contributionFacts'
|
|
70
|
+
version?: number
|
|
71
|
+
loaderVersion?: number
|
|
72
|
+
loader?: string
|
|
73
|
+
noLoader?: true
|
|
74
|
+
noFact?: true
|
|
75
|
+
} = {},
|
|
76
|
+
): string {
|
|
77
|
+
const { kind = 'contributionFacts', version = 1, loaderVersion = version } = options
|
|
78
|
+
const descriptor = { id, roundTripId: `${id}@v${version}` }
|
|
79
|
+
const fact = options.noFact ? '' : JSON.stringify(kind === 'hostFacts' ? descriptor : {
|
|
80
|
+
...descriptor,
|
|
81
|
+
address: { hostId: 'example.product', formVariant: 'default', formOperation: 'update', sectionId: 'notes' },
|
|
82
|
+
operation: 'add',
|
|
83
|
+
requiredCapabilities: [],
|
|
84
|
+
})
|
|
85
|
+
const loaderIdentity = identity(id, loaderVersion).slice(1, -1)
|
|
86
|
+
const loadExpression = options.loader ?? "lazyCrudFormSectionRuntime(() => import('./descriptor.client'))"
|
|
87
|
+
const loader = options.noLoader ? '' : `{ ${loaderIdentity}, load: ${loadExpression} }`
|
|
88
|
+
return `
|
|
89
|
+
import { defineCrudFormSections, lazyCrudFormSectionRuntime } from '@open-mercato/shared/modules/form-sections'
|
|
90
|
+
export const crudFormSections = defineCrudFormSections({
|
|
91
|
+
${kind}: [${fact}],
|
|
92
|
+
runtimes: [${loader}],
|
|
93
|
+
})
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function runtime(id: string, version = 1): string {
|
|
98
|
+
return `export const crudFormSectionRuntime = ${identity(id, version)}`
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
beforeEach(() => {
|
|
102
|
+
root = fs.mkdtempSync(path.join(os.tmpdir(), 'crud-form-sections-'))
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
afterEach(() => {
|
|
106
|
+
registerMutationGuards([])
|
|
107
|
+
fs.rmSync(root, { recursive: true, force: true })
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
describe('CrudForm section registry generation', () => {
|
|
111
|
+
it('runs equivalent handwritten and wrapper registries through the manifest and browser projection', async () => {
|
|
112
|
+
const testRoot = root
|
|
113
|
+
const fixtureSource = path.resolve(__dirname, '../../../../../../.ai/qa/fixtures/crudform-section-policy')
|
|
114
|
+
const moduleId = 'form_policy_fixture'
|
|
115
|
+
const address = { hostId: 'form_policy_fixture.record', formVariant: 'showcase', formOperation: 'update' } as const
|
|
116
|
+
const host = { hostResourceKind: 'form_policy_fixture.record', hostResourceId: 'fixture-record' }
|
|
117
|
+
const identity = { ...address, resourceId: host.hostResourceId }
|
|
118
|
+
const policyKey = crudFormSectionHostKey(address)
|
|
119
|
+
const outputDir = 'app/.mercato/generated'
|
|
120
|
+
fs.symlinkSync(path.resolve(__dirname, '../../../../../../node_modules'), path.join(testRoot, 'node_modules'), 'dir')
|
|
121
|
+
|
|
122
|
+
async function run(variant: 'wrapper' | 'handwritten') {
|
|
123
|
+
root = path.join(testRoot, variant)
|
|
124
|
+
const moduleDir = path.join(root, 'app/src/modules', moduleId)
|
|
125
|
+
fs.cpSync(path.join(fixtureSource, 'src/modules', moduleId), moduleDir, { recursive: true })
|
|
126
|
+
const alternate = path.join(fixtureSource, 'parity')
|
|
127
|
+
fs.copyFileSync(path.join(alternate, `${variant}.form-sections.ts`), path.join(moduleDir, 'form-sections.ts'))
|
|
128
|
+
fs.copyFileSync(path.join(alternate, 'parity-authority.ts'), path.join(moduleDir, 'parity-authority.ts'))
|
|
129
|
+
for (const part of ['details', 'display', 'hide']) {
|
|
130
|
+
const filename = `parity-${part}.client.ts`
|
|
131
|
+
fs.copyFileSync(path.join(alternate, filename), path.join(moduleDir, 'runtime', filename))
|
|
132
|
+
}
|
|
133
|
+
fs.rmSync(path.join(moduleDir, 'form-sections.runtime-revisions.json'))
|
|
134
|
+
await generateModuleRegistries({ resolver: resolver([{ id: moduleId, from: '@app' }]), quiet: true })
|
|
135
|
+
expect(generated('runtime')).toContain('"position": "before" as InjectionPosition')
|
|
136
|
+
const server: { crudFormSectionServerModules: readonly CrudFormSectionServerModule[] } =
|
|
137
|
+
require(path.join(root, outputDir, 'crud-form-section-facts.generated.ts'))
|
|
138
|
+
const browser: {
|
|
139
|
+
crudFormSectionClientHostFacts: CrudFormSectionClientRegistry['hostFacts']
|
|
140
|
+
crudFormSectionRuntimeEntries: CrudFormSectionClientRegistry['runtimeEntries']
|
|
141
|
+
crudFormSectionContributedOverrides: CrudFormSectionClientRegistry['contributedOverrides']
|
|
142
|
+
} = require(path.join(root, outputDir, 'crud-form-section-runtime.generated.ts'))
|
|
143
|
+
const modules = server.crudFormSectionServerModules
|
|
144
|
+
registerMutationGuards([{ moduleId, guards: fixtureGuards(variant === 'handwritten') }])
|
|
145
|
+
const manifest = buildCrudFormSectionManifest(modules)
|
|
146
|
+
const policy = manifest.policies.get(policyKey)
|
|
147
|
+
expect(policy).toBeDefined()
|
|
148
|
+
if (!policy) throw new Error('[internal] Generated fixture policy was not accepted')
|
|
149
|
+
const registry = {
|
|
150
|
+
hostFacts: browser.crudFormSectionClientHostFacts,
|
|
151
|
+
runtimeEntries: browser.crudFormSectionRuntimeEntries,
|
|
152
|
+
contributedOverrides: browser.crudFormSectionContributedOverrides,
|
|
153
|
+
}
|
|
154
|
+
registerCrudFormSectionClientRegistry(registry)
|
|
155
|
+
const composition = selectCrudFormSectionComposition(registry, identity)
|
|
156
|
+
if (!composition) throw new Error('[internal] Generated fixture client composition was not selected')
|
|
157
|
+
const runtime = await loadCrudFormSectionComposition<Record<string, unknown>, Record<string, unknown>>(
|
|
158
|
+
composition, ['details', 'private'], undefined,
|
|
159
|
+
)
|
|
160
|
+
if (!runtime) throw new Error('[internal] Generated fixture client runtime was not accepted')
|
|
161
|
+
const { surface } = composition
|
|
162
|
+
const { descriptors, identities } = runtime
|
|
163
|
+
const clientFingerprint = await computeCrudFormSectionClientFingerprint(surface, identities, composition.overrides)
|
|
164
|
+
expect(clientFingerprint).toBe(policy.clientFingerprint)
|
|
165
|
+
const entityId = 'form_policy_fixture:record'
|
|
166
|
+
const customFields = projectCrudFormSectionCustomFields({
|
|
167
|
+
surface, descriptors, entityIds: [entityId], definitionSets: { 'form_policy_fixture.region-v1': [entityId] },
|
|
168
|
+
definitions: [{ key: 'region', kind: 'text', formEditable: true, entityId }],
|
|
169
|
+
})
|
|
170
|
+
const projection = projectCrudFormSectionSubmission({
|
|
171
|
+
values: { displayName: ' replacement ', privateCode: 'omitted', cf_region: 'north' },
|
|
172
|
+
surface, descriptors, customFields, bareCustomFields: false,
|
|
173
|
+
})
|
|
174
|
+
const invalid = projectCrudFormSectionSubmission({
|
|
175
|
+
values: { displayName: ' ', cf_region: 'north' },
|
|
176
|
+
surface, descriptors, customFields, bareCustomFields: false,
|
|
177
|
+
})
|
|
178
|
+
return { manifest, policy, projection, invalid, descriptors, modules, surface, identities, composition }
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
try {
|
|
182
|
+
const handwritten = await run('handwritten')
|
|
183
|
+
const wrapper = await run('wrapper')
|
|
184
|
+
expect(handwritten.manifest.ledger).toEqual(wrapper.manifest.ledger)
|
|
185
|
+
expect(handwritten.policy.clientFingerprint).toBe(wrapper.policy.clientFingerprint)
|
|
186
|
+
expect(handwritten.policy.capabilities.map(({ fact }) => fact)).toEqual(wrapper.policy.capabilities.map(({ fact }) => fact))
|
|
187
|
+
expect(handwritten.policy.capabilities.map(({ source }) => source.kind)).not.toEqual(wrapper.policy.capabilities.map(({ source }) => source.kind))
|
|
188
|
+
expect(handwritten.policy.requiredLeaves).toEqual(wrapper.policy.requiredLeaves)
|
|
189
|
+
expect(wrapper.policy.requiredLeaves).toContainEqual(expect.objectContaining({ payloadPath: 'privateCode', mode: 'preserve-from-record' }))
|
|
190
|
+
expect(handwritten.projection).toEqual(wrapper.projection)
|
|
191
|
+
expect(wrapper.projection).toEqual({
|
|
192
|
+
state: 'ready', payload: { name: 'replacement', customFields: { region: 'north' } },
|
|
193
|
+
activeValues: { displayName: ' replacement ', cf_region: 'north' },
|
|
194
|
+
})
|
|
195
|
+
expect(wrapper.invalid).toEqual(handwritten.invalid)
|
|
196
|
+
expect(wrapper.invalid).toEqual({ state: 'invalid', fieldErrors: { displayName: 'form_policy_fixture.validation.name' } })
|
|
197
|
+
expect(wrapper.descriptors.map(({ id }) => id)).toEqual(handwritten.descriptors.map(({ id }) => id))
|
|
198
|
+
expect(wrapper.descriptors.map(({ group }) => group.id)).toEqual(['display', 'details'])
|
|
199
|
+
expect(wrapper.descriptors[0].group.title).toBe(handwritten.descriptors[0].group.title)
|
|
200
|
+
|
|
201
|
+
const scoped = buildCrudFormSectionManifest(wrapper.modules.map(({ moduleId: id, sections }) => ({
|
|
202
|
+
moduleId: id, sections: {
|
|
203
|
+
...sections, hostProviders: sections.hostProviders?.map((provider) => ({
|
|
204
|
+
...provider, requireFeatures: [...provider.requireFeatures, 'form_policy_fixture.restricted'],
|
|
205
|
+
})),
|
|
206
|
+
},
|
|
207
|
+
})))
|
|
208
|
+
const scopedPolicy = scoped.policies.get(policyKey)!
|
|
209
|
+
expect(scopedPolicy.requireFeatures).toContain('form_policy_fixture.restricted')
|
|
210
|
+
expect(scoped.ledger.fingerprint).not.toBe(wrapper.manifest.ledger.fingerprint)
|
|
211
|
+
expect(encodeCurrentCrudFormSectionPolicyToken({ address, host, policy: scopedPolicy, fingerprint: scoped.ledger.fingerprint }))
|
|
212
|
+
.not.toBe(encodeCurrentCrudFormSectionPolicyToken({ address, host, policy: wrapper.policy, fingerprint: wrapper.manifest.ledger.fingerprint }))
|
|
213
|
+
const routes = wrapper.surface.clientMutationSurfaces!
|
|
214
|
+
const shifted = routes.map(({ guardedFacade, ...route }) => ({
|
|
215
|
+
...route, guardedFacade: { ...guardedFacade, routePattern: '/form-policy-fixture/alternate/section-policy' },
|
|
216
|
+
}))
|
|
217
|
+
expect(await computeCrudFormSectionClientFingerprint(
|
|
218
|
+
{ ...wrapper.surface, clientMutationSurfaces: shifted }, wrapper.identities, wrapper.composition.overrides,
|
|
219
|
+
)).not.toBe(wrapper.policy.clientFingerprint)
|
|
220
|
+
} finally {
|
|
221
|
+
root = testRoot
|
|
222
|
+
}
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('generates matching fact and lazy runtime registries from the reusable non-production fixture', async () => {
|
|
226
|
+
const fixtureSource = path.resolve(__dirname, '../../../../../../.ai/qa/fixtures/crudform-section-policy/src/modules/form_policy_fixture')
|
|
227
|
+
const fixtureDestination = path.join(root, 'app/src/modules/form_policy_fixture')
|
|
228
|
+
fs.cpSync(fixtureSource, fixtureDestination, { recursive: true })
|
|
229
|
+
const generatedFixture = await generateModuleRegistries({
|
|
230
|
+
resolver: resolver([{ id: 'form_policy_fixture', from: '@app' }]), quiet: true,
|
|
231
|
+
})
|
|
232
|
+
expect(generatedFixture.flatMap(({ filesWritten }) => filesWritten).some((file) =>
|
|
233
|
+
file.endsWith('form-sections.runtime-revisions.json'))).toBe(false)
|
|
234
|
+
|
|
235
|
+
const facts = generated('facts')
|
|
236
|
+
const browser = generated('runtime')
|
|
237
|
+
expect(facts).toContain('form_policy_fixture/form-sections')
|
|
238
|
+
expect(facts.match(/fact: sections0\.(?:hostFacts|contributionFacts)\[\d+\]/g)).toHaveLength(5)
|
|
239
|
+
expect(browser.match(/load: \(\) => import\(/g)).toHaveLength(5)
|
|
240
|
+
expect(browser).toContain('form_policy_fixture.hide-uncovered@v1')
|
|
241
|
+
expect(browser).toContain('form_policy_fixture.record')
|
|
242
|
+
expect(browser).not.toContain('form_policy_fixture/form-sections')
|
|
243
|
+
})
|
|
244
|
+
|
|
245
|
+
it('keeps server imports isolated, follows dependency order and excludes disabled modules', async () => {
|
|
246
|
+
const packageModule = 'package/src/modules/shared_forms'
|
|
247
|
+
const dependent = 'app/src/modules/alpha_forms'
|
|
248
|
+
write(`${packageModule}/form-sections.ts`, declaration('shared.product', { kind: 'hostFacts' }))
|
|
249
|
+
write(`${packageModule}/descriptor.client.tsx`, runtime('shared.product'))
|
|
250
|
+
write(`${dependent}/index.ts`, "export const metadata = { requires: ['shared_forms'] }")
|
|
251
|
+
write(`${dependent}/form-sections.ts`, declaration('alpha.notes'))
|
|
252
|
+
write(`${dependent}/descriptor.client.ts`, runtime('alpha.notes'))
|
|
253
|
+
write('app/src/modules/disabled/form-sections.ts', 'export const crudFormSections = invalid()')
|
|
254
|
+
const fixture = resolver([{ id: 'alpha_forms', from: '@app' }, { id: 'shared_forms' }])
|
|
255
|
+
await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
256
|
+
|
|
257
|
+
const facts = generated('facts')
|
|
258
|
+
expect(facts).toContain('from "@open-mercato/core/modules/shared_forms/form-sections"')
|
|
259
|
+
expect(facts).toContain('from "../../src/modules/alpha_forms/form-sections"')
|
|
260
|
+
expect(facts).toContain('fact: sections0.hostFacts[0]')
|
|
261
|
+
expect(facts).toContain('fact: sections1.contributionFacts[0]')
|
|
262
|
+
expect(facts).not.toMatch(/descriptor\.client|disabled/)
|
|
263
|
+
|
|
264
|
+
const browser = generated('runtime')
|
|
265
|
+
expect(browser).toContain('load: () => import("@open-mercato/core/modules/shared_forms/descriptor.client")')
|
|
266
|
+
expect(browser).toContain('load: () => import("../../src/modules/alpha_forms/descriptor.client")')
|
|
267
|
+
expect(browser).toContain('return runtimesById.get(id)')
|
|
268
|
+
expect(browser.indexOf('id: "shared.product"')).toBeLessThan(browser.indexOf('id: "alpha.notes"'))
|
|
269
|
+
expect(browser).not.toMatch(/\/form-sections"|disabled/)
|
|
270
|
+
const secondRun = await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
271
|
+
expect(secondRun.flatMap((result) => result.filesWritten)).toEqual([])
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
it('records normalized runtime semantics and requires an advancing handwritten revision for each kind of drift', async () => {
|
|
275
|
+
const base = 'app/src/modules/test'
|
|
276
|
+
const descriptorId = 'test.notes'
|
|
277
|
+
const runtimeFile = `${base}/descriptor.client.tsx`
|
|
278
|
+
const declarationFile = `${base}/form-sections.ts`
|
|
279
|
+
const ledgerFile = path.join(root, base, 'form-sections.runtime-revisions.json')
|
|
280
|
+
const generate = (enabled = true) => generateModuleRegistryApp({
|
|
281
|
+
resolver: resolver(enabled ? [{ id: 'test', from: '@app' }] : []), quiet: true,
|
|
282
|
+
})
|
|
283
|
+
const baseline = `
|
|
284
|
+
import { normalize } from './helper'
|
|
285
|
+
export const crudFormSectionRuntime = {
|
|
286
|
+
id: 'test.notes', roundTripId: 'test.notes@v1',
|
|
287
|
+
group: { id: 'notes', component: ({ runSectionMutation }) => <p>Notes</p> },
|
|
288
|
+
ownedFieldPaths: ['note'],
|
|
289
|
+
ownedCustomFieldIds: ['extra'],
|
|
290
|
+
validate: () => normalize('raw'),
|
|
291
|
+
projectPayload: () => ({ note: true }),
|
|
292
|
+
requiredSectionIds: ['details'],
|
|
293
|
+
requiredDataContractIds: ['loader'],
|
|
294
|
+
providedDataContractIds: ['summary'],
|
|
295
|
+
mutationSurfaceIds: ['save'],
|
|
296
|
+
compositionValidator: () => ({ success: true }),
|
|
297
|
+
}
|
|
298
|
+
`
|
|
299
|
+
write(declarationFile, declaration(descriptorId))
|
|
300
|
+
write(runtimeFile, baseline)
|
|
301
|
+
write(`${base}/helper.ts`, 'export const normalize = (value) => value.trim()')
|
|
302
|
+
await generate()
|
|
303
|
+
const ledger = fs.readFileSync(ledgerFile, 'utf8')
|
|
304
|
+
expect(JSON.parse(ledger)).toMatchObject({ [descriptorId]: { roundTripId: 'test.notes@v1' } })
|
|
305
|
+
|
|
306
|
+
write(runtimeFile, baseline.replace("'notes', component", '"notes", /* documentation */ component')
|
|
307
|
+
.replace("['note']", "[ 'note', ]").replace('}\n ', '};\n '))
|
|
308
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
309
|
+
for (const [before, after] of [
|
|
310
|
+
['>Notes<', '>Notes and details<'],
|
|
311
|
+
['>Notes<', '> Notes<'],
|
|
312
|
+
["['note']", "['other']"],
|
|
313
|
+
["['extra']", "['other']"],
|
|
314
|
+
["normalize('raw')", "normalize('updated')"],
|
|
315
|
+
['note: true', 'note: false'],
|
|
316
|
+
["['details']", "['settings']"],
|
|
317
|
+
["['loader']", "['reader']"],
|
|
318
|
+
["['summary']", "['report']"],
|
|
319
|
+
["['save']", "['archive']"],
|
|
320
|
+
['success: true', 'success: false'],
|
|
321
|
+
]) {
|
|
322
|
+
write(runtimeFile, baseline.replace(before, after))
|
|
323
|
+
await expect(generate()).rejects.toThrow(/semantic runtime drift.*requires advancing roundTripId/)
|
|
324
|
+
expect(fs.readFileSync(ledgerFile, 'utf8')).toBe(ledger)
|
|
325
|
+
}
|
|
326
|
+
write(runtimeFile, baseline)
|
|
327
|
+
write(declarationFile, declaration(descriptorId).replace('"operation":"add"', '"operation":"replace"'))
|
|
328
|
+
await expect(generate()).rejects.toThrow(/semantic runtime drift/)
|
|
329
|
+
write(declarationFile, declaration(descriptorId))
|
|
330
|
+
write(`${base}/helper.ts`, 'export const normalize = (value) => value.toUpperCase()')
|
|
331
|
+
await expect(generate()).rejects.toThrow(/semantic runtime drift/)
|
|
332
|
+
await generate(false)
|
|
333
|
+
expect(fs.readFileSync(ledgerFile, 'utf8')).toBe(ledger)
|
|
334
|
+
await expect(generate()).rejects.toThrow(/semantic runtime drift/)
|
|
335
|
+
write(declarationFile, declaration(descriptorId, { version: 2 }))
|
|
336
|
+
write(runtimeFile, baseline.replace('test.notes@v1', 'test.notes@v2'))
|
|
337
|
+
await generate()
|
|
338
|
+
expect(JSON.parse(fs.readFileSync(ledgerFile, 'utf8'))).toMatchObject({ [descriptorId]: { roundTripId: 'test.notes@v2' } })
|
|
339
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
340
|
+
write(declarationFile, declaration(descriptorId))
|
|
341
|
+
write(runtimeFile, baseline)
|
|
342
|
+
await expect(generate()).rejects.toThrow(/requires advancing roundTripId beyond "test.notes@v2"/)
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
it('treats only the omitted and explicit false granular mandatory flag as revision-equivalent', async () => {
|
|
346
|
+
const base = 'app/src/modules/test'
|
|
347
|
+
const descriptorId = 'test.notes'
|
|
348
|
+
const runtimePath = `${base}/descriptor.client.ts`
|
|
349
|
+
const declarationPath = `${base}/form-sections.ts`
|
|
350
|
+
const generate = () => generateModuleRegistryApp({
|
|
351
|
+
resolver: resolver([{ id: 'test', from: '@app' }]), quiet: true,
|
|
352
|
+
})
|
|
353
|
+
const source = (version: number, flag = '', paths = "['name', 'note']", check = 'null') => `
|
|
354
|
+
import { defineCrudFormFieldGranularSection } from '@open-mercato/ui/backend/crud-form-field-granular'
|
|
355
|
+
export const crudFormSectionRuntime = defineCrudFormFieldGranularSection({
|
|
356
|
+
id: 'test.notes', roundTripId: 'test.notes@v${version}',
|
|
357
|
+
refinements: [{ id: 'filled', fieldPaths: ${paths}, ${flag} check: () => ${check} }] as const,
|
|
358
|
+
})
|
|
359
|
+
`
|
|
360
|
+
write(declarationPath, declaration(descriptorId))
|
|
361
|
+
write(runtimePath, source(1))
|
|
362
|
+
await generate()
|
|
363
|
+
write(runtimePath, source(1, 'mandatory: false,'))
|
|
364
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
365
|
+
for (const changed of [
|
|
366
|
+
source(1, 'mandatory: true,'),
|
|
367
|
+
source(1, '', "['note', 'name']"),
|
|
368
|
+
source(1, '', "['name', 'note']", "({ note: 'error.note' })"),
|
|
369
|
+
]) {
|
|
370
|
+
write(runtimePath, changed)
|
|
371
|
+
await expect(generate()).rejects.toThrow(/semantic runtime drift.*requires advancing roundTripId/)
|
|
372
|
+
}
|
|
373
|
+
write(declarationPath, declaration(descriptorId, { version: 2 }))
|
|
374
|
+
write(runtimePath, source(2, 'mandatory: true,'))
|
|
375
|
+
await generate()
|
|
376
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
it('exposes only literal host surface facts to the browser registry', async () => {
|
|
380
|
+
const base = 'app/src/modules/example'
|
|
381
|
+
write(`${base}/form-sections.ts`, `
|
|
382
|
+
import { defineCrudFormSections, lazyCrudFormSectionRuntime } from '@open-mercato/shared/modules/form-sections'
|
|
383
|
+
export const crudFormSections = defineCrudFormSections({
|
|
384
|
+
hostFacts: [{
|
|
385
|
+
id: 'example.host', roundTripId: 'example.host@v1', hostResourceKind: 'example.todo',
|
|
386
|
+
alternatives: [{ surface: {
|
|
387
|
+
id: 'example.base', hostId: 'example.todo', formVariant: 'default', formOperation: 'update',
|
|
388
|
+
orderedSectionIds: ['details'], callerIds: ['example.page'], contributionIds: [],
|
|
389
|
+
ownershipFacts: [], mutationSurfaceIds: [], dependencies: [],
|
|
390
|
+
}, activeDataContractIds: ['server-contract'] }],
|
|
391
|
+
}],
|
|
392
|
+
hostProviders: [{ hostDescriptorId: 'example.host', requireFeatures: [],
|
|
393
|
+
authorizeHost: async function serverAuthorization() { return null },
|
|
394
|
+
}],
|
|
395
|
+
runtimes: [{ id: 'example.host', roundTripId: 'example.host@v1',
|
|
396
|
+
load: lazyCrudFormSectionRuntime(() => import('./descriptor.client')),
|
|
397
|
+
}],
|
|
398
|
+
})
|
|
399
|
+
`)
|
|
400
|
+
write(`${base}/descriptor.client.ts`, runtime('example.host'))
|
|
401
|
+
await generateModuleRegistryApp({ resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true })
|
|
402
|
+
|
|
403
|
+
expect(generated('facts')).toContain('crudFormSectionServerModules')
|
|
404
|
+
expect(generated('runtime')).toContain('crudFormSectionClientHostFacts')
|
|
405
|
+
expect(generated('runtime')).toContain('"id": "example.base"')
|
|
406
|
+
expect(generated('runtime')).toContain('"hostResourceKind": "example.todo"')
|
|
407
|
+
expect(generated('runtime')).not.toMatch(/serverAuthorization|server-contract/)
|
|
408
|
+
expect(generated('runtime')).not.toContain('/form-sections"')
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
it('discovers a server-only leaf default without a browser descriptor or loader', async () => {
|
|
412
|
+
const onlyDefaults = `
|
|
413
|
+
import { defineCrudFormSections } from '@open-mercato/shared/modules/form-sections'
|
|
414
|
+
export const crudFormSections = defineCrudFormSections({
|
|
415
|
+
leafDefaultProviders: [{
|
|
416
|
+
fact: { id: 'example.code-default', roundTripId: 'example.code-default@v1',
|
|
417
|
+
hostId: 'example.todo', formVariant: 'default', formOperation: 'create', payloadPath: 'code', readsPayloadPaths: [] },
|
|
418
|
+
resolve() { return 'server-default-value' },
|
|
419
|
+
}],
|
|
420
|
+
})
|
|
421
|
+
`
|
|
422
|
+
write('app/src/modules/example/form-sections.ts', onlyDefaults)
|
|
423
|
+
await generateModuleRegistryApp({ resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true })
|
|
424
|
+
expect(generated('facts')).toContain('{ moduleId: "example", sections: sections0 }')
|
|
425
|
+
expect(generated('runtime')).not.toMatch(/code-default|server-default-value|\/form-sections"/)
|
|
426
|
+
write('app/src/modules/other/form-sections.ts', onlyDefaults)
|
|
427
|
+
await expect(generateModuleRegistryApp({
|
|
428
|
+
resolver: resolver([{ id: 'example', from: '@app' }, { id: 'other', from: '@app' }]), quiet: true,
|
|
429
|
+
})).rejects.toThrow(/Duplicate leaf default provider id/)
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
it('discovers sink declarations through the server registry and rejects mismatched owners', async () => {
|
|
433
|
+
const sinkDeclaration = `
|
|
434
|
+
export const crudFormSections = defineCrudFormSections({
|
|
435
|
+
sinks: [defineCrudFormSectionSink({
|
|
436
|
+
fact: { id: 'example.brand', roundTripId: 'example.brand@v1', ownerModuleId: 'example', atomicity: 'host-transaction' },
|
|
437
|
+
schema: serverOnlySchema,
|
|
438
|
+
persist: serverOnlyPersistence,
|
|
439
|
+
})],
|
|
440
|
+
})
|
|
441
|
+
`
|
|
442
|
+
const source = 'app/src/modules/example/form-sections.ts'
|
|
443
|
+
write(source, sinkDeclaration)
|
|
444
|
+
await generateModuleRegistryApp({ resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true })
|
|
445
|
+
expect(generated('facts')).toContain('{ moduleId: "example", sections: sections0 }')
|
|
446
|
+
expect(generated('runtime')).not.toMatch(/example.brand|serverOnly|\/form-sections"/)
|
|
447
|
+
write(source, sinkDeclaration.replace("ownerModuleId: 'example'", "ownerModuleId: 'other'"))
|
|
448
|
+
await expect(generateModuleRegistryApp({
|
|
449
|
+
resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true,
|
|
450
|
+
})).rejects.toThrow(/sink "example.brand" must be declared in its owning module/)
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
it('reads standalone npm dist .js declarations and runtime exports without a source mirror', async () => {
|
|
454
|
+
const base = 'package/dist/modules/installed'
|
|
455
|
+
write(`${base}/form-sections.js`, declaration('installed.notes')
|
|
456
|
+
.replace('export const crudFormSections', 'const crudFormSections')
|
|
457
|
+
.replace('./descriptor.client', './descriptor.client.js') + '\nexport { crudFormSections }\n')
|
|
458
|
+
write(`${base}/descriptor.client.js`, runtime('installed.notes')
|
|
459
|
+
.replace('export const crudFormSectionRuntime', 'const descriptor') + '\nexport { descriptor as crudFormSectionRuntime }\n')
|
|
460
|
+
await generateModuleRegistryApp({ resolver: resolver([{ id: 'installed' }], true), quiet: true })
|
|
461
|
+
expect(generated('facts')).toContain('"@open-mercato/core/modules/installed/form-sections"')
|
|
462
|
+
expect(generated('runtime')).toContain('import("@open-mercato/core/modules/installed/descriptor.client")')
|
|
463
|
+
expect(fs.existsSync(path.join(root, base, 'form-sections.runtime-revisions.json'))).toBe(false)
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
it('tracks package source mirror semantics while retaining the compiled loader contract', async () => {
|
|
467
|
+
const source = 'package/src/modules/mirrored'
|
|
468
|
+
const compiled = 'package/dist/modules/mirrored'
|
|
469
|
+
const id = 'mirrored.notes'
|
|
470
|
+
const fixture = resolver([{ id: 'mirrored' }], true)
|
|
471
|
+
const generate = () => generateModuleRegistryApp({ resolver: fixture, quiet: true })
|
|
472
|
+
write(`${source}/form-sections.ts`, declaration(id))
|
|
473
|
+
write(`${source}/descriptor.client.tsx`, runtime(id))
|
|
474
|
+
write(`${compiled}/form-sections.js`, declaration(id))
|
|
475
|
+
write(`${compiled}/descriptor.client.js`, runtime(id))
|
|
476
|
+
await generate()
|
|
477
|
+
|
|
478
|
+
expect(fs.existsSync(path.join(root, source, 'form-sections.runtime-revisions.json'))).toBe(true)
|
|
479
|
+
expect(fs.existsSync(path.join(root, compiled, 'form-sections.runtime-revisions.json'))).toBe(false)
|
|
480
|
+
expect(generated('runtime')).toContain('import("@open-mercato/core/modules/mirrored/descriptor.client")')
|
|
481
|
+
write(`${compiled}/descriptor.client.js`, runtime(id, 2))
|
|
482
|
+
await expect(generate()).rejects.toThrow(/loader declares "mirrored.notes@v1"/)
|
|
483
|
+
})
|
|
484
|
+
|
|
485
|
+
it.each([
|
|
486
|
+
['missing loader', { noLoader: true as const }, 1, /fact "test.notes" has no matching runtime loader/],
|
|
487
|
+
['missing fact', { noFact: true as const }, 1, /runtime loader "test.notes" has no matching fact/],
|
|
488
|
+
['fact and loader revision mismatch', { loaderVersion: 2 }, 2, /fact and runtime roundTripId differ/],
|
|
489
|
+
['loaded descriptor revision mismatch', {}, 2, /exports "test.notes@v2" but loader declares "test.notes@v1"/],
|
|
490
|
+
['non-literal import', { loader: 'lazyCrudFormSectionRuntime(() => import(runtimePath))' }, 1, /expected a non-empty literal runtime import specifier/],
|
|
491
|
+
])('rejects %s', async (_name, options, runtimeVersion, diagnostic) => {
|
|
492
|
+
const base = 'app/src/modules/test'
|
|
493
|
+
write(`${base}/form-sections.ts`, declaration('test.notes', options))
|
|
494
|
+
write(`${base}/descriptor.client.ts`, runtime('test.notes', runtimeVersion))
|
|
495
|
+
await expect(generateModuleRegistryApp({ resolver: resolver([{ id: 'test', from: '@app' }]), quiet: true })).rejects.toThrow(diagnostic)
|
|
496
|
+
})
|
|
497
|
+
|
|
498
|
+
it('extracts named runtime helper identities without importing the client module', async () => {
|
|
499
|
+
write('app/src/modules/example/form-sections.ts', declaration('example.notes'))
|
|
500
|
+
write('app/src/modules/example/descriptor.client.ts', `
|
|
501
|
+
import { defineCrudFormSectionRuntime } from '@open-mercato/ui/backend/injection/crud-form-section-runtime'
|
|
502
|
+
export const crudFormSectionRuntime = defineCrudFormSectionRuntime({
|
|
503
|
+
id: 'example.notes', roundTripId: 'example.notes@v1', group: createClientOnlyGroup(),
|
|
504
|
+
})
|
|
505
|
+
`)
|
|
506
|
+
await generateModuleRegistries({ resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true })
|
|
507
|
+
expect(generated('runtime')).toContain('load: () => import("../../src/modules/example/descriptor.client")')
|
|
508
|
+
})
|
|
509
|
+
|
|
510
|
+
it.each(['authored', 'built mirror'])('rejects a %s runtime linked outside its module', async (location) => {
|
|
511
|
+
const source = 'package/src/modules/test'
|
|
512
|
+
const mirror = 'package/dist/modules/test'
|
|
513
|
+
const id = 'test.notes'
|
|
514
|
+
write(`${source}/form-sections.ts`, declaration(id))
|
|
515
|
+
write(`${mirror}/form-sections.js`, declaration(id))
|
|
516
|
+
write('disabled/descriptor.client.ts', runtime(id))
|
|
517
|
+
if (location === 'authored') {
|
|
518
|
+
fs.symlinkSync(path.join(root, 'disabled/descriptor.client.ts'), path.join(root, source, 'descriptor.client.ts'))
|
|
519
|
+
write(`${mirror}/descriptor.client.js`, runtime(id))
|
|
520
|
+
} else {
|
|
521
|
+
write(`${source}/descriptor.client.ts`, runtime(id))
|
|
522
|
+
fs.symlinkSync(path.join(root, 'disabled/descriptor.client.ts'), path.join(root, mirror, 'descriptor.client.js'))
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
await expect(generateModuleRegistryApp({ resolver: resolver([{ id: 'test' }], true), quiet: true }))
|
|
526
|
+
.rejects.toThrow(/runtime import .* escapes the owning module/)
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
it('rejects descriptor ids repeated across enabled modules', async () => {
|
|
530
|
+
for (const moduleId of ['alpha', 'beta']) {
|
|
531
|
+
write(`app/src/modules/${moduleId}/form-sections.ts`, declaration('test.notes'))
|
|
532
|
+
write(`app/src/modules/${moduleId}/descriptor.client.ts`, runtime('test.notes'))
|
|
533
|
+
}
|
|
534
|
+
await expect(generateModuleRegistryApp({
|
|
535
|
+
resolver: resolver([{ id: 'alpha', from: '@app' }, { id: 'beta', from: '@app' }]),
|
|
536
|
+
quiet: true,
|
|
537
|
+
})).rejects.toThrow(/Duplicate form-sections descriptor id "test.notes" in "alpha" and "beta"/)
|
|
538
|
+
})
|
|
539
|
+
})
|
|
540
|
+
|
|
541
|
+
const plainDerivedRoute = `
|
|
542
|
+
import { z } from 'zod'
|
|
543
|
+
import { makeCrudRoute } from '@open-mercato/shared/lib/crud/factory'
|
|
544
|
+
export const crudRoute = makeCrudRoute({
|
|
545
|
+
metadata: {
|
|
546
|
+
POST: { requireAuth: true, requireFeatures: ['example.manage'] },
|
|
547
|
+
PUT: { requireAuth: true },
|
|
548
|
+
DELETE: { requireAuth: true, requireFeatures: ['example.manage'] },
|
|
549
|
+
},
|
|
550
|
+
orm: { entity: ExampleRecord },
|
|
551
|
+
actions: {
|
|
552
|
+
create: { commandId: 'example.records.create', schema: z.object({ name: z.string() }) },
|
|
553
|
+
update: { commandId: 'example.records.update', mapInput: ({ parsed }) => parsed },
|
|
554
|
+
delete: { commandId: 'example.records.delete' },
|
|
555
|
+
},
|
|
556
|
+
})
|
|
557
|
+
export const { metadata, POST, PUT, DELETE } = crudRoute
|
|
558
|
+
`
|
|
559
|
+
|
|
560
|
+
const derivedDeclaration = `
|
|
561
|
+
import { defineCrudFormSections, lazyCrudFormSectionRuntime } from '@open-mercato/shared/modules/form-sections'
|
|
562
|
+
import { defineCrudRouteSectionHost } from '@open-mercato/shared/lib/crud/form-sections/derived-route-host'
|
|
563
|
+
import { crudRoute } from './api/records/route'
|
|
564
|
+
export const crudFormSections = defineCrudFormSections({
|
|
565
|
+
hostFacts: [{
|
|
566
|
+
id: 'example.edit-rec', roundTripId: 'example.edit-rec@v1', hostResourceKind: 'example.records',
|
|
567
|
+
alternatives: [{ surface: {
|
|
568
|
+
id: 'example.edit-base', hostId: 'example.record', formVariant: 'default', formOperation: 'update',
|
|
569
|
+
orderedSectionIds: ['details'], callerIds: [], contributionIds: [],
|
|
570
|
+
ownershipFacts: [], mutationSurfaceIds: [], dependencies: [],
|
|
571
|
+
} }],
|
|
572
|
+
}],
|
|
573
|
+
derivedHosts: [defineCrudRouteSectionHost({
|
|
574
|
+
hostId: 'example.record', formVariant: 'default', formOperation: 'update', hostDescriptorId: 'example.edit-rec',
|
|
575
|
+
route: crudRoute, sections: [{ id: 'details', writes: 'parent' }],
|
|
576
|
+
delete: { proof: { finalInput: 'transactional-final-input/v1' } },
|
|
577
|
+
})],
|
|
578
|
+
runtimes: [{ id: 'example.edit-rec', roundTripId: 'example.edit-rec@v1',
|
|
579
|
+
load: lazyCrudFormSectionRuntime(() => import('./descriptor.client')),
|
|
580
|
+
}],
|
|
581
|
+
})
|
|
582
|
+
`
|
|
583
|
+
|
|
584
|
+
function writeDerivedFixture(base: string, declarationSource = derivedDeclaration, routeSource = plainDerivedRoute, ext = 'ts'): void {
|
|
585
|
+
write(`${base}/form-sections.${ext}`, declarationSource)
|
|
586
|
+
write(`${base}/api/records/route.${ext}`, routeSource)
|
|
587
|
+
write(`${base}/descriptor.client.${ext}`, runtime('example.edit-rec'))
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
describe('derived CRUD section route generation', () => {
|
|
591
|
+
it('emits one standalone-compatible façade into the static client, runtime, shard and docs route indices', async () => {
|
|
592
|
+
writeDerivedFixture('app/src/modules/example')
|
|
593
|
+
const fixture = resolver([{ id: 'example', from: '@app' }])
|
|
594
|
+
await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
595
|
+
const [derived] = readDerivedCrudFormSectionRouteIndex(fixture.getOutputDir())
|
|
596
|
+
expect(derived).toMatchObject({ moduleId: 'example', routePath: '/example/records/section-policy', methods: ['DELETE', 'PUT'] })
|
|
597
|
+
const content = fs.readFileSync(path.join(fixture.getOutputDir(), derived.fileName), 'utf8')
|
|
598
|
+
expect(content).toContain('export const PUT = facade.handlers.PUT!')
|
|
599
|
+
expect(content).toContain('export const DELETE = facade.handlers.DELETE!')
|
|
600
|
+
expect(content).not.toContain('export const POST')
|
|
601
|
+
expect(content).toContain('export const openApi = facade.openApi')
|
|
602
|
+
for (const fileName of ['api-routes.generated.ts', 'api-route-metadata.generated.ts', 'modules.runtime.generated.ts']) {
|
|
603
|
+
expect(fs.readFileSync(path.join(fixture.getOutputDir(), fileName), 'utf8')).toContain('/example/records/section-policy')
|
|
604
|
+
}
|
|
605
|
+
const docsIndex = path.join(fixture.getOutputDir(), generatedDerivedCrudRouteIndex)
|
|
606
|
+
expect(fs.readFileSync(docsIndex, 'utf8')).toContain('/example/records/section-policy')
|
|
607
|
+
expect(generated('facts')).toContain('bindDerivedCrudRouteSectionHosts')
|
|
608
|
+
expect(generated('runtime')).toContain('"example.edit-rec.update"')
|
|
609
|
+
expect(generated('runtime')).toContain('"clientMutationSurfaces"')
|
|
610
|
+
expect(generated('runtime')).toContain('"routePattern": "/example/records/section-policy"')
|
|
611
|
+
expect(generated('runtime')).toContain('"method": "DELETE"')
|
|
612
|
+
expect(generated('runtime')).not.toContain('example.records.update')
|
|
613
|
+
expect(generated('runtime')).not.toContain('createDerivedCrudFormSectionFacade')
|
|
614
|
+
const second = await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
615
|
+
expect(second.flatMap((result) => result.filesWritten)).toEqual([])
|
|
616
|
+
})
|
|
617
|
+
|
|
618
|
+
it('recognizes the original route binding from packaged JS', async () => {
|
|
619
|
+
writeDerivedFixture('package/dist/modules/example', derivedDeclaration.replace("'./api/records/route'", "'./api/records/route.js'"), plainDerivedRoute, 'js')
|
|
620
|
+
const fixture = resolver([{ id: 'example' }], true)
|
|
621
|
+
await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
622
|
+
const [derived] = readDerivedCrudFormSectionRouteIndex(fixture.getOutputDir())
|
|
623
|
+
expect(fs.readFileSync(path.join(fixture.getOutputDir(), derived.fileName), 'utf8'))
|
|
624
|
+
.toContain('@open-mercato/core/modules/example/form-sections')
|
|
625
|
+
})
|
|
626
|
+
|
|
627
|
+
it.each([
|
|
628
|
+
['secondary write', derivedDeclaration.replace("writes: 'parent'", "writes: 'child'"), plainDerivedRoute, /secondary write/],
|
|
629
|
+
['unknown route factory', derivedDeclaration, plainDerivedRoute.replace('= makeCrudRoute({', '= differentFactory({'), /named original makeCrudRoute/],
|
|
630
|
+
['custom command mapper', derivedDeclaration, plainDerivedRoute.replace('=> parsed', '=> ({ body: parsed })'), /requires direct command input/],
|
|
631
|
+
])('rejects %s as a failed qualifier', async (_name, formSource, routeSource, diagnostic) => {
|
|
632
|
+
writeDerivedFixture('app/src/modules/example', formSource, routeSource)
|
|
633
|
+
await expect(generateModuleRegistries({
|
|
634
|
+
resolver: resolver([{ id: 'example', from: '@app' }]), quiet: true,
|
|
635
|
+
})).rejects.toThrow(diagnostic)
|
|
636
|
+
})
|
|
637
|
+
})
|
|
638
|
+
|
|
639
|
+
it('projects a hand-written child façade without exposing its delegated command or binding definitions', async () => {
|
|
640
|
+
const source = derivedDeclaration
|
|
641
|
+
.replace("import { crudRoute } from './api/records/route'", '')
|
|
642
|
+
.replace(/derivedHosts: \[defineCrudRouteSectionHost\(\{[\s\S]*?\}\)\],/, '')
|
|
643
|
+
.replace('mutationSurfaceIds: [], dependencies: [],\n } }]', `mutationSurfaceIds: ['example.offer.update'], dependencies: [],
|
|
644
|
+
}, mutationSurfaces: [{
|
|
645
|
+
id: 'example.offer.update', kind: 'section-action', requestOperation: 'update',
|
|
646
|
+
guardedFacade: { method: 'PATCH', routePattern: '/example/records/[parentId]/offers/[offerId]' },
|
|
647
|
+
hostResourceKind: 'example.records', mutationResourceKind: 'example.offer', optimisticLock: 'target-required',
|
|
648
|
+
delegatedTarget: { kind: 'command', id: 'secret.server.command' }, resourceBindingIds: ['server.binding.v1'],
|
|
649
|
+
}] }]`)
|
|
650
|
+
write('app/src/modules/example/form-sections.ts', source)
|
|
651
|
+
write('app/src/modules/example/descriptor.client.ts', runtime('example.edit-rec'))
|
|
652
|
+
const fixture = resolver([{ id: 'example', from: '@app' }])
|
|
653
|
+
await generateModuleRegistries({ resolver: fixture, quiet: true })
|
|
654
|
+
expect(generated('runtime')).toContain('"routePattern": "/example/records/[parentId]/offers/[offerId]"')
|
|
655
|
+
expect(generated('runtime')).toContain('"optimisticLock": "target-required"')
|
|
656
|
+
expect(generated('runtime')).not.toMatch(/secret\.server\.command|server\.binding\.v1/)
|
|
657
|
+
})
|
|
658
|
+
|
|
659
|
+
describe('compiled CrudForm extensions', () => {
|
|
660
|
+
const address = { hostId: 'test.record', formVariant: 'edit', formOperation: 'update' }
|
|
661
|
+
const base = {
|
|
662
|
+
...address, id: 'test.edit', orderedSectionIds: ['details', 'private'], callerIds: ['test.editor'],
|
|
663
|
+
contributionIds: [], dependencies: [], mutationSurfaceIds: ['test.submit'],
|
|
664
|
+
ownershipFacts: [
|
|
665
|
+
{ sectionId: 'details', payloadPaths: ['title', 'description'], customFieldOwnership: { mode: 'ids', ids: ['region'], definitionSetId: 'test.fields' } },
|
|
666
|
+
{ sectionId: 'private', payloadPaths: ['code'], customFieldOwnership: { mode: 'none' } },
|
|
667
|
+
],
|
|
668
|
+
}
|
|
669
|
+
const submit = {
|
|
670
|
+
id: 'test.submit', kind: 'parent-submit', requestOperation: 'update',
|
|
671
|
+
guardedFacade: { method: 'PUT', routePattern: '/test/records/section-policy' },
|
|
672
|
+
delegatedTarget: { kind: 'command', id: 'test.update' },
|
|
673
|
+
hostResourceKind: 'test.record', mutationResourceKind: 'test.record', optimisticLock: 'none',
|
|
674
|
+
}
|
|
675
|
+
const authoredId = 'extension.patch'
|
|
676
|
+
const makeExtension = (sections: string, defaults = '{}', id = authoredId, targets = "[{ formVariant: 'edit', formOperation: 'update' }]") => `
|
|
677
|
+
import { defineCrudFormExtension, modify, add, hide, replace, field, store } from '@open-mercato/ui/backend/crud-form-extensions'
|
|
678
|
+
const serverOnlyRule = async () => 'extension.errors.denied'
|
|
679
|
+
export const crudFormExtensions = [defineCrudFormExtension({
|
|
680
|
+
id: ${JSON.stringify(id)}, host: 'crud-form:test.record', targets: ${targets},
|
|
681
|
+
sections: { ${sections} }, defaults: ${defaults},
|
|
682
|
+
})]
|
|
683
|
+
`
|
|
684
|
+
|
|
685
|
+
function host(mandatory = false, secondTarget = false) {
|
|
686
|
+
const manual = {
|
|
687
|
+
id: 'test.manual', roundTripId: 'test.manual@v1', operation: 'add', address: { ...address, sectionId: 'manual' },
|
|
688
|
+
requiredCapabilities: [],
|
|
689
|
+
}
|
|
690
|
+
const hostFacts = [{
|
|
691
|
+
id: 'test.host', roundTripId: 'test.host@v1', hostResourceKind: 'test.record', customFieldSeedEntities: { 'test.fields': 'test:record' },
|
|
692
|
+
alternatives: [
|
|
693
|
+
{ surface: base, mutationSurfaces: [submit] },
|
|
694
|
+
{ surface: { ...base, id: 'test.manual-edit', orderedSectionIds: ['details', 'private', 'manual'], contributionIds: [manual.id] }, mutationSurfaces: [submit] },
|
|
695
|
+
...(secondTarget ? [{ surface: { ...base, id: 'test.edit-other', formVariant: 'other' }, mutationSurfaces: [submit] }] : []),
|
|
696
|
+
],
|
|
697
|
+
}]
|
|
698
|
+
write('app/src/modules/host/form-sections.ts', `
|
|
699
|
+
export const crudFormSections = defineCrudFormSections({
|
|
700
|
+
hostFacts: ${JSON.stringify(hostFacts)}, contributionFacts: [${JSON.stringify(manual)}],
|
|
701
|
+
contributedOverrides: { 'test.record/edit/update/manual': { operation: 'add', contributionId: 'test.manual' } },
|
|
702
|
+
runtimes: [
|
|
703
|
+
{ id: 'test.host', roundTripId: 'test.host@v1', load: lazyCrudFormSectionRuntime(() => import('./host.client')) },
|
|
704
|
+
{ id: 'test.manual', roundTripId: 'test.manual@v1', load: lazyCrudFormSectionRuntime(() => import('./manual.client')) },
|
|
705
|
+
],
|
|
706
|
+
})
|
|
707
|
+
`)
|
|
708
|
+
write('app/src/modules/host/host.client.ts', `
|
|
709
|
+
const details = defineCrudFormFieldGranularSection({
|
|
710
|
+
id: 'test.details', roundTripId: 'test.details@v1', group: { id: 'details' },
|
|
711
|
+
fields: [], fieldPayloadPaths: { title: ['title'], description: ['description'] },
|
|
712
|
+
fieldSchemas: {}, projectField: {},
|
|
713
|
+
refinements: [{ id: 'summary', fieldPaths: ['description'], mandatory: ${mandatory}, check: () => null }],
|
|
714
|
+
})
|
|
715
|
+
const secret = defineCrudFormSectionRuntime({
|
|
716
|
+
id: 'test.private', roundTripId: 'test.private@v1', group: { id: 'private' },
|
|
717
|
+
ownedFieldPaths: ['code'], validate: () => ({ success: true, data: {} }), projectPayload: () => ({}),
|
|
718
|
+
})
|
|
719
|
+
export const crudFormSectionRuntime = {
|
|
720
|
+
id: 'test.host', roundTripId: 'test.host@v1', sectionDescriptors: [details, secret],
|
|
721
|
+
}
|
|
722
|
+
`)
|
|
723
|
+
write('app/src/modules/host/manual.client.ts', runtime(manual.id))
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
function generate(entries: ModuleEntry[] = [{ id: 'extension', from: '@app' }]) {
|
|
727
|
+
return generateModuleRegistryApp({ resolver: resolver([{ id: 'host', from: '@app' }, ...entries]), quiet: true })
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
it('compiles mixed finite alternatives and binds browser and server implementations to the same revision', async () => {
|
|
731
|
+
host()
|
|
732
|
+
const optionValue = 'draft<internal>\u2028pending'
|
|
733
|
+
const definition = makeExtension(`
|
|
734
|
+
details: modify({ fields: {
|
|
735
|
+
title: field.patch({ labelKey: 'extension.fields.title', validate: { server: serverOnlyRule, minLength: 2, enforce: 'client-and-server', messageKey: 'extension.errors.short' } }),
|
|
736
|
+
description: field.remove(),
|
|
737
|
+
} }),
|
|
738
|
+
private: hide(),
|
|
739
|
+
extra: add({ after: 'details', titleKey: 'extension.extra', fields: {
|
|
740
|
+
alias: field.add({ type: 'select', options: [{ value: ${JSON.stringify(optionValue)}, labelKey: 'extension.options.draft' }] }),
|
|
741
|
+
} }),
|
|
742
|
+
`, "{ description: ({ payload }) => String(payload.title ?? '') }")
|
|
743
|
+
write('app/src/modules/extension/form-sections.ts', definition)
|
|
744
|
+
await generate()
|
|
745
|
+
const dir = path.join(root, 'app/.mercato/generated')
|
|
746
|
+
const browser = fs.readdirSync(dir).filter((file) => /^crud-form-section-extension-.*\.ts$/.test(file))
|
|
747
|
+
.map((file) => fs.readFileSync(path.join(dir, file), 'utf8')).join('\n')
|
|
748
|
+
const ledger = path.join(root, 'app/src/modules/extension/form-sections.revisions.json')
|
|
749
|
+
expect(JSON.parse(fs.readFileSync(ledger, 'utf8'))).toMatchObject({
|
|
750
|
+
'extension.patch.details': { n: 1, baseRoundTripId: 'test.details@v1' },
|
|
751
|
+
'extension.patch.extra': { n: 1, baseRoundTripId: null },
|
|
752
|
+
'extension.patch.private': { n: 1, baseRoundTripId: 'test.private@v1' },
|
|
753
|
+
})
|
|
754
|
+
expect(browser).toContain('deriveCrudFormFieldGranularSection')
|
|
755
|
+
expect(browser).toContain('customFields.alias')
|
|
756
|
+
const encodedValue = browser.match(/"value":("draft[^"]+")/)?.[1]
|
|
757
|
+
expect(encodedValue).toBe('"draft\\u003cinternal\\u003e\\u2028pending"')
|
|
758
|
+
expect(JSON.parse(encodedValue!)).toBe(optionValue)
|
|
759
|
+
expect(browser).toContain('extension.fields.title')
|
|
760
|
+
expect(browser).not.toMatch(/serverOnlyRule|\.validate\.server|\.defaults|form-sections["']/)
|
|
761
|
+
expect(generated('facts')).toContain('.validate.server')
|
|
762
|
+
expect(generated('facts')).toContain('"readsPayloadPaths":["title"]')
|
|
763
|
+
expect(generated('facts')).toContain('extensions0[0].defaults["description"]')
|
|
764
|
+
expect(generated('runtime')).toContain('extension.patch.details@v1')
|
|
765
|
+
expect(generated('runtime')).toMatch(/"contributionIds": \[\s+"extension.patch.details",\s+"extension.patch.extra",\s+"extension.patch.private",\s+"test.manual"/)
|
|
766
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
767
|
+
const baseFile = 'app/src/modules/host/host.client.ts'
|
|
768
|
+
const baseRuntime = fs.readFileSync(path.join(root, baseFile), 'utf8')
|
|
769
|
+
write(baseFile, baseRuntime.replace('mandatory: false, ', ''))
|
|
770
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
771
|
+
write('app/src/modules/extension/form-sections.ts', definition.replace('extension.errors.denied', 'extension.errors.new-deny'))
|
|
772
|
+
await generate()
|
|
773
|
+
expect(JSON.parse(fs.readFileSync(ledger, 'utf8'))).toMatchObject({
|
|
774
|
+
'extension.patch.details': { n: 2 }, 'extension.patch.extra': { n: 1 }, 'extension.patch.private': { n: 1 },
|
|
775
|
+
})
|
|
776
|
+
})
|
|
777
|
+
|
|
778
|
+
it('rejects field patches against a section without a granular field contract', async () => {
|
|
779
|
+
host()
|
|
780
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(
|
|
781
|
+
"private: modify({ fields: { code: field.patch({ labelKey: 'extension.fields.code' }) } })",
|
|
782
|
+
))
|
|
783
|
+
await expect(generate()).rejects.toThrow(/granular|component-only/i)
|
|
784
|
+
})
|
|
785
|
+
|
|
786
|
+
it('rejects removal of a mandatory refinement and replacement with different ownership', async () => {
|
|
787
|
+
host(true)
|
|
788
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension("details: modify({ fields: { description: field.remove() } })"))
|
|
789
|
+
await expect(generate()).rejects.toThrow(/mandatory refinement "summary"/)
|
|
790
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension("private: replace(() => import('./replace.client'))"))
|
|
791
|
+
write('app/src/modules/extension/replace.client.ts', `
|
|
792
|
+
export const crudFormSectionRuntime = { id: 'extension.replacement', roundTripId: 'extension.replacement@v1',
|
|
793
|
+
group: { id: 'private' }, ownedFieldPaths: ['unrelated'] }
|
|
794
|
+
`)
|
|
795
|
+
await expect(generate()).rejects.toThrow(/replacement must preserve exact payload ownership/)
|
|
796
|
+
write('app/src/modules/extension/replace.client.ts', `
|
|
797
|
+
export const crudFormSectionRuntime = { id: 'extension.replacement', roundTripId: 'extension.replacement@v1',
|
|
798
|
+
group: { id: 'private' }, ownedFieldPaths: ['code'] }
|
|
799
|
+
`)
|
|
800
|
+
await generate()
|
|
801
|
+
expect(generated('runtime')).toContain('extension.patch.private@v1')
|
|
802
|
+
})
|
|
803
|
+
|
|
804
|
+
it('requires conflict resolution by exact module selector or null and retains both runtime choices', async () => {
|
|
805
|
+
host()
|
|
806
|
+
const patch = "details: modify({ fields: { title: field.patch({ labelKey: 'extension.fields.title' }) } })"
|
|
807
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(patch))
|
|
808
|
+
write('app/src/modules/secondary/form-sections.ts', makeExtension(patch, '{}', 'secondary.patch'))
|
|
809
|
+
const entries = [{ id: 'extension', from: '@app' }, { id: 'secondary', from: '@app' }] satisfies ModuleEntry[]
|
|
810
|
+
await expect(generate(entries)).rejects.toThrow(/extension, secondary.*exact modules.ts selector or null/)
|
|
811
|
+
const key = 'test.record/edit/update/details'
|
|
812
|
+
await generate([{ ...entries[0], formSectionOverrides: { [key]: null } }, entries[1]])
|
|
813
|
+
expect(generated('runtime')).toContain('extension.patch.details@v1')
|
|
814
|
+
expect(generated('runtime')).toContain('secondary.patch.details@v1')
|
|
815
|
+
await generate([{ ...entries[0], formSectionOverrides: { [key]: { contributionId: 'secondary.patch.details', operation: 'replace' } } }, entries[1]])
|
|
816
|
+
expect(generated('runtime')).toContain('secondary.patch.details@v1')
|
|
817
|
+
})
|
|
818
|
+
|
|
819
|
+
it('rejects a default that reads a masked field and permits a conflict mask for overlapping custom keys', async () => {
|
|
820
|
+
host()
|
|
821
|
+
const definition = makeExtension("details: modify({ fields: { title: field.remove(), description: field.remove() } })",
|
|
822
|
+
"{ description: ({ payload }) => String(payload.title) }")
|
|
823
|
+
write('app/src/modules/extension/form-sections.ts', definition)
|
|
824
|
+
await expect(generate()).rejects.toThrow(/effective alternatives.*conflicting fields, defaults/)
|
|
825
|
+
const patch = (fieldId: string) => `details: modify({ fields: { ${fieldId}: field.add({ type: 'text', store: store.customField('shared') }) } })`
|
|
826
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(patch('firstField')))
|
|
827
|
+
write('app/src/modules/secondary/form-sections.ts', makeExtension(patch('secondField'), '{}', 'secondary.patch'))
|
|
828
|
+
const entries = [{ id: 'extension', from: '@app' }, { id: 'secondary', from: '@app' }] satisfies ModuleEntry[]
|
|
829
|
+
await expect(generate(entries)).rejects.toThrow(/requires an exact modules.ts selector or null/)
|
|
830
|
+
await generate([{ ...entries[0], formSectionOverrides: { 'test.record/edit/update/details': null } }, entries[1]])
|
|
831
|
+
expect(generated('runtime')).not.toContain('combined-')
|
|
832
|
+
})
|
|
833
|
+
|
|
834
|
+
it('emits versioned store associations without letting storage callbacks reach browser modules', async () => {
|
|
835
|
+
host()
|
|
836
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(`
|
|
837
|
+
erp: add({ fields: { erpSupplierRef: field.add({ type: 'text' }), erpCostCenter: field.add({ type: 'text' }) },
|
|
838
|
+
store: store.external({ integrationId: 'erp', mirror: 'extension:erp_link', deliver: serverOnlyRule }) }),
|
|
839
|
+
`))
|
|
840
|
+
await generate()
|
|
841
|
+
const facts = generated('facts')
|
|
842
|
+
expect(facts).toContain('"ownerModuleId":"extension"')
|
|
843
|
+
expect(facts).toContain('"payloadPaths":["extensions.extension.erpSupplierRef","extensions.extension.erpCostCenter"]')
|
|
844
|
+
expect(facts).toContain('"modes":["extension-sink"]')
|
|
845
|
+
expect(facts).toContain('.options.store')
|
|
846
|
+
expect(facts).toContain("export { entities as crudFormSectionOrmEntities } from './entities.generated'")
|
|
847
|
+
const dir = path.join(root, 'app/.mercato/generated')
|
|
848
|
+
const browser = fs.readdirSync(dir).filter((file) => /^crud-form-section-extension-.*\.ts$/.test(file))
|
|
849
|
+
.map((file) => fs.readFileSync(path.join(dir, file), 'utf8')).join('\n')
|
|
850
|
+
expect(browser).toContain('extensions.extension.erpSupplierRef')
|
|
851
|
+
expect(browser).not.toMatch(/serverOnlyRule|integrationId|erp_link|deliver|crudFormSectionOrmEntities/)
|
|
852
|
+
})
|
|
853
|
+
|
|
854
|
+
it('feeds compiled custom fields into all ordinary ce.ts seed registries and excludes masked fields', async () => {
|
|
855
|
+
host()
|
|
856
|
+
write('app/src/modules/extension/ce.ts', `export const entities = [
|
|
857
|
+
{ id: 'test:record', fields: [{ key: 'manual_ce', kind: 'text' }] },
|
|
858
|
+
]`)
|
|
859
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(`
|
|
860
|
+
extra: add({ fields: { brandName: field.add({ type: 'text', labelKey: 'extension.fields.brand', store: store.customField('brand_name') }) } }),
|
|
861
|
+
`))
|
|
862
|
+
const generateSeeds = (mask: boolean) => generateModuleRegistries({ resolver: resolver([
|
|
863
|
+
{ id: 'host', from: '@app' }, { id: 'extension', from: '@app',
|
|
864
|
+
...(mask ? { formSectionOverrides: { 'test.record/edit/update/extra': null } } : {}) },
|
|
865
|
+
]), quiet: true })
|
|
866
|
+
const readRegistries = () => ['modules.generated.ts', 'modules.bootstrap.generated.ts', 'modules.cli.generated.ts'].map((name) =>
|
|
867
|
+
fs.readFileSync(path.join(root, 'app/.mercato/generated', name), 'utf8'))
|
|
868
|
+
await generateSeeds(false)
|
|
869
|
+
for (const output of readRegistries()) {
|
|
870
|
+
expect(output).toContain('extension/ce')
|
|
871
|
+
expect(output).toContain('"brand_name"')
|
|
872
|
+
expect(output).toMatch(/"entity":\s*"test:record"/)
|
|
873
|
+
}
|
|
874
|
+
expect(generated('facts')).toContain('"definitionSetId":"test.fields","entityId":"test:record","key":"brand_name","kind":"text"')
|
|
875
|
+
expect(generated('runtime')).not.toContain('test:record')
|
|
876
|
+
await generateSeeds(true)
|
|
877
|
+
for (const output of readRegistries()) {
|
|
878
|
+
expect(output).toContain('extension/ce')
|
|
879
|
+
expect(output).not.toContain('brand_name')
|
|
880
|
+
}
|
|
881
|
+
})
|
|
882
|
+
|
|
883
|
+
it('keeps target-scoped descriptor IDs and revisions stable when target order changes', async () => {
|
|
884
|
+
host(false, true)
|
|
885
|
+
const patch = "details: modify({ fields: { title: field.patch({ labelKey: 'extension.fields.title' }) } })"
|
|
886
|
+
const target = (variant: string) => `{formVariant:${JSON.stringify(variant)},formOperation:'update'}`
|
|
887
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(patch, '{}', authoredId, `[${target('edit')},${target('other')}]`))
|
|
888
|
+
await generate()
|
|
889
|
+
const output = generated('runtime')
|
|
890
|
+
expect(output).toContain('extension.patch.edit.update.details@v1')
|
|
891
|
+
expect(output).toContain('extension.patch.other.update.details@v1')
|
|
892
|
+
write('app/src/modules/extension/form-sections.ts', makeExtension(patch, '{}', authoredId, `[${target('other')},${target('edit')}]`))
|
|
893
|
+
expect((await generate()).filesWritten).toEqual([])
|
|
894
|
+
expect(generated('runtime')).toBe(output)
|
|
895
|
+
})
|
|
896
|
+
})
|