a digital entity named phi that roams bsky
1"""Smoke test for memory system using real .env credentials."""
2
3import pytest
4
5from bot.config import Settings
6from bot.memory import NamespaceMemory
7
8
9@pytest.fixture
10async def memory():
11 s = Settings()
12 if not s.turbopuffer_api_key or not s.openai_api_key:
13 pytest.skip("needs TURBOPUFFER_API_KEY and OPENAI_API_KEY in .env")
14 mem = NamespaceMemory(api_key=s.turbopuffer_api_key)
15 yield mem
16 await mem.close()
17
18
19async def test_build_user_context_old_namespace(memory):
20 """build_user_context should not crash on namespaces without 'kind' column."""
21 # this handle has old data without the kind attribute
22 ctx = await memory.build_user_context(
23 "zzstoatzzdevlog.bsky.social",
24 query_text="hello",
25 include_core=False,
26 )
27 print(f"\n--- context ---\n{ctx}\n---")
28 assert isinstance(ctx, str)
29
30
31async def test_store_and_retrieve(memory):
32 """Round-trip: store interaction, then retrieve it."""
33 handle = "smoke-test.example"
34 await memory.store_interaction(handle, "i like rust", "rust is great!")
35
36 ctx = await memory.build_user_context(handle, query_text="rust", include_core=False)
37 print(f"\n--- context ---\n{ctx}\n---")
38 assert "rust" in ctx.lower()
39
40
41async def test_search_old_namespace(memory):
42 """search should work on namespaces without 'kind' column."""
43 results = await memory.search("zzstoatzzdevlog.bsky.social", "hello", top_k=3)
44 print(f"\n--- search results ---\n{results}\n---")
45 assert isinstance(results, list)