lingo-agent / tests /test_memory.py
lucsanscartier's picture
Add memory tests
da65537 verified
raw
history blame
849 Bytes
import importlib
def test_json_memory_roundtrip(tmp_path, monkeypatch):
memory_file = tmp_path / "memory.json"
monkeypatch.setenv("MEMORY_BACKEND", "json")
monkeypatch.setenv("MEMORY_FILE", str(memory_file))
monkeypatch.setenv("MAX_TURNS", "2")
import memory
memory = importlib.reload(memory)
phone = "+15551234567"
turns = [
{"role": "user", "content": "one"},
{"role": "assistant", "content": "two"},
{"role": "user", "content": "three"},
{"role": "assistant", "content": "four"},
{"role": "user", "content": "five"},
{"role": "assistant", "content": "six"},
]
memory.save(phone, turns)
loaded = memory.load(phone)
assert loaded == turns[-4:]
assert phone in memory.all_callers()
memory.clear(phone)
assert memory.load(phone) == []