@@ -116,9 +116,13 @@ export OPENCLAW_UPGRADE_SURVIVOR_SYSTEMCTL_SHIM_DAEMON_LOG="$SYSTEMCTL_SHIM_DAEM
116116gateway_pid=" "
117117qa_bus_pid=" "
118118supervisor_monitor_pid=" "
119+ CURRENT_PHASE=prepare-runtime
120+ FAILURE_SIGNAL=" "
121+ run_completed=0
119122
120123mkdir -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
154183package_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
164194echo " Installing declared source package $SOURCE_SPEC "
165195openclaw_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
177207fi
178208
209+ CURRENT_PHASE=resolve-target
179210target_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
203235qa_plugin_source=" /tmp/openclaw-update-run-build/dist/extensions/qa-channel"
204236qa_plugin_dir=" $qa_plugin_source "
205237if [ ! -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
261294node 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
420458echo " Exercising authenticated Gateway wizard RPC lifecycle"
421459gateway_call wizard.start ' {"mode":"local"}' " $WIZARD_START_JSON " " $WIZARD_START_ERR "
422460wizard_session_id=" $(
@@ -650,6 +688,7 @@ source_gateway_pid="$gateway_pid"
650688) > " $SUPERVISOR_MONITOR_LOG " 2>&1 &
651689supervisor_monitor_pid=" $! "
652690
691+ CURRENT_PHASE=update-run
653692echo " Invoking authenticated Gateway RPC update.run"
654693gateway_call update.run " $update_params " " $UPDATE_RPC_JSON " " $UPDATE_RPC_ERR " 1200000
655694update_rpc_completed_at_ms=" $( node -e ' process.stdout.write(String(Date.now()))' ) "
672711
673712openclaw_e2e_wait_gateway_ready " $gateway_pid " " $SYSTEMCTL_SHIM_DAEMON_LOG " 180 " $PORT "
674713
714+ CURRENT_PHASE=update-status
675715deadline=$(( SECONDS + 180 ))
676716update_status_candidate=" $ARTIFACT_DIR /update-status.candidate.json"
677717while [ " $SECONDS " -lt " $deadline " ]; do
@@ -704,6 +744,7 @@ if [ ! -f "$UPDATE_STATUS_JSON" ]; then
704744 exit 1
705745fi
706746
747+ CURRENT_PHASE=target-wizard
707748echo " Exercising current target Gateway wizard RPC lifecycle"
708749wait_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
9891031post_restart_observed_at_ms=" $( node -e ' process.stdout.write(String(Date.now()))' ) "
9901032deadline=$(( SECONDS + 60 ))
9911033while [ " $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
10291072TARGET_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
11231167node scripts/e2e/lib/upgrade-survivor/assertions.mjs \
11241168 assert-update-run-self-upgrade \
11251169 " $SUMMARY_JSON "
11261170
11271171echo " Gateway update.run package self-upgrade passed source=$SOURCE_VERSION target=$target_version installed=$installed_version note=$RESTART_NOTE ."
1172+ run_completed=1
0 commit comments