Files
hermes-agent/tests/scripts/install/test_install_ps1_json_failure_frame.py
kshitijk4poor 18d125cc1b test(install): give install.ps1 subprocess tests the stage budget their siblings use
test_install_ps1_json_failure_frame runs a full `install.ps1 -Stage repository
-Json` under Windows PowerShell with a 30 s timeout. On the windows-arm64 lane
that run takes 25.0 s when green and 68.8 s when slow, so it times out
intermittently (twice on PR #130298, a gateway-only change). The same file
invocation in test_install_ps1_staged_git uses 240 s; use that budget here and
for staged_git's dot-sourced Ensure-Git probe, which parses the same script under
the same 30 s limit.

Also read the preserved user file with utf-8-sig, the BOM-tolerant read the
Windows-footgun lint requires for this file.
2026-10-01 22:38:59 +05:30

35 lines
1.5 KiB
Python

"""A fatal stage under -Stage -Json yields exactly one failure frame carrying the reason."""
import json
import os
from pathlib import Path
import shutil
import subprocess
import pytest
pytestmark = pytest.mark.platforms("windows")
INSTALLER = Path(__file__).resolve().parents[3] / "scripts" / "install.ps1"
def test_fail_inside_a_stage_emits_one_json_frame_with_the_reason(tmp_path):
powershell = shutil.which("powershell")
assert powershell
# A nonempty non-checkout refuses before any clone retries, through Fail.
install_dir = tmp_path / "install"
install_dir.mkdir()
(install_dir / "user-file").write_text("preserve me", encoding="utf-8")
tools = tmp_path / "empty-tools"
env = dict(os.environ, HERMES_HOME=str(tmp_path / "home"),
HERMES_RUNTIME_DIR=str(tools))
result = subprocess.run(
[powershell, "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", str(INSTALLER),
"-Stage", "repository", "-Json", "-InstallDir", str(install_dir)],
env=env, capture_output=True, text=True, timeout=240)
frames = [json.loads(line) for line in result.stdout.splitlines() if line.startswith("{")]
assert result.returncode == 1
assert len(frames) == 1, result.stdout
assert frames[0]["ok"] is False and frames[0]["stage"] == "repository"
assert "exists and is not a Hermes git checkout" in frames[0]["reason"]
assert (install_dir / "user-file").read_text(encoding="utf-8-sig") == "preserve me"
assert not tools.exists()