-
Notifications
You must be signed in to change notification settings - Fork 18
fix(main): enhance PATH when spawning thv so macOS credential helpers resolve #2100
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
Merged
Changes from all commits
Commits
Show all changes
3 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
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
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
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
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,128 @@ | ||
| import { describe, it, expect, vi, afterEach, beforeEach } from 'vitest' | ||
| import { platform } from 'node:os' | ||
|
|
||
| import { createEnhancedPath } from '../enhanced-path' | ||
|
|
||
| vi.mock('node:os', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('node:os')>() | ||
| const platformMock = vi.fn(actual.platform) | ||
| return { | ||
| ...actual, | ||
| platform: platformMock, | ||
| default: { | ||
| ...actual, | ||
| platform: platformMock, | ||
| }, | ||
| } | ||
| }) | ||
|
|
||
| const mockPlatform = vi.mocked(platform) | ||
|
|
||
| describe('createEnhancedPath', () => { | ||
| beforeEach(() => { | ||
| mockPlatform.mockReset() | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs() | ||
| }) | ||
|
|
||
| it('prepends macOS container-tooling paths on darwin', () => { | ||
| mockPlatform.mockReturnValue('darwin') | ||
| vi.stubEnv('PATH', '/usr/bin:/bin') | ||
| vi.stubEnv('HOME', '/Users/test') | ||
|
|
||
| const result = createEnhancedPath() | ||
| const entries = result.split(':') | ||
|
|
||
| expect(entries.slice(0, 4)).toEqual([ | ||
| '/Applications/Docker.app/Contents/Resources/bin', | ||
| '/opt/homebrew/bin', | ||
| '/usr/local/bin', | ||
| '/Users/test/.rd/bin', | ||
| ]) | ||
| expect(entries).toContain('/usr/bin') | ||
| expect(entries).toContain('/bin') | ||
| }) | ||
|
|
||
| it('expands ~ using HOME', () => { | ||
| mockPlatform.mockReturnValue('darwin') | ||
| vi.stubEnv('PATH', '') | ||
| vi.stubEnv('HOME', '/Users/alice') | ||
|
|
||
| const result = createEnhancedPath() | ||
|
|
||
| expect(result).toContain('/Users/alice/.rd/bin') | ||
| expect(result).not.toContain('~') | ||
| }) | ||
|
|
||
| it('keeps ~ verbatim when HOME and USERPROFILE are both unset', () => { | ||
| mockPlatform.mockReturnValue('darwin') | ||
| vi.stubEnv('PATH', '') | ||
| vi.stubEnv('HOME', '') | ||
| vi.stubEnv('USERPROFILE', '') | ||
|
|
||
| const result = createEnhancedPath() | ||
| const entries = result.split(':') | ||
|
|
||
| expect(entries).toContain('~/.rd/bin') | ||
| expect(entries).not.toContain('/.rd/bin') | ||
| }) | ||
|
|
||
| it('uses semicolon as separator on win32', () => { | ||
| mockPlatform.mockReturnValue('win32') | ||
| vi.stubEnv('PATH', 'C:\\Windows\\System32;C:\\Windows') | ||
|
|
||
| const result = createEnhancedPath() | ||
| const entries = result.split(';') | ||
|
|
||
| expect(entries[0]).toBe('C:\\Program Files\\Docker\\Docker\\resources\\bin') | ||
| expect(entries[1]).toBe('C:\\Program Files\\RedHat\\Podman') | ||
| expect(entries).toContain('C:\\Windows\\System32') | ||
| expect(entries).toContain('C:\\Windows') | ||
| }) | ||
|
|
||
| it('prepends linux container-tooling paths', () => { | ||
| mockPlatform.mockReturnValue('linux') | ||
| vi.stubEnv('PATH', '/usr/bin:/bin') | ||
| vi.stubEnv('HOME', '/home/test') | ||
|
|
||
| const result = createEnhancedPath() | ||
| const entries = result.split(':') | ||
|
|
||
| expect(entries.slice(0, 4)).toEqual([ | ||
| '/usr/local/bin', | ||
| '/opt/homebrew/bin', | ||
| '/snap/bin', | ||
| '/home/test/.rd/bin', | ||
| ]) | ||
| }) | ||
|
|
||
| it('preserves existing PATH entries after the prepended paths', () => { | ||
| mockPlatform.mockReturnValue('darwin') | ||
| vi.stubEnv('PATH', '/existing/bin:/another/bin') | ||
| vi.stubEnv('HOME', '/Users/test') | ||
|
|
||
| const result = createEnhancedPath() | ||
| const entries = result.split(':') | ||
|
|
||
| const existingIndex = entries.indexOf('/existing/bin') | ||
| const anotherIndex = entries.indexOf('/another/bin') | ||
|
|
||
| expect(existingIndex).toBeGreaterThan(-1) | ||
| expect(anotherIndex).toBeGreaterThan(existingIndex) | ||
| }) | ||
|
|
||
| it('handles empty PATH gracefully', () => { | ||
| mockPlatform.mockReturnValue('darwin') | ||
| vi.stubEnv('PATH', '') | ||
| vi.stubEnv('HOME', '/Users/test') | ||
|
|
||
| const result = createEnhancedPath() | ||
|
|
||
| expect(result).not.toBe('') | ||
| expect(result).toContain('/usr/local/bin') | ||
| // No trailing empty segments from the split/join | ||
| expect(result.endsWith(':')).toBe(false) | ||
| }) | ||
| }) |
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,40 @@ | ||
| import { platform } from 'node:os' | ||
|
|
||
| const getCommonPaths = (): string[] => { | ||
| const currentPlatform = platform() | ||
|
|
||
| switch (currentPlatform) { | ||
| case 'darwin': | ||
| return [ | ||
| '/Applications/Docker.app/Contents/Resources/bin', | ||
| '/opt/homebrew/bin', | ||
| '/usr/local/bin', | ||
| '~/.rd/bin', | ||
| ] | ||
| case 'linux': | ||
| return ['/usr/local/bin', '/opt/homebrew/bin', '/snap/bin', '~/.rd/bin'] | ||
| case 'win32': | ||
| return [ | ||
| 'C:\\Program Files\\Docker\\Docker\\resources\\bin', | ||
| 'C:\\Program Files\\RedHat\\Podman', | ||
| ] | ||
| default: | ||
| return [] | ||
| } | ||
| } | ||
|
|
||
| const expandPath = (path: string): string => { | ||
| if (!path.startsWith('~')) return path | ||
| const homeDir = process.env.HOME || process.env.USERPROFILE | ||
| return homeDir ? path.replace('~', homeDir) : path | ||
| } | ||
|
|
||
| export const createEnhancedPath = (): string => { | ||
| const commonPaths = getCommonPaths().map(expandPath) | ||
| const currentPath = process.env.PATH || '' | ||
| const separator = platform() === 'win32' ? ';' : ':' | ||
|
|
||
| return [...commonPaths, ...currentPath.split(separator)] | ||
| .filter(Boolean) | ||
| .join(separator) | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.