@wildo-ai/platform-config-lib 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts +3 -2
- package/dist/esm/bootstrap/bootstrap.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.contracts.js +3 -2
- package/dist/esm/bootstrap/bootstrap.contracts.js.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts +47 -0
- package/dist/esm/bootstrap/bootstrap.schemas.d.ts.map +1 -1
- package/dist/esm/bootstrap/bootstrap.schemas.js +8 -0
- package/dist/esm/bootstrap/bootstrap.schemas.js.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts +12 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js +12 -0
- package/dist/esm/bootstrap/platform-runtime-env.contracts.js.map +1 -1
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts +37 -0
- package/dist/esm/bootstrap/platform-store-preconnect.d.ts.map +1 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js +43 -0
- package/dist/esm/bootstrap/platform-store-preconnect.js.map +1 -0
- package/dist/esm/bootstrap/runtime-backing-service-access.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-backing-service-access.js +8 -4
- package/dist/esm/bootstrap/runtime-backing-service-access.js.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts +36 -3
- package/dist/esm/bootstrap/runtime-topology.contracts.d.ts.map +1 -1
- package/dist/esm/bootstrap/runtime-topology.contracts.js +36 -13
- package/dist/esm/bootstrap/runtime-topology.contracts.js.map +1 -1
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lockfile/lockfile-io.d.ts +7 -1
- package/dist/esm/lockfile/lockfile-io.d.ts.map +1 -1
- package/dist/esm/lockfile/lockfile-io.js +17 -3
- package/dist/esm/lockfile/lockfile-io.js.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.d.ts +27 -6
- package/dist/esm/lockfile/materialize-infra-section.d.ts.map +1 -1
- package/dist/esm/lockfile/materialize-infra-section.js +23 -10
- package/dist/esm/lockfile/materialize-infra-section.js.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts +455 -6
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.d.ts.map +1 -1
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js +27 -0
- package/dist/esm/lockfile/wildo-saas-lock.shared.schemas.js.map +1 -1
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts +13 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.d.ts.map +1 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js +56 -0
- package/dist/esm/project-config/application-public-pricing-catalog.loader.js.map +1 -0
- package/dist/esm/project-config/define-infra-env-config.d.ts +0 -27
- package/dist/esm/project-config/define-infra-env-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-infra-env-config.js +0 -2
- package/dist/esm/project-config/define-infra-env-config.js.map +1 -1
- package/dist/esm/project-config/define-saas-config.d.ts +52 -0
- package/dist/esm/project-config/define-saas-config.d.ts.map +1 -1
- package/dist/esm/project-config/define-saas-config.js +65 -15
- package/dist/esm/project-config/define-saas-config.js.map +1 -1
- package/dist/esm/project-config/index.d.ts +3 -0
- package/dist/esm/project-config/index.d.ts.map +1 -1
- package/dist/esm/project-config/index.js +3 -0
- package/dist/esm/project-config/index.js.map +1 -1
- package/dist/esm/project-config/loader.d.ts +11 -0
- package/dist/esm/project-config/loader.d.ts.map +1 -1
- package/dist/esm/project-config/loader.js +34 -7
- package/dist/esm/project-config/loader.js.map +1 -1
- package/dist/esm/project-config/npm-version-range.d.ts +23 -0
- package/dist/esm/project-config/npm-version-range.d.ts.map +1 -0
- package/dist/esm/project-config/npm-version-range.js +175 -0
- package/dist/esm/project-config/npm-version-range.js.map +1 -0
- package/dist/esm/project-config/provider-companion-discovery.d.ts +256 -30
- package/dist/esm/project-config/provider-companion-discovery.d.ts.map +1 -1
- package/dist/esm/project-config/provider-companion-discovery.js +719 -40
- package/dist/esm/project-config/provider-companion-discovery.js.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts +125 -2
- package/dist/esm/project-config/provider-runtime-artifacts.d.ts.map +1 -1
- package/dist/esm/project-config/provider-runtime-artifacts.js +283 -66
- package/dist/esm/project-config/provider-runtime-artifacts.js.map +1 -1
- package/dist/esm/project-config/shared/backing-service-servability.d.ts +157 -0
- package/dist/esm/project-config/shared/backing-service-servability.d.ts.map +1 -0
- package/dist/esm/project-config/shared/backing-service-servability.js +256 -0
- package/dist/esm/project-config/shared/backing-service-servability.js.map +1 -0
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts +62 -67
- package/dist/esm/project-config/shared/backing-services.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/backing-services.schemas.js +71 -68
- package/dist/esm/project-config/shared/backing-services.schemas.js.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.d.ts.map +1 -1
- package/dist/esm/project-config/shared/csp-emit.js +41 -2
- package/dist/esm/project-config/shared/csp-emit.js.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts +180 -4
- package/dist/esm/project-config/shared/infra-providers.schemas.d.ts.map +1 -1
- package/dist/esm/project-config/shared/infra-providers.schemas.js +40 -0
- package/dist/esm/project-config/shared/infra-providers.schemas.js.map +1 -1
- package/dist/esm/project-config/static-asset-import-noop.d.ts +26 -0
- package/dist/esm/project-config/static-asset-import-noop.d.ts.map +1 -0
- package/dist/esm/project-config/static-asset-import-noop.js +49 -0
- package/dist/esm/project-config/static-asset-import-noop.js.map +1 -0
- package/dist/esm/registry/companion-api.schemas.d.ts +0 -176
- package/dist/esm/registry/companion-api.schemas.d.ts.map +0 -1
- package/dist/esm/registry/companion-api.schemas.js.map +0 -1
- package/dist/esm/registry/index.d.ts +3 -1
- package/dist/esm/registry/index.d.ts.map +1 -1
- package/dist/esm/registry/index.js +3 -1
- package/dist/esm/registry/index.js.map +1 -1
- package/dist/esm/registry/local-checkout-source.d.ts +31 -0
- package/dist/esm/registry/local-checkout-source.d.ts.map +1 -0
- package/dist/esm/registry/local-checkout-source.js +45 -0
- package/dist/esm/registry/local-checkout-source.js.map +1 -0
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts +174 -14
- package/dist/esm/registry/lockfile-modules-section.schemas.d.ts.map +1 -1
- package/dist/esm/registry/lockfile-modules-section.schemas.js +120 -11
- package/dist/esm/registry/lockfile-modules-section.schemas.js.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.d.ts +79 -0
- package/dist/esm/registry/module-artifact.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-artifact.schemas.js +36 -0
- package/dist/esm/registry/module-artifact.schemas.js.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.d.ts +393 -7
- package/dist/esm/registry/module-manifest.schemas.d.ts.map +1 -1
- package/dist/esm/registry/module-manifest.schemas.js +488 -40
- package/dist/esm/registry/module-manifest.schemas.js.map +1 -1
- package/dist/esm/registry/module-search.schemas.d.ts +80 -0
- package/dist/esm/registry/module-search.schemas.d.ts.map +1 -0
- package/dist/esm/registry/module-search.schemas.js +112 -0
- package/dist/esm/registry/module-search.schemas.js.map +1 -0
- package/dist/esm/registry/registry-config.schemas.d.ts +16 -0
- package/dist/esm/registry/registry-config.schemas.d.ts.map +1 -1
- package/dist/esm/registry/registry-config.schemas.js +8 -0
- package/dist/esm/registry/registry-config.schemas.js.map +1 -1
- package/dist/esm/registry/registry-errors.d.ts +126 -2
- package/dist/esm/registry/registry-errors.d.ts.map +1 -1
- package/dist/esm/registry/registry-errors.js +183 -14
- package/dist/esm/registry/registry-errors.js.map +1 -1
- package/dist/esm/registry/registry-keys.schemas.d.ts +80 -0
- package/dist/esm/registry/registry-keys.schemas.d.ts.map +1 -0
- package/dist/esm/registry/registry-keys.schemas.js +68 -0
- package/dist/esm/registry/registry-keys.schemas.js.map +1 -0
- package/dist/esm/registry/registry-section-schemas.constants.d.ts +25 -3
- package/dist/esm/registry/registry-section-schemas.constants.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts +13 -11
- package/dist/esm/workspace-scope/workspace-homes.schemas.d.ts.map +1 -1
- package/dist/esm/workspace-scope/workspace-homes.schemas.js +2 -2
- package/dist/esm/workspace-scope/workspace-homes.schemas.js.map +1 -1
- package/package.json +7 -7
- package/dist/esm/registry/companion-api.schemas.js +0 -165
- package/dist/tsconfig.build.tsbuildinfo +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-topology.contracts.js","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-topology.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,6BAA6B,GAE9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AAElG,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,2BAA2B,EAC3B,uBAAuB,EACvB,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAQxC,MAAM,UAAU,sCAAsC,CACpD,OAAe,WAAW;IAE1B,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAuB,EAAE,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,IAAI,IAAI,IAAI,EAAE;QACnC,WAAW,EAAE,UAAU,IAAI,IAAI,IAAI,EAAE;KACtC,CAAC,CAAC;IAEH,OAAO,6BAA6B,CAAC;QACnC,WAAW,EAAE,QAAQ,CAAC,sBAAsB,CAAC,YAA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,CAAC,CAAC,EAAE;gBACjH,MAAM,EAAE,EAAE,SAAS,EAAE,QAAQ,CAAC,kBAAkB,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,QAAQ,CAAC,kBAAkB,GAAG,CAAC,CAAC,EAAE;aACvG;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CACjD,KAA0C;IAE1C,OAAO,sCAAsC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5D,mBAAmB,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CACjE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uCAAuC,CACrD,KAA8C;IAE9C,OAAO,sCAAsC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,KAAK,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3G,CAAC","sourcesContent":["import {\n buildApplicationRuntimeEndpoints,\n buildPlatformRuntimeEndpoints,\n type RuntimeEndpointUrls,\n} from '@wildo-ai/platform-core-shared';\nimport {\n buildK8sInternalUrl,\n buildK8sPublicUrl,\n buildServicePublicHost,\n buildServicePublicUrl,\n} from '../project-config/shared/k8s-utils';\nimport { PLATFORM_DEFAULT_PORTS } from '../project-config/shared/infrastructure-defaults.schemas';\n\nexport {\n buildApplicationRuntimeEndpoints,\n buildPlatformRuntimeEndpoints,\n parseRuntimeEndpointsRecord,\n PlatformApplicationType,\n PlatformRuntimeEndpointKey,\n serializeRuntimeEndpointsRecord,\n} from '@wildo-ai/platform-core-shared';\n\nexport type {\n ApplicationRuntimeEndpointsInput,\n PlatformRuntimeEndpointsInput,\n RuntimeEndpointUrls,\n} from '@wildo-ai/platform-core-shared';\n\nexport function buildLocalhostPlatformRuntimeEndpoints(\n host: string = 'localhost',\n): Record<string, RuntimeEndpointUrls> {\n const buildUrl = (port: number): RuntimeEndpointUrls => ({\n publicUrl: `http://${host}:${port}`,\n internalUrl: `http://${host}:${port}`,\n });\n\n return buildPlatformRuntimeEndpoints({\n appsManager: buildUrl(PLATFORM_DEFAULT_PORTS.APPS_MANAGER),\n crontabsBatchesManager: buildUrl(PLATFORM_DEFAULT_PORTS.CRONTABS_BATCHES_MANAGER),\n moduleRegistry: buildUrl(PLATFORM_DEFAULT_PORTS.MODULE_REGISTRY),\n });\n}\n\nexport interface LocalhostApplicationRuntimeEndpointsInput {\n mainBackendApiPort?: number | undefined;\n frontendApplicationPorts?: Record<string, number> | undefined;\n websitePort?: number | undefined;\n technicalDocumentationPort?: number | undefined;\n host?: string | undefined;\n}\n\nexport function buildLocalhostApplicationRuntimeEndpoints(\n input: LocalhostApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n const host = input.host ?? 'localhost';\n /**\n * Local endpoints are plain http, publicly and internally, and there is no knob.\n *\n * A configurable local scheme existed until 2026-08-14 and was removed: it applied ONE scheme to\n * EVERY endpoint's own port, which is only correct when a single ingress fronts them all. Local\n * Docker Compose has none, so declaring https made `main_backend_api.publicUrl` name a port that\n * held no certificate, and every browser session died on its WebSocket readiness poll.\n *\n * Remote is unaffected and always was: `buildServicePublicUrl` hardcodes `https://` because TLS\n * terminates at Traefik/nginx in front of one origin, where a single scheme IS true for every\n * endpoint. That is the only place the question has a well-defined answer, and it never consulted\n * this input.\n */\n const buildUrl = (port: number): RuntimeEndpointUrls => ({\n publicUrl: `http://${host}:${port}`,\n internalUrl: `http://${host}:${port}`,\n });\n\n return buildApplicationRuntimeEndpoints({\n frontendApplications: input.frontendApplicationPorts\n ? Object.fromEntries(\n Object.entries(input.frontendApplicationPorts).map(([frontendServiceName, port]) => [\n frontendServiceName,\n buildUrl(port),\n ]),\n )\n : undefined,\n ...(input.websitePort ? { website: buildUrl(input.websitePort) } : {}),\n ...(input.technicalDocumentationPort\n ? { technicalDocumentation: buildUrl(input.technicalDocumentationPort) }\n : {}),\n ...(input.mainBackendApiPort\n ? {\n mainBackendApi: buildUrl(input.mainBackendApiPort),\n healthCheckApi: buildUrl(input.mainBackendApiPort - 1),\n mainWebhookApi: buildUrl(input.mainBackendApiPort - 2),\n oauth2ProviderApi: buildUrl(input.mainBackendApiPort - 3),\n mcpApi: buildUrl(input.mainBackendApiPort - 4),\n }\n : {}),\n });\n}\n\nexport function buildK8sPlatformRuntimeEndpoints(input: {\n publicDomain: string;\n namespace: string;\n}): Record<string, RuntimeEndpointUrls> {\n return buildPlatformRuntimeEndpoints({\n appsManager: {\n publicUrl: buildK8sPublicUrl('platform-apps-manager', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-apps-manager', PLATFORM_DEFAULT_PORTS.APPS_MANAGER, input.namespace),\n },\n crontabsBatchesManager: {\n publicUrl: buildK8sPublicUrl('platform-crontabs-batches-manager', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-crontabs-batches-manager', PLATFORM_DEFAULT_PORTS.CRONTABS_BATCHES_MANAGER, input.namespace),\n },\n moduleRegistry: {\n publicUrl: buildK8sPublicUrl('platform-module-registry', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-module-registry', PLATFORM_DEFAULT_PORTS.MODULE_REGISTRY, input.namespace),\n },\n });\n}\n\nexport interface K8sIngressRoute {\n /** Public hostname Traefik/ingress routes on (from the serviceHosts resolver). */\n host: string;\n /**\n * Per-service k8s Service NAME this host routes to. In the per-service deploy\n * model each service is its OWN Deployment+Service, so the route target is the\n * service's `serviceName` (e.g. `wonder-todos-backend-api`, `wonder-todos-app`)\n * — NOT one shared app Service. This is the value stamped into the ingress\n * rule's `backend.service.name`.\n */\n serviceName: string;\n /** Port on that per-service Service to route this host to. */\n port: number;\n}\n\n/**\n * One public frontend in the app's service topology. `serviceName` and\n * `serviceKey` are DECOUPLED on purpose:\n * - `serviceName` — the `runtime.endPoints` map key (the consumer contract:\n * `lookupFrontendPublicUrl` / X-Frontend-Service-Name key by serviceName).\n * - `serviceKey` — the `config.services.<key>`, which is the serviceHosts\n * authoring key. The public HOST resolves from THIS, never from serviceName.\n * Conflating them silently ignores authored `serviceHosts` (the serviceName\n * `wonder-todos-app` misses the authored `app` entry).\n */\nexport interface ApplicationPublicFrontend {\n serviceName: string;\n serviceKey: string;\n port: number;\n}\n\nexport interface K8sApplicationIngressRoutesInput {\n publicDomain: string;\n serviceHosts: Record<string, string> | undefined;\n /** Public frontends. Host resolves from `serviceKey` (config key); route target is the frontend's own `serviceName`. */\n frontends: ReadonlyArray<ApplicationPublicFrontend>;\n /** Backend API `config.services.<key>` (host resolution key). */\n mainBackendApiServiceKey?: string | undefined;\n /** Backend API per-service k8s Service name (the ingress route target). */\n mainBackendApiServiceName?: string | undefined;\n /** Backend API Service port. */\n mainBackendApiPort?: number | undefined;\n}\n\n/**\n * Ingress routes for the app's PUBLIC services (every frontend + the main\n * backend API), serviceHosts-driven. Every host resolves from the service's\n * `config.services.<key>` (`serviceKey`) — so GIVEN THE SAME frontends/keys,\n * the routes match the `runtime.endPoints.publicUrl` that\n * {@link buildK8sApplicationRuntimeEndpoints} produces (both key public hosts on\n * `serviceKey`). Coherence is a property of feeding both the SAME `serviceKey`s,\n * not automatic — see the divergence guards in the domain plan. The internal-only\n * APIs (health/webhook/oauth/mcp) are deliberately NOT routed publicly.\n */\nexport function buildK8sApplicationIngressRoutes(\n input: K8sApplicationIngressRoutesInput,\n): K8sIngressRoute[] {\n const host = (serviceKey: string): string =>\n buildServicePublicHost({ serviceKey, serviceHosts: input.serviceHosts, publicDomain: input.publicDomain });\n\n const entries: Array<{ serviceKey: string; serviceName: string; host: string; port: number }> =\n input.frontends.map((f) => ({\n serviceKey: f.serviceKey,\n serviceName: f.serviceName,\n host: host(f.serviceKey),\n port: f.port,\n }));\n if (\n input.mainBackendApiServiceKey !== undefined &&\n input.mainBackendApiServiceName !== undefined &&\n input.mainBackendApiPort !== undefined\n ) {\n entries.push({\n serviceKey: input.mainBackendApiServiceKey,\n serviceName: input.mainBackendApiServiceName,\n host: host(input.mainBackendApiServiceKey),\n port: input.mainBackendApiPort,\n });\n }\n\n // Fail-closed host-uniqueness guard: each public host routes entirely to ONE\n // service:port (no path-based sharing), so two distinct services resolving to\n // the same host — e.g. both authored to the apex (`''`), or an unauthored key\n // that collides with an authored subdomain — is an ambiguous, silently-broken\n // ingress. Reject it at build time with the colliding keys named, rather than\n // emitting a manifest whose routing is undefined.\n const claimedBy = new Map<string, string>();\n for (const entry of entries) {\n const existing = claimedBy.get(entry.host);\n if (existing !== undefined && existing !== entry.serviceKey) {\n throw new Error(\n `serviceHosts collision: services '${existing}' and '${entry.serviceKey}' both resolve to public host '${entry.host}'. ` +\n `Each service needs a distinct 'serviceHosts' subdomain (only one service may map to the apex '').`,\n );\n }\n claimedBy.set(entry.host, entry.serviceKey);\n }\n\n return entries.map(({ host: h, serviceName, port }) => ({ host: h, serviceName, port }));\n}\n\n/**\n * Fields shared by every REMOTE runtime-endpoints builder (k8s + compose). The\n * PUBLIC side (serviceHosts resolution) is runtime-agnostic; only the INTERNAL\n * URL form differs, injected via the `internalUrlFor` callback of the core\n * builder ({@link buildRemoteApplicationRuntimeEndpoints}).\n */\nexport interface RemoteApplicationRuntimeEndpointsCommon {\n /** Operator's public domain (`WildoInfraEnvConfig.publicDomain`). */\n publicDomain: string;\n /** Authored per-service subdomain map (`wildo.infra.<env>.config.ts`). */\n serviceHosts: Record<string, string> | undefined;\n /**\n * Public frontends. The `runtime.endPoints` map is keyed by each frontend's\n * `serviceName` (consumer contract); the public HOST resolves from its\n * `serviceKey` (config key / serviceHosts key). See {@link ApplicationPublicFrontend}.\n */\n frontends: ReadonlyArray<ApplicationPublicFrontend>;\n /** `serviceKey` of the STATIC_WEBSITE frontend (feeds the fixed website endpoint). */\n websiteServiceKey?: string | undefined;\n /** `serviceKey` of the TECH_DOC frontend (feeds the fixed technical-documentation endpoint). */\n technicalDocumentationServiceKey?: string | undefined;\n /** Backend API `config.services.<key>` (host resolution key). */\n mainBackendApiServiceKey?: string | undefined;\n /** Backend API container port (internal URL + the -1..-4 sibling API ports). */\n mainBackendApiPort?: number | undefined;\n}\n\nexport interface K8sApplicationRuntimeEndpointsInput extends RemoteApplicationRuntimeEndpointsCommon {\n /** K8s namespace for cluster-internal service DNS. */\n namespace: string;\n /**\n * K8s Service name for cluster-internal URLs. Single Service per app (all\n * frontends + APIs ride it on different ports), so this is the app's own\n * service name (= its slug).\n */\n appServiceName: string;\n}\n\nexport interface ComposeApplicationRuntimeEndpointsInput extends RemoteApplicationRuntimeEndpointsCommon {\n /**\n * Compose service (container) name for internal URLs. Single container per\n * app serving all frontends + APIs on their ports, reachable by other\n * containers on the shared network as `http://<appServiceName>:<port>`.\n */\n appServiceName: string;\n}\n\n/**\n * Core REMOTE application runtime-endpoints assembly, shared by the k8s and\n * compose builders so their public-URL semantics never drift. PUBLIC URLs come\n * from {@link buildServicePublicUrl} (so ingress hosts, `runtime.endPoints.publicUrl`,\n * and CORS all agree — greenfield, no multi-tenant fan-out). INTERNAL URLs are\n * supplied by `internalUrlFor` (cluster-DNS for k8s, container DNS for compose).\n * The health/webhook/oauth/mcp APIs are internal only — their `publicUrl` is the\n * internal URL (never publicly routed).\n */\nfunction buildRemoteApplicationRuntimeEndpoints(\n input: RemoteApplicationRuntimeEndpointsCommon,\n internalUrlFor: (port: number) => string,\n): Record<string, RuntimeEndpointUrls> {\n const { publicDomain, serviceHosts } = input;\n const pub = (serviceKey: string): string =>\n buildServicePublicUrl({ serviceKey, serviceHosts, publicDomain });\n const internal = internalUrlFor;\n\n // Map key = serviceName (consumer contract: lookupFrontendPublicUrl keys by\n // serviceName); public host = serviceKey (serviceHosts key). Decoupled.\n const frontendApplications = input.frontends.length > 0\n ? Object.fromEntries(\n input.frontends.map((f) => [\n f.serviceName,\n { publicUrl: pub(f.serviceKey), internalUrl: internal(f.port) },\n ]),\n )\n : undefined;\n\n const websiteFrontend = input.websiteServiceKey\n ? input.frontends.find((f) => f.serviceKey === input.websiteServiceKey)\n : undefined;\n const docsFrontend = input.technicalDocumentationServiceKey\n ? input.frontends.find((f) => f.serviceKey === input.technicalDocumentationServiceKey)\n : undefined;\n const { mainBackendApiServiceKey, mainBackendApiPort } = input;\n\n return buildApplicationRuntimeEndpoints({\n frontendApplications,\n ...(websiteFrontend\n ? { website: { publicUrl: pub(websiteFrontend.serviceKey), internalUrl: internal(websiteFrontend.port) } }\n : {}),\n ...(docsFrontend\n ? {\n technicalDocumentation: {\n publicUrl: pub(docsFrontend.serviceKey),\n internalUrl: internal(docsFrontend.port),\n },\n }\n : {}),\n ...(mainBackendApiServiceKey !== undefined && mainBackendApiPort !== undefined\n ? {\n mainBackendApi: {\n publicUrl: pub(mainBackendApiServiceKey),\n internalUrl: internal(mainBackendApiPort),\n },\n // Internal-only APIs — never publicly routed (publicUrl === internal).\n healthCheckApi: { publicUrl: internal(mainBackendApiPort - 1), internalUrl: internal(mainBackendApiPort - 1) },\n mainWebhookApi: { publicUrl: internal(mainBackendApiPort - 2), internalUrl: internal(mainBackendApiPort - 2) },\n oauth2ProviderApi: { publicUrl: internal(mainBackendApiPort - 3), internalUrl: internal(mainBackendApiPort - 3) },\n mcpApi: { publicUrl: internal(mainBackendApiPort - 4), internalUrl: internal(mainBackendApiPort - 4) },\n }\n : {}),\n });\n}\n\n/**\n * Build K8s application runtime endpoints — the self-hosted, single-app,\n * `serviceHosts`-driven counterpart to {@link buildLocalhostApplicationRuntimeEndpoints}.\n * INTERNAL URLs are the app's own cluster-DNS Service on each port.\n */\nexport function buildK8sApplicationRuntimeEndpoints(\n input: K8sApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n return buildRemoteApplicationRuntimeEndpoints(input, (port) =>\n buildK8sInternalUrl(input.appServiceName, port, input.namespace),\n );\n}\n\n/**\n * Build Docker-Compose application runtime endpoints — the compose counterpart\n * of {@link buildK8sApplicationRuntimeEndpoints}. PUBLIC URLs are IDENTICAL\n * (serviceHosts-driven, so the Traefik ingress routes and `runtime.endPoints`\n * agree — the CORS invariant holds for compose too). INTERNAL URLs are the app\n * container's own name on the shared compose network (`http://<appServiceName>:<port>`),\n * NOT localhost — the remote compose stack must not advertise localhost topology.\n */\nexport function buildComposeApplicationRuntimeEndpoints(\n input: ComposeApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n return buildRemoteApplicationRuntimeEndpoints(input, (port) => `http://${input.appServiceName}:${port}`);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"runtime-topology.contracts.js","sourceRoot":"","sources":["../../../../src/bootstrap/runtime-topology.contracts.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gCAAgC,EAChC,6BAA6B,GAE9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,0DAA0D,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAGvE,OAAO,EACL,gCAAgC,EAChC,6BAA6B,EAC7B,2BAA2B,EAC3B,uBAAuB,EACvB,0BAA0B,EAC1B,+BAA+B,GAChC,MAAM,gCAAgC,CAAC;AAQxC,MAAM,UAAU,sCAAsC,CACpD,OAAe,WAAW;IAE1B,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAuB,EAAE,CAAC,CAAC;QACvD,SAAS,EAAE,UAAU,IAAI,IAAI,IAAI,EAAE;QACnC,WAAW,EAAE,UAAU,IAAI,IAAI,IAAI,EAAE;KACtC,CAAC,CAAC;IAEH,OAAO,6BAA6B,CAAC;QACnC,WAAW,EAAE,QAAQ,CAAC,sBAAsB,CAAC,YAAY,CAAC;QAC1D,sBAAsB,EAAE,QAAQ,CAAC,sBAAsB,CAAC,wBAAwB,CAAC;QACjF,cAAc,EAAE,QAAQ,CAAC,sBAAsB,CAAC,eAAe,CAAC;KACjE,CAAC,CAAC;AACL,CAAC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C,EAAE,CAAC;QACP,GAAG,CAAC,wBAAwB,KAAK,SAAS,IAAI,kBAAkB,KAAK,SAAS;YAC5E,CAAC,CAAC;gBACE,cAAc,EAAE;oBACd,SAAS,EAAE,GAAG,CAAC,wBAAwB,CAAC;oBACxC,WAAW,EAAE,QAAQ,CAAC,kBAAkB,CAAC;iBAC1C;aACF;YACH,CAAC,CAAC,EAAE,CAAC;KACR,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,mCAAmC,CACjD,KAA0C;IAE1C,OAAO,sCAAsC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAC5D,mBAAmB,CAAC,KAAK,CAAC,cAAc,EAAE,IAAI,EAAE,KAAK,CAAC,SAAS,CAAC,CACjE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uCAAuC,CACrD,KAA8C;IAE9C,OAAO,sCAAsC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,KAAK,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC,CAAC;AAC3G,CAAC","sourcesContent":["import {\n buildApplicationRuntimeEndpoints,\n buildPlatformRuntimeEndpoints,\n type RuntimeEndpointUrls,\n} from '@wildo-ai/platform-core-shared';\nimport {\n buildK8sInternalUrl,\n buildK8sPublicUrl,\n buildServicePublicHost,\n buildServicePublicUrl,\n} from '../project-config/shared/k8s-utils';\nimport { PLATFORM_DEFAULT_PORTS } from '../project-config/shared/infrastructure-defaults.schemas';\nimport { AppFrontendType } from '@wildo-ai/saas-models/public-runtime';\nimport type { AppServiceDefinition } from '../project-config/shared/service-definitions.schemas';\n\nexport {\n buildApplicationRuntimeEndpoints,\n buildPlatformRuntimeEndpoints,\n parseRuntimeEndpointsRecord,\n PlatformApplicationType,\n PlatformRuntimeEndpointKey,\n serializeRuntimeEndpointsRecord,\n} from '@wildo-ai/platform-core-shared';\n\nexport type {\n ApplicationRuntimeEndpointsInput,\n PlatformRuntimeEndpointsInput,\n RuntimeEndpointUrls,\n} from '@wildo-ai/platform-core-shared';\n\nexport function buildLocalhostPlatformRuntimeEndpoints(\n host: string = 'localhost',\n): Record<string, RuntimeEndpointUrls> {\n const buildUrl = (port: number): RuntimeEndpointUrls => ({\n publicUrl: `http://${host}:${port}`,\n internalUrl: `http://${host}:${port}`,\n });\n\n return buildPlatformRuntimeEndpoints({\n appsManager: buildUrl(PLATFORM_DEFAULT_PORTS.APPS_MANAGER),\n crontabsBatchesManager: buildUrl(PLATFORM_DEFAULT_PORTS.CRONTABS_BATCHES_MANAGER),\n moduleRegistry: buildUrl(PLATFORM_DEFAULT_PORTS.MODULE_REGISTRY),\n });\n}\n\nexport interface LocalhostApplicationRuntimeEndpointsInput {\n mainBackendApiPort?: number | undefined;\n frontendApplicationPorts?: Record<string, number> | undefined;\n websitePort?: number | undefined;\n technicalDocumentationPort?: number | undefined;\n host?: string | undefined;\n}\n\nexport function buildLocalhostApplicationRuntimeEndpoints(\n input: LocalhostApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n const host = input.host ?? 'localhost';\n /**\n * Local endpoints are plain http, publicly and internally, and there is no knob.\n *\n * A configurable local scheme existed until 2026-08-14 and was removed: it applied ONE scheme to\n * EVERY endpoint's own port, which is only correct when a single ingress fronts them all. Local\n * Docker Compose has none, so declaring https made `main_backend_api.publicUrl` name a port that\n * held no certificate, and every browser session died on its WebSocket readiness poll.\n *\n * Remote is unaffected and always was: `buildServicePublicUrl` hardcodes `https://` because TLS\n * terminates at Traefik/nginx in front of one origin, where a single scheme IS true for every\n * endpoint. That is the only place the question has a well-defined answer, and it never consulted\n * this input.\n */\n const buildUrl = (port: number): RuntimeEndpointUrls => ({\n publicUrl: `http://${host}:${port}`,\n internalUrl: `http://${host}:${port}`,\n });\n\n return buildApplicationRuntimeEndpoints({\n frontendApplications: input.frontendApplicationPorts\n ? Object.fromEntries(\n Object.entries(input.frontendApplicationPorts).map(([frontendServiceName, port]) => [\n frontendServiceName,\n buildUrl(port),\n ]),\n )\n : undefined,\n ...(input.websitePort ? { website: buildUrl(input.websitePort) } : {}),\n ...(input.technicalDocumentationPort\n ? { technicalDocumentation: buildUrl(input.technicalDocumentationPort) }\n : {}),\n ...(input.mainBackendApiPort\n ? {\n mainBackendApi: buildUrl(input.mainBackendApiPort),\n }\n : {}),\n });\n}\n\n/**\n * Which backend is an application's MAIN backend API — the one its browser-facing\n * surfaces call. The `backendApi` service key when declared, else the first backend\n * row. One rule, used by the CLI's endpoint and ingress derivation and by the public\n * website's local origins, so the three cannot name different backends.\n */\nexport function selectPrimaryBackendService<TService extends { readonly key: string }>(\n backendServices: readonly TService[],\n): TService | undefined {\n return backendServices.find((backend) => backend.key === 'backendApi') ?? backendServices[0];\n}\n\n/** The origins a locally-running application serves its app and its main API on. */\nexport interface LocalhostApplicationOrigins {\n /** The `SAAS_APP` frontend, when one declares a port. */\n readonly app?: string | undefined;\n /** The main backend API ({@link selectPrimaryBackendService}), when it declares a port. */\n readonly api?: string | undefined;\n}\n\n/**\n * The local-development origins of an application's product and API, derived from\n * the `defaultPort` each service already declares in `wildo.saas.config.ts` — the\n * same ports, host and plain-http scheme {@link buildLocalhostApplicationRuntimeEndpoints}\n * advertises, so a local surface that links into the product reaches the process\n * `wildo local dev` actually started.\n *\n * It exists for the public website, which is a separate origin from the product:\n * its CTAs and capture forms must reach `http://localhost:<appPort>` and\n * `http://localhost:<backendPort>` under `astro dev`. Before this, the API origin\n * was a port hardcoded into each site and the app origin had no local form at all,\n * so every \"Start free\" in local development pointed at a production-shaped host\n * that resolves to nothing.\n */\nexport function resolveLocalhostApplicationOrigins(\n services: Readonly<Record<string, Pick<AppServiceDefinition, 'defaultPort' | 'frontendType'>>>,\n host = 'localhost',\n): LocalhostApplicationOrigins {\n const rows = Object.entries(services).map(([key, service]) => ({ key, ...service }));\n const primaryBackend = selectPrimaryBackendService(rows.filter((row) => row.frontendType === undefined));\n const saasApp = rows.find((row) => row.frontendType === AppFrontendType.SAAS_APP);\n const originOf = (port: number | undefined): string | undefined => (port === undefined ? undefined : `http://${host}:${port}`);\n return { app: originOf(saasApp?.defaultPort), api: originOf(primaryBackend?.defaultPort) };\n}\n\nexport function buildK8sPlatformRuntimeEndpoints(input: {\n publicDomain: string;\n namespace: string;\n}): Record<string, RuntimeEndpointUrls> {\n return buildPlatformRuntimeEndpoints({\n appsManager: {\n publicUrl: buildK8sPublicUrl('platform-apps-manager', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-apps-manager', PLATFORM_DEFAULT_PORTS.APPS_MANAGER, input.namespace),\n },\n crontabsBatchesManager: {\n publicUrl: buildK8sPublicUrl('platform-crontabs-batches-manager', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-crontabs-batches-manager', PLATFORM_DEFAULT_PORTS.CRONTABS_BATCHES_MANAGER, input.namespace),\n },\n moduleRegistry: {\n publicUrl: buildK8sPublicUrl('platform-module-registry', input.publicDomain),\n internalUrl: buildK8sInternalUrl('platform-module-registry', PLATFORM_DEFAULT_PORTS.MODULE_REGISTRY, input.namespace),\n },\n });\n}\n\nexport interface K8sIngressRoute {\n /** Public hostname Traefik/ingress routes on (from the serviceHosts resolver). */\n host: string;\n /**\n * Per-service k8s Service NAME this host routes to. In the per-service deploy\n * model each service is its OWN Deployment+Service, so the route target is the\n * service's `serviceName` (e.g. `wonder-todos-backend-api`, `wonder-todos-app`)\n * — NOT one shared app Service. This is the value stamped into the ingress\n * rule's `backend.service.name`.\n */\n serviceName: string;\n /** Port on that per-service Service to route this host to. */\n port: number;\n}\n\n/**\n * One public frontend in the app's service topology. `serviceName` and\n * `serviceKey` are DECOUPLED on purpose:\n * - `serviceName` — the `runtime.endPoints` map key (the consumer contract:\n * `lookupFrontendPublicUrl` / X-Frontend-Service-Name key by serviceName).\n * - `serviceKey` — the `config.services.<key>`, which is the serviceHosts\n * authoring key. The public HOST resolves from THIS, never from serviceName.\n * Conflating them silently ignores authored `serviceHosts` (the serviceName\n * `wonder-todos-app` misses the authored `app` entry).\n */\nexport interface ApplicationPublicFrontend {\n serviceName: string;\n serviceKey: string;\n port: number;\n}\n\nexport interface K8sApplicationIngressRoutesInput {\n publicDomain: string;\n serviceHosts: Record<string, string> | undefined;\n /** Public frontends. Host resolves from `serviceKey` (config key); route target is the frontend's own `serviceName`. */\n frontends: ReadonlyArray<ApplicationPublicFrontend>;\n /** Backend API `config.services.<key>` (host resolution key). */\n mainBackendApiServiceKey?: string | undefined;\n /** Backend API per-service k8s Service name (the ingress route target). */\n mainBackendApiServiceName?: string | undefined;\n /** Backend API Service port. */\n mainBackendApiPort?: number | undefined;\n}\n\n/**\n * Ingress routes for the app's PUBLIC services (every frontend + the main\n * backend API), serviceHosts-driven. Every host resolves from the service's\n * `config.services.<key>` (`serviceKey`) — so GIVEN THE SAME frontends/keys,\n * the routes match the `runtime.endPoints.publicUrl` that\n * {@link buildK8sApplicationRuntimeEndpoints} produces (both key public hosts on\n * `serviceKey`). Coherence is a property of feeding both the SAME `serviceKey`s,\n * not automatic — see the divergence guards in the domain plan. Health, webhooks,\n * the OAuth provider and MCP are routes on the backend's own port, so they reach\n * the public host through the backend API route like any other path (#1783).\n */\nexport function buildK8sApplicationIngressRoutes(\n input: K8sApplicationIngressRoutesInput,\n): K8sIngressRoute[] {\n const host = (serviceKey: string): string =>\n buildServicePublicHost({ serviceKey, serviceHosts: input.serviceHosts, publicDomain: input.publicDomain });\n\n const entries: Array<{ serviceKey: string; serviceName: string; host: string; port: number }> =\n input.frontends.map((f) => ({\n serviceKey: f.serviceKey,\n serviceName: f.serviceName,\n host: host(f.serviceKey),\n port: f.port,\n }));\n if (\n input.mainBackendApiServiceKey !== undefined &&\n input.mainBackendApiServiceName !== undefined &&\n input.mainBackendApiPort !== undefined\n ) {\n entries.push({\n serviceKey: input.mainBackendApiServiceKey,\n serviceName: input.mainBackendApiServiceName,\n host: host(input.mainBackendApiServiceKey),\n port: input.mainBackendApiPort,\n });\n }\n\n // Fail-closed host-uniqueness guard: each public host routes entirely to ONE\n // service:port (no path-based sharing), so two distinct services resolving to\n // the same host — e.g. both authored to the apex (`''`), or an unauthored key\n // that collides with an authored subdomain — is an ambiguous, silently-broken\n // ingress. Reject it at build time with the colliding keys named, rather than\n // emitting a manifest whose routing is undefined.\n const claimedBy = new Map<string, string>();\n for (const entry of entries) {\n const existing = claimedBy.get(entry.host);\n if (existing !== undefined && existing !== entry.serviceKey) {\n throw new Error(\n `serviceHosts collision: services '${existing}' and '${entry.serviceKey}' both resolve to public host '${entry.host}'. ` +\n `Each service needs a distinct 'serviceHosts' subdomain (only one service may map to the apex '').`,\n );\n }\n claimedBy.set(entry.host, entry.serviceKey);\n }\n\n return entries.map(({ host: h, serviceName, port }) => ({ host: h, serviceName, port }));\n}\n\n/**\n * Fields shared by every REMOTE runtime-endpoints builder (k8s + compose). The\n * PUBLIC side (serviceHosts resolution) is runtime-agnostic; only the INTERNAL\n * URL form differs, injected via the `internalUrlFor` callback of the core\n * builder ({@link buildRemoteApplicationRuntimeEndpoints}).\n */\nexport interface RemoteApplicationRuntimeEndpointsCommon {\n /** Operator's public domain (`WildoInfraEnvConfig.publicDomain`). */\n publicDomain: string;\n /** Authored per-service subdomain map (`wildo.infra.<env>.config.ts`). */\n serviceHosts: Record<string, string> | undefined;\n /**\n * Public frontends. The `runtime.endPoints` map is keyed by each frontend's\n * `serviceName` (consumer contract); the public HOST resolves from its\n * `serviceKey` (config key / serviceHosts key). See {@link ApplicationPublicFrontend}.\n */\n frontends: ReadonlyArray<ApplicationPublicFrontend>;\n /** `serviceKey` of the STATIC_WEBSITE frontend (feeds the fixed website endpoint). */\n websiteServiceKey?: string | undefined;\n /** `serviceKey` of the TECH_DOC frontend (feeds the fixed technical-documentation endpoint). */\n technicalDocumentationServiceKey?: string | undefined;\n /** Backend API `config.services.<key>` (host resolution key). */\n mainBackendApiServiceKey?: string | undefined;\n /** Backend API container port — the one port the backend process binds (its internal URL). */\n mainBackendApiPort?: number | undefined;\n}\n\nexport interface K8sApplicationRuntimeEndpointsInput extends RemoteApplicationRuntimeEndpointsCommon {\n /** K8s namespace for cluster-internal service DNS. */\n namespace: string;\n /**\n * K8s Service name for cluster-internal URLs. Single Service per app (all\n * frontends + APIs ride it on different ports), so this is the app's own\n * service name (= its slug).\n */\n appServiceName: string;\n}\n\nexport interface ComposeApplicationRuntimeEndpointsInput extends RemoteApplicationRuntimeEndpointsCommon {\n /**\n * Compose service (container) name for internal URLs. Single container per\n * app serving all frontends + APIs on their ports, reachable by other\n * containers on the shared network as `http://<appServiceName>:<port>`.\n */\n appServiceName: string;\n}\n\n/**\n * Core REMOTE application runtime-endpoints assembly, shared by the k8s and\n * compose builders so their public-URL semantics never drift. PUBLIC URLs come\n * from {@link buildServicePublicUrl} (so ingress hosts, `runtime.endPoints.publicUrl`,\n * and CORS all agree — greenfield, no multi-tenant fan-out). INTERNAL URLs are\n * supplied by `internalUrlFor` (cluster-DNS for k8s, container DNS for compose).\n * The backend declares ONE endpoint: health, webhooks, the OAuth provider and MCP\n * are routes on its port, not sibling listeners (#1783).\n */\nfunction buildRemoteApplicationRuntimeEndpoints(\n input: RemoteApplicationRuntimeEndpointsCommon,\n internalUrlFor: (port: number) => string,\n): Record<string, RuntimeEndpointUrls> {\n const { publicDomain, serviceHosts } = input;\n const pub = (serviceKey: string): string =>\n buildServicePublicUrl({ serviceKey, serviceHosts, publicDomain });\n const internal = internalUrlFor;\n\n // Map key = serviceName (consumer contract: lookupFrontendPublicUrl keys by\n // serviceName); public host = serviceKey (serviceHosts key). Decoupled.\n const frontendApplications = input.frontends.length > 0\n ? Object.fromEntries(\n input.frontends.map((f) => [\n f.serviceName,\n { publicUrl: pub(f.serviceKey), internalUrl: internal(f.port) },\n ]),\n )\n : undefined;\n\n const websiteFrontend = input.websiteServiceKey\n ? input.frontends.find((f) => f.serviceKey === input.websiteServiceKey)\n : undefined;\n const docsFrontend = input.technicalDocumentationServiceKey\n ? input.frontends.find((f) => f.serviceKey === input.technicalDocumentationServiceKey)\n : undefined;\n const { mainBackendApiServiceKey, mainBackendApiPort } = input;\n\n return buildApplicationRuntimeEndpoints({\n frontendApplications,\n ...(websiteFrontend\n ? { website: { publicUrl: pub(websiteFrontend.serviceKey), internalUrl: internal(websiteFrontend.port) } }\n : {}),\n ...(docsFrontend\n ? {\n technicalDocumentation: {\n publicUrl: pub(docsFrontend.serviceKey),\n internalUrl: internal(docsFrontend.port),\n },\n }\n : {}),\n ...(mainBackendApiServiceKey !== undefined && mainBackendApiPort !== undefined\n ? {\n mainBackendApi: {\n publicUrl: pub(mainBackendApiServiceKey),\n internalUrl: internal(mainBackendApiPort),\n },\n }\n : {}),\n });\n}\n\n/**\n * Build K8s application runtime endpoints — the self-hosted, single-app,\n * `serviceHosts`-driven counterpart to {@link buildLocalhostApplicationRuntimeEndpoints}.\n * INTERNAL URLs are the app's own cluster-DNS Service on each port.\n */\nexport function buildK8sApplicationRuntimeEndpoints(\n input: K8sApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n return buildRemoteApplicationRuntimeEndpoints(input, (port) =>\n buildK8sInternalUrl(input.appServiceName, port, input.namespace),\n );\n}\n\n/**\n * Build Docker-Compose application runtime endpoints — the compose counterpart\n * of {@link buildK8sApplicationRuntimeEndpoints}. PUBLIC URLs are IDENTICAL\n * (serviceHosts-driven, so the Traefik ingress routes and `runtime.endPoints`\n * agree — the CORS invariant holds for compose too). INTERNAL URLs are the app\n * container's own name on the shared compose network (`http://<appServiceName>:<port>`),\n * NOT localhost — the remote compose stack must not advertise localhost topology.\n */\nexport function buildComposeApplicationRuntimeEndpoints(\n input: ComposeApplicationRuntimeEndpointsInput,\n): Record<string, RuntimeEndpointUrls> {\n return buildRemoteApplicationRuntimeEndpoints(input, (port) => `http://${input.appServiceName}:${port}`);\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export * from './bootstrap/platform-runtime-env.contracts';
|
|
|
17
17
|
export * from './bootstrap/runtime-topology.contracts';
|
|
18
18
|
export * from './bootstrap/runtime-principal.contracts';
|
|
19
19
|
export * from './bootstrap/runtime-backing-service-access';
|
|
20
|
+
export * from './bootstrap/platform-store-preconnect';
|
|
20
21
|
export * from './bootstrap/runtime-network-topology';
|
|
21
22
|
export * from './bootstrap/runtime-network-policy';
|
|
22
23
|
export * from './bootstrap/runtime-platform-access';
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -17,6 +17,7 @@ export * from './bootstrap/platform-runtime-env.contracts.js';
|
|
|
17
17
|
export * from './bootstrap/runtime-topology.contracts.js';
|
|
18
18
|
export * from './bootstrap/runtime-principal.contracts.js';
|
|
19
19
|
export * from './bootstrap/runtime-backing-service-access.js';
|
|
20
|
+
export * from './bootstrap/platform-store-preconnect.js';
|
|
20
21
|
export * from './bootstrap/runtime-network-topology.js';
|
|
21
22
|
export * from './bootstrap/runtime-network-policy.js';
|
|
22
23
|
export * from './bootstrap/runtime-platform-access.js';
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './project-config';\nexport * from './workspace-scope';\nexport * from './credentials/credential-generator.service';\n\nexport * from './schemas/platform-application-config.schemas';\nexport * from './schemas/platform-application-secrets.schemas';\nexport * from './schemas/platform-config.schemas';\nexport * from './schemas/framework-info.schemas';\nexport * from './schemas/framework-secrets.schemas';\nexport * from './release/framework-release.constants';\nexport * from './bootstrap/bootstrap.schemas';\nexport * from './bootstrap/bootstrap.contracts';\nexport * from './bootstrap/bootstrap-planner';\nexport * from './bootstrap/application-backend-env.contracts';\nexport * from './bootstrap/wildo-owner-organization.contracts';\nexport * from './bootstrap/application-creation-verification-env.contracts';\nexport * from './bootstrap/platform-runtime-env.contracts';\nexport * from './bootstrap/runtime-topology.contracts';\nexport * from './bootstrap/runtime-principal.contracts';\nexport * from './bootstrap/runtime-backing-service-access';\nexport * from './bootstrap/runtime-network-topology';\nexport * from './bootstrap/runtime-network-policy';\nexport * from './bootstrap/runtime-platform-access';\nexport * from './project-config/minion-local-provider-registration';\nexport * from './project-config/shared/minion-resource-access.validation';\nexport * from './project-config/shared/object-storage-session-policy';\nexport * from './lockfile/wildo-saas-lock.shared.schemas';\nexport * from './lockfile/lockfile-io';\nexport * from './lockfile/build-parallelism';\nexport * from './lockfile/materialize-infra-section';\nexport * from './lockfile/canonical-json';\nexport * from './registry';\nexport * from './_unimplemented';\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,4CAA4C,CAAC;AAE3D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,mCAAmC,CAAC;AAClD,cAAc,kCAAkC,CAAC;AACjD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,+CAA+C,CAAC;AAC9D,cAAc,gDAAgD,CAAC;AAC/D,cAAc,6DAA6D,CAAC;AAC5E,cAAc,4CAA4C,CAAC;AAC3D,cAAc,wCAAwC,CAAC;AACvD,cAAc,yCAAyC,CAAC;AACxD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,uCAAuC,CAAC;AACtD,cAAc,sCAAsC,CAAC;AACrD,cAAc,oCAAoC,CAAC;AACnD,cAAc,qCAAqC,CAAC;AACpD,cAAc,qDAAqD,CAAC;AACpE,cAAc,2DAA2D,CAAC;AAC1E,cAAc,uDAAuD,CAAC;AACtE,cAAc,2CAA2C,CAAC;AAC1D,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,sCAAsC,CAAC;AACrD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,YAAY,CAAC;AAC3B,cAAc,kBAAkB,CAAC","sourcesContent":["export * from './project-config';\nexport * from './workspace-scope';\nexport * from './credentials/credential-generator.service';\n\nexport * from './schemas/platform-application-config.schemas';\nexport * from './schemas/platform-application-secrets.schemas';\nexport * from './schemas/platform-config.schemas';\nexport * from './schemas/framework-info.schemas';\nexport * from './schemas/framework-secrets.schemas';\nexport * from './release/framework-release.constants';\nexport * from './bootstrap/bootstrap.schemas';\nexport * from './bootstrap/bootstrap.contracts';\nexport * from './bootstrap/bootstrap-planner';\nexport * from './bootstrap/application-backend-env.contracts';\nexport * from './bootstrap/wildo-owner-organization.contracts';\nexport * from './bootstrap/application-creation-verification-env.contracts';\nexport * from './bootstrap/platform-runtime-env.contracts';\nexport * from './bootstrap/runtime-topology.contracts';\nexport * from './bootstrap/runtime-principal.contracts';\nexport * from './bootstrap/runtime-backing-service-access';\nexport * from './bootstrap/platform-store-preconnect';\nexport * from './bootstrap/runtime-network-topology';\nexport * from './bootstrap/runtime-network-policy';\nexport * from './bootstrap/runtime-platform-access';\nexport * from './project-config/minion-local-provider-registration';\nexport * from './project-config/shared/minion-resource-access.validation';\nexport * from './project-config/shared/object-storage-session-policy';\nexport * from './lockfile/wildo-saas-lock.shared.schemas';\nexport * from './lockfile/lockfile-io';\nexport * from './lockfile/build-parallelism';\nexport * from './lockfile/materialize-infra-section';\nexport * from './lockfile/canonical-json';\nexport * from './registry';\nexport * from './_unimplemented';\n"]}
|
|
@@ -142,7 +142,13 @@ export declare function readWildoSaasLock(options: Pick<LockfileMutateOptions, '
|
|
|
142
142
|
* re-validated against the envelope schema (and any caller-supplied
|
|
143
143
|
* `sectionSchemas`) before being atomically written.
|
|
144
144
|
*
|
|
145
|
-
* `generatedAt` is
|
|
145
|
+
* `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be
|
|
146
|
+
* written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the
|
|
147
|
+
* envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op
|
|
148
|
+
* sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly
|
|
149
|
+
* one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a
|
|
150
|
+
* no-op mutation still writes back what normalization changed (schema defaults, a missing trailing
|
|
151
|
+
* newline).
|
|
146
152
|
*
|
|
147
153
|
* The library never inspects `sections.providers.runtimeScopes`,
|
|
148
154
|
* `sections.modules`, or `sections.i18n` — it only enforces the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockfile-io.d.ts","sourceRoot":"","sources":["../../../../src/lockfile/lockfile-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAMH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAEL,KAAK,oBAAoB,EAE1B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AACH,eAAO,MAAM,6BAA6B,qCAAqC,CAAC;AAEhF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB;;;;;;;;;CAIuB,CAAC;AAEzD;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG;QAAE,OAAO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A;KAAE,CAAC;IAC1F,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAsB,qBAAqB,CAAC,CAAC,EAC3C,cAAc,EAAE,MAAM,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,WAAW,CAAC,EAAE,wBAAwB,GACrC,OAAO,CAAC,CAAC,CAAC,CAgBZ;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,qCAAqC,EAAE,MACP,CAAC;AAE9C,uEAAuE;AACvE,wBAAgB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAAC,CAAC,EAC/C,OAAO,EAAE,qBAAqB,GAAG;IAC/B,iEAAiE;IACjE,UAAU,EAAE,MAAM,CAAC;IACnB,2DAA2D;IAC3D,aAAa,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC5B,yDAAyD;IACzD,cAAc,EAAE,MAAM,CAAC,CAAC;CACzB,EACD,OAAO,EAAE,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,GACpD,OAAO,CAAC,CAAC,CAAC,CAuBZ"}
|
|
@@ -183,6 +183,10 @@ lockOptions) {
|
|
|
183
183
|
await release();
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
|
+
/** The one on-disk form of the envelope: two-space JSON with a trailing newline. */
|
|
187
|
+
function serializeLockfile(envelope) {
|
|
188
|
+
return JSON.stringify(envelope, null, 2) + '\n';
|
|
189
|
+
}
|
|
186
190
|
function emptyEnvelope() {
|
|
187
191
|
return {
|
|
188
192
|
schemaVersion: 2,
|
|
@@ -209,7 +213,13 @@ async function writeFileAtomicAsync(filePath, content) {
|
|
|
209
213
|
* re-validated against the envelope schema (and any caller-supplied
|
|
210
214
|
* `sectionSchemas`) before being atomically written.
|
|
211
215
|
*
|
|
212
|
-
* `generatedAt` is
|
|
216
|
+
* `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be
|
|
217
|
+
* written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the
|
|
218
|
+
* envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op
|
|
219
|
+
* sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly
|
|
220
|
+
* one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a
|
|
221
|
+
* no-op mutation still writes back what normalization changed (schema defaults, a missing trailing
|
|
222
|
+
* newline).
|
|
213
223
|
*
|
|
214
224
|
* The library never inspects `sections.providers.runtimeScopes`,
|
|
215
225
|
* `sections.modules`, or `sections.i18n` — it only enforces the
|
|
@@ -227,14 +237,18 @@ export async function withLockfileMutate(options, mutator) {
|
|
|
227
237
|
});
|
|
228
238
|
const next = structuredClone(before);
|
|
229
239
|
await mutator(next);
|
|
230
|
-
next.generatedAt = new Date().toISOString();
|
|
231
240
|
// Re-validate AFTER mutation; the mutator may have introduced
|
|
232
241
|
// structurally-invalid input.
|
|
233
242
|
SaasLockfileEnvelopeSchema.parse(next);
|
|
234
243
|
if (options.sectionSchemas) {
|
|
235
244
|
validateAndNormalizeSections(next.sections, options.sectionSchemas);
|
|
236
245
|
}
|
|
237
|
-
await
|
|
246
|
+
const onDisk = await fs.readFile(filePath, 'utf8').catch(() => null);
|
|
247
|
+
if (onDisk === serializeLockfile({ ...next, generatedAt: before.generatedAt })) {
|
|
248
|
+
return { ...next, generatedAt: before.generatedAt };
|
|
249
|
+
}
|
|
250
|
+
next.generatedAt = new Date().toISOString();
|
|
251
|
+
await writeFileAtomicAsync(filePath, serializeLockfile(next));
|
|
238
252
|
return next;
|
|
239
253
|
}, lockOptions);
|
|
240
254
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lockfile-io.js","sourceRoot":"","sources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AAC,cAAc,EAAE,CAAC;QAC5F,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,MAAM,CAAM,CAAC;QAClC,sEAAsE;QACtE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Shared `wildo-saas.lock.json` IO primitives.\n *\n * Phase 1 graduates the locking + atomic-write surface validated by\n * the Phase 0.B contention spike (`module-registry-analysis.md`)\n * into `platform-config-lib`. Both the dev companion's\n * `WildoSaasLockCompanionService` and the CLI-side\n * `RegistryLockfileService` consume this module so concurrent\n * writers — across processes (CLI + companion + minions) — never\n * lose updates and never observe a half-written envelope.\n *\n * Exposes two layers:\n *\n * 1. `withLockfileMutate(opts, mutator)` — full-envelope mutate\n * under `proper-lockfile` + `write-file-atomic`. The companion\n * uses this so it can preserve its full-envelope contract and\n * validate its companion-owned i18n schema in the same pass.\n *\n * 2. `withLockfileSectionMutate(opts, mutator)` — section-scoped\n * mutate. The CLI uses this so it can ONLY touch one section\n * (e.g. `sections.modules`) and never accidentally clobber a\n * sibling section.\n *\n * Both layers preserve unknown sections verbatim — every consumer\n * MUST round-trip every `sections.*` key it does not recognize.\n *\n * Hard contract (KD-4 / KD-15 / KD-18):\n * - The library NEVER writes provider runtime artifacts under\n * `.wildo-saas/generated/providers/*.runtime-providers.generated.json` or\n * `src/generated/wildo-provider-runtime.generated.ts`. Those are\n * produced by the provider materialization workflow alone.\n * - `sections.providers.runtimeScopes` is owned end-to-end by the\n * provider workstream; module-registry callers MUST NOT mutate it.\n * This module is unaware of the provider section beyond\n * preserving its bytes.\n */\n\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport lockfile from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { z } from 'zod';\nimport {\n SaasLockfileEnvelopeSchema,\n type SaasLockfileEnvelope,\n type SaasLockfileKnownSections,\n} from './wildo-saas-lock.shared.schemas';\n\n/**\n * Canonical path of the saas-app lockfile, relative to the saas root.\n */\nexport const WILDO_SAAS_LOCK_RELATIVE_PATH = '.wildo-saas/wildo-saas.lock.json';\n\n/**\n * Build the absolute lockfile path for a given saas root.\n */\nexport function getWildoSaasLockPath(saasRoot: string): string {\n return path.resolve(saasRoot, WILDO_SAAS_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Default `proper-lockfile` options. The 5s `stale` window matches\n * the Phase 0.B spike (`module-registry-analysis.md` Phase 0.B\n * Findings): typical lock-hold time is < 50ms; 5s is generous enough\n * to absorb a CI pause without compromising legitimate locks. Tests\n * 4a-4d all passed under these settings.\n *\n * `realpath: false` is required when the saas root is symlinked\n * (common with pnpm `dependenciesMeta.injected: true` workspaces).\n */\nexport const DEFAULT_LOCK_OPTIONS = {\n retries: { retries: 200, minTimeout: 5, maxTimeout: 50, factor: 1.2 },\n stale: 5000,\n realpath: false,\n} as const satisfies Parameters<typeof lockfile.lock>[1];\n\n/**\n * The result of merging caller options over {@link DEFAULT_LOCK_OPTIONS}.\n *\n * Its leaves are WIDENED (`number` / `boolean`) and that is the point: the\n * defaults are `as const`, so `typeof DEFAULT_LOCK_OPTIONS` describes those exact\n * literals — `stale: 5000`, `realpath: false`. A merge that honours a caller\n * override cannot satisfy it, because an overridden `stale` is not `5000`.\n *\n * Annotating the merge as `typeof DEFAULT_LOCK_OPTIONS` claimed the result was\n * always the defaults, which is true only when nothing was overridden — i.e. in\n * the one case the function exists to avoid.\n */\nexport type ResolvedLockOptions = {\n /**\n * Either a retry POLICY or a bare attempt count — `proper-lockfile` accepts\n * both, and the merge passes a bare number straight through\n * (`overrideRetries ?? baseRetries`). Omitting `number` made the merge unable to\n * describe its own fallback branch.\n */\n readonly retries: number | { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n readonly stale: number;\n readonly realpath: boolean;\n};\n\n/**\n * Deep-merge caller-supplied lock options on top of `DEFAULT_LOCK_OPTIONS`.\n *\n * Phase 1 review (M-2.1): a shallow merge replaced the entire\n * `retries` object whenever a caller passed a partial — so\n * `lockOptions: { retries: { retries: 5 } }` silently lost the\n * `minTimeout`/`maxTimeout`/`factor` defaults that Phase 0.B\n * validated. The deep merge keeps every default intact unless\n * the caller explicitly overrides each leaf.\n */\nfunction mergeLockOptions(\n // `DedicatedFileLockOptions`, NOT `Partial<typeof DEFAULT_LOCK_OPTIONS>`: that constant is\n // `as const`, so every leaf is a LITERAL type and `Partial` only reaches the top level — which\n // made the very call shape this merge exists to support (`{ retries: { retries: 5 } }`) a type\n // error, because `5` is not `200`. It also removes the cast the dedicated-lock caller needed.\n override?: DedicatedFileLockOptions,\n): ResolvedLockOptions {\n if (!override) return DEFAULT_LOCK_OPTIONS;\n const baseRetries = DEFAULT_LOCK_OPTIONS.retries;\n const overrideRetries = override.retries;\n const mergedRetries =\n typeof overrideRetries === 'object' && overrideRetries !== null\n ? { ...baseRetries, ...overrideRetries }\n : overrideRetries ?? baseRetries;\n return {\n ...DEFAULT_LOCK_OPTIONS,\n ...override,\n retries: mergedRetries,\n };\n}\n\nexport interface LockfileMutateOptions {\n /** Absolute path to the saas application root. */\n saasRoot: string;\n /**\n * Optional Zod schemas to validate sibling sections at parse time.\n * Companion-owned sections (e.g. `i18n`) are validated by passing\n * them here. CLI callers can pass\n * `DEFAULT_REGISTRY_SECTION_SCHEMAS` to validate `modules`.\n *\n * Sections not listed here are still PRESERVED on round-trip via\n * the envelope's `.catchall(z.unknown())` — they are simply not\n * type-narrowed.\n */\n sectionSchemas?: Record<string, z.ZodTypeAny>;\n /**\n * Override `proper-lockfile` options. Phase 0.B's measurements\n * suggest the defaults are fine for both CLI and companion\n * call patterns; this hook exists for tests + tuning.\n */\n lockOptions?: DedicatedFileLockOptions;\n /**\n * If true (default), the lockfile is created on first read with an\n * empty `sections` map. Set to false to fail with ENOENT.\n */\n createIfMissing?: boolean;\n}\n\n/**\n * Read the lockfile envelope, applying schema validation.\n *\n * - Returns a fresh empty envelope if the file does not exist\n * (and `createIfMissing` is not explicitly false).\n * - Validates the canonical envelope shape (schemaVersion, generatedAt,\n * sections) against `SaasLockfileEnvelopeSchema`.\n * - Applies caller-supplied `sectionSchemas` after the envelope\n * shape passes — failures throw a `ZodError` so the caller knows\n * exactly which section + field rejected.\n *\n * Does NOT acquire a lock; reads are unsynchronized. Callers that\n * need read-after-write coherence must read INSIDE `withLockfileMutate`.\n */\nexport async function readWildoSaasLock(\n options: Pick<LockfileMutateOptions, 'saasRoot' | 'sectionSchemas' | 'createIfMissing'>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, 'utf8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT' && options.createIfMissing !== false) {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n }\n throw err;\n }\n const json = JSON.parse(raw) as unknown;\n const envelope = SaasLockfileEnvelopeSchema.parse(json);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(envelope.sections, options.sectionSchemas);\n }\n return envelope;\n}\n\n/**\n * Validate every present `sections.<key>` against its caller-supplied\n * Zod schema AND write the parsed (default-expanded) value back so\n * defaults declared in those schemas actually persist on disk.\n *\n * Phase 1 review (H-2.1 / M-1.2): the prior implementation called\n * `.parse(value)` and discarded the result, which meant\n * `.default(...)` clauses in section schemas were only ever applied\n * during validation — never written. Schemas with shallow defaults\n * (e.g. `installed: z.record(...).default({})`) tolerated the bug\n * because mutators always set `installed` directly, but a future\n * schema with deep defaults would silently lose them.\n */\nfunction validateAndNormalizeSections(\n sections: SaasLockfileKnownSections,\n sectionSchemas: Record<string, z.ZodTypeAny>,\n): void {\n const mutable = sections as Record<string, unknown>;\n for (const [key, schema] of Object.entries(sectionSchemas)) {\n const value = mutable[key];\n if (value === undefined) continue;\n mutable[key] = schema.parse(value);\n }\n}\n\n/**\n * Acquire the OS-level lockfile lock, run `fn`, then release it.\n *\n * Wrapper around `proper-lockfile` that:\n * - Creates the parent dir + an empty file if missing (proper-lockfile\n * refuses to lock a non-existent file).\n * - Forwards `realpath: false` so symlinked workspaces lock correctly.\n * - Always releases the lock, even on error.\n */\nasync function withLock<T>(\n filePath: string,\n fn: () => Promise<T>,\n // A MERGED value, not the defaults — see `ResolvedLockOptions`. Typing this as\n // `typeof DEFAULT_LOCK_OPTIONS` demanded the literal `200`/`5000`/`false`, so any\n // caller-overridden option was a type error at the point of USE rather than at\n // the point of override, which is why it read as a failure in the merge.\n lockOptions: ResolvedLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n // Ensure the file exists; `proper-lockfile.lock` refuses ENOENT.\n try {\n await fs.access(filePath);\n } catch {\n await writeFileAtomicAsync(filePath, JSON.stringify(emptyEnvelope(), null, 2));\n }\n const release = await lockfile.lock(filePath, lockOptions);\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\nfunction emptyEnvelope(): SaasLockfileEnvelope {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n}\n\nasync function writeFileAtomicAsync(filePath: string, content: string): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n writeFileAtomic(filePath, content, (err: Error | undefined) => {\n if (err) reject(err);\n else resolve();\n });\n });\n}\n\n/**\n * Read-modify-write a lockfile under an OS-level lock.\n *\n * The mutator receives a deep-cloned, schema-validated envelope —\n * any in-place mutation is safe and won't bleed back into the\n * pre-write copy. After the mutator returns, the result is\n * re-validated against the envelope schema (and any caller-supplied\n * `sectionSchemas`) before being atomically written.\n *\n * `generatedAt` is always refreshed after a successful mutation.\n *\n * The library never inspects `sections.providers.runtimeScopes`,\n * `sections.modules`, or `sections.i18n` — it only enforces the\n * envelope shape. Concrete section semantics live in their owning\n * subsystems.\n */\nexport async function withLockfileMutate(\n options: LockfileMutateOptions,\n mutator: (envelope: SaasLockfileEnvelope) => void | Promise<void>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n const lockOptions = mergeLockOptions(options.lockOptions);\n return withLock(filePath, async () => {\n const before = await readWildoSaasLock({\n saasRoot: options.saasRoot,\n sectionSchemas: options.sectionSchemas,\n createIfMissing: true,\n });\n const next: SaasLockfileEnvelope = structuredClone(before);\n await mutator(next);\n next.generatedAt = new Date().toISOString();\n // Re-validate AFTER mutation; the mutator may have introduced\n // structurally-invalid input.\n SaasLockfileEnvelopeSchema.parse(next);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(next.sections, options.sectionSchemas);\n }\n await writeFileAtomicAsync(filePath, JSON.stringify(next, null, 2) + '\\n');\n return next;\n }, lockOptions);\n}\n\n/**\n * Hold an OS-level `proper-lockfile` lock on an ARBITRARY dedicated lock\n * target while `fn` runs — the path-parameterized sibling of\n * `withLockfileMutate` for callers that need cross-process mutual\n * exclusion WITHOUT the `wildo-saas.lock.json` envelope semantics.\n *\n * Why this exists (meta-workflows P-20, 2026-07-03): the companion's\n * coding-agent dispatch lane serializes workspace mutations on a\n * dedicated target (`<saasRoot>/.wildo-saas/state/workspace-mutation.lock`)\n * held for the WHOLE agent run (minutes). Routing that through\n * `withLockfileMutate` would hold the shared saas lockfile hostage —\n * starving i18n/registry writers — and the envelope re-validation is\n * meaningless for a pure mutex. The primitive lives HERE (not\n * companion-local) so the CLI can adopt the SAME lock target with the\n * SAME semantics when its worktree-mutating commands learn to respect it.\n *\n * Semantics:\n * - Parent directory + an empty placeholder file are created if missing\n * (`proper-lockfile` refuses ENOENT targets). The file content is never\n * read or written by this helper — it is a pure lock anchor.\n * - `proper-lockfile` auto-refreshes the lock mtime while the holder is\n * alive, so long-running holds survive the `stale` window; a crashed\n * holder's lock goes stale and is reclaimed by the next acquirer.\n * - Lock options merge over {@link DEFAULT_LOCK_OPTIONS}. Callers that\n * want fail-fast contention (HTTP 409 instead of queueing) pass\n * `{ retries: { retries: 0 } }`.\n * - The lock is always released (or at least attempted) on completion,\n * including the error path.\n *\n * Contention surfaces as the `proper-lockfile` `ELOCKED` error\n * (`error.code === 'ELOCKED'`) — callers map it to their own conflict\n * vocabulary.\n */\nexport interface DedicatedFileLockOptions {\n /** `proper-lockfile` retry policy — `{ retries: { retries: 0 } }` = fail-fast contention. */\n retries?: { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n /** Stale window in ms (lock mtime auto-refreshes while the holder lives). */\n stale?: number;\n /** Keep `false` for symlinked (pnpm-injected) workspaces. */\n realpath?: boolean;\n}\n\nexport async function withDedicatedFileLock<T>(\n lockTargetPath: string,\n fn: () => Promise<T>,\n lockOptions?: DedicatedFileLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(lockTargetPath), { recursive: true });\n try {\n await fs.access(lockTargetPath);\n } catch {\n await writeFileAtomicAsync(lockTargetPath, '');\n }\n const release = await lockfile.lock(\n lockTargetPath,\n mergeLockOptions(lockOptions),\n );\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/**\n * Canonical workspace-mutation lock target, app-root-relative. ONE constant\n * shared by every process that mutates the application worktree in a way\n * that must serialize against coding-agent dispatch runs (meta-workflows\n * P-20): the companion's dispatch lane holds it for the whole agent run;\n * CLI worktree-writers (e.g. `wildo config sync`) acquire it fail-fast\n * around their write phase. Deliberately NOT taken by human/parallel-session\n * edits (P-19b — per-file attribution compensates, never exclusion).\n * Keep companion and CLI on THIS constant — a hand-copied path is drift.\n */\nexport const WORKSPACE_MUTATION_LOCK_RELATIVE_PATH: string =\n '.wildo-saas/state/workspace-mutation.lock';\n\n/** Absolute workspace-mutation lock target for an application root. */\nexport function getWorkspaceMutationLockPath(saasRoot: string): string {\n return path.join(saasRoot, WORKSPACE_MUTATION_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Section-scoped mutate. The mutator only sees one section's payload\n * (`sections.<sectionKey>`) and CANNOT reach sibling sections —\n * preventing accidental clobbers. Returns the mutated section.\n *\n * Use this from CLI callers (`RegistryLockfileService`) so cross-\n * section bugs are impossible by construction. Companion callers\n * that legitimately need full-envelope access keep using\n * `withLockfileMutate` directly.\n */\nexport async function withLockfileSectionMutate<S>(\n options: LockfileMutateOptions & {\n /** Section key under `sections` (e.g. `'modules'`, `'i18n'`). */\n sectionKey: string;\n /** Zod schema validating the section payload. Required. */\n sectionSchema: z.ZodType<S>;\n /** Initial value when the section does not yet exist. */\n initialSection: () => S;\n },\n mutator: (section: S) => S | void | Promise<S | void>,\n): Promise<S> {\n let mutatedOut!: S;\n await withLockfileMutate(\n {\n saasRoot: options.saasRoot,\n lockOptions: options.lockOptions,\n sectionSchemas: {\n ...options.sectionSchemas,\n [options.sectionKey]: options.sectionSchema,\n },\n },\n async (envelope) => {\n const sections = envelope.sections as Record<string, unknown>;\n const current = (sections[options.sectionKey] as S | undefined) ?? options.initialSection();\n const cloned = structuredClone(current);\n const ret = await mutator(cloned);\n const next = (ret ?? cloned) as S;\n // Per-section validation (also covers initial-default re-validation).\n mutatedOut = options.sectionSchema.parse(next);\n sections[options.sectionKey] = mutatedOut;\n },\n );\n return mutatedOut;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"lockfile-io.js","sourceRoot":"","sources":["../../../../src/lockfile/lockfile-io.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AAEH,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,QAAQ,MAAM,iBAAiB,CAAC;AACvC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD,OAAO,EACL,0BAA0B,GAG3B,MAAM,kCAAkC,CAAC;AAE1C;;GAEG;AAC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G,QAAQ,CAAC,QAAmC,CAAC;QAC9D,MAAM,OAAO,GAAI,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAmB,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;QAC5F,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;QACxC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;QAClC,MAAM,IAAI,GAAG,CAAC,GAAG,IAAI,MAAM,CAAM,CAAC;QAClC,sEAAsE;QACtE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC,CACF,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC","sourcesContent":["/**\n * Shared `wildo-saas.lock.json` IO primitives.\n *\n * Phase 1 graduates the locking + atomic-write surface validated by\n * the Phase 0.B contention spike (`module-registry-analysis.md`)\n * into `platform-config-lib`. Both the dev companion's\n * `WildoSaasLockCompanionService` and the CLI-side\n * `RegistryLockfileService` consume this module so concurrent\n * writers — across processes (CLI + companion + minions) — never\n * lose updates and never observe a half-written envelope.\n *\n * Exposes two layers:\n *\n * 1. `withLockfileMutate(opts, mutator)` — full-envelope mutate\n * under `proper-lockfile` + `write-file-atomic`. The companion\n * uses this so it can preserve its full-envelope contract and\n * validate its companion-owned i18n schema in the same pass.\n *\n * 2. `withLockfileSectionMutate(opts, mutator)` — section-scoped\n * mutate. The CLI uses this so it can ONLY touch one section\n * (e.g. `sections.modules`) and never accidentally clobber a\n * sibling section.\n *\n * Both layers preserve unknown sections verbatim — every consumer\n * MUST round-trip every `sections.*` key it does not recognize.\n *\n * Hard contract (KD-4 / KD-15 / KD-18):\n * - The library NEVER writes provider runtime artifacts under\n * `.wildo-saas/generated/providers/*.runtime-providers.generated.json` or\n * `src/generated/wildo-provider-runtime.generated.ts`. Those are\n * produced by the provider materialization workflow alone.\n * - `sections.providers.runtimeScopes` is owned end-to-end by the\n * provider workstream; module-registry callers MUST NOT mutate it.\n * This module is unaware of the provider section beyond\n * preserving its bytes.\n */\n\nimport { promises as fs } from 'node:fs';\nimport * as path from 'node:path';\nimport lockfile from 'proper-lockfile';\nimport writeFileAtomic from 'write-file-atomic';\nimport { z } from 'zod';\nimport {\n SaasLockfileEnvelopeSchema,\n type SaasLockfileEnvelope,\n type SaasLockfileKnownSections,\n} from './wildo-saas-lock.shared.schemas';\n\n/**\n * Canonical path of the saas-app lockfile, relative to the saas root.\n */\nexport const WILDO_SAAS_LOCK_RELATIVE_PATH = '.wildo-saas/wildo-saas.lock.json';\n\n/**\n * Build the absolute lockfile path for a given saas root.\n */\nexport function getWildoSaasLockPath(saasRoot: string): string {\n return path.resolve(saasRoot, WILDO_SAAS_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Default `proper-lockfile` options. The 5s `stale` window matches\n * the Phase 0.B spike (`module-registry-analysis.md` Phase 0.B\n * Findings): typical lock-hold time is < 50ms; 5s is generous enough\n * to absorb a CI pause without compromising legitimate locks. Tests\n * 4a-4d all passed under these settings.\n *\n * `realpath: false` is required when the saas root is symlinked\n * (common with pnpm `dependenciesMeta.injected: true` workspaces).\n */\nexport const DEFAULT_LOCK_OPTIONS = {\n retries: { retries: 200, minTimeout: 5, maxTimeout: 50, factor: 1.2 },\n stale: 5000,\n realpath: false,\n} as const satisfies Parameters<typeof lockfile.lock>[1];\n\n/**\n * The result of merging caller options over {@link DEFAULT_LOCK_OPTIONS}.\n *\n * Its leaves are WIDENED (`number` / `boolean`) and that is the point: the\n * defaults are `as const`, so `typeof DEFAULT_LOCK_OPTIONS` describes those exact\n * literals — `stale: 5000`, `realpath: false`. A merge that honours a caller\n * override cannot satisfy it, because an overridden `stale` is not `5000`.\n *\n * Annotating the merge as `typeof DEFAULT_LOCK_OPTIONS` claimed the result was\n * always the defaults, which is true only when nothing was overridden — i.e. in\n * the one case the function exists to avoid.\n */\nexport type ResolvedLockOptions = {\n /**\n * Either a retry POLICY or a bare attempt count — `proper-lockfile` accepts\n * both, and the merge passes a bare number straight through\n * (`overrideRetries ?? baseRetries`). Omitting `number` made the merge unable to\n * describe its own fallback branch.\n */\n readonly retries: number | { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n readonly stale: number;\n readonly realpath: boolean;\n};\n\n/**\n * Deep-merge caller-supplied lock options on top of `DEFAULT_LOCK_OPTIONS`.\n *\n * Phase 1 review (M-2.1): a shallow merge replaced the entire\n * `retries` object whenever a caller passed a partial — so\n * `lockOptions: { retries: { retries: 5 } }` silently lost the\n * `minTimeout`/`maxTimeout`/`factor` defaults that Phase 0.B\n * validated. The deep merge keeps every default intact unless\n * the caller explicitly overrides each leaf.\n */\nfunction mergeLockOptions(\n // `DedicatedFileLockOptions`, NOT `Partial<typeof DEFAULT_LOCK_OPTIONS>`: that constant is\n // `as const`, so every leaf is a LITERAL type and `Partial` only reaches the top level — which\n // made the very call shape this merge exists to support (`{ retries: { retries: 5 } }`) a type\n // error, because `5` is not `200`. It also removes the cast the dedicated-lock caller needed.\n override?: DedicatedFileLockOptions,\n): ResolvedLockOptions {\n if (!override) return DEFAULT_LOCK_OPTIONS;\n const baseRetries = DEFAULT_LOCK_OPTIONS.retries;\n const overrideRetries = override.retries;\n const mergedRetries =\n typeof overrideRetries === 'object' && overrideRetries !== null\n ? { ...baseRetries, ...overrideRetries }\n : overrideRetries ?? baseRetries;\n return {\n ...DEFAULT_LOCK_OPTIONS,\n ...override,\n retries: mergedRetries,\n };\n}\n\nexport interface LockfileMutateOptions {\n /** Absolute path to the saas application root. */\n saasRoot: string;\n /**\n * Optional Zod schemas to validate sibling sections at parse time.\n * Companion-owned sections (e.g. `i18n`) are validated by passing\n * them here. CLI callers can pass\n * `DEFAULT_REGISTRY_SECTION_SCHEMAS` to validate `modules`.\n *\n * Sections not listed here are still PRESERVED on round-trip via\n * the envelope's `.catchall(z.unknown())` — they are simply not\n * type-narrowed.\n */\n sectionSchemas?: Record<string, z.ZodTypeAny>;\n /**\n * Override `proper-lockfile` options. Phase 0.B's measurements\n * suggest the defaults are fine for both CLI and companion\n * call patterns; this hook exists for tests + tuning.\n */\n lockOptions?: DedicatedFileLockOptions;\n /**\n * If true (default), the lockfile is created on first read with an\n * empty `sections` map. Set to false to fail with ENOENT.\n */\n createIfMissing?: boolean;\n}\n\n/**\n * Read the lockfile envelope, applying schema validation.\n *\n * - Returns a fresh empty envelope if the file does not exist\n * (and `createIfMissing` is not explicitly false).\n * - Validates the canonical envelope shape (schemaVersion, generatedAt,\n * sections) against `SaasLockfileEnvelopeSchema`.\n * - Applies caller-supplied `sectionSchemas` after the envelope\n * shape passes — failures throw a `ZodError` so the caller knows\n * exactly which section + field rejected.\n *\n * Does NOT acquire a lock; reads are unsynchronized. Callers that\n * need read-after-write coherence must read INSIDE `withLockfileMutate`.\n */\nexport async function readWildoSaasLock(\n options: Pick<LockfileMutateOptions, 'saasRoot' | 'sectionSchemas' | 'createIfMissing'>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n let raw: string;\n try {\n raw = await fs.readFile(filePath, 'utf8');\n } catch (err) {\n if ((err as NodeJS.ErrnoException).code === 'ENOENT' && options.createIfMissing !== false) {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n }\n throw err;\n }\n const json = JSON.parse(raw) as unknown;\n const envelope = SaasLockfileEnvelopeSchema.parse(json);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(envelope.sections, options.sectionSchemas);\n }\n return envelope;\n}\n\n/**\n * Validate every present `sections.<key>` against its caller-supplied\n * Zod schema AND write the parsed (default-expanded) value back so\n * defaults declared in those schemas actually persist on disk.\n *\n * Phase 1 review (H-2.1 / M-1.2): the prior implementation called\n * `.parse(value)` and discarded the result, which meant\n * `.default(...)` clauses in section schemas were only ever applied\n * during validation — never written. Schemas with shallow defaults\n * (e.g. `installed: z.record(...).default({})`) tolerated the bug\n * because mutators always set `installed` directly, but a future\n * schema with deep defaults would silently lose them.\n */\nfunction validateAndNormalizeSections(\n sections: SaasLockfileKnownSections,\n sectionSchemas: Record<string, z.ZodTypeAny>,\n): void {\n const mutable = sections as Record<string, unknown>;\n for (const [key, schema] of Object.entries(sectionSchemas)) {\n const value = mutable[key];\n if (value === undefined) continue;\n mutable[key] = schema.parse(value);\n }\n}\n\n/**\n * Acquire the OS-level lockfile lock, run `fn`, then release it.\n *\n * Wrapper around `proper-lockfile` that:\n * - Creates the parent dir + an empty file if missing (proper-lockfile\n * refuses to lock a non-existent file).\n * - Forwards `realpath: false` so symlinked workspaces lock correctly.\n * - Always releases the lock, even on error.\n */\nasync function withLock<T>(\n filePath: string,\n fn: () => Promise<T>,\n // A MERGED value, not the defaults — see `ResolvedLockOptions`. Typing this as\n // `typeof DEFAULT_LOCK_OPTIONS` demanded the literal `200`/`5000`/`false`, so any\n // caller-overridden option was a type error at the point of USE rather than at\n // the point of override, which is why it read as a failure in the merge.\n lockOptions: ResolvedLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(filePath), { recursive: true });\n // Ensure the file exists; `proper-lockfile.lock` refuses ENOENT.\n try {\n await fs.access(filePath);\n } catch {\n await writeFileAtomicAsync(filePath, JSON.stringify(emptyEnvelope(), null, 2));\n }\n const release = await lockfile.lock(filePath, lockOptions);\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/** The one on-disk form of the envelope: two-space JSON with a trailing newline. */\nfunction serializeLockfile(envelope: SaasLockfileEnvelope): string {\n return JSON.stringify(envelope, null, 2) + '\\n';\n}\n\nfunction emptyEnvelope(): SaasLockfileEnvelope {\n return {\n schemaVersion: 2,\n generatedAt: new Date().toISOString(),\n sections: {},\n };\n}\n\nasync function writeFileAtomicAsync(filePath: string, content: string): Promise<void> {\n await new Promise<void>((resolve, reject) => {\n writeFileAtomic(filePath, content, (err: Error | undefined) => {\n if (err) reject(err);\n else resolve();\n });\n });\n}\n\n/**\n * Read-modify-write a lockfile under an OS-level lock.\n *\n * The mutator receives a deep-cloned, schema-validated envelope —\n * any in-place mutation is safe and won't bleed back into the\n * pre-write copy. After the mutator returns, the result is\n * re-validated against the envelope schema (and any caller-supplied\n * `sectionSchemas`) before being atomically written.\n *\n * `generatedAt` is refreshed only when the mutation changes the file. When the bytes that would be\n * written — with the previous `generatedAt` — equal the bytes on disk, nothing is written and the\n * envelope is returned as it was. The lockfile is committed, and a timestamp that moved on every no-op\n * sync dirtied the tree with nothing in it: a `wildo registry add` + `remove` round trip left exactly\n * one diff, this field (#1765). The comparison is on BYTES rather than on the parsed sections so a\n * no-op mutation still writes back what normalization changed (schema defaults, a missing trailing\n * newline).\n *\n * The library never inspects `sections.providers.runtimeScopes`,\n * `sections.modules`, or `sections.i18n` — it only enforces the\n * envelope shape. Concrete section semantics live in their owning\n * subsystems.\n */\nexport async function withLockfileMutate(\n options: LockfileMutateOptions,\n mutator: (envelope: SaasLockfileEnvelope) => void | Promise<void>,\n): Promise<SaasLockfileEnvelope> {\n const filePath = getWildoSaasLockPath(options.saasRoot);\n const lockOptions = mergeLockOptions(options.lockOptions);\n return withLock(filePath, async () => {\n const before = await readWildoSaasLock({\n saasRoot: options.saasRoot,\n sectionSchemas: options.sectionSchemas,\n createIfMissing: true,\n });\n const next: SaasLockfileEnvelope = structuredClone(before);\n await mutator(next);\n // Re-validate AFTER mutation; the mutator may have introduced\n // structurally-invalid input.\n SaasLockfileEnvelopeSchema.parse(next);\n if (options.sectionSchemas) {\n validateAndNormalizeSections(next.sections, options.sectionSchemas);\n }\n const onDisk = await fs.readFile(filePath, 'utf8').catch(() => null);\n if (onDisk === serializeLockfile({ ...next, generatedAt: before.generatedAt })) {\n return { ...next, generatedAt: before.generatedAt };\n }\n next.generatedAt = new Date().toISOString();\n await writeFileAtomicAsync(filePath, serializeLockfile(next));\n return next;\n }, lockOptions);\n}\n\n/**\n * Hold an OS-level `proper-lockfile` lock on an ARBITRARY dedicated lock\n * target while `fn` runs — the path-parameterized sibling of\n * `withLockfileMutate` for callers that need cross-process mutual\n * exclusion WITHOUT the `wildo-saas.lock.json` envelope semantics.\n *\n * Why this exists (meta-workflows P-20, 2026-07-03): the companion's\n * coding-agent dispatch lane serializes workspace mutations on a\n * dedicated target (`<saasRoot>/.wildo-saas/state/workspace-mutation.lock`)\n * held for the WHOLE agent run (minutes). Routing that through\n * `withLockfileMutate` would hold the shared saas lockfile hostage —\n * starving i18n/registry writers — and the envelope re-validation is\n * meaningless for a pure mutex. The primitive lives HERE (not\n * companion-local) so the CLI can adopt the SAME lock target with the\n * SAME semantics when its worktree-mutating commands learn to respect it.\n *\n * Semantics:\n * - Parent directory + an empty placeholder file are created if missing\n * (`proper-lockfile` refuses ENOENT targets). The file content is never\n * read or written by this helper — it is a pure lock anchor.\n * - `proper-lockfile` auto-refreshes the lock mtime while the holder is\n * alive, so long-running holds survive the `stale` window; a crashed\n * holder's lock goes stale and is reclaimed by the next acquirer.\n * - Lock options merge over {@link DEFAULT_LOCK_OPTIONS}. Callers that\n * want fail-fast contention (HTTP 409 instead of queueing) pass\n * `{ retries: { retries: 0 } }`.\n * - The lock is always released (or at least attempted) on completion,\n * including the error path.\n *\n * Contention surfaces as the `proper-lockfile` `ELOCKED` error\n * (`error.code === 'ELOCKED'`) — callers map it to their own conflict\n * vocabulary.\n */\nexport interface DedicatedFileLockOptions {\n /** `proper-lockfile` retry policy — `{ retries: { retries: 0 } }` = fail-fast contention. */\n retries?: { retries?: number; minTimeout?: number; maxTimeout?: number; factor?: number };\n /** Stale window in ms (lock mtime auto-refreshes while the holder lives). */\n stale?: number;\n /** Keep `false` for symlinked (pnpm-injected) workspaces. */\n realpath?: boolean;\n}\n\nexport async function withDedicatedFileLock<T>(\n lockTargetPath: string,\n fn: () => Promise<T>,\n lockOptions?: DedicatedFileLockOptions,\n): Promise<T> {\n await fs.mkdir(path.dirname(lockTargetPath), { recursive: true });\n try {\n await fs.access(lockTargetPath);\n } catch {\n await writeFileAtomicAsync(lockTargetPath, '');\n }\n const release = await lockfile.lock(\n lockTargetPath,\n mergeLockOptions(lockOptions),\n );\n try {\n return await fn();\n } finally {\n await release();\n }\n}\n\n/**\n * Canonical workspace-mutation lock target, app-root-relative. ONE constant\n * shared by every process that mutates the application worktree in a way\n * that must serialize against coding-agent dispatch runs (meta-workflows\n * P-20): the companion's dispatch lane holds it for the whole agent run;\n * CLI worktree-writers (e.g. `wildo config sync`) acquire it fail-fast\n * around their write phase. Deliberately NOT taken by human/parallel-session\n * edits (P-19b — per-file attribution compensates, never exclusion).\n * Keep companion and CLI on THIS constant — a hand-copied path is drift.\n */\nexport const WORKSPACE_MUTATION_LOCK_RELATIVE_PATH: string =\n '.wildo-saas/state/workspace-mutation.lock';\n\n/** Absolute workspace-mutation lock target for an application root. */\nexport function getWorkspaceMutationLockPath(saasRoot: string): string {\n return path.join(saasRoot, WORKSPACE_MUTATION_LOCK_RELATIVE_PATH);\n}\n\n/**\n * Section-scoped mutate. The mutator only sees one section's payload\n * (`sections.<sectionKey>`) and CANNOT reach sibling sections —\n * preventing accidental clobbers. Returns the mutated section.\n *\n * Use this from CLI callers (`RegistryLockfileService`) so cross-\n * section bugs are impossible by construction. Companion callers\n * that legitimately need full-envelope access keep using\n * `withLockfileMutate` directly.\n */\nexport async function withLockfileSectionMutate<S>(\n options: LockfileMutateOptions & {\n /** Section key under `sections` (e.g. `'modules'`, `'i18n'`). */\n sectionKey: string;\n /** Zod schema validating the section payload. Required. */\n sectionSchema: z.ZodType<S>;\n /** Initial value when the section does not yet exist. */\n initialSection: () => S;\n },\n mutator: (section: S) => S | void | Promise<S | void>,\n): Promise<S> {\n let mutatedOut!: S;\n await withLockfileMutate(\n {\n saasRoot: options.saasRoot,\n lockOptions: options.lockOptions,\n sectionSchemas: {\n ...options.sectionSchemas,\n [options.sectionKey]: options.sectionSchema,\n },\n },\n async (envelope) => {\n const sections = envelope.sections as Record<string, unknown>;\n const current = (sections[options.sectionKey] as S | undefined) ?? options.initialSection();\n const cloned = structuredClone(current);\n const ret = await mutator(cloned);\n const next = (ret ?? cloned) as S;\n // Per-section validation (also covers initial-default re-validation).\n mutatedOut = options.sectionSchema.parse(next);\n sections[options.sectionKey] = mutatedOut;\n },\n );\n return mutatedOut;\n}\n"]}
|
|
@@ -19,8 +19,20 @@
|
|
|
19
19
|
* map is omitted, behavior matches Slice 2.5b — backward-compatible.
|
|
20
20
|
* When the map IS supplied but doesn't contain a module for the
|
|
21
21
|
* resolved `InfraProvider`, the materializer falls back to the
|
|
22
|
-
* authored-entry digest for that capability
|
|
23
|
-
*
|
|
22
|
+
* authored-entry digest for that capability. After #1693 that can only
|
|
23
|
+
* happen for a provider the catalogue declares servable WITHOUT a module
|
|
24
|
+
* (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave
|
|
25
|
+
* `IMMUDB_SELF` its module): every other module-less provider is refused
|
|
26
|
+
* before any digest is computed.
|
|
27
|
+
*
|
|
28
|
+
* **#1693 (2026-09-26)**: the materializer REFUSES any declaration the
|
|
29
|
+
* platform cannot serve — one that resolves to no `InfraProvider`, or to
|
|
30
|
+
* one outside the `servableProviders` set the caller must supply. It used
|
|
31
|
+
* to skip the first silently and hash the second, so the lockfile either
|
|
32
|
+
* omitted a declared kind or recorded a selection nothing executes. Both
|
|
33
|
+
* of its callers (`wildo config sync`, `wildo lock check`) reach the one
|
|
34
|
+
* check here, so the two projections cannot disagree about what is
|
|
35
|
+
* refused. See `backing-service-servability.ts`.
|
|
24
36
|
*
|
|
25
37
|
* **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses
|
|
26
38
|
* `stableSha256Digest` (recursive sorted-keys serialization via
|
|
@@ -63,12 +75,21 @@ export interface MaterializeInfraSectionOptions {
|
|
|
63
75
|
* `buildInfraProviderModuleMap()`. Apps-manager-side callers
|
|
64
76
|
* (none today) would do the same.
|
|
65
77
|
*
|
|
66
|
-
* **
|
|
67
|
-
* falls back to the authored-entry digest
|
|
68
|
-
*
|
|
69
|
-
*
|
|
78
|
+
* **Module-less providers**: a resolved provider with no entry here
|
|
79
|
+
* falls back to the authored-entry digest. Only a provider in
|
|
80
|
+
* `servableProviders` can reach that point, so the fallback covers
|
|
81
|
+
* exactly the catalogue's explicit module-less exemptions.
|
|
70
82
|
*/
|
|
71
83
|
moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;
|
|
84
|
+
/**
|
|
85
|
+
* The providers the platform can actually SERVE — from
|
|
86
|
+
* `collectServableInfraProviders()` in `@wildo-ai/platform-infra-providers`.
|
|
87
|
+
* REQUIRED, not optional: a caller that could omit it would be a
|
|
88
|
+
* projection that skips the refusal, and the whole point is that
|
|
89
|
+
* `wildo config sync` and `wildo lock check` refuse the same
|
|
90
|
+
* declarations (#1693).
|
|
91
|
+
*/
|
|
92
|
+
servableProviders: ReadonlySet<InfraProvider>;
|
|
72
93
|
/**
|
|
73
94
|
* The previous lockfile's `sections.infra` (when present). Threaded
|
|
74
95
|
* so `providerSelectedAt` is STICKY: a capability whose resolved
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialize-infra-section.d.ts","sourceRoot":"","sources":["../../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"materialize-infra-section.d.ts","sourceRoot":"","sources":["../../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAKL,KAAK,wBAAwB,EAC9B,MAAM,mDAAmD,CAAC;AAE3D,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EAEpB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAEV,wBAAwB,EACzB,MAAM,kCAAkC,CAAC;AAG1C;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,wBAAwB,GAAG,SAAS,CAAC;CACvD;AAED,MAAM,WAAW,8BAA8B;IAC7C,IAAI,EAAE,aAAa,CAAC,sBAAsB,CAAC,CAAC;IAC5C;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;;;;;;;;;;;;;;;OAgBG;IACH,SAAS,CAAC,EAAE,WAAW,CAAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;IAC5D;;;;;;;OAOG;IACH,iBAAiB,EAAE,WAAW,CAAC,aAAa,CAAC,CAAC;IAC9C;;;;;;;;;;;;;;;;;OAiBG;IACH,eAAe,CAAC,EAAE,wBAAwB,CAAC;CAC5C;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,wBAAwB,GAAG,SAAS,CAuBtC"}
|
|
@@ -19,8 +19,20 @@
|
|
|
19
19
|
* map is omitted, behavior matches Slice 2.5b — backward-compatible.
|
|
20
20
|
* When the map IS supplied but doesn't contain a module for the
|
|
21
21
|
* resolved `InfraProvider`, the materializer falls back to the
|
|
22
|
-
* authored-entry digest for that capability
|
|
23
|
-
*
|
|
22
|
+
* authored-entry digest for that capability. After #1693 that can only
|
|
23
|
+
* happen for a provider the catalogue declares servable WITHOUT a module
|
|
24
|
+
* (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave
|
|
25
|
+
* `IMMUDB_SELF` its module): every other module-less provider is refused
|
|
26
|
+
* before any digest is computed.
|
|
27
|
+
*
|
|
28
|
+
* **#1693 (2026-09-26)**: the materializer REFUSES any declaration the
|
|
29
|
+
* platform cannot serve — one that resolves to no `InfraProvider`, or to
|
|
30
|
+
* one outside the `servableProviders` set the caller must supply. It used
|
|
31
|
+
* to skip the first silently and hash the second, so the lockfile either
|
|
32
|
+
* omitted a declared kind or recorded a selection nothing executes. Both
|
|
33
|
+
* of its callers (`wildo config sync`, `wildo lock check`) reach the one
|
|
34
|
+
* check here, so the two projections cannot disagree about what is
|
|
35
|
+
* refused. See `backing-service-servability.ts`.
|
|
24
36
|
*
|
|
25
37
|
* **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses
|
|
26
38
|
* `stableSha256Digest` (recursive sorted-keys serialization via
|
|
@@ -28,6 +40,7 @@
|
|
|
28
40
|
* spuriously trigger drift.
|
|
29
41
|
*/
|
|
30
42
|
import { BackingServiceKind, BackingServiceKindToInfraCapability, resolveInfraProvider, } from '../project-config/shared/backing-services.schemas.js';
|
|
43
|
+
import { assertBackingServiceDeclarationsServable } from '../project-config/shared/backing-service-servability.js';
|
|
31
44
|
import { stableSha256Digest } from './canonical-json.js';
|
|
32
45
|
/**
|
|
33
46
|
* Project authored infra envs into the lockfile `sections.infra`
|
|
@@ -38,6 +51,8 @@ import { stableSha256Digest } from './canonical-json.js';
|
|
|
38
51
|
export function materializeInfraSection(options) {
|
|
39
52
|
if (options.envs.length === 0)
|
|
40
53
|
return undefined;
|
|
54
|
+
// Refuse every unservable declaration, across every environment, before projecting any of them.
|
|
55
|
+
assertBackingServiceDeclarationsServable({ envs: options.envs, servableProviders: options.servableProviders });
|
|
41
56
|
const environments = {};
|
|
42
57
|
let recordedAny = false;
|
|
43
58
|
for (const env of options.envs) {
|
|
@@ -71,17 +86,15 @@ function projectBackingServicesToCapabilities(backingServices, generatedAt, envN
|
|
|
71
86
|
const providerBrand = entry.provider;
|
|
72
87
|
const provider = resolveInfraProvider(kind, entry.source, providerBrand);
|
|
73
88
|
if (!provider) {
|
|
74
|
-
//
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
|
|
78
|
-
continue;
|
|
89
|
+
// Unreachable: `assertBackingServiceDeclarationsServable` has already refused every declaration
|
|
90
|
+
// that resolves to no provider. Kept as a throw rather than a `continue`, because a silent skip
|
|
91
|
+
// here is precisely the defect that assertion closed (#1693).
|
|
92
|
+
throw new Error(`backingServices.${kind} in environment '${envName}' resolved to no provider after the servability check.`);
|
|
79
93
|
}
|
|
80
94
|
// Slice 2.5c-1: prefer module.plan() digest when the catalog
|
|
81
95
|
// exposes a module for this provider. Falls back to the
|
|
82
|
-
// authored-entry digest for
|
|
83
|
-
//
|
|
84
|
-
// break materialization.
|
|
96
|
+
// authored-entry digest only for a servable provider the catalogue
|
|
97
|
+
// serves without a module (the operator-credentialed exemptions).
|
|
85
98
|
const planContributionDigest = computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)
|
|
86
99
|
?? computeAuthoredEntryDigest(entry);
|
|
87
100
|
// `providerSelectedAt` is STICKY — only a provider's first
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialize-infra-section.js","sourceRoot":"","sources":["../../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EACL,kBAAkB,EAClB,mCAAmC,EACnC,oBAAoB,GAGrB,MAAM,mDAAmD,CAAC;AAU3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AA+DtD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAEhD,MAAM,YAAY,GAA6C,EAAE,CAAC;IAClE,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,oCAAoC,CACvD,GAAG,CAAC,eAAe,EACnB,OAAO,CAAC,WAAW,EACnB,GAAG,CAAC,OAAO,EACX,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CACnD,CAAC;QACF,IAAI,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QACrD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,EAAE,CAAC;QAC7C,WAAW,GA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AkE;QAClE,kEAAkE;QAClE,MAAM,aAAa,GAAG,WAAW,EAAE,YAAY,CAAC,UAAU,CAAC,CAAC;QAC5D,MAAM,kBAAkB,GACtB,aAAa,IAAI,aAAa,CAAC,QAAQ,KAAK,QAAQ;YAClD,CAAC,CAAC,aAAa,CAAC,kBAAkB;YAClC,CAAC,CAAC,WAAW,CAAC;QAElB,YAAY,CAAC,UAAU,CAAC,GAAG;YACzB,QAAQ;YACR,kBAAkB;YAClB,sBAAsB;SACvB,CAAC;IACJ,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,SAAS,0BAA0B,CAAC,KAA8B;IAChE,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAS,uBAAuB,CAC9B,QAAuB,EACvB,IAAwB,EACxB,KAA8B,EAC9B,YAAoB,EACpB,OAAe,EACf,SAAsE;IAEtE,IAAI,CAAC,SAAS;QAAE,OAAO,SAAS,CAAC;IACjC,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACvC,IAAI,CAAC,MAAM;QAAE,OAAO,SAAS,CAAC;IAC9B,MAAM,eAAe,GAAiC;QACpD,WAAW,EAAE,OAAO;QACpB,OAAO,EAAE,SAAS,EAAE,uDAAuD;QAC3E,iBAAiB,EAAE,IAAI;QACvB,MAAM,EAAE,KAAK;KACd,CAAC;IACF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;IAClD,OAAO,kBAAkB,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * `materializeInfraSection` — pure function that projects authored\n * `wildo.infra.<envName>.config.ts` files into the\n * `sections.infra` slice of `wildo-saas.lock.json` (Slice 2.5b of\n * `infra-provider-planner.md`).\n *\n * Lives in `platform-config-lib` (no runtime, no DI, no I/O — pure\n * projection). The CLI-side caller is responsible for loading the\n * authored configs from disk via\n * `loadInfraEnvConfig` (this package; the CLI's `loadAuthoredInfraEnvConfig` delegates to it) and passing\n * the parsed `backingServices` slice plus the env name.\n *\n * **Slice 2.5c-1 (2026-05-10)**: when the caller supplies an optional\n * `moduleMap` of `InfraProvider → InfraProviderModule`, the digest\n * is computed from `module.plan(planningContext)` instead of from\n * the authored entry. This captures **provider-version drift**\n * (e.g., a module change to plumbing port, secret env vars,\n * per-app blob paths) on top of authored-config drift. When the\n * map is omitted, behavior matches Slice 2.5b — backward-compatible.\n * When the map IS supplied but doesn't contain a module for the\n * resolved `InfraProvider`, the materializer falls back to the\n * authored-entry digest for that capability (allows partial\n * coverage as the catalog grows in Slice 5).\n *\n * **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses\n * `stableSha256Digest` (recursive sorted-keys serialization via\n * `canonical-json.ts`) so nested-object property reorders don't\n * spuriously trigger drift.\n */\n\nimport {\n BackingServiceKind,\n BackingServiceKindToInfraCapability,\n resolveInfraProvider,\n type BackingServiceEnvConfig,\n type BackingServicesEnvConfig,\n} from '../project-config/shared/backing-services.schemas';\nimport type {\n InfraProvider,\n InfraProviderModule,\n InfraProviderPlanningContext,\n} from '../project-config/shared/infra-providers.schemas';\nimport type {\n SaasLockfileInfraEnvironment,\n SaasLockfileInfraSection,\n} from './wildo-saas-lock.shared.schemas';\nimport { stableSha256Digest } from './canonical-json';\n\n/**\n * Per-env input for the materializer. The caller has already loaded\n * the authored `wildo.infra.<envName>.config.ts` and parsed it via\n * `defineInfraEnvConfig`; we only consume the `backingServices`\n * slice (the only authored surface that maps to `InfraCapability`\n * selections).\n */\nexport interface InfraEnvSelectionInput {\n envName: string;\n backingServices: BackingServicesEnvConfig | undefined;\n}\n\nexport interface MaterializeInfraSectionOptions {\n envs: ReadonlyArray<InfraEnvSelectionInput>;\n /**\n * ISO-8601 timestamp used as the selection time for NEWLY-selected\n * or CHANGED capabilities (see `previousSection` for the sticky-reuse\n * rule). Caller controls it so multi-env writes share one\n * deterministic timestamp (matches the pattern from\n * `materializeSaasProviderRuntimeArtifacts`).\n */\n generatedAt: string;\n /**\n * Optional `InfraProvider → InfraProviderModule` lookup. When\n * present, each capability's `planContributionDigest` is computed\n * from `module.plan(planningContext)` (richer — captures\n * provider-version drift) instead of from the authored entry\n * (Slice 2.5b). Slice 2.5c-1 of `infra-provider-planner.md`.\n *\n * The CLI-side caller in `provider-runtime-sync.service.ts`\n * builds this from `@wildo-ai/platform-infra-providers`'s\n * `buildInfraProviderModuleMap()`. Apps-manager-side callers\n * (none today) would do the same.\n *\n * **Partial coverage**: a missing entry for a resolved provider\n * falls back to the authored-entry digest — no fail-closed. This\n * lets the catalog grow incrementally (Slice 5 stateless modules\n * still pending) without blocking lockfile materialization.\n */\n moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;\n /**\n * The previous lockfile's `sections.infra` (when present). Threaded\n * so `providerSelectedAt` is STICKY: a capability whose resolved\n * `provider` is unchanged retains its prior `providerSelectedAt`\n * instead of being re-stamped with `generatedAt`. Only a newly-\n * selected capability or a provider CHANGE stamps a fresh\n * `generatedAt`.\n *\n * **Why this exists**: `generatedAt` is the lockfile's volatile\n * generation timestamp — it is bumped by EVERY lockfile write,\n * including writes by unrelated subsystems via `withLockfileMutate`.\n * Deriving `providerSelectedAt` directly from it made the field\n * drift on every unrelated write, producing phantom\n * `wildo lock check` failures even when no infra selection changed.\n * Both callers — the `wildo config sync` writer and the\n * `wildo lock check` drift-checker — MUST pass the same previous\n * section so their projections agree.\n */\n previousSection?: SaasLockfileInfraSection;\n}\n\n/**\n * Project authored infra envs into the lockfile `sections.infra`\n * shape. Returns `undefined` when there are no envs to record (so\n * the lockfile writer can skip emitting the section entirely\n * instead of writing an empty `{ environments: {} }`).\n */\nexport function materializeInfraSection(\n options: MaterializeInfraSectionOptions,\n): SaasLockfileInfraSection | undefined {\n if (options.envs.length === 0) return undefined;\n\n const environments: SaasLockfileInfraSection['environments'] = {};\n let recordedAny = false;\n\n for (const env of options.envs) {\n const capabilities = projectBackingServicesToCapabilities(\n env.backingServices,\n options.generatedAt,\n env.envName,\n options.moduleMap,\n options.previousSection?.environments[env.envName],\n );\n if (Object.keys(capabilities).length === 0) continue;\n environments[env.envName] = { capabilities };\n recordedAny = true;\n }\n\n return recordedAny ? { environments } : undefined;\n}\n\nfunction projectBackingServicesToCapabilities(\n backingServices: BackingServicesEnvConfig | undefined,\n generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n previousEnv: SaasLockfileInfraEnvironment | undefined,\n): SaasLockfileInfraEnvironment['capabilities'] {\n const capabilities: SaasLockfileInfraEnvironment['capabilities'] = {};\n if (!backingServices) return capabilities;\n\n // Iterate via `Object.values(BackingServiceKind)` (Slice 4.A.2 / M7)\n // — avoids an unsafe `kindKey as BackingServiceKind` cast on\n // `Object.entries`'s string keys. `BackingServicesEnvConfigSchema`\n // is `.strict()` so unknown keys can't reach this code path; this\n // tightening just removes the dead defensive guard that came with\n // the cast.\n for (const kind of Object.values(BackingServiceKind)) {\n const entry = backingServices[kind];\n if (!entry) continue;\n const capability = BackingServiceKindToInfraCapability[kind];\n\n // Some kinds carry an additional `provider` brand (e.g. S3 = minio | aws);\n // others don't. The cast lifts to a permissive shape since\n // `BackingServiceEnvConfig` is a discriminated union and the brand only\n // exists on some variants.\n const providerBrand = (entry as BackingServiceEnvConfig & { provider?: string }).provider;\n const provider = resolveInfraProvider(kind, entry.source, providerBrand);\n if (!provider) {\n // Two kinds (METRICS / BACKUP) have no concrete\n // `InfraProvider` catalog entry yet (Slice 1.b). Skip them in\n // the lockfile until the first concrete provider for each is\n // authored — recording an entry without a provider would lie.\n continue;\n }\n\n // Slice 2.5c-1: prefer module.plan() digest when the catalog\n // exposes a module for this provider. Falls back to the\n // authored-entry digest for uncovered providers (Slice 5\n // stateless modules pending) so partial coverage doesn't\n // break materialization.\n const planContributionDigest =\n computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)\n ?? computeAuthoredEntryDigest(entry);\n\n // `providerSelectedAt` is STICKY — only a provider's first\n // selection (or re-selection after a change) is a meaningful moment.\n // Reuse the prior timestamp when the resolved provider is unchanged\n // so an unrelated `generatedAt` bump never perturbs it (the root\n // cause of phantom `wildo lock check` infra drift). A newly-added\n // capability or a provider change stamps the fresh `generatedAt`.\n const previousEntry = previousEnv?.capabilities[capability];\n const providerSelectedAt =\n previousEntry && previousEntry.provider === provider\n ? previousEntry.providerSelectedAt\n : generatedAt;\n\n capabilities[capability] = {\n provider,\n providerSelectedAt,\n planContributionDigest,\n };\n }\n return capabilities;\n}\n\n/**\n * Stable digest of an authored `BackingServiceEnvConfig` entry.\n * Uses `stableJsonStringify` (recursive sorted-keys serialization)\n * via `stableSha256Digest` so the digest is insensitive to property-\n * order shuffles at ANY nesting level — not just top-level. This\n * matters for entries with nested objects like\n * `MongoBackingService.options: {retryWrites, w, authSource}` where\n * editor saves frequently reorder the nested keys.\n *\n * Slice 4.A.1 / H2 fix: previously this used `JSON.stringify(entry,\n * Object.keys(entry).sort())` which only sorted top-level keys.\n */\nfunction computeAuthoredEntryDigest(entry: BackingServiceEnvConfig): string {\n return stableSha256Digest(entry);\n}\n\n/**\n * Slice 2.5c-1: compute the digest by invoking the module's\n * `plan()` and hashing its contribution. Returns `undefined` when\n * the module map is missing OR doesn't cover the provider — caller\n * falls back to `computeAuthoredEntryDigest`.\n *\n * **Why include the authored entry IN the planning context**: the\n * module may use authored fields (e.g., a future opt-in flag in\n * `RabbitBackingService`) to vary its contribution. Threading the\n * entry through `config` keeps the digest sensitive to authored\n * drift even when the digest source is `module.plan()`.\n *\n * **Why ignore `generatedAt` in the digest**: the timestamp is the\n * `providerSelectedAt` field, NOT part of plan-contribution\n * identity. Using it would make every `wildo lock` run produce a\n * different digest — defeats drift detection. We don't pass it to\n * `module.plan()`; we pass it through the surrounding shape only.\n */\nfunction computeModulePlanDigest(\n provider: InfraProvider,\n kind: BackingServiceKind,\n entry: BackingServiceEnvConfig,\n _generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n): string | undefined {\n if (!moduleMap) return undefined;\n const module = moduleMap.get(provider);\n if (!module) return undefined;\n const planningContext: InfraProviderPlanningContext = {\n environment: envName,\n runtime: 'unknown', // Caller doesn't expose runtime per env at this layer.\n backingServiceKey: kind,\n config: entry,\n };\n const contribution = module.plan(planningContext);\n return stableSha256Digest(contribution);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"materialize-infra-section.js","sourceRoot":"","sources":["../../../../src/lockfile/materialize-infra-section.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EACL,kBAAkB,EAClB,mCAAmC,EACnC,oBAAoB,GAGrB,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,wCAAwC,EAAE,MAAM,sDAAsD,CAAC;AAUhH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAwEtD;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CACrC,OAAuC;IAEvC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IAEhD,gGAAgG;IAChG,wCAAwC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,iBAAiB,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAE/G,MAAM,YAAY,GAA6C,EAAE,CAAC;IAClE,IAAI,WAAW,GAAG,KAAK,CAAC;IAExB,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,oCAAoC,CACvD,GAAG,CAAC,eAAe,EACnB,OAAO,CAAC,WAAW,EACnB,GAAG,CAAC,OAAO,EACX,OAAO,CAAC,SAAS,EACjB,OAAO,CAAC,eAAe,EAAE,YAAY,CAAC,GAAG,CAAC,OAAO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B,CAAC,YAAY,CAAC,CAAC;AAC1C,CAAC","sourcesContent":["/**\n * `materializeInfraSection` — pure function that projects authored\n * `wildo.infra.<envName>.config.ts` files into the\n * `sections.infra` slice of `wildo-saas.lock.json` (Slice 2.5b of\n * `infra-provider-planner.md`).\n *\n * Lives in `platform-config-lib` (no runtime, no DI, no I/O — pure\n * projection). The CLI-side caller is responsible for loading the\n * authored configs from disk via\n * `loadInfraEnvConfig` (this package; the CLI's `loadAuthoredInfraEnvConfig` delegates to it) and passing\n * the parsed `backingServices` slice plus the env name.\n *\n * **Slice 2.5c-1 (2026-05-10)**: when the caller supplies an optional\n * `moduleMap` of `InfraProvider → InfraProviderModule`, the digest\n * is computed from `module.plan(planningContext)` instead of from\n * the authored entry. This captures **provider-version drift**\n * (e.g., a module change to plumbing port, secret env vars,\n * per-app blob paths) on top of authored-config drift. When the\n * map is omitted, behavior matches Slice 2.5b — backward-compatible.\n * When the map IS supplied but doesn't contain a module for the\n * resolved `InfraProvider`, the materializer falls back to the\n * authored-entry digest for that capability. After #1693 that can only\n * happen for a provider the catalogue declares servable WITHOUT a module\n * (`OPERATOR_CREDENTIALED_INFRA_PROVIDERS`, empty since #1696 gave\n * `IMMUDB_SELF` its module): every other module-less provider is refused\n * before any digest is computed.\n *\n * **#1693 (2026-09-26)**: the materializer REFUSES any declaration the\n * platform cannot serve — one that resolves to no `InfraProvider`, or to\n * one outside the `servableProviders` set the caller must supply. It used\n * to skip the first silently and hash the second, so the lockfile either\n * omitted a declared kind or recorded a selection nothing executes. Both\n * of its callers (`wildo config sync`, `wildo lock check`) reach the one\n * check here, so the two projections cannot disagree about what is\n * refused. See `backing-service-servability.ts`.\n *\n * **Slice 4.A.1 / H2 fix (2026-05-07)**: digest computation uses\n * `stableSha256Digest` (recursive sorted-keys serialization via\n * `canonical-json.ts`) so nested-object property reorders don't\n * spuriously trigger drift.\n */\n\nimport {\n BackingServiceKind,\n BackingServiceKindToInfraCapability,\n resolveInfraProvider,\n type BackingServiceEnvConfig,\n type BackingServicesEnvConfig,\n} from '../project-config/shared/backing-services.schemas';\nimport { assertBackingServiceDeclarationsServable } from '../project-config/shared/backing-service-servability';\nimport type {\n InfraProvider,\n InfraProviderModule,\n InfraProviderPlanningContext,\n} from '../project-config/shared/infra-providers.schemas';\nimport type {\n SaasLockfileInfraEnvironment,\n SaasLockfileInfraSection,\n} from './wildo-saas-lock.shared.schemas';\nimport { stableSha256Digest } from './canonical-json';\n\n/**\n * Per-env input for the materializer. The caller has already loaded\n * the authored `wildo.infra.<envName>.config.ts` and parsed it via\n * `defineInfraEnvConfig`; we only consume the `backingServices`\n * slice (the only authored surface that maps to `InfraCapability`\n * selections).\n */\nexport interface InfraEnvSelectionInput {\n envName: string;\n backingServices: BackingServicesEnvConfig | undefined;\n}\n\nexport interface MaterializeInfraSectionOptions {\n envs: ReadonlyArray<InfraEnvSelectionInput>;\n /**\n * ISO-8601 timestamp used as the selection time for NEWLY-selected\n * or CHANGED capabilities (see `previousSection` for the sticky-reuse\n * rule). Caller controls it so multi-env writes share one\n * deterministic timestamp (matches the pattern from\n * `materializeSaasProviderRuntimeArtifacts`).\n */\n generatedAt: string;\n /**\n * Optional `InfraProvider → InfraProviderModule` lookup. When\n * present, each capability's `planContributionDigest` is computed\n * from `module.plan(planningContext)` (richer — captures\n * provider-version drift) instead of from the authored entry\n * (Slice 2.5b). Slice 2.5c-1 of `infra-provider-planner.md`.\n *\n * The CLI-side caller in `provider-runtime-sync.service.ts`\n * builds this from `@wildo-ai/platform-infra-providers`'s\n * `buildInfraProviderModuleMap()`. Apps-manager-side callers\n * (none today) would do the same.\n *\n * **Module-less providers**: a resolved provider with no entry here\n * falls back to the authored-entry digest. Only a provider in\n * `servableProviders` can reach that point, so the fallback covers\n * exactly the catalogue's explicit module-less exemptions.\n */\n moduleMap?: ReadonlyMap<InfraProvider, InfraProviderModule>;\n /**\n * The providers the platform can actually SERVE — from\n * `collectServableInfraProviders()` in `@wildo-ai/platform-infra-providers`.\n * REQUIRED, not optional: a caller that could omit it would be a\n * projection that skips the refusal, and the whole point is that\n * `wildo config sync` and `wildo lock check` refuse the same\n * declarations (#1693).\n */\n servableProviders: ReadonlySet<InfraProvider>;\n /**\n * The previous lockfile's `sections.infra` (when present). Threaded\n * so `providerSelectedAt` is STICKY: a capability whose resolved\n * `provider` is unchanged retains its prior `providerSelectedAt`\n * instead of being re-stamped with `generatedAt`. Only a newly-\n * selected capability or a provider CHANGE stamps a fresh\n * `generatedAt`.\n *\n * **Why this exists**: `generatedAt` is the lockfile's volatile\n * generation timestamp — it is bumped by EVERY lockfile write,\n * including writes by unrelated subsystems via `withLockfileMutate`.\n * Deriving `providerSelectedAt` directly from it made the field\n * drift on every unrelated write, producing phantom\n * `wildo lock check` failures even when no infra selection changed.\n * Both callers — the `wildo config sync` writer and the\n * `wildo lock check` drift-checker — MUST pass the same previous\n * section so their projections agree.\n */\n previousSection?: SaasLockfileInfraSection;\n}\n\n/**\n * Project authored infra envs into the lockfile `sections.infra`\n * shape. Returns `undefined` when there are no envs to record (so\n * the lockfile writer can skip emitting the section entirely\n * instead of writing an empty `{ environments: {} }`).\n */\nexport function materializeInfraSection(\n options: MaterializeInfraSectionOptions,\n): SaasLockfileInfraSection | undefined {\n if (options.envs.length === 0) return undefined;\n\n // Refuse every unservable declaration, across every environment, before projecting any of them.\n assertBackingServiceDeclarationsServable({ envs: options.envs, servableProviders: options.servableProviders });\n\n const environments: SaasLockfileInfraSection['environments'] = {};\n let recordedAny = false;\n\n for (const env of options.envs) {\n const capabilities = projectBackingServicesToCapabilities(\n env.backingServices,\n options.generatedAt,\n env.envName,\n options.moduleMap,\n options.previousSection?.environments[env.envName],\n );\n if (Object.keys(capabilities).length === 0) continue;\n environments[env.envName] = { capabilities };\n recordedAny = true;\n }\n\n return recordedAny ? { environments } : undefined;\n}\n\nfunction projectBackingServicesToCapabilities(\n backingServices: BackingServicesEnvConfig | undefined,\n generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n previousEnv: SaasLockfileInfraEnvironment | undefined,\n): SaasLockfileInfraEnvironment['capabilities'] {\n const capabilities: SaasLockfileInfraEnvironment['capabilities'] = {};\n if (!backingServices) return capabilities;\n\n // Iterate via `Object.values(BackingServiceKind)` (Slice 4.A.2 / M7)\n // — avoids an unsafe `kindKey as BackingServiceKind` cast on\n // `Object.entries`'s string keys. `BackingServicesEnvConfigSchema`\n // is `.strict()` so unknown keys can't reach this code path; this\n // tightening just removes the dead defensive guard that came with\n // the cast.\n for (const kind of Object.values(BackingServiceKind)) {\n const entry = backingServices[kind];\n if (!entry) continue;\n const capability = BackingServiceKindToInfraCapability[kind];\n\n // Some kinds carry an additional `provider` brand (e.g. S3 = minio | aws);\n // others don't. The cast lifts to a permissive shape since\n // `BackingServiceEnvConfig` is a discriminated union and the brand only\n // exists on some variants.\n const providerBrand = (entry as BackingServiceEnvConfig & { provider?: string }).provider;\n const provider = resolveInfraProvider(kind, entry.source, providerBrand);\n if (!provider) {\n // Unreachable: `assertBackingServiceDeclarationsServable` has already refused every declaration\n // that resolves to no provider. Kept as a throw rather than a `continue`, because a silent skip\n // here is precisely the defect that assertion closed (#1693).\n throw new Error(`backingServices.${kind} in environment '${envName}' resolved to no provider after the servability check.`);\n }\n\n // Slice 2.5c-1: prefer module.plan() digest when the catalog\n // exposes a module for this provider. Falls back to the\n // authored-entry digest only for a servable provider the catalogue\n // serves without a module (the operator-credentialed exemptions).\n const planContributionDigest =\n computeModulePlanDigest(provider, kind, entry, generatedAt, envName, moduleMap)\n ?? computeAuthoredEntryDigest(entry);\n\n // `providerSelectedAt` is STICKY — only a provider's first\n // selection (or re-selection after a change) is a meaningful moment.\n // Reuse the prior timestamp when the resolved provider is unchanged\n // so an unrelated `generatedAt` bump never perturbs it (the root\n // cause of phantom `wildo lock check` infra drift). A newly-added\n // capability or a provider change stamps the fresh `generatedAt`.\n const previousEntry = previousEnv?.capabilities[capability];\n const providerSelectedAt =\n previousEntry && previousEntry.provider === provider\n ? previousEntry.providerSelectedAt\n : generatedAt;\n\n capabilities[capability] = {\n provider,\n providerSelectedAt,\n planContributionDigest,\n };\n }\n return capabilities;\n}\n\n/**\n * Stable digest of an authored `BackingServiceEnvConfig` entry.\n * Uses `stableJsonStringify` (recursive sorted-keys serialization)\n * via `stableSha256Digest` so the digest is insensitive to property-\n * order shuffles at ANY nesting level — not just top-level. This\n * matters for entries with nested objects like\n * `MongoBackingService.options: {retryWrites, w, authSource}` where\n * editor saves frequently reorder the nested keys.\n *\n * Slice 4.A.1 / H2 fix: previously this used `JSON.stringify(entry,\n * Object.keys(entry).sort())` which only sorted top-level keys.\n */\nfunction computeAuthoredEntryDigest(entry: BackingServiceEnvConfig): string {\n return stableSha256Digest(entry);\n}\n\n/**\n * Slice 2.5c-1: compute the digest by invoking the module's\n * `plan()` and hashing its contribution. Returns `undefined` when\n * the module map is missing OR doesn't cover the provider — caller\n * falls back to `computeAuthoredEntryDigest`.\n *\n * **Why include the authored entry IN the planning context**: the\n * module may use authored fields (e.g., a future opt-in flag in\n * `RabbitBackingService`) to vary its contribution. Threading the\n * entry through `config` keeps the digest sensitive to authored\n * drift even when the digest source is `module.plan()`.\n *\n * **Why ignore `generatedAt` in the digest**: the timestamp is the\n * `providerSelectedAt` field, NOT part of plan-contribution\n * identity. Using it would make every `wildo lock` run produce a\n * different digest — defeats drift detection. We don't pass it to\n * `module.plan()`; we pass it through the surrounding shape only.\n */\nfunction computeModulePlanDigest(\n provider: InfraProvider,\n kind: BackingServiceKind,\n entry: BackingServiceEnvConfig,\n _generatedAt: string,\n envName: string,\n moduleMap: ReadonlyMap<InfraProvider, InfraProviderModule> | undefined,\n): string | undefined {\n if (!moduleMap) return undefined;\n const module = moduleMap.get(provider);\n if (!module) return undefined;\n const planningContext: InfraProviderPlanningContext = {\n environment: envName,\n runtime: 'unknown', // Caller doesn't expose runtime per env at this layer.\n backingServiceKey: kind,\n config: entry,\n };\n const contribution = module.plan(planningContext);\n return stableSha256Digest(contribution);\n}\n"]}
|