from __future__ import annotations import shutil import subprocess from pathlib import Path import pytest FIXTURES = Path(__file__).parent / "fixtures" def _git_init(repo: Path) -> None: subprocess.run(["git", "init", "-q"], cwd=repo, check=True) subprocess.run(["git", "config", "user.email", "test@example.com"], cwd=repo, check=True) subprocess.run(["git", "config", "user.name", "Test"], cwd=repo, check=True) subprocess.run(["git", "add", "-A"], cwd=repo, check=True) subprocess.run(["git", "commit", "-q", "-m", "fixture baseline"], cwd=repo, check=True) def materialize_fixture(tmp_path: Path, relative: str, *, git: bool = True) -> Path: src = FIXTURES / relative dest = tmp_path / Path(relative).name shutil.copytree(src, dest) if git: _git_init(dest) return dest @pytest.fixture def make_repo(tmp_path): def _make(relative: str, *, git: bool = True) -> Path: return materialize_fixture(tmp_path, relative, git=git) return _make @pytest.fixture def negative_repo(tmp_path): """Materialize a negative//contract.yaml fixture as ops/contract.yaml under a fresh repo.""" def _make(name: str) -> Path: dest = tmp_path / name (dest / "ops").mkdir(parents=True) shutil.copy(FIXTURES / "negative" / name / "contract.yaml", dest / "ops" / "contract.yaml") _git_init(dest) return dest return _make