diff options
Diffstat (limited to 'tests/e2e.sh')
| -rwxr-xr-x | tests/e2e.sh | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tests/e2e.sh b/tests/e2e.sh index 75dbc31..f874c15 100755 --- a/tests/e2e.sh +++ b/tests/e2e.sh @@ -226,6 +226,8 @@ t source-file "$ROOT/packaging/tmux/dingger.tmux" segment=$(t display -p -c "$CLIENT" '#{T:status-right}' | sed 's/#\[[^]]*\]//g') case "$segment" in *"×1"*"✓1"*) pass "segment shows ×1 ✓1 ($segment)";; *) fail "segment: [$segment]";; esac expect "mouse binding installed" "t list-keys -T root | grep MouseDown1StatusRight | grep -c 'dingger focus'" 1 +expect "focus hook installed: learns the terminal window" "t show-hooks -g client-focus-in | grep -c 'dingger terminal focused'" 1 +expect "with the terminal's focus reports" "t show -gv focus-events" on expect "clicking the restore offer runs restore" "t list-keys -T root | grep MouseDown1StatusRight | grep -c 'restore --report'" 1 t set -g @dingger_restore 3 segment=$(t display -p -c "$CLIENT" '#{T:status-right}' | sed 's/#\[[^]]*\]//g') @@ -673,6 +675,95 @@ expect "restore: the agent is resumed once" "grep -c -- '--session $W/sessions/g expect "with both windows" "r list-windows -t '=grp' -F '#{window_name}' | tr '\n' ' '" "agent other " expect "no real agent runs in a test pane (group)" "real_agents" "" +# --- 20. raise the right terminal window --------------------------------------- +# Two terminal windows on one session (Ghostty's `new-session -As 0` does +# that): nested clients, focused by typing a terminal's focus reports into +# their outer panes. A fake osascript plays Ghostty: it answers the focused +# terminal from a file and logs what it is told to focus. `open` is a fake +# too: tests never activate a real app. +echo "20. terminal windows" +cat >"$DIR/osascript" <<FAKE +#!/bin/sh +case "\$2" in + *"focused terminal"*) + echo query >>$DIR/ghostty-queries + # Focus moves on while Ghostty answers. + [ -f $DIR/ghostty-race ] && env -u TMUX tmux -u -L $R send-keys -t "\$(cat $DIR/ghostty-race):" -H 1b 5b 4f && sleep 0.3 + cat $DIR/ghostty-focused ;; + *"focus terminal id"*) + echo "\$2" | grep -o 'id "[^"]*"' | cut -d'"' -f2 >>$DIR/ghostty-raised + [ ! -f $DIR/ghostty-gone ] ;; +esac +FAKE +printf '#!/bin/sh\necho "$2" >> %s\n' "$DIR/opened" >"$DIR/open" +chmod +x "$DIR/osascript" "$DIR/open" +FAKE_APP="$DIR/Fake/Ghostty.app" +start_viewer +r set-environment -g DINGGER_OSASCRIPT "$DIR/osascript" +r set-environment -g DINGGER_OPEN "$DIR/open" +r set-environment -g DINGGER_TERMINAL_APP "$FAKE_APP" +r set-environment -g DINGGER_TMUX_SOCKET "$R" +r set -g focus-events on +# The snippet's own focus hook, pointed at the binary under test. +grep "client-focus-in" "$ROOT/packaging/tmux/dingger.tmux" | sed "s|\$HOME/.local/bin/dingger|$DINGGER|" >"$DIR/focus-hook.tmux" +r source-file "$DIR/focus-hook.tmux" +expect "the snippet's focus hook, on the binary under test" "r show-hooks -g client-focus-in | grep -c \"$DINGGER terminal focused\"" 1 +r new-session -d -s viewer2 -x 120 -y 40 +r send-keys -t viewer2 "exec env -u TMUX tmux -u -L $R attach -t 0" Enter +expect "two terminal windows on session 0" "r list-clients -F '#{session_name}' | sort | tr '\n' ' '" "0 0 " 50 +TTY1=$(r display -p -t viewer: '#{pane_tty}'); TTY2=$(r display -p -t viewer2: '#{pane_tty}') +r new-window -d -t '=0:' -n agent2 "$DIR/rbin/real/pi 100000" +AG=$(r display -p -t '=0:agent2' '#{pane_id}') +r new-window -d -t '=0:' -n other +r new-session -d -s elsewhere +focus_in() { echo "$2" >"$DIR/ghostty-focused"; r send-keys -t "$1:" -H 1b 5b 49; } +focus_out() { r send-keys -t "$1:" -H 1b 5b 4f; } +paired() { r show -gv "@dingger_terminal_$(basename "$1")" 2>/dev/null | cut -d' ' -f2; } +client_session() { r list-clients -F '#{client_tty} #{session_name}' | awk -v t="$1" '$1==t {print $2}'; } +focus_out viewer; focus_out viewer2 +focus_in viewer AAAA-1111 +expect "focusing a window pairs its client with Ghostty's focused terminal" "paired $TTY1" AAAA-1111 50 +focus_out viewer; focus_in viewer2 BBBB-2222 +expect "and the other window's" "paired $TTY2" BBBB-2222 50 +: >"$DIR/ghostty-raised" +renv "$DINGGER" focus --pane "$AG" +expect "a jump raises the focused window's terminal" "tail -1 $DIR/ghostty-raised" BBBB-2222 50 +expect "which shows the agent" "r display -p -c $TTY2 '#{window_name}'" agent2 +focus_out viewer2; focus_in viewer AAAA-1111; sleep 0.5; focus_out viewer +r select-window -t '=0:other' +renv "$DINGGER" focus --pane "$AG" +expect "nothing focused: the most recently focused window's" "tail -1 $DIR/ghostty-raised" AAAA-1111 50 +r switch-client -c "$TTY1" -t '=elsewhere' +renv "$DINGGER" focus --pane "$AG" +expect "a window already on the agent's session wins over a more recent one" "tail -1 $DIR/ghostty-raised" BBBB-2222 50 +expect "and the other window is not moved" "client_session $TTY1" elsewhere +echo viewer >"$DIR/ghostty-race"; : >"$DIR/ghostty-queries" +focus_in viewer CCCC-3333 +expect "Ghostty asked" "wc -l <$DIR/ghostty-queries | tr -d ' '" 1 50 +sleep 1 +expect "focus moved on while Ghostty answered: not paired" "paired $TTY1" AAAA-1111 +rm -f "$DIR/ghostty-race" +focus_in viewer2 AAAA-1111 +expect "a terminal holds one client: the newer pairing" "paired $TTY2" AAAA-1111 50 +expect "replaces the older one" "paired $TTY1" "" +focus_out viewer2 +touch "$DIR/ghostty-gone"; : >"$DIR/opened" +renv "$DINGGER" focus --pane "$AG" +expect "a terminal that is gone is forgotten" "paired $TTY2" "" 50 +expect "and the app is brought forward instead" "cat $DIR/opened" "$FAKE_APP" 50 +rm -f "$DIR/ghostty-gone"; : >"$DIR/opened"; : >"$DIR/ghostty-raised" +renv DINGGER_TERMINAL_APP="$FAKE_APP" DINGGER_OPEN="$DIR/open" "$DINGGER" focus --pane "$AG" +expect "no pairing: the app" "cat $DIR/opened" "$FAKE_APP" 50 +expect "and no terminal raised" "cat $DIR/ghostty-raised" "" +# A window on a session of a group stays on it: a pane target alone lets +# tmux pick a session of the group, the most recently used. +r new-session -d -t grp -s grp-b +r switch-client -c "$TTY1" -t '=grp-b' +r switch-client -c "$TTY2" -t '=grp'; sleep 1.1; r switch-client -c "$TTY2" -t '=0' +renv "$DINGGER" focus --client "$TTY1" --pane "$(r display -p -t '=grp:agent' '#{pane_id}')" +expect "a window on a session group stays on its own session" "client_session $TTY1" grp-b +expect "showing the agent" "r display -p -c $TTY1 '#{window_name}'" agent + # Every daemon this run started must stop with it. kill "$DAEMON_PID" "$DAEMON2_PID" 2>/dev/null expect "the test daemons stop" "ps -o pid= -p $DAEMON_PID,$DAEMON2_PID | wc -l | tr -d ' '" 0 |
