From 45d37a74800780744f32c8c953b6f7e21bacdb23 Mon Sep 17 00:00:00 2001 From: scienidejp <163542152+scienidejp@users.noreply.github.com> Date: Tue, 3 Nov 2026 23:55:05 +0200 Subject: [PATCH] fix(install): address review feedback on profile repair, non-fatal symlink, and /etc/profile fallback --- scripts/install.sh | 48 +++++++++++++++++++++--------------- tests/test_install_script.py | 34 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 20 deletions(-) diff --git a/scripts/install.sh b/scripts/install.sh index 4d6bf7f92..94dceacae 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -240,10 +240,10 @@ setup_path() { config_files="$HOME/.bashrc $HOME/.bash_profile $HOME/.profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile" ;; ash) - config_files="$HOME/.ashrc $HOME/.profile /etc/profile" + config_files="$HOME/.ashrc $HOME/.profile" ;; sh) - config_files="$HOME/.ashrc $HOME/.profile /etc/profile" + config_files="$HOME/.ashrc $HOME/.profile" ;; *) config_files="$HOME/.bashrc $HOME/.bash_profile $XDG_CONFIG_HOME/bash/.bashrc $XDG_CONFIG_HOME/bash/.bash_profile" @@ -254,24 +254,27 @@ setup_path() { for file in $config_files; do if [[ -f $file ]]; then found_config=true - if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then - case $current_shell in - fish) - add_to_path "$file" "fish_add_path $INSTALL_DIR" - ;; - zsh|bash|ash|sh) - add_to_path "$file" "export PATH=$INSTALL_DIR:\$PATH" - ;; - *) - export PATH=$INSTALL_DIR:$PATH - print_message warning "Manually add the directory to $file (or similar):" - print_message info " export PATH=$INSTALL_DIR:\$PATH" - ;; - esac - fi + case $current_shell in + fish) + add_to_path "$file" "fish_add_path $INSTALL_DIR" + ;; + zsh|bash|ash|sh) + add_to_path "$file" "export PATH=$INSTALL_DIR:\$PATH" + ;; + *) + export PATH=$INSTALL_DIR:$PATH + print_message warning "Manually add the directory to $file (or similar):" + print_message info " export PATH=$INSTALL_DIR:\$PATH" + ;; + esac fi done + if [[ "$found_config" == false ]] && [[ "$current_shell" == "ash" || "$current_shell" == "sh" ]] && [[ -f /etc/profile ]]; then + found_config=true + add_to_path "/etc/profile" "export PATH=$INSTALL_DIR:\$PATH" + fi + if [[ "$found_config" == false ]]; then print_message warning "No config file found for $current_shell. You may need to manually add to PATH:" print_message info " export PATH=$INSTALL_DIR:\$PATH" @@ -280,9 +283,14 @@ setup_path() { if [ "$os" != "windows" ] && [[ -x "$INSTALL_DIR/strix" ]]; then local local_bin="$HOME/.local/bin" if [[ -d "$local_bin" || ":$PATH:" == *":$local_bin:"* ]]; then - mkdir -p "$local_bin" - if [[ ! -e "$local_bin/strix" || -L "$local_bin/strix" ]]; then - ln -sf "$INSTALL_DIR/strix" "$local_bin/strix" + if mkdir -p "$local_bin" 2>/dev/null && [[ -w "$local_bin" ]]; then + if [[ ! -e "$local_bin/strix" || -L "$local_bin/strix" ]]; then + if ! ln -sf "$INSTALL_DIR/strix" "$local_bin/strix" 2>/dev/null; then + print_message warning "Could not create symlink in $local_bin/strix; continuing." + fi + fi + else + print_message warning "Skipping symlink in $local_bin (directory is not writable)." fi fi fi diff --git a/tests/test_install_script.py b/tests/test_install_script.py index bd105be28..2c2776f68 100644 --- a/tests/test_install_script.py +++ b/tests/test_install_script.py @@ -191,3 +191,37 @@ def test_installer_symlinks_local_bin_and_updates_all_existing_shell_configs( assert "Removing old pipx installation" not in rerun_result.stdout assert symlink_path.is_symlink() + +def test_installer_repairs_missing_profile_when_install_dir_in_path_and_tolerates_readonly_local_bin( + tmp_path: Path, +) -> None: + repository_root = Path(__file__).resolve().parents[1] + archive_path = _create_release_archive(tmp_path) + mock_bin = _create_mock_commands(tmp_path, machine="aarch64") + environment, home_path, _ = _create_installer_environment( + tmp_path, + archive_path, + mock_bin, + ) + + install_dir = home_path / ".strix/bin" + local_bin = home_path / ".local/bin" + local_bin.mkdir(parents=True) + local_bin.chmod(stat.S_IRUSR | stat.S_IXUSR) + environment["PATH"] = f"{install_dir}:{local_bin}:{environment['PATH']}" + + bashrc = home_path / ".bashrc" + profile = home_path / ".profile" + expected_path_line = f"export PATH={install_dir}:$PATH" + bashrc.write_text(f"# existing bashrc\n{expected_path_line}\n", encoding="utf-8") + profile.write_text("# existing profile without strix\n", encoding="utf-8") + + try: + result = _run_installer(repository_root, environment) + assert result.returncode == 0, result.stderr + assert expected_path_line in profile.read_text(encoding="utf-8") + assert bashrc.read_text(encoding="utf-8").count(expected_path_line) == 1 + finally: + local_bin.chmod(stat.S_IRWXU) + +