feat(phase-20): navigation, error handling, integration tests, and V2 docs (T-132 to T-135)
This commit is contained in:
@@ -61,13 +61,20 @@ def transition_state(
|
||||
Raises :class:`~fastapi.HTTPException` 400 when the transition is invalid.
|
||||
"""
|
||||
if not can_transition(test, target_state):
|
||||
current = test.state if isinstance(test.state, TestState) else TestState(test.state)
|
||||
valid = [s.value for s in VALID_TRANSITIONS.get(current, [])]
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=(
|
||||
f"Invalid transition: cannot move from "
|
||||
f"'{test.state.value if isinstance(test.state, TestState) else test.state}' "
|
||||
f"to '{target_state.value}'"
|
||||
),
|
||||
detail={
|
||||
"message": (
|
||||
f"Cannot transition from '{current.value}' to '{target_state.value}'. "
|
||||
f"Valid transitions: {valid}"
|
||||
),
|
||||
"code": "INVALID_TRANSITION",
|
||||
"current_state": current.value,
|
||||
"target_state": target_state.value,
|
||||
"valid_transitions": valid,
|
||||
},
|
||||
)
|
||||
|
||||
previous_state = test.state.value if isinstance(test.state, TestState) else test.state
|
||||
@@ -159,16 +166,24 @@ def validate_as_red_lead(
|
||||
After recording the decision, :func:`check_dual_validation` is called
|
||||
to potentially advance the test to ``validated`` or ``rejected``.
|
||||
"""
|
||||
current = test.state.value if isinstance(test.state, TestState) else test.state
|
||||
if test.state not in (TestState.in_review,):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Cannot validate red side while test is in '{test.state.value if isinstance(test.state, TestState) else test.state}' state (must be in_review)",
|
||||
detail={
|
||||
"message": f"Cannot validate red side while test is in '{current}' state (must be in_review)",
|
||||
"code": "INVALID_STATE",
|
||||
"current_state": current,
|
||||
},
|
||||
)
|
||||
|
||||
if validation_status not in ("approved", "rejected"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="validation_status must be 'approved' or 'rejected'",
|
||||
detail={
|
||||
"message": "validation_status must be 'approved' or 'rejected'",
|
||||
"code": "INVALID_VALIDATION_STATUS",
|
||||
},
|
||||
)
|
||||
|
||||
now = datetime.utcnow()
|
||||
@@ -207,16 +222,24 @@ def validate_as_blue_lead(
|
||||
After recording the decision, :func:`check_dual_validation` is called
|
||||
to potentially advance the test to ``validated`` or ``rejected``.
|
||||
"""
|
||||
current = test.state.value if isinstance(test.state, TestState) else test.state
|
||||
if test.state not in (TestState.in_review,):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"Cannot validate blue side while test is in '{test.state.value if isinstance(test.state, TestState) else test.state}' state (must be in_review)",
|
||||
detail={
|
||||
"message": f"Cannot validate blue side while test is in '{current}' state (must be in_review)",
|
||||
"code": "INVALID_STATE",
|
||||
"current_state": current,
|
||||
},
|
||||
)
|
||||
|
||||
if validation_status not in ("approved", "rejected"):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="validation_status must be 'approved' or 'rejected'",
|
||||
detail={
|
||||
"message": "validation_status must be 'approved' or 'rejected'",
|
||||
"code": "INVALID_VALIDATION_STATUS",
|
||||
},
|
||||
)
|
||||
|
||||
now = datetime.utcnow()
|
||||
|
||||
Reference in New Issue
Block a user