Skip to content

fix(en): preserve env profile in activated subshells#10124

Merged
jdx merged 1 commit into
mainfrom
fix/en-preserve-mise-env
May 28, 2026
Merged

fix(en): preserve env profile in activated subshells#10124
jdx merged 1 commit into
mainfrom
fix/en-preserve-mise-env

Conversation

@jdx

@jdx jdx commented May 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • keep explicit -E/MISE_ENV profiles out of the __MISE_DIFF that activated child shells reverse
  • add an e2e regression covering mise -E dev en spawning interactive zsh that sources mise activate zsh

Test

  • mise run test:e2e e2e/cli/test_en_mise_env
  • cargo fmt --all -- --check

Fixes discussion #10007.

This PR was generated by an AI coding assistant.


Note

Low Risk
Small, targeted change to exec env serialization plus an e2e regression; no auth or data-path changes.

Overview
Fixes mise -E / MISE_ENV profiles being dropped when a child from mise en (or exec) runs an interactive shell that sources mise activate.

When building __MISE_DIFF for the spawned process, MISE_ENV is temporarily removed (and any stale __MISE_DIFF cleared) so the serialized diff only captures tool/path changes—not the explicit env profile, which would otherwise be undone on activation. MISE_ENV is restored in the child environment after serialization.

Adds e2e test 17: interactive zsh with mise activate still sees MISE_ENV=dev and dev-specific config after mise -E dev en.

Reviewed by Cursor Bugbot for commit 22f82fc. Bugbot is set up for automated code reviews on this repo. Configure here.

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

Copy link
Copy Markdown
Contributor

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 ensures that explicit -E profiles remain active when a child shell sources mise activate by excluding MISE_ENV from the computed environment diff, and adds an integration test to verify this behavior. The review feedback suggests optimizing this change by temporarily removing and restoring MISE_ENV on the original environment map to avoid an expensive clone, while also explicitly excluding __MISE_DIFF to prevent recursive nesting.

Comment thread src/cli/exec.rs Outdated
@greptile-apps

greptile-apps Bot commented May 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Fixes mise -E <profile> en losing its environment profile when the spawned shell runs mise activate by excluding MISE_ENV from the __MISE_DIFF serialization (and clearing any inherited __MISE_DIFF first), then re-inserting it into the child process's env after the diff is computed.

  • src/cli/exec.rs: Temporarily removes MISE_ENV from env before calling EnvDiff::from_final_env, so the profile variable is invisible to the diff and won't be reversed by mise activate in the child shell. Also unconditionally removes the inherited __MISE_DIFF entry before computing the new one, preventing a stale diff from reaching the subprocess when serialization fails (note: from_final_env already filters __MISE_DIFF from the diff computation itself, so this removal only affects the fallback/no-serialization path).
  • e2e/cli/test_en_mise_env: Adds Test 17, which writes a .zshrc that calls eval "$(mise activate zsh)" and runs it via mise -E dev en -s 'zsh -i -c ...', asserting that both $MISE_ENV and the profile-specific variable survive activation.

Confidence Score: 5/5

Safe to merge — the change is narrowly scoped to the __MISE_DIFF serialization step, with no auth or data-path changes.

The fix correctly excludes MISE_ENV from __MISE_DIFF while keeping it in the child process's environment, and the secondary __MISE_DIFF removal avoids stale values reaching the subprocess when serialization fails. The regression test covers the reported scenario end-to-end.

No files require special attention.

Important Files Changed

Filename Overview
src/cli/exec.rs Temporarily strips MISE_ENV (and stale __MISE_DIFF) from env before computing the __MISE_DIFF serialization, then re-inserts MISE_ENV; ensures the child shell's activate reversal does not clobber the -E profile.
e2e/cli/test_en_mise_env Adds Test 17: spawns an interactive zsh with a .zshrc that sources mise activate zsh inside mise -E dev en, and asserts MISE_ENV and profile-specific vars are still set.

Reviews (2): Last reviewed commit: "fix(en): preserve env profile in activat..." | Re-trigger Greptile

Comment thread e2e/cli/test_en_mise_env Outdated
@jdx jdx force-pushed the fix/en-preserve-mise-env branch from 608df90 to 44a5fb1 Compare May 28, 2026 15:24
@jdx jdx force-pushed the fix/en-preserve-mise-env branch from 44a5fb1 to 22f82fc Compare May 28, 2026 15:26

jdx commented May 28, 2026

Copy link
Copy Markdown
Owner Author

Updated in 22f82fc to remove the zsh availability guard; this test now assumes zsh is available in the e2e environment.

This comment was generated by an AI coding assistant.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 22f82fc. Configure here.

Comment thread e2e/cli/test_en_mise_env
eval "\$(mise activate zsh)"
EOF
assert_contains "ZDOTDIR=$(pwd)/zsh-home HOME=$(pwd)/zsh-home SHELL=$zsh_bin mise -E dev en -s 'zsh -i -c \"echo \$MISE_ENV\"'" "dev"
assert_contains "ZDOTDIR=$(pwd)/zsh-home HOME=$(pwd)/zsh-home SHELL=$zsh_bin mise -E dev en -s 'zsh -i -c \"mise env | grep TTT_ENV_NAME\"'" "TTT_ENV_NAME=dev"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing guard skips zsh tests when zsh unavailable

Medium Severity

Test 17 captures zsh_bin=$(command -v zsh) but never conditionally skips the zsh-specific assertions when zsh is not installed. The test runner executes bash scripts with -euo pipefail (see e2e/run_test line 151), so command -v zsh returning exit code 1 will abort the entire test script immediately. This causes all preceding passing tests (1–16) to also appear as failures on any system without zsh.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 22f82fc. Configure here.

@github-actions

Copy link
Copy Markdown

Hyperfine Performance

mise x -- echo

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.15 x -- echo 19.8 ± 0.9 17.9 25.0 1.00
mise x -- echo 20.6 ± 1.4 18.4 27.3 1.04 ± 0.09

mise env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.15 env 19.7 ± 1.3 17.2 27.5 1.00
mise env 19.9 ± 1.0 18.2 24.8 1.01 ± 0.08

mise hook-env

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.15 hook-env 20.7 ± 0.9 18.9 24.2 1.00
mise hook-env 21.0 ± 1.1 18.7 25.7 1.01 ± 0.07

mise ls

Command Mean [ms] Min [ms] Max [ms] Relative
mise-2026.5.15 ls 17.0 ± 0.9 15.1 21.7 1.00
mise ls 17.1 ± 0.9 15.5 22.1 1.01 ± 0.08

xtasks/test/perf

Command mise-2026.5.15 mise Variance
install (cached) 139ms 141ms -1%
ls (cached) 67ms 68ms -1%
bin-paths (cached) 69ms 69ms +0%
task-ls (cached) 140ms 139ms +0%

@jdx jdx merged commit 3e3b2cb into main May 28, 2026
33 checks passed
@jdx jdx deleted the fix/en-preserve-mise-env branch May 28, 2026 15:51
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.

1 participant