The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(update): isolate simulated timeouts to ancestry probes
Jonathan Ephraim Edwina2c4d0dc567e
diff --git a/tests/hermes_cli/test_stable_forward_only_shallow.py b/tests/hermes_cli/test_stable_forward_only_shallow.pyindex e90a0c99b3b..382ebdee395 100644--- a/tests/hermes_cli/test_stable_forward_only_shallow.py+++ b/tests/hermes_cli/test_stable_forward_only_shallow.py@@ -1,6 +1,5 @@"""An unchosen default channel never moves a checkout backward on a guess, and a probe that neveranswered never refuses the update (regression for #137646)."""-import shutilimport subprocessimport pytest@@ -53,38 +52,43 @@ def test_full_history_behind_release_is_proof(history, tmp_path, monkeypatch):assert source_releases._head_containing(["git"], clone, shas[0], "o/r") == shas[0]-def _hanging_git(tmp_path, subcommand: str) -> list[str]:- """A git that never answers ``subcommand``: the bound kills it.+def _timeout_git_probe(monkeypatch, subcommand: str):+ """Simulate only the unanswered probe; other commands keep real git and their normal bounds.- That is the reporter's probe: a release commit this checkout never fetched costs ~12 s of CPU- to look up in a 36-pack partial clone, so the 10 s bound killed `merge-base` before it could- report the missing object.+ Inject TimeoutExpired instead of shortening a shared timeout: the strict HEAD read must not+ become load-sensitive before the test reaches the ancestry probe."""- real = shutil.which("git")- stub = tmp_path / f"git-hangs-on-{subcommand}"- stub.write_text(f'#!/bin/sh\n[ "$1" = {subcommand} ] && exec sleep 30\nexec "{real}" "$@"\n')- stub.chmod(0o755)- return [str(stub)]+ real_run = subprocess.run+ timed_out = []++ def run(cmd, *args, **kwargs):+ if cmd[:2] == ["git", subcommand]:+ timed_out.append(cmd)+ raise subprocess.TimeoutExpired(cmd, kwargs["timeout"])+ return real_run(cmd, *args, **kwargs)++ monkeypatch.setattr(source_releases.subprocess, "run", run)+ return timed_out@pytest.mark.parametrize("compare, keeps_head", [({"status": "ahead"}, True), ({"status": "behind"}, False)])-def test_a_probe_that_never_answered_leaves_the_relation_unknown(history, tmp_path, monkeypatch, compare, keeps_head):+def test_a_probe_that_never_answered_leaves_the_relation_unknown(history, monkeypatch, compare, keeps_head):"""A killed probe is an unknown relation, not a reason to refuse the channel (#137646)."""origin, shas = history- monkeypatch.setattr(source_releases, "_PROBE_TIMEOUT_SECONDS", 0.2, raising=False)+ timed_out = _timeout_git_probe(monkeypatch, "merge-base")monkeypatch.setattr(source_check, "_github_compare", lambda *a, **k: compare)- git = _hanging_git(tmp_path, "merge-base")- assert source_releases._head_containing(git, origin, shas[2], "o/r") == (shas[2] if keeps_head else None)+ assert source_releases._head_containing(["git"], origin, shas[2], "o/r") == (shas[2] if keeps_head else None)+ assert timed_out == [["git", "merge-base", "--is-ancestor", shas[2], shas[2]]]def test_a_probe_that_never_answered_cannot_refuse_a_retirement(tmp_path, monkeypatch):"""The same silence on the retirement probe is not a proven downgrade either (#137646)."""- monkeypatch.setattr(source_releases, "_PROBE_TIMEOUT_SECONDS", 0.2, raising=False)+ timed_out = _timeout_git_probe(monkeypatch, "rev-list")checkout = tmp_path / "checkout"checkout.mkdir()request = {"commit": "0" * 40, "sequence": 1, "sourceVersion": "0.1.0", "repository": "o/r"}- source_releases._refuse_retirement_downgrade(request, {"head": {"sequence": 1}}, _hanging_git(tmp_path, "rev-list"),- checkout)+ 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):