Skip to content

Commit b74984d

Browse files
committed
fix(e2e): bound logged onboard commands
1 parent dfadc7b commit b74984d

4 files changed

Lines changed: 73 additions & 1 deletion

File tree

scripts/e2e/onboard-docker.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ OPENCLAW_TEST_STATE_FUNCTION_B64="$(docker_e2e_test_state_function_b64)"
88
MAX_MEMORY_MIB="${OPENCLAW_ONBOARD_MAX_MEMORY_MIB:-2048}"
99
MAX_CPU_PERCENT="${OPENCLAW_ONBOARD_MAX_CPU_PERCENT:-1200}"
1010
DOCKER_RUN_TIMEOUT="${OPENCLAW_ONBOARD_DOCKER_RUN_TIMEOUT:-1200s}"
11+
COMMAND_TIMEOUT="${OPENCLAW_ONBOARD_COMMAND_TIMEOUT:-${OPENCLAW_E2E_COMMAND_TIMEOUT:-300s}}"
1112
CONTAINER_NAME="openclaw-onboard-e2e-$$"
1213
RUN_LOG="$(mktemp "${TMPDIR:-/tmp}/openclaw-onboard.XXXXXX")"
1314
STATS_LOG="$(mktemp "${TMPDIR:-/tmp}/openclaw-onboard-stats.XXXXXX")"
@@ -25,6 +26,7 @@ docker_e2e_docker_cmd rm -f "$CONTAINER_NAME" >/dev/null 2>&1 || true
2526
docker_e2e_harness_mount_args
2627
DOCKER_COMMAND_TIMEOUT="$DOCKER_RUN_TIMEOUT" docker_e2e_docker_run_cmd run --name "$CONTAINER_NAME" "${DOCKER_E2E_HARNESS_ARGS[@]}" -t \
2728
-e "OPENCLAW_TEST_STATE_FUNCTION_B64=$OPENCLAW_TEST_STATE_FUNCTION_B64" \
29+
-e "OPENCLAW_E2E_COMMAND_TIMEOUT=$COMMAND_TIMEOUT" \
2830
"$IMAGE_NAME" bash scripts/e2e/lib/onboard/scenario.sh >"$RUN_LOG" 2>&1 &
2931
docker_pid="$!"
3032

scripts/lib/openclaw-e2e-instance.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ openclaw_e2e_assert_log_not_contains() {
332332
openclaw_e2e_run_logged() {
333333
local label="$1" log_path="/tmp/openclaw-onboard-${1}.log"
334334
shift
335-
"$@" >"$log_path" 2>&1 || { cat "$log_path"; exit 1; }
335+
local timeout_value="${OPENCLAW_E2E_COMMAND_TIMEOUT:-300s}"
336+
openclaw_e2e_maybe_timeout "$timeout_value" "$@" >"$log_path" 2>&1 || { cat "$log_path"; exit 1; }
336337
}
337338
openclaw_e2e_dump_logs() {
338339
local path

test/scripts/docker-build-helper.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,6 +1128,10 @@ test -f "$TMPDIR/docker-cmd-seen"
11281128

11291129
expect(runner).toContain("OPENCLAW_ONBOARD_MAX_MEMORY_MIB");
11301130
expect(runner).toContain("OPENCLAW_ONBOARD_MAX_CPU_PERCENT");
1131+
expect(runner).toContain(
1132+
'COMMAND_TIMEOUT="${OPENCLAW_ONBOARD_COMMAND_TIMEOUT:-${OPENCLAW_E2E_COMMAND_TIMEOUT:-300s}}"',
1133+
);
1134+
expect(runner).toContain('-e "OPENCLAW_E2E_COMMAND_TIMEOUT=$COMMAND_TIMEOUT"');
11311135
expect(runner).toContain('--name "$CONTAINER_NAME"');
11321136
expect(runner).toContain("docker_e2e_docker_cmd stats --no-stream");
11331137
expect(runner).toContain("assert-resource-ceiling.mjs");

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

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,4 +321,69 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
321321
fs.rmSync(tempDir, { force: true, recursive: true });
322322
}
323323
});
324+
325+
it("wraps logged OpenClaw E2E commands with the configured timeout", () => {
326+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-run-logged-"));
327+
const logLabel = path.basename(tempDir);
328+
const logPath = `/tmp/openclaw-onboard-${logLabel}.log`;
329+
try {
330+
const timeoutArgsPath = path.join(tempDir, "timeout-args.txt");
331+
const commandArgsPath = path.join(tempDir, "command-args.txt");
332+
fs.writeFileSync(
333+
path.join(tempDir, "timeout"),
334+
[
335+
"#!/usr/bin/env bash",
336+
"set -euo pipefail",
337+
'printf "%s\\n" "$*" >"$OPENCLAW_TEST_TIMEOUT_ARGS"',
338+
'while [ "$#" -gt 0 ] && [ "$1" != "fixture-command" ]; do shift; done',
339+
'exec "$@"',
340+
"",
341+
].join("\n"),
342+
);
343+
fs.writeFileSync(
344+
path.join(tempDir, "fixture-command"),
345+
[
346+
"#!/usr/bin/env bash",
347+
"set -euo pipefail",
348+
'printf "%s\\n" "$*" >"$OPENCLAW_TEST_COMMAND_ARGS"',
349+
'printf "fixture output\\n"',
350+
"",
351+
].join("\n"),
352+
);
353+
fs.chmodSync(path.join(tempDir, "timeout"), 0o755);
354+
fs.chmodSync(path.join(tempDir, "fixture-command"), 0o755);
355+
356+
const result = spawnSync(
357+
"/bin/bash",
358+
[
359+
"-c",
360+
[
361+
"set -euo pipefail",
362+
`source ${shellQuote(helperPath)}`,
363+
`openclaw_e2e_run_logged ${shellQuote(logLabel)} fixture-command one two`,
364+
].join("; "),
365+
],
366+
{
367+
encoding: "utf8",
368+
env: {
369+
...process.env,
370+
PATH: `${tempDir}:${process.env.PATH ?? ""}`,
371+
OPENCLAW_E2E_COMMAND_TIMEOUT: "17s",
372+
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
373+
OPENCLAW_TEST_COMMAND_ARGS: commandArgsPath,
374+
},
375+
},
376+
);
377+
378+
expect(result.status).toBe(0);
379+
expect(fs.readFileSync(timeoutArgsPath, "utf8").trim()).toBe(
380+
"--kill-after=30s 17s fixture-command one two",
381+
);
382+
expect(fs.readFileSync(commandArgsPath, "utf8").trim()).toBe("one two");
383+
expect(fs.readFileSync(logPath, "utf8")).toContain("fixture output");
384+
} finally {
385+
fs.rmSync(tempDir, { force: true, recursive: true });
386+
fs.rmSync(logPath, { force: true });
387+
}
388+
});
324389
});

0 commit comments

Comments
 (0)