fix(desktop): preserve Windows SSH probe input encoding
This commit is contained in:
committed by
brooklyn!
parent
5dd73d4641
commit
25d7de6fad
@@ -136,7 +136,11 @@ type SshExecOptions = { stdinData?: string | Buffer }
|
||||
function scriptFromInvocation(command: string, options: SshExecOptions = {}) {
|
||||
const encoded = command.match(/-EncodedCommand\s+([^\s]+)$/)?.[1]
|
||||
|
||||
return encoded ? Buffer.from(encoded, 'base64').toString('utf16le') : String(options.stdinData || '')
|
||||
if (encoded) {
|
||||
return Buffer.from(encoded, 'base64').toString('utf16le')
|
||||
}
|
||||
|
||||
return Buffer.from(String(options.stdinData || '').trim(), 'base64').toString('utf16le')
|
||||
}
|
||||
|
||||
test('PowerShell transport uses UTF-16LE encoded commands and literal escaping', () => {
|
||||
@@ -329,18 +333,9 @@ test('Windows probe validates Hermes and Python topology before selection', asyn
|
||||
assert.ok(pythonCheck < output)
|
||||
})
|
||||
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
import { promisify } from 'node:util'
|
||||
}
|
||||
})
|
||||
|
||||
import { spawn } from 'node:child_process'
|
||||
import fs from 'node:fs'
|
||||
import os from 'node:os'
|
||||
import path from 'node:path'
|
||||
}
|
||||
import { exec as execCallback, spawn } from 'node:child_process'
|
||||
import crypto from 'node:crypto'
|
||||
import { mkdtemp, readFile, rm } from 'node:fs/promises' }
|
||||
})
|
||||
|
||||
test('platform detection preserves POSIX and falls back to Windows PowerShell', async () => {
|
||||
|
||||
@@ -40,7 +40,7 @@ function stripPowerShellNoise(stdout) {
|
||||
// command shell is commonly cmd.exe, whose command-line limit is 8191 chars.
|
||||
// SshConnection.exec already supports streaming stdin to the remote command.
|
||||
function powerShellStdinCommand() {
|
||||
return 'powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command [ScriptBlock]::Create([Console]::In.ReadToEnd()).Invoke()'
|
||||
return 'powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -Command [ScriptBlock]::Create([Text.Encoding]::Unicode.GetString([Convert]::FromBase64String([Console]::In.ReadToEnd()))).Invoke()'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,9 +102,8 @@ async function probeWindowsRemote(ssh, explicitHermesPath = '') {
|
||||
// (module auto-load racing the exec read). stripPowerShellNoise drops every
|
||||
// block; the JSON is the last meaningful line.
|
||||
const lines = stripPowerShellNoise(
|
||||
await ssh.exec(powerShellStdinCommand(), { stdinData: `${script}\r\n` })
|
||||
await ssh.exec(powerShellStdinCommand(), { stdinData: `${encodedPowerShell(script)}\r\n` })
|
||||
)
|
||||
|
||||
const parsed = JSON.parse(lines[lines.length - 1] || 'null')
|
||||
|
||||
if (!parsed?.os || !parsed?.arch) {
|
||||
|
||||
Reference in New Issue
Block a user