The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): never adopt a pre-release Node.js build
semao039540a03fcf4
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..ce608d3c85b--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+semao0diff --git a/hermes_constants.py b/hermes_constants.pyindex 3f28cd8d1a3..ccde302f474 100644--- a/hermes_constants.py+++ b/hermes_constants.py@@ -905,9 +905,18 @@ def _managed_node_tree_outdated(home: Path | None = None) -> bool:timeout=10,creationflags=windows_hide_flags(),)- major = int(result.stdout.decode().strip().lstrip("v").split(".")[0])+ version = result.stdout.decode().strip().lstrip("v")+ major = int(version.split(".")[0])except (OSError, subprocess.TimeoutExpired, ValueError, IndexError):return False # broken, not outdated — the runnable probe handles it+ # A pre-release tree counts as outdated however high its major:+ # nodejs.org publishes a headers tarball only for final releases, so+ # node-gyp cannot build node-pty against one. Without this, an+ # install that adopted such a tree stays broken forever — the heal+ # only fires below the target major, and a pre-release is above it.+ # Mirrors node_satisfies_build() in scripts/install.sh.+ if "-" in version:+ return Truereturn major < _HERMES_NODE_TARGET_MAJORreturn Falsediff --git a/scripts/install.sh b/scripts/install.shindex 916a06ebf28..6f717b011b9 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -890,6 +890,14 @@ check_cxx_compiler() {# replaced with the Hermes-managed Node $NODE_VERSION.node_satisfies_build() {local ver="${1#v}"+ # Pre-release builds are rejected outright, however new they are. `node-pty`+ # ships no Linux prebuild, so every install compiles it with node-gyp, which+ # fetches the headers named by `process.release.headersUrl` — a URL only+ # published for final releases. nodejs.org/dist/latest-v26.x currently+ # serves node-v26.8.0-<os>-<arch>.tar.xz whose binary reports+ # v26.8.0-alpha.0.0.0; its headers 404, and the install dies at+ # `node-gyp rebuild` with the underlying error swallowed by the+ # `node scripts/prebuild.js || node-gyp rebuild` fallback.case "$ver" in *-*) return 1 ;; esaclocal major="${ver%%.*}"local minor="${ver#*.}"; minor="${minor%%.*}"@@ -974,74 +982,38 @@ check_node() {install_node}-install_node() {- if [ "$DISTRO" = "termux" ]; then- log_info "Installing Node.js via pkg..."- if pkg install -y nodejs >/dev/null; then- local installed_ver- installed_ver=$(node --version 2>/dev/null || true)- if [ -n "$installed_ver" ]; then- log_success "Node.js $installed_ver installed via pkg"- HAS_NODE=true- else- # pkg succeeded but the binary cannot start — the same- # silent-success class the managed-download probe guards- # against (#87460). Degrade instead of claiming success.- log_error "Node.js installed via pkg failed to start:"- node --version >&2 || true- HAS_NODE=false- fi- else- log_warn "Failed to install Node.js via pkg"- HAS_NODE=false- fi- return 0- fi-- local arch=$(uname -m)- local node_arch- case "$arch" in- x86_64) node_arch="x64" ;;- aarch64|arm64) node_arch="arm64" ;;- armv7l) node_arch="armv7l" ;;- *)- log_warn "Unsupported architecture ($arch) for Node.js auto-install"- log_info "Install manually: https://nodejs.org/en/download/"- HAS_NODE=false- return 0- ;;- esac-- local node_os- case "$OS" in- linux) node_os="linux" ;;- macos) node_os="darwin" ;;- *)- log_warn "Unsupported OS for Node.js auto-install"- HAS_NODE=false- return 0- ;;- esac-- # Resolve the latest v${NODE_VERSION}.x.x tarball name from the index page- local index_url="https://nodejs.org/dist/latest-v${NODE_VERSION}.x/"+# Download and adopt one Node release line (e.g. 26) into ~/.hermes/node/.+#+# Split out of install_node() so the caller can walk a list of candidate lines.+# A line is rejected — and the caller should try an older one — when nodejs.org+# publishes no tarball for this platform, when the download or extraction+# fails, or when the tree it ships fails node_satisfies_build.+#+# Returns 0 with the tree in place, PATH exported and HAS_NODE=true; 1 when the+# line is unusable. Nothing on disk is replaced until the candidate passes, so+# a rejected line leaves any existing managed Node untouched.+install_node_line() {+ local node_line="$1"+ local node_os="$2"+ local node_arch="$3"++ # Resolve the latest v${node_line}.x.x tarball name from the index page+ local index_url="https://nodejs.org/dist/latest-v${node_line}.x/"local tarball_nametarball_name=$(curl -fsSL "$index_url" \- | grep -oE "node-v${NODE_VERSION}\.[0-9]+\.[0-9]+-${node_os}-${node_arch}\.tar\.xz" \+ | grep -oE "node-v${node_line}\.[0-9]+\.[0-9]+-${node_os}-${node_arch}\.tar\.xz" \| head -1)# Fallback to .tar.gz if .tar.xz not availableif [ -z "$tarball_name" ]; thentarball_name=$(curl -fsSL "$index_url" \- | grep -oE "node-v${NODE_VERSION}\.[0-9]+\.[0-9]+-${node_os}-${node_arch}\.tar\.gz" \+ | grep -oE "node-v${node_line}\.[0-9]+\.[0-9]+-${node_os}-${node_arch}\.tar\.gz" \| head -1)fiif [ -z "$tarball_name" ]; then- log_warn "Could not find Node.js $NODE_VERSION binary for $node_os-$node_arch"- log_info "Install manually: https://nodejs.org/en/download/"- HAS_NODE=false- return 0+ log_warn "Could not find Node.js $node_line binary for $node_os-$node_arch"+ return 1filocal download_url="${index_url}${tarball_name}"@@ -1052,8 +1024,7 @@ install_node() {if ! curl -fsSL "$download_url" -o "$tmp_dir/$tarball_name"; thenlog_warn "Download failed"rm -rf "$tmp_dir"- HAS_NODE=false- return 0+ return 1filog_info "Extracting to ~/.hermes/node/..."@@ -1069,8 +1040,20 @@ install_node() {if [ ! -d "$extracted_dir" ]; thenlog_warn "Extraction failed"rm -rf "$tmp_dir"- HAS_NODE=false- return 0+ return 1+ fi++ # Trust the binary, not the filename. A tarball named for a final release+ # can still carry a pre-release build — latest-v26.x serves+ # node-v26.8.0-<os>-<arch>.tar.xz whose `node --version` is+ # v26.8.0-alpha.0.0.0 — and adopting it leaves node-pty unbuildable for the+ # life of the install. Probe the extracted tree before it replaces anything.+ local candidate_ver+ candidate_ver=$("$extracted_dir/bin/node" --version 2>/dev/null)+ if ! node_satisfies_build "$candidate_ver"; then+ log_warn "Node.js ${candidate_ver:-unreadable} from ${index_url} cannot build native modules — trying an older release line..."+ rm -rf "$tmp_dir"+ return 1fi# Place into ~/.hermes/node/ and symlink binaries into the same bin dir@@ -1109,25 +1092,87 @@ install_node() {local installed_verif ! installed_ver=$("$HERMES_HOME/node/bin/node" --version 2>&1); then- # The downloaded Node exists but cannot start (observed: Node 26- # linux-x64 binaries link libatomic.so.1, missing on minimal- # Debian/Ubuntu). Under set -e this assignment used to abort the- # whole installer at exit 127 with the loader's explanation- # discarded by 2>/dev/null — installs died mid-sentence with no- # output at all (#87460). Degrade instead, and surface the real- # error the loader printed. Remove the broken tree and the bin- # links so later steps and retry runs start clean instead of- # resolving `node` to a binary that cannot start.+ # The adopted Node exists but cannot start (observed: missing+ # libatomic.so.1 on minimal Debian/Ubuntu, #87460). Degrade loudly,+ # surface the loader's real error, and remove the broken tree and+ # bin links so later steps and retry runs start clean. Signal the+ # caller to try an older release line rather than claiming success.log_error "Downloaded Node.js failed to start:"printf '%s\n' "$installed_ver" >&2log_info "On Debian/Ubuntu the usual fix is: sudo apt-get install -y libatomic1"rm -rf "$HERMES_HOME/node"rm -f "$node_link_dir/node" "$node_link_dir/npm" "$node_link_dir/npx"- HAS_NODE=false- return 0+ return 1filog_success "Node.js $installed_ver installed to ~/.hermes/node/"HAS_NODE=true+ return 0+}++install_node() {+ if [ "$DISTRO" = "termux" ]; then+ log_info "Installing Node.js via pkg..."+ if pkg install -y nodejs >/dev/null; then+ local installed_ver+ installed_ver=$(node --version 2>/dev/null || true)+ if [ -n "$installed_ver" ]; then+ log_success "Node.js $installed_ver installed via pkg"+ HAS_NODE=true+ else+ # pkg succeeded but the binary cannot start — the same+ # silent-success class the managed-download probe guards+ # against (#87460). Degrade instead of claiming success.+ log_error "Node.js installed via pkg failed to start:"+ node --version >&2 || true+ HAS_NODE=false+ fi+ else+ log_warn "Failed to install Node.js via pkg"+ HAS_NODE=false+ fi+ return 0+ fi++ local arch=$(uname -m)+ local node_arch+ case "$arch" in+ x86_64) node_arch="x64" ;;+ aarch64|arm64) node_arch="arm64" ;;+ armv7l) node_arch="armv7l" ;;+ *)+ log_warn "Unsupported architecture ($arch) for Node.js auto-install"+ log_info "Install manually: https://nodejs.org/en/download/"+ HAS_NODE=false+ return 0+ ;;+ esac++ local node_os+ case "$OS" in+ linux) node_os="linux" ;;+ macos) node_os="darwin" ;;+ *)+ log_warn "Unsupported OS for Node.js auto-install"+ HAS_NODE=false+ return 0+ ;;+ esac++ # Try the target line first, then the two previous even-numbered (LTS)+ # lines. Whether a line is usable cannot be known from its index page —+ # see install_node_line — and stepping down beats adopting a Node that+ # leaves every native dependency unbuildable.+ local node_line+ for node_line in "$NODE_VERSION" "$((NODE_VERSION - 2))" "$((NODE_VERSION - 4))"; do+ if install_node_line "$node_line" "$node_os" "$node_arch"; then+ return 0+ fi+ done++ log_warn "No usable Node.js release line found for $node_os-$node_arch"+ log_info "Install manually: https://nodejs.org/en/download/"+ HAS_NODE=false+ return 0}check_network_prerequisites() {diff --git a/scripts/lib/node-bootstrap.sh b/scripts/lib/node-bootstrap.shindex a9a10d3fb17..05aaf3f466d 100644--- a/scripts/lib/node-bootstrap.sh+++ b/scripts/lib/node-bootstrap.sh@@ -163,8 +163,20 @@ _nb_ensure_bundled_npm_range() {return 1}+# A pre-release Node (…-alpha/-beta/-rc/-pre/-nightly) never counts as modern,+# however high its major. nodejs.org publishes a headers tarball only for final+# releases, so node-gyp cannot build node-pty — which has no Linux prebuild —+# against one. Mirrors node_satisfies_build() in install.sh.+_nb_node_is_prerelease() {+ case "$(node --version 2>/dev/null)" in+ *-*) return 0 ;;+ *) return 1 ;;+ esac+}+_nb_have_modern_node() {command -v node >/dev/null 2>&1 || return 1+ _nb_node_is_prerelease && return 1[ "$(_nb_node_major)" -ge "$HERMES_NODE_MIN_VERSION" ]}@@ -295,6 +307,18 @@ _nb_install_bundled_node() {return 1fi+ # Trust the binary, not the filename: a tarball named for a final release+ # can still carry a pre-release build (latest-v26.x serves+ # node-v26.8.0-<os>-<arch>.tar.xz stamped v26.8.0-alpha.0.0.0). Probe it+ # before it replaces a working managed tree.+ case "$("$extracted/bin/node" --version 2>/dev/null)" in+ *-*)+ _nb_warn "Node $("$extracted/bin/node" --version 2>/dev/null) is a pre-release build — native modules cannot be built against it"+ rm -rf "$tmp"+ return 1+ ;;+ esac+mkdir -p "$HERMES_HOME"rm -rf "$HERMES_HOME/node"mv "$extracted" "$HERMES_HOME/node"diff --git a/tests/test_install_sh_node_prerelease.py b/tests/test_install_sh_node_prerelease.pynew file mode 100644index 00000000000..2b2a613ed9b--- /dev/null+++ b/tests/test_install_sh_node_prerelease.py@@ -0,0 +1,122 @@+"""The installer must never adopt a pre-release Node.js build.++`nodejs.org/dist/latest-v26.x/` serves `node-v26.8.0-<os>-<arch>.tar.xz` — a+filename that looks like a final release — whose binary reports+`v26.8.0-alpha.0.0.0`. Node publishes a headers tarball only for final+releases, so `process.release.headersUrl` 404s for that build and node-gyp+cannot compile against it.++That is fatal rather than cosmetic: `node-pty` ships prebuilds for darwin and+win32 only, so every Linux install compiles it, and the failure surfaces as an+opaque `[email protected] install: command failed` because the package's+`node scripts/prebuild.js || node-gyp rebuild` fallback swallows gyp's stderr.++These tests drive the real blocks out of `scripts/install.sh` rather than+asserting on a copy, so the guard cannot drift away from the test.+"""++import re+import subprocess+from pathlib import Path++REPO_ROOT = Path(__file__).resolve().parent.parent+INSTALL_SH = REPO_ROOT / "scripts" / "install.sh"+NODE_BOOTSTRAP = REPO_ROOT / "scripts" / "lib" / "node-bootstrap.sh"+++def _extract_function(text: str, name: str) -> str:+ match = re.search(+ rf"^{re.escape(name)}\(\) \{{\n.*?^\}}\n", text, re.M | re.S+ )+ assert match, (+ f"could not locate {name}() in scripts/install.sh — "+ "if it was renamed, update this test with it"+ )+ return match.group(0)+++def _node_satisfies_build(version: str) -> bool:+ """Run the real node_satisfies_build() against one `node --version` string."""+ script = (+ _extract_function(INSTALL_SH.read_text(encoding="utf-8"), "node_satisfies_build")+ + f'\nnode_satisfies_build "{version}"\n'+ )+ return subprocess.run(["bash", "-c", script]).returncode == 0+++def test_prerelease_node_never_satisfies_the_build_floor() -> None:+ """The exact build that breaks node-pty, plus the other pre-release tags."""+ assert not _node_satisfies_build("v26.8.0-alpha.0.0.0")+ assert not _node_satisfies_build("v24.0.0-rc.1")+ assert not _node_satisfies_build("v23.5.0-nightly20260101abcdef")+ assert not _node_satisfies_build("v22.22.0-pre")+++def test_final_releases_still_satisfy_the_build_floor() -> None:+ """The guard must not cost us any version that actually works."""+ assert _node_satisfies_build("v22.22.0") # the floor itself+ assert _node_satisfies_build("v24.20.0")+ assert _node_satisfies_build("v26.8.0") # a real 26 release, once one ships+++def test_versions_below_the_floor_are_still_rejected() -> None:+ assert not _node_satisfies_build("v22.21.0")+ assert not _node_satisfies_build("v20.19.0")+ assert not _node_satisfies_build("not-a-version")+++def test_install_node_falls_back_to_an_older_release_line(tmp_path: Path) -> None:+ """A rejected line must not end the install — the next one is tried.++ install_node_line() cannot be exercised here (it downloads), so it is+ stubbed to reject 26 the way a pre-release tarball does and accept 24.+ """+ body = _extract_function(INSTALL_SH.read_text(encoding="utf-8"), "install_node")+ script = f"""+set -e+NODE_VERSION=26+DISTRO=linux+OS=linux+uname() {{ echo x86_64; }}+log_info(){{ :; }}; log_warn(){{ :; }}; log_success(){{ :; }}+install_node_line() {{+ echo "$1" >> "$TRIED"+ [ "$1" = 24 ]+}}+{body}+install_node+"""+ tried = tmp_path / "tried"+ result = subprocess.run(+ ["bash", "-c", script],+ capture_output=True,+ text=True,+ encoding="utf-8",+ errors="replace",+ env={"PATH": "/usr/bin:/bin", "TRIED": str(tried)},+ )+ assert result.returncode == 0, result.stderr+ # 26 first, then the previous even (LTS) line; stops once one works.+ assert tried.read_text(encoding="utf-8").split() == ["26", "24"]+++def test_downloaded_tree_is_probed_before_it_replaces_anything() -> None:+ """The filename is not evidence — the extracted binary must be checked.++ Guarded as a text assertion because the surrounding block downloads; the+ fallback behaviour it feeds is covered functionally above.+ """+ text = INSTALL_SH.read_text(encoding="utf-8")+ probe = text.index('candidate_ver=$("$extracted_dir/bin/node" --version 2>/dev/null)')+ reject = text.index('if ! node_satisfies_build "$candidate_ver"; then', probe)+ # The probe has to run before the tree is moved into place, or a bad build+ # has already clobbered a working managed Node.+ assert reject < text.index('mv "$extracted_dir" "$HERMES_HOME/node"', probe)+++def test_node_bootstrap_mirrors_the_prerelease_guard() -> None:+ """The sourceable helper answers the same question and must agree."""+ text = NODE_BOOTSTRAP.read_text(encoding="utf-8")+ assert "_nb_node_is_prerelease" in text+ assert "_nb_node_is_prerelease && return 1" in text+