This reverts commit411c9338c6. 문제: #55(b4895894)가 main run 376의 FE-GATE-030(browser file/storage 제거 드릴)을 깨서 411c9338(#64)로 통째로 되돌렸다. #55의 검사기 진단과 시험 빈틈 고침 12커밋이 main에 없다. 고른 방법: 되돌림을 되돌려 #55를 그대로 다시 넣고, 드릴을 깬 원인은 다음 커밋에서 따로 고친다. 리뷰어가 이 커밋이 #55와 같은지 트리로 볼 수 있다. 이 커밋의 트리는b4895894트리에 그 뒤 main에 들어온 #63·#65만 더한 것이다(git diffb4895894<이 커밋>: docs/ledger 두 파일, cross-context-invalidation adapter 한 파일과 시험 두 파일). 버린 대안: #55 커밋 12개 cherry-pick.71606ff1merge의 충돌 해소분을 다시 풀어야 하고 결과 트리를 b4895894와 대조하기 어렵다. 위험·한계: 이 커밋만으로는 main 단계의 FE-GATE-030이 run 376처럼 실패한다(같은 트리 내용). PR 단계 게이트는 돈다. 검증: 다음 커밋 본문에 적는다. 그 커밋의 새 단언을 이 커밋의 검사기에 돌리면 실패한다(RED). Refs: #55, #64
192 lines
6.4 KiB
TypeScript
192 lines
6.4 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { mkdir, readFile, rm } from "node:fs/promises";
|
|
import process from "node:process";
|
|
import { z } from "zod";
|
|
|
|
import {
|
|
ROUTE_REGISTRY,
|
|
ROUTE_RUNTIME_CONTRACT,
|
|
} from "../src/features/installed-feature-contracts.ts";
|
|
import {
|
|
buildManifestArtifactSchema,
|
|
jsonSchemaDocumentArtifactSchema,
|
|
moduleInventoryArtifactSchema,
|
|
releaseManifestV2ArtifactSchema,
|
|
runtimeConfigV2ArtifactSchema,
|
|
} from "./contracts/release-artifacts.ts";
|
|
import { buildContractSet } from "./generate-contract-set.ts";
|
|
import {
|
|
assertCiBuildEnvironment,
|
|
buildDate,
|
|
} from "./lib/build-environment.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import { CANONICAL_VITE_MANIFEST_PATH, findRouteChunk } from "./lib/build-manifest-outputs.ts";
|
|
import { runOutputPath } from "./lib/run-isolation.ts";
|
|
|
|
assertCiBuildEnvironment(process.env);
|
|
// 1105/12-04. With RUN_OUTPUT_ROOT set, this build's dist and artifacts are
|
|
// under that folder. The manifest still records `dist`, `artifacts/...`:
|
|
// its paths are relative to the folder the build wrote, which is the
|
|
// checkout when the variable is unset.
|
|
const at = (relativePath: string) => runOutputPath(relativePath);
|
|
type ViteManifestEntry = Readonly<{
|
|
file: string;
|
|
name?: string;
|
|
isDynamicEntry?: boolean;
|
|
}>;
|
|
|
|
const packageJson = parsePackageMetadata(
|
|
JSON.parse(await readFile("package.json", "utf8")),
|
|
);
|
|
const packageManagerVersion = packageJson.packageManager.split("@").at(-1);
|
|
const buildId = process.env.VITE_BUILD_ID ?? "local-build";
|
|
const commitSha = process.env.VITE_COMMIT_SHA ?? "local";
|
|
const releaseId = process.env.RELEASE_ID ?? "local-release";
|
|
const runnerImage = process.env.CI_RUNNER_IMAGE ?? `${process.platform}-${process.arch}`;
|
|
const buildTime = buildDate(process.env);
|
|
const builtAt = buildTime.toISOString();
|
|
const viteManifest = await readFile(at(CANONICAL_VITE_MANIFEST_PATH), "utf8");
|
|
const viteManifestObject = parseViteManifest(JSON.parse(viteManifest));
|
|
const moduleInventory = await readFile(
|
|
at("dist/.vite/module-inventory.json"),
|
|
"utf8",
|
|
);
|
|
const moduleInventoryDocument = moduleInventoryArtifactSchema.parse(
|
|
JSON.parse(moduleInventory),
|
|
);
|
|
const moduleInventoryBytes = `${JSON.stringify(moduleInventoryDocument, null, 2)}\n`;
|
|
const assetManifestHash = createHash("sha256")
|
|
.update(viteManifest)
|
|
.digest("hex");
|
|
const moduleInventoryHash = createHash("sha256")
|
|
.update(moduleInventoryBytes)
|
|
.digest("hex");
|
|
const runtimeConfig = runtimeConfigV2ArtifactSchema.parse(
|
|
JSON.parse(await readFile(at("dist/config.json"), "utf8")),
|
|
);
|
|
const routeChunks: Record<string, string> = {};
|
|
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
|
ROUTE_RUNTIME_CONTRACT;
|
|
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
|
const chunk = findRouteChunk(
|
|
viteManifestObject,
|
|
definition.routeId,
|
|
runtimeContracts[definition.routeId]?.moduleId,
|
|
);
|
|
if ("error" in chunk) throw new Error(chunk.error);
|
|
routeChunks[definition.chunkId] = chunk.file;
|
|
}
|
|
const runtimeConfigJsonSchema = z.toJSONSchema(runtimeConfigV2ArtifactSchema);
|
|
|
|
runtimeConfig.BUILD_ID = buildId;
|
|
runtimeConfig.RELEASE_ID = releaseId;
|
|
|
|
const manifest = buildManifestArtifactSchema.parse({
|
|
schemaVersion: 1,
|
|
buildId,
|
|
commitSha,
|
|
releaseId,
|
|
moduleInventoryHash,
|
|
generatedAt: builtAt,
|
|
buildContext: {
|
|
nodeVersion: process.version,
|
|
packageManagerVersion,
|
|
runnerImage,
|
|
sourceDateEpoch: process.env.SOURCE_DATE_EPOCH ?? null,
|
|
},
|
|
outputs: {
|
|
directory: "dist",
|
|
viteManifest: CANONICAL_VITE_MANIFEST_PATH,
|
|
moduleInventory: "artifacts/quality/vite-module-inventory.json",
|
|
routeChunks,
|
|
runtimeConfigSchema: "dist/runtime-config.schema.json",
|
|
},
|
|
});
|
|
|
|
// §5.2 / §24.6 RC-3. The writer emits V2 only; the scalar API contract
|
|
// version has no writer source left.
|
|
const releaseManifest = releaseManifestV2ArtifactSchema.parse({
|
|
schemaVersion: 2,
|
|
appVersion: packageJson.version,
|
|
buildId,
|
|
commitSha,
|
|
configSchemaVersion: runtimeConfig.CONFIG_SCHEMA_VERSION,
|
|
assetManifestHash,
|
|
releaseId,
|
|
builtAt,
|
|
routeChunks,
|
|
contractSet: buildContractSet(),
|
|
});
|
|
|
|
await mkdir(at("artifacts/release"), { recursive: true });
|
|
await mkdir(at("artifacts/quality"), { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: at("artifacts/quality/vite-module-inventory.json"),
|
|
schema: moduleInventoryArtifactSchema,
|
|
value: moduleInventoryDocument,
|
|
});
|
|
await rm(at("dist/.vite/module-inventory.json"));
|
|
await writeValidatedJsonArtifact({
|
|
path: at("dist/config.json"),
|
|
schema: runtimeConfigV2ArtifactSchema,
|
|
value: runtimeConfig,
|
|
});
|
|
await writeValidatedJsonArtifact({
|
|
path: at("dist/release-manifest.json"),
|
|
schema: releaseManifestV2ArtifactSchema,
|
|
value: releaseManifest,
|
|
});
|
|
await writeValidatedJsonArtifact({
|
|
path: at("dist/runtime-config.schema.json"),
|
|
schema: jsonSchemaDocumentArtifactSchema,
|
|
value: runtimeConfigJsonSchema,
|
|
});
|
|
await writeValidatedJsonArtifact({
|
|
path: at("artifacts/release/runtime-config.schema.json"),
|
|
schema: jsonSchemaDocumentArtifactSchema,
|
|
value: runtimeConfigJsonSchema,
|
|
});
|
|
await writeValidatedJsonArtifact({
|
|
path: at("artifacts/release/build-manifest.json"),
|
|
schema: buildManifestArtifactSchema,
|
|
value: manifest,
|
|
});
|
|
|
|
function parsePackageMetadata(value: unknown): Readonly<{
|
|
version: string;
|
|
packageManager: string;
|
|
}> {
|
|
if (
|
|
!isRecord(value) ||
|
|
typeof value.version !== "string" ||
|
|
typeof value.packageManager !== "string"
|
|
) {
|
|
throw new TypeError("package.json release metadata is invalid");
|
|
}
|
|
return { version: value.version, packageManager: value.packageManager };
|
|
}
|
|
|
|
function parseViteManifest(
|
|
value: unknown,
|
|
): Readonly<Record<string, ViteManifestEntry>> {
|
|
if (!isRecord(value)) throw new TypeError("Vite manifest must be an object");
|
|
const entries: Record<string, ViteManifestEntry> = {};
|
|
for (const [key, candidate] of Object.entries(value)) {
|
|
if (!isRecord(candidate) || typeof candidate.file !== "string") {
|
|
throw new TypeError(`Invalid Vite manifest entry: ${key}`);
|
|
}
|
|
entries[key] = {
|
|
file: candidate.file,
|
|
...(typeof candidate.name === "string" ? { name: candidate.name } : {}),
|
|
...(typeof candidate.isDynamicEntry === "boolean"
|
|
? { isDynamicEntry: candidate.isDynamicEntry }
|
|
: {}),
|
|
};
|
|
}
|
|
return entries;
|
|
}
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
}
|