diff --git a/models/cama/recurrence/steps.py b/models/cama/recurrence/steps.py index 712fd17..da03d87 100644 --- a/models/cama/recurrence/steps.py +++ b/models/cama/recurrence/steps.py @@ -7,7 +7,7 @@ import sys def run_steps(args: argparse.Namespace) -> int: """`models run cama recurrence --train --promote`: this scenario trains on its files, not on a cohort build.""" from models.__main__ import _promote_step - from models.cama.recurrence.source import ExternalCohorts + from models.cama.recurrence.source import ExternalCohorts, data_folder from models.dags.training import Scenario, find_trained, train if args.export or args.estimate or args.store or args.version: diff --git a/tests/cama/test_recurrence.py b/tests/cama/test_recurrence.py index 224c09a..42883e9 100644 --- a/tests/cama/test_recurrence.py +++ b/tests/cama/test_recurrence.py @@ -144,3 +144,29 @@ def test_a_version_trains_registers_and_publishes_its_figures(files, mlflow_trac 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 + + +def test_the_cli_trains_and_leaves_the_version_waiting_for_its_reports(files, mlflow_tracking, monkeypatch, capsys): + """Pins down: `models run cama recurrence --train --promote` (what a governance job runs) trains the version, says "trained", then + refuses to promote it for want of its reports with the message the job reads ("not promoted, missing") and exit code 1; run + again it finds the version already trained. Fails if the entry point cannot run (a missing import), trains twice, or + promotes without the human reports.""" + import argparse + import dataclasses + + from models.cama.recurrence.steps import run_steps + + 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} + monkeypatch.setattr(Scenario, "load", classmethod(lambda cls, domain, name: dataclasses.replace(scenario, config={"recurrence": tiny}))) + args = argparse.Namespace(export=False, estimate=False, store=False, version=None, train=True, promote=True, environment="prod", + domain="cama", scenario="recurrence") + + first = run_steps(args) + out = capsys.readouterr() + second = run_steps(args) + again = capsys.readouterr() + + assert first == 1 and "trained: version 1" in out.out and "not promoted, missing" in out.err + assert second == 1 and "already trained: version 1" in again.out