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
11 changes: 9 additions & 2 deletions devops/vast/self_destruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,15 @@ def push_results(
for i in range(1, attempts + 1):
fetched = _run(["git", "fetch", "origin", branch], cwd=repo)
if fetched.returncode == 0:
# Rebase our disjoint per-run folder onto the current branch tip.
rebased = _run(["git", "rebase", "--autostash", "FETCH_HEAD"], cwd=repo)
# Replay only the tip results commit onto the current branch tip.
# Boxes often train from merge commits (merged PRs); rebasing the
# full history onto the orphan `results` branch fails trying to
# recreate those merges. Per-run folders are disjoint, so only the
# tip commit needs to move.
rebased = _run(
["git", "rebase", "--autostash", "--onto", "FETCH_HEAD", "HEAD~1"],
cwd=repo,
)
if rebased.returncode != 0:
_run(["git", "rebase", "--abort"], cwd=repo)
_log(f"rebase failed (attempt {i}): {rebased.stderr.strip()}", log)
Expand Down
27 changes: 27 additions & 0 deletions tests/test_infra_safeguards.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,33 @@ def fake_run(args, cwd=None):
) in calls


def test_self_destruct_rebases_only_tip_results_commit(tmp_path, monkeypatch):
calls = []

def fake_run(args, cwd=None):
calls.append(args)
if args[:3] == ["git", "diff", "--cached"]:
return SimpleNamespace(returncode=1, stdout="", stderr="")
return SimpleNamespace(returncode=0, stdout="", stderr="")

monkeypatch.setattr("devops.vast.self_destruct._run", fake_run)

assert push_results(
branch="results",
run_name="test",
instance_id="1",
repo=tmp_path,
)
assert [
"git",
"rebase",
"--autostash",
"--onto",
"FETCH_HEAD",
"HEAD~1",
] in calls


def test_failed_results_push_preserves_box_for_recovery(tmp_path, monkeypatch):
messages = []
destroyed = []
Expand Down