mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-18 04:44:37 +00:00
test(integration): write worker configs beside test-supplied configs (#47066)
Under worker isolation the harness rewrote every proxy config into the owned proxy's directory, so modules a test placed next to its own config (custom_auth) no longer resolved and the proxy died at boot. The copy now lands next to a test-supplied config, while configs inside the checkout still go to the worker directory so nothing is written into the repo tree
This commit is contained in:
parent
ae6f7f6613
commit
e754857de9
2 changed files with 42 additions and 2 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue