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/reproduction_utils/test_delete_file.py

scripts/tests/reproduction_utils/test_delete_file.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])) import mechanical_refactor_reproduction_utils as rrfrom mechanical_refactor_reproduction_utils import (    Repro,    _def_span,    _find_class,    _find_def,    _replace_span,    _slice_span,    dedent,    exec_command,    git_add_and_commit,    verify_mechanical_refactor,)from reproduction_testlib import _apply, _commit, _git, _write  # noqa: F401  def test_delete_file_removes_emptied_source(tmp_path: Path) -> None:    """delete_file removes a source module left empty after its defs relocated."""    (tmp_path / "gone.py").write_text("import os\n")    r = Repro("b", "t").delete_file("gone.py")    _apply(r, tmp_path)    assert not (tmp_path / "gone.py").exists()  def test_delete_file_refuses_a_file_with_remaining_definitions(tmp_path: Path) -> None:    """Deleting a module that still contains defs must fail loudly."""    (tmp_path / "live.py").write_text("def still_used():\n    return 42\n")    r = Repro("b", "t").delete_file("live.py")    with pytest.raises(AssertionError):        _apply(r, tmp_path)    assert (tmp_path / "live.py").exists()  def test_delete_file_on_a_missing_path_is_a_no_op(tmp_path: Path) -> None:    """Deleting an already-absent file does nothing and raises nothing."""    r = Repro("b", "t").delete_file("nope.py")    _apply(r, tmp_path)    assert not (tmp_path / "nope.py").exists()  def test_delete_file_allows_a_bare_module_logger(tmp_path: Path) -> None:    """A leftover module holding only imports and a `logger` is deletable scaffolding."""    (tmp_path / "gone.py").write_text(        "import logging\n\nlogger = logging.getLogger(__name__)\n"    )    r = Repro("b", "t").delete_file("gone.py")    _apply(r, tmp_path)    assert not (tmp_path / "gone.py").exists()  def test_delete_file_still_refuses_a_non_logger_assignment(tmp_path: Path) -> None:    """A leftover module-level assignment other than a logger blocks deletion."""    (tmp_path / "live.py").write_text("CONFIG = {'a': 1}\n")    r = Repro("b", "t").delete_file("live.py")    with pytest.raises(AssertionError):        _apply(r, tmp_path)    assert (tmp_path / "live.py").exists()  # --- adversarial audit: extract_function -----------------------------------------