perf(test): trim fixture and import overhead in hot suites

This commit is contained in:
Peter Steinberger
2026-02-13 22:28:50 +00:00
parent b8703546e9
commit dac8f5ba3f
10 changed files with 262 additions and 166 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";
let embedBatchCalls = 0;
@@ -34,14 +34,25 @@ vi.mock("./embeddings.js", () => {
});
describe("memory index", () => {
let fixtureRoot = "";
let fixtureCount = 0;
let workspaceDir: string;
let indexPath: string;
let manager: MemoryIndexManager | null = null;
beforeAll(async () => {
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-fixtures-"));
});
afterAll(async () => {
await fs.rm(fixtureRoot, { recursive: true, force: true });
});
beforeEach(async () => {
embedBatchCalls = 0;
failEmbeddings = false;
workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-"));
workspaceDir = path.join(fixtureRoot, `case-${fixtureCount++}`);
await fs.mkdir(workspaceDir, { recursive: true });
indexPath = path.join(workspaceDir, "index.sqlite");
await fs.mkdir(path.join(workspaceDir, "memory"));
await fs.writeFile(
@@ -56,7 +67,6 @@ describe("memory index", () => {
await manager.close();
manager = null;
}
await fs.rm(workspaceDir, { recursive: true, force: true });
});
it("indexes memory files and searches by vector", async () => {
@@ -270,7 +280,7 @@ describe("memory index", () => {
});
it("hybrid weights can favor vector-only matches over keyword-only matches", async () => {
const manyAlpha = Array.from({ length: 200 }, () => "Alpha").join(" ");
const manyAlpha = Array.from({ length: 80 }, () => "Alpha").join(" ");
await fs.writeFile(
path.join(workspaceDir, "memory", "vector-only.md"),
"Alpha beta. Alpha beta. Alpha beta. Alpha beta.",
@@ -328,7 +338,7 @@ describe("memory index", () => {
});
it("hybrid weights can favor keyword matches when text weight dominates", async () => {
const manyAlpha = Array.from({ length: 200 }, () => "Alpha").join(" ");
const manyAlpha = Array.from({ length: 80 }, () => "Alpha").join(" ");
await fs.writeFile(
path.join(workspaceDir, "memory", "vector-only.md"),
"Alpha beta. Alpha beta. Alpha beta. Alpha beta.",