From f50a6b6447b6502c993983191f292b9504c22844 Mon Sep 17 00:00:00 2001 From: ruinivist Date: Sat, 21 Mar 2026 08:01:31 +0000 Subject: [PATCH] fix: test slowness on usage of exit --- internal/miro/post_process.go | 11 ++++++++--- internal/miro/post_process_test.go | 15 +++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/miro/post_process.go b/internal/miro/post_process.go index 72d96a2..0fc666d 100644 --- a/internal/miro/post_process.go +++ b/internal/miro/post_process.go @@ -26,7 +26,7 @@ func loadRecordedInput(path string) ([]byte, error) { } } - return trimTrailingNewlineAfterEOF(data), nil + return trimTrailingReplayNewline(data), nil } func loadRecordedOutput(path string) ([]byte, error) { @@ -108,8 +108,13 @@ func findScriptFooter(data []byte) (int, footerMatchState) { return candidate, footerFound } -func trimTrailingNewlineAfterEOF(data []byte) []byte { - if len(data) >= 2 && data[len(data)-2] == eofByte && data[len(data)-1] == '\n' { +func trimTrailingReplayNewline(data []byte) []byte { + // util-linux script records the final Enter as "\r\n", but replay feeds the + // bytes from a file rather than a tty. If the shell exits after consuming the + // trailing '\r', the leftover '\n' can trigger script's ~2s non-tty stdin + // delay before it shuts down. Keep the '\r' that bash consumed, drop only the + // synthetic final '\n'. The same cleanup is needed after a terminal EOF byte. + if len(data) >= 2 && data[len(data)-1] == '\n' && (data[len(data)-2] == '\r' || data[len(data)-2] == eofByte) { return data[:len(data)-1] } diff --git a/internal/miro/post_process_test.go b/internal/miro/post_process_test.go index d345403..e339a20 100644 --- a/internal/miro/post_process_test.go +++ b/internal/miro/post_process_test.go @@ -20,6 +20,21 @@ func TestLoadRecordedInputTrimsTrailingNewlineAfterEOF(t *testing.T) { } } +func TestLoadRecordedInputTrimsTrailingNewlineAfterCarriageReturn(t *testing.T) { + path := filepath.Join(t.TempDir(), "in") + writeFile(t, path, "echo hi\rexit\r\n") + + got, err := loadRecordedInput(path) + if err != nil { + t.Fatalf("loadRecordedInput() error = %v", err) + } + + want := "echo hi\rexit\r" + if string(got) != want { + t.Fatalf("loadRecordedInput() = %q, want %q", string(got), want) + } +} + func TestLoadRecordedInputLeavesNormalTrailingNewline(t *testing.T) { path := filepath.Join(t.TempDir(), "in") writeFile(t, path, "echo hi\n")