fix(contracts): fail public builds without VITE_BUILD_ID and record the local default (F-6, 13-15)
ENV_REGISTRY called VITE_BUILD_ID required with no default while every reader fell back to local-build. Staging and production builds now fail without it; local builds keep the placeholder, and the registry records that default. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9e616d3a06
commit
063375ed04
@@ -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.",
|
"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.",
|
"rollback": "Restore the previous telemetryEvent string on QUERY_CACHE_FAILURE in src/contracts/errors.ts and widen ErrorObservationEvent back to string.",
|
||||||
"owner": "frontend-platform"
|
"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"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import process from "node:process";
|
|||||||
import {
|
import {
|
||||||
DEPLOYMENT_TARGETS,
|
DEPLOYMENT_TARGETS,
|
||||||
isDeploymentTarget,
|
isDeploymentTarget,
|
||||||
|
PUBLIC_TARGETS,
|
||||||
type DeploymentTarget,
|
type DeploymentTarget,
|
||||||
} from "../src/contracts/deployment-admission.ts";
|
} from "../src/contracts/deployment-admission.ts";
|
||||||
import { runtimeConfigV2ArtifactSchema } from "../src/contracts/release-artifacts.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)}`;
|
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";
|
const releaseId = environment["RELEASE_ID"] ?? "local-release";
|
||||||
draft["BUILD_ID"] = buildId;
|
draft["BUILD_ID"] = buildId;
|
||||||
draft["RELEASE_ID"] = releaseId;
|
draft["RELEASE_ID"] = releaseId;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export type DeploymentTarget = (typeof DEPLOYMENT_TARGETS)[number];
|
|||||||
* rule set; `local` and `development` only have to be honest about what they
|
* rule set; `local` and `development` only have to be honest about what they
|
||||||
* are.
|
* are.
|
||||||
*/
|
*/
|
||||||
const PUBLIC_TARGETS: ReadonlySet<DeploymentTarget> = new Set([
|
export const PUBLIC_TARGETS: ReadonlySet<DeploymentTarget> = new Set([
|
||||||
"staging",
|
"staging",
|
||||||
"production",
|
"production",
|
||||||
]);
|
]);
|
||||||
|
|||||||
@@ -40,7 +40,10 @@ export type EnvironmentDefinition = Readonly<{
|
|||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const ENV_REGISTRY = Object.freeze({
|
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_COMMIT_SHA: build("public-metadata", false, "local"),
|
||||||
VITE_ROUTER_BASE_PATH: build("compile-time", true, "/"),
|
VITE_ROUTER_BASE_PATH: build("compile-time", true, "/"),
|
||||||
VITE_RUNTIME_CONFIG_URL: build("compile-time", true, "/config.json"),
|
VITE_RUNTIME_CONFIG_URL: build("compile-time", true, "/config.json"),
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
isDeploymentTarget,
|
isDeploymentTarget,
|
||||||
type AdmissionInput,
|
type AdmissionInput,
|
||||||
} from "../../src/contracts/deployment-admission.ts";
|
} from "../../src/contracts/deployment-admission.ts";
|
||||||
|
import { ENV_REGISTRY, getBuildConfig } from "../../src/contracts/env.ts";
|
||||||
import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts";
|
import { runtimeConfigV2ArtifactSchema } from "../../src/contracts/release-artifacts.ts";
|
||||||
import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts";
|
import { generateRuntimeConfig } from "../../scripts/generate-runtime-config.ts";
|
||||||
|
|
||||||
@@ -195,6 +196,32 @@ describe("runtime config profiles", () => {
|
|||||||
).rejects.toThrow(/runtime config is invalid/u);
|
).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 () => {
|
it("keeps a developer build from carrying a released identity by default", async () => {
|
||||||
const config = await generateRuntimeConfig("local", {});
|
const config = await generateRuntimeConfig("local", {});
|
||||||
expect(config["BUILD_ID"]).toBe("local-build");
|
expect(config["BUILD_ID"]).toBe("local-build");
|
||||||
|
|||||||
Reference in New Issue
Block a user