From 1d35466bfe9208715f0aa4e00c86d27ee4c243c9 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 05:44:15 +0000 Subject: [PATCH 1/2] test: capture command output in a file, not an unread pipe Several tests redirected stdout/stderr to a pipe, ran the command, and only then read the pipe. With nothing reading during the write, the command blocks forever once its output exceeds the pipe buffer, and on macOS that buffer can be as small as 512 bytes when the process holds many pipes. TestChatRecent_CommandPathFiltersSortsAndCaps hung this way under make release-check. Those tests now write to a temp file, and the concurrent capture helpers close their read ends. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016GB34RWVbYYwb6ihVx6xzh --- cmd/calendar_test.go | 6 +++--- cmd/chat_test.go | 18 +++++++++--------- cmd/hooks_test.go | 2 +- cmd/raw_runners_test.go | 31 +++++++++++++++++++++++++++++++ cmd/slides_test.go | 6 +++--- cmd/validation_test.go | 2 +- 6 files changed, 48 insertions(+), 17 deletions(-) diff --git a/cmd/calendar_test.go b/cmd/calendar_test.go index a9319988..9d258da8 100644 --- a/cmd/calendar_test.go +++ b/cmd/calendar_test.go @@ -2163,7 +2163,7 @@ func TestCalendarCreate_AddsSelfByDefault(t *testing.T) { _ = cmd.Flags().Set("attendees", "someone-else@example.com") oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w if err := cmd.RunE(cmd, []string{}); err != nil { os.Stdout = oldStdout @@ -2249,7 +2249,7 @@ func TestCalendarCreate_PrimaryLookupFailureDefaultPath(t *testing.T) { // Note: --add-self left at default true and NOT explicitly set. oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w if err := cmd.RunE(cmd, []string{}); err != nil { os.Stdout = oldStdout @@ -2316,7 +2316,7 @@ func TestCalendarCreate_RespectsAddSelfFalse(t *testing.T) { _ = cmd.Flags().Set("add-self", "false") oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w if err := cmd.RunE(cmd, []string{}); err != nil { os.Stdout = oldStdout diff --git a/cmd/chat_test.go b/cmd/chat_test.go index 9f73bf9e..977a02ee 100644 --- a/cmd/chat_test.go +++ b/cmd/chat_test.go @@ -3344,7 +3344,7 @@ func TestChatFindGroup_CommandE2E(t *testing.T) { // Capture stdout oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w err := cmd.RunE(cmd, []string{}) @@ -3408,7 +3408,7 @@ func TestChatFindGroup_ErrorOnEmptyMembers(t *testing.T) { // Capture stderr (PrintError writes error JSON to stderr per #190) oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w cmd.RunE(cmd, []string{}) @@ -3558,7 +3558,7 @@ func TestChatFindSpace_MatchesByDisplayName(t *testing.T) { cmd.Flags().Set("name", "sales") oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w cmd.RunE(cmd, []string{}) w.Close() @@ -3597,7 +3597,7 @@ func TestChatFindSpace_TypeFilter(t *testing.T) { cmd.Flags().Set("type", "SPACE") oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w cmd.RunE(cmd, []string{}) w.Close() @@ -3626,7 +3626,7 @@ func TestChatFindSpace_InvalidType(t *testing.T) { cmd.Flags().Set("type", "BOGUS") oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w cmd.RunE(cmd, []string{}) w.Close() @@ -3695,7 +3695,7 @@ func TestChatFindSpace_RefreshTypeScoped(t *testing.T) { _ = cmd.Flags().Set("refresh", "true") oldStdout := os.Stdout - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stdout = w if err := cmd.RunE(cmd, []string{}); err != nil { os.Stdout = oldStdout @@ -3764,7 +3764,7 @@ func TestChatFindSpace_NoCache(t *testing.T) { cmd.Flags().Set("name", "sales") oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w cmd.RunE(cmd, []string{}) w.Close() @@ -3791,7 +3791,7 @@ func TestChatFindGroup_NoCache(t *testing.T) { cmd.Flags().Set("members", "alice@example.com") oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w cmd.RunE(cmd, []string{}) @@ -3981,7 +3981,7 @@ func TestChatRecent_CommandPathFiltersSortsAndCaps(t *testing.T) { }() originalStdout := os.Stdout - reader, writer, err := os.Pipe() + reader, writer, err := captureFile(t) if err != nil { t.Fatalf("failed to create stdout pipe: %v", err) } diff --git a/cmd/hooks_test.go b/cmd/hooks_test.go index 9ec7801a..b6dd7bee 100644 --- a/cmd/hooks_test.go +++ b/cmd/hooks_test.go @@ -251,7 +251,7 @@ func captureHookCommandOutput(t *testing.T, outputFormat string, quietValue bool t.Fatal("root --format flag is not registered") } oldFormat, oldQuiet, oldStdout := formatFlag.Value.String(), quiet, os.Stdout - reader, writer, err := os.Pipe() + reader, writer, err := captureFile(t) if err != nil { t.Fatal(err) } diff --git a/cmd/raw_runners_test.go b/cmd/raw_runners_test.go index d8635a24..3b19bd17 100644 --- a/cmd/raw_runners_test.go +++ b/cmd/raw_runners_test.go @@ -14,6 +14,7 @@ import ( "net/http/httptest" "net/url" "os" + "path/filepath" "strings" "sync" "testing" @@ -48,6 +49,7 @@ func captureStdout(t *testing.T, fn func() error) (string, error) { runErr := fn() _ = w.Close() wg.Wait() + _ = r.Close() os.Stdout = orig return buf.String(), runErr } @@ -517,6 +519,7 @@ func captureStderrStr(t *testing.T, fn func()) string { fn() _ = w.Close() wg.Wait() + _ = r.Close() os.Stderr = orig return buf.String() } @@ -574,3 +577,31 @@ func TestChatListRaw_ClampsPageSizeToMax(t *testing.T) { t.Errorf("expected verbatim nextPageToken positioned after item 5, got %q", got.NextPageToken) } } + +// captureFile returns a file to write captured output to and a second +// handle to read it back from, as a drop-in for os.Pipe() in tests that +// run a command first and read its output afterwards. +// +// A pipe cannot be used that way: nothing reads while the command writes, +// so the write blocks for good once the output exceeds the pipe's buffer, +// and that buffer is not a fixed size (macOS shrinks it to 512 bytes when +// a process holds many pipes). A file has no such limit. Both handles are +// closed when the test ends. +func captureFile(t *testing.T) (r, w *os.File, err error) { + t.Helper() + path := filepath.Join(t.TempDir(), "captured-output") + w, err = os.Create(path) + if err != nil { + return nil, nil, err + } + r, err = os.Open(path) + if err != nil { + _ = w.Close() + return nil, nil, err + } + t.Cleanup(func() { + _ = r.Close() + _ = w.Close() + }) + return r, w, nil +} diff --git a/cmd/slides_test.go b/cmd/slides_test.go index 11086bee..28839866 100644 --- a/cmd/slides_test.go +++ b/cmd/slides_test.go @@ -832,7 +832,7 @@ func TestSlidesAddTextCommand_ValidationErrors(t *testing.T) { // Capture os.Stderr since PrintError writes to stderr (#190) oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w // Execute the command with a dummy presentation ID @@ -1069,7 +1069,7 @@ func TestSlidesAddTextCommand_NotesValidation(t *testing.T) { } oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w _ = cmd.RunE(cmd, []string{"test-presentation-id"}) @@ -1137,7 +1137,7 @@ func TestSlidesDeleteTextCommand_NotesValidation(t *testing.T) { } oldStderr := os.Stderr - r, w, _ := os.Pipe() + r, w, _ := captureFile(t) os.Stderr = w _ = cmd.RunE(cmd, []string{"test-presentation-id"}) diff --git a/cmd/validation_test.go b/cmd/validation_test.go index c9b83e1a..7003b8c3 100644 --- a/cmd/validation_test.go +++ b/cmd/validation_test.go @@ -13,7 +13,7 @@ import ( func captureOutput(t *testing.T, fn func()) string { t.Helper() old := os.Stderr - r, w, err := os.Pipe() + r, w, err := captureFile(t) if err != nil { t.Fatalf("failed to create pipe: %v", err) } From 82e1fad9652e18364c112fc59fe63ece523bb755 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 26 Nov 2026 05:45:57 +0000 Subject: [PATCH 2/2] test: captureFile fails the test on setup errors; fix stale messages Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_016GB34RWVbYYwb6ihVx6xzh --- cmd/chat_test.go | 2 +- cmd/raw_runners_test.go | 9 ++++++--- cmd/validation_test.go | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/chat_test.go b/cmd/chat_test.go index 977a02ee..69a9d774 100644 --- a/cmd/chat_test.go +++ b/cmd/chat_test.go @@ -3983,7 +3983,7 @@ func TestChatRecent_CommandPathFiltersSortsAndCaps(t *testing.T) { originalStdout := os.Stdout reader, writer, err := captureFile(t) if err != nil { - t.Fatalf("failed to create stdout pipe: %v", err) + t.Fatalf("failed to create stdout capture file: %v", err) } os.Stdout = writer defer func() { diff --git a/cmd/raw_runners_test.go b/cmd/raw_runners_test.go index 3b19bd17..94dbe498 100644 --- a/cmd/raw_runners_test.go +++ b/cmd/raw_runners_test.go @@ -586,18 +586,21 @@ func TestChatListRaw_ClampsPageSizeToMax(t *testing.T) { // so the write blocks for good once the output exceeds the pipe's buffer, // and that buffer is not a fixed size (macOS shrinks it to 512 bytes when // a process holds many pipes). A file has no such limit. Both handles are -// closed when the test ends. +// closed when the test ends. The error is always nil. func captureFile(t *testing.T) (r, w *os.File, err error) { t.Helper() + // Setup failures end the test here, so a caller that ignores the + // returned error (kept only to match os.Pipe's signature) can never + // go on to install a nil file as os.Stdout or os.Stderr. path := filepath.Join(t.TempDir(), "captured-output") w, err = os.Create(path) if err != nil { - return nil, nil, err + t.Fatalf("failed to create capture file: %v", err) } r, err = os.Open(path) if err != nil { _ = w.Close() - return nil, nil, err + t.Fatalf("failed to open capture file: %v", err) } t.Cleanup(func() { _ = r.Close() diff --git a/cmd/validation_test.go b/cmd/validation_test.go index 7003b8c3..f77c9bc8 100644 --- a/cmd/validation_test.go +++ b/cmd/validation_test.go @@ -15,7 +15,7 @@ func captureOutput(t *testing.T, fn func()) string { old := os.Stderr r, w, err := captureFile(t) if err != nil { - t.Fatalf("failed to create pipe: %v", err) + t.Fatalf("failed to create capture file: %v", err) } os.Stderr = w