test(update): gc custody is asserted through run_git; drop the dead spawn_kwargs (review N-coverage)

What: delete update_custody.spawn_kwargs (no production caller since #132927 removed the gc fold) and
its helper-only test; a parametrized test drives run_git itself (gc holds the lock fd, a reader not).
Why: the old test exercised only the dead helper and returned early on win32, a false green.
Red/green: mutant 'run_git raises' -> new test 2 failed (old test passed under it); real code -> 8 passed.
This commit is contained in:
Teknium
2026-10-04 23:03:46 -07:00
parent 6da284015d
commit d23ddec6d5
2 changed files with 15 additions and 26 deletions

View File

@@ -284,13 +284,6 @@ def run_git(git_cmd: Sequence[str], args: Sequence[str], **kwargs) -> subprocess
return run(argv, inherit_lock=mutator, **kwargs)
def spawn_kwargs(args: Sequence[str]) -> dict:
"""The Popen kwargs :func:`run_git` would give a git child (``args`` = its argv after the
executable, custody config included): the lock fd for a local mutator, else the Linux
parent-death signal. For a runner that needs its own Popen (the bounded gc fold)."""
return _custody_kwargs(is_local_mutator(args), {})
def _partial_clone(git_cmd: Sequence[str], kwargs: dict) -> bool:
"""The repository has a promisor remote (``extensions.partialClone``), read from disk."""
from pathlib import Path

View File

@@ -278,29 +278,25 @@ def test_a_partial_clone_move_never_fetches_under_the_lock_fd(repo, tmp_path, mo
assert "credential.helper=" in moved.args, moved.args
def test_the_gc_fold_runs_in_checkout_custody(repo, tmp_path):
"""m4: the lazy-fetch pack fold (`gc --auto`, which packs refs) ran outside custody: no lock
fd, no death signal, so it outlived a killed owner and repacked under the next one. It is a
local mutator now and its bounded runner passes run_git's custody (POSIX: the lock fd, which
its repack/pack-objects children inherit). `pull` is gone: its network half must not hold it."""
from hermes_cli._subprocess_compat import bounded_probe_run
from hermes_cli.update_custody import LOCAL_MUTATORS, git_argv, spawn_kwargs
@pytest.mark.skipif(not Path("/proc/self/fd").is_dir(), reason="needs /proc fd listing")
@pytest.mark.parametrize(("args", "holds"), [(["gc", "--auto"], True), (["rev-parse", "HEAD"], False)])
def test_run_git_hands_the_lock_fd_to_local_mutators_only(repo, tmp_path, monkeypatch, args, holds):
"""Through the production runner: `gc` (packs refs, repacks) is a local mutator and runs
holding the checkout lock; a reader does not. `pull` is never one (its network half)."""
from hermes_cli.update_custody import LOCAL_MUTATORS, run_git
assert "pull" not in LOCAL_MUTATORS
argv = git_argv(["git"], ["-c", "gc.writeCommitGraph=false", "gc", "--auto"])
git = tmp_path / "git-recorder.sh"
git.write_text(_RECORDER.replace('exec "$@"', 'exec git "$@"'), encoding="utf-8")
git.chmod(0o755)
out = tmp_path / "git.out"
monkeypatch.setenv("HERMES_TEST_LOCK", os.path.realpath(ul.checkout_lock_path(repo)))
monkeypatch.setenv("HERMES_TEST_OUT", str(out))
lock = ul.UpdateLock(path=tmp_path / "marker", install_root=repo)
assert lock.acquire()
try:
custody = spawn_kwargs(argv[1:])
if sys.platform == "win32":
return # the bounded runner's own kill-on-close job: dies with the owner
lock_path = os.path.realpath(ul.checkout_lock_path(repo))
probe = ("import os, sys\n"
"print(any(os.path.realpath(f'/proc/self/fd/{fd}') == sys.argv[1]\n"
" for fd in os.listdir('/proc/self/fd')))")
held = bounded_probe_run([sys.executable, "-c", probe, lock_path], timeout=30, popen_kwargs=custody)
ran = run_git([str(git)], args, cwd=repo, capture_output=True, text=True)
finally:
lock.release()
assert custody.get("pass_fds"), f"gc gets no lock fd: {custody}"
if Path("/proc/self/fd").is_dir():
assert held is not None and held.stdout.strip() == "True", held
assert ran.returncode == 0, ran.stderr
assert out.read_text(encoding="utf-8-sig").split() == (["yes"] if holds else ["no"]), args