-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: preserve nix-shell environment when creating terminals #7022
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Modified Terminal.getEnv() to spread process.env first, preserving nix-shell and other environment variables - Updated TerminalRegistry tests to use expect.objectContaining() for environment checks - Added comprehensive tests for environment preservation in Terminal.env-preservation.spec.ts Fixes #7021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code because apparently I trust no one, not even myself.
| public static getEnv(): Record<string, string> { | ||
| // Start with the existing process environment to preserve nix-shell and other environment variables | ||
| const env: Record<string, string> = { | ||
| ...process.env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this intentional that we're spreading process.env without filtering undefined values? The type signature suggests Record<string, string> but process.env can contain string | undefined. While the tests show this works, would it be safer to explicitly filter out undefined values?
| ...process.env, | |
| // Start with the existing process environment to preserve nix-shell and other environment variables | |
| const env: Record<string, string> = { | |
| ...Object.fromEntries( | |
| Object.entries(process.env).filter(([_, v]) => v !== undefined) | |
| ) as Record<string, string>, |
| } | ||
|
|
||
| public static getEnv(): Record<string, string> { | ||
| // Start with the existing process environment to preserve nix-shell and other environment variables |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we consider adding more detailed documentation here about the precedence order? It would help future maintainers understand which variables Roo Code specifically overrides and why.
For example:
| // Start with the existing process environment to preserve nix-shell and other environment variables | |
| // Start with the existing process environment to preserve nix-shell and other environment variables | |
| // Precedence order: process.env values are preserved, then Roo Code-specific overrides are applied. | |
| // Overridden variables: PAGER, VTE_VERSION, and conditionally: PROMPT_COMMAND, PROMPT_EOL_MARK, | |
| // ITERM_SHELL_INTEGRATION_INSTALLED, POWERLEVEL9K_TERM_SHELL_INTEGRATION, ZDOTDIR |
| // Should not throw and should not include undefined values | ||
| expect(env.SOME_UNDEFINED_VAR).toBeUndefined() | ||
| }) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test coverage! Could we add an edge case test for when process.env might contain non-string values? Though this shouldn't happen in practice, it would make the test suite more robust.
Summary
This PR fixes an issue where Roo Code was creating new terminal instances that lost the nix-shell environment variables, breaking the nix-shell environment for users.
Problem
When a user is in a
nix-shellenvironment and asks Roo Code to run a command, it creates a new terminal with a limited set of environment variables, which cancels out all the nix-shell specific environment variables likeNIX_BUILD_CORES,NIX_STORE,IN_NIX_SHELL,PKG_CONFIG_PATH, etc.Solution
Modified
Terminal.getEnv()to preserve the existingprocess.envvariables by spreading them first before applying Roo Code-specific overrides. This ensures that nix-shell environment variables (and any other environment variables from the parent process) are preserved when creating new terminals.Changes
Terminal.getEnv()to spreadprocess.envfirst, preserving all existing environment variablesTerminalRegistrytests to useexpect.objectContaining()for environment checks since we now include all process environment variablesTerminal.env-preservation.spec.tsto verify environment preservation works correctlyTesting
Fixes #7021
Important
Fixes environment variable preservation in terminals by modifying
Terminal.getEnv()to retain all existingprocess.envvariables, ensuring nix-shell compatibility.Terminal.getEnv()now preserves all existingprocess.envvariables, ensuring nix-shell and other environment variables are retained.Terminal.env-preservation.spec.tsto test environment preservation, including nix-shell variables.TerminalRegistry.spec.tsto useexpect.objectContaining()for environment checks.Terminal.tsto spreadprocess.envingetEnv()function.This description was created by
for d1612f4. You can customize this summary. It will automatically update as commits are pushed.