From fbc0e24c0db0ad811b3b4ca39422ee2c0bbe4007 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 15:06:13 +1100 Subject: [PATCH 1/5] fix(prisma-cloud): an unchanged deploy no longer makes a new version of a service that reads another service's URL A service's url output came from its deployment, which promotes itself on every deploy, so the url was unknown while planning. A consumer writes that url into an environment row and its deployment's triggers, and an unknown trigger replaces the deployment. Every deploy made a new version of every such consumer, even with nothing changed. The url output is now the App's endpoint domain, which is known from the App's create and does not change, the same value a service's own origin already uses. serviceId still waits for the promotion, because a custom domain reads it and is bound to the live deployment. Signed-off-by: willbot Signed-off-by: Will Madden --- .../__tests__/compute-redeploy-apply.test.ts | 285 ++++++++++++++++++ .../src/__tests__/control-lowering.test.ts | 50 ++- .../target/src/descriptors/compute.ts | 32 +- 3 files changed, 341 insertions(+), 26 deletions(-) create mode 100644 packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts new file mode 100644 index 000000000..7a65d9d27 --- /dev/null +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts @@ -0,0 +1,285 @@ +/** Two compute services, one reading the other's URL, deployed twice under the real Alchemy apply engine and the real `Prisma.App`, `Prisma.Deployment` and `Prisma.EnvironmentVariable` providers, against a fake Management API. */ +import { expect, test } from 'bun:test'; +import * as Prisma from '@alchemy.run/prisma'; +import { Credentials, Retry } from '@distilled.cloud/prisma'; +import { dependency, string } from '@internal/core'; +import type { LowerContext } from '@internal/core/deploy'; +import { runScratch, scratchStack } from '@internal/lowering/scratch-stack'; +import * as Provider from 'alchemy/Provider'; +import * as Effect from 'effect/Effect'; +import * as HttpClient from 'effect/http/HttpClient'; +import * as HttpClientResponse from 'effect/http/HttpClientResponse'; +import * as Layer from 'effect/Layer'; +import * as Redacted from 'effect/Redacted'; +import { compute } from '../compute.ts'; +import { computeDescriptor } from '../descriptors/compute.ts'; + +const PROJECT_ID = 'proj_1'; +const BRANCH_ID = 'br_default'; +const CREATED_AT = '2026-11-20T00:00:00.000Z'; + +interface FakePlatform { + readonly services: Map>; + readonly deployments: Map>; + /** The App id of every deployment ever created, in order; a deleted deployment stays listed. */ + readonly created: unknown[]; + readonly variables: Map>; +} + +function record(body: unknown): Record { + return typeof body === 'object' && body !== null ? { ...body } : {}; +} + +function respond(platform: FakePlatform, method: string, url: URL, body: unknown): Response { + const data = (value: unknown) => Response.json({ data: value }); + const page = (values: unknown[]) => + Response.json({ data: values, pagination: { hasMore: false, nextCursor: null } }); + const path = url.pathname; + const sent = record(body); + + if (url.hostname === 'upload.prisma.test' && method === 'PUT') return new Response(null); + + if (method === 'GET' && path === `/v1/projects/${PROJECT_ID}/branches`) { + return page([ + { + id: BRANCH_ID, + type: 'branch', + url: `https://api.prisma.test/v1/branches/${BRANCH_ID}`, + gitName: 'main', + isDefault: true, + role: 'production', + createdAt: CREATED_AT, + updatedAt: CREATED_AT, + project: { + id: PROJECT_ID, + url: `https://api.prisma.test/v1/projects/${PROJECT_ID}`, + name: 'shop', + }, + }, + ]); + } + if (method === 'GET' && path === '/v1/services') { + const logicalId = url.searchParams.get('logicalId'); + return page( + [...platform.services.values()].filter( + (service) => logicalId === null || service['logicalId'] === logicalId, + ), + ); + } + if (method === 'POST' && path === '/v1/services') { + const id = `svc_${platform.services.size + 1}`; + const service = { + id, + type: 'app', + url: `https://api.prisma.test/v1/services/${id}`, + name: sent['displayName'], + region: { id: 'eu-west-3', name: 'Paris' }, + projectId: sent['projectId'], + branchId: sent['branchId'] ?? BRANCH_ID, + latestDeploymentId: null, + appEndpointDomain: `https://${id}.cdg.prisma.build`, + createdAt: CREATED_AT, + logicalId: sent['logicalId'] ?? null, + }; + platform.services.set(id, service); + return data(service); + } + const serviceMatch = path.match(/^\/v1\/services\/([^/]+)(\/[a-z]+)?$/); + const service = serviceMatch === null ? undefined : platform.services.get(serviceMatch[1] ?? ''); + if (serviceMatch !== null && service !== undefined) { + const action = serviceMatch[2]; + if (method === 'GET' && action === undefined) return data(service); + if (method === 'PATCH' && action === undefined) { + Object.assign(service, sent); + return data(service); + } + if (method === 'GET' && action === '/deployments') { + return page( + [...platform.deployments.values()].filter((d) => d['serviceId'] === service['id']), + ); + } + if (method === 'POST' && action === '/deployments') { + platform.created.push(service['id']); + const id = `dep_${platform.created.length}`; + const deployment = { + id, + type: 'deployment', + url: `https://api.prisma.test/v1/deployments/${id}`, + serviceId: service['id'], + foundryVersionId: `ver_${platform.created.length}`, + status: 'new', + previewDomain: null, + createdAt: CREATED_AT, + }; + platform.deployments.set(id, deployment); + return data({ ...deployment, uploadUrl: `https://upload.prisma.test/${id}` }); + } + if (method === 'POST' && action === '/promote') { + service['latestDeploymentId'] = sent['deploymentId']; + return data({ appEndpointDomain: service['appEndpointDomain'], reassignedDomains: 0 }); + } + } + const deploymentMatch = path.match(/^\/v1\/deployments\/([^/]+)(\/start|\/stop)?$/); + const deployment = + deploymentMatch === null ? undefined : platform.deployments.get(deploymentMatch[1] ?? ''); + if (deployment !== undefined) { + if (method === 'GET' && deploymentMatch?.[2] === undefined) return data(deployment); + if (method === 'POST' && deploymentMatch?.[2] === '/start') { + deployment['status'] = 'running'; + deployment['previewDomain'] = `https://${deployment['id']}.preview.prisma.build`; + return data({ previewDomain: deployment['previewDomain'] }); + } + if (method === 'POST' && deploymentMatch?.[2] === '/stop') { + deployment['status'] = 'stopped'; + return data(deployment); + } + if (method === 'DELETE') { + platform.deployments.delete(String(deployment['id'])); + return data(deployment); + } + } + + if (method === 'GET' && path === '/v1/environment-variables') { + const key = url.searchParams.get('key'); + return page([...platform.variables.values()].filter((v) => key === null || v['key'] === key)); + } + if (method === 'POST' && path === '/v1/environment-variables') { + const id = `var_${platform.variables.size + 1}`; + const variable = { + id, + type: 'environment-variable', + url: `https://api.prisma.test/v1/environment-variables/${id}`, + projectId: sent['projectId'], + branchId: null, + class: sent['class'], + key: sent['key'], + valueKid: 'kid_1', + isManagedBySystem: false, + createdAt: CREATED_AT, + updatedAt: CREATED_AT, + }; + platform.variables.set(id, variable); + return data(variable); + } + const variable = platform.variables.get( + path.match(/^\/v1\/environment-variables\/([^/]+)$/)?.[1] ?? '', + ); + if (variable !== undefined && method === 'GET') return data(variable); + if (variable !== undefined && method === 'PATCH') return data(variable); + + return Response.json( + { error: { code: 'unhandled', message: `${method} ${path}` } }, + { status: 400 }, + ); +} + +function fakePlatform() { + const platform: FakePlatform = { + services: new Map(), + deployments: new Map(), + created: [], + variables: new Map(), + }; + const http = HttpClient.make((request) => + Effect.sync(() => { + const url = new URL(request.url); + const sent = request.body; + const text = sent._tag === 'Uint8Array' ? new TextDecoder().decode(sent.body) : ''; + const response = respond(platform, request.method, url, text ? JSON.parse(text) : undefined); + return HttpClientResponse.fromWeb(request, response); + }), + ); + const providers = Layer.effect( + Prisma.Providers, + Provider.collection([Prisma.App, Prisma.Deployment, Prisma.EnvironmentVariable]), + ).pipe( + Layer.provideMerge( + Layer.mergeAll( + Prisma.AppProvider(), + Prisma.DeploymentProvider(), + Prisma.EnvironmentVariableProvider(), + ), + ), + Layer.provideMerge( + Layer.mergeAll( + Layer.succeed(HttpClient.HttpClient, http), + Layer.succeed( + Credentials, + Effect.succeed({ + apiToken: Redacted.make('fake-token'), + apiBaseUrl: 'https://api.prisma.test', + }), + ), + Layer.succeed(Retry.Retry, Retry.makeDefault), + ), + ), + ); + return { platform, options: { providers, dev: false } }; +} + +const build = { + extension: '@prisma/composer/node', + type: 'node', + module: 'file:///test/service.ts', + entry: 'server.js', +}; +const auth = compute({ name: 'auth', deps: {}, build }); +const web = compute({ + name: 'web', + deps: { + auth: dependency({ + type: 'rpc', + connection: { params: { url: string() }, hydrate: (v) => v }, + }), + }, + build, +}); + +const descriptor = computeDescriptor(() => ({ workspaceId: 'ws_1', providerParams: new Map() })); +const graph = { root: { id: 'shop' }, inputBindings: [], edges: [] }; +const application = { + projectId: PROJECT_ID, + branchId: undefined, + defaultBranchId: BRANCH_ID, + branchless: false, +}; +// The fake platform never unpacks an artifact, so any file serves as one. +const artifact = { path: import.meta.path, sha256: 'sha-artifact' }; + +/** The two services' lowering, as core's loop runs it: `web` reads `auth`'s `url` output. */ +function program() { + return Effect.gen(function* () { + const ctxOf = (address: string, node: unknown) => + ({ address, node, graph, application }) as unknown as LowerContext; + const authCtx = ctxOf('shop.auth', auth); + const webCtx = ctxOf('shop.web', web); + const authProvisioned = yield* descriptor.provision(authCtx); + const webProvisioned = yield* descriptor.provision(webCtx); + const authSerialized = yield* descriptor.serialize(authCtx, authProvisioned, { + service: { port: 3000 }, + inputs: {}, + }); + const deployed = yield* descriptor.deploy(authCtx, authProvisioned, artifact, authSerialized); + const webSerialized = yield* descriptor.serialize(webCtx, webProvisioned, { + service: { port: 3000 }, + inputs: { auth: { url: deployed.outputs['url'] } }, + }); + yield* descriptor.deploy(webCtx, webProvisioned, artifact, webSerialized); + }) as Effect.Effect; +} + +test("an unchanged deploy keeps the deployment of a service that reads another service's url", async () => { + const { platform, options } = fakePlatform(); + const stack = scratchStack(options, 'compute-redeploy'); + const createdFor = (address: string) => { + const service = [...platform.services.values()].find((s) => s['logicalId'] === address); + return platform.created.filter((serviceId) => serviceId === service?.['id']); + }; + + await runScratch(stack.deploy(program())); + expect(createdFor('shop.auth')).toHaveLength(1); + expect(createdFor('shop.web')).toHaveLength(1); + + await runScratch(stack.deploy(program())); + expect(createdFor('shop.web')).toHaveLength(1); +}); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts index 1b0c7a1d3..b3eb67400 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts @@ -1715,7 +1715,11 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { graph: { root: { id: 'shop' } }, opts: {}, } as unknown as LowerContext; - const provisioned = { serviceId: 'auth-svc#cloud-id', projectId: 'shop-project#cloud-id' }; + const provisioned = { + serviceId: 'auth-svc#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://auth-svc.example', + }; const artifact = { path: '/tmp/auth.tar.gz', sha256: 'sha-auth' }; const serialized = { environment: [ @@ -1760,7 +1764,7 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { ], ]); expect(result.outputs).toEqual({ - url: 'https://shop.auth.deployment.example', + url: 'https://auth-svc.example', projectId: 'shop-project#cloud-id', serviceId: 'deployment-app-of:shop.auth.deployment', }); @@ -1770,7 +1774,7 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { { kind: 'compute-service', id: 'auth-svc#cloud-id', - url: 'https://shop.auth.deployment.example', + url: 'https://auth-svc.example', }, ]); }); @@ -1783,7 +1787,11 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { graph: { root: { id: 'shop' } }, opts: {}, } as unknown as LowerContext; - const provisioned = { serviceId: 'auth-svc#cloud-id', projectId: 'shop-project#cloud-id' }; + const provisioned = { + serviceId: 'auth-svc#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://auth-svc.example', + }; const artifact = { path: '/tmp/auth.tar.gz', sha256: 'sha-auth' }; const serialized = { environment: [], @@ -1805,7 +1813,7 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { { kind: 'compute-service', id: 'auth-svc#cloud-id', - url: 'https://shop.auth.deployment.example', + url: 'https://auth-svc.example', details: { input: '{"stripeKey":$platform STRIPE_SECRET_KEY}', absent: 'greeting → ENV_GREETING\nregion → ENV_REGION', @@ -1822,7 +1830,11 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { graph: { root: { id: 'shop' } }, opts: {}, } as unknown as LowerContext; - const provisioned = { serviceId: 'mailer-svc#cloud-id', projectId: 'shop-project#cloud-id' }; + const provisioned = { + serviceId: 'mailer-svc#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://mailer-svc.example', + }; const artifact = { path: '/tmp/mailer.tar.gz', sha256: 'sha-mailer' }; const serialized = { environment: [], @@ -1847,7 +1859,7 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { { kind: 'compute-service', id: 'mailer-svc#cloud-id', - url: 'https://shop.mailer.deployment.example', + url: 'https://mailer-svc.example', details: { input: '{"port":$platform SMTP_PORT (number),"from":$platform EMAIL_FROM}' }, }, ]); @@ -1861,7 +1873,11 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { graph: { root: { id: 'shop' } }, opts: {}, } as unknown as LowerContext; - const provisioned = { serviceId: 'auth-svc#cloud-id', projectId: 'shop-project#cloud-id' }; + const provisioned = { + serviceId: 'auth-svc#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://auth-svc.example', + }; const artifact = { path: '/tmp/auth.tar.gz', sha256: 'sha-auth' }; const serialized = { environment: [], @@ -1883,7 +1899,7 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { { kind: 'compute-service', id: 'auth-svc#cloud-id', - url: 'https://shop.auth.deployment.example', + url: 'https://auth-svc.example', details: { input: '{"stripeKey":$platform STRIPE_SECRET_KEY}', }, @@ -2008,7 +2024,11 @@ describe("prismaCloud().nodes['s3-store'] — the service descriptor with extend graph: { root: { id: 'shop' } }, opts: {}, } as unknown as LowerContext; - const provisioned = { serviceId: 'store-svc#cloud-id', projectId: 'shop-project#cloud-id' }; + const provisioned = { + serviceId: 'store-svc#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://store-svc.example', + }; const artifact = { path: '/tmp/store.tar.gz', sha256: 'sha-store' }; const serialized = { environment: [{ id: 'STORE_PORT-var#cloud-id', key: 'STORE_PORT' }], @@ -2026,7 +2046,7 @@ describe("prismaCloud().nodes['s3-store'] — the service descriptor with extend // The four S3Config fields a consumer's s3() slot resolves by name, plus url. expect(result.outputs).toEqual({ - url: 'https://shop.store.deployment.example', + url: 'https://store-svc.example', projectId: 'shop-project#cloud-id', serviceId: 'deployment-app-of:shop.store.deployment', bucket: 'streams', @@ -2041,7 +2061,7 @@ describe("prismaCloud().nodes['s3-store'] — the service descriptor with extend { kind: 'compute-service', id: 'store-svc#cloud-id', - url: 'https://shop.store.deployment.example', + url: 'https://store-svc.example', }, ]); }); @@ -3102,7 +3122,11 @@ describe('resource IDs are built from the full address, and each declares the ID run( serviceDescriptorOf(target, 'compute').deploy( ctx as unknown as LowerContext, - { serviceId: 'shop.auth.api#cloud-id', projectId: 'shop-project#cloud-id' }, + { + serviceId: 'shop.auth.api#cloud-id', + projectId: 'shop-project#cloud-id', + endpointDomain: 'https://shop.auth.api.example', + }, { path: '/tmp/api.tar.gz', sha256: 'sha-api' }, { environment: [], triggers: {}, platformVariables: [], port: 3000 }, ), diff --git a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts index 4c086e563..7b43294a6 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts @@ -121,6 +121,15 @@ function originOf( }); } +function urlOf(provisioned: ComputeProvisioned): Output.Output { + return Output.map(provisioned.endpointDomain, (domain) => { + if (domain === undefined) { + throw new Error('the App reported no endpoint domain for the service.'); + } + return domain; + }); +} + function isComputeProvisioned(value: unknown): value is ComputeProvisioned { return typeof value === 'object' && value !== null && 'endpointDomain' in value; } @@ -396,12 +405,16 @@ export function computeDescriptor( }).pipe(fromLegacyId(legacyNodeResourceId(app, address, 'deploy'))); // `url` IS published here: a Compute service's deployed URL is a // public endpoint, and this descriptor is the only party that knows - // that. Both fields are still unresolved Output references at this - // point — apply resolves them before the report's runner sees them. - // + // that. It is the App's endpoint domain, known from the App's create, + // not the deployment's: the deployment promotes itself on every deploy, + // so its domain is unresolved while planning, and a consumer whose + // environment holds this URL would get a new deployment every time. + // `serviceId` does wait for the promotion, because the custom domain + // that reads it is bound to the live deployment. + const url = urlOf(provisioned); return { outputs: { - url: deployment.appEndpointDomain, + url, projectId: provisioned.projectId, serviceId: deployment.appId, }, @@ -409,7 +422,7 @@ export function computeDescriptor( { kind: 'compute-service', id: provisioned.serviceId, - url: deployment.appEndpointDomain, + url, ...inputDetails(serialized), }, ], @@ -433,14 +446,7 @@ export function computeDescriptor( ...variableClassAndBranch(application), }).pipe(asOwnRow, fromLegacyId(legacyEnvVarId(legacyInputKey(graph.root.id, address)))); } - const url = Output.map(provisioned.endpointDomain, (domain) => { - if (domain === undefined) { - throw new Error( - 'the App reported no endpoint domain for a service without a deployment.', - ); - } - return domain; - }); + const url = urlOf(provisioned); return { outputs: { url, projectId: provisioned.projectId, serviceId: provisioned.serviceId }, entities: [ From c811f013c7639b69638839977596c33e0c09d7e5 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 15:23:12 +1100 Subject: [PATCH 2/5] fix(prisma-cloud): a missing endpoint domain names the service, and the docs say a service's url comes from its App One function reads an App's endpoint domain for a service's url, for serviceOrigin and for a service's own origin, and its error names the service. The design docs now draw a reading service's url row from the App, and no longer say the create-time domain is a placeholder. The tests also check that the reading service's row holds the url, that a new artifact for the service being read replaces only that service's deployment, and that reserve publishes the App's domain. The fake Management API used by the apply tests is now exported from @internal/lowering/scratch-stack. Signed-off-by: willbot Signed-off-by: Will Madden --- .../05-prisma-cloud/alchemy-lowering.md | 6 +- docs/design/05-prisma-cloud/pdp-data-model.md | 2 +- docs/design/10-domains/core-model.md | 15 +-- .../deployment-environment-lifecycle.test.ts | 2 +- .../lowering/src/exports/scratch-stack.ts | 1 + .../{__tests__ => }/fake-management-api.ts | 0 .../state/__tests__/legacy-resources.test.ts | 2 +- .../__tests__/compute-redeploy-apply.test.ts | 96 ++++++++++--------- .../src/__tests__/control-lowering.test.ts | 10 ++ .../target/src/control/extension.ts | 12 +-- .../target/src/descriptors/compute.ts | 42 +++----- 11 files changed, 91 insertions(+), 97 deletions(-) rename packages/1-prisma-cloud/0-lowering/lowering/src/{__tests__ => }/fake-management-api.ts (100%) diff --git a/docs/design/05-prisma-cloud/alchemy-lowering.md b/docs/design/05-prisma-cloud/alchemy-lowering.md index e0f523502..53c7e486e 100644 --- a/docs/design/05-prisma-cloud/alchemy-lowering.md +++ b/docs/design/05-prisma-cloud/alchemy-lowering.md @@ -227,7 +227,7 @@ flowchart TB Ss[App shop.storefront] --> Ds[Deployment shop.storefront.deployment] EVa -- resource ref --> Da EVs -- resource ref --> Ds - Da -- appEndpointDomain --> EVu["EnvironmentVariable(COMPOSER_SHOP_STOREFRONT_AUTH_URL)"] + Sa -- appEndpointDomain --> EVu["EnvironmentVariable(COMPOSER_SHOP_STOREFRONT_AUTH_URL)"] EVu -- resource ref --> Ds end ``` @@ -239,9 +239,7 @@ How the pieces map: - **Each service** lowers to an `App → Deployment` chain plus its own `Database → Connection`, whose url is written as that service's **explicitly named** variable — the same `serialize` path as any other config value. -- **The connection** lowers to two edges: the producer's endpoint domain flows - into a named `EnvironmentVariable`, and that **whole resource flows into the - consumer's `Deployment`** through its `app` prop. +- **The connection** lowers to two edges: the producer's App's endpoint domain flows into a named `EnvironmentVariable`, and that **whole resource flows into the consumer's `Deployment`** through its `app` prop. The domain comes from the App, not the Deployment: the Deployment is promoted on every deploy, so its domain is unknown while planning, and a reading service's deployment, whose triggers hold the value, would be replaced on every deploy. Because the App's domain is known, an unchanged reading service keeps its deployment when the service it reads is redeployed. - Every `EnvironmentVariable` a Deployment boots with is threaded into its `app` — database URLs and connection URLs alike — so the deployment depends on its config being written first. diff --git a/docs/design/05-prisma-cloud/pdp-data-model.md b/docs/design/05-prisma-cloud/pdp-data-model.md index 0dcbcc1aa..af1dd0341 100644 --- a/docs/design/05-prisma-cloud/pdp-data-model.md +++ b/docs/design/05-prisma-cloud/pdp-data-model.md @@ -85,7 +85,7 @@ This is the timing model Prisma Composer's graph must respect: | any time | ConfigVariable rows are created/updated/deleted via the environment-variables API — **rows only; no effect on any existing version** | `routes/v1/environment-variables.ts` | | **version create** | `materializeBranchEnvVars(app.branchId)` resolves the complete map — production branch → production templates; preview branch → preview templates merged with that branch's overrides (override wins) — decrypts it, and hands the **plain map to Foundry with the version**. The env is **frozen into the version** | `routes/v1/versions.ts` → `resolveDeployEnvVars.ts` → `compute-config/materializeBranchEnvVars.ts` | | version start | boots the version; **no env re-resolution** | `routes/v1/version-handlers.ts` | -| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* time is a placeholder region — only the post-promote read is trustworthy (PRO-200) | `interactors/compute/service.ts` | +| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* time used to be a placeholder region (PRO-200); since that fix it names the domain the service will serve on, so it can be read before the first promote | `interactors/compute/service.ts` | Consequences Prisma Composer designs around: diff --git a/docs/design/10-domains/core-model.md b/docs/design/10-domains/core-model.md index e101fe6da..b33ee69a4 100644 --- a/docs/design/10-domains/core-model.md +++ b/docs/design/10-domains/core-model.md @@ -670,7 +670,7 @@ type Outputs = Readonly> // `url` is present only when the descriptor declares the address publicly // reachable — a connection string is never a `url` (no core-level rule is safe: // `url` on compute is an endpoint, on postgres it would be a DSN). A descriptor -// constructing one holds `deployment.appEndpointDomain` — an Output, not a T, +// constructing one holds the App's `appEndpointDomain` — an Output, not a T, // because the stack effect runs before Alchemy applies — so construction sites // traffic in `Input` (LoweredResult.entities above); apply // resolves them before any reader sees them. @@ -1098,7 +1098,7 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor const svc = yield* Prisma.App(address, { project: projectIdOf(application), displayName: address, regionId: o.region ?? "us-east-1", logicalId: address, }) - return { serviceId: svc.appId, projectId: projectIdOf(application) } // : ComputeProvisioned + return { serviceId: svc.appId, projectId: projectIdOf(application), endpointDomain: svc.appEndpointDomain } // : ComputeProvisioned }), // Encode the typed Config into the runtime environment — one env var per @@ -1136,8 +1136,11 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor // serialize's env-var records, so the deployment depends on them — the // ordering edge that kills PRO-211. Returns a LoweredResult: `url` IS // published here — a Compute service's deployed URL is a public endpoint, - // and this descriptor is the only party that knows it. Both fields are - // still Output refs until apply. + // and this descriptor is the only party that knows it. It is the App's + // domain, not the deployment's: the deployment is promoted on every + // deploy, so its domain is unknown while planning, and every service + // reading the URL would get a new deployment. Both fields are still + // Output refs until apply. deploy: ({ address }, provisioned, artifact, serialized) => Effect.gen(function* () { const deployment = yield* Prisma.Deployment(`${address}.deployment`, { @@ -1147,8 +1150,8 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor portMapping: { http: serialized.port }, start: true, promote: true, }) return { - outputs: { url: deployment.appEndpointDomain, projectId: provisioned.projectId }, - entities: [{ kind: "compute-service", id: provisioned.serviceId, url: deployment.appEndpointDomain }], + outputs: { url: provisioned.endpointDomain, projectId: provisioned.projectId, serviceId: deployment.appId }, + entities: [{ kind: "compute-service", id: provisioned.serviceId, url: provisioned.endpointDomain }], } }), }, diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts index 8cb310ea9..da57c094e 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts @@ -8,7 +8,7 @@ import * as Exit from 'effect/Exit'; import * as Fiber from 'effect/Fiber'; import * as Layer from 'effect/Layer'; import * as Redacted from 'effect/Redacted'; -import { data, fakeManagementApi, page } from '../../__tests__/fake-management-api.ts'; +import { data, fakeManagementApi, page } from '../../fake-management-api.ts'; import { runScratch, scratchStack } from '../../scratch-stack.ts'; import { appAfterEnvironment } from '../deployment-edge.ts'; diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/exports/scratch-stack.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/exports/scratch-stack.ts index 69c23bb1d..3a327a985 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/exports/scratch-stack.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/exports/scratch-stack.ts @@ -1 +1,2 @@ +export { data, fakeManagementApi, page } from '../fake-management-api.ts'; export { runScratch, type ScratchStackOptions, scratchStack } from '../scratch-stack.ts'; diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/__tests__/fake-management-api.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/fake-management-api.ts similarity index 100% rename from packages/1-prisma-cloud/0-lowering/lowering/src/__tests__/fake-management-api.ts rename to packages/1-prisma-cloud/0-lowering/lowering/src/fake-management-api.ts diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/legacy-resources.test.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/legacy-resources.test.ts index 14d064529..b24bdd549 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/legacy-resources.test.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/state/__tests__/legacy-resources.test.ts @@ -32,7 +32,7 @@ import * as ConfigProvider from 'effect/ConfigProvider'; import * as Effect from 'effect/Effect'; import * as Layer from 'effect/Layer'; import * as Redacted from 'effect/Redacted'; -import { data, fakeManagementApi, page } from '../../__tests__/fake-management-api.ts'; +import { data, fakeManagementApi, page } from '../../fake-management-api.ts'; import { stateLayerAgainst } from '../layer.ts'; import { migrateLegacyResourceState } from '../legacy-resources.ts'; import { FakeStateApi } from './fake-state-api.ts'; diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts index 7a65d9d27..480c96e77 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts @@ -1,16 +1,19 @@ /** Two compute services, one reading the other's URL, deployed twice under the real Alchemy apply engine and the real `Prisma.App`, `Prisma.Deployment` and `Prisma.EnvironmentVariable` providers, against a fake Management API. */ import { expect, test } from 'bun:test'; +import * as path from 'node:path'; import * as Prisma from '@alchemy.run/prisma'; -import { Credentials, Retry } from '@distilled.cloud/prisma'; import { dependency, string } from '@internal/core'; import type { LowerContext } from '@internal/core/deploy'; -import { runScratch, scratchStack } from '@internal/lowering/scratch-stack'; +import { + data, + fakeManagementApi, + page, + runScratch, + scratchStack, +} from '@internal/lowering/scratch-stack'; import * as Provider from 'alchemy/Provider'; import * as Effect from 'effect/Effect'; -import * as HttpClient from 'effect/http/HttpClient'; -import * as HttpClientResponse from 'effect/http/HttpClientResponse'; import * as Layer from 'effect/Layer'; -import * as Redacted from 'effect/Redacted'; import { compute } from '../compute.ts'; import { computeDescriptor } from '../descriptors/compute.ts'; @@ -24,6 +27,7 @@ interface FakePlatform { /** The App id of every deployment ever created, in order; a deleted deployment stays listed. */ readonly created: unknown[]; readonly variables: Map>; + readonly values: Map; } function record(body: unknown): Record { @@ -31,13 +35,10 @@ function record(body: unknown): Record { } function respond(platform: FakePlatform, method: string, url: URL, body: unknown): Response { - const data = (value: unknown) => Response.json({ data: value }); - const page = (values: unknown[]) => - Response.json({ data: values, pagination: { hasMore: false, nextCursor: null } }); const path = url.pathname; const sent = record(body); - if (url.hostname === 'upload.prisma.test' && method === 'PUT') return new Response(null); + if (method === 'PUT' && path.startsWith('/upload/')) return new Response(null); if (method === 'GET' && path === `/v1/projects/${PROJECT_ID}/branches`) { return page([ @@ -89,10 +90,6 @@ function respond(platform: FakePlatform, method: string, url: URL, body: unknown if (serviceMatch !== null && service !== undefined) { const action = serviceMatch[2]; if (method === 'GET' && action === undefined) return data(service); - if (method === 'PATCH' && action === undefined) { - Object.assign(service, sent); - return data(service); - } if (method === 'GET' && action === '/deployments') { return page( [...platform.deployments.values()].filter((d) => d['serviceId'] === service['id']), @@ -112,7 +109,7 @@ function respond(platform: FakePlatform, method: string, url: URL, body: unknown createdAt: CREATED_AT, }; platform.deployments.set(id, deployment); - return data({ ...deployment, uploadUrl: `https://upload.prisma.test/${id}` }); + return data({ ...deployment, uploadUrl: `https://api.prisma.test/upload/${id}` }); } if (method === 'POST' && action === '/promote') { service['latestDeploymentId'] = sent['deploymentId']; @@ -159,13 +156,17 @@ function respond(platform: FakePlatform, method: string, url: URL, body: unknown updatedAt: CREATED_AT, }; platform.variables.set(id, variable); + platform.values.set(String(sent['key']), sent['value']); return data(variable); } const variable = platform.variables.get( path.match(/^\/v1\/environment-variables\/([^/]+)$/)?.[1] ?? '', ); if (variable !== undefined && method === 'GET') return data(variable); - if (variable !== undefined && method === 'PATCH') return data(variable); + if (variable !== undefined && method === 'PATCH') { + platform.values.set(String(variable['key']), sent['value']); + return data(variable); + } return Response.json( { error: { code: 'unhandled', message: `${method} ${path}` } }, @@ -179,15 +180,10 @@ function fakePlatform() { deployments: new Map(), created: [], variables: new Map(), + values: new Map(), }; - const http = HttpClient.make((request) => - Effect.sync(() => { - const url = new URL(request.url); - const sent = request.body; - const text = sent._tag === 'Uint8Array' ? new TextDecoder().decode(sent.body) : ''; - const response = respond(platform, request.method, url, text ? JSON.parse(text) : undefined); - return HttpClientResponse.fromWeb(request, response); - }), + const api = fakeManagementApi(({ method, path, body }) => + Effect.sync(() => respond(platform, method, new URL(path, 'https://api.prisma.test'), body)), ); const providers = Layer.effect( Prisma.Providers, @@ -200,21 +196,17 @@ function fakePlatform() { Prisma.EnvironmentVariableProvider(), ), ), - Layer.provideMerge( - Layer.mergeAll( - Layer.succeed(HttpClient.HttpClient, http), - Layer.succeed( - Credentials, - Effect.succeed({ - apiToken: Redacted.make('fake-token'), - apiBaseUrl: 'https://api.prisma.test', - }), - ), - Layer.succeed(Retry.Retry, Retry.makeDefault), - ), - ), + Layer.provideMerge(api), ); - return { platform, options: { providers, dev: false } }; + const createdFor = (address: string) => { + const service = [...platform.services.values()].find((s) => s['logicalId'] === address); + return platform.created.filter((serviceId) => serviceId === service?.['id']); + }; + return { + platform, + createdFor, + stack: scratchStack({ providers, dev: false }, 'compute-redeploy'), + }; } const build = { @@ -245,9 +237,9 @@ const application = { }; // The fake platform never unpacks an artifact, so any file serves as one. const artifact = { path: import.meta.path, sha256: 'sha-artifact' }; +const changedArtifact = { path: path.join(import.meta.dir, '..', 'compute.ts'), sha256: 'sha-2' }; -/** The two services' lowering, as core's loop runs it: `web` reads `auth`'s `url` output. */ -function program() { +function program(authArtifact = artifact) { return Effect.gen(function* () { const ctxOf = (address: string, node: unknown) => ({ address, node, graph, application }) as unknown as LowerContext; @@ -259,7 +251,12 @@ function program() { service: { port: 3000 }, inputs: {}, }); - const deployed = yield* descriptor.deploy(authCtx, authProvisioned, artifact, authSerialized); + const deployed = yield* descriptor.deploy( + authCtx, + authProvisioned, + authArtifact, + authSerialized, + ); const webSerialized = yield* descriptor.serialize(webCtx, webProvisioned, { service: { port: 3000 }, inputs: { auth: { url: deployed.outputs['url'] } }, @@ -269,17 +266,24 @@ function program() { } test("an unchanged deploy keeps the deployment of a service that reads another service's url", async () => { - const { platform, options } = fakePlatform(); - const stack = scratchStack(options, 'compute-redeploy'); - const createdFor = (address: string) => { - const service = [...platform.services.values()].find((s) => s['logicalId'] === address); - return platform.created.filter((serviceId) => serviceId === service?.['id']); - }; + const { platform, createdFor, stack } = fakePlatform(); + + await runScratch(stack.deploy(program())); + expect(createdFor('shop.auth')).toHaveLength(1); + expect(createdFor('shop.web')).toHaveLength(1); + expect(platform.values.get('COMPOSER_SHOP_WEB_AUTH_URL')).toBe('https://svc_1.cdg.prisma.build'); await runScratch(stack.deploy(program())); expect(createdFor('shop.auth')).toHaveLength(1); expect(createdFor('shop.web')).toHaveLength(1); +}); + +test('a new artifact for the service that is read replaces its deployment and keeps the reading service', async () => { + const { createdFor, stack } = fakePlatform(); await runScratch(stack.deploy(program())); + await runScratch(stack.deploy(program(changedArtifact))); + + expect(createdFor('shop.auth')).toHaveLength(2); expect(createdFor('shop.web')).toHaveLength(1); }); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts index b3eb67400..9fefb1822 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts @@ -3968,6 +3968,16 @@ describe("a compute service's input document travels in its artifact", () => { ]); }); + test("reserve publishes the App's endpoint domain as the service's url", async () => { + const { reserve } = serviceDescriptorOf(prismaCloud({ workspaceId: 'ws_1' }), 'compute'); + if (reserve === undefined) throw new Error('compute declares reserve'); + + const result = run(reserve(contextFor('Shop'), provisioned, serialize('Shop'))); + + expect(result.outputs['url']).toBe('https://shop.web.example'); + expect(result.entities[0]).toHaveProperty('url', 'https://shop.web.example'); + }); + test('reserve writes the input document as a preview variable on the branch of an environment that has one, as serialize does for its variables', async () => { const { reserve } = serviceDescriptorOf(prismaCloud({ workspaceId: 'ws_1' }), 'compute'); if (reserve === undefined) throw new Error('compute declares reserve'); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts b/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts index 8f3d2dc64..e7e3e96c1 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts @@ -24,7 +24,7 @@ import { prismaCloudContainerOf, } from '../container.ts'; import { bucketDescriptor } from '../descriptors/bucket.ts'; -import { computeDescriptor } from '../descriptors/compute.ts'; +import { computeDescriptor, endpointDomainOf } from '../descriptors/compute.ts'; import { postgresDescriptor } from '../descriptors/orm-postgres.ts'; import { platformVariableDescriptor } from '../descriptors/platform-variable.ts'; import { publicUrlDescriptor } from '../descriptors/public-url.ts'; @@ -163,15 +163,7 @@ const streamsApiKeyValue: ProviderParam['value'] = (refs) => { * than write a row origin() would trust. The raw string is JSON-encoded by * the descriptor's generic loop, like every other reserved provider param. */ -const selfOriginValue: ServiceProviderParam['valueForService'] = (provisioned, address) => - Output.map(provisioned.endpointDomain, (v) => { - if (v === undefined) { - throw new Error( - `the App for "${address}" reported no endpoint domain at provision — cannot resolve the service's own origin (Management API predates the PRO-200 fix?)`, - ); - } - return v; - }); +const selfOriginValue: ServiceProviderParam['valueForService'] = endpointDomainOf; /** The user-facing state descriptor: `state: prismaState()` in the `composer` section of `prisma.config.ts` (ADR-0017). */ export const prismaState = (): StateDescriptor => ({ diff --git a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts index 7b43294a6..79a94e21e 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts @@ -32,6 +32,7 @@ import { logicalIdProp, projectIdOf, type ResolvedCloudOptions, + type ServiceProvisionedAttributes, validatePlatformName, variableClassAndBranch, } from './shared.ts'; @@ -53,10 +54,7 @@ function declaresNoListening(node: unknown): boolean { export interface ComputeProvisioned { readonly serviceId: Output.Output; readonly projectId: string; - /** The platform-assigned public origin domain — resolves to `undefined` only - * in the narrow provider-response gap the origin param's deploy-side value - * function enforces away (control.ts's `selfOriginValue`): every other - * reader may treat it as present. */ + /** The platform-assigned public origin domain. Read it through `endpointDomainOf`, which fails the deploy when the platform reported none. */ readonly endpointDomain: Output.Output; } @@ -111,20 +109,16 @@ function originOf( `address — known services: ${known}.`, ); } - return Output.map(provisioned.endpointDomain, (v) => { - if (v === undefined) { - throw new Error( - `the App for "${target}" reported no endpoint domain — cannot resolve serviceOrigin("${target}") for "${consumer}".`, - ); - } - return v; - }); + return endpointDomainOf(provisioned, target); } -function urlOf(provisioned: ComputeProvisioned): Output.Output { +export function endpointDomainOf( + provisioned: ServiceProvisionedAttributes, + address: string, +): Output.Output { return Output.map(provisioned.endpointDomain, (domain) => { if (domain === undefined) { - throw new Error('the App reported no endpoint domain for the service.'); + throw new Error(`the App for "${address}" reported no endpoint domain.`); } return domain; }); @@ -403,19 +397,13 @@ export function computeDescriptor( start: true, promote: true, }).pipe(fromLegacyId(legacyNodeResourceId(app, address, 'deploy'))); - // `url` IS published here: a Compute service's deployed URL is a - // public endpoint, and this descriptor is the only party that knows - // that. It is the App's endpoint domain, known from the App's create, - // not the deployment's: the deployment promotes itself on every deploy, - // so its domain is unresolved while planning, and a consumer whose - // environment holds this URL would get a new deployment every time. - // `serviceId` does wait for the promotion, because the custom domain - // that reads it is bound to the live deployment. - const url = urlOf(provisioned); + const url = endpointDomainOf(provisioned, address); return { outputs: { + // The App's domain: one that waits for the promotion is unknown while planning, which replaces every reader's deployment. url, projectId: provisioned.projectId, + // Waits for the promotion, because a custom domain is bound to the live version. serviceId: deployment.appId, }, entities: [ @@ -431,10 +419,8 @@ export function computeDescriptor( // ADR-0056: a service that runs its build adapter's dev server under // `prisma dev` has no artifact. What `deploy` returns, with the - // `Deployment` removed: the URL comes from the App, which locally is the - // same `http://localhost:` the Deployment would report, so - // dependents' rows do not change between a served and an assembled run. - // With no artifact to carry it, the input document is a variable. + // `Deployment` removed. With no artifact to carry it, the input document + // is a variable. reserve: ({ address, application, graph }, provisioned, serialized) => Effect.gen(function* () { const { input } = serialized; @@ -446,7 +432,7 @@ export function computeDescriptor( ...variableClassAndBranch(application), }).pipe(asOwnRow, fromLegacyId(legacyEnvVarId(legacyInputKey(graph.root.id, address)))); } - const url = urlOf(provisioned); + const url = endpointDomainOf(provisioned, address); return { outputs: { url, projectId: provisioned.projectId, serviceId: provisioned.serviceId }, entities: [ From 52a25d9e27efa2d155b2d68ec24bf67097634e5d Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 16:00:20 +1100 Subject: [PATCH 3/5] fix(prisma-cloud): a service's deployment is still created only after the services it reads are promoted Taking a service's url from its App removed the edge that made a reading service's deployment wait for its provider's promotion. A reading service's Deployment now also waits, through its app prop, on every output of the services and resources it reads. A Compute provider's serviceId resolves only after its promotion, so the order is kept on a first deploy and when both services change. The wait is on app, not in triggers, and an unresolved app counts as unchanged, so an unchanged reading service is still not replaced. appAfterEnvironment is renamed appAfter, since it now orders the deployment after its provider outputs as well as its environment rows. Signed-off-by: willbot Signed-off-by: Will Madden --- .../05-prisma-cloud/alchemy-lowering.md | 8 +-- docs/design/10-domains/core-model.md | 21 +++---- .../compute/__tests__/deployment-edge.test.ts | 32 ++++++++-- .../deployment-environment-lifecycle.test.ts | 4 +- .../lowering/src/compute/deployment-edge.ts | 42 +++++++------ .../__tests__/compute-redeploy-apply.test.ts | 61 +++++++++++++++++-- .../src/__tests__/control-lowering.test.ts | 25 +++++--- .../target/src/descriptors/compute.ts | 19 +++--- 8 files changed, 149 insertions(+), 63 deletions(-) diff --git a/docs/design/05-prisma-cloud/alchemy-lowering.md b/docs/design/05-prisma-cloud/alchemy-lowering.md index 53c7e486e..6559c6bdc 100644 --- a/docs/design/05-prisma-cloud/alchemy-lowering.md +++ b/docs/design/05-prisma-cloud/alchemy-lowering.md @@ -81,7 +81,7 @@ behind them. | `Prisma.Connection` | database connection info | database, name | connectionId, directConnectionString | Composer binds the DIRECT string explicitly; upstream's `databaseUrl` is pooled-first | | `Prisma.App` | App | project, displayName, regionId, branchId?, logicalId? | appId, appEndpointDomain | `branchId` targets the Branch of an environment other than `production`; omitted, upstream attaches the App to the project's default (production) Branch. `appEndpointDomain` is available at provision — that is what a service's own origin is read from | | `Prisma.EnvironmentVariable` | ConfigVariable | project, class, key, value (Redacted), branchId? | environmentVariableId | production-class with no `branchId` for `production`; preview-class with `branchId` for any other environment. Values are write-only, so upstream re-applies the desired one on every deploy | -| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote** (create-time domain is a placeholder — PRO-200). It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves | +| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote**; since the PRO-200 fix it is the same domain the App reports from its create. It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves | | `Prisma.Bucket` | Bucket | project, name, branchId?, logicalId? | bucketId, name | one per bucket resource; `Prisma.BucketAccessKey` mints its read-write S3 credentials, which become the node's outputs | `logicalId` is set on every deploy except branchless local dev; [§ Platform identity](#platform-identity-logicalid) says what it carries. @@ -229,6 +229,7 @@ flowchart TB EVs -- resource ref --> Ds Sa -- appEndpointDomain --> EVu["EnvironmentVariable(COMPOSER_SHOP_STOREFRONT_AUTH_URL)"] EVu -- resource ref --> Ds + Da -- "serviceId (after promote)" --> Ds end ``` @@ -240,9 +241,8 @@ How the pieces map: `Database → Connection`, whose url is written as that service's **explicitly named** variable — the same `serialize` path as any other config value. - **The connection** lowers to two edges: the producer's App's endpoint domain flows into a named `EnvironmentVariable`, and that **whole resource flows into the consumer's `Deployment`** through its `app` prop. The domain comes from the App, not the Deployment: the Deployment is promoted on every deploy, so its domain is unknown while planning, and a reading service's deployment, whose triggers hold the value, would be replaced on every deploy. Because the App's domain is known, an unchanged reading service keeps its deployment when the service it reads is redeployed. -- Every `EnvironmentVariable` a Deployment boots with is threaded into its - `app` — database URLs and connection URLs alike — so the deployment - depends on its config being written first. +- Every `EnvironmentVariable` a Deployment boots with is threaded into its `app` — database URLs and connection URLs alike — so the deployment depends on its config being written first. +- Every output of the services and resources a service reads is threaded into its Deployment's `app` too, so its deployment waits for the promotion of the services it reads: a Compute service's `serviceId` comes from its Deployment and resolves only after the promotion. The wait is on `app`, not in `triggers`, and upstream treats an unresolved `app` as unchanged, so an unchanged reading service is not replaced. - The Deployment's `portMapping.http` rides the same seam: `serialize` resolves the service's `port` param from the typed Config and surfaces it in its outputs, and `deploy` routes the platform to it — so the routed port and the diff --git a/docs/design/10-domains/core-model.md b/docs/design/10-domains/core-model.md index b33ee69a4..919ad3252 100644 --- a/docs/design/10-domains/core-model.md +++ b/docs/design/10-domains/core-model.md @@ -766,13 +766,7 @@ module-provisioned **resource** lowers exactly once via its extension's nodes are edges only and never lower. Then for each service: 1. `provision` — the service now has identity (its App). -2. core **builds the typed `Config`** — each input's declared params matched by - name to its producer's `outputs` through the one `dependency` edge: - whatever the module wired in — a resource's outputs (shared by every consumer - wired to it) or a producer service's deploy outputs (the producer, earlier in - topo order, is already fully deployed — its URL is real, not the create-time - placeholder) — plus service-param defaults. Leaf values are provisioning refs, - not strings. +2. core **builds the typed `Config`** — each input's declared params matched by name to its producer's `outputs` through the one `dependency` edge: whatever the module wired in — a resource's outputs (shared by every consumer wired to it) or a producer service's deploy outputs — plus service-param defaults. Leaf values are provisioning refs, not strings. A producer service's URL is its App's endpoint domain, known from the App's create. The producer is still deployed first: the consumer's deployment waits for the producer's outputs through its `app` prop, and a Compute producer's `serviceId` resolves only after its promotion. 3. `serialize(config)` — the pack encodes that typed Config into the service's runtime environment (Prisma Cloud: one env write per leaf, keyed by the pack's own naming from the address, value = the ref; the input document @@ -1133,18 +1127,23 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor Effect.try(() => Prisma.packageComputeArtifact({ id, bundleDir: assembled.dir, appEntry: assembled.entry, address, inputDocument: serialized.input && JSON.parse(serialized.input.value) })), // create → upload → start → promote. The app id is read through - // serialize's env-var records, so the deployment depends on them — the - // ordering edge that kills PRO-211. Returns a LoweredResult: `url` IS + // serialize's env-var records and every output of the services it reads, + // so the deployment is created after its rows are written (PRO-211) and + // after the services it reads are promoted. Returns a LoweredResult: `url` IS // published here — a Compute service's deployed URL is a public endpoint, // and this descriptor is the only party that knows it. It is the App's // domain, not the deployment's: the deployment is promoted on every // deploy, so its domain is unknown while planning, and every service // reading the URL would get a new deployment. Both fields are still // Output refs until apply. - deploy: ({ address }, provisioned, artifact, serialized) => + deploy: ({ id, address, graph, lowered }, provisioned, artifact, serialized) => Effect.gen(function* () { + const providerOutputs = graph.edges + .filter((edge) => edge.kind === "dependency" && edge.to === id) + .flatMap((edge) => Object.values(lowered.get(edge.from) ?? {})) + .filter(Output.isOutput) const deployment = yield* Prisma.Deployment(`${address}.deployment`, { - app: appAfterEnvironment(provisioned.serviceId, serialized.environment), + app: appAfter(provisioned.serviceId, serialized.environment, providerOutputs), artifactPath: artifact.path, artifactContentType: "application/gzip", portMapping: { http: serialized.port }, start: true, promote: true, diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts index f8ef9854f..995a6aa18 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts @@ -21,7 +21,7 @@ import { sha256, sha256Object } from 'alchemy/Util/sha256'; import * as Effect from 'effect/Effect'; import * as Layer from 'effect/Layer'; import * as Redacted from 'effect/Redacted'; -import { appAfterEnvironment } from '../deployment-edge.ts'; +import { appAfter } from '../deployment-edge.ts'; /** A stack the resource constructors register into; nothing ever applies it. */ const stack = { name: 'shop', stage: 'prod', resources: {}, bindings: {}, actions: {} }; @@ -66,7 +66,7 @@ afterAll(() => { /** The deploy hook's props, built by the same helper the descriptor uses. */ const deploymentProps = (triggers?: Record) => ({ - app: appAfterEnvironment(app.appId, environment), + app: appAfter(app.appId, environment, []), artifactPath, artifactContentType: 'application/gzip', portMapping: { http: 8080 }, @@ -158,7 +158,7 @@ const diffAgainst = async ( ); }; -describe('appAfterEnvironment — the edge Alchemy actually plans on', () => { +describe('appAfter — the edge Alchemy actually plans on', () => { test('every variable AND the app are upstream of the deployment', () => { const upstream = Output.upstreamAny(deploymentProps()); expect(Object.keys(upstream).sort()).toEqual( @@ -168,7 +168,7 @@ describe('appAfterEnvironment — the edge Alchemy actually plans on', () => { test('the combined expression still resolves to the app id — not a variable id or tuple', () => { const resolved = Effect.runSync( - Output.evaluate(appAfterEnvironment(app.appId, environment), { + Output.evaluate(appAfter(app.appId, environment, []), { 'auth-svc': { appId: 'app-123' }, 'COMPOSER_AUTH_PORT-var': { environmentVariableId: 'var-1' }, 'COMPOSER_AUTH_DB_URL-var': { environmentVariableId: 'var-2' }, @@ -178,11 +178,33 @@ describe('appAfterEnvironment — the edge Alchemy actually plans on', () => { }); test('a service with no variables passes the app id straight through', () => { - expect(Object.keys(Output.upstreamAny({ app: appAfterEnvironment(app.appId, []) }))).toEqual([ + expect(Object.keys(Output.upstreamAny({ app: appAfter(app.appId, [], []) }))).toEqual([ 'auth-svc', ]); }); + test("a provider's outputs are upstream of the deployment, and it still resolves to the app id", () => { + const provider = registered( + Prisma.App('provider-svc', { + project: 'proj-1', + displayName: 'provider', + regionId: 'us-east-1', + }), + ); + const edge = appAfter(app.appId, [], [provider.appId]); + + expect(Object.keys(Output.upstreamAny({ app: edge })).sort()).toEqual( + ['auth-svc', 'provider-svc'].sort(), + ); + const resolved = Effect.runSync( + Output.evaluate(edge, { + 'auth-svc': { appId: 'app-123' }, + 'provider-svc': { appId: 'app-456' }, + }) as Effect.Effect, + ); + expect(resolved).toBe('app-123'); + }); + test('the artifact props are plain values, never expressions', () => { const props = deploymentProps(); expect(Output.isOutput(props.artifactPath)).toBe(false); diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts index da57c094e..a824fe4b9 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-environment-lifecycle.test.ts @@ -10,7 +10,7 @@ import * as Layer from 'effect/Layer'; import * as Redacted from 'effect/Redacted'; import { data, fakeManagementApi, page } from '../../fake-management-api.ts'; import { runScratch, scratchStack } from '../../scratch-stack.ts'; -import { appAfterEnvironment } from '../deployment-edge.ts'; +import { appAfter } from '../deployment-edge.ts'; function isRecord(value: unknown): value is Record { return typeof value === 'object' && value !== null; @@ -212,7 +212,7 @@ test.each(scenarios)( ); } const deployment = yield* Prisma.Deployment('deployment', { - app: appAfterEnvironment(Output.asOutput('app-1'), environment), + app: appAfter(Output.asOutput('app-1'), environment, []), skipCodeUpload: true, start: false, // Environment values alone must replace the deployment. The drift case diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts index 563ed6940..9ffa86b64 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts @@ -1,32 +1,36 @@ /** - * Orders a deployment AFTER the environment rows it boots with: the platform - * materializes rows into a deployment at create time and never re-reads them - * (PRO-211). Alchemy schedules only on resource references inside prop - * values, and upstream's `Prisma.Deployment` has no environment prop, so the - * edge rides `app`: whole variable resources preserve their update edges; - * stable variable IDs alone are folded away during planning. The platform - * still receives the app id. `app` is the ONLY safe prop — upstream's diff - * treats `{portMapping, skipCodeUpload, artifactPath, artifactContentType}` - * as one block and returns "no opinion" if any is unresolved (a brand-new - * variable always is), which would silently skip the artifact comparison. - * Ordering only: shipping a CHANGED value is `Deployment.triggers`' job (the - * compute descriptor declares one member per environment row). + * Orders a deployment AFTER the environment rows it boots with and after the + * outputs of the services and resources it reads. The platform materializes + * rows into a deployment at create time and never re-reads them (PRO-211), and + * a service's deployment must go live after the deployments of the services + * it reads, whose `serviceId` resolves only once they are promoted. Alchemy + * schedules only on resource references inside prop values, and upstream's + * `Prisma.Deployment` has no environment prop, so the edge rides `app`: whole + * variable resources preserve their update edges; stable variable IDs alone + * are folded away during planning. The platform still receives the app id. + * `app` is the ONLY safe prop — upstream's diff treats `{portMapping, + * skipCodeUpload, artifactPath, artifactContentType}` as one block and + * returns "no opinion" if any is unresolved (a brand-new variable always is), + * which would silently skip the artifact comparison, while an unresolved + * `app` counts as unchanged. Ordering only: shipping a CHANGED value is + * `Deployment.triggers`' job (the compute descriptor declares one member per + * environment row), so waiting on a provider never replaces the deployment. */ import type { EnvironmentVariable } from '@alchemy.run/prisma'; import * as Output from 'alchemy/Output'; -export const appAfterEnvironment = ( +export const appAfter = ( app: Output.Output, environment: readonly EnvironmentVariable[], -): Output.Output => - environment.length === 0 + providerOutputs: readonly Output.Output[], +): Output.Output => { + const waits = [...environment.map((variable) => Output.of(variable)), ...providerOutputs]; + return waits.length === 0 ? app : // The app id is inside the combined expression as well as returned from // it: Alchemy's dependency walker looks only at what an expression is // built FROM, never inside the function, so an app referenced only by // the closure would leave the deployment with no edge to its own app. - Output.flatMap( - Output.all(app, ...environment.map((variable) => Output.of(variable))), - () => app, - ); + Output.flatMap(Output.all(app, ...waits), () => app); +}; diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts index 480c96e77..df4e2babd 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts @@ -12,6 +12,8 @@ import { scratchStack, } from '@internal/lowering/scratch-stack'; import * as Provider from 'alchemy/Provider'; +import * as Deferred from 'effect/Deferred'; +import * as Duration from 'effect/Duration'; import * as Effect from 'effect/Effect'; import * as Layer from 'effect/Layer'; import { compute } from '../compute.ts'; @@ -28,6 +30,9 @@ interface FakePlatform { readonly created: unknown[]; readonly variables: Map>; readonly values: Map; + readonly events: string[]; + /** While set, `shop.auth`'s deployment create waits until `shop.web`'s arrives, so a reader that does not wait for its provider is created first. */ + gate: Deferred.Deferred | undefined; } function record(body: unknown): Record { @@ -97,6 +102,7 @@ function respond(platform: FakePlatform, method: string, url: URL, body: unknown } if (method === 'POST' && action === '/deployments') { platform.created.push(service['id']); + platform.events.push(`create:${service['logicalId']}`); const id = `dep_${platform.created.length}`; const deployment = { id, @@ -113,6 +119,7 @@ function respond(platform: FakePlatform, method: string, url: URL, body: unknown } if (method === 'POST' && action === '/promote') { service['latestDeploymentId'] = sent['deploymentId']; + platform.events.push(`promote:${service['logicalId']}`); return data({ appEndpointDomain: service['appEndpointDomain'], reassignedDomains: 0 }); } } @@ -181,9 +188,22 @@ function fakePlatform() { created: [], variables: new Map(), values: new Map(), + events: [], + gate: undefined, }; const api = fakeManagementApi(({ method, path, body }) => - Effect.sync(() => respond(platform, method, new URL(path, 'https://api.prisma.test'), body)), + Effect.gen(function* () { + const url = new URL(path, 'https://api.prisma.test'); + const creating = + method === 'POST' ? url.pathname.match(/^\/v1\/services\/([^/]+)\/deployments$/) : null; + const address = platform.services.get(creating?.[1] ?? '')?.['logicalId']; + const gate = platform.gate; + if (gate !== undefined && address === 'shop.web') yield* Deferred.succeed(gate, undefined); + if (gate !== undefined && address === 'shop.auth') { + yield* Deferred.await(gate).pipe(Effect.timeoutOption(Duration.millis(500))); + } + return respond(platform, method, url, body); + }), ); const providers = Layer.effect( Prisma.Providers, @@ -228,7 +248,11 @@ const web = compute({ }); const descriptor = computeDescriptor(() => ({ workspaceId: 'ws_1', providerParams: new Map() })); -const graph = { root: { id: 'shop' }, inputBindings: [], edges: [] }; +const graph = { + root: { id: 'shop' }, + inputBindings: [], + edges: [{ from: 'shop.auth', to: 'shop.web', input: 'auth', kind: 'dependency' }], +}; const application = { projectId: PROJECT_ID, branchId: undefined, @@ -239,10 +263,11 @@ const application = { const artifact = { path: import.meta.path, sha256: 'sha-artifact' }; const changedArtifact = { path: path.join(import.meta.dir, '..', 'compute.ts'), sha256: 'sha-2' }; -function program(authArtifact = artifact) { +function program(authArtifact = artifact, webArtifact = artifact) { return Effect.gen(function* () { + const lowered = new Map>>(); const ctxOf = (address: string, node: unknown) => - ({ address, node, graph, application }) as unknown as LowerContext; + ({ id: address, address, node, graph, application, lowered }) as unknown as LowerContext; const authCtx = ctxOf('shop.auth', auth); const webCtx = ctxOf('shop.web', web); const authProvisioned = yield* descriptor.provision(authCtx); @@ -257,11 +282,12 @@ function program(authArtifact = artifact) { authArtifact, authSerialized, ); + lowered.set('shop.auth', deployed.outputs); const webSerialized = yield* descriptor.serialize(webCtx, webProvisioned, { service: { port: 3000 }, inputs: { auth: { url: deployed.outputs['url'] } }, }); - yield* descriptor.deploy(webCtx, webProvisioned, artifact, webSerialized); + yield* descriptor.deploy(webCtx, webProvisioned, webArtifact, webSerialized); }) as Effect.Effect; } @@ -287,3 +313,28 @@ test('a new artifact for the service that is read replaces its deployment and ke expect(createdFor('shop.auth')).toHaveLength(2); expect(createdFor('shop.web')).toHaveLength(1); }); + +test("on a first deploy, the service that is read is promoted before the reading service's deployment is created", async () => { + const { platform, stack } = fakePlatform(); + platform.gate = Deferred.makeUnsafe(); + + await runScratch(stack.deploy(program())); + + expect(platform.events.indexOf('promote:shop.auth')).toBeLessThan( + platform.events.indexOf('create:shop.web'), + ); +}); + +test("when both artifacts change, the service that is read is promoted before the reading service's new deployment is created", async () => { + const { platform, createdFor, stack } = fakePlatform(); + await runScratch(stack.deploy(program())); + platform.events.length = 0; + platform.gate = Deferred.makeUnsafe(); + + await runScratch(stack.deploy(program(changedArtifact, changedArtifact))); + + expect(createdFor('shop.web')).toHaveLength(2); + expect(platform.events.indexOf('promote:shop.auth')).toBeLessThan( + platform.events.indexOf('create:shop.web'), + ); +}); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts index 9fefb1822..e0e6076ab 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/control-lowering.test.ts @@ -1712,7 +1712,8 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { const ctx = { id: 'shop.auth', address: 'shop.auth', - graph: { root: { id: 'shop' } }, + graph: { root: { id: 'shop' }, edges: [] }, + lowered: new Map(), opts: {}, } as unknown as LowerContext; const provisioned = { @@ -1784,7 +1785,8 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { const ctx = { id: 'shop.auth', address: 'shop.auth', - graph: { root: { id: 'shop' } }, + graph: { root: { id: 'shop' }, edges: [] }, + lowered: new Map(), opts: {}, } as unknown as LowerContext; const provisioned = { @@ -1827,7 +1829,8 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { const ctx = { id: 'shop.mailer', address: 'shop.mailer', - graph: { root: { id: 'shop' } }, + graph: { root: { id: 'shop' }, edges: [] }, + lowered: new Map(), opts: {}, } as unknown as LowerContext; const provisioned = { @@ -1870,7 +1873,8 @@ describe("prismaCloud().nodes['compute'] — the service descriptor", () => { const ctx = { id: 'shop.auth', address: 'shop.auth', - graph: { root: { id: 'shop' } }, + graph: { root: { id: 'shop' }, edges: [] }, + lowered: new Map(), opts: {}, } as unknown as LowerContext; const provisioned = { @@ -2021,7 +2025,8 @@ describe("prismaCloud().nodes['s3-store'] — the service descriptor with extend const ctx = { id: 'shop.store', address: 'shop.store', - graph: { root: { id: 'shop' } }, + graph: { root: { id: 'shop' }, edges: [] }, + lowered: new Map(), opts: {}, } as unknown as LowerContext; const provisioned = { @@ -3111,11 +3116,17 @@ describe('resource IDs are built from the full address, and each declares the ID recorded.renamePolicy.filter(([r]) => r === resource).at(-1)?.[1]; const idsSince = (rows: ReadonlyArray<[string, unknown]>, before: number) => rows.slice(before).map(([id]) => id); - const shopGraph = { root: { id: 'shop' } }; + const shopGraph = { root: { id: 'shop' }, edges: [] }; test('compute: the App and Deployment of a nested service', () => { const target = prismaCloud({ workspaceId: 'ws_1' }); - const ctx = { id: 'shop.auth.api', address: 'shop.auth.api', graph: shopGraph, application }; + const ctx = { + id: 'shop.auth.api', + address: 'shop.auth.api', + graph: shopGraph, + application, + lowered: new Map(), + }; const before = { svc: recorded.svc.length, deploy: recorded.deploy.length }; run(serviceDescriptorOf(target, 'compute').provision(ctx as unknown as LowerContext)); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts index 79a94e21e..6685d4a06 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts @@ -3,11 +3,7 @@ import * as Prisma from '@alchemy.run/prisma'; import type { ServiceLowering } from '@internal/core/deploy'; import { describeDocument, type PlatformMarkerUse } from '@internal/input-document'; -import { - ARTIFACT_CONTENT_TYPE, - appAfterEnvironment, - packageComputeArtifact, -} from '@internal/lowering'; +import { ARTIFACT_CONTENT_TYPE, appAfter, packageComputeArtifact } from '@internal/lowering'; import * as Output from 'alchemy/Output'; import * as Effect from 'effect/Effect'; import * as Redacted from 'effect/Redacted'; @@ -355,8 +351,12 @@ export function computeDescriptor( }), ), - deploy: ({ address, graph, preflight }, provisioned, artifact, serialized) => + deploy: ({ id, address, graph, lowered, preflight }, provisioned, artifact, serialized) => Effect.gen(function* () { + const providerOutputs = graph.edges + .filter((edge) => edge.kind === 'dependency' && edge.to === id) + .flatMap((edge) => Object.values(lowered.get(edge.from) ?? {})) + .filter(Output.isOutput); const { platformVariableVersion } = preflightView(preflight); // Env keys never contain ':', so a `:updatedAt` member cannot // collide with a row's own trigger member. The key name is historical: @@ -373,10 +373,9 @@ export function computeDescriptor( }; const app = graph.root.id; const deployment = yield* Prisma.Deployment(resourceId(address, 'deployment'), { - // `app` carries the ordering edge on serialize's variable writes as - // well as the app id — see `appAfterEnvironment` for why it is the - // only prop that can (PRO-211). - app: appAfterEnvironment(provisioned.serviceId, serialized.environment), + // `app` carries the ordering edges as well as the app id — see + // `appAfter` for why it is the only prop that can. + app: appAfter(provisioned.serviceId, serialized.environment, providerOutputs), artifactPath: artifact.path, // The artifact IS a gzipped tar (see @internal/lowering's packager); // upstream sends this as the upload's Content-Type and folds it into From cdfc573cd200ed66cd21f50458e6609a99a7df3e Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 16:18:15 +1100 Subject: [PATCH 4/5] fix(prisma-cloud): the deploy-order tests fail when the producer is never promoted, and the docs name producers and consumers The ordering tests now assert the exact sequence of the producer's promotion and the consumer's deployment create, so a missing promotion fails them. Code, tests and docs use producer and consumer for the two ends of a dependency edge. The serviceId output says both reasons it comes from the deployment, the edge helper's comment says only what a caller needs, and the self-origin value is endpointDomainOf itself. The edge decision record has a dated amendment: a service's url comes from its App, and a consumer's deployment waits for its producers' promotion through the app prop, never through triggers. The Prisma Cloud docs and core's lowering steps state what is true now. Signed-off-by: willbot Signed-off-by: Will Madden --- .../05-prisma-cloud/alchemy-lowering.md | 35 +++------------ docs/design/05-prisma-cloud/pdp-data-model.md | 2 +- docs/design/10-domains/core-model.md | 22 +++------- ...come-from-the-upstream-alchemy-provider.md | 3 +- docs/design/90-decisions/README.md | 2 +- .../compute/__tests__/deployment-edge.test.ts | 14 +++--- .../lowering/src/compute/deployment-edge.ts | 24 +++------- .../__tests__/compute-redeploy-apply.test.ts | 44 ++++++++++--------- .../target/src/control/extension.ts | 15 +------ .../target/src/descriptors/compute.ts | 9 ++-- .../1-extensions/target/src/origin-key.ts | 2 +- 11 files changed, 62 insertions(+), 110 deletions(-) diff --git a/docs/design/05-prisma-cloud/alchemy-lowering.md b/docs/design/05-prisma-cloud/alchemy-lowering.md index 6559c6bdc..26b81f147 100644 --- a/docs/design/05-prisma-cloud/alchemy-lowering.md +++ b/docs/design/05-prisma-cloud/alchemy-lowering.md @@ -79,9 +79,9 @@ behind them. | `Prisma.Project` | Project | name | projectId | **one per Prisma Composer application**; resolved by the CLI before Alchemy runs, so no lowering yields one | | `Prisma.Database` | Database | project, name?, region, branchId?, logicalId? | databaseId, connection strings | one per Module-provisioned postgres resource; never the project default; a branch-attached database is created with `branchId` and no display name (upstream refuses the combination — see [deploying.md](../../guides/deploying.md)) | | `Prisma.Connection` | database connection info | database, name | connectionId, directConnectionString | Composer binds the DIRECT string explicitly; upstream's `databaseUrl` is pooled-first | -| `Prisma.App` | App | project, displayName, regionId, branchId?, logicalId? | appId, appEndpointDomain | `branchId` targets the Branch of an environment other than `production`; omitted, upstream attaches the App to the project's default (production) Branch. `appEndpointDomain` is available at provision — that is what a service's own origin is read from | +| `Prisma.App` | App | project, displayName, regionId, branchId?, logicalId? | appId, appEndpointDomain | `branchId` targets the Branch of an environment other than `production`; omitted, upstream attaches the App to the project's default (production) Branch. `appEndpointDomain` is available at provision — that is what a service's own origin and its published `url` are read from | | `Prisma.EnvironmentVariable` | ConfigVariable | project, class, key, value (Redacted), branchId? | environmentVariableId | production-class with no `branchId` for `production`; preview-class with `branchId` for any other environment. Values are write-only, so upstream re-applies the desired one on every deploy | -| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote**; since the PRO-200 fix it is the same domain the App reports from its create. It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves | +| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote**; it is the same domain the App reports from its create. It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves | | `Prisma.Bucket` | Bucket | project, name, branchId?, logicalId? | bucketId, name | one per bucket resource; `Prisma.BucketAccessKey` mints its read-write S3 credentials, which become the node's outputs | `logicalId` is set on every deploy except branchless local dev; [§ Platform identity](#platform-identity-logicalid) says what it carries. @@ -190,14 +190,7 @@ logic is untouched. Management API; the table above is that mapping. One resource maps to one PDP entity except `Deployment`, which spans version-create + upload + start + promote (and therefore owns the env-snapshot moment). -- **PDP → ours**: `foundryVersionId`, `Promotion`, and Foundry's version record - have no resource of ours; they are internal to the `Deployment` provider's - behavior or unmodeled. **Branch** likewise has no Alchemy resource — it is - resolved and its lifecycle managed by the CLI's container-resolution - client, outside the Alchemy graph entirely (see - [§ Environments and container resolution](#environments-and-container-resolution)). - `serviceEndpointDomain` surfaces as `App.appEndpointDomain` (before the first - deploy) and `Deployment.appEndpointDomain` (post-promote). +- **PDP → ours**: `foundryVersionId`, `Promotion`, and Foundry's version record have no resource of ours; they are internal to the `Deployment` provider's behavior or unmodeled. **Branch** likewise has no Alchemy resource — it is resolved and its lifecycle managed by the CLI's container-resolution client, outside the Alchemy graph entirely (see [§ Environments and container resolution](#environments-and-container-resolution)). `serviceEndpointDomain` surfaces as `App.appEndpointDomain` and `Deployment.appEndpointDomain`; both are the same domain. ## The lowering graphs @@ -240,9 +233,9 @@ How the pieces map: - **Each service** lowers to an `App → Deployment` chain plus its own `Database → Connection`, whose url is written as that service's **explicitly named** variable — the same `serialize` path as any other config value. -- **The connection** lowers to two edges: the producer's App's endpoint domain flows into a named `EnvironmentVariable`, and that **whole resource flows into the consumer's `Deployment`** through its `app` prop. The domain comes from the App, not the Deployment: the Deployment is promoted on every deploy, so its domain is unknown while planning, and a reading service's deployment, whose triggers hold the value, would be replaced on every deploy. Because the App's domain is known, an unchanged reading service keeps its deployment when the service it reads is redeployed. +- **The connection** lowers to two edges: the producer's App's endpoint domain flows into a named `EnvironmentVariable`, and that **whole resource flows into the consumer's `Deployment`** through its `app` prop. The domain comes from the App, not the Deployment: the Deployment is promoted on every deploy, so its domain is unknown while planning, and a consumer's deployment, whose triggers hold the value, would be replaced on every deploy. Because the App's domain is known, an unchanged consumer keeps its deployment when its producer is redeployed. - Every `EnvironmentVariable` a Deployment boots with is threaded into its `app` — database URLs and connection URLs alike — so the deployment depends on its config being written first. -- Every output of the services and resources a service reads is threaded into its Deployment's `app` too, so its deployment waits for the promotion of the services it reads: a Compute service's `serviceId` comes from its Deployment and resolves only after the promotion. The wait is on `app`, not in `triggers`, and upstream treats an unresolved `app` as unchanged, so an unchanged reading service is not replaced. +- Every output of a consumer's producers is threaded into its Deployment's `app` too, so its deployment waits for its producers' promotion: a Compute producer's `serviceId` comes from its Deployment and resolves only after the promotion. The wait is on `app`, not in `triggers`, and upstream treats an unresolved `app` as unchanged, so an unchanged consumer is not replaced. - The Deployment's `portMapping.http` rides the same seam: `serialize` resolves the service's `port` param from the typed Config and surfaces it in its outputs, and `deploy` routes the platform to it — so the routed port and the @@ -257,25 +250,11 @@ deployment-create, so new and replacement deployments boot with the completed configuration updates. Without it the two race — the failure documented as PRO-211 in `gotchas.md`. -**Why the edge rides `app`.** Upstream's `Prisma.Deployment` has no -`environment` prop (Composer's deleted one did). Alchemy derives its dependency -graph from the resource references a prop's *value* is built from, so the -descriptor builds `app` as an Output over the app id AND every whole variable -resource, resolving to the app id itself: the graph gains the edges. A persisted -variable ID can resolve before its pending value update finishes; the whole -resource keeps that update as a dependency. The edge cannot ride -`artifactPath` (or any of upstream's other replacement-block props): the diff -reads that block as one unit and gives no opinion the moment any member is -unresolved — and a brand-new variable's reference IS unresolved at plan time — -which would skip the artifact comparison and silently drop a code change. -`compute/deployment-edge.ts` records the full argument and its test drives -upstream's real diff. +**Why the edge rides `app`.** Upstream's `Prisma.Deployment` has no `environment` prop (Composer's deleted one did). Alchemy derives its dependency graph from the resource references a prop's *value* is built from, so the descriptor builds `app` as an Output over the app id, every whole variable resource and every output of the service's producers, resolving to the app id itself: the graph gains the edges. A persisted variable ID can resolve before its pending value update finishes; the whole resource keeps that update as a dependency. The edge cannot ride `artifactPath` (or any of upstream's other replacement-block props): the diff reads that block as one unit and gives no opinion the moment any member is unresolved — and a brand-new variable's reference IS unresolved at plan time — which would skip the artifact comparison and silently drop a code change. [ADR-0048](../90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md) records the full argument, and `compute/__tests__/deployment-edge.test.ts` drives upstream's real diff. **Change propagation is wired through `Prisma.Deployment.triggers`.** The platform freezes a deployment's environment at create, so a *value* change (a rotated URL) reaches a running service only through a new deployment. The compute descriptor declares one trigger member per environment row, carrying the same `Redacted` value the row writes; upstream folds the resolved members into a salted fingerprint inside its own encrypted state and plans a replacement exactly when one moved (and conservatively when a member cannot be resolved at plan time because the producing resource is itself changing). Unchanged service → same fingerprint → reuse; changed value or artifact → replace. Because upstream resolves the actual values, a value re-issued under a stable resource identity (a connection rotated in place, a re-minted service key) moves the fingerprint too. No plaintext lands in state — the members are `Redacted` in props and only the salted hash is persisted. A platform variable a row merely POINTS at (operator-owned; Composer never reads its value) contributes a `:updatedAt` member instead, read at preflight and handed to the lowering in the extension's preflight payload, so an out-of-band rotation still ships a new deployment. A service's input document is not an environment row and has no trigger member: it travels in the service's artifact, in the `inputDocument` field of `compute.bootstrap.json` ([ADR-0065](../90-decisions/ADR-0065-a-compute-services-input-document-travels-in-its-artifact.md)), so a changed document changes the artifact's bytes and its content-addressed `artifactPath`, which replaces the deployment. A platform variable the document names is still a `:updatedAt` member. -The framework's core constructs these edges when lowering a connection (the -`serialize` env-var records thread into `deploy` through the service SPI); no pack -author and no app author ever hand-wires them. +The compute descriptor constructs these edges (the `serialize` env-var records thread into `deploy` through the service SPI, and the producers' outputs come from the lowering context); no app author ever hand-wires them. ## Related diff --git a/docs/design/05-prisma-cloud/pdp-data-model.md b/docs/design/05-prisma-cloud/pdp-data-model.md index af1dd0341..0ced799c9 100644 --- a/docs/design/05-prisma-cloud/pdp-data-model.md +++ b/docs/design/05-prisma-cloud/pdp-data-model.md @@ -85,7 +85,7 @@ This is the timing model Prisma Composer's graph must respect: | any time | ConfigVariable rows are created/updated/deleted via the environment-variables API — **rows only; no effect on any existing version** | `routes/v1/environment-variables.ts` | | **version create** | `materializeBranchEnvVars(app.branchId)` resolves the complete map — production branch → production templates; preview branch → preview templates merged with that branch's overrides (override wins) — decrypts it, and hands the **plain map to Foundry with the version**. The env is **frozen into the version** | `routes/v1/versions.ts` → `resolveDeployEnvVars.ts` → `compute-config/materializeBranchEnvVars.ts` | | version start | boots the version; **no env re-resolution** | `routes/v1/version-handlers.ts` | -| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* time used to be a placeholder region (PRO-200); since that fix it names the domain the service will serve on, so it can be read before the first promote | `interactors/compute/service.ts` | +| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* names the domain the service will serve on | `interactors/compute/service.ts` | Consequences Prisma Composer designs around: diff --git a/docs/design/10-domains/core-model.md b/docs/design/10-domains/core-model.md index 919ad3252..9927d8456 100644 --- a/docs/design/10-domains/core-model.md +++ b/docs/design/10-domains/core-model.md @@ -766,7 +766,7 @@ module-provisioned **resource** lowers exactly once via its extension's nodes are edges only and never lower. Then for each service: 1. `provision` — the service now has identity (its App). -2. core **builds the typed `Config`** — each input's declared params matched by name to its producer's `outputs` through the one `dependency` edge: whatever the module wired in — a resource's outputs (shared by every consumer wired to it) or a producer service's deploy outputs — plus service-param defaults. Leaf values are provisioning refs, not strings. A producer service's URL is its App's endpoint domain, known from the App's create. The producer is still deployed first: the consumer's deployment waits for the producer's outputs through its `app` prop, and a Compute producer's `serviceId` resolves only after its promotion. +2. core **builds the typed `Config`** — each input's declared params matched by name to its producer's `outputs` through the one `dependency` edge: whatever the module wired in — a resource's outputs (shared by every consumer wired to it) or a producer service's deploy outputs — plus service-param defaults. Leaf values are provisioning refs, not strings. Core lowers a producer before its consumers, so a consumer's hooks receive the producer's outputs; how a target makes the consumer's deployment wait for its producers is the target's ([Prisma Cloud](../05-prisma-cloud/alchemy-lowering.md#the-lowering-graphs)). 3. `serialize(config)` — the pack encodes that typed Config into the service's runtime environment (Prisma Cloud: one env write per leaf, keyed by the pack's own naming from the address, value = the ref; the input document @@ -778,15 +778,7 @@ nodes are edges only and never lower. Then for each service: 5. `deploy(artifact)` — the first version snapshots an environment that is already complete. -**How the ordering is actually enforced:** our walk only *assembles* Alchemy -resource descriptions — Alchemy executes them in dependency order and runs -unordered resources concurrently; declaration order is never consulted. So core -realizes the sequence as **dependency edges**: most arise naturally from value flow -(the env var consumes the project id and the producer's URL), and the one that -doesn't — deploy-after-serialize — exists because the service descriptor builds -the `Deployment`'s props out of the environment records it boots with, which is -PDP's own dataflow restored (the deployment-create call literally contains the -materialized env map). See the lowering graphs in +**How the ordering is actually enforced:** our walk only *assembles* Alchemy resource descriptions — Alchemy executes them in dependency order and runs unordered resources concurrently; declaration order is never consulted. So core realizes the sequence as **dependency edges**: most arise naturally from value flow (the env var consumes the project id and the producer's URL), and two do not. Deploy-after-serialize exists because the service descriptor builds the `Deployment`'s props out of the environment records it boots with, which is PDP's own dataflow restored (the deployment-create call literally contains the materialized env map). Deploy-after-producers exists because the service descriptor also builds them out of its producers' outputs, so a consumer's deployment is created after its producers go live. See the lowering graphs in [`../05-prisma-cloud/alchemy-lowering.md`](../05-prisma-cloud/alchemy-lowering.md). This is what makes the fresh-deploy config race (PRO-211) structurally impossible on every target — the edge's **ordering** job. Its second job, **propagating** @@ -1127,9 +1119,9 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor Effect.try(() => Prisma.packageComputeArtifact({ id, bundleDir: assembled.dir, appEntry: assembled.entry, address, inputDocument: serialized.input && JSON.parse(serialized.input.value) })), // create → upload → start → promote. The app id is read through - // serialize's env-var records and every output of the services it reads, - // so the deployment is created after its rows are written (PRO-211) and - // after the services it reads are promoted. Returns a LoweredResult: `url` IS + // serialize's env-var records and every output of its producers, so the + // deployment is created after its rows are written (PRO-211) and after + // its producers are promoted. Returns a LoweredResult: `url` IS // published here — a Compute service's deployed URL is a public endpoint, // and this descriptor is the only party that knows it. It is the App's // domain, not the deployment's: the deployment is promoted on every @@ -1138,12 +1130,12 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor // Output refs until apply. deploy: ({ id, address, graph, lowered }, provisioned, artifact, serialized) => Effect.gen(function* () { - const providerOutputs = graph.edges + const producerOutputs = graph.edges .filter((edge) => edge.kind === "dependency" && edge.to === id) .flatMap((edge) => Object.values(lowered.get(edge.from) ?? {})) .filter(Output.isOutput) const deployment = yield* Prisma.Deployment(`${address}.deployment`, { - app: appAfter(provisioned.serviceId, serialized.environment, providerOutputs), + app: appAfter(provisioned.serviceId, serialized.environment, producerOutputs), artifactPath: artifact.path, artifactContentType: "application/gzip", portMapping: { http: serialized.port }, start: true, promote: true, diff --git a/docs/design/90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md b/docs/design/90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md index cfea8bdd4..f45a665ec 100644 --- a/docs/design/90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md +++ b/docs/design/90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md @@ -4,6 +4,7 @@ Amended by [ADR-0057](ADR-0057-a-nodes-address-is-its-full-path-from-the-app-nam Amended 2026-10-30: from Alchemy 2.0.0-beta.84 the provider is its own package, `@alchemy.run/prisma`, versioned in lockstep with `alchemy`; before that it was the `alchemy/Prisma` module of the `alchemy` package. Only `@prisma/composer-prisma-cloud` and the Prisma Cloud internals it bundles depend on it; `@prisma/composer` and `@prisma/composer-cli` depend on `alchemy` alone. The move kept every resource type id (`Prisma.*`), so deploy state carries over unchanged. The decision below is unchanged. +Amended 2026-11-20: a compute service's published `url` is its App's `appEndpointDomain`, not its Deployment's: the Deployment is updated on every deploy, so its domain is unknown while planning, and every consumer's deployment, whose `triggers` hold the url, would be replaced on every deploy. A consumer's deployment waits for its producers' promotion through the deployment's `app` prop, which also carries every output of the nodes it depends on (a compute producer's `serviceId` resolves only after its promotion), never through `triggers`, so an unchanged consumer is reused. ## Decision @@ -31,7 +32,7 @@ and a lowered compute service is upstream resources wired by Composer's descript const app = Prisma.App(`${id}-svc`, { project, regionId, branchId }); const vars = records.map((r) => Prisma.EnvironmentVariable(...)); const deployment = Prisma.Deployment(`${id}-deploy`, { - app: dependsOnEnvironment(app, vars), // see "The ordering edge" below + app: appAfter(app, vars, producerOutputs), // see "The ordering edge" below artifactPath, // Composer's own tar.gz — never built by Alchemy start: true, promote: true, diff --git a/docs/design/90-decisions/README.md b/docs/design/90-decisions/README.md index 8da6739d2..cf6453017 100644 --- a/docs/design/90-decisions/README.md +++ b/docs/design/90-decisions/README.md @@ -69,7 +69,7 @@ _Earlier drafts (ADR-0001, ADR-0002) were retired as the high-level design settl - [ADR-0045](ADR-0045-deploy-state-lives-behind-the-platform-state-api.md) — Deploy state lives behind the platform state API (the Management API implements Alchemy's stock `HttpStateApi` wire contract per Branch; composer's state layer is Alchemy's stock HTTP client), and deploys hold a server-side per-`(stack, stage)` lease (TTL 60s, heartbeated, released on exit; contention fails fast naming the holder; state operations without a live lease fail 409). Supersedes ADR-0010 (lock → lease) and the storage half of ADR-0034 (Branch scoping and lifetime stand; the visible per-stage database is gone); closes ADR-0012 as obsolete. No migration: legacy stages are refused until destroyed or deleted. - [ADR-0046](ADR-0046-the-orm-facade-is-a-peer-dependency.md) — `@prisma/composer-prisma-cloud` takes the Prisma ORM postgres facade (`@prisma/orm-postgres`) as a **peer** dependency at one exact version, not a regular dependency: Composer registers an extension pack against the application's copy of the target, and two copies of a shell in one tree means two codec/operation registries and two class identities — a value from one is rejected by the other, silently. As a peer, that combination fails at install instead. Every `@prisma/orm-*` spec in the workspace is one exact version and all name the same one (`scripts/lint-orm-pins.mjs`). `@prisma/orm-toolchain`, which Composer drives rather than extends, stays a regular dependency. Replaces ADR-0022's consequence bullet on how the ORM is installed. - [ADR-0047](ADR-0047-compute-assembly-preserves-safe-runtime-topology.md) — Compute assembly traces runtime files from the author-declared Node entry without rebundling app code, preserves only symlinks whose resolved targets remain inside the staged bundle, and installs narrowly runtime-gated bootstrap compatibility when a framework needs Node semantics. Each local mechanism is removed once the upstream Alchemy Compute provider owns the equivalent guarantee. Supersedes ADR-0005's blanket ban on symlinks and its assumption that directory output is already self-contained. -- [ADR-0048](ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md) — The six Management-API resource families (project, database, connection, app, deployment, environment variable) are the upstream Prisma provider's classes (`@alchemy.run/prisma`), registered in Composer's `PrismaComposer` collection; Composer defines resources only where the upstream provider has no support yet (buckets) or no Management API exists behind them. Compute binds the low-level App/Deployment/EnvironmentVariable trio (the `COMPOSER_*_ORIGIN` self-edge and ADR-0005 rule out composite `Compute`); the env→deployment ordering edge rides the deployment's `app` prop, and a deployment is replaced exactly when its artifact or environment fingerprint changes — unchanged services are reused. Legacy rows in the platform state API (retired type-ids and shapes) migrate on read — the older retired SQL state stores stay destroy-only under ADR-0045 — branch-stage databases take generated physical names, and the platform's seeded `DATABASE_URL` is left system-managed. *(Amended by ADR-0057: resource IDs are the node's full address, or the address plus `.` and a role, each declaring its previous ID with `renamedFrom`. Amended 2026-10-30: the provider is the `@alchemy.run/prisma` package from Alchemy beta.84 (formerly the `alchemy/Prisma` module); resource type ids are unchanged.)* +- [ADR-0048](ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md) — The six Management-API resource families (project, database, connection, app, deployment, environment variable) are the upstream Prisma provider's classes (`@alchemy.run/prisma`), registered in Composer's `PrismaComposer` collection; Composer defines resources only where the upstream provider has no support yet (buckets) or no Management API exists behind them. Compute binds the low-level App/Deployment/EnvironmentVariable trio (the `COMPOSER_*_ORIGIN` self-edge and ADR-0005 rule out composite `Compute`); the env→deployment ordering edge rides the deployment's `app` prop, and a deployment is replaced exactly when its artifact or environment fingerprint changes — unchanged services are reused. Legacy rows in the platform state API (retired type-ids and shapes) migrate on read — the older retired SQL state stores stay destroy-only under ADR-0045 — branch-stage databases take generated physical names, and the platform's seeded `DATABASE_URL` is left system-managed. *(Amended by ADR-0057: resource IDs are the node's full address, or the address plus `.` and a role, each declaring its previous ID with `renamedFrom`. Amended 2026-10-30: the provider is the `@alchemy.run/prisma` package from Alchemy beta.84 (formerly the `alchemy/Prisma` module); resource type ids are unchanged. Amended 2026-11-20: a compute service's published `url` is its App's endpoint domain, and a consumer's deployment waits for its producers' promotion through the deployment's `app` prop, never through `triggers`.)* - [ADR-0049](ADR-0049-composers-configuration-is-the-composer-section-of-prisma-config.md) — Composer's configuration is the `composer` section of `prisma.config.ts`, loaded by the Prisma CLI engine: `extensions`, `state`, and optional `entry`, `config` and `secrets` adapter lists. The validator checks only what identifies each value, passes the file's own objects through, never calls an adapter, rejects unknown keys, takes the nearest declaring file's section whole, and returns `{ value, file }`; the programmatic operations take the same input. The old config file is refused, not migrated. Only the first process runs adapters; the second process imports the file for its descriptors and reads what Load read from the app configuration file. *(Amended by ADR-0066: the child-process reason for one declaring file now holds for `destroy` and `prisma dev`; the decision stands.)* *(Amended by ADR-0067: the dev worker thread imports the config; no dev stack file.)* *(Amended by ADR-0068: `destroy` has no second process; no command hands the config to a second process.)* - [ADR-0050](ADR-0050-composer-runs-as-prisma-deploy-and-prisma-dev.md) — Composer has no binary of its own: the `prisma` CLI mounts exactly two Composer commands, `prisma deploy` and `prisma dev`, mounted at the root as bare verbs on purpose rather than under a noun. `destroy` and `log` are operations on `@prisma/composer/control`, called from a script; a teardown script reads `PRISMA_SERVICE_TOKEN` and `PRISMA_WORKSPACE_ID`. Where teardown and logs belong in the `prisma` command tree is not decided; until it is, agents and users need a script for both. A `destroy` command was rejected: the CLI's destructive verb is `delete`, and no Composer command takes `--production`. Retires the `prisma-composer` binary; a CI lint keeps its name out of user-facing files. *(Amended by ADR-0053: the family also ships `dev url`, `dev stop` and `emulator list`, and `prisma dev` gains `--detach`. Amended 2026-10-23: neither command takes a positional entry; both take `--entry` over the config's `entry`. Amended 2026-10-27: the family also ships `deploy list`.)* *(Amended by ADR-0062: the flag is `--environment`, defaulting per command; `destroy` targets an environment by name.)* - [ADR-0051](ADR-0051-a-nodes-address-is-its-logical-id-on-the-platform.md) — A node's address is its identity on Prisma Cloud: Composer writes it, byte for byte, as the `logicalId` of the node's one platform row (Project, App, Database, Bucket) and as the node's `logicalId` in the application topology, so the platform joins topology nodes to rows, and one node across branches, by string equality. A provision ID defaults to the node's name, so changing a name changes identity. The value is never an Alchemy resource ID, a display name or a platform `id`; App, Database and Bucket rows get it as a prop on the upstream resource that creates them, and the Project from container resolution; no separate resource writes it. Changing an address changes the entity's identity; changing a display name changes nothing. *(Amended 2026-10-16: on the app's own Project and Branch, the row holding a node's `logicalId` is that node's row, so a deploy resuming an interrupted create uses it. Superseded by ADR-0057: addresses start with the app name, and resource IDs, env keys and `serviceOrigin()` are built from them; the identity rules here are carried forward.)* diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts index 995a6aa18..c5dfe6b57 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/__tests__/deployment-edge.test.ts @@ -183,23 +183,23 @@ describe('appAfter — the edge Alchemy actually plans on', () => { ]); }); - test("a provider's outputs are upstream of the deployment, and it still resolves to the app id", () => { - const provider = registered( - Prisma.App('provider-svc', { + test("a producer's outputs are upstream of the deployment, and it still resolves to the app id", () => { + const producer = registered( + Prisma.App('producer-svc', { project: 'proj-1', - displayName: 'provider', + displayName: 'producer', regionId: 'us-east-1', }), ); - const edge = appAfter(app.appId, [], [provider.appId]); + const edge = appAfter(app.appId, [], [producer.appId]); expect(Object.keys(Output.upstreamAny({ app: edge })).sort()).toEqual( - ['auth-svc', 'provider-svc'].sort(), + ['auth-svc', 'producer-svc'].sort(), ); const resolved = Effect.runSync( Output.evaluate(edge, { 'auth-svc': { appId: 'app-123' }, - 'provider-svc': { appId: 'app-456' }, + 'producer-svc': { appId: 'app-456' }, }) as Effect.Effect, ); expect(resolved).toBe('app-123'); diff --git a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts index 9ffa86b64..9f8b08011 100644 --- a/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts +++ b/packages/1-prisma-cloud/0-lowering/lowering/src/compute/deployment-edge.ts @@ -1,20 +1,8 @@ /** - * Orders a deployment AFTER the environment rows it boots with and after the - * outputs of the services and resources it reads. The platform materializes - * rows into a deployment at create time and never re-reads them (PRO-211), and - * a service's deployment must go live after the deployments of the services - * it reads, whose `serviceId` resolves only once they are promoted. Alchemy - * schedules only on resource references inside prop values, and upstream's - * `Prisma.Deployment` has no environment prop, so the edge rides `app`: whole - * variable resources preserve their update edges; stable variable IDs alone - * are folded away during planning. The platform still receives the app id. - * `app` is the ONLY safe prop — upstream's diff treats `{portMapping, - * skipCodeUpload, artifactPath, artifactContentType}` as one block and - * returns "no opinion" if any is unresolved (a brand-new variable always is), - * which would silently skip the artifact comparison, while an unresolved - * `app` counts as unchanged. Ordering only: shipping a CHANGED value is - * `Deployment.triggers`' job (the compute descriptor declares one member per - * environment row), so waiting on a provider never replaces the deployment. + * A deployment's `app` prop, ordered after its environment rows and after the + * producer outputs the caller passes. The edges ride `app` because upstream + * treats an unresolved `app` as unchanged, while an unresolved artifact prop + * would skip the artifact comparison. */ import type { EnvironmentVariable } from '@alchemy.run/prisma'; @@ -23,9 +11,9 @@ import * as Output from 'alchemy/Output'; export const appAfter = ( app: Output.Output, environment: readonly EnvironmentVariable[], - providerOutputs: readonly Output.Output[], + producerOutputs: readonly Output.Output[], ): Output.Output => { - const waits = [...environment.map((variable) => Output.of(variable)), ...providerOutputs]; + const waits = [...environment.map((variable) => Output.of(variable)), ...producerOutputs]; return waits.length === 0 ? app : // The app id is inside the combined expression as well as returned from diff --git a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts index df4e2babd..369863e75 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/__tests__/compute-redeploy-apply.test.ts @@ -1,4 +1,4 @@ -/** Two compute services, one reading the other's URL, deployed twice under the real Alchemy apply engine and the real `Prisma.App`, `Prisma.Deployment` and `Prisma.EnvironmentVariable` providers, against a fake Management API. */ +// A producer and a consumer that reads its url, deployed twice under the real Alchemy apply engine and the real `Prisma.App`, `Prisma.Deployment` and `Prisma.EnvironmentVariable` providers, against a fake Management API. import { expect, test } from 'bun:test'; import * as path from 'node:path'; import * as Prisma from '@alchemy.run/prisma'; @@ -26,13 +26,13 @@ const CREATED_AT = '2026-11-20T00:00:00.000Z'; interface FakePlatform { readonly services: Map>; readonly deployments: Map>; - /** The App id of every deployment ever created, in order; a deleted deployment stays listed. */ + // A deleted deployment stays listed. readonly created: unknown[]; readonly variables: Map>; readonly values: Map; readonly events: string[]; - /** While set, `shop.auth`'s deployment create waits until `shop.web`'s arrives, so a reader that does not wait for its provider is created first. */ - gate: Deferred.Deferred | undefined; + // While set, the producer's deployment create waits until the consumer's arrives, so a consumer that does not wait for its producer is created first. + authCreateWaitsForWeb: Deferred.Deferred | undefined; } function record(body: unknown): Record { @@ -189,7 +189,7 @@ function fakePlatform() { variables: new Map(), values: new Map(), events: [], - gate: undefined, + authCreateWaitsForWeb: undefined, }; const api = fakeManagementApi(({ method, path, body }) => Effect.gen(function* () { @@ -197,10 +197,12 @@ function fakePlatform() { const creating = method === 'POST' ? url.pathname.match(/^\/v1\/services\/([^/]+)\/deployments$/) : null; const address = platform.services.get(creating?.[1] ?? '')?.['logicalId']; - const gate = platform.gate; - if (gate !== undefined && address === 'shop.web') yield* Deferred.succeed(gate, undefined); - if (gate !== undefined && address === 'shop.auth') { - yield* Deferred.await(gate).pipe(Effect.timeoutOption(Duration.millis(500))); + const waitForWeb = platform.authCreateWaitsForWeb; + if (waitForWeb !== undefined && address === 'shop.web') { + yield* Deferred.succeed(waitForWeb, undefined); + } + if (waitForWeb !== undefined && address === 'shop.auth') { + yield* Deferred.await(waitForWeb).pipe(Effect.timeoutOption(Duration.millis(500))); } return respond(platform, method, url, body); }), @@ -291,7 +293,7 @@ function program(authArtifact = artifact, webArtifact = artifact) { }) as Effect.Effect; } -test("an unchanged deploy keeps the deployment of a service that reads another service's url", async () => { +test("an unchanged deploy keeps the deployment of a consumer of the producer's url", async () => { const { platform, createdFor, stack } = fakePlatform(); await runScratch(stack.deploy(program())); @@ -304,7 +306,7 @@ test("an unchanged deploy keeps the deployment of a service that reads another s expect(createdFor('shop.web')).toHaveLength(1); }); -test('a new artifact for the service that is read replaces its deployment and keeps the reading service', async () => { +test("a new artifact for the producer replaces its deployment and keeps the consumer's", async () => { const { createdFor, stack } = fakePlatform(); await runScratch(stack.deploy(program())); @@ -314,27 +316,27 @@ test('a new artifact for the service that is read replaces its deployment and ke expect(createdFor('shop.web')).toHaveLength(1); }); -test("on a first deploy, the service that is read is promoted before the reading service's deployment is created", async () => { +test("on a first deploy, the producer is promoted before the consumer's deployment is created", async () => { const { platform, stack } = fakePlatform(); - platform.gate = Deferred.makeUnsafe(); + platform.authCreateWaitsForWeb = Deferred.makeUnsafe(); await runScratch(stack.deploy(program())); - expect(platform.events.indexOf('promote:shop.auth')).toBeLessThan( - platform.events.indexOf('create:shop.web'), - ); + expect( + platform.events.filter((event) => event === 'promote:shop.auth' || event === 'create:shop.web'), + ).toEqual(['promote:shop.auth', 'create:shop.web']); }); -test("when both artifacts change, the service that is read is promoted before the reading service's new deployment is created", async () => { +test("when both artifacts change, the producer is promoted before the consumer's new deployment is created", async () => { const { platform, createdFor, stack } = fakePlatform(); await runScratch(stack.deploy(program())); platform.events.length = 0; - platform.gate = Deferred.makeUnsafe(); + platform.authCreateWaitsForWeb = Deferred.makeUnsafe(); await runScratch(stack.deploy(program(changedArtifact, changedArtifact))); expect(createdFor('shop.web')).toHaveLength(2); - expect(platform.events.indexOf('promote:shop.auth')).toBeLessThan( - platform.events.indexOf('create:shop.web'), - ); + expect( + platform.events.filter((event) => event === 'promote:shop.auth' || event === 'create:shop.web'), + ).toEqual(['promote:shop.auth', 'create:shop.web']); }); diff --git a/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts b/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts index e7e3e96c1..b394c1897 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/control/extension.ts @@ -153,18 +153,6 @@ const streamsApiKeyValue: ProviderParam['value'] = (refs) => { }); }; -/** - * Origin's deploy-side value function (service-derived): the provisioned - * service's own `endpointDomain`, verbatim — `https://…`, no trailing slash, - * no normalization. Every compute service gets this row, exposing or not. - * The undefined guard is a deploy-time invariant check, not a policy: the - * Management API always reports an endpoint domain post-PRO-200, so a missing - * one means the platform predates the fix — fail the deploy loudly rather - * than write a row origin() would trust. The raw string is JSON-encoded by - * the descriptor's generic loop, like every other reserved provider param. - */ -const selfOriginValue: ServiceProviderParam['valueForService'] = endpointDomainOf; - /** The user-facing state descriptor: `state: prismaState()` in the `composer` section of `prisma.config.ts` (ADR-0017). */ export const prismaState = (): StateDescriptor => ({ extension: PRISMA_CLOUD_EXTENSION_ID, @@ -241,7 +229,8 @@ const PROVIDER_PARAM_VALUES: ReadonlyMap = new Map< >([ [RPC_PEER_KEY, { value: rpcAcceptedKeysValue }], [STREAMS_API_KEY, { value: streamsApiKeyValue }], - [SELF_ORIGIN, { valueForService: selfOriginValue }], + // The service's own App domain, verbatim, written for every compute service whether it exposes anything or not. + [SELF_ORIGIN, { valueForService: endpointDomainOf }], ]); /** diff --git a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts index 6685d4a06..199fcf000 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts @@ -353,7 +353,8 @@ export function computeDescriptor( deploy: ({ id, address, graph, lowered, preflight }, provisioned, artifact, serialized) => Effect.gen(function* () { - const providerOutputs = graph.edges + // Only to order this deployment after its producers are live; their values reach it through the rows and triggers. + const producerOutputs = graph.edges .filter((edge) => edge.kind === 'dependency' && edge.to === id) .flatMap((edge) => Object.values(lowered.get(edge.from) ?? {})) .filter(Output.isOutput); @@ -375,7 +376,7 @@ export function computeDescriptor( const deployment = yield* Prisma.Deployment(resourceId(address, 'deployment'), { // `app` carries the ordering edges as well as the app id — see // `appAfter` for why it is the only prop that can. - app: appAfter(provisioned.serviceId, serialized.environment, providerOutputs), + app: appAfter(provisioned.serviceId, serialized.environment, producerOutputs), artifactPath: artifact.path, // The artifact IS a gzipped tar (see @internal/lowering's packager); // upstream sends this as the upload's Content-Type and folds it into @@ -399,10 +400,10 @@ export function computeDescriptor( const url = endpointDomainOf(provisioned, address); return { outputs: { - // The App's domain: one that waits for the promotion is unknown while planning, which replaces every reader's deployment. + // The App's domain, not the deployment's: the deployment's is unknown while planning, so every consumer of this url would get a new deployment. url, projectId: provisioned.projectId, - // Waits for the promotion, because a custom domain is bound to the live version. + // From the deployment, so it resolves once this service is live: a custom domain binds to the live version, and its consumers' deployments wait for it. serviceId: deployment.appId, }, entities: [ diff --git a/packages/1-prisma-cloud/1-extensions/target/src/origin-key.ts b/packages/1-prisma-cloud/1-extensions/target/src/origin-key.ts index 8a35f737b..4c4d32e55 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/origin-key.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/origin-key.ts @@ -2,7 +2,7 @@ * The service's own origin as a reserved provider param (ADR-0031): the ONE * brand and the ONE entry — shared by control.ts (which registers the * deploy-side value function that resolves the provisioned service's - * `endpointDomain` — see its `selfOriginValue`) and compute.ts (which + * `endpointDomain` through `endpointDomainOf`) and compute.ts (which * validates and stashes the row at boot through the generic * `stashProviderParams` loop), so writer and reader cannot drift. * From a0c549c535b91b1e2d83406a92513972849816e6 Mon Sep 17 00:00:00 2001 From: willbot Date: Fri, 20 Nov 2026 17:15:00 +1100 Subject: [PATCH 5/5] fix(prisma-cloud): a serviceOrigin that cannot resolve names the consumer again The shared missing-domain error named only the producing service. It now also says which consumer's serviceOrigin could not be resolved, as the message did before the check was shared. Signed-off-by: willbot Signed-off-by: Will Madden --- .../1-extensions/target/src/descriptors/compute.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts index 199fcf000..81fee7110 100644 --- a/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts +++ b/packages/1-prisma-cloud/1-extensions/target/src/descriptors/compute.ts @@ -105,16 +105,23 @@ function originOf( `address — known services: ${known}.`, ); } - return endpointDomainOf(provisioned, target); + return endpointDomainOf( + provisioned, + target, + `cannot resolve serviceOrigin("${target}") for "${consumer}"`, + ); } export function endpointDomainOf( provisioned: ServiceProvisionedAttributes, address: string, + consequence?: string, ): Output.Output { return Output.map(provisioned.endpointDomain, (domain) => { if (domain === undefined) { - throw new Error(`the App for "${address}" reported no endpoint domain.`); + throw new Error( + `the App for "${address}" reported no endpoint domain${consequence === undefined ? '' : `: ${consequence}`}.`, + ); } return domain; });