Skip to content

fix(which): respect prefer_offline so binary lookup avoids remote fetches - #10595

Merged
jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:fix-which-prefer-offline
Jun 24, 2026
Merged

jdx merged 1 commit into
jdx:mainfrom
JamBalaya56562:fix-which-prefer-offline

Conversation

@JamBalaya56562

@JamBalaya56562 JamBalaya56562 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

mise which is a binary lookup, but it was missing from the prefer-offline auto-enable command list, so version resolution could make remote HTTP calls even when an installed version already satisfies the request. This addresses discussion #10460 ("a binary lookup should not require HTTP calls").

Root cause

The list of commands that auto-enable prefer_offline lives in src/env.rs (prefer_offline()): it contained activate, current, direnv, env, exec, hook-env, ls, where, x but not which. As a result, mise which <bin> resolved with prefer_offline = false. When an explicit minimum_release_age cutoff is configured, filters_installed_versions() is true (tool_version.rs), which forces date-aware remote resolution for non-prefer-offline commands even when an installed version matches.

Fix

  • Add "which" to the prefer-offline command list in src/env.rs.
  • Update the prefer_offline docs string in settings.toml to mention which. (The JSON schema only embeds the description field, not the docs prose, so no schema regeneration is needed.)

Testing

  • New network-free e2e regression test e2e/cli/test_which_prefer_offline, modeled on test_hook_env_no_remote_fetch: it copies the dummy plugin into a spy plugin whose list-all/latest-stable touch a marker file, sets MISE_MINIMUM_RELEASE_AGE=24h, and asserts mise which dummy resolves the installed spy@1.0.0 without recreating the marker (i.e. without a remote fetch). This fails before the fix and passes after.
  • shellcheck -x passes on the new test.

Scope note

The fix covers config-file tools (the reported scenario). 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 deliberately left unchanged and is documented as out of scope in the test.

Note

Local builds/tests were not run in the authoring sandbox (insufficient memory); compilation and e2e are left to CI.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Ensured mise which fully honors prefer_offline, resolving installed versions without triggering remote version lookups when offline preference is enabled.
  • Documentation
    • Updated prefer_offline documentation to list which alongside other commands that avoid remote version fetching.
  • Tests
    • Added an end-to-end regression test confirming mise which remains offline for config-file-based tool resolution (including minimum release age modes) when an installed version already satisfies the requested version.

@coderabbitai

coderabbitai Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 44358e35-75c6-44ca-8966-cfec9da36b35

📥 Commits

Reviewing files that changed from the base of the PR and between eb691de and c16229c.

📒 Files selected for processing (3)
  • e2e/cli/test_which_prefer_offline
  • settings.toml
  • src/env.rs
✅ Files skipped from review due to trivial changes (1)
  • settings.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • e2e/cli/test_which_prefer_offline
  • src/env.rs

📝 Walkthrough

Walkthrough

Adds "which" to the prefer_offline() command-name allowlist in src/env.rs, updates the prefer_offline setting documentation in settings.toml to list which among the commands that skip remote fetches, and introduces a new e2e bash test verifying mise which resolves offline when the installed version satisfies the config.

Changes

prefer_offline extension for mise which

Layer / File(s) Summary
prefer_offline allowlist and documentation update
src/env.rs, settings.toml
Adds "which" to the command-name list in prefer_offline() so argv parsing triggers offline behavior for that command; docs updated to list which alongside ls, current, where, and shims.
e2e regression test
e2e/cli/test_which_prefer_offline
New bash test configures a spy plugin whose remote listing scripts write a marker file, installs spy@1.0.0, clears caches and the marker, then asserts mise which resolves to the installed version without triggering any remote fetch for version constraints latest, 1, and 1.0.0 under both unset and 24h minimum-release-age modes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hippity-hop, no network today,
mise which now knows to stay away!
The spy plugin watches, but no marker appears,
Offline resolution calms all our fears.
A single-line fix, yet the path rings true —
"which" joins the club, hurray, we're through! 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: enabling prefer_offline for the 'which' command to prevent remote fetches during binary lookup.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes mise which to respect prefer_offline by adding it to the auto-enable list in src/env.rs, preventing remote version fetches when an installed version already satisfies the request.

  • Core fix (src/env.rs): One-line addition of "which" between "where" and "x" in the prefer-offline command array, maintaining alphabetical order.
  • Docs (settings.toml): prefer_offline description updated to include which alongside the other auto-enabled commands.
  • Test (e2e/cli/test_which_prefer_offline): End-to-end regression test using a spy plugin that touches a marker file on any remote fetch; covers both unset and 24h minimum_release_age values and all three version specifier forms (latest, prefix, exact), directly matching the coverage of the analogous test_hook_env_no_remote_fetch.

Confidence Score: 5/5

Safe to merge — the change is a single-line addition to a well-understood allow-list with no effect on any code path other than mise which offline resolution.

The fix is minimal and isolated: one entry added to the prefer-offline command list, a matching docs update, and a well-constructed regression test that would have caught the original bug and guards against future regressions. The test structure mirrors the established pattern from test_hook_env_no_remote_fetch and correctly covers the fuzzy-version specifiers that trigger date-aware resolution.

No files require special attention.

Important Files Changed

Filename Overview
src/env.rs Adds "which" to the prefer-offline auto-enable list in alphabetical order, between "where" and "x" — a one-liner fix that is correct and minimal.
settings.toml Updates the prefer_offline docs string to mention which alongside the other auto-enabled commands — accurate and consistent with the code change.
e2e/cli/test_which_prefer_offline New regression test modeled on test_hook_env_no_remote_fetch; correctly covers both the unset and 24h minimum_release_age cases and all three version specifiers (latest, prefix, exact). The spy plugin marker pattern is sound and the --version output assertion directly validates the resolved version.

Reviews (4): Last reviewed commit: "fix(which): respect prefer_offline so bi..." | Re-trigger Greptile

Comment thread e2e/cli/test_which_prefer_offline Resolved
Comment thread e2e/cli/test_which_prefer_offline Resolved
@JamBalaya56562
JamBalaya56562 force-pushed the fix-which-prefer-offline branch 2 times, most recently from b710d0d to eb691de Compare June 24, 2026 02:06

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
e2e/cli/test_which_prefer_offline (1)

20-20: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using a unique temporary path for the marker file.

The marker uses a fixed path in $HOME that could theoretically conflict with other tests if they use the same name or if test isolation is imperfect. While e2e frameworks typically isolate $HOME per test, using a unique temporary location (e.g., mktemp or $PWD/marker-$$) would be more defensive.

Alternative approach
-marker="$HOME/remote-versions-fetched"
+marker="$(pwd)/.remote-versions-fetched-$$"

Or use a temp file:

-marker="$HOME/remote-versions-fetched"
+marker="$(mktemp)"
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@e2e/cli/test_which_prefer_offline` at line 20, The marker file path at line
20 uses a fixed location in $HOME which could cause test conflicts or isolation
issues. Replace the fixed path marker="$HOME/remote-versions-fetched" with a
unique temporary path by either using mktemp to generate a temporary file path,
or by constructing a path with the process ID (using $$) in the current working
directory (e.g., $PWD/marker-$$). Update all references to the marker variable
throughout the test to use this new unique path consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@e2e/cli/test_which_prefer_offline`:
- Around line 22-31: The plugin scripts created with `cat >` for `list-all` and
`latest-stable` in the spy plugin directory are not executable by default, which
will cause permission errors when Mise tries to run them. After each `cat >`
command that creates these scripts, add a `chmod +x` command to set the
executable bit on the newly created files so they can be properly executed
during the test.
- Line 19: The comment at line 19 incorrectly states that cat > preserves the
executable bit from copied scripts. In reality, cat > creates files with default
permissions (typically 644) that are not executable. Correct this comment to
accurately describe that cat > does not preserve executable permissions, and
that if the scripts need to be executable, an explicit chmod +x would be
required instead.

---

Nitpick comments:
In `@e2e/cli/test_which_prefer_offline`:
- Line 20: The marker file path at line 20 uses a fixed location in $HOME which
could cause test conflicts or isolation issues. Replace the fixed path
marker="$HOME/remote-versions-fetched" with a unique temporary path by either
using mktemp to generate a temporary file path, or by constructing a path with
the process ID (using $$) in the current working directory (e.g.,
$PWD/marker-$$). Update all references to the marker variable throughout the
test to use this new unique path consistently.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Central YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 12d3a133-0e2f-4986-9c72-419f3322ad28

📥 Commits

Reviewing files that changed from the base of the PR and between b710d0d and eb691de.

📒 Files selected for processing (3)
  • e2e/cli/test_which_prefer_offline
  • settings.toml
  • src/env.rs
✅ Files skipped from review due to trivial changes (2)
  • src/env.rs
  • settings.toml

Comment thread e2e/cli/test_which_prefer_offline Resolved
Comment thread e2e/cli/test_which_prefer_offline Resolved
…ches

`mise which` is a binary lookup and should not require HTTP calls when an
installed version already satisfies the request. Add `which` to the
prefer-offline auto-enable command list (alongside `where`, `ls`, `exec`,
etc.) so version resolution prefers cached/installed data instead of fetching
remote version lists -- e.g. when an explicit `minimum_release_age` cutoff is
configured, which otherwise forces date-aware remote resolution.

Adds a network-free e2e regression test using a marker-spy plugin.

Resolves jdx#10460

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@JamBalaya56562
JamBalaya56562 force-pushed the fix-which-prefer-offline branch from eb691de to c16229c Compare June 24, 2026 02:22
@jdx
jdx merged commit d1fb2de into jdx:main Jun 24, 2026
34 checks passed
@JamBalaya56562
JamBalaya56562 deleted the fix-which-prefer-offline branch June 24, 2026 04:02
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.

2 participants