Skip to content

The agent that grows with you

refactor: trim the unanswered-probe fix to one helper and two tests

Tekniumd32d684cee0d
diff --git a/hermes_cli/source_releases.py b/hermes_cli/source_releases.py
index 64427225998..831c9587635 100644
--- a/hermes_cli/source_releases.py
+++ b/hermes_cli/source_releases.py
@@ -20,9 +20,6 @@ _GITHUB_ORIGIN = re.compile(
r"([A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?)(?:\.git)?/?$", re.IGNORECASE,
)
_SHA = re.compile(r"[0-9a-f]{40}")
-# A read-only probe answers in milliseconds, except a lookup of an object this checkout does not
-# have: that walks the whole (multi-pack) object store instead of the release's ancestry.
-_PROBE_TIMEOUT_SECONDS = 10
def source_repository(git_cmd=None, cwd=None) -> str:
@@ -100,20 +97,18 @@ def resolve_source_target(channel: str, git_cmd=None, cwd=None, *, repository=No
def _probe(git_cmd, cwd, *args):
- """``git <args>`` in ``cwd``, or None when git did not answer at all.
+ """``git <args>`` in ``cwd``, or None when git did not answer: an unknown relation, not a claim.
- A probe git never answered proves nothing and must not decide an update (issue #137646): the
- bound kills a lookup of a commit this checkout never fetched — seconds of CPU in a large
- partial clone, no network — and a git that is not there answers nothing either. None is an
- unknown relation, never a claim about one.
+ Before the updater's fetch the release commit is usually absent, and git 2.43 spends 7-12 s
+ of CPU on a blobless clone failing to find it even with lazy fetch off (#137646).
"""
from hermes_cli.source_check import source_git_env
try:
return subprocess.run(
[*git_cmd, *args], cwd=cwd, capture_output=True, text=True, encoding="utf-8",
- errors="replace", timeout=_PROBE_TIMEOUT_SECONDS, stdin=subprocess.DEVNULL,
- env=source_git_env(), check=False)
+ errors="replace", timeout=10, stdin=subprocess.DEVNULL, env=source_git_env(),
+ check=False)
except (OSError, subprocess.SubprocessError) as exc:
logger.debug("git %s did not answer: %s", " ".join(args), exc)
return None
@@ -127,21 +122,13 @@ def _head_containing(git_cmd, cwd, commit: str, repository: str) -> str | None:
"""
from hermes_cli.source_check import _github_compare, source_git_env
- def run(*args):
- """HEAD is a local file read every later step needs: a checkout that cannot report it
- fails the update rather than guessing, so this one is not allowed to go unanswered."""
- return subprocess.run(
- [*git_cmd, *args], cwd=cwd, capture_output=True, text=True, encoding="utf-8",
- errors="replace", timeout=_PROBE_TIMEOUT_SECONDS, stdin=subprocess.DEVNULL,
- env=source_git_env(), check=False)
-
- head = run("rev-parse", "HEAD").stdout.strip()
+ head = subprocess.run(
+ [*git_cmd, "rev-parse", "HEAD"], cwd=cwd, capture_output=True, text=True, encoding="utf-8",
+ errors="replace", timeout=10, stdin=subprocess.DEVNULL, env=source_git_env(), check=False,
+ ).stdout.strip()
if not _SHA.fullmatch(head):
return None
- # Whether HEAD *contains* the release is the question that may go unanswered: the release
- # commit need not be in this object store, and no bound makes the local probe answer then.
- # An unknown relation falls through to the comparison API below, as a shallow checkout's
- # does — rather than reporting an unresolvable channel and refusing the update.
+ # An unanswered probe falls through to the comparison API, as a shallow checkout's does.
ancestry = _probe(git_cmd, cwd, "merge-base", "--is-ancestor", commit, head)
if ancestry is not None and ancestry.returncode == 0:
return head
@@ -234,8 +221,7 @@ def _refuse_retirement_downgrade(request: dict, terminal: dict, git_cmd, cwd) ->
result = _probe(git_cmd, cwd, "rev-list", "--ancestry-path", f"{request['commit']}..HEAD")
# The target need not exist locally before the updater's fetch. When it
# does, any descendants prove that this pinned build would roll us back.
- # A probe that never answered (that same absent commit, killed at the bound)
- # proves nothing either, and must not refuse the retirement instead.
+ # An unanswered probe proves nothing either.
if result is not None and result.returncode == 0 and result.stdout.strip():
raise ValueError("Source retirement would downgrade a newer source commit; select the destination channel explicitly")
if terminal["head"]["sequence"] > request["sequence"]:
diff --git a/tests/hermes_cli/test_stable_forward_only_shallow.py b/tests/hermes_cli/test_stable_forward_only_shallow.py
index 382ebdee395..a34a31becd1 100644
--- a/tests/hermes_cli/test_stable_forward_only_shallow.py
+++ b/tests/hermes_cli/test_stable_forward_only_shallow.py
@@ -89,11 +89,3 @@ def test_a_probe_that_never_answered_cannot_refuse_a_retirement(tmp_path, monkey
request = {"commit": "0" * 40, "sequence": 1, "sourceVersion": "0.1.0", "repository": "o/r"}
source_releases._refuse_retirement_downgrade(request, {"head": {"sequence": 1}}, ["git"], checkout)
assert timed_out == [["git", "rev-list", "--ancestry-path", f"{request['commit']}..HEAD"]]
-
-
-def test_a_local_descendant_still_refuses_a_downgrade(history, tmp_path):
- """Silence must not swallow the proof the probe exists for."""
- origin, shas = history
- request = {"commit": shas[0], "sequence": 1, "sourceVersion": "0.1.0", "repository": "o/r"}
- with pytest.raises(ValueError):
- source_releases._refuse_retirement_downgrade(request, {"head": {"sequence": 1}}, ["git"], origin)