Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(integration): write worker configs beside test-supplied configs (#47066)

yuneng-jiange754857de984
diff --git a/tests/integration/_support/process.py b/tests/integration/_support/process.py
index fd61ca3aea2..00b9dca5184 100644
--- a/tests/integration/_support/process.py
+++ b/tests/integration/_support/process.py
@@ -628,8 +628,11 @@ def worker_configuration(config: Path, directory: Path, inherited: Mapping[str,
return f"http://127.0.0.1:{inherited['INTEGRATION_PROVIDER_PORT']}"
contents: Final = re.sub(r"http://127[.]0[.]0[.]1:(8190|8191)(?![0-9])", endpoint, config.read_text())
- directory.mkdir(parents=True, exist_ok=True)
- destination: Final = directory / f"worker-config-{uuid.uuid4().hex}.yaml"
+ checkouts: Final = (_harness_root(), _proxy_root().resolve())
+ inside_checkout: Final = any(config.resolve().is_relative_to(checkout) for checkout in checkouts)
+ target: Final = directory if inside_checkout else config.parent
+ target.mkdir(parents=True, exist_ok=True)
+ destination: Final = target / f"worker-config-{uuid.uuid4().hex}.yaml"
loaded: Final[object] = yaml.safe_load(contents)
if not isinstance(loaded, dict):
destination.write_text(contents)
diff --git a/tests/unit/integration_support/test_process.py b/tests/unit/integration_support/test_process.py
index 2106436edb8..6d1e0af5624 100644
--- a/tests/unit/integration_support/test_process.py
+++ b/tests/unit/integration_support/test_process.py
@@ -20,6 +20,7 @@ import pytest
import yaml
from pydantic import TypeAdapter
+from litellm.proxy.types_utils.utils import get_instance_fn
from tests.integration._support.client import Gateway, eventually
from tests.integration._support.process import (
OwnedProxy,
@@ -93,6 +94,42 @@ def test_worker_configuration_budgets_implicit_pools_without_changing_connection
assert yaml.safe_load(source.read_text()) == original
+def test_worker_configuration_keeps_modules_beside_a_test_config_importable(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ monkeypatch.setenv("INTEGRATION_WORKER_ISOLATION", "1")
+ source: Final = tmp_path / "proxy.yaml"
+ source.write_text(yaml.safe_dump({"general_settings": {"custom_auth": "sibling_auth.authenticate"}}))
+ (tmp_path / "sibling_auth.py").write_text("def authenticate() -> str:\n return 'sibling'\n")
+ configured: Final = worker_configuration(source, tmp_path / "gateway")
+ assert configured != source
+ assert get_instance_fn("sibling_auth.authenticate", config_file_path=str(configured))() == "sibling"
+
+
+def test_worker_configuration_writes_the_repository_config_copy_into_the_worker_directory(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ monkeypatch.setenv("INTEGRATION_WORKER_ISOLATION", "1")
+ monkeypatch.setenv("INTEGRATION_PROVIDER_PORT", "8203")
+ monkeypatch.setenv("INTEGRATION_UPSTREAM_URL", "http://127.0.0.1:8202")
+ monkeypatch.setenv("INTEGRATION_PROXY_ROOT", str(tmp_path / "product"))
+ configured: Final = worker_configuration(TESTS_DIR / "integration/proxy_config.yaml", tmp_path / "worker")
+ assert configured.parent == tmp_path / "worker"
+
+
+def test_worker_configuration_writes_the_proxy_checkout_config_copy_into_the_worker_directory(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ monkeypatch.setenv("INTEGRATION_WORKER_ISOLATION", "1")
+ checkout: Final = tmp_path / "checkout"
+ monkeypatch.setenv("INTEGRATION_PROXY_ROOT", str(checkout))
+ source: Final = checkout / "tests/integration/proxy_config.yaml"
+ source.parent.mkdir(parents=True)
+ source.write_text("model_list: []\n")
+ configured: Final = worker_configuration(source, tmp_path / "worker")
+ assert configured.parent == tmp_path / "worker"
+
+
def test_serial_proxy_keeps_the_requested_configuration(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.delenv("INTEGRATION_WORKER_ISOLATION", raising=False)
source: Final = tmp_path / "source.yaml"