Skip to content

test(integration): cover model_management endpoint contracts - #44684

Merged
mateo-berri merged 11 commits into
mainfrom
litellm_endpoint_contracts_model_management
Oct 14, 2026
Merged

mateo-berri merged 11 commits into
mainfrom
litellm_endpoint_contracts_model_management

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Model and credential management routes had no wire or database contract tests
  • Budgets, key rotation, credential merges and non-admin refusals were unpinned

How it solves it:

  • Adds integration tests driving the real proxy over HTTP
  • Asserts the scripted upstream request, readback routes and Postgres rows
  • Each test was proven red under a one-line product mutation

User Flow

Before: a proxy admin could ship a regression in model or credential management with every integration test still green

  1. An admin sets a budget with PUT https://litellm-domain/access_group//budget and keys keep spending past it, unnoticed by tests
  2. An admin sends a partial POST https://litellm-domain/model/update or PATCH https://litellm-domain/credentials/, and a garbled or dropped provider key is not caught
  3. A team admin or internal user hits POST https://litellm-domain/model/unblock or POST https://litellm-domain/credentials, and a widened route allowlist is not caught

After: the same regressions turn the integration suite red before merge

  1. The budget test fails when the next call over budget reaches the provider instead of getting a 422 budget_exceeded
  2. The secret tests fail when the provider sees anything but the expected bearer or Postgres holds anything but one layer of ciphertext
  3. The authorization tests fail when a non-admin gets anything but today's exact refusal body, or when the stored row changes

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Tests only, no product change. The behaviors now covered, in plain words

Access group budgets: a key granted a budgeted access group through its own models, its team, its organization or its project allowlist spends real chat traffic against PUT /access_group/<name>/budget {"max_budget":0.0001,"budget_duration":"30d"}, the budget reads back through GET /access_group/<name>/budget and the linked budget row, the next call is refused with the exact 422 budget_exceeded body while the scripted upstream receives nothing, and after DELETE the same key is served again. Every step runs once as plain JSON and once with "stream": true, "stream_options": {"include_usage": true}, where the client's SSE frames, the final usage chunk and [DONE] are parsed and the exact streamed body the provider got is asserted. Both spellings run with default reservation and with disable_budget_reservation, and with reservation on the streamed first call is held in flight so a concurrent streamed call is refused before any spend is written. The spend readback waits until GET /access_group/<name>/budget reports exactly the cost of the one served call, so a slow spend write under parallel workers can no longer hand back a stale value

Model secrets on update: a partial legacy POST /model/update with only rpm, or only a typed timeout, keeps every other stored param byte for byte, the api_key stays one layer of ciphertext, and the provider still receives the original request. A PATCH /model/<id>/update with a canary api_key makes the provider receive the new bearer on the next call, while Postgres, the PATCH response, /model/info and /credentials/by_model/<id> never contain the canary. In both, the provider double's single request is asserted whole: POST /v1/chat/completions, the bearer and the full JSON body

Partial credential PATCH, once with a plain credential name and once with a name containing / sent raw in the path: sending only credential_values.api_base sends the next model call to the new base with the original bearer, and credential_values_to_delete: ["organization"] removes that field from the row, from the masked /credentials/by_name readback and from the provider request

Dashboard credential edit: the exact body CredentialsPanel.tsx handleUpdateCredential sends (non-secret api_base and organization resent, the masked api_key stripped, credential_info.custom_llm_provider set) keeps the stored api_key ciphertext byte for byte, keeps credential_info in the row and the masked readback, and the next call reaches the new base with the original bearer and organization

Blocked flag: team admins, org admins and internal users are refused on /model/block, /model/unblock and PATCH {"blocked": ...} with the flag unchanged. An internal user whose key is minted with allowed_routes: ["/model/block", "/model/unblock"] clears the route gate and still gets the handler's exact 403 Only proxy admins can change a model's blocked flag.. While blocked, a call gets the exact 403 Model is blocked body and the provider receives nothing; once unblocked the provider receives the exact method, path, bearer and body

Model creation prohibition: disable_model_add_for_internal_users is switched on through the peer proxy and POST /model/new goes to the main proxy, so the cross-pod fresh read is what is tested. A team admin gets the exact 403, no row is written, the name is absent from /model/info and /v1/models, a proxy admin can still create, and after switching it back off through the peer the team admin can create again

Credentials: create, update, delete, list, by_name and by_model/<id> (for a model bound to the shared credential, after a proxy admin read of the same route succeeds) are refused for all four non-admin callers with the row unchanged and no value echoed. Every cell runs once with a plain credential name and once with a name containing / sent raw in the /credentials/{credential_name:path} routes, so a path alias that slips past the admin-only gate is caught. Broadening the generic route placeholder regex in route_checks.py stays green on both, because credential routes are refused by falling through to the admin-only check rather than by a pattern match

Model rename: renaming a DB model through PATCH /model/<id>/update {"model_name": new} and through the legacy POST /model/update {"model_name": new, "model_info": {"id": id}, "litellm_params": {}} rewrites the allowlist of every key, team, org, project, user and access group that named it, each restricted caller can call the new name, gets the exact 403 model access refusal on the old one, and /v1/models lists the new name. The model points at an owned upstream, so every served call's exact method, path, bearer and body is asserted, and the old-name refusals reach no upstream. The access-group caller's refusal is pinned to team_model_access_denied (5 of 5 captures). A proxy-originated GET /v1/models on the test's upstream is answered with an empty list and left out of the exact provider request list, the same way the budget and blocked-flag tests already treat it. Instrumenting OpenAIGPTConfig._fetch_model_ids and httpx sends across several grouped runs did not reproduce it, so its source is still unknown

Mutation proof

Every mutation was applied alone under litellm/, the proxy and peer restarted, the test run red at the listed assertion, then reverted and run green

Gap Test node id Mutation Assertion tripped
model_management-1 test_access_group_budget.py::test_access_group_budget_refuses_traffic_once_spent_and_serves_again_after_delete[reservation-stream] and test_reservation_refuses_a_concurrent_call_while_an_in_flight_call_holds_the_group_budget budget_reservation.py: delete the counters.extend(await _get_model_access_group_budget_counters(...)) statement (the gap's requested mutation) _assert_served provider body list (test_access_group_budget.py:288, reached from :424 in the concurrent test): the concurrent call reached the provider. The other 9 budget nodes stay green under it, because the auth-time check still refuses once spend is written
model_management-1 test_access_group_budget.py::test_access_group_budget_refuses_traffic_once_spent_and_serves_again_after_delete[*] and test_access_group_budget_refuses_a_key_granted_the_group_through_its_scope[*] (all 11 budget nodes) auth_checks.py _model_access_group_max_budget_check: if group_spend < budget.max_budget: -> if True: _assert_refused_for_budget (:293-:294): no-reservation cells were served 200, reservation cells refused with a different spend figure
model_management-1 test_access_group_budget.py::test_access_group_budget_refuses_a_key_granted_the_group_through_its_scope[reservation-team] and [no-reservation-team] auth_checks.py _granted_model_lists: team_object.models if team_object is not None else () -> () spend readback eventually(... value.spend == pytest.approx(_CALL_COST)) (:386): the served call was never charged to the group
model_management-1 same, [*-organization] auth_checks.py _org_granted_models: return () same assertion
model_management-1 same, [*-project] auth_checks.py _granted_model_lists: project_object.models if project_object is not None else () -> () same assertion
model_management-2 test_stored_config_slots.py::test_partial_legacy_model_update_keeps_the_stored_api_key_usable[rpm] and [timeout] update_model merge: _existing_litellm_params_dict[key] -> encrypt_value_helper(_existing_litellm_params_dict[key]) stored row equality with the sent partial field, both cells
model_management-3 test_stored_config_slots.py::test_patched_model_api_key_rotates_the_provider_bearer_and_is_never_stored_or_echoed update_db_model: else encrypt_value_helper(v) -> else v find_canary(patched.text, (original, rotated)) == (), PATCH echoed the plaintext key
model_management-4 test_effective_settings.py::test_partial_credential_patch_merges_values_and_deletes_only_the_named_field update_db_credential: .credential_values.update(...) -> .credential_values = dict(...) whole credential keys assertion, both [plain-name] and [slash-name]
model_management-4 same, [slash-name] credential_endpoints/endpoints.py: PATCH route /credentials/{credential_name:path} -> /credentials/{credential_name} _patch_credential got 405, [plain-name] stayed green
model_management-5 test_team_admin_gate.py::test_a_key_allowed_the_block_routes_still_cannot_flip_a_models_blocked_flag _set_model_blocked_status: delete the if user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: raise ... check exact (status, body) == _PATCH_BLOCKED_REFUSED, the allowed-routes key got 200 and flipped the flag
model_management-5 test_team_admin_gate.py::test_only_proxy_admin_flips_a_models_blocked_flag (4 callers) _types.py LiteLLMRoutes.internal_user_routes: add "/model/unblock" exact (status, body) refusal, the callers reached the handler instead of the route gate
model_management-5 test_team_admin_gate.py::test_only_proxy_admin_flips_a_models_blocked_flag[team_admin] patch_model: if patch_data.blocked is not None and user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: -> if False: exact _PATCH_BLOCKED_REFUSED, the team admin's PATCH returned 200
model_management-6 test_team_admin_gate.py::test_internal_user_model_creation_prohibition_refuses_team_admin_but_not_proxy_admin add_new_model: delete await sync_ui_settings_to_general_settings(prisma_client, require_fresh=True) exact 403 body, the main proxy never saw the peer's toggle and returned 200
model_management-6 same add_new_model: replace the raise HTTPException(status_code=403, detail="Model creation is disabled for internal users ...") with pass exact 403 body, POST /model/new returned 200
model_management-7 test_team_admin_gate.py::test_only_proxy_admin_reads_or_changes_credentials (4 callers x plain-name, slash-name) _types.py LiteLLMRoutes.internal_user_routes: add "/credentials/by_model/{model_id}" _admin_only_route(call.path) (test_team_admin_gate.py:785) for GET /credentials/by_model/<id>, all 8 cells, it returned the credential
model_management-7 same, all 8 cells _types.py LiteLLMRoutes.internal_user_routes: add "/credentials" (the gap's requested mutation) _admin_only_route(call.path) (:785), POST /credentials returned 200
model_management-8 test_model_rename_propagation.py::test_renamed_model_is_reachable_by_its_new_name_through_every_allowlist_that_named_it[patch] patch_model: delete the await sync_model_allowlists_for_renamed_model(...) statement assert served.status_code == 200 (test_model_rename_propagation.py:212), the key got 403 key_model_access_denied on the new name, [legacy_post] stayed green
model_management-8 same, [legacy_post] update_model: delete the await sync_model_allowlists_for_renamed_model(...) statement same assertion, [patch] stayed green
model_management-4 test_effective_settings.py::test_dashboard_credential_edit_keeps_the_stripped_secret_and_round_trips_credential_info update_db_credential: .credential_values.update(...) -> .credential_values = dict(...) stored credential keys, api_key was dropped
model_management-4 same update_db_credential: replace merged_credential.credential_info.update(...) with pass credential_info row read, the row came back {}

Product bug found

PATCH /model/<id>/update {"blocked": true} on a plain team model, sent by a team member, an outsider or an org admin, returns 403 {"detail": "This team does not allow you to manage your own auto routers."}. The request is refused, but by the member auto-router gate, which names a feature the request has nothing to do with, instead of the role-only blocked-flag check. test_non_team_admin_patching_the_blocked_flag_gets_the_blocked_flag_refusal pins the expected blocked-flag 403 behind pytest.skip("BUG: ..."). With the skip removed it fails on all three callers with the auto-router body. Tracked in #44792, linked from the skip. The main blocked-flag test asserts only 403 and the unchanged row for those callers, so it does not freeze that message. Once #44792 is fixed, removing the skip and making that branch assert the exact _PATCH_BLOCKED_REFUSED body is the follow-up

Rig and runs

Rig as in .circleci/scripts/run_integration.sh: Postgres, Redis, the owned upstream, the proxy on 127.0.0.1:4000 and the peer on 4001, no provider credentials in the environment

uv run --no-sync python tests/integration/run.py management tests/integration/authorization/test_access_group_budget.py tests/integration/authorization/test_team_admin_gate.py tests/integration/configuration/test_effective_settings.py tests/integration/management/test_model_rename_propagation.py
uv run --no-sync python tests/integration/run.py security tests/integration/security/test_stored_config_slots.py
Selection Commit Run 1 Run 2
management selection above e95f9d08dc 345 passed, 3 skipped in 110.62s 345 passed, 3 skipped in 91.99s
scope and rename tests together, 3 more runs e95f9d08dc 8 passed in 46.32s, 50.86s, 33.80s
management selection above 0ce0d416b1 341 passed, 3 skipped 341 passed, 3 skipped
security selection above 0ce0d416b1 (file unchanged since) 21 passed 21 passed
management selection above ce342bdd84 334 passed, 3 skipped in 104.47s 334 passed, 3 skipped in 104.12s
test_team_admin_gate.py ca59f5e302 (shares one assertion helper, no behavior change) 323 passed, 3 skipped
security selection above ce342bdd84 and ca59f5e302 20 passed in 751.19s 20 passed in 771.26s

| test_effective_settings.py | 72fa0e35e4 | 6 passed in 38.21s | |

The 3 skips are the documented BUG test above

CI: the non-required misc / Run tests (tracing fixture replays) and proxy-infra-root / Run tests (/v1/logs component allowlist) jobs fail here and also fail on main at 2156d6c3c7, and this PR touches only tests/integration/

make check passes at the tip

Last updated: 72fa0e35e4 (a normal merge of origin/main resolving the shared budget-route assertion in test_team_admin_gate.py to main's _BUDGET_ROUTES form, plus the dashboard credential edit test). The diff has no product code (git diff origin/main...HEAD -- litellm enterprise is empty), so /qa and /live-pr-risk have no changed behavior to A/B; the proof is the mutation table above

Type

✅ Test

Caveats (if any)

Low

  • With reservation on, the over-budget refusal has two independent enforcers
    • Removing either alone still refuses, so the reserved cases trip on the exact body or the concurrent call
  • Project and user allowlists gate calls but not /v1/models, which lists every model for them
    • The rename test asserts the new name is listed and the old one is not, for those two
  • /credentials/by_model/<id> returns only the deployment's own values, not the bound credential's key
    • So the non-admin refusal is what the test pins there, the no-echo check is a backstop

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

  • ca59f5e passes /live-pr-risk

  • 0ce0d41 passes /live-pr-risk (tests-only commit, carried over from ca59f5e under the no-product-diff rule)

  • e95f9d0 passes /live-pr-risk (tests-only commit, the changed-symbol graph is empty, carried over under the no-product-diff rule)

  • 8e4aabb is a merge of origin/main only, the PR diff is still the five test files

  • 72fa0e3 adds one tests-only credential test on top of a merge of origin/main, still no product diff

mateo-berri and others added 2 commits October 5, 2026 22:02
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@greptile-apps

greptile-apps Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Low risk] Integration tests for model management endpoints.

The PR appears safe to merge; no outstanding finding or actionable new issue was identified.

Summary

The PR adds HTTP integration tests for model and credential management contracts, with assertions against provider requests, API responses, and stored rows.

  • Covers access-group budgets, model rename and blocked-state authorization.
  • Covers credential updates and access controls, plus model-key preservation and rotation.

Reviews (8) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..."

@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

mateo-berri and others added 2 commits October 6, 2026 02:09
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

…ion tests

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…cover slash credential names

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

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.

Stale Bugbot comment from a previous run.

@mateo-berri mateo-berri added run-ci and removed run-ci labels Oct 6, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri removed the run-ci label Oct 6, 2026
mateo-berri and others added 2 commits October 14, 2026 03:12
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

# Conflicts:
#	tests/integration/authorization/test_team_admin_gate.py
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@litereview

litereview Bot commented Oct 14, 2026

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings. The PR changes only five integration test files under tests/integration/ and no product code, so the translation evidence gate does not apply.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The diff touches only tests/integration/authorization/test_access_group_budget.py, tests/integration/authorization/test_team_admin_gate.py, tests/integration/configuration/test_effective_settings.py, tests/integration/management/test_model_rename_propagation.py and tests/integration/security/test_stored_config_slots.py. None of these files sit under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**.
  • Passed · Syntax compile of changed test files (optional): python3 -m py_compile succeeded on all five changed files.
  • Passed · Ruff on changed files (optional): ruff 0.17.0 reported import-order I001 warnings in test_model_rename_propagation.py and test_stored_config_slots.py, plus a RUF100 unused noqa warning. ruff.toml sets lint.exclude = [..., "tests/*"], so repository lint does not enforce these rules on these files. They are not findings.
  • Passed · Helper and cleanup tracing (optional): Checked these helpers against tests/integration/_support/client.py, wire.py and process.py: Scenario.key, team, project, organization, model and delete_budget, wire_server/Reply.chunks, and owned_proxy(config=...). In _budgeted_group, the LIFO cleanup deletes the access-group budget row before the LiteLLM_BudgetTable row. This matches _delete_model_access_group_budget_row, which leaves the LiteLLM_BudgetTable row in place. The new tests follow tests/integration/AGENTS.md: they poll with eventually, assert the upstream body in the handler, and use pytest.skip("BUG: ...") for the known [Bug]: PATCH /model/{id}/update with only the blocked flag returns the auto-router refusal for non-admin team members #44792 bug.
  • Not run · Run the integration selections (optional): These suites need Postgres, Redis, the owned upstream and the proxy plus its peer, as set up in .circleci/scripts/run_integration.sh. I did not start that stack. The PR description reports run.py management and run.py security passing at earlier commits, and test_effective_settings.py passing at 72fa0e35e4. I did not verify those results myself.

View review · Reviewed 72fa0e35e447

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 72fa0e3. Configure here.

@mateo-berri mateo-berri left a comment

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.

LGTM

@mateo-berri
mateo-berri merged commit 013c440 into main Oct 14, 2026
92 of 96 checks passed
@mateo-berri
mateo-berri deleted the litellm_endpoint_contracts_model_management branch October 14, 2026 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant