Skip to content

Commit 14d2cf0

Browse files
authored
test(docker): retain self-upgrade failure diagnostics (#133505)
* test(docker): retain self-upgrade failure diagnostics * style(test): use set membership for diagnostic RPC labels
1 parent 21b2289 commit 14d2cf0

6 files changed

Lines changed: 304 additions & 23 deletions

File tree

‎scripts/e2e/lib/upgrade-survivor/diagnostics.mjs‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,34 @@ const logNames = [
3232
"systemctl-shim-gateway.log.bootstrap.log",
3333
"gateway-restart.log",
3434
];
35+
// Candidate observations select one declared RPC pair, never an arbitrary private path.
36+
const rpcLogNames = new Set([
37+
"channels-status-before",
38+
"wizard-start",
39+
"wizard-status",
40+
"wizard-next",
41+
"wizard-duplicate-start",
42+
"wizard-cancel",
43+
"wizard-cancelled-status",
44+
"wizard-replacement-start",
45+
"wizard-replacement-cancel",
46+
"wizard-replacement-status",
47+
"update-rpc",
48+
"update-status.candidate",
49+
"target-wizard-status-start",
50+
"target-wizard-status",
51+
"target-wizard-status-retained",
52+
"target-wizard-status-cancel",
53+
"target-wizard-status-purged",
54+
"target-wizard-active-start",
55+
"target-wizard-next",
56+
"target-wizard-duplicate-start",
57+
"target-wizard-cancel",
58+
"target-wizard-replacement-start",
59+
"target-wizard-replacement-cancel",
60+
"target-wizard-purged-status",
61+
"channels-status",
62+
]);
3563
const reasons = [
3664
"missing or unsafe file",
3765
"input exceeds cap; omitted whole",
@@ -527,6 +555,20 @@ async function capture(artifactRoot, phase, exitStatus, signal = "", observation
527555
? readOwned(process.env.OPENCLAW_STATE_DIR, "logs/gateway-restart.log", name)
528556
: readOwned(artifactRoot, name, name);
529557
}
558+
const rpcName = readOwned(artifactRoot, "diagnostics/last-rpc", "last RPC")?.trim();
559+
if (rpcLogNames.has(rpcName)) {
560+
report.lastRpc = {
561+
name: rpcName,
562+
stdout: readOwned(artifactRoot, `${rpcName}.json`, "RPC stdout"),
563+
stderr: readOwned(
564+
artifactRoot,
565+
`${rpcName === "update-status.candidate" ? "update-status" : rpcName}.err`,
566+
"RPC stderr",
567+
),
568+
};
569+
} else if (rpcName) {
570+
omissions["last RPC"] = reasons[3];
571+
}
530572
const stateRoot = process.env.OPENCLAW_STATE_DIR;
531573
report.pluginIdentity = await pluginIdentities(stateRoot, artifactRoot);
532574
report.postCore = {
@@ -617,6 +659,9 @@ export function publishDiagnostics(artifactRoot, destination, redactSensitiveTex
617659
// arbitrary omission text. Redact every permitted free-text field on the host.
618660
for (const label of [
619661
...logNames,
662+
"last RPC",
663+
"RPC stdout",
664+
"RPC stderr",
620665
"config",
621666
"service unit",
622667
"service environment",
@@ -649,6 +694,17 @@ export function publishDiagnostics(artifactRoot, destination, redactSensitiveTex
649694
for (const name of logNames) {
650695
report.logs[name] = sanitize(snapshot.logs?.[name], name);
651696
}
697+
if (snapshot.lastRpc !== undefined) {
698+
if (rpcLogNames.has(snapshot.lastRpc?.name)) {
699+
report.lastRpc = {
700+
name: snapshot.lastRpc.name,
701+
stdout: sanitize(snapshot.lastRpc.stdout, "RPC stdout"),
702+
stderr: sanitize(snapshot.lastRpc.stderr, "RPC stderr"),
703+
};
704+
} else {
705+
omissions["last RPC"] = reasons[3];
706+
}
707+
}
652708
for (const field of ["ExecStart", "WorkingDirectory", "supervisorWorkingDirectory"]) {
653709
report.service[field] = sanitize(snapshot.service?.[field], field);
654710
}

‎scripts/e2e/lib/upgrade-survivor/update-run-package-self-upgrade.sh‎

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ export OPENCLAW_UPGRADE_SURVIVOR_SYSTEMCTL_SHIM_DAEMON_LOG="$SYSTEMCTL_SHIM_DAEM
116116
gateway_pid=""
117117
qa_bus_pid=""
118118
supervisor_monitor_pid=""
119+
CURRENT_PHASE=prepare-runtime
120+
FAILURE_SIGNAL=""
121+
run_completed=0
119122

120123
mkdir -p \
121124
"$ARTIFACT_DIR" \
125+
"$ARTIFACT_DIR/diagnostics" \
122126
"$HOME" \
123127
"$OPENCLAW_STATE_DIR" \
124128
"$OPENCLAW_TEST_WORKSPACE_DIR" \
@@ -149,7 +153,32 @@ cleanup() {
149153
wait "$qa_bus_pid" >/dev/null 2>&1 || true
150154
fi
151155
}
152-
trap cleanup EXIT
156+
on_exit() {
157+
local exit_status="$1"
158+
# Command substitutions may inherit EXIT; only the scenario owner may capture or stop children.
159+
[ "$BASH_SUBSHELL" -eq 0 ] || return "$exit_status"
160+
trap - EXIT HUP INT TERM
161+
set +e
162+
if [ "$exit_status" -eq 0 ] && [ "$run_completed" != 1 ]; then
163+
exit_status=1
164+
fi
165+
if [ "$exit_status" -ne 0 ]; then
166+
node scripts/e2e/lib/upgrade-survivor/diagnostics.mjs capture \
167+
"$ARTIFACT_DIR" "$CURRENT_PHASE" "$exit_status" "$FAILURE_SIGNAL" ||
168+
echo "Self-upgrade diagnostics missing; preserving original failure." >&2
169+
fi
170+
cleanup
171+
exit "$exit_status"
172+
}
173+
on_signal() {
174+
FAILURE_SIGNAL="$1"
175+
trap - HUP INT TERM
176+
exit "$2"
177+
}
178+
trap 'on_exit $?' EXIT
179+
trap 'on_signal SIGHUP 129' HUP
180+
trap 'on_signal SIGINT 130' INT
181+
trap 'on_signal SIGTERM 143' TERM
153182

154183
package_root() {
155184
printf '%s/lib/node_modules/openclaw\n' "$npm_config_prefix"
@@ -161,6 +190,7 @@ read_installed_version() {
161190
"$(package_root)"
162191
}
163192

193+
CURRENT_PHASE=install-source
164194
echo "Installing declared source package $SOURCE_SPEC"
165195
openclaw_e2e_maybe_timeout 600s \
166196
npm install -g --prefix "$npm_config_prefix" "$SOURCE_SPEC" --no-fund --no-audit \
@@ -176,6 +206,7 @@ if ! openclaw --version | grep -Fq "$SOURCE_VERSION"; then
176206
exit 1
177207
fi
178208

209+
CURRENT_PHASE=resolve-target
179210
target_version="$(
180211
npm view "openclaw@$TARGET_TAG" version --json --prefer-online --cache "$npm_config_cache" |
181212
node -e '
@@ -200,6 +231,7 @@ TARGET_VERSION="$target_version" TARGET_TAG="$TARGET_TAG" node -e '
200231
);
201232
' "$TARGET_RESOLUTION_JSON"
202233

234+
CURRENT_PHASE=install-plugin
203235
qa_plugin_source="/tmp/openclaw-update-run-build/dist/extensions/qa-channel"
204236
qa_plugin_dir="$qa_plugin_source"
205237
if [ ! -f "$qa_plugin_source/openclaw.plugin.json" ] || [ ! -f "$qa_plugin_source/index.js" ]; then
@@ -258,6 +290,7 @@ node -e '
258290
fs.copyFileSync(indexPath, process.env.SOURCE_PLUGIN_INDEX_OUT);
259291
'
260292

293+
CURRENT_PHASE=configure-gateway
261294
node scripts/e2e/lib/upgrade-survivor/mock-server.mjs \
262295
--port "$QA_BUS_PORT" \
263296
--ready-file "$QA_BUS_READY_FILE" \
@@ -367,6 +400,10 @@ gateway_call() {
367400
local output="$3"
368401
local error_output="$4"
369402
local timeout_ms="${5:-30000}"
403+
local rpc_name="${output##*/}"
404+
# This named QA observation survives command substitutions; the host accepts only closed RPC labels.
405+
printf '%s\n' "${rpc_name%.json}" >"$ARTIFACT_DIR/diagnostics/last-rpc" ||
406+
echo "Self-upgrade last RPC diagnostic unavailable." >&2
370407
openclaw gateway call "$method" \
371408
--url "ws://127.0.0.1:$PORT" \
372409
--token "test-token" \
@@ -417,6 +454,7 @@ gateway_call channels.status '{"probe":false,"timeoutMs":2000}' \
417454
"$ARTIFACT_DIR/channels-status-before.json" \
418455
"$ARTIFACT_DIR/channels-status-before.err"
419456

457+
CURRENT_PHASE=source-wizard
420458
echo "Exercising authenticated Gateway wizard RPC lifecycle"
421459
gateway_call wizard.start '{"mode":"local"}' "$WIZARD_START_JSON" "$WIZARD_START_ERR"
422460
wizard_session_id="$(
@@ -650,6 +688,7 @@ source_gateway_pid="$gateway_pid"
650688
) >"$SUPERVISOR_MONITOR_LOG" 2>&1 &
651689
supervisor_monitor_pid="$!"
652690

691+
CURRENT_PHASE=update-run
653692
echo "Invoking authenticated Gateway RPC update.run"
654693
gateway_call update.run "$update_params" "$UPDATE_RPC_JSON" "$UPDATE_RPC_ERR" 1200000
655694
update_rpc_completed_at_ms="$(node -e 'process.stdout.write(String(Date.now()))')"
@@ -672,6 +711,7 @@ fi
672711

673712
openclaw_e2e_wait_gateway_ready "$gateway_pid" "$SYSTEMCTL_SHIM_DAEMON_LOG" 180 "$PORT"
674713

714+
CURRENT_PHASE=update-status
675715
deadline=$((SECONDS + 180))
676716
update_status_candidate="$ARTIFACT_DIR/update-status.candidate.json"
677717
while [ "$SECONDS" -lt "$deadline" ]; do
@@ -704,6 +744,7 @@ if [ ! -f "$UPDATE_STATUS_JSON" ]; then
704744
exit 1
705745
fi
706746

747+
CURRENT_PHASE=target-wizard
707748
echo "Exercising current target Gateway wizard RPC lifecycle"
708749
wait_for_target_wizard_start() {
709750
local output="$1"
@@ -986,6 +1027,7 @@ TARGET_WIZARD_STATUS_START_JSON="$TARGET_WIZARD_STATUS_START_JSON" \
9861027
);
9871028
'
9881029

1030+
CURRENT_PHASE=post-restart-probes
9891031
post_restart_observed_at_ms="$(node -e 'process.stdout.write(String(Date.now()))')"
9901032
deadline=$((SECONDS + 60))
9911033
while [ "$SECONDS" -lt "$deadline" ]; do
@@ -1026,6 +1068,7 @@ gateway_call channels.status '{"probe":false,"timeoutMs":2000}' \
10261068
"$CHANNELS_STATUS_JSON" \
10271069
"$CHANNELS_STATUS_ERR"
10281070

1071+
CURRENT_PHASE=assert-plugin-state
10291072
TARGET_PLUGIN_INDEX_OUT="$TARGET_PLUGIN_INDEX_JSON" node --input-type=module -e '
10301073
import fs from "node:fs";
10311074
import { readPluginInstallIndex } from "./scripts/e2e/lib/plugin-index-sqlite.mjs";
@@ -1120,8 +1163,10 @@ SOURCE_VERSION="$SOURCE_VERSION" \
11201163
fs.writeFileSync(process.env.SUMMARY_JSON, `${JSON.stringify(summary, null, 2)}\n`);
11211164
'
11221165

1166+
CURRENT_PHASE=assert-summary
11231167
node scripts/e2e/lib/upgrade-survivor/assertions.mjs \
11241168
assert-update-run-self-upgrade \
11251169
"$SUMMARY_JSON"
11261170

11271171
echo "Gateway update.run package self-upgrade passed source=$SOURCE_VERSION target=$target_version installed=$installed_version note=$RESTART_NOTE."
1172+
run_completed=1

‎scripts/e2e/update-run-package-self-upgrade-docker.sh‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ set -euo pipefail
55
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
66
source "$ROOT_DIR/scripts/lib/docker-e2e-image.sh"
77
source "$ROOT_DIR/scripts/lib/docker-e2e-package.sh"
8+
source "$ROOT_DIR/scripts/lib/upgrade-survivor-diagnostics.sh"
9+
HARNESS_ROOT_DIR="$ROOT_DIR"
10+
LANE_ARTIFACT_SUFFIX=update-run-package-self-upgrade
811

912
ALLOW_ENV="OPENCLAW_QA_ALLOW_UPDATE_RUN_SELF"
1013
SOURCE_VERSION="2026.4.26"
@@ -27,8 +30,21 @@ ARTIFACT_DIR="${OPENCLAW_UPDATE_RUN_SELF_UPGRADE_ARTIFACT_DIR:-$ROOT_DIR/.artifa
2730
QA_CHANNEL_FIXTURE_ROOT="$(mktemp -d "${TMPDIR:-/tmp}/openclaw-update-run-qa-channel.XXXXXX")"
2831
HISTORICAL_DIST_ARCHIVE="$QA_CHANNEL_FIXTURE_ROOT/historical-dist.tar"
2932

33+
run_completed=0
34+
diagnostics_ready=0
3035
cleanup() {
36+
local exit_status="$?"
37+
trap - EXIT
38+
set +e
39+
# A joined successful scenario, not teardown, owns the success result.
40+
if [ "$exit_status" -eq 0 ] && [ "$run_completed" != 1 ]; then
41+
exit_status=1
42+
fi
43+
if [ "$exit_status" -ne 0 ] && [ "$diagnostics_ready" = 1 ]; then
44+
publish_diagnostics || echo "Self-upgrade diagnostics missing; preserving original failure." >&2
45+
fi
3146
rm -rf "$QA_CHANNEL_FIXTURE_ROOT"
47+
exit "$exit_status"
3248
}
3349
trap cleanup EXIT
3450

@@ -110,6 +126,7 @@ prepare_qa_channel_fixture() {
110126

111127
mkdir -p "$ARTIFACT_DIR"
112128
chmod -R a+rwX "$ARTIFACT_DIR" || true
129+
prepare_diagnostics_capture
113130
prepare_qa_channel_fixture
114131

115132
docker_e2e_build_or_reuse \
@@ -171,3 +188,4 @@ fs.writeFileSync(
171188
);
172189
NODE
173190
exec bash scripts/e2e/lib/upgrade-survivor/update-run-package-self-upgrade.sh'
191+
run_completed=1

‎scripts/e2e/upgrade-survivor-docker.sh‎

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ ROOT_DIR="$(cd "${OPENCLAW_DOCKER_E2E_REPO_ROOT:-$HARNESS_ROOT_DIR}" && pwd)"
4444
DOCKER_E2E_HARNESS_ROOT_DIR="$HARNESS_ROOT_DIR"
4545
source "$HARNESS_ROOT_DIR/scripts/lib/docker-e2e-image.sh"
4646
source "$HARNESS_ROOT_DIR/scripts/lib/docker-e2e-package.sh"
47+
source "$HARNESS_ROOT_DIR/scripts/lib/upgrade-survivor-diagnostics.sh"
4748
source "$HARNESS_ROOT_DIR/scripts/lib/openclaw-e2e-instance.sh"
4849
source "$HARNESS_ROOT_DIR/scripts/e2e/lib/prepublish-plugin-registry.sh"
4950

@@ -126,28 +127,6 @@ resolve_lane_artifact_suffix() {
126127
LANE_ARTIFACT_SUFFIX="$(resolve_lane_artifact_suffix)"
127128
LANE_ARTIFACT_SUFFIX="${LANE_ARTIFACT_SUFFIX//[^A-Za-z0-9_.-]/_}"
128129
ARTIFACT_DIR="${OPENCLAW_UPGRADE_SURVIVOR_ARTIFACT_DIR:-$ROOT_DIR/.artifacts/upgrade-survivor/$LANE_ARTIFACT_SUFFIX}"
129-
prepare_diagnostics_capture() {
130-
# A previous attempt must never be published as this container's failure.
131-
if [ -L "$ARTIFACT_DIR" ] || [ -L "$ARTIFACT_DIR/diagnostics" ] ||
132-
! rm -f "$ARTIFACT_DIR/diagnostics/raw.json" "$ARTIFACT_DIR/diagnostics/post-core.json"; then
133-
echo "Upgrade survivor diagnostics missing: private capture setup failed." >&2
134-
return 0
135-
fi
136-
diagnostics_ready=1
137-
}
138-
publish_diagnostics() {
139-
# This directory is host-owned and is never mounted into the candidate.
140-
local log_root="${OPENCLAW_DOCKER_ALL_LOG_DIR:-$ROOT_DIR/.artifacts/docker-tests}"
141-
local diagnostic_dir
142-
local private_root
143-
private_root="$(cd "$ARTIFACT_DIR" && pwd)" || return
144-
mkdir -p "$log_root" || return
145-
log_root="$(cd "$log_root" && pwd)" || return
146-
diagnostic_dir="$(mktemp -d "$log_root/upgrade-survivor-$LANE_ARTIFACT_SUFFIX.XXXXXX")" || return
147-
(cd "$HARNESS_ROOT_DIR" && node --import "$HARNESS_ROOT_DIR/scripts/tsx.mjs" \
148-
"$HARNESS_ROOT_DIR/scripts/upgrade-survivor-diagnostics.mjs" \
149-
publish "$private_root" "$diagnostic_dir")
150-
}
151130
DOCKER_RUN_USER_ARGS=()
152131
OPENCLAW_PREPUBLISH_PLUGIN_REGISTRY_DOCKER_ARGS=()
153132
PROBE_ENV_ARGS=(
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Host-only snapshot preparation/publication shared by upgrade harnesses.
3+
prepare_diagnostics_capture() {
4+
# A previous attempt must never be published as this container's failure.
5+
if [ -L "$ARTIFACT_DIR" ] || [ -L "$ARTIFACT_DIR/diagnostics" ] ||
6+
! rm -f "$ARTIFACT_DIR/diagnostics/raw.json" "$ARTIFACT_DIR/diagnostics/post-core.json" "$ARTIFACT_DIR/diagnostics/last-rpc"; then
7+
echo "Upgrade survivor diagnostics missing: private capture setup failed." >&2
8+
return 0
9+
fi
10+
diagnostics_ready=1
11+
}
12+
publish_diagnostics() {
13+
# This directory is host-owned and is never mounted into the candidate.
14+
local log_root="${OPENCLAW_DOCKER_ALL_LOG_DIR:-$ROOT_DIR/.artifacts/docker-tests}"
15+
local diagnostic_dir
16+
local private_root
17+
private_root="$(cd "$ARTIFACT_DIR" && pwd)" || return
18+
mkdir -p "$log_root" || return
19+
log_root="$(cd "$log_root" && pwd)" || return
20+
diagnostic_dir="$(mktemp -d "$log_root/upgrade-survivor-$LANE_ARTIFACT_SUFFIX.XXXXXX")" || return
21+
(cd "$HARNESS_ROOT_DIR" && node --import "$HARNESS_ROOT_DIR/scripts/tsx.mjs" \
22+
"$HARNESS_ROOT_DIR/scripts/upgrade-survivor-diagnostics.mjs" \
23+
publish "$private_root" "$diagnostic_dir")
24+
}

0 commit comments

Comments
 (0)