This commit is contained in:
scienidejp 2026-11-05 17:06:44 -03:00 • committed by GitHub
commit f10a782b44
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 115 additions and 30 deletions

View file

@ -110,6 +110,9 @@ check_existing_installation() {
if [[ ! -e "$path" ]] || [[ "$path" == "$INSTALL_DIR/strix"* ]]; then
continue
fi
if [[ -L "$path" && "$(readlink "$path" 2>/dev/null || true)" == "$INSTALL_DIR/strix"* ]]; then
continue
fi
if [[ -n "$path" ]]; then
echo -e "${MUTED}Found existing strix at: ${NC}$path"
@ -237,50 +240,59 @@ 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"
;;
esac
config_file=""
local found_config=false
for file in $config_files; do
if [[ -f $file ]]; then
config_file=$file
break
found_config=true
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 [[ -z $config_file ]]; then
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"
elif [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
case $current_shell in
fish)
add_to_path "$config_file" "fish_add_path $INSTALL_DIR"
;;
zsh)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
bash)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
ash)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
sh)
add_to_path "$config_file" "export PATH=$INSTALL_DIR:\$PATH"
;;
*)
export PATH=$INSTALL_DIR:$PATH
print_message warning "Manually add the directory to $config_file (or similar):"
print_message info " export PATH=$INSTALL_DIR:\$PATH"
;;
esac
fi
if [ "$os" != "windows" ] && [[ -x "$INSTALL_DIR/strix" ]]; then
local local_bin="$HOME/.local/bin"
if [[ -d "$local_bin" || ":$PATH:" == *":$local_bin:"* ]]; then
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
if [ -n "${GITHUB_ACTIONS-}" ] && [ "${GITHUB_ACTIONS}" == "true" ]; then
@ -294,7 +306,7 @@ verify_installation() {
local which_strix=$(which strix 2>/dev/null || echo "")
if [[ "$which_strix" != "$INSTALL_DIR/strix" && "$which_strix" != "$INSTALL_DIR/strix.exe" ]]; then
if [[ "$which_strix" != "$INSTALL_DIR/strix" && "$which_strix" != "$INSTALL_DIR/strix.exe" && "$(readlink "$which_strix" 2>/dev/null || true)" != "$INSTALL_DIR/strix"* ]]; then
if [[ -n "$which_strix" ]]; then
echo -e "${YELLOW}⚠ Found conflicting strix at: ${NC}$which_strix"
echo -e "${MUTED}Attempting to remove...${NC}"

View file

@ -152,3 +152,76 @@ def test_installer_rejects_unsupported_architecture(tmp_path: Path) -> None:
assert "Unsupported OS/Arch: linux/riscv64" in result.stdout
assert not curl_log_path.exists()
assert not (home_path / ".strix").exists()
def test_installer_symlinks_local_bin_and_updates_all_existing_shell_configs(
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,
)
local_bin = home_path / ".local/bin"
local_bin.mkdir(parents=True)
environment["PATH"] = f"{local_bin}:{environment['PATH']}"
bashrc = home_path / ".bashrc"
profile = home_path / ".profile"
bashrc.write_text("# existing bashrc\n", encoding="utf-8")
profile.write_text("# existing profile\n", encoding="utf-8")
result = _run_installer(repository_root, environment)
assert result.returncode == 0, result.stderr
expected_path_line = f"export PATH={home_path}/.strix/bin:$PATH"
assert expected_path_line in bashrc.read_text(encoding="utf-8")
assert expected_path_line in profile.read_text(encoding="utf-8")
symlink_path = local_bin / "strix"
assert symlink_path.is_symlink()
assert symlink_path.resolve() == (home_path / ".strix/bin/strix").resolve()
rerun_result = _run_installer(repository_root, environment)
assert rerun_result.returncode == 0, rerun_result.stderr
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)