From 9192ff8416bfd5e50a1f3b4c5536caa87f149351 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sat, 20 Jun 2026 06:26:00 +0200 Subject: [PATCH] fix(scripts): write Windows markers without BOM --- scripts/e2e/parallels/guest-transports.ts | 13 ++++++++----- test/scripts/parallels-npm-update-smoke.test.ts | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/e2e/parallels/guest-transports.ts b/scripts/e2e/parallels/guest-transports.ts index d434ffd41290..80525e6c63cb 100644 --- a/scripts/e2e/parallels/guest-transports.ts +++ b/scripts/e2e/parallels/guest-transports.ts @@ -99,7 +99,10 @@ $scriptPath = "$base.ps1" $logPath = "$base.log" $donePath = "$base.done" $exitPath = "$base.exit" -$pidPath = "$base.pid"`; +$pidPath = "$base.pid" +function Write-OpenClawUtf8File([string]$Path, [string]$Value) { + [System.IO.File]::WriteAllText($Path, $Value, [System.Text.UTF8Encoding]::new($false)) +}`; const payload = `$ErrorActionPreference = 'Stop' $PSNativeCommandUseErrorActionPreference = $false ${pathsScript} @@ -120,12 +123,12 @@ try { & { ${options.script} } *>&1 | Add-OpenClawBackgroundLog - Set-Content -Path $exitPath -Value '0' -Encoding UTF8 + Write-OpenClawUtf8File $exitPath '0' } catch { $_ | Add-OpenClawBackgroundLog - Set-Content -Path $exitPath -Value '1' -Encoding UTF8 + Write-OpenClawUtf8File $exitPath '1' } finally { - Set-Content -Path $donePath -Value 'done' -Encoding UTF8 + Write-OpenClawUtf8File $donePath 'done' }`; const writeScript = runCommand( "prlctl", @@ -172,7 +175,7 @@ if (!(Test-Path $scriptPath)) { throw "${safeLabel} background script was not wr "-EncodedCommand", encodePowerShell(`${pathsScript} $process = Start-Process -FilePath powershell.exe -WindowStyle Hidden -ArgumentList @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', $scriptPath) -PassThru -Set-Content -Path $pidPath -Value $process.Id -Encoding UTF8 +Write-OpenClawUtf8File $pidPath ([string]$process.Id) 'started'`), ], { check: false, quiet: true, timeoutMs: timeoutBefore(deadline, 30_000) }, diff --git a/test/scripts/parallels-npm-update-smoke.test.ts b/test/scripts/parallels-npm-update-smoke.test.ts index e59e3014150b..528fdf7d3baa 100644 --- a/test/scripts/parallels-npm-update-smoke.test.ts +++ b/test/scripts/parallels-npm-update-smoke.test.ts @@ -423,9 +423,13 @@ exit 1 it("cleans timed-out Windows background work and reads bounded log chunks", async () => { const decodedCommands: string[] = []; - const fakeRun: typeof hostCommandRun = (_command, args) => { + const inputs: string[] = []; + const fakeRun: typeof hostCommandRun = (_command, args, options) => { const decoded = decodePowerShellFromArgs(args); decodedCommands.push(decoded); + if (options?.input) { + inputs.push(String(options.input)); + } if (decoded.includes("Start-Process")) { return { status: 0, stderr: "", stdout: "started\n" }; } @@ -445,7 +449,13 @@ exit 1 ).rejects.toThrow("windows background timeout timed out"); const commands = decodedCommands.join("\n---\n"); + const payloads = inputs.join("\n---\n"); expect(commands).toContain("$pidPath"); + expect(commands).toContain("function Write-OpenClawUtf8File"); + expect(commands).toContain("[System.Text.UTF8Encoding]::new($false)"); + expect(payloads).toContain("Write-OpenClawUtf8File $exitPath '0'"); + expect(payloads).toContain("Write-OpenClawUtf8File $donePath 'done'"); + expect(commands).toContain("Write-OpenClawUtf8File $pidPath ([string]$process.Id)"); expect(commands).toContain("Start-Process -FilePath powershell.exe"); expect(commands).toContain("-PassThru"); expect(commands).toContain("[System.IO.File]::Open($logPath"); @@ -457,6 +467,9 @@ exit 1 expect(commands).toContain( "Remove-Item -Path $scriptPath, $logPath, $donePath, $exitPath, $pidPath", ); + expect(`${commands}\n${payloads}`).not.toContain("Set-Content -Path $exitPath"); + expect(`${commands}\n${payloads}`).not.toContain("Set-Content -Path $donePath"); + expect(commands).not.toContain("Set-Content -Path $pidPath"); expect(commands).not.toContain("ReadAllBytes"); });