test: reduce hotspot fixture overhead

This commit is contained in:
Peter Steinberger
2026-04-17 02:35:44 +01:00
parent 2cfb660a9b
commit 3a59eddd07
6 changed files with 68 additions and 48 deletions

View File

@@ -1,7 +1,7 @@
import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
import {
buildMultimodalChunkForIndexing,
buildFileEntry,
@@ -16,13 +16,24 @@ import {
type MemoryMultimodalSettings,
} from "./multimodal.js";
let sharedTempRoot = "";
let sharedTempId = 0;
beforeAll(async () => {
sharedTempRoot = await fs.mkdtemp(path.join(os.tmpdir(), "memory-host-sdk-tests-"));
});
afterAll(async () => {
if (sharedTempRoot) {
await fs.rm(sharedTempRoot, { recursive: true, force: true });
}
});
function setupTempDirLifecycle(prefix: string): () => string {
let tmpDir = "";
beforeEach(async () => {
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), prefix));
});
afterEach(async () => {
await fs.rm(tmpDir, { recursive: true, force: true });
tmpDir = path.join(sharedTempRoot, `${prefix}${sharedTempId++}`);
await fs.mkdir(tmpDir, { recursive: true });
});
return () => tmpDir;
}