fix: bind performance evidence to production resources
This commit is contained in:
@@ -4,6 +4,9 @@ import {
|
||||
evaluateBudgetTotals,
|
||||
evaluateMediaAssetBudget,
|
||||
evaluateRuntimeBudgetEvidence,
|
||||
evaluateRuntimeTraceBudgetEvidence,
|
||||
validateRuntimeBudgetTraceReport,
|
||||
calculatePeakRequestConcurrency,
|
||||
PERFORMANCE_BUDGETS,
|
||||
} from '../../scripts/lib/bundle-budgets.mjs';
|
||||
|
||||
@@ -121,4 +124,83 @@ describe('release budgets', () => {
|
||||
tiers: [{ tier: 'low', textures: [], geometryBytes: 0, renderTargets: [] }],
|
||||
})).toThrow(/exactly one Low and High/u);
|
||||
});
|
||||
|
||||
it('counts peak concurrency from actual production resource timing intervals', () => {
|
||||
const peak = calculatePeakRequestConcurrency([
|
||||
{ name: '/assets/a.webp', initiatorType: 'img', startTime: 0, responseEnd: 50 },
|
||||
{ name: '/assets/b.webp', initiatorType: 'img', startTime: 10, responseEnd: 60 },
|
||||
{ name: '/assets/environment-a.js', initiatorType: 'script', startTime: 20, responseEnd: 70 },
|
||||
{ name: '/assets/a.webm', initiatorType: 'video', startTime: 0, responseEnd: 50 },
|
||||
{ name: '/assets/b.mp4', initiatorType: 'video', startTime: 10, responseEnd: 60 },
|
||||
]);
|
||||
expect(peak).toEqual({ imageScene: 3, video: 2 });
|
||||
expect(evaluateRuntimeTraceBudgetEvidence({
|
||||
schema: 'portfolio-runtime-trace-evidence/v1',
|
||||
peakRequests: peak,
|
||||
allocation: { tier: 'low', textures: [], geometryBytes: 0, renderTargets: [] },
|
||||
}).violations.map((item) => item.budget)).toEqual(expect.arrayContaining(['imageSceneConcurrency', 'videoConcurrency']));
|
||||
});
|
||||
|
||||
it('recomputes actual trace allocations and ignores a forged low total', () => {
|
||||
const result = evaluateRuntimeTraceBudgetEvidence({
|
||||
schema: 'portfolio-runtime-trace-evidence/v1',
|
||||
peakRequests: { imageScene: 0, video: 0 },
|
||||
allocation: {
|
||||
tier: 'low',
|
||||
textures: [{ id: 'actual-production-texture', width: 4_096, height: 4_096, bytesPerPixel: 4, layers: 1, mipmapped: true }],
|
||||
geometryBytes: 0,
|
||||
renderTargets: [{ id: 'default-framebuffer', width: 390, height: 844, bytesPerPixel: 4, attachments: 2, samples: 1 }],
|
||||
totalBytes: 1,
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.tier.totalBytes).toBeGreaterThan(PERFORMANCE_BUDGETS.lowTierGpuEstimate!);
|
||||
expect(result.violations.map((item) => item.budget)).toEqual(expect.arrayContaining(['mobileTextureDimension', 'lowTierGpuEstimate']));
|
||||
});
|
||||
|
||||
it('accepts only a production-path High capture whose framebuffer matches the observed DPR cap', () => {
|
||||
const report = {
|
||||
schema: 'runtime-budget-trace.v1',
|
||||
evidenceKind: 'authenticated-test-build-production-path',
|
||||
gatingReferenceResult: false,
|
||||
profile: 'desktop-high',
|
||||
tier: 'high',
|
||||
observed: {
|
||||
viewport: { width: 1_440, height: 900 },
|
||||
devicePixelRatio: 2,
|
||||
rendererPixelRatio: 1.5,
|
||||
},
|
||||
runtimeBudgetEvidence: {
|
||||
schema: 'portfolio-runtime-trace-evidence/v1',
|
||||
peakRequests: { imageScene: 1, video: 0 },
|
||||
allocation: {
|
||||
tier: 'high',
|
||||
textures: [],
|
||||
geometryBytes: 0,
|
||||
renderTargets: [
|
||||
{ id: 'default-framebuffer', width: 2_160, height: 1_350, bytesPerPixel: 4, attachments: 2, samples: 4 },
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(validateRuntimeBudgetTraceReport(report).violations).toEqual([]);
|
||||
expect(() => validateRuntimeBudgetTraceReport({
|
||||
...report,
|
||||
runtimeBudgetEvidence: {
|
||||
...report.runtimeBudgetEvidence,
|
||||
allocation: {
|
||||
...report.runtimeBudgetEvidence.allocation,
|
||||
renderTargets: [
|
||||
{ id: 'default-framebuffer', width: 1_440, height: 900, bytesPerPixel: 4, attachments: 2, samples: 4 },
|
||||
],
|
||||
},
|
||||
},
|
||||
})).toThrow(/framebuffer dimensions/u);
|
||||
expect(() => validateRuntimeBudgetTraceReport({
|
||||
schema: 'portfolio-runtime-budget-evidence/v1',
|
||||
peakRequests: { imageScene: 0, video: 0 },
|
||||
tiers: [],
|
||||
})).toThrow(/authenticated production-path/u);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user