fix(e2e): isolate onboard gateway logs

This commit is contained in:
Vincent Koc
2026-06-02 03:34:37 +02:00
parent 2e6016fdec
commit 7967a3582c
2 changed files with 46 additions and 3 deletions

View File

@@ -18,7 +18,9 @@ ONBOARD_TMP_ROOT="${ONBOARD_TMP_ROOT%/}"
mkdir -p "$ONBOARD_TMP_ROOT"
ONBOARD_TMP_DIR="$(mktemp -d "$ONBOARD_TMP_ROOT/openclaw-onboard.XXXXXX")"
OPENCLAW_E2E_LOG_DIR="$ONBOARD_TMP_DIR/logs"
GATEWAY_LOG_PATH="$ONBOARD_TMP_DIR/gateway-e2e.log"
export OPENCLAW_E2E_LOG_DIR
export GATEWAY_LOG_PATH
mkdir -p "$OPENCLAW_E2E_LOG_DIR"
cleanup_onboard_artifacts() {
openclaw_e2e_stop_process "${GATEWAY_PID:-}"
@@ -71,7 +73,7 @@ wait_for_log() {
}
start_gateway() {
GATEWAY_PID="$(openclaw_e2e_start_gateway "$OPENCLAW_ENTRY" 18789 /tmp/gateway-e2e.log)"
GATEWAY_PID="$(openclaw_e2e_start_gateway "$OPENCLAW_ENTRY" 18789 "$GATEWAY_LOG_PATH")"
}
wait_for_gateway() {
@@ -79,7 +81,7 @@ wait_for_gateway() {
if openclaw_e2e_probe_tcp 127.0.0.1 18789 500 >/dev/null 2>&1; then
return 0
fi
if [ -f /tmp/gateway-e2e.log ] && grep -E -q "listening on ws://[^ ]+:18789" /tmp/gateway-e2e.log; then
if [ -f "$GATEWAY_LOG_PATH" ] && grep -E -q "listening on ws://[^ ]+:18789" "$GATEWAY_LOG_PATH"; then
if [ -n "${GATEWAY_PID:-}" ] && kill -0 "$GATEWAY_PID" 2>/dev/null; then
return 0
fi
@@ -87,7 +89,7 @@ wait_for_gateway() {
sleep 1
done
echo "Gateway failed to start"
cat /tmp/gateway-e2e.log || true
cat "$GATEWAY_LOG_PATH" || true
return 1
}

View File

@@ -83,6 +83,8 @@ run_wizard_cmd failing-wizard fake-state "node fake-wizard" send_noop false
'ONBOARD_TMP_DIR="$(mktemp -d "$ONBOARD_TMP_ROOT/openclaw-onboard.XXXXXX")"',
);
expect(contents).toContain('OPENCLAW_E2E_LOG_DIR="$ONBOARD_TMP_DIR/logs"');
expect(contents).toContain('GATEWAY_LOG_PATH="$ONBOARD_TMP_DIR/gateway-e2e.log"');
expect(contents).not.toContain("/tmp/gateway-e2e.log");
expect(contents).toContain('validate_local_basic_log "$OPENCLAW_E2E_LAST_LOG_PATH"');
expect(contents).not.toContain(
"validate_local_basic_log /tmp/openclaw-onboard-local-basic.log",
@@ -91,4 +93,43 @@ run_wizard_cmd failing-wizard fake-state "node fake-wizard" send_noop false
'openclaw_e2e_assert_log_not_contains "$log_path" "systemctl --user unavailable"',
);
});
it("probes onboarding gateway readiness through the isolated scratch log", async () => {
const tempRoot = await mkdtemp(path.join(tmpdir(), "openclaw-onboard-gateway-log-"));
const fixturePath = path.join(tempRoot, "gateway-log.sh");
await writeFile(
fixturePath,
`#!/usr/bin/env bash
set -euo pipefail
export OPENCLAW_ONBOARD_SCENARIO_SOURCE_ONLY=1
export OPENCLAW_ONBOARD_E2E_TMPDIR=${JSON.stringify(tempRoot)}
OPENCLAW_ENTRY=node
source scripts/e2e/lib/onboard/scenario.sh
openclaw_e2e_probe_tcp() { return 1; }
sleep 30 &
GATEWAY_PID="$!"
printf 'listening on ws://127.0.0.1:18789\\n' >"$GATEWAY_LOG_PATH"
wait_for_gateway
case "$GATEWAY_LOG_PATH" in
"$ONBOARD_TMP_DIR"/*) ;;
*) echo "gateway log escaped scratch root: $GATEWAY_LOG_PATH" >&2; exit 1 ;;
esac
cleanup_onboard_artifacts
test ! -e "$ONBOARD_TMP_DIR"
`,
);
try {
const result = spawnSync("bash", [fixturePath], {
cwd: process.cwd(),
encoding: "utf8",
});
expect(result.status, `${result.stdout}\n${result.stderr}`).toBe(0);
} finally {
await rm(tempRoot, { force: true, recursive: true });
}
});
});