MCPcopy Create free account
hub / github.com/github/copilot-sdk / TestToolsE2E

Function TestToolsE2E

go/internal/e2e/tools_e2e_test.go:16–666  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestToolsE2E(t *testing.T) {
17 ctx := testharness.NewTestContext(t)
18 client := ctx.NewClient()
19 t.Cleanup(func() { client.ForceStop() })
20
21 t.Run("invokes built-in tools", func(t *testing.T) {
22 ctx.ConfigureForTest(t)
23
24 // Write a test file
25 err := os.WriteFile(filepath.Join(ctx.WorkDir, "README.md"), []byte("# ELIZA, the only chatbot you'll ever need"), 0644)
26 if err != nil {
27 t.Fatalf("Failed to write test file: %v", err)
28 }
29
30 session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
31 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
32 })
33 if err != nil {
34 t.Fatalf("Failed to create session: %v", err)
35 }
36
37 _, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "What's the first line of README.md in this directory?"})
38 if err != nil {
39 t.Fatalf("Failed to send message: %v", err)
40 }
41
42 answer, err := testharness.GetFinalAssistantMessage(t.Context(), session)
43 if err != nil {
44 t.Fatalf("Failed to get assistant message: %v", err)
45 }
46
47 if md, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(md.Content, "ELIZA") {
48 t.Errorf("Expected answer to contain 'ELIZA', got %v", answer.Data)
49 }
50 })
51
52 t.Run("invokes custom tool", func(t *testing.T) {
53 ctx.ConfigureForTest(t)
54
55 type EncryptParams struct {
56 Input string `json:"input" jsonschema:"String to encrypt"`
57 }
58
59 session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{
60 OnPermissionRequest: copilot.PermissionHandler.ApproveAll,
61 Tools: []copilot.Tool{
62 copilot.DefineTool("encrypt_string", "Encrypts a string",
63 func(params EncryptParams, inv copilot.ToolInvocation) (string, error) {
64 return strings.ToUpper(params.Input), nil
65 }),
66 },
67 })
68 if err != nil {
69 t.Fatalf("Failed to create session: %v", err)
70 }
71
72 _, err = session.Send(t.Context(), copilot.MessageOptions{Prompt: "Use encrypt_string to encrypt this string: Hello"})
73 if err != nil {

Callers

nothing calls this directly

Calls 12

NewClientMethod · 0.95
ForceStopMethod · 0.95
ConfigureForTestMethod · 0.95
CreateSessionMethod · 0.95
GetExchangesMethod · 0.95
ToSliceMethod · 0.80
AddBuiltInMethod · 0.80
AddCustomMethod · 0.80
SendAndWaitMethod · 0.80
WriteFileMethod · 0.65
SendMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…