test_test_harness.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from __future__ import annotations
  2. import sys
  3. import types
  4. from pathlib import Path
  5. from tests.conftest import (
  6. REPO_ROOT,
  7. SERVICE_IMPORT_CONFIGS,
  8. build_postgres_database_url,
  9. prepare_known_service_import,
  10. )
  11. def test_prepare_known_service_import_resets_app_modules_and_orders_paths() -> None:
  12. sys.modules["app"] = types.ModuleType("app")
  13. sys.modules["app.fake"] = types.ModuleType("app.fake")
  14. prepare_known_service_import("agent-service")
  15. assert "app" not in sys.modules
  16. assert "app.fake" not in sys.modules
  17. assert sys.path[0] == str(REPO_ROOT / "services" / "agent-service")
  18. def test_service_import_configs_cover_services_with_database_tests() -> None:
  19. assert "agent-service" in SERVICE_IMPORT_CONFIGS
  20. assert "session-service" in SERVICE_IMPORT_CONFIGS
  21. assert "core-db" in SERVICE_IMPORT_CONFIGS["agent-service"].libs
  22. def test_build_postgres_database_url_uses_isolated_schema(tmp_path: Path) -> None:
  23. database_url = build_postgres_database_url(tmp_path, "service")
  24. assert database_url.startswith("postgresql+psycopg://")
  25. assert "options=-csearch_path%3Dtest_" in database_url
  26. assert "%2Cpublic" not in database_url
  27. def test_gitlab_ci_installs_services_used_by_tests() -> None:
  28. ci_text = (REPO_ROOT / ".gitlab-ci.yml").read_text(encoding="utf-8")
  29. assert "pip install -e services/agent-service" in ci_text
  30. assert "pip install -e services/knowledge-service" in ci_text