Skip to content

fix(config): use correct config_root in tera context for hooks#7309

Merged
jdx merged 1 commit intomainfrom
fix/config-root-hooks
Dec 15, 2025
Merged

fix(config): use correct config_root in tera context for hooks#7309
jdx merged 1 commit intomainfrom
fix/config-root-hooks

Conversation

@jdx
Copy link
Copy Markdown
Owner

@jdx jdx commented Dec 15, 2025

Summary

  • Fixed config_root template variable in hooks incorrectly pointing to .mise/ directory instead of the project root
  • When a config file is in a .mise/ subdirectory (e.g., ~/src/foo/.mise/config.toml), {{config_root}} now correctly resolves to ~/src/foo/ instead of ~/src/foo/.mise/
  • Added e2e test to verify the fix

Root Cause

In MiseToml::from_str(), the tera context's config_root was set using path.parent(), which returns the immediate parent directory. For a config at ~/src/foo/.mise/config.toml, this would incorrectly return ~/src/foo/.mise/.

The fix uses config_root::config_root(path) which correctly calculates the project root by detecting .mise/ directories and returning their parent.

Test plan

  • Added e2e test test_hooks_config_root that verifies {{config_root}} in hooks points to the project root when using .mise/config.toml
  • All existing unit tests pass (377 tests)
  • All hooks-related e2e tests pass

Fixes: #6531

🤖 Generated with Claude Code


Note

Fixes {{config_root}} in hooks to resolve to the project root (not .mise) and adds an e2e test to verify.

  • Config/Templating:
    • In src/config/config_file/mise_toml.rs, populate Tera context config_root using config_root::config_root(path) in MiseToml::from_str, ensuring hooks see the project root.
  • Tests:
    • Add e2e/config/test_hooks_config_root to assert CONFIG_ROOT equals the workdir root and not .mise.

Written by Cursor Bugbot for commit 637d6f6. This will update automatically on new commits. Configure here.

When a config file is in a .mise/ subdirectory (e.g., ~/src/foo/.mise/config.toml),
the config_root template variable in hooks incorrectly resolved to the .mise/
directory instead of the project root.

This was because MiseToml::from_str() was using path.parent() to set config_root
in the tera context, which returns ~/src/foo/.mise/ for a config at
~/src/foo/.mise/config.toml.

The fix uses config_root::config_root() which correctly calculates the project
root by detecting .mise/ directories and returning the parent.

Fixes: #6531

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 15, 2025 12:15
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

This PR fixes a bug where the config_root template variable in hooks incorrectly resolved to the .mise/ subdirectory instead of the project root when the config file was located at .mise/config.toml.

Key changes:

  • Updated MiseToml::from_str() to use config_root::config_root(path) instead of path.parent() for determining the config root
  • Added e2e test to verify the fix works correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/config/config_file/mise_toml.rs Fixed config_root calculation to use config_root::config_root(path) helper function
e2e/config/test_hooks_config_root Added test verifying config_root correctly points to project root for .mise/config.toml

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

@jdx jdx enabled auto-merge (squash) December 15, 2025 12:22
@github-actions
Copy link
Copy Markdown

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.12.7 x -- echo 20.5 ± 0.7 19.9 27.0 1.00
mise x -- echo 20.6 ± 0.5 19.9 25.0 1.00 ± 0.04

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.12.7 env 20.0 ± 0.3 19.3 21.0 1.00
mise env 20.3 ± 0.9 19.6 29.4 1.02 ± 0.05

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.12.7 hook-env 20.2 ± 0.5 19.4 26.2 1.00
mise hook-env 20.3 ± 0.5 19.5 22.7 1.01 ± 0.04

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2025.12.7 ls 16.8 ± 0.3 16.3 17.9 1.00
mise ls 17.1 ± 0.5 16.5 22.6 1.01 ± 0.03

xtasks/test/perf

Command mise-2025.12.7 mise Variance
install (cached) 109ms 110ms +0%
ls (cached) 66ms 66ms +0%
bin-paths (cached) 72ms 73ms -1%
task-ls (cached) 446ms 428ms +4%

@jdx jdx merged commit e422134 into main Dec 15, 2025
30 checks passed
@jdx jdx deleted the fix/config-root-hooks branch December 15, 2025 12:31
jdx pushed a commit that referenced this pull request Dec 15, 2025
### 🚀 Features

- **(conda)** add dependency resolution for conda packages by @jdx in
[#7280](#7280)
- **(go)** add created_at support to ls-remote --json by @jdx in
[#7305](#7305)
- **(hook-env)** add hook_env.cache_ttl and hook_env.chpwd_only settings
for NFS optimization by @jdx in
[#7312](#7312)
- **(hooks)** add MISE_TOOL_NAME and MISE_TOOL_VERSION to
preinstall/postinstall hooks by @jdx in
[#7311](#7311)
- **(shell_alias)** add shell_alias support for cross-shell aliases by
@jdx in [#7316](#7316)
- **(tool)** add security field to mise tool --json by @jdx in
[#7303](#7303)
- add --before flag for date-based version filtering by @jdx in
[#7298](#7298)

### 🐛 Bug Fixes

- **(aqua)** support cosign v3 bundle verification by @jdx in
[#7314](#7314)
- **(config)** use correct config_root in tera context for hooks by @jdx
in [#7309](#7309)
- **(nu)** fix nushell deactivation script on Windows by @fu050409 in
[#7213](#7213)
- **(python)** apply uv_venv_create_args in auto-venv code path by @jdx
in [#7310](#7310)
- **(shell)** escape exe path in activation scripts for paths with
spaces by @jdx in [#7315](#7315)
- **(task)** parallelize exec_env loading to fix parallel task execution
by @jdx in [#7313](#7313)
- track downloads for python and java by @jdx in
[#7304](#7304)
- include full tool ID in download track by @jdx in
[#7320](#7320)

### 📚 Documentation

- Switch `postinstall` code to be shell-agnostic by @thejcannon in
[#7317](#7317)

### 🧪 Testing

- **(e2e)** disable debug mode by default for windows-e2e by @jdx in
[#7318](#7318)

### New Contributors

- @fu050409 made their first contribution in
[#7213](#7213)
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