fix(e2e): bound shared helper log output

This commit is contained in:
Vincent Koc
2026-06-07 10:19:16 +02:00
parent 3643a68e49
commit eae4d284e7
2 changed files with 107 additions and 6 deletions
+11 -6
View File
@@ -174,6 +174,14 @@ NODE
"$timeout_bin" "$timeout_value" "$@"
fi
}
openclaw_e2e_print_log() {
local path="$1"
local max_bytes="${OPENCLAW_E2E_LOG_TAIL_BYTES:-262144}"
local max_lines="${OPENCLAW_E2E_LOG_TAIL_LINES:-120}"
[ -f "$path" ] || return 0
echo "--- $path ---"
tail -c "$max_bytes" "$path" 2>/dev/null | tail -n "$max_lines" || tail -n "$max_lines" "$path" || true
}
openclaw_e2e_install_package() {
local log_file="$1"
local label="${2:-mounted OpenClaw package}"
@@ -203,9 +211,7 @@ openclaw_e2e_install_package() {
fi
echo "npm install failed for $label" >&2
if [ -f "$log_file" ]; then
while IFS= read -r line || [ -n "$line" ]; do
printf '%s\n' "$line" >&2
done <"$log_file"
openclaw_e2e_print_log "$log_file" >&2
fi
exit 1
fi
@@ -470,7 +476,7 @@ openclaw_e2e_run_logged() {
log_path="$(mktemp "$log_root/openclaw-${safe_label}.XXXXXX.log")"
OPENCLAW_E2E_LAST_LOG_PATH="$log_path"
export OPENCLAW_E2E_LAST_LOG_PATH
openclaw_e2e_run_command "$@" >"$log_path" 2>&1 || { cat "$log_path"; exit 1; }
openclaw_e2e_run_command "$@" >"$log_path" 2>&1 || { openclaw_e2e_print_log "$log_path"; exit 1; }
}
openclaw_e2e_run_command() {
local timeout_value="${OPENCLAW_E2E_COMMAND_TIMEOUT:-300s}"
@@ -490,7 +496,6 @@ openclaw_e2e_enable_openclaw_cli_timeout() {
openclaw_e2e_dump_logs() {
local path
for path in "$@"; do
[ -f "$path" ] || continue
echo "--- $path ---"; tail -n "${OPENCLAW_E2E_LOG_TAIL_LINES:-120}" "$path" || true
openclaw_e2e_print_log "$path"
done
}
@@ -445,6 +445,54 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
}
});
it("bounds npm install failure logs to the configured tail", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-install-log-"));
try {
const timeoutArgsPath = path.join(tempDir, "timeout-args.txt");
const logPath = path.join(tempDir, "install.log");
const packagePath = path.join(tempDir, "openclaw.tgz");
const prefixPath = path.join(tempDir, "prefix");
writePackageFixture(packagePath);
writeFakeTimeout(path.join(tempDir, "timeout"), true);
writeBashExecutable(path.join(tempDir, "npm"), [
'printf "DO_NOT_PRINT_OLD_NPM_LOG\\n"',
'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done',
'printf "\\nrecent npm tail\\n"',
"exit 42",
]);
const result = spawnSync(
"/bin/bash",
[
"-c",
[
"set -euo pipefail",
`source ${shellQuote(helperPath)}`,
`openclaw_e2e_install_package ${shellQuote(logPath)} ${shellQuote("fixture package")} ${shellQuote(prefixPath)}`,
].join("; "),
],
{
encoding: "utf8",
env: shellTestEnv({
PATH: `${tempDir}${path.delimiter}${hostPath}`,
OPENCLAW_CURRENT_PACKAGE_TGZ: packagePath,
OPENCLAW_E2E_LOG_TAIL_BYTES: "80",
OPENCLAW_E2E_NPM_INSTALL_TIMEOUT: "42s",
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
}),
},
);
expect(result.status).toBe(1);
expect(result.stderr).toContain("npm install failed for fixture package");
expect(result.stderr).toContain("recent npm tail");
expect(result.stderr).not.toContain("DO_NOT_PRINT_OLD_NPM_LOG");
expect(fs.readFileSync(logPath, "utf8")).toContain("DO_NOT_PRINT_OLD_NPM_LOG");
} finally {
fs.rmSync(tempDir, { force: true, recursive: true });
}
});
it("bounds commands with the Node watchdog when timeout is unavailable", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-node-watchdog-"));
try {
@@ -912,6 +960,54 @@ exit 1
}
});
it("bounds logged command failure output to the configured tail", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-run-log-tail-"));
const logLabel = path.basename(tempDir);
const logDir = path.join(tempDir, "logs");
try {
const timeoutArgsPath = path.join(tempDir, "timeout-args.txt");
writeFakeTimeout(path.join(tempDir, "timeout"), true);
writeBashExecutable(path.join(tempDir, "fixture-command"), [
'printf "DO_NOT_PRINT_OLD_COMMAND_LOG\\n"',
'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done',
'printf "\\nrecent command tail\\n"',
"exit 23",
]);
const result = spawnSync(
"/bin/bash",
[
"-c",
[
"set -euo pipefail",
`source ${shellQuote(helperPath)}`,
`openclaw_e2e_run_logged ${shellQuote(logLabel)} fixture-command`,
].join("; "),
],
{
encoding: "utf8",
env: shellTestEnv({
PATH: `${tempDir}${path.delimiter}${hostPath}`,
OPENCLAW_E2E_COMMAND_TIMEOUT: "17s",
OPENCLAW_E2E_LOG_DIR: logDir,
OPENCLAW_E2E_LOG_TAIL_BYTES: "80",
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
}),
},
);
expect(result.status).toBe(1);
expect(result.stdout).toContain("recent command tail");
expect(result.stdout).not.toContain("DO_NOT_PRINT_OLD_COMMAND_LOG");
const [logFile] = fs.readdirSync(logDir);
expect(fs.readFileSync(path.join(logDir, logFile), "utf8")).toContain(
"DO_NOT_PRINT_OLD_COMMAND_LOG",
);
} finally {
fs.rmSync(tempDir, { force: true, recursive: true });
}
});
it("installs the trash shim under isolated test state", () => {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-trash-shim-"));
try {