Skip to content

fix(backend): make pre-tools env vars available in postinstall hooks#6418

Merged
jdx merged 1 commit intomainfrom
fix/postinstall-pre-tools-env
Sep 25, 2025
Merged

fix(backend): make pre-tools env vars available in postinstall hooks#6418
jdx merged 1 commit intomainfrom
fix/postinstall-pre-tools-env

Conversation

@jdx
Copy link
Owner

@jdx jdx commented Sep 25, 2025

Summary

  • Fixed an issue where postinstall hooks could not access pre-tools environment variables
  • Environment variables defined with tools=false (or without the tools parameter) are now available in postinstall hooks
  • Added e2e test to verify the behavior

Problem

Tool postinstall hooks were only receiving exec_env from the backend, which was typically empty. This meant that environment variables defined in mise.toml were not available during the postinstall phase, even if they were marked as pre-tools variables (not dependent on tools being loaded).

Solution

Modified run_postinstall_hook in src/backend/mod.rs to include pre-tools environment variables from the config. The function now:

  1. Gets the exec_env as before
  2. Adds pre-tools environment variables from ctx.config.env_maybe()
  3. Passes the combined environment to the postinstall script

Test plan

  • Added e2e test test_hooks_postinstall_env that verifies:
    • Pre-tools environment variables are available in postinstall hooks
    • Environment variables with tools=true are NOT available (as expected)
  • All existing tests pass
  • Linting passes

🤖 Generated with Claude Code

Environment variables defined with tools=false (or without the tools
parameter) are now available in postinstall hooks. This allows
postinstall scripts to access configuration-defined environment
variables during tool installation.

Previously, postinstall hooks only had access to exec_env which was
typically empty. Now they also receive pre-tools environment variables
from the config.

Added e2e test to verify the behavior works correctly.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings September 25, 2025 16:29
Copy link
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

This PR fixes an issue where postinstall hooks couldn't access pre-tools environment variables defined in mise.toml. The solution modifies the postinstall hook execution to include environment variables that are available before tools are loaded.

  • Modified run_postinstall_hook to include pre-tools environment variables from config
  • Added comprehensive e2e test to verify environment variable availability in postinstall hooks
  • Ensured variables marked with tools=true are properly excluded from postinstall context

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/backend/mod.rs Updated postinstall hook execution to include pre-tools environment variables
e2e/config/test_hooks_postinstall_env Added e2e test verifying correct environment variable behavior in postinstall hooks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

// Add pre-tools environment variables from config if available
if let Some(config_env) = ctx.config.env_maybe() {
for (k, v) in config_env {
env_vars.entry(k).or_insert(v);
Copy link

Copilot AI Sep 25, 2025

Choose a reason for hiding this comment

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

The or_insert method will skip config environment variables if they already exist in exec_env. This may not be the intended behavior if config variables should take precedence over exec_env variables. Consider using env_vars.insert(k, v) instead to ensure config variables override exec_env variables.

Suggested change
env_vars.entry(k).or_insert(v);
env_vars.insert(k, v);

Copilot uses AI. Check for mistakes.
@jdx jdx merged commit 8de1218 into main Sep 25, 2025
19 checks passed
@jdx jdx deleted the fix/postinstall-pre-tools-env branch September 25, 2025 16:43
@github-actions
Copy link

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.18 x -- echo 19.1 ± 0.3 18.6 21.4 1.00
mise x -- echo 19.4 ± 0.4 18.6 21.0 1.01 ± 0.03

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.18 env 18.5 ± 0.3 18.0 21.6 1.00
mise env 18.8 ± 0.5 18.2 21.3 1.02 ± 0.03

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.18 hook-env 18.5 ± 0.3 17.9 20.0 1.00 ± 0.03
mise hook-env 18.4 ± 0.4 17.7 22.1 1.00

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.9.18 ls 16.3 ± 0.4 15.7 18.0 1.00
mise ls 16.4 ± 0.3 15.7 18.6 1.00 ± 0.03

xtasks/test/perf

Command mise-2025.9.18 mise Variance
install (cached) 166ms ✅ 103ms +61%
ls (cached) 62ms 62ms +0%
bin-paths (cached) 69ms 68ms +1%
task-ls (cached) 468ms 469ms +0%

✅ Performance improvement: install cached is 61%

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