fix: final review — atomic sqlite seq, remove shims and legacy types, cleanup

This commit is contained in:
lda
2026-09-01 02:10:35 +07:00 Verified
parent 0df23ea8d1
commit 8adb9984f0
11 changed files with 185 additions and 68 deletions
View File
+30 -15
View File
@@ -5,14 +5,20 @@ def test_sqlite_persists_across_handles():
with tempfile.TemporaryDirectory() as d:
p = pathlib.Path(d)/"test.db"
s1 = SQLiteStore(p)
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)
assert s2.get_agent_by_name("Alice").id == a.id
assert len(s2.list_messages(t.id)) == 1
assert s2.find_threads({a})[0].id == t.id
try:
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
assert len(s2.list_messages(t.id)) == 1
assert s2.find_threads({a})[0].id == t.id
finally:
s2.close()
finally:
s1.close()
def test_sqlite_concurrent_append():
import pathlib, tempfile
@@ -20,10 +26,19 @@ def test_sqlite_concurrent_append():
with tempfile.TemporaryDirectory() as d:
p = pathlib.Path(d)/"c.db"
s1 = SQLiteStore(p); s2 = SQLiteStore(p)
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})
s1.append_message(t.id, a, "from s1")
s2.append_message(t.id, b2, "from s2")
assert len(s1.list_messages(t.id)) == 2
try:
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})
s1.append_message(t.id, a, "from s1")
s2.append_message(t.id, b2, "from s2")
assert len(s1.list_messages(t.id)) == 2
# verify seq uniqueness and monotonicity
msgs = s1.list_messages(t.id)
seqs = [m.seq for m in msgs]
assert seqs == [1, 2]
assert len(set(seqs)) == 2
finally:
s2.close()
s1.close()