Files
mem0/integrations/eve/tests/recall.test.ts
T
Himanshu-SangshettiandCursor 10d6717068 fix(eve): scope forget, persist capture idempotency, and fail closed
Review findings: delete was not partitioned by scope.key, capture
replay after restart could double-write, and Mem0 errors were swallowed
as empty recall.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-09 10:48:26 +08:00

72 lines
1.9 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { formatRecallMessages, recallMemories } from "../src/recall.js";
import { createFakeStore } from "./helpers.js";
describe("formatRecallMessages", () => {
it("drops empty memories and empty ids", () => {
expect(
formatRecallMessages([
{ id: "1", memory: " likes tea " },
{ id: "2", memory: " " },
{ id: " ", memory: "kept text" },
]),
).toEqual([{ id: "1", content: "likes tea" }]);
});
});
describe("recallMemories", () => {
it("searches inside the locked scope and returns keyed messages", async () => {
const store = createFakeStore([{ id: "mem_1", memory: "User likes tea" }]);
const result = await recallMemories({
store,
scopeKey: "scope_abc",
query: "What does the user drink?",
topK: 3,
threshold: 0.5,
rerank: true,
});
expect(store.searched).toEqual([
{
query: "What does the user drink?",
userId: "scope_abc",
topK: 3,
threshold: 0.5,
rerank: true,
},
]);
expect(result).toEqual({
messages: [{ id: "mem_1", content: "User likes tea" }],
});
});
it("returns null for an empty query", async () => {
const store = createFakeStore([{ id: "mem_1", memory: "x" }]);
await expect(
recallMemories({
store,
scopeKey: "scope_abc",
query: " ",
topK: 5,
threshold: 0.1,
rerank: false,
}),
).resolves.toBeNull();
expect(store.searched).toEqual([]);
});
it("returns null when search has no usable hits", async () => {
const store = createFakeStore([{ id: " ", memory: " " }]);
await expect(
recallMemories({
store,
scopeKey: "scope_abc",
query: "tea",
topK: 5,
threshold: 0.1,
rerank: false,
}),
).resolves.toBeNull();
});
});