Skip to content

Commit af5a1fb

Browse files
committed
test(parallels): harden npm update smoke transport
1 parent 231e5c6 commit af5a1fb

2 files changed

Lines changed: 79 additions & 17 deletions

File tree

‎scripts/e2e/parallels/npm-update-scripts.ts‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface NpmUpdateScriptInput {
1111

1212
export function macosUpdateScript(input: NpmUpdateScriptInput): string {
1313
return String.raw`set -euo pipefail
14+
export PATH=/opt/homebrew/bin:/opt/homebrew/opt/node/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin
1415
scrub_future_plugin_entries() {
1516
python3 - <<'PY'
1617
import json
@@ -63,7 +64,7 @@ wait_for_gateway() {
6364
}
6465
scrub_future_plugin_entries
6566
stop_openclaw_gateway_processes
66-
OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 /opt/homebrew/bin/openclaw update --tag ${shellQuote(input.updateTarget)} --yes --json
67+
OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 /opt/homebrew/bin/openclaw update --tag ${shellQuote(input.updateTarget)} --yes --json --no-restart
6768
${posixVersionCheck("/opt/homebrew/bin/openclaw", input.expectedNeedle)}
6869
start_openclaw_gateway
6970
wait_for_gateway
@@ -100,11 +101,15 @@ function Stop-OpenClawGatewayProcesses {
100101
Get-CimInstance Win32_Process -ErrorAction SilentlyContinue |
101102
Where-Object { $_.CommandLine -match 'openclaw.*gateway' } |
102103
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
104+
Get-NetTCPConnection -LocalPort 18789 -State Listen -ErrorAction SilentlyContinue |
105+
Select-Object -ExpandProperty OwningProcess -Unique |
106+
ForEach-Object { Stop-Process -Id $_ -Force -ErrorAction SilentlyContinue }
107+
Start-Sleep -Seconds 2
103108
}
104109
Remove-FuturePluginEntries
105110
Stop-OpenClawGatewayProcesses
106111
$env:OPENCLAW_DISABLE_BUNDLED_PLUGINS = '1'
107-
Invoke-OpenClaw update --tag ${psSingleQuote(input.updateTarget)} --yes --json
112+
Invoke-OpenClaw update --tag ${psSingleQuote(input.updateTarget)} --yes --json --no-restart
108113
if ($LASTEXITCODE -ne 0) { throw "openclaw update failed with exit code $LASTEXITCODE" }
109114
$version = Invoke-OpenClaw --version
110115
$version
@@ -120,6 +125,7 @@ Invoke-OpenClaw agent --local --agent main --session-id parallels-npm-update-win
120125

121126
export function linuxUpdateScript(input: NpmUpdateScriptInput): string {
122127
return String.raw`set -euo pipefail
128+
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/snap/bin
123129
scrub_future_plugin_entries() {
124130
node - <<'JS'
125131
const fs = require("node:fs");
@@ -167,7 +173,7 @@ wait_for_gateway() {
167173
}
168174
scrub_future_plugin_entries
169175
stop_openclaw_gateway_processes
170-
OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 openclaw update --tag ${shellQuote(input.updateTarget)} --yes --json
176+
OPENCLAW_DISABLE_BUNDLED_PLUGINS=1 openclaw update --tag ${shellQuote(input.updateTarget)} --yes --json --no-restart
171177
${posixVersionCheck("openclaw", input.expectedNeedle)}
172178
start_openclaw_gateway
173179
wait_for_gateway

‎scripts/e2e/parallels/npm-update-smoke.ts‎

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,23 @@ class NpmUpdateSmoke {
442442
ctx: UpdateJobContext,
443443
): Promise<void> {
444444
const macosExecArgs = this.resolveMacosUpdateExecArgs(ctx);
445-
const status = await this.runStreamingToJobLog(
446-
"prlctl",
447-
["exec", macosVm, ...macosExecArgs, "/bin/bash", "-lc", script],
448-
timeoutMs,
449-
ctx,
445+
const scriptPath = this.writeGuestScript(
446+
macosVm,
447+
script,
448+
"openclaw-parallels-npm-update-macos",
450449
);
451-
if (status !== 0) {
452-
throw new Error(`macOS update command failed with exit code ${status}`);
450+
try {
451+
const status = await this.runStreamingToJobLog(
452+
"prlctl",
453+
["exec", macosVm, ...macosExecArgs, "/bin/bash", scriptPath],
454+
timeoutMs,
455+
ctx,
456+
);
457+
if (status !== 0) {
458+
throw new Error(`macOS update command failed with exit code ${status}`);
459+
}
460+
} finally {
461+
this.removeGuestScript(macosVm, scriptPath);
453462
}
454463
}
455464

@@ -688,15 +697,62 @@ Remove-Item -Path $scriptPath, $logPath, $donePath, $exitPath -Force -ErrorActio
688697
timeoutMs: number,
689698
ctx: UpdateJobContext,
690699
): Promise<void> {
691-
const status = await this.runStreamingToJobLog(
692-
"prlctl",
693-
["exec", this.linuxVm, "/usr/bin/env", "HOME=/root", "bash", "-lc", script],
694-
timeoutMs,
695-
ctx,
700+
const scriptPath = this.writeGuestScript(
701+
this.linuxVm,
702+
script,
703+
"openclaw-parallels-npm-update-linux",
696704
);
697-
if (status !== 0) {
698-
throw new Error(`Linux update command failed with exit code ${status}`);
705+
try {
706+
const status = await this.runStreamingToJobLog(
707+
"prlctl",
708+
[
709+
"exec",
710+
this.linuxVm,
711+
"/usr/bin/env",
712+
"HOME=/root",
713+
"PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/snap/bin",
714+
"bash",
715+
scriptPath,
716+
],
717+
timeoutMs,
718+
ctx,
719+
);
720+
if (status !== 0) {
721+
throw new Error(`Linux update command failed with exit code ${status}`);
722+
}
723+
} finally {
724+
this.removeGuestScript(this.linuxVm, scriptPath);
725+
}
726+
}
727+
728+
private writeGuestScript(vm: string, script: string, prefix: string): string {
729+
const scriptPath = `/tmp/${prefix}-${process.pid}-${Date.now()}.sh`;
730+
const write = run("prlctl", ["exec", vm, "/usr/bin/tee", scriptPath], {
731+
check: false,
732+
input: script,
733+
quiet: true,
734+
timeoutMs: 120_000,
735+
});
736+
if (write.status !== 0) {
737+
throw new Error(`failed to write guest script ${scriptPath}: ${write.stderr.trim()}`);
738+
}
739+
const chmod = run("prlctl", ["exec", vm, "/bin/chmod", "700", scriptPath], {
740+
check: false,
741+
quiet: true,
742+
timeoutMs: 30_000,
743+
});
744+
if (chmod.status !== 0) {
745+
throw new Error(`failed to chmod guest script ${scriptPath}: ${chmod.stderr.trim()}`);
699746
}
747+
return scriptPath;
748+
}
749+
750+
private removeGuestScript(vm: string, scriptPath: string): void {
751+
run("prlctl", ["exec", vm, "/bin/rm", "-f", scriptPath], {
752+
check: false,
753+
quiet: true,
754+
timeoutMs: 30_000,
755+
});
700756
}
701757

702758
private async runStreamingToJobLog(

0 commit comments

Comments
 (0)