litellm/tests/logging_callback_tests
Cursor Agent b637d9f64a
test(vcr): classify cache verdicts, detect live calls, surface cost leaks
Convert the per-test VCR verdict line from a single 'NOOP / HIT / MISS /
PARTIAL' tag into a classified outcome that distinguishes the cases that
silently bill the live API on every CI run from the ones that don't:

  HIT                         pure replay
  PARTIAL                     mixed replay + new recordings
  MISS:RECORDED               new cassette saved to Redis (cached next run)
  MISS:OVERFLOW               cassette > MAX_EPISODES_PER_CASSETTE; persister
                              refused to save; re-bills every run
  MISS:NOT_PERSISTED          test failed; save_cassette skipped; re-bills
  NOOP                        VCR-marked but no HTTP traffic (mocked elsewhere)
  UNMARKED:LIVE_CALL          test bypassed VCR AND opened a TCP connection
                              to a known LLM provider host -> wasted spend
  UNMARKED:NO_TRAFFIC         test bypassed VCR but didn't call out

The UNMARKED:LIVE_CALL signal is what converts 'this test probably hits
live' into 'this test connected to api.openai.com'. We install a
socket.connect / socket.create_connection wrapper for the duration of
each non-VCR-marked test and record any outbound TCP to a known LLM
provider hostname. The probe sits below the httpx layer so vcrpy and
respx (which both patch above the socket) are unaffected.

Replace the file-level _RESPX_CONFLICTING_FILES blacklists in the
llm_translation and local_testing conftests with per-item respx
detection in apply_vcr_auto_marker_to_items. A test now skips VCR when
it actually carries @pytest.mark.respx or has respx_mock in its fixture
chain - not just because some other test in the same file imports
MockRouter. Items skipped by skip_files are split into respx_conflict
(real conflict, the module wires up respx) vs file_opt_out (dead skip-
list entry whose module never touches respx) so the session summary
makes pruning obvious.

Stabilize the AWS SigV4 fingerprint: the Authorization header on
Bedrock requests rotates its Credential date and Signature on every
call, which previously pushed every Bedrock test past the 50-episode
overflow threshold. Extract the access-key id only
('aws-sigv4:AKIA...') so two requests with the same identity match.

Always emit verdict logging when VCR is active (set
LITELLM_VCR_VERBOSE=0 to opt back into the legacy quiet mode). Add a
session-end classification summary that lists overflow tests, unmarked
live-call tests, and the skip-reason breakdown.

Wire the live-call probe + summary hook into every test directory that
already uses the Redis-backed VCR cache (audio_tests, guardrails_tests,
image_gen_tests, litellm_utils_tests, llm_responses_api_testing,
llm_translation, local_testing, logging_callback_tests, ocr_tests,
pass_through_unit_tests, router_unit_tests, search_tests,
unified_google_tests).

Add tests/llm_translation/test_vcr_classification.py covering the
verdict classifier, skip-reason tagging, AWS SigV4 fingerprint stability,
live-host classification, and session summary rendering.

Co-authored-by: Mateo Wang <mateo-berri@users.noreply.github.com>
2026-05-13 00:31:47 +00:00
..
gcs_pub_sub_body test fixes 2026-03-30 16:59:27 -07:00
langfuse_expected_request_body [Test Fix] fix gov pricing tests (#25022) 2026-04-02 15:55:55 -07:00
base_test.py Litellm dev 11 11 2024 (#6693) 2024-11-12 00:16:35 +05:30
conftest.py test(vcr): classify cache verdicts, detect live calls, surface cost leaks 2026-05-13 00:31:47 +00:00
create_mock_standard_logging_payload.py (fixes) datadog logging - handle 1MB max log size on DD (#6996) 2024-12-02 23:01:42 -08:00
gettysburg.wav (Testing) - Add e2e testing for langfuse logging with tags (#7922) 2025-01-22 09:09:25 -08:00
log.txt test: update test 2025-04-10 14:04:57 -07:00
test_alerting.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_amazing_s3_logs.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_assemble_streaming_responses.py test(test_assemble_streaming_responses.py): update test to use correct type 2025-03-17 18:17:01 -07:00
test_bedrock_knowledgebase_hook.py Fix extra body error 2026-04-29 08:34:31 +05:30
test_built_in_tools_cost_tracking.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_custom_callback_router.py test: test 2026-03-28 19:17:38 -07:00
test_datadog.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_datadog_llm_obs.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_dynamic_otel_keys.py Litellm fix langfuse otel trace (#20382) 2026-02-03 22:40:19 -08:00
test_gcs_pub_sub.py feat(guardrails): LLM-as-a-Judge guardrail (#26360) 2026-04-24 17:15:32 -07:00
test_generic_api_callback.py feat(logging): add retry settings for generic API logger (#26645) 2026-04-28 08:38:17 -07:00
test_humanloop_unit_tests.py HumanLoop integration for Prompt Management (#7479) 2024-12-30 22:26:03 -08:00
test_langfuse_dynamic_credentials.py fix(callbacks): preserve langfuse secret alias 2026-04-30 14:36:51 -07:00
test_langfuse_e2e_test.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_langfuse_unit_tests.py add tests for fix 2026-03-15 00:58:08 +05:30
test_langsmith_dynamic_credentials.py chore(callbacks): guard dynamic integration hosts 2026-04-30 14:27:19 -07:00
test_langsmith_unit_test.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_log_db_redis_services.py LiteLLM Minor Fixes & Improvements (12/05/2024) (#7037) 2024-12-05 00:02:31 -08:00
test_logging_redaction_e2e_test.py fix(proxy): sanitize redaction controls at ingress 2026-04-29 22:52:31 -07:00
test_moderations_api_logging.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_opentelemetry_unit_tests.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_otel_logging.py fix(logging): add litellm_call_id to StandardLoggingPayload and OTel span (#26133) 2026-04-21 15:24:32 -07:00
test_pagerduty_alerting.py [Refactor] Make Pagerduty a free feature (#10857) 2025-05-15 10:12:06 -07:00
test_posthog.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_spend_logs.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_sqs_logger.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_standard_logging_payload.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_standard_logging_payload_excluded_fields.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_token_counting.py test_stream_token_counting_anthropic_with_include_usage 2025-10-31 20:24:58 -07:00
test_unit_test_litellm_logging.py (performance improvement - litellm sdk + proxy) - ensure litellm does not create unnecessary threads when running async functions (#7680) 2025-01-10 17:57:22 -08:00
test_unit_tests_init_callbacks.py style: run black formatter on files from main merge 2026-04-17 13:02:59 -07:00
test_view_request_resp_logs.py Fix CI: Revert security scan changes and add GitGuardian ignore rules (#18358) 2025-12-22 17:03:53 -08:00