@@ -1022,6 +1022,7 @@ NODE
10221022 const result = runInstallShell ( `
10231023 set -euo pipefail
10241024 source "${ SCRIPT_PATH } "
1025+ env() { /usr/bin/env "$@"; }
10251026 root="$(mktemp -d)"
10261027 repo="$root/repo"
10271028 npm_root="$root/lib/node_modules"
@@ -1065,6 +1066,9 @@ EOF
10651066 install_openclaw
10661067 status=$?
10671068 set -e
1069+ if (( status == 0 )); then
1070+ commit_openclaw_bin_backup
1071+ fi
10681072 cleanup_tmpfiles
10691073 printf 'status=%s version=%s link=%s\n' "$status" "$("$bin/openclaw" --version)" "$([[ -L "$bin/openclaw" ]] && echo yes || echo no)"
10701074 ` ) ;
@@ -1078,6 +1082,86 @@ EOF
10781082 } ,
10791083 ) ;
10801084
1085+ it ( "restores the same-bin git wrapper when final npm verification fails" , ( ) => {
1086+ const result = runInstallShell ( `
1087+ set -euo pipefail
1088+ source "${ SCRIPT_PATH } "
1089+ root="$HOME/fixture"
1090+ repo="$root/repo"
1091+ npm_root="$root/lib/node_modules"
1092+ bin="$HOME/.local/bin"
1093+ launcher="$npm_root/openclaw/openclaw.mjs"
1094+ calls="$root/candidate-calls"
1095+ mkdir -p "$repo/dist" "$npm_root/openclaw" "$bin"
1096+ printf '%s\n' 'process.stdout.write("git-version\\n")' > "$repo/dist/entry.js"
1097+ cat > "$bin/openclaw" <<EOF
1098+ #!/usr/bin/env bash
1099+ set -euo pipefail
1100+ exec ${ process . execPath } $repo/dist/entry.js "\\$@"
1101+ EOF
1102+ chmod +x "$bin/openclaw"
1103+ cat > "$launcher" <<'EOF'
1104+ #!/usr/bin/env bash
1105+ set -euo pipefail
1106+ count=0
1107+ [[ ! -f "$NPM_CANDIDATE_CALLS" ]] || count="$(cat "$NPM_CANDIDATE_CALLS")"
1108+ count=$((count + 1))
1109+ printf '%s\n' "$count" > "$NPM_CANDIDATE_CALLS"
1110+ (( count < 3 )) || exit 9
1111+ printf 'npm-version\n'
1112+ EOF
1113+ chmod +x "$launcher"
1114+ fake_npm="$root/npm"
1115+ cat > "$fake_npm" <<'EOF'
1116+ #!/usr/bin/env bash
1117+ set -euo pipefail
1118+ case "\${1:-}" in
1119+ --version) printf '12.0.0\n' ;;
1120+ root) printf '%s\n' "$NPM_FAKE_ROOT" ;;
1121+ prefix) printf '%s\n' "$NPM_FAKE_PREFIX" ;;
1122+ config) printf 'null\n' ;;
1123+ *) exit 1 ;;
1124+ esac
1125+ EOF
1126+ chmod +x "$fake_npm"
1127+ npm() { "$fake_npm" "$@"; }
1128+ npm_command_path() { printf '%s\n' "$fake_npm"; }
1129+ install_openclaw_npm() { return 0; }
1130+ bootstrap_gum_temp() { :; }
1131+ print_installer_banner() { :; }
1132+ print_gum_status() { :; }
1133+ detect_os_or_die() { OS=linux; }
1134+ detect_openclaw_checkout() { return 1; }
1135+ show_install_plan() { :; }
1136+ check_existing_openclaw() { return 0; }
1137+ configure_install_stage_total() { :; }
1138+ ui_stage() { :; }
1139+ load_nvm_for_node_detection() { :; }
1140+ check_node() { return 0; }
1141+ activate_supported_node_on_path() { :; }
1142+ ensure_default_node_active_shell() { return 0; }
1143+ check_git() { return 0; }
1144+ fix_npm_permissions() { :; }
1145+ ui_info() { :; }
1146+ ui_warn() { :; }
1147+ ui_error() { :; }
1148+ ui_success() { :; }
1149+ INSTALL_METHOD=npm
1150+ OPENCLAW_VERSION="$root/candidate.tgz"
1151+ export NPM_CANDIDATE_CALLS="$calls" NPM_FAKE_ROOT="$npm_root" NPM_FAKE_PREFIX="$HOME/.local"
1152+ set +e
1153+ (set -e; main)
1154+ status=$?
1155+ set -e
1156+ version="$("$bin/openclaw" --version 2>/dev/null || printf unavailable)"
1157+ printf 'status=%s version=%s link=%s calls=%s\n' \
1158+ "$status" "$version" "$([[ -L "$bin/openclaw" ]] && echo yes || echo no)" "$(cat "$calls")"
1159+ ` ) ;
1160+
1161+ expect ( result . status ) . toBe ( 0 ) ;
1162+ expect ( result . stdout , result . stderr ) . toContain ( "status=1 version=git-version link=no calls=3" ) ;
1163+ } ) ;
1164+
10811165 it ( "restores an active shim backup when installation is interrupted" , ( ) => {
10821166 const tmp = mkdtempSync ( join ( tmpdir ( ) , "openclaw-install-shim-signal-" ) ) ;
10831167 const target = join ( tmp , "openclaw" ) ;
0 commit comments