7d06f9db9d
The `cohorts` and `estimate` steps take the project's cohorts from dbt's manifest (`cohort_urls`) and build each one with models' `build_of` over dbt's queries, instead of the Python-frame TOMLs in models/cohorts, which are gone; without a manifest a project has no cohort steps. The recruitment window and cut-off are dbt's vars. The live estimator reads cin2_logistic through `Scenario` and `KitBuild`, and governance imports `models.reports.experiment`, where models now keeps it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HmQxVJVNR5FYkPAregGEQ7
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""Las dependencias entre los pasos de cada proyecto, como las lee Hamilton de los parámetros."""
|
|
|
|
import json
|
|
|
|
import pytest
|
|
from hamilton import driver
|
|
|
|
from webapi.orchestration import cycle, steps_of
|
|
|
|
|
|
def dependencias(proyecto: str) -> dict[str, set[str]]:
|
|
dr = driver.Builder().with_modules(cycle).with_config({"with_cohorts": proyecto == "cacu"}).build()
|
|
return {n.name: {d.name for d in n.dependencies} - {"ctx"} for n in dr.graph.get_nodes() if n.name != "ctx"}
|
|
|
|
|
|
def antes(deps: dict[str, set[str]], paso: str) -> set[str]:
|
|
"""Todos los pasos que corren antes de `paso`."""
|
|
previos = set()
|
|
pending = list(deps[paso])
|
|
while pending:
|
|
anterior = pending.pop()
|
|
if anterior not in previos:
|
|
previos.add(anterior)
|
|
pending.extend(deps[anterior])
|
|
return previos
|
|
|
|
|
|
@pytest.mark.parametrize("proyecto", ["cacu", "cama", "tea"])
|
|
def test_cada_paso_corre_despues_de_lo_que_necesita(proyecto):
|
|
deps = dependencias(proyecto)
|
|
assert deps["migrate"] == set()
|
|
assert {"migrate", "catalogs"} <= antes(deps, "load") # decisión 6 de §9
|
|
assert {"load"} <= antes(deps, "event_models")
|
|
assert {"registry"} <= antes(deps, "observe")
|
|
assert {"load", "catalogs"} <= antes(deps, "check_silver")
|
|
|
|
|
|
def test_las_cohortes_son_las_del_manifiesto_de_dbt(tmp_path, monkeypatch):
|
|
"""Pins down: a project builds cohorts and estimates only if dbt's manifest has a cohort of it (`meta.cohort` of
|
|
a population query), today only CaCu's; without a manifest no project does. Fails if the cycle reads cohort
|
|
definitions from anywhere else than dbt."""
|
|
manifest = tmp_path / "manifest.json"
|
|
nodo = {"config": {"meta": {"cohort": "cacu/cohorte_vigilancia", "kind": "population"}}}
|
|
manifest.write_text(json.dumps({"nodes": {"model.p.cacu_surveillance_all_patients": nodo}}))
|
|
|
|
assert {"cohorts", "estimate"} <= set(steps_of("cacu", manifest))
|
|
for proyecto in ("cama", "tea"):
|
|
assert not {"cohorts", "estimate"} & set(steps_of(proyecto, manifest))
|
|
monkeypatch.delenv("DBT_MANIFEST", raising=False)
|
|
assert not {"cohorts", "estimate"} & set(steps_of("cacu"))
|