Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Fix/fetch remote config vs pytest (#528)

Louis Choquel7bc710e361ea
diff --git a/pipelex/system/pipelex_service/pipelex_details.py b/pipelex/system/pipelex_service/pipelex_details.py
index c17d83a5f..8eab3f453 100644
--- a/pipelex/system/pipelex_service/pipelex_details.py
+++ b/pipelex/system/pipelex_service/pipelex_details.py
@@ -2,7 +2,7 @@ from pipelex.tools.misc.hash_utils import hash_sha256
class PipelexDetails:
- REMOTE_CONFIG_URL = "https://pipelex-config.s3.amazonaws.com/pipelex_remote_config_01.json"
+ REMOTE_CONFIG_URL = "https://pipelex-config.s3.eu-west-3.amazonaws.com/pipelex_remote_config_01.json"
PIPELEX_GATEWAY_API_KEY_VAR = "PIPELEX_GATEWAY_API_KEY"
@classmethod
diff --git a/pipelex/system/pipelex_service/remote_config_fetcher.py b/pipelex/system/pipelex_service/remote_config_fetcher.py
index ad0748e4a..ec93ebe08 100644
--- a/pipelex/system/pipelex_service/remote_config_fetcher.py
+++ b/pipelex/system/pipelex_service/remote_config_fetcher.py
@@ -2,13 +2,13 @@ import httpx
from pydantic import ValidationError
from tenacity import RetryCallState, retry, retry_if_exception_type, stop_after_attempt, wait_exponential
-from pipelex import log
from pipelex.system.pipelex_service.exceptions import (
RemoteConfigFetchError,
RemoteConfigValidationError,
)
from pipelex.system.pipelex_service.pipelex_details import PipelexDetails
from pipelex.system.pipelex_service.remote_config import RemoteConfig
+from pipelex.tools.misc.terminal_utils import print_to_stderr
from pipelex.tools.typing.pydantic_utils import format_pydantic_validation_error
@@ -27,7 +27,7 @@ class RemoteConfigFetcher:
def _log_retry_attempt(cls, retry_state: RetryCallState) -> None:
"""Log retry attempts for remote config fetch."""
exc = retry_state.outcome.exception() if retry_state.outcome else None
- log.verbose(f"Remote config fetch attempt {retry_state.attempt_number} failed: {exc}. Retrying...")
+ print_to_stderr(f"Remote config fetch attempt {retry_state.attempt_number} failed: {exc}. Retrying...")
@classmethod
def _fetch_remote_config_with_retry(cls, url: str) -> httpx.Response:
diff --git a/tests/conftest.py b/tests/conftest.py
index 8796d8d69..9dd849070 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -2,10 +2,13 @@ from collections.abc import Callable, Generator
from pathlib import Path
import pytest
+from pytest_mock import MockerFixture
from pipelex import log
from pipelex.hub import get_library_manager, set_current_library
from pipelex.pipelex import Pipelex
+from pipelex.system.pipelex_service.remote_config import RemoteConfig
+from pipelex.system.pipelex_service.remote_config_fetcher import RemoteConfigFetcher
from pipelex.system.runtime import IntegrationMode, runtime_manager
pytest_plugins = [
@@ -14,6 +17,23 @@ pytest_plugins = [
TEST_OUTPUTS_DIR = "temp/test_outputs"
+# Session-level cache for remote config (using dict to avoid global statement)
+_remote_config_cache: dict[str, RemoteConfig] = {}
+_original_fetch_remote_config = RemoteConfigFetcher.fetch_remote_config
+
+
+def _cached_fetch_remote_config() -> RemoteConfig:
+ """Wrapper that caches the remote config for the entire test session."""
+ if "config" not in _remote_config_cache:
+ _remote_config_cache["config"] = _original_fetch_remote_config()
+ return _remote_config_cache["config"]
+
+
[email protected](scope="session", autouse=True)
+def cache_remote_config_for_session(session_mocker: MockerFixture):
+ """Cache remote configuration for the entire test session to avoid repeated fetches."""
+ session_mocker.patch.object(RemoteConfigFetcher, "fetch_remote_config", _cached_fetch_remote_config)
+
def _get_test_integration_mode() -> IntegrationMode:
"""Return the appropriate integration mode for tests.