Merge pull request 'feat(scale): precache 상한을 기능 모양 기록에 재고 R9-D7 후보 ID를 태그로 적는다' (#44) from donghyeon.kang/fix/r9-precache-bound-diagnostics into main
frontend-quality-gates / merge / static checks (push) Canceled after 0s
frontend-quality-gates / merge / tests (push) Canceled after 0s
frontend-quality-gates / merge / browser tests (push) Canceled after 0s
frontend-quality-gates / FE-GATE-014 / config-compatibility (push) Canceled after 0s
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (push) Canceled after 0s
frontend-quality-gates / FE-GATE-026 / lab-performance (push) Canceled after 0s
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (push) Canceled after 0s
frontend-quality-gates / external-vulnerability-provider (push) Canceled after 0s
frontend-quality-gates / external-provenance-provider (push) Canceled after 0s
frontend-quality-gates / promote-verified-immutable-candidate (push) Canceled after 0s
frontend-quality-gates / deploy-promoted-release (push) Canceled after 0s
frontend-quality-gates / FE-GATE-019 / hosting-header (push) Canceled after 0s
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (push) Canceled after 0s
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (push) Canceled after 0s
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (push) Canceled after 0s
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (push) Canceled after 0s
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (push) Canceled after 0s
frontend-quality-gates / FE-GATE-018 / field-web-vitals (push) Canceled after 0s
frontend-quality-gates / FE-GATE-017 / diagram-review (push) Canceled after 0s
frontend-quality-gates / main / self-tests and removal drills (push) Canceled after 0s

This commit was merged in pull request #44.
This commit is contained in:
2026-11-13 08:28:36 +00:00
6 changed files with 198 additions and 26 deletions
+34 -9
View File
@@ -69,13 +69,8 @@ export async function collectStaticAssets(
const assets: StaticAssetManifestV1["assets"][number][] = [];
for (const relative of files.sort()) {
const base = path.basename(relative);
if (!relative.split(path.sep).join("/").startsWith(BUILD_ASSET_DIRECTORY)) {
continue;
}
if (EXCLUDED_FILES.has(base)) continue;
const contentType = CACHEABLE_EXTENSIONS[path.extname(base).toLowerCase()];
if (!contentType || !HASHED_NAME.test(base)) continue;
const contentType = precachedContentType(relative);
if (!contentType) continue;
const absolute = path.join(distDirectory, relative);
const bytes = await readFile(absolute);
@@ -99,12 +94,19 @@ export async function collectStaticAssets(
});
}
// 1112/06-02. The count and the bound, so the failure says how far over
// it is. Each generated feature adds its lazy chunks here: with the Service
// Worker on, the asset bound can come before the initial JavaScript budget.
if (assets.length > SERVICE_WORKER_BOUNDS.assets) {
throw new Error("Static asset count exceeds its bound.");
throw new Error(
`Static asset count ${assets.length} exceeds its bound ${SERVICE_WORKER_BOUNDS.assets} (SERVICE_WORKER_BOUNDS.assets, src/contracts/service-worker.ts): every hashed file under ${BUILD_ASSET_DIRECTORY} is precached.`,
);
}
const totalBytes = assets.reduce((sum, asset) => sum + asset.bytes, 0);
if (totalBytes > SERVICE_WORKER_BOUNDS.assetSetBytes) {
throw new Error("Static asset set exceeds its byte bound.");
throw new Error(
`Static asset set ${totalBytes} bytes exceeds its byte bound ${SERVICE_WORKER_BOUNDS.assetSetBytes} (SERVICE_WORKER_BOUNDS.assetSetBytes, src/contracts/service-worker.ts).`,
);
}
// SW-05. The canonical byte serialization lives in the shared runtime-neutral
@@ -133,6 +135,29 @@ export async function collectStaticAssets(
}
/**
* The content type of a dist file the worker precaches, or undefined: a
* content-hashed name with a cacheable type under `BUILD_ASSET_DIRECTORY`,
* not one of `EXCLUDED_FILES`.
*/
function precachedContentType(relative: string): string | undefined {
const base = path.basename(relative);
if (!relative.split(path.sep).join("/").startsWith(BUILD_ASSET_DIRECTORY)) return undefined;
if (EXCLUDED_FILES.has(base) || !HASHED_NAME.test(base)) return undefined;
return CACHEABLE_EXTENSIONS[path.extname(base).toLowerCase()];
}
/**
* 1112/06-02. How many files of a dist the worker would precache, by the
* rule collectStaticAssets applies, without its bounds. The feature-shape
* measurement records it per feature.
*/
export async function countPrecachedAssets(distDirectory: string): Promise<number> {
return (await walk(distDirectory, distDirectory)).filter(
(relative) => precachedContentType(relative) !== undefined,
).length;
}
async function walk(root: string, current: string): Promise<string[]> {
const entries = await readdir(current, { withFileTypes: true });
const files: string[] = [];
+53 -11
View File
@@ -7,6 +7,7 @@ import { gzipSync } from "node:zlib";
import { PLATFORM_ROUTE_REGISTRY } from "../../src/contracts/routes.ts";
import { planFeature, type InstalledFacts } from "../create-feature.ts";
import { countPrecachedAssets } from "../generate-service-worker-assets.ts";
import { classifyViteJavascript } from "../lib/classify-vite-bundle.ts";
import { linkFixtureNodeModules } from "../lib/fixture-node-modules.ts";
import { VITE_BUILD_INPUTS } from "../lib/vite-build-inputs.ts";
@@ -192,14 +193,18 @@ async function javascriptGzipBytes(root: string, files: readonly string[]) {
async function measureInitialJavascript(
features: number,
featuresPerContext = FEATURES_PER_CONTEXT,
): Promise<Readonly<{ gzipBytes: number; files: number }>> {
): Promise<Readonly<{ gzipBytes: number; files: number; precacheAssets: number }>> {
const root = await createFixture(features, featuresPerContext);
try {
run(process.execPath, [path.resolve("scripts/generate-product-feature-index.ts"), `--root=${root}`], root);
run(path.resolve("node_modules/.bin/vite"), ["build", "--logLevel", "error"], root);
const manifest = JSON.parse(await readFile(path.join(root, "dist/.vite/manifest.json"), "utf8"));
const { initialFiles } = classifyViteJavascript(manifest);
return { gzipBytes: await javascriptGzipBytes(root, initialFiles), files: initialFiles.length };
return {
gzipBytes: await javascriptGzipBytes(root, initialFiles),
files: initialFiles.length,
precacheAssets: await countPrecachedAssets(path.join(root, "dist")),
};
} finally {
await rm(root, { recursive: true, force: true });
}
@@ -224,20 +229,55 @@ export type InitialJavascriptCosts = Readonly<{
perContextGzipBytes: number;
}>;
export async function measureInitialJavascriptCosts(): Promise<InitialJavascriptCosts> {
/**
* 1112/06-02. With the Service Worker on, it precaches every hashed file
* under `assets/` (collectStaticAssets), so each feature's lazy chunks count
* towards the precache asset bound (`SERVICE_WORKER_BOUNDS.assets`). The
* same builds as the initial JavaScript, counted by the worker's rule. The
* builds leave the worker off: a build with it on adds the files of its own
* registration code.
*/
export type PrecacheCosts = Readonly<{
assets: number;
firstFeatureAssets: number;
perFeatureAssets: number;
perContextAssets: number;
}>;
export type FeatureShapeCosts = Readonly<{
initialJavascript: InitialJavascriptCosts;
serviceWorkerPrecache: PrecacheCosts;
}>;
export async function measureFeatureShapeCosts(): Promise<FeatureShapeCosts> {
const none = await measureInitialJavascript(0);
const one = await measureInitialJavascript(1);
const twoInOneContext = await measureInitialJavascript(2);
const twoInTwoContexts = await measureInitialJavascript(2, 1);
return {
gzipBytes: none.gzipBytes,
files: none.files,
firstFeatureGzipBytes: one.gzipBytes - none.gzipBytes,
perFeatureGzipBytes: twoInOneContext.gzipBytes - one.gzipBytes,
perContextGzipBytes: twoInTwoContexts.gzipBytes - twoInOneContext.gzipBytes,
initialJavascript: {
gzipBytes: none.gzipBytes,
files: none.files,
firstFeatureGzipBytes: one.gzipBytes - none.gzipBytes,
perFeatureGzipBytes: twoInOneContext.gzipBytes - one.gzipBytes,
perContextGzipBytes: twoInTwoContexts.gzipBytes - twoInOneContext.gzipBytes,
},
serviceWorkerPrecache: {
assets: none.precacheAssets,
firstFeatureAssets: one.precacheAssets - none.precacheAssets,
perFeatureAssets: twoInOneContext.precacheAssets - one.precacheAssets,
perContextAssets: twoInTwoContexts.precacheAssets - twoInOneContext.precacheAssets,
},
};
}
/** 1112/06-02. Fields of the precache record that differ from the build: counts are exact. */
export function precacheRecordDrift(measured: PrecacheCosts, record: PrecacheCosts): string[] {
return (Object.keys(measured) as (keyof PrecacheCosts)[])
.filter((field) => record[field] !== measured[field])
.map((field) => `${field}: record ${record[field]}, build ${measured[field]}`);
}
/**
* 1105/15-02. How far the total may be from the record, in gzip bytes. The
* total moves by tens of bytes with the build id (CI and local builds
@@ -364,11 +404,13 @@ function version(bin: string): string {
* the initial JavaScript.
*/
async function writeInitialBaseline(): Promise<void> {
const measured = await measureInitialJavascriptCosts();
process.stdout.write(`initial JavaScript: ${JSON.stringify(measured)}\n`);
const measured = await measureFeatureShapeCosts();
process.stdout.write(`initial JavaScript: ${JSON.stringify(measured.initialJavascript)}\n`);
process.stdout.write(`service worker precache: ${JSON.stringify(measured.serviceWorkerPrecache)}\n`);
if (!process.argv.includes("--write")) return;
const ceilings = JSON.parse(await readFile(FEATURE_SHAPE_CEILINGS_PATH, "utf8")) as Record<string, unknown>;
ceilings["initialJavascript"] = measured;
ceilings["initialJavascript"] = measured.initialJavascript;
ceilings["serviceWorkerPrecache"] = measured.serviceWorkerPrecache;
await writeFile(FEATURE_SHAPE_CEILINGS_PATH, `${JSON.stringify(ceilings, null, 2)}\n`);
process.stdout.write(`feature-shape initial baseline: ${FEATURE_SHAPE_CEILINGS_PATH}\n`);
}