fix: harden install.sh against inherited Python env leakage

This commit is contained in:
adybag14-cyber 2026-05-06 00:36:21 +01:00 committed by Teknium
parent e70e49016f
commit 043a118d41
2 changed files with 53 additions and 2 deletions

View file

@ -0,0 +1,30 @@
"""Regression tests for install.sh Python environment sanitization.
When install.sh is launched from another Python-driven tool session, inherited
PYTHONPATH/PYTHONHOME can shadow the freshly installed checkout. The installer
must sanitize those vars both during installation and at runtime launch.
"""
from pathlib import Path
REPO_ROOT = Path(__file__).resolve().parent.parent
INSTALL_SH = REPO_ROOT / "scripts" / "install.sh"
def test_install_script_unsets_pythonpath_and_pythonhome_early() -> None:
text = INSTALL_SH.read_text()
# During install, inherited Python env must be sanitized before pip/venv use.
assert 'unset PYTHONPATH' in text
assert 'unset PYTHONHOME' in text
def test_hermes_launcher_wrapper_clears_python_env_before_exec() -> None:
text = INSTALL_SH.read_text()
# Wrapper should clear env and forward args untouched to the venv entrypoint.
assert 'cat > "$command_link_dir/hermes" <<EOF' in text
assert 'unset PYTHONPATH' in text
assert 'unset PYTHONHOME' in text
assert 'exec "$HERMES_BIN" "\\$@"' in text