Repository navigation
test(e2e): cover key max_budget blocks on personal, team, and team-member keys - #33895
ryan-crabbe-berri merged 2 commits into
Conversation
Greptile SummaryThis PR adds three new e2e tests covering
Confidence Score: 5/5Safe to merge — changes are confined to the e2e test directory, touch no production code, and preserve all existing test assertions and coverage registry cells while adding well-isolated new cases. The refactor is behavior-preserving: teardown order is correctly LIFO throughout, lambda captures are not in loops so there is no late-binding hazard, and the new sweep tests correctly keep surroundings roomy (100.0) so only the key-level cap (3e-6) can trip — the control-key assertion then confirms nothing else in the hierarchy was the blocker. Dead-code removal of E2ECase and run_case is clean with no remaining consumers. No files require special attention.
|
| Filename | Overview |
|---|---|
| tests/e2e/quota_management/budgets/test_budget_enforcement_e2e.py | Rewrites from E2ECase/run_case to plain-pytest class pattern; adds three new sweep tests isolating the key-level max_budget across personal, team, and team-member mint shapes |
| tests/e2e/lifecycle.py | Removes the now-unused E2ECase Protocol and run_case() driver; ResourceManager and related protocols are unchanged |
| tests/e2e/conftest.py | Docstring-only update to reflect the ResourceManager lifecycle; no functional change |
Reviews (2): Last reviewed commit: "refactor(e2e): convert budget enforcemen..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ure pattern The E2ECase class pattern existed only in this file; every other suite uses plain pytest tests with the resources fixture. Rewrites the nine cases as two spec classes and removes the now-dead E2ECase protocol and run_case driver from lifecycle.py
|
@greptileai re review |
Relevant issues
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Screenshots / Proof of Fix
All runs are against a live proxy on localhost:4000 running staging commit 366ec6f with a throwaway Postgres and Redis, the fast budget rescheduler, and real provider calls (
claude-haiku-4-5is backed bygroq/llama-3.3-70b-versatilelocally since that is the only live provider key on this machine). Proof was restamped after the refactor commit: the file content that ran is byte-identical to this PR's head b30603eEarlier, the three new sweep tests alone also ran five consecutive times at the pre-refactor commit f012661 (3 passed in 8.50s, 8.21s, 8.68s, 8.20s, 8.26s).
basedpyright tests/e2ereports 0 errors andpython -m coverage_registry.collector --strictpassesType
✅ Test
Changes
Two commits. The first covers the "Key
max_budgetblocks" row of the budgets coverage matrix for the three unexercised key kinds: the existing bare-key case proves a key's own budget blocks; the new cases prove the same key-level cap still blocks when the key is minted to a person (user_id), a team (team_id), or a team membership (both), i.e. that surrounding entities do not shadow or absorb the key's own budget. Each puts the tiny cap (3e-6) on the key itself and every budget around it at a roomy 100.0, so the key-level check is provably the only thing that can block; after the capped key is refused with a 429budget_exceeded, an uncapped control key minted to the same surroundings must still serveThe second commit converts the file from the
E2ECaseclass pattern (init/run/teardown case classes driven byrun_casethrough one parametrized test) to the plain-pytestresourcesfixture pattern every other budgets file already uses. That pattern existed only in this one file, dating from the founding suite PR #30869; the rewrite turns the nine cases into two spec classes,TestBudgetBlocksPerLevel(one test per budget level: bare key, team, internal user, end-user, organization, team member) andTestKeyBudgetBlocksAcrossKeyKinds(the sweep above), with cleanup viaresources.deferand the repeated block-shape assert hoisted into_assert_blocked_429. Assertions and setup shapes are behavior-preserving; node ids change fromtest_budget_enforcement[XxxCase]to the class::method form. The now-deadE2ECaseprotocol andrun_casedriver are removed fromlifecycle.py(this file was their only consumer) and the conftest docstring updatedAll nine tests keep their original registry cells; the three sweep tests intentionally share
quota_management.budget.key.blocks_over_limitwith the bare-key test (same pattern as the team-member-key variant sharinginternal_user.resets_after_window): the matrix tracks the per-key-kind split, the registry keeps one row per budget level x behaviorQA runbook
TestBudgetBlocksPerLevel::test_bare_key_blocks_over_its_own_budgetmints a bare key capped at 3e-6, drives/chat/completionsuntil refused, asserts 429budget_exceeded; key deleted on teardownTestBudgetBlocksPerLevel::test_team_budget_blocks_every_team_keycreates a team capped at 3e-6 with two uncapped keys, drives one to the block, asserts the sibling's first call is also a 429budget_exceeded; teardown deletes keys then teamTestBudgetBlocksPerLevel::test_user_budget_enforced_across_all_their_keyscreates a user capped at 3e-6 with two personal keys and a team-member key on an uncapped team, drives the first personal key to the block, asserts the other two keys are refused as well; teardown deletes keys, team, userTestBudgetBlocksPerLevel::test_end_user_budget_blocks_attributed_callscreates a customer capped at 3e-6 and drives calls attributed viauser=until refused as a budget block; teardown deletes key and customerTestBudgetBlocksPerLevel::test_org_budget_blocks_keys_under_itcreates a capped org with an uncapped team and key under it, drives to the block, asserts the refusal namesOrganization=<id>; teardown deletes key, team, orgTestBudgetBlocksPerLevel::test_member_budget_blocks_without_touching_teammatescreates a roomy team, caps one member at 3e-6 viamax_budget_in_team, drives that member's key to the block, asserts an uncapped teammate's key still serves; teardown deletes keys, users, teamTestKeyBudgetBlocksAcrossKeyKinds::test_personal_key_blocks_over_its_own_budgetcreates a user withmax_budget100, mints a personal key capped at 3e-6 plus an uncapped control key, drives the capped key to a 429budget_exceeded, asserts the control key still serves; teardown deletes keys then userTestKeyBudgetBlocksAcrossKeyKinds::test_team_key_blocks_over_its_own_budgetdoes the same on a team withmax_budget100TestKeyBudgetBlocksAcrossKeyKinds::test_team_member_key_blocks_over_its_own_budgetdoes the same on a team-member key with team, user, and membership all at 100python -m coverage_registry.collector --strictpasses with the sweep tests sharingquota_management.budget.key.blocks_over_limitFinal Attestation