fix: close performance evidence and budget gates

This commit is contained in:
2026-09-02 08:27:21 +03:00
parent 1734003172
commit 5525557c3a
13 changed files with 541 additions and 39 deletions

View File

@@ -1,5 +1,11 @@
import { describe, expect, it } from 'vitest';
import { classifyArtifact, evaluateBudgetTotals, PERFORMANCE_BUDGETS } from '../../scripts/lib/bundle-budgets.mjs';
import {
classifyArtifact,
evaluateBudgetTotals,
evaluateMediaAssetBudget,
evaluateRuntimeBudgetEvidence,
PERFORMANCE_BUDGETS,
} from '../../scripts/lib/bundle-budgets.mjs';
describe('release budgets', () => {
it('pins every exact section 14 threshold', () => {
@@ -31,6 +37,7 @@ describe('release budgets', () => {
expect(classifyArtifact('assets/index-a.css', '')).toBe('critical-css');
expect(classifyArtifact('assets/index-a.js', 'import("./environment-b.js")')).toBe('initial-application-js');
expect(classifyArtifact('assets/environment-b.js', 'three scene')).toBe('first-live-scene');
expect(classifyArtifact('assets/high-tier-b.js', 'optional bloom')).toBe('high-tier-extras');
expect(() => classifyArtifact('assets/mystery.bin', '')).toThrow(/unclassified/u);
});
@@ -38,4 +45,80 @@ describe('release budgets', () => {
expect(evaluateBudgetTotals({ initialHtmlCriticalCss: 100 * 1024 }).violations).toEqual([]);
expect(evaluateBudgetTotals({ initialHtmlCriticalCss: 100 * 1024 + 1 }).violations).toContainEqual(expect.objectContaining({ budget: 'initialHtmlCriticalCss' }));
});
it('rejects an undersized transfer when its video delivery rendition is 20s at 1920x1080', () => {
const result = evaluateMediaAssetBudget({
id: 'project-demo',
mediaType: 'video/webm',
width: 1_920,
height: 1_080,
durationMs: 20_000,
}, {
mediaType: 'video/webm',
width: 1_920,
height: 1_080,
durationMs: 20_000,
}, 1_024);
expect(result.violations.map((violation) => violation.budget)).toEqual(expect.arrayContaining([
'projectVideoDurationSeconds',
'projectVideoWidth',
'projectVideoHeight',
]));
});
it('fails closed when non-empty media dimensions cannot be deterministically probed', () => {
expect(() => evaluateMediaAssetBudget({
id: 'project-still',
mediaType: 'image/webp',
width: 1_280,
height: 720,
}, null, 1_024)).toThrow(/probe evidence/u);
});
it('rejects excessive high-tier extras and request concurrency', () => {
expect(evaluateBudgetTotals({ highTierExtras: PERFORMANCE_BUDGETS.highTierExtras! + 1 }).violations)
.toContainEqual(expect.objectContaining({ budget: 'highTierExtras' }));
expect(evaluateRuntimeBudgetEvidence({
schema: 'portfolio-runtime-budget-evidence/v1',
peakRequests: { imageScene: 3, video: 2 },
tiers: [
{ tier: 'low', textures: [], geometryBytes: 0, renderTargets: [] },
{ tier: 'high', textures: [], geometryBytes: 0, renderTargets: [] },
],
}).violations.map((violation) => violation.budget)).toEqual(expect.arrayContaining([
'imageSceneConcurrency',
'videoConcurrency',
]));
});
it('derives decoded texture and GPU bytes from allocation formulas', () => {
const result = evaluateRuntimeBudgetEvidence({
schema: 'portfolio-runtime-budget-evidence/v1',
peakRequests: { imageScene: 0, video: 0 },
tiers: [
{
tier: 'low',
textures: [{ id: 'oversized', width: 4_096, height: 4_096, bytesPerPixel: 4, layers: 1, mipmapped: true }],
geometryBytes: 40 * 1024 * 1024,
renderTargets: [{ id: 'framebuffer', width: 2_048, height: 2_048, bytesPerPixel: 8, attachments: 2, samples: 1 }],
},
{ tier: 'high', textures: [], geometryBytes: 0, renderTargets: [] },
],
});
expect(result.tiers[0]?.textureBytes).toBe(Math.ceil(4_096 * 4_096 * 4 * 4 / 3));
expect(result.violations.map((violation) => violation.budget)).toEqual(expect.arrayContaining([
'mobileTextureDimension',
'lowTierGpuEstimate',
]));
});
it('fails closed when either named tier allocation ledger is absent', () => {
expect(() => evaluateRuntimeBudgetEvidence({
schema: 'portfolio-runtime-budget-evidence/v1',
peakRequests: { imageScene: 0, video: 0 },
tiers: [{ tier: 'low', textures: [], geometryBytes: 0, renderTargets: [] }],
})).toThrow(/exactly one Low and High/u);
});
});