Files
hermes-agent/tests/scripts/install/conftest.py
Teknium 62f8d2ca1c test(install): stage tests reuse the lane's pinned Git instead of downloading it per home
install.ps1 keeps its store under HERMES_RUNTIME_DIR, else under HERMES_HOME. run_tests.sh never
forwards HERMES_RUNTIME_DIR (4bc973abd3), so every -Stage repository process the native-calls
tests start with a fresh temporary HERMES_HOME found no Git and downloaded and extracted
PortableGit from github.com: four downloads in that file. The iex-failure tests' empty git.exe
placeholders stopped satisfying Get-PinnedGit once it began checking for git-remote-https
(9976c9b04d), so they downloaded too. On a slow or 504ing github.com the native-calls file
blew the 300 s per-file limit on the Windows arm64 lane (306.9 s; 112-157 s on green runs).

A session fixture hands these tests a ready store: the one setup-pm already staged (the pinned
Git first on PATH, checked for git-remote-https), else one Get-PinnedGit fills once.
2026-11-08 05:15:01 -08:00

45 lines
1.9 KiB
Python

"""A ready pinned-Git store for the install.ps1 stage tests.
install.ps1 keeps its tool store under HERMES_RUNTIME_DIR, else under HERMES_HOME. run_tests.sh
never forwards HERMES_RUNTIME_DIR, so a stage started with a temporary HERMES_HOME found no Git
and downloaded and extracted PortableGit from GitHub, once per home. Tests whose subject is not
that download point HERMES_RUNTIME_DIR here: install.ps1 then finds a ready Git and writes nothing.
"""
import json
import os
from pathlib import Path
import shutil
import subprocess
import pytest
ROOT = Path(__file__).resolve().parents[3]
INSTALLER = ROOT / "scripts" / "install.ps1"
def _ready_store_on_path() -> Path | None:
"""The store holding the pinned Git first on PATH (setup-pm stages one on the Windows lanes)."""
version = json.loads((ROOT / "pm" / "lock.json").read_text(encoding="utf-8"))["packages"]["git"]["version"]
git = shutil.which("git")
if not git:
return None
entry = Path(git).resolve().parents[1]
if not entry.name.startswith(f"git-{version}-win32-"):
return None
exec_path = subprocess.run([git, "--exec-path"], capture_output=True, text=True, check=False).stdout.strip()
return entry.parent if exec_path and (Path(exec_path) / "git-remote-https.exe").is_file() else None
@pytest.fixture(scope="session")
def pinned_git_store(tmp_path_factory) -> Path:
store = _ready_store_on_path()
if store is not None:
return store
store = tmp_path_factory.mktemp("tools")
powershell = shutil.which("powershell")
assert powershell, "Windows PowerShell 5.1 is part of every supported Windows"
script = f". '{INSTALLER}'; if (-not (Get-PinnedGit)) {{ exit 9 }}"
subprocess.run([powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", script],
env=dict(os.environ, HERMES_RUNTIME_DIR=str(store)), check=True, capture_output=True, timeout=900)
return store