Repository navigation
fix(which): respect prefer_offline so binary lookup avoids remote fetches #10595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Regression test for https://github.com/jdx/mise/discussions/10460 | ||
| # | ||
| # `mise which` is a binary lookup and must not require HTTP calls when an | ||
| # installed version already satisfies the request. It is now in the | ||
| # prefer-offline auto-enable list (like `where`, `ls`, `exec`), so even an | ||
| # explicit `minimum_release_age` cutoff -- which normally forces date-aware | ||
| # remote resolution on regular commands -- must keep resolving from installed | ||
| # versions instead of fetching a remote version list. | ||
| # | ||
| # Scope: this covers config-file tools. An explicit `--tool=spy@1` argument is | ||
| # a `ToolSource::Argument` request, which intentionally opts out of | ||
| # prefer-offline so explicit version requests resolve accurately (see #10571), | ||
| # consistent with `mise exec`/`mise x`; that path is not exercised here. | ||
|
|
||
| # Copy the dummy plugin into one whose remote version-listing scripts leave a | ||
| # marker file behind when they run, making any remote fetch directly | ||
| # observable. (cat > preserves the executable bit from the copied scripts.) | ||
| marker="$HOME/remote-versions-fetched" | ||
| cp -RL "$MISE_DATA_DIR/plugins/dummy" "$MISE_DATA_DIR/plugins/spy" | ||
| cat >"$MISE_DATA_DIR/plugins/spy/bin/list-all" <<EOF | ||
| #!/usr/bin/env bash | ||
| touch "$marker" | ||
| echo "1.0.0 1.1.0 2.0.0" | ||
| EOF | ||
| cat >"$MISE_DATA_DIR/plugins/spy/bin/latest-stable" <<EOF | ||
| #!/usr/bin/env bash | ||
| touch "$marker" | ||
| echo "2.0.0" | ||
| EOF | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
|
|
||
| mise install spy@1.0.0 | ||
|
|
||
| # Drop the marker and the remote-versions cache written during install. The | ||
| # cache must go too: a regressed which with a warm cache would resolve | ||
| # remotely without re-running list-all, hiding the fetch from the marker. | ||
| rm -f "$marker" | ||
| rm -rf "$MISE_CACHE_DIR/spy" | ||
|
|
||
| # Fuzzy requests ("latest", a prefix) are the dangerous ones: an explicit | ||
| # cutoff pushes those onto the remote date-aware resolution path. Newer remote | ||
| # versions (1.1.0, 2.0.0) exist, so a regressed remote resolution would also | ||
| # report a non-installed version below. Test both with no cutoff (built-in | ||
| # default) and an explicit cutoff. | ||
| for mra in unset 24h; do | ||
| if [[ $mra == unset ]]; then | ||
| unset MISE_MINIMUM_RELEASE_AGE | ||
| else | ||
| export MISE_MINIMUM_RELEASE_AGE="$mra" | ||
| fi | ||
|
|
||
| for version in latest 1 1.0.0; do | ||
| cat >mise.toml <<EOF | ||
| [tools] | ||
| spy = "$version" | ||
| EOF | ||
|
|
||
| # The spy plugin installs a bin named `dummy`; look it up and assert it | ||
| # resolved to the installed 1.0.0 without a remote fetch. Check the | ||
| # resolved version (not the path, whose dir mirrors the request string | ||
| # "1"/"latest") so the assert is request-independent. A regressed remote | ||
| # resolution would pick a newer non-installed version (1.1.0/2.0.0) and | ||
| # `mise which` would fail to find the bin. | ||
| resolved="$(mise which --version dummy)" || fail "mise which dummy failed for spy@$version" | ||
|
|
||
| if [[ -e $marker ]]; then | ||
| fail "mise which fetched remote versions resolving spy@$version (minimum_release_age=$mra)" | ||
| fi | ||
| assert_contains_text "$resolved" "1.0.0" | ||
| done | ||
| done | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.