From d5d8cd4fe1af5eaf101f8e49bdc73f838ecc5f01 Mon Sep 17 00:00:00 2001 From: Andrii Butko Date: Wed, 24 Jun 2026 22:36:42 +0200 Subject: [PATCH] test(proxy): assert negative spend is allowed (one-time grant use-case) Negative spend is intentionally permitted so admins can grant a team member extra allowance for the current budget period only, without raising the recurring budget ceiling. Cover it in validate_finite_spend and via the /team/member_update spend-reset test. --- tests/test_litellm/proxy/test_team_member_update.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tests/test_litellm/proxy/test_team_member_update.py b/tests/test_litellm/proxy/test_team_member_update.py index fb743002afb..c09a5355d8d 100644 --- a/tests/test_litellm/proxy/test_team_member_update.py +++ b/tests/test_litellm/proxy/test_team_member_update.py @@ -169,7 +169,12 @@ async def test_team_member_update_spend_writes_membership_and_invalidates( invalidate = AsyncMock() monkeypatch.setattr(proxy_server, "_invalidate_spend_counter", invalidate) - data, request, auth = _member_update_request(spend=0.0) + # Use a negative spend: this also implicitly validates that negative spend + # is allowed, which is desirable. Admins may grant a team member extra + # allowance for the current budget period only (a one-time spend grant) + # without raising the recurring budget ceiling. Future changes should + # continue allowing negative spend counters. + data, request, auth = _member_update_request(spend=-25.0) response = await team_member_update(data, request, auth) @@ -178,12 +183,12 @@ async def test_team_member_update_spend_writes_membership_and_invalidates( assert kwargs["where"] == { "user_id_team_id": {"user_id": "user-1", "team_id": "team-1234"} } - assert kwargs["data"]["update"] == {"spend": 0.0} - assert kwargs["data"]["create"]["spend"] == 0.0 + assert kwargs["data"]["update"] == {"spend": -25.0} + assert kwargs["data"]["create"]["spend"] == -25.0 invalidate.assert_awaited_once_with( counter_key="spend:team_member:user-1:team-1234" ) - assert response.spend == 0.0 + assert response.spend == -25.0 @pytest.mark.asyncio