45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""Episodic memory store: stable IDs, explicit synthesis states."""
|
|
|
|
from pathlib import Path
|
|
|
|
from rune.orchestration.memory import EpisodicRecord, EpisodicStore
|
|
|
|
|
|
def _rec(kind: str = "user.message") -> EpisodicRecord:
|
|
return EpisodicRecord(
|
|
episode_id="",
|
|
kind=kind,
|
|
evidence_refs=("sha256:a",),
|
|
created_at="2026-09-03T00:00:00Z",
|
|
)
|
|
|
|
|
|
def test_append_assigns_stable_id_and_persists(tmp_path: Path):
|
|
store = EpisodicStore(tmp_path / "episodes.jsonl")
|
|
rec = store.append(_rec())
|
|
assert rec.episode_id.startswith("ep_")
|
|
reopened = EpisodicStore(tmp_path / "episodes.jsonl")
|
|
assert reopened.get(rec.episode_id) == rec
|
|
|
|
|
|
def test_get_missing_returns_none(tmp_path: Path):
|
|
store = EpisodicStore(tmp_path / "episodes.jsonl")
|
|
assert store.get("ep_missing") is None
|
|
|
|
|
|
def test_all_preserves_insertion_order(tmp_path: Path):
|
|
store = EpisodicStore(tmp_path / "episodes.jsonl")
|
|
store.append(_rec("a"))
|
|
store.append(_rec("b"))
|
|
assert [r.kind for r in store.all()] == ["a", "b"]
|
|
|
|
|
|
def test_mark_synthesized_updates_state_exactly(tmp_path: Path):
|
|
store = EpisodicStore(tmp_path / "episodes.jsonl")
|
|
rec = store.append(_rec())
|
|
store.mark_synthesized(rec.episode_id, "synthesized")
|
|
assert store.get(rec.episode_id).synthesis_state == "synthesized"
|
|
# untouched records stay raw
|
|
other = store.append(_rec())
|
|
assert store.get(other.episode_id).synthesis_state == "raw"
|