Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from pathlib import Path


def exec_command(cmd: str, cwd: str | None = None, check: bool = True) -> str:
print(f" $ {cmd}", flush=True)
def exec_command(cmd: list[str], cwd: str | None = None, check: bool = True) -> str:
print(f" $ {' '.join(shlex.quote(c) for c in cmd)}", flush=True)
result = subprocess.run(
cmd,
shell=True,
shell=False,
cwd=cwd,
capture_output=True,
text=True,
Expand All @@ -27,7 +27,8 @@ def exec_command(cmd: str, cwd: str | None = None, check: bool = True) -> str:


def git_add_and_commit(message: str, cwd: str) -> None:
exec_command(f"git add -A && git commit -m {shlex.quote(message)}", cwd=cwd)
exec_command(["git", "add", "-A"], cwd=cwd)
exec_command(["git", "commit", "-m", message], cwd=cwd)


def dedent(text: str, n: int) -> str:
Expand All @@ -41,28 +42,28 @@ def verify_mechanical_refactor(
target_commit: str,
transform: "Callable[[Path], None]",
) -> None:
repo_root = exec_command("git rev-parse --show-toplevel")
repo_root = exec_command(["git", "rev-parse", "--show-toplevel"])
worktree_dir = tempfile.mkdtemp(prefix="verify-mechanical-")
branch_name = f"verify-mechanical-{base_commit[:8]}"

try:
print(f"[1/4] Creating worktree at {base_commit[:8]}...")
exec_command(
f"git worktree add -b {branch_name} {worktree_dir} {base_commit}",
["git", "worktree", "add", "-b", branch_name, worktree_dir, base_commit],
cwd=repo_root,
)

print("[2/4] Running transformation...")
transform(Path(worktree_dir))

print("[3/4] Running pre-commit...")
exec_command("pre-commit run --all-files", cwd=worktree_dir, check=False)
if exec_command("git status --porcelain", cwd=worktree_dir):
exec_command(["pre-commit", "run", "--all-files"], cwd=worktree_dir, check=False)
if exec_command(["git", "status", "--porcelain"], cwd=worktree_dir):
git_add_and_commit("pre-commit fixes", cwd=worktree_dir)

print(f"[4/4] Diffing against {target_commit[:8]}...")
diff = exec_command(
f"git diff {target_commit} -- .",
["git", "diff", target_commit, "--", "."],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

By default, git diff exits with 0 on success (regardless of whether differences exist or not) and only returns a non-zero exit code on actual errors (such as an invalid target_commit).

Using check=False here is dangerous because if git diff fails (e.g., due to a bad revision or repository error), the error is silently ignored, exec_command returns an empty string, and the script incorrectly reports a successful verification (PASS: transform reproduces the commit exactly.).

Please remove check=False (or set check=True) so that any actual git errors are caught and cause the script to fail loudly.

cwd=worktree_dir,
check=False,
)
Expand Down
2 changes: 1 addition & 1 deletion miles/backends/training_utils/ci_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def check_grad_norm(
rollout_id=rollout_id,
step_id=step_id,
)
expected_grad_norm = torch.load(ci_load_grad_norm_path, weights_only=False)
expected_grad_norm = torch.load(ci_load_grad_norm_path, weights_only=True)
assert math.isclose(
grad_norm,
expected_grad_norm,
Expand Down