mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-28 17:21:52 +00:00
perf(test): consolidate memory tool e2e suites
This commit is contained in:
@@ -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",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,18 +1,21 @@
|
|||||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
|
||||||
let backend: "builtin" | "qmd" = "builtin";
|
let backend: "builtin" | "qmd" = "builtin";
|
||||||
|
let searchImpl: () => Promise<unknown[]> = async () => [
|
||||||
|
{
|
||||||
|
path: "MEMORY.md",
|
||||||
|
startLine: 5,
|
||||||
|
endLine: 7,
|
||||||
|
score: 0.9,
|
||||||
|
snippet: "@@ -5,3 @@\nAssistant: noted",
|
||||||
|
source: "memory" as const,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
let readFileImpl: () => Promise<string> = async () => "";
|
||||||
|
|
||||||
const stubManager = {
|
const stubManager = {
|
||||||
search: vi.fn(async () => [
|
search: vi.fn(async () => await searchImpl()),
|
||||||
{
|
readFile: vi.fn(async () => await readFileImpl()),
|
||||||
path: "MEMORY.md",
|
|
||||||
startLine: 5,
|
|
||||||
endLine: 7,
|
|
||||||
score: 0.9,
|
|
||||||
snippet: "@@ -5,3 @@\nAssistant: noted",
|
|
||||||
source: "memory" as const,
|
|
||||||
},
|
|
||||||
]),
|
|
||||||
readFile: vi.fn(),
|
|
||||||
status: () => ({
|
status: () => ({
|
||||||
backend,
|
backend,
|
||||||
files: 1,
|
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(() => {
|
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();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -121,3 +136,46 @@ describe("memory search citations", () => {
|
|||||||
expect(details.results[0]?.snippet).not.toMatch(/Source:/);
|
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",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user