fix(scripts): detect existing dist-runtime growth (#126191)

Punchcard-Session: golden-lantern-cedar-9j

Co-authored-by: qingminlong <qing.minlong@xydigit.com>
This commit is contained in:
Vincent Koc
2026-08-19 13:42:27 +08:00
committed by GitHub
parent 95ac5b27fa
commit d64c1a1a91
2 changed files with 37 additions and 4 deletions
+7 -4
View File
@@ -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,
);
@@ -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 });