Skip to content

test(e2e): fill management P0 coverage gaps and reconcile registry markers - #32409

Closed
mubashir1osmani wants to merge 1 commit into
mainfrom
litellm_e2e_coverage_integration
Closed

mubashir1osmani wants to merge 1 commit into
mainfrom
litellm_e2e_coverage_integration

Conversation

@mubashir1osmani

Copy link
Copy Markdown
Contributor

Relevant issues

Linear ticket

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

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

Captured against a live proxy on localhost:4000 at commit bfc485b21b, hitting the real control plane with no mocks. Each behavior below is exactly what the corresponding new test asserts

1) mgmt.budget.new.persists - create a budget, then read it back through a separate route (/budget/info) to prove it survived the DB roundtrip with a computed reset window

$ curl -sX POST localhost:4000/budget/new -d '{"budget_id":"e2e-proof-budget-6ba59bdd","max_budget":42.5,"soft_budget":21.25,"budget_duration":"30d"}'
{"budget_id": "e2e-proof-budget-6ba59bdd", "max_budget": 42.5, "soft_budget": 21.25, "budget_duration": "30d", "budget_reset_at": "2026-08-01T00:00:00Z"}

$ curl -sX POST localhost:4000/budget/info -d '{"budgets":["e2e-proof-budget-6ba59bdd"]}'
{"budget_id": "e2e-proof-budget-6ba59bdd", "max_budget": 42.5, "soft_budget": 21.25, "budget_duration": "30d", "budget_reset_at": "2026-08-01T00:00:00Z"}

2) mgmt.budget.new.admin_only and mgmt.team.new.admin_only - a key bound to a non-admin internal_user is refused 401 on the proxy-admin-only writes

POST /budget/new -> Authentication Error, Only proxy admin can be used to generate, delete, update info for ... [HTTP 401]
POST /team/new   -> Authentication Error, Only proxy admin can be used to generate, delete, update info for ... [HTTP 401]

3) mgmt.team.member_add.member_forbidden and mgmt.team.member_delete.member_forbidden - a plain team member (role user, not team admin) is refused 403 on the member writes

POST /team/member_add    -> Call not allowed. User not proxy admin OR team admin. route=/team/member_add ...    [HTTP 403]
POST /team/member_delete -> Call not allowed. User not proxy admin OR team admin. route=/team/member_delete ... [HTTP 403]

The full management suite (12 tests) runs green against this same proxy

Type

✅ Test

Changes

The e2e coverage registry that landed in #32304 enumerates the Management/UI behaviors we want covered, but only 4 of its 19 P0 cells had a covering test. This fills the gap for the key/team/user/budget routes and leaves the model-management cells to the model-management fold branch

New tests in tests/e2e/management/: budget-create persistence read back through /budget/info (asserting max, soft, duration, and a computed budget_reset_at all survive), proxy-admin-only enforcement on /budget/new and /team/new, and team-admin-required enforcement on /team/member_add and /team/member_delete. The two authz families assert different real contracts, so they are modelled separately: admin_only is the role check that answers 401 "Only proxy admin can be used ...", while member_forbidden is the team-admin check that answers 403 "not proxy admin OR team admin". Every authz test also reads back the resource afterwards and asserts the write did not land, so removing the check fails the test rather than passing on the status code alone

I also reconciled the covers markers already on the suite to real registry ids so the collector counts them instead of flagging them as orphans: management.team.new.persists to mgmt.team.new.persists, mgmt.user.new.persists to mgmt.user.new.happy_path, mgmt.organization.new.persists to mgmt.organization.new.happy_path, and the route-scoped llm-only-key denial to other.auth.virtual_key.route_permission_enforced, which is the contract it actually proves (allowed_routes whitelisting), not a role check. The key-generate test additionally claims mgmt.key.info.persists and the member add/delete test claims mgmt.team.member_delete.persists, both already asserted in those tests

This moves Management/UI P0 coverage from 4/19 to 13/19. The remaining six P0 gaps are deliberate: the three key.*.admin_only cells are mis-framed because internal users self-serve their own keys (/key/generate|update|delete are in internal_user_routes), so "admin_only" there needs a registry decision rather than a misleading test; key.generate.happy_path is the SSO-driven UI path; and the two model.* cells belong to the model-management fold branch

…rkers

Adds the missing Management/UI P0 e2e tests the coverage registry enumerates but
nothing covered: budget-create persistence read back through /budget/info,
proxy-admin-only enforcement on /budget/new and /team/new, and team-admin-required
enforcement on /team/member_add and /team/member_delete. Each authz test also
asserts the write did not land, so a removed check fails the test rather than
passing on the status code alone

Reconciles the covers markers already on the suite to real registry ids so the
collector counts them instead of flagging orphans: management.team.new.persists to
mgmt.team.new.persists, mgmt.user.new.persists to mgmt.user.new.happy_path,
mgmt.organization.new.persists to mgmt.organization.new.happy_path, and the
route-scoped llm-only-key denial to other.auth.virtual_key.route_permission_enforced,
which is the contract it actually proves. The key-generate test additionally claims
mgmt.key.info.persists and the member add/delete test claims
mgmt.team.member_delete.persists, both of which they already assert

This raises Management/UI P0 coverage from 4/19 to 13/19. The remaining gaps are the
three key.*.admin_only cells (internal users self-serve keys, so "admin_only" is the
wrong framing and needs a registry decision), the SSO-driven key.generate.happy_path,
and the model.* cells handled on the model-management fold branch
@greptile-apps

greptile-apps Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fills P0 coverage gaps in the management-route e2e suite by adding tests for budget persistence, proxy-admin-only enforcement on /budget/new and /team/new, and team-admin-required enforcement on /team/member_add and /team/member_delete. It also reconciles several @pytest.mark.covers markers to match the real registry IDs, moving management P0 coverage from 4/19 to 13/19.

  • New TestBudgetRoutes class: two tests cover budget create-and-read-back (asserting max_budget, soft_budget, budget_duration, and a computed budget_reset_at survive the DB roundtrip) and 401 enforcement for non-admin keys; the read-back is also used to confirm denied writes never land.
  • New TestTeamRoutes auth tests: test_new_forbidden_for_non_admin asserts 401 on /team/new for a non-admin key and verifies via /team/info (404) that no team was created; test_member_writes_forbidden_for_non_admin_member asserts 403 on both member write routes and verifies roster state is unchanged after the denials.
  • Marker reconciliation: four existing @pytest.mark.covers strings are corrected to real registry IDs; the underlying test assertions are untouched.

Confidence Score: 4/5

Safe to merge — all changes are confined to the e2e test directory, no production code is touched.

The new tests are well-structured: each authz test verifies both the denied status code and that the write did not land, which is a stronger contract than a status-code check alone. The BudgetNewBody.budget_id field is declared required in the test model but optional on the server, so the auto-ID generation path can never be exercised. The immediate read-back in test_new_persists_to_budget_info works today because budgets bypass the proxy's auth cache, but there is no comment explaining that invariant, leaving a latent fragility if the caching model changes.

No files require special attention; both observations are in the test layer only.

Important Files Changed

Filename Overview
tests/e2e/models.py Adds six budget management model classes (BudgetNewBody, BudgetInfoBody, BudgetData, BudgetInfoResponse, BudgetDeleteBody) that mirror the server's _types.py shapes; field names and types are correct (BudgetDeleteRequest.id confirmed).
tests/e2e/management/management_client.py Adds create_budget, delete_budget, budget_row, budget_new_status, team_member_add_status, and team_member_delete_status methods; follows the existing patterns exactly (unwrap for reads, discarded result for cleanups, transport.send for raw-status probes).
tests/e2e/management/test_management_e2e.py Adds TestBudgetRoutes and four new TestTeamRoutes tests covering budget persistence, budget/team admin-only enforcement (401), and team-admin-required member write enforcement (403); marker reconciliation on existing tests is correct and does not weaken coverage.

Reviews (1): Last reviewed commit: "test(e2e): fill management P0 coverage g..." | Re-trigger Greptile

Comment thread tests/e2e/models.py
Comment on lines +543 to +547
class BudgetNewBody(BaseModel):
budget_id: str
max_budget: float | None = None
soft_budget: float | None = None
budget_duration: str | None = None

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.

P2 The test model declares budget_id as a required str, but the server's BudgetNewRequest has budget_id: Optional[str] — the proxy auto-generates an ID when none is provided. Because the test model enforces the field, test_new_persists_to_budget_info can never exercise the auto-ID path. Since every call in the suite already passes an explicit ID this causes no test failures, but the schema divergence will silently prevent any future test that wants to omit budget_id from compiling correctly.

Suggested change
class BudgetNewBody(BaseModel):
budget_id: str
max_budget: float | None = None
soft_budget: float | None = None
budget_duration: str | None = None
class BudgetNewBody(BaseModel):
budget_id: str | None = None
max_budget: float | None = None
soft_budget: float | None = None
budget_duration: str | None = None

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +338 to +355
def test_new_persists_to_budget_info(self, client: ManagementClient, resources: ResourceManager) -> None:
budget_id = f"e2e-mgmt-budget-{unique_marker()}"
_create_budget(
client,
resources,
BudgetNewBody(budget_id=budget_id, max_budget=42.5, soft_budget=21.25, budget_duration="30d"),
)

row = client.budget_row(budget_id)
assert row is not None, f"/budget/info does not list {budget_id} after /budget/new"
assert row.max_budget == 42.5, f"/budget/info reports max_budget {row.max_budget}, configured 42.5"
assert row.soft_budget == 21.25, f"/budget/info reports soft_budget {row.soft_budget}, configured 21.25"
assert row.budget_duration == "30d", (
f"/budget/info reports budget_duration {row.budget_duration!r}, configured '30d'"
)
assert row.budget_reset_at is not None, (
"a budget with a 30d duration must persist a computed budget_reset_at, got None"
)

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.

P2 No polling before budget read-back

test_new_persists_to_budget_info calls client.budget_row immediately after _create_budget returns. Every other persistence test in this file that touches an entity the proxy might buffer (keys, teams) uses _poll to absorb propagation delays, but budgets skip this step. If the proxy ever starts caching budget writes before committing to the DB, or if replication lag is introduced, this test will flake with a spurious None result on the first read. Adding an explicit comment explaining why immediate read-back is safe here (direct DB write, no cache layer) would make the intentional design clear to future maintainers.

@codecov

codecov Bot commented Jul 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 30 untouched benchmarks


Comparing litellm_e2e_coverage_integration (bfc485b) with litellm_internal_staging (07aeaa1)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch main September 13, 2026 04:28
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 15:49
@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 23, 2026 15:49
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Closing this as stale since it has had no activity in over 30 days. Feel free to reopen if it is still needed.

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.

2 participants