Skip to content

The agent that grows with you

test(update): the parked-branch fetch guard is proven by a Trace2 fetch count

Tekniumcefe1db95c43
diff --git a/hermes_cli/update_cmd_git.py b/hermes_cli/update_cmd_git.py
index 2b8896a72f9..0e145fae7c3 100644
--- a/hermes_cli/update_cmd_git.py
+++ b/hermes_cli/update_cmd_git.py
@@ -6,7 +6,6 @@ test patches on ``update_cmd`` stay effective).
"""
import logging
-import os
from contextlib import suppress
import subprocess
import sys
@@ -14,7 +13,7 @@ from datetime import datetime, timedelta, timezone
from pathlib import Path
from typing import Optional
-from hermes_cli._subprocess_compat import NO_LAZY_FETCH_ENV, windows_hide_flags
+from hermes_cli._subprocess_compat import NO_LAZY_FETCH_ENV, noninteractive_git_env, windows_hide_flags
logger = logging.getLogger("hermes_cli.update_cmd") # log-record parity with the origin module
@@ -207,7 +206,7 @@ def _assess_parked_branch_switch(git_cmd: list[str], cwd: Path, current_branch:
# 180 GiB over 7 h on Windows (#131444). With lazy fetch off a missing object fails the
# command fast and the commit count below stands in.
cherry = _git_run(git_cmd, ["cherry", f"origin/{target_branch}"], cwd,
- env={**os.environ, **NO_LAZY_FETCH_ENV})
+ env={**noninteractive_git_env(), **NO_LAZY_FETCH_ENV})
if cherry.returncode != 0:
# Patch-equivalence only refines the count for rebase/squash-merged branches;
# a partial clone whose lazy fetch failed must not block a clean checkout,
diff --git a/tests/hermes_cli/test_update_parked_branch_guard.py b/tests/hermes_cli/test_update_parked_branch_guard.py
index 5d86bcdec10..1b14dac2237 100644
--- a/tests/hermes_cli/test_update_parked_branch_guard.py
+++ b/tests/hermes_cli/test_update_parked_branch_guard.py
@@ -20,6 +20,8 @@ branch, clone) — not mocked subprocess.run — so they exercise the actual
``git status`` / ``git cherry`` semantics the guard depends on.
"""
+import json
+import os
import subprocess
from types import SimpleNamespace
@@ -252,21 +254,37 @@ def test_treeless_cherry_failure_degrades_to_conservative_unmerged(tmp_path):
assert reason == "unmerged:1"
-def test_parked_branch_guard_never_lazy_fetches_from_a_live_promisor(tmp_path):
[email protected]("repo_config", [
+ {},
+ # Foreground auto-GC folds each new pack away inside the same command, so the pack
+ # count alone cannot see a fetch; the Trace2 child count still does.
+ {"gc.auto": "1", "gc.autoPackLimit": "1", "gc.autoDetach": "false"},
+], ids=["plain", "foreground-gc"])
+def test_parked_branch_guard_never_lazy_fetches_from_a_live_promisor(tmp_path, monkeypatch, repo_config):
"""Clean parked branch with a local commit on a tree:0 clone whose promisor
remote IS reachable: ``git cherry`` would lazy-fetch a tree batch per
upstream commit, and with nothing bounding that walk one such assessment
wrote 332 packs / 180 GiB in 7 h on Windows (#131444). The guard must not
- add a single pack and settles for the commit-graph count."""
+ start a single fetch and settles for the commit-graph count."""
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", os.devnull)
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
clone = _treeless_repo_pair(tmp_path, promisor_reachable=True)
+ for key, value in repo_config.items():
+ _git(clone, "config", key, value)
(clone / "feature.txt").write_text("unmerged work\n", encoding="utf-8")
_git(clone, "add", "feature.txt")
_git(clone, "commit", "-qm", "feature work")
packs_before = _pack_count(clone)
+ trace = tmp_path / "trace2.json"
+ monkeypatch.setenv("GIT_TRACE2_EVENT", str(trace))
safe, reason = update_cmd._assess_parked_branch_switch(
GIT, clone, "old-feature", "main"
)
+ monkeypatch.delenv("GIT_TRACE2_EVENT")
+ events = [json.loads(line) for line in trace.read_text(encoding="utf-8").splitlines()]
+ fetches = [e["argv"] for e in events if e.get("event") == "child_start" and "fetch" in e.get("argv", [])]
assert (safe, reason) == (True, "unmerged:1")
+ assert fetches == []
assert _pack_count(clone) == packs_before