"""Tests for the deterministic SPAWN scaffold (harness/spawn.py) — LOCKED. These guard the regression that produced variant_2, a torso with no produce.py that made 0 videos: a SPAWN must start life as a COMPLETE, contract-valid clone of its source, not a stub the coder is expected to flesh out. The scaffold clones the source's git-tracked files into the new variant dir so the "new" variant already renders standalone video before the coder applies the twist. """ import json import subprocess from pathlib import Path import pytest from harness import spawn from harness.genome import MANIFEST_FILENAME, PRODUCER_SCRIPT, VariantManifest REPO_ROOT = Path(__file__).resolve().parent.parent def _first_living_source() -> str: """Pick any variant that actually has a manifest to clone from.""" for d in sorted((REPO_ROOT / "variants").iterdir()): if (d / MANIFEST_FILENAME).is_file(): return d.name pytest.skip("no source variant with a manifest to clone") def test_clone_is_complete_and_contract_valid(tmp_path): source = _first_living_source() tracked = subprocess.run( ["git", "ls-files", "--", f"variants/{source}"], cwd=REPO_ROOT, capture_output=True, text=True, check=True, ).stdout.split() copied = spawn.scaffold(source, "variant_clone_test", variants_dir=tmp_path, today="2026-01-01") clone = tmp_path / "variant_clone_test" # Every git-tracked source file made it across — no torso. assert copied == len([p for p in tracked if (REPO_ROOT / p).is_file()]) assert (clone / PRODUCER_SCRIPT).is_file(), "clone must ship produce.py" assert (clone / MANIFEST_FILENAME).is_file() # The clone satisfies the same manifest contract the harness enforces on living variants. manifest = VariantManifest.load(clone) assert manifest.variant_id == "variant_clone_test" assert manifest.parent == source assert manifest.created_at == "2026-01-01" assert isinstance(manifest.genome, dict) and manifest.genome def test_genome_is_copied_verbatim_for_the_coder_to_edit(tmp_path): source = _first_living_source() src_genome = VariantManifest.load(REPO_ROOT / "variants" / source).genome spawn.scaffold(source, "variant_clone_test", variants_dir=tmp_path, today="2026-01-01") # Genome is cloned unchanged on purpose — the coder applies the plan's single gene edit on top. assert VariantManifest.load(tmp_path / "variant_clone_test").genome == src_genome def test_refuses_to_overwrite_existing_target(tmp_path): source = _first_living_source() (tmp_path / "already_here").mkdir() with pytest.raises(SystemExit): spawn.scaffold(source, "already_here", variants_dir=tmp_path) def test_unknown_source_fails_loudly(tmp_path): with pytest.raises(SystemExit): spawn.scaffold("variant_does_not_exist", "variant_clone_test", variants_dir=tmp_path)