style: ruff format + stronger sqlite asserts (delete utils, drop test_no_gng)

This commit is contained in:
lda
2026-09-01 02:56:39 +07:00 Verified
parent 8adb9984f0
commit 41652c3a16
14 changed files with 149 additions and 80 deletions
+28 -11
View File
@@ -1,18 +1,24 @@
import tempfile, pathlib
import pathlib
import tempfile
from agentmsgs.stores.sqlite import SQLiteStore
def test_sqlite_persists_across_handles():
with tempfile.TemporaryDirectory() as d:
p = pathlib.Path(d)/"test.db"
p = pathlib.Path(d) / "test.db"
s1 = SQLiteStore(p)
try:
a = s1.get_or_create_agent("Alice"); b = s1.get_or_create_agent("Bob")
t = s1.create_thread({a,b})
a = s1.get_or_create_agent("Alice")
b = s1.get_or_create_agent("Bob")
t = s1.create_thread({a, b})
s1.append_message(t.id, a, "hi")
# new handle same file
s2 = SQLiteStore(p)
try:
assert s2.get_agent_by_name("Alice").id == a.id
a2 = s2.get_agent_by_name("Alice")
assert a2 is not None
assert a2.id == a.id
assert len(s2.list_messages(t.id)) == 1
assert s2.find_threads({a})[0].id == t.id
finally:
@@ -20,17 +26,28 @@ def test_sqlite_persists_across_handles():
finally:
s1.close()
def test_sqlite_concurrent_append():
import pathlib, tempfile
import pathlib
import tempfile
from agentmsgs.stores.sqlite import SQLiteStore
with tempfile.TemporaryDirectory() as d:
p = pathlib.Path(d)/"c.db"
s1 = SQLiteStore(p); s2 = SQLiteStore(p)
p = pathlib.Path(d) / "c.db"
s1 = SQLiteStore(p)
s2 = SQLiteStore(p)
try:
a = s1.get_or_create_agent("A"); b = s1.get_or_create_agent("B")
a = s1.get_or_create_agent("A")
b = s1.get_or_create_agent("B")
# s2 sees same agents via file
a2 = s2.get_agent_by_name("A"); b2 = s2.get_agent_by_name("B")
t = s1.create_thread({a,b})
a2 = s2.get_agent_by_name("A")
b2 = s2.get_agent_by_name("B")
assert a2 is not None
assert b2 is not None
assert a.id == a2.id
assert b.id == b2.id
t = s1.create_thread({a, b})
s1.append_message(t.id, a, "from s1")
s2.append_message(t.id, b2, "from s2")
assert len(s1.list_messages(t.id)) == 2