diff --git a/config/contracts/registry-change-evidence.json b/config/contracts/registry-change-evidence.json index 0329c0a2..5aa12b9c 100644 --- a/config/contracts/registry-change-evidence.json +++ b/config/contracts/registry-change-evidence.json @@ -104,6 +104,14 @@ "compatibilityWindow": "No wire, storage or runtime-config format changes: the old id was never emitted by any producer, so no consumer could observe it.", "rollback": "Restore the previous telemetryEvent string on QUERY_CACHE_FAILURE in src/contracts/errors.ts and widen ErrorObservationEvent back to string.", "owner": "frontend-platform" + }, + { + "changeId": "FE-REG-ENV:VITE_BUILD_ID:defaultValue:field-type-changed", + "versionBump": "F-6 (13-15): the registry now records the local-build fallback that getBuildConfig and the build scripts already applied; the value itself did not change.", + "migration": "None for local builds. A staging or production build without VITE_BUILD_ID now fails in scripts/generate-runtime-config.ts instead of shipping the placeholder that admission refused.", + "compatibilityWindow": "No runtime document or wire format changes: BUILD_ID was already local-build whenever VITE_BUILD_ID was unset.", + "rollback": "Restore defaultValue null on VITE_BUILD_ID in src/contracts/env.ts and drop the public-target check in scripts/generate-runtime-config.ts.", + "owner": "frontend-platform" } ] } diff --git a/scripts/generate-runtime-config.ts b/scripts/generate-runtime-config.ts index 1ae9e288..5de3e330 100644 --- a/scripts/generate-runtime-config.ts +++ b/scripts/generate-runtime-config.ts @@ -5,6 +5,7 @@ import process from "node:process"; import { DEPLOYMENT_TARGETS, isDeploymentTarget, + PUBLIC_TARGETS, type DeploymentTarget, } from "../src/contracts/deployment-admission.ts"; import { runtimeConfigV2ArtifactSchema } from "../src/contracts/release-artifacts.ts"; @@ -64,7 +65,12 @@ export async function generateRuntimeConfig( ) { draft["RELEASE_MANIFEST_URL"] = `${basePath}${manifestUrl.slice(1)}`; } - const buildId = environment["VITE_BUILD_ID"] ?? "local-build"; + // F-6. A public build without its own identity would ship the local + // placeholder; fail here instead of at admission. + if (PUBLIC_TARGETS.has(target) && !environment["VITE_BUILD_ID"]) { + throw new Error(`${profilePath}: a ${target} build requires VITE_BUILD_ID`); + } + const buildId = environment["VITE_BUILD_ID"] || "local-build"; const releaseId = environment["RELEASE_ID"] ?? "local-release"; draft["BUILD_ID"] = buildId; draft["RELEASE_ID"] = releaseId; diff --git a/src/contracts/deployment-admission.ts b/src/contracts/deployment-admission.ts index 09fd3ae3..718b88e9 100644 --- a/src/contracts/deployment-admission.ts +++ b/src/contracts/deployment-admission.ts @@ -31,7 +31,7 @@ export type DeploymentTarget = (typeof DEPLOYMENT_TARGETS)[number]; * rule set; `local` and `development` only have to be honest about what they * are. */ -const PUBLIC_TARGETS: ReadonlySet = new Set([ +export const PUBLIC_TARGETS: ReadonlySet = new Set([ "staging", "production", ]); diff --git a/src/contracts/env.ts b/src/contracts/env.ts index b9905a3b..56c63159 100644 --- a/src/contracts/env.ts +++ b/src/contracts/env.ts @@ -40,7 +40,10 @@ export type EnvironmentDefinition = Readonly<{ }>; export const ENV_REGISTRY = Object.freeze({ - VITE_BUILD_ID: build("public-metadata", true, null), + // F-6. Required: a staging or production build fails without it + // (scripts/generate-runtime-config.ts). Local and development builds fall + // back to the placeholder, which admission refuses for public targets. + VITE_BUILD_ID: build("public-metadata", true, "local-build"), VITE_COMMIT_SHA: build("public-metadata", false, "local"), VITE_ROUTER_BASE_PATH: build("compile-time", true, "/"), VITE_RUNTIME_CONFIG_URL: build("compile-time", true, "/config.json"), diff --git a/tests/unit/deployment-admission.test.ts b/tests/unit/deployment-admission.test.ts index 2d3c57cb..6bf40263 100644 --- a/tests/unit/deployment-admission.test.ts +++ b/tests/unit/deployment-admission.test.ts @@ -11,6 +11,7 @@ import { isDeploymentTarget, type AdmissionInput, } from "../../src/contracts/deployment-admission.ts"; +import { ENV_REGISTRY, getBuildConfig } from "../../src/contracts/env.ts"; import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts"; import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts"; @@ -195,6 +196,32 @@ describe("runtime config profiles", () => { ).rejects.toThrow(/runtime config is invalid/u); }); + it("refuses a staging or production build without VITE_BUILD_ID (F-6)", async () => { + for (const target of ["staging", "production"] as const) { + await expect( + generateRuntimeConfig(target, { RELEASE_ID: "r-1" }), + ).rejects.toThrow(/VITE_BUILD_ID/u); + await expect( + generateRuntimeConfig(target, { VITE_BUILD_ID: "", RELEASE_ID: "r-1" }), + ).rejects.toThrow(/VITE_BUILD_ID/u); + } + }); + + it("declares the build defaults that getBuildConfig applies (F-6)", () => { + const applied = getBuildConfig({}); + expect({ + VITE_BUILD_ID: ENV_REGISTRY.VITE_BUILD_ID.defaultValue, + VITE_COMMIT_SHA: ENV_REGISTRY.VITE_COMMIT_SHA.defaultValue, + VITE_ROUTER_BASE_PATH: ENV_REGISTRY.VITE_ROUTER_BASE_PATH.defaultValue, + VITE_RUNTIME_CONFIG_URL: ENV_REGISTRY.VITE_RUNTIME_CONFIG_URL.defaultValue, + }).toEqual({ + VITE_BUILD_ID: applied.buildId, + VITE_COMMIT_SHA: applied.commitSha, + VITE_ROUTER_BASE_PATH: applied.routerBasePath, + VITE_RUNTIME_CONFIG_URL: applied.runtimeConfigUrl, + }); + }); + it("keeps a developer build from carrying a released identity by default", async () => { const config = await generateRuntimeConfig("local", {}); expect(config["BUILD_ID"]).toBe("local-build");