From 99797a183beb96da863356e052d7e6af47a1dd96 Mon Sep 17 00:00:00 2001 From: anishamahuli Date: Thu, 5 Mar 2026 12:19:40 -0500 Subject: [PATCH] Add unit tests for normalize_facts covering all LLM fact shapes Tests plain strings, {"fact": ...}, {"text": ...}, mixed lists, and empty string filtering. --- tests/test_memory.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/test_memory.py b/tests/test_memory.py index 020093e1d..ed98e6ab8 100644 --- a/tests/test_memory.py +++ b/tests/test_memory.py @@ -5,6 +5,7 @@ import pytest from mem0 import Memory from mem0.configs.base import MemoryConfig +from mem0.memory.utils import normalize_facts class MockVectorMemory: @@ -294,3 +295,28 @@ def test_add_infer_with_malformed_llm_facts(mock_sqlite, mock_llm_factory, mock_ filters={"user_id": "test_user"}, infer=True, ) + + +def test_normalize_facts_plain_strings(): + assert normalize_facts(["fact one", "fact two"]) == ["fact one", "fact two"] + + +def test_normalize_facts_dict_with_fact_key(): + assert normalize_facts([{"fact": "User likes Python"}]) == ["User likes Python"] + + +def test_normalize_facts_dict_with_text_key(): + assert normalize_facts([{"text": "User is a developer"}]) == ["User is a developer"] + + +def test_normalize_facts_mixed(): + raw = [ + "plain string", + {"fact": "from fact key"}, + {"text": "from text key"}, + ] + assert normalize_facts(raw) == ["plain string", "from fact key", "from text key"] + + +def test_normalize_facts_filters_empty_strings(): + assert normalize_facts(["", "valid", ""]) == ["valid"]