From d64c1a1a9116a8bc84a168058bd45861de9ea0d1 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Wed, 19 Aug 2026 13:42:27 +0800 Subject: [PATCH] fix(scripts): detect existing dist-runtime growth (#126191) Punchcard-Session: golden-lantern-cedar-9j Co-authored-by: qingminlong --- scripts/check-gateway-watch-regression.mts | 11 ++++--- .../check-gateway-watch-regression.test.ts | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/scripts/check-gateway-watch-regression.mts b/scripts/check-gateway-watch-regression.mts index 8e4bd021a4e7..5756106851df 100644 --- a/scripts/check-gateway-watch-regression.mts +++ b/scripts/check-gateway-watch-regression.mts @@ -908,6 +908,9 @@ export function writeBuildAndRuntimePostBuildStamps(params: { cwd?: string } = { writeRuntimePostBuildStamp({ cwd }); } +export function calculateDistRuntimeByteGrowth(beforeBytes: number, afterBytes: number): number { + return afterBytes - beforeBytes; +} /** * Collects pass/fail findings for the bounded gateway watch regression run. */ @@ -1076,10 +1079,10 @@ async function main() { entry.startsWith("dist-runtime/"), ).length; const distRuntimeFileGrowth = distRuntimeAddedPaths; - const distRuntimeByteGrowth = - distRuntimeAddedPaths === 0 - ? 0 - : post.distRuntime.apparentBytes - pre.distRuntime.apparentBytes; + const distRuntimeByteGrowth = calculateDistRuntimeByteGrowth( + pre.distRuntime.apparentBytes, + post.distRuntime.apparentBytes, + ); const totalCpuMs = Math.round( (watchResult.timing.userSeconds + watchResult.timing.sysSeconds) * 1000, ); diff --git a/test/scripts/check-gateway-watch-regression.test.ts b/test/scripts/check-gateway-watch-regression.test.ts index 2d88a3654b0b..ef120cb5b2a8 100644 --- a/test/scripts/check-gateway-watch-regression.test.ts +++ b/test/scripts/check-gateway-watch-regression.test.ts @@ -7,6 +7,7 @@ import { describe, expect, it, vi } from "vitest"; import { appendBoundedWatchLog, buildTimedWatchCommand, + calculateDistRuntimeByteGrowth, collectGatewayWatchFindings, hasGatewayReadyLog, parseArgs, @@ -86,6 +87,35 @@ describe("check-gateway-watch-regression", () => { expect(hasGatewayReadyLog("[gateway] starting HTTP server...")).toBe(false); }); + it("detects byte growth in existing dist-runtime paths", () => { + const distRuntimeByteGrowth = calculateDistRuntimeByteGrowth(100, 2_097_253); + const findings = collectGatewayWatchFindings({ + cpuMs: 0, + distRuntimeByteGrowth, + distRuntimeFileGrowth: 0, + options: { + cpuFailMs: 8000, + cpuWarnMs: 1000, + distRuntimeByteGrowthMax: 2 * 1024 * 1024, + distRuntimeFileGrowthMax: 200, + windowMs: 10_000, + }, + watchBuildReason: null, + watchResult: { + idleCpuMs: 0, + readyBeforeWindow: true, + spawnError: null, + timingFileMissing: false, + }, + watchTriggeredBuild: false, + }); + + expect(distRuntimeByteGrowth).toBe(2_097_153); + expect(findings.failures).toContain( + "dist-runtime apparent byte growth 2097153 exceeded max 2097152", + ); + }); + it("bounds in-memory watch output capture while keeping the newest logs", () => { const first = appendBoundedWatchLog("abc", "def", 8); expect(first).toEqual({ text: "abcdef", truncated: false });