File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -144,7 +144,7 @@ func NewClient(options *ClientOptions) *Client {
144144 opts .CLIPath = options .CLIPath
145145 }
146146 if options .CLIArgs != nil {
147- opts .CLIArgs = options .CLIArgs
147+ opts .CLIArgs = append ([] string {}, options .CLIArgs ... )
148148 }
149149 if options .Cwd != "" {
150150 opts .Cwd = options .Cwd
Original file line number Diff line number Diff line change @@ -362,6 +362,24 @@ func TestClient_CLIArgs(t *testing.T) {
362362 t .Errorf ("Expected 0 CLI args, got %d" , len (client .options .CLIArgs ))
363363 }
364364 })
365+
366+ t .Run ("should store a copy of CLIArgs slice" , func (t * testing.T ) {
367+ args := []string {"--custom-flag" }
368+ client := NewClient (& ClientOptions {
369+ CLIArgs : args ,
370+ })
371+
372+ // Modify the original slice
373+ args = append (args , "--another-flag" )
374+
375+ // The client's copy should not be affected
376+ if len (client .options .CLIArgs ) != 1 {
377+ t .Errorf ("Expected 1 CLI arg, got %d" , len (client .options .CLIArgs ))
378+ }
379+ if client .options .CLIArgs [0 ] != "--custom-flag" {
380+ t .Errorf ("Expected first arg to be '--custom-flag', got %q" , client .options .CLIArgs [0 ])
381+ }
382+ })
365383}
366384
367385func TestClient_EnvOptions (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments