diff --git a/scripts/check-release-admission.ts b/scripts/check-release-admission.ts index a5d4d9f9..c9f28cf7 100644 --- a/scripts/check-release-admission.ts +++ b/scripts/check-release-admission.ts @@ -10,6 +10,7 @@ import { } from "../src/contracts/deployment-admission.ts"; import { unknownProductFeatureOverrides } from "../src/contracts/product-features.ts"; import { parseRuntimeConfigArtifact } from "../src/contracts/release-artifacts.ts"; +import { EXPECTED_CONTRACT_SET_PACKAGES } from "../src/features/installed-contract-contributions.ts"; import { COMPILED_PRODUCT_FEATURE_IDS } from "../src/features/installed-product-manifest.ts"; /** @@ -136,7 +137,15 @@ async function main(): Promise { } } - const violations = findAdmissionViolations(declared, config); + // U7 (decision 2). The packages the build compiled; a placeholder identity + // from create:feature is refused for staging and production. An edited copy + // is checked without them: packages are a build field it cannot change, and + // the build's own admission checked them. + const violations = findAdmissionViolations( + declared, + config, + editedCopy === undefined ? EXPECTED_CONTRACT_SET_PACKAGES : [], + ); // 09-09. Inert by design (a shared document may name another build's // features), so this warns instead of refusing. const warnings = unknownProductFeatureOverrides( diff --git a/src/contracts/deployment-admission.ts b/src/contracts/deployment-admission.ts index d095dd5c..289d6a0c 100644 --- a/src/contracts/deployment-admission.ts +++ b/src/contracts/deployment-admission.ts @@ -45,6 +45,18 @@ const PLACEHOLDER_IDENTIFIERS: ReadonlySet = new Set([ "unknown", ]); +/** + * U7 (decision 2). The contract package identity `pnpm create:feature` writes + * when no `--package` is given: an all-zero digest, version 0.0.0 and revision + * 0000000. It passes every format check (`external-contract-runtime.ts`), so a + * generated feature boots and tests locally; a public target refuses the + * digest below. + */ +export const PLACEHOLDER_CONTRACT_PACKAGE_DIGEST = + `sha256:${"0".repeat(64)}` as const; +export const PLACEHOLDER_CONTRACT_PACKAGE_VERSION = "0.0.0"; +export const PLACEHOLDER_CONTRACT_PACKAGE_REVISION = "0000000"; + export type AdmissionViolation = Readonly<{ field: string; reason: string }>; export type AdmissionInput = RuntimeConfigArtifact & @@ -57,13 +69,21 @@ export function isDeploymentTarget(value: unknown): value is DeploymentTarget { ); } +/** The fields of a contract package identity admission reads. */ +export type AdmissionContractPackage = Readonly<{ + packageId: string; + digest: string; +}>; + /** * Every reason this artifact may not be deployed to `target`. An empty list is - * the only admission. + * the only admission. `contractPackages` is the contract set the build + * compiled (`EXPECTED_CONTRACT_SET_PACKAGES`). */ export function findAdmissionViolations( target: DeploymentTarget, config: AdmissionInput, + contractPackages: readonly AdmissionContractPackage[] = [], ): readonly AdmissionViolation[] { const violations: AdmissionViolation[] = []; if (config.APP_ENV !== target) { @@ -105,6 +125,15 @@ export function findAdmissionViolations( }); } } + for (const contractPackage of contractPackages) { + if (contractPackage.digest === PLACEHOLDER_CONTRACT_PACKAGE_DIGEST) { + violations.push({ + field: `contractPackages.${contractPackage.packageId}`, + reason: + "pins the placeholder identity create:feature writes; pin the published package's version, digest and revision", + }); + } + } return Object.freeze(violations); } diff --git a/tests/unit/deployment-admission.test.ts b/tests/unit/deployment-admission.test.ts index 547bd7ec..0617f17c 100644 --- a/tests/unit/deployment-admission.test.ts +++ b/tests/unit/deployment-admission.test.ts @@ -9,9 +9,11 @@ import { DEPLOYMENT_TARGETS, findAdmissionViolations, isDeploymentTarget, + PLACEHOLDER_CONTRACT_PACKAGE_DIGEST, type AdmissionInput, } from "../../src/contracts/deployment-admission.ts"; import { ENV_REGISTRY, getBuildConfig } from "../../src/contracts/env.ts"; +import { EXPECTED_CONTRACT_SET_PACKAGES } from "../../src/features/installed-contract-contributions.ts"; import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts"; import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts"; @@ -49,6 +51,39 @@ describe("deployment admission", () => { expect(findAdmissionViolations("local", LOCAL_ARTIFACT)).toEqual([]); }); + // U7 (decision 2). `create:feature` pins this digest when no contract + // package is given. It passes every format check, so a public target is + // where it stops; local and development builds keep working with it. + it("refuses a contract package that pins the placeholder digest for a public target", () => { + const placeholder = Object.freeze({ + packageId: "@org-contracts/orders", + digest: PLACEHOLDER_CONTRACT_PACKAGE_DIGEST, + }); + const published = Object.freeze({ + packageId: "@org-contracts/billing", + digest: `sha256:${"a".repeat(64)}` as const, + }); + expect(PLACEHOLDER_CONTRACT_PACKAGE_DIGEST).toBe(`sha256:${"0".repeat(64)}`); + for (const target of ["staging", "production"] as const) { + expect( + findAdmissionViolations( + target, + { ...PRODUCTION_ARTIFACT, APP_ENV: target }, + [placeholder, published], + ).map((violation) => violation.field), + target, + ).toEqual(["contractPackages.@org-contracts/orders"]); + } + for (const target of ["local", "development"] as const) { + expect( + findAdmissionViolations(target, { ...LOCAL_ARTIFACT, APP_ENV: target }, [ + placeholder, + ]), + target, + ).toEqual([]); + } + }); + it("refuses the exact local build that release coherence used to approve", () => { // The review's strongest reproduction: FE-GATE-015 passed on a build whose // runtime document was APP_ENV=local / AUTH_MODE=demo / loopback API. Each @@ -289,9 +324,15 @@ describe("runtime config profiles", () => { // 13-01: the build profile and the admission target are two repository // variables. A staging profile left in place for a production release has to // stop the release, whatever the built document happens to say. + // U7 (decision 2): the script also refuses the compiled contract set while a + // feature from create:feature still pins the placeholder package, so with + // one installed the matching profile is refused for that reason only. + const placeholderInstalled = EXPECTED_CONTRACT_SET_PACKAGES.some( + ({ digest }) => digest === PLACEHOLDER_CONTRACT_PACKAGE_DIGEST, + ); it.each([ ["staging", 1], - ["production", 0], + ["production", placeholderInstalled ? 1 : 0], ] as const)("admits a production artifact under APP_PROFILE=%s only when it names the target", async (profile, status) => { const root = await mkdtemp(path.join(tmpdir(), "release-admission-profile-")); try { @@ -308,7 +349,11 @@ describe("runtime config profiles", () => { }, ); expect(result.status, result.stderr).toBe(status); - if (status === 1) expect(result.stderr).toMatch(/APP_PROFILE=staging/u); + if (profile === "staging") { + expect(result.stderr).toMatch(/APP_PROFILE=staging/u); + } else { + expect(result.stderr).not.toMatch(/APP_PROFILE/u); + } } finally { await rm(root, { recursive: true, force: true }); }