|
11 | 11 | import fs from "node:fs/promises"; |
12 | 12 | import os from "node:os"; |
13 | 13 | import path from "node:path"; |
14 | | -import { describe, test, expect, beforeEach, afterEach } from "vitest"; |
| 14 | +import { describe, test, expect, beforeEach, afterEach, vi } from "vitest"; |
15 | 15 |
|
16 | 16 | const OPENAI_API_KEY = process.env.OPENAI_API_KEY ?? "test-key"; |
17 | 17 | const HAS_OPENAI_KEY = Boolean(process.env.OPENAI_API_KEY); |
@@ -135,6 +135,89 @@ describe("memory plugin e2e", () => { |
135 | 135 | expect(config?.autoRecall).toBe(true); |
136 | 136 | }); |
137 | 137 |
|
| 138 | + test("passes configured dimensions to OpenAI embeddings API", async () => { |
| 139 | + const embeddingsCreate = vi.fn(async () => ({ |
| 140 | + data: [{ embedding: [0.1, 0.2, 0.3] }], |
| 141 | + })); |
| 142 | + const toArray = vi.fn(async () => []); |
| 143 | + const limit = vi.fn(() => ({ toArray })); |
| 144 | + const vectorSearch = vi.fn(() => ({ limit })); |
| 145 | + |
| 146 | + vi.resetModules(); |
| 147 | + vi.doMock("openai", () => ({ |
| 148 | + default: class MockOpenAI { |
| 149 | + embeddings = { create: embeddingsCreate }; |
| 150 | + }, |
| 151 | + })); |
| 152 | + vi.doMock("@lancedb/lancedb", () => ({ |
| 153 | + connect: vi.fn(async () => ({ |
| 154 | + tableNames: vi.fn(async () => ["memories"]), |
| 155 | + openTable: vi.fn(async () => ({ |
| 156 | + vectorSearch, |
| 157 | + countRows: vi.fn(async () => 0), |
| 158 | + add: vi.fn(async () => undefined), |
| 159 | + delete: vi.fn(async () => undefined), |
| 160 | + })), |
| 161 | + })), |
| 162 | + })); |
| 163 | + |
| 164 | + try { |
| 165 | + const { default: memoryPlugin } = await import("./index.js"); |
| 166 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 167 | + const registeredTools: any[] = []; |
| 168 | + const mockApi = { |
| 169 | + id: "memory-lancedb", |
| 170 | + name: "Memory (LanceDB)", |
| 171 | + source: "test", |
| 172 | + config: {}, |
| 173 | + pluginConfig: { |
| 174 | + embedding: { |
| 175 | + apiKey: OPENAI_API_KEY, |
| 176 | + model: "text-embedding-3-small", |
| 177 | + dimensions: 1024, |
| 178 | + }, |
| 179 | + dbPath, |
| 180 | + autoCapture: false, |
| 181 | + autoRecall: false, |
| 182 | + }, |
| 183 | + runtime: {}, |
| 184 | + logger: { |
| 185 | + info: vi.fn(), |
| 186 | + warn: vi.fn(), |
| 187 | + error: vi.fn(), |
| 188 | + debug: vi.fn(), |
| 189 | + }, |
| 190 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 191 | + registerTool: (tool: any, opts: any) => { |
| 192 | + registeredTools.push({ tool, opts }); |
| 193 | + }, |
| 194 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 195 | + registerCli: vi.fn(), |
| 196 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 197 | + registerService: vi.fn(), |
| 198 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 199 | + on: vi.fn(), |
| 200 | + resolvePath: (p: string) => p, |
| 201 | + }; |
| 202 | + |
| 203 | + // oxlint-disable-next-line typescript/no-explicit-any |
| 204 | + memoryPlugin.register(mockApi as any); |
| 205 | + const recallTool = registeredTools.find((t) => t.opts?.name === "memory_recall")?.tool; |
| 206 | + expect(recallTool).toBeDefined(); |
| 207 | + await recallTool.execute("test-call-dims", { query: "hello dimensions" }); |
| 208 | + |
| 209 | + expect(embeddingsCreate).toHaveBeenCalledWith({ |
| 210 | + model: "text-embedding-3-small", |
| 211 | + input: "hello dimensions", |
| 212 | + dimensions: 1024, |
| 213 | + }); |
| 214 | + } finally { |
| 215 | + vi.doUnmock("openai"); |
| 216 | + vi.doUnmock("@lancedb/lancedb"); |
| 217 | + vi.resetModules(); |
| 218 | + } |
| 219 | + }); |
| 220 | + |
138 | 221 | test("shouldCapture applies real capture rules", async () => { |
139 | 222 | const { shouldCapture } = await import("./index.js"); |
140 | 223 |
|
|
0 commit comments