Files
hermes-agent/tests/test_install_clone_throttle_fallback.py
ethernet 92686159d1 fix(pm): integrate audited runtime and lifecycle repairs
Prepare dependency generations before selecting them. Keep shipped tool
bytes separate from writable additions, and store facts beside their entries.
Validate proposed plugin sets before config publication. Restore the previous
config if the facts write fails.

Consolidate duplicate updater, backup, setup, and voice helpers. Repair
launcher selection, dependency consumers, download ownership, update feeds,
and native Windows process and file handling.

Verification: 206 changed/prior-failing Python files reported 4630 passed,
one failed, and 330 skipped. Fix the remaining Hindsight fixture boundary.
The final targeted rerun reported 234 passed and two skipped. The store
review regression batch reported 83 passed and one skipped. Desktop
TypeScript checks, 56 selected Electron tests, 24 release tests, and the
removed-import/compatibility guards passed.

This is an integration checkpoint, not full audit acceptance. The complete
Python suite has not run on this fixed tree. Crash-atomic plugin publication,
generation cleanup, receipt correlation, and packaged lifecycle acceptance
remain open in docs/pm-audit-status.md.
2026-09-05 22:36:48 -04:00

52 lines
2.1 KiB
Python

"""A throttled clone is retried without publishing a partial checkout."""
import os
from pathlib import Path
import shlex
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[1]
@pytest.mark.parametrize("materialize_fails", [False, True])
def test_clone_retries_and_publishes_only_materialized_tree(tmp_path, materialize_fails):
origin = tmp_path / "origin"
origin.mkdir()
def git(*args):
return subprocess.run(["git", "-C", str(origin), *args], check=True, capture_output=True, text=True)
git("init", "-b", "main")
git("config", "user.email", "fixture@example.invalid")
git("config", "user.name", "Fixture")
(origin / "README").write_text("complete checkout\n")
git("add", "README")
git("commit", "-m", "fixture")
dest = tmp_path / "install"
attempts = tmp_path / "attempts"
env = dict(os.environ, HOME=tmp_path.as_posix(), HERMES_HOME=(tmp_path / "home").as_posix(),
HERMES_INSTALL_DIR=dest.as_posix(), HERMES_REPO_URL=origin.as_posix())
# Inject throttling at the network boundary; the fallback and checkout use real Git.
script = f'''source {shlex.quote((ROOT / 'scripts/install.sh').as_posix())} --manifest
sleep() {{ :; }}
git() {{
if [ "$1" = clone ]; then
printf '%s\\n' "$*" >> {shlex.quote(attempts.as_posix())}
case " $* " in *" --filter=blob:none "*) ;; *) return 1 ;; esac
fi
if [ "{int(materialize_fails)}" = 1 ] && [ "${{3:-}}" = reset ]; then return 1; fi
command git "$@"
}}
stage_repository
'''
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, timeout=30)
calls = attempts.read_text().splitlines()
assert len([x for x in calls if "--filter=blob:none" not in x]) > 1
assert "--no-checkout" in calls[-1]
if materialize_fails:
assert result.returncode != 0
assert not dest.exists()
else:
assert result.returncode == 0, result.stdout + result.stderr
assert (dest / "README").read_text() == "complete checkout\n"
assert not list(tmp_path.glob(".hermes-clone-*"))