Skip to content

Commit 9429daa

Browse files
committed
refactor(buds): derive branch_overrides allowed keys from ReleaseStage
The validator hardcoded ``{"uat", "prod"}`` next to a comment that already pointed at the existing ``Literal["uat", "prod"]`` in ``app.schemas.bud_release``. Drop the duplicate and source the allowed-keys set from ``get_args(ReleaseStage)`` so adding a new release-stage tab in one place automatically widens the override contract — no second edit needed, no drift possible. Behaviour and tests unchanged (16 cases pass). Signed-off-by: Arun Rajkumar <mickyarunr@gmail.com>
1 parent 07e7e31 commit 9429daa

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

backend/app/schemas/bud.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import re
2323
import uuid
2424
from datetime import datetime
25-
from typing import Any
25+
from typing import Any, get_args
2626

2727
from pydantic import BaseModel, Field, field_validator, model_validator
2828

@@ -35,6 +35,7 @@
3535
DesignGenerateRequest,
3636
DesignHtmlUpdate,
3737
)
38+
from app.schemas.bud_release import ReleaseStage
3839

3940
# Single source of truth for the accepted Figma share-URL shape:
4041
# - ``/file/<key>/...`` (legacy)
@@ -149,7 +150,12 @@ def _validate_branch_overrides(
149150
be either ``None`` (clear that stage) or a non-empty / non-whitespace
150151
branch pattern.
151152
152-
Catches three classes of bad input at the API edge:
153+
Allowed keys are derived from the existing ``ReleaseStage`` Literal
154+
in :mod:`app.schemas.bud_release` so the two contracts stay in
155+
sync: the only stages that have a release-stage tab are the only
156+
stages a per-BUD override can target. Surfaces three classes of
157+
bad input at the API edge:
158+
153159
* Wrong-case / unknown stage key (``"UAT"`` / ``"production"``).
154160
* Empty string (``""``) — would otherwise read as truthy in some
155161
callers and break the fallback-to-repo-default contract.
@@ -159,7 +165,7 @@ def _validate_branch_overrides(
159165
"""
160166
if value is None:
161167
return None
162-
allowed = {"uat", "prod"}
168+
allowed: set[str] = set(get_args(ReleaseStage))
163169
unknown = sorted(set(value) - allowed)
164170
if unknown:
165171
raise ValueError(

0 commit comments

Comments
 (0)