diff --git a/src/agents/tools/memory-tool.does-not-crash-on-errors.e2e.test.ts b/src/agents/tools/memory-tool.does-not-crash-on-errors.e2e.test.ts deleted file mode 100644 index 85535cedfe5..00000000000 --- a/src/agents/tools/memory-tool.does-not-crash-on-errors.e2e.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -import { describe, expect, it, vi } from "vitest"; - -vi.mock("../../memory/index.js", () => { - return { - getMemorySearchManager: async () => { - return { - manager: { - search: async () => { - throw new Error("openai embeddings failed: 429 insufficient_quota"); - }, - readFile: async () => { - throw new Error("path required"); - }, - status: () => ({ - files: 0, - chunks: 0, - dirty: true, - workspaceDir: "/tmp", - dbPath: "/tmp/index.sqlite", - provider: "openai", - model: "text-embedding-3-small", - requestedProvider: "openai", - }), - }, - }; - }, - }; -}); - -import { createMemoryGetTool, createMemorySearchTool } from "./memory-tool.js"; - -describe("memory tools", () => { - it("does not throw when memory_search fails (e.g. embeddings 429)", async () => { - const cfg = { agents: { list: [{ id: "main", default: true }] } }; - const tool = createMemorySearchTool({ config: cfg }); - expect(tool).not.toBeNull(); - if (!tool) { - throw new Error("tool missing"); - } - - const result = await tool.execute("call_1", { query: "hello" }); - expect(result.details).toEqual({ - results: [], - disabled: true, - error: "openai embeddings failed: 429 insufficient_quota", - }); - }); - - it("does not throw when memory_get fails", async () => { - const cfg = { agents: { list: [{ id: "main", default: true }] } }; - const tool = createMemoryGetTool({ config: cfg }); - expect(tool).not.toBeNull(); - if (!tool) { - throw new Error("tool missing"); - } - - const result = await tool.execute("call_2", { path: "memory/NOPE.md" }); - expect(result.details).toEqual({ - path: "memory/NOPE.md", - text: "", - disabled: true, - error: "path required", - }); - }); -}); diff --git a/src/agents/tools/memory-tool.citations.e2e.test.ts b/src/agents/tools/memory-tool.e2e.test.ts similarity index 69% rename from src/agents/tools/memory-tool.citations.e2e.test.ts rename to src/agents/tools/memory-tool.e2e.test.ts index 8e4d5c1b7fd..38e2caab24d 100644 --- a/src/agents/tools/memory-tool.citations.e2e.test.ts +++ b/src/agents/tools/memory-tool.e2e.test.ts @@ -1,18 +1,21 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; let backend: "builtin" | "qmd" = "builtin"; +let searchImpl: () => Promise = async () => [ + { + path: "MEMORY.md", + startLine: 5, + endLine: 7, + score: 0.9, + snippet: "@@ -5,3 @@\nAssistant: noted", + source: "memory" as const, + }, +]; +let readFileImpl: () => Promise = async () => ""; + const stubManager = { - search: vi.fn(async () => [ - { - path: "MEMORY.md", - startLine: 5, - endLine: 7, - score: 0.9, - snippet: "@@ -5,3 @@\nAssistant: noted", - source: "memory" as const, - }, - ]), - readFile: vi.fn(), + search: vi.fn(async () => await searchImpl()), + readFile: vi.fn(async () => await readFileImpl()), status: () => ({ backend, files: 1, @@ -37,9 +40,21 @@ vi.mock("../../memory/index.js", () => { }; }); -import { createMemorySearchTool } from "./memory-tool.js"; +import { createMemoryGetTool, createMemorySearchTool } from "./memory-tool.js"; beforeEach(() => { + backend = "builtin"; + searchImpl = async () => [ + { + path: "MEMORY.md", + startLine: 5, + endLine: 7, + score: 0.9, + snippet: "@@ -5,3 @@\nAssistant: noted", + source: "memory" as const, + }, + ]; + readFileImpl = async () => ""; vi.clearAllMocks(); }); @@ -121,3 +136,46 @@ describe("memory search citations", () => { expect(details.results[0]?.snippet).not.toMatch(/Source:/); }); }); + +describe("memory tools", () => { + it("does not throw when memory_search fails (e.g. embeddings 429)", async () => { + searchImpl = async () => { + throw new Error("openai embeddings failed: 429 insufficient_quota"); + }; + + const cfg = { agents: { list: [{ id: "main", default: true }] } }; + const tool = createMemorySearchTool({ config: cfg }); + expect(tool).not.toBeNull(); + if (!tool) { + throw new Error("tool missing"); + } + + const result = await tool.execute("call_1", { query: "hello" }); + expect(result.details).toEqual({ + results: [], + disabled: true, + error: "openai embeddings failed: 429 insufficient_quota", + }); + }); + + it("does not throw when memory_get fails", async () => { + readFileImpl = async () => { + throw new Error("path required"); + }; + + const cfg = { agents: { list: [{ id: "main", default: true }] } }; + const tool = createMemoryGetTool({ config: cfg }); + expect(tool).not.toBeNull(); + if (!tool) { + throw new Error("tool missing"); + } + + const result = await tool.execute("call_2", { path: "memory/NOPE.md" }); + expect(result.details).toEqual({ + path: "memory/NOPE.md", + text: "", + disabled: true, + error: "path required", + }); + }); +});