From ee095f1ca2f8e88d581dfe3d1fe839a8b8df2c34 Mon Sep 17 00:00:00 2001 From: Garry Tan Date: Wed, 22 Jul 2026 11:22:40 -0700 Subject: [PATCH] test(progress): assert net-zero live-reporter leak, not process-global zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The signal-handler test asserted __liveReporterCountForTest() === 0 — a process-global absolute that any earlier test file in the same bun shard can poison (a production path that skips finish() on an error branch leaves one live entry behind). Shard-5 LPT packing started co-locating such a file before progress.test.ts, failing this test deterministically on CI across unrelated PRs while master stayed green by packing luck. Snapshot the count before the 50 lifecycles and assert no NET leak — the same prior-state tolerance the handler assertion already applies via installedBefore. The test still catches its own regression class (any leak from these lifecycles shows up as delta >= 1). Co-Authored-By: Claude Fable 5 --- test/progress.test.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/progress.test.ts b/test/progress.test.ts index 0e70e0d6f..29d5dddf6 100644 --- a/test/progress.test.ts +++ b/test/progress.test.ts @@ -218,15 +218,21 @@ describe('progress reporter', () => { test('only one process-level signal handler installed across many reporters', () => { // Baseline: one handler already installed by prior tests in this file. const installedBefore = __signalHandlerInstalledForTest(); + // liveReporters is process-global: earlier test files in the same shard + // can leave a live entry behind (e.g. a production path that skips + // finish() on an error branch). Assert NET-zero leak from THIS test's + // lifecycles, not an absolute zero we don't control — same tolerance + // the handler assertion below already applies via `installedBefore`. + const liveBefore = __liveReporterCountForTest(); const { stream } = sink(false); for (let i = 0; i < 50; i++) { const p = createProgress({ mode: 'json', stream, minIntervalMs: 0, minItems: 1 }); p.start(`phase_${i}`, 1); p.finish(); } - // After 50 reporter lifecycles, still exactly one handler and zero leaked live entries. + // After 50 reporter lifecycles, still exactly one handler and zero NEWLY leaked live entries. expect(__signalHandlerInstalledForTest()).toBe(installedBefore || true); - expect(__liveReporterCountForTest()).toBe(0); + expect(__liveReporterCountForTest()).toBe(liveBefore); }); test('startHeartbeat() fires heartbeats and stop() clears', async () => {