from pathlib import Path

from alembic.config import Config
from alembic.script import ScriptDirectory


def test_each_database_has_the_expected_independent_migration_head() -> None:
    backend_dir = Path(__file__).parents[1]
    expected_heads = {
        "alembic_core": "core_0007",
        "alembic_agent": "agent_0002",
        "alembic_analytics": "analytics_0001",
    }

    for section, expected_head in expected_heads.items():
        config = Config(backend_dir / "alembic.ini", ini_section=section)
        scripts = ScriptDirectory.from_config(config)
        assert scripts.get_current_head() == expected_head
