diff --git a/src/basic_memory/services.py b/src/basic_memory/services.py index 67b231cc..f9adadde 100644 --- a/src/basic_memory/services.py +++ b/src/basic_memory/services.py @@ -1,9 +1,8 @@ from datetime import datetime, UTC from pathlib import Path -from typing import Dict, Optional +from typing import Dict from uuid import uuid4 -from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.exc import IntegrityError from basic_memory.models import Entity @@ -31,9 +30,9 @@ class EntityService: Follows the "filesystem is source of truth" principle. """ - def __init__(self, project_path: Path, session: AsyncSession): + def __init__(self, project_path: Path, entity_repo: EntityRepository): self.project_path = project_path - self.entity_repo = EntityRepository(session, Entity) + self.entity_repo = entity_repo self.entities_path = project_path / "entities" @staticmethod diff --git a/tests/test_entity_service.py b/tests/test_entity_service.py index 2bc620a3..81dfd38a 100644 --- a/tests/test_entity_service.py +++ b/tests/test_entity_service.py @@ -7,6 +7,7 @@ from sqlalchemy.ext.asyncio import create_async_engine, async_sessionmaker from sqlalchemy.pool import StaticPool from basic_memory.models import Base, Entity +from basic_memory.repository import EntityRepository from basic_memory.services import EntityService, FileOperationError, DatabaseSyncError, EntityNotFoundError pytestmark = pytest.mark.asyncio @@ -38,14 +39,19 @@ async def session(engine): yield session @pytest_asyncio.fixture -async def entity_service(session): +async def entity_repo(session): + """Create an EntityRepository instance.""" + return EntityRepository(session, Entity) + +@pytest_asyncio.fixture +async def entity_service(session, entity_repo): """Fixture providing initialized EntityService with temp directories.""" with tempfile.TemporaryDirectory() as temp_dir: project_path = Path(temp_dir) / "test-project" entities_path = project_path / "entities" entities_path.mkdir(parents=True) - service = EntityService(project_path, session) + service = EntityService(project_path, entity_repo) yield service # Happy Path Tests