fix: handle bin-only runtime deps

This commit is contained in:
Peter Steinberger
2026-05-01 09:07:25 +01:00
parent 0ac1a07f7c
commit 7d7b610a24
4 changed files with 119 additions and 10 deletions

View File

@@ -5,6 +5,8 @@ import { describe, expect, it } from "vitest";
import { createScriptTestHarness } from "./test-helpers";
const SCRIPT_PATH = "scripts/install.ps1";
const ENTRYPOINT_RE =
/\r?\n\$mainResults = @\(Main\)\r?\n\$installSucceeded = \$mainResults\.Count -gt 0 -and \$mainResults\[-1\] -eq \$true\r?\nComplete-Install -Succeeded:\$installSucceeded\s*$/m;
function extractFunctionBody(source: string, name: string): string {
const match = source.match(
@@ -35,10 +37,7 @@ function toPowerShellSingleQuotedLiteral(value: string): string {
}
function createFailingNodeFixture(source: string): string {
const scriptWithoutEntryPoint = source.replace(
/\r?\n\$installSucceeded = Main\r?\nComplete-Install -Succeeded:\$installSucceeded\s*$/m,
"",
);
const scriptWithoutEntryPoint = source.replace(ENTRYPOINT_RE, "");
expect(scriptWithoutEntryPoint).not.toBe(source);
return [
@@ -48,7 +47,8 @@ function createFailingNodeFixture(source: string): string {
"function Ensure-ExecutionPolicy { return $true }",
"function Ensure-Node { return $false }",
"",
"$installSucceeded = Main",
"$mainResults = @(Main)",
"$installSucceeded = $mainResults.Count -gt 0 -and $mainResults[-1] -eq $true",
"Complete-Install -Succeeded:$installSucceeded",
"",
].join("\n");
@@ -114,10 +114,7 @@ describe("install.ps1 failure handling", () => {
runIfPowerShell("keeps npm chatter out of Main's success return value", () => {
const tempDir = harness.createTempDir("openclaw-install-ps1-");
const scriptPath = join(tempDir, "install.ps1");
const scriptWithoutEntryPoint = source.replace(
/\r?\n\$installSucceeded = Main\r?\nComplete-Install -Succeeded:\$installSucceeded\s*$/m,
"",
);
const scriptWithoutEntryPoint = source.replace(ENTRYPOINT_RE, "");
writeFileSync(
scriptPath,
[
@@ -149,4 +146,46 @@ describe("install.ps1 failure handling", () => {
expect(result.status).toBe(0);
expect(result.stderr).toBe("");
});
runIfPowerShell("uses Main's final boolean result when helper output precedes success", () => {
const tempDir = harness.createTempDir("openclaw-install-ps1-");
const scriptPath = join(tempDir, "install.ps1");
const scriptWithoutEntryPoint = source.replace(ENTRYPOINT_RE, "");
writeFileSync(
scriptPath,
[
scriptWithoutEntryPoint,
"",
"function Write-Banner { }",
"function Ensure-ExecutionPolicy { return $true }",
"function Ensure-Node { return $true }",
"function Ensure-Git { return $true }",
"function Add-ToPath { param([string]$Path) }",
"function Install-OpenClawNpm {",
" param([string]$Target = 'latest')",
" Write-Output 'native chatter'",
" return $true",
"}",
"function Invoke-NativeCommandCapture {",
" param([string]$FilePath, [string[]]$Arguments)",
" return @{ ExitCode = 0; Stdout = 'npm prefix'; Stderr = '' }",
"}",
"$NoOnboard = $true",
"$mainResults = @(Main)",
"$installSucceeded = $mainResults.Count -gt 0 -and $mainResults[-1] -eq $true",
"Complete-Install -Succeeded:$installSucceeded",
"",
].join("\n"),
);
chmodSync(scriptPath, 0o755);
const result = spawnSync(
powershell!,
["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
{ encoding: "utf8" },
);
expect(result.status).toBe(0);
expect(result.stderr).toBe("");
});
});