Skip to content

Commit d86cc98

Browse files
committed
honor ClientOptions.UseStdio = false
1 parent ccb7d5f commit d86cc98

File tree

4 files changed

+39
-15
lines changed

4 files changed

+39
-15
lines changed

go/client.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type Client struct {
7171
sessionsMux sync.Mutex
7272
isExternalServer bool
7373
conn interface{} // stores net.Conn for external TCP connections
74+
useStdio bool // resolved value from options
7475
autoStart bool // resolved value from options
7576
autoRestart bool // resolved value from options
7677
}
@@ -95,7 +96,6 @@ func NewClient(options *ClientOptions) *Client {
9596
CLIPath: "copilot",
9697
Cwd: "",
9798
Port: 0,
98-
UseStdio: true,
9999
LogLevel: "info",
100100
}
101101

@@ -105,13 +105,14 @@ func NewClient(options *ClientOptions) *Client {
105105
sessions: make(map[string]*Session),
106106
actualHost: "localhost",
107107
isExternalServer: false,
108+
useStdio: true,
108109
autoStart: true, // default
109110
autoRestart: true, // default
110111
}
111112

112113
if options != nil {
113114
// Validate mutually exclusive options
114-
if options.CLIUrl != "" && (options.UseStdio || options.CLIPath != "") {
115+
if options.CLIUrl != "" && ((options.UseStdio != nil && *options.UseStdio) || options.CLIPath != "") {
115116
panic("CLIUrl is mutually exclusive with UseStdio and CLIPath")
116117
}
117118

@@ -126,7 +127,7 @@ func NewClient(options *ClientOptions) *Client {
126127
client.actualHost = host
127128
client.actualPort = port
128129
client.isExternalServer = true
129-
opts.UseStdio = false
130+
client.useStdio = false
130131
opts.CLIUrl = options.CLIUrl
131132
}
132133

@@ -139,14 +140,17 @@ func NewClient(options *ClientOptions) *Client {
139140
if options.Port > 0 {
140141
opts.Port = options.Port
141142
// If port is specified, switch to TCP mode
142-
opts.UseStdio = false
143+
client.useStdio = false
143144
}
144145
if options.LogLevel != "" {
145146
opts.LogLevel = options.LogLevel
146147
}
147148
if len(options.Env) > 0 {
148149
opts.Env = options.Env
149150
}
151+
if options.UseStdio != nil {
152+
client.useStdio = *options.UseStdio
153+
}
150154
if options.AutoStart != nil {
151155
client.autoStart = *options.AutoStart
152156
}
@@ -1050,7 +1054,7 @@ func (c *Client) startCLIServer() error {
10501054
args := []string{"--server", "--log-level", c.options.LogLevel}
10511055

10521056
// Choose transport mode
1053-
if c.options.UseStdio {
1057+
if c.useStdio {
10541058
args = append(args, "--stdio")
10551059
} else if c.options.Port > 0 {
10561060
args = append(args, "--port", strconv.Itoa(c.options.Port))
@@ -1096,7 +1100,7 @@ func (c *Client) startCLIServer() error {
10961100
c.process.Env = append(c.process.Env, "COPILOT_SDK_AUTH_TOKEN="+c.options.GithubToken)
10971101
}
10981102

1099-
if c.options.UseStdio {
1103+
if c.useStdio {
11001104
// For stdio mode, we need stdin/stdout pipes
11011105
stdin, err := c.process.StdinPipe()
11021106
if err != nil {
@@ -1171,7 +1175,7 @@ func (c *Client) startCLIServer() error {
11711175

11721176
// connectToServer establishes a connection to the server.
11731177
func (c *Client) connectToServer() error {
1174-
if c.options.UseStdio {
1178+
if c.useStdio {
11751179
// Already connected via stdio in startCLIServer
11761180
return nil
11771181
}

go/client_test.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestClient_URLParsing(t *testing.T) {
194194

195195
NewClient(&ClientOptions{
196196
CLIUrl: "localhost:8080",
197-
UseStdio: true,
197+
UseStdio: Bool(true),
198198
})
199199
})
200200

@@ -221,11 +221,31 @@ func TestClient_URLParsing(t *testing.T) {
221221
CLIUrl: "8080",
222222
})
223223

224-
if client.options.UseStdio {
224+
if client.useStdio {
225225
t.Error("Expected UseStdio to be false when CLIUrl is provided")
226226
}
227227
})
228228

229+
t.Run("should set UseStdio to false when UseStdio is set to true", func(t *testing.T) {
230+
client := NewClient(&ClientOptions{
231+
UseStdio: Bool(true),
232+
})
233+
234+
if !client.useStdio {
235+
t.Error("Expected UseStdio to be true when UseStdio is set to true")
236+
}
237+
})
238+
239+
t.Run("should set UseStdio to false when UseStdio is set to false", func(t *testing.T) {
240+
client := NewClient(&ClientOptions{
241+
UseStdio: Bool(false),
242+
})
243+
244+
if client.useStdio {
245+
t.Error("Expected UseStdio to be false when UseStdio is set to false")
246+
}
247+
})
248+
229249
t.Run("should mark client as using external server", func(t *testing.T) {
230250
client := NewClient(&ClientOptions{
231251
CLIUrl: "localhost:8080",

go/e2e/client_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestClient(t *testing.T) {
1717
t.Run("should start and connect to server using stdio", func(t *testing.T) {
1818
client := copilot.NewClient(&copilot.ClientOptions{
1919
CLIPath: cliPath,
20-
UseStdio: true,
20+
UseStdio: copilot.Bool(true),
2121
})
2222
t.Cleanup(func() { client.ForceStop() })
2323

@@ -54,7 +54,7 @@ func TestClient(t *testing.T) {
5454
t.Run("should start and connect to server using tcp", func(t *testing.T) {
5555
client := copilot.NewClient(&copilot.ClientOptions{
5656
CLIPath: cliPath,
57-
UseStdio: false,
57+
UseStdio: copilot.Bool(true),
5858
})
5959
t.Cleanup(func() { client.ForceStop() })
6060

@@ -134,7 +134,7 @@ func TestClient(t *testing.T) {
134134
t.Run("should get status with version and protocol info", func(t *testing.T) {
135135
client := copilot.NewClient(&copilot.ClientOptions{
136136
CLIPath: cliPath,
137-
UseStdio: true,
137+
UseStdio: copilot.Bool(true),
138138
})
139139
t.Cleanup(func() { client.ForceStop() })
140140

@@ -161,7 +161,7 @@ func TestClient(t *testing.T) {
161161
t.Run("should get auth status", func(t *testing.T) {
162162
client := copilot.NewClient(&copilot.ClientOptions{
163163
CLIPath: cliPath,
164-
UseStdio: true,
164+
UseStdio: copilot.Bool(true),
165165
})
166166
t.Cleanup(func() { client.ForceStop() })
167167

@@ -190,7 +190,7 @@ func TestClient(t *testing.T) {
190190
t.Run("should list models when authenticated", func(t *testing.T) {
191191
client := copilot.NewClient(&copilot.ClientOptions{
192192
CLIPath: cliPath,
193-
UseStdio: true,
193+
UseStdio: copilot.Bool(true),
194194
})
195195
t.Cleanup(func() { client.ForceStop() })
196196

go/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type ClientOptions struct {
1919
// Port for TCP transport (default: 0 = random port)
2020
Port int
2121
// UseStdio enables stdio transport instead of TCP (default: true)
22-
UseStdio bool
22+
UseStdio *bool
2323
// CLIUrl is the URL of an existing Copilot CLI server to connect to over TCP
2424
// Format: "host:port", "http://host:port", or just "port" (defaults to localhost)
2525
// Examples: "localhost:8080", "http://127.0.0.1:9000", "8080"

0 commit comments

Comments
 (0)