From 302394edff7771eb73b4459fbba7e709730a1c00 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 01:33:43 +0000 Subject: [PATCH 1/8] ci: gate hardcoded commercial AWS partition literals and test us-gov endpoint builders Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .github/workflows/test-code-quality.yml | 3 + .../check_aws_partition_hardcodes.py | 121 ++++++++++++++++++ .../litellm_core_utils/test_aws_partition.py | 116 ++++++++++++++++- 3 files changed, 239 insertions(+), 1 deletion(-) create mode 100644 tests/code_coverage_tests/check_aws_partition_hardcodes.py diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.yml index 987f66773f2..44c3e97db91 100644 --- a/.github/workflows/test-code-quality.yml +++ b/.github/workflows/test-code-quality.yml @@ -146,6 +146,9 @@ jobs: - name: check_migrations_no_data_rewrites run: uv run --no-sync python ./tests/code_coverage_tests/check_migrations_no_data_rewrites.py + - name: check_aws_partition_hardcodes + run: uv run --no-sync python ./tests/code_coverage_tests/check_aws_partition_hardcodes.py + - name: memory_test run: uv run --no-sync python ./tests/code_coverage_tests/memory_test.py diff --git a/tests/code_coverage_tests/check_aws_partition_hardcodes.py b/tests/code_coverage_tests/check_aws_partition_hardcodes.py new file mode 100644 index 00000000000..d7959ea59fe --- /dev/null +++ b/tests/code_coverage_tests/check_aws_partition_hardcodes.py @@ -0,0 +1,121 @@ +#!/usr/bin/env python3 +"""Ban hardcoded commercial-partition AWS hosts and ARN prefixes under `litellm/`. + +An endpoint or ARN built with a literal `amazonaws.com` or `arn:aws:` works in every +commercial region and breaks only for GovCloud (`us-gov-*`, `arn:aws-us-gov:`) and +China (`amazonaws.com.cn`, `arn:aws-cn:`) deployments, so the failure never shows up +in CI or on a developer laptop. `litellm/litellm_core_utils/aws_partition.py` derives +both from the region and is the only place those literals belong. Build hosts with +`get_aws_dns_suffix(region)` and ARNs with `get_aws_arn_prefix(region)`. + +Every string constant in every `litellm/**/*.py` file is scanned, including the +literal parts of f-strings and the strings inside `.format()` calls and +concatenations. Docstrings and comments are not, since they never reach a request. +`amazonaws.com.cn` passes because it is already the China partition. + +`ALLOWED` holds the (file, token) pairs that are text rather than a request target: +a hosted logo, an IAM service principal, and hostnames quoted as examples inside +error messages and field descriptions. An entry only covers that exact token in that +exact file, so a second literal in an allowed file is still caught, and an entry +whose token is gone fails the check so the set only shrinks. +""" + +from __future__ import annotations + +import ast +import re +import sys +from pathlib import Path +from typing import Final, NamedTuple + +REPO_ROOT: Final = Path(__file__).resolve().parents[2] +SCAN_ROOT: Final = REPO_ROOT / "litellm" +PARTITION_HELPER: Final = "litellm/litellm_core_utils/aws_partition.py" + +COMMERCIAL_TOKEN: Final = re.compile(r"[A-Za-z0-9.-]*amazonaws\.com(?!\.cn)|arn:aws:[A-Za-z0-9:/_.*-]*") + + +class Allowance(NamedTuple): + file: str + token: str + + +ALLOWED: Final = frozenset( + { + Allowance("litellm/integrations/email_alerting.py", "litellm-listing.s3.amazonaws.com"), + Allowance("litellm/types/integrations/slack_alerting.py", "litellm-listing.s3.amazonaws.com"), + Allowance("litellm/rag/ingestion/bedrock_ingestion.py", "bedrock.amazonaws.com"), + Allowance( + "litellm/llms/bedrock/chat/agentcore/transformation.py", + "arn:aws:bedrock-agentcore:region:account:runtime/runtime_id", + ), + Allowance("litellm/llms/bedrock/search/transformation.py", ".amazonaws.com"), + Allowance( + "litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py", + "bucket.s3.amazonaws.com", + ), + Allowance("litellm/types/proxy/claude_code_endpoints.py", "bucket.s3.amazonaws.com"), + } +) + + +class Hit(NamedTuple): + file: str + line: int + token: str + + +def _docstring_ids(tree: ast.Module) -> frozenset[int]: + return frozenset( + id(statement.value) + for node in ast.walk(tree) + if isinstance(node, (ast.Module, ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)) + for statement in node.body + if isinstance(statement, ast.Expr) + and isinstance(statement.value, ast.Constant) + and isinstance(statement.value.value, str) + ) + + +def _hits_in_file(path: Path) -> tuple[Hit, ...]: + tree: Final = ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) + docstrings: Final = _docstring_ids(tree) + relative: Final = path.relative_to(REPO_ROOT).as_posix() + return tuple( + Hit(relative, node.lineno, match.group(0)) + for node in ast.walk(tree) + if isinstance(node, ast.Constant) and isinstance(node.value, str) and id(node) not in docstrings + for match in COMMERCIAL_TOKEN.finditer(node.value) + ) + + +def find_hits(scan_root: Path) -> tuple[Hit, ...]: + return tuple( + hit + for path in sorted(scan_root.rglob("*.py")) + if path.relative_to(REPO_ROOT).as_posix() != PARTITION_HELPER + for hit in _hits_in_file(path) + ) + + +def main() -> int: + hits: Final = find_hits(SCAN_ROOT) + seen: Final = frozenset(Allowance(hit.file, hit.token) for hit in hits) + violations: Final = tuple(hit for hit in hits if Allowance(hit.file, hit.token) not in ALLOWED) + stale: Final = ALLOWED - seen + for hit in violations: + print(f"{hit.file}:{hit.line}: hardcoded commercial AWS partition literal {hit.token!r}") + for allowance in sorted(stale): + print(f"{allowance.file}: ALLOWED entry {allowance.token!r} no longer matches anything, remove it") + if violations or stale: + print( + "\nBuild AWS hosts with get_aws_dns_suffix(region) and ARNs with get_aws_arn_prefix(region) " + "from litellm/litellm_core_utils/aws_partition.py so GovCloud and China regions resolve." + ) + return 1 + print(f"No hardcoded commercial AWS partition literals outside {PARTITION_HELPER}.") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tests/test_litellm/litellm_core_utils/test_aws_partition.py b/tests/test_litellm/litellm_core_utils/test_aws_partition.py index 3594d3c354c..24a38268ae9 100644 --- a/tests/test_litellm/litellm_core_utils/test_aws_partition.py +++ b/tests/test_litellm/litellm_core_utils/test_aws_partition.py @@ -1,9 +1,11 @@ import ast from pathlib import Path +from types import MappingProxyType from typing import Final -from urllib.parse import urlparse +from urllib.parse import unquote, urlparse import pytest +from botocore.credentials import Credentials import litellm from litellm.integrations.s3_v2 import S3Logger @@ -20,8 +22,20 @@ from litellm.llms.aws_polly.text_to_speech.transformation import AWSPollyTextToS from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM from litellm.llms.bedrock.batches.transformation import BedrockBatchesConfig from litellm.llms.bedrock.chat.agentcore.transformation import AmazonAgentCoreConfig +from litellm.llms.bedrock.chat.invoke_agent.transformation import AmazonInvokeAgentConfig from litellm.llms.bedrock.common_utils import init_bedrock_client +from litellm.llms.bedrock.files.transformation import BedrockFilesConfig +from litellm.llms.bedrock.rerank.handler import BedrockRerankHandler +from litellm.llms.bedrock.vector_stores.transformation import BedrockVectorStoreConfig from litellm.llms.sagemaker.chat.transformation import SagemakerChatConfig +from litellm.llms.sagemaker.completion.handler import SagemakerLLM +from litellm.proxy.auth.rds_iam_token import init_rds_client +from litellm.proxy.guardrails.guardrail_hooks.bedrock_guardrails import BedrockGuardrail +from litellm.secret_managers.aws_secret_manager_v2 import AWSSecretsManagerV2 + +STATIC_AWS_CREDENTIALS: Final = MappingProxyType( + {"aws_access_key_id": "test-key", "aws_secret_access_key": "test-secret"} +) @pytest.mark.parametrize( @@ -106,6 +120,48 @@ def _s3_object_url(region: str) -> str: return logger._build_object_url("2025-01-01/key.json") +def _bedrock_job_arn(region: str) -> str: + return f"{get_aws_arn_prefix(region)}bedrock:{region}:111122223333:model-invocation-job/abc1234567" + + +def _bedrock_files_upload_url(region: str) -> str: + return BedrockFilesConfig().get_complete_file_url( + api_base=None, + api_key=None, + model="amazon.nova-pro-v1:0", + optional_params={}, + litellm_params={"s3_bucket_name": "batch-bucket", "s3_region_name": region}, + data={"file": ("batch.jsonl", b"{}", "application/jsonl"), "purpose": "batch"}, + ) + + +def _bedrock_files_download_url(region: str) -> str: + return ( + BedrockFilesConfig() + ._s3_request_target(optional_params={}, litellm_params={"s3_region_name": region}) + .endpoint_url + ) + + +def _bedrock_guardrail_url(region: str) -> str: + guardrail = BedrockGuardrail(guardrailIdentifier="guardrail-id", guardrailVersion="1") + return guardrail._prepare_request( + credentials=Credentials("test-key", "test-secret"), + data={"source": "INPUT", "content": []}, + optional_params={}, + aws_region_name=region, + ).url + + +def _secrets_manager_url(region: str) -> str: + endpoint_url, _headers, _body = AWSSecretsManagerV2(aws_region_name=region)._prepare_request( + action="GetSecretValue", + secret_name="my-secret", + optional_params=dict(STATIC_AWS_CREDENTIALS), + ) + return endpoint_url + + ENDPOINT_BUILDERS: Final = { "bedrock_runtime_default": lambda region: BaseAWSLLM()._select_default_endpoint_url("runtime", region), "bedrock_agent_default": lambda region: BaseAWSLLM()._select_default_endpoint_url("agent", region), @@ -124,6 +180,13 @@ ENDPOINT_BUILDERS: Final = { litellm_params={}, data={"input_file_id": "s3://bucket/key.jsonl"}, ), + "bedrock_batches_retrieve": lambda region: BedrockBatchesConfig().transform_retrieve_batch_request( + batch_id=_bedrock_job_arn(region), + optional_params=dict(STATIC_AWS_CREDENTIALS), + litellm_params={}, + )["url"], + "bedrock_files_upload": _bedrock_files_upload_url, + "bedrock_files_download": _bedrock_files_download_url, "bedrock_agentcore_invoke": lambda region: AmazonAgentCoreConfig().get_complete_url( api_base=None, api_key=None, @@ -131,6 +194,32 @@ ENDPOINT_BUILDERS: Final = { optional_params={}, litellm_params={}, ), + "bedrock_invoke_agent": lambda region: AmazonInvokeAgentConfig().get_complete_url( + api_base=None, + api_key=None, + model="agent/AGENT123/ALIAS456", + optional_params={"aws_region_name": region}, + litellm_params={}, + ), + "bedrock_guardrail_apply": _bedrock_guardrail_url, + "bedrock_rerank": lambda region: BedrockRerankHandler()._prepare_request( + model="amazon.rerank-v1:0", + api_base=None, + extra_headers=None, + data={"queries": [], "sources": []}, + optional_params={"aws_region_name": region, **STATIC_AWS_CREDENTIALS}, + )["endpoint_url"], + "bedrock_knowledgebase_search": lambda region: BedrockVectorStoreConfig().get_complete_url( + api_base=None, litellm_params={"aws_region_name": region} + ), + "secrets_manager": _secrets_manager_url, + "rds_iam_client": lambda region: ( + init_rds_client( + aws_region_name=region, + aws_access_key_id="test-key", + aws_secret_access_key="test-secret", + ).meta.endpoint_url + ), "polly": lambda region: AWSPollyTextToSpeechConfig().get_complete_url( model="polly/neural", api_base=None, @@ -152,6 +241,19 @@ ENDPOINT_BUILDERS: Final = { litellm_params={}, stream=True, ), + "sagemaker_completion": lambda region: ( + SagemakerLLM() + ._prepare_request( + credentials=Credentials("test-key", "test-secret"), + model="my-endpoint", + data={}, + messages=[], + litellm_params={}, + optional_params={}, + aws_region_name=region, + ) + .url + ), "s3_object_url": _s3_object_url, } @@ -182,6 +284,18 @@ def test_every_endpoint_builder_keeps_amazonaws_com_outside_cn(builder_name: str assert hostname.endswith(".amazonaws.com"), url +@pytest.mark.parametrize("region", ["us-gov-west-1", "us-gov-east-1"]) +@pytest.mark.parametrize("builder_name", sorted(ENDPOINT_BUILDERS)) +def test_every_endpoint_builder_respects_us_gov_partition(builder_name: str, region: str) -> None: + url = unquote(ENDPOINT_BUILDERS[builder_name](region)) + hostname = urlparse(url).hostname + assert hostname is not None + assert hostname.endswith(f".{region}.amazonaws.com"), url + assert "arn:aws:" not in url, url + if "arn:" in url: + assert "arn:aws-us-gov:" in url, url + + def _fstring_literal_offenders(needle: str) -> list[str]: litellm_root = Path(litellm.__file__).parent return [ From 6a9ae2bba290aaead3b7854715f4cc63f8d20bb6 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 01:47:33 +0000 Subject: [PATCH 2/8] ci(aws-partition): count allowlisted literal occurrences so duplicates in allowed files fail Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .../check_aws_partition_hardcodes.py | 49 +++++++++++++------ 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/tests/code_coverage_tests/check_aws_partition_hardcodes.py b/tests/code_coverage_tests/check_aws_partition_hardcodes.py index d7959ea59fe..0cbee4e7c80 100644 --- a/tests/code_coverage_tests/check_aws_partition_hardcodes.py +++ b/tests/code_coverage_tests/check_aws_partition_hardcodes.py @@ -13,11 +13,12 @@ literal parts of f-strings and the strings inside `.format()` calls and concatenations. Docstrings and comments are not, since they never reach a request. `amazonaws.com.cn` passes because it is already the China partition. -`ALLOWED` holds the (file, token) pairs that are text rather than a request target: -a hosted logo, an IAM service principal, and hostnames quoted as examples inside -error messages and field descriptions. An entry only covers that exact token in that -exact file, so a second literal in an allowed file is still caught, and an entry -whose token is gone fails the check so the set only shrinks. +`ALLOWED` holds the (file, token, count) triples that are text rather than a request +target: a hosted logo, an IAM service principal, and hostnames quoted as examples +inside error messages and field descriptions. An entry only covers that many +occurrences of that exact token in that exact file, so a second copy of an allowed +literal is still caught, and an entry whose token is gone or whose count has changed +fails the check so the set only shrinks. """ from __future__ import annotations @@ -25,7 +26,9 @@ from __future__ import annotations import ast import re import sys +from collections import Counter from pathlib import Path +from types import MappingProxyType from typing import Final, NamedTuple REPO_ROOT: Final = Path(__file__).resolve().parents[2] @@ -38,25 +41,29 @@ COMMERCIAL_TOKEN: Final = re.compile(r"[A-Za-z0-9.-]*amazonaws\.com(?!\.cn)|arn: class Allowance(NamedTuple): file: str token: str + occurrences: int ALLOWED: Final = frozenset( { - Allowance("litellm/integrations/email_alerting.py", "litellm-listing.s3.amazonaws.com"), - Allowance("litellm/types/integrations/slack_alerting.py", "litellm-listing.s3.amazonaws.com"), - Allowance("litellm/rag/ingestion/bedrock_ingestion.py", "bedrock.amazonaws.com"), + Allowance("litellm/integrations/email_alerting.py", "litellm-listing.s3.amazonaws.com", 1), + Allowance("litellm/types/integrations/slack_alerting.py", "litellm-listing.s3.amazonaws.com", 1), + Allowance("litellm/rag/ingestion/bedrock_ingestion.py", "bedrock.amazonaws.com", 1), Allowance( "litellm/llms/bedrock/chat/agentcore/transformation.py", "arn:aws:bedrock-agentcore:region:account:runtime/runtime_id", + 1, ), - Allowance("litellm/llms/bedrock/search/transformation.py", ".amazonaws.com"), + Allowance("litellm/llms/bedrock/search/transformation.py", ".amazonaws.com", 1), Allowance( "litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py", "bucket.s3.amazonaws.com", + 1, ), - Allowance("litellm/types/proxy/claude_code_endpoints.py", "bucket.s3.amazonaws.com"), + Allowance("litellm/types/proxy/claude_code_endpoints.py", "bucket.s3.amazonaws.com", 1), } ) +ALLOWED_COUNTS: Final = MappingProxyType({(entry.file, entry.token): entry.occurrences for entry in ALLOWED}) class Hit(NamedTuple): @@ -98,14 +105,26 @@ def find_hits(scan_root: Path) -> tuple[Hit, ...]: ) +def _violation_message(hit: Hit, found: int) -> str: + allowed: Final = ALLOWED_COUNTS.get((hit.file, hit.token)) + if allowed is None: + return f"{hit.file}:{hit.line}: hardcoded commercial AWS partition literal {hit.token!r}" + return ( + f"{hit.file}:{hit.line}: {hit.token!r} appears {found} times but ALLOWED covers {allowed}; " + "build it from the region helper or update the count" + ) + + def main() -> int: hits: Final = find_hits(SCAN_ROOT) - seen: Final = frozenset(Allowance(hit.file, hit.token) for hit in hits) - violations: Final = tuple(hit for hit in hits if Allowance(hit.file, hit.token) not in ALLOWED) - stale: Final = ALLOWED - seen + counts: Final = MappingProxyType(Counter((hit.file, hit.token) for hit in hits)) + violations: Final = tuple( + sorted(hit for hit in hits if Allowance(hit.file, hit.token, counts[hit.file, hit.token]) not in ALLOWED) + ) + stale: Final = tuple(entry for entry in sorted(ALLOWED) if (entry.file, entry.token) not in counts) for hit in violations: - print(f"{hit.file}:{hit.line}: hardcoded commercial AWS partition literal {hit.token!r}") - for allowance in sorted(stale): + print(_violation_message(hit, counts[hit.file, hit.token])) + for allowance in stale: print(f"{allowance.file}: ALLOWED entry {allowance.token!r} no longer matches anything, remove it") if violations or stale: print( From fc35b78eb42b665c637d7b13969de57d88f2c6a0 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 20:16:07 +0000 Subject: [PATCH 3/8] ci: drop aws partition hardcode gate Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- .github/workflows/test-code-quality.yml | 3 - .../check_aws_partition_hardcodes.py | 140 ------------------ .../litellm_core_utils/test_aws_partition.py | 116 +-------------- 3 files changed, 1 insertion(+), 258 deletions(-) delete mode 100644 tests/code_coverage_tests/check_aws_partition_hardcodes.py diff --git a/.github/workflows/test-code-quality.yml b/.github/workflows/test-code-quality.yml index 44c3e97db91..987f66773f2 100644 --- a/.github/workflows/test-code-quality.yml +++ b/.github/workflows/test-code-quality.yml @@ -146,9 +146,6 @@ jobs: - name: check_migrations_no_data_rewrites run: uv run --no-sync python ./tests/code_coverage_tests/check_migrations_no_data_rewrites.py - - name: check_aws_partition_hardcodes - run: uv run --no-sync python ./tests/code_coverage_tests/check_aws_partition_hardcodes.py - - name: memory_test run: uv run --no-sync python ./tests/code_coverage_tests/memory_test.py diff --git a/tests/code_coverage_tests/check_aws_partition_hardcodes.py b/tests/code_coverage_tests/check_aws_partition_hardcodes.py deleted file mode 100644 index 0cbee4e7c80..00000000000 --- a/tests/code_coverage_tests/check_aws_partition_hardcodes.py +++ /dev/null @@ -1,140 +0,0 @@ -#!/usr/bin/env python3 -"""Ban hardcoded commercial-partition AWS hosts and ARN prefixes under `litellm/`. - -An endpoint or ARN built with a literal `amazonaws.com` or `arn:aws:` works in every -commercial region and breaks only for GovCloud (`us-gov-*`, `arn:aws-us-gov:`) and -China (`amazonaws.com.cn`, `arn:aws-cn:`) deployments, so the failure never shows up -in CI or on a developer laptop. `litellm/litellm_core_utils/aws_partition.py` derives -both from the region and is the only place those literals belong. Build hosts with -`get_aws_dns_suffix(region)` and ARNs with `get_aws_arn_prefix(region)`. - -Every string constant in every `litellm/**/*.py` file is scanned, including the -literal parts of f-strings and the strings inside `.format()` calls and -concatenations. Docstrings and comments are not, since they never reach a request. -`amazonaws.com.cn` passes because it is already the China partition. - -`ALLOWED` holds the (file, token, count) triples that are text rather than a request -target: a hosted logo, an IAM service principal, and hostnames quoted as examples -inside error messages and field descriptions. An entry only covers that many -occurrences of that exact token in that exact file, so a second copy of an allowed -literal is still caught, and an entry whose token is gone or whose count has changed -fails the check so the set only shrinks. -""" - -from __future__ import annotations - -import ast -import re -import sys -from collections import Counter -from pathlib import Path -from types import MappingProxyType -from typing import Final, NamedTuple - -REPO_ROOT: Final = Path(__file__).resolve().parents[2] -SCAN_ROOT: Final = REPO_ROOT / "litellm" -PARTITION_HELPER: Final = "litellm/litellm_core_utils/aws_partition.py" - -COMMERCIAL_TOKEN: Final = re.compile(r"[A-Za-z0-9.-]*amazonaws\.com(?!\.cn)|arn:aws:[A-Za-z0-9:/_.*-]*") - - -class Allowance(NamedTuple): - file: str - token: str - occurrences: int - - -ALLOWED: Final = frozenset( - { - Allowance("litellm/integrations/email_alerting.py", "litellm-listing.s3.amazonaws.com", 1), - Allowance("litellm/types/integrations/slack_alerting.py", "litellm-listing.s3.amazonaws.com", 1), - Allowance("litellm/rag/ingestion/bedrock_ingestion.py", "bedrock.amazonaws.com", 1), - Allowance( - "litellm/llms/bedrock/chat/agentcore/transformation.py", - "arn:aws:bedrock-agentcore:region:account:runtime/runtime_id", - 1, - ), - Allowance("litellm/llms/bedrock/search/transformation.py", ".amazonaws.com", 1), - Allowance( - "litellm/proxy/anthropic_endpoints/claude_code_endpoints/claude_code_marketplace.py", - "bucket.s3.amazonaws.com", - 1, - ), - Allowance("litellm/types/proxy/claude_code_endpoints.py", "bucket.s3.amazonaws.com", 1), - } -) -ALLOWED_COUNTS: Final = MappingProxyType({(entry.file, entry.token): entry.occurrences for entry in ALLOWED}) - - -class Hit(NamedTuple): - file: str - line: int - token: str - - -def _docstring_ids(tree: ast.Module) -> frozenset[int]: - return frozenset( - id(statement.value) - for node in ast.walk(tree) - if isinstance(node, (ast.Module, ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)) - for statement in node.body - if isinstance(statement, ast.Expr) - and isinstance(statement.value, ast.Constant) - and isinstance(statement.value.value, str) - ) - - -def _hits_in_file(path: Path) -> tuple[Hit, ...]: - tree: Final = ast.parse(path.read_text(encoding="utf-8"), filename=str(path)) - docstrings: Final = _docstring_ids(tree) - relative: Final = path.relative_to(REPO_ROOT).as_posix() - return tuple( - Hit(relative, node.lineno, match.group(0)) - for node in ast.walk(tree) - if isinstance(node, ast.Constant) and isinstance(node.value, str) and id(node) not in docstrings - for match in COMMERCIAL_TOKEN.finditer(node.value) - ) - - -def find_hits(scan_root: Path) -> tuple[Hit, ...]: - return tuple( - hit - for path in sorted(scan_root.rglob("*.py")) - if path.relative_to(REPO_ROOT).as_posix() != PARTITION_HELPER - for hit in _hits_in_file(path) - ) - - -def _violation_message(hit: Hit, found: int) -> str: - allowed: Final = ALLOWED_COUNTS.get((hit.file, hit.token)) - if allowed is None: - return f"{hit.file}:{hit.line}: hardcoded commercial AWS partition literal {hit.token!r}" - return ( - f"{hit.file}:{hit.line}: {hit.token!r} appears {found} times but ALLOWED covers {allowed}; " - "build it from the region helper or update the count" - ) - - -def main() -> int: - hits: Final = find_hits(SCAN_ROOT) - counts: Final = MappingProxyType(Counter((hit.file, hit.token) for hit in hits)) - violations: Final = tuple( - sorted(hit for hit in hits if Allowance(hit.file, hit.token, counts[hit.file, hit.token]) not in ALLOWED) - ) - stale: Final = tuple(entry for entry in sorted(ALLOWED) if (entry.file, entry.token) not in counts) - for hit in violations: - print(_violation_message(hit, counts[hit.file, hit.token])) - for allowance in stale: - print(f"{allowance.file}: ALLOWED entry {allowance.token!r} no longer matches anything, remove it") - if violations or stale: - print( - "\nBuild AWS hosts with get_aws_dns_suffix(region) and ARNs with get_aws_arn_prefix(region) " - "from litellm/litellm_core_utils/aws_partition.py so GovCloud and China regions resolve." - ) - return 1 - print(f"No hardcoded commercial AWS partition literals outside {PARTITION_HELPER}.") - return 0 - - -if __name__ == "__main__": - sys.exit(main()) diff --git a/tests/test_litellm/litellm_core_utils/test_aws_partition.py b/tests/test_litellm/litellm_core_utils/test_aws_partition.py index 24a38268ae9..3594d3c354c 100644 --- a/tests/test_litellm/litellm_core_utils/test_aws_partition.py +++ b/tests/test_litellm/litellm_core_utils/test_aws_partition.py @@ -1,11 +1,9 @@ import ast from pathlib import Path -from types import MappingProxyType from typing import Final -from urllib.parse import unquote, urlparse +from urllib.parse import urlparse import pytest -from botocore.credentials import Credentials import litellm from litellm.integrations.s3_v2 import S3Logger @@ -22,20 +20,8 @@ from litellm.llms.aws_polly.text_to_speech.transformation import AWSPollyTextToS from litellm.llms.bedrock.base_aws_llm import BaseAWSLLM from litellm.llms.bedrock.batches.transformation import BedrockBatchesConfig from litellm.llms.bedrock.chat.agentcore.transformation import AmazonAgentCoreConfig -from litellm.llms.bedrock.chat.invoke_agent.transformation import AmazonInvokeAgentConfig from litellm.llms.bedrock.common_utils import init_bedrock_client -from litellm.llms.bedrock.files.transformation import BedrockFilesConfig -from litellm.llms.bedrock.rerank.handler import BedrockRerankHandler -from litellm.llms.bedrock.vector_stores.transformation import BedrockVectorStoreConfig from litellm.llms.sagemaker.chat.transformation import SagemakerChatConfig -from litellm.llms.sagemaker.completion.handler import SagemakerLLM -from litellm.proxy.auth.rds_iam_token import init_rds_client -from litellm.proxy.guardrails.guardrail_hooks.bedrock_guardrails import BedrockGuardrail -from litellm.secret_managers.aws_secret_manager_v2 import AWSSecretsManagerV2 - -STATIC_AWS_CREDENTIALS: Final = MappingProxyType( - {"aws_access_key_id": "test-key", "aws_secret_access_key": "test-secret"} -) @pytest.mark.parametrize( @@ -120,48 +106,6 @@ def _s3_object_url(region: str) -> str: return logger._build_object_url("2025-01-01/key.json") -def _bedrock_job_arn(region: str) -> str: - return f"{get_aws_arn_prefix(region)}bedrock:{region}:111122223333:model-invocation-job/abc1234567" - - -def _bedrock_files_upload_url(region: str) -> str: - return BedrockFilesConfig().get_complete_file_url( - api_base=None, - api_key=None, - model="amazon.nova-pro-v1:0", - optional_params={}, - litellm_params={"s3_bucket_name": "batch-bucket", "s3_region_name": region}, - data={"file": ("batch.jsonl", b"{}", "application/jsonl"), "purpose": "batch"}, - ) - - -def _bedrock_files_download_url(region: str) -> str: - return ( - BedrockFilesConfig() - ._s3_request_target(optional_params={}, litellm_params={"s3_region_name": region}) - .endpoint_url - ) - - -def _bedrock_guardrail_url(region: str) -> str: - guardrail = BedrockGuardrail(guardrailIdentifier="guardrail-id", guardrailVersion="1") - return guardrail._prepare_request( - credentials=Credentials("test-key", "test-secret"), - data={"source": "INPUT", "content": []}, - optional_params={}, - aws_region_name=region, - ).url - - -def _secrets_manager_url(region: str) -> str: - endpoint_url, _headers, _body = AWSSecretsManagerV2(aws_region_name=region)._prepare_request( - action="GetSecretValue", - secret_name="my-secret", - optional_params=dict(STATIC_AWS_CREDENTIALS), - ) - return endpoint_url - - ENDPOINT_BUILDERS: Final = { "bedrock_runtime_default": lambda region: BaseAWSLLM()._select_default_endpoint_url("runtime", region), "bedrock_agent_default": lambda region: BaseAWSLLM()._select_default_endpoint_url("agent", region), @@ -180,13 +124,6 @@ ENDPOINT_BUILDERS: Final = { litellm_params={}, data={"input_file_id": "s3://bucket/key.jsonl"}, ), - "bedrock_batches_retrieve": lambda region: BedrockBatchesConfig().transform_retrieve_batch_request( - batch_id=_bedrock_job_arn(region), - optional_params=dict(STATIC_AWS_CREDENTIALS), - litellm_params={}, - )["url"], - "bedrock_files_upload": _bedrock_files_upload_url, - "bedrock_files_download": _bedrock_files_download_url, "bedrock_agentcore_invoke": lambda region: AmazonAgentCoreConfig().get_complete_url( api_base=None, api_key=None, @@ -194,32 +131,6 @@ ENDPOINT_BUILDERS: Final = { optional_params={}, litellm_params={}, ), - "bedrock_invoke_agent": lambda region: AmazonInvokeAgentConfig().get_complete_url( - api_base=None, - api_key=None, - model="agent/AGENT123/ALIAS456", - optional_params={"aws_region_name": region}, - litellm_params={}, - ), - "bedrock_guardrail_apply": _bedrock_guardrail_url, - "bedrock_rerank": lambda region: BedrockRerankHandler()._prepare_request( - model="amazon.rerank-v1:0", - api_base=None, - extra_headers=None, - data={"queries": [], "sources": []}, - optional_params={"aws_region_name": region, **STATIC_AWS_CREDENTIALS}, - )["endpoint_url"], - "bedrock_knowledgebase_search": lambda region: BedrockVectorStoreConfig().get_complete_url( - api_base=None, litellm_params={"aws_region_name": region} - ), - "secrets_manager": _secrets_manager_url, - "rds_iam_client": lambda region: ( - init_rds_client( - aws_region_name=region, - aws_access_key_id="test-key", - aws_secret_access_key="test-secret", - ).meta.endpoint_url - ), "polly": lambda region: AWSPollyTextToSpeechConfig().get_complete_url( model="polly/neural", api_base=None, @@ -241,19 +152,6 @@ ENDPOINT_BUILDERS: Final = { litellm_params={}, stream=True, ), - "sagemaker_completion": lambda region: ( - SagemakerLLM() - ._prepare_request( - credentials=Credentials("test-key", "test-secret"), - model="my-endpoint", - data={}, - messages=[], - litellm_params={}, - optional_params={}, - aws_region_name=region, - ) - .url - ), "s3_object_url": _s3_object_url, } @@ -284,18 +182,6 @@ def test_every_endpoint_builder_keeps_amazonaws_com_outside_cn(builder_name: str assert hostname.endswith(".amazonaws.com"), url -@pytest.mark.parametrize("region", ["us-gov-west-1", "us-gov-east-1"]) -@pytest.mark.parametrize("builder_name", sorted(ENDPOINT_BUILDERS)) -def test_every_endpoint_builder_respects_us_gov_partition(builder_name: str, region: str) -> None: - url = unquote(ENDPOINT_BUILDERS[builder_name](region)) - hostname = urlparse(url).hostname - assert hostname is not None - assert hostname.endswith(f".{region}.amazonaws.com"), url - assert "arn:aws:" not in url, url - if "arn:" in url: - assert "arn:aws-us-gov:" in url, url - - def _fstring_literal_offenders(needle: str) -> list[str]: litellm_root = Path(litellm.__file__).parent return [ From 5a5b18550cced0bc3e3af7b14e650172b42a6c46 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 20:16:09 +0000 Subject: [PATCH 4/8] test(e2e): cover bedrock batch files in govcloud Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/e2e/CONTRIBUTING.md | 4 + tests/e2e/batches/COVERAGE.md | 4 + tests/e2e/batches/test_batches_e2e.py | 84 +++++++++++++++++-- .../llm_nonconversational.yaml | 2 + tests/e2e/coverage_registry/schema.py | 1 + 5 files changed, 90 insertions(+), 5 deletions(-) diff --git a/tests/e2e/CONTRIBUTING.md b/tests/e2e/CONTRIBUTING.md index 20073e5d68f..75270250f30 100644 --- a/tests/e2e/CONTRIBUTING.md +++ b/tests/e2e/CONTRIBUTING.md @@ -23,6 +23,10 @@ The suites run against a live proxy, so bring one up first by running the litell OPENAI_API_KEY="sk-..." ANTHROPIC_API_KEY="sk-..." GEMINI_API_KEY="..." + AWS_GOVCLOUD_ACCESS_KEY_ID="..." + AWS_GOVCLOUD_SECRET_ACCESS_KEY="..." + AWS_GOVCLOUD_BATCH_S3_BUCKET="..." + AWS_GOVCLOUD_BATCH_ROLE_ARN="..." ``` 2. Bring up a Postgres and a Redis for the proxy to use. The repo-root `docker-compose.yml` already defines a Postgres on `5432`; a `docker run -p 6379:6379 redis:7` covers Redis. Point `DATABASE_URL` / `REDIS_HOST` / `REDIS_PORT` at whatever you run. Tests that read Redis directly default to the deployed shape (TLS + cluster mode) whenever `REDIS_HOST` is set, so for a local standalone Redis also set `REDIS_CLUSTER=false` and `REDIS_SSL=false` (plus `REDIS_PASSWORD` when your Redis requires auth) diff --git a/tests/e2e/batches/COVERAGE.md b/tests/e2e/batches/COVERAGE.md index 919c39f21a2..ad69031278b 100644 --- a/tests/e2e/batches/COVERAGE.md +++ b/tests/e2e/batches/COVERAGE.md @@ -21,6 +21,10 @@ failures are hard test failures (see `tests/e2e/CLAUDE.md`). | Vertex AI | yes | yes | yes | yes | yes (provider-transformed) | GCS (`gcs_bucket_name` / `GCS_BUCKET_NAME` on model) | | Bedrock | yes (unified only) | yes | yes | yes (unfiltered managed list) | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` + `AWS_BATCH_ROLE_ARN` on model) | +The GovCloud partition test requires `AWS_GOVCLOUD_ACCESS_KEY_ID`, +`AWS_GOVCLOUD_SECRET_ACCESS_KEY`, `AWS_GOVCLOUD_BATCH_S3_BUCKET`, and +`AWS_GOVCLOUD_BATCH_ROLE_ARN` in the proxy environment + Bedrock cancel maps to `StopModelInvocationJob` and comes back `cancelling`; the lifecycle asserts it the same way it does for OpenAI (`_CANCEL_ASSERTED_PROVIDERS`). Bedrock has no provider-side list, so list is the proxy's DB-backed managed view: the diff --git a/tests/e2e/batches/test_batches_e2e.py b/tests/e2e/batches/test_batches_e2e.py index c4b699190b8..adce2060ee8 100644 --- a/tests/e2e/batches/test_batches_e2e.py +++ b/tests/e2e/batches/test_batches_e2e.py @@ -21,21 +21,18 @@ import os import re import time from datetime import datetime, timedelta, timezone +from typing import Final import pytest -from pydantic import BaseModel - -from e2e_config import MASTER_KEY, PROXY_BASE_URL, unique_marker - from batch_cleanup import cleanup_batch, cleanup_file from batch_client import ( AZURE_FILE_EXPIRY_SECONDS, - batch_upload_form, UPLOAD_FILENAME, BatchClient, BatchCreateBody, BatchObject, FileObject, + batch_upload_form, is_model_access_denied, is_result_access_denied, ) @@ -57,6 +54,7 @@ from capabilities import ( openai_batch_params, raw_id_matches_provider, ) +from e2e_config import MASTER_KEY, PROXY_BASE_URL, unique_marker from e2e_http import ( FileUploadForm, Result, @@ -68,6 +66,7 @@ from e2e_http import ( ) from lifecycle import ResourceManager from models import KeyGenerateBody, KeyMetadata, LiteLLMParamsBody, SpendLogRow +from pydantic import BaseModel pytestmark = pytest.mark.e2e @@ -1006,6 +1005,81 @@ class TestBedrockBatchAssumeRole: assert fetched.id == batch.id +GOVCLOUD_REGION: Final = "us-gov-west-1" +GOVCLOUD_RAW_MODEL: Final = "bedrock/amazon.nova-lite-v1:0" + + +def _govcloud_params() -> LiteLLMParamsBody: + return LiteLLMParamsBody( + model=GOVCLOUD_RAW_MODEL, + aws_access_key_id="os.environ/AWS_GOVCLOUD_ACCESS_KEY_ID", + aws_secret_access_key="os.environ/AWS_GOVCLOUD_SECRET_ACCESS_KEY", + aws_region_name=GOVCLOUD_REGION, + s3_region_name=GOVCLOUD_REGION, + s3_bucket_name="os.environ/AWS_GOVCLOUD_BATCH_S3_BUCKET", + s3_access_key_id="os.environ/AWS_GOVCLOUD_ACCESS_KEY_ID", + s3_secret_access_key="os.environ/AWS_GOVCLOUD_SECRET_ACCESS_KEY", + aws_batch_role_arn="os.environ/AWS_GOVCLOUD_BATCH_ROLE_ARN", + ) + + +class TestBedrockBatchGovCloud: + """Bedrock batch lifecycle in the AWS GovCloud partition (us-gov-west-1). + + The deployment carries a GovCloud region for both Bedrock and S3, so the proxy has to + sign the file upload against the us-gov S3 endpoint and submit the job to the us-gov + Bedrock endpoint. Commercial-partition hostnames or arn:aws: ARNs reject the GovCloud + key, so a partition regression fails the upload instead of passing silently. + """ + + @pytest.mark.covers( + "llm.batches.bedrock.govcloud_partition.nonstream.works", + "llm.files.bedrock.govcloud_partition.nonstream.works", + exercised_on=["batches", "files"], + ) + def test_unified_file_upload_and_batch_create_in_govcloud( + self, client: BatchClient, resources: ResourceManager + ) -> None: + model_name: Final = batch_model_name("bedrock-govcloud-batch") + model_id: Final = client.create_model(model_name, _govcloud_params()) + resources.defer(lambda: client.delete_model(model_id)) + key: Final = resources.key() + file: Final = unwrap( + client.upload_file( + content=render_jsonl(GOVCLOUD_RAW_MODEL), + form=FileUploadForm(purpose="batch", target_model_names=model_name), + key=key, + ) + ) + resources.defer(lambda: cleanup_file(client, file.id, key=key)) + assert_file_object(file, provider="bedrock") + + downloaded: Final = client.proxy.transport.download( + f"/v1/files/{file.id}/content", + headers=client.proxy.transport.bearer(key), + ) + assert downloaded.status_code == 200, ( + f"GovCloud file content must be 200, got {downloaded.status_code}: {downloaded.body[:300]}" + ) + assert downloaded.body.strip(), "GovCloud file content download returned an empty body" + + created: Final = client.create_batch(body=BatchCreateBody(input_file_id=file.id), key=key) + require_successful_call(created) + batch: Final = BatchObject.model_validate_json(created.body) + resources.defer(lambda: cleanup_batch(client, batch.id, key=key)) + + assert is_managed_id(batch.id), ( + f"GovCloud create via target_model_names must return a managed batch id, got {batch.id!r}" + ) + assert batch.status in CREATED_BATCH_STATUSES, ( + f"GovCloud batch has non-transitional status {batch.status!r}" + ) + assert_batch_object(batch) + + fetched: Final = unwrap(client.retrieve_batch(batch.id, key=key)) + assert fetched.id == batch.id + + GEMINI_FILES_RAW_MODEL = "gemini-2.5-flash" diff --git a/tests/e2e/coverage_registry/llm_nonconversational.yaml b/tests/e2e/coverage_registry/llm_nonconversational.yaml index 635ea3f7ea5..50f9b9808b2 100644 --- a/tests/e2e/coverage_registry/llm_nonconversational.yaml +++ b/tests/e2e/coverage_registry/llm_nonconversational.yaml @@ -23,6 +23,7 @@ - {id: llm.batches.vertex.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: vertex, capability: basic, streaming: nonstream, assertions: [works], source: "batches/capabilities.py:98", rationale: "Vertex batches"} - {id: llm.batches.bedrock.basic.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "batches/capabilities.py:98", rationale: "Bedrock batches (encoded/unified only)"} - {id: llm.batches.bedrock.assume_role.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: bedrock_converse, capability: assume_role, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "Bedrock batch create under STS assume-role credentials"} +- {id: llm.batches.bedrock.govcloud_partition.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: bedrock_converse, capability: govcloud_partition, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "Bedrock batch create in the us-gov-west-1 partition"} - {id: llm.batches.bedrock.cancel.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "Bedrock batch cancel (StopModelInvocationJob) returns the same id with a cancelling/cancelled status"} - {id: llm.batches.bedrock.list.nonstream.works, module: llm, tier: P0, subject_endpoint: batches, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "A Bedrock managed batch is present in the GET /v1/batches list envelope"} - {id: llm.batches.hosted_vllm.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: batches, route: hosted_vllm, capability: basic, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "hosted_vllm OpenAI-compatible batch create"} @@ -45,6 +46,7 @@ - {id: llm.files.azure_openai.upload.nonstream.works, module: llm, tier: P0, subject_endpoint: files, route: azure_openai, capability: basic, streaming: nonstream, assertions: [works], source: "batches/capabilities.py:45", rationale: "Azure file upload managed backend"} - {id: llm.files.vertex.upload.nonstream.works, module: llm, tier: P0, subject_endpoint: files, route: vertex, capability: basic, streaming: nonstream, assertions: [works], source: "batches/capabilities.py:52", rationale: "Vertex file upload to GCS"} - {id: llm.files.bedrock.upload.nonstream.works, module: llm, tier: P0, subject_endpoint: files, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "batches/capabilities.py:59", rationale: "Bedrock file upload to S3"} +- {id: llm.files.bedrock.govcloud_partition.nonstream.works, module: llm, tier: P0, subject_endpoint: files, route: bedrock_converse, capability: govcloud_partition, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "Bedrock file upload to an S3 bucket in the us-gov-west-1 partition"} - {id: llm.files.gemini.upload.nonstream.works, module: llm, tier: P1, subject_endpoint: files, route: gemini, capability: basic, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "Gemini Files API upload via proxy"} - {id: llm.files.hosted_vllm.upload.nonstream.works, module: llm, tier: P1, subject_endpoint: files, route: hosted_vllm, capability: basic, streaming: nonstream, assertions: [works], source: "test_batches_e2e.py", rationale: "hosted_vllm OpenAI-compatible file upload"} - {id: llm.files.openai.require_managed_files_upload.nonstream.works, module: llm, tier: P1, subject_endpoint: files, route: openai, capability: input_validation, streaming: nonstream, assertions: [works], source: "test_managed_files_enforcement_e2e.py / LIT-5902", rationale: "With require_managed_files enabled, an upload without target_model_names and an upload carrying a model param are both rejected 400; runs only in the sequential managed-files stack phase (E2E_MANAGED_FILES_STACK)"} diff --git a/tests/e2e/coverage_registry/schema.py b/tests/e2e/coverage_registry/schema.py index 03d15f532b8..fa6dad90126 100644 --- a/tests/e2e/coverage_registry/schema.py +++ b/tests/e2e/coverage_registry/schema.py @@ -64,6 +64,7 @@ LlmCapability = Literal[ "assume_role", "basic", "count_tokens", + "govcloud_partition", "input_validation", "long_context_1m", "mid_conversation_system", From 5aec6d7bb691a3a034983da123387f17a1ea634a Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 21:31:33 +0000 Subject: [PATCH 5/8] test(e2e): assert govcloud file content round-trips the uploaded record Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/e2e/batches/test_batches_e2e.py | 33 +++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/e2e/batches/test_batches_e2e.py b/tests/e2e/batches/test_batches_e2e.py index adce2060ee8..eff8f297f25 100644 --- a/tests/e2e/batches/test_batches_e2e.py +++ b/tests/e2e/batches/test_batches_e2e.py @@ -66,7 +66,7 @@ from e2e_http import ( ) from lifecycle import ResourceManager from models import KeyGenerateBody, KeyMetadata, LiteLLMParamsBody, SpendLogRow -from pydantic import BaseModel +from pydantic import BaseModel, Field pytestmark = pytest.mark.e2e @@ -74,6 +74,25 @@ CREATED_BATCH_STATUSES = {"validating", "in_progress", "finalizing"} BATCH_CANCEL_DELAY_SECONDS = 2 BATCH_TERMINAL_BEFORE_CANCEL = {"failed", "cancelled", "expired"} BATCH_OP_RETRIES = 5 + + +class _GovCloudBedrockContent(BaseModel): + text: str + + +class _GovCloudBedrockMessage(BaseModel): + content: tuple[_GovCloudBedrockContent, ...] + + +class _GovCloudBedrockInput(BaseModel): + messages: tuple[_GovCloudBedrockMessage, ...] + + +class _GovCloudBedrockRecord(BaseModel): + record_id: str = Field(alias="recordId") + model_input: _GovCloudBedrockInput = Field(alias="modelInput") + + # Azure / Vertex cancel and the pre-cancel re-retrieve are provider-side flakes # (connection refused, brief 500s) and the registry only has one basic cell per # provider (shared across scenarios). Create + retrieve already prove routing; @@ -1061,7 +1080,17 @@ class TestBedrockBatchGovCloud: assert downloaded.status_code == 200, ( f"GovCloud file content must be 200, got {downloaded.status_code}: {downloaded.body[:300]}" ) - assert downloaded.body.strip(), "GovCloud file content download returned an empty body" + downloaded_lines: Final = downloaded.body.strip().splitlines() + assert len(downloaded_lines) == 1, ( + f"GovCloud file content download must contain one JSONL record, got {len(downloaded_lines)}" + ) + downloaded_record: Final = _GovCloudBedrockRecord.model_validate(json.loads(downloaded_lines[0])) + assert downloaded_record.record_id == "req-1", ( + f"GovCloud file content must preserve the uploaded custom_id, got {downloaded_record.record_id!r}" + ) + assert downloaded_record.model_input.messages[0].content[0].text == "ping", ( + "GovCloud file content must preserve the uploaded message text" + ) created: Final = client.create_batch(body=BatchCreateBody(input_file_id=file.id), key=key) require_successful_call(created) From 4b45fd5f44a6a85b0475bf470a5abe14db3eb38a Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 21:47:21 +0000 Subject: [PATCH 6/8] docs(e2e): drop govcloud keys from the contributing starter env Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/e2e/CONTRIBUTING.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/e2e/CONTRIBUTING.md b/tests/e2e/CONTRIBUTING.md index 75270250f30..20073e5d68f 100644 --- a/tests/e2e/CONTRIBUTING.md +++ b/tests/e2e/CONTRIBUTING.md @@ -23,10 +23,6 @@ The suites run against a live proxy, so bring one up first by running the litell OPENAI_API_KEY="sk-..." ANTHROPIC_API_KEY="sk-..." GEMINI_API_KEY="..." - AWS_GOVCLOUD_ACCESS_KEY_ID="..." - AWS_GOVCLOUD_SECRET_ACCESS_KEY="..." - AWS_GOVCLOUD_BATCH_S3_BUCKET="..." - AWS_GOVCLOUD_BATCH_ROLE_ARN="..." ``` 2. Bring up a Postgres and a Redis for the proxy to use. The repo-root `docker-compose.yml` already defines a Postgres on `5432`; a `docker run -p 6379:6379 redis:7` covers Redis. Point `DATABASE_URL` / `REDIS_HOST` / `REDIS_PORT` at whatever you run. Tests that read Redis directly default to the deployed shape (TLS + cluster mode) whenever `REDIS_HOST` is set, so for a local standalone Redis also set `REDIS_CLUSTER=false` and `REDIS_SSL=false` (plus `REDIS_PASSWORD` when your Redis requires auth) From bdd9335116441596a7a476b59d15babc6a358d02 Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 21:51:02 +0000 Subject: [PATCH 7/8] docs(e2e): list the govcloud bedrock test as a coverage matrix row Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/e2e/batches/COVERAGE.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/e2e/batches/COVERAGE.md b/tests/e2e/batches/COVERAGE.md index ad69031278b..a98d771ffeb 100644 --- a/tests/e2e/batches/COVERAGE.md +++ b/tests/e2e/batches/COVERAGE.md @@ -20,10 +20,7 @@ failures are hard test failures (see `tests/e2e/CLAUDE.md`). | Azure | yes | yes | yes | yes | yes (byte-verbatim) | Azure Files | | Vertex AI | yes | yes | yes | yes | yes (provider-transformed) | GCS (`gcs_bucket_name` / `GCS_BUCKET_NAME` on model) | | Bedrock | yes (unified only) | yes | yes | yes (unfiltered managed list) | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` + `AWS_BATCH_ROLE_ARN` on model) | - -The GovCloud partition test requires `AWS_GOVCLOUD_ACCESS_KEY_ID`, -`AWS_GOVCLOUD_SECRET_ACCESS_KEY`, `AWS_GOVCLOUD_BATCH_S3_BUCKET`, and -`AWS_GOVCLOUD_BATCH_ROLE_ARN` in the proxy environment +| Bedrock GovCloud (`us-gov-west-1`) | yes (unified only) | yes | no | no | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` + `AWS_GOVCLOUD_*` on model) | Bedrock cancel maps to `StopModelInvocationJob` and comes back `cancelling`; the lifecycle asserts it the same way it does for OpenAI (`_CANCEL_ASSERTED_PROVIDERS`). From bbde2f8a3ae1290189e6f4707d82740cc4d4b5ca Mon Sep 17 00:00:00 2001 From: kerry Date: Thu, 17 Sep 2026 22:07:50 +0000 Subject: [PATCH 8/8] docs(e2e): name the govcloud env vars in the coverage matrix row Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- tests/e2e/batches/COVERAGE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/batches/COVERAGE.md b/tests/e2e/batches/COVERAGE.md index a98d771ffeb..b36d8937ad0 100644 --- a/tests/e2e/batches/COVERAGE.md +++ b/tests/e2e/batches/COVERAGE.md @@ -20,7 +20,7 @@ failures are hard test failures (see `tests/e2e/CLAUDE.md`). | Azure | yes | yes | yes | yes | yes (byte-verbatim) | Azure Files | | Vertex AI | yes | yes | yes | yes | yes (provider-transformed) | GCS (`gcs_bucket_name` / `GCS_BUCKET_NAME` on model) | | Bedrock | yes (unified only) | yes | yes | yes (unfiltered managed list) | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` + `AWS_BATCH_ROLE_ARN` on model) | -| Bedrock GovCloud (`us-gov-west-1`) | yes (unified only) | yes | no | no | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` + `AWS_GOVCLOUD_*` on model) | +| Bedrock GovCloud (`us-gov-west-1`) | yes (unified only) | yes | no | no | yes (provider-transformed) | S3 (`s3_bucket_name` + `aws_*` on model, resolved from `AWS_GOVCLOUD_ACCESS_KEY_ID` / `AWS_GOVCLOUD_SECRET_ACCESS_KEY` / `AWS_GOVCLOUD_BATCH_S3_BUCKET` / `AWS_GOVCLOUD_BATCH_ROLE_ARN`) | Bedrock cancel maps to `StopModelInvocationJob` and comes back `cancelling`; the lifecycle asserts it the same way it does for OpenAI (`_CANCEL_ASSERTED_PROVIDERS`).