litellm/tests/test_litellm/proxy
Ishaan Jaff f83620157e
[Feat] Policies - Allow connecting Policies to Tags, Simulating Policies, Viewing how many keys, teams it applies on (#20904)
* init schema with TAGS

* ui: add policy test

* resolvePoliciesCall

* add_policy_sources_to_metadata + headers

* types Policy

* preview Impact

* def _describe_match_reason(

* match based on TAGs

* TestTagBasedAttachments

* test fixes

* add policy_resolve_router

* add_guardrails_from_policy_engine

* TestMatchAttribution

* refactor

* fix

* fix: address Greptile review feedback on policy resolve endpoints

- Track unnamed keys/teams as separate counts instead of inflating
  affected_keys_count with duplicate "(unnamed key)" placeholders.
  Added unnamed_keys_count and unnamed_teams_count to response.
- Push alias pattern matching to DB via _build_alias_where() which
  converts exact patterns to Prisma "in" and suffix wildcards to
  "startsWith" filters.
- Gate sync_policies_from_db/sync_attachments_from_db behind
  force_sync query param (default false) to avoid 2 DB round-trips
  on every /policies/resolve request.
- Remove worktree-only conftest.py that cleared sys.modules at import
  time — no longer needed since code moved to main repo.
- Rename MAX_ESTIMATE_IMPACT_ROWS → MAX_POLICY_ESTIMATE_IMPACT_ROWS.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: eliminate duplicate DB queries and fix header delimiter ambiguity

- Fetch teams table once in estimate_attachment_impact and reuse for
  both tag-based and alias-based lookups (was querying teams twice when
  both tag_patterns and team_patterns were provided).
- Convert tag/team filter functions from async DB queries to sync
  filters that operate on pre-fetched data (_filter_keys_by_tags,
  _filter_teams_by_tags).
- Fix comma ambiguity in x-litellm-policy-sources header: use '; '
  as entry delimiter since matched_via values can contain commas.
- Use '+' as the within-value separator in matched_via reason strings
  (e.g. "tag:healthcare+team:health-team") to avoid conflict with
  header delimiters.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* Update litellm/proxy/policy_engine/policy_resolve_endpoints.py

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
2026-02-10 17:50:37 -08:00
..
_experimental/mcp_server [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
agent_endpoints fix(tests): Add missing mocks for MCP IP filtering and updated APIs (#20652) 2026-02-07 11:30:49 -08:00
anthropic_endpoints [Fix] 404 Not Found on /api/event_logging/batch endpoint (#20504) 2026-02-05 10:58:08 -08:00
auth Merge pull request #20854 from BerriAI/litellm_oss_staging_02_05_2026_3 2026-02-10 17:59:56 +05:30
client add a new feature fix to expose the team alias when authenticating th… (#17725) 2025-12-10 10:10:28 -08:00
common_utils fix: ensure auto-rotation updates existing AWS secret instead of creating new one (#19455) 2026-01-20 18:30:36 -08:00
db Adding logging for when batching fails 2026-02-03 20:54:40 -08:00
discovery_endpoints Fixing tests 2025-12-23 14:10:41 -08:00
experimental/mcp_server Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
google_endpoints fix(proxy): handle agent parameter in /interactions endpoint (#19866) 2026-01-27 09:34:58 -08:00
guardrails guardrails list sensitive values fix 2026-02-09 17:11:54 -08:00
health_endpoints Fix health endpoints 2026-01-31 12:25:04 -08:00
hooks [Feat] Add async_post_call_response_headers_hook to CustomLogger (#20083) 2026-01-30 12:44:44 -08:00
image_endpoints test fix 2025-10-17 10:46:42 -07:00
management_endpoints [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
management_helpers [MCP Gateway] Litellm mcp fixes team control (#15304) 2025-10-07 16:48:00 -07:00
middleware Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
openai_files_endpoint Add litellm metadata correctly for file create 2026-01-29 15:20:31 +05:30
pass_through_endpoints addressing comments 2026-02-10 15:16:18 -08:00
policy_engine [Feat] Policies - Allow connecting Policies to Tags, Simulating Policies, Viewing how many keys, teams it applies on (#20904) 2026-02-10 17:50:37 -08:00
prompts fix(prompts): fix prompt info lookup and delete using correct IDs (#19358) 2026-01-20 12:28:34 -08:00
public_endpoints /public/model_hub health information 2026-01-16 15:36:56 -08:00
response_api_endpoints Fix x-litellm-key-spend update 2025-12-12 11:44:51 +05:30
spend_tracking [Release - 02/10/2026] v1.81.10-nightly 2026-02-10 16:26:30 -08:00
test_configs Litellm fix GitHub action testing (#11163) 2025-05-26 14:41:42 -07:00
ui_crud_endpoints feat: support role_mappings from environment variables (#19498) 2026-01-23 19:54:23 -08:00
vector_store_endpoints test_delete_vector_store_checks_access 2026-01-31 12:05:09 -08:00
__init__.py test fix 2025-10-17 10:46:42 -07:00
conftest.py Add health endpoint tests to CI with database and Redis support (#17877) 2025-12-12 07:35:50 -08:00
test_batch_metadata_none_fix.py Fix issue #13995: Handle None metadata in batch requests (#13996) 2025-08-27 14:51:09 -07:00
test_caching_routes.py [Bug Fix] Ensure /redis/info works on GCP Redis (#11732) 2025-06-14 15:35:09 -07:00
test_chat_completion_metadata.py fix: propagate JWT auth metadata to OTEL spans (#19627) 2026-01-23 21:21:23 -08:00
test_common_request_processing.py use cached keys and teams for router settings 2026-02-06 15:07:29 -08:00
test_custom_proxy.py fix(ui/): fix routing for custom server root path (#15701) 2025-10-23 13:59:29 -07:00
test_empty_model_list.py Fixing tests and linting 2026-01-21 11:02:39 -08:00
test_enforce_user_param.py Enforce support of enforce_user_param to openai post endpoints 2025-12-03 12:19:21 +05:30
test_fallback_management_endpoints.py Add fallback endpoints support 2026-01-16 10:51:33 +05:30
test_fastapi_offline_routes.py [Bug Fix] - Get Routes (#13466) 2025-08-09 12:52:23 -07:00
test_health_check_functions.py Add background health checks to db 2025-12-05 14:27:37 +05:30
test_litellm_pre_call_utils.py [Feat] UI + Backend - Allow adding policies on Keys/Teams + Viewing on Info panels (#19688) 2026-01-23 19:03:44 -08:00
test_model_id_header_propagation.py (fix) propagate x-litellm-model-id in responses (#16986) 2025-11-24 20:40:43 -08:00
test_proxy_cli.py test_get_default_unvicorn_init_args 2026-01-24 12:59:51 -08:00
test_proxy_server.py Revert "Merge pull request #18790 from BerriAI/litellm_key_team_routing_3" 2026-01-31 17:58:46 -08:00
test_proxy_types.py Litellm dev 06 06 2025 p1 (#11496) 2025-06-07 09:12:16 -07:00
test_proxy_utils.py Fix date overflow/division by zero in proxy utils (#19527) 2026-01-21 21:09:57 -08:00
test_response_model_sanitization.py fix(proxy): prevent provider-prefixed model leaks (#19943) 2026-01-28 22:26:38 -08:00
test_route_a2a_models.py Fix test_route_a2a_model_bypasses_router 2026-02-05 09:47:05 +05:30
test_route_llm_request.py Override router settings 2026-01-31 16:04:52 -08:00
test_shared_health_check.py Add shared healthcheck 2025-10-09 22:18:05 +05:30
test_spend_log_cleanup.py feat(proxy): cleanup spend logs cron verification, fix, and docs (#19085) 2026-01-14 22:14:48 +05:30
test_swagger_chat_completions.py Fix Swagger UI path with server_root_path in OpenAPI schema (#18947) 2026-01-14 03:48:43 +05:30
test_team_member_update.py fix mapped tests (#12320) 2025-07-04 10:04:43 -07:00