File size: 1,418 Bytes
0366d65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime

import pytest

from server import memory
from server.agent import build_messages
from server.schema import ActionPlan, Event


@pytest.fixture(autouse=True)
def _clean_mem():
    memory.reset()
    yield
    memory.reset()


def test_remember_recall_forget():
    f = memory.remember("Dana is the soccer coach", "contact")
    assert f and f["id"] >= 1
    assert "Dana is the soccer coach" in memory.recall()
    assert memory.forget(f["id"])
    assert memory.recall() == ""


def test_remember_dedupes_and_bumps_weight():
    a = memory.remember("you decline Mondays", "preference")
    b = memory.remember("You decline Mondays", "preference")  # same after normalize
    assert a["id"] == b["id"]
    facts = memory.list_facts()
    assert len(facts) == 1 and facts[0]["weight"] == 2


def test_recall_injected_into_prompt():
    memory.remember("you decline Mondays", "preference")
    msgs = build_messages("lunch?", datetime(2026, 6, 7, 9, 0), [])
    assert "you decline Mondays" in msgs[-1]["content"]


def test_recall_empty_when_no_facts():
    assert memory.recall() == ""


def test_observe_plan_learns_contacts():
    plan = ActionPlan(
        events=[Event(title="Lunch", start="2026-06-09T13:00:00", attendees=["Alex"])]
    )
    memory.observe_plan(plan)
    assert any("Alex" in f["text"] for f in memory.list_facts())