-
Notifications
You must be signed in to change notification settings - Fork 91
Refactor sandbox env passthrough #1073
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Vybestack LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { describe, it, expect, beforeEach } from 'vitest'; | ||
| import { buildSandboxEnvArgs, getPassthroughEnvVars } from './sandbox.js'; | ||
|
|
||
| describe('getPassthroughEnvVars', () => { | ||
| let mockEnv: NodeJS.ProcessEnv; | ||
|
|
||
| beforeEach(() => { | ||
| mockEnv = { | ||
| PATH: '/usr/bin:/bin', | ||
| HOME: '/home/user', | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| LLXPRT_CODE_WELCOME_CONFIG_PATH: '/config.json', | ||
| TERM_PROGRAM: 'VSCode', | ||
| NODE_ENV: 'test', | ||
| }; | ||
| }); | ||
|
|
||
| it('should return empty object when no passthrough vars are set', () => { | ||
| const env: NodeJS.ProcessEnv = { | ||
| PATH: '/usr/bin', | ||
| HOME: '/home/user', | ||
| }; | ||
|
|
||
| const result = getPassthroughEnvVars(env); | ||
|
|
||
| expect(result).toEqual({}); | ||
| }); | ||
|
|
||
| it('should return LLXPRT_CODE_IDE_SERVER_PORT when set', () => { | ||
| const result = getPassthroughEnvVars(mockEnv); | ||
|
|
||
| expect(result).toHaveProperty('LLXPRT_CODE_IDE_SERVER_PORT', '3000'); | ||
| }); | ||
|
|
||
| it('should return LLXPRT_CODE_IDE_WORKSPACE_PATH when set', () => { | ||
| const result = getPassthroughEnvVars(mockEnv); | ||
|
|
||
| expect(result).toHaveProperty( | ||
| 'LLXPRT_CODE_IDE_WORKSPACE_PATH', | ||
| '/workspace', | ||
| ); | ||
| }); | ||
|
|
||
| it('should return LLXPRT_CODE_WELCOME_CONFIG_PATH when set', () => { | ||
| const result = getPassthroughEnvVars(mockEnv); | ||
|
|
||
| expect(result).toHaveProperty( | ||
| 'LLXPRT_CODE_WELCOME_CONFIG_PATH', | ||
| '/config.json', | ||
| ); | ||
| }); | ||
|
|
||
| it('should return TERM_PROGRAM when set', () => { | ||
| const result = getPassthroughEnvVars(mockEnv); | ||
|
|
||
| expect(result).toHaveProperty('TERM_PROGRAM', 'VSCode'); | ||
| }); | ||
|
|
||
| it('should return all passthrough variables when all are set', () => { | ||
| const result = getPassthroughEnvVars(mockEnv); | ||
|
|
||
| expect(result).toEqual({ | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| LLXPRT_CODE_WELCOME_CONFIG_PATH: '/config.json', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }); | ||
| }); | ||
|
|
||
| it('should ignore passthrough vars with empty string values', () => { | ||
| const env: NodeJS.ProcessEnv = { | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }; | ||
|
|
||
| const result = getPassthroughEnvVars(env); | ||
|
|
||
| expect(result).toEqual({ | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }); | ||
| }); | ||
|
|
||
| it('should ignore passthrough vars with undefined values', () => { | ||
| const env: NodeJS.ProcessEnv = { | ||
| LLXPRT_CODE_IDE_SERVER_PORT: undefined, | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }; | ||
|
|
||
| const result = getPassthroughEnvVars(env); | ||
|
|
||
| expect(result).toEqual({ | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle special characters in variable values', () => { | ||
| const env: NodeJS.ProcessEnv = { | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000:3001', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/path/to/workspace with spaces', | ||
| TERM_PROGRAM: 'iTerm.app', | ||
| }; | ||
|
|
||
| const result = getPassthroughEnvVars(env); | ||
|
|
||
| expect(result).toEqual({ | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000:3001', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/path/to/workspace with spaces', | ||
| TERM_PROGRAM: 'iTerm.app', | ||
| }); | ||
| }); | ||
|
|
||
| it('should not mutate the input object', () => { | ||
| const env: NodeJS.ProcessEnv = { ...mockEnv }; | ||
| getPassthroughEnvVars(env); | ||
|
|
||
| expect(env).toEqual(mockEnv); | ||
| }); | ||
|
|
||
| it('should return a new object', () => { | ||
| const env: NodeJS.ProcessEnv = { ...mockEnv }; | ||
| const result = getPassthroughEnvVars(env); | ||
|
|
||
| expect(result).not.toBe(env); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildSandboxEnvArgs', () => { | ||
| let mockEnv: NodeJS.ProcessEnv; | ||
|
|
||
| beforeEach(() => { | ||
| mockEnv = { | ||
| PATH: '/usr/bin:/bin', | ||
| HOME: '/home/user', | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000', | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/workspace', | ||
| LLXPRT_CODE_WELCOME_CONFIG_PATH: '/config.json', | ||
| TERM_PROGRAM: 'VSCode', | ||
| NODE_ENV: 'test', | ||
| }; | ||
| }); | ||
|
|
||
| it('should return empty array when no passthrough vars are set', () => { | ||
| const env: NodeJS.ProcessEnv = { | ||
| PATH: '/usr/bin', | ||
| HOME: '/home/user', | ||
| }; | ||
|
|
||
| const result = buildSandboxEnvArgs(env); | ||
|
|
||
| expect(result).toEqual([]); | ||
| }); | ||
|
|
||
| it('should format passthrough vars as CLI args with --env prefix', () => { | ||
| const result = buildSandboxEnvArgs({ | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000', | ||
| TERM_PROGRAM: 'VSCode', | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| '--env', | ||
| 'LLXPRT_CODE_IDE_SERVER_PORT=3000', | ||
| '--env', | ||
| 'TERM_PROGRAM=VSCode', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should include all set passthrough variables', () => { | ||
| const result = buildSandboxEnvArgs(mockEnv); | ||
|
|
||
| expect(result).toEqual([ | ||
| '--env', | ||
| 'LLXPRT_CODE_IDE_SERVER_PORT=3000', | ||
| '--env', | ||
| 'LLXPRT_CODE_IDE_WORKSPACE_PATH=/workspace', | ||
| '--env', | ||
| 'LLXPRT_CODE_WELCOME_CONFIG_PATH=/config.json', | ||
| '--env', | ||
| 'TERM_PROGRAM=VSCode', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should handle values containing equals signs', () => { | ||
| const result = buildSandboxEnvArgs({ | ||
| LLXPRT_CODE_IDE_SERVER_PORT: '3000=3001', | ||
| }); | ||
|
|
||
| expect(result).toEqual(['--env', 'LLXPRT_CODE_IDE_SERVER_PORT=3000=3001']); | ||
| }); | ||
|
|
||
| it('should handle values with spaces', () => { | ||
| const result = buildSandboxEnvArgs({ | ||
| LLXPRT_CODE_IDE_WORKSPACE_PATH: '/path/to/workspace with spaces', | ||
| }); | ||
|
|
||
| expect(result).toEqual([ | ||
| '--env', | ||
| 'LLXPRT_CODE_IDE_WORKSPACE_PATH=/path/to/workspace with spaces', | ||
| ]); | ||
| }); | ||
|
|
||
| it('should not mutate the input object', () => { | ||
| const env: NodeJS.ProcessEnv = { ...mockEnv }; | ||
| const originalEnv = { ...env }; | ||
| buildSandboxEnvArgs(env); | ||
|
|
||
| expect(env).toEqual(originalEnv); | ||
| }); | ||
|
|
||
| it('should return a new array', () => { | ||
| const env: NodeJS.ProcessEnv = { ...mockEnv }; | ||
| const result1 = buildSandboxEnvArgs(env); | ||
| const result2 = buildSandboxEnvArgs(env); | ||
|
|
||
| expect(result2).not.toBe(result1); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🧩 Analysis chain
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 28763
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 1788
🏁 Script executed:
Repository: vybestack/llxprt-code
Length of output: 839
Object.assign with
getPassthroughEnvVarsis functionally redundant; consider buildingsandboxEnvfrom curated vars only.Starting
sandboxEnvwith{ ...process.env }includes all environment variables. The subsequentObject.assign(sandboxEnv, getPassthroughEnvVars(process.env))overwrites already-present values with identical ones, but doesn't filter out unwanted vars from the spread. If the goal is to pass only curated variables to sandbox-exec (as the helper's name suggests), constructsandboxEnvfromgetPassthroughEnvVars()first, then add proxy/control vars conditionally:🤖 Prompt for AI Agents