scripts/tests/reproduction_cli/cli_testlib.py
scripts/tests/reproduction_cli/cli_testlib.pyBrowse 41 files
534 tokens
1,882 bytes
Token encoding: o200k_base
Snapshot a9fb1c3
← Back to SKILL.md
1import subprocess2from pathlib import Path3 4_PASSING_PROOF = (5 'import sys\nprint("PASS: reproduces the commit byte-for-byte.")\nsys.exit(0)\n'6)7_FAILING_PROOF = 'import sys\nprint("RESIDUAL (2 lines):\\n+x\\n-y")\nsys.exit(1)\n'8 9 10def _git(repo: Path, *args: str) -> str:11 return subprocess.run(12 ["git", *args], cwd=repo, check=True, capture_output=True, text=True13 ).stdout.strip()14 15 16def _write(repo: Path, **files: "str | None") -> None:17 for name, content in files.items():18 path = repo / name.replace("__", "/")19 if content is None:20 path.unlink()21 else:22 path.parent.mkdir(parents=True, exist_ok=True)23 path.write_text(content)24 25 26def _commit(repo: Path, message: str) -> str:27 _git(repo, "add", "-A")28 _git(repo, "commit", "-q", "-m", message)29 return _git(repo, "rev-parse", "HEAD")30 31 32def _chain(repo: Path, messages: "list[str]") -> "tuple[str, list[str]]":33 """A base commit plus one single-file commit per message, on a `chain` branch.34 Returns (base_sha, commit_shas)."""35 _write(repo, **{"seed.py": "SEED = 0\n"})36 base = _commit(repo, "base")37 _git(repo, "switch", "-q", "-c", "chain")38 shas: "list[str]" = []39 for i, message in enumerate(messages):40 _write(repo, **{f"file_{i}.py": f"VALUE = {i}\n"})41 shas.append(_commit(repo, message))42 return base, shas43 44 45def _write_stub_proof(46 proof_dir: Path,47 sha: str,48 *,49 passing: bool = True,50 flat: bool = False,51 stem_len: int = 9,52) -> Path:53 """A stand-in proof script printing the arbiter's verdict line and exiting to match."""54 directory = proof_dir if flat else proof_dir / "repro_scripts"55 directory.mkdir(parents=True, exist_ok=True)56 path = directory / f"{sha[:stem_len]}.py"57 path.write_text(_PASSING_PROOF if passing else _FAILING_PROOF)58 return path59