|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +package e2e |
| 5 | + |
| 6 | +import ( |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | + |
| 10 | + copilot "github.com/github/copilot-sdk/go" |
| 11 | + "github.com/github/copilot-sdk/go/internal/e2e/testharness" |
| 12 | +) |
| 13 | + |
| 14 | +func TestSystemMessageSectionsE2E(t *testing.T) { |
| 15 | + ctx := testharness.NewTestContext(t) |
| 16 | + client := ctx.NewClient() |
| 17 | + t.Cleanup(func() { client.ForceStop() }) |
| 18 | + |
| 19 | + t.Run("should_use_replaced_identity_section_in_response", func(t *testing.T) { |
| 20 | + ctx.ConfigureForTest(t) |
| 21 | + |
| 22 | + session, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ |
| 23 | + OnPermissionRequest: copilot.PermissionHandler.ApproveAll, |
| 24 | + SystemMessage: &copilot.SystemMessageConfig{ |
| 25 | + Mode: "customize", |
| 26 | + Sections: map[string]copilot.SectionOverride{ |
| 27 | + "identity": { |
| 28 | + Action: copilot.SectionActionReplace, |
| 29 | + Content: "You are a helpful gardening assistant called Botanica. You only answer questions about plants and gardening.", |
| 30 | + }, |
| 31 | + }, |
| 32 | + }, |
| 33 | + }) |
| 34 | + if err != nil { |
| 35 | + t.Fatalf("Failed to create session: %v", err) |
| 36 | + } |
| 37 | + |
| 38 | + response, err := session.SendAndWait(t.Context(), copilot.MessageOptions{ |
| 39 | + Prompt: "Who are you?", |
| 40 | + }) |
| 41 | + if err != nil { |
| 42 | + t.Fatalf("Failed to send message: %v", err) |
| 43 | + } |
| 44 | + if response == nil { |
| 45 | + t.Fatal("Expected a response from the assistant") |
| 46 | + } |
| 47 | + |
| 48 | + ad, ok := response.Data.(*copilot.AssistantMessageData) |
| 49 | + if !ok { |
| 50 | + t.Fatalf("Expected AssistantMessageData, got %T", response.Data) |
| 51 | + } |
| 52 | + content := strings.ToLower(ad.Content) |
| 53 | + if !strings.Contains(content, "botanica") && !strings.Contains(content, "garden") && !strings.Contains(content, "plant") { |
| 54 | + t.Errorf("Expected response to reflect the replaced identity section, but got: %s", ad.Content) |
| 55 | + } |
| 56 | + }) |
| 57 | +} |
0 commit comments