Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/_live_test_helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

import pytest


def _skip_live_prompt_caching_test():
if os.environ.get("LITELLM_RUN_LIVE_PROMPT_CACHING_TESTS") != "1":
pytest.skip("Live prompt-caching E2E tests are opt-in")
if os.environ.get("CASSETTE_REDIS_URL"):
pytest.skip("Live prompt-caching E2E tests cannot run under VCR replay")
19 changes: 19 additions & 0 deletions tests/_vcr_conftest_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,25 @@ def emit_vcr_classification_summary(terminalreporter) -> None:
continue
terminalreporter.write_line(f" [{verdict}] {n}")

leak_verdicts = (
VERDICT_PARTIAL,
VERDICT_MISS_OVERFLOW,
VERDICT_MISS_NOT_PERSISTED,
VERDICT_UNMARKED_LIVE_CALL,
)
leak_counts = {verdict: counts.get(verdict, 0) for verdict in leak_verdicts}
total_leaks = sum(leak_counts.values())
terminalreporter.write_sep("-", "VCR COST LEAK CHECK", bold=True)
if total_leaks:
rendered = ", ".join(
f"{verdict}={count}" for verdict, count in leak_counts.items() if count
)
terminalreporter.write_line(f" FAIL: {rendered}")
else:
terminalreporter.write_line(
" PASS: no overflow, partial, not-persisted, or unmarked live-call verdicts"
)
Comment on lines +1941 to +1950

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 VCR COST LEAK CHECK prints "FAIL" but does not fail the test run

terminalreporter.write_line() writes display text only — it has no effect on the pytest exit code. If a future commit re-introduces an UNMARKED:LIVE_CALL or MISS:NOT_PERSISTED verdict, CI will print FAIL: UNMARKED:LIVE_CALL=N but the job will still exit 0 and the regression will silently merge. To turn this into a hard gate the function needs to mutate terminalreporter._session.exitstatus (or the exitstatus arg passed to pytest_terminal_summary) when total_leaks > 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is intentional. The VCR COST LEAK CHECK is a visibility aid, not a hard exit-code gate, and that scope is deliberate. emit_vcr_classification_summary backs the pytest_terminal_summary hook in 14 test directories, 8 of which this PR does not touch (audio_tests, batches_tests, guardrails_tests, image_gen_tests, llm_responses_api_testing, router_unit_tests, search_tests, unified_google_tests). Mutating terminalreporter._session.exitstatus here would flip every one of those suites into a hard CI failure on any benign PARTIAL or transient leak verdict, well outside this PR's scope of closing specific leaks. The PASS/FAIL line already removes the silent-regression problem by surfacing the leak verdicts as an unmissable line; promoting it to a blocking gate is a separate rollout to make once every wired-up suite is confirmed leak-free, not something to land inside this test-cleanup PR

Comment on lines +1941 to +1950

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 VCR cost-leak check is informational only

The FAIL branch writes to the terminal reporter but never modifies the pytest exit code, so a run with leaks will still exit 0 and pass CI. If the intent is to enforce the budget (the PR description says "adds a guard so they stay there"), the block should also signal failure — for example by using a pytest_sessionfinish hook that reads session_stats_snapshot() and sets session.exitstatus = ExitCode.FAILED. As written the check is a useful visibility aid but not a regression gate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping this informational is deliberate rather than an oversight. emit_vcr_classification_summary is shared by the pytest_terminal_summary hooks of 14 test directories, and 8 of them are untouched by this PR (audio_tests, batches_tests, guardrails_tests, image_gen_tests, llm_responses_api_testing, router_unit_tests, search_tests, unified_google_tests). A pytest_sessionfinish hook that reads session_stats_snapshot() and sets session.exitstatus = ExitCode.FAILED would therefore turn every one of those unrelated suites red the moment any benign PARTIAL or transient verdict appears, which is a global behavior change beyond closing the specific leaks this PR targets. The PR's guard is the surfaced PASS/FAIL line: it makes a future regression unmissable in the run output instead of letting it hide among raw counts. Turning that into a hard budget gate is a follow-up to take once all wired-up suites are verified leak-free, so I'm intentionally leaving the exit code untouched here


overflow = snapshot["overflow_tests"]
if overflow:
terminalreporter.write_sep(
Expand Down
27 changes: 2 additions & 25 deletions tests/litellm_utils_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,9 @@

_verbose_state = VerboseReporterState()

_VCR_INCOMPATIBLE_FILES = frozenset()

# Files where VCR replay breaks the test:
# - ``test_litellm_overhead.py``: asserts overhead/total < 40%, which
# inverts when cached replay collapses the upstream time to microseconds.
_VCR_INCOMPATIBLE_FILES = frozenset(
{
"test_litellm_overhead.py",
}
)

# AWS Secrets Manager resource-lifecycle tests. Each run creates a secret
# under a per-run unique name (``litellm_test_<uuid>``) and either asserts the
# API response echoes that exact unique name or reads it straight back. The
# name *must* be unique per run because AWS enforces a >=7-day deletion
# recovery window — a fixed name can't be re-created on the daily VCR
# re-record. Deterministic replay returns the previously-recorded (different)
# name, so the unique-name round-trip cannot be reproduced offline. The
# config-parsing tests in the same file (settings / STS endpoint) make no such
# unique-resource calls and stay VCR-cached.
_VCR_INCOMPATIBLE_NODEID_SUFFIXES: tuple[str, ...] = (
"::test_write_and_read_simple_secret",
"::test_write_and_read_json_secret",
"::test_read_nonexistent_secret",
"::test_primary_secret_functionality",
"::test_write_secret_with_description_and_tags",
)
_VCR_INCOMPATIBLE_NODEID_SUFFIXES: tuple[str, ...] = ()


@pytest.fixture(scope="function", autouse=True)
Expand Down
11 changes: 10 additions & 1 deletion tests/litellm_utils_tests/test_aws_secret_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import litellm.types
import litellm.types.utils


load_dotenv()
import io

Expand Down Expand Up @@ -52,6 +51,11 @@ async def wrapper(*args, **kwargs):

def check_aws_credentials():
"""Helper function to check if AWS credentials are set"""
if os.getenv("LITELLM_RUN_LIVE_AWS_SECRET_MANAGER_TESTS") != "1":
pytest.skip("Live AWS Secrets Manager E2E tests are opt-in")
if os.getenv("CASSETTE_REDIS_URL"):
pytest.skip("Live AWS Secrets Manager E2E tests cannot run under VCR replay")

required_vars = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_REGION_NAME"]
missing_vars = [var for var in required_vars if not os.getenv(var)]
if missing_vars:
Expand Down Expand Up @@ -444,6 +448,11 @@ async def test_end_to_end_iam_role_secret_write():
- TEST_IAM_ROLE_ARN environment variable with ARN of a role that can be assumed
- Proper AWS credentials configured (via instance profile, IAM role, or environment)
"""
if os.getenv("LITELLM_RUN_LIVE_AWS_SECRET_MANAGER_TESTS") != "1":
pytest.skip("Live AWS Secrets Manager E2E tests are opt-in")
if os.getenv("CASSETTE_REDIS_URL"):
pytest.skip("Live AWS Secrets Manager E2E tests cannot run under VCR replay")

# Skip if TEST_IAM_ROLE_ARN is not set
test_role_arn = os.getenv("TEST_IAM_ROLE_ARN")
if not test_role_arn:
Expand Down
Loading
Loading