-
Notifications
You must be signed in to change notification settings - Fork 501
fix: detect remote agents using the execution context's platform, not the client's #2510
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
Open
serhiizghama
wants to merge
2
commits into
generalaction:main
Choose a base branch
from
serhiizghama:fix/remote-agent-detection-use-context-platform
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+104
−4
Open
Changes from all commits
Commits
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
72 changes: 72 additions & 0 deletions
72
apps/emdash-desktop/src/main/core/dependencies/probe.test.ts
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,72 @@ | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import type { IExecutionContext } from '@main/core/execution-context/types'; | ||
| import { resolveCommandPath } from './probe'; | ||
|
|
||
| function makeCtx( | ||
| isWindows: boolean, | ||
| handler: (command: string, args: string[]) => Promise<{ stdout: string; stderr: string }> | ||
| ): IExecutionContext { | ||
| return { | ||
| root: undefined, | ||
| supportsLocalSpawn: false, | ||
| isWindows, | ||
| exec: vi.fn().mockImplementation(handler), | ||
| execStreaming: vi.fn(), | ||
| dispose: vi.fn(), | ||
| } as unknown as IExecutionContext; | ||
| } | ||
|
|
||
| describe('resolveCommandPath', () => { | ||
| it('uses `which` on POSIX hosts', async () => { | ||
| const ctx = makeCtx(false, async () => ({ stdout: '/usr/local/bin/claude\n', stderr: '' })); | ||
|
|
||
| const path = await resolveCommandPath('claude', ctx); | ||
|
|
||
| expect(ctx.exec).toHaveBeenCalledWith('which', ['claude'], { timeout: 5000 }); | ||
| expect(path).toBe('/usr/local/bin/claude'); | ||
| }); | ||
|
|
||
| it('uses `where` on Windows hosts', async () => { | ||
| const ctx = makeCtx(true, async () => ({ stdout: 'C:\\bin\\claude.exe\n', stderr: '' })); | ||
|
|
||
| const path = await resolveCommandPath('claude', ctx); | ||
|
|
||
| expect(ctx.exec).toHaveBeenCalledWith('where', ['claude'], { timeout: 5000 }); | ||
| expect(path).toBe('C:\\bin\\claude.exe'); | ||
| }); | ||
|
|
||
| // Regression: a Windows client connected to a POSIX remote over SSH must run | ||
| // `which` on the remote host, not `where`. The resolve command follows the | ||
| // execution context's platform, never the local client's. See issue #2474. | ||
| it('uses `which` for a POSIX SSH context even when the client is Windows', async () => { | ||
| const ctx = makeCtx(false, async () => ({ | ||
| stdout: '/home/dev/.local/bin/claude\n', | ||
| stderr: '', | ||
| })); | ||
|
|
||
| const path = await resolveCommandPath('claude', ctx); | ||
|
|
||
| expect(ctx.exec).toHaveBeenCalledWith('which', ['claude'], { timeout: 5000 }); | ||
| expect(ctx.exec).not.toHaveBeenCalledWith('where', expect.anything(), expect.anything()); | ||
| expect(path).toBe('/home/dev/.local/bin/claude'); | ||
| }); | ||
|
|
||
| it('returns the first match and trims surrounding whitespace', async () => { | ||
| const ctx = makeCtx(true, async () => ({ | ||
| stdout: 'C:\\bin\\claude.exe\r\nC:\\other\\claude.exe\r\n', | ||
| stderr: '', | ||
| })); | ||
|
|
||
| const path = await resolveCommandPath('claude', ctx); | ||
|
|
||
| expect(path).toBe('C:\\bin\\claude.exe'); | ||
| }); | ||
|
|
||
| it('returns null when resolution fails', async () => { | ||
| const ctx = makeCtx(false, async () => { | ||
| throw new Error('not found'); | ||
| }); | ||
|
|
||
| expect(await resolveCommandPath('claude', ctx)).toBeNull(); | ||
| }); | ||
| }); |
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
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
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
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.
falseassumes all SSH targets are POSIXisWindows = falseis correct for the documented use-case (remote Linux/macOS servers), and the JSDoc on the interface acknowledges this. However, the assumption is baked into the class and will silently misbehave if an SSH-to-Windows target (e.g. OpenSSH on Windows Server) is ever introduced —whichdoes not exist there and every probe would fail just like the original bug. Worth a TODO comment flagging this limitation so it is visible if a Windows SSH target needs to be supported later.Prompt To Fix With AI