mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-27 01:22:18 +00:00
* ci: run the unit_selection.sh shard files on every event instead of only fork pull requests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> * ci: rename fork-flag to unit-flag now that it applies on every event * test: move tests/test_litellm root and small trees into tests/unit Pure renames, no content changes. Follow-up commits in this PR fix references, merge the three files that already existed in tests/unit, keep live-provider tests in tests/test_litellm and wire CI. * test: carry tests/test_litellm conftest isolation into tests/unit Callback lists, routing fallbacks, cached HTTP clients, logger state, AWS, proxy-URL and keychain env, and session-end client cleanup now reset for unit tests too. The environment isolation owns its MonkeyPatch so a test's own monkeypatch is undone before the model-cost teardown runs. * test: merge, split and prune the moved root and small-tree tests Merge batches/test_batch_utils.py and the chat_completions and messages dispatch tests into the files that already existed in tests/unit. Keep the live Gemini interactions tests, the async image-fetch format test and the OpenAI embedding scorer test in tests/test_litellm since they need real network or keys. Put test_router.py under tests/unit/test_router so the existing package no longer shadows it. Delete eight tests the audit found superseded by stronger ones kept in this move. * ci: run the moved root and small-tree tests under their legacy flags Add the misc and responses-caching-types flags to unit_selection.sh and CircleCI, extend enterprise-routing and mcp-integration, and point the legacy GHA shards, Makefile, redis-compat workflow, merge smoke manifest and change classifier at the new paths. * test: make the new tests/unit directories packages tests/unit/test_package_layout.py requires every directory to carry an __init__.py, and without one the moved and retained test_litellm_responses_bridge.py modules collide on import. * test: scope the unit socket block to tests/unit in shared sessions The GHA shards collect the legacy test-path and the unit selection in one pytest session. The unit conftest's loopback-only block leaked into legacy modules that reach the network at import. The legacy conftest now lifts the restriction at collect and setup time, and the unit conftest re-applies it when collecting its own modules. * test: give the shard-script tests their own GITHUB_OUTPUT They only passed where the runner set it. The CircleCI unit job's env allowlist drops it, so the script's redirect failed there. * test: point the router and module-deletion checks at tests/unit router_code_coverage and code_qa_check_tests only searched tests/test_litellm, so the moved router tests no longer counted. The two silent-experiment tests the audit deleted were the only direct callers of those methods; they are replaced with tests that assert the forwarded shadow request and the recursion guard. --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
77 lines
3.1 KiB
Python
77 lines
3.1 KiB
Python
"""
|
|
Static checks that every proxy Docker image installs the `bedrock-realtime` extra.
|
|
|
|
Bedrock Nova Sonic speech-to-speech (`/v1/realtime`) needs `aws-sdk-bedrock-runtime`,
|
|
which only ships in the `bedrock-realtime` extra. An image whose `uv sync` stages
|
|
omit the extra fails every Nova Sonic realtime session with
|
|
"Missing aws_sdk_bedrock_runtime: pip install 'litellm[bedrock-realtime]' ...".
|
|
"""
|
|
|
|
import os
|
|
import re
|
|
import sys
|
|
from typing import Final
|
|
|
|
import pytest
|
|
|
|
from litellm.constants import BEDROCK_REALTIME_SDK_DISTRIBUTION, BEDROCK_REALTIME_SDK_SUPPORTED_RANGE
|
|
|
|
if sys.version_info >= (3, 11):
|
|
import tomllib
|
|
else:
|
|
import tomli as tomllib
|
|
|
|
REPO_ROOT: Final = os.path.join(os.path.dirname(__file__), "..", "..")
|
|
|
|
PROXY_DOCKERFILES: Final = (
|
|
"Dockerfile",
|
|
os.path.join("docker", "Dockerfile.non_root"),
|
|
os.path.join("docker", "Dockerfile.database"),
|
|
os.path.join("gateway", "Dockerfile"),
|
|
)
|
|
|
|
CONTINUED_LINE_RE: Final = re.compile(r"(?:\\\n|[^\n])+")
|
|
UV_SYNC_BOUNDARY_RE: Final = re.compile(r"(?=uv sync)")
|
|
|
|
|
|
def _uv_sync_invocations(dockerfile_text: str) -> tuple[str, ...]:
|
|
"""Return each `uv sync ...` command, split apart when one RUN holds several (if/else branches)."""
|
|
return tuple(
|
|
part
|
|
for line in CONTINUED_LINE_RE.finditer(dockerfile_text)
|
|
for part in UV_SYNC_BOUNDARY_RE.split(line.group(0))
|
|
if part.startswith("uv sync")
|
|
)
|
|
|
|
|
|
@pytest.mark.parametrize("relative_path", PROXY_DOCKERFILES)
|
|
def test_every_uv_sync_installs_bedrock_realtime_extra(relative_path: str):
|
|
dockerfile_path: Final = os.path.join(REPO_ROOT, relative_path)
|
|
if not os.path.exists(dockerfile_path):
|
|
pytest.skip(f"{relative_path} not present in this checkout")
|
|
|
|
with open(dockerfile_path, "r", encoding="utf-8") as f:
|
|
contents: Final = f.read()
|
|
|
|
invocations: Final = _uv_sync_invocations(contents)
|
|
assert invocations, f"{relative_path} has no `uv sync` invocation"
|
|
|
|
missing: Final = tuple(invocation for invocation in invocations if "--extra bedrock-realtime" not in invocation)
|
|
assert not missing, (
|
|
f"{relative_path}: {len(missing)} of {len(invocations)} `uv sync` invocations omit "
|
|
"`--extra bedrock-realtime`, so aws-sdk-bedrock-runtime is absent and Bedrock Nova Sonic "
|
|
"/v1/realtime sessions fail with 'Missing aws_sdk_bedrock_runtime'"
|
|
)
|
|
|
|
|
|
def test_bedrock_realtime_extra_pins_the_range_named_in_the_runtime_error():
|
|
with open(os.path.join(REPO_ROOT, "pyproject.toml"), "rb") as f:
|
|
extra_specs: Final = tomllib.load(f)["project"]["optional-dependencies"]["bedrock-realtime"]
|
|
|
|
sdk_specs: Final = tuple(spec for spec in extra_specs if spec.startswith(BEDROCK_REALTIME_SDK_DISTRIBUTION))
|
|
assert len(sdk_specs) == 1, f"expected exactly one {BEDROCK_REALTIME_SDK_DISTRIBUTION} spec, got {extra_specs}"
|
|
requirement: Final = sdk_specs[0].split(";")[0].strip()
|
|
assert requirement == f"{BEDROCK_REALTIME_SDK_DISTRIBUTION}[awscrt]{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE}", (
|
|
f"pyproject pins {requirement!r} but the handler's install hint names "
|
|
f"{BEDROCK_REALTIME_SDK_SUPPORTED_RANGE!r} with the awscrt extra; keep them in sync"
|
|
)
|