mechanical-refactor-verify

Make mechanical refactoring (file splits, function moves, module extractions, renames) machine-checkable instead of eyeballed. Reproduce a relocation commit byte-for-byte from faithful primitives, and split an extraction into a verifiable prepare + move + postpare. Use when doing or reviewing such changes.

Install
npx skills add 'https://github.com/sgl-project/sglang/tree/main/.claude/skills/mechanical-refactor-verify'
Download bundle ↓
main · a9fb1c3Scanned 2026-09-17

Contributors

GitHub-linked commit authors for this SKILL.md at the saved revision. Co-authors and history before file renames are not included.

File history ↗

scripts/tests/proof_generator/generator_testlib.py

scripts/tests/proof_generator/generator_testlib.pyBrowse 41 files
View on GitHub
← Back to SKILL.md
import subprocessimport sysfrom pathlib import Path import pytest sys.path.insert(0, str(Path(__file__).resolve().parents[2])) from mechanical_refactor_proof_generator import (    infer_recipe,    recipe_to_script,)  def _git(repo: Path, *args: str) -> str:    return subprocess.run(        ["git", *args], cwd=repo, check=True, capture_output=True, text=True    ).stdout.strip()  def _write(repo: Path, **files: str | None) -> None:    for name, content in files.items():        path = repo / name.replace("__", "/")        if content is None:            path.unlink()        else:            path.parent.mkdir(parents=True, exist_ok=True)            path.write_text(content)  def _commit(repo: Path, message: str) -> str:    _git(repo, "add", "-A")    _git(repo, "commit", "-q", "-m", message)    return _git(repo, "rev-parse", "HEAD")  def _method_onto_class(repo: Path) -> None:    """Stage a base + a 'move foo from M onto C, lower the caller' commit."""    _write(        repo,        **{            "model.py": (                "class M:\n"                "    @staticmethod\n"                "    def foo(self, x):\n"                "        return x + 1\n"                "\n"                "    def other(self):\n"                "        return 0\n"            ),            "comp.py": "class C:\n    def keep(self):\n        return 1\n",            "caller.py": (                "class K:\n"                "    def run(self):\n"                "        from model import M\n"                "\n"                "        return M.foo(self.c, 9)\n"            ),        },    )    _commit(repo, "base")    _write(        repo,        **{            "model.py": "class M:\n    def other(self):\n        return 0\n",            "comp.py": (                "class C:\n"                "    def keep(self):\n"                "        return 1\n"                "\n"                "    def foo(self, x):\n"                "        return x + 1\n"            ),            "caller.py": (                "class K:\n    def run(self):\n        return self.c.foo(9)\n"            ),        },    )    _commit(repo, "move foo onto C")  def _free_function_move_with_module_level_caller(repo: Path) -> None:    """Stage a free function moved model.py -> util.py whose caller imports it at module    level (so the repoint shows up in the symmetric module-level import diff)."""    _write(        repo,        **{            "model.py": "def keep():\n    return 0\n\n\ndef resolve(m):\n    return m\n",            "util.py": "import os\n",            "caller.py": (                "from model import resolve\n\n\ndef run(m):\n    return resolve(m)\n"            ),        },    )    _commit(repo, "base")    _write(        repo,        **{            "model.py": "def keep():\n    return 0\n",            "util.py": "import os\n\n\ndef resolve(m):\n    return m\n",            "caller.py": (                "from util import resolve\n\n\ndef run(m):\n    return resolve(m)\n"            ),        },    )    _commit(repo, "move resolve to util")