test(e2e): enforce the cross-region invariant on the Bedrock allowlist

The allowlist rejects an unlisted model before the region resolver runs, so the
two negative cases that used to cover the resolver were passing for the wrong
reason and two mutations of it survived. Answering an env-referenced region with
the default mount is only sound because every allowlisted model is a `us.`
profile that fans out across the US regions, so assert that on the list itself
and drop the per-call branch it made unreachable.
This commit is contained in:
Yuneng Jiang 2026-09-16 04:41:29 -07:00
parent ebf34cd880
commit 7c2234be3a
2 changed files with 43 additions and 17 deletions

View file

@ -33,7 +33,13 @@ from provider_cache import (
successful_response,
)
from provider_cache_redis import PUBLISH, RedisCommands, RedisResponseStore, configured_cache, redis_store
from provider_cache_routing import LIVE_PROVIDER_REQUIRED, route_cache_model
from provider_cache_routing import (
BEDROCK_CROSS_REGION_PREFIX,
BEDROCK_EDGE_MODELS,
LIVE_PROVIDER_REQUIRED,
bedrock_region,
route_cache_model,
)
from fixture_mode import SESSION_TEST_KEY
from provider_edge import EDGE_MOUNTS, configured_cache_backend, resolve_mount, start_provider_edge
from provider_edge_bedrock import bedrock_signer
@ -856,6 +862,31 @@ def test_bedrock_deployments_the_edge_must_not_touch_keep_their_direct_route(par
assert routed is params
@pytest.mark.parametrize("declared,expected", [
(None, "us-east-1"),
("us-west-2", "us-west-2"),
("eu-west-1", "eu-west-1"),
("os.environ/AWS_REGION", "us-east-1"),
("os.environ/ANY_OTHER_NAME", "us-east-1"),
])
def test_a_region_only_the_proxy_can_resolve_falls_back_to_the_default_mount(
declared: str | None, expected: str,
) -> None:
"""A declared literal region is the one the deployment meant. A region the
proxy resolves from its own environment is one the run pod cannot see, and
the default mount answers it."""
assert bedrock_region(declared) == expected
def test_every_model_on_the_edge_allowlist_is_a_cross_region_profile() -> None:
"""Answering an env-referenced region with the default mount is only correct
for a profile that fans out across the US regions and is reachable from any
of them. A single-region model on this list would be sent to a region it may
not exist in, so the list is where that is caught."""
assert BEDROCK_EDGE_MODELS
assert all(model.startswith(BEDROCK_CROSS_REGION_PREFIX) for model in BEDROCK_EDGE_MODELS)
@pytest.mark.parametrize("mode", ["batch", "realtime", "image_generation"])
def test_a_bedrock_deployment_with_a_mode_keeps_its_direct_route(mode: ModelMode) -> None:
params: Final = LiteLLMParamsBody(model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0")

View file

@ -21,22 +21,18 @@ BEDROCK_EDGE_MODELS: Final = frozenset(
ENV_REFERENCE_PREFIX: Final = "os.environ/"
def bedrock_region(declared: str | None, model: str) -> str | None:
"""The region whose edge mount a deployment belongs to, or None when the
harness cannot know it.
def bedrock_region(declared: str | None) -> str:
"""The region whose edge mount a deployment belongs to.
Most Bedrock deployments declare `os.environ/AWS_REGION`, which the proxy
resolves from its own environment. The run pod does not share that
environment, so the harness genuinely does not know the region. A `us.`
inference profile fans out across the US regions and is reachable from any
of them, so the default entry point is correct for those whatever the proxy
resolved; anything else keeps its direct path rather than being sent to a
region the model may not exist in."""
if declared is None:
Most Bedrock deployments declare `os.environ/AWS_REGION`, which only the
proxy can resolve from its own environment; the run pod does not share it.
Answering those with the default mount is correct because every model on the
edge allowlist is a `us.` inference profile, which fans out across the US
regions and is reachable from any of them. That invariant is enforced on the
allowlist itself rather than re-checked per call."""
if declared is None or declared.startswith(ENV_REFERENCE_PREFIX):
return DEFAULT_BEDROCK_REGION
if not declared.startswith(ENV_REFERENCE_PREFIX):
return declared
return DEFAULT_BEDROCK_REGION if model.startswith(BEDROCK_CROSS_REGION_PREFIX) else None
return declared
def bedrock_mount(params: LiteLLMParamsBody) -> str | None:
@ -51,8 +47,7 @@ def bedrock_mount(params: LiteLLMParamsBody) -> str | None:
model: Final = route.partition("/")[2] or route
if model not in BEDROCK_EDGE_MODELS:
return None
region: Final = bedrock_region(params.aws_region_name, model)
return None if region is None else f"bedrock/{region}"
return f"bedrock/{bedrock_region(params.aws_region_name)}"
def route_bedrock(