Skip to content

Instantly share code, notes, and snippets.

@jasonLaster
Last active July 14, 2026 02:08
Show Gist options
  • Select an option

  • Save jasonLaster/4906c741bed2fe50632a24155b29e0e6 to your computer and use it in GitHub Desktop.

Select an option

Save jasonLaster/4906c741bed2fe50632a24155b29e0e6 to your computer and use it in GitHub Desktop.
Mechanical refactor transform: mirror core tests
#!/usr/bin/env python3
"""Reproduce the core test layout moves."""
import sys
from pathlib import Path
sys.path.append(".claude/skills/mechanical-refactor-verify")
from mechanical_refactor_verify_utils import git_add_and_commit, verify_mechanical_refactor
BASE_COMMIT = "23eb002571d220f3d06150d2fcdc4a727c4383a3"
TARGET_COMMIT = "fc096646f8873a7d756a5bf709460cf546a010a7"
def _replace(path: Path, old: str, new: str) -> None:
content = path.read_text()
updated = content.replace(old, new)
if updated == content:
raise RuntimeError(f"replacement not found in {path}: {old!r}")
path.write_text(updated)
def transform(dir_root: Path) -> None:
"""Move core tests and update path-sensitive references."""
moves = {
"autonomy/tests/test_circular_imports.py": "autonomy/tests/utils/test_circular_imports.py",
"autonomy/tests/test_convert_to_sft.py": "autonomy/tests/data/rl/distill/test_convert_to_sft.py",
"autonomy/tests/test_data_config.py": "autonomy/tests/dataloaders/test_data_config.py",
"autonomy/tests/test_data_mixture_source.py": "autonomy/tests/dataloaders/test_data_mixture_source.py",
"autonomy/tests/test_dedupe_embeddings.py": "autonomy/tests/data/rl/dedupe/test_dedupe_embeddings.py",
"autonomy/tests/test_filter_distilled.py": "autonomy/tests/data/rl/distill/test_filter_distilled.py",
"autonomy/tests/test_image_utils.py": "autonomy/tests/utils/test_image_utils.py",
"autonomy/tests/test_import_linter_sync.py": "autonomy/tests/scripts/test_import_linter_sync.py",
"autonomy/tests/test_model_registration.py": "autonomy/tests/models/test_model_registration.py",
"autonomy/tests/test_oss_adapter.py": "autonomy/tests/models/oss/test_adapter.py",
"autonomy/tests/test_reward.py": "autonomy/tests/utils/test_reward_postprocessing.py",
"autonomy/tests/test_s3_utils.py": "autonomy/tests/utils/test_s3_utils.py",
"autonomy/tests/test_standalone_imports.py": "autonomy/tests/utils/coding_utils/test_standalone_imports.py",
"autonomy/tests/test_types.py": "autonomy/tests/utils/test_slime_args_model.py",
"autonomy/tests/test_wandb_pytest_guard.py": "autonomy/tests/loggings/test_wandb_pytest_guard.py",
}
for source_name, target_name in moves.items():
source = dir_root / source_name
target = dir_root / target_name
target.parent.mkdir(parents=True, exist_ok=True)
source.rename(target)
_replace(
dir_root / "autonomy/tests/data/rl/dedupe/test_dedupe_embeddings.py",
"slime_root = Path(__file__).parent.parent.parent.parent",
"slime_root = Path(__file__).parent.parent.parent.parent.parent.parent.parent",
)
for name in ("PYPROJECT", "PACKAGES_ROOT"):
_replace(
dir_root / "autonomy/tests/scripts/test_import_linter_sync.py",
f'{name} = Path(__file__).resolve().parent.parent /',
f'{name} = Path(__file__).resolve().parent.parent.parent /',
)
_replace(
dir_root / "autonomy/tests/utils/coding_utils/test_standalone_imports.py",
'Path(__file__).parent.parent / "utils" / "coding_utils" / "standalone"',
'Path(__file__).resolve().parents[3] / "utils" / "coding_utils" / "standalone"',
)
_replace(
dir_root / "autonomy/pyproject.toml",
"autonomy/tests/test_import_linter_sync.py",
"autonomy/tests/scripts/test_import_linter_sync.py",
)
for relative_path in ("autonomy/README_CLAUDE.md", "autonomy/tests/run_tests.sh"):
_replace(
dir_root / relative_path,
"autonomy/tests/test_reward.py",
"autonomy/tests/utils/test_reward_postprocessing.py",
)
readme = dir_root / "autonomy/README_CLAUDE.md"
replacements = {
"│ ├── test_dedupe_embeddings.py #": (
"│ ├── data/rl/dedupe/test_dedupe_embeddings.py #"
),
"│ ├── test_types.py #": "│ ├── utils/test_slime_args_model.py #",
"│ ├── test_reward.py": "│ ├── utils/test_reward_postprocessing.py",
"[test_reward.py](tests/test_reward.py)": (
"[test_reward_postprocessing.py](tests/utils/test_reward_postprocessing.py)"
),
"[tests/test_filter_distilled.py](tests/test_filter_distilled.py)": (
"[test_filter_distilled.py](tests/data/rl/distill/test_filter_distilled.py)"
),
"[tests/test_verify_distilled.py](tests/test_verify_distilled.py)": (
"[test_verify_distilled.py](tests/data/rl/distill/test_verify_distilled.py)"
),
"[tests/test_convert_to_sft.py](tests/test_convert_to_sft.py)": (
"[test_convert_to_sft.py](tests/data/rl/distill/test_convert_to_sft.py)"
),
"[test_dedupe_embeddings.py](tests/test_dedupe_embeddings.py)": (
"[test_dedupe_embeddings.py](tests/data/rl/dedupe/test_dedupe_embeddings.py)"
),
"[test_filter_distilled.py](tests/test_filter_distilled.py)": (
"[test_filter_distilled.py](tests/data/rl/distill/test_filter_distilled.py)"
),
"[test_verify_distilled.py](tests/test_verify_distilled.py)": (
"[test_verify_distilled.py](tests/data/rl/distill/test_verify_distilled.py)"
),
"[test_types.py](tests/test_types.py)": (
"[test_slime_args_model.py](tests/utils/test_slime_args_model.py)"
),
}
for old, new in replacements.items():
_replace(readme, old, new)
for stale_line in (
"- [test_oss_trajectory.py](tests/test_oss_trajectory.py) - OSSTrajectory message parsing tests:\n",
" - Nova Act SDK observation parsing (type 1=text, type 2=image)\n",
" - Context-aware extraction (first observation vs subsequent observations)\n",
" - Robust marker detection with quoted text handling\n",
):
_replace(readme, stale_line, "")
git_add_and_commit("[tests] refactor: mirror core test layout", cwd=str(dir_root))
if __name__ == "__main__":
verify_mechanical_refactor(
base_commit=BASE_COMMIT,
target_commit=TARGET_COMMIT,
transform=transform,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment