From 8ab6ccaf1da4f2d63f8513cd9f118ba894b53679 Mon Sep 17 00:00:00 2001 From: Gergo Magyar Date: Wed, 20 May 2026 07:52:29 +0100 Subject: [PATCH] test(workers): cleanup leaked temp-dirs and drop duplicate option-resolution block - Add afterEach to worker-pool-resilience.test.ts cleaning up the per-test temp directory created by beforeEach (~25 stale dirs per CI run previously). - Delete the duplicated describe('worker pool option resolution', ...) block. Verified the first block (lines 490-532) is a strict superset (includes the GITNEXUS_WORKER_MAX_CUMULATIVE_TIMEOUT_MS env test the second block omitted), so deletion loses no test coverage. Addresses PR #1693 review findings L2 (temp-dir leak) and L3 (duplicate block). --- .../test/unit/worker-pool-resilience.test.ts | 45 ++++--------------- 1 file changed, 9 insertions(+), 36 deletions(-) diff --git a/gitnexus/test/unit/worker-pool-resilience.test.ts b/gitnexus/test/unit/worker-pool-resilience.test.ts index 2f8635630..2212ed080 100644 --- a/gitnexus/test/unit/worker-pool-resilience.test.ts +++ b/gitnexus/test/unit/worker-pool-resilience.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it, vi, beforeEach } from 'vitest'; +import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; import { EventEmitter } from 'node:events'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; @@ -111,6 +111,14 @@ beforeEach(() => { workerUrl = pathToFileURL(workerPath) as URL; }); +afterEach(() => { + try { + fs.rmSync(tempDir, { recursive: true, force: true }); + } catch { + // best-effort cleanup — directory may already be gone if a test removed it + } +}); + describe('worker pool resilience', () => { it('seeds an empty quarantine on a fresh pool', () => { const pool = createWorkerPool(workerUrl, 1, { @@ -581,38 +589,3 @@ describe('resolveAutoPoolSize', () => { expect(Number.isInteger(resolveAutoPoolSize())).toBe(true); }); }); - -describe('worker pool option resolution', () => { - it('resolves maxRespawnsPerSlot from explicit options', () => { - const opts = resolveWorkerPoolOptions({ maxRespawnsPerSlot: 7 }, 4); - expect(opts.maxRespawnsPerSlot).toBe(7); - }); - - it('defaults consecutiveFailureThreshold to max(3, poolSize)', () => { - expect(resolveWorkerPoolOptions({}, 1).consecutiveFailureThreshold).toBe(3); - expect(resolveWorkerPoolOptions({}, 8).consecutiveFailureThreshold).toBe(8); - }); - - it('defaults maxCumulativeTimeoutMs to 5x subBatchIdleTimeoutMs', () => { - const opts = resolveWorkerPoolOptions({ subBatchIdleTimeoutMs: 1000 }, 1); - expect(opts.maxCumulativeTimeoutMs).toBe(5000); - }); - - it('reads GITNEXUS_WORKER_MAX_RESPAWNS_PER_SLOT env override', () => { - vi.stubEnv('GITNEXUS_WORKER_MAX_RESPAWNS_PER_SLOT', '2'); - try { - expect(resolveWorkerPoolOptions({}, 1).maxRespawnsPerSlot).toBe(2); - } finally { - vi.unstubAllEnvs(); - } - }); - - it('reads GITNEXUS_WORKER_CONSECUTIVE_FAILURE_THRESHOLD env override', () => { - vi.stubEnv('GITNEXUS_WORKER_CONSECUTIVE_FAILURE_THRESHOLD', '12'); - try { - expect(resolveWorkerPoolOptions({}, 1).consecutiveFailureThreshold).toBe(12); - } finally { - vi.unstubAllEnvs(); - } - }); -});