From f1f70af28d121e6ff379ed390ebb88a165e60bad Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sun, 31 May 2026 10:16:46 +0300 Subject: ask: fix watch output to match regular commands by preserving terminal width detection --- internal/askcli/command_watch_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'internal/askcli/command_watch_test.go') diff --git a/internal/askcli/command_watch_test.go b/internal/askcli/command_watch_test.go index 77d0fda..abd74ff 100644 --- a/internal/askcli/command_watch_test.go +++ b/internal/askcli/command_watch_test.go @@ -267,3 +267,29 @@ func TestHandleWatch_RejectsUnsafeSubcommands(t *testing.T) { }) } } + +type mockFdWriter struct { + io.Writer + fd uintptr +} + +func (m *mockFdWriter) Fd() uintptr { return m.fd } + +func TestDeferredWriter_PreservesFd(t *testing.T) { + w := &mockFdWriter{Writer: &bytes.Buffer{}, fd: 42} + dw := &deferredWriter{w: w} + if got := dw.Fd(); got != 42 { + t.Fatalf("Fd() = %d, want 42", got) + } + _, _ = dw.Write([]byte("hello")) + if !bytes.Equal(dw.buf.Bytes(), []byte("hello")) { + t.Fatalf("buf = %q, want hello", dw.buf.Bytes()) + } +} + +func TestDeferredWriter_FdZeroWhenUnsupported(t *testing.T) { + dw := &deferredWriter{w: &bytes.Buffer{}} + if got := dw.Fd(); got != 0 { + t.Fatalf("Fd() = %d, want 0", got) + } +} -- cgit v1.2.3