





















@@ -73,6 +73,44 @@ describe("install.ps1 failure handling", () => {
7373expect(completeInstallBody).toMatch(/\bthrow "OpenClaw installation failed with exit code/);
7474});
757576+it("runs npm capture commands from a writable installer temp directory", () => {
77+const nativeCaptureBody = extractFunctionBody(source, "Invoke-NativeCommandCapture");
78+const npmInstallBody = extractFunctionBody(source, "Install-OpenClawNpm");
79+const mainBody = extractFunctionBody(source, "Main");
80+expect(source).toContain("function Get-NpmWorkingDirectory {");
81+expect(nativeCaptureBody).toContain('[string]$WorkingDirectory = ""');
82+expect(nativeCaptureBody).toContain("$startProcessArgs.WorkingDirectory = $WorkingDirectory");
83+expect(npmInstallBody).toContain("-WorkingDirectory (Get-NpmWorkingDirectory)");
84+expect(mainBody).toContain("-WorkingDirectory (Get-NpmWorkingDirectory)");
85+});
86+87+runIfPowerShell("creates a temp npm working directory", () => {
88+const tempDir = harness.createTempDir("openclaw-install-ps1-");
89+const scriptPath = join(tempDir, "install.ps1");
90+const scriptWithoutEntryPoint = source.replace(ENTRYPOINT_RE, "");
91+writeFileSync(
92+scriptPath,
93+[
94+scriptWithoutEntryPoint,
95+"",
96+"$result = Get-NpmWorkingDirectory",
97+'if (!(Test-Path -LiteralPath $result)) { throw "missing $result" }',
98+'if ($result -notmatch "openclaw-installer") { throw "unexpected $result" }',
99+"",
100+].join("\n"),
101+);
102+chmodSync(scriptPath, 0o755);
103+104+const result = spawnSync(
105+powershell!,
106+["-NoLogo", "-NoProfile", "-ExecutionPolicy", "Bypass", "-File", scriptPath],
107+{ encoding: "utf8" },
108+);
109+110+expect(result.status).toBe(0);
111+expect(result.stderr).toBe("");
112+});
113+76114runIfPowerShell("exits non-zero when run as a script file", () => {
77115const tempDir = harness.createTempDir("openclaw-install-ps1-");
78116const scriptPath = join(tempDir, "install.ps1");
@@ -125,7 +163,7 @@ describe("install.ps1 failure handling", () => {
125163"function Ensure-Node { return $true }",
126164"function Add-ToPath { param([string]$Path) }",
127165"function Invoke-NativeCommandCapture {",
128-" param([string]$FilePath, [string[]]$Arguments)",
166+" param([string]$FilePath, [string[]]$Arguments, [string]$WorkingDirectory = '')",
129167" return @{ ExitCode = 0; Stdout = 'npm stdout'; Stderr = 'npm stderr' }",
130168"}",
131169"$NoOnboard = $true",
@@ -167,7 +205,7 @@ describe("install.ps1 failure handling", () => {
167205" return $true",
168206"}",
169207"function Invoke-NativeCommandCapture {",
170-" param([string]$FilePath, [string[]]$Arguments)",
208+" param([string]$FilePath, [string[]]$Arguments, [string]$WorkingDirectory = '')",
171209" return @{ ExitCode = 0; Stdout = 'npm prefix'; Stderr = '' }",
172210"}",
173211"$NoOnboard = $true",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。