"""Behind-the-scenes feedback storage (fine-tune signal).""" from __future__ import annotations import importlib import pytest @pytest.fixture def memory(tmp_path, monkeypatch): monkeypatch.setenv("LYRA_DB_PATH", str(tmp_path / "t.db")) from lyra import llm monkeypatch.setattr(llm, "embed", lambda texts: [[0.1, 0.2, 0.3] for _ in texts]) import lyra.memory as m importlib.reload(m) return m def test_rating_counts_and_upsert(memory): memory.add_rating("chat", 1, "good reply", context="hey") memory.add_rating("reflection", -1, "repetitive thought") assert memory.rating_counts() == {"total": 2, "up": 1, "down": 1} assert any(r["context"] == "hey" for r in memory.list_ratings()) # re-rating the same content replaces the row (no duplicate; flips the rating) memory.add_rating("chat", -1, "good reply") assert memory.rating_counts() == {"total": 2, "up": 0, "down": 2} assert any(r["content"] == "good reply" and r["rating"] == -1 for r in memory.list_ratings())