test(interactive): replace blind y-loops with accept_until helper
Add an accept_until helper that only sends "y" when a new [Y/n] prompt appears in the tmux pane, replacing the fixed-count blind send loops that could race ahead of prompts or send stray input. Resilient to changes in the number of apply-phase prompts. Relates to #51 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -100,6 +100,33 @@ assert_contains() {
|
||||
return 1
|
||||
}
|
||||
|
||||
# Accept all [Y/n] prompts until a stop pattern appears in the pane.
|
||||
# Usage: accept_until "Signing key options" [max_iterations]
|
||||
accept_until() {
|
||||
local stop_pattern="$1"
|
||||
local max_iters="${2:-80}"
|
||||
local pane_content last_content=""
|
||||
local i
|
||||
for ((i = 0; i < max_iters; i++)); do
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "$stop_pattern"; then
|
||||
return 0
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
return 0
|
||||
fi
|
||||
# Only send "y" when a new prompt has appeared (pane changed and shows [Y/n])
|
||||
if [ "$pane_content" != "$last_content" ] \
|
||||
&& printf '%s' "$pane_content" | grep -qE '\[Y/n\]|\[y/N\]'; then
|
||||
send "y" Enter
|
||||
last_content="$pane_content"
|
||||
sleep 0.3
|
||||
else
|
||||
sleep 0.2
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
pass() {
|
||||
printf '%b PASS:%b %s\n' "$C_GREEN" "$C_RESET" "$1" >&2
|
||||
}
|
||||
|
||||
@@ -26,21 +26,8 @@ main() {
|
||||
wait_for "Proceed with hardening"
|
||||
send "y" Enter
|
||||
|
||||
# Accept each setting prompt by sending "y" + Enter repeatedly.
|
||||
# v0.2.0 adds more prompts (pre-commit hook, gitignore, core.symlinks),
|
||||
# so we need enough iterations to get through all of them.
|
||||
local pane_content
|
||||
for _ in $(seq 1 50); do
|
||||
sleep 0.3
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "Signing key options"; then
|
||||
break
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
break
|
||||
fi
|
||||
send "y" Enter
|
||||
done
|
||||
# Accept all [Y/n] prompts until signing wizard
|
||||
accept_until "Signing key options"
|
||||
|
||||
# Signing wizard — skip
|
||||
wait_for "Signing key options" 20
|
||||
|
||||
@@ -36,20 +36,8 @@ main() {
|
||||
wait_for "Proceed with hardening"
|
||||
send "y" Enter
|
||||
|
||||
# Accept settings until identity guard prompt appears
|
||||
local pane_content
|
||||
for _ in $(seq 1 50); do
|
||||
sleep 0.3
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "Enter your name"; then
|
||||
break
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
fail "Identity guard did not trigger — reached completion"
|
||||
exit 1
|
||||
fi
|
||||
send "y" Enter
|
||||
done
|
||||
# Accept all [Y/n] prompts until identity guard
|
||||
accept_until "Enter your name"
|
||||
|
||||
# Identity guard: enter name
|
||||
wait_for "Enter your name" 15
|
||||
@@ -59,18 +47,8 @@ main() {
|
||||
wait_for "Enter your email" 10
|
||||
send "test@example.com" Enter
|
||||
|
||||
# Continue accepting remaining prompts
|
||||
for _ in $(seq 1 50); do
|
||||
sleep 0.3
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "Signing key options"; then
|
||||
break
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
break
|
||||
fi
|
||||
send "y" Enter
|
||||
done
|
||||
# Accept remaining [Y/n] prompts until signing wizard
|
||||
accept_until "Signing key options"
|
||||
|
||||
# Skip signing
|
||||
if tmux capture-pane -t "$TMUX_SESSION" -p | grep -qF "Signing key options"; then
|
||||
|
||||
@@ -34,19 +34,8 @@ main() {
|
||||
wait_for "Proceed with hardening"
|
||||
send "y" Enter
|
||||
|
||||
# Accept settings until signing wizard (v0.2.0 adds more prompts)
|
||||
local pane_content
|
||||
for _ in $(seq 1 50); do
|
||||
sleep 0.3
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "Signing key options"; then
|
||||
break
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
break
|
||||
fi
|
||||
send "y" Enter
|
||||
done
|
||||
# Accept all [Y/n] prompts until signing wizard
|
||||
accept_until "Signing key options"
|
||||
|
||||
# Signing wizard — option 1: generate ed25519
|
||||
wait_for "Signing key options" 20
|
||||
|
||||
@@ -35,19 +35,8 @@ main() {
|
||||
wait_for "Proceed with hardening"
|
||||
send "y" Enter
|
||||
|
||||
# Accept settings until signing wizard (v0.2.0 adds more prompts)
|
||||
local pane_content
|
||||
for _ in $(seq 1 50); do
|
||||
sleep 0.3
|
||||
pane_content="$(tmux capture-pane -t "$TMUX_SESSION" -p 2>/dev/null || true)"
|
||||
if printf '%s' "$pane_content" | grep -qF "Signing key options"; then
|
||||
break
|
||||
fi
|
||||
if printf '%s' "$pane_content" | grep -qF "Hardening complete"; then
|
||||
break
|
||||
fi
|
||||
send "y" Enter
|
||||
done
|
||||
# Accept all [Y/n] prompts until signing wizard
|
||||
accept_until "Signing key options"
|
||||
|
||||
# Signing wizard — skip
|
||||
wait_for "Signing key options" 20
|
||||
|
||||
Reference in New Issue
Block a user