mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(e2e): bound docker log printing
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -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-"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user