File size: 849 Bytes
da65537
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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) == []