from pathlib import Path from amo.memory import MemoryStore def test_save_and_search_memory(tmp_path): store = MemoryStore(tmp_path / "memory.sqlite3") store.add("قرار المشروع: نستخدم SQLite للذاكرة المحلية", source="test", category="decision") hits = store.search("SQLite الذاكرة", limit=3) assert hits assert "SQLite" in hits[0]["content"] def test_save_and_export_training(tmp_path): store = MemoryStore(tmp_path / "memory.sqlite3") store.save_improvement( task="Improve add", before_code="def add(a,b): return a+b", after_code="def add(a, b):\n return a + b", tests_code="import unittest", summary="readability", before_score=90, after_score=95, test_status="passed", ) out = tmp_path / "train.jsonl" count = store.export_training_jsonl(out) assert count == 1 assert '"messages"' in out.read_text(encoding="utf-8") def test_memory_export_import_round_trip(tmp_path): first = MemoryStore(tmp_path / "first.sqlite3") first.add("حافظ على قرار الاختبارات وعدم تجاهل الخطأ", source="project", category="decision") path = tmp_path / "memory.jsonl" assert first.export_memory_jsonl(path) == 1 second = MemoryStore(tmp_path / "second.sqlite3") imported, notes = second.import_memory_jsonl(path) assert imported == 1 assert second.search("الاختبارات الخطأ", limit=3) assert not notes