"""Contract tests — every living variant must satisfy the harness producer contract. These are the teeth of the liveness gate: when the mutator changes a variant, if it breaks the producer (``produce.py``), the manifest, or the contract shape, THESE tests fail and the mutator must fix the variant (it cannot edit this file — tests/ is locked). They only COMPILE produce.py (never execute it), so no LLM/network/render happens here — that is the job of the runtime smoke test (harness/smoke.py), which actually runs the producer. """ import py_compile from pathlib import Path import pytest from harness.dispatcher import living_variants from harness.genome import PRODUCER_SCRIPT, VariantManifest REPO_ROOT = Path(__file__).resolve().parent.parent VARIANTS = living_variants(REPO_ROOT / "variants") def test_at_least_one_living_variant(): assert len(VARIANTS) >= 1 def test_population_within_cap(): from harness.dispatcher import MAX_LIVING_VARIANTS assert len(VARIANTS) <= MAX_LIVING_VARIANTS @pytest.mark.parametrize("manifest", VARIANTS, ids=[m.variant_id for m in VARIANTS]) def test_variant_has_valid_producer(manifest: VariantManifest): """The variant must ship an executable produce.py that at least parses/compiles.""" script = REPO_ROOT / "variants" / manifest.variant_id / PRODUCER_SCRIPT assert script.exists(), f"{manifest.variant_id} must ship {PRODUCER_SCRIPT} (the producer)" try: py_compile.compile(str(script), doraise=True) except py_compile.PyCompileError as error: pytest.fail(f"{manifest.variant_id}/{PRODUCER_SCRIPT} does not compile: {error}") @pytest.mark.parametrize("manifest", VARIANTS, ids=[m.variant_id for m in VARIANTS]) def test_variant_manifest_valid(manifest: VariantManifest): assert manifest.variant_id assert isinstance(manifest.genome, dict) assert len(manifest.genome_hash) == 12