"""hr's scenario catalogue (tests/scenarios/catalogue.py), in process: hr + the real business-partner brick + a test
provider, each on its own SQLite, real ASGI and a real MCP session. One test per scenario, so a failure names the
promise that broke. Live: `erp-scenarios run tests/scenarios/catalogue.py --live ...` (see README)."""
import pathlib
import sys
import pytest
HERE = pathlib.Path(__file__).resolve().parent
sys.path.insert(0, str(HERE / "scenarios"))
from erp_platform import compose # noqa: E402
from erp_platform.scenarios.inprocess import InProcessRunner # noqa: E402
import catalogue # noqa: E402
CAT = catalogue.CAT
@pytest.fixture(scope="module")
def runner():
with InProcessRunner(CAT) as r:
yield r
def _ids():
return [sc.id for sc in CAT.expand(compose.load(CAT.compose))]
@pytest.mark.parametrize("sid", _ids())
def test_scenario(runner, sid):
sc = next(x for x in runner.scenarios() if x.id == sid)
res = runner.run_one(sc)
assert res.outcome == "passed", f"{sid}: {res.outcome} — {res.message}\n" + "\n".join(res.steps[-15:])
def test_the_catalogue_covers_the_spec():
ids = {sc.id for sc in CAT.scenarios}
wanted = {f"SC-HR-{n:02d}" for n in range(1, 29)} - {"SC-HR-20"} # SC-HR-20 is the generated matrix
assert wanted <= ids, sorted(wanted - ids)
gen = {sc.id.split("-")[1] for sc in CAT.expand(compose.load(CAT.compose)) if sc.generated}
# erp-platform 0.9.2 adds the WILD probes (`*:*:*`, `<module>:*:*`, malformed grants); older ones don't generate them
assert gen - {"WILD"} == {"PERM", "ROWS", "IDEM", "MASS"}