fix(backend): make pre-tools env vars available in postinstall hooks#6418
fix(backend): make pre-tools env vars available in postinstall hooks#6418
Conversation
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>
There was a problem hiding this comment.
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_hookto include pre-tools environment variables from config - Added comprehensive e2e test to verify environment variable availability in postinstall hooks
- Ensured variables marked with
tools=trueare 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); |
There was a problem hiding this comment.
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.
| env_vars.entry(k).or_insert(v); | |
| env_vars.insert(k, v); |
Hyperfine Performance
|
| 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%
Summary
tools=false(or without thetoolsparameter) are now available in postinstall hooksProblem
Tool postinstall hooks were only receiving
exec_envfrom the backend, which was typically empty. This meant that environment variables defined inmise.tomlwere 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_hookinsrc/backend/mod.rsto include pre-tools environment variables from the config. The function now:ctx.config.env_maybe()Test plan
test_hooks_postinstall_envthat verifies:tools=trueare NOT available (as expected)🤖 Generated with Claude Code