mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:58:27 +00:00
perf(test): reduce fixture churn in hot suites
This commit is contained in:
@@ -144,6 +144,7 @@ describe("memory index", () => {
|
||||
throw new Error("manager missing");
|
||||
}
|
||||
await first.manager.sync({ force: true });
|
||||
const callsAfterFirstSync = embedBatchCalls;
|
||||
await first.manager.close();
|
||||
|
||||
const second = await getMemorySearchManager({
|
||||
@@ -168,8 +169,9 @@ describe("memory index", () => {
|
||||
}
|
||||
manager = second.manager;
|
||||
await second.manager.sync({ reason: "test" });
|
||||
const results = await second.manager.search("alpha");
|
||||
expect(results.length).toBeGreaterThan(0);
|
||||
expect(embedBatchCalls).toBeGreaterThan(callsAfterFirstSync);
|
||||
const status = second.manager.status();
|
||||
expect(status.files).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("reuses cached embeddings on forced reindex", async () => {
|
||||
@@ -280,7 +282,7 @@ describe("memory index", () => {
|
||||
});
|
||||
|
||||
it("hybrid weights can favor vector-only matches over keyword-only matches", async () => {
|
||||
const manyAlpha = Array.from({ length: 80 }, () => "Alpha").join(" ");
|
||||
const manyAlpha = Array.from({ length: 50 }, () => "Alpha").join(" ");
|
||||
await fs.writeFile(
|
||||
path.join(workspaceDir, "memory", "vector-only.md"),
|
||||
"Alpha beta. Alpha beta. Alpha beta. Alpha beta.",
|
||||
@@ -338,7 +340,7 @@ describe("memory index", () => {
|
||||
});
|
||||
|
||||
it("hybrid weights can favor keyword matches when text weight dominates", async () => {
|
||||
const manyAlpha = Array.from({ length: 80 }, () => "Alpha").join(" ");
|
||||
const manyAlpha = Array.from({ length: 50 }, () => "Alpha").join(" ");
|
||||
await fs.writeFile(
|
||||
path.join(workspaceDir, "memory", "vector-only.md"),
|
||||
"Alpha beta. Alpha beta. Alpha beta. Alpha beta.",
|
||||
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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 (texts: string[]) => texts.map(() => [0, 1, 0]));
|
||||
@@ -20,16 +20,26 @@ vi.mock("./embeddings.js", () => ({
|
||||
}));
|
||||
|
||||
describe("memory embedding batches", () => {
|
||||
let fixtureRoot: string;
|
||||
let caseId = 0;
|
||||
let workspaceDir: string;
|
||||
let indexPath: string;
|
||||
let manager: MemoryIndexManager | null = null;
|
||||
|
||||
beforeAll(async () => {
|
||||
fixtureRoot = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await fs.rm(fixtureRoot, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
beforeEach(async () => {
|
||||
embedBatch.mockClear();
|
||||
embedQuery.mockClear();
|
||||
workspaceDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-mem-"));
|
||||
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 () => {
|
||||
@@ -37,7 +47,6 @@ describe("memory embedding batches", () => {
|
||||
await manager.close();
|
||||
manager = null;
|
||||
}
|
||||
await fs.rm(workspaceDir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
it("splits large files across multiple embedding batches", async () => {
|
||||
|
||||
Reference in New Issue
Block a user