Files
orca/src/main/ssh/ssh-remote-platform-detection.test.ts
T
Siddiqui QamarandJinwoo Hong e3f0b99f4a fix: detect noisy Windows ARM64 SSH platforms (#7965)
* fix: detect noisy Windows ARM64 SSH platforms

- Scan remote platform probe output line-by-line for supported OS/arch markers.

- Handle PowerShell/OpenSSH first-use CLIXML or banner noise before Windows ARM64.

- Add regression coverage for noisy Windows ARM64 detection.

* fix: harden SSH platform probe markers

---------

Co-authored-by: Jinwoo Hong <73622457+Jinwoo-H@users.noreply.github.com>
2026-07-10 22:31:53 -07:00

112 lines
3.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { SshConnection } from './ssh-connection'
const execCommandMock = vi.hoisted(() => vi.fn())
vi.mock('./ssh-relay-deploy-helpers', () => ({
execCommand: execCommandMock
}))
const { detectRemoteHostPlatform } = await import('./ssh-remote-platform-detection')
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') : ''
}
describe('detectRemoteHostPlatform', () => {
beforeEach(() => {
execCommandMock.mockReset()
})
it('detects POSIX hosts from uname output', async () => {
execCommandMock.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ Linux x86_64\n')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'linux-x64',
os: 'linux',
arch: 'x64',
pathFlavor: 'posix'
})
expect(execCommandMock).toHaveBeenCalledWith(
conn,
"printf '\\n%s ' '__ORCA_REMOTE_PLATFORM__'; uname -sm"
)
})
it('falls back to PowerShell detection for Windows remotes', async () => {
execCommandMock
.mockRejectedValueOnce(new Error('uname unavailable'))
.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ Windows AMD64\r\n')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'win32-x64',
os: 'win32',
arch: 'x64',
pathFlavor: 'windows'
})
expect(execCommandMock).toHaveBeenNthCalledWith(
2,
conn,
expect.stringContaining('powershell.exe'),
{ wrapCommand: false }
)
const command = execCommandMock.mock.calls[1]?.[1] ?? ''
expect(decodePowerShellCommand(command)).toContain(
'Write-Output ("`n__ORCA_REMOTE_PLATFORM__ Windows " + $arch)'
)
})
it('ignores untagged platforms before the tagged Windows ARM64 result', async () => {
execCommandMock
.mockRejectedValueOnce(new Error('uname unavailable'))
.mockResolvedValueOnce(
'Linux x86_64\r\nWindows AMD64\r\n#< CLIXML\r\n' +
'__ORCA_REMOTE_PLATFORM__ Windows ARM64\r\n'
)
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'win32-arm64',
os: 'win32',
arch: 'arm64',
pathFlavor: 'windows'
})
})
it('ignores a marker concatenated to unterminated startup noise', async () => {
execCommandMock.mockResolvedValueOnce(
'startup noise__ORCA_REMOTE_PLATFORM__ Linux x86_64\n' +
'__ORCA_REMOTE_PLATFORM__ Linux arm64\n'
)
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'linux-arm64'
})
})
it('returns null when neither probe yields a supported platform', async () => {
execCommandMock
.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ Linux')
.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ FreeBSD x86_64')
await expect(detectRemoteHostPlatform(conn)).resolves.toBeNull()
})
it('does not use whitespace regex splitting for remote platform output', async () => {
const splitSpy = vi.spyOn(String.prototype, 'split')
execCommandMock.mockResolvedValueOnce('__ORCA_REMOTE_PLATFORM__ Darwin arm64 extra')
await expect(detectRemoteHostPlatform(conn)).resolves.toMatchObject({
relayPlatform: 'darwin-arm64'
})
const usedWhitespaceFieldSplit = splitSpy.mock.calls.some(
([separator]) => separator instanceof RegExp && separator.source.includes('\\s+')
)
splitSpy.mockRestore()
expect(usedWhitespaceFieldSplit).toBe(false)
})
})