diff options
| author | batsumaru <> | 2026-09-17 11:07:06 +0900 |
|---|---|---|
| committer | batsumaru <> | 2026-09-17 11:07:06 +0900 |
| commit | c22cdbffa50ac634f7fecf080f3c3b5662e67131 (patch) | |
| tree | 9d3aba8d47c5dfc5bd4c5972edc7a3a579afbe18 /tests | |
| parent | 71879695b951dd30bbd6cbd25261e22ac7f8e5d1 (diff) | |
Added importance
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/test_memory_store.py | 57 | ||||
| -rw-r--r-- | tests/test_memory_tools.py | 82 |
2 files changed, 139 insertions, 0 deletions
diff --git a/tests/test_memory_store.py b/tests/test_memory_store.py index b83d217..f24f975 100644 --- a/tests/test_memory_store.py +++ b/tests/test_memory_store.py @@ -122,6 +122,7 @@ def test_created_at_round_trips_as_utc(tmp_path): content="UTC timestamp test.", category=MemoryCategory.SEMANTIC, created_at=created_at, + importance=2, ) store.add(memory) @@ -270,3 +271,59 @@ def test_search_filters_by_category(tmp_path): ) assert [result.id for result in results] == [episodic.id] + + +def test_importance_round_trips_through_get(tmp_path): + store = create_store(tmp_path) + + memory = LongTermMemory.create( + "High importance memory.", + MemoryCategory.SEMANTIC, + 3, + ) + + store.add(memory) + + result = store.get(memory.id) + + assert result is not None + assert result.importance == 3 + + +def test_importance_round_trips_through_list(tmp_path): + store = create_store(tmp_path) + + first = LongTermMemory.create( + "Minor memory.", + MemoryCategory.SEMANTIC, + 1, + ) + second = LongTermMemory.create( + "Important memory.", + MemoryCategory.SEMANTIC, + 3, + ) + + store.add(first) + store.add(second) + + result = store.list() + + assert [memory.importance for memory in result] == [1, 3] + + +def test_importance_round_trips_through_search(tmp_path): + store = create_store(tmp_path) + + memory = LongTermMemory.create( + "Important Rust preference.", + MemoryCategory.SEMANTIC, + 3, + ) + + store.add(memory) + + result = store.search("Rust") + + assert len(result) == 1 + assert result[0].importance == 3 diff --git a/tests/test_memory_tools.py b/tests/test_memory_tools.py index 9e0fcb0..89a3e93 100644 --- a/tests/test_memory_tools.py +++ b/tests/test_memory_tools.py @@ -23,6 +23,7 @@ def test_save_tool_persists_memory(tmp_path): { "content": "User prefers Rust for systems programming.", "category": "semantic", + "importance": 2, } ) @@ -31,6 +32,7 @@ def test_save_tool_persists_memory(tmp_path): assert len(memories) == 1 assert memories[0].content == "User prefers Rust for systems programming." assert memories[0].category is MemoryCategory.SEMANTIC + assert memories[0].importance == 2 assert str(memories[0].id) in result.content @@ -55,6 +57,7 @@ def test_save_tool_rejects_invalid_category(tmp_path): { "content": "Something", "category": "invalid", + "importance": 2, } ) except ToolError as error: @@ -72,12 +75,14 @@ def test_search_tool_returns_matching_memories(tmp_path): { "content": "User prefers Rust for systems programming.", "category": "semantic", + "importance": 2, } ) save_tool.execute( { "content": "User visited Tokyo last year.", "category": "episodic", + "importance": 2, } ) @@ -96,12 +101,14 @@ def test_search_tool_can_filter_category(tmp_path): { "content": "User likes Rust.", "category": "semantic", + "importance": 2, } ) save_tool.execute( { "content": "User worked on a Rust project last summer.", "category": "episodic", + "importance": 2, } ) @@ -109,6 +116,7 @@ def test_search_tool_can_filter_category(tmp_path): { "query": "Rust", "category": "episodic", + "importance": 2, } ) @@ -146,6 +154,7 @@ def test_delete_tool_removes_memory(tmp_path): { "content": "User likes Rust.", "category": "semantic", + "importance": 2, } ) @@ -167,3 +176,76 @@ def test_delete_tool_rejects_invalid_id(tmp_path): assert str(error) == "id must be a valid UUID" else: raise AssertionError("Expected ToolError") + + +def test_save_tool_persists_importance(tmp_path): + store = create_store(tmp_path) + tool = LongTermMemorySaveTool(store) + + tool.execute( + { + "content": "Especially important user preference.", + "category": "semantic", + "importance": 3, + } + ) + + memories = store.list() + + assert len(memories) == 1 + assert memories[0].importance == 3 + + +def test_save_tool_rejects_invalid_importance(tmp_path): + store = create_store(tmp_path) + tool = LongTermMemorySaveTool(store) + + for importance in (0, 4): + try: + tool.execute( + { + "content": "Invalid importance.", + "category": "semantic", + "importance": importance, + } + ) + except ToolError as error: + assert str(error) == "importance must be between 1 and 3" + else: + raise AssertionError("Expected ToolError") + + +def test_save_tool_rejects_non_integer_importance(tmp_path): + store = create_store(tmp_path) + tool = LongTermMemorySaveTool(store) + + try: + tool.execute( + { + "content": "Invalid importance.", + "category": "semantic", + "importance": "3", + } + ) + except ToolError as error: + assert str(error) == "importance must be an integer" + else: + raise AssertionError("Expected ToolError") + + +def test_save_tool_rejects_boolean_importance(tmp_path): + store = create_store(tmp_path) + tool = LongTermMemorySaveTool(store) + + try: + tool.execute( + { + "content": "Invalid importance.", + "category": "semantic", + "importance": True, + } + ) + except ToolError as error: + assert str(error) == "importance must be an integer" + else: + raise AssertionError("Expected ToolError") |
