


























@@ -5,6 +5,7 @@ import path from "node:path";
55import { describe, expect, it } from "vitest";
6677const helperPath = path.resolve("scripts/lib/openclaw-e2e-instance.sh");
8+const hostPath = process.env.PATH?.trim() || "/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin";
89910function shellQuote(value: string): string {
1011return `'${value.replace(/'/gu, `'\\''`)}'`;
@@ -33,7 +34,8 @@ function base64(script: string): string {
3334function shellTestEnv(overrides: Record<string, string | undefined>): NodeJS.ProcessEnv {
3435const env: NodeJS.ProcessEnv = {
3536HOME: process.env.HOME ?? os.tmpdir(),
36-PATH: process.env.PATH ?? "",
37+PATH: hostPath,
38+SHELL: "/bin/bash",
3739TMPDIR: process.env.TMPDIR ?? os.tmpdir(),
3840};
3941for (const [key, value] of Object.entries(overrides)) {
@@ -44,6 +46,10 @@ function shellTestEnv(overrides: Record<string, string | undefined>): NodeJS.Pro
4446return env;
4547}
464849+function expectShellSuccess(result: ReturnType<typeof spawnSync>) {
50+expect(result.status, result.stderr || result.stdout || result.error?.message).toBe(0);
51+}
52+4753describe("scripts/lib/openclaw-e2e-instance.sh", () => {
4854it("sources decoded test-state scripts", () => {
4955const result = runHelper(base64('export OPENCLAW_E2E_INSTANCE_TEST="ok"\n'));
@@ -79,8 +85,8 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
7985fs.writeFileSync(
8086path.join(tempDir, "timeout"),
8187[
82-"#!/usr/bin/env bash",
83-"set -euo pipefail",
88+"#!/bin/sh",
89+"set -eu",
8490'printf "%s\\n" "$*" >"$OPENCLAW_TEST_TIMEOUT_ARGS"',
8591'while [ "$#" -gt 0 ] && [ "$1" != "npm" ]; do shift; done',
8692'exec "$@"',
@@ -107,7 +113,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
107113{
108114encoding: "utf8",
109115env: shellTestEnv({
110-PATH: `${tempDir}:${process.env.PATH ?? ""}`,
116+PATH: `${tempDir}${path.delimiter}${hostPath}`,
111117OPENCLAW_CURRENT_PACKAGE_TGZ: packagePath,
112118OPENCLAW_E2E_NPM_INSTALL_TIMEOUT: "42s",
113119OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
@@ -116,7 +122,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
116122},
117123);
118124119-expect(result.status).toBe(0);
125+expectShellSuccess(result);
120126expect(result.stdout).toContain("Installing fixture package...");
121127expect(fs.readFileSync(timeoutArgsPath, "utf8").trim()).toBe(
122128`--kill-after=30s 42s npm install -g ${packagePath} --no-fund --no-audit`,
@@ -140,8 +146,8 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
140146fs.writeFileSync(
141147path.join(tempDir, "timeout"),
142148[
143-"#!/usr/bin/env bash",
144-"set -euo pipefail",
149+"#!/bin/sh",
150+"set -eu",
145151'if [ "${1:-}" = "--kill-after=1s" ]; then',
146152" exit 1",
147153"fi",
@@ -171,7 +177,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
171177{
172178encoding: "utf8",
173179env: shellTestEnv({
174-PATH: `${tempDir}:${process.env.PATH ?? ""}`,
180+PATH: `${tempDir}${path.delimiter}${hostPath}`,
175181OPENCLAW_CURRENT_PACKAGE_TGZ: packagePath,
176182OPENCLAW_E2E_NPM_INSTALL_TIMEOUT: "42s",
177183OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
@@ -180,7 +186,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
180186},
181187);
182188183-expect(result.status).toBe(0);
189+expectShellSuccess(result);
184190expect(fs.readFileSync(timeoutArgsPath, "utf8").trim()).toBe(
185191`42s npm install -g ${packagePath} --no-fund --no-audit`,
186192);
@@ -240,7 +246,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
240246},
241247);
242248243-expect(result.status).toBe(0);
249+expectShellSuccess(result);
244250expect(fs.readFileSync(timeoutArgsPath, "utf8").trim()).toBe(
245251`--kill-after=30s 42s npm install -g ${packagePath} --no-fund --no-audit`,
246252);
@@ -287,7 +293,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
287293},
288294);
289295290-expect(result.status).toBe(0);
296+expectShellSuccess(result);
291297expect(fs.readFileSync(logPath, "utf8")).toContain("using Node watchdog");
292298expect(fs.readFileSync(npmArgsPath, "utf8").trim()).toBe(
293299`install -g ${packagePath} --no-fund --no-audit`,
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。