The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): recognize bare PATH= assignments and keep the appended line idempotent
ymat195cd9dbc26145
diff --git a/scripts/install.sh b/scripts/install.shindex 3d86236d15a..fdaa4833de1 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -623,6 +623,11 @@ desktop_product_present() {return 1}+# Guarded: a login shell whose ~/.bash_profile sources ~/.bashrc (Fedora, RHEL)+# reads both files, so an unconditional prepend would put ~/.local/bin on PATH twice.+SHELL_PATH_LINE='case ":$PATH:" in *":$HOME/.local/bin:"*) ;; *) export PATH="$HOME/.local/bin:$PATH" ;; esac'+SHELL_PATH_SETUP_RE='^[[:space:]]*([^#[:space:]].*)?PATH=.*\.local/bin'+append_shell_path() {local rc="$1" line="$2" pattern="$3"# Existing user PATH setup wins; never append another line on a repair run.@@ -641,18 +646,18 @@ wire_shell_path() {local login_shell="${SHELL:-/bin/bash}"case "${login_shell##*/}" inzsh)- append_shell_path "$HOME/.zshrc" 'export PATH="$HOME/.local/bin:$PATH"' '^[[:space:]]*[^#[:space:]].*PATH=.*\.local/bin'- append_shell_path "$HOME/.zprofile" 'export PATH="$HOME/.local/bin:$PATH"' '^[[:space:]]*[^#[:space:]].*PATH=.*\.local/bin'+ append_shell_path "$HOME/.zshrc" "$SHELL_PATH_LINE" "$SHELL_PATH_SETUP_RE"+ append_shell_path "$HOME/.zprofile" "$SHELL_PATH_LINE" "$SHELL_PATH_SETUP_RE";;fish)append_shell_path "$HOME/.config/fish/config.fish" 'fish_add_path "$HOME/.local/bin"' '^[[:space:]]*fish_add_path.*\.local/bin';;*)- append_shell_path "$HOME/.bashrc" 'export PATH="$HOME/.local/bin:$PATH"' '^[[:space:]]*[^#[:space:]].*PATH=.*\.local/bin'- append_shell_path "$HOME/.profile" 'export PATH="$HOME/.local/bin:$PATH"' '^[[:space:]]*[^#[:space:]].*PATH=.*\.local/bin'+ append_shell_path "$HOME/.bashrc" "$SHELL_PATH_LINE" "$SHELL_PATH_SETUP_RE"+ append_shell_path "$HOME/.profile" "$SHELL_PATH_LINE" "$SHELL_PATH_SETUP_RE"# Bash prefers .bash_profile over .profile if both exist.if [ -f "$HOME/.bash_profile" ]; then- append_shell_path "$HOME/.bash_profile" 'export PATH="$HOME/.local/bin:$PATH"' '^[[:space:]]*[^#[:space:]].*PATH=.*\.local/bin'+ append_shell_path "$HOME/.bash_profile" "$SHELL_PATH_LINE" "$SHELL_PATH_SETUP_RE"fi;;esacdiff --git a/tests/scripts/install/test_install_sh_shell_path.py b/tests/scripts/install/test_install_sh_shell_path.pynew file mode 100644index 00000000000..9a38f192ccb--- /dev/null+++ b/tests/scripts/install/test_install_sh_shell_path.py@@ -0,0 +1,89 @@+"""install.sh wires ~/.local/bin into shell startup files without duplicating it (#123424).++Distro skeletons put ~/.local/bin on PATH with a bare assignment+(`PATH="$HOME/.local/bin:$PATH"`), not `export PATH=...`; that must count as+existing setup. The appended line must also be a no-op when PATH already has the+entry, because Fedora's ~/.bash_profile sources ~/.bashrc in every login shell.+"""+import os+from pathlib import Path+import shlex+import subprocess++import pytest++pytestmark = pytest.mark.platforms("posix")+INSTALL_SH = Path(__file__).resolve().parents[3] / "scripts" / "install.sh"+MARKER = "# Hermes Agent command"++# Fedora /etc/skel (bash-5.2): ~/.bashrc guards and prepends with a bare assignment.+FEDORA_BASHRC = """\+# .bashrc++# Source global definitions+if [ -f /etc/bashrc ]; then+ . /etc/bashrc+fi++# User specific environment+if ! [[ "$PATH" =~ "$HOME/.local/bin:$HOME/bin:" ]]; then+ PATH="$HOME/.local/bin:$HOME/bin:$PATH"+fi+export PATH+"""+FEDORA_BASH_PROFILE = """\+# .bash_profile++# Get the aliases and functions+if [ -f ~/.bashrc ]; then+ . ~/.bashrc+fi++# User specific environment and startup programs+"""+# Debian /etc/skel/.profile tail.+DEBIAN_PROFILE = """\+# set PATH so it includes user's private bin if it exists+if [ -d "$HOME/.local/bin" ] ; then+ PATH="$HOME/.local/bin:$PATH"+fi+"""+++def _wire(home: Path, runs: int = 1) -> None:+ env = {k: v for k, v in os.environ.items() if k not in ("CI", "GITHUB_ACTIONS")}+ env.update(HOME=str(home), HERMES_HOME=str(home / "hermes"), SHELL="/bin/bash",+ NO_COLOR="1", TERM="dumb", CI="true")+ script = f"source {shlex.quote(INSTALL_SH.as_posix())} --manifest\n" + "wire_shell_path\n" * runs+ result = subprocess.run(["bash", "-c", script], env=env, stdin=subprocess.DEVNULL,+ capture_output=True, text=True, timeout=30)+ assert result.returncode == 0, result.stdout + result.stderr+++def _login_path(home: Path) -> list[str]:+ result = subprocess.run(["bash", "-lc", 'printf %s "$PATH"'],+ env={"HOME": str(home), "PATH": "/usr/local/bin:/usr/bin:/bin"},+ stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=30)+ assert result.returncode == 0, result.stderr+ return result.stdout.split(":")+++def _home(tmp_path: Path, **files: str) -> Path:+ (tmp_path / ".local" / "bin").mkdir(parents=True)+ for name, text in files.items():+ (tmp_path / name).write_text(text, encoding="utf-8")+ return tmp_path++[email protected]("name, text", [(".bashrc", FEDORA_BASHRC), (".profile", DEBIAN_PROFILE)])+def test_bare_assignment_counts_as_existing_setup(tmp_path, name, text):+ home = _home(tmp_path, **{name: text})+ _wire(home)+ assert (home / name).read_text(encoding="utf-8-sig") == text+++def test_fedora_login_shell_has_local_bin_once(tmp_path):+ home = _home(tmp_path, **{".bashrc": FEDORA_BASHRC, ".bash_profile": FEDORA_BASH_PROFILE})+ _wire(home, runs=2)+ assert (home / ".bash_profile").read_text(encoding="utf-8-sig").count(MARKER) == 1+ assert _login_path(home).count(str(home / ".local" / "bin")) == 1