Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,33 @@ print_done() {
printf " ${C_BOLD}GitHub${C_RESET} ${C_DIM}https://github.com/nvidia/nemoclaw${C_RESET}\n"
printf " ${C_BOLD}Docs${C_RESET} ${C_DIM}https://docs.nvidia.com/nemoclaw/latest/${C_RESET}\n"
printf "\n"
maybe_offer_shell_reload
}

# Offer to replace the current process with a fresh login shell so the
# just-installed Node (and any other PATH additions) is immediately active.
# Only prompts on a real TTY and when the user didn't pass --non-interactive
# — preserves scriptability (e.g. `curl | bash && nemoclaw onboard` chains
# keep working because the prompt is skipped in piped/non-interactive mode).
# On accept: execs "$SHELL" -l, replacing this script process. On decline:
# noop — the warning already printed the manual activation command.
maybe_offer_shell_reload() {
[[ -z "$NODE_UPGRADED_VERSION" ]] && return 0
[[ "${NON_INTERACTIVE:-}" == "1" ]] && return 0
# Both stdin AND stdout must be a TTY — otherwise (e.g. `install.sh > log.txt`)
# the prompt writes to the redirected file while `read` blocks on invisible
# input, confusing the user.
[[ -t 0 && -t 1 ]] || return 0
local answer
printf " ${C_BOLD}Reload your shell now to activate Node %s?${C_RESET} [Y/n] " "$NODE_UPGRADED_VERSION"
read -r answer || return 0
case "${answer,,}" in
"" | y | yes)
info "Reloading shell — Node ${NODE_UPGRADED_VERSION} will be active in the next prompt…"
exec "${SHELL:-/bin/bash}" -l
;;
*) ;;
esac
}

usage() {
Expand Down Expand Up @@ -443,6 +470,11 @@ NEMOCLAW_RECOVERY_PROFILE=""
NEMOCLAW_RECOVERY_EXPORT_DIR=""
NEMOCLAW_SOURCE_ROOT="$(resolve_repo_root)"
ONBOARD_RAN=false
# Set to the installed Node version string when install_nodejs runs the nvm
# upgrade path. Lets print_done offer to spawn a fresh shell so the user
# lands in a session with the new Node on PATH. Empty string = no upgrade
# happened (Node was already acceptable).
NODE_UPGRADED_VERSION=""

# Compare two semver strings (major.minor.patch). Returns 0 if $1 >= $2.
# Rejects prerelease suffixes (e.g. "22.16.0-rc.1") to avoid arithmetic errors.
Expand Down Expand Up @@ -742,7 +774,16 @@ install_nodejs() {
ensure_nvm_loaded --force
nvm use 22 --silent
nvm alias default 22 2>/dev/null || true
info "Node.js installed: $(node --version)"
local installed_version
installed_version="$(node --version)"
info "Node.js installed via nvm: ${installed_version} (default alias)"
# Flag so print_done can offer an opt-in shell reload at the end. The
# installer runs in a subshell; the user's parent shell still resolves
# `node` via the pre-install PATH until it's reloaded. See issue #2178.
NODE_UPGRADED_VERSION="$installed_version"
warn "Your current shell may still resolve \`node\` to an older version until you reload it."
printf " To activate ${installed_version} in this shell:\n"
printf " exec \"\$SHELL\" -l # (or) nvm use 22\n"
}

# ---------------------------------------------------------------------------
Expand Down
34 changes: 34 additions & 0 deletions test/install-preflight.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,40 @@ fi`,
expect(gitCalls).not.toMatch(/clone/);
expect(gitCalls).not.toMatch(/fetch/);
});

// Issue #2178 — when nvm installs a new Node, the user's parent shell still
// resolves `node` to the old version until the shell is reloaded. The
// installer's upgrade path must surface this loudly and adjacent to the
// "Node.js installed" line, not only in the generic bottom-of-output Next
// block where it's easy to miss.
it("install_nodejs upgrade path emits a Node-specific shell-reload hint", () => {
const script = fs.readFileSync(INSTALLER_PAYLOAD, "utf-8");
const installNodejs = script.match(/install_nodejs\(\)\s*\{[\s\S]*?\n\}/);
expect(installNodejs).not.toBeNull();
const body = installNodejs![0];
// Anchor to the actual warn/printf calls (not the comment) so the test
// fails if the executable statements are removed.
expect(body).toMatch(/\n\s*warn\s+"Your current shell may still resolve/);
// The printf arg is double-quoted so the SHELL reference is backslash-escaped.
expect(body).toMatch(/\n\s*printf\s+"[^"]*exec \\"\\\$SHELL\\" -l/);
});

// Issue #2178 — option 2: let the user auto-activate by spawning a fresh
// login shell. Gates must be respected so scripted / piped invocations
// (e.g. `curl | bash && nemoclaw onboard`) are not broken.
it("maybe_offer_shell_reload skips the prompt in non-interactive mode", () => {
const script = fs.readFileSync(INSTALLER_PAYLOAD, "utf-8");
const helper = script.match(/maybe_offer_shell_reload\(\)\s*\{[\s\S]*?\n\}/);
expect(helper).not.toBeNull();
const body = helper![0];
// Must only prompt when: upgrade actually happened, NON_INTERACTIVE is
// not set, AND stdin is a real TTY. And the accept path must exec $SHELL.
expect(body).toMatch(/NODE_UPGRADED_VERSION/);
expect(body).toMatch(/NON_INTERACTIVE/);
// Both stdin and stdout must be a TTY — guards redirected-stdout case.
expect(body).toMatch(/\[\[ -t 0 && -t 1 \]\]/);
expect(body).toMatch(/exec "\$\{SHELL:-\/bin\/bash\}" -l/);
});
});

// ---------------------------------------------------------------------------
Expand Down
Loading