Files
clean-architecture-frontend…/scripts/lib/performance-budgets.ts
T
DongHyeonkaandClaude Opus 5.5 1e93d30d1f refactor(platform): drop the .tsx re-export, move CI-only policies, derive message locales (Q-6.9-12)
- Delete src/features/reference-feature/presentation/reference-feature-runtime.tsx:
  it only re-exported the same-named .ts and nothing imported it by the
  .tsx path.
- Move promotion-readiness.ts and performance-budgets.ts from
  src/application/policies to scripts/lib: only scripts and their unit
  tests import them. Imports updated in 5 scripts and 2 tests.
  config/testing/risk-coverage.json lists only src modules, so their two
  criticalModules/highRiskPaths entries are removed; the synthetic
  14-file summary fixture now names two other existing src modules.
- installed-feature-messages.ts composes one catalog per locale the
  installed features declare (composeInstalledMessageCatalogs) instead
  of a fixed ko-KR/en-US list that silently dropped other catalogs. The
  exported type still maps each declared locale to its exact key set.

Verified: tests/unit/installed-feature-messages.test.ts (ko-KR/en-US
content pinned first; derived-locale and duplicate-key cases RED before);
app typecheck also passes with a zero-feature generated index; all gates
PASS; check:ci PASS; check-bundle resolves the moved module (stops later
on the absent artifacts/performance/bundle.json).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 13:58:35 +09:00

119 lines
3.1 KiB
TypeScript

export type BundleMeasurements = Readonly<{
initialJsGzipBytes: number;
lazyChunks: readonly Readonly<{ path: string; gzipBytes: number }>[];
}>;
export type BundleThresholds = Readonly<{
initialJsGzipBytes: number;
lazyChunkGzipBytes: number;
}>;
export function evaluateBundleBudget(
measurements: BundleMeasurements,
thresholds: BundleThresholds,
) {
const initialPassed =
measurements.initialJsGzipBytes <= thresholds.initialJsGzipBytes;
const lazyResults = measurements.lazyChunks.map((chunk) => ({
...chunk,
threshold: thresholds.lazyChunkGzipBytes,
passed: chunk.gzipBytes <= thresholds.lazyChunkGzipBytes,
}));
return Object.freeze({
initialPassed,
lazyResults: Object.freeze(lazyResults),
passed: initialPassed && lazyResults.every((chunk) => chunk.passed),
});
}
export type LabMetrics = Readonly<{
lcpMs: number;
cls: number;
namedInteractionMs: number;
}>;
export function evaluateLabBudget(
report: Readonly<{
context?: Readonly<Record<string, unknown>>;
metrics: LabMetrics;
}>,
thresholds: LabMetrics,
) {
const requiredContext = [
"runner",
"browser",
"viewport",
"network",
"cpu",
"cache",
"build",
];
const missingContext = requiredContext.filter(
(field) => report.context?.[field] === undefined,
);
const results = {
lcp: report.metrics.lcpMs <= thresholds.lcpMs,
cls: report.metrics.cls <= thresholds.cls,
namedInteraction:
report.metrics.namedInteractionMs <= thresholds.namedInteractionMs,
};
return Object.freeze({
missingContext: Object.freeze(missingContext),
results: Object.freeze(results),
passed: missingContext.length === 0 && Object.values(results).every(Boolean),
});
}
export function percentile75(values: readonly number[]): number | null {
if (values.length === 0) return null;
const sorted = [...values].sort((left, right) => left - right);
return sorted[Math.ceil(sorted.length * 0.75) - 1];
}
export type FieldMetrics = Readonly<{
p75LcpMs: number | null;
p75Cls: number | null;
p75InpMs: number | null;
}>;
export type FieldThresholds = Readonly<{
p75LcpMs: number;
p75Cls: number;
p75InpMs: number;
minimumEligibleSamples: number | null;
}>;
export type FieldBudgetResult = Readonly<{
status: "PASS" | "FAIL_THRESHOLD" | "FAIL_UNVERIFIED";
passed: boolean;
}>;
export function evaluateFieldBudget(
report: Readonly<{ metrics: FieldMetrics; eligibleSamples: number }>,
thresholds: FieldThresholds,
): FieldBudgetResult {
if (
thresholds.minimumEligibleSamples === null ||
report.eligibleSamples < thresholds.minimumEligibleSamples ||
Object.values(report.metrics).some((value) => value === null)
) {
return Object.freeze({
status: "FAIL_UNVERIFIED",
passed: false,
});
}
const metrics = report.metrics as Readonly<{
p75LcpMs: number;
p75Cls: number;
p75InpMs: number;
}>;
const passed =
metrics.p75LcpMs <= thresholds.p75LcpMs &&
metrics.p75Cls <= thresholds.p75Cls &&
metrics.p75InpMs <= thresholds.p75InpMs;
return Object.freeze({
status: passed ? "PASS" : "FAIL_THRESHOLD",
passed,
});
}