Skip to content

The agent that grows with you

fix(update): a syntax rollback whose marker arm times out still rolls back

Tekniumb9d85003f8a4
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.py
index 644f68f1d2e..e94d13414df 100644
--- a/hermes_cli/update_cmd.py
+++ b/hermes_cli/update_cmd.py
@@ -941,7 +941,7 @@ def _rollback_if_pulled_syntax_error(git_cmd, pre_pull_sha, *, rollback_branch=N
target_sha = _capture_head_sha(git_cmd, root)
try:
_commit.arm_tree_move(git_cmd, root, pre=pre_pull_sha, target=target_sha, stash=None, rollback=mode)
- except OSError as exc:
+ except (OSError, subprocess.SubprocessError) as exc: # its symbolic-ref can time out
# Refusing would leave the broken tree in place: roll back unmarked, and only a tree
# verified whole at pre_pull_sha below may report success (else the manual recipe).
print(f" ⚠ Could not write the interrupted-pull marker ({exc}); rolling back without it.")
diff --git a/tests/hermes_cli/test_update_post_pull_syntax_guard.py b/tests/hermes_cli/test_update_post_pull_syntax_guard.py
index 4308c122671..c997916afb1 100644
--- a/tests/hermes_cli/test_update_post_pull_syntax_guard.py
+++ b/tests/hermes_cli/test_update_post_pull_syntax_guard.py
@@ -172,3 +172,38 @@ def test_a_python_bump_never_admits_a_conflict_marker(tmp_path, monkeypatch):
with pytest.raises(SystemExit):
update_cmd._rollback_if_pulled_syntax_error(["git"], pre)
assert git("rev-parse", "HEAD") == pre
+
+
+def test_a_marker_arm_that_times_out_still_rolls_the_broken_pull_back(tmp_path, monkeypatch, capsys):
+ """arm_tree_move's ``symbolic-ref`` can raise subprocess.TimeoutExpired; the rollback caught only
+ OSError, so a timeout aborted it before any reset and left the broken release checked out
+ (review C10). It must roll back unmarked, as for an unwritable marker."""
+ from hermes_cli import update_cmd_commit
+
+ def git(*args):
+ return subprocess.run(["git", *args], cwd=tmp_path, check=True, capture_output=True, text=True,
+ encoding="utf-8").stdout.strip()
+
+ git("init", "-b", "main")
+ git("config", "user.email", "[email protected]")
+ git("config", "user.name", "Test")
+ source = tmp_path / "hermes_constants.py"
+ source.write_text("print('runnable')\n", encoding="utf-8")
+ git("add", ".")
+ git("commit", "-m", "working")
+ previous = git("rev-parse", "HEAD")
+ source.write_text("<<<<<<< HEAD\n", encoding="utf-8")
+ git("commit", "-am", "broken upstream")
+ monkeypatch.setattr(main, "PROJECT_ROOT", tmp_path)
+
+ def times_out(*_args, **_kwargs):
+ raise subprocess.TimeoutExpired(["git", "symbolic-ref", "-q", "HEAD"], 60)
+
+ monkeypatch.setattr(update_cmd_commit, "arm_tree_move", times_out)
+ with pytest.raises(SystemExit) as failure:
+ update_cmd._rollback_if_pulled_syntax_error(["git"], previous)
+
+ assert failure.value.code == 1
+ assert "Rollback complete" in capsys.readouterr().out
+ assert git("rev-parse", "HEAD") == previous
+ assert source.read_text(encoding="utf-8") == "print('runnable')\n"