Skip to content

Commit 79e22d5

Browse files
Simplify Go SDK
1 parent 66628ea commit 79e22d5

2 files changed

Lines changed: 3 additions & 41 deletions

File tree

go/client.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@ package copilot
2929

3030
import (
3131
"bufio"
32-
"bytes"
3332
"context"
3433
"encoding/json"
3534
"errors"
3635
"fmt"
37-
"io"
3836
"net"
3937
"os"
4038
"os/exec"
@@ -49,11 +47,6 @@ import (
4947
"github.com/github/copilot-sdk/go/rpc"
5048
)
5149

52-
// readAll reads all data from r until EOF or error, returning the data read.
53-
func readAll(r io.Reader) ([]byte, error) {
54-
return io.ReadAll(r)
55-
}
56-
5750
// Client manages the connection to the Copilot CLI server and provides session management.
5851
//
5952
// The Client can either spawn a CLI server process or connect to an existing server.
@@ -92,7 +85,6 @@ type Client struct {
9285
lifecycleHandlers []SessionLifecycleHandler
9386
typedLifecycleHandlers map[SessionLifecycleEventType][]SessionLifecycleHandler
9487
lifecycleHandlersMux sync.Mutex
95-
stderrBuf bytes.Buffer // captures CLI stderr for error messages
9688
processDone chan struct{} // closed when CLI process exits
9789
processError error // set before processDone is closed
9890

@@ -1098,34 +1090,15 @@ func (c *Client) startCLIServer(ctx context.Context) error {
10981090
return fmt.Errorf("failed to create stdout pipe: %w", err)
10991091
}
11001092

1101-
stderr, err := c.process.StderrPipe()
1102-
if err != nil {
1103-
return fmt.Errorf("failed to create stderr pipe: %w", err)
1104-
}
1105-
11061093
if err := c.process.Start(); err != nil {
11071094
return fmt.Errorf("failed to start CLI server: %w", err)
11081095
}
11091096

1110-
// Read stderr in background - reads until EOF (process exit) then signals completion
1111-
stderrDone := make(chan struct{})
1112-
go func() {
1113-
// ReadAll reads until EOF, which happens when process terminates
1114-
data, _ := readAll(stderr)
1115-
c.stderrBuf.Write(data)
1116-
close(stderrDone)
1117-
}()
1118-
11191097
// Monitor process exit to signal pending requests
11201098
c.processDone = make(chan struct{})
11211099
go func() {
11221100
waitErr := c.process.Wait()
1123-
// Wait for stderr reader to finish before accessing buffer
1124-
<-stderrDone
1125-
stderrOutput := strings.TrimSpace(c.stderrBuf.String())
1126-
if stderrOutput != "" {
1127-
c.processError = fmt.Errorf("CLI process exited: %v\nstderr: %s", waitErr, stderrOutput)
1128-
} else if waitErr != nil {
1101+
if waitErr != nil {
11291102
c.processError = fmt.Errorf("CLI process exited: %v", waitErr)
11301103
} else {
11311104
c.processError = fmt.Errorf("CLI process exited unexpectedly")

go/internal/e2e/client_test.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package e2e
22

33
import (
4-
"strings"
54
"testing"
65
"time"
76

@@ -227,7 +226,7 @@ func TestClient(t *testing.T) {
227226
client.Stop()
228227
})
229228

230-
t.Run("should report error with stderr when CLI fails to start", func(t *testing.T) {
229+
t.Run("should report error when CLI fails to start", func(t *testing.T) {
231230
client := copilot.NewClient(&copilot.ClientOptions{
232231
CLIPath: cliPath,
233232
CLIArgs: []string{"--nonexistent-flag-for-testing"},
@@ -240,23 +239,13 @@ func TestClient(t *testing.T) {
240239
t.Fatal("Expected Start to fail with invalid CLI args")
241240
}
242241

243-
errStr := err.Error()
244-
// Verify we get the stderr output in the error message
245-
if !strings.Contains(errStr, "stderr") || !strings.Contains(errStr, "nonexistent") {
246-
t.Errorf("Expected error to contain stderr output about invalid flag, got: %v", err)
247-
}
248-
249-
// Verify subsequent calls also fail with the same error
242+
// Verify subsequent calls also fail (don't hang)
250243
session, err := client.CreateSession(t.Context(), nil)
251244
if err == nil {
252245
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "test"})
253246
}
254247
if err == nil {
255248
t.Fatal("Expected CreateSession/Send to fail after CLI exit")
256249
}
257-
errStr = err.Error()
258-
if !strings.Contains(errStr, "stderr") && !strings.Contains(errStr, "nonexistent") {
259-
t.Errorf("Expected subsequent error to reference CLI failure, got: %v", err)
260-
}
261250
})
262251
}

0 commit comments

Comments
 (0)