Skip to content

Commit 400754b

Browse files
authored
fix: resolve npm from embedded node runtime in update-release (#174)
1 parent 64848fb commit 400754b

2 files changed

Lines changed: 24 additions & 2 deletions

File tree

bin/AGENTS.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@ Scope: shell CLI and operational scripts under `bin/`.
1818
- Reuse shared helpers (`shell-common.sh`, `paths-common.sh`, `release-common.sh`, etc.) instead of duplicating constants or logging/error patterns.
1919
- Prefer portable shell patterns; distro-specific branches are acceptable when reliability improves.
2020
- Any security-relevant shell change must include/adjust tests.
21+
- **Never call `node`, `npm`, or other runtime binaries by bare name** in scripts that run as root or outside the agent user's shell. These binaries live in the agent's embedded runtime (`/home/baudbot_agent/opt/node/bin/`) and are not on root's PATH. Use `runtime-node.sh` helpers (e.g. `bb_resolve_runtime_node_bin`, `bb_resolve_runtime_node_bin_dir`) to resolve the full path, then invoke via a variable. Fall back to bare name only as a last resort.
22+
23+
```bash
24+
# ✅ Good: resolve then invoke
25+
source "$SCRIPT_DIR/lib/runtime-node.sh"
26+
node_bin_dir="$(bb_resolve_runtime_node_bin_dir "$agent_home")"
27+
"$node_bin_dir/npm" ci --omit=dev
28+
29+
# ❌ Bad: bare name breaks when not on PATH
30+
npm ci --omit=dev
31+
```
2132

2233
## Critical files
2334

bin/update-release.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ RELEASE_DIR=""
4646
log() { bb_log "$1"; }
4747
die() { bb_die "$1"; }
4848

49+
# shellcheck source=bin/lib/runtime-node.sh
50+
source "$SCRIPT_DIR/lib/runtime-node.sh"
4951
# shellcheck source=bin/lib/release-common.sh
5052
source "$SCRIPT_DIR/lib/release-common.sh"
5153
# shellcheck source=bin/lib/release-runtime-common.sh
@@ -219,10 +221,19 @@ install_release_bridge_dependencies() {
219221
log "installing production Slack bridge dependencies in release"
220222
rm -rf "$bridge_dir/node_modules"
221223

224+
# Resolve npm from the agent's embedded node runtime, falling back to PATH.
225+
local npm_bin="npm"
226+
local agent_home="/home/${BAUDBOT_AGENT_USER:-baudbot_agent}"
227+
local node_bin_dir=""
228+
node_bin_dir="$(bb_resolve_runtime_node_bin_dir "$agent_home" 2>/dev/null || true)"
229+
if [ -n "$node_bin_dir" ] && [ -x "$node_bin_dir/npm" ]; then
230+
npm_bin="$node_bin_dir/npm"
231+
fi
232+
222233
if [ -f "$bridge_dir/package-lock.json" ]; then
223-
(cd "$bridge_dir" && npm ci --omit=dev)
234+
(cd "$bridge_dir" && "$npm_bin" ci --omit=dev)
224235
else
225-
(cd "$bridge_dir" && npm install --omit=dev)
236+
(cd "$bridge_dir" && "$npm_bin" install --omit=dev)
226237
fi
227238
}
228239

0 commit comments

Comments
 (0)