The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): distinguish early fork sync from pending branch repair
funky-xamarin593eaf6c0766
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex c60f337f4f9..bf2091a7278 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -845,6 +845,20 @@ def _rollback_if_pulled_syntax_error(git_cmd, pre_pull_sha, *, rollback_branch=Nsys.exit(1)+def _update_movement_baseline(git_cmd, pre_pull_sha, pre_sync_sha, rollback_branch, target_sha):+ """Distinguish a branch awaiting repair from an already-applied early sync."""+ if rollback_branch is not None and pre_pull_sha and target_sha:+ # A target already contained in the branch cannot advance it. In that+ # case checkout/early sync supplied the movement, even if pushing the+ # sync back to origin failed. Otherwise verify the pending repair from+ # the stale/diverged branch tip, not the original detached checkout.+ contains_target = _git_run(+ git_cmd, ["merge-base", "--is-ancestor", target_sha, pre_pull_sha])+ if contains_target.returncode == 1:+ return pre_pull_sha+ return pre_sync_sha or pre_pull_sha++def _pull_updates(git_cmd, branch, auto_stash_ref, *, prompt_for_restore, gw_input_fn, discard_local_changes,keep_stash, target_ref=None, pre_sync_sha=None, rollback_branch=None, sync_upstream=False, assume_yes=False,@@ -863,14 +877,8 @@ def _pull_updates(# A release update moves the tree to its tag, not the branch tip: the marker names what git writes.merge_ref = target_ref if target_ref is not None else f"origin/{branch}"target_sha = (_git_run(git_cmd, ["rev-parse", f"{merge_ref}^{{commit}}"]).stdout or "").strip()- movement_baseline = pre_sync_sha or pre_pull_sha- if rollback_branch is not None and pre_pull_sha != target_sha:- # The switched-to branch still needs repair. Verify movement from its- # immediate tip through both origin and optional upstream sync; the- # final upstream tip may legitimately equal the original detached SHA.- # Keep the original SHA separately for syntax rollback. If checkout- # already landed at the target, it remains the movement being verified.- movement_baseline = pre_pull_sha+ movement_baseline = _update_movement_baseline(+ git_cmd, pre_pull_sha, pre_sync_sha, rollback_branch, target_sha)with _best_effort('Could not write the interrupted-pull marker: %s'):pull_marker.write_text(f"pid={os.getpid()}\npre={pre_pull_sha}\ntarget={target_sha}\nstash={auto_stash_ref or ''}\n",@@ -1333,10 +1341,8 @@ def _apply_pulled_update(movement_baseline = _plan.pre_sync_sha or pre_pull_shaif getattr(_plan, "rollback_branch", None) is not None:target_sha = (_git_run(git_cmd, ["rev-parse", f"origin/{branch}^{{commit}}"]).stdout or "").strip()- if pre_pull_sha != target_sha:- # Preserve the repair baseline used by _pull_updates, including a- # fork sync that returned to the original detached checkout SHA.- movement_baseline = pre_pull_sha+ movement_baseline = _update_movement_baseline(+ git_cmd, pre_pull_sha, _plan.pre_sync_sha, _plan.rollback_branch, target_sha)post_pull_sha = _verify_head_after_pull(git_cmd, branch, movement_baseline, in_place_update=_plan.in_place_update,_windows_gateway_resume=_windows_gateway_resume)diff --git a/tests/hermes_cli/test_update_existing_branch_baseline.py b/tests/hermes_cli/test_update_existing_branch_baseline.pyindex 4ce770cd2bf..3298cc50c8b 100644--- a/tests/hermes_cli/test_update_existing_branch_baseline.py+++ b/tests/hermes_cli/test_update_existing_branch_baseline.py@@ -33,10 +33,10 @@ def checkout(tmp_path, monkeypatch):return root, old, tip-def prepare(root):+def prepare(root, *, is_fork=False):return update_cmd._prepare_checkout_for_update(["git"], "main", update_cmd._current_branch_name(["git"], check=True),- is_fork=False, assume_yes=True, gateway_mode=False, gw_input_fn=None,+ is_fork=is_fork, assume_yes=True, gateway_mode=False, gw_input_fn=None,switch_branch=False, _windows_gateway_resume=None,)@@ -161,6 +161,41 @@ def test_fork_sync_after_stale_branch_repair(checkout, monkeypatch, upstream_resassert git(root, "rev-parse", "--abbrev-ref", "HEAD") == "main"+def test_early_fork_sync_without_push_still_completes(checkout, monkeypatch):+ root, old, tip = checkout+ git(root, "checkout", "-q", "main")+ git(root, "commit", "--allow-empty", "-qm", "upstream")+ upstream_tip = git(root, "rev-parse", "HEAD")+ git(root, "checkout", "-q", "--detach", tip)+ git(root, "branch", "-f", "main", tip)++ def sync(*args, **kwargs):+ git(root, "merge", "--ff-only", upstream_tip)+ # Successful local sync need not push the new SHA to origin.+ return True++ monkeypatch.setattr(update_cmd._m(), "_sync_with_upstream_if_needed", sync)+ plan = prepare(root, is_fork=True)+ assert plan.upstream_checked+ assert git(root, "rev-parse", "HEAD") == upstream_tip+ assert git(root, "rev-parse", "origin/main") == tip+ before_pull = update_cmd._pull_updates(+ ["git"], "main", plan.auto_stash_ref, prompt_for_restore=False,+ gw_input_fn=None, discard_local_changes=False, keep_stash=False,+ pre_sync_sha=plan.pre_sync_sha, rollback_branch=plan.rollback_branch,+ sync_upstream=True,+ )+ completed = []+ monkeypatch.setattr(update_cmd, "_complete_source_update", completed.append)+ request = {}+ update_cmd._apply_pulled_update(+ ["git"], "main", before_pull, plan,+ _windows_gateway_resume=None, completion_request=request,+ )+ assert completed == [request]+ assert request["expected_sha"] == upstream_tip++def test_command_hands_off_after_existing_main_switch(update_tree, monkeypatch, capsys):t = update_treemonkeypatch.setattr("hermes_cli.update_owning_install.retarget_to_owning_install", lambda *_: None)