fix(task): resolve env vars in usage tera templates when flags are provided#8957
fix(task): resolve env vars in usage tera templates when flags are provided#8957
Conversation
…ovided
parse_usage_values_from_task was creating an empty EnvMap which
overwrote the real env context in the tera renderer, causing
`{{ env.VAR }}` in usage field defaults to fail when any flags
were passed to the task.
Fixes #8954
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Greptile SummaryThis PR fixes a bug where Confidence Score: 5/5Safe to merge — the fix is minimal and well-targeted, with a direct regression test covering the reported failure. The change is two lines, replaces an obviously wrong empty map with the correct toolset-derived environment, is consistent with how env is used everywhere else in the codebase, and is guarded by a new e2e test that exercises all three scenarios (no flags, explicit flag, --help). No P0/P1 findings. No files require special attention.
|
| Filename | Overview |
|---|---|
| src/task/mod.rs | Two-line fix replacing Default::default() (empty EnvMap) with ts.full_env(config).await? so Tera templates referencing env.* resolve correctly during usage spec parsing. |
| e2e/tasks/test_task_usage_env_default_tera | New e2e regression test covering: env-based usage defaults without flags, with an explicit flag override, --help rendering, and system env vars (HOME) as defaults. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[mise run task --flag value] --> B[parse_usage_values_from_task]
B --> C{Before fix}
B --> D{After fix}
C --> E[EnvMap = empty default]
D --> F[config.get_toolset]
F --> G[ts.full_env - real env vars]
E --> H[parse_usage_spec_with_vars]
G --> H
H --> I{Tera template with env.VAR?}
I -- EnvMap empty --> J[ERROR: Variable not found]
I -- EnvMap populated --> K[Template renders correctly]
K --> L[usage::Parser resolves flag defaults]
L --> M[Return IndexMap of flag values]
Reviews (2): Last reviewed commit: "fix(task): use full_env to include syste..." | Re-trigger Greptile
There was a problem hiding this comment.
Code Review
This pull request adds a regression test to ensure that Tera environment templates work correctly within task usage fields and updates the parse_usage_values_from_task function to retrieve the environment from the toolset. Feedback suggests using full_env instead of env_with_path to maintain consistency with existing patterns in the module and to align with the pull request's stated intent.
| ) -> Result<IndexMap<String, String>> { | ||
| let env: EnvMap = Default::default(); | ||
| let ts = config.get_toolset().await?; | ||
| let env = ts.env_with_path(config).await?; |
There was a problem hiding this comment.
For consistency with other parts of src/task/mod.rs (e.g., lines 1010 and 1181) and to align with the PR description which mentions full_env(), consider using ts.full_env(config) instead of ts.env_with_path(config). Both likely provide the necessary environment, but full_env is the established pattern in this module for obtaining the environment to be used in Tera contexts, ensuring that {{ env.VAR }} references behave identically across all task templates.
| let env = ts.env_with_path(config).await?; | |
| let env = ts.full_env(config).await?; |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 1f563f5. Configure here.
env_with_path only includes mise-managed env vars, but full_env also
includes system variables (PRISTINE_ENV). Without this, references
like {{ env.HOME }} in usage defaults would fail during dependency
resolution while working fine during actual task execution.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Hyperfine Performance
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.4.5 x -- echo |
26.7 ± 0.5 | 24.6 | 28.0 | 1.01 ± 0.03 |
mise x -- echo |
26.6 ± 0.7 | 24.7 | 30.9 | 1.00 |
mise env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.4.5 env |
25.4 ± 0.7 | 23.7 | 30.3 | 1.00 |
mise env |
25.9 ± 1.1 | 24.2 | 38.3 | 1.02 ± 0.05 |
mise hook-env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.4.5 hook-env |
26.4 ± 0.5 | 25.0 | 28.7 | 1.00 |
mise hook-env |
27.4 ± 0.7 | 25.7 | 37.1 | 1.04 ± 0.03 |
mise ls
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.4.5 ls |
24.0 ± 1.3 | 22.8 | 39.8 | 1.00 |
mise ls |
24.4 ± 1.1 | 22.4 | 40.0 | 1.01 ± 0.07 |
xtasks/test/perf
| Command | mise-2026.4.5 | mise | Variance |
|---|---|---|---|
| install (cached) | 160ms | 158ms | +1% |
| ls (cached) | 84ms | 85ms | -1% |
| bin-paths (cached) | 89ms | 90ms | -1% |
| task-ls (cached) | 809ms | 804ms | +0% |
### 🚀 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)

Summary
parse_usage_values_from_taskwas creating an emptyEnvMapand passing it toparse_run_scripts, which overwrote the real env context (already populated bytask.tera_ctx()→toolset.tera_ctx()→full_env()) with empty data{{ env.VAR }}references in taskusagefield defaults to fail with "Variable not found in context" whenever any flags were passed to the taskFixes #8954
Test plan
test_task_usage_env_default_teracovering:{{ env.DEFAULT_FILE }}in usage default runs without flags{{ env.DEFAULT_FILE }}in usage default runs with explicit flag override--helprenders without errortest_task_usage_env,test_task_usage_env_tera,test_task_monorepo_usage_env,test_task_dep_args)🤖 Generated with Claude Code
Note
Medium Risk
Moderate risk because it changes how task CLI args/flags are parsed by wiring in the full computed environment, which could affect usage default evaluation across tasks; scope is small and covered by a targeted e2e regression test.
Overview
Fixes a regression where task
usagedefaults using Tera{{ env.* }}templates could fail when flags were provided by ensuringparse_usage_values_from_taskuses the toolset’s full environment rather than an emptyEnvMap.Adds an e2e regression test (
test_task_usage_env_default_tera) that verifies env-based usage defaults work with no flags, with explicit flag overrides, with--help, and with system env vars likeHOME.Reviewed by Cursor Bugbot for commit 2f5821b. Bugbot is set up for automated code reviews on this repo. Configure here.