From 586cf18b8d7c3baaca4164cebe0e392d9972bdbd Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 7 Jun 2026 05:30:00 +0200 Subject: [PATCH] fix(e2e): bound docker log printing --- scripts/lib/docker-e2e-logs.sh | 22 +++++++++++++++++- test/scripts/docker-build-helper.test.ts | 29 ++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/scripts/lib/docker-e2e-logs.sh b/scripts/lib/docker-e2e-logs.sh index 3d5f839b0b21..fb8882b9d5ed 100644 --- a/scripts/lib/docker-e2e-logs.sh +++ b/scripts/lib/docker-e2e-logs.sh @@ -78,5 +78,25 @@ docker_e2e_run_log() { docker_e2e_print_log() { local log_file="$1" - cat "$log_file" + local max_bytes="${OPENCLAW_DOCKER_E2E_LOG_PRINT_BYTES:-65536}" + if ! [[ "$max_bytes" =~ ^[0-9]+$ ]] || [ "$max_bytes" -lt 1 ]; then + max_bytes="65536" + else + max_bytes="$((10#$max_bytes))" + fi + if [ ! -f "$log_file" ]; then + return 0 + fi + local log_bytes + log_bytes="$(wc -c <"$log_file" 2>/dev/null || echo 0)" + log_bytes="${log_bytes//[[:space:]]/}" + if ! [[ "$log_bytes" =~ ^[0-9]+$ ]]; then + log_bytes="0" + fi + if [ "$log_bytes" -le "$max_bytes" ]; then + cat "$log_file" + return 0 + fi + echo "--- ${log_file} truncated: showing last ${max_bytes} of ${log_bytes} bytes ---" + tail -c "$max_bytes" "$log_file" } diff --git a/test/scripts/docker-build-helper.test.ts b/test/scripts/docker-build-helper.test.ts index b5756b20e138..a71bb8089d15 100644 --- a/test/scripts/docker-build-helper.test.ts +++ b/test/scripts/docker-build-helper.test.ts @@ -1818,10 +1818,39 @@ test -f "$TMPDIR/docker-cmd-seen" expect(helper).toContain("docker_e2e_run_logged_print_with_harness()"); expect(helper).toContain("run_logged_print_heartbeat \\"); expect(helper).toContain("OPENCLAW_DOCKER_E2E_LOG_HEARTBEAT_SECONDS"); + expect(readFileSync("scripts/lib/docker-e2e-logs.sh", "utf8")).toContain( + "OPENCLAW_DOCKER_E2E_LOG_PRINT_BYTES", + ); expect(runner).toContain("docker_e2e_run_logged_print_with_harness \\"); expect(runner).not.toContain("docker_e2e_run_logged_with_harness plugins-run"); }); + it("bounds printed Docker E2E logs to the configured tail", () => { + const workDir = mkdtempSync(join(tmpdir(), "openclaw-docker-e2e-log-print-tail-")); + + try { + const rootDir = process.cwd(); + const script = ` +set -euo pipefail +ROOT_DIR=${shellQuote(rootDir)} +TMPDIR=${shellQuote(workDir)} +export ROOT_DIR TMPDIR +export OPENCLAW_DOCKER_E2E_LOG_PRINT_BYTES=64 + +source "$ROOT_DIR/scripts/lib/docker-e2e-logs.sh" + +output="$(run_logged_print_heartbeat plugins-run 30 bash -c 'printf "DO_NOT_PRINT_OLD_LOG_START"; printf "%0200d" 0; printf "recent container log tail\\\\n"')" +[[ "$output" = *"truncated: showing last 64"* ]] +[[ "$output" = *"recent container log tail"* ]] +[[ "$output" != *"DO_NOT_PRINT_OLD_LOG_START"* ]] +`; + + execFileSync("bash", ["-lc", script], { encoding: "utf8" }); + } finally { + rmSync(workDir, { recursive: true, force: true }); + } + }); + it("prints heartbeat progress for long successful Docker E2E log captures", () => { const workDir = mkdtempSync(join(tmpdir(), "openclaw-docker-e2e-log-heartbeat-"));