Repository navigation
Expand file tree
/
Copy pathtools_e2e_test.go
More file actions
667 lines (571 loc) · 21.1 KB
/
Copy pathtools_e2e_test.go
File metadata and controls
667 lines (571 loc) · 21.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
package e2e
import (
"errors"
"os"
"path/filepath"
"strings"
"sync"
"testing"
copilot "github.com/github/copilot-sdk/go"
"github.com/github/copilot-sdk/go/internal/e2e/testharness"
"github.com/github/copilot-sdk/go/rpc"
)
func TestToolsE2E(t *testing.T) {
ctx := testharness.NewTestContext(t)
client := ctx.NewClient()
t.Cleanup(func() { client.ForceStop() })
t.Run("invokes built-in tools", func(t *testing.T) {
ctx.ConfigureForTest(t)
// Write a test file
err := os.WriteFile(filepath.Join(ctx.WorkDir, "README.md"), []byte("# ELIZA, the only chatbot you'll ever need"), 0644)
if err != nil {
t.Fatalf("Failed to write test file: %v", err)
}
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "What's the first line of README.md in this directory?"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "ELIZA") {
t.Errorf("Expected answer to contain 'ELIZA', got %v", answer.Data)
}
})
t.Run("invokes custom tool", func(t *testing.T) {
ctx.ConfigureForTest(t)
type EncryptParams struct {
Input string `json:"input" jsonschema:"String to encrypt"`
}
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
copilot.DefineTool("encrypt_string", "Encrypts a string",
func(params EncryptParams, inv copilot.ToolInvocation) (string, error) {
return strings.ToUpper(params.Input), nil
}),
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use encrypt_string to encrypt this string: Hello"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "HELLO") {
t.Errorf("Expected answer to contain 'HELLO', got %v", answer.Data)
}
})
t.Run("low_level_tool_definition", func(t *testing.T) {
ctx.ConfigureForTest(t)
type PhaseArgs struct {
Phase string `json:"phase" jsonschema:"Current phase,enum=searching,enum=analyzing,enum=done"`
}
type SearchArgs struct {
Keyword string `json:"keyword" jsonschema:"Search keyword"`
}
var mu sync.Mutex
currentPhase := ""
searchKeyword := ""
setCurrentPhaseTool := copilot.DefineTool("set_current_phase", "Sets the current phase of the agent",
func(params PhaseArgs, inv copilot.ToolInvocation) (string, error) {
mu.Lock()
currentPhase = params.Phase
mu.Unlock()
return "Phase set to " + params.Phase, nil
})
searchItemsTool := copilot.DefineTool("search_items", "Search for items by keyword",
func(params SearchArgs, inv copilot.ToolInvocation) (string, error) {
mu.Lock()
searchKeyword = params.Keyword
mu.Unlock()
return "Found: item_alpha, item_beta", nil
})
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
AvailableTools: copilot.NewToolSet().AddCustom("*").AddBuiltIn("web_fetch").ToSlice(),
Tools: []copilot.Tool{
setCurrentPhaseTool,
searchItemsTool,
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{
Prompt: "First, set the current phase to 'analyzing'. Then search for items with keyword 'copilot'. Report the phase and search results.",
})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if answer == nil {
t.Fatalf("Expected non-nil assistant message")
return
}
ad, ok := answer.Data.(*copilot.AssistantMessageData)
if !ok {
t.Fatalf("Expected AssistantMessageData")
}
content := ad.Content
if content == "" {
t.Fatalf("Expected non-empty response")
}
lower := strings.ToLower(content)
if !strings.Contains(lower, "analyzing") {
t.Errorf("Expected response to contain 'analyzing', got %q", content)
}
if !strings.Contains(lower, "item_alpha") && !strings.Contains(lower, "item_beta") {
t.Errorf("Expected response to contain 'item_alpha' or 'item_beta', got %q", content)
}
mu.Lock()
gotPhase := currentPhase
gotKeyword := searchKeyword
mu.Unlock()
if gotKeyword != "copilot" {
t.Errorf("Expected search keyword to be 'copilot', got %q", gotKeyword)
}
if gotPhase != "analyzing" {
t.Errorf("Expected currentPhase to be 'analyzing', got %q", gotPhase)
}
})
t.Run("handles tool calling errors", func(t *testing.T) {
ctx.ConfigureForTest(t)
type EmptyParams struct{}
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
copilot.DefineTool("get_user_location", "Gets the user's location",
func(params EmptyParams, inv copilot.ToolInvocation) (any, error) {
return nil, errors.New("Melbourne")
}),
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{
Prompt: "What is my location? If you can't find out, just say 'unknown'.",
})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
// Check the underlying traffic
traffic, err := ctx.GetExchanges()
if err != nil {
t.Fatalf("Failed to get exchanges: %v", err)
}
lastConversation := traffic[len(traffic)-1]
// Find tool calls
var toolCalls []testharness.ToolCall
for _, msg := range lastConversation.Request.Messages {
if msg.Role == "assistant" && msg.ToolCalls != nil {
toolCalls = append(toolCalls, msg.ToolCalls...)
}
}
if len(toolCalls) != 1 {
t.Fatalf("Expected 1 tool call, got %d", len(toolCalls))
}
toolCall := toolCalls[0]
if toolCall.Type != "function" {
t.Errorf("Expected tool call type 'function', got '%s'", toolCall.Type)
}
if toolCall.Function.Name != "get_user_location" {
t.Errorf("Expected tool call name 'get_user_location', got '%s'", toolCall.Function.Name)
}
// Find tool results
var toolResults []testharness.Message
for _, msg := range lastConversation.Request.Messages {
if msg.Role == "tool" {
toolResults = append(toolResults, msg)
}
}
if len(toolResults) != 1 {
t.Fatalf("Expected 1 tool result, got %d", len(toolResults))
}
toolResult := toolResults[0]
if toolResult.ToolCallID != toolCall.ID {
t.Errorf("Expected tool result ID '%s', got '%s'", toolCall.ID, toolResult.ToolCallID)
}
// The error message "Melbourne" should NOT be exposed to the LLM
if strings.Contains(toolResult.Content, "Melbourne") {
t.Errorf("Tool result should not contain error details 'Melbourne', got '%s'", toolResult.Content)
}
// The assistant should not see the exception information
if md, ok := answer.Data.(*copilot.AssistantMessageData); ok && strings.Contains(md.Content, "Melbourne") {
t.Errorf("Assistant should not see error details 'Melbourne', got '%s'", md.Content)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(strings.ToLower(md.Content), "unknown") {
t.Errorf("Expected answer to contain 'unknown', got %v", answer.Data)
}
})
t.Run("can receive and return complex types", func(t *testing.T) {
ctx.ConfigureForTest(t)
type DbQuery struct {
Table string `json:"table"`
IDs []int `json:"ids"`
SortAscending bool `json:"sortAscending"`
}
type DbQueryParams struct {
Query DbQuery `json:"query"`
}
type City struct {
CountryID int `json:"countryId"`
CityName string `json:"cityName"`
Population int `json:"population"`
}
var receivedInvocation *copilot.ToolInvocation
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
copilot.DefineTool("db_query", "Performs a database query",
func(params DbQueryParams, inv copilot.ToolInvocation) ([]City, error) {
receivedInvocation = &inv
if params.Query.Table != "cities" {
t.Errorf("Expected table 'cities', got '%s'", params.Query.Table)
}
if len(params.Query.IDs) != 2 || params.Query.IDs[0] != 12 || params.Query.IDs[1] != 19 {
t.Errorf("Expected IDs [12, 19], got %v", params.Query.IDs)
}
if !params.Query.SortAscending {
t.Errorf("Expected sortAscending to be true")
}
return []City{
{CountryID: 19, CityName: "Passos", Population: 135460},
{CountryID: 12, CityName: "San Lorenzo", Population: 204356},
}, nil
}),
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{
Prompt: "Perform a DB query for the 'cities' table using IDs 12 and 19, sorting ascending. " +
"Reply only with lines of the form: [cityname] [population]",
})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if answer == nil {
t.Fatalf("Expected assistant message with content")
return
}
ad, ok := answer.Data.(*copilot.AssistantMessageData)
if !ok {
t.Fatalf("Expected assistant message with content")
}
responseContent := ad.Content
if responseContent == "" {
t.Errorf("Expected non-empty response")
}
if !strings.Contains(responseContent, "Passos") {
t.Errorf("Expected response to contain 'Passos', got '%s'", responseContent)
}
if !strings.Contains(responseContent, "San Lorenzo") {
t.Errorf("Expected response to contain 'San Lorenzo', got '%s'", responseContent)
}
// Remove commas for number checking (e.g., "135,460" -> "135460")
responseWithoutCommas := strings.ReplaceAll(responseContent, ",", "")
if !strings.Contains(responseWithoutCommas, "135460") {
t.Errorf("Expected response to contain '135460', got '%s'", responseContent)
}
if !strings.Contains(responseWithoutCommas, "204356") {
t.Errorf("Expected response to contain '204356', got '%s'", responseContent)
}
// We can access the raw invocation if needed
if receivedInvocation == nil {
t.Fatalf("Expected to receive invocation")
}
if receivedInvocation.SessionID != session.SessionID {
t.Errorf("Expected session ID '%s', got '%s'", session.SessionID, receivedInvocation.SessionID)
}
})
t.Run("skipPermission sent in tool definition", func(t *testing.T) {
ctx.ConfigureForTest(t)
type LookupParams struct {
ID string `json:"id" jsonschema:"ID to look up"`
}
safeLookupTool := copilot.DefineTool("safe_lookup", "A safe lookup that skips permission",
func(params LookupParams, inv copilot.ToolInvocation) (string, error) {
return "RESULT: " + params.ID, nil
})
safeLookupTool.SkipPermission = true
didRunPermissionRequest := false
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: func(request copilot.PermissionRequest, invocation copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
didRunPermissionRequest = true
return &rpc.PermissionDecisionNoResult{}, nil
},
Tools: []copilot.Tool{
safeLookupTool,
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use safe_lookup to look up 'test123'"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "RESULT: test123") {
t.Errorf("Expected answer to contain 'RESULT: test123', got %v", answer.Data)
}
if didRunPermissionRequest {
t.Errorf("Expected permission handler to NOT be called for skipPermission tool")
}
})
t.Run("should execute multiple custom tools in parallel single turn", func(t *testing.T) {
ctx.ConfigureForTest(t)
type CityParams struct {
City string `json:"city" jsonschema:"City name"`
}
type CountryParams struct {
Country string `json:"country" jsonschema:"Country name"`
}
cityCalled := make(chan string, 1)
countryCalled := make(chan string, 1)
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
copilot.DefineTool("lookup_city", "Looks up city information",
func(params CityParams, inv copilot.ToolInvocation) (string, error) {
select {
case cityCalled <- params.City:
default:
}
return "CITY_" + strings.ToUpper(params.City), nil
}),
copilot.DefineTool("lookup_country", "Looks up country information",
func(params CountryParams, inv copilot.ToolInvocation) (string, error) {
select {
case countryCalled <- params.Country:
default:
}
return "COUNTRY_" + strings.ToUpper(params.Country), nil
}),
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
answer, err := session.SendAndWait(t.Context(), copilot.MessageOptions{
Prompt: "Use lookup_city with 'Paris' and lookup_country with 'France' at the same time, then combine both results in your reply.",
})
if err != nil {
t.Fatalf("SendAndWait failed: %v", err)
}
// Verify both tools were called
var cityArg, countryArg string
select {
case cityArg = <-cityCalled:
default:
}
select {
case countryArg = <-countryCalled:
default:
}
if cityArg == "" {
t.Error("lookup_city tool was not called")
}
if countryArg == "" {
t.Error("lookup_country tool was not called")
}
if answer == nil {
t.Error("Expected non-nil assistant message")
} else if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok {
t.Error("Expected AssistantMessageData")
} else {
if !strings.Contains(md.Content, "CITY_PARIS") {
t.Errorf("Expected content to contain 'CITY_PARIS', got %q", md.Content)
}
if !strings.Contains(md.Content, "COUNTRY_FRANCE") {
t.Errorf("Expected content to contain 'COUNTRY_FRANCE', got %q", md.Content)
}
}
})
t.Run("should respect availabletools and excludedtools combined", func(t *testing.T) {
ctx.ConfigureForTest(t)
type InputParams struct {
Input string `json:"input" jsonschema:"Input value"`
}
excludedToolCalled := false
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
copilot.DefineTool("allowed_tool", "An allowed tool",
func(params InputParams, inv copilot.ToolInvocation) (string, error) {
return "ALLOWED_" + strings.ToUpper(params.Input), nil
}),
copilot.DefineTool("excluded_tool", "A tool that should be excluded",
func(params InputParams, inv copilot.ToolInvocation) (string, error) {
excludedToolCalled = true
return "EXCLUDED_" + strings.ToUpper(params.Input), nil
}),
},
AvailableTools: []string{"allowed_tool", "excluded_tool"},
ExcludedTools: []string{"excluded_tool"},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
answer, err := session.SendAndWait(t.Context(), copilot.MessageOptions{
Prompt: "Use the allowed_tool with input 'test'. Do NOT use excluded_tool.",
})
if err != nil {
t.Fatalf("SendAndWait failed: %v", err)
}
if answer == nil {
t.Error("Expected non-nil assistant message")
} else if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok {
t.Error("Expected AssistantMessageData")
} else if !strings.Contains(md.Content, "ALLOWED_TEST") {
t.Errorf("Expected content to contain 'ALLOWED_TEST', got %q", md.Content)
}
if excludedToolCalled {
t.Error("Excluded tool should not have been called")
}
})
t.Run("overrides built-in tool with custom tool", func(t *testing.T) {
ctx.ConfigureForTest(t)
type GrepParams struct {
Query string `json:"query" jsonschema:"Search query"`
}
grepTool := copilot.DefineTool("grep", "A custom grep implementation that overrides the built-in",
func(params GrepParams, inv copilot.ToolInvocation) (string, error) {
return "CUSTOM_GREP_RESULT: " + params.Query, nil
})
grepTool.OverridesBuiltInTool = true
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
Tools: []copilot.Tool{
grepTool,
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use grep to search for the word 'hello'"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "CUSTOM_GREP_RESULT") {
t.Errorf("Expected answer to contain 'CUSTOM_GREP_RESULT', got %v", answer.Data)
}
})
t.Run("invokes custom tool with permission handler", func(t *testing.T) {
ctx.ConfigureForTest(t)
type EncryptParams struct {
Input string `json:"input" jsonschema:"String to encrypt"`
}
var permissionRequests []copilot.PermissionRequest
var mu sync.Mutex
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
Tools: []copilot.Tool{
copilot.DefineTool("encrypt_string", "Encrypts a string",
func(params EncryptParams, inv copilot.ToolInvocation) (string, error) {
return strings.ToUpper(params.Input), nil
}),
},
OnPermissionRequest: func(request copilot.PermissionRequest, invocation copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
mu.Lock()
permissionRequests = append(permissionRequests, request)
mu.Unlock()
return &rpc.PermissionDecisionApproveOnce{}, nil
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use encrypt_string to encrypt this string: Hello"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "HELLO") {
t.Errorf("Expected answer to contain 'HELLO', got %v", answer.Data)
}
// Should have received a custom-tool permission request
mu.Lock()
customToolReqs := 0
for _, req := range permissionRequests {
if customReq, ok := req.(*copilot.PermissionRequestCustomTool); ok {
customToolReqs++
if customReq.ToolName != "encrypt_string" {
t.Errorf("Expected toolName 'encrypt_string', got '%v'", req)
}
}
}
mu.Unlock()
if customToolReqs == 0 {
t.Errorf("Expected at least one custom-tool permission request, got none")
}
})
t.Run("denies custom tool when permission denied", func(t *testing.T) {
ctx.ConfigureForTest(t)
type EncryptParams struct {
Input string `json:"input" jsonschema:"String to encrypt"`
}
toolHandlerCalled := false
session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
Tools: []copilot.Tool{
copilot.DefineTool("encrypt_string", "Encrypts a string",
func(params EncryptParams, inv copilot.ToolInvocation) (string, error) {
toolHandlerCalled = true
return strings.ToUpper(params.Input), nil
}),
},
OnPermissionRequest: func(request copilot.PermissionRequest, invocation copilot.PermissionInvocation) (rpc.PermissionDecision, error) {
return &rpc.PermissionDecisionReject{}, nil
},
})
if err != nil {
t.Fatalf("Failed to create session: %v", err)
}
_, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use encrypt_string to encrypt this string: Hello"})
if err != nil {
t.Fatalf("Failed to send message: %v", err)
}
_, err = testharness.GetFinalAssistantMessage(t.Context(), session)
if err != nil {
t.Fatalf("Failed to get assistant message: %v", err)
}
if toolHandlerCalled {
t.Errorf("Tool handler should NOT have been called since permission was denied")
}
})
}