drop cohort builder plumbing; use kit cohorte_armado builds for MLflow lineage

This commit is contained in:
Roberto Treviño Cervantes
2026-10-30 11:19:21 -06:00
parent cbb3b9c7b6
commit 6e8ed1003d
13 changed files with 249 additions and 491 deletions
+11 -8
View File
@@ -3,7 +3,6 @@ import json
import pytest
from models.base import ScreeningModel
from models.cohort import CohortBuilder, ExclusionCriterion
from models.prediction import ApplicabilityRejected, Interpretability, PredictionService
from models.registry import registry
@@ -18,11 +17,8 @@ class StubModel(ScreeningModel):
return {"label": "positivo", "confianza": 0.73}
class AlwaysRejectCohortBuilder(CohortBuilder):
domain = "cacu"
scenario = "tamizaje"
criteria_version = "v1"
criteria = [ExclusionCriterion(code="X", reason_code="siempre", predicate=lambda e: True, applicable_in_production=True)]
def never_applicable(row: dict) -> bool:
return False
def _promote_a_version(production_ready):
@@ -56,7 +52,7 @@ def test_predict_without_active_version_raises(governance_db, mlflow_tracking):
def test_applicability_gate_flags_but_does_not_block_by_default(production_ready):
_promote_a_version(production_ready)
service = PredictionService(
StubModel(), domain="cacu", scenario="tamizaje", cohort_builder=AlwaysRejectCohortBuilder()
StubModel(), domain="cacu", scenario="tamizaje", aplicable=never_applicable
)
prediction = service.predict_and_record({"edad": 40}, pac_id_hospital="H-1")
@@ -69,9 +65,16 @@ def test_applicability_gate_can_reject_outright(production_ready):
StubModel(),
domain="cacu",
scenario="tamizaje",
cohort_builder=AlwaysRejectCohortBuilder(),
aplicable=never_applicable,
reject_inapplicable=True,
)
with pytest.raises(ApplicabilityRejected):
service.predict_and_record({"edad": 40}, pac_id_hospital="H-1")
def test_applicability_gate_needs_a_dict(production_ready):
_promote_a_version(production_ready)
service = PredictionService(StubModel(), domain="cacu", scenario="tamizaje", aplicable=never_applicable)
with pytest.raises(TypeError):
service.predict_and_record([40], pac_id_hospital="H-1")