litellm/tests/code_coverage_tests
zoveki bc4ca0b218
fix(guardrails): check one-object parts and tool turns on generateContent (#54359)
* fix(google_genai): scan one-object parts in guardrails and skip null-text system parts that carry only metadata

* fix(google_endpoints): keep countTokens fail-closed on unknown Part fields and accept metadata-only system parts

* fix(google_genai): scan string parts, every system instruction, and tool turns in guardrails

The generateContent guardrail now scans plain-string parts, both system
instruction spellings at the top level and inside config, every string in a
functionResponse.response (skipped when the guardrail skips tool messages), and
functionCall args passed as chat-shaped tool_calls. Masked text is written back
in place so the provider gets the caller's wire shape. A functionResponse nested
past DEFAULT_MAX_RECURSE_DEPTH is blocked with a 400 instead of going out unscanned

The countTokens test now covers all eight metadata spellings

* fix(google_genai): scan tool results and code parts as one JSON text, and give each tool call its own id

Scanning each string of a functionResponse on its own fanned one tool result
out into hundreds of guardrail texts, needed a depth cap that turned a clean
deep result into a 400, and missed keys and numbers. Each structured value is
now one JSON text, the way chat scans a tool message, and a change is decoded
back into the part. executableCode, codeExecutionResult, toolCall and
toolResponse parts are scanned too. Function calls reach guardrails under the
call's own id, and their args are written back only when every call comes back

* fix(guardrails): scan generateContent tool results with real line starts and maskable numbers

Tool results keep raw control characters in their scan text so line-start
patterns match, numbers are scanned as strings so a mask replaces them, and a
guardrail that turns functionCall args into a non-object blocks the request

* fix(guardrails): scan generateContent functionCall args as JSON text and check tool calls in model replies

* fix(google_endpoints): keep metadata-only countTokens system parts answering 400, as Gemini does

* fix(guardrails): check tool calls in streamed genai replies and reject unwritable rewrites as unappliable

A post_call guardrail now sees functionCall args in streamGenerateContent chunks, and a rewrite that no longer reads back as JSON raises UnappliableRequestRewrite so a policy pipeline blocks instead of falling through

* fix(guardrails): match chat's scope flags and count checks on generateContent

scan_only_tool_results and skip_system_message_in_guardrail now narrow what a generateContent guardrail sees, as on chat. A request rewrite that changes the text or tool call count, or touches a string in a tuple, is rejected as unappliable instead of sent unmasked. A reply whose tool calls come back in a different count keeps the model's calls, as on chat. Masked numbers in a tool result keep their type when the guardrail reorders fields

* fix(guardrails): keep generateContent tool calls and reply texts the way chat does

A request guardrail that returns a different tool call count, such as an
empty list, now keeps the original calls, as chat does. Reply texts are
written back by index, so a guardrail that answers one text for a reply
with several parts still replaces the first one, as on chat and
/v1/messages. Stream text gets a line break between parts that are not
both text, so two parts cannot spell a blocked word together. Numbers
nested past the scan depth cap keep their type when another value is
masked. The module docstring now states only the rules.

* fix(google-genai): write guardrail tool calls back by position with their names, and keep list numbers typed

A guardrail that returns fewer tool calls now has them applied by position, as on chat,
so a mask on a kept call is no longer lost. A renamed call goes out under its new name,
and numbers in a tool result list a guardrail shortens keep their type.

* fix(google-genai): match kept tool result list items in order so numeric strings stay strings

A guardrail that drops a list item no longer looks originals up by their scan text,
where "1" and 1 share one key. Kept items are matched in order against the
originals instead, so each keeps its own type

* fix(google-genai): reject tool call count changes and keep chat scope flags from narrowing text

A guardrail that drops some but not all tool calls now answers the unappliable error instead of writing calls back by position, on requests and replies. skip_system_message_in_guardrail and scan_only_tool_results no longer skip system or user text, matching chat. List items keep their original values when a mask leaves them unchanged, aligned by content and then by shape

* fix(guardrails): keep streamed text whole around code parts, write a one-text reply verdict to the first text, bound list alignment

* fix(guardrails): keep the last text a reply guardrail sees on the reply's text, so last-text guardrails scan the answer

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 12:32:47 +00:00
..
azure_client_usage_test.py
ban_constant_numbers.py
ban_copy_deepcopy_kwargs.py
bedrock_pricing.py Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_ruff_dead_test_code 2026-08-24 09:46:56 -07:00
callback_manager_test.py
check_data_replace_usage.py
check_e2e_no_raw_requests.py test(e2e): share the coding-CLI harness between suites (#49370) 2026-11-02 13:50:56 -08:00
check_endpoint_coverage.py
check_fastuuid_usage.py
check_get_model_cost_key_performance.py refactor(model-cost): move the cost map inputs, fetch and register_model overlay into Rust (#50501) 2026-11-10 02:37:35 +00:00
check_guardrail_apply_decorator.py
check_licenses.py chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
check_migrations_lock_timeout.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
check_migrations_no_data_rewrites.py fix(proxy-extras): build the remaining request-log indexes in the migration job instead of in migrations (#49667) 2026-11-23 10:15:35 -08:00
check_no_none_string_error_fields.py fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes (#39540) 2026-10-29 18:20:52 -07:00
check_no_publicly_known_master_key.py fix(ui): rebuild the dashboard bundle and cover it in the example master key check (#47612) 2026-10-20 13:02:29 -07:00
check_prisma_binary_cache.py
check_provider_folders_documented.py feat(harness): add pi harness for litellm.agent() (#45467) 2026-10-20 09:01:40 +00:00
check_py310_typing_imports.py fix: keep litellm importable on Python 3.10 and guard 3.11-only typing imports in CI (#39448) 2026-09-02 18:27:19 -07:00
check_router_constructor_stub.py fix(router): make the constructor stub work for mypy and guard it in CI (#50354) 2026-11-22 21:25:00 +00:00
check_spanattributes_value_usage.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
check_telemetry_imports.py feat(telemetry): add litellm.telemetry records, semantic group consent and sink protocol (#45484) 2026-10-13 18:19:22 -07:00
check_unbounded_in_lists.py ci: fail on new unbounded SQL IN lists and add a Prisma chunking helper (#42629) 2026-09-26 13:40:44 -07:00
check_unsafe_enterprise_import.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
check_workflow_job_name_collisions.py fix(ci): keep an expression matrix directive out of the comparison 2026-09-06 02:59:16 -07:00
check_workflow_startup_safety.py ci: render lint, unit and smoke checks as <tier> / <job> with one collector per tier (#45480) 2026-10-09 04:28:41 +00:00
code_qa_check_tests.py test: migrate legacy unit dirs and unrun folders into tests/unit, tests/integration and tests/e2e (#45940) 2026-10-11 06:24:57 -07:00
dependency_license_cache.json chore: move config and docs off the repo root (#50966) 2026-11-11 18:29:35 -08:00
enforce_llms_folder_style.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
ensure_async_clients_test.py feat(proxy): send gateway model calls to Lens as traces when the Lens store is connected (#53042) 2026-11-20 10:12:08 -08:00
info_log_check.py
liccheck.ini feat(gnani): add Prisma v2.5 and v3.0 realtime transcription (#53828) 2026-11-25 10:51:59 +00:00
license_cache.json
litellm_logging_code_coverage.py
log.txt
memory_test.py
prevent_key_leaks_in_exceptions.py
recursive_detector.py fix(guardrails): check one-object parts and tool turns on generateContent (#54359) 2026-11-25 12:32:47 +00:00
router_code_coverage.py fix(openrouter): report the context window and output cap from OpenRouter's catalog (#54046) 2026-11-24 04:37:30 -08:00
router_enforce_line_length.py
router_litellm_globals_check.py refactor(router): delete the python router core, the rust core is the only core (#50178) 2026-11-05 10:40:46 -08:00
router_surface_allowlist.json fix(proxy): reserve least-busy picks on Vertex pass-through calls (#53588) 2026-11-23 04:21:20 +00:00
router_surface_check.py chore: move workspace packages under litellm (#51000) 2026-11-12 04:19:57 +00:00
test_aio_http_image_conversion.py
test_ban_set_verbose.py
test_chat_completion_imports.py
test_check_no_none_string_error_fields.py fix(proxy)!: stop answering with the literal string "None" as error type and param on the proxy-server, auth, spend, and key health routes (#39540) 2026-10-29 18:20:52 -07:00
test_check_no_publicly_known_master_key.py chore: move ui and vscode-extension under litellm and delete docs (#50992) 2026-11-12 04:19:57 +00:00
test_e2e_idp_stack.py test(e2e): verify IdP readiness through real HTTP 2026-09-11 17:25:38 -07:00
test_e2e_junit_report.py test(mcp): replace the live Linear MCP OAuth e2e tests with integration coverage (#47154) 2026-10-17 14:29:59 -07:00
test_e2e_metadata.py ci: render lint, unit and smoke checks as <tier> / <job> with one collector per tier (#45480) 2026-10-09 04:28:41 +00:00
test_generate_provider_endpoints_support.py chore: move scripts and runtime sources under litellm (#51006) 2026-11-12 04:19:57 +00:00
test_merge_smoke.py ci: render lint, unit and smoke checks as <tier> / <job> with one collector per tier (#45480) 2026-10-09 04:28:41 +00:00
test_no_hardcoded_secrets.py test: run the 30 test files stranded in the second mirror (#37595) 2026-08-20 10:59:43 -07:00
test_provider_cache.py fix(e2e): restore main qualification across providers and UI (#49763) 2026-11-03 20:38:47 +00:00
test_provider_replay_harness.py test(e2e): move the harness self-tests out of tests/e2e (#45172) 2026-10-07 22:20:02 +00:00
test_proxy_types_import.py refactor(logging): load enterprise alerting loggers lazily so import litellm skips proxy types (#44762) 2026-10-05 22:06:53 -07:00
test_router_strategy_async.py test: drop the cwd-relative sys.path.insert calls from the test suite (#37802) 2026-08-22 09:25:58 -07:00
test_run_parallel_checks.py ci(lint): run the fast lint checks on pull requests again without compiling Rust (#53421) 2026-11-21 14:17:30 -08:00
test_scan_bundled_crypto.py feat(docker): install cryptography, grpcio and libpq from chainguard apks in the fips image (#52997) 2026-11-20 15:58:28 -08:00
test_unit_passed_gate.py ci: run a core set of unit, lint and smoke jobs on pull requests and the rest on main (#52582) 2026-11-18 10:34:07 -08:00
test_workflow_job_name_collisions.py fix(ci): keep an expression matrix directive out of the comparison 2026-09-06 02:59:16 -07:00
unbounded_in_baseline.txt fix(proxy): preserve concurrent access group assignments (#53840) 2026-11-23 16:27:41 -08:00