test(integration): budget_duration change on /budget/update recomputes budget_reset_at (Pylon #6913)

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
kerry 2026-09-22 20:44:58 +00:00 • committed by Devin AI
parent 1813790dfa
commit 8b3c2166d8
2 changed files with 31 additions and 0 deletions

View file

@ -33,6 +33,9 @@
"tests/integration/management/test_key_updates.py::test_update_preserves_independent_fields_and_serving": [
"mgmt.key.update.preserves_independent_fields"
],
"tests/integration/management/test_budget_updates.py::test_shortening_budget_duration_moves_reset_at_onto_the_new_schedule": [
"mgmt.budget.update.duration_change_recomputes_reset_at"
],
"tests/integration/pricing/test_configured_prices.py::test_custom_price_is_reported_and_charged": [
"quota_management.spend_tracking.custom_price.matches_input_rates"
],

View file

@ -0,0 +1,28 @@
from datetime import datetime
from typing import Final
import pytest
from tests.integration._support.client import Gateway, string_value
from tests.integration._support.database import read_rows
def _persisted_reset_at(budget_id: str) -> datetime:
rows: Final = read_rows(
'SELECT budget_reset_at::text AS reset_at FROM "LiteLLM_BudgetTable" WHERE budget_id = %s', (budget_id,)
)
assert len(rows) == 1, rows
return datetime.fromisoformat(string_value(rows[0]["reset_at"]))
@pytest.mark.covers("mgmt.budget.update.duration_change_recomputes_reset_at")
def test_shortening_budget_duration_moves_reset_at_onto_the_new_schedule(gateway: Gateway) -> None:
with gateway.scenario() as scenario:
budget_id: Final = scenario.budget(max_budget=10.0, budget_duration="30d")
monthly_reset_at: Final = _persisted_reset_at(budget_id)
response: Final = gateway.request("POST", "/budget/update", {"budget_id": budget_id, "budget_duration": "1d"})
assert response.status_code == 200, response.text
control_id: Final = scenario.budget(max_budget=10.0, budget_duration="1d")
daily_reset_at: Final = _persisted_reset_at(control_id)
assert daily_reset_at < monthly_reset_at, f"{daily_reset_at} vs {monthly_reset_at}"
assert _persisted_reset_at(budget_id) == daily_reset_at, response.text