Repository navigation
test(integration): cover model_management endpoint contracts - #44684
Conversation
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>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
bugbot run |
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>
|
bugbot run |
…ion tests Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…cover slash credential names Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…racts_model_management
|
bugbot run |
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>
|
@litereview code-review |
|
bugbot run |
✅ code-review5/5 · Ready for human reviewScope: full · Full PR review. Completed · Some checks not run. No correctness findings. The PR changes only five integration test files under Checks and execution details
View review · Reviewed |
There was a problem hiding this comment.
✅ 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.
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a proxy admin could ship a regression in model or credential management with every integration test still green
After: the same regressions turn the integration suite red before merge
budget_exceededPre-Submission checklist
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 throughGET /access_group/<name>/budgetand the linked budget row, the next call is refused with the exact 422budget_exceededbody while the scripted upstream receives nothing, and afterDELETEthe 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 withdisable_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 untilGET /access_group/<name>/budgetreports exactly the cost of the one served call, so a slow spend write under parallel workers can no longer hand back a stale valueModel secrets on update: a partial legacy
POST /model/updatewith onlyrpm, or only a typedtimeout, keeps every other stored param byte for byte, the api_key stays one layer of ciphertext, and the provider still receives the original request. APATCH /model/<id>/updatewith a canaryapi_keymakes the provider receive the new bearer on the next call, while Postgres, the PATCH response,/model/infoand/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 bodyPartial credential PATCH, once with a plain credential name and once with a name containing
/sent raw in the path: sending onlycredential_values.api_basesends the next model call to the new base with the original bearer, andcredential_values_to_delete: ["organization"]removes that field from the row, from the masked/credentials/by_namereadback and from the provider requestDashboard credential edit: the exact body
CredentialsPanel.tsxhandleUpdateCredentialsends (non-secretapi_baseandorganizationresent, the maskedapi_keystripped,credential_info.custom_llm_providerset) keeps the storedapi_keyciphertext byte for byte, keepscredential_infoin the row and the masked readback, and the next call reaches the new base with the original bearer and organizationBlocked flag: team admins, org admins and internal users are refused on
/model/block,/model/unblockandPATCH {"blocked": ...}with the flag unchanged. An internal user whose key is minted withallowed_routes: ["/model/block", "/model/unblock"]clears the route gate and still gets the handler's exact 403Only proxy admins can change a model's blocked flag.. While blocked, a call gets the exact 403Model is blockedbody and the provider receives nothing; once unblocked the provider receives the exact method, path, bearer and bodyModel creation prohibition:
disable_model_add_for_internal_usersis switched on through the peer proxy andPOST /model/newgoes 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/infoand/v1/models, a proxy admin can still create, and after switching it back off through the peer the team admin can create againCredentials: create, update, delete, list,
by_nameandby_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 inroute_checks.pystays green on both, because credential routes are refused by falling through to the admin-only check rather than by a pattern matchModel rename: renaming a DB model through
PATCH /model/<id>/update {"model_name": new}and through the legacyPOST /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/modelslists 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 toteam_model_access_denied(5 of 5 captures). A proxy-originatedGET /v1/modelson 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. InstrumentingOpenAIGPTConfig._fetch_model_idsand httpx sends across several grouped runs did not reproduce it, so its source is still unknownMutation 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 greentest_access_group_budget.py::test_access_group_budget_refuses_traffic_once_spent_and_serves_again_after_delete[reservation-stream]andtest_reservation_refuses_a_concurrent_call_while_an_in_flight_call_holds_the_group_budgetbudget_reservation.py: delete thecounters.extend(await _get_model_access_group_budget_counters(...))statement (the gap's requested mutation)_assert_servedprovider body list (test_access_group_budget.py:288, reached from:424in 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 writtentest_access_group_budget.py::test_access_group_budget_refuses_traffic_once_spent_and_serves_again_after_delete[*]andtest_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 figuretest_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 ()->()eventually(... value.spend == pytest.approx(_CALL_COST))(:386): the served call was never charged to the group[*-organization]auth_checks.py_org_granted_models:return ()[*-project]auth_checks.py_granted_model_lists:project_object.models if project_object is not None else ()->()test_stored_config_slots.py::test_partial_legacy_model_update_keeps_the_stored_api_key_usable[rpm]and[timeout]update_modelmerge:_existing_litellm_params_dict[key]->encrypt_value_helper(_existing_litellm_params_dict[key])test_stored_config_slots.py::test_patched_model_api_key_rotates_the_provider_bearer_and_is_never_stored_or_echoedupdate_db_model:else encrypt_value_helper(v)->else vfind_canary(patched.text, (original, rotated)) == (), PATCH echoed the plaintext keytest_effective_settings.py::test_partial_credential_patch_merges_values_and_deletes_only_the_named_fieldupdate_db_credential:.credential_values.update(...)->.credential_values = dict(...)[plain-name]and[slash-name][slash-name]credential_endpoints/endpoints.py: PATCH route/credentials/{credential_name:path}->/credentials/{credential_name}_patch_credentialgot 405,[plain-name]stayed greentest_team_admin_gate.py::test_a_key_allowed_the_block_routes_still_cannot_flip_a_models_blocked_flag_set_model_blocked_status: delete theif user_api_key_dict.user_role != LitellmUserRoles.PROXY_ADMIN: raise ...check(status, body) == _PATCH_BLOCKED_REFUSED, the allowed-routes key got 200 and flipped the flagtest_team_admin_gate.py::test_only_proxy_admin_flips_a_models_blocked_flag(4 callers)_types.pyLiteLLMRoutes.internal_user_routes: add"/model/unblock"(status, body)refusal, the callers reached the handler instead of the route gatetest_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:_PATCH_BLOCKED_REFUSED, the team admin's PATCH returned 200test_team_admin_gate.py::test_internal_user_model_creation_prohibition_refuses_team_admin_but_not_proxy_adminadd_new_model: deleteawait sync_ui_settings_to_general_settings(prisma_client, require_fresh=True)add_new_model: replace theraise HTTPException(status_code=403, detail="Model creation is disabled for internal users ...")withpassPOST /model/newreturned 200test_team_admin_gate.py::test_only_proxy_admin_reads_or_changes_credentials(4 callers xplain-name,slash-name)_types.pyLiteLLMRoutes.internal_user_routes: add"/credentials/by_model/{model_id}"_admin_only_route(call.path)(test_team_admin_gate.py:785) forGET /credentials/by_model/<id>, all 8 cells, it returned the credential_types.pyLiteLLMRoutes.internal_user_routes: add"/credentials"(the gap's requested mutation)_admin_only_route(call.path)(:785),POST /credentialsreturned 200test_model_rename_propagation.py::test_renamed_model_is_reachable_by_its_new_name_through_every_allowlist_that_named_it[patch]patch_model: delete theawait sync_model_allowlists_for_renamed_model(...)statementassert served.status_code == 200(test_model_rename_propagation.py:212), the key got 403key_model_access_deniedon the new name,[legacy_post]stayed green[legacy_post]update_model: delete theawait sync_model_allowlists_for_renamed_model(...)statement[patch]stayed greentest_effective_settings.py::test_dashboard_credential_edit_keeps_the_stripped_secret_and_round_trips_credential_infoupdate_db_credential:.credential_values.update(...)->.credential_values = dict(...)api_keywas droppedupdate_db_credential: replacemerged_credential.credential_info.update(...)withpasscredential_inforow 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_refusalpins the expected blocked-flag 403 behindpytest.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_REFUSEDbody is the follow-upRig 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 environmentmanagementselection abovee95f9d08dce95f9d08dcmanagementselection above0ce0d416b1securityselection above0ce0d416b1(file unchanged since)managementselection abovece342bdd84test_team_admin_gate.pyca59f5e302(shares one assertion helper, no behavior change)securityselection abovece342bdd84andca59f5e302|
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) andproxy-infra-root / Run tests(/v1/logscomponent allowlist) jobs fail here and also fail on main at2156d6c3c7, and this PR touches onlytests/integration/make checkpasses at the tipLast updated:
72fa0e35e4(a normal merge oforigin/mainresolving the shared budget-route assertion intest_team_admin_gate.pyto main's_BUDGET_ROUTESform, plus the dashboard credential edit test). The diff has no product code (git diff origin/main...HEAD -- litellm enterpriseis empty), so /qa and /live-pr-risk have no changed behavior to A/B; the proof is the mutation table aboveType
✅ Test
Caveats (if any)
Low
/v1/models, which lists every model for them/credentials/by_model/<id>returns only the deployment's own values, not the bound credential's keyFinal 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/mainonly, the PR diff is still the five test files72fa0e3 adds one tests-only credential test on top of a merge of
origin/main, still no product diff