fix(task): pass env to usage parser for env-backed arguments#7848
Conversation
Fixes jdx/usage#468. When usage specs contain `env="VAR_NAME"` attributes, the usage parser needs access to the environment to resolve defaults from environment variables. The `parse_usage_spec_and_init_env` function in task_executor.rs was using `usage::parse()` without passing the environment, causing env-backed args to always fall back to their default values instead of reading from the shell environment. Now uses `usage::Parser::new().with_env()` to pass the task's full environment (which includes inherited shell env vars) to the parser. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where usage spec arguments with env="VAR_NAME" attributes were not reading from the shell environment, always falling back to defaults instead. The fix passes the environment map to the usage parser so it can properly resolve environment-backed arguments.
Changes:
- Modified task executor to pass environment variables to the usage parser
- Added comprehensive e2e test verifying environment inheritance behavior
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/task/task_executor.rs | Updated to pass env map to usage::Parser for resolving env-backed arguments |
| e2e/tasks/test_task_usage_env_inherited | Added test verifying env inheritance, explicit arg override, and default fallback |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cat <<EOF >mise.toml | ||
| [tasks.test] | ||
| usage = ''' | ||
| arg "[host]" env="TEST_HOST" default="localhost" | ||
| ''' | ||
| run = 'echo "Host: \${usage_host}"' |
There was a problem hiding this comment.
The escape sequence in the echo command may not work as intended. The variable reference should be $usage_host without the backslash escape, or use single quotes in the HEREDOC to prevent shell expansion.
| cat <<EOF >mise.toml | |
| [tasks.test] | |
| usage = ''' | |
| arg "[host]" env="TEST_HOST" default="localhost" | |
| ''' | |
| run = 'echo "Host: \${usage_host}"' | |
| cat <<'EOF' >mise.toml | |
| [tasks.test] | |
| usage = ''' | |
| arg "[host]" env="TEST_HOST" default="localhost" | |
| ''' | |
| run = 'echo "Host: ${usage_host}"' |
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.
- Use quoted heredoc (<<'EOF') to prevent shell expansion - Use assert_contains helper instead of inline assertions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Hyperfine Performance
|
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.1.8 x -- echo |
20.3 ± 0.4 | 19.4 | 21.4 | 1.00 |
mise x -- echo |
20.7 ± 0.4 | 19.8 | 23.3 | 1.02 ± 0.03 |
mise env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.1.8 env |
19.9 ± 0.5 | 18.9 | 26.5 | 1.00 |
mise env |
20.8 ± 0.7 | 19.6 | 25.3 | 1.05 ± 0.05 |
mise hook-env
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.1.8 hook-env |
20.1 ± 0.7 | 19.2 | 26.9 | 1.00 |
mise hook-env |
20.6 ± 0.9 | 19.7 | 29.3 | 1.03 ± 0.06 |
mise ls
| Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
|---|---|---|---|---|
mise-2026.1.8 ls |
17.8 ± 0.6 | 16.8 | 26.2 | 1.00 |
mise ls |
18.1 ± 0.4 | 17.3 | 20.2 | 1.01 ± 0.04 |
xtasks/test/perf
| Command | mise-2026.1.8 | mise | Variance |
|---|---|---|---|
| install (cached) | 112ms | 111ms | +0% |
| ls (cached) | 68ms | 68ms | +0% |
| bin-paths (cached) | 72ms | 72ms | +0% |
| task-ls (cached) | 284ms | 296ms | -4% |
### 🚀 Features - **(doctor)** add backend mismatch warnings by @jdx in [#7847](#7847) - **(http)** add rename_exe support for archive extraction by @jdx in [#7874](#7874) - **(http)** send x-mise-ci header for CI environment tracking by @jdx in [#7875](#7875) - **(install)** auto-install plugins from [plugins] config section by @jdx in [#7856](#7856) - **(registry)** add vercel by @mikecurtis in [#7844](#7844) - **(task)** support glob patterns in task_config.includes by @jdx in [#7870](#7870) - **(task)** add task templates for reusable task definitions by @jdx in [#7873](#7873) ### 🐛 Bug Fixes - **(backend)** change registry mismatch log from info to debug by @jdx in [#7858](#7858) - **(ci)** use squash merge for auto-merge-release workflow by @jdx in [7e5e71e](7e5e71e) - **(ci)** remove --auto flag to merge immediately when CI passes by @jdx in [23ed2ed](23ed2ed) - **(github)** select platform-matching provenance file for SLSA verification by @jdx in [#7853](#7853) - **(go)** filter out version "1" from available versions by @jdx in [#7871](#7871) - **(install)** skip CurDir components when detecting archive structure by @jdx in [#7868](#7868) - **(pipx)** ensure Python minor version symlink exists for postinstall hooks by @jdx in [#7869](#7869) - **(registry)** prevent duplicate -stable suffix in Flutter download URLs by @jdx in [#7872](#7872) - **(task)** pass env to usage parser for env-backed arguments by @jdx in [#7848](#7848) - **(task)** propagate MISE_ENV to child tasks when using -E flag by @jdx in [06ee776](06ee776) - **(vfox-dotnet)** use os.execute() to fix Windows installation by @prodrigues1912 in [#7843](#7843) ### 📚 Documentation - update cache-behavior with env_cache information by @jdx in [#7849](#7849) ###◀️ Revert - remove task inheritance from parent configs in monorepos by @jdx in [#7851](#7851) - Revert "fix(ci): remove --auto flag to merge immediately when CI passes" by @jdx in [0606187](0606187) ### 📦 Registry - add mago ([aqua:carthage-software/mago](https://github.com/carthage-software/mago)) by @scop in [#7845](#7845) ### Chore - **(ci)** auto-merge release branch into main daily at 4am CST by @jdx in [#7852](#7852) ### New Contributors - @mikecurtis made their first contribution in [#7844](#7844) - @prodrigues1912 made their first contribution in [#7843](#7843)
Summary
parse_usage_spec_and_init_envfunction was usingusage::parse()without passing the environment, causingenv="VAR_NAME"attributes to always fall back to defaultsTest plan
test_task_usage_env_inheritedthat verifies:🤖 Generated with Claude Code
Note
Ensures
usagespecs respect environment-backed defaults when running tasks.task_executor.rs,parse_usage_spec_and_init_envnow usesusage::Parser::new(&spec).with_env(env).parse(...)soenv="VAR"args/flags read from the inherited environment instead of always defaultinge2e/tasks/test_task_usage_env_inheritedverifying env inheritance, explicit arg override, and fallback to defaultWritten by Cursor Bugbot for commit c684979. This will update automatically on new commits. Configure here.