Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions go/internal/e2e/multi_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ import (
func TestMultiClient(t *testing.T) {
// Use TCP mode so a second client can connect to the same CLI process
ctx := testharness.NewTestContext(t)
client1 := copilot.NewClient(&copilot.ClientOptions{
CLIPath: ctx.CLIPath,
Cwd: ctx.WorkDir,
Env: ctx.Env(),
UseStdio: copilot.Bool(false),
client1 := ctx.NewClient(func(opts *copilot.ClientOptions) {
opts.UseStdio = copilot.Bool(false)
})
t.Cleanup(func() { client1.ForceStop() })

Expand Down
7 changes: 6 additions & 1 deletion go/internal/e2e/testharness/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ func (c *TestContext) Env() []string {
}

// NewClient creates a CopilotClient configured for this test context.
func (c *TestContext) NewClient() *copilot.Client {
// Optional overrides can be applied to the default ClientOptions via the opts function.
func (c *TestContext) NewClient(opts ...func(*copilot.ClientOptions)) *copilot.Client {
options := &copilot.ClientOptions{
CLIPath: c.CLIPath,
Cwd: c.WorkDir,
Expand All @@ -170,6 +171,10 @@ func (c *TestContext) NewClient() *copilot.Client {
options.GitHubToken = "fake-token-for-e2e-tests"
}

for _, opt := range opts {
opt(options)
}

return copilot.NewClient(options)
}

Expand Down
26 changes: 18 additions & 8 deletions go/internal/jsonrpc2/jsonrpc2.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,23 @@ func (c *Client) Request(method string, params any) (json.RawMessage, error) {
}
}

paramsData, err := json.Marshal(params)
if err != nil {
return nil, fmt.Errorf("failed to marshal params: %w", err)
var paramsData json.RawMessage
if params == nil {
paramsData = json.RawMessage("{}")
} else {
var err error
paramsData, err = json.Marshal(params)
if err != nil {
return nil, fmt.Errorf("failed to marshal params: %w", err)
}
}

// Send request
request := Request{
JSONRPC: "2.0",
ID: json.RawMessage(`"` + requestID + `"`),
Method: method,
Params: json.RawMessage(paramsData),
Params: paramsData,
}

if err := c.sendMessage(request); err != nil {
Expand Down Expand Up @@ -261,15 +267,19 @@ func (c *Client) Request(method string, params any) (json.RawMessage, error) {

// Notify sends a JSON-RPC notification (no response expected)
func (c *Client) Notify(method string, params any) error {
paramsData, err := json.Marshal(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
var paramsData json.RawMessage
if params != nil {
var err error
paramsData, err = json.Marshal(params)
if err != nil {
return fmt.Errorf("failed to marshal params: %w", err)
}
}

notification := Request{
JSONRPC: "2.0",
Method: method,
Params: json.RawMessage(paramsData),
Params: paramsData,
}
return c.sendMessage(notification)
}
Expand Down
Loading
Loading