Skip to content

Commit 2ff54ce

Browse files
committed
test(e2e): exact-match sandbox names and ephemeral install sandbox
Replace `grep -Fqw` existence checks with an awk first-field match helper (`sandbox_exists`) so hyphenated prefixes can no longer false-positive (e.g. `test-dash` matching `test-dash-old`). Also set an ephemeral `NEMOCLAW_SANDBOX_NAME=test-dash-install-$$` before running install.sh so cleanup can never destroy a user's real `my-assistant` sandbox when this script is run locally. Addresses CodeRabbit review feedback on PR #2123. Signed-off-by: Evan Takahashi <evan10takahashi@gmail.com>
1 parent bbb40e1 commit 2ff54ce

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

test/e2e/test-dashboard-reachability.sh

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,22 @@ onboard_sandbox() {
7878
return 1
7979
fi
8080

81-
if ! nemoclaw list 2>/dev/null | grep -Fqw -- "$name"; then
81+
if ! sandbox_exists "$name"; then
8282
log " [onboard_sandbox] Sandbox '$name' not found in nemoclaw list after onboard"
8383
return 1
8484
fi
8585
return 0
8686
}
8787

88+
# ── Exact sandbox-name match helper ──────────────────────────────────────────
89+
# `nemoclaw list` prints one indented sandbox name per line (optionally followed
90+
# by " *" for the default). `grep -Fw` word-boundary matches still accept
91+
# hyphenated prefixes (e.g. "test-dash" matches "test-dash-old"), so we match
92+
# the first whitespace-delimited field exactly instead.
93+
sandbox_exists() {
94+
nemoclaw list 2>/dev/null | awk -v n="$1" '$1==n { found=1; exit } END { exit !found }'
95+
}
96+
8897
# ── Resolve repo root ────────────────────────────────────────────────────────
8998
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)"
9099
if [ -f "$SCRIPT_DIR/../../install.sh" ]; then
@@ -98,6 +107,11 @@ fi
98107

99108
# ── Install NemoClaw if not present ──────────────────────────────────────────
100109
install_nemoclaw() {
110+
# Use an ephemeral, test-only install-sandbox name so cleanup can never
111+
# destroy a user's real 'my-assistant' sandbox when this script is run
112+
# locally outside CI.
113+
local install_sandbox="test-dash-install-$$"
114+
101115
if command -v nemoclaw &>/dev/null; then
102116
log "nemoclaw already installed: $(nemoclaw --version 2>/dev/null || echo 'unknown')"
103117
return 0
@@ -106,7 +120,8 @@ install_nemoclaw() {
106120
log "=== Installing NemoClaw via install.sh ==="
107121

108122
local install_exit=0
109-
bash "$REPO_ROOT/install.sh" --non-interactive --yes-i-accept-third-party-software \
123+
NEMOCLAW_SANDBOX_NAME="$install_sandbox" \
124+
bash "$REPO_ROOT/install.sh" --non-interactive --yes-i-accept-third-party-software \
110125
2>&1 | tee -a "$LOG_FILE" || install_exit=$?
111126

112127
if [ -f "$HOME/.bashrc" ]; then
@@ -134,9 +149,7 @@ install_nemoclaw() {
134149

135150
log "nemoclaw installed: $(nemoclaw --version 2>/dev/null || echo 'unknown')"
136151

137-
local install_sandbox
138-
install_sandbox="${NEMOCLAW_SANDBOX_NAME:-my-assistant}"
139-
if nemoclaw list 2>/dev/null | grep -Fqw -- "$install_sandbox"; then
152+
if sandbox_exists "$install_sandbox"; then
140153
log "Destroying install sandbox '$install_sandbox'..."
141154
nemoclaw "$install_sandbox" destroy --yes 2>/dev/null || true
142155
fi
@@ -167,7 +180,7 @@ preflight() {
167180
rm -f "$HOME/.nemoclaw/onboard.lock"
168181
fi
169182

170-
if nemoclaw list 2>/dev/null | grep -Fqw -- "$SANDBOX"; then
183+
if sandbox_exists "$SANDBOX"; then
171184
log "Cleaning up leftover sandbox: $SANDBOX"
172185
nemoclaw "$SANDBOX" destroy --yes 2>/dev/null || true
173186
fi
@@ -284,7 +297,7 @@ teardown() {
284297
log ""
285298
log "=== Teardown ==="
286299
openshell forward stop "$DASHBOARD_PORT" 2>/dev/null || true
287-
if nemoclaw list 2>/dev/null | grep -Fqw -- "$SANDBOX"; then
300+
if sandbox_exists "$SANDBOX"; then
288301
log "Destroying sandbox '$SANDBOX'..."
289302
nemoclaw "$SANDBOX" destroy --yes 2>/dev/null || true
290303
fi

0 commit comments

Comments
 (0)