feat: add thread info and status reads
This commit is contained in:
16 files changed
+496
-33
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import uuid
|
||||
|
||||
from agentmsgs.stores.memory import InMemoryStore
|
||||
|
||||
|
||||
@@ -36,3 +38,51 @@ def test_memory_append_and_list():
|
||||
m2 = s.append_message(t.id, b, "yo")
|
||||
assert m1.seq == 1 and m2.seq == 2
|
||||
assert s.list_messages(t.id, after_seq=1) == [m2]
|
||||
|
||||
|
||||
def test_memory_thread_info_and_read_state():
|
||||
s = InMemoryStore()
|
||||
a = s.get_or_create_agent("A")
|
||||
b = s.get_or_create_agent("B")
|
||||
t = s.create_thread({a, b})
|
||||
s.append_message(t.id, a, "one")
|
||||
s.append_message(t.id, b, "two")
|
||||
m3 = s.append_message(t.id, a, "three")
|
||||
|
||||
info = s.get_thread_info(t.id)
|
||||
assert info is not None
|
||||
assert info.thread == t
|
||||
assert info.message_count == 3
|
||||
assert info.latest_message == m3
|
||||
|
||||
state = s.get_thread_read_state(t.id, a)
|
||||
assert state.agent == a
|
||||
assert state.cursor_seq == 0
|
||||
assert state.latest_seq == 3
|
||||
assert state.unread_count == 3
|
||||
assert state.unread_from_others_count == 1
|
||||
|
||||
s.set_cursor(t.id, a, 2)
|
||||
state = s.get_thread_read_state(t.id, a)
|
||||
assert state.cursor_seq == 2
|
||||
assert state.unread_count == 1
|
||||
assert state.unread_from_others_count == 0
|
||||
|
||||
|
||||
def test_memory_thread_info_for_empty_thread():
|
||||
s = InMemoryStore()
|
||||
a = s.get_or_create_agent("A")
|
||||
b = s.get_or_create_agent("B")
|
||||
t = s.create_thread({a, b})
|
||||
|
||||
info = s.get_thread_info(t.id)
|
||||
state = s.get_thread_read_state(t.id, a)
|
||||
|
||||
assert info is not None
|
||||
assert info.message_count == 0
|
||||
assert info.latest_message is None
|
||||
assert state.latest_seq == 0
|
||||
assert state.unread_count == 0
|
||||
assert state.unread_from_others_count == 0
|
||||
assert s.get_thread_info(uuid.uuid4()) is None
|
||||
assert s.get_thread_read_state(uuid.uuid4(), a) is None
|
||||
Reference in new issue
Block a user