fix: [y/N] is asked on the terminal, not on stdin
confirm() returned yes whenever stdin was not a tty, so `dotup < /dev/null` in a terminal drew the picker on /dev/tty and then installed without asking. It now opens /dev/tty the way cmd_pick does and reads the answer there; it auto-approves only when no terminal exists at all. pty test plus a mutation (ISSUE-9).
This commit is contained in:
1 parent
91a1224a5e
commit
f8b17a79d3
3 files changed
+47
-2
No files matched your search
@@ -0,0 +1,11 @@
|
||||
# what: confirm() decides on `[ -t 0 ]` again instead of opening /dev/tty
|
||||
# why: `dotup < /dev/null` in a terminal picks, then installs with no [y/N] (ISSUE-9)
|
||||
# kills: stdin /dev/null with a terminal still asks [y/N]
|
||||
# run: unit
|
||||
<<<OLD
|
||||
(exec 3</dev/tty) 2>/dev/null || return 0
|
||||
printf '\n install? [y/N] ' >&2
|
||||
<<<NEW
|
||||
[ -t 0 ] || return 0
|
||||
printf '\n install? [y/N] ' >&2
|
||||
<<<END
|
||||
@@ -1299,6 +1299,36 @@ else
|
||||
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
||||
fi
|
||||
|
||||
printf '\n\033[1m[y/N] means what it says — asked on the terminal\033[0m\n'
|
||||
# ISSUE-9. confirm() asked `[ -t 0 ]`, so `dotup < /dev/null` in a terminal
|
||||
# drew the picker on /dev/tty, accepted, and installed without ever asking.
|
||||
# The pty is the terminal; stdin is /dev/null, as in the report.
|
||||
if command -v python3 >/dev/null; then
|
||||
ttyrun() { # ttyrun <script> -- dotup's default run on a pty, stdin /dev/null
|
||||
python3 ./ptydrive.py --timeout 30 --script "$1" -- \
|
||||
/usr/bin/env -i HOME="$SB" PATH="$BOXPATH" TERM=dumb LANG=C \
|
||||
TMPDIR="$SB/tmp" DOTUP_STATE="$SB/.config/dotfiles" \
|
||||
DOTUP_MANIFEST="$M" DOTUP_TEST_LOG="$LOG" \
|
||||
"$BOXPATH/sh" -c 'exec "$0" "$@" </dev/null' "$BOXPATH/sh" $D 2>&1 \
|
||||
| tr -d '\r' | plain
|
||||
}
|
||||
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
||||
pick core/ripgrep
|
||||
printf 'expect install\\? \\[y/N\\]\nsend n\nexpect nothing installed\n' > "$SB/no.expect"
|
||||
out=$(ttyrun "$SB/no.expect" || true)
|
||||
has "stdin /dev/null with a terminal still asks [y/N]" "install? [y/N]" "$out"
|
||||
is "…and n installs nothing" "0" \
|
||||
"$(grep -c 'apt-get install' "$LOG" || true)"
|
||||
newbox; sh ./seal.sh "$SB/seal" --with fzf >/dev/null; BOXPATH=$SB/seal
|
||||
pick core/ripgrep
|
||||
printf 'expect install\\? \\[y/N\\]\nsend y\n' > "$SB/yes.expect"
|
||||
out=$(ttyrun "$SB/yes.expect" || true)
|
||||
is "…and y, typed on the terminal, installs" "1" \
|
||||
"$(grep -c 'apt-get install.* ripgrep' "$LOG" || true)"
|
||||
else
|
||||
printf ' \033[33mskip\033[0m needs python3 to open a pty\n'
|
||||
fi
|
||||
|
||||
printf '\n\033[1mthe private tier — the three guards, exercised\033[0m\n'
|
||||
# Each of these is one line of dotup, and each of them survived being INVERTED:
|
||||
# the suite only ever checked that the words were in the file. What matters is
|
||||
|
||||
Reference in new issue
Block a user