check:bundle은 Vite manifest의 chunk만 잰다. Service Worker를 켠 제품의 worker와 public·Web Worker 출력은 크기가 얼마든 FE-GATE-012를 통과한다. 빌드가 만든 Service Worker는 새 key `bundle.serviceWorkerGzipBytes`로, assets/에 빌드가 만든 hash 이름 파일은 파일마다 lazy 예산으로 잰다. public/ 사본은 이름이 hash처럼 보이거나 service-worker.js여도 빌드 출력이 아니므로, 그 밖의 예산 없는 JS와 함께 경로를 대고 실패한다. 이름만 보는 안은 HTML이 바로 읽는 public JS 221,678 B가 통과해 버렸다. 새 key가 없으면 파일과 key를 대고 실패한다. 예산 값은 자산 목록을 상한까지(채운 이름은 줄기 16자 무작위) 채우고 build·release id를 128자로 준 worker(Mmax)를 1 KiB 단위로 올림한 값이다(review 판정 2026-11-23, 소유자 결정 아님). 100 B 단위 올림은 기능을 더한 제품이 코드 변경 없이 막히고, 긴 이름에 맞춰 올리거나 id를 512자로 재는 안은 worker 코드 증가를 더 숨긴다. 목록과 코드를 나눠 재는 안은 빌드 구조를 바꿔서 버렸다. 위험: 자산 목록이 상한에 가까우면 이름이 길고 다양하거나 id가 길 때 예산을 넘을 수 있다. 기본 id로도 넘는 조합을 쟀다. 자산이 적은 빌드에서는 목록 몫만큼 worker 코드 증가를 못 잡는다. 기본 선택이 null이라 템플릿 CI는 worker 값을 재지 않는다. 검증: 고치기 전 코드에 이 커밋의 시험을 얹으면 세 파일 47개 가운데 25개가 실패하고 이 트리에서 통과한다. 보호 규칙 변이 15개가 실패한다. 노트북 check:types, lint, check:architecture, test:unit, test:contract, test:runtime-schema, verify:documentation 통과. desktop에서 worker 입력이 같은 트리의 Mmax 23404 B, 자산 길이 다섯 자리 23442 B, handler 둘 23424 B가 예산 안이고 zod를 넣은 worker는 실패했다. merge 단계와 FE-GATE-029·030은 커밋 때 돌리지 않았다. Refs: REV-FE-0010
165 lines
5.4 KiB
TypeScript
165 lines
5.4 KiB
TypeScript
import { readFile } from "node:fs/promises";
|
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
evaluateBundleBudget,
|
|
evaluateFieldBudget,
|
|
evaluateLabBudget,
|
|
percentile75,
|
|
} from "../../scripts/lib/performance-budgets.ts";
|
|
|
|
describe("performance budgets", () => {
|
|
it("rejects initial and lazy JavaScript above their named limits", () => {
|
|
const thresholds = {
|
|
initialJsGzipBytes: 200,
|
|
initialJsFiles: 2,
|
|
lazyChunkGzipBytes: 120,
|
|
serviceWorkerGzipBytes: 80,
|
|
};
|
|
expect(
|
|
evaluateBundleBudget(
|
|
{ initialJsGzipBytes: 201, initialJsFiles: 1, lazyChunks: [], serviceWorkerGzipBytes: null },
|
|
thresholds,
|
|
).passed,
|
|
).toBe(false);
|
|
expect(
|
|
evaluateBundleBudget(
|
|
{
|
|
initialJsGzipBytes: 100,
|
|
initialJsFiles: 1,
|
|
lazyChunks: [{ path: "lazy.js", gzipBytes: 121 }],
|
|
serviceWorkerGzipBytes: null,
|
|
},
|
|
thresholds,
|
|
).passed,
|
|
).toBe(false);
|
|
expect(
|
|
evaluateBundleBudget(
|
|
{ initialJsGzipBytes: 100, initialJsFiles: 3, lazyChunks: [], serviceWorkerGzipBytes: null },
|
|
thresholds,
|
|
),
|
|
).toMatchObject({ initialPassed: true, initialFilesPassed: false, passed: false });
|
|
expect(
|
|
evaluateBundleBudget(
|
|
{ initialJsGzipBytes: 100, initialJsFiles: 1, lazyChunks: [], serviceWorkerGzipBytes: 81 },
|
|
thresholds,
|
|
),
|
|
).toMatchObject({ initialPassed: true, serviceWorkerPassed: false, passed: false });
|
|
});
|
|
|
|
it("fails lab evidence when context is absent or a metric is over budget", () => {
|
|
const thresholds = { lcpMs: 2500, cls: 0.1, namedInteractionMs: 200, featureRouteInteractionMs: 500 };
|
|
expect(
|
|
evaluateLabBudget(
|
|
{ metrics: { lcpMs: 1000, cls: 0, namedInteractionMs: 50, targetDeepLinkCls: 0, featureRouteInteractionMs: null } },
|
|
thresholds,
|
|
),
|
|
).toMatchObject({ passed: false });
|
|
expect(
|
|
evaluateLabBudget(
|
|
{
|
|
context: {
|
|
runner: {},
|
|
browser: {},
|
|
viewport: {},
|
|
network: {},
|
|
cpu: {},
|
|
cache: {},
|
|
build: {},
|
|
},
|
|
metrics: { lcpMs: 2501, cls: 0, namedInteractionMs: 50, targetDeepLinkCls: 0, featureRouteInteractionMs: null },
|
|
},
|
|
thresholds,
|
|
).passed,
|
|
).toBe(false);
|
|
});
|
|
|
|
/**
|
|
* 1105/15-01. The lab entered its target route only by a click, and a
|
|
* shift within 500 ms of a click is left out of CLS. The target screen
|
|
* pushed its content 21 px after its title and the lab reported 0. The
|
|
* direct visit's CLS is judged against the same threshold.
|
|
*/
|
|
it("fails lab evidence when a direct visit to the target route shifts over the CLS budget", () => {
|
|
const thresholds = { lcpMs: 2500, cls: 0.1, namedInteractionMs: 200, featureRouteInteractionMs: 500 };
|
|
const context = {
|
|
runner: {},
|
|
browser: {},
|
|
viewport: {},
|
|
network: {},
|
|
cpu: {},
|
|
cache: {},
|
|
build: {},
|
|
};
|
|
const metrics = { lcpMs: 1000, cls: 0, namedInteractionMs: 50, targetDeepLinkCls: 0.0046, featureRouteInteractionMs: 406 };
|
|
|
|
expect(evaluateLabBudget({ context, metrics }, thresholds).passed).toBe(true);
|
|
const shifted = evaluateLabBudget(
|
|
{ context, metrics: { ...metrics, targetDeepLinkCls: 0.11 } },
|
|
thresholds,
|
|
);
|
|
expect(shifted.passed).toBe(false);
|
|
expect(shifted.results).toMatchObject({ cls: true, targetDeepLinkCls: false });
|
|
});
|
|
|
|
/**
|
|
* 1105/15-04. The lab timed only the platform screen, which loads no
|
|
* feature code. A feature route's first entry took 406 ms (403-410) under
|
|
* the lab conditions at 8a44226, two request rounds (the context route
|
|
* module, then the page chunk, the second about 100 ms), and no gate
|
|
* measured it. The committed budget passes that entry and fails it with
|
|
* one more round of that size.
|
|
*/
|
|
it("judges the feature route entry against its committed budget", async () => {
|
|
const { lab: thresholds } = JSON.parse(
|
|
await readFile("config/performance/budgets.json", "utf8"),
|
|
) as { lab: Parameters<typeof evaluateLabBudget>[1] };
|
|
const context = {
|
|
runner: {},
|
|
browser: {},
|
|
viewport: {},
|
|
network: {},
|
|
cpu: {},
|
|
cache: {},
|
|
build: {},
|
|
};
|
|
const metrics = {
|
|
lcpMs: 1000,
|
|
cls: 0,
|
|
namedInteractionMs: 150,
|
|
targetDeepLinkCls: 0,
|
|
featureRouteInteractionMs: 406,
|
|
};
|
|
const judged = (featureRouteInteractionMs: number | null) =>
|
|
evaluateLabBudget({ context, metrics: { ...metrics, featureRouteInteractionMs } }, thresholds);
|
|
|
|
expect(thresholds.featureRouteInteractionMs).toEqual(expect.any(Number));
|
|
expect(judged(406).passed).toBe(true);
|
|
expect(judged(406 + 110)).toMatchObject({
|
|
passed: false,
|
|
results: { namedInteraction: true, featureRouteInteraction: false },
|
|
});
|
|
// No installed feature owns a public navigation route: nothing to judge.
|
|
expect(judged(null).passed).toBe(true);
|
|
});
|
|
|
|
it("uses the nearest-rank p75 and fails closed while sample minimum is deferred", () => {
|
|
expect(percentile75([4, 1, 3, 2])).toBe(3);
|
|
expect(
|
|
evaluateFieldBudget(
|
|
{
|
|
metrics: { p75LcpMs: 1000, p75Cls: 0.01, p75InpMs: 50 },
|
|
eligibleSamples: 100,
|
|
},
|
|
{
|
|
p75LcpMs: 2500,
|
|
p75Cls: 0.1,
|
|
p75InpMs: 200,
|
|
minimumEligibleSamples: null,
|
|
},
|
|
),
|
|
).toEqual({ status: "FAIL_UNVERIFIED", passed: false });
|
|
});
|
|
});
|