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): run the bedrock mantle prompt cache and output limit wire tests on their own proxy (#47152)

yuneng-jiang603ba6fe00be
diff --git a/tests/integration/_support/process.py b/tests/integration/_support/process.py
index 00b9dca5184..5cbe1309075 100644
--- a/tests/integration/_support/process.py
+++ b/tests/integration/_support/process.py
@@ -17,7 +17,7 @@ from ipaddress import IPv4Address
from itertools import accumulate
from pathlib import Path
from types import MappingProxyType
-from typing import Final
+from typing import TYPE_CHECKING, Final
from urllib.parse import urlsplit
import httpx
@@ -30,9 +30,13 @@ from cryptography.x509.oid import NameOID
from pydantic import TypeAdapter
from tests.integration._support.budget import import_seconds, readiness_for, readiness_seconds
-from tests.integration._support.client import GATEWAY_LIMITS, Gateway
+from tests.integration._support.client import GATEWAY_LIMITS, Gateway, gateway_from_environment
+from tests.integration._support.database import scratch_database
from tests.integration._support.ports import allocate_port
+if TYPE_CHECKING:
+ import pytest
+
DB_PUSH: Final = ("--use_prisma_db_push",)
MIGRATE_DEPLOY: Final = ()
LEGACY_MIGRATE_DEPLOY: Final = ("--use_legacy_migration_resolver",)
@@ -379,6 +383,18 @@ def owned_proxy(
yield owned.gateway
+@contextmanager
+def isolated_gateway(directory: Path, environment: "pytest.MonkeyPatch") -> Iterator[Gateway]:
+ with gateway_from_environment() as shared, scratch_database() as database:
+ environment.setenv("DATABASE_URL", database)
+ environment.setenv("INTEGRATION_PROXY_DATABASE_URL", database)
+ environment.delenv("INTEGRATION_PROXY_READ_REPLICA_URL", raising=False)
+ environment.delenv("DATABASE_URL_READ_REPLICA", raising=False)
+ with owned_proxy(shared, directory, {}) as owned:
+ owned.post("/config/update", {"router_settings": {"num_retries": 0}})
+ yield owned
+
+
def _stop(process: subprocess.Popen[bytes]) -> None:
try:
root_stopped: Final = stop_root_process(process)
diff --git a/tests/integration/providers/test_bedrock_mantle_gpt_prompt_cache_breakpoint_wire.py b/tests/integration/providers/test_bedrock_mantle_gpt_prompt_cache_breakpoint_wire.py
index 2af41c2b683..bc46cf5cde1 100644
--- a/tests/integration/providers/test_bedrock_mantle_gpt_prompt_cache_breakpoint_wire.py
+++ b/tests/integration/providers/test_bedrock_mantle_gpt_prompt_cache_breakpoint_wire.py
@@ -1,10 +1,12 @@
import asyncio
import json
+from collections.abc import Iterator
from typing import Final
from urllib.parse import urlsplit
import pytest
from integration._support.client import Gateway, eventually
+from integration._support.process import isolated_gateway
from integration._support.wire import Request, wire_server
from integration.providers._mantle_gpt_prompt_cache_support import (
ANTHROPIC_PATH,
@@ -68,6 +70,15 @@ from pydantic import JsonValue
pytestmark = pytest.mark.timeout(600)
[email protected](scope="module")
+def gateway(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Gateway]:
+ with (
+ pytest.MonkeyPatch.context() as environment,
+ isolated_gateway(tmp_path_factory.mktemp("gateway"), environment) as owned,
+ ):
+ yield owned
+
+
@pytest.mark.parametrize("stream", [False, True], ids=["json", "stream"])
@pytest.mark.parametrize("endpoint", ENDPOINTS)
def test_a_configured_system_point_reaches_mantle_as_a_breakpoint_over_httpx(
diff --git a/tests/integration/providers/test_bedrock_mantle_output_limit_wire.py b/tests/integration/providers/test_bedrock_mantle_output_limit_wire.py
index 343d5253900..9b07cce2f3a 100644
--- a/tests/integration/providers/test_bedrock_mantle_output_limit_wire.py
+++ b/tests/integration/providers/test_bedrock_mantle_output_limit_wire.py
@@ -5,7 +5,7 @@ import os
import re
import threading
import uuid
-from collections.abc import Callable, Mapping
+from collections.abc import Callable, Iterator, Mapping
from dataclasses import dataclass
from pathlib import Path
from queue import SimpleQueue
@@ -21,7 +21,7 @@ import pytest
import yaml
from integration._support.client import Gateway, Scenario, eventually, object_value, string_value
from integration._support.database import read_rows
-from integration._support.process import graceful_stop_seconds, owned_proxy_process
+from integration._support.process import graceful_stop_seconds, isolated_gateway, owned_proxy_process
from integration._support.wire import Reply, Request, Wire, wire_server
from pydantic import JsonValue, TypeAdapter
@@ -318,6 +318,15 @@ def _spend_statuses(model: str, expected: int) -> list[JsonValue]:
return [row["status"] for row in rows]
[email protected](scope="module")
+def gateway(tmp_path_factory: pytest.TempPathFactory) -> Iterator[Gateway]:
+ with (
+ pytest.MonkeyPatch.context() as environment,
+ isolated_gateway(tmp_path_factory.mktemp("gateway"), environment) as owned,
+ ):
+ yield owned
+
+
def _proxy_url(gateway: Gateway) -> str:
return str(gateway.client.base_url).rstrip("/")