Download src/memory/embedding.test-mocks.ts from shimen/shinclaw: direct link, hf CLI and curl.
- Browser
- Download file 1.46 kB
-
https://huggingface.co/spaces/shimen/shinclaw/resolve/main/src/memory/embedding.test-mocks.ts
- Command line
-
hf download hf://spaces/shimen/shinclaw/src/memory/embedding.test-mocks.ts
-
curl -L -o embedding.test-mocks.ts https://huggingface.co/spaces/shimen/shinclaw/resolve/main/src/memory/embedding.test-mocks.ts
1.46 kB
| import { vi } from "vitest"; | |
| // 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]); | |
| } | |
| // 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", | |
| maxInputTokens: 8192, | |
| embedQuery: hoisted.embedQuery, | |
| embedBatch: hoisted.embedBatch, | |
| }, | |
| }), | |
| })); | |