mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-13 19:10:39 +00:00
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { vi } from "vitest";
|
|
import "./test-runtime-mocks.js";
|
|
|
|
// Avoid exporting vitest mock types (TS2742 under pnpm + d.ts emit).
|
|
// oxlint-disable-next-line typescript/no-explicit-any
|
|
type AnyMock = any;
|
|
|
|
const hoisted = vi.hoisted(() => ({
|
|
embedBatch: vi.fn(async (texts: string[]) => texts.map(() => [0, 1, 0])),
|
|
embedQuery: vi.fn(async () => [0, 1, 0]),
|
|
}));
|
|
|
|
export function getEmbedBatchMock(): AnyMock {
|
|
return hoisted.embedBatch;
|
|
}
|
|
|
|
export function getEmbedQueryMock(): AnyMock {
|
|
return hoisted.embedQuery;
|
|
}
|
|
|
|
export function resetEmbeddingMocks(): void {
|
|
hoisted.embedBatch.mockReset();
|
|
hoisted.embedQuery.mockReset();
|
|
hoisted.embedBatch.mockImplementation(async (texts: string[]) => texts.map(() => [0, 1, 0]));
|
|
hoisted.embedQuery.mockImplementation(async () => [0, 1, 0]);
|
|
}
|
|
|
|
vi.mock("./embeddings.js", () => ({
|
|
createEmbeddingProvider: async () => ({
|
|
requestedProvider: "openai",
|
|
provider: {
|
|
id: "mock",
|
|
model: "mock-embed",
|
|
maxInputTokens: 8192,
|
|
embedQuery: hoisted.embedQuery,
|
|
embedBatch: hoisted.embedBatch,
|
|
},
|
|
}),
|
|
}));
|