"""Unit: the shared engine is a memoized singleton; dispose resets it.

create_async_engine does NOT open a connection, so identity checks need no
DB and run in CI (not integration-marked).
"""

import pytest

from backend.app import extensions


@pytest.mark.asyncio
async def test_get_engine_is_singleton():
    a = extensions.get_engine()
    b = extensions.get_engine()
    assert a is b
    await extensions.dispose_engine()


@pytest.mark.asyncio
async def test_dispose_engine_allows_fresh_engine():
    first = extensions.get_engine()
    await extensions.dispose_engine()
    second = extensions.get_engine()
    assert first is not second
    await extensions.dispose_engine()


def test_get_session_returns_async_context_manager():
    cm = extensions.get_session()
    assert hasattr(cm, "__aenter__") and hasattr(cm, "__aexit__")
