fix(e2e): require TCP gateway readiness

This commit is contained in:
Vincent Koc
2026-06-06 16:40:59 +02:00
parent 205d00bf82
commit bb056dca84
2 changed files with 54 additions and 7 deletions
+9 -5
View File
@@ -77,18 +77,22 @@ start_gateway() {
}
wait_for_gateway() {
for _ in $(seq 1 20); do
local wait_attempts="${OPENCLAW_ONBOARD_GATEWAY_WAIT_ATTEMPTS:-20}"
local wait_interval_s="${OPENCLAW_ONBOARD_GATEWAY_WAIT_INTERVAL_S:-1}"
local saw_listening_log="false"
for _ in $(seq 1 "$wait_attempts"); do
if openclaw_e2e_probe_tcp 127.0.0.1 18789 500 >/dev/null 2>&1; then
return 0
fi
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
saw_listening_log="true"
fi
sleep 1
sleep "$wait_interval_s"
done
echo "Gateway failed to start"
if [ "$saw_listening_log" = "true" ]; then
echo "Gateway log reported listening, but TCP probe never succeeded"
fi
cat "$GATEWAY_LOG_PATH" || true
return 1
}
+45 -2
View File
@@ -95,7 +95,7 @@ run_wizard_cmd failing-wizard fake-state "node fake-wizard" send_noop false
);
});
it("probes onboarding gateway readiness through the isolated scratch log", async () => {
it("probes onboarding gateway readiness through TCP", async () => {
const tempRoot = await mkdtemp(path.join(tmpdir(), "openclaw-onboard-gateway-log-"));
const fixturePath = path.join(tempRoot, "gateway-log.sh");
await writeFile(
@@ -108,7 +108,7 @@ export OPENCLAW_ONBOARD_E2E_TMPDIR=${JSON.stringify(tempRoot)}
OPENCLAW_ENTRY=node
source scripts/e2e/lib/onboard/scenario.sh
openclaw_e2e_probe_tcp() { return 1; }
openclaw_e2e_probe_tcp() { return 0; }
sleep 30 &
GATEWAY_PID="$!"
printf 'listening on ws://127.0.0.1:18789\\n' >"$GATEWAY_LOG_PATH"
@@ -134,6 +134,49 @@ test ! -e "$ONBOARD_TMP_DIR"
}
});
it("rejects onboarding gateway readiness when the TCP probe fails", async () => {
const tempRoot = await mkdtemp(path.join(tmpdir(), "openclaw-onboard-gateway-tcp-"));
const fixturePath = path.join(tempRoot, "gateway-tcp.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)}
export OPENCLAW_ONBOARD_GATEWAY_WAIT_ATTEMPTS=2
export OPENCLAW_ONBOARD_GATEWAY_WAIT_INTERVAL_S=0.1
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"
if wait_for_gateway; then
echo "gateway readiness passed without TCP reachability" >&2
cleanup_onboard_artifacts
exit 1
fi
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);
expect(result.stdout).toContain("Gateway failed to start");
expect(result.stdout).toContain("TCP probe never succeeded");
} finally {
await rm(tempRoot, { force: true, recursive: true });
}
});
it("removes fallback ClawHub skill install HOME on failure", async () => {
const tempRoot = await mkdtemp(path.join(tmpdir(), "openclaw-clawhub-home-test-"));
const fakeBin = path.join(tempRoot, "bin");