perf(test): reduce fixture churn in hot suites

This commit is contained in:
Peter Steinberger
2026-02-13 22:40:20 +00:00
parent dac8f5ba3f
commit e324cb5b94
5 changed files with 237 additions and 133 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, vi } from "vitest";
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
const embedBatch = vi.fn(async () => []);
@@ -25,11 +25,21 @@ vi.mock("./embeddings.js", () => ({
}));
describe("memory indexing with OpenAI batches", () => {
let fixtureRoot: string;
let caseId = 0;
let workspaceDir: string;
let indexPath: string;
let manager: MemoryIndexManager | null = null;
let setTimeoutSpy: ReturnType<typeof vi.spyOn>;
beforeAll(async () => {
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-batch-"));
});
afterAll(async () => {
await fs.rm(fixtureRoot, { recursive: true, force: true });
});
beforeEach(async () => {
embedBatch.mockClear();
embedQuery.mockClear();
@@ -48,9 +58,9 @@ describe("memory indexing with OpenAI batches", () => {
}
return realSetTimeout(handler, delay, ...args);
}) as typeof setTimeout);
workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-batch-"));
workspaceDir = path.join(fixtureRoot, `case-${++caseId}`);
indexPath = path.join(workspaceDir, "index.sqlite");
await fs.mkdir(path.join(workspaceDir, "memory"));
await fs.mkdir(path.join(workspaceDir, "memory"), { recursive: true });
});
afterEach(async () => {
@@ -60,7 +70,6 @@ describe("memory indexing with OpenAI batches", () => {
await manager.close();
manager = null;
}
await fs.rm(workspaceDir, { recursive: true, force: true });
});
it("uses OpenAI batch uploads when enabled", async () => {