| 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")
|
| 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())
|
|
|