-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix MCP OAuth resume order in Node.js SDK #1861
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
adc873c
Fix MCP OAuth resume order in Node.js SDK
MackinnonBuck 40ffd16
Fix MCP OAuth resume order across SDKs and add cross-SDK E2E coverage
MackinnonBuck b57c784
Fix OAuth resume CI checks
MackinnonBuck f702dca
Merge branch 'main' into mackinnonbuck-fix-mcp-oauth-resume-order
stephentoub 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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,60 @@ | ||
| package e2e | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| copilot "github.com/github/copilot-sdk/go" | ||
| "github.com/github/copilot-sdk/go/internal/e2e/testharness" | ||
| ) | ||
|
|
||
| func TestResumeMCPOAuthE2E(t *testing.T) { | ||
| ctx := testharness.NewTestContext(t) | ||
| client := ctx.NewClient() | ||
| t.Cleanup(func() { client.ForceStop() }) | ||
|
|
||
| t.Run("should resume a persisted session with mcp auth handler", func(t *testing.T) { | ||
| ctx.ConfigureForTest(t) | ||
|
|
||
| mcpAuthHandler := func(copilot.MCPAuthRequest, copilot.MCPAuthInvocation) (*copilot.MCPAuthResult, error) { | ||
| return copilot.MCPAuthResultCancelled(), nil | ||
| } | ||
|
|
||
| session1, err := client.CreateSession(t.Context(), &copilot.SessionConfig{ | ||
| OnPermissionRequest: copilot.PermissionHandler.ApproveAll, | ||
| OnMCPAuthRequest: mcpAuthHandler, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to create session: %v", err) | ||
| } | ||
| sessionID := session1.SessionID | ||
|
|
||
| _, err = session1.Send(t.Context(), copilot.MessageOptions{Prompt: "What is 1+1?"}) | ||
| if err != nil { | ||
| t.Fatalf("Failed to send message: %v", err) | ||
| } | ||
|
|
||
| answer, err := testharness.GetFinalAssistantMessage(t.Context(), session1) | ||
| if err != nil { | ||
| t.Fatalf("Failed to get assistant message: %v", err) | ||
| } | ||
| if ad, ok := answer.Data.(*copilot.AssistantMessageData); !ok || !strings.Contains(ad.Content, "2") { | ||
| t.Errorf("Expected answer to contain '2', got %v", answer.Data) | ||
| } | ||
|
|
||
| newClient := ctx.NewClient() | ||
| t.Cleanup(func() { newClient.ForceStop() }) | ||
|
|
||
| session2, err := newClient.ResumeSession(t.Context(), sessionID, &copilot.ResumeSessionConfig{ | ||
| OnPermissionRequest: copilot.PermissionHandler.ApproveAll, | ||
| OnMCPAuthRequest: mcpAuthHandler, | ||
| }) | ||
| if err != nil { | ||
| t.Fatalf("Failed to resume session: %v", err) | ||
| } | ||
|
|
||
| if session2.SessionID != sessionID { | ||
| t.Errorf("Expected resumed session ID to match, got %q vs %q", session2.SessionID, sessionID) | ||
| } | ||
| }) | ||
| } |
76 changes: 76 additions & 0 deletions
76
java/src/test/java/com/github/copilot/McpOAuthResumeE2ETest.java
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,76 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package com.github.copilot; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
|
||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.github.copilot.generated.AssistantMessageEvent; | ||
| import com.github.copilot.rpc.McpAuthResult; | ||
| import com.github.copilot.rpc.MessageOptions; | ||
| import com.github.copilot.rpc.PermissionHandler; | ||
| import com.github.copilot.rpc.ResumeSessionConfig; | ||
| import com.github.copilot.rpc.SessionConfig; | ||
|
|
||
| class McpOAuthResumeE2ETest { | ||
|
|
||
| private static final String SNAPSHOT = "resumes_a_persisted_session_from_a_new_client_when_an_mcp_oauth_handler_is_configured"; | ||
|
|
||
| private static E2ETestContext ctx; | ||
|
|
||
| @BeforeAll | ||
| static void setup() throws Exception { | ||
| ctx = E2ETestContext.create(); | ||
| } | ||
|
|
||
| @AfterAll | ||
| static void teardown() throws Exception { | ||
| if (ctx != null) { | ||
| ctx.close(); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| @Tag("isolated-resume") | ||
| void resumesAPersistedSessionFromANewClientWhenAnMcpOauthHandlerIsConfigured() throws Exception { | ||
| ctx.configureForTest("session", SNAPSHOT); | ||
|
|
||
| String sessionId; | ||
| try (var client = ctx.createClient(); | ||
| var session = client | ||
| .createSession( | ||
| new SessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL) | ||
| .setOnMcpAuthRequest((request, invocation) -> CompletableFuture | ||
| .completedFuture(McpAuthResult.cancelled()))) | ||
| .get(30, TimeUnit.SECONDS)) { | ||
| sessionId = session.getSessionId(); | ||
|
|
||
| AssistantMessageEvent response = session.sendAndWait(new MessageOptions().setPrompt("What is 1+1?"), 60_000) | ||
| .get(90, TimeUnit.SECONDS); | ||
| assertNotNull(response); | ||
| assertTrue(response.getData().content().contains("2"), | ||
| "Response should contain 2: " + response.getData().content()); | ||
| } | ||
|
|
||
| try (var client = ctx.createClient(); | ||
| var session = client | ||
| .resumeSession(sessionId, | ||
| new ResumeSessionConfig().setOnPermissionRequest(PermissionHandler.APPROVE_ALL) | ||
| .setOnMcpAuthRequest((request, invocation) -> CompletableFuture | ||
| .completedFuture(McpAuthResult.cancelled()))) | ||
| .get(30, TimeUnit.SECONDS)) { | ||
| assertEquals(sessionId, session.getSessionId()); | ||
| } | ||
| } | ||
| } |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.