Skip to content

Commit c5b9a53

Browse files
committed
test: stabilize e2e timeout fixture path
1 parent 4fa9234 commit c5b9a53

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

test/scripts/openclaw-e2e-instance.test.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import path from "node:path";
55
import { describe, expect, it } from "vitest";
66

77
const 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";
8+
const hostPath = [
9+
path.dirname(process.execPath),
10+
"/usr/local/bin",
11+
"/opt/homebrew/bin",
12+
"/usr/bin",
13+
"/bin",
14+
].join(path.delimiter);
915

1016
function shellQuote(value: string): string {
1117
return `'${value.replace(/'/gu, `'\\''`)}'`;
@@ -65,6 +71,16 @@ function writePackageFixture(packagePath: string): void {
6571
}
6672
}
6773

74+
function writeNodeShim(binDir: string): void {
75+
const nodePath = path.join(binDir, "node");
76+
try {
77+
fs.symlinkSync(process.execPath, nodePath);
78+
} catch {
79+
fs.writeFileSync(nodePath, `#!/bin/sh\nexec ${shellQuote(process.execPath)} "$@"\n`);
80+
fs.chmodSync(nodePath, 0o755);
81+
}
82+
}
83+
6884
describe("scripts/lib/openclaw-e2e-instance.sh", () => {
6985
it("sources decoded test-state scripts", () => {
7086
const result = runHelper(base64('export OPENCLAW_E2E_INSTANCE_TEST="ok"\n'));
@@ -294,8 +310,8 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
294310
const npmArgsPath = path.join(tempDir, "npm-args.txt");
295311
const logPath = path.join(tempDir, "install.log");
296312
const packagePath = path.join(tempDir, "openclaw.tgz");
297-
const nodeBinDir = path.dirname(process.execPath);
298313
writePackageFixture(packagePath);
314+
writeNodeShim(tempDir);
299315
fs.writeFileSync(
300316
path.join(tempDir, "npm"),
301317
["#!/bin/sh", "set -eu", 'printf "%s\\n" "$*" >"$OPENCLAW_TEST_NPM_ARGS"', ""].join("\n"),
@@ -315,7 +331,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
315331
{
316332
encoding: "utf8",
317333
env: shellTestEnv({
318-
PATH: `${tempDir}:${nodeBinDir}`,
334+
PATH: tempDir,
319335
OPENCLAW_CURRENT_PACKAGE_TGZ: packagePath,
320336
OPENCLAW_E2E_NPM_INSTALL_TIMEOUT: "42s",
321337
OPENCLAW_TEST_NPM_ARGS: npmArgsPath,
@@ -336,7 +352,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
336352
it("bounds commands with the Node watchdog when timeout is unavailable", () => {
337353
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-node-watchdog-"));
338354
try {
339-
const nodeBinDir = path.dirname(process.execPath);
355+
writeNodeShim(tempDir);
340356
const startedAt = Date.now();
341357
const result = spawnSync(
342358
"/bin/bash",
@@ -351,7 +367,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
351367
{
352368
encoding: "utf8",
353369
env: shellTestEnv({
354-
PATH: `${tempDir}:${nodeBinDir}`,
370+
PATH: tempDir,
355371
}),
356372
timeout: 5_000,
357373
},
@@ -460,7 +476,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
460476
{
461477
encoding: "utf8",
462478
env: shellTestEnv({
463-
PATH: `${tempDir}:${process.env.PATH ?? ""}`,
479+
PATH: `${tempDir}:${hostPath}`,
464480
OPENCLAW_E2E_COMMAND_TIMEOUT: "17s",
465481
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
466482
OPENCLAW_TEST_COMMAND_ARGS: commandArgsPath,
@@ -527,7 +543,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
527543
{
528544
encoding: "utf8",
529545
env: shellTestEnv({
530-
PATH: `${tempDir}:${process.env.PATH ?? ""}`,
546+
PATH: `${tempDir}:${hostPath}`,
531547
OPENCLAW_E2E_COMMAND_TIMEOUT: "23s",
532548
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
533549
OPENCLAW_TEST_COMMAND_ARGS: commandArgsPath,
@@ -592,7 +608,7 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
592608
{
593609
encoding: "utf8",
594610
env: shellTestEnv({
595-
PATH: `${tempDir}:${process.env.PATH ?? ""}`,
611+
PATH: `${tempDir}:${hostPath}`,
596612
OPENCLAW_E2E_COMMAND_TIMEOUT: "31s",
597613
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
598614
OPENCLAW_TEST_SCRIPT_ARGS: scriptArgsPath,

0 commit comments

Comments
 (0)