From 7015bd2ea1ab4eb06ec0255545c4600d21b659e5 Mon Sep 17 00:00:00 2001 From: ryan-crabbe-berri Date: Fri, 17 Jul 2026 11:48:18 -0700 Subject: [PATCH] test(e2e): assert an org budget block is a 429 naming the organization (#33638) * test(e2e): assert bare-key budget refusal is 429 and /key/info spend reaches the cap * test(e2e): keep the bare-key budget assertion to the 429 refusal shape * test(e2e): assert a team's max_budget blocks every key on the team * test(e2e): focus the team budget case on the 429 blocking behavior * test(e2e): assert an org budget block is a 429 naming the organization --- .../budgets/test_budget_enforcement_e2e.py | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/e2e/quota_management/budgets/test_budget_enforcement_e2e.py b/tests/e2e/quota_management/budgets/test_budget_enforcement_e2e.py index 47cbfeb7ef0..0b8adfc47ae 100644 --- a/tests/e2e/quota_management/budgets/test_budget_enforcement_e2e.py +++ b/tests/e2e/quota_management/budgets/test_budget_enforcement_e2e.py @@ -141,20 +141,31 @@ class EndUserBudgetCase(_BudgetCase): class OrganizationBudgetCase(_BudgetCase): + """Org carries the tiny budget; the team under it and the key carry none, so + the org is the only entity that can block (the historically weak link). The + refusal must be a 429 budget_exceeded that names the org as the blocker.""" + def init(self) -> None: - # Org carries the tiny budget; the team under it has none, so a block here - # is org-level enforcement (the historically weak link). - org_id = self.client.create_org( + self._org_id = self.client.create_org( max_budget=3e-6, alias=f"e2e-budget-org-{unique_marker()}" ) - self._undo.append(lambda: self.client.delete_org(org_id)) + self._undo.append(lambda: self.client.delete_org(self._org_id)) team_id = self.client.create_team( - alias=f"e2e-budget-team-{unique_marker()}", organization_id=org_id + alias=f"e2e-budget-team-{unique_marker()}", organization_id=self._org_id ) self._undo.append(lambda: self.client.delete_team(team_id)) self.key = self.client.generate_key(team_id=team_id) self._undo.append(lambda: self.client.delete_key(self.key)) + def run(self) -> None: + blocked = _assert_budget_blocks(self.client, self.key) + assert blocked.status_code == 429, ( + f"budget refusal must be 429, got {blocked.status_code}: {blocked.body[:200]}" + ) + assert f"Organization={self._org_id}" in blocked.body, ( + f"refusal must name the org as the blocker, got: {blocked.body[:200]}" + ) + class TeamMemberBudgetCase(_BudgetCase): def init(self) -> None: