frontend-quality-gates / merge / static checks (pull_request) Successful in 1m15s
frontend-quality-gates / merge / tests (pull_request) Successful in 13m20s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 5m16s
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
스크립트 22곳이 argv[1]로 직접 실행을 판정해서, checkout 경로에 공백·한글이 있거나 symlink 절대 경로로 부르면 18곳이 검사 없이 rc=0으로 끝날 수 있다. merge 게이트 명령 셋이 여기 걸린다. isEntryModule(import.meta) 하나로 바꾸고, process.argv 둘째 값 읽기와 helper 밖 판정은 시험으로 막는다. 맨 import.meta.main은 그 값이 없는 Node에서 같은 거짓 통과가 나서 버렸다. realpath 비교는 같은 판정의 사본 22개가 남고, argv 값의 쓰임을 따라가는 시험은 return·대입으로 피할 수 있어 버렸다. 위험·한계: 건너뛰던 검사가 실패하기 시작할 수 있고, 실행 판정이 아닌 process.argv[1] 읽기도 실패한다. import.meta.main이 없는 Node에서 직접 실행하거나 import하면 실패한다. verify-extreme-scale도 그 Node에서는 rc=2보다 먼저 rc=1로 끝나고, 이전 기록(passed일 수 있다)이 그대로 남아 종료 code로 본다. 코드로 읽은 것이고 그 Node로 돌려 보지 않았다. 막는 시험은 process·argv 별칭과 계산한 index를 따라가지 않는다. 검증(노트북, main으로 옮기기 전 트리 a806088b): 새 시험 고치기 전 실패, 고친 뒤 통과. test:unit 3707개, types, lint, check:ci, verify:documentation rc=0. desktop merge 단계는 따로 확인한다. Refs: REV-FE-0040
349 lines
11 KiB
TypeScript
349 lines
11 KiB
TypeScript
import { createHash } from "node:crypto";
|
|
import { mkdir, readFile } from "node:fs/promises";
|
|
|
|
import {
|
|
verifyCompatibilityTuple,
|
|
type CompatibilityTuple,
|
|
} from "../src/contracts/compatibility.ts";
|
|
import type { InstalledContractPackageIdentity } from "../src/contracts/external-contract-runtime.ts";
|
|
import {
|
|
parseBuildManifestArtifact,
|
|
parseReleaseArtifact,
|
|
parseRuntimeConfigArtifact,
|
|
projectReleaseTokens,
|
|
type BuildManifestArtifact,
|
|
type ReleaseArtifact,
|
|
type RuntimeConfigArtifact,
|
|
} from "../src/contracts/release-artifacts.ts";
|
|
import { EXPECTED_CONTRACT_SET_PACKAGES } from "../src/features/installed-contract-contributions.ts";
|
|
import {
|
|
ROUTE_REGISTRY,
|
|
ROUTE_RUNTIME_CONTRACT,
|
|
} from "../src/features/installed-feature-contracts.ts";
|
|
import { isEntryModule } from "./lib/entry-module.ts";
|
|
import { assertMatchesJsonSchema } from "./lib/json-schema.ts";
|
|
import {
|
|
CANONICAL_VITE_MANIFEST_PATH,
|
|
findRouteChunk,
|
|
verifyBuildManifestOutputs,
|
|
} from "./lib/build-manifest-outputs.ts";
|
|
import { verifyReleaseRuntimeCoherence } from "./lib/release-runtime-coherence.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
import { releaseVerificationArtifactSchema } from "./contracts/release-artifacts.ts";
|
|
|
|
type CoherenceFixture = Readonly<{
|
|
name: string;
|
|
expectedCompatible: boolean;
|
|
frontend: CompatibilityTuple;
|
|
runtime: CompatibilityTuple;
|
|
}>;
|
|
type RuntimeConfigDocument = RuntimeConfigArtifact &
|
|
Readonly<{ BUILD_ID: string; RELEASE_ID: string }>;
|
|
type ViteManifestEntry = Readonly<{
|
|
file: string;
|
|
name?: string;
|
|
isDynamicEntry?: boolean;
|
|
}>;
|
|
|
|
export type ReleaseArtifactReader = (path: string) => Promise<unknown>;
|
|
|
|
export type ReleaseArtifactsCoherenceOptions = Readonly<{
|
|
readArtifact?: ReleaseArtifactReader;
|
|
contractPackages?: readonly InstalledContractPackageIdentity[];
|
|
paths?: Readonly<{ release: string; runtime: string }>;
|
|
}>;
|
|
|
|
const DEFAULT_RELEASE_COHERENCE_PATHS = Object.freeze({
|
|
release: "dist/release-manifest.json",
|
|
runtime: "dist/config.json",
|
|
});
|
|
|
|
async function readJsonArtifact(path: string): Promise<unknown> {
|
|
return JSON.parse(await readFile(path, "utf8"));
|
|
}
|
|
|
|
export async function verifyReleaseArtifactsCoherence(
|
|
options: ReleaseArtifactsCoherenceOptions = {},
|
|
) {
|
|
const readArtifact = options.readArtifact ?? readJsonArtifact;
|
|
const paths = options.paths ?? DEFAULT_RELEASE_COHERENCE_PATHS;
|
|
const release = parseReleaseDocument(await readArtifact(paths.release));
|
|
const runtime = parseRuntimeConfigDocument(
|
|
await readArtifact(paths.runtime),
|
|
);
|
|
const coherence = await verifyReleaseRuntimeCoherence({
|
|
release,
|
|
runtime,
|
|
contractPackages:
|
|
options.contractPackages ?? EXPECTED_CONTRACT_SET_PACKAGES,
|
|
});
|
|
return Object.freeze({ release, runtime, coherence });
|
|
}
|
|
|
|
async function main(): Promise<void> {
|
|
const fixturesDocument = parseFixturesDocument(
|
|
JSON.parse(
|
|
await readFile("config/release/coherence-fixtures.json", "utf8"),
|
|
),
|
|
);
|
|
const verifiedRuntime = await verifyReleaseArtifactsCoherence();
|
|
const {
|
|
release,
|
|
coherence: artifactComparison,
|
|
} = verifiedRuntime;
|
|
const buildManifestDocument: unknown = JSON.parse(
|
|
await readFile("artifacts/release/build-manifest.json", "utf8"),
|
|
);
|
|
assertMatchesJsonSchema(
|
|
JSON.parse(
|
|
await readFile("config/schemas/artifacts/build-manifest.schema.json", "utf8"),
|
|
),
|
|
buildManifestDocument,
|
|
"build manifest",
|
|
);
|
|
const buildManifest = parseBuildManifestDocument(buildManifestDocument);
|
|
const runtimeConfigJsonSchema = requireRecord(
|
|
JSON.parse(await readFile("dist/runtime-config.schema.json", "utf8")),
|
|
"runtime config JSON schema",
|
|
);
|
|
const viteManifest = await readFile(CANONICAL_VITE_MANIFEST_PATH, "utf8");
|
|
const viteManifestObject = parseViteManifest(JSON.parse(viteManifest));
|
|
const actualAssetManifestHash = createHash("sha256")
|
|
.update(viteManifest)
|
|
.digest("hex");
|
|
|
|
const artifactMismatches: string[] = [...artifactComparison.mismatches];
|
|
artifactMismatches.push(...(await verifyBuildManifestOutputs(buildManifest)));
|
|
for (const [token, value] of Object.entries(projectReleaseTokens(release))) {
|
|
if (token !== "schemaVersion" && (typeof value !== "string" || value.length === 0)) {
|
|
artifactMismatches.push(`releaseToken:${token}`);
|
|
}
|
|
}
|
|
if (
|
|
typeof release.builtAt !== "string" ||
|
|
!Number.isFinite(Date.parse(release.builtAt))
|
|
) {
|
|
artifactMismatches.push("releaseToken:builtAtFormat");
|
|
}
|
|
if (release.assetManifestHash !== actualAssetManifestHash) {
|
|
artifactMismatches.push("assetManifestContent");
|
|
}
|
|
if (
|
|
runtimeConfigJsonSchema.$schema !== "https://json-schema.org/draft/2020-12/schema" ||
|
|
runtimeConfigJsonSchema.type !== "object" ||
|
|
!runtimeConfigJsonSchema.properties
|
|
) {
|
|
artifactMismatches.push("runtimeConfigSchema");
|
|
}
|
|
if (
|
|
buildManifest.outputs.runtimeConfigSchema !==
|
|
"dist/runtime-config.schema.json"
|
|
) {
|
|
artifactMismatches.push("buildManifest:runtimeConfigSchema");
|
|
}
|
|
for (const [token, buildValue, releaseValue] of [
|
|
["buildId", buildManifest.buildId, release.buildId],
|
|
["commitSha", buildManifest.commitSha, release.commitSha],
|
|
["releaseId", buildManifest.releaseId, release.releaseId],
|
|
["generatedAt", buildManifest.generatedAt, release.builtAt],
|
|
] as const) {
|
|
if (buildValue !== releaseValue) {
|
|
artifactMismatches.push(`buildManifest:${token}`);
|
|
}
|
|
}
|
|
|
|
const expectedChunkIds = new Set(
|
|
Object.values(ROUTE_REGISTRY).map((definition) => definition.chunkId),
|
|
);
|
|
const actualChunkIds = new Set(Object.keys(release.routeChunks));
|
|
for (const chunkId of expectedChunkIds) {
|
|
if (!actualChunkIds.has(chunkId)) {
|
|
artifactMismatches.push(`routeChunk:missing:${chunkId}`);
|
|
}
|
|
}
|
|
for (const chunkId of actualChunkIds) {
|
|
if (!expectedChunkIds.has(chunkId)) {
|
|
artifactMismatches.push(`routeChunk:orphan:${chunkId}`);
|
|
}
|
|
}
|
|
const runtimeContracts: Readonly<Record<string, { moduleId: string }>> =
|
|
ROUTE_RUNTIME_CONTRACT;
|
|
for (const definition of Object.values(ROUTE_REGISTRY)) {
|
|
const viteEntry = findRouteChunk(
|
|
viteManifestObject,
|
|
definition.routeId,
|
|
runtimeContracts[definition.routeId]?.moduleId,
|
|
);
|
|
const routeAsset = release.routeChunks[definition.chunkId];
|
|
if ("error" in viteEntry || routeAsset !== viteEntry.file) {
|
|
artifactMismatches.push(`routeChunk:mismatch:${definition.chunkId}`);
|
|
continue;
|
|
}
|
|
if (
|
|
buildManifest.outputs.routeChunks[definition.chunkId] !== routeAsset
|
|
) {
|
|
artifactMismatches.push(`buildManifest:routeChunk:${definition.chunkId}`);
|
|
}
|
|
try {
|
|
await readFile(`dist/${routeAsset}`);
|
|
} catch {
|
|
artifactMismatches.push(`routeChunk:file:${definition.chunkId}`);
|
|
}
|
|
}
|
|
|
|
const fixtures = fixturesDocument.fixtures.map((fixture) => {
|
|
const result = verifyCompatibilityTuple({
|
|
frontend: fixture.frontend,
|
|
runtime: fixture.runtime,
|
|
});
|
|
return {
|
|
name: fixture.name,
|
|
expectedCompatible: fixture.expectedCompatible,
|
|
actualCompatible: result.compatible,
|
|
mismatches: result.mismatches,
|
|
passed: result.compatible === fixture.expectedCompatible,
|
|
};
|
|
});
|
|
const artifact = {
|
|
checked: true,
|
|
compatible: artifactComparison.compatible && artifactMismatches.length === 0,
|
|
mismatches: artifactMismatches,
|
|
releaseId: release.releaseId,
|
|
};
|
|
const passed = artifact.compatible && fixtures.every((fixture) => fixture.passed);
|
|
const report = {
|
|
schemaVersion: 1,
|
|
generatedAt: release.builtAt,
|
|
artifact,
|
|
fixtures,
|
|
passed,
|
|
};
|
|
|
|
await mkdir("artifacts/release", { recursive: true });
|
|
await writeValidatedJsonArtifact({
|
|
path: "artifacts/release/verification.json",
|
|
schema: releaseVerificationArtifactSchema,
|
|
value: report,
|
|
});
|
|
|
|
if (!passed) {
|
|
process.stderr.write(
|
|
`Release coherence failed: ${artifactMismatches.join(", ") || "fixture"}\n`,
|
|
);
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Release coherence: PASS (${fixtures.length - 1} mixed fixtures rejected)\n`,
|
|
);
|
|
}
|
|
|
|
if (isEntryModule(import.meta)) {
|
|
await main();
|
|
}
|
|
|
|
function parseFixturesDocument(value: unknown): Readonly<{
|
|
fixtures: readonly CoherenceFixture[];
|
|
}> {
|
|
const document = requireRecord(value, "release coherence fixtures");
|
|
if (!Array.isArray(document.fixtures)) {
|
|
throw new TypeError("release coherence fixtures must be an array");
|
|
}
|
|
return {
|
|
fixtures: document.fixtures.map((candidate, index) => {
|
|
const fixture = requireRecord(candidate, `release fixture ${index}`);
|
|
if (
|
|
typeof fixture.name !== "string" ||
|
|
typeof fixture.expectedCompatible !== "boolean"
|
|
) {
|
|
throw new TypeError(`Invalid release fixture metadata: ${index}`);
|
|
}
|
|
return {
|
|
name: fixture.name,
|
|
expectedCompatible: fixture.expectedCompatible,
|
|
frontend: parseCompatibilityTuple(
|
|
fixture.frontend,
|
|
`release fixture ${index}.frontend`,
|
|
),
|
|
runtime: parseCompatibilityTuple(
|
|
fixture.runtime,
|
|
`release fixture ${index}.runtime`,
|
|
),
|
|
};
|
|
}),
|
|
};
|
|
}
|
|
|
|
function parseReleaseDocument(value: unknown): ReleaseArtifact {
|
|
return parseReleaseArtifact(value);
|
|
}
|
|
|
|
function parseRuntimeConfigDocument(value: unknown): RuntimeConfigDocument {
|
|
const document = parseRuntimeConfigArtifact(value);
|
|
return {
|
|
...document,
|
|
BUILD_ID: requireString(document.BUILD_ID, "runtime config BUILD_ID"),
|
|
RELEASE_ID: requireString(document.RELEASE_ID, "runtime config RELEASE_ID"),
|
|
};
|
|
}
|
|
|
|
function parseBuildManifestDocument(value: unknown): BuildManifestArtifact {
|
|
return parseBuildManifestArtifact(value);
|
|
}
|
|
|
|
function parseCompatibilityTuple(value: unknown, label: string): CompatibilityTuple {
|
|
const document = requireRecord(value, label);
|
|
return {
|
|
buildId: requireString(document.buildId, `${label}.buildId`),
|
|
configSchemaVersion: requireString(
|
|
document.configSchemaVersion,
|
|
`${label}.configSchemaVersion`,
|
|
),
|
|
apiContractVersion: requireString(
|
|
document.apiContractVersion,
|
|
`${label}.apiContractVersion`,
|
|
),
|
|
assetManifestHash: requireString(
|
|
document.assetManifestHash,
|
|
`${label}.assetManifestHash`,
|
|
),
|
|
releaseId: requireString(document.releaseId, `${label}.releaseId`),
|
|
};
|
|
}
|
|
|
|
function parseViteManifest(
|
|
value: unknown,
|
|
): Readonly<Record<string, ViteManifestEntry>> {
|
|
const document = requireRecord(value, "Vite manifest");
|
|
const entries: Record<string, ViteManifestEntry> = {};
|
|
for (const [key, candidate] of Object.entries(document)) {
|
|
const entry = requireRecord(candidate, `Vite manifest entry ${key}`);
|
|
entries[key] = {
|
|
file: requireString(entry.file, `Vite manifest entry ${key}.file`),
|
|
...(typeof entry.name === "string" ? { name: entry.name } : {}),
|
|
...(typeof entry.isDynamicEntry === "boolean"
|
|
? { isDynamicEntry: entry.isDynamicEntry }
|
|
: {}),
|
|
};
|
|
}
|
|
return entries;
|
|
}
|
|
|
|
function requireString(value: unknown, label: string): string {
|
|
if (typeof value !== "string" || value.length === 0) {
|
|
throw new TypeError(`${label} must be a non-empty string`);
|
|
}
|
|
return value;
|
|
}
|
|
|
|
function requireRecord(
|
|
value: unknown,
|
|
label: string,
|
|
): Record<string, unknown> {
|
|
if (!isRecord(value)) throw new TypeError(`${label} must be an object`);
|
|
return value;
|
|
}
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
}
|