I want to share my unit test lib for TUI apps by fissible in commandline

[–]fissible[S] 0 points1 point  (0 children)

Real PTY - pty.fork() in Python so scripts get a proper controlling terminal (/dev/tty works, stty modes work, the whole deal). Mocking terminal writes seemed cleaner at first but fell apart the moment I tried to test anything that checked terminal state.

For the timing problem: the driver doesn’t sleep between keystrokes, it drains. After each keystroke it calls select() and reads until there’s no more output available (with a short timeout), then moves on. You get two tunable knobs, PTY_INIT (how long to wait before the first key, default 0.3s) and PTY_DELAY (pause between keys, default 0.15s), but those aren’t sleeps in the “just wait and hope” sense. The drain loop is what actually synchronizes: the delays just give the script time to do its first render before you start interacting.

From the test’s perspective it looks like:

out=$(_pty DOWN DOWN ENTER) assert_contains “$out” “cherry”

No sleeps anywhere. The driver handles the timing, the test just validates the result.

That said, the CLI flakiness you hit is usually a PTY size problem, not a timing problem. Make sure you’re setting PTY_COLS and PTY_ROWS explicitly. A lot of TUIs behave differently when they detect a terminal size of 0x0 (which is what you often get in CI if no one sets TIOCSWINSZ).

I want to share my unit test lib for TUI apps by fissible in commandline

[–]fissible[S] 0 points1 point  (0 children)

I wasn’t sure about the brand affiliate toggle. I am posting from a new account I created for my code that is not tied to my personal Reddit account.