test(memory): cover owner isolation for memory search
Co-authored-by: Cata <cata@bigjohn.local> Co-authored-by: Alexandre Teixeira <111787685+alteixeira20@users.noreply.github.com>
This commit is contained in:
parent
20cf94f53d
commit
9d7a3d66c0
1 changed files with 28 additions and 0 deletions
28
tests/test_memory_owner_isolation.py
Normal file
28
tests/test_memory_owner_isolation.py
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
import routes.memory_routes as memory_routes
|
||||||
|
from src.memory import MemoryManager
|
||||||
|
|
||||||
|
|
||||||
|
def test_memory_search_returns_only_callers_memories(monkeypatch, tmp_path):
|
||||||
|
manager = MemoryManager(str(tmp_path))
|
||||||
|
alice_memory = manager.add_entry("Project codename is Odyssey", owner="alice")
|
||||||
|
bob_memory = manager.add_entry("Project codename is Odyssey", owner="bob")
|
||||||
|
manager.save([alice_memory, bob_memory])
|
||||||
|
|
||||||
|
monkeypatch.setattr(memory_routes, "get_current_user", lambda request: "bob")
|
||||||
|
router = memory_routes.setup_memory_routes(manager, MagicMock())
|
||||||
|
search = next(
|
||||||
|
route.endpoint
|
||||||
|
for route in router.routes
|
||||||
|
if route.path == "/api/memory/search" and "POST" in route.methods
|
||||||
|
)
|
||||||
|
|
||||||
|
result = search(
|
||||||
|
request=None,
|
||||||
|
query="Project codename is Odyssey",
|
||||||
|
session_id=None,
|
||||||
|
category=None,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert [memory["id"] for memory in result["memories"]] == [bob_memory["id"]]
|
||||||
Loading…
Add table
Reference in a new issue