fish-shell/tests
Johannes Altmanninger b89619330b
Some checks failed
make test / ubuntu (push) Waiting to run
make test / ubuntu-32bit-static-pcre2 (push) Waiting to run
make test / ubuntu-asan (push) Waiting to run
make test / macos (push) Waiting to run
Rust checks / rustfmt (push) Waiting to run
Rust checks / clippy (push) Waiting to run
Lock threads / lock (push) Has been cancelled
Disable terminal protocols before cancellable operations
The [disambiguate flag](https://sw.kovidgoyal.net/kitty/keyboard-protocol/#disambiguate) means that:

> In particular, ctrl+c will no longer generate the SIGINT signal,
> but instead be delivered as a CSI u escape code.

so cancellation only works while we turn off disambiguation.

Today we turn it off while running external commands that want to
claim the TTY.  Also we do it (only as a workaround for this issue)
while expanding wildcards or while running builtin wait.

However there are other cases where we don't have a workaround,
like in trivial infinite loops or when opening a fifo.

Before we run "while true; end", we put the terminal back in ICANON
mode. This means it's line-buffered, so we won't be able to detect
if the user pressed ctrl-c.

Commit 8164855b7 (Disable terminal protocols throughout evaluation,
2024-04-02) had the right solution: simply disable terminal protocols
whenever we do computations that might take a long time.
eval_node() covers most of that; there are a few others.

As pointed out in #10494, the logic was fairly unsophisticated then:
it toggled terminal protocols many times.  The fix in 29f2da8d1
(Toggle terminal protocols lazily, 2024-05-16) went to the extreme
other end of only toggling protocols when absolutely necessary.

Back out part of that commit by toggling in eval_node() again,
fixing cancellation.  Fortunately, we can keep most of the benefits
of the lazy approach from 29f2da8d1: we toggle only 2 times instead
of 8 times for an empty prompt.

There are only two places left where we call signal_check_cancel()
without necessarily disabling the disambiguate flag
1. open_cloexec() we assume that the files we open outside eval_node()
   are never blocking fifos.
2. fire_delayed(). Judging by commit history, this check is not
   relevant for interactive sessions; we'll soon end up calling
   eval_node() anyway.

In future, we can leave bracketed paste, modifyOtherKeys and
application keypad mode turned on again, until we actually run an
external command.  We really only want to turn off the disambiguate
flag.

Since this is approach is overly complex, I plan to go with either
of these two alternatives in future:
- extend the kitty keyboard protocol to optionally support VINTR,
  VSTOP and friends.  Then we can drop most of these changes.
- poll stdin for ctrl-c. This promises a great simplification,
  because it implies that terminal ownership (term_steal/term_donate)
  will be perfectly synced with us enabling kitty keyboard protocol.
  This is because polling requires us to turn off ICANON.
  I started working on this change; I'm convinced it must work,
  but it's not finished yet. Note that this will also want to
  add stdin polling to builtin wait.

Closes #10864
2024-11-24 16:11:57 +01:00
..
checks Clean up the accept-autosuggestion code path a little bit 2024-11-16 13:05:44 +01:00
pexpects Disable terminal protocols before cancellable operations 2024-11-24 16:11:57 +01:00
test_functions Fix tmux-multiline-prompt test with EDITOR=vim 2024-10-27 05:03:30 +01:00
.gitignore tweak gitignore rules for *tests* directory 2017-02-20 20:29:43 -08:00
filter-control-sequences.fish fixup! filter control sequences 2024-11-21 21:20:35 +01:00
history_sample_bash Support $(cmd) command substitution as alternative to (cmd) 2021-07-13 21:33:42 +02:00
history_sample_corrupt1 Improve history robustness against corrupt files 2014-07-29 14:42:03 -07:00
history_sample_fish_1_x Enforce that history items must end with trailing newlines 2021-05-10 14:23:07 -07:00
history_sample_fish_2_0 Enforce that history items must end with trailing newlines 2021-05-10 14:23:07 -07:00
interactive.config Remove some unused functions from the test harness 2020-11-15 09:17:23 +01:00
interactive.fish Only retry failed pexpect tests under CI 2022-10-25 13:40:21 -05:00
test_driver.sh Prevent test suite from hanging on panic 2024-11-11 16:45:13 -06:00
test_env.sh test_env: remove stale env sanitization 2024-10-21 12:56:55 +02:00
test_util.fish Run each test fully independently in own environment 2021-08-29 08:56:12 +02:00
test.fish tests: Move control sequences filtering to fish directly 2024-11-21 21:08:56 +01:00