diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 412cef9..d2d6008 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -47,4 +47,3 @@ jobs: # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md # or https://docs.claude.com/en/docs/claude-code/cli-reference for available options # claude_args: '--allowed-tools Bash(gh pr:*)' - diff --git a/tests/test_collector/conftest.py b/tests/test_collector/conftest.py index 1503d1c..c49ea91 100644 --- a/tests/test_collector/conftest.py +++ b/tests/test_collector/conftest.py @@ -1,8 +1,11 @@ """Fixtures for collector component tests.""" import pytest +from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine +from sqlalchemy.ext.asyncio import async_sessionmaker from meshcore_hub.common.database import DatabaseManager +from meshcore_hub.common.models.base import Base @pytest.fixture @@ -23,13 +26,26 @@ def db_session(db_manager): @pytest.fixture -async def async_db_session(db_manager): - """Create an async database session for testing.""" - # Create tables in async engine - async with db_manager.async_engine.begin() as conn: - await conn.run_sync(db_manager.engine.pool.echo) - # Tables already created by db_manager fixture with sync engine - # Async engine shares same database file, so tables exist +async def async_db_session(): + """Create an async database session for testing. - async with db_manager.async_session() as session: + Uses a separate in-memory database with tables created inline. + """ + # Create async engine with in-memory database + engine = create_async_engine("sqlite+aiosqlite:///:memory:") + + # Create tables + async with engine.begin() as conn: + await conn.run_sync(Base.metadata.create_all) + + # Create session factory + async_session_maker = async_sessionmaker( + engine, class_=AsyncSession, expire_on_commit=False + ) + + # Provide session + async with async_session_maker() as session: yield session + + # Cleanup + await engine.dispose() diff --git a/tests/test_collector/test_cleanup.py b/tests/test_collector/test_cleanup.py index 7220e5e..0b67688 100644 --- a/tests/test_collector/test_cleanup.py +++ b/tests/test_collector/test_cleanup.py @@ -30,7 +30,7 @@ async def test_cleanup_old_data_dry_run(async_db_session: AsyncSession) -> None: old_date = datetime.now(timezone.utc) - timedelta(days=60) old_adv = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=old_date, updated_at=old_date, ) @@ -40,7 +40,7 @@ async def test_cleanup_old_data_dry_run(async_db_session: AsyncSession) -> None: recent_date = datetime.now(timezone.utc) - timedelta(days=10) recent_adv = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=recent_date, updated_at=recent_date, ) @@ -81,45 +81,41 @@ async def test_cleanup_old_data_live(async_db_session: AsyncSession) -> None: old_adv = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=old_date, updated_at=old_date, ) async_db_session.add(old_adv) old_msg = Message( - node_id=node.id, - direction="recv", + receiver_node_id=node.id, message_type="channel", text="old message", - payload={}, created_at=old_date, updated_at=old_date, ) async_db_session.add(old_msg) old_telemetry = Telemetry( + receiver_node_id=node.id, node_id=node.id, - payload={}, + node_public_key=node.public_key, created_at=old_date, updated_at=old_date, ) async_db_session.add(old_telemetry) old_trace = TracePath( - node_id=node.id, - destination="c" * 64, - path_hashes=[], - payload={}, + receiver_node_id=node.id, + initiator_tag="test", created_at=old_date, updated_at=old_date, ) async_db_session.add(old_trace) old_event = EventLog( - node_id=node.id, + receiver_node_id=node.id, event_type="test_event", - payload={}, created_at=old_date, updated_at=old_date, ) @@ -130,7 +126,7 @@ async def test_cleanup_old_data_live(async_db_session: AsyncSession) -> None: recent_adv = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=recent_date, updated_at=recent_date, ) @@ -186,7 +182,7 @@ async def test_cleanup_respects_retention_period( # 90 days old - should be deleted with 30-day retention very_old = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=now - timedelta(days=90), updated_at=now - timedelta(days=90), ) @@ -195,7 +191,7 @@ async def test_cleanup_respects_retention_period( # 40 days old - should be deleted with 30-day retention old = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=now - timedelta(days=40), updated_at=now - timedelta(days=40), ) @@ -204,7 +200,7 @@ async def test_cleanup_respects_retention_period( # 20 days old - should be kept recent = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=now - timedelta(days=20), updated_at=now - timedelta(days=20), ) @@ -213,7 +209,7 @@ async def test_cleanup_respects_retention_period( # 5 days old - should be kept very_recent = Advertisement( node_id=node.id, - payload={}, + public_key=node.public_key, created_at=now - timedelta(days=5), updated_at=now - timedelta(days=5), )