The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(install): report every stage outcome once
ethernet3991d4e8e62c
diff --git a/scripts/install.sh b/scripts/install.shindex 226ceac6d69..f8c51af3c28 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -17,7 +17,7 @@ export UV_NO_CONFIG=1REPO_URL="${HERMES_REPO_URL:-https://github.com/NousResearch/hermes-agent.git}"BRANCH="main"INSTALL_COMMIT=""-INSTALL_DIR="${HERMES_INSTALL_DIR:-$HOME/.hermes/hermes-agent}"+INSTALL_DIR="${HERMES_INSTALL_DIR:-}"HERMES_HOME="${HERMES_HOME:-$HOME/.hermes}"STAGE=""WANT_MANIFEST=false@@ -30,6 +30,7 @@ while [ $# -gt 0 ]; do--branch|-Branch) BRANCH="$2"; shift 2 ;;--commit|-Commit) INSTALL_COMMIT="$2"; shift 2 ;;--dir) INSTALL_DIR="$2"; shift 2 ;;+ --hermes-home|-HermesHome) HERMES_HOME="$2"; shift 2 ;;--manifest|-Manifest) WANT_MANIFEST=true; shift ;;--stage|-Stage) STAGE="$2"; shift 2 ;;--json|-Json) JSON=true; shift ;;@@ -38,6 +39,7 @@ while [ $# -gt 0 ]; do--include-desktop|-IncludeDesktop) INCLUDE_DESKTOP=true; shift ;;-h|--help)echo "Usage: install.sh [--branch NAME] [--commit SHA] [--dir PATH]"+ echo " [--hermes-home PATH]"echo " [--manifest] [--stage NAME] [--json]"echo " [--non-interactive] [--include-desktop]"exit 0 ;;@@ -45,8 +47,11 @@ while [ $# -gt 0 ]; doesacdone+INSTALL_DIR="${INSTALL_DIR:-$HERMES_HOME/hermes-agent}"+export HERMES_HOME+log() { printf "\033[1;34m[hermes]\033[0m %s\n" "$1"; }-fail() { printf "\033[1;31m[hermes]\033[0m %s\n" "$1" >&2; exit 1; }+fail() { STAGE_REASON="$1"; printf "\033[1;31m[hermes]\033[0m %s\n" "$1" >&2; exit 1; }# --- BEGIN GENERATED: bootstrap pins (scripts/gen-bootstrap-pins.py) ---# Derived from pm/lock.json. DO NOT EDIT BY HAND:@@ -171,12 +176,37 @@ check_platform() {esac}+json_string() {+ local value="$1" code char escaped+ value="${value//\\/\\\\}"+ value="${value//\"/\\\"}"+ for ((code = 1; code < 32; code++)); do+ printf -v char '\\%03o' "$code"+ printf -v char '%b' "$char"+ printf -v escaped '\\u%04x' "$code"+ value="${value//"$char"/$escaped}"+ done+ printf '"%s"' "$value"+}+json_frame() {# $1 ok, $2 stage, $3 skipped, $4 reasonif [ -n "${4:-}" ]; then- printf '{"ok":%s,"stage":"%s","skipped":%s,"reason":"%s"}\n' "$1" "$2" "$3" "$4"+ printf '{"ok":%s,"stage":%s,"skipped":%s,"reason":%s}\n' "$1" "$(json_string "$2")" "$3" "$(json_string "$4")"+ else+ printf '{"ok":%s,"stage":%s,"skipped":%s}\n' "$1" "$(json_string "$2")" "$3"+ fi+}++stage_result() {+ local code="$1" ok=false reason="${STAGE_REASON:-}"+ if [ "$code" -eq 0 ]; then+ ok=trueelse- printf '{"ok":%s,"stage":"%s","skipped":%s}\n' "$1" "$2" "$3"+ reason="${reason:-stage failed (exit $code)}"+ fi+ if [ "$JSON" = true ]; then+ json_frame "$ok" "$STAGE" "${STAGE_SKIPPED:-false}" "$reason"fi}@@ -399,7 +429,18 @@ stage_complete() {log "install complete. Run: hermes"}-run_stage() {+run_stage() (+ # Keep failure handling out of conditional calls, which disable errexit.+ set -e+ STAGE="$1"+ STAGE_REASON=""+ STAGE_SKIPPED=false+ trap 'stage_result "$?"' EXIT+ if [ "$NON_INTERACTIVE" = true ] && { [ "$STAGE" = setup ] || [ "$STAGE" = gateway ]; }; then+ STAGE_SKIPPED=true+ STAGE_REASON="needs user input"+ exit 0+ ficase "$1" inprerequisites) stage_prerequisites ;;repository) stage_repository ;;@@ -412,9 +453,9 @@ run_stage() {gateway) stage_gateway ;;desktop) stage_desktop ;;complete) stage_complete ;;- *) echo "unknown stage: $1" >&2; exit 2 ;;+ *) STAGE_REASON="unknown stage: $1"; printf '%s\n' "$STAGE_REASON" >&2; exit 2 ;;esac-}+)# Main. Guarded so the script can be SOURCED for its functions (the# installer-test harness sources it with --manifest, which must define@@ -425,26 +466,22 @@ if [ "${BASH_SOURCE[0]}" = "$0" ]; thenexit 0fi+ if [ -n "$STAGE" ] && [ "$JSON" = true ]; then+ trap 'stage_result "$?"' EXIT+ ficheck_platform+ trap - EXITif [ -n "$STAGE" ]; then- if [ "$NON_INTERACTIVE" = true ] && { [ "$STAGE" = setup ] || [ "$STAGE" = gateway ]; }; then- [ "$JSON" = true ] && json_frame true "$STAGE" true "needs user input"- exit 0- fi- if run_stage "$STAGE"; then- [ "$JSON" = true ] && json_frame true "$STAGE" false- exit 0- else- rc=$?- [ "$JSON" = true ] && json_frame false "$STAGE" false "stage failed"- exit "$rc"- fi+ run_stage "$STAGE"+ exit "$?"fi# No --stage: run the whole ladder — the same authoritative list the# manifest prints, so --include-desktop inserts desktop here too.for s in $(stage_names); dorun_stage "$s"+ rc=$?+ [ "$rc" -eq 0 ] || exit "$rc"donefidiff --git a/tests/test_install_stage_frames.py b/tests/test_install_stage_frames.pynew file mode 100644index 00000000000..ebce4f26953--- /dev/null+++ b/tests/test_install_stage_frames.py@@ -0,0 +1,96 @@+"""The real Bash stage dispatcher emits one JSON result for every exit."""+import json+import os+from pathlib import Path+import subprocess++import pytest+++ROOT = Path(__file__).resolve().parents[1]+SCRIPT = ROOT / "scripts" / "install.sh"+++def _env(tmp_path):+ return dict(os.environ, HOME=tmp_path.as_posix(),+ HERMES_HOME=(tmp_path / "home").as_posix(),+ HERMES_INSTALL_DIR=(tmp_path / "install").as_posix())+++def _frame(result):+ lines = [line for line in result.stdout.splitlines() if line.startswith("{")]+ assert len(lines) == 1, result.stdout + result.stderr+ return json.loads(lines[0])++[email protected]("case", ["explicit-failure", "write-failure", "unknown", "skipped", "success"])+def test_stage_result_matches_the_actual_exit(tmp_path, case):+ env = _env(tmp_path)+ stage = {"explicit-failure": "repository", "write-failure": "complete",+ "unknown": 'unknown"\\\n\x1fstage', "skipped": "setup", "success": "node-deps"}[case]+ env["PROBE_STAGE"] = stage+ if case == "explicit-failure":+ repo = tmp_path / "install"+ repo.mkdir()+ subprocess.run(["git", "init", "-q", "-b", "main", str(repo)], check=True, capture_output=True)+ subprocess.run(["git", "-C", str(repo), "remote", "add", "origin", str(tmp_path / "missing")],+ check=True, capture_output=True)+ elif case == "write-failure":+ (tmp_path / "install").write_text("not a directory", encoding="utf-8")+ script = '''source "$1" --manifest+JSON=true+STAGE="$PROBE_STAGE"+NON_INTERACTIVE=true+INSTALL_COMMIT=fixture+run_stage "$STAGE"+'''+ result = subprocess.run(["bash", "-c", script, "stage-test", SCRIPT.as_posix()],+ cwd=tmp_path, env=env, capture_output=True, text=True, encoding="utf-8", timeout=30)+ frame = _frame(result)+ assert frame["stage"] == stage+ assert frame["ok"] is (result.returncode == 0)+ assert frame["skipped"] is (case == "skipped")+ if case in ("skipped", "success"):+ assert result.returncode == 0, result.stderr+ else:+ assert result.returncode != 0+ assert frame["reason"]+ if case == "write-failure":+ assert "install complete" not in result.stdout++[email protected]("windows", "posix")+def test_real_single_stage_cli_reports_admission_or_execution_failure(tmp_path):+ stage = 'unknown"\\\n\x1fstage'+ env = dict(_env(tmp_path), PROBE_STAGE=stage)+ result = subprocess.run(["bash", "-c", 'exec bash "$1" --stage "$PROBE_STAGE" --json',+ "stage-test", SCRIPT.as_posix()],+ cwd=tmp_path, env=env, capture_output=True,+ text=True, encoding="utf-8", timeout=30)+ assert result.returncode != 0+ frame = _frame(result)+ assert frame["stage"] == stage and frame["ok"] is False+ assert frame["skipped"] is False and frame["reason"]++[email protected]("flag", ["--hermes-home", "-HermesHome"])+def test_manifest_accepts_the_desktop_home_argument(tmp_path, flag):+ home = tmp_path / "custom home"+ result = subprocess.run(["bash", str(SCRIPT), "--manifest", flag, str(home)],+ cwd=tmp_path, env=_env(tmp_path), capture_output=True,+ text=True, encoding="utf-8", timeout=30)+ assert result.returncode == 0, result.stderr+ manifest = json.loads(result.stdout)+ assert any(row["name"] == "path" for row in manifest["stages"])+ assert not home.exists()+ env = dict(_env(tmp_path), PROBE_FLAG=flag, PROBE_HOME=home.as_posix())+ env.pop("HERMES_INSTALL_DIR")+ script = '''source "$1" --manifest "$PROBE_FLAG" "$PROBE_HOME"+printf '%s\\n' "$INSTALL_DIR"+bash -c 'printf "%s\\n" "$HERMES_HOME"'+'''+ resolved = subprocess.run(["bash", "-c", script, "home-test", SCRIPT.as_posix()],+ cwd=tmp_path, env=env, capture_output=True,+ text=True, encoding="utf-8", timeout=30)+ assert resolved.returncode == 0, resolved.stderr+ assert resolved.stdout.splitlines() == [(home / "hermes-agent").as_posix(), home.as_posix()]