Skip to content

Commit e8cbb1a

Browse files
authored
Merge pull request #556 from OpenCoven/fix/411-classic-guard-follow-up-panels
fix(cli): guard Classic's follow-up permission panels
2 parents 39ff307 + 9eaa987 commit e8cbb1a

5 files changed

Lines changed: 145 additions & 67 deletions

File tree

‎scripts/tui-tests/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ lands on the main screen. No secrets or network access required.
173173
| `cases/25_next_unicode_composer.sh` | Unicode in the composer | In Next: 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; one Backspace removes a whole ZWJ emoji and one a letter with its combining mark, and Left steps over the emoji whole, shown by a letter typed in front of it; no turn reaches the provider (`fake_anthropic.py`) before Enter, and it and the saved session get exactly the edited text. In Classic (`COVEN_CODE_UI` unset): the same cluster edits, and the provider gets exactly the edited text. tmux sends committed characters only, so input-method preedit is not covered; needs `python3` |
174174
| `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` |
175175
| `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. With a read-only sessions directory, Ctrl+D twice during a held turn exits, and the pane then shows `Session not saved; any earlier saved copy lacks this turn.` once in both renderers, with no resume command, Next's report only in Next, and no session file written (skipped as root); needs `python3` |
176-
| `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` |
176+
| `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 in both renderers: Next guards every panel, and Classic guards a follow-up panel (#411 decision 17); a guarded panel opens on deny and takes keys other than Escape only after 400 ms of quiet. Classic's first panel still opens on allow, which the case checks, and its follow-up panel must open on deny. 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. 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` |
177177
| `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` |
178178
| `cases/30_panic_restore.sh` | Panic restoration | The product has no known input that panics, so the tui crate's `panic_restore` example takes the terminal with the real `setup_terminal` and panics on request; `panic_restore_pty.py` runs it on a raw PTY, with `setup_terminal` for each renderer (Classic and Next; their event loops are not involved). Before the panic: raw termios (output processing off too), alternate screen, mouse capture, bracketed paste, hidden cursor and pushed keyboard flags. A main-thread panic restores every termios field and, before the panic message, turns output processing back on (the message's first line break arrives as CRLF), pops the keyboard flags before leaving the alternate screen they were pushed on (each screen has its own keyboard stack, #410), leaves the alternate screen, turns mouse capture and bracketed paste off and shows the cursor; the message is printed and the exit status is 101. A worker-thread panic restores nothing and the probe keeps drawing; its later main-thread panic still restores. After a suspend and resume through the real `suspend_terminal`, a panic still restores. With `COVEN_CODE_KEYBOARD_ENHANCEMENT=0` no flags are pushed. Lines containing "current behaviour" pin details that need a decision, not endorse them (Unix; Windows has its own restore branch, which is not exercised): a pop is sent even when none was pushed, the startup title is not cleared, each `setup_terminal` call chains another hook (so after a resume the restore is written twice, and its second pop is sent on the main screen), and a worker-thread panic prints its message onto the live screen. Needs `python3` and the probe |
179179
| `cases/31_classic_daemon_glyph.sh` | Coven daemon glyph | In Classic (`COVEN_CODE_UI` unset), a fake daemon on `coven.sock` in a disposable `COVEN_HOME` answers every request. The footer shows `✦ coven` while it runs, turns to `○ coven` within 25 s of the fake stopping and its socket being removed, with no input, and back to `✦ coven` within 25 s of a fresh fake starting; needs `python3` |

‎scripts/tui-tests/cases/28_approval_queue.sh‎

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#
1212
# A key that is already waiting when the first panel closes reaches the
1313
# composer as text in both renderers: the loop reads it before it opens the
14-
# next request. A key that reaches the next panel decides nothing in Next,
15-
# which ignores keys other than Escape until a new panel has been quiet for
16-
# 400 ms. Classic takes it at once and decides the panel. The case pins both;
17-
# whether Classic should change is a decision for the maintainer.
18-
# Engine-local evidence only.
14+
# next request. A key that reaches the next panel decides nothing in either
15+
# renderer. Next guards every panel: it opens on deny and ignores keys other
16+
# than Escape until the panel has been quiet for 400 ms. Classic guards a
17+
# follow-up panel the same way (#411 decision 17), and still opens its first
18+
# panel on allow, taking keys at once. Engine-local evidence only.
1919

2020
register_case tc_approval_queue
2121

@@ -88,8 +88,15 @@ subprocess.run(press, check=True)
8888
print(int((time.monotonic() - start) * 1000))' "$TUI_SOCKET" "$TUI_SESSION" "$1"
8989
}
9090

91+
# Classic's open panel focuses this option: `► [key]`.
92+
_queue_classic_focus() {
93+
grep -oE '► \[[^]]+\]' <<<"$(tui_capture)" | head -n 1 | sed -E 's/^► \[(.*)\]$/\1/'
94+
}
95+
9196
# Wait until the second y has been handled: its call ran, it is in the
92-
# composer, or (Next) the open panel has gone quiet, so it was ignored.
97+
# composer, or the open panel has ignored it. Next says when its panel has
98+
# gone quiet. Classic shows no notice, so its panel counts as quiet once it is
99+
# on screen a second after the first call ran: the second y was read by then.
93100
_queue_settle() { # ui, marker
94101
local waited=0 s
95102
while [ "$waited" -lt 100 ]; do
@@ -100,6 +107,9 @@ _queue_settle() { # ui, marker
100107
! grep -qF -- "$QUEUE_ARMING" <<<"$s"; then
101108
return 0
102109
fi
110+
if [ "$1" = classic ] && [ "$waited" -ge 10 ] && _queue_panel_shows classic "${2##*/}"; then
111+
return 0
112+
fi
103113
sleep 0.1; waited=$((waited + 1))
104114
done
105115
}
@@ -116,7 +126,12 @@ _queue_round() { # ui, round number, how the second y is pressed
116126
_fail "$tag: the first call asks first" "$(tui_capture)"
117127
return 0
118128
fi
119-
if [ "$ui" = next ]; then wait_absent "$QUEUE_ARMING" 5 >/dev/null; fi
129+
if [ "$ui" = next ]; then
130+
wait_absent "$QUEUE_ARMING" 5 >/dev/null
131+
else
132+
# Classic's first panel is not a follow-up: it opens on allow as before.
133+
assert_eq "$(_queue_classic_focus)" "y" "$tag: the first panel opens on allow, unguarded"
134+
fi
120135

121136
case "$how" in
122137
"same write") tui_paste "yy" ;;
@@ -137,53 +152,34 @@ _queue_round() { # ui, round number, how the second y is pressed
137152
if [ -e "$project/$second" ]; then decided=yes; else decided=no; fi
138153
log " $tag: second y sent ${sent_ms} ms after the first, reached the $path, decided: $decided"
139154

140-
if [ "$ui" = next ]; then
141-
# Next counts quiet from when it reads a key, not from when the key
142-
# arrived, so a loop stalled for 400 ms after opening the next panel could
143-
# still let an earlier key count. The limit below bounds only the sending.
144-
if [ "$sent_ms" -ge 400 ]; then
145-
# A key this late can find the next panel armed, and then it counts.
146-
_skip "$tag: the second y took ${sent_ms} ms to send, so this round proves nothing"
147-
else
148-
assert_eq "$decided" "no" "$tag: the second y, which reached the $path, does not decide the next panel"
149-
fi
150-
case "$how" in
151-
"same write")
152-
assert_eq "$path" "composer" "$tag: the second y reaches the composer as text" ;;
153-
"150 ms later")
154-
# With a panel open, a key that is not in the composer went to the panel.
155-
if [ "$path" = panel ]; then _pass "$tag: the second y missed the composer, so the open panel took it"
156-
else _skip "$tag: the second y arrived before the next panel opened"; fi ;;
157-
esac
155+
# A guard counts quiet from when it reads a key, not from when the key
156+
# arrived, so a loop stalled for 400 ms after opening the next panel could
157+
# still let an earlier key count. The limit below bounds only the sending.
158+
if [ "$sent_ms" -ge 400 ]; then
159+
# A key this late can find the next panel armed, and then it counts.
160+
_skip "$tag: the second y took ${sent_ms} ms to send, so this round proves nothing"
158161
else
159-
case "$how" in
160-
"same write")
161-
assert_eq "$path/$decided" "composer/no" \
162-
"$tag: the second y reaches the composer and decides nothing" ;;
163-
"at once")
164-
# Timing decides where it lands; whichever it reached must agree.
165-
if [ "$path" = panel ]; then
166-
assert_eq "$decided" "yes" "$tag: the second y reached the next panel and decided it"
167-
else
168-
assert_eq "$decided" "no" "$tag: the second y reached the composer and decided nothing"
169-
fi ;;
170-
"150 ms later")
171-
if [ "$path" = panel ]; then
172-
assert_eq "$decided" "yes" \
173-
"$tag: a y on the open next panel decides it at once (differs from Next by design)"
174-
else
175-
_skip "$tag: the second y arrived before the next panel opened"
176-
assert_eq "$decided" "no" "$tag: the second y reached the composer and decided nothing"
177-
fi ;;
178-
esac
162+
assert_eq "$decided" "no" "$tag: the second y, which reached the $path, does not decide the next panel"
179163
fi
164+
case "$how" in
165+
"same write")
166+
assert_eq "$path" "composer" "$tag: the second y reaches the composer as text" ;;
167+
"150 ms later")
168+
# With a panel open, a key that is not in the composer went to the panel.
169+
if [ "$path" = panel ]; then _pass "$tag: the second y missed the composer, so the open panel took it"
170+
else _skip "$tag: the second y arrived before the next panel opened"; fi ;;
171+
esac
180172

181173
if [ "$decided" = no ]; then
182174
if _queue_wait_panel "$ui" "$second"; then _pass "$tag: the next panel is still open"
183175
else _fail "$tag: the next panel is still open" "$(tui_capture)"; fi
176+
if [ "$ui" = classic ]; then
177+
# Classic's follow-up panel is guarded as Next's are: it opens on deny.
178+
assert_eq "$(_queue_classic_focus)" "n" "$tag: the follow-up panel opens on deny"
179+
fi
184180
assert_eq "$(_queue_requests)" "$((before + 1))" \
185181
"$tag: the model has been told nothing while the next call waits"
186-
if [ "$ui" = next ]; then wait_absent "$QUEUE_ARMING" 5 >/dev/null; fi
182+
if [ "$ui" = next ]; then wait_absent "$QUEUE_ARMING" 5 >/dev/null; else sleep 0.5; fi
187183
tui_keys y
188184
if _queue_wait_file "$project/$second"; then
189185
_pass "$tag: a deliberate y then runs the second call"

0 commit comments

Comments
 (0)