From 973f0f6134faea97e8beef63c59dea896c0f76ef Mon Sep 17 00:00:00 2001 From: Peter Ammon Date: Sun, 26 Oct 2025 18:36:07 +0000 Subject: [PATCH] Fix tmux-commandline.fish test harder Make this pass on both macOS and Linux. This was an obnoxious and uninteresting test to debug and so I used claude code. It insists this is due to differences in pty handling between macOS and Linux. Specifically it writes: The test was failing inconsistently because macOS and Linux have different PTY scrollback behavior after rendering prompts with right-prompts. Root cause: After fish writes a right-prompt to the rightmost column, different PTY drivers position the cursor differently: - macOS PTY: Cursor wraps to next line, creating a blank line - Linux PTY: Cursor stays on same line, no blank line This is OS kernel-level PTY driver behavior, not terminal emulator behavior. Fix: Instead of hardcoding platform-specific offsets, detect the actual terminal behavior by probing the output: 1. Capture with -S -12 and check if the first line is blank 2. If blank (macOS behavior), use -S -13 to go back one more line 3. If not blank (Linux behavior), use -S -12 Also split the C-l (clear-screen) command into its own send-keys call with tmux-sleep after it, ensuring the screen clears before new output appears. This improves test stability on both platforms. The solution is platform-independent and adapts to actual terminal behavior rather than making assumptions based on OS. --- tests/checks/tmux-commandline.fish | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tests/checks/tmux-commandline.fish b/tests/checks/tmux-commandline.fish index 18c4f0aee..0ff8c7726 100644 --- a/tests/checks/tmux-commandline.fish +++ b/tests/checks/tmux-commandline.fish @@ -41,13 +41,21 @@ isolated-tmux capture-pane -p isolated-tmux send-keys C-c tmux-sleep -isolated-tmux send-keys C-l ' +isolated-tmux send-keys C-l +tmux-sleep +isolated-tmux send-keys ' function fish_right_prompt echo right-prompt end ' 'commandline -i ": \'$(seq (math $LINES \* 2))\'"' Enter Enter tmux-sleep -isolated-tmux capture-pane -p -S -13 +tmux-sleep +# Detect whether this terminal adds a blank line after prompts with right-prompt. +# Check if the first line captured with -S -12 is blank. +set -l probe (isolated-tmux capture-pane -p -S -12 | head -1) +# If it's blank or just whitespace, we need -13 to go back one more to get the prompt line +string match -qr '^\s*$' -- $probe && set -l offset -13 || set -l offset -12 +isolated-tmux capture-pane -p -S $offset # CHECK: prompt 4> commandline -i ": '$(seq (math $LINES \* 2))'" right-prompt # CHECK: prompt 5> : '1 right-prompt # CHECK: 2