fix(scripts): bound gateway watch log capture

This commit is contained in:
Vincent Koc
2026-05-28 08:45:18 +02:00
parent 00fb15253c
commit 0ade360da5
2 changed files with 75 additions and 13 deletions

View File

@@ -4,9 +4,12 @@ import os from "node:os";
import path from "node:path";
import { describe, expect, it, vi } from "vitest";
import {
appendBoundedWatchLog,
hasGatewayReadyLog,
shouldRefreshBuildStampForRestoredArtifacts,
stopTimedWatchChild,
updateWatchBuildDetection,
WATCH_LOG_CAPTURE_MAX_CHARS,
writeBuildAndRuntimePostBuildStamps,
} from "../../scripts/check-gateway-watch-regression.mjs";
import {
@@ -21,6 +24,34 @@ describe("check-gateway-watch-regression", () => {
expect(hasGatewayReadyLog("[gateway] starting HTTP server...")).toBe(false);
});
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 });
const second = appendBoundedWatchLog(first.text, "ghijkl", 8);
expect(second).toEqual({ text: "efghijkl", truncated: true });
expect(second.text).toHaveLength(8);
expect(WATCH_LOG_CAPTURE_MAX_CHARS).toBeGreaterThan(1024);
});
it("keeps build-regression detection after diagnostic logs truncate", () => {
const detected = updateWatchBuildDetection(
{ buffer: "", triggered: false, reason: null },
"Building TypeScript (dist is stale: source_mtime_newer)\n",
);
const afterNoise = updateWatchBuildDetection(detected, "x".repeat(10_000));
expect(afterNoise.triggered).toBe(true);
expect(afterNoise.reason).toBe("source_mtime_newer");
const coalesced = updateWatchBuildDetection(
{ buffer: "", triggered: false, reason: null },
`Building TypeScript (dist is stale: config_newer)\n${"x".repeat(10_000)}`,
);
expect(coalesced.triggered).toBe(true);
expect(coalesced.reason).toBe("config_newer");
});
it("refreshes restored build stamps only for skip-build config mtime drift", () => {
expect(
shouldRefreshBuildStampForRestoredArtifacts({