You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.2 KiB
Python
75 lines
2.2 KiB
Python
from datetime import timedelta
|
|
from types import SimpleNamespace
|
|
|
|
from src.ircfa_interaction.memory_lifecycle import (
|
|
MEMORY_ACTIVE,
|
|
MEMORY_ARCHIVED,
|
|
MEMORY_EXPIRED,
|
|
memory_duplicate_count,
|
|
memory_lifecycle,
|
|
new_memory_metadata,
|
|
refresh_duplicate_metadata,
|
|
update_memory_controls,
|
|
utc_now,
|
|
)
|
|
|
|
|
|
def memory_with(metadata):
|
|
return SimpleNamespace(metadata_json=metadata)
|
|
|
|
|
|
def test_memory_lab_test_note_expires_after_seven_days():
|
|
now = utc_now()
|
|
memory = memory_with(
|
|
new_memory_metadata(
|
|
files=None,
|
|
saved_images=None,
|
|
message_id="message-1",
|
|
message="Please remember this harmless Memory Lab test note: bluebird-4829.",
|
|
now=now,
|
|
)
|
|
)
|
|
|
|
assert memory_lifecycle(memory, now) == MEMORY_ACTIVE
|
|
assert memory_lifecycle(memory, now + timedelta(days=7, seconds=1)) == MEMORY_EXPIRED
|
|
|
|
|
|
def test_archived_memory_stays_archived_and_can_be_restored():
|
|
now = utc_now()
|
|
memory = memory_with({"lifecycle": MEMORY_ACTIVE, "pinned": False})
|
|
|
|
memory.metadata_json = update_memory_controls(memory, lifecycle=MEMORY_ARCHIVED, now=now)
|
|
assert memory_lifecycle(memory, now) == MEMORY_ARCHIVED
|
|
|
|
memory.metadata_json = update_memory_controls(memory, lifecycle=MEMORY_ACTIVE, now=now)
|
|
assert memory_lifecycle(memory, now) == MEMORY_ACTIVE
|
|
|
|
|
|
def test_restoring_an_expired_memory_removes_its_expiry_date():
|
|
now = utc_now()
|
|
memory = memory_with({
|
|
"lifecycle": MEMORY_ACTIVE,
|
|
"expires_at": (now - timedelta(seconds=1)).isoformat(),
|
|
})
|
|
|
|
memory.metadata_json = update_memory_controls(memory, lifecycle=MEMORY_ACTIVE, now=now)
|
|
|
|
assert "expires_at" not in memory.metadata_json
|
|
assert memory_lifecycle(memory, now) == MEMORY_ACTIVE
|
|
|
|
|
|
def test_repeated_memory_request_refreshes_one_record_metadata():
|
|
now = utc_now()
|
|
memory = memory_with({"remember_count": 1, "lifecycle": MEMORY_ACTIVE})
|
|
|
|
refreshed = refresh_duplicate_metadata(
|
|
memory,
|
|
message_id="message-2",
|
|
message="Please remember the same technical note.",
|
|
now=now,
|
|
)
|
|
|
|
assert refreshed["lifecycle"] == MEMORY_ACTIVE
|
|
assert refreshed["message_id"] == "message-2"
|
|
assert memory_duplicate_count(memory_with(refreshed)) == 2
|