Skip to content

fix: respect CARGO_HOME in install.sh#326

Open
lawrence3699 wants to merge 1 commit intoByron:mainfrom
lawrence3699:fix/cargo-home-install-path
Open

fix: respect CARGO_HOME in install.sh#326
lawrence3699 wants to merge 1 commit intoByron:mainfrom
lawrence3699:fix/cargo-home-install-path

Conversation

@lawrence3699
Copy link
Copy Markdown

Fixes #279.

Before this change, omitting --to always defaulted the installer to $HOME/.cargo/bin, even when CARGO_HOME was set. That made the documented installer path disagree with the user's configured Cargo home.

This updates the default destination to use $CARGO_HOME/bin when CARGO_HOME is set, and keeps the existing $HOME/.cargo/bin fallback otherwise. The journey test coverage now exercises both branches with fixed HOME/CARGO_HOME values.

Validation:

  • manual repro with fake HOME/CARGO_HOME before and after the change
  • ./tests/stateless-journey.sh ./target/debug/dua
  • cargo fmt --all -- --check
  • cargo clippy -- -D warnings
  • cargo test --all still failed locally in two unrelated interactive size assertions on this macOS environment

Copilot AI review requested due to automatic review settings April 19, 2026 02:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the ci/install.sh installer to honor CARGO_HOME when choosing the default install destination, aligning behavior with user expectations and documented Cargo configuration.

Changes:

  • Default --to destination now resolves to $CARGO_HOME/bin when CARGO_HOME is set, otherwise $HOME/.cargo/bin.
  • Adds stateless journey coverage for both default-destination branches via snapshot tests.
  • Adds new failure snapshots for installer output in both scenarios.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ci/install.sh Adjusts default install destination logic and updates --help text to mention CARGO_HOME.
tests/stateless-journey.sh Adds journey tests that exercise the installer’s default destination selection.
tests/snapshots/failure-install-script-defaults-to-home-cargo-bin Snapshot for installer output when CARGO_HOME is not used.
tests/snapshots/failure-install-script-defaults-to-cargo-home Snapshot for installer output when defaulting to CARGO_HOME/bin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ci/install.sh
@@ -130,7 +130,7 @@ fi
say_err "Target: $target"

if [ -z $dest ]; then
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dest is optional and may be unset/empty when --to is omitted. In POSIX sh, [ -z $dest ] becomes [ -z ] and typically exits with a "missing argument"/"unary operator expected" error (and with set -e this aborts the script). Quote the variable in the test (and ideally keep it consistently quoted anywhere it’s tested).

Suggested change
if [ -z $dest ]; then
if [ -z "$dest" ]; then

Copilot uses AI. Check for mistakes.
Comment on lines +130 to +136
rm -rf /tmp/dua-install-home /tmp/dua-cargo-home
it "uses CARGO_HOME for the default install location" && {
WITH_SNAPSHOT="$snapshot/failure-install-script-defaults-to-cargo-home" \
PATH="$PWD/fakebin:$PATH" \
HOME=/tmp/dua-install-home \
CARGO_HOME=/tmp/dua-cargo-home \
expect_run ${WITH_FAILURE} sh "$root/../ci/install.sh" \
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test uses fixed global paths under /tmp and rm -rf on them. That can collide under parallel test runs and can delete unrelated data if those paths exist for some other purpose. Prefer using per-sandbox paths (e.g., $PWD/home, $PWD/cargo-home, or a subdir of the sandbox tempdir) and avoid removing global /tmp/... entries.

Copilot uses AI. Check for mistakes.
it "falls back to HOME/.cargo/bin when CARGO_HOME is unset" && {
WITH_SNAPSHOT="$snapshot/failure-install-script-defaults-to-home-cargo-bin" \
PATH="$PWD/fakebin:$PATH" \
HOME=/tmp/dua-install-home \
Copy link

Copilot AI Apr 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The “CARGO_HOME is unset” case isn’t forced here: if the runner’s environment already has CARGO_HOME set, it will be inherited by the sh ci/install.sh process and this snapshot will fail. Make the test deterministic by explicitly unsetting CARGO_HOME (or setting it to an empty value, which still exercises the fallback with ${CARGO_HOME:-...}).

Suggested change
HOME=/tmp/dua-install-home \
HOME=/tmp/dua-install-home \
CARGO_HOME= \

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

@Byron Byron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

Let's keep only the one change to install.sh, then I can merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installation should take CARGO_HOME into account for default location

3 participants