

























@@ -61,6 +61,12 @@ describe("install.ps1 failure handling", () => {
6161const source = readFileSync(SCRIPT_PATH, "utf8");
6262const powershell = findPowerShell();
6363const runIfPowerShell = powershell ? it : it.skip;
64+const runPowerShell = (args: string[]) => {
65+if (!powershell) {
66+throw new Error("PowerShell is not available");
67+}
68+return spawnSync(powershell, args, { encoding: "utf8" });
69+};
64706571it("does not exit directly from inside Main", () => {
6672const mainBody = extractFunctionBody(source, "Main");
@@ -103,11 +109,14 @@ describe("install.ps1 failure handling", () => {
103109);
104110chmodSync(scriptPath, 0o755);
105111106-const result = spawnSync(
107-powershell!,
108-["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
109-{ encoding: "utf8" },
110-);
112+const result = runPowerShell([
113+"-NoLogo",
114+"-NoProfile",
115+"-ExecutionPolicy",
116+"Bypass",
117+"-File",
118+scriptPath,
119+]);
111120112121expect(result.status).toBe(0);
113122expect(result.stderr).toBe("");
@@ -119,11 +128,14 @@ describe("install.ps1 failure handling", () => {
119128writeFileSync(scriptPath, createFailingNodeFixture(source));
120129chmodSync(scriptPath, 0o755);
121130122-const result = spawnSync(
123-powershell!,
124-["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
125-{ encoding: "utf8" },
126-);
131+const result = runPowerShell([
132+"-NoLogo",
133+"-NoProfile",
134+"-ExecutionPolicy",
135+"Bypass",
136+"-File",
137+scriptPath,
138+]);
127139128140expect(result.status).toBe(1);
129141});
@@ -142,9 +154,7 @@ describe("install.ps1 failure handling", () => {
142154"}",
143155'Write-Output "alive-after-install"',
144156].join("\n");
145-const result = spawnSync(powershell!, ["-NoLogo", "-NoProfile", "-Command", command], {
146-encoding: "utf8",
147-});
157+const result = runPowerShell(["-NoLogo", "-NoProfile", "-Command", command]);
148158149159expect(result.status).toBe(0);
150160expect(result.stdout).toContain("caught=OpenClaw installation failed with exit code 1.");
@@ -177,11 +187,14 @@ describe("install.ps1 failure handling", () => {
177187);
178188chmodSync(scriptPath, 0o755);
179189180-const result = spawnSync(
181-powershell!,
182-["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
183-{ encoding: "utf8" },
184-);
190+const result = runPowerShell([
191+"-NoLogo",
192+"-NoProfile",
193+"-ExecutionPolicy",
194+"Bypass",
195+"-File",
196+scriptPath,
197+]);
185198186199expect(result.status).toBe(0);
187200expect(result.stderr).toBe("");
@@ -219,11 +232,14 @@ describe("install.ps1 failure handling", () => {
219232);
220233chmodSync(scriptPath, 0o755);
221234222-const result = spawnSync(
223-powershell!,
224-["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
225-{ encoding: "utf8" },
226-);
235+const result = runPowerShell([
236+"-NoLogo",
237+"-NoProfile",
238+"-ExecutionPolicy",
239+"Bypass",
240+"-File",
241+scriptPath,
242+]);
227243228244expect(result.status).toBe(0);
229245expect(result.stderr).toBe("");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。