Skip to content

Commit 71d4a8c

Browse files
authored
fix(parallels): main install and update smoke cannot complete (#130658)
* fix(parallels): restore candidate install and update smoke coverage * fix(scripts): allow prepublish artifact imports from stdin * refactor(parallels): remove obsolete server re-exports * fix(parallels): require configured Windows gateway RPC readiness
1 parent 6b842df commit 71d4a8c

15 files changed

Lines changed: 669 additions & 268 deletions

‎scripts/e2e/parallels-windows-prepare.sh‎

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fi
8888

8989
require_host_tools() {
9090
local tool
91-
for tool in prlctl curl python3 ruby; do
91+
for tool in prlctl curl python3 ruby node; do
9292
command -v "$tool" >/dev/null 2>&1 || die "missing host tool: $tool"
9393
done
9494
}
@@ -114,12 +114,18 @@ vm_exists() {
114114
}
115115

116116
vm_state() {
117-
prlctl status "$VM_NAME" 2>/dev/null | awk '{print $NF}'
117+
run_bounded 30 prlctl status "$VM_NAME" 2>/dev/null | awk '{print $NF}'
118118
}
119119

120120
ensure_vm_running() {
121-
local state
121+
local state deadline=$((SECONDS + 120))
122122
state="$(vm_state)"
123+
# snapshot-switch can return before Parallels finishes restoring the disk state.
124+
while [[ "$state" == "restoring" ]]; do
125+
[[ "$SECONDS" -lt "$deadline" ]] || die "snapshot restore did not finish within 120 seconds"
126+
sleep 1
127+
state="$(vm_state)"
128+
done
123129
case "$state" in
124130
running)
125131
;;
@@ -617,8 +623,18 @@ ensure_git() {
617623
wait_for_check Git 'where git.exe'
618624
}
619625

626+
guest_node_supported() {
627+
local version
628+
version="$(guest_user_cmd 'node.exe --version' | tr -d '\r' | tail -n 1)" || return 1
629+
node --input-type=module - "$SCRIPT_DIR/../preinstall-package-manager-warning.mjs" "$version" <<'JS'
630+
import { pathToFileURL } from "node:url";
631+
const { enforceSupportedNodeRuntime } = await import(pathToFileURL(process.argv[2]).href);
632+
process.exitCode = enforceSupportedNodeRuntime({ version: process.argv[3], execPath: "Windows guest PATH" }) ? 0 : 1;
633+
JS
634+
}
635+
620636
ensure_node() {
621-
if guest_user_cmd 'where node.exe' >/dev/null 2>&1; then
637+
if guest_node_supported >/dev/null 2>&1; then
622638
return
623639
fi
624640
winget_download OpenJS.NodeJS.LTS
@@ -630,6 +646,7 @@ ensure_node() {
630646
run_windows_installer msiexec.exe /i "$installer" /qn /norestart
631647
finish_installer_reboot
632648
wait_for_check Node.js 'where node.exe'
649+
guest_node_supported || die "installed Node.js does not satisfy the OpenClaw runtime requirement"
633650
}
634651

635652
cleanup_installers() {
@@ -640,6 +657,7 @@ cleanup_installers() {
640657
verify_baseline() {
641658
set_guest_paths
642659
guest_user_cmd 'git --version && node --version && npm --version'
660+
guest_node_supported || die "baseline Node.js is unsupported; rerun prepare with --baseline-snapshot <new-name> to upgrade it"
643661
guest_user_cmd 'wsl.exe --version' || die "MSI-backed WSL is unavailable"
644662
guest_user_cmd 'wsl.exe --status' || die "WSL status failed"
645663
guest_system_ps "if (-not (Get-CimInstance Win32_ComputerSystem).HypervisorPresent) { throw 'Windows hypervisor is not active; WSL 2 workloads cannot start' }"

‎scripts/e2e/parallels/common.ts‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
export * from "./filesystem.ts";
33
export * from "./env-limits.ts";
44
export * from "./host-command.ts";
5-
export {
6-
resolveHostIp,
7-
resolveHostPort,
8-
startHostServer,
9-
startNpmRegistryServer,
10-
} from "./host-server.ts";
5+
export { resolveHostIp, resolveHostPort } from "./host-server.ts";
116
export * from "./lane-runner.ts";
127
export * from "./macos-users.ts";
138
export {

‎scripts/e2e/parallels/guest-transports.ts‎

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,15 @@ interface GuestExecOptions {
1212
timeoutMs?: number;
1313
}
1414

15+
interface PosixGuestOptions extends GuestExecOptions {
16+
env?: Record<string, string>;
17+
}
18+
1519
interface WindowsBackgroundPowerShellOptions {
1620
append?: (chunk: string | Uint8Array) => void;
1721
beforeLaunchAttempt?: () => void;
1822
completedLogDrainGraceMs?: number;
23+
env?: Record<string, string>;
1924
label: string;
2025
onLaunchRetry?: (message: string) => void;
2126
pollIntervalMs?: number;
@@ -43,6 +48,15 @@ function posixSingleQuote(value: string): string {
4348
return `'${value.replaceAll("'", `'\\''`)}'`;
4449
}
4550

51+
function windowsProcessEnvScript(env: Record<string, string> = {}): string {
52+
return Object.entries(env)
53+
.map(
54+
([key, value]) =>
55+
`Set-Item -LiteralPath ${psSingleQuote(`Env:${key}`)} -Value ${psSingleQuote(value)}`,
56+
)
57+
.join("\n");
58+
}
59+
4660
function appendOutput(
4761
append: ((chunk: string | Uint8Array) => void) | undefined,
4862
result: CommandResult,
@@ -387,6 +401,7 @@ function Add-OpenClawBackgroundLog {
387401
}
388402
try {
389403
& {
404+
${windowsProcessEnvScript(options.env)}
390405
${options.script}
391406
} *>&1 | Add-OpenClawBackgroundLog
392407
Write-OpenClawUtf8File $exitPath '0'
@@ -709,14 +724,20 @@ Remove-Item -Path $runDir -Recurse -Force -ErrorAction SilentlyContinue`),
709724
export class LinuxGuest {
710725
private vmName: string;
711726
private phases: PhaseRunner;
727+
private getEnv: () => Record<string, string>;
712728

713-
constructor(vmName: string, phases: PhaseRunner) {
729+
constructor(vmName: string, phases: PhaseRunner, getEnv = () => ({})) {
714730
this.vmName = vmName;
715731
this.phases = phases;
732+
this.getEnv = getEnv;
716733
}
717734

718-
exec(args: string[], options: GuestExecOptions = {}): string {
719-
const result = run("prlctl", this.transportArgs(args), {
735+
exec(args: string[], options: PosixGuestOptions = {}): string {
736+
return this.run(args, options).stdout.trim();
737+
}
738+
739+
run(args: string[], options: PosixGuestOptions = {}): CommandResult {
740+
const result = run("prlctl", this.transportArgs(args, options.env), {
720741
check: false,
721742
input: options.input,
722743
quiet: true,
@@ -725,11 +746,17 @@ export class LinuxGuest {
725746
this.phases.append(result.stdout);
726747
this.phases.append(result.stderr);
727748
throwIfFailed("Linux guest command", result, options.check);
728-
return result.stdout.trim();
749+
return result;
729750
}
730751

731-
private transportArgs(args: string[]): string[] {
732-
return ["exec", this.vmName, "/usr/bin/env", "HOME=/root", "OPENCLAW_ALLOW_ROOT=1", ...args];
752+
private transportArgs(args: string[], env: Record<string, string> = {}): string[] {
753+
const envArgs = Object.entries({
754+
HOME: "/root",
755+
OPENCLAW_ALLOW_ROOT: "1",
756+
...this.getEnv(),
757+
...env,
758+
}).map(([key, value]) => `${key}=${value}`);
759+
return ["exec", this.vmName, "/usr/bin/env", ...envArgs, ...args];
733760
}
734761

735762
bash(script: string): string {
@@ -750,16 +777,13 @@ export class LinuxGuest {
750777
}
751778
}
752779

753-
interface MacosGuestOptions extends GuestExecOptions {
754-
env?: Record<string, string>;
755-
}
756-
757780
type MacosGuestInput = {
758781
vmName: string;
759782
getUser: () => string;
760783
getTransport: () => "current-user" | "sudo";
761784
resolveDesktopHome: (user: string) => string;
762785
path: string;
786+
getEnv?: () => Record<string, string>;
763787
};
764788

765789
export class MacosGuest {
@@ -771,12 +795,12 @@ export class MacosGuest {
771795
this.phases = phases;
772796
}
773797

774-
exec(args: string[], options: MacosGuestOptions = {}): string {
798+
exec(args: string[], options: PosixGuestOptions = {}): string {
775799
return this.run(args, options).stdout.trim();
776800
}
777801

778802
private transportArgs(args: string[], env: Record<string, string> = {}): string[] {
779-
const envArgs = Object.entries({ PATH: this.input.path, ...env }).map(
803+
const envArgs = Object.entries({ PATH: this.input.path, ...this.input.getEnv?.(), ...env }).map(
780804
([key, value]) => `${key}=${value}`,
781805
);
782806
const user = this.input.getUser();
@@ -798,7 +822,7 @@ export class MacosGuest {
798822
: ["exec", this.input.vmName, "--current-user", "/usr/bin/env", ...envArgs, ...args];
799823
}
800824

801-
run(args: string[], options: MacosGuestOptions = {}): CommandResult {
825+
run(args: string[], options: PosixGuestOptions = {}): CommandResult {
802826
const result = run("prlctl", this.transportArgs(args, options.env), {
803827
check: false,
804828
input: options.input,
@@ -845,10 +869,12 @@ export class MacosGuest {
845869
export class WindowsGuest {
846870
private vmName: string;
847871
private phases: PhaseRunner;
872+
private getEnv: () => Record<string, string>;
848873

849-
constructor(vmName: string, phases: PhaseRunner) {
874+
constructor(vmName: string, phases: PhaseRunner, getEnv = () => ({})) {
850875
this.vmName = vmName;
851876
this.phases = phases;
877+
this.getEnv = getEnv;
852878
}
853879

854880
exec(args: string[], options: GuestExecOptions = {}): string {
@@ -886,7 +912,7 @@ export class WindowsGuest {
886912
encodePowerShell(writeScript),
887913
],
888914
{
889-
input: script,
915+
input: `${windowsProcessEnvScript(this.getEnv())}\n${script}`,
890916
quiet: true,
891917
timeoutMs: this.phases.remainingTimeoutMs(120_000),
892918
},

‎scripts/e2e/parallels/linux-smoke.ts‎

Lines changed: 15 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ import {
4141
expectedPackageBuildCommit,
4242
expectedPackageTargetVersion,
4343
extractLastOpenClawVersion,
44+
npmRegistryEnv,
4445
packAndServeSmokeArtifact,
4546
printSmokeTargetSummary,
47+
posixStopGatewayScript,
4648
parseSmokeCliArgs,
4749
SmokeRunController,
4850
type SmokeCliOptions,
@@ -184,6 +186,7 @@ class LinuxSmoke extends SmokeRunController<LinuxOptions> {
184186
private snapshot!: SnapshotInfo;
185187
private phases!: PhaseRunner;
186188
private guest!: LinuxGuest;
189+
private guestEnv: Record<string, string> = {};
187190

188191
protected status = {
189192
daemon: "systemd-user-unavailable",
@@ -217,7 +220,7 @@ class LinuxSmoke extends SmokeRunController<LinuxOptions> {
217220
this.snapshot = shouldSkipSnapshotRestore()
218221
? currentRunningSnapshotInfo(this.options.vmName)
219222
: resolveSnapshot(this.options.vmName, this.options.snapshotHint);
220-
this.guest = new LinuxGuest(this.options.vmName, this.phases);
223+
this.guest = new LinuxGuest(this.options.vmName, this.phases, () => this.guestEnv);
221224
this.latestVersion = resolveLatestVersion(this.options.latestVersion);
222225
await this.prepareHost(
223226
defaultOptions().hostPort,
@@ -232,6 +235,8 @@ class LinuxSmoke extends SmokeRunController<LinuxOptions> {
232235
this.hostIp,
233236
this.hostPort,
234237
this.artifactLabel(),
238+
false,
239+
this.options.provider,
235240
);
236241

237242
await this.runLanesAndFinish();
@@ -354,6 +359,8 @@ printf 'preflight.npmRoot=%s\n' "$(npm root -g 2>/dev/null || true)"`);
354359
}
355360

356361
private restoreSnapshot(): void {
362+
// A restored baseline must resolve public packages, not the previous candidate registry.
363+
this.guestEnv = {};
357364
if (shouldSkipSnapshotRestore()) {
358365
say(`Skip snapshot restore; using current running VM ${this.options.vmName}`);
359366
this.waitForGuestReady();
@@ -463,19 +470,10 @@ fi`);
463470
if (!this.artifact || !this.server) {
464471
die("package artifact/server missing");
465472
}
473+
this.guestEnv = npmRegistryEnv(this.options.npmRegistry ?? this.server.registry?.url);
466474
const tgzUrl = this.server.urlFor(this.artifact.path);
467475
this.downloadGuestFile(tgzUrl, `/tmp/${tempName}`);
468-
const npmArgs = ["npm", "install", "-g", `/tmp/${tempName}`, "--no-fund", "--no-audit"];
469-
this.guestExec(
470-
this.options.npmRegistry
471-
? [
472-
"/usr/bin/env",
473-
`NPM_CONFIG_REGISTRY=${this.options.npmRegistry}`,
474-
`npm_config_registry=${this.options.npmRegistry}`,
475-
...npmArgs,
476-
]
477-
: npmArgs,
478-
);
476+
this.guestExec(["npm", "install", "-g", `/tmp/${tempName}`, "--no-fund", "--no-audit"]);
479477
this.guestExec(["openclaw", "--version"]);
480478
}
481479

@@ -614,17 +612,7 @@ setsid sh -lc ` +
614612
const args = help.includes("--require-rpc")
615613
? ["openclaw", "gateway", "status", "--deep", "--require-rpc"]
616614
: ["openclaw", "gateway", "status", "--deep"];
617-
const result = run(
618-
"prlctl",
619-
["exec", this.options.vmName, "/usr/bin/env", "HOME=/root", "OPENCLAW_ALLOW_ROOT=1", ...args],
620-
{
621-
check: false,
622-
quiet: true,
623-
timeoutMs: this.remainingPhaseTimeoutMs(),
624-
},
625-
);
626-
this.log(result.stdout);
627-
this.log(result.stderr);
615+
const result = this.guest.run(args, { check: false });
628616
if (check && result.status !== 0) {
629617
throw new Error("gateway status failed");
630618
}
@@ -633,26 +621,10 @@ setsid sh -lc ` +
633621

634622
private verifyGatewayStatus(): void {
635623
for (let attempt = 1; attempt <= 8; attempt++) {
636-
const result = run(
637-
"prlctl",
638-
[
639-
"exec",
640-
this.options.vmName,
641-
"/usr/bin/env",
642-
"HOME=/root",
643-
"OPENCLAW_ALLOW_ROOT=1",
644-
"openclaw",
645-
"gateway",
646-
"status",
647-
"--deep",
648-
"--require-rpc",
649-
"--timeout",
650-
"15000",
651-
],
652-
{ check: false, quiet: true, timeoutMs: this.remainingPhaseTimeoutMs() },
624+
const result = this.guest.run(
625+
["openclaw", "gateway", "status", "--deep", "--require-rpc", "--timeout", "15000"],
626+
{ check: false },
653627
);
654-
this.log(result.stdout);
655-
this.log(result.stderr);
656628
if (result.status === 0) {
657629
return;
658630
}
@@ -710,6 +682,7 @@ rm -rf /root/.openclaw/test-bad-plugin`);
710682
}
711683

712684
private verifyLocalTurn(): void {
685+
this.guestBash(`set -euo pipefail\n${posixStopGatewayScript()}`);
713686
this.guestExec(["openclaw", "models", "set", this.auth.modelId]);
714687
const modelProviderConfigBatch = modelProviderConfigBatchJson(this.auth.modelId, "linux");
715688
if (modelProviderConfigBatch) {

0 commit comments

Comments
 (0)