Skip to content

pty test harness - #452

Merged
walles merged 5 commits into
masterfrom
pty-test-harness
Aug 9, 2026
Merged

pty test harness#452
walles merged 5 commits into
masterfrom
pty-test-harness

Conversation

@walles

@walles walles commented Aug 9, 2026

Copy link
Copy Markdown
Owner
  • Add a pty test harness
  • Test that --quit-if-one-screen output lands on the normal screen
  • STARTUP-TUNING: step 3 is done

walles added 5 commits August 9, 2026 21:57
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)
@walles
walles merged commit c19b3bf into master Aug 9, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant