문제: 1105/12-04 뒤 빌드는 `RUN_OUTPUT_ROOT` 아래에 쓰는데, check:bundle의 두 단계(`generate-supply-chain.ts`, `check-bundle.ts`)는 이 변수를 읽지 않고 checkout의 `dist`와 `artifacts/`를 읽는다. 셸에 이 변수를 둔 채 빌드와 check:bundle을 돌리면 예산을 3,504 B 넘는 새 빌드 대신 이전 빌드를 재서 PASS한다(리뷰 12-R2). ci:gate의 신선도 검사도 bundle.json을 check:bundle이 다시 쓰므로 막지 못한다. 고른 방법: `scripts/lib/run-isolation.ts`에 `checkoutBuildReadFailure`를 두고, 두 스크립트가 무엇을 읽기 전에 부른다. 출력 루트가 `.`이 아니면 변수 값과 이유를 적고 exit 1로 멈춘다. `.`(Playwright 설정이 run ID 없이 web server에 넘기는 값)과 빈 값은 그대로 돈다. 그래서 `RUN_OUTPUT_ROOT=.tmp/x corepack pnpm ci:gate -- FE-GATE-012`도 check-bundle 단계에서 변수 이름을 적고 실패한다. 버린 대안: ci:gate가 시작 전에 거절하기(리뷰 문서 (b)). 12-R2처럼 check:bundle을 직접 돌리는 경우를 막지 못한다. 두 스크립트가 같은 루트를 읽게 하기(c)는 supply-chain 산출물 전부와 CI upload 경로를 함께 옮겨야 한다. 위험·한계: - FE-GATE-012는 빌드 단계를 끝까지 돈 뒤 check-bundle에서 실패한다. 빌드 시간만큼 늦게 알린다. - 같은 모양일 수 있는 `check:app-build-input:bundle`, `check:optional-recipes --require-dist`, release candidate 조립은 보지 않았다. FE-GATE-012에서는 check-bundle이 먼저 실패해 거기까지 가지 않는다. - 디버깅으로 변수를 둔 사람은 check:bundle 전에 지워야 한다(문서에 적음). - 이 노트북에서는 실행하지 못했다. 검증: desktop batch에서 확인. node scripts/run-vitest.ts run tests/unit/check-bundle-output.test.ts tests/unit/run-isolation.test.ts 리뷰 12-R2 명령(stale-bundle-rc=1, stderr에 RUN_OUTPUT_ROOT), check:types, lint, verify:documentation, ci:gate FE-GATE-012 Refs: 1106/12-02
160 lines
4.7 KiB
TypeScript
160 lines
4.7 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
import {
|
|
describeBundleBudgetFailures,
|
|
evaluateBundleBudget,
|
|
} from "./lib/performance-budgets.ts";
|
|
import {
|
|
bundleOutputInventoryArtifactSchema,
|
|
bundlePerformanceArtifactSchema,
|
|
} from "./contracts/release-artifacts.ts";
|
|
import { classifyViteJavascript } from "./lib/classify-vite-bundle.ts";
|
|
import { checkoutBuildReadFailure } from "./lib/run-isolation.ts";
|
|
import { writeValidatedJsonArtifact } from "./lib/validated-json-artifact.ts";
|
|
|
|
type ViteManifest = Record<
|
|
string,
|
|
{ file: string; isEntry?: boolean; imports?: string[] }
|
|
>;
|
|
type BundleBudgets = {
|
|
initialJsGzipBytes: number;
|
|
initialJsFiles: number;
|
|
lazyChunkGzipBytes: number;
|
|
};
|
|
|
|
// 1106/12-02. This reads dist/.vite/manifest.json and the inventory
|
|
// scripts/generate-supply-chain.ts made of dist. Under RUN_OUTPUT_ROOT the
|
|
// build wrote elsewhere, and this passed a build over budget on the earlier
|
|
// one the checkout still held.
|
|
const outputRootFailure = checkoutBuildReadFailure("scripts/check-bundle.ts");
|
|
if (outputRootFailure !== undefined) {
|
|
process.stderr.write(`${outputRootFailure}\n`);
|
|
process.exit(1);
|
|
}
|
|
|
|
const report = bundleOutputInventoryArtifactSchema.parse(
|
|
JSON.parse(await readFile("artifacts/performance/bundle.json", "utf8")) as unknown,
|
|
);
|
|
const viteManifest = JSON.parse(
|
|
await readFile("dist/.vite/manifest.json", "utf8"),
|
|
) as ViteManifest;
|
|
const budgets = JSON.parse(
|
|
await readFile("config/performance/budgets.json", "utf8"),
|
|
).bundle as BundleBudgets;
|
|
|
|
const outputByPath = new Map(
|
|
report.outputs.map((output) => [output.path.replace(/^dist\//, ""), output]),
|
|
);
|
|
const classification = classifyViteJavascript(viteManifest);
|
|
const initialJsGzipBytes = classification.initialFiles.reduce(
|
|
(total, file) => total + (outputByPath.get(file)?.gzipBytes ?? 0),
|
|
0,
|
|
);
|
|
const lazyChunks = classification.lazyFiles.map((file) => ({
|
|
path: file,
|
|
gzipBytes: outputByPath.get(file)?.gzipBytes ?? 0,
|
|
}));
|
|
const missingOutputs = [
|
|
...classification.initialFiles,
|
|
...classification.lazyFiles,
|
|
].filter((file) => !outputByPath.has(file));
|
|
const measurements = {
|
|
initialJsGzipBytes,
|
|
initialJsFiles: classification.initialFiles.length,
|
|
lazyChunks,
|
|
};
|
|
const result = evaluateBundleBudget(measurements, budgets);
|
|
const fixtures = [
|
|
{
|
|
name: "initial-js-over-budget",
|
|
passed:
|
|
!evaluateBundleBudget(
|
|
{
|
|
initialJsGzipBytes: budgets.initialJsGzipBytes + 1,
|
|
initialJsFiles: 0,
|
|
lazyChunks: [],
|
|
},
|
|
budgets,
|
|
).passed,
|
|
},
|
|
{
|
|
name: "lazy-chunk-over-budget",
|
|
passed:
|
|
!evaluateBundleBudget(
|
|
{
|
|
initialJsGzipBytes: 0,
|
|
initialJsFiles: 0,
|
|
lazyChunks: [
|
|
{
|
|
path: "fixture.js",
|
|
gzipBytes: budgets.lazyChunkGzipBytes + 1,
|
|
},
|
|
],
|
|
},
|
|
budgets,
|
|
).passed,
|
|
},
|
|
{
|
|
name: "initial-files-over-budget",
|
|
passed:
|
|
!evaluateBundleBudget(
|
|
{
|
|
initialJsGzipBytes: 0,
|
|
initialJsFiles: budgets.initialJsFiles + 1,
|
|
lazyChunks: [],
|
|
},
|
|
budgets,
|
|
).passed,
|
|
},
|
|
];
|
|
const passed =
|
|
result.passed &&
|
|
fixtures.every((fixture) => fixture.passed) &&
|
|
classification.missingImports.length === 0 &&
|
|
missingOutputs.length === 0;
|
|
const completedReport = {
|
|
...report,
|
|
measurements,
|
|
classification,
|
|
missingOutputs,
|
|
thresholds: budgets,
|
|
results: result,
|
|
fixtures,
|
|
passed,
|
|
};
|
|
|
|
await writeValidatedJsonArtifact({
|
|
path: "artifacts/performance/bundle.json",
|
|
schema: bundlePerformanceArtifactSchema,
|
|
value: completedReport,
|
|
});
|
|
// 1103/15-03. The budget and the manifest integrity fail for different
|
|
// reasons, so each says what failed and by how much.
|
|
if (!passed) {
|
|
const budgetFailures = describeBundleBudgetFailures(measurements, budgets);
|
|
if (budgetFailures.length > 0) {
|
|
process.stderr.write(
|
|
`Bundle budget failed (config/performance/budgets.json):\n${budgetFailures
|
|
.map((line) => ` ${line}\n`)
|
|
.join("")}`,
|
|
);
|
|
}
|
|
const integrityFailures = [
|
|
...classification.missingImports.map((key) => `manifest import without an entry: ${key}`),
|
|
...missingOutputs.map((file) => `output missing from the inventory: ${file}`),
|
|
...fixtures
|
|
.filter((fixture) => !fixture.passed)
|
|
.map((fixture) => `budget self-check did not fail: ${fixture.name}`),
|
|
];
|
|
if (integrityFailures.length > 0) {
|
|
process.stderr.write(
|
|
`Bundle manifest integrity failed:\n${integrityFailures.map((line) => ` ${line}\n`).join("")}`,
|
|
);
|
|
}
|
|
process.exit(1);
|
|
}
|
|
process.stdout.write(
|
|
`Bundle budget: PASS (initial JS ${initialJsGzipBytes} / ${budgets.initialJsGzipBytes} gzip bytes, ` +
|
|
`${measurements.initialJsFiles} / ${budgets.initialJsFiles} files)\n`,
|
|
);
|