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:
co-authored by
Cursor
Kartik
parent
d2ff83cf72
commit
890473f891
@@ -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" });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user