From adf6b6a3b4c128f87c08a4e7c4545b35073736ca Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Tue, 13 Oct 2026 10:08:20 +0800 Subject: [PATCH] test(protocol): isolate upload staging fixtures Give cleanup tests a dedicated staging directory so they cannot remove files used by parallel upload tests. Refs #520 --- packages/protocol/tests/highway/stage.test.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/protocol/tests/highway/stage.test.ts b/packages/protocol/tests/highway/stage.test.ts index 3af7fa5d..91b6d8aa 100644 --- a/packages/protocol/tests/highway/stage.test.ts +++ b/packages/protocol/tests/highway/stage.test.ts @@ -1,10 +1,15 @@ -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { randomUUID } from 'crypto'; import fs, { promises as fsp } from 'fs'; import os from 'os'; import path from 'path'; import { pathToFileURL } from 'url'; -import { STAGE_DIR, stageSourceToDisk, sweepStagedUploads } from '@snowluma/protocol/highway/stage'; + +const stageRoot = await fsp.mkdtemp(path.join(os.tmpdir(), 'sl-proto-stage-root-')); +const tmpdir = vi.spyOn(os, 'tmpdir').mockReturnValue(stageRoot); +const { STAGE_DIR, stageSourceToDisk, sweepStagedUploads } = + await import('@snowluma/protocol/highway/stage'); +tmpdir.mockRestore(); const DOWNLOAD_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36'; @@ -56,9 +61,13 @@ afterEach(async () => { await fsp.rm(scratch, { recursive: true, force: true }); }); +afterAll(async () => { + await fsp.rm(stageRoot, { recursive: true, force: true }); +}); + describe('STAGE_DIR', () => { it('is os.tmpdir()/media-stage', () => { - expect(STAGE_DIR).toBe(path.join(os.tmpdir(), 'media-stage')); + expect(STAGE_DIR).toBe(path.join(stageRoot, 'media-stage')); }); });