* feat: add windows ssh relay base support * feat: support windows ssh relay runtime services * fix: default windows ssh pty cwd to user profile * fix: support windows hosts over system ssh * fix: preserve degraded windows relay native deps * fix: gate windows shell args by relay platform * fix: preserve windows relay fallback pipes * test: align windows native deps relay fixture * fix: build valid windows install lock command * fix: address windows SSH relay review findings Resolve correctness, efficiency, and reuse issues found reviewing the Windows SSH native-host support: - GC liveness on Windows now probes the actual named pipe (via node net.connect against markers + deterministic candidates) instead of substring-matching Win32_Process command lines, which could remove a live relay dir. Reports ALIVE conservatively only when there is no liveness signal at all (no markers and no seed pipes). - Resolve the remote node path once per deploy and thread it through install/repair/launch instead of re-resolving 3-7x. - Replace the 200ms node -e poll loop with a single long-lived remote wait process during Windows relay startup. - Skip the no-op executable command on Windows in uploadRelay. - Make the Windows fallback pipe name deterministic and recoverable (drop the global counter), with an extra reconnect attempt. - Normalize the prepended node bin dir to backslashes on Windows PATH. - Batch the system-SSH Windows directory upload into a single streamed JSON package instead of one ssh process per file. - Extract relay endpoint/marker helpers into ssh-relay-endpoints.ts and consolidate the PowerShell EncodedCommand encoding into the shared powershell-command-encoding module. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Support cancellation and timeouts in Windows port scanning - Propagate the request AbortSignal and a 5-second timeout to both PowerShell and netstat child processes during Windows port scanning. - Avoid spawning the netstat fallback process if the port scan has already been aborted. - Wrap the .NET OSArchitecture check in a try/catch block during SSH Windows platform detection to robustly fall back to environment variables if needed. --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Co-authored-by: Jinjing <6427696+AmethystLiang@users.noreply.github.com>
64 lines
2.2 KiB
TypeScript
64 lines
2.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { getRemoteHostPlatform, joinRemotePath } from './ssh-remote-platform'
|
|
import { detectRemoteHostPlatform } from './ssh-remote-platform-detection'
|
|
import { execCommand } from './ssh-relay-deploy-helpers'
|
|
import type { SshConnection } from './ssh-connection'
|
|
|
|
vi.mock('./ssh-relay-deploy-helpers', () => ({
|
|
execCommand: vi.fn()
|
|
}))
|
|
|
|
const conn = {} as SshConnection
|
|
|
|
function decodePowerShellCommand(command: string): string {
|
|
const match = command.match(/-EncodedCommand\s+([A-Za-z0-9+/=]+)/)
|
|
return match ? Buffer.from(match[1], 'base64').toString('utf16le') : ''
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
describe('joinRemotePath', () => {
|
|
it('joins POSIX remote paths', () => {
|
|
expect(joinRemotePath(getRemoteHostPlatform('linux-x64'), '/home/me', '.orca-remote')).toBe(
|
|
'/home/me/.orca-remote'
|
|
)
|
|
})
|
|
|
|
it('normalizes and joins Windows remote paths with forward slashes for SFTP and Node', () => {
|
|
expect(
|
|
joinRemotePath(getRemoteHostPlatform('win32-x64'), 'C:\\Users\\me', '.orca-remote', 'relay')
|
|
).toBe('C:/Users/me/.orca-remote/relay')
|
|
})
|
|
})
|
|
|
|
describe('detectRemoteHostPlatform', () => {
|
|
it('uses uname when the remote is POSIX', async () => {
|
|
vi.mocked(execCommand).mockResolvedValueOnce('Darwin arm64')
|
|
|
|
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
|
|
relayPlatform: 'darwin-arm64',
|
|
commandDialect: 'posix'
|
|
})
|
|
})
|
|
|
|
it('falls back to PowerShell when uname is unavailable on Windows', async () => {
|
|
vi.mocked(execCommand)
|
|
.mockRejectedValueOnce(new Error('uname not recognized'))
|
|
.mockResolvedValueOnce('Windows AMD64')
|
|
|
|
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
|
|
relayPlatform: 'win32-x64',
|
|
commandDialect: 'powershell',
|
|
pathFlavor: 'windows'
|
|
})
|
|
|
|
expect(vi.mocked(execCommand).mock.calls[1]?.[1]).toContain('powershell.exe')
|
|
const script = decodePowerShellCommand(vi.mocked(execCommand).mock.calls[1]?.[1] ?? '')
|
|
expect(script).toContain('$arch = $env:PROCESSOR_ARCHITECTURE')
|
|
expect(script).toContain('try { $runtimeArch =')
|
|
expect(script).toContain('catch {}')
|
|
})
|
|
})
|