Skip to content

fix(tasks): restore MISE_ENV environment inheritance for tasks#6621

Merged
jdx merged 1 commit intojdx:mainfrom
glasser:glasser/fix-mise-env-env-tasks
Oct 9, 2025
Merged

fix(tasks): restore MISE_ENV environment inheritance for tasks#6621
jdx merged 1 commit intojdx:mainfrom
glasser:glasser/fix-mise-env-env-tasks

Conversation

@glasser
Copy link
Copy Markdown
Contributor

@glasser glasser commented Oct 9, 2025

Tasks with config file context were not inheriting environment variables from MISE_ENV-specific config files due to only loading env entries from the task's specific config file instead of all config files in the hierarchy.

🤖 Generated with Claude Code


Note

Restores MISE_ENV env inheritance for tasks by resolving env from all config files for regular tasks (while preserving monorepo behavior) and adds e2e tests covering profiles and override precedence.

  • Core (task env resolution):
    • Resolve config-level env for regular tasks from all config_files (including MISE_ENV-specific files) rather than only the task's config; keep original behavior for monorepo tasks.
    • Update early-return logic to use task_cf.env_entries(); reuse ts.full_env and apply resolved env, then task-specific env.
    • Leverage path-aware tuples (EnvDirective, PathBuf) and refactor to pass aggregated entries directly to resolve_env_directives.
    • Cache/env handling unchanged, but keyed by canonicalized task config path.
  • Tests (e2e):
    • Add e2e/tasks/test_task_mise_env_profiles verifying:
      • Base vs overridden env without/with MISE_ENV.
      • Multiple profiles (production, staging) and comma-separated precedence.
      • Task-specific env overrides both base and MISE_ENV values.

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

Comment thread src/cli/run.rs
let config_env_entries = task_cf.env_entries()?;
// Get env entries from ALL config files (including MISE_ENV-specific ones)
// not just the task's config file
let all_config_env_entries: Vec<(crate::config::env_directive::EnvDirective, PathBuf)> =
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To be clear — I'm not an expert on Mise's internal data structures and I don't really know that this is the right fix, but it does appear to fix the bug reported at https://github.com/blixt/mise-env-bug-repro and the test file looks good to me.

Comment thread src/cli/run.rs
// Early return if no special context needed
if self.should_use_standard_env_resolution(task, task_cf, config, &config_env_entries) {
// Check using task_cf entries for compatibility with existing logic
let task_cf_env_entries = task_cf.env_entries()?;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Definitely at least slightly skeptical of the idea that this call down here needs to use a simpler data structure than the main env resolution, but I don't really know what's going on here!

@jdx
Copy link
Copy Markdown
Owner

jdx commented Oct 9, 2025

bugbot run

cursor[bot]

This comment was marked as outdated.

@glasser
Copy link
Copy Markdown
Contributor Author

glasser commented Oct 9, 2025

It does look like this broke a few tests. Will look into that.

Tasks with config file context were not inheriting environment variables from MISE_ENV-specific config files due to only loading env entries from the task's specific config file instead of all config files in the hierarchy.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@glasser glasser force-pushed the glasser/fix-mise-env-env-tasks branch from 0b54fab to 05d8d4f Compare October 9, 2025 21:32
@jdx
Copy link
Copy Markdown
Owner

jdx commented Oct 9, 2025

bugbot run

@jdx jdx requested a review from Copilot October 9, 2025 21:40
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 tasks were not properly inheriting environment variables from MISE_ENV-specific config files. The issue occurred because task environment resolution was only loading env entries from the task's specific config file instead of considering all config files in the hierarchy.

  • Refactored task environment resolution to distinguish between monorepo tasks and regular tasks
  • For regular tasks, now loads environment entries from all config files (including MISE_ENV-specific ones)
  • Removed the now-unused build_config_env_directives helper function

Reviewed Changes

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

File Description
src/cli/run.rs Updated task environment resolution logic to properly inherit MISE_ENV environment variables for regular tasks while preserving existing behavior for monorepo tasks
e2e/tasks/test_task_mise_env_profiles Added comprehensive test coverage for MISE_ENV environment inheritance in tasks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/cli/run.rs
if self.should_use_standard_env_resolution(task, task_cf, config, &config_env_entries) {
// Check using task_cf entries for compatibility with existing logic
let task_cf_env_entries = task_cf.env_entries()?;
if self.should_use_standard_env_resolution(task, task_cf, config, &task_cf_env_entries) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Config File Mismatch Causes Environment Inconsistency

The early return condition in resolve_task_env_with_config uses only the task's config file entries to decide if standard environment resolution is sufficient. However, the main processing logic considers entries from all relevant config files. This mismatch can cause inconsistent environment resolution, potentially affecting MISE_ENV inheritance for regular tasks.

Fix in Cursor Fix in Web

@jdx jdx merged commit b8b7277 into jdx:main Oct 9, 2025
27 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.

3 participants