refactor(test): share memory embedding mocks

This commit is contained in:
Peter Steinberger
2026-02-15 14:48:23 +00:00
parent e2c68cb169
commit a7b6555195
3 changed files with 57 additions and 62 deletions

View File

@@ -2,34 +2,10 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
import { getEmbedBatchMock, resetEmbeddingMocks } from "./embedding.test-mocks.js";
import { getMemorySearchManager, type MemoryIndexManager } from "./index.js";
const embedBatch = vi.fn(async (texts: string[]) => texts.map(() => [0, 1, 0]));
const embedQuery = vi.fn(async () => [0, 1, 0]);
// Unit tests: avoid importing the real chokidar implementation (native fsevents, etc.).
vi.mock("chokidar", () => ({
default: {
watch: () => ({ on: () => {}, close: async () => {} }),
},
watch: () => ({ on: () => {}, close: async () => {} }),
}));
vi.mock("./sqlite-vec.js", () => ({
loadSqliteVecExtension: async () => ({ ok: false, error: "sqlite-vec disabled in tests" }),
}));
vi.mock("./embeddings.js", () => ({
createEmbeddingProvider: async () => ({
requestedProvider: "openai",
provider: {
id: "mock",
model: "mock-embed",
embedQuery,
embedBatch,
},
}),
}));
const embedBatch = getEmbedBatchMock();
describe("memory embedding batches", () => {
let fixtureRoot: string;
@@ -109,10 +85,7 @@ describe("memory embedding batches", () => {
});
beforeEach(async () => {
embedBatch.mockClear();
embedQuery.mockClear();
embedBatch.mockImplementation(async (texts: string[]) => texts.map(() => [0, 1, 0]));
embedQuery.mockImplementation(async () => [0, 1, 0]);
resetEmbeddingMocks();
await fs.rm(memoryDir, { recursive: true, force: true });
await fs.mkdir(memoryDir, { recursive: true });