mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(scripts): write Windows markers without BOM
This commit is contained in:
@@ -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) },
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user