Skip to content

feat: Make config_root available to environment plugins for relative path resolution#9465

Merged
jdx merged 4 commits intojdx:mainfrom
hisaac:hisaac/inject-config-path-into-env-plugins
Apr 29, 2026
Merged

feat: Make config_root available to environment plugins for relative path resolution#9465
jdx merged 4 commits intojdx:mainfrom
hisaac:hisaac/inject-config-path-into-env-plugins

Conversation

@hisaac
Copy link
Copy Markdown

@hisaac hisaac commented Apr 29, 2026

Note

I'm very open to suggestions or corrections. I'm not an experienced Rust developer, and this is my first contribution to this project.

What's changed?

This PR makes the config_root variable available to environment plugins.

Context

While working on an environment plugin (https://github.com/hisaac/mise-xcode), I ran into issues resolving relative paths. In the environment plugin, any relative path is resolved based on the current working directory. If the mise.toml file is used from a directory other than the config root, paths are not resolved correctly.

I noticed that the built-in environment plugins like file and python do have access to config_root. So this change is to provide that variable to non-built-in plugins.

How to test

I've done some testing locally using my mise-xcode plugin, and from what I can tell this works as expected. Let me know if there's any specific testing I should do.

@hisaac hisaac changed the title Make config_root available to environment plugins for relative path resolution feat: Make config_root available to environment plugins for relative path resolution Apr 29, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces config_root to the mise_env and mise_path hooks, enabling plugins to resolve relative paths relative to the configuration file's directory instead of the current working directory. The changes span the vfox crate, the plugin system, and the environment module directive, and include a new end-to-end test. Review feedback suggests improving the handling of path-to-string conversions in vfox_plugin.rs by using and_then instead of unwrap_or_default to prevent passing empty strings when encoding fails.

Comment thread src/plugins/vfox_plugin.rs Outdated
Comment thread src/plugins/vfox_plugin.rs Outdated
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR propagates config_root (the directory of the mise.toml that defines the module directive) into the MiseEnvContext and MisePathContext Lua tables, making it available to vfox environment plugins via ctx.config_root. It also fixes relative watch_files to be anchored against config_root instead of cwd, which is a correctness improvement.

Confidence Score: 5/5

Safe to merge — clean, focused change with no P0/P1 issues and good test coverage.

The implementation is correct: config_root is computed once, passed through each layer with proper Option propagation, and non-UTF-8 paths are handled via and_then. The watch_files cwd→config_root fix is a genuine correctness improvement. Previous review concerns have been addressed.

No files require special attention.

Important Files Changed

Filename Overview
src/config/env_directive/module.rs Core change: computes config_root once and passes it to both mise_env and mise_path; also fixes watch_files resolution from cwd to config_root.
src/plugins/vfox_plugin.rs Adds config_root: Option<&Path> parameter to mise_env/mise_path; uses and_then for UTF-8 conversion, correctly propagating None for non-UTF-8 paths.
crates/vfox/src/vfox.rs Threads config_root: Option<&str> through mise_env and mise_path to the context structs.
crates/vfox/src/hooks/mise_env.rs Adds config_root: Option field to MiseEnvContext and serializes it to the Lua table.
crates/vfox/src/hooks/mise_path.rs Adds config_root: Option field to MisePathContext and serializes it to the Lua table.
e2e/env/test_env_module_config_root New e2e test covering global config, project-level, and cwd-stable config_root scenarios using a synthetic vfox plugin.

Sequence Diagram

sequenceDiagram
    participant M as module.rs
    participant VFP as VfoxPlugin
    participant VFX as Vfox (crate)
    participant LUA as Lua Plugin

    M->>M: config_root = config_root(&source)
    M->>VFP: mise_env(opts, env, Some(&config_root))
    VFP->>VFP: config_root.and_then(|p| p.to_str())
    VFP->>VFX: mise_env(name, opts, env, config_root: Option<&str>)
    VFX->>VFX: MiseEnvContext { options, config_root }
    VFX->>LUA: ctx.options, ctx.config_root
    LUA-->>VFX: { env, watch_files, cacheable }
    VFX-->>VFP: MiseEnvResult
    VFP-->>M: Option<MiseEnvResponse>
    M->>M: resolve relative watch_files against config_root
Loading

Reviews (4): Last reviewed commit: "[autofix.ci] apply automated fixes" | Re-trigger Greptile

Comment thread src/plugins/vfox_plugin.rs Outdated
Comment thread src/plugins/vfox_plugin.rs Outdated
Comment thread mise.lock
@jdx jdx enabled auto-merge (squash) April 29, 2026 13:27
@jdx jdx merged commit dcb03fb into jdx:main Apr 29, 2026
35 checks passed
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