from __future__ import annotations import sys import types from pathlib import Path from tests.conftest import ( REPO_ROOT, SERVICE_IMPORT_CONFIGS, build_postgres_database_url, prepare_known_service_import, ) def test_prepare_known_service_import_resets_app_modules_and_orders_paths() -> None: sys.modules["app"] = types.ModuleType("app") sys.modules["app.fake"] = types.ModuleType("app.fake") prepare_known_service_import("agent-service") assert "app" not in sys.modules assert "app.fake" not in sys.modules assert sys.path[0] == str(REPO_ROOT / "services" / "agent-service") def test_service_import_configs_cover_services_with_database_tests() -> None: assert "agent-service" in SERVICE_IMPORT_CONFIGS assert "session-service" in SERVICE_IMPORT_CONFIGS assert "core-db" in SERVICE_IMPORT_CONFIGS["agent-service"].libs def test_build_postgres_database_url_uses_isolated_schema(tmp_path: Path) -> None: database_url = build_postgres_database_url(tmp_path, "service") assert database_url.startswith("postgresql+psycopg://") assert "options=-csearch_path%3Dtest_" in database_url assert "%2Cpublic" not in database_url def test_gitlab_ci_installs_services_used_by_tests() -> None: ci_text = (REPO_ROOT / ".gitlab-ci.yml").read_text(encoding="utf-8") assert "pip install -e services/agent-service" in ci_text assert "pip install -e services/knowledge-service" in ci_text