Skip to content

fix(env): pass dependency env to vfox backend plugin hooks#8952

Merged
jdx merged 5 commits intojdx:mainfrom
cprecioso:cprecioso/depends-env-reload
Apr 7, 2026
Merged

fix(env): pass dependency env to vfox backend plugin hooks#8952
jdx merged 5 commits intojdx:mainfrom
cprecioso:cprecioso/depends-env-reload

Conversation

@cprecioso
Copy link
Copy Markdown
Contributor

Summary

  • When a vfox backend plugin has depends on another tool, the dependency installs first but the plugin's Lua hooks (BackendListVersions, BackendInstall, BackendExecEnv) couldn't find the dependency's binaries on PATH
  • Add a cmd_env field to the Vfox struct that calls plugin.set_cmd_env() before executing backend hooks, populated from dependency_env() (already used by go, gem, npm, cargo, spm, dotnet backends)

Closes #8951

Test plan

  • Added unit tests in crates/vfox/src/vfox.rs with a dummy-backend test fixture plugin that verifies cmd_env propagation to Lua hooks
  • mise run build passes
  • mise --cd crates/vfox run test passes (64 tests, 0 failures)
  • mise run test:unit passes (591 tests, 0 failures)

🤖 Generated with Claude Code

When a vfox backend plugin has `depends` on another tool, the
dependency installs first but the plugin's Lua hooks
(BackendListVersions, BackendInstall, BackendExecEnv) couldn't find
the dependency's binaries on PATH.

Add a `cmd_env` field to the Vfox struct that, when set, calls
`plugin.set_cmd_env()` before executing backend hooks. In
VfoxBackend, populate this from `dependency_env()` (already used by
go, gem, npm, cargo, spm, dotnet backends) so dependency bin paths
are on PATH during version resolution and installation.

Closes jdx#8951

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 a cmd_env field to the Vfox struct, enabling the propagation of dependency environments to Lua plugins. This ensures that tools executed via cmd.exec() within plugins have the correct environment variables, such as PATH. The changes update the backend_list_versions, backend_install, and backend_exec_env hooks to respect this new configuration. Feedback indicates that the _exec_env method in src/backend/vfox.rs was missed and should also be updated. Furthermore, it is suggested to extend this environment propagation to other hooks like list_available_versions and to move the environment population logic outside the is_backend_plugin conditional for better consistency across all plugin types.

Comment thread crates/vfox/src/vfox.rs Outdated
Comment thread crates/vfox/src/vfox.rs
Comment thread src/backend/vfox.rs
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 7, 2026

Greptile Summary

This PR fixes vfox backend plugins that declare depends on another tool — the dependency tool's environment (including its PATH entries) is now forwarded into Lua hook calls (BackendListVersions, BackendInstall, BackendExecEnv) via a new cmd_env field on the Vfox struct. The implementation follows the same pattern already used by go, gem, npm, cargo, spm, and dotnet backends, and includes a well-constructed dummy-backend test fixture with proper #[cfg(unix)] gating.

Confidence Score: 5/5

Safe to merge — correct fix, consistent with existing backend patterns, well-tested with unix guard

All three hook-dispatch sites in src/backend/vfox.rs are updated, all six get_sdk() call sites in the vfox crate now use get_sdk_with_env(), the #[cfg(unix)] guard correctly handles the printenv platform difference, and no P0/P1 issues were found. The silent-ignore pattern for dependency_env errors matches the gem backend's own precedent.

No files require special attention

Important Files Changed

Filename Overview
crates/vfox/src/vfox.rs Adds cmd_env field to Vfox struct and get_sdk_with_env() helper; updates 6 hook-dispatch paths to apply env before executing Lua hooks; adds two unit tests (unix-gated where needed)
src/backend/vfox.rs Populates vfox.cmd_env from dependency_env() in all three hook-dispatch sites (list_remote_versions, install_version, get_exec_env), using the same silent-ignore pattern as the gem backend
crates/vfox/plugins/dummy-backend/hooks/backend_list_versions.lua New test fixture hook: reads MY_TEST_VAR via printenv, returns 'fallback' on failure — enables env-propagation unit tests
crates/vfox/plugins/dummy-backend/metadata.lua Minimal plugin metadata for the dummy-backend test fixture

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[VfoxBackend hook method called] --> B[Create vfox instance via plugin.vfox]
    B --> C[dependency_env config]
    C -->|Ok| D[vfox.cmd_env = Some dep_env]
    C -->|Err - silently ignored| E[vfox.cmd_env remains None]
    D --> F[get_sdk_with_env name]
    E --> F
    F --> G{cmd_env set?}
    G -->|Yes| H[plugin.set_cmd_env env]
    G -->|No| I[plugin used as-is]
    H --> J[Execute Lua hook]
    I --> J
    J --> K[Dependency binaries available on PATH in cmd.exec]
Loading

Reviews (5): Last reviewed commit: "Merge branch 'main' into cprecioso/depen..." | Re-trigger Greptile

@cprecioso cprecioso marked this pull request as draft April 7, 2026 08:01
Move cmd_env population before the is_backend_plugin() branch so
traditional vfox plugins also get dependency tools on PATH. Add
get_sdk_with_env() helper to consolidate the set_cmd_env pattern
across all hook methods. Also add cmd_env to _exec_env which was
missed in the initial commit.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Comment thread crates/vfox/src/vfox.rs
printenv is Unix-only; on Windows the pcall fallback would cause
the assertion to fail. Guard the test so Windows CI is not broken.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@cprecioso cprecioso marked this pull request as ready for review April 7, 2026 09:17
@jdx jdx merged commit c9c06a6 into jdx:main Apr 7, 2026
34 checks passed
mise-en-dev added a commit that referenced this pull request Apr 7, 2026
### 🚀 Features

- **(config)** Add Tera template support to miserc.toml by
@richardthe3rd in [#8867](#8867)

### 🐛 Bug Fixes

- **(env)** include tools-only redactions in `mise env --redacted` by
@jakedgy in [#8956](#8956)
- **(env)** pass dependency env to vfox backend plugin hooks by
@cprecioso in [#8952](#8952)
- **(shim)** fix race condition when removing in make_shim, when
multiple plugins provide the same shim by @brander-john in
[#8947](#8947)
- **(spm)** derive API URL from host for self-hosted instances by
@ThomasDutartre in [#8955](#8955)
- **(task)** resolve env vars in usage tera templates when flags are
provided by @jdx in [#8957](#8957)

### 📚 Documentation

- **(python)** clarify attestation settings must be under [settings] in
mise.toml by @fru1tworld in
[#8939](#8939)

### 📦 Registry

- added sing-box by @tony-sol in
[#8944](#8944)

### Chore

- **(ci)** remove auto-draft PR workflow by @jdx in
[#8945](#8945)

### New Contributors

- @ThomasDutartre made their first contribution in
[#8955](#8955)
- @jakedgy made their first contribution in
[#8956](#8956)
- @brander-john made their first contribution in
[#8947](#8947)
- @fru1tworld made their first contribution in
[#8939](#8939)
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