Skip to content

Commit eae4d28

Browse files
committed
fix(e2e): bound shared helper log output
1 parent 3643a68 commit eae4d28

2 files changed

Lines changed: 107 additions & 6 deletions

File tree

scripts/lib/openclaw-e2e-instance.sh

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,14 @@ NODE
174174
"$timeout_bin" "$timeout_value" "$@"
175175
fi
176176
}
177+
openclaw_e2e_print_log() {
178+
local path="$1"
179+
local max_bytes="${OPENCLAW_E2E_LOG_TAIL_BYTES:-262144}"
180+
local max_lines="${OPENCLAW_E2E_LOG_TAIL_LINES:-120}"
181+
[ -f "$path" ] || return 0
182+
echo "--- $path ---"
183+
tail -c "$max_bytes" "$path" 2>/dev/null | tail -n "$max_lines" || tail -n "$max_lines" "$path" || true
184+
}
177185
openclaw_e2e_install_package() {
178186
local log_file="$1"
179187
local label="${2:-mounted OpenClaw package}"
@@ -203,9 +211,7 @@ openclaw_e2e_install_package() {
203211
fi
204212
echo "npm install failed for $label" >&2
205213
if [ -f "$log_file" ]; then
206-
while IFS= read -r line || [ -n "$line" ]; do
207-
printf '%s\n' "$line" >&2
208-
done <"$log_file"
214+
openclaw_e2e_print_log "$log_file" >&2
209215
fi
210216
exit 1
211217
fi
@@ -470,7 +476,7 @@ openclaw_e2e_run_logged() {
470476
log_path="$(mktemp "$log_root/openclaw-${safe_label}.XXXXXX.log")"
471477
OPENCLAW_E2E_LAST_LOG_PATH="$log_path"
472478
export OPENCLAW_E2E_LAST_LOG_PATH
473-
openclaw_e2e_run_command "$@" >"$log_path" 2>&1 || { cat "$log_path"; exit 1; }
479+
openclaw_e2e_run_command "$@" >"$log_path" 2>&1 || { openclaw_e2e_print_log "$log_path"; exit 1; }
474480
}
475481
openclaw_e2e_run_command() {
476482
local timeout_value="${OPENCLAW_E2E_COMMAND_TIMEOUT:-300s}"
@@ -490,7 +496,6 @@ openclaw_e2e_enable_openclaw_cli_timeout() {
490496
openclaw_e2e_dump_logs() {
491497
local path
492498
for path in "$@"; do
493-
[ -f "$path" ] || continue
494-
echo "--- $path ---"; tail -n "${OPENCLAW_E2E_LOG_TAIL_LINES:-120}" "$path" || true
499+
openclaw_e2e_print_log "$path"
495500
done
496501
}

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,54 @@ describe("scripts/lib/openclaw-e2e-instance.sh", () => {
445445
}
446446
});
447447

448+
it("bounds npm install failure logs to the configured tail", () => {
449+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-install-log-"));
450+
try {
451+
const timeoutArgsPath = path.join(tempDir, "timeout-args.txt");
452+
const logPath = path.join(tempDir, "install.log");
453+
const packagePath = path.join(tempDir, "openclaw.tgz");
454+
const prefixPath = path.join(tempDir, "prefix");
455+
writePackageFixture(packagePath);
456+
writeFakeTimeout(path.join(tempDir, "timeout"), true);
457+
writeBashExecutable(path.join(tempDir, "npm"), [
458+
'printf "DO_NOT_PRINT_OLD_NPM_LOG\\n"',
459+
'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done',
460+
'printf "\\nrecent npm tail\\n"',
461+
"exit 42",
462+
]);
463+
464+
const result = spawnSync(
465+
"/bin/bash",
466+
[
467+
"-c",
468+
[
469+
"set -euo pipefail",
470+
`source ${shellQuote(helperPath)}`,
471+
`openclaw_e2e_install_package ${shellQuote(logPath)} ${shellQuote("fixture package")} ${shellQuote(prefixPath)}`,
472+
].join("; "),
473+
],
474+
{
475+
encoding: "utf8",
476+
env: shellTestEnv({
477+
PATH: `${tempDir}${path.delimiter}${hostPath}`,
478+
OPENCLAW_CURRENT_PACKAGE_TGZ: packagePath,
479+
OPENCLAW_E2E_LOG_TAIL_BYTES: "80",
480+
OPENCLAW_E2E_NPM_INSTALL_TIMEOUT: "42s",
481+
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
482+
}),
483+
},
484+
);
485+
486+
expect(result.status).toBe(1);
487+
expect(result.stderr).toContain("npm install failed for fixture package");
488+
expect(result.stderr).toContain("recent npm tail");
489+
expect(result.stderr).not.toContain("DO_NOT_PRINT_OLD_NPM_LOG");
490+
expect(fs.readFileSync(logPath, "utf8")).toContain("DO_NOT_PRINT_OLD_NPM_LOG");
491+
} finally {
492+
fs.rmSync(tempDir, { force: true, recursive: true });
493+
}
494+
});
495+
448496
it("bounds commands with the Node watchdog when timeout is unavailable", () => {
449497
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-node-watchdog-"));
450498
try {
@@ -912,6 +960,54 @@ exit 1
912960
}
913961
});
914962

963+
it("bounds logged command failure output to the configured tail", () => {
964+
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-instance-run-log-tail-"));
965+
const logLabel = path.basename(tempDir);
966+
const logDir = path.join(tempDir, "logs");
967+
try {
968+
const timeoutArgsPath = path.join(tempDir, "timeout-args.txt");
969+
writeFakeTimeout(path.join(tempDir, "timeout"), true);
970+
writeBashExecutable(path.join(tempDir, "fixture-command"), [
971+
'printf "DO_NOT_PRINT_OLD_COMMAND_LOG\\n"',
972+
'i=0; while [ "$i" -lt 220 ]; do printf "x"; i=$((i + 1)); done',
973+
'printf "\\nrecent command tail\\n"',
974+
"exit 23",
975+
]);
976+
977+
const result = spawnSync(
978+
"/bin/bash",
979+
[
980+
"-c",
981+
[
982+
"set -euo pipefail",
983+
`source ${shellQuote(helperPath)}`,
984+
`openclaw_e2e_run_logged ${shellQuote(logLabel)} fixture-command`,
985+
].join("; "),
986+
],
987+
{
988+
encoding: "utf8",
989+
env: shellTestEnv({
990+
PATH: `${tempDir}${path.delimiter}${hostPath}`,
991+
OPENCLAW_E2E_COMMAND_TIMEOUT: "17s",
992+
OPENCLAW_E2E_LOG_DIR: logDir,
993+
OPENCLAW_E2E_LOG_TAIL_BYTES: "80",
994+
OPENCLAW_TEST_TIMEOUT_ARGS: timeoutArgsPath,
995+
}),
996+
},
997+
);
998+
999+
expect(result.status).toBe(1);
1000+
expect(result.stdout).toContain("recent command tail");
1001+
expect(result.stdout).not.toContain("DO_NOT_PRINT_OLD_COMMAND_LOG");
1002+
const [logFile] = fs.readdirSync(logDir);
1003+
expect(fs.readFileSync(path.join(logDir, logFile), "utf8")).toContain(
1004+
"DO_NOT_PRINT_OLD_COMMAND_LOG",
1005+
);
1006+
} finally {
1007+
fs.rmSync(tempDir, { force: true, recursive: true });
1008+
}
1009+
});
1010+
9151011
it("installs the trash shim under isolated test state", () => {
9161012
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-e2e-trash-shim-"));
9171013
try {

0 commit comments

Comments
 (0)