fix(workflow): enforce domain state machine in dual validation path
validate_as_red/blue_lead now delegate to TestEntity. check_dual_validation routes through entity instead of assigning test.state directly. Side effects dispatched via domain events. Entity raises InvalidOperationError for backward compat. Removed 4 dead V1 xfail tests, fixed 2 real test issues. 224 passed, 0 xfailed.
This commit is contained in:
@@ -28,7 +28,11 @@ from dataclasses import dataclass, field
|
||||
from datetime import datetime
|
||||
from typing import Any
|
||||
|
||||
from app.domain.errors import BusinessRuleViolation, InvalidStateTransition
|
||||
from app.domain.errors import (
|
||||
BusinessRuleViolation,
|
||||
InvalidOperationError,
|
||||
InvalidStateTransition,
|
||||
)
|
||||
|
||||
|
||||
# ── Value objects ────────────────────────────────────────────────────
|
||||
@@ -307,9 +311,22 @@ class TestEntity:
|
||||
self.paused_at = None
|
||||
return extra
|
||||
|
||||
def check_dual_validation(self) -> None:
|
||||
"""Evaluate both leads' votes and advance state if appropriate.
|
||||
|
||||
- Both **approved** -> ``validated``
|
||||
- Either **rejected** -> ``rejected``
|
||||
- Otherwise no change (waiting for the other lead).
|
||||
|
||||
Called automatically by :meth:`validate_red` and :meth:`validate_blue`.
|
||||
Also available as a standalone entry point for backward compatibility
|
||||
when validation fields are set externally.
|
||||
"""
|
||||
self._check_dual_validation()
|
||||
|
||||
def _assert_in_review(self, side: str) -> None:
|
||||
if self.state != TestState.in_review:
|
||||
raise BusinessRuleViolation(
|
||||
raise InvalidOperationError(
|
||||
f"Cannot validate {side} side while test is in "
|
||||
f"'{self.state.value}' state (must be in_review)"
|
||||
)
|
||||
@@ -317,7 +334,7 @@ class TestEntity:
|
||||
@staticmethod
|
||||
def _assert_valid_vote(status: str) -> None:
|
||||
if status not in ("approved", "rejected"):
|
||||
raise BusinessRuleViolation(
|
||||
raise InvalidOperationError(
|
||||
"validation_status must be 'approved' or 'rejected'"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user