The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(update): retain branch repair baseline through fork completion
funky-xamarina58fc4fa8e91
diff --git a/hermes_cli/update_cmd.py b/hermes_cli/update_cmd.pyindex 74948cf51e6..c60f337f4f9 100644--- a/hermes_cli/update_cmd.py+++ b/hermes_cli/update_cmd.py@@ -864,10 +864,12 @@ def _pull_updates(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_sync_sha == target_sha:- # The caller already ran the target, but its local update branch was- # stale. Verify the fast-forward from that branch's tip, not a round- # trip back to the original detached SHA. Rollback still uses the latter.+ 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_shawith _best_effort('Could not write the interrupted-pull marker: %s'):pull_marker.write_text(@@ -1328,8 +1330,15 @@ def _finish_already_up_to_date(def _apply_pulled_update(git_cmd, branch, pre_pull_sha, _plan, *, _windows_gateway_resume, completion_request: dict) -> None:"""Post-pull phase: verify HEAD, sync Python/Node/web/Desktop, maintenance, fleet restart."""+ movement_baseline = _plan.pre_sync_sha or pre_pull_sha+ if 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_shapost_pull_sha = _verify_head_after_pull(- git_cmd, branch, _plan.pre_sync_sha or pre_pull_sha, in_place_update=_plan.in_place_update,+ git_cmd, branch, movement_baseline, in_place_update=_plan.in_place_update,_windows_gateway_resume=_windows_gateway_resume)if completion_request is not None:diff --git a/tests/hermes_cli/test_update_existing_branch_baseline.py b/tests/hermes_cli/test_update_existing_branch_baseline.pyindex a423c8e734d..4ce770cd2bf 100644--- a/tests/hermes_cli/test_update_existing_branch_baseline.py+++ b/tests/hermes_cli/test_update_existing_branch_baseline.py@@ -117,6 +117,50 @@ def test_stale_local_main_can_catch_up_to_original_detached_tip(checkout):assert git(root, "rev-parse", "main") == tip[email protected]("upstream_result", ["original", "unchanged", "wrong-branch", "reverted"])+def test_fork_sync_after_stale_branch_repair(checkout, monkeypatch, upstream_result):+ 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", upstream_tip)+ git(root, "branch", "-f", "main", old)+ plan = prepare(root)++ def sync(*args, **kwargs):+ assert git(root, "rev-parse", "HEAD") == tip+ if upstream_result == "original":+ git(root, "merge", "--ff-only", upstream_tip)+ elif upstream_result == "wrong-branch":+ git(root, "checkout", "-qb", "wrong")+ elif upstream_result == "reverted":+ git(root, "reset", "--hard", old)+ return True++ monkeypatch.setattr(update_cmd._m(), "_sync_with_upstream_if_needed", sync)+ kwargs = dict(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)+ if upstream_result in {"wrong-branch", "reverted"}:+ with pytest.raises(SystemExit) as exc:+ update_cmd._pull_updates(["git"], "main", plan.auto_stash_ref, **kwargs)+ assert exc.value.code == 1+ else:+ before_pull = update_cmd._pull_updates(["git"], "main", plan.auto_stash_ref, **kwargs)+ 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 if upstream_result == "original" else tip)+ assert git(root, "rev-parse", "main") == (upstream_tip if upstream_result == "original" else tip)+ assert git(root, "rev-parse", "--abbrev-ref", "HEAD") == "main"++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)