Skip to content

Commit a638063

Browse files
authored
Merge pull request #501 from OpenCoven/test/411-approval-queue-diff
test(tui-tests): qualify queued approvals and binary/rename diffs (#411)
2 parents d9262bc + 74c6f48 commit a638063

7 files changed

Lines changed: 680 additions & 20 deletions

File tree

‎scripts/tui-tests/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ screen, and runs `run.sh`. No secrets or network access required.
7272
| `cases/05_input_editing.sh` | Prompt input | typed text echoes into the buffer, `Ctrl+U` clears it |
7373
| `cases/06_quit.sh` | Shutdown | `Ctrl+C` twice exits cleanly back to the shell |
7474
| `cases/07_paste_burst.sh` | Paste burst | a line delivered in one write still submits; interior newlines coalesce without submitting |
75+
| `cases/19_diff_large.sh` | Reviewing changes with `/diff` | In Classic and Next: scrolling a 150,000-line change, and opening and leaving a minified file's one enormous changed line, each draw within 6 s. A binary change is marked `binary` in the file list and says it has no text diff, and none of its bytes reach the terminal: its text is not drawn and its title sequence does not retitle the pane, while one sent from the shell afterwards does, so the check can see a title change. A `git mv` and a `git mv` followed by an edit each name the old and new paths, and the list marks them `renamed` instead of `+0 -0`; the edited one shows its edit and counts its lines |
7576
| `cases/22_next_resize_stream.sh` | Resize during a turn | `fake_anthropic.py` streams 150,000 lines into Next, then holds the stream open, adding a line every 0.2 s, while tmux moves through 80x24, 40x10, 200x50, 20x5, 120x40, 1x1, 2x2, 160x30, 10x3, 80x24 and 120x40; tmux must apply 200x50, 20x5, 1x1, 2x2, 10x3 and 120x40, each held past its 250 ms resize delay, and nothing saved before the release proves every size landed during the turn; the process survives, the draft stays as typed in the composer, the end of the answer is on screen, every streamed line is saved, including at least 20 sent while the stream was held, and the frame fills 40 rows at 120x40; needs `python3` |
7677
| `cases/23_classic_zero_size.sh` | Zero and tiny sizes | Classic starts at 0x0, 0x40 and 120x0 and survives 120x0 with the exit toast, 0x40, 0x0, 1x1 and 20x6, then draws a full frame at 120x40, exits 0 and restores the terminal; tmux cannot make a zero-sized window, so `zero_size_pty.py` drives a raw PTY and needs `python3` |
7778
| `cases/25_next_unicode_composer.sh` | Unicode in the Next composer | CJK, right-to-left text, a combining mark and an emoji ZWJ sequence typed through tmux stay unsent, and all but the emoji (drawn differently by tmux versions) are checked on screen; Left and Backspace act on whole CJK characters; no turn reaches the provider (`fake_anthropic.py`) before Enter, and it and the saved session get exactly the edited text. tmux sends committed characters only, so input-method preedit is not covered, and editing moves by Unicode scalar, so the ZWJ emoji and combining mark are not edited; needs `python3` |
7879
| `cases/26_classic_cancel.sh` | Cancelling a turn | In Classic (`COVEN_CODE_UI` unset) and Next, `fake_anthropic.py` drives a real turn. Escape while an approved Bash command appends a line every second: once the status no longer says cancelling, at most 3 more lines were written than at the Escape, and the file stops growing. Escape while text is still arriving (a burst of 200,000 text deltas, then a stream held open, so the turn is still running in the runtime): the status acknowledges it, the backlog still arriving does not bring the running turn back within 10 s, and the status settles to `Cancelled`; needs `python3` |
7980
| `cases/27_classic_quit_save.sh` | Quitting mid-turn | In Classic (`COVEN_CODE_UI` unset) and Next, `fake_anthropic.py` drives a real turn. Ctrl+D twice while a held stream is still sending text exits, leaves the alternate screen, restores the cursor and turns mouse reporting off, and the saved session holds the prompt and the text delivered so far. Only Next prints its report and the resume command after exiting. Ctrl+D twice while an approved `sleep 20` runs exits within 8 s and saves the prompt; needs `python3` |
81+
| `cases/28_approval_queue.sh` | A second approval key | `fake_anthropic.py` asks for two Bash calls in one response, so the second request waits behind the first panel. The first panel is decided with `y` and a second `y` follows: in the same write, at once, and 150 ms later. In both renderers a `y` already waiting when the first panel closes lands in the composer as text and decides nothing. A `y` that reaches the open next panel is ignored by Next, which takes keys other than Escape only after 400 ms of quiet, and decides that panel in Classic, which takes keys at once. Each round checks whether the second call ran (its marker file); while it is undecided, its panel must still be open and the model must have been told nothing, and a deliberate `y` then runs it. Every round ends with the model told that both calls ran. In Next, a round whose two keys took 400 ms or more to send skips the decision check, since the next panel may have armed by then; needs `python3` |
8082
| `cases/29_tool_results_kept.sh` | Tool results after a tool turn | In Classic (`COVEN_CODE_UI` unset) and Next, `fake_anthropic.py` asks for a Bash call, the user approves it, and the model answers its result. Once the turn ends, single key presses (`x`, Backspace, as typing sends them) precede a follow-up prompt, whose request, read from the full `messages` the fake logs to a file of their own, must carry the call and, in the user message right after it, the tool result answering it; needs `python3` |
8183

8284
## Configuration

‎scripts/tui-tests/cases/19_diff_large.sh‎

Lines changed: 125 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
# seconds on a large diff or on one changed line in a minified file. Both
77
# renderers show the same viewer. No network or model: /diff runs entirely inside
88
# the TUI.
9+
#
10+
# The same viewer on a binary change and two renames (#411): the binary file is
11+
# marked binary and none of its bytes reach the terminal, and each rename names
12+
# its old and new paths, with the edit of an edited one.
913

1014
register_case tc_diff_large
1115

@@ -71,8 +75,122 @@ _diff_large_journey() {
7175
TUI_BOOT_STRING="$saved_boot"
7276
}
7377

78+
# A binary file whose bytes would color and retitle a terminal if any reached
79+
# it, a pure rename, and a rename with an edit, all staged by git.
80+
_diff_kinds_repo() {
81+
local repo="$1" git_home="$2"
82+
local git_cmd=(git -C "$repo" -c user.name=suite -c user.email=suite@example.invalid)
83+
HOME="$git_home" git -C "$repo" init -q
84+
printf 'BINHEAD\000\001\033[31mRAWRED\000\n' >"$repo/blob.bin"
85+
seq 1 20 | sed 's/^/kept line /' >"$repo/old-name.txt"
86+
seq 1 20 | sed 's/^/moved line /' >"$repo/before-edit.txt"
87+
HOME="$git_home" "${git_cmd[@]}" add -A
88+
HOME="$git_home" "${git_cmd[@]}" commit -qm base
89+
printf 'BINHEAD\000\011\033]0;RAWTITLE\007\000\n' >"$repo/blob.bin"
90+
HOME="$git_home" "${git_cmd[@]}" mv old-name.txt new-name.txt
91+
HOME="$git_home" "${git_cmd[@]}" mv before-edit.txt after-edit.txt
92+
sed 's/^moved line 10$/moved line TEN/' "$repo/after-edit.txt" >"$repo/edited"
93+
mv "$repo/edited" "$repo/after-edit.txt"
94+
}
95+
96+
# The file list's entry for a file, found by the end of its path, which the
97+
# list keeps when it shortens a path. Each screen row also carries a row of the
98+
# detail pane after the divider, which can name other files, so only the cell
99+
# between the dividers that holds the collapse mark is searched. awk splits on
100+
# the divider as a byte string, so this holds in any locale.
101+
_diff_kinds_row() { # end of the path
102+
tui_capture | awk -F'│' -v name="$1" '{
103+
for (i = 1; i <= NF; i++)
104+
if (index($i, "▾ ") && index($i, name)) { print $i; exit }
105+
}'
106+
}
107+
108+
_diff_kinds_journey() {
109+
local ui="$1" boot="$2" scratch="$3" s
110+
local saved_prefix="$TUI_LAUNCH_PREFIX" saved_boot="$TUI_BOOT_STRING"
111+
TUI_LAUNCH_PREFIX="cd $(printf '%q' "$scratch/repo") && env"
112+
local var
113+
for var in ANTHROPIC_API_KEY ANTHROPIC_BASE_URL OPENAI_API_KEY COVEN_CODE_PROVIDER \
114+
COVEN_CODE_API_BASE COVEN_CODE_HOME COVEN_CODE_TEST_HOME COVEN_PARENT COVEN_DAEMON_SOCKET; do
115+
TUI_LAUNCH_PREFIX+=" -u $var"
116+
done
117+
TUI_LAUNCH_PREFIX+=" $(printf '%q ' \
118+
"HOME=$scratch/home" "COVEN_HOME=$scratch/home/.coven" "COVEN_CODE_UI=$ui")"
119+
TUI_BOOT_STRING="$boot"
120+
121+
if tui_start; then
122+
local title_before running
123+
title_before="$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_title}')"
124+
running="$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_current_command}')"
125+
tui_type "/diff"; tui_keys Enter
126+
127+
# Git sorts the files by path: the edited rename comes first.
128+
if wait_for "before-edit.txt → after-edit.txt" 20; then
129+
_pass "$ui: an edited rename names its old and new paths"
130+
else
131+
_fail "$ui: an edited rename names its old and new paths" "$(tui_capture)"
132+
fi
133+
s="$(tui_capture)"
134+
assert_contains "$s" "before-edit.txt → after-edit.txt +1 -1" "$ui: and counts its lines"
135+
assert_contains "$s" "moved line TEN" "$ui: and shows its edit"
136+
assert_matches "$(_diff_kinds_row "edit.txt")" 'renamed *$' "$ui: the list marks it renamed"
137+
138+
tui_keys Down
139+
if wait_for "Binary file — no diff available" "$_DIFF_LARGE_WAIT"; then
140+
_pass "$ui: a binary change says it has no text diff"
141+
else
142+
_fail "$ui: a binary change says it has no text diff" "$(tui_capture)"
143+
fi
144+
s="$(tui_capture)"
145+
assert_contains "$(_diff_kinds_row "blob.bin")" "binary" "$ui: the list marks the file binary"
146+
assert_absent "$s" "BINHEAD" "$ui: none of the binary's text is drawn"
147+
assert_absent "$s" "RAWRED" "$ui: none of the binary's text after an escape is drawn"
148+
assert_eq "$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_title}')" "$title_before" \
149+
"$ui: the binary's title sequence never reached the terminal"
150+
151+
tui_keys Down
152+
if wait_for "old-name.txt → new-name.txt" "$_DIFF_LARGE_WAIT"; then
153+
_pass "$ui: a pure rename names its old and new paths"
154+
else
155+
_fail "$ui: a pure rename names its old and new paths" "$(tui_capture)"
156+
fi
157+
assert_contains "$(tui_capture)" "Renamed from old-name.txt" "$ui: and says the content is unchanged"
158+
assert_matches "$(_diff_kinds_row "name.txt")" 'renamed *$' "$ui: the list marks it renamed, not +0 -0"
159+
160+
tui_keys Escape
161+
if wait_absent "blob.bin" "$_DIFF_LARGE_WAIT"; then _pass "$ui: Esc closes the viewer"
162+
else _fail "$ui: Esc closes the viewer" "$(tui_capture)"; fi
163+
tui_keys C-c; sleep 0.3; tui_keys C-c
164+
165+
# The title check means something only if a title sequence that reaches
166+
# this pane does retitle it: send one from the shell, and keep the shell
167+
# busy while looking, so a prompt that sets its own title cannot hide it.
168+
local waited=0 title=""
169+
while [ "$waited" -lt 50 ] && \
170+
[ "$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_current_command}')" = "$running" ]; do
171+
sleep 0.1; waited=$((waited + 1))
172+
done
173+
if [ "$waited" -lt 50 ]; then
174+
tui_type "printf '\\033]0;suite-title\\007'; sleep 3"; tui_keys Enter
175+
waited=0
176+
while [ "$waited" -lt 30 ]; do
177+
title="$(_tmux display-message -p -t "$TUI_SESSION" '#{pane_title}')"
178+
[ "$title" = suite-title ] && break
179+
sleep 0.1; waited=$((waited + 1))
180+
done
181+
assert_eq "$title" "suite-title" "$ui: a title sequence that reaches the pane does retitle it"
182+
else
183+
_fail "$ui: the TUI exits after Ctrl+C twice" "$(tui_capture)"
184+
fi
185+
fi
186+
tui_stop
187+
188+
TUI_LAUNCH_PREFIX="$saved_prefix"
189+
TUI_BOOT_STRING="$saved_boot"
190+
}
191+
74192
tc_diff_large() {
75-
describe "Large diffs stay responsive in /diff"
193+
describe "/diff on large, binary and renamed changes"
76194
if ! have_tmux; then _skip "tmux not installed"; return 0; fi
77195

78196
local scratch; scratch="$(mktemp -d)"
@@ -83,5 +201,11 @@ tc_diff_large() {
83201
_diff_large_journey classic "Coven v" "$scratch"
84202
_diff_large_journey next "preview" "$scratch"
85203

204+
rm -rf "$scratch/repo"
205+
mkdir -p "$scratch/repo"
206+
_diff_kinds_repo "$scratch/repo" "$scratch/home"
207+
_diff_kinds_journey classic "Coven v" "$scratch"
208+
_diff_kinds_journey next "preview" "$scratch"
209+
86210
rm -rf "$scratch"
87211
}

0 commit comments

Comments
 (0)