CaMa recurrence: a version trains, registers and publishes its figures (test)

This commit is contained in:
rockdrigo
2026-11-21 13:41:15 -06:00
parent 0804937578
commit 9fe1f86c8b
+26
View File
@@ -118,3 +118,29 @@ def test_the_external_cohorts_are_the_versions_reference_and_the_files_are_hashe
assert source.reference()[COHORT_SOURCE_TAG] == REFERENCE_SOURCE and len(before) == 64
assert ExternalCohorts(files).reference()[COHORT_BUILD_TAG] != before
def test_a_version_trains_registers_and_publishes_its_figures(files, mlflow_tracking):
"""Pins down: training the scenario on its files registers a PROD version that carries the figures the dashboard draws
(`analisis/recurrencia.json`), the tables, the routines, the metrics and the saved model, linked to the files' hash, so that
only the human reports stand between it and promotion. Fails if the version cannot be saved, loses its figures, or fails a
promotion check that is not the reports."""
import dataclasses
import json
from models.dags.training import train
from models.io.registry import registry
scenario = Scenario.load("cama", "recurrence")
tiny = {**scenario.config["recurrence"], "data_dir": str(files), "horizons": [12, 36], "n_bootstrap_metabric": 2, "n_bootstrap_scanb": 2,
"n_boot_calc": 3, "min_events": 5, "ks_seconds": 2, "max_parents": 3}
scenario = dataclasses.replace(scenario, config={"recurrence": tiny})
version = train(scenario, ExternalCohorts(files), "PROD")
_, figures = registry.artifact("cama", "recurrence", version, "analisis/recurrencia.json")
_, tables = registry.artifact("cama", "recurrence", version, "analisis/recurrencia_desarrollo.json")
assert json.loads(figures)["escenarios"] and "auc" in json.loads(tables)["tablas"]
checks = {c.code: c.passed for c in registry.checks("cama", "recurrence", version)}
assert all(checks[code] for code in ("ML-02", "ML-03", "ML-01a", "ML-01b"))
assert not checks["MLD-01b"] and not checks["MLD-03"] # the reports are the human gate