fix(management_v1): report a zero team default as no cap

Enforcement treats max_budget 0 on the team default as "no cap" and only
honors 0 as an explicit disable on a member's own row, so reporting an
inheriting member as capped at 0 said the opposite of what happens on their
next request.
This commit is contained in:
ryan-crabbe-berri 2026-09-17 12:35:46 -07:00
parent 648373a260
commit 4f6dfb0480
2 changed files with 15 additions and 1 deletions

View file

@ -92,7 +92,7 @@ def _result(
)
budget: Final = budget_of.get(user_id)
own_max_budget: Final = budget.max_budget if budget is not None else None
inherits: Final = own_max_budget is None and team_default_max_budget is not None
inherits: Final = own_max_budget is None and team_default_max_budget is not None and team_default_max_budget > 0
return TeamMemberBudgetUpdateResult(
user_id=user_id,
user_email=member.user_email,

View file

@ -542,6 +542,20 @@ async def test_a_team_with_no_default_budget_reports_no_effective_cap_for_a_memb
assert (results[0].tpm_limit, results[0].rpm_limit) == (5, 3)
@pytest.mark.asyncio
async def test_a_zero_team_default_reports_no_cap_because_enforcement_reads_zero_there_as_uncapped():
prisma = _FakePrisma(
teams=[_team("m1", default_budget_id="team-default")],
memberships=[_membership("m1", None)],
budgets=[_budget("team-default", max_budget=0.0)],
)
results = await _bulk_update(prisma, [{"user_id": "m1", "tpm_limit": 9}])
assert [(r.success, r.max_budget, r.max_budget_source) for r in results] == [(True, None, None)]
assert results[0].tpm_limit == 9
@pytest.mark.asyncio
async def test_a_row_that_names_nobody_on_the_team_reports_no_cap_and_no_source():
prisma = _FakePrisma(