Skip to content

Commit 2eaa83f

Browse files
committed
test(qa): prove container health endpoints
1 parent 9dfc74e commit 2eaa83f

2 files changed

Lines changed: 227 additions & 22 deletions

File tree

‎qa/scenarios/runtime/compose-setup.yaml‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,40 @@ scenario:
55
surface: containers
66
category: containers.container-setup
77
coverage:
8+
primary:
9+
- containers.docker-compose-gateway
10+
- containers.container-health-endpoints
811
secondary:
912
- containers.docker-compose-mounts-and-secrets
10-
objective: Launch the documented Docker Compose topology from the package-backed functional image and record the exact package, image, and service container identities.
13+
objective: Launch the documented Docker Compose topology from the package-backed functional image and prove its liveness, readiness, authenticated health CLI, Docker health state, recovery, and operator diagnostics.
1114
successCriteria:
1215
- The scheduler builds the real package artifact and package-backed functional image through the canonical Docker planner.
1316
- "`docker compose up` starts the documented `openclaw-gateway` service with isolated state, config, workspace, and auth-profile mounts."
14-
- The Gateway reaches healthy state and the documented container-side health command passes.
15-
- "The `openclaw-cli` Compose service runs successfully in the Gateway network namespace."
16-
- Evidence records the package digest and version, functional image ID, and Gateway and CLI container IDs.
17+
- The Dockerfile definition, resolved Compose configuration, and running container all use `node dist/docker-healthcheck.js`.
18+
- "`/healthz` reports live and `/readyz` reports ready before and after a bounded forced-unhealthy cycle."
19+
- Wrong tokens fail and the configured token passes for `gateway health --json` from both the Gateway service and `openclaw-cli` sidecar.
20+
- Docker records the forced failure as `unhealthy`, records a successful recovery to `healthy`, and exposes non-empty `State.Health` and Compose log diagnostics.
21+
- Evidence records the package digest and version, functional image ID, Gateway and CLI container IDs, and explicit pass markers for each health boundary.
1722
docsRefs:
1823
- docs/install/docker.md
24+
- docs/cli/gateway.md
25+
- docs/gateway/logging.md
26+
- docs/gateway/opentelemetry.md
27+
- docs/gateway/prometheus.md
1928
- docs/help/testing.md
2029
codeRefs:
30+
- Dockerfile
2131
- docker-compose.yml
32+
- src/docker-healthcheck.ts
33+
- src/gateway/server-http.ts
2234
- scripts/e2e/compose-setup.sh
2335
- scripts/lib/docker-e2e-scenarios.mjs
2436
- scripts/package-openclaw-for-docker.mjs
2537
- test/e2e/qa-lab/runtime/docker-artifact-proof.ts
2638
execution:
2739
kind: script
2840
path: test/e2e/qa-lab/runtime/docker-artifact-proof.ts
29-
summary: Builds the package-backed functional image, launches the documented Compose services, validates health, and records artifact identities.
41+
summary: Builds the package-backed functional image, launches the documented Compose services, validates endpoint and authenticated CLI health, forces and recovers Docker health state, captures diagnostics, and records artifact identities.
3042
timeoutMs: 1800000
3143
args:
3244
- --artifact-base

‎scripts/e2e/compose-setup.sh‎

Lines changed: 210 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ PROJECT_DIR="$(mktemp -d "${TMPDIR:-/tmp}/openclaw-compose-proof.XXXXXX")"
1111
PROJECT_NAME="openclaw-compose-proof-$$"
1212
CLI_NAME="$PROJECT_NAME-cli-proof"
1313
TOKEN="compose-proof-$$-$(date +%s)"
14-
COMPOSE=(docker compose --project-name "$PROJECT_NAME" --project-directory "$PROJECT_DIR" -f "$ROOT_DIR/docker-compose.yml")
14+
WRONG_TOKEN="$TOKEN-wrong"
15+
HEALTH_OVERRIDE_PATH="$PROJECT_DIR/compose-health-override.yaml"
16+
COMPOSE=(
17+
docker compose
18+
--project-name "$PROJECT_NAME"
19+
--project-directory "$PROJECT_DIR"
20+
-f "$ROOT_DIR/docker-compose.yml"
21+
-f "$HEALTH_OVERRIDE_PATH"
22+
)
1523

1624
cleanup() {
1725
docker_e2e_docker_cmd rm -f "$CLI_NAME" >/dev/null 2>&1 || true
@@ -43,6 +51,141 @@ if (
4351
) {
4452
throw new Error(`${label} gateway health JSON is incomplete`);
4553
}
54+
NODE
55+
echo "$label accepted the configured token and returned a complete health envelope."
56+
}
57+
58+
assert_dockerfile_healthcheck() {
59+
node - "$ROOT_DIR/Dockerfile" <<'NODE'
60+
const fs = require("node:fs");
61+
const dockerfilePath = process.argv[2];
62+
const dockerfile = fs.readFileSync(dockerfilePath, "utf8").replace(/\\\r?\n[ \t]*/g, " ");
63+
if (!/HEALTHCHECK\b[^\n]*CMD \["node", "dist\/docker-healthcheck\.js"\]/u.test(dockerfile)) {
64+
throw new Error("Dockerfile does not install the built Gateway healthcheck");
65+
}
66+
NODE
67+
echo "Dockerfile healthcheck definition uses dist/docker-healthcheck.js."
68+
}
69+
70+
assert_effective_healthcheck() {
71+
local label="$1"
72+
local kind="$2"
73+
local inspect_path="$3"
74+
node - "$label" "$kind" "$inspect_path" <<'NODE'
75+
const fs = require("node:fs");
76+
const label = process.argv[2];
77+
const kind = process.argv[3];
78+
const inspectPath = process.argv[4];
79+
const payload = JSON.parse(fs.readFileSync(inspectPath, "utf8"));
80+
const actual =
81+
kind === "compose"
82+
? payload?.services?.["openclaw-gateway"]?.healthcheck?.test
83+
: payload?.[0]?.Config?.Healthcheck?.Test;
84+
const expected = ["CMD", "node", "dist/docker-healthcheck.js"];
85+
if (JSON.stringify(actual) !== JSON.stringify(expected)) {
86+
throw new Error(`${label} healthcheck mismatch: ${JSON.stringify(actual)}`);
87+
}
88+
NODE
89+
echo "$label uses dist/docker-healthcheck.js."
90+
}
91+
92+
wait_for_gateway_health() {
93+
local expected="$1"
94+
local attempts="$2"
95+
local health=""
96+
for _ in $(seq 1 "$attempts"); do
97+
health="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$GATEWAY_ID")"
98+
if [ "$health" = "$expected" ]; then
99+
return 0
100+
fi
101+
if [ "$health" = "exited" ] || [ "$health" = "dead" ]; then
102+
break
103+
fi
104+
sleep 1
105+
done
106+
echo "Gateway health did not reach $expected (last state: $health)" >&2
107+
docker inspect --format '{{json .State.Health}}' "$GATEWAY_ID" >&2 || true
108+
"${COMPOSE[@]}" logs --no-color openclaw-gateway >&2 || true
109+
return 1
110+
}
111+
112+
assert_probe_endpoints() {
113+
local label="$1"
114+
local output_path="$2"
115+
"${COMPOSE[@]}" exec -T openclaw-gateway node - "$label" >"$output_path" <<'NODE'
116+
const label = process.argv[2];
117+
const readJson = async (path) => {
118+
const response = await fetch(`http://127.0.0.1:18789${path}`);
119+
const body = await response.json();
120+
return { body, status: response.status };
121+
};
122+
const health = await readJson("/healthz");
123+
const ready = await readJson("/readyz");
124+
if (
125+
health.status !== 200 ||
126+
health.body?.ok !== true ||
127+
health.body?.status !== "live"
128+
) {
129+
throw new Error(`${label} /healthz did not report live: ${JSON.stringify(health)}`);
130+
}
131+
if (
132+
ready.status !== 200 ||
133+
ready.body?.ready !== true ||
134+
!Array.isArray(ready.body?.failing) ||
135+
ready.body.failing.length !== 0
136+
) {
137+
throw new Error(`${label} /readyz did not report ready: ${JSON.stringify(ready)}`);
138+
}
139+
console.log(JSON.stringify({ healthz: health, label, readyz: ready }));
140+
NODE
141+
echo "$label: /healthz is live and /readyz is ready."
142+
}
143+
144+
assert_auth_rejected() {
145+
local label="$1"
146+
local stdout_path="$2"
147+
local stderr_path="$3"
148+
shift 3
149+
local exit_code
150+
set +e
151+
"$@" >"$stdout_path" 2>"$stderr_path"
152+
exit_code=$?
153+
set -e
154+
if [ "$exit_code" -eq 0 ]; then
155+
echo "$label accepted an invalid Gateway token" >&2
156+
return 1
157+
fi
158+
node - "$label" "$stdout_path" "$stderr_path" <<'NODE'
159+
const fs = require("node:fs");
160+
const label = process.argv[2];
161+
const output = [process.argv[3], process.argv[4]]
162+
.map((path) => fs.readFileSync(path, "utf8"))
163+
.join("\n");
164+
if (!/(unauthorized|token mismatch|authentication)/iu.test(output)) {
165+
throw new Error(`${label} failed without an authentication diagnostic`);
166+
}
167+
NODE
168+
echo "$label rejected an invalid Gateway token (exit $exit_code)."
169+
}
170+
171+
assert_health_state() {
172+
local label="$1"
173+
local expected="$2"
174+
local health_path="$3"
175+
node - "$label" "$expected" "$health_path" <<'NODE'
176+
const fs = require("node:fs");
177+
const label = process.argv[2];
178+
const expected = process.argv[3];
179+
const healthPath = process.argv[4];
180+
const health = JSON.parse(fs.readFileSync(healthPath, "utf8"));
181+
if (health?.Status !== expected || !Array.isArray(health.Log) || health.Log.length === 0) {
182+
throw new Error(`${label} Docker health state is incomplete: ${JSON.stringify(health)}`);
183+
}
184+
const expectedExit = expected === "unhealthy" ? (code) => code !== 0 : (code) => code === 0;
185+
if (!health.Log.some((entry) => expectedExit(Number(entry?.ExitCode)))) {
186+
throw new Error(`${label} Docker health log lacks the expected exit status`);
187+
}
188+
console.log(`${label}: ${JSON.stringify({ log: health.Log.slice(-3), status: health.Status })}`);
46189
NODE
47190
}
48191

@@ -57,6 +200,15 @@ cat >"$PROJECT_DIR/config/openclaw.json" <<EOF
57200
}
58201
}
59202
EOF
203+
cat >"$HEALTH_OVERRIDE_PATH" <<'EOF'
204+
services:
205+
openclaw-gateway:
206+
healthcheck:
207+
interval: 1s
208+
timeout: 5s
209+
retries: 3
210+
start_period: 5s
211+
EOF
60212

61213
export OPENCLAW_IMAGE="$IMAGE_NAME"
62214
export OPENCLAW_CONFIG_DIR="$PROJECT_DIR/config"
@@ -71,36 +223,64 @@ export OPENCLAW_CURRENT_PACKAGE_TGZ="$PACKAGE_TGZ"
71223

72224
docker_e2e_build_or_reuse "$IMAGE_NAME" compose-setup "$ROOT_DIR/scripts/e2e/Dockerfile" "$ROOT_DIR" functional
73225

226+
assert_dockerfile_healthcheck
227+
"${COMPOSE[@]}" config --format json >"$PROJECT_DIR/compose-config.json"
228+
assert_effective_healthcheck "resolved Compose service" compose "$PROJECT_DIR/compose-config.json"
229+
74230
echo "Launching documented Docker Compose gateway topology..."
75231
"${COMPOSE[@]}" up -d --no-build openclaw-gateway
76232
GATEWAY_ID="$("${COMPOSE[@]}" ps -q openclaw-gateway)"
77233
if [ -z "$GATEWAY_ID" ]; then
78234
echo "Compose did not create openclaw-gateway" >&2
79235
exit 1
80236
fi
237+
docker inspect "$GATEWAY_ID" >"$PROJECT_DIR/gateway-container.json"
238+
assert_effective_healthcheck "running Gateway container" container "$PROJECT_DIR/gateway-container.json"
81239

82-
for _ in $(seq 1 180); do
83-
health="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$GATEWAY_ID")"
84-
if [ "$health" = "healthy" ]; then
85-
break
86-
fi
87-
if [ "$health" = "unhealthy" ] || [ "$health" = "exited" ] || [ "$health" = "dead" ]; then
88-
"${COMPOSE[@]}" logs --no-color openclaw-gateway >&2
89-
exit 1
90-
fi
91-
sleep 1
92-
done
93-
if [ "$(docker inspect --format '{{.State.Health.Status}}' "$GATEWAY_ID")" != "healthy" ]; then
94-
"${COMPOSE[@]}" logs --no-color openclaw-gateway >&2
95-
echo "Compose gateway did not become healthy" >&2
96-
exit 1
97-
fi
240+
wait_for_gateway_health healthy 180
241+
docker inspect --format '{{json .State.Health}}' "$GATEWAY_ID" >"$PROJECT_DIR/health-initial.json"
242+
assert_health_state "initial healthy state" healthy "$PROJECT_DIR/health-initial.json"
243+
assert_probe_endpoints "initial probes" "$PROJECT_DIR/probes-initial.json"
98244

99245
"${COMPOSE[@]}" exec -T openclaw-gateway sh -lc 'node dist/index.js gateway health --token "$OPENCLAW_GATEWAY_TOKEN"'
246+
assert_auth_rejected \
247+
"gateway service" \
248+
"$PROJECT_DIR/gateway-wrong-token.json" \
249+
"$PROJECT_DIR/gateway-wrong-token.err" \
250+
"${COMPOSE[@]}" exec -T openclaw-gateway \
251+
node dist/index.js gateway health --token "$WRONG_TOKEN" --json
100252
"${COMPOSE[@]}" exec -T openclaw-gateway node dist/index.js gateway health --token "$TOKEN" --json >"$PROJECT_DIR/gateway-health.json"
101253
assert_gateway_health_json "gateway service" "$PROJECT_DIR/gateway-health.json"
254+
assert_auth_rejected \
255+
"CLI sidecar" \
256+
"$PROJECT_DIR/cli-wrong-token.json" \
257+
"$PROJECT_DIR/cli-wrong-token.err" \
258+
"${COMPOSE[@]}" run -T --rm --no-deps \
259+
openclaw-cli gateway health --token "$WRONG_TOKEN" --json
102260
"${COMPOSE[@]}" run -T --no-deps --name "$CLI_NAME" openclaw-cli gateway health --token "$TOKEN" --json >"$PROJECT_DIR/cli-health.json"
103261
assert_gateway_health_json "CLI sidecar" "$PROJECT_DIR/cli-health.json"
262+
263+
echo "Forcing the configured Docker healthcheck to fail..."
264+
docker exec --user 0:0 "$GATEWAY_ID" \
265+
sh -c 'test -f /app/dist/docker-healthcheck.js && mv /app/dist/docker-healthcheck.js /app/dist/docker-healthcheck.js.c3-disabled'
266+
wait_for_gateway_health unhealthy 30
267+
docker inspect --format '{{json .State.Health}}' "$GATEWAY_ID" >"$PROJECT_DIR/health-unhealthy.json"
268+
assert_health_state "forced unhealthy state" unhealthy "$PROJECT_DIR/health-unhealthy.json"
269+
docker exec --user 0:0 "$GATEWAY_ID" \
270+
mv /app/dist/docker-healthcheck.js.c3-disabled /app/dist/docker-healthcheck.js
271+
wait_for_gateway_health healthy 60
272+
docker inspect --format '{{json .State.Health}}' "$GATEWAY_ID" >"$PROJECT_DIR/health-recovered.json"
273+
assert_health_state "recovered healthy state" healthy "$PROJECT_DIR/health-recovered.json"
274+
assert_probe_endpoints "recovered probes" "$PROJECT_DIR/probes-recovered.json"
275+
276+
"${COMPOSE[@]}" logs --no-color openclaw-gateway >"$PROJECT_DIR/gateway-compose.log"
277+
if [ ! -s "$PROJECT_DIR/gateway-compose.log" ]; then
278+
echo "Compose gateway logs were empty" >&2
279+
exit 1
280+
fi
281+
echo "Compose gateway log tail:"
282+
tail -n 40 "$PROJECT_DIR/gateway-compose.log"
283+
104284
GATEWAY_VERSION="$("${COMPOSE[@]}" exec -T openclaw-gateway node -p "require('./package.json').version")"
105285

106286
node --import tsx "$ROOT_DIR/scripts/e2e/lib/docker-artifact-proof/write-identities.ts" \
@@ -112,8 +292,21 @@ node --import tsx "$ROOT_DIR/scripts/e2e/lib/docker-artifact-proof/write-identit
112292
--container "cli=$CLI_NAME" \
113293
--detail "gateway:openclawVersion=$GATEWAY_VERSION" \
114294
--detail "gateway:health=healthy" \
295+
--detail "gateway:dockerfileHealthcheckDefinition=passed" \
296+
--detail "gateway:composeHealthcheckResolved=passed" \
297+
--detail "gateway:runtimeHealthcheckEffective=passed" \
298+
--detail "gateway:healthz=live" \
299+
--detail "gateway:readyz=ready" \
300+
--detail "gateway:wrongTokenRejected=passed" \
301+
--detail "gateway:correctTokenAccepted=passed" \
302+
--detail "gateway:dockerUnhealthy=observed" \
303+
--detail "gateway:dockerRecovery=passed" \
304+
--detail "gateway:composeLogs=observed" \
305+
--detail "gateway:healthStateDiagnostics=observed" \
115306
--detail "gateway:documentedHealthCommand=passed" \
116307
--detail "gateway:healthJsonEnvelope=passed" \
308+
--detail "cli:wrongTokenRejected=passed" \
309+
--detail "cli:correctTokenAccepted=passed" \
117310
--detail "cli:healthJsonEnvelope=passed"
118311

119312
echo "Docker Compose setup proof passed."

0 commit comments

Comments
 (0)