Skip to content

The agent that grows with you

fix(desktop): keep SSH Windows probe stable against CLIXML progress-stream pollution

Konstantin Khlopkovdd479b377615
diff --git a/apps/desktop/electron/windows-remote-lifecycle.test.ts b/apps/desktop/electron/windows-remote-lifecycle.test.ts
index 0e482fdb185..f1a50782f05 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.test.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.test.ts
@@ -221,6 +221,53 @@ test('Windows probe validates Hermes and Python topology before selection', asyn
assert.ok(pythonCheck < output)
})
+const CLEAN_PROBE_RESULT = JSON.stringify({
+ os: 'Windows',
+ arch: 'AMD64',
+ hermesHome: 'C:\\h',
+ hermesPath: 'C:\\h\\hermes.exe',
+ python: 'C:\\h\\python.exe'
+})
+
+const CLIXML_PROGRESS =
+ '#< CLIXML <Objs Version="1.1.0.1" xmlns="http://schemas.microsoft.com/maml/2004/10"><Obj S="progress" RefId="0">正在标准配置首次使用模块</Obj></Objs>'
+
+test('Windows probe script silences the PowerShell progress stream', async () => {
+ let script = ''
+ await probeWindowsRemote(
+ sshWith(async command => {
+ script = Buffer.from(command.split(' ').at(-1) || '', 'base64').toString('utf16le')
+
+ return CLEAN_PROBE_RESULT
+ })
+ )
+
+ assert.ok(script.indexOf('$ProgressPreference="SilentlyContinue"') >= 0)
+ assert.ok(script.indexOf('$ProgressPreference') < script.indexOf('$ErrorActionPreference'))
+})
+
+test('Windows probe tolerates CLIXML progress-stream pollution around the probe JSON', async () => {
+ const pollutedOutputs = [
+ `${CLIXML_PROGRESS}\r\n${CLEAN_PROBE_RESULT}`,
+ `${CLIXML_PROGRESS}${CLEAN_PROBE_RESULT}`,
+ `\uFEFF${CLEAN_PROBE_RESULT}\r\n${CLIXML_PROGRESS}`
+ ]
+
+ for (const output of pollutedOutputs) {
+ const parsed = await probeWindowsRemote(sshWith(async () => output))
+
+ assert.equal(parsed.os, 'Windows')
+ assert.equal(parsed.arch, 'AMD64')
+ assert.equal(parsed.hermesPath, 'C:\\h\\hermes.exe')
+ assert.equal(parsed.python, 'C:\\h\\python.exe')
+ }
+})
+
+test('Windows probe still rejects output that is not platform JSON', async () => {
+ await assert.rejects(probeWindowsRemote(sshWith(async () => 'hermes is not installed on this host')))
+ await assert.rejects(probeWindowsRemote(sshWith(async () => JSON.stringify({ os: 'Windows' })+'\n'+JSON.stringify({unrelated:true}) )))
+})
+
test('platform detection preserves POSIX and falls back to Windows PowerShell', async () => {
assert.deepEqual(await detectRemotePlatform(sshWith(async () => 'Linux\nx86_64\n')), { os: 'Linux', arch: 'x86_64' })
const calls: string[] = []
diff --git a/apps/desktop/electron/windows-remote-lifecycle.ts b/apps/desktop/electron/windows-remote-lifecycle.ts
index 41394a5de26..4f7e4a895a3 100644
--- a/apps/desktop/electron/windows-remote-lifecycle.ts
+++ b/apps/desktop/electron/windows-remote-lifecycle.ts
@@ -24,6 +24,10 @@ async function probeWindowsRemote(ssh, explicitHermesPath = '') {
const explicit = psLiteral(explicitHermesPath)
const script = [
+ // Module auto-load / cold-start progress records get serialized by Windows
+ // OpenSSH as "#< CLIXML <Objs S=\"progress\">..." into the same stdout the
+ // probe parses; silence the progress stream before anything can emit it.
+ '$ProgressPreference="SilentlyContinue"',
'$ErrorActionPreference="Stop"',
'function Assert-NoReparse([string]$candidate,[bool]$allowMissing=$false){',
'if([string]::IsNullOrWhiteSpace($candidate)){return}',
@@ -68,7 +72,25 @@ async function probeWindowsRemote(ssh, explicitHermesPath = '') {
'[ordered]@{os="Windows";arch=$env:PROCESSOR_ARCHITECTURE;hermesHome=$hermesHome;hermesPath=$hermes;python=$python}|ConvertTo-Json -Compress'
].join(';')
- return JSON.parse((await ssh.exec(powerShellCommand(script))).trim())
+ // Windows OpenSSH may serialize PowerShell's progress stream as
+ // "#< CLIXML <Objs ...>...</Objs>" blocks into the same stdout channel the
+ // probe reads, ahead of, after, or on the same line as the probe JSON
+ // (module auto-load racing the exec read). Drop every block, then apply
+ // the sibling helpers' convention: the JSON is the last meaningful line.
+ const lines = String(await ssh.exec(powerShellCommand(script)))
+ .replace(/^\uFEFF/, '')
+ .replace(/#< CLIXML[\s\S]*?<\/Objs>/g, '')
+ .trim()
+ .split(/\r?\n/)
+ .filter(line => line.trim() && !line.trimStart().startsWith('#< CLIXML'))
+
+ const parsed = JSON.parse(lines[lines.length - 1] || 'null')
+
+ if (!parsed?.os || !parsed?.arch) {
+ throw new Error(`Windows probe did not return the expected platform JSON: ${String(lines[lines.length - 1] ?? '').slice(0, 200)}`)
+ }
+
+ return parsed
}
function windowsUpdateMarkerProbeCommand(hermesHome) {