|
36 | 36 | chmod +x "$path" |
37 | 37 | } |
38 | 38 |
|
| 39 | +stub_ui_and_quiet_runner() { |
| 40 | + ui_info() { :; } |
| 41 | + ui_success() { :; } |
| 42 | + ui_warn() { :; } |
| 43 | + ui_error() { :; } |
| 44 | + run_quiet_step() { |
| 45 | + local _title="$1" |
| 46 | + shift |
| 47 | + "$@" |
| 48 | + } |
| 49 | +} |
| 50 | + |
39 | 51 | ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
40 | 52 | TMP_DIR="$(mktemp -d)" |
41 | 53 | trap 'rm -rf "$TMP_DIR"' EXIT |
42 | 54 |
|
| 55 | +export OPENCLAW_INSTALL_SH_NO_RUN=1 |
43 | 56 | export CLAWDBOT_INSTALL_SH_NO_RUN=1 |
44 | 57 | # shellcheck source=../public/install.sh |
45 | 58 | source "${ROOT_DIR}/public/install.sh" |
46 | 59 |
|
47 | | -echo "==> case: direct PATH" |
| 60 | +echo "==> case: resolve_openclaw_bin (direct PATH)" |
48 | 61 | ( |
49 | 62 | bin="${TMP_DIR}/case-path/bin" |
50 | | - make_exe "${bin}/clawdbot" 'echo "ok" >/dev/null' |
| 63 | + make_exe "${bin}/openclaw" 'echo "ok" >/dev/null' |
51 | 64 | export PATH="${bin}:/usr/bin:/bin" |
52 | 65 |
|
53 | | - got="$(resolve_clawdbot_bin)" |
54 | | - assert_eq "$got" "${bin}/clawdbot" "resolve_clawdbot_bin (direct PATH)" |
| 66 | + got="$(resolve_openclaw_bin)" |
| 67 | + assert_eq "$got" "${bin}/openclaw" "resolve_openclaw_bin (direct PATH)" |
55 | 68 | ) |
56 | 69 |
|
57 | | -echo "==> case: npm prefix -g" |
58 | | -( |
59 | | - root="${TMP_DIR}/case-npm-prefix-direct" |
60 | | - prefix="${root}/prefix" |
61 | | - tool_bin="${root}/tool-bin" |
62 | | - |
63 | | - make_exe "${tool_bin}/npm" "if [[ \"\$1\" == \"prefix\" && \"\$2\" == \"-g\" ]]; then echo \"${prefix}\"; exit 0; fi; exit 1" |
64 | | - make_exe "${prefix}/bin/clawdbot" 'echo "ok" >/dev/null' |
65 | | - |
66 | | - export PATH="${tool_bin}:/usr/bin:/bin" |
67 | | - |
68 | | - got="$(resolve_clawdbot_bin)" |
69 | | - assert_eq "$got" "${prefix}/bin/clawdbot" "resolve_clawdbot_bin (npm prefix -g)" |
70 | | -) |
71 | | - |
72 | | -echo "==> case: npm prefix -g fallback" |
| 70 | +echo "==> case: resolve_openclaw_bin (npm prefix -g)" |
73 | 71 | ( |
74 | 72 | root="${TMP_DIR}/case-npm-prefix" |
75 | 73 | prefix="${root}/prefix" |
76 | 74 | tool_bin="${root}/tool-bin" |
77 | 75 |
|
78 | | - make_exe "${tool_bin}/npm" "if [[ \"\$1\" == \"bin\" && \"\$2\" == \"-g\" ]]; then exit 1; fi; if [[ \"\$1\" == \"prefix\" && \"\$2\" == \"-g\" ]]; then echo \"${prefix}\"; exit 0; fi; exit 1" |
79 | | - make_exe "${prefix}/bin/clawdbot" 'echo "ok" >/dev/null' |
| 76 | + make_exe "${tool_bin}/npm" "if [[ \"\$1\" == \"prefix\" && \"\$2\" == \"-g\" ]]; then echo \"${prefix}\"; exit 0; fi; if [[ \"\$1\" == \"config\" && \"\$2\" == \"get\" && \"\$3\" == \"prefix\" ]]; then echo \"${prefix}\"; exit 0; fi; exit 1" |
| 77 | + make_exe "${prefix}/bin/openclaw" 'echo "ok" >/dev/null' |
80 | 78 |
|
81 | 79 | export PATH="${tool_bin}:/usr/bin:/bin" |
82 | 80 |
|
83 | | - got="$(resolve_clawdbot_bin)" |
84 | | - assert_eq "$got" "${prefix}/bin/clawdbot" "resolve_clawdbot_bin (npm prefix -g)" |
| 81 | + got="$(resolve_openclaw_bin)" |
| 82 | + assert_eq "$got" "${prefix}/bin/openclaw" "resolve_openclaw_bin (npm prefix -g)" |
85 | 83 | ) |
86 | 84 |
|
87 | | -echo "==> case: nodenv rehash shim creation" |
| 85 | +echo "==> case: resolve_openclaw_bin (nodenv rehash shim creation)" |
88 | 86 | ( |
89 | 87 | root="${TMP_DIR}/case-nodenv" |
90 | 88 | shim="${root}/shims" |
91 | 89 | tool_bin="${root}/tool-bin" |
92 | 90 |
|
93 | 91 | mkdir -p "${shim}" |
94 | 92 | make_exe "${tool_bin}/npm" "exit 1" |
95 | | - mkdir -p "${tool_bin}" |
96 | 93 | cat >"${tool_bin}/nodenv" <<EOF |
97 | 94 | #!/usr/bin/env bash |
98 | 95 | set -euo pipefail |
99 | 96 | if [[ "\${1:-}" == "rehash" ]]; then |
100 | | - cat >"${shim}/clawdbot" <<'SHIM' |
| 97 | + cat >"${shim}/openclaw" <<'SHIM' |
101 | 98 | #!/usr/bin/env bash |
102 | 99 | set -euo pipefail |
103 | 100 | echo ok >/dev/null |
104 | 101 | SHIM |
105 | | - chmod +x "${shim}/clawdbot" |
| 102 | + chmod +x "${shim}/openclaw" |
106 | 103 | exit 0 |
107 | 104 | fi |
108 | 105 | exit 0 |
109 | 106 | EOF |
110 | 107 | chmod +x "${tool_bin}/nodenv" |
111 | 108 |
|
112 | 109 | export PATH="${shim}:${tool_bin}:/usr/bin:/bin" |
113 | | - command -v clawdbot >/dev/null 2>&1 && fail "precondition: clawdbot unexpectedly present" |
| 110 | + command -v openclaw >/dev/null 2>&1 && fail "precondition: openclaw unexpectedly present" |
114 | 111 |
|
115 | | - got="$(resolve_clawdbot_bin)" |
116 | | - assert_eq "$got" "${shim}/clawdbot" "resolve_clawdbot_bin (nodenv rehash)" |
| 112 | + got="$(resolve_openclaw_bin)" |
| 113 | + assert_eq "$got" "${shim}/openclaw" "resolve_openclaw_bin (nodenv rehash)" |
117 | 114 | ) |
118 | 115 |
|
119 | | -echo "==> case: warn_clawdbot_not_found (smoke)" |
| 116 | +echo "==> case: warn_openclaw_not_found (smoke)" |
120 | 117 | ( |
121 | 118 | root="${TMP_DIR}/case-warn" |
122 | 119 | tool_bin="${root}/tool-bin" |
123 | | - make_exe "${tool_bin}/npm" 'if [[ "$1" == "prefix" && "$2" == "-g" ]]; then echo "/tmp/prefix"; exit 0; fi; if [[ "$1" == "bin" && "$2" == "-g" ]]; then echo "/tmp/prefix/bin"; exit 0; fi; exit 1' |
| 120 | + make_exe "${tool_bin}/npm" 'if [[ "$1" == "prefix" && "$2" == "-g" ]]; then echo "/tmp/prefix"; exit 0; fi; if [[ "$1" == "config" && "$2" == "get" && "$3" == "prefix" ]]; then echo "/tmp/prefix"; exit 0; fi; exit 1' |
| 121 | + export PATH="${tool_bin}:/usr/bin:/bin" |
| 122 | + |
| 123 | + out="$(warn_openclaw_not_found 2>&1 || true)" |
| 124 | + assert_nonempty "$out" "warn_openclaw_not_found output" |
| 125 | +) |
| 126 | + |
| 127 | +echo "==> case: ensure_pnpm (existing pnpm command)" |
| 128 | +( |
| 129 | + root="${TMP_DIR}/case-pnpm-existing" |
| 130 | + tool_bin="${root}/tool-bin" |
| 131 | + make_exe "${tool_bin}/pnpm" 'if [[ "${1:-}" == "--version" ]]; then echo "10.29.2"; exit 0; fi; exit 0' |
| 132 | + |
| 133 | + export PATH="${tool_bin}:/usr/bin:/bin" |
| 134 | + PNPM_CMD=() |
| 135 | + stub_ui_and_quiet_runner |
| 136 | + |
| 137 | + ensure_pnpm |
| 138 | + assert_eq "${PNPM_CMD[*]}" "pnpm" "ensure_pnpm (existing pnpm)" |
| 139 | +) |
| 140 | + |
| 141 | +echo "==> case: ensure_pnpm (corepack fallback when pnpm shim missing)" |
| 142 | +( |
| 143 | + root="${TMP_DIR}/case-pnpm-corepack-fallback" |
| 144 | + tool_bin="${root}/tool-bin" |
| 145 | + mkdir -p "${tool_bin}" |
| 146 | + |
| 147 | + cat >"${tool_bin}/corepack" <<'EOF' |
| 148 | +#!/usr/bin/env bash |
| 149 | +set -euo pipefail |
| 150 | +if [[ "${1:-}" == "enable" ]]; then |
| 151 | + exit 0 |
| 152 | +fi |
| 153 | +if [[ "${1:-}" == "prepare" ]]; then |
| 154 | + exit 0 |
| 155 | +fi |
| 156 | +if [[ "${1:-}" == "pnpm" && "${2:-}" == "--version" ]]; then |
| 157 | + echo "10.29.2" |
| 158 | + exit 0 |
| 159 | +fi |
| 160 | +if [[ "${1:-}" == "pnpm" ]]; then |
| 161 | + shift |
| 162 | + echo "corepack-pnpm:$*" >/dev/null |
| 163 | + exit 0 |
| 164 | +fi |
| 165 | +exit 1 |
| 166 | +EOF |
| 167 | + chmod +x "${tool_bin}/corepack" |
| 168 | + |
| 169 | + export PATH="${tool_bin}:/usr/bin:/bin" |
| 170 | + PNPM_CMD=() |
| 171 | + stub_ui_and_quiet_runner |
| 172 | + |
| 173 | + ensure_pnpm |
| 174 | + assert_eq "${PNPM_CMD[*]}" "corepack pnpm" "ensure_pnpm (corepack fallback)" |
| 175 | + out="$(run_pnpm --version)" |
| 176 | + assert_nonempty "$out" "run_pnpm --version output" |
| 177 | +) |
| 178 | + |
| 179 | +echo "==> case: ensure_pnpm (npm fallback install)" |
| 180 | +( |
| 181 | + root="${TMP_DIR}/case-pnpm-npm-fallback" |
| 182 | + tool_bin="${root}/tool-bin" |
| 183 | + mkdir -p "${tool_bin}" |
| 184 | + |
| 185 | + cat >"${tool_bin}/corepack" <<'EOF' |
| 186 | +#!/usr/bin/env bash |
| 187 | +set -euo pipefail |
| 188 | +exit 1 |
| 189 | +EOF |
| 190 | + chmod +x "${tool_bin}/corepack" |
| 191 | + |
| 192 | + cat >"${tool_bin}/npm" <<'EOF' |
| 193 | +#!/usr/bin/env bash |
| 194 | +set -euo pipefail |
| 195 | +if [[ "${1:-}" == "install" && "${2:-}" == "-g" && "${3:-}" == "pnpm@10" ]]; then |
| 196 | + cat >"${FAKE_PNPM_BIN_DIR}/pnpm" <<'PNPM' |
| 197 | +#!/usr/bin/env bash |
| 198 | +set -euo pipefail |
| 199 | +if [[ "${1:-}" == "--version" ]]; then |
| 200 | + echo "10.29.2" |
| 201 | + exit 0 |
| 202 | +fi |
| 203 | +exit 0 |
| 204 | +PNPM |
| 205 | + chmod +x "${FAKE_PNPM_BIN_DIR}/pnpm" |
| 206 | + exit 0 |
| 207 | +fi |
| 208 | +if [[ "${1:-}" == "prefix" && "${2:-}" == "-g" ]]; then |
| 209 | + echo "${FAKE_PNPM_BIN_DIR%/tool-bin}" |
| 210 | + exit 0 |
| 211 | +fi |
| 212 | +if [[ "${1:-}" == "config" && "${2:-}" == "get" && "${3:-}" == "prefix" ]]; then |
| 213 | + echo "${FAKE_PNPM_BIN_DIR%/tool-bin}" |
| 214 | + exit 0 |
| 215 | +fi |
| 216 | +exit 0 |
| 217 | +EOF |
| 218 | + chmod +x "${tool_bin}/npm" |
| 219 | + |
| 220 | + export FAKE_PNPM_BIN_DIR="${tool_bin}" |
124 | 221 | export PATH="${tool_bin}:/usr/bin:/bin" |
| 222 | + PNPM_CMD=() |
| 223 | + stub_ui_and_quiet_runner |
| 224 | + fix_npm_permissions() { :; } |
125 | 225 |
|
126 | | - out="$(warn_clawdbot_not_found 2>&1 || true)" |
127 | | - assert_nonempty "$out" "warn_clawdbot_not_found output" |
| 226 | + ensure_pnpm |
| 227 | + assert_eq "${PNPM_CMD[*]}" "pnpm" "ensure_pnpm (npm fallback)" |
128 | 228 | ) |
129 | 229 |
|
130 | 230 | echo "OK" |
0 commit comments