Registry: list a domain's scenarios with a version in production

This commit is contained in:
2026-11-22 20:34:38 -06:00
parent e1f388c702
commit ccaa6fca12
2 changed files with 22 additions and 1 deletions
+8
View File
@@ -125,6 +125,14 @@ class ModelRegistry:
def status(self, domain: str, scenario: str, version: str) -> str:
return self._status(self.get(domain, scenario, version))
def in_production(self, domain: str) -> list[str]:
"""The scenarios of `domain` with a version holding the `produccion` alias, by name."""
if domain not in DOMAINS:
raise ValueError(f"dominio desconocido: {domain!r}")
prefix = registered_name(domain, "")
models = self.client.search_registered_models(filter_string=f"name LIKE '{prefix}%'")
return sorted(m.name.removeprefix(prefix) for m in models if PRODUCTION_ALIAS in (m.aliases or {}))
def resolve(self, domain: str, scenario: str, version: str | None = None) -> ResolvedVersion:
"""With no `version`, the one holding the `produccion` alias; with a version, that one, whatever
its status (to test or compare a candidate). The status travels with it: confirming risks only
+14 -1
View File
@@ -1,4 +1,4 @@
"""What this module covers: the registry's promotion checks, promotion and retirement, the lineage of a version, and
"""What this module covers: the registry's promotion checks, promotion and retirement, the scenarios in production, the lineage of a version, and
what its run stored (`registry.artifacts`, `registry.artifact`, `registry.routines`).
Fixtures: `production_ready` (from `conftest.py`), a PROD version whose run recorded every routine and its model;
@@ -108,6 +108,19 @@ def test_retire_and_lineage(production_ready):
registry.retire(domain, scenario, second)
def test_in_production_lists_the_scenarios_holding_the_alias(production_ready):
"""Only scenarios of the domain with a version in production are listed; a candidate or a retired one is not.
Fails if `in_production` stops reading the `produccion` alias or leaks another domain's models."""
domain, scenario, version = production_ready("v1")
production_ready("v1-dx", scenario="diagnostico")
assert registry.in_production(domain) == []
registry.promote(domain, scenario, version)
assert registry.in_production(domain) == [scenario]
assert registry.in_production("cama") == []
registry.retire(domain, scenario, version)
assert registry.in_production(domain) == []
@pytest.mark.parametrize("domain, scenario", [("cacu' OR '1'='1", None), ("cacu", "x' OR name LIKE '%")])
def test_version_filters_reject_anything_but_known_names(mlflow_tracking, domain, scenario):
with pytest.raises(ValueError):