From 44379fa1749b9b9e697b042f13a70bb5b48c3b3e Mon Sep 17 00:00:00 2001 From: ethernet Date: Thu, 29 Oct 2026 15:40:49 -0400 Subject: [PATCH] test(install): simulate a Linux uname for install.sh Linux-behaviour tests (cherry picked from commit f8b2acd580bc86b8257ab71705c1ea2189fdf675) --- tests/scripts/install/_linux_host.py | 27 +++++++++++++++++++ .../test_install_diverged_rescue_ref.py | 4 +++ .../install/test_install_sh_termux_refusal.py | 4 ++- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/scripts/install/_linux_host.py diff --git a/tests/scripts/install/_linux_host.py b/tests/scripts/install/_linux_host.py new file mode 100644 index 0000000000..c6045a68f0 --- /dev/null +++ b/tests/scripts/install/_linux_host.py @@ -0,0 +1,27 @@ +"""Let install.sh's platform gate see a Linux host on any test host. + +``check_platform`` refuses anything but Linux/macOS by ``uname -s`` (Git Bash on Windows +reports ``MINGW64_NT-…`` and is sent to install.ps1, as it should be). Tests of Linux +install behaviour that is not about the host itself put this ``uname`` first on PATH; +every query other than ``-s`` still answers from the real ``uname``. +""" +from __future__ import annotations + +import os +from pathlib import Path + +_UNAME = """#!/bin/sh +case "$*" in -s) echo Linux; exit 0 ;; esac +# This shim's directory is the first PATH entry; drop it to reach the real uname. +PATH="${PATH#*:}" exec uname "$@" +""" + + +def linux_uname_path(tmp_path: Path, path: str) -> str: + """Return ``path`` with a directory holding a Linux-reporting ``uname`` prepended.""" + bindir = tmp_path / "linux-uname" + bindir.mkdir() + uname = bindir / "uname" + uname.write_text(_UNAME, encoding="utf-8", newline="\n") + uname.chmod(0o755) + return str(bindir) + os.pathsep + path diff --git a/tests/scripts/install/test_install_diverged_rescue_ref.py b/tests/scripts/install/test_install_diverged_rescue_ref.py index 40dac94fe8..535896e833 100644 --- a/tests/scripts/install/test_install_diverged_rescue_ref.py +++ b/tests/scripts/install/test_install_diverged_rescue_ref.py @@ -17,6 +17,8 @@ from pathlib import Path import pytest +from tests.scripts.install._linux_host import linux_uname_path + REPO_ROOT = Path(__file__).resolve().parent.parent.parent.parent INSTALL_SH = REPO_ROOT / "scripts" / "install.sh" INSTALL_PS1 = REPO_ROOT / "scripts" / "install.ps1" @@ -75,6 +77,8 @@ def test_install_sh_repository_stage_parks_local_commits_before_reset(tmp_path: env = os.environ | { "HERMES_HOME": str(tmp_path / "hermes-home"), "HERMES_INSTALL_DIR": str(managed), + # The reset under test is host-independent; only the platform gate reads the OS. + "PATH": linux_uname_path(tmp_path, os.environ["PATH"]), } result = subprocess.run( diff --git a/tests/scripts/install/test_install_sh_termux_refusal.py b/tests/scripts/install/test_install_sh_termux_refusal.py index 7fa564b911..f0739d7898 100644 --- a/tests/scripts/install/test_install_sh_termux_refusal.py +++ b/tests/scripts/install/test_install_sh_termux_refusal.py @@ -5,6 +5,8 @@ import subprocess import pytest +from tests.scripts.install._linux_host import linux_uname_path + INSTALL_SH = Path(__file__).resolve().parent.parent.parent.parent / "scripts" / "install.sh" @@ -23,7 +25,7 @@ def test_termux_host_is_refused_before_any_stage_with_apt_hint(tmp_path, marker) def test_plain_linux_host_passes_platform_check(tmp_path): env = {k: v for k, v in os.environ.items() if k not in ("TERMUX_VERSION", "PREFIX")} env.update(HOME=tmp_path.as_posix(), HERMES_HOME=(tmp_path / "home").as_posix(), - HERMES_INSTALL_DIR=(tmp_path / "install").as_posix()) + HERMES_INSTALL_DIR=(tmp_path / "install").as_posix(), PATH=linux_uname_path(tmp_path, env["PATH"])) result = subprocess.run(["bash", INSTALL_SH.as_posix(), "--stage", "prerequisites"], env=env, capture_output=True, text=True, timeout=30, check=False) assert result.returncode == 0, result.stderr