# [DEF:backend.tests.services.clean_release.test_stages:Module]
# @TIER: STANDARD
# @SEMANTICS: tests, clean-release, compliance, stages
# @PURPOSE: Validate final status derivation logic from stage results.
# @LAYER: Domain
# @RELATION: TESTS -> backend.src.services.clean_release.stages

from src.models.clean_release import CheckFinalStatus, CheckStageName, CheckStageResult, CheckStageStatus
from src.services.clean_release.stages import derive_final_status, MANDATORY_STAGE_ORDER

def test_derive_final_status_compliant():
    results = [CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok") for s in MANDATORY_STAGE_ORDER]
    assert derive_final_status(results) == CheckFinalStatus.COMPLIANT

def test_derive_final_status_blocked():
    results = [CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok") for s in MANDATORY_STAGE_ORDER]
    results[1].status = CheckStageStatus.FAIL
    assert derive_final_status(results) == CheckFinalStatus.BLOCKED

def test_derive_final_status_failed_missing():
    results = [CheckStageResult(stage=MANDATORY_STAGE_ORDER[0], status=CheckStageStatus.PASS, details="ok")]
    assert derive_final_status(results) == CheckFinalStatus.FAILED

def test_derive_final_status_failed_skipped():
    results = [CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok") for s in MANDATORY_STAGE_ORDER]
    results[2].status = CheckStageStatus.SKIPPED
    assert derive_final_status(results) == CheckFinalStatus.FAILED


# [/DEF:backend.tests.services.clean_release.test_stages:Module]
