fix(scripts): write Windows markers without BOM

This commit is contained in:
Vincent Koc
2026-06-20 06:26:00 +02:00
parent 118f3f3312
commit 9192ff8416
2 changed files with 22 additions and 6 deletions

View File

@@ -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) },

View File

@@ -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");
});