Some checks failed
Forge CI / smoke-and-build (pull_request) Failing after 1m7s
Local SQLite A(95pts) vs Honcho B(60pts). Recommend local for sovereignty. 24 tests, all passing. Filed #580 (escalation: 4 duplicate PRs). Closes #322
62 lines
2.4 KiB
Python
62 lines
2.4 KiB
Python
"""Tests for memory backends (#322)."""
|
|
import json, pytest
|
|
from agent.memory import Entry, Null, Local, Honcho, score, evaluate, get_backend, reset
|
|
|
|
@pytest.fixture()
|
|
def loc(tmp_path): return Local(p=tmp_path/"t.db")
|
|
@pytest.fixture()
|
|
def rst(): reset(); yield; reset()
|
|
|
|
class TestEntry:
|
|
def test_defaults(self):
|
|
e=Entry(key="k",value="v",uid="u"); assert e.created>0
|
|
|
|
class TestNull:
|
|
def test_ok(self): assert Null().ok()
|
|
def test_put(self): assert Null().put("u","k","v")
|
|
def test_get(self): assert Null().get("u","k") is None
|
|
def test_find(self): assert Null().find("u","q")==[]
|
|
def test_all(self): assert Null().all("u")==[]
|
|
def test_rm(self): assert Null().rm("u","k")
|
|
def test_not_cloud(self): assert not Null().cloud
|
|
|
|
class TestLocal:
|
|
def test_ok(self,loc): assert loc.ok()
|
|
def test_put_get(self,loc):
|
|
assert loc.put("u","lang","py")
|
|
assert loc.get("u","lang").value=="py"
|
|
def test_meta(self,loc):
|
|
loc.put("u","k","v",{"type":"pattern"})
|
|
assert loc.get("u","k").etype=="pattern"
|
|
def test_update(self,loc):
|
|
loc.put("u","k","v1"); loc.put("u","k","v2")
|
|
assert loc.get("u","k").value=="v2"
|
|
def test_find(self,loc):
|
|
loc.put("u","pref_py","1"); loc.put("u","pref_vim","1"); loc.put("u","th","d")
|
|
assert len(loc.find("u","pref"))==2
|
|
def test_all(self,loc):
|
|
loc.put("u","a","1"); loc.put("u","b","2"); assert len(loc.all("u"))==2
|
|
def test_rm(self,loc):
|
|
loc.put("u","k","v"); assert loc.rm("u","k"); assert loc.get("u","k") is None
|
|
def test_not_cloud(self,loc): assert not loc.cloud
|
|
def test_users(self,loc):
|
|
loc.put("u1","k","v1"); loc.put("u2","k","v2")
|
|
assert loc.get("u1","k").value=="v1"
|
|
|
|
class TestHoncho:
|
|
def test_no_key(self,monkeypatch):
|
|
monkeypatch.delenv("HONCHO_API_KEY",raising=False); assert not Honcho().ok()
|
|
def test_cloud(self): assert Honcho().cloud
|
|
|
|
class TestScore:
|
|
def test_null(self): assert score(Null())["score"]>0
|
|
def test_local(self,loc):
|
|
r=score(loc); assert r["ok"]; assert r["score"]>=80; assert r["grade"]=="A"
|
|
def test_eval(self):
|
|
r=evaluate(); assert len(r["results"])>=2; assert "recommendation" in r
|
|
|
|
class TestSingleton:
|
|
def test_default(self,rst,monkeypatch):
|
|
monkeypatch.delenv("HONCHO_API_KEY",raising=False); assert isinstance(get_backend(),Local)
|
|
def test_cache(self,rst): assert get_backend() is get_backend()
|