fix: bind performance evidence to production resources

This commit is contained in:
2026-09-02 08:53:00 +03:00
parent 5b7e47c2a2
commit e3ac3a4db4
23 changed files with 642 additions and 60 deletions

View File

@@ -4,6 +4,7 @@ import type { CDPSession, Page } from '@playwright/test';
import { expect, test } from '../helpers/serve-dist';
import { authorizedPerformanceUrl } from '../helpers/test-build-auth';
import { loadAuthenticatedReferenceRun, validateObservedReferenceEnvironment } from './reference-run';
import { calculatePeakRequestConcurrency, evaluateRuntimeTraceBudgetEvidence } from '../../scripts/lib/bundle-budgets.mjs';
import {
calculateCls,
calculateLabTbt,
@@ -111,6 +112,7 @@ test('drive-trace.v1 runs on current Chromium with fail-closed reference authent
reducedMotion: matchMedia('(prefers-reduced-motion: reduce)').matches ? 'reduce' as const : 'no-preference' as const,
saveData: Boolean((navigator as Navigator & { connection?: { saveData?: boolean } }).connection?.saveData),
pageZoom: visualViewport?.scale ?? 1,
devicePixelRatio,
}));
validateObservedReferenceEnvironment(referenceRun, {
...observed,
@@ -182,6 +184,7 @@ test('drive-trace.v1 runs on current Chromium with fail-closed reference authent
if (snapshot === undefined || snapshot.traceStart === null || snapshot.traceEnd === null || snapshot.firstSceneFrame === null) {
throw new Error('The authenticated performance snapshot is incomplete.');
}
if (snapshot.runtimeAllocation === null) throw new Error('The production scene did not emit an actual allocation ledger.');
const expectedPeriod = warmupMedian;
const fcp = await page.evaluate(() => performance.getEntriesByName('first-contentful-paint')[0]?.startTime ?? null);
const lcp = latestLcpBeforeCutoff(snapshot.lcp, snapshot.cutoff);
@@ -193,6 +196,15 @@ test('drive-trace.v1 runs on current Chromium with fail-closed reference authent
const lost = calculateLostPresentationShare(snapshot.pageRafs, expectedPeriod, Math.floor(20_000 / expectedPeriod) - 3);
const lateShifts = unexpectedLateShifts(snapshot.layoutShifts, snapshot.firstSceneFrame, snapshot.traceEnd);
const sceneCpuP95 = nearestRankP95(snapshot.sceneFrames.map((frame) => frame.end - frame.start));
const resourceTimings = await page.evaluate(() => performance.getEntriesByType('resource').map((entry) => {
const resource = entry as PerformanceResourceTiming;
return { name: resource.name, initiatorType: resource.initiatorType, startTime: resource.startTime, responseEnd: resource.responseEnd };
}));
const peakRequests = calculatePeakRequestConcurrency(resourceTimings);
const runtimeBudgetEvidence = { schema: 'portfolio-runtime-trace-evidence/v1', peakRequests, allocation: snapshot.runtimeAllocation };
const runtimeBudget = evaluateRuntimeTraceBudgetEvidence(runtimeBudgetEvidence);
const runtimeResourcePass = !runtimeBudget.violations.some((item) => ['mobileTextureDimension', 'lowTierGpuEstimate', 'highTierGpuEstimate'].includes(item.budget));
const requestConcurrencyPass = !runtimeBudget.violations.some((item) => ['imageSceneConcurrency', 'videoConcurrency'].includes(item.budget));
const budgetResults = {
lcp: lcp <= 3_000,
@@ -204,6 +216,8 @@ test('drive-trace.v1 runs on current Chromium with fail-closed reference authent
continuity: continuity.passes,
lostPresentation: lost.hasSufficientCoverage && lost.share <= profile.lostShare,
lateShifts: lateShifts.length === 0,
runtimeResources: runtimeResourcePass,
requestConcurrency: requestConcurrencyPass,
};
if (process.env.PORTFOLIO_REFERENCE_LAB === '1') {
expect(Object.values(budgetResults).every(Boolean)).toBe(true);
@@ -212,13 +226,16 @@ test('drive-trace.v1 runs on current Chromium with fail-closed reference authent
const report = {
schema: 'drive-trace.v1',
evidenceKind: referenceRun === null ? 'current-chromium-developer-machine-non-reference' : 'authenticated-physical-reference',
gatingReferenceResult: referenceRun !== null,
evidenceKind: referenceRun === null ? 'current-chromium-developer-machine-non-reference' : 'validated-reference-candidate-unsigned',
gatingReferenceResult: false,
referenceCandidateValidated: referenceRun !== null,
...(referenceRun === null ? {} : { referenceRun: { runId: referenceRun.runId, runIndex: referenceRun.runIndex, attestationDigest: referenceRun.attestationDigest } }),
profile: profile.name,
tier: profile.tier,
browser: testInfo.project.name,
metrics: { warmupMedian, lcp, cls, tbt, postRunningLongTaskCount: postRunning.length, eventToNextPaintP95: eventToPaint.p95, sceneCpuP95, continuity, lostPresentationShare: lost.share, lateShiftCount: lateShifts.length },
runtimeBudgetEvidence,
runtimeBudgetSummary: runtimeBudget.tier,
budgetResults,
referenceBudgetsPass: validReferenceCadence && Object.values(budgetResults).every(Boolean),
validReferenceCadence,