Commit Graph

32441 Commits

Author SHA1 Message Date
Sameer Kankute 6ceebdcfe2 fix mypy 2026-02-16 19:05:06 +05:30
Sameer Kankute 4548d9fbe9 fix mypy 2026-02-16 18:55:21 +05:30
Sameer Kankute ac2f17a514 fix: proxy/batches_endpoints/endpoints.py:309:11: PLR0915 Too many statements (54 > 50) 2026-02-16 18:41:06 +05:30
Sameer Kankute 72a1bd66c7 Merge pull request #21157 from Point72/ephrimstanley/s3-logger-skip-missing-standard-logging-object
Managed batches - Misc bug fixes
2026-02-16 18:29:59 +05:30
Emerson Gomes 06e7bfce2e perf(spend): avoid duplicate daily agent transaction computation (#21187) 2026-02-16 18:28:34 +05:30
Constantine 7ef9083812 fix(aiohttp): prevent closing shared ClientSession in AiohttpTransport (#21117)
When a shared ClientSession is passed to LiteLLMAiohttpTransport,
calling aclose() on the transport would close the shared session,
breaking other clients still using it.

Add owns_session parameter (default True for backwards compatibility)
to AiohttpTransport and LiteLLMAiohttpTransport. When a shared session
is provided in http_handler.py, owns_session=False is set to prevent
the transport from closing a session it does not own.

This aligns AiohttpTransport with the ownership pattern already used
in AiohttpHandler (aiohttp_handler.py).
2026-02-16 18:28:28 +05:30
Kristoffer Arlind 51b1b0339c Allow effort="max" for Claude Opus 4.6 (#21112) 2026-02-16 18:28:22 +05:30
Ephrim Stanley a3762e7d49 Addressed greptile comments to extract common helpers and return 404 2026-02-16 07:58:04 -05:00
Fly 9c71d8b61b feat(s3): add support for virtual-hosted-style URLs (#21094)
Add s3_use_virtual_hosted_style parameter to support AWS S3 virtual-hosted-style URL format (bucket.endpoint/key) alongside the existing path-style format (endpoint/bucket/key).

This enables compatibility with S3-compatible services like MinIO and aligns with AWS S3 official terminology.
2026-02-16 18:26:44 +05:30
jquinter 43f9a588d9 fix: improve Langfuse test isolation to prevent flaky failures (#21093)
The test was creating fresh mocks but not fully isolating from setUp state,
causing intermittent CI failures with 'Expected generation to be called once.
Called 0 times.'

Instead of creating fresh mocks, properly reset the existing setUp mocks to
ensure clean state while maintaining proper mock chain configuration.
2026-02-16 18:26:37 +05:30
Ephrim Stanley cc4e022176 Removed stray .md file 2026-02-16 07:14:42 -05:00
jquinter 44bb1dafdb Merge pull request #21286 from BerriAI/fix/proxy-config-callback-validation
fix(test): mock environment variables for callback validation test
2026-02-15 21:11:12 -03:00
jquinter 49fd1b5de4 Merge pull request #21279 from BerriAI/fix/tokenizer-cache-test-isolation
fix(test): clear tokenizer LRU cache for test isolation
2026-02-15 21:05:38 -03:00
jquinter 5be76dc6e0 Merge pull request #21281 from BerriAI/fix/add-fakeredis-dependency
fix(deps): add fakeredis for pod lock manager tests
2026-02-15 21:04:54 -03:00
Julio Quinteros Pro 2d41b03f8b fix(test): mock environment variables for callback validation test
The test test_proxy_config_state_post_init_callback_call was failing with:
```
ValidationError: 2 validation errors for TeamCallbackMetadata
callback_vars.langfuse_public_key
  Input should be a valid string [type=string_type, input_value=None, input_type=NoneType]
```

Root cause: The test uses environment variable references like
"os.environ/LANGFUSE_PUBLIC_KEY" which get resolved at runtime. In
parallel execution with --dist=loadscope, these environment variables
may not be set in all worker processes, causing the resolution to
return None, which fails Pydantic validation expecting strings.

Solution: Use monkeypatch to set the required environment variables
before the test runs. This ensures consistent behavior across all
test execution environments (local, CI, parallel workers).

Fixes test failure exposed by PR #21277.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 20:44:17 -03:00
Julio Quinteros Pro 706792ba96 refactor: simplify cache clearing to avoid over-engineering
Based on Greptile feedback:
- Removed autouse fixture (applied too broadly to unrelated tests)
- Removed setUpClass (redundant since setUp runs before every test)
- Kept module-level clear and setUp() method (sufficient for test isolation)
- Added blank line for proper formatting

The simplified approach still ensures test isolation under --dist=loadscope
while avoiding unnecessary complexity.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 20:36:24 -03:00
Julio Quinteros Pro e82fc28f42 fix(deps): add fakeredis for pod lock manager tests
The test file test_e2e_pod_lock_manager.py requires fakeredis but it was
not declared as a dev dependency, causing import errors when the test
module is loaded.

This is a pre-existing issue that was exposed by better test coverage in
PR 21277 but is not caused by that PR.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 20:33:09 -03:00
jquinter bae8816c35 Update tests/test_litellm/litellm_core_utils/test_token_counter.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-15 20:27:29 -03:00
Julio Quinteros Pro 5f79bf4906 fix(test): clear tokenizer LRU cache for test isolation
The _select_tokenizer_helper function is decorated with @lru_cache, which
causes test failures when tests run sequentially with --dist=loadscope.
Previous tests' cached results prevent from_pretrained from being called,
causing mock assertions to fail.

Implemented triple-layer cache clearing:
1. Module-level clear on import
2. Class-level clear in setUpClass
3. Function-level clear in setUp + pytest fixture

This ensures test isolation while allowing --dist=loadscope to provide better
overall CI stability (70% pass rate vs 40% without loadscope).

Fixes the intermittent failure in TestTokenizerSelection where
'from_pretrained' mock was never called due to cache hits.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 20:23:27 -03:00
jquinter e1e8a12bf2 Merge pull request #21217 from BerriAI/fix/anthropic-structured-output-test
fix(test): update test_other_constraints_preserved for new schema filtering
2026-02-15 20:20:49 -03:00
jquinter 682e8c0352 Merge pull request #21276 from BerriAI/fix/vertex-gpt-oss-test-mock
fix(test): mock vertexai module in GPT-OSS tests to prevent authentication
2026-02-15 19:50:32 -03:00
jquinter b0f2b4bb2d Merge pull request #21275 from BerriAI/fix/watsonx-gpt-oss-async-mock
fix(test): use async side_effect for client.post mock in watsonx test
2026-02-15 19:44:33 -03:00
Julio Quinteros Pro 03d67d7801 fix(test): mock vertexai module in GPT-OSS tests to prevent authentication
The test_vertex_ai_gpt_oss_simple_request and test_vertex_ai_gpt_oss_reasoning_effort
tests were failing in CI with 401 authentication errors. This was because the
vertexai module import was triggering authentication attempts even though the
_ensure_access_token method was mocked.

Added patch.dict('sys.modules', ...) to mock the vertexai module entirely,
preventing it from trying to authenticate when imported. This ensures tests
are fully isolated and don't attempt real API calls regardless of environment
variables or test execution order.

This follows the same pattern used in other Vertex AI tests and works in
combination with the autouse fixture that clears environment variables.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:44:23 -03:00
Julio Quinteros Pro be63bac1c1 fix(test): use async side_effect for client.post mock in watsonx test
The test_watsonx_gpt_oss_prompt_transformation was using return_value to mock
an async method (AsyncHTTPHandler.post), which doesn't work correctly with
async/await. This could cause intermittent failures in CI due to test ordering.

Changed to use side_effect with an async function (mock_post_func) to properly
mock the async post method, following the same pattern used in other async
tests like test_vertex_ai_gpt_oss_reasoning_effort.

This ensures the mock is always called correctly regardless of test execution
order or parallel test execution.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:39:21 -03:00
jquinter 03215c6495 Merge pull request #21273 from BerriAI/fix/vertex-ai-qwen-test-isolation
fix(test): add environment cleanup for Vertex AI Qwen tests
2026-02-15 19:28:34 -03:00
jquinter ddd71a155a Merge pull request #21272 from BerriAI/fix/vertex-ai-gpt-oss-test-isolation
fix(test): add environment cleanup for Vertex AI GPT-OSS tests
2026-02-15 19:25:49 -03:00
jquinter cdb0b6b9dc Update tests/test_litellm/llms/vertex_ai/vertex_ai_partner_models/gpt_oss/test_vertex_ai_gpt_oss_transformation.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-15 19:25:35 -03:00
Julio Quinteros Pro 62ac8cee8e fix(test): add environment cleanup for Vertex AI Qwen tests
Add autouse pytest fixture to clear Google/Vertex AI environment
variables before each test, preventing authentication errors in CI.

Previous tests may set GOOGLE_APPLICATION_CREDENTIALS or other Vertex
environment variables and not clean them up, causing this test to
attempt real Google authentication instead of using mocks.

This fix:
- Adds clean_vertex_env fixture with autouse=True
- Saves and clears Google/Vertex env vars before each test
- Restores them after each test
- Prevents "AuthenticationError: Request had invalid authentication
  credentials" (401) in CI when run with other tests

Same fix pattern as PR #21268 (rerank) and PR #21272 (GPT-OSS).

Related: test was failing on PR #21217, but NOT caused by PR #21217
(which only modifies test_anthropic_structured_output.py). This is
another test isolation issue.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:19:43 -03:00
jquinter f20dd25b37 Merge pull request #21271 from BerriAI/fix/anthropic-pass-through-reasoning-effort-test
fix(test): update reasoning_effort test to expect dict format
2026-02-15 19:18:21 -03:00
Julio Quinteros Pro cf11867159 fix(test): add environment cleanup for Vertex AI GPT-OSS tests
Add autouse pytest fixture to clear Google/Vertex AI environment
variables before each test, preventing authentication errors in CI.

Previous tests may set GOOGLE_APPLICATION_CREDENTIALS or other Vertex
environment variables and not clean them up, causing this test to
attempt real Google authentication instead of using mocks.

This fix:
- Adds clean_vertex_env fixture with autouse=True
- Saves and clears Google/Vertex env vars before each test
- Restores them after each test
- Prevents "AuthenticationError: Request had invalid authentication
  credentials" in CI when run with other tests

Test makes real API calls in CI without this fix, gets 401 error.
Locally fails with "No module named 'vertexai'" (expected).

Related: test was failing on PR #21217, but NOT caused by PR #21217
(which only modifies test_anthropic_structured_output.py). This is
another test isolation issue.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:16:46 -03:00
Julio Quinteros Pro 7c3020c04a fix(test): update test_other_constraints_preserved for new schema filtering behavior
PR #20813 changed the Anthropic schema filter to remove string and numeric constraints
(minLength/maxLength, minimum/maximum) per Anthropic API requirements, but forgot to
update the corresponding test.

The new behavior (per Anthropic SDK):
1. Remove unsupported constraints from schema (Anthropic API doesn't support them)
2. Add constraint info to description field (e.g., "Note: minimum length: 1")

**Changes:**
- Updated test to expect constraints REMOVED from schema
- Added assertions to verify constraints are added to description
- Updated docstring to explain the new behavior

**Testing:**
-  test_other_constraints_preserved now passes
-  All 4 tests in test_anthropic_structured_output.py pass

**Related:**
- Fixes test broken by PR #20813
- Aligns with Anthropic API requirements documented in commit 84934a7258

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:10:44 -03:00
Julio Quinteros Pro 0812323aaf fix(test): update reasoning_effort test to expect dict format
Update test expectations to match the current code behavior where
reasoning_effort is transformed from a string to a dict with
'effort' and 'summary' fields.

The transformation happens in:
litellm/llms/anthropic/experimental_pass_through/adapters/handler.py:72-74

When reasoning_effort is a string like "minimal", it's converted to:
{"effort": "minimal", "summary": "detailed"}

The test was expecting just the string "minimal", causing it to fail.

Test now passes 

Related: test was failing on PR #21217, but NOT caused by PR #21217
(which only modifies test_anthropic_structured_output.py). This is a
pre-existing broken test that also fails on main branch.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 19:08:18 -03:00
jquinter e162410294 Merge pull request #21268 from BerriAI/fix/vertex-ai-rerank-test-isolation
fix(test): add environment cleanup for Vertex AI rerank tests
2026-02-15 19:03:03 -03:00
Julio Quinteros Pro 28a0c61c51 fix(test): add environment cleanup for Vertex AI rerank tests
Add setup_method and teardown_method to clean up Google/Vertex AI
environment variables that may be left by previous tests.

Previous tests may set GOOGLE_APPLICATION_CREDENTIALS or other Vertex
environment variables and not clean them up, causing this test to
attempt real Google authentication instead of using mocks.

This fix:
- Saves and clears Google/Vertex env vars in setup_method
- Restores them in teardown_method
- Prevents "DefaultCredentialsError" in CI when run with other tests

Test passes in isolation but fails in CI due to test ordering. This
is another test isolation issue, NOT related to PR #21217.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 18:26:51 -03:00
Ephrim Stanley 7d794b567c fix: thread deployment model_info through batch cost calculation
batch_cost_calculator only checked the global cost map, ignoring
deployment-level custom pricing (input_cost_per_token_batches etc.).
Add optional model_info param through the batch cost chain and pass
it from CheckBatchCost.
2026-02-15 14:53:30 -05:00
jquinter 9fb6537607 Merge pull request #21257 from BerriAI/refactor/remove-redundant-cache-flushes
refactor(test): remove redundant cache flush from test_openai_env_base
2026-02-15 14:28:35 -03:00
Julio Quinteros Pro d8dbb7f5ab refactor(test): remove redundant cache flush from test_openai_env_base
The manual cache flush is redundant since the autouse fixture
clear_client_cache (lines 21-32) already flushes the cache before
and after every test in this module.

The manual flush was added in Jan 2026 before the autouse fixture
existed. Now that the fixture handles it, the manual flush is unnecessary.

Related: greptile review comment on PR #21255

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 14:24:38 -03:00
jquinter 0b66bbd904 Merge pull request #21254 from BerriAI/fix/langfuse-test-counter-cleanup
fix(test): restore Langfuse client counter in test cleanup
2026-02-15 14:18:22 -03:00
Julio Quinteros Pro 679a0293bd fix(test): restore Langfuse client counter in test cleanup
Fixes persistent test isolation issue in TestLangfuseUsageDetails by
saving and restoring the global litellm.initialized_langfuse_clients
counter.

Changes:
- Save litellm.initialized_langfuse_clients in setUp
- Restore original value in tearDown
- Prevents counter accumulation across tests

Root Cause:
PR #21248 added logger cleanup but missed the global client counter.
Each test increments litellm.initialized_langfuse_clients when creating
a LangFuseLogger, but the counter was never reset. This caused state
accumulation that could affect test behavior when tests run in certain
orders, leading to "Expected 'generation' to have been called once.
Called 0 times" failures.

Impact:
- test_log_langfuse_v2_handles_null_usage_values was still flaky
- Counter would accumulate: 1, 2, 3... across all tests
- While unlikely to hit MAX (50), accumulated state affected behavior

This completes the test isolation fix started in PR #21248.

Related: #21248
Fixes: Remaining test isolation issues in Langfuse tests

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 14:11:24 -03:00
jquinter 4f751bf815 Merge pull request #21253 from BerriAI/refactor/langfuse-test-cleanup-dead-code
refactor: remove dead code from Langfuse test cleanup
2026-02-15 13:49:14 -03:00
Julio Quinteros Pro 4c53ccd90d refactor: remove dead code from Langfuse test cleanup
Follow-up to PR #21248 addressing greptile code review feedback.

Removes hasattr checks for non-existent attributes that were identified
as dead code by greptile automated code review.

Changes:
- Remove hasattr check for LangFuseLogger._langfuse_clients (class attribute doesn't exist)
- Remove hasattr check for self.logger._langfuse_client_cache (instance attribute doesn't exist)
- Update comments to be more accurate about what cleanup is being done

The core fix from PR #21248 (nulling Langfuse reference and deleting
logger instance) remains unchanged and effective. This just removes
misleading dead code that serves no purpose.

Context:
These checks were added defensively but reference attributes that don't
actually exist on the LangFuseLogger class, making them always no-ops.
Greptile correctly identified these as dead code in PR #21248 review,
but the PR was merged before the cleanup could be applied.

Related: #21248

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:45:23 -03:00
jquinter c362804872 Merge pull request #21250 from BerriAI/fix/test-extra-body-fallback-isolation
fix(test): add cleanup for disable_aiohttp_transport in test_extra_body_with_fallback
2026-02-15 13:41:57 -03:00
jquinter 9a590ce969 Merge pull request #21251 from BerriAI/fix/video-test-http-client-isolation
fix(test): add mock isolation for test_video_content_handler_uses_get_for_openai
2026-02-15 13:41:19 -03:00
jquinter a4deaaa7ac Update tests/test_litellm/test_main.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-15 13:34:32 -03:00
Julio Quinteros Pro 6691694759 fix(test): add mock isolation for test_video_content_handler_uses_get_for_openai
Fixes test isolation issue where test_video_content_handler_uses_get_for_openai
was making real HTTP requests to OpenAI API instead of using the mock client.

Changes:
- Patch _get_httpx_client to ensure it returns the mock client
- Prevents creation of real HTTP client even if isinstance check fails
- Wraps handler call in context manager for proper cleanup

Root Cause:
When run after other tests, the isinstance(mock_client, HTTPHandler) check
in video_content_handler() could fail due to state pollution, causing the
handler to create a real HTTP client via _get_httpx_client(). This resulted in:
- Real API calls to https://api.openai.com/v1/videos/video_abc/content
- 401 errors: "Incorrect API key provided: sk-test"
- Test expecting b'mp4-bytes' but getting actual error response

Impact:
Test passes in isolation but fails when run with other tests, especially
in CI environments with parallel execution.

Fixes: Test isolation for test_video_content_handler_uses_get_for_openai

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:34:19 -03:00
Julio Quinteros Pro a2a3d14443 fix(test): add cleanup for disable_aiohttp_transport in test_extra_body_with_fallback
Fixes test isolation issue where test_extra_body_with_fallback was setting
litellm.disable_aiohttp_transport = True but never resetting it, causing
state pollution that affected other tests.

Changes:
- Save original value of disable_aiohttp_transport before modifying
- Wrap test logic in try/finally block
- Restore original value in finally to ensure cleanup even on failure

Root Cause:
The test was modifying global litellm state without cleanup. When run in
certain orders with other tests:
- If this test ran first, it left disable_aiohttp_transport=True globally
- If other tests ran first, their state could interfere with this test
- Result: "All fallback attempts failed" error in CI

Impact:
Test passes in isolation but fails when run with other tests, especially
in parallel execution or CI environments.

Fixes: Test isolation for test_extra_body_with_fallback

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:31:30 -03:00
jquinter de997b3b27 Merge pull request #21248 from BerriAI/fix/langfuse-test-isolation-improved
fix(test): improve Langfuse test isolation to prevent flaky failures
2026-02-15 13:30:16 -03:00
Julio Quinteros Pro c4fa7e9298 fix(test): improve Langfuse test isolation to prevent flaky failures
Enhances test isolation in TestLangfuseUsageDetails by ensuring the
logger instance is completely fresh for each test and properly cleaned
up afterward.

Changes:
- Clear any class-level cached Langfuse clients before creating logger
- Reset logger's cached client instances in setUp
- Properly clean up logger instance and its state in tearDown

Root Cause:
The test_log_langfuse_v2_handles_null_usage_values test was failing
when run after other tests due to lingering state in the logger instance.
While the test passes in isolation, test ordering issues caused it to
fail with "Expected 'generation' to have been called once. Called 0 times."

This builds on PR #21214 which added sys.modules cleanup, but that wasn't
sufficient to prevent all state leakage between tests.

Fixes: Test isolation issues in test_log_langfuse_v2_handles_null_usage_values

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-15 13:28:12 -03:00
jquinter 068c994d89 Merge pull request #21075 from jquinter/fix/policy-endpoints-import-error
fix: make policy_resolve_endpoints importable without FastAPI
2026-02-15 13:18:21 -03:00
jquinter f555846c83 Merge pull request #21227 from BerriAI/fix/sso-test-premium-check
Fix SSO test flakiness by correctly mocking premium_user
2026-02-15 13:18:08 -03:00