-
Notifications
You must be signed in to change notification settings - Fork 50
ci: verify examples and Copilot integration tests #931
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Michelle Clayton (michelle-clayton-work)
wants to merge
6
commits into
main
Choose a base branch
from
dev/mclayton/live-examples-poc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+292
−24
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98bf93f
ci: verify Copilot example end to end
michelle-clayton-work 2e31f1f
ci: make Copilot canary deterministic
michelle-clayton-work 4ecd807
ci: remove temporary Copilot canary trigger
michelle-clayton-work 12076d7
ci: run Copilot integration tests
michelle-clayton-work 01a1790
ci: fix Copilot integration assertions
michelle-clayton-work 6b659f4
ci: finalize live integration workflow
michelle-clayton-work File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| name: Live examples | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "17 9 * * 1-5" | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| copilot-requests: write | ||
|
|
||
| concurrency: | ||
| group: live-examples | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| verify: | ||
| name: Verify examples and Copilot provider | ||
| if: github.ref == 'refs/heads/main' | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 60 | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Set up Go | ||
| uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 | ||
| with: | ||
| go-version-file: go.mod | ||
| cache-dependency-path: go.sum | ||
|
|
||
| - name: Set up Node.js | ||
| uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Install Copilot CLI | ||
| shell: bash | ||
| run: npm install --global @github/copilot@1.0.75 | ||
|
|
||
| - name: Verify examples | ||
| id: examples | ||
| continue-on-error: true | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set +e | ||
| go run ./cmd/verifyexamples \ | ||
| --parallel 4 \ | ||
| --log live-examples.log \ | ||
| --md live-examples.md | ||
| status=$? | ||
| set -e | ||
|
|
||
| if [[ -f live-examples.md ]]; then | ||
| cat live-examples.md >> "$GITHUB_STEP_SUMMARY" | ||
| else | ||
| echo "The example verifier exited before it could write a report." >> "$GITHUB_STEP_SUMMARY" | ||
| fi | ||
| exit "$status" | ||
|
|
||
| - name: Run Copilot integration tests | ||
| id: copilot_integration | ||
| if: ${{ !cancelled() }} | ||
| continue-on-error: true | ||
| shell: bash | ||
| env: | ||
| GITHUB_TOKEN: ${{ github.token }} | ||
| run: | | ||
| set -o pipefail | ||
| go test -count=1 -v ./provider/copilotprovider -run '^TestE2E_' \ | ||
| 2>&1 | tee copilot-integration-tests.log | ||
|
|
||
| - name: Upload results | ||
| if: always() | ||
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | ||
| with: | ||
| name: live-example-results | ||
| path: | | ||
| live-examples.log | ||
| live-examples.md | ||
| copilot-integration-tests.log | ||
| if-no-files-found: warn | ||
| retention-days: 14 | ||
|
|
||
| - name: Check results | ||
| if: always() | ||
| shell: bash | ||
| env: | ||
| EXAMPLES_OUTCOME: ${{ steps.examples.outcome }} | ||
| COPILOT_INTEGRATION_OUTCOME: ${{ steps.copilot_integration.outcome }} | ||
| run: | | ||
| if [[ "$EXAMPLES_OUTCOME" != "success" || "$COPILOT_INTEGRATION_OUTCOME" != "success" ]]; then | ||
| echo "Example verification or Copilot integration tests failed." | ||
| exit 1 | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| package copilotprovider_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "strings" | ||
| "sync/atomic" | ||
| "testing" | ||
| "time" | ||
|
|
||
| copilot "github.com/github/copilot-sdk/go" | ||
| "github.com/microsoft/agent-framework-go/agent" | ||
| "github.com/microsoft/agent-framework-go/provider/copilotprovider" | ||
| "github.com/microsoft/agent-framework-go/tool" | ||
| "github.com/microsoft/agent-framework-go/tool/functool" | ||
| ) | ||
|
|
||
| func TestE2E_RunTextReturnsResponse(t *testing.T) { | ||
| client := newE2EClient(t) | ||
| canaryAgent := copilotprovider.NewAgent(client, copilotprovider.AgentConfig{ | ||
| SessionConfig: restrictedSessionConfig(nil), | ||
| }) | ||
| session := newE2ESession(t, canaryAgent, client) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute) | ||
| defer cancel() | ||
| response, err := canaryAgent.RunText( | ||
| ctx, | ||
| "What is 2 + 2? Answer with just the number.", | ||
| agent.WithSession(session), | ||
| agent.Stream(false), | ||
| ).Collect() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if response == nil || len(response.Messages) == 0 { | ||
| t.Fatal("response contains no messages") | ||
| } | ||
| if !strings.Contains(response.String(), "4") { | ||
| t.Fatalf("response = %q, want it to contain 4", response.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestE2E_RunTextStreamingReturnsUpdates(t *testing.T) { | ||
| client := newE2EClient(t) | ||
| canaryAgent := copilotprovider.NewAgent(client, copilotprovider.AgentConfig{ | ||
| SessionConfig: restrictedSessionConfig(nil), | ||
| }) | ||
| session := newE2ESession(t, canaryAgent, client) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute) | ||
| defer cancel() | ||
| var responseText strings.Builder | ||
| var updates int | ||
| for update, err := range canaryAgent.RunText( | ||
| ctx, | ||
| "What is 2 + 2? Answer with just the number.", | ||
| agent.WithSession(session), | ||
| agent.Stream(true), | ||
| ) { | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| updates++ | ||
| responseText.WriteString(update.String()) | ||
| } | ||
| if updates == 0 { | ||
| t.Fatal("stream contains no updates") | ||
| } | ||
| if !strings.Contains(responseText.String(), "4") { | ||
| t.Fatalf("streamed response = %q, want it to contain 4", responseText.String()) | ||
| } | ||
| } | ||
|
|
||
| func TestE2E_RunTextInvokesFunctionTool(t *testing.T) { | ||
| client := newE2EClient(t) | ||
| var invoked atomic.Bool | ||
| weatherTool := functool.MustNew(functool.Config{ | ||
| Name: "get_weather", | ||
| Description: "Get the weather for a location", | ||
| }, func(_ context.Context, location string) (string, error) { | ||
| invoked.Store(true) | ||
| return "The weather in " + location + " is sunny with a high of 25C.", nil | ||
| }) | ||
| config := restrictedSessionConfig([]string{"get_weather"}) | ||
| config.OnPermissionRequest = copilot.PermissionHandler.ApproveAll | ||
| canaryAgent := copilotprovider.NewAgent(client, copilotprovider.AgentConfig{ | ||
| SessionConfig: config, | ||
| Instructions: "Always use the get_weather tool to answer weather questions.", | ||
| Config: agent.Config{ | ||
| Tools: []tool.Tool{weatherTool}, | ||
| }, | ||
| }) | ||
| session := newE2ESession(t, canaryAgent, client) | ||
|
|
||
| ctx, cancel := context.WithTimeout(t.Context(), 2*time.Minute) | ||
| defer cancel() | ||
| response, err := canaryAgent.RunText( | ||
| ctx, | ||
| "What is the weather like in Seattle?", | ||
| agent.WithSession(session), | ||
| agent.Stream(false), | ||
| ).Collect() | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if response == nil || len(response.Messages) == 0 { | ||
| t.Fatal("response contains no messages") | ||
| } | ||
| if !invoked.Load() { | ||
| t.Fatal("get_weather was not invoked") | ||
| } | ||
| } | ||
|
|
||
| func newE2EClient(t *testing.T) *copilot.Client { | ||
| t.Helper() | ||
| skipUnlessE2EEnabled(t) | ||
|
|
||
| options := &copilot.ClientOptions{} | ||
| if token := strings.TrimSpace(os.Getenv("GITHUB_TOKEN")); token != "" { | ||
| options.GitHubToken = token | ||
| } | ||
| client := copilot.NewClient(options) | ||
| ctx, cancel := context.WithTimeout(t.Context(), 30*time.Second) | ||
| defer cancel() | ||
| if err := client.Start(ctx); err != nil { | ||
| t.Fatalf("start Copilot client: %v", err) | ||
| } | ||
| t.Cleanup(client.ForceStop) | ||
| return client | ||
| } | ||
|
|
||
| func skipUnlessE2EEnabled(t *testing.T) { | ||
| t.Helper() | ||
| actionsAuth := strings.EqualFold(os.Getenv("GITHUB_ACTIONS"), "true") && strings.TrimSpace(os.Getenv("GITHUB_TOKEN")) != "" | ||
| localOptIn := strings.EqualFold(os.Getenv("RUN_COPILOT_INTEGRATION_TESTS"), "true") | ||
| if !actionsAuth && !localOptIn { | ||
| t.Skip("GitHub Actions auth is unavailable and RUN_COPILOT_INTEGRATION_TESTS is not true") | ||
| } | ||
| } | ||
|
|
||
| func restrictedSessionConfig(availableTools []string) *copilot.SessionConfig { | ||
| return &copilot.SessionConfig{ | ||
| AvailableTools: availableTools, | ||
| EnableConfigDiscovery: new(false), | ||
| EnableOnDemandInstructionDiscovery: new(false), | ||
| EnableFileHooks: new(false), | ||
| EnableHostGitOperations: new(false), | ||
| EnableSessionStore: new(false), | ||
| EnableSkills: new(false), | ||
| InfiniteSessions: &copilot.InfiniteSessionConfig{ | ||
| Enabled: new(false), | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| func newE2ESession(t *testing.T, canaryAgent *agent.Agent, client *copilot.Client) *agent.Session { | ||
| t.Helper() | ||
| session, err := canaryAgent.CreateSession(t.Context()) | ||
| if err != nil { | ||
| t.Fatalf("create session: %v", err) | ||
| } | ||
| t.Cleanup(func() { | ||
| if sessionID := session.ServiceID(); sessionID != "" { | ||
| ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) | ||
| defer cancel() | ||
| if err := client.DeleteSession(ctx, sessionID); err != nil { | ||
| t.Errorf("delete session: %v", err) | ||
| } | ||
| } | ||
| }) | ||
| return session | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The integration tests should run as part of the test workflow, they are orthogonal to the examples.