惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
Martin Fowler
Martin Fowler
C
Check Point Blog
G
Google Developers Blog
V
Visual Studio Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
大猫的无限游戏
大猫的无限游戏
D
Docker
Hugging Face - Blog
Hugging Face - Blog
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
Recent Announcements
Recent Announcements
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
阮一峰的网络日志
阮一峰的网络日志
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(installer): preserve PowerShell host on failure · ope...
steipete · 2026-04-26 · via Recent Commits to openclaw:main

@@ -0,0 +1,113 @@

1+

import { spawnSync } from "node:child_process";

2+

import { chmodSync, readFileSync, writeFileSync } from "node:fs";

3+

import { join } from "node:path";

4+

import { describe, expect, it } from "vitest";

5+

import { createScriptTestHarness } from "./test-helpers";

6+7+

const SCRIPT_PATH = "scripts/install.ps1";

8+9+

function extractFunctionBody(source: string, name: string): string {

10+

const match = source.match(

11+

new RegExp(`^function ${name} \\{\\r?\\n([\\s\\S]*?)^\\}\\r?\\n`, "m"),

12+

);

13+

expect(match?.[1]).toBeDefined();

14+

return match![1];

15+

}

16+17+

function findPowerShell(): string | undefined {

18+

for (const candidate of ["pwsh", "powershell"]) {

19+

const result = spawnSync(

20+

candidate,

21+

["-NoLogo", "-NoProfile", "-Command", "$PSVersionTable.PSVersion"],

22+

{

23+

encoding: "utf8",

24+

},

25+

);

26+

if (result.status === 0) {

27+

return candidate;

28+

}

29+

}

30+

return undefined;

31+

}

32+33+

function toPowerShellSingleQuotedLiteral(value: string): string {

34+

return `'${value.replaceAll("'", "''")}'`;

35+

}

36+37+

function createFailingNodeFixture(source: string): string {

38+

const scriptWithoutEntryPoint = source.replace(

39+

/\r?\n\$installSucceeded = Main\r?\nComplete-Install -Succeeded:\$installSucceeded\s*$/m,

40+

"",

41+

);

42+

expect(scriptWithoutEntryPoint).not.toBe(source);

43+44+

return [

45+

scriptWithoutEntryPoint,

46+

"",

47+

"function Write-Banner { }",

48+

"function Ensure-ExecutionPolicy { return $true }",

49+

"function Ensure-Node { return $false }",

50+

"",

51+

"$installSucceeded = Main",

52+

"Complete-Install -Succeeded:$installSucceeded",

53+

"",

54+

].join("\n");

55+

}

56+57+

describe("install.ps1 failure handling", () => {

58+

const harness = createScriptTestHarness();

59+

const source = readFileSync(SCRIPT_PATH, "utf8");

60+

const powershell = findPowerShell();

61+

const runIfPowerShell = powershell ? it : it.skip;

62+63+

it("does not exit directly from inside Main", () => {

64+

const mainBody = extractFunctionBody(source, "Main");

65+

expect(mainBody).not.toMatch(/\bexit\b/i);

66+

expect(mainBody).toContain("return (Fail-Install)");

67+

});

68+69+

it("keeps failure termination in the top-level completion handler", () => {

70+

const completeInstallBody = extractFunctionBody(source, "Complete-Install");

71+

expect(completeInstallBody).toMatch(/\$PSCommandPath/);

72+

expect(completeInstallBody).toMatch(/\bexit \$script:InstallExitCode\b/);

73+

expect(completeInstallBody).toMatch(/\bthrow "OpenClaw installation failed with exit code/);

74+

});

75+76+

runIfPowerShell("exits non-zero when run as a script file", () => {

77+

const tempDir = harness.createTempDir("openclaw-install-ps1-");

78+

const scriptPath = join(tempDir, "install.ps1");

79+

writeFileSync(scriptPath, createFailingNodeFixture(source));

80+

chmodSync(scriptPath, 0o755);

81+82+

const result = spawnSync(

83+

powershell!,

84+

["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],

85+

{ encoding: "utf8" },

86+

);

87+88+

expect(result.status).toBe(1);

89+

});

90+91+

runIfPowerShell("throws without killing the caller when run as a scriptblock", () => {

92+

const tempDir = harness.createTempDir("openclaw-install-ps1-");

93+

const scriptPath = join(tempDir, "install.ps1");

94+

writeFileSync(scriptPath, createFailingNodeFixture(source));

95+

chmodSync(scriptPath, 0o755);

96+97+

const command = [

98+

"try {",

99+

` & ([scriptblock]::Create((Get-Content -LiteralPath ${toPowerShellSingleQuotedLiteral(scriptPath)} -Raw)))`,

100+

"} catch {",

101+

' Write-Output "caught=$($_.Exception.Message)"',

102+

"}",

103+

'Write-Output "alive-after-install"',

104+

].join("\n");

105+

const result = spawnSync(powershell!, ["-NoLogo", "-NoProfile", "-Command", command], {

106+

encoding: "utf8",

107+

});

108+109+

expect(result.status).toBe(0);

110+

expect(result.stdout).toContain("caught=OpenClaw installation failed with exit code 1.");

111+

expect(result.stdout).toContain("alive-after-install");

112+

});

113+

});