Skip to content

The agent that grows with you

test(update): keep two invariant tests per fix in the salvaged unit tests

teknium1f338f4830c3e
diff --git a/tests/hermes_cli/test_gitlock.py b/tests/hermes_cli/test_gitlock.py
index 6fe8e2ba1a7..7dcd1cdb2d5 100644
--- a/tests/hermes_cli/test_gitlock.py
+++ b/tests/hermes_cli/test_gitlock.py
@@ -149,14 +149,6 @@ _CRASH_STDERR_WINDOWS = (
)
-def test_crash_recognizer_matches_reported_stderr():
- assert is_partial_clone_pack_objects_crash(_CRASH_STDERR)
-
-
-def test_crash_recognizer_matches_windows_stderr_without_signal_wording():
- assert is_partial_clone_pack_objects_crash(_CRASH_STDERR_WINDOWS)
-
-
def test_crash_recognizer_rejects_unrelated_failures():
assert not is_partial_clone_pack_objects_crash(
"fatal: Authentication failed for 'https://github.com/example.git'")
@@ -169,13 +161,14 @@ def test_crash_recognizer_rejects_unrelated_failures():
assert not is_partial_clone_pack_objects_crash(None)
-def test_recovery_retries_once_with_promisor_disabled():
[email protected]("crash_stderr", [_CRASH_STDERR, _CRASH_STDERR_WINDOWS], ids=["posix", "windows"])
+def test_recovery_retries_once_with_promisor_disabled(crash_stderr):
calls = []
def runner(git_cmd, args):
calls.append((list(git_cmd), list(args)))
if len(calls) == 1:
- return CompletedProcess(git_cmd + args, 1, stdout="", stderr=_CRASH_STDERR)
+ return CompletedProcess(git_cmd + args, 1, stdout="", stderr=crash_stderr)
return CompletedProcess(git_cmd + args, 0, stdout="", stderr="")
result = fetch_with_partial_clone_recovery(runner, ["git"], ["fetch", "origin", "main"])
@@ -183,22 +176,3 @@ def test_recovery_retries_once_with_promisor_disabled():
assert [args for _, args in calls] == [["fetch", "origin", "main"]] * 2
assert calls[1][0] == ["git", "-c", "remote.origin.promisor="]
assert result.returncode == 0
-
-
-def test_recovery_passes_through_success_and_unrelated_failure():
- calls = []
-
- def failing_runner(git_cmd, args):
- calls.append((list(git_cmd), list(args)))
- return CompletedProcess(git_cmd + args, 1, stdout="", stderr="fatal: Permission denied (publickey)")
-
- result = fetch_with_partial_clone_recovery(failing_runner, ["git"], ["fetch", "origin", "main"])
- assert result.returncode == 1
- assert calls == [(["git"], ["fetch", "origin", "main"])]
-
- calls.clear()
- ok_runner = lambda gc, a: (calls.append((list(gc), list(a))),
- CompletedProcess(gc + a, 0, stdout="", stderr=""))[-1]
- result = fetch_with_partial_clone_recovery(ok_runner, ["git"], ["fetch", "--no-tags", "origin", "abc123"])
- assert result.returncode == 0
- assert calls == [(["git"], ["fetch", "--no-tags", "origin", "abc123"])]
diff --git a/tests/hermes_cli/test_tag_fetch_partial_clone.py b/tests/hermes_cli/test_tag_fetch_partial_clone.py
index 2b707444f9c..9c55cb66091 100644
--- a/tests/hermes_cli/test_tag_fetch_partial_clone.py
+++ b/tests/hermes_cli/test_tag_fetch_partial_clone.py
@@ -73,33 +73,6 @@ def test_tag_fetch_never_writes_promisor_config_on_a_full_clone(tmp_path):
assert "v0.21.6" in _git(checkout, "tag", "--list")
-def test_tag_fetch_never_introduces_promisor_config_on_a_plain_clone(tmp_path):
- # A plain full clone (never partial) must not be converted either.
- checkout = _clone(tmp_path, _server_repo(tmp_path), "plain", "--no-tags")
- assert not _has_promisor_config(checkout)
-
- fetch_full_commit_graph(checkout)
-
- assert not _has_promisor_config(checkout)
- assert "v0.21.6" in _git(checkout, "tag", "--list")
-
-
-def test_tag_fetch_keeps_partial_clone_semantics_and_tags(tmp_path):
- # Installer clones ship as partial; the filter must keep applying there so
- # trees stay on demand (the original intent of the flag).
- server = _server_repo(tmp_path)
- _git(server, "config", "uploadpack.allowFilter", "true")
- checkout = _clone(tmp_path, server, "partial", "--no-tags", "--filter=tree:0")
- assert _has_promisor_config(checkout)
-
- fetch_full_commit_graph(checkout)
-
- # Still a partial clone with the *same* filter, and the tags still arrived.
- assert _has_promisor_config(checkout)
- assert _git(checkout, "config", "--get", "remote.origin.partialclonefilter") == "tree:0"
- assert "v0.21.6" in _git(checkout, "tag", "--list")
-
-
def test_tag_fetch_preserves_a_non_default_partial_clone_filter(tmp_path):
# A partial clone whose filter the user set themselves (blob:none) must not
# be silently tightened to tree:0 by the tag fetch — repeat the clone's own
@@ -113,36 +86,3 @@ def test_tag_fetch_preserves_a_non_default_partial_clone_filter(tmp_path):
assert _git(checkout, "config", "--get", "remote.origin.partialclonefilter") == "blob:none"
assert "v0.21.6" in _git(checkout, "tag", "--list")
-
-
-def test_tag_fetch_respects_a_de_partialised_former_partial_clone(tmp_path):
- # The exact repair from the report: unsetting the promisor keys is the
- # supported escape from the `should_include_obj` failure, and the next
- # tag fetch must not undo it.
- server = _server_repo(tmp_path)
- _git(server, "config", "uploadpack.allowFilter", "true")
- checkout = _clone(tmp_path, server, "repaired", "--no-tags", "--filter=tree:0")
- assert _has_promisor_config(checkout)
- _git(checkout, "config", "--unset", "remote.origin.promisor")
- _git(checkout, "config", "--unset", "remote.origin.partialclonefilter")
- assert not _has_promisor_config(checkout)
-
- fetch_full_commit_graph(checkout)
-
- assert not _has_promisor_config(checkout)
- assert "v0.21.6" in _git(checkout, "tag", "--list")
-
-
-def test_shallow_unshallow_fetch_leaves_promisor_config_alone(tmp_path):
- # A shallow clone is unshallowed by the same fetch; after --unshallow the
- # repo must still not gain promisor keys it did not have.
- server = _server_repo(tmp_path)
- _git(server, "config", "uploadpack.allowFilter", "true")
- checkout = _clone(tmp_path, server, "shallow", "--no-tags", "--depth", "1")
- assert not _has_promisor_config(checkout)
-
- assert fetch_full_commit_graph(checkout) is True
-
- assert not _has_promisor_config(checkout)
- assert _git(checkout, "rev-parse", "--is-shallow-repository") == "false"
- assert "v0.21.6" in _git(checkout, "tag", "--list")
diff --git a/tests/hermes_cli/test_update_fetch_failure_classifier.py b/tests/hermes_cli/test_update_fetch_failure_classifier.py
index 0c9fdf453b5..39395133eaf 100644
--- a/tests/hermes_cli/test_update_fetch_failure_classifier.py
+++ b/tests/hermes_cli/test_update_fetch_failure_classifier.py
@@ -155,18 +155,3 @@ def test_update_and_upstream_network_calls_disable_terminal_prompts(monkeypatch,
assert env["GIT_ASKPASS"] == "fixture-askpass", args
assert env["GIT_CONFIG_COUNT"] == "1", args
assert env["GIT_CONFIG_VALUE_0"] == "fixture-helper", args
-
-
-class TestTimeoutIsNotANetworkOutage:
- def test_wall_clock_kill_reports_slow_transfer_not_dead_remote(self):
- # The updater kills fetches on a 300s wall-clock cap; on a stale
- # shallow install the transport is healthy and mid-transfer when the
- # kill lands (#123254), so the diagnosis must not send the user
- # debugging their network.
- msg = update_cmd._classify_fetch_failure(
- "git fetch was still running after the 300s network limit"
- " (slow transfer, not a dead remote — a larger fetch may need"
- " `hermes update` again or a manual `git fetch`)")
- assert "update time limit" in msg
- assert "not a broken connection" in msg
- assert "Network error" not in msg
diff --git a/tests/hermes_cli/test_update_shallow_heal.py b/tests/hermes_cli/test_update_shallow_heal.py
index 8baf6f0736c..fbea204874e 100644
--- a/tests/hermes_cli/test_update_shallow_heal.py
+++ b/tests/hermes_cli/test_update_shallow_heal.py
@@ -1,154 +1,58 @@
-"""Heal-before-fetch for stale shallow installer checkouts (#123254).
-
-A depth-1 install far behind ``origin/main`` cannot finish ``git fetch origin
-main`` inside the updater's 300s network cap: the server must send the full
-ancestry of every side branch merged past the shallow boundary, every attempt
-is killed mid-transfer, and the unshallow step that would make later fetches
-incremental only ran *after* a successful update — so a stale shallow install
-could never update at all. The updater now heals the checkout before the
-bounded fetch, non-fatally, and the timeout wording no longer blames a dead
-remote for a wall-clock kill on a healthy transfer.
-
-These run against real local git repositories; only the timing caps are
-irrelevant here (the fetches are local and instant).
+"""A shallow checkout is unshallowed (commit graph only) before the updater's bounded fetch.
+
+From a depth-1 install far behind main, a plain ``git fetch origin main`` drags in ~the whole
+history and cannot finish inside the 300s network cap (#123254); a ``--depth`` pre-fetch grafts
+origin/main so merge-base reports orphan divergence (#123346). Real local git repositories.
"""
from __future__ import annotations
import subprocess
+from pathlib import Path
-import hermes_cli.gitlock as gitlock
-import hermes_cli.update_cmd as update_cmd
+from hermes_cli.gitlock import heal_shallow_history
-def _git(cwd, *args, check=True):
- return subprocess.run(
- ["git", *args],
- cwd=cwd,
- capture_output=True,
- text=True,
- encoding="utf-8",
- errors="replace",
- check=check,
- )
+def _git(cwd: Path, *args: str) -> subprocess.CompletedProcess:
+ return subprocess.run(["git", "-c", "user.email=t@t", "-c", "user.name=t", *args], cwd=cwd,
+ capture_output=True, text=True, encoding="utf-8", errors="replace")
-def _origin_with_history(tmp_path, *, allow_filter=True):
+def _origin(tmp_path: Path, commits: int) -> Path:
origin = tmp_path / "origin"
origin.mkdir()
_git(origin, "init", "-q", "-b", "main")
- _git(origin, "config", "user.email", "[email protected]")
- _git(origin, "config", "user.name", "t")
- _git(origin, "commit", "--allow-empty", "-qm", "c0")
- _git(origin, "commit", "--allow-empty", "-qm", "c1")
- _git(origin, "tag", "v0.21.2")
- if allow_filter:
- # file:// transport requires opt-in; real hosting does this by default.
- _git(origin, "config", "uploadpack.allowFilter", "true")
+ _git(origin, "config", "uploadpack.allowFilter", "true")
+ for i in range(commits):
+ (origin / "f.txt").write_text(f"{i}\n", encoding="utf-8")
+ _git(origin, "add", "f.txt")
+ _git(origin, "commit", "-qm", f"c{i}")
return origin
-def _shallow_clone(tmp_path, origin):
+def test_depth1_clone_of_a_tagless_origin_gets_its_commit_graph(tmp_path):
+ origin = _origin(tmp_path, 3)
+ clone = tmp_path / "clone"
+ _git(tmp_path, "clone", "-q", "--depth", "1", f"file://{origin}", str(clone))
+
+ assert heal_shallow_history(clone, "main") is True
+
+ assert _git(clone, "rev-parse", "--is-shallow-repository").stdout.strip() == "false"
+ assert _git(clone, "rev-list", "--count", "HEAD").stdout.strip() == "3"
+ # History really was missing: fetched commits-only, as a tree:0 partial clone.
+ assert _git(clone, "config", "remote.origin.partialclonefilter").stdout.strip() == "tree:0"
+
+
+def test_depth_prefetch_on_a_full_clone_restores_ancestry_and_keeps_it_full(tmp_path):
+ origin = _origin(tmp_path, 2)
clone = tmp_path / "clone"
- subprocess.run(
- ["git", "clone", "-q", "--depth", "1", f"file://{origin}", str(clone)],
- check=True,
- capture_output=True,
- text=True,
- )
- return clone
-
-
-class TestHealShallowHistory:
- def test_heals_stale_shallow_clone_and_returns_true(self, tmp_path):
- origin = _origin_with_history(tmp_path)
- clone = _shallow_clone(tmp_path, origin)
- assert (clone / ".git" / "shallow").exists()
-
- assert gitlock.heal_shallow_history(clone, "main") is True
-
- assert not (clone / ".git" / "shallow").exists()
- # The history behind the boundary is present, so the bounded fetch
- # that follows is incremental instead of re-downloading the graph.
- assert _git(clone, "rev-list", "--count", "--all").stdout.strip() == "2"
-
- def test_full_clone_is_a_noop_returning_false(self, tmp_path):
- origin = _origin_with_history(tmp_path)
- clone = tmp_path / "clone"
- subprocess.run(
- ["git", "clone", "-q", f"file://{origin}", str(clone)],
- check=True,
- capture_output=True,
- text=True,
- )
-
- assert gitlock.heal_shallow_history(clone, "main") is False
- assert _git(clone, "rev-list", "--count", "--all").stdout.strip() == "2"
-
- def test_origin_without_tags_still_unshallows(self, tmp_path):
- # The tag refspec alone matches nothing on a tag-less origin and git
- # fails the whole fetch; the branch refspec must ride along.
- origin = _origin_with_history(tmp_path)
- _git(origin, "tag", "-d", "v0.21.2")
- clone = _shallow_clone(tmp_path, origin)
-
- assert gitlock.heal_shallow_history(clone, "main") is True
- assert not (clone / ".git" / "shallow").exists()
-
-
-class TestUpdateHealIsNonFatal:
- def test_heal_failure_keeps_the_update_alive(self, tmp_path, monkeypatch, capsys):
- origin = _origin_with_history(tmp_path)
- clone = _shallow_clone(tmp_path, origin)
-
- def broken_heal(*a, **kw):
- raise subprocess.CalledProcessError(
- 128, "git", stderr="fatal: filter not supported"
- )
-
- monkeypatch.setattr(gitlock, "heal_shallow_history", broken_heal)
- # Must not raise: the update proceeds with the old fetch behaviour.
- update_cmd._heal_stale_shallow_checkout(clone, "main")
- out = capsys.readouterr().out
- assert "Could not heal the shallow checkout" in out
- assert "filter not supported" in out
-
- def test_healed_checkout_prints_one_line(self, tmp_path, capsys):
- origin = _origin_with_history(tmp_path)
- clone = _shallow_clone(tmp_path, origin)
-
- update_cmd._heal_stale_shallow_checkout(clone, "main")
-
- assert "shallow checkout healed" in capsys.readouterr().out
- assert not (clone / ".git" / "shallow").exists()
-
- def test_full_checkout_stays_silent(self, tmp_path, capsys):
- origin = _origin_with_history(tmp_path)
- clone = tmp_path / "clone"
- subprocess.run(
- ["git", "clone", "-q", f"file://{origin}", str(clone)],
- check=True,
- capture_output=True,
- text=True,
- )
-
- update_cmd._heal_stale_shallow_checkout(clone, "main")
-
- assert capsys.readouterr().out == ""
-
-
-class TestTimeoutWording:
- def test_wall_clock_kill_does_not_blame_a_dead_remote(self, monkeypatch):
- # A wall-clock kill says nothing about the transport: the fetch may
- # have been actively transferring a multi-hundred-MB pack (#123254).
- def never_finishes(cmd, **kw):
- raise subprocess.TimeoutExpired(cmd, update_cmd.NETWORK_GIT_TIMEOUT_SECONDS)
-
- monkeypatch.setattr(update_cmd.subprocess, "run", never_finishes)
- result = update_cmd._git_run(
- ["git"], ["fetch", "origin", "main"], cwd="/tmp", network=True
- )
- assert result.returncode == 124
- assert "no response from the remote" not in result.stderr
- assert "network limit" in result.stderr
- assert "manual `git fetch`" in result.stderr
+ _git(tmp_path, "clone", "-q", f"file://{origin}", str(clone))
+ (origin / "f.txt").write_text("next\n", encoding="utf-8")
+ _git(origin, "commit", "-qam", "next")
+ _git(clone, "fetch", "-q", "--depth", "1", "origin", "main")
+ assert _git(clone, "merge-base", "HEAD", "origin/main").returncode != 0
+
+ assert heal_shallow_history(clone, "main") is True
+
+ assert _git(clone, "merge-base", "--is-ancestor", "HEAD", "origin/main").returncode == 0
+ assert _git(clone, "config", "--get", "remote.origin.promisor").returncode != 0