from grantflow.api.app import app
from grantflow.api.routers import include_api_routers


def test_import_contract_app_loads() -> None:
    assert app.title == "GrantFlow API"


def test_import_contract_routers_exports_include() -> None:
    assert callable(include_api_routers)


def test_import_contract_routers_are_owned_by_route_modules() -> None:
    from grantflow.api.routers import jobs_router as registry_jobs_router
    from grantflow.api.routes.jobs import jobs_router

    assert registry_jobs_router is jobs_router


def test_import_contract_legacy_private_exports_resolve_lazily() -> None:
    from grantflow.api.app import _resolve_export_inputs

    assert callable(_resolve_export_inputs)


def test_import_contract_legacy_exports_resolve_to_owner_modules() -> None:
    import pytest
    import grantflow.api.app as api_app_module
    from grantflow.api.compat_exports import APP_LEGACY_EXPORT_MODULES

    assert api_app_module._LEGACY_EXPORT_MODULES is APP_LEGACY_EXPORT_MODULES
    assert api_app_module._LEGACY_EXPORT_MODULES["_pause_for_hitl"] == "grantflow.api.review_service"
    assert callable(api_app_module._pause_for_hitl)
    with pytest.raises(AttributeError):
        getattr(api_app_module, "_definitely_not_a_legacy_export")
