diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ad480f6b6..3a1f6afa2a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -101,6 +101,7 @@ Docs: https://docs.openclaw.ai - Gateway/Linux: include fnm `aliases/default/bin` in generated service PATHs and let doctor accept either modern fnm aliases or the legacy `current/bin` symlink, avoiding false PATH repair prompts. Fixes #68169. Thanks @richard-scott. - Installer/Linux: run apt installs with noninteractive dpkg and needrestart settings so fresh Ubuntu 24.04 `curl | bash` installs do not hang while installing Node.js, Git, or build tools. Fixes #41146. Thanks @iht76, @alexcarv318, @cs3gallery, @firofame, and @cgdusek. - Providers/Bedrock: defer the AWS SDK import until Bedrock discovery actually runs so plugin registration and setup stay lightweight on cold start. Fixes #71690. Thanks @jarvis-ai-gregmoser. +- Installer/macOS: stop immediately when Homebrew `node@24` installation fails and avoid printing PATH advice for missing Homebrew Node installs. Fixes #70411. Thanks @1fanwang. - WhatsApp: remove ack reactions after a visible reply when `messages.removeAckAfterReply` is enabled, matching other reaction-capable channels. Fixes #26183. Thanks @MrUnforsaken. - Providers/Z.AI: map OpenClaw thinking controls to Z.AI's `thinking` payload and add opt-in preserved thinking replay via `params.preserveThinking`, so GLM 5.x can keep prior `reasoning_content` when requested. Fixes #58680. Thanks @xuanmingguo. - Channels/status: keep read-only channel lists on manifest and package metadata by default, loading setup runtime only for explicit fallback callers. Thanks @shakkernerd. diff --git a/scripts/install.sh b/scripts/install.sh index 47677bdcb62..20e6840ee91 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1353,13 +1353,16 @@ ensure_macos_default_node_active() { active_path="$(command -v node 2>/dev/null || echo "not found")" active_version="$(node -v 2>/dev/null || echo "missing")" - ui_error "Node.js v${NODE_DEFAULT_MAJOR} was installed but this shell is using ${active_version} (${active_path})" - if [[ -n "$brew_node_prefix" ]]; then - echo "Add this to your shell profile and restart shell:" - echo " export PATH=\"${brew_node_prefix}/bin:\$PATH\"" - else - echo "Ensure Homebrew node@${NODE_DEFAULT_MAJOR} is first on PATH, then rerun installer." + if [[ -z "$brew_node_prefix" || ! -x "${brew_node_prefix}/bin/node" ]]; then + ui_error "Homebrew node@${NODE_DEFAULT_MAJOR} is not installed on disk" + echo "The previous 'brew install' step appears to have failed." + echo "Re-run 'brew install node@${NODE_DEFAULT_MAJOR}' directly or rerun the installer with --verbose to see the underlying error." + return 1 fi + + ui_error "Node.js v${NODE_DEFAULT_MAJOR} was installed but this shell is using ${active_version} (${active_path})" + echo "Add this to your shell profile and restart shell:" + echo " export PATH=\"${brew_node_prefix}/bin:\$PATH\"" return 1 } @@ -1423,7 +1426,10 @@ check_node() { install_node() { if [[ "$OS" == "macos" ]]; then ui_info "Installing Node.js via Homebrew" - run_quiet_step "Installing node@${NODE_DEFAULT_MAJOR}" brew install "node@${NODE_DEFAULT_MAJOR}" + if ! run_quiet_step "Installing node@${NODE_DEFAULT_MAJOR}" brew install "node@${NODE_DEFAULT_MAJOR}"; then + echo "Re-run with --verbose or run 'brew install node@${NODE_DEFAULT_MAJOR}' directly, then rerun the installer." + exit 1 + fi brew link "node@${NODE_DEFAULT_MAJOR}" --overwrite --force 2>/dev/null || true if ! ensure_macos_default_node_active; then exit 1 diff --git a/test/scripts/install-sh.test.ts b/test/scripts/install-sh.test.ts index d3ecf9463fc..fe7efa4167f 100644 --- a/test/scripts/install-sh.test.ts +++ b/test/scripts/install-sh.test.ts @@ -1,8 +1,19 @@ +import { spawnSync } from "node:child_process"; import { readFileSync } from "node:fs"; import { describe, expect, it } from "vitest"; const SCRIPT_PATH = "scripts/install.sh"; +function runInstallShell(script: string) { + return spawnSync("bash", ["-c", script], { + encoding: "utf8", + env: { + ...process.env, + OPENCLAW_INSTALL_SH_NO_RUN: "1", + }, + }); +} + describe("install.sh apt behavior", () => { const script = readFileSync(SCRIPT_PATH, "utf8"); @@ -29,3 +40,87 @@ describe("install.sh apt behavior", () => { ); }); }); + +describe("install.sh macOS Homebrew Node behavior", () => { + const script = readFileSync(SCRIPT_PATH, "utf8"); + + it("stops when Homebrew node installation fails", () => { + expect(script).toContain( + 'if ! run_quiet_step "Installing node@${NODE_DEFAULT_MAJOR}" brew install "node@${NODE_DEFAULT_MAJOR}"; then', + ); + + const failedInstallIndex = script.indexOf( + 'if ! run_quiet_step "Installing node@${NODE_DEFAULT_MAJOR}" brew install "node@${NODE_DEFAULT_MAJOR}"; then', + ); + const brewLinkIndex = script.indexOf( + 'brew link "node@${NODE_DEFAULT_MAJOR}" --overwrite --force', + ); + expect(failedInstallIndex).toBeGreaterThanOrEqual(0); + expect(brewLinkIndex).toBeGreaterThan(failedInstallIndex); + }); + + it("aborts before brew link when Homebrew node installation fails at runtime", () => { + const result = runInstallShell(` + set -euo pipefail + source "${SCRIPT_PATH}" + OS=macos + run_quiet_step() { echo "run_quiet_step:$*"; return 1; } + brew() { echo "brew:$*"; return 0; } + ensure_macos_default_node_active() { echo "ensure-called"; return 0; } + if install_node; then + echo "install_node returned success" + else + echo "install_node returned failure" + fi + `); + + expect(result.status).toBe(1); + expect(result.stdout).toContain( + "Re-run with --verbose or run 'brew install node@24' directly, then rerun the installer.", + ); + expect(result.stdout).not.toContain("brew:link"); + expect(result.stdout).not.toContain("ensure-called"); + }); + + it("separates missing Homebrew node from PATH shadowing", () => { + const missingNodeGuardIndex = script.indexOf( + 'if [[ -z "$brew_node_prefix" || ! -x "${brew_node_prefix}/bin/node" ]]; then', + ); + const pathAdviceIndex = script.indexOf("Add this to your shell profile and restart shell:"); + + expect(missingNodeGuardIndex).toBeGreaterThanOrEqual(0); + expect(script).toContain( + 'ui_error "Homebrew node@${NODE_DEFAULT_MAJOR} is not installed on disk"', + ); + expect(script).toContain('echo " export PATH=\\"${brew_node_prefix}/bin:\\$PATH\\""'); + expect(pathAdviceIndex).toBeGreaterThan(missingNodeGuardIndex); + }); + + it("does not print PATH advice when Homebrew node is missing at runtime", () => { + const result = runInstallShell(` + set -euo pipefail + source "${SCRIPT_PATH}" + OS=macos + missing_prefix="$(mktemp -d)/node@24" + brew() { + if [[ "$1" == "--prefix" ]]; then + echo "$missing_prefix" + return 0 + fi + return 0 + } + node_major_version() { echo 16; } + if ensure_macos_default_node_active; then + echo "ensure returned success" + else + echo "ensure returned failure" + fi + `); + + expect(result.status).toBe(0); + expect(result.stdout).toContain("Homebrew node@24 is not installed on disk"); + expect(result.stdout).toContain("ensure returned failure"); + expect(result.stdout).not.toContain("Node.js v24 was installed"); + expect(result.stdout).not.toContain("Add this to your shell profile"); + }); +});