fix(core): validate and trim entity IDs in delete_all() (#5735)

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Kartik <kartik.labhshetwar@mem0.ai>
This commit is contained in:
rafid001
2026-06-25 16:14:30 +05:30
committed by GitHub
co-authored by Cursor Kartik
parent d2ff83cf72
commit 890473f891
4 changed files with 52 additions and 1 deletions
@@ -314,4 +314,27 @@ describe("Memory Input Validation", () => {
expect(result.results).toBeDefined();
});
});
describe("deleteAll() entity ID validation", () => {
it("should throw error when userId is whitespace-only", async () => {
await expect(memory.deleteAll({ userId: " " })).rejects.toThrow(
"Invalid userId",
);
});
it("should throw error when userId contains internal whitespace", async () => {
await expect(memory.deleteAll({ userId: "user 123" })).rejects.toThrow(
"Invalid userId: cannot contain whitespace",
);
});
it("should trim userId before listing memories", async () => {
const listSpy = jest.spyOn(memory["vectorStore"], "list");
listSpy.mockResolvedValue([[], null]);
await memory.deleteAll({ userId: " alice " });
expect(listSpy).toHaveBeenCalledWith({ user_id: "alice" });
});
});
});