Files
wehub-resource-sync 555e282cc4
pi-agent-plugin checks / lint (push) Has been cancelled
pi-agent-plugin checks / test (20) (push) Has been cancelled
pi-agent-plugin checks / test (22) (push) Has been cancelled
pi-agent-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / check_changes (push) Has been cancelled
TypeScript SDK CI / changelog_check (push) Has been cancelled
ci / changelog_check (push) Has been cancelled
ci / check_changes (push) Has been cancelled
ci / build_mem0 (3.10) (push) Has been cancelled
ci / build_mem0 (3.11) (push) Has been cancelled
ci / build_mem0 (3.12) (push) Has been cancelled
CLI Node CI / lint (push) Has been cancelled
CLI Node CI / test (20) (push) Has been cancelled
CLI Node CI / test (22) (push) Has been cancelled
CLI Node CI / build (push) Has been cancelled
CLI Python CI / lint (push) Has been cancelled
CLI Python CI / test (3.10) (push) Has been cancelled
CLI Python CI / test (3.11) (push) Has been cancelled
CLI Python CI / test (3.12) (push) Has been cancelled
CLI Python CI / build (push) Has been cancelled
openclaw checks / lint (push) Has been cancelled
openclaw checks / test (20) (push) Has been cancelled
openclaw checks / test (22) (push) Has been cancelled
openclaw checks / build (push) Has been cancelled
opencode-plugin checks / build (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / build_ts_sdk (22) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (20) (push) Has been cancelled
TypeScript SDK CI / integration_ts_sdk (22) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:03:45 +08:00

62 lines
2.3 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { buildToolExecute } from "../src/memory/tools.ts";
import type { ScopeContext } from "../src/types.ts";
const mockMem0 = {
search: vi.fn(),
add: vi.fn(),
getAll: vi.fn(),
delete: vi.fn(),
deleteAll: vi.fn(),
};
const scopeCtx: ScopeContext = {
userId: "testuser",
appId: "testproject",
runId: "session123",
};
describe("buildToolExecute", () => {
const execute = buildToolExecute(mockMem0 as any, scopeCtx, "project");
it("search calls mem0.search with correct filters", async () => {
mockMem0.search.mockResolvedValue({ results: [] });
await execute({ action: "search", query: "dark mode" });
expect(mockMem0.search).toHaveBeenCalledWith("dark mode", {
filters: { user_id: "testuser", app_id: "testproject" },
});
});
it("add calls mem0.add with customCategories and entity params", async () => {
mockMem0.add.mockResolvedValue([{ id: "new-id", memory: "test" }]);
await execute({ action: "add", content: "User likes tabs" });
const call = mockMem0.add.mock.calls[0];
expect(call[0]).toEqual([{ role: "user", content: "User likes tabs" }]);
expect(call[1].userId).toBe("testuser");
expect(call[1].appId).toBe("testproject");
expect(call[1].customCategories).toBeDefined();
expect(call[1].customCategories.length).toBe(10);
});
it("search with scope=global filters by user_id with app_id wildcard", async () => {
mockMem0.search.mockResolvedValue({ results: [] });
await execute({ action: "search", query: "preferences", scope: "global" });
expect(mockMem0.search).toHaveBeenCalledWith("preferences", {
filters: { user_id: "testuser", app_id: "*" },
});
});
it("delete calls mem0.delete with full memory_id", async () => {
mockMem0.delete.mockResolvedValue({ message: "deleted" });
await execute({ action: "delete", memory_id: "abc12345-6789-0abc-def0-123456789abc" });
expect(mockMem0.delete).toHaveBeenCalledWith("abc12345-6789-0abc-def0-123456789abc");
});
it("delete passes memory_id directly to mem0.delete", async () => {
const fullId = "956e3d68-b420-4e07-a4e3-3019e7cebe6f";
mockMem0.delete.mockResolvedValue({ message: "deleted" });
await execute({ action: "delete", memory_id: fullId });
expect(mockMem0.delete).toHaveBeenCalledWith(fullId);
});
});