pty test harness - #452
Merged
Merged
Conversation
walles
commented
Aug 9, 2026
Owner
- Add a pty test harness
- Test that --quit-if-one-screen output lands on the normal screen
- STARTUP-TUNING: step 3 is done
Moor refuses to page unless stdout is a terminal, so until now nothing in the repo could assert on the escape sequences moor writes. This harness runs moor as a subprocess on a pseudo terminal and captures its raw output, escape sequences included. First test: paging a file that doesn't fit on one screen happens on the alternate screen. The harness answers moor's terminal background color query on request. Terminals that don't answer it make moor wait out a 50ms timeout, and that difference matters for startup timing, so both cases need to be testable. Not available on Windows: creack/pty has no ConPTY support, its Windows entry points all return ErrUnsupported. Both files are build tagged !windows, the way twin/screen-setup_test.go already is. 🤖 Committed by Claude (Opus 5)
This is the output correctness contract that steps 4 and 5 of STARTUP-TUNING.md must not break: what moor leaves behind has to end up after the last ESC[?1049l, so that it looks like cat printed it. Deliberately not asserting that moor stays off the alternate screen entirely. It doesn't today, and removing that switch is step 5. Phrased this way the test passes both before and after that. Run for both a terminal that answers the background color query and one that doesn't, since those take moor down measurably different startup paths. 🤖 Committed by Claude (Opus 5)
Resolves the open question about how to get at a pty from tests, and records the two things that were non-obvious while building the harness: the Windows build tag being load bearing, and waiting for painted contents rather than for the alternate screen escape sequence. 🤖 Committed by Claude (Opus 5)
Build with -trimpath, matching build.sh. Without it every dependency gets compiled a second time, since -trimpath changes the build ID of every package. Measured cold: 10.4s versus 0.3s once build.sh has run, and test.sh gives the whole cmd/moor package 20 seconds. Give up on waitFor() as soon as moor is gone. Moor dying at startup is the most likely failure, and burning the full timeout on each waitFor() and wait() could take the package past test.sh's limit, replacing the harness' output dump with a "test timed out" goroutine dump. Also reap moor in the cleanup, for tests that never call wait(). Assert that the alternate screen is left after it was entered, not just that both happened. An unpaired or reordered ESC[?1049l is a real hazard, DECRST 1049 restores a saved cursor position. Towards #425, see STARTUP-TUNING.md. 🤖 Committed by Claude (Opus 5)
The harness captures bytes, not timestamps, so calling it the measurement tool for steps 1 and 5 was only half true. Say so. Also note two things step 5 will hit: there is no way to pipe input to moor through the harness as it stands, which is the case issue #425 is actually about, and its new assertion makes the alternate screen half of the quit-if-one-screen test redundant. Towards #425. 🤖 Committed by Claude (Opus 5)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.