Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save jasonLaster/ebd04cb28ce6f9df4c8c704fba400e5a to your computer and use it in GitHub Desktop.
Mechanical refactor transform: mirror autonomy test layout
#!/usr/bin/env python3
"""Reproduce the F-X1-1 autonomy test layout cleanup.
Run from the repo root: python3 /tmp/transform_autonomy_test_layout.py
"""
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 = "9bfa2e4e4e38465cd7d5aae77c4a3f0a9889e459"
TARGET_COMMIT = "6593af78182bf0e8df4973b6749401bdda4d0ce1"
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 _move(dir_root: Path, source_name: str, target_name: str) -> None:
source = dir_root / source_name
target = dir_root / target_name
target.parent.mkdir(parents=True, exist_ok=True)
source.rename(target)
def _logging_tests(dir_root: Path) -> None:
target_name = "autonomy/tests/loggings/test_rollout_metrics.py"
_move(dir_root, "autonomy/tests/test_rollout_logging.py", target_name)
_replace(
dir_root / target_name,
"autonomy.tests.test_rollout_logging.reference_rollout_metric_reward",
"autonomy.tests.loggings.test_rollout_metrics.reference_rollout_metric_reward",
)
_replace(
dir_root / "autonomy/README_CLAUDE.md",
"[test_rollout_logging.py](tests/test_rollout_logging.py)",
"[test_rollout_metrics.py](tests/loggings/test_rollout_metrics.py)",
)
git_add_and_commit("[tests, logging] refactor: mirror rollout logging tests", cwd=str(dir_root))
def _async_rollout_tests(dir_root: Path) -> None:
for test_name in (
"test_distributed_rollout.py",
"test_fully_async_rollout.py",
"test_generate_interface.py",
"test_strands_distributed_rollout.py",
):
_move(
dir_root,
f"autonomy/tests/{test_name}",
f"autonomy/tests/rollouts/{test_name}",
)
readme = dir_root / "autonomy/README_CLAUDE.md"
_replace(
readme,
"│ ├── test_generate_interface.py",
"│ ├── rollouts/test_generate_interface.py",
)
_replace(
readme,
"│ ├── test_distributed_rollout.py",
"│ ├── rollouts/test_distributed_rollout.py",
)
for test_name in (
"test_distributed_rollout.py",
"test_fully_async_rollout.py",
"test_generate_interface.py",
):
_replace(
readme,
f"tests/{test_name}",
f"tests/rollouts/{test_name}",
)
git_add_and_commit("[tests, rollout] refactor: mirror async rollout tests", cwd=str(dir_root))
def _multi_turn_tests(dir_root: Path) -> None:
moves = {
"autonomy/tests/test_rollout.py": "autonomy/tests/rollouts/test_multi_turn_vlm.py",
"autonomy/tests/test_nova_act_prompt_golden.py": (
"autonomy/tests/rollouts/test_nova_act_prompt_golden.py"
),
"autonomy/tests/test_total_generation_length.py": (
"autonomy/tests/rollouts/test_total_generation_length.py"
),
"autonomy/tests/fake_env.py": "autonomy/tests/fixtures/fake_env.py",
}
for source_name, target_name in moves.items():
_move(dir_root, source_name, target_name)
for relative_path in (
"autonomy/tests/rollouts/test_multi_turn_vlm.py",
"autonomy/tests/rollouts/test_nova_act_prompt_golden.py",
):
_replace(
dir_root / relative_path,
"autonomy.tests.fake_env",
"autonomy.tests.fixtures.fake_env",
)
for relative_path in ("autonomy/runbook.md", "autonomy/README_CLAUDE.md"):
_replace(
dir_root / relative_path,
"autonomy/tests/test_rollout.py",
"autonomy/tests/rollouts/test_multi_turn_vlm.py",
)
readme = dir_root / "autonomy/README_CLAUDE.md"
replacements = {
"│ ├── test_rollout.py": "│ ├── rollouts/test_multi_turn_vlm.py",
"│ ├── fake_env.py": "│ ├── fixtures/fake_env.py",
"[test_rollout.py](tests/test_rollout.py)": (
"[test_multi_turn_vlm.py](tests/rollouts/test_multi_turn_vlm.py)"
),
"[fake_env.py](tests/fake_env.py)": (
"[fake_env.py](tests/fixtures/fake_env.py)"
),
}
for old, new in replacements.items():
_replace(readme, old, new)
_replace(
dir_root / "autonomy/tests/run_tests.sh",
"autonomy/tests/test_rollout.py",
"autonomy/tests/rollouts/test_multi_turn_vlm.py",
)
git_add_and_commit("[tests, rollout] refactor: mirror multi-turn rollout tests", cwd=str(dir_root))
def _agent_trainer_tests(dir_root: Path) -> None:
_move(
dir_root,
"autonomy/tests/test_strands_rollout.py",
"autonomy/tests/rollouts/test_agent_rollout.py",
)
trainers_dir = dir_root / "autonomy/tests/trainers"
(trainers_dir / "__init__.py").write_text("\n")
for test_name in (
"test_distill_only.py",
"test_reloadable_process_group.py",
"test_train_dispose_try_finally.py",
):
_move(
dir_root,
f"autonomy/tests/{test_name}",
f"autonomy/tests/trainers/{test_name}",
)
_replace(trainers_dir / "test_distill_only.py", "parents[2]", "parents[3]")
_replace(
trainers_dir / "test_train_dispose_try_finally.py",
"autonomy.tests.test_distill_only",
"autonomy.tests.trainers.test_distill_only",
)
_replace(
trainers_dir / "test_train_dispose_try_finally.py",
"parents[2]",
"parents[3]",
)
readme = dir_root / "autonomy/README_CLAUDE.md"
_replace(
readme,
"│ ├── test_strands_rollout.py # Strands rollout integration tests with typed interface",
"│ ├── rollouts/test_agent_rollout.py # Agent rollout integration tests with typed interface",
)
_replace(
readme,
"[test_strands_rollout.py](tests/test_strands_rollout.py) - Strands rollout integration",
"[test_agent_rollout.py](tests/rollouts/test_agent_rollout.py) - Agent rollout integration",
)
git_add_and_commit(
"[tests, rollout, trainer] refactor: mirror agent and trainer tests",
cwd=str(dir_root),
)
def _environment_tests(dir_root: Path) -> None:
moves = {
"autonomy/tests/test_podman_provider.py": "autonomy/tests/env_providers/test_podman_provider.py",
"autonomy/tests/math_verifier_report.txt": "autonomy/tests/envs/math_verifier_report.txt",
"autonomy/tests/math_verifier_test_data.json": "autonomy/tests/envs/math_verifier_test_data.json",
"autonomy/tests/test_pydantic_typing.py": "autonomy/tests/envs/test_coding_metadata_validation.py",
"autonomy/tests/test_harbor_env.py": "autonomy/tests/envs/test_harbor_env.py",
"autonomy/tests/test_math_verifier.py": "autonomy/tests/envs/test_math_env.py",
"autonomy/tests/test_nova_act_env.py": "autonomy/tests/envs/test_nova_act_env_pool.py",
"autonomy/tests/test_oss_nova_act_env.py": "autonomy/tests/envs/test_oss_nova_act_env.py",
"autonomy/tests/test_parsing_assertions.py": "autonomy/tests/envs/test_oss_nova_act_parsing.py",
"autonomy/tests/test_verifier_env_dispatch.py": "autonomy/tests/envs/test_verifier_env_dispatch.py",
"autonomy/tests/test_verifier_utils.py": "autonomy/tests/envs/test_verifier_utils.py",
"autonomy/tests/local_provider.py": "autonomy/tests/fixtures/local_provider.py",
}
for source_name, target_name in moves.items():
_move(dir_root, source_name, target_name)
local_provider_import = "from autonomy.tests.local_provider import LocalProvider"
fixture_provider_import = "from autonomy.tests.fixtures.local_provider import LocalProvider"
for relative_path in (
"autonomy/README_CLAUDE.md",
"autonomy/tests/env_providers/test_service_endpoints.py",
"autonomy/tests/envs/test_coding_metadata_validation.py",
"autonomy/tests/envs/test_verifier_utils.py",
"autonomy/tests/fixtures/local_provider.py",
"autonomy/tests/utils/test_code_verifier.py",
"autonomy/tests/utils/test_code_verifier_sample.py",
):
_replace(dir_root / relative_path, local_provider_import, fixture_provider_import)
for relative_path in (
"autonomy/tests/envs/test_coding_metadata_validation.py",
"autonomy/tests/envs/test_verifier_utils.py",
):
_replace(
dir_root / relative_path,
(
"from autonomy.tests.fixtures.verify import verify_via_env\n"
"from autonomy.tests.fixtures.local_provider import LocalProvider"
),
(
"from autonomy.tests.fixtures.local_provider import LocalProvider\n"
"from autonomy.tests.fixtures.verify import verify_via_env"
),
)
for relative_path in (
"autonomy/tests/envs/test_coding_metadata_validation.py",
"autonomy/tests/envs/test_math_env.py",
"autonomy/tests/envs/test_verifier_utils.py",
):
_replace(
dir_root / relative_path,
"slime_root = Path(__file__).parent.parent.parent.parent",
"slime_root = Path(__file__).parent.parent.parent.parent.parent",
)
_replace(
dir_root / "autonomy/tests/envs/test_harbor_env.py",
"autonomy/tests/test_harbor_env.py",
"autonomy/tests/envs/test_harbor_env.py",
)
_replace(
dir_root / "autonomy/tests/fixtures/local_provider.py",
"intentionally placed in autonomy/tests/ to prevent",
"intentionally placed in autonomy/tests/fixtures/ to prevent",
)
_replace(
dir_root / "autonomy/tests/run_tests.sh",
"autonomy/tests/test_verifier_utils.py",
"autonomy/tests/envs/test_verifier_utils.py",
)
_replace(
dir_root / "autonomy/tests/envs/test_math_env.py",
'report_path = Path("./math_verifier_report.txt")',
'report_path = Path(__file__).parent / "math_verifier_report.txt"',
)
readme = dir_root / "autonomy/README_CLAUDE.md"
replacements = {
"│ ├── local_provider.py #": "│ ├── fixtures/local_provider.py #",
"│ ├── test_math_verifier.py": "│ ├── envs/test_math_env.py",
"│ ├── test_verifier_utils.py #": "│ ├── envs/test_verifier_utils.py #",
"[test_math_verifier.py](tests/test_math_verifier.py)": (
"[test_math_env.py](tests/envs/test_math_env.py)"
),
"`AutoGrader_API_Key` for live tests": "`OPENROUTER_API_KEY` for live tests",
"[test_code_verifier.py](tests/test_code_verifier.py)": (
"[test_code_verifier.py](tests/utils/test_code_verifier.py)"
),
"[code_verifier_test_data.json](tests/code_verifier_test_data.json)": (
"[code_verifier_test_data.json](tests/utils/code_verifier_test_data.json)"
),
"[test_code_verifier_sample.py](tests/test_code_verifier_sample.py)": (
"[test_code_verifier_sample.py](tests/utils/test_code_verifier_sample.py)"
),
"[test_verifier_utils.py](tests/test_verifier_utils.py)": (
"[test_verifier_utils.py](tests/envs/test_verifier_utils.py)"
),
"[tests/local_provider.py](tests/local_provider.py)": (
"[tests/fixtures/local_provider.py](tests/fixtures/local_provider.py)"
),
"placed in `autonomy/tests/` to prevent": (
"placed in `autonomy/tests/fixtures/` to prevent"
),
}
for old, new in replacements.items():
_replace(readme, old, new)
git_add_and_commit("[tests, env] refactor: mirror environment tests", cwd=str(dir_root))
def _core_tests(dir_root: Path) -> None:
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():
_move(dir_root, source_name, target_name)
_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))
def _launcher_ci_tests(dir_root: Path) -> None:
_move(
dir_root,
"autonomy/tests/test_launcher.py",
"autonomy/tests/launcher/test_launcher.py",
)
_move(
dir_root,
"autonomy/tests/test_autonomy_image_tests_workflow.py",
"autonomy/tests/scripts/ci/test_autonomy_image_tests_workflow.py",
)
_replace(
dir_root / "autonomy/tests/scripts/ci/test_autonomy_image_tests_workflow.py",
"REPO_ROOT = Path(__file__).resolve().parents[2]",
"REPO_ROOT = Path(__file__).resolve().parents[4]",
)
_replace(
dir_root / "autonomy/README_CLAUDE.md",
"│ ├── test_launcher.py #",
"│ ├── launcher/test_launcher.py #",
)
_replace(
dir_root / "autonomy/README_CLAUDE.md",
"[test_launcher.py](tests/test_launcher.py)",
"[test_launcher.py](tests/launcher/test_launcher.py)",
)
_replace(
dir_root / ".claude/skills/gpu-ci/SKILL.md",
"autonomy/tests/test_autonomy_image_tests_workflow.py",
"autonomy/tests/scripts/ci/test_autonomy_image_tests_workflow.py",
)
git_add_and_commit("[tests, ci] refactor: mirror launcher and workflow tests", cwd=str(dir_root))
def _package_support_tests(dir_root: Path) -> None:
_move(
dir_root,
"autonomy/tests/test_container_utils.py",
"autonomy/tests/utils/test_container_utils.py",
)
_move(
dir_root,
"autonomy/tests/test_package_dist_names.py",
"autonomy/tests/packages/test_dist_names.py",
)
(dir_root / "autonomy/tests/packages/__init__.py").write_text("\n")
_replace(
dir_root / "autonomy/tests/packages/test_dist_names.py",
'PACKAGES_ROOT = Path(__file__).resolve().parent.parent / "packages"',
'PACKAGES_ROOT = Path(__file__).resolve().parent.parent.parent / "packages"',
)
for relative_path in (
".claude/skills/add-subpackage/SKILL.md",
"autonomy/packages/public/README.md",
"autonomy/packages/public/circuit_client/README.md",
):
_replace(
dir_root / relative_path,
"autonomy/tests/test_package_dist_names.py",
"autonomy/tests/packages/test_dist_names.py",
)
_replace(
dir_root / "autonomy/packages/internal/gym_proxy/tests/test_proxy_integration.py",
"autonomy/tests/\ntest_container_utils.py",
"autonomy/tests/utils/\ntest_container_utils.py",
)
_replace(
dir_root / ".github/CODEOWNERS",
"/autonomy/packages/ @GymPod/SlimeCodeowners @GymPod/NextAct\n",
(
"/autonomy/packages/ @GymPod/SlimeCodeowners @GymPod/NextAct\n"
"/autonomy/tests/packages/ @GymPod/SlimeCodeowners @GymPod/NextAct\n"
),
)
_replace(
dir_root / "autonomy/packages/internal/circuit_internal/ARCHITECTURE.md",
(
"`autonomy/tests/test_package_isolation.py` enforces the autonomy boundary\n"
"mechanically. The `slime.*` / `strands.*` boundary is enforced by code\n"
"review and grep. If you find yourself wanting to import either inside this\n"
"package, the work belongs in the wrapper instead — see\n"
),
(
"The import-linter contracts in `autonomy/pyproject.toml` enforce the autonomy\n"
"boundary mechanically, with\n"
"`autonomy/tests/scripts/test_import_linter_sync.py` keeping the package list in\n"
"sync. The `slime.*` / `strands.*` boundary is enforced by code review and grep.\n"
"If you find yourself wanting to import either inside this package, the work\n"
"belongs in the wrapper instead — see\n"
),
)
git_add_and_commit("[tests, packages] refactor: mirror package support tests", cwd=str(dir_root))
def _sft_tool_use_test(dir_root: Path) -> None:
_move(
dir_root,
"autonomy/tests/test_sft_tooluse.py",
"autonomy/tests/data/sft/tooluse/test_build_sft_tooluse.py",
)
readme = dir_root / "autonomy/README_CLAUDE.md"
_replace(
readme,
"tests/test_sft_tooluse.py",
"tests/data/sft/tooluse/test_build_sft_tooluse.py",
)
_replace(readme, "[test_sft_tooluse.py]", "[test_build_sft_tooluse.py]")
git_add_and_commit("[tests, data] refactor: mirror SFT tool-use test", cwd=str(dir_root))
def _review_followup(dir_root: Path) -> None:
_replace(
dir_root / ".claude/skills/add-subpackage/SKILL.md",
"test_package_dist_names.py enforces",
"test_dist_names.py enforces",
)
git_add_and_commit(
"[tests, packages] docs: update mirrored test reference",
cwd=str(dir_root),
)
def _package_marker_followup(dir_root: Path) -> None:
for relative_path in (
"autonomy/tests/data/sft/__init__.py",
"autonomy/tests/data/sft/tooluse/__init__.py",
"autonomy/tests/models/oss/__init__.py",
):
(dir_root / relative_path).write_text("\n")
git_add_and_commit(
"[tests] chore: add mirrored test package markers",
cwd=str(dir_root),
)
def transform(dir_root: Path) -> None:
"""Apply the nine atomic F-X1-1 slices and review follow-ups."""
_logging_tests(dir_root)
_async_rollout_tests(dir_root)
_multi_turn_tests(dir_root)
_agent_trainer_tests(dir_root)
_environment_tests(dir_root)
_core_tests(dir_root)
_launcher_ci_tests(dir_root)
_package_support_tests(dir_root)
_sft_tool_use_test(dir_root)
_review_followup(dir_root)
_package_marker_followup(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